@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.
- package/README.md +3 -3
- package/package.json +5 -2
- package/src/types/public-api/schema.d.ts +4071 -850
- package/src/types/sync.ts +20 -5
- package/.eslintcache +0 -1
- 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 -98
- package/coverage/clover.xml +0 -1645
- package/coverage/coverage-final.json +0 -19
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -146
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/src/helpers/index.html +0 -131
- package/coverage/lcov-report/src/helpers/openapi.ts.html +0 -151
- package/coverage/lcov-report/src/helpers/settings.ts.html +0 -94
- package/coverage/lcov-report/src/index.html +0 -116
- package/coverage/lcov-report/src/index.ts.html +0 -88
- package/coverage/lcov-report/src/modules/accounting.ts.html +0 -1156
- package/coverage/lcov-report/src/modules/api.ts.html +0 -190
- package/coverage/lcov-report/src/modules/consumer.ts.html +0 -616
- package/coverage/lcov-report/src/modules/consumers.ts.html +0 -331
- package/coverage/lcov-report/src/modules/custom.ts.html +0 -193
- package/coverage/lcov-report/src/modules/datastores.ts.html +0 -142
- package/coverage/lcov-report/src/modules/ecommerce.ts.html +0 -331
- package/coverage/lcov-report/src/modules/flow.ts.html +0 -589
- package/coverage/lcov-report/src/modules/index.html +0 -326
- package/coverage/lcov-report/src/modules/integrations.ts.html +0 -151
- package/coverage/lcov-report/src/modules/internalApi.ts.html +0 -586
- package/coverage/lcov-report/src/modules/invoicing.ts.html +0 -391
- package/coverage/lcov-report/src/modules/pos.ts.html +0 -421
- package/coverage/lcov-report/src/modules/sync.ts.html +0 -316
- package/coverage/lcov-report/src/modules/syncs.ts.html +0 -169
- package/coverage/lcov-report/src/modules/webhooks.ts.html +0 -343
- package/coverage/lcov.info +0 -1976
- 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 -16795
- package/dist/src/modules/api.js +0 -36
- package/dist/src/modules/consumer.d.ts +0 -3313
- package/dist/src/modules/consumer.js +0 -139
- package/dist/src/modules/consumers.d.ts +0 -16684
- 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/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 -13414
- 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 -55
- 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/public-api/schema.d.ts +0 -12003
- package/dist/src/types/public-api/schema.js +0 -6
- package/dist/src/types/sync.d.ts +0 -20
- 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 -582
- 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 -220
- 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 -108
- package/dist/test/modules/pos.test.d.ts +0 -1
- package/dist/test/modules/pos.test.js +0 -182
- package/dist/test/modules/sync.test.d.ts +0 -1
- package/dist/test/modules/sync.test.js +0 -81
- 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 -213
- 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 -127
- 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 -114
- 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/src/types/public-api/schema.ts +0 -12073
- package/test/data/accounting_invoice.pdf +0 -0
- package/test/modules/accounting.test.ts +0 -628
- package/test/modules/consumer.test.ts +0 -68
- package/test/modules/consumers.test.ts +0 -85
- package/test/modules/ecommerce.test.ts +0 -208
- package/test/modules/integrations.test.ts +0 -22
- package/test/modules/invoicing.test.ts +0 -88
- package/test/modules/pos.test.ts +0 -166
- package/test/modules/sync.test.ts +0 -60
- package/test/modules/syncs.test.ts +0 -23
- package/test/modules/webhooks.test.ts +0 -92
- package/test/set_envs.sh +0 -14
- package/tsconfig.json +0 -107
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import axios, { AxiosInstance } from 'axios';
|
|
2
|
-
import { AuthType, TokenType, RequestData } from '../types/api';
|
|
3
|
-
import Settings from '../helpers/settings';
|
|
4
|
-
|
|
5
|
-
class InternalAPI {
|
|
6
|
-
instance: AxiosInstance;
|
|
7
|
-
auth: AuthType;
|
|
8
|
-
token?: TokenType;
|
|
9
|
-
debug = false;
|
|
10
|
-
relatedChainExecutionId?: string;
|
|
11
|
-
connectionId?: string;
|
|
12
|
-
integrationId?: string;
|
|
13
|
-
get;
|
|
14
|
-
post;
|
|
15
|
-
patch;
|
|
16
|
-
delete;
|
|
17
|
-
|
|
18
|
-
constructor(auth: AuthType) {
|
|
19
|
-
// add interceptor
|
|
20
|
-
this.auth = auth;
|
|
21
|
-
this.instance = axios.create({
|
|
22
|
-
baseURL: this.auth.baseUrl || Settings.BASE_URL,
|
|
23
|
-
});
|
|
24
|
-
this.get = this.instance.get;
|
|
25
|
-
this.post = this.instance.post;
|
|
26
|
-
this.patch = this.instance.patch;
|
|
27
|
-
this.delete = this.instance.delete;
|
|
28
|
-
|
|
29
|
-
this.instance.interceptors.request.use(
|
|
30
|
-
(config) => {
|
|
31
|
-
return new Promise((resolve, reject) => {
|
|
32
|
-
if (this.connectionId) {
|
|
33
|
-
config.headers['X-Chift-ConnectionId'] = this.connectionId;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (this.integrationId) {
|
|
37
|
-
config.headers['X-Chift-IntegrationId'] = this.integrationId;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (this.relatedChainExecutionId) {
|
|
41
|
-
config.headers['X-Chift-RelatedChainExecutionId'] =
|
|
42
|
-
this.relatedChainExecutionId;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (this.token) {
|
|
46
|
-
if (this.token?.expires_on < new Date().getTime()) {
|
|
47
|
-
return this.getToken()
|
|
48
|
-
.then(() => {
|
|
49
|
-
config.headers['Authorization'] =
|
|
50
|
-
'Bearer ' + this.token?.access_token;
|
|
51
|
-
return resolve(config);
|
|
52
|
-
})
|
|
53
|
-
.catch((err) => {
|
|
54
|
-
return reject(err);
|
|
55
|
-
});
|
|
56
|
-
} else {
|
|
57
|
-
config.headers['Authorization'] = 'Bearer ' + this.token?.access_token;
|
|
58
|
-
return resolve(config);
|
|
59
|
-
}
|
|
60
|
-
} else {
|
|
61
|
-
return this.getToken()
|
|
62
|
-
.then(() => {
|
|
63
|
-
config.headers['Authorization'] =
|
|
64
|
-
'Bearer ' + this.token?.access_token;
|
|
65
|
-
return resolve(config);
|
|
66
|
-
})
|
|
67
|
-
.catch((err) => {
|
|
68
|
-
return reject(err);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
},
|
|
73
|
-
function (error) {
|
|
74
|
-
// Do something with request error
|
|
75
|
-
return Promise.reject(error);
|
|
76
|
-
}
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
getToken = async () => {
|
|
81
|
-
try {
|
|
82
|
-
const tokenData: AuthType = {
|
|
83
|
-
clientId: this.auth.clientId,
|
|
84
|
-
clientSecret: this.auth.clientSecret,
|
|
85
|
-
accountId: this.auth.accountId,
|
|
86
|
-
};
|
|
87
|
-
if (this.auth.envId) {
|
|
88
|
-
tokenData['envId'] = this.auth.envId;
|
|
89
|
-
}
|
|
90
|
-
const res = await axios.post(
|
|
91
|
-
`${this.auth.baseUrl || Settings.BASE_URL}/token`,
|
|
92
|
-
tokenData
|
|
93
|
-
);
|
|
94
|
-
this.token = res.data;
|
|
95
|
-
} catch (err: any) {
|
|
96
|
-
if (axios.isAxiosError(err)) {
|
|
97
|
-
if (err.response) {
|
|
98
|
-
if (err.response.status === 401) {
|
|
99
|
-
throw new Error('The provided credentials are not correct');
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
getPaginationParams = (currPage: number) => {
|
|
107
|
-
return {
|
|
108
|
-
page: currPage,
|
|
109
|
-
size: 100,
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
public setRelatedChainExecutionId(chainExecutionId: string) {
|
|
114
|
-
this.relatedChainExecutionId = chainExecutionId;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
public async makeRequest<TResponse>(requestData: RequestData<TResponse>) {
|
|
118
|
-
try {
|
|
119
|
-
if (this.debug) {
|
|
120
|
-
console.log(
|
|
121
|
-
`[DEBUG]: Executing operation ${requestData?.property} with url ${requestData.url} for consumer: ${requestData.consumerName}`
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
let continuePagination = true;
|
|
125
|
-
let items: any[] = [];
|
|
126
|
-
let currentPage = 0;
|
|
127
|
-
while (continuePagination) {
|
|
128
|
-
currentPage++;
|
|
129
|
-
let params = requestData.params || {};
|
|
130
|
-
if (requestData.method === 'get') {
|
|
131
|
-
params = {
|
|
132
|
-
...params,
|
|
133
|
-
...this.getPaginationParams(currentPage),
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
const res = await this.instance({
|
|
137
|
-
url: requestData.url,
|
|
138
|
-
method: requestData.method,
|
|
139
|
-
params: params,
|
|
140
|
-
data: requestData.body !== undefined ? requestData.body : undefined,
|
|
141
|
-
});
|
|
142
|
-
const { data } = res;
|
|
143
|
-
if (data) {
|
|
144
|
-
if (requestData.method === 'get' && 'total' in data && 'items' in data) {
|
|
145
|
-
if (currentPage * 100 > data.total) {
|
|
146
|
-
continuePagination = false;
|
|
147
|
-
}
|
|
148
|
-
} else {
|
|
149
|
-
if (this.debug) {
|
|
150
|
-
console.log(`[DEBUG]: Data received: ${JSON.stringify(data)}`);
|
|
151
|
-
}
|
|
152
|
-
return data;
|
|
153
|
-
}
|
|
154
|
-
items = items.concat(data.items);
|
|
155
|
-
} else {
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (this.debug) {
|
|
160
|
-
console.log(`[DEBUG]: Data received: ${JSON.stringify(items)}`);
|
|
161
|
-
}
|
|
162
|
-
return items;
|
|
163
|
-
} catch (e: any) {
|
|
164
|
-
if (e.response) {
|
|
165
|
-
if (e.response.data) {
|
|
166
|
-
const error = { ...e.response.data, status_code: e.response.status };
|
|
167
|
-
const fullerror = {
|
|
168
|
-
error,
|
|
169
|
-
consumerId: requestData.consumerId,
|
|
170
|
-
consumerName: requestData.consumerName,
|
|
171
|
-
url: requestData.url,
|
|
172
|
-
};
|
|
173
|
-
//return error as TResponse;
|
|
174
|
-
throw fullerror;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
throw e;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export { InternalAPI };
|
package/src/modules/invoicing.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { components, operations } from '../types/public-api/schema';
|
|
2
|
-
import { AutoPaginatedParams, RequestData } from '../types/api';
|
|
3
|
-
|
|
4
|
-
type GetInvoicesParams = AutoPaginatedParams<
|
|
5
|
-
operations['invoicing_get_invoices']['parameters']['query']
|
|
6
|
-
>;
|
|
7
|
-
|
|
8
|
-
type GetContactsParams = AutoPaginatedParams<
|
|
9
|
-
operations['invoicing_get_contacts']['parameters']['query']
|
|
10
|
-
>;
|
|
11
|
-
|
|
12
|
-
const invoicingFactory = {
|
|
13
|
-
getInvoices(
|
|
14
|
-
params?: GetInvoicesParams
|
|
15
|
-
): RequestData<components['schemas']['InvoiceItemOut'][]> {
|
|
16
|
-
return {
|
|
17
|
-
method: 'get',
|
|
18
|
-
url: `/consumers/{consumer_id}/invoicing/invoices`,
|
|
19
|
-
params: params,
|
|
20
|
-
};
|
|
21
|
-
},
|
|
22
|
-
getInvoiceById(
|
|
23
|
-
invoiceId: string,
|
|
24
|
-
params?: operations['invoicing_get_invoice']['parameters']['query']
|
|
25
|
-
): RequestData<components['schemas']['InvoiceItemOut']> {
|
|
26
|
-
return {
|
|
27
|
-
method: 'get',
|
|
28
|
-
url: `/consumers/{consumer_id}/invoicing/invoices/${invoiceId}`,
|
|
29
|
-
params: params,
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
createInvoice(
|
|
33
|
-
invoice: components['schemas']['InvoiceItem']
|
|
34
|
-
): RequestData<components['schemas']['InvoiceItemOut']> {
|
|
35
|
-
return {
|
|
36
|
-
method: 'create',
|
|
37
|
-
url: `/consumers/{consumer_id}/invoicing/invoices`,
|
|
38
|
-
body: invoice,
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
getProducts(): RequestData<components['schemas']['ProductItemOut'][]> {
|
|
42
|
-
return {
|
|
43
|
-
method: 'get',
|
|
44
|
-
url: `/consumers/{consumer_id}/invoicing/products`,
|
|
45
|
-
};
|
|
46
|
-
},
|
|
47
|
-
getProductById(productId: string): RequestData<components['schemas']['ProductItemOut']> {
|
|
48
|
-
return {
|
|
49
|
-
method: 'get',
|
|
50
|
-
url: `/consumers/{consumer_id}/invoicing/products/${productId}`,
|
|
51
|
-
};
|
|
52
|
-
},
|
|
53
|
-
createProduct(
|
|
54
|
-
product: components['schemas']['models__invoicing__ProductItem']
|
|
55
|
-
): RequestData<components['schemas']['ProductItemOut']> {
|
|
56
|
-
return {
|
|
57
|
-
method: 'create',
|
|
58
|
-
url: `/consumers/{consumer_id}/invoicing/products`,
|
|
59
|
-
body: product,
|
|
60
|
-
};
|
|
61
|
-
},
|
|
62
|
-
getTaxes(): RequestData<components['schemas']['models__invoicing__VatCode'][]> {
|
|
63
|
-
return {
|
|
64
|
-
method: 'get',
|
|
65
|
-
url: `/consumers/{consumer_id}/invoicing/taxes`,
|
|
66
|
-
};
|
|
67
|
-
},
|
|
68
|
-
getTaxById(taxId: string): RequestData<components['schemas']['models__invoicing__VatCode']> {
|
|
69
|
-
return {
|
|
70
|
-
method: 'get',
|
|
71
|
-
url: `/consumers/{consumer_id}/invoicing/taxes/${taxId}`,
|
|
72
|
-
};
|
|
73
|
-
},
|
|
74
|
-
getOpportunities(): RequestData<components['schemas']['OpportunityItem'][]> {
|
|
75
|
-
return {
|
|
76
|
-
method: 'get',
|
|
77
|
-
url: `/consumers/{consumer_id}/invoicing/opportunities`,
|
|
78
|
-
};
|
|
79
|
-
},
|
|
80
|
-
getOpportunitiesById(
|
|
81
|
-
opportunityId: string
|
|
82
|
-
): RequestData<components['schemas']['OpportunityItem']> {
|
|
83
|
-
return {
|
|
84
|
-
method: 'get',
|
|
85
|
-
url: `/consumers/{consumer_id}/invoicing/opportunities/${opportunityId}`,
|
|
86
|
-
};
|
|
87
|
-
},
|
|
88
|
-
getContacts(
|
|
89
|
-
params?: GetContactsParams
|
|
90
|
-
): RequestData<components['schemas']['ContactItemOut'][]> {
|
|
91
|
-
return {
|
|
92
|
-
method: 'get',
|
|
93
|
-
url: `/consumers/{consumer_id}/invoicing/contacts`,
|
|
94
|
-
params: params,
|
|
95
|
-
};
|
|
96
|
-
},
|
|
97
|
-
getContactById(contactId: string): RequestData<components['schemas']['ContactItemOut']> {
|
|
98
|
-
return {
|
|
99
|
-
method: 'get',
|
|
100
|
-
url: `/consumers/{consumer_id}/invoicing/contacts/${contactId}`,
|
|
101
|
-
};
|
|
102
|
-
},
|
|
103
|
-
createContact(
|
|
104
|
-
contact: components['schemas']['ContactItemIn']
|
|
105
|
-
): RequestData<components['schemas']['ContactItemOut']> {
|
|
106
|
-
return {
|
|
107
|
-
method: 'create',
|
|
108
|
-
url: `/consumers/{consumer_id}/invoicing/contacts`,
|
|
109
|
-
body: contact,
|
|
110
|
-
};
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
export { invoicingFactory };
|
package/src/modules/pms.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { operations, components } from '../types/public-api/schema';
|
|
2
|
-
import { AutoPaginatedParams, RequestData } from '../types/api';
|
|
3
|
-
|
|
4
|
-
type GetPaymentsParams = AutoPaginatedParams<operations['pms_get_payments']['parameters']['query']>;
|
|
5
|
-
|
|
6
|
-
type GetPaymentMethodsParams = AutoPaginatedParams<
|
|
7
|
-
operations['pms_get_payments_methods']['parameters']['query']
|
|
8
|
-
>;
|
|
9
|
-
|
|
10
|
-
type GetAccountingCategoriesParams = AutoPaginatedParams<
|
|
11
|
-
operations['pms_get_accounting_categories']['parameters']['query']
|
|
12
|
-
>;
|
|
13
|
-
|
|
14
|
-
type GetOrdersParams = AutoPaginatedParams<operations['pms_get_orders']['parameters']['query']>;
|
|
15
|
-
|
|
16
|
-
const pmsFactory = {
|
|
17
|
-
getLocations(): RequestData<components['schemas']['PMSLocationItem'][]> {
|
|
18
|
-
return {
|
|
19
|
-
method: 'get',
|
|
20
|
-
url: '/consumers/{consumer_id}/pms/locations',
|
|
21
|
-
};
|
|
22
|
-
},
|
|
23
|
-
getOrders(params: GetOrdersParams): RequestData<components['schemas']['PMSOrderItem'][]> {
|
|
24
|
-
return {
|
|
25
|
-
params,
|
|
26
|
-
method: 'get',
|
|
27
|
-
url: '/consumers/{consumer_id}/pms/orders',
|
|
28
|
-
};
|
|
29
|
-
},
|
|
30
|
-
getPaymentMethods(
|
|
31
|
-
params?: GetPaymentMethodsParams
|
|
32
|
-
): RequestData<components['schemas']['PMSPaymentMethods'][]> {
|
|
33
|
-
return {
|
|
34
|
-
params,
|
|
35
|
-
method: 'get',
|
|
36
|
-
url: `/consumers/{consumer_id}/pms/payment-methods`,
|
|
37
|
-
};
|
|
38
|
-
},
|
|
39
|
-
getClosure(
|
|
40
|
-
date: string,
|
|
41
|
-
params?: operations['pms_get_closure']['parameters']['query']
|
|
42
|
-
): RequestData<components['schemas']['PMSClosureItem']> {
|
|
43
|
-
return {
|
|
44
|
-
params,
|
|
45
|
-
method: 'get',
|
|
46
|
-
url: `/consumers/{consumer_id}/pms/closures/${date}`,
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
getPayments(params: GetPaymentsParams): RequestData<components['schemas']['PMSPaymentItem'][]> {
|
|
50
|
-
return {
|
|
51
|
-
params,
|
|
52
|
-
method: 'get',
|
|
53
|
-
url: `/consumers/{consumer_id}/pms/payments`,
|
|
54
|
-
};
|
|
55
|
-
},
|
|
56
|
-
getAccountingCategories(
|
|
57
|
-
params?: GetAccountingCategoriesParams
|
|
58
|
-
): RequestData<components['schemas']['PMSAccountingCategoryItem'][]> {
|
|
59
|
-
return {
|
|
60
|
-
params,
|
|
61
|
-
method: 'get',
|
|
62
|
-
url: `/consumers/{consumer_id}/pms/accounting-categories`,
|
|
63
|
-
};
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export { pmsFactory };
|
package/src/modules/pos.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { operations, components } from '../types/public-api/schema';
|
|
2
|
-
import { AutoPaginatedParams, RequestData } from '../types/api';
|
|
3
|
-
|
|
4
|
-
type GetPaymentsParams = AutoPaginatedParams<operations['pos_get_payments']['parameters']['query']>;
|
|
5
|
-
|
|
6
|
-
type GetPaymentMethodsParams = AutoPaginatedParams<
|
|
7
|
-
operations['pos_get_payments_methods']['parameters']['query']
|
|
8
|
-
>;
|
|
9
|
-
|
|
10
|
-
type GetProductCategoriesParams = AutoPaginatedParams<
|
|
11
|
-
operations['pos_get_product_categories']['parameters']['query']
|
|
12
|
-
>;
|
|
13
|
-
|
|
14
|
-
type GetProductsParams = AutoPaginatedParams<operations['pos_get_products']['parameters']['query']>;
|
|
15
|
-
|
|
16
|
-
type GetCustomersParams = AutoPaginatedParams<
|
|
17
|
-
operations['pos_get_customers']['parameters']['query']
|
|
18
|
-
>;
|
|
19
|
-
|
|
20
|
-
type GetAccountingCategoriesParams = AutoPaginatedParams<
|
|
21
|
-
operations['pos_get_accounting_categories']['parameters']['query']
|
|
22
|
-
>;
|
|
23
|
-
|
|
24
|
-
type GetOrdersParams = AutoPaginatedParams<operations['pos_get_orders']['parameters']['query']>;
|
|
25
|
-
|
|
26
|
-
const posFactory = {
|
|
27
|
-
getLocations(): RequestData<components['schemas']['POSLocationItem'][]> {
|
|
28
|
-
return {
|
|
29
|
-
method: 'get',
|
|
30
|
-
url: '/consumers/{consumer_id}/pos/locations',
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
|
-
getOrders(params: GetOrdersParams): RequestData<components['schemas']['POSOrderItem'][]> {
|
|
34
|
-
return {
|
|
35
|
-
params,
|
|
36
|
-
method: 'get',
|
|
37
|
-
url: '/consumers/{consumer_id}/pos/orders',
|
|
38
|
-
};
|
|
39
|
-
},
|
|
40
|
-
getCustomers(
|
|
41
|
-
params?: GetCustomersParams
|
|
42
|
-
): RequestData<components['schemas']['POSCustomerItem'][]> {
|
|
43
|
-
return {
|
|
44
|
-
params,
|
|
45
|
-
method: 'get',
|
|
46
|
-
url: '/consumers/{consumer_id}/pos/customers',
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
getOrder(orderId: string): RequestData<components['schemas']['POSOrderItem']> {
|
|
50
|
-
return {
|
|
51
|
-
method: 'get',
|
|
52
|
-
url: `/consumers/{consumer_id}/pos/orders/${orderId}`,
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
|
-
getCustomer(customerId: string): RequestData<components['schemas']['POSCustomerItem']> {
|
|
56
|
-
return {
|
|
57
|
-
method: 'get',
|
|
58
|
-
url: `/consumers/{consumer_id}/pos/customers/${customerId}`,
|
|
59
|
-
};
|
|
60
|
-
},
|
|
61
|
-
createCustomer(
|
|
62
|
-
customer: components['schemas']['POSCreateCustomerItem']
|
|
63
|
-
): RequestData<components['schemas']['POSCustomerItem']> {
|
|
64
|
-
return {
|
|
65
|
-
method: 'create',
|
|
66
|
-
url: `/consumers/{consumer_id}/pos/customers`,
|
|
67
|
-
body: customer,
|
|
68
|
-
};
|
|
69
|
-
},
|
|
70
|
-
getPaymentMethods(
|
|
71
|
-
params?: GetPaymentMethodsParams
|
|
72
|
-
): RequestData<components['schemas']['PaymentMethods'][]> {
|
|
73
|
-
return {
|
|
74
|
-
params,
|
|
75
|
-
method: 'get',
|
|
76
|
-
url: `/consumers/{consumer_id}/pos/payment-methods`,
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
getProductCategories(
|
|
80
|
-
params?: GetProductCategoriesParams
|
|
81
|
-
): RequestData<components['schemas']['CategoryItem'][]> {
|
|
82
|
-
return {
|
|
83
|
-
params,
|
|
84
|
-
method: 'get',
|
|
85
|
-
url: `/consumers/{consumer_id}/pos/product-categories`,
|
|
86
|
-
};
|
|
87
|
-
},
|
|
88
|
-
getProducts(
|
|
89
|
-
params?: GetProductsParams
|
|
90
|
-
): RequestData<components['schemas']['POSProductItem'][]> {
|
|
91
|
-
return {
|
|
92
|
-
params,
|
|
93
|
-
method: 'get',
|
|
94
|
-
url: `/consumers/{consumer_id}/pos/products`,
|
|
95
|
-
};
|
|
96
|
-
},
|
|
97
|
-
getSales(
|
|
98
|
-
params: operations['pos_get_sales']['parameters']['query']
|
|
99
|
-
): RequestData<components['schemas']['SalesItem']> {
|
|
100
|
-
return {
|
|
101
|
-
params,
|
|
102
|
-
method: 'get',
|
|
103
|
-
url: `/consumers/{consumer_id}/pos/sales`,
|
|
104
|
-
};
|
|
105
|
-
},
|
|
106
|
-
getClosure(
|
|
107
|
-
date: string,
|
|
108
|
-
params?: operations['pos_get_closure']['parameters']['query']
|
|
109
|
-
): RequestData<components['schemas']['ClosureItem']> {
|
|
110
|
-
return {
|
|
111
|
-
params,
|
|
112
|
-
method: 'get',
|
|
113
|
-
url: `/consumers/{consumer_id}/pos/closures/${date}`,
|
|
114
|
-
};
|
|
115
|
-
},
|
|
116
|
-
getPayments(params: GetPaymentsParams): RequestData<components['schemas']['POSPaymentItem'][]> {
|
|
117
|
-
return {
|
|
118
|
-
params,
|
|
119
|
-
method: 'get',
|
|
120
|
-
url: `/consumers/{consumer_id}/pos/payments`,
|
|
121
|
-
};
|
|
122
|
-
},
|
|
123
|
-
updateOrder(
|
|
124
|
-
orderId: string,
|
|
125
|
-
order: components['schemas']['UpdateOrderItem']
|
|
126
|
-
): RequestData<components['schemas']['POSOrderItem']> {
|
|
127
|
-
return {
|
|
128
|
-
method: 'patch',
|
|
129
|
-
url: `/consumers/{consumer_id}/pos/orders/${orderId}`,
|
|
130
|
-
body: order,
|
|
131
|
-
};
|
|
132
|
-
},
|
|
133
|
-
getAccountingCategories(
|
|
134
|
-
params?: GetAccountingCategoriesParams
|
|
135
|
-
): RequestData<components['schemas']['AccountingCategoryItem'][]> {
|
|
136
|
-
return {
|
|
137
|
-
params,
|
|
138
|
-
method: 'get',
|
|
139
|
-
url: `/consumers/{consumer_id}/pos/accounting-categories`,
|
|
140
|
-
};
|
|
141
|
-
},
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
export { posFactory };
|
package/src/modules/sync.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { components } from '../types/public-api/schema';
|
|
2
|
-
import { InternalAPI } from './internalApi';
|
|
3
|
-
import { ContextType } from '../types/sync';
|
|
4
|
-
import { Consumer } from './consumer';
|
|
5
|
-
import { Flow } from './flow';
|
|
6
|
-
|
|
7
|
-
const Sync = (internalApi: InternalAPI, body: components['schemas']['ReadSyncItem']) => {
|
|
8
|
-
const _internalApi: InternalAPI = internalApi;
|
|
9
|
-
const data = body;
|
|
10
|
-
const name = data.name;
|
|
11
|
-
const consumers = data.consumers;
|
|
12
|
-
const syncid = data.syncid;
|
|
13
|
-
|
|
14
|
-
const getFlows = () => {
|
|
15
|
-
return data.flows.map((flow) => Flow(_internalApi, flow, data.syncid, data.consumers));
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const getFlowByName = (name: string) => {
|
|
19
|
-
const flow = data.flows.find((flow) => flow.name.toLowerCase() === name.toLowerCase());
|
|
20
|
-
if (flow) {
|
|
21
|
-
return Flow(_internalApi, flow, data.syncid, data.consumers);
|
|
22
|
-
}
|
|
23
|
-
return undefined;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const getFlowById = (id: string) => {
|
|
27
|
-
const flow = data.flows.find((flow) => flow.id === id);
|
|
28
|
-
if (flow) {
|
|
29
|
-
return Flow(_internalApi, flow, data.syncid, data.consumers);
|
|
30
|
-
}
|
|
31
|
-
return undefined;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Internal use: Used to create flow based on code and triggers.
|
|
36
|
-
* @param context
|
|
37
|
-
* @param process
|
|
38
|
-
* @returns flow
|
|
39
|
-
*/
|
|
40
|
-
const createFlow = async (
|
|
41
|
-
context: ContextType,
|
|
42
|
-
process?: (consumer: typeof Consumer, context: any) => any
|
|
43
|
-
) => {
|
|
44
|
-
const executionData = context.execution.data || {};
|
|
45
|
-
if (context.execution.type === 'code') {
|
|
46
|
-
const fullFunc = process?.toString();
|
|
47
|
-
const bodyFunc = fullFunc?.slice(fullFunc.indexOf('{') + 1, fullFunc.lastIndexOf('}'));
|
|
48
|
-
executionData['code'] = bodyFunc;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const { data: createFlowData }: { data: components['schemas']['ReadFlowItem'] } =
|
|
52
|
-
await _internalApi.post(`/syncs/${data.syncid}/flows`, {
|
|
53
|
-
name: context.name,
|
|
54
|
-
description: context.description,
|
|
55
|
-
execution: {
|
|
56
|
-
type: context.execution.type,
|
|
57
|
-
data: executionData,
|
|
58
|
-
},
|
|
59
|
-
trigger: context.trigger,
|
|
60
|
-
config: context.config,
|
|
61
|
-
});
|
|
62
|
-
const myflow = Flow(_internalApi, createFlowData, data.syncid, data.consumers, process);
|
|
63
|
-
return myflow;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
createFlow,
|
|
68
|
-
getFlows,
|
|
69
|
-
getFlowByName,
|
|
70
|
-
getFlowById,
|
|
71
|
-
name,
|
|
72
|
-
consumers,
|
|
73
|
-
syncid,
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export { Sync };
|
package/src/modules/syncs.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { components } from '../types/public-api/schema';
|
|
2
|
-
import { InternalAPI } from './internalApi';
|
|
3
|
-
import { Sync } from './sync';
|
|
4
|
-
|
|
5
|
-
export type SyncsAPI = {
|
|
6
|
-
createSync: (
|
|
7
|
-
body?: components['schemas']['CreateSyncItem']
|
|
8
|
-
) => Promise<ReturnType<typeof Sync>>;
|
|
9
|
-
getSyncs: () => Promise<ReturnType<typeof Sync>[]>;
|
|
10
|
-
getSyncById: (syncid: string) => Promise<ReturnType<typeof Sync>>;
|
|
11
|
-
updateSync: (
|
|
12
|
-
body?: components['schemas']['CreateSyncItem']
|
|
13
|
-
) => Promise<ReturnType<typeof Sync>>;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const Syncs = (internalApi: InternalAPI): SyncsAPI => {
|
|
17
|
-
const _internalApi: InternalAPI = internalApi;
|
|
18
|
-
|
|
19
|
-
const getSyncs = async () => {
|
|
20
|
-
const { data }: { data: components['schemas']['ReadSyncItem'][] } = await _internalApi.get(
|
|
21
|
-
'/syncs'
|
|
22
|
-
);
|
|
23
|
-
return data.map((sync) => Sync(_internalApi, sync));
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const getSyncById = async (syncid: string) => {
|
|
27
|
-
const { data }: { data: components['schemas']['ReadSyncItem'] } = await _internalApi.get(
|
|
28
|
-
`/syncs/${syncid}`
|
|
29
|
-
);
|
|
30
|
-
return Sync(_internalApi, data);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const createSync = async (body?: components['schemas']['CreateSyncItem']) => {
|
|
34
|
-
const {
|
|
35
|
-
data,
|
|
36
|
-
}: {
|
|
37
|
-
data: components['schemas']['ReadSyncItem'];
|
|
38
|
-
} = await _internalApi.post('/syncs', body);
|
|
39
|
-
return Sync(_internalApi, data);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const updateSync = async (body?: components['schemas']['CreateSyncItem']) => {
|
|
43
|
-
const {
|
|
44
|
-
data,
|
|
45
|
-
}: {
|
|
46
|
-
data: components['schemas']['ReadSyncItem'];
|
|
47
|
-
} = await _internalApi.patch('/syncs', body);
|
|
48
|
-
return Sync(_internalApi, data);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
createSync,
|
|
53
|
-
getSyncs,
|
|
54
|
-
getSyncById,
|
|
55
|
-
updateSync,
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export { Syncs };
|