@loomcore/api 0.2.27 → 0.2.28

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.
Files changed (80) hide show
  1. package/README.md +1 -1
  2. package/dist/__tests__/common-test.utils.js +7 -7
  3. package/dist/__tests__/test-objects.js +3 -27
  4. package/dist/controllers/api.controller.d.ts +1 -3
  5. package/dist/controllers/api.controller.js +28 -27
  6. package/dist/controllers/auth.controller.js +174 -126
  7. package/dist/controllers/authorizations.controller.d.ts +1 -1
  8. package/dist/controllers/authorizations.controller.js +4 -5
  9. package/dist/controllers/features.controller.d.ts +1 -1
  10. package/dist/controllers/features.controller.js +4 -5
  11. package/dist/controllers/organizations.controller.js +95 -44
  12. package/dist/controllers/query-api.controller.d.ts +1 -3
  13. package/dist/controllers/query-api.controller.js +11 -13
  14. package/dist/controllers/roles.controller.d.ts +3 -3
  15. package/dist/controllers/roles.controller.js +4 -5
  16. package/dist/controllers/user-roles.controller.d.ts +1 -1
  17. package/dist/controllers/user-roles.controller.js +4 -5
  18. package/dist/controllers/users.controller.d.ts +0 -2
  19. package/dist/controllers/users.controller.js +1 -3
  20. package/dist/databases/postgres/postgres.database.d.ts +2 -2
  21. package/dist/databases/postgres/postgres.database.js +2 -12
  22. package/dist/decorators/authorize.decorator.d.ts +13 -0
  23. package/dist/decorators/authorize.decorator.js +33 -0
  24. package/dist/errors/unauthorized.error.d.ts +1 -1
  25. package/dist/errors/unauthorized.error.js +5 -3
  26. package/dist/middleware/authorize/authenticate-request.d.ts +3 -0
  27. package/dist/middleware/authorize/authenticate-request.js +21 -0
  28. package/dist/middleware/authorize/authorize.middleware.d.ts +3 -0
  29. package/dist/middleware/authorize/authorize.middleware.js +23 -0
  30. package/dist/middleware/index.d.ts +1 -2
  31. package/dist/middleware/index.js +1 -2
  32. package/dist/models/index.d.ts +0 -1
  33. package/dist/models/index.js +0 -1
  34. package/dist/services/authorizations.service.d.ts +7 -0
  35. package/dist/services/authorizations.service.js +12 -0
  36. package/dist/services/features.service.d.ts +7 -0
  37. package/dist/services/features.service.js +12 -0
  38. package/dist/services/index.d.ts +4 -0
  39. package/dist/services/index.js +4 -0
  40. package/dist/services/refresh-token.service.d.ts +1 -1
  41. package/dist/services/refresh-token.service.js +1 -1
  42. package/dist/services/roles.service.d.ts +7 -0
  43. package/dist/services/roles.service.js +12 -0
  44. package/dist/services/user-roles.service.d.ts +7 -0
  45. package/dist/services/user-roles.service.js +12 -0
  46. package/dist/services/user.service.js +3 -3
  47. package/dist/services/utils/getUserContextAuthorizations.util.d.ts +2 -2
  48. package/dist/services/utils/getUserContextAuthorizations.util.js +3 -3
  49. package/dist/utils/auth/assert-owner-or-admin.util.d.ts +2 -3
  50. package/dist/utils/auth/assert-owner-or-admin.util.js +2 -2
  51. package/dist/utils/auth/assert-user-has-feature.util.d.ts +2 -0
  52. package/dist/utils/auth/assert-user-has-feature.util.js +10 -0
  53. package/dist/utils/auth/{assert-self-or-admin.util.d.ts → assert-user-or-admin.util.d.ts} +1 -1
  54. package/dist/utils/auth/{assert-self-or-admin.util.js → assert-user-or-admin.util.js} +1 -1
  55. package/dist/utils/auth/attempt-login.util.js +3 -3
  56. package/dist/utils/auth/auth-user-specs.util.d.ts +0 -1
  57. package/dist/utils/auth/auth-user-specs.util.js +1 -3
  58. package/dist/utils/auth/authorize-method.util.d.ts +2 -0
  59. package/dist/utils/auth/authorize-method.util.js +8 -0
  60. package/dist/utils/auth/create-new-refresh-token.util.d.ts +1 -1
  61. package/dist/utils/auth/create-new-tokens.util.d.ts +1 -2
  62. package/dist/utils/auth/get-active-refresh-token.util.d.ts +1 -2
  63. package/dist/utils/auth/index.d.ts +3 -1
  64. package/dist/utils/auth/index.js +3 -1
  65. package/dist/utils/auth/is-admin.util.js +1 -2
  66. package/package.json +4 -3
  67. package/dist/middleware/is-authorized.d.ts +0 -4
  68. package/dist/middleware/is-authorized.js +0 -57
  69. package/dist/models/authorization.model.d.ts +0 -16
  70. package/dist/models/authorization.model.js +0 -11
  71. package/dist/models/feature.model.d.ts +0 -7
  72. package/dist/models/feature.model.js +0 -6
  73. package/dist/models/method-auth.model.d.ts +0 -9
  74. package/dist/models/method-auth.model.js +0 -12
  75. package/dist/models/refresh-token.model.d.ts +0 -19
  76. package/dist/models/refresh-token.model.js +0 -12
  77. package/dist/models/role.model.d.ts +0 -7
  78. package/dist/models/role.model.js +0 -6
  79. package/dist/models/user-role.model.d.ts +0 -8
  80. package/dist/models/user-role.model.js +0 -7
