@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,77 @@
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']['SyncItem']) => {
8
+ const _internalApi: InternalAPI = internalApi;
9
+ const data = body;
10
+ const name = data.name;
11
+ const consumers = data.consumers;
12
+ const syncid = data.syncid;
13
+
14
+ const getFlows = () => {
15
+ return data.flows.map((flow) => Flow(_internalApi, flow, data.syncid, data.consumers));
16
+ };
17
+
18
+ const getFlowByName = (name: string) => {
19
+ const flow = data.flows.find((flow) => flow.name.toLowerCase() === name.toLowerCase());
20
+ if (flow) {
21
+ return Flow(_internalApi, flow, data.syncid, data.consumers);
22
+ }
23
+ return undefined;
24
+ };
25
+
26
+ const getFlowById = (id: string) => {
27
+ const flow = data.flows.find((flow) => flow.id === id);
28
+ if (flow) {
29
+ return Flow(_internalApi, flow, data.syncid, data.consumers);
30
+ }
31
+ return undefined;
32
+ };
33
+
34
+ /**
35
+ * Internal use: Used to create flow based on code and triggers.
36
+ * @param context
37
+ * @param process
38
+ * @returns flow
39
+ */
40
+ const createFlow = async (
41
+ context: ContextType,
42
+ process?: (consumer: typeof Consumer, context: any) => any
43
+ ) => {
44
+ const executionData = context.execution.data || {};
45
+ if (context.execution.type === 'code') {
46
+ const fullFunc = process?.toString();
47
+ const bodyFunc = fullFunc?.slice(fullFunc.indexOf('{') + 1, fullFunc.lastIndexOf('}'));
48
+ executionData['code'] = bodyFunc;
49
+ }
50
+
51
+ const { data: createFlowData }: { data: components['schemas']['ReadFlowItem'] } =
52
+ await _internalApi.post(`/syncs/${data.syncid}/flows`, {
53
+ name: context.name,
54
+ description: context.description,
55
+ execution: {
56
+ type: context.execution.type,
57
+ data: executionData,
58
+ },
59
+ trigger: context.trigger,
60
+ config: context.config,
61
+ });
62
+ const myflow = Flow(_internalApi, createFlowData, data.syncid, data.consumers, process);
63
+ return myflow;
64
+ };
65
+
66
+ return {
67
+ createFlow,
68
+ getFlows,
69
+ getFlowByName,
70
+ getFlowById,
71
+ name,
72
+ consumers,
73
+ syncid,
74
+ };
75
+ };
76
+
77
+ export { Sync };
@@ -0,0 +1,28 @@
1
+ import { components } from '../types/public-api/schema';
2
+ import { InternalAPI } from './internalApi';
3
+ import { Sync } from './sync';
4
+
5
+ const Syncs = (internalApi: InternalAPI) => {
6
+ const _internalApi: InternalAPI = internalApi;
7
+
8
+ const getSyncs = async () => {
9
+ const { data }: { data: components['schemas']['SyncItem'][] } = await _internalApi.get(
10
+ '/syncs'
11
+ );
12
+ return data.map((sync) => Sync(_internalApi, sync));
13
+ };
14
+
15
+ const getSyncById = async (syncid: string) => {
16
+ const { data }: { data: components['schemas']['SyncItem'] } = await _internalApi.get(
17
+ `/syncs/${syncid}`
18
+ );
19
+ return Sync(_internalApi, data);
20
+ };
21
+
22
+ return {
23
+ getSyncs,
24
+ getSyncById,
25
+ };
26
+ };
27
+
28
+ export { Syncs };
@@ -0,0 +1,86 @@
1
+ import { operations } from '../types/public-api/schema';
2
+ import { InternalAPI } from './internalApi';
3
+ import { chiftOperations } from '../types/public-api/mappings';
4
+
5
+ const Webhooks = (internalApi: InternalAPI) => {
6
+ const _internalApi: InternalAPI = internalApi;
7
+
8
+ const getWebhookTypes = async () => {
9
+ const {
10
+ data,
11
+ }: {
12
+ data: operations[chiftOperations['getWebhookTypes']]['responses'][200]['content']['application/json'];
13
+ } = await _internalApi.get('/webhooks/list');
14
+ return data;
15
+ };
16
+
17
+ const getWebhooks = async () => {
18
+ const {
19
+ data,
20
+ }: {
21
+ data: operations[chiftOperations['getWebhooks']]['responses'][200]['content']['application/json'];
22
+ } = await _internalApi.get('/webhooks');
23
+ return data;
24
+ };
25
+
26
+ const registerWebhook = async (
27
+ body: operations[chiftOperations['registerWebhook']]['requestBody']['content']['application/json']
28
+ ) => {
29
+ const {
30
+ data,
31
+ }: {
32
+ data: operations[chiftOperations['createConsumer']]['responses'][200]['content']['application/json'];
33
+ } = await _internalApi.post('/webhooks', body);
34
+ return data;
35
+ };
36
+
37
+ const getWebhookById = async (webhookId: string) => {
38
+ const {
39
+ data,
40
+ }: {
41
+ data: operations[chiftOperations['getWebhookById']]['responses'][200]['content']['application/json'];
42
+ } = await _internalApi.get(`/webhooks/${webhookId}`);
43
+ return data;
44
+ };
45
+
46
+ const updateWebhookById = async (
47
+ webhookId: string,
48
+ body: operations[chiftOperations['updateWebhookById']]['requestBody']['content']['application/json']
49
+ ) => {
50
+ const {
51
+ data,
52
+ }: {
53
+ data: operations[chiftOperations['updateConsumer']]['responses'][200]['content']['application/json'];
54
+ } = await _internalApi.patch(`/webhooks/${webhookId}`, body);
55
+ return data;
56
+ };
57
+
58
+ const unRegisterWebhook = async (webhookId: string) => {
59
+ const {
60
+ data,
61
+ }: { data: operations[chiftOperations['unRegisterWebhook']]['responses'][204] } =
62
+ await _internalApi.delete(`/webhooks/${webhookId}`);
63
+ return data;
64
+ };
65
+
66
+ const getWebhookLogsByWebhookId = async (webhookId: string) => {
67
+ const {
68
+ data,
69
+ }: {
70
+ data: operations[chiftOperations['getWebhookLogsByWebhookId']]['responses'][200]['content']['application/json'];
71
+ } = await _internalApi.get(`/webhooks/${webhookId}/logs`);
72
+ return data;
73
+ };
74
+
75
+ return {
76
+ getWebhookTypes,
77
+ registerWebhook,
78
+ getWebhookById,
79
+ updateWebhookById,
80
+ unRegisterWebhook,
81
+ getWebhookLogsByWebhookId,
82
+ getWebhooks,
83
+ };
84
+ };
85
+
86
+ export { Webhooks };
@@ -0,0 +1,35 @@
1
+ export interface AuthType {
2
+ clientId: string;
3
+ clientSecret: string;
4
+ accountId: string;
5
+ envId?: string;
6
+ baseUrl?: string;
7
+ }
8
+
9
+ export interface TokenType {
10
+ access_token: string;
11
+ token_type: string;
12
+ expires_in: number;
13
+ expires_on: number;
14
+ }
15
+
16
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
17
+ export type RequestData<TResponse> = {
18
+ method: string;
19
+ property?: string;
20
+ consumerName?: string;
21
+ consumerId?: string;
22
+ url: string;
23
+ params?: unknown;
24
+ body?: unknown;
25
+ };
26
+
27
+ export type RequestFactory = { [key: string]: (...args: any) => RequestData<any> };
28
+
29
+ export type ApiFor<TFactory extends RequestFactory> = {
30
+ [key in keyof TFactory]: TFactory[key] extends (
31
+ ...args: infer TArgs
32
+ ) => RequestData<infer TResponse>
33
+ ? (...args: TArgs) => Promise<TResponse>
34
+ : never;
35
+ };
@@ -0,0 +1,9 @@
1
+ export interface Consumers {
2
+ method: void;
3
+ }
4
+
5
+ export interface ConsumerLog {
6
+ type: string;
7
+ message: string;
8
+ context: any;
9
+ }
@@ -0,0 +1,21 @@
1
+ export type chiftOperations = {
2
+ getConsumers: 'consumers_get_consumers';
3
+ createConsumer: 'consumers_create_consumer';
4
+ getConsumerById: 'consumers_get_consumer';
5
+ updateConsumer: 'consumers_update_consumer';
6
+ deleteConsumerById: 'consumers_delete_consumer';
7
+ getConnectionsByConsumerId: 'connections_get_connections';
8
+ createConnection: 'connections_create_connection';
9
+ deleteConnectionById: 'connections_delete_connection';
10
+ updateConnection: 'connections_update_connection';
11
+ getSyncs: 'syncs_get_syncs';
12
+ getIntegrations: 'integrations_get_integrations';
13
+ getWebhookTypes: 'webhooks_get_webhook_types';
14
+ getWebhooks: 'webhooks_get_webhooks';
15
+ registerWebhook: 'webhooks_create_webhook';
16
+ unRegisterWebhook: 'webhooks_delete_webhook';
17
+ getWebhookById: 'webhooks_get_webhook';
18
+ updateWebhookById: 'webhooks_update_webhook';
19
+ getWebhookLogsByWebhookId: 'webhooks_get_webhook_logs';
20
+ getSync: 'syncs_get_sync';
21
+ };