@prismatic-io/components-karbon 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1664 @@
1
+ let _prismatic_io_spectral = require("@prismatic-io/spectral");
2
+ let _prismatic_io_spectral_http = require("@prismatic-io/spectral/http");
3
+ var connections_default = [(0, _prismatic_io_spectral.connection)({
4
+ key: "karbonApiKey",
5
+ display: {
6
+ label: "API Key",
7
+ description: "API Key connection for Karbon"
8
+ },
9
+ inputs: {
10
+ applicationId: {
11
+ type: "string",
12
+ label: "Application ID",
13
+ comments: "The application ID for the Karbon API. You receive this when you create an application in Karbon.",
14
+ example: "00000000-0000-0000-0000-000000000000",
15
+ required: true
16
+ },
17
+ accessKey: {
18
+ type: "password",
19
+ label: "Access Key",
20
+ comments: "Get this by clicking Settings > Connected Apps > Manage on your app.",
21
+ example: "eyJ.....",
22
+ required: true
23
+ }
24
+ }
25
+ })];
26
+ //#endregion
27
+ //#region src/constants.ts
28
+ const BASE_URL = "https://api.karbonhq.com";
29
+ const SUCCESS_MESSAGE = "Success";
30
+ const POLL_RESOURCE_CONFIG = {
31
+ Contacts: {
32
+ endpoint: "/v3/Contacts",
33
+ timestampField: "LastModifiedDateTime"
34
+ },
35
+ Invoices: {
36
+ endpoint: "/v3/Invoices",
37
+ timestampField: "UpdatedAt"
38
+ }
39
+ };
40
+ const LOOK_BACK_DATE_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
41
+ //#endregion
42
+ //#region src/client.ts
43
+ const createKarbonClient = (connection, debug) => {
44
+ validateConnection(connection);
45
+ const { applicationId, accessKey } = getCredentialsFromConnection(connection);
46
+ return (0, _prismatic_io_spectral_http.createClient)({
47
+ baseUrl: BASE_URL,
48
+ headers: {
49
+ AccessKey: accessKey,
50
+ Authorization: `Bearer ${applicationId}`
51
+ },
52
+ debug
53
+ });
54
+ };
55
+ //#endregion
56
+ //#region src/utils.ts
57
+ const cleanOdata = (obj) => Object.entries(obj).reduce((acc, [currentKey, currentValue]) => {
58
+ if (currentKey.startsWith("@odata.")) return {
59
+ ...acc,
60
+ odata: {
61
+ [currentKey.replace("@odata.", "")]: currentValue,
62
+ ...acc.odata
63
+ }
64
+ };
65
+ else return {
66
+ [currentKey]: currentValue,
67
+ ...acc
68
+ };
69
+ }, {});
70
+ const validateConnection = (connection) => {
71
+ if (!connections_default.map((c) => c.key).includes(connection.key)) throw new _prismatic_io_spectral.ConnectionError(connection, `Unsupported connection ${connection.key}.`);
72
+ };
73
+ const cleanStringInput = (value) => value ? _prismatic_io_spectral.util.types.toString(value) : void 0;
74
+ const cleanCodeInput = (value) => value ? _prismatic_io_spectral.util.types.toObject(value) : void 0;
75
+ const cleanNumberInput = (value) => value ? _prismatic_io_spectral.util.types.toNumber(value) : void 0;
76
+ const getCredentialsFromConnection = (connection) => {
77
+ return {
78
+ applicationId: _prismatic_io_spectral.util.types.toString(connection.fields.applicationId),
79
+ accessKey: _prismatic_io_spectral.util.types.toString(connection.fields.accessKey)
80
+ };
81
+ };
82
+ const getPaginatedData = async ({ client, endpoint, getAllData, pagination: { $top, $skip }, $filter, $orderby }) => {
83
+ if (getAllData) {
84
+ $skip = 0;
85
+ $top = 100;
86
+ } else {
87
+ $skip = $skip || 0;
88
+ $top = $top || 100;
89
+ }
90
+ const { data } = await client.get(endpoint, { params: {
91
+ $top,
92
+ $skip,
93
+ $filter,
94
+ $orderby
95
+ } });
96
+ const originalData = cleanOdata(data);
97
+ originalData.value = originalData.value || [];
98
+ if (!getAllData) return originalData;
99
+ const count = _prismatic_io_spectral.util.types.toNumber(originalData.odata?.count);
100
+ if (count === 0 || count <= 100) return originalData;
101
+ const totalPages = Math.ceil(count / 100);
102
+ const pagePromises = Array.from({ length: totalPages - 1 }, (_, i) => (i + 1) * 100).map((skip) => client.get(endpoint, { params: {
103
+ $top: 100,
104
+ $skip: skip,
105
+ $filter,
106
+ $orderby
107
+ } }));
108
+ const pageResponses = await Promise.all(pagePromises);
109
+ originalData.value = [...originalData.value || [], ...pageResponses.flatMap((response) => response.data.value)];
110
+ return originalData;
111
+ };
112
+ const createWebhook = async (connection, debug, targetUrl, webhookType) => {
113
+ const response = await createKarbonClient(connection, debug).post("/v3/WebhookSubscriptions", {
114
+ TargetUrl: targetUrl,
115
+ WebhookType: webhookType
116
+ });
117
+ return { data: cleanOdata(response.data) };
118
+ };
119
+ const deleteWebhook = async (connection, debug, webhookType) => {
120
+ const { data } = await createKarbonClient(connection, debug).delete(`/v3/WebhookSubscriptions/${webhookType}`);
121
+ return { data };
122
+ };
123
+ const pollResourceModel = Object.keys(POLL_RESOURCE_CONFIG).map((value) => ({
124
+ label: value,
125
+ value
126
+ }));
127
+ const filterRecordsModifiedAfter = (records, timestampField, lastPolledAt) => {
128
+ const lastPolledAtMs = new Date(lastPolledAt).getTime();
129
+ return records.filter((record) => {
130
+ const value = record[timestampField];
131
+ const recordMs = typeof value === "string" ? new Date(value).getTime() : NaN;
132
+ return !Number.isNaN(recordMs) && recordMs > lastPolledAtMs;
133
+ });
134
+ };
135
+ //#endregion
136
+ //#region src/inputs/shared.ts
137
+ const connection = (0, _prismatic_io_spectral.input)({
138
+ label: "Connection",
139
+ type: "connection",
140
+ required: true
141
+ });
142
+ const additionalFields = (0, _prismatic_io_spectral.input)({
143
+ label: "Additional Fields",
144
+ type: "code",
145
+ language: "json",
146
+ comments: "Additional fields that are not covered by the standard inputs.",
147
+ required: false,
148
+ example: JSON.stringify({}, null, 2),
149
+ clean: cleanCodeInput
150
+ });
151
+ const $top = (0, _prismatic_io_spectral.input)({
152
+ label: "Top",
153
+ type: "string",
154
+ comments: "The number of records to return at once.",
155
+ required: false,
156
+ example: "50",
157
+ placeholder: "50",
158
+ clean: cleanNumberInput
159
+ });
160
+ const $filter = (0, _prismatic_io_spectral.input)({
161
+ label: "Filter",
162
+ type: "string",
163
+ comments: "A filter expression to apply to the results.",
164
+ example: "FullName eq 'Sample Management Team'",
165
+ placeholder: "FullName eq 'Sample Management Team'",
166
+ required: false,
167
+ clean: cleanStringInput
168
+ });
169
+ const $orderby = (0, _prismatic_io_spectral.input)({
170
+ label: "Order By",
171
+ type: "string",
172
+ comments: "The property to order the results by.",
173
+ example: "FullName",
174
+ placeholder: "",
175
+ required: false,
176
+ clean: cleanStringInput
177
+ });
178
+ const $skip = (0, _prismatic_io_spectral.input)({
179
+ label: "Skip",
180
+ type: "string",
181
+ comments: "The number of records to skip when looping over pages of results. If you fetch 100 results, you should skip 0 the first iteration, then 100, 200, 300, etc. until no more records are available.",
182
+ example: "100",
183
+ placeholder: "100",
184
+ required: false,
185
+ clean: cleanNumberInput
186
+ });
187
+ const getAllData = (0, _prismatic_io_spectral.input)({
188
+ label: "Get All Data",
189
+ type: "boolean",
190
+ comments: "Turn this on to retrieve all pages of data. $top and $skip will be ignored.",
191
+ required: false,
192
+ default: "false",
193
+ clean: _prismatic_io_spectral.util.types.toBool
194
+ });
195
+ const webhookType = (0, _prismatic_io_spectral.input)({
196
+ label: "Webhook Type",
197
+ type: "string",
198
+ model: [
199
+ "Contact",
200
+ "Work",
201
+ "Note",
202
+ "User",
203
+ "Invoice"
204
+ ].map((value) => ({
205
+ value,
206
+ label: value
207
+ })),
208
+ comments: "The type of the Webhook.",
209
+ required: true,
210
+ example: "Contact",
211
+ clean: cleanStringInput
212
+ });
213
+ //#endregion
214
+ //#region src/inputs/contacts/shared.ts
215
+ const contactkey = (0, _prismatic_io_spectral.input)({
216
+ label: "Contactkey",
217
+ comments: "The Contact key.",
218
+ type: "string",
219
+ required: true,
220
+ clean: cleanStringInput,
221
+ example: "4jgPTtcXxwC2",
222
+ placeholder: "4jgPTtcXxwC2",
223
+ dataSource: "selectContact"
224
+ });
225
+ const firstName = (0, _prismatic_io_spectral.input)({
226
+ label: "Contact's First Name",
227
+ comments: "The first name of the Contact.",
228
+ type: "string",
229
+ required: true,
230
+ clean: cleanStringInput,
231
+ example: "John",
232
+ placeholder: "John"
233
+ });
234
+ const lastName = (0, _prismatic_io_spectral.input)({
235
+ label: "Contact's Last Name",
236
+ comments: "The last name of the Contact.",
237
+ type: "string",
238
+ required: true,
239
+ clean: cleanStringInput,
240
+ example: "Doe",
241
+ placeholder: "Doe"
242
+ });
243
+ //#endregion
244
+ //#region src/inputs/contacts/createContact.ts
245
+ const DOCUMENTATION_COMMENTS$4 = `See [Karbon API documentation](https://karbonhq.github.io/karbon-api-reference/#post-/v3/Contacts) for more information.`;
246
+ var createContact_default = {
247
+ connection,
248
+ firstName,
249
+ lastName,
250
+ additionalFields: (0, _prismatic_io_spectral.input)({
251
+ ...additionalFields,
252
+ example: JSON.stringify({
253
+ Salutation: "Mr",
254
+ Suffix: "Jr.",
255
+ RestrictionLevel: "Public",
256
+ UserDefinedIdentifier: "BILLJR-001",
257
+ BusinessCards: [{
258
+ IsPrimaryCard: true,
259
+ OrganizationKey: "7NN1ySxv89B",
260
+ WebSites: ["www.website.one", "www.website.two"],
261
+ EmailAddresses: ["sample@example.com", "sample.two@example.com"],
262
+ RoleOrTitle: "COO",
263
+ FacebookLink: "facebook.com/sampleName",
264
+ LinkedInLink: "linkedin.com/sampleName",
265
+ TwitterLink: "twitter.com/sampleName",
266
+ SkypeLink: "skype.com/sampleName",
267
+ Addresses: [{
268
+ AddressLines: "45 Sample Street",
269
+ City: "Alexandria",
270
+ StateProvinceCounty: "NSW",
271
+ ZipCode: 2015,
272
+ CountryCode: "AU",
273
+ Label: "Physical"
274
+ }],
275
+ PhoneNumbers: [{
276
+ Number: 1234567890,
277
+ CountryCode: 61,
278
+ Label: "Work"
279
+ }]
280
+ }]
281
+ }, null, 2),
282
+ comments: `${additionalFields.comments} ${DOCUMENTATION_COMMENTS$4}`
283
+ })
284
+ };
285
+ //#endregion
286
+ //#region src/examplePayloads.ts
287
+ const createContactExamplePayload = { data: {
288
+ odata: {
289
+ context: "https://api.karbonhq.com/v3/$metadata#Contacts/KarbonService.ContactDTO/$entity",
290
+ type: "#KarbonService.ContactDTO"
291
+ },
292
+ ContactKey: "67zlxNyJSr8e",
293
+ FirstName: "William",
294
+ MiddleName: "John",
295
+ LastName: "Connor",
296
+ PreferredName: "Bill",
297
+ Salutation: "Mr",
298
+ Suffix: "Jr.",
299
+ ClientOwner: "rodney.muller@samplecompany.com",
300
+ ClientManager: "jessica.tse@samplecompany.com",
301
+ ContactType: "Client",
302
+ UserDefinedIdentifier: "BILLJR",
303
+ RestrictionLevel: "Public",
304
+ AvatarUrl: "https://az.karbonemail.com/images/e4ae96c1-8d17-4c6e-af8a-8040482176fc",
305
+ LastModifiedDateTime: "2022-07-05T07:30:13.7188114Z",
306
+ EntityDescription: { Text: "Birthday on June 23." },
307
+ AccountingDetail: {
308
+ ContactPermaKey: "4XHEn8T3J4Y6",
309
+ OrganizationPermaKey: null,
310
+ BirthDate: "1969-08-05T00:00:00Z",
311
+ DeathDate: null,
312
+ Salutation: "Mr",
313
+ Sex: "M",
314
+ FinancialYearEndDay: 8,
315
+ FinancialYearEndMonth: 30,
316
+ IncorporationDate: null,
317
+ IncorporationState: null,
318
+ LegalName: null,
319
+ LineOfBusiness: null,
320
+ EntityType: null,
321
+ TaxCountryCode: "US",
322
+ TradingName: null,
323
+ AnnualRevenue: null,
324
+ BaseCurrency: null,
325
+ GstBasis: null,
326
+ GstPeriod: null,
327
+ IncomeTaxInstallmentPeriod: "Yearly",
328
+ IsVATRegistered: null,
329
+ OrganizationValuation: null,
330
+ PaysTax: null,
331
+ PrepareGST: null,
332
+ ProvisionaTaxBasic: null,
333
+ ProvisionalTaxRatio: null,
334
+ RevenueModel: null,
335
+ SalesTaxBasis: null,
336
+ SalesTaxPeriod: null,
337
+ Sells: null,
338
+ RegistrationNumbers: {
339
+ RegistrationNumber: "12-3456789",
340
+ Type: "Social Security Number (SSN)"
341
+ },
342
+ Notes: {
343
+ Body: "This is a sample note text.",
344
+ Type: "Basic"
345
+ }
346
+ },
347
+ BusinessCards: {
348
+ BusinessCardKey: "2tBHyXtJBxBy",
349
+ IsPrimaryCard: true,
350
+ WebSites: ["www.website.one", "www.website.two"],
351
+ EmailAddresses: ["sample@example.com", "sample.two@example.com"],
352
+ OrganizationKey: "ZGNmtYyLm4z",
353
+ RoleOrTitle: "COO",
354
+ FacebookLink: "facebook.com/sampleName",
355
+ LinkedInLink: "linkedin.com/sampleName",
356
+ TwitterLink: "twitter.com/sampleName",
357
+ SkypeLink: "skype.com/sampleName",
358
+ Addresses: {
359
+ AddressKey: "e150a05a-2dea-4292-8bc8-03398c9384e4",
360
+ AddressLines: "45 Sample Street",
361
+ City: "Alexandria",
362
+ StateProvinceCounty: "NSW",
363
+ ZipCode: "2015",
364
+ CountryCode: "AU",
365
+ Label: "Physical"
366
+ },
367
+ PhoneNumbers: {
368
+ PhoneNumberKey: "6e0b9ace-24b1-4328-a922-3b8be5ef5052",
369
+ Number: 1234567890,
370
+ CountryCode: 61,
371
+ Label: "Work"
372
+ }
373
+ }
374
+ } };
375
+ const listContactsExamplePayload = { data: {
376
+ odata: {
377
+ context: "https://api.karbonhq.com/v3/$metadata#Contacts/KarbonService.ContactSummaryDTO",
378
+ count: 323
379
+ },
380
+ value: [{
381
+ "@odata.type": "#KarbonService.ContactSummaryDTO",
382
+ ContactKey: "29YXnqWcqCf3",
383
+ FullName: "William John Connor",
384
+ PreferredName: "Bill",
385
+ Salutation: "Mr",
386
+ ClientOwner: "rodney.muller@samplecompany.com",
387
+ ClientManager: "jessica.tse@samplecompany.com",
388
+ Address: "42 Galaxy Way, London",
389
+ EmailAddress: "william.connor@samplecompany.com",
390
+ PhoneNumber: "0987888686",
391
+ RoleOrTitle: "COO",
392
+ UserDefinedIdentifier: "73YEnqFcqCf3",
393
+ LastModifiedDateTime: "2021-12-29T07:01:53Z"
394
+ }]
395
+ } };
396
+ listContactsExamplePayload.data.value;
397
+ const getInvoiceExamplePayload = { data: {
398
+ odata: { context: "https://api.karbonhq.com/v3/$metadata#Invoices/$entity" },
399
+ InvoiceKey: "M2dVbCt4RHk",
400
+ InvoiceNumber: "KIN-1001",
401
+ TotalAmountDue: 1607.13,
402
+ InvoiceTotal: 1607.13,
403
+ InvoiceSubTotal: 1397.5,
404
+ InvoiceTaxTotal: 209.63,
405
+ InvoiceDate: "2023-07-21T00:00:00Z",
406
+ PaymentDueDate: "2023-07-28T00:00:00Z",
407
+ UpdatedAt: "2023-07-20T23:52:11Z",
408
+ CurrencyCode: "AUD",
409
+ PaymentInstructions: "Payment due 7 days from invoice date",
410
+ InvoiceStatus: "AwaitingPayment",
411
+ Client: {
412
+ ClientKey: "2xxnBLyCP4Ts",
413
+ ClientType: "Organization",
414
+ Name: "Acme Corp",
415
+ AddressLine: "15 Example Street",
416
+ City: "Sydney",
417
+ StateProvinceCounty: "NSW",
418
+ ZipCode: "4004",
419
+ Country: "Australia",
420
+ EmailAddress: "acme@example.com"
421
+ },
422
+ TaxLineItems: [{
423
+ TaxName: "GST",
424
+ TaxValue: 209.63
425
+ }]
426
+ } };
427
+ const listInvoicesExamplePayload = { data: {
428
+ odata: {
429
+ context: "https://api.karbonhq.com/v3/$metadata#Invoices(LineItems())",
430
+ count: 1
431
+ },
432
+ value: [{
433
+ InvoiceKey: "2F8bb4Xk4N1T",
434
+ InvoiceNumber: "KIN-1000",
435
+ TotalAmountDue: 5,
436
+ InvoiceTotal: 5,
437
+ InvoiceSubTotal: 5,
438
+ InvoiceTaxTotal: 0,
439
+ InvoiceDate: "2024-05-23T00:00:00Z",
440
+ PaymentDueDate: "2024-05-30T00:00:00Z",
441
+ UpdatedAt: "2024-05-23T16:44:29Z",
442
+ CurrencyCode: "USD",
443
+ PaymentInstructions: null,
444
+ InvoiceStatus: "Approved",
445
+ Client: {
446
+ ClientKey: "4hFn8Czrnw4v",
447
+ ClientType: "Organization",
448
+ Name: "Example Sandbox",
449
+ AddressLine: null,
450
+ City: null,
451
+ StateProvinceCounty: null,
452
+ ZipCode: null,
453
+ Country: null,
454
+ EmailAddress: null
455
+ },
456
+ TaxLineItems: [],
457
+ LineItems: [{
458
+ LineItemKey: "3aebacb913b44aaa81b1cb2acf958b1b",
459
+ BillableItemEntityKey: "2SFw2p31285T",
460
+ BillableItemType: "Expense",
461
+ Description: "My Services",
462
+ Quantity: 1,
463
+ UnitPrice: 5,
464
+ Amount: 5,
465
+ TaxRate: 0,
466
+ TaxRateName: "No Tax Set"
467
+ }]
468
+ }]
469
+ } };
470
+ const createUserExamplePayload = { data: {
471
+ odata: { context: "https://api.karbonhq.com/v3/$metadata#Users/$entity" },
472
+ Id: "4LR9qmR5NQ6T",
473
+ Name: "Joe Min",
474
+ EmailAddress: "joe@samplecompany.com"
475
+ } };
476
+ const listWorkItemsExamplePayload = { data: {
477
+ value: [{
478
+ "@odata.type": "#KarbonService.WorkItemSummaryDTO",
479
+ WorkItemKey: "2LPSrkzbYrn4",
480
+ AssigneeEmailAddress: "joe@samplecompany.com",
481
+ AssigneeKey: "4gHCvnbFFqsq",
482
+ AssigneeName: "Joe Min",
483
+ Title: "Payroll 31 Aug - 15 Sep 2022",
484
+ ClientKey: "4ncPZ7q96SGc",
485
+ ClientName: "Acme Corporation",
486
+ ClientType: "Organization",
487
+ ClientUserDefinedIdentifier: "ACMECORP",
488
+ RelatedClientGroupKey: "3LCPr987gNrc",
489
+ ClientGroupKey: "3LCPr987gNrc",
490
+ RelatedClientGroupName: "Smith Family Group",
491
+ StartDate: "2021-12-29T00:00:00Z",
492
+ DueDate: "2022-01-30T00:00:00Z",
493
+ DeadlineDate: "2022-01-31T00:00:00Z",
494
+ CompletedDate: "2022-02-01T00:00:00Z",
495
+ ToDoPeriod: "2021-12-29T00:00:00Z",
496
+ WorkType: "Payroll",
497
+ WorkStatus: "Ready To Start - Send client requests",
498
+ PrimaryStatus: "Ready To Start",
499
+ SecondaryStatus: "Send client requests",
500
+ WorkTemplateKey: "p56mtcBhwb9",
501
+ WorkTemplateTile: "Payroll processing",
502
+ WorkScheduleKey: "4f3gHnLC323"
503
+ }],
504
+ odata: {
505
+ count: 323,
506
+ context: "https://api.karbonhq.com/v3/$metadata#WorkItems/KarbonService.WorkItemSummaryDTO",
507
+ nextLink: "https://api.karbonhq.com/v3/WorkItems?$skip=100"
508
+ }
509
+ } };
510
+ const getContactExamplePayload = { data: {
511
+ odata: {
512
+ context: "https://api.karbonhq.com/v3/$metadata#Contacts/KarbonService.ContactDTO/$entity",
513
+ type: "#KarbonService.ContactDTO"
514
+ },
515
+ ContactKey: "67zlxNyJSr8e",
516
+ FirstName: "William",
517
+ MiddleName: "John",
518
+ LastName: "Connor",
519
+ PreferredName: "Bill",
520
+ Salutation: "Mr",
521
+ Suffix: "Jr.",
522
+ ClientOwner: "rodney.muller@samplecompany.com",
523
+ ClientManager: "jessica.tse@samplecompany.com",
524
+ ContactType: "Client",
525
+ UserDefinedIdentifier: "BILLJR",
526
+ RestrictionLevel: "Public",
527
+ AvatarUrl: "https://az.karbonemail.com/images/e4ae96c1-8d17-4c6e-af8a-8040482176fc",
528
+ LastModifiedDateTime: "2022-07-05T07:30:13.7188114Z",
529
+ EntityDescription: { Text: "Birthday on June 23." },
530
+ AccountingDetail: {
531
+ ContactPermaKey: "4XHEn8T3J4Y6",
532
+ OrganizationPermaKey: null,
533
+ BirthDate: "1969-08-05T00:00:00Z",
534
+ DeathDate: null,
535
+ Salutation: "Mr",
536
+ Sex: "M",
537
+ FinancialYearEndDay: 8,
538
+ FinancialYearEndMonth: 30,
539
+ IncorporationDate: null,
540
+ IncorporationState: null,
541
+ LegalName: null,
542
+ LineOfBusiness: null,
543
+ EntityType: null,
544
+ TaxCountryCode: "US",
545
+ TradingName: null,
546
+ AnnualRevenue: null,
547
+ BaseCurrency: null,
548
+ GstBasis: null,
549
+ GstPeriod: null,
550
+ IncomeTaxInstallmentPeriod: "Quaterly",
551
+ IsVATRegistered: null,
552
+ OrganizationValuation: null,
553
+ PaysTax: null,
554
+ PrepareGST: null,
555
+ ProvisionaTaxBasic: null,
556
+ ProvisionalTaxRatio: null,
557
+ RevenueModel: null,
558
+ SalesTaxBasis: null,
559
+ SalesTaxPeriod: null,
560
+ Sells: null,
561
+ RegistrationNumbers: {
562
+ RegistrationNumber: "12-3456789",
563
+ Type: "Social Security Number (SSN)"
564
+ },
565
+ Notes: {
566
+ Body: "This is a sample note text.",
567
+ Type: "Basic"
568
+ }
569
+ },
570
+ BusinessCards: {
571
+ BusinessCardKey: "2tBHyXtJBxBy",
572
+ EntityType: "Contact",
573
+ EntityKey: "67zlxNyJSr8e",
574
+ IsPrimaryCard: true,
575
+ WebSites: ["www.website.one", "www.website.two"],
576
+ EmailAddresses: ["sample@example.com", "sample.two@example.com"],
577
+ OrganizationKey: "ZGNmtYyLm4z",
578
+ RoleOrTitle: "COO",
579
+ FacebookLink: "facebook.com/sampleName",
580
+ LinkedInLink: "linkedin.com/sampleName",
581
+ TwitterLink: "twitter.com/sampleName",
582
+ SkypeLink: "skype.com/sampleName",
583
+ Addresses: {
584
+ AddressKey: "e150a05a-2dea-4292-8bc8-03398c9384e4",
585
+ AddressLines: "45 Sample Street",
586
+ City: "Alexandria",
587
+ StateProvinceCounty: "NSW",
588
+ ZipCode: "2015",
589
+ CountryCode: "AU",
590
+ Label: "Physical"
591
+ },
592
+ PhoneNumbers: {
593
+ PhoneNumberKey: "6e0b9ace-24b1-4328-a922-3b8be5ef5052",
594
+ Number: 1234567890,
595
+ CountryCode: 61,
596
+ Label: "Work"
597
+ }
598
+ }
599
+ } };
600
+ const updateContactExamplePayload = { data: SUCCESS_MESSAGE };
601
+ const listUsersExamplePayload = { data: {
602
+ odata: {
603
+ context: "https://api.karbonhq.com/v3/$metadata#Users",
604
+ count: 1,
605
+ nextLink: "https://api.karbonhq.com/v3/Users?$skip=100"
606
+ },
607
+ value: [{
608
+ Id: "4LR9qmR5NQ6T",
609
+ Name: "Joe Min",
610
+ EmailAddress: "joe@samplecompany.com"
611
+ }]
612
+ } };
613
+ const getUserExamplePayload = { data: {
614
+ odata: {
615
+ context: "https://api.karbonhq.com/v3/$metadata#Users/KarbonService.UserProfileDTO/$entity",
616
+ type: "#KarbonService.UserProfileDTO"
617
+ },
618
+ Id: "2bYxtn94ZSdY",
619
+ Name: "Janet Smith",
620
+ EmailAddress: "janet@example.com",
621
+ BillableRate: 0,
622
+ CapacityMinutesPerWeek: 2400,
623
+ Permissions: ["User"],
624
+ Roles: ["Accountant", "Bookkeeper"],
625
+ Teams: ["Accountants", "Bookkeepers"]
626
+ } };
627
+ const createWorkItemExamplePayload = { data: {
628
+ odata: {
629
+ context: "https://api.karbonhq.com/v3/$metadata#WorkItems/KarbonService.WorkItemDTO/$entity",
630
+ type: "#KarbonService.WorkItemDTO"
631
+ },
632
+ WorkItemKey: "2LPSrkzbYrn4",
633
+ AssigneeEmailAddress: "joe@samplecompany.com",
634
+ AssigneeKey: "4gHCvnbFFqsq",
635
+ AssigneeName: "Joe Min",
636
+ Title: "Payroll 31 Aug - 15 Sep 2022",
637
+ ClientKey: "4ncPZ7q96SGc",
638
+ ClientName: "Acme Corporation",
639
+ ClientType: "Organization",
640
+ ClientUserDefinedIdentifier: "ACMECORP",
641
+ RelatedClientGroupKey: "3LCPr987gNrc",
642
+ ClientGroupKey: "3LCPr987gNrc",
643
+ RelatedClientGroupName: "Smith Family Group",
644
+ StartDate: "2021-12-29T00:00:00Z",
645
+ DueDate: "2022-01-30T00:00:00Z",
646
+ DeadlineDate: "2022-01-31T00:00:00Z",
647
+ CompletedDate: "2022-02-01T00:00:00Z",
648
+ ToDoPeriod: "2021-12-29T00:00:00Z",
649
+ WorkType: "Payroll",
650
+ WorkStatus: "Ready To Start - Send client requests",
651
+ PrimaryStatus: "Ready To Start",
652
+ SecondaryStatus: "Send client requests",
653
+ WorkTemplateKey: "p56mtcBhwb9",
654
+ WorkTemplateTile: "Payroll processing",
655
+ WorkScheduleKey: "4f3gHnLC323",
656
+ FeeSettings: {
657
+ FeeType: "FixedFee",
658
+ FeeValue: 5150.2
659
+ },
660
+ Description: "Send to Jo for review",
661
+ ClientTaskRecipient: null
662
+ } };
663
+ const getWorkItemExamplePayload = { data: {
664
+ odata: {
665
+ context: "https://api.karbonhq.com/v3/$metadata#WorkItems/KarbonService.WorkItemDTO/$entity",
666
+ type: "#KarbonService.WorkItemDTO"
667
+ },
668
+ WorkItemKey: "2LPSrkzbYrn4",
669
+ AssigneeEmailAddress: "joe@samplecompany.com",
670
+ AssigneeKey: "4gHCvnbFFqsq",
671
+ AssigneeName: "Joe Min",
672
+ Title: "Payroll 31 Aug - 15 Sep 2022",
673
+ ClientKey: "4ncPZ7q96SGc",
674
+ ClientName: "Acme Corporation",
675
+ ClientType: "Organization",
676
+ ClientUserDefinedIdentifier: "ACMECORP",
677
+ RelatedClientGroupKey: "3LCPr987gNrc",
678
+ ClientGroupKey: "3LCPr987gNrc",
679
+ RelatedClientGroupName: "Smith Family Group",
680
+ StartDate: "2021-12-29T00:00:00Z",
681
+ DueDate: "2022-01-30T00:00:00Z",
682
+ DeadlineDate: "2022-01-31T00:00:00Z",
683
+ CompletedDate: "2022-02-01T00:00:00Z",
684
+ ToDoPeriod: "2021-12-29T00:00:00Z",
685
+ WorkType: "Payroll",
686
+ WorkStatus: "Ready To Start - Send client requests",
687
+ PrimaryStatus: "Ready To Start",
688
+ SecondaryStatus: "Send client requests",
689
+ WorkTemplateKey: "p56mtcBhwb9",
690
+ WorkTemplateTile: "Payroll processing",
691
+ WorkScheduleKey: "4f3gHnLC323",
692
+ FeeSettings: {
693
+ FeeType: "FixedFee",
694
+ FeeValue: 5150.2
695
+ },
696
+ Description: "Send to Jo for review",
697
+ ClientTaskRecipient: null
698
+ } };
699
+ const updateWorkItemExamplePayload = { data: SUCCESS_MESSAGE };
700
+ const deleteAllWebhookSubscriptionsExamplePayload = { data: SUCCESS_MESSAGE };
701
+ const getWebhookExamplePayload = { data: {
702
+ odata: { context: "https://api.karbonhq.com/v3/$metadata#WebhookSubscriptions/$entity" },
703
+ TargetUrl: "https://evelyn.info/hooks/catch/3550924/ovsbqn4/",
704
+ WebhookType: "Contact"
705
+ } };
706
+ //#endregion
707
+ //#region src/actions/contacts/createContact.ts
708
+ const createContact = (0, _prismatic_io_spectral.action)({
709
+ display: {
710
+ label: "Create a Contact",
711
+ description: "Create a new contact"
712
+ },
713
+ inputs: { ...createContact_default },
714
+ perform: async (context, { connection, firstName, lastName, additionalFields }) => {
715
+ return { data: cleanOdata((await createKarbonClient(connection, context.debug.enabled).post("/v3/Contacts", {
716
+ FirstName: firstName,
717
+ LastName: lastName,
718
+ ...additionalFields || {}
719
+ })).data) };
720
+ },
721
+ examplePayload: createContactExamplePayload
722
+ });
723
+ //#endregion
724
+ //#region src/inputs/contacts/listContacts.ts
725
+ const DOCUMENTATION_COMMENTS$3 = `See [Karbon API documentation](https://karbonhq.github.io/karbon-api-reference/#get-/v3/Contacts) for more information.`;
726
+ var listContacts_default = {
727
+ connection,
728
+ $filter: (0, _prismatic_io_spectral.input)({
729
+ ...$filter,
730
+ comments: `${$filter.comments} ${DOCUMENTATION_COMMENTS$3}`
731
+ }),
732
+ $top,
733
+ $skip,
734
+ $orderby: (0, _prismatic_io_spectral.input)({
735
+ ...$orderby,
736
+ model: [
737
+ {
738
+ value: "FullName",
739
+ label: "Full Name"
740
+ },
741
+ {
742
+ value: "FullName desc",
743
+ label: "Full Name Descending"
744
+ },
745
+ {
746
+ value: "LastModifiedDateTime",
747
+ label: "Last Modified Date Time"
748
+ },
749
+ {
750
+ value: "LastModifiedDateTime desc",
751
+ label: "Last Modified Date Time Descending"
752
+ }
753
+ ]
754
+ }),
755
+ getAllData
756
+ };
757
+ //#endregion
758
+ //#region src/actions/contacts/listContacts.ts
759
+ const listContacts = (0, _prismatic_io_spectral.action)({
760
+ display: {
761
+ label: "List Contacts",
762
+ description: "List all Contacts"
763
+ },
764
+ inputs: { ...listContacts_default },
765
+ perform: async (context, { connection, $filter, $top, $skip, $orderby, getAllData }) => {
766
+ const client = createKarbonClient(connection, context.debug.enabled);
767
+ return { data: await getPaginatedData({
768
+ pagination: {
769
+ $top,
770
+ $skip
771
+ },
772
+ client,
773
+ endpoint: "/v3/Contacts",
774
+ getAllData,
775
+ $orderby,
776
+ $filter
777
+ }) };
778
+ },
779
+ examplePayload: listContactsExamplePayload
780
+ });
781
+ //#endregion
782
+ //#region src/inputs/contacts/getContact.ts
783
+ const expandBusinessCards = (0, _prismatic_io_spectral.input)({
784
+ label: "Expand Business Cards",
785
+ comments: "Whether to return the Business Card associated with the Contact.",
786
+ type: "boolean",
787
+ required: false,
788
+ default: "false",
789
+ clean: _prismatic_io_spectral.util.types.toBool
790
+ });
791
+ var getContact_default = {
792
+ connection,
793
+ contactkey: (0, _prismatic_io_spectral.input)({
794
+ ...contactkey,
795
+ comments: `${contactkey.comments} to get the Contact for.`
796
+ }),
797
+ expandBusinessCards
798
+ };
799
+ //#endregion
800
+ //#region src/actions/contacts/getContact.ts
801
+ const getContact = (0, _prismatic_io_spectral.action)({
802
+ display: {
803
+ label: "Get Contact",
804
+ description: "Get a single Contact by Contact key"
805
+ },
806
+ inputs: { ...getContact_default },
807
+ perform: async (context, { connection, contactkey, expandBusinessCards }) => {
808
+ return { data: cleanOdata((await createKarbonClient(connection, context.debug.enabled).get(`/v3/Contacts/${contactkey}`, { params: { $expand: expandBusinessCards ? "BusinessCards" : void 0 } })).data) };
809
+ },
810
+ examplePayload: getContactExamplePayload
811
+ });
812
+ //#endregion
813
+ //#region src/inputs/contacts/updateContact.ts
814
+ const middleName = (0, _prismatic_io_spectral.input)({
815
+ label: "Contact's Middle Name",
816
+ comments: "The middle name of the Contact.",
817
+ type: "string",
818
+ required: false,
819
+ clean: cleanStringInput,
820
+ example: "John",
821
+ placeholder: "John"
822
+ });
823
+ const preferredName = (0, _prismatic_io_spectral.input)({
824
+ label: "Contact's Preferred Name",
825
+ comments: "The preferred name of the Contact.",
826
+ type: "string",
827
+ required: false,
828
+ clean: cleanStringInput,
829
+ example: "John",
830
+ placeholder: "John"
831
+ });
832
+ const salutation = (0, _prismatic_io_spectral.input)({
833
+ label: "Contact's Salutation",
834
+ comments: "The title to address the Contact.",
835
+ type: "string",
836
+ required: false,
837
+ clean: cleanStringInput,
838
+ example: "Mr",
839
+ placeholder: "Mr"
840
+ });
841
+ const suffix = (0, _prismatic_io_spectral.input)({
842
+ label: "Contact's Suffix",
843
+ comments: "The suffix of the Contact.",
844
+ type: "string",
845
+ required: false,
846
+ clean: cleanStringInput,
847
+ example: "Jr.",
848
+ placeholder: "Jr."
849
+ });
850
+ var updateContact_default = {
851
+ connection,
852
+ contactkey: (0, _prismatic_io_spectral.input)({
853
+ ...contactkey,
854
+ comments: `${contactkey.comments} to update the Contact for.`
855
+ }),
856
+ firstName: (0, _prismatic_io_spectral.input)({
857
+ ...firstName,
858
+ required: false
859
+ }),
860
+ lastName: (0, _prismatic_io_spectral.input)({
861
+ ...lastName,
862
+ required: false
863
+ }),
864
+ middleName,
865
+ preferredName,
866
+ salutation,
867
+ suffix
868
+ };
869
+ //#endregion
870
+ //#region src/actions/contacts/index.ts
871
+ var contacts_default = {
872
+ listContacts,
873
+ createContact,
874
+ getContact,
875
+ updateContact: (0, _prismatic_io_spectral.action)({
876
+ display: {
877
+ label: "Update a Contact",
878
+ description: "Partially update a contact by Contact key"
879
+ },
880
+ inputs: { ...updateContact_default },
881
+ perform: async (context, { connection, contactkey, firstName, lastName, middleName, preferredName, salutation, suffix }) => {
882
+ await createKarbonClient(connection, context.debug.enabled).patch(`/v3/Contacts/${contactkey}`, {
883
+ FirstName: firstName,
884
+ MiddleName: middleName,
885
+ LastName: lastName,
886
+ PreferredName: preferredName,
887
+ Salutation: salutation,
888
+ Suffix: suffix
889
+ });
890
+ return { data: SUCCESS_MESSAGE };
891
+ },
892
+ examplePayload: updateContactExamplePayload
893
+ })
894
+ };
895
+ //#endregion
896
+ //#region src/inputs/invoices/shared.ts
897
+ const includeLineItems = (0, _prismatic_io_spectral.input)({
898
+ label: "Include Line Items",
899
+ type: "boolean",
900
+ required: false,
901
+ default: "false",
902
+ comments: "Include additional lineitems invoice properties.",
903
+ clean: _prismatic_io_spectral.util.types.toBool
904
+ });
905
+ var getInvoice_default = {
906
+ connection,
907
+ invoiceKey: (0, _prismatic_io_spectral.input)({
908
+ label: "Invoice Key",
909
+ type: "string",
910
+ required: true,
911
+ example: "M2dVbCt4RHk",
912
+ placeholder: "M2dVbCt4RHk",
913
+ comments: "The Invoice key to get the Invoice for.",
914
+ clean: cleanStringInput,
915
+ dataSource: "selectInvoice"
916
+ }),
917
+ includeLineItems
918
+ };
919
+ //#endregion
920
+ //#region src/actions/invoices/getInvoice.ts
921
+ const getInvoice = (0, _prismatic_io_spectral.action)({
922
+ display: {
923
+ label: "Get Invoice",
924
+ description: "Get an invoice by key"
925
+ },
926
+ inputs: { ...getInvoice_default },
927
+ perform: async (context, { connection, invoiceKey, includeLineItems }) => {
928
+ return { data: cleanOdata((await createKarbonClient(connection, context.debug.enabled).get(`/v3/Invoices/${invoiceKey}`, { params: { $expand: includeLineItems ? "LineItems" : void 0 } })).data) };
929
+ },
930
+ examplePayload: getInvoiceExamplePayload
931
+ });
932
+ //#endregion
933
+ //#region src/inputs/invoices/listInvoices.ts
934
+ var listInvoices_default = {
935
+ connection,
936
+ includeLineItems,
937
+ $orderby: (0, _prismatic_io_spectral.input)({
938
+ ...$orderby,
939
+ model: [
940
+ {
941
+ value: "InvoiceDate",
942
+ label: "Invoice Date"
943
+ },
944
+ {
945
+ value: "InvoiceDate asc",
946
+ label: "Invoice Date asc"
947
+ },
948
+ {
949
+ value: "InvoiceDate desc",
950
+ label: "Invoice Date desc"
951
+ }
952
+ ]
953
+ })
954
+ };
955
+ //#endregion
956
+ //#region src/actions/invoices/index.ts
957
+ var invoices_default = {
958
+ getInvoice,
959
+ listInvoices: (0, _prismatic_io_spectral.action)({
960
+ display: {
961
+ label: "List Invoices",
962
+ description: "List invoices"
963
+ },
964
+ inputs: { ...listInvoices_default },
965
+ perform: async (context, { connection, includeLineItems, $orderby }) => {
966
+ return { data: cleanOdata((await createKarbonClient(connection, context.debug.enabled).get("/v3/Invoices", { params: {
967
+ $expand: includeLineItems ? "LineItems" : void 0,
968
+ $orderby
969
+ } })).data) };
970
+ },
971
+ examplePayload: listInvoicesExamplePayload
972
+ })
973
+ };
974
+ var createUser_default = {
975
+ connection,
976
+ userName: (0, _prismatic_io_spectral.input)({
977
+ label: "User's Name",
978
+ type: "string",
979
+ comments: "The name of the User.",
980
+ required: true,
981
+ clean: cleanStringInput,
982
+ example: "John Doe",
983
+ placeholder: "John Doe"
984
+ }),
985
+ userEmail: (0, _prismatic_io_spectral.input)({
986
+ label: "User's Email",
987
+ type: "string",
988
+ comments: "The email of the User.",
989
+ required: true,
990
+ clean: cleanStringInput,
991
+ example: "example@email.com",
992
+ placeholder: "example@email.com"
993
+ })
994
+ };
995
+ //#endregion
996
+ //#region src/actions/users/createUser.ts
997
+ const createUser = (0, _prismatic_io_spectral.action)({
998
+ display: {
999
+ label: "Create User",
1000
+ description: "Create a new user"
1001
+ },
1002
+ inputs: { ...createUser_default },
1003
+ perform: async (context, { connection, userName, userEmail }) => {
1004
+ return { data: cleanOdata((await createKarbonClient(connection, context.debug.enabled).post("/v3/Users", {
1005
+ Name: userName,
1006
+ EmailAddress: userEmail
1007
+ })).data) };
1008
+ },
1009
+ examplePayload: createUserExamplePayload
1010
+ });
1011
+ var getUser_default = {
1012
+ connection,
1013
+ userId: (0, _prismatic_io_spectral.input)({
1014
+ label: "User ID",
1015
+ type: "string",
1016
+ comments: "The unique ID of the User to get.",
1017
+ required: true,
1018
+ clean: cleanStringInput,
1019
+ example: "2bYxtn94ZSdY",
1020
+ placeholder: "2bYxtn94ZSdY",
1021
+ dataSource: "selectUser"
1022
+ })
1023
+ };
1024
+ //#endregion
1025
+ //#region src/actions/users/getUser.ts
1026
+ const getUser = (0, _prismatic_io_spectral.action)({
1027
+ display: {
1028
+ label: "Get User",
1029
+ description: "Gets the details of a single User"
1030
+ },
1031
+ inputs: { ...getUser_default },
1032
+ perform: async (context, { connection, userId }) => {
1033
+ return { data: cleanOdata((await createKarbonClient(connection, context.debug.enabled).get(`/v3/Users/${userId}`)).data) };
1034
+ },
1035
+ examplePayload: getUserExamplePayload
1036
+ });
1037
+ //#endregion
1038
+ //#region src/inputs/users/listUsers.ts
1039
+ const DOCUMENTATION_COMMENTS$2 = `See [Karbon API documentation](https://karbonhq.github.io/karbon-api-reference/#get-/v3/Users) for more information.`;
1040
+ var listUsers_default = {
1041
+ connection,
1042
+ $filter: (0, _prismatic_io_spectral.input)({
1043
+ ...$filter,
1044
+ comments: `${$filter.comments} ${DOCUMENTATION_COMMENTS$2}`
1045
+ }),
1046
+ $top,
1047
+ $skip,
1048
+ getAllData
1049
+ };
1050
+ //#endregion
1051
+ //#region src/actions/users/index.ts
1052
+ var users_default = {
1053
+ createUser,
1054
+ listUsers: (0, _prismatic_io_spectral.action)({
1055
+ display: {
1056
+ label: "List Users",
1057
+ description: "Get a list of Users"
1058
+ },
1059
+ inputs: { ...listUsers_default },
1060
+ perform: async (context, { connection, $filter, $top, $skip, getAllData }) => {
1061
+ const client = createKarbonClient(connection, context.debug.enabled);
1062
+ return { data: await getPaginatedData({
1063
+ pagination: {
1064
+ $top,
1065
+ $skip
1066
+ },
1067
+ client,
1068
+ endpoint: "/v3/Users",
1069
+ getAllData,
1070
+ $filter
1071
+ }) };
1072
+ },
1073
+ examplePayload: listUsersExamplePayload
1074
+ }),
1075
+ getUser
1076
+ };
1077
+ //#endregion
1078
+ //#region src/inputs/workitems/createWorkItem.ts
1079
+ const DOCUMENTATION_COMMENTS$1 = `See [Karbon API documentation](https://karbonhq.github.io/karbon-api-reference/#post-/v3/WorkItems) for more information.`;
1080
+ var createWorkItem_default = {
1081
+ connection,
1082
+ assigneeEmailAddres: (0, _prismatic_io_spectral.input)({
1083
+ label: "Assignee Email Address",
1084
+ type: "string",
1085
+ comments: "The email address of the user to whom the Work Item is going to be assigned.",
1086
+ required: true,
1087
+ clean: cleanStringInput,
1088
+ example: "example@email.com",
1089
+ placeholder: "example@email.com"
1090
+ }),
1091
+ title: (0, _prismatic_io_spectral.input)({
1092
+ label: "Title",
1093
+ type: "string",
1094
+ comments: "The title of the Work Item.",
1095
+ required: true,
1096
+ clean: cleanStringInput,
1097
+ example: "Work Item Title",
1098
+ placeholder: "Work Item Title"
1099
+ }),
1100
+ clientKey: (0, _prismatic_io_spectral.input)({
1101
+ label: "Client Key",
1102
+ type: "string",
1103
+ comments: "A Karbon-generated value used to identify the existing Client (Contact, Organization or ClientGroup) for whom the Work Item is prepared.",
1104
+ required: true,
1105
+ clean: cleanStringInput,
1106
+ example: "p56mtcBhwb9",
1107
+ placeholder: "p56mtcBhwb9"
1108
+ }),
1109
+ clientType: (0, _prismatic_io_spectral.input)({
1110
+ label: "Client Type",
1111
+ type: "string",
1112
+ model: [
1113
+ "Contact",
1114
+ "Organization",
1115
+ "ClientGroup"
1116
+ ].map((value) => ({
1117
+ value,
1118
+ label: value
1119
+ })),
1120
+ comments: "The type of the Client.",
1121
+ required: true,
1122
+ example: "Organization",
1123
+ clean: cleanStringInput
1124
+ }),
1125
+ relatedClientGroupKey: (0, _prismatic_io_spectral.input)({
1126
+ label: "Related Client Group Key",
1127
+ type: "string",
1128
+ comments: "A Karbon-generated value used to identify the Client Group of the Client.",
1129
+ clean: cleanStringInput,
1130
+ example: "4f3gHnLC323",
1131
+ required: false,
1132
+ placeholder: "4f3gHnLC323"
1133
+ }),
1134
+ startDate: (0, _prismatic_io_spectral.input)({
1135
+ label: "Start Date",
1136
+ type: "string",
1137
+ comments: "The date and time at which the Work Item should start.",
1138
+ required: true,
1139
+ example: "2022-01-30",
1140
+ placeholder: "2022-01-30",
1141
+ clean: cleanStringInput
1142
+ }),
1143
+ additionalFields: (0, _prismatic_io_spectral.input)({
1144
+ ...additionalFields,
1145
+ example: JSON.stringify({
1146
+ DueDate: "2022-01-30",
1147
+ DeadlineDate: "2022-01-31",
1148
+ WorkType: "Payroll",
1149
+ WorkStatus: "Ready To Start - Send client requests",
1150
+ WorkTemplateKey: "p56mtcBhwb9",
1151
+ WorkScheduleKey: "4f3gHnLC323",
1152
+ Description: "Send to Jo for review",
1153
+ UserRoleAssignments: [{
1154
+ RoleKey: "2mYzTtly89Lq",
1155
+ UserProfileKey: "2Qy48WVCRBcP"
1156
+ }],
1157
+ ClientTaskRecipient: {
1158
+ RecipientKey: "4ncPZ7q96SGc",
1159
+ LinkType: "Organization",
1160
+ EmailAddress: "acme@corp.com"
1161
+ },
1162
+ FeeSettings: {
1163
+ FeeType: "FixedFee",
1164
+ FeeValue: 5150.2
1165
+ }
1166
+ }, null, 2),
1167
+ comments: `${additionalFields.comments} ${DOCUMENTATION_COMMENTS$1}`
1168
+ })
1169
+ };
1170
+ //#endregion
1171
+ //#region src/actions/workitems/createWorkItem.ts
1172
+ const createWorkItem = (0, _prismatic_io_spectral.action)({
1173
+ display: {
1174
+ label: "Create a Work Item",
1175
+ description: "Create a new Work Item"
1176
+ },
1177
+ inputs: { ...createWorkItem_default },
1178
+ perform: async (context, { connection, assigneeEmailAddres, title, clientKey, clientType, relatedClientGroupKey, startDate, additionalFields }) => {
1179
+ return { data: cleanOdata((await createKarbonClient(connection, context.debug.enabled).post("/v3/WorkItems", {
1180
+ AssigneeEmailAddress: assigneeEmailAddres,
1181
+ Title: title,
1182
+ ClientKey: clientKey,
1183
+ ClientType: clientType,
1184
+ RelatedClientGroupKey: relatedClientGroupKey,
1185
+ StartDate: startDate,
1186
+ ...additionalFields || {}
1187
+ })).data) };
1188
+ },
1189
+ examplePayload: createWorkItemExamplePayload
1190
+ });
1191
+ //#endregion
1192
+ //#region src/inputs/workitems/shared.ts
1193
+ const workItemkey = (0, _prismatic_io_spectral.input)({
1194
+ label: "Work Item Key",
1195
+ type: "string",
1196
+ comments: "The Work Item key",
1197
+ required: true,
1198
+ clean: cleanStringInput,
1199
+ example: "2LPSrkzbYrn4",
1200
+ placeholder: "2LPSrkzbYrn4",
1201
+ dataSource: "selectWorkItem"
1202
+ });
1203
+ //#endregion
1204
+ //#region src/inputs/workitems/getWorkItem.ts
1205
+ var getWorkItem_default = {
1206
+ connection,
1207
+ workItemkey: (0, _prismatic_io_spectral.input)({
1208
+ ...workItemkey,
1209
+ comments: `${workItemkey.comments} to get the Work Item for.`
1210
+ })
1211
+ };
1212
+ //#endregion
1213
+ //#region src/actions/workitems/getWorkItem.ts
1214
+ const getWorkItem = (0, _prismatic_io_spectral.action)({
1215
+ display: {
1216
+ label: "Get Work Item",
1217
+ description: "Gets a Work Item by Work Item key"
1218
+ },
1219
+ inputs: { ...getWorkItem_default },
1220
+ perform: async (context, { connection, workItemkey }) => {
1221
+ return { data: cleanOdata((await createKarbonClient(connection, context.debug.enabled).get(`/v3/WorkItems/${workItemkey}`)).data) };
1222
+ },
1223
+ examplePayload: getWorkItemExamplePayload
1224
+ });
1225
+ //#endregion
1226
+ //#region src/inputs/workitems/listWorkItems.ts
1227
+ const DOCUMENTATION_COMMENTS = `See [Karbon API documentation](https://karbonhq.github.io/karbon-api-reference/#get-/v3/WorkItems) for more information.`;
1228
+ var listWorkItems_default = {
1229
+ connection,
1230
+ $filter: (0, _prismatic_io_spectral.input)({
1231
+ ...$filter,
1232
+ comments: `${$filter.comments} ${DOCUMENTATION_COMMENTS}`
1233
+ }),
1234
+ $top,
1235
+ $skip,
1236
+ $orderby: (0, _prismatic_io_spectral.input)({
1237
+ ...$orderby,
1238
+ model: [
1239
+ {
1240
+ value: "StartDate",
1241
+ label: "Start Date"
1242
+ },
1243
+ {
1244
+ value: "StartDate desc",
1245
+ label: "Start Date Descending"
1246
+ },
1247
+ {
1248
+ value: "DeadlineDate",
1249
+ label: "Deadline Date"
1250
+ },
1251
+ {
1252
+ value: "DeadlineDate desc",
1253
+ label: "Deadline Date Descending"
1254
+ }
1255
+ ]
1256
+ }),
1257
+ getAllData
1258
+ };
1259
+ //#endregion
1260
+ //#region src/actions/workitems/listWorkItems.ts
1261
+ const listWorkItems = (0, _prismatic_io_spectral.action)({
1262
+ display: {
1263
+ label: "List Work Items",
1264
+ description: "Receive a list of work items from your tenant"
1265
+ },
1266
+ inputs: { ...listWorkItems_default },
1267
+ perform: async (context, { connection, $filter, $top, $skip, $orderby, getAllData }) => {
1268
+ const client = createKarbonClient(connection, context.debug.enabled);
1269
+ return { data: await getPaginatedData({
1270
+ pagination: {
1271
+ $top,
1272
+ $skip
1273
+ },
1274
+ client,
1275
+ endpoint: "/v3/WorkItems",
1276
+ getAllData,
1277
+ $filter,
1278
+ $orderby
1279
+ }) };
1280
+ },
1281
+ examplePayload: listWorkItemsExamplePayload
1282
+ });
1283
+ //#endregion
1284
+ //#region src/inputs/workitems/updateWorkItem.ts
1285
+ const description = (0, _prismatic_io_spectral.input)({
1286
+ label: "Description",
1287
+ type: "string",
1288
+ comments: "A free form text field to add more information about the Work Item",
1289
+ required: false,
1290
+ example: "This is a description.",
1291
+ placeholder: "This is a description.",
1292
+ clean: cleanStringInput
1293
+ });
1294
+ const deadlineDate = (0, _prismatic_io_spectral.input)({
1295
+ label: "Deadline Date",
1296
+ type: "string",
1297
+ comments: "The deadline of the workitem as ISO8601 formated datestamp or timestamp",
1298
+ required: false,
1299
+ example: "2022-01-30",
1300
+ placeholder: "2022-01-30",
1301
+ clean: cleanStringInput
1302
+ });
1303
+ var updateWorkItem_default = {
1304
+ connection,
1305
+ workItemkey: (0, _prismatic_io_spectral.input)({
1306
+ ...workItemkey,
1307
+ comments: `${workItemkey.comments} to update a Work Item by.`
1308
+ }),
1309
+ description,
1310
+ deadlineDate
1311
+ };
1312
+ //#endregion
1313
+ //#region src/actions/workitems/index.ts
1314
+ var workitems_default = {
1315
+ listWorkItems,
1316
+ createWorkItem,
1317
+ getWorkItem,
1318
+ updateWorkItem: (0, _prismatic_io_spectral.action)({
1319
+ display: {
1320
+ label: "Update Work Item",
1321
+ description: "Partially update a Work Item by Work Item key"
1322
+ },
1323
+ inputs: { ...updateWorkItem_default },
1324
+ perform: async (context, { connection, workItemkey, description, deadlineDate }) => {
1325
+ await createKarbonClient(connection, context.debug.enabled).patch(`/v3/WorkItems/${workItemkey}`, {
1326
+ Description: description,
1327
+ DeadlineDate: deadlineDate
1328
+ });
1329
+ return { data: SUCCESS_MESSAGE };
1330
+ },
1331
+ examplePayload: updateWorkItemExamplePayload
1332
+ })
1333
+ };
1334
+ //#endregion
1335
+ //#region src/actions/misc/rawRequest.ts
1336
+ const { debugRequest: _, ...rawRequestInputs } = _prismatic_io_spectral_http.inputs;
1337
+ //#endregion
1338
+ //#region src/actions/misc/index.ts
1339
+ var misc_default = { rawRequest: (0, _prismatic_io_spectral.action)({
1340
+ display: {
1341
+ label: "Raw Request",
1342
+ description: "Send raw HTTP request to Karbon"
1343
+ },
1344
+ perform: async (context, { connection, ...rawRequestInputs }) => {
1345
+ validateConnection(connection);
1346
+ const { applicationId, accessKey } = getCredentialsFromConnection(connection);
1347
+ const { data, headers } = await (0, _prismatic_io_spectral_http.sendRawRequest)(BASE_URL, {
1348
+ ...rawRequestInputs,
1349
+ debugRequest: context.debug.enabled
1350
+ }, {
1351
+ AccessKey: accessKey,
1352
+ Authorization: `Bearer ${applicationId}`
1353
+ });
1354
+ return { data: {
1355
+ data: cleanOdata(data),
1356
+ headers
1357
+ } };
1358
+ },
1359
+ inputs: {
1360
+ connection,
1361
+ ...rawRequestInputs,
1362
+ url: {
1363
+ ...rawRequestInputs.url,
1364
+ comments: `Input the path only (/v3/ClientGroups), The base URL is already included (${BASE_URL}). For example, to connect to ${BASE_URL}/v3/ClientGroups, only /v3/ClientGroups is entered in this field.`,
1365
+ example: "/v3/ClientGroups",
1366
+ placeholder: "/v3/ClientGroups"
1367
+ }
1368
+ }
1369
+ }) };
1370
+ //#endregion
1371
+ //#region src/inputs/webhooks/deleteAllWebhookSubscriptions.ts
1372
+ var deleteAllWebhookSubscriptions_default = { connection };
1373
+ //#endregion
1374
+ //#region src/actions/webhooks/deleteAllWebhookSubscriptions.ts
1375
+ const deleteAllWebhookSubscriptions = (0, _prismatic_io_spectral.action)({
1376
+ display: {
1377
+ label: "Delete All Webhook Subscriptions",
1378
+ description: "Deletes all Webhook Subscriptions associated with Contact, Work, and Note"
1379
+ },
1380
+ inputs: { ...deleteAllWebhookSubscriptions_default },
1381
+ perform: async (context, { connection }) => {
1382
+ await createKarbonClient(connection, context.debug.enabled).delete(`/v3/WebhookSubscriptions`);
1383
+ return { data: SUCCESS_MESSAGE };
1384
+ },
1385
+ examplePayload: deleteAllWebhookSubscriptionsExamplePayload
1386
+ });
1387
+ //#endregion
1388
+ //#region src/inputs/webhooks/getWebhook.ts
1389
+ var getWebhook_default = {
1390
+ connection,
1391
+ webhookType
1392
+ };
1393
+ //#endregion
1394
+ //#region src/actions/webhooks/index.ts
1395
+ var webhooks_default = {
1396
+ deleteAllWebhookSubscriptions,
1397
+ getWebhook: (0, _prismatic_io_spectral.action)({
1398
+ display: {
1399
+ label: "Get Webhook",
1400
+ description: "Get a webhook subscription associated with the Karbon entity specified"
1401
+ },
1402
+ inputs: { ...getWebhook_default },
1403
+ perform: async (context, { connection, webhookType }) => {
1404
+ const { data } = await createKarbonClient(connection, context.debug.enabled).get(`/v3/WebhookSubscriptions/${webhookType}`);
1405
+ return { data: cleanOdata(data) };
1406
+ },
1407
+ examplePayload: getWebhookExamplePayload
1408
+ })
1409
+ };
1410
+ //#endregion
1411
+ //#region src/actions/index.ts
1412
+ var actions_default = {
1413
+ ...contacts_default,
1414
+ ...invoices_default,
1415
+ ...users_default,
1416
+ ...workitems_default,
1417
+ ...misc_default,
1418
+ ...webhooks_default
1419
+ };
1420
+ //#endregion
1421
+ //#region src/dataSources/organization/index.ts
1422
+ var organization_default = { selectOrganization: (0, _prismatic_io_spectral.dataSource)({
1423
+ display: {
1424
+ label: "Select Organization",
1425
+ description: "Select an Organization from a dropdown menu"
1426
+ },
1427
+ inputs: { connection },
1428
+ dataSourceType: "picklist",
1429
+ perform: async (context, { connection }) => {
1430
+ return { result: ((await getPaginatedData({
1431
+ client: createKarbonClient(connection, false),
1432
+ endpoint: "/v3/Organizations/",
1433
+ getAllData: true,
1434
+ pagination: {}
1435
+ })).value || []).map((organization) => ({
1436
+ key: organization.OrganizationKey,
1437
+ label: organization.FullName
1438
+ })) };
1439
+ }
1440
+ }) };
1441
+ //#endregion
1442
+ //#region src/dataSources/contact/index.ts
1443
+ var contact_default = { selectContact: (0, _prismatic_io_spectral.dataSource)({
1444
+ display: {
1445
+ label: "Select Contact",
1446
+ description: "Select a Contact from a dropdown menu"
1447
+ },
1448
+ inputs: { connection },
1449
+ dataSourceType: "picklist",
1450
+ perform: async (context, { connection }) => {
1451
+ return { result: ((await getPaginatedData({
1452
+ client: createKarbonClient(connection, false),
1453
+ endpoint: "/v3/Contacts",
1454
+ getAllData: true,
1455
+ pagination: {}
1456
+ })).value || []).map((contact) => ({
1457
+ key: contact.ContactKey,
1458
+ label: `${contact.FullName || "No Name"} ${contact.EmailAddress || ""}`
1459
+ })) };
1460
+ }
1461
+ }) };
1462
+ //#endregion
1463
+ //#region src/dataSources/invoice/index.ts
1464
+ var invoice_default = { selectInvoice: (0, _prismatic_io_spectral.dataSource)({
1465
+ display: {
1466
+ label: "Select Invoice",
1467
+ description: "Select an Invoice from a dropdown menu"
1468
+ },
1469
+ inputs: { connection },
1470
+ dataSourceType: "picklist",
1471
+ perform: async (context, { connection }) => {
1472
+ return { result: (cleanOdata((await createKarbonClient(connection, false).get("/v3/Invoices")).data).value || []).map((invoice) => ({
1473
+ key: invoice.InvoiceKey,
1474
+ label: invoice.InvoiceNumber
1475
+ })) };
1476
+ }
1477
+ }) };
1478
+ //#endregion
1479
+ //#region src/dataSources/user/index.ts
1480
+ var user_default = { selectUser: (0, _prismatic_io_spectral.dataSource)({
1481
+ display: {
1482
+ label: "Select User",
1483
+ description: "Select a User from a dropdown menu"
1484
+ },
1485
+ inputs: { connection },
1486
+ dataSourceType: "picklist",
1487
+ perform: async (context, { connection }) => {
1488
+ return { result: ((await getPaginatedData({
1489
+ client: createKarbonClient(connection, false),
1490
+ endpoint: "/v3/Users",
1491
+ getAllData: true,
1492
+ pagination: {}
1493
+ })).value || []).map((user) => ({
1494
+ key: user.Id,
1495
+ label: `${user.Name} ${user.EmailAddress}`
1496
+ })) };
1497
+ }
1498
+ }) };
1499
+ //#endregion
1500
+ //#region src/dataSources/workItem/index.ts
1501
+ var workItem_default = { selectWorkItem: (0, _prismatic_io_spectral.dataSource)({
1502
+ display: {
1503
+ label: "Select Work Item",
1504
+ description: "Select a Work Item from a dropdown menu"
1505
+ },
1506
+ inputs: { connection },
1507
+ dataSourceType: "picklist",
1508
+ perform: async (context, { connection }) => {
1509
+ return { result: ((await getPaginatedData({
1510
+ client: createKarbonClient(connection, false),
1511
+ endpoint: "/v3/WorkItems",
1512
+ getAllData: true,
1513
+ pagination: {}
1514
+ })).value || []).map((workItem) => ({
1515
+ key: workItem.WorkItemKey,
1516
+ label: workItem.Title
1517
+ })) };
1518
+ }
1519
+ }) };
1520
+ //#endregion
1521
+ //#region src/dataSources/index.ts
1522
+ var dataSources_default = {
1523
+ ...organization_default,
1524
+ ...contact_default,
1525
+ ...invoice_default,
1526
+ ...user_default,
1527
+ ...workItem_default
1528
+ };
1529
+ //#endregion
1530
+ //#region src/inputs/triggers/entityTrigger.ts
1531
+ var entityTrigger_default = {
1532
+ connection,
1533
+ webhookType
1534
+ };
1535
+ //#endregion
1536
+ //#region src/triggers/entityTrigger.ts
1537
+ const entityTrigger = (0, _prismatic_io_spectral.trigger)({
1538
+ display: {
1539
+ label: "Entity Trigger",
1540
+ description: "Get notified to this flow when a Karbon entity changes"
1541
+ },
1542
+ allowsBranching: false,
1543
+ inputs: { ...entityTrigger_default },
1544
+ synchronousResponseSupport: "invalid",
1545
+ scheduleSupport: "invalid",
1546
+ perform: async (_context, payload) => {
1547
+ return Promise.resolve({ payload });
1548
+ },
1549
+ webhookLifecycleHandlers: {
1550
+ create: async (context, { connection, webhookType }) => {
1551
+ const endpoint = context.webhookUrls[context.flow.name];
1552
+ await createWebhook(connection, false, endpoint, webhookType);
1553
+ },
1554
+ delete: async (_context, { connection, webhookType }) => {
1555
+ await deleteWebhook(connection, false, webhookType);
1556
+ }
1557
+ }
1558
+ });
1559
+ //#endregion
1560
+ //#region src/util/polling.ts
1561
+ const lookBackDateClean = (value) => {
1562
+ const str = _prismatic_io_spectral.util.types.toString(value).trim();
1563
+ if (!str) return "";
1564
+ if (!LOOK_BACK_DATE_PATTERN.test(str)) throw new Error("Look-back Date must be in YYYY-MM-DD format.");
1565
+ const parts = str.split("-");
1566
+ const year = _prismatic_io_spectral.util.types.toNumber(parts[0]);
1567
+ const month = _prismatic_io_spectral.util.types.toNumber(parts[1]);
1568
+ const day = _prismatic_io_spectral.util.types.toNumber(parts[2]);
1569
+ const parsed = new Date(year, month - 1, day);
1570
+ if (parsed.getFullYear() !== year || parsed.getMonth() !== month - 1 || parsed.getDate() !== day) throw new Error(`Look-back Date "${str}" is not a valid calendar date.`);
1571
+ if (parsed > /* @__PURE__ */ new Date()) throw new Error("Look-back Date cannot be a future date.");
1572
+ return str;
1573
+ };
1574
+ const resolvePollingRecordChanges = (data) => {
1575
+ if (!data) return [];
1576
+ const changes = [];
1577
+ for (const record of data.updated ?? []) changes.push({
1578
+ changeType: "updated",
1579
+ record
1580
+ });
1581
+ return changes;
1582
+ };
1583
+ var pollChanges_default = {
1584
+ connection,
1585
+ pollResourceType: (0, _prismatic_io_spectral.input)({
1586
+ label: "Resource Type",
1587
+ type: "string",
1588
+ required: true,
1589
+ default: "Contacts",
1590
+ model: pollResourceModel,
1591
+ comments: "The type of Karbon resource to poll for updated records.",
1592
+ clean: _prismatic_io_spectral.util.types.toString
1593
+ }),
1594
+ lookBackDate: (0, _prismatic_io_spectral.input)({
1595
+ label: "Look-back Date",
1596
+ placeholder: "Enter look-back date (YYYY-MM-DD)",
1597
+ type: "string",
1598
+ required: false,
1599
+ comments: "The date the initial sync starts from, in YYYY-MM-DD format. Cannot be a future date. Leave empty to start from the first recurrence with no backfill. When set, the initial sync seeds each record modified on or after this date once.",
1600
+ example: "2026-01-01",
1601
+ clean: lookBackDateClean
1602
+ })
1603
+ };
1604
+ //#endregion
1605
+ //#region src/triggers/index.ts
1606
+ var triggers_default = {
1607
+ entityTrigger,
1608
+ pollChangesTrigger: (0, _prismatic_io_spectral.pollingTrigger)({
1609
+ display: {
1610
+ label: "Updated Records",
1611
+ description: "Retrieves existing and ongoing updated records from Karbon. Load history once, check for changes on a schedule, or both."
1612
+ },
1613
+ inputs: pollChanges_default,
1614
+ triggerResolverSupport: "valid",
1615
+ batchConfig: { batchSize: 50 },
1616
+ triggerResolver: { resolveItems: (_context, { payload }) => resolvePollingRecordChanges(payload.body.data) },
1617
+ perform: async (context, payload, params) => {
1618
+ const config = POLL_RESOURCE_CONFIG[params.pollResourceType];
1619
+ if (!config) throw new Error(`Unsupported resource type: ${params.pollResourceType}`);
1620
+ const pollState = context.polling.getState();
1621
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1622
+ const lastPolledAt = pollState?.lastPolledAt ?? (params.lookBackDate ? new Date(params.lookBackDate).toISOString() : now);
1623
+ const response = await getPaginatedData({
1624
+ client: createKarbonClient(params.connection, context.debug.enabled),
1625
+ endpoint: config.endpoint,
1626
+ getAllData: true,
1627
+ pagination: {}
1628
+ });
1629
+ const records = filterRecordsModifiedAfter(response.value ?? [], config.timestampField, lastPolledAt);
1630
+ context.polling.setState({ lastPolledAt: now });
1631
+ if (context.debug.enabled) context.logger.debug(`Polled Karbon ${params.pollResourceType}: ${(response.value ?? []).length} fetched, ${records.length} changed`);
1632
+ return {
1633
+ payload: {
1634
+ ...payload,
1635
+ body: { data: { updated: records } }
1636
+ },
1637
+ polledNoChanges: records.length === 0
1638
+ };
1639
+ }
1640
+ })
1641
+ };
1642
+ //#endregion
1643
+ //#region src/index.ts
1644
+ var src_default = (0, _prismatic_io_spectral.component)({
1645
+ key: "karbon",
1646
+ public: true,
1647
+ documentationUrl: "https://prismatic.io/docs/components/karbon/",
1648
+ display: {
1649
+ label: "Karbon",
1650
+ description: "Karbon is a collaborative practice management platform for accounting firms.",
1651
+ iconPath: "icon.png",
1652
+ category: "Application Connectors"
1653
+ },
1654
+ hooks: { error: _prismatic_io_spectral_http.handleErrors },
1655
+ actions: actions_default,
1656
+ connections: connections_default,
1657
+ dataSources: dataSources_default,
1658
+ triggers: triggers_default
1659
+ });
1660
+ //#endregion
1661
+ //#region npm-dist/.entry.ts
1662
+ var _entry_default = (0, _prismatic_io_spectral.callableComponent)(src_default);
1663
+ //#endregion
1664
+ module.exports = _entry_default;