rebill-web-components-sdk 1.10.12 → 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 (43) 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-renewal.cjs.entry.js +17 -9
  6. package/dist/cjs/rebill-renewal.entry.cjs.js.map +1 -1
  7. package/dist/cjs/rebill-web-components-sdk.cjs.js +1 -1
  8. package/dist/collection/components/checkout/rebill-checkout.js +49 -40
  9. package/dist/collection/components/checkout/rebill-checkout.js.map +1 -1
  10. package/dist/collection/components/renewal/rebill-renewal.js +17 -9
  11. package/dist/collection/components/renewal/rebill-renewal.js.map +1 -1
  12. package/dist/collection/utils/index.js +2 -0
  13. package/dist/collection/utils/index.js.map +1 -1
  14. package/dist/collection/utils/resource-injector.js +118 -0
  15. package/dist/collection/utils/resource-injector.js.map +1 -0
  16. package/dist/components/p-8BpuJ_V5.js.map +1 -1
  17. package/dist/components/rebill-checkout.js +148 -40
  18. package/dist/components/rebill-checkout.js.map +1 -1
  19. package/dist/components/rebill-renewal.js +17 -9
  20. package/dist/components/rebill-renewal.js.map +1 -1
  21. package/dist/esm/index-BTZ7D7jU.js.map +1 -1
  22. package/dist/esm/loader.js +1 -1
  23. package/dist/esm/rebill-checkout.entry.js +147 -40
  24. package/dist/esm/rebill-checkout.entry.js.map +1 -1
  25. package/dist/esm/rebill-renewal.entry.js +17 -9
  26. package/dist/esm/rebill-renewal.entry.js.map +1 -1
  27. package/dist/esm/rebill-web-components-sdk.js +1 -1
  28. package/dist/rebill-web-components-sdk/{p-ecd698bc.entry.js → p-11b3fc35.entry.js} +2 -2
  29. package/dist/rebill-web-components-sdk/p-11b3fc35.entry.js.map +1 -0
  30. package/dist/rebill-web-components-sdk/p-457f405c.entry.js +2 -0
  31. package/dist/rebill-web-components-sdk/p-457f405c.entry.js.map +1 -0
  32. package/dist/rebill-web-components-sdk/p-BTZ7D7jU.js.map +1 -1
  33. package/dist/rebill-web-components-sdk/rebill-checkout.entry.esm.js.map +1 -1
  34. package/dist/rebill-web-components-sdk/rebill-renewal.entry.esm.js.map +1 -1
  35. package/dist/rebill-web-components-sdk/rebill-web-components-sdk.esm.js +1 -1
  36. package/dist/types/components/checkout/rebill-checkout.d.ts +14 -0
  37. package/dist/types/components.d.ts +8 -0
  38. package/dist/types/utils/index.d.ts +1 -0
  39. package/dist/types/utils/resource-injector.d.ts +29 -0
  40. package/package.json +1 -1
  41. package/dist/rebill-web-components-sdk/p-4b4e2e73.entry.js +0 -2
  42. package/dist/rebill-web-components-sdk/p-4b4e2e73.entry.js.map +0 -1
  43. package/dist/rebill-web-components-sdk/p-ecd698bc.entry.js.map +0 -1
@@ -23,6 +23,7 @@ import { GoogleMapsService } from "../../utils/google-maps.service";
23
23
  import { PaymentErrorMapper } from "../../utils/payment-error-mapper";
24
24
  import { PaymentMethodMapper } from "../../utils/payment-method-mapper";
25
25
  import { getFieldValues, isFieldRequired } from "../../utils/required-fields-mappers";
26
+ import { cleanupCSS, cleanupJS, injectCSS, injectJS } from "../../utils/resource-injector";
26
27
  import "../shared/mode-sandbox/mode-sandbox";
27
28
  import { getAllRequiredFields, getRequiredFieldsForMethod, } from "./utils/getRequiredFields";
28
29
  import { getSessionToInitialize } from "./utils/getSessionToInitialize";
