mirror of
https://github.com/logto-io/logto.git
synced 2025-01-06 20:40:08 -05:00
feat(toolkit): define optional keys for connector.getUserInfo (#2716)
This commit is contained in:
parent
61f4e7fd2d
commit
e38cd36579
8 changed files with 18 additions and 23 deletions
|
@ -1,21 +1,10 @@
|
|||
import type { AllConnector, CreateConnector, VerificationCodeType } from '@logto/connector-kit';
|
||||
import type { Connector } from '@logto/schemas';
|
||||
import { z } from 'zod';
|
||||
|
||||
export { ConnectorType } from '@logto/schemas';
|
||||
|
||||
export type TemplateType = VerificationCodeType;
|
||||
|
||||
export const socialUserInfoGuard = z.object({
|
||||
id: z.string(),
|
||||
email: z.string().optional(),
|
||||
phone: z.string().optional(),
|
||||
name: z.string().optional(),
|
||||
avatar: z.string().optional(),
|
||||
});
|
||||
|
||||
export type SocialUserInfo = z.infer<typeof socialUserInfoGuard>;
|
||||
|
||||
/**
|
||||
* Dynamic loaded connector type.
|
||||
*/
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import type { GetSession } from '@logto/connector-kit';
|
||||
import type { GetSession, SocialUserInfo } from '@logto/connector-kit';
|
||||
import { socialUserInfoGuard } from '@logto/connector-kit';
|
||||
import type { User } from '@logto/schemas';
|
||||
import { ConnectorType } from '@logto/schemas';
|
||||
import type { Nullable } from '@silverhand/essentials';
|
||||
|
@ -6,8 +7,6 @@ import type { InteractionResults } from 'oidc-provider';
|
|||
import { z } from 'zod';
|
||||
|
||||
import { getLogtoConnectorById } from '#src/connectors/index.js';
|
||||
import type { SocialUserInfo } from '#src/connectors/types.js';
|
||||
import { socialUserInfoGuard } from '#src/connectors/types.js';
|
||||
import RequestError from '#src/errors/RequestError/index.js';
|
||||
import { findUserByEmail, findUserByPhone } from '#src/queries/user.js';
|
||||
import assertThat from '#src/utils/assert-that.js';
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import { socialUserInfoGuard } from '@logto/connector-kit';
|
||||
import { emailRegEx, phoneRegEx, validateRedirectUrl } from '@logto/core-kit';
|
||||
import { eventGuard, profileGuard, InteractionEvent } from '@logto/schemas';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { socialUserInfoGuard } from '#src/connectors/types.js';
|
||||
|
||||
// Passcode Send Route Payload Guard
|
||||
export const sendPasscodePayloadGuard = z.union([
|
||||
z.object({
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import type { SocialUserInfo } from '@logto/connector-kit';
|
||||
import type {
|
||||
UsernamePasswordPayload,
|
||||
EmailPasswordPayload,
|
||||
|
@ -8,8 +9,6 @@ import type {
|
|||
} from '@logto/schemas';
|
||||
import type { z } from 'zod';
|
||||
|
||||
import type { SocialUserInfo } from '#src/connectors/types.js';
|
||||
|
||||
import type {
|
||||
sendPasscodePayloadGuard,
|
||||
socialAuthorizationUrlPayloadGuard,
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import type { ConnectorSession } from '@logto/connector-kit';
|
||||
import type { ConnectorSession, SocialUserInfo } from '@logto/connector-kit';
|
||||
import type { SocialConnectorPayload } from '@logto/schemas';
|
||||
import { ConnectorType } from '@logto/schemas';
|
||||
import type { Provider } from 'oidc-provider';
|
||||
|
||||
import { getLogtoConnectorById } from '#src/connectors/index.js';
|
||||
import type { SocialUserInfo } from '#src/connectors/types.js';
|
||||
import { getUserInfoByAuthCode } from '#src/libraries/social.js';
|
||||
import type { WithLogContext } from '#src/middleware/koa-audit-log.js';
|
||||
import {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import type { SocialUserInfo } from '@logto/connector-kit';
|
||||
import type { CreateUser, User } from '@logto/schemas';
|
||||
import { ConnectorType } from '@logto/schemas';
|
||||
import { createMockUtils } from '@logto/shared/esm';
|
||||
|
@ -9,7 +10,6 @@ import {
|
|||
mockUser,
|
||||
mockUserResponse,
|
||||
} from '#src/__mocks__/index.js';
|
||||
import type { SocialUserInfo } from '#src/connectors/types.js';
|
||||
import { createMockProvider } from '#src/test-utils/oidc-provider.js';
|
||||
import { createRequester } from '#src/utils/test-utils.js';
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { ConnectorType } from '@logto/connector-kit';
|
||||
import type { SocialUserInfo } from '@logto/connector-kit';
|
||||
import type { User } from '@logto/schemas';
|
||||
import { Provider } from 'oidc-provider';
|
||||
|
||||
import { mockLogtoConnectorList, mockSignInExperience, mockUser } from '#src/__mocks__/index.js';
|
||||
import { getLogtoConnectorById } from '#src/connectors/index.js';
|
||||
import type { SocialUserInfo } from '#src/connectors/types.js';
|
||||
import RequestError from '#src/errors/RequestError/index.js';
|
||||
import { createRequester } from '#src/utils/test-utils.js';
|
||||
|
||||
|
|
|
@ -171,7 +171,17 @@ export type GetAuthorizationUri = (
|
|||
setSession?: SetSession
|
||||
) => Promise<string>;
|
||||
|
||||
export const socialUserInfoGuard = z.object({
|
||||
id: z.string(),
|
||||
email: z.string().optional(),
|
||||
phone: z.string().optional(),
|
||||
name: z.string().optional(),
|
||||
avatar: z.string().optional(),
|
||||
});
|
||||
|
||||
export type SocialUserInfo = z.infer<typeof socialUserInfoGuard>;
|
||||
|
||||
export type GetUserInfo = (
|
||||
data: unknown,
|
||||
getSession?: GetSession
|
||||
) => Promise<{ id: string } & Record<string, string | boolean | number | undefined>>;
|
||||
) => Promise<SocialUserInfo & Record<string, string | boolean | number | undefined>>;
|
||||
|
|
Loading…
Reference in a new issue