n8n-nodes-digit 0.1.9 → 0.1.11
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 +112 -121
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/nodes/DIGIT.node.js
CHANGED
|
@@ -35,7 +35,6 @@ exports.description = {
|
|
|
35
35
|
},
|
|
36
36
|
],
|
|
37
37
|
requestDefaults: {
|
|
38
|
-
baseURL: '={{ $credentials.baseUrl }}',
|
|
39
38
|
headers: {
|
|
40
39
|
Accept: 'application/json',
|
|
41
40
|
'Content-Type': 'application/json',
|
|
@@ -75,7 +74,19 @@ class DIGIT {
|
|
|
75
74
|
this.description = exports.description;
|
|
76
75
|
}
|
|
77
76
|
async execute() {
|
|
77
|
+
// -------------------------------
|
|
78
|
+
// Credentials
|
|
79
|
+
// -------------------------------
|
|
78
80
|
var _a;
|
|
81
|
+
const credentials = await this.getCredentials('digitApi');
|
|
82
|
+
let baseUrl = credentials === null || credentials === void 0 ? void 0 : credentials.baseUrl;
|
|
83
|
+
if (!baseUrl) {
|
|
84
|
+
throw new Error('DIGIT Credentials: Base URL is missing');
|
|
85
|
+
}
|
|
86
|
+
if (!baseUrl.startsWith('http')) {
|
|
87
|
+
throw new Error('DIGIT Credentials: Base URL must start with http:// or https://');
|
|
88
|
+
}
|
|
89
|
+
baseUrl = baseUrl.replace(/\/+$/, '');
|
|
79
90
|
const resource = this.getNodeParameter('resource', 0);
|
|
80
91
|
const items = this.getInputData();
|
|
81
92
|
const returnData = [];
|
|
@@ -86,77 +97,59 @@ class DIGIT {
|
|
|
86
97
|
const operation = this.getNodeParameter('authOperation', 0);
|
|
87
98
|
if (operation === 'auth_decode_token') {
|
|
88
99
|
for (let i = 0; i < items.length; i++) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
if (payload.iss) {
|
|
99
|
-
const parts = payload.iss.split('/');
|
|
100
|
-
tenant = parts[parts.length - 1];
|
|
101
|
-
}
|
|
102
|
-
returnData.push({
|
|
103
|
-
json: {
|
|
104
|
-
authToken: `Bearer ${raw}`,
|
|
105
|
-
roles,
|
|
106
|
-
clientId,
|
|
107
|
-
tenantId: tenant,
|
|
108
|
-
subject: payload.sub,
|
|
109
|
-
username: payload.preferred_username || '',
|
|
110
|
-
email: payload.email || '',
|
|
111
|
-
exp: payload.exp,
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
if (this.continueOnFail()) {
|
|
117
|
-
returnData.push({ json: { error: error.message } });
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
throw error;
|
|
121
|
-
}
|
|
100
|
+
const tokenParam = this.getNodeParameter('accessToken', i);
|
|
101
|
+
const raw = tokenParam.replace(/^Bearer\s+/i, '');
|
|
102
|
+
const base64Url = raw.split('.')[1];
|
|
103
|
+
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
|
104
|
+
const payload = JSON.parse(buffer_1.Buffer.from(base64, 'base64').toString('utf8'));
|
|
105
|
+
let tenant = '';
|
|
106
|
+
if (payload === null || payload === void 0 ? void 0 : payload.iss) {
|
|
107
|
+
const parts = payload.iss.split('/');
|
|
108
|
+
tenant = parts[parts.length - 1];
|
|
122
109
|
}
|
|
110
|
+
returnData.push({
|
|
111
|
+
json: {
|
|
112
|
+
authToken: `Bearer ${raw}`,
|
|
113
|
+
roles: ((_a = payload === null || payload === void 0 ? void 0 : payload.realm_access) === null || _a === void 0 ? void 0 : _a.roles) || [],
|
|
114
|
+
clientId: (payload === null || payload === void 0 ? void 0 : payload.azp) || '',
|
|
115
|
+
tenantId: tenant,
|
|
116
|
+
username: (payload === null || payload === void 0 ? void 0 : payload.preferred_username) || '',
|
|
117
|
+
email: (payload === null || payload === void 0 ? void 0 : payload.email) || '',
|
|
118
|
+
subject: payload === null || payload === void 0 ? void 0 : payload.sub,
|
|
119
|
+
exp: payload === null || payload === void 0 ? void 0 : payload.exp,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
123
122
|
}
|
|
124
123
|
return [returnData];
|
|
125
124
|
}
|
|
126
125
|
}
|
|
127
126
|
// ==================================================
|
|
128
|
-
// FILESTORE — FILE
|
|
127
|
+
// FILESTORE — FETCH FILE METADATA
|
|
129
128
|
// ==================================================
|
|
130
129
|
if (resource === 'filestore') {
|
|
131
130
|
const operation = this.getNodeParameter('filestoreOperation', 0);
|
|
132
131
|
if (operation === 'file_get') {
|
|
133
132
|
for (let i = 0; i < items.length; i++) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
returnData.push({ json: { error: error.message } });
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
throw error;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
133
|
+
const fileId = this.getNodeParameter('fileId', i);
|
|
134
|
+
const tenantId = this.getNodeParameter('tenantId', i);
|
|
135
|
+
const accessToken = this.getNodeParameter('accessToken', i);
|
|
136
|
+
const url = new URL(`/filestore/v1/files/${fileId}`, baseUrl).toString();
|
|
137
|
+
const response = await this.helpers.httpRequest({
|
|
138
|
+
method: 'GET',
|
|
139
|
+
url,
|
|
140
|
+
qs: { tenantId },
|
|
141
|
+
headers: {
|
|
142
|
+
'X-Tenant-Id': tenantId,
|
|
143
|
+
Authorization: `Bearer ${accessToken.replace(/^Bearer\s+/i, '')}`,
|
|
144
|
+
},
|
|
145
|
+
json: true,
|
|
146
|
+
});
|
|
147
|
+
returnData.push({
|
|
148
|
+
json: {
|
|
149
|
+
data: response,
|
|
150
|
+
success: true,
|
|
151
|
+
},
|
|
152
|
+
});
|
|
160
153
|
}
|
|
161
154
|
return [returnData];
|
|
162
155
|
}
|
|
@@ -168,34 +161,31 @@ class DIGIT {
|
|
|
168
161
|
const operation = this.getNodeParameter('boundaryOperation', 0);
|
|
169
162
|
if (operation === 'boundary_search_codes') {
|
|
170
163
|
for (let i = 0; i < items.length; i++) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
throw error;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
164
|
+
const tenantId = this.getNodeParameter('tenantId', i);
|
|
165
|
+
const codes = this.getNodeParameter('codes', i);
|
|
166
|
+
const accessToken = this.getNodeParameter('accessToken', i);
|
|
167
|
+
const clientId = this.getNodeParameter('clientId', i);
|
|
168
|
+
const url = new URL('/egov-location/location/v11/boundarys/_search', baseUrl).toString();
|
|
169
|
+
const response = await this.helpers.httpRequest({
|
|
170
|
+
method: 'GET',
|
|
171
|
+
url,
|
|
172
|
+
qs: {
|
|
173
|
+
tenantId,
|
|
174
|
+
boundaryCodes: codes,
|
|
175
|
+
},
|
|
176
|
+
headers: {
|
|
177
|
+
'X-Tenant-Id': tenantId,
|
|
178
|
+
'X-Client-Id': clientId,
|
|
179
|
+
Authorization: `Bearer ${accessToken.replace(/^Bearer\s+/i, '')}`,
|
|
180
|
+
},
|
|
181
|
+
json: true,
|
|
182
|
+
});
|
|
183
|
+
returnData.push({
|
|
184
|
+
json: {
|
|
185
|
+
data: response,
|
|
186
|
+
success: true,
|
|
187
|
+
},
|
|
188
|
+
});
|
|
199
189
|
}
|
|
200
190
|
return [returnData];
|
|
201
191
|
}
|
|
@@ -207,45 +197,46 @@ class DIGIT {
|
|
|
207
197
|
const operation = this.getNodeParameter('idgenOperation', 0);
|
|
208
198
|
if (operation === 'idgen_generate') {
|
|
209
199
|
for (let i = 0; i < items.length; i++) {
|
|
200
|
+
const tenantId = this.getNodeParameter('tenantId', i);
|
|
201
|
+
const clientId = this.getNodeParameter('clientId', i);
|
|
202
|
+
const accessToken = this.getNodeParameter('accessToken', i);
|
|
203
|
+
let requestBody;
|
|
210
204
|
try {
|
|
211
|
-
|
|
212
|
-
const clientId = this.getNodeParameter('clientId', i);
|
|
213
|
-
const accessToken = this.getNodeParameter('accessToken', i);
|
|
214
|
-
let body;
|
|
215
|
-
try {
|
|
216
|
-
body = JSON.parse(this.getNodeParameter('requestBody', i));
|
|
217
|
-
}
|
|
218
|
-
catch {
|
|
219
|
-
throw new Error('Invalid JSON in Request Body');
|
|
220
|
-
}
|
|
221
|
-
const response = await this.helpers.httpRequest({
|
|
222
|
-
method: 'POST',
|
|
223
|
-
url: `/idgen/v1/generate`,
|
|
224
|
-
headers: {
|
|
225
|
-
'X-Tenant-Id': tenantId,
|
|
226
|
-
'X-Client-Id': clientId,
|
|
227
|
-
Authorization: accessToken.startsWith('Bearer')
|
|
228
|
-
? accessToken
|
|
229
|
-
: `Bearer ${accessToken}`,
|
|
230
|
-
},
|
|
231
|
-
body,
|
|
232
|
-
json: true,
|
|
233
|
-
});
|
|
234
|
-
returnData.push({ json: response });
|
|
205
|
+
requestBody = JSON.parse(this.getNodeParameter('requestBody', i));
|
|
235
206
|
}
|
|
236
|
-
catch
|
|
237
|
-
|
|
238
|
-
returnData.push({ json: { error: error.message } });
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
throw error;
|
|
242
|
-
}
|
|
207
|
+
catch {
|
|
208
|
+
throw new Error('Invalid JSON in Request Body');
|
|
243
209
|
}
|
|
210
|
+
const body = {
|
|
211
|
+
RequestInfo: {
|
|
212
|
+
apiId: 'n8n',
|
|
213
|
+
authToken: accessToken.replace(/^Bearer\s+/i, ''),
|
|
214
|
+
},
|
|
215
|
+
...requestBody,
|
|
216
|
+
};
|
|
217
|
+
const url = new URL('/egov-idgen/id/_generate', baseUrl).toString();
|
|
218
|
+
const response = await this.helpers.httpRequest({
|
|
219
|
+
method: 'POST',
|
|
220
|
+
url,
|
|
221
|
+
headers: {
|
|
222
|
+
'X-Tenant-Id': tenantId,
|
|
223
|
+
'X-Client-Id': clientId,
|
|
224
|
+
Authorization: `Bearer ${accessToken.replace(/^Bearer\s+/i, '')}`,
|
|
225
|
+
},
|
|
226
|
+
body,
|
|
227
|
+
json: true,
|
|
228
|
+
});
|
|
229
|
+
returnData.push({
|
|
230
|
+
json: {
|
|
231
|
+
data: response,
|
|
232
|
+
success: true,
|
|
233
|
+
},
|
|
234
|
+
});
|
|
244
235
|
}
|
|
245
236
|
return [returnData];
|
|
246
237
|
}
|
|
247
238
|
}
|
|
248
|
-
throw new Error('DIGIT node: Unsupported resource/operation combination');
|
|
239
|
+
throw new Error('DIGIT node: Unsupported resource / operation combination');
|
|
249
240
|
}
|
|
250
241
|
}
|
|
251
242
|
exports.DIGIT = DIGIT;
|
package/dist/package.json
CHANGED