storyblok 4.18.1 → 4.18.3

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.
package/dist/index.d.mts CHANGED
@@ -2,24 +2,24 @@
2
2
  type StoryblokPropertyType = 'asset' | 'multiasset' | 'multilink' | 'table' | 'richtext';
3
3
  interface StoryblokAsset {
4
4
  alt: string | null;
5
- copyright: string | null;
6
5
  fieldtype: 'asset';
7
6
  id: number;
8
7
  filename: string | null;
9
8
  name: string;
10
9
  title: string | null;
11
10
  focus: string | null;
12
- meta_data: Record<string, any>;
13
- source: string | null;
14
- is_external_url: boolean;
15
- is_private: boolean;
16
- src: string;
17
- updated_at: string;
18
- width: number | null;
19
- height: number | null;
20
- aspect_ratio: number | null;
21
- public_id: string | null;
22
- content_type: string;
11
+ copyright?: string | null;
12
+ meta_data?: Record<string, any>;
13
+ source?: string | null;
14
+ is_external_url?: boolean;
15
+ is_private?: boolean;
16
+ src?: string;
17
+ updated_at?: string;
18
+ width?: number | null;
19
+ height?: number | null;
20
+ aspect_ratio?: number | null;
21
+ public_id?: string | null;
22
+ content_type?: string;
23
23
  }
24
24
  interface StoryblokMultiasset extends Array<StoryblokAsset> {
25
25
  }
package/dist/index.d.ts CHANGED
@@ -2,24 +2,24 @@
2
2
  type StoryblokPropertyType = 'asset' | 'multiasset' | 'multilink' | 'table' | 'richtext';
3
3
  interface StoryblokAsset {
4
4
  alt: string | null;
5
- copyright: string | null;
6
5
  fieldtype: 'asset';
7
6
  id: number;
8
7
  filename: string | null;
9
8
  name: string;
10
9
  title: string | null;
11
10
  focus: string | null;
12
- meta_data: Record<string, any>;
13
- source: string | null;
14
- is_external_url: boolean;
15
- is_private: boolean;
16
- src: string;
17
- updated_at: string;
18
- width: number | null;
19
- height: number | null;
20
- aspect_ratio: number | null;
21
- public_id: string | null;
22
- content_type: string;
11
+ copyright?: string | null;
12
+ meta_data?: Record<string, any>;
13
+ source?: string | null;
14
+ is_external_url?: boolean;
15
+ is_private?: boolean;
16
+ src?: string;
17
+ updated_at?: string;
18
+ width?: number | null;
19
+ height?: number | null;
20
+ aspect_ratio?: number | null;
21
+ public_id?: string | null;
22
+ content_type?: string;
23
23
  }
24
24
  interface StoryblokMultiasset extends Array<StoryblokAsset> {
25
25
  }
package/dist/index.mjs CHANGED
@@ -6722,7 +6722,62 @@ ${Object.entries(storyblokVars).map(([key, value]) => `${key}=${value}`).join("\
6722
6722
  throw new Error(`Failed to create .env file: ${error.message}`);
6723
6723
  }
6724
6724
  };
