create-svc 0.1.72 → 0.1.74
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/package.json
CHANGED
|
@@ -348,9 +348,10 @@ async function runSdk(args: string[]) {
|
|
|
348
348
|
const [subcommand] = args;
|
|
349
349
|
if (subcommand === "publish") {
|
|
350
350
|
requireCommand("buf");
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
351
|
+
const authEnv = resolveBufAuthEnv();
|
|
352
|
+
ensureBufModule(authEnv);
|
|
353
|
+
run("buf", ["push"], { env: authEnv });
|
|
354
|
+
const published = resolvePublishedSdk(authEnv);
|
|
354
355
|
await writeSdkMode("remote", published);
|
|
355
356
|
return `Schema pushed to Buf Schema Registry and recorded for consumers: ${published.commit}`;
|
|
356
357
|
}
|
|
@@ -373,8 +374,8 @@ async function runSdk(args: string[]) {
|
|
|
373
374
|
|
|
374
375
|
if (subcommand === "use-remote") {
|
|
375
376
|
requireCommand("buf");
|
|
376
|
-
|
|
377
|
-
const published = resolvePublishedSdk();
|
|
377
|
+
const authEnv = resolveBufAuthEnv();
|
|
378
|
+
const published = resolvePublishedSdk(authEnv);
|
|
378
379
|
await writeSdkMode("remote", published);
|
|
379
380
|
return `Remote Buf SDK recorded for consumers: ${bufModule()}@${published.commit}`;
|
|
380
381
|
}
|
|
@@ -395,9 +396,9 @@ type PublishedSdk = {
|
|
|
395
396
|
createTime?: string;
|
|
396
397
|
};
|
|
397
398
|
|
|
398
|
-
function resolvePublishedSdk(): PublishedSdk {
|
|
399
|
+
function resolvePublishedSdk(authEnv: Record<string, string> = {}): PublishedSdk {
|
|
399
400
|
const module = bufModule();
|
|
400
|
-
const result = run("buf", ["registry", "module", "commit", "list", module, "--format", "json", "--page-size", "1"]);
|
|
401
|
+
const result = run("buf", ["registry", "module", "commit", "list", module, "--format", "json", "--page-size", "1"], { env: authEnv });
|
|
401
402
|
const parsed = JSON.parse(result.stdout) as {
|
|
402
403
|
commits?: Array<Record<string, unknown>>;
|
|
403
404
|
commit?: Record<string, unknown>;
|
|
@@ -453,14 +454,23 @@ function bufModule() {
|
|
|
453
454
|
return config.buf.module || `buf.build/anmho/${config.serviceName}`;
|
|
454
455
|
}
|
|
455
456
|
|
|
456
|
-
function
|
|
457
|
+
function ensureBufModule(authEnv: Record<string, string>) {
|
|
458
|
+
const module = bufModule();
|
|
459
|
+
const existing = run("buf", ["registry", "module", "info", module], { env: authEnv, allowFailure: true });
|
|
460
|
+
if (existing.success) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
run("buf", ["registry", "module", "create", module, "--visibility", "private"], { env: authEnv });
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function resolveBufAuthEnv(): Record<string, string> {
|
|
457
467
|
const token =
|
|
458
468
|
process.env.BUF_TOKEN?.trim() ||
|
|
459
469
|
readVaultField(config.buf.vaultMount, config.buf.vaultPath, ["BUF_TOKEN", "buf.api_token", "buf_token", "api_token", "token"]);
|
|
460
470
|
if (!token) {
|
|
461
|
-
return;
|
|
471
|
+
return {};
|
|
462
472
|
}
|
|
463
|
-
|
|
473
|
+
return { BUF_TOKEN: token };
|
|
464
474
|
}
|
|
465
475
|
|
|
466
476
|
async function resolveLocalSdkPath() {
|
|
@@ -47,8 +47,11 @@ test("service sdk publish pushes the named Buf module and selects remote SDK mod
|
|
|
47
47
|
[
|
|
48
48
|
"#!/bin/sh",
|
|
49
49
|
`echo "$@" >> "${bufLog}"`,
|
|
50
|
-
'
|
|
51
|
-
|
|
50
|
+
`printf '%s' "$BUF_TOKEN" > "${tokenLog}"`,
|
|
51
|
+
'if [ "$1 $2 $3 $4" = "registry module info buf.build/anmho/sdk-proof" ]; then',
|
|
52
|
+
" exit 1",
|
|
53
|
+
"fi",
|
|
54
|
+
'if [ "$1 $2 $3 $4" = "registry module create buf.build/anmho/sdk-proof" ] && [ "$5 $6" = "--visibility private" ]; then',
|
|
52
55
|
" exit 0",
|
|
53
56
|
"fi",
|
|
54
57
|
'if [ "$1 $2 $3 $4" = "registry module commit list" ]; then',
|
|
@@ -77,7 +80,12 @@ test("service sdk publish pushes the named Buf module and selects remote SDK mod
|
|
|
77
80
|
expect(result.stdout.toString()).not.toContain("test-token");
|
|
78
81
|
expect(result.stderr.toString()).not.toContain("test-token");
|
|
79
82
|
expect((await readFile(bufLog, "utf8")).trim()).toBe(
|
|
80
|
-
[
|
|
83
|
+
[
|
|
84
|
+
"registry module info buf.build/anmho/sdk-proof",
|
|
85
|
+
"registry module create buf.build/anmho/sdk-proof --visibility private",
|
|
86
|
+
"push",
|
|
87
|
+
"registry module commit list buf.build/anmho/sdk-proof --format json --page-size 1",
|
|
88
|
+
].join("\n")
|
|
81
89
|
);
|
|
82
90
|
expect((await readFile(tokenLog, "utf8")).trim()).toBe("test-token");
|
|
83
91
|
const sdkState = JSON.parse(await Bun.file(join(generatedRoot, ".service", "sdk.json")).text());
|