@mondaydotcomorg/z2h-cli 0.30.0 → 0.31.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/backend/handlers.d.ts +3 -0
- package/dist/backend/handlers.d.ts.map +1 -1
- package/dist/backend/handlers.js +7 -4
- package/dist/backend/parser/__tests__/ast.test.d.ts.map +1 -0
- package/dist/backend/parser/__tests__/parse.test.d.ts.map +1 -0
- package/dist/backend/parser/api-signatures.d.ts +4 -0
- package/dist/backend/parser/api-signatures.d.ts.map +1 -0
- package/dist/backend/parser/api-signatures.js +31 -0
- package/dist/backend/parser/api-usage.d.ts +5 -0
- package/dist/backend/parser/api-usage.d.ts.map +1 -0
- package/dist/backend/parser/api-usage.js +61 -0
- package/dist/backend/parser/bindings.d.ts +5 -0
- package/dist/backend/parser/bindings.d.ts.map +1 -0
- package/dist/backend/parser/bindings.js +84 -0
- package/dist/backend/parser/handler-declaration.d.ts.map +1 -0
- package/dist/backend/parser/member-path.d.ts +3 -0
- package/dist/backend/parser/member-path.d.ts.map +1 -0
- package/dist/backend/parser/member-path.js +31 -0
- package/dist/backend/parser/messages.d.ts.map +1 -0
- package/dist/backend/parser/parse.d.ts.map +1 -0
- package/dist/backend/{parse.js → parser/parse.js} +9 -9
- package/dist/backend/parser/static-value.d.ts +6 -0
- package/dist/backend/parser/static-value.d.ts.map +1 -0
- package/dist/backend/parser/static-value.js +117 -0
- package/dist/backend/parser/types.d.ts +53 -0
- package/dist/backend/parser/types.d.ts.map +1 -0
- package/dist/backend/parser/types.js +1 -0
- package/dist/backend/parser/utils.d.ts +19 -0
- package/dist/backend/parser/utils.d.ts.map +1 -0
- package/dist/backend/parser/utils.js +97 -0
- package/dist/backend/validate.d.ts +3 -3
- package/dist/backend/validate.d.ts.map +1 -1
- package/dist/backend/validate.js +18 -18
- package/dist/commands/backend.d.ts +2 -13
- package/dist/commands/backend.d.ts.map +1 -1
- package/dist/commands/backend.js +30 -21
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +1 -0
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +2 -8
- package/dist/esm/backend/handlers.d.ts +3 -0
- package/dist/esm/backend/handlers.d.ts.map +1 -1
- package/dist/esm/backend/handlers.mjs +7 -4
- package/dist/esm/backend/parser/__tests__/ast.test.d.ts.map +1 -0
- package/dist/esm/backend/parser/__tests__/parse.test.d.ts.map +1 -0
- package/dist/esm/backend/parser/api-signatures.d.ts +4 -0
- package/dist/esm/backend/parser/api-signatures.d.ts.map +1 -0
- package/dist/esm/backend/parser/api-signatures.mjs +24 -0
- package/dist/esm/backend/parser/api-usage.d.ts +5 -0
- package/dist/esm/backend/parser/api-usage.d.ts.map +1 -0
- package/dist/esm/backend/parser/api-usage.mjs +58 -0
- package/dist/esm/backend/parser/bindings.d.ts +5 -0
- package/dist/esm/backend/parser/bindings.d.ts.map +1 -0
- package/dist/esm/backend/parser/bindings.mjs +81 -0
- package/dist/esm/backend/parser/handler-declaration.d.ts.map +1 -0
- package/dist/esm/backend/parser/member-path.d.ts +3 -0
- package/dist/esm/backend/parser/member-path.d.ts.map +1 -0
- package/dist/esm/backend/parser/member-path.mjs +29 -0
- package/dist/esm/backend/parser/messages.d.ts.map +1 -0
- package/dist/esm/backend/parser/parse.d.ts.map +1 -0
- package/dist/esm/backend/{parse.mjs → parser/parse.mjs} +1 -1
- package/dist/esm/backend/parser/static-value.d.ts +6 -0
- package/dist/esm/backend/parser/static-value.d.ts.map +1 -0
- package/dist/esm/backend/parser/static-value.mjs +114 -0
- package/dist/esm/backend/parser/types.d.ts +53 -0
- package/dist/esm/backend/parser/types.d.ts.map +1 -0
- package/dist/esm/backend/parser/types.mjs +1 -0
- package/dist/esm/backend/parser/utils.d.ts +19 -0
- package/dist/esm/backend/parser/utils.d.ts.map +1 -0
- package/dist/esm/backend/parser/utils.mjs +88 -0
- package/dist/esm/backend/validate.d.ts +3 -3
- package/dist/esm/backend/validate.d.ts.map +1 -1
- package/dist/esm/backend/validate.mjs +8 -8
- package/dist/esm/commands/backend.d.ts +2 -13
- package/dist/esm/commands/backend.d.ts.map +1 -1
- package/dist/esm/commands/backend.mjs +31 -22
- package/dist/esm/commands/create.d.ts.map +1 -1
- package/dist/esm/commands/create.mjs +1 -0
- package/dist/esm/commands/deploy.d.ts.map +1 -1
- package/dist/esm/commands/deploy.mjs +3 -8
- package/dist/esm/templates/app/usage.mjs +5 -0
- package/dist/esm/util/machine-identity.d.ts +2 -3
- package/dist/esm/util/machine-identity.d.ts.map +1 -1
- package/dist/esm/util/machine-identity.mjs +7 -4
- package/dist/templates/app/usage.js +7 -0
- package/dist/util/machine-identity.d.ts +2 -3
- package/dist/util/machine-identity.d.ts.map +1 -1
- package/dist/util/machine-identity.js +11 -3
- package/handler-api/signatures.json +26 -0
- package/package.json +1 -1
- package/src/backend/__tests__/handlers.test.ts +13 -2
- package/src/backend/__tests__/validate.test.ts +54 -0
- package/src/backend/handlers.ts +10 -5
- package/src/backend/parser/__tests__/ast.test.ts +252 -0
- package/src/backend/{__tests__ → parser/__tests__}/parse.test.ts +2 -2
- package/src/backend/parser/api-signatures.ts +23 -0
- package/src/backend/parser/api-usage.ts +73 -0
- package/src/backend/parser/bindings.ts +87 -0
- package/src/backend/parser/member-path.ts +31 -0
- package/src/backend/{parse.ts → parser/parse.ts} +1 -1
- package/src/backend/parser/static-value.ts +145 -0
- package/src/backend/parser/types.ts +66 -0
- package/src/backend/parser/utils.ts +106 -0
- package/src/backend/validate.ts +12 -8
- package/src/commands/__tests__/backend-deploy.test.ts +70 -5
- package/src/commands/__tests__/backend-validate.test.ts +11 -1
- package/src/commands/__tests__/create.test.ts +1 -0
- package/src/commands/backend.ts +31 -20
- package/src/commands/create.ts +1 -0
- package/src/commands/deploy.ts +3 -9
- package/src/templates/app/usage.json +1 -0
- package/src/util/machine-identity.ts +7 -3
- package/dist/backend/__tests__/ast.test.d.ts.map +0 -1
- package/dist/backend/__tests__/parse.test.d.ts.map +0 -1
- package/dist/backend/ast.d.ts +0 -39
- package/dist/backend/ast.d.ts.map +0 -1
- package/dist/backend/ast.js +0 -149
- package/dist/backend/handler-declaration.d.ts.map +0 -1
- package/dist/backend/messages.d.ts.map +0 -1
- package/dist/backend/parse.d.ts.map +0 -1
- package/dist/esm/backend/__tests__/ast.test.d.ts.map +0 -1
- package/dist/esm/backend/__tests__/parse.test.d.ts.map +0 -1
- package/dist/esm/backend/ast.d.ts +0 -39
- package/dist/esm/backend/ast.d.ts.map +0 -1
- package/dist/esm/backend/ast.mjs +0 -144
- package/dist/esm/backend/handler-declaration.d.ts.map +0 -1
- package/dist/esm/backend/messages.d.ts.map +0 -1
- package/dist/esm/backend/parse.d.ts.map +0 -1
- package/src/backend/__tests__/ast.test.ts +0 -53
- package/src/backend/ast.ts +0 -201
- /package/dist/backend/{__tests__ → parser/__tests__}/ast.test.d.ts +0 -0
- /package/dist/backend/{__tests__ → parser/__tests__}/parse.test.d.ts +0 -0
- /package/dist/backend/{handler-declaration.d.ts → parser/handler-declaration.d.ts} +0 -0
- /package/dist/backend/{handler-declaration.js → parser/handler-declaration.js} +0 -0
- /package/dist/backend/{messages.d.ts → parser/messages.d.ts} +0 -0
- /package/dist/backend/{messages.js → parser/messages.js} +0 -0
- /package/dist/backend/{parse.d.ts → parser/parse.d.ts} +0 -0
- /package/dist/esm/backend/{__tests__ → parser/__tests__}/ast.test.d.ts +0 -0
- /package/dist/esm/backend/{__tests__ → parser/__tests__}/parse.test.d.ts +0 -0
- /package/dist/esm/backend/{handler-declaration.d.ts → parser/handler-declaration.d.ts} +0 -0
- /package/dist/esm/backend/{handler-declaration.mjs → parser/handler-declaration.mjs} +0 -0
- /package/dist/esm/backend/{messages.d.ts → parser/messages.d.ts} +0 -0
- /package/dist/esm/backend/{messages.mjs → parser/messages.mjs} +0 -0
- /package/dist/esm/backend/{parse.d.ts → parser/parse.d.ts} +0 -0
- /package/src/backend/{handler-declaration.ts → parser/handler-declaration.ts} +0 -0
- /package/src/backend/{messages.ts → parser/messages.ts} +0 -0
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
|
+
import { readJson, writeJson } from 'fs-extra';
|
|
3
4
|
import { PutObjectCommand } from '@aws-sdk/client-s3';
|
|
4
5
|
import { output, info } from '../util/logger.mjs';
|
|
5
|
-
import {
|
|
6
|
+
import { mfAppName, getCwdAppName } from '../util/app-name.mjs';
|
|
7
|
+
import { whoAmI } from '../util/machine-identity.mjs';
|
|
6
8
|
import { readHandlers } from '../backend/handlers.mjs';
|
|
7
9
|
import { detectIntegrations } from '../backend/detect-integrations.mjs';
|
|
8
10
|
import { getS3Client } from '../util/s3/client.mjs';
|
|
@@ -17,30 +19,41 @@ function currentAppName() {
|
|
|
17
19
|
}
|
|
18
20
|
return mfAppName(raw);
|
|
19
21
|
}
|
|
20
|
-
/**
|
|
21
|
-
* True if the app ships an app-level backend — a `backend/handlers/` directory.
|
|
22
|
-
* Callers gate on this so the deploy path is explicit about whether a backend is in
|
|
23
|
-
* play.
|
|
24
|
-
*/
|
|
25
22
|
function hasHandlers(appDir) {
|
|
26
23
|
return existsSync(path.join(appDir, 'backend', 'handlers'));
|
|
27
24
|
}
|
|
25
|
+
/** Other features may add top-level fields, so writes below merge into this copy instead of replacing it. */
|
|
26
|
+
async function readExistingUsage(appDir) {
|
|
27
|
+
try {
|
|
28
|
+
return (await readJson(path.join(appDir, 'usage.json')));
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
if (err.code === 'ENOENT') {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Keeps the app's git-tracked `usage.json` current with every handler parse (validate or deploy). */
|
|
38
|
+
async function writeUsageJson(appDir, patch) {
|
|
39
|
+
const existing = await readExistingUsage(appDir);
|
|
40
|
+
await writeJson(path.join(appDir, 'usage.json'), { ...existing, ...patch }, { spaces: 2 });
|
|
41
|
+
}
|
|
28
42
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* (or it is empty of sources) so callers can always pass the result to
|
|
32
|
-
* `registerOrUpdateApp` without a separate gate.
|
|
43
|
+
* Returns `[]` when there is no `backend/handlers/` dir (or it is empty of sources)
|
|
44
|
+
* so callers can always pass the result to `registerOrUpdateApp` without a separate gate.
|
|
33
45
|
*/
|
|
34
|
-
async function readDetectAndUpload(appDir, prefix, version, deployedBy, logLabel) {
|
|
46
|
+
async function readDetectAndUpload(appDir, prefix, appName, version, deployedBy, logLabel) {
|
|
35
47
|
if (!hasHandlers(appDir)) {
|
|
36
48
|
return [];
|
|
37
49
|
}
|
|
38
50
|
info(`reading backend handlers ${logLabel}`);
|
|
39
|
-
const { handlers, apiDomains } = await readHandlers(appDir);
|
|
51
|
+
const { handlers, apiDomains, apiUsages } = await readHandlers(appDir);
|
|
40
52
|
const integrations = detectIntegrations(apiDomains);
|
|
41
53
|
if (Object.keys(handlers).length === 0) {
|
|
42
54
|
return integrations;
|
|
43
55
|
}
|
|
56
|
+
await writeUsageJson(appDir, { appName, deployedBy, apiUsages });
|
|
44
57
|
const s3 = getS3Client();
|
|
45
58
|
const meta = JSON.stringify({ version, deployedBy, handlers: Object.keys(handlers) });
|
|
46
59
|
const put = (key, body, contentType) => s3.send(new PutObjectCommand({ Bucket: BUCKET_WRITE_NAME, Key: key, Body: body, ContentType: contentType }));
|
|
@@ -55,11 +68,6 @@ async function readDetectAndUpload(appDir, prefix, version, deployedBy, logLabel
|
|
|
55
68
|
* from their sources. Each `.js` handler is uploaded as its own flat file — no
|
|
56
69
|
* compilation, no bundling, no npm deps.
|
|
57
70
|
*
|
|
58
|
-
* Live and preview differ only in where the handlers land, so that is the only
|
|
59
|
-
* thing `isPreview` switches:
|
|
60
|
-
* - live: `<appName>/backend-<version>` — the app's immutable per-version slot.
|
|
61
|
-
* - preview: `<mfKeyPrefix without /MF>/MS` — beside the preview's `/MF` frontend.
|
|
62
|
-
*
|
|
63
71
|
* Integration sync note: the returned set is re-derived from the CURRENT backend
|
|
64
72
|
* sources on every deploy, and the platform set is reconciled to exactly match
|
|
65
73
|
* it (there is no stored declaration to fall back on). A deploy therefore always
|
|
@@ -71,25 +79,26 @@ async function deployBackend(opts) {
|
|
|
71
79
|
const prefix = isPreview ? `${mfKeyPrefix.replace(/\/MF$/, '')}/MS` : `${appName}/backend-${version}`;
|
|
72
80
|
const logLabel = isPreview ? 'for preview' : `for "${appName}"`;
|
|
73
81
|
try {
|
|
74
|
-
return await readDetectAndUpload(appDir, prefix, version, deployedBy, logLabel);
|
|
82
|
+
return await readDetectAndUpload(appDir, prefix, appName, version, deployedBy, logLabel);
|
|
75
83
|
}
|
|
76
84
|
catch (err) {
|
|
77
85
|
throw tagDeployError('deploy_backend_error', err);
|
|
78
86
|
}
|
|
79
87
|
}
|
|
80
88
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* uploading anything. Throws on the first invalid handler.
|
|
89
|
+
* Runs the same checks deploy does against the working tree, refreshing the
|
|
90
|
+
* local `usage.json` — no upload to S3. Throws on the first invalid handler.
|
|
84
91
|
*/
|
|
85
92
|
async function backendValidateCommand(appDir = process.cwd()) {
|
|
86
93
|
if (!hasHandlers(appDir)) {
|
|
87
94
|
output('[z2h-cli] no backend/handlers/ directory — nothing to validate', { handlers: [], integrations: [] });
|
|
88
95
|
return;
|
|
89
96
|
}
|
|
90
|
-
const { handlers, apiDomains } = await readHandlers(appDir);
|
|
97
|
+
const { handlers, apiDomains, apiUsages } = await readHandlers(appDir);
|
|
91
98
|
const names = Object.keys(handlers).sort();
|
|
92
99
|
const integrations = detectIntegrations(apiDomains);
|
|
100
|
+
const { name } = (await readJson(path.join(appDir, 'package.json')));
|
|
101
|
+
await writeUsageJson(appDir, { appName: name ? mfAppName(name) : undefined, deployedBy: whoAmI(), apiUsages });
|
|
93
102
|
const list = (xs) => (xs.length ? xs.join(', ') : 'none');
|
|
94
103
|
output(`[z2h-cli] ${names.length} handler(s) valid: ${list(names)}\n[z2h-cli] integrations: ${list(integrations)}`, {
|
|
95
104
|
handlers: names,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/commands/create.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAE,KAAK,UAAU,EAA2C,MAAM,4BAA4B,CAAC;AAKpH,OAAO,EAAE,YAAY,EAAE,KAAK,UAAU,EAAE,CAAC;AAEzC,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAwBD,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/commands/create.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAE,KAAK,UAAU,EAA2C,MAAM,4BAA4B,CAAC;AAKpH,OAAO,EAAE,YAAY,EAAE,KAAK,UAAU,EAAE,CAAC;AAEzC,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAwBD,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CA8F5F"}
|
|
@@ -85,6 +85,7 @@ async function createCommand(appName, opts = {}) {
|
|
|
85
85
|
await copy(path.join(appTemplatesDir, 'gitignore'), path.join(appDir, '.gitignore'));
|
|
86
86
|
await copy(path.join(appTemplatesDir, 'claude-settings.json'), path.join(appDir, '.claude', 'settings.json'));
|
|
87
87
|
await copy(path.join(appTemplatesDir, 'CLAUDE.md'), path.join(appDir, 'CLAUDE.md'));
|
|
88
|
+
await copy(path.join(appTemplatesDir, 'usage.json'), path.join(appDir, 'usage.json'));
|
|
88
89
|
// html-embed: also copy the source HTML.
|
|
89
90
|
if (template === 'html-embed' && opts.htmlFile) {
|
|
90
91
|
await copy(opts.htmlFile, path.join(appDir, 'src', 'page.html'));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/commands/deploy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/commands/deploy.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,KAAK,UAAU,EAA2C,MAAM,4BAA4B,CAAC;AAatG,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IAIrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAWD,wBAAsB,aAAa,CAAC,IAAI,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyB3E"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import os from 'node:os';
|
|
2
1
|
import path from 'node:path';
|
|
3
2
|
import { readJson, ensureDir, copy } from 'fs-extra';
|
|
4
3
|
import { info, output, getOutputMode, warn } from '../util/logger.mjs';
|
|
@@ -13,7 +12,7 @@ import { getRemoteUrl, initRepo, guardCleanTree, pullAndResolve, pushToRemote }
|
|
|
13
12
|
import { resolveGitEnv } from '../util/git/git-env.mjs';
|
|
14
13
|
import { validateRemoteOptions, resolveRemoteUrl } from '../util/git/remote-options.mjs';
|
|
15
14
|
import { setupS3Client } from '../util/s3/client.mjs';
|
|
16
|
-
import {
|
|
15
|
+
import { whoAmI } from '../util/machine-identity.mjs';
|
|
17
16
|
import { fetchApp, registerOrUpdateApp } from '../util/broker/app.mjs';
|
|
18
17
|
import { openInBrowser } from '../util/open-browser.mjs';
|
|
19
18
|
import { resolvePortAndMetadata } from '../shadow/prepare.mjs';
|
|
@@ -22,10 +21,6 @@ import { deployBackend } from './backend.mjs';
|
|
|
22
21
|
import { buildCommand } from './build.mjs';
|
|
23
22
|
import { promptForTags } from './tag.mjs';
|
|
24
23
|
|
|
25
|
-
/** Who is publishing this version — the machine identity, else the OS user. */
|
|
26
|
-
function whoDeployed() {
|
|
27
|
-
return getMachineAppName() ?? os.userInfo().username;
|
|
28
|
-
}
|
|
29
24
|
// Should be run from the consumer app directory — uses process.cwd() to locate it.
|
|
30
25
|
async function deployCommand(opts = {}) {
|
|
31
26
|
const paths = resolveConsumerPaths(process.cwd());
|
|
@@ -68,7 +63,7 @@ async function buildAndStamp(opts) {
|
|
|
68
63
|
else {
|
|
69
64
|
({ assetManifest } = await buildCommand({ publicUrl: opts.publicUrl }));
|
|
70
65
|
}
|
|
71
|
-
const deployedBy =
|
|
66
|
+
const deployedBy = whoAmI();
|
|
72
67
|
return {
|
|
73
68
|
...assetManifest,
|
|
74
69
|
version: opts.nextVersion,
|
|
@@ -94,7 +89,7 @@ async function uploadAndRegister(opts) {
|
|
|
94
89
|
appName,
|
|
95
90
|
mfKeyPrefix: keyPrefix,
|
|
96
91
|
version: nextVersion,
|
|
97
|
-
deployedBy:
|
|
92
|
+
deployedBy: whoAmI(),
|
|
98
93
|
isPreview,
|
|
99
94
|
});
|
|
100
95
|
await registerOrUpdateApp({
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns the machine app name when running as a service (e.g. agent-runner).
|
|
3
3
|
* Available when the process is a monday.com microservice with `APP_NAME` set
|
|
4
|
-
* by the platform runtime.
|
|
5
|
-
*
|
|
6
|
-
* Returns `undefined` for interactive human users (fallback to os.userInfo).
|
|
4
|
+
* by the platform runtime. Returns `undefined` for interactive human users.
|
|
7
5
|
*/
|
|
8
6
|
export declare function getMachineAppName(): string | undefined;
|
|
7
|
+
export declare function whoAmI(): string;
|
|
9
8
|
//# sourceMappingURL=machine-identity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"machine-identity.d.ts","sourceRoot":"","sources":["../../../src/util/machine-identity.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"machine-identity.d.ts","sourceRoot":"","sources":["../../../src/util/machine-identity.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,GAAG,SAAS,CAEtD;AAED,wBAAgB,MAAM,IAAI,MAAM,CAE/B"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Returns the machine app name when running as a service (e.g. agent-runner).
|
|
3
5
|
* Available when the process is a monday.com microservice with `APP_NAME` set
|
|
4
|
-
* by the platform runtime.
|
|
5
|
-
*
|
|
6
|
-
* Returns `undefined` for interactive human users (fallback to os.userInfo).
|
|
6
|
+
* by the platform runtime. Returns `undefined` for interactive human users.
|
|
7
7
|
*/
|
|
8
8
|
function getMachineAppName() {
|
|
9
9
|
return process.env.APP_NAME || undefined;
|
|
10
10
|
}
|
|
11
|
+
function whoAmI() {
|
|
12
|
+
return getMachineAppName() ?? os.userInfo().username;
|
|
13
|
+
}
|
|
11
14
|
|
|
12
|
-
export { getMachineAppName };
|
|
15
|
+
export { getMachineAppName, whoAmI };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns the machine app name when running as a service (e.g. agent-runner).
|
|
3
3
|
* Available when the process is a monday.com microservice with `APP_NAME` set
|
|
4
|
-
* by the platform runtime.
|
|
5
|
-
*
|
|
6
|
-
* Returns `undefined` for interactive human users (fallback to os.userInfo).
|
|
4
|
+
* by the platform runtime. Returns `undefined` for interactive human users.
|
|
7
5
|
*/
|
|
8
6
|
export declare function getMachineAppName(): string | undefined;
|
|
7
|
+
export declare function whoAmI(): string;
|
|
9
8
|
//# sourceMappingURL=machine-identity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"machine-identity.d.ts","sourceRoot":"","sources":["../../src/util/machine-identity.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"machine-identity.d.ts","sourceRoot":"","sources":["../../src/util/machine-identity.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,GAAG,SAAS,CAEtD;AAED,wBAAgB,MAAM,IAAI,MAAM,CAE/B"}
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
+
const os = require('node:os');
|
|
4
|
+
|
|
5
|
+
const _interopDefault = e => e && e.__esModule ? e : { default: e };
|
|
6
|
+
|
|
7
|
+
const os__default = /*#__PURE__*/_interopDefault(os);
|
|
8
|
+
|
|
3
9
|
/**
|
|
4
10
|
* Returns the machine app name when running as a service (e.g. agent-runner).
|
|
5
11
|
* Available when the process is a monday.com microservice with `APP_NAME` set
|
|
6
|
-
* by the platform runtime.
|
|
7
|
-
*
|
|
8
|
-
* Returns `undefined` for interactive human users (fallback to os.userInfo).
|
|
12
|
+
* by the platform runtime. Returns `undefined` for interactive human users.
|
|
9
13
|
*/
|
|
10
14
|
function getMachineAppName() {
|
|
11
15
|
return process.env.APP_NAME || undefined;
|
|
12
16
|
}
|
|
17
|
+
function whoAmI() {
|
|
18
|
+
return getMachineAppName() ?? os__default.default.userInfo().username;
|
|
19
|
+
}
|
|
13
20
|
|
|
14
21
|
exports.getMachineAppName = getMachineAppName;
|
|
22
|
+
exports.whoAmI = whoAmI;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"db.delete": [
|
|
3
|
+
"key"
|
|
4
|
+
],
|
|
5
|
+
"db.get": [
|
|
6
|
+
"key"
|
|
7
|
+
],
|
|
8
|
+
"db.list": [],
|
|
9
|
+
"db.put": [
|
|
10
|
+
"key",
|
|
11
|
+
"value"
|
|
12
|
+
],
|
|
13
|
+
"llm.complete": [
|
|
14
|
+
"modelId",
|
|
15
|
+
"messages"
|
|
16
|
+
],
|
|
17
|
+
"monday.query": [
|
|
18
|
+
"query",
|
|
19
|
+
"variables"
|
|
20
|
+
],
|
|
21
|
+
"snowflake.query": [
|
|
22
|
+
"sql",
|
|
23
|
+
"params",
|
|
24
|
+
"options"
|
|
25
|
+
]
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -5,6 +5,9 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
5
5
|
|
|
6
6
|
import { readHandlers } from '../handlers';
|
|
7
7
|
|
|
8
|
+
vi.mock('../parser/api-signatures', () => ({
|
|
9
|
+
loadApiSignatures: () => ({ 'monday.query': ['query', 'variables'] }),
|
|
10
|
+
}));
|
|
8
11
|
vi.mock('../../util/tracker', () => ({
|
|
9
12
|
trackEvent: vi.fn().mockResolvedValue(undefined),
|
|
10
13
|
trackDuration: vi.fn(),
|
|
@@ -28,14 +31,14 @@ describe('readHandlers — discovery', () => {
|
|
|
28
31
|
it('returns empty handlers when backend/handlers does not exist', async () => {
|
|
29
32
|
const dir = await mkdtemp(path.join(os.tmpdir(), 'z2h-empty-'));
|
|
30
33
|
try {
|
|
31
|
-
await expect(readHandlers(dir)).resolves.toEqual({ handlers: {}, apiDomains: [] });
|
|
34
|
+
await expect(readHandlers(dir)).resolves.toEqual({ handlers: {}, apiDomains: [], apiUsages: {} });
|
|
32
35
|
} finally {
|
|
33
36
|
await rm(dir, { recursive: true, force: true });
|
|
34
37
|
}
|
|
35
38
|
});
|
|
36
39
|
|
|
37
40
|
it('returns empty handlers when the directory is empty', async () => {
|
|
38
|
-
await expect(readHandlers(appDir)).resolves.toEqual({ handlers: {}, apiDomains: [] });
|
|
41
|
+
await expect(readHandlers(appDir)).resolves.toEqual({ handlers: {}, apiDomains: [], apiUsages: {} });
|
|
39
42
|
});
|
|
40
43
|
|
|
41
44
|
it('uses the filename (without .js) as the handler name', async () => {
|
|
@@ -69,6 +72,14 @@ describe('readHandlers — output contract', () => {
|
|
|
69
72
|
const { apiDomains } = await readHandlers(appDir);
|
|
70
73
|
expect(apiDomains).toEqual(['db', 'monday']);
|
|
71
74
|
});
|
|
75
|
+
|
|
76
|
+
it('attaches per-handler apiUsages keyed by handler name', async () => {
|
|
77
|
+
await writeHandler('a.js', 'async function handler(ctx) { return ctx.api.v1.monday.query("x"); }');
|
|
78
|
+
await writeHandler('c.js', 'async function handler(ctx) { return ctx.input; }');
|
|
79
|
+
const { apiUsages } = await readHandlers(appDir);
|
|
80
|
+
expect(apiUsages.a).toEqual({ monday: { query: [{ query: 'x' }] } });
|
|
81
|
+
expect(apiUsages.c).toEqual({});
|
|
82
|
+
});
|
|
72
83
|
});
|
|
73
84
|
|
|
74
85
|
// Per-shape validation rules are covered in validate.test.ts; here we only prove
|
|
@@ -3,6 +3,12 @@ import { warn } from '../../util/logger';
|
|
|
3
3
|
import { validateHandlerSource } from '../validate';
|
|
4
4
|
|
|
5
5
|
vi.mock('../../util/logger');
|
|
6
|
+
vi.mock('../parser/api-signatures', () => ({
|
|
7
|
+
loadApiSignatures: () => ({
|
|
8
|
+
'snowflake.query': ['sql', 'params', 'options'],
|
|
9
|
+
'monday.query': ['query', 'variables'],
|
|
10
|
+
}),
|
|
11
|
+
}));
|
|
6
12
|
vi.mock('../../util/tracker', () => ({
|
|
7
13
|
trackEvent: vi.fn().mockResolvedValue(undefined),
|
|
8
14
|
trackDuration: vi.fn(),
|
|
@@ -203,3 +209,51 @@ describe('validateHandlerSource — ctx.api.v1 domains', () => {
|
|
|
203
209
|
expect(warnMock).toHaveBeenCalledTimes(1);
|
|
204
210
|
});
|
|
205
211
|
});
|
|
212
|
+
|
|
213
|
+
describe('validateHandlerSource — apiUsages (per-call domain/method/args)', () => {
|
|
214
|
+
it('records each call keyed by parameter name — static strings resolved, dynamic object values kept as source text', () => {
|
|
215
|
+
const { apiUsages } = validate(
|
|
216
|
+
'async function handler(ctx) { return ctx.api.v1.snowflake.query("SELECT 1", { userId: ctx.caller.id }); }'
|
|
217
|
+
);
|
|
218
|
+
expect(apiUsages).toEqual({ snowflake: { query: [{ sql: 'SELECT 1', params: { userId: 'ctx.caller.id' } }] } });
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('keeps multiple calls to the same method as separate entries', () => {
|
|
222
|
+
const { apiUsages } = validate(
|
|
223
|
+
'async function handler(ctx) { await ctx.api.v1.snowflake.query("SELECT 1"); return ctx.api.v1.snowflake.query("SELECT 2"); }'
|
|
224
|
+
);
|
|
225
|
+
expect(apiUsages.snowflake.query).toEqual([{ sql: 'SELECT 1' }, { sql: 'SELECT 2' }]);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('falls back to source text for a dynamic argument and a dynamic array element', () => {
|
|
229
|
+
const { apiUsages } = validate(
|
|
230
|
+
'async function handler(ctx) { const q = ctx.input.q; return ctx.api.v1.monday.query(q, [ctx.input.id]); }'
|
|
231
|
+
);
|
|
232
|
+
expect(apiUsages.monday.query).toEqual([{ query: 'ctx.input.q', variables: ['ctx.input.id'] }]);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('resolves a same-scope const alias back to its ctx.api.v1 chain', () => {
|
|
236
|
+
const { apiUsages } = validate(
|
|
237
|
+
'async function handler(ctx) { const d = ctx.api.v1.snowflake; return d.query("SELECT 1"); }'
|
|
238
|
+
);
|
|
239
|
+
expect(apiUsages).toEqual({ snowflake: { query: [{ sql: 'SELECT 1' }] } });
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('returns {} for a handler with no ctx.api.v1 calls', () => {
|
|
243
|
+
expect(validate('async function handler(ctx) { return ctx.input; }').apiUsages).toEqual({});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('tracks a call reached through a computed string-literal member access', () => {
|
|
247
|
+
const { apiUsages } = validate(
|
|
248
|
+
'async function handler(ctx) { return ctx.api.v1.snowflake[\'query\']("SELECT 1"); }'
|
|
249
|
+
);
|
|
250
|
+
expect(apiUsages).toEqual({ snowflake: { query: [{ sql: 'SELECT 1' }] } });
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('does not track a call reached through a dynamic member access', () => {
|
|
254
|
+
const { apiUsages } = validate(
|
|
255
|
+
'async function handler(ctx) { const m = "query"; return ctx.api.v1.snowflake[m]("SELECT 1"); }'
|
|
256
|
+
);
|
|
257
|
+
expect(apiUsages).toEqual({});
|
|
258
|
+
});
|
|
259
|
+
});
|
package/src/backend/handlers.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { readdir, readFile } from 'node:fs/promises';
|
|
3
3
|
import { pathExists } from 'fs-extra';
|
|
4
|
-
import { validateHandlerSource } from './validate';
|
|
4
|
+
import { validateHandlerSource, type ApiUsage } from './validate';
|
|
5
5
|
|
|
6
6
|
const HANDLERS_DIR = path.join('backend', 'handlers');
|
|
7
7
|
|
|
@@ -10,6 +10,8 @@ export interface ReadHandlersResult {
|
|
|
10
10
|
handlers: Record<string, string>;
|
|
11
11
|
/** Every `ctx.api.v1.<domain>` any handler touches, sorted and unique. */
|
|
12
12
|
apiDomains: string[];
|
|
13
|
+
/** handler name → per-call `ctx.api.v1` usage, for `usage.json`. */
|
|
14
|
+
apiUsages: Record<string, ApiUsage>;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
/**
|
|
@@ -20,7 +22,7 @@ export interface ReadHandlersResult {
|
|
|
20
22
|
export async function readHandlers(consumerDir: string): Promise<ReadHandlersResult> {
|
|
21
23
|
const handlersDir = path.join(consumerDir, HANDLERS_DIR);
|
|
22
24
|
if (!(await pathExists(handlersDir))) {
|
|
23
|
-
return { handlers: {}, apiDomains: [] };
|
|
25
|
+
return { handlers: {}, apiDomains: [], apiUsages: {} };
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
const entries = await readdir(handlersDir);
|
|
@@ -28,13 +30,15 @@ export async function readHandlers(consumerDir: string): Promise<ReadHandlersRes
|
|
|
28
30
|
if (tsFiles.length > 0) {
|
|
29
31
|
throw new Error(`TypeScript handlers are not yet supported (${tsFiles.join(', ')}). Compile to .js first.`);
|
|
30
32
|
}
|
|
31
|
-
|
|
33
|
+
// Sorted so usage.json's key order is deterministic across machines, not readdir()'s.
|
|
34
|
+
const jsFiles = entries.filter(f => f.endsWith('.js')).sort();
|
|
32
35
|
if (jsFiles.length === 0) {
|
|
33
|
-
return { handlers: {}, apiDomains: [] };
|
|
36
|
+
return { handlers: {}, apiDomains: [], apiUsages: {} };
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
const handlers: Record<string, string> = {};
|
|
37
40
|
const apiDomains = new Set<string>();
|
|
41
|
+
const apiUsages: Record<string, ApiUsage> = {};
|
|
38
42
|
for (const file of jsFiles) {
|
|
39
43
|
const handlerName = path.parse(file).name;
|
|
40
44
|
const source = await readFile(path.join(handlersDir, file), 'utf8');
|
|
@@ -42,6 +46,7 @@ export async function readHandlers(consumerDir: string): Promise<ReadHandlersRes
|
|
|
42
46
|
const validation = validateHandlerSource(file, source);
|
|
43
47
|
validation.apiDomains.forEach(d => apiDomains.add(d));
|
|
44
48
|
handlers[handlerName] = source;
|
|
49
|
+
apiUsages[handlerName] = validation.apiUsages;
|
|
45
50
|
}
|
|
46
|
-
return { handlers, apiDomains: [...apiDomains].sort() };
|
|
51
|
+
return { handlers, apiDomains: [...apiDomains].sort(), apiUsages };
|
|
47
52
|
}
|