@rebilly/instruments 4.8.0 → 4.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebilly/instruments",
3
- "version": "4.8.0",
3
+ "version": "4.8.1",
4
4
  "author": "Rebilly",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -134,6 +134,13 @@ export async function fetchData({
134
134
  try {
135
135
  state.data = new DataInstance();
136
136
 
137
+ if (!riskMetadata) {
138
+ const { riskMetadata: data } = await collectData();
139
+ state.data.riskMetadata = data;
140
+ } else {
141
+ state.data.riskMetadata = riskMetadata;
142
+ }
143
+
137
144
  if (state.options?.deposit) {
138
145
  if (state.options.deposit.depositRequestId) {
139
146
  state.data.deposit = await fetchDepositRequest({
@@ -156,10 +163,10 @@ export async function fetchData({
156
163
  state.data.account = account;
157
164
  state.data.website = website;
158
165
  });
159
- readyToPayPromise = fetchReadyToPay({ riskMetadata });
166
+ readyToPayPromise = fetchReadyToPay();
160
167
  availableInstrumentsPromise = fetchInstruments({ state });
161
168
  } else {
162
- readyToPayPromise = fetchReadyToPay({ riskMetadata });
169
+ readyToPayPromise = fetchReadyToPay();
163
170
  }
164
171
 
165
172
  if (state.options?.transactionId) {
@@ -183,11 +190,6 @@ export async function fetchData({
183
190
  state.data.invoice = invoice;
184
191
  }
185
192
 
186
- if (!riskMetadata) {
187
- ({ riskMetadata } = await collectData());
188
- state.data.riskMetadata = riskMetadata;
189
- }
190
-
191
193
  const previewPurchasePromise = state.options.items
192
194
  ? fetchSummary()
193
195
  : null;
@@ -55,15 +55,15 @@ export function filterReadyToPay(readyToPay) {
55
55
  .filter(({ metadata }) => metadata.storefrontEnabled);
56
56
  }
57
57
 
58
- export async function fetchReadyToPay({ riskMetadata = null }) {
58
+ export async function fetchReadyToPay() {
59
59
  return Endpoint(async () => {
60
- if (!riskMetadata) {
60
+ if (!state.data.riskMetadata) {
61
61
  const { riskMetadata: data } = await collectData();
62
- riskMetadata = data;
62
+ state.data.riskMetadata = data;
63
63
  }
64
64
 
65
65
  const data = {
66
- riskMetadata,
66
+ riskMetadata: state.data.riskMetadata,
67
67
  };
68
68
 
69
69
  data.websiteId = state.options?.websiteId || null;
@@ -42,10 +42,8 @@ describe('Storefront API Ready to Pay', () => {
42
42
 
43
43
  vi.spyOn(instance.storefront.purchase, 'readyToPay');
44
44
 
45
- const riskMetadata = null;
46
45
  const response = await fetchReadyToPay({
47
46
  state: instance,
48
- riskMetadata,
49
47
  });
50
48
 
51
49
  expect(instance.storefront.purchase.readyToPay).toBeCalledTimes(1);
@@ -68,13 +66,11 @@ describe('Storefront API Ready to Pay', () => {
68
66
  });
69
67
 
70
68
  it('should throw errors with no options', async () => {
71
- const riskMetadata = null;
72
-
73
69
  const noConfigOrOptionsInstance = new StorefontTestingInstance({
74
70
  options: null,
75
71
  });
76
72
  await expectConfigurationError(
77
- fetchReadyToPay({ riskMetadata, state: noConfigOrOptionsInstance }),
73
+ fetchReadyToPay({ state: noConfigOrOptionsInstance }),
78
74
  );
79
75
  });
80
76
  });
@@ -36,9 +36,7 @@ export async function mountAmountSelector() {
36
36
  currency,
37
37
  };
38
38
 
39
- const readyToPayUpdated = await fetchReadyToPay({
40
- riskMetadata: state.data.riskMetadata,
41
- });
39
+ const readyToPayUpdated = await fetchReadyToPay();
42
40
 
43
41
  state.data.readyToPay = readyToPayUpdated;
44
42
 
@@ -31,7 +31,7 @@ it('should only return the allowed methods', async () => {
31
31
  },
32
32
  ]),
33
33
  );
34
- state.data.readyToPay = await fetchReadyToPay({});
34
+ state.data.readyToPay = await fetchReadyToPay();
35
35
 
36
36
  const results = getPaymentMethods();
37
37