@mondaydotcomorg/z2h-cli 0.6.0 → 0.6.1
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/commands/create-workspace.d.ts.map +1 -1
- package/dist/commands/create-workspace.js +2 -5
- package/dist/commands/create.js +2 -2
- package/dist/constants.d.ts +18 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +41 -0
- package/dist/esm/commands/create-workspace.d.ts.map +1 -1
- package/dist/esm/commands/create-workspace.mjs +2 -5
- package/dist/esm/commands/create.mjs +2 -2
- package/dist/esm/constants.d.ts +18 -0
- package/dist/esm/constants.d.ts.map +1 -1
- package/dist/esm/constants.mjs +35 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/migrations/003-npm-broker-scope-split.d.ts +14 -0
- package/dist/esm/migrations/003-npm-broker-scope-split.d.ts.map +1 -0
- package/dist/esm/migrations/003-npm-broker-scope-split.mjs +49 -0
- package/dist/esm/migrations/__tests__/003-npm-broker-scope-split.test.d.ts +2 -0
- package/dist/esm/migrations/__tests__/003-npm-broker-scope-split.test.d.ts.map +1 -0
- package/dist/esm/shadow/sync.d.ts.map +1 -1
- package/dist/esm/shadow/sync.mjs +4 -6
- package/dist/esm/util/auth/auth-store.d.ts +10 -0
- package/dist/esm/util/auth/auth-store.d.ts.map +1 -1
- package/dist/esm/util/auth/auth-store.mjs +20 -2
- package/dist/esm/util/auth/broker-credential-provider.d.ts +0 -1
- package/dist/esm/util/auth/broker-credential-provider.d.ts.map +1 -1
- package/dist/esm/util/auth/broker-credential-provider.mjs +2 -5
- package/dist/esm/util/npm/__tests__/broker-config.test.d.ts +2 -0
- package/dist/esm/util/npm/__tests__/broker-config.test.d.ts.map +1 -0
- package/dist/esm/util/npm/__tests__/install.test.d.ts +2 -0
- package/dist/esm/util/npm/__tests__/install.test.d.ts.map +1 -0
- package/dist/esm/util/npm/broker-config.d.ts +20 -0
- package/dist/esm/util/npm/broker-config.d.ts.map +1 -0
- package/dist/esm/util/npm/broker-config.mjs +59 -0
- package/dist/esm/util/npm/ensure-token.d.ts +19 -0
- package/dist/esm/util/npm/ensure-token.d.ts.map +1 -0
- package/dist/esm/util/npm/ensure-token.mjs +22 -0
- package/dist/esm/util/npm/install.d.ts +18 -0
- package/dist/esm/util/npm/install.d.ts.map +1 -0
- package/dist/esm/util/npm/install.mjs +74 -0
- package/dist/index.js +1 -1
- package/dist/migrations/003-npm-broker-scope-split.d.ts +14 -0
- package/dist/migrations/003-npm-broker-scope-split.d.ts.map +1 -0
- package/dist/migrations/003-npm-broker-scope-split.js +51 -0
- package/dist/migrations/__tests__/003-npm-broker-scope-split.test.d.ts +2 -0
- package/dist/migrations/__tests__/003-npm-broker-scope-split.test.d.ts.map +1 -0
- package/dist/shadow/sync.d.ts.map +1 -1
- package/dist/shadow/sync.js +4 -6
- package/dist/util/auth/auth-store.d.ts +10 -0
- package/dist/util/auth/auth-store.d.ts.map +1 -1
- package/dist/util/auth/auth-store.js +19 -0
- package/dist/util/auth/broker-credential-provider.d.ts +0 -1
- package/dist/util/auth/broker-credential-provider.d.ts.map +1 -1
- package/dist/util/auth/broker-credential-provider.js +2 -6
- package/dist/util/npm/__tests__/broker-config.test.d.ts +2 -0
- package/dist/util/npm/__tests__/broker-config.test.d.ts.map +1 -0
- package/dist/util/npm/__tests__/install.test.d.ts +2 -0
- package/dist/util/npm/__tests__/install.test.d.ts.map +1 -0
- package/dist/util/npm/broker-config.d.ts +20 -0
- package/dist/util/npm/broker-config.d.ts.map +1 -0
- package/dist/util/npm/broker-config.js +63 -0
- package/dist/util/npm/ensure-token.d.ts +19 -0
- package/dist/util/npm/ensure-token.d.ts.map +1 -0
- package/dist/util/npm/ensure-token.js +24 -0
- package/dist/util/npm/install.d.ts +18 -0
- package/dist/util/npm/install.d.ts.map +1 -0
- package/dist/util/npm/install.js +76 -0
- package/migrations.json +5 -0
- package/package.json +1 -1
- package/src/commands/__tests__/create-workspace.test.ts +9 -11
- package/src/commands/__tests__/create.test.ts +9 -6
- package/src/commands/create-workspace.ts +2 -5
- package/src/commands/create.ts +2 -2
- package/src/constants.ts +41 -0
- package/src/index.ts +1 -1
- package/src/migrations/003-npm-broker-scope-split.ts +52 -0
- package/src/migrations/__tests__/003-npm-broker-scope-split.test.ts +99 -0
- package/src/shadow/sync.ts +4 -6
- package/src/templates/workspace/npmrc +3 -2
- package/src/templates/workspace/yarnrc.yml +6 -2
- package/src/util/__tests__/workspace-templates-shipped.test.ts +19 -0
- package/src/util/auth/__tests__/broker-credential-provider.test.ts +2 -1
- package/src/util/auth/auth-store.ts +19 -1
- package/src/util/auth/broker-credential-provider.ts +1 -5
- package/src/util/npm/__tests__/broker-config.test.ts +48 -0
- package/src/util/npm/__tests__/install.test.ts +94 -0
- package/src/util/npm/broker-config.ts +63 -0
- package/src/util/npm/ensure-token.ts +28 -0
- package/src/util/npm/install.ts +84 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-workspace.d.ts","sourceRoot":"","sources":["../../src/commands/create-workspace.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"create-workspace.d.ts","sourceRoot":"","sources":["../../src/commands/create-workspace.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CA0CxF"}
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3
3
|
const path = require('node:path');
|
|
4
4
|
const promises = require('node:fs/promises');
|
|
5
5
|
const fsExtra = require('fs-extra');
|
|
6
|
-
const execa = require('execa');
|
|
7
6
|
const util_logger = require('../util/logger.js');
|
|
8
7
|
const util_workspace = require('../util/workspace.js');
|
|
9
8
|
const util_templates = require('../util/templates.js');
|
|
9
|
+
const util_npm_install = require('../util/npm/install.js');
|
|
10
10
|
|
|
11
11
|
const _interopDefault = e => e && e.__esModule ? e : { default: e };
|
|
12
12
|
|
|
@@ -41,10 +41,7 @@ async function createWorkspaceCommand(opts) {
|
|
|
41
41
|
fsExtra.copy(path__default.default.join(wsTemplatesDir, 'yarn-releases', 'yarn-4.5.1.cjs'), path__default.default.join(home, '.yarn', 'releases', 'yarn-4.5.1.cjs')),
|
|
42
42
|
]);
|
|
43
43
|
util_logger.info(`setting up your Z2H workspace — this may take a minute...`);
|
|
44
|
-
await
|
|
45
|
-
cwd: home,
|
|
46
|
-
stdio: 'inherit',
|
|
47
|
-
});
|
|
44
|
+
await util_npm_install.runYarnInstall({ cwd: home });
|
|
48
45
|
util_logger.output(`Your workspace is ready! 🚀 Apps will live at ${home}`, {
|
|
49
46
|
ok: true,
|
|
50
47
|
workspace: home,
|
package/dist/commands/create.js
CHANGED
|
@@ -3,13 +3,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3
3
|
const path = require('node:path');
|
|
4
4
|
const promises = require('node:fs/promises');
|
|
5
5
|
const fsExtra = require('fs-extra');
|
|
6
|
-
const execa = require('execa');
|
|
7
6
|
const util_logger = require('../util/logger.js');
|
|
8
7
|
const util_workspace = require('../util/workspace.js');
|
|
9
8
|
const util_templates = require('../util/templates.js');
|
|
10
9
|
const util_manifest = require('../util/manifest.js');
|
|
11
10
|
const util_appName = require('../util/app-name.js');
|
|
12
11
|
const constants = require('../constants.js');
|
|
12
|
+
const util_npm_install = require('../util/npm/install.js');
|
|
13
13
|
|
|
14
14
|
const _interopDefault = e => e && e.__esModule ? e : { default: e };
|
|
15
15
|
|
|
@@ -96,7 +96,7 @@ async function createCommand(appName, opts) {
|
|
|
96
96
|
await fsExtra.copy(opts.htmlFile, path__default.default.join(appDir, 'src', 'page.html'));
|
|
97
97
|
}
|
|
98
98
|
util_logger.info(`installing dependencies for ${appName}...`);
|
|
99
|
-
await
|
|
99
|
+
await util_npm_install.runYarnInstall({ cwd: workspace });
|
|
100
100
|
util_logger.output(`[z2h-cli] app ready at ${appDir}`, {
|
|
101
101
|
ok: true,
|
|
102
102
|
appDir,
|
package/dist/constants.d.ts
CHANGED
|
@@ -16,4 +16,22 @@ export declare const BUCKET_READ_DNS_URL = "https://bigbrain-zth-mf-assets.bigbr
|
|
|
16
16
|
export declare const MANIFEST_KEY = "mf-assets";
|
|
17
17
|
export declare const MANIFEST_READ_URL = "https://bigbrain-zth-mf-assets.bigbrain.me/mf-assets";
|
|
18
18
|
export declare const APP_NAME_PATTERN: RegExp;
|
|
19
|
+
export declare const DEFAULT_BROKER_BASE_URL = "https://bigbrain-zth.bigbrain.me";
|
|
20
|
+
/**
|
|
21
|
+
* Resolves the broker origin (no trailing slash). Honors
|
|
22
|
+
* `Z2H_BROKER_BASE_URL` (tests/staging), else the prod default. Shared by the
|
|
23
|
+
* STS credential provider and the npm-broker registry URL.
|
|
24
|
+
*/
|
|
25
|
+
export declare function brokerBaseUrl(): string;
|
|
26
|
+
export declare const NPM_BROKER_PATH = "/z2h-cli/npm";
|
|
27
|
+
export declare const BROKER_NPM_SCOPE = "@mondaydotcomorg";
|
|
28
|
+
export declare const PUBLIC_NPM_REGISTRY_URL = "https://registry.npmjs.org/";
|
|
29
|
+
export declare const Z2H_NPM_TOKEN_ENV: "Z2H_NPM_TOKEN";
|
|
30
|
+
/**
|
|
31
|
+
* Broker npm registry URL (no trailing slash), e.g. prod
|
|
32
|
+
* `https://bigbrain-zth.bigbrain.me/z2h-cli/npm`. Built on `brokerBaseUrl()`
|
|
33
|
+
* so the staging override flows through. The trailing-slash forms required by
|
|
34
|
+
* the `.npmrc`/`.yarnrc.yml` configs are added where those files are written.
|
|
35
|
+
*/
|
|
36
|
+
export declare function brokerNpmRegistryUrl(): string;
|
|
19
37
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,eAAO,MAAM,eAAe,SAAS,CAAC;AAGtC,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAGjD,CAAC;AAQF,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAElD,CAAC;AAMF,eAAO,MAAM,QAAQ,QAAQ,CAAC;AAC9B,eAAO,MAAM,QAAQ,QAAQ,CAAC;AAG9B,eAAO,MAAM,iBAAiB,UAAY,CAAC;AAQ3C,eAAO,MAAM,iBAAiB,qCAAqC,CAAC;AACpE,eAAO,MAAM,MAAM,cAAc,CAAC;AAClC,eAAO,MAAM,gBAAgB,wEAA4D,CAAC;AAE1F,eAAO,MAAM,oBAAoB,2BAA2B,CAAC;AAC7D,eAAO,MAAM,mBAAmB,+CAAgD,CAAC;AAKjF,eAAO,MAAM,YAAY,cAAc,CAAC;AACxC,eAAO,MAAM,iBAAiB,yDAA2C,CAAC;AAM1E,eAAO,MAAM,gBAAgB,QAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,eAAO,MAAM,eAAe,SAAS,CAAC;AAGtC,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAGjD,CAAC;AAQF,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAElD,CAAC;AAMF,eAAO,MAAM,QAAQ,QAAQ,CAAC;AAC9B,eAAO,MAAM,QAAQ,QAAQ,CAAC;AAG9B,eAAO,MAAM,iBAAiB,UAAY,CAAC;AAQ3C,eAAO,MAAM,iBAAiB,qCAAqC,CAAC;AACpE,eAAO,MAAM,MAAM,cAAc,CAAC;AAClC,eAAO,MAAM,gBAAgB,wEAA4D,CAAC;AAE1F,eAAO,MAAM,oBAAoB,2BAA2B,CAAC;AAC7D,eAAO,MAAM,mBAAmB,+CAAgD,CAAC;AAKjF,eAAO,MAAM,YAAY,cAAc,CAAC;AACxC,eAAO,MAAM,iBAAiB,yDAA2C,CAAC;AAM1E,eAAO,MAAM,gBAAgB,QAA2B,CAAC;AAKzD,eAAO,MAAM,uBAAuB,qCAAqC,CAAC;AAE1E;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAKD,eAAO,MAAM,eAAe,iBAAiB,CAAC;AAG9C,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAGnD,eAAO,MAAM,uBAAuB,gCAAgC,CAAC;AAMrE,eAAO,MAAM,iBAAiB,EAAG,eAAwB,CAAC;AAE1D;;;;;GAKG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C"}
|
package/dist/constants.js
CHANGED
|
@@ -48,18 +48,59 @@ const MANIFEST_READ_URL = `${BUCKET_READ_DNS_URL}/${MANIFEST_KEY}`;
|
|
|
48
48
|
// backend STS broker rejects anything else with 400; the CLI can validate
|
|
49
49
|
// upfront for friendlier errors.
|
|
50
50
|
const APP_NAME_PATTERN = /^[a-z][a-z0-9-]{1,49}$/;
|
|
51
|
+
// ─────────── Broker origin + npm registry (shared §3 contract) ─────
|
|
52
|
+
// The bigbrain-zth broker fronts both the STS credential route and the npm
|
|
53
|
+
// proxy. `Z2H_BROKER_BASE_URL` overrides the origin for tests/staging.
|
|
54
|
+
const DEFAULT_BROKER_BASE_URL = 'https://bigbrain-zth.bigbrain.me';
|
|
55
|
+
/**
|
|
56
|
+
* Resolves the broker origin (no trailing slash). Honors
|
|
57
|
+
* `Z2H_BROKER_BASE_URL` (tests/staging), else the prod default. Shared by the
|
|
58
|
+
* STS credential provider and the npm-broker registry URL.
|
|
59
|
+
*/
|
|
60
|
+
function brokerBaseUrl() {
|
|
61
|
+
return process.env.Z2H_BROKER_BASE_URL || DEFAULT_BROKER_BASE_URL;
|
|
62
|
+
}
|
|
63
|
+
// The authenticated npm reverse-proxy is mounted here on the broker. Only the
|
|
64
|
+
// `@mondaydotcomorg` scope is served; everything else resolves from npmjs
|
|
65
|
+
// directly. See docs/superpowers/specs/2026-06-03-npm-brokering-design.md §3.
|
|
66
|
+
const NPM_BROKER_PATH = '/z2h-cli/npm';
|
|
67
|
+
// The scope brokered through the proxy — the ONLY scope it serves.
|
|
68
|
+
const BROKER_NPM_SCOPE = '@mondaydotcomorg';
|
|
69
|
+
// Public registry for everything outside the brokered scope (unchanged speed).
|
|
70
|
+
const PUBLIC_NPM_REGISTRY_URL = 'https://registry.npmjs.org/';
|
|
71
|
+
// Env var the client config (`~/.npmrc`, `.yarnrc.yml`) interpolates at
|
|
72
|
+
// invocation time; its value is the z2h JWT, injected per-spawn by the CLI.
|
|
73
|
+
// Deliberately NOT `NPM_TOKEN` — avoids colliding with the monorepo's own dev
|
|
74
|
+
// token and makes clear it is the z2h JWT, not a real npm token.
|
|
75
|
+
const Z2H_NPM_TOKEN_ENV = 'Z2H_NPM_TOKEN';
|
|
76
|
+
/**
|
|
77
|
+
* Broker npm registry URL (no trailing slash), e.g. prod
|
|
78
|
+
* `https://bigbrain-zth.bigbrain.me/z2h-cli/npm`. Built on `brokerBaseUrl()`
|
|
79
|
+
* so the staging override flows through. The trailing-slash forms required by
|
|
80
|
+
* the `.npmrc`/`.yarnrc.yml` configs are added where those files are written.
|
|
81
|
+
*/
|
|
82
|
+
function brokerNpmRegistryUrl() {
|
|
83
|
+
return `${brokerBaseUrl()}${NPM_BROKER_PATH}`;
|
|
84
|
+
}
|
|
51
85
|
|
|
52
86
|
exports.APP_NAME_PATTERN = APP_NAME_PATTERN;
|
|
87
|
+
exports.BROKER_NPM_SCOPE = BROKER_NPM_SCOPE;
|
|
53
88
|
exports.BUCKET_READ_DNS_NAME = BUCKET_READ_DNS_NAME;
|
|
54
89
|
exports.BUCKET_READ_DNS_URL = BUCKET_READ_DNS_URL;
|
|
55
90
|
exports.BUCKET_WRITE_NAME = BUCKET_WRITE_NAME;
|
|
56
91
|
exports.BUCKET_WRITE_URL = BUCKET_WRITE_URL;
|
|
92
|
+
exports.DEFAULT_BROKER_BASE_URL = DEFAULT_BROKER_BASE_URL;
|
|
57
93
|
exports.GITIGNORE_ENTRIES = GITIGNORE_ENTRIES;
|
|
58
94
|
exports.MANIFEST_KEY = MANIFEST_KEY;
|
|
59
95
|
exports.MANIFEST_READ_URL = MANIFEST_READ_URL;
|
|
60
96
|
exports.MAX_PORT = MAX_PORT;
|
|
61
97
|
exports.MIN_PORT = MIN_PORT;
|
|
98
|
+
exports.NPM_BROKER_PATH = NPM_BROKER_PATH;
|
|
99
|
+
exports.PUBLIC_NPM_REGISTRY_URL = PUBLIC_NPM_REGISTRY_URL;
|
|
62
100
|
exports.REGION = REGION;
|
|
63
101
|
exports.SHADOW_DEV_DEPS = SHADOW_DEV_DEPS;
|
|
64
102
|
exports.SHADOW_DIR_NAME = SHADOW_DIR_NAME;
|
|
65
103
|
exports.SHADOW_SCRIPTS = SHADOW_SCRIPTS;
|
|
104
|
+
exports.Z2H_NPM_TOKEN_ENV = Z2H_NPM_TOKEN_ENV;
|
|
105
|
+
exports.brokerBaseUrl = brokerBaseUrl;
|
|
106
|
+
exports.brokerNpmRegistryUrl = brokerNpmRegistryUrl;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-workspace.d.ts","sourceRoot":"","sources":["../../../src/commands/create-workspace.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"create-workspace.d.ts","sourceRoot":"","sources":["../../../src/commands/create-workspace.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CA0CxF"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import { pathExists, readdir, ensureDir, writeFile, copy } from 'fs-extra';
|
|
4
|
-
import { execa } from 'execa';
|
|
5
4
|
import { setOutputMode, info, output } from '../util/logger.mjs';
|
|
6
5
|
import { getWorkspaceHome } from '../util/workspace.mjs';
|
|
7
6
|
import { getTemplatesDir } from '../util/templates.mjs';
|
|
7
|
+
import { runYarnInstall } from '../util/npm/install.mjs';
|
|
8
8
|
|
|
9
9
|
async function createWorkspaceCommand(opts) {
|
|
10
10
|
if (opts.json) {
|
|
@@ -35,10 +35,7 @@ async function createWorkspaceCommand(opts) {
|
|
|
35
35
|
copy(path.join(wsTemplatesDir, 'yarn-releases', 'yarn-4.5.1.cjs'), path.join(home, '.yarn', 'releases', 'yarn-4.5.1.cjs')),
|
|
36
36
|
]);
|
|
37
37
|
info(`setting up your Z2H workspace — this may take a minute...`);
|
|
38
|
-
await
|
|
39
|
-
cwd: home,
|
|
40
|
-
stdio: 'inherit',
|
|
41
|
-
});
|
|
38
|
+
await runYarnInstall({ cwd: home });
|
|
42
39
|
output(`Your workspace is ready! 🚀 Apps will live at ${home}`, {
|
|
43
40
|
ok: true,
|
|
44
41
|
workspace: home,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import { pathExists, ensureDir, writeFile, copy, readdir } from 'fs-extra';
|
|
4
|
-
import { execa } from 'execa';
|
|
5
4
|
import { setOutputMode, info, output } from '../util/logger.mjs';
|
|
6
5
|
import { assertWorkspace } from '../util/workspace.mjs';
|
|
7
6
|
import { APP_TEMPLATES, getTemplatesDir, renderTemplate } from '../util/templates.mjs';
|
|
8
7
|
import { readManifest } from '../util/manifest.mjs';
|
|
9
8
|
import { mfAppName } from '../util/app-name.mjs';
|
|
10
9
|
import { APP_NAME_PATTERN } from '../constants.mjs';
|
|
10
|
+
import { runYarnInstall } from '../util/npm/install.mjs';
|
|
11
11
|
|
|
12
12
|
// Names reserved by the host MF (mf-bigbrain-zth) for platform pages under
|
|
13
13
|
// /bigbrain-vibe/<name>. Creating an app with one of these would shadow the
|
|
@@ -90,7 +90,7 @@ async function createCommand(appName, opts) {
|
|
|
90
90
|
await copy(opts.htmlFile, path.join(appDir, 'src', 'page.html'));
|
|
91
91
|
}
|
|
92
92
|
info(`installing dependencies for ${appName}...`);
|
|
93
|
-
await
|
|
93
|
+
await runYarnInstall({ cwd: workspace });
|
|
94
94
|
output(`[z2h-cli] app ready at ${appDir}`, {
|
|
95
95
|
ok: true,
|
|
96
96
|
appDir,
|
package/dist/esm/constants.d.ts
CHANGED
|
@@ -16,4 +16,22 @@ export declare const BUCKET_READ_DNS_URL = "https://bigbrain-zth-mf-assets.bigbr
|
|
|
16
16
|
export declare const MANIFEST_KEY = "mf-assets";
|
|
17
17
|
export declare const MANIFEST_READ_URL = "https://bigbrain-zth-mf-assets.bigbrain.me/mf-assets";
|
|
18
18
|
export declare const APP_NAME_PATTERN: RegExp;
|
|
19
|
+
export declare const DEFAULT_BROKER_BASE_URL = "https://bigbrain-zth.bigbrain.me";
|
|
20
|
+
/**
|
|
21
|
+
* Resolves the broker origin (no trailing slash). Honors
|
|
22
|
+
* `Z2H_BROKER_BASE_URL` (tests/staging), else the prod default. Shared by the
|
|
23
|
+
* STS credential provider and the npm-broker registry URL.
|
|
24
|
+
*/
|
|
25
|
+
export declare function brokerBaseUrl(): string;
|
|
26
|
+
export declare const NPM_BROKER_PATH = "/z2h-cli/npm";
|
|
27
|
+
export declare const BROKER_NPM_SCOPE = "@mondaydotcomorg";
|
|
28
|
+
export declare const PUBLIC_NPM_REGISTRY_URL = "https://registry.npmjs.org/";
|
|
29
|
+
export declare const Z2H_NPM_TOKEN_ENV: "Z2H_NPM_TOKEN";
|
|
30
|
+
/**
|
|
31
|
+
* Broker npm registry URL (no trailing slash), e.g. prod
|
|
32
|
+
* `https://bigbrain-zth.bigbrain.me/z2h-cli/npm`. Built on `brokerBaseUrl()`
|
|
33
|
+
* so the staging override flows through. The trailing-slash forms required by
|
|
34
|
+
* the `.npmrc`/`.yarnrc.yml` configs are added where those files are written.
|
|
35
|
+
*/
|
|
36
|
+
export declare function brokerNpmRegistryUrl(): string;
|
|
19
37
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,eAAO,MAAM,eAAe,SAAS,CAAC;AAGtC,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAGjD,CAAC;AAQF,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAElD,CAAC;AAMF,eAAO,MAAM,QAAQ,QAAQ,CAAC;AAC9B,eAAO,MAAM,QAAQ,QAAQ,CAAC;AAG9B,eAAO,MAAM,iBAAiB,UAAY,CAAC;AAQ3C,eAAO,MAAM,iBAAiB,qCAAqC,CAAC;AACpE,eAAO,MAAM,MAAM,cAAc,CAAC;AAClC,eAAO,MAAM,gBAAgB,wEAA4D,CAAC;AAE1F,eAAO,MAAM,oBAAoB,2BAA2B,CAAC;AAC7D,eAAO,MAAM,mBAAmB,+CAAgD,CAAC;AAKjF,eAAO,MAAM,YAAY,cAAc,CAAC;AACxC,eAAO,MAAM,iBAAiB,yDAA2C,CAAC;AAM1E,eAAO,MAAM,gBAAgB,QAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,eAAO,MAAM,eAAe,SAAS,CAAC;AAGtC,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAGjD,CAAC;AAQF,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAElD,CAAC;AAMF,eAAO,MAAM,QAAQ,QAAQ,CAAC;AAC9B,eAAO,MAAM,QAAQ,QAAQ,CAAC;AAG9B,eAAO,MAAM,iBAAiB,UAAY,CAAC;AAQ3C,eAAO,MAAM,iBAAiB,qCAAqC,CAAC;AACpE,eAAO,MAAM,MAAM,cAAc,CAAC;AAClC,eAAO,MAAM,gBAAgB,wEAA4D,CAAC;AAE1F,eAAO,MAAM,oBAAoB,2BAA2B,CAAC;AAC7D,eAAO,MAAM,mBAAmB,+CAAgD,CAAC;AAKjF,eAAO,MAAM,YAAY,cAAc,CAAC;AACxC,eAAO,MAAM,iBAAiB,yDAA2C,CAAC;AAM1E,eAAO,MAAM,gBAAgB,QAA2B,CAAC;AAKzD,eAAO,MAAM,uBAAuB,qCAAqC,CAAC;AAE1E;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAKD,eAAO,MAAM,eAAe,iBAAiB,CAAC;AAG9C,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAGnD,eAAO,MAAM,uBAAuB,gCAAgC,CAAC;AAMrE,eAAO,MAAM,iBAAiB,EAAG,eAAwB,CAAC;AAE1D;;;;;GAKG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C"}
|
package/dist/esm/constants.mjs
CHANGED
|
@@ -46,5 +46,39 @@ const MANIFEST_READ_URL = `${BUCKET_READ_DNS_URL}/${MANIFEST_KEY}`;
|
|
|
46
46
|
// backend STS broker rejects anything else with 400; the CLI can validate
|
|
47
47
|
// upfront for friendlier errors.
|
|
48
48
|
const APP_NAME_PATTERN = /^[a-z][a-z0-9-]{1,49}$/;
|
|
49
|
+
// ─────────── Broker origin + npm registry (shared §3 contract) ─────
|
|
50
|
+
// The bigbrain-zth broker fronts both the STS credential route and the npm
|
|
51
|
+
// proxy. `Z2H_BROKER_BASE_URL` overrides the origin for tests/staging.
|
|
52
|
+
const DEFAULT_BROKER_BASE_URL = 'https://bigbrain-zth.bigbrain.me';
|
|
53
|
+
/**
|
|
54
|
+
* Resolves the broker origin (no trailing slash). Honors
|
|
55
|
+
* `Z2H_BROKER_BASE_URL` (tests/staging), else the prod default. Shared by the
|
|
56
|
+
* STS credential provider and the npm-broker registry URL.
|
|
57
|
+
*/
|
|
58
|
+
function brokerBaseUrl() {
|
|
59
|
+
return process.env.Z2H_BROKER_BASE_URL || DEFAULT_BROKER_BASE_URL;
|
|
60
|
+
}
|
|
61
|
+
// The authenticated npm reverse-proxy is mounted here on the broker. Only the
|
|
62
|
+
// `@mondaydotcomorg` scope is served; everything else resolves from npmjs
|
|
63
|
+
// directly. See docs/superpowers/specs/2026-06-03-npm-brokering-design.md §3.
|
|
64
|
+
const NPM_BROKER_PATH = '/z2h-cli/npm';
|
|
65
|
+
// The scope brokered through the proxy — the ONLY scope it serves.
|
|
66
|
+
const BROKER_NPM_SCOPE = '@mondaydotcomorg';
|
|
67
|
+
// Public registry for everything outside the brokered scope (unchanged speed).
|
|
68
|
+
const PUBLIC_NPM_REGISTRY_URL = 'https://registry.npmjs.org/';
|
|
69
|
+
// Env var the client config (`~/.npmrc`, `.yarnrc.yml`) interpolates at
|
|
70
|
+
// invocation time; its value is the z2h JWT, injected per-spawn by the CLI.
|
|
71
|
+
// Deliberately NOT `NPM_TOKEN` — avoids colliding with the monorepo's own dev
|
|
72
|
+
// token and makes clear it is the z2h JWT, not a real npm token.
|
|
73
|
+
const Z2H_NPM_TOKEN_ENV = 'Z2H_NPM_TOKEN';
|
|
74
|
+
/**
|
|
75
|
+
* Broker npm registry URL (no trailing slash), e.g. prod
|
|
76
|
+
* `https://bigbrain-zth.bigbrain.me/z2h-cli/npm`. Built on `brokerBaseUrl()`
|
|
77
|
+
* so the staging override flows through. The trailing-slash forms required by
|
|
78
|
+
* the `.npmrc`/`.yarnrc.yml` configs are added where those files are written.
|
|
79
|
+
*/
|
|
80
|
+
function brokerNpmRegistryUrl() {
|
|
81
|
+
return `${brokerBaseUrl()}${NPM_BROKER_PATH}`;
|
|
82
|
+
}
|
|
49
83
|
|
|
50
|
-
export { APP_NAME_PATTERN, BUCKET_READ_DNS_NAME, BUCKET_READ_DNS_URL, BUCKET_WRITE_NAME, BUCKET_WRITE_URL, GITIGNORE_ENTRIES, MANIFEST_KEY, MANIFEST_READ_URL, MAX_PORT, MIN_PORT, REGION, SHADOW_DEV_DEPS, SHADOW_DIR_NAME, SHADOW_SCRIPTS };
|
|
84
|
+
export { APP_NAME_PATTERN, BROKER_NPM_SCOPE, BUCKET_READ_DNS_NAME, BUCKET_READ_DNS_URL, BUCKET_WRITE_NAME, BUCKET_WRITE_URL, DEFAULT_BROKER_BASE_URL, GITIGNORE_ENTRIES, MANIFEST_KEY, MANIFEST_READ_URL, MAX_PORT, MIN_PORT, NPM_BROKER_PATH, PUBLIC_NPM_REGISTRY_URL, REGION, SHADOW_DEV_DEPS, SHADOW_DIR_NAME, SHADOW_SCRIPTS, Z2H_NPM_TOKEN_ENV, brokerBaseUrl, brokerNpmRegistryUrl };
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
-
import { Command } from 'commander';
|
|
3
2
|
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { Command } from 'commander';
|
|
4
4
|
import { devCommand } from './commands/dev.mjs';
|
|
5
5
|
import { buildCommand } from './commands/build.mjs';
|
|
6
6
|
import { cleanCommand } from './commands/clean.mjs';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Tree } from '@nx/devkit';
|
|
2
|
+
/**
|
|
3
|
+
* Migrate the workspace npm/yarn config from the legacy single-registry
|
|
4
|
+
* `${NPM_TOKEN}` form to the `@mondaydotcomorg`→broker scope-split
|
|
5
|
+
* (`${Z2H_NPM_TOKEN}` placeholder). Rewrites the workspace-root `.yarnrc.yml`
|
|
6
|
+
* and `.npmrc`, plus any consumer-app copies that still carry the legacy
|
|
7
|
+
* placeholder (migration 001 normally removes per-consumer `.yarnrc.yml`, so
|
|
8
|
+
* this is just defensive cleanup).
|
|
9
|
+
*
|
|
10
|
+
* The global `~/.npmrc` broker block is written separately by `migrateCommand`
|
|
11
|
+
* (it lives outside the workspace Tree).
|
|
12
|
+
*/
|
|
13
|
+
export default function npmBrokerScopeSplit(tree: Tree): void;
|
|
14
|
+
//# sourceMappingURL=003-npm-broker-scope-split.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"003-npm-broker-scope-split.d.ts","sourceRoot":"","sources":["../../../src/migrations/003-npm-broker-scope-split.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAuBvC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAgB5D"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { workspaceYarnrcContents, workspaceNpmrcContents } from '../util/npm/broker-config.mjs';
|
|
2
|
+
|
|
3
|
+
// Legacy marker: the old configs interpolated a real npm token via
|
|
4
|
+
// `${NPM_TOKEN}`. Its presence means the file predates npm brokering and must
|
|
5
|
+
// be rewritten to the scope-split. Once rewritten (placeholder is now
|
|
6
|
+
// `${Z2H_NPM_TOKEN}`) this no longer matches, so the migration is idempotent.
|
|
7
|
+
const LEGACY_TOKEN_PLACEHOLDER = '${NPM_TOKEN}';
|
|
8
|
+
/**
|
|
9
|
+
* Rewrite a single rc file to `contents` iff it exists and still carries the
|
|
10
|
+
* legacy `${NPM_TOKEN}` placeholder. Returns nothing; mutates the Tree.
|
|
11
|
+
*/
|
|
12
|
+
function rewriteIfLegacy(tree, filePath, contents) {
|
|
13
|
+
if (!tree.exists(filePath)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const current = tree.read(filePath, 'utf-8') ?? '';
|
|
17
|
+
if (!current.includes(LEGACY_TOKEN_PLACEHOLDER)) {
|
|
18
|
+
return; // already migrated (or never legacy) — leave untouched
|
|
19
|
+
}
|
|
20
|
+
tree.write(filePath, contents);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Migrate the workspace npm/yarn config from the legacy single-registry
|
|
24
|
+
* `${NPM_TOKEN}` form to the `@mondaydotcomorg`→broker scope-split
|
|
25
|
+
* (`${Z2H_NPM_TOKEN}` placeholder). Rewrites the workspace-root `.yarnrc.yml`
|
|
26
|
+
* and `.npmrc`, plus any consumer-app copies that still carry the legacy
|
|
27
|
+
* placeholder (migration 001 normally removes per-consumer `.yarnrc.yml`, so
|
|
28
|
+
* this is just defensive cleanup).
|
|
29
|
+
*
|
|
30
|
+
* The global `~/.npmrc` broker block is written separately by `migrateCommand`
|
|
31
|
+
* (it lives outside the workspace Tree).
|
|
32
|
+
*/
|
|
33
|
+
function npmBrokerScopeSplit(tree) {
|
|
34
|
+
const yarnrc = workspaceYarnrcContents();
|
|
35
|
+
const npmrc = workspaceNpmrcContents();
|
|
36
|
+
// Workspace root.
|
|
37
|
+
rewriteIfLegacy(tree, '.yarnrc.yml', yarnrc);
|
|
38
|
+
rewriteIfLegacy(tree, '.npmrc', npmrc);
|
|
39
|
+
// Any consumer apps that still carry their own legacy rc files.
|
|
40
|
+
for (const entry of tree.children('.')) {
|
|
41
|
+
if (entry.startsWith('.')) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
rewriteIfLegacy(tree, `${entry}/.yarnrc.yml`, yarnrc);
|
|
45
|
+
rewriteIfLegacy(tree, `${entry}/.npmrc`, npmrc);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { npmBrokerScopeSplit as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"003-npm-broker-scope-split.test.d.ts","sourceRoot":"","sources":["../../../../src/migrations/__tests__/003-npm-broker-scope-split.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../../src/shadow/sync.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE3D;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../../src/shadow/sync.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE3D;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAe9F"}
|
package/dist/esm/shadow/sync.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { pathExists, readFile, writeFile } from 'fs-extra';
|
|
2
|
-
import { execa } from 'execa';
|
|
3
2
|
import { info } from '../util/logger.mjs';
|
|
3
|
+
import { runYarnInstall } from '../util/npm/install.mjs';
|
|
4
4
|
import { buildShadowPkg, writeShadowPkg, hashConsumerDeps } from './merge-package-json.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -17,11 +17,9 @@ async function syncShadow(paths, consumerPkg) {
|
|
|
17
17
|
if (oldHash !== newHash) {
|
|
18
18
|
info(oldHash ? 'consumer deps changed — yarn install' : 'first run — yarn install');
|
|
19
19
|
// Yarn 4 is cache-first and non-interactive by default in non-TTY
|
|
20
|
-
// contexts, so plain `yarn install` is all we need.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
stdio: 'inherit',
|
|
24
|
-
});
|
|
20
|
+
// contexts, so plain `yarn install` is all we need. runYarnInstall injects
|
|
21
|
+
// the npm-broker token, preflights auth, and re-auths on a broker 401.
|
|
22
|
+
await runYarnInstall({ cwd: paths.consumerDir });
|
|
25
23
|
await writeFile(paths.shadowDepsHash, newHash);
|
|
26
24
|
}
|
|
27
25
|
}
|
|
@@ -8,4 +8,14 @@ export declare class Z2hAuthMissingError extends Error {
|
|
|
8
8
|
constructor(authFilePath: string);
|
|
9
9
|
}
|
|
10
10
|
export declare function readZthAuth(): Promise<ZthAuth>;
|
|
11
|
+
/**
|
|
12
|
+
* Synchronous, never-throws read of the z2h JWT from `~/.zth/auth.json`.
|
|
13
|
+
* Returns the token string, or `null` when the file is absent, unreadable,
|
|
14
|
+
* malformed, or missing the `token` field.
|
|
15
|
+
*
|
|
16
|
+
* Used when building the env for a spawned package-manager process, where a
|
|
17
|
+
* missing token must degrade gracefully (best-effort self-update) rather than
|
|
18
|
+
* blow up — and where an inline sync read keeps the spawn call site simple.
|
|
19
|
+
*/
|
|
20
|
+
export declare function tryReadAuthTokenSync(): string | null;
|
|
11
21
|
//# sourceMappingURL=auth-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-store.d.ts","sourceRoot":"","sources":["../../../../src/util/auth/auth-store.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,QAAkC,CAAC;AAC5D,eAAO,MAAM,aAAa,QAAuC,CAAC;AAElE,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,mBAAoB,SAAQ,KAAK;aAChB,YAAY,EAAE,MAAM;gBAApB,YAAY,EAAE,MAAM;CAIjD;AAED,wBAAsB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CASpD"}
|
|
1
|
+
{"version":3,"file":"auth-store.d.ts","sourceRoot":"","sources":["../../../../src/util/auth/auth-store.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,QAAkC,CAAC;AAC5D,eAAO,MAAM,aAAa,QAAuC,CAAC;AAElE,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,mBAAoB,SAAQ,KAAK;aAChB,YAAY,EAAE,MAAM;gBAApB,YAAY,EAAE,MAAM;CAIjD;AAED,wBAAsB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CASpD;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,GAAG,IAAI,CAOpD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import os from 'node:os';
|
|
3
|
-
import { pathExists, readJson } from 'fs-extra';
|
|
3
|
+
import { pathExists, readJson, readJsonSync } from 'fs-extra';
|
|
4
4
|
|
|
5
5
|
// npm-style convention: per-user config under ~/.zth (mirrors ~/.npmrc, ~/.aws/).
|
|
6
6
|
// Kept out of the workspace dir so accidental `git init` in ~/zth-projects can't
|
|
@@ -25,5 +25,23 @@ async function readZthAuth() {
|
|
|
25
25
|
}
|
|
26
26
|
return { token: parsed.token };
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Synchronous, never-throws read of the z2h JWT from `~/.zth/auth.json`.
|
|
30
|
+
* Returns the token string, or `null` when the file is absent, unreadable,
|
|
31
|
+
* malformed, or missing the `token` field.
|
|
32
|
+
*
|
|
33
|
+
* Used when building the env for a spawned package-manager process, where a
|
|
34
|
+
* missing token must degrade gracefully (best-effort self-update) rather than
|
|
35
|
+
* blow up — and where an inline sync read keeps the spawn call site simple.
|
|
36
|
+
*/
|
|
37
|
+
function tryReadAuthTokenSync() {
|
|
38
|
+
try {
|
|
39
|
+
const parsed = readJsonSync(Z2H_AUTH_FILE);
|
|
40
|
+
return parsed?.token ?? null;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
28
46
|
|
|
29
|
-
export { Z2H_AUTH_DIR, Z2H_AUTH_FILE, Z2hAuthMissingError, readZthAuth };
|
|
47
|
+
export { Z2H_AUTH_DIR, Z2H_AUTH_FILE, Z2hAuthMissingError, readZthAuth, tryReadAuthTokenSync };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AwsCredentialIdentityProvider } from '@aws-sdk/types';
|
|
2
|
-
export declare const DEFAULT_BROKER_BASE_URL = "https://bigbrain-zth.bigbrain.me";
|
|
3
2
|
export declare const STS_BROKER_PATH = "/z2h-cli/sts/credentials";
|
|
4
3
|
/**
|
|
5
4
|
* AWS SDK credential provider that fetches short-lived deploy credentials
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"broker-credential-provider.d.ts","sourceRoot":"","sources":["../../../../src/util/auth/broker-credential-provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"broker-credential-provider.d.ts","sourceRoot":"","sources":["../../../../src/util/auth/broker-credential-provider.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAyB,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAE3F,eAAO,MAAM,eAAe,6BAA6B,CAAC;AAwD1D;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,6BAA6B,CAuBxG"}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
+
import { brokerBaseUrl } from '../../constants.mjs';
|
|
1
2
|
import { readZthAuth } from './auth-store.mjs';
|
|
2
3
|
|
|
3
|
-
const DEFAULT_BROKER_BASE_URL = 'https://bigbrain-zth.bigbrain.me';
|
|
4
4
|
const STS_BROKER_PATH = '/z2h-cli/sts/credentials';
|
|
5
5
|
// Refresh the cached credentials this many ms before they expire so the next
|
|
6
6
|
// AWS API call doesn't race the broker round-trip against a hard expiry.
|
|
7
7
|
const REFRESH_BUFFER_MS = 5 * 60 * 1000;
|
|
8
|
-
function brokerBaseUrl() {
|
|
9
|
-
return process.env.Z2H_BROKER_BASE_URL || DEFAULT_BROKER_BASE_URL;
|
|
10
|
-
}
|
|
11
8
|
async function fetchCredentialsOnce(appName) {
|
|
12
9
|
const { token } = await readZthAuth();
|
|
13
10
|
const url = `${brokerBaseUrl()}${STS_BROKER_PATH}`;
|
|
@@ -73,4 +70,4 @@ function brokerCredentialProvider({ appName }) {
|
|
|
73
70
|
};
|
|
74
71
|
}
|
|
75
72
|
|
|
76
|
-
export {
|
|
73
|
+
export { STS_BROKER_PATH, brokerCredentialProvider };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broker-config.test.d.ts","sourceRoot":"","sources":["../../../../../src/util/npm/__tests__/broker-config.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.test.d.ts","sourceRoot":"","sources":["../../../../../src/util/npm/__tests__/install.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two npm config lines (§3.1 / §3.3) that route the brokered scope to the
|
|
3
|
+
* proxy and supply the `${Z2H_NPM_TOKEN}` placeholder. No literal token — npm
|
|
4
|
+
* interpolates the placeholder from the env at invocation time.
|
|
5
|
+
*/
|
|
6
|
+
export declare function brokerNpmrcLines(): string[];
|
|
7
|
+
/**
|
|
8
|
+
* Full contents for a **workspace** `.npmrc` (§3.3): broker scope-split plus an
|
|
9
|
+
* explicit public default registry and always-auth. Used by the template and
|
|
10
|
+
* the migration so both stay byte-identical.
|
|
11
|
+
*/
|
|
12
|
+
export declare function workspaceNpmrcContents(): string;
|
|
13
|
+
/**
|
|
14
|
+
* Full contents for a **workspace** `.yarnrc.yml` (§3.2): the brokered scope
|
|
15
|
+
* points at the proxy with the `${Z2H_NPM_TOKEN}` placeholder + always-auth;
|
|
16
|
+
* the default `npmRegistryServer` stays the public registry (direct, unchanged
|
|
17
|
+
* speed). `yarnPath` keeps the bundled Berry release so any `yarn` runs 4.x.
|
|
18
|
+
*/
|
|
19
|
+
export declare function workspaceYarnrcContents(): string;
|
|
20
|
+
//# sourceMappingURL=broker-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broker-config.d.ts","sourceRoot":"","sources":["../../../../src/util/npm/broker-config.ts"],"names":[],"mappings":"AAkBA;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,EAAE,CAK3C;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,CAE/C;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAiBhD"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { BROKER_NPM_SCOPE, Z2H_NPM_TOKEN_ENV, PUBLIC_NPM_REGISTRY_URL, brokerNpmRegistryUrl } from '../../constants.mjs';
|
|
2
|
+
|
|
3
|
+
/** `https://host/path/` (with trailing slash) for the registry= line. */
|
|
4
|
+
function registryUrlWithSlash() {
|
|
5
|
+
const url = brokerNpmRegistryUrl();
|
|
6
|
+
return url.endsWith('/') ? url : `${url}/`;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The `//host/path/` prefix (scheme stripped, trailing slash kept) that npm
|
|
10
|
+
* requires the `:_authToken` key to be keyed under so it aligns with the
|
|
11
|
+
* registry path. Derived from the same registry URL so staging overrides flow
|
|
12
|
+
* through.
|
|
13
|
+
*/
|
|
14
|
+
function authKeyPrefix() {
|
|
15
|
+
return registryUrlWithSlash().replace(/^https?:/, '');
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The two npm config lines (§3.1 / §3.3) that route the brokered scope to the
|
|
19
|
+
* proxy and supply the `${Z2H_NPM_TOKEN}` placeholder. No literal token — npm
|
|
20
|
+
* interpolates the placeholder from the env at invocation time.
|
|
21
|
+
*/
|
|
22
|
+
function brokerNpmrcLines() {
|
|
23
|
+
return [
|
|
24
|
+
`${BROKER_NPM_SCOPE}:registry=${registryUrlWithSlash()}`,
|
|
25
|
+
`${authKeyPrefix()}:_authToken=\${${Z2H_NPM_TOKEN_ENV}}`,
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Full contents for a **workspace** `.npmrc` (§3.3): broker scope-split plus an
|
|
30
|
+
* explicit public default registry and always-auth. Used by the template and
|
|
31
|
+
* the migration so both stay byte-identical.
|
|
32
|
+
*/
|
|
33
|
+
function workspaceNpmrcContents() {
|
|
34
|
+
return [...brokerNpmrcLines(), `registry=${PUBLIC_NPM_REGISTRY_URL}`, 'always-auth=true'].join('\n') + '\n';
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Full contents for a **workspace** `.yarnrc.yml` (§3.2): the brokered scope
|
|
38
|
+
* points at the proxy with the `${Z2H_NPM_TOKEN}` placeholder + always-auth;
|
|
39
|
+
* the default `npmRegistryServer` stays the public registry (direct, unchanged
|
|
40
|
+
* speed). `yarnPath` keeps the bundled Berry release so any `yarn` runs 4.x.
|
|
41
|
+
*/
|
|
42
|
+
function workspaceYarnrcContents() {
|
|
43
|
+
const scopeKey = BROKER_NPM_SCOPE.replace(/^@/, '');
|
|
44
|
+
return ([
|
|
45
|
+
'nodeLinker: node-modules',
|
|
46
|
+
'',
|
|
47
|
+
'npmScopes:',
|
|
48
|
+
` ${scopeKey}:`,
|
|
49
|
+
` npmRegistryServer: "${brokerNpmRegistryUrl()}"`,
|
|
50
|
+
` npmAuthToken: "\${${Z2H_NPM_TOKEN_ENV}}"`,
|
|
51
|
+
' npmAlwaysAuth: true',
|
|
52
|
+
'',
|
|
53
|
+
`npmRegistryServer: "${PUBLIC_NPM_REGISTRY_URL}"`,
|
|
54
|
+
'',
|
|
55
|
+
'yarnPath: .yarn/releases/yarn-4.5.1.cjs',
|
|
56
|
+
].join('\n') + '\n');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { brokerNpmrcLines, workspaceNpmrcContents, workspaceYarnrcContents };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface EnsureZ2hTokenOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Re-run the token flow even if a token already exists on disk. Used after a
|
|
4
|
+
* broker 401, where the stored token is present but expired/invalid.
|
|
5
|
+
*/
|
|
6
|
+
forceRefresh?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Ensure a z2h JWT exists at `~/.zth/auth.json` before an install-bearing
|
|
10
|
+
* command runs. If none is present (or `forceRefresh` is set), drive the
|
|
11
|
+
* existing `generate-z2h-token` flow — loopback capture with manual-paste
|
|
12
|
+
* fallback — which writes the token. No-ops when a token already exists and no
|
|
13
|
+
* refresh was requested.
|
|
14
|
+
*
|
|
15
|
+
* This is the install preflight: it keeps a friendly auth prompt in front of
|
|
16
|
+
* the raw npm error a non-technical user would otherwise hit.
|
|
17
|
+
*/
|
|
18
|
+
export declare function ensureZ2hToken(opts?: EnsureZ2hTokenOptions): Promise<void>;
|
|
19
|
+
//# sourceMappingURL=ensure-token.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensure-token.d.ts","sourceRoot":"","sources":["../../../../src/util/npm/ensure-token.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;;;;;;;GASG;AACH,wBAAsB,cAAc,CAAC,IAAI,GAAE,qBAA0B,GAAG,OAAO,CAAC,IAAI,CAAC,CAKpF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { tryReadAuthTokenSync } from '../auth/auth-store.mjs';
|
|
2
|
+
import { info } from '../logger.mjs';
|
|
3
|
+
import { generateZ2HTokenCommand } from '../../commands/generate-z2h-token.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Ensure a z2h JWT exists at `~/.zth/auth.json` before an install-bearing
|
|
7
|
+
* command runs. If none is present (or `forceRefresh` is set), drive the
|
|
8
|
+
* existing `generate-z2h-token` flow — loopback capture with manual-paste
|
|
9
|
+
* fallback — which writes the token. No-ops when a token already exists and no
|
|
10
|
+
* refresh was requested.
|
|
11
|
+
*
|
|
12
|
+
* This is the install preflight: it keeps a friendly auth prompt in front of
|
|
13
|
+
* the raw npm error a non-technical user would otherwise hit.
|
|
14
|
+
*/
|
|
15
|
+
async function ensureZ2hToken(opts = {}) {
|
|
16
|
+
if (opts.forceRefresh || !tryReadAuthTokenSync()) {
|
|
17
|
+
info('you need to sign in to install monday packages — opening the sign-in page');
|
|
18
|
+
await generateZ2HTokenCommand();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { ensureZ2hToken };
|