@stripe/link-sdk 0.7.0 → 0.9.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,10 @@
1
- // src/resources/attestations.ts
2
- import { createHash as createHash2 } from "crypto";
1
+ import {
2
+ REPORT_ATTEMPT_TRACE_MAX_LENGTH,
3
+ REPORT_OUTCOMES,
4
+ REPORT_TAGS
5
+ } from "./chunk-TYOT25QK.js";
6
+
7
+ // src/resources/approval-policy.ts
3
8
  import { z } from "zod";
4
9
 
5
10
  // src/errors.ts
@@ -45,6 +50,224 @@ var LinkApiError = class extends LinkSdkError {
45
50
  }
46
51
  };
47
52
 
53
+ // src/config.ts
54
+ var DEFAULT_API_BASE_URL = "https://api.link.com";
55
+ function createDefaultHeadersFetch(baseFetch, defaultHeaders) {
56
+ return ((input, init) => {
57
+ const headers = new Headers(init?.headers);
58
+ for (const [key, value] of Object.entries(defaultHeaders)) {
59
+ if (!headers.has(key)) {
60
+ headers.set(key, value);
61
+ }
62
+ }
63
+ return baseFetch(input, { ...init, headers });
64
+ });
65
+ }
66
+ function createDefaultLogger() {
67
+ return {
68
+ debug() {
69
+ }
70
+ };
71
+ }
72
+ function resolveLinkSdkConfig(options, defaults = {}) {
73
+ const verbose = options.verbose ?? false;
74
+ const logger = options.logger ?? createDefaultLogger();
75
+ if (options.accessToken !== void 0 && options.getAccessToken !== void 0) {
76
+ throw new LinkConfigurationError(
77
+ "Pass either `accessToken` or `getAccessToken`, not both."
78
+ );
79
+ }
80
+ let getAccessToken;
81
+ let canRefreshAccessToken;
82
+ if (options.accessToken !== void 0) {
83
+ if (options.accessToken.trim().length === 0) {
84
+ throw new LinkConfigurationError("`accessToken` cannot be empty.");
85
+ }
86
+ const accessToken = options.accessToken;
87
+ getAccessToken = () => accessToken;
88
+ canRefreshAccessToken = false;
89
+ } else if (typeof options.getAccessToken === "function") {
90
+ getAccessToken = options.getAccessToken;
91
+ canRefreshAccessToken = true;
92
+ } else {
93
+ throw new LinkConfigurationError(
94
+ "Pass `accessToken` or `getAccessToken` to the Link client."
95
+ );
96
+ }
97
+ const apiBaseUrl = options.apiBaseUrl ?? defaults.apiBaseUrl ?? DEFAULT_API_BASE_URL;
98
+ const spendRequestBaseUrl = options.spendRequestBaseUrl ?? defaults.spendRequestBaseUrl ?? apiBaseUrl;
99
+ const baseFetch = options.fetch ?? globalThis.fetch;
100
+ const effectiveFetch = options.defaultHeaders && Object.keys(options.defaultHeaders).length > 0 ? createDefaultHeadersFetch(baseFetch, options.defaultHeaders) : baseFetch;
101
+ return {
102
+ verbose,
103
+ getAccessToken,
104
+ canRefreshAccessToken,
105
+ fetch: effectiveFetch,
106
+ apiBaseUrl,
107
+ spendRequestBaseUrl,
108
+ logger
109
+ };
110
+ }
111
+ function requireFetchImplementation(config) {
112
+ if (!config.fetch) {
113
+ throw new LinkConfigurationError(
114
+ "No fetch implementation available. Pass `fetch` in Link SDK options."
115
+ );
116
+ }
117
+ return config.fetch;
118
+ }
119
+
120
+ // src/resources/base.ts
121
+ function isRecord(value) {
122
+ return value !== null && typeof value === "object" && !Array.isArray(value);
123
+ }
124
+ function extractErrorMessage(data, rawBody) {
125
+ if (isRecord(data)) {
126
+ if (typeof data.error === "string") {
127
+ return data.error;
128
+ }
129
+ if (isRecord(data.error)) {
130
+ const nested = data.error;
131
+ if (typeof nested.message === "string") {
132
+ return nested.message;
133
+ }
134
+ if (typeof nested.code === "string") {
135
+ return nested.code;
136
+ }
137
+ }
138
+ if (typeof data.message === "string") {
139
+ return data.message;
140
+ }
141
+ }
142
+ return rawBody || "unknown error";
143
+ }
144
+ var BaseResource = class {
145
+ verbose;
146
+ getAccessToken;
147
+ canRefreshAccessToken;
148
+ fetchImpl;
149
+ endpoint;
150
+ logger;
151
+ constructor(options, endpointPath, base = "api") {
152
+ const config = resolveLinkSdkConfig(options);
153
+ this.verbose = config.verbose;
154
+ this.getAccessToken = config.getAccessToken;
155
+ this.canRefreshAccessToken = config.canRefreshAccessToken;
156
+ this.fetchImpl = requireFetchImplementation(config);
157
+ const baseUrl = base === "spend" ? config.spendRequestBaseUrl : config.apiBaseUrl;
158
+ this.endpoint = `${baseUrl}${endpointPath}`;
159
+ this.logger = config.logger;
160
+ }
161
+ async rawFetch(opts) {
162
+ if (this.verbose) {
163
+ this.logger.debug(`> ${opts.method} ${opts.url}`);
164
+ }
165
+ let response;
166
+ try {
167
+ const init = {
168
+ method: opts.method,
169
+ ...opts.headers !== void 0 && { headers: opts.headers },
170
+ ...opts.body !== void 0 && { body: opts.body },
171
+ ...opts.signal !== void 0 && { signal: opts.signal },
172
+ ...opts.redirect !== void 0 && { redirect: opts.redirect }
173
+ };
174
+ response = await this.fetchImpl(opts.url, init);
175
+ } catch (error) {
176
+ throw new LinkTransportError(
177
+ `Request failed: ${opts.method} ${opts.url}`,
178
+ { cause: error }
179
+ );
180
+ }
181
+ const rawBody = await response.text();
182
+ let data = null;
183
+ try {
184
+ data = JSON.parse(rawBody);
185
+ } catch {
186
+ }
187
+ if (this.verbose) {
188
+ this.logger.debug(`< ${response.status} ${response.statusText}`);
189
+ }
190
+ return { status: response.status, data, rawBody };
191
+ }
192
+ async apiFetch(opts) {
193
+ const token = await this.getAccessToken();
194
+ const authedOpts = {
195
+ ...opts,
196
+ headers: {
197
+ ...opts.headers,
198
+ Authorization: `Bearer ${token}`
199
+ }
200
+ };
201
+ const res = await this.rawFetch(authedOpts);
202
+ if (res.status === 401 && this.canRefreshAccessToken) {
203
+ const refreshedToken = await this.getAccessToken({ forceRefresh: true });
204
+ return this.rawFetch({
205
+ ...opts,
206
+ headers: {
207
+ ...opts.headers,
208
+ Authorization: `Bearer ${refreshedToken}`
209
+ }
210
+ });
211
+ }
212
+ return res;
213
+ }
214
+ throwApiError(operation, status, data, rawBody, cause) {
215
+ const msg = extractErrorMessage(data, rawBody);
216
+ throw new LinkApiError(`Failed to ${operation} (${status}): ${msg}`, {
217
+ status,
218
+ rawBody,
219
+ details: data,
220
+ cause
221
+ });
222
+ }
223
+ parseResponse(operation, status, parser) {
224
+ try {
225
+ return parser();
226
+ } catch (error) {
227
+ throw new LinkResponseError(operation, status, { cause: error });
228
+ }
229
+ }
230
+ };
231
+
232
+ // src/resources/approval-policy.ts
233
+ var approvalPolicySchema = z.looseObject({
234
+ rules: z.array(
235
+ z.looseObject({
236
+ action: z.string(),
237
+ limits: z.looseObject({
238
+ per_purchase: z.looseObject({
239
+ amount: z.number().int(),
240
+ currency: z.string()
241
+ })
242
+ }),
243
+ allowed_payment_methods: z.array(z.string()).optional()
244
+ })
245
+ )
246
+ });
247
+ var ApprovalPolicyResource = class extends BaseResource {
248
+ constructor(options) {
249
+ super(options, "/approval-policy");
250
+ }
251
+ async retrieve() {
252
+ const { status, data, rawBody } = await this.apiFetch({
253
+ method: "GET",
254
+ url: this.endpoint
255
+ });
256
+ if (status < 200 || status >= 300) {
257
+ this.throwApiError("retrieve approval policy", status, data, rawBody);
258
+ }
259
+ return this.parseResponse(
260
+ "retrieve approval policy",
261
+ status,
262
+ () => approvalPolicySchema.parse(data)
263
+ );
264
+ }
265
+ };
266
+
267
+ // src/resources/attestations.ts
268
+ import { createHash as createHash2 } from "crypto";
269
+ import { z as z2 } from "zod";
270
+
48
271
  // src/resources/attestations-crypto.ts
