@logto/js 1.1.2 → 2.0.1

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.
Files changed (45) hide show
  1. package/lib/consts/{index.mjs → index.cjs} +13 -11
  2. package/lib/consts/index.js +11 -13
  3. package/lib/core/fetch-token.cjs +47 -0
  4. package/lib/core/fetch-token.d.ts +1 -1
  5. package/lib/core/fetch-token.js +18 -25
  6. package/lib/core/index.d.ts +6 -6
  7. package/lib/core/oidc-config.cjs +13 -0
  8. package/lib/core/oidc-config.d.ts +1 -1
  9. package/lib/core/oidc-config.js +3 -10
  10. package/lib/core/revoke.cjs +14 -0
  11. package/lib/core/revoke.d.ts +1 -1
  12. package/lib/core/revoke.js +5 -7
  13. package/lib/core/sign-in.cjs +31 -0
  14. package/lib/core/sign-in.d.ts +2 -2
  15. package/lib/core/sign-in.js +16 -19
  16. package/lib/core/sign-out.cjs +13 -0
  17. package/lib/core/sign-out.js +4 -6
  18. package/lib/core/{user-info.mjs → user-info.cjs} +3 -1
  19. package/lib/core/user-info.d.ts +1 -1
  20. package/lib/core/user-info.js +1 -3
  21. package/lib/index.cjs +56 -0
  22. package/lib/index.d.ts +4 -4
  23. package/lib/index.js +12 -56
  24. package/lib/utils/{arbitrary-object.mjs → arbitrary-object.cjs} +3 -1
  25. package/lib/utils/arbitrary-object.js +1 -3
  26. package/lib/utils/callback-uri.cjs +36 -0
  27. package/lib/utils/callback-uri.js +13 -16
  28. package/lib/utils/errors.cjs +45 -0
  29. package/lib/utils/errors.d.ts +8 -13
  30. package/lib/utils/errors.js +11 -33
  31. package/lib/utils/{id-token.mjs → id-token.cjs} +13 -10
  32. package/lib/utils/id-token.js +10 -13
  33. package/lib/utils/index.d.ts +5 -5
  34. package/lib/utils/scopes.cjs +15 -0
  35. package/lib/utils/scopes.js +4 -6
  36. package/package.json +23 -27
  37. package/lib/core/fetch-token.mjs +0 -40
  38. package/lib/core/oidc-config.mjs +0 -6
  39. package/lib/core/revoke.mjs +0 -12
  40. package/lib/core/sign-in.mjs +0 -30
  41. package/lib/core/sign-out.mjs +0 -11
  42. package/lib/index.mjs +0 -12
  43. package/lib/utils/callback-uri.mjs +0 -33
  44. package/lib/utils/errors.mjs +0 -53
  45. package/lib/utils/scopes.mjs +0 -13
@@ -1,53 +0,0 @@
1
- import get from 'lodash.get';
2
- import { isArbitraryObject } from './arbitrary-object.mjs';
3
-
4
- const logtoErrorCodes = Object.freeze({
5
- id_token: {
6
- invalid_iat: 'Invalid issued at time in the ID token',
7
- invalid_token: 'Invalid ID token',
8
- },
9
- callback_uri_verification: {
10
- redirect_uri_mismatched: 'The callback URI mismatches the redirect URI.',
11
- error_found: 'Error found in the callback URI',
12
- missing_state: 'Missing state in the callback URI',
13
- state_mismatched: 'State mismatched in the callback URI',
14
- missing_code: 'Missing code in the callback URI',
15
- },
16
- crypto_subtle_unavailable: 'Crypto.subtle is unavailable in insecure contexts (non-HTTPS).',
17
- unexpected_response_error: 'Unexpected response error from the server.',
18
- });
19
- const getMessageByErrorCode = (errorCode) => {
20
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
21
- const message = get(logtoErrorCodes, errorCode);
22
- if (typeof message === 'string') {
23
- return message;
24
- }
25
- return errorCode;
26
- };
27
- class LogtoError extends Error {
28
- constructor(code, data) {
29
- super(getMessageByErrorCode(code));
30
- this.code = code;
31
- this.data = data;
32
- }
33
- }
34
- const isLogtoRequestError = (data) => {
35
- if (!isArbitraryObject(data)) {
36
- return false;
37
- }
38
- return typeof data.code === 'string' && typeof data.message === 'string';
39
- };
40
- class LogtoRequestError extends Error {
41
- constructor(code, message) {
42
- super(message);
43
- this.code = code;
44
- }
45
- }
46
- class OidcError {
47
- constructor(error, errorDescription) {
48
- this.error = error;
49
- this.errorDescription = errorDescription;
50
- }
51
- }
52
-
53
- export { LogtoError, LogtoRequestError, OidcError, isLogtoRequestError };
@@ -1,13 +0,0 @@
1
- import { ReservedScope, UserScope } from '../consts/index.mjs';
2
-
3
- /**
4
- * @param originalScopes
5
- * @return scopes should contain all default scopes (`openid`, `offline_access` and `profile`)
6
- */
7
- const withDefaultScopes = (originalScopes) => {
8
- const reservedScopes = Object.values(ReservedScope);
9
- const uniqueScopes = new Set([...reservedScopes, UserScope.Profile, ...(originalScopes ?? [])]);
10
- return Array.from(uniqueScopes).join(' ');
11
- };
12
-
13
- export { withDefaultScopes };