n8n-nodes-digit 0.1.12 → 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.
@@ -34,9 +34,7 @@ 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
+ // baseURL intentionally not set here
40
38
  requestDefaults: {
41
39
  headers: {
42
40
  Accept: 'application/json',
@@ -89,55 +87,48 @@ class DIGIT {
89
87
  if (!baseUrl.startsWith('http')) {
90
88
  throw new Error('DIGIT Credentials: Base URL must start with http:// or https://');
91
89
  }
92
- // Normalize trailing slash
90
+ // normalize trailing slash
93
91
  baseUrl = baseUrl.replace(/\/+$/, '');
94
92
  // -------------------------------
93
+ // Detect gateway environment
94
+ // -------------------------------
95
+ const isGatewayEnv = baseUrl.includes('digit.org') ||
96
+ baseUrl.includes('digit-lts') ||
97
+ baseUrl.includes('gateway');
98
+ // -------------------------------
95
99
  // Setup
96
100
  // -------------------------------
97
101
  const resource = this.getNodeParameter('resource', 0);
98
102
  const items = this.getInputData();
99
103
  const returnData = [];
100
104
  // ==================================================
101
- // AUTH — TOKEN DECODE (LOCAL ONLY)
105
+ // AUTH — TOKEN DECODE
102
106
  // ==================================================
103
107
  if (resource === 'auth') {
104
108
  const operation = this.getNodeParameter('authOperation', 0);
105
109
  if (operation === 'auth_decode_token') {
106
110
  for (let i = 0; i < items.length; i++) {
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
- }
111
+ const tokenParam = this.getNodeParameter('accessToken', i);
112
+ const raw = tokenParam.replace(/^Bearer\s+/i, '');
113
+ const base64Url = raw.split('.')[1];
114
+ const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
115
+ const payload = JSON.parse(buffer_1.Buffer.from(base64, 'base64').toString('utf8'));
116
+ let tenant = '';
117
+ if (payload.iss) {
118
+ const parts = payload.iss.split('/');
119
+ tenant = parts[parts.length - 1];
140
120
  }
121
+ returnData.push({
122
+ json: {
123
+ authToken: `Bearer ${raw}`,
124
+ roles: ((_a = payload === null || payload === void 0 ? void 0 : payload.realm_access) === null || _a === void 0 ? void 0 : _a.roles) || [],
125
+ clientId: (payload === null || payload === void 0 ? void 0 : payload.azp) || '',
126
+ tenantId: tenant,
127
+ username: payload.preferred_username || '',
128
+ email: payload.email || '',
129
+ exp: payload.exp,
130
+ },
131
+ });
141
132
  }
142
133
  return [returnData];
143
134
  }
@@ -149,34 +140,22 @@ class DIGIT {
149
140
  const operation = this.getNodeParameter('filestoreOperation', 0);
150
141
  if (operation === 'file_get') {
151
142
  for (let i = 0; i < items.length; i++) {
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
- }
143
+ const fileId = this.getNodeParameter('fileId', i);
144
+ const tenantId = this.getNodeParameter('tenantId', i);
145
+ const accessToken = this.getNodeParameter('accessToken', i);
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,
152
+ Authorization: accessToken.startsWith('Bearer')
153
+ ? accessToken
154
+ : `Bearer ${accessToken}`,
155
+ },
156
+ json: true,
157
+ });
158
+ returnData.push({ json: response });
180
159
  }
181
160
  return [returnData];
182
161
  }
@@ -188,86 +167,59 @@ class DIGIT {
188
167
  const operation = this.getNodeParameter('boundaryOperation', 0);
189
168
  if (operation === 'boundary_search_codes') {
190
169
  for (let i = 0; i < items.length; i++) {
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
- }
170
+ const tenantId = this.getNodeParameter('tenantId', i);
171
+ const codes = this.getNodeParameter('codes', i);
172
+ const accessToken = this.getNodeParameter('accessToken', i);
173
+ const response = await this.helpers.httpRequest({
174
+ method: 'GET',
175
+ url: new URL('/egov-location/location/v11/boundarys/_search', baseUrl).toString(),
176
+ qs: {
177
+ tenantId,
178
+ boundaryCodes: codes,
179
+ },
180
+ headers: {
181
+ 'X-Tenant-Id': tenantId,
182
+ Authorization: accessToken.startsWith('Bearer')
183
+ ? accessToken
184
+ : `Bearer ${accessToken}`,
185
+ },
186
+ json: true,
187
+ });
188
+ returnData.push({ json: response });
224
189
  }
225
190
  return [returnData];
226
191
  }
227
192
  }
228
193
  // ==================================================
229
- // IDGEN — GENERATE
194
+ // IDGEN — GENERATE (AUTO ROUTE)
230
195
  // ==================================================
231
196
  if (resource === 'idgen') {
232
197
  const operation = this.getNodeParameter('idgenOperation', 0);
233
198
  if (operation === 'idgen_generate') {
234
199
  for (let i = 0; i < items.length; i++) {
200
+ const accessToken = this.getNodeParameter('accessToken', i);
201
+ let body;
235
202
  try {
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 });
203
+ body = JSON.parse(this.getNodeParameter('requestBody', i));
262
204
  }
263
- catch (error) {
264
- if (this.continueOnFail()) {
265
- returnData.push({ json: { error: error.message } });
266
- }
267
- else {
268
- throw error;
269
- }
205
+ catch {
206
+ throw new Error('Invalid JSON in Request Body');
270
207
  }
208
+ const idgenPath = isGatewayEnv
209
+ ? '/idgen/v1/generate'
210
+ : '/egov-idgen/id/_generate';
211
+ const response = await this.helpers.httpRequest({
212
+ method: 'POST',
213
+ url: new URL(idgenPath, baseUrl).toString(),
214
+ headers: {
215
+ Authorization: accessToken.startsWith('Bearer')
216
+ ? accessToken
217
+ : `Bearer ${accessToken}`,
218
+ },
219
+ body,
220
+ json: true,
221
+ });
222
+ returnData.push({ json: response });
271
223
  }
272
224
  return [returnData];
273
225
  }
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "n8n-nodes-digit",
3
+ "version": "0.1.12",
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-digit",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "DIGIT Platform nodes for n8n",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",