@capacms/sdk 1.0.0-next.10 → 1.0.0-next.12

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +170 -0
  2. package/README.md +368 -5
  3. package/bin/capa-check-bundle.js +80 -0
  4. package/bin/capa.js +3 -3
  5. package/bin/graphql-project.js +1 -1
  6. package/dist/client.d.ts +84 -4
  7. package/dist/client.js +23 -5
  8. package/dist/esm/image/index.d.ts +69 -2
  9. package/dist/esm/image/index.js +108 -5
  10. package/dist/esm/image/shared-params.generated.d.ts +126 -2
  11. package/dist/esm/image/shared-params.generated.js +224 -5
  12. package/dist/esm/overlay/index.d.ts +4 -1
  13. package/dist/esm/overlay/index.js +382 -30
  14. package/dist/esm/overlay/live-fields.d.ts +133 -0
  15. package/dist/esm/overlay/live-fields.js +478 -0
  16. package/dist/esm/overlay/markdown.d.ts +38 -0
  17. package/dist/esm/overlay/markdown.js +536 -0
  18. package/dist/esm/overlay/protocol.d.ts +51 -5
  19. package/dist/esm/overlay/protocol.js +79 -9
  20. package/dist/image/index.d.ts +69 -2
  21. package/dist/image/index.js +109 -4
  22. package/dist/image/shared-params.generated.d.ts +126 -2
  23. package/dist/image/shared-params.generated.js +235 -6
  24. package/dist/index.d.ts +1 -1
  25. package/dist/next/attrs.d.ts +42 -1
  26. package/dist/next/attrs.js +42 -3
  27. package/dist/next/client.d.ts +48 -1
  28. package/dist/next/client.js +33 -2
  29. package/dist/next/entry-fields.d.ts +43 -2
  30. package/dist/next/graphql/request.d.ts +4 -0
  31. package/dist/next/graphql/request.js +4 -0
  32. package/dist/next/graphql/tree.js +9 -0
  33. package/dist/next/index.d.ts +4 -4
  34. package/dist/next/index.js +3 -1
  35. package/dist/nextjs/index.d.ts +91 -7
  36. package/dist/nextjs/index.js +230 -17
  37. package/dist/nextjs/write-key-guard.d.ts +117 -0
  38. package/dist/nextjs/write-key-guard.js +285 -0
  39. package/dist/overlay/index.d.ts +4 -1
  40. package/dist/overlay/index.js +399 -29
  41. package/dist/overlay/live-fields.d.ts +133 -0
  42. package/dist/overlay/live-fields.js +493 -0
  43. package/dist/overlay/markdown.d.ts +38 -0
  44. package/dist/overlay/markdown.js +539 -0
  45. package/dist/overlay/protocol.d.ts +51 -5
  46. package/dist/overlay/protocol.js +82 -9
  47. package/dist/server/browser.d.ts +1 -0
  48. package/dist/server/browser.js +20 -0
  49. package/dist/server/client.d.ts +268 -0
  50. package/dist/server/client.js +335 -0
  51. package/dist/server/errors.d.ts +60 -0
  52. package/dist/server/errors.js +120 -0
  53. package/dist/server/index.d.ts +14 -0
  54. package/dist/server/index.js +32 -0
  55. package/dist/server/key-format.d.ts +41 -0
  56. package/dist/server/key-format.js +91 -0
  57. package/dist/server/transport.d.ts +47 -0
  58. package/dist/server/transport.js +114 -0
  59. package/dist/webhooks.d.ts +8 -0
  60. package/package.json +18 -4
@@ -1,24 +1,34 @@
1
1
  "use strict";
