@skriptfabrik/n8n-nodes-fulfillmenttools 0.1.0 → 0.1.2

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 (42) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.json +30 -0
  3. package/CHANGELOG.md +25 -0
  4. package/jest.config.ts +11 -0
  5. package/package.json +3 -3
  6. package/project.json +37 -0
  7. package/src/api.d.ts +37084 -0
  8. package/src/credentials/FulfillmenttoolsApi.credentials.spec.ts +101 -0
  9. package/src/credentials/FulfillmenttoolsApi.credentials.ts +166 -0
  10. package/src/nodes/Fulfillmenttools/Fulfillmenttools.node.spec.ts +1149 -0
  11. package/src/nodes/Fulfillmenttools/Fulfillmenttools.node.ts +390 -0
  12. package/src/nodes/Fulfillmenttools/FulfillmenttoolsTrigger.node.spec.ts +386 -0
  13. package/src/nodes/Fulfillmenttools/FulfillmenttoolsTrigger.node.ts +396 -0
  14. package/src/nodes/Fulfillmenttools/GenericFunctions.spec.ts +279 -0
  15. package/src/nodes/Fulfillmenttools/GenericFunctions.ts +156 -0
  16. package/src/nodes/Fulfillmenttools/descriptions/FacilityCarrierDescription.ts +335 -0
  17. package/src/nodes/Fulfillmenttools/descriptions/FacilityDescription.ts +621 -0
  18. package/src/nodes/Fulfillmenttools/descriptions/OrderDescription.ts +338 -0
  19. package/tsconfig.json +22 -0
  20. package/tsconfig.lib.json +10 -0
  21. package/tsconfig.spec.json +13 -0
  22. package/src/credentials/FulfillmenttoolsApi.credentials.d.ts +0 -13
  23. package/src/credentials/FulfillmenttoolsApi.credentials.js +0 -126
  24. package/src/credentials/FulfillmenttoolsApi.credentials.js.map +0 -1
  25. package/src/nodes/Fulfillmenttools/Fulfillmenttools.node.d.ts +0 -5
  26. package/src/nodes/Fulfillmenttools/Fulfillmenttools.node.js +0 -174
  27. package/src/nodes/Fulfillmenttools/Fulfillmenttools.node.js.map +0 -1
  28. package/src/nodes/Fulfillmenttools/FulfillmenttoolsTrigger.node.d.ts +0 -12
  29. package/src/nodes/Fulfillmenttools/FulfillmenttoolsTrigger.node.js +0 -330
  30. package/src/nodes/Fulfillmenttools/FulfillmenttoolsTrigger.node.js.map +0 -1
  31. package/src/nodes/Fulfillmenttools/GenericFunctions.d.ts +0 -3
  32. package/src/nodes/Fulfillmenttools/GenericFunctions.js +0 -91
  33. package/src/nodes/Fulfillmenttools/GenericFunctions.js.map +0 -1
  34. package/src/nodes/Fulfillmenttools/descriptions/FacilityCarrierDescription.d.ts +0 -3
  35. package/src/nodes/Fulfillmenttools/descriptions/FacilityCarrierDescription.js +0 -322
  36. package/src/nodes/Fulfillmenttools/descriptions/FacilityCarrierDescription.js.map +0 -1
  37. package/src/nodes/Fulfillmenttools/descriptions/FacilityDescription.d.ts +0 -3
  38. package/src/nodes/Fulfillmenttools/descriptions/FacilityDescription.js +0 -610
  39. package/src/nodes/Fulfillmenttools/descriptions/FacilityDescription.js.map +0 -1
  40. package/src/nodes/Fulfillmenttools/descriptions/OrderDescription.d.ts +0 -3
  41. package/src/nodes/Fulfillmenttools/descriptions/OrderDescription.js +0 -328
  42. package/src/nodes/Fulfillmenttools/descriptions/OrderDescription.js.map +0 -1
