diff --git a/packages/backend/src/apps/invoice-ninja/actions/create-client/fields.ts b/packages/backend/src/apps/invoice-ninja/actions/create-client/fields.ts new file mode 100644 index 00000000..d38099c1 --- /dev/null +++ b/packages/backend/src/apps/invoice-ninja/actions/create-client/fields.ts @@ -0,0 +1,388 @@ +export const fields = [ + { + label: 'Client Name', + key: 'clientName', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Contact First Name', + key: 'contactFirstName', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Contact Last Name', + key: 'contactLastName', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Contact Email', + key: 'contactEmail', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Contact Phone', + key: 'contactPhone', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Language Code', + key: 'languageCode', + type: 'dropdown' as const, + required: false, + description: '', + variables: true, + options: [ + { value: 1, label: 'English - United States' }, + { value: 2, label: 'Italian' }, + { value: 3, label: 'German' }, + { value: 4, label: 'French' }, + { value: 5, label: 'Portuguese - Brazilian' }, + { value: 6, label: 'Dutch' }, + { value: 7, label: 'Spanish' }, + { value: 8, label: 'Norwegian' }, + { value: 9, label: 'Danish' }, + { value: 10, label: 'Japanese' }, + { value: 11, label: 'Swedish' }, + { value: 12, label: 'Spanish - Spain' }, + { value: 13, label: 'French - Canada' }, + { value: 14, label: 'Lithuanian' }, + { value: 15, label: 'Polish' }, + { value: 16, label: 'Czech' }, + { value: 17, label: 'Croatian' }, + { value: 18, label: 'Albanian' }, + { value: 19, label: 'Greek' }, + { value: 20, label: 'English - United Kingdom' }, + { value: 21, label: 'Portuguese - Portugal' }, + { value: 22, label: 'Slovenian' }, + { value: 23, label: 'Finnish' }, + { value: 24, label: 'Romanian' }, + { value: 25, label: 'Turkish - Turkey' }, + { value: 26, label: 'Thai' }, + { value: 27, label: 'Macedonian' }, + { value: 28, label: 'Chinese - Taiwan' }, + { value: 29, label: 'Russian (Russia)' }, + { value: 30, label: 'Arabic' }, + { value: 31, label: 'Persian' }, + { value: 32, label: 'Latvian' }, + { value: 33, label: 'Serbian' }, + { value: 34, label: 'Slovak' }, + { value: 35, label: 'Estonian' }, + { value: 36, label: 'Bulgarian' }, + { value: 37, label: 'Hebrew' }, + { value: 38, label: 'Khmer' }, + { value: 39, label: 'Hungarian' }, + { value: 40, label: 'French - Swiss' }, + ], + }, + { + label: 'Currency Code', + key: 'currencyCode', + type: 'dropdown' as const, + required: false, + description: '', + variables: true, + options: [ + { value: 1, label: 'US Dollar' }, + { value: 2, label: 'British Pound' }, + { value: 3, label: 'Euro' }, + { value: 4, label: 'South African Rand' }, + { value: 5, label: 'Danish Krone' }, + { value: 6, label: 'Israeli Shekel' }, + { value: 7, label: 'Swedish Krona' }, + { value: 8, label: 'Kenyan Shilling' }, + { value: 9, label: 'Canadian Dollar' }, + { value: 10, label: 'Philippine Peso' }, + { value: 11, label: 'Indian Rupee' }, + { value: 12, label: 'Australian Dollar' }, + { value: 13, label: 'Singapore Dollar' }, + { value: 14, label: 'Norske Kroner' }, + { value: 15, label: 'New Zealand Dollar' }, + { value: 16, label: 'Vietnamese Dong' }, + { value: 17, label: 'Swiss Franc' }, + { value: 18, label: 'Guatemalan Quetzal' }, + { value: 19, label: 'Malaysian Ringgit' }, + { value: 20, label: 'Brazilian Real' }, + { value: 21, label: 'Thai Baht' }, + { value: 22, label: 'Nigerian Naira' }, + { value: 23, label: 'Argentine Peso' }, + { value: 24, label: 'Bangladeshi Taka' }, + { value: 25, label: 'United Arab Emirates Dirham' }, + { value: 26, label: 'Hong Kong Dollar' }, + { value: 27, label: 'Indonesian Rupiah' }, + { value: 28, label: 'Mexican Peso' }, + { value: 29, label: 'Egyptian Pound' }, + { value: 30, label: 'Colombian Peso' }, + { value: 31, label: 'West African Franc' }, + { value: 32, label: 'Chinese Renminbi' }, + { value: 33, label: 'Rwandan Franc' }, + { value: 34, label: 'Tanzanian Shilling' }, + { value: 35, label: 'Netherlands Antillean Guilder' }, + { value: 36, label: 'Trinidad and Tobago Dollar' }, + { value: 37, label: 'East Caribbean Dollar' }, + { value: 38, label: 'Ghanaian Cedi' }, + { value: 39, label: 'Bulgarian Lev' }, + { value: 40, label: 'Aruban Florin' }, + { value: 41, label: 'Turkish Lira' }, + { value: 42, label: 'Romanian New Leu' }, + { value: 43, label: 'Croatian Kuna' }, + { value: 44, label: 'Saudi Riyal' }, + { value: 45, label: 'Japanese Yen' }, + { value: 46, label: 'Maldivian Rufiyaa' }, + { value: 47, label: 'Costa Rican Colón' }, + { value: 48, label: 'Pakistani Rupee' }, + { value: 49, label: 'Polish Zloty' }, + { value: 50, label: 'Sri Lankan Rupee' }, + { value: 51, label: 'Czech Koruna' }, + { value: 52, label: 'Uruguayan Peso' }, + { value: 53, label: 'Namibian Dollar' }, + { value: 54, label: 'Tunisian Dinar' }, + { value: 55, label: 'Russian Ruble' }, + { value: 56, label: 'Mozambican Metical' }, + { value: 57, label: 'Omani Rial' }, + { value: 58, label: 'Ukrainian Hryvnia' }, + { value: 59, label: 'Macanese Pataca' }, + { value: 60, label: 'Taiwan New Dollar' }, + { value: 61, label: 'Dominican Peso' }, + { value: 62, label: 'Chilean Peso' }, + { value: 63, label: 'Icelandic Króna' }, + { value: 64, label: 'Papua New Guinean Kina' }, + { value: 65, label: 'Jordanian Dinar' }, + { value: 66, label: 'Myanmar Kyat' }, + { value: 67, label: 'Peruvian Sol' }, + { value: 68, label: 'Botswana Pula' }, + { value: 69, label: 'Hungarian Forint' }, + { value: 70, label: 'Ugandan Shilling' }, + { value: 71, label: 'Barbadian Dollar' }, + { value: 72, label: 'Brunei Dollar' }, + { value: 73, label: 'Georgian Lari' }, + { value: 74, label: 'Qatari Riyal' }, + { value: 75, label: 'Honduran Lempira' }, + { value: 76, label: 'Surinamese Dollar' }, + { value: 77, label: 'Bahraini Dinar' }, + { value: 78, label: 'Venezuelan Bolivars' }, + { value: 79, label: 'South Korean Won' }, + { value: 80, label: 'Moroccan Dirham' }, + { value: 81, label: 'Jamaican Dollar' }, + { value: 82, label: 'Angolan Kwanza' }, + { value: 83, label: 'Haitian Gourde' }, + { value: 84, label: 'Zambian Kwacha' }, + { value: 85, label: 'Nepalese Rupee' }, + { value: 86, label: 'CFP Franc' }, + { value: 87, label: 'Mauritian Rupee' }, + { value: 88, label: 'Cape Verdean Escudo' }, + { value: 89, label: 'Kuwaiti Dinar' }, + { value: 90, label: 'Algerian Dinar' }, + { value: 91, label: 'Macedonian Denar' }, + { value: 92, label: 'Fijian Dollar' }, + { value: 93, label: 'Bolivian Boliviano' }, + { value: 94, label: 'Albanian Lek' }, + { value: 95, label: 'Serbian Dinar' }, + { value: 96, label: 'Lebanese Pound' }, + { value: 97, label: 'Armenian Dram' }, + { value: 98, label: 'Azerbaijan Manat' }, + { value: 99, label: 'Bosnia and Herzegovina Convertible Mark' }, + { value: 100, label: 'Belarusian Ruble' }, + { value: 101, label: 'Gibraltar Pound' }, + { value: 102, label: 'Moldovan Leu' }, + { value: 103, label: 'Kazakhstani Tenge' }, + { value: 104, label: 'Ethiopian Birr' }, + { value: 105, label: 'Gambia Dalasi' }, + { value: 106, label: 'Paraguayan Guarani' }, + { value: 107, label: 'Malawi Kwacha' }, + { value: 108, label: 'Zimbabwean Dollar' }, + { value: 109, label: 'Cambodian Riel' }, + { value: 110, label: 'Vanuatu Vatu' }, + { value: 111, label: 'Cuban Peso' }, + { value: 112, label: 'Cayman Island Dollar' }, + { value: 113, label: 'Swazi lilangeni' }, + { value: 114, label: 'BZ Dollar' }, + { value: 115, label: 'Libyan Dinar' }, + { value: 116, label: 'Silver Troy Ounce' }, + { value: 117, label: 'Gold Troy Ounce' }, + { value: 118, label: 'Nicaraguan Córdoba' }, + ], + }, + { + label: 'Id Number', + key: 'idNumber', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Vat Number', + key: 'vatNumber', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Street Address', + key: 'streetAddress', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Apt/Suite', + key: 'aptSuite', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'City', + key: 'city', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'State/Province', + key: 'stateProvince', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Postal Code', + key: 'postalCode', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Country Code', + key: 'countryCode', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Shipping Street Address', + key: 'shippingStreetAddress', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Shipping Apt/Suite', + key: 'shippingAptSuite', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Shipping City', + key: 'shippingCity', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Shipping State/Province', + key: 'shippingStateProvince', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Shipping Postal Code', + key: 'shippingPostalCode', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Shipping Country Code', + key: 'shippingCountryCode', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Private Notes', + key: 'privateNotes', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Public Notes', + key: 'publicNotes', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Website', + key: 'website', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Custom Value 1', + key: 'customValue1', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Custom Value 2', + key: 'customValue2', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Custom Value 3', + key: 'customValue3', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Custom Value 4', + key: 'customValue4', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, +]; diff --git a/packages/backend/src/apps/invoice-ninja/actions/create-client/index.ts b/packages/backend/src/apps/invoice-ninja/actions/create-client/index.ts new file mode 100644 index 00000000..b32d7adc --- /dev/null +++ b/packages/backend/src/apps/invoice-ninja/actions/create-client/index.ts @@ -0,0 +1,84 @@ +import defineAction from '../../../../helpers/define-action'; +import { filterProvidedFields } from '../../common/filter-provided-fields'; +import { fields } from './fields'; + +export default defineAction({ + name: 'Create client', + key: 'createClient', + description: 'Creates a new client.', + arguments: fields, + + async run($) { + const { + clientName, + contactFirstName, + contactLastName, + contactEmail, + contactPhone, + languageCode, + currencyCode, + idNumber, + vatNumber, + streetAddress, + aptSuite, + city, + stateProvince, + postalCode, + countryCode, + shippingStreetAddress, + shippingAptSuite, + shippingCity, + shippingStateProvince, + shippingPostalCode, + shippingCountryCode, + privateNotes, + publicNotes, + website, + customValue1, + customValue2, + customValue3, + customValue4, + } = $.step.parameters; + + const bodyFields = { + name: clientName, + contacts: { + first_name: contactFirstName, + last_name: contactLastName, + email: contactEmail, + phone: contactPhone, + }, + settings: { + language_id: languageCode, + currency_id: currencyCode, + }, + id_number: idNumber, + vat_number: vatNumber, + address1: streetAddress, + address2: aptSuite, + city: city, + state: stateProvince, + postal_code: postalCode, + country_id: countryCode, + shipping_address1: shippingStreetAddress, + shipping_address2: shippingAptSuite, + shipping_city: shippingCity, + shipping_state: shippingStateProvince, + shipping_postal_code: shippingPostalCode, + shipping_country_id: shippingCountryCode, + private_notes: privateNotes, + public_notes: publicNotes, + website: website, + custom_value1: customValue1, + custom_value2: customValue2, + custom_value3: customValue3, + custom_value4: customValue4, + }; + + const body = filterProvidedFields(bodyFields); + + const response = await $.http.post('/v1/clients', body); + + $.setActionItem({ raw: response.data.data }); + }, +}); diff --git a/packages/backend/src/apps/invoice-ninja/actions/index.ts b/packages/backend/src/apps/invoice-ninja/actions/index.ts new file mode 100644 index 00000000..b2ecee29 --- /dev/null +++ b/packages/backend/src/apps/invoice-ninja/actions/index.ts @@ -0,0 +1,3 @@ +import createClient from './create-client'; + +export default [createClient]; diff --git a/packages/backend/src/apps/invoice-ninja/common/filter-provided-fields.ts b/packages/backend/src/apps/invoice-ninja/common/filter-provided-fields.ts new file mode 100644 index 00000000..fa88c8ee --- /dev/null +++ b/packages/backend/src/apps/invoice-ninja/common/filter-provided-fields.ts @@ -0,0 +1,18 @@ +import isObject from 'lodash/isObject'; + +export function filterProvidedFields(body: Record) { + return Object.keys(body).reduce>((result, key) => { + const value = body[key]; + if (isObject(value)) { + const filteredNestedObj = filterProvidedFields( + value as Record + ); + if (Object.keys(filteredNestedObj).length > 0) { + result[key] = filteredNestedObj; + } + } else if (body[key]) { + result[key] = value; + } + return result; + }, {}); +} diff --git a/packages/backend/src/apps/invoice-ninja/index.ts b/packages/backend/src/apps/invoice-ninja/index.ts index 522367ea..7198b4dc 100644 --- a/packages/backend/src/apps/invoice-ninja/index.ts +++ b/packages/backend/src/apps/invoice-ninja/index.ts @@ -2,6 +2,7 @@ import defineApp from '../../helpers/define-app'; import addAuthHeader from './common/add-auth-header'; import auth from './auth'; import triggers from './triggers'; +import actions from './actions'; export default defineApp({ name: 'Invoice Ninja', @@ -15,4 +16,5 @@ export default defineApp({ beforeRequest: [addAuthHeader], auth, triggers, + actions, }); diff --git a/packages/docs/pages/.vitepress/config.js b/packages/docs/pages/.vitepress/config.js index 2c058d6a..674a7315 100644 --- a/packages/docs/pages/.vitepress/config.js +++ b/packages/docs/pages/.vitepress/config.js @@ -175,6 +175,7 @@ export default defineConfig({ collapsed: true, items: [ { text: 'Triggers', link: '/apps/invoice-ninja/triggers' }, + { text: 'Actions', link: '/apps/invoice-ninja/actions' }, { text: 'Connection', link: '/apps/invoice-ninja/connection' }, ], }, diff --git a/packages/docs/pages/apps/invoice-ninja/actions.md b/packages/docs/pages/apps/invoice-ninja/actions.md new file mode 100644 index 00000000..c57f6e72 --- /dev/null +++ b/packages/docs/pages/apps/invoice-ninja/actions.md @@ -0,0 +1,12 @@ +--- +favicon: /favicons/invoice-ninja.svg +items: + - name: Create client + desc: Creates a new client. +--- + + + +