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