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