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

chore: update workspace configs

This commit is contained in:
Gao Sun 2023-04-01 16:37:49 +08:00
parent 18ba35ce39
commit 79f3c44b62
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
20 changed files with 3864 additions and 165 deletions

View file

@ -5,6 +5,9 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"preinstall": "npx only-allow pnpm", "preinstall": "npx only-allow pnpm",
"connectors:sync": "cd packages/connectors && node templates/sync-to-current.js",
"connectors:update": "cd packages/connectors && node templates/sync-from-current.js",
"pnpm:devPreinstall": "pnpm connectors:sync",
"prepare": "if test \"$NODE_ENV\" != \"production\" && test \"$CI\" != \"true\" ; then husky install ; fi", "prepare": "if test \"$NODE_ENV\" != \"production\" && test \"$CI\" != \"true\" ; then husky install ; fi",
"prepack": "pnpm -r prepack", "prepack": "pnpm -r prepack",
"dev": "pnpm -r prepack && pnpm start:dev", "dev": "pnpm -r prepack && pnpm start:dev",

View file

@ -1,6 +1,6 @@
import crypto from 'node:crypto'; import crypto from 'node:crypto';
import { parseJson } from '@logto/connector-kit'; import { parseJsonObject } from '@logto/connector-kit';
import iconv from 'iconv-lite'; import iconv from 'iconv-lite';
import snakeCaseKeys from 'snakecase-keys'; import snakeCaseKeys from 'snakecase-keys';
@ -16,11 +16,12 @@ export const signingParameters: SigningParameters = (
parameters: AlipayNativeConfig & Record<string, string | undefined> parameters: AlipayNativeConfig & Record<string, string | undefined>
): Record<string, string> => { ): Record<string, string> => {
const { biz_content, privateKey, ...rest } = parameters; const { biz_content, privateKey, ...rest } = parameters;
const signParameters = snakeCaseKeys( const signParameters = snakeCaseKeys(
biz_content biz_content
? { ? {
...rest, ...rest,
bizContent: JSON.stringify(snakeCaseKeys(parseJson(biz_content))), bizContent: JSON.stringify(snakeCaseKeys(parseJsonObject(biz_content))),
} }
: rest : rest
); );

View file

@ -1,6 +1,6 @@
import crypto from 'node:crypto'; import crypto from 'node:crypto';
import { parseJson } from '@logto/connector-kit'; import { parseJsonObject } from '@logto/connector-kit';
import iconv from 'iconv-lite'; import iconv from 'iconv-lite';
import snakeCaseKeys from 'snakecase-keys'; import snakeCaseKeys from 'snakecase-keys';
@ -16,11 +16,12 @@ export const signingParameters: SigningParameters = (
parameters: AlipayConfig & Record<string, string | undefined> parameters: AlipayConfig & Record<string, string | undefined>
): Record<string, string> => { ): Record<string, string> => {
const { biz_content, privateKey, ...rest } = parameters; const { biz_content, privateKey, ...rest } = parameters;
const signParameters = snakeCaseKeys( const signParameters = snakeCaseKeys(
biz_content biz_content
? { ? {
...rest, ...rest,
bizContent: JSON.stringify(snakeCaseKeys(parseJson(biz_content))), bizContent: JSON.stringify(snakeCaseKeys(parseJsonObject(biz_content))),
} }
: rest : rest
); );

View file

@ -1,4 +1,4 @@
import { createHmac } from 'crypto'; import { createHmac } from 'node:crypto';
import { got } from 'got'; import { got } from 'got';

View file

@ -1,4 +1,4 @@
import { createHmac } from 'crypto'; import { createHmac } from 'node:crypto';
import { got } from 'got'; import { got } from 'got';

View file

@ -1,4 +1,4 @@
import path from 'path'; import path from 'node:path';
import type { AuthorizationCodeRequest, AuthorizationUrlRequest } from '@azure/msal-node'; import type { AuthorizationCodeRequest, AuthorizationUrlRequest } from '@azure/msal-node';
import { ConfidentialClientApplication, CryptoProvider } from '@azure/msal-node'; import { ConfidentialClientApplication, CryptoProvider } from '@azure/msal-node';

View file

@ -88,7 +88,6 @@ export const getAccessToken = async (
const getUserInfo = const getUserInfo =
(getConfig: GetConnectorConfig): GetUserInfo => (getConfig: GetConnectorConfig): GetUserInfo =>
// eslint-disable-next-line complexity
async (data) => { async (data) => {
const { code, redirectUri } = await authorizationCallbackHandler(data); const { code, redirectUri } = await authorizationCallbackHandler(data);
const config = await getConfig(defaultMetadata.id); const config = await getConfig(defaultMetadata.id);

View file

@ -1,5 +1,5 @@
import fs from 'fs/promises'; import fs from 'node:fs/promises';
import path from 'path'; import path from 'node:path';
import type { import type {
GetConnectorConfig, GetConnectorConfig,

View file

@ -1,5 +1,5 @@
import fs from 'fs/promises'; import fs from 'node:fs/promises';
import path from 'path'; import path from 'node:path';
import type { import type {
GetConnectorConfig, GetConnectorConfig,

View file

@ -1,5 +1,5 @@
import fs from 'fs/promises'; import fs from 'node:fs/promises';
import path from 'path'; import path from 'node:path';
import type { import type {
GetConnectorConfig, GetConnectorConfig,

View file

@ -1,4 +1,4 @@
import { randomUUID } from 'crypto'; import { randomUUID } from 'node:crypto';
import type { import type {
GetAuthorizationUri, GetAuthorizationUri,

View file

@ -1,16 +1,14 @@
import type {
GetAuthorizationUri,
GetUserInfo,
SocialConnector,
CreateConnector,
GetConnectorConfig,
} from '@logto/connector-kit';
import { import {
type GetAuthorizationUri,
type GetUserInfo,
type SocialConnector,
type CreateConnector,
type GetConnectorConfig,
parseJsonObject,
ConnectorError, ConnectorError,
ConnectorErrorCodes, ConnectorErrorCodes,
validateConfig, validateConfig,
ConnectorType, ConnectorType,
parseJson,
} from '@logto/connector-kit'; } from '@logto/connector-kit';
import { assert, pick } from '@silverhand/essentials'; import { assert, pick } from '@silverhand/essentials';
import { got, HTTPError } from 'got'; import { got, HTTPError } from 'got';
@ -74,7 +72,7 @@ const getUserInfo =
timeout: { request: defaultTimeout }, timeout: { request: defaultTimeout },
}); });
return userProfileMapping(parseJson(httpResponse.body), parsedConfig.profileMap); return userProfileMapping(parseJsonObject(httpResponse.body), parsedConfig.profileMap);
} catch (error: unknown) { } catch (error: unknown) {
if (error instanceof HTTPError) { if (error instanceof HTTPError) {
throw new ConnectorError(ConnectorErrorCodes.General, JSON.stringify(error.response.body)); throw new ConnectorError(ConnectorErrorCodes.General, JSON.stringify(error.response.body));

View file

@ -59,7 +59,8 @@ const accessTokenResponseHandler = async (
}; };
export const userProfileMapping = ( export const userProfileMapping = (
originUserProfile: Record<string, unknown>, // eslint-disable-next-line @typescript-eslint/ban-types
originUserProfile: object,
keyMapping: ProfileMap keyMapping: ProfileMap
) => { ) => {
const keyMap = new Map( const keyMap = new Map(

View file

@ -59,7 +59,6 @@ const getAuthorizationUri =
const getUserInfo = const getUserInfo =
(getConfig: GetConnectorConfig): GetUserInfo => (getConfig: GetConnectorConfig): GetUserInfo =>
// eslint-disable-next-line complexity
async (data, getSession) => { async (data, getSession) => {
const config = await getConfig(defaultMetadata.id); const config = await getConfig(defaultMetadata.id);
validateConfig<OidcConfig>(config, oidcConfigGuard); validateConfig<OidcConfig>(config, oidcConfigGuard);

View file

@ -65,15 +65,18 @@ const sendMessage =
const parseContents = (contents: string, contentType: ContextType) => { const parseContents = (contents: string, contentType: ContextType) => {
switch (contentType) { switch (contentType) {
case ContextType.Text: case ContextType.Text: {
return { text: contents }; return { text: contents };
case ContextType.Html: }
case ContextType.Html: {
return { html: contents }; return { html: contents };
default: }
default: {
throw new ConnectorError( throw new ConnectorError(
ConnectorErrorCodes.InvalidConfig, ConnectorErrorCodes.InvalidConfig,
'`contentType` should be ContextType.' '`contentType` should be ContextType.'
); );
}
} }
}; };

View file

@ -1,5 +1,5 @@
import type { BinaryToTextEncoding } from 'crypto'; import type { BinaryToTextEncoding } from 'node:crypto';
import crypto from 'crypto'; import crypto from 'node:crypto';
import { got } from 'got'; import { got } from 'got';
@ -38,7 +38,7 @@ export function isSmsErrorResponse(response: unknown): response is TencentErrorR
return result.success; return result.success;
} }
export function sendSmsRequest( export async function sendSmsRequest(
templateId: string, templateId: string,
templateParameters: string[], templateParameters: string[],
phoneNumber: string, phoneNumber: string,

View file

@ -22,7 +22,7 @@
"test:only": "NODE_OPTIONS=--experimental-vm-modules jest", "test:only": "NODE_OPTIONS=--experimental-vm-modules jest",
"test": "pnpm build:test && pnpm test:only", "test": "pnpm build:test && pnpm test:only",
"test:ci": "pnpm test:only --silent --coverage", "test:ci": "pnpm test:only --silent --coverage",
"prepack": "pnpm build" "prepublishOnly": "pnpm build"
}, },
"dependencies": { "dependencies": {
"@logto/connector-kit": "workspace:^", "@logto/connector-kit": "workspace:^",

View file

@ -16,13 +16,22 @@ export const parseJson = (
jsonString: string, jsonString: string,
errorCode: ConnectorErrorCodes = ConnectorErrorCodes.InvalidResponse, errorCode: ConnectorErrorCodes = ConnectorErrorCodes.InvalidResponse,
errorPayload?: unknown errorPayload?: unknown
) => { ): unknown => {
try { try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return JSON.parse(jsonString); return JSON.parse(jsonString);
} catch { } catch {
throw new ConnectorError(errorCode, errorPayload ?? jsonString); throw new ConnectorError(errorCode, errorPayload ?? jsonString);
} }
}; };
export const parseJsonObject = (...args: Parameters<typeof parseJson>) => {
const parsed = parseJson(...args);
if (!(parsed !== null && typeof parsed === 'object')) {
throw new ConnectorError(ConnectorErrorCodes.InvalidResponse, parsed);
}
return parsed;
};
export const mockSmsVerificationCodeFileName = 'logto_mock_verification_code_record.txt'; export const mockSmsVerificationCodeFileName = 'logto_mock_verification_code_record.txt';

File diff suppressed because it is too large Load diff

View file

@ -1,3 +1,5 @@
packages: packages:
- packages/* - packages/*
- packages/toolkit/* - packages/toolkit/*
- packages/connectors/*
- "!packages/connectors/templates"