@datocms/cma-client 5.4.13 → 5.4.15

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 (36) hide show
  1. package/dist/cjs/fieldTypes/index.js.map +1 -1
  2. package/dist/cjs/generated/Client.js +1 -1
  3. package/dist/esm/fieldTypes/appearance/color_picker.d.ts +4 -4
  4. package/dist/esm/fieldTypes/appearance/framed_single_block.d.ts +1 -1
  5. package/dist/esm/fieldTypes/appearance/markdown.d.ts +2 -2
  6. package/dist/esm/fieldTypes/appearance/rich_text.d.ts +1 -1
  7. package/dist/esm/fieldTypes/appearance/seo.d.ts +4 -4
  8. package/dist/esm/fieldTypes/appearance/single_line.d.ts +2 -2
  9. package/dist/esm/fieldTypes/appearance/structured_text.d.ts +9 -9
  10. package/dist/esm/fieldTypes/appearance/wysiwyg.d.ts +2 -2
  11. package/dist/esm/fieldTypes/index.d.ts +37 -6
  12. package/dist/esm/fieldTypes/index.js.map +1 -1
  13. package/dist/esm/fieldTypes/validators/sanitized_html.d.ts +1 -1
  14. package/dist/esm/generated/Client.js +1 -1
  15. package/dist/types/fieldTypes/appearance/color_picker.d.ts +4 -4
  16. package/dist/types/fieldTypes/appearance/framed_single_block.d.ts +1 -1
  17. package/dist/types/fieldTypes/appearance/markdown.d.ts +2 -2
  18. package/dist/types/fieldTypes/appearance/rich_text.d.ts +1 -1
  19. package/dist/types/fieldTypes/appearance/seo.d.ts +4 -4
  20. package/dist/types/fieldTypes/appearance/single_line.d.ts +2 -2
  21. package/dist/types/fieldTypes/appearance/structured_text.d.ts +9 -9
  22. package/dist/types/fieldTypes/appearance/wysiwyg.d.ts +2 -2
  23. package/dist/types/fieldTypes/index.d.ts +37 -6
  24. package/dist/types/fieldTypes/validators/sanitized_html.d.ts +1 -1
  25. package/package.json +2 -2
  26. package/src/fieldTypes/appearance/color_picker.ts +4 -4
  27. package/src/fieldTypes/appearance/framed_single_block.ts +1 -1
  28. package/src/fieldTypes/appearance/markdown.ts +2 -2
  29. package/src/fieldTypes/appearance/rich_text.ts +1 -1
  30. package/src/fieldTypes/appearance/seo.ts +4 -4
  31. package/src/fieldTypes/appearance/single_line.ts +2 -2
  32. package/src/fieldTypes/appearance/structured_text.ts +9 -9
  33. package/src/fieldTypes/appearance/wysiwyg.ts +2 -2
  34. package/src/fieldTypes/index.ts +61 -11
  35. package/src/fieldTypes/validators/sanitized_html.ts +1 -1
  36. package/src/generated/Client.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fieldTypes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAsDA,wDAAsC;AACtC,+CAA6B;AAC7B,6CAA2B;AAC3B,4CAA0B;AAC1B,iDAA+B;AAC/B,4CAA0B;AAC1B,6CAA2B;AAC3B,+CAA6B;AAC7B,+CAA6B;AAC7B,4CAA0B;AAC1B,+CAA6B;AAC7B,4CAA0B;AAC1B,6CAA2B;AAC3B,iDAA+B;AAC/B,2CAAyB;AACzB,oDAAkC;AAClC,4CAA0B;AAC1B,8CAA4B;AAC5B,uDAAqC;AACrC,4CAA0B;AAC1B,wDAAsC;AACtC,6CAA2B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fieldTypes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAwGA,wDAAsC;AACtC,+CAA6B;AAC7B,6CAA2B;AAC3B,4CAA0B;AAC1B,iDAA+B;AAC/B,4CAA0B;AAC1B,6CAA2B;AAC3B,+CAA6B;AAC7B,+CAA6B;AAC7B,4CAA0B;AAC1B,+CAA6B;AAC7B,4CAA0B;AAC1B,6CAA2B;AAC3B,iDAA+B;AAC/B,2CAAyB;AACzB,oDAAkC;AAClC,4CAA0B;AAC1B,8CAA4B;AAC5B,uDAAqC;AACrC,4CAA0B;AAC1B,wDAAsC;AACtC,6CAA2B"}
@@ -90,7 +90,7 @@ class Client {
90
90
  return this.config.baseUrl || Client.defaultBaseUrl;
91
91
  }
