@snap-pay/types 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/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0
4
+
5
+ Initial public release.
6
+
7
+ - Wire shapes for `PublicSession`, `PaymentResult`, and every Element's postMessage protocol
8
+ - `SnapSelection` discriminated union (`"provider"` | `"card"`) for extensible container selection
9
+ - Full Appearance API: `theme`, `primaryColor`, `borderRadius`, `fontFamily`, `spacingUnit`, `labelColor`, `errorColor`, `mutedColor`, and per-Element `rules`
10
+ - `SnapElementsHandle._getValue(type)` for reading form values from `billingAddress` / `customer` / `otp` elements
11
+ - `ElementType` union covers the full Element surface: `wallet`, `card`, `payment`, `express`, `paymentMethodSelector`, `billingAddress`, `customer`, `otp`, `qr`
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # @snap-pay/types
2
+
3
+ Shared, dependency-free TypeScript definitions used by every SNAP client-side package (`@snap-pay/js`, `@snap-pay/elements`, `@snap-pay/react`).
4
+
5
+ You usually don't install this directly — it's a transitive dependency of the packages you actually consume. Import types straight from those packages:
6
+
7
+ ```ts
8
+ import type { Appearance, PaymentResult } from "@snap-pay/js";
9
+ ```
10
+
11
+ ## Why a separate package
12
+
13
+ Isolating the wire shapes (`PublicSession`, `PaymentResult`, the postMessage protocol for the Card iframe, the discriminated `SnapSelection` union) in their own package means bumping a type shape doesn't force a rebuild of every downstream package that only re-exported it. Downstream consumers pin the same version transitively.
14
+
15
+ ## License
16
+
17
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -0,0 +1,189 @@
1
+ type Environment = "sandbox" | "live";
2
+ type CheckoutProvider = "mock" | "evcPlus" | "sahal" | "zaad" | "edahab" | "jeeb" | "premierWallet" | "premierMastercard";
3
+ type WalletProvider = Exclude<CheckoutProvider, "mock" | "premierMastercard">;
4
+ type SessionStatus = "open" | "processing" | "paid" | "canceled" | "expired";
5
+ interface PublicSessionResponse {
6
+ id: string;
7
+ object: "checkout.session";
8
+ amount: number;
9
+ currency: string;
10
+ allowed_providers: CheckoutProvider[];
11
+ status: SessionStatus;
12
+ expires_at: number;
13
+ transaction_id: string | null;
14
+ merchant_name: string;
15
+ customer: {
16
+ name?: string;
17
+ email?: string;
18
+ phone?: string;
19
+ country?: string;
20
+ } | null;
21
+ success_url: string;
22
+ cancel_url: string;
23
+ request_id: string;
24
+ }
25
+ interface PublicSession {
26
+ id: string;
27
+ amount: number;
28
+ currency: string;
29
+ allowedProviders: CheckoutProvider[];
30
+ status: SessionStatus;
31
+ expiresAt: number;
32
+ transactionId: string | null;
33
+ merchantName: string;
34
+ customer: {
35
+ name?: string;
36
+ email?: string;
37
+ phone?: string;
38
+ country?: string;
39
+ } | null;
40
+ successUrl: string;
41
+ cancelUrl: string;
42
+ }
43
+ type PaymentStatus = "pending" | "processing" | "succeeded" | "failed" | "cancelled" | "refunded" | "partially_refunded" | "held_for_review";
44
+ interface PaymentResult {
45
+ transactionId: string;
46
+ status: PaymentStatus;
47
+ }
48
+ interface WirePaymentResult {
49
+ transaction_id: string;
50
+ object: "checkout.session.payment";
51
+ status: PaymentStatus;
52
+ request_id: string;
53
+ }
54
+ interface ElementEventMap {
55
+ ready: undefined;
56
+ change: {
57
+ complete: boolean;
58
+ };
59
+ focus: undefined;
60
+ blur: undefined;
61
+ submit: undefined;
62
+ failed: {
63
+ error: string;
64
+ };
65
+ }
66
+ type ElementEventName = keyof ElementEventMap;
67
+ type ElementEventHandler<E extends ElementEventName> = (payload: ElementEventMap[E]) => void;
68
+ type ElementType = "wallet" | "card" | "payment" | "express" | "paymentMethodSelector" | "billingAddress" | "customer" | "otp" | "qr";
69
+ interface ElementRule {
70
+ background?: string;
71
+ foreground?: string;
72
+ border?: string;
73
+ borderRadius?: string;
74
+ fontFamily?: string;
75
+ padding?: string;
76
+ gap?: string;
77
+ }
78
+ interface Appearance {
79
+ theme?: "light" | "dark" | "auto";
80
+ primaryColor?: string;
81
+ borderRadius?: string;
82
+ fontFamily?: string;
83
+ spacingUnit?: string;
84
+ labelColor?: string;
85
+ errorColor?: string;
86
+ mutedColor?: string;
87
+ rules?: Partial<Record<ElementType, ElementRule>>;
88
+ }
89
+ interface ElementsOptions {
90
+ clientSecret: string;
91
+ appearance?: Appearance;
92
+ }
93
+ interface CreateElementOptions {
94
+ layout?: "vertical" | "tabs";
95
+ defaultCountry?: string;
96
+ otpLength?: number;
97
+ }
98
+ interface ConfirmPaymentOptions {
99
+ elements: SnapElementsHandle;
100
+ clientSecret: string;
101
+ }
102
+ type SnapSelection = {
103
+ kind: "provider";
104
+ provider: CheckoutProvider;
105
+ } | {
106
+ kind: "card";
107
+ token: string;
108
+ brand: string;
109
+ last4: string;
110
+ };
111
+ interface BillingAddressValue {
112
+ name?: string;
113
+ line1?: string;
114
+ line2?: string;
115
+ city?: string;
116
+ region?: string;
117
+ postalCode?: string;
118
+ country?: string;
119
+ }
120
+ interface CustomerValue {
121
+ name?: string;
122
+ email?: string;
123
+ phone?: string;
124
+ }
125
+ interface OtpValue {
126
+ code: string;
127
+ }
128
+ interface SnapElementsHandle {
129
+ readonly clientSecret: string;
130
+ readonly appearance: Appearance;
131
+ _getSelection(): SnapSelection | null;
132
+ _getValue?(type: ElementType): unknown | null;
133
+ }
134
+ interface SnapElementHandle {
135
+ readonly type: ElementType;
136
+ mount(target: string | HTMLElement): void;
137
+ unmount(): void;
138
+ destroy(): void;
139
+ on<E extends ElementEventName>(event: E, handler: ElementEventHandler<E>): void;
140
+ off<E extends ElementEventName>(event: E, handler: ElementEventHandler<E>): void;
141
+ getValue?(): unknown;
142
+ }
143
+ interface SnapOptions {
144
+ apiBase?: string;
145
+ locale?: "en";
146
+ cardFrameUrl?: string;
147
+ }
148
+ type SnapCardParentMessage = {
149
+ channel: "snap-card";
150
+ type: "init";
151
+ publishableKey: string;
152
+ clientSecret: string;
153
+ environment: Environment;
154
+ appearance: Appearance;
155
+ } | {
156
+ channel: "snap-card";
157
+ type: "submit";
158
+ } | {
159
+ channel: "snap-card";
160
+ type: "reset";
161
+ };
162
+ type SnapCardFrameMessage = {
163
+ channel: "snap-card";
164
+ type: "ready";
165
+ } | {
166
+ channel: "snap-card";
167
+ type: "change";
168
+ complete: boolean;
169
+ brand: string;
170
+ error: string | null;
171
+ } | {
172
+ channel: "snap-card";
173
+ type: "focus";
174
+ } | {
175
+ channel: "snap-card";
176
+ type: "blur";
177
+ } | {
178
+ channel: "snap-card";
179
+ type: "token";
180
+ token: string;
181
+ brand: string;
182
+ last4: string;
183
+ } | {
184
+ channel: "snap-card";
185
+ type: "error";
186
+ message: string;
187
+ };
188
+
189
+ export type { Appearance, BillingAddressValue, CheckoutProvider, ConfirmPaymentOptions, CreateElementOptions, CustomerValue, ElementEventHandler, ElementEventMap, ElementEventName, ElementRule, ElementType, ElementsOptions, Environment, OtpValue, PaymentResult, PaymentStatus, PublicSession, PublicSessionResponse, SessionStatus, SnapCardFrameMessage, SnapCardParentMessage, SnapElementHandle, SnapElementsHandle, SnapOptions, SnapSelection, WalletProvider, WirePaymentResult };
@@ -0,0 +1,189 @@
1
+ type Environment = "sandbox" | "live";
2
+ type CheckoutProvider = "mock" | "evcPlus" | "sahal" | "zaad" | "edahab" | "jeeb" | "premierWallet" | "premierMastercard";
3
+ type WalletProvider = Exclude<CheckoutProvider, "mock" | "premierMastercard">;
4
+ type SessionStatus = "open" | "processing" | "paid" | "canceled" | "expired";
5
+ interface PublicSessionResponse {
6
+ id: string;
7
+ object: "checkout.session";
8
+ amount: number;
9
+ currency: string;
10
+ allowed_providers: CheckoutProvider[];
11
+ status: SessionStatus;
12
+ expires_at: number;
13
+ transaction_id: string | null;
14
+ merchant_name: string;
15
+ customer: {
16
+ name?: string;
17
+ email?: string;
18
+ phone?: string;
19
+ country?: string;
20
+ } | null;
21
+ success_url: string;
22
+ cancel_url: string;
23
+ request_id: string;
24
+ }
25
+ interface PublicSession {
26
+ id: string;
27
+ amount: number;
28
+ currency: string;
29
+ allowedProviders: CheckoutProvider[];
30
+ status: SessionStatus;
31
+ expiresAt: number;
32
+ transactionId: string | null;
33
+ merchantName: string;
34
+ customer: {
35
+ name?: string;
36
+ email?: string;
37
+ phone?: string;
38
+ country?: string;
39
+ } | null;
40
+ successUrl: string;
41
+ cancelUrl: string;
42
+ }
43
+ type PaymentStatus = "pending" | "processing" | "succeeded" | "failed" | "cancelled" | "refunded" | "partially_refunded" | "held_for_review";
44
+ interface PaymentResult {
45
+ transactionId: string;
46
+ status: PaymentStatus;
47
+ }
48
+ interface WirePaymentResult {
49
+ transaction_id: string;
50
+ object: "checkout.session.payment";
51
+ status: PaymentStatus;
52
+ request_id: string;
53
+ }
54
+ interface ElementEventMap {
55
+ ready: undefined;
56
+ change: {
57
+ complete: boolean;
58
+ };
59
+ focus: undefined;
60
+ blur: undefined;
61
+ submit: undefined;
62
+ failed: {
63
+ error: string;
64
+ };
65
+ }
66
+ type ElementEventName = keyof ElementEventMap;
67
+ type ElementEventHandler<E extends ElementEventName> = (payload: ElementEventMap[E]) => void;
68
+ type ElementType = "wallet" | "card" | "payment" | "express" | "paymentMethodSelector" | "billingAddress" | "customer" | "otp" | "qr";
69
+ interface ElementRule {
70
+ background?: string;
71
+ foreground?: string;
72
+ border?: string;
73
+ borderRadius?: string;
74
+ fontFamily?: string;
75
+ padding?: string;
76
+ gap?: string;
77
+ }
78
+ interface Appearance {
79
+ theme?: "light" | "dark" | "auto";
80
+ primaryColor?: string;
81
+ borderRadius?: string;
82
+ fontFamily?: string;
83
+ spacingUnit?: string;
84
+ labelColor?: string;
85
+ errorColor?: string;
86
+ mutedColor?: string;
87
+ rules?: Partial<Record<ElementType, ElementRule>>;
88
+ }
89
+ interface ElementsOptions {
90
+ clientSecret: string;
91
+ appearance?: Appearance;
92
+ }
93
+ interface CreateElementOptions {
94
+ layout?: "vertical" | "tabs";
95
+ defaultCountry?: string;
96
+ otpLength?: number;
97
+ }
98
+ interface ConfirmPaymentOptions {
99
+ elements: SnapElementsHandle;
100
+ clientSecret: string;
101
+ }
102
+ type SnapSelection = {
103
+ kind: "provider";
104
+ provider: CheckoutProvider;
105
+ } | {
106
+ kind: "card";
107
+ token: string;
108
+ brand: string;
109
+ last4: string;
110
+ };
111
+ interface BillingAddressValue {
112
+ name?: string;
113
+ line1?: string;
114
+ line2?: string;
115
+ city?: string;
116
+ region?: string;
117
+ postalCode?: string;
118
+ country?: string;
119
+ }
120
+ interface CustomerValue {
121
+ name?: string;
122
+ email?: string;
123
+ phone?: string;
124
+ }
125
+ interface OtpValue {
126
+ code: string;
127
+ }
128
+ interface SnapElementsHandle {
129
+ readonly clientSecret: string;
130
+ readonly appearance: Appearance;
131
+ _getSelection(): SnapSelection | null;
132
+ _getValue?(type: ElementType): unknown | null;
133
+ }
134
+ interface SnapElementHandle {
135
+ readonly type: ElementType;
136
+ mount(target: string | HTMLElement): void;
137
+ unmount(): void;
138
+ destroy(): void;
139
+ on<E extends ElementEventName>(event: E, handler: ElementEventHandler<E>): void;
140
+ off<E extends ElementEventName>(event: E, handler: ElementEventHandler<E>): void;
141
+ getValue?(): unknown;
142
+ }
143
+ interface SnapOptions {
144
+ apiBase?: string;
145
+ locale?: "en";
146
+ cardFrameUrl?: string;
147
+ }
148
+ type SnapCardParentMessage = {
149
+ channel: "snap-card";
150
+ type: "init";
151
+ publishableKey: string;
152
+ clientSecret: string;
153
+ environment: Environment;
154
+ appearance: Appearance;
155
+ } | {
156
+ channel: "snap-card";
157
+ type: "submit";
158
+ } | {
159
+ channel: "snap-card";
160
+ type: "reset";
161
+ };
162
+ type SnapCardFrameMessage = {
163
+ channel: "snap-card";
164
+ type: "ready";
165
+ } | {
166
+ channel: "snap-card";
167
+ type: "change";
168
+ complete: boolean;
169
+ brand: string;
170
+ error: string | null;
171
+ } | {
172
+ channel: "snap-card";
173
+ type: "focus";
174
+ } | {
175
+ channel: "snap-card";
176
+ type: "blur";
177
+ } | {
178
+ channel: "snap-card";
179
+ type: "token";
180
+ token: string;
181
+ brand: string;
182
+ last4: string;
183
+ } | {
184
+ channel: "snap-card";
185
+ type: "error";
186
+ message: string;
187
+ };
188
+
189
+ export type { Appearance, BillingAddressValue, CheckoutProvider, ConfirmPaymentOptions, CreateElementOptions, CustomerValue, ElementEventHandler, ElementEventMap, ElementEventName, ElementRule, ElementType, ElementsOptions, Environment, OtpValue, PaymentResult, PaymentStatus, PublicSession, PublicSessionResponse, SessionStatus, SnapCardFrameMessage, SnapCardParentMessage, SnapElementHandle, SnapElementsHandle, SnapOptions, SnapSelection, WalletProvider, WirePaymentResult };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@snap-pay/types",
3
+ "version": "1.0.0",
4
+ "description": "Shared TypeScript types for the SNAP client-side SDKs (@snap-pay/js, @snap-pay/elements, @snap-pay/react).",
5
+ "license": "MIT",
6
+ "author": "SNAP",
7
+ "homepage": "https://github.com/khaledhussein957/SNAP/tree/main/packages/types",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/khaledhussein957/SNAP.git",
11
+ "directory": "packages/types"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/khaledhussein957/SNAP/issues"
15
+ },
16
+ "keywords": ["snap", "payments", "types", "typescript", "sdk"],
17
+ "sideEffects": false,
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "type": "module",
22
+ "main": "./dist/index.cjs",
23
+ "module": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js",
29
+ "require": "./dist/index.cjs"
30
+ }
31
+ },
32
+ "files": ["dist", "README.md", "CHANGELOG.md"],
33
+ "scripts": {
34
+ "build": "tsup",
35
+ "typecheck": "tsc --noEmit"
36
+ },
37
+ "devDependencies": {
38
+ "tsup": "^8.3.5",
39
+ "typescript": "^5.7.2"
40
+ }
41
+ }