@usethrottle/discounts 0.3.0 → 0.4.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/CLAUDE.md +7 -0
- package/dist/index.cjs +12 -11
- package/dist/index.d.cts +12 -4
- package/dist/index.d.ts +12 -4
- package/dist/index.js +9 -10
- package/package.json +4 -1
package/CLAUDE.md
CHANGED
|
@@ -15,6 +15,13 @@ Headless public SDK for Throttle discount and promotion code APIs.
|
|
|
15
15
|
`DELETE /api/v1/carts/:cartId/discount`.
|
|
16
16
|
- Never encourage exposing `THROTTLE_API_KEY` to buyer browsers.
|
|
17
17
|
|
|
18
|
+
## Errors
|
|
19
|
+
|
|
20
|
+
`ThrottleDiscountsError` extends the shared `ThrottleError` from
|
|
21
|
+
`@usethrottle/errors` (a `dependency`, `workspace:^`); the package re-exports
|
|
22
|
+
`ThrottleError` + `isThrottleError`. Keep it a subclass so a single
|
|
23
|
+
`instanceof ThrottleError` catches errors from every Throttle SDK.
|
|
24
|
+
|
|
18
25
|
## Testing
|
|
19
26
|
|
|
20
27
|
Focused commands:
|
package/dist/index.cjs
CHANGED
|
@@ -22,21 +22,19 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
DiscountsClient: () => DiscountsClient,
|
|
24
24
|
ThrottleDiscountsError: () => ThrottleDiscountsError,
|
|
25
|
-
|
|
25
|
+
ThrottleError: () => import_errors2.ThrottleError,
|
|
26
|
+
createDiscountsClient: () => createDiscountsClient,
|
|
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 ThrottleDiscountsError = class extends import_errors.ThrottleError {
|
|
34
35
|
constructor(args) {
|
|
35
|
-
super(args
|
|
36
|
+
super(args);
|
|
36
37
|
this.name = "ThrottleDiscountsError";
|
|
37
|
-
this.code = args.code;
|
|
38
|
-
this.statusCode = args.statusCode;
|
|
39
|
-
this.details = args.details;
|
|
40
38
|
}
|
|
41
39
|
};
|
|
42
40
|
|
|
@@ -79,7 +77,8 @@ var DiscountsClient = class {
|
|
|
79
77
|
code: json?.error?.code ?? "unknown_error",
|
|
80
78
|
message: json?.error?.message ?? `HTTP ${res.status}`,
|
|
81
79
|
statusCode: res.status,
|
|
82
|
-
details: json?.error?.details
|
|
80
|
+
details: json?.error?.details,
|
|
81
|
+
responseHeaders: res.headers
|
|
83
82
|
});
|
|
84
83
|
}
|
|
85
84
|
return {
|
|
@@ -160,5 +159,7 @@ function serializeDates(input) {
|
|
|
160
159
|
0 && (module.exports = {
|
|
161
160
|
DiscountsClient,
|
|
162
161
|
ThrottleDiscountsError,
|
|
163
|
-
|
|
162
|
+
ThrottleError,
|
|
163
|
+
createDiscountsClient,
|
|
164
|
+
isThrottleError
|
|
164
165
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { ThrottleError, ThrottleErrorArgs } from '@usethrottle/errors';
|
|
2
|
+
export { ThrottleError, isThrottleError } from '@usethrottle/errors';
|
|
3
|
+
|
|
1
4
|
type DiscountType = 'percentage' | 'fixed_amount';
|
|
2
5
|
interface Discount {
|
|
3
6
|
id: string;
|
|
@@ -130,15 +133,20 @@ declare class DiscountsClient {
|
|
|
130
133
|
}
|
|
131
134
|
declare function createDiscountsClient(opts: DiscountsClientOptions): DiscountsClient;
|
|
132
135
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Thrown on a non-2xx response from the Throttle Discounts API.
|
|
138
|
+
*
|
|
139
|
+
* Extends the shared {@link ThrottleError} so a single
|
|
140
|
+
* `catch (e) { if (e instanceof ThrottleError) … }` covers errors from every
|
|
141
|
+
* Throttle SDK. `instanceof ThrottleDiscountsError` keeps working.
|
|
142
|
+
*/
|
|
143
|
+
declare class ThrottleDiscountsError extends ThrottleError {
|
|
137
144
|
constructor(args: {
|
|
138
145
|
code: string;
|
|
139
146
|
message: string;
|
|
140
147
|
statusCode: number;
|
|
141
148
|
details?: unknown;
|
|
149
|
+
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
142
150
|
});
|
|
143
151
|
}
|
|
144
152
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { ThrottleError, ThrottleErrorArgs } from '@usethrottle/errors';
|
|
2
|
+
export { ThrottleError, isThrottleError } from '@usethrottle/errors';
|
|
3
|
+
|
|
1
4
|
type DiscountType = 'percentage' | 'fixed_amount';
|
|
2
5
|
interface Discount {
|
|
3
6
|
id: string;
|
|
@@ -130,15 +133,20 @@ declare class DiscountsClient {
|
|
|
130
133
|
}
|
|
131
134
|
declare function createDiscountsClient(opts: DiscountsClientOptions): DiscountsClient;
|
|
132
135
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Thrown on a non-2xx response from the Throttle Discounts API.
|
|
138
|
+
*
|
|
139
|
+
* Extends the shared {@link ThrottleError} so a single
|
|
140
|
+
* `catch (e) { if (e instanceof ThrottleError) … }` covers errors from every
|
|
141
|
+
* Throttle SDK. `instanceof ThrottleDiscountsError` keeps working.
|
|
142
|
+
*/
|
|
143
|
+
declare class ThrottleDiscountsError extends ThrottleError {
|
|
137
144
|
constructor(args: {
|
|
138
145
|
code: string;
|
|
139
146
|
message: string;
|
|
140
147
|
statusCode: number;
|
|
141
148
|
details?: unknown;
|
|
149
|
+
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
142
150
|
});
|
|
143
151
|
}
|
|
144
152
|
|
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 ThrottleDiscountsError = class extends ThrottleError {
|
|
6
5
|
constructor(args) {
|
|
7
|
-
super(args
|
|
6
|
+
super(args);
|
|
8
7
|
this.name = "ThrottleDiscountsError";
|
|
9
|
-
this.code = args.code;
|
|
10
|
-
this.statusCode = args.statusCode;
|
|
11
|
-
this.details = args.details;
|
|
12
8
|
}
|
|
13
9
|
};
|
|
14
10
|
|
|
@@ -51,7 +47,8 @@ var DiscountsClient = class {
|
|
|
51
47
|
code: json?.error?.code ?? "unknown_error",
|
|
52
48
|
message: json?.error?.message ?? `HTTP ${res.status}`,
|
|
53
49
|
statusCode: res.status,
|
|
54
|
-
details: json?.error?.details
|
|
50
|
+
details: json?.error?.details,
|
|
51
|
+
responseHeaders: res.headers
|
|
55
52
|
});
|
|
56
53
|
}
|
|
57
54
|
return {
|
|
@@ -131,5 +128,7 @@ function serializeDates(input) {
|
|
|
131
128
|
export {
|
|
132
129
|
DiscountsClient,
|
|
133
130
|
ThrottleDiscountsError,
|
|
134
|
-
|
|
131
|
+
ThrottleError2 as ThrottleError,
|
|
132
|
+
createDiscountsClient,
|
|
133
|
+
isThrottleError
|
|
135
134
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usethrottle/discounts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Headless TypeScript client for Throttle discount and promotion code APIs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
"README.md",
|
|
19
19
|
"CLAUDE.md"
|
|
20
20
|
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@usethrottle/errors": "^1.1.0"
|
|
23
|
+
},
|
|
21
24
|
"devDependencies": {
|
|
22
25
|
"tsup": "^8.0.0",
|
|
23
26
|
"typescript": "^5.7.0",
|