@enonic/nextjs-adapter 3.0.0-B1 → 3.0.0-B3

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 (241) hide show
  1. package/baseMappings.js +3 -2
  2. package/baseMappings.js.map +1 -0
  3. package/client.d.ts +1 -0
  4. package/client.js +3 -0
  5. package/client.js.map +1 -0
  6. package/common/ComponentRegistry.d.ts +34 -0
  7. package/{ComponentRegistry.js → common/ComponentRegistry.js} +26 -26
  8. package/common/ComponentRegistry.js.map +1 -0
  9. package/{UrlProcessor.d.ts → common/UrlProcessor.d.ts} +2 -2
  10. package/{UrlProcessor.js → common/UrlProcessor.js} +16 -8
  11. package/common/UrlProcessor.js.map +1 -0
  12. package/common/constants.d.ts +50 -0
  13. package/common/constants.js +79 -0
  14. package/common/constants.js.map +1 -0
  15. package/common/env.d.ts +11 -0
  16. package/common/env.js +29 -0
  17. package/common/env.js.map +1 -0
  18. package/guillotine/applyProcessors.d.ts +2 -0
  19. package/guillotine/applyProcessors.js +33 -0
  20. package/guillotine/applyProcessors.js.map +1 -0
  21. package/guillotine/buildComponentTree.d.ts +2 -0
  22. package/guillotine/buildComponentTree.js +45 -0
  23. package/guillotine/buildComponentTree.js.map +1 -0
  24. package/guillotine/buildErrorResponse.d.ts +3 -0
  25. package/guillotine/buildErrorResponse.js +26 -0
  26. package/guillotine/buildErrorResponse.js.map +1 -0
  27. package/guillotine/buildPage.d.ts +2 -0
  28. package/guillotine/buildPage.js +10 -0
  29. package/guillotine/buildPage.js.map +1 -0
  30. package/guillotine/collectComponentDescriptors.d.ts +6 -0
  31. package/guillotine/collectComponentDescriptors.js +43 -0
  32. package/guillotine/collectComponentDescriptors.js.map +1 -0
  33. package/guillotine/combineMultipleQueries.d.ts +2 -0
  34. package/guillotine/combineMultipleQueries.js +58 -0
  35. package/guillotine/combineMultipleQueries.js.map +1 -0
  36. package/guillotine/createMetaData.d.ts +17 -0
  37. package/guillotine/createMetaData.js +44 -0
  38. package/guillotine/createMetaData.js.map +1 -0
  39. package/guillotine/fetchContent.d.ts +2 -40
  40. package/guillotine/fetchContent.js +65 -676
  41. package/guillotine/fetchContent.js.map +1 -0
  42. package/guillotine/fetchContentData.d.ts +2 -0
  43. package/guillotine/fetchContentData.js +27 -0
  44. package/guillotine/fetchContentData.js.map +1 -0
  45. package/guillotine/fetchContentPathsForAllLocales.d.ts +2 -0
  46. package/guillotine/fetchContentPathsForAllLocales.js +21 -0
  47. package/guillotine/fetchContentPathsForAllLocales.js.map +1 -0
  48. package/guillotine/fetchContentPathsForLocale.d.ts +2 -0
  49. package/guillotine/fetchContentPathsForLocale.js +40 -0
  50. package/guillotine/fetchContentPathsForLocale.js.map +1 -0
  51. package/guillotine/fetchFromApi.d.ts +3 -0
  52. package/guillotine/fetchFromApi.js +67 -0
  53. package/guillotine/fetchFromApi.js.map +1 -0
  54. package/guillotine/fetchGuillotine.d.ts +3 -0
  55. package/guillotine/fetchGuillotine.js +57 -0
  56. package/guillotine/fetchGuillotine.js.map +1 -0
  57. package/guillotine/fetchMetaData.d.ts +2 -0
  58. package/guillotine/fetchMetaData.js +30 -0
  59. package/guillotine/fetchMetaData.js.map +1 -0
  60. package/guillotine/getCleanContentPathArrayOrThrow400.d.ts +2 -0
  61. package/guillotine/getCleanContentPathArrayOrThrow400.js +20 -0
  62. package/guillotine/getCleanContentPathArrayOrThrow400.js.map +1 -0
  63. package/guillotine/getComponentConfig.d.ts +2 -0
  64. package/guillotine/getComponentConfig.js +5 -0
  65. package/guillotine/getComponentConfig.js.map +1 -0
  66. package/guillotine/getContentAndComponentPaths.d.ts +1 -0
  67. package/guillotine/getContentAndComponentPaths.js +12 -0
  68. package/guillotine/getContentAndComponentPaths.js.map +1 -0
  69. package/guillotine/getMetaData.d.ts +0 -92
  70. package/guillotine/getMetaData.js +47 -109
  71. package/guillotine/getMetaData.js.map +1 -0
  72. package/guillotine/getParentRegion.d.ts +2 -0
  73. package/guillotine/getParentRegion.js +40 -0
  74. package/guillotine/getParentRegion.js.map +1 -0
  75. package/guillotine/getQueryAndVariables.d.ts +2 -0
  76. package/guillotine/getQueryAndVariables.js +32 -0
  77. package/guillotine/getQueryAndVariables.js.map +1 -0
  78. package/guillotine/metadata/configQuery.d.ts +2 -0
  79. package/guillotine/metadata/configQuery.js +36 -0
  80. package/guillotine/metadata/configQuery.js.map +1 -0
  81. package/guillotine/metadata/richTextQuery.d.ts +1 -0
  82. package/guillotine/metadata/richTextQuery.js +32 -0
  83. package/guillotine/metadata/richTextQuery.js.map +1 -0
  84. package/guillotine/parseComponentPath.d.ts +2 -0
  85. package/guillotine/parseComponentPath.js +22 -0
  86. package/guillotine/parseComponentPath.js.map +1 -0
  87. package/guillotine/prefixLayoutPath.d.ts +1 -0
  88. package/guillotine/prefixLayoutPath.js +13 -0
  89. package/guillotine/prefixLayoutPath.js.map +1 -0
  90. package/guillotine/processComponentConfig.d.ts +2 -0
  91. package/guillotine/processComponentConfig.js +30 -0
  92. package/guillotine/processComponentConfig.js.map +1 -0
  93. package/guillotine/restrictComponentsToPath.d.ts +2 -0
  94. package/guillotine/restrictComponentsToPath.js +35 -0
  95. package/guillotine/restrictComponentsToPath.js.map +1 -0
  96. package/guillotine/validateData.d.ts +2 -0
  97. package/guillotine/validateData.js +7 -0
  98. package/guillotine/validateData.js.map +1 -0
  99. package/guillotine/validateNotFound.d.ts +2 -0
  100. package/guillotine/validateNotFound.js +16 -0
  101. package/guillotine/validateNotFound.js.map +1 -0
  102. package/guillotine/validateShortcut.d.ts +2 -0
  103. package/guillotine/validateShortcut.js +29 -0
  104. package/guillotine/validateShortcut.js.map +1 -0
  105. package/i18n/LocaleContext.d.ts +2 -8
  106. package/i18n/LocaleContext.jsx +17 -13
  107. package/i18n/LocaleContext.jsx.map +1 -0
  108. package/i18n/i18n.d.ts +1 -3
  109. package/i18n/i18n.js +2 -1
  110. package/i18n/i18n.js.map +1 -0
  111. package/index.d.ts +14 -7
  112. package/index.js +14 -7
  113. package/index.js.map +1 -0
  114. package/package.json +63 -15
  115. package/query/Shortcut.js +1 -0
  116. package/query/Shortcut.js.map +1 -0
  117. package/server.d.ts +5 -0
  118. package/server.js.map +1 -0
  119. package/types/component.d.ts +114 -0
  120. package/types/component.js +2 -0
  121. package/types/component.js.map +1 -0
  122. package/types/componentProps.d.ts +104 -0
  123. package/types/componentProps.js +2 -0
  124. package/types/componentProps.js.map +1 -0
  125. package/types/guillotine.d.ts +342 -0
  126. package/types/guillotine.js +2 -0
  127. package/types/guillotine.js.map +1 -0
  128. package/types/i18n.d.ts +7 -0
  129. package/types/i18n.js +2 -0
  130. package/types/i18n.js.map +1 -0
  131. package/types/index.d.ts +45 -0
  132. package/types/index.js +3 -0
  133. package/types/index.js.map +1 -0
  134. package/types/next.d.ts +6 -0
  135. package/types/next.js +2 -0
  136. package/types/next.js.map +1 -0
  137. package/types/util.d.ts +3 -0
  138. package/types/util.js +3 -0
  139. package/types/util.js.map +1 -0
  140. package/utils/addLineNumbers.d.ts +1 -0
  141. package/utils/addLineNumbers.js +4 -0
  142. package/utils/addLineNumbers.js.map +1 -0
  143. package/utils/buildGuillotineRequestHeaders.d.ts +7 -0
  144. package/utils/buildGuillotineRequestHeaders.js +16 -0
  145. package/utils/buildGuillotineRequestHeaders.js.map +1 -0
  146. package/utils/commonChars.d.ts +1 -0
  147. package/utils/commonChars.js +17 -0
  148. package/utils/commonChars.js.map +1 -0
  149. package/utils/fixDoubleSlashes.d.ts +1 -0
  150. package/utils/fixDoubleSlashes.js +4 -0
  151. package/utils/fixDoubleSlashes.js.map +1 -0
  152. package/utils/getContentApiUrl.d.ts +2 -0
  153. package/utils/getContentApiUrl.js +15 -0
  154. package/utils/getContentApiUrl.js.map +1 -0
  155. package/utils/getProjectLocaleConfig.d.ts +2 -0
  156. package/utils/getProjectLocaleConfig.js +19 -0
  157. package/utils/getProjectLocaleConfig.js.map +1 -0
  158. package/utils/getProjectLocaleConfigById.d.ts +2 -0
  159. package/utils/getProjectLocaleConfigById.js +16 -0
  160. package/utils/getProjectLocaleConfigById.js.map +1 -0
  161. package/utils/getProjectLocaleConfigByLocale.d.ts +2 -0
  162. package/utils/getProjectLocaleConfigByLocale.js +13 -0
  163. package/utils/getProjectLocaleConfigByLocale.js.map +1 -0
  164. package/utils/getProjectLocaleConfigs.d.ts +2 -0
  165. package/utils/getProjectLocaleConfigs.js +30 -0
  166. package/utils/getProjectLocaleConfigs.js.map +1 -0
  167. package/utils/getProjectLocales.d.ts +1 -0
  168. package/utils/getProjectLocales.js +5 -0
  169. package/utils/getProjectLocales.js.map +1 -0
  170. package/utils/getRenderMode.d.ts +3 -0
  171. package/utils/getRenderMode.js +8 -0
  172. package/utils/getRenderMode.js.map +1 -0
  173. package/utils/getRequestLocaleInfo.d.ts +6 -0
  174. package/utils/getRequestLocaleInfo.js +26 -0
  175. package/utils/getRequestLocaleInfo.js.map +1 -0
  176. package/utils/getXpBaseUrl.d.ts +2 -0
  177. package/utils/getXpBaseUrl.js +8 -0
  178. package/utils/getXpBaseUrl.js.map +1 -0
  179. package/utils/indent.d.ts +1 -0
  180. package/utils/indent.js +5 -0
  181. package/utils/indent.js.map +1 -0
  182. package/utils/sanitizeGraphqlName.d.ts +1 -0
  183. package/utils/sanitizeGraphqlName.js +12 -0
  184. package/utils/sanitizeGraphqlName.js.map +1 -0
  185. package/views/BaseComponent.d.ts +6 -11
  186. package/views/BaseComponent.jsx +18 -21
  187. package/views/BaseComponent.jsx.map +1 -0
  188. package/views/BaseContent.d.ts +3 -3
  189. package/views/BaseContent.jsx +2 -5
  190. package/views/BaseContent.jsx.map +1 -0
  191. package/views/BaseLayout.d.ts +3 -16
  192. package/views/BaseLayout.jsx +3 -3
  193. package/views/BaseLayout.jsx.map +1 -0
  194. package/views/BaseMacro.d.ts +3 -13
  195. package/views/BaseMacro.jsx +4 -3
  196. package/views/BaseMacro.jsx.map +1 -0
  197. package/views/BasePage.d.ts +3 -18
  198. package/views/BasePage.jsx +3 -3
  199. package/views/BasePage.jsx.map +1 -0
  200. package/views/BasePart.d.ts +3 -18
  201. package/views/BasePart.jsx +3 -3
  202. package/views/BasePart.jsx.map +1 -0
  203. package/views/Empty.d.ts +2 -2
  204. package/views/Empty.jsx +2 -1
  205. package/views/Empty.jsx.map +1 -0
  206. package/views/Fragment.d.ts +3 -9
  207. package/views/Fragment.jsx +2 -2
  208. package/views/Fragment.jsx.map +1 -0
  209. package/views/MainView.d.ts +3 -3
  210. package/views/MainView.jsx +2 -2
  211. package/views/MainView.jsx.map +1 -0
  212. package/views/PropsView.d.ts +3 -0
  213. package/views/PropsView.jsx +21 -0
  214. package/views/PropsView.jsx.map +1 -0
  215. package/views/Region.d.ts +4 -17
  216. package/views/Region.jsx +2 -2
  217. package/views/Region.jsx.map +1 -0
  218. package/views/RichTextView.d.ts +3 -13
  219. package/views/RichTextView.jsx +2 -2
  220. package/views/RichTextView.jsx.map +1 -0
  221. package/views/SingleComponent.d.ts +3 -3
  222. package/views/SingleComponent.jsx +1 -2
  223. package/views/SingleComponent.jsx.map +1 -0
  224. package/views/StaticContent.d.ts +2 -6
  225. package/views/StaticContent.jsx +1 -0
  226. package/views/StaticContent.jsx.map +1 -0
  227. package/views/Text.d.ts +5 -5
  228. package/views/Text.jsx +1 -1
  229. package/views/Text.jsx.map +1 -0
  230. package/views/getClientHydratedHtml.d.ts +2 -0
  231. package/views/getClientHydratedHtml.jsx +9 -0
  232. package/views/getClientHydratedHtml.jsx.map +1 -0
  233. package/views/macros/DefaultMacro.d.ts +1 -1
  234. package/views/macros/DefaultMacro.jsx +1 -0
  235. package/views/macros/DefaultMacro.jsx.map +1 -0
  236. package/views/macros/DisableMacro.d.ts +1 -1
  237. package/views/macros/DisableMacro.jsx +1 -0
  238. package/views/macros/DisableMacro.jsx.map +1 -0
  239. package/ComponentRegistry.d.ts +0 -64
  240. package/utils.d.ts +0 -111
  241. package/utils.js +0 -255
