rebill-web-components-sdk 1.10.13 → 1.11.0-beta.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.
Files changed (31) hide show
  1. package/dist/cjs/index-C-VTnc0I.js.map +1 -1
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/rebill-checkout.cjs.entry.js +147 -40
  4. package/dist/cjs/rebill-checkout.entry.cjs.js.map +1 -1
  5. package/dist/cjs/rebill-web-components-sdk.cjs.js +1 -1
  6. package/dist/collection/components/checkout/rebill-checkout.js +49 -40
  7. package/dist/collection/components/checkout/rebill-checkout.js.map +1 -1
  8. package/dist/collection/utils/index.js +2 -0
  9. package/dist/collection/utils/index.js.map +1 -1
  10. package/dist/collection/utils/resource-injector.js +118 -0
  11. package/dist/collection/utils/resource-injector.js.map +1 -0
  12. package/dist/components/p-8BpuJ_V5.js.map +1 -1
  13. package/dist/components/rebill-checkout.js +148 -40
  14. package/dist/components/rebill-checkout.js.map +1 -1
  15. package/dist/esm/index-BTZ7D7jU.js.map +1 -1
  16. package/dist/esm/loader.js +1 -1
  17. package/dist/esm/rebill-checkout.entry.js +147 -40
  18. package/dist/esm/rebill-checkout.entry.js.map +1 -1
  19. package/dist/esm/rebill-web-components-sdk.js +1 -1
  20. package/dist/rebill-web-components-sdk/p-457f405c.entry.js +2 -0
  21. package/dist/rebill-web-components-sdk/p-457f405c.entry.js.map +1 -0
  22. package/dist/rebill-web-components-sdk/p-BTZ7D7jU.js.map +1 -1
  23. package/dist/rebill-web-components-sdk/rebill-checkout.entry.esm.js.map +1 -1
  24. package/dist/rebill-web-components-sdk/rebill-web-components-sdk.esm.js +1 -1
  25. package/dist/types/components/checkout/rebill-checkout.d.ts +14 -0
  26. package/dist/types/components.d.ts +8 -0
  27. package/dist/types/utils/index.d.ts +1 -0
  28. package/dist/types/utils/resource-injector.d.ts +29 -0
  29. package/package.json +1 -1
  30. package/dist/rebill-web-components-sdk/p-4b4e2e73.entry.js +0 -2
  31. package/dist/rebill-web-components-sdk/p-4b4e2e73.entry.js.map +0 -1
@@ -78,6 +78,124 @@ const DEFAULT_DISPLAY_CONFIG = {
78
78
  useAddressSearch: true,
79
79
  };
80
80
 
