agentmall 0.1.17 → 0.1.19

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
@@ -73,6 +73,7 @@ var AgentMall = class {
73
73
  purchases;
74
74
  payments;
75
75
  refunds;
76
+ managedAccounts;
76
77
  constructor(config = {}) {
77
78
  this.baseUrl = (config.baseUrl ?? BASE_URL).replace(/\/$/, "");
78
79
  this.apiSecret = config.apiSecret;
@@ -81,6 +82,7 @@ var AgentMall = class {
81
82
  this.purchases = new AgentMallPurchases(this);
82
83
  this.payments = new AgentMallPayments(this);
83
84
  this.refunds = new AgentMallRefunds(this);
85
+ this.managedAccounts = new AgentMallManagedAccounts(this);
84
86
  }
85
87
  /** @internal */
86
88
  hasApiSecret() {
@@ -132,6 +134,9 @@ var AgentMall = class {
132
134
  }
133
135
  throw new AgentMallError(response.status, body);
134
136
  }
137
+ if (response.status === 204) {
138
+ return void 0;
139
+ }
135
140
  return await response.json();
136
141
  }
137
142
  };
@@ -263,6 +268,58 @@ var AgentMallRefunds = class {
263
268
  return result.refunds;
264
269
  }
265
270
  };
271
+ var AgentMallManagedAccounts = class {
272
+ constructor(client) {
273
+ this.client = client;
274
+ }
275
+ async walletHeaders(account) {
276
+ const challenge = await this.client.request(
277
+ "POST",
278
+ "/api/managed-accounts/challenge",
279
+ {
280
+ body: {
281
+ address: account.address
282
+ }
283
+ }
284
+ );
285
+ const signature = await account.signMessage({
286
+ message: challenge.message
287
+ });
288
+ return {
289
+ "X-AgentMall-Wallet-Address": account.address,
290
+ "X-AgentMall-Auth-Challenge": challenge.challenge,
291
+ "X-AgentMall-Auth-Signature": signature
292
+ };
293
+ }
294
+ /** List managed retailer accounts. Requires either apiSecret or a wallet signer. */
295
+ async list(options) {
296
+ const result = await this.client.request("GET", "/api/managed-accounts", {
297
+ ...options?.account ? { headers: await this.walletHeaders(options.account) } : { auth: true }
298
+ });
299
+ return result.credentials;
300
+ }
301
+ /** Create a managed retailer account. Requires either apiSecret or a wallet signer. */
302
+ async create(body, options) {
303
+ return this.client.request("POST", "/api/managed-accounts", {
304
+ ...options?.account ? { headers: await this.walletHeaders(options.account) } : { auth: true },
305
+ body
306
+ });
307
+ }
308
+ /** Update a managed retailer account. Requires either apiSecret or a wallet signer. */
309
+ async update(body, options) {
310
+ return this.client.request("PUT", "/api/managed-accounts", {
311
+ ...options?.account ? { headers: await this.walletHeaders(options.account) } : { auth: true },
312
+ body
313
+ });
314
+ }
315
+ /** Delete a managed retailer account. Requires either apiSecret or a wallet signer. */
316
+ async delete(shortId, options) {
317
+ await this.client.request("DELETE", "/api/managed-accounts", {
318
+ ...options?.account ? { headers: await this.walletHeaders(options.account) } : { auth: true },
319
+ params: { short_id: shortId }
320
+ });
321
+ }
322
+ };
266
323
 
267
324
  // src/cli/ui.ts
