@logto/connector-github 1.4.0 → 1.4.2

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/README.md CHANGED
@@ -55,7 +55,7 @@ Fill out the `clientId` and `clientSecret` field with _Client ID_ and _Client Se
55
55
 
56
56
  ## Test GitHub connector
57
57
 
58
- That's it. The GitHub connector should be available now. Don't forget to [Enable connector in sign-in experience](https://docs.logto.io/docs/tutorials/get-started/passwordless-sign-in-by-adding-connectors#enable-social-sign-in).
58
+ That's it. The GitHub connector should be available now. Don't forget to [Enable connector in sign-in experience](https://docs.logto.io/docs/recipes/configure-connectors/social-connector/enable-social-sign-in/).
59
59
 
60
60
  ## Reference
61
61
 
package/lib/index.js CHANGED
@@ -26,6 +26,28 @@ const notFalsy = (value) => Boolean(value);
26
26
  */
27
27
  const conditional = (exp) => (notFalsy(exp) ? exp : undefined);
28
28
 
29
+ // Intended
30
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
31
+ const isPromise = (value) => value !== null &&
32
+ (typeof value === 'object' || typeof value === 'function') &&
33
+ 'then' in value &&
34
+ typeof value.then === 'function';
35
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
36
+ const trySafe = (exec, onError) => {
37
+ try {
38
+ const unwrapped = typeof exec === 'function' ? exec() : exec;
39
+ return isPromise(unwrapped)
40
+ ? // eslint-disable-next-line promise/prefer-await-to-then
41
+ unwrapped.catch((error) => {
42
+ onError?.(error);
43
+ })
44
+ : unwrapped;
45
+ }
46
+ catch (error) {
47
+ onError?.(error);
48
+ }
49
+ };
50
+
29
51
  // eslint-lint-disable-next-line @typescript-eslint/naming-convention
30
52
  class HTTPError extends Error {
31
53
  constructor(response, request, options) {
@@ -731,9 +753,16 @@ const getUserInfo = (getConfig) => async (data) => {
731
753
  },
732
754
  });
733
755
  try {
734
- const [userInfo, userEmails] = await Promise.all([
756
+ /**
757
+ * If user(s) is using GitHub Apps (instead of OAuth Apps), they can customize
758
+ * "Account permissions" and restrict the "email addresses" visibility, and GitHub
759
+ * hence throws error instead of returning an empty array.
760
+ *
761
+ * We try catch the error and return an empty array instead.
762
+ */
763
+ const [userInfo, userEmails = []] = await Promise.all([
735
764
  authedApi.get(userInfoEndpoint).json(),
736
- authedApi.get(userEmailsEndpoint).json(),
765
+ trySafe(authedApi.get(userEmailsEndpoint).json()),
737
766
  ]);
738
767
  const userInfoResult = userInfoResponseGuard.safeParse(userInfo);
739
768
  const userEmailsResult = emailAddressGuard.array().safeParse(userEmails);
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@logto/connector-github",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Github web connector implementation.",
5
5
  "author": "Silverhand Inc. <contact@silverhand.io>",
6
6
  "dependencies": {
7
- "@logto/connector-kit": "^3.0.0",
8
- "@silverhand/essentials": "^2.9.0",
7
+ "@logto/connector-kit": "^4.0.0",
8
+ "@silverhand/essentials": "^2.9.1",
9
9
  "ky": "^1.2.3",
10
10
  "query-string": "^9.0.0",
11
11
  "snakecase-keys": "^8.0.0",
@@ -42,7 +42,7 @@
42
42
  "access": "public"
43
43
  },
44
44
  "devDependencies": {
45
- "@rollup/plugin-commonjs": "^25.0.7",
45
+ "@rollup/plugin-commonjs": "^26.0.0",
46
46
  "@rollup/plugin-json": "^6.1.0",
47
47
  "@rollup/plugin-node-resolve": "^15.2.3",
48
48
  "@rollup/plugin-typescript": "^11.1.6",
@@ -53,7 +53,7 @@
53
53
  "@vitest/coverage-v8": "^1.4.0",
54
54
  "eslint": "^8.56.0",
55
55
  "lint-staged": "^15.0.2",
56
- "nock": "14.0.0-beta.6",
56
+ "nock": "14.0.0-beta.7",
57
57
  "prettier": "^3.0.0",
58
58
  "rollup": "^4.12.0",
59
59
  "rollup-plugin-output-size": "^1.3.0",