File tree 20 files changed +4713
-1014
lines changed
connector-alipay-native/src
connector-mock-email-alternative/src
connector-mock-social/src
connector-tencent-sms/src
toolkit/connector-kit/src
20 files changed +4713
-1014
lines changed Original file line number Diff line number Diff line change 5
5
"type" : " module" ,
6
6
"scripts" : {
7
7
"preinstall" : " npx only-allow pnpm" ,
8
+ "connectors:sync" : " cd packages/connectors && node templates/sync-to-current.js" ,
9
+ "connectors:update" : " cd packages/connectors && node templates/sync-from-current.js" ,
10
+ "pnpm:devPreinstall" : " pnpm connectors:sync" ,
8
11
"prepare" : " if test \" $NODE_ENV\" != \" production\" && test \" $CI\" != \" true\" ; then husky install ; fi" ,
9
12
"prepack" : " pnpm -r prepack" ,
10
13
"dev" : " pnpm -r prepack && pnpm start:dev" ,
Original file line number Diff line number Diff line change 1
1
import crypto from 'node:crypto' ;
2
2
3
- import { parseJson } from '@logto/connector-kit' ;
3
+ import { parseJsonObject } from '@logto/connector-kit' ;
4
4
import iconv from 'iconv-lite' ;
5
5
import snakeCaseKeys from 'snakecase-keys' ;
6
6
@@ -16,11 +16,12 @@ export const signingParameters: SigningParameters = (
16
16
parameters : AlipayNativeConfig & Record < string , string | undefined >
17
17
) : Record < string , string > => {
18
18
const { biz_content, privateKey, ...rest } = parameters ;
19
+
19
20
const signParameters = snakeCaseKeys (
20
21
biz_content
21
22
? {
22
23
...rest ,
23
- bizContent : JSON . stringify ( snakeCaseKeys ( parseJson ( biz_content ) ) ) ,
24
+ bizContent : JSON . stringify ( snakeCaseKeys ( parseJsonObject ( biz_content ) ) ) ,
24
25
}
25
26
: rest
26
27
) ;
Original file line number Diff line number Diff line change 1
1
import crypto from 'node:crypto' ;
2
2
3
- import { parseJson } from '@logto/connector-kit' ;
3
+ import { parseJsonObject } from '@logto/connector-kit' ;
4
4
import iconv from 'iconv-lite' ;
5
5
import snakeCaseKeys from 'snakecase-keys' ;
6
6
@@ -16,11 +16,12 @@ export const signingParameters: SigningParameters = (
16
16
parameters : AlipayConfig & Record < string , string | undefined >
17
17
) : Record < string , string > => {
18
18
const { biz_content, privateKey, ...rest } = parameters ;
19
+
19
20
const signParameters = snakeCaseKeys (
20
21
biz_content
21
22
? {
22
23
...rest ,
23
- bizContent : JSON . stringify ( snakeCaseKeys ( parseJson ( biz_content ) ) ) ,
24
+ bizContent : JSON . stringify ( snakeCaseKeys ( parseJsonObject ( biz_content ) ) ) ,
24
25
}
25
26
: rest
26
27
) ;
Original file line number Diff line number Diff line change 1
- import { createHmac } from 'crypto' ;
1
+ import { createHmac } from 'node: crypto' ;
2
2
3
3
import { got } from 'got' ;
4
4
Original file line number Diff line number Diff line change 1
- import { createHmac } from 'crypto' ;
1
+ import { createHmac } from 'node: crypto' ;
2
2
3
3
import { got } from 'got' ;
4
4
Original file line number Diff line number Diff line change 1
- import path from 'path' ;
1
+ import path from 'node: path' ;
2
2
3
3
import type { AuthorizationCodeRequest , AuthorizationUrlRequest } from '@azure/msal-node' ;
4
4
import { ConfidentialClientApplication , CryptoProvider } from '@azure/msal-node' ;
Original file line number Diff line number Diff line change @@ -88,7 +88,6 @@ export const getAccessToken = async (
88
88
89
89
const getUserInfo =
90
90
( getConfig : GetConnectorConfig ) : GetUserInfo =>
91
- // eslint-disable-next-line complexity
92
91
async ( data ) => {
93
92
const { code, redirectUri } = await authorizationCallbackHandler ( data ) ;
94
93
const config = await getConfig ( defaultMetadata . id ) ;
Original file line number Diff line number Diff line change 1
- import fs from 'fs/promises' ;
2
- import path from 'path' ;
1
+ import fs from 'node: fs/promises' ;
2
+ import path from 'node: path' ;
3
3
4
4
import type {
5
5
GetConnectorConfig ,
Original file line number Diff line number Diff line change 1
- import fs from 'fs/promises' ;
2
- import path from 'path' ;
1
+ import fs from 'node: fs/promises' ;
2
+ import path from 'node: path' ;
3
3
4
4
import type {
5
5
GetConnectorConfig ,
Original file line number Diff line number Diff line change 1
- import fs from 'fs/promises' ;
2
- import path from 'path' ;
1
+ import fs from 'node: fs/promises' ;
2
+ import path from 'node: path' ;
3
3
4
4
import type {
5
5
GetConnectorConfig ,
Original file line number Diff line number Diff line change 1
- import { randomUUID } from 'crypto' ;
1
+ import { randomUUID } from 'node: crypto' ;
2
2
3
3
import type {
4
4
GetAuthorizationUri ,
Original file line number Diff line number Diff line change 1
- import type {
2
- GetAuthorizationUri ,
3
- GetUserInfo ,
4
- SocialConnector ,
5
- CreateConnector ,
6
- GetConnectorConfig ,
7
- } from '@logto/connector-kit' ;
8
1
import {
2
+ type GetAuthorizationUri ,
3
+ type GetUserInfo ,
4
+ type SocialConnector ,
5
+ type CreateConnector ,
6
+ type GetConnectorConfig ,
7
+ parseJsonObject ,
9
8
ConnectorError ,
10
9
ConnectorErrorCodes ,
11
10
validateConfig ,
12
11
ConnectorType ,
13
- parseJson ,
14
12
} from '@logto/connector-kit' ;
15
13
import { assert , pick } from '@silverhand/essentials' ;
16
14
import { got , HTTPError } from 'got' ;
@@ -74,7 +72,7 @@ const getUserInfo =
74
72
timeout : { request : defaultTimeout } ,
75
73
} ) ;
76
74
77
- return userProfileMapping ( parseJson ( httpResponse . body ) , parsedConfig . profileMap ) ;
75
+ return userProfileMapping ( parseJsonObject ( httpResponse . body ) , parsedConfig . profileMap ) ;
78
76
} catch ( error : unknown ) {
79
77
if ( error instanceof HTTPError ) {
80
78
throw new ConnectorError ( ConnectorErrorCodes . General , JSON . stringify ( error . response . body ) ) ;
Original file line number Diff line number Diff line change @@ -59,7 +59,8 @@ const accessTokenResponseHandler = async (
59
59
} ;
60
60
61
61
export const userProfileMapping = (
62
- originUserProfile : Record < string , unknown > ,
62
+ // eslint-disable-next-line @typescript-eslint/ban-types
63
+ originUserProfile : object ,
63
64
keyMapping : ProfileMap
64
65
) => {
65
66
const keyMap = new Map (
Original file line number Diff line number Diff line change @@ -59,7 +59,6 @@ const getAuthorizationUri =
59
59
60
60
const getUserInfo =
61
61
( getConfig : GetConnectorConfig ) : GetUserInfo =>
62
- // eslint-disable-next-line complexity
63
62
async ( data , getSession ) => {
64
63
const config = await getConfig ( defaultMetadata . id ) ;
65
64
validateConfig < OidcConfig > ( config , oidcConfigGuard ) ;
Original file line number Diff line number Diff line change @@ -65,15 +65,18 @@ const sendMessage =
65
65
66
66
const parseContents = ( contents : string , contentType : ContextType ) => {
67
67
switch ( contentType ) {
68
- case ContextType . Text :
68
+ case ContextType . Text : {
69
69
return { text : contents } ;
70
- case ContextType . Html :
70
+ }
71
+ case ContextType . Html : {
71
72
return { html : contents } ;
72
- default :
73
+ }
74
+ default : {
73
75
throw new ConnectorError (
74
76
ConnectorErrorCodes . InvalidConfig ,
75
77
'`contentType` should be ContextType.'
76
78
) ;
79
+ }
77
80
}
78
81
} ;
79
82
Original file line number Diff line number Diff line change 1
- import type { BinaryToTextEncoding } from 'crypto' ;
2
- import crypto from 'crypto' ;
1
+ import type { BinaryToTextEncoding } from 'node: crypto' ;
2
+ import crypto from 'node: crypto' ;
3
3
4
4
import { got } from 'got' ;
5
5
@@ -38,7 +38,7 @@ export function isSmsErrorResponse(response: unknown): response is TencentErrorR
38
38
return result . success ;
39
39
}
40
40
41
- export function sendSmsRequest (
41
+ export async function sendSmsRequest (
42
42
templateId : string ,
43
43
templateParameters : string [ ] ,
44
44
phoneNumber : string ,
Original file line number Diff line number Diff line change 22
22
"test:only" : " NODE_OPTIONS=--experimental-vm-modules jest" ,
23
23
"test" : " pnpm build:test && pnpm test:only" ,
24
24
"test:ci" : " pnpm test:only --silent --coverage" ,
25
- "prepack " : " pnpm build"
25
+ "prepublishOnly " : " pnpm build"
26
26
},
27
27
"dependencies" : {
28
28
"@logto/connector-kit" : " workspace:^" ,
Original file line number Diff line number Diff line change @@ -16,13 +16,22 @@ export const parseJson = (
16
16
jsonString : string ,
17
17
errorCode : ConnectorErrorCodes = ConnectorErrorCodes . InvalidResponse ,
18
18
errorPayload ?: unknown
19
- ) => {
19
+ ) : unknown => {
20
20
try {
21
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
22
21
return JSON . parse ( jsonString ) ;
23
22
} catch {
24
23
throw new ConnectorError ( errorCode , errorPayload ?? jsonString ) ;
25
24
}
26
25
} ;
27
26
27
+ export const parseJsonObject = ( ...args : Parameters < typeof parseJson > ) => {
28
+ const parsed = parseJson ( ...args ) ;
29
+
30
+ if ( ! ( parsed !== null && typeof parsed === 'object' ) ) {
31
+ throw new ConnectorError ( ConnectorErrorCodes . InvalidResponse , parsed ) ;
32
+ }
33
+
34
+ return parsed ;
35
+ } ;
36
+
28
37
export const mockSmsVerificationCodeFileName = 'logto_mock_verification_code_record.txt' ;
You can’t perform that action at this time.
0 commit comments