@ozura/elements 1.2.1 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +105 -0
  2. package/dist/frame/element-frame.js +49 -4
  3. package/dist/frame/element-frame.js.map +1 -1
  4. package/dist/frame/tokenizer-frame.js +145 -61
  5. package/dist/frame/tokenizer-frame.js.map +1 -1
  6. package/dist/oz-elements.esm.js +221 -97
  7. package/dist/oz-elements.esm.js.map +1 -1
  8. package/dist/oz-elements.umd.js +221 -97
  9. package/dist/oz-elements.umd.js.map +1 -1
  10. package/dist/react/frame/elementFrame.d.ts +9 -0
  11. package/dist/react/frame/tokenizerFrame.d.ts +17 -1
  12. package/dist/react/index.cjs.js +221 -97
  13. package/dist/react/index.cjs.js.map +1 -1
  14. package/dist/react/index.esm.js +221 -97
  15. package/dist/react/index.esm.js.map +1 -1
  16. package/dist/react/sdk/OzElement.d.ts +4 -1
  17. package/dist/react/sdk/OzVault.d.ts +3 -9
  18. package/dist/react/sdk/createSessionFetcher.d.ts +2 -2
  19. package/dist/react/server/index.d.ts +26 -0
  20. package/dist/react/types/index.d.ts +30 -11
  21. package/dist/react/utils/billingUtils.d.ts +2 -1
  22. package/dist/react/vue/index.d.ts +88 -0
  23. package/dist/server/frame/elementFrame.d.ts +9 -0
  24. package/dist/server/frame/tokenizerFrame.d.ts +17 -1
  25. package/dist/server/index.cjs.js +65 -24
  26. package/dist/server/index.cjs.js.map +1 -1
  27. package/dist/server/index.esm.js +65 -24
  28. package/dist/server/index.esm.js.map +1 -1
  29. package/dist/server/sdk/OzElement.d.ts +4 -1
  30. package/dist/server/sdk/OzVault.d.ts +3 -9
  31. package/dist/server/sdk/createSessionFetcher.d.ts +2 -2
  32. package/dist/server/server/index.d.ts +26 -0
  33. package/dist/server/types/index.d.ts +30 -11
  34. package/dist/server/utils/billingUtils.d.ts +2 -1
  35. package/dist/server/vue/index.d.ts +88 -0
  36. package/dist/types/frame/elementFrame.d.ts +9 -0
  37. package/dist/types/frame/tokenizerFrame.d.ts +17 -1
  38. package/dist/types/sdk/OzElement.d.ts +4 -1
  39. package/dist/types/sdk/OzVault.d.ts +3 -9
  40. package/dist/types/sdk/createSessionFetcher.d.ts +2 -2
  41. package/dist/types/server/index.d.ts +26 -0
  42. package/dist/types/types/index.d.ts +30 -11
  43. package/dist/types/utils/billingUtils.d.ts +2 -1
  44. package/dist/types/vue/index.d.ts +88 -0
  45. package/dist/vue/frame/protocol.d.ts +12 -0
  46. package/dist/vue/index.cjs.js +2335 -0
  47. package/dist/vue/index.cjs.js.map +1 -0
  48. package/dist/vue/index.esm.js +2327 -0
  49. package/dist/vue/index.esm.js.map +1 -0
  50. package/dist/vue/sdk/OzElement.d.ts +99 -0
  51. package/dist/vue/sdk/OzVault.d.ts +250 -0
  52. package/dist/vue/sdk/createSessionFetcher.d.ts +29 -0
  53. package/dist/vue/sdk/errors.d.ts +65 -0
  54. package/dist/vue/sdk/index.d.ts +14 -0
  55. package/dist/vue/types/index.d.ts +667 -0
  56. package/dist/vue/utils/appearance.d.ts +22 -0
  57. package/dist/vue/utils/billingUtils.d.ts +61 -0
  58. package/dist/vue/utils/uuid.d.ts +12 -0
  59. package/dist/vue/vue/index.d.ts +88 -0
  60. package/package.json +15 -3
