@ozura/elements 0.1.0-beta.7 → 1.0.1
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 +906 -663
- package/dist/frame/element-frame.js +77 -57
- package/dist/frame/element-frame.js.map +1 -1
- package/dist/frame/tokenizer-frame.html +1 -1
- package/dist/frame/tokenizer-frame.js +211 -94
- package/dist/frame/tokenizer-frame.js.map +1 -1
- package/dist/oz-elements.esm.js +817 -230
- package/dist/oz-elements.esm.js.map +1 -1
- package/dist/oz-elements.umd.js +817 -229
- package/dist/oz-elements.umd.js.map +1 -1
- package/dist/react/frame/tokenizerFrame.d.ts +32 -0
- package/dist/react/index.cjs.js +968 -218
- package/dist/react/index.cjs.js.map +1 -1
- package/dist/react/index.esm.js +965 -219
- package/dist/react/index.esm.js.map +1 -1
- package/dist/react/react/index.d.ts +148 -6
- package/dist/react/sdk/OzElement.d.ts +34 -3
- package/dist/react/sdk/OzVault.d.ts +68 -4
- package/dist/react/sdk/errors.d.ts +9 -0
- package/dist/react/sdk/index.d.ts +29 -0
- package/dist/react/server/index.d.ts +181 -17
- package/dist/react/types/index.d.ts +69 -19
- package/dist/react/utils/appearance.d.ts +9 -0
- package/dist/react/utils/cardUtils.d.ts +14 -0
- package/dist/react/utils/uuid.d.ts +12 -0
- package/dist/server/frame/tokenizerFrame.d.ts +32 -0
- package/dist/server/index.cjs.js +608 -71
- package/dist/server/index.cjs.js.map +1 -1
- package/dist/server/index.esm.js +606 -72
- package/dist/server/index.esm.js.map +1 -1
- package/dist/server/sdk/OzElement.d.ts +34 -3
- package/dist/server/sdk/OzVault.d.ts +68 -4
- package/dist/server/sdk/errors.d.ts +9 -0
- package/dist/server/sdk/index.d.ts +29 -0
- package/dist/server/server/index.d.ts +181 -17
- package/dist/server/types/index.d.ts +69 -19
- package/dist/server/utils/appearance.d.ts +9 -0
- package/dist/server/utils/cardUtils.d.ts +14 -0
- package/dist/server/utils/uuid.d.ts +12 -0
- package/dist/types/frame/tokenizerFrame.d.ts +32 -0
- package/dist/types/sdk/OzElement.d.ts +34 -3
- package/dist/types/sdk/OzVault.d.ts +68 -4
- package/dist/types/sdk/errors.d.ts +9 -0
- package/dist/types/sdk/index.d.ts +29 -0
- package/dist/types/server/index.d.ts +181 -17
- package/dist/types/types/index.d.ts +69 -19
- package/dist/types/utils/appearance.d.ts +9 -0
- package/dist/types/utils/cardUtils.d.ts +14 -0
- package/dist/types/utils/uuid.d.ts +12 -0
- package/package.json +7 -4
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```ts
|
|
9
|
-
* import { Ozura } from '
|
|
9
|
+
* import { Ozura } from '@ozura/elements/server';
|
|
10
10
|
*
|
|
11
11
|
* const ozura = new Ozura({
|
|
12
12
|
* merchantId: process.env.MERCHANT_ID!,
|
|
@@ -28,11 +28,17 @@
|
|
|
28
28
|
*/
|
|
29
29
|
import type { BillingDetails, CardSaleResponseData, TransactionQueryPagination, TransactionData, TransactionType } from '../types';
|
|
30
30
|
export interface OzuraConfig {
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Your Ozura merchant ID (e.g. "ozu_...").
|
|
33
|
+
* Required for `cardSale()`. Tokenize-only integrations (mint + tokenize only) can omit this.
|
|
34
|
+
*/
|
|
35
|
+
merchantId?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Merchant Pay API key — sent as x-api-key header on charge requests.
|
|
38
|
+
* Required for `cardSale()`. Tokenize-only integrations can omit this.
|
|
39
|
+
*/
|
|
40
|
+
apiKey?: string;
|
|
41
|
+
/** Vault API key — used for `mintWaxKey()` and `revokeWaxKey()`. Always required. */
|
|
36
42
|
vaultKey: string;
|
|
37
43
|
/** Ozura Pay API base URL. Defaults to staging. */
|
|
38
44
|
apiUrl?: string;
|
|
@@ -58,6 +64,37 @@ export interface MintWaxKeyResult {
|
|
|
58
64
|
/** Seconds until the wax key expires. Typically 1800 (30 min). */
|
|
59
65
|
expiresInSeconds: number;
|
|
60
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Options for {@link Ozura.mintWaxKey}.
|
|
69
|
+
*/
|
|
70
|
+
export interface MintWaxKeyOptions {
|
|
71
|
+
/**
|
|
72
|
+
* SDK-generated session UUID forwarded from the `fetchWaxKey` callback.
|
|
73
|
+
* Stored by the vault for correlation and audit — not used for authentication.
|
|
74
|
+
*/
|
|
75
|
+
tokenizationSessionId?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Maximum number of tokenize calls this wax key will accept before the vault
|
|
78
|
+
* marks it as consumed. Once consumed, further tokenize attempts return an
|
|
79
|
+
* auth/validation error and the client SDK automatically re-mints a fresh key.
|
|
80
|
+
*
|
|
81
|
+
* Keep this value small (3–5) to limit the blast radius if a key is intercepted.
|
|
82
|
+
* Set the same value in `VaultOptions.maxTokenizeCalls` so the client SDK can
|
|
83
|
+
* proactively refresh before hitting the wall, avoiding a user-visible delay.
|
|
84
|
+
*
|
|
85
|
+
* @default 3
|
|
86
|
+
*/
|
|
87
|
+
maxTokenizeCalls?: number;
|
|
88
|
+
/**
|
|
89
|
+
* Maximum number of proxy calls this wax key will accept.
|
|
90
|
+
* Proxy calls are distinct from tokenize calls — they cover non-tokenize vault
|
|
91
|
+
* operations. Leave `undefined` to use the vault's built-in default.
|
|
92
|
+
*
|
|
93
|
+
* In most integrations you only need `maxTokenizeCalls`; set this only if you
|
|
94
|
+
* are explicitly using vault proxy endpoints.
|
|
95
|
+
*/
|
|
96
|
+
maxProxyCalls?: number;
|
|
97
|
+
}
|
|
61
98
|
export interface CardSaleInput {
|
|
62
99
|
/** From TokenResponse.token (frontend SDK). */
|
|
63
100
|
token: string;
|
|
@@ -96,8 +133,8 @@ export interface ListTransactionsResult {
|
|
|
96
133
|
pagination: TransactionQueryPagination;
|
|
97
134
|
}
|
|
98
135
|
export declare class Ozura {
|
|
99
|
-
private merchantId
|
|
100
|
-
private apiKey
|
|
136
|
+
private merchantId?;
|
|
137
|
+
private apiKey?;
|
|
101
138
|
private vaultKey;
|
|
102
139
|
private apiUrl;
|
|
103
140
|
private vaultUrl;
|
|
@@ -118,27 +155,34 @@ export declare class Ozura {
|
|
|
118
155
|
*/
|
|
119
156
|
listTransactions(input?: ListTransactionsInput): Promise<ListTransactionsResult>;
|
|
120
157
|
/**
|
|
121
|
-
* Mint a short-lived wax key from the vault.
|
|
158
|
+
* Mint a short-lived, use-limited wax key from the vault.
|
|
122
159
|
*
|
|
123
160
|
* Call this server-side to implement the `fetchWaxKey` callback required by
|
|
124
161
|
* `OzVault.create()` on the frontend. The wax key replaces the vault secret
|
|
125
162
|
* on every browser tokenize call — the secret never leaves your server.
|
|
126
163
|
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
164
|
+
* **Use limits:** by default each wax key accepts up to 3 tokenize calls
|
|
165
|
+
* (`maxTokenizeCalls: 3`). After that the vault marks the key as consumed and
|
|
166
|
+
* the client SDK transparently re-mints. Keep `maxTokenizeCalls` in sync with
|
|
167
|
+
* `VaultOptions.maxTokenizeCalls` so the SDK can proactively refresh before
|
|
168
|
+
* hitting the limit rather than waiting for a rejection.
|
|
169
|
+
*
|
|
170
|
+
* **Session correlation:** the `tokenizationSessionId` forwarded from the SDK's
|
|
171
|
+
* `fetchWaxKey` callback should be passed here so the vault can correlate the
|
|
172
|
+
* key with the checkout session in its audit log.
|
|
130
173
|
*
|
|
131
174
|
* @example
|
|
132
175
|
* // Next.js API route
|
|
133
176
|
* export async function POST(req: Request) {
|
|
134
177
|
* const { sessionId } = await req.json();
|
|
135
|
-
* const { waxKey } = await ozura.mintWaxKey({
|
|
178
|
+
* const { waxKey } = await ozura.mintWaxKey({
|
|
179
|
+
* tokenizationSessionId: sessionId,
|
|
180
|
+
* maxTokenizeCalls: 3,
|
|
181
|
+
* });
|
|
136
182
|
* return Response.json({ waxKey });
|
|
137
183
|
* }
|
|
138
184
|
*/
|
|
139
|
-
mintWaxKey(options?:
|
|
140
|
-
tokenizationSessionId?: string;
|
|
141
|
-
}): Promise<MintWaxKeyResult>;
|
|
185
|
+
mintWaxKey(options?: MintWaxKeyOptions): Promise<MintWaxKeyResult>;
|
|
142
186
|
/**
|
|
143
187
|
* Revoke a previously minted wax key.
|
|
144
188
|
*
|
|
@@ -163,11 +207,19 @@ export declare class Ozura {
|
|
|
163
207
|
private post;
|
|
164
208
|
private getRaw;
|
|
165
209
|
private handleResponse;
|
|
210
|
+
/**
|
|
211
|
+
* Parses a Pay API response JSON and throws `OzuraError` on HTTP errors or
|
|
212
|
+
* `success: false` payloads. Used by both `getRaw` and `handleResponse` to
|
|
213
|
+
* avoid duplicating the error-mapping logic.
|
|
214
|
+
*/
|
|
215
|
+
private parseApiJson;
|
|
166
216
|
}
|
|
167
217
|
/** Minimal response shape required by {@link createMintWaxMiddleware}. */
|
|
168
218
|
interface NodeLikeResponse {
|
|
169
219
|
json(data: unknown): void;
|
|
170
220
|
status(code: number): NodeLikeResponse;
|
|
221
|
+
/** Present on Node/Express `ServerResponse` — used for 429 `Retry-After`. */
|
|
222
|
+
setHeader?(name: string, value: string | number): void;
|
|
171
223
|
}
|
|
172
224
|
/**
|
|
173
225
|
* Creates a ready-to-use Fetch API route handler for minting wax keys.
|
|
@@ -219,6 +271,7 @@ export declare function createMintWaxHandler(ozura: Ozura): (req: Request) => Pr
|
|
|
219
271
|
*/
|
|
220
272
|
export declare function createMintWaxMiddleware(ozura: Ozura): (req: {
|
|
221
273
|
body?: unknown;
|
|
274
|
+
headers?: unknown;
|
|
222
275
|
}, res: NodeLikeResponse) => Promise<void>;
|
|
223
276
|
/**
|
|
224
277
|
* Extract the client IP address from a server request object.
|
|
@@ -229,12 +282,123 @@ export declare function createMintWaxMiddleware(ozura: Ozura): (req: {
|
|
|
229
282
|
* (Cloudflare) → `x-forwarded-for` (reverse proxy) → `x-real-ip` →
|
|
230
283
|
* `socket.remoteAddress` → `"0.0.0.0"`.
|
|
231
284
|
*
|
|
285
|
+
* **Proxy trust requirements — read before deploying:**
|
|
286
|
+
*
|
|
287
|
+
* - **`x-forwarded-for` / `x-real-ip`** are HTTP headers that any client can
|
|
288
|
+
* set arbitrarily. They are only trustworthy when your server sits behind a
|
|
289
|
+
* reverse proxy (nginx, AWS ALB, Cloudflare, etc.) that strips and rewrites
|
|
290
|
+
* those headers. If your Node.js process is directly internet-accessible,
|
|
291
|
+
* an attacker can spoof any IP value and bypass payment-processor
|
|
292
|
+
* IP-based fraud checks.
|
|
293
|
+
* - **Express `req.ip`** resolves through `X-Forwarded-For` only when
|
|
294
|
+
* `app.set('trust proxy', true)` (or a specific proxy count/subnet) is
|
|
295
|
+
* configured. Without `trust proxy`, `req.ip` returns the direct socket
|
|
296
|
+
* address (your load-balancer's IP, not the client's).
|
|
297
|
+
* - **`cf-connecting-ip`** is only trustworthy when Cloudflare is genuinely
|
|
298
|
+
* in front of your server. Without Cloudflare, any client can send this
|
|
299
|
+
* header with a fabricated value.
|
|
300
|
+
*
|
|
301
|
+
* In all cases, ensure your infrastructure strips untrusted forwarding headers
|
|
302
|
+
* before they reach your application.
|
|
303
|
+
*
|
|
232
304
|
* @example
|
|
233
|
-
* // Express
|
|
305
|
+
* // Express — requires app.set('trust proxy', true) behind a proxy
|
|
234
306
|
* clientIpAddress: getClientIp(req)
|
|
235
307
|
*
|
|
236
308
|
* // Next.js App Router
|
|
237
309
|
* clientIpAddress: getClientIp(req)
|
|
238
310
|
*/
|
|
239
311
|
export declare function getClientIp(req: Record<string, unknown>): string;
|
|
312
|
+
/**
|
|
313
|
+
* Options for {@link createCardSaleHandler} and {@link createCardSaleMiddleware}.
|
|
314
|
+
*
|
|
315
|
+
* The only required option is `getAmount` — it must return the authoritative
|
|
316
|
+
* transaction amount from **your own** database or session. Never read the
|
|
317
|
+
* amount from the request body without validating it against your records;
|
|
318
|
+
* a malicious client could otherwise send an arbitrarily low amount.
|
|
319
|
+
*/
|
|
320
|
+
export interface CardSaleHandlerOptions {
|
|
321
|
+
/**
|
|
322
|
+
* Return the authoritative amount for this transaction as a decimal string
|
|
323
|
+
* (e.g. `"49.00"`). Source this from your own database or session — never
|
|
324
|
+
* trust the value the client sends in the request body.
|
|
325
|
+
*
|
|
326
|
+
* Receives the parsed request body so you can forward an `orderId` or
|
|
327
|
+
* similar identifier to look up the correct amount.
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* getAmount: async (body) => {
|
|
331
|
+
* const order = await db.orders.findById(body.orderId as string);
|
|
332
|
+
* return order.total;
|
|
333
|
+
* }
|
|
334
|
+
*/
|
|
335
|
+
getAmount: (body: Record<string, unknown>) => string | Promise<string>;
|
|
336
|
+
/**
|
|
337
|
+
* Return the ISO 4217 currency code for this transaction. Default: `"USD"`.
|
|
338
|
+
*/
|
|
339
|
+
getCurrency?: (body: Record<string, unknown>) => string | Promise<string>;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Creates a ready-to-use Fetch API route handler for charging a tokenized card.
|
|
343
|
+
*
|
|
344
|
+
* Drop-in for Next.js App Router, Cloudflare Workers, Vercel Edge, and any
|
|
345
|
+
* runtime built on the standard Web API `Request` / `Response`.
|
|
346
|
+
*
|
|
347
|
+
* The handler reads `{ token, cvcSession, billing }` from the JSON request body,
|
|
348
|
+
* resolves the amount via `options.getAmount()`, calls `ozura.cardSale()`, and
|
|
349
|
+
* returns `{ transactionId, amount, cardLastFour, cardBrand }` on success.
|
|
350
|
+
* On error it returns `{ error }` with a normalized, user-facing message and
|
|
351
|
+
* an appropriate HTTP status.
|
|
352
|
+
*
|
|
353
|
+
* `clientIpAddress` is extracted automatically from the request headers.
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* // app/api/charge/route.ts (Next.js App Router)
|
|
357
|
+
* import { Ozura, createCardSaleHandler } from '@ozura/elements/server';
|
|
358
|
+
*
|
|
359
|
+
* const ozura = new Ozura({ merchantId: '...', apiKey: '...', vaultKey: '...' });
|
|
360
|
+
*
|
|
361
|
+
* export const POST = createCardSaleHandler(ozura, {
|
|
362
|
+
* getAmount: async (body) => {
|
|
363
|
+
* const order = await db.orders.findById(body.orderId as string);
|
|
364
|
+
* return order.total;
|
|
365
|
+
* },
|
|
366
|
+
* });
|
|
367
|
+
*/
|
|
368
|
+
export declare function createCardSaleHandler(ozura: Ozura, options: CardSaleHandlerOptions): (req: Request) => Promise<Response>;
|
|
369
|
+
/**
|
|
370
|
+
* Creates a ready-to-use Express / Connect middleware for charging a tokenized card.
|
|
371
|
+
*
|
|
372
|
+
* Requires `express.json()` (or equivalent body-parser) to be registered before
|
|
373
|
+
* this middleware so `req.body` is available.
|
|
374
|
+
*
|
|
375
|
+
* The middleware reads `{ token, cvcSession, billing }` from `req.body`, resolves
|
|
376
|
+
* the amount via `options.getAmount()`, calls `ozura.cardSale()`, and sends
|
|
377
|
+
* `{ transactionId, amount, cardLastFour, cardBrand }` on success.
|
|
378
|
+
* On error it sends `{ error }` with a normalized, user-facing message and an
|
|
379
|
+
* appropriate HTTP status.
|
|
380
|
+
*
|
|
381
|
+
* `clientIpAddress` is extracted automatically from the request object.
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
* // Express
|
|
385
|
+
* import express from 'express';
|
|
386
|
+
* import { Ozura, createCardSaleMiddleware } from '@ozura/elements/server';
|
|
387
|
+
*
|
|
388
|
+
* const app = express();
|
|
389
|
+
* const ozura = new Ozura({ merchantId: '...', apiKey: '...', vaultKey: '...' });
|
|
390
|
+
*
|
|
391
|
+
* app.use(express.json());
|
|
392
|
+
* app.post('/api/charge', createCardSaleMiddleware(ozura, {
|
|
393
|
+
* getAmount: async (body) => {
|
|
394
|
+
* const order = await db.orders.findById(body.orderId as string);
|
|
395
|
+
* return order.total;
|
|
396
|
+
* },
|
|
397
|
+
* }));
|
|
398
|
+
*/
|
|
399
|
+
export declare function createCardSaleMiddleware(ozura: Ozura, options: CardSaleHandlerOptions): (req: {
|
|
400
|
+
body?: unknown;
|
|
401
|
+
headers?: unknown;
|
|
402
|
+
}, res: NodeLikeResponse) => Promise<void>;
|
|
240
403
|
export type { BillingDetails, CardSaleResponseData, TransactionQueryPagination, TransactionType, TransactionBase, CardTransactionData, AchTransactionData, CryptoTransactionData, TransactionData, } from '../types';
|
|
404
|
+
export { normalizeCardSaleError } from '../sdk/errors';
|
|
@@ -5,6 +5,9 @@ export interface ElementStyle {
|
|
|
5
5
|
fontWeight?: string;
|
|
6
6
|
fontStyle?: string;
|
|
7
7
|
fontVariant?: string;
|
|
8
|
+
fontSmoothing?: string;
|
|
9
|
+
webkitFontSmoothing?: string;
|
|
10
|
+
mozOsxFontSmoothing?: string;
|
|
8
11
|
letterSpacing?: string;
|
|
9
12
|
lineHeight?: string;
|
|
10
13
|
textAlign?: string;
|
|
@@ -55,8 +58,6 @@ export interface ElementStyle {
|
|
|
55
58
|
minHeight?: string;
|
|
56
59
|
maxHeight?: string;
|
|
57
60
|
transition?: string;
|
|
58
|
-
/** Index signature for forward-compatibility with future CSS properties. */
|
|
59
|
-
[key: string]: string | undefined;
|
|
60
61
|
}
|
|
61
62
|
export interface ElementStyleConfig {
|
|
62
63
|
/** Default styles applied to the input. */
|
|
@@ -74,7 +75,8 @@ export interface ElementOptions {
|
|
|
74
75
|
style?: ElementStyleConfig;
|
|
75
76
|
placeholder?: string;
|
|
76
77
|
disabled?: boolean;
|
|
77
|
-
/** How long to wait (ms) for the iframe to load before emitting `loaderror`. Default: 10 000.
|
|
78
|
+
/** How long to wait (ms) for the iframe to load before emitting `loaderror`. Default: 10 000.
|
|
79
|
+
* Only takes effect when this element's `onLoadError` option is provided or when `VaultOptions.onLoadError` is set. */
|
|
78
80
|
loadTimeoutMs?: number;
|
|
79
81
|
}
|
|
80
82
|
export interface ElementChangeEvent {
|
|
@@ -118,7 +120,7 @@ export interface AppearanceVariables {
|
|
|
118
120
|
colorText?: string;
|
|
119
121
|
/** Input background color. Maps to `base.backgroundColor`. */
|
|
120
122
|
colorBackground?: string;
|
|
121
|
-
/** Primary accent color. Maps to `focus.caretColor` and `
|
|
123
|
+
/** Primary accent color. Maps to `focus.caretColor` and `base.caretColor`. */
|
|
122
124
|
colorPrimary?: string;
|
|
123
125
|
/** Error/invalid state text color. Maps to `invalid.color`. */
|
|
124
126
|
colorDanger?: string;
|
|
@@ -162,7 +164,7 @@ export interface VaultOptions {
|
|
|
162
164
|
* It replaces the vault secret on every browser tokenize call — the secret
|
|
163
165
|
* never leaves your server.
|
|
164
166
|
*
|
|
165
|
-
* **Server-side (recommended):** Use `ozura.mintWaxKey()` from
|
|
167
|
+
* **Server-side (recommended):** Use `ozura.mintWaxKey()` from `@ozura/elements/server`:
|
|
166
168
|
* @example
|
|
167
169
|
* // Your API route (e.g. Next.js App Router):
|
|
168
170
|
* // POST /api/mint-wax
|
|
@@ -205,8 +207,40 @@ export interface VaultOptions {
|
|
|
205
207
|
* Use this to show a fallback UI (e.g. "Unable to load payment fields").
|
|
206
208
|
*/
|
|
207
209
|
onLoadError?: () => void;
|
|
208
|
-
/** How long to wait (ms) for the tokenizer iframe before calling `onLoadError`. Default: 10 000.
|
|
210
|
+
/** How long to wait (ms) for the tokenizer iframe before calling `onLoadError`. Default: 10 000.
|
|
211
|
+
* Only takes effect when `onLoadError` is also provided — setting this without `onLoadError` has no effect. */
|
|
209
212
|
loadTimeoutMs?: number;
|
|
213
|
+
/**
|
|
214
|
+
* Called when the SDK silently re-mints the wax key during a tokenization
|
|
215
|
+
* attempt (expiry or consumption). The `createToken()` / `createBankToken()`
|
|
216
|
+
* promise stays pending until the refresh completes and the retry resolves.
|
|
217
|
+
* Use this to show a loading indicator while the re-mint round trip is in flight.
|
|
218
|
+
*/
|
|
219
|
+
onWaxRefresh?: () => void;
|
|
220
|
+
/**
|
|
221
|
+
* Maximum number of tokenize calls each minted wax key accepts before the
|
|
222
|
+
* vault marks it as consumed. Should match the `maxTokenizeCalls` passed to
|
|
223
|
+
* `ozura.mintWaxKey()` on your server (both default to `3`).
|
|
224
|
+
*
|
|
225
|
+
* The SDK uses this value to proactively refresh the wax key after it has been
|
|
226
|
+
* fully consumed — before the next `createToken()` call is made — so users
|
|
227
|
+
* never experience a delay from a reactive re-mint. If the values are out of
|
|
228
|
+
* sync the reactive refresh path still catches consumption errors; this is
|
|
229
|
+
* purely an optimisation.
|
|
230
|
+
*
|
|
231
|
+
* @default 3
|
|
232
|
+
*/
|
|
233
|
+
maxTokenizeCalls?: number;
|
|
234
|
+
/**
|
|
235
|
+
* Called once when the tokenizer iframe has loaded and is ready to accept
|
|
236
|
+
* tokenization requests. Useful in vanilla JS to re-evaluate submit-button
|
|
237
|
+
* readiness when the tokenizer becomes ready after all element iframes have
|
|
238
|
+
* already loaded.
|
|
239
|
+
*
|
|
240
|
+
* In React, use `useOzElements().ready` instead — it combines both tokenizer
|
|
241
|
+
* and element readiness automatically.
|
|
242
|
+
*/
|
|
243
|
+
onReady?: () => void;
|
|
210
244
|
/**
|
|
211
245
|
* Global appearance configuration. Applies preset themes and/or variable
|
|
212
246
|
* overrides to all elements created by this vault. Per-element `style`
|
|
@@ -278,8 +312,8 @@ export interface BankTokenizeOptions {
|
|
|
278
312
|
export interface BankAccountMetadata {
|
|
279
313
|
/** Last 4 digits of the account number. */
|
|
280
314
|
last4: string;
|
|
281
|
-
/**
|
|
282
|
-
|
|
315
|
+
/** Last 4 digits of the routing number — sufficient for display and reconciliation. */
|
|
316
|
+
routingNumberLast4: string;
|
|
283
317
|
}
|
|
284
318
|
/** Non-sensitive card metadata returned alongside the token. */
|
|
285
319
|
export interface CardMetadata {
|
|
@@ -294,9 +328,20 @@ export interface CardMetadata {
|
|
|
294
328
|
}
|
|
295
329
|
export interface TokenResponse {
|
|
296
330
|
token: string;
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
331
|
+
/**
|
|
332
|
+
* CVC session token returned by the vault alongside the card token.
|
|
333
|
+
*
|
|
334
|
+
* Required by the Ozura Pay API `cardSale` endpoint. The SDK validates this
|
|
335
|
+
* field before resolving `createToken()` — if it is absent the promise rejects
|
|
336
|
+
* with `OZ_TOKEN_ERROR`. In practice this field is always present on a
|
|
337
|
+
* successful tokenization.
|
|
338
|
+
*/
|
|
339
|
+
cvcSession: string;
|
|
340
|
+
/**
|
|
341
|
+
* Non-sensitive card metadata — always present on successful tokenization.
|
|
342
|
+
* Available immediately; no `cardSale` call required.
|
|
343
|
+
*/
|
|
344
|
+
card: CardMetadata;
|
|
300
345
|
/**
|
|
301
346
|
* Validated, normalized billing details — ready to spread into a cardSale request.
|
|
302
347
|
* Only present when billing was passed to createToken().
|
|
@@ -368,12 +413,12 @@ export interface CardSaleResponseData {
|
|
|
368
413
|
amount: string;
|
|
369
414
|
/** ISO 4217 currency code, e.g. "USD". */
|
|
370
415
|
currency: string;
|
|
371
|
-
/** Surcharge amount applied, e.g. "
|
|
372
|
-
surchargeAmount
|
|
416
|
+
/** Surcharge amount applied, e.g. "1.50". Absent when no surcharge was configured. */
|
|
417
|
+
surchargeAmount?: string;
|
|
373
418
|
/** Sales tax calculated by the Pay API based on billing address. */
|
|
374
419
|
salesTaxAmount?: string;
|
|
375
|
-
/** Tip amount applied, e.g. "
|
|
376
|
-
tipAmount
|
|
420
|
+
/** Tip amount applied, e.g. "5.00". Absent when no tip was included in the request. */
|
|
421
|
+
tipAmount?: string;
|
|
377
422
|
/** Last four digits of the card number. */
|
|
378
423
|
cardLastFour: string;
|
|
379
424
|
/** First six digits of the card number (BIN). */
|
|
@@ -408,12 +453,17 @@ export interface CardSaleResponseData {
|
|
|
408
453
|
* Full response envelope from the Ozura Pay API cardSale endpoint.
|
|
409
454
|
*
|
|
410
455
|
* On success: `{ success: true, data: CardSaleResponseData }`
|
|
411
|
-
* On failure: HTTP 4xx/5xx with `{ error: string }` — pass
|
|
412
|
-
* `normalizeCardSaleError()` to get a user-facing message.
|
|
456
|
+
* On failure: HTTP 4xx/5xx with `{ success: false, error: string }` — pass
|
|
457
|
+
* `error` to `normalizeCardSaleError()` to get a user-facing message.
|
|
458
|
+
*
|
|
459
|
+
* Note: the server SDK `Ozura.cardSale()` throws `OzuraError` on failure rather
|
|
460
|
+
* than returning this shape. This type is only needed when calling the Pay API
|
|
461
|
+
* directly via `fetch`.
|
|
413
462
|
*/
|
|
414
463
|
export interface CardSaleApiResponse {
|
|
415
464
|
success: boolean;
|
|
416
|
-
data
|
|
465
|
+
data?: CardSaleResponseData;
|
|
466
|
+
error?: string;
|
|
417
467
|
}
|
|
418
468
|
/**
|
|
419
469
|
* Transaction types returned by the Pay API transQuery endpoint.
|
|
@@ -539,7 +589,7 @@ export interface TransactionQueryResponse {
|
|
|
539
589
|
data: TransactionData[];
|
|
540
590
|
pagination: TransactionQueryPagination;
|
|
541
591
|
}
|
|
542
|
-
export type OzMessageType = 'OZ_FRAME_READY' | 'OZ_INIT' | 'OZ_UPDATE' | 'OZ_CLEAR' | 'OZ_CHANGE' | 'OZ_FOCUS' | 'OZ_BLUR' | 'OZ_RESIZE' | '
|
|
592
|
+
export type OzMessageType = 'OZ_FRAME_READY' | 'OZ_INIT' | 'OZ_UPDATE' | 'OZ_CLEAR' | 'OZ_CHANGE' | 'OZ_FOCUS' | 'OZ_BLUR' | 'OZ_RESIZE' | 'OZ_BEGIN_COLLECT' | 'OZ_FIELD_VALUE' | 'OZ_TOKENIZE' | 'OZ_TOKEN_RESULT' | 'OZ_TOKEN_ERROR' | 'OZ_FOCUS_REQUEST' | 'OZ_BLUR_REQUEST' | 'OZ_SET_CVV_LENGTH' | 'OZ_BANK_TOKENIZE' | 'OZ_BANK_TOKEN_RESULT' | 'OZ_TOKENIZE_CANCEL';
|
|
543
593
|
export interface OzMessage {
|
|
544
594
|
__oz: true;
|
|
545
595
|
vaultId: string;
|
|
@@ -4,6 +4,15 @@ import type { Appearance, ElementStyleConfig } from '../types';
|
|
|
4
4
|
* Resolution order: theme defaults → variable overrides.
|
|
5
5
|
* The returned config is then used as the "base appearance" that
|
|
6
6
|
* per-element `style` overrides merge on top of.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* - `appearance: undefined` → no styles injected (element iframes use their
|
|
10
|
+
* own minimal built-in defaults).
|
|
11
|
+
* - `appearance: {}` or `appearance: { variables: {...} }` without an explicit
|
|
12
|
+
* `theme` → the `'default'` theme is used as the base. Omitting `theme`
|
|
13
|
+
* does NOT mean "no theme" — it means `theme: 'default'`. To opt out of
|
|
14
|
+
* the preset themes entirely, use per-element `style` overrides without
|
|
15
|
+
* passing an `appearance` prop at all.
|
|
7
16
|
*/
|
|
8
17
|
export declare function resolveAppearance(appearance?: Appearance): ElementStyleConfig | undefined;
|
|
9
18
|
/**
|
|
@@ -21,6 +21,20 @@ export interface CardValidationResult {
|
|
|
21
21
|
valid: boolean;
|
|
22
22
|
error?: string;
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Canonical card number validation: length check then Luhn.
|
|
26
|
+
*
|
|
27
|
+
* **Not called by `elementFrame.ts` at runtime.** The frame needs `complete`
|
|
28
|
+
* and `valid` as separate signals for field UX (show completion indicator
|
|
29
|
+
* before running Luhn), so it implements both checks inline via `isComplete()`
|
|
30
|
+
* and `isValid()`. Those methods MUST stay logically in sync with this
|
|
31
|
+
* function — any change to length bounds or error text here must be mirrored
|
|
32
|
+
* there, and vice-versa.
|
|
33
|
+
*
|
|
34
|
+
* Used by the unit test suite as the authoritative spec for the algorithm.
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
24
38
|
export declare function validateCardNumber(digits: string, brand: CardBrand | string): CardValidationResult;
|
|
25
39
|
export interface ExpiryValidationResult {
|
|
26
40
|
complete: boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a RFC 4122 v4 UUID.
|
|
3
|
+
*
|
|
4
|
+
* Uses `crypto.randomUUID()` when available (Chrome 92+, Firefox 95+,
|
|
5
|
+
* Safari 15.4+, Node 14.17+) and falls back to `crypto.getRandomValues()`
|
|
6
|
+
* for older environments (Safari 14, some embedded WebViews, older Node).
|
|
7
|
+
*
|
|
8
|
+
* Both paths use the same CSPRNG — the difference is only in API surface.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare function uuid(): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ozura/elements",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "PCI-compliant card tokenization SDK for the Ozura Vault — collect card data in iframe-isolated fields and tokenize without PCI scope",
|
|
5
5
|
"main": "dist/oz-elements.umd.js",
|
|
6
6
|
"module": "dist/oz-elements.esm.js",
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
"require": "./dist/oz-elements.umd.js"
|
|
13
13
|
},
|
|
14
14
|
"./react": {
|
|
15
|
-
"types": "./dist/react/index.d.ts",
|
|
15
|
+
"types": "./dist/react/react/index.d.ts",
|
|
16
16
|
"import": "./dist/react/index.esm.js",
|
|
17
17
|
"require": "./dist/react/index.cjs.js"
|
|
18
18
|
},
|
|
19
19
|
"./server": {
|
|
20
|
-
"types": "./dist/server/index.d.ts",
|
|
20
|
+
"types": "./dist/server/server/index.d.ts",
|
|
21
21
|
"import": "./dist/server/index.esm.js",
|
|
22
22
|
"require": "./dist/server/index.cjs.js"
|
|
23
23
|
}
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
"test:coverage": "vitest run --coverage",
|
|
42
42
|
"test:e2e": "playwright test --project=mock",
|
|
43
43
|
"test:e2e:live": "playwright test --project=live",
|
|
44
|
-
"
|
|
44
|
+
"check:csp": "node scripts/check-csp.mjs",
|
|
45
|
+
"prepublishOnly": "cross-env NODE_ENV=production npm run build"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
48
|
"react": ">=17",
|
|
@@ -80,6 +81,8 @@
|
|
|
80
81
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
81
82
|
"@rollup/plugin-replace": "^6.0.3",
|
|
82
83
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
84
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
85
|
+
"@testing-library/react": "^16.3.2",
|
|
83
86
|
"@types/node": "^22.14.0",
|
|
84
87
|
"@types/react": "^19.2.14",
|
|
85
88
|
"@types/react-dom": "^19.2.3",
|