n8n-nodes-digit 0.1.12 → 0.1.14
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/nodes/DIGIT.node.js +80 -132
- package/dist/package.json +19 -0
- package/package.json +1 -1
package/dist/nodes/DIGIT.node.js
CHANGED
|
@@ -34,9 +34,6 @@ exports.description = {
|
|
|
34
34
|
required: true,
|
|
35
35
|
},
|
|
36
36
|
],
|
|
37
|
-
// NOTE:
|
|
38
|
-
// baseURL intentionally NOT set here
|
|
39
|
-
// URLs are built safely inside execute()
|
|
40
37
|
requestDefaults: {
|
|
41
38
|
headers: {
|
|
42
39
|
Accept: 'application/json',
|
|
@@ -92,52 +89,45 @@ class DIGIT {
|
|
|
92
89
|
// Normalize trailing slash
|
|
93
90
|
baseUrl = baseUrl.replace(/\/+$/, '');
|
|
94
91
|
// -------------------------------
|
|
92
|
+
// Detect gateway environment
|
|
93
|
+
// -------------------------------
|
|
94
|
+
const isGatewayEnv = baseUrl.includes('digit.org') ||
|
|
95
|
+
baseUrl.includes('digit-lts') ||
|
|
96
|
+
baseUrl.includes('gateway');
|
|
97
|
+
// -------------------------------
|
|
95
98
|
// Setup
|
|
96
99
|
// -------------------------------
|
|
97
100
|
const resource = this.getNodeParameter('resource', 0);
|
|
98
101
|
const items = this.getInputData();
|
|
99
102
|
const returnData = [];
|
|
100
103
|
// ==================================================
|
|
101
|
-
// AUTH — TOKEN DECODE
|
|
104
|
+
// AUTH — TOKEN DECODE
|
|
102
105
|
// ==================================================
|
|
103
106
|
if (resource === 'auth') {
|
|
104
107
|
const operation = this.getNodeParameter('authOperation', 0);
|
|
105
108
|
if (operation === 'auth_decode_token') {
|
|
106
109
|
for (let i = 0; i < items.length; i++) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
if (payload.iss) {
|
|
117
|
-
const parts = payload.iss.split('/');
|
|
118
|
-
tenant = parts[parts.length - 1];
|
|
119
|
-
}
|
|
120
|
-
returnData.push({
|
|
121
|
-
json: {
|
|
122
|
-
authToken: `Bearer ${raw}`,
|
|
123
|
-
roles,
|
|
124
|
-
clientId,
|
|
125
|
-
tenantId: tenant,
|
|
126
|
-
subject: payload.sub,
|
|
127
|
-
username: payload.preferred_username || '',
|
|
128
|
-
email: payload.email || '',
|
|
129
|
-
exp: payload.exp,
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
catch (error) {
|
|
134
|
-
if (this.continueOnFail()) {
|
|
135
|
-
returnData.push({ json: { error: error.message } });
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
throw error;
|
|
139
|
-
}
|
|
110
|
+
const tokenParam = this.getNodeParameter('accessToken', i);
|
|
111
|
+
const raw = tokenParam.replace(/^Bearer\s+/i, '').trim();
|
|
112
|
+
const base64Url = raw.split('.')[1];
|
|
113
|
+
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
|
114
|
+
const payload = JSON.parse(buffer_1.Buffer.from(base64, 'base64').toString('utf8'));
|
|
115
|
+
let tenant = '';
|
|
116
|
+
if (payload.iss) {
|
|
117
|
+
const parts = payload.iss.split('/');
|
|
118
|
+
tenant = parts[parts.length - 1];
|
|
140
119
|
}
|
|
120
|
+
returnData.push({
|
|
121
|
+
json: {
|
|
122
|
+
authToken: `Bearer ${raw}`,
|
|
123
|
+
roles: ((_a = payload === null || payload === void 0 ? void 0 : payload.realm_access) === null || _a === void 0 ? void 0 : _a.roles) || [],
|
|
124
|
+
clientId: (payload === null || payload === void 0 ? void 0 : payload.azp) || '',
|
|
125
|
+
tenantId: tenant,
|
|
126
|
+
username: payload.preferred_username || '',
|
|
127
|
+
email: payload.email || '',
|
|
128
|
+
exp: payload.exp,
|
|
129
|
+
},
|
|
130
|
+
});
|
|
141
131
|
}
|
|
142
132
|
return [returnData];
|
|
143
133
|
}
|
|
@@ -149,34 +139,21 @@ class DIGIT {
|
|
|
149
139
|
const operation = this.getNodeParameter('filestoreOperation', 0);
|
|
150
140
|
if (operation === 'file_get') {
|
|
151
141
|
for (let i = 0; i < items.length; i++) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
resolveWithFullResponse: false,
|
|
168
|
-
simple: true,
|
|
169
|
-
});
|
|
170
|
-
returnData.push({ json: response });
|
|
171
|
-
}
|
|
172
|
-
catch (error) {
|
|
173
|
-
if (this.continueOnFail()) {
|
|
174
|
-
returnData.push({ json: { error: error.message } });
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
throw error;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
142
|
+
const fileId = this.getNodeParameter('fileId', i);
|
|
143
|
+
const tenantId = this.getNodeParameter('tenantId', i);
|
|
144
|
+
const accessToken = this.getNodeParameter('accessToken', i);
|
|
145
|
+
const cleanToken = accessToken.replace(/^Bearer\s+/i, '').trim();
|
|
146
|
+
const response = await this.helpers.httpRequest({
|
|
147
|
+
method: 'GET',
|
|
148
|
+
url: new URL(`/filestore/v1/files/${fileId}`, baseUrl).toString(),
|
|
149
|
+
qs: { tenantId },
|
|
150
|
+
headers: {
|
|
151
|
+
'X-Tenant-Id': tenantId.toLowerCase(),
|
|
152
|
+
Authorization: `Bearer ${cleanToken}`,
|
|
153
|
+
},
|
|
154
|
+
json: true,
|
|
155
|
+
});
|
|
156
|
+
returnData.push({ json: response });
|
|
180
157
|
}
|
|
181
158
|
return [returnData];
|
|
182
159
|
}
|
|
@@ -188,86 +165,57 @@ class DIGIT {
|
|
|
188
165
|
const operation = this.getNodeParameter('boundaryOperation', 0);
|
|
189
166
|
if (operation === 'boundary_search_codes') {
|
|
190
167
|
for (let i = 0; i < items.length; i++) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
},
|
|
210
|
-
json: true,
|
|
211
|
-
resolveWithFullResponse: false,
|
|
212
|
-
simple: true,
|
|
213
|
-
});
|
|
214
|
-
returnData.push({ json: response });
|
|
215
|
-
}
|
|
216
|
-
catch (error) {
|
|
217
|
-
if (this.continueOnFail()) {
|
|
218
|
-
returnData.push({ json: { error: error.message } });
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
throw error;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
168
|
+
const tenantId = this.getNodeParameter('tenantId', i);
|
|
169
|
+
const codes = this.getNodeParameter('codes', i);
|
|
170
|
+
const accessToken = this.getNodeParameter('accessToken', i);
|
|
171
|
+
const cleanToken = accessToken.replace(/^Bearer\s+/i, '').trim();
|
|
172
|
+
const response = await this.helpers.httpRequest({
|
|
173
|
+
method: 'GET',
|
|
174
|
+
url: new URL('/egov-location/location/v11/boundarys/_search', baseUrl).toString(),
|
|
175
|
+
qs: {
|
|
176
|
+
tenantId: tenantId.toLowerCase(),
|
|
177
|
+
boundaryCodes: codes,
|
|
178
|
+
},
|
|
179
|
+
headers: {
|
|
180
|
+
'X-Tenant-Id': tenantId.toLowerCase(),
|
|
181
|
+
Authorization: `Bearer ${cleanToken}`,
|
|
182
|
+
},
|
|
183
|
+
json: true,
|
|
184
|
+
});
|
|
185
|
+
returnData.push({ json: response });
|
|
224
186
|
}
|
|
225
187
|
return [returnData];
|
|
226
188
|
}
|
|
227
189
|
}
|
|
228
190
|
// ==================================================
|
|
229
|
-
// IDGEN — GENERATE
|
|
191
|
+
// IDGEN — GENERATE (AUTO ROUTE)
|
|
230
192
|
// ==================================================
|
|
231
193
|
if (resource === 'idgen') {
|
|
232
194
|
const operation = this.getNodeParameter('idgenOperation', 0);
|
|
233
195
|
if (operation === 'idgen_generate') {
|
|
234
196
|
for (let i = 0; i < items.length; i++) {
|
|
197
|
+
const accessToken = this.getNodeParameter('accessToken', i);
|
|
198
|
+
const cleanToken = accessToken.replace(/^Bearer\s+/i, '').trim();
|
|
199
|
+
let body;
|
|
235
200
|
try {
|
|
236
|
-
|
|
237
|
-
const clientId = this.getNodeParameter('clientId', i);
|
|
238
|
-
const accessToken = this.getNodeParameter('accessToken', i);
|
|
239
|
-
let body;
|
|
240
|
-
try {
|
|
241
|
-
body = JSON.parse(this.getNodeParameter('requestBody', i));
|
|
242
|
-
}
|
|
243
|
-
catch {
|
|
244
|
-
throw new Error('Invalid JSON in Request Body');
|
|
245
|
-
}
|
|
246
|
-
const response = await this.helpers.httpRequest({
|
|
247
|
-
method: 'POST',
|
|
248
|
-
url: new URL('/egov-idgen/id/_generate', baseUrl).toString(),
|
|
249
|
-
headers: {
|
|
250
|
-
'X-Tenant-Id': tenantId,
|
|
251
|
-
'X-Client-Id': clientId,
|
|
252
|
-
Authorization: accessToken.startsWith('Bearer')
|
|
253
|
-
? accessToken
|
|
254
|
-
: `Bearer ${accessToken}`,
|
|
255
|
-
},
|
|
256
|
-
body,
|
|
257
|
-
json: true,
|
|
258
|
-
resolveWithFullResponse: false,
|
|
259
|
-
simple: true,
|
|
260
|
-
});
|
|
261
|
-
returnData.push({ json: response });
|
|
201
|
+
body = JSON.parse(this.getNodeParameter('requestBody', i));
|
|
262
202
|
}
|
|
263
|
-
catch
|
|
264
|
-
|
|
265
|
-
returnData.push({ json: { error: error.message } });
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
throw error;
|
|
269
|
-
}
|
|
203
|
+
catch {
|
|
204
|
+
throw new Error('Invalid JSON in Request Body');
|
|
270
205
|
}
|
|
206
|
+
const idgenPath = isGatewayEnv
|
|
207
|
+
? '/idgen/v1/generate'
|
|
208
|
+
: '/egov-idgen/id/_generate';
|
|
209
|
+
const response = await this.helpers.httpRequest({
|
|
210
|
+
method: 'POST',
|
|
211
|
+
url: new URL(idgenPath, baseUrl).toString(),
|
|
212
|
+
headers: {
|
|
213
|
+
Authorization: `Bearer ${cleanToken}`,
|
|
214
|
+
},
|
|
215
|
+
body,
|
|
216
|
+
json: true,
|
|
217
|
+
});
|
|
218
|
+
returnData.push({ json: response });
|
|
271
219
|
}
|
|
272
220
|
return [returnData];
|
|
273
221
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "n8n-nodes-digit",
|
|
3
|
+
"version": "0.1.13",
|
|
4
|
+
"description": "DIGIT Platform nodes for n8n",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"n8n": {
|
|
11
|
+
"nodes": [
|
|
12
|
+
"nodes/DIGIT.node.js"
|
|
13
|
+
],
|
|
14
|
+
"credentials": [
|
|
15
|
+
"credentials/DIGITApi.credentials.js"
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT"
|
|
19
|
+
}
|