@casfa/client 0.0.1 → 0.3.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/claim.d.ts +21 -0
- package/dist/api/claim.d.ts.map +1 -0
- package/dist/api/delegates.d.ts +39 -0
- package/dist/api/delegates.d.ts.map +1 -0
- package/dist/api/depots.d.ts +68 -0
- package/dist/api/depots.d.ts.map +1 -0
- package/dist/api/filesystem.d.ts +55 -0
- package/dist/api/filesystem.d.ts.map +1 -0
- package/dist/api/index.d.ts +13 -3
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +355 -207
- package/dist/api/index.js.map +19 -1
- package/dist/api/info.d.ts +16 -0
- package/dist/api/info.d.ts.map +1 -0
- package/dist/api/nodes.d.ts +42 -0
- package/dist/api/nodes.d.ts.map +1 -0
- package/dist/api/oauth.d.ts +54 -0
- package/dist/api/oauth.d.ts.map +1 -0
- package/dist/api/requests.d.ts +33 -0
- package/dist/api/requests.d.ts.map +1 -0
- package/dist/api/tokens.d.ts +19 -0
- package/dist/api/tokens.d.ts.map +1 -0
- package/dist/client/delegates.d.ts +26 -0
- package/dist/client/delegates.d.ts.map +1 -0
- package/dist/client/depots.d.ts +28 -0
- package/dist/client/depots.d.ts.map +1 -0
- package/dist/client/filesystem.d.ts +39 -0
- package/dist/client/filesystem.d.ts.map +1 -0
- package/dist/client/helpers.d.ts +27 -0
- package/dist/client/helpers.d.ts.map +1 -0
- package/dist/client/index.d.ts +49 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/nodes.d.ts +30 -0
- package/dist/client/nodes.d.ts.map +1 -0
- package/dist/client/oauth.d.ts +24 -0
- package/dist/client/oauth.d.ts.map +1 -0
- package/dist/client/tokens.d.ts +23 -0
- package/dist/client/tokens.d.ts.map +1 -0
- package/dist/index.d.ts +14 -294
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +414 -515
- package/dist/index.js.map +32 -1
- package/dist/store/index.d.ts +8 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/jwt-refresh.d.ts +31 -0
- package/dist/store/jwt-refresh.d.ts.map +1 -0
- package/dist/store/token-checks.d.ts +33 -0
- package/dist/store/token-checks.d.ts.map +1 -0
- package/dist/store/token-selector.d.ts +29 -0
- package/dist/store/token-selector.d.ts.map +1 -0
- package/dist/store/token-store.d.ts +30 -0
- package/dist/store/token-store.d.ts.map +1 -0
- package/dist/types/client.d.ts +64 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -142
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +14 -3
- package/dist/types/index.js.map +10 -1
- package/dist/types/tokens.d.ts +86 -0
- package/dist/types/tokens.d.ts.map +1 -0
- package/dist/utils/http.d.ts +32 -0
- package/dist/utils/http.d.ts.map +1 -0
- package/package.json +7 -3
- package/dist/index-cPO-6GxE.d.ts +0 -338
package/dist/api/index.js
CHANGED
|
@@ -1,3 +1,59 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, {
|
|
5
|
+
get: all[name],
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
set: (newValue) => all[name] = () => newValue
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/api/index.ts
|
|
13
|
+
var exports_api = {};
|
|
14
|
+
__export(exports_api, {
|
|
15
|
+
updateDepot: () => updateDepot,
|
|
16
|
+
tokenResponseToStoredUserToken: () => tokenResponseToStoredUserToken,
|
|
17
|
+
revokeDelegate: () => revokeDelegate,
|
|
18
|
+
rejectAuthRequest: () => rejectAuthRequest,
|
|
19
|
+
refreshToken: () => refreshToken,
|
|
20
|
+
refresh: () => refresh,
|
|
21
|
+
putNode: () => putNode,
|
|
22
|
+
pollAuthRequest: () => pollAuthRequest,
|
|
23
|
+
login: () => login,
|
|
24
|
+
listDepots: () => listDepots,
|
|
25
|
+
listDelegates: () => listDelegates,
|
|
26
|
+
healthCheck: () => healthCheck,
|
|
27
|
+
getOAuthConfig: () => getOAuthConfig,
|
|
28
|
+
getNodeNavigated: () => getNodeNavigated,
|
|
29
|
+
getNodeMetadata: () => getNodeMetadata,
|
|
30
|
+
getNode: () => getNode,
|
|
31
|
+
getMe: () => getMe,
|
|
32
|
+
getDepot: () => getDepot,
|
|
33
|
+
getDelegate: () => getDelegate,
|
|
34
|
+
getAuthRequest: () => getAuthRequest,
|
|
35
|
+
fsWrite: () => fsWrite,
|
|
36
|
+
fsStat: () => fsStat,
|
|
37
|
+
fsRm: () => fsRm,
|
|
38
|
+
fsRewrite: () => fsRewrite,
|
|
39
|
+
fsRead: () => fsRead,
|
|
40
|
+
fsMv: () => fsMv,
|
|
41
|
+
fsMkdir: () => fsMkdir,
|
|
42
|
+
fsLs: () => fsLs,
|
|
43
|
+
fsCp: () => fsCp,
|
|
44
|
+
fetchServiceInfo: () => fetchServiceInfo,
|
|
45
|
+
exchangeCode: () => exchangeCode,
|
|
46
|
+
deleteDepot: () => deleteDepot,
|
|
47
|
+
createDepot: () => createDepot,
|
|
48
|
+
createDelegate: () => createDelegate,
|
|
49
|
+
createAuthRequest: () => createAuthRequest,
|
|
50
|
+
commitDepot: () => commitDepot,
|
|
51
|
+
claimNode: () => claimNode,
|
|
52
|
+
checkNodes: () => checkNodes,
|
|
53
|
+
batchClaimNodes: () => batchClaimNodes,
|
|
54
|
+
approveAuthRequest: () => approveAuthRequest
|
|
55
|
+
});
|
|
56
|
+
|
|
1
57
|
// src/utils/http.ts
|
|
2
58
|
var statusToErrorCode = (status) => {
|
|
3
59
|
switch (status) {
|
|
@@ -21,18 +77,22 @@ var statusToErrorCode = (status) => {
|
|
|
21
77
|
var createErrorFromResponse = async (response) => {
|
|
22
78
|
const code = statusToErrorCode(response.status);
|
|
23
79
|
let message = response.statusText;
|
|
24
|
-
let details;
|
|
80
|
+
let details = null;
|
|
25
81
|
try {
|
|
26
82
|
const body = await response.json();
|
|
27
83
|
if (typeof body.message === "string") {
|
|
28
84
|
message = body.message;
|
|
29
|
-
}
|
|
30
|
-
if (typeof body.error === "string") {
|
|
85
|
+
} else if (typeof body.error === "string") {
|
|
31
86
|
message = body.error;
|
|
32
87
|
}
|
|
88
|
+
if (body.error && typeof body.error === "object" && "issues" in body.error) {
|
|
89
|
+
const issues = body.error.issues;
|
|
90
|
+
if (Array.isArray(issues) && issues.length > 0) {
|
|
91
|
+
message = issues.map((i) => i.path?.length ? `${i.path.join(".")}: ${i.message}` : i.message).join("; ");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
33
94
|
details = body;
|
|
34
|
-
} catch {
|
|
35
|
-
}
|
|
95
|
+
} catch {}
|
|
36
96
|
return { code, message, status: response.status, details };
|
|
37
97
|
};
|
|
38
98
|
var createNetworkError = (err) => ({
|
|
@@ -43,14 +103,14 @@ var createNetworkError = (err) => ({
|
|
|
43
103
|
var fetchApi = async (url, options = {}) => {
|
|
44
104
|
const { method = "GET", headers = {}, body, responseType = "json" } = options;
|
|
45
105
|
const requestHeaders = { ...headers };
|
|
46
|
-
if (body !==
|
|
106
|
+
if (body !== undefined && !requestHeaders["Content-Type"]) {
|
|
47
107
|
requestHeaders["Content-Type"] = "application/json";
|
|
48
108
|
}
|
|
49
109
|
try {
|
|
50
110
|
const response = await fetch(url, {
|
|
51
111
|
method,
|
|
52
112
|
headers: requestHeaders,
|
|
53
|
-
body: body !==
|
|
113
|
+
body: body !== undefined ? JSON.stringify(body) : undefined
|
|
54
114
|
});
|
|
55
115
|
if (!response.ok) {
|
|
56
116
|
const error = await createErrorFromResponse(response);
|
|
@@ -68,7 +128,7 @@ var fetchApi = async (url, options = {}) => {
|
|
|
68
128
|
data = await response.text();
|
|
69
129
|
break;
|
|
70
130
|
case "none":
|
|
71
|
-
data =
|
|
131
|
+
data = undefined;
|
|
72
132
|
break;
|
|
73
133
|
}
|
|
74
134
|
return { ok: true, data, status: response.status };
|
|
@@ -84,62 +144,212 @@ var fetchWithAuth = async (url, authHeader, options = {}) => {
|
|
|
84
144
|
return fetchApi(url, { ...options, headers });
|
|
85
145
|
};
|
|
86
146
|
|
|
147
|
+
// src/api/claim.ts
|
|
148
|
+
var claimNode = async (baseUrl, realm, accessTokenBase64, nodeKey, params) => {
|
|
149
|
+
return fetchWithAuth(`${baseUrl}/api/realm/${encodeURIComponent(realm)}/nodes/${encodeURIComponent(nodeKey)}/claim`, `Bearer ${accessTokenBase64}`, {
|
|
150
|
+
method: "POST",
|
|
151
|
+
body: params
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
var batchClaimNodes = async (baseUrl, realm, accessTokenBase64, params) => {
|
|
155
|
+
return fetchWithAuth(`${baseUrl}/api/realm/${encodeURIComponent(realm)}/nodes/claim`, `Bearer ${accessTokenBase64}`, {
|
|
156
|
+
method: "POST",
|
|
157
|
+
body: params
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
// src/api/delegates.ts
|
|
161
|
+
var createDelegate = async (baseUrl, realm, accessTokenBase64, params) => {
|
|
162
|
+
return fetchWithAuth(`${baseUrl}/api/realm/${encodeURIComponent(realm)}/delegates`, `Bearer ${accessTokenBase64}`, {
|
|
163
|
+
method: "POST",
|
|
164
|
+
body: params
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
var listDelegates = async (baseUrl, realm, accessTokenBase64, params) => {
|
|
168
|
+
const query = new URLSearchParams;
|
|
169
|
+
if (params?.limit)
|
|
170
|
+
query.set("limit", String(params.limit));
|
|
171
|
+
if (params?.cursor)
|
|
172
|
+
query.set("cursor", params.cursor);
|
|
173
|
+
if (params?.includeRevoked)
|
|
174
|
+
query.set("includeRevoked", "true");
|
|
175
|
+
const queryString = query.toString();
|
|
176
|
+
const url = `${baseUrl}/api/realm/${encodeURIComponent(realm)}/delegates${queryString ? `?${queryString}` : ""}`;
|
|
177
|
+
return fetchWithAuth(url, `Bearer ${accessTokenBase64}`);
|
|
178
|
+
};
|
|
179
|
+
var getDelegate = async (baseUrl, realm, accessTokenBase64, delegateId) => {
|
|
180
|
+
return fetchWithAuth(`${baseUrl}/api/realm/${encodeURIComponent(realm)}/delegates/${encodeURIComponent(delegateId)}`, `Bearer ${accessTokenBase64}`);
|
|
181
|
+
};
|
|
182
|
+
var revokeDelegate = async (baseUrl, realm, accessTokenBase64, delegateId) => {
|
|
183
|
+
return fetchWithAuth(`${baseUrl}/api/realm/${encodeURIComponent(realm)}/delegates/${encodeURIComponent(delegateId)}/revoke`, `Bearer ${accessTokenBase64}`, {
|
|
184
|
+
method: "POST"
|
|
185
|
+
});
|
|
186
|
+
};
|
|
87
187
|
// src/api/depots.ts
|
|
88
188
|
var createDepot = async (baseUrl, realm, accessTokenBase64, params) => {
|
|
89
|
-
return fetchWithAuth(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
method: "POST",
|
|
94
|
-
body: params
|
|
95
|
-
}
|
|
96
|
-
);
|
|
189
|
+
return fetchWithAuth(`${baseUrl}/api/realm/${encodeURIComponent(realm)}/depots`, `Bearer ${accessTokenBase64}`, {
|
|
190
|
+
method: "POST",
|
|
191
|
+
body: params
|
|
192
|
+
});
|
|
97
193
|
};
|
|
98
194
|
var listDepots = async (baseUrl, realm, accessTokenBase64, params) => {
|
|
99
|
-
const query = new URLSearchParams
|
|
100
|
-
if (params?.limit)
|
|
101
|
-
|
|
195
|
+
const query = new URLSearchParams;
|
|
196
|
+
if (params?.limit)
|
|
197
|
+
query.set("limit", String(params.limit));
|
|
198
|
+
if (params?.cursor)
|
|
199
|
+
query.set("cursor", params.cursor);
|
|
102
200
|
const queryString = query.toString();
|
|
103
201
|
const url = `${baseUrl}/api/realm/${encodeURIComponent(realm)}/depots${queryString ? `?${queryString}` : ""}`;
|
|
104
202
|
return fetchWithAuth(url, `Bearer ${accessTokenBase64}`);
|
|
105
203
|
};
|
|
106
204
|
var getDepot = async (baseUrl, realm, accessTokenBase64, depotId) => {
|
|
107
|
-
return fetchWithAuth(
|
|
108
|
-
`${baseUrl}/api/realm/${encodeURIComponent(realm)}/depots/${encodeURIComponent(depotId)}`,
|
|
109
|
-
`Bearer ${accessTokenBase64}`
|
|
110
|
-
);
|
|
205
|
+
return fetchWithAuth(`${baseUrl}/api/realm/${encodeURIComponent(realm)}/depots/${encodeURIComponent(depotId)}`, `Bearer ${accessTokenBase64}`);
|
|
111
206
|
};
|
|
112
207
|
var updateDepot = async (baseUrl, realm, accessTokenBase64, depotId, params) => {
|
|
113
|
-
return fetchWithAuth(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
method: "PATCH",
|
|
118
|
-
body: params
|
|
119
|
-
}
|
|
120
|
-
);
|
|
208
|
+
return fetchWithAuth(`${baseUrl}/api/realm/${encodeURIComponent(realm)}/depots/${encodeURIComponent(depotId)}`, `Bearer ${accessTokenBase64}`, {
|
|
209
|
+
method: "PATCH",
|
|
210
|
+
body: params
|
|
211
|
+
});
|
|
121
212
|
};
|
|
122
213
|
var deleteDepot = async (baseUrl, realm, accessTokenBase64, depotId) => {
|
|
123
|
-
return fetchWithAuth(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
method: "DELETE",
|
|
128
|
-
responseType: "none"
|
|
129
|
-
}
|
|
130
|
-
);
|
|
214
|
+
return fetchWithAuth(`${baseUrl}/api/realm/${encodeURIComponent(realm)}/depots/${encodeURIComponent(depotId)}`, `Bearer ${accessTokenBase64}`, {
|
|
215
|
+
method: "DELETE",
|
|
216
|
+
responseType: "none"
|
|
217
|
+
});
|
|
131
218
|
};
|
|
132
219
|
var commitDepot = async (baseUrl, realm, accessTokenBase64, depotId, params) => {
|
|
133
|
-
return fetchWithAuth(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
220
|
+
return fetchWithAuth(`${baseUrl}/api/realm/${encodeURIComponent(realm)}/depots/${encodeURIComponent(depotId)}/commit`, `Bearer ${accessTokenBase64}`, {
|
|
221
|
+
method: "POST",
|
|
222
|
+
body: params
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
// src/api/filesystem.ts
|
|
226
|
+
function buildFsUrl(baseUrl, realm, rootKey, op) {
|
|
227
|
+
return `${baseUrl}/api/realm/${encodeURIComponent(realm)}/nodes/fs/${encodeURIComponent(rootKey)}/${op}`;
|
|
228
|
+
}
|
|
229
|
+
var fsStat = async (baseUrl, realm, accessTokenBase64, rootKey, path) => {
|
|
230
|
+
const params = new URLSearchParams;
|
|
231
|
+
if (path)
|
|
232
|
+
params.set("path", path);
|
|
233
|
+
const qs = params.toString();
|
|
234
|
+
const url = `${buildFsUrl(baseUrl, realm, rootKey, "stat")}${qs ? `?${qs}` : ""}`;
|
|
235
|
+
return fetchWithAuth(url, `Bearer ${accessTokenBase64}`);
|
|
236
|
+
};
|
|
237
|
+
var fsLs = async (baseUrl, realm, accessTokenBase64, rootKey, path, opts) => {
|
|
238
|
+
const params = new URLSearchParams;
|
|
239
|
+
if (path)
|
|
240
|
+
params.set("path", path);
|
|
241
|
+
if (opts?.limit)
|
|
242
|
+
params.set("limit", String(opts.limit));
|
|
243
|
+
if (opts?.cursor)
|
|
244
|
+
params.set("cursor", opts.cursor);
|
|
245
|
+
const qs = params.toString();
|
|
246
|
+
const url = `${buildFsUrl(baseUrl, realm, rootKey, "ls")}${qs ? `?${qs}` : ""}`;
|
|
247
|
+
return fetchWithAuth(url, `Bearer ${accessTokenBase64}`);
|
|
248
|
+
};
|
|
249
|
+
var fsRead = async (baseUrl, realm, accessTokenBase64, rootKey, path) => {
|
|
250
|
+
const params = new URLSearchParams({ path });
|
|
251
|
+
const url = `${buildFsUrl(baseUrl, realm, rootKey, "read")}?${params}`;
|
|
252
|
+
try {
|
|
253
|
+
const response = await fetch(url, {
|
|
254
|
+
headers: { Authorization: `Bearer ${accessTokenBase64}` }
|
|
255
|
+
});
|
|
256
|
+
if (!response.ok) {
|
|
257
|
+
let message = response.statusText;
|
|
258
|
+
try {
|
|
259
|
+
const body = await response.json();
|
|
260
|
+
if (typeof body.message === "string")
|
|
261
|
+
message = body.message;
|
|
262
|
+
} catch {}
|
|
263
|
+
return {
|
|
264
|
+
ok: false,
|
|
265
|
+
error: { code: String(response.status), message, status: response.status }
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
const blob = await response.blob();
|
|
269
|
+
return { ok: true, data: blob, status: response.status };
|
|
270
|
+
} catch (err) {
|
|
271
|
+
return {
|
|
272
|
+
ok: false,
|
|
273
|
+
error: {
|
|
274
|
+
code: "NETWORK_ERROR",
|
|
275
|
+
message: err instanceof Error ? err.message : "Network error"
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
var fsWrite = async (baseUrl, realm, accessTokenBase64, rootKey, path, data, contentType = "application/octet-stream") => {
|
|
281
|
+
const params = new URLSearchParams({ path });
|
|
282
|
+
const url = `${buildFsUrl(baseUrl, realm, rootKey, "write")}?${params}`;
|
|
283
|
+
const body = data instanceof Blob ? data : new Blob([data], { type: contentType });
|
|
284
|
+
try {
|
|
285
|
+
const response = await fetch(url, {
|
|
137
286
|
method: "POST",
|
|
138
|
-
|
|
287
|
+
headers: {
|
|
288
|
+
Authorization: `Bearer ${accessTokenBase64}`,
|
|
289
|
+
"Content-Type": contentType,
|
|
290
|
+
"Content-Length": String(body.size)
|
|
291
|
+
},
|
|
292
|
+
body
|
|
293
|
+
});
|
|
294
|
+
if (!response.ok) {
|
|
295
|
+
let message = response.statusText;
|
|
296
|
+
try {
|
|
297
|
+
const body2 = await response.json();
|
|
298
|
+
if (typeof body2.message === "string")
|
|
299
|
+
message = body2.message;
|
|
300
|
+
} catch {}
|
|
301
|
+
return {
|
|
302
|
+
ok: false,
|
|
303
|
+
error: { code: String(response.status), message, status: response.status }
|
|
304
|
+
};
|
|
139
305
|
}
|
|
140
|
-
|
|
306
|
+
const result = await response.json();
|
|
307
|
+
return { ok: true, data: result, status: response.status };
|
|
308
|
+
} catch (err) {
|
|
309
|
+
return {
|
|
310
|
+
ok: false,
|
|
311
|
+
error: {
|
|
312
|
+
code: "NETWORK_ERROR",
|
|
313
|
+
message: err instanceof Error ? err.message : "Network error"
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
var fsMkdir = async (baseUrl, realm, accessTokenBase64, rootKey, path) => {
|
|
319
|
+
const url = buildFsUrl(baseUrl, realm, rootKey, "mkdir");
|
|
320
|
+
return fetchWithAuth(url, `Bearer ${accessTokenBase64}`, {
|
|
321
|
+
method: "POST",
|
|
322
|
+
body: { path }
|
|
323
|
+
});
|
|
324
|
+
};
|
|
325
|
+
var fsRm = async (baseUrl, realm, accessTokenBase64, rootKey, path) => {
|
|
326
|
+
const url = buildFsUrl(baseUrl, realm, rootKey, "rm");
|
|
327
|
+
return fetchWithAuth(url, `Bearer ${accessTokenBase64}`, {
|
|
328
|
+
method: "POST",
|
|
329
|
+
body: { path }
|
|
330
|
+
});
|
|
331
|
+
};
|
|
332
|
+
var fsMv = async (baseUrl, realm, accessTokenBase64, rootKey, from, to) => {
|
|
333
|
+
const url = buildFsUrl(baseUrl, realm, rootKey, "mv");
|
|
334
|
+
return fetchWithAuth(url, `Bearer ${accessTokenBase64}`, {
|
|
335
|
+
method: "POST",
|
|
336
|
+
body: { from, to }
|
|
337
|
+
});
|
|
338
|
+
};
|
|
339
|
+
var fsCp = async (baseUrl, realm, accessTokenBase64, rootKey, from, to) => {
|
|
340
|
+
const url = buildFsUrl(baseUrl, realm, rootKey, "cp");
|
|
341
|
+
return fetchWithAuth(url, `Bearer ${accessTokenBase64}`, {
|
|
342
|
+
method: "POST",
|
|
343
|
+
body: { from, to }
|
|
344
|
+
});
|
|
345
|
+
};
|
|
346
|
+
var fsRewrite = async (baseUrl, realm, accessTokenBase64, rootKey, entries, deletes) => {
|
|
347
|
+
const url = buildFsUrl(baseUrl, realm, rootKey, "rewrite");
|
|
348
|
+
return fetchWithAuth(url, `Bearer ${accessTokenBase64}`, {
|
|
349
|
+
method: "POST",
|
|
350
|
+
body: { entries, deletes }
|
|
351
|
+
});
|
|
141
352
|
};
|
|
142
|
-
|
|
143
353
|
// src/api/info.ts
|
|
144
354
|
var fetchServiceInfo = async (baseUrl) => {
|
|
145
355
|
return fetchApi(`${baseUrl}/api/info`);
|
|
@@ -147,17 +357,14 @@ var fetchServiceInfo = async (baseUrl) => {
|
|
|
147
357
|
var healthCheck = async (baseUrl) => {
|
|
148
358
|
return fetchApi(`${baseUrl}/api/health`);
|
|
149
359
|
};
|
|
150
|
-
|
|
151
360
|
// src/api/nodes.ts
|
|
152
|
-
var getNode = async (baseUrl, realm, accessTokenBase64, nodeKey
|
|
153
|
-
const url = `${baseUrl}/api/realm/${encodeURIComponent(realm)}/nodes/${encodeURIComponent(nodeKey)}`;
|
|
361
|
+
var getNode = async (baseUrl, realm, accessTokenBase64, nodeKey) => {
|
|
362
|
+
const url = `${baseUrl}/api/realm/${encodeURIComponent(realm)}/nodes/raw/${encodeURIComponent(nodeKey)}`;
|
|
154
363
|
try {
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
});
|
|
364
|
+
const headers = {
|
|
365
|
+
Authorization: `Bearer ${accessTokenBase64}`
|
|
366
|
+
};
|
|
367
|
+
const response = await fetch(url, { headers });
|
|
161
368
|
if (!response.ok) {
|
|
162
369
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
163
370
|
return {
|
|
@@ -181,29 +388,47 @@ var getNode = async (baseUrl, realm, accessTokenBase64, nodeKey, indexPath) => {
|
|
|
181
388
|
};
|
|
182
389
|
}
|
|
183
390
|
};
|
|
184
|
-
var
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
391
|
+
var getNodeNavigated = async (baseUrl, realm, accessTokenBase64, nodeKey, indexPath) => {
|
|
392
|
+
const url = `${baseUrl}/api/realm/${encodeURIComponent(realm)}/nodes/raw/${encodeURIComponent(nodeKey)}/${indexPath}`;
|
|
393
|
+
try {
|
|
394
|
+
const headers = {
|
|
395
|
+
Authorization: `Bearer ${accessTokenBase64}`
|
|
396
|
+
};
|
|
397
|
+
const response = await fetch(url, { headers });
|
|
398
|
+
if (!response.ok) {
|
|
399
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
400
|
+
return {
|
|
401
|
+
ok: false,
|
|
402
|
+
error: {
|
|
403
|
+
code: String(response.status),
|
|
404
|
+
message: error.message ?? response.statusText,
|
|
405
|
+
status: response.status
|
|
406
|
+
}
|
|
407
|
+
};
|
|
192
408
|
}
|
|
193
|
-
|
|
409
|
+
const data = new Uint8Array(await response.arrayBuffer());
|
|
410
|
+
return { ok: true, data, status: response.status };
|
|
411
|
+
} catch (err) {
|
|
412
|
+
return {
|
|
413
|
+
ok: false,
|
|
414
|
+
error: {
|
|
415
|
+
code: "NETWORK_ERROR",
|
|
416
|
+
message: err instanceof Error ? err.message : "Network error"
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
}
|
|
194
420
|
};
|
|
195
|
-
var
|
|
196
|
-
return fetchWithAuth(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
);
|
|
421
|
+
var getNodeMetadata = async (baseUrl, realm, accessTokenBase64, nodeKey) => {
|
|
422
|
+
return fetchWithAuth(`${baseUrl}/api/realm/${encodeURIComponent(realm)}/nodes/metadata/${encodeURIComponent(nodeKey)}`, `Bearer ${accessTokenBase64}`);
|
|
423
|
+
};
|
|
424
|
+
var checkNodes = async (baseUrl, realm, accessTokenBase64, params) => {
|
|
425
|
+
return fetchWithAuth(`${baseUrl}/api/realm/${encodeURIComponent(realm)}/nodes/check`, `Bearer ${accessTokenBase64}`, {
|
|
426
|
+
method: "POST",
|
|
427
|
+
body: params
|
|
428
|
+
});
|
|
204
429
|
};
|
|
205
430
|
var putNode = async (baseUrl, realm, accessTokenBase64, nodeKey, content) => {
|
|
206
|
-
const url = `${baseUrl}/api/realm/${encodeURIComponent(realm)}/nodes/${encodeURIComponent(nodeKey)}`;
|
|
431
|
+
const url = `${baseUrl}/api/realm/${encodeURIComponent(realm)}/nodes/raw/${encodeURIComponent(nodeKey)}`;
|
|
207
432
|
try {
|
|
208
433
|
const response = await fetch(url, {
|
|
209
434
|
method: "PUT",
|
|
@@ -236,7 +461,6 @@ var putNode = async (baseUrl, realm, accessTokenBase64, nodeKey, content) => {
|
|
|
236
461
|
};
|
|
237
462
|
}
|
|
238
463
|
};
|
|
239
|
-
|
|
240
464
|
// src/api/oauth.ts
|
|
241
465
|
var getOAuthConfig = async (baseUrl) => {
|
|
242
466
|
return fetchApi(`${baseUrl}/api/oauth/config`);
|
|
@@ -263,12 +487,11 @@ var getMe = async (baseUrl, userAccessToken) => {
|
|
|
263
487
|
return fetchWithAuth(`${baseUrl}/api/oauth/me`, `Bearer ${userAccessToken}`);
|
|
264
488
|
};
|
|
265
489
|
var tokenResponseToStoredUserToken = (response, userId) => ({
|
|
266
|
-
accessToken: response.accessToken,
|
|
490
|
+
accessToken: response.idToken ?? response.accessToken,
|
|
267
491
|
refreshToken: response.refreshToken,
|
|
268
492
|
userId,
|
|
269
|
-
expiresAt: Date.now() + response.expiresIn *
|
|
493
|
+
expiresAt: Date.now() + response.expiresIn * 1000
|
|
270
494
|
});
|
|
271
|
-
|
|
272
495
|
// src/api/requests.ts
|
|
273
496
|
var createAuthRequest = async (baseUrl, params) => {
|
|
274
497
|
return fetchApi(`${baseUrl}/api/tokens/requests`, {
|
|
@@ -277,145 +500,70 @@ var createAuthRequest = async (baseUrl, params) => {
|
|
|
277
500
|
});
|
|
278
501
|
};
|
|
279
502
|
var pollAuthRequest = async (baseUrl, requestId) => {
|
|
280
|
-
return fetchApi(
|
|
281
|
-
`${baseUrl}/api/tokens/requests/${encodeURIComponent(requestId)}/poll`
|
|
282
|
-
);
|
|
503
|
+
return fetchApi(`${baseUrl}/api/tokens/requests/${encodeURIComponent(requestId)}/poll`);
|
|
283
504
|
};
|
|
284
505
|
var getAuthRequest = async (baseUrl, userAccessToken, requestId) => {
|
|
285
|
-
return fetchWithAuth(
|
|
286
|
-
`${baseUrl}/api/tokens/requests/${encodeURIComponent(requestId)}`,
|
|
287
|
-
`Bearer ${userAccessToken}`
|
|
288
|
-
);
|
|
506
|
+
return fetchWithAuth(`${baseUrl}/api/tokens/requests/${encodeURIComponent(requestId)}`, `Bearer ${userAccessToken}`);
|
|
289
507
|
};
|
|
290
508
|
var approveAuthRequest = async (baseUrl, userAccessToken, requestId, params) => {
|
|
291
|
-
return fetchWithAuth(
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
method: "POST",
|
|
296
|
-
body: params ?? {}
|
|
297
|
-
}
|
|
298
|
-
);
|
|
509
|
+
return fetchWithAuth(`${baseUrl}/api/tokens/requests/${encodeURIComponent(requestId)}/approve`, `Bearer ${userAccessToken}`, {
|
|
510
|
+
method: "POST",
|
|
511
|
+
body: params ?? {}
|
|
512
|
+
});
|
|
299
513
|
};
|
|
300
514
|
var rejectAuthRequest = async (baseUrl, userAccessToken, requestId, params) => {
|
|
301
|
-
return fetchWithAuth(
|
|
302
|
-
`${baseUrl}/api/tokens/requests/${encodeURIComponent(requestId)}/reject`,
|
|
303
|
-
`Bearer ${userAccessToken}`,
|
|
304
|
-
{
|
|
305
|
-
method: "POST",
|
|
306
|
-
body: params ?? {}
|
|
307
|
-
}
|
|
308
|
-
);
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
// src/api/tickets.ts
|
|
312
|
-
var createTicket = async (baseUrl, realm, accessTokenBase64, params) => {
|
|
313
|
-
return fetchWithAuth(
|
|
314
|
-
`${baseUrl}/api/realm/${encodeURIComponent(realm)}/tickets`,
|
|
315
|
-
`Bearer ${accessTokenBase64}`,
|
|
316
|
-
{
|
|
317
|
-
method: "POST",
|
|
318
|
-
body: params
|
|
319
|
-
}
|
|
320
|
-
);
|
|
321
|
-
};
|
|
322
|
-
var listTickets = async (baseUrl, realm, accessTokenBase64, params) => {
|
|
323
|
-
const query = new URLSearchParams();
|
|
324
|
-
if (params?.limit) query.set("limit", String(params.limit));
|
|
325
|
-
if (params?.cursor) query.set("cursor", params.cursor);
|
|
326
|
-
if (params?.status) query.set("status", params.status);
|
|
327
|
-
const queryString = query.toString();
|
|
328
|
-
const url = `${baseUrl}/api/realm/${encodeURIComponent(realm)}/tickets${queryString ? `?${queryString}` : ""}`;
|
|
329
|
-
return fetchWithAuth(url, `Bearer ${accessTokenBase64}`);
|
|
330
|
-
};
|
|
331
|
-
var getTicket = async (baseUrl, realm, accessTokenBase64, ticketId) => {
|
|
332
|
-
return fetchWithAuth(
|
|
333
|
-
`${baseUrl}/api/realm/${encodeURIComponent(realm)}/tickets/${encodeURIComponent(ticketId)}`,
|
|
334
|
-
`Bearer ${accessTokenBase64}`
|
|
335
|
-
);
|
|
336
|
-
};
|
|
337
|
-
var submitTicket = async (baseUrl, realm, accessTokenBase64, ticketId, params) => {
|
|
338
|
-
return fetchWithAuth(
|
|
339
|
-
`${baseUrl}/api/realm/${encodeURIComponent(realm)}/tickets/${encodeURIComponent(ticketId)}/submit`,
|
|
340
|
-
`Bearer ${accessTokenBase64}`,
|
|
341
|
-
{
|
|
342
|
-
method: "POST",
|
|
343
|
-
body: params
|
|
344
|
-
}
|
|
345
|
-
);
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
// src/api/tokens.ts
|
|
349
|
-
var createToken = async (baseUrl, userAccessToken, params) => {
|
|
350
|
-
return fetchWithAuth(`${baseUrl}/api/tokens`, `Bearer ${userAccessToken}`, {
|
|
515
|
+
return fetchWithAuth(`${baseUrl}/api/tokens/requests/${encodeURIComponent(requestId)}/reject`, `Bearer ${userAccessToken}`, {
|
|
351
516
|
method: "POST",
|
|
352
|
-
body: params
|
|
517
|
+
body: params ?? {}
|
|
353
518
|
});
|
|
354
519
|
};
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
const queryString = query.toString();
|
|
361
|
-
const url = `${baseUrl}/api/tokens${queryString ? `?${queryString}` : ""}`;
|
|
362
|
-
return fetchWithAuth(url, `Bearer ${userAccessToken}`);
|
|
363
|
-
};
|
|
364
|
-
var getToken = async (baseUrl, userAccessToken, tokenId) => {
|
|
365
|
-
return fetchWithAuth(
|
|
366
|
-
`${baseUrl}/api/tokens/${encodeURIComponent(tokenId)}`,
|
|
367
|
-
`Bearer ${userAccessToken}`
|
|
368
|
-
);
|
|
369
|
-
};
|
|
370
|
-
var revokeToken = async (baseUrl, userAccessToken, tokenId) => {
|
|
371
|
-
return fetchWithAuth(
|
|
372
|
-
`${baseUrl}/api/tokens/${encodeURIComponent(tokenId)}/revoke`,
|
|
373
|
-
`Bearer ${userAccessToken}`,
|
|
374
|
-
{ method: "POST" }
|
|
375
|
-
);
|
|
376
|
-
};
|
|
377
|
-
var delegateToken = async (baseUrl, delegateTokenBase64, params) => {
|
|
378
|
-
return fetchWithAuth(
|
|
379
|
-
`${baseUrl}/api/tokens/delegate`,
|
|
380
|
-
`Bearer ${delegateTokenBase64}`,
|
|
381
|
-
{
|
|
382
|
-
method: "POST",
|
|
383
|
-
body: params
|
|
384
|
-
}
|
|
385
|
-
);
|
|
520
|
+
// src/api/tokens.ts
|
|
521
|
+
var refreshToken = async (baseUrl, refreshTokenBase64) => {
|
|
522
|
+
return fetchWithAuth(`${baseUrl}/api/auth/refresh`, `Bearer ${refreshTokenBase64}`, {
|
|
523
|
+
method: "POST"
|
|
524
|
+
});
|
|
386
525
|
};
|
|
387
526
|
export {
|
|
388
|
-
|
|
389
|
-
commitDepot,
|
|
390
|
-
createAuthRequest,
|
|
391
|
-
createDepot,
|
|
392
|
-
createTicket,
|
|
393
|
-
createToken,
|
|
394
|
-
delegateToken,
|
|
395
|
-
deleteDepot,
|
|
396
|
-
exchangeCode,
|
|
397
|
-
fetchServiceInfo,
|
|
398
|
-
getAuthRequest,
|
|
399
|
-
getDepot,
|
|
400
|
-
getMe,
|
|
401
|
-
getNode,
|
|
402
|
-
getNodeMetadata,
|
|
403
|
-
getOAuthConfig,
|
|
404
|
-
getTicket,
|
|
405
|
-
getToken,
|
|
406
|
-
healthCheck,
|
|
407
|
-
listDepots,
|
|
408
|
-
listTickets,
|
|
409
|
-
listTokens,
|
|
410
|
-
login,
|
|
411
|
-
pollAuthRequest,
|
|
412
|
-
prepareNodes,
|
|
413
|
-
putNode,
|
|
414
|
-
refresh,
|
|
415
|
-
rejectAuthRequest,
|
|
416
|
-
revokeToken,
|
|
417
|
-
submitTicket,
|
|
527
|
+
updateDepot,
|
|
418
528
|
tokenResponseToStoredUserToken,
|
|
419
|
-
|
|
529
|
+
revokeDelegate,
|
|
530
|
+
rejectAuthRequest,
|
|
531
|
+
refreshToken,
|
|
532
|
+
refresh,
|
|
533
|
+
putNode,
|
|
534
|
+
pollAuthRequest,
|
|
535
|
+
login,
|
|
536
|
+
listDepots,
|
|
537
|
+
listDelegates,
|
|
538
|
+
healthCheck,
|
|
539
|
+
getOAuthConfig,
|
|
540
|
+
getNodeNavigated,
|
|
541
|
+
getNodeMetadata,
|
|
542
|
+
getNode,
|
|
543
|
+
getMe,
|
|
544
|
+
getDepot,
|
|
545
|
+
getDelegate,
|
|
546
|
+
getAuthRequest,
|
|
547
|
+
fsWrite,
|
|
548
|
+
fsStat,
|
|
549
|
+
fsRm,
|
|
550
|
+
fsRewrite,
|
|
551
|
+
fsRead,
|
|
552
|
+
fsMv,
|
|
553
|
+
fsMkdir,
|
|
554
|
+
fsLs,
|
|
555
|
+
fsCp,
|
|
556
|
+
fetchServiceInfo,
|
|
557
|
+
exchangeCode,
|
|
558
|
+
deleteDepot,
|
|
559
|
+
createDepot,
|
|
560
|
+
createDelegate,
|
|
561
|
+
createAuthRequest,
|
|
562
|
+
commitDepot,
|
|
563
|
+
claimNode,
|
|
564
|
+
checkNodes,
|
|
565
|
+
batchClaimNodes,
|
|
566
|
+
approveAuthRequest
|
|
420
567
|
};
|
|
421
|
-
|
|
568
|
+
|
|
569
|
+
//# debugId=514FBDA2B32CF85B64756E2164756E21
|