@moonpay/platform-protocol 0.3.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -0
- package/dist/{index.cjs → api/errors.cjs} +7 -51
- package/dist/api/errors.cjs.map +1 -0
- package/dist/api/errors.d.cts +46 -0
- package/dist/api/errors.d.ts +46 -0
- package/dist/api/errors.js +27 -0
- package/dist/api/errors.js.map +1 -0
- package/dist/api/identity.cjs +19 -0
- package/dist/api/identity.cjs.map +1 -0
- package/dist/api/identity.d.cts +156 -0
- package/dist/api/identity.d.ts +156 -0
- package/dist/api/identity.js +1 -0
- package/dist/api/identity.js.map +1 -0
- package/dist/api/index.cjs +19 -0
- package/dist/api/index.cjs.map +1 -0
- package/dist/api/index.d.cts +466 -0
- package/dist/api/index.d.ts +466 -0
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +1 -0
- package/dist/frames/add-card.cjs +19 -0
- package/dist/frames/add-card.cjs.map +1 -0
- package/dist/frames/add-card.d.cts +24 -0
- package/dist/frames/add-card.d.ts +24 -0
- package/dist/frames/add-card.js +1 -0
- package/dist/frames/add-card.js.map +1 -0
- package/dist/frames/apple-pay.cjs +19 -0
- package/dist/frames/apple-pay.cjs.map +1 -0
- package/dist/frames/apple-pay.d.cts +22 -0
- package/dist/frames/apple-pay.d.ts +22 -0
- package/dist/frames/apple-pay.js +1 -0
- package/dist/frames/apple-pay.js.map +1 -0
- package/dist/frames/auth.cjs +19 -0
- package/dist/frames/auth.cjs.map +1 -0
- package/dist/frames/auth.d.cts +15 -0
- package/dist/frames/auth.d.ts +15 -0
- package/dist/frames/auth.js +1 -0
- package/dist/frames/auth.js.map +1 -0
- package/dist/frames/buy-button.cjs +19 -0
- package/dist/frames/buy-button.cjs.map +1 -0
- package/dist/frames/buy-button.d.cts +21 -0
- package/dist/frames/buy-button.d.ts +21 -0
- package/dist/frames/buy-button.js +1 -0
- package/dist/frames/buy-button.js.map +1 -0
- package/dist/frames/buy.cjs +19 -0
- package/dist/frames/buy.cjs.map +1 -0
- package/dist/frames/buy.d.cts +22 -0
- package/dist/frames/buy.d.ts +22 -0
- package/dist/frames/buy.js +1 -0
- package/dist/frames/buy.js.map +1 -0
- package/dist/frames/challenge.cjs +19 -0
- package/dist/frames/challenge.cjs.map +1 -0
- package/dist/frames/challenge.d.cts +30 -0
- package/dist/frames/challenge.d.ts +30 -0
- package/dist/frames/challenge.js +1 -0
- package/dist/frames/challenge.js.map +1 -0
- package/dist/frames/connect.cjs +19 -0
- package/dist/frames/connect.cjs.map +1 -0
- package/dist/frames/connect.d.cts +9 -0
- package/dist/frames/connect.d.ts +9 -0
- package/dist/frames/connect.js +1 -0
- package/dist/frames/connect.js.map +1 -0
- package/dist/frames/google-pay.cjs +19 -0
- package/dist/frames/google-pay.cjs.map +1 -0
- package/dist/frames/google-pay.d.cts +22 -0
- package/dist/frames/google-pay.d.ts +22 -0
- package/dist/frames/google-pay.js +1 -0
- package/dist/frames/google-pay.js.map +1 -0
- package/dist/frames/reset.cjs +19 -0
- package/dist/frames/reset.cjs.map +1 -0
- package/dist/frames/reset.d.cts +12 -0
- package/dist/frames/reset.d.ts +12 -0
- package/dist/frames/reset.js +1 -0
- package/dist/frames/reset.js.map +1 -0
- package/dist/frames/widget.cjs +19 -0
- package/dist/frames/widget.cjs.map +1 -0
- package/dist/frames/widget.d.cts +19 -0
- package/dist/frames/widget.d.ts +19 -0
- package/dist/frames/widget.js +1 -0
- package/dist/frames/widget.js.map +1 -0
- package/dist/models/challenge.cjs +19 -0
- package/dist/models/challenge.cjs.map +1 -0
- package/dist/models/challenge.d.cts +12 -0
- package/dist/models/challenge.d.ts +12 -0
- package/dist/models/challenge.js +1 -0
- package/dist/models/challenge.js.map +1 -0
- package/dist/models/connection.cjs +46 -0
- package/dist/models/connection.cjs.map +1 -0
- package/dist/models/connection.d.cts +142 -0
- package/dist/models/connection.d.ts +142 -0
- package/dist/models/connection.js +20 -0
- package/dist/models/connection.js.map +1 -0
- package/dist/models/transaction.cjs +19 -0
- package/dist/models/transaction.cjs.map +1 -0
- package/dist/models/transaction.d.cts +15 -0
- package/dist/models/transaction.d.ts +15 -0
- package/dist/models/transaction.js +1 -0
- package/dist/models/transaction.js.map +1 -0
- package/dist/protocol.cjs +34 -0
- package/dist/protocol.cjs.map +1 -0
- package/dist/protocol.d.cts +30 -0
- package/dist/protocol.d.ts +30 -0
- package/dist/protocol.js +8 -0
- package/dist/protocol.js.map +1 -0
- package/dist/result.cjs +40 -0
- package/dist/result.cjs.map +1 -0
- package/dist/result.d.cts +30 -0
- package/dist/result.d.ts +30 -0
- package/dist/result.js +14 -0
- package/dist/result.js.map +1 -0
- package/dist/sdks/add-card.cjs +19 -0
- package/dist/sdks/add-card.cjs.map +1 -0
- package/dist/sdks/add-card.d.cts +20 -0
- package/dist/sdks/add-card.d.ts +20 -0
- package/dist/sdks/add-card.js +1 -0
- package/dist/sdks/add-card.js.map +1 -0
- package/dist/sdks/apple-pay.cjs +19 -0
- package/dist/sdks/apple-pay.cjs.map +1 -0
- package/dist/sdks/apple-pay.d.cts +36 -0
- package/dist/sdks/apple-pay.d.ts +36 -0
- package/dist/sdks/apple-pay.js +1 -0
- package/dist/sdks/apple-pay.js.map +1 -0
- package/dist/sdks/auth.cjs +19 -0
- package/dist/sdks/auth.cjs.map +1 -0
- package/dist/sdks/auth.d.cts +18 -0
- package/dist/sdks/auth.d.ts +18 -0
- package/dist/sdks/auth.js +1 -0
- package/dist/sdks/auth.js.map +1 -0
- package/dist/sdks/buy-button.cjs +19 -0
- package/dist/sdks/buy-button.cjs.map +1 -0
- package/dist/sdks/buy-button.d.cts +21 -0
- package/dist/sdks/buy-button.d.ts +21 -0
- package/dist/sdks/buy-button.js +1 -0
- package/dist/sdks/buy-button.js.map +1 -0
- package/dist/sdks/buy.cjs +19 -0
- package/dist/sdks/buy.cjs.map +1 -0
- package/dist/sdks/buy.d.cts +23 -0
- package/dist/sdks/buy.d.ts +23 -0
- package/dist/sdks/buy.js +1 -0
- package/dist/sdks/buy.js.map +1 -0
- package/dist/sdks/challenge.cjs +19 -0
- package/dist/sdks/challenge.cjs.map +1 -0
- package/dist/sdks/challenge.d.cts +22 -0
- package/dist/sdks/challenge.d.ts +22 -0
- package/dist/sdks/challenge.js +1 -0
- package/dist/sdks/challenge.js.map +1 -0
- package/dist/sdks/connect.cjs +19 -0
- package/dist/sdks/connect.cjs.map +1 -0
- package/dist/sdks/connect.d.cts +20 -0
- package/dist/sdks/connect.d.ts +20 -0
- package/dist/sdks/connect.js +1 -0
- package/dist/sdks/connect.js.map +1 -0
- package/dist/sdks/google-pay.cjs +19 -0
- package/dist/sdks/google-pay.cjs.map +1 -0
- package/dist/sdks/google-pay.d.cts +36 -0
- package/dist/sdks/google-pay.d.ts +36 -0
- package/dist/sdks/google-pay.js +1 -0
- package/dist/sdks/google-pay.js.map +1 -0
- package/dist/sdks/reset.cjs +19 -0
- package/dist/sdks/reset.cjs.map +1 -0
- package/dist/sdks/reset.d.cts +5 -0
- package/dist/sdks/reset.d.ts +5 -0
- package/dist/sdks/reset.js +1 -0
- package/dist/sdks/reset.js.map +1 -0
- package/dist/sdks/widget.cjs +19 -0
- package/dist/sdks/widget.cjs.map +1 -0
- package/dist/sdks/widget.d.cts +26 -0
- package/dist/sdks/widget.d.ts +26 -0
- package/dist/sdks/widget.js +1 -0
- package/dist/sdks/widget.js.map +1 -0
- package/package.json +278 -11
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1289
- package/dist/index.d.ts +0 -1289
- package/dist/index.js +0 -63
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/models/connection.ts"],"sourcesContent":["// ---------------------------------------------------------------------------\n// Connection statuses\n// ---------------------------------------------------------------------------\n\nexport enum ConnectionStatus {\n /**\n * New or expired user — needs the full connect flow.\n */\n connectionRequired = 'connectionRequired',\n\n /**\n * Valid connection — encrypted credentials are included.\n */\n active = 'active',\n\n /**\n * Restricted location — connection cannot be used.\n */\n unavailable = 'unavailable',\n\n /**\n * KYC decision delayed — may resolve on a subsequent visit.\n */\n pending = 'pending',\n\n /**\n * Terminal failure — KYC fail, rejection, etc.\n */\n failed = 'failed',\n\n /**\n * Customer has no valid Terms of Use attestation on file (headless/Identity API partners).\n * Display Terms of Use in your own UI, capture acceptance, call\n * `POST /platform/v1/terms/attestations`, then retry the connection.\n */\n termsAcceptanceRequired = 'termsAcceptanceRequired',\n}\n\nexport interface ConnectionRequired {\n status: ConnectionStatus.connectionRequired;\n /**\n * Base64-encoded, X25519+AES-GCM encrypted anonymous token payload.\n * These are frame-internal tokens used by the connect frame — they cannot be\n * used to call MoonPay APIs directly. Decrypt via `decryptCredentials()` only\n * if you need the `clientToken` to bootstrap the connect frame manually.\n */\n credentials: string;\n /**\n * Capabilities and regulatory requirements available before authentication, if any.\n * Present when Apple Pay 1TAP is enabled for the partner.\n */\n capabilities?: CustomerCapabilities;\n}\n\nexport interface ActiveConnection {\n status: ConnectionStatus.active;\n /** The authenticated MoonPay customer. */\n customer: { id: string };\n /**\n * Base64-encoded, X25519+AES-GCM encrypted JSON containing:\n * ```json\n * {\n * \"accessToken\": \"<token>\",\n * \"clientToken\": \"<token>\",\n * \"expiresAt\": \"<iso8601>\"\n * }\n * ```\n *\n * - `accessToken`: A token that can be used to make API requests from the client.\n * - `clientToken`: A token that can be used to initialize sensitive frames such as Apple Pay.\n * - `expiresAt`: An ISO 8601 formatted string indicating when the tokens expire.\n */\n credentials: string;\n /**\n * Capabilities and regulatory requirements for the authenticated customer.\n */\n capabilities: CustomerCapabilities;\n}\n\nexport interface UnavailableConnection {\n status: ConnectionStatus.unavailable;\n}\n\nexport interface PendingConnection {\n status: ConnectionStatus.pending;\n}\n\nexport interface FailedConnection {\n status: ConnectionStatus.failed;\n reason: string;\n}\n\nexport interface TermsAcceptanceRequiredConnection {\n status: ConnectionStatus.termsAcceptanceRequired;\n}\n\n/** Discriminated union of all connection result statuses. */\nexport type Connection =\n | ConnectionRequired\n | ActiveConnection\n | UnavailableConnection\n | PendingConnection\n | FailedConnection\n | TermsAcceptanceRequiredConnection;\n\n// ---------------------------------------------------------------------------\n// Decrypted credentials (what the SDK exposes after decryption)\n// ---------------------------------------------------------------------------\n\nexport interface DecryptedCredentials {\n accessToken: string;\n clientToken: string;\n expiresAt: string;\n}\n\n// ---------------------------------------------------------------------------\n// Customer capabilities\n// ---------------------------------------------------------------------------\n\n/**\n * Capabilities and regulatory requirements for the authenticated customer.\n */\nexport interface CustomerCapabilities {\n /** Capabilities for the ramps (buy and sell) product. */\n ramps?: RampsCapability;\n /** Capabilities for the Apple Pay 1TAP flow. Present when 1TAP is enabled for the partner and the customer matches. */\n oneTapApplePay?: RampsCapability;\n}\n\n/**\n * Capabilities and requirements for the ramps (buy and sell) product.\n */\nexport interface RampsCapability {\n /** Regulatory requirements for ramps operations in the customer's jurisdiction. */\n requirements: RampsRequirements;\n}\n\n/**\n * Regulatory requirements that apply to ramps operations for the customer.\n */\nexport interface RampsRequirements {\n /**\n * Present when the customer's jurisdiction requires payment disclosures\n * before a ramps transaction. Omitted when no disclosures are required.\n */\n paymentDisclosures?: PaymentDisclosuresRequirement;\n}\n\n/**\n * A jurisdiction that requires payment disclosures before a ramps transaction.\n */\nexport interface PaymentDisclosuresRequirement {\n /** The ISO 3166-1 alpha-3 country code for the jurisdiction. */\n country: string;\n /** The state or province code within the country. */\n administrativeArea: string;\n}\n\n// ---------------------------------------------------------------------------\n// Connection errors\n// ---------------------------------------------------------------------------\n\nexport enum ConnectionErrorCode {\n validationError = 'validationError',\n /** Wire value is `'generic'`. */\n connectionFailedGeneric = 'generic',\n}\n\nexport interface ConfigValidationFieldError {\n code: 'invalidSessionToken' | 'invalidClientToken' | 'invalidPublicKey';\n message: string;\n}\n\nexport type ConnectionError =\n | {\n code: ConnectionErrorCode.validationError;\n errors: ConfigValidationFieldError[];\n }\n | {\n code: ConnectionErrorCode.connectionFailedGeneric;\n message?: string;\n };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,IAAK,mBAAL,kBAAKA,sBAAL;AAIL,EAAAA,kBAAA,wBAAqB;AAKrB,EAAAA,kBAAA,YAAS;AAKT,EAAAA,kBAAA,iBAAc;AAKd,EAAAA,kBAAA,aAAU;AAKV,EAAAA,kBAAA,YAAS;AAOT,EAAAA,kBAAA,6BAA0B;AA/BhB,SAAAA;AAAA,GAAA;AA8JL,IAAK,sBAAL,kBAAKC,yBAAL;AACL,EAAAA,qBAAA,qBAAkB;AAElB,EAAAA,qBAAA,6BAA0B;AAHhB,SAAAA;AAAA,GAAA;","names":["ConnectionStatus","ConnectionErrorCode"]}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
declare enum ConnectionStatus {
|
|
2
|
+
/**
|
|
3
|
+
* New or expired user — needs the full connect flow.
|
|
4
|
+
*/
|
|
5
|
+
connectionRequired = "connectionRequired",
|
|
6
|
+
/**
|
|
7
|
+
* Valid connection — encrypted credentials are included.
|
|
8
|
+
*/
|
|
9
|
+
active = "active",
|
|
10
|
+
/**
|
|
11
|
+
* Restricted location — connection cannot be used.
|
|
12
|
+
*/
|
|
13
|
+
unavailable = "unavailable",
|
|
14
|
+
/**
|
|
15
|
+
* KYC decision delayed — may resolve on a subsequent visit.
|
|
16
|
+
*/
|
|
17
|
+
pending = "pending",
|
|
18
|
+
/**
|
|
19
|
+
* Terminal failure — KYC fail, rejection, etc.
|
|
20
|
+
*/
|
|
21
|
+
failed = "failed",
|
|
22
|
+
/**
|
|
23
|
+
* Customer has no valid Terms of Use attestation on file (headless/Identity API partners).
|
|
24
|
+
* Display Terms of Use in your own UI, capture acceptance, call
|
|
25
|
+
* `POST /platform/v1/terms/attestations`, then retry the connection.
|
|
26
|
+
*/
|
|
27
|
+
termsAcceptanceRequired = "termsAcceptanceRequired"
|
|
28
|
+
}
|
|
29
|
+
interface ConnectionRequired {
|
|
30
|
+
status: ConnectionStatus.connectionRequired;
|
|
31
|
+
/**
|
|
32
|
+
* Base64-encoded, X25519+AES-GCM encrypted anonymous token payload.
|
|
33
|
+
* These are frame-internal tokens used by the connect frame — they cannot be
|
|
34
|
+
* used to call MoonPay APIs directly. Decrypt via `decryptCredentials()` only
|
|
35
|
+
* if you need the `clientToken` to bootstrap the connect frame manually.
|
|
36
|
+
*/
|
|
37
|
+
credentials: string;
|
|
38
|
+
/**
|
|
39
|
+
* Capabilities and regulatory requirements available before authentication, if any.
|
|
40
|
+
* Present when Apple Pay 1TAP is enabled for the partner.
|
|
41
|
+
*/
|
|
42
|
+
capabilities?: CustomerCapabilities;
|
|
43
|
+
}
|
|
44
|
+
interface ActiveConnection {
|
|
45
|
+
status: ConnectionStatus.active;
|
|
46
|
+
/** The authenticated MoonPay customer. */
|
|
47
|
+
customer: {
|
|
48
|
+
id: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Base64-encoded, X25519+AES-GCM encrypted JSON containing:
|
|
52
|
+
* ```json
|
|
53
|
+
* {
|
|
54
|
+
* "accessToken": "<token>",
|
|
55
|
+
* "clientToken": "<token>",
|
|
56
|
+
* "expiresAt": "<iso8601>"
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* - `accessToken`: A token that can be used to make API requests from the client.
|
|
61
|
+
* - `clientToken`: A token that can be used to initialize sensitive frames such as Apple Pay.
|
|
62
|
+
* - `expiresAt`: An ISO 8601 formatted string indicating when the tokens expire.
|
|
63
|
+
*/
|
|
64
|
+
credentials: string;
|
|
65
|
+
/**
|
|
66
|
+
* Capabilities and regulatory requirements for the authenticated customer.
|
|
67
|
+
*/
|
|
68
|
+
capabilities: CustomerCapabilities;
|
|
69
|
+
}
|
|
70
|
+
interface UnavailableConnection {
|
|
71
|
+
status: ConnectionStatus.unavailable;
|
|
72
|
+
}
|
|
73
|
+
interface PendingConnection {
|
|
74
|
+
status: ConnectionStatus.pending;
|
|
75
|
+
}
|
|
76
|
+
interface FailedConnection {
|
|
77
|
+
status: ConnectionStatus.failed;
|
|
78
|
+
reason: string;
|
|
79
|
+
}
|
|
80
|
+
interface TermsAcceptanceRequiredConnection {
|
|
81
|
+
status: ConnectionStatus.termsAcceptanceRequired;
|
|
82
|
+
}
|
|
83
|
+
/** Discriminated union of all connection result statuses. */
|
|
84
|
+
type Connection = ConnectionRequired | ActiveConnection | UnavailableConnection | PendingConnection | FailedConnection | TermsAcceptanceRequiredConnection;
|
|
85
|
+
interface DecryptedCredentials {
|
|
86
|
+
accessToken: string;
|
|
87
|
+
clientToken: string;
|
|
88
|
+
expiresAt: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Capabilities and regulatory requirements for the authenticated customer.
|
|
92
|
+
*/
|
|
93
|
+
interface CustomerCapabilities {
|
|
94
|
+
/** Capabilities for the ramps (buy and sell) product. */
|
|
95
|
+
ramps?: RampsCapability;
|
|
96
|
+
/** Capabilities for the Apple Pay 1TAP flow. Present when 1TAP is enabled for the partner and the customer matches. */
|
|
97
|
+
oneTapApplePay?: RampsCapability;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Capabilities and requirements for the ramps (buy and sell) product.
|
|
101
|
+
*/
|
|
102
|
+
interface RampsCapability {
|
|
103
|
+
/** Regulatory requirements for ramps operations in the customer's jurisdiction. */
|
|
104
|
+
requirements: RampsRequirements;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Regulatory requirements that apply to ramps operations for the customer.
|
|
108
|
+
*/
|
|
109
|
+
interface RampsRequirements {
|
|
110
|
+
/**
|
|
111
|
+
* Present when the customer's jurisdiction requires payment disclosures
|
|
112
|
+
* before a ramps transaction. Omitted when no disclosures are required.
|
|
113
|
+
*/
|
|
114
|
+
paymentDisclosures?: PaymentDisclosuresRequirement;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* A jurisdiction that requires payment disclosures before a ramps transaction.
|
|
118
|
+
*/
|
|
119
|
+
interface PaymentDisclosuresRequirement {
|
|
120
|
+
/** The ISO 3166-1 alpha-3 country code for the jurisdiction. */
|
|
121
|
+
country: string;
|
|
122
|
+
/** The state or province code within the country. */
|
|
123
|
+
administrativeArea: string;
|
|
124
|
+
}
|
|
125
|
+
declare enum ConnectionErrorCode {
|
|
126
|
+
validationError = "validationError",
|
|
127
|
+
/** Wire value is `'generic'`. */
|
|
128
|
+
connectionFailedGeneric = "generic"
|
|
129
|
+
}
|
|
130
|
+
interface ConfigValidationFieldError {
|
|
131
|
+
code: 'invalidSessionToken' | 'invalidClientToken' | 'invalidPublicKey';
|
|
132
|
+
message: string;
|
|
133
|
+
}
|
|
134
|
+
type ConnectionError = {
|
|
135
|
+
code: ConnectionErrorCode.validationError;
|
|
136
|
+
errors: ConfigValidationFieldError[];
|
|
137
|
+
} | {
|
|
138
|
+
code: ConnectionErrorCode.connectionFailedGeneric;
|
|
139
|
+
message?: string;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export { type ActiveConnection, type ConfigValidationFieldError, type Connection, type ConnectionError, ConnectionErrorCode, type ConnectionRequired, ConnectionStatus, type CustomerCapabilities, type DecryptedCredentials, type FailedConnection, type PaymentDisclosuresRequirement, type PendingConnection, type RampsCapability, type RampsRequirements, type TermsAcceptanceRequiredConnection, type UnavailableConnection };
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
declare enum ConnectionStatus {
|
|
2
|
+
/**
|
|
3
|
+
* New or expired user — needs the full connect flow.
|
|
4
|
+
*/
|
|
5
|
+
connectionRequired = "connectionRequired",
|
|
6
|
+
/**
|
|
7
|
+
* Valid connection — encrypted credentials are included.
|
|
8
|
+
*/
|
|
9
|
+
active = "active",
|
|
10
|
+
/**
|
|
11
|
+
* Restricted location — connection cannot be used.
|
|
12
|
+
*/
|
|
13
|
+
unavailable = "unavailable",
|
|
14
|
+
/**
|
|
15
|
+
* KYC decision delayed — may resolve on a subsequent visit.
|
|
16
|
+
*/
|
|
17
|
+
pending = "pending",
|
|
18
|
+
/**
|
|
19
|
+
* Terminal failure — KYC fail, rejection, etc.
|
|
20
|
+
*/
|
|
21
|
+
failed = "failed",
|
|
22
|
+
/**
|
|
23
|
+
* Customer has no valid Terms of Use attestation on file (headless/Identity API partners).
|
|
24
|
+
* Display Terms of Use in your own UI, capture acceptance, call
|
|
25
|
+
* `POST /platform/v1/terms/attestations`, then retry the connection.
|
|
26
|
+
*/
|
|
27
|
+
termsAcceptanceRequired = "termsAcceptanceRequired"
|
|
28
|
+
}
|
|
29
|
+
interface ConnectionRequired {
|
|
30
|
+
status: ConnectionStatus.connectionRequired;
|
|
31
|
+
/**
|
|
32
|
+
* Base64-encoded, X25519+AES-GCM encrypted anonymous token payload.
|
|
33
|
+
* These are frame-internal tokens used by the connect frame — they cannot be
|
|
34
|
+
* used to call MoonPay APIs directly. Decrypt via `decryptCredentials()` only
|
|
35
|
+
* if you need the `clientToken` to bootstrap the connect frame manually.
|
|
36
|
+
*/
|
|
37
|
+
credentials: string;
|
|
38
|
+
/**
|
|
39
|
+
* Capabilities and regulatory requirements available before authentication, if any.
|
|
40
|
+
* Present when Apple Pay 1TAP is enabled for the partner.
|
|
41
|
+
*/
|
|
42
|
+
capabilities?: CustomerCapabilities;
|
|
43
|
+
}
|
|
44
|
+
interface ActiveConnection {
|
|
45
|
+
status: ConnectionStatus.active;
|
|
46
|
+
/** The authenticated MoonPay customer. */
|
|
47
|
+
customer: {
|
|
48
|
+
id: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Base64-encoded, X25519+AES-GCM encrypted JSON containing:
|
|
52
|
+
* ```json
|
|
53
|
+
* {
|
|
54
|
+
* "accessToken": "<token>",
|
|
55
|
+
* "clientToken": "<token>",
|
|
56
|
+
* "expiresAt": "<iso8601>"
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* - `accessToken`: A token that can be used to make API requests from the client.
|
|
61
|
+
* - `clientToken`: A token that can be used to initialize sensitive frames such as Apple Pay.
|
|
62
|
+
* - `expiresAt`: An ISO 8601 formatted string indicating when the tokens expire.
|
|
63
|
+
*/
|
|
64
|
+
credentials: string;
|
|
65
|
+
/**
|
|
66
|
+
* Capabilities and regulatory requirements for the authenticated customer.
|
|
67
|
+
*/
|
|
68
|
+
capabilities: CustomerCapabilities;
|
|
69
|
+
}
|
|
70
|
+
interface UnavailableConnection {
|
|
71
|
+
status: ConnectionStatus.unavailable;
|
|
72
|
+
}
|
|
73
|
+
interface PendingConnection {
|
|
74
|
+
status: ConnectionStatus.pending;
|
|
75
|
+
}
|
|
76
|
+
interface FailedConnection {
|
|
77
|
+
status: ConnectionStatus.failed;
|
|
78
|
+
reason: string;
|
|
79
|
+
}
|
|
80
|
+
interface TermsAcceptanceRequiredConnection {
|
|
81
|
+
status: ConnectionStatus.termsAcceptanceRequired;
|
|
82
|
+
}
|
|
83
|
+
/** Discriminated union of all connection result statuses. */
|
|
84
|
+
type Connection = ConnectionRequired | ActiveConnection | UnavailableConnection | PendingConnection | FailedConnection | TermsAcceptanceRequiredConnection;
|
|
85
|
+
interface DecryptedCredentials {
|
|
86
|
+
accessToken: string;
|
|
87
|
+
clientToken: string;
|
|
88
|
+
expiresAt: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Capabilities and regulatory requirements for the authenticated customer.
|
|
92
|
+
*/
|
|
93
|
+
interface CustomerCapabilities {
|
|
94
|
+
/** Capabilities for the ramps (buy and sell) product. */
|
|
95
|
+
ramps?: RampsCapability;
|
|
96
|
+
/** Capabilities for the Apple Pay 1TAP flow. Present when 1TAP is enabled for the partner and the customer matches. */
|
|
97
|
+
oneTapApplePay?: RampsCapability;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Capabilities and requirements for the ramps (buy and sell) product.
|
|
101
|
+
*/
|
|
102
|
+
interface RampsCapability {
|
|
103
|
+
/** Regulatory requirements for ramps operations in the customer's jurisdiction. */
|
|
104
|
+
requirements: RampsRequirements;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Regulatory requirements that apply to ramps operations for the customer.
|
|
108
|
+
*/
|
|
109
|
+
interface RampsRequirements {
|
|
110
|
+
/**
|
|
111
|
+
* Present when the customer's jurisdiction requires payment disclosures
|
|
112
|
+
* before a ramps transaction. Omitted when no disclosures are required.
|
|
113
|
+
*/
|
|
114
|
+
paymentDisclosures?: PaymentDisclosuresRequirement;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* A jurisdiction that requires payment disclosures before a ramps transaction.
|
|
118
|
+
*/
|
|
119
|
+
interface PaymentDisclosuresRequirement {
|
|
120
|
+
/** The ISO 3166-1 alpha-3 country code for the jurisdiction. */
|
|
121
|
+
country: string;
|
|
122
|
+
/** The state or province code within the country. */
|
|
123
|
+
administrativeArea: string;
|
|
124
|
+
}
|
|
125
|
+
declare enum ConnectionErrorCode {
|
|
126
|
+
validationError = "validationError",
|
|
127
|
+
/** Wire value is `'generic'`. */
|
|
128
|
+
connectionFailedGeneric = "generic"
|
|
129
|
+
}
|
|
130
|
+
interface ConfigValidationFieldError {
|
|
131
|
+
code: 'invalidSessionToken' | 'invalidClientToken' | 'invalidPublicKey';
|
|
132
|
+
message: string;
|
|
133
|
+
}
|
|
134
|
+
type ConnectionError = {
|
|
135
|
+
code: ConnectionErrorCode.validationError;
|
|
136
|
+
errors: ConfigValidationFieldError[];
|
|
137
|
+
} | {
|
|
138
|
+
code: ConnectionErrorCode.connectionFailedGeneric;
|
|
139
|
+
message?: string;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export { type ActiveConnection, type ConfigValidationFieldError, type Connection, type ConnectionError, ConnectionErrorCode, type ConnectionRequired, ConnectionStatus, type CustomerCapabilities, type DecryptedCredentials, type FailedConnection, type PaymentDisclosuresRequirement, type PendingConnection, type RampsCapability, type RampsRequirements, type TermsAcceptanceRequiredConnection, type UnavailableConnection };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/models/connection.ts
|
|
2
|
+
var ConnectionStatus = /* @__PURE__ */ ((ConnectionStatus2) => {
|
|
3
|
+
ConnectionStatus2["connectionRequired"] = "connectionRequired";
|
|
4
|
+
ConnectionStatus2["active"] = "active";
|
|
5
|
+
ConnectionStatus2["unavailable"] = "unavailable";
|
|
6
|
+
ConnectionStatus2["pending"] = "pending";
|
|
7
|
+
ConnectionStatus2["failed"] = "failed";
|
|
8
|
+
ConnectionStatus2["termsAcceptanceRequired"] = "termsAcceptanceRequired";
|
|
9
|
+
return ConnectionStatus2;
|
|
10
|
+
})(ConnectionStatus || {});
|
|
11
|
+
var ConnectionErrorCode = /* @__PURE__ */ ((ConnectionErrorCode2) => {
|
|
12
|
+
ConnectionErrorCode2["validationError"] = "validationError";
|
|
13
|
+
ConnectionErrorCode2["connectionFailedGeneric"] = "generic";
|
|
14
|
+
return ConnectionErrorCode2;
|
|
15
|
+
})(ConnectionErrorCode || {});
|
|
16
|
+
export {
|
|
17
|
+
ConnectionErrorCode,
|
|
18
|
+
ConnectionStatus
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/models/connection.ts"],"sourcesContent":["// ---------------------------------------------------------------------------\n// Connection statuses\n// ---------------------------------------------------------------------------\n\nexport enum ConnectionStatus {\n /**\n * New or expired user — needs the full connect flow.\n */\n connectionRequired = 'connectionRequired',\n\n /**\n * Valid connection — encrypted credentials are included.\n */\n active = 'active',\n\n /**\n * Restricted location — connection cannot be used.\n */\n unavailable = 'unavailable',\n\n /**\n * KYC decision delayed — may resolve on a subsequent visit.\n */\n pending = 'pending',\n\n /**\n * Terminal failure — KYC fail, rejection, etc.\n */\n failed = 'failed',\n\n /**\n * Customer has no valid Terms of Use attestation on file (headless/Identity API partners).\n * Display Terms of Use in your own UI, capture acceptance, call\n * `POST /platform/v1/terms/attestations`, then retry the connection.\n */\n termsAcceptanceRequired = 'termsAcceptanceRequired',\n}\n\nexport interface ConnectionRequired {\n status: ConnectionStatus.connectionRequired;\n /**\n * Base64-encoded, X25519+AES-GCM encrypted anonymous token payload.\n * These are frame-internal tokens used by the connect frame — they cannot be\n * used to call MoonPay APIs directly. Decrypt via `decryptCredentials()` only\n * if you need the `clientToken` to bootstrap the connect frame manually.\n */\n credentials: string;\n /**\n * Capabilities and regulatory requirements available before authentication, if any.\n * Present when Apple Pay 1TAP is enabled for the partner.\n */\n capabilities?: CustomerCapabilities;\n}\n\nexport interface ActiveConnection {\n status: ConnectionStatus.active;\n /** The authenticated MoonPay customer. */\n customer: { id: string };\n /**\n * Base64-encoded, X25519+AES-GCM encrypted JSON containing:\n * ```json\n * {\n * \"accessToken\": \"<token>\",\n * \"clientToken\": \"<token>\",\n * \"expiresAt\": \"<iso8601>\"\n * }\n * ```\n *\n * - `accessToken`: A token that can be used to make API requests from the client.\n * - `clientToken`: A token that can be used to initialize sensitive frames such as Apple Pay.\n * - `expiresAt`: An ISO 8601 formatted string indicating when the tokens expire.\n */\n credentials: string;\n /**\n * Capabilities and regulatory requirements for the authenticated customer.\n */\n capabilities: CustomerCapabilities;\n}\n\nexport interface UnavailableConnection {\n status: ConnectionStatus.unavailable;\n}\n\nexport interface PendingConnection {\n status: ConnectionStatus.pending;\n}\n\nexport interface FailedConnection {\n status: ConnectionStatus.failed;\n reason: string;\n}\n\nexport interface TermsAcceptanceRequiredConnection {\n status: ConnectionStatus.termsAcceptanceRequired;\n}\n\n/** Discriminated union of all connection result statuses. */\nexport type Connection =\n | ConnectionRequired\n | ActiveConnection\n | UnavailableConnection\n | PendingConnection\n | FailedConnection\n | TermsAcceptanceRequiredConnection;\n\n// ---------------------------------------------------------------------------\n// Decrypted credentials (what the SDK exposes after decryption)\n// ---------------------------------------------------------------------------\n\nexport interface DecryptedCredentials {\n accessToken: string;\n clientToken: string;\n expiresAt: string;\n}\n\n// ---------------------------------------------------------------------------\n// Customer capabilities\n// ---------------------------------------------------------------------------\n\n/**\n * Capabilities and regulatory requirements for the authenticated customer.\n */\nexport interface CustomerCapabilities {\n /** Capabilities for the ramps (buy and sell) product. */\n ramps?: RampsCapability;\n /** Capabilities for the Apple Pay 1TAP flow. Present when 1TAP is enabled for the partner and the customer matches. */\n oneTapApplePay?: RampsCapability;\n}\n\n/**\n * Capabilities and requirements for the ramps (buy and sell) product.\n */\nexport interface RampsCapability {\n /** Regulatory requirements for ramps operations in the customer's jurisdiction. */\n requirements: RampsRequirements;\n}\n\n/**\n * Regulatory requirements that apply to ramps operations for the customer.\n */\nexport interface RampsRequirements {\n /**\n * Present when the customer's jurisdiction requires payment disclosures\n * before a ramps transaction. Omitted when no disclosures are required.\n */\n paymentDisclosures?: PaymentDisclosuresRequirement;\n}\n\n/**\n * A jurisdiction that requires payment disclosures before a ramps transaction.\n */\nexport interface PaymentDisclosuresRequirement {\n /** The ISO 3166-1 alpha-3 country code for the jurisdiction. */\n country: string;\n /** The state or province code within the country. */\n administrativeArea: string;\n}\n\n// ---------------------------------------------------------------------------\n// Connection errors\n// ---------------------------------------------------------------------------\n\nexport enum ConnectionErrorCode {\n validationError = 'validationError',\n /** Wire value is `'generic'`. */\n connectionFailedGeneric = 'generic',\n}\n\nexport interface ConfigValidationFieldError {\n code: 'invalidSessionToken' | 'invalidClientToken' | 'invalidPublicKey';\n message: string;\n}\n\nexport type ConnectionError =\n | {\n code: ConnectionErrorCode.validationError;\n errors: ConfigValidationFieldError[];\n }\n | {\n code: ConnectionErrorCode.connectionFailedGeneric;\n message?: string;\n };\n"],"mappings":";AAIO,IAAK,mBAAL,kBAAKA,sBAAL;AAIL,EAAAA,kBAAA,wBAAqB;AAKrB,EAAAA,kBAAA,YAAS;AAKT,EAAAA,kBAAA,iBAAc;AAKd,EAAAA,kBAAA,aAAU;AAKV,EAAAA,kBAAA,YAAS;AAOT,EAAAA,kBAAA,6BAA0B;AA/BhB,SAAAA;AAAA,GAAA;AA8JL,IAAK,sBAAL,kBAAKC,yBAAL;AACL,EAAAA,qBAAA,qBAAkB;AAElB,EAAAA,qBAAA,6BAA0B;AAHhB,SAAAA;AAAA,GAAA;","names":["ConnectionStatus","ConnectionErrorCode"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/models/transaction.ts
|
|
17
|
+
var transaction_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(transaction_exports);
|
|
19
|
+
//# sourceMappingURL=transaction.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/models/transaction.ts"],"sourcesContent":["/**\n * Transaction shape as sent within frame postMessage payloads.\n * Two variants: happy path (`{ id, status }`) and explicit failed path with\n * `failureReason` for partner-facing diagnostics.\n */\nexport type FrameTransaction =\n | { id: string; status: string }\n | { id?: string; status: 'failed'; failureReason: string };\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transaction shape as sent within frame postMessage payloads.
|
|
3
|
+
* Two variants: happy path (`{ id, status }`) and explicit failed path with
|
|
4
|
+
* `failureReason` for partner-facing diagnostics.
|
|
5
|
+
*/
|
|
6
|
+
type FrameTransaction = {
|
|
7
|
+
id: string;
|
|
8
|
+
status: string;
|
|
9
|
+
} | {
|
|
10
|
+
id?: string;
|
|
11
|
+
status: 'failed';
|
|
12
|
+
failureReason: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type { FrameTransaction };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transaction shape as sent within frame postMessage payloads.
|
|
3
|
+
* Two variants: happy path (`{ id, status }`) and explicit failed path with
|
|
4
|
+
* `failureReason` for partner-facing diagnostics.
|
|
5
|
+
*/
|
|
6
|
+
type FrameTransaction = {
|
|
7
|
+
id: string;
|
|
8
|
+
status: string;
|
|
9
|
+
} | {
|
|
10
|
+
id?: string;
|
|
11
|
+
status: 'failed';
|
|
12
|
+
failureReason: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type { FrameTransaction };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/protocol.ts
|
|
21
|
+
var protocol_exports = {};
|
|
22
|
+
__export(protocol_exports, {
|
|
23
|
+
HANDSHAKE_ACK_KIND: () => HANDSHAKE_ACK_KIND,
|
|
24
|
+
HANDSHAKE_REQUEST_KIND: () => HANDSHAKE_REQUEST_KIND
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(protocol_exports);
|
|
27
|
+
var HANDSHAKE_REQUEST_KIND = "handshake";
|
|
28
|
+
var HANDSHAKE_ACK_KIND = "ack";
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
HANDSHAKE_ACK_KIND,
|
|
32
|
+
HANDSHAKE_REQUEST_KIND
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=protocol.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/protocol.ts"],"sourcesContent":["// Wire format\nexport interface ProtocolMessage<K extends string = string, P = unknown> {\n version: 2;\n meta: { channelId: string };\n kind: K;\n payload?: P;\n}\n\n// Handshake\nexport const HANDSHAKE_REQUEST_KIND = 'handshake' as const;\nexport const HANDSHAKE_ACK_KIND = 'ack' as const;\nexport type HandshakeRequest = ProtocolMessage<typeof HANDSHAKE_REQUEST_KIND>;\nexport type HandshakeAck = ProtocolMessage<typeof HANDSHAKE_ACK_KIND>;\n\n/**\n * Generic error payload sent by frames to the SDK. `C` is the union of known\n * error codes — defaults to `string` for frames where the code set is open.\n *\n * Consumers should obtain a frame's concrete error type via the message map,\n * e.g. `InboundMessageMap['error']`, rather than constructing\n * `FrameError<...>` directly.\n */\nexport interface FrameError<C extends string = string> {\n code: C;\n message: string;\n}\n\n// Typed message constructors (utility types)\nexport type TypedMessage<\n Map extends Record<string, unknown>,\n K extends keyof Map & string,\n> = Map[K] extends void ? ProtocolMessage<K, undefined> : ProtocolMessage<K, Map[K]>;\n\nexport type MessageUnion<Map extends Record<string, unknown>> = {\n [K in keyof Map & string]: TypedMessage<Map, K>;\n}[keyof Map & string];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASO,IAAM,yBAAyB;AAC/B,IAAM,qBAAqB;","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
interface ProtocolMessage<K extends string = string, P = unknown> {
|
|
2
|
+
version: 2;
|
|
3
|
+
meta: {
|
|
4
|
+
channelId: string;
|
|
5
|
+
};
|
|
6
|
+
kind: K;
|
|
7
|
+
payload?: P;
|
|
8
|
+
}
|
|
9
|
+
declare const HANDSHAKE_REQUEST_KIND: "handshake";
|
|
10
|
+
declare const HANDSHAKE_ACK_KIND: "ack";
|
|
11
|
+
type HandshakeRequest = ProtocolMessage<typeof HANDSHAKE_REQUEST_KIND>;
|
|
12
|
+
type HandshakeAck = ProtocolMessage<typeof HANDSHAKE_ACK_KIND>;
|
|
13
|
+
/**
|
|
14
|
+
* Generic error payload sent by frames to the SDK. `C` is the union of known
|
|
15
|
+
* error codes — defaults to `string` for frames where the code set is open.
|
|
16
|
+
*
|
|
17
|
+
* Consumers should obtain a frame's concrete error type via the message map,
|
|
18
|
+
* e.g. `InboundMessageMap['error']`, rather than constructing
|
|
19
|
+
* `FrameError<...>` directly.
|
|
20
|
+
*/
|
|
21
|
+
interface FrameError<C extends string = string> {
|
|
22
|
+
code: C;
|
|
23
|
+
message: string;
|
|
24
|
+
}
|
|
25
|
+
type TypedMessage<Map extends Record<string, unknown>, K extends keyof Map & string> = Map[K] extends void ? ProtocolMessage<K, undefined> : ProtocolMessage<K, Map[K]>;
|
|
26
|
+
type MessageUnion<Map extends Record<string, unknown>> = {
|
|
27
|
+
[K in keyof Map & string]: TypedMessage<Map, K>;
|
|
28
|
+
}[keyof Map & string];
|
|
29
|
+
|
|
30
|
+
export { type FrameError, HANDSHAKE_ACK_KIND, HANDSHAKE_REQUEST_KIND, type HandshakeAck, type HandshakeRequest, type MessageUnion, type ProtocolMessage, type TypedMessage };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
interface ProtocolMessage<K extends string = string, P = unknown> {
|
|
2
|
+
version: 2;
|
|
3
|
+
meta: {
|
|
4
|
+
channelId: string;
|
|
5
|
+
};
|
|
6
|
+
kind: K;
|
|
7
|
+
payload?: P;
|
|
8
|
+
}
|
|
9
|
+
declare const HANDSHAKE_REQUEST_KIND: "handshake";
|
|
10
|
+
declare const HANDSHAKE_ACK_KIND: "ack";
|
|
11
|
+
type HandshakeRequest = ProtocolMessage<typeof HANDSHAKE_REQUEST_KIND>;
|
|
12
|
+
type HandshakeAck = ProtocolMessage<typeof HANDSHAKE_ACK_KIND>;
|
|
13
|
+
/**
|
|
14
|
+
* Generic error payload sent by frames to the SDK. `C` is the union of known
|
|
15
|
+
* error codes — defaults to `string` for frames where the code set is open.
|
|
16
|
+
*
|
|
17
|
+
* Consumers should obtain a frame's concrete error type via the message map,
|
|
18
|
+
* e.g. `InboundMessageMap['error']`, rather than constructing
|
|
19
|
+
* `FrameError<...>` directly.
|
|
20
|
+
*/
|
|
21
|
+
interface FrameError<C extends string = string> {
|
|
22
|
+
code: C;
|
|
23
|
+
message: string;
|
|
24
|
+
}
|
|
25
|
+
type TypedMessage<Map extends Record<string, unknown>, K extends keyof Map & string> = Map[K] extends void ? ProtocolMessage<K, undefined> : ProtocolMessage<K, Map[K]>;
|
|
26
|
+
type MessageUnion<Map extends Record<string, unknown>> = {
|
|
27
|
+
[K in keyof Map & string]: TypedMessage<Map, K>;
|
|
28
|
+
}[keyof Map & string];
|
|
29
|
+
|
|
30
|
+
export { type FrameError, HANDSHAKE_ACK_KIND, HANDSHAKE_REQUEST_KIND, type HandshakeAck, type HandshakeRequest, type MessageUnion, type ProtocolMessage, type TypedMessage };
|
package/dist/protocol.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/protocol.ts"],"sourcesContent":["// Wire format\nexport interface ProtocolMessage<K extends string = string, P = unknown> {\n version: 2;\n meta: { channelId: string };\n kind: K;\n payload?: P;\n}\n\n// Handshake\nexport const HANDSHAKE_REQUEST_KIND = 'handshake' as const;\nexport const HANDSHAKE_ACK_KIND = 'ack' as const;\nexport type HandshakeRequest = ProtocolMessage<typeof HANDSHAKE_REQUEST_KIND>;\nexport type HandshakeAck = ProtocolMessage<typeof HANDSHAKE_ACK_KIND>;\n\n/**\n * Generic error payload sent by frames to the SDK. `C` is the union of known\n * error codes — defaults to `string` for frames where the code set is open.\n *\n * Consumers should obtain a frame's concrete error type via the message map,\n * e.g. `InboundMessageMap['error']`, rather than constructing\n * `FrameError<...>` directly.\n */\nexport interface FrameError<C extends string = string> {\n code: C;\n message: string;\n}\n\n// Typed message constructors (utility types)\nexport type TypedMessage<\n Map extends Record<string, unknown>,\n K extends keyof Map & string,\n> = Map[K] extends void ? ProtocolMessage<K, undefined> : ProtocolMessage<K, Map[K]>;\n\nexport type MessageUnion<Map extends Record<string, unknown>> = {\n [K in keyof Map & string]: TypedMessage<Map, K>;\n}[keyof Map & string];\n"],"mappings":";AASO,IAAM,yBAAyB;AAC/B,IAAM,qBAAqB;","names":[]}
|
package/dist/result.cjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/result.ts
|
|
21
|
+
var result_exports = {};
|
|
22
|
+
__export(result_exports, {
|
|
23
|
+
err: () => err,
|
|
24
|
+
ok: () => ok
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(result_exports);
|
|
27
|
+
var ok = (value) => ({
|
|
28
|
+
ok: true,
|
|
29
|
+
value
|
|
30
|
+
});
|
|
31
|
+
var err = (error) => ({
|
|
32
|
+
ok: false,
|
|
33
|
+
error
|
|
34
|
+
});
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
err,
|
|
38
|
+
ok
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=result.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/result.ts"],"sourcesContent":["/**\n * A discriminated union representing either a successful value or an error.\n * SDK methods return this type instead of throwing exceptions.\n */\nexport type Result<T, E> = { ok: true; value: T } | { ok: false; error: E };\n\n/** A Result variant for operations that produce no value on success. */\nexport type EmptyResult<E> = { ok: true } | { ok: false; error: E };\n\n/** Construct a successful Result. */\nexport const ok = <T>(value: T): { ok: true; value: T } => ({\n ok: true,\n value,\n});\n\n/** Construct a failed Result. */\nexport const err = <E>(error: E): { ok: false; error: E } => ({\n ok: false,\n error,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUO,IAAM,KAAK,CAAI,WAAsC;AAAA,EAC1D,IAAI;AAAA,EACJ;AACF;AAGO,IAAM,MAAM,CAAI,WAAuC;AAAA,EAC5D,IAAI;AAAA,EACJ;AACF;","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A discriminated union representing either a successful value or an error.
|
|
3
|
+
* SDK methods return this type instead of throwing exceptions.
|
|
4
|
+
*/
|
|
5
|
+
type Result<T, E> = {
|
|
6
|
+
ok: true;
|
|
7
|
+
value: T;
|
|
8
|
+
} | {
|
|
9
|
+
ok: false;
|
|
10
|
+
error: E;
|
|
11
|
+
};
|
|
12
|
+
/** A Result variant for operations that produce no value on success. */
|
|
13
|
+
type EmptyResult<E> = {
|
|
14
|
+
ok: true;
|
|
15
|
+
} | {
|
|
16
|
+
ok: false;
|
|
17
|
+
error: E;
|
|
18
|
+
};
|
|
19
|
+
/** Construct a successful Result. */
|
|
20
|
+
declare const ok: <T>(value: T) => {
|
|
21
|
+
ok: true;
|
|
22
|
+
value: T;
|
|
23
|
+
};
|
|
24
|
+
/** Construct a failed Result. */
|
|
25
|
+
declare const err: <E>(error: E) => {
|
|
26
|
+
ok: false;
|
|
27
|
+
error: E;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { type EmptyResult, type Result, err, ok };
|
package/dist/result.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A discriminated union representing either a successful value or an error.
|
|
3
|
+
* SDK methods return this type instead of throwing exceptions.
|
|
4
|
+
*/
|
|
5
|
+
type Result<T, E> = {
|
|
6
|
+
ok: true;
|
|
7
|
+
value: T;
|
|
8
|
+
} | {
|
|
9
|
+
ok: false;
|
|
10
|
+
error: E;
|
|
11
|
+
};
|
|
12
|
+
/** A Result variant for operations that produce no value on success. */
|
|
13
|
+
type EmptyResult<E> = {
|
|
14
|
+
ok: true;
|
|
15
|
+
} | {
|
|
16
|
+
ok: false;
|
|
17
|
+
error: E;
|
|
18
|
+
};
|
|
19
|
+
/** Construct a successful Result. */
|
|
20
|
+
declare const ok: <T>(value: T) => {
|
|
21
|
+
ok: true;
|
|
22
|
+
value: T;
|
|
23
|
+
};
|
|
24
|
+
/** Construct a failed Result. */
|
|
25
|
+
declare const err: <E>(error: E) => {
|
|
26
|
+
ok: false;
|
|
27
|
+
error: E;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { type EmptyResult, type Result, err, ok };
|
package/dist/result.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/result.ts"],"sourcesContent":["/**\n * A discriminated union representing either a successful value or an error.\n * SDK methods return this type instead of throwing exceptions.\n */\nexport type Result<T, E> = { ok: true; value: T } | { ok: false; error: E };\n\n/** A Result variant for operations that produce no value on success. */\nexport type EmptyResult<E> = { ok: true } | { ok: false; error: E };\n\n/** Construct a successful Result. */\nexport const ok = <T>(value: T): { ok: true; value: T } => ({\n ok: true,\n value,\n});\n\n/** Construct a failed Result. */\nexport const err = <E>(error: E): { ok: false; error: E } => ({\n ok: false,\n error,\n});\n"],"mappings":";AAUO,IAAM,KAAK,CAAI,WAAsC;AAAA,EAC1D,IAAI;AAAA,EACJ;AACF;AAGO,IAAM,MAAM,CAAI,WAAuC;AAAA,EAC5D,IAAI;AAAA,EACJ;AACF;","names":[]}
|