@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.
- package/README.md +105 -0
- package/dist/frame/element-frame.js +49 -4
- package/dist/frame/element-frame.js.map +1 -1
- package/dist/frame/tokenizer-frame.js +145 -61
- package/dist/frame/tokenizer-frame.js.map +1 -1
- package/dist/oz-elements.esm.js +221 -97
- package/dist/oz-elements.esm.js.map +1 -1
- package/dist/oz-elements.umd.js +221 -97
- package/dist/oz-elements.umd.js.map +1 -1
- package/dist/react/frame/elementFrame.d.ts +9 -0
- package/dist/react/frame/tokenizerFrame.d.ts +17 -1
- package/dist/react/index.cjs.js +221 -97
- package/dist/react/index.cjs.js.map +1 -1
- package/dist/react/index.esm.js +221 -97
- package/dist/react/index.esm.js.map +1 -1
- package/dist/react/sdk/OzElement.d.ts +4 -1
- package/dist/react/sdk/OzVault.d.ts +3 -9
- package/dist/react/sdk/createSessionFetcher.d.ts +2 -2
- package/dist/react/server/index.d.ts +26 -0
- package/dist/react/types/index.d.ts +30 -11
- package/dist/react/utils/billingUtils.d.ts +2 -1
- package/dist/react/vue/index.d.ts +88 -0
- package/dist/server/frame/elementFrame.d.ts +9 -0
- package/dist/server/frame/tokenizerFrame.d.ts +17 -1
- package/dist/server/index.cjs.js +65 -24
- package/dist/server/index.cjs.js.map +1 -1
- package/dist/server/index.esm.js +65 -24
- package/dist/server/index.esm.js.map +1 -1
- package/dist/server/sdk/OzElement.d.ts +4 -1
- package/dist/server/sdk/OzVault.d.ts +3 -9
- package/dist/server/sdk/createSessionFetcher.d.ts +2 -2
- package/dist/server/server/index.d.ts +26 -0
- package/dist/server/types/index.d.ts +30 -11
- package/dist/server/utils/billingUtils.d.ts +2 -1
- package/dist/server/vue/index.d.ts +88 -0
- package/dist/types/frame/elementFrame.d.ts +9 -0
- package/dist/types/frame/tokenizerFrame.d.ts +17 -1
- package/dist/types/sdk/OzElement.d.ts +4 -1
- package/dist/types/sdk/OzVault.d.ts +3 -9
- package/dist/types/sdk/createSessionFetcher.d.ts +2 -2
- package/dist/types/server/index.d.ts +26 -0
- package/dist/types/types/index.d.ts +30 -11
- package/dist/types/utils/billingUtils.d.ts +2 -1
- package/dist/types/vue/index.d.ts +88 -0
- package/dist/vue/frame/protocol.d.ts +12 -0
- package/dist/vue/index.cjs.js +2335 -0
- package/dist/vue/index.cjs.js.map +1 -0
- package/dist/vue/index.esm.js +2327 -0
- package/dist/vue/index.esm.js.map +1 -0
- package/dist/vue/sdk/OzElement.d.ts +99 -0
- package/dist/vue/sdk/OzVault.d.ts +250 -0
- package/dist/vue/sdk/createSessionFetcher.d.ts +29 -0
- package/dist/vue/sdk/errors.d.ts +65 -0
- package/dist/vue/sdk/index.d.ts +14 -0
- package/dist/vue/types/index.d.ts +667 -0
- package/dist/vue/utils/appearance.d.ts +22 -0
- package/dist/vue/utils/billingUtils.d.ts +61 -0
- package/dist/vue/utils/uuid.d.ts +12 -0
- package/dist/vue/vue/index.d.ts +88 -0
- package/package.json +15 -3
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* billingUtils.ts — billing detail validation and normalization.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the validation in checkout/page.tsx (pre-flight checks before cardSale)
|
|
5
|
+
* so that billing data passed to createToken() is guaranteed schema-compliant and
|
|
6
|
+
* ready to forward directly to the Ozura Pay API cardSale endpoint.
|
|
7
|
+
*
|
|
8
|
+
* All string fields enforced to 1–50 characters (cardSale schema constraint).
|
|
9
|
+
* State is normalized to 2-letter abbreviation for US and CA.
|
|
10
|
+
* Phone must be E.164 format (matches checkout's formatPhoneForAPI output).
|
|
11
|
+
*/
|
|
12
|
+
import { BillingDetails } from '../types';
|
|
13
|
+
/** Returns true when the email is syntactically valid and ≤50 characters. */
|
|
14
|
+
export declare function validateEmail(email: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Validates E.164 phone format: starts with +, 1–3 digit country code,
|
|
17
|
+
* followed by 7–12 digits, max 15 digits total (E.164 spec cap = 16 chars
|
|
18
|
+
* including the leading +).
|
|
19
|
+
*
|
|
20
|
+
* Matches the output of checkout's formatPhoneForAPI() function.
|
|
21
|
+
* Examples: "+15551234567", "+447911123456", "+61412345678"
|
|
22
|
+
*/
|
|
23
|
+
export declare function validateE164Phone(phone: string): boolean;
|
|
24
|
+
/** Returns true when the string is non-empty and ≤50 characters (cardSale schema). */
|
|
25
|
+
export declare function isValidBillingField(value: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Converts a full US state or Canadian province name to its 2-letter abbreviation.
|
|
28
|
+
* If already a valid abbreviation (case-insensitive), returns it uppercased.
|
|
29
|
+
* For non-US/CA countries, returns the input uppercased unchanged.
|
|
30
|
+
*
|
|
31
|
+
* Matches checkout's convertStateToAbbreviation() behaviour exactly.
|
|
32
|
+
*/
|
|
33
|
+
export declare function normalizeState(state: string, country: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Validates a postal/ZIP code against country-specific format rules.
|
|
36
|
+
* For countries without a specific pattern, falls back to generic 1–50 char check.
|
|
37
|
+
*/
|
|
38
|
+
export declare function validatePostalCode(zip: string, country: string): {
|
|
39
|
+
valid: boolean;
|
|
40
|
+
error?: string;
|
|
41
|
+
};
|
|
42
|
+
export interface BillingValidationResult {
|
|
43
|
+
valid: boolean;
|
|
44
|
+
/** One entry per failing field, each suitable for display in a thrown OzError message. */
|
|
45
|
+
errors: string[];
|
|
46
|
+
/** Trimmed and normalized billing details — state converted, address2 omitted if blank. */
|
|
47
|
+
normalized: BillingDetails;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Validates and normalizes billing details against the Ozura cardSale API schema.
|
|
51
|
+
*
|
|
52
|
+
* Rules applied (same as checkout's pre-flight validation in page.tsx):
|
|
53
|
+
* - firstName, lastName: required, 1–50 chars
|
|
54
|
+
* - email: optional; if provided, must be valid format and ≤50 chars
|
|
55
|
+
* - phone: optional; if provided, must be E.164 and ≤50 chars
|
|
56
|
+
* - address fields: if address is provided, line1/city/state/zip/country are
|
|
57
|
+
* required (1–50 chars each); line2 is optional and omitted from normalized
|
|
58
|
+
* output if blank (cardSale schema: minLength 1 if present)
|
|
59
|
+
* - state: normalized to 2-letter abbreviation for US and CA
|
|
60
|
+
*/
|
|
61
|
+
export declare function validateBilling(billing: BillingDetails): BillingValidationResult;
|
|
@@ -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;
|
|
@@ -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';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ozura/elements",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
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",
|
|
@@ -20,6 +20,11 @@
|
|
|
20
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
|
+
},
|
|
24
|
+
"./vue": {
|
|
25
|
+
"types": "./dist/vue/vue/index.d.ts",
|
|
26
|
+
"import": "./dist/vue/index.esm.js",
|
|
27
|
+
"require": "./dist/vue/index.cjs.js"
|
|
23
28
|
}
|
|
24
29
|
},
|
|
25
30
|
"files": [
|
|
@@ -30,6 +35,7 @@
|
|
|
30
35
|
"dist/frame",
|
|
31
36
|
"dist/react",
|
|
32
37
|
"dist/server",
|
|
38
|
+
"dist/vue",
|
|
33
39
|
"dist/types"
|
|
34
40
|
],
|
|
35
41
|
"scripts": {
|
|
@@ -46,7 +52,8 @@
|
|
|
46
52
|
},
|
|
47
53
|
"peerDependencies": {
|
|
48
54
|
"react": ">=17",
|
|
49
|
-
"react-dom": ">=17"
|
|
55
|
+
"react-dom": ">=17",
|
|
56
|
+
"vue": ">=3.3"
|
|
50
57
|
},
|
|
51
58
|
"peerDependenciesMeta": {
|
|
52
59
|
"react": {
|
|
@@ -54,6 +61,9 @@
|
|
|
54
61
|
},
|
|
55
62
|
"react-dom": {
|
|
56
63
|
"optional": true
|
|
64
|
+
},
|
|
65
|
+
"vue": {
|
|
66
|
+
"optional": true
|
|
57
67
|
}
|
|
58
68
|
},
|
|
59
69
|
"keywords": [
|
|
@@ -95,6 +105,8 @@
|
|
|
95
105
|
"rollup-plugin-copy": "^3.5.0",
|
|
96
106
|
"tslib": "^2.8.1",
|
|
97
107
|
"typescript": "^5.8.3",
|
|
98
|
-
"vitest": "^4.0.18"
|
|
108
|
+
"vitest": "^4.0.18",
|
|
109
|
+
"vue": "^3.5.0",
|
|
110
|
+
"@vue/test-utils": "^2.4.0"
|
|
99
111
|
}
|
|
100
112
|
}
|