|
1 | | -import invoice_ninja from "../../invoice_ninja.app.mjs"; |
2 | | -import { axios } from "@pipedream/platform"; |
| 1 | +import { CLASSIFICATION_OPTIONS } from "../../common/constants.mjs"; |
| 2 | +import { parseObject } from "../../common/utils.mjs"; |
| 3 | +import app from "../../invoice_ninja.app.mjs"; |
3 | 4 |
|
4 | 5 | export default { |
5 | 6 | key: "invoice_ninja-create-client", |
6 | 7 | name: "Create Client", |
7 | | - description: "Creates a new client in Invoice Ninja. [See the documentation]()", |
8 | | - version: "0.0.{{ts}}", |
| 8 | + description: "Creates a new client in Invoice Ninja. [See the documentation](https://api-docs.invoicing.co/#tag/clients/POST/api/v1/clients)", |
| 9 | + version: "0.0.1", |
9 | 10 | type: "action", |
10 | 11 | props: { |
11 | | - invoice_ninja, |
| 12 | + app, |
12 | 13 | contacts: { |
13 | | - propDefinition: [ |
14 | | - invoice_ninja, |
15 | | - "contacts", |
16 | | - ], |
17 | | - }, |
18 | | - countryId: { |
19 | | - propDefinition: [ |
20 | | - invoice_ninja, |
21 | | - "countryId", |
22 | | - ], |
| 14 | + type: "string[]", |
| 15 | + label: "Contacts", |
| 16 | + description: "An array of contact objects in JSON format. **Example: { \"first_name\": \"John\", \"last_name\": \"Smith\", \"email\": \"[email protected]\", \"phone\": \"555-0123\" }**", |
23 | 17 | }, |
24 | 18 | name: { |
25 | | - propDefinition: [ |
26 | | - invoice_ninja, |
27 | | - "name", |
28 | | - ], |
| 19 | + type: "string", |
| 20 | + label: "Client Name", |
| 21 | + description: "Name of the client", |
29 | 22 | optional: true, |
30 | 23 | }, |
31 | 24 | website: { |
32 | | - propDefinition: [ |
33 | | - invoice_ninja, |
34 | | - "website", |
35 | | - ], |
| 25 | + type: "string", |
| 26 | + label: "Website", |
| 27 | + description: "Website of the client", |
36 | 28 | optional: true, |
37 | 29 | }, |
38 | 30 | privateNotes: { |
39 | | - propDefinition: [ |
40 | | - invoice_ninja, |
41 | | - "privateNotes", |
42 | | - ], |
| 31 | + type: "string", |
| 32 | + label: "Private Notes", |
| 33 | + description: "Notes that are only visible to the user who created the client", |
43 | 34 | optional: true, |
44 | 35 | }, |
45 | 36 | industryId: { |
46 | 37 | propDefinition: [ |
47 | | - invoice_ninja, |
| 38 | + app, |
48 | 39 | "industryId", |
49 | 40 | ], |
50 | 41 | optional: true, |
51 | 42 | }, |
52 | 43 | sizeId: { |
53 | 44 | propDefinition: [ |
54 | | - invoice_ninja, |
| 45 | + app, |
55 | 46 | "sizeId", |
56 | 47 | ], |
57 | 48 | optional: true, |
58 | 49 | }, |
59 | 50 | address1: { |
60 | | - propDefinition: [ |
61 | | - invoice_ninja, |
62 | | - "address1", |
63 | | - ], |
| 51 | + type: "string", |
| 52 | + label: "Address 1", |
| 53 | + description: "Primary address line for the client", |
64 | 54 | optional: true, |
65 | 55 | }, |
66 | 56 | address2: { |
67 | | - propDefinition: [ |
68 | | - invoice_ninja, |
69 | | - "address2", |
70 | | - ], |
| 57 | + type: "string", |
| 58 | + label: "Address 2", |
| 59 | + description: "Secondary address line for the client", |
71 | 60 | optional: true, |
72 | 61 | }, |
73 | 62 | city: { |
74 | | - propDefinition: [ |
75 | | - invoice_ninja, |
76 | | - "city", |
77 | | - ], |
| 63 | + type: "string", |
| 64 | + label: "City", |
| 65 | + description: "City of the client", |
78 | 66 | optional: true, |
79 | 67 | }, |
80 | 68 | state: { |
81 | | - propDefinition: [ |
82 | | - invoice_ninja, |
83 | | - "state", |
84 | | - ], |
| 69 | + type: "string", |
| 70 | + label: "State", |
| 71 | + description: "State of the client", |
85 | 72 | optional: true, |
86 | 73 | }, |
87 | 74 | postalCode: { |
88 | | - propDefinition: [ |
89 | | - invoice_ninja, |
90 | | - "postalCode", |
91 | | - ], |
| 75 | + type: "string", |
| 76 | + label: "Postal Code", |
| 77 | + description: "Postal code of the client", |
92 | 78 | optional: true, |
93 | 79 | }, |
94 | 80 | phone: { |
| 81 | + type: "string", |
| 82 | + label: "Phone", |
| 83 | + description: "Phone number of the client", |
| 84 | + optional: true, |
| 85 | + }, |
| 86 | + countryId: { |
95 | 87 | propDefinition: [ |
96 | | - invoice_ninja, |
97 | | - "phone", |
| 88 | + app, |
| 89 | + "countryId", |
98 | 90 | ], |
| 91 | + }, |
| 92 | + customValue1: { |
| 93 | + type: "string", |
| 94 | + label: "Custom Value 1", |
| 95 | + description: "A custom field for storing additional information", |
| 96 | + optional: true, |
| 97 | + }, |
| 98 | + customValue2: { |
| 99 | + type: "string", |
| 100 | + label: "Custom Value 2", |
| 101 | + description: "A custom field for storing additional information", |
| 102 | + optional: true, |
| 103 | + }, |
| 104 | + customValue3: { |
| 105 | + type: "string", |
| 106 | + label: "Custom Value 3", |
| 107 | + description: "A custom field for storing additional information", |
| 108 | + optional: true, |
| 109 | + }, |
| 110 | + customValue4: { |
| 111 | + type: "string", |
| 112 | + label: "Custom Value 4", |
| 113 | + description: "A custom field for storing additional information", |
99 | 114 | optional: true, |
100 | 115 | }, |
101 | 116 | vatNumber: { |
102 | | - propDefinition: [ |
103 | | - invoice_ninja, |
104 | | - "vatNumber", |
105 | | - ], |
| 117 | + type: "string", |
| 118 | + label: "VAT Number", |
| 119 | + description: "The client's VAT (Value Added Tax) number, if applicable", |
106 | 120 | optional: true, |
107 | 121 | }, |
108 | 122 | idNumber: { |
| 123 | + type: "string", |
| 124 | + label: "ID Number", |
| 125 | + description: "A unique identification number for the client, such as a tax ID or business registration number", |
| 126 | + optional: true, |
| 127 | + }, |
| 128 | + number: { |
| 129 | + type: "string", |
| 130 | + label: "Number", |
| 131 | + description: "A system-assigned unique number for the client, typically used for invoicing purposes", |
| 132 | + optional: true, |
| 133 | + }, |
| 134 | + shippingAddress1: { |
| 135 | + type: "string", |
| 136 | + label: "Shipping Address 1", |
| 137 | + description: "First line of the client's shipping address", |
| 138 | + optional: true, |
| 139 | + }, |
| 140 | + shippingAddress2: { |
| 141 | + type: "string", |
| 142 | + label: "Shipping Address 2", |
| 143 | + description: "Second line of the client's shipping address, if needed", |
| 144 | + optional: true, |
| 145 | + }, |
| 146 | + shippingCity: { |
| 147 | + type: "string", |
| 148 | + label: "Shipping City", |
| 149 | + description: "City of the client's shipping address", |
| 150 | + optional: true, |
| 151 | + }, |
| 152 | + shippingState: { |
| 153 | + type: "string", |
| 154 | + label: "Shipping State", |
| 155 | + description: "State of the client's shipping address", |
| 156 | + optional: true, |
| 157 | + }, |
| 158 | + shippingPostalCode: { |
| 159 | + type: "string", |
| 160 | + label: "Shipping Postal Code", |
| 161 | + description: "Postal code of the client's shipping address", |
| 162 | + optional: true, |
| 163 | + }, |
| 164 | + shippingCountryId: { |
109 | 165 | propDefinition: [ |
110 | | - invoice_ninja, |
111 | | - "idNumber", |
| 166 | + app, |
| 167 | + "countryId", |
112 | 168 | ], |
| 169 | + label: "Shipping Country ID", |
| 170 | + description: "The ID of the country for the client's shipping address", |
113 | 171 | optional: true, |
114 | 172 | }, |
115 | 173 | groupSettingsId: { |
116 | 174 | propDefinition: [ |
117 | | - invoice_ninja, |
| 175 | + app, |
118 | 176 | "groupSettingsId", |
119 | 177 | ], |
120 | 178 | optional: true, |
121 | 179 | }, |
| 180 | + isTaxExempt: { |
| 181 | + type: "boolean", |
| 182 | + label: "Is Tax Exempt", |
| 183 | + description: "Flag which defines if the client is exempt from taxes", |
| 184 | + optional: true, |
| 185 | + }, |
| 186 | + hasValidVatNumber: { |
| 187 | + type: "boolean", |
| 188 | + label: "Has Valid VAT Number", |
| 189 | + description: "Flag which defines if the client has a valid VAT number", |
| 190 | + optional: true, |
| 191 | + }, |
122 | 192 | classification: { |
123 | | - propDefinition: [ |
124 | | - invoice_ninja, |
125 | | - "classification", |
126 | | - ], |
| 193 | + type: "string", |
| 194 | + label: "Classification", |
| 195 | + description: "Classification of the client", |
| 196 | + options: CLASSIFICATION_OPTIONS, |
| 197 | + optional: true, |
| 198 | + }, |
| 199 | + settings: { |
| 200 | + type: "object", |
| 201 | + label: "Settings", |
| 202 | + description: "An array of settings objects in JSON format. **Example: {\"currency_id\": 1, \"timezone_id\": 5, \"date_format_id\": 1, \"language_id\": 1}** [See the documentation](https://api-docs.invoicing.co/#tag/clients/POST/api/v1/clients) for further details", |
127 | 203 | optional: true, |
128 | 204 | }, |
129 | 205 | }, |
130 | 206 | async run({ $ }) { |
131 | | - const client = await this.invoice_ninja.createNewClient({ |
132 | | - contacts: this.contacts.map(JSON.parse), |
133 | | - country_id: this.countryId, |
134 | | - name: this.name, |
135 | | - website: this.website, |
136 | | - private_notes: this.privateNotes, |
137 | | - industry_id: this.industryId, |
138 | | - size_id: this.sizeId, |
139 | | - address1: this.address1, |
140 | | - address2: this.address2, |
141 | | - city: this.city, |
142 | | - state: this.state, |
143 | | - postal_code: this.postalCode, |
144 | | - phone: this.phone, |
145 | | - vat_number: this.vatNumber, |
146 | | - id_number: this.idNumber, |
147 | | - group_settings_id: this.groupSettingsId, |
148 | | - classification: this.classification, |
| 207 | + const { data } = await this.app.createNewClient({ |
| 208 | + $, |
| 209 | + data: { |
| 210 | + contacts: parseObject(this.contacts), |
| 211 | + name: this.name, |
| 212 | + website: this.website, |
| 213 | + private_notes: this.privateNotes, |
| 214 | + industry_id: this.industryId, |
| 215 | + size_id: this.sizeId, |
| 216 | + address1: this.address1, |
| 217 | + address2: this.address2, |
| 218 | + city: this.city, |
| 219 | + state: this.state, |
| 220 | + postal_code: this.postalCode, |
| 221 | + phone: this.phone, |
| 222 | + country_id: this.countryId, |
| 223 | + custom_value1: this.customValue1, |
| 224 | + custom_value2: this.customValue2, |
| 225 | + custom_value3: this.customValue3, |
| 226 | + custom_value4: this.customValue4, |
| 227 | + vat_number: this.vatNumber, |
| 228 | + id_number: this.idNumber, |
| 229 | + number: this.number, |
| 230 | + shipping_address1: this.shippingAddress1, |
| 231 | + shipping_address2: this.shippingAddress2, |
| 232 | + shipping_city: this.shippingCity, |
| 233 | + shipping_state: this.shippingState, |
| 234 | + shipping_postal_code: this.shippingPostalCode, |
| 235 | + shipping_country_id: this.shipping_country_id, |
| 236 | + group_settings_id: this.groupSettingsId, |
| 237 | + is_tax_exempt: this.isTaxExempt, |
| 238 | + has_valid_vat_number: this.hasValidVatNumber, |
| 239 | + classification: this.classification, |
| 240 | + settings: parseObject(this.settings), |
| 241 | + }, |
149 | 242 | }); |
150 | | - $.export("$summary", `Created client ${client.name}`); |
151 | | - return client; |
| 243 | + $.export("$summary", `Created client: ${data.id}`); |
| 244 | + return data; |
152 | 245 | }, |
153 | 246 | }; |
0 commit comments