apinow-sdk 0.17.0 → 0.19.0

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.
package/dist/cli.js CHANGED
@@ -194,6 +194,92 @@ program
194
194
  process.exit(1);
195
195
  }
196
196
  });
197
+ // ─── endpoint-create ───
198
+ program
199
+ .command('endpoint-create')
200
+ .description('Create an endpoint (raw CRUD)')
201
+ .requiredOption('--namespace <ns>', 'Namespace')
202
+ .requiredOption('--name <name>', 'Endpoint name')
203
+ .requiredOption('--url <url>', 'Upstream URL')
204
+ .requiredOption('--description <desc>', 'Description')
205
+ .option('--method <method>', 'HTTP method', 'POST')
206
+ .option('--price <usdc>', 'USDC price per call', '0.01')
207
+ .option('-k, --key <privateKey>', 'Wallet private key')
208
+ .action(async (opts) => {
209
+ try {
210
+ const { address } = getWallet(opts);
211
+ const body = {
212
+ namespace: opts.namespace,
213
+ endpointName: opts.name,
214
+ url: opts.url,
215
+ description: opts.description,
216
+ httpMethod: opts.method.toUpperCase(),
217
+ paymentOptions: [{ usdAmount: opts.price, amount: opts.price }],
218
+ };
219
+ const data = await fetchJson(`${API_BASE}/api/endpoints`, {
220
+ method: 'POST',
221
+ headers: walletHeaders(address),
222
+ body: JSON.stringify(body),
223
+ });
224
+ console.log(JSON.stringify(data, null, 2));
225
+ }
226
+ catch (err) {
227
+ console.error(`Error: ${err.message}`);
228
+ process.exit(1);
229
+ }
230
+ });
231
+ // ─── endpoint-update ───
232
+ program
233
+ .command('endpoint-update <id>')
234
+ .description('Update an endpoint by ID')
235
+ .option('--description <desc>', 'New description')
236
+ .option('--url <url>', 'New URL')
237
+ .option('--price <usdc>', 'New USDC price')
238
+ .option('--status <status>', 'New status')
239
+ .option('-k, --key <privateKey>', 'Wallet private key')
240
+ .action(async (id, opts) => {
241
+ try {
242
+ const { address } = getWallet(opts);
243
+ const body = {};
244
+ if (opts.description)
245
+ body.description = opts.description;
246
+ if (opts.url)
247
+ body.url = opts.url;
248
+ if (opts.status)
249
+ body.status = opts.status;
250
+ if (opts.price)
251
+ body.paymentOptions = [{ usdAmount: opts.price, amount: opts.price }];
252
+ const data = await fetchJson(`${API_BASE}/api/endpoints/${id}`, {
253
+ method: 'PUT',
254
+ headers: walletHeaders(address),
255
+ body: JSON.stringify(body),
256
+ });
257
+ console.log(JSON.stringify(data, null, 2));
258
+ }
259
+ catch (err) {
260
+ console.error(`Error: ${err.message}`);
261
+ process.exit(1);
262
+ }
263
+ });
264
+ // ─── endpoint-delete ───
265
+ program
266
+ .command('endpoint-delete <id>')
267
+ .description('Delete an endpoint by ID')
268
+ .option('-k, --key <privateKey>', 'Wallet private key')
269
+ .action(async (id, opts) => {
270
+ try {
271
+ const { address } = getWallet(opts);
272
+ const data = await fetchJson(`${API_BASE}/api/endpoints/${id}`, {
273
+ method: 'DELETE',
274
+ headers: walletHeaders(address),
275
+ });
276
+ console.log(JSON.stringify(data, null, 2));
277
+ }
278
+ catch (err) {
279
+ console.error(`Error: ${err.message}`);
280
+ process.exit(1);
281
+ }
282
+ });
197
283
  // ─── call ───
198
284
  program
199
285
  .command('call <endpoint>')
@@ -321,6 +407,93 @@ program
321
407
  process.exit(1);
322
408
  }
323
409
  });
