@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.
Files changed (114) hide show
  1. package/package.json +5 -2
  2. package/.eslintignore +0 -1
  3. package/.eslintrc.json +0 -25
  4. package/.github/workflows/ci.yml +0 -75
  5. package/.husky/pre-commit +0 -4
  6. package/.prettierignore +0 -1
  7. package/.prettierrc.json +0 -7
  8. package/CHANGELOG.md +0 -108
  9. package/dist/src/helpers/openapi.d.ts +0 -3
  10. package/dist/src/helpers/openapi.js +0 -18
  11. package/dist/src/helpers/settings.d.ts +0 -4
  12. package/dist/src/helpers/settings.js +0 -5
  13. package/dist/src/index.d.ts +0 -1
  14. package/dist/src/modules/accounting.d.ts +0 -68
  15. package/dist/src/modules/accounting.js +0 -326
  16. package/dist/src/modules/api.d.ts +0 -18351
  17. package/dist/src/modules/api.js +0 -36
  18. package/dist/src/modules/consumer.d.ts +0 -3622
  19. package/dist/src/modules/consumer.js +0 -142
  20. package/dist/src/modules/consumers.d.ts +0 -18237
  21. package/dist/src/modules/consumers.js +0 -51
  22. package/dist/src/modules/custom.d.ts +0 -8
  23. package/dist/src/modules/custom.js +0 -36
  24. package/dist/src/modules/datastores.d.ts +0 -18
  25. package/dist/src/modules/datastores.js +0 -23
  26. package/dist/src/modules/ecommerce.d.ts +0 -24
  27. package/dist/src/modules/ecommerce.js +0 -97
  28. package/dist/src/modules/flow.d.ts +0 -15
  29. package/dist/src/modules/flow.js +0 -156
  30. package/dist/src/modules/integrations.d.ts +0 -23
  31. package/dist/src/modules/integrations.js +0 -23
  32. package/dist/src/modules/internalApi.d.ts +0 -24
  33. package/dist/src/modules/internalApi.js +0 -175
  34. package/dist/src/modules/invoicing.d.ts +0 -20
  35. package/dist/src/modules/invoicing.js +0 -90
  36. package/dist/src/modules/payment.d.ts +0 -14
  37. package/dist/src/modules/payment.js +0 -41
  38. package/dist/src/modules/pms.d.ts +0 -15
  39. package/dist/src/modules/pms.js +0 -47
  40. package/dist/src/modules/pos.d.ts +0 -26
  41. package/dist/src/modules/pos.js +0 -101
  42. package/dist/src/modules/sync.d.ts +0 -14654
  43. package/dist/src/modules/sync.js +0 -73
  44. package/dist/src/modules/syncs.d.ts +0 -11
  45. package/dist/src/modules/syncs.js +0 -39
  46. package/dist/src/modules/webhooks.d.ts +0 -58
  47. package/dist/src/modules/webhooks.js +0 -53
  48. package/dist/src/types/api.d.ts +0 -29
  49. package/dist/src/types/api.js +0 -2
  50. package/dist/src/types/consumers.d.ts +0 -8
  51. package/dist/src/types/consumers.js +0 -2
  52. package/dist/src/types/public-api/mappings.d.ts +0 -21
  53. package/dist/src/types/public-api/mappings.js +0 -2
  54. package/dist/src/types/sync.d.ts +0 -37
  55. package/dist/src/types/sync.js +0 -2
  56. package/dist/test/modules/accounting.test.d.ts +0 -1
  57. package/dist/test/modules/accounting.test.js +0 -590
  58. package/dist/test/modules/consumer.test.d.ts +0 -1
  59. package/dist/test/modules/consumer.test.js +0 -89
  60. package/dist/test/modules/consumers.test.d.ts +0 -1
  61. package/dist/test/modules/consumers.test.js +0 -109
  62. package/dist/test/modules/ecommerce.test.d.ts +0 -1
  63. package/dist/test/modules/ecommerce.test.js +0 -224
  64. package/dist/test/modules/integrations.test.d.ts +0 -1
  65. package/dist/test/modules/integrations.test.js +0 -54
  66. package/dist/test/modules/invoicing.test.d.ts +0 -1
  67. package/dist/test/modules/invoicing.test.js +0 -115
  68. package/dist/test/modules/payment.test.d.ts +0 -1
  69. package/dist/test/modules/payment.test.js +0 -88
  70. package/dist/test/modules/pms.test.d.ts +0 -1
  71. package/dist/test/modules/pms.test.js +0 -90
  72. package/dist/test/modules/pos.test.d.ts +0 -1
  73. package/dist/test/modules/pos.test.js +0 -179
  74. package/dist/test/modules/sync.test.d.ts +0 -1
  75. package/dist/test/modules/sync.test.js +0 -93
  76. package/dist/test/modules/syncs.test.d.ts +0 -1
  77. package/dist/test/modules/syncs.test.js +0 -53
  78. package/dist/test/modules/webhooks.test.d.ts +0 -1
  79. package/dist/test/modules/webhooks.test.js +0 -120
  80. package/jest.config.ts +0 -195
  81. package/src/helpers/openapi.ts +0 -22
  82. package/src/helpers/settings.ts +0 -3
  83. package/src/index.ts +0 -1
  84. package/src/modules/accounting.ts +0 -510
  85. package/src/modules/api.ts +0 -35
  86. package/src/modules/consumer.ts +0 -216
  87. package/src/modules/consumers.ts +0 -82
  88. package/src/modules/custom.ts +0 -36
  89. package/src/modules/datastores.ts +0 -19
  90. package/src/modules/ecommerce.ts +0 -129
  91. package/src/modules/flow.ts +0 -168
  92. package/src/modules/integrations.ts +0 -24
  93. package/src/modules/internalApi.ts +0 -182
  94. package/src/modules/invoicing.ts +0 -118
  95. package/src/modules/payment.ts +0 -59
  96. package/src/modules/pms.ts +0 -67
  97. package/src/modules/pos.ts +0 -144
  98. package/src/modules/sync.ts +0 -77
  99. package/src/modules/syncs.ts +0 -59
  100. package/src/modules/webhooks.ts +0 -86
  101. package/test/data/accounting_invoice.pdf +0 -0
  102. package/test/modules/accounting.test.ts +0 -647
  103. package/test/modules/consumer.test.ts +0 -68
  104. package/test/modules/consumers.test.ts +0 -85
  105. package/test/modules/ecommerce.test.ts +0 -213
  106. package/test/modules/integrations.test.ts +0 -22
  107. package/test/modules/invoicing.test.ts +0 -98
  108. package/test/modules/payment.test.ts +0 -65
  109. package/test/modules/pms.test.ts +0 -69
  110. package/test/modules/pos.test.ts +0 -164
  111. package/test/modules/sync.test.ts +0 -74
  112. package/test/modules/syncs.test.ts +0 -23
  113. package/test/modules/webhooks.test.ts +0 -92
  114. 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 };
