@chift/chift-nodejs 1.0.17 → 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.
- package/package.json +5 -2
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -25
- package/.github/workflows/ci.yml +0 -75
- package/.husky/pre-commit +0 -4
- package/.prettierignore +0 -1
- package/.prettierrc.json +0 -7
- package/CHANGELOG.md +0 -108
- package/dist/src/helpers/openapi.d.ts +0 -3
- package/dist/src/helpers/openapi.js +0 -18
- package/dist/src/helpers/settings.d.ts +0 -4
- package/dist/src/helpers/settings.js +0 -5
- package/dist/src/index.d.ts +0 -1
- package/dist/src/modules/accounting.d.ts +0 -68
- package/dist/src/modules/accounting.js +0 -326
- package/dist/src/modules/api.d.ts +0 -18351
- package/dist/src/modules/api.js +0 -36
- package/dist/src/modules/consumer.d.ts +0 -3622
- package/dist/src/modules/consumer.js +0 -142
- package/dist/src/modules/consumers.d.ts +0 -18237
- package/dist/src/modules/consumers.js +0 -51
- package/dist/src/modules/custom.d.ts +0 -8
- package/dist/src/modules/custom.js +0 -36
- package/dist/src/modules/datastores.d.ts +0 -18
- package/dist/src/modules/datastores.js +0 -23
- package/dist/src/modules/ecommerce.d.ts +0 -24
- package/dist/src/modules/ecommerce.js +0 -97
- package/dist/src/modules/flow.d.ts +0 -15
- package/dist/src/modules/flow.js +0 -156
- package/dist/src/modules/integrations.d.ts +0 -23
- package/dist/src/modules/integrations.js +0 -23
- package/dist/src/modules/internalApi.d.ts +0 -24
- package/dist/src/modules/internalApi.js +0 -175
- package/dist/src/modules/invoicing.d.ts +0 -20
- package/dist/src/modules/invoicing.js +0 -90
- package/dist/src/modules/payment.d.ts +0 -14
- package/dist/src/modules/payment.js +0 -41
- package/dist/src/modules/pms.d.ts +0 -15
- package/dist/src/modules/pms.js +0 -47
- package/dist/src/modules/pos.d.ts +0 -26
- package/dist/src/modules/pos.js +0 -101
- package/dist/src/modules/sync.d.ts +0 -14654
- package/dist/src/modules/sync.js +0 -73
- package/dist/src/modules/syncs.d.ts +0 -11
- package/dist/src/modules/syncs.js +0 -39
- package/dist/src/modules/webhooks.d.ts +0 -58
- package/dist/src/modules/webhooks.js +0 -53
- package/dist/src/types/api.d.ts +0 -29
- package/dist/src/types/api.js +0 -2
- package/dist/src/types/consumers.d.ts +0 -8
- package/dist/src/types/consumers.js +0 -2
- package/dist/src/types/public-api/mappings.d.ts +0 -21
- package/dist/src/types/public-api/mappings.js +0 -2
- package/dist/src/types/sync.d.ts +0 -37
- package/dist/src/types/sync.js +0 -2
- package/dist/test/modules/accounting.test.d.ts +0 -1
- package/dist/test/modules/accounting.test.js +0 -590
- package/dist/test/modules/consumer.test.d.ts +0 -1
- package/dist/test/modules/consumer.test.js +0 -89
- package/dist/test/modules/consumers.test.d.ts +0 -1
- package/dist/test/modules/consumers.test.js +0 -109
- package/dist/test/modules/ecommerce.test.d.ts +0 -1
- package/dist/test/modules/ecommerce.test.js +0 -224
- package/dist/test/modules/integrations.test.d.ts +0 -1
- package/dist/test/modules/integrations.test.js +0 -54
- package/dist/test/modules/invoicing.test.d.ts +0 -1
- package/dist/test/modules/invoicing.test.js +0 -115
- package/dist/test/modules/payment.test.d.ts +0 -1
- package/dist/test/modules/payment.test.js +0 -88
- package/dist/test/modules/pms.test.d.ts +0 -1
- package/dist/test/modules/pms.test.js +0 -90
- package/dist/test/modules/pos.test.d.ts +0 -1
- package/dist/test/modules/pos.test.js +0 -179
- package/dist/test/modules/sync.test.d.ts +0 -1
- package/dist/test/modules/sync.test.js +0 -93
- package/dist/test/modules/syncs.test.d.ts +0 -1
- package/dist/test/modules/syncs.test.js +0 -53
- package/dist/test/modules/webhooks.test.d.ts +0 -1
- package/dist/test/modules/webhooks.test.js +0 -120
- package/jest.config.ts +0 -195
- package/src/helpers/openapi.ts +0 -22
- package/src/helpers/settings.ts +0 -3
- package/src/index.ts +0 -1
- package/src/modules/accounting.ts +0 -510
- package/src/modules/api.ts +0 -35
- package/src/modules/consumer.ts +0 -216
- package/src/modules/consumers.ts +0 -82
- package/src/modules/custom.ts +0 -36
- package/src/modules/datastores.ts +0 -19
- package/src/modules/ecommerce.ts +0 -129
- package/src/modules/flow.ts +0 -168
- package/src/modules/integrations.ts +0 -24
- package/src/modules/internalApi.ts +0 -182
- package/src/modules/invoicing.ts +0 -118
- package/src/modules/payment.ts +0 -59
- package/src/modules/pms.ts +0 -67
- package/src/modules/pos.ts +0 -144
- package/src/modules/sync.ts +0 -77
- package/src/modules/syncs.ts +0 -59
- package/src/modules/webhooks.ts +0 -86
- package/test/data/accounting_invoice.pdf +0 -0
- package/test/modules/accounting.test.ts +0 -647
- package/test/modules/consumer.test.ts +0 -68
- package/test/modules/consumers.test.ts +0 -85
- package/test/modules/ecommerce.test.ts +0 -213
- package/test/modules/integrations.test.ts +0 -22
- package/test/modules/invoicing.test.ts +0 -98
- package/test/modules/payment.test.ts +0 -65
- package/test/modules/pms.test.ts +0 -69
- package/test/modules/pos.test.ts +0 -164
- package/test/modules/sync.test.ts +0 -74
- package/test/modules/syncs.test.ts +0 -23
- package/test/modules/webhooks.test.ts +0 -92
- package/tsconfig.json +0 -107
package/src/modules/consumer.ts
DELETED
|
@@ -1,216 +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 { paymentFactory } from './payment';
|
|
7
|
-
import { createApiFor } from '../helpers/openapi';
|
|
8
|
-
import { accountingFactory } from './accounting';
|
|
9
|
-
import { invoicingFactory } from './invoicing';
|
|
10
|
-
import { ecommerceFactory } from './ecommerce';
|
|
11
|
-
import { customFactory } from './custom';
|
|
12
|
-
import { SimpleResponseModel } from '../types/sync';
|
|
13
|
-
import { ConsumerLog } from '../types/consumers';
|
|
14
|
-
|
|
15
|
-
const Consumer = (
|
|
16
|
-
internalApi: InternalAPI,
|
|
17
|
-
body: operations[chiftOperations['getConsumerById']]['responses'][200]['content']['application/json']
|
|
18
|
-
) => {
|
|
19
|
-
const _internalApi = internalApi;
|
|
20
|
-
const data = body;
|
|
21
|
-
const consumerId = data.consumerid;
|
|
22
|
-
const name = data.name;
|
|
23
|
-
const redirect_url = data.redirect_url;
|
|
24
|
-
const email = data.email;
|
|
25
|
-
const pos = createApiFor(posFactory, _internalApi, data.name, consumerId);
|
|
26
|
-
const pms = createApiFor(pmsFactory, _internalApi, data.name, consumerId);
|
|
27
|
-
const payment = createApiFor(paymentFactory, _internalApi, data.name, consumerId);
|
|
28
|
-
const accounting = createApiFor(accountingFactory, _internalApi, data.name, consumerId);
|
|
29
|
-
const invoicing = createApiFor(invoicingFactory, _internalApi, data.name, consumerId);
|
|
30
|
-
const ecommerce = createApiFor(ecommerceFactory, _internalApi, data.name, consumerId);
|
|
31
|
-
const custom = createApiFor(customFactory, _internalApi, data.name, consumerId);
|
|
32
|
-
|
|
33
|
-
const setConnectionId = async (connectionId: string) => {
|
|
34
|
-
_internalApi.connectionId = connectionId;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const setIntegrationId = async (integrationId: string) => {
|
|
38
|
-
_internalApi.integrationId = integrationId;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const getConnections = async () => {
|
|
42
|
-
const {
|
|
43
|
-
data,
|
|
44
|
-
}: {
|
|
45
|
-
data: operations[chiftOperations['getConnectionsByConsumerId']]['responses'][200]['content']['application/json'];
|
|
46
|
-
} = await _internalApi.get(`/consumers/${consumerId}/connections`);
|
|
47
|
-
return data;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const createConnection = async (
|
|
51
|
-
body?: components['schemas']['backbone_api__app__routers__connections__PostConnectionItem']
|
|
52
|
-
) => {
|
|
53
|
-
const {
|
|
54
|
-
data,
|
|
55
|
-
}: {
|
|
56
|
-
data: operations[chiftOperations['createConnection']]['responses'][200]['content']['application/json'];
|
|
57
|
-
} = await _internalApi.post(`/consumers/${consumerId}/connections`, { ...body });
|
|
58
|
-
return data;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const updateConnection = async (
|
|
62
|
-
connectionId: string,
|
|
63
|
-
body?: components['schemas']['PatchConnectionItem']
|
|
64
|
-
) => {
|
|
65
|
-
const {
|
|
66
|
-
data,
|
|
67
|
-
}: {
|
|
68
|
-
data: operations[chiftOperations['updateConnection']]['responses'][200]['content']['application/json'];
|
|
69
|
-
} = await _internalApi.patch(`/consumers/${consumerId}/connections/${connectionId}`, {
|
|
70
|
-
...body,
|
|
71
|
-
});
|
|
72
|
-
return data;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const deleteConnection = async (connectionId: string) => {
|
|
76
|
-
const {
|
|
77
|
-
data,
|
|
78
|
-
}: { data: operations[chiftOperations['deleteConnectionById']]['responses'][204] } =
|
|
79
|
-
await _internalApi.delete(`/consumers/${consumerId}/connections/${connectionId}`);
|
|
80
|
-
return data;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const getSyncUrl = async (body: components['schemas']['CreateConsumerSyncItem']) => {
|
|
84
|
-
const { data }: { data: components['schemas']['LinkSyncItem'] } = await _internalApi.post(
|
|
85
|
-
`/consumers/${consumerId}/syncs`,
|
|
86
|
-
body
|
|
87
|
-
);
|
|
88
|
-
return data;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const getSyncData = async (syncId: string) => {
|
|
92
|
-
const { data }: { data: components['schemas']['SyncConsumerItem'] } =
|
|
93
|
-
await _internalApi.get(`/consumers/${consumerId}/syncs/${syncId}`);
|
|
94
|
-
return data;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const enableFlow = async (
|
|
98
|
-
syncId: string,
|
|
99
|
-
flowId: string,
|
|
100
|
-
body: components['schemas']['EnableFlowConsumer']
|
|
101
|
-
) => {
|
|
102
|
-
const { data }: { data: SimpleResponseModel } = await _internalApi.post(
|
|
103
|
-
`/consumers/${consumerId}/syncs/${syncId}/flows/${flowId}/enable`,
|
|
104
|
-
body
|
|
105
|
-
);
|
|
106
|
-
return data;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const getDataByDataStoreName = async (dataStoreName: string, params?: object) => {
|
|
110
|
-
const { data }: { data: components['schemas']['DataStoreItem'][] } = await _internalApi.get(
|
|
111
|
-
`/datastores`
|
|
112
|
-
);
|
|
113
|
-
for (let i = 0; i < data.length; i++) {
|
|
114
|
-
if (data[i].name == dataStoreName) {
|
|
115
|
-
return await getDataByDataStoreId(data[i].id, params);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
throw Error('Datastore could not be found');
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const getDataByDataStoreId = async (dataStoreId: string, params?: object) => {
|
|
122
|
-
const { data }: { data: components['schemas']['DataItemOut'][] } = await _internalApi.get(
|
|
123
|
-
`/consumers/${consumerId}/datastore/${dataStoreId}/data`,
|
|
124
|
-
{ params: params }
|
|
125
|
-
);
|
|
126
|
-
return data;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
const addDataByDataStoreId = async (
|
|
130
|
-
dataStoreId: string,
|
|
131
|
-
data: components['schemas']['DataItem'][]
|
|
132
|
-
) => {
|
|
133
|
-
const { data: response }: { data: components['schemas']['DataItemOut'][] } =
|
|
134
|
-
await _internalApi.post(`/consumers/${consumerId}/datastore/${dataStoreId}/data`, data);
|
|
135
|
-
return response;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const addDataByDataStoreName = async (
|
|
139
|
-
dataStoreName: string,
|
|
140
|
-
data: components['schemas']['DataItem'][]
|
|
141
|
-
) => {
|
|
142
|
-
const { data: datastores }: { data: components['schemas']['DataStoreItem'][] } =
|
|
143
|
-
await _internalApi.get(`/datastores`);
|
|
144
|
-
for (let i = 0; i < datastores.length; i++) {
|
|
145
|
-
if (datastores[i].name == dataStoreName) {
|
|
146
|
-
return await addDataByDataStoreId(datastores[i].id, data);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
const updateDataStoreData = async (
|
|
152
|
-
dataStoreId: string,
|
|
153
|
-
dataStoreDataId: string,
|
|
154
|
-
data: components['schemas']['DataItem']
|
|
155
|
-
) => {
|
|
156
|
-
const { data: response }: { data: components['schemas']['DataItemOut'][] } =
|
|
157
|
-
await _internalApi.patch(
|
|
158
|
-
`/consumers/${consumerId}/datastore/${dataStoreId}/data/${dataStoreDataId}`,
|
|
159
|
-
data
|
|
160
|
-
);
|
|
161
|
-
return response;
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const deleteDataStoreData = async (dataStoreId: string, dataStoreDataId: string) => {
|
|
165
|
-
const { data: response }: { data: SimpleResponseModel } = await _internalApi.delete(
|
|
166
|
-
`/consumers/${consumerId}/datastore/${dataStoreId}/data/${dataStoreDataId}`
|
|
167
|
-
);
|
|
168
|
-
return response;
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* This function is used to add logs related to a chainexecution (passed in the header)
|
|
173
|
-
* INTERNAL USE only
|
|
174
|
-
* @param logs
|
|
175
|
-
* @returns
|
|
176
|
-
*/
|
|
177
|
-
const logData = async (logs: ConsumerLog[]) => {
|
|
178
|
-
const { data: response }: { data: SimpleResponseModel } = await _internalApi.post(
|
|
179
|
-
`/consumers/${consumerId}/logs`,
|
|
180
|
-
logs
|
|
181
|
-
);
|
|
182
|
-
return response;
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
return {
|
|
186
|
-
consumerId,
|
|
187
|
-
getConnections,
|
|
188
|
-
createConnection,
|
|
189
|
-
updateConnection,
|
|
190
|
-
deleteConnection,
|
|
191
|
-
enableFlow,
|
|
192
|
-
getSyncUrl,
|
|
193
|
-
name,
|
|
194
|
-
redirect_url,
|
|
195
|
-
email,
|
|
196
|
-
pos,
|
|
197
|
-
pms,
|
|
198
|
-
payment,
|
|
199
|
-
accounting,
|
|
200
|
-
invoicing,
|
|
201
|
-
ecommerce,
|
|
202
|
-
custom,
|
|
203
|
-
getDataByDataStoreId,
|
|
204
|
-
addDataByDataStoreId,
|
|
205
|
-
getSyncData,
|
|
206
|
-
getDataByDataStoreName,
|
|
207
|
-
addDataByDataStoreName,
|
|
208
|
-
updateDataStoreData,
|
|
209
|
-
deleteDataStoreData,
|
|
210
|
-
logData,
|
|
211
|
-
setConnectionId,
|
|
212
|
-
setIntegrationId,
|
|
213
|
-
};
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
export { Consumer };
|
package/src/modules/consumers.ts
DELETED
|
@@ -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 };
|
package/src/modules/custom.ts
DELETED
|
@@ -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 };
|
package/src/modules/ecommerce.ts
DELETED
|
@@ -1,129 +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<
|
|
30
|
-
components['schemas']['backbone_api__app__routers__commerce__ProductItem'][]
|
|
31
|
-
> {
|
|
32
|
-
return {
|
|
33
|
-
method: 'get',
|
|
34
|
-
url: '/consumers/{consumer_id}/commerce/products',
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
getCustomer(customerId: string): RequestData<components['schemas']['CommerceCustomerItem']> {
|
|
38
|
-
return {
|
|
39
|
-
method: 'get',
|
|
40
|
-
url: `/consumers/{consumer_id}/commerce/customers/${customerId}`,
|
|
41
|
-
};
|
|
42
|
-
},
|
|
43
|
-
getProduct(
|
|
44
|
-
productId: string
|
|
45
|
-
): RequestData<components['schemas']['backbone_api__app__routers__commerce__ProductItem']> {
|
|
46
|
-
return {
|
|
47
|
-
method: 'get',
|
|
48
|
-
url: `/consumers/{consumer_id}/commerce/products/${productId}`,
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
getProductVariantById(variantId: string): RequestData<components['schemas']['VariantItem']> {
|
|
52
|
-
return {
|
|
53
|
-
method: 'get',
|
|
54
|
-
url: `/consumers/{consumer_id}/commerce/variants/${variantId}`,
|
|
55
|
-
};
|
|
56
|
-
},
|
|
57
|
-
updateAvailableQuantity(
|
|
58
|
-
variantId: string,
|
|
59
|
-
inventoryDetails: components['schemas']['InventoryDetailsUpdate']
|
|
60
|
-
): RequestData<components['schemas']['InventoryDetailsItem']> {
|
|
61
|
-
return {
|
|
62
|
-
method: 'post',
|
|
63
|
-
url: `/consumers/{consumer_id}/commerce/variants/set_quantity/${variantId}`,
|
|
64
|
-
body: inventoryDetails,
|
|
65
|
-
};
|
|
66
|
-
},
|
|
67
|
-
getLocations(): RequestData<components['schemas']['CommerceLocationItem'][]> {
|
|
68
|
-
return {
|
|
69
|
-
method: 'get',
|
|
70
|
-
url: '/consumers/{consumer_id}/commerce/locations',
|
|
71
|
-
};
|
|
72
|
-
},
|
|
73
|
-
getOrders(params?: GetOrdersParams): RequestData<components['schemas']['OrderItemOut'][]> {
|
|
74
|
-
return {
|
|
75
|
-
method: 'get',
|
|
76
|
-
url: '/consumers/{consumer_id}/commerce/orders',
|
|
77
|
-
params: params,
|
|
78
|
-
};
|
|
79
|
-
},
|
|
80
|
-
createOrder(
|
|
81
|
-
order: components['schemas']['OrderItemIn']
|
|
82
|
-
): RequestData<components['schemas']['OrderItemOut']> {
|
|
83
|
-
return {
|
|
84
|
-
method: 'post',
|
|
85
|
-
url: `/consumers/{consumer_id}/commerce/orders`,
|
|
86
|
-
body: order,
|
|
87
|
-
};
|
|
88
|
-
},
|
|
89
|
-
getOrder(orderId: string): RequestData<components['schemas']['OrderItemOut']> {
|
|
90
|
-
return {
|
|
91
|
-
method: 'get',
|
|
92
|
-
url: `/consumers/{consumer_id}/commerce/orders/${orderId}`,
|
|
93
|
-
};
|
|
94
|
-
},
|
|
95
|
-
getPaymentMethods(
|
|
96
|
-
params?: GetPaymentMethodsParams
|
|
97
|
-
): RequestData<components['schemas']['PaymentMethodItem'][]> {
|
|
98
|
-
return {
|
|
99
|
-
params,
|
|
100
|
-
method: 'get',
|
|
101
|
-
url: `/consumers/{consumer_id}/commerce/payment-methods`,
|
|
102
|
-
};
|
|
103
|
-
},
|
|
104
|
-
getProductCategories(
|
|
105
|
-
params?: GetProductCategoriesParams
|
|
106
|
-
): RequestData<components['schemas']['CategoryItem'][]> {
|
|
107
|
-
return {
|
|
108
|
-
params,
|
|
109
|
-
method: 'get',
|
|
110
|
-
url: `/consumers/{consumer_id}/commerce/product-categories`,
|
|
111
|
-
};
|
|
112
|
-
},
|
|
113
|
-
getTaxes(params?: GetTaxesParams): RequestData<components['schemas']['TaxRateItem'][]> {
|
|
114
|
-
return {
|
|
115
|
-
params,
|
|
116
|
-
method: 'get',
|
|
117
|
-
url: `/consumers/{consumer_id}/commerce/taxes`,
|
|
118
|
-
};
|
|
119
|
-
},
|
|
120
|
-
getCountries(params?: GetCountriesParams): RequestData<components['schemas']['CountryItem'][]> {
|
|
121
|
-
return {
|
|
122
|
-
params,
|
|
123
|
-
method: 'get',
|
|
124
|
-
url: `/consumers/{consumer_id}/commerce/countries`,
|
|
125
|
-
};
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
export { ecommerceFactory };
|
package/src/modules/flow.ts
DELETED
|
@@ -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 };
|