Repository navigation
feat(docs): the snippets are compiled, not pasted - #74
Merged
Merged
Conversation
Contributor
Coverage Reportℹ️ This PR adds no executable lines, so there is no patch coverage to report. Additional details and impacted packages@@ Coverage Diff @@
## main@70cf2b1 #74 +/- ##
=============================================
Coverage 95.63% 95.63%
=============================================
Packages 4 4
Lines 962 962
Branches 343 343
=============================================
Hits 920 920
Misses 42 42
Measured by vitest + v8 over each package's |
dimartiro
force-pushed
the
feat/docs-merchant-sections
branch
from
October 27, 2026 16:45
4c1e162 to
ce593e4
Compare
dimartiro
force-pushed
the
feat/docs-compiled-snippets
branch
from
October 27, 2026 16:48
1ef06e9 to
0abd2a8
Compare
Contributor
|
📘 Docs preview: https://chainsafe.github.io/canton-x402-sdk/pr-74/ Updated on every push. Removed when this pull request closes. |
dimartiro
force-pushed
the
feat/docs-compiled-snippets
branch
from
October 27, 2026 16:50
0abd2a8 to
36cc2a2
Compare
Getting started pasted its two TypeScript programs, the merchant's gated route and the buyer's paying fetch, as fenced blocks that document whatever the SDK looked like the day they were written. They now live in docs/snippets as files the workspace compiles, and the page transcludes them (`<<< @/snippets/…#snippet`), so it shows exactly what compiles. docs/snippets is a private workspace package whose typecheck runs under the root `pnpm typecheck`, after `pnpm build` as CI already orders it, against the packages' own declarations. Compiled, never run. Chosen for the reader over pulling regions from examples/mortgage: each side stays one self-contained program a reader can copy, in the page's own names, where the demo's excerpts were fragments full of env helpers and credit-score plumbing. The merchant program now reads the names the dashboard's integration panel prints (NETWORK_ID, MERCHANT_PARTY, AMULET_ADMIN, FACILITATOR_API_KEY), so that .env drives it unchanged, and the API reference's curl uses $FACILITATOR_API_KEY for the same reason. VitePress renders the whole file, silently, when a region is missing. The docs config now fails the page instead, checking the token VitePress itself resolved rather than re-parsing the markdown. Checked by breaking it: renaming paymentRequired's `requirements` and CantonX402Payer's `registries` inside their packages, which still build, fails this typecheck at exactly those two options. Also: the buyer program logs the response it reads, because the linter refuses an unused `data`, and eslint skips docs/.vitepress/cache, which `docs:dev` fills with vendored Vue. (cherry picked from commit 36cc2a2)
dhyaniarun1993
force-pushed
the
feat/docs-compiled-snippets
branch
from
October 28, 2026 07:08
36cc2a2 to
812811f
Compare
dhyaniarun1993
approved these changes
Oct 28, 2026
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.
Closes #69. Stacked on #73; review that one first.
The two TypeScript programs on Getting started, the merchant's gated route and the buyer's paying fetch, move into
docs/snippets/*.ts, and the page transcludes them with<<< @/snippets/…#snippet. What the page shows is exactly what compiles.I put the reader first
The issue suggests pulling code from
examples/mortgagewith region markers where it already exists. I tried that, and it made the page worse to learn from. Each side became four excerpts of the demo, with no imports, env helpers the page never shows (req(),netConfig(),authConfig()), and credit-score plumbing in the main path, so a reader could no longer copy one block and run it. I therefore kept each side as one self-contained program in the page's own names, and linked the mortgage demo as the runnable pair. Both copies compile, so a signature change breaks both. What this does not catch is the demo and the docs drifting apart in content.The merchant program also reads the names the dashboard's integration panel prints (
FACILITATOR_URL,FACILITATOR_API_KEY,NETWORK_ID,MERCHANT_PARTY,AMULET_ADMIN), so a merchant can drop that.envin as is. The API reference's curl uses$FACILITATOR_API_KEYfor the same reason.How it is checked
docs/snippetsis a private workspace package with atypecheckscript, so the rootpnpm typecheckcovers it. CI already runspnpm buildfirst, so the snippets compile against the packages' real declarations, with no workflow change.#regionis missing. The docs config now fails the page instead, checking the token VitePress itself resolved. With ci(docs): publish the docs site, with a preview per pull request #72's docs build on every PR, this runs in CI once the branch is rebased.Breaking a signature fails the docs
Demonstrated, then reverted. Renaming
paymentRequired'srequirementsandCantonX402Payer'sregistriesinside their packages, which still build, gives:Against the issue
docs/snippetsis covered bypnpm typecheckand CI.curlandnpm installstay fenced, with a note on where$FACILITATOR_URLand$FACILITATOR_API_KEYcome from.examples/mortgagewhere the code exists: deliberately not done, as explained above.Also
console.log(data), because the linter refuses an unuseddata.docs/.vitepress/cache, whichdocs:devfills with vendored Vue. Before this,pnpm lintfailed locally after running the docs.docs/snippetsis a private workspace package, andchangeset statusasks for one.Verification
pnpm build && pnpm typecheck,pnpm lint,prettier --check,pnpm docs:buildandchangeset statuspass. The lockfile only gains the new importer, which reuses versions already in the tree.