apinow-sdk 0.18.0 → 0.20.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
@@ -7,7 +7,7 @@ const program = new Command();
7
7
  program
8
8
  .name('apinow')
9
9
  .description('CLI for APINow.fun — search, inspect, and call pay-per-request APIs')
10
- .version('0.17.0');
10
+ .version('0.20.0');
11
11
  // ─── Helpers ───
12
12
  function getPrivateKey(opts) {
13
13
  const raw = opts.key || process.env.APINOW_WALLET_PKEY || process.env.PRIVATE_KEY;
@@ -311,6 +311,72 @@ program
311
311
  process.exit(1);
312
312
  }
313
313
  });
314
+ // ─── discover (external x402) ───
315
+ program
316
+ .command('discover <url>')
317
+ .description('Discover the x402 price of any external endpoint (free)')
318
+ .option('-m, --method <method>', 'HTTP method the target expects', 'POST')
319
+ .action(async (url, opts) => {
320
+ try {
321
+ const params = new URLSearchParams({ url, method: opts.method.toUpperCase() });
322
+ const data = await fetchJson(`${API_BASE}/api/x402-proxy?${params}`);
323
+ console.log(`\n ${data.url}`);
324
+ console.log(` ${'─'.repeat(50)}`);
325
+ console.log(` Method: ${data.method}`);
326
+ console.log(` x402 endpoint: ${data.isX402 ? 'YES' : 'NO'}`);
327
+ console.log(` Upstream price: ${data.upstreamPrice}`);
328
+ console.log(` Proxy fee: ${data.proxyFee}`);
329
+ console.log(` Total price: ${data.totalPrice}`);
330
+ console.log(` Network: ${data.network}`);
331
+ if (data.upstreamAccepts?.length) {
332
+ console.log(` Accepts:`);
333
+ for (const a of data.upstreamAccepts) {
334
+ console.log(` scheme=${a.scheme} payTo=${a.payTo?.substring(0, 16)}…`);
335
+ }
336
+ }
337
+ console.log('');
338
+ }
339
+ catch (err) {
340
+ console.error(`Error: ${err.message}`);
341
+ process.exit(1);
342
+ }
343
+ });
344
+ // ─── call-external (external x402 proxy) ───
345
+ program
346
+ .command('call-external <url>')
347
+ .description('Call any external x402 endpoint through the APINow proxy (paid)')
348
+ .option('-d, --data <json>', 'JSON body to send to the target')
349
+ .option('-m, --method <method>', 'HTTP method', 'POST')
350
+ .option('-H, --header <kv...>', 'Extra headers as key:value pairs')
351
+ .option('-k, --key <privateKey>', 'Wallet private key')
352
+ .action(async (url, opts) => {
353
+ try {
354
+ const privateKey = getPrivateKey(opts);
355
+ const body = opts.data ? JSON.parse(opts.data) : undefined;
356
+ const headers = {};
357
+ if (opts.header) {
358
+ for (const h of opts.header) {
359
+ const idx = h.indexOf(':');
360
+ if (idx > 0)
361
+ headers[h.slice(0, idx).trim()] = h.slice(idx + 1).trim();
362
+ }
363
+ }
364
+ const params = new URLSearchParams({ url, method: opts.method.toUpperCase() });
365
+ const priceData = await fetchJson(`${API_BASE}/api/x402-proxy?${params}`);
366
+ console.error(`Calling ${url} [${opts.method.toUpperCase()}] — total cost: ${priceData.totalPrice} (upstream: ${priceData.upstreamPrice} + fee: ${priceData.proxyFee})`);
367
+ const apinow = createClient({ privateKey });
368
+ const result = await apinow.callExternal(url, {
369
+ method: opts.method.toUpperCase(),
370
+ ...(body ? { body } : {}),
371
+ ...(Object.keys(headers).length ? { headers } : {}),
372
+ });
373
+ console.log(JSON.stringify(result, null, 2));
374
+ }
375
+ catch (err) {
376
+ console.error(`Error: ${err.message}`);
377
+ process.exit(1);
378
+ }
379
+ });
314
380
  // ─── workflows ───
315
381
  program
316
382
  .command('workflows')
@@ -416,6 +482,7 @@ program
416
482
  .option('--graph <json>', 'Graph JSON (nodes + outputNode)')
417
483
  .option('--prompt <prompt>', 'AI prompt to generate workflow')
