@stripe/link-sdk 0.7.0 → 0.8.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/index.js CHANGED
@@ -1,5 +1,4 @@
1
- // src/resources/attestations.ts
2
- import { createHash as createHash2 } from "crypto";
1
+ // src/resources/approval-policy.ts
3
2
  import { z } from "zod";
4
3
 
5
4
  // src/errors.ts
@@ -45,6 +44,224 @@ var LinkApiError = class extends LinkSdkError {
45
44
  }
46
45
  };
47
46
 
47
+ // src/config.ts
48
+ var DEFAULT_API_BASE_URL = "https://api.link.com";
49
+ function createDefaultHeadersFetch(baseFetch, defaultHeaders) {
50
+ return ((input, init) => {
51
+ const headers = new Headers(init?.headers);
52
+ for (const [key, value] of Object.entries(defaultHeaders)) {
53
+ if (!headers.has(key)) {
54
+ headers.set(key, value);
55
+ }
56
+ }
57
+ return baseFetch(input, { ...init, headers });
58
+ });
59
+ }
60
+ function createDefaultLogger() {
61
+ return {
62
+ debug() {
63
+ }
64
+ };
65
+ }
66
+ function resolveLinkSdkConfig(options, defaults = {}) {
67
+ const verbose = options.verbose ?? false;
68
+ const logger = options.logger ?? createDefaultLogger();
69
+ if (options.accessToken !== void 0 && options.getAccessToken !== void 0) {
70
+ throw new LinkConfigurationError(
71
+ "Pass either `accessToken` or `getAccessToken`, not both."
72
+ );
73
+ }
74
+ let getAccessToken;
75
+ let canRefreshAccessToken;
76
+ if (options.accessToken !== void 0) {
77
+ if (options.accessToken.trim().length === 0) {
78
+ throw new LinkConfigurationError("`accessToken` cannot be empty.");
79
+ }
80
+ const accessToken = options.accessToken;
81
+ getAccessToken = () => accessToken;
82
+ canRefreshAccessToken = false;
83
+ } else if (typeof options.getAccessToken === "function") {
84
+ getAccessToken = options.getAccessToken;
85
+ canRefreshAccessToken = true;
86
+ } else {
87
+ throw new LinkConfigurationError(
88
+ "Pass `accessToken` or `getAccessToken` to the Link client."
89
+ );
90
+ }
91
+ const apiBaseUrl = options.apiBaseUrl ?? defaults.apiBaseUrl ?? DEFAULT_API_BASE_URL;
92
+ const spendRequestBaseUrl = options.spendRequestBaseUrl ?? defaults.spendRequestBaseUrl ?? apiBaseUrl;
93
+ const baseFetch = options.fetch ?? globalThis.fetch;
94
+ const effectiveFetch = options.defaultHeaders && Object.keys(options.defaultHeaders).length > 0 ? createDefaultHeadersFetch(baseFetch, options.defaultHeaders) : baseFetch;
95
+ return {
96
+ verbose,
97
+ getAccessToken,
98
+ canRefreshAccessToken,
99
+ fetch: effectiveFetch,
100
+ apiBaseUrl,
101
+ spendRequestBaseUrl,
102
+ logger
103
+ };
104
+ }
105
+ function requireFetchImplementation(config) {
106
+ if (!config.fetch) {
107
+ throw new LinkConfigurationError(
108
+ "No fetch implementation available. Pass `fetch` in Link SDK options."
109
+ );
110
+ }
111
+ return config.fetch;
112
+ }
113
+
114
+ // src/resources/base.ts
115
+ function isRecord(value) {
116
+ return value !== null && typeof value === "object" && !Array.isArray(value);
117
+ }
118
+ function extractErrorMessage(data, rawBody) {
119
+ if (isRecord(data)) {
120
+ if (typeof data.error === "string") {
121
+ return data.error;
122
+ }
123
+ if (isRecord(data.error)) {
124
+ const nested = data.error;
125
+ if (typeof nested.message === "string") {
126
+ return nested.message;
127
+ }
128
+ if (typeof nested.code === "string") {
129
+ return nested.code;
130
+ }
131
+ }
132
+ if (typeof data.message === "string") {
133
+ return data.message;
134
+ }
135
+ }
136
+ return rawBody || "unknown error";
137
+ }
138
+ var BaseResource = class {
139
+ verbose;
140
+ getAccessToken;
141
+ canRefreshAccessToken;
142
+ fetchImpl;
143
+ endpoint;
144
+ logger;
145
+ constructor(options, endpointPath, base = "api") {
146
+ const config = resolveLinkSdkConfig(options);
147
+ this.verbose = config.verbose;
148
+ this.getAccessToken = config.getAccessToken;
149
+ this.canRefreshAccessToken = config.canRefreshAccessToken;
150
+ this.fetchImpl = requireFetchImplementation(config);
151
+ const baseUrl = base === "spend" ? config.spendRequestBaseUrl : config.apiBaseUrl;
152
+ this.endpoint = `${baseUrl}${endpointPath}`;
153
+ this.logger = config.logger;
154
+ }
155
+ async rawFetch(opts) {
156
+ if (this.verbose) {
157
+ this.logger.debug(`> ${opts.method} ${opts.url}`);
158
+ }
159
+ let response;
160
+ try {
161
+ const init = {
162
+ method: opts.method,
163
+ ...opts.headers !== void 0 && { headers: opts.headers },
164
+ ...opts.body !== void 0 && { body: opts.body },
165
+ ...opts.signal !== void 0 && { signal: opts.signal },
166
+ ...opts.redirect !== void 0 && { redirect: opts.redirect }
167
+ };
168
+ response = await this.fetchImpl(opts.url, init);
169
+ } catch (error) {
170
+ throw new LinkTransportError(
171
+ `Request failed: ${opts.method} ${opts.url}`,
172
+ { cause: error }
173
+ );
174
+ }
175
+ const rawBody = await response.text();
176
+ let data = null;
177
+ try {
178
+ data = JSON.parse(rawBody);
179
+ } catch {
180
+ }
181
+ if (this.verbose) {
182
+ this.logger.debug(`< ${response.status} ${response.statusText}`);
183
+ }
184
+ return { status: response.status, data, rawBody };
185
+ }
186
+ async apiFetch(opts) {
187
+ const token = await this.getAccessToken();
188
+ const authedOpts = {
189
+ ...opts,
190
+ headers: {
191
+ ...opts.headers,
192
+ Authorization: `Bearer ${token}`
193
+ }
194
+ };
195
+ const res = await this.rawFetch(authedOpts);
196
+ if (res.status === 401 && this.canRefreshAccessToken) {
197
+ const refreshedToken = await this.getAccessToken({ forceRefresh: true });
198
+ return this.rawFetch({
199
+ ...opts,
200
+ headers: {
201
+ ...opts.headers,
202
+ Authorization: `Bearer ${refreshedToken}`
203
+ }
204
+ });
205
+ }
206
+ return res;
207
+ }
208
+ throwApiError(operation, status, data, rawBody, cause) {
209
+ const msg = extractErrorMessage(data, rawBody);
210
+ throw new LinkApiError(`Failed to ${operation} (${status}): ${msg}`, {
211
+ status,
212
+ rawBody,
213
+ details: data,
214
+ cause
215
+ });
216
+ }
217
+ parseResponse(operation, status, parser) {
218
+ try {
219
+ return parser();
220
+ } catch (error) {
221
+ throw new LinkResponseError(operation, status, { cause: error });
222
+ }
223
+ }
224
+ };
225
+
226
+ // src/resources/approval-policy.ts
227
+ var approvalPolicySchema = z.looseObject({
228
+ rules: z.array(
229
+ z.looseObject({
230
+ action: z.string(),
231
+ limits: z.looseObject({
232
+ per_purchase: z.looseObject({
233
+ amount: z.number().int(),
234
+ currency: z.string()
235
+ })
236
+ }),
237
+ allowed_payment_methods: z.array(z.string()).optional()
238
+ })
239
+ )
240
+ });
241
+ var ApprovalPolicyResource = class extends BaseResource {
242
+ constructor(options) {
243
+ super(options, "/approval-policy");
244
+ }
245
+ async retrieve() {
246
+ const { status, data, rawBody } = await this.apiFetch({
247
+ method: "GET",
248
+ url: this.endpoint
249
+ });
250
+ if (status < 200 || status >= 300) {
251
+ this.throwApiError("retrieve approval policy", status, data, rawBody);
252
+ }
253
+ return this.parseResponse(
254
+ "retrieve approval policy",
255
+ status,
256
+ () => approvalPolicySchema.parse(data)
257
+ );
258
+ }
259
+ };
260
+
261
+ // src/resources/attestations.ts
262
+ import { createHash as createHash2 } from "crypto";
263
+ import { z as z2 } from "zod";
264
+
48
265
  // src/resources/attestations-crypto.ts