81
+ /**
82
+ * Utility functions for injecting custom CSS and JavaScript resources into the document
83
+ */
84
+ /**
85
+ * Checks if a string is a URL (http, https, or protocol-relative)
86
+ */
87
+ function isUrl(content) {
88
+ return (content.startsWith('http://') || content.startsWith('https://') || content.startsWith('//'));
89
+ }
90
+ /**
91
+ * Generates a unique ID for injected resources
92
+ */
93
+ function generateResourceId(prefix) {
94
+ return `${prefix}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
95
+ }
96
+ /**
97
+ * Creates a CSS link element for loading CSS from a URL
98
+ */
99
+ function createCssLinkElement(url, id) {
100
+ const linkElement = document.createElement('link');
101
+ linkElement.rel = 'stylesheet';
102
+ linkElement.href = url;
103
+ linkElement.id = id;
104
+ linkElement.setAttribute('data-rebill-injected', 'true');
105
+ return linkElement;
106
+ }
107
+ /**
108
+ * Creates a style element for injecting raw CSS
109
+ */
110
+ function createStyleElement(css, id) {
111
+ const styleElement = document.createElement('style');
112
+ styleElement.id = id;
113
+ styleElement.setAttribute('data-rebill-injected', 'true');
114
+ styleElement.textContent = css;
115
+ return styleElement;
116
+ }
117
+ /**
118
+ * Creates a script element for loading JavaScript from a URL
119
+ */
120
+ function createScriptLinkElement(url, id) {
121
+ const scriptElement = document.createElement('script');
122
+ scriptElement.src = url;
123
+ scriptElement.id = id;
124
+ scriptElement.setAttribute('data-rebill-injected', 'true');
125
+ scriptElement.async = true;
126
+ return scriptElement;
127
+ }
128
+ /**
129
+ * Creates a script element for injecting raw JavaScript
130
+ */
131
+ function createScriptElement(js, id) {
132
+ const scriptElement = document.createElement('script');
133
+ scriptElement.id = id;
134
+ scriptElement.setAttribute('data-rebill-injected', 'true');
135
+ scriptElement.textContent = js;
136
+ return scriptElement;
137
+ }
138
+ /**
139
+ * Removes an injected resource element from the DOM
140
+ */
141
+ function removeInjectedResource(element) {
142
+ if (!element) {
143
+ return;
144
+ }
145
+ try {
146
+ element.remove();
147
+ }
148
+ catch (error) {
149
+ console.warn('Error removing injected resource:', error);
150
+ }
151
+ }
152
+ /**
153
+ * Injects custom CSS into the document
154
+ * @param css - CSS content (raw CSS string or URL)
155
+ * @param existingElement - Optional existing injected element to clean up first
156
+ * @returns The injected element or null if no CSS was provided
157
+ */
158
+ function injectCSS(css, existingElement = null) {
159
+ if (!css) {
160
+ return null;
161
+ }
162
+ // Clean up existing element if provided
163
+ removeInjectedResource(existingElement);
164
+ const cssId = generateResourceId('rebill-checkout-css');
165
+ const element = isUrl(css) ? createCssLinkElement(css, cssId) : createStyleElement(css, cssId);
166
+ document.head.appendChild(element);
167
+ return element;
168
+ }
169
+ /**
170
+ * Injects custom JavaScript into the document
171
+ * @param js - JavaScript content (raw JS string or URL)
172
+ * @param existingElement - Optional existing injected element to clean up first
173
+ * @returns The injected element or null if no JS was provided
174
+ */
175
+ function injectJS(js, existingElement = null) {
176
+ if (!js) {
177
+ return null;
178
+ }
179
+ // Clean up existing element if provided
180
+ removeInjectedResource(existingElement);
181
+ const jsId = generateResourceId('rebill-checkout-js');
182
+ const element = isUrl(js) ? createScriptLinkElement(js, jsId) : createScriptElement(js, jsId);
183
+ document.head.appendChild(element);
184
+ return element;
185
+ }
186
+ /**
187
+ * Cleans up injected CSS element
188
+ */
189
+ function cleanupCSS(element) {
190
+ removeInjectedResource(element);
191
+ }
192
+ /**
193
+ * Cleans up injected JavaScript element
194
+ */
195
+ function cleanupJS(element) {
196
+ removeInjectedResource(element);
197
+ }
198
+
81
199
  var PROVIDER_ENUM;
82
200
  (function (PROVIDER_ENUM) {
83
201
  PROVIDER_ENUM["BAMBOO"] = "bamboo_payment";
@@ -245,6 +363,11 @@ const RebillCheckout$1 = /*@__PURE__*/ proxyCustomElement(class RebillCheckout e
245
363
  * Can be a string of CSS or a URL to a CSS file
246
364
  */
247
365
  css;
366
+ /**
367
+ * Custom JavaScript to be injected into the component
368
+ * Can be a string of JavaScript code or a URL to a JS file
369
+ */
370
+ js;
248
371
  /**
249
372
  * Language code for the application display
250
373
  * If not provided, the language will be determined by the current session logic
@@ -313,6 +436,7 @@ const RebillCheckout$1 = /*@__PURE__*/ proxyCustomElement(class RebillCheckout e
313
436
  formElement;
314
437
  emailDebounceTimeout = null;
315
438
  injectedStyleElement = null;
439
+ injectedScriptElement = null;
316
440
  /**
317
441
  * Get the display configuration, merging user config with defaults
318
442
  */
@@ -416,49 +540,27 @@ const RebillCheckout$1 = /*@__PURE__*/ proxyCustomElement(class RebillCheckout e
416
540
  * Inject custom CSS into the document
417
541
  */
418
542
  injectCustomCSS() {
419
- if (!this.css) {
420
- return;
421
- }
422
- // Clean up any existing injected CSS
423
- this.cleanupInjectedCSS();
424
- // Create a unique ID for this component's CSS
425
- const cssId = `rebill-checkout-css-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
426
- // Check if CSS is a URL or raw CSS
427
- if (this.css.startsWith('http://') ||
428
- this.css.startsWith('https://') ||
429
- this.css.startsWith('//')) {
430
- // Load CSS from URL
431
- const linkElement = document.createElement('link');
432
- linkElement.rel = 'stylesheet';
433
- linkElement.href = this.css;
434
- linkElement.id = cssId;
435
- linkElement.setAttribute('data-rebill-injected', 'true');
436
- document.head.appendChild(linkElement);
437
- this.injectedStyleElement = linkElement; // Store reference for cleanup
438
- }
439
- else {
440
- // Inject raw CSS
441
- const styleElement = document.createElement('style');
442
- styleElement.id = cssId;
443
- styleElement.setAttribute('data-rebill-injected', 'true');
444
- styleElement.textContent = this.css;
445
- document.head.appendChild(styleElement);
446
- this.injectedStyleElement = styleElement;
447
- }
543
+ this.injectedStyleElement = injectCSS(this.css, this.injectedStyleElement);
448
544
  }
