storyblok 3.28.1 → 3.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +86 -0
  2. package/{src/tasks/templates/teaser.js → dist/chunks/teaser.mjs} +4 -2
  3. package/dist/cli.d.mts +69 -0
  4. package/dist/cli.d.ts +69 -0
  5. package/dist/cli.mjs +3868 -0
  6. package/package.json +19 -7
  7. package/.eslintrc.js +0 -23
  8. package/.github/.dependabot.yml +0 -13
  9. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -27
  10. package/.github/workflows/release.yml +0 -23
  11. package/.github/workflows/unit-tests.yml +0 -22
  12. package/__mocks__/axios.js +0 -31
  13. package/__mocks__/fs-extra.js +0 -63
  14. package/__mocks__/fs.js +0 -51
  15. package/pull_request_template.md +0 -29
  16. package/src/cli.js +0 -540
  17. package/src/constants.js +0 -29
  18. package/src/tasks/delete-component.js +0 -32
  19. package/src/tasks/delete-components.js +0 -112
  20. package/src/tasks/delete-datasources.js +0 -41
  21. package/src/tasks/import/import.js +0 -40
  22. package/src/tasks/import/utils.js +0 -234
  23. package/src/tasks/index.js +0 -16
  24. package/src/tasks/list-spaces.js +0 -63
  25. package/src/tasks/migrations/generate.js +0 -61
  26. package/src/tasks/migrations/rollback.js +0 -70
  27. package/src/tasks/migrations/run.js +0 -159
  28. package/src/tasks/migrations/utils.js +0 -336
  29. package/src/tasks/pull-components.js +0 -84
  30. package/src/tasks/pull-languages.js +0 -39
  31. package/src/tasks/push-components.js +0 -207
  32. package/src/tasks/quickstart.js +0 -91
  33. package/src/tasks/scaffold.js +0 -29
  34. package/src/tasks/sync-commands/component-groups.js +0 -140
  35. package/src/tasks/sync-commands/components.js +0 -263
  36. package/src/tasks/sync-commands/datasources.js +0 -305
  37. package/src/tasks/sync.js +0 -288
  38. package/src/tasks/templates/migration-file.js +0 -8
  39. package/src/utils/api.js +0 -316
  40. package/src/utils/capitalize.js +0 -12
  41. package/src/utils/creds.js +0 -83
  42. package/src/utils/find-by-property.js +0 -12
  43. package/src/utils/get-questions.js +0 -317
  44. package/src/utils/index.js +0 -11
  45. package/src/utils/last-step.js +0 -108
  46. package/src/utils/parse-error.js +0 -25
  47. package/src/utils/presets-lib.js +0 -137
  48. package/src/utils/region.js +0 -7
  49. package/src/utils/replace.js +0 -23
  50. package/src/utils/save-file-factory.js +0 -16
  51. package/tests/constants.js +0 -310
  52. package/tests/units/delete-component.spec.js +0 -53
  53. package/tests/units/delete-components.spec.js +0 -94
  54. package/tests/units/generate.spec.js +0 -183
  55. package/tests/units/import.spec.js +0 -112
  56. package/tests/units/is-authorized.spec.js +0 -37
  57. package/tests/units/list-spaces.spec.js +0 -52
  58. package/tests/units/login.spec.js +0 -37
  59. package/tests/units/logout.spec.js +0 -19
  60. package/tests/units/migrations/change_teaser_date.js +0 -5
  61. package/tests/units/migrations/change_teaser_headline.js +0 -4
  62. package/tests/units/migrations/change_teaser_subtitle.js +0 -3
  63. package/tests/units/pull-components.spec.js +0 -149
  64. package/tests/units/pull-languages.spec.js +0 -62
  65. package/tests/units/push-components.spec.js +0 -86
  66. package/tests/units/quickstart.spec.js +0 -76
  67. package/tests/units/run-migration.spec.js +0 -538
  68. package/tests/units/scaffold.spec.js +0 -77
  69. package/tests/units/signup.spec.js +0 -36
  70. package/tests/units/sync-components.spec.js +0 -369
  71. package/tests/units/sync.spec.js +0 -68
package/README.md CHANGED
@@ -554,6 +554,92 @@ module.exports = function (block) {
554
554
  }
