@ztimson/momentum 0.36.2 → 0.37.0
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/dist/auth.d.ts +2 -2
- package/dist/auth.d.ts.map +1 -1
- package/dist/index.cjs +13 -8
- package/dist/index.mjs +13 -8
- package/package.json +1 -1
package/dist/auth.d.ts
CHANGED
|
@@ -22,14 +22,14 @@ export declare class Totp {
|
|
|
22
22
|
setup(username: string, method?: string, totp?: string): import('@ztimson/utils').PromiseProgress<void>;
|
|
23
23
|
}
|
|
24
24
|
export declare class Auth extends TypedEmitter<AuthEvents> {
|
|
25
|
-
private readonly opts
|
|
25
|
+
private readonly opts;
|
|
26
26
|
private readonly api;
|
|
27
27
|
private readonly storageKey;
|
|
28
28
|
totp: Totp;
|
|
29
29
|
$user: BehaviorSubject<User | null | undefined>;
|
|
30
30
|
get user(): User | null | undefined;
|
|
31
31
|
set user(user: User | null | undefined);
|
|
32
|
-
constructor(api: Api | string, opts?: AuthOptions
|
|
32
|
+
constructor(api: Api | string, opts?: AuthOptions);
|
|
33
33
|
knownHost(host?: string): Promise<void>;
|
|
34
34
|
login(username: string, password: string, totp?: string): Promise<User | null>;
|
|
35
35
|
loginRedirect(host?: string): Promise<string>;
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,MAAM,CAAC;AACrC,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAiB,YAAY,EAAE,KAAK,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC9E,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,SAAS,CAAC;AAElC,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG;IACtC,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK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;IAMR,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAOtF,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IACtD,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY7B,OAAO,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,UAAQ,GAAG,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,IAAI,CAAC;QAAC,WAAW,EAAE,MAAM,EAAE,CAAA;KAAC,GAAG,IAAI,CAAC;IAexG,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAQ7F"}
|
package/dist/index.cjs
CHANGED
|
@@ -1261,8 +1261,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1261
1261
|
}
|
|
1262
1262
|
}
|
|
1263
1263
|
class Auth extends F {
|
|
1264
|
-
constructor(api, opts) {
|
|
1265
|
-
var _a;
|
|
1264
|
+
constructor(api, opts = {}) {
|
|
1266
1265
|
super();
|
|
1267
1266
|
__publicField(this, "api");
|
|
1268
1267
|
__publicField(this, "storageKey");
|
|
@@ -1271,7 +1270,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1271
1270
|
this.opts = opts;
|
|
1272
1271
|
this.api = typeof api == "string" ? new Api(api) : api;
|
|
1273
1272
|
this.totp = new Totp(this.api);
|
|
1274
|
-
|
|
1273
|
+
this.opts = {
|
|
1274
|
+
loginUi: this.api.url + "/ui/#/login",
|
|
1275
|
+
persist: true,
|
|
1276
|
+
...this.opts
|
|
1277
|
+
};
|
|
1275
1278
|
this.storageKey = `momentum:${new URL(this.api.url).host}`;
|
|
1276
1279
|
this.api.addInterceptor((resp, next) => {
|
|
1277
1280
|
const blacklist = [
|
|
@@ -1284,8 +1287,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1284
1287
|
next();
|
|
1285
1288
|
});
|
|
1286
1289
|
this.api.on("TOKEN", (token) => {
|
|
1287
|
-
var
|
|
1288
|
-
if ((
|
|
1290
|
+
var _a;
|
|
1291
|
+
if ((_a = this.opts) == null ? void 0 : _a.persist) {
|
|
1289
1292
|
if (token) localStorage.setItem(this.storageKey, token);
|
|
1290
1293
|
else localStorage.removeItem(this.storageKey);
|
|
1291
1294
|
}
|
|
@@ -1336,9 +1339,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1336
1339
|
var _a;
|
|
1337
1340
|
const win = window.open(encodeURI(`${(_a = this.opts) == null ? void 0 : _a.loginUi}?redirect=postmessage&host=${host}`), "_blank");
|
|
1338
1341
|
if (!win) return rej("Unable to open login");
|
|
1342
|
+
const origin = new URL(this.opts.loginUi).origin;
|
|
1339
1343
|
win.addEventListener("message", (event) => {
|
|
1340
|
-
|
|
1341
|
-
if (
|
|
1344
|
+
const data = (event == null ? void 0 : event.data) || {};
|
|
1345
|
+
if (event.origin != data.sender || data.sender != origin) return;
|
|
1346
|
+
if (!data.token) return rej("Unknown response from login");
|
|
1342
1347
|
this.api.token = event.data.token;
|
|
1343
1348
|
res(event.data.token);
|
|
1344
1349
|
win.close();
|
|
@@ -1721,7 +1726,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1721
1726
|
}
|
|
1722
1727
|
upload(files, opts = "") {
|
|
1723
1728
|
return new m(async (res, rej, prog) => {
|
|
1724
|
-
if (!files) files = await It();
|
|
1729
|
+
if (!files) files = await It(typeof opts == "object" ? opts : void 0);
|
|
1725
1730
|
if (!files || Array.isArray(files) && !files.length) return [];
|
|
1726
1731
|
const url = this.api.url + ("/api/storage/" + ((typeof opts == "string" ? opts : opts == null ? void 0 : opts.path) || "")).replaceAll("//", "/");
|
|
1727
1732
|
return $t({
|
package/dist/index.mjs
CHANGED
|
@@ -1257,8 +1257,7 @@ class Totp {
|
|
|
1257
1257
|
}
|
|
1258
1258
|
}
|
|
1259
1259
|
class Auth extends F {
|
|
1260
|
-
constructor(api, opts) {
|
|
1261
|
-
var _a;
|
|
1260
|
+
constructor(api, opts = {}) {
|
|
1262
1261
|
super();
|
|
1263
1262
|
__publicField(this, "api");
|
|
1264
1263
|
__publicField(this, "storageKey");
|
|
@@ -1267,7 +1266,11 @@ class Auth extends F {
|
|
|
1267
1266
|
this.opts = opts;
|
|
1268
1267
|
this.api = typeof api == "string" ? new Api(api) : api;
|
|
1269
1268
|
this.totp = new Totp(this.api);
|
|
1270
|
-
|
|
1269
|
+
this.opts = {
|
|
1270
|
+
loginUi: this.api.url + "/ui/#/login",
|
|
1271
|
+
persist: true,
|
|
1272
|
+
...this.opts
|
|
1273
|
+
};
|
|
1271
1274
|
this.storageKey = `momentum:${new URL(this.api.url).host}`;
|
|
1272
1275
|
this.api.addInterceptor((resp, next) => {
|
|
1273
1276
|
const blacklist = [
|
|
@@ -1280,8 +1283,8 @@ class Auth extends F {
|
|
|
1280
1283
|
next();
|
|
1281
1284
|
});
|
|
1282
1285
|
this.api.on("TOKEN", (token) => {
|
|
1283
|
-
var
|
|
1284
|
-
if ((
|
|
1286
|
+
var _a;
|
|
1287
|
+
if ((_a = this.opts) == null ? void 0 : _a.persist) {
|
|
1285
1288
|
if (token) localStorage.setItem(this.storageKey, token);
|
|
1286
1289
|
else localStorage.removeItem(this.storageKey);
|
|
1287
1290
|
}
|
|
@@ -1332,9 +1335,11 @@ class Auth extends F {
|
|
|
1332
1335
|
var _a;
|
|
1333
1336
|
const win = window.open(encodeURI(`${(_a = this.opts) == null ? void 0 : _a.loginUi}?redirect=postmessage&host=${host}`), "_blank");
|
|
1334
1337
|
if (!win) return rej("Unable to open login");
|
|
1338
|
+
const origin = new URL(this.opts.loginUi).origin;
|
|
1335
1339
|
win.addEventListener("message", (event) => {
|
|
1336
|
-
|
|
1337
|
-
if (
|
|
1340
|
+
const data = (event == null ? void 0 : event.data) || {};
|
|
1341
|
+
if (event.origin != data.sender || data.sender != origin) return;
|
|
1342
|
+
if (!data.token) return rej("Unknown response from login");
|
|
1338
1343
|
this.api.token = event.data.token;
|
|
1339
1344
|
res(event.data.token);
|
|
1340
1345
|
win.close();
|
|
@@ -1717,7 +1722,7 @@ class Storage extends F {
|
|
|
1717
1722
|
}
|
|
1718
1723
|
upload(files, opts = "") {
|
|
1719
1724
|
return new m(async (res, rej, prog) => {
|
|
1720
|
-
if (!files) files = await It();
|
|
1725
|
+
if (!files) files = await It(typeof opts == "object" ? opts : void 0);
|
|
1721
1726
|
if (!files || Array.isArray(files) && !files.length) return [];
|
|
1722
1727
|
const url = this.api.url + ("/api/storage/" + ((typeof opts == "string" ? opts : opts == null ? void 0 : opts.path) || "")).replaceAll("//", "/");
|
|
1723
1728
|
return $t({
|