449
545
  /**
450
546
  * Clean up injected CSS
451
547
  */
452
548
  cleanupInjectedCSS() {
453
- if (this.injectedStyleElement) {
454
- try {
455
- this.injectedStyleElement.remove();
456
- }
457
- catch (error) {
458
- console.warn('Error removing injected CSS:', error);
459
- }
460
- this.injectedStyleElement = null;
461
- }
549
+ cleanupCSS(this.injectedStyleElement);
550
+ this.injectedStyleElement = null;
551
+ }
552
+ /**
553
+ * Inject custom JavaScript into the document
554
+ */
555
+ injectCustomJS() {
556
+ this.injectedScriptElement = injectJS(this.js, this.injectedScriptElement);
557
+ }
558
+ /**
559
+ * Clean up injected JavaScript
560
+ */
561
+ cleanupInjectedJS() {
562
+ cleanupJS(this.injectedScriptElement);
563
+ this.injectedScriptElement = null;
462
564
  }
463
565
  timeToRedirectAPM = 5000;
464
566
  resizeHandler = () => {
@@ -474,6 +576,7 @@ const RebillCheckout$1 = /*@__PURE__*/ proxyCustomElement(class RebillCheckout e
474
576
  this.emailDebounceTimeout = null;
475
577
  }
476
578
  this.cleanupInjectedCSS();
579
+ this.cleanupInjectedJS();
477
580
  }
