@sitecore-content-sdk/nextjs 0.1.0-beta.8 → 0.1.0-canary.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 (99) hide show
  1. package/README.md +5 -4
  2. package/client.d.ts +1 -0
  3. package/client.js +1 -0
  4. package/component-props-loader.d.ts +1 -0
  5. package/component-props-loader.js +3 -0
  6. package/dist/cjs/client/index.js +10 -0
  7. package/dist/cjs/client/sitecore-nextjs-client.js +117 -0
  8. package/dist/cjs/components/RichText.js +16 -4
  9. package/dist/cjs/config/define-cli-config.js +30 -0
  10. package/dist/cjs/config/index.js +3 -1
  11. package/dist/cjs/editing/editing-config-middleware.js +1 -3
  12. package/dist/cjs/editing/editing-render-middleware.js +13 -9
  13. package/dist/cjs/editing/index.js +2 -2
  14. package/dist/cjs/index.js +16 -18
  15. package/dist/cjs/middleware/index.js +3 -1
  16. package/dist/cjs/middleware/middleware.js +23 -12
  17. package/dist/cjs/middleware/multisite-middleware.js +19 -8
  18. package/dist/cjs/middleware/personalize-middleware.js +3 -3
  19. package/dist/cjs/middleware/redirects-middleware.js +28 -13
  20. package/dist/cjs/middleware/sitemap-middleware.js +47 -0
  21. package/dist/cjs/services/component-props-service.js +41 -50
  22. package/dist/cjs/tools/component-props.loader.js +101 -0
  23. package/dist/cjs/tools/index.js +9 -0
  24. package/dist/cjs/tools/templating/byoc-component.js +75 -0
  25. package/dist/cjs/tools/templating/constants.js +7 -0
  26. package/dist/cjs/tools/templating/default-component.js +54 -0
  27. package/dist/cjs/tools/templating/utils.js +18 -0
  28. package/dist/cjs/utils/index.js +2 -1
  29. package/dist/cjs/utils/utils.js +10 -1
  30. package/dist/esm/client/index.js +2 -0
  31. package/dist/esm/client/sitecore-nextjs-client.js +113 -0
  32. package/dist/esm/components/RichText.js +14 -2
  33. package/dist/esm/config/define-cli-config.js +26 -0
  34. package/dist/esm/config/index.js +1 -0
  35. package/dist/esm/editing/editing-config-middleware.js +1 -3
  36. package/dist/esm/editing/editing-render-middleware.js +11 -7
  37. package/dist/esm/editing/index.js +1 -1
  38. package/dist/esm/index.js +3 -5
  39. package/dist/esm/middleware/index.js +1 -0
  40. package/dist/esm/middleware/middleware.js +23 -12
  41. package/dist/esm/middleware/multisite-middleware.js +20 -9
  42. package/dist/esm/middleware/personalize-middleware.js +4 -4
  43. package/dist/esm/middleware/redirects-middleware.js +29 -14
  44. package/dist/esm/middleware/sitemap-middleware.js +43 -0
  45. package/dist/esm/services/component-props-service.js +41 -50
  46. package/dist/esm/tools/component-props.loader.js +65 -0
  47. package/dist/esm/tools/index.js +1 -0
  48. package/dist/esm/tools/templating/byoc-component.js +69 -0
  49. package/dist/esm/tools/templating/constants.js +4 -0
  50. package/dist/esm/tools/templating/default-component.js +48 -0
  51. package/dist/esm/tools/templating/utils.js +12 -0
  52. package/dist/esm/utils/index.js +1 -1
  53. package/dist/esm/utils/utils.js +8 -0
  54. package/package.json +16 -13
  55. package/tools.d.ts +1 -0
  56. package/tools.js +1 -0
  57. package/types/client/index.d.ts +2 -0
  58. package/types/client/sitecore-nextjs-client.d.ts +44 -0
  59. package/types/components/RichText.d.ts +7 -1
  60. package/types/config/define-cli-config.d.ts +8 -0
  61. package/types/config/index.d.ts +1 -0
  62. package/types/editing/editing-config-middleware.d.ts +4 -2
  63. package/types/editing/editing-render-middleware.d.ts +3 -31
  64. package/types/editing/index.d.ts +1 -1
  65. package/types/index.d.ts +6 -8
  66. package/types/middleware/index.d.ts +1 -0
  67. package/types/middleware/middleware.d.ts +13 -7
  68. package/types/middleware/sitemap-middleware.d.ts +12 -0
  69. package/types/services/component-props-service.d.ts +10 -26
  70. package/types/sharedTypes/component-props.d.ts +18 -0
  71. package/types/sharedTypes/sitecore-page-props.d.ts +5 -0
  72. package/types/tools/component-props.loader.d.ts +7 -0
  73. package/types/tools/index.d.ts +1 -0
  74. package/types/tools/templating/byoc-component.d.ts +2 -0
  75. package/types/tools/templating/constants.d.ts +4 -0
  76. package/types/tools/templating/default-component.d.ts +2 -0
  77. package/types/tools/templating/utils.d.ts +6 -0
  78. package/types/utils/index.d.ts +1 -1
  79. package/types/utils/utils.d.ts +2 -0
  80. package/dist/cjs/ComponentBuilder.js +0 -63
  81. package/dist/cjs/graphql/index.js +0 -7
  82. package/dist/cjs/services/base-graphql-sitemap-service.js +0 -206
  83. package/dist/cjs/services/graphql-sitemap-service.js +0 -64
  84. package/dist/cjs/services/mutisite-graphql-sitemap-service.js +0 -81
  85. package/dist/esm/ComponentBuilder.js +0 -59
  86. package/dist/esm/graphql/index.js +0 -1
  87. package/dist/esm/services/base-graphql-sitemap-service.js +0 -201
  88. package/dist/esm/services/graphql-sitemap-service.js +0 -59
  89. package/dist/esm/services/mutisite-graphql-sitemap-service.js +0 -77
  90. package/graphql.d.ts +0 -1
  91. package/graphql.js +0 -1
  92. package/types/ComponentBuilder.d.ts +0 -59
  93. package/types/graphql/index.d.ts +0 -1
  94. package/types/services/base-graphql-sitemap-service.d.ts +0 -148
  95. package/types/services/graphql-sitemap-service.d.ts +0 -51
  96. package/types/services/mutisite-graphql-sitemap-service.d.ts +0 -42
  97. package/types/sharedTypes/module-factory.d.ts +0 -32
  98. /package/dist/cjs/sharedTypes/{module-factory.js → sitecore-page-props.js} +0 -0
  99. /package/dist/esm/sharedTypes/{module-factory.js → sitecore-page-props.js} +0 -0
