@fabrika/app 0.9.0-dev.4 → 0.9.0-dev.5

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 (113) hide show
  1. package/package.json +9 -9
  2. package/skill/SKILL.md +41 -14
  3. package/skill/references/app-setup.md +43 -12
  4. package/skill/references/dev.md +2 -1
  5. package/skill/references/endpoint.md +30 -24
  6. package/skill/references/errors.md +40 -35
  7. package/skill/references/files.md +4 -2
  8. package/skill/references/jobs.md +21 -4
  9. package/skill/references/table-and-migration.md +19 -2
  10. package/skill/references/tests.md +40 -1
  11. package/skill/references/webhooks-links-connectors.md +1 -1
  12. package/src/build-recipe.ts +198 -0
  13. package/src/build.ts +60 -4
  14. package/src/bun.ts +181 -13
  15. package/src/cloudflare/application.ts +822 -0
  16. package/src/cloudflare/bindings.ts +159 -0
  17. package/src/cloudflare/export.ts +641 -0
  18. package/src/cloudflare/import.ts +1021 -0
  19. package/src/cloudflare/maintenance.ts +518 -0
  20. package/src/cloudflare/names.ts +16 -0
  21. package/src/cloudflare/ops.ts +375 -0
  22. package/src/cloudflare/r2-files.ts +172 -0
  23. package/src/cloudflare/restore.ts +167 -0
  24. package/src/cloudflare/tracker.ts +192 -0
  25. package/src/cloudflare.ts +100 -146
  26. package/src/contract/app-id.ts +5 -0
  27. package/src/contract/artifact-schema.ts +9 -1
  28. package/src/contract/build.ts +40 -2
  29. package/src/contract/compile.ts +1 -0
  30. package/src/contract/context.ts +35 -9
  31. package/src/contract/declaration.ts +2 -0
  32. package/src/contract/defaults.ts +22 -2
  33. package/src/contract/define.ts +29 -3
  34. package/src/contract/kit.ts +4 -1
  35. package/src/contract/platform.ts +3 -2
  36. package/src/contract/vocabulary.ts +26 -8
  37. package/src/dev/launcher.ts +50 -4
  38. package/src/disk-assets.ts +8 -3
  39. package/src/files/archive.ts +2 -2
  40. package/src/files/job-names.ts +12 -0
  41. package/src/files/kinds.ts +73 -31
  42. package/src/files/scan.ts +3 -4
  43. package/src/files/streams.ts +3 -1
  44. package/src/implement/anonymous.ts +12 -11
  45. package/src/implement/boot.ts +75 -6
  46. package/src/implement/bounded.ts +21 -2
  47. package/src/implement/capability.ts +15 -3
  48. package/src/implement/dispatch.ts +419 -177
  49. package/src/implement/failures.ts +17 -1
  50. package/src/implement/faults.ts +1 -0
  51. package/src/implement/index.ts +1 -0
  52. package/src/implement/invocation.ts +58 -10
  53. package/src/implement/principal.ts +25 -2
  54. package/src/implement/terminals.ts +93 -0
  55. package/src/implement/workload.ts +42 -16
  56. package/src/jobs/mail.ts +8 -0
  57. package/src/jobs/report.ts +5 -1
  58. package/src/jobs/runner.ts +672 -113
  59. package/src/jobs/schedule.ts +7 -1
  60. package/src/jobs/scrub.ts +14 -1
  61. package/src/jobs/types.ts +6 -0
  62. package/src/spa-fallback.ts +12 -0
  63. package/src/testing/endpoint-access.ts +307 -152
  64. package/src/testing/isolation.ts +8 -1
  65. package/src/testing/kit.ts +80 -2
  66. package/src/testing/proxy.ts +15 -10
  67. package/types/src/build-recipe.d.ts +70 -0
  68. package/types/src/build.d.ts +19 -1
  69. package/types/src/bun.d.ts +34 -1
  70. package/types/src/cloudflare/application.d.ts +73 -0
  71. package/types/src/cloudflare/bindings.d.ts +33 -0
  72. package/types/src/cloudflare/export.d.ts +16 -0
  73. package/types/src/cloudflare/import.d.ts +51 -0
  74. package/types/src/cloudflare/maintenance.d.ts +117 -0
  75. package/types/src/cloudflare/names.d.ts +11 -0
  76. package/types/src/cloudflare/ops.d.ts +81 -0
  77. package/types/src/cloudflare/r2-files.d.ts +9 -0
  78. package/types/src/cloudflare/restore.d.ts +9 -0
  79. package/types/src/cloudflare/tracker.d.ts +29 -0
  80. package/types/src/cloudflare.d.ts +12 -18
  81. package/types/src/contract/app-id.d.ts +2 -0
  82. package/types/src/contract/artifact-schema.d.ts +2 -0
  83. package/types/src/contract/context.d.ts +35 -11
  84. package/types/src/contract/declaration.d.ts +4 -0
  85. package/types/src/contract/defaults.d.ts +19 -1
  86. package/types/src/contract/define.d.ts +20 -3
  87. package/types/src/contract/kit.d.ts +2 -1
  88. package/types/src/contract/platform.d.ts +2 -2
  89. package/types/src/contract/vocabulary.d.ts +9 -7
  90. package/types/src/disk-assets.d.ts +4 -1
  91. package/types/src/files/job-names.d.ts +9 -0
  92. package/types/src/files/kinds.d.ts +21 -14
  93. package/types/src/files/scan.d.ts +1 -3
  94. package/types/src/implement/anonymous.d.ts +2 -4
  95. package/types/src/implement/boot.d.ts +17 -1
  96. package/types/src/implement/bounded.d.ts +11 -1
  97. package/types/src/implement/capability.d.ts +4 -2
  98. package/types/src/implement/dispatch.d.ts +34 -1
  99. package/types/src/implement/failures.d.ts +5 -0
  100. package/types/src/implement/faults.d.ts +1 -0
  101. package/types/src/implement/index.d.ts +1 -0
  102. package/types/src/implement/invocation.d.ts +22 -7
  103. package/types/src/implement/principal.d.ts +6 -1
  104. package/types/src/implement/terminals.d.ts +33 -0
  105. package/types/src/implement/workload.d.ts +5 -0
  106. package/types/src/jobs/runner.d.ts +66 -2
  107. package/types/src/jobs/schedule.d.ts +2 -0
  108. package/types/src/jobs/types.d.ts +6 -0
  109. package/types/src/spa-fallback.d.ts +2 -0
  110. package/types/src/testing/endpoint-access.d.ts +37 -5
  111. package/types/src/testing/isolation.d.ts +1 -1
  112. package/types/src/testing/kit.d.ts +22 -1
  113. package/types/src/testing/proxy.d.ts +4 -4
