@stackbit/sdk 0.2.39-alpha.2 → 0.3.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.
Files changed (65) hide show
  1. package/dist/analyzer/site-analyzer.d.ts.map +1 -1
  2. package/dist/analyzer/site-analyzer.js +3 -1
  3. package/dist/analyzer/site-analyzer.js.map +1 -1
  4. package/dist/config/config-errors.d.ts +3 -0
  5. package/dist/config/config-errors.d.ts.map +1 -1
  6. package/dist/config/config-errors.js +7 -2
  7. package/dist/config/config-errors.js.map +1 -1
  8. package/dist/config/config-loader-esbuild.d.ts +3 -14
  9. package/dist/config/config-loader-esbuild.d.ts.map +1 -1
  10. package/dist/config/config-loader-esbuild.js +19 -2
  11. package/dist/config/config-loader-esbuild.js.map +1 -1
  12. package/dist/config/config-loader-static.d.ts +14 -0
  13. package/dist/config/config-loader-static.d.ts.map +1 -0
  14. package/dist/config/config-loader-static.js +170 -0
  15. package/dist/config/config-loader-static.js.map +1 -0
  16. package/dist/config/config-loader-utils.d.ts +34 -0
  17. package/dist/config/config-loader-utils.d.ts.map +1 -0
  18. package/dist/config/config-loader-utils.js +211 -0
  19. package/dist/config/config-loader-utils.js.map +1 -0
  20. package/dist/config/config-loader.d.ts +13 -9
  21. package/dist/config/config-loader.d.ts.map +1 -1
  22. package/dist/config/config-loader.js +174 -198
  23. package/dist/config/config-loader.js.map +1 -1
  24. package/dist/config/config-schema/style-field-schema.d.ts.map +1 -1
  25. package/dist/config/config-schema/style-field-schema.js.map +1 -1
  26. package/dist/config/config-schema.d.ts +2 -2
  27. package/dist/config/config-schema.d.ts.map +1 -1
  28. package/dist/config/config-schema.js +5 -6
  29. package/dist/config/config-schema.js.map +1 -1
  30. package/dist/config/config-types.d.ts +32 -2
  31. package/dist/config/config-types.d.ts.map +1 -1
  32. package/dist/config/config-validator.d.ts +5 -3
  33. package/dist/config/config-validator.d.ts.map +1 -1
  34. package/dist/config/config-validator.js.map +1 -1
  35. package/dist/config/config-writer.d.ts +1 -4
  36. package/dist/config/config-writer.d.ts.map +1 -1
  37. package/dist/config/config-writer.js +3 -27
  38. package/dist/config/config-writer.js.map +1 -1
  39. package/dist/content/content-schema.js +5 -6
  40. package/dist/content/content-schema.js.map +1 -1
  41. package/dist/index.d.ts +4 -2
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +6 -2
  44. package/dist/index.js.map +1 -1
  45. package/dist/utils/index.d.ts +1 -1
  46. package/dist/utils/index.d.ts.map +1 -1
  47. package/dist/utils/model-extender.d.ts +1 -1
  48. package/dist/utils/model-extender.d.ts.map +1 -1
  49. package/dist/utils/model-extender.js.map +1 -1
  50. package/package.json +4 -3
  51. package/src/analyzer/site-analyzer.ts +3 -1
  52. package/src/config/config-errors.ts +7 -1
  53. package/src/config/config-loader-esbuild.ts +24 -19
  54. package/src/config/config-loader-static.ts +210 -0
  55. package/src/config/config-loader-utils.ts +253 -0
  56. package/src/config/config-loader.ts +209 -236
  57. package/src/config/config-schema/style-field-schema.ts +1 -4
  58. package/src/config/config-schema.ts +17 -18
  59. package/src/config/config-types.ts +31 -2
  60. package/src/config/config-validator.ts +5 -3
  61. package/src/config/config-writer.ts +2 -30
  62. package/src/content/content-schema.ts +17 -18
  63. package/src/index.ts +4 -2
  64. package/src/utils/index.ts +1 -1
  65. package/src/utils/model-extender.ts +2 -2
@@ -59,10 +59,7 @@ const stylePropsSchema = Joi.object({
59
59
  label: Joi.string().required()
60
60
  })
61
61
  ),
62
- fontSize: stylePropWithAll(
63
- Joi.string().pattern(sizePattern),
64
- arrayOf(Joi.string().pattern(sizePattern), Joi.number().integer().min(0).multiple(1))
65
- ),
62
+ fontSize: stylePropWithAll(Joi.string().pattern(sizePattern), arrayOf(Joi.string().pattern(sizePattern), Joi.number().integer().min(0).multiple(1))),
66
63
  fontStyle: arrayOfStringsWithAll(...STYLE_PROPS_VALUES.fontStyle),
67
64
  fontWeight: stylePropWithAll(
68
65
  Joi.string().pattern(fontWeightPattern),
@@ -13,7 +13,7 @@ import {
13
13
  PresetSourceFiles,
14
14
  SanityImport,
15
15
  YamlBaseModel,
16
- YamlConfig,
16
+ RawConfig,
17
17
  YamlConfigModel,
18
18
  YamlDataModel,
19
19
  YamlModel,
@@ -28,7 +28,7 @@ import {
28
28
  ModelsSourceSanity
29
29
  } from './config-types';
30
30
 
31
- function getConfigFromValidationState(state: Joi.State): YamlConfig {
31
+ function getConfigFromValidationState(state: Joi.State): RawConfig {
32
32
  return _.last(state.ancestors)!;
33
33
  }
34
34
 
@@ -128,7 +128,7 @@ const validReferenceFieldGroups = Joi.string()
128
128
  errors: { wrap: { label: false } }
129
129
  });
130
130
 
131
- function getModelNamesForGroup(group: string, config: YamlConfig) {
131
+ function getModelNamesForGroup(group: string, config: RawConfig) {
132
132
  const models = config.models ?? {};
133
133
  return _.reduce(
134
134
  models,
@@ -234,7 +234,9 @@ const contentfulImportSchema = Joi.object<ContentfulImport>({
234
234
  uploadAssets: Joi.boolean(),
235
235
  assetsDirectory: Joi.string(),
236
236
  spaceIdEnvVar: Joi.string(),
237
- accessTokenEnvVar: Joi.string()
237
+ accessTokenEnvVar: Joi.string(),
238
+ deliveryTokenEnvVar: Joi.string(),
239
+ previewTokenEnvVar: Joi.string()
238
240
  }).and('uploadAssets', 'assetsDirectory');
239
241
 
240
242
  const sanityImportSchema = Joi.object<SanityImport>({
@@ -263,9 +265,7 @@ const presetSourceFilesSchema = Joi.object<PresetSourceFiles>({
263
265
  const presetSourceSchema = Joi.object<PresetSource>({
264
266
  type: Joi.string().valid('files').required()
265
267
  }).when('.type', {
266
- switch: [
267
- { is: 'files', then: presetSourceFilesSchema }
268
- ]
268
+ switch: [{ is: 'files', then: presetSourceFilesSchema }]
269
269
  });
270
270
 
271
271
  const modelsSourceFilesSchema = Joi.object<ModelsSourceFiles>({
@@ -460,16 +460,15 @@ const listItemsSchema = Joi.object({
460
460
  const listFieldPartialSchema = Joi.object({
461
461
  type: Joi.string().valid('list').required(),
462
462
  controlType: Joi.string().valid('checkbox'),
463
- items: Joi.any()
464
- .when('..controlType', {
465
- switch: [
466
- {
467
- is: 'checkbox',
468
- then: enumFieldPartialSchema
469
- }
470
- ],
471
- otherwise: listItemsSchema
472
- })
463
+ items: Joi.any().when('..controlType', {
464
+ switch: [
465
+ {
466
+ is: 'checkbox',
467
+ then: enumFieldPartialSchema
468
+ }
469
+ ],
470
+ otherwise: listItemsSchema
471
+ })
473
472
  });
474
473
 
475
474
  const fieldSchema: Joi.ObjectSchema<Field> = fieldCommonPropsSchema.when('.type', {
@@ -720,7 +719,7 @@ const modelsSchema = Joi.object<ModelMap>()
720
719
  errors: { wrap: { label: false } }
721
720
  });
722
721
 
723
- export const stackbitConfigSchema = Joi.object<YamlConfig>({
722
+ export const stackbitConfigSchema = Joi.object<RawConfig>({
724
723
  stackbitVersion: Joi.string().required(),
725
724
  ssgName: Joi.string().valid(...SSG_NAMES),
726
725
  ssgVersion: Joi.string(),
@@ -2,19 +2,27 @@ import { StricterUnion } from '../utils';
2
2
  import { CMS_NAMES, FIELD_TYPES, SSG_NAMES, STYLE_PROPS } from './config-consts';
3
3
 
4
4
  export interface Config extends BaseConfig {
5
+ stackbitVersion: string;
5
6
  models: Model[];
6
7
  presets?: Record<string, Preset>;
8
+ hcrHandled?: boolean;
9
+ internalStackbitRunnerOptions?: SSGRunOptions;
10
+ dirPath: string;
11
+ filePath: string;
7
12
  }
8
13
 
9
- export interface YamlConfig extends BaseConfig {
14
+ export interface RawConfig extends BaseConfig {
15
+ stackbitVersion?: string;
10
16
  models?: ModelMap;
11
17
  }
12
18
 
13
19
  interface BaseConfig {
14
- stackbitVersion: string;
15
20
  ssgName?: typeof SSG_NAMES[number];
16
21
  ssgVersion?: string;
17
22
  nodeVersion?: string;
23
+ postGitCloneCommand?: string;
24
+ preInstallCommand?: string;
25
+ postInstallCommand?: string;
18
26
  devCommand?: string;
19
27
  cmsName?: typeof CMS_NAMES[number];
20
28
  import?: Import;
@@ -33,6 +41,16 @@ interface BaseConfig {
33
41
  contentModels?: ContentModelMap;
34
42
  presetSource?: PresetSource;
35
43
  modelsSource?: ModelsSource;
44
+ presetReferenceBehavior?: 'copyReference' | 'duplicateContents';
45
+ nonDuplicatableModels?: string[];
46
+ duplicatableModels?: string[];
47
+ contentSources?: any[]; // TODO: set to ContentSourceInterface[], move it to @stackbit/types first
48
+ mapModels?: (options: { models: Model[]; contentSourceType: string; contentSourceProjectId: string }) => Model[];
49
+
50
+ // DEPRECATED
51
+ noEncodeFields?: string[]; // DEPRECATED, for backward compatibility and typescript support
52
+ omitFields?: string[]; // DEPRECATED, for backward compatibility and typescript support
53
+ encodedFieldTypes?: string[]; // DEPRECATED, for backward compatibility and typescript support
36
54
  }
37
55
 
38
56
  export type Import = ContentfulImport | SanityImport;
@@ -44,6 +62,8 @@ export interface ContentfulImport {
44
62
  assetsDirectory?: string;
45
63
  spaceIdEnvVar?: string;
46
64
  accessTokenEnvVar?: string;
65
+ deliveryTokenEnvVar?: string;
66
+ previewTokenEnvVar?: string;
47
67
  }
48
68
 
49
69
  export interface SanityImport {
@@ -120,6 +140,15 @@ export interface Preset {
120
140
  data: Record<string, any>;
121
141
  }
122
142
 
143
+ export interface SSGRunOptions {
144
+ displayName?: string;
145
+ triggerInstallFiles?: string[];
146
+ directPaths?: string[];
147
+ patterns?: {
148
+ doneStart?: string[];
149
+ };
150
+ }
151
+
123
152
  /*******************
124
153
  *** Model Types ***
125
154
  *******************/
@@ -3,14 +3,16 @@ import Joi from 'joi';
3
3
 
4
4
  import { stackbitConfigSchema, contentModelsSchema } from './config-schema';
5
5
  import { ConfigValidationError } from './config-errors';
6
+ import { RawConfigWithPaths } from './config-loader-utils';
7
+ import { ContentModelMap, ModelMap } from './config-types';
6
8
 
7
9
  export interface ConfigValidationResult {
8
- value: any;
10
+ value: RawConfigWithPaths;
9
11
  valid: boolean;
10
12
  errors: ConfigValidationError[];
11
13
  }
12
14
 
13
- export function validateConfig(config: any): ConfigValidationResult {
15
+ export function validateConfig(config: RawConfigWithPaths): ConfigValidationResult {
14
16
  const validationOptions = { abortEarly: false };
15
17
  const validationResult = stackbitConfigSchema.validate(config, validationOptions);
16
18
  const value = validationResult.value;
@@ -24,7 +26,7 @@ export function validateConfig(config: any): ConfigValidationResult {
24
26
  };
25
27
  }
26
28
 
27
- export function validateContentModels(contentModels: any, models: any): ConfigValidationResult {
29
+ export function validateContentModels(contentModels: ContentModelMap, models: ModelMap): ConfigValidationResult {
28
30
  const validationResult = contentModelsSchema.validate(
29
31
  { contentModels: contentModels },
30
32
  {
@@ -1,9 +1,9 @@
1
1
  import path from 'path';
2
2
  import fse from 'fs-extra';
3
3
  import yaml from 'js-yaml';
4
- import _ from 'lodash';
5
4
 
6
- import { Config, Model, YamlConfig, YamlModel, ModelMap } from './config-types';
5
+ import { Config } from './config-types';
6
+ import { convertToYamlConfig } from './config-loader-utils';
7
7
 
8
8
  const packageJson = require('../../package.json');
9
9
 
@@ -22,31 +22,3 @@ export async function writeConfig({ dirPath, config }: WriteConfigOptions) {
22
22
  const data = info + yamlString;
23
23
  await fse.outputFile(filePath, data);
24
24
  }
25
-
26
- export function convertToYamlConfig({ config }: { config: Config }): YamlConfig {
27
- const yamlConfig: YamlConfig = _.cloneDeep(_.omit(config, 'models'));
28
- if (!_.isEmpty(config.models)) {
29
- yamlConfig.models = _.reduce(
30
- config.models,
31
- (yamlModels: ModelMap, model: Model) => {
32
- if (model.type === 'image') {
33
- return yamlModels;
34
- }
35
- const yamlModel = _.omit(model, ['name', '__metadata']) as YamlModel;
36
- if (yamlModel.type === 'page' && !yamlModel.hideContent && yamlModel.fields) {
37
- _.remove(yamlModel.fields, (field) => field.name === 'markdown_content');
38
- }
39
- if (yamlModel.type === 'page' && yamlModel.fields) {
40
- _.remove(yamlModel.fields, (field) => field.name === (config.pageLayoutKey || 'layout'));
41
- }
42
- if (yamlModel.type === 'data' && yamlModel.fields) {
43
- _.remove(yamlModel.fields, (field) => field.name === (config.objectTypeKey || 'type'));
44
- }
45
- yamlModels[model.name] = yamlModel;
46
- return yamlModels;
47
- },
48
- {}
49
- );
50
- }
51
- return yamlConfig;
52
- }
@@ -123,10 +123,7 @@ function joiSchemaForField(field: Field | FieldListItems, config: Config, fieldP
123
123
  fieldSchema = Joi.string().allow('', null);
124
124
  break;
125
125
  case 'image':
126
- fieldSchema = Joi.alternatives([
127
- Joi.string().allow('', null),
128
- Joi.object()
129
- ]);
126
+ fieldSchema = Joi.alternatives([Joi.string().allow('', null), Joi.object()]);
130
127
  break;
131
128
  case 'boolean':
132
129
  fieldSchema = Joi.boolean();
@@ -335,20 +332,22 @@ const textDecorationWrongValue = 'textDecoration.wrong.value';
335
332
 
336
333
  function stylePropTextDecorationSchema(styleConfig: any) {
337
334
  const values = styleConfig === '*' ? STYLE_PROPS_VALUES.textDecoration : styleConfig;
338
- return Joi.string().custom((value: string, { error, errorsArray }: CustomHelpers & { errorsArray?: () => ErrorReport[] }) => {
339
- const parts = value.split?.(' ');
340
- const errors = errorsArray!();
341
- parts.forEach((part) => {
342
- if (!values.includes(part)) {
343
- errors.push(error(textDecorationWrongValue));
335
+ return Joi.string()
336
+ .custom((value: string, { error, errorsArray }: CustomHelpers & { errorsArray?: () => ErrorReport[] }) => {
337
+ const parts = value.split?.(' ');
338
+ const errors = errorsArray!();
339
+ parts.forEach((part) => {
340
+ if (!values.includes(part)) {
341
+ errors.push(error(textDecorationWrongValue));
342
+ }
343
+ });
344
+ return errors && errors.length ? errors : value;
345
+ })
346
+ .prefs({
347
+ messages: {
348
+ [textDecorationWrongValue]: `{{#label}} must be a space separated string values from [${values.join(', ')}]`
344
349
  }
345
350
  });
346
- return errors && errors.length ? errors : value;
347
- }).prefs({
348
- messages: {
349
- [textDecorationWrongValue]: `{{#label}} must be a space separated string values from [${values.join(', ')}]`
350
- }
351
- });
352
351
  }
353
352
 
354
353
  function stylePropSizeSchema(styleConfig: any) {
@@ -475,7 +474,7 @@ function stylePropOpacitySchema(styleConfig: any) {
475
474
  if (styleConfig === '*') {
476
475
  return Joi.number().integer().min(0).max(100).multiple(5);
477
476
  }
478
- return Joi.number().valid(...parseRange(styleConfig, { userDefinedStep: false, defaultStep: 5 }));
477
+ return Joi.number().valid(...parseRange(styleConfig, { userDefinedStep: false, defaultStep: 5 }));
479
478
  }
480
479
 
481
480
  function parseRange(styleConfig: any, { userDefinedStep = true, defaultStep = 1 } = {}) {
@@ -508,4 +507,4 @@ function parseRange(styleConfig: any, { userDefinedStep = true, defaultStep = 1
508
507
  new Set<number>()
509
508
  );
510
509
  return Array.from(values);
511
- }
510
+ }
package/src/index.ts CHANGED
@@ -5,8 +5,10 @@ export * from './content/content-errors';
5
5
  export * from './config/config-errors';
6
6
  export * from './analyzer/file-browser';
7
7
  export * from './utils';
8
- export { loadConfig, loadConfigFromDir, extendConfig, ConfigLoaderOptions, ConfigLoaderResult } from './config/config-loader';
9
- export { writeConfig, WriteConfigOptions, convertToYamlConfig } from './config/config-writer';
8
+ export * from './config/config-loader-static';
9
+ export { RawConfigWithPaths, findStackbitConfigFile, isStackbitYamlFile, convertToYamlConfig } from './config/config-loader-utils';
10
+ export { loadConfig, loadConfigFromDir, extendConfig, ConfigLoaderOptions, ConfigLoaderResult, ConfigLoaderResultWithStop } from './config/config-loader';
11
+ export { writeConfig, WriteConfigOptions } from './config/config-writer';
10
12
  export { loadContent, ContentItem, ContentLoaderOptions, ContentLoaderResult } from './content/content-loader';
11
13
  export { matchSSG, SSGMatcherOptions, SSGMatchResult } from './analyzer/ssg-matcher';
12
14
  export { matchCMS, CMSMatcherOptions, CMSMatchResult } from './analyzer/cms-matcher';
@@ -9,7 +9,7 @@ type StricterUnionMember<T, Union, Keys extends string = UnionKeys<Union> extend
9
9
 
10
10
  export type StricterUnion<Union, Union2 = Union> = Union2 extends any ? StricterUnionMember<Union2, Union> : never;
11
11
 
12
- export type Logger = Pick<Console, 'log' | 'debug' | 'info' | 'warn' | 'error' | 'group' | 'groupEnd'>;
12
+ export type Logger = Pick<Console, 'log' | 'debug' | 'info' | 'warn' | 'error'>;
13
13
 
14
14
  export * from './model-utils';
15
15
  export * from './model-matcher';
@@ -21,12 +21,12 @@ export function extendModelArray(models: Model[]): { models: Model[]; errors: Co
21
21
  );
22
22
  }
23
23
 
24
- export function extendModelMap(models: ModelMap): { models: ModelMap; errors: ConfigValidationError[] } {
24
+ export function extendModelMap(models?: ModelMap): { models: ModelMap; errors: ConfigValidationError[] } {
25
25
  const memorized = _.memoize(extendModel, (model, modelName) => modelName);
26
26
  return _.reduce(
27
27
  models,
28
28
  (result: { models: ModelMap; errors: ConfigValidationError[] }, model, modelName) => {
29
- const { model: extendedModel, errors } = memorized(model, modelName, models);
29
+ const { model: extendedModel, errors } = memorized(model, modelName, models!);
30
30
  return {
31
31
  models: _.assign(result.models, { [modelName]: extendedModel }),
32
32
  errors: result.errors.concat(errors)