@klnap/cache-invalidation 0.0.0-stage → 0.0.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 (143) hide show
  1. package/CHANGELOG.md +139 -0
  2. package/LICENSE +21 -0
  3. package/README.md +176 -2
  4. package/dist/consumers/next/compile-tag-template.d.ts +16 -0
  5. package/dist/consumers/next/compile-tag-template.js +83 -0
  6. package/dist/consumers/next/consumer-types.d.ts +98 -0
  7. package/dist/consumers/next/consumer-types.js +3 -0
  8. package/dist/consumers/next/define-cache.d.ts +4 -0
  9. package/dist/consumers/next/define-cache.js +281 -0
  10. package/dist/consumers/next/host-types.d.ts +44 -0
  11. package/dist/consumers/next/host-types.js +3 -0
  12. package/dist/consumers/next/index.d.ts +5 -0
  13. package/dist/consumers/next/index.js +2 -0
  14. package/dist/consumers/next/param-values.d.ts +8 -0
  15. package/dist/consumers/next/param-values.js +23 -0
  16. package/dist/consumers/next/profile.d.ts +2 -0
  17. package/dist/consumers/next/profile.js +18 -0
  18. package/dist/consumers/next/registry-builders.d.ts +3 -0
  19. package/dist/consumers/next/registry-builders.js +155 -0
  20. package/dist/consumers/next/revalidation-handler.d.ts +6 -0
  21. package/dist/consumers/next/revalidation-handler.js +2 -0
  22. package/dist/consumers/next/runtime.d.ts +5 -0
  23. package/dist/consumers/next/runtime.js +560 -0
  24. package/dist/core/cloudevents.d.ts +27 -0
  25. package/dist/core/cloudevents.js +172 -0
  26. package/dist/core/dispatch-outcome.d.ts +4 -0
  27. package/dist/core/dispatch-outcome.js +17 -0
  28. package/dist/core/errors.d.ts +16 -0
  29. package/dist/core/errors.js +28 -0
  30. package/dist/core/event-limits.d.ts +15 -0
  31. package/dist/core/event-limits.js +20 -0
  32. package/dist/core/event-selector.d.ts +9 -0
  33. package/dist/core/event-selector.js +5 -0
  34. package/dist/core/index.d.ts +10 -0
  35. package/dist/core/index.js +6 -0
  36. package/dist/core/resource-changed-schema.d.ts +35 -0
  37. package/dist/core/resource-changed-schema.js +12 -0
  38. package/dist/core/standard-schema.d.ts +2 -0
  39. package/dist/core/standard-schema.js +7 -0
  40. package/dist/core/types.d.ts +35 -0
  41. package/dist/core/types.js +1 -0
  42. package/dist/core/url-segment.d.ts +2 -0
  43. package/dist/core/url-segment.js +17 -0
  44. package/dist/dispatchers/http/index.d.ts +20 -0
  45. package/dist/dispatchers/http/index.js +274 -0
  46. package/dist/dispatchers/http/targets.d.ts +14 -0
  47. package/dist/dispatchers/http/targets.js +26 -0
  48. package/dist/dispatchers/index.d.ts +1 -0
  49. package/dist/dispatchers/index.js +1 -0
  50. package/dist/producers/payload/exclude-fields.d.ts +19 -0
  51. package/dist/producers/payload/exclude-fields.js +75 -0
  52. package/dist/producers/payload/index.d.ts +4 -0
  53. package/dist/producers/payload/index.js +3 -0
  54. package/dist/producers/payload/lifecycle/deferred.d.ts +55 -0
  55. package/dist/producers/payload/lifecycle/deferred.js +111 -0
  56. package/dist/producers/payload/lifecycle/dispatch.d.ts +18 -0
  57. package/dist/producers/payload/lifecycle/dispatch.js +21 -0
  58. package/dist/producers/payload/lifecycle/doc-content.d.ts +8 -0
  59. package/dist/producers/payload/lifecycle/doc-content.js +88 -0
  60. package/dist/producers/payload/lifecycle/draft-status.d.ts +6 -0
  61. package/dist/producers/payload/lifecycle/draft-status.js +15 -0
  62. package/dist/producers/payload/lifecycle/helpers.d.ts +13 -0
  63. package/dist/producers/payload/lifecycle/helpers.js +12 -0
  64. package/dist/producers/payload/lifecycle/identifier-field.d.ts +8 -0
  65. package/dist/producers/payload/lifecycle/identifier-field.js +48 -0
  66. package/dist/producers/payload/lifecycle/identifiers.d.ts +4 -0
  67. package/dist/producers/payload/lifecycle/identifiers.js +5 -0
  68. package/dist/producers/payload/lifecycle/locale-published.d.ts +7 -0
  69. package/dist/producers/payload/lifecycle/locale-published.js +19 -0
  70. package/dist/producers/payload/lifecycle/locale.d.ts +24 -0
  71. package/dist/producers/payload/lifecycle/locale.js +44 -0
  72. package/dist/producers/payload/lifecycle/log.d.ts +31 -0
  73. package/dist/producers/payload/lifecycle/log.js +67 -0
  74. package/dist/producers/payload/lifecycle/media-equality.d.ts +4 -0
  75. package/dist/producers/payload/lifecycle/media-equality.js +36 -0
  76. package/dist/producers/payload/lifecycle/operation.d.ts +2 -0
  77. package/dist/producers/payload/lifecycle/operation.js +7 -0
  78. package/dist/producers/payload/lifecycle/orderable-hooks.d.ts +21 -0
  79. package/dist/producers/payload/lifecycle/orderable-hooks.js +26 -0
  80. package/dist/producers/payload/lifecycle/orderable-neighbors.d.ts +21 -0
  81. package/dist/producers/payload/lifecycle/orderable-neighbors.js +151 -0
  82. package/dist/producers/payload/lifecycle/public-snapshots.d.ts +16 -0
  83. package/dist/producers/payload/lifecycle/public-snapshots.js +173 -0
  84. package/dist/producers/payload/lifecycle/revalidate.d.ts +16 -0
  85. package/dist/producers/payload/lifecycle/revalidate.js +162 -0
  86. package/dist/producers/payload/lifecycle/skip-rules.d.ts +19 -0
  87. package/dist/producers/payload/lifecycle/skip-rules.js +57 -0
  88. package/dist/producers/payload/lifecycle/types.d.ts +32 -0
  89. package/dist/producers/payload/lifecycle/types.js +1 -0
  90. package/dist/producers/payload/media/media-references.d.ts +31 -0
  91. package/dist/producers/payload/media/media-references.js +127 -0
  92. package/dist/producers/payload/media/resolve-media-affected-locales.d.ts +22 -0
  93. package/dist/producers/payload/media/resolve-media-affected-locales.js +70 -0
  94. package/dist/producers/payload/media/resolve-media-dependents.d.ts +39 -0
  95. package/dist/producers/payload/media/resolve-media-dependents.js +157 -0
  96. package/dist/producers/payload/media/resolve-media-slug.d.ts +7 -0
  97. package/dist/producers/payload/media/resolve-media-slug.js +17 -0
  98. package/dist/producers/payload/media/revalidate-media-dependents.d.ts +14 -0
  99. package/dist/producers/payload/media/revalidate-media-dependents.js +222 -0
  100. package/dist/producers/payload/plugin.d.ts +36 -0
  101. package/dist/producers/payload/plugin.js +235 -0
  102. package/dist/producers/payload/publish-all/context.d.ts +2 -0
  103. package/dist/producers/payload/publish-all/context.js +2 -0
  104. package/dist/producers/payload/publish-all/edited-locale.d.ts +5 -0
  105. package/dist/producers/payload/publish-all/edited-locale.js +5 -0
  106. package/dist/producers/payload/publish-all/index.d.ts +3 -0
  107. package/dist/producers/payload/publish-all/index.js +3 -0
  108. package/dist/producers/payload/publish-all/localization.d.ts +7 -0
  109. package/dist/producers/payload/publish-all/localization.js +1 -0
  110. package/dist/producers/payload/publish-all/mirror-publish-all-locales-to-req.d.ts +19 -0
  111. package/dist/producers/payload/publish-all/mirror-publish-all-locales-to-req.js +32 -0
  112. package/dist/producers/payload/publish-all/preserve-locales-on-publish-all.d.ts +2 -0
  113. package/dist/producers/payload/publish-all/preserve-locales-on-publish-all.js +145 -0
  114. package/dist/producers/payload/publish-all/read-localized-scalar.d.ts +2 -0
  115. package/dist/producers/payload/publish-all/read-localized-scalar.js +24 -0
  116. package/dist/producers/payload/publish-all/request-flags.d.ts +13 -0
  117. package/dist/producers/payload/publish-all/request-flags.js +9 -0
  118. package/dist/producers/payload/publish-all/restore-guard.d.ts +2 -0
  119. package/dist/producers/payload/publish-all/restore-guard.js +12 -0
  120. package/dist/producers/payload/publish-all/restore-locales-after-publish-all.d.ts +2 -0
  121. package/dist/producers/payload/publish-all/restore-locales-after-publish-all.js +85 -0
  122. package/dist/producers/payload/revalidation-custom.d.ts +37 -0
  123. package/dist/producers/payload/revalidation-custom.js +54 -0
  124. package/dist/producers/payload/schema.d.ts +3 -0
  125. package/dist/producers/payload/schema.js +23 -0
  126. package/docs/concepts/architecture.md +32 -0
  127. package/docs/concepts/cache-tags.md +97 -0
  128. package/docs/concepts/event-contract.md +38 -0
  129. package/docs/consumers/custom.md +19 -0
  130. package/docs/consumers/next.md +277 -0
  131. package/docs/dispatchers/custom.md +38 -0
  132. package/docs/dispatchers/http.md +66 -0
  133. package/docs/extending.md +26 -0
  134. package/docs/migration/0.3.0-to-0.4.0.md +67 -0
  135. package/docs/migration/0.4.0-to-0.5.0.md +60 -0
  136. package/docs/migration/0.5.x-to-0.0.0.md +143 -0
  137. package/docs/producers/custom.md +63 -0
  138. package/docs/producers/payload-media-dependencies.md +45 -0
  139. package/docs/producers/payload.md +140 -0
  140. package/docs/reliability.md +35 -0
  141. package/docs/security.md +34 -0
  142. package/docs/troubleshooting.md +14 -0
  143. package/package.json +120 -4