@@ -72,6 +72,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
72
72
  core_1.debug.redirects('skipped (redirect does not exist)');
73
73
  return res;
74
74
  }
75
+ core_1.debug.redirects('Matched redirect rule: %o', { existsRedirect });
75
76
  // Find context site language and replace token
76
77
  if (REGEXP_CONTEXT_SITE_LANG.test(existsRedirect.target) &&
77
78
  !(REGEXP_ABSOLUTE_URL.test(existsRedirect.target) &&
@@ -118,7 +119,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
118
119
  return this.createRedirectResponse(url, res, 302, 'Found');
119
120
  }
120
121
  case site_1.REDIRECT_TYPE_SERVER_TRANSFER: {
121
- return this.rewrite(url.href, req, res);
122
+ return this.rewrite(url.href, req, res, true);
122
123
  }
123
124
  default:
124
125
  return res;
@@ -153,23 +154,35 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
153
154
  */
154
155
  getExistsRedirect(req, siteName) {
155
156
  return __awaiter(this, void 0, void 0, function* () {
156
- const { pathname: targetURL, search: targetQS = '', locale } = this.normalizeUrl(req.nextUrl.clone());
157
- const normalizedPath = targetURL.replace(/\/*$/gi, '');
157
+ const { pathname: incomingURL, search: incomingQS = '' } = this.normalizeUrl(req.nextUrl.clone());
158
+ const locale = this.getLanguage(req);
159
+ const normalizedPath = incomingURL.replace(/\/*$/gi, '');
158
160
  const redirects = yield this.redirectsService.fetchRedirects(siteName);
159
161
  const language = this.getLanguage(req);
160
162
  const modifyRedirects = structuredClone(redirects);
161
163
  let matchedQueryString;
164
+ const localePath = `/${locale.toLowerCase()}${normalizedPath}`;
162
165
  return modifyRedirects.length
163
166
  ? modifyRedirects.find((redirect) => {
164
- var _a;
167
+ // process static URL (non-regex) rules
165
168
  if ((0, utils_1.isRegexOrUrl)(redirect.pattern) === 'url') {
166
- const parseUrlPattern = redirect.pattern.endsWith('/')
169
+ const urlArray = redirect.pattern.endsWith('/')
167
170
  ? redirect.pattern.slice(0, -1).split('?')
168
171
  : redirect.pattern.split('?');
169
- return ((parseUrlPattern[0] === normalizedPath ||
170
- parseUrlPattern[0] === `/${locale}${normalizedPath}`) &&
171
- (0, utils_1.areURLSearchParamsEqual)(new URLSearchParams((_a = parseUrlPattern[1]) !== null && _a !== void 0 ? _a : ''), new URLSearchParams(targetQS)));
172
+ const patternQS = urlArray[1];
173
+ let patternPath = urlArray[0];
174
+ // nextjs routes are case-sensitive, but locales should be compared case-insensitively
175
+ const patternParts = patternPath.split('/');
176
+ const maybeLocale = patternParts[1].toLowerCase();
177
+ // case insensitive lookup of locales
178
+ if (new RegExp(this.locales.join('|'), 'i').test(maybeLocale)) {
179
+ patternPath = patternPath.replace(`/${patternParts[1]}`, `/${maybeLocale}`);
180
+ }
181
+ return ((patternPath === localePath || patternPath === normalizedPath) &&
182
+ (!patternQS ||
183
+ (0, utils_1.areURLSearchParamsEqual)(new URLSearchParams(patternQS), new URLSearchParams(incomingQS))));
172
184
  }
185
+ // process regex rules
173
186
  // Modify the redirect pattern to ignore the language prefix in the path
174
187
  // And escapes non-special "?" characters in a string or regex.
175
188
  redirect.pattern = (0, utils_1.escapeNonSpecialQuestionMarks)(redirect.pattern.replace(new RegExp(`^[^]?/${language}/`, 'gi'), ''));
@@ -179,16 +192,17 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
179
192
  .replace(/^\^\/|\/\$$/g, '') // Removes unnecessary start (^) and end ($) anchors
180
193
  .replace(/^\^|\$$/g, '') // Further cleans up anchors
181
194
  .replace(/\$\/gi$/g, '')}[\/]?$/i`; // Ensures the pattern allows an optional trailing slash
195
+ // Redirect pattern matches the full incoming URL with query string present
182
196
  matchedQueryString = [
183
- (0, regex_parser_1.default)(redirect.pattern).test(`${normalizedPath}${targetQS}`),
184
- (0, regex_parser_1.default)(redirect.pattern).test(`/${locale}${normalizedPath}${targetQS}`),
197
+ (0, regex_parser_1.default)(redirect.pattern).test(`/${localePath}${incomingQS}`),
198
+ (0, regex_parser_1.default)(redirect.pattern).test(`${normalizedPath}${incomingQS}`),
185
199
  ].some(Boolean)
186
- ? targetQS
200
+ ? incomingQS
187
201
  : undefined;
188
202
  // Save the matched query string (if found) into the redirect object
189
203
  redirect.matchedQueryString = matchedQueryString || '';
190
- return (!!((0, regex_parser_1.default)(redirect.pattern).test(targetURL) ||
191
- (0, regex_parser_1.default)(redirect.pattern).test(`/${req.nextUrl.locale}${targetURL}`) ||
204
+ return (!!((0, regex_parser_1.default)(redirect.pattern).test(`/${req.nextUrl.locale}${incomingURL}`) ||
205
+ (0, regex_parser_1.default)(redirect.pattern).test(incomingURL) ||
192
206
  matchedQueryString) && (redirect.locale ? redirect.locale.toLowerCase() === locale.toLowerCase() : true));
193
207
  })
194
208
  : undefined;
@@ -251,6 +265,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
251
265
  if (res === null || res === void 0 ? void 0 : res.headers) {
252
266
  redirect.headers.delete('x-middleware-next');
253
267
  redirect.headers.delete('x-middleware-rewrite');
268
+ redirect.headers.delete(middleware_1.REWRITE_HEADER_NAME);
254
269
  }
255
270
  return redirect;
256
271
  }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SitemapMiddleware = void 0;
13
+ /**
14
+ * Middleware for handling sitemap requests in a Next.js application.
15
+ * Encapsulates all HTTP-related logic for sitemap generation and delivery.
16
+ */
17
+ class SitemapMiddleware {
18
+ constructor(client) {
19
+ this.client = client;
20
+ }
21
+ getHandler() {
22
+ return this.handler.bind(this);
23
+ }
24
+ handler(req, res) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const id = Array.isArray(req.query.id) ? req.query.id[0] : req.query.id;
27
+ const reqHost = req.headers.host || '';
28
+ const reqProtocol = req.headers['x-forwarded-proto'] || 'https';
29
+ const site = this.client.resolveSite(reqHost);
30
+ const options = { reqHost, reqProtocol, id, siteName: site.name };
31
+ try {
32
+ const xmlContent = yield this.client.getSiteMap(options);
33
+ res.setHeader('Content-Type', 'text/xml;charset=utf-8');
34
+ res.send(xmlContent);
35
+ }
36
+ catch (error) {
37
+ if (error instanceof Error && error.message === 'REDIRECT_404') {
38
+ res.redirect('/404');
39
+ }
40
+ else {
41
+ res.status(500).send('Internal Server Error');
42
+ }
43
+ }
44
+ });
45
+ }
46
+ }
47
+ exports.SitemapMiddleware = SitemapMiddleware;
@@ -15,57 +15,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.ComponentPropsService = void 0;
16
16
  const chalk_1 = __importDefault(require("chalk"));
17
17
  class ComponentPropsService {
18
- /**
19
- * SSR mode
20
- * Fetch component props using getServerSideProps function
21
- * @param {FetchComponentPropsArguments<GetServerSidePropsContext>} params fetch params
22
- * @returns {Promise<ComponentPropsCollection>} props
23
- */
24
- fetchServerSideComponentProps(params) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- const { moduleFactory, layoutData, context } = params;
27
- const fetchFunctionFactory = (componentName) => __awaiter(this, void 0, void 0, function* () {
28
- const module = yield moduleFactory(componentName);
29
- return module === null || module === void 0 ? void 0 : module.getServerSideProps;
30
- });
31
- return this.fetchComponentProps(fetchFunctionFactory, layoutData, context);
32
- });
33
- }
34
- /**
35
- * SSG mode
36
- * Fetch component props using getStaticProps function
37
- * @param {FetchComponentPropsArguments<GetStaticPropsContext>} params fetch arguments
38
- * @returns {Promise<ComponentPropsCollection>} props
39
- */
40
- fetchStaticComponentProps(params) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- const { moduleFactory, layoutData, context } = params;
43
- const fetchFunctionFactory = (componentName) => __awaiter(this, void 0, void 0, function* () {
44
- const module = yield moduleFactory(componentName);
45
- return module === null || module === void 0 ? void 0 : module.getStaticProps;
46
- });
47
- return this.fetchComponentProps(fetchFunctionFactory, layoutData, context);
48
- });
49
- }
50
- /**
51
- * Traverse Layout Service data tree and call side effects on component level.
52
- * Side effect function can be: getStaticProps (SSG) or getServerSideProps (SSR)
53
- * @param {FetchFunctionFactory<NextContext>} fetchFunctionFactory fetch function factory
54
- * @param {LayoutServiceData} layoutData layout data
55
- * @param {NextContext} context next context
56
- * @returns {Promise<ComponentPropsCollection>} component props
57
- */
58
- fetchComponentProps(fetchFunctionFactory, layoutData, context) {
18
+ fetchComponentProps(params) {
59
19
  return __awaiter(this, void 0, void 0, function* () {
60
- var _a;
61
- // Array of side effect functions
62
- const requests = yield this.collectRequests({
63
- placeholders: (_a = layoutData.sitecore.route) === null || _a === void 0 ? void 0 : _a.placeholders,
64
- fetchFunctionFactory,
65
- layoutData,
66
- context,
67
- });
68
- return yield this.execRequests(requests);
20
+ var _a, _b;
21
+ const { layoutData, context, components } = params;
22
+ if (this.isServerSidePropsContext(context)) {
23
+ const fetchFunctionFactory = (componentName) => __awaiter(this, void 0, void 0, function* () { var _a; return (_a = (yield this.getModule(components, componentName))) === null || _a === void 0 ? void 0 : _a.getServerSideProps; });
24
+ const requests = yield this.collectRequests({
25
+ placeholders: (_a = layoutData.sitecore.route) === null || _a === void 0 ? void 0 : _a.placeholders,
26
+ fetchFunctionFactory,
27
+ layoutData,
28
+ context,
29
+ });
30
+ return yield this.execRequests(requests);
31
+ }
32
+ else {
33
+ const fetchFunctionFactory = (componentName) => __awaiter(this, void 0, void 0, function* () { var _a; return (_a = (yield this.getModule(components, componentName))) === null || _a === void 0 ? void 0 : _a.getStaticProps; });
34
+ const requests = yield this.collectRequests({
35
+ placeholders: (_b = layoutData.sitecore.route) === null || _b === void 0 ? void 0 : _b.placeholders,
36
+ fetchFunctionFactory,
37
+ layoutData,
38
+ context,
39
+ });
40
+ return yield this.execRequests(requests);
41
+ }
69
42
  });
70
43
  }
71
44
  /**
@@ -163,5 +136,23 @@ class ComponentPropsService {
163
136
  });
164
137
  return allComponentRenderings;
165
138
  }
139
+ // TODO: remove when unifying server/static component props
140
+ /**
141
+ * Determines whether context is GetServerSidePropsContext (SSR) or GetStaticPropsContext (SSG)
142
+ * @param {GetServerSidePropsContext | GetStaticPropsContext} context
143
+ */
144
+ isServerSidePropsContext(context) {
145
+ return context.req !== undefined;
146
+ }
147
+ getModule(components, componentName) {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ var _a;
150
+ const component = components.get(componentName);
151
+ if (!component)
152
+ return null;
153
+ const module = component.dynamicModule ? yield ((_a = component === null || component === void 0 ? void 0 : component.dynamicModule) === null || _a === void 0 ? void 0 : _a.call(component)) : component;
154
+ return module;
155
+ });
156
+ }
166
157
  }
