@akanjs/cli 3.1.0-rc.1 → 3.1.0-rc.3
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/.build-stamp +1 -1
- package/{CodeAgent-kyprmy06.js → CodeAgent-ctk4fh2b.js} +2 -2
- package/{CodeTui-21mtze3j.js → CodeTui-mrxtrdzw.js} +1 -1
- package/TunnelShare-rj74jd6x.js +13 -0
- package/{agent.command-f3gsc1gd.js → agent.command-ncre6kwz.js} +5 -5
- package/akanCode.js +2 -2
- package/{application.command-5s780vnz.js → application.command-54mawreg.js} +52 -41
- package/{applicationBuildRunner-1yaqsrdq.js → applicationBuildRunner-8573zr2w.js} +16 -30
- package/buildBatch.proc.js +22 -13
- package/{cloud.command-yj6xb2a7.js → cloud.command-nyemv0m3.js} +57 -65
- package/cloud.script-ht6yb203.js +23 -0
- package/{code.command-3wkn4ja5.js → code.command-spsrzg63.js} +6 -6
- package/{context.command-9jjn3gcw.js → context.command-768zv7z4.js} +16 -13
- package/context.runner-tf1b53qq.js +24 -0
- package/{guideline.command-dtczrqpf.js → guideline.command-4ycwc51q.js} +2 -2
- package/guidelines/conventions/conventions.instruction.md +28 -15
- package/guidelines/cssRule/cssRule.instruction.md +12 -6
- package/guidelines/mcpRule/mcpRule.instruction.md +27 -11
- package/guidelines/runtimeRule/runtimeRule.instruction.md +24 -15
- package/guidelines/transportRule/transportRule.instruction.md +28 -5
- package/incrementalBuilder.proc.js +9 -6
- package/{index-2etcv0sc.js → index-00seamy5.js} +1 -1
- package/{index-jx4bzvwg.js → index-1a7nhq56.js} +92 -52
- package/{index-e0cvze1s.js → index-1nyxvz8j.js} +4 -4
- package/index-2z3kykvd.js +248 -0
- package/{index-rtct7d43.js → index-3675mvjw.js} +1 -1
- package/{index-56d2g8ms.js → index-3ddt3qjg.js} +1 -1
- package/{index-6jjtnhkw.js → index-3x7yeecy.js} +51 -9
- package/{index-ww9bhp67.js → index-4pf8g7ff.js} +1 -1
- package/index-8935h3n1.js +33 -0
- package/{index-v29746vb.js → index-8eqkxwsx.js} +3 -3
- package/{index-c2yrsxdh.js → index-91rt5bye.js} +96 -320
- package/{index-55mynnqs.js → index-bv210r6t.js} +459 -210
- package/{index-c76k723e.js → index-c4h5b5nq.js} +2 -2
- package/{index-qt22xstj.js → index-c9zjb3tw.js} +5 -3
- package/{index-c1x0be5j.js → index-dmsvd2rv.js} +2 -2
- package/index-ec080x99.js +1124 -0
- package/{index-ctanya41.js → index-fjqvd5mx.js} +4 -4
- package/{index-aprt7pkz.js → index-fvn6f5wx.js} +229 -1327
- package/{index-rc5rwyps.js → index-jj7yapwq.js} +71 -60
- package/index-kmamh5bv.js +241 -0
- package/{index-fm46xrf1.js → index-q5abh0jq.js} +3 -3
- package/{index-1w2qaee2.js → index-qf8g88j9.js} +361 -291
- package/{index-gnyf1fqy.js → index-qvghfv6v.js} +2 -2
- package/{index-ae5pwhgs.js → index-r5d6rq19.js} +10 -8
- package/{index-2mx692qq.js → index-vhfjzda3.js} +2 -2
- package/{index-8r4d7cmt.js → index-w9b71b6y.js} +4 -4
- package/{index-8ggztp8k.js → index-wanhh011.js} +42 -177
- package/{index-05g3jayg.js → index-wdze51wz.js} +1 -1
- package/index-wjqbc7sf.js +668 -0
- package/{index-rwq3ekqc.js → index-xf40a295.js} +7 -7
- package/{index-krq7btbt.js → index-xm5tmpv0.js} +3 -3
- package/index.js +22 -22
- package/{library.command-gaga5bmq.js → library.command-88ahgych.js} +3 -3
- package/{localRegistry.command-vsreyy42.js → localRegistry.command-ykea1m7b.js} +12 -9
- package/{module.command-7vpf6db4.js → module.command-zky4b7m9.js} +5 -5
- package/{package.command-twmvvf69.js → package.command-vh8pcedh.js} +3 -3
- package/package.json +2 -2
- package/{page.command-5asq7fdf.js → page.command-fyqeqxc3.js} +3 -3
- package/{pipeline.command-d0v38572.js → pipeline.command-r5t30py6.js} +220 -219
- package/{primitive.command-dyrs2fm8.js → primitive.command-a0516zfk.js} +6 -6
- package/{projectTypecheck-cvtkrzp2.js → projectTypecheck-7djd4z50.js} +1 -1
- package/{quality.command-6emsqpbg.js → quality.command-k7jcnfn0.js} +2 -2
- package/{repair.command-8t6aegv5.js → repair.command-85zg2an3.js} +5 -5
- package/{scalar.command-bnggy1x7.js → scalar.command-g5vmqwca.js} +4 -4
- package/{subspace.command-md2teygq.js → subspace.command-mp4evgsj.js} +421 -362
- package/{tunnel.command-jx3tdm2d.js → tunnel.command-kbnr99sj.js} +7 -4
- package/{workflow.command-jx0wag5r.js → workflow.command-9y9p1n8y.js} +10 -10
- package/{workspace.command-yxd7rr7g.js → workspace.command-jmec2kjg.js} +33 -30
- package/TunnelShare-q4jq08qg.js +0 -9
- package/cloud.script-h6pvcpa2.js +0 -20
- package/context.runner-atcrzz5b.js +0 -21
- package/index-6w0rbr9d.js +0 -68
- package/index-pgj2rt78.js +0 -404
package/index-pgj2rt78.js
DELETED
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import {
|
|
3
|
-
FileSys2
|
|
4
|
-
} from "./index-52w0fvh8.js";
|
|
5
|
-
import {
|
|
6
|
-
ConfigLock
|
|
7
|
-
} from "./index-3hx1z96c.js";
|
|
8
|
-
|
|
9
|
-
// pkgs/@akanjs/devkit/cloud/globalConfig.ts
|
|
10
|
-
import { mkdir, rm, writeFile } from "fs/promises";
|
|
11
|
-
import dayjs from "dayjs";
|
|
12
|
-
|
|
13
|
-
// pkgs/@akanjs/devkit/cloud/constants.ts
|
|
14
|
-
import path from "path";
|
|
15
|
-
var basePath = path.join(Bun.env.HOME ?? Bun.env.USERPROFILE ?? "", ".akan");
|
|
16
|
-
var configPath = path.join(basePath, "config.json");
|
|
17
|
-
var getDefaultHostConfig = (host = GlobalConfig.akanCloudHost) => ({ host });
|
|
18
|
-
var defaultAkanGlobalConfig = {
|
|
19
|
-
cloudHost: {},
|
|
20
|
-
remoteEnvServers: {},
|
|
21
|
-
testTargets: {}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// pkgs/@akanjs/devkit/cloud/globalConfig.ts
|
|
25
|
-
class GlobalConfig {
|
|
26
|
-
static akanCloudHost = process.env.USE_AKANJS_PKGS === "true" ? `http://localhost:${process.env.CLOUD_HOST_PORT ?? 8283}` : "https://cloud.akanjs.com";
|
|
27
|
-
static async#getAkanGlobalConfig() {
|
|
28
|
-
const exists = await FileSys2.fileExists(configPath);
|
|
29
|
-
const akanConfig = exists ? await FileSys2.readJson(configPath) : {};
|
|
30
|
-
return {
|
|
31
|
-
...defaultAkanGlobalConfig,
|
|
32
|
-
...akanConfig,
|
|
33
|
-
cloudHost: akanConfig.cloudHost ?? defaultAkanGlobalConfig.cloudHost,
|
|
34
|
-
remoteEnvServers: akanConfig.remoteEnvServers ?? defaultAkanGlobalConfig.remoteEnvServers,
|
|
35
|
-
testTargets: akanConfig.testTargets ?? defaultAkanGlobalConfig.testTargets
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
static async#setAkanGlobalConfig(akanConfig) {
|
|
39
|
-
await mkdir(basePath, { recursive: true, mode: 448 });
|
|
40
|
-
const temp = `${configPath}.${process.pid}.${crypto.randomUUID()}.tmp`;
|
|
41
|
-
try {
|
|
42
|
-
await writeFile(temp, JSON.stringify(akanConfig, null, 2), { mode: 384 });
|
|
43
|
-
await FileSys2.replace(temp, configPath);
|
|
44
|
-
} catch (error) {
|
|
45
|
-
await rm(temp, { force: true });
|
|
46
|
-
throw error;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
static #lockPath = `${configPath}.lock`;
|
|
50
|
-
static async#update(mutate) {
|
|
51
|
-
await ConfigLock.run(GlobalConfig.#lockPath, async () => {
|
|
52
|
-
await GlobalConfig.#setAkanGlobalConfig(mutate(await GlobalConfig.#getAkanGlobalConfig()));
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
static async hostFor(workspace, host) {
|
|
56
|
-
if (host)
|
|
57
|
-
return host;
|
|
58
|
-
return (await workspace.getConfig()).cloudHost ?? GlobalConfig.akanCloudHost;
|
|
59
|
-
}
|
|
60
|
-
static async getHostConfig(host = GlobalConfig.akanCloudHost) {
|
|
61
|
-
const akanConfig = await GlobalConfig.#getAkanGlobalConfig();
|
|
62
|
-
return GlobalConfig.toHostConfig(akanConfig.cloudHost[host] ?? getDefaultHostConfig(host));
|
|
63
|
-
}
|
|
64
|
-
static async setHostConfig(config = getDefaultHostConfig()) {
|
|
65
|
-
await GlobalConfig.#update((akanConfig) => GlobalConfig.#withHost(akanConfig, config));
|
|
66
|
-
}
|
|
67
|
-
static #withHost(akanConfig, config) {
|
|
68
|
-
return {
|
|
69
|
-
...akanConfig,
|
|
70
|
-
cloudHost: { ...akanConfig.cloudHost, [config.host]: GlobalConfig.toHostConfigDto(config) }
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
static async refreshHostAuth(host, refresh) {
|
|
74
|
-
try {
|
|
75
|
-
return await ConfigLock.run(GlobalConfig.#lockPath, async () => {
|
|
76
|
-
const akanConfig = await GlobalConfig.#getAkanGlobalConfig();
|
|
77
|
-
const current = GlobalConfig.toHostConfig(akanConfig.cloudHost[host] ?? getDefaultHostConfig(host));
|
|
78
|
-
const accessToken = current.auth?.accessToken;
|
|
79
|
-
const refreshToken = accessToken?.refreshToken;
|
|
80
|
-
if (!accessToken || !refreshToken || !GlobalConfig.needRefreshToken(accessToken))
|
|
81
|
-
return current;
|
|
82
|
-
const claimed = {
|
|
83
|
-
...current,
|
|
84
|
-
auth: { ...current.auth, accessToken: { ...accessToken, refreshToken: null } }
|
|
85
|
-
};
|
|
86
|
-
await GlobalConfig.#setAkanGlobalConfig(GlobalConfig.#withHost(akanConfig, claimed));
|
|
87
|
-
const next = await refresh(refreshToken).catch(() => null);
|
|
88
|
-
if (!next?.jwt)
|
|
89
|
-
return claimed;
|
|
90
|
-
const refreshed = { ...current, auth: { ...current.auth, accessToken: next } };
|
|
91
|
-
await GlobalConfig.#setAkanGlobalConfig(GlobalConfig.#withHost(await GlobalConfig.#getAkanGlobalConfig(), refreshed));
|
|
92
|
-
return refreshed;
|
|
93
|
-
});
|
|
94
|
-
} catch {
|
|
95
|
-
return await GlobalConfig.getHostConfig(host);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
static async getRemoteEnvServers() {
|
|
99
|
-
return (await GlobalConfig.#getAkanGlobalConfig()).remoteEnvServers;
|
|
100
|
-
}
|
|
101
|
-
static async setRemoteEnvServer(name, config) {
|
|
102
|
-
await GlobalConfig.#update((akanConfig) => ({
|
|
103
|
-
...akanConfig,
|
|
104
|
-
remoteEnvServers: { ...akanConfig.remoteEnvServers, [name]: config }
|
|
105
|
-
}));
|
|
106
|
-
}
|
|
107
|
-
static async removeRemoteEnvServer(name) {
|
|
108
|
-
await GlobalConfig.#update((akanConfig) => {
|
|
109
|
-
const { [name]: _, ...remoteEnvServers } = akanConfig.remoteEnvServers;
|
|
110
|
-
return { ...akanConfig, remoteEnvServers };
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
static async getTestTargets() {
|
|
114
|
-
return (await GlobalConfig.#getAkanGlobalConfig()).testTargets;
|
|
115
|
-
}
|
|
116
|
-
static async setTestTargets(testTargets) {
|
|
117
|
-
await GlobalConfig.#update((akanConfig) => ({
|
|
118
|
-
...akanConfig,
|
|
119
|
-
testTargets: { ...akanConfig.testTargets, ...testTargets }
|
|
120
|
-
}));
|
|
121
|
-
}
|
|
122
|
-
static needRefreshToken(accessToken) {
|
|
123
|
-
return !!accessToken?.expiresAt?.isBefore(dayjs().add(1, "hour"));
|
|
124
|
-
}
|
|
125
|
-
static toAccessToken(accessToken) {
|
|
126
|
-
return {
|
|
127
|
-
jwt: accessToken.jwt,
|
|
128
|
-
refreshToken: accessToken.refreshToken ?? null,
|
|
129
|
-
expiresAt: accessToken.expiresAt ? dayjs(accessToken.expiresAt) : null
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
static toAccessTokenDto(accessToken) {
|
|
133
|
-
return {
|
|
134
|
-
jwt: accessToken.jwt,
|
|
135
|
-
refreshToken: accessToken.refreshToken ?? null,
|
|
136
|
-
expiresAt: accessToken.expiresAt?.toString() ?? null
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
static toHostConfigDto(hostConfig) {
|
|
140
|
-
return {
|
|
141
|
-
host: hostConfig.host,
|
|
142
|
-
auth: {
|
|
143
|
-
accessToken: hostConfig.auth?.accessToken ? GlobalConfig.toAccessTokenDto(hostConfig.auth.accessToken) : undefined,
|
|
144
|
-
self: hostConfig.auth?.self
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
static toHostConfig(hostConfigDto) {
|
|
149
|
-
return {
|
|
150
|
-
host: hostConfigDto.host,
|
|
151
|
-
auth: {
|
|
152
|
-
accessToken: hostConfigDto.auth?.accessToken ? GlobalConfig.toAccessToken(hostConfigDto.auth.accessToken) : undefined,
|
|
153
|
-
self: hostConfigDto.auth?.self
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// pkgs/@akanjs/devkit/cloud/cloudApi.ts
|
|
160
|
-
class HttpClient {
|
|
161
|
-
baseUrl;
|
|
162
|
-
headers = {};
|
|
163
|
-
constructor(baseUrl, headers = {}) {
|
|
164
|
-
this.baseUrl = baseUrl;
|
|
165
|
-
this.headers = headers;
|
|
166
|
-
}
|
|
167
|
-
async get(url, { headers, signal } = {}) {
|
|
168
|
-
const response = await fetch(`${this.baseUrl}${url}`, {
|
|
169
|
-
headers: { "Content-Type": "application/json", ...this.headers, ...headers },
|
|
170
|
-
...signal ? { signal } : {}
|
|
171
|
-
});
|
|
172
|
-
return await HttpClient.#body(response, url);
|
|
173
|
-
}
|
|
174
|
-
async getFile(url, localPath, headers) {
|
|
175
|
-
const response = await fetch(`${this.baseUrl}${url}`, {
|
|
176
|
-
headers: { ...this.headers, ...headers }
|
|
177
|
-
});
|
|
178
|
-
if (!response.ok)
|
|
179
|
-
throw new Error(`Failed to download file: ${response.status} ${response.statusText}`);
|
|
180
|
-
await Bun.write(localPath, response);
|
|
181
|
-
}
|
|
182
|
-
async post(url, data, { headers, signal } = {}) {
|
|
183
|
-
const isFormData = data instanceof FormData;
|
|
184
|
-
const response = await fetch(`${this.baseUrl}${url}`, {
|
|
185
|
-
method: "POST",
|
|
186
|
-
body: isFormData ? data : JSON.stringify(data),
|
|
187
|
-
headers: isFormData ? { ...this.headers, ...headers } : { "Content-Type": "application/json", ...this.headers, ...headers },
|
|
188
|
-
...signal ? { signal } : {}
|
|
189
|
-
});
|
|
190
|
-
return await HttpClient.#body(response, url);
|
|
191
|
-
}
|
|
192
|
-
static async#body(response, url) {
|
|
193
|
-
const text = await response.text();
|
|
194
|
-
if (!response.ok)
|
|
195
|
-
throw new Error(`${response.status} ${response.statusText} from ${url}: ${text.slice(0, 200)}`);
|
|
196
|
-
return JSON.parse(text);
|
|
197
|
-
}
|
|
198
|
-
setHeaders(headers) {
|
|
199
|
-
Object.assign(this.headers, headers);
|
|
200
|
-
return this;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
class CloudApi {
|
|
205
|
-
static statusOf(error) {
|
|
206
|
-
const status = Number(/(?:^|: )(\d{3}) /.exec(error instanceof Error ? error.message : String(error))?.[1]);
|
|
207
|
-
return Number.isNaN(status) ? null : status;
|
|
208
|
-
}
|
|
209
|
-
#api;
|
|
210
|
-
#accessToken = null;
|
|
211
|
-
#workspace;
|
|
212
|
-
host;
|
|
213
|
-
url;
|
|
214
|
-
static async fromHost(workspace, host) {
|
|
215
|
-
const hostConfig = await GlobalConfig.getHostConfig(host);
|
|
216
|
-
const accessToken = hostConfig.auth?.accessToken;
|
|
217
|
-
if (!accessToken || !GlobalConfig.needRefreshToken(accessToken))
|
|
218
|
-
return new CloudApi(workspace, hostConfig);
|
|
219
|
-
const tokenless = new CloudApi(workspace, hostConfig);
|
|
220
|
-
const refreshed = await GlobalConfig.refreshHostAuth(hostConfig.host, (refreshToken) => tokenless.refreshAuthToken(refreshToken));
|
|
221
|
-
return new CloudApi(workspace, refreshed);
|
|
222
|
-
}
|
|
223
|
-
constructor(workspace, hostConfig) {
|
|
224
|
-
this.#workspace = workspace;
|
|
225
|
-
this.#accessToken = hostConfig.auth?.accessToken ?? null;
|
|
226
|
-
this.host = hostConfig.host;
|
|
227
|
-
this.url = `${this.host}/api`;
|
|
228
|
-
this.#api = new HttpClient(this.url);
|
|
229
|
-
if (this.#accessToken && !GlobalConfig.needRefreshToken(this.#accessToken))
|
|
230
|
-
this.#api.setHeaders({ Authorization: `Bearer ${this.#accessToken.jwt}` });
|
|
231
|
-
}
|
|
232
|
-
#authorize(accessTokenDto) {
|
|
233
|
-
this.#accessToken = GlobalConfig.toAccessToken(accessTokenDto);
|
|
234
|
-
this.#api.setHeaders({ Authorization: `Bearer ${this.#accessToken.jwt}` });
|
|
235
|
-
return this.#accessToken;
|
|
236
|
-
}
|
|
237
|
-
async uploadEnv(devProjectId, file) {
|
|
238
|
-
const formData = new FormData;
|
|
239
|
-
formData.append("devProjectId", devProjectId);
|
|
240
|
-
formData.append("file", file);
|
|
241
|
-
return await this.#api.post(`/uploadEnv/${devProjectId}`, formData);
|
|
242
|
-
}
|
|
243
|
-
async uploadSecret(devProjectId, secret) {
|
|
244
|
-
return await this.#api.post(`/uploadSecret/${encodeURIComponent(devProjectId)}`, secret);
|
|
245
|
-
}
|
|
246
|
-
async listSecrets(devProjectId) {
|
|
247
|
-
return await this.#api.get(`/listSecrets/${encodeURIComponent(devProjectId)}`);
|
|
248
|
-
}
|
|
249
|
-
async removeSecret(devProjectId, secret) {
|
|
250
|
-
return await this.#api.post(`/removeSecret/${encodeURIComponent(devProjectId)}`, secret);
|
|
251
|
-
}
|
|
252
|
-
async requestUpdateUpload(devProjectId, upload) {
|
|
253
|
-
return await this.#api.post(`/requestUpdateUpload/${encodeURIComponent(devProjectId)}`, upload);
|
|
254
|
-
}
|
|
255
|
-
async commitUpdateUpload(devProjectId, uploadId) {
|
|
256
|
-
return await this.#api.post(`/commitUpdateUpload/${encodeURIComponent(devProjectId)}`, { uploadId }, { signal: AbortSignal.timeout(11 * 60000) });
|
|
257
|
-
}
|
|
258
|
-
async registerAppBinary(devProjectId, binary) {
|
|
259
|
-
const formData = new FormData;
|
|
260
|
-
for (const key of ["appName", "target", "distribution"])
|
|
261
|
-
formData.append(key, binary[key]);
|
|
262
|
-
if (binary.channel)
|
|
263
|
-
formData.append("channel", binary.channel);
|
|
264
|
-
formData.append("bundle", binary.bundle, "bundle.json");
|
|
265
|
-
if (binary.packUploadId)
|
|
266
|
-
formData.append("packUploadId", binary.packUploadId);
|
|
267
|
-
if (binary.pack)
|
|
268
|
-
formData.append("pack", binary.pack, "pack.tgz");
|
|
269
|
-
return await this.#api.post(`/registerAppBinary/${encodeURIComponent(devProjectId)}`, formData, {
|
|
270
|
-
signal: AbortSignal.timeout(11 * 60000)
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
async downloadEnv(devProjectId) {
|
|
274
|
-
const localPath = `${this.#workspace.workspaceRoot}/local/env.tar`;
|
|
275
|
-
await this.#api.getFile(`/downloadEnv/${devProjectId}`, localPath);
|
|
276
|
-
return localPath;
|
|
277
|
-
}
|
|
278
|
-
async getRemoteAuthToken(remoteId) {
|
|
279
|
-
try {
|
|
280
|
-
return this.#authorize(await this.#api.get(`/getRemoteAuthToken/${remoteId}`));
|
|
281
|
-
} catch (_) {
|
|
282
|
-
return null;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
async refreshAuthToken(refreshToken) {
|
|
286
|
-
return this.#authorize(await this.#api.post(`/refreshAuthToken`, { refreshToken }, { signal: AbortSignal.timeout(20000) }));
|
|
287
|
-
}
|
|
288
|
-
async requestTunnel(input) {
|
|
289
|
-
return await this.#api.post(`/tunnel/requestTunnel`, input);
|
|
290
|
-
}
|
|
291
|
-
async tunnelListInSelf() {
|
|
292
|
-
return await this.#api.get(`/tunnel/tunnelListInSelf`);
|
|
293
|
-
}
|
|
294
|
-
async revokeTunnel(code) {
|
|
295
|
-
return await this.#api.post(`/tunnel/revokeTunnel`, { code }, { signal: AbortSignal.timeout(5000) });
|
|
296
|
-
}
|
|
297
|
-
async getRemoteSelf() {
|
|
298
|
-
try {
|
|
299
|
-
return await this.#api.get(`/getRemoteSelf`);
|
|
300
|
-
} catch {
|
|
301
|
-
return null;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
// pkgs/@akanjs/devkit/cloud/updatePackUpload.ts
|
|
306
|
-
import { Logger, sleep } from "akanjs/common";
|
|
307
|
-
class UpdatePackUpload {
|
|
308
|
-
static maxBytes = 200 * 1024 * 1024;
|
|
309
|
-
static #transientPut = new Set([0, 408, 429, 500, 502, 503, 504]);
|
|
310
|
-
#api;
|
|
311
|
-
#devProjectId;
|
|
312
|
-
#putRetryMs;
|
|
313
|
-
#commitRetryMs;
|
|
314
|
-
#cutOffWindowMs;
|
|
315
|
-
#commitLimitMs;
|
|
316
|
-
constructor(api, devProjectId, {
|
|
317
|
-
putRetryMs = 1000,
|
|
318
|
-
commitRetryMs = 1e4,
|
|
319
|
-
cutOffWindowMs = 15 * 60000,
|
|
320
|
-
commitLimitMs = 60 * 60000
|
|
321
|
-
} = {}) {
|
|
322
|
-
this.#api = api;
|
|
323
|
-
this.#devProjectId = devProjectId;
|
|
324
|
-
this.#putRetryMs = putRetryMs;
|
|
325
|
-
this.#commitRetryMs = commitRetryMs;
|
|
326
|
-
this.#cutOffWindowMs = cutOffWindowMs;
|
|
327
|
-
this.#commitLimitMs = commitLimitMs;
|
|
328
|
-
}
|
|
329
|
-
async send(archive, fields) {
|
|
330
|
-
const uploadId = await this.stage(archive, fields);
|
|
331
|
-
return await this.settle(() => this.#api.commitUpdateUpload(this.#devProjectId, uploadId));
|
|
332
|
-
}
|
|
333
|
-
async stage(archive, fields) {
|
|
334
|
-
const file = Bun.file(archive);
|
|
335
|
-
if (file.size < 1 || file.size > UpdatePackUpload.maxBytes)
|
|
336
|
-
throw new Error(`The pack archive is ${file.size} bytes; a project takes 1 byte to 200 MiB.`);
|
|
337
|
-
const hasher = new Bun.CryptoHasher("sha256");
|
|
338
|
-
for await (const chunk of file.stream())
|
|
339
|
-
hasher.update(chunk);
|
|
340
|
-
const upload = { ...fields, size: file.size, sha256: hasher.digest("hex") };
|
|
341
|
-
for (let ticket = 1;; ticket++) {
|
|
342
|
-
const { uploadId, uploadUrl, contentType } = await this.#request(upload);
|
|
343
|
-
const status = await this.#put(uploadUrl, contentType, file);
|
|
344
|
-
if (status >= 200 && status < 300)
|
|
345
|
-
return uploadId;
|
|
346
|
-
if (status !== 403 || ticket === 2)
|
|
347
|
-
throw new Error(`The storage refused the pack upload (${status ? `HTTP ${status}` : "no response"}).`);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
async#request(upload) {
|
|
351
|
-
return await this.#api.requestUpdateUpload(this.#devProjectId, upload).catch((error) => {
|
|
352
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
353
|
-
if (CloudApi.statusOf(error) === 404 && !/"error"\s*:\s*"[\w$-]+\.error\.[\w$-]+"/.test(message))
|
|
354
|
-
throw new Error("The project's server does not take direct pack uploads yet: update akasys and try again, or upload the pack from the project's release screen.");
|
|
355
|
-
throw error;
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
async#put(url, contentType, file) {
|
|
359
|
-
for (let retry = 0;; retry++) {
|
|
360
|
-
const status = await fetch(url, { method: "PUT", body: file, headers: { "Content-Type": contentType } }).then(async (response) => {
|
|
361
|
-
await response.arrayBuffer().catch(() => {
|
|
362
|
-
return;
|
|
363
|
-
});
|
|
364
|
-
return response.status;
|
|
365
|
-
}).catch(() => 0);
|
|
366
|
-
if (retry === 3 || !UpdatePackUpload.#transientPut.has(status))
|
|
367
|
-
return status;
|
|
368
|
-
await sleep(this.#putRetryMs * (retry + 1));
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
async settle(call) {
|
|
372
|
-
const limit = performance.now() + this.#commitLimitMs;
|
|
373
|
-
let cutOffSince = null;
|
|
374
|
-
for (;; ) {
|
|
375
|
-
try {
|
|
376
|
-
return await call();
|
|
377
|
-
} catch (error) {
|
|
378
|
-
const now = performance.now();
|
|
379
|
-
if (UpdatePackUpload.#inProgress(error))
|
|
380
|
-
cutOffSince = null;
|
|
381
|
-
else if (UpdatePackUpload.#cutOff(error))
|
|
382
|
-
cutOffSince ??= now;
|
|
383
|
-
else
|
|
384
|
-
throw error;
|
|
385
|
-
const deadline = cutOffSince === null ? limit : Math.min(limit, cutOffSince + this.#cutOffWindowMs);
|
|
386
|
-
if (now + this.#commitRetryMs > deadline)
|
|
387
|
-
throw error;
|
|
388
|
-
Logger.rawLog(`The project is still taking the pack; asking again in ${Math.round(this.#commitRetryMs / 1000)}s.`);
|
|
389
|
-
await sleep(this.#commitRetryMs);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
static #inProgress(error) {
|
|
394
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
395
|
-
return CloudApi.statusOf(error) === 409 && message.includes("uploadCommitInProgress");
|
|
396
|
-
}
|
|
397
|
-
static #cutOff(error) {
|
|
398
|
-
const status = CloudApi.statusOf(error);
|
|
399
|
-
if (status === null)
|
|
400
|
-
return !(error instanceof SyntaxError);
|
|
401
|
-
return status === 502 || status === 504 || status >= 520 && status <= 527;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
export { getDefaultHostConfig, GlobalConfig, CloudApi, UpdatePackUpload };
|