@chift/chift-nodejs 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.
Files changed (146) hide show
  1. package/.eslintcache +1 -0
  2. package/.eslintignore +1 -0
  3. package/.eslintrc.json +25 -0
  4. package/.github/workflows/ci.yml +73 -0
  5. package/.husky/pre-commit +4 -0
  6. package/.prettierignore +1 -0
  7. package/.prettierrc.json +7 -0
  8. package/CHANGELOG.md +4 -0
  9. package/LICENSE +201 -0
  10. package/README.md +48 -0
  11. package/coverage/clover.xml +1645 -0
  12. package/coverage/coverage-final.json +19 -0
  13. package/coverage/lcov-report/base.css +224 -0
  14. package/coverage/lcov-report/block-navigation.js +87 -0
  15. package/coverage/lcov-report/favicon.png +0 -0
  16. package/coverage/lcov-report/index.html +146 -0
  17. package/coverage/lcov-report/prettify.css +1 -0
  18. package/coverage/lcov-report/prettify.js +2 -0
  19. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  20. package/coverage/lcov-report/sorter.js +196 -0
  21. package/coverage/lcov-report/src/helpers/index.html +131 -0
  22. package/coverage/lcov-report/src/helpers/openapi.ts.html +151 -0
  23. package/coverage/lcov-report/src/helpers/settings.ts.html +94 -0
  24. package/coverage/lcov-report/src/index.html +116 -0
  25. package/coverage/lcov-report/src/index.ts.html +88 -0
  26. package/coverage/lcov-report/src/modules/accounting.ts.html +1156 -0
  27. package/coverage/lcov-report/src/modules/api.ts.html +190 -0
  28. package/coverage/lcov-report/src/modules/consumer.ts.html +616 -0
  29. package/coverage/lcov-report/src/modules/consumers.ts.html +331 -0
  30. package/coverage/lcov-report/src/modules/custom.ts.html +193 -0
  31. package/coverage/lcov-report/src/modules/datastores.ts.html +142 -0
  32. package/coverage/lcov-report/src/modules/ecommerce.ts.html +331 -0
  33. package/coverage/lcov-report/src/modules/flow.ts.html +589 -0
  34. package/coverage/lcov-report/src/modules/index.html +326 -0
  35. package/coverage/lcov-report/src/modules/integrations.ts.html +151 -0
  36. package/coverage/lcov-report/src/modules/internalApi.ts.html +586 -0
  37. package/coverage/lcov-report/src/modules/invoicing.ts.html +391 -0
  38. package/coverage/lcov-report/src/modules/pos.ts.html +421 -0
  39. package/coverage/lcov-report/src/modules/sync.ts.html +316 -0
  40. package/coverage/lcov-report/src/modules/syncs.ts.html +169 -0
  41. package/coverage/lcov-report/src/modules/webhooks.ts.html +343 -0
  42. package/coverage/lcov.info +1976 -0
  43. package/dist/src/helpers/openapi.d.ts +3 -0
  44. package/dist/src/helpers/openapi.js +18 -0
  45. package/dist/src/helpers/settings.d.ts +4 -0
  46. package/dist/src/helpers/settings.js +5 -0
  47. package/dist/src/index.d.ts +1 -0
  48. package/dist/src/index.js +17 -0
  49. package/dist/src/modules/accounting.d.ts +48 -0
  50. package/dist/src/modules/accounting.js +255 -0
  51. package/dist/src/modules/api.d.ts +39333 -0
  52. package/dist/src/modules/api.js +36 -0
  53. package/dist/src/modules/consumer.d.ts +2588 -0
  54. package/dist/src/modules/consumer.js +118 -0
  55. package/dist/src/modules/consumers.d.ts +13034 -0
  56. package/dist/src/modules/consumers.js +51 -0
  57. package/dist/src/modules/custom.d.ts +8 -0
  58. package/dist/src/modules/custom.js +36 -0
  59. package/dist/src/modules/datastores.d.ts +18 -0
  60. package/dist/src/modules/datastores.js +23 -0
  61. package/dist/src/modules/ecommerce.d.ts +16 -0
  62. package/dist/src/modules/ecommerce.js +69 -0
  63. package/dist/src/modules/flow.d.ts +15 -0
  64. package/dist/src/modules/flow.js +156 -0
  65. package/dist/src/modules/integrations.d.ts +14 -0
  66. package/dist/src/modules/integrations.js +23 -0
  67. package/dist/src/modules/internalApi.d.ts +22 -0
  68. package/dist/src/modules/internalApi.js +160 -0
  69. package/dist/src/modules/invoicing.d.ts +18 -0
  70. package/dist/src/modules/invoicing.js +90 -0
  71. package/dist/src/modules/pos.d.ts +20 -0
  72. package/dist/src/modules/pos.js +80 -0
  73. package/dist/src/modules/sync.d.ts +10494 -0
  74. package/dist/src/modules/sync.js +75 -0
  75. package/dist/src/modules/syncs.d.ts +26200 -0
  76. package/dist/src/modules/syncs.js +29 -0
  77. package/dist/src/modules/webhooks.d.ts +55 -0
  78. package/dist/src/modules/webhooks.js +53 -0
  79. package/dist/src/types/api.d.ts +28 -0
  80. package/dist/src/types/api.js +2 -0
  81. package/dist/src/types/consumers.d.ts +8 -0
  82. package/dist/src/types/consumers.js +2 -0
  83. package/dist/src/types/public-api/mappings.d.ts +21 -0
  84. package/dist/src/types/public-api/mappings.js +2 -0
  85. package/dist/src/types/sync.d.ts +20 -0
  86. package/dist/src/types/sync.js +2 -0
  87. package/dist/test/modules/accounting.test.d.ts +1 -0
  88. package/dist/test/modules/accounting.test.js +453 -0
  89. package/dist/test/modules/consumer.test.d.ts +1 -0
  90. package/dist/test/modules/consumer.test.js +89 -0
  91. package/dist/test/modules/consumers.test.d.ts +1 -0
  92. package/dist/test/modules/consumers.test.js +109 -0
  93. package/dist/test/modules/ecommerce.test.d.ts +1 -0
  94. package/dist/test/modules/ecommerce.test.js +193 -0
  95. package/dist/test/modules/flow.test.d.ts +1 -0
  96. package/dist/test/modules/flow.test.js +69 -0
  97. package/dist/test/modules/integrations.test.d.ts +1 -0
  98. package/dist/test/modules/integrations.test.js +54 -0
  99. package/dist/test/modules/invoicing.test.d.ts +1 -0
  100. package/dist/test/modules/invoicing.test.js +108 -0
  101. package/dist/test/modules/pos.test.d.ts +1 -0
  102. package/dist/test/modules/pos.test.js +164 -0
  103. package/dist/test/modules/sync.test.d.ts +1 -0
  104. package/dist/test/modules/sync.test.js +81 -0
  105. package/dist/test/modules/syncs.test.d.ts +1 -0
  106. package/dist/test/modules/syncs.test.js +53 -0
  107. package/dist/test/modules/webhooks.test.d.ts +1 -0
  108. package/dist/test/modules/webhooks.test.js +120 -0
  109. package/jest.config.ts +195 -0
  110. package/package.json +47 -0
  111. package/src/helpers/openapi.ts +22 -0
  112. package/src/helpers/settings.ts +3 -0
  113. package/src/index.ts +1 -0
  114. package/src/modules/accounting.ts +357 -0
  115. package/src/modules/api.ts +35 -0
  116. package/src/modules/consumer.ts +177 -0
  117. package/src/modules/consumers.ts +82 -0
  118. package/src/modules/custom.ts +36 -0
  119. package/src/modules/datastores.ts +19 -0
  120. package/src/modules/ecommerce.ts +82 -0
  121. package/src/modules/flow.ts +168 -0
  122. package/src/modules/integrations.ts +22 -0
  123. package/src/modules/internalApi.ts +162 -0
  124. package/src/modules/invoicing.ts +106 -0
  125. package/src/modules/pos.ts +112 -0
  126. package/src/modules/sync.ts +77 -0
  127. package/src/modules/syncs.ts +28 -0
  128. package/src/modules/webhooks.ts +86 -0
  129. package/src/types/api.ts +35 -0
  130. package/src/types/consumers.ts +9 -0
  131. package/src/types/public-api/mappings.ts +21 -0
  132. package/src/types/public-api/schema.d.ts +9436 -0
  133. package/src/types/sync.ts +23 -0
  134. package/test/data/accounting_invoice.pdf +0 -0
  135. package/test/modules/accounting.test.ts +483 -0
  136. package/test/modules/consumer.test.ts +68 -0
  137. package/test/modules/consumers.test.ts +83 -0
  138. package/test/modules/ecommerce.test.ts +177 -0
  139. package/test/modules/integrations.test.ts +22 -0
  140. package/test/modules/invoicing.test.ts +88 -0
  141. package/test/modules/pos.test.ts +145 -0
  142. package/test/modules/sync.test.ts +60 -0
  143. package/test/modules/syncs.test.ts +23 -0
  144. package/test/modules/webhooks.test.ts +92 -0
  145. package/test/set_envs.sh +14 -0
  146. package/tsconfig.json +107 -0
