@rebilly/instruments 7.3.1 → 7.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1614,12 +1614,25 @@ const iframes = (() => {
1614
1614
  }
1615
1615
  };
1616
1616
  })().getInstance();
1617
+ function validateStorefront(storefront) {
1618
+ if (storefront == null) {
1619
+ throw new Error("Could not access rebilly-js-sdk instance");
1620
+ }
1621
+ }
1622
+ function validateOptions$1(options) {
1623
+ if (options == null) {
1624
+ throw new Error(
1625
+ "Could not use Rebilly Instruments mount options to fetch Rebilly data"
1626
+ );
1627
+ }
1628
+ }
1617
1629
  const state = (() => {
1618
1630
  let state2 = null;
1619
1631
  const defaultState = {
1620
1632
  options: null,
1621
1633
  data: {},
1622
1634
  mountingPoints: null,
1635
+ mainStyleVars: null,
1623
1636
  storefront: null,
1624
1637
  form: null,
1625
1638
  summary: null,
@@ -1627,9 +1640,10 @@ const state = (() => {
1627
1640
  translate: new Translate(),
1628
1641
  hasMounted: false,
1629
1642
  toModel() {
1643
+ var _a;
1630
1644
  const model = {
1631
1645
  ...state2,
1632
- data: (state2 == null ? void 0 : state2.data.toPostmatesModel) ? state2.data.toPostmatesModel() : {}
1646
+ data: ((_a = state2 == null ? void 0 : state2.data) == null ? void 0 : _a.toPostmatesModel) ? state2.data.toPostmatesModel() : {}
1633
1647
  };
1634
1648
  delete model.toModel;
1635
1649
  delete model.updateModel;
@@ -5335,7 +5349,7 @@ function cloneArrayDeep(val, instanceClone) {
5335
5349
  return res;
5336
5350
  }
5337
5351
  var cloneDeep_1 = cloneDeep;
5338
- const version = "54.3.0";
5352
+ const version = "54.3.1";
5339
5353
  let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
5340
5354
  let nanoid = (size2 = 21) => {
5341
5355
  let id2 = "";
@@ -8874,18 +8888,12 @@ function RebillyStorefrontAPI({ publishableKey = null, jwt = null, sandbox = fal
8874
8888
  }
8875
8889
  const TIMEOUT = 6e4;
8876
8890
  function validateStateForStorefront() {
8877
- if (!state.storefront) {
8878
- throw new Error("Could not access rebilly-js-sdk instance");
8879
- }
8880
- if (!state.options) {
8881
- throw new Error(
8882
- "Could not use Rebilly Instruments mount options to fetch Rebilly data"
8883
- );
8884
- }
8891
+ validateStorefront(state.storefront);
8892
+ validateOptions$1(state.options);
8885
8893
  }
8886
8894
  async function Endpoint(callback) {
8887
8895
  try {
8888
- validateStateForStorefront({ state });
8896
+ validateStateForStorefront();
8889
8897
  return await callback();
8890
8898
  } catch (error2) {
8891
8899
  showError(error2);
@@ -8906,25 +8914,36 @@ class StorefrontInstance {
8906
8914
  live: liveUrl || "https://api.rebilly.com",
8907
8915
  sandbox: sandboxUrl || "https://api-sandbox.rebilly.com"
8908
8916
  };
8917
+ const parsedTimeout = typeof timeout === "string" ? parseInt(timeout, 10) : timeout;
8909
8918
  const config = {
8910
- organizationId,
8919
+ organizationId: organizationId ? organizationId : void 0,
8911
8920
  sandbox: mode === "sandbox",
8912
- timeout: Number.isNaN(parseInt(timeout, 10)) ? TIMEOUT : parseInt(timeout, 10),
8921
+ timeout: Number.isNaN(parsedTimeout) ? TIMEOUT : parsedTimeout,
8913
8922
  urls
8914
8923
  };
8915
8924
  const api = RebillyStorefrontAPI(config);
8916
- const rebilly = typeof RebillyAPI.default === "function" ? RebillyAPI.default(config) : RebillyAPI(config);
8925
+ const rebilly = (
8926
+ // @ts-ignore refactor with above todo
8927
+ typeof RebillyAPI.default === "function" ? (
8928
+ // @ts-ignore refactor with above todo
8929
+ RebillyAPI.default(config)
8930
+ ) : RebillyAPI(config)
8931
+ );
8917
8932
  const experimental = RebillyExperimentalAPI(config);
8918
8933
  api.setSessionToken(publishableKey || jwt);
8919
8934
  rebilly.setSessionToken(publishableKey || jwt);
8920
8935
  experimental.setSessionToken(publishableKey || jwt);
8921
8936
  this.api = api;
8922
8937
  this.api.rebilly = rebilly;
8923
- this.api.rebilly.experimental = experimental;
8938
+ if (this.api.rebilly) {
8939
+ this.api.rebilly.experimental = experimental;
8940
+ }
8924
8941
  return this.api;
8925
8942
  }
8926
8943
  }
8927
- const Storefront = (config = {}) => new StorefrontInstance(config);
8944
+ const Storefront = (config = {}) => {
8945
+ return new StorefrontInstance(config);
8946
+ };
8928
8947
  const isObject3 = (val) => val != null && typeof val === "object";
8929
8948
  const defaultOptions = {
8930
8949
  minimum: 1,
@@ -8962,46 +8981,60 @@ function updateItemQuantityFromMap(quantitiesByPlanId) {
8962
8981
  }
8963
8982
  };
8964
8983
  }
8965
- async function fetchSummary({ data: data2 = null } = {}) {
8984
+ async function fetchSummary({
8985
+ data: data2 = null
8986
+ } = {}) {
8966
8987
  return Endpoint(async () => {
8967
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
8988
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
8968
8989
  const items2 = (_a = state.options) == null ? void 0 : _a.items;
8969
8990
  const websiteId = ((_b = state.options) == null ? void 0 : _b.websiteId) || null;
8970
8991
  const bumpOfferProductsIds = ((_d = (_c = state.options) == null ? void 0 : _c.bumpOffer) == null ? void 0 : _d.map(({ planId }) => planId)) || [];
8971
8992
  const payload = {
8972
8993
  data: {
8973
- websiteId
8994
+ websiteId: websiteId ?? void 0
8974
8995
  }
8975
8996
  };
8976
- const isBumpOfferSummary = () => state.data.summaryLineItems.every(
8977
- (item) => bumpOfferProductsIds.includes(item.planId)
8978
- );
8979
- if (!isBumpOfferSummary() && !state.data.acceptBumpOffer) {
8997
+ const isBumpOfferSummary = () => {
8998
+ var _a2, _b2;
8999
+ return (_b2 = (_a2 = state.data) == null ? void 0 : _a2.summaryLineItems) == null ? void 0 : _b2.every((item) => {
9000
+ if (item.planId == null) {
9001
+ return false;
9002
+ }
9003
+ return bumpOfferProductsIds.includes(item.planId);
9004
+ });
9005
+ };
9006
+ if (!isBumpOfferSummary() && !((_e = state.data) == null ? void 0 : _e.acceptBumpOffer) && ((_f = state.data) == null ? void 0 : _f.summaryLineItems)) {
8980
9007
  payload.data.items = mapItemsQuantities(
8981
- state.data.summaryLineItems
9008
+ (_g = state.data) == null ? void 0 : _g.summaryLineItems
8982
9009
  );
8983
9010
  } else if (items2) {
8984
- if (state.data.acceptBumpOffer) {
8985
- payload.data.items = state.options.bumpOffer;
9011
+ if ((_h = state.data) == null ? void 0 : _h.acceptBumpOffer) {
9012
+ payload.data.items = (_i = state.options) == null ? void 0 : _i.bumpOffer;
8986
9013
  } else {
8987
- payload.data.items = mapItemsQuantities(items2);
9014
+ payload.data.items = mapItemsQuantities(items2 ?? []);
8988
9015
  }
8989
9016
  } else {
8990
- payload.data.items = mapItemsQuantities(
8991
- state.data.summaryLineItems
8992
- );
8993
- if (((_e = state.data) == null ? void 0 : _e.addons.length) > 0) {
8994
- payload.data.items = payload.data.items.concat(
8995
- state.data.addons.map(mapItemsQuantities)
9017
+ if ((_j = state.data) == null ? void 0 : _j.summaryLineItems) {
9018
+ payload.data.items = mapItemsQuantities(
9019
+ state.data.summaryLineItems
9020
+ );
9021
+ }
9022
+ if (!((_k = state.data) == null ? void 0 : _k.acceptBumpOffer) && // @ts-ignore TODO: type "addonLineItems" once "views/common/iframe/events/update-addons-handler.js" is typed.
9023
+ ((_n = (_m = (_l = state.data) == null ? void 0 : _l.previewPurchase) == null ? void 0 : _m.addonLineItems) == null ? void 0 : _n.length) > 0) {
9024
+ payload.data.items = (_p = (_o = payload.data) == null ? void 0 : _o.items) == null ? void 0 : _p.concat(
9025
+ // @ts-ignore TODO: type "addonLineItems" once "views/common/iframe/events/update-addons-handler.js" is typed.
9026
+ state.data.previewPurchase.addonLineItems
8996
9027
  );
8997
9028
  }
8998
9029
  }
8999
- if (!state.data.acceptBumpOffer && ((_h = (_g = (_f = state.data) == null ? void 0 : _f.previewPurchase) == null ? void 0 : _g.addonLineItems) == null ? void 0 : _h.length) > 0) {
9000
- payload.data.items = payload.data.items.concat(
9030
+ if (!((_q = state.data) == null ? void 0 : _q.acceptBumpOffer) && // @ts-ignore TODO: type "addonLineItems" once "views/common/iframe/events/update-addons-handler.js" is typed.
9031
+ ((_t = (_s = (_r = state.data) == null ? void 0 : _r.previewPurchase) == null ? void 0 : _s.addonLineItems) == null ? void 0 : _t.length) > 0) {
9032
+ payload.data.items = (_u = payload.data.items) == null ? void 0 : _u.concat(
9033
+ // @ts-ignore TODO: type "addonLineItems" once "views/common/iframe/events/update-addons-handler.js" is typed.
9001
9034
  state.data.previewPurchase.addonLineItems
9002
9035
  );
9003
9036
  }
9004
- if ((_i = state.data) == null ? void 0 : _i.amountAndCurrency) {
9037
+ if ((_v = state.data) == null ? void 0 : _v.amountAndCurrency) {
9005
9038
  payload.data = {
9006
9039
  ...payload.data,
9007
9040
  ...state.data.amountAndCurrency
@@ -9013,34 +9046,42 @@ async function fetchSummary({ data: data2 = null } = {}) {
9013
9046
  if (data2 == null ? void 0 : data2.deliveryAddress) {
9014
9047
  payload.data.deliveryAddress = data2.deliveryAddress;
9015
9048
  }
9016
- if ((_j = state.data) == null ? void 0 : _j.couponIds) {
9049
+ if ((_w = state.data) == null ? void 0 : _w.couponIds) {
9017
9050
  payload.data.couponIds = state.data.couponIds;
9018
9051
  }
9052
+ validateStorefront(state.storefront);
9019
9053
  const { fields: summaryFields } = await state.storefront.purchase.preview(payload);
9020
9054
  let transformedFields = summaryFields;
9021
- if (!state.data.acceptBumpOffer) {
9022
- const quantitiesByPlanId = createQuantitiesMap(items2);
9055
+ if (!((_x = state.data) == null ? void 0 : _x.acceptBumpOffer)) {
9056
+ const quantitiesByPlanId = createQuantitiesMap(items2 ?? []);
9023
9057
  transformedFields = cloneDeep$1(summaryFields);
9024
9058
  if (transformedFields.lineItems) {
9025
- if ((_l = (_k = state.data) == null ? void 0 : _k.previewPurchase) == null ? void 0 : _l.addonLineItems) {
9026
- const addonsMap = state.data.previewPurchase.addonLineItems.reduce(
9027
- (map, curr) => {
9028
- map.set(curr.planId, curr);
9029
- return map;
9030
- },
9031
- /* @__PURE__ */ new Map()
9059
+ if ((_z = (_y = state.data) == null ? void 0 : _y.previewPurchase) == null ? void 0 : _z.addonLineItems) {
9060
+ const addonsMap = (
9061
+ // @ts-ignore TODO: type "addonLineItems" once "views/common/iframe/events/update-addons-handler.js" is typed.
9062
+ state.data.previewPurchase.addonLineItems.reduce(
9063
+ // @ts-ignore TODO: type "addonLineItems" once "views/common/iframe/events/update-addons-handler.js" is typed.
9064
+ (map, curr) => {
9065
+ map.set(curr.planId, curr);
9066
+ return map;
9067
+ },
9068
+ /* @__PURE__ */ new Map()
9069
+ )
9032
9070
  );
9033
9071
  transformedFields.lineItems = transformedFields.lineItems.filter(
9034
9072
  (item) => !addonsMap.has(item.planId)
9035
9073
  );
9036
- transformedFields.addonLineItems = state.data.previewPurchase.addonLineItems;
9074
+ transformedFields.addonLineItems = // @ts-ignore TODO: type "addonLineItems" once "views/common/iframe/events/update-addons-handler.js" is typed.
9075
+ state.data.previewPurchase.addonLineItems;
9037
9076
  }
9038
9077
  transformedFields.lineItems.forEach(
9039
9078
  updateItemQuantityFromMap(quantitiesByPlanId)
9040
9079
  );
9041
9080
  }
9042
9081
  }
9043
- state.data.previewPurchase = transformedFields;
9082
+ if (state.data) {
9083
+ state.data.previewPurchase = transformedFields;
9084
+ }
9044
9085
  return new SummaryModel(transformedFields);
9045
9086
  });
9046
9087
  }
@@ -10551,10 +10592,12 @@ class ProductModel extends BaseModel {
10551
10592
  }
10552
10593
  async function fetchProductsFromPlans() {
10553
10594
  return Endpoint(async () => {
10554
- var _a, _b, _c;
10555
- let lineItems = state.data.summaryLineItems;
10556
- if (lineItems.length === 0) {
10557
- lineItems = ((_a = state.options) == null ? void 0 : _a.items) ?? [];
10595
+ var _a, _b, _c, _d;
10596
+ let lineItems;
10597
+ if (((_a = state.data) == null ? void 0 : _a.summaryLineItems) && state.data.summaryLineItems.length > 0) {
10598
+ lineItems = state.data.summaryLineItems;
10599
+ } else {
10600
+ lineItems = ((_b = state.options) == null ? void 0 : _b.items) ?? [];
10558
10601
  }
10559
10602
  const filterByPlanId = {
10560
10603
  filter: "",
@@ -10562,24 +10605,28 @@ async function fetchProductsFromPlans() {
10562
10605
  };
10563
10606
  if (lineItems.length) {
10564
10607
  let ids = lineItems.map((item) => item.planId);
10565
- if ((_b = state.options) == null ? void 0 : _b.addons) {
10608
+ if ((_c = state.options) == null ? void 0 : _c.addons) {
10566
10609
  ids = ids.concat(
10567
10610
  state.options.addons.map((item) => item.planId)
10568
10611
  );
10569
10612
  }
10570
- if ((_c = state.options) == null ? void 0 : _c.bumpOffer) {
10613
+ if ((_d = state.options) == null ? void 0 : _d.bumpOffer) {
10571
10614
  ids = ids.concat(
10572
10615
  state.options.bumpOffer.map((item) => item.planId)
10573
10616
  );
10574
10617
  }
10575
- filterByPlanId.filter = `id:${[...new Set(ids)].join(",")}`;
10618
+ filterByPlanId.filter = `id:${Array.from(new Set(ids)).join(",")}`;
10576
10619
  }
10577
10620
  if (filterByPlanId.filter.length) {
10578
10621
  try {
10622
+ validateStorefront(state.storefront);
10579
10623
  const { items: planItems } = await state.storefront.plans.getAll(filterByPlanId);
10580
10624
  const products = [];
10581
10625
  planItems.map(
10582
- ({ fields }) => new ProductModel(fields._embedded.product)
10626
+ ({ fields }) => {
10627
+ var _a2;
10628
+ return new ProductModel((_a2 = fields._embedded) == null ? void 0 : _a2.product);
10629
+ }
10583
10630
  ).forEach((product) => {
10584
10631
  if (products.every((item) => item.id !== product.id)) {
10585
10632
  products.push(product);
@@ -10697,6 +10744,7 @@ async function fetchPlansFromAddonsBumpOffer() {
10697
10744
  );
10698
10745
  }
10699
10746
  if (ids.length > 0) {
10747
+ validateStorefront(state.storefront);
10700
10748
  const { items: planItems } = await state.storefront.plans.getAll({
10701
10749
  filter: `id:${ids.join(",")}`
10702
10750
  });
@@ -11475,8 +11523,8 @@ const paymentMethods = [
11475
11523
  name: "eZeeWallet",
11476
11524
  landscapeLogo: null,
11477
11525
  portraitLogo: null,
11478
- summary: "eZeeWallet is an e-wallet solution that supports online casino deposits and\nwithdrawals in multiple currencies.\n",
11479
- description: "eZeeWallet is an e-wallet solution that supports online casino deposits and\nwithdrawals in multiple currencies.\n",
11526
+ summary: "eZeeWallet is a digital wallet that offers secure, customer-focused payment services that make paying\nand getting paid simple and hassle-free.\n",
11527
+ description: "eZeeWallet is a digital wallet that offers secure, customer-focused payment services that make paying\nand getting paid simple and hassle-free.\n",
11480
11528
  countries: {
11481
11529
  mode: "unknown",
11482
11530
  values: []
@@ -14052,14 +14100,23 @@ _InvoiceModel.Status = {
14052
14100
  disputed: "disputed"
14053
14101
  };
14054
14102
  let InvoiceModel = _InvoiceModel;
14055
- async function fetchInvoiceAndProducts({ data: data2 = null }) {
14103
+ async function fetchInvoiceAndProducts({
14104
+ data: data2 = null
14105
+ }) {
14056
14106
  return Endpoint(async () => {
14107
+ var _a;
14108
+ validateStorefront(state.storefront);
14109
+ validateOptions$1(state.options);
14057
14110
  state.storefront.setSessionToken(state.options.jwt);
14058
14111
  const { fields } = await state.storefront.invoices.get({
14059
14112
  ...data2,
14113
+ // @ts-ignore TODO: check why `expand` is not typed in `get` arguments.
14060
14114
  expand: "items.*.product"
14061
14115
  });
14062
- const products = fields.items.filter((item) => item._embedded).map((items2) => new ProductModel(items2._embedded.product));
14116
+ const products = (_a = fields.items) == null ? void 0 : _a.filter((item) => item._embedded).map((items2) => {
14117
+ var _a2;
14118
+ return new ProductModel((_a2 = items2._embedded) == null ? void 0 : _a2.product);
14119
+ });
14063
14120
  return {
14064
14121
  products,
14065
14122
  invoice: new InvoiceModel(fields)
@@ -14078,8 +14135,15 @@ class TransactionModel extends BaseModel {
14078
14135
  return Boolean(this.invoiceId);
14079
14136
  }
14080
14137
  }
14081
- async function fetchTransaction({ data: data2 = null }) {
14138
+ async function fetchTransaction({
14139
+ data: data2 = null
14140
+ }) {
14082
14141
  return Endpoint(async () => {
14142
+ validateStorefront(state.storefront);
14143
+ validateOptions$1(state.options);
14144
+ if (data2 == null) {
14145
+ throw new Error("Invalid payload.");
14146
+ }
14083
14147
  state.storefront.setSessionToken(state.options.jwt);
14084
14148
  const { fields } = await state.storefront.transactions.get(data2);
14085
14149
  return new TransactionModel(fields);
@@ -14124,6 +14188,8 @@ class WebsiteModel extends BaseModel {
14124
14188
  async function fetchAccountAndWebsite() {
14125
14189
  return Endpoint(async () => {
14126
14190
  var _a;
14191
+ validateStorefront(state.storefront);
14192
+ validateOptions$1(state.options);
14127
14193
  state.storefront.setSessionToken(state.options.jwt);
14128
14194
  const { fields } = await state.storefront.account.get({
14129
14195
  expand: "website"
@@ -14134,9 +14200,13 @@ async function fetchAccountAndWebsite() {
14134
14200
  };
14135
14201
  });
14136
14202
  }
14137
- async function setupPaymentInstrument({ data: data2 }) {
14203
+ async function setupPaymentInstrument({
14204
+ data: data2
14205
+ }) {
14138
14206
  return Endpoint(async () => {
14139
- var _a, _b;
14207
+ var _a, _b, _c;
14208
+ validateStorefront(state.storefront);
14209
+ validateOptions$1(state.options);
14140
14210
  const { fields: instrument } = await state.storefront.paymentInstruments.create({ data: data2 });
14141
14211
  state.storefront.setSessionToken(instrument.token || state.options.jwt);
14142
14212
  const setupPayload = {
@@ -14146,13 +14216,13 @@ async function setupPaymentInstrument({ data: data2 }) {
14146
14216
  ...data2
14147
14217
  }
14148
14218
  };
14149
- if (state.data.amountAndCurrency) {
14219
+ if ((_a = state.data) == null ? void 0 : _a.amountAndCurrency) {
14150
14220
  setupPayload.data = {
14151
14221
  ...setupPayload.data,
14152
14222
  ...state.data.amountAndCurrency
14153
14223
  };
14154
14224
  }
14155
- if ((_b = (_a = state.data) == null ? void 0 : _a.transaction) == null ? void 0 : _b.redirectUrl) {
14225
+ if ((_c = (_b = state.data) == null ? void 0 : _b.transaction) == null ? void 0 : _c.redirectUrl) {
14156
14226
  setupPayload.data.redirectUrl = `${setupPayload.data.redirectUrl}&originalRedirectUrl=${state.data.transaction.redirectUrl}`;
14157
14227
  }
14158
14228
  const { fields: transaction } = await state.storefront.paymentInstruments.setup(setupPayload);
@@ -14161,6 +14231,7 @@ async function setupPaymentInstrument({ data: data2 }) {
14161
14231
  }
14162
14232
  async function fetchPaymentInstrument() {
14163
14233
  return Endpoint(async () => {
14234
+ validateStorefront(state.storefront);
14164
14235
  const { items: instruments } = await state.storefront.paymentInstruments.getAll({
14165
14236
  filter: `status:active,inactive,verification-needed`
14166
14237
  });
@@ -14189,13 +14260,75 @@ class DepositRequestModel extends BaseModel {
14189
14260
  );
14190
14261
  }
14191
14262
  }
14192
- async function fetchDepositRequest({ data: data2 = null }) {
14263
+ async function fetchDepositRequest({
14264
+ data: data2 = null
14265
+ }) {
14193
14266
  return Endpoint(async () => {
14267
+ validateStorefront(state.storefront);
14268
+ validateOptions$1(state.options);
14269
+ if (data2 == null) {
14270
+ throw new Error("Invalid payload.");
14271
+ }
14194
14272
  state.storefront.setSessionToken(state.options.jwt);
14195
14273
  const { fields } = await state.storefront.cashierRequests.get(data2);
14196
14274
  return new DepositRequestModel(fields);
14197
14275
  });
14198
14276
  }
14277
+ function optional(schema2) {
14278
+ return schema2;
14279
+ }
14280
+ function isDepositRequest(deposit) {
14281
+ return deposit != null && "depositRequestId" in deposit && typeof deposit.depositRequestId === "string";
14282
+ }
14283
+ const depositRequestSchema = {
14284
+ type: "object",
14285
+ properties: {
14286
+ depositRequestId: { type: "string" }
14287
+ },
14288
+ required: ["depositRequestId"]
14289
+ };
14290
+ const depositObjectSchema = {
14291
+ type: "object",
14292
+ properties: {
14293
+ currency: {
14294
+ type: "string",
14295
+ minLength: 3,
14296
+ maxLength: 3
14297
+ },
14298
+ amount: optional({
14299
+ type: "number"
14300
+ }),
14301
+ buttons: optional({
14302
+ type: "array",
14303
+ items: {
14304
+ type: "number"
14305
+ }
14306
+ }),
14307
+ editable: optional({ type: "boolean" }),
14308
+ customAmount: optional({
14309
+ type: "object",
14310
+ properties: {
14311
+ minimum: optional({ type: "number" }),
14312
+ maximum: optional({ type: "number" }),
14313
+ multipleOf: optional({ type: "number" })
14314
+ },
14315
+ required: []
14316
+ })
14317
+ },
14318
+ anyOf: [
14319
+ {
14320
+ required: ["amount"]
14321
+ },
14322
+ {
14323
+ required: ["buttons"]
14324
+ }
14325
+ ],
14326
+ required: ["currency"]
14327
+ };
14328
+ const depositSchema = {
14329
+ type: "object",
14330
+ oneOf: [depositRequestSchema, depositObjectSchema]
14331
+ };
14199
14332
  const collectedProperties = [
14200
14333
  // Google UTM fields
14201
14334
  "utm_source",
@@ -14223,7 +14356,10 @@ const getLeadSourceData = () => {
14223
14356
  return collectedProperties.indexOf(name) > -1;
14224
14357
  }).reduce((data2, field) => {
14225
14358
  const [name, value = null] = field;
14226
- data2[name.replace(prefix, "")] = value;
14359
+ const key = name.replace(prefix, "");
14360
+ if (key) {
14361
+ data2[key] = value;
14362
+ }
14227
14363
  return data2;
14228
14364
  }, leadSource);
14229
14365
  };
@@ -14330,7 +14466,7 @@ async function fetchData({
14330
14466
  fetchInstruments = fetchPaymentInstrument,
14331
14467
  fetchDepositRequest: fetchDepositRequest$1 = fetchDepositRequest
14332
14468
  } = {}) {
14333
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
14469
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
14334
14470
  try {
14335
14471
  state.data = new DataInstance();
14336
14472
  if (!riskMetadata) {
@@ -14340,7 +14476,7 @@ async function fetchData({
14340
14476
  state.data.riskMetadata = riskMetadata;
14341
14477
  }
14342
14478
  if ((_a = state.options) == null ? void 0 : _a.deposit) {
14343
- if (state.options.deposit.depositRequestId) {
14479
+ if (isDepositRequest(state.options.deposit)) {
14344
14480
  state.data.deposit = await fetchDepositRequest$1({
14345
14481
  data: {
14346
14482
  id: state.options.deposit.depositRequestId
@@ -14348,6 +14484,7 @@ async function fetchData({
14348
14484
  });
14349
14485
  } else {
14350
14486
  state.data.deposit = new DepositRequestModel(
14487
+ // @ts-ignore TODO: refactor - customAmounts optional modifier not present in api-definitions.
14351
14488
  state.options.deposit
14352
14489
  );
14353
14490
  }
@@ -14355,12 +14492,15 @@ async function fetchData({
14355
14492
  let readyToPayPromise = Promise.resolve(null);
14356
14493
  let availableInstrumentsPromise = null;
14357
14494
  if ((_b = state.options) == null ? void 0 : _b.jwt) {
14358
- fetchAccountAndWebsite$1({ state }).then(({ account, website }) => {
14495
+ fetchAccountAndWebsite$1().then(({ account, website }) => {
14496
+ if (state.data == null) {
14497
+ throw new Error("Invalid data instance");
14498
+ }
14359
14499
  state.data.account = account;
14360
14500
  state.data.website = website;
14361
14501
  });
14362
14502
  readyToPayPromise = fetchReadyToPay();
14363
- availableInstrumentsPromise = fetchInstruments({ state });
14503
+ availableInstrumentsPromise = fetchInstruments();
14364
14504
  } else {
14365
14505
  readyToPayPromise = fetchReadyToPay();
14366
14506
  }
@@ -14382,15 +14522,15 @@ async function fetchData({
14382
14522
  productsPromise = Promise.resolve(products2);
14383
14523
  state.data.invoice = invoice;
14384
14524
  }
14385
- const previewPurchasePromise = state.options.items ? fetchSummary() : null;
14386
- if (!((_g = state.options) == null ? void 0 : _g.jwt)) {
14387
- productsPromise = fetchProductsFromPlans({ state });
14525
+ const previewPurchasePromise = ((_g = state.options) == null ? void 0 : _g.items) ? fetchSummary() : null;
14526
+ if (!((_h = state.options) == null ? void 0 : _h.jwt)) {
14527
+ productsPromise = fetchProductsFromPlans();
14388
14528
  }
14389
14529
  let plansPromise = new Promise((resolve2) => {
14390
14530
  resolve2([]);
14391
14531
  });
14392
- if (((_h = state.options) == null ? void 0 : _h.addons) || ((_i = state.options) == null ? void 0 : _i.bumpOffer)) {
14393
- plansPromise = fetchPlansFromAddonsBumpOffer({ state });
14532
+ if (((_i = state.options) == null ? void 0 : _i.addons) || ((_j = state.options) == null ? void 0 : _j.bumpOffer)) {
14533
+ plansPromise = fetchPlansFromAddonsBumpOffer();
14394
14534
  }
14395
14535
  const [
14396
14536
  readyToPay,
@@ -15047,7 +15187,7 @@ const setupElement = ({ element = "" }) => {
15047
15187
  throw new Error('element must be "form" or "summary"');
15048
15188
  }
15049
15189
  const getProp = () => {
15050
- if (options[element]) {
15190
+ if (options != null && options[element]) {
15051
15191
  return options[element];
15052
15192
  }
15053
15193
  switch (element) {
@@ -15065,6 +15205,7 @@ const setupElement = ({ element = "" }) => {
15065
15205
  });
15066
15206
  };
15067
15207
  const setupStorefront = () => {
15208
+ validateOptions$1(state.options);
15068
15209
  const { publishableKey, organizationId, apiMode, _dev } = state.options;
15069
15210
  const storefront = {
15070
15211
  organizationId,
@@ -22142,9 +22283,6 @@ jsonSchema201909.default = addMetaSchema2019;
22142
22283
  })(_2019, _2019.exports);
22143
22284
  var _2019Exports = _2019.exports;
22144
22285
  const AJV = /* @__PURE__ */ getDefaultExportFromCjs(_2019Exports);
22145
- function optional(schema2) {
22146
- return schema2;
22147
- }
22148
22286
  const itemsSchema = {
22149
22287
  type: "array",
22150
22288
  items: {
@@ -22204,55 +22342,6 @@ const moneySchema = {
22204
22342
  },
22205
22343
  required: ["amount", "currency"]
22206
22344
  };
22207
- const depositRequestSchema = {
22208
- type: "object",
22209
- properties: {
22210
- depositRequestId: { type: "string" }
22211
- },
22212
- required: ["depositRequestId"]
22213
- };
22214
- const depositObjectSchema = {
22215
- type: "object",
22216
- properties: {
22217
- currency: {
22218
- type: "string",
22219
- minLength: 3,
22220
- maxLength: 3
22221
- },
22222
- amount: optional({
22223
- type: "number"
22224
- }),
22225
- buttons: optional({
22226
- type: "array",
22227
- items: {
22228
- type: "number"
22229
- }
22230
- }),
22231
- editable: optional({ type: "boolean" }),
22232
- customAmount: optional({
22233
- type: "object",
22234
- properties: {
22235
- minimum: optional({ type: "number" }),
22236
- maximum: optional({ type: "number" }),
22237
- multipleOf: optional({ type: "number" })
22238
- },
22239
- required: []
22240
- })
22241
- },
22242
- anyOf: [
22243
- {
22244
- required: ["amount"]
22245
- },
22246
- {
22247
- required: ["buttons"]
22248
- }
22249
- ],
22250
- required: ["currency"]
22251
- };
22252
- const depositSchema = {
22253
- type: "object",
22254
- oneOf: [depositRequestSchema, depositObjectSchema]
22255
- };
22256
22345
  const i18nSchema = {
22257
22346
  type: "object",
22258
22347
  patternProperties: {
@@ -23081,19 +23170,20 @@ ${displayNode}`
23081
23170
  "Configuration is invalid"
23082
23171
  ).trimStack()
23083
23172
  );
23084
- return void 0;
23173
+ return null;
23085
23174
  }
23086
23175
  function handleComputedProperty(options) {
23087
23176
  var _a;
23088
- options._computed = {
23089
- version: "7.3.0",
23090
- paymentMethodsUrl: ((_a = options._dev) == null ? void 0 : _a.paymentMethodsUrl) ?? "https://forms.secure-payments.app"
23091
- };
23092
- return options;
23177
+ return Object.assign({}, options, {
23178
+ _computed: {
23179
+ version: "7.3.1",
23180
+ paymentMethodsUrl: ((_a = options._dev) == null ? void 0 : _a.paymentMethodsUrl) ?? "https://forms.secure-payments.app"
23181
+ }
23182
+ });
23093
23183
  }
23094
23184
  function handleNestedPropertiesDefaultValues(options) {
23095
- var _a, _b;
23096
- if ((_a = options.deposit) == null ? void 0 : _a.currency) {
23185
+ var _a;
23186
+ if (!isDepositRequest(options.deposit) && ((_a = options.deposit) == null ? void 0 : _a.currency)) {
23097
23187
  options.deposit = merge$1(
23098
23188
  {
23099
23189
  editable: true,
@@ -23107,11 +23197,11 @@ function handleNestedPropertiesDefaultValues(options) {
23107
23197
  options.deposit || {}
23108
23198
  );
23109
23199
  if (Number.isNaN(options.deposit.amount)) {
23110
- if (options.deposit.buttons.length > 0) {
23200
+ if (options.deposit.buttons && options.deposit.buttons.length > 0) {
23111
23201
  [options.deposit.amount] = options.deposit.buttons;
23112
23202
  }
23113
23203
  }
23114
- } else if ((_b = options.deposit) == null ? void 0 : _b.depositRequestId) {
23204
+ } else if (isDepositRequest(options.deposit)) {
23115
23205
  options.deposit = merge$1(
23116
23206
  {
23117
23207
  customAmount: {
@@ -23148,13 +23238,19 @@ function handleJwtDestructuring(options) {
23148
23238
  }
23149
23239
  });
23150
23240
  if (cashierRequestId && !options.deposit) {
23151
- options.deposit = {};
23152
- options.deposit.depositRequestId = cashierRequestId;
23241
+ options.deposit = Object.assign(
23242
+ {},
23243
+ {
23244
+ depositRequestId: cashierRequestId
23245
+ }
23246
+ );
23153
23247
  }
23154
23248
  }
23155
23249
  return options;
23156
23250
  }
23157
- const setupOptions = ({ options = {} } = {}) => {
23251
+ const setupOptions = ({
23252
+ options = {}
23253
+ } = {}) => {
23158
23254
  let validOptions = validateOptions(options);
23159
23255
  if (validOptions) {
23160
23256
  validOptions = handleJwtDestructuring(validOptions);
@@ -25515,6 +25611,7 @@ function minifyCss(_content) {
25515
25611
  return content2;
25516
25612
  }
25517
25613
  const setupStylesVars = () => {
25614
+ validateOptions$1(state.options);
25518
25615
  const { theme: theme2 = {}, css } = state.options;
25519
25616
  const styleVars = mainStyleVars(theme2 || {});
25520
25617
  addDOMElement({
@@ -25550,7 +25647,7 @@ const setupI18n = () => {
25550
25647
  };
25551
25648
  function processCSS(rawCss) {
25552
25649
  const cssMap = {};
25553
- [...rawCss.matchAll(/(--rebilly.*(?=:))[:\s](.*(?=;))/g)].forEach(
25650
+ Array.from(rawCss.matchAll(/(--rebilly.*(?=:))[:\s](.*(?=;))/g)).forEach(
25554
25651
  (item) => {
25555
25652
  cssMap[item[1]] = item[2].trim();
25556
25653
  }
@@ -25560,8 +25657,10 @@ function processCSS(rawCss) {
25560
25657
  if (cssVariables) {
25561
25658
  let cssValue = value;
25562
25659
  cssVariables.forEach((variable) => {
25563
- const cssVarName = variable.match(/\((.*)\)/i)[1];
25564
- cssValue = value.replace(variable, cssMap[cssVarName]);
25660
+ const cssVar = variable.match(/\((.*)\)/i);
25661
+ if (cssVar) {
25662
+ cssValue = value.replace(variable, cssMap[cssVar[1]]);
25663
+ }
25565
25664
  });
25566
25665
  return parseValue(cssValue);
25567
25666
  }
@@ -25652,6 +25751,7 @@ function on({ eventName, callback }) {
25652
25751
  }
25653
25752
  async function postPurchase({ data: data2 }) {
25654
25753
  return Endpoint(async () => {
25754
+ validateStorefront(state.storefront);
25655
25755
  const purchaseSchemaKeys = [
25656
25756
  "websiteId",
25657
25757
  "paymentInstruction",
@@ -25673,6 +25773,7 @@ async function postPurchase({ data: data2 }) {
25673
25773
  }
25674
25774
  async function postPayment({ data: data2 }) {
25675
25775
  return Endpoint(async () => {
25776
+ validateStorefront(state.storefront);
25676
25777
  const {
25677
25778
  token,
25678
25779
  transactionId,
@@ -26042,7 +26143,10 @@ async function show({ componentName, payload }) {
26042
26143
  throw new Error(`'${componentName}' not a supported component`);
26043
26144
  }
26044
26145
  }
26045
- function showResult({ state: state2, payload }) {
26146
+ function showResult({
26147
+ state: state2,
26148
+ payload
26149
+ }) {
26046
26150
  show({
26047
26151
  componentName: "result",
26048
26152
  payload,
@@ -26050,22 +26154,21 @@ function showResult({ state: state2, payload }) {
26050
26154
  });
26051
26155
  }
26052
26156
  const setupUserFlow = ({ state: state2 = {} }) => {
26053
- if (state2.options.features.autoConfirmation) {
26157
+ var _a, _b, _c, _d;
26158
+ if ((_b = (_a = state2.options) == null ? void 0 : _a.features) == null ? void 0 : _b.autoConfirmation) {
26054
26159
  on({
26055
26160
  eventName: "instrument-ready",
26056
26161
  callback: (payload) => {
26057
- var _a;
26058
- if (((_a = payload._raw) == null ? void 0 : _a.method) === "paypal") {
26059
- if (!state2.data.isShippingRequired) {
26060
- if (state2.options.transactionType === "setup") {
26061
- setup({ state: state2, payload });
26162
+ var _a2, _b2, _c2, _d2;
26163
+ if (((_a2 = payload._raw) == null ? void 0 : _a2.method) === "paypal") {
26164
+ if (!((_b2 = state2.data) == null ? void 0 : _b2.isShippingRequired)) {
26165
+ if (((_c2 = state2.options) == null ? void 0 : _c2.transactionType) === "setup") {
26166
+ setup({ payload });
26062
26167
  } else {
26063
- purchase({ state: state2, payload });
26168
+ purchase({ payload });
26064
26169
  }
26065
- state2.loader.startLoading({
26066
- state: state2,
26067
- id: "express-purchase",
26068
- message: "form.loaderMessages.processingPayment"
26170
+ (_d2 = state2.loader) == null ? void 0 : _d2.startLoading({
26171
+ id: "express-purchase"
26069
26172
  });
26070
26173
  return;
26071
26174
  }
@@ -26078,7 +26181,7 @@ const setupUserFlow = ({ state: state2 = {} }) => {
26078
26181
  }
26079
26182
  });
26080
26183
  }
26081
- if (state2.options.features.autoResult) {
26184
+ if ((_d = (_c = state2.options) == null ? void 0 : _c.features) == null ? void 0 : _d.autoResult) {
26082
26185
  on({
26083
26186
  eventName: "purchase-completed",
26084
26187
  callback: (payload) => {
@@ -26099,20 +26202,24 @@ async function mount({
26099
26202
  setupFramepay: setupFramepay$1 = setupFramepay,
26100
26203
  ...options
26101
26204
  } = {}) {
26102
- var _a, _b, _c, _d, _e, _f, _g;
26205
+ var _a, _b, _c, _d, _e, _f, _g, _h;
26103
26206
  try {
26104
26207
  state.data = {};
26105
26208
  state.options = {};
26106
26209
  state.options = setupOptions({ options });
26107
26210
  state.form = setupElement({ element: "form" });
26108
26211
  state.summary = setupElement({ element: "summary" });
26109
- state.form.style.maxWidth = "750px";
26212
+ if (state.form) {
26213
+ state.form.style.maxWidth = "750px";
26214
+ }
26110
26215
  if (state.summary) {
26111
26216
  state.summary.style.maxWidth = "750px";
26112
26217
  }
26113
26218
  state.storefront = setupStorefront();
26114
26219
  state.mainStyleVars = setupStylesVars();
26115
- state.options.themeFramepay = setupFramepayTheme();
26220
+ if (state.options) {
26221
+ state.options.themeFramepay = setupFramepayTheme();
26222
+ }
26116
26223
  state.loader.addDOMElement({ el: state.form });
26117
26224
  state.loader.addDOMElement({ section: "summary", el: state.summary });
26118
26225
  state.loader.startLoading({
@@ -26124,12 +26231,12 @@ async function mount({
26124
26231
  state.data = data2;
26125
26232
  events.dataReady.dispatch(state.data);
26126
26233
  state.i18n = setupI18n();
26127
- if (!state.options.websiteId && ((_a = state.data.transaction) == null ? void 0 : _a.websiteId)) {
26234
+ if (state.options && !state.options.websiteId && ((_a = state.data.transaction) == null ? void 0 : _a.websiteId)) {
26128
26235
  state.options.websiteId = state.data.transaction.websiteId;
26129
- } else if (!state.options.websiteId && ((_b = state.data.invoice) == null ? void 0 : _b.websiteId)) {
26236
+ } else if (state.options && !state.options.websiteId && ((_b = state.data.invoice) == null ? void 0 : _b.websiteId)) {
26130
26237
  state.options.websiteId = state.data.invoice.websiteId;
26131
26238
  }
26132
- if (state.data.transaction && ((_c = state.data.transaction) == null ? void 0 : _c.type) === "setup") {
26239
+ if (state.options && state.data.transaction && ((_c = state.data.transaction) == null ? void 0 : _c.type) === "setup") {
26133
26240
  state.options.transactionType = "setup";
26134
26241
  }
26135
26242
  if (state.form) {
@@ -26138,10 +26245,10 @@ async function mount({
26138
26245
  if (state.summary) {
26139
26246
  mountSummary();
26140
26247
  }
26141
- state.i18n({ state });
26248
+ state.i18n();
26142
26249
  state.hasMounted = true;
26143
26250
  const invoiceId = ((_d = state.options) == null ? void 0 : _d.invoiceId) || ((_f = (_e = state.data) == null ? void 0 : _e.transaction) == null ? void 0 : _f.invoiceId);
26144
- if (invoiceId && state.data.invoice.isPaid) {
26251
+ if (invoiceId && ((_g = state.data.invoice) == null ? void 0 : _g.isPaid)) {
26145
26252
  state.loader.stopLoading({ id: "rebilly-instruments-form" });
26146
26253
  removeForm();
26147
26254
  showError(
@@ -26149,7 +26256,7 @@ async function mount({
26149
26256
  false
26150
26257
  );
26151
26258
  }
26152
- if (!((_g = data2.readyToPay) == null ? void 0 : _g.length)) {
26259
+ if (!((_h = data2.readyToPay) == null ? void 0 : _h.length)) {
26153
26260
  state.loader.stopLoading({ id: "rebilly-instruments-form" });
26154
26261
  showError(
26155
26262
  state.translate.getTranslation("form.error.noPaymentMethods")
@@ -26217,7 +26324,7 @@ class RebillyInstrumentsInstance {
26217
26324
  await show({ componentName, payload });
26218
26325
  }
26219
26326
  get version() {
26220
- return `RebillyInstruments Ver.${"7.3.0"}`;
26327
+ return `RebillyInstruments Ver.${"7.3.1"}`;
26221
26328
  }
26222
26329
  on(eventName, callback) {
26223
26330
  on({ eventName, callback });