@logto/connector-discord 1.0.0-beta.18 → 1.0.0-beta.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { ConnectorPlatform, parseJson, ConnectorError, ConnectorErrorCodes, ConnectorType, validateConfig } from '@logto/connector-kit';
1
+ import { ConnectorPlatform, parseJson, ConnectorError, ConnectorErrorCodes, ConnectorType, validateConfig, socialUserInfoGuard } from '@logto/connector-kit';
2
2
  import { got, HTTPError } from 'got';
3
3
  import { z } from 'zod';
4
4
 
@@ -54,6 +54,12 @@ const defaultMetadata = {
54
54
  };
55
55
  const defaultTimeout = 5000;
56
56
 
57
+ const nullishToUndefined = (input) => {
58
+ if (!input) {
59
+ return;
60
+ }
61
+ return input;
62
+ };
57
63
  const discordConfigGuard = z.object({
58
64
  clientId: z.string(),
59
65
  clientSecret: z.string(),
@@ -66,10 +72,10 @@ const accessTokenResponseGuard = z.object({
66
72
  });
67
73
  const userInfoResponseGuard = z.object({
68
74
  id: z.string(),
69
- username: z.string().optional(),
70
- avatar: z.string().optional(),
71
- email: z.string().optional(),
72
- verified: z.boolean().optional(),
75
+ username: z.string().nullish().transform(nullishToUndefined),
76
+ avatar: z.string().nullish().transform(nullishToUndefined),
77
+ email: z.string().nullish().transform(nullishToUndefined),
78
+ verified: z.boolean().nullish().transform(nullishToUndefined),
73
79
  });
74
80
  z.object({
75
81
  error: z.string(),
@@ -114,7 +120,9 @@ const getAccessToken = async (config, codeObject) => {
114
120
  assert(accessToken, new ConnectorError(ConnectorErrorCodes.SocialAuthCodeInvalid));
115
121
  return { accessToken };
116
122
  };
117
- const getUserInfo = (getConfig) => async (data) => {
123
+ const getUserInfo = (getConfig) =>
124
+ // eslint-disable-next-line complexity
125
+ async (data) => {
118
126
  const { code, redirectUri } = await authorizationCallbackHandler(data);
119
127
  const config = await getConfig(defaultMetadata.id);
120
128
  validateConfig(config, discordConfigGuard);
@@ -131,13 +139,17 @@ const getUserInfo = (getConfig) => async (data) => {
131
139
  throw new ConnectorError(ConnectorErrorCodes.InvalidResponse, result.error);
132
140
  }
133
141
  const { id, username: name, avatar, email, verified } = result.data;
134
- return {
142
+ const rawUserInfo = {
135
143
  id,
136
144
  name,
137
145
  avatar: conditional(avatar && `https://cdn.discordapp.com/avatars/${id}/${avatar}`),
138
- email: conditional(email),
139
- email_verified: verified,
146
+ email: conditional(verified && email),
140
147
  };
148
+ const userInfoResult = socialUserInfoGuard.safeParse(rawUserInfo);
149
+ if (!userInfoResult.success) {
150
+ throw new ConnectorError(ConnectorErrorCodes.InvalidResponse, userInfoResult.error);
151
+ }
152
+ return userInfoResult.data;
141
153
  }
142
154
  catch (error) {
143
155
  if (error instanceof HTTPError) {
package/lib/types.d.ts CHANGED
@@ -29,10 +29,10 @@ export declare const accessTokenResponseGuard: z.ZodObject<{
29
29
  export type AccessTokenResponse = z.infer<typeof accessTokenResponseGuard>;
30
30
  export declare const userInfoResponseGuard: z.ZodObject<{
31
31
  id: z.ZodString;
32
- username: z.ZodOptional<z.ZodString>;
33
- avatar: z.ZodOptional<z.ZodString>;
34
- email: z.ZodOptional<z.ZodString>;
35
- verified: z.ZodOptional<z.ZodBoolean>;
32
+ username: z.ZodEffects<z.ZodNullable<z.ZodOptional<z.ZodString>>, string | undefined, string | null | undefined>;
33
+ avatar: z.ZodEffects<z.ZodNullable<z.ZodOptional<z.ZodString>>, string | undefined, string | null | undefined>;
34
+ email: z.ZodEffects<z.ZodNullable<z.ZodOptional<z.ZodString>>, string | undefined, string | null | undefined>;
35
+ verified: z.ZodEffects<z.ZodNullable<z.ZodOptional<z.ZodBoolean>>, boolean | undefined, boolean | null | undefined>;
36
36
  }, "strip", z.ZodTypeAny, {
37
37
  username?: string | undefined;
38
38
  avatar?: string | undefined;
@@ -40,10 +40,10 @@ export declare const userInfoResponseGuard: z.ZodObject<{
40
40
  verified?: boolean | undefined;
41
41
  id: string;
42
42
  }, {
43
- username?: string | undefined;
44
- avatar?: string | undefined;
45
- email?: string | undefined;
46
- verified?: boolean | undefined;
43
+ username?: string | null | undefined;
44
+ avatar?: string | null | undefined;
45
+ email?: string | null | undefined;
46
+ verified?: boolean | null | undefined;
47
47
  id: string;
48
48
  }>;
49
49
  export type UserInfoResponse = z.infer<typeof userInfoResponseGuard>;
package/logo.svg CHANGED
@@ -1,4 +1,4 @@
1
- <svg width="34" height="34" viewBox="0 0 34 34" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <path d="M0.333252 7.00001C0.333252 3.31811 3.31804 0.333344 6.99997 0.333344H27.0001C30.6821 0.333344 33.6668 3.31811 33.6668 7.00001V27C33.6668 30.6819 30.6821 33.6667 27.0001 33.6667H6.99997C3.31804 33.6667 0.333252 30.6819 0.333252 27V7.00001Z" fill="#5865F2"/>
3
- <path d="M25.0861 10.141C23.5989 9.45859 22.0041 8.95584 20.3366 8.66789C20.3062 8.66234 20.2759 8.67623 20.2603 8.704C20.0552 9.06879 19.828 9.5447 19.6689 9.91875C17.8754 9.65025 16.0912 9.65025 14.3345 9.91875C14.1753 9.53638 13.9399 9.06879 13.7339 8.704C13.7182 8.67715 13.6879 8.66326 13.6575 8.66789C11.991 8.95492 10.3962 9.45767 8.90808 10.141C8.8952 10.1465 8.88415 10.1558 8.87682 10.1678C5.85183 14.6871 5.02316 19.0952 5.42968 23.4487C5.43152 23.47 5.44347 23.4904 5.46003 23.5034C7.45583 24.969 9.38911 25.8588 11.2865 26.4486C11.3169 26.4578 11.349 26.4467 11.3684 26.4217C11.8172 25.8088 12.2173 25.1626 12.5603 24.4829C12.5805 24.4431 12.5612 24.3959 12.5198 24.3802C11.8852 24.1394 11.281 23.8459 10.6997 23.5126C10.6537 23.4858 10.65 23.42 10.6923 23.3885C10.8147 23.2969 10.937 23.2015 11.0538 23.1052C11.0749 23.0876 11.1044 23.0839 11.1292 23.095C14.9479 24.8385 19.0821 24.8385 22.8557 23.095C22.8805 23.083 22.91 23.0867 22.932 23.1043C23.0489 23.2006 23.1712 23.2969 23.2944 23.3885C23.3367 23.42 23.334 23.4858 23.288 23.5126C22.7067 23.8524 22.1025 24.1394 21.4669 24.3792C21.4256 24.395 21.4072 24.4431 21.4274 24.4829C21.7778 25.1616 22.1779 25.8079 22.6184 26.4208C22.6368 26.4467 22.6699 26.4578 22.7003 26.4486C24.6069 25.8588 26.5401 24.969 28.5359 23.5034C28.5534 23.4904 28.5645 23.471 28.5663 23.4497C29.0528 18.4165 27.7514 14.0445 25.1164 10.1687C25.11 10.1558 25.0989 10.1465 25.0861 10.141ZM13.1306 20.7979C11.9809 20.7979 11.0336 19.7424 11.0336 18.4462C11.0336 17.1499 11.9625 16.0944 13.1306 16.0944C14.3078 16.0944 15.2459 17.1592 15.2275 18.4462C15.2275 19.7424 14.2986 20.7979 13.1306 20.7979ZM20.8838 20.7979C19.7342 20.7979 18.7869 19.7424 18.7869 18.4462C18.7869 17.1499 19.7158 16.0944 20.8838 16.0944C22.0611 16.0944 22.9992 17.1592 22.9808 18.4462C22.9808 19.7424 22.0611 20.7979 20.8838 20.7979Z" fill="white"/>
1
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M0 4.8C0 2.14903 2.14903 0 4.8 0H19.2C21.851 0 24 2.14903 24 4.8V19.2C24 21.851 21.851 24 19.2 24H4.8C2.14903 24 0 21.851 0 19.2V4.8Z" fill="#5865F2"/>
3
+ <path d="M17.8219 7.06149C16.7511 6.57017 15.6029 6.20819 14.4023 6.00087C14.3804 5.99687 14.3586 6.00687 14.3473 6.02687C14.1997 6.28952 14.0361 6.63217 13.9215 6.90149C12.6303 6.70817 11.3456 6.70817 10.0808 6.90149C9.96623 6.62618 9.79671 6.28952 9.64838 6.02687C9.63711 6.00754 9.61527 5.99754 9.59341 6.00087C8.39351 6.20753 7.24527 6.56951 6.17383 7.06149C6.16455 7.06549 6.1566 7.07216 6.15133 7.08082C3.97335 10.3347 3.37671 13.5085 3.6694 16.6431C3.67073 16.6584 3.67933 16.6731 3.69125 16.6824C5.12822 17.7377 6.52017 18.3783 7.88627 18.803C7.90813 18.8096 7.9313 18.8016 7.94521 18.7836C8.26836 18.3423 8.55643 17.877 8.80341 17.3877C8.81798 17.359 8.80407 17.325 8.77428 17.3137C8.31737 17.1404 7.8823 16.9291 7.46379 16.6891C7.43068 16.6697 7.42803 16.6224 7.45849 16.5997C7.54656 16.5337 7.63465 16.4651 7.71874 16.3957C7.73396 16.3831 7.75516 16.3804 7.77305 16.3884C10.5225 17.6437 13.4991 17.6437 16.216 16.3884C16.2339 16.3797 16.2551 16.3824 16.271 16.3951C16.3551 16.4644 16.4432 16.5337 16.5319 16.5997C16.5624 16.6224 16.5604 16.6697 16.5273 16.6891C16.1088 16.9337 15.6737 17.1404 15.2161 17.313C15.1863 17.3244 15.1731 17.359 15.1877 17.3877C15.44 17.8763 15.728 18.3417 16.0452 18.783C16.0585 18.8016 16.0823 18.8096 16.1041 18.803C17.4769 18.3783 18.8688 17.7377 20.3058 16.6824C20.3184 16.6731 20.3263 16.6591 20.3276 16.6437C20.6779 13.0199 19.7409 9.87203 17.8437 7.08148C17.8391 7.07216 17.8312 7.06549 17.8219 7.06149ZM9.21399 14.7345C8.38622 14.7345 7.70417 13.9745 7.70417 13.0412C7.70417 12.1079 8.373 11.348 9.21399 11.348C10.0616 11.348 10.737 12.1146 10.7238 13.0412C10.7238 13.9745 10.055 14.7345 9.21399 14.7345ZM14.7963 14.7345C13.9686 14.7345 13.2865 13.9745 13.2865 13.0412C13.2865 12.1079 13.9553 11.348 14.7963 11.348C15.6439 11.348 16.3194 12.1146 16.3061 13.0412C16.3061 13.9745 15.6439 14.7345 14.7963 14.7345Z" fill="white"/>
4
4
  </svg>
package/package.json CHANGED
@@ -51,7 +51,7 @@
51
51
  "access": "public"
52
52
  },
53
53
  "name": "@logto/connector-discord",
54
- "version": "1.0.0-beta.18",
54
+ "version": "1.0.0-beta.19",
55
55
  "description": "Discord connector implementation.",
56
56
  "author": "ZR3SYSTEMS. <https://github.com/FlurryNight>",
57
57
  "scripts": {