@@ -0,0 +1,357 @@
1
+ import { operations, components } from '../types/public-api/schema';
2
+ import { RequestData } from '../types/api';
3
+
4
+ type getChartOfAccountsParams = Omit<
5
+ operations['accounting_get_chart_of_accounts']['parameters']['query'],
6
+ 'page' | 'size'
7
+ >;
8
+
9
+ type getMiscOperationsParams = Omit<
10
+ operations['accounting_get_miscellaneous_operations']['parameters']['query'],
11
+ 'page' | 'size'
12
+ >;
13
+
14
+ type getJournalEntriesWithMultiplePlansParams = Omit<
15
+ operations['accounting_get_journal_entries_mutli_plan']['parameters']['query'],
16
+ 'page' | 'size'
17
+ >;
18
+
19
+ type getJournalEntriesParams = Omit<
20
+ operations['accounting_get_journal_entries']['parameters']['query'],
21
+ 'page' | 'size'
22
+ >;
23
+
24
+ type getInvoicesByTypeWithMultiplePlansParams = Omit<
25
+ operations['accounting_get_invoices_by_type_multi_analytic_plans']['parameters']['query'],
26
+ 'page' | 'size'
27
+ >;
28
+
29
+ type getInvoicesByTypeParams = Omit<
30
+ operations['accounting_get_invoices_by_type']['parameters']['query'],
31
+ 'page' | 'size'
32
+ >;
33
+
34
+ const accountingFactory = {
35
+ getAnalyticPlans(): RequestData<components['schemas']['AnalyticPlanItem'][]> {
36
+ return {
37
+ method: 'get',
38
+ url: '/consumers/{consumer_id}/accounting/analytic-plans',
39
+ };
40
+ },
41
+ getClients(): RequestData<components['schemas']['ClientItemOut'][]> {
42
+ return {
43
+ method: 'get',
44
+ url: '/consumers/{consumer_id}/accounting/clients',
45
+ };
46
+ },
47
+ createClient(
48
+ client: components['schemas']['ClientItemIn'],
49
+ params: operations['accounting_create_client']['parameters']['query']
50
+ ): RequestData<components['schemas']['ClientItemOut']> {
51
+ return {
52
+ method: 'post',
53
+ url: '/consumers/{consumer_id}/accounting/clients',
54
+ body: client,
55
+ params: params,
56
+ };
57
+ },
58
+ getClient(clientId: string): RequestData<components['schemas']['ClientItemOut']> {
59
+ return {
60
+ method: 'get',
61
+ url: `/consumers/{consumer_id}/accounting/clients/${clientId}`,
62
+ };
63
+ },
64
+ updateClient(
65
+ clientId: string,
66
+ client: components['schemas']['ClientItemUpdate']
67
+ ): RequestData<components['schemas']['ClientItemOut']> {
68
+ return {
69
+ method: 'patch',
70
+ url: `/consumers/{consumer_id}/accounting/clients/${clientId}`,
71
+ body: client,
72
+ };
73
+ },
74
+ getSuppliers(): RequestData<components['schemas']['SupplierItemOut'][]> {
75
+ return {
76
+ method: 'get',
77
+ url: '/consumers/{consumer_id}/accounting/suppliers',
78
+ };
79
+ },
80
+ createSupplier(
81
+ supplier: components['schemas']['SupplierItemIn'],
82
+ params: operations['accounting_create_supplier']['parameters']['query']
83
+ ): RequestData<components['schemas']['SupplierItemOut']> {
84
+ return {
85
+ method: 'post',
86
+ url: '/consumers/{consumer_id}/accounting/suppliers',
87
+ body: supplier,
88
+ params: params,
89
+ };
90
+ },
91
+ getSupplier(supplierId: string): RequestData<components['schemas']['SupplierItemOut']> {
92
+ return {
93
+ method: 'get',
94
+ url: `/consumers/{consumer_id}/accounting/suppliers/${supplierId}`,
95
+ };
96
+ },
97
+ updateSupplier(
98
+ supplierId: string,
99
+ supplier: components['schemas']['SupplierItemUpdate']
100
+ ): RequestData<components['schemas']['SupplierItemOut']> {
101
+ return {
102
+ method: 'patch',
103
+ url: `/consumers/{consumer_id}/accounting/suppliers/${supplierId}`,
104
+ body: supplier,
105
+ };
106
+ },
107
+ createInvoice(
108
+ invoice: components['schemas']['InvoiceItemInMonoAnalyticPlan'],
109
+ params: operations['accounting_create_invoice']['parameters']['query']
110
+ ): RequestData<components['schemas']['InvoiceItemOutMonoAnalyticPlan']> {
111
+ return {
112
+ params,
113
+ method: 'post',
114
+ url: '/consumers/{consumer_id}/accounting/invoices',
115
+ body: invoice,
116
+ };
117
+ },
118
+ createInvoiceWithMultiplePlans(
119
+ invoice: components['schemas']['InvoiceItemInMultiAnalyticPlans'],
120
+ params: operations['accounting_create_invoice_multiple_plans']['parameters']['query']
121
+ ): RequestData<components['schemas']['InvoiceItemOutMultiAnalyticPlans']> {
122
+ return {
123
+ params,
124
+ method: 'post',
125
+ url: '/consumers/{consumer_id}/accounting/invoices/multi-analytic-plans',
126
+ body: invoice,
127
+ };
128
+ },
129
+ getInvoicesByType(
130
+ invoice_type: components['schemas']['app__routers__accounting__InvoiceType'],
131
+ params: getInvoicesByTypeParams
132
+ ): RequestData<components['schemas']['InvoiceItemOutMonoAnalyticPlan'][]> {
133
+ return {
134
+ params,
135
+ method: 'get',
136
+ url: `/consumers/{consumer_id}/accounting/invoices/type/${invoice_type}`,
137
+ };
138
+ },
139
+ getInvoice(
140
+ invoiceId: string,
141
+ params: operations['accounting_get_invoice']['parameters']['query']
142
+ ): RequestData<components['schemas']['InvoiceItemOutMonoAnalyticPlan']> {
143
+ return {
144
+ params,
145
+ method: 'get',
146
+ url: `/consumers/{consumer_id}/accounting/invoices/${invoiceId}`,
147
+ };
148
+ },
149
+ getInvoiceWithMultiplePlans(
150
+ invoiceId: string,
151
+ params: operations['accounting_get_invoice_multi_analytic_plans']['parameters']['query']
152
+ ): RequestData<components['schemas']['InvoiceItemOutMultiAnalyticPlans']> {
153
+ return {
154
+ params,
155
+ method: 'get',
156
+ url: `/consumers/{consumer_id}/accounting/invoices/multi-analytic-plans/${invoiceId}`,
157
+ };
158
+ },
159
+ getInvoicesByTypeWithMultiplePlans(
160
+ invoice_type: components['schemas']['app__routers__accounting__InvoiceType'],
161
+ params: getInvoicesByTypeWithMultiplePlansParams
162
+ ): RequestData<components['schemas']['InvoiceItemOutMultiAnalyticPlans'][]> {
163
+ return {
164
+ params,
165
+ method: 'get',
166
+ url: `/consumers/{consumer_id}/accounting/invoices/multi-analytic-plans/type/${invoice_type}`,
167
+ };
168
+ },
169
+ createAnalyticAccount(
170
+ analyticAccount: components['schemas']['AnalyticAccountItemIn']
171
+ ): RequestData<components['schemas']['AnalyticAccountItemOut']> {
172
+ return {
173
+ method: 'post',
174
+ url: '/consumers/{consumer_id}/accounting/analytic-accounts',
175
+ body: analyticAccount,
176
+ };
177
+ },
178
+ getAnalyticAccounts(): RequestData<components['schemas']['AnalyticAccountItemOut'][]> {
179
+ return {
180
+ method: 'get',
181
+ url: '/consumers/{consumer_id}/accounting/analytic-accounts',
182
+ };
183
+ },
184
+ createAnalyticAccountWithMultiplePlans(
185
+ analytic_plan: string,
186
+ analyticAccount: components['schemas']['AnalyticAccountItemIn']
187
+ ): RequestData<components['schemas']['AnalyticAccountItemOutMultiAnalyticPlans']> {
188
+ return {
189
+ method: 'post',
190
+ url: `/consumers/{consumer_id}/accounting/analytic-accounts/multi-analytic-plans/${analytic_plan}`,
191
+ body: analyticAccount,
192
+ };
193
+ },
194
+ getAnalyticAccount(
195
+ analytic_account_id: string
196
+ ): RequestData<components['schemas']['AnalyticAccountItemOut']> {
197
+ return {
198
+ method: 'get',
199
+ url: `/consumers/{consumer_id}/accounting/analytic-accounts/${analytic_account_id}`,
200
+ };
201
+ },
202
+ updateAnalyticAccount(
203
+ analytic_account_id: string,
204
+ analyticAccount: components['schemas']['AnalyticAccountItemUpdate']
205
+ ): RequestData<components['schemas']['AnalyticAccountItemOut']> {
206
+ return {
207
+ method: 'patch',
208
+ url: `/consumers/{consumer_id}/accounting/analytic-accounts/${analytic_account_id}`,
209
+ body: analyticAccount,
210
+ };
211
+ },
212
+ getAnalyticAccountWithMultiplePlans(
213
+ analytic_account_id: string,
214
+ analytic_plan: string
215
+ ): RequestData<components['schemas']['AnalyticAccountItemOutMultiAnalyticPlans']> {
216
+ return {
217
+ method: 'get',
218
+ url: `/consumers/{consumer_id}/accounting/analytic-accounts/${analytic_account_id}/multi-analytic-plans/${analytic_plan}`,
219
+ };
220
+ },
221
+ updateAnalyticAccountWithMultiplePlans(
222
+ analytic_account_id: string,
223
+ analytic_plan: string,
224
+ analyticAccount: components['schemas']['AnalyticAccountItemUpdate']
225
+ ): RequestData<components['schemas']['AnalyticAccountItemOutMultiAnalyticPlans']> {
226
+ return {
227
+ method: 'patch',
228
+ url: `/consumers/{consumer_id}/accounting/analytic-accounts/${analytic_account_id}/multi-analytic-plans/${analytic_plan}`,
229
+ body: analyticAccount,
230
+ };
231
+ },
232
+ getAnalyticAccountsWithMultiplePlans(): RequestData<
233
+ components['schemas']['AnalyticAccountItemOutMultiAnalyticPlans'][]
234
+ > {
235
+ return {
236
+ method: 'get',
237
+ url: '/consumers/{consumer_id}/accounting/analytic-accounts/multi-analytic-plans',
238
+ };
239
+ },
240
+ getAnalyticLinesOfAccount(
241
+ analytic_account_id: string
242
+ ): RequestData<components['schemas']['AnalyticAccountLineItemOut'][]> {
243
+ return {
244
+ method: 'get',
245
+ url: `/consumers/{consumer_id}/accounting/analytic-account-lines/account/${analytic_account_id}`,
246
+ };
247
+ },
248
+ getJournalEntries(
249
+ params: getJournalEntriesParams
250
+ ): RequestData<components['schemas']['JournalEntryMonoAnalyticPlan'][]> {
251
+ return {
252
+ params,
253
+ method: 'get',
254
+ url: `/consumers/{consumer_id}/accounting/journal/entries`,
255
+ };
256
+ },
257
+ getJournalEntriesWithMultiplePlans(
258
+ params: getJournalEntriesWithMultiplePlansParams
259
+ ): RequestData<components['schemas']['JournalEntryMultiAnalyticPlan'][]> {
260
+ return {
261
+ params,
262
+ method: 'get',
263
+ url: `/consumers/{consumer_id}/accounting/journal/entries/multi-analytic-plans`,
264
+ };
265
+ },
266
+ getPaymentsByInvoiceId(invoice_id: string): RequestData<components['schemas']['Payment'][]> {
267
+ return {
268
+ method: 'get',
269
+ url: `/consumers/{consumer_id}/accounting/invoices/id/${invoice_id}/payments`,
270
+ };
271
+ },
272
+ getJournals(): RequestData<components['schemas']['Journal'][]> {
273
+ return {
274
+ method: 'get',
275
+ url: `/consumers/{consumer_id}/accounting/journals`,
276
+ };
277
+ },
278
+ getVatCodes(): RequestData<components['schemas']['app__routers__accounting__VatCode'][]> {
279
+ return {
280
+ method: 'get',
281
+ url: `/consumers/{consumer_id}/accounting/vat-codes`,
282
+ };
283
+ },
284
+ getMiscOperations(
285
+ params: getMiscOperationsParams
286
+ ): RequestData<components['schemas']['MiscellaneousOperationOut'][]> {
287
+ return {
288
+ params,
289
+ method: 'get',
290
+ url: '/consumers/{consumer_id}/accounting/miscellaneous-operation',
291
+ };
292
+ },
293
+ createMiscOperation(
294
+ operation: components['schemas']['MiscellaneousOperationIn']
295
+ ): RequestData<components['schemas']['MiscellaneousOperationOut']> {
296
+ return {
297
+ method: 'post',
298
+ url: '/consumers/{consumer_id}/accounting/miscellaneous-operation',
299
+ body: operation,
300
+ };
301
+ },
302
+ getMiscOperation(
303
+ operation_id: string
304
+ ): RequestData<components['schemas']['MiscellaneousOperationOut']> {
305
+ return {
306
+ method: 'get',
307
+ url: `/consumers/{consumer_id}/accounting/miscellaneous-operation/${operation_id}`,
308
+ };
309
+ },
310
+ attachPDF(
311
+ invoice_id: string,
312
+ attachment: components['schemas']['AttachmentItem'],
313
+ params: operations['accounting_add_attachment']['parameters']['query']
314
+ ): RequestData<operations['accounting_add_attachment']['responses'][201]> {
315
+ return {
316
+ params,
317
+ method: 'post',
318
+ url: `/consumers/{consumer_id}/accounting/invoices/pdf/${invoice_id}`,
319
+ body: attachment,
320
+ };
321
+ },
322
+ getChartOfAccounts(
323
+ params: getChartOfAccountsParams
324
+ ): RequestData<components['schemas']['AccountItem'][]> {
325
+ return {
326
+ params,
327
+ method: 'get',
328
+ url: '/consumers/{consumer_id}/accounting/chart-of-accounts',
329
+ };
330
+ },
331
+ getBalanceOfAccounts(
332
+ filter: components['schemas']['AccountBalanceFilter']
333
+ ): RequestData<components['schemas']['AccountBalance'][]> {
334
+ return {
335
+ method: 'post',
336
+ url: '/consumers/{consumer_id}/accounting/chart-of-accounts/balance',
337
+ body: filter,
338
+ };
339
+ },
340
+ getEmployees(): RequestData<components['schemas']['EmployeeItem'][]> {
341
+ return {
342
+ method: 'get',
343
+ url: '/consumers/{consumer_id}/accounting/employees',
344
+ };
345
+ },
346
+ createFinancialEntry(
347
+ financial_entry: components['schemas']['FinancialEntryItemIn']
348
+ ): RequestData<components['schemas']['FinancialEntryItemOut']> {
349
+ return {
350
+ method: 'post',
351
+ url: '/consumers/{consumer_id}/accounting/financial-entry',
352
+ body: financial_entry,
353
+ };
354
+ },
355
+ };
356
+
357
+ export { accountingFactory };
@@ -0,0 +1,35 @@
1
+ import { AuthType } from '../types/api';
2
+ import { InternalAPI } from './internalApi';
3
+ import { Consumers } from './consumers';
4
+ import { Syncs } from './syncs';
5
+ import { Integrations } from './integrations';
6
+ import { Webhooks } from './webhooks';
7
+ import { DataStores } from './datastores';
8
+
9
+ export class API {
10
+ auth: AuthType;
11
+ token?: string;
12
+ internalApi?: any;
13
+ Consumers;
14
+ Syncs;
15
+ Integrations;
16
+ Webhooks;
17
+ DataStores;
18
+
19
+ constructor(auth: AuthType) {
20
+ this.auth = auth;
21
+ this._setup();
22
+ this.Consumers = Consumers(this.internalApi);
23
+ this.Syncs = Syncs(this.internalApi);
24
+ this.Integrations = Integrations(this.internalApi);
25
+ this.Webhooks = Webhooks(this.internalApi);
26
+ this.DataStores = DataStores(this.internalApi);
27
+ }
28
+
29
+ private _setup = async () => {
30
+ if (!this.auth.clientId || !this.auth.clientSecret || !this.auth.accountId) {
31
+ throw new Error('Missing mandatory auth parameters');
32
+ }
33
+ this.internalApi = new InternalAPI(this.auth);
34
+ };
35
+ }
@@ -0,0 +1,177 @@
1
+ import { operations, components } from '../types/public-api/schema';
2
+ import { InternalAPI } from './internalApi';
3
+ import { chiftOperations } from '../types/public-api/mappings';
4
+ import { posFactory } from './pos';
5
+ import { createApiFor } from '../helpers/openapi';
6
+ import { accountingFactory } from './accounting';
7
+ import { invoicingFactory } from './invoicing';
8
+ import { ecommerceFactory } from './ecommerce';
9
+ import { customFactory } from './custom';
10
+ import { SimpleResponseModel } from '../types/sync';
11
+ import { ConsumerLog } from '../types/consumers';
12
+
13
+ const Consumer = (
14
+ internalApi: InternalAPI,
15
+ body: operations[chiftOperations['getConsumerById']]['responses'][200]['content']['application/json']
16
+ ) => {
17
+ const _internalApi = internalApi;
18
+ const data = body;
19
+ const consumerId = data.consumerid;
20
+ const name = data.name;
21
+ const redirect_url = data.redirect_url;
22
+ const email = data.email;
23
+ const pos = createApiFor(posFactory, _internalApi, data.name, consumerId);
24
+ const accounting = createApiFor(accountingFactory, _internalApi, data.name, consumerId);
25
+ const invoicing = createApiFor(invoicingFactory, _internalApi, data.name, consumerId);
26
+ const ecommerce = createApiFor(ecommerceFactory, _internalApi, data.name, consumerId);
27
+ const custom = createApiFor(customFactory, _internalApi, data.name, consumerId);
28
+
29
+ const getConnections = async () => {
30
+ const {
31
+ data,
32
+ }: {
33
+ data: operations[chiftOperations['getConnectionsByConsumerId']]['responses'][200]['content']['application/json'];
34
+ } = await _internalApi.get(`/consumers/${consumerId}/connections`);
35
+ return data;
36
+ };
37
+
38
+ const createConnection = async (body?: components['schemas']['PostConnectionItem']) => {
39
+ const {
40
+ data,
41
+ }: {
42
+ data: operations[chiftOperations['createConnection']]['responses'][200]['content']['application/json'];
43
+ } = await _internalApi.post(`/consumers/${consumerId}/connections`, { ...body });
44
+ return data;
45
+ };
46
+
47
+ const updateConnection = async (
48
+ connectionId: string,
49
+ body?: components['schemas']['PatchConnectionItem']
50
+ ) => {
51
+ const {
52
+ data,
53
+ }: {
54
+ data: operations[chiftOperations['updateConnection']]['responses'][200]['content']['application/json'];
55
+ } = await _internalApi.patch(`/consumers/${consumerId}/connections/${connectionId}`, {
56
+ ...body,
57
+ });
58
+ return data;
59
+ };
60
+
61
+ const deleteConnection = async (connectionId: string) => {
62
+ const {
63
+ data,
64
+ }: { data: operations[chiftOperations['deleteConnectionById']]['responses'][204] } =
65
+ await _internalApi.delete(`/consumers/${consumerId}/connections/${connectionId}`);
66
+ return data;
67
+ };
68
+
69
+ const getSyncUrl = async (body: components['schemas']['CreateConsumerSyncItem']) => {
70
+ const { data }: { data: components['schemas']['LinkSyncItem'] } = await _internalApi.post(
71
+ `/consumers/${consumerId}/syncs`,
72
+ body
73
+ );
74
+ return data;
75
+ };
76
+
77
+ const getSyncData = async (syncId: string) => {
78
+ const { data }: { data: components['schemas']['SyncConsumerItem'] } =
79
+ await _internalApi.get(`/consumers/${consumerId}/syncs/${syncId}`);
80
+ return data;
81
+ };
82
+
83
+ const getDataByDataStoreName = async (dataStoreName: string, params?: object) => {
84
+ const { data }: { data: components['schemas']['DataStoreItem'][] } = await _internalApi.get(
85
+ `/datastores`
86
+ );
87
+ for (let i = 0; i < data.length; i++) {
88
+ if (data[i].name == dataStoreName) {
89
+ return await getDataByDataStoreId(data[i].id, params);
90
+ }
91
+ }
92
+ throw Error('Datastore could not be found');
93
+ };
94
+
95
+ const getDataByDataStoreId = async (dataStoreId: string, params?: object) => {
96
+ const { data }: { data: components['schemas']['DataItemOut'][] } = await _internalApi.get(
97
+ `/consumers/${consumerId}/datastore/${dataStoreId}/data`,
98
+ { params: params }
99
+ );
100
+ return data;
101
+ };
102
+
103
+ const addDataByDataStoreId = async (
104
+ dataStoreId: string,
105
+ data: components['schemas']['DataItem'][]
106
+ ) => {
107
+ const { data: response }: { data: components['schemas']['DataItemOut'][] } =
108
+ await _internalApi.post(`/consumers/${consumerId}/datastore/${dataStoreId}/data`, data);
109
+ return response;
110
+ };
111
+
112
+ const addDataByDataStoreName = async (
113
+ dataStoreName: string,
114
+ data: components['schemas']['DataItem'][]
115
+ ) => {
116
+ const { data: datastores }: { data: components['schemas']['DataStoreItem'][] } =
117
+ await _internalApi.get(`/datastores`);
118
+ for (let i = 0; i < datastores.length; i++) {
119
+ if (datastores[i].name == dataStoreName) {
120
+ return await addDataByDataStoreId(datastores[i].id, data);
121
+ }
122
+ }
123
+ };
124
+
125
+ const updateDataStoreData = async (
126
+ dataStoreId: string,
127
+ dataStoreDataId: string,
128
+ data: components['schemas']['DataItem']
129
+ ) => {
130
+ const { data: response }: { data: components['schemas']['DataItemOut'][] } =
131
+ await _internalApi.patch(
132
+ `/consumers/${consumerId}/datastore/${dataStoreId}/data/${dataStoreDataId}`,
133
+ data
134
+ );
135
+ return response;
136
+ };
137
+
138
+ /**
139
+ * This function is used to add logs related to a chainexecution (passed in the header)
140
+ * INTERNAL USE only
141
+ * @param logs
142
+ * @returns
143
+ */
144
+ const logData = async (logs: ConsumerLog[]) => {
145
+ const { data: response }: { data: SimpleResponseModel } = await _internalApi.post(
146
+ `/consumers/${consumerId}/logs`,
147
+ logs
148
+ );
149
+ return response;
150
+ };
151
+
152
+ return {
153
+ consumerId,
154
+ getConnections,
155
+ createConnection,
156
+ updateConnection,
157
+ deleteConnection,
158
+ getSyncUrl,
159
+ name,
160
+ redirect_url,
161
+ email,
162
+ pos,
163
+ accounting,
164
+ invoicing,
165
+ ecommerce,
166
+ custom,
167
+ getDataByDataStoreId,
168
+ addDataByDataStoreId,
169
+ getSyncData,
170
+ getDataByDataStoreName,
171
+ addDataByDataStoreName,
172
+ updateDataStoreData,
173
+ logData,
174
+ };
175
+ };
176
+
177
+ export { Consumer };
@@ -0,0 +1,82 @@
1
+ import { operations } from '../types/public-api/schema';
2
+ import { InternalAPI } from './internalApi';
3
+ import { Consumer } from './consumer';
4
+ import { chiftOperations } from '../types/public-api/mappings';
5
+
6
+ const Consumers = (internalApi: InternalAPI) => {
7
+ const _internalApi: InternalAPI = internalApi;
8
+
9
+ const getConsumers = async () => {
10
+ const {
11
+ data,
12
+ }: {
13
+ data: operations[chiftOperations['getConsumers']]['responses'][200]['content']['application/json'];
14
+ } = await _internalApi.get('/consumers');
15
+ return data.map((consumer) => Consumer(_internalApi, consumer));
16
+ };
17
+
18
+ const createConsumer = async (
19
+ body: operations[chiftOperations['createConsumer']]['requestBody']['content']['application/json']
20
+ ) => {
21
+ const {
22
+ data,
23
+ }: {
24
+ data: operations[chiftOperations['createConsumer']]['responses'][200]['content']['application/json'];
25
+ } = await _internalApi.post('/consumers', body);
26
+ return Consumer(_internalApi, data);
27
+ };
28
+
29
+ const getConsumerById = async (consumerId: string) => {
30
+ const {
31
+ data,
32
+ }: {
33
+ data: operations[chiftOperations['getConsumerById']]['responses'][200]['content']['application/json'];
34
+ } = await _internalApi.get(`/consumers/${consumerId}`);
35
+ return Consumer(_internalApi, { ...data });
36
+ };
37
+
38
+ const getConsumersByName = async (consumerName: string) => {
39
+ const {
40
+ data,
41
+ }: {
42
+ data: operations[chiftOperations['getConsumers']]['responses'][200]['content']['application/json'];
43
+ } = await _internalApi.get('/consumers');
44
+ return data
45
+ .filter(
46
+ (consumer) =>
47
+ consumer.name.toLowerCase().indexOf(consumerName.toLocaleLowerCase()) !== -1
48
+ )
49
+ .map((consumer) => Consumer(_internalApi, consumer));
50
+ };
51
+
52
+ const updateConsumerById = async (
53
+ consumerId: string,
54
+ body: operations[chiftOperations['updateConsumer']]['requestBody']['content']['application/json']
55
+ ) => {
56
+ const {
57
+ data,
58
+ }: {
59
+ data: operations[chiftOperations['updateConsumer']]['responses'][200]['content']['application/json'];
60
+ } = await _internalApi.patch(`/consumers/${consumerId}`, body);
61
+ return Consumer(_internalApi, data);
62
+ };
63
+
64
+ const deleteConsumerById = async (consumerId: string) => {
65
+ const {
66
+ data,
67
+ }: { data: operations[chiftOperations['deleteConsumerById']]['responses'][204] } =
68
+ await _internalApi.delete(`/consumers/${consumerId}`);
69
+ return data;
70
+ };
71
+
72
+ return {
73
+ getConsumers,
74
+ createConsumer,
75
+ getConsumerById,
76
+ getConsumersByName,
77
+ updateConsumerById,
78
+ deleteConsumerById,
79
+ };
80
+ };
81
+
82
+ export { Consumers };
@@ -0,0 +1,36 @@
1
+ import { RequestData } from '../types/api';
2
+
3
+ const customFactory = {
4
+ get(name: string, resource: string, params?: any): RequestData<any> {
5
+ return {
6
+ method: 'get',
7
+ url: `/consumers/{consumer_id}/custom/${name}/${resource}`,
8
+ params: params,
9
+ };
10
+ },
11
+ post(name: string, resource: string, body: any, params?: any): RequestData<any> {
12
+ return {
13
+ method: 'post',
14
+ url: `/consumers/{consumer_id}/custom/${name}/${resource}`,
15
+ body: body,
16
+ params: params,
17
+ };
18
+ },
19
+ patch(name: string, resource: string, body: any, params?: any): RequestData<any> {
20
+ return {
21
+ method: 'patch',
22
+ url: `/consumers/{consumer_id}/custom/${name}/${resource}`,
23
+ body: body,
24
+ params: params,
25
+ };
26
+ },
27
+ delete(name: string, resource: string, params?: any): RequestData<any> {
28
+ return {
29
+ method: 'delete',
30
+ url: `/consumers/{consumer_id}/custom/${name}/${resource}`,
31
+ params: params,
32
+ };
33
+ },
34
+ };
35
+
36
+ export { customFactory };