@sweidos/eidos 1.1.0 → 1.2.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/runtime.js CHANGED
@@ -1,32 +1,49 @@
1
- import { useEidosStore as o } from "./store.js";
2
- import { registerBgSyncHandler as a, registerServiceWorker as u } from "./sw-bridge.js";
3
- import { idbGetQueue as c } from "./idb.js";
4
- import { replayQueue as f } from "./action.js";
5
- import { subscribeReplayOnReconnect as l } from "./replay.js";
6
- var e = !1, t = null;
7
- async function h(r = {}) {
8
- if (typeof window > "u" || e) return;
9
- e = !0;
10
- const s = r.swPath ?? "/eidos-sw.js", n = r.autoReplay ?? !0;
1
+ import { useEidosStore as a } from "./store.js";
2
+ import { registerBgSyncHandler as u, registerServiceWorker as c } from "./sw-bridge.js";
3
+ import { idbGetQueue as m, idbQueueStorage as d } from "./idb.js";
4
+ import { _getQueueStorage as y } from "./queue-storage.js";
5
+ import { replayQueue as p } from "./action.js";
6
+ import { subscribeReplayOnReconnect as f } from "./replay.js";
7
+ async function l(e) {
8
+ if (e.schemaVersion === 2 && e.idempotencyKey) return e;
9
+ const t = {
10
+ ...e,
11
+ schemaVersion: 2,
12
+ idempotencyKey: e.idempotencyKey ?? crypto.randomUUID()
13
+ };
14
+ return await (y() ?? d).update(t.id, {
15
+ schemaVersion: t.schemaVersion,
16
+ idempotencyKey: t.idempotencyKey
17
+ }).catch(() => {
18
+ }), t;
19
+ }
20
+ var r = !1, i = null;
21
+ async function K(e = {}) {
22
+ if (typeof window > "u" || r) return;
23
+ r = !0;
24
+ const t = e.swPath ?? "/eidos-sw.js", n = e.autoReplay ?? !0;
11
25
  try {
12
- const i = await c();
13
- i.length > 0 && o.getState().hydrateQueue(i);
26
+ const o = await m();
27
+ if (o.length > 0) {
28
+ const s = await Promise.all(o.map(l));
29
+ a.getState().hydrateQueue(s);
30
+ }
14
31
  } catch {
15
32
  }
16
33
  try {
17
- await u(s);
34
+ await c(t);
18
35
  } catch {
19
36
  }
20
- a(() => {
21
- o.getState().isOnline && setTimeout(f, 200);
22
- }), n && (t = l());
37
+ u(() => {
38
+ a.getState().isOnline && setTimeout(p, 200);
39
+ }), n && (i = f());
23
40
  }
24
- function b() {
25
- t?.(), t = null, e = !1;
41
+ function R() {
42
+ i?.(), i = null, r = !1;
26
43
  }
27
44
  export {
28
- b as _resetEidos,
29
- h as initEidos
45
+ R as _resetEidos,
46
+ K as initEidos
30
47
  };
31
48
 
32
49
  //# sourceMappingURL=runtime.js.map
package/dist/sw-bridge.js CHANGED
@@ -1,22 +1,22 @@
1
- import { useEidosStore as i } from "./store.js";
1
+ import { useEidosStore as a } from "./store.js";
2
2
  var s = null, o = [];
3
- function l() {
3
+ function E() {
4
4
  return s;
5
5
  }
6
- async function w(e) {
6
+ async function p(e) {
7
7
  if (typeof navigator > "u" || !("serviceWorker" in navigator)) {
8
- i.getState().setSwStatus("unsupported");
8
+ a.getState().setSwStatus("unsupported");
9
9
  return;
10
10
  }
11
- const t = i.getState();
11
+ const t = a.getState();
12
12
  t.setSwStatus("registering");
13
13
  try {
14
- s = await navigator.serviceWorker.register(e, { scope: "/" }), await f(s), t.setSwStatus("active"), navigator.serviceWorker.addEventListener("message", d), window.addEventListener("online", () => t.setOnline(!0)), window.addEventListener("offline", () => t.setOnline(!1)), S();
14
+ s = await navigator.serviceWorker.register(e, { scope: "/" }), await d(s), t.setSwStatus("active"), navigator.serviceWorker.addEventListener("message", g), window.addEventListener("online", () => t.setOnline(!0)), window.addEventListener("offline", () => t.setOnline(!1)), l();
15
15
  } catch (n) {
16
16
  t.setSwStatus("error", String(n));
17
17
  }
18
18
  }
19
- function f(e) {
19
+ function d(e) {
20
20
  return new Promise((t) => {
21
21
  if (e.active) {
22
22
  t();
@@ -27,43 +27,55 @@ function f(e) {
27
27
  t();
28
28
  return;
29
29
  }
30
- const a = setTimeout(t, 1e4);
30
+ const i = setTimeout(t, 1e4);
31
31
  n.addEventListener("statechange", function r() {
32
- n.state === "activated" && (clearTimeout(a), n.removeEventListener("statechange", r), t());
32
+ n.state === "activated" && (clearTimeout(i), n.removeEventListener("statechange", r), t());
33
33
  });
34
34
  });
35
35
  }
36
- function g(e) {
36
+ function S(e) {
37
37
  const t = s?.active;
38
38
  t ? t.postMessage(e) : o.push(e);
39
39
  }
40
- var c = null;
41
- function E(e) {
42
- c = e;
40
+ var u = null;
41
+ function w(e) {
42
+ u = e;
43
43
  }
44
- function p() {
44
+ function h() {
45
45
  try {
46
46
  return typeof navigator < "u" && "serviceWorker" in navigator && s !== null && "sync" in s;
47
47
  } catch {
48
48
  return !1;
49
49
  }
50
50
  }
51
- function d(e) {
51
+ var c = {};
52
+ function O(e) {
53
+ c = e;
54
+ }
55
+ function g(e) {
52
56
  const t = e.data;
53
57
  if (!t?.type) return;
54
- const n = i.getState(), { type: a, url: r } = t;
55
- if (a === "EIDOS_BACKGROUND_SYNC") {
56
- c?.();
58
+ const n = a.getState(), { type: i, url: r } = t;
59
+ if (i === "EIDOS_BACKGROUND_SYNC") {
60
+ u?.();
61
+ return;
62
+ }
63
+ if (i === "EIDOS_NOTIFICATION_CLICK") {
64
+ c.onNotificationClick?.(t.data);
65
+ return;
66
+ }
67
+ if (i === "EIDOS_SUBSCRIPTION_EXPIRED") {
68
+ c.onSubscriptionExpired?.(t.subscription);
57
69
  return;
58
70
  }
59
71
  if (r)
60
- switch (a) {
72
+ switch (i) {
61
73
  case "EIDOS_CACHE_HIT": {
62
- const u = n.resources[r];
74
+ const f = n.resources[r];
63
75
  n.updateResource(r, {
64
76
  status: "fresh",
65
77
  lastEvent: "cache-hit",
66
- cacheHits: (u?.cacheHits ?? 0) + 1
78
+ cacheHits: (f?.cacheHits ?? 0) + 1
67
79
  });
68
80
  break;
69
81
  }
@@ -82,13 +94,13 @@ function d(e) {
82
94
  break;
83
95
  }
84
96
  }
85
- function h(e) {
86
- g({
97
+ function _(e) {
98
+ S({
87
99
  type: "EIDOS_SIMULATE_OFFLINE",
88
100
  enabled: e
89
- }), i.getState().setOnline(!e);
101
+ }), a.getState().setOnline(!e);
90
102
  }
91
- function S() {
103
+ function l() {
92
104
  const e = s?.active;
93
105
  if (e) {
94
106
  for (const t of o) e.postMessage(t);
@@ -96,12 +108,13 @@ function S() {
96
108
  }
97
109
  }
98
110
  export {
99
- l as getSwRegistration,
100
- p as isBgSyncSupported,
101
- E as registerBgSyncHandler,
102
- w as registerServiceWorker,
103
- g as sendToWorker,
104
- h as setOfflineSimulation
111
+ E as getSwRegistration,
112
+ h as isBgSyncSupported,
113
+ w as registerBgSyncHandler,
114
+ O as registerPushCallbacks,
115
+ p as registerServiceWorker,
116
+ S as sendToWorker,
117
+ _ as setOfflineSimulation
105
118
  };
106
119
 
107
120
  //# sourceMappingURL=sw-bridge.js.map
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
- var r = "1.1.0";
1
+ var r = "1.2.0";
2
2
  export {
3
3
  r as VERSION
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sweidos/eidos",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Describe intent. The runtime figures out how. An abstraction layer for offline-first web apps.",
5
5
  "author": "Aditya Raj",
6
6
  "license": "MIT",
@@ -42,6 +42,9 @@
42
42
  "main": "./dist/eidos.cjs",
43
43
  "module": "./dist/index.js",
44
44
  "types": "./dist/index.d.ts",
45
+ "bin": {
46
+ "eidos": "./dist/cli.js"
47
+ },
45
48
  "exports": {
46
49
  ".": {
47
50
  "types": "./dist/index.d.ts",
@@ -61,6 +64,11 @@
61
64
  "import": "./dist/query.js",
62
65
  "require": "./dist/query.cjs"
63
66
  },
67
+ "./push": {
68
+ "types": "./dist/push.d.ts",
69
+ "import": "./dist/push.js",
70
+ "require": "./dist/push.cjs"
71
+ },
64
72
  "./testing": {
65
73
  "types": "./dist/testing.d.ts",
66
74
  "import": "./dist/testing.js",
@@ -141,7 +149,7 @@
141
149
  "vitest": "^4.1.8"
142
150
  },
143
151
  "scripts": {
144
- "build": "vite build && vite build --config vite.cjs.config.ts && vite build --config vite.plugin.config.ts && vite build --config vite.query.config.ts && vite build --config vite.testing.config.ts && vite build --config vite.nextjs.config.ts && vite build --config vite.sveltekit.config.ts && vite build --config vite.devtools.config.ts && vite build --config vite.react-native.config.ts && node scripts/copy-sw.mjs",
152
+ "build": "vite build && vite build --config vite.cjs.config.ts && vite build --config vite.plugin.config.ts && vite build --config vite.query.config.ts && vite build --config vite.push.config.ts && vite build --config vite.testing.config.ts && vite build --config vite.nextjs.config.ts && vite build --config vite.sveltekit.config.ts && vite build --config vite.devtools.config.ts && vite build --config vite.react-native.config.ts && vite build --config vite.cli.config.ts && node scripts/copy-sw.mjs",
145
153
  "dev": "vite build --watch",
146
154
  "type-check": "tsc --noEmit",
147
155
  "test": "vitest run",