@@ -1,118 +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']['backbone_common__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<
63
- components['schemas']['backbone_common__models__invoicing__VatCode'][]
64
- > {
65
- return {
66
- method: 'get',
67
- url: `/consumers/{consumer_id}/invoicing/taxes`,
68
- };
69
- },
70
- getTaxById(
71
- taxId: string
72
- ): RequestData<components['schemas']['backbone_common__models__invoicing__VatCode']> {
73
- return {
74
- method: 'get',
75
- url: `/consumers/{consumer_id}/invoicing/taxes/${taxId}`,
76
- };
77
- },
78
- getOpportunities(): RequestData<components['schemas']['OpportunityItem'][]> {
79
- return {
80
- method: 'get',
81
- url: `/consumers/{consumer_id}/invoicing/opportunities`,
82
- };
83
- },
84
- getOpportunitiesById(
85
- opportunityId: string
86
- ): RequestData<components['schemas']['OpportunityItem']> {
87
- return {
88
- method: 'get',
89
- url: `/consumers/{consumer_id}/invoicing/opportunities/${opportunityId}`,
90
- };
91
- },
92
- getContacts(
93
- params?: GetContactsParams
94
- ): RequestData<components['schemas']['ContactItemOut'][]> {
95
- return {
96
- method: 'get',
97
- url: `/consumers/{consumer_id}/invoicing/contacts`,
98
- params: params,
99
- };
100
- },
101
- getContactById(contactId: string): RequestData<components['schemas']['ContactItemOut']> {
102
- return {
103
- method: 'get',
104
- url: `/consumers/{consumer_id}/invoicing/contacts/${contactId}`,
105
- };
106
- },
107
- createContact(
108
- contact: components['schemas']['ContactItemIn']
109
- ): RequestData<components['schemas']['ContactItemOut']> {
110
- return {
111
- method: 'create',
112
- url: `/consumers/{consumer_id}/invoicing/contacts`,
113
- body: contact,
114
- };
115
- },
116
- };
117
-
118
- export { invoicingFactory };
@@ -1,59 +0,0 @@
1
- import { operations, components } from '../types/public-api/schema';
2
- import { AutoPaginatedParams, RequestData } from '../types/api';
3
-
4
- type GetBalancesParams = AutoPaginatedParams<
5
- operations['payment_get_balances']['parameters']['query']
6
- >;
7
- type GetPaymentsParams = AutoPaginatedParams<
8
- operations['payment_get_payments']['parameters']['query']
9
- >;
10
- type GetTransactionsParams = AutoPaginatedParams<
11
- operations['payment_get_transaction']['parameters']['query']
12
- >;
13
- type GetRefundsParams = AutoPaginatedParams<
14
- operations['payment_get_refunds']['parameters']['query']
15
- >;
16
-
17
- const paymentFactory = {
18
- getPayments(params: GetPaymentsParams): RequestData<components['schemas']['PaymentItemOut'][]> {
19
- return {
20
- params,
21
- method: 'get',
22
- url: `/consumers/{consumer_id}/payment/payments`,
23
- };
24
- },
25
- getBalances(params: GetBalancesParams): RequestData<components['schemas']['BalanceItemOut'][]> {
26
- return {
27
- params,
28
- method: 'get',
29
- url: `/consumers/{consumer_id}/payment/balances`,
30
- };
31
- },
32
- getTransactions(
33
- params: GetTransactionsParams
34
- ): RequestData<components['schemas']['TransactionItemOut'][]> {
35
- return {
36
- params,
37
- method: 'get',
38
- url: `/consumers/{consumer_id}/payment/transactions`,
39
- };
40
- },
41
- getPayment(
42
- params: operations['payment_get_payment']['parameters']['path']
43
- ): RequestData<components['schemas']['PaymentItemOut']> {
44
- return {
45
- params,
46
- method: 'get',
47
- url: `/consumers/{consumer_id}/payment/payments/{payment_id}`,
48
- };
49
- },
50
- getRefunds(params: GetRefundsParams): RequestData<components['schemas']['RefundItemOut'][]> {
51
- return {
52
- params,
53
- method: 'get',
54
- url: `/consumers/{consumer_id}/payment/refunds`,
55
- };
56
- },
57
- };
58
-
59
- export { paymentFactory };
@@ -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 };
@@ -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 };
@@ -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
- triggers: context.triggers,
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 };