@ztimson/momentum 0.50.7 → 0.52.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.
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAiB,SAAS,EAAE,gBAAgB,EAAM,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,SAAS,CAAC;AAElC,MAAM,MAAM,WAAW,GAAG;IACzB,yBAAyB;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,IAAI,GAAG,IAAI,CAAC;CACpB,CAAA;AAED,qBAAa,KAAM,SAAQ,gBAAgB;IAC9B,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,GAAG;IAI5B,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAO3C,MAAM,CAAC,KAAK,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,IAAI,GAAG,IAAI,CAAA;KAAC,GAAG,OAAO,CAAC,SAAS,CAAC;IAOrF,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAIjC;AAED,qBAAa,IAAI;IACJ,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,GAAG;IAE5B,OAAO,CAAC,QAAQ,EAAE,MAAM;IAIxB,MAAM,aAEU,MAAM,oDAFF;I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AI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAa7C,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;CAO3C"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,gBAAgB,EAAM,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG,OAAO,GAAG,SAAS,CAAC;AAEnF,qBAAa,MAAO,SAAQ,gBAAgB;IAqC/B,OAAO,CAAC,GAAG;IAAO,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAnCvD,IAAI,MAAM,YAAyD;IAEnE,OAAO,CAAC,cAAc,CAAS;IAC/B,IAAI,aAAa,IACkB,OAAO,CADS;IACnD,OAAO,KAAK,aAAa,QAGxB;IAED,OAAO,CAAC,SAAS,CAAC,CAAW;IAC7B,IAAI,QAAQ,IAAI,QAAQ,CAWvB;IAED,IAAI,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAGvD;IAED,OAAO,CAAC,IAAI,CAAC,CAAU;IACvB,IAAI,GAAG,IAAI,OAAO,CAIjB;gBAEmB,GAAG,EAAE,GAAG,EAAmB,QAAQ,EAAE,QAAQ;IAK3D,MAAM,CAAC,MAAM,UAAQ,EAAE,SAAS,UAAO;IAqH7C,SAAS,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,KAAK;IAoIhC,mBAAmB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAa7C,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;CAO3C"}
package/dist/index.cjs CHANGED
@@ -1249,17 +1249,25 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1249
1249
  loginRedirect(host = location.origin) {
1250
1250
  return new Promise((res, rej) => {
1251
1251
  var _a;
1252
- const win = window.open(encodeURI(`${(_a = this.opts) == null ? void 0 : _a.loginUrl}?redirect=postmessage&host=${host}`), "_blank");
1253
- if (!win) return rej("Unable to open login");
1254
- const origin = new URL(this.opts.loginUrl).origin;
1255
- win.addEventListener("message", (event) => {
1252
+ let origin = new URL(this.opts.loginUrl).origin, done = false, listener, win;
1253
+ window.addEventListener("message", listener = (event) => {
1256
1254
  const data = (event == null ? void 0 : event.data) || {};
1257
- if (event.origin != data.sender || data.sender != origin) return;
1255
+ if (event.origin != origin || data.sender != origin) return;
1258
1256
  if (!data.token) return rej("Unknown response from login");
1257
+ done = true;
1259
1258
  this.api.token = event.data.token;
1259
+ window.removeEventListener("message", listener);
1260
1260
  res(event.data.token);
1261
1261
  win.close();
1262
1262
  });
1263
+ win = window.open(encodeURI(`${(_a = this.opts) == null ? void 0 : _a.loginUrl}?redirect=postmessage&host=${host}`), "_blank");
1264
+ if (!win) {
1265
+ window.removeEventListener("message", listener);
1266
+ return rej("Unable to open login");
1267
+ }
1268
+ win.addEventListener("close", () => {
1269
+ if (!done) rej("Window closed before logging in");
1270
+ });
1263
1271
  });
1264
1272
  }
1265
1273
  logout() {
@@ -1350,11 +1358,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1350
1358
  get pushSubscription() {
1351
1359
  var _a;
1352
1360
  if (!((_a = navigator.serviceWorker) == null ? void 0 : _a.controller)) return Promise.resolve(null);
1353
- return navigator.serviceWorker.ready.then((sw) => sw.pushManager.getSubscription());
1361
+ return navigator.serviceWorker.ready.then((sw) => {
1362
+ var _a2;
1363
+ return (_a2 = sw == null ? void 0 : sw.pushManager) == null ? void 0 : _a2.getSubscription();
1364
+ });
1354
1365
  }
1355
1366
  get pwa() {
1356
1367
  if (this._pwa == null)
1357
- this._pwa = window.matchMedia("(display-mode: standalone)").matches || (navigator == null ? void 0 : navigator.standalone) || document.referrer.includes("android-app://");
1368
+ this._pwa = matchMedia("(display-mode: standalone)").matches || (navigator == null ? void 0 : navigator.standalone) || document.referrer.includes("android-app://");
1358
1369
  return this._pwa;
1359
1370
  }
1360
1371
  async inject(reload = false, firstLoad = true) {
@@ -1362,6 +1373,50 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1362
1373
  let settings = this.settings.cache;
1363
1374
  if (firstLoad) this.settings.all(false, reload).then(() => this.inject(false, false)).catch(() => {
1364
1375
  });
1376
+ if (settings["title"] && !document.head.querySelector('meta[property="og:title"]')) {
1377
+ const meta = document.createElement("meta");
1378
+ meta.setAttribute("property", "og:title");
1379
+ meta.content = settings["title"];
1380
+ document.head.append(meta);
1381
+ }
1382
+ if (!document.querySelector('meta[property="og:type"]')) {
1383
+ const meta = document.createElement("meta");
1384
+ meta.setAttribute("property", "og:type");
1385
+ meta.content = "article";
1386
+ document.head.append(meta);
1387
+ }
1388
+ if (settings["public_url"] && !document.querySelector('meta[property="og:url"]')) {
1389
+ const meta = document.createElement("meta");
1390
+ meta.setAttribute("property", "og:url");
1391
+ meta.content = settings["public_url"];
1392
+ document.head.append(meta);
1393
+ }
1394
+ if (settings["description"]) {
1395
+ if (!document.querySelector('meta[property="og:description"]')) {
1396
+ const meta = document.createElement("meta");
1397
+ meta.setAttribute("property", "og:description");
1398
+ meta.content = settings["description"];
1399
+ document.head.append(meta);
1400
+ }
1401
+ if (!document.querySelector('meta[property="description"]')) {
1402
+ const meta = document.createElement("meta");
1403
+ meta.setAttribute("property", "description");
1404
+ meta.content = settings["description"];
1405
+ document.head.append(meta);
1406
+ }
1407
+ if (!document.querySelector('meta[property="twitter:card"]')) {
1408
+ const meta = document.createElement("meta");
1409
+ meta.setAttribute("property", "twitter:card");
1410
+ meta.content = settings["description"];
1411
+ document.head.append(meta);
1412
+ }
1413
+ }
1414
+ if (settings["public_url"] && !document.querySelector('meta[property="og:image"]')) {
1415
+ const meta = document.createElement("meta");
1416
+ meta.setAttribute("property", "og:image");
1417
+ meta.content = settings["public_url"] + "/favicon.ico";
1418
+ document.head.append(meta);
1419
+ }
1365
1420
  if (!document.querySelector('meta[name="mobile-web-app-capable"]')) {
1366
1421
  const meta = document.createElement("meta");
1367
1422
  meta.name = "mobile-web-app-capable";
@@ -1374,46 +1429,41 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1374
1429
  meta.content = "default";
1375
1430
  document.head.append(meta);
1376
1431
  }
1377
- if (!document.querySelector('meta[name="apple-mobile-web-app-title"]')) {
1432
+ if (settings["title"] && !document.querySelector('meta[name="apple-mobile-web-app-title"]')) {
1378
1433
  const meta = document.createElement("meta");
1379
1434
  meta.name = "apple-mobile-web-app-title";
1380
1435
  meta.content = settings["title"];
1381
1436
  document.head.append(meta);
1382
1437
  }
1383
- if (!document.querySelector('link[rel="apple-touch-icon"]')) {
1438
+ if (settings["public_url"] && !document.querySelector('link[rel="apple-touch-icon"]')) {
1384
1439
  const meta = document.createElement("link");
1385
1440
  meta.rel = "apple-touch-icon";
1386
- meta.href = settings["logo"];
1441
+ meta.href = settings["public_url"] + "/favicon.ico";
1387
1442
  document.head.append(meta);
1388
1443
  }
1389
- if (!document.querySelector('link[rel="apple-touch-startup-image"]')) {
1444
+ if (settings["public_url"] && !document.querySelector('link[rel="apple-touch-startup-image"]')) {
1390
1445
  const meta = document.createElement("link");
1391
1446
  meta.rel = "apple-touch-startup-image";
1392
- meta.href = settings["logo"];
1447
+ meta.href = settings["public_url"] + "/favicon.ico";
1393
1448
  document.head.append(meta);
1394
1449
  }
1395
- window.document.body.classList.add(((_a = settings["theme"]) == null ? void 0 : _a.darkMode) ? "theme-dark" : "theme-light");
1396
- window.document.body.classList.remove(((_b = settings["theme"]) == null ? void 0 : _b.darkMode) ? "theme-light" : "theme-dark");
1397
- if (settings["title"])
1398
- window.document.querySelectorAll(".momentum-title").forEach((el) => el.innerText = settings["title"]);
1399
- if (settings["description"])
1400
- window.document.querySelectorAll(".momentum-description").forEach((el) => el.innerText = settings["description"]);
1401
- if (settings.version)
1402
- window.document.querySelectorAll(".momentum-version").forEach((el) => el.innerText = settings["version"]);
1403
- if (settings["logo"]) {
1404
- window.document.querySelectorAll(".momentum-logo").forEach((el) => el.src = settings["logo"]);
1405
- }
1450
+ if (settings["title"]) document.querySelectorAll(".momentum-title").forEach((el) => el.innerText = settings["title"]);
1451
+ if (settings["description"]) document.querySelectorAll(".momentum-description").forEach((el) => el.innerText = settings["description"]);
1452
+ if (settings["version"]) document.querySelectorAll(".momentum-version").forEach((el) => el.innerText = settings["version"]);
1453
+ if (settings["logo"]) document.querySelectorAll(".momentum-logo").forEach((el) => el.src = settings["logo"]);
1406
1454
  if (settings["theme"]) {
1455
+ document.body.classList.add(((_a = settings["theme"]) == null ? void 0 : _a.darkMode) ? "theme-dark" : "theme-light");
1456
+ document.body.classList.remove(((_b = settings["theme"]) == null ? void 0 : _b.darkMode) ? "theme-light" : "theme-dark");
1407
1457
  document.body.style.setProperty("--theme-backdrop", (_c = settings["theme"]) == null ? void 0 : _c.background);
1408
1458
  document.body.style.setProperty("--theme-primary", (_d = settings["theme"]) == null ? void 0 : _d.primary);
1409
1459
  document.body.style.setProperty("--theme-accent", (_e = settings["theme"]) == null ? void 0 : _e.accent);
1410
1460
  document.body.style.setProperty("--theme-contrast", blackOrWhite((_f = settings["theme"]) == null ? void 0 : _f.background));
1411
1461
  }
1412
1462
  if (settings["pwa"]) {
1413
- const link = window.document.createElement("link");
1463
+ const link = document.createElement("link");
1414
1464
  link.setAttribute("rel", "manifest");
1415
1465
  link.setAttribute("href", this.settings.api.url + "/manifest.json");
1416
- window.document.head.append(link);
1466
+ document.head.append(link);
1417
1467
  setTimeout(() => {
1418
1468
  const dismissed = !!localStorage.getItem("momentum:install-prompt");
1419
1469
  if (!dismissed && !this.pwa && this.mobile) this.pwaPrompt();
@@ -1986,60 +2036,61 @@ ${log}`;
1986
2036
  __publicField(_Socket, "pollingSpeed", 3e4);
1987
2037
  let Socket = _Socket;
1988
2038
  let Storage$1 = class Storage extends PathEventEmitter {
1989
- constructor(api) {
2039
+ constructor(api, path = "storage") {
1990
2040
  super();
1991
2041
  __publicField(this, "api");
2042
+ this.path = path;
1992
2043
  this.api = typeof api == "string" ? new Api(api) : api;
1993
2044
  }
1994
2045
  copy(source, destination) {
1995
2046
  if (!source || !destination) throw new Error("Cannot copy file or folder, missing source or destination");
1996
- return this.api.request({ url: "/api/" + PES`storage/${destination}`, body: { from: source } }).then((response) => {
1997
- this.emit(PES`storage/${destination}:c`, response);
2047
+ return this.api.request({ url: "/api/" + PES`${this.path}/${destination}`, body: { from: source } }).then((response) => {
2048
+ this.emit(PES`${this.path}/${destination}:c`, response);
1998
2049
  return response;
1999
2050
  });
2000
2051
  }
2001
2052
  delete(path) {
2002
2053
  if (!path) throw new Error("Cannot delete file or folder, missing path");
2003
- return this.api.request({ url: "/api/" + PES`storage/${path}`, method: "DELETE" }).then(() => {
2004
- this.emit(PES`storage/${path}:d`, path);
2054
+ return this.api.request({ url: "/api/" + PES`${this.path}/${path}`, method: "DELETE" }).then(() => {
2055
+ this.emit(PES`${this.path}/${path}:d`, path);
2005
2056
  });
2006
2057
  }
2007
2058
  download(path, opts = {}) {
2008
2059
  if (!path) throw new Error("Cannot download file, missing path");
2009
- return this.api.request({ ...opts, url: "/api/" + PES`storage/${path}`, decode: false }).then(async (response) => {
2060
+ return this.api.request({ ...opts, url: "/api/" + PES`${this.path}/${path}`, decode: false }).then(async (response) => {
2010
2061
  const blob = await response.blob();
2011
2062
  const name = opts.downloadAs || path.split("/").pop();
2012
- this.emit(PES`storage/${path}:r`, blob);
2063
+ this.emit(PES`${this.path}/${path}:r`, blob);
2013
2064
  downloadFile(blob, name);
2014
2065
  return response;
2015
2066
  });
2016
2067
  }
2017
2068
  list(path) {
2018
2069
  if (!path) path = "/";
2019
- return this.api.request({ url: "/api/" + PES`storage/${path}` + "?list" }).then((resp) => {
2020
- this.emit(PES`storage/${path}:r`, resp);
2070
+ return this.api.request({ url: "/api/" + PES`${this.path}/${path}` + "?list" }).then((resp) => {
2071
+ this.emit(PES`${this.path}/${path}:r`, resp);
2021
2072
  return resp;
2022
2073
  });
2023
2074
  }
2024
2075
  open(path, target = "_blank") {
2025
2076
  if (!path) throw new Error("Cannot download file, missing path");
2026
- const link = `${this.api.url}/api/` + PES`storage/${path}` + (this.api.token ? `?token=${this.api.token}` : "");
2077
+ const link = `${this.api.url}/api/` + PES`${this.path}/${path}` + (this.api.token ? `?token=${this.api.token}` : "");
2027
2078
  if (!target) return link;
2028
- this.emit(PES`storage/${path}:r`, path);
2079
+ this.emit(PES`${this.path}/${path}:r`, path);
2029
2080
  return window.open(link, target);
2030
2081
  }
2031
2082
  mkdir(path) {
2032
2083
  if (!path) throw new Error("Cannot make directory, missing path");
2033
- return this.api.request({ url: "/api/" + PES`storage/${path}`, body: { directory: true } }).then((resp) => {
2034
- this.emit(PES`storage/${path}:c`, resp);
2084
+ return this.api.request({ url: "/api/" + PES`${this.path}/${path}`, body: { directory: true } }).then((resp) => {
2085
+ this.emit(PES`${this.path}/${path}:c`, resp);
2035
2086
  return resp;
2036
2087
  });
2037
2088
  }
2038
2089
  move(source, destination) {
2039
2090
  if (!source || !destination) throw new Error("Cannot move file or folder, missing source or destination");
2040
2091
  if (source == destination) return this.list(destination);
2041
- return this.api.request({ url: "/api/" + PES`storage/${source}`, method: "PATCH", body: { move: destination } }).then((response) => {
2042
- this.emit(PES`storage/${source}:u`, response);
2092
+ return this.api.request({ url: "/api/" + PES`${this.path}/${source}`, method: "PATCH", body: { move: destination } }).then((response) => {
2093
+ this.emit(PES`${this.path}/${source}:u`, response);
2043
2094
  return response;
2044
2095
  });
2045
2096
  }
@@ -2049,13 +2100,13 @@ ${log}`;
2049
2100
  if (!files || Array.isArray(files) && !files.length) return [];
2050
2101
  const path = (opts && typeof opts == "object" ? opts == null ? void 0 : opts.path : opts) || "/";
2051
2102
  return uploadWithProgress({
2052
- url: `${this.api.url}/api/` + PES`storage/${path}`,
2103
+ url: `${this.api.url}/api/` + PES`${this.path}/${path}`,
2053
2104
  files: makeArray(files),
2054
2105
  headers: this.api.headers
2055
2106
  }).onProgress((p) => {
2056
2107
  prog(p);
2057
2108
  }).then((resp) => {
2058
- this.emit(PES`storage/${path}:c`, resp);
2109
+ this.emit(PES`${this.path}/${path}:c`, resp);
2059
2110
  res(resp);
2060
2111
  }).catch((err) => rej(err));
2061
2112
  });
@@ -2170,32 +2221,9 @@ ${log}`;
2170
2221
  });
2171
2222
  }
2172
2223
  }
2173
- class Static extends PathEventEmitter {
2224
+ class Static extends Storage$1 {
2174
2225
  constructor(api) {
2175
- super();
2176
- __publicField(this, "api");
2177
- this.api = typeof api == "string" ? new Api(api) : api;
2178
- }
2179
- delete(path) {
2180
- if (!path) throw new Error("Cannot delete static asset, missing path");
2181
- return this.api.request({ url: `/api/` + PES`static/${path}`, method: "DELETE" }).then(() => {
2182
- this.emit(PES`static/${path}:d`, path);
2183
- });
2184
- }
2185
- upload(files, path = "/") {
2186
- if (!files) throw new Error("Cannot upload static assets, missing file");
2187
- return new PromiseProgress(async (res, rej, prog) => {
2188
- return uploadWithProgress({
2189
- url: this.api.url + "/api/" + PES`static/${path}`,
2190
- files: makeArray(files),
2191
- headers: this.api.headers
2192
- }).onProgress((p) => {
2193
- prog(p);
2194
- }).then((resp) => {
2195
- this.emit(PES`static/${path}:c`, resp);
2196
- res(resp);
2197
- }).catch((err) => rej(err));
2198
- });
2226
+ super(api, "static");
2199
2227
  }
2200
2228
  }
2201
2229
  class Momentum extends PathEventEmitter {
@@ -2224,7 +2252,7 @@ ${log}`;
2224
2252
  this.actions = new Actions(this.api);
2225
2253
  this.ai = new Ai(this.api);
2226
2254
  this.analytics = new Analytics(this.api);
2227
- this.auth = new Auth(this.api, { loginUrl: opts == null ? void 0 : opts.loginUrl });
2255
+ this.auth = new Auth(this.api, opts);
2228
2256
  this.data = new Data(this.api);
2229
2257
  this.email = new Email(this.api);
2230
2258
  this.forms = new Forms(this.api);
@@ -2262,7 +2290,7 @@ ${log}`;
2262
2290
  if (cached) this.auth.user = cached;
2263
2291
  });
2264
2292
  if (!(opts == null ? void 0 : opts.disableWorker) && "serviceWorker" in navigator) {
2265
- navigator.serviceWorker.register("/momentum-worker.js");
2293
+ navigator.serviceWorker.register((opts == null ? void 0 : opts.workerUrl) || "/momentum.worker.js").catch(() => console.warn("Unable to load momentum worker, some features may be limited."));
2266
2294
  }
2267
2295
  }
2268
2296
  }
package/dist/index.mjs CHANGED
@@ -1245,17 +1245,25 @@ class Auth extends PathEventEmitter {
1245
1245
  loginRedirect(host = location.origin) {
1246
1246
  return new Promise((res, rej) => {
1247
1247
  var _a;
1248
- const win = window.open(encodeURI(`${(_a = this.opts) == null ? void 0 : _a.loginUrl}?redirect=postmessage&host=${host}`), "_blank");
1249
- if (!win) return rej("Unable to open login");
1250
- const origin = new URL(this.opts.loginUrl).origin;
1251
- win.addEventListener("message", (event) => {
1248
+ let origin = new URL(this.opts.loginUrl).origin, done = false, listener, win;
1249
+ window.addEventListener("message", listener = (event) => {
1252
1250
  const data = (event == null ? void 0 : event.data) || {};
1253
- if (event.origin != data.sender || data.sender != origin) return;
1251
+ if (event.origin != origin || data.sender != origin) return;
1254
1252
  if (!data.token) return rej("Unknown response from login");
1253
+ done = true;
1255
1254
  this.api.token = event.data.token;
1255
+ window.removeEventListener("message", listener);
1256
1256
  res(event.data.token);
1257
1257
  win.close();
1258
1258
  });
1259
+ win = window.open(encodeURI(`${(_a = this.opts) == null ? void 0 : _a.loginUrl}?redirect=postmessage&host=${host}`), "_blank");
1260
+ if (!win) {
1261
+ window.removeEventListener("message", listener);
1262
+ return rej("Unable to open login");
1263
+ }
1264
+ win.addEventListener("close", () => {
1265
+ if (!done) rej("Window closed before logging in");
1266
+ });
1259
1267
  });
1260
1268
  }
1261
1269
  logout() {
@@ -1346,11 +1354,14 @@ class Client extends PathEventEmitter {
1346
1354
  get pushSubscription() {
1347
1355
  var _a;
1348
1356
  if (!((_a = navigator.serviceWorker) == null ? void 0 : _a.controller)) return Promise.resolve(null);
1349
- return navigator.serviceWorker.ready.then((sw) => sw.pushManager.getSubscription());
1357
+ return navigator.serviceWorker.ready.then((sw) => {
1358
+ var _a2;
1359
+ return (_a2 = sw == null ? void 0 : sw.pushManager) == null ? void 0 : _a2.getSubscription();
1360
+ });
1350
1361
  }
1351
1362
  get pwa() {
1352
1363
  if (this._pwa == null)
1353
- this._pwa = window.matchMedia("(display-mode: standalone)").matches || (navigator == null ? void 0 : navigator.standalone) || document.referrer.includes("android-app://");
1364
+ this._pwa = matchMedia("(display-mode: standalone)").matches || (navigator == null ? void 0 : navigator.standalone) || document.referrer.includes("android-app://");
1354
1365
  return this._pwa;
1355
1366
  }
1356
1367
  async inject(reload = false, firstLoad = true) {
@@ -1358,6 +1369,50 @@ class Client extends PathEventEmitter {
1358
1369
  let settings = this.settings.cache;
1359
1370
  if (firstLoad) this.settings.all(false, reload).then(() => this.inject(false, false)).catch(() => {
1360
1371
  });
1372
+ if (settings["title"] && !document.head.querySelector('meta[property="og:title"]')) {
1373
+ const meta = document.createElement("meta");
1374
+ meta.setAttribute("property", "og:title");
1375
+ meta.content = settings["title"];
1376
+ document.head.append(meta);
1377
+ }
1378
+ if (!document.querySelector('meta[property="og:type"]')) {
1379
+ const meta = document.createElement("meta");
1380
+ meta.setAttribute("property", "og:type");
1381
+ meta.content = "article";
1382
+ document.head.append(meta);
1383
+ }
1384
+ if (settings["public_url"] && !document.querySelector('meta[property="og:url"]')) {
1385
+ const meta = document.createElement("meta");
1386
+ meta.setAttribute("property", "og:url");
1387
+ meta.content = settings["public_url"];
1388
+ document.head.append(meta);
1389
+ }
1390
+ if (settings["description"]) {
1391
+ if (!document.querySelector('meta[property="og:description"]')) {
1392
+ const meta = document.createElement("meta");
1393
+ meta.setAttribute("property", "og:description");
1394
+ meta.content = settings["description"];
1395
+ document.head.append(meta);
1396
+ }
1397
+ if (!document.querySelector('meta[property="description"]')) {
1398
+ const meta = document.createElement("meta");
1399
+ meta.setAttribute("property", "description");
1400
+ meta.content = settings["description"];
1401
+ document.head.append(meta);
1402
+ }
1403
+ if (!document.querySelector('meta[property="twitter:card"]')) {
1404
+ const meta = document.createElement("meta");
1405
+ meta.setAttribute("property", "twitter:card");
1406
+ meta.content = settings["description"];
1407
+ document.head.append(meta);
1408
+ }
1409
+ }
1410
+ if (settings["public_url"] && !document.querySelector('meta[property="og:image"]')) {
1411
+ const meta = document.createElement("meta");
1412
+ meta.setAttribute("property", "og:image");
1413
+ meta.content = settings["public_url"] + "/favicon.ico";
1414
+ document.head.append(meta);
1415
+ }
1361
1416
  if (!document.querySelector('meta[name="mobile-web-app-capable"]')) {
1362
1417
  const meta = document.createElement("meta");
1363
1418
  meta.name = "mobile-web-app-capable";
@@ -1370,46 +1425,41 @@ class Client extends PathEventEmitter {
1370
1425
  meta.content = "default";
1371
1426
  document.head.append(meta);
1372
1427
  }
1373
- if (!document.querySelector('meta[name="apple-mobile-web-app-title"]')) {
1428
+ if (settings["title"] && !document.querySelector('meta[name="apple-mobile-web-app-title"]')) {
1374
1429
  const meta = document.createElement("meta");
1375
1430
  meta.name = "apple-mobile-web-app-title";
1376
1431
  meta.content = settings["title"];
1377
1432
  document.head.append(meta);
1378
1433
  }
1379
- if (!document.querySelector('link[rel="apple-touch-icon"]')) {
1434
+ if (settings["public_url"] && !document.querySelector('link[rel="apple-touch-icon"]')) {
1380
1435
  const meta = document.createElement("link");
1381
1436
  meta.rel = "apple-touch-icon";
1382
- meta.href = settings["logo"];
1437
+ meta.href = settings["public_url"] + "/favicon.ico";
1383
1438
  document.head.append(meta);
1384
1439
  }
1385
- if (!document.querySelector('link[rel="apple-touch-startup-image"]')) {
1440
+ if (settings["public_url"] && !document.querySelector('link[rel="apple-touch-startup-image"]')) {
1386
1441
  const meta = document.createElement("link");
1387
1442
  meta.rel = "apple-touch-startup-image";
1388
- meta.href = settings["logo"];
1443
+ meta.href = settings["public_url"] + "/favicon.ico";
1389
1444
  document.head.append(meta);
1390
1445
  }
1391
- window.document.body.classList.add(((_a = settings["theme"]) == null ? void 0 : _a.darkMode) ? "theme-dark" : "theme-light");
1392
- window.document.body.classList.remove(((_b = settings["theme"]) == null ? void 0 : _b.darkMode) ? "theme-light" : "theme-dark");
1393
- if (settings["title"])
1394
- window.document.querySelectorAll(".momentum-title").forEach((el) => el.innerText = settings["title"]);
1395
- if (settings["description"])
1396
- window.document.querySelectorAll(".momentum-description").forEach((el) => el.innerText = settings["description"]);
1397
- if (settings.version)
1398
- window.document.querySelectorAll(".momentum-version").forEach((el) => el.innerText = settings["version"]);
1399
- if (settings["logo"]) {
1400
- window.document.querySelectorAll(".momentum-logo").forEach((el) => el.src = settings["logo"]);
1401
- }
1446
+ if (settings["title"]) document.querySelectorAll(".momentum-title").forEach((el) => el.innerText = settings["title"]);
1447
+ if (settings["description"]) document.querySelectorAll(".momentum-description").forEach((el) => el.innerText = settings["description"]);
1448
+ if (settings["version"]) document.querySelectorAll(".momentum-version").forEach((el) => el.innerText = settings["version"]);
1449
+ if (settings["logo"]) document.querySelectorAll(".momentum-logo").forEach((el) => el.src = settings["logo"]);
1402
1450
  if (settings["theme"]) {
1451
+ document.body.classList.add(((_a = settings["theme"]) == null ? void 0 : _a.darkMode) ? "theme-dark" : "theme-light");
1452
+ document.body.classList.remove(((_b = settings["theme"]) == null ? void 0 : _b.darkMode) ? "theme-light" : "theme-dark");
1403
1453
  document.body.style.setProperty("--theme-backdrop", (_c = settings["theme"]) == null ? void 0 : _c.background);
1404
1454
  document.body.style.setProperty("--theme-primary", (_d = settings["theme"]) == null ? void 0 : _d.primary);
1405
1455
  document.body.style.setProperty("--theme-accent", (_e = settings["theme"]) == null ? void 0 : _e.accent);
1406
1456
  document.body.style.setProperty("--theme-contrast", blackOrWhite((_f = settings["theme"]) == null ? void 0 : _f.background));
1407
1457
  }
1408
1458
  if (settings["pwa"]) {
1409
- const link = window.document.createElement("link");
1459
+ const link = document.createElement("link");
1410
1460
  link.setAttribute("rel", "manifest");
1411
1461
  link.setAttribute("href", this.settings.api.url + "/manifest.json");
1412
- window.document.head.append(link);
1462
+ document.head.append(link);
1413
1463
  setTimeout(() => {
1414
1464
  const dismissed = !!localStorage.getItem("momentum:install-prompt");
1415
1465
  if (!dismissed && !this.pwa && this.mobile) this.pwaPrompt();
@@ -1982,60 +2032,61 @@ const _Socket = class _Socket {
1982
2032
  __publicField(_Socket, "pollingSpeed", 3e4);
1983
2033
  let Socket = _Socket;
1984
2034
  let Storage$1 = class Storage2 extends PathEventEmitter {
1985
- constructor(api) {
2035
+ constructor(api, path = "storage") {
1986
2036
  super();
1987
2037
  __publicField(this, "api");
2038
+ this.path = path;
1988
2039
  this.api = typeof api == "string" ? new Api(api) : api;
1989
2040
  }
1990
2041
  copy(source, destination) {
1991
2042
  if (!source || !destination) throw new Error("Cannot copy file or folder, missing source or destination");
1992
- return this.api.request({ url: "/api/" + PES`storage/${destination}`, body: { from: source } }).then((response) => {
1993
- this.emit(PES`storage/${destination}:c`, response);
2043
+ return this.api.request({ url: "/api/" + PES`${this.path}/${destination}`, body: { from: source } }).then((response) => {
2044
+ this.emit(PES`${this.path}/${destination}:c`, response);
1994
2045
  return response;
1995
2046
  });
1996
2047
  }
1997
2048
  delete(path) {
1998
2049
  if (!path) throw new Error("Cannot delete file or folder, missing path");
1999
- return this.api.request({ url: "/api/" + PES`storage/${path}`, method: "DELETE" }).then(() => {
2000
- this.emit(PES`storage/${path}:d`, path);
2050
+ return this.api.request({ url: "/api/" + PES`${this.path}/${path}`, method: "DELETE" }).then(() => {
2051
+ this.emit(PES`${this.path}/${path}:d`, path);
2001
2052
  });
2002
2053
  }
2003
2054
  download(path, opts = {}) {
2004
2055
  if (!path) throw new Error("Cannot download file, missing path");
2005
- return this.api.request({ ...opts, url: "/api/" + PES`storage/${path}`, decode: false }).then(async (response) => {
2056
+ return this.api.request({ ...opts, url: "/api/" + PES`${this.path}/${path}`, decode: false }).then(async (response) => {
2006
2057
  const blob = await response.blob();
2007
2058
  const name = opts.downloadAs || path.split("/").pop();
2008
- this.emit(PES`storage/${path}:r`, blob);
2059
+ this.emit(PES`${this.path}/${path}:r`, blob);
2009
2060
  downloadFile(blob, name);
2010
2061
  return response;
2011
2062
  });
2012
2063
  }
2013
2064
  list(path) {
2014
2065
  if (!path) path = "/";
2015
- return this.api.request({ url: "/api/" + PES`storage/${path}` + "?list" }).then((resp) => {
2016
- this.emit(PES`storage/${path}:r`, resp);
2066
+ return this.api.request({ url: "/api/" + PES`${this.path}/${path}` + "?list" }).then((resp) => {
2067
+ this.emit(PES`${this.path}/${path}:r`, resp);
2017
2068
  return resp;
2018
2069
  });
2019
2070
  }
2020
2071
  open(path, target = "_blank") {
2021
2072
  if (!path) throw new Error("Cannot download file, missing path");
2022
- const link = `${this.api.url}/api/` + PES`storage/${path}` + (this.api.token ? `?token=${this.api.token}` : "");
2073
+ const link = `${this.api.url}/api/` + PES`${this.path}/${path}` + (this.api.token ? `?token=${this.api.token}` : "");
2023
2074
  if (!target) return link;
2024
- this.emit(PES`storage/${path}:r`, path);
2075
+ this.emit(PES`${this.path}/${path}:r`, path);
2025
2076
  return window.open(link, target);
2026
2077
  }
2027
2078
  mkdir(path) {
2028
2079
  if (!path) throw new Error("Cannot make directory, missing path");
2029
- return this.api.request({ url: "/api/" + PES`storage/${path}`, body: { directory: true } }).then((resp) => {
2030
- this.emit(PES`storage/${path}:c`, resp);
2080
+ return this.api.request({ url: "/api/" + PES`${this.path}/${path}`, body: { directory: true } }).then((resp) => {
2081
+ this.emit(PES`${this.path}/${path}:c`, resp);
2031
2082
  return resp;
2032
2083
  });
2033
2084
  }
2034
2085
  move(source, destination) {
2035
2086
  if (!source || !destination) throw new Error("Cannot move file or folder, missing source or destination");
2036
2087
  if (source == destination) return this.list(destination);
2037
- return this.api.request({ url: "/api/" + PES`storage/${source}`, method: "PATCH", body: { move: destination } }).then((response) => {
2038
- this.emit(PES`storage/${source}:u`, response);
2088
+ return this.api.request({ url: "/api/" + PES`${this.path}/${source}`, method: "PATCH", body: { move: destination } }).then((response) => {
2089
+ this.emit(PES`${this.path}/${source}:u`, response);
2039
2090
  return response;
2040
2091
  });
2041
2092
  }
@@ -2045,13 +2096,13 @@ let Storage$1 = class Storage2 extends PathEventEmitter {
2045
2096
  if (!files || Array.isArray(files) && !files.length) return [];
2046
2097
  const path = (opts && typeof opts == "object" ? opts == null ? void 0 : opts.path : opts) || "/";
2047
2098
  return uploadWithProgress({
2048
- url: `${this.api.url}/api/` + PES`storage/${path}`,
2099
+ url: `${this.api.url}/api/` + PES`${this.path}/${path}`,
2049
2100
  files: makeArray(files),
2050
2101
  headers: this.api.headers
2051
2102
  }).onProgress((p) => {
2052
2103
  prog(p);
2053
2104
  }).then((resp) => {
2054
- this.emit(PES`storage/${path}:c`, resp);
2105
+ this.emit(PES`${this.path}/${path}:c`, resp);
2055
2106
  res(resp);
2056
2107
  }).catch((err) => rej(err));
2057
2108
  });
@@ -2166,32 +2217,9 @@ class Settings extends PathEventEmitter {
2166
2217
  });
2167
2218
  }
2168
2219
  }
2169
- class Static extends PathEventEmitter {
2220
+ class Static extends Storage$1 {
2170
2221
  constructor(api) {
2171
- super();
2172
- __publicField(this, "api");
2173
- this.api = typeof api == "string" ? new Api(api) : api;
2174
- }
2175
- delete(path) {
2176
- if (!path) throw new Error("Cannot delete static asset, missing path");
2177
- return this.api.request({ url: `/api/` + PES`static/${path}`, method: "DELETE" }).then(() => {
2178
- this.emit(PES`static/${path}:d`, path);
2179
- });
2180
- }
2181
- upload(files, path = "/") {
2182
- if (!files) throw new Error("Cannot upload static assets, missing file");
2183
- return new PromiseProgress(async (res, rej, prog) => {
2184
- return uploadWithProgress({
2185
- url: this.api.url + "/api/" + PES`static/${path}`,
2186
- files: makeArray(files),
2187
- headers: this.api.headers
2188
- }).onProgress((p) => {
2189
- prog(p);
2190
- }).then((resp) => {
2191
- this.emit(PES`static/${path}:c`, resp);
2192
- res(resp);
2193
- }).catch((err) => rej(err));
2194
- });
2222
+ super(api, "static");
2195
2223
  }
2196
2224
  }
2197
2225
  class Momentum extends PathEventEmitter {
@@ -2220,7 +2248,7 @@ class Momentum extends PathEventEmitter {
2220
2248
  this.actions = new Actions(this.api);
2221
2249
  this.ai = new Ai(this.api);
2222
2250
  this.analytics = new Analytics(this.api);
2223
- this.auth = new Auth(this.api, { loginUrl: opts == null ? void 0 : opts.loginUrl });
2251
+ this.auth = new Auth(this.api, opts);
2224
2252
  this.data = new Data(this.api);
2225
2253
  this.email = new Email(this.api);
2226
2254
  this.forms = new Forms(this.api);
@@ -2258,7 +2286,7 @@ class Momentum extends PathEventEmitter {
2258
2286
  if (cached) this.auth.user = cached;
2259
2287
  });
2260
2288
  if (!(opts == null ? void 0 : opts.disableWorker) && "serviceWorker" in navigator) {
2261
- navigator.serviceWorker.register("/momentum-worker.js");
2289
+ navigator.serviceWorker.register((opts == null ? void 0 : opts.workerUrl) || "/momentum.worker.js").catch(() => console.warn("Unable to load momentum worker, some features may be limited."));
2262
2290
  }
2263
2291
  }
2264
2292
  }
@@ -29,6 +29,8 @@ export type MomentumOptions = ApiOptions & AuthOptions & {
29
29
  socket?: boolean;
30
30
  /** Enable payment processing */
31
31
  stripeSecret?: string;
32
+ /** Web worker URL */
33
+ workerUrl?: string;
32
34
  };
33
35
  export declare class Momentum extends PathEventEmitter {
34
36
  api: Api;
@@ -1 +1 @@
1
- {"version":3,"file":"momentum.d.ts","sourceRoot":"","sources":["../src/momentum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,EAAE,EAAC,MAAM,MAAM,CAAC;AACxB,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,OAAO,EAAC,GAAG,EAAE,UAAU,EAAC,MAAM,OAAO,CAAC;AACtC,OAAO,EAAC,IAAI,EAAE,WAAW,EAAC,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAA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,CAAC;IAChB,OAAO,EAAG,OAAO,CAAC;IAClB,KAAK,EAAG,KAAK,CAAC;gBAEF,GAAG,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,eAAe;CAoDhD"}
@@ -0,0 +1,16 @@
1
+ self.addEventListener('push', (event) => {
2
+ if(!(self.Notification && self.Notification.permission === "granted")) return;
3
+ const data = event.data?.json() ?? {};
4
+ self.registration.showNotification(data.title, {
5
+ body: data.message,
6
+ tag: data.title || 'general',
7
+ icon: data.icon || `/favicon.ico`,
8
+ data
9
+ });
10
+ });
11
+
12
+ self.addEventListener('notificationclick', (event) => {
13
+ const data = event.notification.data;
14
+ event.notification.close();
15
+ if (data.link) event.waitUntil(clients.openWindow(data.link));
16
+ });
package/dist/static.d.ts CHANGED
@@ -1,9 +1,6 @@
1
1
  import { Api } from './api';
2
- import { PathEventEmitter, PromiseProgress } from '@ztimson/utils';
3
- export declare class Static extends PathEventEmitter {
4
- private readonly api;
2
+ import { Storage } from './storage';
3
+ export declare class Static extends Storage {
5
4
  constructor(api: Api | string);
6
- delete(path: string): Promise<void>;
7
- upload(files: File | File[], path?: string): PromiseProgress<string[]>;
8
5
  }
9
6
  //# sourceMappingURL=static.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../src/static.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAY,gBAAgB,EAAO,eAAe,EAAqB,MAAM,gBAAgB,CAAC;AAErG,qBAAa,MAAO,SAAQ,gBAAgB;IAC3C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAO;gBAEf,GAAG,EAAE,GAAG,GAAG,MAAM;IAK7B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOnC,MAAM,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,EAAE,IAAI,SAAM,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC;CAenE"}
1
+ {"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../src/static.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAElC,qBAAa,MAAO,SAAQ,OAAO;gBACtB,GAAG,EAAE,GAAG,GAAG,MAAM;CAG7B"}
package/dist/storage.d.ts CHANGED
@@ -16,8 +16,9 @@ export type FileMeta = Meta & {
16
16
  missing?: boolean;
17
17
  };
18
18
  export declare class Storage extends PathEventEmitter {
19
+ private readonly path;
19
20
  readonly api: Api;
20
- constructor(api: Api | string);
21
+ constructor(api: Api | string, path?: string);
21
22
  copy(source: string, destination: string): Promise<DirMeta | FileMeta>;
22
23
  delete(path: string): Promise<void>;
23
24
  download(path: string, opts?: HttpRequestOptions & {
@@ -1 +1 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,KAAK,IAAI,EAAC,MAAM,QAAQ,CAAC;AACjC,OAAO,EACN,eAAe,EACf,kBAAkB,EAKlB,gBAAgB,EAChB,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,OAAO,GAAG;IACrB,QAAQ,EAAE,CAAC,OAAO,GAAG,QAAQ,CAAC,EAAE,CAAC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACb,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB,C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K,GAAG,MAAM;IACzC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI;IAS9D,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQrC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,QAAQ,CAAC;IAStE,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAC,GAAG,eAAe,CAAC,QAAQ,EAAE,CAAC;CAiBvI"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ztimson/momentum",
3
- "version": "0.50.7",
3
+ "version": "0.52.0",
4
4
  "description": "Client library for momentum",
5
5
  "keywords": ["Momentum"],
6
6
  "author": "Zak Timson <zaktimson@gmail.com>",
@@ -21,7 +21,7 @@
21
21
  "start": "vite build --watch",
22
22
  "prebuild": "node -e \"const fs=require('fs');fs.cpSync('../README.md','./README.md')\"",
23
23
  "build": "tsc && vite build",
24
- "postbuild": "node -e \"const fs=require('fs');fs.cpSync('dist/index.mjs','../server/public/momentum.mjs');fs.cpSync('dist/index.cjs','../server/public/momentum.js')\""
24
+ "postbuild": "node -e \"const fs=require('fs');fs.cpSync('dist/index.mjs','../server/public/momentum.mjs');fs.cpSync('dist/index.cjs','../server/public/momentum.js');fs.cpSync('dist/momentum.worker.js','../server/public/momentum.worker.js')\""
25
25
  },
26
26
  "dependencies": {
27
27
  "@ztimson/utils": "0.23.8",