n8n-nodes-digit 0.1.13 → 0.1.15

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