478
581
  async componentWillLoad() {
479
582
  try {
@@ -481,6 +584,8 @@ const RebillCheckout$1 = /*@__PURE__*/ proxyCustomElement(class RebillCheckout e
481
584
  window.addEventListener('resize', this.resizeHandler);
482
585
  // Inject custom CSS if provided
483
586
  this.injectCustomCSS();
587
+ // Inject custom JS if provided
588
+ this.injectCustomJS();
484
589
  // Initialize language - use prop if provided, otherwise use current session logic
485
590
  if (this.language) {
486
591
  await I18nService.changeLanguage(this.language);
@@ -549,6 +654,8 @@ const RebillCheckout$1 = /*@__PURE__*/ proxyCustomElement(class RebillCheckout e
549
654
  componentWillUpdate() {
550
655
  // Re-inject CSS when css prop changes
551
656
  this.injectCustomCSS();
657
+ // Re-inject JS when js prop changes
658
+ this.injectCustomJS();
552
659
  }
553
660
  async changePaymentMethod(paymentMethod) {
554
661
  if (paymentMethod !== this.currentPaymentMethod &&
@@ -1103,8 +1210,8 @@ const RebillCheckout$1 = /*@__PURE__*/ proxyCustomElement(class RebillCheckout e
1103
1210
  label: country.country,
1104
1211
  value: country.isoCountryCode,
1105
1212
  }));
1106
- const renderRebillSummary = (props = {}) => (h("rebill-summary", { key: '4b1db10c60e123202a604f64dc89990eace6325b', totalAmount: state.data.pricing.total, currency: state.data.pricing.currency, itemTitle: state._session?.getTitle(), itemDescription: state._session?.getDescription(), itemAmount: state.data.pricing.subtotal, subtotal: state.data.pricing.subtotal, allowCoupon: state._session?.getAllowCoupon(this.displayConfig), currentBreakpoint: this.breakpoint, planFrequency: state._session?.getPlanFrequency(), planFrequencyCount: state._session?.getPlanFrequencyCount(), discountType: state.data.discount.discountType, discountedPercentage: state.data.discount.discountedPercentage, discountDuration: state.data.discount.discountDuration, discountAmount: state.data.discount.discountAmount, ...props }));
1107
- return (state.isInitialized && (h(h.Fragment, null, this.showRefreshModal && h("rebill-modal-overlay", { key: '479d5fbdd896241eadf43771c112d683fdafd54b' }), this.displayConfig.processingPayment && (h("rebill-processing-payment", { key: '29f1f76748c8603b97537e62fd6c973b17fecff7', style: { display: this.isCardSubmitting ? 'block' : 'none' } })), this.displayConfig.successPage &&
1213
+ const renderRebillSummary = (props = {}) => (h("rebill-summary", { key: 'f59c6912ff6e36c26f1e307e5258a3dca45d6d13', totalAmount: state.data.pricing.total, currency: state.data.pricing.currency, itemTitle: state._session?.getTitle(), itemDescription: state._session?.getDescription(), itemAmount: state.data.pricing.subtotal, subtotal: state.data.pricing.subtotal, allowCoupon: state._session?.getAllowCoupon(this.displayConfig), currentBreakpoint: this.breakpoint, planFrequency: state._session?.getPlanFrequency(), planFrequencyCount: state._session?.getPlanFrequencyCount(), discountType: state.data.discount.discountType, discountedPercentage: state.data.discount.discountedPercentage, discountDuration: state.data.discount.discountDuration, discountAmount: state.data.discount.discountAmount, ...props }));
1214
+ return (state.isInitialized && (h(h.Fragment, null, this.showRefreshModal && h("rebill-modal-overlay", { key: 'a108e0ac7ab80a67d38d94fe3ee2182edade936a' }), this.displayConfig.processingPayment && (h("rebill-processing-payment", { key: '03f97c3d9c68586df7ba0e29323f4cf9d50e3f1c', style: { display: this.isCardSubmitting ? 'block' : 'none' } })), this.displayConfig.successPage &&
1108
1215
  this.isPaymentApproved() &&
1109
1216
  state.isInitialized ? (h("success-page", { typePaymentMethod: state.data.paymentMethodSelected, paymentMethodName: PaymentMethodMapper.mapToAPMPaymentMethod(state.data.paymentMethodSelected ||
1110
1217
  state.data.payment?.paymentMethodType, state.data?.pricing?.country), country: state.data?.pricing?.country, bank: state.data.payment?.paymentMethodMetadata?.bank ||
@@ -1251,6 +1358,7 @@ const RebillCheckout$1 = /*@__PURE__*/ proxyCustomElement(class RebillCheckout e
1251
1358
  "customerInformation": [1, "customer-information"],
1252
1359
  "oneClickCheckout": [4, "one-click-checkout"],
1253
1360
  "css": [1],
1361
+ "js": [1],
1254
1362
  "language": [1],
1255
1363
  "checkoutLandingSession": [1, "checkout-landing-session"],
1256
1364
  "externalPayment": [1, "external-payment"],