167
158
  exports.ComponentPropsService = ComponentPropsService;
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.default = componentPropsLoader;
37
+ const recast = __importStar(require("recast"));
38
+ /**
39
+ * Webpack loader to strip functions from the source code
40
+ * Strips the `getServerSideProps` and `getStaticProps` functions from the source code
41
+ * @param {string} source file source code
42
+ * @returns {string} output file source code with stripped functions
43
+ */
44
+ function componentPropsLoader(source) {
45
+ // Parse the source code into an AST (Abstract Syntax Tree)
46
+ const ast = recast.parse(source, {
47
+ parser: require('recast/parsers/babel-ts'),
48
+ });
49
+ // List of functions to strip from the AST
50
+ const functionsToStrip = ['getServerSideProps', 'getStaticProps'];
51
+ // Remove the function from the list of functions to strip
52
+ const updateList = (functionName) => {
53
+ // Remove the function from the list of functions to strip
54
+ functionsToStrip.splice(functionsToStrip.indexOf(functionName), 1);
55
+ };
56
+ // Traverse the AST and strip the functions
57
+ recast.visit(ast, {
58
+ // Visit the named export function expression
59
+ visitExportNamedDeclaration: function (path) {
60
+ var _a, _b;
61
+ // Get the variable declaration from the AST
62
+ (_b = (_a = path.node.declaration) === null || _a === void 0 ? void 0 : _a.declarations) === null || _b === void 0 ? void 0 : _b.forEach((declaration) => {
63
+ // Check if the function is in the list of functions to strip
64
+ if ('id' in declaration &&
65
+ 'name' in declaration.id &&
66
+ typeof declaration.id.name === 'string' &&
67
+ functionsToStrip.includes(declaration.id.name)) {
68
+ updateList(declaration.id.name);
69
+ // Strip the function from the AST
70
+ path.prune();
71
+ }
72
+ });
73
+ if (functionsToStrip.length === 0) {
74
+ // We have pruned all the functions we need to, so we can stop traversing the AST
75
+ return false;
76
+ }
77
+ // Continue traversing the AST
78
+ this.traverse(path);
79
+ },
80
+ // Visit the named export function declaration
81
+ visitFunctionDeclaration: function (path) {
82
+ // Check if the function is in the list of functions to strip
83
+ if (path.node.id &&
84
+ 'name' in path.node.id &&
85
+ typeof path.node.id.name === 'string' &&
86
+ functionsToStrip.includes(path.node.id.name)) {
87
+ updateList(path.node.id.name);
88
+ // Strip the function from the AST
89
+ path.prune();
90
+ }
91
+ if (functionsToStrip.length === 0) {
92
+ // We have pruned all the functions we need to, so we can stop traversing the AST
93
+ return false;
94
+ }
95
+ // Continue traversing the AST
96
+ this.traverse(path);
97
+ },
98
+ });
99
+ // Generate the output code
100
+ return recast.print(ast).code;
101
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ModuleType = exports.generatePlugins = exports.getComponentList = exports.generateMetadata = exports.generateSites = void 0;
4
+ var tools_1 = require("@sitecore-content-sdk/core/tools");
5
+ Object.defineProperty(exports, "generateSites", { enumerable: true, get: function () { return tools_1.generateSites; } });
6
+ Object.defineProperty(exports, "generateMetadata", { enumerable: true, get: function () { return tools_1.generateMetadata; } });
7
+ Object.defineProperty(exports, "getComponentList", { enumerable: true, get: function () { return tools_1.getComponentList; } });
8
+ Object.defineProperty(exports, "generatePlugins", { enumerable: true, get: function () { return tools_1.generatePlugins; } });
9
+ Object.defineProperty(exports, "ModuleType", { enumerable: true, get: function () { return tools_1.ModuleType; } });
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.byocTemplate = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const config_1 = require("@sitecore-content-sdk/core/config");
9
+ const constants_1 = require("./constants");
10
+ /**
11
+ * Next.js BYOC component boilerplate
12
+ * @param {string} componentName - the component name
13
+ * @returns component generated template
14
+ */
15
+ const generateTemplate = (componentName) => {
16
+ return `import React from 'react';
17
+ import * as FEAAS from '@sitecore-feaas/clientside/react';
18
+
19
+ interface ${componentName}Props {
20
+ title: string;
21
+ columnsCount: number;
22
+ }
23
+
24
+ export const ${componentName} = (props: ${componentName}Props): JSX.Element => {
25
+ const columns: string[] = [];
26
+ for (let i = 0; i < props.columnsCount; i++) {
27
+ columns.push(\`Component Column \${i + 1}\`);
28
+ }
29
+ return (
30
+ <div className="container">
31
+ <h2>{props.title || 'BYOC Demo'}</h2>
32
+ <p>${componentName} Component</p>
33
+ <div className="row">
34
+ {columns.map((text, index) => (
35
+ <div key={index} className={\`col-sm-\${props.columnsCount}\`}>
36
+ {text}
37
+ </div>
38
+ ))}
39
+ </div>
40
+ </div>
41
+ );
42
+ };
43
+
44
+ FEAAS.External.registerComponent(${componentName}, {
45
+ name: '${componentName}',
46
+ properties: {
47
+ title: {
48
+ type: 'string',
49
+ },
50
+ columnsCount: {
51
+ type: 'number',
52
+ },
53
+ },
54
+ });
55
+ `;
56
+ };
57
+ /**
58
+ * Generates a list of next steps when scaffolding a component.
59
+ * @param {string} componentOutputPath - The file path where the component file is generated.
60
+ * @returns {string[]} An array of strings, each representing a next step.
61
+ */
62
+ const getNextSteps = (componentOutputPath) => {
63
+ const nextSteps = [];
64
+ nextSteps.push('* Modify component registration through FEAAS.External.registerComponent if needed');
65
+ if (componentOutputPath) {
66
+ nextSteps.push(`* Implement the component in ${chalk_1.default.green(componentOutputPath)}`);
67
+ }
68
+ return nextSteps;
69
+ };
70
+ exports.byocTemplate = {
71
+ name: config_1.ComponentTemplateType.BYOC,
72
+ fileExtension: constants_1.COMPONENT_FILE_EXTENSION,
73
+ generateTemplate,
74
+ getNextSteps,
75
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.COMPONENT_FILE_EXTENSION = void 0;
4
+ /**
5
+ * The file extension for nextjs components
6
+ */
7
+ exports.COMPONENT_FILE_EXTENSION = 'tsx';
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.defaultTemplate = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const config_1 = require("@sitecore-content-sdk/core/config");
9
+ const constants_1 = require("./constants");
10
+ /**
11
+ * Next.js component boilerplate
12
+ * @param {string} componentName - the component name
13
+ * @returns component generated template
14
+ */
15
+ const generateTemplate = (componentName) => {
16
+ return `import React from 'react';
17
+ import { ComponentParams, ComponentRendering } from '@sitecore-content-sdk/nextjs';
18
+
19
+ interface ${componentName}Props {
20
+ rendering: ComponentRendering & { params: ComponentParams };
21
+ params: ComponentParams;
22
+ }
23
+
24
+ export const Default = (props: ${componentName}Props): JSX.Element => {
25
+ const id = props.params.RenderingIdentifier;
26
+
27
+ return (
28
+ <div className={\`component \${props.params.styles}\`} id={id ? id : undefined}>
29
+ <div className="component-content">
30
+ <p>${componentName} Component</p>
31
+ </div>
32
+ </div>
33
+ );
34
+ };
35
+ `;
36
+ };
37
+ /**
38
+ * Generates a list of next steps when scaffolding a component.
39
+ * @param {string} componentOutputPath - The file path where the component file is generated.
40
+ * @returns {string[]} An array of strings, each representing a next step.
41
+ */
42
+ const getNextSteps = (componentOutputPath) => {
43
+ const nextSteps = [];
44
+ if (componentOutputPath) {
45
+ nextSteps.push(`* Implement the React component in ${chalk_1.default.green(componentOutputPath)}`);
46
+ }
47
+ return nextSteps;
48
+ };
49
+ exports.defaultTemplate = {
50
+ name: config_1.ComponentTemplateType.DEFAULT,
51
+ fileExtension: constants_1.COMPONENT_FILE_EXTENSION,
52
+ generateTemplate,
53
+ getNextSteps,
54
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.watchItems = watchItems;
7
+ const chokidar_1 = __importDefault(require("chokidar"));
8
+ /**
9
+ * Run watch mode, watching on @var paths
10
+ * @param {string[]} paths paths to watch by chokidar
11
+ * @param {Function<void>} cb callback to run on file change
12
+ */
13
+ function watchItems(paths, cb) {
14
+ chokidar_1.default
15
+ .watch(paths, { ignoreInitial: true, awaitWriteFinish: true })
16
+ .on('add', cb)
17
+ .on('unlink', cb);
18
+ }
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resetEditorChromes = exports.isEditorActive = exports.resolveUrl = exports.tryParseEnvValue = exports.handleEditorFastRefresh = void 0;
3
+ exports.resetEditorChromes = exports.isEditorActive = exports.resolveUrl = exports.tryParseEnvValue = exports.extractPath = exports.handleEditorFastRefresh = void 0;
4
4
  var utils_1 = require("./utils");
5
5
  Object.defineProperty(exports, "handleEditorFastRefresh", { enumerable: true, get: function () { return utils_1.handleEditorFastRefresh; } });
6
+ Object.defineProperty(exports, "extractPath", { enumerable: true, get: function () { return utils_1.extractPath; } });
6
7
  var utils_2 = require("@sitecore-content-sdk/core/utils");
7
8
  Object.defineProperty(exports, "tryParseEnvValue", { enumerable: true, get: function () { return utils_2.tryParseEnvValue; } });
8
9
  Object.defineProperty(exports, "resolveUrl", { enumerable: true, get: function () { return utils_2.resolveUrl; } });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getJssEditingSecret = exports.handleEditorFastRefresh = void 0;
3
+ exports.extractPath = exports.getJssEditingSecret = exports.handleEditorFastRefresh = void 0;
4
4
  const editing_1 = require("@sitecore-content-sdk/core/editing");
5
5
  /**
6
6
  * Since Sitecore editors do not support Fast Refresh:
@@ -40,3 +40,12 @@ const getJssEditingSecret = () => {
40
40
  return secret;
41
41
  };
42
42
  exports.getJssEditingSecret = getJssEditingSecret;
43
+ const extractPath = (context) => {
44
+ var _a;
45
+ return context.params === undefined
46
+ ? '/'
47
+ : Array.isArray(context.params.path)
48
+ ? context.params.path.join('/')
49
+ : (_a = context.params.path) !== null && _a !== void 0 ? _a : '/';
50
+ };
51
+ exports.extractPath = extractPath;
@@ -0,0 +1,2 @@
1
+ export { DefaultRetryStrategy, GraphQLRequestClient, getEdgeProxyContentUrl, createGraphQLClientFactory, } from '@sitecore-content-sdk/core/client';
2
+ export { SitecoreNextjsClient as SitecoreClient } from './sitecore-nextjs-client';