n8n-nodes-agnicwallet 1.0.12 → 1.0.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.
@@ -1,327 +1,362 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.X402HttpRequest = void 0;
4
- const n8n_workflow_1 = require("n8n-workflow");
5
- class X402HttpRequest {
6
- constructor() {
7
- this.description = {
8
- displayName: "AgnicWallet X402 Request",
9
- name: "agnicWalletX402Request",
10
- group: ["transform"],
11
- version: 1,
12
- description: "Make HTTP requests to X402-enabled APIs with automatic payment via AgnicWallet",
13
- defaults: {
14
- name: "AgnicWallet X402",
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // nodes/X402HttpRequest/X402HttpRequest.node.ts
22
+ var X402HttpRequest_node_exports = {};
23
+ __export(X402HttpRequest_node_exports, {
24
+ X402HttpRequest: () => X402HttpRequest
25
+ });
26
+ module.exports = __toCommonJS(X402HttpRequest_node_exports);
27
+ var import_n8n_workflow = require("n8n-workflow");
28
+ var X402HttpRequest = class {
29
+ constructor() {
30
+ this.description = {
31
+ displayName: "AgnicWallet X402 Request",
32
+ name: "agnicWalletX402Request",
33
+ group: ["transform"],
34
+ version: 1,
35
+ description: "Make HTTP requests to X402-enabled APIs with automatic payment via AgnicWallet",
36
+ defaults: {
37
+ name: "AgnicWallet X402"
38
+ },
39
+ icon: "file:X402HttpRequest.png",
40
+ usableAsTool: true,
41
+ inputs: ["main"],
42
+ outputs: ["main"],
43
+ credentials: [
44
+ {
45
+ name: "agnicWalletOAuth2Api",
46
+ required: false,
47
+ displayOptions: {
48
+ show: {
49
+ authentication: ["oAuth2"]
50
+ }
51
+ }
52
+ },
53
+ {
54
+ name: "agnicWalletApi",
55
+ required: false,
56
+ displayOptions: {
57
+ show: {
58
+ authentication: ["apiKey"]
59
+ }
60
+ }
61
+ }
62
+ ],
63
+ properties: [
64
+ {
65
+ displayName: "Authentication",
66
+ name: "authentication",
67
+ type: "options",
68
+ options: [
69
+ {
70
+ name: "OAuth2",
71
+ value: "oAuth2",
72
+ description: "Recommended: Connect your account"
15
73
  },
16
- icon: "file:X402HttpRequest.png",
17
- usableAsTool: true,
18
- inputs: ["main"],
19
- outputs: ["main"],
20
- credentials: [
21
- {
22
- name: "agnicWalletOAuth2Api",
23
- required: false,
24
- displayOptions: {
25
- show: {
26
- authentication: ["oAuth2"],
27
- },
28
- },
29
- },
30
- {
31
- name: "agnicWalletApi",
32
- required: false,
33
- displayOptions: {
34
- show: {
35
- authentication: ["apiKey"],
36
- },
37
- },
38
- },
39
- ],
40
- properties: [
41
- {
42
- displayName: "Authentication",
43
- name: "authentication",
44
- type: "options",
45
- options: [
46
- {
47
- name: "OAuth2",
48
- value: "oAuth2",
49
- description: "Recommended: Connect your account",
50
- },
51
- {
52
- name: "API Key",
53
- value: "apiKey",
54
- description: "For CI/CD or programmatic access",
55
- },
56
- ],
57
- default: "oAuth2",
58
- description: "How to authenticate with AgnicWallet",
59
- },
60
- {
61
- displayName: "Method",
62
- name: "method",
63
- type: "options",
64
- options: [
65
- {
66
- name: "GET",
67
- value: "GET",
68
- },
69
- {
70
- name: "POST",
71
- value: "POST",
72
- },
73
- {
74
- name: "PUT",
75
- value: "PUT",
76
- },
77
- {
78
- name: "DELETE",
79
- value: "DELETE",
80
- },
81
- ],
82
- default: "GET",
83
- description: "The HTTP method to use",
84
- },
85
- {
86
- displayName: "URL",
87
- name: "url",
88
- type: "string",
89
- default: "",
90
- required: true,
91
- placeholder: "https://api.example.com/endpoint",
92
- description: "The URL of the X402-enabled API",
93
- },
74
+ {
75
+ name: "API Key",
76
+ value: "apiKey",
77
+ description: "For CI/CD or programmatic access"
78
+ }
79
+ ],
80
+ default: "oAuth2",
81
+ description: "How to authenticate with AgnicWallet"
82
+ },
83
+ {
84
+ displayName: "Method",
85
+ name: "method",
86
+ type: "options",
87
+ options: [
88
+ {
89
+ name: "GET",
90
+ value: "GET"
91
+ },
92
+ {
93
+ name: "POST",
94
+ value: "POST"
95
+ },
96
+ {
97
+ name: "PUT",
98
+ value: "PUT"
99
+ },
100
+ {
101
+ name: "DELETE",
102
+ value: "DELETE"
103
+ }
104
+ ],
105
+ default: "GET",
106
+ description: "The HTTP method to use"
107
+ },
108
+ {
109
+ displayName: "URL",
110
+ name: "url",
111
+ type: "string",
112
+ default: "",
113
+ required: true,
114
+ placeholder: "https://api.example.com/endpoint",
115
+ description: "The URL of the X402-enabled API"
116
+ },
117
+ {
118
+ displayName: "Headers",
119
+ name: "headers",
120
+ type: "fixedCollection",
121
+ typeOptions: {
122
+ multipleValues: true
123
+ },
124
+ default: {},
125
+ options: [
126
+ {
127
+ name: "header",
128
+ displayName: "Header",
129
+ values: [
94
130
  {
95
- displayName: "Headers",
96
- name: "headers",
97
- type: "fixedCollection",
98
- typeOptions: {
99
- multipleValues: true,
100
- },
101
- default: {},
102
- options: [
103
- {
104
- name: "header",
105
- displayName: "Header",
106
- values: [
107
- {
108
- displayName: "Name",
109
- name: "name",
110
- type: "string",
111
- default: "",
112
- description: "Name of the header",
113
- },
114
- {
115
- displayName: "Value",
116
- name: "value",
117
- type: "string",
118
- default: "",
119
- description: "Value of the header",
120
- },
121
- ],
122
- },
123
- ],
124
- description: "Additional headers to send with the request",
131
+ displayName: "Name",
132
+ name: "name",
133
+ type: "string",
134
+ default: "",
135
+ description: "Name of the header"
125
136
  },
126
137
  {
127
- displayName: "Body",
128
- name: "body",
129
- type: "json",
130
- default: "{}",
131
- displayOptions: {
132
- show: {
133
- method: ["POST", "PUT"],
134
- },
135
- },
136
- description: "JSON body to send with the request",
137
- },
138
- ],
139
- };
140
- }
141
- async execute() {
142
- const items = this.getInputData();
143
- const returnData = [];
144
- for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
145
- try {
146
- // Get authentication type
147
- const authentication = this.getNodeParameter("authentication", itemIndex);
148
- let apiBaseUrl;
149
- let authHeader;
150
- // Use AgnicWallet backend API endpoint (production cloud)
151
- apiBaseUrl = "https://api.agnicpay.xyz";
152
- if (authentication === "oAuth2") {
153
- // OAuth2 authentication
154
- const credentials = (await this.getCredentials("agnicWalletOAuth2Api", itemIndex));
155
- authHeader = `Bearer ${credentials.oauthTokenData.access_token}`;
138
+ displayName: "Value",
139
+ name: "value",
140
+ type: "string",
141
+ default: "",
142
+ description: "Value of the header"
156
143
  }
157
- else {
158
- // API Key authentication
159
- const credentials = await this.getCredentials("agnicWalletApi", itemIndex);
160
- const { apiToken } = credentials;
161
- authHeader = apiToken;
162
- }
163
- // Get parameters
164
- const method = this.getNodeParameter("method", itemIndex);
165
- const url = this.getNodeParameter("url", itemIndex);
166
- const headersConfig = this.getNodeParameter("headers", itemIndex, {});
167
- const body = this.getNodeParameter("body", itemIndex, "{}");
168
- // Build headers
169
- const headers = {
170
- "Content-Type": "application/json",
171
- };
172
- if (headersConfig.header) {
173
- headersConfig.header.forEach((h) => {
174
- headers[h.name] = h.value;
175
- });
176
- }
177
- // Make request with X402 payment handling
178
- const response = await makeX402Request(this, {
179
- url,
180
- method,
181
- headers,
182
- body: method === "POST" || method === "PUT"
183
- ? JSON.parse(body)
184
- : undefined,
185
- agnicWalletApi: apiBaseUrl,
186
- authHeader,
187
- isOAuth: authentication === "oAuth2",
188
- });
189
- returnData.push({
190
- json: response,
191
- pairedItem: {
192
- item: itemIndex,
193
- },
194
- });
144
+ ]
195
145
  }
196
- catch (error) {
197
- const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
198
- if (this.continueOnFail()) {
199
- returnData.push({
200
- json: {
201
- error: errorMessage,
202
- },
203
- pairedItem: {
204
- item: itemIndex,
205
- },
206
- });
207
- continue;
208
- }
209
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage, {
210
- itemIndex,
211
- });
146
+ ],
147
+ description: "Additional headers to send with the request"
148
+ },
149
+ {
150
+ displayName: "Body",
151
+ name: "body",
152
+ type: "json",
153
+ default: "{}",
154
+ displayOptions: {
155
+ show: {
156
+ method: ["POST", "PUT"]
212
157
  }
158
+ },
159
+ description: "JSON body to send with the request"
213
160
  }
214
- return [returnData];
215
- }
216
- }
217
- exports.X402HttpRequest = X402HttpRequest;
218
- // Helper function: Make X402 request with automatic payment
219
- async function makeX402Request(context, config) {
220
- const { url, method, headers, body, agnicWalletApi, authHeader, isOAuth } = config;
221
- try {
222
- // 1. Try the request first (may return 402)
223
- context.logger.info(`Making initial request to: ${url}`);
224
- let response = await fetch(url, {
225
- method,
226
- headers,
227
- body: body ? JSON.stringify(body) : undefined,
161
+ ]
162
+ };
163
+ }
164
+ static {
165
+ __name(this, "X402HttpRequest");
166
+ }
167
+ async execute() {
168
+ const items = this.getInputData();
169
+ const returnData = [];
170
+ for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
171
+ try {
172
+ const authentication = this.getNodeParameter(
173
+ "authentication",
174
+ itemIndex
175
+ );
176
+ let apiBaseUrl;
177
+ let authHeader;
178
+ apiBaseUrl = "https://api.agnicpay.xyz";
179
+ if (authentication === "oAuth2") {
180
+ const credentials = await this.getCredentials(
181
+ "agnicWalletOAuth2Api",
182
+ itemIndex
183
+ );
184
+ authHeader = `Bearer ${credentials.oauthTokenData.access_token}`;
185
+ } else {
186
+ const credentials = await this.getCredentials(
187
+ "agnicWalletApi",
188
+ itemIndex
189
+ );
190
+ const { apiToken } = credentials;
191
+ authHeader = apiToken;
192
+ }
193
+ const method = this.getNodeParameter("method", itemIndex);
194
+ const url = this.getNodeParameter("url", itemIndex);
195
+ const headersConfig = this.getNodeParameter(
196
+ "headers",
197
+ itemIndex,
198
+ {}
199
+ );
200
+ const body = this.getNodeParameter("body", itemIndex, "{}");
201
+ const headers = {
202
+ "Content-Type": "application/json"
203
+ };
204
+ if (headersConfig.header) {
205
+ headersConfig.header.forEach((h) => {
206
+ headers[h.name] = h.value;
207
+ });
208
+ }
209
+ const response = await makeX402Request(this, {
210
+ url,
211
+ method,
212
+ headers,
213
+ body: method === "POST" || method === "PUT" ? JSON.parse(body) : void 0,
214
+ agnicWalletApi: apiBaseUrl,
215
+ authHeader,
216
+ isOAuth: authentication === "oAuth2"
228
217
  });
229
- context.logger.info(`Response status: ${response.status}`);
230
- // 2. If 402 Payment Required, use AgnicWallet to sign
231
- if (response.status === 402) {
232
- context.logger.info("402 Payment Required detected, parsing payment requirements...");
233
- // Get response text first for debugging
234
- const responseText = await response.text();
235
- context.logger.info(`Payment requirements response: ${responseText}`);
236
- let paymentRequirements;
237
- try {
238
- paymentRequirements = JSON.parse(responseText);
239
- }
240
- catch (parseError) {
241
- throw new Error(`Failed to parse payment requirements: ${parseError instanceof Error ? parseError.message : "Unknown error"}. Response: ${responseText}`);
242
- }
243
- context.logger.info(`Payment required: ${JSON.stringify(paymentRequirements)}`);
244
- // 3. Call AgnicWallet signing API
245
- context.logger.info(`Calling AgnicWallet API at: ${agnicWalletApi}/api/sign-payment`);
246
- // Build auth headers based on auth type
247
- const authHeaders = {
248
- "Content-Type": "application/json",
249
- };
250
- if (isOAuth) {
251
- // OAuth: Use Authorization header with Bearer token
252
- authHeaders["Authorization"] = authHeader;
253
- }
254
- else {
255
- // API Key: Use X-Agnic-Token header
256
- authHeaders["X-Agnic-Token"] = authHeader;
257
- }
258
- const signingResponse = await fetch(`${agnicWalletApi}/api/sign-payment`, {
259
- method: "POST",
260
- headers: authHeaders,
261
- body: JSON.stringify({
262
- paymentRequirements,
263
- requestData: { url, method, body },
264
- }),
265
- });
266
- if (!signingResponse.ok) {
267
- const errorText = await signingResponse.text();
268
- context.logger.error(`AgnicWallet signing failed: ${errorText}`);
269
- throw new Error(`Payment signing failed (${signingResponse.status}): ${errorText}`);
270
- }
271
- const signingResult = (await signingResponse.json());
272
- const { paymentHeader, amountPaid } = signingResult;
273
- context.logger.info(`Payment signed successfully: $${amountPaid}`);
274
- context.logger.info(`Payment header (Base64): ${paymentHeader}`);
275
- // 4. Retry original request with payment header
276
- // The paymentHeader is already Base64-encoded and X402-compliant
277
- context.logger.info("Retrying request with X402 payment header...");
278
- response = await fetch(url, {
279
- method,
280
- headers: {
281
- ...headers,
282
- "X-PAYMENT": paymentHeader,
283
- },
284
- body: body ? JSON.stringify(body) : undefined,
285
- });
286
- context.logger.info(`Retry response status: ${response.status}`);
287
- if (!response.ok) {
288
- const errorText = await response.text();
289
- throw new Error(`Request failed after payment (${response.status}): ${errorText}`);
290
- }
291
- const resultText = await response.text();
292
- let result;
293
- try {
294
- result = JSON.parse(resultText);
295
- }
296
- catch (parseError) {
297
- context.logger.warn(`Response is not JSON: ${resultText}`);
298
- result = { data: resultText };
218
+ returnData.push({
219
+ json: response,
220
+ pairedItem: {
221
+ item: itemIndex
222
+ }
223
+ });
224
+ } catch (error) {
225
+ const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
226
+ if (this.continueOnFail()) {
227
+ returnData.push({
228
+ json: {
229
+ error: errorMessage
230
+ },
231
+ pairedItem: {
232
+ item: itemIndex
299
233
  }
300
- return {
301
- ...(typeof result === "object" && result !== null ? result : {}),
302
- _agnicWallet: {
303
- paymentMade: true,
304
- amountPaid,
305
- timestamp: new Date().toISOString(),
306
- },
307
- };
234
+ });
235
+ continue;
308
236
  }
309
- // 5. If no payment required, just return the result
310
- if (!response.ok) {
311
- const errorText = await response.text();
312
- throw new Error(`Request failed (${response.status} ${response.statusText}): ${errorText}`);
313
- }
314
- const resultText = await response.text();
315
- try {
316
- return JSON.parse(resultText);
237
+ throw new import_n8n_workflow.NodeOperationError(this.getNode(), errorMessage, {
238
+ itemIndex
239
+ });
240
+ }
241
+ }
242
+ return [returnData];
243
+ }
244
+ };
245
+ async function makeX402Request(context, config) {
246
+ const { url, method, headers, body, agnicWalletApi, authHeader, isOAuth } = config;
247
+ try {
248
+ context.logger.info(`Making initial request to: ${url}`);
249
+ let response = await fetch(url, {
250
+ method,
251
+ headers,
252
+ body: body ? JSON.stringify(body) : void 0
253
+ });
254
+ context.logger.info(`Response status: ${response.status}`);
255
+ if (response.status === 402) {
256
+ context.logger.info(
257
+ "402 Payment Required detected, parsing payment requirements..."
258
+ );
259
+ const responseText = await response.text();
260
+ context.logger.info(`Payment requirements response: ${responseText}`);
261
+ let paymentRequirements;
262
+ try {
263
+ paymentRequirements = JSON.parse(responseText);
264
+ } catch (parseError) {
265
+ throw new Error(
266
+ `Failed to parse payment requirements: ${parseError instanceof Error ? parseError.message : "Unknown error"}. Response: ${responseText}`
267
+ );
268
+ }
269
+ context.logger.info(
270
+ `Payment required: ${JSON.stringify(paymentRequirements)}`
271
+ );
272
+ context.logger.info(
273
+ `Calling AgnicWallet API at: ${agnicWalletApi}/api/sign-payment`
274
+ );
275
+ const authHeaders = {
276
+ "Content-Type": "application/json"
277
+ };
278
+ if (isOAuth) {
279
+ authHeaders["Authorization"] = authHeader;
280
+ } else {
281
+ authHeaders["X-Agnic-Token"] = authHeader;
282
+ }
283
+ const signingResponse = await fetch(
284
+ `${agnicWalletApi}/api/sign-payment`,
285
+ {
286
+ method: "POST",
287
+ headers: authHeaders,
288
+ body: JSON.stringify({
289
+ paymentRequirements,
290
+ requestData: { url, method, body }
291
+ })
317
292
  }
318
- catch (parseError) {
319
- context.logger.warn(`Response is not JSON: ${resultText}`);
320
- return { data: resultText };
293
+ );
294
+ if (!signingResponse.ok) {
295
+ const errorText = await signingResponse.text();
296
+ context.logger.error(`AgnicWallet signing failed: ${errorText}`);
297
+ throw new Error(
298
+ `Payment signing failed (${signingResponse.status}): ${errorText}`
299
+ );
300
+ }
301
+ const signingResult = await signingResponse.json();
302
+ const { paymentHeader, amountPaid } = signingResult;
303
+ context.logger.info(`Payment signed successfully: $${amountPaid}`);
304
+ context.logger.info(`Payment header (Base64): ${paymentHeader}`);
305
+ context.logger.info("Retrying request with X402 payment header...");
306
+ response = await fetch(url, {
307
+ method,
308
+ headers: {
309
+ ...headers,
310
+ "X-PAYMENT": paymentHeader
311
+ },
312
+ body: body ? JSON.stringify(body) : void 0
313
+ });
314
+ context.logger.info(`Retry response status: ${response.status}`);
315
+ if (!response.ok) {
316
+ const errorText = await response.text();
317
+ throw new Error(
318
+ `Request failed after payment (${response.status}): ${errorText}`
319
+ );
320
+ }
321
+ const resultText2 = await response.text();
322
+ let result;
323
+ try {
324
+ result = JSON.parse(resultText2);
325
+ } catch (parseError) {
326
+ context.logger.warn(`Response is not JSON: ${resultText2}`);
327
+ result = { data: resultText2 };
328
+ }
329
+ return {
330
+ ...typeof result === "object" && result !== null ? result : {},
331
+ _agnicWallet: {
332
+ paymentMade: true,
333
+ amountPaid,
334
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
321
335
  }
336
+ };
337
+ }
338
+ if (!response.ok) {
339
+ const errorText = await response.text();
340
+ throw new Error(
341
+ `Request failed (${response.status} ${response.statusText}): ${errorText}`
342
+ );
322
343
  }
323
- catch (error) {
324
- context.logger.error(`Error in makeX402Request: ${error instanceof Error ? error.message : "Unknown error"}`);
325
- throw error;
344
+ const resultText = await response.text();
345
+ try {
346
+ return JSON.parse(resultText);
347
+ } catch (parseError) {
348
+ context.logger.warn(`Response is not JSON: ${resultText}`);
349
+ return { data: resultText };
326
350
  }
351
+ } catch (error) {
352
+ context.logger.error(
353
+ `Error in makeX402Request: ${error instanceof Error ? error.message : "Unknown error"}`
354
+ );
355
+ throw error;
356
+ }
327
357
  }
358
+ __name(makeX402Request, "makeX402Request");
359
+ // Annotate the CommonJS export names for ESM import in node:
360
+ 0 && (module.exports = {
361
+ X402HttpRequest
362
+ });