@thavguard/arc-pay 0.1.1 → 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.
- package/README.md +14 -8
- package/dist/{arcpay-DAwTxM9e.d.cts → arcpay-Cxgei9TD.d.cts} +3 -34
- package/dist/{arcpay-DAwTxM9e.d.ts → arcpay-Cxgei9TD.d.ts} +3 -34
- package/dist/cdn/arcpay.global.js +3 -0
- package/dist/cdn/arcpay.global.js.map +1 -0
- package/dist/index.cjs +5 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -8
- package/dist/index.d.ts +3 -8
- package/dist/index.mjs +6 -79
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.cjs +8 -61
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.mjs +8 -61
- package/dist/react/index.mjs.map +1 -1
- package/dist/server/index.cjs +9 -0
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +30 -3
- package/dist/server/index.d.ts +30 -3
- package/dist/server/index.mjs +9 -0
- package/dist/server/index.mjs.map +1 -1
- package/package.json +3 -1
|
@@ -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,IAAA,CAAK,WA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":"index.cjs","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\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 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 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\",\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"]}
|
|
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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I,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.cjs","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/dist/server/index.d.cts
CHANGED
|
@@ -4,7 +4,6 @@ type CaptureMode = "one_stage" | "two_stage";
|
|
|
4
4
|
type PaymentFlowMode = "h2h" | "redirect";
|
|
5
5
|
type Locale = "ru" | "en";
|
|
6
6
|
type PaymentStatus = "created" | "pending" | "pending_3ds" | "authorized" | "captured" | "settled" | "voided" | "expired" | "refunded" | "chargeback" | "declined" | "failed" | "timeout";
|
|
7
|
-
type PaymentOperation = "create" | "capture" | "refund" | "void" | "execute";
|
|
8
7
|
interface Payment {
|
|
9
8
|
id: string;
|
|
10
9
|
amount: number;
|
|
@@ -46,6 +45,8 @@ interface CreatePaymentRequest {
|
|
|
46
45
|
payment_method: PaymentMethod;
|
|
47
46
|
external_id: string;
|
|
48
47
|
capture_mode: CaptureMode;
|
|
48
|
+
save_card?: boolean;
|
|
49
|
+
customer_id?: string;
|
|
49
50
|
description?: string;
|
|
50
51
|
success_url?: string;
|
|
51
52
|
fail_url?: string;
|
|
@@ -111,6 +112,21 @@ interface ExecutePaymentResponse {
|
|
|
111
112
|
decline_code?: string;
|
|
112
113
|
decline_message?: string;
|
|
113
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
|
+
}
|
|
114
130
|
interface CompleteThreeDSMethodRequest {
|
|
115
131
|
completion_indicator: "Y" | "N" | "U";
|
|
116
132
|
three_ds_server_trans_id: string;
|
|
@@ -120,8 +136,13 @@ interface AvailablePaymentMethod {
|
|
|
120
136
|
payment_mode: PaymentFlowMode;
|
|
121
137
|
display_name: string;
|
|
122
138
|
is_active: boolean;
|
|
139
|
+
unavailable_reason?: string;
|
|
123
140
|
icon_url?: string;
|
|
124
|
-
|
|
141
|
+
supported_currencies?: Currency[];
|
|
142
|
+
supported_countries?: string[];
|
|
143
|
+
min_amount?: number;
|
|
144
|
+
max_amount?: number;
|
|
145
|
+
sandbox_requirements?: string;
|
|
125
146
|
}
|
|
126
147
|
interface CreateLinkRequest {
|
|
127
148
|
link_type: "one_time" | "reusable" | "invoice" | "recurring";
|
|
@@ -132,6 +153,7 @@ interface CreateLinkRequest {
|
|
|
132
153
|
max_uses?: number;
|
|
133
154
|
expires_at?: string;
|
|
134
155
|
customer_name?: string;
|
|
156
|
+
customer_id?: string;
|
|
135
157
|
customer_email?: string;
|
|
136
158
|
due_date?: string;
|
|
137
159
|
redirect_url?: string;
|
|
@@ -176,6 +198,7 @@ interface Link {
|
|
|
176
198
|
uses_count?: number;
|
|
177
199
|
expires_at?: string;
|
|
178
200
|
customer_name?: string;
|
|
201
|
+
customer_id?: string;
|
|
179
202
|
customer_email?: string;
|
|
180
203
|
due_date?: string;
|
|
181
204
|
external_order_id?: string;
|
|
@@ -216,6 +239,7 @@ interface CreateCheckoutSessionRequest {
|
|
|
216
239
|
fail_url?: string;
|
|
217
240
|
cancel_url?: string;
|
|
218
241
|
customer_email?: string;
|
|
242
|
+
customer_id?: string;
|
|
219
243
|
external_id?: string;
|
|
220
244
|
metadata?: Record<string, string>;
|
|
221
245
|
autocompletion_date?: string;
|
|
@@ -264,13 +288,16 @@ declare class ArcPayClient {
|
|
|
264
288
|
capturePayment(paymentId: string, body: CaptureRequest, opts: IdempotencyOptions): Promise<Payment>;
|
|
265
289
|
voidPayment(paymentId: string, body: VoidRequest, opts: IdempotencyOptions): Promise<Payment>;
|
|
266
290
|
createRefund(paymentId: string, body: CreateRefundRequest, opts: IdempotencyOptions): Promise<Refund>;
|
|
291
|
+
chargeSavedCard(body: ChargeSavedCardRequest, opts: IdempotencyOptions): Promise<ExecutePaymentResponse>;
|
|
267
292
|
executePayment(paymentId: string, body: ExecutePaymentRequest, opts: IdempotencyOptions): Promise<ExecutePaymentResponse>;
|
|
268
293
|
completeThreeDSMethod(paymentId: string, body: CompleteThreeDSMethodRequest, opts?: RequestOptions): Promise<ExecutePaymentResponse>;
|
|
269
294
|
listAvailablePaymentMethods(query: ListAvailablePaymentMethodsQuery, opts?: RequestOptions): Promise<AvailablePaymentMethod[]>;
|
|
270
295
|
createLink(body: CreateLinkRequest, opts: IdempotencyOptions): Promise<Link>;
|
|
296
|
+
getLink(linkId: string, opts?: RequestOptions): Promise<Link>;
|
|
297
|
+
cancelLink(linkId: string, opts?: RequestOptions): Promise<Link>;
|
|
271
298
|
createCheckoutSession(body: CreateCheckoutSessionRequest, opts: IdempotencyOptions): Promise<CheckoutSession>;
|
|
272
299
|
private request;
|
|
273
300
|
}
|
|
274
301
|
declare const createArcPayClient: (options: ArcPayClientOptions) => ArcPayClient;
|
|
275
302
|
|
|
276
|
-
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 };
|
package/dist/server/index.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ type CaptureMode = "one_stage" | "two_stage";
|
|
|
4
4
|
type PaymentFlowMode = "h2h" | "redirect";
|
|
5
5
|
type Locale = "ru" | "en";
|
|
6
6
|
type PaymentStatus = "created" | "pending" | "pending_3ds" | "authorized" | "captured" | "settled" | "voided" | "expired" | "refunded" | "chargeback" | "declined" | "failed" | "timeout";
|
|
7
|
-
type PaymentOperation = "create" | "capture" | "refund" | "void" | "execute";
|
|
8
7
|
interface Payment {
|
|
9
8
|
id: string;
|
|
10
9
|
amount: number;
|
|
@@ -46,6 +45,8 @@ interface CreatePaymentRequest {
|
|
|
46
45
|
payment_method: PaymentMethod;
|
|
47
46
|
external_id: string;
|
|
48
47
|
capture_mode: CaptureMode;
|
|
48
|
+
save_card?: boolean;
|
|
49
|
+
customer_id?: string;
|
|
49
50
|
description?: string;
|
|
50
51
|
success_url?: string;
|
|
51
52
|
fail_url?: string;
|
|
@@ -111,6 +112,21 @@ interface ExecutePaymentResponse {
|
|
|
111
112
|
decline_code?: string;
|
|
112
113
|
decline_message?: string;
|
|
113
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
|
+
}
|
|
114
130
|
interface CompleteThreeDSMethodRequest {
|
|
115
131
|
completion_indicator: "Y" | "N" | "U";
|
|
116
132
|
three_ds_server_trans_id: string;
|
|
@@ -120,8 +136,13 @@ interface AvailablePaymentMethod {
|
|
|
120
136
|
payment_mode: PaymentFlowMode;
|
|
121
137
|
display_name: string;
|
|
122
138
|
is_active: boolean;
|
|
139
|
+
unavailable_reason?: string;
|
|
123
140
|
icon_url?: string;
|
|
124
|
-
|
|
141
|
+
supported_currencies?: Currency[];
|
|
142
|
+
supported_countries?: string[];
|
|
143
|
+
min_amount?: number;
|
|
144
|
+
max_amount?: number;
|
|
145
|
+
sandbox_requirements?: string;
|
|
125
146
|
}
|
|
126
147
|
interface CreateLinkRequest {
|
|
127
148
|
link_type: "one_time" | "reusable" | "invoice" | "recurring";
|
|
@@ -132,6 +153,7 @@ interface CreateLinkRequest {
|
|
|
132
153
|
max_uses?: number;
|
|
133
154
|
expires_at?: string;
|
|
134
155
|
customer_name?: string;
|
|
156
|
+
customer_id?: string;
|
|
135
157
|
customer_email?: string;
|
|
136
158
|
due_date?: string;
|
|
137
159
|
redirect_url?: string;
|
|
@@ -176,6 +198,7 @@ interface Link {
|
|
|
176
198
|
uses_count?: number;
|
|
177
199
|
expires_at?: string;
|
|
178
200
|
customer_name?: string;
|
|
201
|
+
customer_id?: string;
|
|
179
202
|
customer_email?: string;
|
|
180
203
|
due_date?: string;
|
|
181
204
|
external_order_id?: string;
|
|
@@ -216,6 +239,7 @@ interface CreateCheckoutSessionRequest {
|
|
|
216
239
|
fail_url?: string;
|
|
217
240
|
cancel_url?: string;
|
|
218
241
|
customer_email?: string;
|
|
242
|
+
customer_id?: string;
|
|
219
243
|
external_id?: string;
|
|
220
244
|
metadata?: Record<string, string>;
|
|
221
245
|
autocompletion_date?: string;
|
|
@@ -264,13 +288,16 @@ declare class ArcPayClient {
|
|
|
264
288
|
capturePayment(paymentId: string, body: CaptureRequest, opts: IdempotencyOptions): Promise<Payment>;
|
|
265
289
|
voidPayment(paymentId: string, body: VoidRequest, opts: IdempotencyOptions): Promise<Payment>;
|
|
266
290
|
createRefund(paymentId: string, body: CreateRefundRequest, opts: IdempotencyOptions): Promise<Refund>;
|
|
291
|
+
chargeSavedCard(body: ChargeSavedCardRequest, opts: IdempotencyOptions): Promise<ExecutePaymentResponse>;
|
|
267
292
|
executePayment(paymentId: string, body: ExecutePaymentRequest, opts: IdempotencyOptions): Promise<ExecutePaymentResponse>;
|
|
268
293
|
completeThreeDSMethod(paymentId: string, body: CompleteThreeDSMethodRequest, opts?: RequestOptions): Promise<ExecutePaymentResponse>;
|
|
269
294
|
listAvailablePaymentMethods(query: ListAvailablePaymentMethodsQuery, opts?: RequestOptions): Promise<AvailablePaymentMethod[]>;
|
|
270
295
|
createLink(body: CreateLinkRequest, opts: IdempotencyOptions): Promise<Link>;
|
|
296
|
+
getLink(linkId: string, opts?: RequestOptions): Promise<Link>;
|
|
297
|
+
cancelLink(linkId: string, opts?: RequestOptions): Promise<Link>;
|
|
271
298
|
createCheckoutSession(body: CreateCheckoutSessionRequest, opts: IdempotencyOptions): Promise<CheckoutSession>;
|
|
272
299
|
private request;
|
|
273
300
|
}
|
|
274
301
|
declare const createArcPayClient: (options: ArcPayClientOptions) => ArcPayClient;
|
|
275
302
|
|
|
276
|
-
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 };
|
package/dist/server/index.mjs
CHANGED
|
@@ -135,6 +135,9 @@ var ArcPayClient = class {
|
|
|
135
135
|
true
|
|
136
136
|
);
|
|
137
137
|
}
|
|
138
|
+
async chargeSavedCard(body, opts) {
|
|
139
|
+
return this.request("POST", "/payments/saved-card", body, opts, true);
|
|
140
|
+
}
|
|
138
141
|
async executePayment(paymentId, body, opts) {
|
|
139
142
|
return this.request(
|
|
140
143
|
"POST",
|
|
@@ -163,6 +166,12 @@ var ArcPayClient = class {
|
|
|
163
166
|
async createLink(body, opts) {
|
|
164
167
|
return this.request("POST", "/links", body, opts, true);
|
|
165
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);
|
|
174
|
+
}
|
|
166
175
|
async createCheckoutSession(body, opts) {
|
|
167
176
|
return this.request("POST", "/checkout/sessions", body, opts, true);
|
|
168
177
|
}
|
|
@@ -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,IAAA,CAAK,WAAA;AACxB,IAAA,IAAA,CAAK,YAAY,IAAA,CAAK,SAAA;AACtB,IAAA,IAAA,CAAK,YAAY,IAAA,CAAK,SAAA;AAAA,EACxB;AACF,CAAA;;;ACsBA,IAAM,gBAAA,GAAmB,6BAAA;AACzB,IAAM,WAAA,GAAc,YAAA;AAEpB,SAAS,kBAAkB,GAAA,EAAqC;AAC9D,E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AAA,EAAoB;AACtB,MAAA,OAAA,CAAQ,iBAAiB,CAAA,GAAI,qBAAA,CAAsB,WAAW,CAAA;AAAA,IAChE,CAAA,MAAA,IAAW,WAAA,CAAY,cAAA,KAAmB,MAAA,EAAW;AACnD,MAAA,OAAA,CAAQ,iBAAiB,CAAA,GAAI,qBAAA,CAAsB,WAAW,CAAA;AAAA,IAChE;AAEA,IAAA,IAAI,GAAA;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,WAAA,CAAY;AAAA,OACrB,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\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 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 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\",\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"]}
|
|
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,CAAC,GAAA,CAAI,UAAA,CAAW,UAAU,CAAA,EAAG;AAC9D,IAAA,MAAM,IAAI,WAAA,CAAY;AAAA,MACpB,IAAA,EAAM,s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| \"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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thavguard/arc-pay",
|
|
3
|
-
"version": "0.1.
|
|
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
6
|
"license": "MIT",
|
|
@@ -56,6 +56,8 @@
|
|
|
56
56
|
"test:watch": "vitest",
|
|
57
57
|
"typecheck": "tsc --noEmit",
|
|
58
58
|
"size": "node ./scripts/check-bundle-size.mjs",
|
|
59
|
+
"prepack": "pnpm typecheck && pnpm test && pnpm build:all && pnpm size",
|
|
60
|
+
"prepublishOnly": "pnpm prepack",
|
|
59
61
|
"e2e": "pnpm build:all && playwright test --config=e2e/playwright.config.ts",
|
|
60
62
|
"e2e:install": "playwright install --with-deps chromium firefox webkit",
|
|
61
63
|
"e2e:headed": "playwright test --config=e2e/playwright.config.ts --headed"
|