49
272
  import {
50
273
  createHash,
@@ -403,185 +626,6 @@ function computeChallengeDigest(tokenType, issuerName) {
403
626
  return new Uint8Array(createHash("sha256").update(challenge).digest());
404
627
  }
405
628
 
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
629
  // src/resources/attestations.ts
586
630
  var TOKEN_TYPE_BLIND_RSA = 2;
587
631
  var CONTENT_TYPE_TOKEN_REQUEST = "application/private-token-generic-batch-request";
@@ -589,17 +633,17 @@ var CONTENT_TYPE_TOKEN_RESPONSE = "application/private-token-generic-batch-respo
589
633
  var LINK_ISSUER = "https://api.link.com";
590
634
  var LINK_ISSUER_HOSTNAME = "api.link.com";
591
635
  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()
636
+ var issuerMetadataSchema = z2.looseObject({
637
+ issuer: z2.literal(LINK_ISSUER),
638
+ token_issuance_endpoint: z2.string(),
639
+ token_keys: z2.string()
596
640
  });
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()
641
+ var tokenKeyDirectorySchema = z2.looseObject({
642
+ "token-keys": z2.array(
643
+ z2.looseObject({
644
+ "token-type": z2.number(),
645
+ "token-key": z2.string(),
646
+ "not-before": z2.number().int().nonnegative().optional()
603
647
  })
604
648
  )
605
649
  });
@@ -912,20 +956,20 @@ var AttestationsResource = class extends BaseResource {
912
956
  };
913
957
 
914
958
  // 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()
959
+ import { z as z3 } from "zod";
960
+ var currencyAmountsSchema = z3.record(z3.string(), z3.number());
961
+ var balanceSchema = z3.looseObject({
962
+ source_id: z3.string(),
963
+ type: z3.enum(["cash", "credit"]),
964
+ cash: z3.looseObject({ available: currencyAmountsSchema }).nullable().optional(),
965
+ credit: z3.looseObject({ used: currencyAmountsSchema.nullable() }).nullable().optional(),
966
+ current: z3.number(),
967
+ currency: z3.string(),
968
+ as_of: z3.string()
925
969
  });
926
- var balancesPageSchema = z2.looseObject({
927
- data: z2.array(balanceSchema),
928
- has_more: z2.boolean().optional()
970
+ var balancesPageSchema = z3.looseObject({
971
+ data: z3.array(balanceSchema),
972
+ has_more: z3.boolean().optional()
929
973
  });
930
974
  var BalancesResource = class extends BaseResource {
931
975
  constructor(options) {
@@ -966,7 +1010,7 @@ var BalancesResource = class extends BaseResource {
966
1010
  };
967
1011
 
968
1012
  // src/resources/identity-credentials.ts
969
- import { z as z3 } from "zod";
1013
+ import { z as z4 } from "zod";
970
1014
 
971
1015
  // src/resources/holder-jwk.ts
972
1016
  import { createHash as createHash3 } from "crypto";
@@ -1002,14 +1046,14 @@ function parseHolderPublicJwk(value) {
1002
1046
  // src/resources/identity-credentials.ts
1003
1047
  var LINK_ISSUER2 = "https://api.link.com";
1004
1048
  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()
1049
+ var identityCredentialIssuerMetadataSchema = z4.looseObject({
1050
+ issuer: z4.literal(LINK_ISSUER2),
1051
+ credential_endpoint: z4.string()
1008
1052
  });
1009
- var issueIdentityCredentialResponseSchema = z3.looseObject({
1010
- credential: z3.string(),
1011
- issuer: z3.literal(LINK_ISSUER2),
1012
- expires_at: z3.string()
1053
+ var issueIdentityCredentialResponseSchema = z4.looseObject({
1054
+ credential: z4.string(),
1055
+ issuer: z4.literal(LINK_ISSUER2),
1056
+ expires_at: z4.string()
1013
1057
  });
1014
1058
  function requireLinkEndpoint2(value, field) {
1015
1059
  let url;
@@ -1092,16 +1136,23 @@ var IdentityCredentialsResource = class extends BaseResource {
1092
1136
  };
1093
1137
 
1094
1138
  // 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())
1139
+ import { z as z5 } from "zod";
1140
+ var balanceDetailsSchema = z5.looseObject({
1141
+ available_balance: z5.looseObject({
1142
+ amount: z5.number().int(),
1143
+ currency: z5.string()
1144
+ }).optional()
1102
1145
  });
1103
- var paymentMethodsResponseSchema = z4.looseObject({
1104
- payment_details: z4.array(paymentMethodSchema)
1146
+ var paymentMethodSchema = z5.looseObject({
1147
+ id: z5.string(),
1148
+ type: z5.string(),
1149
+ is_default: z5.boolean(),
1150
+ name: z5.string(),
1151
+ nickname: z5.optional(z5.string().nullable()),
1152
+ balance_details: balanceDetailsSchema.nullable().optional()
1153
+ });
1154
+ var paymentMethodsResponseSchema = z5.looseObject({
1155
+ payment_details: z5.array(paymentMethodSchema)
1105
1156
  });
1106
1157
  var PaymentMethodsResource = class extends BaseResource {
1107
1158
  constructor(options) {
@@ -1121,17 +1172,48 @@ var PaymentMethodsResource = class extends BaseResource {
1121
1172
  () => paymentMethodsResponseSchema.parse(data).payment_details
1122
1173
  );
1123
1174
  }
1175
+ async retrieve(id) {
1176
+ const { status, data, rawBody } = await this.apiFetch({
1177
+ method: "GET",
1178
+ url: `${this.endpoint}/${encodeURIComponent(id)}`
1179
+ });
1180
+ if (status === 404) return null;
1181
+ if (status < 200 || status >= 300) {
1182
+ this.throwApiError("retrieve payment method", status, data, rawBody);
1183
+ }
1184
+ return this.parseResponse(
1185
+ "retrieve payment method",
1186
+ status,
1187
+ () => paymentMethodSchema.parse(data)
1188
+ );
1189
+ }
1190
+ async update(id, params) {
1191
+ const { status, data, rawBody } = await this.apiFetch({
1192
+ method: "POST",
1193
+ url: `${this.endpoint}/${encodeURIComponent(id)}`,
1194
+ headers: { "Content-Type": "application/json" },
1195
+ body: JSON.stringify({ nickname: params.nickname })
1196
+ });
1197
+ if (status < 200 || status >= 300) {
1198
+ this.throwApiError("update payment method", status, data, rawBody);
1199
+ }
1200
+ return this.parseResponse(
1201
+ "update payment method",
1202
+ status,
1203
+ () => paymentMethodSchema.parse(data)
1204
+ );
1205
+ }
1124
1206
  };
1125
1207
 
1126
1208
  // 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()
1209
+ import { z as z6 } from "zod";
1210
+ var reportRecordSchema = z6.looseObject({
1211
+ object: z6.string(),
1212
+ created_at: z6.string(),
1213
+ domain: z6.string(),
1214
+ outcome: z6.string(),
1215
+ spend_request_id: z6.string(),
1216
+ status: z6.string()
1135
1217
  });
1136
1218
  var ReportResource = class extends BaseResource {
1137
1219
  constructor(options) {
@@ -1156,15 +1238,15 @@ var ReportResource = class extends BaseResource {
1156
1238
  };
1157
1239
 
1158
1240
  // 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()
1241
+ import { z as z7 } from "zod";
1242
+ var shippingAddressSchema = z7.looseObject({
1243
+ id: z7.string(),
1244
+ is_default: z7.boolean(),
1245
+ nickname: z7.optional(z7.string().nullable()),
1246
+ address: z7.looseObject({}).nullable()
1165
1247
  });
1166
- var shippingAddressesResponseSchema = z6.looseObject({
1167
- shipping_addresses: z6.array(shippingAddressSchema)
1248
+ var shippingAddressesResponseSchema = z7.looseObject({
1249
+ shipping_addresses: z7.array(shippingAddressSchema)
1168
1250
  });
1169
1251
  var ShippingAddressResource = class extends BaseResource {
1170
1252
  constructor(options) {
@@ -1187,21 +1269,21 @@ var ShippingAddressResource = class extends BaseResource {
1187
1269
  };
1188
1270
 
1189
1271
  // 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(),
1272
+ import { z as z8 } from "zod";
1273
+ var nullableRecordSchema = z8.record(z8.string(), z8.unknown()).nullable().optional();
1274
+ var sourceSchema = z8.looseObject({
1275
+ id: z8.string().nullable().optional(),
1276
+ name: z8.string().nullable().optional(),
1277
+ type: z8.string().nullable().optional(),
1196
1278
  capabilities: nullableRecordSchema,
1197
1279
  external_connection: nullableRecordSchema,
1198
- granted_actions: z7.array(z7.string()).nullable().optional(),
1280
+ granted_actions: z8.array(z8.string()).nullable().optional(),
1199
1281
  bank_account: nullableRecordSchema,
1200
1282
  card: nullableRecordSchema
1201
1283
  });
1202
- var sourcesPageSchema = z7.looseObject({
1203
- data: z7.array(sourceSchema),
1204
- has_more: z7.boolean().optional()
1284
+ var sourcesPageSchema = z8.looseObject({
1285
+ data: z8.array(sourceSchema),
1286
+ has_more: z8.boolean().optional()
1205
1287
  });
1206
1288
  var SourcesResource = class extends BaseResource {
1207
1289
  constructor(options) {
@@ -1237,34 +1319,34 @@ var SourcesResource = class extends BaseResource {
1237
1319
  };
1238
1320
 
1239
1321
  // 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() })
1322
+ import { z as z9 } from "zod";
1323
+ var sharedPaymentTokenSchema = z9.union([
1324
+ z9.string().transform((id) => ({ id })),
1325
+ z9.looseObject({ id: z9.string() })
1244
1326
  ]);
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(),
1327
+ var spendRequestSchema = z9.looseObject({
1328
+ id: z9.string(),
1329
+ payment_details: z9.string().optional(),
1330
+ status: z9.string(),
1331
+ line_items: z9.array(z9.unknown()).optional(),
1332
+ totals: z9.array(z9.unknown()).optional(),
1333
+ created_at: z9.string(),
1334
+ updated_at: z9.string(),
1253
1335
  shared_payment_token: sharedPaymentTokenSchema.nullable().optional()
1254
1336
  });
1255
- var spendRequestsResponseSchema = z8.looseObject({
1256
- data: z8.array(spendRequestSchema)
1337
+ var spendRequestsResponseSchema = z9.looseObject({
1338
+ data: z9.array(spendRequestSchema)
1257
1339
  });
1258
- var requestApprovalResponseSchema = z8.looseObject({
1259
- id: z8.string(),
1260
- approval_link: z8.string()
1340
+ var requestApprovalResponseSchema = z9.looseObject({
1341
+ id: z9.string(),
1342
+ approval_link: z9.string()
1261
1343
  }).transform(({ approval_link, ...response }) => ({
1262
1344
  ...response,
1263
1345
  approval_url: approval_link
1264
1346
  }));
1265
- var duplicateSpendRequestErrorSchema = z8.looseObject({
1266
- error: z8.looseObject({
1267
- duplicate_spend_request: z8.unknown().optional()
1347
+ var duplicateSpendRequestErrorSchema = z9.looseObject({
1348
+ error: z9.looseObject({
1349
+ duplicate_spend_request: z9.unknown().optional()
1268
1350
  })
1269
1351
  });
1270
1352
  function parseSpendRequest(value) {
@@ -1383,65 +1465,6 @@ var SpendRequestResource = class extends BaseResource {
1383
1465
  }
1384
1466
  };
1385
1467
 
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
1468
  // src/resources/transactions.ts
1446
1469
  import { z as z10 } from "zod";
1447
1470
  var transactionSchema = z10.looseObject({
@@ -1738,13 +1761,17 @@ var agentWalletVerificationRequirementSchema = z11.object({
1738
1761
  });
1739
1762
  var userInfoAddressSchema = z11.object({
1740
1763
  line1: z11.string().nullable(),
1741
- line2: z11.string().nullable(),
1764
+ line2: z11.string().nullable().optional(),
1742
1765
  city: z11.string().nullable(),
1743
1766
  state: z11.string().nullable(),
1744
1767
  postal_code: z11.string().nullable(),
1745
1768
  country: z11.string().nullable()
1746
- });
1769
+ }).transform(({ line2, ...address }) => ({
1770
+ ...address,
1771
+ ...line2 === void 0 ? {} : { line2 }
1772
+ }));
1747
1773
  var userInfoSchema = z11.looseObject({
1774
+ id: z11.string().min(1).optional(),
1748
1775
  email: z11.string().nullable().optional(),
1749
1776
  name: z11.string().nullable().optional(),
1750
1777
  first_name: z11.string().nullable().optional(),
@@ -1756,6 +1783,7 @@ var userInfoSchema = z11.looseObject({
1756
1783
  agent_wallet_step_up: agentWalletVerificationRequirementSchema.optional()
1757
1784
  }).transform(
1758
1785
  ({
1786
+ id,
1759
1787
  email,
1760
1788
  name,
1761
1789
  first_name,
@@ -1766,6 +1794,7 @@ var userInfoSchema = z11.looseObject({
1766
1794
  agent_wallet_spend_limits,
1767
1795
  agent_wallet_step_up
1768
1796
  }) => ({
1797
+ ...id === void 0 ? {} : { id },
1769
1798
  email: email ?? null,
1770
1799
  name: name ?? null,
1771
1800
  first_name: first_name ?? null,
@@ -1859,10 +1888,10 @@ var Link = class {
1859
1888
  paymentMethods;
1860
1889
  shippingAddresses;
1861
1890
  userInfo;
1891
+ approvalPolicy;
1862
1892
  transactions;
1863
1893
  sources;
1864
1894
  balances;
1865
- summaries;
1866
1895
  webBotAuth;
1867
1896
  reports;
1868
1897
  ucp;
@@ -1873,37 +1902,18 @@ var Link = class {
1873
1902
  this.paymentMethods = new PaymentMethodsResource(options);
1874
1903
  this.shippingAddresses = new ShippingAddressResource(options);
1875
1904
  this.userInfo = new UserInfoResource(options);
1905
+ this.approvalPolicy = new ApprovalPolicyResource(options);
1876
1906
  this.transactions = new TransactionsResource(options);
1877
1907
  this.sources = new SourcesResource(options);
1878
1908
  this.balances = new BalancesResource(options);
1879
- this.summaries = new SummariesResource(options);
1880
1909
  this.webBotAuth = new WebBotAuthResource(options);
1881
1910
  this.reports = new ReportResource(options);
1882
1911
  this.ucp = new UcpResource(options);
1883
1912
  }
1884
1913
  };
1885
1914
  var client_default = Link;
1886
-
1887
- // src/resources/interfaces.ts
1888
- var REPORT_OUTCOMES = ["success", "blocked", "abandoned"];
1889
- var REPORT_TAGS = [
1890
- "stripe_checkout",
1891
- "captcha",
1892
- "anti_bot_script",
1893
- "cdn_block",
1894
- "waf_block",
1895
- "dns_block",
1896
- "rate_limited",
1897
- "login_required",
1898
- "3ds_challenge",
1899
- "page_inaccessible",
1900
- "timeout",
1901
- "site_error",
1902
- "payment_declined",
1903
- "other"
1904
- ];
1905
- var REPORT_ATTEMPT_TRACE_MAX_LENGTH = 8e3;
1906
1915
  export {
1916
+ ApprovalPolicyResource,
1907
1917
  AttestationsResource,
1908
1918
  Link,
1909
1919
  LinkApiError,
@@ -1914,7 +1924,6 @@ export {
1914
1924
  REPORT_ATTEMPT_TRACE_MAX_LENGTH,
1915
1925
  REPORT_OUTCOMES,
1916
1926
  REPORT_TAGS,
1917
- SummariesResource,
1918
1927
  client_default as default,
1919
1928
  getDuplicateSpendRequest,
1920
1929
  holderJwkThumbprint,