@@ -0,0 +1,7 @@
1
+ import { IUserContext, IUserRole } from "@loomcore/common/models";
2
+ import { IDatabase } from "../databases/index.js";
3
+ import { MultiTenantApiService } from "./multi-tenant-api.service.js";
4
+ export declare class UserRolesService extends MultiTenantApiService<IUserRole> {
5
+ constructor(database: IDatabase);
6
+ preProcessEntity(userContext: IUserContext, entity: Partial<IUserRole>, isCreate: boolean, allowId?: boolean): Promise<Partial<IUserRole>>;
7
+ }
@@ -0,0 +1,12 @@
1
+ import { UserRoleModelSpec } from "@loomcore/common/models";
2
+ import { MultiTenantApiService } from "./multi-tenant-api.service.js";
3
+ import { assertUserHasFeature } from "../utils/index.js";
4
+ export class UserRolesService extends MultiTenantApiService {
5
+ constructor(database) {
6
+ super(database, "user_roles", "user_role", UserRoleModelSpec);
7
+ }
8
+ async preProcessEntity(userContext, entity, isCreate, allowId = true) {
9
+ assertUserHasFeature(userContext, ['admin', 'system', 'user-roles']);
10
+ return super.preProcessEntity(userContext, entity, isCreate, allowId);
11
+ }
12
+ }
@@ -1,6 +1,6 @@
1
1
  import { UserSpec, } from "@loomcore/common/models";
2
2
  import { BadRequestError, ServerError } from "../errors/index.js";
3
- import { assertAdmin, assertSelfOrAdmin, } from "../utils/auth/index.js";
3
+ import { assertAdmin, assertUserOrAdmin, } from "../utils/auth/index.js";
4
4
  import { passwordUtils } from "../utils/password.utils.js";
5
5
  import { MultiTenantApiService } from "./multi-tenant-api.service.js";
