@one-payments/web-components 1.1.26 → 1.1.27

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.
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @one-payments/web-components - Browser Entry Point (IIFE Bundle)
3
+ *
4
+ * This file is used ONLY for the browser/CDN bundle (IIFE format).
5
+ * It is completely separate from the existing ESM build and does NOT
6
+ * affect React, Vue, Angular, or any other framework wrappers.
7
+ *
8
+ * Responsibilities:
9
+ * - Safely register the <one-payment> custom element (if not already registered)
10
+ * - Expose a minimal global window.OnePayments API
11
+ * - Be safe if loaded multiple times (no hard crashes)
12
+ *
13
+ * Usage (CDN):
14
+ * <script src="https://cdn.jsdelivr.net/npm/@one-payments/web-components@X.Y.Z/dist/one-payment.browser.iife.js"></script>
15
+ * <one-payment amount="5000" currency="USD" order-id="order-123"></one-payment>
16
+ * <script>
17
+ * const el = document.querySelector('one-payment');
18
+ * el.config = { apiKey: 'pk_...', environment: 'prod' };
19
+ * el.adapters = OnePayments.createWebAdapters();
20
+ * </script>
21
+ *
22
+ * @module @one-payments/web-components/browser
23
+ */
24
+ import { createWebAdapters } from '@one-payments/adapters-web';
25
+ declare const TAG_NAME = "one-payment";
26
+ declare const VERSION = "__VERSION__";
27
+ /**
28
+ * Minimal global API exposed on window.OnePayments for CDN consumers.
29
+ *
30
+ * This API is intentionally small and stable. Only add new properties
31
+ * if absolutely necessary for CDN integrations.
32
+ */
33
+ declare const OnePayments: {
34
+ /**
35
+ * Factory to create standard web adapters for browser environment.
36
+ *
37
+ * This is the primary way CDN consumers configure the component:
38
+ * ```javascript
39
+ * const adapters = OnePayments.createWebAdapters();
40
+ * element.adapters = adapters;
41
+ * ```
42
+ */
43
+ createWebAdapters: typeof createWebAdapters;
44
+ /**
45
+ * The registered custom element tag name.
46
+ * Always 'one-payment'.
47
+ */
48
+ TAG_NAME: string;
49
+ /**
50
+ * Runtime version of this package.
51
+ * Useful for debugging and support.
52
+ */
53
+ VERSION: string;
54
+ /**
55
+ * Check if the custom element is registered.
56
+ * @returns {boolean} true if <one-payment> is registered
57
+ */
58
+ isRegistered(): boolean;
59
+ /**
60
+ * Wait for the custom element to be defined.
61
+ * Useful if you need to ensure the element is ready before use.
62
+ * @returns {Promise<CustomElementConstructor>}
63
+ */
64
+ whenDefined(): Promise<CustomElementConstructor>;
65
+ };
66
+ declare global {
67
+ interface Window {
68
+ OnePayments?: typeof OnePayments;
69
+ }
70
+ }
71
+ export default OnePayments;
72
+ export { OnePayments, createWebAdapters, TAG_NAME, VERSION };
73
+ //# sourceMappingURL=browser-entry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-entry.d.ts","sourceRoot":"","sources":["../src/browser-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAaH,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAM/D,QAAA,MAAM,QAAQ,gBAAgB,CAAC;AAG/B,QAAA,MAAM,OAAO,gBAAgB,CAAC;AAuD9B;;;;;GAKG;AACH,QAAA,MAAM,WAAW;IACf;;;;;;;;OAQG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;OAGG;oBACa,OAAO;IAOvB;;;;OAIG;mBACY,OAAO,CAAC,wBAAwB,CAAC;CAQjD,CAAC;AAOF,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,WAAW,CAAC,EAAE,OAAO,WAAW,CAAC;KAClC;CACF;AAmBD,eAAe,WAAW,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,145 @@
1
+ /**
2
+ * @one-payments/web-components - Browser Entry Point (IIFE Bundle)
3
+ *
4
+ * This file is used ONLY for the browser/CDN bundle (IIFE format).
5
+ * It is completely separate from the existing ESM build and does NOT
6
+ * affect React, Vue, Angular, or any other framework wrappers.
7
+ *
8
+ * Responsibilities:
9
+ * - Safely register the <one-payment> custom element (if not already registered)
10
+ * - Expose a minimal global window.OnePayments API
11
+ * - Be safe if loaded multiple times (no hard crashes)
12
+ *
13
+ * Usage (CDN):
14
+ * <script src="https://cdn.jsdelivr.net/npm/@one-payments/web-components@X.Y.Z/dist/one-payment.browser.iife.js"></script>
15
+ * <one-payment amount="5000" currency="USD" order-id="order-123"></one-payment>
16
+ * <script>
17
+ * const el = document.querySelector('one-payment');
18
+ * el.config = { apiKey: 'pk_...', environment: 'prod' };
19
+ * el.adapters = OnePayments.createWebAdapters();
20
+ * </script>
21
+ *
22
+ * @module @one-payments/web-components/browser
23
+ */
24
+ // =============================================================================
25
+ // Imports
26
+ // These will be bundled inline by Vite/Rollup for the IIFE build
27
+ // =============================================================================
28
+ // Import the component class (NOT auto-registered in this context because
29
+ // we import the class directly, the @customElement decorator only fires
30
+ // when the module containing the class definition is evaluated)
31
+ import { OnePayment } from './one-payment.js';
32
+ // Import web adapters factory - this is the key API for CDN consumers
33
+ import { createWebAdapters } from '@one-payments/adapters-web';
34
+ // =============================================================================
35
+ // Constants
36
+ // =============================================================================
37
+ const TAG_NAME = 'one-payment';
38
+ // Version will be replaced at build time via Vite's define config
39
+ const VERSION = '__VERSION__';
40
+ // =============================================================================
41
+ // Safe Custom Element Registration
42
+ // =============================================================================
43
+ /**
44
+ * Safely register the <one-payment> custom element.
45
+ *
46
+ * This function:
47
+ * - Checks if customElements API is available
48
+ * - Checks if the element is already registered (prevents errors)
49
+ * - Wraps registration in try-catch for safety
50
+ *
51
+ * @returns {boolean} true if registration succeeded or element was already registered
52
+ */
53
+ function registerElement() {
54
+ // Check if customElements API is available (not available in Node.js/SSR)
55
+ if (typeof customElements === 'undefined') {
56
+ console.error('[OnePayments] customElements API is not available in this environment. ' +
57
+ 'This bundle is designed for browser environments only.');
58
+ return false;
59
+ }
60
+ // Check if element is already registered (by ESM import, another bundle load, etc.)
61
+ if (customElements.get(TAG_NAME)) {
62
+ console.info(`[OnePayments] <${TAG_NAME}> is already registered. Skipping re-registration.`);
63
+ return true;
64
+ }
65
+ // Attempt to register the custom element
66
+ try {
67
+ customElements.define(TAG_NAME, OnePayment);
68
+ console.info(`[OnePayments] Registered <${TAG_NAME}> custom element (v${VERSION})`);
69
+ return true;
70
+ }
71
+ catch (error) {
72
+ console.error(`[OnePayments] Failed to register <${TAG_NAME}>:`, error);
73
+ return false;
74
+ }
75
+ }
76
+ // Register immediately when script loads
77
+ // This is safe because customElements.define() doesn't need DOMContentLoaded
78
+ registerElement();
79
+ // =============================================================================
80
+ // Global API
81
+ // =============================================================================
82
+ /**
83
+ * Minimal global API exposed on window.OnePayments for CDN consumers.
84
+ *
85
+ * This API is intentionally small and stable. Only add new properties
86
+ * if absolutely necessary for CDN integrations.
87
+ */
88
+ const OnePayments = {
89
+ /**
90
+ * Factory to create standard web adapters for browser environment.
91
+ *
92
+ * This is the primary way CDN consumers configure the component:
93
+ * ```javascript
94
+ * const adapters = OnePayments.createWebAdapters();
95
+ * element.adapters = adapters;
96
+ * ```
97
+ */
98
+ createWebAdapters,
99
+ /**
100
+ * The registered custom element tag name.
101
+ * Always 'one-payment'.
102
+ */
103
+ TAG_NAME,
104
+ /**
105
+ * Runtime version of this package.
106
+ * Useful for debugging and support.
107
+ */
108
+ VERSION,
109
+ /**
110
+ * Check if the custom element is registered.
111
+ * @returns {boolean} true if <one-payment> is registered
112
+ */
113
+ isRegistered() {
114
+ return (typeof customElements !== 'undefined' &&
115
+ customElements.get(TAG_NAME) !== undefined);
116
+ },
117
+ /**
118
+ * Wait for the custom element to be defined.
119
+ * Useful if you need to ensure the element is ready before use.
120
+ * @returns {Promise<CustomElementConstructor>}
121
+ */
122
+ whenDefined() {
123
+ if (typeof customElements === 'undefined') {
124
+ return Promise.reject(new Error('customElements API is not available'));
125
+ }
126
+ return customElements.whenDefined(TAG_NAME);
127
+ },
128
+ };
129
+ // Attach to window, but don't overwrite if something already exists
130
+ // This handles the case where the bundle might be loaded twice
131
+ if (typeof window !== 'undefined') {
132
+ if (!window.OnePayments) {
133
+ window.OnePayments = OnePayments;
134
+ }
135
+ else {
136
+ console.warn('[OnePayments] window.OnePayments already exists. ' +
137
+ 'The bundle may have been loaded multiple times. Using existing reference.');
138
+ }
139
+ }
140
+ // =============================================================================
141
+ // Exports (for potential ESM usage of this file, though primarily IIFE)
142
+ // =============================================================================
143
+ export default OnePayments;
144
+ export { OnePayments, createWebAdapters, TAG_NAME, VERSION };
145
+ //# sourceMappingURL=browser-entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-entry.js","sourceRoot":"","sources":["../src/browser-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,gFAAgF;AAChF,UAAU;AACV,iEAAiE;AACjE,gFAAgF;AAEhF,0EAA0E;AAC1E,wEAAwE;AACxE,gEAAgE;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,sEAAsE;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF,MAAM,QAAQ,GAAG,aAAa,CAAC;AAE/B,kEAAkE;AAClE,MAAM,OAAO,GAAG,aAAa,CAAC;AAE9B,gFAAgF;AAChF,mCAAmC;AACnC,gFAAgF;AAEhF;;;;;;;;;GASG;AACH,SAAS,eAAe;IACtB,0EAA0E;IAC1E,IAAI,OAAO,cAAc,KAAK,WAAW,EAAE,CAAC;QAC1C,OAAO,CAAC,KAAK,CACX,yEAAyE;YACvE,wDAAwD,CAC3D,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,oFAAoF;IACpF,IAAI,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QACjC,OAAO,CAAC,IAAI,CACV,kBAAkB,QAAQ,oDAAoD,CAC/E,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,yCAAyC;IACz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