@mondaydotcomorg/z2h-cli 0.32.2 → 0.33.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.
Files changed (67) hide show
  1. package/dist/backend/__tests__/format-sandbox-run.test.d.ts +2 -0
  2. package/dist/backend/__tests__/format-sandbox-run.test.d.ts.map +1 -0
  3. package/dist/backend/client.d.ts +32 -2
  4. package/dist/backend/client.d.ts.map +1 -1
  5. package/dist/backend/client.js +8 -5
  6. package/dist/backend/format-sandbox-run.d.ts +4 -0
  7. package/dist/backend/format-sandbox-run.d.ts.map +1 -0
  8. package/dist/backend/format-sandbox-run.js +49 -0
  9. package/dist/commands/__tests__/backend-invoke.test.d.ts +2 -0
  10. package/dist/commands/__tests__/backend-invoke.test.d.ts.map +1 -0
  11. package/dist/commands/__tests__/custom-integrations.test.d.ts +2 -0
  12. package/dist/commands/__tests__/custom-integrations.test.d.ts.map +1 -0
  13. package/dist/commands/backend.d.ts +6 -1
  14. package/dist/commands/backend.d.ts.map +1 -1
  15. package/dist/commands/backend.js +35 -3
  16. package/dist/commands/custom-integrations.d.ts +3 -0
  17. package/dist/commands/custom-integrations.d.ts.map +1 -0
  18. package/dist/commands/custom-integrations.js +51 -0
  19. package/dist/commands/deploy.js +3 -0
  20. package/dist/esm/backend/__tests__/format-sandbox-run.test.d.ts +2 -0
  21. package/dist/esm/backend/__tests__/format-sandbox-run.test.d.ts.map +1 -0
  22. package/dist/esm/backend/client.d.ts +32 -2
  23. package/dist/esm/backend/client.d.ts.map +1 -1
  24. package/dist/esm/backend/client.mjs +8 -5
  25. package/dist/esm/backend/format-sandbox-run.d.ts +4 -0
  26. package/dist/esm/backend/format-sandbox-run.d.ts.map +1 -0
  27. package/dist/esm/backend/format-sandbox-run.mjs +47 -0
  28. package/dist/esm/commands/__tests__/backend-invoke.test.d.ts +2 -0
  29. package/dist/esm/commands/__tests__/backend-invoke.test.d.ts.map +1 -0
  30. package/dist/esm/commands/__tests__/custom-integrations.test.d.ts +2 -0
  31. package/dist/esm/commands/__tests__/custom-integrations.test.d.ts.map +1 -0
  32. package/dist/esm/commands/backend.d.ts +6 -1
  33. package/dist/esm/commands/backend.d.ts.map +1 -1
  34. package/dist/esm/commands/backend.mjs +36 -4
  35. package/dist/esm/commands/custom-integrations.d.ts +3 -0
  36. package/dist/esm/commands/custom-integrations.d.ts.map +1 -0
  37. package/dist/esm/commands/custom-integrations.mjs +48 -0
  38. package/dist/esm/commands/deploy.mjs +3 -0
  39. package/dist/esm/index.mjs +18 -4
  40. package/dist/esm/util/app-name.mjs +1 -1
  41. package/dist/esm/util/broker/app.d.ts +4 -1
  42. package/dist/esm/util/broker/app.d.ts.map +1 -1
  43. package/dist/index.js +18 -4
  44. package/dist/util/app-name.js +1 -1
  45. package/dist/util/broker/app.d.ts +4 -1
  46. package/dist/util/broker/app.d.ts.map +1 -1
  47. package/handler-api/backend-runner/backend-runner.errors.ts +13 -0
  48. package/handler-api/backend-runner/backend-runner.types.ts +3 -0
  49. package/handler-api/backend-runner/channels/channel-map.ts +26 -6
  50. package/handler-api/backend-runner/channels/channel-telemetry.ts +13 -7
  51. package/handler-api/backend-runner/channels/channel-trace.ts +52 -0
  52. package/handler-api/backend-runner/channels/custom-integration-channel/custom-integration.channel.ts +243 -0
  53. package/handler-api/signatures.json +4 -0
  54. package/package.json +2 -2
  55. package/src/backend/__tests__/client.test.ts +17 -13
  56. package/src/backend/__tests__/format-sandbox-run.test.ts +42 -0
  57. package/src/backend/client.ts +27 -10
  58. package/src/backend/format-sandbox-run.ts +51 -0
  59. package/src/commands/__tests__/backend-invoke.test.ts +125 -0
  60. package/src/commands/__tests__/custom-integrations.test.ts +62 -0
  61. package/src/commands/backend.ts +43 -4
  62. package/src/commands/custom-integrations.ts +68 -0
  63. package/src/commands/deploy.ts +3 -0
  64. package/src/index.ts +24 -5
  65. package/src/util/app-name.ts +1 -1
  66. package/src/util/broker/__tests__/app.test.ts +32 -0
  67. package/src/util/broker/app.ts +4 -1
package/src/index.ts CHANGED
@@ -9,6 +9,7 @@ import { cleanCommand } from './commands/clean';
9
9
  import { deployCommand } from './commands/deploy';
10
10
  import { deleteCommand } from './commands/delete';
11
11
  import { grantCommand, revokeCommand, transferOwnerCommand } from './commands/grant';
12
+ import { listCustomIntegrationsCommand, removeCustomIntegrationCommand } from './commands/custom-integrations';
12
13
  import { createWorkspaceCommand } from './commands/create-workspace';
13
14
  import { createCommand, CreateOptions } from './commands/create';
14
15
  import { generateCommand, GenerateOptions } from './commands/generate';
@@ -260,6 +261,16 @@ async function main(): Promise<void> {
260
261
  .description('Transfer ownership of the current app to another monday.com user')
261
262
  .action(runCommand({}, (email: string | undefined) => transferOwnerCommand(email)));
262
263
 
264
+ program
265
+ .command('custom-integration:list')
266
+ .description("List the current app's registered custom integrations (never shows the PAT)")
267
+ .action(runCommand({}, () => listCustomIntegrationsCommand()));
268
+
269
+ program
270
+ .command('custom-integration:remove <name>')
271
+ .description('Remove a registered custom integration from the current app')
272
+ .action(runCommand({}, (name: string) => removeCustomIntegrationCommand(name)));
273
+
263
274
  program
264
275
  .command('delete')
265
276
  .description('Permanently delete the current app and take it offline (owners/admins only)')
@@ -268,7 +279,7 @@ async function main(): Promise<void> {
268
279
 
269
280
  const backend = program
270
281
  .command('backend')
271
- .description("Inspect the app's backend: validate handler sources or invoke a deployed handler by name");
282
+ .description("Inspect the app's backend: validate handler sources or run a handler from the working tree");
272
283
 
273
284
  backend
274
285
  .command('validate')
@@ -280,15 +291,21 @@ async function main(): Promise<void> {
280
291
  backend
281
292
  .command('invoke <handlerName>')
282
293
  .description(
283
- 'Invoke a deployed backend handler by name (the filename without .ts) — mainly for testing a handler without going through the frontend'
294
+ "Run backend/handlers/<handlerName>.js from the working tree — not the deployed handler — against the app's real " +
295
+ 'channels (real db data, real monday calls), and print a trace of every channel call and the ' +
296
+ 'result. Nothing is deployed. Exits 1 when the handler fails.'
297
+ )
298
+ .option('--input <json>', 'JSON passed to the handler as ctx.input (what the frontend would send)')
299
+ .option(
300
+ '--code <source>',
301
+ 'run this source instead of backend/handlers/<handlerName>.js — <handlerName> is then just a label'
284
302
  )
285
- .option('--input <json>', 'JSON payload passed as ctx.input')
286
303
  .action(
287
304
  runCommand(
288
305
  {
289
306
  data: ([handlerName]: [string, unknown]) => ({ app_name: getCwdAppName(), handler: handlerName }),
290
307
  },
291
- (handlerName: string, opts: { input?: string }) => backendInvokeCommand(handlerName, opts)
308
+ (handlerName: string, opts: { input?: string; code?: string }) => backendInvokeCommand(handlerName, opts)
292
309
  )
293
310
  );
294
311
 
@@ -319,7 +336,9 @@ void main()
319
336
  if (getOutputMode() === 'human') {
320
337
  selfUpdate();
321
338
  }
322
- process.exit(0);
339
+ // A command can finish normally and still report a non-zero code (e.g.
340
+ // `backend invoke` when the handler failed) via process.exitCode.
341
+ process.exit(process.exitCode ?? 0);
323
342
  })
324
343
  .catch(async (err: unknown) => {
325
344
  const errorMsg = err instanceof Error ? err.message : String(err);
@@ -29,7 +29,7 @@ export function mfAppName(name: string): string {
29
29
  // Names reserved by the host MF (mf-bigbrain-zth) for platform pages under
30
30
  // /bigbrain-vibe/<name>. Creating an app with one of these would shadow the
31
31
  // platform page in the URL, so we refuse upfront.
32
- const RESERVED_APP_NAMES = new Set(['generate-z2h-token']);
32
+ const RESERVED_APP_NAMES = new Set(['generate-z2h-token', 'set-custom-integration']);
33
33
 
34
34
  /**
35
35
  * Validates a de-scoped, kebab-case app name against every rule shared by
@@ -60,6 +60,38 @@ describe('registerOrUpdateApp', () => {
60
60
  });
61
61
  });
62
62
 
63
+ it('forwards masterAppName on registration only', async () => {
64
+ const fetchMock = mockFetchOnce();
65
+
66
+ await registerOrUpdateApp({
67
+ appName: 'mf-zth-preview-abc-my-app',
68
+ token: 'jwt',
69
+ nextVersion: 1,
70
+ entry: ENTRY,
71
+ gitRemote: '',
72
+ masterAppName: 'mf-my-app',
73
+ });
74
+
75
+ const [, init] = fetchMock.mock.calls[0] as [string, RequestInit];
76
+ expect(JSON.parse(init.body as string)).toMatchObject({ masterAppName: 'mf-my-app' });
77
+ });
78
+
79
+ it('does not send masterAppName on update — the link is immutable after registration', async () => {
80
+ const fetchMock = mockFetchOnce();
81
+
82
+ await registerOrUpdateApp({
83
+ appName: 'mf-zth-preview-abc-my-app',
84
+ token: 'jwt',
85
+ nextVersion: 2,
86
+ entry: ENTRY,
87
+ gitRemote: '',
88
+ masterAppName: 'mf-my-app',
89
+ });
90
+
91
+ const [, init] = fetchMock.mock.calls[0] as [string, RequestInit];
92
+ expect(JSON.parse(init.body as string)).not.toHaveProperty('masterAppName');
93
+ });
94
+
63
95
  it('updates (not registers) when nextVersion > 1, without prompting for visibility', async () => {
64
96
  const fetchMock = mockFetchOnce();
65
97
 
@@ -115,7 +115,10 @@ export interface RegisterOrUpdateOptions {
115
115
  gitRemote: string;
116
116
  integrations?: string[];
117
117
  description?: string;
118
- /** For a preview app's first registration, the real app it previews. Ignored past v1. */
118
+ /**
119
+ * The base app a preview is for, sent only on first registration — the link
120
+ * is set once and is immutable thereafter, so a later update doesn't need it.
121
+ */
119
122
  masterAppName?: string;
120
123
  }
121
124