@usethrottle/cart 3.2.0 → 3.3.0
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/README.md +27 -0
- package/dist/index.cjs +10 -10
- package/dist/index.d.cts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +7 -9
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -194,6 +194,33 @@ try {
|
|
|
194
194
|
}
|
|
195
195
|
```
|
|
196
196
|
|
|
197
|
+
`ThrottleApiError` extends the shared **`ThrottleError`** from
|
|
198
|
+
[`@usethrottle/errors`](https://www.npmjs.com/package/@usethrottle/errors),
|
|
199
|
+
re-exported here. If you use more than one Throttle SDK you can catch all of
|
|
200
|
+
their errors with a single check — `instanceof ThrottleApiError` keeps working:
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
import { ThrottleError } from '@usethrottle/cart'; // same class across every SDK
|
|
204
|
+
|
|
205
|
+
try {
|
|
206
|
+
await cart.items.add(cartId, item);
|
|
207
|
+
await checkout.completeSession(sessionId, payment);
|
|
208
|
+
} catch (e) {
|
|
209
|
+
if (e instanceof ThrottleError) {
|
|
210
|
+
console.error(e.statusCode, e.code, e.message);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Line item `imageUrl`
|
|
216
|
+
|
|
217
|
+
`imageUrl` accepts an absolute `http(s)` URL **or** a relative path like
|
|
218
|
+
`/images/x.png`. Relative paths are resolved to an absolute URL against your
|
|
219
|
+
application's storefront base URL so the image renders on the hosted checkout —
|
|
220
|
+
set it with `PUT /v1/embed-config { "storefrontBaseUrl": "https://yourstore.com" }`
|
|
221
|
+
(the first `allowedOrigin` is used as a fallback). A relative path with no
|
|
222
|
+
resolvable base returns `400 image_url_unresolvable`.
|
|
223
|
+
|
|
197
224
|
## Client options
|
|
198
225
|
|
|
199
226
|
| Option | Default | Description |
|
package/dist/index.cjs
CHANGED
|
@@ -22,21 +22,19 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
CartClient: () => CartClient,
|
|
24
24
|
StorefrontQuoteClient: () => StorefrontQuoteClient,
|
|
25
|
-
ThrottleApiError: () => ThrottleApiError
|
|
25
|
+
ThrottleApiError: () => ThrottleApiError,
|
|
26
|
+
ThrottleError: () => import_errors2.ThrottleError,
|
|
27
|
+
isThrottleError: () => import_errors2.isThrottleError
|
|
26
28
|
});
|
|
27
29
|
module.exports = __toCommonJS(index_exports);
|
|
28
30
|
|
|
29
31
|
// src/errors.ts
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
details;
|
|
32
|
+
var import_errors = require("@usethrottle/errors");
|
|
33
|
+
var import_errors2 = require("@usethrottle/errors");
|
|
34
|
+
var ThrottleApiError = class extends import_errors.ThrottleError {
|
|
34
35
|
constructor(args) {
|
|
35
|
-
super(args
|
|
36
|
+
super(args);
|
|
36
37
|
this.name = "ThrottleApiError";
|
|
37
|
-
this.code = args.code;
|
|
38
|
-
this.statusCode = args.statusCode;
|
|
39
|
-
this.details = args.details;
|
|
40
38
|
}
|
|
41
39
|
};
|
|
42
40
|
|
|
@@ -193,5 +191,7 @@ var StorefrontQuoteClient = class {
|
|
|
193
191
|
0 && (module.exports = {
|
|
194
192
|
CartClient,
|
|
195
193
|
StorefrontQuoteClient,
|
|
196
|
-
ThrottleApiError
|
|
194
|
+
ThrottleApiError,
|
|
195
|
+
ThrottleError,
|
|
196
|
+
isThrottleError
|
|
197
197
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { ThrottleError } from '@usethrottle/errors';
|
|
2
|
+
export { ThrottleError, isThrottleError } from '@usethrottle/errors';
|
|
3
|
+
|
|
1
4
|
interface Cart {
|
|
2
5
|
id: string;
|
|
3
6
|
workspaceId: string;
|
|
@@ -359,9 +362,14 @@ declare class StorefrontQuoteClient {
|
|
|
359
362
|
quote(input: ShippingTaxQuoteInput): Promise<ShippingTaxCalculationResponse>;
|
|
360
363
|
}
|
|
361
364
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
+
/**
|
|
366
|
+
* Thrown on a non-2xx response from the Throttle Cart API.
|
|
367
|
+
*
|
|
368
|
+
* Extends the shared {@link ThrottleError} so a single
|
|
369
|
+
* `catch (e) { if (e instanceof ThrottleError) … }` covers errors from every
|
|
370
|
+
* Throttle SDK. `instanceof ThrottleApiError` keeps working for existing code.
|
|
371
|
+
*/
|
|
372
|
+
declare class ThrottleApiError extends ThrottleError {
|
|
365
373
|
readonly details?: Record<string, unknown>;
|
|
366
374
|
constructor(args: {
|
|
367
375
|
code: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { ThrottleError } from '@usethrottle/errors';
|
|
2
|
+
export { ThrottleError, isThrottleError } from '@usethrottle/errors';
|
|
3
|
+
|
|
1
4
|
interface Cart {
|
|
2
5
|
id: string;
|
|
3
6
|
workspaceId: string;
|
|
@@ -359,9 +362,14 @@ declare class StorefrontQuoteClient {
|
|
|
359
362
|
quote(input: ShippingTaxQuoteInput): Promise<ShippingTaxCalculationResponse>;
|
|
360
363
|
}
|
|
361
364
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
+
/**
|
|
366
|
+
* Thrown on a non-2xx response from the Throttle Cart API.
|
|
367
|
+
*
|
|
368
|
+
* Extends the shared {@link ThrottleError} so a single
|
|
369
|
+
* `catch (e) { if (e instanceof ThrottleError) … }` covers errors from every
|
|
370
|
+
* Throttle SDK. `instanceof ThrottleApiError` keeps working for existing code.
|
|
371
|
+
*/
|
|
372
|
+
declare class ThrottleApiError extends ThrottleError {
|
|
365
373
|
readonly details?: Record<string, unknown>;
|
|
366
374
|
constructor(args: {
|
|
367
375
|
code: string;
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
// src/errors.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
details;
|
|
2
|
+
import { ThrottleError } from "@usethrottle/errors";
|
|
3
|
+
import { ThrottleError as ThrottleError2, isThrottleError } from "@usethrottle/errors";
|
|
4
|
+
var ThrottleApiError = class extends ThrottleError {
|
|
6
5
|
constructor(args) {
|
|
7
|
-
super(args
|
|
6
|
+
super(args);
|
|
8
7
|
this.name = "ThrottleApiError";
|
|
9
|
-
this.code = args.code;
|
|
10
|
-
this.statusCode = args.statusCode;
|
|
11
|
-
this.details = args.details;
|
|
12
8
|
}
|
|
13
9
|
};
|
|
14
10
|
|
|
@@ -164,5 +160,7 @@ var StorefrontQuoteClient = class {
|
|
|
164
160
|
export {
|
|
165
161
|
CartClient,
|
|
166
162
|
StorefrontQuoteClient,
|
|
167
|
-
ThrottleApiError
|
|
163
|
+
ThrottleApiError,
|
|
164
|
+
ThrottleError2 as ThrottleError,
|
|
165
|
+
isThrottleError
|
|
168
166
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usethrottle/cart",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Typed REST client for the Throttle Cart API.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
"dist",
|
|
18
18
|
"README.md"
|
|
19
19
|
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@usethrottle/errors": "^1.0.0"
|
|
22
|
+
},
|
|
20
23
|
"devDependencies": {
|
|
21
24
|
"tsup": "^8.0.0",
|
|
22
25
|
"vitest": "^2.1.9",
|