@@ -0,0 +1,35 @@
1
+ # Reliability
2
+
3
+ Revalidation has separate stages: a producer captures a change, a dispatcher delivers it, a consumer plans operations, and the cache API performs invalidation. Success at one stage does not guarantee success at the next.
4
+
5
+ ## Delivery
6
+
7
+ The built-in HTTP dispatcher uses bounded retries and a total deadline. It reports per-target outcomes but has no persistent queue. Retries can deliver duplicates. Process exit, prolonged outages, or an expired deadline can lose an event.
8
+
9
+ Event IDs remain stable across retries. The Next.js handler suppresses repeated `(source, id)` identities inside one request and rejects conflicting content under a repeated identity. It does not persist replay history across requests or restarts.
10
+
11
+ ## Payload transaction timing
12
+
13
+ Ordinary collection and global hooks run before Payload commits their transaction. Deferred best-effort delivery does not prove commit ordering. An event may be delivered for a write that later rolls back, or trigger cache repopulation before the write is visible.
14
+
15
+ The orderable integration defers through its transaction owner's `onCommitted` and `onRolledBack` callbacks. This timing applies only when that host integration owns the transaction and invokes those callbacks as expected. It does not make unrelated Payload hooks post-commit.
16
+
17
+ Payload snapshot or dependency read failures are logged and do not reject the save. The affected event or resource may be omitted. Failed reads are never represented as a genuine `null` snapshot. Media dependency discovery dispatches successful resolutions when other scopes fail, then logs failed scopes; it does not retry them.
18
+
19
+ ## Consumer execution
20
+
21
+ The Next.js handler validates and plans the full request before executing operations. Planning is preflighted, but execution is not atomic. A cache API can fail after earlier operations completed.
22
+
23
+ Application-owned operations run before their dependent tag and path operations. If one fails, those dependent cache operations are skipped and the handler returns an error. `AbortSignal` is cooperative: it cannot forcibly stop arbitrary JavaScript, cancel every external service, or roll back side effects.
24
+
25
+ ## Next.js cache semantics
26
+
27
+ The consumer calls native `revalidateTag(tag, profile)` and `revalidatePath(path, type?)`. The default tag profile `{ expire: 0 }` requests immediate expiration; a later server read may regenerate the data. A profile such as `'max'` may serve stale data while revalidation runs.
28
+
29
+ Path invalidation targets a route or route pattern. It does not regenerate every matching page immediately, refresh every open browser, or invalidate an external CDN. Next.js and its cache handler own distributed cache coordination.
30
+
31
+ `cacheLife()` sets cache lifetime. On-demand invalidation is a separate operation. Neither profile configuration nor cache lifetime repairs lost event delivery or proves that an upstream index is current.
32
+
33
+ ## Guarantees
34
+
35
+ The package does not provide exactly-once delivery, durable delivery, global ordering, transactional webhook dispatch, atomic cache invalidation, or a workflow engine. Applications that require those guarantees must own the corresponding queue, transaction, revision, and recovery mechanisms.
@@ -0,0 +1,34 @@
1
+ # Security
2
+
3
+ ## Webhook authentication
4
+
5
+ The HTTP dispatcher signs the exact serialized request body with Standard Webhooks. The Next.js handler verifies the received body and timestamp before parsing CloudEvents or running operations.
6
+
7
+ - Use HTTPS between producer and consumer.
8
+ - Keep secrets in server-only environment variables. Never expose them in client bundles.
9
+ - Use Standard Webhooks `whsec_`-encoded secrets.
10
+ - Keep target URLs trusted. HTTPS does not provide destination allowlisting.
11
+ - Plain HTTP is limited to loopback unless `allowInsecure: true` is enabled.
12
+ - Captured signed requests can be replayed within the accepted timestamp window. The handler has no persistent replay store.
13
+
14
+ `allowedSources` restricts CloudEvents source values after signature verification. It does not identify which holder of a shared signing secret sent a request.
15
+
16
+ ## Input boundaries
17
+
18
+ The handler checks the content type and bounded request body, verifies the signature, parses the CloudEvents envelope, authorizes sources, validates relevant local schemas, and preflights operations before side effects.
19
+
20
+ Default limits are 256 KiB per body and 100 events per request. Generated tags are limited to Next.js's 256-character constraint. Paths must be valid rooted paths within the configured path length limit. See the [Next.js consumer guide](consumers/next.md).
21
+
22
+ Schemas are resolved from local configuration. The handler never downloads a schema based on an incoming `dataschema` URI. Unknown data stays unknown unless a local Standard Schema V1 validator accepts it.
23
+
24
+ ## Payload snapshots
25
+
26
+ Payload hook documents can contain hidden or privileged fields. The producer reads snapshots through Payload's normal access control and field visibility, with relation depth zero. It does not fall back to raw hook documents if safe reads fail. Projection reduces fields only after public-state comparison; it is not an access-control mechanism.
27
+
28
+ Treat event data and logs as potentially sensitive. Do not include secrets, credentials, or private application fields in public snapshots.
29
+
30
+ ## Logging and deployment controls
31
+
32
+ Do not log webhook secrets, signatures, raw request bodies, or confidential event content. The built-in handler logs request identifiers, statuses, outcomes, and error names. HTTP responses use sanitized error messages.
33
+
34
+ The package does not provide rate limiting, destination allowlisting, a durable queue, or replay storage. Apply infrastructure controls when the deployment requires them.
@@ -0,0 +1,14 @@
1
+ # Troubleshooting
2
+
3
+ | Symptom | Cause | Fix |
4
+ | --- | --- | --- |
5
+ | `401 Unauthorized` | Standard Webhooks signature is missing, invalid, or outside the accepted timestamp window. | Check that the producer and `cacheInvalidationHandler` use the same secret and that the original request body reaches the handler. |
6
+ | `403 Event source not allowed` | The event source is not in the handler's `allowedSources`. | Add the exact CloudEvents `source` URI to the local allowlist. |
7
+ | `415 Unsupported media type` | Request content type is not a supported CloudEvents JSON format. | Send `application/cloudevents+json` or `application/cloudevents-batch+json`. |
8
+ | `413 Request limit exceeded` | Body or event count exceeds the configured handler limit. | Reduce the batch size or set an appropriate transport limit. |
9
+ | `400 Invalid request` | The body is malformed, an event is invalid, or recognized data fails local schema or planning validation. | Inspect consumer diagnostics without exposing them to the caller; correct the producer payload or local rule. |
10
+ | `500 Internal server error` | Cache operation or custom execution failed. | Inspect consumer logs and the failed operation outcome. |
11
+ | No cache change after delivery | The event type has no rule, the cached function lacks the matching tag, or its tag differs from the planned tag. | Check ignored-event outcomes, rule keys, and `cacheTag()` values. |
12
+ | Old route remains cached | A concrete path or route-pattern scope does not match the intended Next.js route. | Check path parameters and use a scoped tuple for literal `page` or `layout` invalidation. |
13
+ | Media edit misses dependent content | The media field shape is unsupported or the dependent resource is not enabled for cache invalidation. | Check [media dependency support](producers/payload-media-dependencies.md#supported-relationships) and resource configuration. |
14
+ | Payload logs a delivery failure | Synchronous best-effort dispatch failed or exhausted bounded retries. | Check target URL, timeout, secret, and dispatcher logs. The Payload save remains fail-open. |
package/package.json CHANGED
@@ -1,6 +1,122 @@
1
1
  {
2
2
  "name": "@klnap/cache-invalidation",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.0",
4
+ "description": "Declarative, type-safe cache invalidation across applications with a framework-independent event protocol and native Payload CMS, HTTP, and Next.js integrations.",
5
+ "keywords": [
6
+ "revalidation",
7
+ "cache",
8
+ "cache-invalidation",
9
+ "cache-tags",
10
+ "type-safe",
11
+ "event-driven",
12
+ "nextjs",
13
+ "payloadcms"
14
+ ],
15
+ "homepage": "https://github.com/klnap/cache-invalidation#readme",
16
+ "bugs": {
17
+ "url": "https://github.com/klnap/cache-invalidation/issues"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/klnap/cache-invalidation.git"
22
+ },
23
+ "license": "MIT",
24
+ "author": "klnap",
25
+ "packageManager": "bun@1.4.5",
26
+ "type": "module",
27
+ "sideEffects": false,
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/core/index.d.ts",
31
+ "default": "./dist/core/index.js"
32
+ },
33
+ "./producers/payload": {
34
+ "types": "./dist/producers/payload/index.d.ts",
35
+ "default": "./dist/producers/payload/index.js"
36
+ },
37
+ "./consumers/next": {
38
+ "types": "./dist/consumers/next/index.d.ts",
39
+ "default": "./dist/consumers/next/index.js"
40
+ },
41
+ "./dispatchers": {
42
+ "types": "./dist/dispatchers/index.d.ts",
43
+ "default": "./dist/dispatchers/index.js"
44
+ },
45
+ "./dispatchers/http": {
46
+ "types": "./dist/dispatchers/http/index.d.ts",
47
+ "default": "./dist/dispatchers/http/index.js"
48
+ }
49
+ },
50
+ "files": [
51
+ "dist",
52
+ "docs/concepts",
53
+ "docs/consumers",
54
+ "docs/dispatchers",
55
+ "docs/migration",
56
+ "docs/producers",
57
+ "docs/extending.md",
58
+ "docs/reliability.md",
59
+ "docs/security.md",
60
+ "docs/troubleshooting.md",
61
+ "README.md",
62
+ "CHANGELOG.md",
63
+ "LICENSE"
64
+ ],
65
+ "scripts": {
66
+ "build": "rm -rf dist && tsc -p tsconfig.build.json",
67
+ "typecheck": "bun run build && tsc -p tsconfig.json && tsc -p tsconfig.types.json",
68
+ "test": "bun test src tests/unit tests/contract tests/docs",
69
+ "test:integration": "bun test --timeout=30000 tests/integration/payload-revalidation.int.test.ts tests/integration/media-dependents.int.test.ts",
70
+ "test:orderable-integration": "scripts/test-orderable-integration.sh",
71
+ "test:consumer-smoke": "bun run build && scripts/consumer-smoke.sh",
72
+ "format": "biome format .",
73
+ "format:write": "biome format --write .",
74
+ "lint": "biome lint .",
75
+ "knip": "knip",
76
+ "verify:package": "publint --strict && attw --pack . --profile esm-only",
77
+ "check": "bun run format && bun run lint && bun run typecheck && bun run knip && bun run check:boundaries && bun run test && bun run verify:package",
78
+ "changeset": "changeset",
79
+ "changeset:version": "changeset version",
80
+ "changeset:version-check": "bun run changeset:version && bun run check",
81
+ "check:boundaries": "depcruise --config dependency-cruiser.config.mjs --output-type err-long src"
82
+ },
83
+ "peerDependencies": {
84
+ "next": ">=16.4.5 <17",
85
+ "payload": ">=3.94.1 <4"
86
+ },
87
+ "peerDependenciesMeta": {
88
+ "next": {
89
+ "optional": true
90
+ },
91
+ "payload": {
92
+ "optional": true
93
+ }
94
+ },
95
+ "dependencies": {
96
+ "@standard-schema/spec": "^1.1.0",
97
+ "standardwebhooks": "^1.3.0",
98
+ "valibot": "^1.4.0"
99
+ },
100
+ "devDependencies": {
101
+ "@arethetypeswrong/cli": "0.18.5",
102
+ "@biomejs/biome": "2.6.8",
103
+ "@changesets/cli": "3.0.3",
104
+ "@payloadcms/db-sqlite": "3.94.1",
105
+ "@swc/core": "1.16.22",
106
+ "@types/bun": "1.4.5",
107
+ "dependency-cruiser": "18.9.0",
108
+ "knip": "6.48.0",
109
+ "next": "16.4.6",
110
+ "npm": "12.2.3",
111
+ "payload": "3.94.1",
112
+ "publint": "0.3.25",
113
+ "typescript": "7.0.2"
114
+ },
115
+ "engines": {
116
+ "node": "^22.23.5 || ^24.22.3 || >=26.13.1"
117
+ },
118
+ "publishConfig": {
119
+ "access": "public",
120
+ "registry": "https://registry.npmjs.org/"
121
+ }
122
+ }