49
266
  import {
50
267
  createHash,
@@ -403,185 +620,6 @@ function computeChallengeDigest(tokenType, issuerName) {
403
620
  return new Uint8Array(createHash("sha256").update(challenge).digest());
404
621
  }
405
622
 
406
- // src/config.ts
407
- var DEFAULT_API_BASE_URL = "https://api.link.com";
408
- function createDefaultHeadersFetch(baseFetch, defaultHeaders) {
409
- return ((input, init) => {
410
- const headers = new Headers(init?.headers);
411
- for (const [key, value] of Object.entries(defaultHeaders)) {
412
- if (!headers.has(key)) {
413
- headers.set(key, value);
414
- }
415
- }
416
- return baseFetch(input, { ...init, headers });
417
- });
418
- }
419
- function createDefaultLogger() {
420
- return {
421
- debug() {
422
- }
423
- };
424
- }
425
- function resolveLinkSdkConfig(options, defaults = {}) {
426
- const verbose = options.verbose ?? false;
427
- const logger = options.logger ?? createDefaultLogger();
428
- if (options.accessToken !== void 0 && options.getAccessToken !== void 0) {
429
- throw new LinkConfigurationError(
430
- "Pass either `accessToken` or `getAccessToken`, not both."
431
- );
432
- }
433
- let getAccessToken;
434
- let canRefreshAccessToken;
435
- if (options.accessToken !== void 0) {
436
- if (options.accessToken.trim().length === 0) {
437
- throw new LinkConfigurationError("`accessToken` cannot be empty.");
438
- }
439
- const accessToken = options.accessToken;
440
- getAccessToken = () => accessToken;
441
- canRefreshAccessToken = false;
442
- } else if (typeof options.getAccessToken === "function") {
443
- getAccessToken = options.getAccessToken;
444
- canRefreshAccessToken = true;
445
- } else {
446
- throw new LinkConfigurationError(
447
- "Pass `accessToken` or `getAccessToken` to the Link client."
448
- );
449
- }
450
- const apiBaseUrl = options.apiBaseUrl ?? defaults.apiBaseUrl ?? DEFAULT_API_BASE_URL;
451
- const spendRequestBaseUrl = options.spendRequestBaseUrl ?? defaults.spendRequestBaseUrl ?? apiBaseUrl;
452
- const baseFetch = options.fetch ?? globalThis.fetch;
453
- const effectiveFetch = options.defaultHeaders && Object.keys(options.defaultHeaders).length > 0 ? createDefaultHeadersFetch(baseFetch, options.defaultHeaders) : baseFetch;
454
- return {
455
- verbose,
456
- getAccessToken,
457
- canRefreshAccessToken,
458
- fetch: effectiveFetch,
459
- apiBaseUrl,
460
- spendRequestBaseUrl,
461
- logger
462
- };
463
- }
464
- function requireFetchImplementation(config) {
465
- if (!config.fetch) {
466
- throw new LinkConfigurationError(
467
- "No fetch implementation available. Pass `fetch` in Link SDK options."
468
- );
469
- }
470
- return config.fetch;
471
- }
472
-
473
- // src/resources/base.ts
474
- function isRecord(value) {
475
- return value !== null && typeof value === "object" && !Array.isArray(value);
476
- }
477
- function extractErrorMessage(data, rawBody) {
478
- if (isRecord(data)) {
479
- if (typeof data.error === "string") {
480
- return data.error;
481
- }
482
- if (isRecord(data.error)) {
483
- const nested = data.error;
484
- if (typeof nested.message === "string") {
485
- return nested.message;
486
- }
487
- if (typeof nested.code === "string") {
488
- return nested.code;
489
- }
490
- }
491
- if (typeof data.message === "string") {
492
- return data.message;
493
- }
494
- }
495
- return rawBody || "unknown error";
496
- }
497
- var BaseResource = class {
498
- verbose;
499
- getAccessToken;
500
- canRefreshAccessToken;
501
- fetchImpl;
502
- endpoint;
503
- logger;
504
- constructor(options, endpointPath, base = "api") {
505
- const config = resolveLinkSdkConfig(options);
506
- this.verbose = config.verbose;
507
- this.getAccessToken = config.getAccessToken;
508
- this.canRefreshAccessToken = config.canRefreshAccessToken;
509
- this.fetchImpl = requireFetchImplementation(config);
510
- const baseUrl = base === "spend" ? config.spendRequestBaseUrl : config.apiBaseUrl;
511
- this.endpoint = `${baseUrl}${endpointPath}`;
512
- this.logger = config.logger;
513
- }
514
- async rawFetch(opts) {
515
- if (this.verbose) {
516
- this.logger.debug(`> ${opts.method} ${opts.url}`);
517
- }
518
- let response;
519
- try {
520
- const init = {
521
- method: opts.method,
522
- ...opts.headers !== void 0 && { headers: opts.headers },
523
- ...opts.body !== void 0 && { body: opts.body },
524
- ...opts.signal !== void 0 && { signal: opts.signal },
525
- ...opts.redirect !== void 0 && { redirect: opts.redirect }
526
- };
527
- response = await this.fetchImpl(opts.url, init);
528
- } catch (error) {
529
- throw new LinkTransportError(
530
- `Request failed: ${opts.method} ${opts.url}`,
531
- { cause: error }
532
- );
533
- }
534
- const rawBody = await response.text();
535
- let data = null;
536
- try {
537
- data = JSON.parse(rawBody);
538
- } catch {
539
- }
540
- if (this.verbose) {
541
- this.logger.debug(`< ${response.status} ${response.statusText}`);
542
- }
543
- return { status: response.status, data, rawBody };
544
- }
545
- async apiFetch(opts) {
546
- const token = await this.getAccessToken();
547
- const authedOpts = {
548
- ...opts,
549
- headers: {
550
- ...opts.headers,
551
- Authorization: `Bearer ${token}`
552
- }
553
- };
554
- const res = await this.rawFetch(authedOpts);
555
- if (res.status === 401 && this.canRefreshAccessToken) {
556
- const refreshedToken = await this.getAccessToken({ forceRefresh: true });
557
- return this.rawFetch({
558
- ...opts,
559
- headers: {
560
- ...opts.headers,
561
- Authorization: `Bearer ${refreshedToken}`
562
- }
563
- });
564
- }
565
- return res;
566
- }
567
- throwApiError(operation, status, data, rawBody, cause) {
568
- const msg = extractErrorMessage(data, rawBody);
569
- throw new LinkApiError(`Failed to ${operation} (${status}): ${msg}`, {
570
- status,
571
- rawBody,
572
- details: data,
573
- cause
574
- });
575
- }
576
- parseResponse(operation, status, parser) {
577
- try {
578
- return parser();
579
- } catch (error) {
580
- throw new LinkResponseError(operation, status, { cause: error });
581
- }
582
- }
583
- };
584
-
585
623
  // src/resources/attestations.ts
586
624
  var TOKEN_TYPE_BLIND_RSA = 2;
587
625
  var CONTENT_TYPE_TOKEN_REQUEST = "application/private-token-generic-batch-request";
@@ -589,17 +627,17 @@ var CONTENT_TYPE_TOKEN_RESPONSE = "application/private-token-generic-batch-respo
589
627
  var LINK_ISSUER = "https://api.link.com";
590
628
  var LINK_ISSUER_HOSTNAME = "api.link.com";
591
629
  var LINK_ISSUER_METADATA_URL = `${LINK_ISSUER}/.well-known/aap-issuer`;
592
- var issuerMetadataSchema = z.looseObject({
593
- issuer: z.literal(LINK_ISSUER),
594
- token_issuance_endpoint: z.string(),
595
- token_keys: z.string()
630
+ var issuerMetadataSchema = z2.looseObject({
631
+ issuer: z2.literal(LINK_ISSUER),
632
+ token_issuance_endpoint: z2.string(),
633
+ token_keys: z2.string()
596
634
  });
597
- var tokenKeyDirectorySchema = z.looseObject({
598
- "token-keys": z.array(
599
- z.looseObject({
600
- "token-type": z.number(),
601
- "token-key": z.string(),
602
- "not-before": z.number().int().nonnegative().optional()
635
+ var tokenKeyDirectorySchema = z2.looseObject({
636
+ "token-keys": z2.array(
637
+ z2.looseObject({
638
+ "token-type": z2.number(),
639
+ "token-key": z2.string(),
640
+ "not-before": z2.number().int().nonnegative().optional()
603
641
  })
604
642
  )
605
643
  });
@@ -912,20 +950,20 @@ var AttestationsResource = class extends BaseResource {
912
950
  };
913
951
 
914
952
  // src/resources/balances.ts
915
- import { z as z2 } from "zod";
916
- var currencyAmountsSchema = z2.record(z2.string(), z2.number());
917
- var balanceSchema = z2.looseObject({
918
- source_id: z2.string(),
919
- type: z2.enum(["cash", "credit"]),
920
- cash: z2.looseObject({ available: currencyAmountsSchema }).nullable().optional(),
921
- credit: z2.looseObject({ used: currencyAmountsSchema.nullable() }).nullable().optional(),
922
- current: z2.number(),
923
- currency: z2.string(),
924
- as_of: z2.string()
953
+ import { z as z3 } from "zod";
954
+ var currencyAmountsSchema = z3.record(z3.string(), z3.number());
955
+ var balanceSchema = z3.looseObject({
956
+ source_id: z3.string(),
957
+ type: z3.enum(["cash", "credit"]),
958
+ cash: z3.looseObject({ available: currencyAmountsSchema }).nullable().optional(),
959
+ credit: z3.looseObject({ used: currencyAmountsSchema.nullable() }).nullable().optional(),
960
+ current: z3.number(),
961
+ currency: z3.string(),
962
+ as_of: z3.string()
925
963
  });
926
- var balancesPageSchema = z2.looseObject({
927
- data: z2.array(balanceSchema),
928
- has_more: z2.boolean().optional()
964
+ var balancesPageSchema = z3.looseObject({
965
+ data: z3.array(balanceSchema),
966
+ has_more: z3.boolean().optional()
929
967
  });
930
968
  var BalancesResource = class extends BaseResource {
931
969
  constructor(options) {
@@ -966,7 +1004,7 @@ var BalancesResource = class extends BaseResource {
966
1004
  };
967
1005
 
968
1006
  // src/resources/identity-credentials.ts
969
- import { z as z3 } from "zod";
1007
+ import { z as z4 } from "zod";
970
1008
 
971
1009
  // src/resources/holder-jwk.ts
972
1010
  import { createHash as createHash3 } from "crypto";
@@ -1002,14 +1040,14 @@ function parseHolderPublicJwk(value) {
1002
1040
  // src/resources/identity-credentials.ts
1003
1041
  var LINK_ISSUER2 = "https://api.link.com";
1004
1042
  var LINK_ISSUER_METADATA_URL2 = `${LINK_ISSUER2}/.well-known/aap-issuer`;
1005
- var identityCredentialIssuerMetadataSchema = z3.looseObject({
1006
- issuer: z3.literal(LINK_ISSUER2),
1007
- credential_endpoint: z3.string()
1043
+ var identityCredentialIssuerMetadataSchema = z4.looseObject({
1044
+ issuer: z4.literal(LINK_ISSUER2),
1045
+ credential_endpoint: z4.string()
1008
1046
  });
1009
- var issueIdentityCredentialResponseSchema = z3.looseObject({
1010
- credential: z3.string(),
1011
- issuer: z3.literal(LINK_ISSUER2),
1012
- expires_at: z3.string()
1047
+ var issueIdentityCredentialResponseSchema = z4.looseObject({
1048
+ credential: z4.string(),
1049
+ issuer: z4.literal(LINK_ISSUER2),
1050
+ expires_at: z4.string()
1013
1051
  });
1014
1052
  function requireLinkEndpoint2(value, field) {
1015
1053
  let url;
@@ -1092,16 +1130,23 @@ var IdentityCredentialsResource = class extends BaseResource {
1092
1130
  };
1093
1131
 
1094
1132
  // src/resources/payment-methods.ts
1095
- import { z as z4 } from "zod";
1096
- var paymentMethodSchema = z4.looseObject({
1097
- id: z4.string(),
1098
- type: z4.string(),
1099
- is_default: z4.boolean(),
1100
- name: z4.string(),
1101
- nickname: z4.optional(z4.string().nullable())
1133
+ import { z as z5 } from "zod";
1134
+ var balanceDetailsSchema = z5.looseObject({
1135
+ available_balance: z5.looseObject({
1136
+ amount: z5.number().int(),
1137
+ currency: z5.string()
1138
+ }).optional()
1139
+ });
1140
+ var paymentMethodSchema = z5.looseObject({
1141
+ id: z5.string(),
1142
+ type: z5.string(),
1143
+ is_default: z5.boolean(),
1144
+ name: z5.string(),
1145
+ nickname: z5.optional(z5.string().nullable()),
1146
+ balance_details: balanceDetailsSchema.nullable().optional()
1102
1147
  });
1103
- var paymentMethodsResponseSchema = z4.looseObject({
1104
- payment_details: z4.array(paymentMethodSchema)
1148
+ var paymentMethodsResponseSchema = z5.looseObject({
1149
+ payment_details: z5.array(paymentMethodSchema)
1105
1150
  });
1106
1151
  var PaymentMethodsResource = class extends BaseResource {
1107
1152
  constructor(options) {
@@ -1121,17 +1166,48 @@ var PaymentMethodsResource = class extends BaseResource {
1121
1166
  () => paymentMethodsResponseSchema.parse(data).payment_details
1122
1167
  );
1123
1168
  }
1169
+ async retrieve(id) {
1170
+ const { status, data, rawBody } = await this.apiFetch({
1171
+ method: "GET",
1172
+ url: `${this.endpoint}/${encodeURIComponent(id)}`
1173
+ });
1174
+ if (status === 404) return null;
1175
+ if (status < 200 || status >= 300) {
1176
+ this.throwApiError("retrieve payment method", status, data, rawBody);
1177
+ }
1178
+ return this.parseResponse(
1179
+ "retrieve payment method",
1180
+ status,
1181
+ () => paymentMethodSchema.parse(data)
1182
+ );
1183
+ }
1184
+ async update(id, params) {
1185
+ const { status, data, rawBody } = await this.apiFetch({
1186
+ method: "POST",
1187
+ url: `${this.endpoint}/${encodeURIComponent(id)}`,
1188
+ headers: { "Content-Type": "application/json" },
1189
+ body: JSON.stringify({ nickname: params.nickname })
1190
+ });
1191
+ if (status < 200 || status >= 300) {
1192
+ this.throwApiError("update payment method", status, data, rawBody);
1193
+ }
1194
+ return this.parseResponse(
1195
+ "update payment method",
1196
+ status,
1197
+ () => paymentMethodSchema.parse(data)
1198
+ );
1199
+ }
1124
1200
  };
1125
1201
 
1126
1202
  // src/resources/report.ts
1127
- import { z as z5 } from "zod";
1128
- var reportRecordSchema = z5.looseObject({
1129
- object: z5.string(),
1130
- created_at: z5.string(),
1131
- domain: z5.string(),
1132
- outcome: z5.string(),
1133
- spend_request_id: z5.string(),
1134
- status: z5.string()
1203
+ import { z as z6 } from "zod";
1204
+ var reportRecordSchema = z6.looseObject({
1205
+ object: z6.string(),
1206
+ created_at: z6.string(),
1207
+ domain: z6.string(),
1208
+ outcome: z6.string(),
1209
+ spend_request_id: z6.string(),
1210
+ status: z6.string()
1135
1211
  });
1136
1212
  var ReportResource = class extends BaseResource {
1137
1213
  constructor(options) {
@@ -1156,15 +1232,15 @@ var ReportResource = class extends BaseResource {
1156
1232
  };
1157
1233
 
1158
1234
  // src/resources/shipping-address.ts
1159
- import { z as z6 } from "zod";
1160
- var shippingAddressSchema = z6.looseObject({
1161
- id: z6.string(),
1162
- is_default: z6.boolean(),
1163
- nickname: z6.optional(z6.string().nullable()),
1164
- address: z6.looseObject({}).nullable()
1235
+ import { z as z7 } from "zod";
1236
+ var shippingAddressSchema = z7.looseObject({
1237
+ id: z7.string(),
1238
+ is_default: z7.boolean(),
1239
+ nickname: z7.optional(z7.string().nullable()),
1240
+ address: z7.looseObject({}).nullable()
1165
1241
  });
1166
- var shippingAddressesResponseSchema = z6.looseObject({
1167
- shipping_addresses: z6.array(shippingAddressSchema)
1242
+ var shippingAddressesResponseSchema = z7.looseObject({
1243
+ shipping_addresses: z7.array(shippingAddressSchema)
1168
1244
  });
1169
1245
  var ShippingAddressResource = class extends BaseResource {
1170
1246
  constructor(options) {
@@ -1187,21 +1263,21 @@ var ShippingAddressResource = class extends BaseResource {
1187
1263
  };
1188
1264
 
1189
1265
  // src/resources/sources.ts
1190
- import { z as z7 } from "zod";
1191
- var nullableRecordSchema = z7.record(z7.string(), z7.unknown()).nullable().optional();
1192
- var sourceSchema = z7.looseObject({
1193
- id: z7.string().nullable().optional(),
1194
- name: z7.string().nullable().optional(),
1195
- type: z7.string().nullable().optional(),
1266
+ import { z as z8 } from "zod";
1267
+ var nullableRecordSchema = z8.record(z8.string(), z8.unknown()).nullable().optional();
1268
+ var sourceSchema = z8.looseObject({
1269
+ id: z8.string().nullable().optional(),
1270
+ name: z8.string().nullable().optional(),
1271
+ type: z8.string().nullable().optional(),
1196
1272
  capabilities: nullableRecordSchema,
1197
1273
  external_connection: nullableRecordSchema,
1198
- granted_actions: z7.array(z7.string()).nullable().optional(),
1274
+ granted_actions: z8.array(z8.string()).nullable().optional(),
1199
1275
  bank_account: nullableRecordSchema,
1200
1276
  card: nullableRecordSchema
1201
1277
  });
1202
- var sourcesPageSchema = z7.looseObject({
1203
- data: z7.array(sourceSchema),
1204
- has_more: z7.boolean().optional()
1278
+ var sourcesPageSchema = z8.looseObject({
1279
+ data: z8.array(sourceSchema),
1280
+ has_more: z8.boolean().optional()
1205
1281
  });
1206
1282
  var SourcesResource = class extends BaseResource {
1207
1283
  constructor(options) {
@@ -1237,34 +1313,34 @@ var SourcesResource = class extends BaseResource {
1237
1313
  };
1238
1314
 
1239
1315
  // src/resources/spend-request.ts
1240
- import { z as z8 } from "zod";
1241
- var sharedPaymentTokenSchema = z8.union([
1242
- z8.string().transform((id) => ({ id })),
1243
- z8.looseObject({ id: z8.string() })
1316
+ import { z as z9 } from "zod";
1317
+ var sharedPaymentTokenSchema = z9.union([
1318
+ z9.string().transform((id) => ({ id })),
1319
+ z9.looseObject({ id: z9.string() })
1244
1320
  ]);
1245
- var spendRequestSchema = z8.looseObject({
1246
- id: z8.string(),
1247
- payment_details: z8.string().optional(),
1248
- status: z8.string(),
1249
- line_items: z8.array(z8.unknown()).optional(),
1250
- totals: z8.array(z8.unknown()).optional(),
1251
- created_at: z8.string(),
1252
- updated_at: z8.string(),
1321
+ var spendRequestSchema = z9.looseObject({
1322
+ id: z9.string(),
1323
+ payment_details: z9.string().optional(),
1324
+ status: z9.string(),
1325
+ line_items: z9.array(z9.unknown()).optional(),
1326
+ totals: z9.array(z9.unknown()).optional(),
1327
+ created_at: z9.string(),
1328
+ updated_at: z9.string(),
1253
1329
  shared_payment_token: sharedPaymentTokenSchema.nullable().optional()
1254
1330
  });
1255
- var spendRequestsResponseSchema = z8.looseObject({
1256
- data: z8.array(spendRequestSchema)
1331
+ var spendRequestsResponseSchema = z9.looseObject({
1332
+ data: z9.array(spendRequestSchema)
1257
1333
  });
1258
- var requestApprovalResponseSchema = z8.looseObject({
1259
- id: z8.string(),
1260
- approval_link: z8.string()
1334
+ var requestApprovalResponseSchema = z9.looseObject({
1335
+ id: z9.string(),
1336
+ approval_link: z9.string()
1261
1337
  }).transform(({ approval_link, ...response }) => ({
1262
1338
  ...response,
1263
1339
  approval_url: approval_link
1264
1340
  }));
1265
- var duplicateSpendRequestErrorSchema = z8.looseObject({
1266
- error: z8.looseObject({
1267
- duplicate_spend_request: z8.unknown().optional()
1341
+ var duplicateSpendRequestErrorSchema = z9.looseObject({
1342
+ error: z9.looseObject({
1343
+ duplicate_spend_request: z9.unknown().optional()
1268
1344
  })
1269
1345
  });
1270
1346
  function parseSpendRequest(value) {
@@ -1383,65 +1459,6 @@ var SpendRequestResource = class extends BaseResource {
1383
1459
  }
1384
1460
  };
1385
1461
 
1386
- // src/resources/summaries.ts
1387
- import { z as z9 } from "zod";
1388
- var summaryValueSchema = z9.discriminatedUnion("unit", [
1389
- z9.looseObject({ unit: z9.literal("count"), count: z9.number() }),
1390
- z9.looseObject({
1391
- unit: z9.literal("payment_volume"),
1392
- amount: z9.number(),
1393
- currency: z9.string()
1394
- })
1395
- ]);
1396
- var summaryDataValueSchema = z9.discriminatedUnion("unit", [
1397
- z9.looseObject({ unit: z9.literal("count"), amount: z9.number() }),
1398
- z9.looseObject({
1399
- unit: z9.literal("payment_volume"),
1400
- amount: z9.number(),
1401
- currency: z9.string()
1402
- })
1403
- ]);
1404
- var summarySchema = z9.looseObject({
1405
- id: z9.string(),
1406
- description: z9.string(),
1407
- created_at: z9.string().nullable().optional(),
1408
- status: z9.enum(["ready", "pending", "no_data"]),
1409
- entries: z9.array(z9.looseObject({ label: z9.string(), value: summaryValueSchema })).default([]),
1410
- as_of: z9.number().optional(),
1411
- data: z9.array(z9.looseObject({ label: z9.string(), value: summaryDataValueSchema })).nullable().optional()
1412
- });
1413
- var summariesPageSchema = z9.looseObject({
1414
- data: z9.array(summarySchema),
1415
- has_more: z9.boolean().optional()
1416
- });
1417
- var SummariesResource = class extends BaseResource {
1418
- constructor(options) {
1419
- super(options, "/summaries");
1420
- }
1421
- buildUrl(params) {
1422
- const url = new URL(this.endpoint);
1423
- if (params.starting_after !== void 0)
1424
- url.searchParams.set("starting_after", params.starting_after);
1425
- if (params.summaries !== void 0)
1426
- for (const summary of params.summaries)
1427
- url.searchParams.append("summaries[]", summary);
1428
- return url.toString();
1429
- }
1430
- async list(params = {}) {
1431
- const { status, data, rawBody } = await this.apiFetch({
1432
- method: "GET",
1433
- url: this.buildUrl(params)
1434
- });
1435
- if (status < 200 || status >= 300)
1436
- this.throwApiError("list summaries", status, data, rawBody);
1437
- return this.parseResponse(
1438
- "list summaries",
1439
- status,
1440
- () => summariesPageSchema.parse(data)
1441
- );
1442
- }
1443
- };
1444
-
1445
1462
  // src/resources/transactions.ts
1446
1463
  import { z as z10 } from "zod";
1447
1464
  var transactionSchema = z10.looseObject({
@@ -1738,13 +1755,17 @@ var agentWalletVerificationRequirementSchema = z11.object({
1738
1755
  });
1739
1756
  var userInfoAddressSchema = z11.object({
1740
1757
  line1: z11.string().nullable(),
1741
- line2: z11.string().nullable(),
1758
+ line2: z11.string().nullable().optional(),
1742
1759
  city: z11.string().nullable(),
1743
1760
  state: z11.string().nullable(),
1744
1761
  postal_code: z11.string().nullable(),
1745
1762
  country: z11.string().nullable()
1746
- });
1763
+ }).transform(({ line2, ...address }) => ({
1764
+ ...address,
1765
+ ...line2 === void 0 ? {} : { line2 }
1766
+ }));
1747
1767
  var userInfoSchema = z11.looseObject({
1768
+ id: z11.string().min(1).optional(),
1748
1769
  email: z11.string().nullable().optional(),
1749
1770
  name: z11.string().nullable().optional(),
1750
1771
  first_name: z11.string().nullable().optional(),
@@ -1756,6 +1777,7 @@ var userInfoSchema = z11.looseObject({
1756
1777
  agent_wallet_step_up: agentWalletVerificationRequirementSchema.optional()
1757
1778
  }).transform(
1758
1779
  ({
1780
+ id,
1759
1781
  email,
1760
1782
  name,
1761
1783
  first_name,
@@ -1766,6 +1788,7 @@ var userInfoSchema = z11.looseObject({
1766
1788
  agent_wallet_spend_limits,
1767
1789
  agent_wallet_step_up
1768
1790
  }) => ({
1791
+ ...id === void 0 ? {} : { id },
1769
1792
  email: email ?? null,
1770
1793
  name: name ?? null,
1771
1794
  first_name: first_name ?? null,
@@ -1859,10 +1882,10 @@ var Link = class {
1859
1882
  paymentMethods;
1860
1883
  shippingAddresses;
1861
1884
  userInfo;
1885
+ approvalPolicy;
1862
1886
  transactions;
1863
1887
  sources;
1864
1888
  balances;
1865
- summaries;
1866
1889
  webBotAuth;
1867
1890
  reports;
1868
1891
  ucp;
@@ -1873,10 +1896,10 @@ var Link = class {
1873
1896
  this.paymentMethods = new PaymentMethodsResource(options);
1874
1897
  this.shippingAddresses = new ShippingAddressResource(options);
1875
1898
  this.userInfo = new UserInfoResource(options);
1899
+ this.approvalPolicy = new ApprovalPolicyResource(options);
1876
1900
  this.transactions = new TransactionsResource(options);
1877
1901
  this.sources = new SourcesResource(options);
1878
1902
  this.balances = new BalancesResource(options);
1879
- this.summaries = new SummariesResource(options);
1880
1903
  this.webBotAuth = new WebBotAuthResource(options);
1881
1904
  this.reports = new ReportResource(options);
1882
1905
  this.ucp = new UcpResource(options);
@@ -1904,6 +1927,7 @@ var REPORT_TAGS = [
1904
1927
  ];
1905
1928
  var REPORT_ATTEMPT_TRACE_MAX_LENGTH = 8e3;
1906
1929
  export {
1930
+ ApprovalPolicyResource,
1907
1931
  AttestationsResource,
1908
1932
  Link,
1909
1933
  LinkApiError,
@@ -1914,7 +1938,6 @@ export {
1914
1938
  REPORT_ATTEMPT_TRACE_MAX_LENGTH,
1915
1939
  REPORT_OUTCOMES,
1916
1940
  REPORT_TAGS,
1917
- SummariesResource,
1918
1941
  client_default as default,
1919
1942
  getDuplicateSpendRequest,
1920
1943
  holderJwkThumbprint,