@bymax-one/nest-auth 1.5.16 → 1.5.17
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 +36 -1
- package/README.md +26 -0
- package/dist/server/index.cjs +279 -141
- package/dist/server/index.d.cts +89 -10
- package/dist/server/index.d.ts +89 -10
- package/dist/server/index.mjs +279 -141
- package/package.json +5 -1
package/dist/server/index.d.cts
CHANGED
|
@@ -542,6 +542,11 @@ interface IUserRepository {
|
|
|
542
542
|
* The `passwordHash` field must be a hash generated by PasswordService.
|
|
543
543
|
* Never receive or store a plaintext password.
|
|
544
544
|
*
|
|
545
|
+
* A unique index is what stops two requests that both passed the caller's check. When the
|
|
546
|
+
* write hits it, an implementation SHOULD throw `new AuthException(AUTH_ERROR_CODES.EMAIL_ALREADY_EXISTS)`
|
|
547
|
+
* (409). Do not rely on the library to translate another error: it may reach the caller as an
|
|
548
|
+
* unexpected failure (500 `auth.internal` on an HTTP route).
|
|
549
|
+
*
|
|
545
550
|
* @param data - Creation payload. See {@link CreateUserData}.
|
|
546
551
|
* @returns The newly created user record with all fields populated.
|
|
547
552
|
*/
|
|
@@ -639,7 +644,9 @@ interface IUserRepository {
|
|
|
639
644
|
* `1`. A write keyed by id alone can land on another tenant's row. An implementation MUST scope
|
|
640
645
|
* the update by both the id and the tenant, exactly as its read does.
|
|
641
646
|
*
|
|
642
|
-
* @throws
|
|
647
|
+
* @throws `AuthException` `EMAIL_ALREADY_EXISTS`, SHOULD, when the address is taken by the time
|
|
648
|
+
* of the write. Do not rely on the library to translate another error: it may reach the caller
|
|
649
|
+
* as an unexpected failure (500 `auth.internal` on an HTTP route).
|
|
643
650
|
*/
|
|
644
651
|
updateEmail(params: UpdateEmailParams): Promise<void>;
|
|
645
652
|
/**
|
|
@@ -673,6 +680,11 @@ interface IUserRepository {
|
|
|
673
680
|
* Users created via this path have no local password. A password may be
|
|
674
681
|
* set later via {@link updatePassword}.
|
|
675
682
|
*
|
|
683
|
+
* A unique index is what stops two requests that both passed the caller's check. When the
|
|
684
|
+
* write hits it, an implementation SHOULD throw `new AuthException(AUTH_ERROR_CODES.EMAIL_ALREADY_EXISTS)`
|
|
685
|
+
* (409). Do not rely on the library to translate another error: it may reach the caller as an
|
|
686
|
+
* unexpected failure (500 `auth.internal` on an HTTP route).
|
|
687
|
+
*
|
|
676
688
|
* @param data - OAuth creation payload. See {@link CreateWithOAuthData}.
|
|
677
689
|
* @returns The newly created user record with all fields populated.
|
|
678
690
|
*/
|
|
@@ -10910,10 +10922,11 @@ declare class EmailChangeService implements OnModuleInit {
|
|
|
10910
10922
|
/**
|
|
10911
10923
|
* Refuses an address the account already has, or that another account in the tenant holds.
|
|
10912
10924
|
*
|
|
10913
|
-
* Answering `EMAIL_ALREADY_EXISTS`
|
|
10914
|
-
*
|
|
10915
|
-
*
|
|
10916
|
-
*
|
|
10925
|
+
* Answering `EMAIL_ALREADY_EXISTS` discloses that an address is registered in the caller's
|
|
10926
|
+
* tenant. Where `register` is mounted it discloses the same; where accounts are created by
|
|
10927
|
+
* invitation only, this route is itself a way for a signed-in user to learn it, behind that
|
|
10928
|
+
* user's password and the route's throttle. Withholding it would leave a user who typos into
|
|
10929
|
+
* a colleague's address waiting on a message that never comes, with no way to tell why.
|
|
10917
10930
|
*
|
|
10918
10931
|
* The account's own current address is refused through the same code: it is a change that
|
|
10919
10932
|
* changes nothing, and letting it through would send a verification for a move that is not
|
|
@@ -11970,11 +11983,49 @@ declare class InvitationService {
|
|
|
11970
11983
|
* @param revokerUserId - Internal ID of the authenticated user withdrawing the invitation.
|
|
11971
11984
|
* @param email - The invited address. Normalized at this boundary.
|
|
11972
11985
|
* @param tenantId - The tenant the invitation was issued for.
|
|
11973
|
-
* @returns `true` when a pending invitation was removed, `false` when
|
|
11974
|
-
* @throws {@link AuthException} `TOKEN_INVALID` when the revoker no longer exists,
|
|
11975
|
-
* `INSUFFICIENT_ROLE` when they
|
|
11986
|
+
* @returns `true` when a pending invitation was removed, `false` when none was.
|
|
11987
|
+
* @throws {@link AuthException} `TOKEN_INVALID` when the revoker no longer exists,
|
|
11988
|
+
* `INSUFFICIENT_ROLE` when they are outside the tenant or not in good standing, or
|
|
11989
|
+
* `TOO_MANY_REQUESTS` when the invitation was replaced during each attempt to remove it.
|
|
11976
11990
|
*/
|
|
11977
11991
|
revokeInvitation(revokerUserId: string, email: string, tenantId: string): Promise<boolean>;
|
|
11992
|
+
/**
|
|
11993
|
+
* Removes the invitation the index names, when the revoker may withdraw what is there.
|
|
11994
|
+
*
|
|
11995
|
+
* A record that is there is deleted before its index is released, so a store failure between the
|
|
11996
|
+
* two never leaves a redeemable record that nothing names. An index that names no record is
|
|
11997
|
+
* released first, so that an invite about to write it fails its second claim. A release that finds
|
|
11998
|
+
* the index claimed by a later invite starts over, and judges what replaced the invitation.
|
|
11999
|
+
*
|
|
12000
|
+
* @param revoker - The authenticated caller, in the tenant and in good standing.
|
|
12001
|
+
* @param indexKey - The invitee index key.
|
|
12002
|
+
* @param tenantId - The tenant, for the log.
|
|
12003
|
+
* @param revokerUserId - Who revokes, for the log.
|
|
12004
|
+
* @returns `true` when this call removed a pending invitation, `false` when it removed none.
|
|
12005
|
+
* @throws {@link AuthException} `TOO_MANY_REQUESTS` when the invitation was replaced before the
|
|
12006
|
+
* index could be released, on every attempt.
|
|
12007
|
+
*/
|
|
12008
|
+
private withdrawPending;
|
|
12009
|
+
/**
|
|
12010
|
+
* Whether the stored invitation is above the revoker, recording the refusal when it is.
|
|
12011
|
+
*
|
|
12012
|
+
* The caller names an address, not a role, so the role is read from the record. One that no longer
|
|
12013
|
+
* parses is withdrawn without a role check: it cannot be accepted either. The refusal is answered
|
|
12014
|
+
* like an address with no invitation, because a `403` would disclose that one is pending; it is
|
|
12015
|
+
* logged server-side.
|
|
12016
|
+
*
|
|
12017
|
+
* @param revoker - The authenticated caller.
|
|
12018
|
+
* @param raw - The stored record.
|
|
12019
|
+
* @returns `true` when the withdrawal is refused.
|
|
12020
|
+
*/
|
|
12021
|
+
private refusesRevoker;
|
|
12022
|
+
/**
|
|
12023
|
+
* Drops the invitee index of an invitation whose record was consumed, while it still names it.
|
|
12024
|
+
*
|
|
12025
|
+
* @param invitation - The consumed record.
|
|
12026
|
+
* @param token - The raw token it was consumed with.
|
|
12027
|
+
*/
|
|
12028
|
+
private releaseAccepted;
|
|
11978
12029
|
/**
|
|
11979
12030
|
* Parses a stored invitation, answering `null` for anything that is not one.
|
|
11980
12031
|
*
|
|
@@ -12837,6 +12888,15 @@ declare class WorkspaceInvitationStore {
|
|
|
12837
12888
|
key: string;
|
|
12838
12889
|
record: StoredWorkspaceInvitation | null;
|
|
12839
12890
|
} | null>;
|
|
12891
|
+
/**
|
|
12892
|
+
* Whether an address's index names a record key.
|
|
12893
|
+
*
|
|
12894
|
+
* @param ref - The workspace.
|
|
12895
|
+
* @param email - The invitee, normalized.
|
|
12896
|
+
* @param key - The record key.
|
|
12897
|
+
* @returns `true` while the index holds `key`.
|
|
12898
|
+
*/
|
|
12899
|
+
names(ref: WorkspaceRef, email: string, key: string): Promise<boolean>;
|
|
12840
12900
|
/**
|
|
12841
12901
|
* Writes a record, points the address's index at it and lists it as pending, retiring the record
|
|
12842
12902
|
* the index named when it was read, all in one step.
|
|
@@ -14664,12 +14724,15 @@ declare class WorkspaceInvitationService {
|
|
|
14664
14724
|
resend(ref: WorkspaceRef, actor: WorkspaceActor, rawEmail: string, context: HookContext): Promise<void>;
|
|
14665
14725
|
/**
|
|
14666
14726
|
* Withdraws a pending invitation. An address with none, or one the actor may not act on, is
|
|
14667
|
-
* answered like a success and changes nothing.
|
|
14727
|
+
* answered like a success and changes nothing. An invitation that replaces the one being
|
|
14728
|
+
* withdrawn is read again and held to the same ceiling.
|
|
14668
14729
|
*
|
|
14669
14730
|
* @param ref - The workspace.
|
|
14670
14731
|
* @param actor - Who revokes.
|
|
14671
14732
|
* @param rawEmail - The invitee.
|
|
14672
14733
|
* @param context - Request metadata for the hook.
|
|
14734
|
+
* @throws {AuthException} `auth.too_many_requests` when the invitation was replaced during each
|
|
14735
|
+
* attempt to remove it.
|
|
14673
14736
|
*/
|
|
14674
14737
|
revoke(ref: WorkspaceRef, actor: WorkspaceActor, rawEmail: string, context: HookContext): Promise<void>;
|
|
14675
14738
|
/**
|
|
@@ -14719,13 +14782,29 @@ declare class WorkspaceInvitationService {
|
|
|
14719
14782
|
}>;
|
|
14720
14783
|
/**
|
|
14721
14784
|
* Withdraws a platform bootstrap invitation. An address with none, or with an ordinary member
|
|
14722
|
-
* invitation, is answered like a success and changes nothing.
|
|
14785
|
+
* invitation, is answered like a success and changes nothing. A replacement of the invitation
|
|
14786
|
+
* being withdrawn is read again and removed only if it is a bootstrap one too.
|
|
14723
14787
|
*
|
|
14724
14788
|
* @param ref - The workspace id `inviteAsPlatform` returned.
|
|
14725
14789
|
* @param rawEmail - The invitee.
|
|
14726
14790
|
* @param context - Request metadata for the hook.
|
|
14791
|
+
* @throws {AuthException} `auth.too_many_requests` when the invitation was replaced during each
|
|
14792
|
+
* attempt to remove it.
|
|
14727
14793
|
*/
|
|
14728
14794
|
revokeAsPlatform(ref: WorkspaceRef, rawEmail: string, context: HookContext): Promise<void>;
|
|
14795
|
+
/**
|
|
14796
|
+
* Removes the address's invitation and reports it, when `mayWithdraw` accepts what is there.
|
|
14797
|
+
*
|
|
14798
|
+
* The report is for a removal only. When the index stops naming the record, before the record is
|
|
14799
|
+
* read or before it is removed, the address is read again and what replaced it is judged anew.
|
|
14800
|
+
*
|
|
14801
|
+
* @param ref - The workspace.
|
|
14802
|
+
* @param email - The invitee, normalized.
|
|
14803
|
+
* @param mayWithdraw - Whether this caller may remove the record it is shown.
|
|
14804
|
+
* @param actorUserId - Who revokes, or `null` for the platform.
|
|
14805
|
+
* @param context - Request metadata for the hook.
|
|
14806
|
+
*/
|
|
14807
|
+
private withdraw;
|
|
14729
14808
|
/** Counts one invitation against the inviter's hour, refusing the twenty-first. */
|
|
14730
14809
|
private takeInviterSlot;
|
|
14731
14810
|
/** Refuses to replace an invitation the actor may not act on, or one sent too recently or often. */
|
package/dist/server/index.d.ts
CHANGED
|
@@ -542,6 +542,11 @@ interface IUserRepository {
|
|
|
542
542
|
* The `passwordHash` field must be a hash generated by PasswordService.
|
|
543
543
|
* Never receive or store a plaintext password.
|
|
544
544
|
*
|
|
545
|
+
* A unique index is what stops two requests that both passed the caller's check. When the
|
|
546
|
+
* write hits it, an implementation SHOULD throw `new AuthException(AUTH_ERROR_CODES.EMAIL_ALREADY_EXISTS)`
|
|
547
|
+
* (409). Do not rely on the library to translate another error: it may reach the caller as an
|
|
548
|
+
* unexpected failure (500 `auth.internal` on an HTTP route).
|
|
549
|
+
*
|
|
545
550
|
* @param data - Creation payload. See {@link CreateUserData}.
|
|
546
551
|
* @returns The newly created user record with all fields populated.
|
|
547
552
|
*/
|
|
@@ -639,7 +644,9 @@ interface IUserRepository {
|
|
|
639
644
|
* `1`. A write keyed by id alone can land on another tenant's row. An implementation MUST scope
|
|
640
645
|
* the update by both the id and the tenant, exactly as its read does.
|
|
641
646
|
*
|
|
642
|
-
* @throws
|
|
647
|
+
* @throws `AuthException` `EMAIL_ALREADY_EXISTS`, SHOULD, when the address is taken by the time
|
|
648
|
+
* of the write. Do not rely on the library to translate another error: it may reach the caller
|
|
649
|
+
* as an unexpected failure (500 `auth.internal` on an HTTP route).
|
|
643
650
|
*/
|
|
644
651
|
updateEmail(params: UpdateEmailParams): Promise<void>;
|
|
645
652
|
/**
|
|
@@ -673,6 +680,11 @@ interface IUserRepository {
|
|
|
673
680
|
* Users created via this path have no local password. A password may be
|
|
674
681
|
* set later via {@link updatePassword}.
|
|
675
682
|
*
|
|
683
|
+
* A unique index is what stops two requests that both passed the caller's check. When the
|
|
684
|
+
* write hits it, an implementation SHOULD throw `new AuthException(AUTH_ERROR_CODES.EMAIL_ALREADY_EXISTS)`
|
|
685
|
+
* (409). Do not rely on the library to translate another error: it may reach the caller as an
|
|
686
|
+
* unexpected failure (500 `auth.internal` on an HTTP route).
|
|
687
|
+
*
|
|
676
688
|
* @param data - OAuth creation payload. See {@link CreateWithOAuthData}.
|
|
677
689
|
* @returns The newly created user record with all fields populated.
|
|
678
690
|
*/
|
|
@@ -10910,10 +10922,11 @@ declare class EmailChangeService implements OnModuleInit {
|
|
|
10910
10922
|
/**
|
|
10911
10923
|
* Refuses an address the account already has, or that another account in the tenant holds.
|
|
10912
10924
|
*
|
|
10913
|
-
* Answering `EMAIL_ALREADY_EXISTS`
|
|
10914
|
-
*
|
|
10915
|
-
*
|
|
10916
|
-
*
|
|
10925
|
+
* Answering `EMAIL_ALREADY_EXISTS` discloses that an address is registered in the caller's
|
|
10926
|
+
* tenant. Where `register` is mounted it discloses the same; where accounts are created by
|
|
10927
|
+
* invitation only, this route is itself a way for a signed-in user to learn it, behind that
|
|
10928
|
+
* user's password and the route's throttle. Withholding it would leave a user who typos into
|
|
10929
|
+
* a colleague's address waiting on a message that never comes, with no way to tell why.
|
|
10917
10930
|
*
|
|
10918
10931
|
* The account's own current address is refused through the same code: it is a change that
|
|
10919
10932
|
* changes nothing, and letting it through would send a verification for a move that is not
|
|
@@ -11970,11 +11983,49 @@ declare class InvitationService {
|
|
|
11970
11983
|
* @param revokerUserId - Internal ID of the authenticated user withdrawing the invitation.
|
|
11971
11984
|
* @param email - The invited address. Normalized at this boundary.
|
|
11972
11985
|
* @param tenantId - The tenant the invitation was issued for.
|
|
11973
|
-
* @returns `true` when a pending invitation was removed, `false` when
|
|
11974
|
-
* @throws {@link AuthException} `TOKEN_INVALID` when the revoker no longer exists,
|
|
11975
|
-
* `INSUFFICIENT_ROLE` when they
|
|
11986
|
+
* @returns `true` when a pending invitation was removed, `false` when none was.
|
|
11987
|
+
* @throws {@link AuthException} `TOKEN_INVALID` when the revoker no longer exists,
|
|
11988
|
+
* `INSUFFICIENT_ROLE` when they are outside the tenant or not in good standing, or
|
|
11989
|
+
* `TOO_MANY_REQUESTS` when the invitation was replaced during each attempt to remove it.
|
|
11976
11990
|
*/
|
|
11977
11991
|
revokeInvitation(revokerUserId: string, email: string, tenantId: string): Promise<boolean>;
|
|
11992
|
+
/**
|
|
11993
|
+
* Removes the invitation the index names, when the revoker may withdraw what is there.
|
|
11994
|
+
*
|
|
11995
|
+
* A record that is there is deleted before its index is released, so a store failure between the
|
|
11996
|
+
* two never leaves a redeemable record that nothing names. An index that names no record is
|
|
11997
|
+
* released first, so that an invite about to write it fails its second claim. A release that finds
|
|
11998
|
+
* the index claimed by a later invite starts over, and judges what replaced the invitation.
|
|
11999
|
+
*
|
|
12000
|
+
* @param revoker - The authenticated caller, in the tenant and in good standing.
|
|
12001
|
+
* @param indexKey - The invitee index key.
|
|
12002
|
+
* @param tenantId - The tenant, for the log.
|
|
12003
|
+
* @param revokerUserId - Who revokes, for the log.
|
|
12004
|
+
* @returns `true` when this call removed a pending invitation, `false` when it removed none.
|
|
12005
|
+
* @throws {@link AuthException} `TOO_MANY_REQUESTS` when the invitation was replaced before the
|
|
12006
|
+
* index could be released, on every attempt.
|
|
12007
|
+
*/
|
|
12008
|
+
private withdrawPending;
|
|
12009
|
+
/**
|
|
12010
|
+
* Whether the stored invitation is above the revoker, recording the refusal when it is.
|
|
12011
|
+
*
|
|
12012
|
+
* The caller names an address, not a role, so the role is read from the record. One that no longer
|
|
12013
|
+
* parses is withdrawn without a role check: it cannot be accepted either. The refusal is answered
|
|
12014
|
+
* like an address with no invitation, because a `403` would disclose that one is pending; it is
|
|
12015
|
+
* logged server-side.
|
|
12016
|
+
*
|
|
12017
|
+
* @param revoker - The authenticated caller.
|
|
12018
|
+
* @param raw - The stored record.
|
|
12019
|
+
* @returns `true` when the withdrawal is refused.
|
|
12020
|
+
*/
|
|
12021
|
+
private refusesRevoker;
|
|
12022
|
+
/**
|
|
12023
|
+
* Drops the invitee index of an invitation whose record was consumed, while it still names it.
|
|
12024
|
+
*
|
|
12025
|
+
* @param invitation - The consumed record.
|
|
12026
|
+
* @param token - The raw token it was consumed with.
|
|
12027
|
+
*/
|
|
12028
|
+
private releaseAccepted;
|
|
11978
12029
|
/**
|
|
11979
12030
|
* Parses a stored invitation, answering `null` for anything that is not one.
|
|
11980
12031
|
*
|
|
@@ -12837,6 +12888,15 @@ declare class WorkspaceInvitationStore {
|
|
|
12837
12888
|
key: string;
|
|
12838
12889
|
record: StoredWorkspaceInvitation | null;
|
|
12839
12890
|
} | null>;
|
|
12891
|
+
/**
|
|
12892
|
+
* Whether an address's index names a record key.
|
|
12893
|
+
*
|
|
12894
|
+
* @param ref - The workspace.
|
|
12895
|
+
* @param email - The invitee, normalized.
|
|
12896
|
+
* @param key - The record key.
|
|
12897
|
+
* @returns `true` while the index holds `key`.
|
|
12898
|
+
*/
|
|
12899
|
+
names(ref: WorkspaceRef, email: string, key: string): Promise<boolean>;
|
|
12840
12900
|
/**
|
|
12841
12901
|
* Writes a record, points the address's index at it and lists it as pending, retiring the record
|
|
12842
12902
|
* the index named when it was read, all in one step.
|
|
@@ -14664,12 +14724,15 @@ declare class WorkspaceInvitationService {
|
|
|
14664
14724
|
resend(ref: WorkspaceRef, actor: WorkspaceActor, rawEmail: string, context: HookContext): Promise<void>;
|
|
14665
14725
|
/**
|
|
14666
14726
|
* Withdraws a pending invitation. An address with none, or one the actor may not act on, is
|
|
14667
|
-
* answered like a success and changes nothing.
|
|
14727
|
+
* answered like a success and changes nothing. An invitation that replaces the one being
|
|
14728
|
+
* withdrawn is read again and held to the same ceiling.
|
|
14668
14729
|
*
|
|
14669
14730
|
* @param ref - The workspace.
|
|
14670
14731
|
* @param actor - Who revokes.
|
|
14671
14732
|
* @param rawEmail - The invitee.
|
|
14672
14733
|
* @param context - Request metadata for the hook.
|
|
14734
|
+
* @throws {AuthException} `auth.too_many_requests` when the invitation was replaced during each
|
|
14735
|
+
* attempt to remove it.
|
|
14673
14736
|
*/
|
|
14674
14737
|
revoke(ref: WorkspaceRef, actor: WorkspaceActor, rawEmail: string, context: HookContext): Promise<void>;
|
|
14675
14738
|
/**
|
|
@@ -14719,13 +14782,29 @@ declare class WorkspaceInvitationService {
|
|
|
14719
14782
|
}>;
|
|
14720
14783
|
/**
|
|
14721
14784
|
* Withdraws a platform bootstrap invitation. An address with none, or with an ordinary member
|
|
14722
|
-
* invitation, is answered like a success and changes nothing.
|
|
14785
|
+
* invitation, is answered like a success and changes nothing. A replacement of the invitation
|
|
14786
|
+
* being withdrawn is read again and removed only if it is a bootstrap one too.
|
|
14723
14787
|
*
|
|
14724
14788
|
* @param ref - The workspace id `inviteAsPlatform` returned.
|
|
14725
14789
|
* @param rawEmail - The invitee.
|
|
14726
14790
|
* @param context - Request metadata for the hook.
|
|
14791
|
+
* @throws {AuthException} `auth.too_many_requests` when the invitation was replaced during each
|
|
14792
|
+
* attempt to remove it.
|
|
14727
14793
|
*/
|
|
14728
14794
|
revokeAsPlatform(ref: WorkspaceRef, rawEmail: string, context: HookContext): Promise<void>;
|
|
14795
|
+
/**
|
|
14796
|
+
* Removes the address's invitation and reports it, when `mayWithdraw` accepts what is there.
|
|
14797
|
+
*
|
|
14798
|
+
* The report is for a removal only. When the index stops naming the record, before the record is
|
|
14799
|
+
* read or before it is removed, the address is read again and what replaced it is judged anew.
|
|
14800
|
+
*
|
|
14801
|
+
* @param ref - The workspace.
|
|
14802
|
+
* @param email - The invitee, normalized.
|
|
14803
|
+
* @param mayWithdraw - Whether this caller may remove the record it is shown.
|
|
14804
|
+
* @param actorUserId - Who revokes, or `null` for the platform.
|
|
14805
|
+
* @param context - Request metadata for the hook.
|
|
14806
|
+
*/
|
|
14807
|
+
private withdraw;
|
|
14729
14808
|
/** Counts one invitation against the inviter's hour, refusing the twenty-first. */
|
|
14730
14809
|
private takeInviterSlot;
|
|
14731
14810
|
/** Refuses to replace an invitation the actor may not act on, or one sent too recently or often. */
|