@thavguard/arc-pay 0.1.0 → 0.1.2

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.
@@ -2,6 +2,7 @@ type Currency = "RUB" | "KZT" | "UZS";
2
2
  type PaymentMethod = "bank_card" | "sbp" | "sberpay" | "tpay" | "alfapay" | "dolyami" | "mirpay" | "applepay" | "googlepay" | "bnpl";
3
3
  type CaptureMode = "one_stage" | "two_stage";
4
4
  type PaymentFlowMode = "h2h" | "redirect";
5
+ type Locale = "ru" | "en";
5
6
  type PaymentStatus = "created" | "pending" | "pending_3ds" | "authorized" | "captured" | "settled" | "voided" | "expired" | "refunded" | "chargeback" | "declined" | "failed" | "timeout";
6
7
  interface Payment {
7
8
  id: string;
@@ -21,6 +22,7 @@ interface Payment {
21
22
  bank_rrn?: string;
22
23
  bank_internal_ref?: string;
23
24
  bank_auth_code?: string;
25
+ card_token_id?: string;
24
26
  decline_code?: string;
25
27
  card_mask?: string;
26
28
  card_scheme?: string;
@@ -43,6 +45,8 @@ interface CreatePaymentRequest {
43
45
  payment_method: PaymentMethod;
44
46
  external_id: string;
45
47
  capture_mode: CaptureMode;
48
+ save_card?: boolean;
49
+ customer_id?: string;
46
50
  description?: string;
47
51
  success_url?: string;
48
52
  fail_url?: string;
@@ -87,9 +91,14 @@ interface ExecutePaymentRequest {
87
91
  }
88
92
  interface ExecutePaymentResponse {
89
93
  payment_id: string;
90
- status: "authorized" | "captured" | "pending_3ds" | "failed" | "declined";
94
+ status: "authorized" | "captured" | "pending" | "pending_3ds" | "failed" | "declined";
91
95
  authorized_amount?: number;
92
96
  payment_mode?: PaymentFlowMode;
97
+ redirect_url?: string;
98
+ qr_url?: string;
99
+ qr_image_base64?: string;
100
+ qr_content_type?: "image/png" | "image/svg+xml" | string;
101
+ qr_expires_at?: string;
93
102
  liability_shifted?: boolean;
94
103
  requires_3ds?: boolean;
95
104
  acs_url?: string;
@@ -103,6 +112,21 @@ interface ExecutePaymentResponse {
103
112
  decline_code?: string;
104
113
  decline_message?: string;
105
114
  }
115
+ interface ChargeSavedCardRequest {
116
+ amount: number;
117
+ currency: Currency;
118
+ card_token_id: string;
119
+ customer_id: string;
120
+ external_id?: string;
121
+ description?: string;
122
+ metadata?: Record<string, string>;
123
+ fiscal_items?: {
124
+ name: string;
125
+ quantity: number;
126
+ unit_price: number;
127
+ vat_rate: "no_vat" | "vat0" | "vat10" | "vat20";
128
+ }[];
129
+ }
106
130
  interface CompleteThreeDSMethodRequest {
107
131
  completion_indicator: "Y" | "N" | "U";
108
132
  three_ds_server_trans_id: string;
@@ -112,7 +136,13 @@ interface AvailablePaymentMethod {
112
136
  payment_mode: PaymentFlowMode;
113
137
  display_name: string;
114
138
  is_active: boolean;
139
+ unavailable_reason?: string;
115
140
  icon_url?: string;
141
+ supported_currencies?: Currency[];
142
+ supported_countries?: string[];
143
+ min_amount?: number;
144
+ max_amount?: number;
145
+ sandbox_requirements?: string;
116
146
  }
117
147
  interface CreateLinkRequest {
118
148
  link_type: "one_time" | "reusable" | "invoice" | "recurring";
@@ -123,6 +153,7 @@ interface CreateLinkRequest {
123
153
  max_uses?: number;
124
154
  expires_at?: string;
125
155
  customer_name?: string;
156
+ customer_id?: string;
126
157
  customer_email?: string;
127
158
  due_date?: string;
128
159
  redirect_url?: string;
@@ -131,6 +162,7 @@ interface CreateLinkRequest {
131
162
  metadata?: Record<string, string>;
132
163
  capture_mode: CaptureMode;
133
164
  autocompletion_date?: string;
165
+ locale?: Locale;
134
166
  payment_methods: {
135
167
  method: PaymentMethod;
136
168
  payment_mode: PaymentFlowMode;
@@ -166,6 +198,7 @@ interface Link {
166
198
  uses_count?: number;
167
199
  expires_at?: string;
168
200
  customer_name?: string;
201
+ customer_id?: string;
169
202
  customer_email?: string;
170
203
  due_date?: string;
171
204
  external_order_id?: string;
@@ -191,6 +224,7 @@ interface Link {
191
224
  metadata?: Record<string, string>;
192
225
  capture_mode: CaptureMode;
193
226
  autocompletion_date?: string;
227
+ locale?: Locale;
194
228
  }
195
229
  interface CreateCheckoutSessionRequest {
196
230
  amount: number;
@@ -205,9 +239,11 @@ interface CreateCheckoutSessionRequest {
205
239
  fail_url?: string;
206
240
  cancel_url?: string;
207
241
  customer_email?: string;
242
+ customer_id?: string;
208
243
  external_id?: string;
209
244
  metadata?: Record<string, string>;
210
245
  autocompletion_date?: string;
246
+ locale?: Locale;
211
247
  }
212
248
  interface CheckoutSession {
213
249
  id: string;
@@ -252,13 +288,16 @@ declare class ArcPayClient {
252
288
  capturePayment(paymentId: string, body: CaptureRequest, opts: IdempotencyOptions): Promise<Payment>;
253
289
  voidPayment(paymentId: string, body: VoidRequest, opts: IdempotencyOptions): Promise<Payment>;
254
290
  createRefund(paymentId: string, body: CreateRefundRequest, opts: IdempotencyOptions): Promise<Refund>;
291
+ chargeSavedCard(body: ChargeSavedCardRequest, opts: IdempotencyOptions): Promise<ExecutePaymentResponse>;
255
292
  executePayment(paymentId: string, body: ExecutePaymentRequest, opts: IdempotencyOptions): Promise<ExecutePaymentResponse>;
256
293
  completeThreeDSMethod(paymentId: string, body: CompleteThreeDSMethodRequest, opts?: RequestOptions): Promise<ExecutePaymentResponse>;
257
294
  listAvailablePaymentMethods(query: ListAvailablePaymentMethodsQuery, opts?: RequestOptions): Promise<AvailablePaymentMethod[]>;
258
295
  createLink(body: CreateLinkRequest, opts: IdempotencyOptions): Promise<Link>;
296
+ getLink(linkId: string, opts?: RequestOptions): Promise<Link>;
297
+ cancelLink(linkId: string, opts?: RequestOptions): Promise<Link>;
259
298
  createCheckoutSession(body: CreateCheckoutSessionRequest, opts: IdempotencyOptions): Promise<CheckoutSession>;
260
299
  private request;
261
300
  }
262
301
  declare const createArcPayClient: (options: ArcPayClientOptions) => ArcPayClient;
263
302
 
264
- export { ArcPayClient, type ArcPayClientOptions, type AvailablePaymentMethod, type CaptureRequest, type CheckoutSession, type CompleteThreeDSMethodRequest, type CreateCheckoutSessionRequest, type CreateLinkRequest, type CreatePaymentRequest, type CreateRefundRequest, type ExecutePaymentRequest, type ExecutePaymentResponse, type IdempotencyOptions, type Link, type ListAvailablePaymentMethodsQuery, type ListPaymentsQuery, type Payment, type PaymentFlowMode, type PaymentList, type PaymentMethod, type Refund, type RequestOptions, type VoidRequest, createArcPayClient };
303
+ export { ArcPayClient, type ArcPayClientOptions, type AvailablePaymentMethod, type CaptureRequest, type ChargeSavedCardRequest, type CheckoutSession, type CompleteThreeDSMethodRequest, type CreateCheckoutSessionRequest, type CreateLinkRequest, type CreatePaymentRequest, type CreateRefundRequest, type ExecutePaymentRequest, type ExecutePaymentResponse, type IdempotencyOptions, type Link, type ListAvailablePaymentMethodsQuery, type ListPaymentsQuery, type Payment, type PaymentFlowMode, type PaymentList, type PaymentMethod, type Refund, type RequestOptions, type VoidRequest, createArcPayClient };
@@ -2,6 +2,7 @@ type Currency = "RUB" | "KZT" | "UZS";
2
2
  type PaymentMethod = "bank_card" | "sbp" | "sberpay" | "tpay" | "alfapay" | "dolyami" | "mirpay" | "applepay" | "googlepay" | "bnpl";
3
3
  type CaptureMode = "one_stage" | "two_stage";
4
4
  type PaymentFlowMode = "h2h" | "redirect";
5
+ type Locale = "ru" | "en";
5
6
  type PaymentStatus = "created" | "pending" | "pending_3ds" | "authorized" | "captured" | "settled" | "voided" | "expired" | "refunded" | "chargeback" | "declined" | "failed" | "timeout";
6
7
  interface Payment {
7
8
  id: string;
@@ -21,6 +22,7 @@ interface Payment {
21
22
  bank_rrn?: string;
22
23
  bank_internal_ref?: string;
23
24
  bank_auth_code?: string;
25
+ card_token_id?: string;
24
26
  decline_code?: string;
25
27
  card_mask?: string;
26
28
  card_scheme?: string;
@@ -43,6 +45,8 @@ interface CreatePaymentRequest {
43
45
  payment_method: PaymentMethod;
44
46
  external_id: string;
45
47
  capture_mode: CaptureMode;
48
+ save_card?: boolean;
49
+ customer_id?: string;
46
50
  description?: string;
47
51
  success_url?: string;
48
52
  fail_url?: string;
@@ -87,9 +91,14 @@ interface ExecutePaymentRequest {
87
91
  }
88
92
  interface ExecutePaymentResponse {
89
93
  payment_id: string;
90
- status: "authorized" | "captured" | "pending_3ds" | "failed" | "declined";
94
+ status: "authorized" | "captured" | "pending" | "pending_3ds" | "failed" | "declined";
91
95
  authorized_amount?: number;
92
96
  payment_mode?: PaymentFlowMode;
97
+ redirect_url?: string;
98
+ qr_url?: string;
99
+ qr_image_base64?: string;
100
+ qr_content_type?: "image/png" | "image/svg+xml" | string;
101
+ qr_expires_at?: string;
93
102
  liability_shifted?: boolean;
94
103
  requires_3ds?: boolean;
95
104
  acs_url?: string;
@@ -103,6 +112,21 @@ interface ExecutePaymentResponse {
103
112
  decline_code?: string;
104
113
  decline_message?: string;
105
114
  }
115
+ interface ChargeSavedCardRequest {
116
+ amount: number;
117
+ currency: Currency;
118
+ card_token_id: string;
119
+ customer_id: string;
120
+ external_id?: string;
121
+ description?: string;
122
+ metadata?: Record<string, string>;
123
+ fiscal_items?: {
124
+ name: string;
125
+ quantity: number;
126
+ unit_price: number;
127
+ vat_rate: "no_vat" | "vat0" | "vat10" | "vat20";
128
+ }[];
129
+ }
106
130
  interface CompleteThreeDSMethodRequest {
107
131
  completion_indicator: "Y" | "N" | "U";
108
132
  three_ds_server_trans_id: string;
@@ -112,7 +136,13 @@ interface AvailablePaymentMethod {
112
136
  payment_mode: PaymentFlowMode;
113
137
  display_name: string;
114
138
  is_active: boolean;
139
+ unavailable_reason?: string;
115
140
  icon_url?: string;
141
+ supported_currencies?: Currency[];
142
+ supported_countries?: string[];
143
+ min_amount?: number;
144
+ max_amount?: number;
145
+ sandbox_requirements?: string;
116
146
  }
117
147
  interface CreateLinkRequest {
118
148
  link_type: "one_time" | "reusable" | "invoice" | "recurring";
@@ -123,6 +153,7 @@ interface CreateLinkRequest {
123
153
  max_uses?: number;
124
154
  expires_at?: string;
125
155
  customer_name?: string;
156
+ customer_id?: string;
126
157
  customer_email?: string;
127
158
  due_date?: string;
128
159
  redirect_url?: string;
@@ -131,6 +162,7 @@ interface CreateLinkRequest {
131
162
  metadata?: Record<string, string>;
132
163
  capture_mode: CaptureMode;
133
164
  autocompletion_date?: string;
165
+ locale?: Locale;
134
166
  payment_methods: {
135
167
  method: PaymentMethod;
136
168
  payment_mode: PaymentFlowMode;
@@ -166,6 +198,7 @@ interface Link {
166
198
  uses_count?: number;
167
199
  expires_at?: string;
168
200
  customer_name?: string;
201
+ customer_id?: string;
169
202
  customer_email?: string;
170
203
  due_date?: string;
171
204
  external_order_id?: string;
@@ -191,6 +224,7 @@ interface Link {
191
224
  metadata?: Record<string, string>;
192
225
  capture_mode: CaptureMode;
193
226
  autocompletion_date?: string;
227
+ locale?: Locale;
194
228
  }
195
229
  interface CreateCheckoutSessionRequest {
196
230
  amount: number;
@@ -205,9 +239,11 @@ interface CreateCheckoutSessionRequest {
205
239
  fail_url?: string;
206
240
  cancel_url?: string;
207
241
  customer_email?: string;
242
+ customer_id?: string;
208
243
  external_id?: string;
209
244
  metadata?: Record<string, string>;
210
245
  autocompletion_date?: string;
246
+ locale?: Locale;
211
247
  }
212
248
  interface CheckoutSession {
213
249
  id: string;
@@ -252,13 +288,16 @@ declare class ArcPayClient {
252
288
  capturePayment(paymentId: string, body: CaptureRequest, opts: IdempotencyOptions): Promise<Payment>;
253
289
  voidPayment(paymentId: string, body: VoidRequest, opts: IdempotencyOptions): Promise<Payment>;
254
290
  createRefund(paymentId: string, body: CreateRefundRequest, opts: IdempotencyOptions): Promise<Refund>;
291
+ chargeSavedCard(body: ChargeSavedCardRequest, opts: IdempotencyOptions): Promise<ExecutePaymentResponse>;
255
292
  executePayment(paymentId: string, body: ExecutePaymentRequest, opts: IdempotencyOptions): Promise<ExecutePaymentResponse>;
256
293
  completeThreeDSMethod(paymentId: string, body: CompleteThreeDSMethodRequest, opts?: RequestOptions): Promise<ExecutePaymentResponse>;
257
294
  listAvailablePaymentMethods(query: ListAvailablePaymentMethodsQuery, opts?: RequestOptions): Promise<AvailablePaymentMethod[]>;
258
295
  createLink(body: CreateLinkRequest, opts: IdempotencyOptions): Promise<Link>;
296
+ getLink(linkId: string, opts?: RequestOptions): Promise<Link>;
297
+ cancelLink(linkId: string, opts?: RequestOptions): Promise<Link>;
259
298
  createCheckoutSession(body: CreateCheckoutSessionRequest, opts: IdempotencyOptions): Promise<CheckoutSession>;
260
299
  private request;
261
300
  }
262
301
  declare const createArcPayClient: (options: ArcPayClientOptions) => ArcPayClient;
263
302
 
264
- export { ArcPayClient, type ArcPayClientOptions, type AvailablePaymentMethod, type CaptureRequest, type CheckoutSession, type CompleteThreeDSMethodRequest, type CreateCheckoutSessionRequest, type CreateLinkRequest, type CreatePaymentRequest, type CreateRefundRequest, type ExecutePaymentRequest, type ExecutePaymentResponse, type IdempotencyOptions, type Link, type ListAvailablePaymentMethodsQuery, type ListPaymentsQuery, type Payment, type PaymentFlowMode, type PaymentList, type PaymentMethod, type Refund, type RequestOptions, type VoidRequest, createArcPayClient };
303
+ export { ArcPayClient, type ArcPayClientOptions, type AvailablePaymentMethod, type CaptureRequest, type ChargeSavedCardRequest, type CheckoutSession, type CompleteThreeDSMethodRequest, type CreateCheckoutSessionRequest, type CreateLinkRequest, type CreatePaymentRequest, type CreateRefundRequest, type ExecutePaymentRequest, type ExecutePaymentResponse, type IdempotencyOptions, type Link, type ListAvailablePaymentMethodsQuery, type ListPaymentsQuery, type Payment, type PaymentFlowMode, type PaymentList, type PaymentMethod, type Refund, type RequestOptions, type VoidRequest, createArcPayClient };
@@ -35,6 +35,7 @@ function validateSecretKey(key) {
35
35
  }
36
36
  }
37
37
  var normalizeBase = (base) => base.replace(/\/+$/, "");
38
+ var normalizeRequestOptions = (opts) => opts != null ? opts : {};
38
39
  var requireIdempotencyKey = (opts) => {
39
40
  if (!opts.idempotencyKey) {
40
41
  throw new ArcPayError({
@@ -97,26 +98,53 @@ var ArcPayClient = class {
97
98
  return this.request("GET", appendQuery("/payments", query), void 0, opts);
98
99
  }
99
100
  async createPayment(body, opts) {
100
- return this.request("POST", "/payments", body, opts);
101
+ return this.request("POST", "/payments", body, opts, true);
101
102
  }
102
103
  async getPayment(paymentId, opts = {}) {
103
- return this.request("GET", `/payments/${encodeURIComponent(paymentId)}`, void 0, opts);
104
+ return this.request(
105
+ "GET",
106
+ `/payments/${encodeURIComponent(paymentId)}`,
107
+ void 0,
108
+ opts
109
+ );
104
110
  }
105
111
  async capturePayment(paymentId, body, opts) {
106
- return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/capture`, body, opts);
112
+ return this.request(
113
+ "POST",
114
+ `/payments/${encodeURIComponent(paymentId)}/capture`,
115
+ body,
116
+ opts,
117
+ true
118
+ );
107
119
  }
108
120
  async voidPayment(paymentId, body, opts) {
109
- return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/void`, body, opts);
121
+ return this.request(
122
+ "POST",
123
+ `/payments/${encodeURIComponent(paymentId)}/void`,
124
+ body,
125
+ opts,
126
+ true
127
+ );
110
128
  }
111
129
  async createRefund(paymentId, body, opts) {
112
- return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/refunds`, body, opts);
130
+ return this.request(
131
+ "POST",
132
+ `/payments/${encodeURIComponent(paymentId)}/refunds`,
133
+ body,
134
+ opts,
135
+ true
136
+ );
137
+ }
138
+ async chargeSavedCard(body, opts) {
139
+ return this.request("POST", "/payments/saved-card", body, opts, true);
113
140
  }
114
141
  async executePayment(paymentId, body, opts) {
115
142
  return this.request(
116
143
  "POST",
117
144
  `/payments/${encodeURIComponent(paymentId)}/execute`,
118
145
  body,
119
- opts
146
+ opts,
147
+ true
120
148
  );
121
149
  }
122
150
  async completeThreeDSMethod(paymentId, body, opts = {}) {
@@ -136,19 +164,28 @@ var ArcPayClient = class {
136
164
  );
137
165
  }
138
166
  async createLink(body, opts) {
139
- return this.request("POST", "/links", body, opts);
167
+ return this.request("POST", "/links", body, opts, true);
168
+ }
169
+ async getLink(linkId, opts = {}) {
170
+ return this.request("GET", `/links/${encodeURIComponent(linkId)}`, void 0, opts);
171
+ }
172
+ async cancelLink(linkId, opts = {}) {
173
+ return this.request("DELETE", `/links/${encodeURIComponent(linkId)}`, void 0, opts);
140
174
  }
141
175
  async createCheckoutSession(body, opts) {
142
- return this.request("POST", "/checkout/sessions", body, opts);
176
+ return this.request("POST", "/checkout/sessions", body, opts, true);
143
177
  }
144
- async request(method, path, body, opts) {
178
+ async request(method, path, body, opts = void 0, requireIdempotency = false) {
179
+ const requestOpts = normalizeRequestOptions(opts);
145
180
  const headers = {
146
181
  Authorization: `Bearer ${this.secretKey}`,
147
182
  "X-Arc-Pay-API-Version": API_VERSION,
148
183
  "Content-Type": "application/json"
149
184
  };
150
- if ("idempotencyKey" in opts) {
151
- headers["Idempotency-Key"] = requireIdempotencyKey(opts);
185
+ if (requireIdempotency) {
186
+ headers["Idempotency-Key"] = requireIdempotencyKey(requestOpts);
187
+ } else if (requestOpts.idempotencyKey !== void 0) {
188
+ headers["Idempotency-Key"] = requireIdempotencyKey(requestOpts);
152
189
  }
153
190
  let res;
154
191
  try {
@@ -156,7 +193,7 @@ var ArcPayClient = class {
156
193
  method,
157
194
  headers,
158
195
  body: body === void 0 ? void 0 : JSON.stringify(body),
159
- signal: opts.signal
196
+ signal: requestOpts.signal
160
197
  });
161
198
  } catch (err) {
162
199
  throw new ArcPayError({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/errors.ts","../../src/server/client.ts"],"names":[],"mappings":";AAqBO,IAAM,WAAA,GAAN,cAA0B,KAAA,CAAM;AAAA,EASrC,YAAY,IAAA,EAAuB;AACjC,IAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,IAAA,IAAA,CAAK,IAAA,GAAO,aAAA;AACZ,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,QAAQ,IAAA,CAAK,KAAA;AAClB,IAAA,IAAA,CAAK,YAAY,IAAA,CAAK,SAAA;AACtB,IAAA,IAAA,CAAK,cAAc,IA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AAA;AACJ,IAAA,IAAI;AACF,MAAA,GAAA,GAAM,MAAM,KAAK,SAAA,CAAU,CAAA,EAAG,KAAK,OAAO,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI;AAAA,QACnD,MAAA;AAAA,QACA,OAAA;AAAA,QACA,MAAM,IAAA,KAAS,KAAA,CAAA,GAAY,KAAA,CAAA,GAAY,IAAA,CAAK,UAAU,IAAI,CAAA;AAAA,QAC1D,QAAQ,IAAA,CAAK;AAAA,OACd,CAAA;AAAA,IACH,SAAS,GAAA,EAAK;AACZ,MAAA,MAAM,IAAI,WAAA,CAAY;AAAA,QACpB,IAAA,EAAM,eAAA;AAAA,QACN,OAAA,EAAS,GAAA,YAAe,KAAA,GAAQ,GAAA,CAAI,OAAA,GAAU,wBAAA;AAAA,QAC9C,SAAA,EAAW;AAAA,OACZ,CAAA;AAAA,IACH;AACA,IAAA,IAAI,CAAC,GAAA,CAAI,EAAA,EAAI,MAAM,MAAM,mBAAmB,GAAG,CAAA;AAC/C,IAAA,OAAQ,MAAM,IAAI,IAAA,EAAK;AAAA,EACzB;AACF;AAEO,IAAM,kBAAA,GAAqB,CAAC,OAAA,KACjC,IAAI,aAAa,OAAO","file":"index.mjs","sourcesContent":["export type ArcPayErrorType =\n | \"validation_error\"\n | \"authentication_error\"\n | \"authorization_error\"\n | \"state_error\"\n | \"rate_limit_error\"\n | \"api_error\"\n | \"network_error\"\n | \"challenge_aborted\";\n\nexport interface ArcPayErrorInit {\n type: ArcPayErrorType;\n message: string;\n code?: string;\n param?: string;\n paymentId?: string;\n declineCode?: string;\n retryable: boolean;\n requestId?: string;\n}\n\nexport class ArcPayError extends Error {\n readonly type: ArcPayErrorType;\n readonly code?: string;\n readonly param?: string;\n readonly paymentId?: string;\n readonly declineCode?: string;\n readonly retryable: boolean;\n readonly requestId?: string;\n\n constructor(init: ArcPayErrorInit) {\n super(init.message);\n this.name = \"ArcPayError\";\n this.type = init.type;\n this.code = init.code;\n this.param = init.param;\n this.paymentId = init.paymentId;\n this.declineCode = init.declineCode;\n this.retryable = init.retryable;\n this.requestId = init.requestId;\n }\n}\n\nexport const isValidationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"validation_error\";\nexport const isAuthenticationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"authentication_error\";\nexport const isAuthorizationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"authorization_error\";\nexport const isStateError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"state_error\";\nexport const isRateLimitError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"rate_limit_error\";\nexport const isApiError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"api_error\";\nexport const isNetworkError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"network_error\";\nexport const isChallengeAborted = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"challenge_aborted\";\n","import { ArcPayError, type ArcPayErrorType } from \"../core/errors\";\nimport type {\n AvailablePaymentMethod,\n CaptureRequest,\n CheckoutSession,\n CompleteThreeDSMethodRequest,\n CreateCheckoutSessionRequest,\n CreateLinkRequest,\n CreatePaymentRequest,\n CreateRefundRequest,\n ExecutePaymentRequest,\n ExecutePaymentResponse,\n Link,\n ListAvailablePaymentMethodsQuery,\n ListPaymentsQuery,\n Payment,\n PaymentList,\n Refund,\n VoidRequest,\n} from \"./types\";\n\nexport type {\n AvailablePaymentMethod,\n CaptureMode,\n CaptureRequest,\n CheckoutSession,\n CompleteThreeDSMethodRequest,\n CreateCheckoutSessionRequest,\n CreateLinkRequest,\n CreatePaymentRequest,\n CreateRefundRequest,\n Currency,\n ExecutePaymentRequest,\n ExecutePaymentResponse,\n Link,\n ListAvailablePaymentMethodsQuery,\n ListPaymentsQuery,\n Payment,\n PaymentFlowMode,\n PaymentList,\n PaymentMethod,\n PaymentStatus,\n Refund,\n VoidRequest,\n} from \"./types\";\n\nexport interface ArcPayClientOptions {\n secretKey: string;\n apiBase?: string;\n fetch?: typeof fetch;\n}\n\nexport interface IdempotencyOptions {\n idempotencyKey: string;\n signal?: AbortSignal;\n}\n\nexport interface RequestOptions {\n signal?: AbortSignal;\n}\n\nconst DEFAULT_API_BASE = \"https://api.arcpay.space/v1\";\nconst API_VERSION = \"2026-05-06\";\n\nfunction validateSecretKey(key: unknown): asserts key is string {\n if (typeof key !== \"string\" || key.length === 0) {\n throw new ArcPayError({\n type: \"authentication_error\",\n code: \"invalid_secret_key\",\n message: \"Secret key must be a non-empty string\",\n retryable: false,\n });\n }\n if (!key.startsWith(\"sk_test_\") && !key.startsWith(\"sk_live_\")) {\n throw new ArcPayError({\n type: \"authentication_error\",\n code: \"invalid_secret_key\",\n message: \"Secret key must start with sk_test_ or sk_live_. Publishable keys cannot call server APIs.\",\n retryable: false,\n });\n }\n}\n\nconst normalizeBase = (base: string): string => base.replace(/\\/+$/, \"\");\n\nconst requireIdempotencyKey = (opts: IdempotencyOptions): string => {\n if (!opts.idempotencyKey) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"missing_idempotency_key\",\n message: \"idempotencyKey is required for this operation\",\n retryable: false,\n });\n }\n return opts.idempotencyKey;\n};\n\nconst appendQuery = (path: string, query?: object): string => {\n if (!query) return path;\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined || value === null || value === \"\") continue;\n params.set(key, String(value));\n }\n const encoded = params.toString();\n return encoded ? `${path}?${encoded}` : path;\n};\n\ninterface APIErrorBody {\n error?: {\n type?: string;\n code?: string;\n message?: string;\n param?: string;\n request_id?: string;\n decline_code?: string;\n };\n}\n\nconst isPublicErrorType = (value: unknown): value is ArcPayErrorType =>\n value === \"validation_error\" ||\n value === \"authentication_error\" ||\n value === \"authorization_error\" ||\n value === \"state_error\" ||\n value === \"rate_limit_error\" ||\n value === \"api_error\";\n\nconst parseErrorResponse = async (res: Response): Promise<ArcPayError> => {\n let body: APIErrorBody = {};\n try {\n body = (await res.json()) as APIErrorBody;\n } catch {\n /* keep default error below */\n }\n const detail = body.error ?? {};\n const type = isPublicErrorType(detail.type)\n ? detail.type\n : res.status >= 500\n ? \"api_error\"\n : \"validation_error\";\n return new ArcPayError({\n type,\n code: detail.code,\n message: detail.message ?? `Request failed with status ${res.status}`,\n param: detail.param,\n requestId: detail.request_id,\n declineCode: detail.decline_code,\n retryable: type === \"api_error\" || type === \"rate_limit_error\",\n });\n};\n\nexport class ArcPayClient {\n private readonly secretKey: string;\n private readonly apiBase: string;\n private readonly fetchImpl: typeof fetch;\n\n constructor(options: ArcPayClientOptions) {\n const secretKey: unknown = options.secretKey;\n validateSecretKey(secretKey);\n if (!options.fetch && typeof fetch === \"undefined\") {\n throw new ArcPayError({\n type: \"api_error\",\n code: \"fetch_unavailable\",\n message: \"A fetch implementation is required in this runtime\",\n retryable: false,\n });\n }\n this.secretKey = secretKey;\n this.apiBase = normalizeBase(options.apiBase ?? DEFAULT_API_BASE);\n this.fetchImpl = options.fetch ?? fetch;\n }\n\n async listPayments(query: ListPaymentsQuery = {}, opts: RequestOptions = {}): Promise<PaymentList> {\n return this.request<PaymentList>(\"GET\", appendQuery(\"/payments\", query), undefined, opts);\n }\n\n async createPayment(body: CreatePaymentRequest, opts: IdempotencyOptions): Promise<Payment> {\n return this.request<Payment>(\"POST\", \"/payments\", body, opts);\n }\n\n async getPayment(paymentId: string, opts: RequestOptions = {}): Promise<Payment> {\n return this.request<Payment>(\"GET\", `/payments/${encodeURIComponent(paymentId)}`, undefined, opts);\n }\n\n async capturePayment(\n paymentId: string,\n body: CaptureRequest,\n opts: IdempotencyOptions,\n ): Promise<Payment> {\n return this.request<Payment>(\"POST\", `/payments/${encodeURIComponent(paymentId)}/capture`, body, opts);\n }\n\n async voidPayment(\n paymentId: string,\n body: VoidRequest,\n opts: IdempotencyOptions,\n ): Promise<Payment> {\n return this.request<Payment>(\"POST\", `/payments/${encodeURIComponent(paymentId)}/void`, body, opts);\n }\n\n async createRefund(\n paymentId: string,\n body: CreateRefundRequest,\n opts: IdempotencyOptions,\n ): Promise<Refund> {\n return this.request<Refund>(\"POST\", `/payments/${encodeURIComponent(paymentId)}/refunds`, body, opts);\n }\n\n async executePayment(\n paymentId: string,\n body: ExecutePaymentRequest,\n opts: IdempotencyOptions,\n ): Promise<ExecutePaymentResponse> {\n return this.request<ExecutePaymentResponse>(\n \"POST\",\n `/payments/${encodeURIComponent(paymentId)}/execute`,\n body,\n opts,\n );\n }\n\n async completeThreeDSMethod(\n paymentId: string,\n body: CompleteThreeDSMethodRequest,\n opts: RequestOptions = {},\n ): Promise<ExecutePaymentResponse> {\n return this.request<ExecutePaymentResponse>(\n \"POST\",\n `/payments/${encodeURIComponent(paymentId)}/complete-3ds-method`,\n body,\n opts,\n );\n }\n\n async listAvailablePaymentMethods(\n query: ListAvailablePaymentMethodsQuery,\n opts: RequestOptions = {},\n ): Promise<AvailablePaymentMethod[]> {\n return this.request<AvailablePaymentMethod[]>(\n \"GET\",\n appendQuery(\"/payment-methods/available\", query),\n undefined,\n opts,\n );\n }\n\n async createLink(body: CreateLinkRequest, opts: IdempotencyOptions): Promise<Link> {\n return this.request<Link>(\"POST\", \"/links\", body, opts);\n }\n\n async createCheckoutSession(\n body: CreateCheckoutSessionRequest,\n opts: IdempotencyOptions,\n ): Promise<CheckoutSession> {\n return this.request<CheckoutSession>(\"POST\", \"/checkout/sessions\", body, opts);\n }\n\n private async request<T>(\n method: \"GET\" | \"POST\",\n path: string,\n body: unknown,\n opts: RequestOptions | IdempotencyOptions,\n ): Promise<T> {\n const headers: Record<string, string> = {\n Authorization: `Bearer ${this.secretKey}`,\n \"X-Arc-Pay-API-Version\": API_VERSION,\n \"Content-Type\": \"application/json\",\n };\n if (\"idempotencyKey\" in opts) {\n headers[\"Idempotency-Key\"] = requireIdempotencyKey(opts);\n }\n\n let res: Response;\n try {\n res = await this.fetchImpl(`${this.apiBase}${path}`, {\n method,\n headers,\n body: body === undefined ? undefined : JSON.stringify(body),\n signal: opts.signal,\n });\n } catch (err) {\n throw new ArcPayError({\n type: \"network_error\",\n message: err instanceof Error ? err.message : \"Network request failed\",\n retryable: true,\n });\n }\n if (!res.ok) throw await parseErrorResponse(res);\n return (await res.json()) as T;\n }\n}\n\nexport const createArcPayClient = (options: ArcPayClientOptions): ArcPayClient =>\n new ArcPayClient(options);\n"]}
1
+ {"version":3,"sources":["../../src/core/errors.ts","../../src/server/client.ts"],"names":[],"mappings":";AAqBO,IAAM,WAAA,GAAN,cAA0B,KAAA,CAAM;AAAA,EASrC,YAAY,IAAA,EAAuB;AACjC,IAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,IAAA,IAAA,CAAK,IAAA,GAAO,aAAA;AACZ,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,QAAQ,IAAA,CAAK,KAAA;AAClB,IAAA,IAAA,CAAK,YAAY,IAAA,CAAK,SAAA;AACtB,IAAA,IAAA,CAAK,cAAc,IAAA,CAAK,WAAA;AACxB,IAAA,IAAA,CAAK,YAAY,IAAA,CAAK,SAAA;AACtB,IAAA,IAAA,CAAK,YAAY,IAAA,CAAK,SAAA;AAAA,EACxB;AACF,CAAA;;;ACwBA,IAAM,gBAAA,GAAmB,6BAAA;AACzB,IAAM,WAAA,GAAc,YAAA;AAEpB,SAAS,kBAAkB,GAAA,EAAqC;AAC9D,EAAA,IAAI,OAAO,GAAA,KAAQ,QAAA,IAAY,GAAA,CAAI,WAAW,CAAA,EAAG;AAC/C,IAAA,MAAM,IAAI,WAAA,CAAY;AAAA,MACpB,IAAA,EAAM,sBAAA;AAAA,MACN,IAAA,EAAM,oBAAA;AAAA,MACN,OAAA,EAAS,uCAAA;AAAA,MACT,SAAA,EAAW;AAAA,KACZ,CAAA;AAAA,EACH;AACA,EAAA,IAAI,CAAC,IAAI,UAAA,CAAW,UAAU,KAAK,CAA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AAqB,CAAC,OAAA,KACjC,IAAI,aAAa,OAAO","file":"index.mjs","sourcesContent":["export type ArcPayErrorType =\n | \"validation_error\"\n | \"authentication_error\"\n | \"authorization_error\"\n | \"state_error\"\n | \"rate_limit_error\"\n | \"api_error\"\n | \"network_error\"\n | \"challenge_aborted\";\n\nexport interface ArcPayErrorInit {\n type: ArcPayErrorType;\n message: string;\n code?: string;\n param?: string;\n paymentId?: string;\n declineCode?: string;\n retryable: boolean;\n requestId?: string;\n}\n\nexport class ArcPayError extends Error {\n readonly type: ArcPayErrorType;\n readonly code?: string;\n readonly param?: string;\n readonly paymentId?: string;\n readonly declineCode?: string;\n readonly retryable: boolean;\n readonly requestId?: string;\n\n constructor(init: ArcPayErrorInit) {\n super(init.message);\n this.name = \"ArcPayError\";\n this.type = init.type;\n this.code = init.code;\n this.param = init.param;\n this.paymentId = init.paymentId;\n this.declineCode = init.declineCode;\n this.retryable = init.retryable;\n this.requestId = init.requestId;\n }\n}\n\nexport const isValidationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"validation_error\";\nexport const isAuthenticationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"authentication_error\";\nexport const isAuthorizationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"authorization_error\";\nexport const isStateError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"state_error\";\nexport const isRateLimitError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"rate_limit_error\";\nexport const isApiError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"api_error\";\nexport const isNetworkError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"network_error\";\nexport const isChallengeAborted = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"challenge_aborted\";\n","import { ArcPayError, type ArcPayErrorType } from \"../core/errors\";\nimport type {\n AvailablePaymentMethod,\n CaptureRequest,\n ChargeSavedCardRequest,\n CheckoutSession,\n CompleteThreeDSMethodRequest,\n CreateCheckoutSessionRequest,\n CreateLinkRequest,\n CreatePaymentRequest,\n CreateRefundRequest,\n ExecutePaymentRequest,\n ExecutePaymentResponse,\n Link,\n ListAvailablePaymentMethodsQuery,\n ListPaymentsQuery,\n Payment,\n PaymentList,\n Refund,\n VoidRequest,\n} from \"./types\";\n\nexport type {\n AvailablePaymentMethod,\n CaptureMode,\n CaptureRequest,\n ChargeSavedCardRequest,\n CheckoutSession,\n CompleteThreeDSMethodRequest,\n CreateCheckoutSessionRequest,\n CreateLinkRequest,\n CreatePaymentRequest,\n CreateRefundRequest,\n Currency,\n ExecutePaymentRequest,\n ExecutePaymentResponse,\n Link,\n ListAvailablePaymentMethodsQuery,\n ListPaymentsQuery,\n Payment,\n PaymentFlowMode,\n PaymentList,\n PaymentMethod,\n PaymentStatus,\n Refund,\n VoidRequest,\n} from \"./types\";\n\nexport interface ArcPayClientOptions {\n secretKey: string;\n apiBase?: string;\n fetch?: typeof fetch;\n}\n\nexport interface IdempotencyOptions {\n idempotencyKey: string;\n signal?: AbortSignal;\n}\n\ntype RequestOptionsInput = RequestOptions | IdempotencyOptions | null | undefined;\n\nexport interface RequestOptions {\n signal?: AbortSignal;\n}\n\nconst DEFAULT_API_BASE = \"https://api.arcpay.space/v1\";\nconst API_VERSION = \"2026-05-06\";\n\nfunction validateSecretKey(key: unknown): asserts key is string {\n if (typeof key !== \"string\" || key.length === 0) {\n throw new ArcPayError({\n type: \"authentication_error\",\n code: \"invalid_secret_key\",\n message: \"Secret key must be a non-empty string\",\n retryable: false,\n });\n }\n if (!key.startsWith(\"sk_test_\") && !key.startsWith(\"sk_live_\")) {\n throw new ArcPayError({\n type: \"authentication_error\",\n code: \"invalid_secret_key\",\n message:\n \"Secret key must start with sk_test_ or sk_live_. Publishable keys cannot call server APIs.\",\n retryable: false,\n });\n }\n}\n\nconst normalizeBase = (base: string): string => base.replace(/\\/+$/, \"\");\n\ninterface RequestOptionsWithOptionalIdempotency extends RequestOptions {\n idempotencyKey?: string;\n}\n\nconst normalizeRequestOptions = (\n opts: RequestOptionsInput,\n): RequestOptionsWithOptionalIdempotency => opts ?? {};\n\nconst requireIdempotencyKey = (opts: RequestOptionsWithOptionalIdempotency): string => {\n if (!opts.idempotencyKey) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"missing_idempotency_key\",\n message: \"idempotencyKey is required for this operation\",\n retryable: false,\n });\n }\n return opts.idempotencyKey;\n};\n\nconst appendQuery = (path: string, query?: object): string => {\n if (!query) return path;\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined || value === null || value === \"\") continue;\n params.set(key, String(value));\n }\n const encoded = params.toString();\n return encoded ? `${path}?${encoded}` : path;\n};\n\ninterface APIErrorBody {\n error?: {\n type?: string;\n code?: string;\n message?: string;\n param?: string;\n request_id?: string;\n decline_code?: string;\n };\n}\n\nconst isPublicErrorType = (value: unknown): value is ArcPayErrorType =>\n value === \"validation_error\" ||\n value === \"authentication_error\" ||\n value === \"authorization_error\" ||\n value === \"state_error\" ||\n value === \"rate_limit_error\" ||\n value === \"api_error\";\n\nconst parseErrorResponse = async (res: Response): Promise<ArcPayError> => {\n let body: APIErrorBody = {};\n try {\n body = (await res.json()) as APIErrorBody;\n } catch {\n /* keep default error below */\n }\n const detail = body.error ?? {};\n const type = isPublicErrorType(detail.type)\n ? detail.type\n : res.status >= 500\n ? \"api_error\"\n : \"validation_error\";\n return new ArcPayError({\n type,\n code: detail.code,\n message: detail.message ?? `Request failed with status ${res.status}`,\n param: detail.param,\n requestId: detail.request_id,\n declineCode: detail.decline_code,\n retryable: type === \"api_error\" || type === \"rate_limit_error\",\n });\n};\n\nexport class ArcPayClient {\n private readonly secretKey: string;\n private readonly apiBase: string;\n private readonly fetchImpl: typeof fetch;\n\n constructor(options: ArcPayClientOptions) {\n const secretKey: unknown = options.secretKey;\n validateSecretKey(secretKey);\n if (!options.fetch && typeof fetch === \"undefined\") {\n throw new ArcPayError({\n type: \"api_error\",\n code: \"fetch_unavailable\",\n message: \"A fetch implementation is required in this runtime\",\n retryable: false,\n });\n }\n this.secretKey = secretKey;\n this.apiBase = normalizeBase(options.apiBase ?? DEFAULT_API_BASE);\n this.fetchImpl = options.fetch ?? fetch;\n }\n\n async listPayments(\n query: ListPaymentsQuery = {},\n opts: RequestOptions = {},\n ): Promise<PaymentList> {\n return this.request<PaymentList>(\"GET\", appendQuery(\"/payments\", query), undefined, opts);\n }\n\n async createPayment(body: CreatePaymentRequest, opts: IdempotencyOptions): Promise<Payment>;\n async createPayment(body: CreatePaymentRequest, opts: RequestOptionsInput): Promise<Payment> {\n return this.request<Payment>(\"POST\", \"/payments\", body, opts, true);\n }\n\n async getPayment(paymentId: string, opts: RequestOptions = {}): Promise<Payment> {\n return this.request<Payment>(\n \"GET\",\n `/payments/${encodeURIComponent(paymentId)}`,\n undefined,\n opts,\n );\n }\n\n async capturePayment(\n paymentId: string,\n body: CaptureRequest,\n opts: IdempotencyOptions,\n ): Promise<Payment>;\n async capturePayment(\n paymentId: string,\n body: CaptureRequest,\n opts: RequestOptionsInput,\n ): Promise<Payment> {\n return this.request<Payment>(\n \"POST\",\n `/payments/${encodeURIComponent(paymentId)}/capture`,\n body,\n opts,\n true,\n );\n }\n\n async voidPayment(\n paymentId: string,\n body: VoidRequest,\n opts: IdempotencyOptions,\n ): Promise<Payment>;\n async voidPayment(\n paymentId: string,\n body: VoidRequest,\n opts: RequestOptionsInput,\n ): Promise<Payment> {\n return this.request<Payment>(\n \"POST\",\n `/payments/${encodeURIComponent(paymentId)}/void`,\n body,\n opts,\n true,\n );\n }\n\n async createRefund(\n paymentId: string,\n body: CreateRefundRequest,\n opts: IdempotencyOptions,\n ): Promise<Refund>;\n async createRefund(\n paymentId: string,\n body: CreateRefundRequest,\n opts: RequestOptionsInput,\n ): Promise<Refund> {\n return this.request<Refund>(\n \"POST\",\n `/payments/${encodeURIComponent(paymentId)}/refunds`,\n body,\n opts,\n true,\n );\n }\n\n async chargeSavedCard(\n body: ChargeSavedCardRequest,\n opts: IdempotencyOptions,\n ): Promise<ExecutePaymentResponse>;\n async chargeSavedCard(\n body: ChargeSavedCardRequest,\n opts: RequestOptionsInput,\n ): Promise<ExecutePaymentResponse> {\n return this.request<ExecutePaymentResponse>(\"POST\", \"/payments/saved-card\", body, opts, true);\n }\n\n async executePayment(\n paymentId: string,\n body: ExecutePaymentRequest,\n opts: IdempotencyOptions,\n ): Promise<ExecutePaymentResponse>;\n async executePayment(\n paymentId: string,\n body: ExecutePaymentRequest,\n opts: RequestOptionsInput,\n ): Promise<ExecutePaymentResponse> {\n return this.request<ExecutePaymentResponse>(\n \"POST\",\n `/payments/${encodeURIComponent(paymentId)}/execute`,\n body,\n opts,\n true,\n );\n }\n\n async completeThreeDSMethod(\n paymentId: string,\n body: CompleteThreeDSMethodRequest,\n opts: RequestOptions = {},\n ): Promise<ExecutePaymentResponse> {\n return this.request<ExecutePaymentResponse>(\n \"POST\",\n `/payments/${encodeURIComponent(paymentId)}/complete-3ds-method`,\n body,\n opts,\n );\n }\n\n async listAvailablePaymentMethods(\n query: ListAvailablePaymentMethodsQuery,\n opts: RequestOptions = {},\n ): Promise<AvailablePaymentMethod[]> {\n return this.request<AvailablePaymentMethod[]>(\n \"GET\",\n appendQuery(\"/payment-methods/available\", query),\n undefined,\n opts,\n );\n }\n\n async createLink(body: CreateLinkRequest, opts: IdempotencyOptions): Promise<Link>;\n async createLink(body: CreateLinkRequest, opts: RequestOptionsInput): Promise<Link> {\n return this.request<Link>(\"POST\", \"/links\", body, opts, true);\n }\n\n async getLink(linkId: string, opts: RequestOptions = {}): Promise<Link> {\n return this.request<Link>(\"GET\", `/links/${encodeURIComponent(linkId)}`, undefined, opts);\n }\n\n async cancelLink(linkId: string, opts: RequestOptions = {}): Promise<Link> {\n return this.request<Link>(\"DELETE\", `/links/${encodeURIComponent(linkId)}`, undefined, opts);\n }\n\n async createCheckoutSession(\n body: CreateCheckoutSessionRequest,\n opts: IdempotencyOptions,\n ): Promise<CheckoutSession>;\n async createCheckoutSession(\n body: CreateCheckoutSessionRequest,\n opts: RequestOptionsInput,\n ): Promise<CheckoutSession> {\n return this.request<CheckoutSession>(\"POST\", \"/checkout/sessions\", body, opts, true);\n }\n\n private async request<T>(\n method: \"GET\" | \"POST\" | \"DELETE\",\n path: string,\n body: unknown,\n opts: RequestOptionsInput = undefined,\n requireIdempotency = false,\n ): Promise<T> {\n const requestOpts = normalizeRequestOptions(opts);\n const headers: Record<string, string> = {\n Authorization: `Bearer ${this.secretKey}`,\n \"X-Arc-Pay-API-Version\": API_VERSION,\n \"Content-Type\": \"application/json\",\n };\n if (requireIdempotency) {\n headers[\"Idempotency-Key\"] = requireIdempotencyKey(requestOpts);\n } else if (requestOpts.idempotencyKey !== undefined) {\n headers[\"Idempotency-Key\"] = requireIdempotencyKey(requestOpts);\n }\n\n let res: Response;\n try {\n res = await this.fetchImpl(`${this.apiBase}${path}`, {\n method,\n headers,\n body: body === undefined ? undefined : JSON.stringify(body),\n signal: requestOpts.signal,\n });\n } catch (err) {\n throw new ArcPayError({\n type: \"network_error\",\n message: err instanceof Error ? err.message : \"Network request failed\",\n retryable: true,\n });\n }\n if (!res.ok) throw await parseErrorResponse(res);\n return (await res.json()) as T;\n }\n}\n\nexport const createArcPayClient = (options: ArcPayClientOptions): ArcPayClient =>\n new ArcPayClient(options);\n"]}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@thavguard/arc-pay",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Arc Pay browser SDK — publishable-key tokenization, Hosted Fields, and React bindings",
5
5
  "private": false,
6
- "license": "UNLICENSED",
6
+ "license": "MIT",
7
7
  "type": "module",
8
8
  "main": "./dist/index.cjs",
9
9
  "module": "./dist/index.mjs",
@@ -32,7 +32,8 @@
32
32
  },
33
33
  "files": [
34
34
  "dist",
35
- "README.md"
35
+ "README.md",
36
+ "LICENSE"
36
37
  ],
37
38
  "publishConfig": {
38
39
  "registry": "https://registry.npmjs.org/"
@@ -55,6 +56,8 @@
55
56
  "test:watch": "vitest",
56
57
  "typecheck": "tsc --noEmit",
57
58
  "size": "node ./scripts/check-bundle-size.mjs",
59
+ "prepack": "pnpm typecheck && pnpm test && pnpm build:all && pnpm size",
60
+ "prepublishOnly": "pnpm prepack",
58
61
  "e2e": "pnpm build:all && playwright test --config=e2e/playwright.config.ts",
59
62
  "e2e:install": "playwright install --with-deps chromium firefox webkit",
60
63
  "e2e:headed": "playwright test --config=e2e/playwright.config.ts --headed"