@acmekit/js-sdk 2.13.36 → 2.13.38
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/dist/admin/index.d.ts +34 -6
- package/dist/admin/index.d.ts.map +1 -1
- package/dist/admin/index.js +42 -3
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/workflow-execution.d.ts +0 -23
- package/dist/admin/workflow-execution.d.ts.map +1 -1
- package/dist/admin/workflow-execution.js +0 -35
- package/dist/admin/workflow-execution.js.map +1 -1
- package/dist/auth/index.d.ts +21 -38
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +24 -38
- package/dist/auth/index.js.map +1 -1
- package/dist/base/typed-api-namespace.d.ts +34 -0
- package/dist/base/typed-api-namespace.d.ts.map +1 -0
- package/dist/base/typed-api-namespace.js +47 -0
- package/dist/base/typed-api-namespace.js.map +1 -0
- package/dist/client-api/index.d.ts +31 -0
- package/dist/client-api/index.d.ts.map +1 -0
- package/dist/client-api/index.js +43 -0
- package/dist/client-api/index.js.map +1 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +32 -10
- package/dist/client.js.map +1 -1
- package/dist/esm/admin/index.d.ts +34 -6
- package/dist/esm/admin/index.d.ts.map +1 -1
- package/dist/esm/admin/index.js +42 -3
- package/dist/esm/admin/index.js.map +1 -1
- package/dist/esm/admin/workflow-execution.d.ts +0 -23
- package/dist/esm/admin/workflow-execution.d.ts.map +1 -1
- package/dist/esm/admin/workflow-execution.js +0 -45
- package/dist/esm/admin/workflow-execution.js.map +1 -1
- package/dist/esm/auth/index.d.ts +21 -38
- package/dist/esm/auth/index.d.ts.map +1 -1
- package/dist/esm/auth/index.js +24 -38
- package/dist/esm/auth/index.js.map +1 -1
- package/dist/esm/base/typed-api-namespace.d.ts +34 -0
- package/dist/esm/base/typed-api-namespace.d.ts.map +1 -0
- package/dist/esm/base/typed-api-namespace.js +43 -0
- package/dist/esm/base/typed-api-namespace.js.map +1 -0
- package/dist/esm/client-api/index.d.ts +31 -0
- package/dist/esm/client-api/index.d.ts.map +1 -0
- package/dist/esm/client-api/index.js +39 -0
- package/dist/esm/client-api/index.js.map +1 -0
- package/dist/esm/client.d.ts +1 -1
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +43 -11
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/index.d.ts +18 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +9 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/route-registry.d.ts +108 -0
- package/dist/esm/types/route-registry.d.ts.map +1 -0
- package/dist/esm/types/route-registry.js +2 -0
- package/dist/esm/types/route-registry.js.map +1 -0
- package/dist/esm/types.d.ts +6 -1
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/index.d.ts +18 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -6
- package/dist/index.js.map +1 -1
- package/dist/types/route-registry.d.ts +108 -0
- package/dist/types/route-registry.d.ts.map +1 -0
- package/dist/types/route-registry.js +3 -0
- package/dist/types/route-registry.js.map +1 -0
- package/dist/types.d.ts +6 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +12 -4
- package/dist/admin/workflow-definition.d.ts +0 -39
- package/dist/admin/workflow-definition.d.ts.map +0 -1
- package/dist/admin/workflow-definition.js +0 -24
- package/dist/admin/workflow-definition.js.map +0 -1
- package/dist/esm/admin/workflow-definition.d.ts +0 -39
- package/dist/esm/admin/workflow-definition.d.ts.map +0 -1
- package/dist/esm/admin/workflow-definition.js +0 -33
- package/dist/esm/admin/workflow-definition.js.map +0 -1
package/dist/esm/auth/index.d.ts
CHANGED
|
@@ -9,13 +9,11 @@ export declare class Auth {
|
|
|
9
9
|
* This method is used to retrieve a registration JWT token for a user, customer, or custom actor type. It sends a request to the
|
|
10
10
|
* [Retrieve Registration Token API route](https://docs.acmekit.com/api/store#auth_postactor_typeauth_provider_register).
|
|
11
11
|
*
|
|
12
|
-
* Then, it stores the returned token and passes it in the header of subsequent requests.
|
|
13
|
-
* [store.customer.create](https://docs.acmekit.com/resources/references/js-sdk/store/customer#create) method,
|
|
14
|
-
* for example, after calling this method.
|
|
12
|
+
* Then, it stores the returned token and passes it in the header of subsequent requests.
|
|
15
13
|
*
|
|
16
14
|
* Learn more in the [JS SDK Authentication](https://docs.acmekit.com/resources/js-sdk/auth/overview) guide.
|
|
17
15
|
*
|
|
18
|
-
* @param actor - The actor type. For example, `user` for admin user, or `customer` for
|
|
16
|
+
* @param actor - The actor type. For example, `user` for admin user, or `customer` for custom actor types.
|
|
19
17
|
* @param method - The authentication provider to use. For example, `emailpass` or `google`.
|
|
20
18
|
* @param payload - The data to pass in the request's body for authentication. When using the `emailpass` provider,
|
|
21
19
|
* you pass the email and password.
|
|
@@ -25,19 +23,15 @@ export declare class Auth {
|
|
|
25
23
|
*
|
|
26
24
|
* @example
|
|
27
25
|
* await sdk.auth.register(
|
|
28
|
-
* "
|
|
26
|
+
* "user",
|
|
29
27
|
* "emailpass",
|
|
30
28
|
* {
|
|
31
|
-
* email: "
|
|
29
|
+
* email: "user@example.com",
|
|
32
30
|
* password: "supersecret"
|
|
33
31
|
* }
|
|
34
32
|
* )
|
|
35
33
|
*
|
|
36
34
|
* // all subsequent requests will use the token in the header
|
|
37
|
-
* const { customer } = await sdk.store.customer.create({
|
|
38
|
-
* email: "customer@gmail.com",
|
|
39
|
-
* password: "supersecret"
|
|
40
|
-
* })
|
|
41
35
|
*/
|
|
42
36
|
register: (actor: string, method: string, payload: HttpTypes.AdminSignUpWithEmailPassword | Record<string, unknown>) => Promise<string>;
|
|
43
37
|
/**
|
|
@@ -53,7 +47,7 @@ export declare class Auth {
|
|
|
53
47
|
* :::note
|
|
54
48
|
*
|
|
55
49
|
* For an example of implementing third-party authentication, refer to the
|
|
56
|
-
* [
|
|
50
|
+
* [Custom Admin Authentication](https://docs.acmekit.com/resources/how-to-tutorials/how-to/admin/auth) guide.
|
|
57
51
|
*
|
|
58
52
|
* :::
|
|
59
53
|
*
|
|
@@ -71,7 +65,7 @@ export declare class Auth {
|
|
|
71
65
|
*
|
|
72
66
|
* Learn more in the [JS SDK Authentication](https://docs.acmekit.com/resources/js-sdk/auth/overview) guide.
|
|
73
67
|
*
|
|
74
|
-
* @param actor - The actor type. For example, `user` for admin user, or
|
|
68
|
+
* @param actor - The actor type. For example, `user` for admin user, or custom actor types.
|
|
75
69
|
* @param method - The authentication provider to use. For example, `emailpass` or `google`.
|
|
76
70
|
* @param payload - The data to pass in the request's body for authentication. When using the `emailpass` provider,
|
|
77
71
|
* you pass the email and password.
|
|
@@ -81,10 +75,10 @@ export declare class Auth {
|
|
|
81
75
|
*
|
|
82
76
|
* @example
|
|
83
77
|
* const result = await sdk.auth.login(
|
|
84
|
-
* "
|
|
78
|
+
* "user",
|
|
85
79
|
* "emailpass",
|
|
86
80
|
* {
|
|
87
|
-
* email: "
|
|
81
|
+
* email: "user@example.com",
|
|
88
82
|
* password: "supersecret"
|
|
89
83
|
* }
|
|
90
84
|
* )
|
|
@@ -96,24 +90,22 @@ export declare class Auth {
|
|
|
96
90
|
* return
|
|
97
91
|
* }
|
|
98
92
|
*
|
|
99
|
-
* //
|
|
93
|
+
* // user is now authenticated
|
|
100
94
|
* // all subsequent requests will use the token in the header
|
|
101
|
-
* const { customer } = await sdk.store.customer.retrieve()
|
|
102
95
|
*/
|
|
103
96
|
login: (actor: string, method: string, payload: HttpTypes.AdminSignInWithEmailPassword | Record<string, unknown>) => Promise<string | {
|
|
104
97
|
location: string;
|
|
105
98
|
}>;
|
|
106
99
|
/**
|
|
107
|
-
* This method is used to validate an Oauth callback from a third-party service, such as Google, for an admin user
|
|
100
|
+
* This method is used to validate an Oauth callback from a third-party service, such as Google, for an admin user or custom actor types.
|
|
108
101
|
* It sends a request to the [Validate Authentication Callback](https://docs.acmekit.com/api/admin#auth_postactor_typeauth_providercallback).
|
|
109
102
|
*
|
|
110
103
|
* The method stores the returned token and passes it in the header of subsequent requests. So, you can call the
|
|
111
|
-
*
|
|
112
|
-
* for example, after calling this method.
|
|
104
|
+
* {@link refresh} method, for example, after calling this method.
|
|
113
105
|
*
|
|
114
106
|
* Learn more in the [JS SDK Authentication](https://docs.acmekit.com/resources/js-sdk/auth/overview) guide.
|
|
115
107
|
*
|
|
116
|
-
* @param actor - The actor type. For example, `user` for admin user, or
|
|
108
|
+
* @param actor - The actor type. For example, `user` for admin user, or custom actor types.
|
|
117
109
|
* @param method - The authentication provider to use. For example, `google`.
|
|
118
110
|
* @param query - The query parameters from the Oauth callback, which should be passed to the API route. This includes query parameters like
|
|
119
111
|
* `code` and `state`.
|
|
@@ -123,7 +115,7 @@ export declare class Auth {
|
|
|
123
115
|
*
|
|
124
116
|
* @example
|
|
125
117
|
* await sdk.auth.callback(
|
|
126
|
-
* "
|
|
118
|
+
* "user",
|
|
127
119
|
* "google",
|
|
128
120
|
* {
|
|
129
121
|
* code: "123",
|
|
@@ -132,10 +124,6 @@ export declare class Auth {
|
|
|
132
124
|
* )
|
|
133
125
|
*
|
|
134
126
|
* // all subsequent requests will use the token in the header
|
|
135
|
-
* const { customer } = await sdk.store.customer.create({
|
|
136
|
-
* email: "customer@gmail.com",
|
|
137
|
-
* password: "supersecret"
|
|
138
|
-
* })
|
|
139
127
|
*
|
|
140
128
|
* @privateRemarks
|
|
141
129
|
* The callback expects all query parameters from the Oauth callback to be passed to
|
|
@@ -152,7 +140,7 @@ export declare class Auth {
|
|
|
152
140
|
* Learn more in the [JS SDK Authentication](https://docs.acmekit.com/resources/js-sdk/auth/overview) guide.
|
|
153
141
|
*
|
|
154
142
|
* For an example of implementing third-party authentication, refer to the
|
|
155
|
-
* [
|
|
143
|
+
* [Custom Admin Authentication](https://docs.acmekit.com/resources/how-to-tutorials/how-to/admin/auth) guide.
|
|
156
144
|
*
|
|
157
145
|
* @param headers - Headers to pass in the request
|
|
158
146
|
*
|
|
@@ -164,7 +152,6 @@ export declare class Auth {
|
|
|
164
152
|
* const token = await sdk.auth.refresh()
|
|
165
153
|
*
|
|
166
154
|
* // all subsequent requests will use the token in the header
|
|
167
|
-
* const { customer } = await sdk.store.customer.retrieve()
|
|
168
155
|
*/
|
|
169
156
|
refresh: (headers?: ClientHeaders) => Promise<string>;
|
|
170
157
|
/**
|
|
@@ -187,14 +174,12 @@ export declare class Auth {
|
|
|
187
174
|
*/
|
|
188
175
|
logout: () => Promise<void>;
|
|
189
176
|
/**
|
|
190
|
-
* This method requests a reset password token for an admin user
|
|
177
|
+
* This method requests a reset password token for an admin user or custom actor type.
|
|
191
178
|
* It sends a request to the [Generate Reset Password Token API route](https://docs.acmekit.com/api/admin#auth_postactor_typeauth_providerresetpassword).
|
|
192
179
|
*
|
|
193
180
|
* To reset the password later using the token delivered to the user, use the {@link updateProvider} method.
|
|
194
181
|
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
* @param actor - The actor type. For example, `user` for admin user, or `customer` for customer.
|
|
182
|
+
* @param actor - The actor type. For example, `user` for admin user, or custom actor types.
|
|
198
183
|
* @param provider - The authentication provider to use. For example, `emailpass`.
|
|
199
184
|
* @param body - The data required to identify the user.
|
|
200
185
|
*
|
|
@@ -202,10 +187,10 @@ export declare class Auth {
|
|
|
202
187
|
*
|
|
203
188
|
* @example
|
|
204
189
|
* sdk.auth.resetPassword(
|
|
205
|
-
* "
|
|
190
|
+
* "user",
|
|
206
191
|
* "emailpass",
|
|
207
192
|
* {
|
|
208
|
-
* identifier: "
|
|
193
|
+
* identifier: "user@example.com"
|
|
209
194
|
* }
|
|
210
195
|
* )
|
|
211
196
|
* .then(() => {
|
|
@@ -228,14 +213,12 @@ export declare class Auth {
|
|
|
228
213
|
/**
|
|
229
214
|
* This method is used to update user-related data authentication data.
|
|
230
215
|
*
|
|
231
|
-
* More specifically, use this method when updating the password of an admin user
|
|
216
|
+
* More specifically, use this method when updating the password of an admin user or
|
|
232
217
|
* custom actor type after requesting to reset their password with {@link resetPassword}.
|
|
233
218
|
*
|
|
234
219
|
* This method sends a request to [this API route](https://docs.acmekit.com/api/admin#auth_postactor_typeauth_providerupdate).
|
|
235
220
|
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
* @param actor - The actor type. For example, `user` for admin user, or `customer` for customer.
|
|
221
|
+
* @param actor - The actor type. For example, `user` for admin user, or custom actor types.
|
|
239
222
|
* @param provider - The authentication provider to use. For example, `emailpass`.
|
|
240
223
|
* @param body - The data necessary to update the user's authentication data. When resetting the user's password,
|
|
241
224
|
* send the `password` property.
|
|
@@ -244,7 +227,7 @@ export declare class Auth {
|
|
|
244
227
|
*
|
|
245
228
|
* @example
|
|
246
229
|
* sdk.auth.updateProvider(
|
|
247
|
-
* "
|
|
230
|
+
* "user",
|
|
248
231
|
* "emailpass",
|
|
249
232
|
* {
|
|
250
233
|
* password: "supersecret"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEhD,qBAAa,IAAI;IACf,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,MAAM,CAAQ;gBAEV,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK1C
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEhD,qBAAa,IAAI;IACf,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,MAAM,CA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 -13,13 +13,11 @@ export class Auth {
|
|
|
13
13
|
* This method is used to retrieve a registration JWT token for a user, customer, or custom actor type. It sends a request to the
|
|
14
14
|
* [Retrieve Registration Token API route](https://docs.acmekit.com/api/store#auth_postactor_typeauth_provider_register).
|
|
15
15
|
*
|
|
16
|
-
* Then, it stores the returned token and passes it in the header of subsequent requests.
|
|
17
|
-
* [store.customer.create](https://docs.acmekit.com/resources/references/js-sdk/store/customer#create) method,
|
|
18
|
-
* for example, after calling this method.
|
|
16
|
+
* Then, it stores the returned token and passes it in the header of subsequent requests.
|
|
19
17
|
*
|
|
20
18
|
* Learn more in the [JS SDK Authentication](https://docs.acmekit.com/resources/js-sdk/auth/overview) guide.
|
|
21
19
|
*
|
|
22
|
-
* @param actor - The actor type. For example, `user` for admin user, or `customer` for
|
|
20
|
+
* @param actor - The actor type. For example, `user` for admin user, or `customer` for custom actor types.
|
|
23
21
|
* @param method - The authentication provider to use. For example, `emailpass` or `google`.
|
|
24
22
|
* @param payload - The data to pass in the request's body for authentication. When using the `emailpass` provider,
|
|
25
23
|
* you pass the email and password.
|
|
@@ -29,19 +27,15 @@ export class Auth {
|
|
|
29
27
|
*
|
|
30
28
|
* @example
|
|
31
29
|
* await sdk.auth.register(
|
|
32
|
-
* "
|
|
30
|
+
* "user",
|
|
33
31
|
* "emailpass",
|
|
34
32
|
* {
|
|
35
|
-
* email: "
|
|
33
|
+
* email: "user@example.com",
|
|
36
34
|
* password: "supersecret"
|
|
37
35
|
* }
|
|
38
36
|
* )
|
|
39
37
|
*
|
|
40
38
|
* // all subsequent requests will use the token in the header
|
|
41
|
-
* const { customer } = await sdk.store.customer.create({
|
|
42
|
-
* email: "customer@gmail.com",
|
|
43
|
-
* password: "supersecret"
|
|
44
|
-
* })
|
|
45
39
|
*/
|
|
46
40
|
this.register = (actor, method, payload) => __awaiter(this, void 0, void 0, function* () {
|
|
47
41
|
const { token } = yield this.client.fetch(`/auth/${actor}/${method}/register`, {
|
|
@@ -64,7 +58,7 @@ export class Auth {
|
|
|
64
58
|
* :::note
|
|
65
59
|
*
|
|
66
60
|
* For an example of implementing third-party authentication, refer to the
|
|
67
|
-
* [
|
|
61
|
+
* [Custom Admin Authentication](https://docs.acmekit.com/resources/how-to-tutorials/how-to/admin/auth) guide.
|
|
68
62
|
*
|
|
69
63
|
* :::
|
|
70
64
|
*
|
|
@@ -82,7 +76,7 @@ export class Auth {
|
|
|
82
76
|
*
|
|
83
77
|
* Learn more in the [JS SDK Authentication](https://docs.acmekit.com/resources/js-sdk/auth/overview) guide.
|
|
84
78
|
*
|
|
85
|
-
* @param actor - The actor type. For example, `user` for admin user, or
|
|
79
|
+
* @param actor - The actor type. For example, `user` for admin user, or custom actor types.
|
|
86
80
|
* @param method - The authentication provider to use. For example, `emailpass` or `google`.
|
|
87
81
|
* @param payload - The data to pass in the request's body for authentication. When using the `emailpass` provider,
|
|
88
82
|
* you pass the email and password.
|
|
@@ -92,10 +86,10 @@ export class Auth {
|
|
|
92
86
|
*
|
|
93
87
|
* @example
|
|
94
88
|
* const result = await sdk.auth.login(
|
|
95
|
-
* "
|
|
89
|
+
* "user",
|
|
96
90
|
* "emailpass",
|
|
97
91
|
* {
|
|
98
|
-
* email: "
|
|
92
|
+
* email: "user@example.com",
|
|
99
93
|
* password: "supersecret"
|
|
100
94
|
* }
|
|
101
95
|
* )
|
|
@@ -107,9 +101,8 @@ export class Auth {
|
|
|
107
101
|
* return
|
|
108
102
|
* }
|
|
109
103
|
*
|
|
110
|
-
* //
|
|
104
|
+
* // user is now authenticated
|
|
111
105
|
* // all subsequent requests will use the token in the header
|
|
112
|
-
* const { customer } = await sdk.store.customer.retrieve()
|
|
113
106
|
*/
|
|
114
107
|
this.login = (actor, method, payload) => __awaiter(this, void 0, void 0, function* () {
|
|
115
108
|
// There will either be token or location returned from the backend.
|
|
@@ -122,20 +115,22 @@ export class Auth {
|
|
|
122
115
|
if (location) {
|
|
123
116
|
return { location };
|
|
124
117
|
}
|
|
118
|
+
if (!token) {
|
|
119
|
+
throw new Error("Unexpected auth response: server returned neither a token nor a redirect location.");
|
|
120
|
+
}
|
|
125
121
|
yield this.setToken_(token);
|
|
126
122
|
return token;
|
|
127
123
|
});
|
|
128
124
|
/**
|
|
129
|
-
* This method is used to validate an Oauth callback from a third-party service, such as Google, for an admin user
|
|
125
|
+
* This method is used to validate an Oauth callback from a third-party service, such as Google, for an admin user or custom actor types.
|
|
130
126
|
* It sends a request to the [Validate Authentication Callback](https://docs.acmekit.com/api/admin#auth_postactor_typeauth_providercallback).
|
|
131
127
|
*
|
|
132
128
|
* The method stores the returned token and passes it in the header of subsequent requests. So, you can call the
|
|
133
|
-
*
|
|
134
|
-
* for example, after calling this method.
|
|
129
|
+
* {@link refresh} method, for example, after calling this method.
|
|
135
130
|
*
|
|
136
131
|
* Learn more in the [JS SDK Authentication](https://docs.acmekit.com/resources/js-sdk/auth/overview) guide.
|
|
137
132
|
*
|
|
138
|
-
* @param actor - The actor type. For example, `user` for admin user, or
|
|
133
|
+
* @param actor - The actor type. For example, `user` for admin user, or custom actor types.
|
|
139
134
|
* @param method - The authentication provider to use. For example, `google`.
|
|
140
135
|
* @param query - The query parameters from the Oauth callback, which should be passed to the API route. This includes query parameters like
|
|
141
136
|
* `code` and `state`.
|
|
@@ -145,7 +140,7 @@ export class Auth {
|
|
|
145
140
|
*
|
|
146
141
|
* @example
|
|
147
142
|
* await sdk.auth.callback(
|
|
148
|
-
* "
|
|
143
|
+
* "user",
|
|
149
144
|
* "google",
|
|
150
145
|
* {
|
|
151
146
|
* code: "123",
|
|
@@ -154,10 +149,6 @@ export class Auth {
|
|
|
154
149
|
* )
|
|
155
150
|
*
|
|
156
151
|
* // all subsequent requests will use the token in the header
|
|
157
|
-
* const { customer } = await sdk.store.customer.create({
|
|
158
|
-
* email: "customer@gmail.com",
|
|
159
|
-
* password: "supersecret"
|
|
160
|
-
* })
|
|
161
152
|
*
|
|
162
153
|
* @privateRemarks
|
|
163
154
|
* The callback expects all query parameters from the Oauth callback to be passed to
|
|
@@ -181,7 +172,7 @@ export class Auth {
|
|
|
181
172
|
* Learn more in the [JS SDK Authentication](https://docs.acmekit.com/resources/js-sdk/auth/overview) guide.
|
|
182
173
|
*
|
|
183
174
|
* For an example of implementing third-party authentication, refer to the
|
|
184
|
-
* [
|
|
175
|
+
* [Custom Admin Authentication](https://docs.acmekit.com/resources/how-to-tutorials/how-to/admin/auth) guide.
|
|
185
176
|
*
|
|
186
177
|
* @param headers - Headers to pass in the request
|
|
187
178
|
*
|
|
@@ -193,7 +184,6 @@ export class Auth {
|
|
|
193
184
|
* const token = await sdk.auth.refresh()
|
|
194
185
|
*
|
|
195
186
|
* // all subsequent requests will use the token in the header
|
|
196
|
-
* const { customer } = await sdk.store.customer.retrieve()
|
|
197
187
|
*/
|
|
198
188
|
this.refresh = (headers) => __awaiter(this, void 0, void 0, function* () {
|
|
199
189
|
const { token } = yield this.client.fetch("/auth/token/refresh", {
|
|
@@ -233,14 +223,12 @@ export class Auth {
|
|
|
233
223
|
this.client.clearToken();
|
|
234
224
|
});
|
|
235
225
|
/**
|
|
236
|
-
* This method requests a reset password token for an admin user
|
|
226
|
+
* This method requests a reset password token for an admin user or custom actor type.
|
|
237
227
|
* It sends a request to the [Generate Reset Password Token API route](https://docs.acmekit.com/api/admin#auth_postactor_typeauth_providerresetpassword).
|
|
238
228
|
*
|
|
239
229
|
* To reset the password later using the token delivered to the user, use the {@link updateProvider} method.
|
|
240
230
|
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
* @param actor - The actor type. For example, `user` for admin user, or `customer` for customer.
|
|
231
|
+
* @param actor - The actor type. For example, `user` for admin user, or custom actor types.
|
|
244
232
|
* @param provider - The authentication provider to use. For example, `emailpass`.
|
|
245
233
|
* @param body - The data required to identify the user.
|
|
246
234
|
*
|
|
@@ -248,10 +236,10 @@ export class Auth {
|
|
|
248
236
|
*
|
|
249
237
|
* @example
|
|
250
238
|
* sdk.auth.resetPassword(
|
|
251
|
-
* "
|
|
239
|
+
* "user",
|
|
252
240
|
* "emailpass",
|
|
253
241
|
* {
|
|
254
|
-
* identifier: "
|
|
242
|
+
* identifier: "user@example.com"
|
|
255
243
|
* }
|
|
256
244
|
* )
|
|
257
245
|
* .then(() => {
|
|
@@ -268,14 +256,12 @@ export class Auth {
|
|
|
268
256
|
/**
|
|
269
257
|
* This method is used to update user-related data authentication data.
|
|
270
258
|
*
|
|
271
|
-
* More specifically, use this method when updating the password of an admin user
|
|
259
|
+
* More specifically, use this method when updating the password of an admin user or
|
|
272
260
|
* custom actor type after requesting to reset their password with {@link resetPassword}.
|
|
273
261
|
*
|
|
274
262
|
* This method sends a request to [this API route](https://docs.acmekit.com/api/admin#auth_postactor_typeauth_providerupdate).
|
|
275
263
|
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
* @param actor - The actor type. For example, `user` for admin user, or `customer` for customer.
|
|
264
|
+
* @param actor - The actor type. For example, `user` for admin user, or custom actor types.
|
|
279
265
|
* @param provider - The authentication provider to use. For example, `emailpass`.
|
|
280
266
|
* @param body - The data necessary to update the user's authentication data. When resetting the user's password,
|
|
281
267
|
* send the `password` property.
|
|
@@ -284,7 +270,7 @@ export class Auth {
|
|
|
284
270
|
*
|
|
285
271
|
* @example
|
|
286
272
|
* sdk.auth.updateProvider(
|
|
287
|
-
* "
|
|
273
|
+
* "user",
|
|
288
274
|
* "emailpass",
|
|
289
275
|
* {
|
|
290
276
|
* password: "supersecret"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":";;;;;;;;;AAIA,MAAM,OAAO,IAAI;IAIf,YAAY,MAAc,EAAE,MAAc;QAK1C
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":";;;;;;;;;AAIA,MAAM,OAAO,IAAI;IAIf,YAAY,MAAc,EAAE,MAAc;QAK1C;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;WA2BG;QACH,mBAAc,GAAG,CACf,KAAa,EACb,QAAgB,EAChB,IAAmC,EACnC,KAAa,EACE,EAAE;YACjB,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,KAAK,IAAI,QAAQ,SAAS,EAAE;gBAC3D,MAAM,EAAE,MAAM;gBACd,IAAI;gBACJ,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,KAAK,EAAE,EAAE;aAC9C,CAAC,CAAA;QACJ,CAAC,CAAA,CAAA;QAED;;WAEG;QACK,cAAS,GAAG,CAAO,KAAa,EAAE,EAAE;;YAC1C,wIAAwI;YACxI,IAAI,CAAA,MAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,IAAI,0CAAE,IAAI,MAAK,SAAS,EAAE,CAAC;gBAC1C,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,EAAE;oBACvC,MAAM,EAAE,MAAM;oBACd,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,KAAK,EAAE,EAAE;iBAC9C,CAAC,CAAA;YACJ,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;YAC7B,CAAC;QACH,CAAC,CAAA,CAAA;QArWC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;CAoWF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Client } from "../client";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for typed API namespaces.
|
|
4
|
+
*
|
|
5
|
+
* Provides the foundation for type-safe API access.
|
|
6
|
+
* Each derived class should define its own `get`, `post`, and `delete` methods
|
|
7
|
+
* with explicit path unions for proper IDE autocomplete support.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* class Admin extends TypedApiNamespace<"/admin"> {
|
|
11
|
+
* public user: User
|
|
12
|
+
* constructor(client: Client) {
|
|
13
|
+
* super(client, "/admin")
|
|
14
|
+
* this.user = new User(client)
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* // Define explicit method signatures for IDE autocomplete
|
|
18
|
+
* get(path: "/users" | "/users/:id", ...): Promise<...> {
|
|
19
|
+
* return this.httpClient.fetch(...)
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
*/
|
|
23
|
+
export declare class TypedApiNamespace<Prefix extends string> {
|
|
24
|
+
protected httpClient: Client;
|
|
25
|
+
protected prefix: Prefix;
|
|
26
|
+
constructor(client: Client, prefix: Prefix);
|
|
27
|
+
/**
|
|
28
|
+
* Resolve path parameters in a template string.
|
|
29
|
+
* @param template - Path template (e.g. "/users/:id")
|
|
30
|
+
* @param params - Path parameter values
|
|
31
|
+
*/
|
|
32
|
+
protected resolvePath(template: string, params?: Record<string, string>): string;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=typed-api-namespace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-api-namespace.d.ts","sourceRoot":"","sources":["../../../src/base/typed-api-namespace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAElC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,iBAAiB,CAAC,MAAM,SAAS,MAAM;IAClD,SAAS,CAAC,UAAU,EAAE,MAAM,CAAA;IAC5B,SAAS,CAAC,MAAM,EAAE,MAAM,CAAA;gBAEZ,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK1C;;;;OAIG;IACH,SAAS,CAAC,WAAW,CACnB,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,MAAM;CASV"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for typed API namespaces.
|
|
3
|
+
*
|
|
4
|
+
* Provides the foundation for type-safe API access.
|
|
5
|
+
* Each derived class should define its own `get`, `post`, and `delete` methods
|
|
6
|
+
* with explicit path unions for proper IDE autocomplete support.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* class Admin extends TypedApiNamespace<"/admin"> {
|
|
10
|
+
* public user: User
|
|
11
|
+
* constructor(client: Client) {
|
|
12
|
+
* super(client, "/admin")
|
|
13
|
+
* this.user = new User(client)
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* // Define explicit method signatures for IDE autocomplete
|
|
17
|
+
* get(path: "/users" | "/users/:id", ...): Promise<...> {
|
|
18
|
+
* return this.httpClient.fetch(...)
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
export class TypedApiNamespace {
|
|
23
|
+
constructor(client, prefix) {
|
|
24
|
+
this.httpClient = client;
|
|
25
|
+
this.prefix = prefix;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Resolve path parameters in a template string.
|
|
29
|
+
* @param template - Path template (e.g. "/users/:id")
|
|
30
|
+
* @param params - Path parameter values
|
|
31
|
+
*/
|
|
32
|
+
resolvePath(template, params) {
|
|
33
|
+
if (!params)
|
|
34
|
+
return template;
|
|
35
|
+
return template.replace(/:(\w+)/g, (_, key) => {
|
|
36
|
+
if (!(key in params)) {
|
|
37
|
+
throw new Error(`Missing path parameter: ${key}`);
|
|
38
|
+
}
|
|
39
|
+
return encodeURIComponent(params[key]);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=typed-api-namespace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-api-namespace.js","sourceRoot":"","sources":["../../../src/base/typed-api-namespace.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,iBAAiB;IAI5B,YAAY,MAAc,EAAE,MAAc;QACxC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAA;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED;;;;OAIG;IACO,WAAW,CACnB,QAAgB,EAChB,MAA+B;QAE/B,IAAI,CAAC,MAAM;YAAE,OAAO,QAAQ,CAAA;QAC5B,OAAO,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;YAC5C,IAAI,CAAC,CAAC,GAAG,IAAI,MAAM,CAAC,EAAE,CAAC;gBACrB,MAAM,IAAI,KAAK,CAAC,2BAA2B,GAAG,EAAE,CAAC,CAAA;YACnD,CAAC;YACD,OAAO,kBAAkB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;QACxC,CAAC,CAAC,CAAA;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Client } from "../client";
|
|
2
|
+
import { TypedApiNamespace } from "../base/typed-api-namespace";
|
|
3
|
+
import type { StorePaths } from "../index";
|
|
4
|
+
import type { TypedFetchOptions, FetchResponseOf } from "../types/route-registry";
|
|
5
|
+
export declare class ClientApi extends TypedApiNamespace<"/client"> {
|
|
6
|
+
constructor(client: Client);
|
|
7
|
+
/**
|
|
8
|
+
* Send a typed request to a client API route.
|
|
9
|
+
*
|
|
10
|
+
* The `method` field is constrained to only the HTTP verbs that the route
|
|
11
|
+
* actually declares — passing a method the route doesn't support is a
|
|
12
|
+
* compile-time error.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* // GET /client/products?limit=20
|
|
16
|
+
* const { products } = await sdk.client.fetch("/products", {
|
|
17
|
+
* method: "GET",
|
|
18
|
+
* query: { limit: 20 },
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* // POST /client/carts/:id/line-items
|
|
22
|
+
* const { cart } = await sdk.client.fetch("/carts/:id/line-items", {
|
|
23
|
+
* method: "POST",
|
|
24
|
+
* body: { variant_id: "variant_123", quantity: 1 },
|
|
25
|
+
* params: { id: "cart_abc" },
|
|
26
|
+
* })
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
fetch<P extends (keyof StorePaths & string) | (string & {}), O extends TypedFetchOptions<StorePaths, P>>(path: P, options: O): Promise<FetchResponseOf<StorePaths, P, O>>;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client-api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EAChB,MAAM,yBAAyB,CAAA;AAEhC,qBAAa,SAAU,SAAQ,iBAAiB,CAAC,SAAS,CAAC;gBAC7C,MAAM,EAAE,MAAM;IAI1B;;;;;;;;;;;;;;;;;;;;;OAqBG;IACI,KAAK,CACV,CAAC,SAAS,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,EACrD,CAAC,SAAS,iBAAiB,CAAC,UAAU,EAAE,CAAC,CAAC,EAC1C,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;CAgBnE"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { TypedApiNamespace } from "../base/typed-api-namespace";
|
|
2
|
+
export class ClientApi extends TypedApiNamespace {
|
|
3
|
+
constructor(client) {
|
|
4
|
+
super(client, "/client");
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Send a typed request to a client API route.
|
|
8
|
+
*
|
|
9
|
+
* The `method` field is constrained to only the HTTP verbs that the route
|
|
10
|
+
* actually declares — passing a method the route doesn't support is a
|
|
11
|
+
* compile-time error.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* // GET /client/products?limit=20
|
|
15
|
+
* const { products } = await sdk.client.fetch("/products", {
|
|
16
|
+
* method: "GET",
|
|
17
|
+
* query: { limit: 20 },
|
|
18
|
+
* })
|
|
19
|
+
*
|
|
20
|
+
* // POST /client/carts/:id/line-items
|
|
21
|
+
* const { cart } = await sdk.client.fetch("/carts/:id/line-items", {
|
|
22
|
+
* method: "POST",
|
|
23
|
+
* body: { variant_id: "variant_123", quantity: 1 },
|
|
24
|
+
* params: { id: "cart_abc" },
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
fetch(path, options) {
|
|
29
|
+
const opts = options;
|
|
30
|
+
const resolvedPath = this.resolvePath(path, opts.params);
|
|
31
|
+
return this.httpClient.fetch(`${this.prefix}${resolvedPath}`, {
|
|
32
|
+
method: opts.method,
|
|
33
|
+
body: opts.body,
|
|
34
|
+
query: opts.query,
|
|
35
|
+
headers: opts.headers,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client-api/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAO/D,MAAM,OAAO,SAAU,SAAQ,iBAA4B;IACzD,YAAY,MAAc;QACxB,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IAC1B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACI,KAAK,CAGV,IAAO,EAAE,OAAU;QACnB,MAAM,IAAI,GAAG,OAMZ,CAAA;QACD,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QACxD,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,YAAY,EAAE,EAAE;YAC5D,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,IAAI,EAAE,IAAI,CAAC,IAA2B;YACtC,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAA+C,CAAA;IAClD,CAAC;CACF"}
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare class FetchError extends Error {
|
|
|
7
7
|
constructor(message: string, statusText?: string, status?: number);
|
|
8
8
|
}
|
|
9
9
|
export declare class Client {
|
|
10
|
-
fetch_
|
|
10
|
+
private fetch_;
|
|
11
11
|
private config;
|
|
12
12
|
private logger;
|
|
13
13
|
private DEFAULT_JWT_STORAGE_KEY;
|
package/dist/esm/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,WAAW,EACX,MAAM,EACN,SAAS,EACT,UAAU,EACV,mBAAmB,EAEpB,MAAM,SAAS,CAAA;AAEhB,eAAO,MAAM,qBAAqB,qBAAqB,CAAA;AACvD,eAAO,MAAM,kBAAkB,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,WAAW,EACX,MAAM,EACN,SAAS,EACT,UAAU,EACV,mBAAmB,EAEpB,MAAM,SAAS,CAAA;AAEhB,eAAO,MAAM,qBAAqB,qBAAqB,CAAA;AACvD,eAAO,MAAM,kBAAkB,mBAAmB,CAAA;AAkGlD,qBAAa,UAAW,SAAQ,KAAK;IACnC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;gBAElB,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