@faable/auth-js 1.2.2 → 1.3.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 (58) hide show
  1. package/README.md +26 -1
  2. package/dist/Base.d.ts +0 -1
  3. package/dist/BaseLog.d.ts +0 -1
  4. package/dist/FaableAuthApi.d.ts +0 -1
  5. package/dist/FaableAuthClient.d.ts +5 -1
  6. package/dist/entrypoints/faableauth.d.ts +6 -0
  7. package/dist/faableauth.js +7 -0
  8. package/dist/faableauth.js.map +1 -0
  9. package/dist/lib/constants.d.ts +0 -1
  10. package/dist/lib/errors.d.ts +0 -1
  11. package/dist/lib/fetch.d.ts +8 -5
  12. package/dist/lib/globals.d.ts +4 -0
  13. package/dist/lib/helpers.d.ts +18 -8
  14. package/dist/lib/jwt.d.ts +0 -1
  15. package/dist/lib/local-storage.d.ts +0 -1
  16. package/dist/lib/storage_helpers.d.ts +0 -1
  17. package/dist/lib/types.d.ts +0 -1
  18. package/dist/lib/url_helpers.d.ts +7 -0
  19. package/dist/lib/version.d.ts +0 -1
  20. package/dist/lock/Lock.d.ts +0 -1
  21. package/dist/lock/locks.d.ts +0 -1
  22. package/dist/utils.d.ts +0 -1
  23. package/package.json +5 -24
  24. package/dist/Base.d.ts.map +0 -1
  25. package/dist/Base.js +0 -16
  26. package/dist/BaseLog.d.ts.map +0 -1
  27. package/dist/BaseLog.js +0 -21
  28. package/dist/FaableAuthApi.d.ts.map +0 -1
  29. package/dist/FaableAuthApi.js +0 -37
  30. package/dist/FaableAuthClient.d.ts.map +0 -1
  31. package/dist/FaableAuthClient.js +0 -1073
  32. package/dist/index.d.ts +0 -7
  33. package/dist/index.d.ts.map +0 -1
  34. package/dist/index.js +0 -13
  35. package/dist/lib/constants.d.ts.map +0 -1
  36. package/dist/lib/constants.js +0 -13
  37. package/dist/lib/errors.d.ts.map +0 -1
  38. package/dist/lib/errors.js +0 -100
  39. package/dist/lib/fetch.d.ts.map +0 -1
  40. package/dist/lib/fetch.js +0 -53
  41. package/dist/lib/helpers.d.ts.map +0 -1
  42. package/dist/lib/helpers.js +0 -257
  43. package/dist/lib/jwt.d.ts.map +0 -1
  44. package/dist/lib/jwt.js +0 -139
  45. package/dist/lib/local-storage.d.ts.map +0 -1
  46. package/dist/lib/local-storage.js +0 -45
  47. package/dist/lib/storage_helpers.d.ts.map +0 -1
  48. package/dist/lib/storage_helpers.js +0 -34
  49. package/dist/lib/types.d.ts.map +0 -1
  50. package/dist/lib/types.js +0 -6
  51. package/dist/lib/version.d.ts.map +0 -1
  52. package/dist/lib/version.js +0 -5
  53. package/dist/lock/Lock.d.ts.map +0 -1
  54. package/dist/lock/Lock.js +0 -82
  55. package/dist/lock/locks.d.ts.map +0 -1
  56. package/dist/lock/locks.js +0 -137
  57. package/dist/utils.d.ts.map +0 -1
  58. package/dist/utils.js +0 -88
