@chift/chift-nodejs 1.0.16 → 1.0.18

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 (145) hide show
  1. package/README.md +3 -3
  2. package/package.json +5 -2
  3. package/src/types/public-api/schema.d.ts +4071 -850
  4. package/src/types/sync.ts +20 -5
  5. package/.eslintcache +0 -1
  6. package/.eslintignore +0 -1
  7. package/.eslintrc.json +0 -25
  8. package/.github/workflows/ci.yml +0 -75
  9. package/.husky/pre-commit +0 -4
  10. package/.prettierignore +0 -1
  11. package/.prettierrc.json +0 -7
  12. package/CHANGELOG.md +0 -98
  13. package/coverage/clover.xml +0 -1645
  14. package/coverage/coverage-final.json +0 -19
  15. package/coverage/lcov-report/base.css +0 -224
  16. package/coverage/lcov-report/block-navigation.js +0 -87
  17. package/coverage/lcov-report/favicon.png +0 -0
  18. package/coverage/lcov-report/index.html +0 -146
  19. package/coverage/lcov-report/prettify.css +0 -1
  20. package/coverage/lcov-report/prettify.js +0 -2
  21. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  22. package/coverage/lcov-report/sorter.js +0 -196
  23. package/coverage/lcov-report/src/helpers/index.html +0 -131
  24. package/coverage/lcov-report/src/helpers/openapi.ts.html +0 -151
  25. package/coverage/lcov-report/src/helpers/settings.ts.html +0 -94
  26. package/coverage/lcov-report/src/index.html +0 -116
  27. package/coverage/lcov-report/src/index.ts.html +0 -88
  28. package/coverage/lcov-report/src/modules/accounting.ts.html +0 -1156
  29. package/coverage/lcov-report/src/modules/api.ts.html +0 -190
  30. package/coverage/lcov-report/src/modules/consumer.ts.html +0 -616
  31. package/coverage/lcov-report/src/modules/consumers.ts.html +0 -331
  32. package/coverage/lcov-report/src/modules/custom.ts.html +0 -193
  33. package/coverage/lcov-report/src/modules/datastores.ts.html +0 -142
  34. package/coverage/lcov-report/src/modules/ecommerce.ts.html +0 -331
  35. package/coverage/lcov-report/src/modules/flow.ts.html +0 -589
  36. package/coverage/lcov-report/src/modules/index.html +0 -326
  37. package/coverage/lcov-report/src/modules/integrations.ts.html +0 -151
  38. package/coverage/lcov-report/src/modules/internalApi.ts.html +0 -586
  39. package/coverage/lcov-report/src/modules/invoicing.ts.html +0 -391
  40. package/coverage/lcov-report/src/modules/pos.ts.html +0 -421
  41. package/coverage/lcov-report/src/modules/sync.ts.html +0 -316
  42. package/coverage/lcov-report/src/modules/syncs.ts.html +0 -169
  43. package/coverage/lcov-report/src/modules/webhooks.ts.html +0 -343
  44. package/coverage/lcov.info +0 -1976
  45. package/dist/src/helpers/openapi.d.ts +0 -3
  46. package/dist/src/helpers/openapi.js +0 -18
  47. package/dist/src/helpers/settings.d.ts +0 -4
  48. package/dist/src/helpers/settings.js +0 -5
  49. package/dist/src/index.d.ts +0 -1
  50. package/dist/src/modules/accounting.d.ts +0 -68
  51. package/dist/src/modules/accounting.js +0 -326
  52. package/dist/src/modules/api.d.ts +0 -16795
  53. package/dist/src/modules/api.js +0 -36
  54. package/dist/src/modules/consumer.d.ts +0 -3313
  55. package/dist/src/modules/consumer.js +0 -139
  56. package/dist/src/modules/consumers.d.ts +0 -16684
  57. package/dist/src/modules/consumers.js +0 -51
  58. package/dist/src/modules/custom.d.ts +0 -8
  59. package/dist/src/modules/custom.js +0 -36
  60. package/dist/src/modules/datastores.d.ts +0 -18
  61. package/dist/src/modules/datastores.js +0 -23
  62. package/dist/src/modules/ecommerce.d.ts +0 -24
  63. package/dist/src/modules/ecommerce.js +0 -97
  64. package/dist/src/modules/flow.d.ts +0 -15
  65. package/dist/src/modules/flow.js +0 -156
  66. package/dist/src/modules/integrations.d.ts +0 -23
  67. package/dist/src/modules/integrations.js +0 -23
  68. package/dist/src/modules/internalApi.d.ts +0 -24
  69. package/dist/src/modules/internalApi.js +0 -175
  70. package/dist/src/modules/invoicing.d.ts +0 -20
  71. package/dist/src/modules/invoicing.js +0 -90
  72. package/dist/src/modules/pms.d.ts +0 -15
  73. package/dist/src/modules/pms.js +0 -47
  74. package/dist/src/modules/pos.d.ts +0 -26
  75. package/dist/src/modules/pos.js +0 -101
  76. package/dist/src/modules/sync.d.ts +0 -13414
  77. package/dist/src/modules/sync.js +0 -73
  78. package/dist/src/modules/syncs.d.ts +0 -11
  79. package/dist/src/modules/syncs.js +0 -39
  80. package/dist/src/modules/webhooks.d.ts +0 -55
  81. package/dist/src/modules/webhooks.js +0 -53
  82. package/dist/src/types/api.d.ts +0 -29
  83. package/dist/src/types/api.js +0 -2
  84. package/dist/src/types/consumers.d.ts +0 -8
  85. package/dist/src/types/consumers.js +0 -2
  86. package/dist/src/types/public-api/mappings.d.ts +0 -21
  87. package/dist/src/types/public-api/mappings.js +0 -2
  88. package/dist/src/types/public-api/schema.d.ts +0 -12003
  89. package/dist/src/types/public-api/schema.js +0 -6
  90. package/dist/src/types/sync.d.ts +0 -20
  91. package/dist/src/types/sync.js +0 -2
  92. package/dist/test/modules/accounting.test.d.ts +0 -1
  93. package/dist/test/modules/accounting.test.js +0 -582
  94. package/dist/test/modules/consumer.test.d.ts +0 -1
  95. package/dist/test/modules/consumer.test.js +0 -89
  96. package/dist/test/modules/consumers.test.d.ts +0 -1
  97. package/dist/test/modules/consumers.test.js +0 -109
  98. package/dist/test/modules/ecommerce.test.d.ts +0 -1
  99. package/dist/test/modules/ecommerce.test.js +0 -220
  100. package/dist/test/modules/integrations.test.d.ts +0 -1
  101. package/dist/test/modules/integrations.test.js +0 -54
  102. package/dist/test/modules/invoicing.test.d.ts +0 -1
  103. package/dist/test/modules/invoicing.test.js +0 -108
  104. package/dist/test/modules/pos.test.d.ts +0 -1
  105. package/dist/test/modules/pos.test.js +0 -182
  106. package/dist/test/modules/sync.test.d.ts +0 -1
  107. package/dist/test/modules/sync.test.js +0 -81
  108. package/dist/test/modules/syncs.test.d.ts +0 -1
  109. package/dist/test/modules/syncs.test.js +0 -53
  110. package/dist/test/modules/webhooks.test.d.ts +0 -1
  111. package/dist/test/modules/webhooks.test.js +0 -120
  112. package/jest.config.ts +0 -195
  113. package/src/helpers/openapi.ts +0 -22
  114. package/src/helpers/settings.ts +0 -3
  115. package/src/index.ts +0 -1
  116. package/src/modules/accounting.ts +0 -510
  117. package/src/modules/api.ts +0 -35
  118. package/src/modules/consumer.ts +0 -213
  119. package/src/modules/consumers.ts +0 -82
  120. package/src/modules/custom.ts +0 -36
  121. package/src/modules/datastores.ts +0 -19
  122. package/src/modules/ecommerce.ts +0 -127
  123. package/src/modules/flow.ts +0 -168
  124. package/src/modules/integrations.ts +0 -24
  125. package/src/modules/internalApi.ts +0 -182
  126. package/src/modules/invoicing.ts +0 -114
  127. package/src/modules/pms.ts +0 -67
  128. package/src/modules/pos.ts +0 -144
  129. package/src/modules/sync.ts +0 -77
  130. package/src/modules/syncs.ts +0 -59
  131. package/src/modules/webhooks.ts +0 -86
  132. package/src/types/public-api/schema.ts +0 -12073
  133. package/test/data/accounting_invoice.pdf +0 -0
  134. package/test/modules/accounting.test.ts +0 -628
  135. package/test/modules/consumer.test.ts +0 -68
  136. package/test/modules/consumers.test.ts +0 -85
  137. package/test/modules/ecommerce.test.ts +0 -208
  138. package/test/modules/integrations.test.ts +0 -22
  139. package/test/modules/invoicing.test.ts +0 -88
  140. package/test/modules/pos.test.ts +0 -166
  141. package/test/modules/sync.test.ts +0 -60
  142. package/test/modules/syncs.test.ts +0 -23
  143. package/test/modules/webhooks.test.ts +0 -92
  144. package/test/set_envs.sh +0 -14
  145. package/tsconfig.json +0 -107
