@stackbit/cms-contentful 0.4.53-staging.1 → 0.4.53

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.
@@ -51,12 +51,13 @@ export type ConvertEntriesOptions = {
51
51
  getModelByName: GetModelByName;
52
52
  userMap: Record<string, UserProps>;
53
53
  defaultLocale: string;
54
+ projectUrl: string;
54
55
  };
55
56
 
56
- export function convertEntities({ entries, getModelByName, userMap, defaultLocale }: ConvertEntriesOptions): ContextualDocument[] {
57
+ export function convertEntities({ entries, getModelByName, userMap, defaultLocale, projectUrl }: ConvertEntriesOptions): ContextualDocument[] {
57
58
  return entries
58
59
  .map((entry) => {
59
- return convertEntry({ entry, getModelByName, userMap, defaultLocale });
60
+ return convertEntry({ entry, getModelByName, userMap, defaultLocale, projectUrl });
60
61
  })
61
62
  .filter((document): document is ContextualDocument => !!document);
62
63
  }
@@ -66,12 +67,13 @@ export type ConvertAssetsOptions = {
66
67
  userMap: Record<string, UserProps>;
67
68
  defaultLocale: string;
68
69
  useLocalizedAssetFields: boolean;
70
+ projectUrl: string;
69
71
  };
70
72
 
71
- export function convertAssets({ assets, userMap, defaultLocale, useLocalizedAssetFields }: ConvertAssetsOptions) {
73
+ export function convertAssets({ assets, userMap, defaultLocale, useLocalizedAssetFields, projectUrl }: ConvertAssetsOptions) {
72
74
  return assets
73
75
  .map((asset) => {
74
- return convertAsset({ asset, userMap, defaultLocale, useLocalizedAssetFields });
76
+ return convertAsset({ asset, userMap, defaultLocale, useLocalizedAssetFields, projectUrl });
75
77
  })
76
78
  .filter((asset): asset is ContextualAsset => !!asset);
77
79
  }
@@ -81,9 +83,10 @@ export type ConvertEntryOptions = {
81
83
  getModelByName: GetModelByName;
82
84
  userMap: Record<string, UserProps>;
83
85
  defaultLocale: string;
86
+ projectUrl: string;
84
87
  };
85
88
 
86
- export function convertEntry({ entry, getModelByName, userMap, defaultLocale }: ConvertEntryOptions): ContextualDocument | undefined {
89
+ export function convertEntry({ entry, getModelByName, userMap, defaultLocale, projectUrl }: ConvertEntryOptions): ContextualDocument | undefined {
87
90
  if (!entry) {
88
91
  return;
89
92
  }
@@ -93,10 +96,9 @@ export function convertEntry({ entry, getModelByName, userMap, defaultLocale }:
93
96
  return;
94
97
  }
95
98
  const entryId = getEntityId(entry);
96
- const spaceId = getEntitySpaceId(entry);
97
99
  const environment = getEntryEnvironmentId(entry);
98
100
  const envUrlPath = environment && environment !== 'master' ? `/environments/${environment}` : '';
99
- const objectUrl = `https://app.contentful.com/spaces/${spaceId}${envUrlPath}/entries/${entryId}`;
101
+ const objectUrl = `${projectUrl}${envUrlPath}/entries/${entryId}`;
100
102
  return {
101
103
  type: 'document',
102
104
  id: entryId,
@@ -124,18 +126,18 @@ export type ConvertAssetOptions = {
124
126
  userMap: Record<string, UserProps>;
125
127
  defaultLocale: string;
126
128
  useLocalizedAssetFields: boolean;
129
+ projectUrl: string;
127
130
  };
128
131
 
129
- export function convertAsset({ asset, userMap, defaultLocale, useLocalizedAssetFields }: ConvertAssetOptions): ContextualAsset | undefined {
132
+ export function convertAsset({ asset, userMap, defaultLocale, useLocalizedAssetFields, projectUrl }: ConvertAssetOptions): ContextualAsset | undefined {
130
133
  if (!asset) {
131
134
  return;
132
135
  }
133
136
 
134
137
  const assetId = getEntityId(asset);
135
- const spaceId = getEntitySpaceId(asset);
136
138
  const environment = getEntryEnvironmentId(asset);
137
139
  const envUrlPath = environment && environment !== 'master' ? `/environments/${environment}` : '';
138
- const objectUrl = `https://app.contentful.com/spaces/${spaceId}${envUrlPath}/assets/${assetId}`;
140
+ const objectUrl = `${projectUrl}${envUrlPath}/assets/${assetId}`;
139
141
 
140
142
  // Remap Contentful Asset fields to Stackbit AssetFields
141
143
  // ContentfulAsset.fields: {
@@ -595,15 +597,17 @@ export function convertDocumentVersions({
595
597
  entries,
596
598
  userMap,
597
599
  defaultLocale,
598
- getModelByName
600
+ getModelByName,
601
+ projectUrl
599
602
  }: {
600
603
  entries: SnapshotProps<EntryProps>[];
601
604
  userMap: Record<string, UserProps>;
602
605
  getModelByName: GetModelByName;
603
606
  defaultLocale: string;
607
+ projectUrl: string;
604
608
  }): DocumentVersionWithDocument[] {
605
609
  return entries.map((entry) => {
606
- const document = convertEntry({ entry: entry.snapshot, getModelByName, userMap, defaultLocale });
610
+ const document = convertEntry({ entry: entry.snapshot, getModelByName, userMap, defaultLocale, projectUrl });
607
611
  if (!document) {
608
612
  throw new Error(`Could not convert entry ${entry.sys.id} to Document`);
609
613
  }