@zapier/kitcore 0.0.0 → 0.5.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,96 @@
1
+ # @zapier/kitcore
2
+
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5f5f028: The module model is complete; the legacy function-plugin bridge is deprecated.
8
+
9
+ New:
10
+ - `createSdk(root, { configuration })` injects immutable values by plugin id
11
+ at build time (your SDK's options, framework options). A `declareProperty`
12
+ or `declareOptionalProperty` (new) stand-in with a matching id receives the
13
+ value as a normal import.
14
+ - The `kitcore/coreOptions` configuration entry now accepts a
15
+ `logDeprecation` handler, called on every invocation of a deprecated
16
+ method. The default logs a warning once per process.
17
+ - `defineHook`, a new plugin kind that attaches behavior to methods:
18
+ `observe` runs `onMethodStart` / `onMethodEnd` observers over every method
19
+ call, and `wrap` is targeted, contract-preserving middleware over a direct
20
+ import (a `{ imports, input, state, next }` bag).
21
+ - Every plugin can declare `dispose` beside `setup`. `disposeSdk(sdk,
22
+ input?)` runs them in reverse build order — call it to release what your
23
+ plugins acquired (timers, listeners). Idempotent; failures aggregate into
24
+ `CoreDisposeError`.
25
+ - `resolvePlugin(sdk, ref)` reads a plugin binding off a built sdk, for
26
+ infrastructure code that can't declare `imports`.
27
+ - `PluginSurface<typeof plugin>` derives the surface a plugin contributes
28
+ (method callable, property value, or an aggregate's bindings), so you don't
29
+ hand-write provides types. The `PluginSummary` / `LeafSummary` ledger types
30
+ are exported alongside it, so a package that exports plugins can emit their
31
+ inferred descriptor types — completeness ledger included — in its
32
+ declarations.
33
+ - Raw-output methods now get the full method boundary — input validation
34
+ branded through your `adaptError`, lifecycle hooks — while staying
35
+ synchronous.
36
+ - Object parameters resolve more naturally in interactive mode: an optional
37
+ object sits behind one entry question (declining skips its field fetch),
38
+ required fields come first, and the remaining optionals are offered as a
39
+ batch. A nested field's `requireParameters` can now name top-level
40
+ parameters. `collection` questions carry `container: "array" | "object"`;
41
+ hosts that render `message` + `actions` generically need no changes.
42
+
43
+ Breaking:
44
+ - `definePlugin`'s `middleware` map is removed. Declare a `defineHook` with
45
+ `wrap` instead.
46
+ - `listItems` is required on dynamic resolvers: a dynamic resolver IS a
47
+ candidate-lister. For a free-text field, use `type: "static"`.
48
+ - On `collection` questions, `count` and `min` are now optional (present on
49
+ array decisions only, absent on the new object gates). A host reading
50
+ `question.count` unconditionally must handle `undefined`.
51
+
52
+ Deprecated (runtime warnings now, removal in a later release):
53
+ `createPluginStack`, `createPluginMethod`, `createPaginatedPluginMethod`,
54
+ `createCorePlugin`, `fromFunctionPlugin`, `defineLegacyMerge`, and the
55
+ function form of `definePlugin`. Author with `defineMethod` /
56
+ `defineProperty` / `definePlugin({ ... })` and build with `createSdk`.
57
+
58
+ Fixed: an sdk built by one bundled copy of kitcore is now readable by another
59
+ copy's `getContext` / `resolvePlugin` (the context key moved to the global
60
+ symbol registry).
61
+
62
+ ## 0.4.0
63
+
64
+ ### Minor Changes
65
+
66
+ - 5e2cf0d: Add the resolution controller: a sibling layer over a built SDK that completes a method's partial input into a fully validated one, interacting with a host only when needed. `createController(sdk)` exposes a wizard face (`resolve` / `start` / `step` over a serializable protocol) and a serializable reflection face (`listMethods` / `getMethod` / `listChoices`) that projects the registry to plain JSON (JSON Schema types, positional, output) without leaking zod. Adds the `defineResolver` authoring API and the signal hierarchy (`CoreSignal`, `CoreCancelledSignal`, `isCoreSignal`).
67
+
68
+ ## 0.3.0
69
+
70
+ ### Minor Changes
71
+
72
+ - f5466d7: Publish kitcore publicly as `@zapier/kitcore`.
73
+
74
+ The package was previously private and internal-only. It is now published under the `@zapier` scope. It remains bundled into `@zapier/zapier-sdk` (unchanged); this additionally makes it available as a standalone package.
75
+
76
+ ## 0.2.0
77
+
78
+ ### Minor Changes
79
+
80
+ - b8ff1dd: Refactor the SDKs onto kitcore's new internal plugin model.
81
+
82
+ kitcore (an internal building block) gained a new plugin model, and the SDKs were rebuilt on it behind a compatibility bridge, so existing behavior is unchanged. The only changes to the published packages' surface:
83
+ - Removed the deprecated `sdk.addPlugin(...)` chain method (and the `WithAddPlugin` type / chain-style no-arg `createSdk()` doorway). Extend a built SDK with the top-level `addPlugin(sdk, plugin)` instead.
84
+ - `@zapier/zapier-sdk` now re-exports the plugin-authoring helpers (`createSdk`, `defineMethod` / `definePlugin` / `declareMethod` / etc., `selectExports`, `addPlugin`). Note `createSdk` reuses the old doorway's name but now takes a root plugin, so a stale no-arg `createSdk()` call is a compile error rather than silent misbehavior.
85
+
86
+ ## 0.1.0
87
+
88
+ ### Minor Changes
89
+
90
+ - 571f90d: Add zapier-sdk-package-operation header to identify the caller operation
91
+
92
+ ## 0.0.1
93
+
94
+ ### Patch Changes
95
+
96
+ - da80c77: Fix paginated list results silently truncating to page 1 when the same result is consumed twice (iterating pages then `.items()`, `.items()` then pages, or iterating either one twice). Pages and items are now two views over one page stream, so consuming either drains the other: the second view yields nothing instead of silently replaying page 1. A paginated result is consumed once; call the method again for a fresh result. Awaiting the result to read just the first page is unaffected: it is a repeatable peek that does not start the stream, so awaiting and then iterating still works.
package/LICENSE ADDED
@@ -0,0 +1,2 @@
1
+ Copyright (c) Zapier, Inc.
2
+ The Zapier SDK is part of Zapier's services. By downloading, installing, accessing, or using any part of the Zapier SDK you agree to the Zapier Terms of Service, which can be found at: https://zapier.com/tos, or such other agreement between you and Zapier governing Zapier services (as applicable). If you do not agree to the Zapier Terms of Service (or do not have another governing agreement in place with Zapier), you may not download, install, access, or use the Zapier SDK.
package/README.md CHANGED
@@ -1,5 +1,429 @@
1
1
  # @zapier/kitcore
2
2
 
3
- Placeholder release that reserves the `@zapier/kitcore` name on the registry with public access.
3
+ A TypeScript framework for building plugin-driven SDKs.
4
4
 
5
- Install the latest published version for actual usage.
5
+ kitcore lets you assemble an SDK out of small, independent units called **plugins**. A plugin is shaped like an ES module: it has an identity, declares the other plugins it **imports**, and **exports** named members. You compose plugins by importing and re-exporting them, and `createSdk` materializes the whole graph into a finished, fully typed SDK object.
6
+
7
+ The design goals:
8
+
9
+ - **Fully typed authoring.** Inside a method, both its private `state` and its `imports` are inferred with no manual annotations.
10
+ - **Introspectable without running anything.** A plugin's contract (its methods, input schemas, output modes, metadata) is plain data, so a CLI, MCP server, or docs generator can walk it without invoking your code.
11
+ - **Low ceremony.** No base classes, no decorators, no DI container. You write functions and arrays.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install @zapier/kitcore zod
17
+ ```
18
+
19
+ `zod` is a peer dependency (used for input validation and schema-driven typing).
20
+
21
+ ## Quick start
22
+
23
+ The smallest SDK is a single method. `defineMethod` describes it; `createSdk` builds it.
24
+
25
+ ```ts
26
+ import { z } from "zod";
27
+ import { defineMethod, createSdk } from "@zapier/kitcore";
28
+
29
+ const greet = defineMethod({
30
+ name: "greet",
31
+ inputSchema: z.object({ name: z.string() }),
32
+ run: ({ input }) => `Hi ${input.name}`,
33
+ });
34
+
35
+ const sdk = createSdk(greet);
36
+ sdk.greet({ name: "Ada" }); // "Hi Ada"
37
+ ```
38
+
39
+ `inputSchema` is optional. When present it validates the call at the boundary and types `input` for you, so `run` needs no annotations.
40
+
41
+ ## Plugins are modules
42
+
43
+ There are four kinds of plugin, and an SDK is just a materialized plugin:
44
+
45
+ - **Method** (`defineMethod`) — a leaf that _is_ a function.
46
+ - **Property** (`defineProperty`) — a leaf that _is_ a value.
47
+ - **Hook** (`defineHook`) — a leaf contributing cross-cutting behavior (see [Hooks](#hooks-wrap-and-observe)).
48
+ - **Aggregate** (`definePlugin`) — re-exports other plugins under binding names.
49
+
50
+ A plugin declares `imports` (an array of the plugins it depends on) and receives them as a flat `imports` bag, with each import bound under its own name. The two ends share the word the way ES modules do: `import { x } from "y"` is the declaration, `x` is the binding.
51
+
52
+ ```ts
53
+ const transport = defineMethod({
54
+ name: "transport",
55
+ run: ({ input }) => fetch(input.url),
56
+ });
57
+
58
+ const getUser = defineMethod({
59
+ name: "getUser",
60
+ imports: [transport], // depend on transport
61
+ run: ({ imports, input }) => imports.transport({ url: `/users/${input.id}` }),
62
+ });
63
+ ```
64
+
65
+ Importing a plugin pulls it into the graph but keeps it private. It only becomes part of the SDK surface if an aggregate **exports** it.
66
+
67
+ ## Composing an SDK
68
+
69
+ `definePlugin` builds an aggregate. Its `exports` array decides the public surface: a leaf binds under its own name, and a nested aggregate spreads its bindings.
70
+
71
+ ```ts
72
+ import { definePlugin, createSdk } from "@zapier/kitcore";
73
+
74
+ const api = definePlugin({
75
+ name: "api",
76
+ exports: [getUser, fetch], // surface getUser + fetch; transport stays private
77
+ });
78
+
79
+ const sdk = createSdk(api);
80
+ sdk.getUser({ id: 1 });
81
+ sdk.fetch(url);
82
+ sdk.transport; // undefined — imported by getUser, never exported
83
+ ```
84
+
85
+ ### Subsetting and renaming with `selectExports`
86
+
87
+ `selectExports` is the `{ a, b as c }` clause. It picks a subset of a module's exports and optionally renames them. It works the same on the `exports` side (what you re-export) and the `imports` side (what a body sees).
88
+
89
+ ```ts
90
+ import { selectExports } from "@zapier/kitcore";
91
+
92
+ const sdk = createSdk(
93
+ definePlugin({
94
+ name: "users",
95
+ // re-export getUser under its own name, and listUsers as `listAll`
96
+ exports: [selectExports(users, "getUser", { listAll: "listUsers" })],
97
+ }),
98
+ );
99
+ sdk.getUser({ id: 1 });
100
+ sdk.listAll();
101
+ ```
102
+
103
+ If two different plugins try to bind the same name, kitcore throws and points you at `selectExports` to rename one. Composition is dependency-based, so registration order never matters.
104
+
105
+ ## State and effects: `setup`
106
+
107
+ `setup` is a per-build constructor. It runs once when `createSdk` materializes the plugin (dependencies first), may perform side effects, and returns private state handed to `run` as `bag.state`.
108
+
109
+ ```ts
110
+ const counter = defineMethod({
111
+ name: "next",
112
+ setup: () => ({ n: 0 }), // runs once at createSdk
113
+ run: ({ state }) => ++state.n, // same state across calls
114
+ });
115
+
116
+ const sdk = createSdk(counter);
117
+ sdk.next(); // 1
118
+ sdk.next(); // 2
119
+ ```
120
+
121
+ `setup` can read `imports`, so state can be built from dependencies. Because state lives behind `setup`, several small "state plugins" can each own a slice instead of one monolith.
122
+
123
+ ## Properties
124
+
125
+ A property is a value rather than a function. It can be a static `value`, or a **live** `get` re-derived on every read, with an optional `setup` building the state `get` returns. So `setup` + `get` mirrors a method's `setup` + `run`.
126
+
127
+ ```ts
128
+ import { defineProperty } from "@zapier/kitcore";
129
+
130
+ // static value
131
+ const version = defineProperty({ name: "version", value: "1.0.0" });
132
+
133
+ // built once, returned live
134
+ const apps = defineProperty({
135
+ name: "apps",
136
+ imports: [runAction, fetch],
137
+ setup: ({ imports }) => buildAppsProxy(imports), // once at createSdk
138
+ get: ({ state }) => state, // returned per read
139
+ });
140
+ ```
141
+
142
+ Use `setup` + `get` when construction is expensive and should happen once; compute directly in `get` (no `setup`) when the value is cheap and you want it fresh on each access.
143
+
144
+ ## Sharing state between plugins
145
+
146
+ State doesn't have to live inside one plugin. A property whose `setup` builds a value once becomes a small **state plugin**: every plugin that imports it receives the same instance, so state is shared without a global or a monolithic context object.
147
+
148
+ ```ts
149
+ // A state plugin: one Map, built once at createSdk.
150
+ const cache = defineProperty({
151
+ name: "cache",
152
+ setup: () => new Map<string, unknown>(),
153
+ get: ({ state }) => state, // every importer gets the same Map
154
+ });
155
+
156
+ const write = defineMethod({
157
+ name: "write",
158
+ imports: [cache],
159
+ run: ({ imports, input }) => imports.cache.set(input.key, input.value),
160
+ });
161
+
162
+ const read = defineMethod({
163
+ name: "read",
164
+ imports: [cache],
165
+ run: ({ imports, input }) => imports.cache.get(input.key),
166
+ });
167
+
168
+ const sdk = createSdk(definePlugin({ name: "store", exports: [write, read] }));
169
+ sdk.write({ key: "a", value: 1 });
170
+ sdk.read({ key: "a" }); // 1 — the same Map, shared across both methods
171
+ ```
172
+
173
+ Prefer several focused state plugins over one big shared object: each owns a slice, dependents declare exactly the state they touch, and you can swap or mock one slice in tests without disturbing the rest.
174
+
175
+ ## Output modes
176
+
177
+ A method's `output` mode shapes what `run` returns into the public surface:
178
+
179
+ ```ts
180
+ // raw (default): the surface is whatever run returns
181
+ const transport = defineMethod({
182
+ name: "transport",
183
+ run: ({ input }) => fetch(input.url),
184
+ });
185
+
186
+ // item: run returns the value; the framework wraps it in { data }
187
+ const getApp = defineMethod({ name: "getApp", output: "item", run: () => app });
188
+ const { data } = await sdk.getApp({ app: "slack" });
189
+
190
+ // list: run returns one page; the surface is a paginated iterable
191
+ const listApps = defineMethod({
192
+ name: "listApps",
193
+ output: { type: "list", adaptPage, defaultPageSize: 100 },
194
+ run: ({ input }) => api.get("/apps", { offset: input.cursor }),
195
+ });
196
+ for await (const app of sdk.listApps().items()) {
197
+ /* every app across pages */
198
+ }
199
+ ```
200
+
201
+ ### Positional methods
202
+
203
+ By default a method takes a single options object. `positional` projects named input keys onto an ordered argument list for the public call, while validation, middleware, and `run` still see the canonical `{ input }`.
204
+
205
+ ```ts
206
+ const fetchMethod = defineMethod({
207
+ name: "fetch",
208
+ inputSchema: z.object({ url: z.string(), init: z.object({}).optional() }),
209
+ positional: ["url", "init"],
210
+ run: ({ input }) => doFetch(input.url, input.init),
211
+ });
212
+ sdk.fetch("https://example.com", { method: "GET" });
213
+ ```
214
+
215
+ ## Hooks: wrap and observe
216
+
217
+ Cross-cutting behavior lives in a **hook** (`defineHook`), a fourth kind of leaf with two faces.
218
+
219
+ `wrap` is targeted middleware. An entry is keyed by the import binding it wraps and receives `{ imports, next, input }`. It must preserve the target's contract (enforced by the types), so it cannot change the public signature.
220
+
221
+ ```ts
222
+ import { defineHook } from "@zapier/kitcore";
223
+
224
+ const auth = defineHook({
225
+ name: "auth",
226
+ imports: [transport, credentials],
227
+ wrap: {
228
+ transport: ({ imports, next, input }) =>
229
+ next({
230
+ ...input,
231
+ headers: withAuth(input.headers, imports.credentials()),
232
+ }),
233
+ },
234
+ });
235
+
236
+ const retry = defineHook({
237
+ name: "retry",
238
+ imports: [transport, auth], // import auth so retry nests around it
239
+ wrap: { transport: ({ next, input }) => withRetry(() => next(input)) },
240
+ });
241
+ ```
242
+
243
+ A method that imports `transport` knows nothing about `auth` or `retry`; it just calls `imports.transport(...)` and the chain runs automatically. Nesting follows the dependency edges (`retry` imports `auth`, so it wraps around it), not registration order, and `next(input)` runs the next layer.
244
+
245
+ `observe` is fire-and-forget: `onMethodStart` / `onMethodEnd` observers that the method boundary fires around every SDK method (`input` carries the lifecycle context: `methodName`, `args`, `durationMs`, `error`, ...). Observers run defensively, so a throwing observer never breaks the observed call, and an observer that itself calls SDK methods does not re-trigger itself. `setup` gives the hook private state, delivered to each observer.
246
+
247
+ ```ts
248
+ const telemetry = defineHook({
249
+ name: "telemetry",
250
+ setup: () => ({ events: [] as string[] }),
251
+ observe: {
252
+ onMethodEnd: ({ input, state }) =>
253
+ state.events.push(`${input.methodName}:${input.error ? "err" : "ok"}`),
254
+ },
255
+ });
256
+ ```
257
+
258
+ A hook joins the graph like any other plugin: import or export it from an aggregate.
259
+
260
+ ## Dependency injection
261
+
262
+ A plugin "names what it needs and receives it" without knowing who supplied it. That makes test doubles and configured providers trivial: register a real implementation under the same id and dependents get it transparently. This is the normal way one plugin reaches another, import the plugin, read it from the `imports` bag.
263
+
264
+ ### Configuration
265
+
266
+ Runtime values (an options object, a configured client) enter through `createSdk`'s `configuration` map, keyed by plugin id. Each entry materializes as a value property with that id, satisfying a `declareProperty` / `declareOptionalProperty` stand-in — so plugins read configuration through `imports` like any other dependency, and tests inject doubles the same way.
267
+
268
+ ```ts
269
+ import { declareOptionalProperty } from "@zapier/kitcore";
270
+
271
+ const configRef = declareOptionalProperty<"config", { pageSize?: number }>({
272
+ id: "config",
273
+ });
274
+
275
+ const listThings = defineMethod({
276
+ name: "listThings",
277
+ imports: [configRef],
278
+ run: ({ imports }) => api.list({ pageSize: imports.config?.pageSize ?? 10 }),
279
+ });
280
+
281
+ const sdk = createSdk(listThings, {
282
+ configuration: { config: { pageSize: 50 } },
283
+ });
284
+ ```
285
+
286
+ ## Extending a built SDK
287
+
288
+ `addPlugin` materializes a plugin into an already-built SDK in place. A TypeScript assertion-function signature widens the existing binding to include the new plugin's contributions, so you don't need a new variable.
289
+
290
+ ```ts
291
+ import { addPlugin } from "@zapier/kitcore";
292
+
293
+ addPlugin(sdk, defineMethod({ name: "ping", run: () => "pong" }));
294
+ sdk.ping(); // "pong", typed
295
+ ```
296
+
297
+ ## Teardown
298
+
299
+ `dispose` is `setup`'s dual: a leaf that owns a resource declares one, receiving `{ imports, state, input }`. `disposeSdk(sdk, input?)` runs every disposer in reverse build order (dependents before their dependencies) and is idempotent; `input` is forwarded to each disposer (e.g. `{ exitCode }` from a CLI shutdown).
300
+
301
+ ```ts
302
+ import { disposeSdk } from "@zapier/kitcore";
303
+
304
+ const emitter = defineProperty({
305
+ name: "emitter",
306
+ setup: () => createEmitter(),
307
+ get: ({ state }) => state,
308
+ dispose: ({ state }) => state.close(),
309
+ });
310
+
311
+ // at shutdown
312
+ await disposeSdk(sdk, { exitCode: 0 });
313
+ ```
314
+
315
+ ## Introspection
316
+
317
+ Re-export the built-in `getRegistryPlugin` to put a `getRegistry()` method on the SDK. It reports the live surface as plain data (one entry per binding, with the leaf's metadata), which is what drives generated docs, CLI commands, and MCP tools.
318
+
319
+ ```ts
320
+ import { getRegistryPlugin } from "@zapier/kitcore";
321
+
322
+ const sdk = createSdk(
323
+ definePlugin({ name: "api", exports: [greet, getRegistryPlugin] }),
324
+ );
325
+
326
+ const registry = sdk.getRegistry();
327
+ registry.functions; // [{ name, description, inputSchema, ... }]
328
+ registry.categories; // grouped for menus / docs
329
+ ```
330
+
331
+ Because the registry reads the surface at call time, it also reflects anything added later with `addPlugin`.
332
+
333
+ ## Resolving inputs: controllers
334
+
335
+ A method's `inputSchema` says what a complete call looks like, but a caller often starts with only part of it. A **resolution controller** is a sibling layer over a built SDK that turns a partial input into a complete, validated one, asking a host (a CLI prompt, a web form, an agent) for each missing piece only when it has to. The SDK surface is untouched; the controller reads its schemas and resolvers and drives them.
336
+
337
+ You make a parameter resolvable by attaching a `defineResolver` to it on the method. A resolver can offer a static enum (derived from the schema), fetch a dynamic list (with pagination and search), resolve without a prompt (a configured default), or describe an object/array to fill in field by field.
338
+
339
+ ```ts
340
+ import { defineMethod, defineResolver, createSdk } from "@zapier/kitcore";
341
+
342
+ const appResolver = defineResolver({
343
+ // a paginated, searchable picker
344
+ listItems: ({ input, search, cursor }) => api.listApps({ search, cursor }),
345
+ prompt: ({ items }) => ({
346
+ message: "Which app?",
347
+ choices: items.map((a) => ({ label: a.title, value: a.key })),
348
+ }),
349
+ });
350
+
351
+ const runAction = defineMethod({
352
+ name: "runAction",
353
+ inputSchema: z.object({ app: z.string(), action: z.string() }),
354
+ resolvers: { app: appResolver },
355
+ run: ({ input }) => api.run(input),
356
+ });
357
+ ```
358
+
359
+ `createController(sdk)` exposes two faces over the same engine.
360
+
361
+ ### Wizard face: `resolve`
362
+
363
+ `resolve` is in-process sugar: it loops the resolution against an `answer` callback and returns the finished input. The callback's only job is to render a question and return the chosen action; all resolution logic (fetching, pagination, search, validation, nesting) stays in the engine.
364
+
365
+ ```ts
366
+ const controller = createController(sdk);
367
+
368
+ const input = await controller.resolve({
369
+ method: "runAction",
370
+ input: { action: "send_message" }, // seed what you already have
371
+ answer: async ({ state, result }) => {
372
+ // render result.question (a select / input / collection) however you like,
373
+ // then map the user's choice back to an action:
374
+ return { type: "choose", value: "slack" };
375
+ },
376
+ });
377
+
378
+ await sdk.runAction(input); // complete + validated
379
+ ```
380
+
381
+ ### Serializable protocol: `start` / `step`
382
+
383
+ For a host that spans a client/server boundary (web, agent, MCP), drive the protocol directly. `start` returns the first `{ state, result }`; you render `result`, then send the user's action plus the `state` back through `step`. `state` is plain JSON, so it round-trips over the wire with no live objects to keep alive between turns.
384
+
385
+ ```ts
386
+ let { state, result } = await controller.start({ method: "runAction" });
387
+ while (result.status === "ask") {
388
+ const action = await renderAndCollect(result.question); // your host
389
+ ({ state, result } = await controller.step({ state, action }));
390
+ }
391
+ // result.status is now "done" | "invalid" | "cancelled"
392
+ ```
393
+
394
+ ### Reflection face: `describe` / `listChoices`
395
+
396
+ For a form-style host that renders every field up front instead of one question at a time, `describe` returns the static shape of a method's inputs (required-ness, value type, which are dynamic, their dependencies), and `listChoices` enumerates the legal values for one dynamic parameter.
397
+
398
+ ```ts
399
+ controller.describe({ method: "runAction" });
400
+ // { app: { required: true, dynamic: true }, action: { required: true, ... } }
401
+
402
+ await controller.listChoices({
403
+ method: "runAction",
404
+ parameter: "app",
405
+ search: "sl",
406
+ });
407
+ // { data: [{ label: "Slack", value: "slack" }], nextCursor }
408
+ ```
409
+
410
+ ## Stand-ins
411
+
412
+ When a plugin depends on something supplied elsewhere (a configured client, a test double), declare a typed stand-in with `declareMethod` / `declareProperty` (a single leaf) or `declarePlugin` (a whole module, with its export surface declared as leaf stand-ins). Dependents reference it for typing; at `createSdk` it is satisfied by whatever real plugin is registered under the same id, and an unsatisfied stand-in is a **compile-time** error (with a runtime backstop). You reference a stand-in by `id` (`namespace/name`, or a bare name), and the contract is provided as explicit type arguments (`declareMethod<"fetch", Input, Output>({ id: "fetch" })`), because the id must be a literal the dependency ledger can read. The binding is the id's last segment.
413
+
414
+ ## Namespaces
415
+
416
+ Plugin ids are `name` by default, or `namespace/name` when you set the optional `namespace` field. Namespacing lets two packages define a plugin with the same bare name without their ids colliding; the surface and imports stay bare-named, so consumers are unaffected.
417
+
418
+ ```ts
419
+ const greet = defineMethod({
420
+ name: "greet",
421
+ namespace: "acme",
422
+ run: () => "hi",
423
+ });
424
+ // id is "acme/greet"; sdk.greet() is still the call
425
+ ```
426
+
427
+ ## Status
428
+
429
+ Pre-release. The public surface is being stabilized as part of an extraction from [`@zapier/zapier-sdk`](https://www.npmjs.com/package/@zapier/zapier-sdk). Until a `1.0.0` release, expect breaking changes between minor versions.