0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-03-31 22:51:25 -05:00

Merge pull request #3676 from logto-io/gao-reorg-pacakges

refactor: reorg packages
This commit is contained in:
Gao Sun 2023-04-07 01:22:17 +08:00 committed by GitHub
commit 9847fdc098
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
112 changed files with 230 additions and 162 deletions

View file

@ -0,0 +1,9 @@
---
"@logto/shared": major
"@logto/core-kit": major
"@logto/connector-kit": patch
---
- connector-kit: add `DemoConnector` type and demo connector ids
- core-kit: remove nanoid utils, add tenant model utils
- shared: remove models, add database types and universal export

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

@ -6,10 +6,10 @@ import { got } from 'got';
import type { Interaction } from './hook.js';
const { jest } = import.meta;
const { mockEsmDefault, mockEsmWithActual } = createMockUtils(jest);
const { mockEsmWithActual } = createMockUtils(jest);
const nanoIdMock = 'mockId';
await mockEsmWithActual('@logto/core-kit', () => ({
await mockEsmWithActual('@logto/shared', () => ({
// eslint-disable-next-line unicorn/consistent-function-scoping
buildIdGenerator: () => () => nanoIdMock,
generateStandardId: () => nanoIdMock,

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

@ -10,7 +10,7 @@ const { jest } = import.meta;
const { mockEsmWithActual } = createMockUtils(jest);
const nanoIdMock = 'mockId';
await mockEsmWithActual('@logto/core-kit', () => ({
await mockEsmWithActual('@logto/shared', () => ({
// eslint-disable-next-line unicorn/consistent-function-scoping
buildIdGenerator: () => () => nanoIdMock,
generateStandardId: () => nanoIdMock,

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

@ -11,7 +11,7 @@ const { mockEsmWithActual } = createMockUtils(jest);
const findApplicationById = jest.fn(async () => mockApplication);
const deleteApplicationById = jest.fn();
await mockEsmWithActual('@logto/core-kit', () => ({
await mockEsmWithActual('@logto/shared', () => ({
// eslint-disable-next-line unicorn/consistent-function-scoping
buildIdGenerator: () => () => 'randomId',
generateStandardId: () => 'randomId',

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

@ -47,7 +47,7 @@ const libraries = {
},
};
mockEsm('@logto/core-kit', () => ({
mockEsm('@logto/shared', () => ({
// eslint-disable-next-line unicorn/consistent-function-scoping
buildIdGenerator: () => () => 'randomId',
}));

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

@ -4,6 +4,6 @@ const { mockEsmWithActual } = createMockUtils(import.meta.jest);
export const mockId = 'mockId';
export const mockStandardId = async () =>
mockEsmWithActual('@logto/core-kit', () => ({
mockEsmWithActual('@logto/shared', () => ({
generateStandardId: () => mockId,
}));

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

2
packages/shared/src/node/env/index.ts vendored Normal file
View file

@ -0,0 +1,2 @@
export { default as UrlSet } from './UrlSet.js';
export { default as GlobalValues } from './GlobalValues.js';

View file

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

View file

@ -0,0 +1,2 @@
export * from './database/index.js';
export * from './utils/index.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,
]);

Some files were not shown because too many files have changed in this diff Show more