@@ -22,6 +22,8 @@ export declare class ElementFrame {
22
22
  private vaultId;
23
23
  private frameId;
24
24
  private hostOrigin;
25
+ /** Mirrors the parent vault's debug flag — set via OZ_INIT. */
26
+ private debug;
25
27
  private rawValue;
26
28
  private cardBrand;
27
29
  private cvvMaxLength;
@@ -64,6 +66,13 @@ export declare class ElementFrame {
64
66
  private reapplyStateStyles;
65
67
  private applyPlaceholderStyles;
66
68
  private fontsInjected;
69
+ /**
70
+ * Allowed hostnames for cssSrc font stylesheets. Restricting to known font
71
+ * CDNs prevents a merchant from loading arbitrary third-party stylesheets
72
+ * inside the PCI-isolated iframe, which could otherwise be used to load
73
+ * tracking scripts via @import or attempt CSS-based data extraction.
74
+ */
75
+ private static readonly ALLOWED_FONT_HOSTS;
67
76
  private injectFonts;
68
77
  /**
69
78
  * Delivers this field's raw value to the tokenizer iframe via the MessagePort
@@ -23,11 +23,27 @@ export declare function isAllowedVaultOrigin(apiUrl: string): boolean;
23
23
  export declare class TokenizerFrame {
24
24
  private vaultId;
25
25
  private hostOrigin;
26
- /** Wax key delivered once via OZ_INIT. Used for all tokenize calls. */
26
+ /**
27
+ * Session key — delivered via OZ_INIT on first ready and again after each
28
+ * auto-refresh. The latest value is always used for tokenize calls.
29
+ */
27
30
  private waxKey;
28
31
  private pending;
29
32
  private pendingBank;
33
+ /** Mirrors the parent vault's debug flag — set via OZ_INIT. When true, the frame relays debug-level info in addition to errors/warnings. */
34
+ private debug;
30
35
  constructor();
36
+ /**
37
+ * Relays a message to the parent window as OZ_DEBUG_LOG so it surfaces in
38
+ * the merchant page's DevTools console rather than the hidden tokenizer-frame
39
+ * context.
40
+ *
41
+ * Level semantics:
42
+ * 'error' — always relayed (genuine failure)
43
+ * 'warn' — always relayed (developer misconfiguration)
44
+ * 'log' — only relayed when debug mode is enabled (lifecycle / timing info)
45
+ */
46
+ private postDebugLog;
31
47
  private onMessage;
32
48
  /**
33
49
  * Shared vault POST helper. Handles origin guard, header construction,
@@ -22,7 +22,10 @@ export declare class OzElement {
22
22
  private _loadTimer;
23
23
  private pendingMessages;
24
24
  private handlers;
25
- constructor(elementType: AnyElementType, options: ElementOptions, vaultId: string, frameBaseUrl: string, fonts?: FontSource[], appearanceStyle?: ElementStyleConfig);
25
+ /** Called by OzVault when this element is destroyed so it can remove stale map entries. @internal */
26
+ private _onDestroy;
27
+ private debug;
28
+ constructor(elementType: AnyElementType, options: ElementOptions, vaultId: string, frameBaseUrl: string, fonts?: FontSource[], appearanceStyle?: ElementStyleConfig, onDestroy?: () => void, debug?: boolean);
26
29
  /** The element type this proxy represents. */
27
30
  get type(): AnyElementType;
28
31
  /** True once the element iframe has loaded and signalled ready. */
@@ -7,16 +7,10 @@ import { ElementType, BankElementType, ElementOptions, VaultOptions, TokenizeOpt
7
7
  * Use the static `OzVault.create()` factory — do not call `new OzVault()` directly.
8
8
  *
9
9
  * @example
10
+ * // Recommended — pass sessionUrl and let the SDK call your backend automatically
10
11
  * const vault = await OzVault.create({
11
- * pubKey: 'pk_live_...',
12
- * fetchWaxKey: async (sessionId) => {
13
- * // Call your backend — which calls ozura.mintWaxKey() from @ozura/elements/server
14
- * const { waxKey } = await fetch('/api/mint-wax', {
15
- * method: 'POST',
16
- * body: JSON.stringify({ sessionId }),
17
- * }).then(r => r.json());
18
- * return waxKey;
19
- * },
12
+ * pubKey: 'pk_prod_...', // or 'pk_test_...' for test mode
13
+ * sessionUrl: '/api/oz-session', // backend endpoint that calls ozura.createSession()
20
14
  * });
21
15
  * const cardNum = vault.createElement('cardNumber');
22
16
  * cardNum.mount('#card-number');
@@ -17,12 +17,12 @@
17
17
  *
18
18
  * @example
19
19
  * // Simplest — just pass sessionUrl, no need to call this directly
20
- * const vault = await OzVault.create({ pubKey: 'pk_live_...', sessionUrl: '/api/oz-session' });
20
+ * const vault = await OzVault.create({ pubKey: 'pk_prod_...', sessionUrl: '/api/oz-session' });
21
21
  *
22
22
  * @example
23
23
  * // Manual — use when you need custom headers
24
24
  * const vault = await OzVault.create({
25
- * pubKey: 'pk_live_...',
25
+ * pubKey: 'pk_prod_...',
26
26
  * getSessionKey: createSessionFetcher('/api/oz-session'),
27
27
  * });
28
28
  */
@@ -51,6 +51,13 @@ export interface OzuraConfig {
51
51
  timeoutMs?: number;
52
52
  /** Max retry attempts for 5xx / network errors. Default: 2 (up to 3 total attempts). Set 0 to disable. */
53
53
  retries?: number;
54
+ /**
55
+ * Enables structured debug logging to the server console.
56
+ * Logs method, path, HTTP status, and duration for every Pay API and vault request.
57
+ * Request bodies are included with sensitive fields (tokens, session keys) redacted.
58
+ * Never enable in production — for local development and CI debugging only.
59
+ */
60
+ debug?: boolean;
54
61
  }
55
62
  export declare class OzuraError extends Error {
56
63
  readonly statusCode: number;
@@ -155,6 +162,17 @@ export interface CardSaleInput {
155
162
  surchargePercent?: string;
156
163
  /** Defaults to "0.00". */
157
164
  tipAmount?: string;
165
+ /**
166
+ * Who initiated the transaction. Default: `'cit'` (customer-initiated) — correct
167
+ * for standard web checkouts. Override for MIT recurring charges (`'mit'`) or
168
+ * unscheduled credential-on-file charges (`'ucof'`).
169
+ */
170
+ transactionInitiationType?: 'cit' | 'mit' | 'ucof' | 'refund';
171
+ /**
172
+ * Channel through which the transaction is processed. Default: `'ecommerce'`.
173
+ * Override for MOTO (`'moto'`) or recurring scheduled charges (`'recurring'`).
174
+ */
175
+ transactionChannel?: 'cardPresent' | 'ecommerce' | 'moto' | 'recurring';
158
176
  }
159
177
  export interface ListTransactionsInput {
160
178
  /** Look up a single transaction by ID. When set, dateFrom/dateTo are not required. */
@@ -180,7 +198,15 @@ export declare class Ozura {
180
198
  private vaultUrl;
181
199
  private timeoutMs;
182
200
  private retries;
201
+ private debug;
183
202
  constructor(config: OzuraConfig);
203
+ /** Emits a `[Ozura]`-prefixed entry to `console.log`. No-op when `debug` is not set. */
204
+ private log;
205
+ /**
206
+ * Returns a copy of `body` with known-sensitive fields replaced by `'[REDACTED]'`.
207
+ * Used to make debug logs safe to emit without leaking vault tokens or session keys.
208
+ */
209
+ private static redactBody;
184
210
  /**
185
211
  * Charge a tokenized card. Maps the friendly `CardSaleInput` shape to the
186
212
  * Pay API's flat field format and handles headers, defaults, and errors.
@@ -418,27 +418,46 @@ export interface CardSaleRequest {
418
418
  amount: string;
419
419
  /** ISO 4217, e.g. "USD". */
420
420
  currency: string;
421
- /** From TokenResponse.token */
422
- ozuraCardToken: string;
421
+ /**
422
+ * Who initiated the transaction. Required by the Pay API.
423
+ * - `'cit'` — Customer-Initiated Transaction (default for web checkouts).
424
+ * - `'mit'` — Merchant-Initiated (scheduled recurring charge, customer not present).
425
+ * - `'ucof'` — Unscheduled Credential-on-File (threshold billing, account-updater, etc.).
426
+ * - `'refund'` — Voids, returns, reversals (not a stored-credential use).
427
+ */
428
+ transactionInitiationType: 'cit' | 'mit' | 'ucof' | 'refund';
429
+ /**
430
+ * Channel through which the transaction is processed. Required by the Pay API.
431
+ * - `'ecommerce'` — Online, customer self-serve (default for web checkouts).
432
+ * - `'moto'` — Mail order / telephone order.
433
+ * - `'cardPresent'`— POS / in-person.
434
+ * - `'recurring'` — Scheduled MIT charge; never the initial CIT charge.
435
+ */
436
+ transactionChannel: 'cardPresent' | 'ecommerce' | 'moto' | 'recurring';
437
+ /** From TokenResponse.token. The vault token representing the stored card. */
438
+ ozuraVaultToken: string;
423
439
  /** From TokenResponse.cvcSession */
424
440
  ozuraCvcSession: string;
425
441
  billingFirstName: string;
426
442
  billingLastName: string;
427
- /** Optional but must be non-empty if provided — Pay API enforces minLength 1. Omit the key rather than send "". */
443
+ /**
444
+ * Required by the Pay API (minLength 1). Optional here so merchants can omit it
445
+ * in rare server-side-only flows, but the Pay API will reject the request if absent.
446
+ */
428
447
  billingEmail?: string;
429
- /** E.164 format, max 50 chars. Optional but must be non-empty if provided. */
448
+ /** E.164 format, max 50 chars. Required by the Pay API; optional here for flexibility. */
430
449
  billingPhone?: string;
431
- /** Optional but must be non-empty if provided. */
450
+ /** Required by the Pay API; optional here for flexibility. Must be non-empty if provided. */
432
451
  billingAddress1?: string;
433
- /** Omit entirely if blank — schema enforces minLength 1 if present. */
452
+ /** Omit entirely if blank — Pay API schema enforces minLength 1 if present. */
434
453
  billingAddress2?: string;
435
- /** Optional but must be non-empty if provided. */
454
+ /** Required by the Pay API; optional here for flexibility. Must be non-empty if provided. */
436
455
  billingCity?: string;
437
- /** 2-letter state/province code. Optional but must be non-empty if provided. */
456
+ /** 2-letter state/province code. Required by the Pay API; optional here for flexibility. */
438
457
  billingState?: string;
439
- /** Optional but must be non-empty if provided. */
458
+ /** Required by the Pay API; optional here for flexibility. Must be non-empty if provided. */
440
459
  billingZipcode?: string;
441
- /** ISO 3166-1 alpha-2. Defaults to 'US'. */
460
+ /** ISO 3166-1 alpha-2. Required by the Pay API. Defaults to 'US' in `Ozura.cardSale()`. */
442
461
  billingCountry?: string;
443
462
  /** Fetch from your server — use an internal route, not api.ipify.org (ad-blockers block it). */
444
463
  clientIpAddress: string;
@@ -637,7 +656,7 @@ export interface TransactionQueryResponse {
637
656
  data: TransactionData[];
638
657
  pagination: TransactionQueryPagination;
639
658
  }
640
- 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';
659
+ 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' | 'OZ_DEBUG_LOG';
641
660
  export interface OzMessage {
642
661
  __oz: true;
643
662
  /** Protocol version stamped by the frame on OZ_FRAME_READY. Read by the SDK to detect stale CDN frames. */
@@ -14,7 +14,8 @@ import { BillingDetails } from '../types';
14
14
  export declare function validateEmail(email: string): boolean;
15
15
  /**
16
16
  * Validates E.164 phone format: starts with +, 1–3 digit country code,
17
- * followed by 7–12 digits, total ≤50 characters.
17
+ * followed by 7–12 digits, max 15 digits total (E.164 spec cap = 16 chars
18
+ * including the leading +).
18
19
  *
19
20
  * Matches the output of checkout's formatPhoneForAPI() function.
20
21
  * Examples: "+15551234567", "+447911123456", "+61412345678"
@@ -0,0 +1,88 @@
1
+ /**
2
+ * @ozura/elements/vue — Vue 3 wrapper for OzElements.
3
+ *
4
+ * Provides a context-based provider that creates and manages an OzVault instance,
5
+ * five individual field components, and a composable to access createToken +
6
+ * readiness state from anywhere inside the provider tree.
7
+ *
8
+ * Quick start:
9
+ * @example
10
+ * ```vue
11
+ * <script setup lang="ts">
12
+ * import { OzElements, OzCardNumber, OzExpiry, OzCvv, useOzElements } from '@ozura/elements/vue';
13
+ * const { createToken, ready } = useOzElements();
14
+ * </script>
15
+ *
16
+ * <template>
17
+ * <OzElements pub-key="pk_live_..." session-url="/api/oz-session">
18
+ * <OzCardNumber />
19
+ * <OzExpiry />
20
+ * <OzCvv />
21
+ * <button :disabled="!ready" @click="createToken()">Pay</button>
22
+ * </OzElements>
23
+ * </template>
24
+ * ```
25
+ */
26
+ import { type Ref, type ComputedRef } from 'vue';
27
+ import type { TokenizeOptions, TokenResponse, BankTokenizeOptions, BankTokenResponse, FontSource, Appearance } from '../types';
28
+ export interface OzElementsProps {
29
+ pubKey: string;
30
+ sessionUrl?: string;
31
+ getSessionKey?: (sessionId: string) => Promise<string>;
32
+ frameBaseUrl?: string;
33
+ fonts?: FontSource[];
34
+ appearance?: Appearance;
35
+ loadTimeoutMs?: number;
36
+ debug?: boolean;
37
+ }
38
+ /**
39
+ * Creates and owns an OzVault instance for the lifetime of this component.
40
+ * All field components must be rendered inside this provider.
41
+ */
42
+ export declare const OzElements: any;
43
+ export interface UseOzElementsReturn {
44
+ /**
45
+ * Tokenizes all mounted card fields. Resolves with a token and cvcSession
46
+ * that can be passed to the Ozura Pay API endpoint.
47
+ */
48
+ createToken: (options?: TokenizeOptions) => Promise<TokenResponse>;
49
+ /**
50
+ * Tokenizes mounted bank account fields (accountNumber + routingNumber).
51
+ */
52
+ createBankToken: (options: BankTokenizeOptions) => Promise<BankTokenResponse>;
53
+ /**
54
+ * True when the vault tokenizer and all mounted field iframes are ready.
55
+ * Gate your submit button on this.
56
+ */
57
+ ready: ComputedRef<boolean>;
58
+ /**
59
+ * Non-null when OzVault.create() rejected during initialization.
60
+ */
61
+ initError: Ref<Error | null>;
62
+ /**
63
+ * Number of successful tokenizations since the last session refresh.
64
+ */
65
+ tokenizeCount: Ref<number>;
66
+ /**
67
+ * Clears all mounted element fields without destroying the vault.
68
+ */
69
+ reset: () => void;
70
+ }
71
+ /**
72
+ * Returns createToken, createBankToken, ready, initError, tokenizeCount, and reset.
73
+ * Must be called from inside an <OzElements> provider tree.
74
+ *
75
+ * @throws {Error} if called outside an <OzElements> provider
76
+ */
77
+ export declare function useOzElements(): UseOzElementsReturn;
78
+ /** Card number field. Emits `change` (ElementChangeEvent), `focus`, `blur`. */
79
+ export declare const OzCardNumber: any;
80
+ /** Expiry date field. Emits `change` (ElementChangeEvent), `focus`, `blur`. */
81
+ export declare const OzExpiry: any;
82
+ /** CVV / CVC field. Emits `change` (ElementChangeEvent), `focus`, `blur`. */
83
+ export declare const OzCvv: any;
84
+ /** Bank account number field. Emits `change` (ElementChangeEvent), `focus`, `blur`. */
85
+ export declare const OzBankAccountNumber: any;
86
+ /** Bank routing number field. Emits `change` (ElementChangeEvent), `focus`, `blur`. */
87
+ export declare const OzBankRoutingNumber: any;
88
+ export type { ElementChangeEvent, TokenizeOptions, TokenResponse, BankTokenizeOptions, BankTokenResponse, Appearance, FontSource, } from '../types';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Shared postMessage protocol constants.
3
+ *
4
+ * PROTOCOL_VERSION must be incremented any time a breaking change is made to
5
+ * the postMessage message shape (new required fields, renamed types, removed
6
+ * fields, changed semantics). The SDK reads this value from OZ_FRAME_READY
7
+ * messages and warns when the frame and SDK are out of sync.
8
+ *
9
+ * Non-breaking additions (new optional fields, new message types that old
10
+ * frames can safely ignore) do NOT require a version bump.
11
+ */
12
+ export declare const PROTOCOL_VERSION = 1;