package/utils.js DELETED
@@ -1,255 +0,0 @@
1
- import Negotiator from 'negotiator';
2
- import { match as localeMatcher } from '@formatjs/intl-localematcher';
3
- const mode = process.env.MODE || process.env.NEXT_PUBLIC_MODE;
4
- export const IS_DEV_MODE = (mode === 'development');
5
- export var ENV_VARS;
6
- (function (ENV_VARS) {
7
- ENV_VARS["PROJECTS"] = "ENONIC_PROJECTS";
8
- ENV_VARS["API"] = "ENONIC_API";
9
- ENV_VARS["API_TOKEN"] = "ENONIC_API_TOKEN";
10
- })(ENV_VARS || (ENV_VARS = {}));
11
- /** URL to the guillotine API */
12
- const API_URL = (process.env.ENONIC_API || process.env.NEXT_PUBLIC_ENONIC_API);
13
- /** Locales and Enonic XP projects correspondence list */
14
- const PROJECTS = (process.env.ENONIC_PROJECTS || process.env.NEXT_PUBLIC_ENONIC_PROJECTS);
15
- /** Optional utility value - defining in one place the name of the target app (the app that defines the content types, the app name is therefore part of the content type strings used both in typeselector and in query introspections) */
16
- export const APP_NAME = (process.env.ENONIC_APP_NAME || process.env.NEXT_PUBLIC_ENONIC_APP_NAME);
17
- /** Optional utility value - derived from APP_NAME, only with underscores instead of dots */
18
- export const APP_NAME_UNDERSCORED = (APP_NAME || '').replace(/\./g, '_');
19
- /** Optional utility value - derived from APP_NAME, only with dashes instead of dots */
20
- export const APP_NAME_DASHED = (APP_NAME || '').replace(/\./g, '-');
21
- const PROJECT_CONFIG_REGEXP = new RegExp('^([\\w-]+):([^\\/\\s]+)(\\/[\\w-.]+)?$', 'i');
22
- // //////////////////////////////////////////////////////////////////////// Hardcode-able constants
23
- // URI parameter marking that a request is for a preview for CS. MUST MATCH THE VALUE OF 'FROM_XP_PARAM' on XP side.
24
- export const XP_BASE_URL_HEADER = 'xpbaseurl';
25
- export const RENDER_MODE_HEADER = 'content-studio-mode';
26
- export const PROJECT_ID_HEADER = 'content-studio-project';
27
- export const JSESSIONID_HEADER = 'jsessionid';
28
- export const PORTAL_COMPONENT_ATTRIBUTE = 'data-portal-component-type';
29
- export const PORTAL_REGION_ATTRIBUTE = 'data-portal-region';
30
- export const FRAGMENT_CONTENTTYPE_NAME = 'portal:fragment';
31
- export const FRAGMENT_DEFAULT_REGION_NAME = 'fragment';
32
- export const PAGE_TEMPLATE_CONTENTTYPE_NAME = 'portal:page-template';
33
- export const PAGE_TEMPLATE_FOLDER = 'portal:template-folder';
34
- export const SITE_CONTENTTYPE_NAME = 'portal:site';
35
- export const LOCALE_HEADER = 'locale';
36
- export const LOCALES_HEADER = 'locales';
37
- export const DEFAULT_LOCALE_HEADER = 'default-locale';
38
- /** excluded contents:
39
- * - folder
40
- * - shortcuts (redirect can't be used in prerender)
41
- * - media
42
- * - paths with '/_' in them
43
- */
44
- export const GET_STATIC_PATHS_QUERY = `query ($count: Int) {
45
- guillotine {
46
- queryDsl(
47
- first: $count,
48
- sort: {
49
- field: "modifiedTime",
50
- direction: DESC
51
- }
52
- query: {boolean: {mustNot: [
53
- {in: {field: "type", stringValues: ["base:folder", "base:shortcut"]}}
54
- {like: {field: "type", value: "media:*"}}
55
- {like: {field: "_path", value: "*/_*"}}
56
- ]}}
57
- ) {
58
- _name
59
- _path
60
- site {_name}
61
- }
62
- }
63
- }`;
64
- // ------------------------------- Exports and auxillary functions derived from values above ------------------------------------
65
- export var XP_REQUEST_TYPE;
66
- (function (XP_REQUEST_TYPE) {
67
- XP_REQUEST_TYPE["COMPONENT"] = "component";
68
- XP_REQUEST_TYPE["TYPE"] = "type";
69
- XP_REQUEST_TYPE["PAGE"] = "page";
70
- })(XP_REQUEST_TYPE || (XP_REQUEST_TYPE = {}));
71
- export var RENDER_MODE;
72
- (function (RENDER_MODE) {
73
- RENDER_MODE["INLINE"] = "inline";
74
- RENDER_MODE["EDIT"] = "edit";
75
- RENDER_MODE["PREVIEW"] = "preview";
76
- RENDER_MODE["LIVE"] = "live";
77
- RENDER_MODE["ADMIN"] = "admin";
78
- RENDER_MODE["NEXT"] = "next"; // Fallback: not using XP proxy but rendering directly with next.js
79
- })(RENDER_MODE || (RENDER_MODE = {}));
80
- // TODO: Use these instead of hardcoded strings everywhere
81
- export var XP_COMPONENT_TYPE;
82
- (function (XP_COMPONENT_TYPE) {
83
- XP_COMPONENT_TYPE["PART"] = "part";
84
- XP_COMPONENT_TYPE["LAYOUT"] = "layout";
85
- XP_COMPONENT_TYPE["TEXT"] = "text";
86
- XP_COMPONENT_TYPE["FRAGMENT"] = "fragment";
87
- XP_COMPONENT_TYPE["PAGE"] = "page";
88
- })(XP_COMPONENT_TYPE || (XP_COMPONENT_TYPE = {}));
89
- export const getRenderMode = (context) => {
90
- var _a;
91
- const value = (_a = context.headers) === null || _a === void 0 ? void 0 : _a.get(RENDER_MODE_HEADER);
92
- const enumValue = RENDER_MODE[value === null || value === void 0 ? void 0 : value.toUpperCase()];
93
- return enumValue || RENDER_MODE[process.env.RENDER_MODE] || RENDER_MODE.NEXT;
94
- };
95
- export function getRequestLocaleInfo(context) {
96
- var _a, _b, _c;
97
- let locale;
98
- const configs = getProjectLocaleConfigs();
99
- const locales = Object.keys(configs);
100
- const defaultLocale = locales.find((locale) => configs[locale].default);
101
- const projectId = (_a = context.headers) === null || _a === void 0 ? void 0 : _a.get(PROJECT_ID_HEADER);
102
- if (projectId) {
103
- locale = (_b = getProjectLocaleConfigById(projectId, false)) === null || _b === void 0 ? void 0 : _b.locale;
104
- }
105
- else {
106
- locale = context.locale;
107
- if (!locale) {
108
- const acceptLang = ((_c = context.headers) === null || _c === void 0 ? void 0 : _c.get('accept-language')) || '';
109
- const langs = new Negotiator({ headers: { 'accept-language': acceptLang } }).languages();
110
- locale = localeMatcher(langs, locales, defaultLocale);
111
- }
112
- }
113
- return { locale, locales, defaultLocale };
114
- }
115
- export function getProjectLocaleConfig(context) {
116
- var _a;
117
- const projectId = (_a = context.headers) === null || _a === void 0 ? void 0 : _a.get(PROJECT_ID_HEADER);
118
- let config;
119
- if (projectId) {
120
- // first use project id header
121
- config = getProjectLocaleConfigById(projectId, false);
122
- }
123
- if (!config) {
124
- // next try to use locale from url
125
- // it will fall back to default locale if not found
126
- config = getProjectLocaleConfigByLocale(context.locale);
127
- }
128
- return config;
129
- }
130
- export function getProjectLocales() {
131
- return Object.keys(getProjectLocaleConfigs());
132
- }
133
- export function getProjectLocaleConfigById(projectId, useDefault = true) {
134
- const configs = getProjectLocaleConfigs();
135
- let config;
136
- if (projectId) {
137
- config = Object.values(configs).find(p => {
138
- var _a;
139
- return ((_a = p === null || p === void 0 ? void 0 : p.project) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === projectId.toLowerCase();
140
- });
141
- }
142
- if (!config && useDefault) {
143
- config = Object.values(configs).find(c => c.default);
144
- }
145
- return config;
146
- }
147
- export function getProjectLocaleConfigByLocale(locale, useDefault = true) {
148
- const configs = getProjectLocaleConfigs();
149
- let config;
150
- if (locale) {
151
- config = configs[locale];
152
- }
153
- if (!config && useDefault) {
154
- config = Object.values(configs).find(c => c.default);
155
- }
156
- return config;
157
- }
158
- export function getProjectLocaleConfigs() {
159
- const str = PROJECTS;
160
- const envVarName = ENV_VARS.PROJECTS;
161
- if (!(str === null || str === void 0 ? void 0 : str.length)) {
162
- throw new Error(`Did you forget to define "${ENV_VARS.PROJECTS}" environmental variable?
163
- Format: <default-language>:<default-repository-name>/<default-site-path>,<language>:<repository-name>/<site-path>,...`);
164
- }
165
- return str.split(',').reduce((config, prjStr, index) => {
166
- const matches = PROJECT_CONFIG_REGEXP.exec(prjStr === null || prjStr === void 0 ? void 0 : prjStr.trim());
167
- if (!(matches === null || matches === void 0 ? void 0 : matches.length)) {
168
- return config;
169
- }
170
- const [full, lang, project, site] = matches;
171
- if (project && site) {
172
- config[lang] = {
173
- default: index === 0,
174
- project,
175
- site,
176
- locale: lang,
177
- };
178
- }
179
- else {
180
- throw Error(`Wrong configuration in "${envVarName}": ${prjStr}.
181
- Format: <default-language>:<default-repository-name>/<default-site-path>,<language>:<repository-name>/<site-path>,...`);
182
- }
183
- return config;
184
- }, {});
185
- }
186
- export function fixDoubleSlashes(str) {
187
- return str.replace(/(^|[^:/])\/{2,}/g, '$1/');
188
- }
189
- export function getContentApiUrl(context) {
190
- const project = getProjectLocaleConfig(context).project;
191
- const branch = getRenderMode(context) === RENDER_MODE.NEXT ? 'master' : 'draft';
192
- return fixDoubleSlashes(`${API_URL}/${project}/${branch}`);
193
- }
194
- export function addJsessionHeaders(target = {}, context) {
195
- var _a;
196
- const jsessionid = (_a = context.headers) === null || _a === void 0 ? void 0 : _a.get(JSESSIONID_HEADER);
197
- if (jsessionid) {
198
- target['Cookie'] = `${JSESSIONID_HEADER}=${jsessionid}`;
199
- }
200
- }
201
- export function addLocaleHeaders(target = {}, locale, locales, defaultLocale) {
202
- target[LOCALE_HEADER] = locale;
203
- target[LOCALES_HEADER] = JSON.stringify(locales);
204
- target[DEFAULT_LOCALE_HEADER] = defaultLocale;
205
- }
206
- export const getXpBaseUrl = (context) => {
207
- var _a;
208
- const header = ((_a = context.headers) === null || _a === void 0 ? void 0 : _a.get(XP_BASE_URL_HEADER)) || '/';
209
- // TODO: workaround for XP pattern controller mapping not picked up in edit mode
210
- return header.replace(/\/edit\//, '/inline/');
211
- };
212
- export const commonChars = (s1, s2) => {
213
- let result = '';
214
- if (!s1 || s1.length === 0 || !s2 || s2.length === 0) {
215
- return result;
216
- }
217
- for (let i = 0; i < s1.length; i++) {
218
- const s1Element = s1[i];
219
- if (s2[i] === s1Element) {
220
- result += s1Element;
221
- }
222
- else {
223
- break;
224
- }
225
- }
226
- return result;
227
- };
228
- // sanitizes text according to graphql naming spec http://spec.graphql.org/October2021/#sec-Names
229
- export const sanitizeGraphqlName = (text) => {
230
- if (!text || text.trim().length === 0) {
231
- return '';
232
- }
233
- let result = text.replace(/([^0-9A-Za-z])+/g, '_');
234
- if (result.length > 0 && /[0-9]/.test(result.charAt(0))) {
235
- result = '_' + result;
236
- }
237
- return result;
238
- };
239
- // ---------------------------------------------------------------------------------------------------------------- Export
240
- const adapterConstants = {
241
- IS_DEV_MODE,
242
- APP_NAME,
243
- APP_NAME_UNDERSCORED,
244
- APP_NAME_DASHED,
245
- PORTAL_COMPONENT_ATTRIBUTE,
246
- PORTAL_REGION_ATTRIBUTE,
247
- };
248
- // Verify required values
249
- const NOT_REQUIRED = ['IS_DEV_MODE'];
250
- Object.keys(adapterConstants).forEach(key => {
251
- if (NOT_REQUIRED.indexOf(key) === -1 && !adapterConstants[key]) {
252
- throw Error(`constants.ts: Config value '${key}' is missing (from .env?)`);
253
- }
254
- });
255
- export default adapterConstants;