0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

refactor: reorg packages

update `@logto/shared` to a non-business package
and put business components into `@logto/*kit`.
This commit is contained in:
Gao Sun 2023-04-04 16:23:25 +08:00
parent 964e078c3f
commit aa203308f0
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
96 changed files with 196 additions and 148 deletions

View file

@ -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"
},

View file

@ -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';

View file

@ -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') {

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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: {

View file

@ -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"
},

View file

@ -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",

View file

@ -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';

View file

@ -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"
},

View file

@ -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';

View file

@ -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",

View file

@ -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';

View file

@ -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';
<Step
title="Add dependencies"

View file

@ -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';
<Step
title="添加依赖"

View file

@ -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';
<Step
title="Add Logto SDK as a dependency"

View file

@ -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';
<Step
title="将 Logto SDK 添加至依赖"

View file

@ -1,4 +1,4 @@
import { appInsightsReact } from '@logto/app-insights/lib/react';
import { appInsightsReact } from '@logto/app-insights/react';
import type { AdminConsoleKey } from '@logto/phrases';
import { useEffect, useState } from 'react';
import { Helmet } from 'react-helmet';

View file

@ -1,11 +1,13 @@
import { HTTPError, type Options } from 'ky';
import type { KyInstance } from 'ky/distribution/types/ky';
import type ky from 'ky';
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import type { BareFetcher } from 'swr';
import { RequestError } from './use-api';
type KyInstance = typeof ky;
type WithTotalNumber<T> = Array<Awaited<T> | number>;
type useSwrFetcherHook = {

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -1,6 +1,7 @@
{
"extends": "@silverhand/ts-config-react/tsconfig.base",
"compilerOptions": {
"moduleResolution": "bundler",
"baseUrl": "./",
"paths": {
"@/*": ["./src/*"],

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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"
}

View file

@ -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<K> = undefined extends K
? ZodOptional<ZodType<Exclude<K, undefined>>>
: ZodType<K>;
@ -12,12 +15,6 @@ export type Guard<T extends Record<string, unknown>> = ZodObject<{
[key in keyof T]: ZodType<T[key]>;
}>;
export type SchemaValuePrimitive = string | number | boolean | undefined;
export type SchemaValue = SchemaValuePrimitive | Record<string, unknown> | unknown[] | null;
export type SchemaLike<Key extends string = string> = {
[key in Key]: SchemaValue;
};
export type GeneratedSchema<
CreateSchema extends SchemaLike,
Schema extends CreateSchema

View file

@ -1,4 +1,4 @@
import { generateStandardId } from '@logto/core-kit';
import { generateStandardId } from '@logto/shared/universal';
import type {
Application,

View file

@ -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';

View file

@ -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';

View file

@ -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.

View file

@ -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",

View file

@ -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';

View file

@ -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;

View file

@ -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 = <T>(value: T, buildSql: (value: Exclude<T, Falsy>) => SqlSqlToken) =>
notFalsy(value) ? buildSql(value) : sql``;

View file

@ -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<string, unknown> | unknown[] | null;
export type SchemaLike<Key extends string = string> = {
[key in Key]: SchemaValue;
};
export type Table = { table: string; fields: Record<string, string> };
export type FieldIdentifiers<Key extends string | number | symbol> = {
[key in Key]: IdentifierSqlToken;

View file

@ -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';

View file

@ -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,
];

View file

@ -1,2 +0,0 @@
export * from './tenant.js';
export * from './connector.js';

View file

@ -0,0 +1 @@
export { default as findPackage } from './find-package.js';

View file

@ -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';

View file

@ -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<typeof customAlphabet>;
/**
* 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<typeof customAlphabet>;
};
export const buildIdGenerator: BuildIdGenerator = (size: number, includingUppercase = false) =>
customAlphabet(includingUppercase ? alphabet : lowercaseAlphabet, size);
export const generateStandardId = buildIdGenerator(21);

View file

@ -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';

View file

@ -259,3 +259,15 @@ export type GetUserInfo = (
data: unknown,
getSession: GetSession
) => Promise<SocialUserInfo & Record<string, string | boolean | number | undefined>>;
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,
]);

View file

@ -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",

View file

@ -1,3 +1,4 @@
export * from './utils/index.js';
export * from './regex.js';
export * from './scope.js';
export * from './models/index.js';

View file

@ -0,0 +1 @@
export * from './tenant.js';

View file

@ -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}`;

View file

@ -1,6 +0,0 @@
import { customAlphabet } from 'nanoid';
const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
export const buildIdGenerator = (size: number) => customAlphabet(alphabet, size);
export const generateStandardId = buildIdGenerator(21);

View file

@ -1,3 +1,2 @@
export * from './color.js';
export * from './id.js';
export * from './url.js';

View file

@ -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: