@smartmemory/sdk-js 1.4.124 → 1.4.125
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/apiBaseUrl.js +37 -0
- package/dist/connection.js +1 -1
- package/dist/{core-DUg_hHl8.js → core-CmAr3Blx.js} +382 -369
- package/dist/core.js +2 -2
- package/dist/index-BKn-OWw0.js +108 -0
- package/dist/index.js +5 -3
- package/dist/react.js +1 -1
- package/package.json +5 -1
- package/dist/index-BKI1h_Wn.js +0 -107
package/dist/core.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as e, a as r, d as A, e as o, B as I, D as P, f as n, I as t, M as g, O as i, j as m, q as M, l as f, m as h, T as p, o as l, U as S, W as c } from "./core-
|
|
2
|
-
import { R as y } from "./index-
|
|
1
|
+
import { A as e, a as r, d as A, e as o, B as I, D as P, f as n, I as t, M as g, O as i, j as m, q as M, l as f, m as h, T as p, o as l, U as S, W as c } from "./core-CmAr3Blx.js";
|
|
2
|
+
import { R as y } from "./index-BKn-OWw0.js";
|
|
3
3
|
export {
|
|
4
4
|
e as APIError,
|
|
5
5
|
r as AgentAPI,
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
var E = (t) => {
|
|
2
|
+
throw TypeError(t);
|
|
3
|
+
};
|
|
4
|
+
var _ = (t, e, s) => e.has(t) || E("Cannot " + s);
|
|
5
|
+
var n = (t, e, s) => (_(t, e, "read from private field"), s ? s.call(t) : e.get(t)), l = (t, e, s) => e.has(t) ? E("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, s), k = (t, e, s, r) => (_(t, e, "write to private field"), r ? r.call(t, s) : e.set(t, s), s), p = (t, e, s) => (_(t, e, "access private method"), s);
|
|
6
|
+
var u, a, c, d, b;
|
|
7
|
+
class M {
|
|
8
|
+
constructor() {
|
|
9
|
+
l(this, d);
|
|
10
|
+
l(this, u, /* @__PURE__ */ new Set());
|
|
11
|
+
l(this, a, /* @__PURE__ */ new Map());
|
|
12
|
+
l(this, c, !1);
|
|
13
|
+
}
|
|
14
|
+
get snapshot() {
|
|
15
|
+
return Object.freeze({
|
|
16
|
+
status: n(this, c) ? "signed_out" : n(this, a).size ? "reconnecting" : "connected",
|
|
17
|
+
reason: n(this, c) ? "Authentication required" : [...n(this, a).values()].at(-1) || null
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
subscribe(e) {
|
|
21
|
+
return n(this, u).add(e), e(this.snapshot), () => n(this, u).delete(e);
|
|
22
|
+
}
|
|
23
|
+
report(e, s) {
|
|
24
|
+
s ? n(this, a).set(e, s) : n(this, a).delete(e), p(this, d, b).call(this);
|
|
25
|
+
}
|
|
26
|
+
signedOut() {
|
|
27
|
+
k(this, c, !0), p(this, d, b).call(this);
|
|
28
|
+
}
|
|
29
|
+
authenticated() {
|
|
30
|
+
n(this, c) && n(this, a).clear(), k(this, c, !1), p(this, d, b).call(this);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
u = new WeakMap(), a = new WeakMap(), c = new WeakMap(), d = new WeakSet(), b = function() {
|
|
34
|
+
const e = this.snapshot;
|
|
35
|
+
for (const s of n(this, u))
|
|
36
|
+
try {
|
|
37
|
+
s(e);
|
|
38
|
+
} catch (r) {
|
|
39
|
+
console.warn("[connection] Listener failed", r);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
class g extends Error {
|
|
43
|
+
constructor(e, s = 0, r = !0) {
|
|
44
|
+
super(e), this.name = "SessionRefreshError", this.status = s, this.recoverable = r;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
var f, T, m;
|
|
48
|
+
class C {
|
|
49
|
+
/**
|
|
50
|
+
* @param {Object} options
|
|
51
|
+
* @param {string | function(): string} options.apiBaseUrl - base URL, or a
|
|
52
|
+
* zero-arg resolver invoked per refresh (runtime-resolved bases)
|
|
53
|
+
* @param {string} options.refreshEndpoint
|
|
54
|
+
* @param {import('./TokenManager.js').TokenManager} options.tokenManager
|
|
55
|
+
* @param {boolean} [options.useCookieAuth=false]
|
|
56
|
+
* @param {function(string): void} options.onTokenRefreshed
|
|
57
|
+
* @param {function(): void} options.onRefreshFailed
|
|
58
|
+
*/
|
|
59
|
+
constructor({ apiBaseUrl: e, refreshEndpoint: s, tokenManager: r, useCookieAuth: O = !1, onTokenRefreshed: w, onRefreshFailed: y, getRequestOptions: R, fetchFn: o, connection: i, getSessionKey: h }) {
|
|
60
|
+
l(this, T);
|
|
61
|
+
l(this, f, null);
|
|
62
|
+
this.getRequestOptions = R || ((S) => S), this.fetchFn = o, this.getSessionKey = h, this.connection = i, this.apiBaseUrl = e, this.refreshEndpoint = s, this.tokenManager = r, this.useCookieAuth = O, this.onTokenRefreshed = w, this.onRefreshFailed = y;
|
|
63
|
+
}
|
|
64
|
+
async refresh() {
|
|
65
|
+
if (n(this, f))
|
|
66
|
+
return n(this, f);
|
|
67
|
+
k(this, f, p(this, T, m).call(this));
|
|
68
|
+
try {
|
|
69
|
+
return await n(this, f);
|
|
70
|
+
} finally {
|
|
71
|
+
k(this, f, null);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
f = new WeakMap(), T = new WeakSet(), m = async function() {
|
|
76
|
+
var w, y, R;
|
|
77
|
+
const e = (w = this.getSessionKey) == null ? void 0 : w.call(this), s = () => {
|
|
78
|
+
var o;
|
|
79
|
+
if (((o = this.getSessionKey) == null ? void 0 : o.call(this)) !== e) throw new DOMException("Session changed during refresh", "AbortError");
|
|
80
|
+
}, r = this.tokenManager.getRefreshToken();
|
|
81
|
+
if (!r && !this.useCookieAuth)
|
|
82
|
+
throw console.warn("[auth] No refresh token available; authentication required"), this.onRefreshFailed(), new g("No refresh token", 401, !1);
|
|
83
|
+
const O = JSON.stringify(r ? { refresh_token: r } : {});
|
|
84
|
+
try {
|
|
85
|
+
const o = typeof this.apiBaseUrl == "function" ? this.apiBaseUrl() : this.apiBaseUrl, i = await (this.fetchFn || globalThis.fetch.bind(globalThis))(`${o}${this.refreshEndpoint}`, this.getRequestOptions({
|
|
86
|
+
...this.useCookieAuth ? { credentials: "include" } : {},
|
|
87
|
+
method: "POST",
|
|
88
|
+
headers: { "Content-Type": "application/json" },
|
|
89
|
+
body: O
|
|
90
|
+
}));
|
|
91
|
+
if (s(), !i.ok) {
|
|
92
|
+
const S = i.status === 401 || i.status === 403;
|
|
93
|
+
throw S && this.onRefreshFailed(), new g(`Refresh failed: ${i.status}`, i.status, !S);
|
|
94
|
+
}
|
|
95
|
+
const h = await i.json();
|
|
96
|
+
if (s(), typeof h.access_token != "string" || !h.access_token) throw new g("Refresh response has no access token");
|
|
97
|
+
return this.tokenManager.setAccessToken(h.access_token), h.refresh_token && this.tokenManager.setRefreshToken(h.refresh_token), this.onTokenRefreshed(h.access_token), (y = this.connection) == null || y.report("refresh", null), h.access_token;
|
|
98
|
+
} catch (o) {
|
|
99
|
+
if (o.name === "AbortError") throw o;
|
|
100
|
+
const i = o instanceof g ? o : new g(o.message);
|
|
101
|
+
throw console.warn("[auth] Session refresh failed", i), i.recoverable && ((R = this.connection) == null || R.report("refresh", i.message)), i;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
export {
|
|
105
|
+
M as C,
|
|
106
|
+
C as R,
|
|
107
|
+
g as S
|
|
108
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { A as f, a as u, b as A, c as P, d as b, e as I, D as h, E as g, G as x, f as p, I as w, L as k, M as m, O as v, g as T, P as B, h as y, i as C, j as S, R as E, k as R, S as F, l as L, m as M, T as O, n as
|
|
1
|
+
import { A as f, a as u, b as A, c as P, d as b, e as I, D as h, E as g, G as x, f as p, I as w, L as k, M as m, O as v, g as T, P as B, h as y, i as C, j as S, R as E, k as R, S as F, l as L, m as M, T as O, n as U, o as G, p as W, U as $, V as D, W as V, Z } from "./core-CmAr3Blx.js";
|
|
2
|
+
import { createApiBaseUrl as q } from "./apiBaseUrl.js";
|
|
2
3
|
const i = {
|
|
3
4
|
variables: {
|
|
4
5
|
colorBackground: "transparent",
|
|
@@ -103,13 +104,14 @@ export {
|
|
|
103
104
|
L as SmartMemoryClient,
|
|
104
105
|
M as SubscriptionAPI,
|
|
105
106
|
O as TeamAPI,
|
|
106
|
-
|
|
107
|
-
|
|
107
|
+
U as TemporalAPI,
|
|
108
|
+
G as TokenManager,
|
|
108
109
|
W as TokenUsageAPI,
|
|
109
110
|
$ as UsageAPI,
|
|
110
111
|
D as ValidationAPI,
|
|
111
112
|
V as WorkspaceAPI,
|
|
112
113
|
Z as ZettelkastenAPI,
|
|
114
|
+
q as createApiBaseUrl,
|
|
113
115
|
l as exchangeClerkSession,
|
|
114
116
|
n as getClerkTokenWithRetry
|
|
115
117
|
};
|
package/dist/react.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import h, { createContext as d, useRef as I, useState as S, useEffect as C, useCallback as c, useContext as g } from "react";
|
|
2
|
-
import { l as y } from "./core-
|
|
2
|
+
import { l as y } from "./core-CmAr3Blx.js";
|
|
3
3
|
const f = d(null), m = d(null);
|
|
4
4
|
function b({ children: e, ...r }) {
|
|
5
5
|
const n = I(null);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartmemory/sdk-js",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.125",
|
|
4
4
|
"description": "Unified JavaScript SDK for SmartMemory API — auth + API client for all frontends",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,6 +36,10 @@
|
|
|
36
36
|
"types": "./types/connection.d.ts",
|
|
37
37
|
"development": "./src/connection/index.js",
|
|
38
38
|
"default": "./dist/connection.js"
|
|
39
|
+
},
|
|
40
|
+
"./apiBaseUrl": {
|
|
41
|
+
"development": "./src/apiBaseUrl.js",
|
|
42
|
+
"default": "./dist/apiBaseUrl.js"
|
|
39
43
|
}
|
|
40
44
|
},
|
|
41
45
|
"files": [
|
package/dist/index-BKI1h_Wn.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
var _ = (t) => {
|
|
2
|
-
throw TypeError(t);
|
|
3
|
-
};
|
|
4
|
-
var O = (t, e, s) => e.has(t) || _("Cannot " + s);
|
|
5
|
-
var i = (t, e, s) => (O(t, e, "read from private field"), s ? s.call(t) : e.get(t)), f = (t, e, s) => e.has(t) ? _("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, s), d = (t, e, s, o) => (O(t, e, "write to private field"), o ? o.call(t, s) : e.set(t, s), s), k = (t, e, s) => (O(t, e, "access private method"), s);
|
|
6
|
-
var l, h, a, u, S;
|
|
7
|
-
class M {
|
|
8
|
-
constructor() {
|
|
9
|
-
f(this, u);
|
|
10
|
-
f(this, l, /* @__PURE__ */ new Set());
|
|
11
|
-
f(this, h, /* @__PURE__ */ new Map());
|
|
12
|
-
f(this, a, !1);
|
|
13
|
-
}
|
|
14
|
-
get snapshot() {
|
|
15
|
-
return Object.freeze({
|
|
16
|
-
status: i(this, a) ? "signed_out" : i(this, h).size ? "reconnecting" : "connected",
|
|
17
|
-
reason: i(this, a) ? "Authentication required" : [...i(this, h).values()].at(-1) || null
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
subscribe(e) {
|
|
21
|
-
return i(this, l).add(e), e(this.snapshot), () => i(this, l).delete(e);
|
|
22
|
-
}
|
|
23
|
-
report(e, s) {
|
|
24
|
-
s ? i(this, h).set(e, s) : i(this, h).delete(e), k(this, u, S).call(this);
|
|
25
|
-
}
|
|
26
|
-
signedOut() {
|
|
27
|
-
d(this, a, !0), k(this, u, S).call(this);
|
|
28
|
-
}
|
|
29
|
-
authenticated() {
|
|
30
|
-
i(this, a) && i(this, h).clear(), d(this, a, !1), k(this, u, S).call(this);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
l = new WeakMap(), h = new WeakMap(), a = new WeakMap(), u = new WeakSet(), S = function() {
|
|
34
|
-
const e = this.snapshot;
|
|
35
|
-
for (const s of i(this, l))
|
|
36
|
-
try {
|
|
37
|
-
s(e);
|
|
38
|
-
} catch (o) {
|
|
39
|
-
console.warn("[connection] Listener failed", o);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
class g extends Error {
|
|
43
|
-
constructor(e, s = 0, o = !0) {
|
|
44
|
-
super(e), this.name = "SessionRefreshError", this.status = s, this.recoverable = o;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
var c, b, E;
|
|
48
|
-
class C {
|
|
49
|
-
/**
|
|
50
|
-
* @param {Object} options
|
|
51
|
-
* @param {string} options.apiBaseUrl
|
|
52
|
-
* @param {string} options.refreshEndpoint
|
|
53
|
-
* @param {import('./TokenManager.js').TokenManager} options.tokenManager
|
|
54
|
-
* @param {boolean} [options.useCookieAuth=false]
|
|
55
|
-
* @param {function(string): void} options.onTokenRefreshed
|
|
56
|
-
* @param {function(): void} options.onRefreshFailed
|
|
57
|
-
*/
|
|
58
|
-
constructor({ apiBaseUrl: e, refreshEndpoint: s, tokenManager: o, useCookieAuth: T = !1, onTokenRefreshed: p, onRefreshFailed: w, getRequestOptions: R, fetchFn: n, connection: r, getSessionKey: y }) {
|
|
59
|
-
f(this, b);
|
|
60
|
-
f(this, c, null);
|
|
61
|
-
this.getRequestOptions = R || ((m) => m), this.fetchFn = n, this.getSessionKey = y, this.connection = r, this.apiBaseUrl = e, this.refreshEndpoint = s, this.tokenManager = o, this.useCookieAuth = T, this.onTokenRefreshed = p, this.onRefreshFailed = w;
|
|
62
|
-
}
|
|
63
|
-
async refresh() {
|
|
64
|
-
if (i(this, c))
|
|
65
|
-
return i(this, c);
|
|
66
|
-
d(this, c, k(this, b, E).call(this));
|
|
67
|
-
try {
|
|
68
|
-
return await i(this, c);
|
|
69
|
-
} finally {
|
|
70
|
-
d(this, c, null);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
c = new WeakMap(), b = new WeakSet(), E = async function() {
|
|
75
|
-
var p, w, R;
|
|
76
|
-
const e = (p = this.getSessionKey) == null ? void 0 : p.call(this), s = () => {
|
|
77
|
-
var n;
|
|
78
|
-
if (((n = this.getSessionKey) == null ? void 0 : n.call(this)) !== e) throw new DOMException("Session changed during refresh", "AbortError");
|
|
79
|
-
}, o = this.tokenManager.getRefreshToken();
|
|
80
|
-
if (!o && !this.useCookieAuth)
|
|
81
|
-
throw console.warn("[auth] No refresh token available; authentication required"), this.onRefreshFailed(), new g("No refresh token", 401, !1);
|
|
82
|
-
const T = JSON.stringify(o ? { refresh_token: o } : {});
|
|
83
|
-
try {
|
|
84
|
-
const n = await (this.fetchFn || globalThis.fetch.bind(globalThis))(`${this.apiBaseUrl}${this.refreshEndpoint}`, this.getRequestOptions({
|
|
85
|
-
...this.useCookieAuth ? { credentials: "include" } : {},
|
|
86
|
-
method: "POST",
|
|
87
|
-
headers: { "Content-Type": "application/json" },
|
|
88
|
-
body: T
|
|
89
|
-
}));
|
|
90
|
-
if (s(), !n.ok) {
|
|
91
|
-
const y = n.status === 401 || n.status === 403;
|
|
92
|
-
throw y && this.onRefreshFailed(), new g(`Refresh failed: ${n.status}`, n.status, !y);
|
|
93
|
-
}
|
|
94
|
-
const r = await n.json();
|
|
95
|
-
if (s(), typeof r.access_token != "string" || !r.access_token) throw new g("Refresh response has no access token");
|
|
96
|
-
return this.tokenManager.setAccessToken(r.access_token), r.refresh_token && this.tokenManager.setRefreshToken(r.refresh_token), this.onTokenRefreshed(r.access_token), (w = this.connection) == null || w.report("refresh", null), r.access_token;
|
|
97
|
-
} catch (n) {
|
|
98
|
-
if (n.name === "AbortError") throw n;
|
|
99
|
-
const r = n instanceof g ? n : new g(n.message);
|
|
100
|
-
throw console.warn("[auth] Session refresh failed", r), r.recoverable && ((R = this.connection) == null || R.report("refresh", r.message)), r;
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
export {
|
|
104
|
-
M as C,
|
|
105
|
-
C as R,
|
|
106
|
-
g as S
|
|
107
|
-
};
|