n8n-nodes-digit 0.1.11 → 0.1.12

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.
@@ -34,6 +34,9 @@ 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()
37
40
  requestDefaults: {
38
41
  headers: {
39
42
  Accept: 'application/json',
@@ -75,7 +78,7 @@ class DIGIT {
75
78
  }
76
79
  async execute() {
77
80
  // -------------------------------
78
- // Credentials
81
+ // Load & validate credentials
79
82
  // -------------------------------
80
83
  var _a;
81
84
  const credentials = await this.getCredentials('digitApi');
@@ -86,70 +89,94 @@ class DIGIT {
86
89
  if (!baseUrl.startsWith('http')) {
87
90
  throw new Error('DIGIT Credentials: Base URL must start with http:// or https://');
88
91
  }
92
+ // Normalize trailing slash
89
93
  baseUrl = baseUrl.replace(/\/+$/, '');
94
+ // -------------------------------
95
+ // Setup
96
+ // -------------------------------
90
97
  const resource = this.getNodeParameter('resource', 0);
91
98
  const items = this.getInputData();
92
99
  const returnData = [];
93
100
  // ==================================================
94
- // AUTH — TOKEN DECODE
101
+ // AUTH — TOKEN DECODE (LOCAL ONLY)
95
102
  // ==================================================
96
103
  if (resource === 'auth') {
97
104
  const operation = this.getNodeParameter('authOperation', 0);
98
105
  if (operation === 'auth_decode_token') {
99
106
  for (let i = 0; i < items.length; i++) {
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];
107
+ try {
108
+ const tokenParam = this.getNodeParameter('accessToken', i);
109
+ const raw = tokenParam.replace(/^Bearer\s+/i, '');
110
+ const base64Url = raw.split('.')[1];
111
+ const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
112
+ const payload = JSON.parse(buffer_1.Buffer.from(base64, 'base64').toString('utf8'));
113
+ const roles = ((_a = payload === null || payload === void 0 ? void 0 : payload.realm_access) === null || _a === void 0 ? void 0 : _a.roles) || [];
114
+ const clientId = (payload === null || payload === void 0 ? void 0 : payload.azp) || '';
115
+ let tenant = '';
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
+ }
109
140
  }
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
- });
122
141
  }
123
142
  return [returnData];
124
143
  }
125
144
  }
126
145
  // ==================================================
127
- // FILESTORE — FETCH FILE METADATA
146
+ // FILESTORE — FILE FETCH
128
147
  // ==================================================
129
148
  if (resource === 'filestore') {
130
149
  const operation = this.getNodeParameter('filestoreOperation', 0);
131
150
  if (operation === 'file_get') {
132
151
  for (let i = 0; i < items.length; i++) {
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
- });
152
+ try {
153
+ const fileId = this.getNodeParameter('fileId', i);
154
+ const tenantId = this.getNodeParameter('tenantId', i);
155
+ const accessToken = this.getNodeParameter('accessToken', i);
156
+ const response = await this.helpers.httpRequest({
157
+ method: 'GET',
158
+ url: new URL(`/filestore/v1/files/${fileId}`, baseUrl).toString(),
159
+ qs: { tenantId },
160
+ headers: {
161
+ 'X-Tenant-Id': tenantId,
162
+ Authorization: accessToken.startsWith('Bearer')
163
+ ? accessToken
164
+ : `Bearer ${accessToken}`,
165
+ },
166
+ json: true,
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
+ }
153
180
  }
154
181
  return [returnData];
155
182
  }
@@ -161,31 +188,39 @@ class DIGIT {
161
188
  const operation = this.getNodeParameter('boundaryOperation', 0);
162
189
  if (operation === 'boundary_search_codes') {
163
190
  for (let i = 0; i < items.length; i++) {
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
- });
191
+ try {
192
+ const tenantId = this.getNodeParameter('tenantId', i);
193
+ const codes = this.getNodeParameter('codes', i);
194
+ const accessToken = this.getNodeParameter('accessToken', i);
195
+ const clientId = this.getNodeParameter('clientId', i);
196
+ const response = await this.helpers.httpRequest({
197
+ method: 'GET',
198
+ url: new URL('/egov-location/location/v11/boundarys/_search', baseUrl).toString(),
199
+ qs: {
200
+ tenantId,
201
+ boundaryCodes: codes,
202
+ },
203
+ headers: {
204
+ 'X-Tenant-Id': tenantId,
205
+ 'X-Client-Id': clientId,
206
+ Authorization: accessToken.startsWith('Bearer')
207
+ ? accessToken
208
+ : `Bearer ${accessToken}`,
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
+ }
189
224
  }
190
225
  return [returnData];
191
226
  }
@@ -197,46 +232,47 @@ class DIGIT {
197
232
  const operation = this.getNodeParameter('idgenOperation', 0);
198
233
  if (operation === 'idgen_generate') {
199
234
  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;
204
235
  try {
205
- requestBody = JSON.parse(this.getNodeParameter('requestBody', i));
236
+ const tenantId = this.getNodeParameter('tenantId', i);
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 });
206
262
  }
207
- catch {
208
- throw new Error('Invalid JSON in Request Body');
263
+ catch (error) {
264
+ if (this.continueOnFail()) {
265
+ returnData.push({ json: { error: error.message } });
266
+ }
267
+ else {
268
+ throw error;
269
+ }
209
270
  }
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
- });
235
271
  }
236
272
  return [returnData];
237
273
  }
238
274
  }
239
- throw new Error('DIGIT node: Unsupported resource / operation combination');
275
+ throw new Error('DIGIT node: Unsupported resource/operation combination');
240
276
  }
241
277
  }
242
278
  exports.DIGIT = DIGIT;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-digit",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "DIGIT Platform nodes for n8n",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/dist/package.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "name": "n8n-nodes-digit",
3
- "version": "0.1.10",
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
- }