@usethrottle/discounts 0.2.1 → 0.4.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/CLAUDE.md +7 -0
- package/README.md +5 -0
- package/dist/index.cjs +10 -11
- package/dist/index.d.cts +11 -6
- package/dist/index.d.ts +11 -6
- package/dist/index.js +7 -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/README.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
<p align="left">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/Epic-Design-Labs/app-throttle/main/packages/brand/assets/throttle-logo.png" alt="Throttle" height="56" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
|
|
1
6
|
# @usethrottle/discounts
|
|
2
7
|
|
|
3
8
|
Headless TypeScript client for Throttle discount codes.
|
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
|
|
|
@@ -96,7 +94,6 @@ var DiscountsClient = class {
|
|
|
96
94
|
async list(params = {}) {
|
|
97
95
|
const query = new URLSearchParams();
|
|
98
96
|
if (params.q) query.set("q", params.q);
|
|
99
|
-
if (params.storeId) query.set("storeId", params.storeId);
|
|
100
97
|
if (params.isActive !== void 0) query.set("isActive", String(params.isActive));
|
|
101
98
|
if (params.code) query.set("code", params.code);
|
|
102
99
|
if (params.type) query.set("type", params.type);
|
|
@@ -161,5 +158,7 @@ function serializeDates(input) {
|
|
|
161
158
|
0 && (module.exports = {
|
|
162
159
|
DiscountsClient,
|
|
163
160
|
ThrottleDiscountsError,
|
|
164
|
-
|
|
161
|
+
ThrottleError,
|
|
162
|
+
createDiscountsClient,
|
|
163
|
+
isThrottleError
|
|
165
164
|
});
|
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
|
type DiscountType = 'percentage' | 'fixed_amount';
|
|
2
5
|
interface Discount {
|
|
3
6
|
id: string;
|
|
@@ -16,7 +19,6 @@ interface Discount {
|
|
|
16
19
|
createdAt: string;
|
|
17
20
|
}
|
|
18
21
|
interface CreateDiscountInput {
|
|
19
|
-
storeId?: string;
|
|
20
22
|
code?: string;
|
|
21
23
|
name: string;
|
|
22
24
|
type: DiscountType;
|
|
@@ -41,7 +43,6 @@ interface UpdateDiscountInput {
|
|
|
41
43
|
}
|
|
42
44
|
interface DiscountListParams {
|
|
43
45
|
q?: string;
|
|
44
|
-
storeId?: string;
|
|
45
46
|
isActive?: boolean;
|
|
46
47
|
code?: string;
|
|
47
48
|
type?: DiscountType;
|
|
@@ -132,10 +133,14 @@ declare class DiscountsClient {
|
|
|
132
133
|
}
|
|
133
134
|
declare function createDiscountsClient(opts: DiscountsClientOptions): DiscountsClient;
|
|
134
135
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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 {
|
|
139
144
|
constructor(args: {
|
|
140
145
|
code: string;
|
|
141
146
|
message: 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
|
type DiscountType = 'percentage' | 'fixed_amount';
|
|
2
5
|
interface Discount {
|
|
3
6
|
id: string;
|
|
@@ -16,7 +19,6 @@ interface Discount {
|
|
|
16
19
|
createdAt: string;
|
|
17
20
|
}
|
|
18
21
|
interface CreateDiscountInput {
|
|
19
|
-
storeId?: string;
|
|
20
22
|
code?: string;
|
|
21
23
|
name: string;
|
|
22
24
|
type: DiscountType;
|
|
@@ -41,7 +43,6 @@ interface UpdateDiscountInput {
|
|
|
41
43
|
}
|
|
42
44
|
interface DiscountListParams {
|
|
43
45
|
q?: string;
|
|
44
|
-
storeId?: string;
|
|
45
46
|
isActive?: boolean;
|
|
46
47
|
code?: string;
|
|
47
48
|
type?: DiscountType;
|
|
@@ -132,10 +133,14 @@ declare class DiscountsClient {
|
|
|
132
133
|
}
|
|
133
134
|
declare function createDiscountsClient(opts: DiscountsClientOptions): DiscountsClient;
|
|
134
135
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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 {
|
|
139
144
|
constructor(args: {
|
|
140
145
|
code: string;
|
|
141
146
|
message: 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 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
|
|
|
@@ -68,7 +64,6 @@ var DiscountsClient = class {
|
|
|
68
64
|
async list(params = {}) {
|
|
69
65
|
const query = new URLSearchParams();
|
|
70
66
|
if (params.q) query.set("q", params.q);
|
|
71
|
-
if (params.storeId) query.set("storeId", params.storeId);
|
|
72
67
|
if (params.isActive !== void 0) query.set("isActive", String(params.isActive));
|
|
73
68
|
if (params.code) query.set("code", params.code);
|
|
74
69
|
if (params.type) query.set("type", params.type);
|
|
@@ -132,5 +127,7 @@ function serializeDates(input) {
|
|
|
132
127
|
export {
|
|
133
128
|
DiscountsClient,
|
|
134
129
|
ThrottleDiscountsError,
|
|
135
|
-
|
|
130
|
+
ThrottleError2 as ThrottleError,
|
|
131
|
+
createDiscountsClient,
|
|
132
|
+
isThrottleError
|
|
136
133
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usethrottle/discounts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
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.0.0"
|
|
23
|
+
},
|
|
21
24
|
"devDependencies": {
|
|
22
25
|
"tsup": "^8.0.0",
|
|
23
26
|
"typescript": "^5.7.0",
|