@@ -1,213 +0,0 @@
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 { pmsFactory } from './pms';
6
- import { createApiFor } from '../helpers/openapi';
7
- import { accountingFactory } from './accounting';
8
- import { invoicingFactory } from './invoicing';
9
- import { ecommerceFactory } from './ecommerce';
10
- import { customFactory } from './custom';
11
- import { SimpleResponseModel } from '../types/sync';
12
- import { ConsumerLog } from '../types/consumers';
13
-
14
- const Consumer = (
15
- internalApi: InternalAPI,
16
- body: operations[chiftOperations['getConsumerById']]['responses'][200]['content']['application/json']
17
- ) => {
18
- const _internalApi = internalApi;
19
- const data = body;
20
- const consumerId = data.consumerid;
21
- const name = data.name;
22
- const redirect_url = data.redirect_url;
23
- const email = data.email;
24
- const pos = createApiFor(posFactory, _internalApi, data.name, consumerId);
25
- const pms = createApiFor(pmsFactory, _internalApi, data.name, consumerId);
26
- const accounting = createApiFor(accountingFactory, _internalApi, data.name, consumerId);
27
- const invoicing = createApiFor(invoicingFactory, _internalApi, data.name, consumerId);
28
- const ecommerce = createApiFor(ecommerceFactory, _internalApi, data.name, consumerId);
29
- const custom = createApiFor(customFactory, _internalApi, data.name, consumerId);
30
-
31
- const setConnectionId = async (connectionId: string) => {
32
- _internalApi.connectionId = connectionId;
33
- };
34
-
35
- const setIntegrationId = async (integrationId: string) => {
36
- _internalApi.integrationId = integrationId;
37
- };
38
-
39
- const getConnections = async () => {
40
- const {
41
- data,
42
- }: {
43
- data: operations[chiftOperations['getConnectionsByConsumerId']]['responses'][200]['content']['application/json'];
44
- } = await _internalApi.get(`/consumers/${consumerId}/connections`);
45
- return data;
46
- };
47
-
48
- const createConnection = async (
49
- body?: components['schemas']['app__routers__connections__PostConnectionItem']
50
- ) => {
51
- const {
52
- data,
53
- }: {
54
- data: operations[chiftOperations['createConnection']]['responses'][200]['content']['application/json'];
55
- } = await _internalApi.post(`/consumers/${consumerId}/connections`, { ...body });
56
- return data;
57
- };
58
-
59
- const updateConnection = async (
60
- connectionId: string,
61
- body?: components['schemas']['PatchConnectionItem']
62
- ) => {
63
- const {
64
- data,
65
- }: {
66
- data: operations[chiftOperations['updateConnection']]['responses'][200]['content']['application/json'];
67
- } = await _internalApi.patch(`/consumers/${consumerId}/connections/${connectionId}`, {
68
- ...body,
69
- });
70
- return data;
71
- };
72
-
73
- const deleteConnection = async (connectionId: string) => {
74
- const {
75
- data,
76
- }: { data: operations[chiftOperations['deleteConnectionById']]['responses'][204] } =
77
- await _internalApi.delete(`/consumers/${consumerId}/connections/${connectionId}`);
78
- return data;
79
- };
80
-
81
- const getSyncUrl = async (body: components['schemas']['CreateConsumerSyncItem']) => {
82
- const { data }: { data: components['schemas']['LinkSyncItem'] } = await _internalApi.post(
83
- `/consumers/${consumerId}/syncs`,
84
- body
85
- );
86
- return data;
87
- };
88
-
89
- const getSyncData = async (syncId: string) => {
90
- const { data }: { data: components['schemas']['SyncConsumerItem'] } =
91
- await _internalApi.get(`/consumers/${consumerId}/syncs/${syncId}`);
92
- return data;
93
- };
94
-
95
- const enableFlow = async (
96
- syncId: string,
97
- flowId: string,
98
- body: components['schemas']['EnableFlowConsumer']
99
- ) => {
100
- const { data }: { data: SimpleResponseModel } = await _internalApi.post(
101
- `/consumers/${consumerId}/syncs/${syncId}/flows/${flowId}/enable`,
102
- body
103
- );
104
- return data;
105
- };
106
-
107
- const getDataByDataStoreName = async (dataStoreName: string, params?: object) => {
108
- const { data }: { data: components['schemas']['DataStoreItem'][] } = await _internalApi.get(
109
- `/datastores`
110
- );
111
- for (let i = 0; i < data.length; i++) {
112
- if (data[i].name == dataStoreName) {
113
- return await getDataByDataStoreId(data[i].id, params);
114
- }
115
- }
116
- throw Error('Datastore could not be found');
117
- };
118
-
119
- const getDataByDataStoreId = async (dataStoreId: string, params?: object) => {
120
- const { data }: { data: components['schemas']['DataItemOut'][] } = await _internalApi.get(
121
- `/consumers/${consumerId}/datastore/${dataStoreId}/data`,
122
- { params: params }
123
- );
124
- return data;
125
- };
126
-
127
- const addDataByDataStoreId = async (
128
- dataStoreId: string,
129
- data: components['schemas']['DataItem'][]
130
- ) => {
131
- const { data: response }: { data: components['schemas']['DataItemOut'][] } =
132
- await _internalApi.post(`/consumers/${consumerId}/datastore/${dataStoreId}/data`, data);
133
- return response;
134
- };
135
-
136
- const addDataByDataStoreName = async (
137
- dataStoreName: string,
138
- data: components['schemas']['DataItem'][]
139
- ) => {
140
- const { data: datastores }: { data: components['schemas']['DataStoreItem'][] } =
141
- await _internalApi.get(`/datastores`);
142
- for (let i = 0; i < datastores.length; i++) {
143
- if (datastores[i].name == dataStoreName) {
144
- return await addDataByDataStoreId(datastores[i].id, data);
145
- }
146
- }
147
- };
148
-
149
- const updateDataStoreData = async (
150
- dataStoreId: string,
151
- dataStoreDataId: string,
152
- data: components['schemas']['DataItem']
153
- ) => {
154
- const { data: response }: { data: components['schemas']['DataItemOut'][] } =
155
- await _internalApi.patch(
156
- `/consumers/${consumerId}/datastore/${dataStoreId}/data/${dataStoreDataId}`,
157
- data
158
- );
159
- return response;
160
- };
161
-
162
- const deleteDataStoreData = async (dataStoreId: string, dataStoreDataId: string) => {
163
- const { data: response }: { data: SimpleResponseModel } = await _internalApi.delete(
164
- `/consumers/${consumerId}/datastore/${dataStoreId}/data/${dataStoreDataId}`
165
- );
166
- return response;
167
- };
168
-
169
- /**
170
- * This function is used to add logs related to a chainexecution (passed in the header)
171
- * INTERNAL USE only
172
- * @param logs
173
- * @returns
174
- */
175
- const logData = async (logs: ConsumerLog[]) => {
176
- const { data: response }: { data: SimpleResponseModel } = await _internalApi.post(
177
- `/consumers/${consumerId}/logs`,
178
- logs
179
- );
180
- return response;
181
- };
182
-
183
- return {
184
- consumerId,
185
- getConnections,
186
- createConnection,
187
- updateConnection,
188
- deleteConnection,
189
- enableFlow,
190
- getSyncUrl,
191
- name,
192
- redirect_url,
193
- email,
194
- pos,
195
- pms,
196
- accounting,
197
- invoicing,
198
- ecommerce,
199
- custom,
200
- getDataByDataStoreId,
201
- addDataByDataStoreId,
202
- getSyncData,
203
- getDataByDataStoreName,
204
- addDataByDataStoreName,
205
- updateDataStoreData,
206
- deleteDataStoreData,
207
- logData,
208
- setConnectionId,
209
- setIntegrationId,
210
- };
211
- };
212
-
213
- export { Consumer };
@@ -1,82 +0,0 @@
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 };
@@ -1,36 +0,0 @@
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 };
@@ -1,19 +0,0 @@
1
- import { components } from '../types/public-api/schema';
2
- import { InternalAPI } from './internalApi';
3
-
4
- const DataStores = (internalApi: InternalAPI) => {
5
- const _internalApi: InternalAPI = internalApi;
6
-
7
- const getDataStores = async () => {
8
- const { data }: { data: components['schemas']['DataStoreItem'][] } = await _internalApi.get(
9
- '/datastores'
10
- );
11
- return data;
12
- };
13
-
14
- return {
15
- getDataStores,
16
- };
17
- };
18
-
19
- export { DataStores };
@@ -1,127 +0,0 @@
1
- import { operations, components } from '../types/public-api/schema';
2
- import { AutoPaginatedParams, RequestData } from '../types/api';
3
-
4
- type GetOrdersParams = AutoPaginatedParams<
5
- operations['ecommerce_get_orders']['parameters']['query']
6
- >;
7
-
8
- type GetPaymentMethodsParams = AutoPaginatedParams<
9
- operations['ecommerce_get_payments_methods']['parameters']['query']
10
- >;
11
-
12
- type GetProductCategoriesParams = AutoPaginatedParams<
13
- operations['ecommerce_get_product_categories']['parameters']['query']
14
- >;
15
-
16
- type GetTaxesParams = AutoPaginatedParams<operations['ecommerce_get_taxes']['parameters']['query']>;
17
-
18
- type GetCountriesParams = AutoPaginatedParams<
19
- operations['ecommerce_get_countries']['parameters']['query']
20
- >;
21
-
22
- const ecommerceFactory = {
23
- getCustomers(): RequestData<components['schemas']['CommerceCustomerItem'][]> {
24
- return {
25
- method: 'get',
26
- url: '/consumers/{consumer_id}/commerce/customers',
27
- };
28
- },
29
- getProducts(): RequestData<components['schemas']['app__routers__commerce__ProductItem'][]> {
30
- return {
31
- method: 'get',
32
- url: '/consumers/{consumer_id}/commerce/products',
33
- };
34
- },
35
- getCustomer(customerId: string): RequestData<components['schemas']['CommerceCustomerItem']> {
36
- return {
37
- method: 'get',
38
- url: `/consumers/{consumer_id}/commerce/customers/${customerId}`,
39
- };
40
- },
41
- getProduct(
42
- productId: string
43
- ): RequestData<components['schemas']['app__routers__commerce__ProductItem']> {
44
- return {
45
- method: 'get',
46
- url: `/consumers/{consumer_id}/commerce/products/${productId}`,
47
- };
48
- },
49
- getProductVariantById(variantId: string): RequestData<components['schemas']['VariantItem']> {
50
- return {
51
- method: 'get',
52
- url: `/consumers/{consumer_id}/commerce/variants/${variantId}`,
53
- };
54
- },
55
- updateAvailableQuantity(
56
- variantId: string,
57
- inventoryDetails: components['schemas']['InventoryDetailsUpdate']
58
- ): RequestData<components['schemas']['InventoryDetailsItem']> {
59
- return {
60
- method: 'post',
61
- url: `/consumers/{consumer_id}/commerce/variants/set_quantity/${variantId}`,
62
- body: inventoryDetails,
63
- };
64
- },
65
- getLocations(): RequestData<components['schemas']['CommerceLocationItem'][]> {
66
- return {
67
- method: 'get',
68
- url: '/consumers/{consumer_id}/commerce/locations',
69
- };
70
- },
71
- getOrders(params?: GetOrdersParams): RequestData<components['schemas']['OrderItemOut'][]> {
72
- return {
73
- method: 'get',
74
- url: '/consumers/{consumer_id}/commerce/orders',
75
- params: params,
76
- };
77
- },
78
- createOrder(
79
- order: components['schemas']['OrderItemIn']
80
- ): RequestData<components['schemas']['OrderItemOut']> {
81
- return {
82
- method: 'post',
83
- url: `/consumers/{consumer_id}/commerce/orders`,
84
- body: order,
85
- };
86
- },
87
- getOrder(orderId: string): RequestData<components['schemas']['OrderItemOut']> {
88
- return {
89
- method: 'get',
90
- url: `/consumers/{consumer_id}/commerce/orders/${orderId}`,
91
- };
92
- },
93
- getPaymentMethods(
94
- params?: GetPaymentMethodsParams
95
- ): RequestData<components['schemas']['PaymentMethodItem'][]> {
96
- return {
97
- params,
98
- method: 'get',
99
- url: `/consumers/{consumer_id}/commerce/payment-methods`,
100
- };
101
- },
102
- getProductCategories(
103
- params?: GetProductCategoriesParams
104
- ): RequestData<components['schemas']['CategoryItem'][]> {
105
- return {
106
- params,
107
- method: 'get',
108
- url: `/consumers/{consumer_id}/commerce/product-categories`,
109
- };
110
- },
111
- getTaxes(params?: GetTaxesParams): RequestData<components['schemas']['TaxRateItem'][]> {
112
- return {
113
- params,
114
- method: 'get',
115
- url: `/consumers/{consumer_id}/commerce/taxes`,
116
- };
117
- },
118
- getCountries(params?: GetCountriesParams): RequestData<components['schemas']['CountryItem'][]> {
119
- return {
120
- params,
121
- method: 'get',
122
- url: `/consumers/{consumer_id}/commerce/countries`,
123
- };
124
- },
125
- };
126
-
127
- export { ecommerceFactory };
@@ -1,168 +0,0 @@
1
- import { components } from '../types/public-api/schema';
2
- import { InternalAPI } from './internalApi';
3
- import { Consumers } from './consumers';
4
- import { Consumer } from './consumer';
5
- import { SimpleResponseModel } from '../types/sync';
6
-
7
- const Flow = (
8
- internalApi: any,
9
- body: components['schemas']['ReadFlowItem'],
10
- syncid: string,
11
- consumers: string[],
12
- process?: (consumer: any, context: any) => any
13
- ) => {
14
- const _internalApi: InternalAPI = internalApi;
15
- const data: components['schemas']['ReadFlowItem'] = body;
16
- const _syncid = syncid;
17
- const _consumers = consumers;
18
- const _process = process;
19
-
20
- const sendEvent = async (payload: components['schemas']['PostSyncFlowEvent']) => {
21
- const { data: response }: { data: components['schemas']['TriggerResponse'] } =
22
- await _internalApi.post(`/syncs/${_syncid}/flows/${data.id}/event`, payload);
23
- return response;
24
- };
25
-
26
- const getExecution = async (executionId: string) => {
27
- const { data: response }: { data: components['schemas']['ChainExecutionItem'] } =
28
- await _internalApi.get(`/syncs/${_syncid}/flows/${data.id}/executions/${executionId}`);
29
- return response;
30
- };
31
-
32
- /**
33
- * Internal use: Function used to execute a flow while testing locally or by calling the sendEvent function
34
- */
35
- const execute = async ({ testData = {}, context = {} }: any) => {
36
- // first create the process in Chift (it will check if it's already created or not and execute it)
37
- await _internalApi.post(`/syncs/${_syncid}/flows`, {
38
- name: data.name,
39
- description: data.description,
40
- execution: data.execution,
41
- triggers: data.triggers,
42
- config: data.config,
43
- });
44
- // execute locally or remotely by sending an event to execute the flow
45
- if (context.local) {
46
- // when you execute locally you need to have a process defined
47
- const logs = context.logs || false;
48
- if (_process) executeLocal(_process, logs);
49
- else throw Error('Process is not defined it cannot be executed');
50
- } else {
51
- await sendEvent(testData);
52
- }
53
- };
54
-
55
- /**
56
- * Internal use: Function used to execute a flow locally based on the configured consumers.
57
- */
58
- const localExecution = async (process: (consumer: any, context: any) => any) => {
59
- _internalApi.debug = true;
60
- for (let i = 0; i < _consumers.length; i++) {
61
- // we do not care about the customer
62
- let consumer;
63
- try {
64
- consumer = await Consumers(_internalApi).getConsumerById(_consumers[i]);
65
- } catch (err) {
66
- console.log(
67
- `Cannot run for consumer ${_consumers[i]} as it cannot be found; probably part of an external account ? Use the platform to debug.`
68
- );
69
- }
70
- if (consumer) {
71
- const syncData = await consumer.getSyncData(_syncid);
72
- const flow = syncData.enabled_flows?.find((flow) => flow.id === data.id);
73
- if (flow && syncData.status === 'active') {
74
- const context = {
75
- ...syncData,
76
- flow_id: flow.id,
77
- flow_name: flow.name,
78
- flow_values: flow.values,
79
- flow_config: flow.config,
80
- };
81
- delete context['enabled_flows'];
82
- await process(consumer, context);
83
- } else {
84
- console.log(
85
- `Cannot run for consumer ${_consumers[i]} as the flow is not activated or not correctly configured`
86
- );
87
- }
88
- }
89
- }
90
- _internalApi.debug = false;
91
- };
92
-
93
- /**
94
- * Internal use: Function used to execute a flow locally for debugging purposes. It will create the executions server-side on Chift to be able to follow-up the execution through Chift's UI.
95
- * It will call localExecution to execute the flow for the configured consumers
96
- */
97
- const executeLocal = async (
98
- process: (consumer: typeof Consumer, context: any) => any,
99
- log = false
100
- ) => {
101
- if (log) {
102
- // create executions on the platform to add the logs to the server
103
- const { data: response }: { data: SimpleResponseModel } = await _internalApi.post(
104
- `/syncs/${_syncid}/flows/${data.id}/local`,
105
- { type: 'START' }
106
- );
107
- if (response.data) {
108
- const { executionid, chainexecutionid } = response.data;
109
- _internalApi.setRelatedChainExecutionId(chainexecutionid);
110
- try {
111
- await localExecution(process);
112
- await _internalApi.post(`/syncs/${_syncid}/flows/${data.id}/local`, {
113
- type: 'END',
114
- executionid: executionid,
115
- chainexecutionid: chainexecutionid,
116
- });
117
- } catch (err: any) {
118
- if (err.error) {
119
- // it's an error from the one api
120
- const error_message = `Error when executing request with url ${err.url} for consumer ${err.consumerName} (${err.consumerId})`;
121
- console.log(`[ERROR]: ${error_message}: ${JSON.stringify(err.error)}`);
122
- await _internalApi.post(`/syncs/${_syncid}/flows/${data.id}/local`, {
123
- type: 'END',
124
- executionid: executionid,
125
- chainexecutionid: chainexecutionid,
126
- error: true,
127
- error_message: error_message,
128
- technical_error_message: JSON.stringify(err.error),
129
- });
130
- } else {
131
- console.log('[ERROR]: ' + err.toString());
132
- await _internalApi.post(`/syncs/${_syncid}/flows/${data.id}/local`, {
133
- type: 'END',
134
- executionid: executionid,
135
- chainexecutionid: chainexecutionid,
136
- error: true,
137
- technical_error_message: err.toString(),
138
- });
139
- }
140
- }
141
- _internalApi.setRelatedChainExecutionId('');
142
- } else {
143
- throw Error('Execution could not be executed');
144
- }
145
- } else {
146
- try {
147
- await localExecution(process);
148
- } catch (err: any) {
149
- if (err.error) {
150
- const error_message = `Error when executing request with url ${err.url} for consumer ${err.consumerName} (${err.consumerId})`;
151
- console.log(`[ERROR] ${error_message}: ${JSON.stringify(err.error)}`);
152
- } else {
153
- console.log('[ERROR]: ' + err.toString());
154
- }
155
- }
156
- }
157
- };
158
-
159
- return {
160
- execute,
161
- getExecution,
162
- executeLocal,
163
- flowId: data.id,
164
- name: data.name,
165
- };
166
- };
167
-
168
- export { Flow };
@@ -1,24 +0,0 @@
1
- import { operations } from '../types/public-api/schema';
2
- import { InternalAPI } from './internalApi';
3
- import { chiftOperations } from '../types/public-api/mappings';
4
-
5
- const Integrations = (internalApi: InternalAPI) => {
6
- const _internalApi: InternalAPI = internalApi;
7
-
8
- const getIntegrations = async (
9
- params: operations[chiftOperations['getIntegrations']]['parameters']['query'] = {}
10
- ) => {
11
- const {
12
- data,
13
- }: {
14
- data: operations[chiftOperations['getIntegrations']]['responses'][200]['content']['application/json'];
15
- } = await _internalApi.get('/integrations', { params });
16
- return data;
17
- };
18
-
19
- return {
20
- getIntegrations,
21
- };
22
- };
23
-
24
- export { Integrations };