@chift/chift-nodejs 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/.eslintcache +1 -0
  2. package/.eslintignore +1 -0
  3. package/.eslintrc.json +25 -0
  4. package/.github/workflows/ci.yml +73 -0
  5. package/.husky/pre-commit +4 -0
  6. package/.prettierignore +1 -0
  7. package/.prettierrc.json +7 -0
  8. package/CHANGELOG.md +4 -0
  9. package/LICENSE +201 -0
  10. package/README.md +48 -0
  11. package/coverage/clover.xml +1645 -0
  12. package/coverage/coverage-final.json +19 -0
  13. package/coverage/lcov-report/base.css +224 -0
  14. package/coverage/lcov-report/block-navigation.js +87 -0
  15. package/coverage/lcov-report/favicon.png +0 -0
  16. package/coverage/lcov-report/index.html +146 -0
  17. package/coverage/lcov-report/prettify.css +1 -0
  18. package/coverage/lcov-report/prettify.js +2 -0
  19. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  20. package/coverage/lcov-report/sorter.js +196 -0
  21. package/coverage/lcov-report/src/helpers/index.html +131 -0
  22. package/coverage/lcov-report/src/helpers/openapi.ts.html +151 -0
  23. package/coverage/lcov-report/src/helpers/settings.ts.html +94 -0
  24. package/coverage/lcov-report/src/index.html +116 -0
  25. package/coverage/lcov-report/src/index.ts.html +88 -0
  26. package/coverage/lcov-report/src/modules/accounting.ts.html +1156 -0
  27. package/coverage/lcov-report/src/modules/api.ts.html +190 -0
  28. package/coverage/lcov-report/src/modules/consumer.ts.html +616 -0
  29. package/coverage/lcov-report/src/modules/consumers.ts.html +331 -0
  30. package/coverage/lcov-report/src/modules/custom.ts.html +193 -0
  31. package/coverage/lcov-report/src/modules/datastores.ts.html +142 -0
  32. package/coverage/lcov-report/src/modules/ecommerce.ts.html +331 -0
  33. package/coverage/lcov-report/src/modules/flow.ts.html +589 -0
  34. package/coverage/lcov-report/src/modules/index.html +326 -0
  35. package/coverage/lcov-report/src/modules/integrations.ts.html +151 -0
  36. package/coverage/lcov-report/src/modules/internalApi.ts.html +586 -0
  37. package/coverage/lcov-report/src/modules/invoicing.ts.html +391 -0
  38. package/coverage/lcov-report/src/modules/pos.ts.html +421 -0
  39. package/coverage/lcov-report/src/modules/sync.ts.html +316 -0
  40. package/coverage/lcov-report/src/modules/syncs.ts.html +169 -0
  41. package/coverage/lcov-report/src/modules/webhooks.ts.html +343 -0
  42. package/coverage/lcov.info +1976 -0
  43. package/dist/src/helpers/openapi.d.ts +3 -0
  44. package/dist/src/helpers/openapi.js +18 -0
  45. package/dist/src/helpers/settings.d.ts +4 -0
  46. package/dist/src/helpers/settings.js +5 -0
  47. package/dist/src/index.d.ts +1 -0
  48. package/dist/src/index.js +17 -0
  49. package/dist/src/modules/accounting.d.ts +48 -0
  50. package/dist/src/modules/accounting.js +255 -0
  51. package/dist/src/modules/api.d.ts +39333 -0
  52. package/dist/src/modules/api.js +36 -0
  53. package/dist/src/modules/consumer.d.ts +2588 -0
  54. package/dist/src/modules/consumer.js +118 -0
  55. package/dist/src/modules/consumers.d.ts +13034 -0
  56. package/dist/src/modules/consumers.js +51 -0
  57. package/dist/src/modules/custom.d.ts +8 -0
  58. package/dist/src/modules/custom.js +36 -0
  59. package/dist/src/modules/datastores.d.ts +18 -0
  60. package/dist/src/modules/datastores.js +23 -0
  61. package/dist/src/modules/ecommerce.d.ts +16 -0
  62. package/dist/src/modules/ecommerce.js +69 -0
  63. package/dist/src/modules/flow.d.ts +15 -0
  64. package/dist/src/modules/flow.js +156 -0
  65. package/dist/src/modules/integrations.d.ts +14 -0
  66. package/dist/src/modules/integrations.js +23 -0
  67. package/dist/src/modules/internalApi.d.ts +22 -0
  68. package/dist/src/modules/internalApi.js +160 -0
  69. package/dist/src/modules/invoicing.d.ts +18 -0
  70. package/dist/src/modules/invoicing.js +90 -0
  71. package/dist/src/modules/pos.d.ts +20 -0
  72. package/dist/src/modules/pos.js +80 -0
  73. package/dist/src/modules/sync.d.ts +10494 -0
  74. package/dist/src/modules/sync.js +75 -0
  75. package/dist/src/modules/syncs.d.ts +26200 -0
  76. package/dist/src/modules/syncs.js +29 -0
  77. package/dist/src/modules/webhooks.d.ts +55 -0
  78. package/dist/src/modules/webhooks.js +53 -0
  79. package/dist/src/types/api.d.ts +28 -0
  80. package/dist/src/types/api.js +2 -0
  81. package/dist/src/types/consumers.d.ts +8 -0
  82. package/dist/src/types/consumers.js +2 -0
  83. package/dist/src/types/public-api/mappings.d.ts +21 -0
  84. package/dist/src/types/public-api/mappings.js +2 -0
  85. package/dist/src/types/sync.d.ts +20 -0
  86. package/dist/src/types/sync.js +2 -0
  87. package/dist/test/modules/accounting.test.d.ts +1 -0
  88. package/dist/test/modules/accounting.test.js +453 -0
  89. package/dist/test/modules/consumer.test.d.ts +1 -0
  90. package/dist/test/modules/consumer.test.js +89 -0
  91. package/dist/test/modules/consumers.test.d.ts +1 -0
  92. package/dist/test/modules/consumers.test.js +109 -0
  93. package/dist/test/modules/ecommerce.test.d.ts +1 -0
  94. package/dist/test/modules/ecommerce.test.js +193 -0
  95. package/dist/test/modules/flow.test.d.ts +1 -0
  96. package/dist/test/modules/flow.test.js +69 -0
  97. package/dist/test/modules/integrations.test.d.ts +1 -0
  98. package/dist/test/modules/integrations.test.js +54 -0
  99. package/dist/test/modules/invoicing.test.d.ts +1 -0
  100. package/dist/test/modules/invoicing.test.js +108 -0
  101. package/dist/test/modules/pos.test.d.ts +1 -0
  102. package/dist/test/modules/pos.test.js +164 -0
  103. package/dist/test/modules/sync.test.d.ts +1 -0
  104. package/dist/test/modules/sync.test.js +81 -0
  105. package/dist/test/modules/syncs.test.d.ts +1 -0
  106. package/dist/test/modules/syncs.test.js +53 -0
  107. package/dist/test/modules/webhooks.test.d.ts +1 -0
  108. package/dist/test/modules/webhooks.test.js +120 -0
  109. package/jest.config.ts +195 -0
  110. package/package.json +47 -0
  111. package/src/helpers/openapi.ts +22 -0
  112. package/src/helpers/settings.ts +3 -0
  113. package/src/index.ts +1 -0
  114. package/src/modules/accounting.ts +357 -0
  115. package/src/modules/api.ts +35 -0
  116. package/src/modules/consumer.ts +177 -0
  117. package/src/modules/consumers.ts +82 -0
  118. package/src/modules/custom.ts +36 -0
  119. package/src/modules/datastores.ts +19 -0
  120. package/src/modules/ecommerce.ts +82 -0
  121. package/src/modules/flow.ts +168 -0
  122. package/src/modules/integrations.ts +22 -0
  123. package/src/modules/internalApi.ts +162 -0
  124. package/src/modules/invoicing.ts +106 -0
  125. package/src/modules/pos.ts +112 -0
  126. package/src/modules/sync.ts +77 -0
  127. package/src/modules/syncs.ts +28 -0
  128. package/src/modules/webhooks.ts +86 -0
  129. package/src/types/api.ts +35 -0
  130. package/src/types/consumers.ts +9 -0
  131. package/src/types/public-api/mappings.ts +21 -0
  132. package/src/types/public-api/schema.d.ts +9436 -0
  133. package/src/types/sync.ts +23 -0
  134. package/test/data/accounting_invoice.pdf +0 -0
  135. package/test/modules/accounting.test.ts +483 -0
  136. package/test/modules/consumer.test.ts +68 -0
  137. package/test/modules/consumers.test.ts +83 -0
  138. package/test/modules/ecommerce.test.ts +177 -0
  139. package/test/modules/integrations.test.ts +22 -0
  140. package/test/modules/invoicing.test.ts +88 -0
  141. package/test/modules/pos.test.ts +145 -0
  142. package/test/modules/sync.test.ts +60 -0
  143. package/test/modules/syncs.test.ts +23 -0
  144. package/test/modules/webhooks.test.ts +92 -0
  145. package/test/set_envs.sh +14 -0
  146. package/tsconfig.json +107 -0