92
92
  request(options) {
93
- return (0, rest_client_utils_1.request)(Object.assign(Object.assign(Object.assign({}, this.config), options), { logFn: this.config.logFn || console.log, userAgent: '@datocms/cma-client v5.4.13', baseUrl: this.baseUrl, preCallStack: new Error().stack, extraHeaders: Object.assign(Object.assign(Object.assign({}, (this.config.extraHeaders || {})), (this.config.environment
93
+ return (0, rest_client_utils_1.request)(Object.assign(Object.assign(Object.assign({}, this.config), options), { logFn: this.config.logFn || console.log, userAgent: '@datocms/cma-client v5.4.15', baseUrl: this.baseUrl, preCallStack: new Error().stack, extraHeaders: Object.assign(Object.assign(Object.assign({}, (this.config.extraHeaders || {})), (this.config.environment
94
94
  ? { 'X-Environment': this.config.environment }
95
95
  : {})), { 'X-API-Version': '3' }), fetchJobResult: (jobId) => {
96
96
  return this.jobResultsFetcher
@@ -2,8 +2,8 @@
2
2
  * Built-in editor for Color fields.
3
3
  */
4
4
  export type ColorPickerEditorConfiguration = {
5
- /** Should the color picker allow to specify the alpha value? */
6
- enable_alpha: boolean;
7
- /** List of preset colors to offer to the user (hex color strings) */
8
- preset_colors: Array<string>;
5
+ /** Should the color picker allow to specify the alpha value? (default: false) */
6
+ enable_alpha?: boolean;
7
+ /** List of preset colors to offer to the user (hex color strings) (default: []) */
8
+ preset_colors?: Array<string>;
9
9
  };
@@ -2,6 +2,6 @@
2
2
  * Built-in editor for Single block fields.
3
3
  */
4
4
  export type FramedSingleBlockEditorConfiguration = {
5
- /** Whether you want block record collapsed by default or not */
5
+ /** Whether you want block record collapsed by default or not (default: false) */
6
6
  start_collapsed?: boolean;
7
7
  };
@@ -2,6 +2,6 @@
2
2
  * Markdown editor for Multiple-paragraph text fields.
3
3
  */
4
4
  export type MarkdownEditorConfiguration = {
5
- /** Specify which buttons the toolbar should have */
6
- toolbar: Array<'heading' | 'bold' | 'italic' | 'strikethrough' | 'code' | 'unordered_list' | 'ordered_list' | 'quote' | 'link' | 'image' | 'fullscreen'>;
5
+ /** Specify which buttons the toolbar should have (default: all allowed values) */
6
+ toolbar?: Array<'heading' | 'bold' | 'italic' | 'strikethrough' | 'code' | 'unordered_list' | 'ordered_list' | 'quote' | 'link' | 'image' | 'fullscreen'>;
7
7
  };
@@ -2,6 +2,6 @@
2
2
  * Built-in editor for Modular content fields.
3
3
  */
4
4
  export type RichTextEditorConfiguration = {
5
- /** Whether you want block records collapsed by default or not */
5
+ /** Whether you want block records collapsed by default or not (default: false) */
6
6
  start_collapsed?: boolean;
7
7
  };
@@ -2,8 +2,8 @@
2
2
  * Built-in editor for SEO fields.
3
3
  */
4
4
  export type SeoEditorConfiguration = {
5
- /** Specify which fields of the SEO input should be visible to editors */
6
- fields: Array<'title' | 'description' | 'image' | 'no_index' | 'twitter_card'>;
7
- /** Specify which previews should be visible to editors */
8
- previews: Array<'google' | 'twitter' | 'slack' | 'whatsapp' | 'telegram' | 'facebook' | 'linkedin'>;
5
+ /** Specify which fields of the SEO input should be visible to editors (default: all allowed values) */
6
+ fields?: Array<'title' | 'description' | 'image' | 'no_index' | 'twitter_card'>;
7
+ /** Specify which previews should be visible to editors (default: all allowed values) */
8
+ previews?: Array<'google' | 'twitter' | 'slack' | 'whatsapp' | 'telegram' | 'facebook' | 'linkedin'>;
9
9
  };
@@ -2,8 +2,8 @@
2
2
  * Simple textual input for Single-line string fields.
3
3
  */
4
4
  export type SingleLineEditorConfiguration = {
5
- /** Indicates if the field should be shown bigger, as a field representing a heading */
6
- heading: boolean;
5
+ /** Indicates if the field should be shown bigger, as a field representing a heading (default: false) */
6
+ heading?: boolean;
7
7
  /** A placeholder that will be shown in the editor's input to provide editors with an example */
8
8
  placeholder?: string;
9
9
  };
@@ -2,16 +2,16 @@
2
2
  * Built-in editor for Structured text fields.
3
3
  */
4
4
  export type StructuredTextEditorConfiguration = {
5
- /** Specify which nodes the field should allow */
6
- nodes: Array<'blockquote' | 'code' | 'heading' | 'link' | 'list' | 'thematicBreak'>;
7
- /** Specify which marks the field should allow */
8
- marks: Array<'strong' | 'emphasis' | 'underline' | 'strikethrough' | 'code' | 'highlight'>;
9
- /** If nodes includes "heading", specify which heading levels the field should allow (numbers between 1 and 6) */
10
- heading_levels: Array<1 | 2 | 3 | 4 | 5 | 6>;
11
- /** Whether you want block nodes collapsed by default or not */
5
+ /** Specify which nodes the field should allow (default: all allowed values) */
6
+ nodes?: Array<'blockquote' | 'code' | 'heading' | 'link' | 'list' | 'thematicBreak'>;
7
+ /** Specify which marks the field should allow (default: all allowed values) */
8
+ marks?: Array<'strong' | 'emphasis' | 'underline' | 'strikethrough' | 'code' | 'highlight'>;
9
+ /** If nodes includes "heading", specify which heading levels the field should allow (numbers between 1 and 6) (default: all allowed values) */
10
+ heading_levels?: Array<1 | 2 | 3 | 4 | 5 | 6>;
11
+ /** Whether you want block nodes collapsed by default or not (default: false) */
12
12
  blocks_start_collapsed?: boolean;
13
- /** Whether you want to show the "Open this link in a new tab?" checkbox, that fills in the target: "_blank" meta attribute for links */
13
+ /** Whether you want to show the "Open this link in a new tab?" checkbox, that fills in the target: "_blank" meta attribute for links (default: true) */
14
14
  show_links_target_blank?: boolean;
15
- /** Whether you want to show the complete meta editor for links */
15
+ /** Whether you want to show the complete meta editor for links (default: false) */
16
16
  show_links_meta_editor?: boolean;
17
17
  };
@@ -2,6 +2,6 @@
2
2
  * HTML editor for Multiple-paragraph text fields.
3
3
  */
4
4
  export type WysiwygEditorConfiguration = {
5
- /** Specify which buttons the toolbar should have */
6
- toolbar: Array<'format' | 'bold' | 'italic' | 'strikethrough' | 'code' | 'ordered_list' | 'unordered_list' | 'quote' | 'table' | 'link' | 'image' | 'show_source' | 'undo' | 'redo' | 'align_left' | 'align_center' | 'align_right' | 'align_justify' | 'outdent' | 'indent' | 'fullscreen'>;
5
+ /** Specify which buttons the toolbar should have (default: ['format', 'bold', 'italic', 'strikethrough', 'ordered_list', 'unordered_list', 'quote', 'table', 'link', 'image', 'show_source', 'fullscreen']) */
6
+ toolbar?: Array<'format' | 'bold' | 'italic' | 'strikethrough' | 'code' | 'ordered_list' | 'unordered_list' | 'quote' | 'table' | 'link' | 'image' | 'show_source' | 'undo' | 'redo' | 'align_left' | 'align_center' | 'align_right' | 'align_justify' | 'outdent' | 'indent' | 'fullscreen'>;
7
7
  };
@@ -1,7 +1,7 @@
1
1
  import type * as ApiTypes from '../generated/ApiTypes.js';
2
2
  import type * as RawApiTypes from '../generated/RawApiTypes.js';
3
- import type { ToItemAttributesInRequest } from '../utilities/itemDefinition.js';
4
- type ItemTypeDefinitionOf<T> = T extends ApiTypes.Item<infer D> ? D : T extends ApiTypes.ItemInNestedResponse<infer D> ? D : T extends RawApiTypes.Item<infer D> ? D : T extends RawApiTypes.ItemInNestedResponse<infer D> ? D : never;
3
+ import type { ItemTypeDefinition, ToItemAttributes, ToItemAttributesInNestedResponse, ToItemAttributesInRequest } from '../utilities/itemDefinition.js';
4
+ type ItemTypeDefinitionOf<T> = T extends ItemTypeDefinition<any, any, any> ? T : T extends ApiTypes.Item<infer D> ? D : T extends ApiTypes.ItemInNestedResponse<infer D> ? D : T extends RawApiTypes.Item<infer D> ? D : T extends RawApiTypes.ItemInNestedResponse<infer D> ? D : never;
5
5
  /**
6
6
  * Given a record or block you've read from the CMA and one of its field keys,
7
7
  * resolves to the type you'd send back when writing that field — for example,
@@ -13,10 +13,9 @@ type ItemTypeDefinitionOf<T> = T extends ApiTypes.Item<infer D> ? D : T extends
13
13
  *
14
14
  * The first parameter accepts any item-shaped value the CMA produces:
15
15
  * top-level records as well as nested blocks inside a parent record's
16
- * modular-content / structured-text / single-block field.
17
- *
18
- * The resulting type preserves `null`. Every CMA field can be cleared by
19
- * sending `null`, so the type reflects that.
16
+ * modular-content / structured-text / single-block field. You can also pass
17
+ * an `ItemTypeDefinition` directly when you already have the definition type
18
+ * in hand and don't need to round-trip through an `ApiTypes.Item<…>` shape.
20
19
  *
21
20
  * @example
22
21
  * // Read a record with nested blocks, edit one block, write the whole field
@@ -36,6 +35,38 @@ type ItemTypeDefinitionOf<T> = T extends ApiTypes.Item<infer D> ? D : T extends
36
35
  * await client.items.update<LandingPage>(page.id, { sections });
37
36
  */
38
37
  export type FieldValueInRequest<T, K extends keyof ToItemAttributesInRequest<ItemTypeDefinitionOf<T>>> = K extends keyof ToItemAttributesInRequest<ItemTypeDefinitionOf<T>> ? Required<ToItemAttributesInRequest<ItemTypeDefinitionOf<T>>>[K] : never;
38
+ /**
39
+ * Given a record or block you've read from the CMA and one of its field keys,
40
+ * resolves to the field's value type as it appears in a standard (non-nested)
41
+ * response — for example, what you'd read off `record.attributes[fieldKey]`
42
+ * after `client.items.find(id)`.
43
+ *
44
+ * The first parameter accepts any item-shaped value the CMA produces, or an
45
+ * `ItemTypeDefinition` directly.
46
+ *
47
+ * @example
48
+ * // Read nested, then collect just the block IDs for an outline view.
49
+ * const page = await client.items.find<LandingPage>(id, { nested: true });
50
+ * const sectionIds: FieldValue<typeof page, 'sections'> = page.sections.map(
51
+ * (block) => block.id,
52
+ * );
53
+ */
54
+ export type FieldValue<T, K extends keyof ToItemAttributes<ItemTypeDefinitionOf<T>>> = K extends keyof ToItemAttributes<ItemTypeDefinitionOf<T>> ? ToItemAttributes<ItemTypeDefinitionOf<T>>[K] : never;
55
+ /**
56
+ * Given a record or block you've read from the CMA and one of its field keys,
57
+ * resolves to the field's value type in a nested response — i.e. what you'd
58
+ * read off the field after `client.items.find(id, { nested: true })`, where
59
+ * blocks are inlined as full objects instead of ID strings.
60
+ *
61
+ * The first parameter accepts any item-shaped value the CMA produces, or an
62
+ * `ItemTypeDefinition` directly.
63
+ *
64
+ * @example
65
+ * const page = await client.items.find<LandingPage>(id, { nested: true });
66
+ * const sections: FieldValueInNestedResponse<typeof page, 'sections'> = page.sections;
67
+ * // sections elements are full block objects, not ID strings.
68
+ */
69
+ export type FieldValueInNestedResponse<T, K extends keyof ToItemAttributesInNestedResponse<ItemTypeDefinitionOf<T>>> = K extends keyof ToItemAttributesInNestedResponse<ItemTypeDefinitionOf<T>> ? ToItemAttributesInNestedResponse<ItemTypeDefinitionOf<T>>[K] : never;
39
70
  export * from './appearance/index.js';
40
71
  export * from './boolean.js';
41
72
  export * from './color.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fieldTypes/index.ts"],"names":[],"mappings":"AAsDA,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fieldTypes/index.ts"],"names":[],"mappings":"AAwGA,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC"}
@@ -3,5 +3,5 @@
3
3
  */
4
4
  export type SanitizedHtmlValidator = {
5
5
  /** Content is actively sanitized before applying the validation */
6
- sanitize_before_validation: boolean;
6
+ sanitize_before_validation?: boolean;
7
7
  };
@@ -64,7 +64,7 @@ export class Client {
64
64
  return this.config.baseUrl || Client.defaultBaseUrl;
65
65
  }
66
66
  request(options) {
67
- return request(Object.assign(Object.assign(Object.assign({}, this.config), options), { logFn: this.config.logFn || console.log, userAgent: '@datocms/cma-client v5.4.13', baseUrl: this.baseUrl, preCallStack: new Error().stack, extraHeaders: Object.assign(Object.assign(Object.assign({}, (this.config.extraHeaders || {})), (this.config.environment
67
+ return request(Object.assign(Object.assign(Object.assign({}, this.config), options), { logFn: this.config.logFn || console.log, userAgent: '@datocms/cma-client v5.4.15', baseUrl: this.baseUrl, preCallStack: new Error().stack, extraHeaders: Object.assign(Object.assign(Object.assign({}, (this.config.extraHeaders || {})), (this.config.environment
68
68
  ? { 'X-Environment': this.config.environment }
69
69
  : {})), { 'X-API-Version': '3' }), fetchJobResult: (jobId) => {
70
70
  return this.jobResultsFetcher
@@ -2,8 +2,8 @@
2
2
  * Built-in editor for Color fields.
3
3
  */
4
4
  export type ColorPickerEditorConfiguration = {
5
- /** Should the color picker allow to specify the alpha value? */
6
- enable_alpha: boolean;
7
- /** List of preset colors to offer to the user (hex color strings) */
8
- preset_colors: Array<string>;
5
+ /** Should the color picker allow to specify the alpha value? (default: false) */
6
+ enable_alpha?: boolean;
7
+ /** List of preset colors to offer to the user (hex color strings) (default: []) */
8
+ preset_colors?: Array<string>;
9
9
  };
@@ -2,6 +2,6 @@
2
2
  * Built-in editor for Single block fields.
3
3
  */
4
4
  export type FramedSingleBlockEditorConfiguration = {
5
- /** Whether you want block record collapsed by default or not */
5
+ /** Whether you want block record collapsed by default or not (default: false) */
6
6
  start_collapsed?: boolean;
7
7
  };
@@ -2,6 +2,6 @@
2
2
  * Markdown editor for Multiple-paragraph text fields.
3
3
  */
4
4
  export type MarkdownEditorConfiguration = {
5
- /** Specify which buttons the toolbar should have */
6
- toolbar: Array<'heading' | 'bold' | 'italic' | 'strikethrough' | 'code' | 'unordered_list' | 'ordered_list' | 'quote' | 'link' | 'image' | 'fullscreen'>;
5
+ /** Specify which buttons the toolbar should have (default: all allowed values) */
6
+ toolbar?: Array<'heading' | 'bold' | 'italic' | 'strikethrough' | 'code' | 'unordered_list' | 'ordered_list' | 'quote' | 'link' | 'image' | 'fullscreen'>;
7
7
  };
@@ -2,6 +2,6 @@
2
2
  * Built-in editor for Modular content fields.
3
3
  */
4
4
  export type RichTextEditorConfiguration = {
5
- /** Whether you want block records collapsed by default or not */
5
+ /** Whether you want block records collapsed by default or not (default: false) */
6
6
  start_collapsed?: boolean;
7
7
  };
@@ -2,8 +2,8 @@
2
2
  * Built-in editor for SEO fields.
3
3
  */
4
4
  export type SeoEditorConfiguration = {
5
- /** Specify which fields of the SEO input should be visible to editors */
6
- fields: Array<'title' | 'description' | 'image' | 'no_index' | 'twitter_card'>;
7
- /** Specify which previews should be visible to editors */
8
- previews: Array<'google' | 'twitter' | 'slack' | 'whatsapp' | 'telegram' | 'facebook' | 'linkedin'>;
5
+ /** Specify which fields of the SEO input should be visible to editors (default: all allowed values) */
6
+ fields?: Array<'title' | 'description' | 'image' | 'no_index' | 'twitter_card'>;
7
+ /** Specify which previews should be visible to editors (default: all allowed values) */
8
+ previews?: Array<'google' | 'twitter' | 'slack' | 'whatsapp' | 'telegram' | 'facebook' | 'linkedin'>;
9
9
  };
@@ -2,8 +2,8 @@
2
2
  * Simple textual input for Single-line string fields.
3
3
  */
4
4
  export type SingleLineEditorConfiguration = {
5
- /** Indicates if the field should be shown bigger, as a field representing a heading */
6
- heading: boolean;
5
+ /** Indicates if the field should be shown bigger, as a field representing a heading (default: false) */
6
+ heading?: boolean;
7
7
  /** A placeholder that will be shown in the editor's input to provide editors with an example */
8
8
  placeholder?: string;
9
9
  };
@@ -2,16 +2,16 @@
2
2
  * Built-in editor for Structured text fields.
3
3
  */
4
4
  export type StructuredTextEditorConfiguration = {
5
- /** Specify which nodes the field should allow */
6
- nodes: Array<'blockquote' | 'code' | 'heading' | 'link' | 'list' | 'thematicBreak'>;
7
- /** Specify which marks the field should allow */
8
- marks: Array<'strong' | 'emphasis' | 'underline' | 'strikethrough' | 'code' | 'highlight'>;
9
- /** If nodes includes "heading", specify which heading levels the field should allow (numbers between 1 and 6) */
10
- heading_levels: Array<1 | 2 | 3 | 4 | 5 | 6>;
11
- /** Whether you want block nodes collapsed by default or not */
5
+ /** Specify which nodes the field should allow (default: all allowed values) */
6
+ nodes?: Array<'blockquote' | 'code' | 'heading' | 'link' | 'list' | 'thematicBreak'>;
7
+ /** Specify which marks the field should allow (default: all allowed values) */
8
+ marks?: Array<'strong' | 'emphasis' | 'underline' | 'strikethrough' | 'code' | 'highlight'>;
9
+ /** If nodes includes "heading", specify which heading levels the field should allow (numbers between 1 and 6) (default: all allowed values) */
10
+ heading_levels?: Array<1 | 2 | 3 | 4 | 5 | 6>;
11
+ /** Whether you want block nodes collapsed by default or not (default: false) */
12
12
  blocks_start_collapsed?: boolean;
13
- /** Whether you want to show the "Open this link in a new tab?" checkbox, that fills in the target: "_blank" meta attribute for links */
13
+ /** Whether you want to show the "Open this link in a new tab?" checkbox, that fills in the target: "_blank" meta attribute for links (default: true) */
14
14
  show_links_target_blank?: boolean;
15
- /** Whether you want to show the complete meta editor for links */
15
+ /** Whether you want to show the complete meta editor for links (default: false) */
16
16
  show_links_meta_editor?: boolean;
17
17
  };
@@ -2,6 +2,6 @@
2
2
  * HTML editor for Multiple-paragraph text fields.
3
3
  */
4
4
  export type WysiwygEditorConfiguration = {
5
- /** Specify which buttons the toolbar should have */
6
- toolbar: Array<'format' | 'bold' | 'italic' | 'strikethrough' | 'code' | 'ordered_list' | 'unordered_list' | 'quote' | 'table' | 'link' | 'image' | 'show_source' | 'undo' | 'redo' | 'align_left' | 'align_center' | 'align_right' | 'align_justify' | 'outdent' | 'indent' | 'fullscreen'>;
5
+ /** Specify which buttons the toolbar should have (default: ['format', 'bold', 'italic', 'strikethrough', 'ordered_list', 'unordered_list', 'quote', 'table', 'link', 'image', 'show_source', 'fullscreen']) */
6
+ toolbar?: Array<'format' | 'bold' | 'italic' | 'strikethrough' | 'code' | 'ordered_list' | 'unordered_list' | 'quote' | 'table' | 'link' | 'image' | 'show_source' | 'undo' | 'redo' | 'align_left' | 'align_center' | 'align_right' | 'align_justify' | 'outdent' | 'indent' | 'fullscreen'>;
7
7
  };
@@ -1,7 +1,7 @@
1
1
  import type * as ApiTypes from '../generated/ApiTypes.js';
2
2
  import type * as RawApiTypes from '../generated/RawApiTypes.js';
3
- import type { ToItemAttributesInRequest } from '../utilities/itemDefinition.js';
4
- type ItemTypeDefinitionOf<T> = T extends ApiTypes.Item<infer D> ? D : T extends ApiTypes.ItemInNestedResponse<infer D> ? D : T extends RawApiTypes.Item<infer D> ? D : T extends RawApiTypes.ItemInNestedResponse<infer D> ? D : never;
3
+ import type { ItemTypeDefinition, ToItemAttributes, ToItemAttributesInNestedResponse, ToItemAttributesInRequest } from '../utilities/itemDefinition.js';
4
+ type ItemTypeDefinitionOf<T> = T extends ItemTypeDefinition<any, any, any> ? T : T extends ApiTypes.Item<infer D> ? D : T extends ApiTypes.ItemInNestedResponse<infer D> ? D : T extends RawApiTypes.Item<infer D> ? D : T extends RawApiTypes.ItemInNestedResponse<infer D> ? D : never;
5
5
  /**
6
6
  * Given a record or block you've read from the CMA and one of its field keys,
7
7
  * resolves to the type you'd send back when writing that field — for example,
@@ -13,10 +13,9 @@ type ItemTypeDefinitionOf<T> = T extends ApiTypes.Item<infer D> ? D : T extends
13
13
  *
14
14
  * The first parameter accepts any item-shaped value the CMA produces:
15
15
  * top-level records as well as nested blocks inside a parent record's
16
- * modular-content / structured-text / single-block field.
17
- *
18
- * The resulting type preserves `null`. Every CMA field can be cleared by
19
- * sending `null`, so the type reflects that.
16
+ * modular-content / structured-text / single-block field. You can also pass
17
+ * an `ItemTypeDefinition` directly when you already have the definition type
18
+ * in hand and don't need to round-trip through an `ApiTypes.Item<…>` shape.
20
19
  *
21
20
  * @example
22
21
  * // Read a record with nested blocks, edit one block, write the whole field
@@ -36,6 +35,38 @@ type ItemTypeDefinitionOf<T> = T extends ApiTypes.Item<infer D> ? D : T extends
36
35
  * await client.items.update<LandingPage>(page.id, { sections });
37
36
  */
38
37
  export type FieldValueInRequest<T, K extends keyof ToItemAttributesInRequest<ItemTypeDefinitionOf<T>>> = K extends keyof ToItemAttributesInRequest<ItemTypeDefinitionOf<T>> ? Required<ToItemAttributesInRequest<ItemTypeDefinitionOf<T>>>[K] : never;
38
+ /**
39
+ * Given a record or block you've read from the CMA and one of its field keys,
40
+ * resolves to the field's value type as it appears in a standard (non-nested)
41
+ * response — for example, what you'd read off `record.attributes[fieldKey]`
42
+ * after `client.items.find(id)`.
43
+ *
44
+ * The first parameter accepts any item-shaped value the CMA produces, or an
45
+ * `ItemTypeDefinition` directly.
46
+ *
47
+ * @example
48
+ * // Read nested, then collect just the block IDs for an outline view.
49
+ * const page = await client.items.find<LandingPage>(id, { nested: true });
50
+ * const sectionIds: FieldValue<typeof page, 'sections'> = page.sections.map(
51
+ * (block) => block.id,
52
+ * );
53
+ */
54
+ export type FieldValue<T, K extends keyof ToItemAttributes<ItemTypeDefinitionOf<T>>> = K extends keyof ToItemAttributes<ItemTypeDefinitionOf<T>> ? ToItemAttributes<ItemTypeDefinitionOf<T>>[K] : never;
55
+ /**
56
+ * Given a record or block you've read from the CMA and one of its field keys,
57
+ * resolves to the field's value type in a nested response — i.e. what you'd
58
+ * read off the field after `client.items.find(id, { nested: true })`, where
59
+ * blocks are inlined as full objects instead of ID strings.
60
+ *
61
+ * The first parameter accepts any item-shaped value the CMA produces, or an
62
+ * `ItemTypeDefinition` directly.
63
+ *
64
+ * @example
65
+ * const page = await client.items.find<LandingPage>(id, { nested: true });
66
+ * const sections: FieldValueInNestedResponse<typeof page, 'sections'> = page.sections;
67
+ * // sections elements are full block objects, not ID strings.
68
+ */
69
+ export type FieldValueInNestedResponse<T, K extends keyof ToItemAttributesInNestedResponse<ItemTypeDefinitionOf<T>>> = K extends keyof ToItemAttributesInNestedResponse<ItemTypeDefinitionOf<T>> ? ToItemAttributesInNestedResponse<ItemTypeDefinitionOf<T>>[K] : never;
39
70
  export * from './appearance/index.js';
40
71
  export * from './boolean.js';
41
72
  export * from './color.js';
@@ -3,5 +3,5 @@
3
3
  */
4
4
  export type SanitizedHtmlValidator = {
5
5
  /** Content is actively sanitized before applying the validation */
6
- sanitize_before_validation: boolean;
6
+ sanitize_before_validation?: boolean;
7
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datocms/cma-client",
3
- "version": "5.4.13",
3
+ "version": "5.4.15",
4
4
  "description": "JS client for DatoCMS REST Content Management API",
5
5
  "keywords": [
6
6
  "datocms",
@@ -45,5 +45,5 @@
45
45
  "@datocms/dashboard-client": "^5.4.9",
46
46
  "@types/uuid": "^9.0.7"
47
47
  },
48
- "gitHead": "e2ccb5d21e7c5b25525568581f1b8e1db18cc3b8"
48
+ "gitHead": "c368fd252a0ba33c3b22759b5619781c7a8aba7b"
49
49
  }
@@ -2,8 +2,8 @@
2
2
  * Built-in editor for Color fields.
3
3
  */
4
4
  export type ColorPickerEditorConfiguration = {
5
- /** Should the color picker allow to specify the alpha value? */
6
- enable_alpha: boolean;
7
- /** List of preset colors to offer to the user (hex color strings) */
8
- preset_colors: Array<string>;
5
+ /** Should the color picker allow to specify the alpha value? (default: false) */
6
+ enable_alpha?: boolean;
7
+ /** List of preset colors to offer to the user (hex color strings) (default: []) */
8
+ preset_colors?: Array<string>;
9
9
  };
@@ -2,6 +2,6 @@
2
2
  * Built-in editor for Single block fields.
3
3
  */
4
4
  export type FramedSingleBlockEditorConfiguration = {
5
- /** Whether you want block record collapsed by default or not */
5
+ /** Whether you want block record collapsed by default or not (default: false) */
6
6
  start_collapsed?: boolean;
7
7
  };
@@ -2,8 +2,8 @@
2
2
  * Markdown editor for Multiple-paragraph text fields.
3
3
  */
4
4
  export type MarkdownEditorConfiguration = {
5
- /** Specify which buttons the toolbar should have */
6
- toolbar: Array<
5
+ /** Specify which buttons the toolbar should have (default: all allowed values) */
6
+ toolbar?: Array<
7
7
  | 'heading'
8
8
  | 'bold'
9
9
  | 'italic'
@@ -2,6 +2,6 @@
2
2
  * Built-in editor for Modular content fields.
3
3
  */
4
4
  export type RichTextEditorConfiguration = {
5
- /** Whether you want block records collapsed by default or not */
5
+ /** Whether you want block records collapsed by default or not (default: false) */
6
6
  start_collapsed?: boolean;
7
7
  };
@@ -2,12 +2,12 @@
2
2
  * Built-in editor for SEO fields.
3
3
  */
4
4
  export type SeoEditorConfiguration = {
5
- /** Specify which fields of the SEO input should be visible to editors */
6
- fields: Array<
5
+ /** Specify which fields of the SEO input should be visible to editors (default: all allowed values) */
6
+ fields?: Array<
7
7
  'title' | 'description' | 'image' | 'no_index' | 'twitter_card'
8
8
  >;
9
- /** Specify which previews should be visible to editors */
10
- previews: Array<
9
+ /** Specify which previews should be visible to editors (default: all allowed values) */
10
+ previews?: Array<
11
11
  | 'google'
12
12
  | 'twitter'
13
13
  | 'slack'
@@ -2,8 +2,8 @@
2
2
  * Simple textual input for Single-line string fields.
3
3
  */
4
4
  export type SingleLineEditorConfiguration = {
5
- /** Indicates if the field should be shown bigger, as a field representing a heading */
6
- heading: boolean;
5
+ /** Indicates if the field should be shown bigger, as a field representing a heading (default: false) */
6
+ heading?: boolean;
7
7
  /** A placeholder that will be shown in the editor's input to provide editors with an example */
8
8
  placeholder?: string;
9
9
  };
@@ -2,20 +2,20 @@
2
2
  * Built-in editor for Structured text fields.
3
3
  */
4
4
  export type StructuredTextEditorConfiguration = {
5
- /** Specify which nodes the field should allow */
6
- nodes: Array<
5
+ /** Specify which nodes the field should allow (default: all allowed values) */
6
+ nodes?: Array<
7
7
  'blockquote' | 'code' | 'heading' | 'link' | 'list' | 'thematicBreak'
8
8
  >;
9
- /** Specify which marks the field should allow */
10
- marks: Array<
9
+ /** Specify which marks the field should allow (default: all allowed values) */
10
+ marks?: Array<
11
11
  'strong' | 'emphasis' | 'underline' | 'strikethrough' | 'code' | 'highlight'
12
12
  >;
13
- /** If nodes includes "heading", specify which heading levels the field should allow (numbers between 1 and 6) */
14
- heading_levels: Array<1 | 2 | 3 | 4 | 5 | 6>;
15
- /** Whether you want block nodes collapsed by default or not */
13
+ /** If nodes includes "heading", specify which heading levels the field should allow (numbers between 1 and 6) (default: all allowed values) */
14
+ heading_levels?: Array<1 | 2 | 3 | 4 | 5 | 6>;
15
+ /** Whether you want block nodes collapsed by default or not (default: false) */
16
16
  blocks_start_collapsed?: boolean;
17
- /** Whether you want to show the "Open this link in a new tab?" checkbox, that fills in the target: "_blank" meta attribute for links */
17
+ /** Whether you want to show the "Open this link in a new tab?" checkbox, that fills in the target: "_blank" meta attribute for links (default: true) */
18
18
  show_links_target_blank?: boolean;
19
- /** Whether you want to show the complete meta editor for links */
19
+ /** Whether you want to show the complete meta editor for links (default: false) */
20
20
  show_links_meta_editor?: boolean;
21
21
  };
@@ -2,8 +2,8 @@
2
2
  * HTML editor for Multiple-paragraph text fields.
3
3
  */
4
4
  export type WysiwygEditorConfiguration = {
5
- /** Specify which buttons the toolbar should have */
6
- toolbar: Array<
5
+ /** Specify which buttons the toolbar should have (default: ['format', 'bold', 'italic', 'strikethrough', 'ordered_list', 'unordered_list', 'quote', 'table', 'link', 'image', 'show_source', 'fullscreen']) */
6
+ toolbar?: Array<
7
7
  | 'format'
8
8
  | 'bold'
9
9
  | 'italic'
@@ -1,16 +1,23 @@
1
1
  import type * as ApiTypes from '../generated/ApiTypes.js';
2
2
  import type * as RawApiTypes from '../generated/RawApiTypes.js';
3
- import type { ToItemAttributesInRequest } from '../utilities/itemDefinition.js';
3
+ import type {
4
+ ItemTypeDefinition,
5
+ ToItemAttributes,
6
+ ToItemAttributesInNestedResponse,
7
+ ToItemAttributesInRequest,
8
+ } from '../utilities/itemDefinition.js';
4
9
 
5
- type ItemTypeDefinitionOf<T> = T extends ApiTypes.Item<infer D>
6
- ? D
7
- : T extends ApiTypes.ItemInNestedResponse<infer D>
10
+ type ItemTypeDefinitionOf<T> = T extends ItemTypeDefinition<any, any, any>
11
+ ? T
12
+ : T extends ApiTypes.Item<infer D>
8
13
  ? D
9
- : T extends RawApiTypes.Item<infer D>
14
+ : T extends ApiTypes.ItemInNestedResponse<infer D>
10
15
  ? D
11
- : T extends RawApiTypes.ItemInNestedResponse<infer D>
16
+ : T extends RawApiTypes.Item<infer D>
12
17
  ? D
13
- : never;
18
+ : T extends RawApiTypes.ItemInNestedResponse<infer D>
19
+ ? D
20
+ : never;
14
21
 
15
22
  /**
16
23
  * Given a record or block you've read from the CMA and one of its field keys,
@@ -23,10 +30,9 @@ type ItemTypeDefinitionOf<T> = T extends ApiTypes.Item<infer D>
23
30
  *
24
31
  * The first parameter accepts any item-shaped value the CMA produces:
25
32
  * top-level records as well as nested blocks inside a parent record's
26
- * modular-content / structured-text / single-block field.
27
- *
28
- * The resulting type preserves `null`. Every CMA field can be cleared by
29
- * sending `null`, so the type reflects that.
33
+ * modular-content / structured-text / single-block field. You can also pass
34
+ * an `ItemTypeDefinition` directly when you already have the definition type
35
+ * in hand and don't need to round-trip through an `ApiTypes.Item<…>` shape.
30
36
  *
31
37
  * @example
32
38
  * // Read a record with nested blocks, edit one block, write the whole field
@@ -52,6 +58,50 @@ export type FieldValueInRequest<
52
58
  ? Required<ToItemAttributesInRequest<ItemTypeDefinitionOf<T>>>[K]
53
59
  : never;
54
60
 
61
+ /**
62
+ * Given a record or block you've read from the CMA and one of its field keys,
63
+ * resolves to the field's value type as it appears in a standard (non-nested)
64
+ * response — for example, what you'd read off `record.attributes[fieldKey]`
65
+ * after `client.items.find(id)`.
66
+ *
67
+ * The first parameter accepts any item-shaped value the CMA produces, or an
68
+ * `ItemTypeDefinition` directly.
69
+ *
70
+ * @example
71
+ * // Read nested, then collect just the block IDs for an outline view.
72
+ * const page = await client.items.find<LandingPage>(id, { nested: true });
73
+ * const sectionIds: FieldValue<typeof page, 'sections'> = page.sections.map(
74
+ * (block) => block.id,
75
+ * );
76
+ */
77
+ export type FieldValue<
78
+ T,
79
+ K extends keyof ToItemAttributes<ItemTypeDefinitionOf<T>>,
80
+ > = K extends keyof ToItemAttributes<ItemTypeDefinitionOf<T>>
81
+ ? ToItemAttributes<ItemTypeDefinitionOf<T>>[K]
82
+ : never;
83
+
84
+ /**
85
+ * Given a record or block you've read from the CMA and one of its field keys,
86
+ * resolves to the field's value type in a nested response — i.e. what you'd
87
+ * read off the field after `client.items.find(id, { nested: true })`, where
88
+ * blocks are inlined as full objects instead of ID strings.
89
+ *
90
+ * The first parameter accepts any item-shaped value the CMA produces, or an
91
+ * `ItemTypeDefinition` directly.
92
+ *
93
+ * @example
94
+ * const page = await client.items.find<LandingPage>(id, { nested: true });
95
+ * const sections: FieldValueInNestedResponse<typeof page, 'sections'> = page.sections;
96
+ * // sections elements are full block objects, not ID strings.
97
+ */
98
+ export type FieldValueInNestedResponse<
99
+ T,
100
+ K extends keyof ToItemAttributesInNestedResponse<ItemTypeDefinitionOf<T>>,
101
+ > = K extends keyof ToItemAttributesInNestedResponse<ItemTypeDefinitionOf<T>>
102
+ ? ToItemAttributesInNestedResponse<ItemTypeDefinitionOf<T>>[K]
103
+ : never;
104
+
55
105
  export * from './appearance/index.js';
56
106
  export * from './boolean.js';
57
107
  export * from './color.js';
@@ -3,5 +3,5 @@
3
3
  */
4
4
  export type SanitizedHtmlValidator = {
5
5
  /** Content is actively sanitized before applying the validation */
6
- sanitize_before_validation: boolean;
6
+ sanitize_before_validation?: boolean;
7
7
  };
@@ -151,7 +151,7 @@ export class Client {
151
151
  ...this.config,
152
152
  ...options,
153
153
  logFn: this.config.logFn || console.log,
154
- userAgent: '@datocms/cma-client v5.4.13',
154
+ userAgent: '@datocms/cma-client v5.4.15',
155
155
  baseUrl: this.baseUrl,
156
156
  preCallStack: new Error().stack,
157
157
  extraHeaders: {