6725
- async function handleEnvFileCreation(resolvedPath, token, region) {
6725
+ const updateAngularEnvironmentFiles = async (projectPath, token, region) => {
6726
+ const environmentsDir = join(projectPath, "src", "environments");
6727
+ const envFiles = ["environment.ts", "environment.development.ts"];
6728
+ const updatedFiles = [];
6729
+ for (const envFile of envFiles) {
6730
+ const filePath = join(environmentsDir, envFile);
6731
+ try {
6732
+ let content = await fs.readFile(filePath, "utf-8");
6733
+ if (token) {
6734
+ content = content.replaceAll("STORYBLOK_DELIVERY_API_TOKEN", token);
6735
+ }
6736
+ if (region) {
6737
+ content = content.replaceAll("STORYBLOK_REGION", region);
6738
+ }
6739
+ await saveToFile(filePath, content);
6740
+ updatedFiles.push(filePath);
6741
+ } catch (error) {
6742
+ const fsError = error;
6743
+ if (fsError.code === "ENOENT") {
6744
+ continue;
6745
+ }
6746
+ throw new Error(`Failed to update ${envFile}: ${error.message}`);
6747
+ }
6748
+ }
6749
+ return { updatedFiles };
6750
+ };
6751
+ async function handleEnvFileCreation(resolvedPath, token, region, template) {
6752
+ if (template === "angular") {
6753
+ if (!token && !region) {
6754
+ ui$1.info("No environment variables to write");
6755
+ return true;
6756
+ }
6757
+ try {
6758
+ const { updatedFiles } = await updateAngularEnvironmentFiles(resolvedPath, token, region);
6759
+ if (updatedFiles.length === 0) {
6760
+ ui$1.info("No Angular environment files found to update");
6761
+ return true;
6762
+ }
6763
+ const writtenVars = [token && "accessToken", region && "region"].filter(Boolean).join(", ");
6764
+ ui$1.ok(`Updated Angular environment files with: ${writtenVars}`, true);
6765
+ return true;
6766
+ } catch (error) {
6767
+ ui$1.warn(`Failed to update Angular environment files: ${error.message}`);
6768
+ if (token) {
6769
+ ui$1.info(
6770
+ `You can manually add accessToken to src/environments/environment.ts and src/environments/environment.development.ts`
6771
+ );
6772
+ }
6773
+ if (region) {
6774
+ ui$1.info(
6775
+ `You can manually add region to src/environments/environment.ts and src/environments/environment.development.ts`
6776
+ );
6777
+ }
6778
+ return false;
6779
+ }
6780
+ }
6726
6781
  const envVars = {};
6727
6782
  if (token) {
6728
6783
  envVars.STORYBLOK_DELIVERY_API_TOKEN = token;
@@ -6954,13 +7009,13 @@ program$5.command(`${commands.CREATE} [project-path]`).alias("c").description(`S
6954
7009
  let userData;
6955
7010
  let whereToCreateSpace = "personal";
6956
7011
  if (token) {
6957
- await handleEnvFileCreation(resolvedPath, token, options.region || region);
7012
+ await handleEnvFileCreation(resolvedPath, token, options.region || region, technologyTemplate);
6958
7013
  showNextSteps(technologyTemplate, finalProjectPath);
6959
7014
  return;
6960
7015
  }
6961
7016
  if (options.skipSpace) {
6962
7017
  if (options.region || region) {
6963
- await handleEnvFileCreation(resolvedPath, void 0, options.region || region);
7018
+ await handleEnvFileCreation(resolvedPath, void 0, options.region || region, technologyTemplate);
6964
7019
  }
6965
7020
  showNextSteps(technologyTemplate, finalProjectPath);
6966
7021
  return;
@@ -7032,7 +7087,7 @@ program$5.command(`${commands.CREATE} [project-path]`).alias("c").description(`S
7032
7087
  createdSpace = await createSpace(spaceToCreate);
7033
7088
  spinnerSpace.succeed(`Space "${chalk.hex(colorPalette.PRIMARY)(toHumanReadable(projectName))}" created successfully`);
7034
7089
  if (createdSpace?.first_token) {
7035
- await handleEnvFileCreation(resolvedPath, createdSpace.first_token, region);
7090
+ await handleEnvFileCreation(resolvedPath, createdSpace.first_token, region, technologyTemplate);
7036
7091
  }
7037
7092
  if (createdSpace?.id) {
7038
7093
  try {
@@ -7398,6 +7453,17 @@ const loadAssetFolderMap = async (manifestFile) => {
7398
7453
  const manifest = await loadManifest(manifestFile);
7399
7454
  return new Map(manifest.map((e) => [Number(e.old_id), Number(e.new_id)]));
7400
7455
  };
7456
+ const extractAssetSizeFromFilename = (filename) => {
7457
+ if (!filename) {
7458
+ return void 0;
7459
+ }
7460
+ try {
7461
+ const segments = new URL(filename).pathname.split("/");
7462
+ return segments.find((segment) => /^\d+x\d+$/.test(segment));
7463
+ } catch {
7464
+ return void 0;
7465
+ }
7466
+ };
7401
7467
  const getAssetNameAndExt = (asset) => {
7402
7468
  const filename = asset.short_filename || (asset.filename ? basename(asset.filename) : void 0);
7403
7469
  if (!filename) {
@@ -7883,9 +7949,7 @@ const makeCleanupAssetFSTransport = () => async ({ assetBinaryPath, assetPath })
7883
7949
  const hasId = (a) => {
7884
7950
  return !!a && typeof a === "object" && "id" in a && typeof a.id === "number";
7885
7951
  };
7886
- const hasShortFilename = (a) => {
7887
- return !!a && typeof a === "object" && "short_filename" in a && typeof a.short_filename === "string";
7888
- };
7952
+ const hasProp = (a, key) => !!a && typeof a === "object" && key in a && typeof a[key] === "string";
7889
7953
  const processAsset = async ({
7890
7954
  localAsset,
7891
7955
  fileBuffer,
@@ -7923,13 +7987,15 @@ const processAsset = async ({
7923
7987
  );
7924
7988
  newRemoteAsset = { ...remoteAsset, ...updatePayload };
7925
7989
  status = "updated";
7926
- } else if (hasShortFilename(localAsset)) {
7990
+ } else if (hasProp(localAsset, "short_filename")) {
7927
7991
  const { internal_tags_list: _internalTagsList, internal_tag_ids: _sourceTagIds, ...rest } = localAsset;
7928
7992
  const mappedTagIds = "internal_tag_ids" in localAsset ? resolveInternalTagIds(localAsset.internal_tag_ids) : void 0;
7993
+ const size = hasProp(rest, "size") ? rest.size : hasProp(localAsset, "filename") ? extractAssetSizeFromFilename(localAsset.filename) : void 0;
7929
7994
  const createPayload = {
7930
7995
  ...rest,
7931
7996
  asset_folder_id: remoteFolderId,
7932
- ...mappedTagIds !== void 0 ? { internal_tag_ids: mappedTagIds } : {}
7997
+ ...mappedTagIds !== void 0 ? { internal_tag_ids: mappedTagIds } : {},
7998
+ ...size !== void 0 ? { size } : {}
7933
7999
  };
7934
8000
  newRemoteAsset = await transports.createAsset(createPayload, fileBuffer);
7935
8001
  status = "created";