268
325
  var c = {
@@ -405,6 +462,122 @@ var FAILURE_MESSAGES = {
405
462
  function formatCents(cents) {
406
463
  return `$${(cents / 100).toFixed(2)}`;
407
464
  }
465
+ function compactTrackingValue(value) {
466
+ if (typeof value === "string") {
467
+ const trimmed = value.trim();
468
+ return trimmed || null;
469
+ }
470
+ if (typeof value === "number" || typeof value === "boolean") {
471
+ return String(value);
472
+ }
473
+ return null;
474
+ }
475
+ function normalizeTrackingCarrier(carrier, trackingNumber) {
476
+ const carrierValue = carrier?.trim().toLowerCase() ?? null;
477
+ const trackingValue = trackingNumber?.trim().toUpperCase() ?? null;
478
+ if ((carrierValue === "znlogic" || carrierValue === "amazon logistics") && trackingValue?.startsWith("TBA")) {
479
+ return "amazon";
480
+ }
481
+ return carrierValue;
482
+ }
483
+ function isAmazonStyleTracking(carrier, trackingNumber) {
484
+ return normalizeTrackingCarrier(carrier, trackingNumber) === "amazon";
485
+ }
486
+ function displayTrackingCarrier(carrier, trackingNumber) {
487
+ if (!carrier && !trackingNumber) return null;
488
+ if (isAmazonStyleTracking(carrier, trackingNumber)) {
489
+ return "Amazon Logistics";
490
+ }
491
+ return carrier;
492
+ }
493
+ function trackingUrlForCarrier(carrier, trackingNumber) {
494
+ if (!trackingNumber) return null;
495
+ switch (normalizeTrackingCarrier(carrier, trackingNumber)) {
496
+ case "ups":
497
+ return `https://www.ups.com/track?tracknum=${encodeURIComponent(trackingNumber)}`;
498
+ case "fedex":
499
+ return `https://www.fedex.com/fedextrack/?trknbr=${encodeURIComponent(trackingNumber)}`;
500
+ case "usps":
501
+ return `https://tools.usps.com/go/TrackConfirmAction?tLabels=${encodeURIComponent(trackingNumber)}`;
502
+ case "dhl":
503
+ return `https://www.dhl.com/us-en/home/tracking.html?tracking-id=${encodeURIComponent(trackingNumber)}`;
504
+ default:
505
+ return null;
506
+ }
507
+ }
508
+ function isBuyerUsableTrackingUrl(url) {
509
+ if (!url) return false;
510
+ try {
511
+ const parsed = new URL(url);
512
+ const hostname = parsed.hostname.toLowerCase();
513
+ const path = parsed.pathname.toLowerCase();
514
+ if ((hostname === "amazon.com" || hostname === "www.amazon.com") && path.includes("/progress-tracker/")) {
515
+ return false;
516
+ }
517
+ } catch {
518
+ if (/amazon\.com\/progress-tracker\//i.test(url)) {
519
+ return false;
520
+ }
521
+ }
522
+ return true;
523
+ }
524
+ function hasAmazonTracking(tracking) {
525
+ const direct = compactTrackingValue(tracking);
526
+ if (direct) return direct.trim().toUpperCase().startsWith("TBA");
527
+ if (Array.isArray(tracking)) {
528
+ return tracking.some((entry) => hasAmazonTracking(entry));
529
+ }
530
+ if (!tracking || typeof tracking !== "object") {
531
+ return false;
532
+ }
533
+ const record = tracking;
534
+ const carrierRaw = compactTrackingValue(record.carrier) ?? compactTrackingValue(record.provider) ?? compactTrackingValue(record.shipper);
535
+ const number = compactTrackingValue(record.tracking_number) ?? compactTrackingValue(record.trackingNumber) ?? compactTrackingValue(record.number) ?? compactTrackingValue(record.code);
536
+ if (isAmazonStyleTracking(carrierRaw, number)) {
537
+ return true;
538
+ }
539
+ return ["shipments", "tracking_numbers", "trackingNumbers", "numbers"].some(
540
+ (nestedKey) => nestedKey in record && hasAmazonTracking(record[nestedKey])
541
+ );
542
+ }
543
+ function trackingLines(tracking) {
544
+ const direct = compactTrackingValue(tracking);
545
+ if (direct) return [direct];
546
+ if (Array.isArray(tracking)) {
547
+ return tracking.flatMap((entry) => trackingLines(entry)).filter((line2, index, lines2) => line2 && lines2.indexOf(line2) === index);
548
+ }
549
+ if (!tracking || typeof tracking !== "object") {
550
+ return [];
551
+ }
552
+ const record = tracking;
553
+ const carrierRaw = compactTrackingValue(record.carrier) ?? compactTrackingValue(record.provider) ?? compactTrackingValue(record.shipper);
554
+ const number = compactTrackingValue(record.tracking_number) ?? compactTrackingValue(record.trackingNumber) ?? compactTrackingValue(record.number) ?? compactTrackingValue(record.code);
555
+ const carrier = normalizeTrackingCarrier(carrierRaw, number);
556
+ const carrierLabel = displayTrackingCarrier(carrierRaw, number);
557
+ const urlCandidates = [
558
+ compactTrackingValue(record.tracking_url) ?? compactTrackingValue(record.trackingUrl),
559
+ compactTrackingValue(record.url),
560
+ compactTrackingValue(record.retailer_tracking_url),
561
+ compactTrackingValue(record.retailerTrackingUrl),
562
+ trackingUrlForCarrier(carrier, number)
563
+ ];
564
+ const url = urlCandidates.find((candidate) => isBuyerUsableTrackingUrl(candidate)) ?? null;
565
+ const lines = [];
566
+ if (carrierLabel && number) {
567
+ lines.push(`${carrierLabel}: ${number}`);
568
+ } else if (number) {
569
+ lines.push(number);
570
+ } else if (carrierLabel) {
571
+ lines.push(carrierLabel);
572
+ }
573
+ if (url) lines.push(url);
574
+ for (const nestedKey of ["shipments", "tracking_numbers", "trackingNumbers", "numbers"]) {
575
+ if (nestedKey in record) {
576
+ lines.push(...trackingLines(record[nestedKey]));
577
+ }
578
+ }
579
+ return lines.filter((line2, index, all) => line2 && all.indexOf(line2) === index);
580
+ }
408
581
  function getBudgetBasePrice(product) {
409
582
  return product.price;
410
583
  }
@@ -568,6 +741,18 @@ function displayStatus(purchase) {
568
741
  if (purchase.deliveryMethod) {
569
742
  kv("Shipping", purchase.deliveryMethod);
570
743
  }
744
+ const tracking = trackingLines(purchase.tracking);
745
+ if (tracking.length) {
746
+ kv("Tracking", tracking[0]);
747
+ for (const extra of tracking.slice(1)) {
748
+ kv("", extra, { dim: true });
749
+ }
750
+ if (hasAmazonTracking(purchase.tracking)) {
751
+ kv("", "Detailed tracking may appear once the package is in transit.", {
752
+ dim: true
753
+ });
754
+ }
755
+ }
571
756
  kv("Created", new Date(purchase.createdAt).toLocaleString(), { dim: true });
572
757
  gap();
573
758
  }
@@ -592,7 +777,7 @@ function displayRefund(refund2) {
592
777
  import { input, confirm, select } from "@inquirer/prompts";
593
778
  async function promptProductUrl() {
594
779
  return input({
595
- message: "Product URL",
780
+ message: "Product URL or retailer link",
596
781
  validate: (value) => {
597
782
  try {
598
783
  const url = new URL(value);
@@ -719,8 +904,9 @@ import { dirname, join } from "path";
719
904
  var STORE_PATH = join(homedir(), ".agentmall", "tokens.json");
720
905
  function emptyStore() {
721
906
  return {
722
- version: 1,
723
- purchases: {}
907
+ version: 2,
908
+ purchases: {},
909
+ preferredManagedAccounts: {}
724
910
  };
725
911
  }
726
912
  async function readStore() {
@@ -728,8 +914,9 @@ async function readStore() {
728
914
  const raw = await readFile(STORE_PATH, "utf8");
729
915
  const parsed = JSON.parse(raw);
730
916
  return {
731
- version: 1,
732
- purchases: parsed.purchases ?? {}
917
+ version: 2,
918
+ purchases: parsed.purchases ?? {},
919
+ preferredManagedAccounts: parsed.preferredManagedAccounts ?? {}
733
920
  };
734
921
  } catch {
735
922
  return emptyStore();
@@ -758,6 +945,19 @@ async function getBuyerToken(purchaseId) {
758
945
 
759
946
  // src/cli/index.ts
760
947
  var EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
948
+ var SUPPORTED_RETAILER_LABELS = [
949
+ "Amazon",
950
+ "Walmart",
951
+ "Target",
952
+ "Best Buy",
953
+ "Home Depot",
954
+ "eBay",
955
+ "Lowe's",
956
+ "Wayfair",
957
+ "Ace Hardware",
958
+ "1-800-Flowers",
959
+ "Pokemon Center"
960
+ ];
761
961
  function parseTempoBalance(balance) {
762
962
  const parsed = Number.parseFloat(balance ?? "0");
763
963
  return Number.isFinite(parsed) ? parsed : 0;
@@ -939,6 +1139,11 @@ async function buy(urlArg) {
939
1139
  try {
940
1140
  banner();
941
1141
  gap();
1142
+ if (!urlArg) {
1143
+ muted("Paste a product URL from a supported retailer.");
1144
+ muted(`Supported retailers: ${SUPPORTED_RETAILER_LABELS.join(", ")}.`);
1145
+ gap();
1146
+ }
942
1147
  const url = urlArg ?? await promptProductUrl();
943
1148
  const client = new AgentMall();
944
1149
  const product = await spin(
package/dist/index.cjs CHANGED
@@ -113,6 +113,7 @@ var AgentMall = class {
113
113
  purchases;
114
114
  payments;
115
115
  refunds;
116
+ managedAccounts;
116
117
  constructor(config = {}) {
117
118
  this.baseUrl = (config.baseUrl ?? BASE_URL).replace(/\/$/, "");
118
119
  this.apiSecret = config.apiSecret;
@@ -121,6 +122,7 @@ var AgentMall = class {
121
122
  this.purchases = new AgentMallPurchases(this);
122
123
  this.payments = new AgentMallPayments(this);
123
124
  this.refunds = new AgentMallRefunds(this);
125
+ this.managedAccounts = new AgentMallManagedAccounts(this);
124
126
  }
125
127
  /** @internal */
126
128
  hasApiSecret() {
@@ -172,6 +174,9 @@ var AgentMall = class {
172
174
  }
173
175
  throw new AgentMallError(response.status, body);
174
176
  }
177
+ if (response.status === 204) {
178
+ return void 0;
179
+ }
175
180
  return await response.json();
176
181
  }
177
182
  };
@@ -303,6 +308,58 @@ var AgentMallRefunds = class {
303
308
  return result.refunds;
304
309
  }
305
310
  };
311
+ var AgentMallManagedAccounts = class {
312
+ constructor(client) {
313
+ this.client = client;
314
+ }
315
+ async walletHeaders(account) {
316
+ const challenge = await this.client.request(
317
+ "POST",
318
+ "/api/managed-accounts/challenge",
319
+ {
320
+ body: {
321
+ address: account.address
322
+ }
323
+ }
324
+ );
325
+ const signature = await account.signMessage({
326
+ message: challenge.message
327
+ });
328
+ return {
329
+ "X-AgentMall-Wallet-Address": account.address,
330
+ "X-AgentMall-Auth-Challenge": challenge.challenge,
331
+ "X-AgentMall-Auth-Signature": signature
332
+ };
333
+ }
334
+ /** List managed retailer accounts. Requires either apiSecret or a wallet signer. */
335
+ async list(options) {
336
+ const result = await this.client.request("GET", "/api/managed-accounts", {
337
+ ...options?.account ? { headers: await this.walletHeaders(options.account) } : { auth: true }
338
+ });
339
+ return result.credentials;
340
+ }
341
+ /** Create a managed retailer account. Requires either apiSecret or a wallet signer. */
342
+ async create(body, options) {
343
+ return this.client.request("POST", "/api/managed-accounts", {
344
+ ...options?.account ? { headers: await this.walletHeaders(options.account) } : { auth: true },
345
+ body
346
+ });
347
+ }
348
+ /** Update a managed retailer account. Requires either apiSecret or a wallet signer. */
349
+ async update(body, options) {
350
+ return this.client.request("PUT", "/api/managed-accounts", {
351
+ ...options?.account ? { headers: await this.walletHeaders(options.account) } : { auth: true },
352
+ body
353
+ });
354
+ }
355
+ /** Delete a managed retailer account. Requires either apiSecret or a wallet signer. */
356
+ async delete(shortId, options) {
357
+ await this.client.request("DELETE", "/api/managed-accounts", {
358
+ ...options?.account ? { headers: await this.walletHeaders(options.account) } : { auth: true },
359
+ params: { short_id: shortId }
360
+ });
361
+ }
362
+ };
306
363
 
307
364
  // src/purchase.ts
308
365
  async function purchase(config) {
package/dist/index.d.cts CHANGED
@@ -62,6 +62,7 @@ type CreatePurchaseRequest = {
62
62
  delivery_address: DeliveryAddress;
63
63
  max_budget: number;
64
64
  buyer_email: string;
65
+ retailer_credentials_id?: string;
65
66
  idempotency_key?: string;
66
67
  metadata?: unknown;
67
68
  };
@@ -90,6 +91,8 @@ type Purchase = {
90
91
  status: PurchaseLifecycleStatus;
91
92
  items: PurchaseItem[];
92
93
  deliveryMethod?: string;
94
+ tracking?: unknown;
95
+ retailerCredentialsId?: string;
93
96
  maxBudget: number;
94
97
  finalTotal?: number;
95
98
  merchantReferences?: string[];
@@ -140,6 +143,38 @@ type RefundFilters = {
140
143
  purchase_id?: string;
141
144
  status?: string;
142
145
  };
146
+ type ManagedAccount = {
147
+ id: string;
148
+ short_id: string;
149
+ email: string;
150
+ retailer: string | null;
151
+ has_totp?: boolean;
152
+ has_forwarding?: boolean;
153
+ retailer_config?: Record<string, unknown> | null;
154
+ forwarding_email: string;
155
+ created_at: string;
156
+ updated_at: string;
157
+ };
158
+ type ManagedAccountAuthChallenge = {
159
+ challenge: string;
160
+ message: string;
161
+ expiresAt: number;
162
+ };
163
+ type CreateManagedAccountRequest = {
164
+ email: string;
165
+ password?: string | null;
166
+ retailer?: string | null;
167
+ totp_secret?: string | null;
168
+ retailer_config?: Record<string, unknown> | null;
169
+ };
170
+ type UpdateManagedAccountRequest = {
171
+ short_id: string;
172
+ email?: string | null;
173
+ password?: string | null;
174
+ retailer?: string | null;
175
+ totp_secret?: string | null;
176
+ retailer_config?: Record<string, unknown> | null;
177
+ };
143
178
 
144
179
  declare class AgentMall {
145
180
  private baseUrl;
@@ -149,6 +184,7 @@ declare class AgentMall {
149
184
  purchases: AgentMallPurchases;
150
185
  payments: AgentMallPayments;
151
186
  refunds: AgentMallRefunds;
187
+ managedAccounts: AgentMallManagedAccounts;
152
188
  constructor(config?: AgentMallConfig);
153
189
  /** @internal */
154
190
  hasApiSecret(): boolean;
@@ -201,6 +237,27 @@ declare class AgentMallRefunds {
201
237
  /** List refunds. Requires apiSecret. */
202
238
  list(filters?: RefundFilters): Promise<Refund[]>;
203
239
  }
240
+ declare class AgentMallManagedAccounts {
241
+ private client;
242
+ constructor(client: AgentMall);
243
+ private walletHeaders;
244
+ /** List managed retailer accounts. Requires either apiSecret or a wallet signer. */
245
+ list(options?: {
246
+ account?: WalletAccount;
247
+ }): Promise<ManagedAccount[]>;
248
+ /** Create a managed retailer account. Requires either apiSecret or a wallet signer. */
249
+ create(body: CreateManagedAccountRequest, options?: {
250
+ account?: WalletAccount;
251
+ }): Promise<ManagedAccount>;
252
+ /** Update a managed retailer account. Requires either apiSecret or a wallet signer. */
253
+ update(body: UpdateManagedAccountRequest, options?: {
254
+ account?: WalletAccount;
255
+ }): Promise<ManagedAccount>;
256
+ /** Delete a managed retailer account. Requires either apiSecret or a wallet signer. */
257
+ delete(shortId: string, options?: {
258
+ account?: WalletAccount;
259
+ }): Promise<void>;
260
+ }
204
261
 
205
262
  type PurchaseConfig = CreatePurchaseRequest & {
206
263
  /** viem Account for MPP payment (from privateKeyToAccount or mppx resolveAccount). */
@@ -251,4 +308,4 @@ declare const BASE_URL = "https://api.agentmall.sh";
251
308
  declare const SERVICE_FEE_CENTS = 150;
252
309
  declare const SUPPORTED_RETAILERS: readonly ["amazon.com", "walmart.com", "target.com", "bestbuy.com", "homedepot.com", "ebay.com", "lowes.com", "wayfair.com", "acehardware.com", "1800flowers.com", "pokemoncenter.com"];
253
310
 
254
- export { AgentMall, type AgentMallConfig, AgentMallError, BASE_URL, ConflictError, type CreatePurchaseRequest, type CreatePurchaseResponse, type DeliveryAddress, type Payment, type PaymentFilters, PaymentRequiredError, type ProductLookup, type ProductVariant, type Purchase, type PurchaseFilters, type PurchaseItem, type PurchaseItemInput, type PurchaseLifecycleStatus, type PurchaseStatusChallenge, RateLimitError, type Refund, type RefundFilters, type RefundStatusChallenge, SERVICE_FEE_CENTS, SUPPORTED_RETAILERS, ValidationError, type VariantSelection, type WalletAccount, purchase };
311
+ export { AgentMall, type AgentMallConfig, AgentMallError, BASE_URL, ConflictError, type CreateManagedAccountRequest, type CreatePurchaseRequest, type CreatePurchaseResponse, type DeliveryAddress, type ManagedAccount, type ManagedAccountAuthChallenge, type Payment, type PaymentFilters, PaymentRequiredError, type ProductLookup, type ProductVariant, type Purchase, type PurchaseFilters, type PurchaseItem, type PurchaseItemInput, type PurchaseLifecycleStatus, type PurchaseStatusChallenge, RateLimitError, type Refund, type RefundFilters, type RefundStatusChallenge, SERVICE_FEE_CENTS, SUPPORTED_RETAILERS, type UpdateManagedAccountRequest, ValidationError, type VariantSelection, type WalletAccount, purchase };
package/dist/index.d.ts CHANGED
@@ -62,6 +62,7 @@ type CreatePurchaseRequest = {
62
62
  delivery_address: DeliveryAddress;
63
63
  max_budget: number;
64
64
  buyer_email: string;
65
+ retailer_credentials_id?: string;
65
66
  idempotency_key?: string;
66
67
  metadata?: unknown;
67
68
  };
@@ -90,6 +91,8 @@ type Purchase = {
90
91
  status: PurchaseLifecycleStatus;
91
92
  items: PurchaseItem[];
92
93
  deliveryMethod?: string;
94
+ tracking?: unknown;
95
+ retailerCredentialsId?: string;
93
96
  maxBudget: number;
94
97
  finalTotal?: number;
95
98
  merchantReferences?: string[];
@@ -140,6 +143,38 @@ type RefundFilters = {
140
143
  purchase_id?: string;
141
144
  status?: string;
142
145
  };
146
+ type ManagedAccount = {
147
+ id: string;
148
+ short_id: string;
149
+ email: string;
150
+ retailer: string | null;
151
+ has_totp?: boolean;
152
+ has_forwarding?: boolean;
153
+ retailer_config?: Record<string, unknown> | null;
154
+ forwarding_email: string;
155
+ created_at: string;
156
+ updated_at: string;
157
+ };
158
+ type ManagedAccountAuthChallenge = {
159
+ challenge: string;
160
+ message: string;
161
+ expiresAt: number;
162
+ };
163
+ type CreateManagedAccountRequest = {
164
+ email: string;
165
+ password?: string | null;
166
+ retailer?: string | null;
167
+ totp_secret?: string | null;
168
+ retailer_config?: Record<string, unknown> | null;
169
+ };
170
+ type UpdateManagedAccountRequest = {
171
+ short_id: string;
172
+ email?: string | null;
173
+ password?: string | null;
174
+ retailer?: string | null;
175
+ totp_secret?: string | null;
176
+ retailer_config?: Record<string, unknown> | null;
177
+ };
143
178
 
144
179
  declare class AgentMall {
145
180
  private baseUrl;
@@ -149,6 +184,7 @@ declare class AgentMall {
149
184
  purchases: AgentMallPurchases;
150
185
  payments: AgentMallPayments;
151
186
  refunds: AgentMallRefunds;
187
+ managedAccounts: AgentMallManagedAccounts;
152
188
  constructor(config?: AgentMallConfig);
153
189
  /** @internal */
154
190
  hasApiSecret(): boolean;
@@ -201,6 +237,27 @@ declare class AgentMallRefunds {
201
237
  /** List refunds. Requires apiSecret. */
202
238
  list(filters?: RefundFilters): Promise<Refund[]>;
203
239
  }
240
+ declare class AgentMallManagedAccounts {
241
+ private client;
242
+ constructor(client: AgentMall);
243
+ private walletHeaders;
244
+ /** List managed retailer accounts. Requires either apiSecret or a wallet signer. */
245
+ list(options?: {
246
+ account?: WalletAccount;
247
+ }): Promise<ManagedAccount[]>;
248
+ /** Create a managed retailer account. Requires either apiSecret or a wallet signer. */
249
+ create(body: CreateManagedAccountRequest, options?: {
250
+ account?: WalletAccount;
251
+ }): Promise<ManagedAccount>;
252
+ /** Update a managed retailer account. Requires either apiSecret or a wallet signer. */
253
+ update(body: UpdateManagedAccountRequest, options?: {
254
+ account?: WalletAccount;
255
+ }): Promise<ManagedAccount>;
256
+ /** Delete a managed retailer account. Requires either apiSecret or a wallet signer. */
257
+ delete(shortId: string, options?: {
258
+ account?: WalletAccount;
259
+ }): Promise<void>;
260
+ }
204
261
 
205
262
  type PurchaseConfig = CreatePurchaseRequest & {
206
263
  /** viem Account for MPP payment (from privateKeyToAccount or mppx resolveAccount). */
@@ -251,4 +308,4 @@ declare const BASE_URL = "https://api.agentmall.sh";
251
308
  declare const SERVICE_FEE_CENTS = 150;
252
309
  declare const SUPPORTED_RETAILERS: readonly ["amazon.com", "walmart.com", "target.com", "bestbuy.com", "homedepot.com", "ebay.com", "lowes.com", "wayfair.com", "acehardware.com", "1800flowers.com", "pokemoncenter.com"];
253
310
 
254
- export { AgentMall, type AgentMallConfig, AgentMallError, BASE_URL, ConflictError, type CreatePurchaseRequest, type CreatePurchaseResponse, type DeliveryAddress, type Payment, type PaymentFilters, PaymentRequiredError, type ProductLookup, type ProductVariant, type Purchase, type PurchaseFilters, type PurchaseItem, type PurchaseItemInput, type PurchaseLifecycleStatus, type PurchaseStatusChallenge, RateLimitError, type Refund, type RefundFilters, type RefundStatusChallenge, SERVICE_FEE_CENTS, SUPPORTED_RETAILERS, ValidationError, type VariantSelection, type WalletAccount, purchase };
311
+ export { AgentMall, type AgentMallConfig, AgentMallError, BASE_URL, ConflictError, type CreateManagedAccountRequest, type CreatePurchaseRequest, type CreatePurchaseResponse, type DeliveryAddress, type ManagedAccount, type ManagedAccountAuthChallenge, type Payment, type PaymentFilters, PaymentRequiredError, type ProductLookup, type ProductVariant, type Purchase, type PurchaseFilters, type PurchaseItem, type PurchaseItemInput, type PurchaseLifecycleStatus, type PurchaseStatusChallenge, RateLimitError, type Refund, type RefundFilters, type RefundStatusChallenge, SERVICE_FEE_CENTS, SUPPORTED_RETAILERS, type UpdateManagedAccountRequest, ValidationError, type VariantSelection, type WalletAccount, purchase };
package/dist/index.js CHANGED
@@ -68,6 +68,7 @@ var AgentMall = class {
68
68
  purchases;
69
69
  payments;
70
70
  refunds;
71
+ managedAccounts;
71
72
  constructor(config = {}) {
72
73
  this.baseUrl = (config.baseUrl ?? BASE_URL).replace(/\/$/, "");
73
74
  this.apiSecret = config.apiSecret;
@@ -76,6 +77,7 @@ var AgentMall = class {
76
77
  this.purchases = new AgentMallPurchases(this);
77
78
  this.payments = new AgentMallPayments(this);
78
79
  this.refunds = new AgentMallRefunds(this);
80
+ this.managedAccounts = new AgentMallManagedAccounts(this);
79
81
  }
80
82
  /** @internal */
81
83
  hasApiSecret() {
@@ -127,6 +129,9 @@ var AgentMall = class {
127
129
  }
128
130
  throw new AgentMallError(response.status, body);
129
131
  }
132
+ if (response.status === 204) {
133
+ return void 0;
134
+ }
130
135
  return await response.json();
131
136
  }
132
137
  };
@@ -258,6 +263,58 @@ var AgentMallRefunds = class {
258
263
  return result.refunds;
259
264
  }
260
265
  };
266
+ var AgentMallManagedAccounts = class {
267
+ constructor(client) {
268
+ this.client = client;
269
+ }
270
+ async walletHeaders(account) {
271
+ const challenge = await this.client.request(
272
+ "POST",
273
+ "/api/managed-accounts/challenge",
274
+ {
275
+ body: {
276
+ address: account.address
277
+ }
278
+ }
279
+ );
280
+ const signature = await account.signMessage({
281
+ message: challenge.message
282
+ });
283
+ return {
284
+ "X-AgentMall-Wallet-Address": account.address,
285
+ "X-AgentMall-Auth-Challenge": challenge.challenge,
286
+ "X-AgentMall-Auth-Signature": signature
287
+ };
288
+ }
289
+ /** List managed retailer accounts. Requires either apiSecret or a wallet signer. */
290
+ async list(options) {
291
+ const result = await this.client.request("GET", "/api/managed-accounts", {
292
+ ...options?.account ? { headers: await this.walletHeaders(options.account) } : { auth: true }
293
+ });
294
+ return result.credentials;
295
+ }
296
+ /** Create a managed retailer account. Requires either apiSecret or a wallet signer. */
297
+ async create(body, options) {
298
+ return this.client.request("POST", "/api/managed-accounts", {
299
+ ...options?.account ? { headers: await this.walletHeaders(options.account) } : { auth: true },
300
+ body
301
+ });
302
+ }
303
+ /** Update a managed retailer account. Requires either apiSecret or a wallet signer. */
304
+ async update(body, options) {
305
+ return this.client.request("PUT", "/api/managed-accounts", {
306
+ ...options?.account ? { headers: await this.walletHeaders(options.account) } : { auth: true },
307
+ body
308
+ });
309
+ }
310
+ /** Delete a managed retailer account. Requires either apiSecret or a wallet signer. */
311
+ async delete(shortId, options) {
312
+ await this.client.request("DELETE", "/api/managed-accounts", {
313
+ ...options?.account ? { headers: await this.walletHeaders(options.account) } : { auth: true },
314
+ params: { short_id: shortId }
315
+ });
316
+ }
317
+ };
261
318
 
262
319
  // src/purchase.ts
263
320
  async function purchase(config) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentmall",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "SDK and CLI for the AgentMall API — let AI agents buy physical products from US retailers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",