@ztimson/momentum 1.4.5 → 1.5.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/api.d.ts.map +1 -1
- package/dist/captcha.d.ts.map +1 -1
- package/dist/client.d.ts +23 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/data.d.ts +18 -12
- package/dist/data.d.ts.map +1 -1
- package/dist/index.js +156 -66
- package/dist/index.mjs +156 -66
- package/dist/routes.d.ts +1 -0
- package/dist/routes.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,IAAI,EACJ,kBAAkB,EAClB,iBAAiB,EAEjB,eAAe,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,8BAA8B;AAC9B,MAAM,MAAM,MAAM,GAAG;IACpB,sBAAsB;IACtB,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,GAAG,UAAU,GAAG,OAAO,CAAC;IACzD,qBAAqB;IACrB,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,gBAAgB;IAChB,QAAQ,CAAC,EAAE,EAAE,YAAY,CAAC;IAC1B,sBAAsB;IACtB,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,mBAAmB;IACnB,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,sBAAsB;IACtB,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,mBAAmB;IACnB,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,yBAAyB;IACzB,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,qBAAqB;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,kBAA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IAUtC,IAAI,kEAAwC;IAC5C,GAAG,4DAAuC;IAC1C,EAAE,0KAAsC;IACxC,IAAI,+IAAwC;IAC5C,WAAW,uCAA+C;IAE1D;;;OAGG;IACH,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAI9B;;;;OAIG;IACH,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,kBAAkB,GAAG,eAAe,CAAC,CAAC,CAAC;CA4C3D"}
|
package/dist/captcha.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"captcha.d.ts","sourceRoot":"","sources":["../src/captcha.ts"],"names":[],"mappings":"AAAA,qBAAa,OAAO;IACnB,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,MAAM,CAAoF;IAClG,OAAO,CAAC,SAAS,CAAkD;IACnE,OAAO,CAAC,UAAU,CAAgB;IAElC,OAAO,CAAC,MAAM,CAAO;IACrB,OAAO,KAAK,KAAK,QAAwB;IACzC,IAAI,KAAK,WAA0B;IAEnC,IAAI,OAAO,IAAI,SAAS,GAAG,OAAO,GAAG,KAAK,CAIzC;;IAsCD,OAAO,CAAC,cAAc;IAStB,MAAM;
|
|
1
|
+
{"version":3,"file":"captcha.d.ts","sourceRoot":"","sources":["../src/captcha.ts"],"names":[],"mappings":"AAAA,qBAAa,OAAO;IACnB,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,MAAM,CAAoF;IAClG,OAAO,CAAC,SAAS,CAAkD;IACnE,OAAO,CAAC,UAAU,CAAgB;IAElC,OAAO,CAAC,MAAM,CAAO;IACrB,OAAO,KAAK,KAAK,QAAwB;IACzC,IAAI,KAAK,WAA0B;IAEnC,IAAI,OAAO,IAAI,SAAS,GAAG,OAAO,GAAG,KAAK,CAIzC;;IAsCD,OAAO,CAAC,cAAc;IAStB,MAAM;CAsFN"}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
import { Momentum } from './momentum';
|
|
2
2
|
import { PathEventEmitter } from './core';
|
|
3
3
|
export type Platform = 'windows' | 'android' | 'ios' | 'mac' | 'linux' | 'unknown';
|
|
4
|
+
export type Theme = {
|
|
5
|
+
background: string;
|
|
6
|
+
backgroundContrast: string;
|
|
7
|
+
surface: string;
|
|
8
|
+
border: string;
|
|
9
|
+
text: string;
|
|
10
|
+
muted: string;
|
|
11
|
+
primary: string;
|
|
12
|
+
primaryContrast: string;
|
|
13
|
+
accent: string;
|
|
14
|
+
accentContrast: string;
|
|
15
|
+
info: string;
|
|
16
|
+
success: string;
|
|
17
|
+
warn: string;
|
|
18
|
+
danger: string;
|
|
19
|
+
black: string;
|
|
20
|
+
white: string;
|
|
21
|
+
font: string;
|
|
22
|
+
lighter: string;
|
|
23
|
+
darker: string;
|
|
24
|
+
};
|
|
4
25
|
/** Handle device settings */
|
|
5
26
|
export declare class Client extends PathEventEmitter {
|
|
6
27
|
protected momentum: Momentum;
|
|
@@ -34,6 +55,8 @@ export declare class Client extends PathEventEmitter {
|
|
|
34
55
|
get platform(): Platform;
|
|
35
56
|
get storage(): boolean;
|
|
36
57
|
constructor(momentum: Momentum);
|
|
58
|
+
static theme(setting: any, css: true): string;
|
|
59
|
+
static theme(setting: any, css?: false): Theme;
|
|
37
60
|
/**
|
|
38
61
|
* Inject the client theme settings, meta tags & PWA prompt
|
|
39
62
|
* @param opts Injection options: reload - use cached settings or reload; pwa - disabled auto pwa prompt
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,gBAAgB,EAAM,MAAM,QAAQ,CAAA;AAE5C,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG,OAAO,GAAG,SAAS,CAAC;AAEnF,6BAA6B;AAC7B,qB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CAAyC;IACzC,MAAM;CAUN"}
|
package/dist/data.d.ts
CHANGED
|
@@ -62,23 +62,14 @@ export declare class Data extends PathEventEmitter {
|
|
|
62
62
|
* @param {Document<T> | Document<T>[]} documents New document(s)
|
|
63
63
|
* @return {Promise<Document<T> | Document<T>[]>} New saved document(s)
|
|
64
64
|
*/
|
|
65
|
-
create<T>(collection: string, documents: Document<T>
|
|
66
|
-
|
|
67
|
-
* Delete document(s) from collection
|
|
68
|
-
* @param {string} collection Target collection
|
|
69
|
-
* @param {number | Filter<T>} filter Document ID or filter object
|
|
70
|
-
* @param {DeleteOptions} options Delete options
|
|
71
|
-
* @return {Promise<number[]>} Array of deleted document IDs
|
|
72
|
-
*/
|
|
73
|
-
delete(collection: string, id: number, options?: DeleteOptions): Promise<number[]>;
|
|
74
|
-
delete(collection: string, ids: number[], options?: DeleteOptions): Promise<number[]>;
|
|
75
|
-
delete<T>(collection: string, filter: Filter<T>, options?: DeleteOptions): Promise<number[]>;
|
|
65
|
+
create<T>(collection: string, documents: Document<T>): Promise<Document<T>>;
|
|
66
|
+
create<T>(collection: string, documents: Document<T>[]): Promise<Document<T>[]>;
|
|
76
67
|
/**
|
|
77
68
|
* Read document(s) from collection
|
|
78
69
|
* @param {string} collection Target collection
|
|
79
70
|
* @param {number | Filter<T>} filter Document ID or filter object
|
|
80
71
|
* @param {ReadOptions} options Read options (limit, page, sortBy, sortDir)
|
|
81
|
-
* @return {Promise<T | T[]>} Single document if ID provided, array
|
|
72
|
+
* @return {Promise<T | T[]>} Single document if numeric ID provided, array otherwise
|
|
82
73
|
*/
|
|
83
74
|
read<T extends Meta>(collection: string, filter?: undefined, options?: ReadOptions): Promise<T[]>;
|
|
84
75
|
read<T extends Meta>(collection: string, filter?: number, options?: ReadOptions): Promise<T>;
|
|
@@ -90,7 +81,22 @@ export declare class Data extends PathEventEmitter {
|
|
|
90
81
|
* @param {UpdateOptions<T>} options Update options (filter, append, limit, upsert)
|
|
91
82
|
* @return {Promise<Document<T> | Document<T>[]>} Updated document(s)
|
|
92
83
|
*/
|
|
84
|
+
update<T>(collection: string, documents: Document<T>, options?: UpdateOptions<T>): Promise<Document<T>>;
|
|
85
|
+
update<T>(collection: string, documents: Document<T>[], options?: UpdateOptions<T>): Promise<Document<T>[]>;
|
|
86
|
+
update<T>(collection: string, documents: Partial<T>, options: UpdateOptions<T> & {
|
|
87
|
+
filter: Filter<T>;
|
|
88
|
+
}): Promise<Document<T>[]>;
|
|
93
89
|
update<T>(collection: string, documents: Document<T> | Document<T>[], options?: UpdateOptions<T>): Promise<Document<T> | Document<T>[]>;
|
|
90
|
+
/**
|
|
91
|
+
* Delete document(s) from collection
|
|
92
|
+
* @param {string} collection Target collection
|
|
93
|
+
* @param {number | Filter<T>} filter Document ID or filter object
|
|
94
|
+
* @param {DeleteOptions} options Delete options
|
|
95
|
+
* @return {Promise<number[]>} Array of deleted document IDs
|
|
96
|
+
*/
|
|
97
|
+
delete(collection: string, id: number, options?: DeleteOptions): Promise<number[]>;
|
|
98
|
+
delete(collection: string, ids: number[], options?: DeleteOptions): Promise<number[]>;
|
|
99
|
+
delete<T>(collection: string, filter: Filter<T>, options?: DeleteOptions): Promise<number[]>;
|
|
94
100
|
/**
|
|
95
101
|
* Execute raw MongoDB query
|
|
96
102
|
* @param {string} collection Target collection name
|
package/dist/data.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../src/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAC,KAAK,IAAI,EAAE,gBAAgB,EAAM,MAAM,QAAQ,CAAC;AACxD,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,uCAAuC;AACvC,MAAM,MAAM,cAAc,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,KAA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AAM,EAAE,CAAC;IACrF,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAkB5F;;;;;OAKG;IACH,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IASzD;;;;;;OAMG;IACH,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,IAAI,GAAE;QAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAM,GAAG,WAAW;CAmBtG"}
|
package/dist/index.js
CHANGED
|
@@ -455,6 +455,9 @@
|
|
|
455
455
|
complete = false;
|
|
456
456
|
/** Await initial loading */
|
|
457
457
|
loading = new Promise((r) => this._loading = r);
|
|
458
|
+
get size() {
|
|
459
|
+
return this.store.keys().toArray().length;
|
|
460
|
+
}
|
|
458
461
|
getKey(value) {
|
|
459
462
|
if (!this.key) throw new Error("No key defined");
|
|
460
463
|
if (value[this.key] === void 0) throw new Error(`${this.key.toString()} Doesn't exist on ${JSON.stringify(value, null, 2)}`);
|
|
@@ -640,6 +643,10 @@
|
|
|
640
643
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
641
644
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + " " + sizes[i];
|
|
642
645
|
}
|
|
646
|
+
function kebabCase(str) {
|
|
647
|
+
if (!str) return "";
|
|
648
|
+
return wordSegments(str).map((w) => w.toLowerCase()).join("-");
|
|
649
|
+
}
|
|
643
650
|
function randomStringBuilder(length, letters = false, numbers = false, symbols = false) {
|
|
644
651
|
if (!letters && !numbers && !symbols) throw new Error("Must enable at least one: letters, numbers, symbols");
|
|
645
652
|
return Array(length).fill(null).map(() => {
|
|
@@ -657,6 +664,10 @@
|
|
|
657
664
|
return c;
|
|
658
665
|
}).join("");
|
|
659
666
|
}
|
|
667
|
+
function wordSegments(str) {
|
|
668
|
+
if (!str) return [];
|
|
669
|
+
return str.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/([0-9]+)([a-zA-Z])/g, "$1 $2").replace(/([a-zA-Z])([0-9]+)/g, "$1 $2").replace(/[_\-\s]+/g, " ").trim().split(/\s+/).filter(Boolean);
|
|
670
|
+
}
|
|
660
671
|
function dayOfWeek(d) {
|
|
661
672
|
return ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][d];
|
|
662
673
|
}
|
|
@@ -823,6 +834,9 @@
|
|
|
823
834
|
async function sleepWhile(fn2, checkInterval = 100) {
|
|
824
835
|
while (await fn2()) await sleep(checkInterval);
|
|
825
836
|
}
|
|
837
|
+
function timeUntil(date) {
|
|
838
|
+
return (date instanceof Date ? date.getTime() : date) - (/* @__PURE__ */ new Date()).getTime();
|
|
839
|
+
}
|
|
826
840
|
class AsyncLock {
|
|
827
841
|
p = Promise.resolve();
|
|
828
842
|
run(fn2) {
|
|
@@ -2508,8 +2522,31 @@
|
|
|
2508
2522
|
options.headers["X-Captcha"] = (+this.momentum.client.captchaScore.toFixed(2)).toString();
|
|
2509
2523
|
}
|
|
2510
2524
|
this.pending[key] = super.request({ ...options, credentials: "include" }).then((response) => {
|
|
2525
|
+
function _d(obj, secret) {
|
|
2526
|
+
const xor = secret % 128 || 127;
|
|
2527
|
+
if (typeof obj === "boolean") return Boolean((obj ? 1 : 0) ^ xor & 1);
|
|
2528
|
+
if (typeof obj === "string") {
|
|
2529
|
+
const decrypted = Array.from(obj).map((c) => String.fromCharCode(c.charCodeAt(0) ^ xor)).join("");
|
|
2530
|
+
const num = Number(decrypted);
|
|
2531
|
+
if (!isNaN(num) && decrypted.trim() !== "") return num;
|
|
2532
|
+
const date = new Date(decrypted);
|
|
2533
|
+
if (!isNaN(date.getTime()) && decrypted.includes("T")) return date;
|
|
2534
|
+
return decrypted;
|
|
2535
|
+
}
|
|
2536
|
+
if (Array.isArray(obj)) return obj.map((v) => _d(v, secret));
|
|
2537
|
+
if (typeof obj === "object" && obj !== null) return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, _d(v, secret)]));
|
|
2538
|
+
return obj;
|
|
2539
|
+
}
|
|
2540
|
+
const hasDate = response.headers.get("Access-Control-Expose-Headers");
|
|
2541
|
+
const cacheDate = response.headers.get("date");
|
|
2511
2542
|
this.emit(`response:${method}`, { request: options, response });
|
|
2512
|
-
|
|
2543
|
+
if (options.decode === false) {
|
|
2544
|
+
return response;
|
|
2545
|
+
} else if (this.sameOrigin ? hasDate : cacheDate) {
|
|
2546
|
+
return _d(response.data, new Date(cacheDate).getTime());
|
|
2547
|
+
} else {
|
|
2548
|
+
return response.data;
|
|
2549
|
+
}
|
|
2513
2550
|
}).catch((err) => {
|
|
2514
2551
|
const e = err?.data || err;
|
|
2515
2552
|
this.emit(`error:${method}`, { request: options, error: e });
|
|
@@ -2666,7 +2703,7 @@ Must be either: call, email or sms`);
|
|
|
2666
2703
|
password: password?.trim(),
|
|
2667
2704
|
totp: opts?.totp ? opts.totp.toString() : void 0,
|
|
2668
2705
|
totpMethod: opts?.totpMethod,
|
|
2669
|
-
expire: opts?.expire
|
|
2706
|
+
expire: !!opts?.expire ? opts.expire instanceof Date ? ~~(timeUntil(opts.expire) / 1e3) : opts.expire : void 0
|
|
2670
2707
|
}, true)
|
|
2671
2708
|
}).then(async (resp) => {
|
|
2672
2709
|
if (resp?.token) await this.readSession(resp.token, true);
|
|
@@ -2849,37 +2886,73 @@ Must be either: call, email or sms`);
|
|
|
2849
2886
|
return ua.length > 20 && ua.length < 1e3;
|
|
2850
2887
|
}
|
|
2851
2888
|
update() {
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2889
|
+
if (navigator.webdriver) {
|
|
2890
|
+
this.score = 0;
|
|
2891
|
+
return;
|
|
2892
|
+
}
|
|
2893
|
+
let delta = 0;
|
|
2894
|
+
const elapsed = (Date.now() - this.start) / 1e3;
|
|
2895
|
+
delta += elapsed > 30 ? 0.08 : elapsed > 10 ? 0.04 : elapsed > 3 ? 0.01 : -0.05;
|
|
2896
|
+
if (this.events.mouse.length >= 5) {
|
|
2897
|
+
const recent = this.events.mouse.slice(-20);
|
|
2858
2898
|
let changes = 0;
|
|
2899
|
+
let maxStraightRun = 0;
|
|
2900
|
+
let currentRun = 0;
|
|
2859
2901
|
for (let i = 2; i < recent.length; i++) {
|
|
2860
2902
|
const a1 = Math.atan2(recent[i - 1].y - recent[i - 2].y, recent[i - 1].x - recent[i - 2].x);
|
|
2861
2903
|
const a2 = Math.atan2(recent[i].y - recent[i - 1].y, recent[i].x - recent[i - 1].x);
|
|
2862
|
-
if (Math.abs(a1 - a2) > 0.
|
|
2904
|
+
if (Math.abs(a1 - a2) > 0.3) {
|
|
2905
|
+
changes++;
|
|
2906
|
+
currentRun = 0;
|
|
2907
|
+
} else {
|
|
2908
|
+
currentRun++;
|
|
2909
|
+
maxStraightRun = Math.max(maxStraightRun, currentRun);
|
|
2910
|
+
}
|
|
2863
2911
|
}
|
|
2864
|
-
|
|
2912
|
+
const entropy = changes / (recent.length - 2);
|
|
2913
|
+
if (entropy > 0.4) delta += 0.12;
|
|
2914
|
+
else if (entropy > 0.2) delta += 0.05;
|
|
2915
|
+
else delta -= 0.08;
|
|
2916
|
+
if (maxStraightRun > 8) delta -= 0.1;
|
|
2917
|
+
} else if (this.events.mouse.length === 0) {
|
|
2918
|
+
delta -= 0.03;
|
|
2865
2919
|
}
|
|
2866
|
-
|
|
2867
|
-
if (this.velocities.length > 5) {
|
|
2920
|
+
if (this.velocities.length >= 5) {
|
|
2868
2921
|
const avg = this.velocities.reduce((a, b) => a + b, 0) / this.velocities.length;
|
|
2869
|
-
|
|
2922
|
+
const variance = this.velocities.reduce((a, b) => a + Math.pow(b - avg, 2), 0) / this.velocities.length;
|
|
2923
|
+
const stdDev = Math.sqrt(variance);
|
|
2924
|
+
const cv = avg > 0 ? stdDev / avg : 0;
|
|
2925
|
+
if (cv > 0.4) delta += 0.1;
|
|
2926
|
+
else if (cv > 0.15) delta += 0.04;
|
|
2927
|
+
else if (avg > 0) delta -= 0.1;
|
|
2870
2928
|
}
|
|
2871
|
-
|
|
2872
|
-
|
|
2929
|
+
if (this.events.clicks.length > 0) {
|
|
2930
|
+
const lastClick = this.events.clicks[this.events.clicks.length - 1];
|
|
2931
|
+
const mouseBeforeClick = this.events.mouse.some(
|
|
2932
|
+
(m) => m.t < lastClick.t && lastClick.t - m.t < 2e3
|
|
2933
|
+
);
|
|
2934
|
+
delta += mouseBeforeClick ? 0.08 : -0.12;
|
|
2935
|
+
const suspiciousClicks = this.events.clicks.filter(
|
|
2936
|
+
(c) => Number.isInteger(c.x) && Number.isInteger(c.y) && c.x % 10 === 0 && c.y % 10 === 0
|
|
2937
|
+
// rounded coords = likely synthetic
|
|
2938
|
+
).length;
|
|
2939
|
+
if (suspiciousClicks / this.events.clicks.length > 0.5) delta -= 0.08;
|
|
2940
|
+
}
|
|
2941
|
+
if (this.events.keys.length >= 3) {
|
|
2873
2942
|
const intervals = [];
|
|
2874
2943
|
for (let i = 1; i < this.events.keys.length; i++) {
|
|
2875
2944
|
intervals.push(this.events.keys[i] - this.events.keys[i - 1]);
|
|
2876
2945
|
}
|
|
2877
|
-
const
|
|
2878
|
-
|
|
2946
|
+
const avg = intervals.reduce((a, b) => a + b, 0) / intervals.length;
|
|
2947
|
+
const stdDev = Math.sqrt(intervals.reduce((a, b) => a + Math.pow(b - avg, 2), 0) / intervals.length);
|
|
2948
|
+
if (avg < 20) delta -= 0.15;
|
|
2949
|
+
else if (stdDev < 5) delta -= 0.12;
|
|
2950
|
+
else if (avg < 50) delta -= 0.05;
|
|
2951
|
+
else if (avg < 1e3 && stdDev > 20) delta += 0.1;
|
|
2879
2952
|
}
|
|
2880
|
-
const
|
|
2881
|
-
this.score = this.score * 0.
|
|
2882
|
-
this.score = Math.max(0.
|
|
2953
|
+
const raw = this.score + delta;
|
|
2954
|
+
this.score = this.score * 0.75 + raw * 0.25;
|
|
2955
|
+
this.score = Math.max(0.05, Math.min(0.95, this.score));
|
|
2883
2956
|
}
|
|
2884
2957
|
}
|
|
2885
2958
|
class Client extends PathEventEmitter {
|
|
@@ -2980,6 +3053,42 @@ Must be either: call, email or sms`);
|
|
|
2980
3053
|
get storage() {
|
|
2981
3054
|
return typeof localStorage != "undefined";
|
|
2982
3055
|
}
|
|
3056
|
+
static theme(setting, css = false) {
|
|
3057
|
+
const t = {
|
|
3058
|
+
background: setting?.background,
|
|
3059
|
+
backgroundContrast: contrast(setting?.background),
|
|
3060
|
+
surface: setting?.darkMode ? "#2e2e2e" : "#ffffff",
|
|
3061
|
+
border: setting?.darkMode ? "#374151" : "#E5E7EB",
|
|
3062
|
+
text: setting?.darkMode ? "#ffffff" : "#000000",
|
|
3063
|
+
muted: setting?.darkMode ? "#cccccc" : "#6c757d",
|
|
3064
|
+
primary: setting?.primary,
|
|
3065
|
+
primaryContrast: contrast(setting?.primary),
|
|
3066
|
+
accent: setting?.accent,
|
|
3067
|
+
accentContrast: contrast(setting?.accent),
|
|
3068
|
+
info: "#6157cc",
|
|
3069
|
+
success: "#65c147",
|
|
3070
|
+
warn: "#d88750",
|
|
3071
|
+
danger: "#bf4f4f",
|
|
3072
|
+
black: "black",
|
|
3073
|
+
white: "white",
|
|
3074
|
+
font: setting?.font,
|
|
3075
|
+
lighter: setting?.darkMode ? "rgba(255, 255, 255, 0.1)" : "rgba(255, 255, 255, 0.05)",
|
|
3076
|
+
darker: setting?.darkMode ? "rgba(0, 0, 0, 0.1)" : "rgba(0, 0, 0, 0.05)"
|
|
3077
|
+
};
|
|
3078
|
+
if (!css) return t;
|
|
3079
|
+
return `:root, :root .theme-${setting?.darkMode ? "dark" : "light"} {
|
|
3080
|
+
${Object.entries(t).map(([name, value]) => `--theme-${kebabCase(name)}: ${value} !important;`).join("\n")}
|
|
3081
|
+
}
|
|
3082
|
+
|
|
3083
|
+
:root .theme-${!setting?.darkMode ? "dark" : "light"} {
|
|
3084
|
+
--theme-surface: ${!setting?.darkMode ? "#2e2e2e" : "#ffffff"} !important;
|
|
3085
|
+
--theme-border: ${!setting?.darkMode ? "#374151" : "#E5E7EB"} !important;
|
|
3086
|
+
--theme-text: ${!setting?.darkMode ? "#ffffff" : "#000000"} !important;
|
|
3087
|
+
--theme-muted: ${!setting?.darkMode ? "#cccccc" : "#6c757d"} !important;
|
|
3088
|
+
--theme-lighter: ${!setting?.darkMode ? "rgba(255, 255, 255, 0.1)" : "rgba(255, 255, 255, 0.05)"};
|
|
3089
|
+
--theme-darker: ${!setting?.darkMode ? "rgba(0, 0, 0, 0.1)" : "rgba(0, 0, 0, 0.05)"};
|
|
3090
|
+
}`;
|
|
3091
|
+
}
|
|
2983
3092
|
/**
|
|
2984
3093
|
* Inject the client theme settings, meta tags & PWA prompt
|
|
2985
3094
|
* @param opts Injection options: reload - use cached settings or reload; pwa - disabled auto pwa prompt
|
|
@@ -3049,18 +3158,7 @@ Must be either: call, email or sms`);
|
|
|
3049
3158
|
}
|
|
3050
3159
|
const style = document.querySelector("style.momentum-theme") || document.createElement("style");
|
|
3051
3160
|
style.classList.add("momentum-theme");
|
|
3052
|
-
style.innerHTML =
|
|
3053
|
-
:root {
|
|
3054
|
-
--theme-backdrop: ${settings["theme"]?.background} !important;
|
|
3055
|
-
--theme-backdrop-alt: ${settings["theme"]?.darkMode ? "rgba(0, 0, 0, 0.1)" : "rgba(0, 0, 0, 0.05)"} !important;
|
|
3056
|
-
--theme-primary: ${settings["theme"]?.primary} !important;
|
|
3057
|
-
--theme-accent: ${settings["theme"]?.accent} !important;
|
|
3058
|
-
--theme-backdrop-contrast: ${contrast(settings["theme"]?.background)} !important;
|
|
3059
|
-
--theme-primary-contrast: ${contrast(settings["theme"]?.primary)} !important;
|
|
3060
|
-
--theme-accent-contrast: ${contrast(settings["theme"]?.accent)} !important;
|
|
3061
|
-
--theme-font: ${settings["theme"]?.font} !important;
|
|
3062
|
-
}
|
|
3063
|
-
`;
|
|
3161
|
+
style.innerHTML = Client.theme(settings["theme"] || {}, true);
|
|
3064
3162
|
if (!style.parentElement) document.head.append(style);
|
|
3065
3163
|
this.emit(PES`client/inject:c`, this.platform);
|
|
3066
3164
|
return settings;
|
|
@@ -3189,6 +3287,11 @@ Must be either: call, email or sms`);
|
|
|
3189
3287
|
}
|
|
3190
3288
|
}
|
|
3191
3289
|
}
|
|
3290
|
+
function numericPk(filter) {
|
|
3291
|
+
if (filter == null || typeof filter !== "object" || Array.isArray(filter)) return null;
|
|
3292
|
+
const id = filter["_id"];
|
|
3293
|
+
return typeof id === "number" ? id : null;
|
|
3294
|
+
}
|
|
3192
3295
|
class Data extends PathEventEmitter {
|
|
3193
3296
|
constructor(momentum) {
|
|
3194
3297
|
super();
|
|
@@ -3199,12 +3302,6 @@ Must be either: call, email or sms`);
|
|
|
3199
3302
|
dataUrl(collection, pk) {
|
|
3200
3303
|
return `api/data/${collection}${pk != null ? `/${pk}` : ""}`;
|
|
3201
3304
|
}
|
|
3202
|
-
/**
|
|
3203
|
-
* Create new document(s) in collection
|
|
3204
|
-
* @param {string} collection Target collection
|
|
3205
|
-
* @param {Document<T> | Document<T>[]} documents New document(s)
|
|
3206
|
-
* @return {Promise<Document<T> | Document<T>[]>} New saved document(s)
|
|
3207
|
-
*/
|
|
3208
3305
|
create(collection, documents) {
|
|
3209
3306
|
if (!collection || !documents) throw new Error("Cannot create document, missing collection or document");
|
|
3210
3307
|
if (Array.isArray(documents) && !documents.length) return Promise.resolve([]);
|
|
@@ -3218,26 +3315,10 @@ Must be either: call, email or sms`);
|
|
|
3218
3315
|
return resp;
|
|
3219
3316
|
});
|
|
3220
3317
|
}
|
|
3221
|
-
async delete(collection, filter, options) {
|
|
3222
|
-
if (!collection || filter == null) throw new Error("Cannot delete document, missing collection or filter");
|
|
3223
|
-
if (Array.isArray(filter) && !filter.length) return [];
|
|
3224
|
-
const pk = Array.isArray(filter) ? null : typeof filter == "object" ? filter["_id"] == null || Array.isArray(filter["_id"]) ? null : filter["_id"] : filter;
|
|
3225
|
-
const url = this.dataUrl(collection, pk);
|
|
3226
|
-
const ids = await this.momentum.api.request({
|
|
3227
|
-
url,
|
|
3228
|
-
method: "DELETE",
|
|
3229
|
-
body: {
|
|
3230
|
-
filter: Array.isArray(filter) ? { _id: ["in", filter] } : typeof filter == "object" && pk == null ? filter : null,
|
|
3231
|
-
...options
|
|
3232
|
-
}
|
|
3233
|
-
});
|
|
3234
|
-
ids.forEach((id) => this.emit(PES`data/${collection}/${id}:d`, id));
|
|
3235
|
-
return ids;
|
|
3236
|
-
}
|
|
3237
3318
|
read(collection, filter, options) {
|
|
3238
3319
|
if (!collection) throw new Error("Cannot read documents, missing collection");
|
|
3239
|
-
const pk =
|
|
3240
|
-
const q = typeof filter
|
|
3320
|
+
const pk = typeof filter === "number" ? filter : numericPk(filter);
|
|
3321
|
+
const q = typeof filter === "object" && filter != null && Object.keys(filter).length && pk == null ? filter : null;
|
|
3241
3322
|
const url = this.dataUrl(collection, pk);
|
|
3242
3323
|
return this.momentum.api.request({
|
|
3243
3324
|
url,
|
|
@@ -3254,31 +3335,40 @@ Must be either: call, email or sms`);
|
|
|
3254
3335
|
return resp;
|
|
3255
3336
|
});
|
|
3256
3337
|
}
|
|
3257
|
-
/**
|
|
3258
|
-
* Update document(s) in collection
|
|
3259
|
-
* @param {string} collection Target collection
|
|
3260
|
-
* @param {Document<T> | Document<T>[]} documents Document(s) to update
|
|
3261
|
-
* @param {UpdateOptions<T>} options Update options (filter, append, limit, upsert)
|
|
3262
|
-
* @return {Promise<Document<T> | Document<T>[]>} Updated document(s)
|
|
3263
|
-
*/
|
|
3264
3338
|
update(collection, documents, options = {}) {
|
|
3265
3339
|
if (!collection || !documents) throw new Error("Cannot update, missing collection or document");
|
|
3266
3340
|
if (Array.isArray(documents) && !documents.length) return Promise.resolve([]);
|
|
3267
3341
|
const { filter, append, ...queryOptions } = options;
|
|
3268
3342
|
const isArray = Array.isArray(documents);
|
|
3269
3343
|
const firstDoc = isArray ? documents[0] : documents;
|
|
3270
|
-
const pk =
|
|
3344
|
+
const pk = !isArray && !filter ? typeof firstDoc._id === "number" ? firstDoc._id : null : null;
|
|
3271
3345
|
const url = this.dataUrl(collection, pk);
|
|
3272
3346
|
return this.momentum.api.request({
|
|
3273
3347
|
url,
|
|
3274
3348
|
method: append === false ? "PUT" : "PATCH",
|
|
3275
|
-
body: { data: documents, filter: filter && filter
|
|
3349
|
+
body: { data: documents, filter: filter && numericPk(filter) == null ? filter : null, ...queryOptions }
|
|
3276
3350
|
}).then((resp) => {
|
|
3277
3351
|
if (!resp) return null;
|
|
3278
3352
|
makeArray(resp).forEach((r) => this.emit(PES`data/${collection}/${r._id}:u`, r));
|
|
3279
3353
|
return resp;
|
|
3280
3354
|
});
|
|
3281
3355
|
}
|
|
3356
|
+
async delete(collection, filter, options) {
|
|
3357
|
+
if (!collection || filter == null) throw new Error("Cannot delete document, missing collection or filter");
|
|
3358
|
+
if (Array.isArray(filter) && !filter.length) return [];
|
|
3359
|
+
const pk = typeof filter === "number" ? filter : null;
|
|
3360
|
+
const url = this.dataUrl(collection, pk);
|
|
3361
|
+
const ids = await this.momentum.api.request({
|
|
3362
|
+
url,
|
|
3363
|
+
method: "DELETE",
|
|
3364
|
+
body: {
|
|
3365
|
+
filter: Array.isArray(filter) ? { _id: ["in", filter] } : typeof filter === "object" ? filter : null,
|
|
3366
|
+
...options
|
|
3367
|
+
}
|
|
3368
|
+
});
|
|
3369
|
+
ids.forEach((id) => this.emit(PES`data/${collection}/${id}:d`, id));
|
|
3370
|
+
return ids;
|
|
3371
|
+
}
|
|
3282
3372
|
/**
|
|
3283
3373
|
* Execute raw MongoDB query
|
|
3284
3374
|
* @param {string} collection Target collection name
|
|
@@ -4338,7 +4428,7 @@ ${log}`;
|
|
|
4338
4428
|
}
|
|
4339
4429
|
momentum;
|
|
4340
4430
|
}
|
|
4341
|
-
const version = "1.
|
|
4431
|
+
const version = "1.5.0";
|
|
4342
4432
|
class WebRtc extends PathEventEmitter {
|
|
4343
4433
|
constructor(momentum) {
|
|
4344
4434
|
super("webrtc");
|
package/dist/index.mjs
CHANGED
|
@@ -451,6 +451,9 @@ class Cache {
|
|
|
451
451
|
complete = false;
|
|
452
452
|
/** Await initial loading */
|
|
453
453
|
loading = new Promise((r) => this._loading = r);
|
|
454
|
+
get size() {
|
|
455
|
+
return this.store.keys().toArray().length;
|
|
456
|
+
}
|
|
454
457
|
getKey(value) {
|
|
455
458
|
if (!this.key) throw new Error("No key defined");
|
|
456
459
|
if (value[this.key] === void 0) throw new Error(`${this.key.toString()} Doesn't exist on ${JSON.stringify(value, null, 2)}`);
|
|
@@ -636,6 +639,10 @@ function formatBytes(bytes, decimals = 2) {
|
|
|
636
639
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
637
640
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + " " + sizes[i];
|
|
638
641
|
}
|
|
642
|
+
function kebabCase(str) {
|
|
643
|
+
if (!str) return "";
|
|
644
|
+
return wordSegments(str).map((w) => w.toLowerCase()).join("-");
|
|
645
|
+
}
|
|
639
646
|
function randomStringBuilder(length, letters = false, numbers = false, symbols = false) {
|
|
640
647
|
if (!letters && !numbers && !symbols) throw new Error("Must enable at least one: letters, numbers, symbols");
|
|
641
648
|
return Array(length).fill(null).map(() => {
|
|
@@ -653,6 +660,10 @@ function randomStringBuilder(length, letters = false, numbers = false, symbols =
|
|
|
653
660
|
return c;
|
|
654
661
|
}).join("");
|
|
655
662
|
}
|
|
663
|
+
function wordSegments(str) {
|
|
664
|
+
if (!str) return [];
|
|
665
|
+
return str.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/([0-9]+)([a-zA-Z])/g, "$1 $2").replace(/([a-zA-Z])([0-9]+)/g, "$1 $2").replace(/[_\-\s]+/g, " ").trim().split(/\s+/).filter(Boolean);
|
|
666
|
+
}
|
|
656
667
|
function dayOfWeek(d) {
|
|
657
668
|
return ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][d];
|
|
658
669
|
}
|
|
@@ -819,6 +830,9 @@ function sleep(ms) {
|
|
|
819
830
|
async function sleepWhile(fn2, checkInterval = 100) {
|
|
820
831
|
while (await fn2()) await sleep(checkInterval);
|
|
821
832
|
}
|
|
833
|
+
function timeUntil(date) {
|
|
834
|
+
return (date instanceof Date ? date.getTime() : date) - (/* @__PURE__ */ new Date()).getTime();
|
|
835
|
+
}
|
|
822
836
|
class AsyncLock {
|
|
823
837
|
p = Promise.resolve();
|
|
824
838
|
run(fn2) {
|
|
@@ -2504,8 +2518,31 @@ class Api extends Http {
|
|
|
2504
2518
|
options.headers["X-Captcha"] = (+this.momentum.client.captchaScore.toFixed(2)).toString();
|
|
2505
2519
|
}
|
|
2506
2520
|
this.pending[key] = super.request({ ...options, credentials: "include" }).then((response) => {
|
|
2521
|
+
function _d(obj, secret) {
|
|
2522
|
+
const xor = secret % 128 || 127;
|
|
2523
|
+
if (typeof obj === "boolean") return Boolean((obj ? 1 : 0) ^ xor & 1);
|
|
2524
|
+
if (typeof obj === "string") {
|
|
2525
|
+
const decrypted = Array.from(obj).map((c) => String.fromCharCode(c.charCodeAt(0) ^ xor)).join("");
|
|
2526
|
+
const num = Number(decrypted);
|
|
2527
|
+
if (!isNaN(num) && decrypted.trim() !== "") return num;
|
|
2528
|
+
const date = new Date(decrypted);
|
|
2529
|
+
if (!isNaN(date.getTime()) && decrypted.includes("T")) return date;
|
|
2530
|
+
return decrypted;
|
|
2531
|
+
}
|
|
2532
|
+
if (Array.isArray(obj)) return obj.map((v) => _d(v, secret));
|
|
2533
|
+
if (typeof obj === "object" && obj !== null) return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, _d(v, secret)]));
|
|
2534
|
+
return obj;
|
|
2535
|
+
}
|
|
2536
|
+
const hasDate = response.headers.get("Access-Control-Expose-Headers");
|
|
2537
|
+
const cacheDate = response.headers.get("date");
|
|
2507
2538
|
this.emit(`response:${method}`, { request: options, response });
|
|
2508
|
-
|
|
2539
|
+
if (options.decode === false) {
|
|
2540
|
+
return response;
|
|
2541
|
+
} else if (this.sameOrigin ? hasDate : cacheDate) {
|
|
2542
|
+
return _d(response.data, new Date(cacheDate).getTime());
|
|
2543
|
+
} else {
|
|
2544
|
+
return response.data;
|
|
2545
|
+
}
|
|
2509
2546
|
}).catch((err) => {
|
|
2510
2547
|
const e = err?.data || err;
|
|
2511
2548
|
this.emit(`error:${method}`, { request: options, error: e });
|
|
@@ -2662,7 +2699,7 @@ Must be either: call, email or sms`);
|
|
|
2662
2699
|
password: password?.trim(),
|
|
2663
2700
|
totp: opts?.totp ? opts.totp.toString() : void 0,
|
|
2664
2701
|
totpMethod: opts?.totpMethod,
|
|
2665
|
-
expire: opts?.expire
|
|
2702
|
+
expire: !!opts?.expire ? opts.expire instanceof Date ? ~~(timeUntil(opts.expire) / 1e3) : opts.expire : void 0
|
|
2666
2703
|
}, true)
|
|
2667
2704
|
}).then(async (resp) => {
|
|
2668
2705
|
if (resp?.token) await this.readSession(resp.token, true);
|
|
@@ -2845,37 +2882,73 @@ class Captcha {
|
|
|
2845
2882
|
return ua.length > 20 && ua.length < 1e3;
|
|
2846
2883
|
}
|
|
2847
2884
|
update() {
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2885
|
+
if (navigator.webdriver) {
|
|
2886
|
+
this.score = 0;
|
|
2887
|
+
return;
|
|
2888
|
+
}
|
|
2889
|
+
let delta = 0;
|
|
2890
|
+
const elapsed = (Date.now() - this.start) / 1e3;
|
|
2891
|
+
delta += elapsed > 30 ? 0.08 : elapsed > 10 ? 0.04 : elapsed > 3 ? 0.01 : -0.05;
|
|
2892
|
+
if (this.events.mouse.length >= 5) {
|
|
2893
|
+
const recent = this.events.mouse.slice(-20);
|
|
2854
2894
|
let changes = 0;
|
|
2895
|
+
let maxStraightRun = 0;
|
|
2896
|
+
let currentRun = 0;
|
|
2855
2897
|
for (let i = 2; i < recent.length; i++) {
|
|
2856
2898
|
const a1 = Math.atan2(recent[i - 1].y - recent[i - 2].y, recent[i - 1].x - recent[i - 2].x);
|
|
2857
2899
|
const a2 = Math.atan2(recent[i].y - recent[i - 1].y, recent[i].x - recent[i - 1].x);
|
|
2858
|
-
if (Math.abs(a1 - a2) > 0.
|
|
2900
|
+
if (Math.abs(a1 - a2) > 0.3) {
|
|
2901
|
+
changes++;
|
|
2902
|
+
currentRun = 0;
|
|
2903
|
+
} else {
|
|
2904
|
+
currentRun++;
|
|
2905
|
+
maxStraightRun = Math.max(maxStraightRun, currentRun);
|
|
2906
|
+
}
|
|
2859
2907
|
}
|
|
2860
|
-
|
|
2908
|
+
const entropy = changes / (recent.length - 2);
|
|
2909
|
+
if (entropy > 0.4) delta += 0.12;
|
|
2910
|
+
else if (entropy > 0.2) delta += 0.05;
|
|
2911
|
+
else delta -= 0.08;
|
|
2912
|
+
if (maxStraightRun > 8) delta -= 0.1;
|
|
2913
|
+
} else if (this.events.mouse.length === 0) {
|
|
2914
|
+
delta -= 0.03;
|
|
2861
2915
|
}
|
|
2862
|
-
|
|
2863
|
-
if (this.velocities.length > 5) {
|
|
2916
|
+
if (this.velocities.length >= 5) {
|
|
2864
2917
|
const avg = this.velocities.reduce((a, b) => a + b, 0) / this.velocities.length;
|
|
2865
|
-
|
|
2918
|
+
const variance = this.velocities.reduce((a, b) => a + Math.pow(b - avg, 2), 0) / this.velocities.length;
|
|
2919
|
+
const stdDev = Math.sqrt(variance);
|
|
2920
|
+
const cv = avg > 0 ? stdDev / avg : 0;
|
|
2921
|
+
if (cv > 0.4) delta += 0.1;
|
|
2922
|
+
else if (cv > 0.15) delta += 0.04;
|
|
2923
|
+
else if (avg > 0) delta -= 0.1;
|
|
2866
2924
|
}
|
|
2867
|
-
|
|
2868
|
-
|
|
2925
|
+
if (this.events.clicks.length > 0) {
|
|
2926
|
+
const lastClick = this.events.clicks[this.events.clicks.length - 1];
|
|
2927
|
+
const mouseBeforeClick = this.events.mouse.some(
|
|
2928
|
+
(m) => m.t < lastClick.t && lastClick.t - m.t < 2e3
|
|
2929
|
+
);
|
|
2930
|
+
delta += mouseBeforeClick ? 0.08 : -0.12;
|
|
2931
|
+
const suspiciousClicks = this.events.clicks.filter(
|
|
2932
|
+
(c) => Number.isInteger(c.x) && Number.isInteger(c.y) && c.x % 10 === 0 && c.y % 10 === 0
|
|
2933
|
+
// rounded coords = likely synthetic
|
|
2934
|
+
).length;
|
|
2935
|
+
if (suspiciousClicks / this.events.clicks.length > 0.5) delta -= 0.08;
|
|
2936
|
+
}
|
|
2937
|
+
if (this.events.keys.length >= 3) {
|
|
2869
2938
|
const intervals = [];
|
|
2870
2939
|
for (let i = 1; i < this.events.keys.length; i++) {
|
|
2871
2940
|
intervals.push(this.events.keys[i] - this.events.keys[i - 1]);
|
|
2872
2941
|
}
|
|
2873
|
-
const
|
|
2874
|
-
|
|
2942
|
+
const avg = intervals.reduce((a, b) => a + b, 0) / intervals.length;
|
|
2943
|
+
const stdDev = Math.sqrt(intervals.reduce((a, b) => a + Math.pow(b - avg, 2), 0) / intervals.length);
|
|
2944
|
+
if (avg < 20) delta -= 0.15;
|
|
2945
|
+
else if (stdDev < 5) delta -= 0.12;
|
|
2946
|
+
else if (avg < 50) delta -= 0.05;
|
|
2947
|
+
else if (avg < 1e3 && stdDev > 20) delta += 0.1;
|
|
2875
2948
|
}
|
|
2876
|
-
const
|
|
2877
|
-
this.score = this.score * 0.
|
|
2878
|
-
this.score = Math.max(0.
|
|
2949
|
+
const raw = this.score + delta;
|
|
2950
|
+
this.score = this.score * 0.75 + raw * 0.25;
|
|
2951
|
+
this.score = Math.max(0.05, Math.min(0.95, this.score));
|
|
2879
2952
|
}
|
|
2880
2953
|
}
|
|
2881
2954
|
class Client extends PathEventEmitter {
|
|
@@ -2976,6 +3049,42 @@ class Client extends PathEventEmitter {
|
|
|
2976
3049
|
get storage() {
|
|
2977
3050
|
return typeof localStorage != "undefined";
|
|
2978
3051
|
}
|
|
3052
|
+
static theme(setting, css = false) {
|
|
3053
|
+
const t = {
|
|
3054
|
+
background: setting?.background,
|
|
3055
|
+
backgroundContrast: contrast(setting?.background),
|
|
3056
|
+
surface: setting?.darkMode ? "#2e2e2e" : "#ffffff",
|
|
3057
|
+
border: setting?.darkMode ? "#374151" : "#E5E7EB",
|
|
3058
|
+
text: setting?.darkMode ? "#ffffff" : "#000000",
|
|
3059
|
+
muted: setting?.darkMode ? "#cccccc" : "#6c757d",
|
|
3060
|
+
primary: setting?.primary,
|
|
3061
|
+
primaryContrast: contrast(setting?.primary),
|
|
3062
|
+
accent: setting?.accent,
|
|
3063
|
+
accentContrast: contrast(setting?.accent),
|
|
3064
|
+
info: "#6157cc",
|
|
3065
|
+
success: "#65c147",
|
|
3066
|
+
warn: "#d88750",
|
|
3067
|
+
danger: "#bf4f4f",
|
|
3068
|
+
black: "black",
|
|
3069
|
+
white: "white",
|
|
3070
|
+
font: setting?.font,
|
|
3071
|
+
lighter: setting?.darkMode ? "rgba(255, 255, 255, 0.1)" : "rgba(255, 255, 255, 0.05)",
|
|
3072
|
+
darker: setting?.darkMode ? "rgba(0, 0, 0, 0.1)" : "rgba(0, 0, 0, 0.05)"
|
|
3073
|
+
};
|
|
3074
|
+
if (!css) return t;
|
|
3075
|
+
return `:root, :root .theme-${setting?.darkMode ? "dark" : "light"} {
|
|
3076
|
+
${Object.entries(t).map(([name, value]) => `--theme-${kebabCase(name)}: ${value} !important;`).join("\n")}
|
|
3077
|
+
}
|
|
3078
|
+
|
|
3079
|
+
:root .theme-${!setting?.darkMode ? "dark" : "light"} {
|
|
3080
|
+
--theme-surface: ${!setting?.darkMode ? "#2e2e2e" : "#ffffff"} !important;
|
|
3081
|
+
--theme-border: ${!setting?.darkMode ? "#374151" : "#E5E7EB"} !important;
|
|
3082
|
+
--theme-text: ${!setting?.darkMode ? "#ffffff" : "#000000"} !important;
|
|
3083
|
+
--theme-muted: ${!setting?.darkMode ? "#cccccc" : "#6c757d"} !important;
|
|
3084
|
+
--theme-lighter: ${!setting?.darkMode ? "rgba(255, 255, 255, 0.1)" : "rgba(255, 255, 255, 0.05)"};
|
|
3085
|
+
--theme-darker: ${!setting?.darkMode ? "rgba(0, 0, 0, 0.1)" : "rgba(0, 0, 0, 0.05)"};
|
|
3086
|
+
}`;
|
|
3087
|
+
}
|
|
2979
3088
|
/**
|
|
2980
3089
|
* Inject the client theme settings, meta tags & PWA prompt
|
|
2981
3090
|
* @param opts Injection options: reload - use cached settings or reload; pwa - disabled auto pwa prompt
|
|
@@ -3045,18 +3154,7 @@ class Client extends PathEventEmitter {
|
|
|
3045
3154
|
}
|
|
3046
3155
|
const style = document.querySelector("style.momentum-theme") || document.createElement("style");
|
|
3047
3156
|
style.classList.add("momentum-theme");
|
|
3048
|
-
style.innerHTML =
|
|
3049
|
-
:root {
|
|
3050
|
-
--theme-backdrop: ${settings["theme"]?.background} !important;
|
|
3051
|
-
--theme-backdrop-alt: ${settings["theme"]?.darkMode ? "rgba(0, 0, 0, 0.1)" : "rgba(0, 0, 0, 0.05)"} !important;
|
|
3052
|
-
--theme-primary: ${settings["theme"]?.primary} !important;
|
|
3053
|
-
--theme-accent: ${settings["theme"]?.accent} !important;
|
|
3054
|
-
--theme-backdrop-contrast: ${contrast(settings["theme"]?.background)} !important;
|
|
3055
|
-
--theme-primary-contrast: ${contrast(settings["theme"]?.primary)} !important;
|
|
3056
|
-
--theme-accent-contrast: ${contrast(settings["theme"]?.accent)} !important;
|
|
3057
|
-
--theme-font: ${settings["theme"]?.font} !important;
|
|
3058
|
-
}
|
|
3059
|
-
`;
|
|
3157
|
+
style.innerHTML = Client.theme(settings["theme"] || {}, true);
|
|
3060
3158
|
if (!style.parentElement) document.head.append(style);
|
|
3061
3159
|
this.emit(PES`client/inject:c`, this.platform);
|
|
3062
3160
|
return settings;
|
|
@@ -3185,6 +3283,11 @@ class Client extends PathEventEmitter {
|
|
|
3185
3283
|
}
|
|
3186
3284
|
}
|
|
3187
3285
|
}
|
|
3286
|
+
function numericPk(filter) {
|
|
3287
|
+
if (filter == null || typeof filter !== "object" || Array.isArray(filter)) return null;
|
|
3288
|
+
const id = filter["_id"];
|
|
3289
|
+
return typeof id === "number" ? id : null;
|
|
3290
|
+
}
|
|
3188
3291
|
class Data extends PathEventEmitter {
|
|
3189
3292
|
constructor(momentum) {
|
|
3190
3293
|
super();
|
|
@@ -3195,12 +3298,6 @@ class Data extends PathEventEmitter {
|
|
|
3195
3298
|
dataUrl(collection, pk) {
|
|
3196
3299
|
return `api/data/${collection}${pk != null ? `/${pk}` : ""}`;
|
|
3197
3300
|
}
|
|
3198
|
-
/**
|
|
3199
|
-
* Create new document(s) in collection
|
|
3200
|
-
* @param {string} collection Target collection
|
|
3201
|
-
* @param {Document<T> | Document<T>[]} documents New document(s)
|
|
3202
|
-
* @return {Promise<Document<T> | Document<T>[]>} New saved document(s)
|
|
3203
|
-
*/
|
|
3204
3301
|
create(collection, documents) {
|
|
3205
3302
|
if (!collection || !documents) throw new Error("Cannot create document, missing collection or document");
|
|
3206
3303
|
if (Array.isArray(documents) && !documents.length) return Promise.resolve([]);
|
|
@@ -3214,26 +3311,10 @@ class Data extends PathEventEmitter {
|
|
|
3214
3311
|
return resp;
|
|
3215
3312
|
});
|
|
3216
3313
|
}
|
|
3217
|
-
async delete(collection, filter, options) {
|
|
3218
|
-
if (!collection || filter == null) throw new Error("Cannot delete document, missing collection or filter");
|
|
3219
|
-
if (Array.isArray(filter) && !filter.length) return [];
|
|
3220
|
-
const pk = Array.isArray(filter) ? null : typeof filter == "object" ? filter["_id"] == null || Array.isArray(filter["_id"]) ? null : filter["_id"] : filter;
|
|
3221
|
-
const url = this.dataUrl(collection, pk);
|
|
3222
|
-
const ids = await this.momentum.api.request({
|
|
3223
|
-
url,
|
|
3224
|
-
method: "DELETE",
|
|
3225
|
-
body: {
|
|
3226
|
-
filter: Array.isArray(filter) ? { _id: ["in", filter] } : typeof filter == "object" && pk == null ? filter : null,
|
|
3227
|
-
...options
|
|
3228
|
-
}
|
|
3229
|
-
});
|
|
3230
|
-
ids.forEach((id) => this.emit(PES`data/${collection}/${id}:d`, id));
|
|
3231
|
-
return ids;
|
|
3232
|
-
}
|
|
3233
3314
|
read(collection, filter, options) {
|
|
3234
3315
|
if (!collection) throw new Error("Cannot read documents, missing collection");
|
|
3235
|
-
const pk =
|
|
3236
|
-
const q = typeof filter
|
|
3316
|
+
const pk = typeof filter === "number" ? filter : numericPk(filter);
|
|
3317
|
+
const q = typeof filter === "object" && filter != null && Object.keys(filter).length && pk == null ? filter : null;
|
|
3237
3318
|
const url = this.dataUrl(collection, pk);
|
|
3238
3319
|
return this.momentum.api.request({
|
|
3239
3320
|
url,
|
|
@@ -3250,31 +3331,40 @@ class Data extends PathEventEmitter {
|
|
|
3250
3331
|
return resp;
|
|
3251
3332
|
});
|
|
3252
3333
|
}
|
|
3253
|
-
/**
|
|
3254
|
-
* Update document(s) in collection
|
|
3255
|
-
* @param {string} collection Target collection
|
|
3256
|
-
* @param {Document<T> | Document<T>[]} documents Document(s) to update
|
|
3257
|
-
* @param {UpdateOptions<T>} options Update options (filter, append, limit, upsert)
|
|
3258
|
-
* @return {Promise<Document<T> | Document<T>[]>} Updated document(s)
|
|
3259
|
-
*/
|
|
3260
3334
|
update(collection, documents, options = {}) {
|
|
3261
3335
|
if (!collection || !documents) throw new Error("Cannot update, missing collection or document");
|
|
3262
3336
|
if (Array.isArray(documents) && !documents.length) return Promise.resolve([]);
|
|
3263
3337
|
const { filter, append, ...queryOptions } = options;
|
|
3264
3338
|
const isArray = Array.isArray(documents);
|
|
3265
3339
|
const firstDoc = isArray ? documents[0] : documents;
|
|
3266
|
-
const pk =
|
|
3340
|
+
const pk = !isArray && !filter ? typeof firstDoc._id === "number" ? firstDoc._id : null : null;
|
|
3267
3341
|
const url = this.dataUrl(collection, pk);
|
|
3268
3342
|
return this.momentum.api.request({
|
|
3269
3343
|
url,
|
|
3270
3344
|
method: append === false ? "PUT" : "PATCH",
|
|
3271
|
-
body: { data: documents, filter: filter && filter
|
|
3345
|
+
body: { data: documents, filter: filter && numericPk(filter) == null ? filter : null, ...queryOptions }
|
|
3272
3346
|
}).then((resp) => {
|
|
3273
3347
|
if (!resp) return null;
|
|
3274
3348
|
makeArray(resp).forEach((r) => this.emit(PES`data/${collection}/${r._id}:u`, r));
|
|
3275
3349
|
return resp;
|
|
3276
3350
|
});
|
|
3277
3351
|
}
|
|
3352
|
+
async delete(collection, filter, options) {
|
|
3353
|
+
if (!collection || filter == null) throw new Error("Cannot delete document, missing collection or filter");
|
|
3354
|
+
if (Array.isArray(filter) && !filter.length) return [];
|
|
3355
|
+
const pk = typeof filter === "number" ? filter : null;
|
|
3356
|
+
const url = this.dataUrl(collection, pk);
|
|
3357
|
+
const ids = await this.momentum.api.request({
|
|
3358
|
+
url,
|
|
3359
|
+
method: "DELETE",
|
|
3360
|
+
body: {
|
|
3361
|
+
filter: Array.isArray(filter) ? { _id: ["in", filter] } : typeof filter === "object" ? filter : null,
|
|
3362
|
+
...options
|
|
3363
|
+
}
|
|
3364
|
+
});
|
|
3365
|
+
ids.forEach((id) => this.emit(PES`data/${collection}/${id}:d`, id));
|
|
3366
|
+
return ids;
|
|
3367
|
+
}
|
|
3278
3368
|
/**
|
|
3279
3369
|
* Execute raw MongoDB query
|
|
3280
3370
|
* @param {string} collection Target collection name
|
|
@@ -4334,7 +4424,7 @@ class Static extends Storage {
|
|
|
4334
4424
|
}
|
|
4335
4425
|
momentum;
|
|
4336
4426
|
}
|
|
4337
|
-
const version = "1.
|
|
4427
|
+
const version = "1.5.0";
|
|
4338
4428
|
class WebRtc extends PathEventEmitter {
|
|
4339
4429
|
constructor(momentum) {
|
|
4340
4430
|
super("webrtc");
|
package/dist/routes.d.ts
CHANGED
package/dist/routes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAC,eAAe,EAAC,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,MAAM,MAAM,WAAW,GAAG,IAAI,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG;IAC9B,KAAK,EAAE;QACN,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;KACpB,CAAC;IACF,QAAQ,EAAE;QACT,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;KACvB,CAAA;IACD,KAAK,EAAE;QACN,EAAE,EAAE,OAAO,CAAC;QACZ,IAAI,EAAE,OAAO,CAAC;QACd,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;QACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;KACrB,CAAA;CACD,CAAA;AAED,qBAAa,SAAU,SAAQ,eAAe,CAAC,WAAW,CAAC;IAC9C,SAAS,CAAC,QAAQ,EAAE,QAAQ;gBAAlB,QAAQ,EAAE,QAAQ;IAIlC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;CAGhE;AAED,qBAAa,WAAY,SAAQ,eAAe,CAAC,SAAS,CAAC;IAC9C,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AAQ,EAAE,QAAQ;IAIlC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;CAGhE;AAED,qBAAa,WAAY,SAAQ,eAAe,CAAC,SAAS,CAAC;IAC9C,SAAS,CAAC,QAAQ,EAAE,QAAQ;gBAAlB,QAAQ,EAAE,QAAQ;CAGxC;AAED,qBAAa,MAAO,SAAQ,gBAAgB;IAI/B,SAAS,CAAC,QAAQ,EAAE,QAAQ;IAHxC,SAAS,EAAG,SAAS,CAAC;IACtB,WAAW,EAAG,WAAW,CAAC;gBAEJ,QAAQ,EAAE,QAAQ;CAOxC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ztimson/momentum",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Client library for momentum",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Momentum"
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"postbuild": "npm run build:docs && node -e \"const fs=require('fs');fs.cpSync('dist/index.mjs','../server/public/momentum.mjs');fs.cpSync('dist/index.js','../server/public/momentum.js');fs.cpSync('dist/momentum.worker.mjs','../server/public/momentum.worker.mjs')\""
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@ztimson/utils": "^0.30.
|
|
36
|
+
"@ztimson/utils": "^0.30.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^22.5.4",
|