@meshagent/meshagent-ts-auth 0.42.2 → 0.43.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.
- package/CHANGELOG.md +12 -0
- package/dist/browser/access-token-provider.d.ts +1 -1
- package/dist/browser/browser-global.d.ts +1 -1
- package/dist/browser/index.d.ts +7 -7
- package/dist/browser/ma-auth.global.js +685 -658
- package/dist/browser/mauth-response.d.ts +2 -2
- package/dist/browser/meshagent-auth.d.ts +1 -1
- package/dist/browser/oauth-session-manager.d.ts +1 -1
- package/dist/browser/pkce-generator.d.ts +1 -1
- package/dist/cjs/access-token-provider.d.ts +1 -1
- package/dist/cjs/access-token-provider.js +2 -2
- package/dist/cjs/browser-global.d.ts +1 -1
- package/dist/cjs/ensure-login.js +14 -14
- package/dist/cjs/index.d.ts +7 -7
- package/dist/cjs/index.js +7 -7
- package/dist/cjs/mauth-response.d.ts +2 -2
- package/dist/cjs/mauth-response.js +6 -6
- package/dist/cjs/meshagent-auth.d.ts +1 -1
- package/dist/cjs/meshagent-auth.js +2 -2
- package/dist/cjs/oauth-session-manager.d.ts +1 -1
- package/dist/cjs/oauth-session-manager.js +2 -2
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/pkce-generator.d.ts +1 -1
- package/dist/cjs/pkce-generator.js +2 -2
- package/dist/esm/access-token-provider.d.ts +1 -1
- package/dist/esm/access-token-provider.js +1 -1
- package/dist/esm/browser-global.d.ts +1 -1
- package/dist/esm/ensure-login.js +5 -5
- package/dist/esm/index.d.ts +7 -7
- package/dist/esm/index.js +7 -7
- package/dist/esm/mauth-response.d.ts +2 -2
- package/dist/esm/mauth-response.js +3 -3
- package/dist/esm/meshagent-auth.d.ts +1 -1
- package/dist/esm/meshagent-auth.js +1 -1
- package/dist/esm/oauth-session-manager.d.ts +1 -1
- package/dist/esm/oauth-session-manager.js +1 -1
- package/dist/esm/pkce-generator.d.ts +1 -1
- package/dist/esm/pkce-generator.js +1 -1
- package/package.json +4 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Meshagent } from "@meshagent/meshagent";
|
|
2
|
-
import { MeshagentAuth } from "./meshagent-auth";
|
|
3
|
-
import type { StorageLike } from "./storage";
|
|
2
|
+
import { MeshagentAuth } from "./meshagent-auth.js";
|
|
3
|
+
import type { StorageLike } from "./storage.js";
|
|
4
4
|
export declare function getAuthorizationCode(): string | null;
|
|
5
5
|
export declare function normalizedExpiresIn(expiresIn: unknown): number | null;
|
|
6
6
|
export declare function getMeshagentClient(auth: MeshagentAuth, serverUrl: URL | string): Meshagent;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RefreshAccessTokenProvider = void 0;
|
|
4
|
-
const
|
|
4
|
+
const oauth_session_manager_js_1 = require("./oauth-session-manager.js");
|
|
5
5
|
class RefreshAccessTokenProvider {
|
|
6
6
|
constructor(options) {
|
|
7
7
|
Object.defineProperty(this, "session", {
|
|
@@ -10,7 +10,7 @@ class RefreshAccessTokenProvider {
|
|
|
10
10
|
writable: true,
|
|
11
11
|
value: void 0
|
|
12
12
|
});
|
|
13
|
-
this.session = new
|
|
13
|
+
this.session = new oauth_session_manager_js_1.OAuthSessionManager(options);
|
|
14
14
|
}
|
|
15
15
|
getToken() {
|
|
16
16
|
return this.session.getValidAccessTokenOrThrow();
|
package/dist/cjs/ensure-login.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ensureLogin = ensureLogin;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
4
|
+
const pkce_generator_js_1 = require("./pkce-generator.js");
|
|
5
|
+
const mauth_response_js_1 = require("./mauth-response.js");
|
|
6
|
+
const meshagent_auth_js_1 = require("./meshagent-auth.js");
|
|
7
|
+
const storage_js_1 = require("./storage.js");
|
|
8
|
+
const mauth_response_js_2 = require("./mauth-response.js");
|
|
9
9
|
const DEFAULT_SERVER_URL = "https://api.meshagent.com";
|
|
10
10
|
function getCurrentUrl() {
|
|
11
11
|
if (typeof window === "undefined") {
|
|
@@ -49,28 +49,28 @@ function replaceCurrentUrlWithoutAuthParams() {
|
|
|
49
49
|
}
|
|
50
50
|
async function ensureLogin({ oauthClientId, serverUrl, callbackUrl, provider, }) {
|
|
51
51
|
const serverBaseUrl = serverUrl ?? DEFAULT_SERVER_URL;
|
|
52
|
-
const storage = (0,
|
|
53
|
-
const cache = new
|
|
52
|
+
const storage = (0, storage_js_1.getDefaultStorage)();
|
|
53
|
+
const cache = new pkce_generator_js_1.LocalStoragePkceCache(storage);
|
|
54
54
|
const authorizationCode = isMeshagentCallbackUrl(callbackUrl ?? window.location.href)
|
|
55
|
-
? (0,
|
|
55
|
+
? (0, mauth_response_js_1.getAuthorizationCode)()
|
|
56
56
|
: null;
|
|
57
57
|
if (authorizationCode) {
|
|
58
58
|
const exchangeCallbackUrl = getRedirectCallbackUrl(callbackUrl);
|
|
59
|
-
await (0,
|
|
59
|
+
await (0, mauth_response_js_1.exchangeToken)({
|
|
60
60
|
oauthClientId,
|
|
61
61
|
serverUrl: serverBaseUrl,
|
|
62
62
|
callbackUrl: exchangeCallbackUrl,
|
|
63
63
|
authorizationCode,
|
|
64
64
|
storage,
|
|
65
|
-
auth:
|
|
65
|
+
auth: meshagent_auth_js_1.MeshagentAuth.current,
|
|
66
66
|
});
|
|
67
67
|
await cache.clearVerifier();
|
|
68
68
|
replaceCurrentUrlWithoutAuthParams();
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
|
-
if (
|
|
72
|
-
const auth =
|
|
73
|
-
const client = (0,
|
|
71
|
+
if (meshagent_auth_js_1.MeshagentAuth.current.isLoggedIn()) {
|
|
72
|
+
const auth = meshagent_auth_js_1.MeshagentAuth.current;
|
|
73
|
+
const client = (0, mauth_response_js_2.getMeshagentClient)(auth, serverUrl ?? DEFAULT_SERVER_URL);
|
|
74
74
|
const me = await client.getUserProfile("me");
|
|
75
75
|
if (me) {
|
|
76
76
|
auth.setUser(me);
|
|
@@ -78,7 +78,7 @@ async function ensureLogin({ oauthClientId, serverUrl, callbackUrl, provider, })
|
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
80
|
const redirectCallbackUrl = getRedirectCallbackUrl(callbackUrl);
|
|
81
|
-
const generator = new
|
|
81
|
+
const generator = new pkce_generator_js_1.PkceGenerator();
|
|
82
82
|
const pkce = await generator.generate();
|
|
83
83
|
await cache.saveVerifier(pkce.codeVerifier);
|
|
84
84
|
const query = new URLSearchParams({
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from "./access-token-provider";
|
|
2
|
-
export * from "./ensure-login";
|
|
3
|
-
export * from "./mauth-response";
|
|
4
|
-
export * from "./meshagent-auth";
|
|
5
|
-
export * from "./oauth-session-manager";
|
|
6
|
-
export * from "./pkce-generator";
|
|
7
|
-
export * from "./storage";
|
|
1
|
+
export * from "./access-token-provider.js";
|
|
2
|
+
export * from "./ensure-login.js";
|
|
3
|
+
export * from "./mauth-response.js";
|
|
4
|
+
export * from "./meshagent-auth.js";
|
|
5
|
+
export * from "./oauth-session-manager.js";
|
|
6
|
+
export * from "./pkce-generator.js";
|
|
7
|
+
export * from "./storage.js";
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,10 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./access-token-provider"), exports);
|
|
18
|
-
__exportStar(require("./ensure-login"), exports);
|
|
19
|
-
__exportStar(require("./mauth-response"), exports);
|
|
20
|
-
__exportStar(require("./meshagent-auth"), exports);
|
|
21
|
-
__exportStar(require("./oauth-session-manager"), exports);
|
|
22
|
-
__exportStar(require("./pkce-generator"), exports);
|
|
23
|
-
__exportStar(require("./storage"), exports);
|
|
17
|
+
__exportStar(require("./access-token-provider.js"), exports);
|
|
18
|
+
__exportStar(require("./ensure-login.js"), exports);
|
|
19
|
+
__exportStar(require("./mauth-response.js"), exports);
|
|
20
|
+
__exportStar(require("./meshagent-auth.js"), exports);
|
|
21
|
+
__exportStar(require("./oauth-session-manager.js"), exports);
|
|
22
|
+
__exportStar(require("./pkce-generator.js"), exports);
|
|
23
|
+
__exportStar(require("./storage.js"), exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Meshagent } from "@meshagent/meshagent";
|
|
2
|
-
import { MeshagentAuth } from "./meshagent-auth";
|
|
3
|
-
import type { StorageLike } from "./storage";
|
|
2
|
+
import { MeshagentAuth } from "./meshagent-auth.js";
|
|
3
|
+
import type { StorageLike } from "./storage.js";
|
|
4
4
|
export declare function getAuthorizationCode(): string | null;
|
|
5
5
|
export declare function normalizedExpiresIn(expiresIn: unknown): number | null;
|
|
6
6
|
export declare function getMeshagentClient(auth: MeshagentAuth, serverUrl: URL | string): Meshagent;
|
|
@@ -5,9 +5,9 @@ exports.normalizedExpiresIn = normalizedExpiresIn;
|
|
|
5
5
|
exports.getMeshagentClient = getMeshagentClient;
|
|
6
6
|
exports.exchangeToken = exchangeToken;
|
|
7
7
|
const meshagent_1 = require("@meshagent/meshagent");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
8
|
+
const meshagent_auth_js_1 = require("./meshagent-auth.js");
|
|
9
|
+
const pkce_generator_js_1 = require("./pkce-generator.js");
|
|
10
|
+
const storage_js_1 = require("./storage.js");
|
|
11
11
|
function toUrl(value) {
|
|
12
12
|
return value instanceof URL ? value : new URL(value);
|
|
13
13
|
}
|
|
@@ -45,9 +45,9 @@ async function exchangeToken(props, signal) {
|
|
|
45
45
|
const serverUrl = toUrl(props.serverUrl);
|
|
46
46
|
const callbackUrl = toUrl(props.callbackUrl);
|
|
47
47
|
const authorizationCode = props.authorizationCode ?? getAuthorizationCode();
|
|
48
|
-
const storage = props.storage ?? (0,
|
|
49
|
-
const auth = props.auth ??
|
|
50
|
-
const cache = new
|
|
48
|
+
const storage = props.storage ?? (0, storage_js_1.getDefaultStorage)();
|
|
49
|
+
const auth = props.auth ?? meshagent_auth_js_1.MeshagentAuth.current;
|
|
50
|
+
const cache = new pkce_generator_js_1.LocalStoragePkceCache(storage);
|
|
51
51
|
if (!authorizationCode) {
|
|
52
52
|
throw new Error("Missing authorization code");
|
|
53
53
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.meshagentAuth = exports.MeshagentAuth = void 0;
|
|
4
|
-
const
|
|
4
|
+
const storage_js_1 = require("./storage.js");
|
|
5
5
|
const ACCESS_TOKEN_KEY = "ma:access_token";
|
|
6
6
|
const REFRESH_TOKEN_KEY = "ma:refresh_token";
|
|
7
7
|
const EXPIRATION_KEY = "ma:expiration";
|
|
@@ -28,7 +28,7 @@ function sameDate(left, right) {
|
|
|
28
28
|
return left.getTime() === right.getTime();
|
|
29
29
|
}
|
|
30
30
|
class MeshagentAuth {
|
|
31
|
-
constructor(storage = (0,
|
|
31
|
+
constructor(storage = (0, storage_js_1.getDefaultStorage)()) {
|
|
32
32
|
Object.defineProperty(this, "storage", {
|
|
33
33
|
enumerable: true,
|
|
34
34
|
configurable: true,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OAuthSessionManager = void 0;
|
|
4
|
-
const
|
|
4
|
+
const meshagent_auth_js_1 = require("./meshagent-auth.js");
|
|
5
5
|
function toUrl(value) {
|
|
6
6
|
return value instanceof URL ? value : new URL(value);
|
|
7
7
|
}
|
|
8
8
|
class OAuthSessionManager {
|
|
9
|
-
constructor({ serverUrl, clientId, clientSecret, refreshSkew = 2 * 60 * 1000, minValidFor = 8 * 60 * 60 * 1000, auth =
|
|
9
|
+
constructor({ serverUrl, clientId, clientSecret, refreshSkew = 2 * 60 * 1000, minValidFor = 8 * 60 * 60 * 1000, auth = meshagent_auth_js_1.meshagentAuth, }) {
|
|
10
10
|
Object.defineProperty(this, "serverUrl", {
|
|
11
11
|
enumerable: true,
|
|
12
12
|
configurable: true,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PkceGenerator = exports.LocalStoragePkceCache = void 0;
|
|
4
|
-
const
|
|
4
|
+
const storage_js_1 = require("./storage.js");
|
|
5
5
|
const PKCE_VERIFIER_KEY = "cv";
|
|
6
6
|
class LocalStoragePkceCache {
|
|
7
|
-
constructor(storage = (0,
|
|
7
|
+
constructor(storage = (0, storage_js_1.getDefaultStorage)()) {
|
|
8
8
|
Object.defineProperty(this, "storage", {
|
|
9
9
|
enumerable: true,
|
|
10
10
|
configurable: true,
|
package/dist/esm/ensure-login.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { LocalStoragePkceCache, PkceGenerator } from "./pkce-generator";
|
|
2
|
-
import { exchangeToken, getAuthorizationCode } from "./mauth-response";
|
|
3
|
-
import { MeshagentAuth } from "./meshagent-auth";
|
|
4
|
-
import { getDefaultStorage } from "./storage";
|
|
5
|
-
import { getMeshagentClient } from "./mauth-response";
|
|
1
|
+
import { LocalStoragePkceCache, PkceGenerator } from "./pkce-generator.js";
|
|
2
|
+
import { exchangeToken, getAuthorizationCode } from "./mauth-response.js";
|
|
3
|
+
import { MeshagentAuth } from "./meshagent-auth.js";
|
|
4
|
+
import { getDefaultStorage } from "./storage.js";
|
|
5
|
+
import { getMeshagentClient } from "./mauth-response.js";
|
|
6
6
|
const DEFAULT_SERVER_URL = "https://api.meshagent.com";
|
|
7
7
|
function getCurrentUrl() {
|
|
8
8
|
if (typeof window === "undefined") {
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from "./access-token-provider";
|
|
2
|
-
export * from "./ensure-login";
|
|
3
|
-
export * from "./mauth-response";
|
|
4
|
-
export * from "./meshagent-auth";
|
|
5
|
-
export * from "./oauth-session-manager";
|
|
6
|
-
export * from "./pkce-generator";
|
|
7
|
-
export * from "./storage";
|
|
1
|
+
export * from "./access-token-provider.js";
|
|
2
|
+
export * from "./ensure-login.js";
|
|
3
|
+
export * from "./mauth-response.js";
|
|
4
|
+
export * from "./meshagent-auth.js";
|
|
5
|
+
export * from "./oauth-session-manager.js";
|
|
6
|
+
export * from "./pkce-generator.js";
|
|
7
|
+
export * from "./storage.js";
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from "./access-token-provider";
|
|
2
|
-
export * from "./ensure-login";
|
|
3
|
-
export * from "./mauth-response";
|
|
4
|
-
export * from "./meshagent-auth";
|
|
5
|
-
export * from "./oauth-session-manager";
|
|
6
|
-
export * from "./pkce-generator";
|
|
7
|
-
export * from "./storage";
|
|
1
|
+
export * from "./access-token-provider.js";
|
|
2
|
+
export * from "./ensure-login.js";
|
|
3
|
+
export * from "./mauth-response.js";
|
|
4
|
+
export * from "./meshagent-auth.js";
|
|
5
|
+
export * from "./oauth-session-manager.js";
|
|
6
|
+
export * from "./pkce-generator.js";
|
|
7
|
+
export * from "./storage.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Meshagent } from "@meshagent/meshagent";
|
|
2
|
-
import { MeshagentAuth } from "./meshagent-auth";
|
|
3
|
-
import type { StorageLike } from "./storage";
|
|
2
|
+
import { MeshagentAuth } from "./meshagent-auth.js";
|
|
3
|
+
import type { StorageLike } from "./storage.js";
|
|
4
4
|
export declare function getAuthorizationCode(): string | null;
|
|
5
5
|
export declare function normalizedExpiresIn(expiresIn: unknown): number | null;
|
|
6
6
|
export declare function getMeshagentClient(auth: MeshagentAuth, serverUrl: URL | string): Meshagent;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Meshagent } from "@meshagent/meshagent";
|
|
2
|
-
import { MeshagentAuth } from "./meshagent-auth";
|
|
3
|
-
import { LocalStoragePkceCache } from "./pkce-generator";
|
|
4
|
-
import { getDefaultStorage } from "./storage";
|
|
2
|
+
import { MeshagentAuth } from "./meshagent-auth.js";
|
|
3
|
+
import { LocalStoragePkceCache } from "./pkce-generator.js";
|
|
4
|
+
import { getDefaultStorage } from "./storage.js";
|
|
5
5
|
function toUrl(value) {
|
|
6
6
|
return value instanceof URL ? value : new URL(value);
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshagent/meshagent-ts-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.1",
|
|
4
4
|
"description": "Meshagent Typescript Auth",
|
|
5
5
|
"homepage": "https://github.com/meshagent/meshagent-ts-auth",
|
|
6
6
|
"scripts": {
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"test": "jest",
|
|
9
9
|
"test:watch": "jest --watch"
|
|
10
10
|
},
|
|
11
|
-
"author": "
|
|
11
|
+
"author": "Timu, LLC",
|
|
12
12
|
"license": "Apache-2.0",
|
|
13
13
|
"type": "module",
|
|
14
14
|
"unpkg": "./dist/browser/ma-auth.global.js",
|
|
15
15
|
"jsdelivr": "./dist/browser/ma-auth.global.js",
|
|
16
16
|
"module": "dist/esm/index.js",
|
|
17
|
-
"main": "./dist/
|
|
17
|
+
"main": "./dist/cjs/index.js",
|
|
18
18
|
"types": "dist/esm/index.d.ts",
|
|
19
19
|
"typesVersions": {
|
|
20
20
|
"*": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"CHANGELOG.md"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@meshagent/meshagent": "^0.
|
|
42
|
+
"@meshagent/meshagent": "^0.43.1",
|
|
43
43
|
"typescript": "^5.8.3"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|