From 3a3a107811bb6ff37560961a044d1c267d5eed11 Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Tue, 20 Dec 2022 00:01:40 +0800 Subject: [PATCH 1/2] refactor: schema export and id generator --- packages/cli/package.json | 1 + .../cli/src/commands/database/seed/index.ts | 24 +++++++++---------- packages/console/src/App.tsx | 2 +- .../src/components/ApplicationName/index.tsx | 2 +- .../components/ApplicationSelector/index.tsx | 2 +- packages/console/src/hooks/use-api.ts | 2 +- .../src/pages/ApiResourceDetails/index.tsx | 3 +-- packages/console/src/pages/GetStarted/hook.ts | 3 +-- .../src/libraries/sign-in-experience/index.ts | 2 +- packages/core/src/libraries/user.ts | 2 +- packages/core/src/middleware/koa-auth.ts | 2 +- .../core/src/middleware/koa-check-demo-app.ts | 2 +- .../core/src/middleware/koa-error-handler.ts | 5 ++++ packages/core/src/oidc/adapter.ts | 2 +- packages/core/src/routes/application.test.ts | 4 ++-- packages/core/src/routes/application.ts | 4 ++-- packages/core/src/routes/connector.ts | 3 +-- .../core/src/routes/interaction/index.test.ts | 3 +-- packages/core/src/routes/phrase.test.ts | 8 +++---- packages/core/src/routes/phrase.ts | 5 +--- packages/core/src/routes/resource.ts | 2 +- .../core/src/routes/session/index.test.ts | 5 ++-- packages/core/src/routes/session/index.ts | 2 +- .../middleware/koa-guard-session-action.ts | 2 +- .../core/src/routes/session/password.test.ts | 5 ++-- packages/core/src/routes/session/password.ts | 2 +- packages/core/src/routes/well-known.test.ts | 10 ++++---- packages/core/src/routes/well-known.ts | 2 +- packages/demo-app/src/App.tsx | 2 +- .../integration-tests/src/client/index.ts | 2 +- packages/integration-tests/src/constants.ts | 3 +-- .../src/tests/api/application.test.ts | 2 +- .../src/tests/api/get-access-token.test.ts | 2 +- .../src/tests/api/resource.test.ts | 2 +- .../src/tests/api/session.test.ts | 2 +- .../src/tests/api/wellknown.test.ts | 2 +- packages/phrases/src/locales/de/errors.ts | 1 + packages/phrases/src/locales/en/errors.ts | 1 + packages/phrases/src/locales/fr/errors.ts | 1 + packages/phrases/src/locales/ko/errors.ts | 1 + packages/phrases/src/locales/pt-br/errors.ts | 1 + packages/phrases/src/locales/pt-pt/errors.ts | 1 + packages/phrases/src/locales/tr-tr/errors.ts | 1 + packages/phrases/src/locales/zh-cn/errors.ts | 1 + .../1.0.0_beta.10-1-logto-config.ts | 2 +- ...ta.10-1663923211-machine-to-machine-app.ts | 2 +- ...1.0.0_beta.10-1664265197-custom-phrases.ts | 2 +- ...1-1664347703-rename-language-key-to-tag.ts | 2 +- ...64356000-add-created-at-column-to-users.ts | 2 +- ...ect-user-created-at-column-by-user-logs.ts | 2 +- ....0.0_beta.14-1665300135-sign-in-sign-up.ts | 2 +- ...ta.14-1667283640-remove-forgot-password.ts | 2 +- ...eta.14-1667292082-remove-sign-in-method.ts | 2 +- .../1.0.0_beta.14-1667374974-user-suspend.ts | 2 +- ...4-1667900481-add-passcode-type-continue.ts | 2 +- ...90-support-multiple-connector-instances.ts | 2 +- ...ext-1668666600-remove-connector-enabled.ts | 2 +- .../next-1669091623-roles-and-scopes.ts | 2 +- .../alterations/next-1669702299-sign-up.ts | 2 +- .../next-1671039448-add-user-name-index.ts | 2 +- .../next-1671080370-terms-of-use.ts | 2 +- packages/schemas/package.json | 14 +++++++++-- packages/schemas/src/index.ts | 2 +- packages/schemas/tsconfig.build.json | 2 +- packages/schemas/tsconfig.json | 1 + packages/shared/src/utils/id.ts | 7 ------ packages/shared/src/utils/index.ts | 1 - .../core-kit/src/utilities}/id.test.ts | 10 +------- packages/toolkit/core-kit/src/utilities/id.ts | 6 +++++ .../toolkit/core-kit/src/utilities/index.ts | 2 +- .../core-kit/src/utilities/string.test.ts | 15 ------------ .../toolkit/core-kit/src/utilities/string.ts | 6 ----- 72 files changed, 109 insertions(+), 127 deletions(-) delete mode 100644 packages/shared/src/utils/id.ts rename packages/{shared/src/utils => toolkit/core-kit/src/utilities}/id.test.ts (57%) create mode 100644 packages/toolkit/core-kit/src/utilities/id.ts delete mode 100644 packages/toolkit/core-kit/src/utilities/string.test.ts delete mode 100644 packages/toolkit/core-kit/src/utilities/string.ts diff --git a/packages/cli/package.json b/packages/cli/package.json index d830fbb20..263b658c8 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -43,6 +43,7 @@ "url": "https://github.com/logto-io/logto/issues" }, "dependencies": { + "@logto/core-kit": "workspace:*", "@logto/schemas": "workspace:*", "@logto/shared": "workspace:*", "@silverhand/essentials": "^1.3.0", diff --git a/packages/cli/src/commands/database/seed/index.ts b/packages/cli/src/commands/database/seed/index.ts index 75a70a1f7..5ce0ce4f6 100644 --- a/packages/cli/src/commands/database/seed/index.ts +++ b/packages/cli/src/commands/database/seed/index.ts @@ -1,8 +1,16 @@ import { readdir, readFile } from 'fs/promises'; import path from 'path'; -import { logtoConfigGuards, LogtoOidcConfigKey, seeds } from '@logto/schemas'; -import { buildApplicationSecret } from '@logto/shared'; +import { generateStandardId } from '@logto/core-kit'; +import { + logtoConfigGuards, + LogtoOidcConfigKey, + managementResource, + defaultSignInExperience, + createDefaultSetting, + createDemoAppApplication, + defaultRole, +} from '@logto/schemas'; import chalk from 'chalk'; import type { DatabasePool, DatabaseTransactionConnection } from 'slonik'; import { sql } from 'slonik'; @@ -40,21 +48,11 @@ const createTables = async (connection: DatabaseTransactionConnection) => { }; const seedTables = async (connection: DatabaseTransactionConnection) => { - const { - managementResource, - defaultSignInExperience, - createDefaultSetting, - createDemoAppApplication, - defaultRole, - } = seeds; - await Promise.all([ connection.query(insertInto(managementResource, 'resources')), connection.query(insertInto(createDefaultSetting(), 'settings')), connection.query(insertInto(defaultSignInExperience, 'sign_in_experiences')), - connection.query( - insertInto(createDemoAppApplication(buildApplicationSecret()), 'applications') - ), + connection.query(insertInto(createDemoAppApplication(generateStandardId()), 'applications')), connection.query(insertInto(defaultRole, 'roles')), updateDatabaseTimestamp(connection, await getLatestAlterationTimestamp()), ]); diff --git a/packages/console/src/App.tsx b/packages/console/src/App.tsx index d3f0ca60a..3c9e5dc7e 100644 --- a/packages/console/src/App.tsx +++ b/packages/console/src/App.tsx @@ -1,6 +1,6 @@ import { UserScope } from '@logto/core-kit'; import { LogtoProvider } from '@logto/react'; -import { adminConsoleApplicationId, managementResource } from '@logto/schemas/lib/seeds'; +import { adminConsoleApplicationId, managementResource } from '@logto/schemas'; import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom'; import { SWRConfig } from 'swr'; diff --git a/packages/console/src/components/ApplicationName/index.tsx b/packages/console/src/components/ApplicationName/index.tsx index 6164b61d2..25f5c987b 100644 --- a/packages/console/src/components/ApplicationName/index.tsx +++ b/packages/console/src/components/ApplicationName/index.tsx @@ -1,5 +1,5 @@ import type { Application } from '@logto/schemas'; -import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds'; +import { adminConsoleApplicationId } from '@logto/schemas'; import { useTranslation } from 'react-i18next'; import { Link } from 'react-router-dom'; import useSWR from 'swr'; diff --git a/packages/console/src/components/AuditLogTable/components/ApplicationSelector/index.tsx b/packages/console/src/components/AuditLogTable/components/ApplicationSelector/index.tsx index 275cd0349..e685bfab3 100644 --- a/packages/console/src/components/AuditLogTable/components/ApplicationSelector/index.tsx +++ b/packages/console/src/components/AuditLogTable/components/ApplicationSelector/index.tsx @@ -1,5 +1,5 @@ import type { Application } from '@logto/schemas'; -import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds'; +import { adminConsoleApplicationId } from '@logto/schemas'; import { useTranslation } from 'react-i18next'; import useSWR from 'swr'; diff --git a/packages/console/src/hooks/use-api.ts b/packages/console/src/hooks/use-api.ts index d7f229af4..aeef5ab2d 100644 --- a/packages/console/src/hooks/use-api.ts +++ b/packages/console/src/hooks/use-api.ts @@ -1,6 +1,6 @@ import { useLogto } from '@logto/react'; import type { RequestErrorBody } from '@logto/schemas'; -import { managementResource } from '@logto/schemas/lib/seeds'; +import { managementResource } from '@logto/schemas'; import ky from 'ky'; import { useCallback, useMemo } from 'react'; import { toast } from 'react-hot-toast'; diff --git a/packages/console/src/pages/ApiResourceDetails/index.tsx b/packages/console/src/pages/ApiResourceDetails/index.tsx index 8e07b4d93..9ef26b21d 100644 --- a/packages/console/src/pages/ApiResourceDetails/index.tsx +++ b/packages/console/src/pages/ApiResourceDetails/index.tsx @@ -1,6 +1,5 @@ import type { Resource } from '@logto/schemas'; -import { AppearanceMode } from '@logto/schemas'; -import { managementResource } from '@logto/schemas/lib/seeds'; +import { AppearanceMode, managementResource } from '@logto/schemas'; import { useEffect, useState } from 'react'; import { useForm } from 'react-hook-form'; import { toast } from 'react-hot-toast'; diff --git a/packages/console/src/pages/GetStarted/hook.ts b/packages/console/src/pages/GetStarted/hook.ts index 70e8d4053..caa2e9881 100644 --- a/packages/console/src/pages/GetStarted/hook.ts +++ b/packages/console/src/pages/GetStarted/hook.ts @@ -1,7 +1,6 @@ import type { AdminConsoleKey } from '@logto/phrases'; import type { Application } from '@logto/schemas'; -import { AppearanceMode } from '@logto/schemas'; -import { demoAppApplicationId } from '@logto/schemas/lib/seeds'; +import { AppearanceMode, demoAppApplicationId } from '@logto/schemas'; import { useMemo } from 'react'; import { useNavigate } from 'react-router-dom'; import useSWR from 'swr'; diff --git a/packages/core/src/libraries/sign-in-experience/index.ts b/packages/core/src/libraries/sign-in-experience/index.ts index 76e925819..b1ad9de86 100644 --- a/packages/core/src/libraries/sign-in-experience/index.ts +++ b/packages/core/src/libraries/sign-in-experience/index.ts @@ -5,7 +5,7 @@ import { adminConsoleApplicationId, adminConsoleSignInExperience, demoAppApplicationId, -} from '@logto/schemas/lib/seeds/index.js'; +} from '@logto/schemas'; import { deduplicate } from '@silverhand/essentials'; import i18next from 'i18next'; diff --git a/packages/core/src/libraries/user.ts b/packages/core/src/libraries/user.ts index 8f190c903..9ef49041a 100644 --- a/packages/core/src/libraries/user.ts +++ b/packages/core/src/libraries/user.ts @@ -1,6 +1,6 @@ +import { buildIdGenerator } from '@logto/core-kit'; import type { User, CreateUser } from '@logto/schemas'; import { Users, UsersPasswordEncryptionMethod } from '@logto/schemas'; -import { buildIdGenerator } from '@logto/shared'; import type { Nullable } from '@silverhand/essentials'; import { deduplicate } from '@silverhand/essentials'; import { argon2Verify } from 'hash-wasm'; diff --git a/packages/core/src/middleware/koa-auth.ts b/packages/core/src/middleware/koa-auth.ts index ee9ba010e..a3d806875 100644 --- a/packages/core/src/middleware/koa-auth.ts +++ b/packages/core/src/middleware/koa-auth.ts @@ -1,7 +1,7 @@ import type { IncomingHttpHeaders } from 'http'; import { UserRole } from '@logto/schemas'; -import { managementResource } from '@logto/schemas/lib/seeds/index.js'; +import { managementResource } from '@logto/schemas'; import type { Optional } from '@silverhand/essentials'; import { conditional } from '@silverhand/essentials'; import { jwtVerify } from 'jose'; diff --git a/packages/core/src/middleware/koa-check-demo-app.ts b/packages/core/src/middleware/koa-check-demo-app.ts index e005c1ba5..f8dba3913 100644 --- a/packages/core/src/middleware/koa-check-demo-app.ts +++ b/packages/core/src/middleware/koa-check-demo-app.ts @@ -1,4 +1,4 @@ -import { demoAppApplicationId } from '@logto/schemas/lib/seeds/index.js'; +import { demoAppApplicationId } from '@logto/schemas'; import type { MiddlewareType } from 'koa'; import { findApplicationById } from '#src/queries/application.js'; diff --git a/packages/core/src/middleware/koa-error-handler.ts b/packages/core/src/middleware/koa-error-handler.ts index e4f029e52..d8226bd91 100644 --- a/packages/core/src/middleware/koa-error-handler.ts +++ b/packages/core/src/middleware/koa-error-handler.ts @@ -30,6 +30,11 @@ export default function koaErrorHandler(): Middleware< return; } + // Should log 500 errors in prod anyway + if (envSet.values.isProduction) { + console.error(error); + } + ctx.status = 500; ctx.body = { message: 'Internal server error.' }; } diff --git a/packages/core/src/oidc/adapter.ts b/packages/core/src/oidc/adapter.ts index 8e3fa5ed7..ecbb598ce 100644 --- a/packages/core/src/oidc/adapter.ts +++ b/packages/core/src/oidc/adapter.ts @@ -1,6 +1,6 @@ import type { CreateApplication, OidcClientMetadata } from '@logto/schemas'; import { ApplicationType } from '@logto/schemas'; -import { adminConsoleApplicationId, demoAppApplicationId } from '@logto/schemas/lib/seeds/index.js'; +import { adminConsoleApplicationId, demoAppApplicationId } from '@logto/schemas'; import { tryThat } from '@logto/shared'; import { deduplicate } from '@silverhand/essentials'; import { addSeconds } from 'date-fns'; diff --git a/packages/core/src/routes/application.test.ts b/packages/core/src/routes/application.test.ts index 5106240df..0330deb10 100644 --- a/packages/core/src/routes/application.test.ts +++ b/packages/core/src/routes/application.test.ts @@ -29,10 +29,10 @@ const { findApplicationById } = mockEsm('#src/queries/application.js', () => ({ ), })); -mockEsm('@logto/shared', () => ({ +mockEsm('@logto/core-kit', () => ({ // eslint-disable-next-line unicorn/consistent-function-scoping buildIdGenerator: jest.fn(() => () => 'randomId'), - buildApplicationSecret: jest.fn(() => 'randomId'), + generateStandardId: jest.fn(() => 'randomId'), })); const { createRequester } = await import('#src/utils/test-utils.js'); diff --git a/packages/core/src/routes/application.ts b/packages/core/src/routes/application.ts index b634d8c42..cc75a5726 100644 --- a/packages/core/src/routes/application.ts +++ b/packages/core/src/routes/application.ts @@ -1,5 +1,5 @@ +import { generateStandardId, buildIdGenerator } from '@logto/core-kit'; import { Applications } from '@logto/schemas'; -import { buildApplicationSecret, buildIdGenerator } from '@logto/shared'; import { object, string } from 'zod'; import koaGuard from '#src/middleware/koa-guard.js'; @@ -47,7 +47,7 @@ export default function applicationRoutes(router: T) { ctx.body = await insertApplication({ id: applicationId(), - secret: buildApplicationSecret(), + secret: generateStandardId(), oidcClientMetadata: buildOidcClientMetadata(oidcClientMetadata), ...rest, }); diff --git a/packages/core/src/routes/connector.ts b/packages/core/src/routes/connector.ts index b1b99af43..d3c9eea09 100644 --- a/packages/core/src/routes/connector.ts +++ b/packages/core/src/routes/connector.ts @@ -1,8 +1,7 @@ import { MessageTypes } from '@logto/connector-kit'; -import { emailRegEx, phoneRegEx } from '@logto/core-kit'; +import { emailRegEx, phoneRegEx, buildIdGenerator } from '@logto/core-kit'; import type { ConnectorFactoryResponse, ConnectorResponse } from '@logto/schemas'; import { arbitraryObjectGuard, Connectors, ConnectorType } from '@logto/schemas'; -import { buildIdGenerator } from '@logto/shared'; import cleanDeep from 'clean-deep'; import { object, string } from 'zod'; diff --git a/packages/core/src/routes/interaction/index.test.ts b/packages/core/src/routes/interaction/index.test.ts index cb073317f..bc61ef3c2 100644 --- a/packages/core/src/routes/interaction/index.test.ts +++ b/packages/core/src/routes/interaction/index.test.ts @@ -1,6 +1,5 @@ import { ConnectorType } from '@logto/connector-kit'; -import { Event } from '@logto/schemas'; -import { demoAppApplicationId } from '@logto/schemas/lib/seeds/application.js'; +import { Event, demoAppApplicationId } from '@logto/schemas'; import { mockEsm, mockEsmDefault, mockEsmWithActual, pickDefault } from '@logto/shared/esm'; import { mockSignInExperience } from '#src/__mocks__/sign-in-experience.js'; diff --git a/packages/core/src/routes/phrase.test.ts b/packages/core/src/routes/phrase.test.ts index 7ffa5d302..0bbdcb77e 100644 --- a/packages/core/src/routes/phrase.test.ts +++ b/packages/core/src/routes/phrase.test.ts @@ -1,14 +1,12 @@ import zhCN from '@logto/phrases-ui/lib/locales/zh-cn.js'; import type { SignInExperience } from '@logto/schemas'; -import { - adminConsoleApplicationId, - adminConsoleSignInExperience, -} from '@logto/schemas/lib/seeds/index.js'; +import { adminConsoleApplicationId, adminConsoleSignInExperience } from '@logto/schemas'; import { mockEsm, mockEsmWithActual, pickDefault } from '@logto/shared/esm'; +import { createMockProvider } from '#src/test-utils/oidc-provider.js'; + import { zhCnTag } from '#src/__mocks__/custom-phrase.js'; import { mockSignInExperience } from '#src/__mocks__/index.js'; -import { createMockProvider } from '#src/test-utils/oidc-provider.js'; const { jest } = import.meta; diff --git a/packages/core/src/routes/phrase.ts b/packages/core/src/routes/phrase.ts index e01097297..40036ffcb 100644 --- a/packages/core/src/routes/phrase.ts +++ b/packages/core/src/routes/phrase.ts @@ -1,8 +1,5 @@ import { isBuiltInLanguageTag } from '@logto/phrases-ui'; -import { - adminConsoleApplicationId, - adminConsoleSignInExperience, -} from '@logto/schemas/lib/seeds/index.js'; +import { adminConsoleApplicationId, adminConsoleSignInExperience } from '@logto/schemas'; import type { Provider } from 'oidc-provider'; import detectLanguage from '#src/i18n/detect-language.js'; diff --git a/packages/core/src/routes/resource.ts b/packages/core/src/routes/resource.ts index 43e9be35d..09897e92e 100644 --- a/packages/core/src/routes/resource.ts +++ b/packages/core/src/routes/resource.ts @@ -1,5 +1,5 @@ +import { buildIdGenerator } from '@logto/core-kit'; import { Resources } from '@logto/schemas'; -import { buildIdGenerator } from '@logto/shared'; import { object, string } from 'zod'; import koaGuard from '#src/middleware/koa-guard.js'; diff --git a/packages/core/src/routes/session/index.test.ts b/packages/core/src/routes/session/index.test.ts index de1577edc..7a81fdd89 100644 --- a/packages/core/src/routes/session/index.test.ts +++ b/packages/core/src/routes/session/index.test.ts @@ -1,12 +1,13 @@ import type { User } from '@logto/schemas'; -import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds/index.js'; +import { adminConsoleApplicationId } from '@logto/schemas'; import { Provider } from 'oidc-provider'; -import { mockUser } from '#src/__mocks__/index.js'; import { createRequester } from '#src/utils/test-utils.js'; import sessionRoutes from './index.js'; +import { mockUser } from '#src/__mocks__/index.js'; + const findUserById = jest.fn(async (): Promise => mockUser); const updateUserById = jest.fn(async (..._args: unknown[]) => ({ id: 'id' })); diff --git a/packages/core/src/routes/session/index.ts b/packages/core/src/routes/session/index.ts index 126048c90..95f6c3f71 100644 --- a/packages/core/src/routes/session/index.ts +++ b/packages/core/src/routes/session/index.ts @@ -2,7 +2,7 @@ import path from 'path'; import type { LogtoErrorCode } from '@logto/phrases'; import { UserRole } from '@logto/schemas'; -import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds/index.js'; +import { adminConsoleApplicationId } from '@logto/schemas'; import { conditional } from '@silverhand/essentials'; import type { Provider } from 'oidc-provider'; import { object, string } from 'zod'; diff --git a/packages/core/src/routes/session/middleware/koa-guard-session-action.ts b/packages/core/src/routes/session/middleware/koa-guard-session-action.ts index 2dfccfc54..9b71a1d88 100644 --- a/packages/core/src/routes/session/middleware/koa-guard-session-action.ts +++ b/packages/core/src/routes/session/middleware/koa-guard-session-action.ts @@ -1,5 +1,5 @@ import { SignInMode } from '@logto/schemas'; -import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds/index.js'; +import { adminConsoleApplicationId } from '@logto/schemas'; import type { MiddlewareType } from 'koa'; import type { Provider } from 'oidc-provider'; import { errors } from 'oidc-provider'; diff --git a/packages/core/src/routes/session/password.test.ts b/packages/core/src/routes/session/password.test.ts index 334d90fc0..71ff8e595 100644 --- a/packages/core/src/routes/session/password.test.ts +++ b/packages/core/src/routes/session/password.test.ts @@ -1,13 +1,14 @@ import type { User } from '@logto/schemas'; import { UserRole, SignInIdentifier } from '@logto/schemas'; -import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds/index.js'; +import { adminConsoleApplicationId } from '@logto/schemas'; import { Provider } from 'oidc-provider'; -import { mockSignInExperience, mockUser } from '#src/__mocks__/index.js'; import { createRequester } from '#src/utils/test-utils.js'; import passwordRoutes, { registerRoute, signInRoute } from './password.js'; +import { mockSignInExperience, mockUser } from '#src/__mocks__/index.js'; + const insertUser = jest.fn(async (..._args: unknown[]) => mockUser); const hasUser = jest.fn(async (username: string) => username === 'username1'); const findUserById = jest.fn(async (): Promise => mockUser); diff --git a/packages/core/src/routes/session/password.ts b/packages/core/src/routes/session/password.ts index 0ef8447f8..e464618ee 100644 --- a/packages/core/src/routes/session/password.ts +++ b/packages/core/src/routes/session/password.ts @@ -1,6 +1,6 @@ import { passwordRegEx, usernameRegEx } from '@logto/core-kit'; import { SignInIdentifier, UserRole } from '@logto/schemas'; -import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds/index.js'; +import { adminConsoleApplicationId } from '@logto/schemas'; import type { Provider } from 'oidc-provider'; import { object, string } from 'zod'; diff --git a/packages/core/src/routes/well-known.test.ts b/packages/core/src/routes/well-known.test.ts index 740f6115c..fe8340615 100644 --- a/packages/core/src/routes/well-known.test.ts +++ b/packages/core/src/routes/well-known.test.ts @@ -1,10 +1,10 @@ import { SignInMode } from '@logto/schemas'; -import { - adminConsoleApplicationId, - adminConsoleSignInExperience, -} from '@logto/schemas/lib/seeds/index.js'; +import { adminConsoleApplicationId, adminConsoleSignInExperience } from '@logto/schemas'; import { mockEsm, mockEsmWithActual, pickDefault } from '@logto/shared/esm'; +import { createMockProvider } from '#src/test-utils/oidc-provider.js'; +import { createRequester } from '#src/utils/test-utils.js'; + import { mockAliyunDmConnector, mockAliyunSmsConnector, @@ -15,8 +15,6 @@ import { mockWechatConnector, mockWechatNativeConnector, } from '#src/__mocks__/index.js'; -import { createMockProvider } from '#src/test-utils/oidc-provider.js'; -import { createRequester } from '#src/utils/test-utils.js'; const { jest } = import.meta; await mockEsmWithActual('i18next', () => ({ diff --git a/packages/core/src/routes/well-known.ts b/packages/core/src/routes/well-known.ts index 5a6c69035..b39b57b73 100644 --- a/packages/core/src/routes/well-known.ts +++ b/packages/core/src/routes/well-known.ts @@ -1,6 +1,6 @@ import type { ConnectorMetadata } from '@logto/connector-kit'; import { ConnectorType } from '@logto/connector-kit'; -import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds/index.js'; +import { adminConsoleApplicationId } from '@logto/schemas'; import etag from 'etag'; import type { Provider } from 'oidc-provider'; diff --git a/packages/demo-app/src/App.tsx b/packages/demo-app/src/App.tsx index b60944ac8..b794407ab 100644 --- a/packages/demo-app/src/App.tsx +++ b/packages/demo-app/src/App.tsx @@ -1,6 +1,6 @@ import type { IdTokenClaims } from '@logto/react'; import { LogtoProvider, useLogto, Prompt } from '@logto/react'; -import { demoAppApplicationId } from '@logto/schemas/lib/seeds'; +import { demoAppApplicationId } from '@logto/schemas'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; diff --git a/packages/integration-tests/src/client/index.ts b/packages/integration-tests/src/client/index.ts index 2af732f2c..585f6cc2c 100644 --- a/packages/integration-tests/src/client/index.ts +++ b/packages/integration-tests/src/client/index.ts @@ -1,6 +1,6 @@ import type { LogtoConfig } from '@logto/node'; import LogtoClient from '@logto/node'; -import { demoAppApplicationId } from '@logto/schemas/lib/seeds/index.js'; +import { demoAppApplicationId } from '@logto/schemas'; import type { Optional } from '@silverhand/essentials'; import { assert } from '@silverhand/essentials'; import { got } from 'got'; diff --git a/packages/integration-tests/src/constants.ts b/packages/integration-tests/src/constants.ts index 0d0b31222..141cbcef0 100644 --- a/packages/integration-tests/src/constants.ts +++ b/packages/integration-tests/src/constants.ts @@ -1,5 +1,4 @@ -import { SignInIdentifier } from '@logto/schemas'; -import { demoAppApplicationId } from '@logto/schemas/lib/seeds'; +import { SignInIdentifier, demoAppApplicationId } from '@logto/schemas'; import { assertEnv } from '@silverhand/essentials'; export const logtoUrl = assertEnv('INTEGRATION_TESTS_LOGTO_URL'); diff --git a/packages/integration-tests/src/tests/api/application.test.ts b/packages/integration-tests/src/tests/api/application.test.ts index a9aed13f6..89b8f4223 100644 --- a/packages/integration-tests/src/tests/api/application.test.ts +++ b/packages/integration-tests/src/tests/api/application.test.ts @@ -1,5 +1,5 @@ import { ApplicationType } from '@logto/schemas'; -import { demoAppApplicationId } from '@logto/schemas/lib/seeds'; +import { demoAppApplicationId } from '@logto/schemas'; import { HTTPError } from 'got'; import { diff --git a/packages/integration-tests/src/tests/api/get-access-token.test.ts b/packages/integration-tests/src/tests/api/get-access-token.test.ts index 38dd7ba7f..21adfb6b3 100644 --- a/packages/integration-tests/src/tests/api/get-access-token.test.ts +++ b/packages/integration-tests/src/tests/api/get-access-token.test.ts @@ -1,7 +1,7 @@ import path from 'path'; import { fetchTokenByRefreshToken } from '@logto/js'; -import { managementResource } from '@logto/schemas/lib/seeds'; +import { managementResource } from '@logto/schemas'; import { assert } from '@silverhand/essentials'; import fetch from 'node-fetch'; diff --git a/packages/integration-tests/src/tests/api/resource.test.ts b/packages/integration-tests/src/tests/api/resource.test.ts index 2391f8dfe..12744b33e 100644 --- a/packages/integration-tests/src/tests/api/resource.test.ts +++ b/packages/integration-tests/src/tests/api/resource.test.ts @@ -1,4 +1,4 @@ -import { managementResource } from '@logto/schemas/lib/seeds'; +import { managementResource } from '@logto/schemas'; import { HTTPError } from 'got'; import { createResource, getResource, updateResource, deleteResource } from '#src/api/index.js'; diff --git a/packages/integration-tests/src/tests/api/session.test.ts b/packages/integration-tests/src/tests/api/session.test.ts index 2b07e0eca..b9d722661 100644 --- a/packages/integration-tests/src/tests/api/session.test.ts +++ b/packages/integration-tests/src/tests/api/session.test.ts @@ -1,5 +1,5 @@ import { SignInIdentifier } from '@logto/schemas'; -import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds'; +import { adminConsoleApplicationId } from '@logto/schemas'; import { assert } from '@silverhand/essentials'; import { diff --git a/packages/integration-tests/src/tests/api/wellknown.test.ts b/packages/integration-tests/src/tests/api/wellknown.test.ts index 8001f303f..7661ec388 100644 --- a/packages/integration-tests/src/tests/api/wellknown.test.ts +++ b/packages/integration-tests/src/tests/api/wellknown.test.ts @@ -1,4 +1,4 @@ -import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds'; +import { adminConsoleApplicationId } from '@logto/schemas'; import { assert } from '@silverhand/essentials'; import { getWellKnownSignInExperience } from '#src/api/index.js'; diff --git a/packages/phrases/src/locales/de/errors.ts b/packages/phrases/src/locales/de/errors.ts index 58a86a380..aa071e1a0 100644 --- a/packages/phrases/src/locales/de/errors.ts +++ b/packages/phrases/src/locales/de/errors.ts @@ -1,6 +1,7 @@ const errors = { request: { invalid_input: 'Input is invalid. {{details}}', // UNTRANSLATED + general: 'Request error occurred.', // UNTRANSLATED }, auth: { authorization_header_missing: 'Autorisierungs-Header fehlt.', diff --git a/packages/phrases/src/locales/en/errors.ts b/packages/phrases/src/locales/en/errors.ts index 2d43ed811..05e73d0ed 100644 --- a/packages/phrases/src/locales/en/errors.ts +++ b/packages/phrases/src/locales/en/errors.ts @@ -1,6 +1,7 @@ const errors = { request: { invalid_input: 'Input is invalid. {{details}}', + general: 'Request error occurred.', }, auth: { authorization_header_missing: 'Authorization header is missing.', diff --git a/packages/phrases/src/locales/fr/errors.ts b/packages/phrases/src/locales/fr/errors.ts index 5ea209162..72b36d047 100644 --- a/packages/phrases/src/locales/fr/errors.ts +++ b/packages/phrases/src/locales/fr/errors.ts @@ -1,6 +1,7 @@ const errors = { request: { invalid_input: 'Input is invalid. {{details}}', // UNTRANSLATED + general: 'Request error occurred.', // UNTRANSLATED }, auth: { authorization_header_missing: "L'en-tête d'autorisation est manquant.", diff --git a/packages/phrases/src/locales/ko/errors.ts b/packages/phrases/src/locales/ko/errors.ts index b4cb1c7e9..9d8018d6e 100644 --- a/packages/phrases/src/locales/ko/errors.ts +++ b/packages/phrases/src/locales/ko/errors.ts @@ -1,6 +1,7 @@ const errors = { request: { invalid_input: 'Input is invalid. {{details}}', // UNTRANSLATED + general: 'Request error occurred.', // UNTRANSLATED }, auth: { authorization_header_missing: '인증 헤더가 존재하지 않아요.', diff --git a/packages/phrases/src/locales/pt-br/errors.ts b/packages/phrases/src/locales/pt-br/errors.ts index 49c7ed3c8..2d9770099 100644 --- a/packages/phrases/src/locales/pt-br/errors.ts +++ b/packages/phrases/src/locales/pt-br/errors.ts @@ -1,6 +1,7 @@ const errors = { request: { invalid_input: 'Input is invalid. {{details}}', // UNTRANSLATED + general: 'Request error occurred.', // UNTRANSLATED }, auth: { authorization_header_missing: 'O cabeçalho de autorização está ausente.', diff --git a/packages/phrases/src/locales/pt-pt/errors.ts b/packages/phrases/src/locales/pt-pt/errors.ts index 0217c40bd..838240d94 100644 --- a/packages/phrases/src/locales/pt-pt/errors.ts +++ b/packages/phrases/src/locales/pt-pt/errors.ts @@ -1,6 +1,7 @@ const errors = { request: { invalid_input: 'Input is invalid. {{details}}', // UNTRANSLATED + general: 'Request error occurred.', // UNTRANSLATED }, auth: { authorization_header_missing: 'O cabeçalho de autorização está ausente.', diff --git a/packages/phrases/src/locales/tr-tr/errors.ts b/packages/phrases/src/locales/tr-tr/errors.ts index 68e535920..7cbcfbf37 100644 --- a/packages/phrases/src/locales/tr-tr/errors.ts +++ b/packages/phrases/src/locales/tr-tr/errors.ts @@ -1,6 +1,7 @@ const errors = { request: { invalid_input: 'Input is invalid. {{details}}', // UNTRANSLATED + general: 'Request error occurred.', // UNTRANSLATED }, auth: { authorization_header_missing: 'Yetkilendirme başlığı eksik.', diff --git a/packages/phrases/src/locales/zh-cn/errors.ts b/packages/phrases/src/locales/zh-cn/errors.ts index c443693e7..f0685381d 100644 --- a/packages/phrases/src/locales/zh-cn/errors.ts +++ b/packages/phrases/src/locales/zh-cn/errors.ts @@ -1,6 +1,7 @@ const errors = { request: { invalid_input: 'Input is invalid. {{details}}', // UNTRANSLATED + general: 'Request error occurred.', // UNTRANSLATED }, auth: { authorization_header_missing: 'Authorization 请求头缺失。', diff --git a/packages/schemas/alterations/1.0.0_beta.10-1-logto-config.ts b/packages/schemas/alterations/1.0.0_beta.10-1-logto-config.ts index 644145283..2954857c0 100644 --- a/packages/schemas/alterations/1.0.0_beta.10-1-logto-config.ts +++ b/packages/schemas/alterations/1.0.0_beta.10-1-logto-config.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/types/alteration.js'; +import type { AlterationScript } from '../lib/src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/1.0.0_beta.10-1663923211-machine-to-machine-app.ts b/packages/schemas/alterations/1.0.0_beta.10-1663923211-machine-to-machine-app.ts index a8bb4d683..27f85ded3 100644 --- a/packages/schemas/alterations/1.0.0_beta.10-1663923211-machine-to-machine-app.ts +++ b/packages/schemas/alterations/1.0.0_beta.10-1663923211-machine-to-machine-app.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/types/alteration.js'; +import type { AlterationScript } from '../lib/src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/1.0.0_beta.10-1664265197-custom-phrases.ts b/packages/schemas/alterations/1.0.0_beta.10-1664265197-custom-phrases.ts index 5f496d401..cabc149c7 100644 --- a/packages/schemas/alterations/1.0.0_beta.10-1664265197-custom-phrases.ts +++ b/packages/schemas/alterations/1.0.0_beta.10-1664265197-custom-phrases.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/types/alteration.js'; +import type { AlterationScript } from '../lib/src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/1.0.0_beta.11-1664347703-rename-language-key-to-tag.ts b/packages/schemas/alterations/1.0.0_beta.11-1664347703-rename-language-key-to-tag.ts index b17b1567e..181a5e58c 100644 --- a/packages/schemas/alterations/1.0.0_beta.11-1664347703-rename-language-key-to-tag.ts +++ b/packages/schemas/alterations/1.0.0_beta.11-1664347703-rename-language-key-to-tag.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/types/alteration.js'; +import type { AlterationScript } from '../lib/src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/1.0.0_beta.11-1664356000-add-created-at-column-to-users.ts b/packages/schemas/alterations/1.0.0_beta.11-1664356000-add-created-at-column-to-users.ts index 1e708b9d6..502d4a454 100644 --- a/packages/schemas/alterations/1.0.0_beta.11-1664356000-add-created-at-column-to-users.ts +++ b/packages/schemas/alterations/1.0.0_beta.11-1664356000-add-created-at-column-to-users.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/types/alteration.js'; +import type { AlterationScript } from '../lib/src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/1.0.0_beta.11-1664462389-correct-user-created-at-column-by-user-logs.ts b/packages/schemas/alterations/1.0.0_beta.11-1664462389-correct-user-created-at-column-by-user-logs.ts index 9669dd100..239e7a611 100644 --- a/packages/schemas/alterations/1.0.0_beta.11-1664462389-correct-user-created-at-column-by-user-logs.ts +++ b/packages/schemas/alterations/1.0.0_beta.11-1664462389-correct-user-created-at-column-by-user-logs.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/types/alteration.js'; +import type { AlterationScript } from '../lib/src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/1.0.0_beta.14-1665300135-sign-in-sign-up.ts b/packages/schemas/alterations/1.0.0_beta.14-1665300135-sign-in-sign-up.ts index 08e172d8a..3df9087b2 100644 --- a/packages/schemas/alterations/1.0.0_beta.14-1665300135-sign-in-sign-up.ts +++ b/packages/schemas/alterations/1.0.0_beta.14-1665300135-sign-in-sign-up.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/types/alteration.js'; +import type { AlterationScript } from '../lib/src/types/alteration.js'; enum SignInMethodState { Primary = 'primary', diff --git a/packages/schemas/alterations/1.0.0_beta.14-1667283640-remove-forgot-password.ts b/packages/schemas/alterations/1.0.0_beta.14-1667283640-remove-forgot-password.ts index cfb0534de..e7ec2a582 100644 --- a/packages/schemas/alterations/1.0.0_beta.14-1667283640-remove-forgot-password.ts +++ b/packages/schemas/alterations/1.0.0_beta.14-1667283640-remove-forgot-password.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/types/alteration.js'; +import type { AlterationScript } from '../lib/src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/1.0.0_beta.14-1667292082-remove-sign-in-method.ts b/packages/schemas/alterations/1.0.0_beta.14-1667292082-remove-sign-in-method.ts index a939e32d4..857e27368 100644 --- a/packages/schemas/alterations/1.0.0_beta.14-1667292082-remove-sign-in-method.ts +++ b/packages/schemas/alterations/1.0.0_beta.14-1667292082-remove-sign-in-method.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/types/alteration.js'; +import type { AlterationScript } from '../lib/src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/1.0.0_beta.14-1667374974-user-suspend.ts b/packages/schemas/alterations/1.0.0_beta.14-1667374974-user-suspend.ts index d48f7f6cf..352a91937 100644 --- a/packages/schemas/alterations/1.0.0_beta.14-1667374974-user-suspend.ts +++ b/packages/schemas/alterations/1.0.0_beta.14-1667374974-user-suspend.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/types/alteration.js'; +import type { AlterationScript } from '../lib/src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/1.0.0_beta.14-1667900481-add-passcode-type-continue.ts b/packages/schemas/alterations/1.0.0_beta.14-1667900481-add-passcode-type-continue.ts index fa5923886..39a8cf579 100644 --- a/packages/schemas/alterations/1.0.0_beta.14-1667900481-add-passcode-type-continue.ts +++ b/packages/schemas/alterations/1.0.0_beta.14-1667900481-add-passcode-type-continue.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/types/alteration.js'; +import type { AlterationScript } from '../lib/src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/next-1668666590-support-multiple-connector-instances.ts b/packages/schemas/alterations/next-1668666590-support-multiple-connector-instances.ts index b2d9af7d0..a42ab126e 100644 --- a/packages/schemas/alterations/next-1668666590-support-multiple-connector-instances.ts +++ b/packages/schemas/alterations/next-1668666590-support-multiple-connector-instances.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/types/alteration.js'; +import type { AlterationScript } from '../lib/src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/next-1668666600-remove-connector-enabled.ts b/packages/schemas/alterations/next-1668666600-remove-connector-enabled.ts index aeceedcb0..ee68bfd06 100644 --- a/packages/schemas/alterations/next-1668666600-remove-connector-enabled.ts +++ b/packages/schemas/alterations/next-1668666600-remove-connector-enabled.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/types/alteration.js'; +import type { AlterationScript } from '../lib/src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/next-1669091623-roles-and-scopes.ts b/packages/schemas/alterations/next-1669091623-roles-and-scopes.ts index ba5cebd78..b976f48ca 100644 --- a/packages/schemas/alterations/next-1669091623-roles-and-scopes.ts +++ b/packages/schemas/alterations/next-1669091623-roles-and-scopes.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/types/alteration.js'; +import type { AlterationScript } from '../lib/src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/next-1669702299-sign-up.ts b/packages/schemas/alterations/next-1669702299-sign-up.ts index c5c6b8f80..4cd640c8f 100644 --- a/packages/schemas/alterations/next-1669702299-sign-up.ts +++ b/packages/schemas/alterations/next-1669702299-sign-up.ts @@ -2,7 +2,7 @@ import { isSameArray } from '@silverhand/essentials'; import type { DatabaseTransactionConnection } from 'slonik'; import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/types/alteration.js'; +import type { AlterationScript } from '../lib/src/types/alteration.js'; enum DeprecatedSignUpIdentifier { Email = 'email', diff --git a/packages/schemas/alterations/next-1671039448-add-user-name-index.ts b/packages/schemas/alterations/next-1671039448-add-user-name-index.ts index fb30bec7c..e3d940136 100644 --- a/packages/schemas/alterations/next-1671039448-add-user-name-index.ts +++ b/packages/schemas/alterations/next-1671039448-add-user-name-index.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/types/alteration.js'; +import type { AlterationScript } from '../lib/src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/next-1671080370-terms-of-use.ts b/packages/schemas/alterations/next-1671080370-terms-of-use.ts index 4f05d31f0..d70f4f6aa 100644 --- a/packages/schemas/alterations/next-1671080370-terms-of-use.ts +++ b/packages/schemas/alterations/next-1671080370-terms-of-use.ts @@ -1,7 +1,7 @@ import type { DatabaseTransactionConnection } from 'slonik'; import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/types/alteration.js'; +import type { AlterationScript } from '../lib/src/types/alteration.js'; type DeprecatedTermsOfUse = { enabled: boolean; diff --git a/packages/schemas/package.json b/packages/schemas/package.json index 51a7ad293..97f8184fd 100644 --- a/packages/schemas/package.json +++ b/packages/schemas/package.json @@ -1,7 +1,6 @@ { "name": "@logto/schemas", "version": "1.0.0-beta.16", - "main": "lib/index.js", "author": "Silverhand Inc. ", "license": "MPL-2.0", "type": "module", @@ -11,6 +10,13 @@ "alterations-js", "tables" ], + "main": "./lib/src/index.js", + "exports": { + ".": "./lib/src/index.js", + "./lib/*": "./lib/src/*", + "./models": "./lib/src-models/index.js", + "./package.json": "./package.json" + }, "publishConfig": { "access": "public" }, @@ -55,7 +61,9 @@ "rules": { "@typescript-eslint/ban-types": "off" }, - "ignorePatterns": ["src/db-entries/"], + "ignorePatterns": [ + "src/db-entries/" + ], "overrides": [ { "files": [ @@ -74,6 +82,8 @@ "@logto/language-kit": "workspace:*", "@logto/phrases": "workspace:*", "@logto/phrases-ui": "workspace:*", + "@withtyped/server": "^0.3.0", + "nanoid": "^4.0.0", "zod": "^3.20.2" } } diff --git a/packages/schemas/src/index.ts b/packages/schemas/src/index.ts index 23a82911b..3d4607c6a 100644 --- a/packages/schemas/src/index.ts +++ b/packages/schemas/src/index.ts @@ -2,4 +2,4 @@ export * from './foundations/index.js'; export * from './db-entries/index.js'; export * from './types/index.js'; export * from './api/index.js'; -export * as seeds from './seeds/index.js'; +export * from './seeds/index.js'; diff --git a/packages/schemas/tsconfig.build.json b/packages/schemas/tsconfig.build.json index 44d2d8165..abf537072 100644 --- a/packages/schemas/tsconfig.build.json +++ b/packages/schemas/tsconfig.build.json @@ -1,5 +1,5 @@ { "extends": "./tsconfig", - "include": ["src"], + "include": ["src", "src-models"], "exclude": ["src/gen"] } diff --git a/packages/schemas/tsconfig.json b/packages/schemas/tsconfig.json index 05e3acb09..c5fc7fd55 100644 --- a/packages/schemas/tsconfig.json +++ b/packages/schemas/tsconfig.json @@ -8,6 +8,7 @@ }, "include": [ "src", + "src-models", "alterations" ] } diff --git a/packages/shared/src/utils/id.ts b/packages/shared/src/utils/id.ts deleted file mode 100644 index ef06da84a..000000000 --- a/packages/shared/src/utils/id.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { customAlphabet } from 'nanoid'; - -export const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; - -export const buildIdGenerator = (size: number) => customAlphabet(alphabet, size); - -export const buildApplicationSecret = buildIdGenerator(21); diff --git a/packages/shared/src/utils/index.ts b/packages/shared/src/utils/index.ts index 8bfcfa7f3..99230af64 100644 --- a/packages/shared/src/utils/index.ts +++ b/packages/shared/src/utils/index.ts @@ -1,3 +1,2 @@ -export * from './id.js'; export * from './function.js'; export { default as findPackage } from './find-package.js'; diff --git a/packages/shared/src/utils/id.test.ts b/packages/toolkit/core-kit/src/utilities/id.test.ts similarity index 57% rename from packages/shared/src/utils/id.test.ts rename to packages/toolkit/core-kit/src/utilities/id.test.ts index b6cc4d532..be456a2be 100644 --- a/packages/shared/src/utils/id.test.ts +++ b/packages/toolkit/core-kit/src/utilities/id.test.ts @@ -1,4 +1,4 @@ -import { buildIdGenerator, alphabet } from './id.js'; +import { buildIdGenerator } from './id.js'; describe('id generator', () => { it('should match the input length', () => { @@ -12,12 +12,4 @@ describe('id generator', () => { expect(id_1).not.toEqual(id_2); }); - - it('should only contains provided alphabets', () => { - const id = buildIdGenerator(20)(); - - for (const char of id) { - expect(alphabet.includes(char)).toBeTruthy(); - } - }); }); diff --git a/packages/toolkit/core-kit/src/utilities/id.ts b/packages/toolkit/core-kit/src/utilities/id.ts new file mode 100644 index 000000000..bf1579bce --- /dev/null +++ b/packages/toolkit/core-kit/src/utilities/id.ts @@ -0,0 +1,6 @@ +import { customAlphabet } from 'nanoid'; + +const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; + +export const buildIdGenerator = (size: number) => customAlphabet(alphabet, size); +export const generateStandardId = buildIdGenerator(21); diff --git a/packages/toolkit/core-kit/src/utilities/index.ts b/packages/toolkit/core-kit/src/utilities/index.ts index 5cf8bede3..8166f7308 100644 --- a/packages/toolkit/core-kit/src/utilities/index.ts +++ b/packages/toolkit/core-kit/src/utilities/index.ts @@ -1,4 +1,4 @@ export * from './color.js'; -export * from './string.js'; +export * from './id.js'; export * from './zod.js'; export * from './url.js'; diff --git a/packages/toolkit/core-kit/src/utilities/string.test.ts b/packages/toolkit/core-kit/src/utilities/string.test.ts deleted file mode 100644 index f084cf9ab..000000000 --- a/packages/toolkit/core-kit/src/utilities/string.test.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { generateRandomString } from './string.js'; - -describe('generateRandomString', () => { - it('should return a random string with specified length', () => { - const randomString = generateRandomString(32); - expect(randomString).toHaveLength(32); - }); - - it('should contain only 0-9, A-Z and a-z by default', () => { - const randomString = generateRandomString(32); - expect(() => { - /[\dA-Za-z]/.test(randomString); - }).toBeTruthy(); - }); -}); diff --git a/packages/toolkit/core-kit/src/utilities/string.ts b/packages/toolkit/core-kit/src/utilities/string.ts deleted file mode 100644 index 7c0a83ae9..000000000 --- a/packages/toolkit/core-kit/src/utilities/string.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { customAlphabet } from 'nanoid'; - -export const generateRandomString = ( - size: number, - alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' -): string => customAlphabet(alphabet, size)(); From 0f2548e0c4dbd5849848da6fcb6873e0b6571039 Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Tue, 20 Dec 2022 10:25:47 +0800 Subject: [PATCH 2/2] refactor: fix build errors --- .../console/src/components/AuditLogTable/index.tsx | 2 +- packages/console/src/pages/AuditLogDetails/index.tsx | 2 +- packages/core/src/include.d/import-meta.d.ts | 10 ++++++++++ .../core/src/libraries/sign-in-experience/index.ts | 4 +++- packages/core/src/middleware/koa-auth.ts | 3 +-- packages/core/src/oidc/adapter.ts | 3 +-- packages/core/src/routes/application.test.ts | 7 ++++--- packages/core/src/routes/phrase.test.ts | 3 +-- packages/core/src/routes/resource.test.ts | 3 ++- packages/core/src/routes/session/index.test.ts | 3 +-- packages/core/src/routes/session/index.ts | 3 +-- .../session/middleware/koa-guard-session-action.ts | 3 +-- packages/core/src/routes/session/password.test.ts | 6 ++---- packages/core/src/routes/session/password.ts | 3 +-- packages/core/src/routes/well-known.test.ts | 12 +++++++----- .../src/tests/api/application.test.ts | 3 +-- .../integration-tests/src/tests/api/session.test.ts | 3 +-- .../alterations/1.0.0_beta.10-1-logto-config.ts | 2 +- ....0.0_beta.10-1663923211-machine-to-machine-app.ts | 2 +- .../1.0.0_beta.10-1664265197-custom-phrases.ts | 2 +- ..._beta.11-1664347703-rename-language-key-to-tag.ts | 2 +- ...a.11-1664356000-add-created-at-column-to-users.ts | 2 +- ...89-correct-user-created-at-column-by-user-logs.ts | 2 +- .../1.0.0_beta.14-1665300135-sign-in-sign-up.ts | 2 +- ....0.0_beta.14-1667283640-remove-forgot-password.ts | 2 +- ...1.0.0_beta.14-1667292082-remove-sign-in-method.ts | 2 +- .../1.0.0_beta.14-1667374974-user-suspend.ts | 2 +- ..._beta.14-1667900481-add-passcode-type-continue.ts | 2 +- ...668666590-support-multiple-connector-instances.ts | 2 +- .../next-1668666600-remove-connector-enabled.ts | 2 +- .../alterations/next-1669091623-roles-and-scopes.ts | 2 +- .../schemas/alterations/next-1669702299-sign-up.ts | 2 +- .../next-1671039448-add-user-name-index.ts | 2 +- .../alterations/next-1671080370-terms-of-use.ts | 2 +- packages/schemas/package.json | 10 ++++------ packages/schemas/tsconfig.json | 1 - packages/toolkit/core-kit/package.json | 2 +- pnpm-lock.yaml | 4 +++- 38 files changed, 64 insertions(+), 60 deletions(-) create mode 100644 packages/core/src/include.d/import-meta.d.ts diff --git a/packages/console/src/components/AuditLogTable/index.tsx b/packages/console/src/components/AuditLogTable/index.tsx index ffe94e2a4..1c97cebd2 100644 --- a/packages/console/src/components/AuditLogTable/index.tsx +++ b/packages/console/src/components/AuditLogTable/index.tsx @@ -1,5 +1,5 @@ import { LogResult } from '@logto/schemas'; -import type { LogDto } from '@logto/schemas/lib/types/log-legacy.js'; +import type { LogDto } from '@logto/schemas/lib/types/log-legacy'; import { conditional, conditionalString } from '@silverhand/essentials'; import classNames from 'classnames'; import { useTranslation } from 'react-i18next'; diff --git a/packages/console/src/pages/AuditLogDetails/index.tsx b/packages/console/src/pages/AuditLogDetails/index.tsx index de82e18d2..87a6f9e5c 100644 --- a/packages/console/src/pages/AuditLogDetails/index.tsx +++ b/packages/console/src/pages/AuditLogDetails/index.tsx @@ -1,5 +1,5 @@ import type { User } from '@logto/schemas'; -import type { LogDto } from '@logto/schemas/lib/types/log-legacy.js'; +import type { LogDto } from '@logto/schemas/lib/types/log-legacy'; import classNames from 'classnames'; import { useTranslation } from 'react-i18next'; import { useLocation, useParams } from 'react-router-dom'; diff --git a/packages/core/src/include.d/import-meta.d.ts b/packages/core/src/include.d/import-meta.d.ts new file mode 100644 index 000000000..e016debb5 --- /dev/null +++ b/packages/core/src/include.d/import-meta.d.ts @@ -0,0 +1,10 @@ +interface ImportMeta { + jest: typeof jest & { + // Almost same as `jest.mock()`, but factory is required + unstable_mockModule: ( + moduleName: string, + factory: () => T, + options?: jest.MockOptions + ) => typeof jest; + }; +} diff --git a/packages/core/src/libraries/sign-in-experience/index.ts b/packages/core/src/libraries/sign-in-experience/index.ts index b1ad9de86..e73b35c57 100644 --- a/packages/core/src/libraries/sign-in-experience/index.ts +++ b/packages/core/src/libraries/sign-in-experience/index.ts @@ -1,7 +1,9 @@ import { builtInLanguages } from '@logto/phrases-ui'; import type { Branding, LanguageInfo, SignInExperience } from '@logto/schemas'; -import { SignInMode, ConnectorType, BrandingStyle } from '@logto/schemas'; import { + SignInMode, + ConnectorType, + BrandingStyle, adminConsoleApplicationId, adminConsoleSignInExperience, demoAppApplicationId, diff --git a/packages/core/src/middleware/koa-auth.ts b/packages/core/src/middleware/koa-auth.ts index a3d806875..692c7b699 100644 --- a/packages/core/src/middleware/koa-auth.ts +++ b/packages/core/src/middleware/koa-auth.ts @@ -1,7 +1,6 @@ import type { IncomingHttpHeaders } from 'http'; -import { UserRole } from '@logto/schemas'; -import { managementResource } from '@logto/schemas'; +import { UserRole, managementResource } from '@logto/schemas'; import type { Optional } from '@silverhand/essentials'; import { conditional } from '@silverhand/essentials'; import { jwtVerify } from 'jose'; diff --git a/packages/core/src/oidc/adapter.ts b/packages/core/src/oidc/adapter.ts index ecbb598ce..e7198468c 100644 --- a/packages/core/src/oidc/adapter.ts +++ b/packages/core/src/oidc/adapter.ts @@ -1,6 +1,5 @@ import type { CreateApplication, OidcClientMetadata } from '@logto/schemas'; -import { ApplicationType } from '@logto/schemas'; -import { adminConsoleApplicationId, demoAppApplicationId } from '@logto/schemas'; +import { ApplicationType, adminConsoleApplicationId, demoAppApplicationId } from '@logto/schemas'; import { tryThat } from '@logto/shared'; import { deduplicate } from '@silverhand/essentials'; import { addSeconds } from 'date-fns'; diff --git a/packages/core/src/routes/application.test.ts b/packages/core/src/routes/application.test.ts index 0330deb10..c4303137c 100644 --- a/packages/core/src/routes/application.test.ts +++ b/packages/core/src/routes/application.test.ts @@ -29,10 +29,11 @@ const { findApplicationById } = mockEsm('#src/queries/application.js', () => ({ ), })); -mockEsm('@logto/core-kit', () => ({ +// Cannot use `mockEsm()` here, pending investigation. +jest.unstable_mockModule('@logto/core-kit', () => ({ // eslint-disable-next-line unicorn/consistent-function-scoping - buildIdGenerator: jest.fn(() => () => 'randomId'), - generateStandardId: jest.fn(() => 'randomId'), + buildIdGenerator: () => () => 'randomId', + generateStandardId: () => 'randomId', })); const { createRequester } = await import('#src/utils/test-utils.js'); diff --git a/packages/core/src/routes/phrase.test.ts b/packages/core/src/routes/phrase.test.ts index 0bbdcb77e..a8acf47aa 100644 --- a/packages/core/src/routes/phrase.test.ts +++ b/packages/core/src/routes/phrase.test.ts @@ -3,10 +3,9 @@ import type { SignInExperience } from '@logto/schemas'; import { adminConsoleApplicationId, adminConsoleSignInExperience } from '@logto/schemas'; import { mockEsm, mockEsmWithActual, pickDefault } from '@logto/shared/esm'; -import { createMockProvider } from '#src/test-utils/oidc-provider.js'; - import { zhCnTag } from '#src/__mocks__/custom-phrase.js'; import { mockSignInExperience } from '#src/__mocks__/index.js'; +import { createMockProvider } from '#src/test-utils/oidc-provider.js'; const { jest } = import.meta; diff --git a/packages/core/src/routes/resource.test.ts b/packages/core/src/routes/resource.test.ts index 03da2cd92..e3856505f 100644 --- a/packages/core/src/routes/resource.test.ts +++ b/packages/core/src/routes/resource.test.ts @@ -21,7 +21,8 @@ mockEsm('#src/queries/resource.js', () => ({ deleteResourceById: jest.fn(), })); -mockEsm('@logto/shared', () => ({ +// Cannot use `mockEsm()` here, pending investigation. +jest.unstable_mockModule('@logto/core-kit', () => ({ // eslint-disable-next-line unicorn/consistent-function-scoping buildIdGenerator: () => () => 'randomId', })); diff --git a/packages/core/src/routes/session/index.test.ts b/packages/core/src/routes/session/index.test.ts index 7a81fdd89..8d243fdc1 100644 --- a/packages/core/src/routes/session/index.test.ts +++ b/packages/core/src/routes/session/index.test.ts @@ -2,12 +2,11 @@ import type { User } from '@logto/schemas'; import { adminConsoleApplicationId } from '@logto/schemas'; import { Provider } from 'oidc-provider'; +import { mockUser } from '#src/__mocks__/index.js'; import { createRequester } from '#src/utils/test-utils.js'; import sessionRoutes from './index.js'; -import { mockUser } from '#src/__mocks__/index.js'; - const findUserById = jest.fn(async (): Promise => mockUser); const updateUserById = jest.fn(async (..._args: unknown[]) => ({ id: 'id' })); diff --git a/packages/core/src/routes/session/index.ts b/packages/core/src/routes/session/index.ts index 95f6c3f71..a85cc5e3f 100644 --- a/packages/core/src/routes/session/index.ts +++ b/packages/core/src/routes/session/index.ts @@ -1,8 +1,7 @@ import path from 'path'; import type { LogtoErrorCode } from '@logto/phrases'; -import { UserRole } from '@logto/schemas'; -import { adminConsoleApplicationId } from '@logto/schemas'; +import { UserRole, adminConsoleApplicationId } from '@logto/schemas'; import { conditional } from '@silverhand/essentials'; import type { Provider } from 'oidc-provider'; import { object, string } from 'zod'; diff --git a/packages/core/src/routes/session/middleware/koa-guard-session-action.ts b/packages/core/src/routes/session/middleware/koa-guard-session-action.ts index 9b71a1d88..17e8331a4 100644 --- a/packages/core/src/routes/session/middleware/koa-guard-session-action.ts +++ b/packages/core/src/routes/session/middleware/koa-guard-session-action.ts @@ -1,5 +1,4 @@ -import { SignInMode } from '@logto/schemas'; -import { adminConsoleApplicationId } from '@logto/schemas'; +import { SignInMode, adminConsoleApplicationId } from '@logto/schemas'; import type { MiddlewareType } from 'koa'; import type { Provider } from 'oidc-provider'; import { errors } from 'oidc-provider'; diff --git a/packages/core/src/routes/session/password.test.ts b/packages/core/src/routes/session/password.test.ts index 71ff8e595..ba7f7a755 100644 --- a/packages/core/src/routes/session/password.test.ts +++ b/packages/core/src/routes/session/password.test.ts @@ -1,14 +1,12 @@ import type { User } from '@logto/schemas'; -import { UserRole, SignInIdentifier } from '@logto/schemas'; -import { adminConsoleApplicationId } from '@logto/schemas'; +import { UserRole, SignInIdentifier, adminConsoleApplicationId } from '@logto/schemas'; import { Provider } from 'oidc-provider'; +import { mockSignInExperience, mockUser } from '#src/__mocks__/index.js'; import { createRequester } from '#src/utils/test-utils.js'; import passwordRoutes, { registerRoute, signInRoute } from './password.js'; -import { mockSignInExperience, mockUser } from '#src/__mocks__/index.js'; - const insertUser = jest.fn(async (..._args: unknown[]) => mockUser); const hasUser = jest.fn(async (username: string) => username === 'username1'); const findUserById = jest.fn(async (): Promise => mockUser); diff --git a/packages/core/src/routes/session/password.ts b/packages/core/src/routes/session/password.ts index e464618ee..94189f1a1 100644 --- a/packages/core/src/routes/session/password.ts +++ b/packages/core/src/routes/session/password.ts @@ -1,6 +1,5 @@ import { passwordRegEx, usernameRegEx } from '@logto/core-kit'; -import { SignInIdentifier, UserRole } from '@logto/schemas'; -import { adminConsoleApplicationId } from '@logto/schemas'; +import { SignInIdentifier, UserRole, adminConsoleApplicationId } from '@logto/schemas'; import type { Provider } from 'oidc-provider'; import { object, string } from 'zod'; diff --git a/packages/core/src/routes/well-known.test.ts b/packages/core/src/routes/well-known.test.ts index fe8340615..44e54375a 100644 --- a/packages/core/src/routes/well-known.test.ts +++ b/packages/core/src/routes/well-known.test.ts @@ -1,10 +1,10 @@ -import { SignInMode } from '@logto/schemas'; -import { adminConsoleApplicationId, adminConsoleSignInExperience } from '@logto/schemas'; +import { + SignInMode, + adminConsoleApplicationId, + adminConsoleSignInExperience, +} from '@logto/schemas'; import { mockEsm, mockEsmWithActual, pickDefault } from '@logto/shared/esm'; -import { createMockProvider } from '#src/test-utils/oidc-provider.js'; -import { createRequester } from '#src/utils/test-utils.js'; - import { mockAliyunDmConnector, mockAliyunSmsConnector, @@ -15,6 +15,8 @@ import { mockWechatConnector, mockWechatNativeConnector, } from '#src/__mocks__/index.js'; +import { createMockProvider } from '#src/test-utils/oidc-provider.js'; +import { createRequester } from '#src/utils/test-utils.js'; const { jest } = import.meta; await mockEsmWithActual('i18next', () => ({ diff --git a/packages/integration-tests/src/tests/api/application.test.ts b/packages/integration-tests/src/tests/api/application.test.ts index 89b8f4223..3d2b5d979 100644 --- a/packages/integration-tests/src/tests/api/application.test.ts +++ b/packages/integration-tests/src/tests/api/application.test.ts @@ -1,5 +1,4 @@ -import { ApplicationType } from '@logto/schemas'; -import { demoAppApplicationId } from '@logto/schemas'; +import { ApplicationType, demoAppApplicationId } from '@logto/schemas'; import { HTTPError } from 'got'; import { diff --git a/packages/integration-tests/src/tests/api/session.test.ts b/packages/integration-tests/src/tests/api/session.test.ts index b9d722661..b7cf82824 100644 --- a/packages/integration-tests/src/tests/api/session.test.ts +++ b/packages/integration-tests/src/tests/api/session.test.ts @@ -1,5 +1,4 @@ -import { SignInIdentifier } from '@logto/schemas'; -import { adminConsoleApplicationId } from '@logto/schemas'; +import { SignInIdentifier, adminConsoleApplicationId } from '@logto/schemas'; import { assert } from '@silverhand/essentials'; import { diff --git a/packages/schemas/alterations/1.0.0_beta.10-1-logto-config.ts b/packages/schemas/alterations/1.0.0_beta.10-1-logto-config.ts index 2954857c0..eb7dbb6c5 100644 --- a/packages/schemas/alterations/1.0.0_beta.10-1-logto-config.ts +++ b/packages/schemas/alterations/1.0.0_beta.10-1-logto-config.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/src/types/alteration.js'; +import type { AlterationScript } from '../src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/1.0.0_beta.10-1663923211-machine-to-machine-app.ts b/packages/schemas/alterations/1.0.0_beta.10-1663923211-machine-to-machine-app.ts index 27f85ded3..7a0146b0f 100644 --- a/packages/schemas/alterations/1.0.0_beta.10-1663923211-machine-to-machine-app.ts +++ b/packages/schemas/alterations/1.0.0_beta.10-1663923211-machine-to-machine-app.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/src/types/alteration.js'; +import type { AlterationScript } from '../src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/1.0.0_beta.10-1664265197-custom-phrases.ts b/packages/schemas/alterations/1.0.0_beta.10-1664265197-custom-phrases.ts index cabc149c7..65c7c8005 100644 --- a/packages/schemas/alterations/1.0.0_beta.10-1664265197-custom-phrases.ts +++ b/packages/schemas/alterations/1.0.0_beta.10-1664265197-custom-phrases.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/src/types/alteration.js'; +import type { AlterationScript } from '../src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/1.0.0_beta.11-1664347703-rename-language-key-to-tag.ts b/packages/schemas/alterations/1.0.0_beta.11-1664347703-rename-language-key-to-tag.ts index 181a5e58c..2463cb407 100644 --- a/packages/schemas/alterations/1.0.0_beta.11-1664347703-rename-language-key-to-tag.ts +++ b/packages/schemas/alterations/1.0.0_beta.11-1664347703-rename-language-key-to-tag.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/src/types/alteration.js'; +import type { AlterationScript } from '../src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/1.0.0_beta.11-1664356000-add-created-at-column-to-users.ts b/packages/schemas/alterations/1.0.0_beta.11-1664356000-add-created-at-column-to-users.ts index 502d4a454..02cf4dafb 100644 --- a/packages/schemas/alterations/1.0.0_beta.11-1664356000-add-created-at-column-to-users.ts +++ b/packages/schemas/alterations/1.0.0_beta.11-1664356000-add-created-at-column-to-users.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/src/types/alteration.js'; +import type { AlterationScript } from '../src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/1.0.0_beta.11-1664462389-correct-user-created-at-column-by-user-logs.ts b/packages/schemas/alterations/1.0.0_beta.11-1664462389-correct-user-created-at-column-by-user-logs.ts index 239e7a611..a6b3479e3 100644 --- a/packages/schemas/alterations/1.0.0_beta.11-1664462389-correct-user-created-at-column-by-user-logs.ts +++ b/packages/schemas/alterations/1.0.0_beta.11-1664462389-correct-user-created-at-column-by-user-logs.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/src/types/alteration.js'; +import type { AlterationScript } from '../src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/1.0.0_beta.14-1665300135-sign-in-sign-up.ts b/packages/schemas/alterations/1.0.0_beta.14-1665300135-sign-in-sign-up.ts index 3df9087b2..3460ca40e 100644 --- a/packages/schemas/alterations/1.0.0_beta.14-1665300135-sign-in-sign-up.ts +++ b/packages/schemas/alterations/1.0.0_beta.14-1665300135-sign-in-sign-up.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/src/types/alteration.js'; +import type { AlterationScript } from '../src/types/alteration.js'; enum SignInMethodState { Primary = 'primary', diff --git a/packages/schemas/alterations/1.0.0_beta.14-1667283640-remove-forgot-password.ts b/packages/schemas/alterations/1.0.0_beta.14-1667283640-remove-forgot-password.ts index e7ec2a582..63466b2bb 100644 --- a/packages/schemas/alterations/1.0.0_beta.14-1667283640-remove-forgot-password.ts +++ b/packages/schemas/alterations/1.0.0_beta.14-1667283640-remove-forgot-password.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/src/types/alteration.js'; +import type { AlterationScript } from '../src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/1.0.0_beta.14-1667292082-remove-sign-in-method.ts b/packages/schemas/alterations/1.0.0_beta.14-1667292082-remove-sign-in-method.ts index 857e27368..25d747401 100644 --- a/packages/schemas/alterations/1.0.0_beta.14-1667292082-remove-sign-in-method.ts +++ b/packages/schemas/alterations/1.0.0_beta.14-1667292082-remove-sign-in-method.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/src/types/alteration.js'; +import type { AlterationScript } from '../src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/1.0.0_beta.14-1667374974-user-suspend.ts b/packages/schemas/alterations/1.0.0_beta.14-1667374974-user-suspend.ts index 352a91937..71d51e83b 100644 --- a/packages/schemas/alterations/1.0.0_beta.14-1667374974-user-suspend.ts +++ b/packages/schemas/alterations/1.0.0_beta.14-1667374974-user-suspend.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/src/types/alteration.js'; +import type { AlterationScript } from '../src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/1.0.0_beta.14-1667900481-add-passcode-type-continue.ts b/packages/schemas/alterations/1.0.0_beta.14-1667900481-add-passcode-type-continue.ts index 39a8cf579..553633db7 100644 --- a/packages/schemas/alterations/1.0.0_beta.14-1667900481-add-passcode-type-continue.ts +++ b/packages/schemas/alterations/1.0.0_beta.14-1667900481-add-passcode-type-continue.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/src/types/alteration.js'; +import type { AlterationScript } from '../src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/next-1668666590-support-multiple-connector-instances.ts b/packages/schemas/alterations/next-1668666590-support-multiple-connector-instances.ts index a42ab126e..81a9c6a4b 100644 --- a/packages/schemas/alterations/next-1668666590-support-multiple-connector-instances.ts +++ b/packages/schemas/alterations/next-1668666590-support-multiple-connector-instances.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/src/types/alteration.js'; +import type { AlterationScript } from '../src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/next-1668666600-remove-connector-enabled.ts b/packages/schemas/alterations/next-1668666600-remove-connector-enabled.ts index ee68bfd06..0621df559 100644 --- a/packages/schemas/alterations/next-1668666600-remove-connector-enabled.ts +++ b/packages/schemas/alterations/next-1668666600-remove-connector-enabled.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/src/types/alteration.js'; +import type { AlterationScript } from '../src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/next-1669091623-roles-and-scopes.ts b/packages/schemas/alterations/next-1669091623-roles-and-scopes.ts index b976f48ca..9b3e51949 100644 --- a/packages/schemas/alterations/next-1669091623-roles-and-scopes.ts +++ b/packages/schemas/alterations/next-1669091623-roles-and-scopes.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/src/types/alteration.js'; +import type { AlterationScript } from '../src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/next-1669702299-sign-up.ts b/packages/schemas/alterations/next-1669702299-sign-up.ts index 4cd640c8f..0e0bfc521 100644 --- a/packages/schemas/alterations/next-1669702299-sign-up.ts +++ b/packages/schemas/alterations/next-1669702299-sign-up.ts @@ -2,7 +2,7 @@ import { isSameArray } from '@silverhand/essentials'; import type { DatabaseTransactionConnection } from 'slonik'; import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/src/types/alteration.js'; +import type { AlterationScript } from '../src/types/alteration.js'; enum DeprecatedSignUpIdentifier { Email = 'email', diff --git a/packages/schemas/alterations/next-1671039448-add-user-name-index.ts b/packages/schemas/alterations/next-1671039448-add-user-name-index.ts index e3d940136..3b79ae2c3 100644 --- a/packages/schemas/alterations/next-1671039448-add-user-name-index.ts +++ b/packages/schemas/alterations/next-1671039448-add-user-name-index.ts @@ -1,6 +1,6 @@ import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/src/types/alteration.js'; +import type { AlterationScript } from '../src/types/alteration.js'; const alteration: AlterationScript = { up: async (pool) => { diff --git a/packages/schemas/alterations/next-1671080370-terms-of-use.ts b/packages/schemas/alterations/next-1671080370-terms-of-use.ts index d70f4f6aa..bf22791bf 100644 --- a/packages/schemas/alterations/next-1671080370-terms-of-use.ts +++ b/packages/schemas/alterations/next-1671080370-terms-of-use.ts @@ -1,7 +1,7 @@ import type { DatabaseTransactionConnection } from 'slonik'; import { sql } from 'slonik'; -import type { AlterationScript } from '../lib/src/types/alteration.js'; +import type { AlterationScript } from '../src/types/alteration.js'; type DeprecatedTermsOfUse = { enabled: boolean; diff --git a/packages/schemas/package.json b/packages/schemas/package.json index 97f8184fd..5f158ba0b 100644 --- a/packages/schemas/package.json +++ b/packages/schemas/package.json @@ -10,11 +10,11 @@ "alterations-js", "tables" ], - "main": "./lib/src/index.js", + "main": "./lib/index.js", "exports": { - ".": "./lib/src/index.js", - "./lib/*": "./lib/src/*", - "./models": "./lib/src-models/index.js", + ".": "./lib/index.js", + "./lib/*": "./lib/*", + "./models": "./lib/models/index.js", "./package.json": "./package.json" }, "publishConfig": { @@ -82,8 +82,6 @@ "@logto/language-kit": "workspace:*", "@logto/phrases": "workspace:*", "@logto/phrases-ui": "workspace:*", - "@withtyped/server": "^0.3.0", - "nanoid": "^4.0.0", "zod": "^3.20.2" } } diff --git a/packages/schemas/tsconfig.json b/packages/schemas/tsconfig.json index c5fc7fd55..05e3acb09 100644 --- a/packages/schemas/tsconfig.json +++ b/packages/schemas/tsconfig.json @@ -8,7 +8,6 @@ }, "include": [ "src", - "src-models", "alterations" ] } diff --git a/packages/toolkit/core-kit/package.json b/packages/toolkit/core-kit/package.json index 55d2cd655..86a5d5b79 100644 --- a/packages/toolkit/core-kit/package.json +++ b/packages/toolkit/core-kit/package.json @@ -39,7 +39,7 @@ "node": "^16.13.0 || ^18.12.0" }, "dependencies": { - "@logto/language-kit": "^1.0.0-beta.29", + "@logto/language-kit": "workspace:*", "color": "^4.2.3", "nanoid": "^4.0.0" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 82b35f9eb..b9ddc5d6e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,6 +23,7 @@ importers: packages/cli: specifiers: + '@logto/core-kit': workspace:* '@logto/schemas': workspace:* '@logto/shared': workspace:* '@silverhand/eslint-config': 1.3.0 @@ -62,6 +63,7 @@ importers: yargs: ^17.6.0 zod: ^3.20.2 dependencies: + '@logto/core-kit': link:../toolkit/core-kit '@logto/schemas': link:../schemas '@logto/shared': link:../shared '@silverhand/essentials': 1.3.0 @@ -682,7 +684,7 @@ importers: packages/toolkit/core-kit: specifiers: '@jest/types': ^29.0.3 - '@logto/language-kit': ^1.0.0-beta.29 + '@logto/language-kit': workspace:* '@rollup/plugin-typescript': ^10.0.1 '@silverhand/eslint-config': 1.3.0 '@silverhand/eslint-config-react': 1.3.0