Skip to content

Commit

Permalink
feat(invoice-ninja): add create client action
Browse files Browse the repository at this point in the history
  • Loading branch information
ridvanakca committed Oct 11, 2023
1 parent 497ce2e commit 902cd39
Show file tree
Hide file tree
Showing 7 changed files with 346 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
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: 'string' as const,
required: false,
description: '',
variables: true,
},
{
label: 'Currency Code',
key: 'currencyCode',
type: 'string' as const,
required: false,
description: '',
variables: true,
},
{
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,
},
];
Original file line number Diff line number Diff line change
@@ -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 });
},
});
3 changes: 3 additions & 0 deletions packages/backend/src/apps/invoice-ninja/actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import createClient from './create-client';

export default [createClient];
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import isObject from 'lodash/isObject';

export function filterProvidedFields(body: Record<string, unknown>) {
return Object.keys(body).reduce<Record<string, unknown>>((result, key) => {
const value = body[key];
if (isObject(value)) {
const filteredNestedObj = filterProvidedFields(
value as Record<string, unknown>
);
if (Object.keys(filteredNestedObj).length > 0) {
result[key] = filteredNestedObj;
}
} else if (body[key]) {
result[key] = value;
}
return result;
}, {});
}
2 changes: 2 additions & 0 deletions packages/backend/src/apps/invoice-ninja/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import defineApp from '../../helpers/define-app';
import addAuthHeader from './common/add-auth-header';
import auth from './auth';
import actions from './actions';

export default defineApp({
name: 'Invoice Ninja',
Expand All @@ -13,4 +14,5 @@ export default defineApp({
supportsConnections: true,
beforeRequest: [addAuthHeader],
auth,
actions,
});
1 change: 1 addition & 0 deletions packages/docs/pages/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export default defineConfig({
collapsible: true,
collapsed: true,
items: [
{ text: 'Actions', link: '/apps/invoice-ninja/actions' },
{ text: 'Connection', link: '/apps/invoice-ninja/connection' },
],
},
Expand Down
12 changes: 12 additions & 0 deletions packages/docs/pages/apps/invoice-ninja/actions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
favicon: /favicons/invoice-ninja.svg
items:
- name: Create client
desc: Creates a new client.
---

<script setup>
import CustomListing from '../../components/CustomListing.vue'
</script>

<CustomListing />

0 comments on commit 902cd39

Please sign in to comment.