@@ -0,0 +1,101 @@
1
+ import {
2
+ type IHttpRequestHelper,
3
+ type ICredentialDataDecryptedObject,
4
+ } from 'n8n-workflow';
5
+ import { mockClear, mockDeep } from 'jest-mock-extended';
6
+ import { FulfillmenttoolsApi } from './FulfillmenttoolsApi.credentials';
7
+
8
+ describe('FulfillmenttoolsApi', () => {
9
+ const httpRequestHelper = mockDeep<IHttpRequestHelper>({});
10
+
11
+ let credentials: ICredentialDataDecryptedObject;
12
+
13
+ let fulfillmenttoolsApi: FulfillmenttoolsApi;
14
+
15
+ beforeEach(() => {
16
+ credentials = {
17
+ username: '_email_',
18
+ password: '_password_',
19
+ apiKey: '_api_key_',
20
+ subDomain: '_sub_domain_',
21
+ };
22
+
23
+ fulfillmenttoolsApi = new FulfillmenttoolsApi();
24
+ });
25
+
26
+ afterEach(() => {
27
+ mockClear(httpRequestHelper);
28
+ });
29
+
30
+ it('should be defined', () => {
31
+ expect(fulfillmenttoolsApi).toBeDefined();
32
+ });
33
+
34
+ it('should retrieve idToken', async () => {
35
+ const requestUrl =
36
+ 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword';
37
+
38
+ httpRequestHelper.helpers.httpRequest.mockResolvedValueOnce({
39
+ idToken: '_id_token_',
40
+ refreshToken: '_refresh_token_',
41
+ expiresIn: 3600,
42
+ });
43
+
44
+ const result = await fulfillmenttoolsApi.preAuthentication.call(
45
+ httpRequestHelper,
46
+ credentials,
47
+ );
48
+
49
+ expect(httpRequestHelper.helpers.httpRequest).toHaveBeenCalledWith({
50
+ method: 'POST',
51
+ url: requestUrl,
52
+ body: {
53
+ email: `${credentials['username']}@${credentials['subDomain']}.com`,
54
+ password: credentials['password'],
55
+ returnSecureToken: true,
56
+ },
57
+ qs: {
58
+ key: credentials['apiKey'],
59
+ },
60
+ });
61
+
62
+ expect(result).toEqual({
63
+ idToken: '_id_token_',
64
+ refreshToken: '_refresh_token_',
65
+ });
66
+ });
67
+
68
+ it('should refresh idToken', async () => {
69
+ credentials['refreshToken'] = '_refresh_token_';
70
+
71
+ const requestUrl = 'https://securetoken.googleapis.com/v1/token';
72
+
73
+ httpRequestHelper.helpers.httpRequest.mockResolvedValueOnce({
74
+ id_token: '_id_token_',
75
+ refresh_token: '_refresh_token_',
76
+ expires_in: 3600,
77
+ });
78
+
79
+ const result = await fulfillmenttoolsApi.preAuthentication.call(
80
+ httpRequestHelper,
81
+ credentials,
82
+ );
83
+
84
+ expect(httpRequestHelper.helpers.httpRequest).toHaveBeenCalledWith({
85
+ method: 'POST',
86
+ url: requestUrl,
87
+ body: {
88
+ grant_type: 'refresh_token',
89
+ refresh_token: '_refresh_token_',
90
+ },
91
+ qs: {
92
+ key: credentials['apiKey'],
93
+ },
94
+ });
95
+
96
+ expect(result).toEqual({
97
+ idToken: '_id_token_',
98
+ refreshToken: '_refresh_token_',
99
+ });
100
+ });
101
+ });
@@ -0,0 +1,166 @@
1
+ import { randomBytes } from 'crypto';
2
+ import {
3
+ type IAuthenticateGeneric,
4
+ type ICredentialDataDecryptedObject,
5
+ type ICredentialTestRequest,
6
+ type ICredentialType,
7
+ type IHttpRequestHelper,
8
+ type INodeProperties,
9
+ } from 'n8n-workflow';
10
+
11
+ type IdTokenResponse = {
12
+ kind: string; // deprecated
13
+ localeId: string;
14
+ email: string;
15
+ displayName: string;
16
+ idToken: string;
17
+ registered: boolean; // deprecated
18
+ profilePicture: string;
19
+ oauthAccessToken: string; // deprecated
20
+ oauthExpireIn: number; // deprecated
21
+ oauthAuthorizationCode: string; // deprecated
22
+ refreshToken: string;
23
+ expiresIn: number;
24
+ mfaPendingCredential: string;
25
+ mfaInfo: object[];
26
+ userNotifications: object[];
27
+ };
28
+
29
+ type RefreshTokenResponse = {
30
+ expires_in: string;
31
+ token_type: string;
32
+ refresh_token: string;
33
+ id_token: string;
34
+ user_id: string;
35
+ project_id: string;
36
+ };
37
+
38
+ export class FulfillmenttoolsApi implements ICredentialType {
39
+ name = 'fulfillmenttoolsApi';
40
+
41
+ displayName = 'fulfillmenttools API';
42
+
43
+ documentationUrl =
44
+ 'https://docs.fulfillmenttools.com/api-docs/getting-started/make-your-first-api-call';
45
+
46
+ properties: INodeProperties[] = [
47
+ {
48
+ displayName: 'Username',
49
+ name: 'username',
50
+ type: 'string',
51
+ required: true,
52
+ default: undefined,
53
+ },
54
+ {
55
+ displayName: 'Password',
56
+ name: 'password',
57
+ type: 'string',
58
+ typeOptions: {
59
+ password: true,
60
+ },
61
+ required: true,
62
+ default: undefined,
63
+ },
64
+ {
65
+ displayName: 'API Key',
66
+ name: 'apiKey',
67
+ type: 'string',
68
+ typeOptions: {
69
+ password: true,
70
+ },
71
+ required: true,
72
+ default: undefined,
73
+ },
74
+ {
75
+ displayName: 'Sub Domain',
76
+ name: 'subDomain',
77
+ type: 'string',
78
+ required: true,
79
+ default: undefined,
80
+ },
81
+ {
82
+ displayName: 'Webhook Token',
83
+ name: 'webhookToken',
84
+ type: 'string',
85
+ typeOptions: {
86
+ password: true,
87
+ },
88
+ required: true,
89
+ default: randomBytes(16).toString('hex'),
90
+ },
91
+ {
92
+ displayName: 'ID Token',
93
+ name: 'idToken',
94
+ type: 'hidden',
95
+ typeOptions: {
96
+ expirable: true,
97
+ },
98
+ default: undefined,
99
+ },
100
+ {
101
+ displayName: 'Refresh Token',
102
+ name: 'refreshToken',
103
+ type: 'hidden',
104
+ default: undefined,
105
+ },
106
+ ];
107
+
108
+ async preAuthentication(
109
+ this: IHttpRequestHelper,
110
+ credentials: ICredentialDataDecryptedObject,
111
+ ) {
112
+ if (!credentials['refreshToken']) {
113
+ const responseData = (await this.helpers.httpRequest({
114
+ method: 'POST',
115
+ url: 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword',
116
+ body: {
117
+ email: `${credentials['username']}@${credentials['subDomain']}.com`,
118
+ password: credentials['password'],
119
+ returnSecureToken: true,
120
+ },
121
+ qs: {
122
+ key: credentials['apiKey'],
123
+ },
124
+ })) as IdTokenResponse;
125
+
126
+ return {
127
+ idToken: responseData.idToken,
128
+ refreshToken: responseData.refreshToken,
129
+ };
130
+ }
131
+
132
+ const responseData = (await this.helpers.httpRequest({
133
+ method: 'POST',
134
+ url: 'https://securetoken.googleapis.com/v1/token',
135
+ body: {
136
+ grant_type: 'refresh_token',
137
+ refresh_token: credentials['refreshToken'],
138
+ },
139
+ qs: {
140
+ key: credentials['apiKey'],
141
+ },
142
+ })) as RefreshTokenResponse;
143
+
144
+ return {
145
+ idToken: responseData.id_token,
146
+ refreshToken: responseData.refresh_token,
147
+ };
148
+ }
149
+
150
+ authenticate: IAuthenticateGeneric = {
151
+ type: 'generic',
152
+ properties: {
153
+ headers: {
154
+ Authorization: '=Bearer {{$credentials.idToken}}',
155
+ },
156
+ },
157
+ };
158
+
159
+ test: ICredentialTestRequest = {
160
+ request: {
161
+ baseURL:
162
+ '=https://{{$credentials.subDomain}}.api.fulfillmenttools.com/api',
163
+ url: '/health',
164
+ },
165
+ };
166
+ }