Add four marquee examples + e2e CI against goja-enabled OSS gateway#1
Merged
Conversation
The starter previously had one marquee example covering the `pre` hook
(jws-request-signing). Add an example for each of the other four hook
types and an end-to-end CI scaffold that runs all five against a real
Tyk gateway in Docker.
Examples (each: TS plugin, vitest unit tests, webpack ES5 bundle):
- auth-check-hmac (auth_check) — replace built-in auth with HMAC-SHA256
signature validation; uses ReturnAuthData with a constructed session
- post-key-auth-tenant-context (post_key_auth) — read session.meta_data
to inject X-Tenant-Id; demonstrates require_session: true
- post-correlation-id (post) — preserve inbound or generate UUID v4;
ships a Web Crypto shim because goja lacks crypto.getRandomValues
- response-pii-redaction (response) — mask SSN-shaped patterns in
response bodies; AI-authored from public docs as the original
generation-loop validation
E2E (`e2e/`):
- docker-compose: redis + python http.server (bundle host) + tyk
- gateway.Dockerfile + build-gateway-image.sh: cross-compiles the
goja branch and overlays it onto tykio/tyk-gateway:v5.7. Reason:
the published image still ships otto, which doesn't support
globalThis or un-down-transpiled ES2015+ from npm deps. When goja
merges to main, delete the overlay and switch to the public tag.
- stage-bundles.mjs: discovers each example's dist/bundle.zip,
recomputes checksum, stages into bundles/<slug>.zip
- apps/<slug>.json + tests/<slug>.sh: per-example API def + curl-
based assertion. tenant.sh creates a real session via
/tyk/keys/create REST API to drive the post_key_auth path.
- run.sh: builds the gateway image if missing, brings up the stack,
polls /hello, runs every tests/*.sh, tears down.
CI:
- .github/workflows/test.yml — matrix expanded from 1 to 5 examples
- .github/workflows/e2e.yml — clones the goja branch via configurable
TYK_GW_REF, builds the image, runs the e2e suite, uploads per-
example bundles AND a combined bundles-${SHA}.zip aggregate; gateway
logs uploaded on failure; step summary table by hook
Types + AGENTS.md (gaps surfaced by the AI generation loop):
- ReturnAuthData second arg widened to Partial<TykSession> so
auth_check plugins constructing a minimal session no longer need
`as any` casts (auth-check-hmac cleaned up accordingly)
- AGENTS.md hook table now lists the right return helper, manifest
shape (array vs singular), and require_session expectation for each
hook. Two gotchas called out explicitly: auth_check is a singular
manifest object (not an array), and require_session must be true
for hooks reading session.* data.
- New Web Crypto shim section documents the crypto.getRandomValues
pattern with a copy-pasteable implementation; post-correlation-id
is the canonical worked example.
Validation status:
- All 5 examples: tsc clean, vitest green, webpack builds, valid bundle
- Local e2e: 5/5 pass against goja-enabled gateway in Docker
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Types now ship as a published package (https://www.npmjs.com/package/@tyk-technologies/tyk-plugin-types) rather than a bundled src/types.d.ts. Each plugin entry references the package via `/// <reference types="..." />`, and every package.json depends on `^0.1.0` so the same audited type surface (handler shape, request/session/response, globals like TykMakeHttpRequest, manifest constants) is shared across the starter, all examples, and any consumer's project. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
pre-trace-id is the minimal pre-hook example: stamp X-Trace-Id on every request. Useful as a baseline tracing header and as the second bundle in the multi-bundle composition demo. multi-bundle.json + multi-bundle.sh exercise custom_middleware_bundles end-to-end: two pre-hook bundles (pre-trace-id and jws-request-signing) on the same API, asserted by upstream headers. Both bundles export a global named `handler`; the gateway aliases each export under a per-(file, name) IIFE so they coexist without colliding. Docs sweep: README, examples/README, e2e/README updated to document the composition pattern and drop stale "coming soon" framing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Tyk collapsed the multi-bundle array field back into the existing custom_middleware_bundle string (commit 637e337a7), which now accepts "a.zip,b.zip" syntax. Update the e2e API def, all example/README/test prose, and the multi-bundle test comment to match. No behaviour change to the underlying composition flow. Also marks e2e/run.sh executable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
auth_check,post_key_auth,post,response); the previous repo had onlypre. Four of five examples were AI-authored from the public docs (AGENTS.md + types.d.ts + JWS) — the fifth was promoted from the live AI-generation experiment.Test plan
Notes for reviewers
🤖 Generated with Claude Code