diff --git a/packages/app-insights/package.json b/packages/app-insights/package.json index 42362ee99..0ded6ca6e 100644 --- a/packages/app-insights/package.json +++ b/packages/app-insights/package.json @@ -14,6 +14,10 @@ "types": "./lib/*.d.ts" } }, + "//": "This field is for parcel. Remove after https://github.com/parcel-bundler/parcel/pull/8807 published.", + "alias": { + "./react": "./lib/react.js" + }, "publishConfig": { "access": "public" }, diff --git a/packages/cli/src/commands/database/seed/tenant.ts b/packages/cli/src/commands/database/seed/tenant.ts index 676b999f7..6e8e653c2 100644 --- a/packages/cli/src/commands/database/seed/tenant.ts +++ b/packages/cli/src/commands/database/seed/tenant.ts @@ -1,4 +1,4 @@ -import { generateStandardId } from '@logto/core-kit'; +import { createTenantMetadata } from '@logto/core-kit'; import type { TenantModel, AdminData, @@ -6,7 +6,7 @@ import type { CreateScope, CreateRolesScope, } from '@logto/schemas'; -import { createTenantMetadata } from '@logto/shared'; +import { generateStandardId } from '@logto/shared'; import { assert } from '@silverhand/essentials'; import type { CommonQueryMethods } from 'slonik'; import { sql } from 'slonik'; diff --git a/packages/cli/src/commands/database/utils.ts b/packages/cli/src/commands/database/utils.ts index 180d88eff..7e4be383a 100644 --- a/packages/cli/src/commands/database/utils.ts +++ b/packages/cli/src/commands/database/utils.ts @@ -1,7 +1,7 @@ import { generateKeyPair } from 'node:crypto'; import { promisify } from 'node:util'; -import { generateStandardId } from '@logto/core-kit'; +import { generateStandardId } from '@logto/shared'; export const generateOidcPrivateKey = async (type: 'rsa' | 'ec' = 'ec') => { if (type === 'rsa') { diff --git a/packages/cloud/src/libraries/services.ts b/packages/cloud/src/libraries/services.ts index 9ae5a8444..35965cc2c 100644 --- a/packages/cloud/src/libraries/services.ts +++ b/packages/cloud/src/libraries/services.ts @@ -7,9 +7,9 @@ import type { SmsConnector, } from '@logto/connector-kit'; import { validateConfig } from '@logto/connector-kit'; -import { generateStandardId } from '@logto/core-kit'; import type { ServiceLogType } from '@logto/schemas'; import { adminTenantId } from '@logto/schemas'; +import { generateStandardId } from '@logto/shared'; import { trySafe } from '@silverhand/essentials'; import { RequestError } from '@withtyped/server'; diff --git a/packages/cloud/src/libraries/tenants.ts b/packages/cloud/src/libraries/tenants.ts index 0c57e835b..f04be5fda 100644 --- a/packages/cloud/src/libraries/tenants.ts +++ b/packages/cloud/src/libraries/tenants.ts @@ -2,7 +2,8 @@ import { generateOidcCookieKey, generateOidcPrivateKey, } from '@logto/cli/lib/commands/database/utils.js'; -import { generateStandardId } from '@logto/core-kit'; +import { DemoConnector } from '@logto/connector-kit'; +import { createTenantMetadata } from '@logto/core-kit'; import type { LogtoOidcConfigType, TenantInfo, TenantModel } from '@logto/schemas'; import { createAdminTenantApplicationRole, @@ -17,7 +18,7 @@ import { createAdminData, createAdminDataInAdminTenant, } from '@logto/schemas'; -import { createTenantMetadata, DemoConnector } from '@logto/shared'; +import { generateStandardId } from '@logto/shared'; import { appendPath } from '@silverhand/essentials'; import type { ZodType } from 'zod'; import { z } from 'zod'; diff --git a/packages/cloud/src/queries/tenants.ts b/packages/cloud/src/queries/tenants.ts index 4612cbe95..1af2fe8e6 100644 --- a/packages/cloud/src/queries/tenants.ts +++ b/packages/cloud/src/queries/tenants.ts @@ -1,6 +1,5 @@ import assert from 'node:assert'; -import { generateStandardId } from '@logto/core-kit'; import { adminConsoleApplicationId, adminTenantId, @@ -8,6 +7,7 @@ import { PredefinedScope, } from '@logto/schemas'; import type { AdminData, TenantModel, CreateRolesScope } from '@logto/schemas'; +import { generateStandardId } from '@logto/shared'; import type { PostgreSql } from '@withtyped/postgres'; import { jsonb, dangerousRaw, id, sql } from '@withtyped/postgres'; import type { Queryable } from '@withtyped/server'; diff --git a/packages/cloud/src/utils/connector/seed.ts b/packages/cloud/src/utils/connector/seed.ts index 8f852ae2c..1ec28eb64 100644 --- a/packages/cloud/src/utils/connector/seed.ts +++ b/packages/cloud/src/utils/connector/seed.ts @@ -1,6 +1,5 @@ -import { generateStandardId } from '@logto/core-kit'; import { cloudApiIndicator } from '@logto/schemas'; -import { GlobalValues } from '@logto/shared'; +import { generateStandardId, GlobalValues } from '@logto/shared'; import { appendPath } from '@silverhand/essentials'; export const createCloudServiceConnector = (data: { diff --git a/packages/connectors/connector-alipay-web/package.json b/packages/connectors/connector-alipay-web/package.json index 35248a329..76e75555e 100644 --- a/packages/connectors/connector-alipay-web/package.json +++ b/packages/connectors/connector-alipay-web/package.json @@ -4,7 +4,6 @@ "description": "Alipay implementation.", "dependencies": { "@logto/connector-kit": "workspace:^", - "@logto/core-kit": "workspace:^", "dayjs": "^1.10.5", "iconv-lite": "^0.6.3" }, diff --git a/packages/connectors/connector-apple/package.json b/packages/connectors/connector-apple/package.json index 7812bb3bb..d221e8909 100644 --- a/packages/connectors/connector-apple/package.json +++ b/packages/connectors/connector-apple/package.json @@ -4,7 +4,7 @@ "description": "Apple web connector implementation.", "dependencies": { "@logto/connector-kit": "workspace:^", - "@logto/core-kit": "workspace:^", + "@logto/shared": "workspace:^", "jose": "^4.3.8" }, "main": "./lib/index.js", diff --git a/packages/connectors/connector-apple/src/index.ts b/packages/connectors/connector-apple/src/index.ts index f5fd95e3b..9b82cb1ee 100644 --- a/packages/connectors/connector-apple/src/index.ts +++ b/packages/connectors/connector-apple/src/index.ts @@ -13,7 +13,7 @@ import { validateConfig, ConnectorType, } from '@logto/connector-kit'; -import { generateStandardId } from '@logto/core-kit'; +import { generateStandardId } from '@logto/shared/universal'; import { createRemoteJWKSet, jwtVerify } from 'jose'; import { scope, defaultMetadata, jwksUri, issuer, authorizationEndpoint } from './constant.js'; diff --git a/packages/connectors/connector-oidc/package.json b/packages/connectors/connector-oidc/package.json index da7c7ac75..839ca026d 100644 --- a/packages/connectors/connector-oidc/package.json +++ b/packages/connectors/connector-oidc/package.json @@ -4,7 +4,7 @@ "description": "OIDC standard connector implementation.", "dependencies": { "@logto/connector-kit": "workspace:^", - "@logto/core-kit": "workspace:^", + "@logto/shared": "workspace:^", "jose": "^4.3.8", "nanoid": "^4.0.0" }, diff --git a/packages/connectors/connector-oidc/src/index.ts b/packages/connectors/connector-oidc/src/index.ts index 984ca3d1c..3ccb58bbe 100644 --- a/packages/connectors/connector-oidc/src/index.ts +++ b/packages/connectors/connector-oidc/src/index.ts @@ -15,7 +15,7 @@ import { validateConfig, ConnectorType, } from '@logto/connector-kit'; -import { generateStandardId } from '@logto/core-kit'; +import { generateStandardId } from '@logto/shared/universal'; import { createRemoteJWKSet, jwtVerify } from 'jose'; import { defaultMetadata } from './constant.js'; diff --git a/packages/console/package.json b/packages/console/package.json index 3e206071f..57e9ad2a0 100644 --- a/packages/console/package.json +++ b/packages/console/package.json @@ -7,7 +7,9 @@ "license": "MPL-2.0", "type": "module", "private": true, - "files": ["dist"], + "files": [ + "dist" + ], "scripts": { "precommit": "lint-staged", "start": "parcel src/index.html", @@ -28,6 +30,7 @@ "@logto/phrases-ui": "workspace:^", "@logto/react": "1.1.0", "@logto/schemas": "workspace:^", + "@logto/shared": "workspace:^", "@mdx-js/react": "^1.6.22", "@parcel/compressor-brotli": "2.8.3", "@parcel/compressor-gzip": "2.8.3", @@ -57,7 +60,7 @@ "csstype": "^3.0.11", "date-fns": "^2.29.3", "dayjs": "^1.10.5", - "deep-object-diff": "^1.1.7", + "deep-object-diff": "^1.1.9", "deepmerge": "^4.2.2", "dnd-core": "^16.0.0", "eslint": "^8.34.0", diff --git a/packages/console/src/App.tsx b/packages/console/src/App.tsx index aeab1f5c2..2dff7a6e4 100644 --- a/packages/console/src/App.tsx +++ b/packages/console/src/App.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import { UserScope } from '@logto/core-kit'; import { LogtoProvider } from '@logto/react'; import { adminConsoleApplicationId, PredefinedScope } from '@logto/schemas'; diff --git a/packages/console/src/assets/docs/tutorial/integrate-sdk/express.mdx b/packages/console/src/assets/docs/tutorial/integrate-sdk/express.mdx index 1c7588b42..60cc11bce 100644 --- a/packages/console/src/assets/docs/tutorial/integrate-sdk/express.mdx +++ b/packages/console/src/assets/docs/tutorial/integrate-sdk/express.mdx @@ -3,7 +3,7 @@ import Step from '@mdx/components/Step'; import Tabs from '@mdx/components/Tabs'; import TabItem from '@mdx/components/TabItem'; import Alert from '@/components/Alert'; -import { buildIdGenerator } from '@logto/core-kit'; +import { buildIdGenerator } from '@logto/shared/universal'; = Array | number>; type useSwrFetcherHook = { diff --git a/packages/console/src/hooks/use-track-user-id.ts b/packages/console/src/hooks/use-track-user-id.ts index ba8e8c6ad..757c70f4c 100644 --- a/packages/console/src/hooks/use-track-user-id.ts +++ b/packages/console/src/hooks/use-track-user-id.ts @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import { useLogto } from '@logto/react'; import { trySafe } from '@silverhand/essentials'; import { useEffect } from 'react'; diff --git a/packages/console/src/onboarding/pages/About/index.tsx b/packages/console/src/onboarding/pages/About/index.tsx index 39168fe02..82900cdcf 100644 --- a/packages/console/src/onboarding/pages/About/index.tsx +++ b/packages/console/src/onboarding/pages/About/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import { conditional } from '@silverhand/essentials'; import { useEffect } from 'react'; import { Controller, useForm } from 'react-hook-form'; diff --git a/packages/console/src/onboarding/pages/Congrats/index.tsx b/packages/console/src/onboarding/pages/Congrats/index.tsx index 34d4c115b..fb4e6d7de 100644 --- a/packages/console/src/onboarding/pages/Congrats/index.tsx +++ b/packages/console/src/onboarding/pages/Congrats/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import classNames from 'classnames'; import { useContext } from 'react'; import { Trans, useTranslation } from 'react-i18next'; diff --git a/packages/console/src/onboarding/pages/SignInExperience/index.tsx b/packages/console/src/onboarding/pages/SignInExperience/index.tsx index a8b92fdbb..db23b01bb 100644 --- a/packages/console/src/onboarding/pages/SignInExperience/index.tsx +++ b/packages/console/src/onboarding/pages/SignInExperience/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import type { SignInExperience as SignInExperienceType } from '@logto/schemas'; import { SignInIdentifier } from '@logto/schemas'; import { useCallback, useEffect, useMemo } from 'react'; diff --git a/packages/console/src/onboarding/pages/Welcome/index.tsx b/packages/console/src/onboarding/pages/Welcome/index.tsx index d2d3b211e..3f7a9ba2d 100644 --- a/packages/console/src/onboarding/pages/Welcome/index.tsx +++ b/packages/console/src/onboarding/pages/Welcome/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import classNames from 'classnames'; import { useEffect } from 'react'; import { Controller, useForm } from 'react-hook-form'; diff --git a/packages/console/src/pages/ApiResourceDetails/index.tsx b/packages/console/src/pages/ApiResourceDetails/index.tsx index 9f378bc00..3d2b6b0aa 100644 --- a/packages/console/src/pages/ApiResourceDetails/index.tsx +++ b/packages/console/src/pages/ApiResourceDetails/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import type { Resource } from '@logto/schemas'; import { isManagementApi, Theme } from '@logto/schemas'; import classNames from 'classnames'; diff --git a/packages/console/src/pages/ApiResources/index.tsx b/packages/console/src/pages/ApiResources/index.tsx index dc1d83590..3d5041a63 100644 --- a/packages/console/src/pages/ApiResources/index.tsx +++ b/packages/console/src/pages/ApiResources/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import type { Resource } from '@logto/schemas'; import { Theme } from '@logto/schemas'; import { toast } from 'react-hot-toast'; diff --git a/packages/console/src/pages/ApplicationDetails/index.tsx b/packages/console/src/pages/ApplicationDetails/index.tsx index f7cdaadee..fe37665af 100644 --- a/packages/console/src/pages/ApplicationDetails/index.tsx +++ b/packages/console/src/pages/ApplicationDetails/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import type { Application, ApplicationResponse, SnakeCaseOidcConfig } from '@logto/schemas'; import { ApplicationType } from '@logto/schemas'; import { useEffect, useState } from 'react'; diff --git a/packages/console/src/pages/Applications/index.tsx b/packages/console/src/pages/Applications/index.tsx index de396451d..fa446288b 100644 --- a/packages/console/src/pages/Applications/index.tsx +++ b/packages/console/src/pages/Applications/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import type { Application } from '@logto/schemas'; import { ApplicationType } from '@logto/schemas'; import { useTranslation } from 'react-i18next'; diff --git a/packages/console/src/pages/AuditLogDetails/index.tsx b/packages/console/src/pages/AuditLogDetails/index.tsx index 09a95c7b2..cd7f4c79d 100644 --- a/packages/console/src/pages/AuditLogDetails/index.tsx +++ b/packages/console/src/pages/AuditLogDetails/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import type { User, Log } from '@logto/schemas'; import { demoAppApplicationId } from '@logto/schemas'; import { useTranslation } from 'react-i18next'; diff --git a/packages/console/src/pages/AuditLogs/index.tsx b/packages/console/src/pages/AuditLogs/index.tsx index f7110adca..6b84f2cd5 100644 --- a/packages/console/src/pages/AuditLogs/index.tsx +++ b/packages/console/src/pages/AuditLogs/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import AuditLogTable from '@/components/AuditLogTable'; import CardTitle from '@/components/CardTitle'; diff --git a/packages/console/src/pages/ConnectorDetails/index.tsx b/packages/console/src/pages/ConnectorDetails/index.tsx index 97ef843e0..a67634ed1 100644 --- a/packages/console/src/pages/ConnectorDetails/index.tsx +++ b/packages/console/src/pages/ConnectorDetails/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import { ConnectorType } from '@logto/schemas'; import type { ConnectorFactoryResponse, ConnectorResponse } from '@logto/schemas'; import { useEffect, useState } from 'react'; diff --git a/packages/console/src/pages/Connectors/components/Guide/index.tsx b/packages/console/src/pages/Connectors/components/Guide/index.tsx index 2f6463cf1..c18656eed 100644 --- a/packages/console/src/pages/Connectors/components/Guide/index.tsx +++ b/packages/console/src/pages/Connectors/components/Guide/index.tsx @@ -1,7 +1,7 @@ -import { generateStandardId } from '@logto/core-kit'; import { isLanguageTag } from '@logto/language-kit'; import type { ConnectorFactoryResponse, ConnectorResponse, RequestErrorBody } from '@logto/schemas'; import { ConnectorType } from '@logto/schemas'; +import { generateStandardId } from '@logto/shared/universal'; import { conditional } from '@silverhand/essentials'; import i18next from 'i18next'; import { HTTPError } from 'ky'; diff --git a/packages/console/src/pages/Connectors/index.tsx b/packages/console/src/pages/Connectors/index.tsx index 61639b10f..4ffc71680 100644 --- a/packages/console/src/pages/Connectors/index.tsx +++ b/packages/console/src/pages/Connectors/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import type { ConnectorFactoryResponse } from '@logto/schemas'; import { ConnectorType } from '@logto/schemas'; import { conditional } from '@silverhand/essentials'; diff --git a/packages/console/src/pages/Dashboard/index.tsx b/packages/console/src/pages/Dashboard/index.tsx index 6a12ddf5f..bb38ca2b8 100644 --- a/packages/console/src/pages/Dashboard/index.tsx +++ b/packages/console/src/pages/Dashboard/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import { format } from 'date-fns'; import type { ChangeEventHandler } from 'react'; import { useState } from 'react'; diff --git a/packages/console/src/pages/GetStarted/index.tsx b/packages/console/src/pages/GetStarted/index.tsx index 9ce6219cb..50ce145f8 100644 --- a/packages/console/src/pages/GetStarted/index.tsx +++ b/packages/console/src/pages/GetStarted/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useNavigate } from 'react-router-dom'; diff --git a/packages/console/src/pages/Profile/components/LinkAccountSection/index.tsx b/packages/console/src/pages/Profile/components/LinkAccountSection/index.tsx index fd20172e0..3998bf371 100644 --- a/packages/console/src/pages/Profile/components/LinkAccountSection/index.tsx +++ b/packages/console/src/pages/Profile/components/LinkAccountSection/index.tsx @@ -1,8 +1,8 @@ import type { SocialUserInfo } from '@logto/connector-kit'; import { socialUserInfoGuard } from '@logto/connector-kit'; -import { buildIdGenerator } from '@logto/core-kit'; import type { ConnectorResponse, UserInfo } from '@logto/schemas'; import { Theme } from '@logto/schemas'; +import { buildIdGenerator } from '@logto/shared/universal'; import type { Optional } from '@silverhand/essentials'; import { appendPath, conditional } from '@silverhand/essentials'; import { useCallback, useMemo } from 'react'; diff --git a/packages/console/src/pages/Profile/index.tsx b/packages/console/src/pages/Profile/index.tsx index dcea7e17e..da67ae9b6 100644 --- a/packages/console/src/pages/Profile/index.tsx +++ b/packages/console/src/pages/Profile/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import type { ConnectorResponse } from '@logto/schemas'; import { useState } from 'react'; import { useTranslation } from 'react-i18next'; diff --git a/packages/console/src/pages/RoleDetails/index.tsx b/packages/console/src/pages/RoleDetails/index.tsx index 413e24c59..38cc1b1e4 100644 --- a/packages/console/src/pages/RoleDetails/index.tsx +++ b/packages/console/src/pages/RoleDetails/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import type { Role } from '@logto/schemas'; import classNames from 'classnames'; import { useEffect, useState } from 'react'; diff --git a/packages/console/src/pages/Roles/index.tsx b/packages/console/src/pages/Roles/index.tsx index e1ab117b9..50a7f7c3c 100644 --- a/packages/console/src/pages/Roles/index.tsx +++ b/packages/console/src/pages/Roles/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import type { RoleResponse } from '@logto/schemas'; import { conditional } from '@silverhand/essentials'; import { useTranslation } from 'react-i18next'; diff --git a/packages/console/src/pages/SignInExperience/index.tsx b/packages/console/src/pages/SignInExperience/index.tsx index 81a724058..79a10041f 100644 --- a/packages/console/src/pages/SignInExperience/index.tsx +++ b/packages/console/src/pages/SignInExperience/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import type { SignInExperience as SignInExperienceType } from '@logto/schemas'; import classNames from 'classnames'; import type { ReactNode } from 'react'; diff --git a/packages/console/src/pages/UserDetails/index.tsx b/packages/console/src/pages/UserDetails/index.tsx index 3a19bf828..11aa61246 100644 --- a/packages/console/src/pages/UserDetails/index.tsx +++ b/packages/console/src/pages/UserDetails/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import type { User } from '@logto/schemas'; import classNames from 'classnames'; import { useEffect, useState } from 'react'; diff --git a/packages/console/src/pages/Users/index.tsx b/packages/console/src/pages/Users/index.tsx index 472d88867..9c3d1201f 100644 --- a/packages/console/src/pages/Users/index.tsx +++ b/packages/console/src/pages/Users/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import type { User } from '@logto/schemas'; import { conditional } from '@silverhand/essentials'; import { useTranslation } from 'react-i18next'; diff --git a/packages/console/tsconfig.json b/packages/console/tsconfig.json index ec55f4430..908bc14a5 100644 --- a/packages/console/tsconfig.json +++ b/packages/console/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "@silverhand/ts-config-react/tsconfig.base", "compilerOptions": { + "moduleResolution": "bundler", "baseUrl": "./", "paths": { "@/*": ["./src/*"], diff --git a/packages/core/src/__mocks__/connector.ts b/packages/core/src/__mocks__/connector.ts index cc08d019f..20a409307 100644 --- a/packages/core/src/__mocks__/connector.ts +++ b/packages/core/src/__mocks__/connector.ts @@ -1,8 +1,7 @@ import type { ConnectorFactory } from '@logto/cli/lib/connector/index.js'; -import { ConnectorPlatform } from '@logto/connector-kit'; +import { ConnectorPlatform, DemoConnector } from '@logto/connector-kit'; import type { Connector } from '@logto/schemas'; import { ConnectorType } from '@logto/schemas'; -import { DemoConnector } from '@logto/shared'; import { any } from 'zod'; import type { LogtoConnector } from '#src/utils/connectors/types.js'; diff --git a/packages/core/src/libraries/hook.ts b/packages/core/src/libraries/hook.ts index 949cbc7a9..dd5e40b32 100644 --- a/packages/core/src/libraries/hook.ts +++ b/packages/core/src/libraries/hook.ts @@ -1,4 +1,3 @@ -import { generateStandardId } from '@logto/core-kit'; import { HookEvent, type HookEventPayload, @@ -6,6 +5,7 @@ import { LogResult, userInfoSelectFields, } from '@logto/schemas'; +import { generateStandardId } from '@logto/shared'; import { conditional, pick, trySafe } from '@silverhand/essentials'; import type { Response } from 'got'; import { got, HTTPError } from 'got'; diff --git a/packages/core/src/libraries/user.ts b/packages/core/src/libraries/user.ts index 221b7de78..ff946ae7d 100644 --- a/packages/core/src/libraries/user.ts +++ b/packages/core/src/libraries/user.ts @@ -1,6 +1,6 @@ -import { buildIdGenerator, generateStandardId } from '@logto/core-kit'; import type { User, CreateUser, Scope } from '@logto/schemas'; import { Users, UsersPasswordEncryptionMethod } from '@logto/schemas'; +import { buildIdGenerator, generateStandardId } from '@logto/shared'; import type { OmitAutoSetFields } from '@logto/shared'; import type { Nullable } from '@silverhand/essentials'; import { deduplicate } from '@silverhand/essentials'; diff --git a/packages/core/src/libraries/verification-status.ts b/packages/core/src/libraries/verification-status.ts index 1ada8ade9..2dc31e613 100644 --- a/packages/core/src/libraries/verification-status.ts +++ b/packages/core/src/libraries/verification-status.ts @@ -1,4 +1,4 @@ -import { generateStandardId } from '@logto/core-kit'; +import { generateStandardId } from '@logto/shared'; import RequestError from '#src/errors/RequestError/index.js'; import { verificationTimeout } from '#src/routes/consts.js'; diff --git a/packages/core/src/middleware/koa-audit-log.ts b/packages/core/src/middleware/koa-audit-log.ts index 5af877d5b..e7cd30a17 100644 --- a/packages/core/src/middleware/koa-audit-log.ts +++ b/packages/core/src/middleware/koa-audit-log.ts @@ -1,6 +1,6 @@ -import { generateStandardId } from '@logto/core-kit'; import type { LogContextPayload, LogKey } from '@logto/schemas'; import { LogResult } from '@logto/schemas'; +import { generateStandardId } from '@logto/shared'; import { pick } from '@silverhand/essentials'; import type { Context, MiddlewareType } from 'koa'; import type { IRouterParamContext } from 'koa-router'; diff --git a/packages/core/src/routes/admin-user-role.ts b/packages/core/src/routes/admin-user-role.ts index 1e27ac1ff..efcd6a4dc 100644 --- a/packages/core/src/routes/admin-user-role.ts +++ b/packages/core/src/routes/admin-user-role.ts @@ -1,4 +1,4 @@ -import { generateStandardId } from '@logto/core-kit'; +import { generateStandardId } from '@logto/shared'; import { tryThat } from '@silverhand/essentials'; import { object, string } from 'zod'; diff --git a/packages/core/src/routes/application.ts b/packages/core/src/routes/application.ts index f3ca60e9d..403067956 100644 --- a/packages/core/src/routes/application.ts +++ b/packages/core/src/routes/application.ts @@ -1,4 +1,3 @@ -import { generateStandardId, buildIdGenerator } from '@logto/core-kit'; import type { Role } from '@logto/schemas'; import { demoAppApplicationId, @@ -6,6 +5,7 @@ import { Applications, InternalRole, } from '@logto/schemas'; +import { generateStandardId, buildIdGenerator } from '@logto/shared'; import { boolean, object, string, z } from 'zod'; import RequestError from '#src/errors/RequestError/index.js'; diff --git a/packages/core/src/routes/connector.ts b/packages/core/src/routes/connector.ts index 505eab1c9..4920ce2d0 100644 --- a/packages/core/src/routes/connector.ts +++ b/packages/core/src/routes/connector.ts @@ -1,11 +1,16 @@ /* eslint-disable max-lines */ import { buildRawConnector } from '@logto/cli/lib/connector/index.js'; import type { ConnectorFactory } from '@logto/cli/lib/connector/index.js'; -import type { SmsConnector, EmailConnector } from '@logto/connector-kit'; -import { VerificationCodeType, validateConfig } from '@logto/connector-kit'; -import { emailRegEx, phoneRegEx, buildIdGenerator } from '@logto/core-kit'; +import { + type SmsConnector, + type EmailConnector, + demoConnectorIds, + VerificationCodeType, + validateConfig, +} from '@logto/connector-kit'; +import { phoneRegEx, emailRegEx } from '@logto/core-kit'; import { arbitraryObjectGuard, Connectors, ConnectorType } from '@logto/schemas'; -import { demoConnectorIds } from '@logto/shared'; +import { buildIdGenerator } from '@logto/shared'; import cleanDeep from 'clean-deep'; import { string, object } from 'zod'; diff --git a/packages/core/src/routes/custom-phrase.ts b/packages/core/src/routes/custom-phrase.ts index e3cf1496d..83b4f2e47 100644 --- a/packages/core/src/routes/custom-phrase.ts +++ b/packages/core/src/routes/custom-phrase.ts @@ -1,8 +1,8 @@ -import { generateStandardId } from '@logto/core-kit'; import { languageTagGuard } from '@logto/language-kit'; import resource from '@logto/phrases-ui'; import type { Translation } from '@logto/schemas'; import { CustomPhrases, translationGuard } from '@logto/schemas'; +import { generateStandardId } from '@logto/shared'; import cleanDeep from 'clean-deep'; import { object } from 'zod'; diff --git a/packages/core/src/routes/hook.ts b/packages/core/src/routes/hook.ts index 26e6a59ba..8dda6b59c 100644 --- a/packages/core/src/routes/hook.ts +++ b/packages/core/src/routes/hook.ts @@ -1,5 +1,5 @@ -import { generateStandardId } from '@logto/core-kit'; import { Hooks } from '@logto/schemas'; +import { generateStandardId } from '@logto/shared'; import { z } from 'zod'; import koaGuard from '#src/middleware/koa-guard.js'; diff --git a/packages/core/src/routes/resource.ts b/packages/core/src/routes/resource.ts index 30130c3ba..cc1675628 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, Scopes } from '@logto/schemas'; +import { buildIdGenerator } from '@logto/shared'; import { tryThat, yes } from '@silverhand/essentials'; import { object, string } from 'zod'; diff --git a/packages/core/src/routes/role.scope.ts b/packages/core/src/routes/role.scope.ts index 6422f6e81..a103c86aa 100644 --- a/packages/core/src/routes/role.scope.ts +++ b/packages/core/src/routes/role.scope.ts @@ -1,5 +1,5 @@ -import { generateStandardId } from '@logto/core-kit'; import type { ScopeResponse } from '@logto/schemas'; +import { generateStandardId } from '@logto/shared'; import { tryThat } from '@silverhand/essentials'; import { object, string } from 'zod'; diff --git a/packages/core/src/routes/role.ts b/packages/core/src/routes/role.ts index c704d6fe2..70ee96ca1 100644 --- a/packages/core/src/routes/role.ts +++ b/packages/core/src/routes/role.ts @@ -1,6 +1,6 @@ -import { generateStandardId } from '@logto/core-kit'; import type { RoleResponse } from '@logto/schemas'; import { userInfoSelectFields, Roles } from '@logto/schemas'; +import { generateStandardId } from '@logto/shared'; import { pick, tryThat } from '@silverhand/essentials'; import { object, string, z } from 'zod'; diff --git a/packages/core/src/routes/sign-in-experience/index.ts b/packages/core/src/routes/sign-in-experience/index.ts index b8c5b027d..b731b07de 100644 --- a/packages/core/src/routes/sign-in-experience/index.ts +++ b/packages/core/src/routes/sign-in-experience/index.ts @@ -1,5 +1,5 @@ +import { DemoConnector } from '@logto/connector-kit'; import { ConnectorType, SignInExperiences } from '@logto/schemas'; -import { DemoConnector } from '@logto/shared'; import { literal, object, string, z } from 'zod'; import { validateSignUp, validateSignIn } from '#src/libraries/sign-in-experience/index.js'; diff --git a/packages/core/src/routes/user-assets.ts b/packages/core/src/routes/user-assets.ts index 84d3ba91b..03b223519 100644 --- a/packages/core/src/routes/user-assets.ts +++ b/packages/core/src/routes/user-assets.ts @@ -1,6 +1,5 @@ import { readFile } from 'node:fs/promises'; -import { generateStandardId } from '@logto/core-kit'; import type { UserAssets } from '@logto/schemas'; import { userAssetsGuard, @@ -8,6 +7,7 @@ import { allowUploadMimeTypes, maxUploadFileSize, } from '@logto/schemas'; +import { generateStandardId } from '@logto/shared'; import { format } from 'date-fns'; import { object } from 'zod'; diff --git a/packages/core/src/utils/connectors/index.ts b/packages/core/src/utils/connectors/index.ts index efaf909cf..114f896ca 100644 --- a/packages/core/src/utils/connectors/index.ts +++ b/packages/core/src/utils/connectors/index.ts @@ -6,8 +6,9 @@ import type { ConnectorFactory } from '@logto/cli/lib/connector/index.js'; import { loadConnectorFactories as _loadConnectorFactories } from '@logto/cli/lib/connector/index.js'; import { connectorDirectory } from '@logto/cli/lib/constants.js'; import { getConnectorPackagesFromDirectory } from '@logto/cli/lib/utils.js'; +import { demoConnectorIds } from '@logto/connector-kit'; import type { ConnectorFactoryResponse, ConnectorResponse } from '@logto/schemas'; -import { demoConnectorIds, findPackage } from '@logto/shared'; +import { findPackage } from '@logto/shared'; import { deduplicate, pick } from '@silverhand/essentials'; import { EnvSet } from '#src/env-set/index.js'; diff --git a/packages/schemas/alterations/1.0.0-1677765137-seed-for-admin-tenant.ts b/packages/schemas/alterations/1.0.0-1677765137-seed-for-admin-tenant.ts index f2dce23bf..11dcc3e83 100644 --- a/packages/schemas/alterations/1.0.0-1677765137-seed-for-admin-tenant.ts +++ b/packages/schemas/alterations/1.0.0-1677765137-seed-for-admin-tenant.ts @@ -1,4 +1,4 @@ -import { generateStandardId } from '@logto/core-kit'; +import { generateStandardId } from '@logto/shared/universal'; import type { CommonQueryMethods } from 'slonik'; import { sql } from 'slonik'; diff --git a/packages/schemas/alterations/1.0.0-1677907982-allow-admin-create-multiple-tenants.ts b/packages/schemas/alterations/1.0.0-1677907982-allow-admin-create-multiple-tenants.ts index ae3e14e43..ca7fa7f54 100644 --- a/packages/schemas/alterations/1.0.0-1677907982-allow-admin-create-multiple-tenants.ts +++ b/packages/schemas/alterations/1.0.0-1677907982-allow-admin-create-multiple-tenants.ts @@ -1,4 +1,4 @@ -import { generateStandardId } from '@logto/core-kit'; +import { generateStandardId } from '@logto/shared/universal'; import { sql } from 'slonik'; import type { AlterationScript } from '../lib/types/alteration.js'; diff --git a/packages/schemas/alterations/1.0.0-1678425761-m2m-app-for-tenants.ts b/packages/schemas/alterations/1.0.0-1678425761-m2m-app-for-tenants.ts index 66c19291e..8ec500bfb 100644 --- a/packages/schemas/alterations/1.0.0-1678425761-m2m-app-for-tenants.ts +++ b/packages/schemas/alterations/1.0.0-1678425761-m2m-app-for-tenants.ts @@ -1,4 +1,4 @@ -import { generateStandardId } from '@logto/core-kit'; +import { generateStandardId } from '@logto/shared/universal'; import { sql } from 'slonik'; import type { AlterationScript } from '../lib/types/alteration.js'; diff --git a/packages/schemas/alterations/1.0.0_rc.1-1675788753-multi-tenancy-rls.ts b/packages/schemas/alterations/1.0.0_rc.1-1675788753-multi-tenancy-rls.ts index ebe3b594d..53543b141 100644 --- a/packages/schemas/alterations/1.0.0_rc.1-1675788753-multi-tenancy-rls.ts +++ b/packages/schemas/alterations/1.0.0_rc.1-1675788753-multi-tenancy-rls.ts @@ -1,4 +1,4 @@ -import { generateStandardId } from '@logto/core-kit'; +import { generateStandardId } from '@logto/shared/universal'; import type { CommonQueryMethods } from 'slonik'; import { sql } from 'slonik'; import { raw } from 'slonik-sql-tag-raw'; diff --git a/packages/schemas/alterations/1.0.0_rc.1-1676115897-add-admin-tenant.ts b/packages/schemas/alterations/1.0.0_rc.1-1676115897-add-admin-tenant.ts index 03d5278bf..422b33c73 100644 --- a/packages/schemas/alterations/1.0.0_rc.1-1676115897-add-admin-tenant.ts +++ b/packages/schemas/alterations/1.0.0_rc.1-1676115897-add-admin-tenant.ts @@ -1,4 +1,4 @@ -import { generateStandardId } from '@logto/core-kit'; +import { generateStandardId } from '@logto/shared/universal'; import type { CommonQueryMethods } from 'slonik'; import { sql } from 'slonik'; import { raw } from 'slonik-sql-tag-raw'; diff --git a/packages/schemas/alterations/1.0.0_rc.1-1676190092-migrate-admin-data.ts b/packages/schemas/alterations/1.0.0_rc.1-1676190092-migrate-admin-data.ts index 828f25ce4..cb2e49446 100644 --- a/packages/schemas/alterations/1.0.0_rc.1-1676190092-migrate-admin-data.ts +++ b/packages/schemas/alterations/1.0.0_rc.1-1676190092-migrate-admin-data.ts @@ -1,7 +1,7 @@ -import { generateKeyPair } from 'crypto'; -import { promisify } from 'util'; +import { generateKeyPair } from 'node:crypto'; +import { promisify } from 'node:util'; -import { generateStandardId } from '@logto/core-kit'; +import { generateStandardId } from '@logto/shared/universal'; import inquirer from 'inquirer'; import type { CommonQueryMethods, SerializableValue } from 'slonik'; import { sql } from 'slonik'; diff --git a/packages/schemas/alterations/1.0.0_rc.1-1676906977-remove-demo-app.ts b/packages/schemas/alterations/1.0.0_rc.1-1676906977-remove-demo-app.ts index f88838c52..0e744b16c 100644 --- a/packages/schemas/alterations/1.0.0_rc.1-1676906977-remove-demo-app.ts +++ b/packages/schemas/alterations/1.0.0_rc.1-1676906977-remove-demo-app.ts @@ -1,4 +1,4 @@ -import { generateStandardId } from '@logto/core-kit'; +import { generateStandardId } from '@logto/shared/universal'; import chalk from 'chalk'; import inquirer from 'inquirer'; import { sql } from 'slonik'; diff --git a/packages/schemas/alterations/1.0.0_rc.1-1677059985-move-console-application-to-database.ts b/packages/schemas/alterations/1.0.0_rc.1-1677059985-move-console-application-to-database.ts index aeb88bfa9..4dc1de144 100644 --- a/packages/schemas/alterations/1.0.0_rc.1-1677059985-move-console-application-to-database.ts +++ b/packages/schemas/alterations/1.0.0_rc.1-1677059985-move-console-application-to-database.ts @@ -1,4 +1,4 @@ -import { generateStandardId } from '@logto/core-kit'; +import { generateStandardId } from '@logto/shared/universal'; import { sql } from 'slonik'; import type { AlterationScript } from '../lib/types/alteration.js'; diff --git a/packages/schemas/package.json b/packages/schemas/package.json index 27c116a9f..2e1209bf6 100644 --- a/packages/schemas/package.json +++ b/packages/schemas/package.json @@ -85,6 +85,7 @@ "@logto/language-kit": "workspace:^", "@logto/phrases": "workspace:^", "@logto/phrases-ui": "workspace:^", + "@logto/shared": "workspace:^", "@withtyped/server": "^0.8.1", "zod": "^3.20.2" } diff --git a/packages/schemas/src/foundations/schemas.ts b/packages/schemas/src/foundations/schemas.ts index cb3164ffd..c4d99cde3 100644 --- a/packages/schemas/src/foundations/schemas.ts +++ b/packages/schemas/src/foundations/schemas.ts @@ -1,5 +1,8 @@ +import { type SchemaLike } from '@logto/shared/universal'; import type { ZodObject, ZodType, ZodOptional } from 'zod'; +export type { SchemaLike, SchemaValue, SchemaValuePrimitive } from '@logto/shared/universal'; + type ParseOptional = undefined extends K ? ZodOptional>> : ZodType; @@ -12,12 +15,6 @@ export type Guard> = ZodObject<{ [key in keyof T]: ZodType; }>; -export type SchemaValuePrimitive = string | number | boolean | undefined; -export type SchemaValue = SchemaValuePrimitive | Record | unknown[] | null; -export type SchemaLike = { - [key in Key]: SchemaValue; -}; - export type GeneratedSchema< CreateSchema extends SchemaLike, Schema extends CreateSchema diff --git a/packages/schemas/src/seeds/application.ts b/packages/schemas/src/seeds/application.ts index 7896bcd44..42dad8044 100644 --- a/packages/schemas/src/seeds/application.ts +++ b/packages/schemas/src/seeds/application.ts @@ -1,4 +1,4 @@ -import { generateStandardId } from '@logto/core-kit'; +import { generateStandardId } from '@logto/shared/universal'; import type { Application, diff --git a/packages/schemas/src/seeds/cloud-api.ts b/packages/schemas/src/seeds/cloud-api.ts index 76fd9117b..c51d520e0 100644 --- a/packages/schemas/src/seeds/cloud-api.ts +++ b/packages/schemas/src/seeds/cloud-api.ts @@ -1,4 +1,4 @@ -import { generateStandardId } from '@logto/core-kit'; +import { generateStandardId } from '@logto/shared/universal'; import type { CreateScope, Role } from '../index.js'; import { AdminTenantRole } from '../types/index.js'; diff --git a/packages/schemas/src/seeds/management-api.ts b/packages/schemas/src/seeds/management-api.ts index 21b1599e2..d952bb544 100644 --- a/packages/schemas/src/seeds/management-api.ts +++ b/packages/schemas/src/seeds/management-api.ts @@ -1,4 +1,4 @@ -import { generateStandardId } from '@logto/core-kit'; +import { generateStandardId } from '@logto/shared/universal'; import type { CreateResource, CreateRole, CreateScope } from '../db-entries/index.js'; import { PredefinedScope, InternalRole, AdminTenantRole } from '../types/index.js'; diff --git a/packages/shared/REAMDE.md b/packages/shared/REAMDE.md new file mode 100644 index 000000000..4a495648e --- /dev/null +++ b/packages/shared/REAMDE.md @@ -0,0 +1,5 @@ +# @logto/shared + +The shared package for **non-business** components. For Logto business related stuff, put it to one of the packages in `packages/toolkit/`. + +The main import includes all components which may require Node. Import `@logto/shared/universal` for the universal bundle. diff --git a/packages/shared/package.json b/packages/shared/package.json index 5aa26512e..8b661a23d 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -10,12 +10,22 @@ ], "exports": { ".": { - "import": "./lib/index.js" + "import": "./lib/index.js", + "types": "./lib/index.d.ts" + }, + "./universal": { + "import": "./lib/universal.js", + "types": "./lib/universal.d.ts" }, "./esm": { - "import": "./lib/esm/index.js" + "import": "./lib/esm/index.js", + "types": "./lib/esm/index.d.ts" } }, + "//": "This field is for parcel. Remove after https://github.com/parcel-bundler/parcel/pull/8807 published.", + "alias": { + "./universal": "./lib/universal.js" + }, "publishConfig": { "access": "public" }, @@ -54,8 +64,6 @@ }, "prettier": "@silverhand/eslint-config/.prettierrc", "dependencies": { - "@logto/core-kit": "workspace:^", - "@logto/schemas": "workspace:^", "@silverhand/essentials": "^2.5.0", "chalk": "^5.0.0", "find-up": "^6.3.0", diff --git a/packages/shared/src/database/index.ts b/packages/shared/src/database/index.ts index 920534d03..cfaca1176 100644 --- a/packages/shared/src/database/index.ts +++ b/packages/shared/src/database/index.ts @@ -1,2 +1,6 @@ +/* + We does not export `sql.ts` here since it requires slonik which is not universal. + It will be exported separately in `/src/index.ts`. +*/ + export * from './types.js'; -export * from './utils.js'; diff --git a/packages/shared/src/database/utils.test.ts b/packages/shared/src/database/sql.test.ts similarity index 99% rename from packages/shared/src/database/utils.test.ts rename to packages/shared/src/database/sql.test.ts index 9199c1021..78dba6e8b 100644 --- a/packages/shared/src/database/utils.test.ts +++ b/packages/shared/src/database/sql.test.ts @@ -1,7 +1,6 @@ import { sql } from 'slonik'; import { SqlToken } from 'slonik/dist/src/tokens.js'; -import type { Table } from './types.js'; import { excludeAutoSetFields, autoSetFields, @@ -9,7 +8,8 @@ import { convertToIdentifiers, convertToTimestamp, conditionalSql, -} from './utils.js'; +} from './sql.js'; +import type { Table } from './types.js'; const { jest } = import.meta; diff --git a/packages/shared/src/database/utils.ts b/packages/shared/src/database/sql.ts similarity index 95% rename from packages/shared/src/database/utils.ts rename to packages/shared/src/database/sql.ts index 8bee023e7..fec638b72 100644 --- a/packages/shared/src/database/utils.ts +++ b/packages/shared/src/database/sql.ts @@ -1,10 +1,9 @@ -import type { SchemaValuePrimitive, SchemaValue } from '@logto/schemas'; import type { Falsy } from '@silverhand/essentials'; import { notFalsy } from '@silverhand/essentials'; import type { SqlSqlToken, SqlToken, QueryResult, IdentifierSqlToken } from 'slonik'; import { sql } from 'slonik'; -import type { FieldIdentifiers, Table } from './types.js'; +import type { FieldIdentifiers, SchemaValue, SchemaValuePrimitive, Table } from './types.js'; export const conditionalSql = (value: T, buildSql: (value: Exclude) => SqlSqlToken) => notFalsy(value) ? buildSql(value) : sql``; diff --git a/packages/shared/src/database/types.ts b/packages/shared/src/database/types.ts index 88a449216..7cfc79003 100644 --- a/packages/shared/src/database/types.ts +++ b/packages/shared/src/database/types.ts @@ -1,6 +1,11 @@ -import type { SchemaLike } from '@logto/schemas'; import type { IdentifierSqlToken } from 'slonik'; +export type SchemaValuePrimitive = string | number | boolean | undefined; +export type SchemaValue = SchemaValuePrimitive | Record | unknown[] | null; +export type SchemaLike = { + [key in Key]: SchemaValue; +}; + export type Table = { table: string; fields: Record }; export type FieldIdentifiers = { [key in Key]: IdentifierSqlToken; diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index 5379f0d66..bd0487a64 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -1,5 +1,3 @@ -export * from './database/index.js'; -export * from './utils/index.js'; -export * from './models/index.js'; -export { default as UrlSet } from './env/UrlSet.js'; -export { default as GlobalValues } from './env/GlobalValues.js'; +export * from './universal.js'; +export * from './node/index.js'; +export * from './database/sql.js'; diff --git a/packages/shared/src/models/connector.ts b/packages/shared/src/models/connector.ts deleted file mode 100644 index 93176dc21..000000000 --- a/packages/shared/src/models/connector.ts +++ /dev/null @@ -1,11 +0,0 @@ -export enum DemoConnector { - Sms = 'logto-sms', - Email = 'logto-email', - Social = 'logto-social-demo', -} - -export const demoConnectorIds: string[] = [ - DemoConnector.Sms, - DemoConnector.Email, - DemoConnector.Social, -]; diff --git a/packages/shared/src/models/index.ts b/packages/shared/src/models/index.ts deleted file mode 100644 index 26edebe36..000000000 --- a/packages/shared/src/models/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './tenant.js'; -export * from './connector.js'; diff --git a/packages/shared/src/utils/find-package.ts b/packages/shared/src/node/find-package.ts similarity index 100% rename from packages/shared/src/utils/find-package.ts rename to packages/shared/src/node/find-package.ts diff --git a/packages/shared/src/node/index.ts b/packages/shared/src/node/index.ts new file mode 100644 index 000000000..f0318fc3b --- /dev/null +++ b/packages/shared/src/node/index.ts @@ -0,0 +1 @@ +export { default as findPackage } from './find-package.js'; diff --git a/packages/shared/src/universal.ts b/packages/shared/src/universal.ts new file mode 100644 index 000000000..4f8006dbc --- /dev/null +++ b/packages/shared/src/universal.ts @@ -0,0 +1,4 @@ +export * from './database/index.js'; +export * from './utils/index.js'; +export { default as UrlSet } from './env/UrlSet.js'; +export { default as GlobalValues } from './env/GlobalValues.js'; diff --git a/packages/toolkit/core-kit/src/utils/id.test.ts b/packages/shared/src/utils/id.test.ts similarity index 100% rename from packages/toolkit/core-kit/src/utils/id.test.ts rename to packages/shared/src/utils/id.test.ts diff --git a/packages/shared/src/utils/id.ts b/packages/shared/src/utils/id.ts new file mode 100644 index 000000000..f48d9ee22 --- /dev/null +++ b/packages/shared/src/utils/id.ts @@ -0,0 +1,22 @@ +import { customAlphabet } from 'nanoid'; + +const lowercaseAlphabet = '0123456789abcdefghijklmnopqrstuvwxyz'; +const alphabet = `${lowercaseAlphabet}ABCDEFGHIJKLMNOPQRSTUVWXYZ` as const; + +type BuildIdGenerator = { + /** + * Build a nanoid generator function uses numbers (0-9), lowercase letters (a-z), and uppercase letters (A-Z) as the alphabet. + * @param size The default id length for the generator. + */ + (size: number): ReturnType; + /** + * Build a nanoid generator function uses numbers (0-9) and lowercase letters (a-z) as the alphabet. + * @param size The default id length for the generator. + */ + // eslint-disable-next-line @typescript-eslint/unified-signatures + (size: number, includingUppercase: false): ReturnType; +}; + +export const buildIdGenerator: BuildIdGenerator = (size: number, includingUppercase = false) => + customAlphabet(includingUppercase ? alphabet : lowercaseAlphabet, size); +export const generateStandardId = buildIdGenerator(21); diff --git a/packages/shared/src/utils/index.ts b/packages/shared/src/utils/index.ts index af9d1d8c9..5ee5aa525 100644 --- a/packages/shared/src/utils/index.ts +++ b/packages/shared/src/utils/index.ts @@ -1,3 +1,3 @@ export * from './object.js'; -export { default as findPackage } from './find-package.js'; export * from './ttl-cache.js'; +export * from './id.js'; diff --git a/packages/toolkit/connector-kit/src/types.ts b/packages/toolkit/connector-kit/src/types.ts index 89ede5673..f98effc44 100644 --- a/packages/toolkit/connector-kit/src/types.ts +++ b/packages/toolkit/connector-kit/src/types.ts @@ -259,3 +259,15 @@ export type GetUserInfo = ( data: unknown, getSession: GetSession ) => Promise>; + +export enum DemoConnector { + Sms = 'logto-sms', + Email = 'logto-email', + Social = 'logto-social-demo', +} + +export const demoConnectorIds: readonly string[] = Object.freeze([ + DemoConnector.Sms, + DemoConnector.Email, + DemoConnector.Social, +]); diff --git a/packages/toolkit/core-kit/package.json b/packages/toolkit/core-kit/package.json index bea4d955f..5e071d2f2 100644 --- a/packages/toolkit/core-kit/package.json +++ b/packages/toolkit/core-kit/package.json @@ -40,8 +40,8 @@ }, "dependencies": { "@logto/language-kit": "workspace:^", - "color": "^4.2.3", - "nanoid": "^4.0.0" + "@logto/shared": "workspace:^", + "color": "^4.2.3" }, "optionalDependencies": { "zod": "^3.20.2" @@ -49,9 +49,9 @@ "devDependencies": { "@jest/types": "^29.0.3", "@silverhand/eslint-config": "3.0.0", - "@silverhand/ts-config-react": "3.0.0", "@silverhand/essentials": "^2.5.0", "@silverhand/ts-config": "3.0.0", + "@silverhand/ts-config-react": "3.0.0", "@types/color": "^3.0.3", "@types/jest": "^29.4.0", "@types/node": "^18.11.18", diff --git a/packages/toolkit/core-kit/src/index.ts b/packages/toolkit/core-kit/src/index.ts index 8c661714f..0954662e4 100644 --- a/packages/toolkit/core-kit/src/index.ts +++ b/packages/toolkit/core-kit/src/index.ts @@ -1,3 +1,4 @@ export * from './utils/index.js'; export * from './regex.js'; export * from './scope.js'; +export * from './models/index.js'; diff --git a/packages/toolkit/core-kit/src/models/index.ts b/packages/toolkit/core-kit/src/models/index.ts new file mode 100644 index 000000000..8d4d25673 --- /dev/null +++ b/packages/toolkit/core-kit/src/models/index.ts @@ -0,0 +1 @@ +export * from './tenant.js'; diff --git a/packages/shared/src/models/tenant.ts b/packages/toolkit/core-kit/src/models/tenant.ts similarity index 68% rename from packages/shared/src/models/tenant.ts rename to packages/toolkit/core-kit/src/models/tenant.ts index 0317acb38..ad52d5167 100644 --- a/packages/shared/src/models/tenant.ts +++ b/packages/toolkit/core-kit/src/models/tenant.ts @@ -1,8 +1,7 @@ -import { generateStandardId } from '@logto/core-kit'; -import { customAlphabet } from 'nanoid'; +import { generateStandardId, buildIdGenerator } from '@logto/shared/universal'; // Use lowercase letters for tenant IDs to improve compatibility -export const tenantIdAlphabet = '0123456789abcdefghijklmnopqrstuvwxyz'; +const generateTenantId = buildIdGenerator(6, false); export type TenantMetadata = { id: string; @@ -13,7 +12,7 @@ export type TenantMetadata = { export const createTenantMetadata = ( databaseName: string, - tenantId = customAlphabet(tenantIdAlphabet)(6) + tenantId = generateTenantId(6) ): TenantMetadata => { const parentRole = `logto_tenant_${databaseName}`; const role = `logto_tenant_${databaseName}_${tenantId}`; diff --git a/packages/toolkit/core-kit/src/utils/id.ts b/packages/toolkit/core-kit/src/utils/id.ts deleted file mode 100644 index bf1579bce..000000000 --- a/packages/toolkit/core-kit/src/utils/id.ts +++ /dev/null @@ -1,6 +0,0 @@ -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/utils/index.ts b/packages/toolkit/core-kit/src/utils/index.ts index c53c75e83..51455fb4b 100644 --- a/packages/toolkit/core-kit/src/utils/index.ts +++ b/packages/toolkit/core-kit/src/utils/index.ts @@ -1,3 +1,2 @@ export * from './color.js'; -export * from './id.js'; export * from './url.js'; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 69f5df7da..7ef51f9a6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -411,9 +411,6 @@ importers: '@logto/connector-kit': specifier: workspace:^ version: link:../../toolkit/connector-kit - '@logto/core-kit': - specifier: workspace:^ - version: link:../../toolkit/core-kit '@silverhand/essentials': specifier: ^2.5.0 version: 2.5.0 @@ -660,9 +657,9 @@ importers: '@logto/connector-kit': specifier: workspace:^ version: link:../../toolkit/connector-kit - '@logto/core-kit': + '@logto/shared': specifier: workspace:^ - version: link:../../toolkit/core-kit + version: link:../../shared '@silverhand/essentials': specifier: ^2.5.0 version: 2.5.0 @@ -2103,9 +2100,9 @@ importers: '@logto/connector-kit': specifier: workspace:^ version: link:../../toolkit/connector-kit - '@logto/core-kit': + '@logto/shared': specifier: workspace:^ - version: link:../../toolkit/core-kit + version: link:../../shared '@silverhand/essentials': specifier: ^2.5.0 version: 2.5.0 @@ -2780,6 +2777,9 @@ importers: '@logto/schemas': specifier: workspace:^ version: link:../schemas + '@logto/shared': + specifier: workspace:^ + version: link:../shared '@mdx-js/react': specifier: ^1.6.22 version: 1.6.22(react@18.2.0) @@ -2868,8 +2868,8 @@ importers: specifier: ^1.10.5 version: 1.11.6 deep-object-diff: - specifier: ^1.1.7 - version: 1.1.7 + specifier: ^1.1.9 + version: 1.1.9 deepmerge: specifier: ^4.2.2 version: 4.2.2 @@ -3519,6 +3519,9 @@ importers: '@logto/phrases-ui': specifier: workspace:^ version: link:../phrases-ui + '@logto/shared': + specifier: workspace:^ + version: link:../shared '@withtyped/server': specifier: ^0.8.1 version: 0.8.1 @@ -3583,12 +3586,6 @@ importers: packages/shared: dependencies: - '@logto/core-kit': - specifier: workspace:^ - version: link:../toolkit/core-kit - '@logto/schemas': - specifier: workspace:^ - version: link:../schemas '@silverhand/essentials': specifier: ^2.5.0 version: 2.5.0 @@ -3679,12 +3676,12 @@ importers: '@logto/language-kit': specifier: workspace:^ version: link:../language-kit + '@logto/shared': + specifier: workspace:^ + version: link:../../shared color: specifier: ^4.2.3 version: 4.2.3 - nanoid: - specifier: ^4.0.0 - version: 4.0.0 optionalDependencies: zod: specifier: ^3.20.2 @@ -10224,8 +10221,8 @@ packages: resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==} dev: true - /deep-object-diff@1.1.7: - resolution: {integrity: sha512-QkgBca0mL08P6HiOjoqvmm6xOAl2W6CT2+34Ljhg0OeFan8cwlcdq8jrLKsBBuUFAZLsN5b6y491KdKEoSo9lg==} + /deep-object-diff@1.1.9: + resolution: {integrity: sha512-Rn+RuwkmkDwCi2/oXOFS9Gsr5lJZu/yTGpK7wAaAIE75CC+LCGEZHpY6VQJa/RoJcrmaA/docWJZvYohlNkWPA==} dev: true /deepmerge@4.2.2: