@beignet/cli 0.0.37 → 0.0.38

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 (70) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +18 -5
  3. package/dist/config.d.ts +1 -1
  4. package/dist/config.d.ts.map +1 -1
  5. package/dist/config.js +1 -1
  6. package/dist/config.js.map +1 -1
  7. package/dist/inspect.js +15 -15
  8. package/dist/inspect.js.map +1 -1
  9. package/dist/lint.d.ts.map +1 -1
  10. package/dist/lint.js +27 -6
  11. package/dist/lint.js.map +1 -1
  12. package/dist/make/inbox.js +7 -7
  13. package/dist/make/inbox.js.map +1 -1
  14. package/dist/make/payments.d.ts +2 -1
  15. package/dist/make/payments.d.ts.map +1 -1
  16. package/dist/make/payments.js +15 -11
  17. package/dist/make/payments.js.map +1 -1
  18. package/dist/make/shared.d.ts +1 -1
  19. package/dist/make/shared.d.ts.map +1 -1
  20. package/dist/make/shared.js +49 -37
  21. package/dist/make/shared.js.map +1 -1
  22. package/dist/make/tenancy.js +8 -8
  23. package/dist/make/tenancy.js.map +1 -1
  24. package/dist/make.d.ts.map +1 -1
  25. package/dist/make.js +27 -16
  26. package/dist/make.js.map +1 -1
  27. package/dist/operational-error-reporting.d.ts +15 -0
  28. package/dist/operational-error-reporting.d.ts.map +1 -0
  29. package/dist/operational-error-reporting.js +42 -0
  30. package/dist/operational-error-reporting.js.map +1 -0
  31. package/dist/outbox.d.ts.map +1 -1
  32. package/dist/outbox.js +73 -0
  33. package/dist/outbox.js.map +1 -1
  34. package/dist/provider-add.js +17 -17
  35. package/dist/provider-add.js.map +1 -1
  36. package/dist/provider-audit.js +3 -3
  37. package/dist/provider-audit.js.map +1 -1
  38. package/dist/schedule.d.ts.map +1 -1
  39. package/dist/schedule.js +28 -1
  40. package/dist/schedule.js.map +1 -1
  41. package/dist/task.d.ts.map +1 -1
  42. package/dist/task.js +37 -4
  43. package/dist/task.js.map +1 -1
  44. package/dist/templates/index.js +2 -2
  45. package/dist/templates/index.js.map +1 -1
  46. package/dist/templates/server.d.ts +1 -1
  47. package/dist/templates/server.d.ts.map +1 -1
  48. package/dist/templates/server.js +5 -5
  49. package/dist/templates/server.js.map +1 -1
  50. package/dist/templates/testing.js +1 -1
  51. package/dist/templates/todos.js +6 -6
  52. package/package.json +4 -4
  53. package/src/config.ts +2 -2
  54. package/src/inspect.ts +15 -17
  55. package/src/lint.ts +35 -4
  56. package/src/make/inbox.ts +7 -7
  57. package/src/make/payments.ts +23 -15
  58. package/src/make/shared.ts +56 -40
  59. package/src/make/tenancy.ts +8 -8
  60. package/src/make.ts +30 -16
  61. package/src/operational-error-reporting.ts +60 -0
  62. package/src/outbox.ts +77 -0
  63. package/src/provider-add.ts +21 -17
  64. package/src/provider-audit.ts +3 -3
  65. package/src/schedule.ts +32 -1
  66. package/src/task.ts +41 -4
  67. package/src/templates/index.ts +2 -2
  68. package/src/templates/server.ts +5 -5
  69. package/src/templates/testing.ts +1 -1
  70. package/src/templates/todos.ts +6 -6
package/src/task.ts CHANGED
@@ -3,6 +3,11 @@ import path from "node:path";
3
3
  import type { TaskDef, TaskRunContextArgs } from "@beignet/core/tasks";
4
4
  import { createJiti } from "jiti";
5
5
  import { loadBeignetConfig, normalizePath } from "./config.js";
6
+ import {
7
+ flushOperationalErrorReporter,
8
+ type OperationalErrorReportingContext,
9
+ reportOperationalFailure,
10
+ } from "./operational-error-reporting.js";
6
11
 
7
12
  /**
8
13
  * Options for running an app-owned operational task.
@@ -63,10 +68,35 @@ export async function runAppTask(
63
68
  : {};
64
69
 
65
70
  try {
66
- const output = await runTask(task, {
67
- input: parsedInput,
68
- ctx,
69
- });
71
+ let output: unknown;
72
+ try {
73
+ output = await runTask(task, {
74
+ input: parsedInput,
75
+ ctx,
76
+ });
77
+ } catch (error) {
78
+ await reportOperationalFailure({
79
+ ctx: toOperationalContext(ctx),
80
+ error,
81
+ reportOptions: {
82
+ level: "error",
83
+ mechanism: "beignet.task.cli",
84
+ handled: false,
85
+ tags: {
86
+ "beignet.kind": "task",
87
+ "beignet.task": task.name,
88
+ },
89
+ contexts: {
90
+ task: {
91
+ name: task.name,
92
+ tenant: options.tenant ?? null,
93
+ source: "beignet-cli",
94
+ },
95
+ },
96
+ },
97
+ });
98
+ throw error;
99
+ }
70
100
 
71
101
  return {
72
102
  schemaVersion: 1,
@@ -79,10 +109,17 @@ export async function runAppTask(
79
109
  durationMs: Math.round(performance.now() - startedAt),
80
110
  };
81
111
  } finally {
112
+ await flushOperationalErrorReporter(toOperationalContext(ctx));
82
113
  await taskModule.stopTaskContext?.(ctx, contextArgs);
83
114
  }
84
115
  }
85
116
 
117
+ function toOperationalContext(ctx: unknown): OperationalErrorReportingContext {
118
+ return typeof ctx === "object" && ctx !== null
119
+ ? (ctx as OperationalErrorReportingContext)
120
+ : {};
121
+ }
122
+
86
123
  function parseTaskInputFlag(input: RunAppTaskOptions["input"]): unknown {
87
124
  if (input === undefined) return {};
88
125
  if (typeof input !== "string") return input;
@@ -19,8 +19,8 @@ import { dbFiles } from "./db/index.js";
19
19
  import {
20
20
  betterAuth,
21
21
  env,
22
- infrastructurePorts,
23
22
  ports,
23
+ portWiring,
24
24
  server,
25
25
  serverFiles,
26
26
  serverProviders,
@@ -109,7 +109,7 @@ export function getTemplateFiles(ctx: TemplateContext): TemplateFile[] {
109
109
  },
110
110
  { path: "ports/index.ts", content: ports(ctx) },
111
111
  { path: "ports/auth.ts", content: serverFiles.authPort },
112
- { path: "infra/app-ports.ts", content: infrastructurePorts(ctx) },
112
+ { path: "infra/port-wiring.ts", content: portWiring(ctx) },
113
113
  { path: "infra/db/client.ts", content: db.dbClient },
114
114
  { path: "infra/db/database-ready.ts", content: db.databaseReady },
115
115
  { path: "infra/db/provider.ts", content: db.dbProvider },
@@ -101,7 +101,7 @@ ${usesResend ? "\tmailer: MailerPort;\n" : ""}${usesUpstash ? "\trateLimit: Rate
101
101
  `;
102
102
  }
103
103
 
104
- export function infrastructurePorts(ctx: TemplateContext): string {
104
+ export function portWiring(ctx: TemplateContext): string {
105
105
  const deferred = [
106
106
  '\t\t"auth",',
107
107
  '\t\t"idempotency",',
@@ -130,13 +130,13 @@ const gate = createGate({
130
130
  });
131
131
 
132
132
  /**
133
- * App ports the server boots with.
133
+ * Initial port values the server boots with.
134
134
  *
135
135
  * Bound ports are app-owned. Every deferred key is contributed by a provider
136
136
  * in server/providers.ts during startup; createNextServer(...) fails boot if
137
137
  * any of them is still unbound after providers have started.
138
138
  */
