@tribe-nest/forge 1.18.0 → 1.19.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/server/jobs.ts +33 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tribe-nest/forge",
3
- "version": "1.18.0",
3
+ "version": "1.19.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -14,8 +14,21 @@ export interface AppJobsEnv {
14
14
  }
15
15
 
16
16
  interface AppJobsStub {
17
- reconcile: (script: string, appId: string, desired: JobSchedule[], hash: string) => Promise<{ changed: boolean }>;
18
- enqueue: (script: string, appId: string, name: string, payload: unknown, delayMs: number) => Promise<void>;
17
+ reconcile: (
18
+ script: string,
19
+ appId: string,
20
+ desired: JobSchedule[],
21
+ hash: string,
22
+ host: string,
23
+ ) => Promise<{ changed: boolean }>;
24
+ enqueue: (
25
+ script: string,
26
+ appId: string,
27
+ name: string,
28
+ payload: unknown,
29
+ delayMs: number,
30
+ host: string,
31
+ ) => Promise<void>;
19
32
  status: () => Promise<AppJobsStatus>;
20
33
  }
21
34
 
@@ -24,12 +37,18 @@ interface AppJobsStub {
24
37
  * and what happened on the LAST delivery attempt. Because jobs fail silently (no
25
38
  * logs / dead-letter), this is how you SEE why one didn't run:
26
39
  * - `lastDispatchAt` null while `alarmAt` is in the past → the alarm isn't firing;
27
- * - `lastError` starting "dispatch threw:" the callback never reached your app;
40
+ * - `appHost` null this app predates host registration; redeploy it;
41
+ * - `lastError` starting "dispatch threw:" → the callback never reached your app
42
+ * (host unroutable / your Worker is down);
28
43
  * - `lastDispatchStatus` "401" → your app was reached but rejected the token
29
- * (the dispatch-worker's APP_SYNC_SECRET ≠ the backend JWT_SECRET).
44
+ * (the dispatch-worker's APP_SYNC_SECRET ≠ the backend JWT_SECRET);
45
+ * - `lastDispatchStatus` "402" → the site is suspended for billing;
46
+ * - `lastDispatchStatus` "404" → no /api/tn-jobs/run route (or an unknown job name).
30
47
  */
31
48
  export interface AppJobsStatus {
32
49
  appId: string | null;
50
+ /** The public host job runs are posted to. Null on apps deployed before this existed. */
51
+ appHost: string | null;
33
52
  now: number;
34
53
  alarmAt: number | null;
35
54
  schedules: Array<{ name: string; intervalMs: number | null; cron: string | null; nextRun: number }>;
@@ -72,6 +91,14 @@ export interface AppJobsConfig {
72
91
  script: string;
73
92
  /** The TribeNest public API base (VITE_API_URL) — used to verify the callback token. */
74
93
  apiUrl: string;
94
+ /**
95
+ * This app's public host, no scheme (VITE_APP_HOST) — e.g. "acme.tribenest.co".
96
+ * The job runtime posts each run to `https://<host>/api/tn-jobs/run`; it cannot
97
+ * reach the app any other way, so an app that never registers a host will not
98
+ * run jobs (its status reports "no app host recorded"). Injected at deploy —
99
+ * do not hand-set it.
100
+ */
101
+ host: string;
75
102
  }
76
103
 
77
104
  const stub = (env: AppJobsEnv, appId: string): AppJobsStub => env.JOBS.get(env.JOBS.idFromName(appId));
@@ -93,7 +120,7 @@ function scheduleHash(schedules: JobSchedule[]): string {
93
120
  * one, a removed one is pruned.
94
121
  */
95
122
  export async function reconcileAppJobs(env: AppJobsEnv, cfg: AppJobsConfig, schedules: JobSchedule[]): Promise<void> {
96
- await stub(env, cfg.appId).reconcile(cfg.script, cfg.appId, schedules, scheduleHash(schedules));
123
+ await stub(env, cfg.appId).reconcile(cfg.script, cfg.appId, schedules, scheduleHash(schedules), cfg.host);
97
124
  }
98
125
 
99
126
  /** Enqueue a durable one-time job (survives redeploys, retried on failure). */
@@ -104,7 +131,7 @@ export async function enqueueAppJob(
104
131
  payload?: unknown,
105
132
  delayMs = 0,
106
133
  ): Promise<void> {
107
- await stub(env, cfg.appId).enqueue(cfg.script, cfg.appId, name, payload ?? null, delayMs);
134
+ await stub(env, cfg.appId).enqueue(cfg.script, cfg.appId, name, payload ?? null, delayMs, cfg.host);
108
135
  }
109
136
 
110
137
  /**