@alphawebai/hs-prism 0.1.0-rc.27
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/LICENSE +201 -0
- package/README.md +493 -0
- package/dist/src/alphaweb/contracts.d.ts +6 -0
- package/dist/src/alphaweb/contracts.js +14 -0
- package/dist/src/alphaweb/error.d.ts +13 -0
- package/dist/src/alphaweb/error.js +100 -0
- package/dist/src/alphaweb/index.d.ts +3 -0
- package/dist/src/alphaweb/index.js +22 -0
- package/dist/src/alphaweb/manifest.d.ts +28 -0
- package/dist/src/alphaweb/manifest.js +55 -0
- package/dist/src/alphaweb/money.d.ts +19 -0
- package/dist/src/alphaweb/money.js +128 -0
- package/dist/src/alphaweb/stripe-connector.d.ts +58 -0
- package/dist/src/alphaweb/stripe-connector.js +1402 -0
- package/dist/src/alphaweb/types.d.ts +255 -0
- package/dist/src/alphaweb/types.js +3 -0
- package/dist/src/http_client.d.ts +58 -0
- package/dist/src/http_client.js +179 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.js +41 -0
- package/dist/src/payments/_generated_connector_client_flows.d.ts +112 -0
- package/dist/src/payments/_generated_connector_client_flows.js +215 -0
- package/dist/src/payments/_generated_flows.js +141 -0
- package/dist/src/payments/_generated_grpc_client.d.ts +194 -0
- package/dist/src/payments/_generated_grpc_client.js +905 -0
- package/dist/src/payments/_generated_uniffi_client_flows.d.ts +169 -0
- package/dist/src/payments/_generated_uniffi_client_flows.js +342 -0
- package/dist/src/payments/connector_client.d.ts +51 -0
- package/dist/src/payments/connector_client.js +152 -0
- package/dist/src/payments/errors.d.ts +27 -0
- package/dist/src/payments/errors.js +39 -0
- package/dist/src/payments/generated/libconnector_service_ffi.so +0 -0
- package/dist/src/payments/generated/proto.d.ts +49087 -0
- package/dist/src/payments/generated/proto.js +154163 -0
- package/dist/src/payments/grpc_client.d.ts +1 -0
- package/dist/src/payments/grpc_client.js +20 -0
- package/dist/src/payments/uniffi_client.d.ts +40 -0
- package/dist/src/payments/uniffi_client.js +249 -0
- package/package.json +79 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toProviderMinorAmount = exports.getCurrencyRule = exports.fromProviderMinorAmount = exports.assertSafeProviderMoney = exports.normalizePrismError = exports.PrismOperationError = exports.ALPHAWEB_PRISM_COMPATIBILITY_MANIFEST = void 0;
|
|
4
|
+
var manifest_1 = require("./manifest");
|
|
5
|
+
Object.defineProperty(exports, "ALPHAWEB_PRISM_COMPATIBILITY_MANIFEST", { enumerable: true, get: function () { return manifest_1.ALPHAWEB_PRISM_COMPATIBILITY_MANIFEST; } });
|
|
6
|
+
var error_1 = require("./error");
|
|
7
|
+
Object.defineProperty(exports, "PrismOperationError", { enumerable: true, get: function () { return error_1.PrismOperationError; } });
|
|
8
|
+
Object.defineProperty(exports, "normalizePrismError", { enumerable: true, get: function () { return error_1.normalizePrismError; } });
|
|
9
|
+
var money_1 = require("./money");
|
|
10
|
+
Object.defineProperty(exports, "assertSafeProviderMoney", { enumerable: true, get: function () { return money_1.assertSafeProviderMoney; } });
|
|
11
|
+
Object.defineProperty(exports, "fromProviderMinorAmount", { enumerable: true, get: function () { return money_1.fromProviderMinorAmount; } });
|
|
12
|
+
Object.defineProperty(exports, "getCurrencyRule", { enumerable: true, get: function () { return money_1.getCurrencyRule; } });
|
|
13
|
+
Object.defineProperty(exports, "toProviderMinorAmount", { enumerable: true, get: function () { return money_1.toProviderMinorAmount; } });
|
|
14
|
+
//# sourceMappingURL=contracts.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface PrismOperationErrorShape {
|
|
2
|
+
category: 'configuration' | 'authentication' | 'validation' | 'customer_action' | 'declined' | 'rate_limited' | 'network' | 'provider_server' | 'conflict' | 'unknown';
|
|
3
|
+
providerCode?: string;
|
|
4
|
+
providerRequestId?: string;
|
|
5
|
+
retryable: boolean;
|
|
6
|
+
outcome: 'definitely_not_applied' | 'applied' | 'ambiguous';
|
|
7
|
+
safeMessage: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class PrismOperationError extends Error {
|
|
10
|
+
readonly shape: PrismOperationErrorShape;
|
|
11
|
+
constructor(shape: PrismOperationErrorShape, options?: ErrorOptions);
|
|
12
|
+
}
|
|
13
|
+
export declare function normalizePrismError(error: unknown): PrismOperationError;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PrismOperationError = void 0;
|
|
4
|
+
exports.normalizePrismError = normalizePrismError;
|
|
5
|
+
const errors_1 = require("../payments/errors");
|
|
6
|
+
class PrismOperationError extends Error {
|
|
7
|
+
shape;
|
|
8
|
+
constructor(shape, options) {
|
|
9
|
+
super(shape.safeMessage, options);
|
|
10
|
+
this.name = 'PrismOperationError';
|
|
11
|
+
this.shape = Object.freeze({ ...shape });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.PrismOperationError = PrismOperationError;
|
|
15
|
+
function readString(value) {
|
|
16
|
+
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
17
|
+
}
|
|
18
|
+
function recordOf(value) {
|
|
19
|
+
return typeof value === 'object' && value !== null ? value : {};
|
|
20
|
+
}
|
|
21
|
+
function normalizePrismError(error) {
|
|
22
|
+
if (error instanceof PrismOperationError)
|
|
23
|
+
return error;
|
|
24
|
+
const details = recordOf(error);
|
|
25
|
+
const cause = recordOf(details.cause);
|
|
26
|
+
const status = Number((error instanceof errors_1.ConnectorError ? error.httpStatusCode : undefined) ??
|
|
27
|
+
details.statusCode ??
|
|
28
|
+
details.status ??
|
|
29
|
+
cause.statusCode ??
|
|
30
|
+
cause.status);
|
|
31
|
+
const code = (error instanceof errors_1.IntegrationError || error instanceof errors_1.ConnectorError
|
|
32
|
+
? readString(error.errorCode)
|
|
33
|
+
: undefined) ??
|
|
34
|
+
readString(details.code) ??
|
|
35
|
+
readString(cause.code);
|
|
36
|
+
const name = (error instanceof Error ? readString(error.name) : undefined) ??
|
|
37
|
+
readString(details.name) ??
|
|
38
|
+
readString(cause.name);
|
|
39
|
+
const requestId = readString(details.requestId) ??
|
|
40
|
+
readString(details.request_id) ??
|
|
41
|
+
readString(cause.requestId) ??
|
|
42
|
+
readString(cause.request_id);
|
|
43
|
+
const normalizedCode = code?.toLowerCase() ?? '';
|
|
44
|
+
let category = 'unknown';
|
|
45
|
+
let retryable = false;
|
|
46
|
+
let outcome = 'ambiguous';
|
|
47
|
+
let safeMessage = 'The payment provider could not complete the request.';
|
|
48
|
+
if (error instanceof errors_1.IntegrationError) {
|
|
49
|
+
category = 'validation';
|
|
50
|
+
outcome = 'definitely_not_applied';
|
|
51
|
+
safeMessage = 'The payment request could not be created for this provider.';
|
|
52
|
+
}
|
|
53
|
+
else if (status === 401 || status === 403 || normalizedCode.includes('auth')) {
|
|
54
|
+
category = 'authentication';
|
|
55
|
+
outcome = 'definitely_not_applied';
|
|
56
|
+
safeMessage = 'The payment provider credentials are not authorized.';
|
|
57
|
+
}
|
|
58
|
+
else if (status === 400 || status === 404 || normalizedCode.includes('invalid')) {
|
|
59
|
+
category = 'validation';
|
|
60
|
+
outcome = 'definitely_not_applied';
|
|
61
|
+
safeMessage = 'The payment provider rejected the request parameters.';
|
|
62
|
+
}
|
|
63
|
+
else if (status === 402 || normalizedCode.includes('declin')) {
|
|
64
|
+
category = 'declined';
|
|
65
|
+
outcome = 'definitely_not_applied';
|
|
66
|
+
safeMessage = 'The payment method was declined.';
|
|
67
|
+
}
|
|
68
|
+
else if (status === 409) {
|
|
69
|
+
category = 'conflict';
|
|
70
|
+
retryable = true;
|
|
71
|
+
safeMessage = 'The payment result must be reconciled before retrying.';
|
|
72
|
+
}
|
|
73
|
+
else if (status === 429) {
|
|
74
|
+
category = 'rate_limited';
|
|
75
|
+
retryable = true;
|
|
76
|
+
safeMessage = 'The payment provider is temporarily rate limited.';
|
|
77
|
+
}
|
|
78
|
+
else if (Number.isFinite(status) && status >= 500) {
|
|
79
|
+
category = 'provider_server';
|
|
80
|
+
retryable = true;
|
|
81
|
+
safeMessage = 'The payment provider is temporarily unavailable.';
|
|
82
|
+
}
|
|
83
|
+
else if (error instanceof errors_1.ConnectorError ||
|
|
84
|
+
normalizedCode.includes('network') ||
|
|
85
|
+
normalizedCode.includes('timeout') ||
|
|
86
|
+
name === 'AbortError') {
|
|
87
|
+
category = 'network';
|
|
88
|
+
retryable = true;
|
|
89
|
+
safeMessage = 'The payment provider response was interrupted.';
|
|
90
|
+
}
|
|
91
|
+
return new PrismOperationError({
|
|
92
|
+
category,
|
|
93
|
+
...(code ? { providerCode: code } : {}),
|
|
94
|
+
...(requestId ? { providerRequestId: requestId } : {}),
|
|
95
|
+
retryable,
|
|
96
|
+
outcome,
|
|
97
|
+
safeMessage,
|
|
98
|
+
}, error instanceof Error ? { cause: error } : undefined);
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.verifyPrismStripeRuntimeCredential = exports.PrismStripeConnector = void 0;
|
|
18
|
+
__exportStar(require("./contracts"), exports);
|
|
19
|
+
var stripe_connector_1 = require("./stripe-connector");
|
|
20
|
+
Object.defineProperty(exports, "PrismStripeConnector", { enumerable: true, get: function () { return stripe_connector_1.PrismStripeConnector; } });
|
|
21
|
+
Object.defineProperty(exports, "verifyPrismStripeRuntimeCredential", { enumerable: true, get: function () { return stripe_connector_1.verifyPrismStripeRuntimeCredential; } });
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const ALPHAWEB_STRIPE_WEBHOOK_EVENTS: readonly ["charge.dispute.closed", "charge.dispute.created", "charge.dispute.funds_reinstated", "charge.dispute.funds_withdrawn", "charge.dispute.updated", "mandate.updated", "payment_intent.amount_capturable_updated", "payment_intent.canceled", "payment_intent.payment_failed", "payment_intent.processing", "payment_intent.requires_action", "payment_intent.succeeded", "payment_method.attached", "payment_method.automatically_updated", "payment_method.detached", "payment_method.updated", "refund.created", "refund.failed", "refund.updated", "setup_intent.canceled", "setup_intent.requires_action", "setup_intent.setup_failed", "setup_intent.succeeded"];
|
|
2
|
+
export declare const ALPHAWEB_PRISM_COMPATIBILITY_MANIFEST: Readonly<{
|
|
3
|
+
readonly release: "0.1.0-rc.27";
|
|
4
|
+
readonly upstreamCommit: "b07af7d9dac271de729548e74217ddcf895c602b";
|
|
5
|
+
readonly medusaRange: ">=2.17.2 <2.18.0";
|
|
6
|
+
readonly stripeApiVersion: "2026-06-24.dahlia";
|
|
7
|
+
readonly auditedUpstreamStripeApiVersion: "2022-11-15";
|
|
8
|
+
readonly stripeWebhookEvents: readonly ["charge.dispute.closed", "charge.dispute.created", "charge.dispute.funds_reinstated", "charge.dispute.funds_withdrawn", "charge.dispute.updated", "mandate.updated", "payment_intent.amount_capturable_updated", "payment_intent.canceled", "payment_intent.payment_failed", "payment_intent.processing", "payment_intent.requires_action", "payment_intent.succeeded", "payment_method.attached", "payment_method.automatically_updated", "payment_method.detached", "payment_method.updated", "refund.created", "refund.failed", "refund.updated", "setup_intent.canceled", "setup_intent.requires_action", "setup_intent.setup_failed", "setup_intent.succeeded"];
|
|
9
|
+
readonly stripeWebhookEventSetSha256: "5f9eeb16bed529b9dcb66de5985ec34ab8a818a3d9980204dbadd495d409d428";
|
|
10
|
+
readonly stripeWebhookEventSetEncoding: "utf8-sorted-lf-v1";
|
|
11
|
+
readonly stripeJsContract: "payment-element-v1";
|
|
12
|
+
readonly webhookSchemaVersion: 1;
|
|
13
|
+
readonly reusableReferenceVersion: 1;
|
|
14
|
+
readonly normalizedStatusMappingVersion: 1;
|
|
15
|
+
readonly nativeAbiVersion: 1;
|
|
16
|
+
readonly nativeAbi: readonly ["linux-x64-gnu"];
|
|
17
|
+
readonly connectors: readonly ["stripe"];
|
|
18
|
+
readonly features: {
|
|
19
|
+
readonly oneTimePayment: true;
|
|
20
|
+
readonly futureUse: true;
|
|
21
|
+
readonly repeatPayment: true;
|
|
22
|
+
readonly webhookParse: true;
|
|
23
|
+
readonly webhookEndpointManagement: true;
|
|
24
|
+
readonly refundProjection: true;
|
|
25
|
+
readonly disputeProjection: true;
|
|
26
|
+
};
|
|
27
|
+
}>;
|
|
28
|
+
export type AlphaWebPrismCompatibilityManifest = typeof ALPHAWEB_PRISM_COMPATIBILITY_MANIFEST;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ALPHAWEB_PRISM_COMPATIBILITY_MANIFEST = exports.ALPHAWEB_STRIPE_WEBHOOK_EVENTS = void 0;
|
|
4
|
+
exports.ALPHAWEB_STRIPE_WEBHOOK_EVENTS = Object.freeze([
|
|
5
|
+
'charge.dispute.closed',
|
|
6
|
+
'charge.dispute.created',
|
|
7
|
+
'charge.dispute.funds_reinstated',
|
|
8
|
+
'charge.dispute.funds_withdrawn',
|
|
9
|
+
'charge.dispute.updated',
|
|
10
|
+
'mandate.updated',
|
|
11
|
+
'payment_intent.amount_capturable_updated',
|
|
12
|
+
'payment_intent.canceled',
|
|
13
|
+
'payment_intent.payment_failed',
|
|
14
|
+
'payment_intent.processing',
|
|
15
|
+
'payment_intent.requires_action',
|
|
16
|
+
'payment_intent.succeeded',
|
|
17
|
+
'payment_method.attached',
|
|
18
|
+
'payment_method.automatically_updated',
|
|
19
|
+
'payment_method.detached',
|
|
20
|
+
'payment_method.updated',
|
|
21
|
+
'refund.created',
|
|
22
|
+
'refund.failed',
|
|
23
|
+
'refund.updated',
|
|
24
|
+
'setup_intent.canceled',
|
|
25
|
+
'setup_intent.requires_action',
|
|
26
|
+
'setup_intent.setup_failed',
|
|
27
|
+
'setup_intent.succeeded',
|
|
28
|
+
]);
|
|
29
|
+
exports.ALPHAWEB_PRISM_COMPATIBILITY_MANIFEST = Object.freeze({
|
|
30
|
+
release: '0.1.0-rc.27',
|
|
31
|
+
upstreamCommit: 'b07af7d9dac271de729548e74217ddcf895c602b',
|
|
32
|
+
medusaRange: '>=2.17.2 <2.18.0',
|
|
33
|
+
stripeApiVersion: '2026-06-24.dahlia',
|
|
34
|
+
auditedUpstreamStripeApiVersion: '2022-11-15',
|
|
35
|
+
stripeWebhookEvents: exports.ALPHAWEB_STRIPE_WEBHOOK_EVENTS,
|
|
36
|
+
stripeWebhookEventSetSha256: '5f9eeb16bed529b9dcb66de5985ec34ab8a818a3d9980204dbadd495d409d428',
|
|
37
|
+
stripeWebhookEventSetEncoding: 'utf8-sorted-lf-v1',
|
|
38
|
+
stripeJsContract: 'payment-element-v1',
|
|
39
|
+
webhookSchemaVersion: 1,
|
|
40
|
+
reusableReferenceVersion: 1,
|
|
41
|
+
normalizedStatusMappingVersion: 1,
|
|
42
|
+
nativeAbiVersion: 1,
|
|
43
|
+
nativeAbi: ['linux-x64-gnu'],
|
|
44
|
+
connectors: ['stripe'],
|
|
45
|
+
features: {
|
|
46
|
+
oneTimePayment: true,
|
|
47
|
+
futureUse: true,
|
|
48
|
+
repeatPayment: true,
|
|
49
|
+
webhookParse: true,
|
|
50
|
+
webhookEndpointManagement: true,
|
|
51
|
+
refundProjection: true,
|
|
52
|
+
disputeProjection: true,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PrismMoney } from './types';
|
|
2
|
+
export interface CurrencyRule {
|
|
3
|
+
code: string;
|
|
4
|
+
exponent: 0 | 2 | 3;
|
|
5
|
+
stripeChargeRule: 'normal' | 'integer_with_trailing_zeros';
|
|
6
|
+
}
|
|
7
|
+
export declare function getCurrencyRule(currency: string): CurrencyRule;
|
|
8
|
+
export declare function toProviderMinorAmount(input: {
|
|
9
|
+
medusaAmount: string | number | bigint;
|
|
10
|
+
currency: string;
|
|
11
|
+
}): bigint;
|
|
12
|
+
export declare function fromProviderMinorAmount(input: {
|
|
13
|
+
amountMinor: bigint | string;
|
|
14
|
+
currency: string;
|
|
15
|
+
}): string;
|
|
16
|
+
export declare function assertSafeProviderMoney(money: PrismMoney): {
|
|
17
|
+
amountMinor: number;
|
|
18
|
+
currency: string;
|
|
19
|
+
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCurrencyRule = getCurrencyRule;
|
|
4
|
+
exports.toProviderMinorAmount = toProviderMinorAmount;
|
|
5
|
+
exports.fromProviderMinorAmount = fromProviderMinorAmount;
|
|
6
|
+
exports.assertSafeProviderMoney = assertSafeProviderMoney;
|
|
7
|
+
const ZERO_DECIMAL = new Set([
|
|
8
|
+
'bif',
|
|
9
|
+
'clp',
|
|
10
|
+
'djf',
|
|
11
|
+
'gnf',
|
|
12
|
+
'jpy',
|
|
13
|
+
'kmf',
|
|
14
|
+
'krw',
|
|
15
|
+
'mga',
|
|
16
|
+
'pyg',
|
|
17
|
+
'rwf',
|
|
18
|
+
'vnd',
|
|
19
|
+
'vuv',
|
|
20
|
+
'xaf',
|
|
21
|
+
'xof',
|
|
22
|
+
'xpf',
|
|
23
|
+
]);
|
|
24
|
+
const THREE_DECIMAL = new Set(['bhd', 'jod', 'kwd', 'omr', 'tnd']);
|
|
25
|
+
const SPECIAL_TRAILING_ZERO = new Set(['isk', 'ugx']);
|
|
26
|
+
const CURRENCY_CODE = /^[a-z]{3}$/;
|
|
27
|
+
const INTEGER = /^\d+$/;
|
|
28
|
+
// Stripe's pinned API contract. Unknown ISO-like values are rejected here rather
|
|
29
|
+
// than allowed to fail later, after a merchant operation has been claimed.
|
|
30
|
+
const STRIPE_SUPPORTED_CURRENCIES = new Set([
|
|
31
|
+
'aed', 'afn', 'all', 'amd', 'ang', 'aoa', 'ars', 'aud', 'awg', 'azn', 'bam',
|
|
32
|
+
'bbd', 'bdt', 'bgn', 'bhd', 'bif', 'bmd', 'bnd', 'bob', 'brl', 'bsd', 'bwp', 'byn',
|
|
33
|
+
'bzd', 'cad', 'cdf', 'chf', 'clp', 'cny', 'cop', 'crc', 'cve', 'czk', 'djf',
|
|
34
|
+
'dkk', 'dop', 'dzd', 'egp', 'etb', 'eur', 'fjd', 'fkp', 'gbp', 'gel', 'gip',
|
|
35
|
+
'gmd', 'gnf', 'gtq', 'gyd', 'hkd', 'hnl', 'htg', 'huf', 'idr', 'ils', 'inr',
|
|
36
|
+
'isk', 'jmd', 'jod', 'jpy', 'kes', 'kgs', 'khr', 'kmf', 'krw', 'kwd', 'kyd',
|
|
37
|
+
'kzt', 'lak',
|
|
38
|
+
'lbp', 'lkr', 'lrd', 'lsl', 'mad', 'mdl', 'mga', 'mkd', 'mmk', 'mnt', 'mop',
|
|
39
|
+
'mru', 'mur', 'mvr', 'mwk', 'mxn', 'myr', 'mzn', 'nad', 'ngn', 'nio', 'nok',
|
|
40
|
+
'npr', 'nzd', 'pab', 'pen', 'pgk', 'php', 'pkr', 'pln', 'pyg', 'qar', 'ron',
|
|
41
|
+
'omr', 'rsd', 'rub', 'rwf', 'sar', 'sbd', 'scr', 'sek', 'sgd', 'shp', 'sle', 'sos',
|
|
42
|
+
'srd', 'stn', 'szl', 'thb', 'tjs', 'tnd', 'top', 'try', 'ttd', 'twd', 'tzs', 'uah',
|
|
43
|
+
'ugx', 'usd', 'uyu', 'uzs', 'vnd', 'vuv', 'wst', 'xaf', 'xcd', 'xof', 'xpf',
|
|
44
|
+
'yer', 'zar', 'zmw',
|
|
45
|
+
]);
|
|
46
|
+
function getCurrencyRule(currency) {
|
|
47
|
+
const code = currency.trim().toLowerCase();
|
|
48
|
+
if (!CURRENCY_CODE.test(code)) {
|
|
49
|
+
throw new RangeError(`Unsupported currency code: ${currency}`);
|
|
50
|
+
}
|
|
51
|
+
if (!STRIPE_SUPPORTED_CURRENCIES.has(code)) {
|
|
52
|
+
throw new RangeError(`Currency is not supported by the pinned Stripe contract: ${currency}`);
|
|
53
|
+
}
|
|
54
|
+
if (SPECIAL_TRAILING_ZERO.has(code)) {
|
|
55
|
+
return { code, exponent: 2, stripeChargeRule: 'integer_with_trailing_zeros' };
|
|
56
|
+
}
|
|
57
|
+
if (ZERO_DECIMAL.has(code)) {
|
|
58
|
+
return { code, exponent: 0, stripeChargeRule: 'normal' };
|
|
59
|
+
}
|
|
60
|
+
if (THREE_DECIMAL.has(code)) {
|
|
61
|
+
return { code, exponent: 3, stripeChargeRule: 'normal' };
|
|
62
|
+
}
|
|
63
|
+
return { code, exponent: 2, stripeChargeRule: 'normal' };
|
|
64
|
+
}
|
|
65
|
+
function decimalString(value) {
|
|
66
|
+
if (typeof value === 'bigint')
|
|
67
|
+
return value.toString();
|
|
68
|
+
if (typeof value === 'number') {
|
|
69
|
+
if (!Number.isFinite(value))
|
|
70
|
+
throw new RangeError('Money must be finite.');
|
|
71
|
+
const plain = value.toString();
|
|
72
|
+
if (/[eE]/.test(plain))
|
|
73
|
+
throw new RangeError('Exponential money values are not accepted.');
|
|
74
|
+
return plain;
|
|
75
|
+
}
|
|
76
|
+
const trimmed = value.trim();
|
|
77
|
+
if (!/^-?\d+(?:\.\d+)?$/.test(trimmed)) {
|
|
78
|
+
throw new RangeError('Money must be a base-10 decimal value.');
|
|
79
|
+
}
|
|
80
|
+
return trimmed;
|
|
81
|
+
}
|
|
82
|
+
function toProviderMinorAmount(input) {
|
|
83
|
+
const rule = getCurrencyRule(input.currency);
|
|
84
|
+
const value = decimalString(input.medusaAmount);
|
|
85
|
+
if (value.startsWith('-'))
|
|
86
|
+
throw new RangeError('Payment amount cannot be negative.');
|
|
87
|
+
const [whole, fraction = ''] = value.split('.');
|
|
88
|
+
if (fraction.length > rule.exponent) {
|
|
89
|
+
throw new RangeError(`${rule.code.toUpperCase()} accepts at most ${rule.exponent} decimals.`);
|
|
90
|
+
}
|
|
91
|
+
const padded = fraction.padEnd(rule.exponent, '0');
|
|
92
|
+
const minor = BigInt(`${whole}${padded}`.replace(/^0+(?=\d)/, '') || '0');
|
|
93
|
+
if (rule.stripeChargeRule === 'integer_with_trailing_zeros' && minor % 100n !== 0n) {
|
|
94
|
+
throw new RangeError(`${rule.code.toUpperCase()} charge amounts must end in 00 minor units.`);
|
|
95
|
+
}
|
|
96
|
+
return minor;
|
|
97
|
+
}
|
|
98
|
+
function fromProviderMinorAmount(input) {
|
|
99
|
+
const rule = getCurrencyRule(input.currency);
|
|
100
|
+
if (typeof input.amountMinor === 'string' && !INTEGER.test(input.amountMinor)) {
|
|
101
|
+
throw new RangeError('Provider minor amount must be a non-negative integer.');
|
|
102
|
+
}
|
|
103
|
+
const minor = typeof input.amountMinor === 'bigint' ? input.amountMinor : BigInt(input.amountMinor);
|
|
104
|
+
if (minor < 0n)
|
|
105
|
+
throw new RangeError('Payment amount cannot be negative.');
|
|
106
|
+
if (rule.exponent === 0)
|
|
107
|
+
return minor.toString();
|
|
108
|
+
const digits = minor.toString().padStart(rule.exponent + 1, '0');
|
|
109
|
+
const splitAt = digits.length - rule.exponent;
|
|
110
|
+
return `${digits.slice(0, splitAt)}.${digits.slice(splitAt)}`;
|
|
111
|
+
}
|
|
112
|
+
function assertSafeProviderMoney(money) {
|
|
113
|
+
const rule = getCurrencyRule(money.currency);
|
|
114
|
+
if (!INTEGER.test(money.amountMinor)) {
|
|
115
|
+
throw new RangeError('Provider minor amount must be a non-negative integer string.');
|
|
116
|
+
}
|
|
117
|
+
const amount = BigInt(money.amountMinor);
|
|
118
|
+
if (amount <= 0n)
|
|
119
|
+
throw new RangeError('Provider payment amount must be positive.');
|
|
120
|
+
if (amount > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
121
|
+
throw new RangeError('Provider payment amount exceeds the safe integer range.');
|
|
122
|
+
}
|
|
123
|
+
if (rule.stripeChargeRule === 'integer_with_trailing_zeros' && amount % 100n !== 0n) {
|
|
124
|
+
throw new RangeError(`${rule.code.toUpperCase()} charge amounts must end in 00 minor units.`);
|
|
125
|
+
}
|
|
126
|
+
return { amountMinor: Number(amount), currency: rule.code };
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=money.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { types } from '../payments/generated/proto';
|
|
2
|
+
import type { PrismCancelInput, PrismCaptureInput, PrismCreateWebhookEndpointInput, PrismDeleteWebhookEndpointInput, PrismDisputeResult, PrismEstablishReusableReferenceInput, PrismFindPaymentInput, PrismFindRefundInput, PrismMerchantOperation, PrismPaymentResult, PrismRefundInput, PrismRefundResult, PrismRetrieveDisputeInput, PrismRetrieveRefundInput, PrismRetryPaymentInput, PrismReusableReferenceDerivation, PrismRetrieveWebhookEndpointInput, PrismRetrievePaymentInput, PrismStripeConnectorOptions, PrismStripeConnectorV1, PrismStripeRuntimeVerification, PrismStripeRuntimeVerificationInput, PrismUpdateWebhookEndpointInput, PrismWebhookEndpoint, PrismWebhookEndpointCreated, PrismWebhookParseInput, PrismWebhookParseResult } from './types';
|
|
3
|
+
interface MerchantAuthenticationPort {
|
|
4
|
+
createClientAuthenticationToken(input: types.IMerchantAuthenticationServiceCreateClientAuthenticationTokenRequest): Promise<types.MerchantAuthenticationServiceCreateClientAuthenticationTokenResponse>;
|
|
5
|
+
}
|
|
6
|
+
interface PaymentPort {
|
|
7
|
+
get(input: types.IPaymentServiceGetRequest): Promise<types.PaymentServiceGetResponse>;
|
|
8
|
+
capture(input: types.IPaymentServiceCaptureRequest): Promise<types.PaymentServiceCaptureResponse>;
|
|
9
|
+
void(input: types.IPaymentServiceVoidRequest): Promise<types.PaymentServiceVoidResponse>;
|
|
10
|
+
refund(input: types.IPaymentServiceRefundRequest): Promise<types.RefundResponse>;
|
|
11
|
+
}
|
|
12
|
+
interface RecurringPaymentPort {
|
|
13
|
+
charge(input: types.IRecurringPaymentServiceChargeRequest): Promise<types.RecurringPaymentServiceChargeResponse>;
|
|
14
|
+
}
|
|
15
|
+
interface EventPort {
|
|
16
|
+
handleEvent(input: types.IEventServiceHandleRequest): Promise<types.EventServiceHandleResponse>;
|
|
17
|
+
}
|
|
18
|
+
export interface PrismStripeConnectorDependencies {
|
|
19
|
+
merchantAuthentication: MerchantAuthenticationPort;
|
|
20
|
+
payments: PaymentPort;
|
|
21
|
+
recurringPayments: RecurringPaymentPort;
|
|
22
|
+
events: EventPort;
|
|
23
|
+
fetch: typeof fetch;
|
|
24
|
+
}
|
|
25
|
+
export declare class PrismStripeConnector implements PrismStripeConnectorV1 {
|
|
26
|
+
readonly options: Readonly<PrismStripeConnectorOptions>;
|
|
27
|
+
private readonly dependencies;
|
|
28
|
+
constructor(options: PrismStripeConnectorOptions, dependencies?: PrismStripeConnectorDependencies);
|
|
29
|
+
private validateOptions;
|
|
30
|
+
private assertOperation;
|
|
31
|
+
private recoverRepeatPayment;
|
|
32
|
+
private stripeRequest;
|
|
33
|
+
createPayment(input: PrismMerchantOperation): Promise<PrismPaymentResult>;
|
|
34
|
+
repeatPayment(input: PrismMerchantOperation): Promise<PrismPaymentResult>;
|
|
35
|
+
retryPayment(input: PrismRetryPaymentInput): Promise<PrismPaymentResult>;
|
|
36
|
+
retrievePayment(input: PrismRetrievePaymentInput): Promise<PrismPaymentResult>;
|
|
37
|
+
establishReusableReference(input: PrismEstablishReusableReferenceInput): Promise<PrismReusableReferenceDerivation>;
|
|
38
|
+
findPaymentsByMerchantOperation(input: PrismFindPaymentInput): Promise<PrismPaymentResult[]>;
|
|
39
|
+
capturePayment(input: PrismCaptureInput): Promise<PrismPaymentResult>;
|
|
40
|
+
cancelPayment(input: PrismCancelInput): Promise<PrismPaymentResult>;
|
|
41
|
+
refundPayment(input: PrismRefundInput): Promise<PrismRefundResult>;
|
|
42
|
+
retrieveRefund(input: PrismRetrieveRefundInput): Promise<PrismRefundResult>;
|
|
43
|
+
findRefundsByMerchantOperation(input: PrismFindRefundInput): Promise<PrismRefundResult[]>;
|
|
44
|
+
retrieveDispute(input: PrismRetrieveDisputeInput): Promise<PrismDisputeResult>;
|
|
45
|
+
parseWebhookEvent(input: PrismWebhookParseInput): Promise<PrismWebhookParseResult>;
|
|
46
|
+
createWebhookEndpoint(input: PrismCreateWebhookEndpointInput): Promise<PrismWebhookEndpointCreated>;
|
|
47
|
+
updateWebhookEndpoint(input: PrismUpdateWebhookEndpointInput): Promise<PrismWebhookEndpoint>;
|
|
48
|
+
deleteWebhookEndpoint(input: PrismDeleteWebhookEndpointInput): Promise<void>;
|
|
49
|
+
retrieveWebhookEndpoint(input: PrismRetrieveWebhookEndpointInput): Promise<PrismWebhookEndpoint>;
|
|
50
|
+
private normalizeEndpoint;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Verifies that one Stripe key pair resolves to the expected merchant account
|
|
54
|
+
* and that the pinned native Prism runtime can be constructed for it. Consumer
|
|
55
|
+
* applications receive only the verified account identity and mode.
|
|
56
|
+
*/
|
|
57
|
+
export declare function verifyPrismStripeRuntimeCredential(input: PrismStripeRuntimeVerificationInput, dependencies?: PrismStripeConnectorDependencies): Promise<PrismStripeRuntimeVerification>;
|
|
58
|
+
export {};
|