feat(sdk): Frontend @gonext/sdk — slug detection, REST shims, Trusted Types#460
Merged
Conversation
Replaces the package.json-only stub with a working browser-side
SDK plugin authors import via the host's import map.
Surface:
- getSlug() / setSlug() / SlugRequiredError — auto-detects the
plugin slug from the loading import-map URL (or page <script>
tags, the gn-plugin-context JSON block, or window.__GN_PLUGIN_SLUG__
as fallbacks).
- host.{posts,users,media,cache} — same-origin REST shims over the
WP-compat surface (/wp-json/wp/v2/...) and the plugin-scoped
subtree (/api/plugins/{slug}/...). HostFetchError carries
status + parsed body so consumers can branch on transport vs.
server-side failures.
- defineBlock(spec) — forwards to __GN_BLOCK_REGISTRY__ (or the
legacy BLOCK_REGISTRY) when published by the editor, else
captures locally for later drain.
- i18n.t(key, args) / i18n.load(locale) — fetches the per-plugin
catalogue at /api/plugins/{slug}/i18n/{locale}.json, caches by
(slug, locale), falls back to the key on miss / error.
- setHTML(el, html) — Trusted-Types-safe innerHTML setter that
routes through the host's gn-plugin policy when one exists.
Build pipeline (tsup):
- dist/index.mjs (ESM, what the import map loads)
- dist/index.cjs (CJS, Node test harnesses)
- dist/index.d.ts (rolled-up declarations)
- sideEffects: false; zero runtime dependencies.
Tests (Vitest, jsdom): 69 cases covering slug detection across
all four strategies, REST shim transport (headers, abort, errors,
204 handling, query camel→snake mapping), Trusted Types compat
(installed factory, identity fallback, createPolicy refusal),
block registry forwarding + capture, and i18n catalogue caching
with malformed-input filtering.
Refs #214.
Signed-off-by: Tayeb Mokni <tayeb.mokni@gmail.com>
|
Heads up — this PR touches strings that often signal a security disclosure ( If this PR fixes or describes a real vulnerability that has not yet been publicly disclosed, please stop and use the private path:
See If this is a false positive (test fixture, doc update, release notes, etc.) please ignore this comment — the check is advisory only and does not block the PR. Matched files:
|
tayebmokni
pushed a commit
that referenced
this pull request
May 25, 2026
Closes #242. packages/ts/sdk-plugin: TypeScript SDK for GoNext plugin authors via Javy (JavaScript → WASM). - pluginInit + registerAction / registerFilter - Typed wrappers over every gn_* host ABI through globalThis - JSON envelope codec - Manifest builder mirroring the Go side - bin/gonext-sdk-build.js wraps esbuild + javy compile - cli/gonext/templates/typescript + 'gonext plugin init --template=typescript' - examples/plugins/sdk-ts-hello working example - 54 Vitest tests (codec + manifest + dispatch) This PR was rebased onto main after #460/#461/#462 landed; the runInit dispatch now switches on template name and embeds both templates/go and templates/typescript via the single templatesFS. Signed-off-by: Tayeb Mokni <tayeb.mokni@gmail.com>
tayebmokni
pushed a commit
that referenced
this pull request
May 25, 2026
Closes #239. packages/rust/gonext-sdk + packages/rust/gonext-sdk-macros: Cargo crates for Rust plugin authors. - plugin_init! proc-macro generates gn_alloc/gn_free/_start/gn_handle_hook exports - Safe typed wrappers over every gn_* host ABI (env, env_net, gonext_data, env_platform) - JSON envelope codec via serde_json - Manifest builder mirroring the Go side - cli/gonext/cmd/plugin/templates/rust + 'gonext plugin init --template=rust' - examples/plugins/sdk-rust-hello: working example (action + filter + kv.set + audit.emit) Rebased onto main after #460/#461/#462 landed; init.go now switches on template name. TestRunInitUnknownTemplate updated to use a clearly-not-real template name so it stays robust as new templates land. Signed-off-by: Tayeb Mokni <tayeb.mokni@gmail.com>
tayebmokni
pushed a commit
that referenced
this pull request
May 25, 2026
Closes #242. packages/ts/sdk-plugin: TypeScript SDK for GoNext plugin authors via Javy (JavaScript → WASM). - pluginInit + registerAction / registerFilter - Typed wrappers over every gn_* host ABI through globalThis - JSON envelope codec - Manifest builder mirroring the Go side - bin/gonext-sdk-build.js wraps esbuild + javy compile - cli/gonext/templates/typescript + 'gonext plugin init --template=typescript' - examples/plugins/sdk-ts-hello working example - 54 Vitest tests (codec + manifest + dispatch) This PR was rebased onto main after #460/#461/#462 landed; the runInit dispatch now switches on template name and embeds both templates/go and templates/typescript via the single templatesFS. Signed-off-by: Tayeb Mokni <tayeb.mokni@gmail.com>
tayebmokni
pushed a commit
that referenced
this pull request
May 26, 2026
Closes #242. packages/ts/sdk-plugin: TypeScript SDK for GoNext plugin authors via Javy (JavaScript → WASM). - pluginInit + registerAction / registerFilter - Typed wrappers over every gn_* host ABI through globalThis - JSON envelope codec - Manifest builder mirroring the Go side - bin/gonext-sdk-build.js wraps esbuild + javy compile - cli/gonext/templates/typescript + 'gonext plugin init --template=typescript' - examples/plugins/sdk-ts-hello working example - 54 Vitest tests (codec + manifest + dispatch) This PR was rebased onto main after #460/#461/#462 landed; the runInit dispatch now switches on template name and embeds both templates/go and templates/typescript via the single templatesFS. Signed-off-by: Tayeb Mokni <tayeb.mokni@gmail.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.
Closes #214.
`@gonext/sdk`: the browser-side TS package plugin authors import.
Surface
Build pipeline
`tsup` emits ESM (`dist/index.mjs`), CJS (`dist/index.cjs`), and rolled-up types (`dist/index.d.ts`). `sideEffects: false`, zero runtime dependencies — the SRI hash in the host's import map stays stable.
Tests
69 Vitest cases on jsdom, covering:
Files
🤖 Generated with Claude Code