@bymax-one/nest-auth 1.4.2 → 1.4.3
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/CHANGELOG.md +713 -1
- package/README.md +355 -44
- package/dist/client/index.cjs +26 -4
- package/dist/client/index.d.cts +30 -14
- package/dist/client/index.d.ts +30 -14
- package/dist/client/index.mjs +27 -5
- package/dist/server/index.cjs +629 -70
- package/dist/server/index.d.cts +107 -7
- package/dist/server/index.d.ts +107 -7
- package/dist/server/index.mjs +631 -72
- package/dist/shared/index.cjs +62 -10
- package/dist/shared/index.d.cts +112 -5
- package/dist/shared/index.d.ts +112 -5
- package/dist/shared/index.mjs +60 -11
- package/package.json +8 -2
package/dist/client/index.d.cts
CHANGED
|
@@ -172,24 +172,32 @@ interface RegisterInput {
|
|
|
172
172
|
password: string;
|
|
173
173
|
/** Display name. */
|
|
174
174
|
name: string;
|
|
175
|
-
/**
|
|
176
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Tenant identifier scoping the new account.
|
|
177
|
+
*
|
|
178
|
+
* Optional here because whether it is required is the DEPLOYMENT's answer, not this type's:
|
|
179
|
+
* the server requires it when no `tenantIdResolver` is configured and **refuses** it when one
|
|
180
|
+
* is, answering `auth.validation` with a `tenantId` field detail in both directions. A static
|
|
181
|
+
* shape cannot be right for both, and a type that guessed would contradict the server with more
|
|
182
|
+
* authority than the server has. Send it, or do not, according to the deployment you talk to.
|
|
183
|
+
*/
|
|
184
|
+
tenantId?: string;
|
|
177
185
|
}
|
|
178
186
|
/**
|
|
179
187
|
* Payload accepted by {@link AuthClient.login}.
|
|
180
|
-
*
|
|
181
|
-
* `tenantId` is required because the server-side `LoginDto` enforces it
|
|
182
|
-
* with `@IsNotEmpty()`. Multi-tenant deployments use it to scope the
|
|
183
|
-
* credential lookup; single-tenant deployments must still supply a
|
|
184
|
-
* stable identifier (commonly `'default'`).
|
|
185
188
|
*/
|
|
186
189
|
interface LoginInput {
|
|
187
190
|
/** User's primary email address. */
|
|
188
191
|
email: string;
|
|
189
192
|
/** Plaintext password — server hashes immediately on receipt. */
|
|
190
193
|
password: string;
|
|
191
|
-
/**
|
|
192
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Tenant identifier the login attempt is scoped to.
|
|
196
|
+
*
|
|
197
|
+
* Optional for the reason {@link RegisterInput.tenantId} gives: whether it is required is the
|
|
198
|
+
* deployment's answer, not this type's.
|
|
199
|
+
*/
|
|
200
|
+
tenantId?: string;
|
|
193
201
|
}
|
|
194
202
|
/**
|
|
195
203
|
* Fields shared by every reset-password flow.
|
|
@@ -201,8 +209,13 @@ interface LoginInput {
|
|
|
201
209
|
interface ResetPasswordBase {
|
|
202
210
|
/** Email address of the account being reset. */
|
|
203
211
|
email: string;
|
|
204
|
-
/**
|
|
205
|
-
|
|
212
|
+
/**
|
|
213
|
+
* Tenant the account belongs to.
|
|
214
|
+
*
|
|
215
|
+
* Optional for the reason {@link RegisterInput.tenantId} gives: whether it is required is the
|
|
216
|
+
* deployment's answer, not this type's.
|
|
217
|
+
*/
|
|
218
|
+
tenantId?: string;
|
|
206
219
|
/** New plaintext password — server hashes immediately. Min 8 chars, max 128. */
|
|
207
220
|
newPassword: string;
|
|
208
221
|
}
|
|
@@ -265,10 +278,13 @@ interface AuthClient {
|
|
|
265
278
|
/**
|
|
266
279
|
* Initiate a password reset. The server returns 200 regardless of
|
|
267
280
|
* whether the email is registered — the response carries no signal
|
|
268
|
-
* either way (anti-enumeration design).
|
|
269
|
-
*
|
|
281
|
+
* either way (anti-enumeration design).
|
|
282
|
+
*
|
|
283
|
+
* `tenantId` is optional for the reason {@link RegisterInput.tenantId} gives. It stays a
|
|
284
|
+
* positional parameter rather than moving into an object so the widening breaks no caller:
|
|
285
|
+
* it is last, so every existing two-argument call still compiles.
|
|
270
286
|
*/
|
|
271
|
-
forgotPassword(email: string, tenantId
|
|
287
|
+
forgotPassword(email: string, tenantId?: string): Promise<void>;
|
|
272
288
|
/**
|
|
273
289
|
* Submit a new password using one of the three reset flows:
|
|
274
290
|
* token, OTP, or verified-token. See {@link ResetPasswordInput}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -172,24 +172,32 @@ interface RegisterInput {
|
|
|
172
172
|
password: string;
|
|
173
173
|
/** Display name. */
|
|
174
174
|
name: string;
|
|
175
|
-
/**
|
|
176
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Tenant identifier scoping the new account.
|
|
177
|
+
*
|
|
178
|
+
* Optional here because whether it is required is the DEPLOYMENT's answer, not this type's:
|
|
179
|
+
* the server requires it when no `tenantIdResolver` is configured and **refuses** it when one
|
|
180
|
+
* is, answering `auth.validation` with a `tenantId` field detail in both directions. A static
|
|
181
|
+
* shape cannot be right for both, and a type that guessed would contradict the server with more
|
|
182
|
+
* authority than the server has. Send it, or do not, according to the deployment you talk to.
|
|
183
|
+
*/
|
|
184
|
+
tenantId?: string;
|
|
177
185
|
}
|
|
178
186
|
/**
|
|
179
187
|
* Payload accepted by {@link AuthClient.login}.
|
|
180
|
-
*
|
|
181
|
-
* `tenantId` is required because the server-side `LoginDto` enforces it
|
|
182
|
-
* with `@IsNotEmpty()`. Multi-tenant deployments use it to scope the
|
|
183
|
-
* credential lookup; single-tenant deployments must still supply a
|
|
184
|
-
* stable identifier (commonly `'default'`).
|
|
185
188
|
*/
|
|
186
189
|
interface LoginInput {
|
|
187
190
|
/** User's primary email address. */
|
|
188
191
|
email: string;
|
|
189
192
|
/** Plaintext password — server hashes immediately on receipt. */
|
|
190
193
|
password: string;
|
|
191
|
-
/**
|
|
192
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Tenant identifier the login attempt is scoped to.
|
|
196
|
+
*
|
|
197
|
+
* Optional for the reason {@link RegisterInput.tenantId} gives: whether it is required is the
|
|
198
|
+
* deployment's answer, not this type's.
|
|
199
|
+
*/
|
|
200
|
+
tenantId?: string;
|
|
193
201
|
}
|
|
194
202
|
/**
|
|
195
203
|
* Fields shared by every reset-password flow.
|
|
@@ -201,8 +209,13 @@ interface LoginInput {
|
|
|
201
209
|
interface ResetPasswordBase {
|
|
202
210
|
/** Email address of the account being reset. */
|
|
203
211
|
email: string;
|
|
204
|
-
/**
|
|
205
|
-
|
|
212
|
+
/**
|
|
213
|
+
* Tenant the account belongs to.
|
|
214
|
+
*
|
|
215
|
+
* Optional for the reason {@link RegisterInput.tenantId} gives: whether it is required is the
|
|
216
|
+
* deployment's answer, not this type's.
|
|
217
|
+
*/
|
|
218
|
+
tenantId?: string;
|
|
206
219
|
/** New plaintext password — server hashes immediately. Min 8 chars, max 128. */
|
|
207
220
|
newPassword: string;
|
|
208
221
|
}
|
|
@@ -265,10 +278,13 @@ interface AuthClient {
|
|
|
265
278
|
/**
|
|
266
279
|
* Initiate a password reset. The server returns 200 regardless of
|
|
267
280
|
* whether the email is registered — the response carries no signal
|
|
268
|
-
* either way (anti-enumeration design).
|
|
269
|
-
*
|
|
281
|
+
* either way (anti-enumeration design).
|
|
282
|
+
*
|
|
283
|
+
* `tenantId` is optional for the reason {@link RegisterInput.tenantId} gives. It stays a
|
|
284
|
+
* positional parameter rather than moving into an object so the widening breaks no caller:
|
|
285
|
+
* it is last, so every existing two-argument call still compiles.
|
|
270
286
|
*/
|
|
271
|
-
forgotPassword(email: string, tenantId
|
|
287
|
+
forgotPassword(email: string, tenantId?: string): Promise<void>;
|
|
272
288
|
/**
|
|
273
289
|
* Submit a new password using one of the three reset flows:
|
|
274
290
|
* token, OTP, or verified-token. See {@link ResetPasswordInput}
|
package/dist/client/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AUTH_PROXY_ROUTES, buildAuthRefreshSkipSuffixes, AUTH_ROUTES, AuthClientError } from '@bymax-one/nest-auth/shared';
|
|
1
|
+
import { AUTH_PROXY_ROUTES, buildAuthRefreshSkipSuffixes, AUTH_ROUTES, AuthClientError, AUTH_ERROR_CODES } from '@bymax-one/nest-auth/shared';
|
|
2
2
|
export { AuthClientError } from '@bymax-one/nest-auth/shared';
|
|
3
3
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -21,6 +21,23 @@ function shouldSkipRefreshOnUrl(url, suffixes) {
|
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
23
|
__name(shouldSkipRefreshOnUrl, "shouldSkipRefreshOnUrl");
|
|
24
|
+
var ERROR_BODY_READ_TIMEOUT_MS = 2e3;
|
|
25
|
+
async function isExpiredSessionResponse(response) {
|
|
26
|
+
const clone = response.clone();
|
|
27
|
+
let timer;
|
|
28
|
+
const body = await Promise.race([
|
|
29
|
+
clone.json().catch(() => void 0),
|
|
30
|
+
new Promise((resolve) => {
|
|
31
|
+
timer = setTimeout(() => resolve(void 0), ERROR_BODY_READ_TIMEOUT_MS);
|
|
32
|
+
})
|
|
33
|
+
]);
|
|
34
|
+
clearTimeout(timer);
|
|
35
|
+
if (typeof body !== "object" || body === null) return true;
|
|
36
|
+
const envelope = body;
|
|
37
|
+
const code = envelope.error?.code ?? envelope.code;
|
|
38
|
+
return typeof code !== "string" || code === AUTH_ERROR_CODES.TOKEN_INVALID;
|
|
39
|
+
}
|
|
40
|
+
__name(isExpiredSessionResponse, "isExpiredSessionResponse");
|
|
24
41
|
function resolveRequestUrl(input, baseUrl) {
|
|
25
42
|
if (typeof input === "string") {
|
|
26
43
|
return baseUrl !== void 0 && !/^https?:\/\//i.test(input) ? `${baseUrl}${input}` : input;
|
|
@@ -101,7 +118,7 @@ async function performRefresh(endpoint, credentials) {
|
|
|
101
118
|
}
|
|
102
119
|
});
|
|
103
120
|
const ok = response.ok;
|
|
104
|
-
|
|
121
|
+
void response.body?.cancel().catch(
|
|
105
122
|
/* istanbul ignore next */
|
|
106
123
|
() => void 0
|
|
107
124
|
);
|
|
@@ -155,6 +172,9 @@ function createAuthFetch(config = {}) {
|
|
|
155
172
|
if (response.status !== 401 || shouldSkipRefreshOnUrl(url, skipRefreshSuffixes)) {
|
|
156
173
|
return response;
|
|
157
174
|
}
|
|
175
|
+
if (!await isExpiredSessionResponse(response)) {
|
|
176
|
+
return response;
|
|
177
|
+
}
|
|
158
178
|
const refreshed = await getOrStartRefresh();
|
|
159
179
|
if (!refreshed) {
|
|
160
180
|
try {
|
|
@@ -233,7 +253,7 @@ async function expectNoContent(response) {
|
|
|
233
253
|
const text = await response.text();
|
|
234
254
|
throwAuthError(response, text);
|
|
235
255
|
}
|
|
236
|
-
|
|
256
|
+
void response.body?.cancel().catch(
|
|
237
257
|
/* istanbul ignore next */
|
|
238
258
|
() => void 0
|
|
239
259
|
);
|
|
@@ -364,15 +384,17 @@ function createAuthClient(config) {
|
|
|
364
384
|
async forgotPassword(email, tenantId) {
|
|
365
385
|
return postNoContent(AUTH_ROUTES.password.forgotPassword, {
|
|
366
386
|
email,
|
|
367
|
-
tenantId
|
|
387
|
+
...tenantId !== void 0 ? {
|
|
388
|
+
tenantId
|
|
389
|
+
} : {}
|
|
368
390
|
});
|
|
369
391
|
},
|
|
370
392
|
async resetPassword(input) {
|
|
371
393
|
const payload = {
|
|
372
394
|
email: input.email,
|
|
373
|
-
tenantId: input.tenantId,
|
|
374
395
|
newPassword: input.newPassword
|
|
375
396
|
};
|
|
397
|
+
if (input.tenantId !== void 0) payload["tenantId"] = input.tenantId;
|
|
376
398
|
if (input.token !== void 0) payload["token"] = input.token;
|
|
377
399
|
if (input.otp !== void 0) payload["otp"] = input.otp;
|
|
378
400
|
if (input.verifiedToken !== void 0) payload["verifiedToken"] = input.verifiedToken;
|