410
+ // ─── workflow-create ───
411
+ program
412
+ .command('workflow-create')
413
+ .description('Create a workflow (raw CRUD)')
414
+ .requiredOption('--name <name>', 'Workflow name')
415
+ .option('--description <desc>', 'Description')
416
+ .option('--graph <json>', 'Graph JSON (nodes + outputNode)')
417
+ .option('--prompt <prompt>', 'AI prompt to generate workflow')
418
+ .option('--price <usdc>', 'Total price', '0.10')
419
+ .option('--splits <json>', 'Splits JSON array [{address, basisPoints, label?, tokenAddress?}]')
420
+ .option('-k, --key <privateKey>', 'Wallet private key')
421
+ .action(async (opts) => {
422
+ try {
423
+ const { address } = getWallet(opts);
424
+ const body = { name: opts.name, totalPrice: opts.price };
425
+ if (opts.description)
426
+ body.description = opts.description;
427
+ if (opts.graph)
428
+ body.graph = JSON.parse(opts.graph);
429
+ if (opts.prompt)
430
+ body.prompt = opts.prompt;
431
+ if (opts.splits)
432
+ body.splits = JSON.parse(opts.splits);
433
+ const data = await fetchJson(`${API_BASE}/api/workflows`, {
434
+ method: 'POST',
435
+ headers: walletHeaders(address),
436
+ body: JSON.stringify(body),
437
+ });
438
+ console.log(JSON.stringify(data, null, 2));
439
+ }
440
+ catch (err) {
441
+ console.error(`Error: ${err.message}`);
442
+ process.exit(1);
443
+ }
444
+ });
445
+ // ─── workflow-update ───
446
+ program
447
+ .command('workflow-update <id>')
448
+ .description('Update a workflow by ID')
449
+ .option('--name <name>', 'New name')
450
+ .option('--description <desc>', 'New description')
451
+ .option('--status <status>', 'New status')
452
+ .option('--price <usdc>', 'New total price')
453
+ .option('-k, --key <privateKey>', 'Wallet private key')
454
+ .action(async (id, opts) => {
455
+ try {
456
+ const { address } = getWallet(opts);
457
+ const body = {};
458
+ if (opts.name)
459
+ body.name = opts.name;
460
+ if (opts.description)
461
+ body.description = opts.description;
462
+ if (opts.status)
463
+ body.status = opts.status;
464
+ if (opts.price)
465
+ body.totalPrice = opts.price;
466
+ const data = await fetchJson(`${API_BASE}/api/workflows/${id}`, {
467
+ method: 'PUT',
468
+ headers: walletHeaders(address),
469
+ body: JSON.stringify(body),
470
+ });
471
+ console.log(JSON.stringify(data, null, 2));
472
+ }
473
+ catch (err) {
474
+ console.error(`Error: ${err.message}`);
475
+ process.exit(1);
476
+ }
477
+ });
478
+ // ─── workflow-delete ───
479
+ program
480
+ .command('workflow-delete <id>')
481
+ .description('Delete a workflow by ID')
482
+ .option('-k, --key <privateKey>', 'Wallet private key')
483
+ .action(async (id, opts) => {
484
+ try {
485
+ const { address } = getWallet(opts);
486
+ const data = await fetchJson(`${API_BASE}/api/workflows/${id}`, {
487
+ method: 'DELETE',
488
+ headers: walletHeaders(address),
489
+ });
490
+ console.log(JSON.stringify(data, null, 2));
491
+ }
492
+ catch (err) {
493
+ console.error(`Error: ${err.message}`);
494
+ process.exit(1);
495
+ }
496
+ });
324
497
  // ─── factory-balance ───
325
498
  program
326
499
  .command('factory-balance')
@@ -452,6 +625,10 @@ program
452
625
  .description('Create a markup workflow that wraps an existing endpoint')
453
626
  .option('--markup <percent>', 'Markup percentage', '20')
454
627
  .option('--name <name>', 'Workflow name')
628
+ .option('--token-buy-percent <percent>', 'Percent of markup allocated to token buy')
629
+ .option('--token-buy-recipient <wallet>', 'Wallet to receive token buy USDC')
630
+ .option('--token-buy-ca <address>', 'Token contract address (default: $APINOW)')
631
+ .option('--markup-recipient <wallet>', 'Wallet to receive markup USDC')
455
632
  .option('-k, --key <privateKey>', 'Wallet private key')
