@nextlyhq/plugin-sdk 0.0.1

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.
package/README.md ADDED
@@ -0,0 +1,163 @@
1
+ # @nextlyhq/plugin-sdk
2
+
3
+ The author-facing SDK for building [Nextly](https://nextlyhq.com) plugins.
4
+
5
+ > **⚠️ Alpha (`0.x`) — pin your versions.**
6
+ >
7
+ > The plugin API surface listed in [`STABILITY.md`](./STABILITY.md) is now **stable
8
+ > (`@public`) and semver-protected** (D40): once Nextly reaches `1.0`, breaking it
9
+ > requires a major version bump. Everything still marked `@experimental` carries **no**
10
+ > compatibility guarantee and may change in any release. While we are pre-`1.0`, **pin
11
+ > your `nextly` / `@nextlyhq/plugin-sdk` versions** and read the release notes before
12
+ > upgrading.
13
+
14
+ ## What this package is
15
+
16
+ `@nextlyhq/plugin-sdk` re-exports **exactly** the public, semver-protected plugin
17
+ surface — nothing internal. **This package _is_ the stability boundary** (D40/D43):
18
+ if it's not exported here (or from a subpath below), it is not part of the public
19
+ plugin API and may change at any time.
20
+
21
+ You can build a plugin against `nextly` directly, but importing from
22
+ `@nextlyhq/plugin-sdk` guarantees you only touch the supported surface.
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ npm install @nextlyhq/plugin-sdk
28
+ # nextly is a peer dependency; @nextlyhq/admin + react are optional peers
29
+ # (only needed for the /client and /admin entries).
30
+ ```
31
+
32
+ Add the `nextly-plugin` keyword to your plugin's `package.json` so it's
33
+ discoverable, and declare a `nextly` core-compatibility range (see below).
34
+
35
+ ## Entry points
36
+
37
+ | Import | Use it for | Needs React? |
38
+ | ------------------------------ | ------------------------------------------------------------------------------------------------------------------ | ------------------- |
39
+ | `@nextlyhq/plugin-sdk` | `definePlugin`, the `contributes`/`ctx`/hook/event/filter types, `PermissionSlug`/`EventName`, `secret()` | No (Node-safe) |
40
+ | `@nextlyhq/plugin-sdk/testing` | `createTestNextly` — boot a real Nextly on in-memory SQLite for integration tests | No |
41
+ | `@nextlyhq/plugin-sdk/client` | `useCan` / `<Can>` — client-side permission gating in admin components | Yes (optional peer) |
42
+ | `@nextlyhq/plugin-sdk/admin` | `registerComponent(s)` / `registerKnownPlugin` — register the React components your `contributes.admin` references | Yes (optional peer) |
43
+
44
+ The default `.` entry is React-free, so a plugin with no admin UI never pulls
45
+ React into a Node context.
46
+
47
+ ## Quick start
48
+
49
+ ```ts
50
+ import { definePlugin } from "@nextlyhq/plugin-sdk";
51
+
52
+ export const myPlugin = (opts: MyPluginOptions = {}) =>
53
+ definePlugin({
54
+ name: "@acme/nextly-plugin-hello",
55
+ version: "0.1.0",
56
+ nextly: "^0.0.2-alpha", // core-compatibility range, boot-checked (D6)
57
+ contributes: {
58
+ collections: [Greetings],
59
+ permissions: [
60
+ { action: "send", resource: "greeting", label: "Send Greeting" },
61
+ ],
62
+ },
63
+ init(ctx) {
64
+ // react to events (observe-only, post-commit); resolve your own slugs via ctx.self (D54)
65
+ ctx.events.on(
66
+ `collection.${ctx.self.collections.greetings}.created`,
67
+ () => {
68
+ ctx.logger.info("greeting created");
69
+ }
70
+ );
71
+ },
72
+ destroy(ctx) {
73
+ // teardown on shutdown / HMR / test teardown
74
+ },
75
+ });
76
+ ```
77
+
78
+ Register it in a host app:
79
+
80
+ ```ts
81
+ // nextly.config.ts
82
+ import { defineConfig } from "nextly";
83
+ import { myPlugin } from "@acme/nextly-plugin-hello";
84
+
85
+ export default defineConfig({
86
+ plugins: [myPlugin()],
87
+ });
88
+ ```
89
+
90
+ ## The plugin model (one-minute tour)
91
+
92
+ - **`definePlugin({...})`** returns a `PluginDefinition`: declarative **`contributes`**
93
+ (collections, singles, components, `extend`, permissions, events, routes, admin UI)
94
+ plus imperative **`setup` → `init` → `destroy`** lifecycle functions. All plugins'
95
+ `setup`s run before any `init`; load order is a topological sort over `dependsOn`.
96
+ - **`ctx` (in `init`/`destroy`)** gives you: `services` (managed, secure-by-default
97
+ data access — pass `{ as: "system" }` to elevate), `db` (raw Drizzle escape hatch),
98
+ `hooks` (in-transaction, modify/abort), `events` (post-commit, observe-only),
99
+ `filters`/`actions` (typed seams), `self` (your entities' resolved slugs after any
100
+ host `.rename()`), `logger`, `config`, and `nextlyVersion`.
101
+ - **Hooks vs events:** need to modify or abort an operation → use a **hook**; need to
102
+ react/notify after it commits → use an **event** (best-effort, may be dropped).
103
+ - **`ctx.self`** is how you reference your own collections/singles by their _resolved_
104
+ slug, so your plugin keeps working when an integrator renames an entity via
105
+ `plugin.rename({...})`. Never hardcode your own slugs in `init`.
106
+
107
+ ## Stability & versioning policy
108
+
109
+ The authoritative ledger of what is `@public` (stable) vs `@experimental` lives in
110
+ [`STABILITY.md`](./STABILITY.md). In short:
111
+
112
+ - **Stable (`@public`)** — `definePlugin`/`contributes`/lifecycle, `ctx.services`
113
+ (incl. `{ as: "system" }`), `contributes.routes`, `contributes.admin`
114
+ (menu/pages/views), `ctx.events` + the event-name constants, the collection
115
+ `HookContext`, and `@nextlyhq/plugin-sdk/testing`. Breaking a `@public` export
116
+ requires a Nextly **major** (D40).
117
+ - **Still `@experimental`** — the raw `ctx.db` escape hatch, `ctx.hooks` plugin
118
+ registration, filters/actions (D63), `secret()`, `useCan`/`<Can>`, and admin
119
+ dashboard widgets (D22). No compatibility guarantee yet — each graduates once a
120
+ first-party plugin exercises it (D55).
121
+ - **Deprecations** warn, keep at least a one-major support window, and ship with a
122
+ migration guide (D41). Promotion (`@experimental` → `@public`) is **not** a breaking
123
+ change.
124
+ - **Pre-`1.0` caveat** — during the `0.x` alpha, pin your versions; the major-bump
125
+ guarantee formally applies from `1.0`.
126
+ - **Declare a `nextly` range** in your `definePlugin` (e.g. `"^1 || ^2"`); it's checked
127
+ at boot and may span majors. Use `ctx.nextlyVersion` for runtime feature detection.
128
+
129
+ ## Building from source (contributors)
130
+
131
+ `@nextlyhq/plugin-sdk` declares `nextly` and `@nextlyhq/admin` as **peer
132
+ dependencies** and marks them `external` at build time — its generated `.d.ts`
133
+ files resolve those types against the **built `dist/`** of `nextly` /
134
+ `@nextlyhq/admin`. So build the core packages first:
135
+
136
+ ```bash
137
+ # from the monorepo root — builds nextly + admin before the SDK
138
+ pnpm turbo build --filter=@nextlyhq/plugin-sdk...
139
+ # or just build everything
140
+ pnpm turbo build
141
+ ```
142
+
143
+ Running `pnpm build` **inside** `packages/plugin-sdk` in isolation against a stale
144
+ or missing core `dist/` produces confusing `TS2305: Module 'nextly' has no exported
145
+ member …` errors — those are the stale-`dist` symptom, not a real API mismatch.
146
+ The Turborepo pipeline (`"build": { "dependsOn": ["^build"] }`) orders this
147
+ correctly; prefer it over building the package alone.
148
+
149
+ ## Author guide
150
+
151
+ See the full plugin author guide, API reference, and error-code reference in the
152
+ [Nextly docs](https://nextlyhq.com/docs/plugins). Scaffold a new plugin with:
153
+
154
+ ```bash
155
+ npm create nextly-app -- --template plugin
156
+ ```
157
+
158
+ which generates the package anatomy plus an embedded `dev/` playground (a minimal
159
+ Nextly app on SQLite with hot-reload) for iterating on your plugin locally.
160
+
161
+ ## License
162
+
163
+ MIT
@@ -0,0 +1,3 @@
1
+ export { ComponentPath, registerComponent, registerComponents, registerKnownPlugin } from '@nextlyhq/admin';
2
+ export { PluginAdminContributions, PluginAdminPage, PluginCollectionView, PluginMenuItem } from 'nextly';
3
+ import 'nextly/testing';
package/dist/admin.mjs ADDED
@@ -0,0 +1,3 @@
1
+ export { registerComponent, registerComponents, registerKnownPlugin } from '@nextlyhq/admin';
2
+ //# sourceMappingURL=admin.mjs.map
3
+ //# sourceMappingURL=admin.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"admin.mjs","sourcesContent":[]}
@@ -0,0 +1 @@
1
+ export { Can, CanProps, useCan } from '@nextlyhq/admin';
@@ -0,0 +1,3 @@
1
+ export { Can, useCan } from '@nextlyhq/admin';
2
+ //# sourceMappingURL=client.mjs.map
3
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"client.mjs","sourcesContent":[]}
@@ -0,0 +1,23 @@
1
+ export { Action, AuthEventName, AuthEvents, AuthHookName, AuthHooks, AuthInput, AuthOutcome, AuthStrategy, AuthUser, BatchOperationResult, Challenge, ChallengeDefinition, ComponentPath, CoreFilterSeam, DocumentEventName, DocumentEvents, EmailAfterSendValue, EmailFilterContext, EmailPayloadFilterValue, EventBus, EventEnvelope, EventHandler, EventName, Filter, FilterSeams, HookContext, HookHandler, HookType, ListQueryFilterContext, ListQueryWhere, MediaEventName, MediaEvents, Middleware, NavCollectionItem, NavFilterContext, PaginatedResult, PermissionSlug, PluginActionRegistry, PluginAdminContributions, PluginAdminPage, PluginAdminWidget, PluginCollectionService, PluginCollectionView, PluginContext, PluginContributions, PluginDefinition, PluginEmailProvider, PluginEmailTemplate, PluginFieldType, PluginFilterRegistry, PluginHookRegistry, PluginMenuItem, PluginPermission, PluginRole, PluginRoute, PluginRouteContext, PluginRouteHandler, QueryOptions, RouteMethod, ScheduledTask, ServiceOpts, definePlugin } from 'nextly';
2
+
3
+ /**
4
+ * @experimental A secret value that auto-redacts at every common leak vector —
5
+ * `JSON.stringify` (`toJSON`), `String()`/template interpolation (`toString`),
6
+ * and `console.log`/`util.inspect` (the node inspect symbol). The real value is
7
+ * available only via the explicit, greppable `.reveal()`. Wrap secret config /
8
+ * env values (D37): `secret(process.env.API_KEY)`.
9
+ */
10
+ declare class Secret<T = string> {
11
+ #private;
12
+ constructor(value: T);
13
+ /** Return the underlying secret value. The only way to read it. */
14
+ reveal(): T;
15
+ toJSON(): string;
16
+ toString(): string;
17
+ }
18
+ /** @experimental Wrap a value so it redacts unless explicitly `.reveal()`ed (D37). */
19
+ declare function secret<T>(value: T): Secret<T>;
20
+ /** @experimental True if `value` is a {@link Secret}. */
21
+ declare function isSecret(value: unknown): value is Secret<unknown>;
22
+
23
+ export { Secret, isSecret, secret };
package/dist/index.mjs ADDED
@@ -0,0 +1,35 @@
1
+ export { AuthEvents, DocumentEvents, FilterSeams, MediaEvents, definePlugin } from 'nextly';
2
+
3
+ // src/index.ts
4
+
5
+ // src/secret.ts
6
+ var REDACTED = "[redacted]";
7
+ var Secret = class {
8
+ #value;
9
+ constructor(value) {
10
+ this.#value = value;
11
+ }
12
+ /** Return the underlying secret value. The only way to read it. */
13
+ reveal() {
14
+ return this.#value;
15
+ }
16
+ toJSON() {
17
+ return REDACTED;
18
+ }
19
+ toString() {
20
+ return REDACTED;
21
+ }
22
+ [Symbol.for("nodejs.util.inspect.custom")]() {
23
+ return REDACTED;
24
+ }
25
+ };
26
+ function secret(value) {
27
+ return new Secret(value);
28
+ }
29
+ function isSecret(value) {
30
+ return value instanceof Secret;
31
+ }
32
+
33
+ export { Secret, isSecret, secret };
34
+ //# sourceMappingURL=index.mjs.map
35
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/secret.ts"],"names":[],"mappings":";;;;;AAAA,IAAM,QAAA,GAAW,YAAA;AASV,IAAM,SAAN,MAAyB;AAAA,EACrB,MAAA;AAAA,EACT,YAAY,KAAA,EAAU;AACpB,IAAA,IAAA,CAAK,MAAA,GAAS,KAAA;AAAA,EAChB;AAAA;AAAA,EAEA,MAAA,GAAY;AACV,IAAA,OAAO,IAAA,CAAK,MAAA;AAAA,EACd;AAAA,EACA,MAAA,GAAiB;AACf,IAAA,OAAO,QAAA;AAAA,EACT;AAAA,EACA,QAAA,GAAmB;AACjB,IAAA,OAAO,QAAA;AAAA,EACT;AAAA,EACA,CAAC,MAAA,CAAO,GAAA,CAAI,4BAA4B,CAAC,CAAA,GAAY;AACnD,IAAA,OAAO,QAAA;AAAA,EACT;AACF;AAGO,SAAS,OAAU,KAAA,EAAqB;AAC7C,EAAA,OAAO,IAAI,OAAO,KAAK,CAAA;AACzB;AAGO,SAAS,SAAS,KAAA,EAA0C;AACjE,EAAA,OAAO,KAAA,YAAiB,MAAA;AAC1B","file":"index.mjs","sourcesContent":["const REDACTED = \"[redacted]\";\n\n/**\n * @experimental A secret value that auto-redacts at every common leak vector —\n * `JSON.stringify` (`toJSON`), `String()`/template interpolation (`toString`),\n * and `console.log`/`util.inspect` (the node inspect symbol). The real value is\n * available only via the explicit, greppable `.reveal()`. Wrap secret config /\n * env values (D37): `secret(process.env.API_KEY)`.\n */\nexport class Secret<T = string> {\n readonly #value: T;\n constructor(value: T) {\n this.#value = value;\n }\n /** Return the underlying secret value. The only way to read it. */\n reveal(): T {\n return this.#value;\n }\n toJSON(): string {\n return REDACTED;\n }\n toString(): string {\n return REDACTED;\n }\n [Symbol.for(\"nodejs.util.inspect.custom\")](): string {\n return REDACTED;\n }\n}\n\n/** @experimental Wrap a value so it redacts unless explicitly `.reveal()`ed (D37). */\nexport function secret<T>(value: T): Secret<T> {\n return new Secret(value);\n}\n\n/** @experimental True if `value` is a {@link Secret}. */\nexport function isSecret(value: unknown): value is Secret<unknown> {\n return value instanceof Secret;\n}\n"]}
@@ -0,0 +1 @@
1
+ export { CreateTestNextlyOptions, TestNextly, createTestNextly } from 'nextly/testing';
@@ -0,0 +1,3 @@
1
+ export { createTestNextly } from 'nextly/testing';
2
+ //# sourceMappingURL=testing.mjs.map
3
+ //# sourceMappingURL=testing.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"testing.mjs","sourcesContent":[]}
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "@nextlyhq/plugin-sdk",
3
+ "version": "0.0.1",
4
+ "description": "Nextly Plugin SDK — the author-facing surface for building Nextly plugins; the plugin API stability boundary (see STABILITY.md).",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/nextlyhq/nextly.git",
9
+ "directory": "packages/plugin-sdk"
10
+ },
11
+ "homepage": "https://nextlyhq.com/docs/plugins",
12
+ "bugs": {
13
+ "url": "https://github.com/nextlyhq/nextly/issues"
14
+ },
15
+ "type": "module",
16
+ "main": "dist/index.mjs",
17
+ "module": "dist/index.mjs",
18
+ "types": "dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.mjs"
23
+ },
24
+ "./testing": {
25
+ "types": "./dist/testing.d.ts",
26
+ "import": "./dist/testing.mjs"
27
+ },
28
+ "./client": {
29
+ "types": "./dist/client.d.ts",
30
+ "import": "./dist/client.mjs"
31
+ },
32
+ "./admin": {
33
+ "types": "./dist/admin.d.ts",
34
+ "import": "./dist/admin.mjs"
35
+ }
36
+ },
37
+ "files": [
38
+ "dist"
39
+ ],
40
+ "scripts": {
41
+ "build": "tsup",
42
+ "dev": "tsup --watch",
43
+ "check-types": "tsc --noEmit",
44
+ "lint": "eslint . --max-warnings 0",
45
+ "clean": "rimraf dist",
46
+ "test": "vitest run"
47
+ },
48
+ "engines": {
49
+ "node": ">=20.0.0"
50
+ },
51
+ "peerDependencies": {
52
+ "@nextlyhq/admin": "workspace:*",
53
+ "nextly": "workspace:*",
54
+ "react": "^18.0.0 || ^19.0.0",
55
+ "react-dom": "^18.0.0 || ^19.0.0"
56
+ },
57
+ "peerDependenciesMeta": {
58
+ "@nextlyhq/admin": {
59
+ "optional": true
60
+ },
61
+ "react": {
62
+ "optional": true
63
+ },
64
+ "react-dom": {
65
+ "optional": true
66
+ }
67
+ },
68
+ "devDependencies": {
69
+ "@nextlyhq/admin": "workspace:*",
70
+ "@nextlyhq/eslint-config": "workspace:*",
71
+ "@nextlyhq/tsconfig": "workspace:*",
72
+ "@types/react": "^19.0.0",
73
+ "nextly": "workspace:*",
74
+ "react": "^19.0.0",
75
+ "react-dom": "^19.0.0",
76
+ "tsup": "^8.5.0",
77
+ "typescript": "^5.9.3",
78
+ "vitest": "^4.0.8"
79
+ },
80
+ "publishConfig": {
81
+ "access": "public",
82
+ "registry": "https://registry.npmjs.org/",
83
+ "provenance": true
84
+ },
85
+ "keywords": [
86
+ "nextly",
87
+ "plugin",
88
+ "sdk",
89
+ "nextly-plugin"
90
+ ]
91
+ }