2
2
  /**
3
3
  * The live preview protocol, site side. Pure: no DOM, no globals, so it can be
4
- * tested under plain `node --test`.
4
+ * tested under plain `node --test`. Its one import, `./live-fields.js`, is
5
+ * pure too.
5
6
  *
6
7
  * The Capa admin frames the site and the two talk over `postMessage`. Every
7
8
  * message is a plain object `{ source, v: 1, type, ...fields }`:
8
9
  *
9
10
  * admin -> site (source "capa-admin")
10
11
  * hello {} sent on the frame's load
11
- * highlight { entryId, field: string | null } entryId "" clears
12
+ * highlight { entryId, field: string | null, item? }
13
+ * entryId "" clears. `item`: one item
14
+ * of a list field (`data-capa-item`)
12
15
  * outline { on: boolean } outline every tagged element
13
16
  * refresh {} re-render the draft
14
17
  * patch { entryId, fields: [{ field, value, saved }] }
15
18
  * unsaved text, as the editor types it
19
+ * fields { entryId, fields: [{ field, kind, value, saved }] }
20
+ * unsaved HTML and Rich Text, images,
21
+ * toggles and dates (`./live-fields.ts`).
22
+ * Sent only to an overlay whose ready
23
+ * lists "fields". A kind it does not
24
+ * know is skipped, the rest kept
16
25
  *
17
26
  * site -> admin (source "capa")
18
27
  * ready { path, entries, features } after hello, and after every navigation.
19
28
  * `features`: what this overlay can do
20
29
  * beyond v1 (`SITE_FEATURES`)
21
- * select { entryId, field } a tagged element was clicked
30
+ * select { entryId, field, item? } a tagged element was clicked. `item`:
31
+ * its `data-capa-item`, when it has one
22
32
  * hover { entryId, field } | { entryId: "", field: null }
23
33
  * visible { entryId, field } the tagged element at the centre of the
24
34
  * viewport changed (throttled, on scroll)
@@ -30,6 +40,15 @@
30
40
  * same kind of addition: an admin sends `patch` only to an overlay whose
31
41
  * `ready` lists "patch", and an older admin never reads `features`.
32
42
  *
43
+ * `item` is the same kind of addition, on two messages v1 already has. The
44
+ * site tags one item of a list (`capaAttrs(entry, "faqs", { item: 2 })`), a
45
+ * click reports it, and the editor opens that item rather than the top of
46
+ * the list. The editor sends it with a highlight only where the project has
47
+ * it on (`CAPA_PREVIEW_TARGETS`), and an overlay that does not read it
48
+ * outlines the whole field, as before. An item that is not a well-formed
49
+ * path (`isItemPath`) is dropped and the message kept: the field is still
50
+ * right.
51
+ *
33
52
  * A PATCH IS TEXT ONLY, and only where the page shows the field verbatim. The
34
53
  * overlay changes a tagged element's text while it reads exactly `saved` (the
35
54
  * value the page was rendered from) or what this page last patched it to, so
@@ -41,24 +60,42 @@
41
60
  */
42
61
  Object.defineProperty(exports, "__esModule", { value: true });
43
62
  exports.PATCH_MAX_LENGTH = exports.PATCH_MAX_FIELDS = exports.SITE_FEATURES = exports.SITE_SOURCE = exports.ADMIN_SOURCE = exports.PROTOCOL_VERSION = void 0;
63
+ exports.isItemPath = isItemPath;
44
64
  exports.normaliseOrigins = normaliseOrigins;
45
65
  exports.acceptMessage = acceptMessage;
46
66
  exports.patchedText = patchedText;
47
67
  exports.textAround = textAround;
48
68
  exports.readyMessage = readyMessage;
49
69
  exports.selectMessage = selectMessage;
70
+ exports.itemMatches = itemMatches;
71
+ exports.itemLabel = itemLabel;
50
72
  exports.hoverMessage = hoverMessage;
51
73
  exports.visibleMessage = visibleMessage;
52
74
  exports.pickCentred = pickCentred;
53
75
  exports.scrollEdge = scrollEdge;
76
+ const live_fields_js_1 = require("./live-fields.js");
54
77
  exports.PROTOCOL_VERSION = 1;