@@ -1,5 +1,6 @@
1
1
  // The five-field cron expressions of `c.cron`, read in UTC: which minutes a job is due, so the runner can tell how
2
- // long ago it should last have succeeded. The crontab, not this module, triggers a run.
2
+ // long ago it should last have succeeded. On Bun the crontab triggers a run; on Cloudflare the application's object
3
+ // runs, at each minute tick, the jobs `isDueAt` that minute.
3
4
 
4
5
  interface Field {
5
6
  readonly min: number
@@ -96,6 +97,11 @@ function dayMatches(schedule: CronSchedule, day: Date): boolean {
96
97
  return schedule.eitherDay ? byMonth || byWeek : byMonth && byWeek
97
98
  }
98
99
 
100
+ /** Whether the schedule is due in the UTC minute that holds `at`: what a Worker's minute tick runs (ADR-0065). */
101
+ export function isDueAt(schedule: CronSchedule, at: Date): boolean {
102
+ return schedule.minutes.has(at.getUTCMinutes()) && schedule.hours.has(at.getUTCHours()) && dayMatches(schedule, at)
103
+ }
104
+
99
105
  const descending = (values: ReadonlySet<number>): number[] => [...values].sort((left, right) => right - left)
100
106
 
101
107
  /** The latest `count` due minutes at or before `at`, newest first; fewer when the schedule is that rare. */
package/src/jobs/scrub.ts CHANGED
@@ -1,7 +1,16 @@
1
1
  // What an error report must not carry (ADR-0059): the values of the application's secrets, and anything shaped like a
2
2
  // credential — a JWT, an `Authorization` scheme or header, a URL's userinfo, a sensitive query parameter.
3
3
 
4
- import { FABRIKA_CONTRACT_DIGEST, FABRIKA_IAM_APP_ID, FABRIKA_IAM_ISSUER, PLATFORM_RECEIVERS, platformTransportVariables } from '@fabrika/auth-core'
4
+ import {
5
+ FABRIKA_APPLICATION_OBJECT,
6
+ FABRIKA_APPLICATION_OBJECTS,
7
+ FABRIKA_CONTRACT_DIGEST,
8
+ FABRIKA_IAM_APP_ID,
9
+ FABRIKA_IAM_ISSUER,
10
+ FABRIKA_OPS_KEY_DIGESTS,
11
+ PLATFORM_RECEIVERS,
12
+ platformTransportVariables,
13
+ } from '@fabrika/auth-core'
5
14
  import type { CapturedEnvironment } from '../implement/environment'
6
15
 
7
16
  export const REDACTED = '[redacted]'
@@ -21,6 +30,10 @@ const PUBLIC_FRAMEWORK_VARIABLES: ReadonlySet<string> = new Set([
21
30
  FABRIKA_CONTRACT_DIGEST,
22
31
  FABRIKA_IAM_APP_ID,
23
32
  FABRIKA_IAM_ISSUER,
33
+ // Digests of the ops keys, which are no credential; the object names are words (`application`) a message carries.
34
+ FABRIKA_OPS_KEY_DIGESTS,
35
+ FABRIKA_APPLICATION_OBJECT,
36
+ FABRIKA_APPLICATION_OBJECTS,
24
37
  ...PLATFORM_RECEIVERS.map((receiver) => platformTransportVariables(receiver).url),
25
38
  ])
26
39
 
package/src/jobs/types.ts CHANGED
@@ -54,6 +54,12 @@ export interface AppMailMessage {
54
54
  * an `https:` link, usually `ctx.url` of a public procedure that verifies a signed token.
55
55
  */
56
56
  readonly unsubscribe?: { readonly url: string }
57
+ /**
58
+ * One message of a send to many recipients (a newsletter, an announcement), not a reply to what the recipient did.
59
+ * The transport sends it on the provider's channel for broadcast mail, which keeps it apart from sign-in links and
60
+ * receipts. It needs `unsubscribe`. A transport without `capabilities.broadcast` refuses it as `invalid_message`.
61
+ */
62
+ readonly broadcast?: boolean
57
63
  /**
58
64
  * Files the message carries: references this attempt holds and may read, as `ctx.files.open` takes them. Only a
59
65
  * `live` file is sent; the bytes of all of them together stay within the transport's `maxAttachmentBytes`, and a
@@ -0,0 +1,12 @@
1
+ // Which request an SPA mount answers with its `index.html` when it names no file: a route of the page, not a missing
2
+ // asset. Both asset servers apply it (`diskAssets`, `bindingAssets`), so a missing script stays a 404 and never arrives
3
+ // as an HTML page with a 200.
4
+
5
+ import { rawRequestTarget } from '@fabrika/auth-core'
6
+
7
+ /** A GET or HEAD whose last path segment has no extension, or one that asks for HTML (a navigation to `/notes/v1.2`). */
8
+ export function isPageRoute(request: Request): boolean {
9
+ if (request.method !== 'GET' && request.method !== 'HEAD') return false
10
+ const last = rawRequestTarget(request.url).pathname.split('/').pop() ?? ''
11
+ return !last.includes('.') || (request.headers.get('Accept') ?? '').includes('text/html')
12
+ }