@@ -0,0 +1,177 @@
1
+ import { beforeAll, expect, test } from '@jest/globals';
2
+ import * as chift from '../../src/index';
3
+ import * as dotenv from 'dotenv';
4
+ import { components } from '../../src/types/public-api/schema';
5
+ dotenv.config();
6
+
7
+ const client = new chift.API({
8
+ baseUrl: process.env.CHIFT_BASE_URL,
9
+ clientId: process.env.CHIFT_CLIENT_ID as string,
10
+ clientSecret: process.env.CHIFT_CLIENT_SECRET as string,
11
+ accountId: process.env.CHIFT_ACCOUNT_ID as string,
12
+ });
13
+
14
+ const consumerId = process.env.CHIFT_WOOCOMMERCE_CONSUMER_ID as string;
15
+
16
+ let consumer: any;
17
+ beforeAll(async () => {
18
+ consumer = await client.Consumers.getConsumerById(consumerId);
19
+ });
20
+
21
+ let customers: components['schemas']['CommerceCustomerItem'][];
22
+ test('getCustomers', async () => {
23
+ customers = await consumer.ecommerce.getCustomers();
24
+ expect(customers).toBeInstanceOf(Array);
25
+ expect(customers.length).toBeGreaterThan(0);
26
+ expect(customers[0]).toHaveProperty('id', expect.any(String));
27
+ });
28
+
29
+ let products: components['schemas']['app__routers__commerce__ProductItem'][];
30
+ test('getProducts', async () => {
31
+ products = await consumer.ecommerce.getProducts();
32
+ expect(products).toBeInstanceOf(Array);
33
+ expect(products.length).toBeGreaterThan(0);
34
+ expect(products[0]).toHaveProperty('id', expect.any(String));
35
+ });
36
+
37
+ test('getCustomer', async () => {
38
+ const customer = await consumer.ecommerce.getCustomer(customers[0].id);
39
+ expect(customer).toHaveProperty('id', customers[0].id);
40
+ expect(customer).toHaveProperty('first_name');
41
+ expect(customer).toHaveProperty('last_name');
42
+ expect(customer).toHaveProperty('phone');
43
+ expect(customer).toHaveProperty('email');
44
+ expect(customer).toHaveProperty('language');
45
+ expect(customer).toHaveProperty('internal_notes');
46
+ expect(customer).toHaveProperty('currency');
47
+ expect(customer).toHaveProperty('addresses');
48
+ expect(customer).toHaveProperty('created_on');
49
+ });
50
+
51
+ test('getProduct', async () => {
52
+ const product = await consumer.ecommerce.getProduct(products[0].id);
53
+ expect(product).toBeTruthy();
54
+ expect(product).toHaveProperty('id', products[0].id);
55
+ expect(product).toHaveProperty('name', expect.any(String));
56
+ expect(product).toHaveProperty('description');
57
+ expect(product).toHaveProperty('description_html');
58
+ expect(product).toHaveProperty('categories');
59
+ expect(product).toHaveProperty('created_on');
60
+ expect(product).toHaveProperty('variants');
61
+ expect(product).toHaveProperty('status');
62
+ expect(product).toHaveProperty('common_attributes');
63
+ expect(product).toHaveProperty('variant_attributes_options');
64
+ expect(product).toHaveProperty('common_images');
65
+ });
66
+
67
+ test('getProductVariantById', async () => {
68
+ if (!products?.length) {
69
+ throw new Error('No product to test');
70
+ }
71
+
72
+ if (!products[0].variants) {
73
+ throw new Error('No product variant to test');
74
+ }
75
+
76
+ const variant = await consumer.ecommerce.getProductVariantById(products[0].variants[0].id);
77
+ expect(variant).toBeTruthy();
78
+ expect(variant).toHaveProperty('id', expect.any(String));
79
+ });
80
+
81
+ let locations: components['schemas']['CommerceLocationItem'][];
82
+ test('getLocations', async () => {
83
+ locations = await consumer.ecommerce.getLocations();
84
+ expect(locations).toBeInstanceOf(Array);
85
+ expect(locations.length).toBeGreaterThan(0);
86
+ expect(locations[0]).toHaveProperty('id', expect.any(String));
87
+ expect(locations[0]).toHaveProperty('name', expect.any(String));
88
+ });
89
+
90
+ test('updateAvailableQuantity', async () => {
91
+ if (!products?.length) {
92
+ throw new Error('No product to test');
93
+ }
94
+
95
+ if (!products[0].variants) {
96
+ throw new Error('No product variant to test');
97
+ }
98
+
99
+ const product = await consumer.ecommerce.updateAvailableQuantity(products[0].variants[0].id, {
100
+ location_id: locations[0].id,
101
+ available_quantity: 1,
102
+ });
103
+ expect(product).toBeTruthy();
104
+ expect(product).toHaveProperty('available_quantity', expect.any(Number));
105
+ });
106
+
107
+ /*
108
+ test('createOrder', async () => {
109
+ const order = await consumer.ecommerce.createOrder({
110
+ customer: {
111
+ email: 'test@test.com',
112
+ },
113
+ billing_address: {
114
+ first_name: 'Test',
115
+ last_name: 'Test',
116
+ street: 'Test',
117
+ number: '1',
118
+ city: 'Test',
119
+ country: 'BE',
120
+ },
121
+ shipping_address: {
122
+ first_name: 'Test',
123
+ last_name: 'Test',
124
+ street: 'Test',
125
+ number: '1',
126
+ city: 'Test',
127
+ country: 'BE',
128
+ },
129
+ currency: 'EUR',
130
+ lines: [
131
+ {
132
+ variant_id: '1',
133
+ quantity: 1,
134
+ tax_rate: 21.0,
135
+ unit_price: 10.0,
136
+ },
137
+ ],
138
+ payment_method: 'bank-transfer',
139
+ });
140
+ expect(order).toBeTruthy();
141
+ expect(order).toHaveProperty('id', expect.any(String));
142
+ });
143
+ */
144
+
145
+ let orders: components['schemas']['OrderItemOut'][];
146
+ test('getOrders', async () => {
147
+ orders = await consumer.ecommerce.getOrders({
148
+ date_from: '2021-10-01',
149
+ date_to: '2021-12-31',
150
+ });
151
+ expect(orders).toBeInstanceOf(Array);
152
+ });
153
+
154
+ test('getOrder', async () => {
155
+ const order = await consumer.ecommerce.getOrder(orders[0].id);
156
+ expect(order).toBeTruthy();
157
+ expect(order).toHaveProperty('id', expect.any(String));
158
+ expect(order).toHaveProperty('order_number');
159
+ expect(order).toHaveProperty('billing_address');
160
+ expect(order).toHaveProperty('shipping_address');
161
+ expect(order).toHaveProperty('created_on');
162
+ expect(order).toHaveProperty('confirmed_on');
163
+ expect(order).toHaveProperty('cancelled_on');
164
+ expect(order).toHaveProperty('status', expect.any(String));
165
+ expect(order).toHaveProperty('discount_amount', expect.any(Number));
166
+ expect(order).toHaveProperty('untaxed_amount_without_fees', expect.any(Number));
167
+ expect(order).toHaveProperty('tax_amount_without_fees', expect.any(Number));
168
+ expect(order).toHaveProperty('total_without_fees', expect.any(Number));
169
+ expect(order).toHaveProperty('untaxed_amount', expect.any(Number));
170
+ expect(order).toHaveProperty('tax_amount', expect.any(Number));
171
+ expect(order).toHaveProperty('total', expect.any(Number));
172
+ expect(order).toHaveProperty('refunded_amount', expect.any(Number));
173
+ expect(order).toHaveProperty('currency');
174
+ expect(order).toHaveProperty('note');
175
+ expect(order).toHaveProperty('lines', expect.any(Array));
176
+ expect(order).toHaveProperty('other_fees');
177
+ });
@@ -0,0 +1,22 @@
1
+ import { expect, test } from '@jest/globals';
2
+ import * as chift from '../../src/index';
3
+ import * as dotenv from 'dotenv';
4
+ dotenv.config();
5
+
6
+ const client = new chift.API({
7
+ baseUrl: process.env.CHIFT_BASE_URL,
8
+ clientId: process.env.CHIFT_CLIENT_ID as string,
9
+ clientSecret: process.env.CHIFT_CLIENT_SECRET as string,
10
+ accountId: process.env.CHIFT_ACCOUNT_ID as string,
11
+ });
12
+
13
+ test('getIntegrations', async () => {
14
+ const integrations = await client.Integrations.getIntegrations();
15
+ expect(integrations).toBeInstanceOf(Array);
16
+ expect(integrations.length).toBeGreaterThan(0);
17
+ expect(integrations[0]).toHaveProperty('integrationid', expect.any(Number));
18
+ expect(integrations[0]).toHaveProperty('name', expect.any(String));
19
+ expect(integrations[0]).toHaveProperty('status', expect.stringMatching(/^(active|inactive)$/));
20
+ expect(integrations[0]).toHaveProperty('api', expect.any(String));
21
+ expect(integrations[0]).toHaveProperty('credentials', expect.any(Array));
22
+ });
@@ -0,0 +1,88 @@
1
+ import { beforeAll, expect, test } from '@jest/globals';
2
+ import * as chift from '../../src/index';
3
+ import * as dotenv from 'dotenv';
4
+ import { components } from '../../src/types/public-api/schema';
5
+ dotenv.config();
6
+
7
+ const client = new chift.API({
8
+ baseUrl: process.env.CHIFT_BASE_URL,
9
+ clientId: process.env.CHIFT_CLIENT_ID as string,
10
+ clientSecret: process.env.CHIFT_CLIENT_SECRET as string,
11
+ accountId: process.env.CHIFT_ACCOUNT_ID as string,
12
+ });
13
+
14
+ const consumerId = process.env.CHIFT_AXONAUT_CONSUMER_ID as string;
15
+
16
+ let consumer: any;
17
+ beforeAll(async () => {
18
+ consumer = await client.Consumers.getConsumerById(consumerId);
19
+ });
20
+
21
+ let invoices: components['schemas']['InvoiceItemOut'][];
22
+ test('getInvoices', async () => {
23
+ invoices = await consumer.invoicing.getInvoices({
24
+ invoice_type: 'customer_invoice',
25
+ date_from: '2023-01-01',
26
+ date_to: '2023-01-31',
27
+ });
28
+ expect(invoices).toBeInstanceOf(Array);
29
+ expect(invoices.length).toBeGreaterThan(0);
30
+ expect(invoices[0]).toHaveProperty('id', expect.any(String));
31
+ });
32
+
33
+ test('getInvoiceById', async () => {
34
+ const invoice = await consumer.invoicing.getInvoiceById(invoices[0].id, { include_pdf: false });
35
+ expect(invoice).toHaveProperty('id', expect.any(String));
36
+ });
37
+
38
+ let products: components['schemas']['ProductItemOut'][];
39
+ test('getProducts', async () => {
40
+ products = await consumer.invoicing.getProducts();
41
+ expect(products).toBeInstanceOf(Array);
42
+ expect(products.length).toBeGreaterThan(0);
43
+ expect(products[0]).toHaveProperty('id', expect.any(String));
44
+ });
45
+
46
+ test('getProductById', async () => {
47
+ const product = await consumer.invoicing.getProductById(products[0].id);
48
+ expect(product).toHaveProperty('id', expect.any(String));
49
+ });
50
+
51
+ let vatCodes: components['schemas']['models__invoicing__VatCode'][];
52
+ test('getTaxes', async () => {
53
+ vatCodes = await consumer.invoicing.getTaxes();
54
+ expect(vatCodes).toBeInstanceOf(Array);
55
+ expect(vatCodes.length).toBeGreaterThan(0);
56
+ expect(vatCodes[0]).toHaveProperty('id', expect.any(String));
57
+ });
58
+
59
+ test('getTaxById', async () => {
60
+ const tax = await consumer.invoicing.getTaxById(vatCodes[0].id);
61
+ expect(tax).toHaveProperty('id', expect.any(String));
62
+ });
63
+
64
+ let opportunities: components['schemas']['OpportunityItem'][];
65
+ test('getOpportunities', async () => {
66
+ opportunities = await consumer.invoicing.getOpportunities();
67
+ expect(opportunities).toBeInstanceOf(Array);
68
+ expect(opportunities.length).toBeGreaterThan(0);
69
+ expect(opportunities[0]).toHaveProperty('id', expect.any(String));
70
+ });
71
+
72
+ test('getOpportunitiesById', async () => {
73
+ const opportunity = await consumer.invoicing.getOpportunitiesById(opportunities[0].id);
74
+ expect(opportunity).toHaveProperty('id', expect.any(String));
75
+ });
76
+
77
+ let contacts: components['schemas']['ContactItemOut'][];
78
+ test('getContacts', async () => {
79
+ contacts = await consumer.invoicing.getContacts();
80
+ expect(contacts).toBeInstanceOf(Array);
81
+ expect(contacts.length).toBeGreaterThan(0);
82
+ expect(contacts[0]).toHaveProperty('id', expect.any(String));
83
+ });
84
+
85
+ test('getContactById', async () => {
86
+ const contact = await consumer.invoicing.getContactById(contacts[0].id);
87
+ expect(contact).toHaveProperty('id', expect.any(String));
88
+ });
@@ -0,0 +1,145 @@
1
+ import { beforeAll, expect, test } from '@jest/globals';
2
+ import * as chift from '../../src/index';
3
+ import * as dotenv from 'dotenv';
4
+ import { components } from '../../src/types/public-api/schema';
5
+ dotenv.config();
6
+
7
+ const client = new chift.API({
8
+ baseUrl: process.env.CHIFT_BASE_URL,
9
+ clientId: process.env.CHIFT_CLIENT_ID as string,
10
+ clientSecret: process.env.CHIFT_CLIENT_SECRET as string,
11
+ accountId: process.env.CHIFT_ACCOUNT_ID as string,
12
+ });
13
+
14
+ // Split testing between two APIs to support all endpoints
15
+ const cashpadConsumerId = process.env.CHIFT_CASHPAD_CONSUMER_ID as string;
16
+ const lightspeedConsumerId = process.env.CHIFT_LIGHTSPEED_CONSUMER_ID as string;
17
+
18
+ let cashpadConsumer: any;
19
+ let lightspeedConsumer: any;
20
+ beforeAll(async () => {
21
+ cashpadConsumer = await client.Consumers.getConsumerById(cashpadConsumerId);
22
+ lightspeedConsumer = await client.Consumers.getConsumerById(lightspeedConsumerId);
23
+ });
24
+
25
+ test('getLocations', async () => {
26
+ const locations = await lightspeedConsumer.pos.getLocations();
27
+ expect(locations).toBeInstanceOf(Array);
28
+ expect(locations.length).toBeGreaterThan(0);
29
+ expect(locations[0]).toHaveProperty('id', expect.any(String));
30
+ expect(locations[0]).toHaveProperty('name', expect.any(String));
31
+ });
32
+
33
+ let orders: components['schemas']['OrderItem'][];
34
+ test('getOrders', async () => {
35
+ orders = await lightspeedConsumer.pos.getOrders({
36
+ date_from: '2023-01-11',
37
+ date_to: '2023-02-28',
38
+ });
39
+ expect(orders).toBeInstanceOf(Array);
40
+ expect(orders.length).toBeGreaterThan(0);
41
+ expect(orders[0]).toHaveProperty('id', expect.any(String));
42
+ });
43
+
44
+ // TODO: Fix Method Not Allowed error
45
+ test.skip('createCustomer', async () => {
46
+ const body = {
47
+ first_name: 'John',
48
+ last_name: 'Doe',
49
+ email: 'test@test.com',
50
+ };
51
+ const customer = await cashpadConsumer.pos.createCustomer(body);
52
+ expect(customer).toBeTruthy();
53
+ expect(customer).toHaveProperty('id', expect.any(String));
54
+ expect(customer).toHaveProperty('name');
55
+ });
56
+
57
+ // TODO: Fix timeout error
58
+ let customers: any[] = [];
59
+ test.skip('getCustomers', async () => {
60
+ customers = await cashpadConsumer.pos.getCustomers();
61
+ expect(customers).toBeInstanceOf(Array);
62
+ expect(customers.length).toBeGreaterThan(0);
63
+ expect(customers[0]).toHaveProperty('id', expect.any(String));
64
+ });
65
+
66
+ // TODO: Fix The day parameter is missing error
67
+ test.skip('getOrder', async () => {
68
+ const order = await lightspeedConsumer.pos.getOrder(orders[0].id);
69
+ expect(order).toBeTruthy();
70
+ expect(order).toHaveProperty('id', expect.any(String));
71
+ expect(order).toHaveProperty('order_number');
72
+ expect(order).toHaveProperty('creation_date', expect.any(String));
73
+ expect(order).toHaveProperty('closing_date');
74
+ expect(order).toHaveProperty('service_date');
75
+ expect(order).toHaveProperty('total', expect.any(Number));
76
+ expect(order).toHaveProperty('tax_amount', expect.any(Number));
77
+ expect(order).toHaveProperty('total_discount');
78
+ expect(order).toHaveProperty('total_refund');
79
+ expect(order).toHaveProperty('total_tip', expect.any(Number));
80
+ expect(order).toHaveProperty('items', expect.any(Array));
81
+ expect(order).toHaveProperty('payments', expect.any(Array));
82
+ expect(order).toHaveProperty('currency');
83
+ expect(order).toHaveProperty('country');
84
+ expect(order).toHaveProperty('loyalty');
85
+ expect(order).toHaveProperty('customer_id');
86
+ expect(order).toHaveProperty('location_id');
87
+ expect(order).toHaveProperty('taxes');
88
+ });
89
+
90
+ // TODO: Fix getCustomers first
91
+ test.skip('getCustomer', async () => {
92
+ const customer = await cashpadConsumer.pos.getCustomer(customers[0].id);
93
+ expect(customer).toBeTruthy();
94
+ expect(customer).toHaveProperty('id', expect.any(String));
95
+ expect(customer).toHaveProperty('name');
96
+ });
97
+
98
+ test('getPaymentMethods', async () => {
99
+ const paymentMethods = await lightspeedConsumer.pos.getPaymentMethods();
100
+ expect(paymentMethods).toBeInstanceOf(Array);
101
+ expect(paymentMethods.length).toBeGreaterThan(0);
102
+ expect(paymentMethods[0]).toHaveProperty('id', expect.any(String));
103
+ expect(paymentMethods[0]).toHaveProperty('name', expect.any(String));
104
+ expect(paymentMethods[0]).toHaveProperty('extra');
105
+ });
106
+
107
+ test('getSales', async () => {
108
+ const sales = await lightspeedConsumer.pos.getSales({
109
+ date_from: '2022-08-11',
110
+ date_to: '2022-08-12',
111
+ });
112
+ expect(sales).toHaveProperty('total', expect.any(Number));
113
+ expect(sales).toHaveProperty('tax_amount', expect.any(Number));
114
+ expect(sales).toHaveProperty('taxes', expect.any(Array));
115
+ });
116
+
117
+ test('getClosure', async () => {
118
+ const closure = await lightspeedConsumer.pos.getClosure('2022-08-11');
119
+ expect(closure).toHaveProperty('date', expect.any(String));
120
+ expect(closure).toHaveProperty('status');
121
+ });
122
+
123
+ test('getPayments', async () => {
124
+ const payments = await lightspeedConsumer.pos.getPayments({
125
+ date_from: '2023-01-11',
126
+ date_to: '2023-02-28',
127
+ });
128
+ expect(payments).toBeInstanceOf(Array);
129
+ expect(payments.length).toBeGreaterThan(0);
130
+ expect(payments[0]).toHaveProperty('id');
131
+ expect(payments[0]).toHaveProperty('payment_method_id');
132
+ expect(payments[0]).toHaveProperty('payment_method_name');
133
+ expect(payments[0]).toHaveProperty('total', expect.any(Number));
134
+ expect(payments[0]).toHaveProperty('tip', expect.any(Number));
135
+ expect(payments[0]).toHaveProperty('status');
136
+ expect(payments[0]).toHaveProperty('currency');
137
+ expect(payments[0]).toHaveProperty('date');
138
+ });
139
+
140
+ // TODO: Fix API Resource does not exist
141
+ test.skip('updateOrder', async () => {
142
+ const order = await lightspeedConsumer.pos.updateOrder(orders[0].id, {});
143
+ expect(order).toBeTruthy();
144
+ expect(order).toHaveProperty('id', expect.any(String));
145
+ });
@@ -0,0 +1,60 @@
1
+ import { beforeAll, expect, test } from '@jest/globals';
2
+ import * as chift from '../../src/index';
3
+ import * as dotenv from 'dotenv';
4
+
5
+ dotenv.config();
6
+
7
+ const client = new chift.API({
8
+ baseUrl: process.env.CHIFT_BASE_URL,
9
+ clientId: process.env.CHIFT_CLIENT_ID as string,
10
+ clientSecret: process.env.CHIFT_CLIENT_SECRET as string,
11
+ accountId: process.env.CHIFT_ACCOUNT_ID as string,
12
+ });
13
+
14
+ const flowName = 'Je suis un flux de test';
15
+
16
+ let sync: any;
17
+ let flow: any;
18
+
19
+ beforeAll(async () => {
20
+ const syncId = process.env.CHIFT_TEST_SYNC_ID as string;
21
+ sync = await client.Syncs.getSyncById(syncId);
22
+ });
23
+
24
+ test('createFlow', async () => {
25
+ flow = await sync.createFlow(
26
+ {
27
+ name: flowName,
28
+ description: 'Flux de test',
29
+ execution: {
30
+ type: 'code',
31
+ },
32
+ trigger: {
33
+ type: 'event',
34
+ },
35
+ config: {},
36
+ },
37
+ async (consumer: any, flowContext: any) => {
38
+ console.log(`Mon flow_id : ${flowContext.flow_id}`);
39
+ console.log(`Bonjour, ceci est un test, on exécute le flux pour consumer: ${consumer}`);
40
+ }
41
+ );
42
+
43
+ expect(flow).toHaveProperty('flowId');
44
+ expect(flow).toHaveProperty('name', flowName);
45
+ });
46
+
47
+ test('getFlows', async () => {
48
+ const flows = await sync.getFlows();
49
+ expect(flows).toBeInstanceOf(Array);
50
+ });
51
+
52
+ test('getFlowByName', async () => {
53
+ const flowWithName = await sync.getFlowByName(flow.name);
54
+ expect(flowWithName).toHaveProperty('name', flow.name);
55
+ });
56
+
57
+ test('getFlowById', async () => {
58
+ const flowWithId = await sync.getFlowById(flow.flowId);
59
+ expect(flowWithId).toHaveProperty('flowId', flow.flowId);
60
+ });
@@ -0,0 +1,23 @@
1
+ import { expect, test } from '@jest/globals';
2
+ import * as chift from '../../src/index';
3
+ import * as dotenv from 'dotenv';
4
+
5
+ dotenv.config();
6
+
7
+ const client = new chift.API({
8
+ baseUrl: process.env.CHIFT_BASE_URL,
9
+ clientId: process.env.CHIFT_CLIENT_ID as string,
10
+ clientSecret: process.env.CHIFT_CLIENT_SECRET as string,
11
+ accountId: process.env.CHIFT_ACCOUNT_ID as string,
12
+ });
13
+
14
+ test('getSyncs', async () => {
15
+ const syncs = await client.Syncs.getSyncs();
16
+ expect(syncs).toBeInstanceOf(Array);
17
+ });
18
+
19
+ test('getSyncById', async () => {
20
+ const syncId = process.env.CHIFT_TEST_SYNC_ID as string;
21
+ const sync = await client.Syncs.getSyncById(syncId);
22
+ expect(sync).toHaveProperty('syncid', syncId);
23
+ });
@@ -0,0 +1,92 @@
1
+ import { afterAll, beforeAll, expect, test } from '@jest/globals';
2
+ import * as chift from '../../src/index';
3
+ import * as dotenv from 'dotenv';
4
+ import axios from 'axios';
5
+ dotenv.config();
6
+
7
+ const client = new chift.API({
8
+ baseUrl: process.env.CHIFT_BASE_URL,
9
+ clientId: process.env.CHIFT_CLIENT_ID as string,
10
+ clientSecret: process.env.CHIFT_CLIENT_SECRET as string,
11
+ accountId: process.env.CHIFT_ACCOUNT_ID as string,
12
+ });
13
+
14
+ let webhook: any;
15
+
16
+ beforeAll(async () => {
17
+ webhook = await client.Webhooks.registerWebhook({
18
+ event: 'account.connection.created',
19
+ url: 'https://test',
20
+ signingsecret: 'secret',
21
+ });
22
+ expect(webhook).toHaveProperty('status', 'active');
23
+ expect(webhook).toHaveProperty('webhookid', expect.any(String));
24
+ expect(webhook).toHaveProperty('accountid', expect.any(String));
25
+ expect(webhook).toHaveProperty('createdby');
26
+ expect(webhook).toHaveProperty('createdon');
27
+ expect(webhook).toHaveProperty('event', 'account.connection.created');
28
+ expect(webhook).toHaveProperty('url', 'https://test');
29
+ expect(webhook).toHaveProperty('status', 'active');
30
+ expect(webhook).toHaveProperty('integrationid');
31
+ });
32
+
33
+ test('getWebhookTypes', async () => {
34
+ const webhookTypes = await client.Webhooks.getWebhookTypes();
35
+ expect(webhookTypes).toBeInstanceOf(Array);
36
+ expect(webhookTypes.length).toBeGreaterThan(0);
37
+ expect(webhookTypes[0]).toHaveProperty('event', expect.any(String));
38
+ expect(webhookTypes[0]).toHaveProperty('api');
39
+ });
40
+
41
+ test('getWebhooks', async () => {
42
+ const webhooks = await client.Webhooks.getWebhooks();
43
+ expect(webhooks).toBeInstanceOf(Array);
44
+ expect(webhooks.length).toBeGreaterThan(0);
45
+ expect(webhooks[0]).toHaveProperty('webhookid', expect.any(String));
46
+ });
47
+
48
+ test('getWebhookById', async () => {
49
+ const webhookWithId = await client.Webhooks.getWebhookById(webhook.webhookid);
50
+ expect(webhookWithId).toHaveProperty('webhookid', webhook.webhookid);
51
+ expect(webhookWithId).toHaveProperty('accountid', expect.any(String));
52
+ expect(webhookWithId).toHaveProperty('createdby');
53
+ expect(webhookWithId).toHaveProperty('createdon');
54
+ expect(webhookWithId).toHaveProperty('event', expect.any(String));
55
+ expect(webhookWithId).toHaveProperty('url', expect.any(String));
56
+ expect(webhookWithId).toHaveProperty('status', expect.any(String));
57
+ expect(webhookWithId).toHaveProperty('integrationid');
58
+ });
59
+
60
+ test('updateWebhookById', async () => {
61
+ const updatedWebhook = await client.Webhooks.updateWebhookById(webhook.webhookid, {
62
+ status: 'inactive',
63
+ });
64
+ expect(updatedWebhook).toHaveProperty('webhookid', expect.any(String));
65
+ expect(updatedWebhook).toHaveProperty('accountid', expect.any(String));
66
+ expect(updatedWebhook).toHaveProperty('createdby');
67
+ expect(updatedWebhook).toHaveProperty('createdon');
68
+ expect(updatedWebhook).toHaveProperty('event', 'account.connection.created');
69
+ expect(updatedWebhook).toHaveProperty('url', 'https://test');
70
+ expect(updatedWebhook).toHaveProperty('status', 'inactive');
71
+ expect(updatedWebhook).toHaveProperty('integrationid');
72
+ });
73
+
74
+ test('getWebhookLogsByWebhookId', async () => {
75
+ const webhookLogs = await client.Webhooks.getWebhookLogsByWebhookId(webhook.webhookid);
76
+ expect(webhookLogs).toBeInstanceOf(Array);
77
+ });
78
+
79
+ afterAll(async () => {
80
+ expect.assertions(1);
81
+ try {
82
+ await client.Webhooks.unRegisterWebhook(webhook.webhookid);
83
+ await client.Webhooks.getWebhookById(webhook.webhookid);
84
+ } catch (e: unknown) {
85
+ if (axios.isAxiosError(e)) {
86
+ expect(e.message).toMatch('Request failed with status code 404');
87
+ return;
88
+ }
89
+
90
+ throw e;
91
+ }
92
+ });
@@ -0,0 +1,14 @@
1
+ #!/bin/bash
2
+ export CHIFT_ACCOUNT_ID="c16e37b6-b816-4265-8924-f2aeefcbe7fe"
3
+ export CHIFT_AXONAUT_CONSUMER_ID="05a68dfd-4fcd-45d5-93c5-c987587ebad5"
4
+ export CHIFT_BASE_URL="https://api.chift.site"
5
+ export CHIFT_CASHPAD_CONSUMER_ID="a6572100-fbb6-4d9d-a507-773dbe6b1042"
6
+ export CHIFT_CLIENT_ID="IzagGvQFLKnFRsW"
7
+ export CHIFT_CLIENT_SECRET="NvroyDxDjjA6ylxmotjz"
8
+ export CHIFT_LIGHTSPEED_CONSUMER_ID="d0b5d8c6-b7b0-4714-af0d-eec857e91feb"
9
+ export CHIFT_ODOO_CONSUMER_ID="84a6cb97-a641-43ab-ac63-d9bd7ecb85e0"
10
+ export CHIFT_TEST_SYNC_ID="1174849b-f710-454b-b088-df0ea38089f7"
11
+ export CHIFT_WOOCOMMERCE_CONSUMER_ID="dd168ff5-3a40-4b65-bd83-4dde1efb316b"
12
+ export CHIFT_SYNC_CONSUMER_ID="05a68dfd-4fcd-45d5-93c5-c987587ebad5"
13
+ export CHIFT_TEST_DATASTORE_NAME="CONTACTS"
14
+ export CHIFT_TEST_DATASTORE_ID="06794cc1-011e-4a49-8f83-cf98e04ce64d"