55
78
  exports.ADMIN_SOURCE = "capa-admin";
56
79
  exports.SITE_SOURCE = "capa";
57
- /** What this overlay can do beyond v1, listed in its `ready`. */
58
- exports.SITE_FEATURES = ["patch"];
80
+ /**
81
+ * What this overlay can do beyond v1, listed in its `ready`. `release`: this
82
+ * SDK sends a release preview's token on its reads (`Capa-Release`), so the
83
+ * admin can tell a site that shows a release from one that shows every draft.
84
+ */
85
+ exports.SITE_FEATURES = ["patch", "fields", "release"];
59
86
  /** A `patch` past these is refused whole: no form has that many text fields, or that much text in one. */
60
87
  exports.PATCH_MAX_FIELDS = 500;
61
88
  exports.PATCH_MAX_LENGTH = 100_000;
89
+ /**
90
+ * One item of a list field, as `data-capa-item` spells it: up to 16 segments
91
+ * joined with dots, each a whole number or a key of letters, digits, `_` and
92
+ * `-` (`2`, `2.question`). `itemPath` in `@capacms/sdk/next` writes it.
93
+ */
94
+ const ITEM_PATH = /^[A-Za-z0-9_-]{1,64}(\.[A-Za-z0-9_-]{1,64}){0,15}$/;
95
+ /** Whether a value is an item path an overlay sends and an editor reads. */
96
+ function isItemPath(value) {
97
+ return typeof value === "string" && value.length <= 1040 && ITEM_PATH.test(value);
98
+ }
62
99
  /**
63
100
  * `https://admin.example.com/` and `https://admin.example.com` are one origin,
64
101
  * and a configured value that is not a URL at all is dropped rather than
@@ -112,12 +149,17 @@ function acceptMessage(event, allowedOrigins, parent) {
112
149
  if (typeof m.on !== "boolean")
113
150
  return null;
114
151
  return { source: exports.ADMIN_SOURCE, v: 1, type: "outline", on: m.on };
115
- case "highlight":
152
+ case "highlight": {
116
153
  if (typeof m.entryId !== "string")
117
154
  return null;
118
155
  if (m.field !== null && typeof m.field !== "string")
119
156
  return null;
120
- return { source: exports.ADMIN_SOURCE, v: 1, type: "highlight", entryId: m.entryId, field: m.field };
157
+ const highlight = { source: exports.ADMIN_SOURCE, v: 1, type: "highlight", entryId: m.entryId, field: m.field };
158
+ // Optional: an item of the field, kept only when it is one (a clear has none).
159
+ if (m.entryId !== "" && m.field !== null && isItemPath(m.item))
160
+ highlight.item = m.item;
161
+ return highlight;
162
+ }
121
163
  case "patch": {
122
164
  if (typeof m.entryId !== "string" || m.entryId === "")
123
165
  return null;
@@ -138,6 +180,14 @@ function acceptMessage(event, allowedOrigins, parent) {
138
180
  }
139
181
  return { source: exports.ADMIN_SOURCE, v: 1, type: "patch", entryId: m.entryId, fields };
140
182
  }
183
+ case "fields": {
184
+ if (typeof m.entryId !== "string" || m.entryId === "")
185
+ return null;
186
+ const fields = (0, live_fields_js_1.acceptLiveFields)(m.fields);
187
+ if (fields === null)
188
+ return null;
189
+ return { source: exports.ADMIN_SOURCE, v: 1, type: "fields", entryId: m.entryId, fields };
190
+ }
141
191
  default:
142
192
  return null;
143
193
  }
@@ -175,8 +225,31 @@ function readyMessage(path, entries, features) {
175
225
  ? { source: exports.SITE_SOURCE, v: 1, type: "ready", path, entries, features: [...features] }
176
226
  : { source: exports.SITE_SOURCE, v: 1, type: "ready", path, entries };
177
227
  }
178
- function selectMessage(entryId, field) {
179
- return { source: exports.SITE_SOURCE, v: 1, type: "select", entryId, field };
228
+ /** A click on a tagged element, with its list item when it names a well-formed one. */
229
+ function selectMessage(entryId, field, item) {
230
+ return isItemPath(item)
231
+ ? { source: exports.SITE_SOURCE, v: 1, type: "select", entryId, field, item }
232
+ : { source: exports.SITE_SOURCE, v: 1, type: "select", entryId, field };
233
+ }
234
+ /**
235
+ * Whether an element's `data-capa-item` is the item asked for, or inside it:
236
+ * `2.question` is in item `2`. Pure, so the overlay's matching is tested
237
+ * without a DOM.
238
+ */
239
+ function itemMatches(tagged, wanted) {
240
+ if (typeof tagged !== "string")
241
+ return false;
242
+ return tagged === wanted || tagged.startsWith(`${wanted}.`);
243
+ }
244
+ /**
245
+ * The label the overlay draws for an item: "faqs › item 3" for an index,
246
+ * which counts from one as an editor does, "faqs › question" for a key.
247
+ */
248
+ function itemLabel(field, item) {
249
+ if (!isItemPath(item))
250
+ return field;
251
+ const parts = item.split(".").map((part) => (/^\d+$/.test(part) ? `item ${Number(part) + 1}` : part));
252
+ return `${field} › ${parts.join(" › ")}`;
180
253
  }
