@schematichq/schematic-components 1.4.1 → 1.4.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.
@@ -289,17 +289,17 @@ var require_debounce = __commonJS({
289
289
  var FUNC_ERROR_TEXT = "Expected a function";
290
290
  var nativeMax = Math.max;
291
291
  var nativeMin = Math.min;
292
- function debounce4(func, wait, options2) {
292
+ function debounce4(func, wait, options) {
293
293
  var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
294
294
  if (typeof func != "function") {
295
295
  throw new TypeError(FUNC_ERROR_TEXT);
296
296
  }
297
297
  wait = toNumber(wait) || 0;
298
- if (isObject2(options2)) {
299
- leading = !!options2.leading;
300
- maxing = "maxWait" in options2;
301
- maxWait = maxing ? nativeMax(toNumber(options2.maxWait) || 0, wait) : maxWait;
302
- trailing = "trailing" in options2 ? !!options2.trailing : trailing;
298
+ if (isObject2(options)) {
299
+ leading = !!options.leading;
300
+ maxing = "maxWait" in options;
301
+ maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
302
+ trailing = "trailing" in options ? !!options.trailing : trailing;
303
303
  }
304
304
  function invokeFunc(time) {
305
305
  var args = lastArgs, thisArg = lastThis;
@@ -1918,7 +1918,7 @@ var HOURS_IN_MS = MINUTES_IN_MS * 60;
1918
1918
  var DAYS_IN_MS = HOURS_IN_MS * 24;
1919
1919
 
1920
1920
  // src/const/debounce.ts
1921
- var debounceOptions = {
1921
+ var DEBOUNCE_SETTINGS = {
1922
1922
  leading: true,
1923
1923
  trailing: false
1924
1924
  };
@@ -1945,8 +1945,8 @@ function getPriceValue(billingPrice) {
1945
1945
  const price = typeof billingPrice.priceDecimal === "string" ? Number(billingPrice.priceDecimal) : billingPrice.price;
1946
1946
  return price;
1947
1947
  }
1948
- function getPlanPrice(plan, period = "month", options2 = { useSelectedPeriod: true }) {
1949
- const billingPrice = options2.useSelectedPeriod ? period === "year" ? plan.yearlyPrice : plan.monthlyPrice : plan.yearlyPrice && !plan.monthlyPrice ? plan.yearlyPrice : plan.monthlyPrice;
1948
+ function getPlanPrice(plan, period = "month", options = { useSelectedPeriod: true }) {
1949
+ const billingPrice = options.useSelectedPeriod ? period === "year" ? plan.yearlyPrice : plan.monthlyPrice : plan.yearlyPrice && !plan.monthlyPrice ? plan.yearlyPrice : plan.monthlyPrice;
1950
1950
  if (billingPrice) {
1951
1951
  return { ...billingPrice, price: getPriceValue(billingPrice) };
1952
1952
  }
@@ -2078,14 +2078,14 @@ function groupPlanCreditGrants(creditGrants) {
2078
2078
  );
2079
2079
  return Object.values(map);
2080
2080
  }
2081
- function groupCreditGrants(creditGrants, options2) {
2081
+ function groupCreditGrants(creditGrants, options) {
2082
2082
  const today = /* @__PURE__ */ new Date();
2083
2083
  const map = creditGrants.reduce(
2084
2084
  (acc, grant) => {
2085
2085
  const isExpired = !!grant.expiresAt && grant.expiresAt <= today;
2086
2086
  const isZeroedOut = !!grant.zeroedOutDate;
2087
2087
  if (!isExpired && !isZeroedOut) {
2088
- const key = options2?.groupBy === "bundle" ? grant.billingCreditBundleId || grant.id : options2?.groupBy === "credit" ? grant.billingCreditId : grant.id;
2088
+ const key = options?.groupBy === "bundle" ? grant.billingCreditBundleId || grant.id : options?.groupBy === "credit" ? grant.billingCreditId : grant.id;
2089
2089
  const current = acc[key];
2090
2090
  acc[key] = {
2091
2091
  // credit-specific attributes
@@ -4145,7 +4145,7 @@ attr.rem = function propAsRem(key, value) {
4145
4145
  };
4146
4146
 
4147
4147
  // src/hooks/useAvailablePlans.ts
4148
- function useAvailablePlans(activePeriod, options2 = { useSelectedPeriod: true }) {
4148
+ function useAvailablePlans(activePeriod, options = { useSelectedPeriod: true }) {
4149
4149
  const { data, settings } = useEmbed();
4150
4150
  const getAvailablePeriods = (0, import_react2.useCallback)(() => {
4151
4151
  const periods = [];
@@ -4160,14 +4160,14 @@ function useAvailablePlans(activePeriod, options2 = { useSelectedPeriod: true })
4160
4160
  const getActivePlans = (0, import_react2.useCallback)(
4161
4161
  (plans) => {
4162
4162
  const activePlans = settings.mode === "edit" ? plans.slice() : plans.filter((plan) => {
4163
- if (options2.useSelectedPeriod) {
4163
+ if (options.useSelectedPeriod) {
4164
4164
  return activePeriod === "month" && plan.monthlyPrice || activePeriod === "year" && plan.yearlyPrice || plan.chargeType === ChargeType.oneTime;
4165
4165
  }
4166
4166
  return plan.monthlyPrice || plan.yearlyPrice || plan.chargeType === ChargeType.oneTime;
4167
4167
  });
4168
4168
  return activePlans.map((plan) => ({ ...plan, isSelected: false }));
4169
4169
  },
4170
- [activePeriod, options2.useSelectedPeriod, settings.mode]
4170
+ [activePeriod, options.useSelectedPeriod, settings.mode]
4171
4171
  );
4172
4172
  return (0, import_react2.useMemo)(() => {
4173
4173
  return {
@@ -4273,6 +4273,7 @@ var initialContext = {
4273
4273
  hydrateComponent: stub,
4274
4274
  hydrateExternal: stub,
4275
4275
  getUpcomingInvoice: stub,
4276
+ getCustomerBalance: stub,
4276
4277
  listInvoices: stub,
4277
4278
  createSetupIntent: stub,
4278
4279
  updatePaymentMethod: stub,
@@ -4285,7 +4286,8 @@ var initialContext = {
4285
4286
  setLayout: stub,
4286
4287
  setCheckoutState: stub,
4287
4288
  setData: stub,
4288
- updateSettings: stub
4289
+ updateSettings: stub,
4290
+ debug: stub
4289
4291
  };
4290
4292
  var EmbedContext = (0, import_react3.createContext)(initialContext);
4291
4293
 
@@ -4497,14 +4499,14 @@ var consoleLogger = {
4497
4499
  }
4498
4500
  };
4499
4501
  var Logger = class _Logger {
4500
- constructor(concreteLogger, options2 = {}) {
4501
- this.init(concreteLogger, options2);
4502
+ constructor(concreteLogger, options = {}) {
4503
+ this.init(concreteLogger, options);
4502
4504
  }
4503
- init(concreteLogger, options2 = {}) {
4504
- this.prefix = options2.prefix || "i18next:";
4505
+ init(concreteLogger, options = {}) {
4506
+ this.prefix = options.prefix || "i18next:";
4505
4507
  this.logger = concreteLogger || consoleLogger;
4506
- this.options = options2;
4507
- this.debug = options2.debug;
4508
+ this.options = options;
4509
+ this.debug = options.debug;
4508
4510
  }
4509
4511
  log(...args) {
4510
4512
  return this.forward(args, "log", "", true);
@@ -4531,10 +4533,10 @@ var Logger = class _Logger {
4531
4533
  ...this.options
4532
4534
  });
4533
4535
  }
4534
- clone(options2) {
4535
- options2 = options2 || this.options;
4536
- options2.prefix = options2.prefix || this.prefix;
4537
- return new _Logger(this.logger, options2);
4536
+ clone(options) {
4537
+ options = options || this.options;
4538
+ options.prefix = options.prefix || this.prefix;
4539
+ return new _Logger(this.logger, options);
4538
4540
  }
4539
4541
  };
4540
4542
  var baseLogger = new Logger();
@@ -4578,13 +4580,13 @@ var EventEmitter = class {
4578
4580
  }
4579
4581
  };
4580
4582
  var ResourceStore = class extends EventEmitter {
4581
- constructor(data, options2 = {
4583
+ constructor(data, options = {
4582
4584
  ns: ["translation"],
4583
4585
  defaultNS: "translation"
4584
4586
  }) {
4585
4587
  super();
4586
4588
  this.data = data || {};
4587
- this.options = options2;
4589
+ this.options = options;
4588
4590
  if (this.options.keySeparator === void 0) {
4589
4591
  this.options.keySeparator = ".";
4590
4592
  }
@@ -4603,9 +4605,9 @@ var ResourceStore = class extends EventEmitter {
4603
4605
  this.options.ns.splice(index, 1);
4604
4606
  }
4605
4607
  }
4606
- getResource(lng, ns, key, options2 = {}) {
4607
- const keySeparator = options2.keySeparator !== void 0 ? options2.keySeparator : this.options.keySeparator;
4608
- const ignoreJSONStructure = options2.ignoreJSONStructure !== void 0 ? options2.ignoreJSONStructure : this.options.ignoreJSONStructure;
4608
+ getResource(lng, ns, key, options = {}) {
4609
+ const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
4610
+ const ignoreJSONStructure = options.ignoreJSONStructure !== void 0 ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
4609
4611
  let path;
4610
4612
  if (lng.indexOf(".") > -1) {
4611
4613
  path = lng.split(".");
@@ -4630,10 +4632,10 @@ var ResourceStore = class extends EventEmitter {
4630
4632
  if (result || !ignoreJSONStructure || !isString(key)) return result;
4631
4633
  return deepFind(this.data?.[lng]?.[ns], key, keySeparator);
4632
4634
  }
4633
- addResource(lng, ns, key, value, options2 = {
4635
+ addResource(lng, ns, key, value, options = {
4634
4636
  silent: false
4635
4637
  }) {
4636
- const keySeparator = options2.keySeparator !== void 0 ? options2.keySeparator : this.options.keySeparator;
4638
+ const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
4637
4639
  let path = [lng, ns];
4638
4640
  if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
4639
4641
  if (lng.indexOf(".") > -1) {
@@ -4643,9 +4645,9 @@ var ResourceStore = class extends EventEmitter {
4643
4645
  }
4644
4646
  this.addNamespaces(ns);
4645
4647
  setPath(this.data, path, value);
4646
- if (!options2.silent) this.emit("added", lng, ns, key, value);
4648
+ if (!options.silent) this.emit("added", lng, ns, key, value);
4647
4649
  }
4648
- addResources(lng, ns, resources, options2 = {
4650
+ addResources(lng, ns, resources, options = {
4649
4651
  silent: false
4650
4652
  }) {
4651
4653
  for (const m2 in resources) {
@@ -4653,9 +4655,9 @@ var ResourceStore = class extends EventEmitter {
4653
4655
  silent: true
4654
4656
  });
4655
4657
  }
4656
- if (!options2.silent) this.emit("added", lng, ns, resources);
4658
+ if (!options.silent) this.emit("added", lng, ns, resources);
4657
4659
  }
4658
- addResourceBundle(lng, ns, resources, deep, overwrite, options2 = {
4660
+ addResourceBundle(lng, ns, resources, deep, overwrite, options = {
4659
4661
  silent: false,
4660
4662
  skipCopy: false
4661
4663
  }) {
@@ -4668,7 +4670,7 @@ var ResourceStore = class extends EventEmitter {
4668
4670
  }
4669
4671
  this.addNamespaces(ns);
4670
4672
  let pack = getPath(this.data, path) || {};
4671
- if (!options2.skipCopy) resources = JSON.parse(JSON.stringify(resources));
4673
+ if (!options.skipCopy) resources = JSON.parse(JSON.stringify(resources));
4672
4674
  if (deep) {
4673
4675
  deepExtend(pack, resources, overwrite);
4674
4676
  } else {
@@ -4678,7 +4680,7 @@ var ResourceStore = class extends EventEmitter {
4678
4680
  };
4679
4681
  }
4680
4682
  setPath(this.data, path, pack);
4681
- if (!options2.silent) this.emit("added", lng, ns, resources);
4683
+ if (!options.silent) this.emit("added", lng, ns, resources);
4682
4684
  }
4683
4685
  removeResourceBundle(lng, ns) {
4684
4686
  if (this.hasResourceBundle(lng, ns)) {
@@ -4711,9 +4713,9 @@ var postProcessor = {
4711
4713
  addPostProcessor(module2) {
4712
4714
  this.processors[module2.name] = module2;
4713
4715
  },
4714
- handle(processors, value, key, options2, translator) {
4716
+ handle(processors, value, key, options, translator) {
4715
4717
  processors.forEach((processor) => {
4716
- value = this.processors[processor]?.process(value, key, options2, translator) ?? value;
4718
+ value = this.processors[processor]?.process(value, key, options, translator) ?? value;
4717
4719
  });
4718
4720
  return value;
4719
4721
  }
@@ -4741,10 +4743,10 @@ function keysFromSelector(selector, opts) {
4741
4743
  var checkedLoadedFor = {};
4742
4744
  var shouldHandleAsObject = (res) => !isString(res) && typeof res !== "boolean" && typeof res !== "number";
4743
4745
  var Translator = class _Translator extends EventEmitter {
4744
- constructor(services, options2 = {}) {
4746
+ constructor(services, options = {}) {
4745
4747
  super();
4746
4748
  copy2(["resourceStore", "languageUtils", "pluralResolver", "interpolator", "backendConnector", "i18nFormat", "utils"], services, this);
4747
- this.options = options2;
4749
+ this.options = options;
4748
4750
  if (this.options.keySeparator === void 0) {
4749
4751
  this.options.keySeparator = ".";
4750
4752
  }
@@ -4794,12 +4796,15 @@ var Translator = class _Translator extends EventEmitter {
4794
4796
  if (typeof opt !== "object" && this.options.overloadTranslationOptionHandler) {
4795
4797
  opt = this.options.overloadTranslationOptionHandler(arguments);
4796
4798
  }
4797
- if (typeof options === "object") opt = {
4799
+ if (typeof opt === "object") opt = {
4798
4800
  ...opt
4799
4801
  };
4800
4802
  if (!opt) opt = {};
4801
4803
  if (keys == null) return "";
4802
- if (typeof keys === "function") keys = keysFromSelector(keys, opt);
4804
+ if (typeof keys === "function") keys = keysFromSelector(keys, {
4805
+ ...this.options,
4806
+ ...opt
4807
+ });
4803
4808
  if (!Array.isArray(keys)) keys = [String(keys)];
4804
4809
  const returnDetails = opt.returnDetails !== void 0 ? opt.returnDetails : this.options.returnDetails;
4805
4810
  const keySeparator = opt.keySeparator !== void 0 ? opt.keySeparator : this.options.keySeparator;
@@ -5120,16 +5125,16 @@ var Translator = class _Translator extends EventEmitter {
5120
5125
  isValidLookup(res) {
5121
5126
  return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
5122
5127
  }
5123
- getResource(code, ns, key, options2 = {}) {
5124
- if (this.i18nFormat?.getResource) return this.i18nFormat.getResource(code, ns, key, options2);
5125
- return this.resourceStore.getResource(code, ns, key, options2);
5128
+ getResource(code, ns, key, options = {}) {
5129
+ if (this.i18nFormat?.getResource) return this.i18nFormat.getResource(code, ns, key, options);
5130
+ return this.resourceStore.getResource(code, ns, key, options);
5126
5131
  }
5127
- getUsedParamsDetails(options2 = {}) {
5132
+ getUsedParamsDetails(options = {}) {
5128
5133
  const optionsKeys = ["defaultValue", "ordinal", "context", "replace", "lng", "lngs", "fallbackLng", "ns", "keySeparator", "nsSeparator", "returnObjects", "returnDetails", "joinArrays", "postProcess", "interpolation"];
5129
- const useOptionsReplaceForData = options2.replace && !isString(options2.replace);
5130
- let data = useOptionsReplaceForData ? options2.replace : options2;
5131
- if (useOptionsReplaceForData && typeof options2.count !== "undefined") {
5132
- data.count = options2.count;
5134
+ const useOptionsReplaceForData = options.replace && !isString(options.replace);
5135
+ let data = useOptionsReplaceForData ? options.replace : options;
5136
+ if (useOptionsReplaceForData && typeof options.count !== "undefined") {
5137
+ data.count = options.count;
5133
5138
  }
5134
5139
  if (this.options.interpolation.defaultVariables) {
5135
5140
  data = {
@@ -5147,10 +5152,10 @@ var Translator = class _Translator extends EventEmitter {
5147
5152
  }
5148
5153
  return data;
5149
5154
  }
5150
- static hasDefaultValue(options2) {
5155
+ static hasDefaultValue(options) {
5151
5156
  const prefix2 = "defaultValue";
5152
- for (const option in options2) {
5153
- if (Object.prototype.hasOwnProperty.call(options2, option) && prefix2 === option.substring(0, prefix2.length) && void 0 !== options2[option]) {
5157
+ for (const option in options) {
5158
+ if (Object.prototype.hasOwnProperty.call(options, option) && prefix2 === option.substring(0, prefix2.length) && void 0 !== options[option]) {
5154
5159
  return true;
5155
5160
  }
5156
5161
  }
@@ -5158,8 +5163,8 @@ var Translator = class _Translator extends EventEmitter {
5158
5163
  }
5159
5164
  };
5160
5165
  var LanguageUtil = class {
5161
- constructor(options2) {
5162
- this.options = options2;
5166
+ constructor(options) {
5167
+ this.options = options;
5163
5168
  this.supportedLngs = this.options.supportedLngs || false;
5164
5169
  this.logger = baseLogger.create("languageUtils");
5165
5170
  }
@@ -5280,9 +5285,9 @@ var dummyRule = {
5280
5285
  })
5281
5286
  };
5282
5287
  var PluralResolver = class {
5283
- constructor(languageUtils, options2 = {}) {
5288
+ constructor(languageUtils, options = {}) {
5284
5289
  this.languageUtils = languageUtils;
5285
- this.options = options2;
5290
+ this.options = options;
5286
5291
  this.logger = baseLogger.create("pluralResolver");
5287
5292
  this.pluralRulesCache = {};
5288
5293
  }
@@ -5292,9 +5297,9 @@ var PluralResolver = class {
5292
5297
  clearCache() {
5293
5298
  this.pluralRulesCache = {};
5294
5299
  }
5295
- getRule(code, options2 = {}) {
5300
+ getRule(code, options = {}) {
5296
5301
  const cleanedCode = getCleanedCode(code === "dev" ? "en" : code);
5297
- const type = options2.ordinal ? "ordinal" : "cardinal";
5302
+ const type = options.ordinal ? "ordinal" : "cardinal";
5298
5303
  const cacheKey = JSON.stringify({
5299
5304
  cleanedCode,
5300
5305
  type
@@ -5314,32 +5319,32 @@ var PluralResolver = class {
5314
5319
  }
5315
5320
  if (!code.match(/-|_/)) return dummyRule;
5316
5321
  const lngPart = this.languageUtils.getLanguagePartFromCode(code);
5317
- rule = this.getRule(lngPart, options2);
5322
+ rule = this.getRule(lngPart, options);
5318
5323
  }
5319
5324
  this.pluralRulesCache[cacheKey] = rule;
5320
5325
  return rule;
5321
5326
  }
5322
- needsPlural(code, options2 = {}) {
5323
- let rule = this.getRule(code, options2);
5324
- if (!rule) rule = this.getRule("dev", options2);
5327
+ needsPlural(code, options = {}) {
5328
+ let rule = this.getRule(code, options);
5329
+ if (!rule) rule = this.getRule("dev", options);
5325
5330
  return rule?.resolvedOptions().pluralCategories.length > 1;
5326
5331
  }
5327
- getPluralFormsOfKey(code, key, options2 = {}) {
5328
- return this.getSuffixes(code, options2).map((suffix) => `${key}${suffix}`);
5332
+ getPluralFormsOfKey(code, key, options = {}) {
5333
+ return this.getSuffixes(code, options).map((suffix) => `${key}${suffix}`);
5329
5334
  }
5330
- getSuffixes(code, options2 = {}) {
5331
- let rule = this.getRule(code, options2);
5332
- if (!rule) rule = this.getRule("dev", options2);
5335
+ getSuffixes(code, options = {}) {
5336
+ let rule = this.getRule(code, options);
5337
+ if (!rule) rule = this.getRule("dev", options);
5333
5338
  if (!rule) return [];
5334
- return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options2.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
5339
+ return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
5335
5340
  }
5336
- getSuffix(code, count, options2 = {}) {
5337
- const rule = this.getRule(code, options2);
5341
+ getSuffix(code, count, options = {}) {
5342
+ const rule = this.getRule(code, options);
5338
5343
  if (rule) {
5339
- return `${this.options.prepend}${options2.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
5344
+ return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
5340
5345
  }
5341
5346
  this.logger.warn(`no plural rule found for: ${code}`);
5342
- return this.getSuffix("dev", count, options2);
5347
+ return this.getSuffix("dev", count, options);
5343
5348
  }
5344
5349
  };
5345
5350
  var deepFindWithDefaults = (data, defaultData, key, keySeparator = ".", ignoreJSONStructure = true) => {
@@ -5352,14 +5357,14 @@ var deepFindWithDefaults = (data, defaultData, key, keySeparator = ".", ignoreJS
5352
5357
  };
5353
5358
  var regexSafe = (val) => val.replace(/\$/g, "$$$$");
5354
5359
  var Interpolator = class {
5355
- constructor(options2 = {}) {
5360
+ constructor(options = {}) {
5356
5361
  this.logger = baseLogger.create("interpolator");
5357
- this.options = options2;
5358
- this.format = options2?.interpolation?.format || ((value) => value);
5359
- this.init(options2);
5362
+ this.options = options;
5363
+ this.format = options?.interpolation?.format || ((value) => value);
5364
+ this.init(options);
5360
5365
  }
5361
- init(options2 = {}) {
5362
- if (!options2.interpolation) options2.interpolation = {
5366
+ init(options = {}) {
5367
+ if (!options.interpolation) options.interpolation = {
5363
5368
  escapeValue: true
5364
5369
  };
5365
5370
  const {
@@ -5380,7 +5385,7 @@ var Interpolator = class {
5380
5385
  nestingOptionsSeparator,
5381
5386
  maxReplaces,
5382
5387
  alwaysFormat
5383
- } = options2.interpolation;
5388
+ } = options.interpolation;
5384
5389
  this.escape = escape$1 !== void 0 ? escape$1 : escape;
5385
5390
  this.escapeValue = escapeValue !== void 0 ? escapeValue : true;
5386
5391
  this.useRawValueToEscape = useRawValueToEscape !== void 0 ? useRawValueToEscape : false;
@@ -5411,7 +5416,7 @@ var Interpolator = class {
5411
5416
  this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
5412
5417
  this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`);
5413
5418
  }
5414
- interpolate(str, data, lng, options2) {
5419
+ interpolate(str, data, lng, options) {
5415
5420
  let match2;
5416
5421
  let value;
5417
5422
  let replaces;
@@ -5420,7 +5425,7 @@ var Interpolator = class {
5420
5425
  if (key.indexOf(this.formatSeparator) < 0) {
5421
5426
  const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
5422
5427
  return this.alwaysFormat ? this.format(path, void 0, lng, {
5423
- ...options2,
5428
+ ...options,
5424
5429
  ...data,
5425
5430
  interpolationkey: key
5426
5431
  }) : path;
@@ -5429,14 +5434,14 @@ var Interpolator = class {
5429
5434
  const k2 = p2.shift().trim();
5430
5435
  const f2 = p2.join(this.formatSeparator).trim();
5431
5436
  return this.format(deepFindWithDefaults(data, defaultData, k2, this.options.keySeparator, this.options.ignoreJSONStructure), f2, lng, {
5432
- ...options2,
5437
+ ...options,
5433
5438
  ...data,
5434
5439
  interpolationkey: k2
5435
5440
  });
5436
5441
  };
5437
5442
  this.resetRegExp();
5438
- const missingInterpolationHandler = options2?.missingInterpolationHandler || this.options.missingInterpolationHandler;
5439
- const skipOnVariables = options2?.interpolation?.skipOnVariables !== void 0 ? options2.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
5443
+ const missingInterpolationHandler = options?.missingInterpolationHandler || this.options.missingInterpolationHandler;
5444
+ const skipOnVariables = options?.interpolation?.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
5440
5445
  const todos = [{
5441
5446
  regex: this.regexpUnescape,
5442
5447
  safeValue: (val) => regexSafe(val)
@@ -5451,9 +5456,9 @@ var Interpolator = class {
5451
5456
  value = handleFormat(matchedVar);
5452
5457
  if (value === void 0) {
5453
5458
  if (typeof missingInterpolationHandler === "function") {
5454
- const temp = missingInterpolationHandler(str, match2, options2);
5459
+ const temp = missingInterpolationHandler(str, match2, options);
5455
5460
  value = isString(temp) ? temp : "";
5456
- } else if (options2 && Object.prototype.hasOwnProperty.call(options2, matchedVar)) {
5461
+ } else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
5457
5462
  value = "";
5458
5463
  } else if (skipOnVariables) {
5459
5464
  value = match2[0];
@@ -5481,7 +5486,7 @@ var Interpolator = class {
5481
5486
  });
5482
5487
  return str;
5483
5488
  }
5484
- nest(str, fc, options2 = {}) {
5489
+ nest(str, fc, options = {}) {
5485
5490
  let match2;
5486
5491
  let value;
5487
5492
  let clonedOptions;
@@ -5513,7 +5518,7 @@ var Interpolator = class {
5513
5518
  while (match2 = this.nestingRegexp.exec(str)) {
5514
5519
  let formatters = [];
5515
5520
  clonedOptions = {
5516
- ...options2
5521
+ ...options
5517
5522
  };
5518
5523
  clonedOptions = clonedOptions.replace && !isString(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
5519
5524
  clonedOptions.applyPostProcessor = false;
@@ -5531,8 +5536,8 @@ var Interpolator = class {
5531
5536
  value = "";
5532
5537
  }
5533
5538
  if (formatters.length) {
5534
- value = formatters.reduce((v2, f2) => this.format(v2, f2, options2.lng, {
5535
- ...options2,
5539
+ value = formatters.reduce((v2, f2) => this.format(v2, f2, options.lng, {
5540
+ ...options,
5536
5541
  interpolationkey: match2[1].trim()
5537
5542
  }), value.trim());
5538
5543
  }
@@ -5594,16 +5599,16 @@ var createCachedFormatter = (fn) => {
5594
5599
  };
5595
5600
  var createNonCachedFormatter = (fn) => (v2, l2, o2) => fn(getCleanedCode(l2), o2)(v2);
5596
5601
  var Formatter = class {
5597
- constructor(options2 = {}) {
5602
+ constructor(options = {}) {
5598
5603
  this.logger = baseLogger.create("formatter");
5599
- this.options = options2;
5600
- this.init(options2);
5604
+ this.options = options;
5605
+ this.init(options);
5601
5606
  }
5602
- init(services, options2 = {
5607
+ init(services, options = {
5603
5608
  interpolation: {}
5604
5609
  }) {
5605
- this.formatSeparator = options2.interpolation.formatSeparator || ",";
5606
- const cf = options2.cacheInBuiltFormats ? createCachedFormatter : createNonCachedFormatter;
5610
+ this.formatSeparator = options.interpolation.formatSeparator || ",";
5611
+ const cf = options.cacheInBuiltFormats ? createCachedFormatter : createNonCachedFormatter;
5607
5612
  this.formats = {
5608
5613
  number: cf((lng, opt) => {
5609
5614
  const formatter = new Intl.NumberFormat(lng, {
@@ -5644,7 +5649,7 @@ var Formatter = class {
5644
5649
  addCached(name, fc) {
5645
5650
  this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
5646
5651
  }
5647
- format(value, format, lng, options2 = {}) {
5652
+ format(value, format, lng, options = {}) {
5648
5653
  const formats = format.split(this.formatSeparator);
5649
5654
  if (formats.length > 1 && formats[0].indexOf("(") > 1 && formats[0].indexOf(")") < 0 && formats.find((f2) => f2.indexOf(")") > -1)) {
5650
5655
  const lastIndex = formats.findIndex((f2) => f2.indexOf(")") > -1);
@@ -5658,11 +5663,11 @@ var Formatter = class {
5658
5663
  if (this.formats[formatName]) {
5659
5664
  let formatted = mem;
5660
5665
  try {
5661
- const valOptions = options2?.formatParams?.[options2.interpolationkey] || {};
5662
- const l2 = valOptions.locale || valOptions.lng || options2.locale || options2.lng || lng;
5666
+ const valOptions = options?.formatParams?.[options.interpolationkey] || {};
5667
+ const l2 = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
5663
5668
  formatted = this.formats[formatName](mem, l2, {
5664
5669
  ...formatOptions,
5665
- ...options2,
5670
+ ...options,
5666
5671
  ...valOptions
5667
5672
  });
5668
5673
  } catch (error) {
@@ -5684,24 +5689,24 @@ var removePending = (q2, name) => {
5684
5689
  }
5685
5690
  };
5686
5691
  var Connector = class extends EventEmitter {
5687
- constructor(backend, store, services, options2 = {}) {
5692
+ constructor(backend, store, services, options = {}) {
5688
5693
  super();
5689
5694
  this.backend = backend;
5690
5695
  this.store = store;
5691
5696
  this.services = services;
5692
5697
  this.languageUtils = services.languageUtils;
5693
- this.options = options2;
5698
+ this.options = options;
5694
5699
  this.logger = baseLogger.create("backendConnector");
5695
5700
  this.waitingReads = [];
5696
- this.maxParallelReads = options2.maxParallelReads || 10;
5701
+ this.maxParallelReads = options.maxParallelReads || 10;
5697
5702
  this.readingCalls = 0;
5698
- this.maxRetries = options2.maxRetries >= 0 ? options2.maxRetries : 5;
5699
- this.retryTimeout = options2.retryTimeout >= 1 ? options2.retryTimeout : 350;
5703
+ this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
5704
+ this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
5700
5705
  this.state = {};
5701
5706
  this.queue = [];
5702
- this.backend?.init?.(services, options2.backend, options2);
5707
+ this.backend?.init?.(services, options.backend, options);
5703
5708
  }
5704
- queueLoad(languages, namespaces, options2, callback) {
5709
+ queueLoad(languages, namespaces, options, callback) {
5705
5710
  const toLoad = {};
5706
5711
  const pending = {};
5707
5712
  const toLoadLanguages = {};
@@ -5710,7 +5715,7 @@ var Connector = class extends EventEmitter {
5710
5715
  let hasAllNamespaces = true;
5711
5716
  namespaces.forEach((ns) => {
5712
5717
  const name = `${lng}|${ns}`;
5713
- if (!options2.reload && this.store.hasResourceBundle(lng, ns)) {
5718
+ if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
5714
5719
  this.state[name] = 2;
5715
5720
  } else if (this.state[name] < 0) ;
5716
5721
  else if (this.state[name] === 1) {
@@ -5823,14 +5828,14 @@ var Connector = class extends EventEmitter {
5823
5828
  }
5824
5829
  return fc(lng, ns, resolver);
5825
5830
  }
5826
- prepareLoading(languages, namespaces, options2 = {}, callback) {
5831
+ prepareLoading(languages, namespaces, options = {}, callback) {
5827
5832
  if (!this.backend) {
5828
5833
  this.logger.warn("No backend was added via i18next.use. Will not load resources.");
5829
5834
  return callback && callback();
5830
5835
  }
5831
5836
  if (isString(languages)) languages = this.languageUtils.toResolveHierarchy(languages);
5832
5837
  if (isString(namespaces)) namespaces = [namespaces];
5833
- const toLoad = this.queueLoad(languages, namespaces, options2, callback);
5838
+ const toLoad = this.queueLoad(languages, namespaces, options, callback);
5834
5839
  if (!toLoad.toLoad.length) {
5835
5840
  if (!toLoad.pending.length) callback();
5836
5841
  return null;
@@ -5857,7 +5862,7 @@ var Connector = class extends EventEmitter {
5857
5862
  this.loaded(name, err2, data);
5858
5863
  });
5859
5864
  }
5860
- saveMissing(languages, namespace, key, fallbackValue, isUpdate, options2 = {}, clb = () => {
5865
+ saveMissing(languages, namespace, key, fallbackValue, isUpdate, options = {}, clb = () => {
5861
5866
  }) {
5862
5867
  if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(namespace)) {
5863
5868
  this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
@@ -5866,7 +5871,7 @@ var Connector = class extends EventEmitter {
5866
5871
  if (key === void 0 || key === null || key === "") return;
5867
5872
  if (this.backend?.create) {
5868
5873
  const opts = {
5869
- ...options2,
5874
+ ...options,
5870
5875
  isUpdate
5871
5876
  };
5872
5877
  const fc = this.backend.create.bind(this.backend);
@@ -5933,9 +5938,9 @@ var get = () => ({
5933
5938
  if (isString(args[1])) ret.defaultValue = args[1];
5934
5939
  if (isString(args[2])) ret.tDescription = args[2];
5935
5940
  if (typeof args[2] === "object" || typeof args[3] === "object") {
5936
- const options2 = args[3] || args[2];
5937
- Object.keys(options2).forEach((key) => {
5938
- ret[key] = options2[key];
5941
+ const options = args[3] || args[2];
5942
+ Object.keys(options).forEach((key) => {
5943
+ ret[key] = options[key];
5939
5944
  });
5940
5945
  }
5941
5946
  return ret;
@@ -5955,15 +5960,15 @@ var get = () => ({
5955
5960
  },
5956
5961
  cacheInBuiltFormats: true
5957
5962
  });
5958
- var transformOptions = (options2) => {
5959
- if (isString(options2.ns)) options2.ns = [options2.ns];
5960
- if (isString(options2.fallbackLng)) options2.fallbackLng = [options2.fallbackLng];
5961
- if (isString(options2.fallbackNS)) options2.fallbackNS = [options2.fallbackNS];
5962
- if (options2.supportedLngs?.indexOf?.("cimode") < 0) {
5963
- options2.supportedLngs = options2.supportedLngs.concat(["cimode"]);
5963
+ var transformOptions = (options) => {
5964
+ if (isString(options.ns)) options.ns = [options.ns];
5965
+ if (isString(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
5966
+ if (isString(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
5967
+ if (options.supportedLngs?.indexOf?.("cimode") < 0) {
5968
+ options.supportedLngs = options.supportedLngs.concat(["cimode"]);
5964
5969
  }
5965
- if (typeof options2.initImmediate === "boolean") options2.initAsync = options2.initImmediate;
5966
- return options2;
5970
+ if (typeof options.initImmediate === "boolean") options.initAsync = options.initImmediate;
5971
+ return options;
5967
5972
  };
5968
5973
  var noop = () => {
5969
5974
  };
@@ -5976,53 +5981,53 @@ var bindMemberFunctions = (inst) => {
5976
5981
  });
5977
5982
  };
5978
5983
  var I18n = class _I18n extends EventEmitter {
5979
- constructor(options2 = {}, callback) {
5984
+ constructor(options = {}, callback) {
5980
5985
  super();
5981
- this.options = transformOptions(options2);
5986
+ this.options = transformOptions(options);
5982
5987
  this.services = {};
5983
5988
  this.logger = baseLogger;
5984
5989
  this.modules = {
5985
5990
  external: []
5986
5991
  };
5987
5992
  bindMemberFunctions(this);
5988
- if (callback && !this.isInitialized && !options2.isClone) {
5993
+ if (callback && !this.isInitialized && !options.isClone) {
5989
5994
  if (!this.options.initAsync) {
5990
- this.init(options2, callback);
5995
+ this.init(options, callback);
5991
5996
  return this;
5992
5997
  }
5993
5998
  setTimeout(() => {
5994
- this.init(options2, callback);
5999
+ this.init(options, callback);
5995
6000
  }, 0);
5996
6001
  }
5997
6002
  }
5998
- init(options2 = {}, callback) {
6003
+ init(options = {}, callback) {
5999
6004
  this.isInitializing = true;
6000
- if (typeof options2 === "function") {
6001
- callback = options2;
6002
- options2 = {};
6005
+ if (typeof options === "function") {
6006
+ callback = options;
6007
+ options = {};
6003
6008
  }
6004
- if (options2.defaultNS == null && options2.ns) {
6005
- if (isString(options2.ns)) {
6006
- options2.defaultNS = options2.ns;
6007
- } else if (options2.ns.indexOf("translation") < 0) {
6008
- options2.defaultNS = options2.ns[0];
6009
+ if (options.defaultNS == null && options.ns) {
6010
+ if (isString(options.ns)) {
6011
+ options.defaultNS = options.ns;
6012
+ } else if (options.ns.indexOf("translation") < 0) {
6013
+ options.defaultNS = options.ns[0];
6009
6014
  }
6010
6015
  }
6011
6016
  const defOpts = get();
6012
6017
  this.options = {
6013
6018
  ...defOpts,
6014
6019
  ...this.options,
6015
- ...transformOptions(options2)
6020
+ ...transformOptions(options)
6016
6021
  };
6017
6022
  this.options.interpolation = {
6018
6023
  ...defOpts.interpolation,
6019
6024
  ...this.options.interpolation
6020
6025
  };
6021
- if (options2.keySeparator !== void 0) {
6022
- this.options.userDefinedKeySeparator = options2.keySeparator;
6026
+ if (options.keySeparator !== void 0) {
6027
+ this.options.userDefinedKeySeparator = options.keySeparator;
6023
6028
  }
6024
- if (options2.nsSeparator !== void 0) {
6025
- this.options.userDefinedNsSeparator = options2.nsSeparator;
6029
+ if (options.nsSeparator !== void 0) {
6030
+ this.options.userDefinedNsSeparator = options.nsSeparator;
6026
6031
  }
6027
6032
  const createClassOnDemand = (ClassOrObject) => {
6028
6033
  if (!ClassOrObject) return null;
@@ -6287,8 +6292,18 @@ var I18n = class _I18n extends EventEmitter {
6287
6292
  const keySeparator = this.options.keySeparator || ".";
6288
6293
  let resultKey;
6289
6294
  if (o2.keyPrefix && Array.isArray(key)) {
6290
- resultKey = key.map((k2) => `${o2.keyPrefix}${keySeparator}${k2}`);
6295
+ resultKey = key.map((k2) => {
6296
+ if (typeof k2 === "function") k2 = keysFromSelector(k2, {
6297
+ ...this.options,
6298
+ ...opts
6299
+ });
6300
+ return `${o2.keyPrefix}${keySeparator}${k2}`;
6301
+ });
6291
6302
  } else {
6303
+ if (typeof key === "function") key = keysFromSelector(key, {
6304
+ ...this.options,
6305
+ ...opts
6306
+ });
6292
6307
  resultKey = o2.keyPrefix ? `${o2.keyPrefix}${keySeparator}${key}` : key;
6293
6308
  }
6294
6309
  return this.t(resultKey, o2);
@@ -6311,7 +6326,7 @@ var I18n = class _I18n extends EventEmitter {
6311
6326
  setDefaultNamespace(ns) {
6312
6327
  this.options.defaultNS = ns;
6313
6328
  }
6314
- hasLoadedNamespace(ns, options2 = {}) {
6329
+ hasLoadedNamespace(ns, options = {}) {
6315
6330
  if (!this.isInitialized) {
6316
6331
  this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
6317
6332
  return false;
@@ -6320,7 +6335,7 @@ var I18n = class _I18n extends EventEmitter {
6320
6335
  this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages);
6321
6336
  return false;
6322
6337
  }
6323
- const lng = options2.lng || this.resolvedLanguage || this.languages[0];
6338
+ const lng = options.lng || this.resolvedLanguage || this.languages[0];
6324
6339
  const fallbackLng = this.options ? this.options.fallbackLng : false;
6325
6340
  const lastLng = this.languages[this.languages.length - 1];
6326
6341
  if (lng.toLowerCase() === "cimode") return true;
@@ -6328,8 +6343,8 @@ var I18n = class _I18n extends EventEmitter {
6328
6343
  const loadState = this.services.backendConnector.state[`${l2}|${n}`];
6329
6344
  return loadState === -1 || loadState === 0 || loadState === 2;
6330
6345
  };
6331
- if (options2.precheck) {
6332
- const preResult = options2.precheck(this, loadNotPending);
6346
+ if (options.precheck) {
6347
+ const preResult = options.precheck(this, loadNotPending);
6333
6348
  if (preResult !== void 0) return preResult;
6334
6349
  }
6335
6350
  if (this.hasResourceBundle(lng, ns)) return true;
@@ -6385,22 +6400,22 @@ var I18n = class _I18n extends EventEmitter {
6385
6400
  if (lng.toLowerCase().indexOf("-latn") > 1) return "ltr";
6386
6401
  return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
6387
6402
  }
6388
- static createInstance(options2 = {}, callback) {
6389
- return new _I18n(options2, callback);
6403
+ static createInstance(options = {}, callback) {
6404
+ return new _I18n(options, callback);
6390
6405
  }
6391
- cloneInstance(options2 = {}, callback = noop) {
6392
- const forkResourceStore = options2.forkResourceStore;
6393
- if (forkResourceStore) delete options2.forkResourceStore;
6406
+ cloneInstance(options = {}, callback = noop) {
6407
+ const forkResourceStore = options.forkResourceStore;
6408
+ if (forkResourceStore) delete options.forkResourceStore;
6394
6409
  const mergedOptions = {
6395
6410
  ...this.options,
6396
- ...options2,
6411
+ ...options,
6397
6412
  ...{
6398
6413
  isClone: true
6399
6414
  }
6400
6415
  };
6401
6416
  const clone = new _I18n(mergedOptions);
6402
- if (options2.debug !== void 0 || options2.prefix !== void 0) {
6403
- clone.logger = clone.logger.clone(options2);
6417
+ if (options.debug !== void 0 || options.prefix !== void 0) {
6418
+ clone.logger = clone.logger.clone(options);
6404
6419
  }
6405
6420
  const membersToCopy = ["store", "services", "language"];
6406
6421
  membersToCopy.forEach((m2) => {
@@ -6521,7 +6536,7 @@ var loadLanguages2 = (i18n, lng, ns, cb) => {
6521
6536
  });
6522
6537
  i18n.loadLanguages(lng, loadedClb(i18n, cb));
6523
6538
  };
6524
- var hasLoadedNamespace2 = (ns, i18n, options2 = {}) => {
6539
+ var hasLoadedNamespace2 = (ns, i18n, options = {}) => {
6525
6540
  if (!i18n.languages || !i18n.languages.length) {
6526
6541
  warnOnce(i18n, "NO_LANGUAGES", "i18n.languages were undefined or empty", {
6527
6542
  languages: i18n.languages
@@ -6529,9 +6544,9 @@ var hasLoadedNamespace2 = (ns, i18n, options2 = {}) => {
6529
6544
  return true;
6530
6545
  }
6531
6546
  return i18n.hasLoadedNamespace(ns, {
6532
- lng: options2.lng,
6547
+ lng: options.lng,
6533
6548
  precheck: (i18nInstance2, loadNotPending) => {
6534
- if (options2.bindI18n && options2.bindI18n.indexOf("languageChanging") > -1 && i18nInstance2.services.backendConnector.backend && i18nInstance2.isLanguageChangingTo && !loadNotPending(i18nInstance2.isLanguageChangingTo, ns)) return false;
6549
+ if (options.bindI18n && options.bindI18n.indexOf("languageChanging") > -1 && i18nInstance2.services.backendConnector.backend && i18nInstance2.isLanguageChangingTo && !loadNotPending(i18nInstance2.isLanguageChangingTo, ns)) return false;
6535
6550
  }
6536
6551
  });
6537
6552
  };
@@ -6576,10 +6591,10 @@ var defaultOptions = {
6576
6591
  useSuspense: true,
6577
6592
  unescape
6578
6593
  };
6579
- var setDefaults = (options2 = {}) => {
6594
+ var setDefaults = (options = {}) => {
6580
6595
  defaultOptions = {
6581
6596
  ...defaultOptions,
6582
- ...options2
6597
+ ...options
6583
6598
  };
6584
6599
  };
6585
6600
  var getDefaults = () => defaultOptions;
@@ -6766,8 +6781,10 @@ var en_default = {
6766
6781
  "Choose add-on": "Choose add-on",
6767
6782
  "Choose plan": "Choose plan",
6768
6783
  "Choose your base plan": "Choose your base plan",
6769
- "Credits to be applied to future invoices": "Credits to be applied to future invoices",
6784
+ "Credit bundles": "Credit bundles",
6770
6785
  Credits: "Credits",
6786
+ "Credits in plan": "Credits in plan",
6787
+ "Credits to be applied to future invoices": "Credits to be applied to future invoices",
6771
6788
  "Current plan": "Current plan",
6772
6789
  "Current usage exceeds the limit of this plan.": "Current usage exceeds the limit of this plan.",
6773
6790
  "Currently using": "Currently using {{quantity}} {{unit}}",
@@ -6818,8 +6835,10 @@ var en_default = {
6818
6835
  "Please provide an access token.": "Please provide an access token.",
6819
6836
  "Powered by": "Powered by",
6820
6837
  "Price by unit based on final tier reached.": "Price by unit based on final tier reached.",
6838
+ "Promotional credits": "Promotional credits",
6821
6839
  Proration: "Proration",
6822
6840
  "Quantity to pay for in advance": "Quantity to pay for in advance",
6841
+ "Remaining balance": "Remaining balance",
6823
6842
  "Remove add-on": "Remove add-on",
6824
6843
  Resets: "Resets {{date}}",
6825
6844
  "Save payment method": "Save payment method",
@@ -7103,12 +7122,12 @@ var randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.ra
7103
7122
  var native_default = { randomUUID };
7104
7123
 
7105
7124
  // node_modules/uuid/dist/esm-browser/v4.js
7106
- function v4(options2, buf, offset) {
7107
- if (native_default.randomUUID && !buf && !options2) {
7125
+ function v4(options, buf, offset) {
7126
+ if (native_default.randomUUID && !buf && !options) {
7108
7127
  return native_default.randomUUID();
7109
7128
  }
7110
- options2 = options2 || {};
7111
- const rnds = options2.random ?? options2.rng?.() ?? rng();
7129
+ options = options || {};
7130
+ const rnds = options.random ?? options.rng?.() ?? rng();
7112
7131
  if (rnds.length < 16) {
7113
7132
  throw new Error("Random bytes length must be >= 16");
7114
7133
  }
@@ -8532,6 +8551,21 @@ function ComponentCapabilitiesFromJSONTyped(json, ignoreDiscriminator) {
8532
8551
  };
8533
8552
  }
8534
8553
 
8554
+ // src/api/checkoutexternal/models/ComponentCheckoutSettings.ts
8555
+ function ComponentCheckoutSettingsFromJSON(json) {
8556
+ return ComponentCheckoutSettingsFromJSONTyped(json, false);
8557
+ }
8558
+ function ComponentCheckoutSettingsFromJSONTyped(json, ignoreDiscriminator) {
8559
+ if (json == null) {
8560
+ return json;
8561
+ }
8562
+ return {
8563
+ collectAddress: json["collect_address"],
8564
+ collectEmail: json["collect_email"],
8565
+ collectPhone: json["collect_phone"]
8566
+ };
8567
+ }
8568
+
8535
8569
  // src/api/checkoutexternal/models/PlanDetailResponseData.ts
8536
8570
  function PlanDetailResponseDataFromJSON(json) {
8537
8571
  return PlanDetailResponseDataFromJSONTyped(json, false);
@@ -8729,6 +8763,9 @@ function ComponentHydrateResponseDataFromJSONTyped(json, ignoreDiscriminator) {
8729
8763
  CompatiblePlansFromJSON
8730
8764
  ),
8731
8765
  capabilities: json["capabilities"] == null ? void 0 : ComponentCapabilitiesFromJSON(json["capabilities"]),
8766
+ checkoutSettings: ComponentCheckoutSettingsFromJSON(
8767
+ json["checkout_settings"]
8768
+ ),
8732
8769
  company: json["company"] == null ? void 0 : CompanyDetailResponseDataFromJSON(json["company"]),
8733
8770
  component: json["component"] == null ? void 0 : ComponentResponseDataFromJSON(json["component"]),
8734
8771
  creditBundles: json["credit_bundles"].map(
@@ -10479,18 +10516,18 @@ var EmbedProvider = ({
10479
10516
  children,
10480
10517
  apiKey,
10481
10518
  apiConfig,
10482
- ...options2
10519
+ ...options
10483
10520
  }) => {
10484
10521
  const sessionIdRef = (0, import_react12.useRef)(v4_default());
10485
10522
  const styleRef = (0, import_react12.useRef)(null);
10486
- const [state, dispatch] = (0, import_react12.useReducer)(reducer, options2, (opts) => {
10523
+ const [state, dispatch] = (0, import_react12.useReducer)(reducer, options, (opts) => {
10487
10524
  const providedState = { settings: opts.settings || {} };
10488
10525
  const resolvedState = (0, import_merge2.default)({}, initialState, providedState);
10489
10526
  return resolvedState;
10490
10527
  });
10491
10528
  const customHeaders = (0, import_react12.useMemo)(
10492
10529
  () => ({
10493
- "X-Schematic-Components-Version": "1.4.1",
10530
+ "X-Schematic-Components-Version": "1.4.3",
10494
10531
  "X-Schematic-Session-ID": sessionIdRef.current
10495
10532
  }),
10496
10533
  []
@@ -10498,11 +10535,11 @@ var EmbedProvider = ({
10498
10535
  const [api, setApi] = (0, import_react12.useState)({});
10499
10536
  const debug = (0, import_react12.useCallback)(
10500
10537
  (message, ...args) => {
10501
- if (options2.debug) {
10538
+ if (options.debug) {
10502
10539
  console.debug(`[Schematic] ${message}`, ...args);
10503
10540
  }
10504
10541
  },
10505
- [options2.debug]
10542
+ [options.debug]
10506
10543
  );
10507
10544
  const hydratePublic = (0, import_react12.useCallback)(async () => {
10508
10545
  dispatch({ type: "HYDRATE_STARTED" });
@@ -10523,7 +10560,7 @@ var EmbedProvider = ({
10523
10560
  }
10524
10561
  }, [api.public]);
10525
10562
  const debouncedHydratePublic = (0, import_react12.useMemo)(
10526
- () => (0, import_debounce.default)(hydratePublic, FETCH_DEBOUNCE_TIMEOUT, debounceOptions),
10563
+ () => (0, import_debounce.default)(hydratePublic, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
10527
10564
  [hydratePublic]
10528
10565
  );
10529
10566
  const hydrate = (0, import_react12.useCallback)(async () => {
@@ -10545,7 +10582,7 @@ var EmbedProvider = ({
10545
10582
  }
10546
10583
  }, [api.checkout]);
10547
10584
  const debouncedHydrate = (0, import_react12.useMemo)(
10548
- () => (0, import_debounce.default)(hydrate, FETCH_DEBOUNCE_TIMEOUT, debounceOptions),
10585
+ () => (0, import_debounce.default)(hydrate, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
10549
10586
  [hydrate]
10550
10587
  );
10551
10588
  const hydrateComponent = (0, import_react12.useCallback)(
@@ -10572,7 +10609,7 @@ var EmbedProvider = ({
10572
10609
  [api.checkout]
10573
10610
  );
10574
10611
  const debouncedHydrateComponent = (0, import_react12.useMemo)(
10575
- () => (0, import_debounce.default)(hydrateComponent, FETCH_DEBOUNCE_TIMEOUT, debounceOptions),
10612
+ () => (0, import_debounce.default)(hydrateComponent, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
10576
10613
  [hydrateComponent]
10577
10614
  );
10578
10615
  const hydrateExternal = (0, import_react12.useCallback)(async function(fn) {
@@ -10592,14 +10629,14 @@ var EmbedProvider = ({
10592
10629
  }
10593
10630
  }, []);
10594
10631
  const debouncedHydrateExternal = (0, import_react12.useMemo)(
10595
- () => (0, import_debounce.default)(hydrateExternal, FETCH_DEBOUNCE_TIMEOUT, debounceOptions),
10632
+ () => (0, import_debounce.default)(hydrateExternal, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
10596
10633
  [hydrateExternal]
10597
10634
  );
10598
10635
  const createSetupIntent = (0, import_react12.useCallback)(async () => {
10599
10636
  return api.checkout?.createSetupIntent();
10600
10637
  }, [api.checkout]);
10601
10638
  const debouncedCreateSetupIntent = (0, import_react12.useMemo)(
10602
- () => (0, import_debounce.default)(createSetupIntent, FETCH_DEBOUNCE_TIMEOUT, debounceOptions),
10639
+ () => (0, import_debounce.default)(createSetupIntent, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
10603
10640
  [createSetupIntent]
10604
10641
  );
10605
10642
  const updatePaymentMethod = (0, import_react12.useCallback)(
@@ -10618,7 +10655,7 @@ var EmbedProvider = ({
10618
10655
  [api.checkout]
10619
10656
  );
10620
10657
  const debouncedUpdatePaymentMethod = (0, import_react12.useMemo)(
10621
- () => (0, import_debounce.default)(updatePaymentMethod, FETCH_DEBOUNCE_TIMEOUT, debounceOptions),
10658
+ () => (0, import_debounce.default)(updatePaymentMethod, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
10622
10659
  [updatePaymentMethod]
10623
10660
  );
10624
10661
  const deletePaymentMethod = (0, import_react12.useCallback)(
@@ -10637,7 +10674,7 @@ var EmbedProvider = ({
10637
10674
  [api.checkout]
10638
10675
  );
10639
10676
  const debouncedDeletePaymentMethod = (0, import_react12.useMemo)(
10640
- () => (0, import_debounce.default)(deletePaymentMethod, FETCH_DEBOUNCE_TIMEOUT, debounceOptions),
10677
+ () => (0, import_debounce.default)(deletePaymentMethod, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
10641
10678
  [deletePaymentMethod]
10642
10679
  );
10643
10680
  const checkout = (0, import_react12.useCallback)(
@@ -10656,7 +10693,7 @@ var EmbedProvider = ({
10656
10693
  [api.checkout]
10657
10694
  );
10658
10695
  const debouncedCheckout = (0, import_react12.useMemo)(
10659
- () => (0, import_debounce.default)(checkout, FETCH_DEBOUNCE_TIMEOUT, debounceOptions),
10696
+ () => (0, import_debounce.default)(checkout, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
10660
10697
  [checkout]
10661
10698
  );
10662
10699
  const previewCheckout = (0, import_react12.useCallback)(
@@ -10666,7 +10703,12 @@ var EmbedProvider = ({
10666
10703
  [api.checkout]
10667
10704
  );
10668
10705
  const debouncedPreviewCheckout = (0, import_react12.useMemo)(
10669
- () => (0, import_debounce.default)(previewCheckout, FETCH_DEBOUNCE_TIMEOUT, debounceOptions),
10706
+ () => (0, import_debounce.default)(previewCheckout, FETCH_DEBOUNCE_TIMEOUT, {
10707
+ // invoke immediately for minimal latency
10708
+ leading: true,
10709
+ // but also ensure latest data is fetched
10710
+ trailing: true
10711
+ }),
10670
10712
  [previewCheckout]
10671
10713
  );
10672
10714
  const unsubscribe = (0, import_react12.useCallback)(async () => {
@@ -10680,7 +10722,7 @@ var EmbedProvider = ({
10680
10722
  return response;
10681
10723
  }, [api.checkout]);
10682
10724
  const debouncedUnsubscribe = (0, import_react12.useMemo)(
10683
- () => (0, import_debounce.default)(unsubscribe, FETCH_DEBOUNCE_TIMEOUT, debounceOptions),
10725
+ () => (0, import_debounce.default)(unsubscribe, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
10684
10726
  [unsubscribe]
10685
10727
  );
10686
10728
  const getUpcomingInvoice = (0, import_react12.useCallback)(
@@ -10692,19 +10734,30 @@ var EmbedProvider = ({
10692
10734
  [api.checkout]
10693
10735
  );
10694
10736
  const debouncedGetUpcomingInvoice = (0, import_react12.useMemo)(
10695
- () => (0, import_debounce.default)(getUpcomingInvoice, FETCH_DEBOUNCE_TIMEOUT, debounceOptions),
10737
+ () => (0, import_debounce.default)(getUpcomingInvoice, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
10696
10738
  [getUpcomingInvoice]
10697
10739
  );
10740
+ const getCustomerBalance = (0, import_react12.useCallback)(async () => {
10741
+ return api.checkout?.fetchCustomerBalance();
10742
+ }, [api.checkout]);
10743
+ const debouncedGetCustomerBalance = (0, import_react12.useMemo)(
10744
+ () => (0, import_debounce.default)(getCustomerBalance, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
10745
+ [getCustomerBalance]
10746
+ );
10698
10747
  const listInvoices = (0, import_react12.useCallback)(async () => {
10699
10748
  return api.checkout?.listInvoices();
10700
10749
  }, [api.checkout]);
10701
10750
  const debouncedListInvoices = (0, import_react12.useMemo)(
10702
- () => (0, import_debounce.default)(listInvoices, FETCH_DEBOUNCE_TIMEOUT, debounceOptions),
10751
+ () => (0, import_debounce.default)(listInvoices, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
10703
10752
  [listInvoices]
10704
10753
  );
10705
- const setError = (0, import_react12.useCallback)((error) => {
10706
- dispatch({ type: "ERROR", error });
10707
- }, []);
10754
+ const setError = (0, import_react12.useCallback)(
10755
+ (error) => {
10756
+ debug(error.message);
10757
+ dispatch({ type: "ERROR", error });
10758
+ },
10759
+ [debug]
10760
+ );
10708
10761
  const setAccessToken = (0, import_react12.useCallback)((token2) => {
10709
10762
  dispatch({ type: "SET_ACCESS_TOKEN", token: token2 });
10710
10763
  }, []);
@@ -10712,8 +10765,8 @@ var EmbedProvider = ({
10712
10765
  dispatch({ type: "SET_DATA", data });
10713
10766
  }, []);
10714
10767
  const updateSettings = (0, import_react12.useCallback)(
10715
- (settings = {}, options3) => {
10716
- dispatch({ type: "UPDATE_SETTINGS", settings, update: options3?.update });
10768
+ (settings = {}, options2) => {
10769
+ dispatch({ type: "UPDATE_SETTINGS", settings, update: options2?.update });
10717
10770
  },
10718
10771
  []
10719
10772
  );
@@ -10729,13 +10782,13 @@ var EmbedProvider = ({
10729
10782
  );
10730
10783
  if (element) {
10731
10784
  styleRef.current = element;
10732
- return;
10785
+ } else {
10786
+ const style = document.createElement("link");
10787
+ style.id = "schematic-fonts";
10788
+ style.rel = "stylesheet";
10789
+ document.head.appendChild(style);
10790
+ styleRef.current = style;
10733
10791
  }
10734
- const style = document.createElement("link");
10735
- style.id = "schematic-fonts";
10736
- style.rel = "stylesheet";
10737
- document.head.appendChild(style);
10738
- styleRef.current = style;
10739
10792
  const darkModeQuery = matchMedia("(prefers-color-scheme: dark)");
10740
10793
  const colorMode = darkModeQuery.matches ? "dark" : "light";
10741
10794
  dispatch({
@@ -10746,13 +10799,17 @@ var EmbedProvider = ({
10746
10799
  }
10747
10800
  }
10748
10801
  });
10749
- darkModeQuery.addEventListener("change", (event) => {
10802
+ function darkModeQueryHandler(event) {
10750
10803
  const newColorMode = event.matches ? "dark" : "light";
10751
10804
  dispatch({
10752
10805
  type: "UPDATE_SETTINGS",
10753
10806
  settings: { theme: { colorMode: newColorMode } }
10754
10807
  });
10755
- });
10808
+ }
10809
+ darkModeQuery.addEventListener("change", darkModeQueryHandler);
10810
+ return () => {
10811
+ darkModeQuery.removeEventListener("change", darkModeQueryHandler);
10812
+ };
10756
10813
  }, []);
10757
10814
  (0, import_react12.useEffect)(() => {
10758
10815
  const fontSet = /* @__PURE__ */ new Set([]);
@@ -10799,23 +10856,18 @@ var EmbedProvider = ({
10799
10856
  }
10800
10857
  }, [state.accessToken, apiConfig, customHeaders]);
10801
10858
  (0, import_react12.useEffect)(() => {
10802
- if (state.error) {
10803
- debug(state.error.message);
10804
- }
10805
- }, [debug, state.error]);
10806
- (0, import_react12.useEffect)(() => {
10807
- const providedSettings = { ...options2.settings || {} };
10859
+ const providedSettings = { ...options.settings || {} };
10808
10860
  updateSettings(providedSettings, { update: false });
10809
- }, [options2.settings, updateSettings]);
10861
+ }, [options.settings, updateSettings]);
10810
10862
  (0, import_react12.useEffect)(() => {
10811
- const planChanged = (event) => {
10863
+ function planChangedHandler(event) {
10812
10864
  if (event instanceof CustomEvent) {
10813
10865
  debug("plan changed", event.detail);
10814
10866
  }
10815
- };
10816
- window.addEventListener("plan-changed", planChanged);
10867
+ }
10868
+ window.addEventListener("plan-changed", planChangedHandler);
10817
10869
  return () => {
10818
- window.removeEventListener("plan-changed", planChanged);
10870
+ window.removeEventListener("plan-changed", planChangedHandler);
10819
10871
  };
10820
10872
  }, [debug]);
10821
10873
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
@@ -10840,13 +10892,15 @@ var EmbedProvider = ({
10840
10892
  previewCheckout: debouncedPreviewCheckout,
10841
10893
  unsubscribe: debouncedUnsubscribe,
10842
10894
  getUpcomingInvoice: debouncedGetUpcomingInvoice,
10895
+ getCustomerBalance: debouncedGetCustomerBalance,
10843
10896
  listInvoices: debouncedListInvoices,
10844
10897
  setError,
10845
10898
  setAccessToken,
10846
10899
  setLayout,
10847
10900
  setCheckoutState,
10848
10901
  setData,
10849
- updateSettings
10902
+ updateSettings,
10903
+ debug
10850
10904
  },
10851
10905
  children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(ot, { theme: state.settings.theme, children: [
10852
10906
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconStyles, {}),
@@ -12489,6 +12543,7 @@ var Sidebar = ({
12489
12543
  addOns,
12490
12544
  creditBundles = [],
12491
12545
  usageBasedEntitlements,
12546
+ addOnUsageBasedEntitlements = [],
12492
12547
  charges,
12493
12548
  checkoutRef,
12494
12549
  checkoutStage,
@@ -12673,6 +12728,35 @@ var Sidebar = ({
12673
12728
  }
12674
12729
  setError(void 0);
12675
12730
  setIsLoading(true);
12731
+ const planPayInAdvance = payInAdvanceEntitlements.reduce(
12732
+ (acc, { meteredMonthlyPrice, meteredYearlyPrice, quantity }) => {
12733
+ const priceId2 = (planPeriod === "year" ? meteredYearlyPrice : meteredMonthlyPrice)?.priceId;
12734
+ if (priceId2) {
12735
+ acc.push({
12736
+ priceId: priceId2,
12737
+ quantity
12738
+ });
12739
+ }
12740
+ return acc;
12741
+ },
12742
+ []
12743
+ );
12744
+ const addOnPayInAdvance = addOnUsageBasedEntitlements.filter(
12745
+ (entitlement) => entitlement.priceBehavior === "pay_in_advance" /* PayInAdvance */
12746
+ ).reduce(
12747
+ (acc, { meteredMonthlyPrice, meteredYearlyPrice, quantity }) => {
12748
+ const priceId2 = (planPeriod === "year" ? meteredYearlyPrice : meteredMonthlyPrice)?.priceId;
12749
+ if (priceId2) {
12750
+ acc.push({
12751
+ priceId: priceId2,
12752
+ quantity
12753
+ });
12754
+ }
12755
+ return acc;
12756
+ },
12757
+ []
12758
+ );
12759
+ const allPayInAdvance = [...planPayInAdvance, ...addOnPayInAdvance];
12676
12760
  await checkout({
12677
12761
  newPlanId: planId,
12678
12762
  newPriceId: priceId,
@@ -12688,19 +12772,7 @@ var Sidebar = ({
12688
12772
  }
12689
12773
  return acc;
12690
12774
  }, []),
12691
- payInAdvance: payInAdvanceEntitlements.reduce(
12692
- (acc, { meteredMonthlyPrice, meteredYearlyPrice, quantity }) => {
12693
- const priceId2 = (planPeriod === "year" ? meteredYearlyPrice : meteredMonthlyPrice)?.priceId;
12694
- if (priceId2) {
12695
- acc.push({
12696
- priceId: priceId2,
12697
- quantity
12698
- });
12699
- }
12700
- return acc;
12701
- },
12702
- []
12703
- ),
12775
+ payInAdvance: allPayInAdvance,
12704
12776
  creditBundles: creditBundles.reduce(
12705
12777
  (acc, { id, count }) => {
12706
12778
  if (count > 0) {
@@ -12738,6 +12810,7 @@ var Sidebar = ({
12738
12810
  setIsLoading,
12739
12811
  setLayout,
12740
12812
  payInAdvanceEntitlements,
12813
+ addOnUsageBasedEntitlements,
12741
12814
  willTrialWithoutPaymentMethod,
12742
12815
  promoCode
12743
12816
  ]);
@@ -14433,6 +14506,12 @@ var CheckoutDialog = ({ top = 0 }) => {
14433
14506
  ),
14434
14507
  [usageBasedEntitlements]
14435
14508
  );
14509
+ const addOnPayInAdvanceEntitlements = (0, import_react30.useMemo)(
14510
+ () => addOnUsageBasedEntitlements.filter(
14511
+ (entitlement) => entitlement.priceBehavior === "pay_in_advance" /* PayInAdvance */
14512
+ ),
14513
+ [addOnUsageBasedEntitlements]
14514
+ );
14436
14515
  const [promoCode, setPromoCode] = (0, import_react30.useState)(null);
14437
14516
  const [isPaymentMethodRequired, setIsPaymentMethodRequired] = (0, import_react30.useState)(false);
14438
14517
  const willTrialWithoutPaymentMethod = (0, import_react30.useMemo)(
@@ -14656,11 +14735,12 @@ var CheckoutDialog = ({ top = 0 }) => {
14656
14735
  const entitlements = plan.entitlements.reduce(
14657
14736
  (acc, entitlement) => {
14658
14737
  if (entitlement.priceBehavior && (period === "month" && entitlement.meteredMonthlyPrice || period === "year" && entitlement.meteredYearlyPrice)) {
14738
+ const allocation = entitlement.valueNumeric || 0;
14659
14739
  acc.push({
14660
14740
  ...entitlement,
14661
- allocation: entitlement.valueNumeric || 0,
14741
+ allocation,
14662
14742
  usage: 0,
14663
- quantity: 0
14743
+ quantity: allocation
14664
14744
  });
14665
14745
  }
14666
14746
  return acc;
@@ -14727,7 +14807,10 @@ var CheckoutDialog = ({ top = 0 }) => {
14727
14807
  }))
14728
14808
  );
14729
14809
  setAddOnUsageBasedEntitlements(updatedAddOnEntitlements);
14730
- handlePreviewCheckout({ addOns: updated });
14810
+ handlePreviewCheckout({
14811
+ addOns: updated,
14812
+ addOnPayInAdvanceEntitlements: updatedAddOnEntitlements
14813
+ });
14731
14814
  return updated;
14732
14815
  });
14733
14816
  },
@@ -14973,7 +15056,7 @@ var CheckoutDialog = ({ top = 0 }) => {
14973
15056
  isLoading,
14974
15057
  period: planPeriod,
14975
15058
  selectedPlan,
14976
- entitlements: addOnUsageBasedEntitlements,
15059
+ entitlements: addOnPayInAdvanceEntitlements,
14977
15060
  updateQuantity: updateAddOnEntitlementQuantity
14978
15061
  }
14979
15062
  ) : checkoutStage === "credits" ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
@@ -15001,6 +15084,7 @@ var CheckoutDialog = ({ top = 0 }) => {
15001
15084
  selectedPlan,
15002
15085
  addOns,
15003
15086
  usageBasedEntitlements,
15087
+ addOnUsageBasedEntitlements,
15004
15088
  creditBundles,
15005
15089
  charges,
15006
15090
  checkoutRef,
@@ -15122,7 +15206,7 @@ var PaymentForm = ({ onConfirm }) => {
15122
15206
  var import_react33 = require("react");
15123
15207
  var import_jsx_runtime24 = require("react/jsx-runtime");
15124
15208
  var PeriodToggle = ({
15125
- options: options2,
15209
+ options,
15126
15210
  selectedOption,
15127
15211
  selectedPlan,
15128
15212
  onSelect
@@ -15155,7 +15239,7 @@ var PeriodToggle = ({
15155
15239
  $width: "fit-content"
15156
15240
  }
15157
15241
  },
15158
- children: options2.map((option) => {
15242
+ children: options.map((option) => {
15159
15243
  const element = /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
15160
15244
  Flex,
15161
15245
  {
@@ -16207,8 +16291,8 @@ function resolveDesignProps3(props) {
16207
16291
  }
16208
16292
  };
16209
16293
  }
16210
- function formatInvoices(invoices, options2) {
16211
- const { hideUpcoming = true } = options2 || {};
16294
+ function formatInvoices(invoices, options) {
16295
+ const { hideUpcoming = true } = options || {};
16212
16296
  const now = /* @__PURE__ */ new Date();
16213
16297
  return (invoices || []).filter(({ dueDate }) => !hideUpcoming || dueDate && +dueDate <= +now).sort((a2, b2) => a2.dueDate && b2.dueDate ? +b2.dueDate - +a2.dueDate : 1).map(({ amountDue, dueDate, url, currency }) => ({
16214
16298
  amount: formatCurrency(amountDue, currency),
@@ -17129,7 +17213,7 @@ var registerWrapper = function registerWrapper2(stripe, startTime) {
17129
17213
  }
17130
17214
  stripe._registerWrapper({
17131
17215
  name: "stripe-js",
17132
- version: "7.8.0",
17216
+ version: "7.9.0",
17133
17217
  startTime
17134
17218
  });
17135
17219
  };
@@ -17204,7 +17288,7 @@ var initStripe = function initStripe2(maybeStripe, args, startTime) {
17204
17288
  var version = runtimeVersionToUrlVersion(maybeStripe.version);
17205
17289
  var expectedVersion = RELEASE_TRAIN;
17206
17290
  if (isTestKey && version !== expectedVersion) {
17207
- console.warn("Stripe.js@".concat(version, " was loaded on the page, but @stripe/stripe-js@").concat("7.8.0", " expected Stripe.js@").concat(expectedVersion, ". This may result in unexpected behavior. For more information, see https://docs.stripe.com/sdks/stripejs-versioning"));
17291
+ console.warn("Stripe.js@".concat(version, " was loaded on the page, but @stripe/stripe-js@").concat("7.9.0", " expected Stripe.js@").concat(expectedVersion, ". This may result in unexpected behavior. For more information, see https://docs.stripe.com/sdks/stripejs-versioning"));
17208
17292
  }
17209
17293
  var stripe = maybeStripe.apply(void 0, args);
17210
17294
  registerWrapper(stripe, startTime);
@@ -17742,11 +17826,29 @@ var PlanManager = (0, import_react48.forwardRef)(({ children, className, portal,
17742
17826
  featureUsage: featureUsage2,
17743
17827
  trialPaymentMethodRequired: trialPaymentMethodRequired2
17744
17828
  } = data;
17829
+ const creditGroups2 = groupCreditGrants(creditGrants, {
17830
+ groupBy: "bundle"
17831
+ }).reduce(
17832
+ (acc, grant) => {
17833
+ switch (grant.grantReason) {
17834
+ case "plan" /* Plan */:
17835
+ acc.plan.push(grant);
17836
+ break;
17837
+ case "purchased" /* Purchased */:
17838
+ acc.bundles.push(grant);
17839
+ break;
17840
+ case "free" /* Free */:
17841
+ acc.promotional.push(grant);
17842
+ }
17843
+ return acc;
17844
+ },
17845
+ { plan: [], bundles: [], promotional: [] }
17846
+ );
17745
17847
  return {
17746
17848
  currentPlan: company?.plan,
17747
17849
  currentAddOns: company?.addOns || [],
17748
17850
  creditBundles: creditBundles2,
17749
- creditGroups: groupCreditGrants(creditGrants, { groupBy: "bundle" }),
17851
+ creditGroups: creditGroups2,
17750
17852
  billingSubscription: company?.billingSubscription,
17751
17853
  canCheckout: capabilities?.checkout ?? true,
17752
17854
  defaultPlan: defaultPlan2,
@@ -17758,7 +17860,7 @@ var PlanManager = (0, import_react48.forwardRef)(({ children, className, portal,
17758
17860
  currentPlan: void 0,
17759
17861
  currentAddOns: [],
17760
17862
  creditBundles: [],
17761
- creditGroups: [],
17863
+ creditGroups: { plan: [], bundles: [], promotional: [] },
17762
17864
  billingSubscription: void 0,
17763
17865
  canCheckout: false,
17764
17866
  defaultPlan: void 0,
@@ -17915,77 +18017,151 @@ var PlanManager = (0, import_react48.forwardRef)(({ children, className, portal,
17915
18017
  );
17916
18018
  }) })
17917
18019
  ] }),
17918
- props.addOns.isVisible && creditGroups.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Flex, { $flexDirection: "column", $gap: "0.5rem", children: [
18020
+ props.addOns.isVisible && creditGroups.plan.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Flex, { $flexDirection: "column", $gap: "0.5rem", children: [
17919
18021
  props.addOns.showLabel && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
17920
18022
  Text,
17921
18023
  {
17922
18024
  $color: isLightBackground ? darken(settings.theme.card.background, 0.46) : lighten(settings.theme.card.background, 0.46),
17923
18025
  $leading: 1,
17924
- children: t2("Credits")
18026
+ children: t2("Credits in plan")
17925
18027
  }
17926
18028
  ),
17927
- /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Flex, { $flexDirection: "column", $gap: "1rem", children: creditGroups.reduce(
17928
- (acc, group, groupIndex) => {
17929
- const bundle = group.grantReason === "purchased" /* Purchased */ && group?.bundleId ? creditBundles.find((b2) => b2.id === group.bundleId) : void 0;
17930
- acc.push(
17931
- /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
17932
- Flex,
17933
- {
17934
- $justifyContent: "space-between",
17935
- $alignItems: "center",
17936
- $flexWrap: "wrap",
17937
- $gap: "0.5rem",
17938
- children: [
17939
- group.grantReason === "plan" /* Plan */ ? /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Text, { display: props.addOns.fontStyle, children: [
17940
- group.quantity,
17941
- " ",
17942
- getFeatureName(group, group.quantity),
18029
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Flex, { $flexDirection: "column", $gap: "1rem", children: creditGroups.plan.map((group, groupIndex) => {
18030
+ return /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
18031
+ Flex,
18032
+ {
18033
+ $justifyContent: "space-between",
18034
+ $alignItems: "center",
18035
+ $flexWrap: "wrap",
18036
+ $gap: "0.5rem",
18037
+ children: [
18038
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Text, { display: props.addOns.fontStyle, children: [
18039
+ group.quantity,
18040
+ " ",
18041
+ getFeatureName(group, group.quantity),
18042
+ " ",
18043
+ subscriptionInterval && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(import_jsx_runtime43.Fragment, { children: [
18044
+ t2("per"),
18045
+ " ",
18046
+ t2(subscriptionInterval)
18047
+ ] })
18048
+ ] }),
18049
+ group.total.used > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
18050
+ Text,
18051
+ {
18052
+ style: { opacity: 0.54 },
18053
+ $size: 0.875 * settings.theme.typography.text.fontSize,
18054
+ $color: settings.theme.typography.text.color,
18055
+ children: [
18056
+ group.total.used,
17943
18057
  " ",
17944
- subscriptionInterval && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(import_jsx_runtime43.Fragment, { children: [
17945
- t2("per"),
17946
- " ",
17947
- t2(subscriptionInterval)
17948
- ] })
17949
- ] }) : bundle ? /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Text, { display: props.addOns.fontStyle, children: [
17950
- group.grants.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Text, { style: { opacity: 0.5 }, children: [
17951
- "(",
17952
- group.grants.length,
17953
- ")",
17954
- " "
17955
- ] }),
17956
- bundle.name,
17957
- " (",
17958
- group.quantity,
18058
+ t2("used")
18059
+ ]
18060
+ }
18061
+ )
18062
+ ]
18063
+ },
18064
+ groupIndex
18065
+ );
18066
+ }) })
18067
+ ] }),
18068
+ props.addOns.isVisible && creditGroups.bundles.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Flex, { $flexDirection: "column", $gap: "0.5rem", children: [
18069
+ props.addOns.showLabel && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
18070
+ Text,
18071
+ {
18072
+ $color: isLightBackground ? darken(settings.theme.card.background, 0.46) : lighten(settings.theme.card.background, 0.46),
18073
+ $leading: 1,
18074
+ children: t2("Credit bundles")
18075
+ }
18076
+ ),
18077
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Flex, { $flexDirection: "column", $gap: "1rem", children: creditGroups.bundles.map((group, groupIndex) => {
18078
+ const bundle = group?.bundleId ? creditBundles.find((b2) => b2.id === group.bundleId) : void 0;
18079
+ return /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
18080
+ Flex,
18081
+ {
18082
+ $justifyContent: "space-between",
18083
+ $alignItems: "center",
18084
+ $flexWrap: "wrap",
18085
+ $gap: "0.5rem",
18086
+ children: [
18087
+ bundle ? /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Text, { display: props.addOns.fontStyle, children: [
18088
+ group.grants.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Text, { style: { opacity: 0.5 }, children: [
18089
+ "(",
18090
+ group.grants.length,
18091
+ ")",
18092
+ " "
18093
+ ] }),
18094
+ bundle.name,
18095
+ " (",
18096
+ group.quantity,
18097
+ " ",
18098
+ getFeatureName(group, group.quantity),
18099
+ ")"
18100
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Text, { display: props.addOns.fontStyle, children: [
18101
+ group.quantity,
18102
+ " ",
18103
+ getFeatureName(group, group.quantity)
18104
+ ] }),
18105
+ group.total.used > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
18106
+ Text,
18107
+ {
18108
+ style: { opacity: 0.54 },
18109
+ $size: 0.875 * settings.theme.typography.text.fontSize,
18110
+ $color: settings.theme.typography.text.color,
18111
+ children: [
18112
+ group.total.used,
17959
18113
  " ",
17960
- getFeatureName(group, group.quantity),
17961
- ")"
17962
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Text, { display: props.addOns.fontStyle, children: [
17963
- group.quantity,
18114
+ t2("used")
18115
+ ]
18116
+ }
18117
+ )
18118
+ ]
18119
+ },
18120
+ groupIndex
18121
+ );
18122
+ }) })
18123
+ ] }),
18124
+ props.addOns.isVisible && creditGroups.promotional.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Flex, { $flexDirection: "column", $gap: "0.5rem", children: [
18125
+ props.addOns.showLabel && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
18126
+ Text,
18127
+ {
18128
+ $color: isLightBackground ? darken(settings.theme.card.background, 0.46) : lighten(settings.theme.card.background, 0.46),
18129
+ $leading: 1,
18130
+ children: t2("Promotional credits")
18131
+ }
18132
+ ),
18133
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Flex, { $flexDirection: "column", $gap: "1rem", children: creditGroups.promotional.map((group, groupIndex) => {
18134
+ return /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
18135
+ Flex,
18136
+ {
18137
+ $justifyContent: "space-between",
18138
+ $alignItems: "center",
18139
+ $flexWrap: "wrap",
18140
+ $gap: "0.5rem",
18141
+ children: [
18142
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Text, { display: props.addOns.fontStyle, children: [
18143
+ group.quantity,
18144
+ " ",
18145
+ getFeatureName(group, group.quantity)
18146
+ ] }),
18147
+ group.total.used > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
18148
+ Text,
18149
+ {
18150
+ style: { opacity: 0.54 },
18151
+ $size: 0.875 * settings.theme.typography.text.fontSize,
18152
+ $color: settings.theme.typography.text.color,
18153
+ children: [
18154
+ group.total.used,
17964
18155
  " ",
17965
- getFeatureName(group, group.quantity)
17966
- ] }),
17967
- group.total.used > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
17968
- Text,
17969
- {
17970
- style: { opacity: 0.54 },
17971
- $size: 0.875 * settings.theme.typography.text.fontSize,
17972
- $color: settings.theme.typography.text.color,
17973
- children: [
17974
- group.total.used,
17975
- " ",
17976
- t2("used")
17977
- ]
17978
- }
17979
- )
17980
- ]
17981
- },
17982
- groupIndex
17983
- )
17984
- );
17985
- return acc;
17986
- },
17987
- []
17988
- ) })
18156
+ t2("used")
18157
+ ]
18158
+ }
18159
+ )
18160
+ ]
18161
+ },
18162
+ groupIndex
18163
+ );
18164
+ }) })
17989
18165
  ] }),
17990
18166
  canCheckout && props.callToAction.isVisible && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
17991
18167
  Button,
@@ -18998,11 +19174,12 @@ function resolveDesignProps11(props) {
18998
19174
  var UpcomingBill = (0, import_react54.forwardRef)(({ className, ...rest }, ref) => {
18999
19175
  const props = resolveDesignProps11(rest);
19000
19176
  const { t: t2 } = useTranslation();
19001
- const { data, settings, getUpcomingInvoice } = useEmbed();
19177
+ const { data, settings, debug, getUpcomingInvoice, getCustomerBalance } = useEmbed();
19002
19178
  const isLightBackground = useIsLightBackground();
19003
19179
  const [isLoading, setIsLoading] = (0, import_react54.useState)(false);
19004
19180
  const [error, setError] = (0, import_react54.useState)();
19005
19181
  const [upcomingInvoice, setUpcomingInvoice] = (0, import_react54.useState)();
19182
+ const [balances, setBalances] = (0, import_react54.useState)([]);
19006
19183
  const discounts = (0, import_react54.useMemo)(() => {
19007
19184
  return (isCheckoutData(data) && data.subscription?.discounts || []).map(
19008
19185
  (discount) => ({
@@ -19031,9 +19208,22 @@ var UpcomingBill = (0, import_react54.forwardRef)(({ className, ...rest }, ref)
19031
19208
  }
19032
19209
  }
19033
19210
  }, [data, getUpcomingInvoice]);
19211
+ const getBalances = (0, import_react54.useCallback)(async () => {
19212
+ try {
19213
+ const response = await getCustomerBalance();
19214
+ if (response) {
19215
+ setBalances(response.data.balances);
19216
+ }
19217
+ } catch (err2) {
19218
+ debug("Failed to fetch customer balance.", err2);
19219
+ }
19220
+ }, [debug, getCustomerBalance]);
19034
19221
  (0, import_react54.useEffect)(() => {
19035
19222
  getInvoice();
19036
19223
  }, [getInvoice]);
19224
+ (0, import_react54.useEffect)(() => {
19225
+ getBalances();
19226
+ }, [getBalances]);
19037
19227
  if (!isCheckoutData(data) || !data.subscription || data.subscription.cancelAt) {
19038
19228
  return null;
19039
19229
  }
@@ -19083,6 +19273,19 @@ var UpcomingBill = (0, import_react54.forwardRef)(({ className, ...rest }, ref)
19083
19273
  ]
19084
19274
  }
19085
19275
  ),
19276
+ balances.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
19277
+ Flex,
19278
+ {
19279
+ as: TransitionBox,
19280
+ $justifyContent: "space-between",
19281
+ $alignItems: "start",
19282
+ $gap: "1rem",
19283
+ children: [
19284
+ /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(Text, { $weight: 600, children: t2("Remaining balance") }),
19285
+ /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(Flex, { $flexDirection: "column", $gap: "0.5rem", children: balances.map((item, idx) => /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(Text, { children: formatCurrency(item.balance, item.currency) }, idx)) })
19286
+ ]
19287
+ }
19288
+ ),
19086
19289
  discounts.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
19087
19290
  Flex,
19088
19291
  {
@@ -21224,7 +21427,7 @@ var {
21224
21427
  Z_DEFAULT_STRATEGY,
21225
21428
  Z_DEFLATED: Z_DEFLATED$1
21226
21429
  } = constants$2;
21227
- function Deflate$1(options2) {
21430
+ function Deflate$1(options) {
21228
21431
  this.options = common.assign({
21229
21432
  level: Z_DEFAULT_COMPRESSION,
21230
21433
  method: Z_DEFLATED$1,
@@ -21232,7 +21435,7 @@ function Deflate$1(options2) {
21232
21435
  windowBits: 15,
21233
21436
  memLevel: 8,
21234
21437
  strategy: Z_DEFAULT_STRATEGY
21235
- }, options2 || {});
21438
+ }, options || {});
21236
21439
  let opt = this.options;
21237
21440
  if (opt.raw && opt.windowBits > 0) {
21238
21441
  opt.windowBits = -opt.windowBits;
@@ -21338,23 +21541,23 @@ Deflate$1.prototype.onEnd = function(status) {
21338
21541
  this.err = status;
21339
21542
  this.msg = this.strm.msg;
21340
21543
  };
21341
- function deflate$1(input, options2) {
21342
- const deflator = new Deflate$1(options2);
21544
+ function deflate$1(input, options) {
21545
+ const deflator = new Deflate$1(options);
21343
21546
  deflator.push(input, true);
21344
21547
  if (deflator.err) {
21345
21548
  throw deflator.msg || messages[deflator.err];
21346
21549
  }
21347
21550
  return deflator.result;
21348
21551
  }
21349
- function deflateRaw$1(input, options2) {
21350
- options2 = options2 || {};
21351
- options2.raw = true;
21352
- return deflate$1(input, options2);
21552
+ function deflateRaw$1(input, options) {
21553
+ options = options || {};
21554
+ options.raw = true;
21555
+ return deflate$1(input, options);
21353
21556
  }
21354
- function gzip$1(input, options2) {
21355
- options2 = options2 || {};
21356
- options2.gzip = true;
21357
- return deflate$1(input, options2);
21557
+ function gzip$1(input, options) {
21558
+ options = options || {};
21559
+ options.gzip = true;
21560
+ return deflate$1(input, options);
21358
21561
  }
21359
21562
  var Deflate_1$1 = Deflate$1;
21360
21563
  var deflate_2 = deflate$1;
@@ -23167,12 +23370,12 @@ var {
23167
23370
  Z_DATA_ERROR,
23168
23371
  Z_MEM_ERROR
23169
23372
  } = constants$2;
23170
- function Inflate$1(options2) {
23373
+ function Inflate$1(options) {
23171
23374
  this.options = common.assign({
23172
23375
  chunkSize: 1024 * 64,
23173
23376
  windowBits: 15,
23174
23377
  to: ""
23175
- }, options2 || {});
23378
+ }, options || {});
23176
23379
  const opt = this.options;
23177
23380
  if (opt.raw && opt.windowBits >= 0 && opt.windowBits < 16) {
23178
23381
  opt.windowBits = -opt.windowBits;
@@ -23180,7 +23383,7 @@ function Inflate$1(options2) {
23180
23383
  opt.windowBits = -15;
23181
23384
  }
23182
23385
  }
23183
- if (opt.windowBits >= 0 && opt.windowBits < 16 && !(options2 && options2.windowBits)) {
23386
+ if (opt.windowBits >= 0 && opt.windowBits < 16 && !(options && options.windowBits)) {
23184
23387
  opt.windowBits += 32;
23185
23388
  }
23186
23389
  if (opt.windowBits > 15 && opt.windowBits < 48) {
@@ -23302,16 +23505,16 @@ Inflate$1.prototype.onEnd = function(status) {
23302
23505
  this.err = status;
23303
23506
  this.msg = this.strm.msg;
23304
23507
  };
23305
- function inflate$1(input, options2) {
23306
- const inflator = new Inflate$1(options2);
23508
+ function inflate$1(input, options) {
23509
+ const inflator = new Inflate$1(options);
23307
23510
  inflator.push(input);
23308
23511
  if (inflator.err) throw inflator.msg || messages[inflator.err];
23309
23512
  return inflator.result;
23310
23513
  }
23311
- function inflateRaw$1(input, options2) {
23312
- options2 = options2 || {};
23313
- options2.raw = true;
23314
- return inflate$1(input, options2);
23514
+ function inflateRaw$1(input, options) {
23515
+ options = options || {};
23516
+ options.raw = true;
23517
+ return inflate$1(input, options);
23315
23518
  }
23316
23519
  var Inflate_1$1 = Inflate$1;
23317
23520
  var inflate_2 = inflate$1;
@@ -23379,8 +23582,8 @@ function parseEditorState(data) {
23379
23582
  });
23380
23583
  return arr;
23381
23584
  }
23382
- function createRenderer(options2) {
23383
- const { useFallback = false } = options2 || {};
23585
+ function createRenderer(options) {
23586
+ const { useFallback = false } = options || {};
23384
23587
  return function renderNode(node2, index) {
23385
23588
  const { type, props = {}, children } = node2;
23386
23589
  const name = typeof type !== "string" ? type.resolvedName : type;