mppx 0.10.0 → 0.10.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.
@@ -148,7 +148,7 @@ export function create(config) {
148
148
  }
149
149
  }
150
150
  async function prepareRequest(input, init, options) {
151
- const { maxRedirects = 20, ...paymentOptions } = options ?? {};
151
+ const { maxRedirects = 20, requirePayment = false, ...paymentOptions } = options ?? {};
152
152
  const preparedHttp = await prepareHttpRequest({
153
153
  acceptPayment: acceptPayment.header,
154
154
  acceptPaymentPolicy,
@@ -159,8 +159,16 @@ export function create(config) {
159
159
  signer: attestationSigner,
160
160
  });
161
161
  const requestInit = requestToInit(preparedHttp.replayRequest, preparedHttp.body);
162
- if (!(await transport.isPaymentRequired(preparedHttp.response, requestInit)))
163
- throw new Error('Response does not require payment.');
162
+ if (!(await transport.isPaymentRequired(preparedHttp.response, requestInit))) {
163
+ if (requirePayment)
164
+ throw new Error('Response does not require payment.');
165
+ return Object.freeze({
166
+ payment: undefined,
167
+ request: preparedHttp.request,
168
+ response: preparedHttp.response,
169
+ redirects: preparedHttp.redirects,
170
+ });
171
+ }
164
172
  const payment = (await preparePayment(preparedHttp.response, {
165
173
  ...paymentOptions,
166
174
  request: requestInit,
@@ -176,12 +184,9 @@ export function create(config) {
176
184
  });
177
185
  return payment.createCredential(context);
178
186
  });
179
- return Object.freeze({
187
+ const preparedPayment = Object.freeze({
180
188
  ...payment,
181
189
  createCredential: createRequestCredential,
182
- request: preparedHttp.request,
183
- response: preparedHttp.response,
184
- redirects: preparedHttp.redirects,
185
190
  async pay(context) {
186
191
  const credential = await createRequestCredential(context);
187
192
  const paidInit = payment.setCredential(requestToInit(preparedHttp.replayRequest, preparedHttp.body), credential);
@@ -191,6 +196,12 @@ export function create(config) {
191
196
  });
192
197
  },
193
198
  });
199
+ return Object.freeze({
200
+ payment: preparedPayment,
201
+ request: preparedHttp.request,
202
+ response: preparedHttp.response,
203
+ redirects: preparedHttp.redirects,
204
+ });
194
205
  }
195
206
  return {
196
207
  fetch,
@@ -1,5 +1,5 @@
1
1
  /** Current mppx package version. */
2
- export declare const version = "0.10.0";
2
+ export declare const version = "0.10.1";
3
3
  /** Canonical SDK identifier for this mppx release. */
4
- export declare const sdkIdentifier = "mppx/0.10.0";
4
+ export declare const sdkIdentifier = "mppx/0.10.1";
5
5
  //# sourceMappingURL=version.d.ts.map
@@ -1,6 +1,6 @@
1
1
  // Generated by scripts/sync-version.ts.
2
2
  /** Current mppx package version. */
3
- export const version = '0.10.0';
3
+ export const version = '0.10.1';
4
4
  /** Canonical SDK identifier for this mppx release. */
5
5
  export const sdkIdentifier = `mppx/${version}`;
6
6
  //# sourceMappingURL=version.js.map