package/dist/index.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { FaableAuthClient } from "./FaableAuthClient";
2
- import { FaableAuthClientConfig } from "./lib/types";
3
- import { Session, User } from "./lib/types";
4
- import { AuthError } from "./lib/errors";
5
- export declare const createClient: (config: FaableAuthClientConfig) => FaableAuthClient;
6
- export { Session, User, FaableAuthClient, AuthError };
7
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,eAAO,MAAM,YAAY,WAAY,sBAAsB,qBAE1D,CAAC;AAEF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,SAAS,EAAE,CAAC"}
package/dist/index.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AuthError = exports.FaableAuthClient = exports.User = exports.createClient = void 0;
4
- const FaableAuthClient_1 = require("./FaableAuthClient");
5
- Object.defineProperty(exports, "FaableAuthClient", { enumerable: true, get: function () { return FaableAuthClient_1.FaableAuthClient; } });
6
- const types_1 = require("./lib/types");
7
- Object.defineProperty(exports, "User", { enumerable: true, get: function () { return types_1.User; } });
8
- const errors_1 = require("./lib/errors");
9
- Object.defineProperty(exports, "AuthError", { enumerable: true, get: function () { return errors_1.AuthError; } });
10
- const createClient = (config) => {
11
- return new FaableAuthClient_1.FaableAuthClient(config);
12
- };
13
- exports.createClient = createClient;
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/lib/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,UAAU,0BAA0B,CAAC;AAClD,eAAO,MAAM,WAAW,sBAAsB,CAAC;AAC/C,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAClE,eAAO,MAAM,YAAY;;;;;CAKxB,CAAC"}
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.API_VERSIONS = exports.API_VERSION_HEADER_NAME = exports.EXPIRY_MARGIN = exports.STORAGE_KEY = exports.GOTRUE_URL = void 0;
4
- exports.GOTRUE_URL = "http://localhost:9999";
5
- exports.STORAGE_KEY = "faable.auth.token";
6
- exports.EXPIRY_MARGIN = 10; // in seconds
7
- exports.API_VERSION_HEADER_NAME = "X-Faableauth-Api-Version";
8
- exports.API_VERSIONS = {
9
- "2024-01-01": {
10
- timestamp: Date.parse("2024-01-01T00:00:00.0Z"),
11
- name: "2024-01-01",
12
- },
13
- };
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"A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E,aAAa,EAAE,OAAO;CAKpD;AAED,qBAAa,6BAA8B,SAAQ,eAAe;;CASjE;AAED,qBAAa,uBAAwB,SAAQ,eAAe;gBAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAG5C;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,uBAAuB,CAElC"}
@@ -1,100 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isAuthRetryableFetchError = exports.AuthRetryableFetchError = exports.AuthInvalidTokenResponseError = exports.AuthUnknownError = exports.AuthPKCEGrantCodeExchangeError = exports.AuthImplicitGrantRedirectError = exports.isAuthApiError = exports.AuthApiError = exports.isAuthError = exports.AuthSessionMissingError = exports.CustomAuthError = exports.AuthError = void 0;
4
- class AuthError extends Error {
5
- constructor(message, status, code) {
6
- super(message);
7
- this.__isAuthError = true;
8
- this.name = "AuthError";
9
- this.status = status;
10
- this.code = code;
11
- }
12
- }
13
- exports.AuthError = AuthError;
14
- class CustomAuthError extends AuthError {
15
- constructor(message, name, status, code) {
16
- super(message, status, code);
17
- this.name = name;
18
- this.status = status;
19
- }
20
- }
21
- exports.CustomAuthError = CustomAuthError;
22
- class AuthSessionMissingError extends CustomAuthError {
23
- constructor() {
24
- super("Auth session missing!", "AuthSessionMissingError", 400, undefined);
25
- }
26
- }
27
- exports.AuthSessionMissingError = AuthSessionMissingError;
28
- function isAuthError(error) {
29
- return (typeof error === "object" && error !== null && "__isAuthError" in error);
30
- }
31
- exports.isAuthError = isAuthError;
32
- class AuthApiError extends AuthError {
33
- constructor(message, status, code) {
34
- super(message, status, code);
35
- this.name = "AuthApiError";
36
- this.status = status;
37
- this.code = code;
38
- }
39
- }
40
- exports.AuthApiError = AuthApiError;
41
- function isAuthApiError(error) {
42
- return isAuthError(error) && error.name === "AuthApiError";
43
- }
44
- exports.isAuthApiError = isAuthApiError;
45
- class AuthImplicitGrantRedirectError extends CustomAuthError {
46
- constructor(message, details = null) {
47
- super(message, "AuthImplicitGrantRedirectError", 500, undefined);
48
- this.details = null;
49
- this.details = details;
50
- }
51
- toJSON() {
52
- return {
53
- name: this.name,
54
- message: this.message,
55
- status: this.status,
56
- details: this.details,
57
- };
58
- }
59
- }
60
- exports.AuthImplicitGrantRedirectError = AuthImplicitGrantRedirectError;
61
- class AuthPKCEGrantCodeExchangeError extends CustomAuthError {
62
- constructor(message, details = null) {
63
- super(message, "AuthPKCEGrantCodeExchangeError", 500, undefined);
64
- this.details = null;
65
- this.details = details;
66
- }
67
- toJSON() {
68
- return {
69
- name: this.name,
70
- message: this.message,
71
- status: this.status,
72
- details: this.details,
73
- };
74
- }
75
- }
76
- exports.AuthPKCEGrantCodeExchangeError = AuthPKCEGrantCodeExchangeError;
77
- class AuthUnknownError extends AuthError {
78
- constructor(message, originalError) {
79
- super(message);
80
- this.name = "AuthUnknownError";
81
- this.originalError = originalError;
82
- }
83
- }
84
- exports.AuthUnknownError = AuthUnknownError;
85
- class AuthInvalidTokenResponseError extends CustomAuthError {
86
- constructor() {
87
- super("Auth session or user missing", "AuthInvalidTokenResponseError", 500, undefined);
88
- }
89
- }
90
- exports.AuthInvalidTokenResponseError = AuthInvalidTokenResponseError;
91
- class AuthRetryableFetchError extends CustomAuthError {
92
- constructor(message, status) {
93
- super(message, "AuthRetryableFetchError", status, undefined);
94
- }
95
- }
96
- exports.AuthRetryableFetchError = AuthRetryableFetchError;
97
- function isAuthRetryableFetchError(error) {
98
- return isAuthError(error) && error.name === "AuthRetryableFetchError";
99
- }
100
- exports.isAuthRetryableFetchError = isAuthRetryableFetchError;
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/lib/fetch.ts"],"names":[],"mappings":"AAGA,KAAK,oBAAoB,GAAG,WAAW,GAAG;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,GAAG,CAAC;CAChC,CAAC;AAaF,eAAO,MAAM,KAAK,QACX,MAAM,QACL,MAAM,SACL,oBAAoB,iBAiB5B,CAAC;AAEF,eAAO,MAAM,IAAI,QAAe,MAAM,SAAS,oBAAoB,iBAelE,CAAC"}
package/dist/lib/fetch.js DELETED
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports._get = exports._post = void 0;
16
- const isomorphic_fetch_1 = __importDefault(require("isomorphic-fetch"));
17
- const headers = (init) => {
18
- let headers = {};
19
- if (init === null || init === void 0 ? void 0 : init.token) {
20
- headers = Object.assign(Object.assign({}, headers), { Authorization: `Bearer ${init === null || init === void 0 ? void 0 : init.token}` });
21
- }
22
- return Object.assign(Object.assign({}, init === null || init === void 0 ? void 0 : init.headers), headers);
23
- };
24
- const _post = (url, data, init) => __awaiter(void 0, void 0, void 0, function* () {
25
- try {
26
- const res = yield (0, isomorphic_fetch_1.default)(url, {
27
- method: "POST",
28
- body: JSON.stringify(data),
29
- headers: Object.assign(Object.assign({}, headers(init)), { "Content-Type": "application/json" }),
30
- });
31
- const body = yield res.json();
32
- return init && init.transform
33
- ? init.transform(body)
34
- : { data: body, error: null };
35
- }
36
- catch (e) {
37
- return { data: null, error: e };
38
- }
39
- });
40
- exports._post = _post;
41
- const _get = (url, init) => __awaiter(void 0, void 0, void 0, function* () {
42
- try {
43
- const res = yield (0, isomorphic_fetch_1.default)(url, Object.assign(Object.assign({}, init), { method: "GET", headers: headers(init) }));
44
- const body = yield res.json();
45
- return init && init.transform
46
- ? init.transform(body)
47
- : { data: body, error: null };
48
- }
49
- catch (e) {
50
- return { data: null, error: e };
51
- }
52
- });
53
- exports._get = _get;
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/lib/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAsB,MAAM,SAAS,CAAC;AAO7E,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CA2BrD;AAGD,wBAAgB,oBAAoB,WAenC;AAiBD,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,mBAc3D;AAED,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,gBAAgB,EACzB,UAAU,EAAE,MAAM,EAClB,kBAAkB,UAAQ,qBAe3B;AAED,eAAO,MAAM,SAAS,eAAwC,CAAC;AAO/D;;GAEG;AACH,eAAO,MAAM,oBAAoB,eAmChC,CAAC;AAEF,wBAAgB,IAAI,WAMnB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM;;EAsBlD;AAWD,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,UAG1C;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,GAAG,GAAG,YAAY,CAYxD;AAED;;;;GAIG;AACH,qBAAa,QAAQ,CAAC,CAAC,GAAG,GAAG;IAC3B,OAAc,kBAAkB,EAAE,kBAAkB,CAAW;IAE/D,SAAgB,OAAO,EAAG,WAAW,CAAC,CAAC,CAAC,CAAC;IAEzC,SAAgB,OAAO,EAAG,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IAE/D,SAAgB,MAAM,EAAG,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC;;CAWhD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,EACzB,EAAE,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,EACnC,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC,KAAK,OAAO,GACvE,OAAO,CAAC,CAAC,CAAC,CAuBZ;AAED;;GAEG;AACH,wBAAsB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIvD"}
@@ -1,257 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.sleep = exports.retryable = exports.Deferred = exports._sessionResponse = exports.expiresAt = exports.parseParametersFromURL = exports.uuid = exports.supportsLocalStorage = exports.isBrowser = exports.getCodeChallengeAndMethod = exports.generatePKCEChallenge = exports.generatePKCEVerifier = exports.decodeBase64URL = void 0;
13
- const storage_helpers_1 = require("./storage_helpers");
14
- function dec2hex(dec) {
15
- return ("0" + dec.toString(16)).substr(-2);
16
- }
17
- function decodeBase64URL(value) {
18
- const key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
19
- let base64 = "";
20
- let chr1, chr2, chr3;
21
- let enc1, enc2, enc3, enc4;
22
- let i = 0;
23
- value = value.replace("-", "+").replace("_", "/");
24
- while (i < value.length) {
25
- enc1 = key.indexOf(value.charAt(i++));
26
- enc2 = key.indexOf(value.charAt(i++));
27
- enc3 = key.indexOf(value.charAt(i++));
28
- enc4 = key.indexOf(value.charAt(i++));
29
- chr1 = (enc1 << 2) | (enc2 >> 4);
30
- chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
31
- chr3 = ((enc3 & 3) << 6) | enc4;
32
- base64 = base64 + String.fromCharCode(chr1);
33
- if (enc3 != 64 && chr2 != 0) {
34
- base64 = base64 + String.fromCharCode(chr2);
35
- }
36
- if (enc4 != 64 && chr3 != 0) {
37
- base64 = base64 + String.fromCharCode(chr3);
38
- }
39
- }
40
- return base64;
41
- }
42
- exports.decodeBase64URL = decodeBase64URL;
43
- // Functions below taken from: https://stackoverflow.com/questions/63309409/creating-a-code-verifier-and-challenge-for-pkce-auth-on-spotify-api-in-reactjs
44
- function generatePKCEVerifier() {
45
- const verifierLength = 56;
46
- const array = new Uint32Array(verifierLength);
47
- if (typeof crypto === "undefined") {
48
- const charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
49
- const charSetLen = charSet.length;
50
- let verifier = "";
51
- for (let i = 0; i < verifierLength; i++) {
52
- verifier += charSet.charAt(Math.floor(Math.random() * charSetLen));
53
- }
54
- return verifier;
55
- }
56
- crypto.getRandomValues(array);
57
- return Array.from(array, dec2hex).join("");
58
- }
59
- exports.generatePKCEVerifier = generatePKCEVerifier;
60
- function sha256(randomString) {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- const encoder = new TextEncoder();
63
- const encodedData = encoder.encode(randomString);
64
- const hash = yield crypto.subtle.digest("SHA-256", encodedData);
65
- const bytes = new Uint8Array(hash);
66
- return Array.from(bytes)
67
- .map((c) => String.fromCharCode(c))
68
- .join("");
69
- });
70
- }
71
- function base64urlencode(str) {
72
- return btoa(str).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
73
- }
74
- function generatePKCEChallenge(verifier) {
75
- return __awaiter(this, void 0, void 0, function* () {
76
- const hasCryptoSupport = typeof crypto !== "undefined" &&
77
- typeof crypto.subtle !== "undefined" &&
78
- typeof TextEncoder !== "undefined";
79
- if (!hasCryptoSupport) {
80
- console.warn("WebCrypto API is not supported. Code challenge method will default to use plain instead of sha256.");
81
- return verifier;
82
- }
83
- const hashed = yield sha256(verifier);
84
- return base64urlencode(hashed);
85
- });
86
- }
87
- exports.generatePKCEChallenge = generatePKCEChallenge;
88
- function getCodeChallengeAndMethod(storage_1, storageKey_1) {
89
- return __awaiter(this, arguments, void 0, function* (storage, storageKey, isPasswordRecovery = false) {
90
- const codeVerifier = generatePKCEVerifier();
91
- let storedCodeVerifier = codeVerifier;
92
- if (isPasswordRecovery) {
93
- storedCodeVerifier += "/PASSWORD_RECOVERY";
94
- }
95
- yield (0, storage_helpers_1.setItemAsync)(storage, `${storageKey}-code-verifier`, storedCodeVerifier);
96
- const codeChallenge = yield generatePKCEChallenge(codeVerifier);
97
- const codeChallengeMethod = codeVerifier === codeChallenge ? "plain" : "S256";
98
- return [codeChallenge, codeChallengeMethod];
99
- });
100
- }
101
- exports.getCodeChallengeAndMethod = getCodeChallengeAndMethod;
102
- const isBrowser = () => typeof document !== "undefined";
103
- exports.isBrowser = isBrowser;
104
- const localStorageWriteTests = {
105
- tested: false,
106
- writable: false,
107
- };
108
- /**
109
- * Checks whether localStorage is supported on this browser.
110
- */
111
- const supportsLocalStorage = () => {
112
- if (!(0, exports.isBrowser)()) {
113
- return false;
114
- }
115
- try {
116
- if (typeof globalThis.localStorage !== "object") {
117
- return false;
118
- }
119
- }
120
- catch (e) {
121
- // DOM exception when accessing `localStorage`
122
- return false;
123
- }
124
- if (localStorageWriteTests.tested) {
125
- return localStorageWriteTests.writable;
126
- }
127
- const randomKey = `lswt-${Math.random()}${Math.random()}`;
128
- try {
129
- globalThis.localStorage.setItem(randomKey, randomKey);
130
- globalThis.localStorage.removeItem(randomKey);
131
- localStorageWriteTests.tested = true;
132
- localStorageWriteTests.writable = true;
133
- }
134
- catch (e) {
135
- // localStorage can't be written to
136
- // https://www.chromium.org/for-testers/bug-reporting-guidelines/uncaught-securityerror-failed-to-read-the-localstorage-property-from-window-access-is-denied-for-this-document
137
- localStorageWriteTests.tested = true;
138
- localStorageWriteTests.writable = false;
139
- }
140
- return localStorageWriteTests.writable;
141
- };
142
- exports.supportsLocalStorage = supportsLocalStorage;
143
- function uuid() {
144
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
145
- const r = (Math.random() * 16) | 0, v = c == "x" ? r : (r & 0x3) | 0x8;
146
- return v.toString(16);
147
- });
148
- }
149
- exports.uuid = uuid;
150
- /**
151
- * Extracts parameters encoded in the URL both in the query and fragment.
152
- */
153
- function parseParametersFromURL(href) {
154
- const result = {};
155
- const url = new URL(href);
156
- if (url.hash && url.hash[0] === "#") {
157
- try {
158
- const hashSearchParams = new URLSearchParams(url.hash.substring(1));
159
- hashSearchParams.forEach((value, key) => {
160
- result[key] = value;
161
- });
162
- }
163
- catch (e) {
164
- // hash is not a query string
165
- }
166
- }
167
- // search parameters take precedence over hash parameters
168
- url.searchParams.forEach((value, key) => {
169
- result[key] = value;
170
- });
171
- return result;
172
- }
173
- exports.parseParametersFromURL = parseParametersFromURL;
174
- /**
175
- * hasSession checks if the response object contains a valid session
176
- * @param data A response object
177
- * @returns true if a session is in the response
178
- */
179
- function hasSession(data) {
180
- return data.access_token && data.refresh_token && data.expires_in;
181
- }
182
- function expiresAt(expiresIn) {
183
- const timeNow = Math.round(Date.now() / 1000);
184
- return timeNow + expiresIn;
185
- }
186
- exports.expiresAt = expiresAt;
187
- function _sessionResponse(data) {
188
- var _a;
189
- let session = null;
190
- if (hasSession(data)) {
191
- session = Object.assign({}, data);
192
- if (!data.expires_at) {
193
- session.expires_at = expiresAt(data.expires_in);
194
- }
195
- }
196
- const user = (_a = data.user) !== null && _a !== void 0 ? _a : data;
197
- return { data: { session, user }, error: null };
198
- }
199
- exports._sessionResponse = _sessionResponse;
200
- /**
201
- * A deferred represents some asynchronous work that is not yet finished, which
202
- * may or may not culminate in a value.
203
- * Taken from: https://github.com/mike-north/types/blob/master/src/async.ts
204
- */
205
- class Deferred {
206
- constructor() {
207
- // eslint-disable-next-line @typescript-eslint/no-extra-semi
208
- this.promise = new Deferred.promiseConstructor((res, rej) => {
209
- // eslint-disable-next-line @typescript-eslint/no-extra-semi
210
- this.resolve = res;
211
- // eslint-disable-next-line @typescript-eslint/no-extra-semi
212
- this.reject = rej;
213
- });
214
- }
215
- }
216
- exports.Deferred = Deferred;
217
- Deferred.promiseConstructor = Promise;
218
- /**
219
- * Converts the provided async function into a retryable function. Each result
220
- * or thrown error is sent to the isRetryable function which should return true
221
- * if the function should run again.
222
- */
223
- function retryable(fn, isRetryable) {
224
- const promise = new Promise((accept, reject) => {
225
- // eslint-disable-next-line @typescript-eslint/no-extra-semi
226
- (() => __awaiter(this, void 0, void 0, function* () {
227
- for (let attempt = 0; attempt < Infinity; attempt++) {
228
- try {
229
- const result = yield fn(attempt);
230
- if (!isRetryable(attempt, null, result)) {
231
- accept(result);
232
- return;
233
- }
234
- }
235
- catch (e) {
236
- if (!isRetryable(attempt, e)) {
237
- reject(e);
238
- return;
239
- }
240
- }
241
- }
242
- }))();
243
- });
244
- return promise;
245
- }
246
- exports.retryable = retryable;
247
- /**
248
- * Creates a promise that resolves to null after some time.
249
- */
250
- function sleep(time) {
251
- return __awaiter(this, void 0, void 0, function* () {
252
- return new Promise((accept) => {
253
- setTimeout(() => accept(null), time);
254
- });
255
- });
256
- }
257
- exports.sleep = sleep;
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../src/lib/jwt.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,M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EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAqCD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,OAiB7C;AAED,eAAO,MAAM,MAAM,YAAa,gBAAgB,QAkJ/C,CAAC"}
package/dist/lib/jwt.js DELETED
@@ -1,139 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verify = exports.decodeJWTPayload = void 0;
4
- const helpers_1 = require("./helpers");
5
- const isNumber = (n) => typeof n === "number";
6
- const idTokendecoded = [
7
- "iss",
8
- "aud",
9
- "exp",
10
- "nbf",
11
- "iat",
12
- "jti",
13
- "azp",
14
- "nonce",
15
- "auth_time",
16
- "at_hash",
17
- "c_hash",
18
- "acr",
19
- "amr",
20
- "sub_jwk",
21
- "cnf",
22
- "sip_from_tag",
23
- "sip_date",
24
- "sip_callid",
25
- "sip_cseq_num",
26
- "sip_via_branch",
27
- "orig",
28
- "dest",
29
- "mky",
30
- "events",
31
- "toe",
32
- "txn",
33
- "rph",
34
- "sid",
35
- "vot",
36
- "vtm",
37
- ];
38
- function decodeJWTPayload(token) {
39
- // Regex checks for base64url format
40
- const base64UrlRegex = /^([a-z0-9_-]{4})*($|[a-z0-9_-]{3}=?$|[a-z0-9_-]{2}(==)?$)$/i;
41
- const parts = token.split(".");
42
- if (parts.length !== 3) {
43
- throw new Error("JWT is not valid: not a JWT structure");
44
- }
45
- if (!base64UrlRegex.test(parts[1])) {
46
- throw new Error("JWT is not valid: payload is not in base64url format");
47
- }
48
- const base64Url = parts[1];
49
- return JSON.parse((0, helpers_1.decodeBase64URL)(base64Url));
50
- }
51
- exports.decodeJWTPayload = decodeJWTPayload;
52
- const verify = (options) => {
53
- if (!options.id_token) {
54
- throw new Error("ID token is required but missing");
55
- }
56
- const decoded = decodeJWTPayload(options.id_token);
57
- if (!decoded.claims.iss) {
58
- throw new Error("Issuer (iss) claim must be a string present in the ID token");
59
- }
60
- if (decoded.claims.iss !== options.iss) {
61
- throw new Error(`Issuer (iss) claim mismatch in the ID token; expected "${options.iss}", found "${decoded.claims.iss}"`);
62
- }
63
- if (!decoded.user.sub) {
64
- throw new Error("Subject (sub) claim must be a string present in the ID token");
65
- }
66
- if (decoded.header.alg !== "RS256") {
67
- throw new Error(`Signature algorithm of "${decoded.header.alg}" is not supported. Expected the ID token to be signed with "RS256".`);
68
- }
69
- if (!decoded.claims.aud ||
70
- !(typeof decoded.claims.aud === "string" ||
71
- Array.isArray(decoded.claims.aud))) {
72
- throw new Error("Audience (aud) claim must be a string or array of strings present in the ID token");
73
- }
74
- if (Array.isArray(decoded.claims.aud)) {
75
- if (!decoded.claims.aud.includes(options.aud)) {
76
- throw new Error(`Audience (aud) claim mismatch in the ID token; expected "${options.aud}" but was not one of "${decoded.claims.aud.join(", ")}"`);
77
- }
78
- if (decoded.claims.aud.length > 1) {
79
- if (!decoded.claims.azp) {
80
- throw new Error("Authorized Party (azp) claim must be a string present in the ID token when Audience (aud) claim has multiple values");
81
- }
82
- if (decoded.claims.azp !== options.aud) {
83
- throw new Error(`Authorized Party (azp) claim mismatch in the ID token; expected "${options.aud}", found "${decoded.claims.azp}"`);
84
- }
85
- }
86
- }
87
- else if (decoded.claims.aud !== options.aud) {
88
- throw new Error(`Audience (aud) claim mismatch in the ID token; expected "${options.aud}" but found "${decoded.claims.aud}"`);
89
- }
90
- if (options.nonce) {
91
- if (!decoded.claims.nonce) {
92
- throw new Error("Nonce (nonce) claim must be a string present in the ID token");
93
- }
94
- if (decoded.claims.nonce !== options.nonce) {
95
- throw new Error(`Nonce (nonce) claim mismatch in the ID token; expected "${options.nonce}", found "${decoded.claims.nonce}"`);
96
- }
97
- }
98
- if (options.max_age && !isNumber(decoded.claims.auth_time)) {
99
- throw new Error("Authentication Time (auth_time) claim must be a number present in the ID token when Max Age (max_age) is specified");
100
- }
101
- /* c8 ignore next 5 */
102
- if (decoded.claims.exp == null || !isNumber(decoded.claims.exp)) {
103
- throw new Error("Expiration Time (exp) claim must be a number present in the ID token");
104
- }
105
- if (!isNumber(decoded.claims.iat)) {
106
- throw new Error("Issued At (iat) claim must be a number present in the ID token");
107
- }
108
- const leeway = options.leeway || 60;
109
- const now = new Date(options.now || Date.now());
110
- const expDate = new Date(0);
111
- expDate.setUTCSeconds(decoded.claims.exp + leeway);
112
- if (now > expDate) {
113
- throw new Error(`Expiration Time (exp) claim error in the ID token; current time (${now}) is after expiration time (${expDate})`);
114
- }
115
- if (decoded.claims.nbf != null && isNumber(decoded.claims.nbf)) {
116
- const nbfDate = new Date(0);
117
- nbfDate.setUTCSeconds(decoded.claims.nbf - leeway);
118
- if (now < nbfDate) {
119
- throw new Error(`Not Before time (nbf) claim in the ID token indicates that this token can't be used just yet. Current time (${now}) is before ${nbfDate}`);
120
- }
121
- }
122
- if (decoded.claims.auth_time != null && isNumber(decoded.claims.auth_time)) {
123
- const authTimeDate = new Date(0);
124
- authTimeDate.setUTCSeconds(parseInt(decoded.claims.auth_time) + options.max_age + leeway);
125
- if (now > authTimeDate) {
126
- throw new Error(`Authentication Time (auth_time) claim in the ID token indicates that too much time has passed since the last end-user authentication. Current time (${now}) is after last auth at ${authTimeDate}`);
127
- }
128
- }
129
- if (options.organizationId) {
130
- if (!decoded.claims.org_id) {
131
- throw new Error("Organization ID (org_id) claim must be a string present in the ID token");
132
- }
133
- else if (options.organizationId !== decoded.claims.org_id) {
134
- throw new Error(`Organization ID (org_id) claim mismatch in the ID token; expected "${options.organizationId}", found "${decoded.claims.org_id}"`);
135
- }
136
- }
137
- return decoded;
138
- };
139
- exports.verify = verify;
@@ -1 +0,0 @@
1
- {"version":3,"file":"local-storage.d.ts","sourceRoot":"","sources":["../../src/lib/local-storage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,gBAsBjC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,GAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAO,GACpC,gBAAgB,CAclB"}
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.memoryLocalStorageAdapter = exports.localStorageAdapter = void 0;
4
- const helpers_1 = require("./helpers");
5
- /**
6
- * Provides safe access to the globalThis.localStorage property.
7
- */
8
- exports.localStorageAdapter = {
9
- getItem: (key) => {
10
- if (!(0, helpers_1.supportsLocalStorage)()) {
11
- return null;
12
- }
13
- return globalThis.localStorage.getItem(key);
14
- },
15
- setItem: (key, value) => {
16
- if (!(0, helpers_1.supportsLocalStorage)()) {
17
- return;
18
- }
19
- globalThis.localStorage.setItem(key, value);
20
- },
21
- removeItem: (key) => {
22
- if (!(0, helpers_1.supportsLocalStorage)()) {
23
- return;
24
- }
25
- globalThis.localStorage.removeItem(key);
26
- },
27
- };
28
- /**
29
- * Returns a localStorage-like object that stores the key-value pairs in
30
- * memory.
31
- */
32
- function memoryLocalStorageAdapter(store = {}) {
33
- return {
34
- getItem: (key) => {
35
- return store[key] || null;
36
- },
37
- setItem: (key, value) => {
38
- store[key] = value;
39
- },
40
- removeItem: (key) => {
41
- delete store[key];
42
- },
43
- };
44
- }
45
- exports.memoryLocalStorageAdapter = memoryLocalStorageAdapter;
@@ -1 +0,0 @@
1
- {"version":3,"file":"storage_helpers.d.ts","sourceRoot":"","sources":["../../src/lib/storage_helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAG3C,eAAO,MAAM,YAAY,YACd,gBAAgB,OACpB,MAAM,QACL,GAAG,KACR,QAAQ,IAAI,CAEd,CAAC;AAEF,eAAO,MAAM,YAAY,YACd,gBAAgB,OACpB,MAAM,KACV,QAAQ,OAAO,CAYjB,CAAC;AAEF,eAAO,MAAM,eAAe,YACjB,gBAAgB,OACpB,MAAM,KACV,QAAQ,IAAI,CAEd,CAAC"}