najm-auth 6.2.0 → 6.3.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/README.md +23 -0
- package/dist/index.d.ts +44 -3
- package/dist/index.js +49 -9
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -635,6 +635,29 @@ An upgrade alone does not rewrite unsafe queries in consumers. Keep role
|
|
|
635
635
|
and cross-user integration tests in each app. `@Policy` and `@CanRead` check
|
|
636
636
|
permissions, not the ownership of a requested record ID.
|
|
637
637
|
|
|
638
|
+
### Row conditions and owned-id subqueries (6.3+)
|
|
639
|
+
|
|
640
|
+
A rule may also hold `when()` conditions on the owned row. After a join chain
|
|
641
|
+
they narrow it; on their own they are the whole rule, for rows that belong to
|
|
642
|
+
an audience rather than to one linked person. A function receives the user id
|
|
643
|
+
and the rule's role. `ownedIds(token, role, userId)` is the subquery of ids a
|
|
644
|
+
user owns through another token, for use inside a condition.
|
|
645
|
+
|
|
646
|
+
```typescript
|
|
647
|
+
import { own, join, where, when, ownedIds } from 'najm-auth';
|
|
648
|
+
|
|
649
|
+
export const Alert = own(alerts, { adminRoles: ['admin'] })
|
|
650
|
+
// Alerts about my children that are addressed to parents
|
|
651
|
+
.for('parent', join(alerts.studentId, students.id), where(students.parentUserId),
|
|
652
|
+
when(eq(alerts.audience, 'parents')))
|
|
653
|
+
// Alerts naming nobody, for classes I teach
|
|
654
|
+
.for('teacher', when(isNull(alerts.studentId),
|
|
655
|
+
(userId, role) => inArray(alerts.classId, ownedIds(Class, role, userId))));
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
`own(table, { name })` sets the token's resource name when it should differ
|
|
659
|
+
from the table's.
|
|
660
|
+
|
|
638
661
|
### Advanced Ownership: Multi-Role Scoping
|
|
639
662
|
|
|
640
663
|
```typescript
|
package/dist/index.d.ts
CHANGED
|
@@ -2709,6 +2709,12 @@ interface OwnerStep {
|
|
|
2709
2709
|
col: any;
|
|
2710
2710
|
}
|
|
2711
2711
|
type OwnershipStep = JoinStep | OwnerStep;
|
|
2712
|
+
/** A condition on the owned row; a function receives the user id and the rule's role. */
|
|
2713
|
+
type RowRule = SQL | ((userId: string, role: string) => SQL);
|
|
2714
|
+
interface WhenStep {
|
|
2715
|
+
type: 'when';
|
|
2716
|
+
rules: RowRule[];
|
|
2717
|
+
}
|
|
2712
2718
|
/**
|
|
2713
2719
|
* JOIN step — links two columns across tables.
|
|
2714
2720
|
* The target table is inferred from the right column.
|
|
@@ -2722,6 +2728,21 @@ declare function join(left: any, right: any): JoinStep;
|
|
|
2722
2728
|
* @example where(teachers.userId)
|
|
2723
2729
|
*/
|
|
2724
2730
|
declare function where(col: any): OwnerStep;
|
|
2731
|
+
/**
|
|
2732
|
+
* Row-condition step — a condition on the owned row itself.
|
|
2733
|
+
*
|
|
2734
|
+
* After a join chain it narrows the rows the chain reaches ("…and the alert is
|
|
2735
|
+
* for parents"). On its own it is the whole rule, for rows that belong to an
|
|
2736
|
+
* audience rather than to one linked person ("every published notice for
|
|
2737
|
+
* parents"). Several rules in one step, and several steps, are AND-ed.
|
|
2738
|
+
*
|
|
2739
|
+
* @example
|
|
2740
|
+
* own(alerts)
|
|
2741
|
+
* .for('parent', join(alerts.studentId, students.id), where(students.parentUserId),
|
|
2742
|
+
* when(eq(alerts.audience, 'parents')))
|
|
2743
|
+
* .for('teacher', when(isNull(alerts.studentId), (userId) => eq(alerts.createdBy, userId)))
|
|
2744
|
+
*/
|
|
2745
|
+
declare function when(...rules: RowRule[]): WhenStep;
|
|
2725
2746
|
type ScopeResult = {
|
|
2726
2747
|
query: any;
|
|
2727
2748
|
condition: any;
|
|
@@ -2729,6 +2750,8 @@ type ScopeResult = {
|
|
|
2729
2750
|
interface OwnershipTokenOptions {
|
|
2730
2751
|
/** Admin roles that bypass all scoping. Falls back to global admin roles if not set. */
|
|
2731
2752
|
adminRoles?: string[];
|
|
2753
|
+
/** Resource name (default: the table's name), e.g. for permission and policy names. */
|
|
2754
|
+
name?: string;
|
|
2732
2755
|
}
|
|
2733
2756
|
declare class OwnershipToken {
|
|
2734
2757
|
readonly symbol: symbol;
|
|
@@ -2739,8 +2762,12 @@ declare class OwnershipToken {
|
|
|
2739
2762
|
private _adminRoles?;
|
|
2740
2763
|
constructor(table: any, opts?: OwnershipTokenOptions);
|
|
2741
2764
|
private isAdmin;
|
|
2742
|
-
/**
|
|
2743
|
-
|
|
2765
|
+
/**
|
|
2766
|
+
* Define the scope rule for a role: a join chain ending in `where()`, and/or
|
|
2767
|
+
* `when()` row conditions. A chain with conditions reaches the rows the
|
|
2768
|
+
* chain reaches that also satisfy them; conditions alone are the whole rule.
|
|
2769
|
+
*/
|
|
2770
|
+
for(role: string, ...steps: Array<OwnershipStep | WhenStep>): this;
|
|
2744
2771
|
/**
|
|
2745
2772
|
* Column to verify ownership before write operations (create/update).
|
|
2746
2773
|
* @example .writeBy(grades.studentId)
|
|
@@ -2758,6 +2785,17 @@ declare class OwnershipToken {
|
|
|
2758
2785
|
*/
|
|
2759
2786
|
applyScopeSplit(uid: string, role: string, query: any): ScopeResult;
|
|
2760
2787
|
}
|
|
2788
|
+
/**
|
|
2789
|
+
* The ids of `token`'s rows that a `role` user owns, as a subquery — for a
|
|
2790
|
+
* `when()` condition on another resource: "one of the classes this parent's
|
|
2791
|
+
* children are in". A role that bypasses scoping gets every id; a role with no
|
|
2792
|
+
* rule gets none.
|
|
2793
|
+
*
|
|
2794
|
+
* @example
|
|
2795
|
+
* own(announcements).for('parent', when((userId, role) =>
|
|
2796
|
+
* inArray(announcements.classId, ownedIds(Class, role, userId))))
|
|
2797
|
+
*/
|
|
2798
|
+
declare function ownedIds(token: OwnershipToken, role: string, userId: string): any;
|
|
2761
2799
|
/**
|
|
2762
2800
|
* Start an ownership definition chain.
|
|
2763
2801
|
*
|
|
@@ -2770,6 +2808,9 @@ declare class OwnershipToken {
|
|
|
2770
2808
|
* // With explicit admin roles (avoids global state):
|
|
2771
2809
|
* export const Grade = own(grades, { adminRoles: ['admin', 'principal'] })
|
|
2772
2810
|
* .for('teacher', join(grades.studentId, students.id), where(teachers.userId));
|
|
2811
|
+
*
|
|
2812
|
+
* // With a resource name other than the table's:
|
|
2813
|
+
* export const Report = own(reportRows, { name: 'reports' });
|
|
2773
2814
|
*/
|
|
2774
2815
|
declare function own(table: any, opts?: OwnershipTokenOptions): OwnershipToken;
|
|
2775
2816
|
|
|
@@ -3237,4 +3278,4 @@ declare const authSeed: (config: AuthSeedConfig) => Record<string, SeedEntry>;
|
|
|
3237
3278
|
*/
|
|
3238
3279
|
declare function seedAuthData(config: SeedAuthDataConfig): Promise<SeedAuthDataResult>;
|
|
3239
3280
|
|
|
3240
|
-
export { AUTH_CONFIG, AUTH_CORE_MODULE, en as AUTH_EN, AUTH_LOCALES, AUTH_LOGIN_RATE_LIMIT_ENV, AUTH_MODULE, AUTH_PERMISSIONS, AUTH_ROLE, AUTH_SCHEMA, AUTH_SUPPORTED_LANGUAGES, AUTH_USER, type AdministrativeDelivery, type AssignPermissionDto, type AssignRoleDto, type AssignRoleParams, type AuthConfig, AuthController, AuthGuard, type AuthLoginRateLimitConfig, type AuthPluginConfig, AuthQueries, type AuthRateLimitEnvironment, AuthResolver, type AuthSchema, type AuthSeedConfig, AuthService, AuthSessionService, type AuthUser, CREDENTIAL_SETUP_CODES, CREDENTIAL_SETUP_MODULE, Can, CanCreate, CanDelete, CanList, CanRead, CanUpdate, type ChainableGuard, type ChangePasswordDto, type CheckPermissionDto, type ConfiguredOwnership, type ConfirmResetPasswordDto, type ConsumedSetPasswordToken, CookieManager, type CreatePermissionDto, type CreateRoleDto, type CreateTokenDto, type CreateUserDto, type CredentialSetupChangeDto, type CredentialSetupCode, type CredentialSetupConfig, CredentialSetupController, type CredentialSetupOptions, type CredentialSetupPasswordOptions, type CredentialSetupPending, CredentialSetupRepository, CredentialSetupRequirementRepository, type CredentialSetupRequirementRow, CredentialSetupRequirementService, CredentialSetupService, type CredentialSetupSessionInfo, type CredentialSetupStarted, DEFAULT_AUTH_LOGIN_RATE_LIMIT, DEFAULT_CREDENTIAL_SETUP_COOKIE_NAME, DEFAULT_CREDENTIAL_SETUP_TTL_MS, type DefineRolesOptions, type EmailParam, EncryptionService, type GitHubOAuthConfig, type GoogleOAuthConfig, IdentityConfig, type IdentityResolver, type InviteUserDto, type JwtConfig, type JwtPayload, type LanguageParam, type LoginDto, type LoginResult, NewPermission, NewRoleEntity, NewUser, type OAuthConfig, type OAuthProvider, Owned, type OwnedMethods, type OwnedWhere, type OwnershipConditionMethods, type OwnershipConfig, type OwnershipProvider, type OwnershipReadContext, type OwnershipRule, OwnershipToken, type OwnershipTokenOptions, PASSWORD_SETUP_PURPOSE, PUBLIC_REGISTRATION_MODULE, PasswordSetupService, Permission, PermissionController, PermissionGuard, type PermissionIdParam, PermissionRepository, PermissionService, PermissionValidator, Policy, type ProvisionUserInput, type ProvisionUserWithPasswordInput, type ProvisionUserWithSetupInput, ROLES, ROLE_GROUPS, type RefreshTokenDto, type RefreshedSession, type RegisterDto, RegistrationController, type ResetPasswordDto, type ResolvedCredentialSetupConfig, ResolvedIdentityConfig, type ResourceAccessor, type ResourceGuards, type ResourceGuardsOptions, type RevokeTokenDto, Role, RoleController, RoleEntity, RoleGuard, type RoleIdParam, type RoleInput, RolePermission, RoleRepository, RoleService, type RoleType, RoleValidator, type RunAsUser, type SanitizedUser, ScopeContext, type ScopeResult, type SeedAuthDataConfig, type SeedAuthDataResult, type SeedUserConfig, type SessionCookieData, SessionInvalidationService, type SetPasswordToken, type SetPasswordTokenType, TOKEN_STATUS, TOKEN_TYPE, TemporaryCredentialInput, type TemporaryCredentialReset, type TokenIdParam, type TokenPair, TokenRepository, TokenService, USER_STATUS, type UpdatePermissionDto, type UpdateRoleDto, type UpdateTokenDto, type UpdateUserDto, User, UserController, type UserIdInParam, type UserIdParam, type UserListQuery, UserRepository, UserService, UserValidator, type UserWithPermissions, type VerifyTokenDto, assignPermissionDto, assignRoleDto, assignRoleParams, auth$1 as auth, authEmailRateLimitKey, authIdentityRateLimitKey, authSeed, avatarsPath, calculateAge, calculateYearsOfExperience, changePasswordDto, checkPermissionDto, clean, configureOwnership, confirmResetPasswordDto, createIdentityResolver, createPermissionDto, createRoleDto, createTokenDto, createUserDto, credentialSetupChangeDto, credentialSetupError, defaultCredentialSetupPasswordSchema, defineRoles, emailParam, formatDate, getAuthLocale, getAvatarFile, inviteUserDto, isAdmin, isAdministrator, isAuth, isEmailIdentifier, isEmpty, isFile, isPath, join, languageParam, loginDto, normalizeAuthIdentifier, normalizeSetupPurpose, own, ownershipCondition, parseSchema, permissionIdParam, pickProps, refreshTokenDto, registerDto, resetPasswordDto, resolveAuthLoginRateLimitConfig, revokeTokenDto, roleIdParam, runAsUser, seedAuthData, tokenIdParam, updatePermissionDto, updateRoleDto, updateTokenDto, updateUserDto, userIdInParam, userIdParam, userListQuery, verifyTokenDto, where };
|
|
3281
|
+
export { AUTH_CONFIG, AUTH_CORE_MODULE, en as AUTH_EN, AUTH_LOCALES, AUTH_LOGIN_RATE_LIMIT_ENV, AUTH_MODULE, AUTH_PERMISSIONS, AUTH_ROLE, AUTH_SCHEMA, AUTH_SUPPORTED_LANGUAGES, AUTH_USER, type AdministrativeDelivery, type AssignPermissionDto, type AssignRoleDto, type AssignRoleParams, type AuthConfig, AuthController, AuthGuard, type AuthLoginRateLimitConfig, type AuthPluginConfig, AuthQueries, type AuthRateLimitEnvironment, AuthResolver, type AuthSchema, type AuthSeedConfig, AuthService, AuthSessionService, type AuthUser, CREDENTIAL_SETUP_CODES, CREDENTIAL_SETUP_MODULE, Can, CanCreate, CanDelete, CanList, CanRead, CanUpdate, type ChainableGuard, type ChangePasswordDto, type CheckPermissionDto, type ConfiguredOwnership, type ConfirmResetPasswordDto, type ConsumedSetPasswordToken, CookieManager, type CreatePermissionDto, type CreateRoleDto, type CreateTokenDto, type CreateUserDto, type CredentialSetupChangeDto, type CredentialSetupCode, type CredentialSetupConfig, CredentialSetupController, type CredentialSetupOptions, type CredentialSetupPasswordOptions, type CredentialSetupPending, CredentialSetupRepository, CredentialSetupRequirementRepository, type CredentialSetupRequirementRow, CredentialSetupRequirementService, CredentialSetupService, type CredentialSetupSessionInfo, type CredentialSetupStarted, DEFAULT_AUTH_LOGIN_RATE_LIMIT, DEFAULT_CREDENTIAL_SETUP_COOKIE_NAME, DEFAULT_CREDENTIAL_SETUP_TTL_MS, type DefineRolesOptions, type EmailParam, EncryptionService, type GitHubOAuthConfig, type GoogleOAuthConfig, IdentityConfig, type IdentityResolver, type InviteUserDto, type JwtConfig, type JwtPayload, type LanguageParam, type LoginDto, type LoginResult, NewPermission, NewRoleEntity, NewUser, type OAuthConfig, type OAuthProvider, Owned, type OwnedMethods, type OwnedWhere, type OwnershipConditionMethods, type OwnershipConfig, type OwnershipProvider, type OwnershipReadContext, type OwnershipRule, OwnershipToken, type OwnershipTokenOptions, PASSWORD_SETUP_PURPOSE, PUBLIC_REGISTRATION_MODULE, PasswordSetupService, Permission, PermissionController, PermissionGuard, type PermissionIdParam, PermissionRepository, PermissionService, PermissionValidator, Policy, type ProvisionUserInput, type ProvisionUserWithPasswordInput, type ProvisionUserWithSetupInput, ROLES, ROLE_GROUPS, type RefreshTokenDto, type RefreshedSession, type RegisterDto, RegistrationController, type ResetPasswordDto, type ResolvedCredentialSetupConfig, ResolvedIdentityConfig, type ResourceAccessor, type ResourceGuards, type ResourceGuardsOptions, type RevokeTokenDto, Role, RoleController, RoleEntity, RoleGuard, type RoleIdParam, type RoleInput, RolePermission, RoleRepository, RoleService, type RoleType, RoleValidator, type RowRule, type RunAsUser, type SanitizedUser, ScopeContext, type ScopeResult, type SeedAuthDataConfig, type SeedAuthDataResult, type SeedUserConfig, type SessionCookieData, SessionInvalidationService, type SetPasswordToken, type SetPasswordTokenType, TOKEN_STATUS, TOKEN_TYPE, TemporaryCredentialInput, type TemporaryCredentialReset, type TokenIdParam, type TokenPair, TokenRepository, TokenService, USER_STATUS, type UpdatePermissionDto, type UpdateRoleDto, type UpdateTokenDto, type UpdateUserDto, User, UserController, type UserIdInParam, type UserIdParam, type UserListQuery, UserRepository, UserService, UserValidator, type UserWithPermissions, type VerifyTokenDto, type WhenStep, assignPermissionDto, assignRoleDto, assignRoleParams, auth$1 as auth, authEmailRateLimitKey, authIdentityRateLimitKey, authSeed, avatarsPath, calculateAge, calculateYearsOfExperience, changePasswordDto, checkPermissionDto, clean, configureOwnership, confirmResetPasswordDto, createIdentityResolver, createPermissionDto, createRoleDto, createTokenDto, createUserDto, credentialSetupChangeDto, credentialSetupError, defaultCredentialSetupPasswordSchema, defineRoles, emailParam, formatDate, getAuthLocale, getAvatarFile, inviteUserDto, isAdmin, isAdministrator, isAuth, isEmailIdentifier, isEmpty, isFile, isPath, join, languageParam, loginDto, normalizeAuthIdentifier, normalizeSetupPurpose, own, ownedIds, ownershipCondition, parseSchema, permissionIdParam, pickProps, refreshTokenDto, registerDto, resetPasswordDto, resolveAuthLoginRateLimitConfig, revokeTokenDto, roleIdParam, runAsUser, seedAuthData, tokenIdParam, updatePermissionDto, updateRoleDto, updateTokenDto, updateUserDto, userIdInParam, userIdParam, userListQuery, verifyTokenDto, when, where };
|
package/dist/index.js
CHANGED
|
@@ -3792,6 +3792,8 @@ var AuthService = class AuthService2 {
|
|
|
3792
3792
|
status: body.status ?? "active",
|
|
3793
3793
|
emailVerified: false
|
|
3794
3794
|
});
|
|
3795
|
+
if (!body.email?.trim())
|
|
3796
|
+
return { ...user, emailSent: false };
|
|
3795
3797
|
const { emailSent } = await this.deliverInvitation(user.id, body.email, user.name, body.role);
|
|
3796
3798
|
return { ...user, emailSent };
|
|
3797
3799
|
}
|
|
@@ -6193,7 +6195,9 @@ var revokeTokenDto = z4.object({
|
|
|
6193
6195
|
});
|
|
6194
6196
|
|
|
6195
6197
|
// src/ownership/scopedOwnership.ts
|
|
6196
|
-
import { aliasedTable, eq as eq8, getTableColumns, sql as sql5 } from "drizzle-orm";
|
|
6198
|
+
import { aliasedTable, and as and6, eq as eq8, getTableColumns, is, sql as sql5 } from "drizzle-orm";
|
|
6199
|
+
import { PgTable, QueryBuilder as PgQueryBuilder } from "drizzle-orm/pg-core";
|
|
6200
|
+
import { SQLiteTable, QueryBuilder as SQLiteQueryBuilder } from "drizzle-orm/sqlite-core";
|
|
6197
6201
|
var DEFAULT_ADMIN_ROLES = ["admin"];
|
|
6198
6202
|
var DRIZZLE_NAME = Symbol.for("drizzle:Name");
|
|
6199
6203
|
var DRIZZLE_BASE_NAME = Symbol.for("drizzle:BaseName");
|
|
@@ -6209,6 +6213,11 @@ function where(col) {
|
|
|
6209
6213
|
return { type: "owner", col };
|
|
6210
6214
|
}
|
|
6211
6215
|
__name(where, "where");
|
|
6216
|
+
function when(...rules) {
|
|
6217
|
+
return { type: "when", rules };
|
|
6218
|
+
}
|
|
6219
|
+
__name(when, "when");
|
|
6220
|
+
var resolveWhen = /* @__PURE__ */ __name((step, uid, role) => and6(...step.rules.map((rule) => typeof rule === "function" ? rule(uid, role) : rule)), "resolveWhen");
|
|
6212
6221
|
function isAliased(table) {
|
|
6213
6222
|
return table?.[DRIZZLE_IS_ALIAS] === true;
|
|
6214
6223
|
}
|
|
@@ -6296,7 +6305,7 @@ var OwnershipToken = class {
|
|
|
6296
6305
|
_writeScopeCol;
|
|
6297
6306
|
_adminRoles;
|
|
6298
6307
|
constructor(table, opts) {
|
|
6299
|
-
const name = table[DRIZZLE_NAME] ?? table?._.baseName ?? table?._.name ?? "resource";
|
|
6308
|
+
const name = opts?.name ?? table[DRIZZLE_NAME] ?? table?._.baseName ?? table?._.name ?? "resource";
|
|
6300
6309
|
this.name = name;
|
|
6301
6310
|
this.table = table;
|
|
6302
6311
|
this.symbol = Symbol(name);
|
|
@@ -6305,9 +6314,26 @@ var OwnershipToken = class {
|
|
|
6305
6314
|
isAdmin(role) {
|
|
6306
6315
|
return (this._adminRoles ?? DEFAULT_ADMIN_ROLES).includes(role);
|
|
6307
6316
|
}
|
|
6308
|
-
/**
|
|
6317
|
+
/**
|
|
6318
|
+
* Define the scope rule for a role: a join chain ending in `where()`, and/or
|
|
6319
|
+
* `when()` row conditions. A chain with conditions reaches the rows the
|
|
6320
|
+
* chain reaches that also satisfy them; conditions alone are the whole rule.
|
|
6321
|
+
*/
|
|
6309
6322
|
for(role, ...steps) {
|
|
6310
|
-
|
|
6323
|
+
const chain = steps.filter((step) => step.type !== "when");
|
|
6324
|
+
const conditions = steps.filter((step) => step.type === "when");
|
|
6325
|
+
if (!conditions.length) {
|
|
6326
|
+
this._rules[role] = compile(chain);
|
|
6327
|
+
return this;
|
|
6328
|
+
}
|
|
6329
|
+
const joined = chain.length ? compile(chain) : void 0;
|
|
6330
|
+
this._rules[role] = (uid, query) => {
|
|
6331
|
+
const narrowing = and6(...conditions.map((condition) => resolveWhen(condition, uid, role)));
|
|
6332
|
+
if (!joined)
|
|
6333
|
+
return { query, condition: narrowing };
|
|
6334
|
+
const scoped = joined(uid, query);
|
|
6335
|
+
return { query: scoped.query, condition: and6(scoped.condition, narrowing) };
|
|
6336
|
+
};
|
|
6311
6337
|
return this;
|
|
6312
6338
|
}
|
|
6313
6339
|
/**
|
|
@@ -6349,6 +6375,18 @@ var OwnershipToken = class {
|
|
|
6349
6375
|
return rule(uid, query);
|
|
6350
6376
|
}
|
|
6351
6377
|
};
|
|
6378
|
+
function ownedIds(token, role, userId) {
|
|
6379
|
+
const table = token.table;
|
|
6380
|
+
if (!table?.id)
|
|
6381
|
+
throw new Error(`ownedIds(): ${token.name} has no id column.`);
|
|
6382
|
+
const builder = is(table, SQLiteTable) ? new SQLiteQueryBuilder() : is(table, PgTable) ? new PgQueryBuilder() : null;
|
|
6383
|
+
if (!builder)
|
|
6384
|
+
throw new Error(`ownedIds(): ${token.name} is not a pg or sqlite table.`);
|
|
6385
|
+
const rows = builder.select({ id: table.id }).from(table);
|
|
6386
|
+
const { query, condition } = token.applyScopeSplit(userId, role, rows);
|
|
6387
|
+
return condition === null ? query : query.where(condition);
|
|
6388
|
+
}
|
|
6389
|
+
__name(ownedIds, "ownedIds");
|
|
6352
6390
|
function own(table, opts) {
|
|
6353
6391
|
return new OwnershipToken(table, opts);
|
|
6354
6392
|
}
|
|
@@ -6704,7 +6742,7 @@ __name(Policy, "Policy");
|
|
|
6704
6742
|
|
|
6705
6743
|
// src/ownership/OwnedDecorator.ts
|
|
6706
6744
|
import "reflect-metadata";
|
|
6707
|
-
import { sql as sql7, and as
|
|
6745
|
+
import { sql as sql7, and as and7 } from "drizzle-orm";
|
|
6708
6746
|
import { Injectable as Injectable17, Inject as Inject19, DI as DI3, Container as Container2, REQUEST_ID } from "najm-core";
|
|
6709
6747
|
import { USER as USER2 } from "najm-guard";
|
|
6710
6748
|
|
|
@@ -6866,7 +6904,7 @@ function Owned(token, ...alternatives) {
|
|
|
6866
6904
|
return null;
|
|
6867
6905
|
if (filtered.length === 1)
|
|
6868
6906
|
return filtered[0];
|
|
6869
|
-
return
|
|
6907
|
+
return and7(...filtered);
|
|
6870
6908
|
}
|
|
6871
6909
|
__name(combineConditions, "combineConditions");
|
|
6872
6910
|
function applyQueryOptions(query, opts = {}, whereCondition) {
|
|
@@ -7386,7 +7424,7 @@ import { Inject as Inject24, Injectable as Injectable21 } from "najm-core";
|
|
|
7386
7424
|
import { Transaction as Transaction5 } from "najm-database";
|
|
7387
7425
|
|
|
7388
7426
|
// src/oauth/OAuthAccountRepository.ts
|
|
7389
|
-
import { and as
|
|
7427
|
+
import { and as and8, eq as eq9 } from "drizzle-orm";
|
|
7390
7428
|
import { Inject as Inject23, Repository as Repository7 } from "najm-core";
|
|
7391
7429
|
import { DB as DB7 } from "najm-database";
|
|
7392
7430
|
var __decorate37 = function(decorators, target, key, desc) {
|
|
@@ -7411,11 +7449,11 @@ var OAuthAccountRepository = class OAuthAccountRepository2 {
|
|
|
7411
7449
|
return this.schema.oauthAccounts;
|
|
7412
7450
|
}
|
|
7413
7451
|
async getByProviderAccount(provider, providerAccountId) {
|
|
7414
|
-
const [account] = await this.db.select().from(this.accounts).where(
|
|
7452
|
+
const [account] = await this.db.select().from(this.accounts).where(and8(eq9(this.accounts.provider, provider), eq9(this.accounts.providerAccountId, providerAccountId))).limit(1);
|
|
7415
7453
|
return account;
|
|
7416
7454
|
}
|
|
7417
7455
|
async getByUserProvider(userId, provider) {
|
|
7418
|
-
const [account] = await this.db.select().from(this.accounts).where(
|
|
7456
|
+
const [account] = await this.db.select().from(this.accounts).where(and8(eq9(this.accounts.userId, userId), eq9(this.accounts.provider, provider))).limit(1);
|
|
7419
7457
|
return account;
|
|
7420
7458
|
}
|
|
7421
7459
|
async create(data) {
|
|
@@ -8548,6 +8586,7 @@ export {
|
|
|
8548
8586
|
normalizeTunisianPhone,
|
|
8549
8587
|
oauthAccountsTable,
|
|
8550
8588
|
own,
|
|
8589
|
+
ownedIds,
|
|
8551
8590
|
ownershipCondition,
|
|
8552
8591
|
parseSchema,
|
|
8553
8592
|
permissionIdParam,
|
|
@@ -8580,5 +8619,6 @@ export {
|
|
|
8580
8619
|
userStatusEnum,
|
|
8581
8620
|
usersTable,
|
|
8582
8621
|
verifyTokenDto,
|
|
8622
|
+
when,
|
|
8583
8623
|
where
|
|
8584
8624
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "najm-auth",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.1",
|
|
4
4
|
"description": "Authentication and authorization library for najm framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -96,10 +96,10 @@
|
|
|
96
96
|
"najm-core": "^3.1.0",
|
|
97
97
|
"najm-database": "^2.2.1",
|
|
98
98
|
"najm-guard": "^2.2.1",
|
|
99
|
-
"najm-i18n": "^2.
|
|
100
|
-
"najm-cache": "^2.
|
|
101
|
-
"najm-email": "^3.
|
|
102
|
-
"najm-rate": "^3.
|
|
99
|
+
"najm-i18n": "^2.2.0",
|
|
100
|
+
"najm-cache": "^2.3.0",
|
|
101
|
+
"najm-email": "^3.1.1",
|
|
102
|
+
"najm-rate": "^3.1.0",
|
|
103
103
|
"najm-validation": "^2.0.3",
|
|
104
104
|
"jsonwebtoken": "^9.0.3",
|
|
105
105
|
"jose": "^6.1.3",
|