@nohead/sdk 0.8.0 → 0.10.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.
@@ -1,5 +1,5 @@
1
1
  export type ClientOptions = {
2
- baseUrl: 'https://api.nohead.io' | 'http://localhost:3000' | (string & {});
2
+ baseUrl: 'https://api.nohead.io' | (string & {});
3
3
  };
4
4
  export type Webhooks = WebhookEventWebhookRequest;
5
5
  export type RequestId = string;
@@ -219,6 +219,9 @@ export type LongTextFieldConfiguration = {
219
219
  min_length?: number;
220
220
  max_length?: number;
221
221
  };
222
+ /**
223
+ * A rich text document up to 1,000,000 bytes (`too_large`), written as Markdown or a document (see `RecordData`).
224
+ */
222
225
  export type RichTextFieldConfiguration = {
223
226
  /**
224
227
  * Help text for editors.
@@ -388,6 +391,9 @@ export type RelationFieldConfiguration = {
388
391
  */
389
392
  target_collection_id: string;
390
393
  };
394
+ /**
395
+ * Any JSON value up to 100,000 bytes (`too_large`), nested at most 32 levels deep (`too_deep`): for data with a shape of its own, such as settings or another service's payload. Content belongs in typed fields, and large data in an asset.
396
+ */
391
397
  export type JsonFieldConfiguration = {
392
398
  /**
393
399
  * Help text for editors.
@@ -595,6 +601,9 @@ export type CollectionCreate = {
595
601
  slug: string;
596
602
  description?: string | null;
597
603
  public_search?: boolean;
604
+ /**
605
+ * At most 100 (`too_many`).
606
+ */
598
607
  fields?: Array<FieldCreate>;
599
608
  };
