@thavguard/arc-pay 0.1.1 → 0.1.3
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 +20 -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 +15 -1
- 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 +15 -1
- package/dist/server/index.mjs.map +1 -1
- package/package.json +7 -1
package/dist/react/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/errors.ts","../../src/core/csp.ts","../../src/core/env.ts","../../src/core/sandbox-banner.ts","../../src/elements/postmessage.ts","../../src/elements/style.ts","../../src/elements/element.ts","../../src/elements/elements.ts","../../src/core/arcpay.ts","../../src/react/provider.tsx","../../src/react/use-arcpay.ts","../../src/react/index.ts"],"names":["validatePublishableKey","React2"],"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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AAA;AACH,QAAA,QAAA,CAAS;AAAA,UACP,MAAA,EAAQ,OAAA;AAAA,UACR,QAAA,EAAU,IAAA;AAAA,UACV,KAAA,EAAO,iBAAiB,KAAA,GAAQ,KAAA,GAAQ,IAAI,KAAA,CAAM,MAAA,CAAO,KAAK,CAAC;AAAA,SAChE,CAAA;AAAA,IACL,CAAC,CAAA;AACH,IAAA,OAAO,MAAM;AACX,MAAA,QAAA,GAAW,IAAA;AAAA,IACb,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,cAAA,EAAgB,OAAO,CAAC,CAAA;AAE5B,EAAA,2BAAQ,GAAA,CAAI,QAAA,EAAJ,EAAa,KAAA,EAAO,OAAQ,QAAA,EAAS,CAAA;AAC/C;AAEO,IAAM,aAAA,GAAgB;AC7CtB,IAAM,YAAY,MAAmB;AAC1C,EAAA,MAAM,GAAA,GAAYC,iBAAW,aAAa,CAAA;AAC1C,EAAA,IAAI,CAAC,GAAA,EAAK,MAAM,IAAI,MAAM,mDAAmD,CAAA;AAC7E,EAAA,OAAO,GAAA;AACT;;;ACJO,IAAM,qBAAA,GAAwB","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 } from \"./errors\";\n\nconst readCspContent = (): string | null => {\n if (typeof document === \"undefined\") return null;\n const meta = document.head.querySelector<HTMLMetaElement>(\n 'meta[http-equiv=\"Content-Security-Policy\"]',\n );\n return meta?.getAttribute(\"content\") ?? null;\n};\n\nconst extractDirective = (csp: string, name: string): string | null => {\n const lower = csp.toLowerCase();\n const idx = lower.indexOf(`${name} `);\n if (idx === -1) return null;\n const rest = csp.slice(idx + name.length + 1);\n const end = rest.indexOf(\";\");\n return (end === -1 ? rest : rest.slice(0, end)).trim();\n};\n\nconst directiveAllowsHost = (directive: string, host: string): boolean => {\n const tokens = directive.split(/\\s+/).filter(Boolean);\n if (tokens.includes(\"*\")) return true;\n return tokens.some((t) => {\n if (t === host) return true;\n if (t.startsWith(\"https://*\")) {\n const suffix = t.slice(\"https://*\".length);\n return host.endsWith(suffix);\n }\n return false;\n });\n};\n\nexport const verifyCspAllowsApiBase = (apiBase: string): void => {\n const csp = readCspContent();\n if (!csp) return;\n const directive = extractDirective(csp, \"connect-src\");\n if (!directive) return;\n if (directiveAllowsHost(directive, apiBase)) return;\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"csp_blocks_api\",\n message: `CSP connect-src directive does not allow ${apiBase}. Add it to your Content-Security-Policy header.`,\n retryable: false,\n });\n};\n","import { ArcPayError } from \"./errors\";\n\nexport type Environment = \"sandbox\" | \"live\";\n\nexport const detectEnvironment = (publishableKey: string): Environment =>\n publishableKey.startsWith(\"pk_test_\") ? \"sandbox\" : \"live\";\n\nexport const validatePublishableKey = (key: unknown): asserts key is string => {\n if (typeof key !== \"string\" || key.length === 0) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"invalid_publishable_key\",\n message: \"Publishable key must be a non-empty string\",\n retryable: false,\n });\n }\n if (!key.startsWith(\"pk_test_\") && !key.startsWith(\"pk_live_\")) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"invalid_publishable_key\",\n message:\n \"Publishable key must start with pk_test_ or pk_live_. Secret keys (sk_*) cannot be used in browser.\",\n retryable: false,\n });\n }\n};\n","const BANNER_ATTR = \"data-arcpay-sandbox-banner\";\n\nexport const showSandboxBanner = (): void => {\n if (typeof document === \"undefined\") return;\n if (document.querySelector(`[${BANNER_ATTR}]`)) return;\n\n const bar = document.createElement(\"div\");\n bar.setAttribute(BANNER_ATTR, \"\");\n bar.style.cssText =\n \"position:fixed;top:0;left:0;right:0;z-index:2147483647;background:#ffd166;color:#222;font:13px/1.4 system-ui,sans-serif;padding:6px 12px;display:flex;align-items:center;justify-content:center;box-shadow:0 1px 3px rgba(0,0,0,0.1);\";\n\n const text = document.createElement(\"span\");\n text.textContent = \"ARC PAY TEST MODE — payments are simulated\";\n bar.appendChild(text);\n\n const dismiss = document.createElement(\"button\");\n dismiss.type = \"button\";\n dismiss.setAttribute(\"data-arcpay-banner-dismiss\", \"\");\n dismiss.textContent = \"×\";\n dismiss.setAttribute(\"aria-label\", \"Dismiss test mode banner\");\n dismiss.style.cssText =\n \"margin-left:12px;background:transparent;border:0;font-size:18px;cursor:pointer;color:inherit;\";\n dismiss.addEventListener(\"click\", () => bar.remove());\n bar.appendChild(dismiss);\n\n document.body.appendChild(bar);\n};\n","import { ArcPayError } from \"../core/errors\";\n\nexport type FieldType = \"cardNumber\" | \"cardExpiry\" | \"cardCvv\";\n\n// Parent → iframe\nexport type ParentToIframe =\n | { type: \"arcpay:hello\"; origin: string; publishableKey: string; channelId: string }\n | { type: \"arcpay:style\"; payload: StyleSubset }\n | { type: \"arcpay:focus\" }\n | { type: \"arcpay:clear\" }\n | { type: \"arcpay:tokenize\"; paymentId: string; idempotencyKey: string };\n\n// iframe → parent\nexport type IframeToParent =\n | { type: \"arcpay:ready\" }\n | { type: \"arcpay:rejected\"; reason: string }\n | {\n type: \"arcpay:change\";\n field: FieldType;\n isValid: boolean;\n brand?: string;\n lastFour?: string;\n }\n | {\n type: \"arcpay:tokenize-result\";\n cardTokenId: string;\n cardMask: string;\n cardScheme: string;\n cardBin: string;\n expiresIn: number;\n expiresAt: string;\n }\n | { type: \"arcpay:tokenize-error\"; errorType: string; code?: string; message: string };\n\nexport interface StyleSubset {\n base: Record<string, string>;\n invalid?: Record<string, string>;\n focus?: Record<string, string>;\n}\n\nconst ARCPAY_TYPE_PREFIX = \"arcpay:\";\n\nconst isArcpayMessage = (data: unknown): data is { type: string } =>\n typeof data === \"object\" &&\n data !== null &&\n \"type\" in data &&\n typeof (data as { type: unknown }).type === \"string\" &&\n (data as { type: string }).type.startsWith(ARCPAY_TYPE_PREFIX);\n\nexport const postToIframe = (\n iframe: HTMLIFrameElement,\n message: ParentToIframe,\n targetOrigin: string,\n): void => {\n if (targetOrigin === \"*\") {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"wildcard_origin_forbidden\",\n message: \"postToIframe: targetOrigin cannot be '*'\",\n retryable: false,\n });\n }\n if (!iframe.contentWindow) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"iframe_not_loaded\",\n message: \"postToIframe: iframe.contentWindow is null (iframe not mounted)\",\n retryable: false,\n });\n }\n iframe.contentWindow.postMessage(message, targetOrigin);\n};\n\nexport const postToParent = (message: IframeToParent, targetOrigin: string): void => {\n if (targetOrigin === \"*\") {\n throw new Error(\"postToParent: targetOrigin cannot be '*'\");\n }\n window.parent.postMessage(message, targetOrigin);\n};\n\nexport const parseIncoming = <T extends { type: string }>(\n event: MessageEvent,\n expectedOrigin: string,\n): T | null => {\n if (event.origin !== expectedOrigin) return null;\n if (!isArcpayMessage(event.data)) return null;\n return event.data as T;\n};\n","import type { StyleSubset } from \"./postmessage\";\n\n// Spec calls out position:fixed, transform, pointer-events:none as forbidden.\n// We extend to cover the full clickjacking attack surface: any positioning\n// (fixed/absolute/sticky), transform, all pointer-events values, z-index, and\n// inset properties (top/left/right/bottom/inset). The legitimate use cases\n// for these in a 1-line input field are zero, so blanket drop.\nconst FORBIDDEN_PROPERTIES = new Set([\n \"position\",\n \"transform\",\n \"pointer-events\",\n \"z-index\",\n \"top\",\n \"left\",\n \"right\",\n \"bottom\",\n \"inset\",\n]);\n\nconst sanitizeBlock = (block: Record<string, string>): Record<string, string> => {\n const out: Record<string, string> = {};\n for (const [key, value] of Object.entries(block)) {\n const normalizedKey = key.toLowerCase();\n if (FORBIDDEN_PROPERTIES.has(normalizedKey)) {\n // Defense against position/transform-based clickjacking. Silently drop.\n continue;\n }\n out[key] = value;\n }\n return out;\n};\n\nexport const sanitizeStyle = (style: StyleSubset): StyleSubset => {\n const result: StyleSubset = { base: sanitizeBlock(style.base) };\n if (style.invalid !== undefined) result.invalid = sanitizeBlock(style.invalid);\n if (style.focus !== undefined) result.focus = sanitizeBlock(style.focus);\n return result;\n};\n","import { ArcPayError } from \"../core/errors\";\nimport {\n type FieldType,\n type ParentToIframe,\n type IframeToParent,\n type StyleSubset,\n postToIframe,\n parseIncoming,\n} from \"./postmessage\";\nimport { sanitizeStyle } from \"./style\";\n\nexport interface ElementOptions {\n /** StyleSubset applied via arcpay:style postMessage. */\n style?: StyleSubset;\n placeholder?: string;\n}\n\nexport type ElementEvent =\n | { type: \"ready\" }\n | { type: \"change\"; isValid: boolean; brand?: string; lastFour?: string }\n | { type: \"error\"; reason: string };\n\ntype Listener = (event: ElementEvent) => void;\n\nexport interface ElementContext {\n iframeBase: string;\n publishableKey: string;\n channelId: string;\n}\n\nexport class Element {\n private iframe: HTMLIFrameElement | null = null;\n private readonly listeners = new Set<Listener>();\n private status: \"pending\" | \"ready\" | \"error\" = \"pending\";\n private messageHandler: ((e: MessageEvent) => void) | null = null;\n\n constructor(\n public readonly field: FieldType,\n private readonly options: ElementOptions,\n private readonly context: ElementContext,\n ) {}\n\n mount(target: string | HTMLElement): void {\n if (this.iframe) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"already_mounted\",\n message: `Element ${this.field} is already mounted`,\n retryable: false,\n });\n }\n const container = typeof target === \"string\" ? document.querySelector(target) : target;\n if (!(container instanceof HTMLElement)) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"mount_target_not_found\",\n message: `mount target not found: ${String(target)}`,\n retryable: false,\n });\n }\n\n const iframe = document.createElement(\"iframe\");\n iframe.src = `${this.context.iframeBase}/iframe/${this.field}`;\n iframe.style.cssText = \"border:0;width:100%;height:100%;display:block;\";\n iframe.setAttribute(\"allow\", \"payment\");\n iframe.setAttribute(\"data-arcpay-element\", this.field);\n container.appendChild(iframe);\n this.iframe = iframe;\n\n const expectedOrigin = new URL(this.context.iframeBase).origin;\n\n this.messageHandler = (event: MessageEvent) => {\n // C1: source guard — only accept messages from this element's own iframe.\n // Without this, any iframe at the same origin (e.g. cardExpiry, cardCvv)\n // could trigger handlers on cardNumber and vice-versa.\n if (event.source !== this.iframe?.contentWindow) return;\n // C4: use parseIncoming for origin + arcpay: prefix guard.\n const data = parseIncoming<IframeToParent>(event, expectedOrigin);\n if (!data) return;\n this.handleMessage(data);\n };\n window.addEventListener(\"message\", this.messageHandler);\n\n iframe.addEventListener(\n \"load\",\n () => {\n if (!this.iframe) return;\n const hello: ParentToIframe = {\n type: \"arcpay:hello\",\n origin: window.location.origin,\n publishableKey: this.context.publishableKey,\n channelId: this.context.channelId,\n };\n postToIframe(this.iframe, hello, expectedOrigin);\n },\n { once: true },\n );\n }\n\n private handleMessage(data: IframeToParent): void {\n if (data.type === \"arcpay:ready\") {\n this.status = \"ready\";\n // Apply initial style if provided at construction time.\n if (this.options.style) {\n this.send({ type: \"arcpay:style\", payload: sanitizeStyle(this.options.style) });\n }\n this.emit({ type: \"ready\" });\n } else if (data.type === \"arcpay:rejected\") {\n this.status = \"error\";\n this.emit({ type: \"error\", reason: data.reason });\n } else if (data.type === \"arcpay:change\" && data.field === this.field) {\n this.emit({\n type: \"change\",\n isValid: data.isValid,\n brand: data.brand,\n lastFour: data.lastFour,\n });\n }\n // arcpay:tokenize-result / arcpay:tokenize-error handled by Elements factory (Task 9).\n }\n\n update(options: { style?: StyleSubset }): void {\n if (options.style) {\n this.send({ type: \"arcpay:style\", payload: sanitizeStyle(options.style) });\n }\n }\n\n destroy(): void {\n if (this.iframe) {\n this.iframe.remove();\n this.iframe = null;\n }\n if (this.messageHandler) {\n window.removeEventListener(\"message\", this.messageHandler);\n this.messageHandler = null;\n }\n this.listeners.clear();\n this.status = \"pending\";\n }\n\n on(_event: \"ready\" | \"change\" | \"error\", callback: Listener): () => void {\n this.listeners.add(callback);\n return () => this.listeners.delete(callback);\n }\n\n focus(): void {\n this.send({ type: \"arcpay:focus\" });\n }\n\n clear(): void {\n this.send({ type: \"arcpay:clear\" });\n }\n\n isReady(): boolean {\n return this.status === \"ready\";\n }\n\n /**\n * Internal: returns the iframe's contentWindow for source-filtering in\n * Elements.doTokenize(). Returns null when the iframe is not yet mounted\n * or when jsdom has not yet populated contentWindow (test environment).\n */\n getIframeContentWindow(): Window | null {\n return this.iframe?.contentWindow ?? null;\n }\n\n /** Internal: used by Elements factory to send tokenize commands. */\n send(message: ParentToIframe): void {\n if (!this.iframe) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"not_mounted\",\n message: `Element ${this.field} is not mounted`,\n retryable: false,\n });\n }\n postToIframe(this.iframe, message, new URL(this.context.iframeBase).origin);\n }\n\n private emit(event: ElementEvent): void {\n for (const listener of this.listeners) {\n listener(event);\n }\n }\n}\n","import { ArcPayError } from \"../core/errors\";\nimport { Element, type ElementContext, type ElementOptions } from \"./element\";\nimport type { FieldType, IframeToParent } from \"./postmessage\";\nimport { parseIncoming } from \"./postmessage\";\nimport type { TokenizeResult } from \"../tokenize/tokenize\";\n\nexport type { TokenizeResult };\n\nexport type ElementsOptions = Record<string, never>;\n\nconst DEFAULT_IFRAME_BASE = \"https://sdk.arcpay.space\";\n\nconst createChannelId = (): string => {\n if (!globalThis.crypto?.randomUUID) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"crypto_unavailable\",\n message: \"crypto.randomUUID is required for Hosted Fields\",\n retryable: false,\n });\n }\n return globalThis.crypto.randomUUID();\n};\n\nexport class Elements {\n private readonly elementMap = new Map<FieldType, Element>();\n private readonly iframeBase: string;\n private readonly publishableKey: string;\n private readonly channelId: string;\n private tokenizeInFlight = false;\n\n constructor(opts: { publishableKey: string; iframeBase?: string }) {\n this.publishableKey = opts.publishableKey;\n this.iframeBase = opts.iframeBase ?? DEFAULT_IFRAME_BASE;\n this.channelId = createChannelId();\n }\n\n create(field: FieldType, options: ElementOptions = {}): Element {\n if (this.elementMap.has(field)) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"duplicate_element\",\n message: `Element for ${field} already created`,\n retryable: false,\n });\n }\n const ctx: ElementContext = {\n iframeBase: this.iframeBase,\n publishableKey: this.publishableKey,\n channelId: this.channelId,\n };\n const element = new Element(field, options, ctx);\n this.elementMap.set(field, element);\n return element;\n }\n\n async tokenize(paymentId: string, idempotencyKey: string): Promise<TokenizeResult> {\n // C2: concurrent-call guard — only one tokenize() may be in-flight at a time.\n if (this.tokenizeInFlight) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"tokenize_in_progress\",\n message: \"A tokenize() call is already in progress for this Elements instance\",\n retryable: false,\n });\n }\n\n const cardNumber = this.elementMap.get(\"cardNumber\");\n const cardExpiry = this.elementMap.get(\"cardExpiry\");\n const cardCvv = this.elementMap.get(\"cardCvv\");\n\n if (!cardNumber || !cardExpiry || !cardCvv) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"incomplete_elements\",\n message:\n \"All three elements (cardNumber, cardExpiry, cardCvv) must be created and mounted before tokenize()\",\n retryable: false,\n });\n }\n if (!cardNumber.isReady() || !cardExpiry.isReady() || !cardCvv.isReady()) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"elements_not_ready\",\n message: \"Wait for all elements to fire 'ready' event before tokenize()\",\n retryable: false,\n });\n }\n\n this.tokenizeInFlight = true;\n try {\n return await this.doTokenize(cardNumber, paymentId, idempotencyKey);\n } finally {\n this.tokenizeInFlight = false;\n }\n }\n\n private doTokenize(\n cardNumber: Element,\n paymentId: string,\n idempotencyKey: string,\n ): Promise<TokenizeResult> {\n const iframeOrigin = new URL(this.iframeBase).origin;\n // C1: obtain reference to the cardNumber iframe's contentWindow before\n // registering the listener so we can filter by source.\n const cardIframeWindow = cardNumber.getIframeContentWindow();\n\n return new Promise<TokenizeResult>((resolve, reject) => {\n // C3: 30-second timeout — rejects and cleans up if no result arrives.\n const timer = window.setTimeout(() => {\n window.removeEventListener(\"message\", onMessage);\n reject(\n new ArcPayError({\n type: \"network_error\",\n code: \"tokenize_timeout\",\n message: \"tokenize() timed out after 30 seconds\",\n retryable: true,\n paymentId,\n }),\n );\n }, 30_000);\n\n const onMessage = (event: MessageEvent) => {\n // C1: source guard — only accept messages from the cardNumber iframe.\n if (cardIframeWindow !== null && event.source !== cardIframeWindow) return;\n // C4: use parseIncoming for origin + arcpay: prefix guard.\n const data = parseIncoming<IframeToParent>(event, iframeOrigin);\n if (!data) return;\n\n if (data.type === \"arcpay:tokenize-result\") {\n clearTimeout(timer);\n window.removeEventListener(\"message\", onMessage);\n resolve({\n cardTokenId: data.cardTokenId,\n cardMask: data.cardMask,\n cardScheme: data.cardScheme,\n cardBin: data.cardBin,\n expiresIn: data.expiresIn,\n expiresAt: data.expiresAt,\n });\n } else if (data.type === \"arcpay:tokenize-error\") {\n clearTimeout(timer);\n window.removeEventListener(\"message\", onMessage);\n const errType =\n data.errorType === \"validation_error\" || data.errorType === \"api_error\"\n ? data.errorType\n : \"api_error\";\n reject(\n new ArcPayError({\n type: errType,\n code: data.code,\n message: data.message,\n retryable: false,\n paymentId,\n }),\n );\n }\n };\n\n window.addEventListener(\"message\", onMessage);\n cardNumber.send({ type: \"arcpay:tokenize\", paymentId, idempotencyKey });\n });\n }\n\n destroy(): void {\n for (const el of this.elementMap.values()) {\n el.destroy();\n }\n this.elementMap.clear();\n }\n}\n","import { verifyCspAllowsApiBase } from \"./csp\";\nimport {\n detectEnvironment,\n type Environment,\n validatePublishableKey as _validatePublishableKey,\n} from \"./env\";\nimport { showSandboxBanner } from \"./sandbox-banner\";\nimport { Elements, type ElementsOptions } from \"../elements/elements\";\n\nconst validatePublishableKey: (key: unknown) => asserts key is string = _validatePublishableKey;\n\nexport interface ArcPayLoadOptions {\n apiBase?: string;\n}\n\nconst DEFAULT_API_BASE = \"https://api.arcpay.space\";\n\nexport interface ArcPayInstance {\n readonly publishableKey: string;\n readonly apiBase: string;\n readonly environment: Environment;\n elements: (opts?: ElementsOptions) => Elements;\n}\n\nconst cache = new Map<string, Promise<ArcPayInstance>>();\n\nconst buildInstance = (publishableKey: string, opts: ArcPayLoadOptions): ArcPayInstance => {\n const apiBase = opts.apiBase ?? DEFAULT_API_BASE;\n verifyCspAllowsApiBase(apiBase);\n if (detectEnvironment(publishableKey) === \"sandbox\") {\n showSandboxBanner();\n }\n return {\n publishableKey,\n apiBase,\n environment: detectEnvironment(publishableKey),\n elements: () => new Elements({ publishableKey }),\n };\n};\n\nfunction load(publishableKey: string, opts: ArcPayLoadOptions = {}): Promise<ArcPayInstance> {\n try {\n validatePublishableKey(publishableKey);\n } catch (err) {\n return Promise.reject(err);\n }\n const key = `${publishableKey}|${opts.apiBase ?? DEFAULT_API_BASE}`;\n const existing = cache.get(key);\n if (existing) return existing;\n const promise = Promise.resolve(buildInstance(publishableKey, opts));\n cache.set(key, promise);\n return promise;\n}\n\nconst resetForTests = (): void => {\n cache.clear();\n};\n\nexport const ArcPay = {\n load,\n __resetForTests: resetForTests,\n};\n","import { ArcPay, type ArcPayInstance, type ArcPayLoadOptions } from \"../index\";\nimport * as React from \"react\";\n\nexport type ArcPayState =\n | { status: \"loading\"; instance: null; error: null }\n | { status: \"ready\"; instance: ArcPayInstance; error: null }\n | { status: \"error\"; instance: null; error: Error };\n\nconst Ctx = React.createContext<ArcPayState | null>(null);\n\nexport interface ArcPayProviderProps extends ArcPayLoadOptions {\n publishableKey: string;\n children: React.ReactNode;\n}\n\nexport const ArcPayProvider: React.FC<ArcPayProviderProps> = ({\n publishableKey,\n apiBase,\n children,\n}) => {\n const [state, setState] = React.useState<ArcPayState>({\n status: \"loading\",\n instance: null,\n error: null,\n });\n\n React.useEffect(() => {\n let canceled = false;\n ArcPay.load(publishableKey, { apiBase })\n .then((instance) => {\n if (!canceled) setState({ status: \"ready\", instance, error: null });\n })\n .catch((error: unknown) => {\n if (!canceled)\n setState({\n status: \"error\",\n instance: null,\n error: error instanceof Error ? error : new Error(String(error)),\n });\n });\n return () => {\n canceled = true;\n };\n }, [publishableKey, apiBase]);\n\n return <Ctx.Provider value={state}>{children}</Ctx.Provider>;\n};\n\nexport const ArcPayContext = Ctx;\n","import * as React from \"react\";\nimport { ArcPayContext, type ArcPayState } from \"./provider\";\n\nexport const useArcPay = (): ArcPayState => {\n const ctx = React.useContext(ArcPayContext);\n if (!ctx) throw new Error(\"useArcPay must be called within an ArcPayProvider\");\n return ctx;\n};\n","export { ArcPayProvider, ArcPayContext } from \"./provider\";\nexport type { ArcPayProviderProps, ArcPayState } from \"./provider\";\nexport { useArcPay } from \"./use-arcpay\";\nexport const REACT_WRAPPER_VERSION = \"0.1.0\";\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/core/errors.ts","../../src/core/env.ts","../../src/core/sandbox-banner.ts","../../src/elements/postmessage.ts","../../src/elements/style.ts","../../src/elements/element.ts","../../src/elements/elements.ts","../../src/core/arcpay.ts","../../src/react/provider.tsx","../../src/react/use-arcpay.ts","../../src/react/index.ts"],"names":["validatePublishableKey","React2"],"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;;;ACrCO,IAAM,oBAAoB,CAAC,cAAA,KAChC,eAAe,UAAA,CAAW,UAAU,IAAI,SAAA,GAAY,MAAA;AAE/C,IAAM,sBAAA,GAAyB,CAAC,GAAA,KAAwC;AAC7E,EAAA,IAAI,OAAO,GAAA,KAAQ,QAAA,IAAY,GAAA,CAAI,WAAW,CAAA,EAAG;AAC/C,IAAA,MAAM,IAAI,WAAA,CAAY;AAAA,MACpB,IAAA,EAAM,kBAAA;AAAA,MACN,IAAA,EAAM,yBAAA;AAAA,MACN,OAAA,EAAS,4CAAA;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,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,CAAA,QAAA,CAAsB;AAAA,IACpD,MAAA,EAAQ,SAAA;AAAA,IACR,QAAA,EAAU,IAAA;AAAA,IACV,KAAA,EAAO;AAAA,GACR,CAAA;AAED,EAAM,gBAAU,MAAM;AACpB,IAAA,IAAI,QAAA,GAAW,KAAA;AACf,IAAA,MAAA,CAAO,IAAA,CAAK,cAAc,CAAA,CACvB,IAAA,CAAK,CAAC,QAAA,KAAa;AAClB,MAAA,IAAI,CAAC,UAAU,QAAA,CAAS,EAAE,QAAQ,OAAA,EAAS,QAAA,EAAU,KAAA,EAAO,IAAA,EAAM,CAAA;AAAA,IACpE,CAAC,CAAA,CACA,KAAA,CAAM,CAAC,KAAA,KAAmB;AACzB,MAAA,IAAI,CAAC,QAAA;AACH,QAAA,QAAA,CAAS;AAAA,UACP,MAAA,EAAQ,OAAA;AAAA,UACR,QAAA,EAAU,IAAA;AAAA,UACV,KAAA,EAAO,iBAAiB,KAAA,GAAQ,KAAA,GAAQ,IAAI,KAAA,CAAM,MAAA,CAAO,KAAK,CAAC;AAAA,SAChE,CAAA;AAAA,IACL,CAAC,CAAA;AACH,IAAA,OAAO,MAAM;AACX,MAAA,QAAA,GAAW,IAAA;AAAA,IACb,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,cAAc,CAAC,CAAA;AAEnB,EAAA,2BAAQ,GAAA,CAAI,QAAA,EAAJ,EAAa,KAAA,EAAO,OAAQ,QAAA,EAAS,CAAA;AAC/C;AAEO,IAAM,aAAA,GAAgB;ACzCtB,IAAM,YAAY,MAAmB;AAC1C,EAAA,MAAM,GAAA,GAAYC,iBAAW,aAAa,CAAA;AAC1C,EAAA,IAAI,CAAC,GAAA,EAAK,MAAM,IAAI,MAAM,mDAAmD,CAAA;AAC7E,EAAA,OAAO,GAAA;AACT;;;ACJO,IAAM,qBAAA,GAAwB","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 } from \"./errors\";\n\nexport type Environment = \"sandbox\" | \"live\";\n\nexport const detectEnvironment = (publishableKey: string): Environment =>\n publishableKey.startsWith(\"pk_test_\") ? \"sandbox\" : \"live\";\n\nexport const validatePublishableKey = (key: unknown): asserts key is string => {\n if (typeof key !== \"string\" || key.length === 0) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"invalid_publishable_key\",\n message: \"Publishable key must be a non-empty string\",\n retryable: false,\n });\n }\n if (!key.startsWith(\"pk_test_\") && !key.startsWith(\"pk_live_\")) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"invalid_publishable_key\",\n message:\n \"Publishable key must start with pk_test_ or pk_live_. Secret keys (sk_*) cannot be used in browser.\",\n retryable: false,\n });\n }\n};\n","const BANNER_ATTR = \"data-arcpay-sandbox-banner\";\n\nexport const showSandboxBanner = (): void => {\n if (typeof document === \"undefined\") return;\n if (document.querySelector(`[${BANNER_ATTR}]`)) return;\n\n const bar = document.createElement(\"div\");\n bar.setAttribute(BANNER_ATTR, \"\");\n bar.style.cssText =\n \"position:fixed;top:0;left:0;right:0;z-index:2147483647;background:#ffd166;color:#222;font:13px/1.4 system-ui,sans-serif;padding:6px 12px;display:flex;align-items:center;justify-content:center;box-shadow:0 1px 3px rgba(0,0,0,0.1);\";\n\n const text = document.createElement(\"span\");\n text.textContent = \"ARC PAY TEST MODE — payments are simulated\";\n bar.appendChild(text);\n\n const dismiss = document.createElement(\"button\");\n dismiss.type = \"button\";\n dismiss.setAttribute(\"data-arcpay-banner-dismiss\", \"\");\n dismiss.textContent = \"×\";\n dismiss.setAttribute(\"aria-label\", \"Dismiss test mode banner\");\n dismiss.style.cssText =\n \"margin-left:12px;background:transparent;border:0;font-size:18px;cursor:pointer;color:inherit;\";\n dismiss.addEventListener(\"click\", () => bar.remove());\n bar.appendChild(dismiss);\n\n document.body.appendChild(bar);\n};\n","import { ArcPayError } from \"../core/errors\";\n\nexport type FieldType = \"cardNumber\" | \"cardExpiry\" | \"cardCvv\";\n\n// Parent → iframe\nexport type ParentToIframe =\n | { type: \"arcpay:hello\"; origin: string; publishableKey: string; channelId: string }\n | { type: \"arcpay:style\"; payload: StyleSubset }\n | { type: \"arcpay:focus\" }\n | { type: \"arcpay:clear\" }\n | { type: \"arcpay:tokenize\"; paymentId: string; idempotencyKey: string };\n\n// iframe → parent\nexport type IframeToParent =\n | { type: \"arcpay:ready\" }\n | { type: \"arcpay:rejected\"; reason: string }\n | {\n type: \"arcpay:change\";\n field: FieldType;\n isValid: boolean;\n brand?: string;\n lastFour?: string;\n }\n | {\n type: \"arcpay:tokenize-result\";\n cardTokenId: string;\n cardMask: string;\n cardScheme: string;\n cardBin: string;\n expiresIn: number;\n expiresAt: string;\n }\n | { type: \"arcpay:tokenize-error\"; errorType: string; code?: string; message: string };\n\nexport interface StyleSubset {\n base: Record<string, string>;\n invalid?: Record<string, string>;\n focus?: Record<string, string>;\n}\n\nconst ARCPAY_TYPE_PREFIX = \"arcpay:\";\n\nconst isArcpayMessage = (data: unknown): data is { type: string } =>\n typeof data === \"object\" &&\n data !== null &&\n \"type\" in data &&\n typeof (data as { type: unknown }).type === \"string\" &&\n (data as { type: string }).type.startsWith(ARCPAY_TYPE_PREFIX);\n\nexport const postToIframe = (\n iframe: HTMLIFrameElement,\n message: ParentToIframe,\n targetOrigin: string,\n): void => {\n if (targetOrigin === \"*\") {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"wildcard_origin_forbidden\",\n message: \"postToIframe: targetOrigin cannot be '*'\",\n retryable: false,\n });\n }\n if (!iframe.contentWindow) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"iframe_not_loaded\",\n message: \"postToIframe: iframe.contentWindow is null (iframe not mounted)\",\n retryable: false,\n });\n }\n iframe.contentWindow.postMessage(message, targetOrigin);\n};\n\nexport const postToParent = (message: IframeToParent, targetOrigin: string): void => {\n if (targetOrigin === \"*\") {\n throw new Error(\"postToParent: targetOrigin cannot be '*'\");\n }\n window.parent.postMessage(message, targetOrigin);\n};\n\nexport const parseIncoming = <T extends { type: string }>(\n event: MessageEvent,\n expectedOrigin: string,\n): T | null => {\n if (event.origin !== expectedOrigin) return null;\n if (!isArcpayMessage(event.data)) return null;\n return event.data as T;\n};\n","import type { StyleSubset } from \"./postmessage\";\n\n// Spec calls out position:fixed, transform, pointer-events:none as forbidden.\n// We extend to cover the full clickjacking attack surface: any positioning\n// (fixed/absolute/sticky), transform, all pointer-events values, z-index, and\n// inset properties (top/left/right/bottom/inset). The legitimate use cases\n// for these in a 1-line input field are zero, so blanket drop.\nconst FORBIDDEN_PROPERTIES = new Set([\n \"position\",\n \"transform\",\n \"pointer-events\",\n \"z-index\",\n \"top\",\n \"left\",\n \"right\",\n \"bottom\",\n \"inset\",\n]);\n\nconst sanitizeBlock = (block: Record<string, string>): Record<string, string> => {\n const out: Record<string, string> = {};\n for (const [key, value] of Object.entries(block)) {\n const normalizedKey = key.toLowerCase();\n if (FORBIDDEN_PROPERTIES.has(normalizedKey)) {\n // Defense against position/transform-based clickjacking. Silently drop.\n continue;\n }\n out[key] = value;\n }\n return out;\n};\n\nexport const sanitizeStyle = (style: StyleSubset): StyleSubset => {\n const result: StyleSubset = { base: sanitizeBlock(style.base) };\n if (style.invalid !== undefined) result.invalid = sanitizeBlock(style.invalid);\n if (style.focus !== undefined) result.focus = sanitizeBlock(style.focus);\n return result;\n};\n","import { ArcPayError } from \"../core/errors\";\nimport {\n type FieldType,\n type ParentToIframe,\n type IframeToParent,\n type StyleSubset,\n postToIframe,\n parseIncoming,\n} from \"./postmessage\";\nimport { sanitizeStyle } from \"./style\";\n\nexport interface ElementOptions {\n /** StyleSubset applied via arcpay:style postMessage. */\n style?: StyleSubset;\n placeholder?: string;\n}\n\nexport type ElementEvent =\n | { type: \"ready\" }\n | { type: \"change\"; isValid: boolean; brand?: string; lastFour?: string }\n | { type: \"error\"; reason: string };\n\ntype Listener = (event: ElementEvent) => void;\n\nexport interface ElementContext {\n iframeBase: string;\n publishableKey: string;\n channelId: string;\n}\n\nexport class Element {\n private iframe: HTMLIFrameElement | null = null;\n private readonly listeners = new Set<Listener>();\n private status: \"pending\" | \"ready\" | \"error\" = \"pending\";\n private messageHandler: ((e: MessageEvent) => void) | null = null;\n\n constructor(\n public readonly field: FieldType,\n private readonly options: ElementOptions,\n private readonly context: ElementContext,\n ) {}\n\n mount(target: string | HTMLElement): void {\n if (this.iframe) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"already_mounted\",\n message: `Element ${this.field} is already mounted`,\n retryable: false,\n });\n }\n const container = typeof target === \"string\" ? document.querySelector(target) : target;\n if (!(container instanceof HTMLElement)) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"mount_target_not_found\",\n message: `mount target not found: ${String(target)}`,\n retryable: false,\n });\n }\n\n const iframe = document.createElement(\"iframe\");\n iframe.src = `${this.context.iframeBase}/iframe/${this.field}`;\n iframe.style.cssText = \"border:0;width:100%;height:100%;display:block;\";\n iframe.setAttribute(\"allow\", \"payment\");\n iframe.setAttribute(\"data-arcpay-element\", this.field);\n container.appendChild(iframe);\n this.iframe = iframe;\n\n const expectedOrigin = new URL(this.context.iframeBase).origin;\n\n this.messageHandler = (event: MessageEvent) => {\n // C1: source guard — only accept messages from this element's own iframe.\n // Without this, any iframe at the same origin (e.g. cardExpiry, cardCvv)\n // could trigger handlers on cardNumber and vice-versa.\n if (event.source !== this.iframe?.contentWindow) return;\n // C4: use parseIncoming for origin + arcpay: prefix guard.\n const data = parseIncoming<IframeToParent>(event, expectedOrigin);\n if (!data) return;\n this.handleMessage(data);\n };\n window.addEventListener(\"message\", this.messageHandler);\n\n iframe.addEventListener(\n \"load\",\n () => {\n if (!this.iframe) return;\n const hello: ParentToIframe = {\n type: \"arcpay:hello\",\n origin: window.location.origin,\n publishableKey: this.context.publishableKey,\n channelId: this.context.channelId,\n };\n postToIframe(this.iframe, hello, expectedOrigin);\n },\n { once: true },\n );\n }\n\n private handleMessage(data: IframeToParent): void {\n if (data.type === \"arcpay:ready\") {\n this.status = \"ready\";\n // Apply initial style if provided at construction time.\n if (this.options.style) {\n this.send({ type: \"arcpay:style\", payload: sanitizeStyle(this.options.style) });\n }\n this.emit({ type: \"ready\" });\n } else if (data.type === \"arcpay:rejected\") {\n this.status = \"error\";\n this.emit({ type: \"error\", reason: data.reason });\n } else if (data.type === \"arcpay:change\" && data.field === this.field) {\n this.emit({\n type: \"change\",\n isValid: data.isValid,\n brand: data.brand,\n lastFour: data.lastFour,\n });\n }\n // arcpay:tokenize-result / arcpay:tokenize-error handled by Elements factory (Task 9).\n }\n\n update(options: { style?: StyleSubset }): void {\n if (options.style) {\n this.send({ type: \"arcpay:style\", payload: sanitizeStyle(options.style) });\n }\n }\n\n destroy(): void {\n if (this.iframe) {\n this.iframe.remove();\n this.iframe = null;\n }\n if (this.messageHandler) {\n window.removeEventListener(\"message\", this.messageHandler);\n this.messageHandler = null;\n }\n this.listeners.clear();\n this.status = \"pending\";\n }\n\n on(_event: \"ready\" | \"change\" | \"error\", callback: Listener): () => void {\n this.listeners.add(callback);\n return () => this.listeners.delete(callback);\n }\n\n focus(): void {\n this.send({ type: \"arcpay:focus\" });\n }\n\n clear(): void {\n this.send({ type: \"arcpay:clear\" });\n }\n\n isReady(): boolean {\n return this.status === \"ready\";\n }\n\n /**\n * Internal: returns the iframe's contentWindow for source-filtering in\n * Elements.doTokenize(). Returns null when the iframe is not yet mounted\n * or when jsdom has not yet populated contentWindow (test environment).\n */\n getIframeContentWindow(): Window | null {\n return this.iframe?.contentWindow ?? null;\n }\n\n /** Internal: used by Elements factory to send tokenize commands. */\n send(message: ParentToIframe): void {\n if (!this.iframe) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"not_mounted\",\n message: `Element ${this.field} is not mounted`,\n retryable: false,\n });\n }\n postToIframe(this.iframe, message, new URL(this.context.iframeBase).origin);\n }\n\n private emit(event: ElementEvent): void {\n for (const listener of this.listeners) {\n listener(event);\n }\n }\n}\n","import { ArcPayError } from \"../core/errors\";\nimport { Element, type ElementContext, type ElementOptions } from \"./element\";\nimport type { FieldType, IframeToParent } from \"./postmessage\";\nimport { parseIncoming } from \"./postmessage\";\nimport type { TokenizeResult } from \"../tokenize/tokenize\";\n\nexport type { TokenizeResult };\n\nexport type ElementsOptions = Record<string, never>;\n\nconst DEFAULT_IFRAME_BASE = \"https://sdk.arcpay.space\";\n\nconst createChannelId = (): string => {\n if (!globalThis.crypto?.randomUUID) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"crypto_unavailable\",\n message: \"crypto.randomUUID is required for Hosted Fields\",\n retryable: false,\n });\n }\n return globalThis.crypto.randomUUID();\n};\n\nexport class Elements {\n private readonly elementMap = new Map<FieldType, Element>();\n private readonly iframeBase: string;\n private readonly publishableKey: string;\n private readonly channelId: string;\n private tokenizeInFlight = false;\n\n constructor(opts: { publishableKey: string; iframeBase?: string }) {\n this.publishableKey = opts.publishableKey;\n this.iframeBase = opts.iframeBase ?? DEFAULT_IFRAME_BASE;\n this.channelId = createChannelId();\n }\n\n create(field: FieldType, options: ElementOptions = {}): Element {\n if (this.elementMap.has(field)) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"duplicate_element\",\n message: `Element for ${field} already created`,\n retryable: false,\n });\n }\n const ctx: ElementContext = {\n iframeBase: this.iframeBase,\n publishableKey: this.publishableKey,\n channelId: this.channelId,\n };\n const element = new Element(field, options, ctx);\n this.elementMap.set(field, element);\n return element;\n }\n\n async tokenize(paymentId: string, idempotencyKey: string): Promise<TokenizeResult> {\n // C2: concurrent-call guard — only one tokenize() may be in-flight at a time.\n if (this.tokenizeInFlight) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"tokenize_in_progress\",\n message: \"A tokenize() call is already in progress for this Elements instance\",\n retryable: false,\n });\n }\n\n const cardNumber = this.elementMap.get(\"cardNumber\");\n const cardExpiry = this.elementMap.get(\"cardExpiry\");\n const cardCvv = this.elementMap.get(\"cardCvv\");\n\n if (!cardNumber || !cardExpiry || !cardCvv) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"incomplete_elements\",\n message:\n \"All three elements (cardNumber, cardExpiry, cardCvv) must be created and mounted before tokenize()\",\n retryable: false,\n });\n }\n if (!cardNumber.isReady() || !cardExpiry.isReady() || !cardCvv.isReady()) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"elements_not_ready\",\n message: \"Wait for all elements to fire 'ready' event before tokenize()\",\n retryable: false,\n });\n }\n\n this.tokenizeInFlight = true;\n try {\n return await this.doTokenize(cardNumber, paymentId, idempotencyKey);\n } finally {\n this.tokenizeInFlight = false;\n }\n }\n\n private doTokenize(\n cardNumber: Element,\n paymentId: string,\n idempotencyKey: string,\n ): Promise<TokenizeResult> {\n const iframeOrigin = new URL(this.iframeBase).origin;\n // C1: obtain reference to the cardNumber iframe's contentWindow before\n // registering the listener so we can filter by source.\n const cardIframeWindow = cardNumber.getIframeContentWindow();\n\n return new Promise<TokenizeResult>((resolve, reject) => {\n // C3: 30-second timeout — rejects and cleans up if no result arrives.\n const timer = window.setTimeout(() => {\n window.removeEventListener(\"message\", onMessage);\n reject(\n new ArcPayError({\n type: \"network_error\",\n code: \"tokenize_timeout\",\n message: \"tokenize() timed out after 30 seconds\",\n retryable: true,\n paymentId,\n }),\n );\n }, 30_000);\n\n const onMessage = (event: MessageEvent) => {\n // C1: source guard — only accept messages from the cardNumber iframe.\n if (cardIframeWindow !== null && event.source !== cardIframeWindow) return;\n // C4: use parseIncoming for origin + arcpay: prefix guard.\n const data = parseIncoming<IframeToParent>(event, iframeOrigin);\n if (!data) return;\n\n if (data.type === \"arcpay:tokenize-result\") {\n clearTimeout(timer);\n window.removeEventListener(\"message\", onMessage);\n resolve({\n cardTokenId: data.cardTokenId,\n cardMask: data.cardMask,\n cardScheme: data.cardScheme,\n cardBin: data.cardBin,\n expiresIn: data.expiresIn,\n expiresAt: data.expiresAt,\n });\n } else if (data.type === \"arcpay:tokenize-error\") {\n clearTimeout(timer);\n window.removeEventListener(\"message\", onMessage);\n const errType =\n data.errorType === \"validation_error\" || data.errorType === \"api_error\"\n ? data.errorType\n : \"api_error\";\n reject(\n new ArcPayError({\n type: errType,\n code: data.code,\n message: data.message,\n retryable: false,\n paymentId,\n }),\n );\n }\n };\n\n window.addEventListener(\"message\", onMessage);\n cardNumber.send({ type: \"arcpay:tokenize\", paymentId, idempotencyKey });\n });\n }\n\n destroy(): void {\n for (const el of this.elementMap.values()) {\n el.destroy();\n }\n this.elementMap.clear();\n }\n}\n","import {\n detectEnvironment,\n type Environment,\n validatePublishableKey as _validatePublishableKey,\n} from \"./env\";\nimport { showSandboxBanner } from \"./sandbox-banner\";\nimport { Elements, type ElementsOptions } from \"../elements/elements\";\n\nconst validatePublishableKey: (key: unknown) => asserts key is string = _validatePublishableKey;\n\nexport interface ArcPayLoadOptions {\n readonly _reserved?: never;\n}\n\nexport interface ArcPayInstance {\n readonly publishableKey: string;\n readonly environment: Environment;\n elements: (opts?: ElementsOptions) => Elements;\n}\n\nconst cache = new Map<string, Promise<ArcPayInstance>>();\n\nconst buildInstance = (publishableKey: string): ArcPayInstance => {\n if (detectEnvironment(publishableKey) === \"sandbox\") {\n showSandboxBanner();\n }\n return {\n publishableKey,\n environment: detectEnvironment(publishableKey),\n elements: () => new Elements({ publishableKey }),\n };\n};\n\nfunction load(publishableKey: string): Promise<ArcPayInstance> {\n try {\n validatePublishableKey(publishableKey);\n } catch (err) {\n return Promise.reject(err);\n }\n const key = publishableKey;\n const existing = cache.get(key);\n if (existing) return existing;\n const promise = Promise.resolve(buildInstance(publishableKey));\n cache.set(key, promise);\n return promise;\n}\n\nconst resetForTests = (): void => {\n cache.clear();\n};\n\nexport const ArcPay = {\n load,\n __resetForTests: resetForTests,\n};\n","import { ArcPay, type ArcPayInstance } from \"../index\";\nimport * as React from \"react\";\n\nexport type ArcPayState =\n | { status: \"loading\"; instance: null; error: null }\n | { status: \"ready\"; instance: ArcPayInstance; error: null }\n | { status: \"error\"; instance: null; error: Error };\n\nconst Ctx = React.createContext<ArcPayState | null>(null);\n\nexport interface ArcPayProviderProps {\n publishableKey: string;\n children: React.ReactNode;\n}\n\nexport const ArcPayProvider: React.FC<ArcPayProviderProps> = ({ publishableKey, children }) => {\n const [state, setState] = React.useState<ArcPayState>({\n status: \"loading\",\n instance: null,\n error: null,\n });\n\n React.useEffect(() => {\n let canceled = false;\n ArcPay.load(publishableKey)\n .then((instance) => {\n if (!canceled) setState({ status: \"ready\", instance, error: null });\n })\n .catch((error: unknown) => {\n if (!canceled)\n setState({\n status: \"error\",\n instance: null,\n error: error instanceof Error ? error : new Error(String(error)),\n });\n });\n return () => {\n canceled = true;\n };\n }, [publishableKey]);\n\n return <Ctx.Provider value={state}>{children}</Ctx.Provider>;\n};\n\nexport const ArcPayContext = Ctx;\n","import * as React from \"react\";\nimport { ArcPayContext, type ArcPayState } from \"./provider\";\n\nexport const useArcPay = (): ArcPayState => {\n const ctx = React.useContext(ArcPayContext);\n if (!ctx) throw new Error(\"useArcPay must be called within an ArcPayProvider\");\n return ctx;\n};\n","export { ArcPayProvider, ArcPayContext } from \"./provider\";\nexport type { ArcPayProviderProps, ArcPayState } from \"./provider\";\nexport { useArcPay } from \"./use-arcpay\";\nexport const REACT_WRAPPER_VERSION = \"0.1.3\";\n"]}
|
package/dist/server/index.cjs
CHANGED
|
@@ -60,6 +60,11 @@ var appendQuery = (path, query) => {
|
|
|
60
60
|
return encoded ? `${path}?${encoded}` : path;
|
|
61
61
|
};
|
|
62
62
|
var isPublicErrorType = (value) => value === "validation_error" || value === "authentication_error" || value === "authorization_error" || value === "state_error" || value === "rate_limit_error" || value === "api_error";
|
|
63
|
+
var isRetryableError = (type, status, code) => {
|
|
64
|
+
if (type === "rate_limit_error") return true;
|
|
65
|
+
if (code === "timeout") return false;
|
|
66
|
+
return type === "api_error" && status >= 500;
|
|
67
|
+
};
|
|
63
68
|
var parseErrorResponse = async (res) => {
|
|
64
69
|
var _a, _b;
|
|
65
70
|
let body = {};
|
|
@@ -76,7 +81,7 @@ var parseErrorResponse = async (res) => {
|
|
|
76
81
|
param: detail.param,
|
|
77
82
|
requestId: detail.request_id,
|
|
78
83
|
declineCode: detail.decline_code,
|
|
79
|
-
retryable: type
|
|
84
|
+
retryable: isRetryableError(type, res.status, detail.code)
|
|
80
85
|
});
|
|
81
86
|
};
|
|
82
87
|
var ArcPayClient = class {
|
|
@@ -137,6 +142,9 @@ var ArcPayClient = class {
|
|
|
137
142
|
true
|
|
138
143
|
);
|
|
139
144
|
}
|
|
145
|
+
async chargeSavedCard(body, opts) {
|
|
146
|
+
return this.request("POST", "/payments/saved-card", body, opts, true);
|
|
147
|
+
}
|
|
140
148
|
async executePayment(paymentId, body, opts) {
|
|
141
149
|
return this.request(
|
|
142
150
|
"POST",
|
|
@@ -165,6 +173,12 @@ var ArcPayClient = class {
|
|
|
165
173
|
async createLink(body, opts) {
|
|
166
174
|
return this.request("POST", "/links", body, opts, true);
|
|
167
175
|
}
|
|
176
|
+
async getLink(linkId, opts = {}) {
|
|
177
|
+
return this.request("GET", `/links/${encodeURIComponent(linkId)}`, void 0, opts);
|
|
178
|
+
}
|
|
179
|
+
async cancelLink(linkId, opts = {}) {
|
|
180
|
+
return this.request("DELETE", `/links/${encodeURIComponent(linkId)}`, void 0, opts);
|
|
181
|
+
}
|
|
168
182
|
async createCheckoutSession(body, opts) {
|
|
169
183
|
return this.request("POST", "/checkout/sessions", body, opts, true);
|
|
170
184
|
}
|
|
@@ -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;A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,OAAA,EAAU,IAAA,CAAK,SAAS,CAAA,CAAA;AAAA,MACvC,uBAAA,EAAyB,WAAA;AAAA,MACzB,cAAA,EAAgB;AAAA,KAClB;AACA,IAAA,IAAI,kBAAA,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.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,OAAA,EAAS,uCAAA;AAAA,MACT,SAAA,EAAW;AAAA,KACZ,CAAA;AAAA,EACH;AACA,EAAA,IAAI,CAAC,IAAI,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A,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.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 isRetryableError = (type: ArcPayErrorType, status: number, code?: string): boolean => {\n if (type === \"rate_limit_error\") return true;\n if (code === \"timeout\") return false;\n return type === \"api_error\" && status >= 500;\n};\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: isRetryableError(type, res.status, detail.code),\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
|
@@ -58,6 +58,11 @@ var appendQuery = (path, query) => {
|
|
|
58
58
|
return encoded ? `${path}?${encoded}` : path;
|
|
59
59
|
};
|
|
60
60
|
var isPublicErrorType = (value) => value === "validation_error" || value === "authentication_error" || value === "authorization_error" || value === "state_error" || value === "rate_limit_error" || value === "api_error";
|
|
61
|
+
var isRetryableError = (type, status, code) => {
|
|
62
|
+
if (type === "rate_limit_error") return true;
|
|
63
|
+
if (code === "timeout") return false;
|
|
64
|
+
return type === "api_error" && status >= 500;
|
|
65
|
+
};
|
|
61
66
|
var parseErrorResponse = async (res) => {
|
|
62
67
|
var _a, _b;
|
|
63
68
|
let body = {};
|
|
@@ -74,7 +79,7 @@ var parseErrorResponse = async (res) => {
|
|
|
74
79
|
param: detail.param,
|
|
75
80
|
requestId: detail.request_id,
|
|
76
81
|
declineCode: detail.decline_code,
|
|
77
|
-
retryable: type
|
|
82
|
+
retryable: isRetryableError(type, res.status, detail.code)
|
|
78
83
|
});
|
|
79
84
|
};
|
|
80
85
|
var ArcPayClient = class {
|
|
@@ -135,6 +140,9 @@ var ArcPayClient = class {
|
|
|
135
140
|
true
|
|
136
141
|
);
|
|
137
142
|
}
|
|
143
|
+
async chargeSavedCard(body, opts) {
|
|
144
|
+
return this.request("POST", "/payments/saved-card", body, opts, true);
|
|
145
|
+
}
|
|
138
146
|
async executePayment(paymentId, body, opts) {
|
|
139
147
|
return this.request(
|
|
140
148
|
"POST",
|
|
@@ -163,6 +171,12 @@ var ArcPayClient = class {
|
|
|
163
171
|
async createLink(body, opts) {
|
|
164
172
|
return this.request("POST", "/links", body, opts, true);
|
|
165
173
|
}
|
|
174
|
+
async getLink(linkId, opts = {}) {
|
|
175
|
+
return this.request("GET", `/links/${encodeURIComponent(linkId)}`, void 0, opts);
|
|
176
|
+
}
|
|
177
|
+
async cancelLink(linkId, opts = {}) {
|
|
178
|
+
return this.request("DELETE", `/links/${encodeURIComponent(linkId)}`, void 0, opts);
|
|
179
|
+
}
|
|
166
180
|
async createCheckoutSession(body, opts) {
|
|
167
181
|
return this.request("POST", "/checkout/sessions", body, opts, true);
|
|
168
182
|
}
|