555
555
  ```
556
556
 
557
+ ## Typescript
558
+ It is possible to generate Typescript type definitions for your Storyblok components. The type definitions are based on the components' JSON Schema that can be retrieved with the [pull-components](#pull-components) command.
559
+
560
+ ### generate-typescript-typedefs
561
+
562
+ Generate a file with the type definitions for the specified components' JSON Schemas.
563
+
564
+ ```sh
565
+ $ storyblok generate-typescript-typedefs
566
+ --sourceFilePaths <PATHS>
567
+ --destinationFilePath <PATH>
568
+ --typeNamesPrefix <STRING>
569
+ --typeNamesSuffix <STRING>
570
+ --JSONSchemaToTSOptionsPath <PATH>
571
+ --customFieldTypesParserPath <PATH>
572
+ ```
573
+
574
+ #### Options
575
+
576
+ * `sourceFilePaths` <sub>(alias `source`)</sub> : Path(s) to the components JSON file(s) as comma separated values
577
+ * `destinationFilePath` <sub>(alias `target`) *optional*</sub> : Path to the Typescript file that will be generated (*default*: `storyblok-component-types.d.ts`)
578
+ * `typeNamesPrefix` <sub>(alias `titlePrefix`) *optional*</sub> : A prefix that will be prepended to all the names of the generated types
579
+ * `typeNamesSuffix` <sub>(alias `titleSuffix`) *optional*</sub> : A suffix that will be appended to all the names of the generated types (*default*: `Storyblok`)
580
+ * `JSONSchemaToTSOptionsPath` <sub>(alias `compilerOptions`) *optional*</sub> : Path to a JSON file with a list of options supported by `json-schema-to-typescript`
581
+ * `customFieldTypesParserPath` <sub>(alias `customTypeParser`) *optional*</sub> : Path to the parser file for Custom Field Types
582
+
583
+ #### Examples
584
+
585
+ ```sh
586
+ # Generate typedefs for the components retrieved for the space `12345` via the `storyblok pull-components` command
587
+ $ storyblok generate-typescript-typedefs --sourceFilePaths ./components.12345.json
588
+
589
+ # Generate typedefs for multiple components sources
590
+ $ storyblok generate-typescript-typedefs --sourceFilePaths ./fooComponent-12345.json,./barComponent-12345.json
591
+
592
+ # Custom path for the typedefs file
593
+ $ storyblok generate-typescript-typedefs --sourceFilePaths ./components.12345.json --destinationFilePath ./types/my-custom-type-file.d.ts
594
+
595
+ # Provide customized options for the JSON-schema-to-typescript lib
596
+ $ storyblok generate-typescript-typedefs --sourceFilePaths ./components.12345.json --JSONSchemaToTSOptionsPath ./PathToJSONFileWithCustomOptions.json
597
+
598
+ # Provide a custom field types parser
599
+ $ storyblok generate-typescript-typedefs --sourceFilePaths ./components.12345.json --customFieldTypesParserPath ./customFieldTypesParser.js
600
+
601
+ ```
602
+
603
+ ##### JSON Schema to Typescript options
604
+ This script uses the `json-schema-to-typescript` library under the hood. Values of the [JSON Schema to Typescript options](https://www.npmjs.com/package/json-schema-to-typescript#options) can be customized providing a JSON file to the `JSONSchemaToTSOptionsPath`.
605
+
606
+ The default values used for the `storyblok generate-typescript-typedefs` command are the same defaults for the library except for two properties:
607
+ * `bannerComment` - The default value is `""` to remove noise from the generated Typedefs file
608
+ * `unknownAny` - The default value is `false` because it can help a smoother Typescript adoption on a JS project
609
+
610
+ Example `JSONSchemaToTSOptions` JSON file to remove `additionalProperties` from the generated type definitions:
611
+
612
+ ```json
613
+ {
614
+ "additionalProperties": false,
615
+ }
616
+ ```
617
+
618
+ ##### Custom Field Types parser
619
+ Storyblok [Custom Field Types](https://www.storyblok.com/docs/plugins/field-plugins/introduction) do not have inherent JSONSchema definitions. To overcome this issue, you can provide a path to a script exporting a parser function that should render a [JSONSchema Node](https://json-schema.org/learn/getting-started-step-by-step#define-properties) for each of your Custom Field Types. The parser function should be exported as a default export, like in the following example:
620
+ ```js
621
+ export default function (key, obj) {
622
+ switch (obj.field_type) {
623
+ case 'my-custom-field-type-name':
624
+ return {
625
+ [key]: {
626
+ type: 'object',
627
+ properties: {
628
+ color: { type: 'string' }
629
+ },
630
+ required: ['color']
631
+ }
632
+ }
633
+ default:
634
+ return {}
635
+ }
636
+ }
637
+ ```
638
+
639
+
640
+
641
+
642
+
557
643
  ## You're looking for a headstart?
558
644
 
559
645
  Check out our guides for client side apps (VueJS, Angular, React, ...), static site (Jekyll, NuxtJs, ...), dynamic site examples (Node, PHP, Python, Laravel, ...) on our [Getting Started](https://www.storyblok.com/getting-started) page.
@@ -1,4 +1,4 @@
1
- module.exports = `<div class="quickstart__teaser">
1
+ const teaser = `<div class="quickstart__teaser">
2
2
  <!--
3
3
  The _editable attribute makes the next
4
4
  DOM-element clickable so the sidebar can
@@ -22,4 +22,6 @@ module.exports = `<div class="quickstart__teaser">
22
22
  <!-- HINT: Try to change something and the browser window in Storyblok will automatically refresh. -->