418
484
  .option('--price <usdc>', 'Total price', '0.10')
485
+ .option('--splits <json>', 'Splits JSON array [{address, basisPoints, label?, tokenAddress?}]')
419
486
  .option('-k, --key <privateKey>', 'Wallet private key')
420
487
  .action(async (opts) => {
421
488
  try {
@@ -427,6 +494,8 @@ program
427
494
  body.graph = JSON.parse(opts.graph);
428
495
  if (opts.prompt)
429
496
  body.prompt = opts.prompt;
497
+ if (opts.splits)
498
+ body.splits = JSON.parse(opts.splits);
430
499
  const data = await fetchJson(`${API_BASE}/api/workflows`, {
431
500
  method: 'POST',
432
501
  headers: walletHeaders(address),
@@ -622,6 +691,10 @@ program
622
691
  .description('Create a markup workflow that wraps an existing endpoint')
623
692
  .option('--markup <percent>', 'Markup percentage', '20')
624
693
  .option('--name <name>', 'Workflow name')
694
+ .option('--token-buy-percent <percent>', 'Percent of markup allocated to token buy')
695
+ .option('--token-buy-recipient <wallet>', 'Wallet to receive token buy USDC')
696
+ .option('--token-buy-ca <address>', 'Token contract address (default: $APINOW)')
697
+ .option('--markup-recipient <wallet>', 'Wallet to receive markup USDC')
625
698
  .option('-k, --key <privateKey>', 'Wallet private key')
626
699
  .action(async (endpointId, opts) => {
627
700
  try {
@@ -629,7 +702,16 @@ program
629
702
  const body = { endpointId, markupPercent: Number(opts.markup) };
630
703
  if (opts.name)
631
704
  body.workflowName = opts.name;
632
- console.error(`Creating markup workflow (${opts.markup}%)…`);
705
+ if (opts.tokenBuyPercent)
706
+ body.tokenBuyPercent = Number(opts.tokenBuyPercent);
707
+ if (opts.tokenBuyRecipient)
708
+ body.tokenBuyRecipient = opts.tokenBuyRecipient;
709
+ if (opts.tokenBuyCa)
710
+ body.tokenBuyCA = opts.tokenBuyCa;
711
+ if (opts.markupRecipient)
712
+ body.markupRecipient = opts.markupRecipient;
713
+ const tbLabel = opts.tokenBuyPercent ? ` + ${opts.tokenBuyPercent}% token buy` : '';
714
+ console.error(`Creating markup workflow (${opts.markup}%${tbLabel})…`);
633
715
  const data = await fetchJson(`${API_BASE}/api/user-factory/markup`, {
634
716
  method: 'POST',
635
717
  headers: walletHeaders(address),
@@ -640,6 +722,8 @@ program
640
722
  console.log(` ID: ${w.workflowId}`);
641
723
  console.log(` Base: $${w.basePrice} USDC`);
642
724
  console.log(` Markup: ${w.markupPercent}%`);
725
+ if (w.tokenBuyPercent)
726
+ console.log(` Token Buy: ${w.tokenBuyPercent}% of markup`);
643
727
  console.log(` Total: $${w.totalPrice} USDC`);
644
728
  console.log(` View: https://apinow.fun${w.viewUrl}\n`);
645
729
  }
package/dist/index.d.ts CHANGED
@@ -3,6 +3,21 @@ export interface CallOptions {
3
3
  body?: Record<string, any>;
4
4
  headers?: Record<string, string>;
5
5
  }
6
+ export interface ExternalCallOptions {
7
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
8
+ body?: Record<string, any>;
9
+ headers?: Record<string, string>;
10
+ }
11
+ export interface PriceDiscovery {
12
+ url: string;
13
+ method: string;
14
+ isX402: boolean;
15
+ upstreamPrice: string;
16
+ proxyFee: string;
17
+ totalPrice: string;
18
+ network: string;
19
+ upstreamAccepts: any[];
20
+ }
6
21
  export interface ApinowConfig {
7
22
  privateKey: `0x${string}`;
8
23
  baseUrl?: string;
@@ -86,6 +101,7 @@ export declare function createClient(config: ApinowConfig): {
86
101
  address: string;
87
102
  basisPoints: number;
88
103
  label?: string;
104
+ tokenAddress?: string;
89
105
  }>;
90
106
  chain?: string;
91
107
  }): Promise<any>;
@@ -134,11 +150,16 @@ export declare function createClient(config: ApinowConfig): {
134
150
  }): Promise<any>;
135
151
  /**
136
152
  * Create a markup workflow wrapping an existing endpoint.
153
+ * Optionally allocate a portion of the markup to a token buy split.
137
154
  */
138
155
  factoryMarkup(opts: {
139
156
  endpointId: string;
140
157
  markupPercent?: number;
141
158
  workflowName?: string;
159
+ tokenBuyPercent?: number;
160
+ tokenBuyRecipient?: string;
161
+ tokenBuyCA?: string;
162
+ markupRecipient?: string;
142
163
  }): Promise<any>;
143
164
  /**
144
165
  * Test-call an endpoint without payment (free, server-side LLM call).
@@ -149,6 +170,27 @@ export declare function createClient(config: ApinowConfig): {
149
170
  input?: any;
150
171
  saveExample?: boolean;
151
172
  }): Promise<any>;
173
+ /**
174
+ * Discover the x402 price for any external URL without executing it.
175
+ * Free — no payment required.
176
+ *
177
+ * @example
178
+ * const price = await apinow.discoverPrice('https://stablesocial.dev/api/tiktok/profile');
179
+ * console.log(price.totalPrice); // "$0.070000"
180
+ */
181
+ discoverPrice(url: string, method?: string): Promise<PriceDiscovery>;
182
+ /**
183
+ * Call any external x402 endpoint through the APINow proxy.
184
+ * Handles payment automatically: you pay APINow (upstream price + proxy fee),
185
+ * and APINow pays the upstream service with its server wallet.
186
+ *
187
+ * @example
188
+ * const data = await apinow.callExternal('https://stablesocial.dev/api/tiktok/profile', {
189
+ * method: 'POST',
190
+ * body: { handle: 'someuser' },
191
+ * });
192
+ */
193
+ callExternal(url: string, opts?: ExternalCallOptions): Promise<any>;
152
194
  /**
153
195
  * The underlying x402-wrapped fetch, for advanced use.
154
196
  */
package/dist/index.js CHANGED
@@ -241,6 +241,7 @@ export function createClient(config) {
241
241
  },
242
242
  /**
243
243
  * Create a markup workflow wrapping an existing endpoint.
244
+ * Optionally allocate a portion of the markup to a token buy split.
244
245
  */
245
246
  async factoryMarkup(opts) {
246
247
  const res = await fetch(`${baseUrl}/api/user-factory/markup`, {
@@ -269,6 +270,48 @@ export function createClient(config) {
269
270
  }
270
271
  return res.json();
271
272
  },
273
+ // ─── External x402 Proxy ───
274
+ /**
275
+ * Discover the x402 price for any external URL without executing it.
276
+ * Free — no payment required.
277
+ *
278
+ * @example
279
+ * const price = await apinow.discoverPrice('https://stablesocial.dev/api/tiktok/profile');
280
+ * console.log(price.totalPrice); // "$0.070000"
281
+ */
282
+ async discoverPrice(url, method) {
283
+ const params = new URLSearchParams({ url });
284
+ if (method)
285
+ params.set('method', method);
286
+ const res = await fetch(`${baseUrl}/api/x402-proxy?${params}`);
287
+ if (!res.ok) {
288
+ const text = await res.text();
289
+ throw new Error(`Discovery failed: ${res.status} ${text}`);
290
+ }
291
+ return res.json();
292
+ },
293
+ /**
294
+ * Call any external x402 endpoint through the APINow proxy.
295
+ * Handles payment automatically: you pay APINow (upstream price + proxy fee),
296
+ * and APINow pays the upstream service with its server wallet.
297
+ *
298
+ * @example
299
+ * const data = await apinow.callExternal('https://stablesocial.dev/api/tiktok/profile', {
300
+ * method: 'POST',
301
+ * body: { handle: 'someuser' },
302
+ * });
303
+ */
304
+ async callExternal(url, opts = {}) {
305
+ return this.call('/api/x402-proxy', {
306
+ method: 'POST',
307
+ body: {
308
+ url,
309
+ method: opts.method || 'POST',
310
+ body: opts.body,
311
+ headers: opts.headers,
312
+ },
313
+ });
314
+ },
272
315
  /**
273
316
  * The underlying x402-wrapped fetch, for advanced use.
274
317
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apinow-sdk",
3
- "version": "0.18.0",
3
+ "version": "0.20.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",