181
254
  function hoverMessage(entryId, field) {
182
255
  return entryId === ""
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * browser.ts — what `@capacms/sdk/server` resolves to under a bundler's
5
+ * `browser` condition: an import that throws.
6
+ *
7
+ * A write key works from a server only, and the write host turns off a key a
8
+ * browser sends. So when a client bundle imports the server entry (a
9
+ * `"use client"` component, a Vite or webpack browser build), the module
10
+ * fails the moment the page loads it, with a message that says why, instead
11
+ * of only when a write is attempted.
12
+ *
13
+ * Server and edge builds never get here: package.json lists `edge-light`,
14
+ * `workerd`, `worker`, `react-server` and `node` before `browser`, so Next's
15
+ * edge runtime, Cloudflare Workers, server components and Node all resolve
16
+ * the real client.
17
+ */
18
+ throw new Error("@capacms/sdk/server is server only, and this bundle is for a browser. " +
19
+ "A write key sent from a browser is refused and the key is turned off. " +
20
+ "Import @capacms/sdk/server only from server code: a route handler, a server action, a server-only module or a script.");
@@ -0,0 +1,268 @@
1
+ export declare const DEFAULT_WRITE_BASE_URL = "https://write.capacms.com";
2
+ /** The write API versions this release of the SDK speaks. */
3
+ export type WriteApiVersion = "2026-10-01";
4
+ export declare const WRITE_API_VERSIONS: readonly WriteApiVersion[];
5
+ /**
6
+ * The default `maxRetryAfterSeconds`: the longest `Retry-After` the client
7
+ * waits out before its one retry. 10 seconds, so a serverless function with a
8
+ * short limit is not killed mid-wait. A longer wait throws at once.
9
+ */
10
+ export declare const MAX_RETRY_AFTER_SECONDS = 10;
11
+ export interface WriteClientConfig {
12
+ /** The `capw_` key. Read it from a server-only environment variable, never from code a browser loads. */
13
+ key: string;
14
+ /** The write API version, pinned in code: `"2026-10-01"`. */
15
+ version: WriteApiVersion;
16
+ /** The write host. Defaults to `https://write.capacms.com`. Must be https; plain http only for localhost, 127.0.0.1 and [::1]. */
17
+ baseUrl?: string;
18
+ /**
19
+ * A fetch to send with instead of the default (Node's `https` module on
20
+ * Node, the global fetch elsewhere). The write host refuses a request with
21
+ * an `Origin`, `Sec-Fetch-Site`, `Sec-Fetch-Dest` or `Cookie` header, so
22
+ * the fetch you pass must send none of those. Node's own fetch is fine: the
23
+ * `Sec-Fetch-Mode` it adds is not counted.
24
+ */
25
+ fetch?: typeof fetch;
26
+ /**
27
+ * How long one request may take, in milliseconds, before it is abandoned
28
+ * with `CapaWriteTimeoutError`. Default 30000. `0` waits as long as the
29
+ * transport does. Your own `signal` still aborts sooner.
30
+ */
31
+ timeoutMs?: number;
32
+ /**
33
+ * The longest `Retry-After`, in seconds, the client waits out before
34
+ * retrying a `429` once. Default 10. A longer one throws `rate_limited` at
35
+ * once, with `retryAfter` set; `0` never retries.
36
+ */
37
+ maxRetryAfterSeconds?: number;
38
+ }
39
+ /** The default `timeoutMs`: 30 seconds. */
40
+ export declare const DEFAULT_WRITE_TIMEOUT_MS = 30000;
41
+ /** What every request names itself as, so the key's activity shows which client wrote. */
42
+ export declare const WRITE_CLIENT_USER_AGENT = "capacms-sdk/server";
43
+ /** A field value as `/api/` reads it: a scalar, a relation or media as `{ id }`, or a list. */
44
+ export type WriteFieldValue = string | number | boolean | null | {
45
+ id: string;
46
+ } | ReadonlyArray<WriteFieldValue> | {
47
+ readonly [key: string]: unknown;
48
+ };
49
+ export type WriteFields = Record<string, WriteFieldValue | undefined>;
50
+ /** `changed` is a published entry with a newer draft, as `/api/` reports it. */
51
+ export type EntryStatus = "draft" | "published" | "changed";
52
+ /** An entry as the write host returns it, from a read and from every write. */
53
+ export interface WriteEntry<F = Record<string, unknown>> {
54
+ id: string;
55
+ /** The model's namespace. */
56
+ model: string;
57
+ status: EntryStatus;
58
+ /** The current (authored) values. */
59
+ fields: F;
60
+ versions: {
61
+ /** `number` is the `version` `/api/` reads report for the entry. Send it back as `ifMatch`. */
62
+ current: {
63
+ id: string;
64
+ number: number;
65
+ status: EntryStatus;
66
+ savedAt: string;
67
+ };
68
+ /** What is live, its values included. Null when nothing is published. */
69
+ published: {
70
+ id: string;
71
+ number: number;
72
+ publishedAt: string;
73
+ fields: F;
74
+ } | null;
75
+ };
76
+ }
77
+ export interface WriteMeta {
78
+ version: string;
79
+ requestId: string;
80
+ [key: string]: unknown;
81
+ }
82
+ export interface WriteSingle<T> {
83
+ data: T;
84
+ meta: WriteMeta;
85
+ }
86
+ export interface WritePageInfo {
87
+ limit: number;
88
+ hasNext: boolean;
89
+ next: string | null;
90
+ }
91
+ export interface WritePage<T> {
92
+ data: T[];
93
+ page: WritePageInfo;
94
+ meta: WriteMeta;
95
+ }
96
+ export type WriteKeyAction = "create" | "update" | "publish" | "delete";
97
+ /** `GET /me`: the project the key writes to, and the key. */
98
+ export interface WriteKeyInfo {
99
+ project: {
100
+ id: string;
101
+ name: string;
102
+ };
103
+ key: {
104
+ id: string;
105
+ name: string | null;
106
+ scopes: string[];
107
+ /** Each model the key reaches, by id and namespace, and what it may do there. */
108
+ models: Array<{
109
+ id: string;
110
+ namespace: string;
111
+ actions: WriteKeyAction[];
112
+ }>;
113
+ /** True when the key's scopes are not limited to models. */
114
+ allModels: boolean;
115
+ expiresAt: string;
116
+ allowedIps: string[] | null;
117
+ };
118
+ }
119
+ /** `dead` is a publish the worker gave up on after its retries. */
120
+ export type ScheduledActionStatus = "pending" | "running" | "done" | "failed" | "dead" | "cancelled";
121
+ export interface ScheduledAction {
122
+ id: string;
123
+ /** What it does, such as `publish`. */
124
+ action: string;
125
+ status: ScheduledActionStatus;
126
+ runAt: string;
127
+ timezone: string | null;
128
+ wallTime: string | null;
129
+ target: {
130
+ model: string;
131
+ id: string;
132
+ versionId: string | null;
133
+ };
134
+ requestedByKeyId: string | null;
135
+ createdAt: string;
136
+ /** The published copy's version id once a publish is `done`, else null. */
137
+ resultVersionId: string | null;
138
+ /** Why it `failed`, else null. */
139
+ lastError: {
140
+ code: string;
141
+ message: string;
142
+ } | null;
143
+ }
144
+ /** The `202` of a scheduled publish. */
145
+ export interface ScheduledPublish<F = Record<string, unknown>> {
146
+ action: {
147
+ id: string;
148
+ status: "pending";
149
+ runAt: string;
150
+ timezone: string | null;
151
+ wallTime: string | null;
152
+ /** The scheduler's resolution note, such as a daylight saving shift, or null. */
153
+ note: string | null;
154
+ };
155
+ /** The pending publishes of this entry that this one replaced. */
156
+ replaced: string[];
157
+ entry: WriteEntry<F>;
158
+ }
159
+ export interface CallOptions {
160
+ signal?: AbortSignal;
161
+ }
162
+ export interface WriteCallOptions extends CallOptions {
163
+ /** Sent as `Idempotency-Key`. A create sends a random UUID when this is not given. */
164
+ idempotencyKey?: string;
165
+ }
166
+ export interface ConditionalWriteOptions extends WriteCallOptions {
167
+ /** The entry version you read (`versions.current.number`), sent as `If-Match`. A newer version answers 412 `version_conflict`. */
168
+ ifMatch?: number;
169
+ }
170
+ export interface UnpublishOptions extends WriteCallOptions {
171
+ /**
172
+ * The published version you expect to take down, sent as `{ versionId }`.
173
+ * When another version is live, the host answers 412 `version_conflict`
174
+ * and nothing is taken down. Left out, whatever is live is unpublished.
175
+ */
176
+ versionId?: string;
177
+ }
178
+ export interface EntryWriteBody<F extends WriteFields = WriteFields> {
179
+ fields: F;
180
+ /**
181
+ * `draft` (the default) saves a draft version and leaves a published
182
+ * version live. `published` saves, then publishes what it saved, and needs
183
+ * `instance:publish` as well.
184
+ */
185
+ status?: "draft" | "published";
186
+ }
187
+ export interface ListEntriesOptions extends CallOptions {
188
+ /** Up to 200. */
189
+ limit?: number;
190
+ /** The cursor from the previous page's `page.next`. */
191
+ after?: string;
192
+ /** Equality on scalar fields, sent as `filter[field][eq]=value`. */
193
+ filter?: Record<string, string | number | boolean>;
194
+ }
195
+ /** Publish now: the current version, or `versionId`. */
196
+ export type PublishNowBody = {
197
+ versionId?: string;
198
+ at?: undefined;
199
+ wallTime?: undefined;
200
+ timezone?: undefined;
201
+ };
202
+ /**
203
+ * Schedule a publish: at an ISO instant, or at a wall time in a timezone.
204
+ * With `at`, `timezone` is optional and only names the zone the action is
205
+ * shown in (UTC when left out).
206
+ */
207
+ export type SchedulePublishBody = {
208
+ versionId?: string;
209
+ at: string;
210
+ wallTime?: undefined;
211
+ timezone?: string;
212
+ } | {
213
+ versionId?: string;
214
+ at?: undefined;
215
+ wallTime: string;
216
+ timezone: string;
217
+ };
218
+ export type PublishBody = PublishNowBody | SchedulePublishBody;
219
+ export interface ListScheduledActionsOptions extends CallOptions {
220
+ targetId?: string;
221
+ /** One status or several, sent comma-separated. */
222
+ status?: ScheduledActionStatus | readonly ScheduledActionStatus[];
223
+ /** Up to 200. */
224
+ limit?: number;
225
+ /** The cursor from the previous page's `page.next`. */
226
+ after?: string;
227
+ }
228
+ export interface WriteEntriesResource {
229
+ list<F = Record<string, unknown>>(model: string, options?: ListEntriesOptions): Promise<WritePage<WriteEntry<F>>>;
230
+ get<F = Record<string, unknown>>(model: string, id: string, options?: CallOptions): Promise<WriteSingle<WriteEntry<F>>>;
231
+ create<F extends WriteFields = WriteFields>(model: string, body: EntryWriteBody<F>, options?: WriteCallOptions): Promise<WriteSingle<WriteEntry>>;
232
+ /** Merge `fields` onto the current state: a key replaces, `null` clears, an absent key keeps. */
233
+ update<F extends WriteFields = WriteFields>(model: string, id: string, body: EntryWriteBody<Partial<F>>, options?: ConditionalWriteOptions): Promise<WriteSingle<WriteEntry>>;
234
+ /** Replace every field. */
235
+ replace<F extends WriteFields = WriteFields>(model: string, id: string, body: EntryWriteBody<F>, options?: ConditionalWriteOptions): Promise<WriteSingle<WriteEntry>>;
236
+ /**
237
+ * Publish now (`200`, the entry), or schedule it with `at` (an ISO
238
+ * instant) or `wallTime` plus `timezone` (`202`, the action, the pending
239
+ * publishes it replaced, and the entry). A version saved under an older
240
+ * model version is refused with 409 `stale_model_version`.
241
+ */
242
+ publish(model: string, id: string, body?: PublishNowBody, options?: WriteCallOptions): Promise<WriteSingle<WriteEntry>>;
243
+ publish(model: string, id: string, body: SchedulePublishBody, options?: WriteCallOptions): Promise<WriteSingle<ScheduledPublish>>;
244
+ publish(model: string, id: string, body?: PublishBody, options?: WriteCallOptions): Promise<WriteSingle<WriteEntry> | WriteSingle<ScheduledPublish>>;
245
+ /**
246
+ * Take the published version down. With `versionId`, only if that version
247
+ * is the live one: another live version is 412 `version_conflict`.
248
+ */
249
+ unpublish(model: string, id: string, options?: UnpublishOptions): Promise<WriteSingle<WriteEntry>>;
250
+ /** Soft delete. Needs `instance:delete`. */
251
+ delete(model: string, id: string, options?: ConditionalWriteOptions): Promise<void>;
252
+ }
253
+ export interface WriteScheduledActionsResource {
254
+ get(id: string, options?: CallOptions): Promise<WriteSingle<ScheduledAction>>;
255
+ list(options?: ListScheduledActionsOptions): Promise<WritePage<ScheduledAction>>;
256
+ cancel(id: string, options?: WriteCallOptions): Promise<WriteSingle<ScheduledAction>>;
257
+ }
258
+ export interface CapaWriteClient {
259
+ readonly baseUrl: string;
260
+ readonly version: WriteApiVersion;
261
+ /** `GET /me`: the project, and the key's id, name, scopes, models, expiry and allowed IPs. */
262
+ me(options?: CallOptions): Promise<WriteSingle<WriteKeyInfo>>;
263
+ entries: WriteEntriesResource;
264
+ scheduledActions: WriteScheduledActionsResource;
265
+ }
266
+ /** Whether this code runs where a browser would: `window` or `document` exists. */
267
+ export declare function inBrowser(): boolean;
268
+ export declare function createWriteClient(config: WriteClientConfig): CapaWriteClient;