6
6
  export class UserService extends MultiTenantApiService {
@@ -8,7 +8,7 @@ export class UserService extends MultiTenantApiService {
8
8
  super(database, "users", "user", modelSpec);
9
9
  }
10
10
  async getById(userContext, id) {
11
- assertSelfOrAdmin(userContext, id);
11
+ assertUserOrAdmin(userContext, id);
12
12
  return super.getById(userContext, id);
13
13
  }
14
14
  async get(userContext, queryOptions) {
@@ -39,7 +39,7 @@ export class UserService extends MultiTenantApiService {
39
39
  return super.batchUpdate(userContext, entities);
40
40
  }
41
41
  async partialUpdateById(userContext, id, entity, allowPasswordUpdate = false) {
42
- assertSelfOrAdmin(userContext, id);
42
+ assertUserOrAdmin(userContext, id);
43
43
  this.assertPasswordUpdateAllowed(userContext, id, entity, allowPasswordUpdate);
44
44
  return super.partialUpdateById(userContext, id, entity);
45
45
  }
@@ -1,3 +1,3 @@
1
- import type { IUser, IUserContextAuthorization } from "@loomcore/common/models";
1
+ import type { IUser } from "@loomcore/common/models";
2
2
  import type { IDatabase } from "../../databases/models/index.js";
3
- export declare function getUserContextAuthorizations(database: IDatabase, user: IUser): Promise<IUserContextAuthorization[]>;
3
+ export declare function getUserContextFeatures(database: IDatabase, user: IUser): Promise<string[]>;
@@ -1,9 +1,9 @@
1
1
  import { PostgresDatabase } from "../../databases/postgres/postgres.database.js";
2
- export async function getUserContextAuthorizations(database, user) {
2
+ export async function getUserContextFeatures(database, user) {
3
3
  if (!(database instanceof PostgresDatabase)) {
4
4
  return [];
5
5
  }
6
6
  const orgId = user._orgId;
7
- const authorizations = await database.getUserAuthorizations(user._id, orgId);
8
- return authorizations;
7
+ const features = await database.getUserFeatures(user._id, orgId);
8
+ return features;
9
9
  }
@@ -1,3 +1,2 @@
1
- import type { IUserContext } from "@loomcore/common/models";
2
- import { AppIdType } from "@loomcore/common/types";
3
- export declare function assertOwnerOrAdmin(userContext: IUserContext, createdBy: AppIdType): void;
1
+ import type { IAuditable, IUserContext } from "@loomcore/common/models";
2
+ export declare function assertOwnerOrAdmin(userContext: IUserContext, auditable: IAuditable): void;
@@ -1,10 +1,10 @@
1
1
  import { UnauthorizedError } from "../../errors/index.js";
2
2
  import { isAdmin } from "./is-admin.util.js";
3
- export function assertOwnerOrAdmin(userContext, createdBy) {
3
+ export function assertOwnerOrAdmin(userContext, auditable) {
4
4
  if (isAdmin(userContext)) {
5
5
  return;
6
6
  }
7
- if (userContext.user._id !== createdBy) {
7
+ if (userContext.user._id !== auditable._createdBy) {
8
8
  throw new UnauthorizedError();
9
9
  }
10
10
  }
@@ -0,0 +1,2 @@
1
+ import { IUserContext } from "@loomcore/common/models";
2
+ export declare function assertUserHasFeature(userContext: IUserContext, features: string[]): void;
@@ -0,0 +1,10 @@
1
+ import { UnauthorizedError } from "../../errors/index.js";
2
+ export function assertUserHasFeature(userContext, features) {
3
+ if (features.length === 0) {
4
+ return;
5
+ }
6
+ const missingFeatures = features.filter(feature => !userContext.features.includes(feature));
7
+ if (missingFeatures.length > 0) {
8
+ throw new UnauthorizedError(missingFeatures);
9
+ }
10
+ }
@@ -1,3 +1,3 @@
1
1
  import type { IUserContext } from "@loomcore/common/models";
2
2
  import type { AppIdType } from "@loomcore/common/types";
3
- export declare function assertSelfOrAdmin(userContext: IUserContext, userId: AppIdType): void;
3
+ export declare function assertUserOrAdmin(userContext: IUserContext, userId: AppIdType): void;
@@ -1,6 +1,6 @@
1
1
  import { UnauthorizedError } from "../../errors/index.js";
2
2
  import { isAdmin } from "./is-admin.util.js";
3
- export function assertSelfOrAdmin(userContext, userId) {
3
+ export function assertUserOrAdmin(userContext, userId) {
4
4
  if (isAdmin(userContext)) {
5
5
  return;
6
6
  }
@@ -1,9 +1,9 @@
1
1
  import { EmptyUserContext, } from "@loomcore/common/models";
2
2
  import { BadRequestError } from "../../errors/index.js";
3
3
  import { UserService } from "../../services/user.service.js";
4
- import { getUserContextAuthorizations } from "../../services/utils/getUserContextAuthorizations.util.js";
5
4
  import { passwordUtils } from "../password.utils.js";
6
5
  import { logUserIn } from "./log-user-in.util.js";
6
+ import { getUserContextFeatures } from "../../services/utils/getUserContextAuthorizations.util.js";
7
7
  export async function attemptLogin(database, email, password, deviceId, organization, userService = new UserService(database)) {
8
8
  const lowerCaseEmail = email.toLowerCase();
9
9
  const userContext = {
@@ -22,11 +22,11 @@ export async function attemptLogin(database, email, password, deviceId, organiza
22
22
  if (!passwordsMatch) {
23
23
  throw new BadRequestError("Invalid Credentials");
24
24
  }
25
- const authorizations = await getUserContextAuthorizations(database, user);
25
+ const features = await getUserContextFeatures(database, user);
26
26
  const authenticatedUserContext = {
27
27
  user: user,
28
28
  organization: organization ?? undefined,
29
- authorizations: authorizations,
29
+ features: features,
30
30
  };
31
31
  const tokens = await logUserIn(database, authenticatedUserContext, deviceId, userService);
32
32
  return {
@@ -1,4 +1,3 @@
1
1
  import { type IModelSpec } from "@loomcore/common/models";
2
2
  export declare function createLoginResponseSpec(userContextSpec: IModelSpec): IModelSpec;
3
- export declare function setAuthUserContextSpec(spec: IModelSpec): void;
4
3
  export declare function getAuthUserContextSpec(): IModelSpec;
@@ -2,15 +2,13 @@ import { TokenResponseSchema, UserContextSpec, } from "@loomcore/common/models";
2
2
  import { entityUtils } from "@loomcore/common/utils";
3
3
  import { Type } from "@sinclair/typebox";
4
4
  export function createLoginResponseSpec(userContextSpec) {
5
+ authUserContextSpec = userContextSpec;
5
6
  return entityUtils.getModelSpec(Type.Object({
6
7
  tokens: TokenResponseSchema,
7
8
  userContext: userContextSpec.fullSchema,
8
9
  }), { isEntity: false });
9
10
  }
10
11
  let authUserContextSpec = UserContextSpec;
11
- export function setAuthUserContextSpec(spec) {
12
- authUserContextSpec = spec;
13
- }
14
12
  export function getAuthUserContextSpec() {
15
13
  return authUserContextSpec;
16
14
  }
@@ -0,0 +1,2 @@
1
+ import { RequestHandler } from 'express';
2
+ export declare function authorizeMethod<T extends object>(instance: T, methodName: Extract<keyof T, string>): RequestHandler;
@@ -0,0 +1,8 @@
1
+ import { resolveAuthRequirement } from '../../decorators/authorize.decorator.js';
2
+ import { buildAuthGuard } from '../../middleware/authorize/authorize.middleware.js';
3
+ export function authorizeMethod(instance, methodName) {
4
+ const constructor = instance.constructor;
5
+ const prototype = Object.getPrototypeOf(instance);
6
+ const requirement = resolveAuthRequirement(constructor, prototype, methodName);
7
+ return buildAuthGuard(requirement);
8
+ }
@@ -1,4 +1,4 @@
1
+ import { type IRefreshToken } from "@loomcore/common/models";
1
2
  import type { AppIdType } from "@loomcore/common/types";
2
3
  import type { IDatabase } from "../../databases/models/index.js";
3
- import type { IRefreshToken } from "../../models/refresh-token.model.js";
4
4
  export declare function createNewRefreshToken(database: IDatabase, userId: AppIdType, deviceId: string, orgId?: AppIdType): Promise<IRefreshToken>;
@@ -1,3 +1,2 @@
1
- import type { ITokenResponse, IUserContext } from "@loomcore/common/models";
2
- import type { IRefreshToken } from "../../models/refresh-token.model.js";
1
+ import type { IRefreshToken, ITokenResponse, IUserContext } from "@loomcore/common/models";
3
2
  export declare function createNewTokens(userContext: IUserContext, activeRefreshToken: IRefreshToken): Promise<ITokenResponse>;
@@ -1,4 +1,3 @@
1
- import type { IUserContext } from "@loomcore/common/models";
1
+ import type { IRefreshToken, IUserContext } from "@loomcore/common/models";
2
2
  import type { IDatabase } from "../../databases/models/index.js";
3
- import type { IRefreshToken } from "../../models/refresh-token.model.js";
4
3
  export declare function getActiveRefreshToken(database: IDatabase, userContext: IUserContext, refreshToken: string, deviceId: string): Promise<IRefreshToken | null>;
@@ -1,8 +1,9 @@
1
1
  export * from "./assert-admin.util.js";
2
2
  export * from "./assert-owner-or-admin.util.js";
3
- export * from "./assert-self-or-admin.util.js";
3
+ export * from "./assert-user-or-admin.util.js";
4
4
  export * from "./attempt-login.util.js";
5
5
  export * from "./auth-user-specs.util.js";
6
+ export * from "./assert-user-has-feature.util.js";
6
7
  export * from "./change-password.util.js";
7
8
  export * from "./create-new-refresh-token.util.js";
8
9
  export * from "./create-new-tokens.util.js";
@@ -21,3 +22,4 @@ export * from "./request-token-using-refresh-token.util.js";
21
22
  export * from "./reset-password.util.js";
22
23
  export * from "./send-reset-password-email.util.js";
23
24
  export * from "./update-last-logged-in.util.js";
25
+ export * from "./authorize-method.util.js";
@@ -1,8 +1,9 @@
1
1
  export * from "./assert-admin.util.js";
2
2
  export * from "./assert-owner-or-admin.util.js";
3
- export * from "./assert-self-or-admin.util.js";
3
+ export * from "./assert-user-or-admin.util.js";
4
4
  export * from "./attempt-login.util.js";
5
5
  export * from "./auth-user-specs.util.js";
6
+ export * from "./assert-user-has-feature.util.js";
6
7
  export * from "./change-password.util.js";
7
8
  export * from "./create-new-refresh-token.util.js";
8
9
  export * from "./create-new-tokens.util.js";
@@ -21,3 +22,4 @@ export * from "./request-token-using-refresh-token.util.js";
21
22
  export * from "./reset-password.util.js";
22
23
  export * from "./send-reset-password-email.util.js";
23
24
  export * from "./update-last-logged-in.util.js";
25
+ export * from "./authorize-method.util.js";
@@ -1,4 +1,3 @@
1
1
  export function isAdmin(userContext) {
2
- return userContext.authorizations.some((authorization) => authorization.feature === "admin" ||
3
- authorization.feature === "system");
2
+ return userContext.features.some((feature) => feature === "admin" || feature === "system");
4
3
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/api",
3
- "version": "0.2.27",
3
+ "version": "0.2.28",
4
4
  "private": false,
5
5
  "description": "Loom Core Api - An opinionated Node.js api using Typescript, Express, and MongoDb or PostgreSQL",
6
6
  "scripts": {
@@ -55,10 +55,11 @@
55
55
  "dependencies": {
56
56
  "jsonwebtoken": "^9.0.2",
57
57
  "node-mailjet": "^6.0.8",
58
- "qs": "^6.15.2"
58
+ "qs": "^6.15.2",
59
+ "reflect-metadata": "^0.2.2"
59
60
  },
60
61
  "peerDependencies": {
61
- "@loomcore/common": "^0.0.78",
62
+ "@loomcore/common": "^0.0.80",
62
63
  "@sinclair/typebox": "0.34.33",
63
64
  "cookie-parser": "^1.4.6",
64
65
  "cors": "^2.8.5",
@@ -1,4 +0,0 @@
1
- import type { NextFunction, Request, Response } from "express";
2
- import type { MethodAuth } from "../models/method-auth.model.js";
3
- declare const isAuthorized: (config: MethodAuth) => (req: Request, _res: Response, next: NextFunction) => void;
4
- export { isAuthorized };
@@ -1,57 +0,0 @@
1
- import jwt from "jsonwebtoken";
2
- import { BadRequestError, UnauthenticatedError, UnauthorizedError, } from "../errors/index.js";
3
- import { getAuthUserContextSpec } from "../utils/auth/auth-user-specs.util.js";
4
- import { getAuthConfig } from "../utils/auth/get-auth-config.util.js";
5
- function resolveAuthMethod(req) {
6
- switch (req.method.toUpperCase()) {
7
- case "GET":
8
- case "HEAD":
9
- return "read";
10
- case "POST":
11
- return "create";
12
- case "PUT":
13
- case "PATCH":
14
- return "update";
15
- case "DELETE":
16
- return "delete";
17
- default:
18
- return null;
19
- }
20
- }
21
- function assertFeatureRequirement(userContext, requirement) {
22
- if (requirement === undefined) {
23
- throw new UnauthorizedError();
24
- }
25
- if (requirement === true) {
26
- return;
27
- }
28
- if (!requirement.some((feature) => userContext.authorizations.some((authorization) => authorization.feature === feature))) {
29
- throw new UnauthorizedError();
30
- }
31
- }
32
- const isAuthorized = (config) => {
33
- return (req, _res, next) => {
34
- let token = null;
35
- if (req.headers?.authorization) {
36
- const authHeader = req.headers.authorization;
37
- const authHeaderArray = authHeader.split("Bearer ");
38
- if (authHeaderArray?.length > 1) {
39
- token = authHeaderArray[1];
40
- }
41
- }
42
- if (!token) {
43
- throw new UnauthenticatedError();
44
- }
45
- const authConfig = getAuthConfig();
46
- const rawPayload = jwt.verify(token, authConfig.clientSecret);
47
- const userContext = getAuthUserContextSpec().decode(rawPayload);
48
- req.userContext = userContext;
49
- const method = resolveAuthMethod(req);
50
- if (!method) {
51
- throw new BadRequestError("Invalid HTTP method");
52
- }
53
- assertFeatureRequirement(userContext, config[method]);
54
- next();
55
- };
56
- };
57
- export { isAuthorized };
@@ -1,16 +0,0 @@
1
- import { IAuditable, IEntity } from "@loomcore/common/models";
2
- export interface IAuthorization extends IEntity, IAuditable {
3
- roleId: string;
4
- featureId: string;
5
- startDate?: Date;
6
- endDate?: Date;
7
- config?: any;
8
- }
9
- export declare const AuthorizationSchema: import("@sinclair/typebox").TObject<{
10
- roleId: import("@sinclair/typebox").TString;
11
- featureId: import("@sinclair/typebox").TString;
12
- startDate: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>>;
13
- endDate: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>>;
14
- config: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TAny>;
15
- }>;
16
- export declare const AuthorizationModelSpec: import("@loomcore/common/models").IModelSpec<import("@sinclair/typebox").TSchema>;
@@ -1,11 +0,0 @@
1
- import { Type } from "@sinclair/typebox";
2
- import { entityUtils } from "@loomcore/common/utils";
3
- import { TypeboxIsoDate } from "@loomcore/common/validation";
4
- export const AuthorizationSchema = Type.Object({
5
- roleId: Type.String({ minLength: 1, title: 'Role ID' }),
6
- featureId: Type.String({ minLength: 1, title: 'Feature ID' }),
7
- startDate: Type.Optional(TypeboxIsoDate({ title: 'Start Date' })),
8
- endDate: Type.Optional(TypeboxIsoDate({ title: 'End Date' })),
9
- config: Type.Optional(Type.Any({ title: 'Config' }))
10
- });
11
- export const AuthorizationModelSpec = entityUtils.getModelSpec(AuthorizationSchema, { isAuditable: true });
@@ -1,7 +0,0 @@
1
- import { IEntity } from "@loomcore/common/models";
2
- import { TSchema } from "@sinclair/typebox";
3
- export interface IFeature extends IEntity {
4
- name: string;
5
- }
6
- export declare const FeatureSchema: TSchema;
7
- export declare const FeatureModelSpec: import("@loomcore/common/models").IModelSpec<TSchema>;
@@ -1,6 +0,0 @@
1
- import { entityUtils } from "@loomcore/common/utils";
2
- import { Type } from "@sinclair/typebox";
3
- export const FeatureSchema = Type.Object({
4
- name: Type.String({ minLength: 1 }),
5
- });
6
- export const FeatureModelSpec = entityUtils.getModelSpec(FeatureSchema);
@@ -1,9 +0,0 @@
1
- export type FeatureRequirement = true | string[];
2
- export interface MethodAuth {
3
- read?: FeatureRequirement;
4
- create?: FeatureRequirement;
5
- update?: FeatureRequirement;
6
- delete?: FeatureRequirement;
7
- }
8
- export declare const authenticated: MethodAuth;
9
- export declare const adminWrites: MethodAuth;
@@ -1,12 +0,0 @@
1
- export const authenticated = {
2
- read: true,
3
- create: true,
4
- update: true,
5
- delete: true,
6
- };
7
- export const adminWrites = {
8
- read: true,
9
- create: ["admin"],
10
- update: ["admin"],
11
- delete: ["admin"],
12
- };
@@ -1,19 +0,0 @@
1
- import type { IEntity } from "@loomcore/common/models";
2
- import type { AppIdType } from "@loomcore/common/types";
3
- export interface IRefreshToken extends IEntity {
4
- token: string;
5
- deviceId: string;
6
- userId: AppIdType;
7
- expiresOn: number;
8
- created: Date;
9
- createdBy: AppIdType;
10
- }
11
- export declare const refreshTokenSchema: import("@sinclair/typebox").TObject<{
12
- token: import("@sinclair/typebox").TString;
13
- deviceId: import("@sinclair/typebox").TString;
14
- userId: import("@sinclair/typebox").TSchema;
15
- expiresOn: import("@sinclair/typebox").TNumber;
16
- created: import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>;
17
- createdBy: import("@sinclair/typebox").TSchema;
18
- }>;
19
- export declare const refreshTokenModelSpec: import("@loomcore/common/models").IModelSpec<import("@sinclair/typebox").TSchema>;
@@ -1,12 +0,0 @@
1
- import { entityUtils } from "@loomcore/common/utils";
2
- import { getIdSchema, TypeboxIsoDate } from "@loomcore/common/validation";
3
- import { Type } from "@sinclair/typebox";
4
- export const refreshTokenSchema = Type.Object({
5
- token: Type.String({ minLength: 1 }),
6
- deviceId: Type.String({ minLength: 1 }),
7
- userId: getIdSchema(),
8
- expiresOn: Type.Number(),
9
- created: TypeboxIsoDate({ title: "Created Date" }),
10
- createdBy: getIdSchema(),
11
- });
12
- export const refreshTokenModelSpec = entityUtils.getModelSpec(refreshTokenSchema);
@@ -1,7 +0,0 @@
1
- import { IEntity } from "@loomcore/common/models";
2
- import { TSchema } from "@sinclair/typebox";
3
- export interface IRole extends IEntity {
4
- name: string;
5
- }
6
- export declare const RoleSchema: TSchema;
7
- export declare const RoleModelSpec: import("@loomcore/common/models").IModelSpec<TSchema>;
@@ -1,6 +0,0 @@
1
- import { Type } from "@sinclair/typebox";
2
- import { entityUtils } from "@loomcore/common/utils";
3
- export const RoleSchema = Type.Object({
4
- name: Type.String({ minLength: 1 }),
5
- });
6
- export const RoleModelSpec = entityUtils.getModelSpec(RoleSchema);
@@ -1,8 +0,0 @@
1
- import { IAuditable, IEntity } from "@loomcore/common/models";
2
- import { TSchema } from "@sinclair/typebox";
3
- export interface IUserRole extends IEntity, IAuditable {
4
- userId: string;
5
- roleId: string;
6
- }
7
- export declare const UserRoleSchema: TSchema;
8
- export declare const UserRoleModelSpec: import("@loomcore/common/models").IModelSpec<TSchema>;
@@ -1,7 +0,0 @@
1
- import { entityUtils } from "@loomcore/common/utils";
2
- import { Type } from "@sinclair/typebox";
3
- export const UserRoleSchema = Type.Object({
4
- userId: Type.String({ minLength: 1 }),
5
- roleId: Type.String({ minLength: 1 }),
6
- });
7
- export const UserRoleModelSpec = entityUtils.getModelSpec(UserRoleSchema, { isAuditable: true });