@chift/chift-nodejs 1.0.4 → 1.0.6
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/.eslintcache +1 -0
- package/CHANGELOG.md +8 -0
- package/coverage/clover.xml +1645 -0
- package/coverage/coverage-final.json +19 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +146 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/src/helpers/index.html +131 -0
- package/coverage/lcov-report/src/helpers/openapi.ts.html +151 -0
- package/coverage/lcov-report/src/helpers/settings.ts.html +94 -0
- package/coverage/lcov-report/src/index.html +116 -0
- package/coverage/lcov-report/src/index.ts.html +88 -0
- package/coverage/lcov-report/src/modules/accounting.ts.html +1156 -0
- package/coverage/lcov-report/src/modules/api.ts.html +190 -0
- package/coverage/lcov-report/src/modules/consumer.ts.html +616 -0
- package/coverage/lcov-report/src/modules/consumers.ts.html +331 -0
- package/coverage/lcov-report/src/modules/custom.ts.html +193 -0
- package/coverage/lcov-report/src/modules/datastores.ts.html +142 -0
- package/coverage/lcov-report/src/modules/ecommerce.ts.html +331 -0
- package/coverage/lcov-report/src/modules/flow.ts.html +589 -0
- package/coverage/lcov-report/src/modules/index.html +326 -0
- package/coverage/lcov-report/src/modules/integrations.ts.html +151 -0
- package/coverage/lcov-report/src/modules/internalApi.ts.html +586 -0
- package/coverage/lcov-report/src/modules/invoicing.ts.html +391 -0
- package/coverage/lcov-report/src/modules/pos.ts.html +421 -0
- package/coverage/lcov-report/src/modules/sync.ts.html +316 -0
- package/coverage/lcov-report/src/modules/syncs.ts.html +169 -0
- package/coverage/lcov-report/src/modules/webhooks.ts.html +343 -0
- package/coverage/lcov.info +1976 -0
- package/dist/src/modules/api.d.ts +855 -420
- package/dist/src/modules/consumer.d.ts +56 -28
- package/dist/src/modules/consumers.d.ts +285 -140
- package/dist/src/modules/internalApi.js +13 -4
- package/dist/src/modules/pos.d.ts +4 -0
- package/dist/src/modules/pos.js +14 -0
- package/dist/src/modules/sync.d.ts +229 -113
- package/dist/src/modules/syncs.d.ts +570 -280
- package/dist/test/modules/flow.test.d.ts +1 -0
- package/dist/test/modules/flow.test.js +69 -0
- package/dist/test/modules/pos.test.js +13 -0
- package/jest.config.ts +1 -1
- package/package.json +1 -1
- package/src/modules/internalApi.ts +19 -10
- package/src/modules/pos.ts +26 -0
- package/src/modules/sync.ts +1 -1
- package/src/modules/syncs.ts +2 -2
- package/src/types/public-api/schema.d.ts +426 -80
- package/test/modules/consumer.test.ts +1 -1
- package/test/modules/pos.test.ts +15 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
const globals_1 = require("@jest/globals");
|
|
36
|
+
const chift = __importStar(require("../../src/index"));
|
|
37
|
+
const dotenv = __importStar(require("dotenv"));
|
|
38
|
+
dotenv.config();
|
|
39
|
+
const client = new chift.API({
|
|
40
|
+
baseUrl: process.env.CHIFT_BASE_URL,
|
|
41
|
+
clientId: process.env.CHIFT_CLIENT_ID,
|
|
42
|
+
clientSecret: process.env.CHIFT_CLIENT_SECRET,
|
|
43
|
+
accountId: process.env.CHIFT_ACCOUNT_ID,
|
|
44
|
+
});
|
|
45
|
+
let flow;
|
|
46
|
+
(0, globals_1.beforeAll)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
const syncId = process.env.CHIFT_TEST_SYNC_ID;
|
|
48
|
+
const sync = yield client.Syncs.getSyncById(syncId);
|
|
49
|
+
flow = yield sync.createFlow({
|
|
50
|
+
name: 'Je suis un flux de test',
|
|
51
|
+
description: 'Flux de test',
|
|
52
|
+
execution: {
|
|
53
|
+
type: 'code',
|
|
54
|
+
},
|
|
55
|
+
trigger: {
|
|
56
|
+
type: 'event',
|
|
57
|
+
},
|
|
58
|
+
config: {},
|
|
59
|
+
}, (consumer, flowContext) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
+
console.log(`Mon flow_id : ${flowContext.flow_id}`);
|
|
61
|
+
console.log(`Bonjour, ceci est un test, on exécute le flux pour consumer: ${consumer}`);
|
|
62
|
+
}));
|
|
63
|
+
}));
|
|
64
|
+
(0, globals_1.test)('executeLocal', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
flow.execute({ context: { logs: true, local: true } });
|
|
66
|
+
}));
|
|
67
|
+
(0, globals_1.test)('execute', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
flow.execute({ context: { logs: true, local: false } });
|
|
69
|
+
}));
|
|
@@ -45,11 +45,14 @@ const client = new chift.API({
|
|
|
45
45
|
// Split testing between two APIs to support all endpoints
|
|
46
46
|
const cashpadConsumerId = process.env.CHIFT_CASHPAD_CONSUMER_ID;
|
|
47
47
|
const lightspeedConsumerId = process.env.CHIFT_LIGHTSPEED_CONSUMER_ID;
|
|
48
|
+
const zeltyConsumerId = process.env.CHIFT_ZELTY_CONSUMER_ID;
|
|
48
49
|
let cashpadConsumer;
|
|
49
50
|
let lightspeedConsumer;
|
|
51
|
+
let zeltyConsumer;
|
|
50
52
|
(0, globals_1.beforeAll)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
53
|
cashpadConsumer = yield client.Consumers.getConsumerById(cashpadConsumerId);
|
|
52
54
|
lightspeedConsumer = yield client.Consumers.getConsumerById(lightspeedConsumerId);
|
|
55
|
+
zeltyConsumer = yield client.Consumers.getConsumerById(zeltyConsumerId);
|
|
53
56
|
}));
|
|
54
57
|
(0, globals_1.test)('getLocations', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
58
|
const locations = yield lightspeedConsumer.pos.getLocations();
|
|
@@ -162,3 +165,13 @@ globals_1.test.skip('updateOrder', () => __awaiter(void 0, void 0, void 0, funct
|
|
|
162
165
|
(0, globals_1.expect)(order).toBeTruthy();
|
|
163
166
|
(0, globals_1.expect)(order).toHaveProperty('id', globals_1.expect.any(String));
|
|
164
167
|
}));
|
|
168
|
+
(0, globals_1.test)('getProducts', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
169
|
+
const products = yield zeltyConsumer.pos.getProducts();
|
|
170
|
+
(0, globals_1.expect)(products).toBeInstanceOf(Array);
|
|
171
|
+
(0, globals_1.expect)(products.length).toBeGreaterThan(0);
|
|
172
|
+
}));
|
|
173
|
+
(0, globals_1.test)('getProductCategories', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
174
|
+
const productCategories = yield zeltyConsumer.pos.getProductCategories();
|
|
175
|
+
(0, globals_1.expect)(productCategories).toBeInstanceOf(Array);
|
|
176
|
+
(0, globals_1.expect)(productCategories.length).toBeGreaterThan(0);
|
|
177
|
+
}));
|
package/jest.config.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chift/chift-nodejs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "The Chift NodeJS library provides convenient access to the Chift API from applications written in the NodeJS language (Javascript/Typescript).",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -26,27 +26,36 @@ class InternalAPI {
|
|
|
26
26
|
|
|
27
27
|
this.instance.interceptors.request.use(
|
|
28
28
|
(config) => {
|
|
29
|
-
return new Promise((resolve) => {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
30
|
if (this.relatedChainExecutionId) {
|
|
31
31
|
config.headers['X-Chift-RelatedChainExecutionId'] =
|
|
32
32
|
this.relatedChainExecutionId;
|
|
33
33
|
}
|
|
34
34
|
if (this.token) {
|
|
35
35
|
if (this.token?.expires_on < new Date().getTime()) {
|
|
36
|
-
return this.getToken()
|
|
37
|
-
|
|
38
|
-
'
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
return this.getToken()
|
|
37
|
+
.then(() => {
|
|
38
|
+
config.headers['Authorization'] =
|
|
39
|
+
'Bearer ' + this.token?.access_token;
|
|
40
|
+
return resolve(config);
|
|
41
|
+
})
|
|
42
|
+
.catch((err) => {
|
|
43
|
+
return reject(err);
|
|
44
|
+
});
|
|
41
45
|
} else {
|
|
42
46
|
config.headers['Authorization'] = 'Bearer ' + this.token?.access_token;
|
|
43
47
|
return resolve(config);
|
|
44
48
|
}
|
|
45
49
|
} else {
|
|
46
|
-
return this.getToken()
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
return this.getToken()
|
|
51
|
+
.then(() => {
|
|
52
|
+
config.headers['Authorization'] =
|
|
53
|
+
'Bearer ' + this.token?.access_token;
|
|
54
|
+
return resolve(config);
|
|
55
|
+
})
|
|
56
|
+
.catch((err) => {
|
|
57
|
+
return reject(err);
|
|
58
|
+
});
|
|
50
59
|
}
|
|
51
60
|
});
|
|
52
61
|
},
|
package/src/modules/pos.ts
CHANGED
|
@@ -11,6 +11,16 @@ type getPaymentMethodsParams = Omit<
|
|
|
11
11
|
'page' | 'size'
|
|
12
12
|
>;
|
|
13
13
|
|
|
14
|
+
type getProductCategoriesParams = Omit<
|
|
15
|
+
operations['pos_get_product_categories']['parameters']['query'],
|
|
16
|
+
'page' | 'size'
|
|
17
|
+
>;
|
|
18
|
+
|
|
19
|
+
type getProductsParams = Omit<
|
|
20
|
+
operations['pos_get_products']['parameters']['query'],
|
|
21
|
+
'page' | 'size'
|
|
22
|
+
>;
|
|
23
|
+
|
|
14
24
|
type getCustomersParams = Omit<
|
|
15
25
|
operations['pos_get_customers']['parameters']['query'],
|
|
16
26
|
'page' | 'size'
|
|
@@ -71,6 +81,22 @@ const posFactory = {
|
|
|
71
81
|
url: `/consumers/{consumer_id}/pos/payment-methods`,
|
|
72
82
|
};
|
|
73
83
|
},
|
|
84
|
+
getProductCategories(
|
|
85
|
+
params: getProductCategoriesParams
|
|
86
|
+
): RequestData<components['schemas']['ProductCategoryItem'][]> {
|
|
87
|
+
return {
|
|
88
|
+
params,
|
|
89
|
+
method: 'get',
|
|
90
|
+
url: `/consumers/{consumer_id}/pos/product-categories`,
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
getProducts(params: getProductsParams): RequestData<components['schemas']['POSProductItem'][]> {
|
|
94
|
+
return {
|
|
95
|
+
params,
|
|
96
|
+
method: 'get',
|
|
97
|
+
url: `/consumers/{consumer_id}/pos/products`,
|
|
98
|
+
};
|
|
99
|
+
},
|
|
74
100
|
getSales(
|
|
75
101
|
params: operations['pos_get_sales']['parameters']['query']
|
|
76
102
|
): RequestData<components['schemas']['SalesItem']> {
|
package/src/modules/sync.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { ContextType } from '../types/sync';
|
|
|
4
4
|
import { Consumer } from './consumer';
|
|
5
5
|
import { Flow } from './flow';
|
|
6
6
|
|
|
7
|
-
const Sync = (internalApi: InternalAPI, body: components['schemas']['
|
|
7
|
+
const Sync = (internalApi: InternalAPI, body: components['schemas']['ReadSyncItem']) => {
|
|
8
8
|
const _internalApi: InternalAPI = internalApi;
|
|
9
9
|
const data = body;
|
|
10
10
|
const name = data.name;
|
package/src/modules/syncs.ts
CHANGED
|
@@ -6,14 +6,14 @@ const Syncs = (internalApi: InternalAPI) => {
|
|
|
6
6
|
const _internalApi: InternalAPI = internalApi;
|
|
7
7
|
|
|
8
8
|
const getSyncs = async () => {
|
|
9
|
-
const { data }: { data: components['schemas']['
|
|
9
|
+
const { data }: { data: components['schemas']['ReadSyncItem'][] } = await _internalApi.get(
|
|
10
10
|
'/syncs'
|
|
11
11
|
);
|
|
12
12
|
return data.map((sync) => Sync(_internalApi, sync));
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
const getSyncById = async (syncid: string) => {
|
|
16
|
-
const { data }: { data: components['schemas']['
|
|
16
|
+
const { data }: { data: components['schemas']['ReadSyncItem'] } = await _internalApi.get(
|
|
17
17
|
`/syncs/${syncid}`
|
|
18
18
|
);
|
|
19
19
|
return Sync(_internalApi, data);
|