@nuvin/session 0.2.0-rc.4 → 0.2.0-rc.5
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":"http-data-client.d.ts","sourceRoot":"","sources":["../../src/client/http-data-client.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAmC,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGpF,MAAM,MAAM,qBAAqB,GAAG;IAClC,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACxC,0EAA0E;IAC1E,kBAAkB,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAClD,8DAA8D;IAC9D,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B,CAAC;AAEF,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIvD;AA0CD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,qBAA0B,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"http-data-client.d.ts","sourceRoot":"","sources":["../../src/client/http-data-client.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAmC,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGpF,MAAM,MAAM,qBAAqB,GAAG;IAClC,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACxC,0EAA0E;IAC1E,kBAAkB,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAClD,8DAA8D;IAC9D,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B,CAAC;AAEF,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIvD;AA0CD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,qBAA0B,GAAG,UAAU,CA8UpF"}
|
package/dist/client/index.js
CHANGED
|
@@ -54,6 +54,21 @@ function createHttpDataClient(options = {}) {
|
|
|
54
54
|
const fetchImpl = options.fetchImpl ?? ((...args) => fetch(...args));
|
|
55
55
|
const baseUrl = (options.baseUrl ?? "").replace(/\/+$/, "");
|
|
56
56
|
const rows = /* @__PURE__ */ new Map();
|
|
57
|
+
let directoryResolve = null;
|
|
58
|
+
const directoryReady = new Promise((resolve) => {
|
|
59
|
+
directoryResolve = resolve;
|
|
60
|
+
});
|
|
61
|
+
const resolveDirectory = () => {
|
|
62
|
+
if (directoryResolve) {
|
|
63
|
+
directoryResolve();
|
|
64
|
+
directoryResolve = null;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const ensureDirectoryReady = async (id) => {
|
|
68
|
+
if (rows.has(id)) return;
|
|
69
|
+
if (baseUrl !== "") return;
|
|
70
|
+
await directoryReady;
|
|
71
|
+
};
|
|
57
72
|
const resolveToken = async (id) => {
|
|
58
73
|
const endpoint = rows.get(id)?.endpoint;
|
|
59
74
|
if (endpoint) return endpoint.token;
|
|
@@ -64,6 +79,7 @@ function createHttpDataClient(options = {}) {
|
|
|
64
79
|
return endpoint ? httpBaseFromWsUrl(endpoint.wsUrl) : baseUrl;
|
|
65
80
|
};
|
|
66
81
|
const daemonFetch = async (id, suffix, init = {}) => {
|
|
82
|
+
await ensureDirectoryReady(id);
|
|
67
83
|
const token = await resolveToken(id);
|
|
68
84
|
const response = await fetchImpl(
|
|
69
85
|
`${resolveBase(id)}/api/daemons/${encodeURIComponent(id)}${suffix}`,
|
|
@@ -88,23 +104,27 @@ function createHttpDataClient(options = {}) {
|
|
|
88
104
|
};
|
|
89
105
|
return {
|
|
90
106
|
async listDaemons() {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
107
|
+
try {
|
|
108
|
+
const token = options.getToken ? await options.getToken() : null;
|
|
109
|
+
const response = await fetchImpl(`${baseUrl}/api/daemons`, {
|
|
110
|
+
cache: "no-store",
|
|
111
|
+
headers: token !== null ? { Authorization: `Bearer ${token}` } : {}
|
|
112
|
+
});
|
|
113
|
+
if (response.status === 401) {
|
|
114
|
+
options.onUnauthorized?.();
|
|
115
|
+
throw new TerminalEndpointError("unauthorized", "Signed out \u2014 authentication required.");
|
|
116
|
+
}
|
|
117
|
+
if (!response.ok) await throwFromResponse(response, "Failed to fetch the daemon list");
|
|
118
|
+
const body = await response.json();
|
|
119
|
+
rows.clear();
|
|
120
|
+
for (const row of body.daemons) rows.set(row.id, row);
|
|
121
|
+
return {
|
|
122
|
+
daemons: body.daemons,
|
|
123
|
+
...body.defaultSessionId !== void 0 ? { defaultSessionId: body.defaultSessionId } : {}
|
|
124
|
+
};
|
|
125
|
+
} finally {
|
|
126
|
+
resolveDirectory();
|
|
99
127
|
}
|
|
100
|
-
if (!response.ok) await throwFromResponse(response, "Failed to fetch the daemon list");
|
|
101
|
-
const body = await response.json();
|
|
102
|
-
rows.clear();
|
|
103
|
-
for (const row of body.daemons) rows.set(row.id, row);
|
|
104
|
-
return {
|
|
105
|
-
daemons: body.daemons,
|
|
106
|
-
...body.defaultSessionId !== void 0 ? { defaultSessionId: body.defaultSessionId } : {}
|
|
107
|
-
};
|
|
108
128
|
},
|
|
109
129
|
async acquireEndpoint(daemonId) {
|
|
110
130
|
const endpoint = rows.get(daemonId)?.endpoint;
|