139
- export const appPorts = definePorts<AppPorts>()({
139
+ export const initialPorts = definePorts<AppPorts>()({
140
140
  bound: {
141
141
  errorReporter: createNoopErrorReporter(),
142
142
  gate,
@@ -290,7 +290,7 @@ import {
290
290
  createSecurityHeadersHooks,
291
291
  } from "@beignet/core/server";
292
292
  import type { AppContext } from "@/app-context";
293
- import { appPorts } from "@/infra/app-ports";
293
+ import { initialPorts } from "@/infra/port-wiring";
294
294
  import { closeDatabaseClient } from "@/infra/db/client";
295
295
  import { env } from "@/lib/env";
296
296
  import { appContext } from "./context";
@@ -300,7 +300,7 @@ export const getServer = createNextServerLoader(async () => {
300
300
  const { providers } = await import("./providers");
301
301
 
302
302
  const server = await createNextServer({
303
- ports: appPorts,
303
+ ports: initialPorts,
304
304
  providers,
305
305
  hooks: [
306
306
  createSecurityHeadersHooks<AppContext>(),
@@ -536,7 +536,7 @@ async function configuredRoots(cwd: string): Promise<string[]> {
536
536
  paths.features,
537
537
  parentPath(paths.routes),
538
538
  parentPath(paths.server),
539
- parentPath(paths.infrastructurePorts),
539
+ parentPath(paths.portWiring),
540
540
  parentPath(paths.ports),
541
541
  parentPath(paths.useCaseBuilder),
542
542
  parentPath(paths.routesBuilder),
@@ -368,7 +368,7 @@ import {
368
368
  import { createInMemoryDevtools } from "@beignet/devtools";
369
369
  import type { AppContext } from "@/app-context";
370
370
  import type { TodoRepository } from "@/features/todos/ports";
371
- import { appPorts } from "@/infra/app-ports";
371
+ import { initialPorts } from "@/infra/port-wiring";
372
372
  import type { AppTransactionPorts } from "@/ports";
373
373
  import {
374
374
  createTodoUseCase,
@@ -388,9 +388,9 @@ function createTester(userId: string, todos: TodoRepository) {
388
388
  session: { id: \`session_\${userId}\` },
389
389
  };
390
390
  const testFixture = createTestPorts<AppContext["ports"], AppTransactionPorts>({
391
- base: appPorts,
391
+ base: initialPorts,
392
392
  overrides: {
393
- gate: appPorts.gate,
393
+ gate: initialPorts.gate,
394
394
  todos,
395
395
  devtools: createInMemoryDevtools(),
396
396
  },
@@ -483,7 +483,7 @@ import { createInMemoryDevtools } from "@beignet/devtools";
483
483
  import { createTestApp, createTestRequester } from "@beignet/web/testing";
484
484
  import type { AppContext } from "@/app-context";
485
485
  import type { TodoRepository } from "@/features/todos/ports";
486
- import { appPorts } from "@/infra/app-ports";
486
+ import { initialPorts } from "@/infra/port-wiring";
487
487
  import type { AppPorts, AppTransactionPorts } from "@/ports";
488
488
  import type { AuthRequest, AuthSessionMetadata, AuthUser } from "@/ports/auth";
489
489
  import { type AppServiceContextInput, appContext } from "@/server/context";
@@ -507,9 +507,9 @@ async function createTodosTestApp(
507
507
  ) {
508
508
  const todos = options.todos ?? createTestTodoRepository();
509
509
  const fixture = createTestPorts<AppContext["ports"], AppTransactionPorts>({
510
- base: appPorts,
510
+ base: initialPorts,
511
511
  overrides: {
512
- gate: appPorts.gate,
512
+ gate: initialPorts.gate,
513
513
  todos,
514
514
  devtools: createInMemoryDevtools(),
515
515
  auth: options.auth ?? createSignedOutAuth(),