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",
"scripts": {
"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",
"prepack": "pnpm -r prepack",
"dev": "pnpm -r prepack && pnpm start:dev",

View file

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

View file

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

View file

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

View file

@ -1,4 +1,4 @@
import { createHmac } from 'crypto';
import { createHmac } from 'node:crypto';
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 { ConfidentialClientApplication, CryptoProvider } from '@azure/msal-node';

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -16,13 +16,22 @@ export const parseJson = (
jsonString: string,
errorCode: ConnectorErrorCodes = ConnectorErrorCodes.InvalidResponse,
errorPayload?: unknown
) => {
): unknown => {
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return JSON.parse(jsonString);
} catch {
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';

File diff suppressed because it is too large Load diff

View file

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