23
23
  </h3>
24
24
  </div>
25
- </div>`
25
+ </div>`;
26
+
27
+ export { teaser as default };
package/dist/cli.d.mts ADDED
@@ -0,0 +1,69 @@
1
+ import { Options, JSONSchema } from 'json-schema-to-typescript';
2
+ export { ISbStoryData } from 'storyblok-js-client';
3
+
4
+ type StoryblokProvidedPropertyType = "asset" | "multiasset" | "multilink" | "table" | "richtext";
5
+ type ComponentPropertySchemaType = StoryblokProvidedPropertyType | "array" | "bloks" | "boolean" | "custom" | "datetime" | "image" | "markdown" | "number" | "option" | "options" | "text" | "textarea";
6
+ type JSONSchemaToTSOptions = Partial<Options>;
7
+ interface GenerateTypescriptTypedefsCLIOptions {
8
+ sourceFilePaths: string[];
9
+ destinationFilePath?: string;
10
+ typeNamesPrefix?: string;
11
+ typeNamesSuffix?: string;
12
+ customFieldTypesParserPath?: string;
13
+ JSONSchemaToTSOptionsPath?: string;
14
+ }
15
+ interface ComponentPropertySchemaOption {
16
+ _uid: string;
17
+ name: string;
18
+ value: string;
19
+ }
20
+ type ComponentPropertySchema = {
21
+ asset_link_type?: boolean;
22
+ component_group_whitelist?: string[];
23
+ component_whitelist?: string[];
24
+ email_link_type?: boolean;
25
+ exclude_empty_option?: boolean;
26
+ filter_content_type?: string[];
27
+ key: string;
28
+ options?: ComponentPropertySchemaOption[];
29
+ pos: number;
30
+ restrict_components?: boolean;
31
+ restrict_type?: "groups" | "";
32
+ source?: "internal" | "external" | "internal_stories" | "internal_languages";
33
+ type: ComponentPropertySchemaType;
34
+ use_uuid?: boolean;
35
+ };
36
+ type ComponentPropertyTypeAnnotation = {
37
+ tsType: string | string[];
38
+ } | {
39
+ type: string | string[];
40
+ enum: string[];
41
+ } | {
42
+ type: string | string[];
43
+ } | {
44
+ type: "array";
45
+ items: {
46
+ type: string | string[];
47
+ };
48
+ } | {
49
+ type: "array";
50
+ items: {
51
+ enum: string[];
52
+ };
53
+ };
54
+ type GenerateTSTypedefsFromComponentsJSONSchemasOptions = {
55
+ sourceFilePaths: string[];
56
+ destinationFilePath: string;
57
+ typeNamesPrefix?: string;
58
+ typeNamesSuffix?: string;
59
+ customFieldTypesParserPath?: string;
60
+ JSONSchemaToTSCustomOptions: JSONSchemaToTSOptions;
61
+ };
62
+ type CustomTypeParser = (_typeName: string, _schema: ComponentPropertySchema) => Record<string, any>;
63
+ type GetStoryblokProvidedPropertyTypeSchemaFn = (title: string) => JSONSchema;
64
+ type ComponentGroupsAndNamesObject = {
65
+ componentGroups: Map<string, Set<string>>;
66
+ componentNames: Set<string>;
67
+ };
68
+
69
+ export type { ComponentGroupsAndNamesObject, ComponentPropertySchema, ComponentPropertySchemaOption, ComponentPropertySchemaType, ComponentPropertyTypeAnnotation, CustomTypeParser, GenerateTSTypedefsFromComponentsJSONSchemasOptions, GenerateTypescriptTypedefsCLIOptions, GetStoryblokProvidedPropertyTypeSchemaFn, JSONSchemaToTSOptions, StoryblokProvidedPropertyType };
package/dist/cli.d.ts ADDED
@@ -0,0 +1,69 @@
1
+ import { Options, JSONSchema } from 'json-schema-to-typescript';
2
+ export { ISbStoryData } from 'storyblok-js-client';
3
+
4
+ type StoryblokProvidedPropertyType = "asset" | "multiasset" | "multilink" | "table" | "richtext";
5
+ type ComponentPropertySchemaType = StoryblokProvidedPropertyType | "array" | "bloks" | "boolean" | "custom" | "datetime" | "image" | "markdown" | "number" | "option" | "options" | "text" | "textarea";
6
+ type JSONSchemaToTSOptions = Partial<Options>;
7
+ interface GenerateTypescriptTypedefsCLIOptions {
8
+ sourceFilePaths: string[];
9
+ destinationFilePath?: string;
10
+ typeNamesPrefix?: string;
11
+ typeNamesSuffix?: string;
12
+ customFieldTypesParserPath?: string;
13
+ JSONSchemaToTSOptionsPath?: string;
14
+ }
15
+ interface ComponentPropertySchemaOption {
16
+ _uid: string;
17
+ name: string;
18
+ value: string;
19
+ }
20
+ type ComponentPropertySchema = {
21
+ asset_link_type?: boolean;
22
+ component_group_whitelist?: string[];
23
+ component_whitelist?: string[];
24
+ email_link_type?: boolean;
25
+ exclude_empty_option?: boolean;
26
+ filter_content_type?: string[];
27
+ key: string;
28
+ options?: ComponentPropertySchemaOption[];
29
+ pos: number;
30
+ restrict_components?: boolean;
31
+ restrict_type?: "groups" | "";
32
+ source?: "internal" | "external" | "internal_stories" | "internal_languages";
33
+ type: ComponentPropertySchemaType;
34
+ use_uuid?: boolean;
35
+ };
36
+ type ComponentPropertyTypeAnnotation = {
37
+ tsType: string | string[];
38
+ } | {
39
+ type: string | string[];
40
+ enum: string[];
41
+ } | {
42
+ type: string | string[];
43
+ } | {
44
+ type: "array";
45
+ items: {
46
+ type: string | string[];
47
+ };
48
+ } | {
49
+ type: "array";
50
+ items: {
51
+ enum: string[];
52
+ };
53
+ };
54
+ type GenerateTSTypedefsFromComponentsJSONSchemasOptions = {
55
+ sourceFilePaths: string[];
56
+ destinationFilePath: string;
57
+ typeNamesPrefix?: string;
58
+ typeNamesSuffix?: string;
59
+ customFieldTypesParserPath?: string;
60
+ JSONSchemaToTSCustomOptions: JSONSchemaToTSOptions;
61
+ };
62
+ type CustomTypeParser = (_typeName: string, _schema: ComponentPropertySchema) => Record<string, any>;
63
+ type GetStoryblokProvidedPropertyTypeSchemaFn = (title: string) => JSONSchema;
64
+ type ComponentGroupsAndNamesObject = {
65
+ componentGroups: Map<string, Set<string>>;
66
+ componentNames: Set<string>;
67
+ };
68
+
69
+ export type { ComponentGroupsAndNamesObject, ComponentPropertySchema, ComponentPropertySchemaOption, ComponentPropertySchemaType, ComponentPropertyTypeAnnotation, CustomTypeParser, GenerateTSTypedefsFromComponentsJSONSchemasOptions, GenerateTypescriptTypedefsCLIOptions, GetStoryblokProvidedPropertyTypeSchemaFn, JSONSchemaToTSOptions, StoryblokProvidedPropertyType };