456
633
  .action(async (endpointId, opts) => {
457
634
  try {
@@ -459,7 +636,16 @@ program
459
636
  const body = { endpointId, markupPercent: Number(opts.markup) };
460
637
  if (opts.name)
461
638
  body.workflowName = opts.name;
462
- console.error(`Creating markup workflow (${opts.markup}%)…`);
639
+ if (opts.tokenBuyPercent)
640
+ body.tokenBuyPercent = Number(opts.tokenBuyPercent);
641
+ if (opts.tokenBuyRecipient)
642
+ body.tokenBuyRecipient = opts.tokenBuyRecipient;
643
+ if (opts.tokenBuyCa)
644
+ body.tokenBuyCA = opts.tokenBuyCa;
645
+ if (opts.markupRecipient)
646
+ body.markupRecipient = opts.markupRecipient;
647
+ const tbLabel = opts.tokenBuyPercent ? ` + ${opts.tokenBuyPercent}% token buy` : '';
648
+ console.error(`Creating markup workflow (${opts.markup}%${tbLabel})…`);
463
649
  const data = await fetchJson(`${API_BASE}/api/user-factory/markup`, {
464
650
  method: 'POST',
465
651
  headers: walletHeaders(address),
@@ -470,6 +656,8 @@ program
470
656
  console.log(` ID: ${w.workflowId}`);
471
657
  console.log(` Base: $${w.basePrice} USDC`);
472
658
  console.log(` Markup: ${w.markupPercent}%`);
659
+ if (w.tokenBuyPercent)
660
+ console.log(` Token Buy: ${w.tokenBuyPercent}% of markup`);
473
661
  console.log(` Total: $${w.totalPrice} USDC`);
474
662
  console.log(` View: https://apinow.fun${w.viewUrl}\n`);
475
663
  }
package/dist/index.d.ts CHANGED
@@ -27,6 +27,34 @@ export declare function createClient(config: ApinowConfig): {
27
27
  * Get public endpoint info (free, no payment).
28
28
  */
29
29
  info(namespace: string, endpointName: string): Promise<any>;
30
+ createEndpoint(config: {
31
+ namespace: string;
32
+ endpointName: string;
33
+ url: string;
34
+ description: string;
35
+ httpMethod: "GET" | "POST";
36
+ paymentOptions: Array<{
37
+ amount?: string;
38
+ usdAmount?: string;
39
+ tokenAddress?: string;
40
+ tokenSymbol?: string;
41
+ }>;
42
+ chain?: string;
43
+ querySchema?: any;
44
+ responseSchema?: any;
45
+ exampleQuery?: any;
46
+ exampleOutput?: any;
47
+ docsUrl?: string;
48
+ }): Promise<any>;
49
+ getEndpoint(id: string): Promise<any>;
50
+ updateEndpoint(id: string, updates: Record<string, any>): Promise<any>;
51
+ deleteEndpoint(id: string): Promise<any>;
52
+ listEndpoints(opts?: {
53
+ limit?: number;
54
+ sortBy?: string;
55
+ namespace?: string;
56
+ search?: string;
57
+ }): Promise<any>;
30
58
  /**
31
59
  * List workflows. Optionally filter by creator or status.
32
60
  */
@@ -39,6 +67,31 @@ export declare function createClient(config: ApinowConfig): {
39
67
  * Get workflow details by ID.
40
68
  */
41
69
  getWorkflow(workflowId: string): Promise<any>;
70
+ createWorkflow(config: {
71
+ name?: string;
72
+ description?: string;
73
+ graph?: {
74
+ nodes: Array<{
75
+ id: string;
76
+ endpoint: string;
77
+ inputMapping: any;
78
+ dependsOn: string[];
79
+ }>;
80
+ outputNode: string;
81
+ outputMapping?: any;
82
+ };
83
+ prompt?: string;
84
+ totalPrice?: string;
85
+ splits?: Array<{
86
+ address: string;
87
+ basisPoints: number;
88
+ label?: string;
89
+ tokenAddress?: string;
90
+ }>;
91
+ chain?: string;
92
+ }): Promise<any>;
93
+ updateWorkflow(workflowId: string, updates: Record<string, any>): Promise<any>;
94
+ deleteWorkflow(workflowId: string): Promise<any>;
42
95
  /**
43
96
  * Run a workflow. Handles x402 payment automatically.
44
97
  *
@@ -82,11 +135,16 @@ export declare function createClient(config: ApinowConfig): {
82
135
  }): Promise<any>;
83
136
  /**
84
137
  * Create a markup workflow wrapping an existing endpoint.
138
+ * Optionally allocate a portion of the markup to a token buy split.
85
139
  */
86
140
  factoryMarkup(opts: {
87
141
  endpointId: string;
88
142
  markupPercent?: number;
89
143
  workflowName?: string;
144
+ tokenBuyPercent?: number;
145
+ tokenBuyRecipient?: string;
146
+ tokenBuyCA?: string;
147
+ markupRecipient?: string;
90
148
  }): Promise<any>;
91
149
  /**
92
150
  * Test-call an endpoint without payment (free, server-side LLM call).
package/dist/index.js CHANGED
@@ -58,6 +58,63 @@ export function createClient(config) {
58
58
  throw new Error(`Failed to fetch info: ${res.status}`);
59
59
  return res.json();
60
60
  },
61
+ // ─── Endpoint CRUD ───
62
+ async createEndpoint(config) {
63
+ const res = await fetch(`${baseUrl}/api/endpoints`, {
64
+ method: 'POST',
65
+ headers: { 'Content-Type': 'application/json', 'x-wallet-address': account.address },
66
+ body: JSON.stringify(config),
67
+ });
68
+ if (!res.ok) {
69
+ const text = await res.text();
70
+ throw new Error(`Failed to create endpoint: ${res.status} ${text}`);
71
+ }
72
+ return res.json();
73
+ },
74
+ async getEndpoint(id) {
75
+ const res = await fetch(`${baseUrl}/api/endpoints/${id}`);
76
+ if (!res.ok)
77
+ throw new Error(`Failed to get endpoint: ${res.status}`);
78
+ return res.json();
79
+ },
80
+ async updateEndpoint(id, updates) {
81
+ const res = await fetch(`${baseUrl}/api/endpoints/${id}`, {
82
+ method: 'PUT',
83
+ headers: { 'Content-Type': 'application/json', 'x-wallet-address': account.address },
84
+ body: JSON.stringify(updates),
85
+ });
86
+ if (!res.ok) {
87
+ const text = await res.text();
88
+ throw new Error(`Failed to update endpoint: ${res.status} ${text}`);
89
+ }
90
+ return res.json();
91
+ },
92
+ async deleteEndpoint(id) {
93
+ const res = await fetch(`${baseUrl}/api/endpoints/${id}`, {
94
+ method: 'DELETE',
95
+ headers: { 'x-wallet-address': account.address },
96
+ });
97
+ if (!res.ok) {
98
+ const text = await res.text();
99
+ throw new Error(`Failed to delete endpoint: ${res.status} ${text}`);
100
+ }
101
+ return res.json();
102
+ },
103
+ async listEndpoints(opts = {}) {
104
+ const params = new URLSearchParams();
105
+ if (opts.limit)
106
+ params.set('limit', String(opts.limit));
107
+ if (opts.sortBy)
108
+ params.set('sortBy', opts.sortBy);
109
+ if (opts.namespace)
110
+ params.set('namespace', opts.namespace);
111
+ if (opts.search)
112
+ params.set('search', opts.search);
113
+ const res = await fetch(`${baseUrl}/api/endpoints?${params}`);
114
+ if (!res.ok)
115
+ throw new Error(`Failed to list endpoints: ${res.status}`);
116
+ return res.json();
117
+ },
61
118
  // ─── Workflows ───
62
119
  /**
63
120
  * List workflows. Optionally filter by creator or status.
@@ -84,6 +141,41 @@ export function createClient(config) {
84
141
  throw new Error(`Failed to get workflow: ${res.status}`);
85
142
  return res.json();
86
143
  },
144
+ async createWorkflow(config) {
145
+ const res = await fetch(`${baseUrl}/api/workflows`, {
146
+ method: 'POST',
147
+ headers: { 'Content-Type': 'application/json', 'x-wallet-address': account.address },
148
+ body: JSON.stringify(config),
149
+ });
150
+ if (!res.ok) {
151
+ const text = await res.text();
152
+ throw new Error(`Failed to create workflow: ${res.status} ${text}`);
153
+ }
154
+ return res.json();
155
+ },
156
+ async updateWorkflow(workflowId, updates) {
157
+ const res = await fetch(`${baseUrl}/api/workflows/${workflowId}`, {
158
+ method: 'PUT',
159
+ headers: { 'Content-Type': 'application/json', 'x-wallet-address': account.address },
160
+ body: JSON.stringify(updates),
161
+ });
162
+ if (!res.ok) {
163
+ const text = await res.text();
164
+ throw new Error(`Failed to update workflow: ${res.status} ${text}`);
165
+ }
166
+ return res.json();
167
+ },
168
+ async deleteWorkflow(workflowId) {
169
+ const res = await fetch(`${baseUrl}/api/workflows/${workflowId}`, {
170
+ method: 'DELETE',
171
+ headers: { 'x-wallet-address': account.address },
172
+ });
173
+ if (!res.ok) {
174
+ const text = await res.text();
175
+ throw new Error(`Failed to delete workflow: ${res.status} ${text}`);
176
+ }
177
+ return res.json();
178
+ },
87
179
  /**
88
180
  * Run a workflow. Handles x402 payment automatically.
89
181
  *
@@ -149,6 +241,7 @@ export function createClient(config) {
149
241
  },
150
242
  /**
151
243
  * Create a markup workflow wrapping an existing endpoint.
244
+ * Optionally allocate a portion of the markup to a token buy split.
152
245
  */
153
246
  async factoryMarkup(opts) {
154
247
  const res = await fetch(`${baseUrl}/api/user-factory/markup`, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apinow-sdk",
3
- "version": "0.17.0",
3
+ "version": "0.19.0",
4
4
  "description": "Pay-per-call API SDK & CLI for APINow.fun — endpoints + workflows, wraps x402 so you don't have to",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",