@@ -64,6 +65,11 @@ export class RebillCheckout {
64
65
  * Can be a string of CSS or a URL to a CSS file
65
66
  */
66
67
  css;
68
+ /**
69
+ * Custom JavaScript to be injected into the component
70
+ * Can be a string of JavaScript code or a URL to a JS file
71
+ */
72
+ js;
67
73
  /**
68
74
  * Language code for the application display
69
75
  * If not provided, the language will be determined by the current session logic
@@ -132,6 +138,7 @@ export class RebillCheckout {
132
138
  formElement;
133
139
  emailDebounceTimeout = null;
134
140
  injectedStyleElement = null;
141
+ injectedScriptElement = null;
135
142
  /**
136
143
  * Get the display configuration, merging user config with defaults
137
144
  */
@@ -235,49 +242,27 @@ export class RebillCheckout {
235
242
  * Inject custom CSS into the document
236
243
  */
237
244
  injectCustomCSS() {
238
- if (!this.css) {
239
- return;
240
- }
241
- // Clean up any existing injected CSS
242
- this.cleanupInjectedCSS();
243
- // Create a unique ID for this component's CSS
244
- const cssId = `rebill-checkout-css-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
245
- // Check if CSS is a URL or raw CSS
246
- if (this.css.startsWith('http://') ||
247
- this.css.startsWith('https://') ||
248
- this.css.startsWith('//')) {
249
- // Load CSS from URL
250
- const linkElement = document.createElement('link');
251
- linkElement.rel = 'stylesheet';
252
- linkElement.href = this.css;
253
- linkElement.id = cssId;
254
- linkElement.setAttribute('data-rebill-injected', 'true');
255
- document.head.appendChild(linkElement);
256
- this.injectedStyleElement = linkElement; // Store reference for cleanup
257
- }
258
- else {
259
- // Inject raw CSS
260
- const styleElement = document.createElement('style');
261
- styleElement.id = cssId;
262
- styleElement.setAttribute('data-rebill-injected', 'true');
263
- styleElement.textContent = this.css;
264
- document.head.appendChild(styleElement);
265
- this.injectedStyleElement = styleElement;
266
- }
245
+ this.injectedStyleElement = injectCSS(this.css, this.injectedStyleElement);
267
246
  }
268
247
  /**
269
248
  * Clean up injected CSS
270
249
  */
271
250
  cleanupInjectedCSS() {
272
- if (this.injectedStyleElement) {
273
- try {
274
- this.injectedStyleElement.remove();
275
- }
276
- catch (error) {
277
- console.warn('Error removing injected CSS:', error);
278
- }
279
- this.injectedStyleElement = null;
280
- }
251
+ cleanupCSS(this.injectedStyleElement);
252
+ this.injectedStyleElement = null;
253
+ }
254
+ /**
255
+ * Inject custom JavaScript into the document
256
+ */
257
+ injectCustomJS() {
258
+ this.injectedScriptElement = injectJS(this.js, this.injectedScriptElement);
259
+ }
260
+ /**
261
+ * Clean up injected JavaScript
262
+ */
263
+ cleanupInjectedJS() {
264
+ cleanupJS(this.injectedScriptElement);
265
+ this.injectedScriptElement = null;
281
266
  }
282
267
  timeToRedirectAPM = 5000;
283
268
  resizeHandler = () => {
@@ -293,6 +278,7 @@ export class RebillCheckout {
293
278
  this.emailDebounceTimeout = null;
294
279
  }
295
280
  this.cleanupInjectedCSS();
281
+ this.cleanupInjectedJS();
296
282
  }
297
283
  async componentWillLoad() {
298
284
  try {
@@ -300,6 +286,8 @@ export class RebillCheckout {
300
286
  window.addEventListener('resize', this.resizeHandler);
301
287
  // Inject custom CSS if provided
302
288
  this.injectCustomCSS();
289
+ // Inject custom JS if provided
290
+ this.injectCustomJS();
303
291
  // Initialize language - use prop if provided, otherwise use current session logic
304
292
  if (this.language) {
305
293
  await I18nService.changeLanguage(this.language);
@@ -368,6 +356,8 @@ export class RebillCheckout {
368
356
  componentWillUpdate() {
369
357
  // Re-inject CSS when css prop changes
370
358
  this.injectCustomCSS();
359
+ // Re-inject JS when js prop changes
360
+ this.injectCustomJS();
371
361
  }
372
362
  async changePaymentMethod(paymentMethod) {
373
363
  if (paymentMethod !== this.currentPaymentMethod &&
@@ -925,8 +915,8 @@ export class RebillCheckout {
925
915
  label: country.country,
926
916
  value: country.isoCountryCode,
927
917
  }));
928
- const renderRebillSummary = (props = {}) => (h("rebill-summary", { key: '4b1db10c60e123202a604f64dc89990eace6325b', totalAmount: sessionState.data.pricing.total, currency: sessionState.data.pricing.currency, itemTitle: sessionState._session?.getTitle(), itemDescription: sessionState._session?.getDescription(), itemAmount: sessionState.data.pricing.subtotal, subtotal: sessionState.data.pricing.subtotal, allowCoupon: sessionState._session?.getAllowCoupon(this.displayConfig), currentBreakpoint: this.breakpoint, planFrequency: sessionState._session?.getPlanFrequency(), planFrequencyCount: sessionState._session?.getPlanFrequencyCount(), discountType: sessionState.data.discount.discountType, discountedPercentage: sessionState.data.discount.discountedPercentage, discountDuration: sessionState.data.discount.discountDuration, discountAmount: sessionState.data.discount.discountAmount, ...props }));
929
- return (sessionState.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 &&
918
+ const renderRebillSummary = (props = {}) => (h("rebill-summary", { key: 'f59c6912ff6e36c26f1e307e5258a3dca45d6d13', totalAmount: sessionState.data.pricing.total, currency: sessionState.data.pricing.currency, itemTitle: sessionState._session?.getTitle(), itemDescription: sessionState._session?.getDescription(), itemAmount: sessionState.data.pricing.subtotal, subtotal: sessionState.data.pricing.subtotal, allowCoupon: sessionState._session?.getAllowCoupon(this.displayConfig), currentBreakpoint: this.breakpoint, planFrequency: sessionState._session?.getPlanFrequency(), planFrequencyCount: sessionState._session?.getPlanFrequencyCount(), discountType: sessionState.data.discount.discountType, discountedPercentage: sessionState.data.discount.discountedPercentage, discountDuration: sessionState.data.discount.discountDuration, discountAmount: sessionState.data.discount.discountAmount, ...props }));
919
+ return (sessionState.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 &&
930
920
  this.isPaymentApproved() &&
931
921
  sessionState.isInitialized ? (h("success-page", { typePaymentMethod: sessionState.data.paymentMethodSelected, paymentMethodName: PaymentMethodMapper.mapToAPMPaymentMethod(sessionState.data.paymentMethodSelected ||
932
922
  sessionState.data.payment?.paymentMethodType, sessionState.data?.pricing?.country), country: sessionState.data?.pricing?.country, bank: sessionState.data.payment?.paymentMethodMetadata?.bank ||
@@ -1259,6 +1249,25 @@ export class RebillCheckout {
1259
1249
  "reflect": false,
1260
1250
  "attribute": "css"
1261
1251
  },
1252
+ "js": {
1253
+ "type": "string",
1254
+ "mutable": false,
1255
+ "complexType": {
1256
+ "original": "string",
1257
+ "resolved": "string",
1258
+ "references": {}
1259
+ },
1260
+ "required": false,
1261
+ "optional": true,
1262
+ "docs": {
1263
+ "tags": [],
1264
+ "text": "Custom JavaScript to be injected into the component\nCan be a string of JavaScript code or a URL to a JS file"
1265
+ },
1266
+ "getter": false,
1267
+ "setter": false,
1268
+ "reflect": false,
1269
+ "attribute": "js"
1270
+ },
1262
1271
  "language": {
1263
1272
  "type": "string",
1264
1273
  "mutable": false,