@enformik/cli 0.2.0 → 0.5.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/LICENSE +21 -0
- package/README.md +3 -3
- package/dist/cli.js +29 -8
- package/dist/codegen.js +137 -0
- package/dist/commands/ai.js +168 -0
- package/dist/commands/app.js +142 -0
- package/dist/commands/codegen.js +42 -0
- package/dist/commands/schema.js +72 -5
- package/dist/commands/site.js +47 -9
- package/dist/commands/whoami.js +3 -2
- package/dist/config.js +2 -0
- package/dist/http.js +10 -1
- package/dist/output.js +1 -1
- package/dist/precheck.js +104 -3
- package/dist/schema.js +62 -8
- package/dist/site.js +30 -7
- package/dist/zip.js +8 -2
- package/package.json +2 -2
package/dist/site.js
CHANGED
|
@@ -2,7 +2,7 @@ import { execFileSync } from 'node:child_process';
|
|
|
2
2
|
import { createHash, randomUUID } from 'node:crypto';
|
|
3
3
|
import { readFileSync } from 'node:fs';
|
|
4
4
|
import { ApiError, CliError } from './errors.js';
|
|
5
|
-
import { ensureOk, joinUrl, request } from './http.js';
|
|
5
|
+
import { assertSecureUrl, ensureOk, joinUrl, request } from './http.js';
|
|
6
6
|
// Web sitesi dağıtımı — makine uçları (/api/deploy/v1) istemcisi. Akış: init → PUT content → finalize → poll.
|
|
7
7
|
// Sözleşme: docs/plans/DEVELOPER_PLATFORM_DEPLOY_DESIGN.md §3.4, §4.
|
|
8
8
|
export const MAX_ARCHIVE_BYTES = 50 * 1024 * 1024;
|
|
@@ -10,6 +10,8 @@ export class DeployClient {
|
|
|
10
10
|
o;
|
|
11
11
|
constructor(o) {
|
|
12
12
|
this.o = o;
|
|
13
|
+
// Her kullanım yolunda (deploy, status, whoami, app check) dağıtım anahtarı düz metin gitmesin.
|
|
14
|
+
assertSecureUrl(o.consoleUrl, 'Konsol adresi');
|
|
13
15
|
}
|
|
14
16
|
url(path) { return joinUrl(this.o.consoleUrl, `/api/deploy/v1${path}`); }
|
|
15
17
|
headers(extra = {}) {
|
|
@@ -44,6 +46,8 @@ export class DeployClient {
|
|
|
44
46
|
return (await this.call(`/deployments/${id}`, { retries: 2 })).deployment;
|
|
45
47
|
}
|
|
46
48
|
}
|
|
49
|
+
/** Üst üste bu kadar yoklama hatasından sonra bırakılır. */
|
|
50
|
+
const MAX_POLL_FAILURES = 5;
|
|
47
51
|
const TERMINAL = new Set(['live', 'failed', 'expired', 'superseded']);
|
|
48
52
|
export const isTerminal = (s) => TERMINAL.has(s);
|
|
49
53
|
/** Durum değiştikçe onStatus çağırarak terminal duruma kadar bekler. */
|
|
@@ -53,8 +57,24 @@ export async function waitForDeployment(client, id, opts) {
|
|
|
53
57
|
const start = now();
|
|
54
58
|
let last = '';
|
|
55
59
|
let interval = opts.intervalMs ?? 2000;
|
|
60
|
+
let failures = 0;
|
|
56
61
|
for (;;) {
|
|
57
|
-
|
|
62
|
+
let v;
|
|
63
|
+
try {
|
|
64
|
+
v = await client.status(id);
|
|
65
|
+
failures = 0;
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
// Geçici hata (ağ, 5xx): sunucu dağıtımı yayınlıyor olabilir, tek bir yoklama hatası CI'ı kırmasın.
|
|
69
|
+
// Kalıcı hatalar (geçersiz anahtar, 404…) kodla gelir ve hemen iletilir.
|
|
70
|
+
const transient = e instanceof CliError && (!e.code || e.code === 'deploy_unavailable');
|
|
71
|
+
if (!transient || ++failures >= MAX_POLL_FAILURES)
|
|
72
|
+
throw e;
|
|
73
|
+
if (now() - start > opts.timeoutMs)
|
|
74
|
+
throw e;
|
|
75
|
+
await sleep(interval);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
58
78
|
if (v.status !== last) {
|
|
59
79
|
last = v.status;
|
|
60
80
|
opts.onStatus?.(v.status);
|
|
@@ -94,14 +114,17 @@ function gitCmd(cwd, args) {
|
|
|
94
114
|
}
|
|
95
115
|
}
|
|
96
116
|
/**
|
|
97
|
-
* Idempotency-Key: CI'da koşu + deneme numarası (yeniden çalıştırma yeni anahtar alır,
|
|
98
|
-
* dağıtım "tekrar oynatılırdı"
|
|
117
|
+
* Idempotency-Key: CI'da koşu + deneme numarası + arşiv sağlama toplamının başı (yeniden çalıştırma yeni anahtar alır,
|
|
118
|
+
* yoksa eski — belki başarısız — dağıtım "tekrar oynatılırdı"; aynı işte farklı içerikli iki dağıtım da aynı anahtarı
|
|
119
|
+
* paylaşmaz); yerelde her çalıştırma için rastgele.
|
|
99
120
|
*/
|
|
100
|
-
export function idempotencyKey(env, rand = randomUUID) {
|
|
121
|
+
export function idempotencyKey(env, rand = randomUUID, contentSha) {
|
|
122
|
+
const tail = contentSha ? `-${contentSha.slice(0, 12)}` : '';
|
|
123
|
+
const fit = (base) => `${base.slice(0, 64 - tail.length)}${tail}`;
|
|
101
124
|
if (env.GITHUB_RUN_ID)
|
|
102
|
-
return `gh-${env.GITHUB_RUN_ID}-${env.GITHUB_RUN_ATTEMPT ?? '1'}
|
|
125
|
+
return fit(`gh-${env.GITHUB_RUN_ID}-${env.GITHUB_RUN_ATTEMPT ?? '1'}`);
|
|
103
126
|
if (env.CI_PIPELINE_ID)
|
|
104
|
-
return `gl-${env.CI_PIPELINE_ID}-${env.CI_JOB_ID ?? '0'}
|
|
127
|
+
return fit(`gl-${env.CI_PIPELINE_ID}-${env.CI_JOB_ID ?? '0'}`);
|
|
105
128
|
return `cli-${rand()}`.slice(0, 64);
|
|
106
129
|
}
|
|
107
130
|
const HINTS = {
|
package/dist/zip.js
CHANGED
|
@@ -17,7 +17,7 @@ export function crc32(buf) {
|
|
|
17
17
|
return (c ^ 0xffffffff) >>> 0;
|
|
18
18
|
}
|
|
19
19
|
function dosDateTime(d) {
|
|
20
|
-
const y = Math.max(1980, d.getFullYear());
|
|
20
|
+
const y = Math.min(2107, Math.max(1980, d.getFullYear())); // DOS tarihi yıl alanı 7 bit (1980–2107)
|
|
21
21
|
return {
|
|
22
22
|
time: (d.getHours() << 11) | (d.getMinutes() << 5) | Math.floor(d.getSeconds() / 2),
|
|
23
23
|
date: ((y - 1980) << 9) | ((d.getMonth() + 1) << 5) | d.getDate(),
|
|
@@ -33,7 +33,13 @@ export function writeZipFile(files, outPath) {
|
|
|
33
33
|
const fd = openSync(outPath, 'w');
|
|
34
34
|
let offset = 0;
|
|
35
35
|
const central = [];
|
|
36
|
-
|
|
36
|
+
// writeSync kısmi yazabilir (disk dolu, sinyal); kesik zip geçerli sağlama toplamıyla yüklenmesin diye tamamlanana dek döner.
|
|
37
|
+
const write = (b) => {
|
|
38
|
+
let done = 0;
|
|
39
|
+
while (done < b.length)
|
|
40
|
+
done += writeSync(fd, b, done, b.length - done);
|
|
41
|
+
offset += b.length;
|
|
42
|
+
};
|
|
37
43
|
try {
|
|
38
44
|
for (const f of sorted) {
|
|
39
45
|
const data = readFileSync(f.path);
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enformik/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Enformik geliştirici CLI'si: web sitesi dağıtımı ve uygulama modülü (şema) yükseltme.",
|
|
5
|
-
"license": "
|
|
5
|
+
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
8
|
"enformik": "dist/cli.js"
|