@chift/chift-nodejs 1.0.18 → 1.0.19
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/dist/src/helpers/openapi.d.ts +3 -0
- package/dist/src/helpers/openapi.js +18 -0
- package/dist/src/helpers/settings.d.ts +4 -0
- package/dist/src/helpers/settings.js +5 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/modules/accounting.d.ts +68 -0
- package/dist/src/modules/accounting.js +326 -0
- package/dist/src/modules/api.d.ts +18351 -0
- package/dist/src/modules/api.js +36 -0
- package/dist/src/modules/consumer.d.ts +3622 -0
- package/dist/src/modules/consumer.js +142 -0
- package/dist/src/modules/consumers.d.ts +18237 -0
- package/dist/src/modules/consumers.js +51 -0
- package/dist/src/modules/custom.d.ts +8 -0
- package/dist/src/modules/custom.js +36 -0
- package/dist/src/modules/datastores.d.ts +18 -0
- package/dist/src/modules/datastores.js +23 -0
- package/dist/src/modules/ecommerce.d.ts +24 -0
- package/dist/src/modules/ecommerce.js +97 -0
- package/dist/src/modules/flow.d.ts +15 -0
- package/dist/src/modules/flow.js +156 -0
- package/dist/src/modules/integrations.d.ts +23 -0
- package/dist/src/modules/integrations.js +23 -0
- package/dist/src/modules/internalApi.d.ts +24 -0
- package/dist/src/modules/internalApi.js +175 -0
- package/dist/src/modules/invoicing.d.ts +20 -0
- package/dist/src/modules/invoicing.js +90 -0
- package/dist/src/modules/payment.d.ts +14 -0
- package/dist/src/modules/payment.js +41 -0
- package/dist/src/modules/pms.d.ts +15 -0
- package/dist/src/modules/pms.js +47 -0
- package/dist/src/modules/pos.d.ts +26 -0
- package/dist/src/modules/pos.js +101 -0
- package/dist/src/modules/sync.d.ts +14654 -0
- package/dist/src/modules/sync.js +73 -0
- package/dist/src/modules/syncs.d.ts +11 -0
- package/dist/src/modules/syncs.js +39 -0
- package/dist/src/modules/webhooks.d.ts +58 -0
- package/dist/src/modules/webhooks.js +53 -0
- package/{src/types/api.ts → dist/src/types/api.d.ts} +4 -12
- package/dist/src/types/api.js +2 -0
- package/{src/types/consumers.ts → dist/src/types/consumers.d.ts} +0 -1
- package/dist/src/types/consumers.js +2 -0
- package/dist/src/types/public-api/mappings.js +2 -0
- package/dist/src/types/public-api/schema.d.ts +15294 -0
- package/{src/types/sync.ts → dist/src/types/sync.d.ts} +5 -6
- package/dist/src/types/sync.js +2 -0
- package/dist/test/modules/accounting.test.d.ts +1 -0
- package/dist/test/modules/accounting.test.js +590 -0
- package/dist/test/modules/consumer.test.d.ts +1 -0
- package/dist/test/modules/consumer.test.js +89 -0
- package/dist/test/modules/consumers.test.d.ts +1 -0
- package/dist/test/modules/consumers.test.js +109 -0
- package/dist/test/modules/ecommerce.test.d.ts +1 -0
- package/dist/test/modules/ecommerce.test.js +224 -0
- package/dist/test/modules/integrations.test.d.ts +1 -0
- package/dist/test/modules/integrations.test.js +54 -0
- package/dist/test/modules/invoicing.test.d.ts +1 -0
- package/dist/test/modules/invoicing.test.js +115 -0
- package/dist/test/modules/payment.test.d.ts +1 -0
- package/dist/test/modules/payment.test.js +88 -0
- package/dist/test/modules/pms.test.d.ts +1 -0
- package/dist/test/modules/pms.test.js +90 -0
- package/dist/test/modules/pos.test.d.ts +1 -0
- package/dist/test/modules/pos.test.js +179 -0
- package/dist/test/modules/sync.test.d.ts +1 -0
- package/dist/test/modules/sync.test.js +93 -0
- package/dist/test/modules/syncs.test.d.ts +1 -0
- package/dist/test/modules/syncs.test.js +53 -0
- package/dist/test/modules/webhooks.test.d.ts +1 -0
- package/dist/test/modules/webhooks.test.js +120 -0
- package/package.json +3 -2
- /package/{src/types/public-api/mappings.ts → dist/src/types/public-api/mappings.d.ts} +0 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Consumers = void 0;
|
|
13
|
+
const consumer_1 = require("./consumer");
|
|
14
|
+
const Consumers = (internalApi) => {
|
|
15
|
+
const _internalApi = internalApi;
|
|
16
|
+
const getConsumers = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const { data, } = yield _internalApi.get('/consumers');
|
|
18
|
+
return data.map((consumer) => (0, consumer_1.Consumer)(_internalApi, consumer));
|
|
19
|
+
});
|
|
20
|
+
const createConsumer = (body) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
const { data, } = yield _internalApi.post('/consumers', body);
|
|
22
|
+
return (0, consumer_1.Consumer)(_internalApi, data);
|
|
23
|
+
});
|
|
24
|
+
const getConsumerById = (consumerId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
const { data, } = yield _internalApi.get(`/consumers/${consumerId}`);
|
|
26
|
+
return (0, consumer_1.Consumer)(_internalApi, Object.assign({}, data));
|
|
27
|
+
});
|
|
28
|
+
const getConsumersByName = (consumerName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
const { data, } = yield _internalApi.get('/consumers');
|
|
30
|
+
return data
|
|
31
|
+
.filter((consumer) => consumer.name.toLowerCase().indexOf(consumerName.toLocaleLowerCase()) !== -1)
|
|
32
|
+
.map((consumer) => (0, consumer_1.Consumer)(_internalApi, consumer));
|
|
33
|
+
});
|
|
34
|
+
const updateConsumerById = (consumerId, body) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
const { data, } = yield _internalApi.patch(`/consumers/${consumerId}`, body);
|
|
36
|
+
return (0, consumer_1.Consumer)(_internalApi, data);
|
|
37
|
+
});
|
|
38
|
+
const deleteConsumerById = (consumerId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
const { data, } = yield _internalApi.delete(`/consumers/${consumerId}`);
|
|
40
|
+
return data;
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
getConsumers,
|
|
44
|
+
createConsumer,
|
|
45
|
+
getConsumerById,
|
|
46
|
+
getConsumersByName,
|
|
47
|
+
updateConsumerById,
|
|
48
|
+
deleteConsumerById,
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
exports.Consumers = Consumers;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RequestData } from '../types/api';
|
|
2
|
+
declare const customFactory: {
|
|
3
|
+
get(name: string, resource: string, params?: any): RequestData<any>;
|
|
4
|
+
post(name: string, resource: string, body: any, params?: any): RequestData<any>;
|
|
5
|
+
patch(name: string, resource: string, body: any, params?: any): RequestData<any>;
|
|
6
|
+
delete(name: string, resource: string, params?: any): RequestData<any>;
|
|
7
|
+
};
|
|
8
|
+
export { customFactory };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.customFactory = void 0;
|
|
4
|
+
const customFactory = {
|
|
5
|
+
get(name, resource, params) {
|
|
6
|
+
return {
|
|
7
|
+
method: 'get',
|
|
8
|
+
url: `/consumers/{consumer_id}/custom/${name}/${resource}`,
|
|
9
|
+
params: params,
|
|
10
|
+
};
|
|
11
|
+
},
|
|
12
|
+
post(name, resource, body, params) {
|
|
13
|
+
return {
|
|
14
|
+
method: 'post',
|
|
15
|
+
url: `/consumers/{consumer_id}/custom/${name}/${resource}`,
|
|
16
|
+
body: body,
|
|
17
|
+
params: params,
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
patch(name, resource, body, params) {
|
|
21
|
+
return {
|
|
22
|
+
method: 'patch',
|
|
23
|
+
url: `/consumers/{consumer_id}/custom/${name}/${resource}`,
|
|
24
|
+
body: body,
|
|
25
|
+
params: params,
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
delete(name, resource, params) {
|
|
29
|
+
return {
|
|
30
|
+
method: 'delete',
|
|
31
|
+
url: `/consumers/{consumer_id}/custom/${name}/${resource}`,
|
|
32
|
+
params: params,
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
exports.customFactory = customFactory;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { InternalAPI } from './internalApi';
|
|
2
|
+
declare const DataStores: (internalApi: InternalAPI) => {
|
|
3
|
+
getDataStores: () => Promise<{
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
status: "active" | "inactive";
|
|
7
|
+
definition: {
|
|
8
|
+
columns: {
|
|
9
|
+
name: string;
|
|
10
|
+
title: string;
|
|
11
|
+
type: string;
|
|
12
|
+
optional: boolean;
|
|
13
|
+
}[];
|
|
14
|
+
search_column?: string | undefined;
|
|
15
|
+
};
|
|
16
|
+
}[]>;
|
|
17
|
+
};
|
|
18
|
+
export { DataStores };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DataStores = void 0;
|
|
13
|
+
const DataStores = (internalApi) => {
|
|
14
|
+
const _internalApi = internalApi;
|
|
15
|
+
const getDataStores = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const { data } = yield _internalApi.get('/datastores');
|
|
17
|
+
return data;
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
getDataStores,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
exports.DataStores = DataStores;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { operations, components } from '../types/public-api/schema';
|
|
2
|
+
import { AutoPaginatedParams, RequestData } from '../types/api';
|
|
3
|
+
type GetOrdersParams = AutoPaginatedParams<operations['ecommerce_get_orders']['parameters']['query']>;
|
|
4
|
+
type GetPaymentMethodsParams = AutoPaginatedParams<operations['ecommerce_get_payments_methods']['parameters']['query']>;
|
|
5
|
+
type GetProductCategoriesParams = AutoPaginatedParams<operations['ecommerce_get_product_categories']['parameters']['query']>;
|
|
6
|
+
type GetTaxesParams = AutoPaginatedParams<operations['ecommerce_get_taxes']['parameters']['query']>;
|
|
7
|
+
type GetCountriesParams = AutoPaginatedParams<operations['ecommerce_get_countries']['parameters']['query']>;
|
|
8
|
+
declare const ecommerceFactory: {
|
|
9
|
+
getCustomers(): RequestData<components['schemas']['CommerceCustomerItem'][]>;
|
|
10
|
+
getProducts(): RequestData<components['schemas']['backbone_api__app__routers__commerce__ProductItem'][]>;
|
|
11
|
+
getCustomer(customerId: string): RequestData<components['schemas']['CommerceCustomerItem']>;
|
|
12
|
+
getProduct(productId: string): RequestData<components['schemas']['backbone_api__app__routers__commerce__ProductItem']>;
|
|
13
|
+
getProductVariantById(variantId: string): RequestData<components['schemas']['VariantItem']>;
|
|
14
|
+
updateAvailableQuantity(variantId: string, inventoryDetails: components['schemas']['InventoryDetailsUpdate']): RequestData<components['schemas']['InventoryDetailsItem']>;
|
|
15
|
+
getLocations(): RequestData<components['schemas']['CommerceLocationItem'][]>;
|
|
16
|
+
getOrders(params?: GetOrdersParams): RequestData<components['schemas']['OrderItemOut'][]>;
|
|
17
|
+
createOrder(order: components['schemas']['OrderItemIn']): RequestData<components['schemas']['OrderItemOut']>;
|
|
18
|
+
getOrder(orderId: string): RequestData<components['schemas']['OrderItemOut']>;
|
|
19
|
+
getPaymentMethods(params?: GetPaymentMethodsParams): RequestData<components['schemas']['PaymentMethodItem'][]>;
|
|
20
|
+
getProductCategories(params?: GetProductCategoriesParams): RequestData<components['schemas']['CategoryItem'][]>;
|
|
21
|
+
getTaxes(params?: GetTaxesParams): RequestData<components['schemas']['TaxRateItem'][]>;
|
|
22
|
+
getCountries(params?: GetCountriesParams): RequestData<components['schemas']['CountryItem'][]>;
|
|
23
|
+
};
|
|
24
|
+
export { ecommerceFactory };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ecommerceFactory = void 0;
|
|
4
|
+
const ecommerceFactory = {
|
|
5
|
+
getCustomers() {
|
|
6
|
+
return {
|
|
7
|
+
method: 'get',
|
|
8
|
+
url: '/consumers/{consumer_id}/commerce/customers',
|
|
9
|
+
};
|
|
10
|
+
},
|
|
11
|
+
getProducts() {
|
|
12
|
+
return {
|
|
13
|
+
method: 'get',
|
|
14
|
+
url: '/consumers/{consumer_id}/commerce/products',
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
getCustomer(customerId) {
|
|
18
|
+
return {
|
|
19
|
+
method: 'get',
|
|
20
|
+
url: `/consumers/{consumer_id}/commerce/customers/${customerId}`,
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
getProduct(productId) {
|
|
24
|
+
return {
|
|
25
|
+
method: 'get',
|
|
26
|
+
url: `/consumers/{consumer_id}/commerce/products/${productId}`,
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
getProductVariantById(variantId) {
|
|
30
|
+
return {
|
|
31
|
+
method: 'get',
|
|
32
|
+
url: `/consumers/{consumer_id}/commerce/variants/${variantId}`,
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
updateAvailableQuantity(variantId, inventoryDetails) {
|
|
36
|
+
return {
|
|
37
|
+
method: 'post',
|
|
38
|
+
url: `/consumers/{consumer_id}/commerce/variants/set_quantity/${variantId}`,
|
|
39
|
+
body: inventoryDetails,
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
getLocations() {
|
|
43
|
+
return {
|
|
44
|
+
method: 'get',
|
|
45
|
+
url: '/consumers/{consumer_id}/commerce/locations',
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
getOrders(params) {
|
|
49
|
+
return {
|
|
50
|
+
method: 'get',
|
|
51
|
+
url: '/consumers/{consumer_id}/commerce/orders',
|
|
52
|
+
params: params,
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
createOrder(order) {
|
|
56
|
+
return {
|
|
57
|
+
method: 'post',
|
|
58
|
+
url: `/consumers/{consumer_id}/commerce/orders`,
|
|
59
|
+
body: order,
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
getOrder(orderId) {
|
|
63
|
+
return {
|
|
64
|
+
method: 'get',
|
|
65
|
+
url: `/consumers/{consumer_id}/commerce/orders/${orderId}`,
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
getPaymentMethods(params) {
|
|
69
|
+
return {
|
|
70
|
+
params,
|
|
71
|
+
method: 'get',
|
|
72
|
+
url: `/consumers/{consumer_id}/commerce/payment-methods`,
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
getProductCategories(params) {
|
|
76
|
+
return {
|
|
77
|
+
params,
|
|
78
|
+
method: 'get',
|
|
79
|
+
url: `/consumers/{consumer_id}/commerce/product-categories`,
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
getTaxes(params) {
|
|
83
|
+
return {
|
|
84
|
+
params,
|
|
85
|
+
method: 'get',
|
|
86
|
+
url: `/consumers/{consumer_id}/commerce/taxes`,
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
getCountries(params) {
|
|
90
|
+
return {
|
|
91
|
+
params,
|
|
92
|
+
method: 'get',
|
|
93
|
+
url: `/consumers/{consumer_id}/commerce/countries`,
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
exports.ecommerceFactory = ecommerceFactory;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { components } from '../types/public-api/schema';
|
|
2
|
+
import { Consumer } from './consumer';
|
|
3
|
+
declare const Flow: (internalApi: any, body: components['schemas']['ReadFlowItem'], syncid: string, consumers: string[], process?: ((consumer: any, context: any) => any) | undefined) => {
|
|
4
|
+
execute: ({ testData, context }: any) => Promise<void>;
|
|
5
|
+
getExecution: (executionId: string) => Promise<{
|
|
6
|
+
id: string;
|
|
7
|
+
start: string;
|
|
8
|
+
end?: string | undefined;
|
|
9
|
+
status: string;
|
|
10
|
+
}>;
|
|
11
|
+
executeLocal: (process: (consumer: typeof Consumer, context: any) => any, log?: boolean) => Promise<void>;
|
|
12
|
+
flowId: string;
|
|
13
|
+
name: string;
|
|
14
|
+
};
|
|
15
|
+
export { Flow };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Flow = void 0;
|
|
13
|
+
const consumers_1 = require("./consumers");
|
|
14
|
+
const Flow = (internalApi, body, syncid, consumers, process) => {
|
|
15
|
+
const _internalApi = internalApi;
|
|
16
|
+
const data = body;
|
|
17
|
+
const _syncid = syncid;
|
|
18
|
+
const _consumers = consumers;
|
|
19
|
+
const _process = process;
|
|
20
|
+
const sendEvent = (payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
const { data: response } = yield _internalApi.post(`/syncs/${_syncid}/flows/${data.id}/event`, payload);
|
|
22
|
+
return response;
|
|
23
|
+
});
|
|
24
|
+
const getExecution = (executionId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
const { data: response } = yield _internalApi.get(`/syncs/${_syncid}/flows/${data.id}/executions/${executionId}`);
|
|
26
|
+
return response;
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Internal use: Function used to execute a flow while testing locally or by calling the sendEvent function
|
|
30
|
+
*/
|
|
31
|
+
const execute = ({ testData = {}, context = {} }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
// first create the process in Chift (it will check if it's already created or not and execute it)
|
|
33
|
+
yield _internalApi.post(`/syncs/${_syncid}/flows`, {
|
|
34
|
+
name: data.name,
|
|
35
|
+
description: data.description,
|
|
36
|
+
execution: data.execution,
|
|
37
|
+
triggers: data.triggers,
|
|
38
|
+
config: data.config,
|
|
39
|
+
});
|
|
40
|
+
// execute locally or remotely by sending an event to execute the flow
|
|
41
|
+
if (context.local) {
|
|
42
|
+
// when you execute locally you need to have a process defined
|
|
43
|
+
const logs = context.logs || false;
|
|
44
|
+
if (_process)
|
|
45
|
+
executeLocal(_process, logs);
|
|
46
|
+
else
|
|
47
|
+
throw Error('Process is not defined it cannot be executed');
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
yield sendEvent(testData);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* Internal use: Function used to execute a flow locally based on the configured consumers.
|
|
55
|
+
*/
|
|
56
|
+
const localExecution = (process) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
var _a;
|
|
58
|
+
_internalApi.debug = true;
|
|
59
|
+
for (let i = 0; i < _consumers.length; i++) {
|
|
60
|
+
// we do not care about the customer
|
|
61
|
+
let consumer;
|
|
62
|
+
try {
|
|
63
|
+
consumer = yield (0, consumers_1.Consumers)(_internalApi).getConsumerById(_consumers[i]);
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
console.log(`Cannot run for consumer ${_consumers[i]} as it cannot be found; probably part of an external account ? Use the platform to debug.`);
|
|
67
|
+
}
|
|
68
|
+
if (consumer) {
|
|
69
|
+
const syncData = yield consumer.getSyncData(_syncid);
|
|
70
|
+
const flow = (_a = syncData.enabled_flows) === null || _a === void 0 ? void 0 : _a.find((flow) => flow.id === data.id);
|
|
71
|
+
if (flow && syncData.status === 'active') {
|
|
72
|
+
const context = Object.assign(Object.assign({}, syncData), { flow_id: flow.id, flow_name: flow.name, flow_values: flow.values, flow_config: flow.config });
|
|
73
|
+
delete context['enabled_flows'];
|
|
74
|
+
yield process(consumer, context);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
console.log(`Cannot run for consumer ${_consumers[i]} as the flow is not activated or not correctly configured`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
_internalApi.debug = false;
|
|
82
|
+
});
|
|
83
|
+
/**
|
|
84
|
+
* Internal use: Function used to execute a flow locally for debugging purposes. It will create the executions server-side on Chift to be able to follow-up the execution through Chift's UI.
|
|
85
|
+
* It will call localExecution to execute the flow for the configured consumers
|
|
86
|
+
*/
|
|
87
|
+
const executeLocal = (process, log = false) => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
|
+
if (log) {
|
|
89
|
+
// create executions on the platform to add the logs to the server
|
|
90
|
+
const { data: response } = yield _internalApi.post(`/syncs/${_syncid}/flows/${data.id}/local`, { type: 'START' });
|
|
91
|
+
if (response.data) {
|
|
92
|
+
const { executionid, chainexecutionid } = response.data;
|
|
93
|
+
_internalApi.setRelatedChainExecutionId(chainexecutionid);
|
|
94
|
+
try {
|
|
95
|
+
yield localExecution(process);
|
|
96
|
+
yield _internalApi.post(`/syncs/${_syncid}/flows/${data.id}/local`, {
|
|
97
|
+
type: 'END',
|
|
98
|
+
executionid: executionid,
|
|
99
|
+
chainexecutionid: chainexecutionid,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
if (err.error) {
|
|
104
|
+
// it's an error from the one api
|
|
105
|
+
const error_message = `Error when executing request with url ${err.url} for consumer ${err.consumerName} (${err.consumerId})`;
|
|
106
|
+
console.log(`[ERROR]: ${error_message}: ${JSON.stringify(err.error)}`);
|
|
107
|
+
yield _internalApi.post(`/syncs/${_syncid}/flows/${data.id}/local`, {
|
|
108
|
+
type: 'END',
|
|
109
|
+
executionid: executionid,
|
|
110
|
+
chainexecutionid: chainexecutionid,
|
|
111
|
+
error: true,
|
|
112
|
+
error_message: error_message,
|
|
113
|
+
technical_error_message: JSON.stringify(err.error),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
console.log('[ERROR]: ' + err.toString());
|
|
118
|
+
yield _internalApi.post(`/syncs/${_syncid}/flows/${data.id}/local`, {
|
|
119
|
+
type: 'END',
|
|
120
|
+
executionid: executionid,
|
|
121
|
+
chainexecutionid: chainexecutionid,
|
|
122
|
+
error: true,
|
|
123
|
+
technical_error_message: err.toString(),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
_internalApi.setRelatedChainExecutionId('');
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
throw Error('Execution could not be executed');
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
try {
|
|
135
|
+
yield localExecution(process);
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
if (err.error) {
|
|
139
|
+
const error_message = `Error when executing request with url ${err.url} for consumer ${err.consumerName} (${err.consumerId})`;
|
|
140
|
+
console.log(`[ERROR] ${error_message}: ${JSON.stringify(err.error)}`);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
console.log('[ERROR]: ' + err.toString());
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return {
|
|
149
|
+
execute,
|
|
150
|
+
getExecution,
|
|
151
|
+
executeLocal,
|
|
152
|
+
flowId: data.id,
|
|
153
|
+
name: data.name,
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
exports.Flow = Flow;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { operations } from '../types/public-api/schema';
|
|
2
|
+
import { InternalAPI } from './internalApi';
|
|
3
|
+
import { chiftOperations } from '../types/public-api/mappings';
|
|
4
|
+
declare const Integrations: (internalApi: InternalAPI) => {
|
|
5
|
+
getIntegrations: (params?: operations[chiftOperations['getIntegrations']]['parameters']['query']) => Promise<{
|
|
6
|
+
integrationid: number;
|
|
7
|
+
name: string;
|
|
8
|
+
status: "active" | "inactive";
|
|
9
|
+
api: "Payment" | "Point of Sale" | "eCommerce" | "Accounting" | "Invoicing" | "Communication" | "Banking" | "Custom" | "Property Management System";
|
|
10
|
+
logo_url: string;
|
|
11
|
+
icon_url: string;
|
|
12
|
+
post_connections: {
|
|
13
|
+
title: string;
|
|
14
|
+
optional: boolean;
|
|
15
|
+
resource: string;
|
|
16
|
+
}[];
|
|
17
|
+
credentials: {
|
|
18
|
+
name: string;
|
|
19
|
+
optional: boolean;
|
|
20
|
+
}[];
|
|
21
|
+
}[]>;
|
|
22
|
+
};
|
|
23
|
+
export { Integrations };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Integrations = void 0;
|
|
13
|
+
const Integrations = (internalApi) => {
|
|
14
|
+
const _internalApi = internalApi;
|
|
15
|
+
const getIntegrations = (params = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const { data, } = yield _internalApi.get('/integrations', { params });
|
|
17
|
+
return data;
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
getIntegrations,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
exports.Integrations = Integrations;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { AuthType, TokenType, RequestData } from '../types/api';
|
|
3
|
+
declare class InternalAPI {
|
|
4
|
+
instance: AxiosInstance;
|
|
5
|
+
auth: AuthType;
|
|
6
|
+
token?: TokenType;
|
|
7
|
+
debug: boolean;
|
|
8
|
+
relatedChainExecutionId?: string;
|
|
9
|
+
connectionId?: string;
|
|
10
|
+
integrationId?: string;
|
|
11
|
+
get: <T = any, R = import("axios").AxiosResponse<T, any>, D = any>(url: string, config?: import("axios").AxiosRequestConfig<D> | undefined) => Promise<R>;
|
|
12
|
+
post: <T = any, R = import("axios").AxiosResponse<T, any>, D = any>(url: string, data?: D | undefined, config?: import("axios").AxiosRequestConfig<D> | undefined) => Promise<R>;
|
|
13
|
+
patch: <T = any, R = import("axios").AxiosResponse<T, any>, D = any>(url: string, data?: D | undefined, config?: import("axios").AxiosRequestConfig<D> | undefined) => Promise<R>;
|
|
14
|
+
delete: <T = any, R = import("axios").AxiosResponse<T, any>, D = any>(url: string, config?: import("axios").AxiosRequestConfig<D> | undefined) => Promise<R>;
|
|
15
|
+
constructor(auth: AuthType);
|
|
16
|
+
getToken: () => Promise<void>;
|
|
17
|
+
getPaginationParams: (currPage: number) => {
|
|
18
|
+
page: number;
|
|
19
|
+
size: number;
|
|
20
|
+
};
|
|
21
|
+
setRelatedChainExecutionId(chainExecutionId: string): void;
|
|
22
|
+
makeRequest<TResponse>(requestData: RequestData<TResponse>): Promise<any>;
|
|
23
|
+
}
|
|
24
|
+
export { InternalAPI };
|