600
609
  export type CollectionUpdate = {
@@ -967,14 +976,38 @@ export type MergedDraft = {
967
976
  edited_by: Array<Actor>;
968
977
  };
969
978
  /**
970
- * Field values keyed by field `key`. A rich text value is a
971
- * ProseMirror/Tiptap JSON document (`{"type": "doc", "content": [...]}`).
972
- * An image of an asset in it is `{"type": "image", "attrs": {"asset_id":
973
- * "ast_...", "alt": "..."}}`, between the document's blocks (not inside
974
- * a list or quote), at most 100 per document (`too_many_images`); a
975
- * newly shown image must be an uploaded JPEG, PNG, GIF, WebP or AVIF of
976
- * the project (`invalid_reference`, `type_not_accepted`). `expand` embeds the assets, and published-only
977
- * keys can read the images of published records.
979
+ * Field values keyed by field `key`.
980
+ *
981
+ * A rich text value is written as Markdown (GitHub Flavored, a string)
982
+ * or as a ProseMirror JSON document (`{"type": "doc", "content": [...]}`),
983
+ * and stored and read as the document (`rich_text` reads it as HTML or
984
+ * Markdown). Markdown is converted as closely as the vocabulary allows:
985
+ * headings below h3 become h3, task list items plain items, footnotes and
986
+ * raw HTML text. A document uses the web editor's vocabulary (Tiptap's
987
+ * StarterKit and tables) and nothing else; another name is refused with
988
+ * `invalid_format`, naming ours where one fits (`strong` is `bold`):
989
+ *
990
+ * - blocks: `paragraph`, `heading` (`level` 1-3), `blockquote`,
991
+ * `bulletList` and `orderedList` (`start`, `type`) of `listItem`
992
+ * (starting with a paragraph), `codeBlock` (`language`),
993
+ * `horizontalRule`, and `table` of `tableRow` of `tableHeader` or
994
+ * `tableCell` (`colspan`, `rowspan`, `colwidth`, `align`); any block
995
+ * may have `dir` (`auto`, `ltr`, `rtl`);
996
+ * - inline: `text` (non-empty) and `hardBreak`;
997
+ * - marks on text: `bold`, `italic`, `strike`, `underline`, `code` (alone),
998
+ * and `link` (`href`, and `target`, `rel`, `class`, `title`); a link's
999
+ * `href` is an `http`, `https`, `mailto`, `tel` or relative URL.
1000
+ *
1001
+ * An image of an asset is `{"type": "image", "attrs": {"asset_id":
1002
+ * "ast_...", "alt": "..."}}` (in Markdown `![alt](ast_...)`, or the
1003
+ * asset's `image_url`), between the document's blocks (not inside a list,
1004
+ * quote or table), at most 100 per document (`too_many_images`); a newly
1005
+ * shown image must be an uploaded JPEG, PNG, GIF, WebP, AVIF or SVG of
1006
+ * the project (`invalid_reference`, `type_not_accepted`). `expand` embeds
1007
+ * the assets, and published-only keys can read the images of published
1008
+ * records. A record holds at
1009
+ * most 2,000,000 bytes of values, all fields together (`too_large` on
1010
+ * `data`); one already larger can still be edited without growing.
978
1011
  *
979
1012
  */
980
1013
  export type RecordData = {
@@ -1129,7 +1162,7 @@ export type Principal = {
1129
1162
  email: string;
1130
1163
  name: string | null;
1131
1164
  /**
1132
- * Nohead staff (internal tooling access).
1165
+ * Whether the user is Nohead staff.
1133
1166
  */
1134
1167
  staff: boolean;
1135
1168
  };
@@ -1523,9 +1556,11 @@ export type AssetProperties = {
1523
1556
  */
1524
1557
  purge_after: NullableTimestamp;
1525
1558
  /**
1526
- * The URL of the whole image, for ready images (JPEG, PNG, GIF, WebP
1527
- * or AVIF), deleted ones included until they are purged; null
1528
- * otherwise. Image URLs are open and never expire. For a rendition,
1559
+ * The URL of the whole image, for ready images (JPEG, PNG, GIF, WebP,
1560
+ * AVIF or SVG), deleted ones included until they are purged; null
1561
+ * otherwise. Image URLs are open and never expire. An SVG is served
1562
+ * as SVG without its scripts, unless a format such as `@webp`
1563
+ * rasterizes it. For a rendition,
1529
1564
  * write [imgproxy processing options](https://docs.imgproxy.net/usage/processing)
1530
1565
  * before `/plain/`, and a format after `@`: for example
1531
1566
  * `https://images.nohead.io/rs:fill:800:600/g:sm/plain/…@webp`. Renditions
@@ -1536,7 +1571,7 @@ export type AssetProperties = {
1536
1571
  */
1537
1572
  image_url: string | null;
1538
1573
  /**
1539
- * The URL of a small rendition (fits in 640×640, WebP), for ready images and SVGs (rasterized; SVGs have no `image_url`), deleted ones included until they are purged; null otherwise.
1574
+ * The URL of a small rendition (fits in 640×640, WebP), for ready images and SVGs (rasterized), deleted ones included until they are purged; null otherwise.
1540
1575
  */
1541
1576
  preview_url: string | null;
1542
1577
  /**
@@ -1550,7 +1585,10 @@ export type AssetProperties = {
1550
1585
  /**
1551
1586
  * The URL that plays a ready video or audio file inline, for
1552
1587
  * `<video>` and `<audio>` (with range requests, so players can seek),
1553
- * deleted ones included until they are purged; null for other types.
1588
+ * deleted ones included until they are purged: MP4, QuickTime, M4A,
1589
+ * 3GP, WebM, Matroska, MP3, AAC, FLAC, WAV and Ogg (whose content is
1590
+ * checked when the upload completes). Null for other types, which
1591
+ * `file_url` downloads.
1554
1592
  * Open, never expiring and cached on a CDN, like `file_url`.
1555
1593
  *
1556
1594
  */
@@ -1619,7 +1657,7 @@ export type AssetUploadTarget = {
1619
1657
  expires_at: Timestamp;
1620
1658
  };
1621
1659
  /**
1622
- * What a project API key may do. `records:write` also publishes, unpublishes and schedules records (the `records:publish` permission). `webhooks:read` includes delivery payloads and `webhooks:write` can subscribe an endpoint to every event, so both give access to the record, schema and asset data in events, unpublished records included; published-only keys cannot have them.
1660
+ * What a project API key may do. `records:write` also publishes, unpublishes and schedules records. `webhooks:read` includes delivery payloads and `webhooks:write` can subscribe an endpoint to every event, so both give access to the record, schema and asset data in events, unpublished records included; published-only keys cannot have them.
1623
1661
  */
1624
1662
  export type ApiKeyScope = 'records:read' | 'records:write' | 'schema:read' | 'schema:write' | 'assets:read' | 'assets:write' | 'search:read' | 'webhooks:read' | 'webhooks:write' | 'audit:read';
1625
1663
  /**
@@ -1684,6 +1722,10 @@ export type RevisionId = string;
1684
1722
  * Per-record revision number.
1685
1723
  */
1686
1724
  export type RevisionNumber = number;
1725
+ /**
1726
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
1727
+ */
1728
+ export type RichText = 'document' | 'html' | 'markdown';
1687
1729
  /**
1688
1730
  * Comma-separated relation, asset or rich text field keys whose records or assets to embed under `expanded` (at most 5); for a rich text field, the assets its images show. Embedding needs permission to read what is embedded: `records:read` for relations, `assets:read` for assets and rich text (`403` otherwise).
1689
1731
  */
@@ -1692,8 +1734,7 @@ export type Expand = string;
1692
1734
  * `filter[<key>]=value` (equal), or `filter[<key>][<operator>]=value`;
1693
1735
  * filters combine with AND. Keys are field keys, `published_at`,
1694
1736
  * `deleted` (`true` lists soft-deleted records instead) and, in record
1695
- * lists and counts, `created_at` and `updated_at`. In search,
1696
- * `published_at` takes only `exists`.
1737
+ * lists and counts, `created_at` and `updated_at`.
1697
1738
  *
1698
1739
  * - `eq`, `ne`: equal, not equal. For fields with several values,
1699
1740
  * "contains" and "does not contain". `ne` matches records with no value.
@@ -1833,12 +1874,15 @@ export type RecordsListData = {
1833
1874
  collection_id: string;
1834
1875
  };
1835
1876
  query?: {
1877
+ /**
1878
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
1879
+ */
1880
+ rich_text?: 'document' | 'html' | 'markdown';
1836
1881
  /**
1837
1882
  * `filter[<key>]=value` (equal), or `filter[<key>][<operator>]=value`;
1838
1883
  * filters combine with AND. Keys are field keys, `published_at`,
1839
1884
  * `deleted` (`true` lists soft-deleted records instead) and, in record
1840
- * lists and counts, `created_at` and `updated_at`. In search,
1841
- * `published_at` takes only `exists`.
1885
+ * lists and counts, `created_at` and `updated_at`.
1842
1886
  *
1843
1887
  * - `eq`, `ne`: equal, not equal. For fields with several values,
1844
1888
  * "contains" and "does not contain". `ne` matches records with no value.
@@ -1961,7 +2005,12 @@ export type RecordsCreateData = {
1961
2005
  */
1962
2006
  collection_id: string;
1963
2007
  };
1964
- query?: never;
2008
+ query?: {
2009
+ /**
2010
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
2011
+ */
2012
+ rich_text?: 'document' | 'html' | 'markdown';
2013
+ };
1965
2014
  url: '/v1/collections/{collection_id}/records';
1966
2015
  };
1967
2016
  export type RecordsCreateErrors = {
@@ -2060,7 +2109,12 @@ export type RecordsDeleteData = {
2060
2109
  path: {
2061
2110
  record_id: string;
2062
2111
  };
2063
- query?: never;
2112
+ query?: {
2113
+ /**
2114
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
2115
+ */
2116
+ rich_text?: 'document' | 'html' | 'markdown';
2117
+ };
2064
2118
  url: '/v1/records/{record_id}';
2065
2119
  };
2066
2120
  export type RecordsDeleteErrors = {
@@ -2116,6 +2170,10 @@ export type RecordsGetData = {
2116
2170
  record_id: string;
2117
2171
  };
2118
2172
  query?: {
2173
+ /**
2174
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
2175
+ */
2176
+ rich_text?: 'document' | 'html' | 'markdown';
2119
2177
  /**
2120
2178
  * Comma-separated relation, asset or rich text field keys whose records or assets to embed under `expanded` (at most 5); for a rich text field, the assets its images show. Embedding needs permission to read what is embedded: `records:read` for relations, `assets:read` for assets and rich text (`403` otherwise).
2121
2179
  */
@@ -2195,7 +2253,12 @@ export type RecordsUpdateData = {
2195
2253
  path: {
2196
2254
  record_id: string;
2197
2255
  };
2198
- query?: never;
2256
+ query?: {
2257
+ /**
2258
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
2259
+ */
2260
+ rich_text?: 'document' | 'html' | 'markdown';
2261
+ };
2199
2262
  url: '/v1/records/{record_id}';
2200
2263
  };
2201
2264
  export type RecordsUpdateErrors = {
@@ -2262,8 +2325,7 @@ export type RecordsCountData = {
2262
2325
  * `filter[<key>]=value` (equal), or `filter[<key>][<operator>]=value`;
2263
2326
  * filters combine with AND. Keys are field keys, `published_at`,
2264
2327
  * `deleted` (`true` lists soft-deleted records instead) and, in record
2265
- * lists and counts, `created_at` and `updated_at`. In search,
2266
- * `published_at` takes only `exists`.
2328
+ * lists and counts, `created_at` and `updated_at`.
2267
2329
  *
2268
2330
  * - `eq`, `ne`: equal, not equal. For fields with several values,
2269
2331
  * "contains" and "does not contain". `ne` matches records with no value.
@@ -2362,7 +2424,12 @@ export type RecordsBulkData = {
2362
2424
  */
2363
2425
  collection_id: string;
2364
2426
  };
2365
- query?: never;
2427
+ query?: {
2428
+ /**
2429
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
2430
+ */
2431
+ rich_text?: 'document' | 'html' | 'markdown';
2432
+ };
2366
2433
  url: '/v1/collections/{collection_id}/record-batches';
2367
2434
  };
2368
2435
  export type RecordsBulkErrors = {
@@ -2445,7 +2512,12 @@ export type RecordsRestoreData = {
2445
2512
  path: {
2446
2513
  record_id: string;
2447
2514
  };
2448
- query?: never;
2515
+ query?: {
2516
+ /**
2517
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
2518
+ */
2519
+ rich_text?: 'document' | 'html' | 'markdown';
2520
+ };
2449
2521
  url: '/v1/records/{record_id}/restore';
2450
2522
  };
2451
2523
  export type RecordsRestoreErrors = {
@@ -2536,7 +2608,12 @@ export type RecordsUnpublishData = {
2536
2608
  path: {
2537
2609
  record_id: string;
2538
2610
  };
2539
- query?: never;
2611
+ query?: {
2612
+ /**
2613
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
2614
+ */
2615
+ rich_text?: 'document' | 'html' | 'markdown';
2616
+ };
2540
2617
  url: '/v1/records/{record_id}/publication';
2541
2618
  };
2542
2619
  export type RecordsUnpublishErrors = {
@@ -2666,7 +2743,12 @@ export type RecordsPublishData = {
2666
2743
  path: {
2667
2744
  record_id: string;
2668
2745
  };
2669
- query?: never;
2746
+ query?: {
2747
+ /**
2748
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
2749
+ */
2750
+ rich_text?: 'document' | 'html' | 'markdown';
2751
+ };
2670
2752
  url: '/v1/records/{record_id}/publication';
2671
2753
  };
2672
2754
  export type RecordsPublishErrors = {
@@ -3152,6 +3234,10 @@ export type RecordRevisionsRevertData = {
3152
3234
  revision: number;
3153
3235
  };
3154
3236
  query?: {
3237
+ /**
3238
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
3239
+ */
3240
+ rich_text?: 'document' | 'html' | 'markdown';
3155
3241
  dry_run?: boolean;
3156
3242
  };
3157
3243
  url: '/v1/records/{record_id}/revisions/{revision}/revert';
@@ -3261,6 +3347,10 @@ export type RecordDraftsListData = {
3261
3347
  record_id: string;
3262
3348
  };
3263
3349
  query?: {
3350
+ /**
3351
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
3352
+ */
3353
+ rich_text?: 'document' | 'html' | 'markdown';
3264
3354
  /**
3265
3355
  * Page size.
3266
3356
  */
@@ -3330,7 +3420,12 @@ export type DraftsCreateData = {
3330
3420
  path: {
3331
3421
  record_id: string;
3332
3422
  };
3333
- query?: never;
3423
+ query?: {
3424
+ /**
3425
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
3426
+ */
3427
+ rich_text?: 'document' | 'html' | 'markdown';
3428
+ };
3334
3429
  url: '/v1/records/{record_id}/drafts';
3335
3430
  };
3336
3431
  export type DraftsCreateErrors = {
@@ -3387,6 +3482,10 @@ export type DraftsListData = {
3387
3482
  collection_id: string;
3388
3483
  };
3389
3484
  query?: {
3485
+ /**
3486
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
3487
+ */
3488
+ rich_text?: 'document' | 'html' | 'markdown';
3390
3489
  sort?: 'updated_at' | '-updated_at';
3391
3490
  /**
3392
3491
  * Page size.
@@ -3461,7 +3560,12 @@ export type DraftsDiscardData = {
3461
3560
  path: {
3462
3561
  draft_id: string;
3463
3562
  };
3464
- query?: never;
3563
+ query?: {
3564
+ /**
3565
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
3566
+ */
3567
+ rich_text?: 'document' | 'html' | 'markdown';
3568
+ };
3465
3569
  url: '/v1/drafts/{draft_id}';
3466
3570
  };
3467
3571
  export type DraftsDiscardErrors = {
@@ -3517,6 +3621,10 @@ export type DraftsGetData = {
3517
3621
  draft_id: string;
3518
3622
  };
3519
3623
  query?: {
3624
+ /**
3625
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
3626
+ */
3627
+ rich_text?: 'document' | 'html' | 'markdown';
3520
3628
  /**
3521
3629
  * Comma-separated relation, asset or rich text field keys whose records or assets to embed under `expanded` (at most 5); for a rich text field, the assets its images show. Embedding needs permission to read what is embedded: `records:read` for relations, `assets:read` for assets and rich text (`403` otherwise).
3522
3630
  */
@@ -3586,7 +3694,12 @@ export type DraftsUpdateData = {
3586
3694
  path: {
3587
3695
  draft_id: string;
3588
3696
  };
3589
- query?: never;
3697
+ query?: {
3698
+ /**
3699
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
3700
+ */
3701
+ rich_text?: 'document' | 'html' | 'markdown';
3702
+ };
3590
3703
  url: '/v1/drafts/{draft_id}';
3591
3704
  };
3592
3705
  export type DraftsUpdateErrors = {
@@ -3675,7 +3788,12 @@ export type DraftsMergeData = {
3675
3788
  path: {
3676
3789
  draft_id: string;
3677
3790
  };
3678
- query?: never;
3791
+ query?: {
3792
+ /**
3793
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
3794
+ */
3795
+ rich_text?: 'document' | 'html' | 'markdown';
3796
+ };
3679
3797
  url: '/v1/drafts/{draft_id}/merge';
3680
3798
  };
3681
3799
  export type DraftsMergeErrors = {
@@ -3750,7 +3868,12 @@ export type DraftsUnscheduleData = {
3750
3868
  path: {
3751
3869
  draft_id: string;
3752
3870
  };
3753
- query?: never;
3871
+ query?: {
3872
+ /**
3873
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
3874
+ */
3875
+ rich_text?: 'document' | 'html' | 'markdown';
3876
+ };
3754
3877
  url: '/v1/drafts/{draft_id}/schedule';
3755
3878
  };
3756
3879
  export type DraftsUnscheduleErrors = {
@@ -3815,7 +3938,12 @@ export type DraftsScheduleData = {
3815
3938
  path: {
3816
3939
  draft_id: string;
3817
3940
  };
3818
- query?: never;
3941
+ query?: {
3942
+ /**
3943
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
3944
+ */
3945
+ rich_text?: 'document' | 'html' | 'markdown';
3946
+ };
3819
3947
  url: '/v1/drafts/{draft_id}/schedule';
3820
3948
  };
3821
3949
  export type DraftsScheduleErrors = {
@@ -5935,6 +6063,10 @@ export type CollectionsSearchData = {
5935
6063
  collection_id: string;
5936
6064
  };
5937
6065
  query?: {
6066
+ /**
6067
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
6068
+ */
6069
+ rich_text?: 'document' | 'html' | 'markdown';
5938
6070
  /**
5939
6071
  * The words to search for; empty matches everything.
5940
6072
  */
@@ -5951,8 +6083,7 @@ export type CollectionsSearchData = {
5951
6083
  * `filter[<key>]=value` (equal), or `filter[<key>][<operator>]=value`;
5952
6084
  * filters combine with AND. Keys are field keys, `published_at`,
5953
6085
  * `deleted` (`true` lists soft-deleted records instead) and, in record
5954
- * lists and counts, `created_at` and `updated_at`. In search,
5955
- * `published_at` takes only `exists`.
6086
+ * lists and counts, `created_at` and `updated_at`.
5956
6087
  *
5957
6088
  * - `eq`, `ne`: equal, not equal. For fields with several values,
5958
6089
  * "contains" and "does not contain". `ne` matches records with no value.
@@ -6036,6 +6167,10 @@ export type ProjectsSearchData = {
6036
6167
  project_id: string;
6037
6168
  };
6038
6169
  query?: {
6170
+ /**
6171
+ * How rich text fields read in the records and drafts returned (and in records they embed with `expand`): `document`, the stored ProseMirror JSON document; `html`, an HTML fragment of known elements with every text and attribute escaped, to put in a page as it is; or `markdown` (GitHub Flavored), which reads back as the same document when written. Images render with their URLs, so they need no `expand`: in HTML a WebP rendition at most 1600 pixels wide with its `width` and `height` (an SVG as itself), in Markdown the asset's `image_url`. An image whose asset was deleted is left out of HTML, and written as its asset ID in Markdown. Record history keeps documents.
6172
+ */
6173
+ rich_text?: 'document' | 'html' | 'markdown';
6039
6174
  /**
6040
6175
  * The words to search for; empty matches everything.
6041
6176
  */
package/dist/images.js CHANGED
@@ -16,8 +16,13 @@ export function imageUrl(image, options = {}) {
16
16
  const at = base.indexOf("/plain/");
17
17
  if (at < 0)
18
18
  throw new TypeError(`Not a Nohead image URL: ${base}`);
19
- const { width, height, fit = "contain", format, quality, dpr, gravity, } = options;
20
- for (const option of [gravity, ...(options.options ?? [])])
19
+ // Empty options count as unset.
20
+ const { width, height, format, quality, dpr, gravity } = options;
21
+ const fit = options.fit || "contain";
22
+ if (!Object.hasOwn(FITS, fit))
23
+ throw new TypeError(`fit must be one of ${Object.keys(FITS).join(", ")}`);
24
+ const others = (options.options ?? []).filter(Boolean);
25
+ for (const option of [gravity, ...others])
21
26
  if (option && /[/@?#]/.test(option))
22
27
  throw new TypeError(`Not an imgproxy option: ${option}`);
23
28
  const segments = [];
@@ -29,7 +34,7 @@ export function imageUrl(image, options = {}) {
29
34
  segments.push(`dpr:${dpr}`);
30
35
  if (quality)
31
36
  segments.push(`q:${quality}`);
32
- segments.push(...(options.options ?? []));
37
+ segments.push(...others);
33
38
  // The source comes last; a format replaces any the URL already names.
34
39
  let source = base.slice(at);
35
40
  if (format)
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { Nohead } from "./client.ts";
2
2
  export { APIPromise, Page, PagePromise, type APIResponse, } from "./api-promise.ts";
3
- export type { ClientOptions, ConditionalRequestOptions, ConditionalWriteOptions, RequestOptions, RetryEvent, WriteOptions, } from "./core.ts";
3
+ export { DEFAULT_BASE_URL, type ClientOptions, type ConditionalRequestOptions, type ConditionalWriteOptions, type CopyOptions, type RequestOptions, type RetryEvent, type RichTextOptions, type WriteOptions, } from "./core.ts";
4
4
  export { APIError, AbortError, AuthenticationError, AuthorizationError, ConflictError, ConnectionError, InternalServerError, InvalidRequestError, NoheadError, NotFoundError, PlanLimitExceededError, PreconditionFailedError, RateLimitError, ServiceUnavailableError, TimeoutError, UploadError, ValidationError, WebhookVerificationError, } from "./errors.ts";
5
5
  export type { Uploadable, UploadParams } from "./resources/assets.ts";
6
6
  export type * from "./types.ts";
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { Nohead } from "./client.js";
2
2
  export { APIPromise, Page, PagePromise, } from "./api-promise.js";
3
+ export { DEFAULT_BASE_URL, } from "./core.js";
3
4
  export { APIError, AbortError, AuthenticationError, AuthorizationError, ConflictError, ConnectionError, InternalServerError, InvalidRequestError, NoheadError, NotFoundError, PlanLimitExceededError, PreconditionFailedError, RateLimitError, ServiceUnavailableError, TimeoutError, UploadError, ValidationError, WebhookVerificationError, } from "./errors.js";
4
5
  export { unwrapWebhook, } from "./webhooks.js";
5
6
  export { VERSION } from "./version.js";
@@ -8,11 +8,15 @@ export type Uploadable = Blob | ArrayBuffer | Uint8Array | ReadableStream;
8
8
  export interface UploadParams {
9
9
  /** Defaults to a `File`'s name, else `upload`. */
10
10
  filename?: string;
11
- /** Defaults to the `Blob`'s type, else `application/octet-stream`. */
11
+ /**
12
+ * Defaults to the `Blob`'s type, else the filename's extension's for
13
+ * common files, else `application/octet-stream`.
14
+ */
12
15
  content_type?: string;
13
16
  /** Required for a `ReadableStream`; known for everything else. */
14
17
  byte_size?: number;
15
18
  }
19
+ /** Files of the key's project. `asset` is an asset ID (`ast_…`). */
16
20
  export declare class Assets extends Resource {
17
21
  /**
18
22
  * Uploads a file and returns the `ready` asset: creates the upload, sends
@@ -1,6 +1,5 @@
1
1
  import { AbortError, UploadError } from "../errors.js";
2
2
  import { listQuery, Resource } from "./resource.js";
3
- /** Files of the key's project. `asset` is an asset ID (`ast_…`). */
4
3
  /** Common files' types by extension, as the other SDKs guess them. */
5
4
  const CONTENT_TYPES = {
6
5
  avif: "image/avif",
@@ -26,6 +25,7 @@ function contentTypeOf(filename) {
26
25
  ? CONTENT_TYPES[filename.slice(dot + 1).toLowerCase()]
27
26
  : undefined;
28
27
  }
28
+ /** Files of the key's project. `asset` is an asset ID (`ast_…`). */
29
29
  export class Assets extends Resource {
30
30
  /**
31
31
  * Uploads a file and returns the `ready` asset: creates the upload, sends
@@ -45,23 +45,28 @@ export class Assets extends Resource {
45
45
  * extension's for common files.
46
46
  */
47
47
  async upload(file, params = {}, options) {
48
+ // Never a path: the Python and Ruby SDKs take one, so it would be easy
49
+ // to send its text instead.
50
+ if (typeof file === "string") {
51
+ throw new TypeError("upload takes a Blob, File, ArrayBuffer, Uint8Array or ReadableStream; to upload a file from disk, pass await fs.openAsBlob(path)");
52
+ }
48
53
  const byteSize = params.byte_size ?? sizeOf(file);
49
54
  if (byteSize === undefined) {
50
55
  throw new UploadError("Uploading a stream needs `byte_size`");
51
56
  }
52
- const filename = params.filename ??
53
- (typeof File !== "undefined" && file instanceof File
54
- ? file.name
55
- : "upload");
57
+ // Empty ones count as unset.
58
+ const filename = params.filename ||
59
+ (typeof File !== "undefined" && file instanceof File && file.name) ||
60
+ "upload";
56
61
  const { upload, ...asset } = await this.createUpload({
57
62
  filename,
58
63
  // The Blob's own type, or one the filename's extension implies (a
59
64
  // Blob from Node's openAsBlob has none), as the Python and Ruby
60
65
  // SDKs do.
61
- content_type: params.content_type ??
62
- ((file instanceof Blob && file.type) ||
63
- contentTypeOf(filename) ||
64
- "application/octet-stream"),
66
+ content_type: params.content_type ||
67
+ (file instanceof Blob && file.type) ||
68
+ contentTypeOf(filename) ||
69
+ "application/octet-stream",
65
70
  byte_size: byteSize,
66
71
  }, options);
67
72
  // A replayed start returns the first run's asset, which may be done.
@@ -74,24 +79,28 @@ export class Assets extends Resource {
74
79
  return current;
75
80
  // The key replays the first run's upload URL, which expires sooner.
76
81
  if (Date.parse(upload.expires_at) <= Date.now()) {
77
- throw new UploadError(`The upload of ${asset.filename} expired: start it again with a new idempotencyKey`);
82
+ throw new UploadError(`The upload of ${filename} expired: start it again with a new idempotencyKey`);
78
83
  }
79
84
  }
80
85
  const stream = file instanceof ReadableStream;
81
86
  const response = await this.core
82
87
  .fetchWithRetries(upload.url, {
83
88
  method: upload.method,
84
- headers: upload.headers,
89
+ // The URL is signed for this size; fetch would send a stream
90
+ // in chunks, without one.
91
+ headers: stream
92
+ ? { ...upload.headers, "Content-Length": String(byteSize) }
93
+ : upload.headers,
85
94
  body: file,
86
95
  ...(stream ? { duplex: "half" } : {}),
87
- }, { ...options, retry: !stream })
96
+ }, { ...options, retry: !stream, byteSize })
88
97
  .catch((error) => {
89
98
  if (error instanceof AbortError)
90
99
  throw error;
91
- throw new UploadError(`Could not upload ${asset.filename}: ${error.message}`, undefined, { cause: error });
100
+ throw new UploadError(`Could not upload ${filename}: ${error.message}`, undefined, { cause: error });
92
101
  });
93
102
  if (!response.ok) {
94
- throw new UploadError(`Storage refused the upload of ${asset.filename} (${response.status})`, response.status);
103
+ throw new UploadError(`Storage refused the upload of ${filename} (${response.status})`, response.status);
95
104
  }
96
105
  // The key belongs to the start: the API refuses one key on two requests.
97
106
  return this.complete(asset.id, { ...options, idempotencyKey: undefined });