@loomcore/api 0.2.42 → 0.2.45
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/LICENSE +201 -201
- package/dist/__tests__/common-test.utils.d.ts +13 -13
- package/dist/__tests__/common-test.utils.js +72 -72
- package/dist/__tests__/models/category.model.d.ts +1 -1
- package/dist/__tests__/models/category.model.js +2 -2
- package/dist/__tests__/models/product-with-category.model.d.ts +3 -3
- package/dist/__tests__/models/product-with-category.model.js +4 -4
- package/dist/__tests__/models/product.model.d.ts +2 -2
- package/dist/__tests__/models/product.model.js +2 -2
- package/dist/__tests__/models/test-entity.model.d.ts +2 -2
- package/dist/__tests__/models/test-entity.model.js +2 -2
- package/dist/__tests__/models/test-item.model.d.ts +1 -1
- package/dist/__tests__/models/test-item.model.js +3 -3
- package/dist/__tests__/mongo-db.test-database.js +1 -1
- package/dist/__tests__/postgres-test-migrations/postgres-test-schema.d.ts +2 -2
- package/dist/__tests__/postgres-test-migrations/postgres-test-schema.js +38 -38
- package/dist/__tests__/postgres.test-database.d.ts +2 -2
- package/dist/__tests__/postgres.test-database.js +25 -25
- package/dist/__tests__/test-database.interface.d.ts +1 -1
- package/dist/__tests__/test-email-client.d.ts +1 -1
- package/dist/__tests__/test-express-app.d.ts +3 -3
- package/dist/__tests__/test-express-app.js +12 -12
- package/dist/__tests__/test-objects.d.ts +1 -1
- package/dist/__tests__/test-objects.js +26 -26
- package/dist/config/base-api-config.d.ts +2 -2
- package/dist/config/base-api-config.js +17 -17
- package/dist/controllers/auth.controller.d.ts +4 -4
- package/dist/controllers/auth.controller.js +32 -32
- package/dist/controllers/authorizations.controller.d.ts +4 -4
- package/dist/controllers/authorizations.controller.js +4 -4
- package/dist/controllers/features.controller.d.ts +4 -4
- package/dist/controllers/features.controller.js +4 -4
- package/dist/controllers/index.d.ts +10 -10
- package/dist/controllers/index.js +10 -10
- package/dist/controllers/organizations.controller.d.ts +5 -5
- package/dist/controllers/organizations.controller.js +10 -10
- package/dist/controllers/roles.controller.d.ts +4 -4
- package/dist/controllers/roles.controller.js +4 -4
- package/dist/controllers/types.d.ts +2 -2
- package/dist/controllers/user-roles.controller.d.ts +4 -4
- package/dist/controllers/user-roles.controller.js +4 -4
- package/dist/controllers/users.controller.d.ts +5 -5
- package/dist/controllers/users.controller.js +4 -4
- package/dist/databases/models/database.interface.d.ts +5 -5
- package/dist/databases/mongo-db/commands/mongo-batch-update.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-batch-update.command.js +5 -5
- package/dist/databases/mongo-db/commands/mongo-create-many.command.d.ts +1 -1
- package/dist/databases/mongo-db/commands/mongo-create-many.command.js +1 -1
- package/dist/databases/mongo-db/commands/mongo-create.command.d.ts +1 -1
- package/dist/databases/mongo-db/commands/mongo-create.command.js +1 -1
- package/dist/databases/mongo-db/commands/mongo-delete-by-id.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-delete-by-id.command.js +4 -4
- package/dist/databases/mongo-db/commands/mongo-delete-many.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-delete-many.command.js +2 -2
- package/dist/databases/mongo-db/commands/mongo-full-updateby-id.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-full-updateby-id.command.js +4 -4
- package/dist/databases/mongo-db/commands/mongo-partial-update-by-id.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-partial-update-by-id.command.js +4 -4
- package/dist/databases/mongo-db/commands/mongo-update.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-update.command.js +3 -3
- package/dist/databases/mongo-db/migrations/mongo-initial-schema.d.ts +2 -2
- package/dist/databases/mongo-db/migrations/mongo-initial-schema.js +108 -108
- package/dist/databases/mongo-db/models/no-sql-pipeline.d.ts +4 -4
- package/dist/databases/mongo-db/models/no-sql-pipeline.interface.d.ts +3 -3
- package/dist/databases/mongo-db/models/no-sql-pipeline.js +1 -1
- package/dist/databases/mongo-db/mongo-db.database.d.ts +7 -7
- package/dist/databases/mongo-db/mongo-db.database.js +5 -5
- package/dist/databases/mongo-db/queries/mongo-find-one.query.d.ts +2 -2
- package/dist/databases/mongo-db/queries/mongo-find-one.query.js +1 -1
- package/dist/databases/mongo-db/queries/mongo-find.query.d.ts +2 -2
- package/dist/databases/mongo-db/queries/mongo-find.query.js +1 -1
- package/dist/databases/mongo-db/queries/mongo-get-all.query.d.ts +2 -2
- package/dist/databases/mongo-db/queries/mongo-get-all.query.js +1 -1
- package/dist/databases/mongo-db/queries/mongo-get-by-id.query.d.ts +4 -4
- package/dist/databases/mongo-db/queries/mongo-get-by-id.query.js +3 -3
- package/dist/databases/mongo-db/queries/mongo-get-count.query.d.ts +1 -1
- package/dist/databases/mongo-db/queries/mongo-get.query.d.ts +3 -3
- package/dist/databases/mongo-db/queries/mongo-get.query.js +2 -2
- package/dist/databases/mongo-db/utils/build-find-options.util.d.ts +2 -2
- package/dist/databases/mongo-db/utils/build-mongo-url.util.d.ts +1 -1
- package/dist/databases/mongo-db/utils/build-mongo-url.util.js +4 -4
- package/dist/databases/operations/__tests__/models/test-agent.model.d.ts +2 -2
- package/dist/databases/operations/__tests__/models/test-agent.model.js +3 -3
- package/dist/databases/operations/__tests__/models/test-client-report.model.d.ts +4 -4
- package/dist/databases/operations/__tests__/models/test-client-report.model.js +5 -5
- package/dist/databases/operations/__tests__/models/test-district.model.d.ts +2 -2
- package/dist/databases/operations/__tests__/models/test-district.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-email-address.model.d.ts +1 -1
- package/dist/databases/operations/__tests__/models/test-email-address.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-person.model.d.ts +4 -4
- package/dist/databases/operations/__tests__/models/test-person.model.js +4 -4
- package/dist/databases/operations/__tests__/models/test-phone-number.model.d.ts +1 -1
- package/dist/databases/operations/__tests__/models/test-phone-number.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-policy.model.d.ts +3 -3
- package/dist/databases/operations/__tests__/models/test-policy.model.js +4 -4
- package/dist/databases/operations/__tests__/models/test-premium.model.d.ts +1 -1
- package/dist/databases/operations/__tests__/models/test-premium.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-school.model.d.ts +2 -2
- package/dist/databases/operations/__tests__/models/test-school.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-state.model.d.ts +1 -1
- package/dist/databases/operations/__tests__/models/test-state.model.js +2 -2
- package/dist/databases/operations/operation.d.ts +3 -3
- package/dist/databases/postgres/commands/postgres-batch-update.command.d.ts +1 -1
- package/dist/databases/postgres/commands/postgres-batch-update.command.js +11 -11
- package/dist/databases/postgres/commands/postgres-create-many.command.js +5 -5
- package/dist/databases/postgres/commands/postgres-create.command.d.ts +3 -3
- package/dist/databases/postgres/commands/postgres-create.command.js +5 -5
- package/dist/databases/postgres/commands/postgres-delete-by-id.command.d.ts +1 -1
- package/dist/databases/postgres/commands/postgres-delete-by-id.command.js +1 -1
- package/dist/databases/postgres/commands/postgres-delete-many.command.d.ts +2 -2
- package/dist/databases/postgres/commands/postgres-delete-many.command.js +1 -1
- package/dist/databases/postgres/commands/postgres-full-update-by-id.command.d.ts +1 -1
- package/dist/databases/postgres/commands/postgres-full-update-by-id.command.js +4 -4
- package/dist/databases/postgres/commands/postgres-partial-update-by-id.command.d.ts +1 -1
- package/dist/databases/postgres/commands/postgres-partial-update-by-id.command.js +11 -11
- package/dist/databases/postgres/commands/postgres-update.command.d.ts +2 -2
- package/dist/databases/postgres/commands/postgres-update.command.js +11 -11
- package/dist/databases/postgres/migrations/postgres-initial-schema.d.ts +2 -2
- package/dist/databases/postgres/migrations/postgres-initial-schema.js +69 -69
- package/dist/databases/postgres/postgres.database.d.ts +6 -6
- package/dist/databases/postgres/postgres.database.js +18 -18
- package/dist/databases/postgres/queries/postgres-find-one.query.d.ts +1 -1
- package/dist/databases/postgres/queries/postgres-find-one.query.js +2 -2
- package/dist/databases/postgres/queries/postgres-find.query.d.ts +1 -1
- package/dist/databases/postgres/queries/postgres-find.query.js +2 -2
- package/dist/databases/postgres/queries/postgres-get-all.query.d.ts +1 -1
- package/dist/databases/postgres/queries/postgres-get-all.query.js +3 -3
- package/dist/databases/postgres/queries/postgres-get-by-id.query.d.ts +1 -1
- package/dist/databases/postgres/queries/postgres-get-by-id.query.js +5 -5
- package/dist/databases/postgres/queries/postgres-get-count.query.js +1 -1
- package/dist/databases/postgres/queries/postgres-get.query.d.ts +2 -2
- package/dist/databases/postgres/queries/postgres-get.query.js +9 -9
- package/dist/databases/postgres/utils/build-count-query.d.ts +1 -1
- package/dist/databases/postgres/utils/build-count-query.js +1 -1
- package/dist/databases/postgres/utils/build-join-clauses.d.ts +1 -1
- package/dist/databases/postgres/utils/build-join-clauses.js +7 -7
- package/dist/databases/postgres/utils/build-order-by-clause.d.ts +1 -1
- package/dist/databases/postgres/utils/build-pagination-clause.d.ts +1 -1
- package/dist/databases/postgres/utils/build-postgres-url.util.d.ts +1 -1
- package/dist/databases/postgres/utils/build-postgres-url.util.js +2 -2
- package/dist/databases/postgres/utils/build-select-clause.js +9 -9
- package/dist/databases/postgres/utils/build-where-clause.d.ts +1 -1
- package/dist/databases/postgres/utils/build-where-clause.js +1 -1
- package/dist/databases/postgres/utils/columns-and-values-from-entity.d.ts +1 -1
- package/dist/databases/postgres/utils/does-table-exist.util.d.ts +1 -1
- package/dist/databases/postgres/utils/does-table-exist.util.js +5 -5
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +1 -0
- package/dist/middleware/authorize/authenticate-request.d.ts +2 -2
- package/dist/middleware/authorize/authenticate-request.js +5 -5
- package/dist/middleware/index.d.ts +4 -4
- package/dist/middleware/index.js +4 -4
- package/dist/models/app-config.interface.d.ts +1 -1
- package/dist/models/base-api-config.interface.d.ts +6 -6
- package/dist/models/initial-database-config.interface.d.ts +3 -3
- package/dist/models/log-level.type.d.ts +1 -1
- package/dist/services/authorizations.service.d.ts +3 -3
- package/dist/services/authorizations.service.js +7 -7
- package/dist/services/email.service.js +5 -5
- package/dist/services/features.service.d.ts +3 -3
- package/dist/services/features.service.js +4 -4
- package/dist/services/generic-api-service/generic-api-service.interface.d.ts +6 -6
- package/dist/services/generic-api-service/generic-api.service.d.ts +8 -8
- package/dist/services/generic-api-service/generic-api.service.js +7 -7
- package/dist/services/index.d.ts +16 -16
- package/dist/services/index.js +16 -16
- package/dist/services/multi-tenant-api.service.d.ts +4 -4
- package/dist/services/multi-tenant-api.service.js +9 -9
- package/dist/services/organization-domain.service.d.ts +3 -3
- package/dist/services/organization-domain.service.js +3 -3
- package/dist/services/organization.service.d.ts +4 -4
- package/dist/services/organization.service.js +7 -7
- package/dist/services/password-reset-token.service.d.ts +3 -3
- package/dist/services/password-reset-token.service.js +5 -5
- package/dist/services/refresh-token.service.d.ts +3 -3
- package/dist/services/refresh-token.service.js +3 -3
- package/dist/services/roles.service.d.ts +3 -3
- package/dist/services/roles.service.js +4 -4
- package/dist/services/tenant-query-decorator.d.ts +1 -1
- package/dist/services/tenant-query-decorator.js +8 -8
- package/dist/services/user-roles.service.d.ts +3 -3
- package/dist/services/user-roles.service.js +4 -4
- package/dist/services/user.service.d.ts +4 -4
- package/dist/services/user.service.js +11 -11
- package/dist/services/utils/audit-for-create.util.d.ts +1 -1
- package/dist/services/utils/audit-for-create.util.js +2 -2
- package/dist/services/utils/audit-for-update.util.d.ts +1 -1
- package/dist/services/utils/audit-for-update.util.js +2 -2
- package/dist/services/utils/strip-sender-provided-system-properties.util.d.ts +1 -1
- package/dist/services/utils/strip-sender-provided-system-properties.util.js +4 -4
- package/dist/utils/auth/assert-admin-or-feature.util.d.ts +1 -1
- package/dist/utils/auth/assert-admin-or-feature.util.js +2 -2
- package/dist/utils/auth/assert-admin.util.d.ts +1 -1
- package/dist/utils/auth/assert-admin.util.js +2 -2
- package/dist/utils/auth/assert-owner-or-admin.util.d.ts +1 -1
- package/dist/utils/auth/assert-owner-or-admin.util.js +2 -2
- package/dist/utils/auth/assert-user-has-feature.util.d.ts +1 -1
- package/dist/utils/auth/assert-user-has-feature.util.js +1 -1
- package/dist/utils/auth/assert-user-or-admin.util.d.ts +2 -2
- package/dist/utils/auth/assert-user-or-admin.util.js +2 -2
- package/dist/utils/auth/attempt-login.util.d.ts +4 -4
- package/dist/utils/auth/attempt-login.util.js +8 -8
- package/dist/utils/auth/auth-user-specs.util.d.ts +1 -1
- package/dist/utils/auth/auth-user-specs.util.js +3 -3
- package/dist/utils/auth/change-password.util.d.ts +4 -4
- package/dist/utils/auth/change-password.util.js +2 -2
- package/dist/utils/auth/create-new-refresh-token.util.d.ts +3 -3
- package/dist/utils/auth/create-new-refresh-token.util.js +8 -8
- package/dist/utils/auth/create-new-tokens.util.d.ts +1 -1
- package/dist/utils/auth/create-new-tokens.util.js +3 -3
- package/dist/utils/auth/generate-device-id.util.js +2 -2
- package/dist/utils/auth/generate-refresh-token.util.js +2 -2
- package/dist/utils/auth/get-active-refresh-token.util.d.ts +2 -2
- package/dist/utils/auth/get-active-refresh-token.util.js +1 -1
- package/dist/utils/auth/get-and-set-device-id-cookie.util.d.ts +1 -1
- package/dist/utils/auth/get-and-set-device-id-cookie.util.js +4 -4
- package/dist/utils/auth/get-auth-config.util.d.ts +1 -1
- package/dist/utils/auth/get-auth-config.util.js +3 -3
- package/dist/utils/auth/get-device-id-from-cookie.util.d.ts +1 -1
- package/dist/utils/auth/index.d.ts +26 -26
- package/dist/utils/auth/index.js +26 -26
- package/dist/utils/auth/is-admin.util.d.ts +1 -1
- package/dist/utils/auth/is-admin.util.js +1 -1
- package/dist/utils/auth/log-user-in.util.d.ts +3 -3
- package/dist/utils/auth/log-user-in.util.js +5 -5
- package/dist/utils/auth/request-token-using-refresh-token.util.d.ts +4 -4
- package/dist/utils/auth/request-token-using-refresh-token.util.js +7 -7
- package/dist/utils/auth/reset-password.util.d.ts +4 -4
- package/dist/utils/auth/reset-password.util.js +8 -8
- package/dist/utils/auth/send-reset-password-email.util.d.ts +2 -2
- package/dist/utils/auth/send-reset-password-email.util.js +5 -5
- package/dist/utils/auth/update-last-logged-in.util.d.ts +3 -3
- package/dist/utils/auth/update-last-logged-in.util.js +3 -3
- package/dist/utils/create-public-spec.utils.d.ts +1 -1
- package/dist/utils/create-public-spec.utils.js +2 -2
- package/dist/utils/express.utils.d.ts +4 -4
- package/dist/utils/express.utils.js +5 -5
- package/dist/utils/index.d.ts +10 -10
- package/dist/utils/index.js +10 -10
- package/dist/utils/jwt.utils.d.ts +1 -1
- package/dist/utils/jwt.utils.js +3 -3
- package/dist/utils/logger.utils.d.ts +1 -1
- package/dist/utils/logger.utils.js +10 -10
- package/dist/utils/password.utils.js +7 -7
- package/package.json +2 -1
package/dist/utils/auth/index.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
15
|
-
export * from
|
|
16
|
-
export * from
|
|
17
|
-
export * from
|
|
18
|
-
export * from
|
|
19
|
-
export * from
|
|
20
|
-
export * from
|
|
21
|
-
export * from
|
|
22
|
-
export * from
|
|
23
|
-
export * from
|
|
24
|
-
export * from
|
|
25
|
-
export * from
|
|
26
|
-
export * from
|
|
1
|
+
export * from './assert-admin.util.js';
|
|
2
|
+
export * from './assert-admin-or-feature.util.js';
|
|
3
|
+
export * from './assert-owner-or-admin.util.js';
|
|
4
|
+
export * from './assert-user-or-admin.util.js';
|
|
5
|
+
export * from './attempt-login.util.js';
|
|
6
|
+
export * from './auth-user-specs.util.js';
|
|
7
|
+
export * from './assert-user-has-feature.util.js';
|
|
8
|
+
export * from './change-password.util.js';
|
|
9
|
+
export * from './create-new-refresh-token.util.js';
|
|
10
|
+
export * from './create-new-tokens.util.js';
|
|
11
|
+
export * from './generate-device-id.util.js';
|
|
12
|
+
export * from './generate-refresh-token.util.js';
|
|
13
|
+
export * from './get-active-refresh-token.util.js';
|
|
14
|
+
export * from './get-and-set-device-id-cookie.util.js';
|
|
15
|
+
export * from './get-auth-config.util.js';
|
|
16
|
+
export * from './get-device-id-from-cookie.util.js';
|
|
17
|
+
export * from './get-expires-on-from-days.util.js';
|
|
18
|
+
export * from './get-expires-on-from-minutes.util.js';
|
|
19
|
+
export * from './get-expires-on-from-seconds.util.js';
|
|
20
|
+
export * from './is-admin.util.js';
|
|
21
|
+
export * from './log-user-in.util.js';
|
|
22
|
+
export * from './request-token-using-refresh-token.util.js';
|
|
23
|
+
export * from './reset-password.util.js';
|
|
24
|
+
export * from './send-reset-password-email.util.js';
|
|
25
|
+
export * from './update-last-logged-in.util.js';
|
|
26
|
+
export * from './authorize-method.util.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { IUserContext } from
|
|
1
|
+
import type { IUserContext } from '@loomcore/common/models';
|
|
2
2
|
export declare function isAdmin(userContext: IUserContext): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ITokenResponse, IUserContext } from
|
|
2
|
-
import type { IDatabase } from
|
|
3
|
-
import type { UserService } from
|
|
1
|
+
import type { ITokenResponse, IUserContext } from '@loomcore/common/models';
|
|
2
|
+
import type { IDatabase } from '../../databases/models/index.js';
|
|
3
|
+
import type { UserService } from '../../services/user.service.js';
|
|
4
4
|
export declare function logUserIn(database: IDatabase, userContext: IUserContext, deviceId: string, userService?: UserService): Promise<ITokenResponse>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { generateJwt } from
|
|
2
|
-
import { createNewRefreshToken } from
|
|
3
|
-
import { getAuthConfig } from
|
|
4
|
-
import { getExpiresOnFromSeconds } from
|
|
5
|
-
import { updateLastLoggedIn } from
|
|
1
|
+
import { generateJwt } from '../jwt.utils.js';
|
|
2
|
+
import { createNewRefreshToken } from './create-new-refresh-token.util.js';
|
|
3
|
+
import { getAuthConfig } from './get-auth-config.util.js';
|
|
4
|
+
import { getExpiresOnFromSeconds } from './get-expires-on-from-seconds.util.js';
|
|
5
|
+
import { updateLastLoggedIn } from './update-last-logged-in.util.js';
|
|
6
6
|
export async function logUserIn(database, userContext, deviceId, userService) {
|
|
7
7
|
const authConfig = getAuthConfig();
|
|
8
8
|
const accessToken = generateJwt(userContext);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type ITokenResponse } from
|
|
2
|
-
import type { IDatabase } from
|
|
3
|
-
import { AuthorizationsService } from
|
|
4
|
-
import { UserService } from
|
|
1
|
+
import { type ITokenResponse } from '@loomcore/common/models';
|
|
2
|
+
import type { IDatabase } from '../../databases/models/index.js';
|
|
3
|
+
import { AuthorizationsService } from '../../services/authorizations.service.js';
|
|
4
|
+
import { UserService } from '../../services/user.service.js';
|
|
5
5
|
export declare function requestTokenUsingRefreshToken(database: IDatabase, refreshToken: string, deviceId: string, userService?: UserService, authorizationsService?: AuthorizationsService): Promise<ITokenResponse | null>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { getSystemUserContext, } from
|
|
2
|
-
import { AuthorizationsService } from
|
|
3
|
-
import { UserService } from
|
|
4
|
-
import { createNewTokens } from
|
|
5
|
-
import { getActiveRefreshToken } from
|
|
6
|
-
import { BadRequestError } from
|
|
1
|
+
import { getSystemUserContext, } from '@loomcore/common/models';
|
|
2
|
+
import { AuthorizationsService } from '../../services/authorizations.service.js';
|
|
3
|
+
import { UserService } from '../../services/user.service.js';
|
|
4
|
+
import { createNewTokens } from './create-new-tokens.util.js';
|
|
5
|
+
import { getActiveRefreshToken } from './get-active-refresh-token.util.js';
|
|
6
|
+
import { BadRequestError } from '../../errors/index.js';
|
|
7
7
|
export async function requestTokenUsingRefreshToken(database, refreshToken, deviceId, userService = new UserService(database), authorizationsService = new AuthorizationsService(database)) {
|
|
8
8
|
const systemUserContext = getSystemUserContext();
|
|
9
9
|
const activeRefreshToken = await getActiveRefreshToken(database, systemUserContext, refreshToken, deviceId);
|
|
@@ -15,7 +15,7 @@ export async function requestTokenUsingRefreshToken(database, refreshToken, devi
|
|
|
15
15
|
};
|
|
16
16
|
const user = await userService.findOne(systemUserContext, userQueryOptions);
|
|
17
17
|
if (!user) {
|
|
18
|
-
throw new BadRequestError(
|
|
18
|
+
throw new BadRequestError('User not found');
|
|
19
19
|
}
|
|
20
20
|
const features = await authorizationsService.getUserContextFeatures(user);
|
|
21
21
|
const userContext = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type IModelSpec, type IOrganization } from
|
|
2
|
-
import type { IDatabase } from
|
|
3
|
-
import type { UpdateResult } from
|
|
4
|
-
import { UserService } from
|
|
1
|
+
import { type IModelSpec, type IOrganization } from '@loomcore/common/models';
|
|
2
|
+
import type { IDatabase } from '../../databases/models/index.js';
|
|
3
|
+
import type { UpdateResult } from '../../databases/models/update-result.js';
|
|
4
|
+
import { UserService } from '../../services/user.service.js';
|
|
5
5
|
export declare function resetPassword(database: IDatabase, email: string, passwordResetToken: string, password: string, organization: IOrganization | null, userService?: UserService, userSpec?: IModelSpec): Promise<UpdateResult>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { EmptyUserContext, passwordValidator, UserSpec, } from
|
|
2
|
-
import { entityUtils } from
|
|
3
|
-
import { BadRequestError, ServerError } from
|
|
4
|
-
import { PasswordResetTokenService } from
|
|
5
|
-
import { UserService } from
|
|
6
|
-
import { changePassword } from
|
|
1
|
+
import { EmptyUserContext, passwordValidator, UserSpec, } from '@loomcore/common/models';
|
|
2
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
3
|
+
import { BadRequestError, ServerError } from '../../errors/index.js';
|
|
4
|
+
import { PasswordResetTokenService } from '../../services/password-reset-token.service.js';
|
|
5
|
+
import { UserService } from '../../services/user.service.js';
|
|
6
|
+
import { changePassword } from './change-password.util.js';
|
|
7
7
|
export async function resetPassword(database, email, passwordResetToken, password, organization, userService = new UserService(database), userSpec = UserSpec) {
|
|
8
8
|
const validationErrors = entityUtils.validate(userSpec, { password: password }, true, passwordValidator);
|
|
9
|
-
entityUtils.handleValidationResult(validationErrors,
|
|
9
|
+
entityUtils.handleValidationResult(validationErrors, 'AuthService.resetPassword');
|
|
10
10
|
const lowerCaseEmail = email.toLowerCase();
|
|
11
11
|
const passwordResetTokenService = new PasswordResetTokenService(database);
|
|
12
12
|
const userContext = {
|
|
@@ -24,7 +24,7 @@ export async function resetPassword(database, email, passwordResetToken, passwor
|
|
|
24
24
|
}
|
|
25
25
|
if (retrievedPasswordResetToken.token !== passwordResetToken ||
|
|
26
26
|
retrievedPasswordResetToken.expiresOn < Date.now()) {
|
|
27
|
-
throw new BadRequestError(
|
|
27
|
+
throw new BadRequestError('Invalid password reset token');
|
|
28
28
|
}
|
|
29
29
|
const user = await userService.findOne(userContext, {
|
|
30
30
|
filters: { email: { eq: lowerCaseEmail } },
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type IUserContext } from
|
|
2
|
-
import type { IDatabase } from
|
|
1
|
+
import { type IUserContext } from '@loomcore/common/models';
|
|
2
|
+
import type { IDatabase } from '../../databases/models/index.js';
|
|
3
3
|
export declare function sendResetPasswordEmail(userContext: IUserContext, database: IDatabase, emailAddress: string, clientBaseUrl: string): Promise<void>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ServerError } from
|
|
2
|
-
import { EmailService } from
|
|
3
|
-
import { PasswordResetTokenService } from
|
|
4
|
-
import { getAuthConfig } from
|
|
5
|
-
import { getExpiresOnFromMinutes } from
|
|
1
|
+
import { ServerError } from '../../errors/index.js';
|
|
2
|
+
import { EmailService } from '../../services/email.service.js';
|
|
3
|
+
import { PasswordResetTokenService } from '../../services/password-reset-token.service.js';
|
|
4
|
+
import { getAuthConfig } from './get-auth-config.util.js';
|
|
5
|
+
import { getExpiresOnFromMinutes } from './get-expires-on-from-minutes.util.js';
|
|
6
6
|
export async function sendResetPasswordEmail(userContext, database, emailAddress, clientBaseUrl) {
|
|
7
7
|
const authConfig = getAuthConfig();
|
|
8
8
|
const passwordResetTokenService = new PasswordResetTokenService(database);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AppIdType } from
|
|
2
|
-
import type { IDatabase } from
|
|
3
|
-
import { UserService } from
|
|
1
|
+
import type { AppIdType } from '@loomcore/common/types';
|
|
2
|
+
import type { IDatabase } from '../../databases/models/index.js';
|
|
3
|
+
import { UserService } from '../../services/user.service.js';
|
|
4
4
|
export declare function updateLastLoggedIn(database: IDatabase, userId: AppIdType, userService?: UserService): Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { getSystemUserContext } from
|
|
2
|
-
import moment from
|
|
3
|
-
import { UserService } from
|
|
1
|
+
import { getSystemUserContext } from '@loomcore/common/models';
|
|
2
|
+
import moment from 'moment';
|
|
3
|
+
import { UserService } from '../../services/user.service.js';
|
|
4
4
|
export async function updateLastLoggedIn(database, userId, userService = new UserService(database)) {
|
|
5
5
|
try {
|
|
6
6
|
const updates = {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IModelSpec } from
|
|
1
|
+
import { IModelSpec } from '@loomcore/common/models';
|
|
2
2
|
export declare function createPublicSpec(spec: IModelSpec): IModelSpec;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { entityUtils } from
|
|
2
|
-
import { config } from
|
|
1
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
2
|
+
import { config } from '../config/index.js';
|
|
3
3
|
export function createPublicSpec(spec) {
|
|
4
4
|
if (config.debug?.showAuditFields) {
|
|
5
5
|
return spec;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Application } from 'express';
|
|
2
|
-
import { MongoClient } from
|
|
3
|
-
import type { Client, Pool } from
|
|
4
|
-
import { Server } from
|
|
5
|
-
import { IBaseApiConfig } from
|
|
2
|
+
import { MongoClient } from 'mongodb';
|
|
3
|
+
import type { Client, Pool } from 'pg';
|
|
4
|
+
import { Server } from 'http';
|
|
5
|
+
import { IBaseApiConfig } from '../models/index.js';
|
|
6
6
|
import { IDatabase } from '../databases/models/index.js';
|
|
7
7
|
type RouteSetupFunction = (app: Application, database: IDatabase, config: IBaseApiConfig) => void;
|
|
8
8
|
declare function setupExpressApp(database: IDatabase, config: IBaseApiConfig, setupRoutes: RouteSetupFunction): Application;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
|
-
import cookieParser from
|
|
3
|
-
import bodyParser from
|
|
4
|
-
import cors from
|
|
2
|
+
import cookieParser from 'cookie-parser';
|
|
3
|
+
import bodyParser from 'body-parser';
|
|
4
|
+
import cors from 'cors';
|
|
5
5
|
import qs from 'qs';
|
|
6
|
-
import { NotFoundError } from
|
|
7
|
-
import { errorHandler } from
|
|
6
|
+
import { NotFoundError } from '../errors/not-found.error.js';
|
|
7
|
+
import { errorHandler } from '../middleware/error-handler.js';
|
|
8
8
|
import { ensureUserContext } from '../middleware/ensure-user-context.js';
|
|
9
9
|
function setupExpressApp(database, config, setupRoutes) {
|
|
10
10
|
const app = express();
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
1
|
+
export * from './address.utils.js';
|
|
2
|
+
export * from './api.utils.js';
|
|
3
|
+
export * from './auth/index.js';
|
|
4
|
+
export * from './conversion.utils.js';
|
|
5
|
+
export * from './create-public-spec.utils.js';
|
|
6
|
+
export * from './express.utils.js';
|
|
7
|
+
export * from './jwt.utils.js';
|
|
8
|
+
export * from './logger.utils.js';
|
|
9
|
+
export * from './password.utils.js';
|
|
10
|
+
export * from './string.utils.js';
|
package/dist/utils/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
1
|
+
export * from './address.utils.js';
|
|
2
|
+
export * from './api.utils.js';
|
|
3
|
+
export * from './auth/index.js';
|
|
4
|
+
export * from './conversion.utils.js';
|
|
5
|
+
export * from './create-public-spec.utils.js';
|
|
6
|
+
export * from './express.utils.js';
|
|
7
|
+
export * from './jwt.utils.js';
|
|
8
|
+
export * from './logger.utils.js';
|
|
9
|
+
export * from './password.utils.js';
|
|
10
|
+
export * from './string.utils.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { IUserContext } from
|
|
1
|
+
import type { IUserContext } from '@loomcore/common/models';
|
|
2
2
|
export declare function generateJwt(userContext: IUserContext): string;
|
package/dist/utils/jwt.utils.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import jwt from
|
|
2
|
-
import { getAuthConfig } from
|
|
1
|
+
import jwt from 'jsonwebtoken';
|
|
2
|
+
import { getAuthConfig } from './auth/get-auth-config.util.js';
|
|
3
3
|
export function generateJwt(userContext) {
|
|
4
4
|
const authConfig = getAuthConfig();
|
|
5
5
|
const jwtExpiryConfig = authConfig.jwtExpirationInSeconds;
|
|
6
|
-
const jwtExpirationInSeconds = typeof jwtExpiryConfig ===
|
|
6
|
+
const jwtExpirationInSeconds = typeof jwtExpiryConfig === 'string'
|
|
7
7
|
? Number.parseInt(jwtExpiryConfig, 10)
|
|
8
8
|
: jwtExpiryConfig;
|
|
9
9
|
return jwt.sign(userContext, authConfig.clientSecret, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { config } from
|
|
1
|
+
import { config } from '../config/index.js';
|
|
2
2
|
const LOG_LEVEL_PRIORITIES = {
|
|
3
3
|
debug: 0,
|
|
4
4
|
info: 1,
|
|
@@ -7,13 +7,13 @@ const LOG_LEVEL_PRIORITIES = {
|
|
|
7
7
|
};
|
|
8
8
|
export const getCurrentLogLevel = () => {
|
|
9
9
|
const envLogLevel = config.debug?.logLevel?.toLowerCase();
|
|
10
|
-
if (envLogLevel ===
|
|
11
|
-
envLogLevel ===
|
|
12
|
-
envLogLevel ===
|
|
13
|
-
envLogLevel ===
|
|
10
|
+
if (envLogLevel === 'debug' ||
|
|
11
|
+
envLogLevel === 'info' ||
|
|
12
|
+
envLogLevel === 'warn' ||
|
|
13
|
+
envLogLevel === 'error') {
|
|
14
14
|
return envLogLevel;
|
|
15
15
|
}
|
|
16
|
-
return
|
|
16
|
+
return 'info';
|
|
17
17
|
};
|
|
18
18
|
const shouldLog = (messageLevel) => {
|
|
19
19
|
const currentLevel = getCurrentLogLevel();
|
|
@@ -21,22 +21,22 @@ const shouldLog = (messageLevel) => {
|
|
|
21
21
|
};
|
|
22
22
|
export const logger = {
|
|
23
23
|
debug: (...args) => {
|
|
24
|
-
if (shouldLog(
|
|
24
|
+
if (shouldLog('debug')) {
|
|
25
25
|
console.debug(...args);
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
info: (...args) => {
|
|
29
|
-
if (shouldLog(
|
|
29
|
+
if (shouldLog('info')) {
|
|
30
30
|
console.info(...args);
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
warn: (...args) => {
|
|
34
|
-
if (shouldLog(
|
|
34
|
+
if (shouldLog('warn')) {
|
|
35
35
|
console.warn(...args);
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
error: (...args) => {
|
|
39
|
-
if (shouldLog(
|
|
39
|
+
if (shouldLog('error')) {
|
|
40
40
|
console.error(...args);
|
|
41
41
|
}
|
|
42
42
|
},
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { randomBytes, scrypt } from
|
|
2
|
-
import { promisify } from
|
|
1
|
+
import { randomBytes, scrypt } from 'node:crypto';
|
|
2
|
+
import { promisify } from 'util';
|
|
3
3
|
const scryptAsync = promisify(scrypt);
|
|
4
4
|
async function hashPassword(password) {
|
|
5
|
-
const salt = randomBytes(8).toString(
|
|
5
|
+
const salt = randomBytes(8).toString('hex');
|
|
6
6
|
const buf = (await scryptAsync(password, salt, 64));
|
|
7
|
-
return `${buf.toString(
|
|
7
|
+
return `${buf.toString('hex')}.${salt}`;
|
|
8
8
|
}
|
|
9
9
|
async function comparePasswords(storedPassword, suppliedPassword) {
|
|
10
|
-
if (!storedPassword?.includes(
|
|
10
|
+
if (!storedPassword?.includes('.')) {
|
|
11
11
|
return false;
|
|
12
12
|
}
|
|
13
|
-
const [hashedPassword, salt] = storedPassword.split(
|
|
13
|
+
const [hashedPassword, salt] = storedPassword.split('.');
|
|
14
14
|
if (!salt) {
|
|
15
15
|
return false;
|
|
16
16
|
}
|
|
17
17
|
const buf = (await scryptAsync(suppliedPassword, salt, 64));
|
|
18
|
-
return buf.toString(
|
|
18
|
+
return buf.toString('hex') === hashedPassword;
|
|
19
19
|
}
|
|
20
20
|
export const passwordUtils = {
|
|
21
21
|
hashPassword,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loomcore/api",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.45",
|
|
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": {
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"./config": "./dist/config/index.js",
|
|
47
47
|
"./controllers": "./dist/controllers/index.js",
|
|
48
48
|
"./databases": "./dist/databases/index.js",
|
|
49
|
+
"./decorators": "./dist/decorators/index.js",
|
|
49
50
|
"./errors": "./dist/errors/index.js",
|
|
50
51
|
"./middleware": "./dist/middleware/index.js",
|
|
51
52
|
"./models": "./dist/models/index.js",
|