@sitecore-content-sdk/nextjs 0.2.0-beta.6 → 0.2.0-beta.7
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/cjs/config/define-config.js +25 -0
- package/dist/cjs/config/index.js +3 -3
- package/dist/cjs/index.js +9 -4
- package/dist/cjs/middleware/index.js +10 -1
- package/dist/cjs/middleware/middleware.js +4 -0
- package/dist/cjs/middleware/personalize-middleware.js +32 -25
- package/dist/cjs/middleware/redirects-middleware.js +12 -1
- package/dist/cjs/middleware/robots-middleware.js +42 -0
- package/dist/esm/config/define-config.js +20 -0
- package/dist/esm/config/index.js +1 -1
- package/dist/esm/index.js +3 -3
- package/dist/esm/middleware/index.js +3 -0
- package/dist/esm/middleware/middleware.js +4 -0
- package/dist/esm/middleware/personalize-middleware.js +32 -25
- package/dist/esm/middleware/redirects-middleware.js +12 -1
- package/dist/esm/middleware/robots-middleware.js +38 -0
- package/package.json +30 -32
- package/types/config/define-config.d.ts +33 -0
- package/types/config/index.d.ts +1 -1
- package/types/index.d.ts +4 -4
- package/types/middleware/index.d.ts +3 -0
- package/types/middleware/middleware.d.ts +3 -0
- package/types/middleware/personalize-middleware.d.ts +6 -29
- package/types/middleware/redirects-middleware.d.ts +13 -6
- package/types/middleware/robots-middleware.d.ts +11 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineConfig = exports.getNextFallbackConfig = void 0;
|
|
4
|
+
const config_1 = require("@sitecore-content-sdk/core/config");
|
|
5
|
+
/**
|
|
6
|
+
* Provides default NextJs initial values from env variables for SitecoreConfig
|
|
7
|
+
* @param {SitecoreConfigInput} config optional override values to be written over default config settings
|
|
8
|
+
* @returns default nextjs input config
|
|
9
|
+
*/
|
|
10
|
+
const getNextFallbackConfig = (config) => {
|
|
11
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
12
|
+
return Object.assign(Object.assign({}, config), { api: Object.assign(Object.assign({}, config === null || config === void 0 ? void 0 : config.api), { edge: Object.assign(Object.assign({}, (_a = config === null || config === void 0 ? void 0 : config.api) === null || _a === void 0 ? void 0 : _a.edge), { contextId: ((_c = (_b = config === null || config === void 0 ? void 0 : config.api) === null || _b === void 0 ? void 0 : _b.edge) === null || _c === void 0 ? void 0 : _c.contextId) || process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID || '', clientContextId: ((_e = (_d = config === null || config === void 0 ? void 0 : config.api) === null || _d === void 0 ? void 0 : _d.edge) === null || _e === void 0 ? void 0 : _e.clientContextId) || process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID, edgeUrl: ((_g = (_f = config === null || config === void 0 ? void 0 : config.api) === null || _f === void 0 ? void 0 : _f.edge) === null || _g === void 0 ? void 0 : _g.edgeUrl) || process.env.NEXT_PUBLIC_SITECORE_EDGE_URL }), local: Object.assign(Object.assign({}, (_h = config === null || config === void 0 ? void 0 : config.api) === null || _h === void 0 ? void 0 : _h.local), { apiKey: ((_k = (_j = config === null || config === void 0 ? void 0 : config.api) === null || _j === void 0 ? void 0 : _j.local) === null || _k === void 0 ? void 0 : _k.apiKey) || process.env.NEXT_PUBLIC_SITECORE_API_KEY || '', apiHost: ((_m = (_l = config === null || config === void 0 ? void 0 : config.api) === null || _l === void 0 ? void 0 : _l.local) === null || _m === void 0 ? void 0 : _m.apiHost) || process.env.NEXT_PUBLIC_SITECORE_API_HOST || '' }) }), defaultSite: (config === null || config === void 0 ? void 0 : config.defaultSite) || process.env.NEXT_PUBLIC_SITECORE_SITE_NAME || '', defaultLanguage: (config === null || config === void 0 ? void 0 : config.defaultLanguage) || process.env.NEXT_PUBLIC_DEFAULT_LANGUAGE || 'en', multisite: Object.assign(Object.assign({}, config === null || config === void 0 ? void 0 : config.multisite), { useCookieResolution: (_p = (_o = config === null || config === void 0 ? void 0 : config.multisite) === null || _o === void 0 ? void 0 : _o.useCookieResolution) !== null && _p !== void 0 ? _p : (() => process.env.VERCEL_ENV === 'preview') }), personalize: Object.assign(Object.assign({}, config === null || config === void 0 ? void 0 : config.personalize), { scope: ((_q = config === null || config === void 0 ? void 0 : config.personalize) === null || _q === void 0 ? void 0 : _q.scope) || process.env.NEXT_PUBLIC_PERSONALIZE_SCOPE }), disableStaticPaths: process.env.DISABLE_SSG_FETCH !== undefined
|
|
13
|
+
? process.env.DISABLE_SSG_FETCH.toLowerCase() === 'true'
|
|
14
|
+
: (_r = config === null || config === void 0 ? void 0 : config.disableStaticPaths) !== null && _r !== void 0 ? _r : false });
|
|
15
|
+
};
|
|
16
|
+
exports.getNextFallbackConfig = getNextFallbackConfig;
|
|
17
|
+
/**
|
|
18
|
+
* Accepts a SitecoreConfigInput object and returns full sitecore configuration
|
|
19
|
+
* @param {SitecoreConfigInput} config override values to be written over default config settings
|
|
20
|
+
* @returns {SitecoreConfig} full sitecore configuration to use in application
|
|
21
|
+
*/
|
|
22
|
+
const defineConfig = (config) => {
|
|
23
|
+
return (0, config_1.defineConfig)((0, exports.getNextFallbackConfig)(config));
|
|
24
|
+
};
|
|
25
|
+
exports.defineConfig = defineConfig;
|
package/dist/cjs/config/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var config_1 = require("@sitecore-content-sdk/core/config");
|
|
5
|
-
Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return config_1.defineConfig; } });
|
|
3
|
+
exports.defineConfig = exports.defineCliConfig = void 0;
|
|
6
4
|
var define_cli_config_1 = require("./define-cli-config");
|
|
7
5
|
Object.defineProperty(exports, "defineCliConfig", { enumerable: true, get: function () { return define_cli_config_1.defineCliConfig; } });
|
|
6
|
+
var define_config_1 = require("./define-config");
|
|
7
|
+
Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return define_config_1.defineConfig; } });
|
package/dist/cjs/index.js
CHANGED
|
@@ -33,8 +33,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.
|
|
37
|
-
exports.Form = exports.EditingScripts = exports.withEmptyFieldEditingComponent = exports.withFieldMetadata = exports.withDatasourceCheck = exports.withPlaceholder = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = exports.DefaultEmptyFieldEditingComponentText = void 0;
|
|
36
|
+
exports.fetchFEaaSComponentServerProps = exports.FEaaSComponent = exports.DateField = exports.Text = exports.Image = exports.BYOCWrapper = exports.FEaaSWrapper = exports.NextImage = exports.Placeholder = exports.RichText = exports.Link = exports.useComponentProps = exports.ComponentPropsContext = exports.ComponentPropsReactContext = exports.ComponentPropsService = exports.normalizeSiteRewrite = exports.getSiteRewriteData = exports.getSiteRewrite = exports.GraphQLSiteInfoService = exports.SiteResolver = exports.GraphQLRobotsService = exports.GraphQLErrorPagesService = exports.GraphQLSitemapXmlService = exports.REDIRECT_TYPE_SERVER_TRANSFER = exports.REDIRECT_TYPE_302 = exports.REDIRECT_TYPE_301 = exports.GraphQLRedirectsService = exports.GraphQLSitePathService = exports.GraphQLPersonalizeService = exports.CdpHelper = exports.normalizePersonalizedRewrite = exports.getGroomedVariantIds = exports.getPersonalizedRewriteData = exports.getPersonalizedRewrite = exports.personalizeLayout = exports.GraphQLDictionaryService = exports.mediaApi = exports.RestComponentLayoutService = exports.RenderingType = exports.EditMode = exports.getContentStylesheetLink = exports.getFieldValue = exports.getChildPlaceholder = exports.GraphQLLayoutService = exports.LayoutServicePageState = exports.MemoryCacheClient = exports.debug = exports.enableDebug = exports.NativeDataFetcher = exports.constants = void 0;
|
|
37
|
+
exports.Form = exports.EditingScripts = exports.withEmptyFieldEditingComponent = exports.withFieldMetadata = exports.withDatasourceCheck = exports.withPlaceholder = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = exports.DefaultEmptyFieldEditingComponentText = exports.DefaultEmptyFieldEditingComponentImage = exports.DesignLibrary = exports.File = exports.getDesignLibraryStylesheetLinks = exports.BYOCComponent = void 0;
|
|
38
38
|
var core_1 = require("@sitecore-content-sdk/core");
|
|
39
39
|
Object.defineProperty(exports, "constants", { enumerable: true, get: function () { return core_1.constants; } });
|
|
40
40
|
// generic data access
|
|
@@ -63,10 +63,13 @@ Object.defineProperty(exports, "getPersonalizedRewriteData", { enumerable: true,
|
|
|
63
63
|
Object.defineProperty(exports, "getGroomedVariantIds", { enumerable: true, get: function () { return personalize_1.getGroomedVariantIds; } });
|
|
64
64
|
Object.defineProperty(exports, "normalizePersonalizedRewrite", { enumerable: true, get: function () { return personalize_1.normalizePersonalizedRewrite; } });
|
|
65
65
|
Object.defineProperty(exports, "CdpHelper", { enumerable: true, get: function () { return personalize_1.CdpHelper; } });
|
|
66
|
-
|
|
67
|
-
Object.defineProperty(exports, "ComponentPropsService", { enumerable: true, get: function () { return component_props_service_1.ComponentPropsService; } });
|
|
66
|
+
Object.defineProperty(exports, "GraphQLPersonalizeService", { enumerable: true, get: function () { return personalize_1.GraphQLPersonalizeService; } });
|
|
68
67
|
var site_1 = require("@sitecore-content-sdk/core/site");
|
|
69
68
|
Object.defineProperty(exports, "GraphQLSitePathService", { enumerable: true, get: function () { return site_1.GraphQLSitePathService; } });
|
|
69
|
+
Object.defineProperty(exports, "GraphQLRedirectsService", { enumerable: true, get: function () { return site_1.GraphQLRedirectsService; } });
|
|
70
|
+
Object.defineProperty(exports, "REDIRECT_TYPE_301", { enumerable: true, get: function () { return site_1.REDIRECT_TYPE_301; } });
|
|
71
|
+
Object.defineProperty(exports, "REDIRECT_TYPE_302", { enumerable: true, get: function () { return site_1.REDIRECT_TYPE_302; } });
|
|
72
|
+
Object.defineProperty(exports, "REDIRECT_TYPE_SERVER_TRANSFER", { enumerable: true, get: function () { return site_1.REDIRECT_TYPE_SERVER_TRANSFER; } });
|
|
70
73
|
var site_2 = require("@sitecore-content-sdk/core/site");
|
|
71
74
|
Object.defineProperty(exports, "GraphQLSitemapXmlService", { enumerable: true, get: function () { return site_2.GraphQLSitemapXmlService; } });
|
|
72
75
|
Object.defineProperty(exports, "GraphQLErrorPagesService", { enumerable: true, get: function () { return site_2.GraphQLErrorPagesService; } });
|
|
@@ -76,6 +79,8 @@ Object.defineProperty(exports, "GraphQLSiteInfoService", { enumerable: true, get
|
|
|
76
79
|
Object.defineProperty(exports, "getSiteRewrite", { enumerable: true, get: function () { return site_2.getSiteRewrite; } });
|
|
77
80
|
Object.defineProperty(exports, "getSiteRewriteData", { enumerable: true, get: function () { return site_2.getSiteRewriteData; } });
|
|
78
81
|
Object.defineProperty(exports, "normalizeSiteRewrite", { enumerable: true, get: function () { return site_2.normalizeSiteRewrite; } });
|
|
82
|
+
var component_props_service_1 = require("./services/component-props-service");
|
|
83
|
+
Object.defineProperty(exports, "ComponentPropsService", { enumerable: true, get: function () { return component_props_service_1.ComponentPropsService; } });
|
|
79
84
|
var ComponentPropsContext_1 = require("./components/ComponentPropsContext");
|
|
80
85
|
Object.defineProperty(exports, "ComponentPropsReactContext", { enumerable: true, get: function () { return ComponentPropsContext_1.ComponentPropsReactContext; } });
|
|
81
86
|
Object.defineProperty(exports, "ComponentPropsContext", { enumerable: true, get: function () { return ComponentPropsContext_1.ComponentPropsContext; } });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SitemapMiddleware = exports.MultisiteMiddleware = exports.PersonalizeMiddleware = exports.RedirectsMiddleware = exports.defineMiddleware = exports.Middleware = exports.MiddlewareBase = exports.debug = void 0;
|
|
3
|
+
exports.REDIRECT_TYPE_SERVER_TRANSFER = exports.REDIRECT_TYPE_302 = exports.REDIRECT_TYPE_301 = exports.GraphQLRedirectsService = exports.GraphQLPersonalizeService = exports.RobotsMiddleware = exports.SitemapMiddleware = exports.MultisiteMiddleware = exports.PersonalizeMiddleware = exports.RedirectsMiddleware = exports.defineMiddleware = exports.Middleware = exports.MiddlewareBase = exports.debug = void 0;
|
|
4
4
|
var core_1 = require("@sitecore-content-sdk/core");
|
|
5
5
|
Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return core_1.debug; } });
|
|
6
6
|
var middleware_1 = require("./middleware");
|
|
@@ -15,3 +15,12 @@ var multisite_middleware_1 = require("./multisite-middleware");
|
|
|
15
15
|
Object.defineProperty(exports, "MultisiteMiddleware", { enumerable: true, get: function () { return multisite_middleware_1.MultisiteMiddleware; } });
|
|
16
16
|
var sitemap_middleware_1 = require("./sitemap-middleware");
|
|
17
17
|
Object.defineProperty(exports, "SitemapMiddleware", { enumerable: true, get: function () { return sitemap_middleware_1.SitemapMiddleware; } });
|
|
18
|
+
var robots_middleware_1 = require("./robots-middleware");
|
|
19
|
+
Object.defineProperty(exports, "RobotsMiddleware", { enumerable: true, get: function () { return robots_middleware_1.RobotsMiddleware; } });
|
|
20
|
+
var personalize_1 = require("@sitecore-content-sdk/core/personalize");
|
|
21
|
+
Object.defineProperty(exports, "GraphQLPersonalizeService", { enumerable: true, get: function () { return personalize_1.GraphQLPersonalizeService; } });
|
|
22
|
+
var site_1 = require("@sitecore-content-sdk/core/site");
|
|
23
|
+
Object.defineProperty(exports, "GraphQLRedirectsService", { enumerable: true, get: function () { return site_1.GraphQLRedirectsService; } });
|
|
24
|
+
Object.defineProperty(exports, "REDIRECT_TYPE_301", { enumerable: true, get: function () { return site_1.REDIRECT_TYPE_301; } });
|
|
25
|
+
Object.defineProperty(exports, "REDIRECT_TYPE_302", { enumerable: true, get: function () { return site_1.REDIRECT_TYPE_302; } });
|
|
26
|
+
Object.defineProperty(exports, "REDIRECT_TYPE_SERVER_TRANSFER", { enumerable: true, get: function () { return site_1.REDIRECT_TYPE_SERVER_TRANSFER; } });
|
|
@@ -13,6 +13,7 @@ exports.defineMiddleware = exports.MiddlewareBase = exports.Middleware = exports
|
|
|
13
13
|
const site_1 = require("@sitecore-content-sdk/core/site");
|
|
14
14
|
const core_1 = require("@sitecore-content-sdk/core");
|
|
15
15
|
const server_1 = require("next/server");
|
|
16
|
+
const client_1 = require("@sitecore-content-sdk/core/client");
|
|
16
17
|
exports.REWRITE_HEADER_NAME = 'x-sc-rewrite';
|
|
17
18
|
/**
|
|
18
19
|
* Middleware class to be extended by all middleware implementations
|
|
@@ -108,6 +109,9 @@ class MiddlewareBase extends Middleware {
|
|
|
108
109
|
}
|
|
109
110
|
return this.siteResolver.getByHost(hostname);
|
|
110
111
|
}
|
|
112
|
+
getClientFactory(graphQLOptions) {
|
|
113
|
+
return (0, client_1.createGraphQLClientFactory)(graphQLOptions);
|
|
114
|
+
}
|
|
111
115
|
/**
|
|
112
116
|
* Create a rewrite response
|
|
113
117
|
* @param {string} rewritePath the destionation path
|
|
@@ -23,6 +23,7 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
23
23
|
* @param {PersonalizeMiddlewareConfig} [config] Personalize middleware config
|
|
24
24
|
*/
|
|
25
25
|
constructor(config) {
|
|
26
|
+
var _a;
|
|
26
27
|
super(config);
|
|
27
28
|
this.config = config;
|
|
28
29
|
this.handle = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -123,14 +124,39 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
123
124
|
return res;
|
|
124
125
|
}
|
|
125
126
|
});
|
|
127
|
+
const graphQLOptions = {
|
|
128
|
+
api: {
|
|
129
|
+
edge: {
|
|
130
|
+
contextId: this.config.contextId,
|
|
131
|
+
clientContextId: this.config.clientContextId,
|
|
132
|
+
edgeUrl: this.config.edgeUrl,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
};
|
|
126
136
|
// NOTE: we provide native fetch for compatibility on Next.js Edge Runtime
|
|
127
137
|
// (underlying default 'cross-fetch' is not currently compatible: https://github.com/lquixada/cross-fetch/issues/78)
|
|
128
|
-
this.personalizeService =
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
138
|
+
this.personalizeService =
|
|
139
|
+
(_a = this.config.personalizeService) !== null && _a !== void 0 ? _a : new personalize_1.GraphQLPersonalizeService({
|
|
140
|
+
clientFactory: this.getClientFactory(graphQLOptions),
|
|
141
|
+
timeout: this.config.edgeTimeout,
|
|
142
|
+
scope: this.config.scope,
|
|
143
|
+
fetch: fetch,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
getExperienceParams(req) {
|
|
147
|
+
const extraParams = this.config.getExtraUtmParams ? this.config.getExtraUtmParams(req) : {};
|
|
148
|
+
const utm = Object.assign({ campaign: req.nextUrl.searchParams.get('utm_campaign') || undefined, content: req.nextUrl.searchParams.get('utm_content') || undefined, medium: req.nextUrl.searchParams.get('utm_medium') || undefined, source: req.nextUrl.searchParams.get('utm_source') || undefined }, extraParams);
|
|
149
|
+
return {
|
|
150
|
+
// It's expected that the header name "referer" is actually a misspelling of the word "referrer"
|
|
151
|
+
// req.referrer is used during fetching to determine the value of the Referer header of the request being made,
|
|
152
|
+
// used as a fallback
|
|
153
|
+
referrer: req.headers.get('referer') || req.referrer,
|
|
154
|
+
utm,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
disabled(req, res) {
|
|
158
|
+
// ignore files
|
|
159
|
+
return req.nextUrl.pathname.includes('.') || super.disabled(req, res);
|
|
134
160
|
}
|
|
135
161
|
initPersonalizeServer(_a) {
|
|
136
162
|
return __awaiter(this, arguments, void 0, function* ({ hostname, siteName, request, response, }) {
|
|
@@ -159,25 +185,6 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
159
185
|
}, { timeout }));
|
|
160
186
|
});
|
|
161
187
|
}
|
|
162
|
-
getExperienceParams(req) {
|
|
163
|
-
const utm = {
|
|
164
|
-
campaign: req.nextUrl.searchParams.get('utm_campaign') || undefined,
|
|
165
|
-
content: req.nextUrl.searchParams.get('utm_content') || undefined,
|
|
166
|
-
medium: req.nextUrl.searchParams.get('utm_medium') || undefined,
|
|
167
|
-
source: req.nextUrl.searchParams.get('utm_source') || undefined,
|
|
168
|
-
};
|
|
169
|
-
return {
|
|
170
|
-
// It's expected that the header name "referer" is actually a misspelling of the word "referrer"
|
|
171
|
-
// req.referrer is used during fetching to determine the value of the Referer header of the request being made,
|
|
172
|
-
// used as a fallback
|
|
173
|
-
referrer: req.headers.get('referer') || req.referrer,
|
|
174
|
-
utm: utm,
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
disabled(req, res) {
|
|
178
|
-
// ignore files
|
|
179
|
-
return req.nextUrl.pathname.includes('.') || super.disabled(req, res);
|
|
180
|
-
}
|
|
181
188
|
/**
|
|
182
189
|
* Aggregates personalize executions based on the provided route personalize information and language
|
|
183
190
|
* @param {PersonalizeInfo} personalizeInfo the route personalize information
|
|
@@ -30,6 +30,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
30
30
|
* @param {RedirectsMiddlewareConfig} [config] redirects middleware config
|
|
31
31
|
*/
|
|
32
32
|
constructor(config) {
|
|
33
|
+
var _a;
|
|
33
34
|
super(config);
|
|
34
35
|
this.config = config;
|
|
35
36
|
this.handle = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -140,9 +141,19 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
140
141
|
return res;
|
|
141
142
|
}
|
|
142
143
|
});
|
|
144
|
+
const graphQLOptions = {
|
|
145
|
+
api: {
|
|
146
|
+
edge: {
|
|
147
|
+
contextId: this.config.contextId,
|
|
148
|
+
clientContextId: this.config.clientContextId,
|
|
149
|
+
edgeUrl: this.config.edgeUrl,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
};
|
|
143
153
|
// NOTE: we provide native fetch for compatibility on Next.js Edge Runtime
|
|
144
154
|
// (underlying default 'cross-fetch' is not currently compatible: https://github.com/lquixada/cross-fetch/issues/78)
|
|
145
|
-
this.redirectsService =
|
|
155
|
+
this.redirectsService =
|
|
156
|
+
(_a = this.config.redirectsService) !== null && _a !== void 0 ? _a : new site_1.GraphQLRedirectsService(Object.assign(Object.assign({}, config), { clientFactory: this.getClientFactory(graphQLOptions), fetch: fetch }));
|
|
146
157
|
this.locales = config.locales;
|
|
147
158
|
}
|
|
148
159
|
/**
|
|
@@ -0,0 +1,42 @@
|
|
|
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.RobotsMiddleware = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* Middleware for handling robots.txt requests in a Next.js application.
|
|
15
|
+
*/
|
|
16
|
+
class RobotsMiddleware {
|
|
17
|
+
constructor(client) {
|
|
18
|
+
this.client = client;
|
|
19
|
+
}
|
|
20
|
+
getHandler() {
|
|
21
|
+
return this.handler.bind(this);
|
|
22
|
+
}
|
|
23
|
+
handler(req, res) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
var _a;
|
|
26
|
+
res.setHeader('Content-Type', 'text/plain');
|
|
27
|
+
const hostName = ((_a = req.headers.host) === null || _a === void 0 ? void 0 : _a.split(':')[0]) || 'localhost';
|
|
28
|
+
const site = this.client.resolveSite(hostName);
|
|
29
|
+
try {
|
|
30
|
+
const robotsContent = yield this.client.getRobots(site.name);
|
|
31
|
+
if (!robotsContent) {
|
|
32
|
+
return res.status(404).send('User-agent: *\nDisallow: /');
|
|
33
|
+
}
|
|
34
|
+
res.status(200).send(robotsContent);
|
|
35
|
+
}
|
|
36
|
+
catch (_b) {
|
|
37
|
+
res.status(500).send('Internal Server Error');
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.RobotsMiddleware = RobotsMiddleware;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineConfig as defineConfigCore, } from '@sitecore-content-sdk/core/config';
|
|
2
|
+
/**
|
|
3
|
+
* Provides default NextJs initial values from env variables for SitecoreConfig
|
|
4
|
+
* @param {SitecoreConfigInput} config optional override values to be written over default config settings
|
|
5
|
+
* @returns default nextjs input config
|
|
6
|
+
*/
|
|
7
|
+
export const getNextFallbackConfig = (config) => {
|
|
8
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
9
|
+
return Object.assign(Object.assign({}, config), { api: Object.assign(Object.assign({}, config === null || config === void 0 ? void 0 : config.api), { edge: Object.assign(Object.assign({}, (_a = config === null || config === void 0 ? void 0 : config.api) === null || _a === void 0 ? void 0 : _a.edge), { contextId: ((_c = (_b = config === null || config === void 0 ? void 0 : config.api) === null || _b === void 0 ? void 0 : _b.edge) === null || _c === void 0 ? void 0 : _c.contextId) || process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID || '', clientContextId: ((_e = (_d = config === null || config === void 0 ? void 0 : config.api) === null || _d === void 0 ? void 0 : _d.edge) === null || _e === void 0 ? void 0 : _e.clientContextId) || process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID, edgeUrl: ((_g = (_f = config === null || config === void 0 ? void 0 : config.api) === null || _f === void 0 ? void 0 : _f.edge) === null || _g === void 0 ? void 0 : _g.edgeUrl) || process.env.NEXT_PUBLIC_SITECORE_EDGE_URL }), local: Object.assign(Object.assign({}, (_h = config === null || config === void 0 ? void 0 : config.api) === null || _h === void 0 ? void 0 : _h.local), { apiKey: ((_k = (_j = config === null || config === void 0 ? void 0 : config.api) === null || _j === void 0 ? void 0 : _j.local) === null || _k === void 0 ? void 0 : _k.apiKey) || process.env.NEXT_PUBLIC_SITECORE_API_KEY || '', apiHost: ((_m = (_l = config === null || config === void 0 ? void 0 : config.api) === null || _l === void 0 ? void 0 : _l.local) === null || _m === void 0 ? void 0 : _m.apiHost) || process.env.NEXT_PUBLIC_SITECORE_API_HOST || '' }) }), defaultSite: (config === null || config === void 0 ? void 0 : config.defaultSite) || process.env.NEXT_PUBLIC_SITECORE_SITE_NAME || '', defaultLanguage: (config === null || config === void 0 ? void 0 : config.defaultLanguage) || process.env.NEXT_PUBLIC_DEFAULT_LANGUAGE || 'en', multisite: Object.assign(Object.assign({}, config === null || config === void 0 ? void 0 : config.multisite), { useCookieResolution: (_p = (_o = config === null || config === void 0 ? void 0 : config.multisite) === null || _o === void 0 ? void 0 : _o.useCookieResolution) !== null && _p !== void 0 ? _p : (() => process.env.VERCEL_ENV === 'preview') }), personalize: Object.assign(Object.assign({}, config === null || config === void 0 ? void 0 : config.personalize), { scope: ((_q = config === null || config === void 0 ? void 0 : config.personalize) === null || _q === void 0 ? void 0 : _q.scope) || process.env.NEXT_PUBLIC_PERSONALIZE_SCOPE }), disableStaticPaths: process.env.DISABLE_SSG_FETCH !== undefined
|
|
10
|
+
? process.env.DISABLE_SSG_FETCH.toLowerCase() === 'true'
|
|
11
|
+
: (_r = config === null || config === void 0 ? void 0 : config.disableStaticPaths) !== null && _r !== void 0 ? _r : false });
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Accepts a SitecoreConfigInput object and returns full sitecore configuration
|
|
15
|
+
* @param {SitecoreConfigInput} config override values to be written over default config settings
|
|
16
|
+
* @returns {SitecoreConfig} full sitecore configuration to use in application
|
|
17
|
+
*/
|
|
18
|
+
export const defineConfig = (config) => {
|
|
19
|
+
return defineConfigCore(getNextFallbackConfig(config));
|
|
20
|
+
};
|
package/dist/esm/config/index.js
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -5,10 +5,10 @@ export { LayoutServicePageState, GraphQLLayoutService, getChildPlaceholder, getF
|
|
|
5
5
|
export { RestComponentLayoutService } from '@sitecore-content-sdk/core/editing';
|
|
6
6
|
export { mediaApi } from '@sitecore-content-sdk/core/media';
|
|
7
7
|
export { GraphQLDictionaryService, } from '@sitecore-content-sdk/core/i18n';
|
|
8
|
-
export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, getGroomedVariantIds, normalizePersonalizedRewrite, CdpHelper, } from '@sitecore-content-sdk/core/personalize';
|
|
9
|
-
export {
|
|
10
|
-
export { GraphQLSitePathService, } from '@sitecore-content-sdk/core/site';
|
|
8
|
+
export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, getGroomedVariantIds, normalizePersonalizedRewrite, CdpHelper, GraphQLPersonalizeService, } from '@sitecore-content-sdk/core/personalize';
|
|
9
|
+
export { GraphQLSitePathService, GraphQLRedirectsService, REDIRECT_TYPE_301, REDIRECT_TYPE_302, REDIRECT_TYPE_SERVER_TRANSFER, } from '@sitecore-content-sdk/core/site';
|
|
11
10
|
export { GraphQLSitemapXmlService, GraphQLErrorPagesService, GraphQLRobotsService, SiteResolver, GraphQLSiteInfoService, getSiteRewrite, getSiteRewriteData, normalizeSiteRewrite, } from '@sitecore-content-sdk/core/site';
|
|
11
|
+
export { ComponentPropsService } from './services/component-props-service';
|
|
12
12
|
export { ComponentPropsReactContext, ComponentPropsContext, useComponentProps, } from './components/ComponentPropsContext';
|
|
13
13
|
export { Link } from './components/Link';
|
|
14
14
|
export { RichText } from './components/RichText';
|
|
@@ -4,3 +4,6 @@ export { RedirectsMiddleware } from './redirects-middleware';
|
|
|
4
4
|
export { PersonalizeMiddleware } from './personalize-middleware';
|
|
5
5
|
export { MultisiteMiddleware } from './multisite-middleware';
|
|
6
6
|
export { SitemapMiddleware } from './sitemap-middleware';
|
|
7
|
+
export { RobotsMiddleware } from './robots-middleware';
|
|
8
|
+
export { GraphQLPersonalizeService, } from '@sitecore-content-sdk/core/personalize';
|
|
9
|
+
export { GraphQLRedirectsService, REDIRECT_TYPE_301, REDIRECT_TYPE_302, REDIRECT_TYPE_SERVER_TRANSFER, } from '@sitecore-content-sdk/core/site';
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { SITE_KEY, SiteResolver } from '@sitecore-content-sdk/core/site';
|
|
11
11
|
import { debug } from '@sitecore-content-sdk/core';
|
|
12
12
|
import { NextResponse } from 'next/server';
|
|
13
|
+
import { createGraphQLClientFactory, } from '@sitecore-content-sdk/core/client';
|
|
13
14
|
export const REWRITE_HEADER_NAME = 'x-sc-rewrite';
|
|
14
15
|
/**
|
|
15
16
|
* Middleware class to be extended by all middleware implementations
|
|
@@ -104,6 +105,9 @@ export class MiddlewareBase extends Middleware {
|
|
|
104
105
|
}
|
|
105
106
|
return this.siteResolver.getByHost(hostname);
|
|
106
107
|
}
|
|
108
|
+
getClientFactory(graphQLOptions) {
|
|
109
|
+
return createGraphQLClientFactory(graphQLOptions);
|
|
110
|
+
}
|
|
107
111
|
/**
|
|
108
112
|
* Create a rewrite response
|
|
109
113
|
* @param {string} rewritePath the destionation path
|
|
@@ -20,6 +20,7 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
20
20
|
* @param {PersonalizeMiddlewareConfig} [config] Personalize middleware config
|
|
21
21
|
*/
|
|
22
22
|
constructor(config) {
|
|
23
|
+
var _a;
|
|
23
24
|
super(config);
|
|
24
25
|
this.config = config;
|
|
25
26
|
this.handle = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -120,14 +121,39 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
120
121
|
return res;
|
|
121
122
|
}
|
|
122
123
|
});
|
|
124
|
+
const graphQLOptions = {
|
|
125
|
+
api: {
|
|
126
|
+
edge: {
|
|
127
|
+
contextId: this.config.contextId,
|
|
128
|
+
clientContextId: this.config.clientContextId,
|
|
129
|
+
edgeUrl: this.config.edgeUrl,
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
};
|
|
123
133
|
// NOTE: we provide native fetch for compatibility on Next.js Edge Runtime
|
|
124
134
|
// (underlying default 'cross-fetch' is not currently compatible: https://github.com/lquixada/cross-fetch/issues/78)
|
|
125
|
-
this.personalizeService =
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
135
|
+
this.personalizeService =
|
|
136
|
+
(_a = this.config.personalizeService) !== null && _a !== void 0 ? _a : new GraphQLPersonalizeService({
|
|
137
|
+
clientFactory: this.getClientFactory(graphQLOptions),
|
|
138
|
+
timeout: this.config.edgeTimeout,
|
|
139
|
+
scope: this.config.scope,
|
|
140
|
+
fetch: fetch,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
getExperienceParams(req) {
|
|
144
|
+
const extraParams = this.config.getExtraUtmParams ? this.config.getExtraUtmParams(req) : {};
|
|
145
|
+
const utm = Object.assign({ campaign: req.nextUrl.searchParams.get('utm_campaign') || undefined, content: req.nextUrl.searchParams.get('utm_content') || undefined, medium: req.nextUrl.searchParams.get('utm_medium') || undefined, source: req.nextUrl.searchParams.get('utm_source') || undefined }, extraParams);
|
|
146
|
+
return {
|
|
147
|
+
// It's expected that the header name "referer" is actually a misspelling of the word "referrer"
|
|
148
|
+
// req.referrer is used during fetching to determine the value of the Referer header of the request being made,
|
|
149
|
+
// used as a fallback
|
|
150
|
+
referrer: req.headers.get('referer') || req.referrer,
|
|
151
|
+
utm,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
disabled(req, res) {
|
|
155
|
+
// ignore files
|
|
156
|
+
return req.nextUrl.pathname.includes('.') || super.disabled(req, res);
|
|
131
157
|
}
|
|
132
158
|
initPersonalizeServer(_a) {
|
|
133
159
|
return __awaiter(this, arguments, void 0, function* ({ hostname, siteName, request, response, }) {
|
|
@@ -156,25 +182,6 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
156
182
|
}, { timeout }));
|
|
157
183
|
});
|
|
158
184
|
}
|
|
159
|
-
getExperienceParams(req) {
|
|
160
|
-
const utm = {
|
|
161
|
-
campaign: req.nextUrl.searchParams.get('utm_campaign') || undefined,
|
|
162
|
-
content: req.nextUrl.searchParams.get('utm_content') || undefined,
|
|
163
|
-
medium: req.nextUrl.searchParams.get('utm_medium') || undefined,
|
|
164
|
-
source: req.nextUrl.searchParams.get('utm_source') || undefined,
|
|
165
|
-
};
|
|
166
|
-
return {
|
|
167
|
-
// It's expected that the header name "referer" is actually a misspelling of the word "referrer"
|
|
168
|
-
// req.referrer is used during fetching to determine the value of the Referer header of the request being made,
|
|
169
|
-
// used as a fallback
|
|
170
|
-
referrer: req.headers.get('referer') || req.referrer,
|
|
171
|
-
utm: utm,
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
disabled(req, res) {
|
|
175
|
-
// ignore files
|
|
176
|
-
return req.nextUrl.pathname.includes('.') || super.disabled(req, res);
|
|
177
|
-
}
|
|
178
185
|
/**
|
|
179
186
|
* Aggregates personalize executions based on the provided route personalize information and language
|
|
180
187
|
* @param {PersonalizeInfo} personalizeInfo the route personalize information
|
|
@@ -24,6 +24,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
24
24
|
* @param {RedirectsMiddlewareConfig} [config] redirects middleware config
|
|
25
25
|
*/
|
|
26
26
|
constructor(config) {
|
|
27
|
+
var _a;
|
|
27
28
|
super(config);
|
|
28
29
|
this.config = config;
|
|
29
30
|
this.handle = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -134,9 +135,19 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
134
135
|
return res;
|
|
135
136
|
}
|
|
136
137
|
});
|
|
138
|
+
const graphQLOptions = {
|
|
139
|
+
api: {
|
|
140
|
+
edge: {
|
|
141
|
+
contextId: this.config.contextId,
|
|
142
|
+
clientContextId: this.config.clientContextId,
|
|
143
|
+
edgeUrl: this.config.edgeUrl,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
};
|
|
137
147
|
// NOTE: we provide native fetch for compatibility on Next.js Edge Runtime
|
|
138
148
|
// (underlying default 'cross-fetch' is not currently compatible: https://github.com/lquixada/cross-fetch/issues/78)
|
|
139
|
-
this.redirectsService =
|
|
149
|
+
this.redirectsService =
|
|
150
|
+
(_a = this.config.redirectsService) !== null && _a !== void 0 ? _a : new GraphQLRedirectsService(Object.assign(Object.assign({}, config), { clientFactory: this.getClientFactory(graphQLOptions), fetch: fetch }));
|
|
140
151
|
this.locales = config.locales;
|
|
141
152
|
}
|
|
142
153
|
/**
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Middleware for handling robots.txt requests in a Next.js application.
|
|
12
|
+
*/
|
|
13
|
+
export class RobotsMiddleware {
|
|
14
|
+
constructor(client) {
|
|
15
|
+
this.client = client;
|
|
16
|
+
}
|
|
17
|
+
getHandler() {
|
|
18
|
+
return this.handler.bind(this);
|
|
19
|
+
}
|
|
20
|
+
handler(req, res) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
var _a;
|
|
23
|
+
res.setHeader('Content-Type', 'text/plain');
|
|
24
|
+
const hostName = ((_a = req.headers.host) === null || _a === void 0 ? void 0 : _a.split(':')[0]) || 'localhost';
|
|
25
|
+
const site = this.client.resolveSite(hostName);
|
|
26
|
+
try {
|
|
27
|
+
const robotsContent = yield this.client.getRobots(site.name);
|
|
28
|
+
if (!robotsContent) {
|
|
29
|
+
return res.status(404).send('User-agent: *\nDisallow: /');
|
|
30
|
+
}
|
|
31
|
+
res.status(200).send(robotsContent);
|
|
32
|
+
}
|
|
33
|
+
catch (_b) {
|
|
34
|
+
res.status(500).send('Internal Server Error');
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-content-sdk/nextjs",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.7",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -30,48 +30,47 @@
|
|
|
30
30
|
"url": "https://github.com/sitecore/content-sdk/issues"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@sitecore-cloudsdk/core": "^0.5.
|
|
34
|
-
"@sitecore-cloudsdk/personalize": "^0.5.
|
|
33
|
+
"@sitecore-cloudsdk/core": "^0.5.1",
|
|
34
|
+
"@sitecore-cloudsdk/personalize": "^0.5.1",
|
|
35
35
|
"@testing-library/dom": "^10.4.0",
|
|
36
36
|
"@testing-library/react": "^16.3.0",
|
|
37
|
-
"@types/chai": "^
|
|
38
|
-
"@types/chai-
|
|
39
|
-
"@types/
|
|
40
|
-
"@types/
|
|
41
|
-
"@types/
|
|
42
|
-
"@types/react": "^19.1.
|
|
37
|
+
"@types/chai": "^5.2.2",
|
|
38
|
+
"@types/chai-string": "^1.4.5",
|
|
39
|
+
"@types/mocha": "^10.0.10",
|
|
40
|
+
"@types/node": "~22.15.14",
|
|
41
|
+
"@types/proxyquire": "^1.3.31",
|
|
42
|
+
"@types/react": "^19.1.3",
|
|
43
43
|
"@types/react-dom": "^19.1.3",
|
|
44
|
-
"@types/sinon": "^
|
|
44
|
+
"@types/sinon": "^17.0.4",
|
|
45
45
|
"@types/sinon-chai": "^3.2.9",
|
|
46
|
-
"chai": "^4.
|
|
47
|
-
"chai-
|
|
48
|
-
"chai-string": "^1.5.0",
|
|
46
|
+
"chai": "^4.4.1",
|
|
47
|
+
"chai-string": "^1.6.0",
|
|
49
48
|
"chalk": "^4.1.2",
|
|
50
49
|
"cross-fetch": "^4.1.0",
|
|
51
50
|
"del-cli": "^6.0.0",
|
|
52
51
|
"eslint": "^8.56.0",
|
|
53
52
|
"eslint-plugin-react": "^7.37.5",
|
|
54
|
-
"jsdom": "^26.
|
|
55
|
-
"mocha": "^11.
|
|
56
|
-
"next": "^15.3.
|
|
53
|
+
"jsdom": "^26.1.0",
|
|
54
|
+
"mocha": "^11.2.2",
|
|
55
|
+
"next": "^15.3.2",
|
|
57
56
|
"nock": "14.0.0-beta.7",
|
|
58
57
|
"nyc": "^17.1.0",
|
|
59
58
|
"proxyquire": "^2.1.3",
|
|
60
|
-
"react": "^19.
|
|
61
|
-
"react-dom": "^19.
|
|
62
|
-
"sinon": "^
|
|
59
|
+
"react": "^19.1.0",
|
|
60
|
+
"react-dom": "^19.1.0",
|
|
61
|
+
"sinon": "^20.0.0",
|
|
63
62
|
"sinon-chai": "^3.7.0",
|
|
64
|
-
"ts-node": "^10.9.
|
|
65
|
-
"typescript": "~5.
|
|
63
|
+
"ts-node": "^10.9.2",
|
|
64
|
+
"typescript": "~5.8.3"
|
|
66
65
|
},
|
|
67
66
|
"peerDependencies": {
|
|
68
|
-
"@sitecore-cloudsdk/core": "^0.5.
|
|
69
|
-
"@sitecore-cloudsdk/events": "^0.5.
|
|
70
|
-
"@sitecore-cloudsdk/personalize": "^0.5.
|
|
71
|
-
"next": "^15.3.
|
|
67
|
+
"@sitecore-cloudsdk/core": "^0.5.1",
|
|
68
|
+
"@sitecore-cloudsdk/events": "^0.5.1",
|
|
69
|
+
"@sitecore-cloudsdk/personalize": "^0.5.1",
|
|
70
|
+
"next": "^15.3.2",
|
|
72
71
|
"react": "^19.1.0",
|
|
73
72
|
"react-dom": "^19.1.0",
|
|
74
|
-
"typescript": "^5.
|
|
73
|
+
"typescript": "^5.8.3"
|
|
75
74
|
},
|
|
76
75
|
"peerDependenciesMeta": {
|
|
77
76
|
"typescript": {
|
|
@@ -79,17 +78,16 @@
|
|
|
79
78
|
}
|
|
80
79
|
},
|
|
81
80
|
"dependencies": {
|
|
82
|
-
"@babel/parser": "^7.
|
|
83
|
-
"@sitecore-content-sdk/core": "0.2.0-beta.
|
|
84
|
-
"@sitecore-content-sdk/react": "0.2.0-beta.
|
|
85
|
-
"@vercel/kv": "^3.0.0",
|
|
81
|
+
"@babel/parser": "^7.27.2",
|
|
82
|
+
"@sitecore-content-sdk/core": "0.2.0-beta.7",
|
|
83
|
+
"@sitecore-content-sdk/react": "0.2.0-beta.7",
|
|
86
84
|
"recast": "^0.23.11",
|
|
87
|
-
"regex-parser": "^2.3.
|
|
85
|
+
"regex-parser": "^2.3.1",
|
|
88
86
|
"sync-disk-cache": "^2.1.0"
|
|
89
87
|
},
|
|
90
88
|
"description": "",
|
|
91
89
|
"types": "types/index.d.ts",
|
|
92
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "72e0db1a8d4142e567d6849f3d98e39b7826e6d9",
|
|
93
91
|
"files": [
|
|
94
92
|
"dist",
|
|
95
93
|
"types",
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { DeepRequired, SitecoreConfigInput as SitecoreConfigInputCore } from '@sitecore-content-sdk/core/config';
|
|
2
|
+
/**
|
|
3
|
+
* Provides default NextJs initial values from env variables for SitecoreConfig
|
|
4
|
+
* @param {SitecoreConfigInput} config optional override values to be written over default config settings
|
|
5
|
+
* @returns default nextjs input config
|
|
6
|
+
*/
|
|
7
|
+
export declare const getNextFallbackConfig: (config?: SitecoreConfigInput) => SitecoreConfigInput;
|
|
8
|
+
/**
|
|
9
|
+
* Type to be used as config input in sitecore.config
|
|
10
|
+
*/
|
|
11
|
+
export type SitecoreConfigInput = SitecoreConfigInputCore & {
|
|
12
|
+
/**
|
|
13
|
+
* Indicates whether SSG `getStaticPaths` pre-render any pages.
|
|
14
|
+
*
|
|
15
|
+
* Set the environment variable `DISABLE_SSG_FETCH=true`
|
|
16
|
+
* to disable static paths generation and enable full ISR (Incremental Static Regeneration) flow.
|
|
17
|
+
*
|
|
18
|
+
* By default, this is set to `false`.
|
|
19
|
+
*
|
|
20
|
+
* This is set to `true` when the application is deployed and used as editing host in Sitecore.
|
|
21
|
+
*/
|
|
22
|
+
disableStaticPaths?: boolean;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Final sitecore config type used at runtime Every property should be populated, either from sitecore.config or built-in fallback values
|
|
26
|
+
*/
|
|
27
|
+
export type SitecoreConfig = DeepRequired<SitecoreConfigInput>;
|
|
28
|
+
/**
|
|
29
|
+
* Accepts a SitecoreConfigInput object and returns full sitecore configuration
|
|
30
|
+
* @param {SitecoreConfigInput} config override values to be written over default config settings
|
|
31
|
+
* @returns {SitecoreConfig} full sitecore configuration to use in application
|
|
32
|
+
*/
|
|
33
|
+
export declare const defineConfig: (config?: SitecoreConfigInput) => SitecoreConfig;
|
package/types/config/index.d.ts
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -3,13 +3,13 @@ export { LayoutServiceData, LayoutServicePageState, LayoutServiceContext, Layout
|
|
|
3
3
|
export { RestComponentLayoutService } from '@sitecore-content-sdk/core/editing';
|
|
4
4
|
export { mediaApi } from '@sitecore-content-sdk/core/media';
|
|
5
5
|
export { DictionaryPhrases, DictionaryService, GraphQLDictionaryService, GraphQLDictionaryServiceConfig, } from '@sitecore-content-sdk/core/i18n';
|
|
6
|
-
export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, getGroomedVariantIds, normalizePersonalizedRewrite, CdpHelper, } from '@sitecore-content-sdk/core/personalize';
|
|
6
|
+
export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, getGroomedVariantIds, normalizePersonalizedRewrite, CdpHelper, GraphQLPersonalizeService, } from '@sitecore-content-sdk/core/personalize';
|
|
7
|
+
export { GraphQLSitePathService, GraphQLSitePathServiceConfig, GraphQLRedirectsService, GraphQLRedirectsServiceConfig, REDIRECT_TYPE_301, REDIRECT_TYPE_302, REDIRECT_TYPE_SERVER_TRANSFER, RedirectInfo, } from '@sitecore-content-sdk/core/site';
|
|
8
|
+
export { StaticPath } from '@sitecore-content-sdk/core';
|
|
9
|
+
export { GraphQLSitemapXmlService, GraphQLSitemapXmlServiceConfig, GraphQLErrorPagesService, GraphQLErrorPagesServiceConfig, RobotsQueryResult, GraphQLRobotsService, GraphQLRobotsServiceConfig, ErrorPages, SiteInfo, SiteResolver, GraphQLSiteInfoService, GraphQLSiteInfoServiceConfig, getSiteRewrite, getSiteRewriteData, normalizeSiteRewrite, } from '@sitecore-content-sdk/core/site';
|
|
7
10
|
export { ComponentPropsCollection, ComponentPropsError, GetStaticComponentProps, GetServerSideComponentProps, NextjsJssComponent, } from './sharedTypes/component-props';
|
|
8
11
|
export { SitecorePageProps } from './sharedTypes/sitecore-page-props';
|
|
9
12
|
export { ComponentPropsService } from './services/component-props-service';
|
|
10
|
-
export { GraphQLSitePathService, GraphQLSitePathServiceConfig, } from '@sitecore-content-sdk/core/site';
|
|
11
|
-
export { StaticPath } from '@sitecore-content-sdk/core';
|
|
12
|
-
export { GraphQLSitemapXmlService, GraphQLSitemapXmlServiceConfig, GraphQLErrorPagesService, GraphQLErrorPagesServiceConfig, RobotsQueryResult, GraphQLRobotsService, GraphQLRobotsServiceConfig, ErrorPages, SiteInfo, SiteResolver, GraphQLSiteInfoService, GraphQLSiteInfoServiceConfig, getSiteRewrite, getSiteRewriteData, normalizeSiteRewrite, } from '@sitecore-content-sdk/core/site';
|
|
13
13
|
export { ComponentPropsReactContext, ComponentPropsContextProps, ComponentPropsContext, useComponentProps, } from './components/ComponentPropsContext';
|
|
14
14
|
export { Link, LinkProps } from './components/Link';
|
|
15
15
|
export { RichText, RichTextProps } from './components/RichText';
|
|
@@ -4,3 +4,6 @@ export { RedirectsMiddleware, RedirectsMiddlewareConfig } from './redirects-midd
|
|
|
4
4
|
export { PersonalizeMiddleware, PersonalizeMiddlewareConfig } from './personalize-middleware';
|
|
5
5
|
export { MultisiteMiddleware, MultisiteMiddlewareConfig } from './multisite-middleware';
|
|
6
6
|
export { SitemapMiddleware } from './sitemap-middleware';
|
|
7
|
+
export { RobotsMiddleware } from './robots-middleware';
|
|
8
|
+
export { GraphQLPersonalizeService, GraphQLPersonalizeServiceConfig, } from '@sitecore-content-sdk/core/personalize';
|
|
9
|
+
export { GraphQLRedirectsService, GraphQLRedirectsServiceConfig, REDIRECT_TYPE_301, REDIRECT_TYPE_302, REDIRECT_TYPE_SERVER_TRANSFER, RedirectInfo, } from '@sitecore-content-sdk/core/site';
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { SiteInfo, SiteResolver } from '@sitecore-content-sdk/core/site';
|
|
2
|
+
import { GraphQLRequestClientFactory } from '@sitecore-content-sdk/core';
|
|
2
3
|
import { NextRequest, NextFetchEvent, NextResponse } from 'next/server';
|
|
4
|
+
import { GraphQLClientOptions } from '@sitecore-content-sdk/core/client';
|
|
3
5
|
export declare const REWRITE_HEADER_NAME = "x-sc-rewrite";
|
|
4
6
|
export type MiddlewareBaseConfig = {
|
|
5
7
|
/**
|
|
@@ -85,6 +87,7 @@ export declare abstract class MiddlewareBase extends Middleware {
|
|
|
85
87
|
* @returns {SiteInfo} site information
|
|
86
88
|
*/
|
|
87
89
|
protected getSite(req: NextRequest, res?: NextResponse): SiteInfo;
|
|
90
|
+
protected getClientFactory(graphQLOptions: GraphQLClientOptions): GraphQLRequestClientFactory;
|
|
88
91
|
/**
|
|
89
92
|
* Create a rewrite response
|
|
90
93
|
* @param {string} rewritePath the destionation path
|
|
@@ -1,33 +1,10 @@
|
|
|
1
1
|
import { NextResponse, NextRequest } from 'next/server';
|
|
2
|
-
import { PersonalizeInfo } from '@sitecore-content-sdk/core/personalize';
|
|
3
|
-
import { GraphQLRequestClientFactory } from '@sitecore-content-sdk/core';
|
|
2
|
+
import { GraphQLPersonalizeService, PersonalizeInfo } from '@sitecore-content-sdk/core/personalize';
|
|
4
3
|
import { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
|
|
5
4
|
import { SitecoreConfig } from '../config';
|
|
6
|
-
export type CdpServiceConfig = {
|
|
7
|
-
/**
|
|
8
|
-
* Your Sitecore Edge Platform endpoint
|
|
9
|
-
* Default is https://edge-platform.sitecorecloud.io
|
|
10
|
-
*/
|
|
11
|
-
sitecoreEdgeUrl?: string;
|
|
12
|
-
/**
|
|
13
|
-
* Your unified Sitecore Edge Context Id
|
|
14
|
-
*/
|
|
15
|
-
sitecoreEdgeContextId: string;
|
|
16
|
-
/**
|
|
17
|
-
* The Sitecore CDP channel to use for events. Uses 'WEB' by default.
|
|
18
|
-
*/
|
|
19
|
-
channel?: string;
|
|
20
|
-
/**
|
|
21
|
-
* Currency for CDP request. Uses 'USA' as default.
|
|
22
|
-
*/
|
|
23
|
-
currency?: string;
|
|
24
|
-
/**
|
|
25
|
-
* Timeout (ms) for CDP request. Default is 400.
|
|
26
|
-
*/
|
|
27
|
-
timeout?: number;
|
|
28
|
-
};
|
|
29
5
|
export type PersonalizeMiddlewareConfig = MiddlewareBaseConfig & SitecoreConfig['api']['edge'] & SitecoreConfig['personalize'] & {
|
|
30
|
-
|
|
6
|
+
personalizeService?: GraphQLPersonalizeService;
|
|
7
|
+
getExtraUtmParams?: (req: NextRequest) => Partial<ExperienceParams['utm']>;
|
|
31
8
|
};
|
|
32
9
|
/**
|
|
33
10
|
* Object model of Experience Context data
|
|
@@ -54,12 +31,14 @@ type PersonalizeExecution = {
|
|
|
54
31
|
*/
|
|
55
32
|
export declare class PersonalizeMiddleware extends MiddlewareBase {
|
|
56
33
|
protected config: PersonalizeMiddlewareConfig;
|
|
57
|
-
|
|
34
|
+
protected personalizeService: GraphQLPersonalizeService;
|
|
58
35
|
/**
|
|
59
36
|
* @param {PersonalizeMiddlewareConfig} [config] Personalize middleware config
|
|
60
37
|
*/
|
|
61
38
|
constructor(config: PersonalizeMiddlewareConfig);
|
|
62
39
|
handle: (req: NextRequest, res: NextResponse) => Promise<NextResponse>;
|
|
40
|
+
protected getExperienceParams(req: NextRequest): ExperienceParams;
|
|
41
|
+
protected disabled(req: NextRequest, res: NextResponse): boolean | undefined;
|
|
63
42
|
protected initPersonalizeServer({ hostname, siteName, request, response, }: {
|
|
64
43
|
hostname: string;
|
|
65
44
|
siteName: string;
|
|
@@ -75,8 +54,6 @@ export declare class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
75
54
|
}, request: NextRequest): Promise<{
|
|
76
55
|
variantId: string;
|
|
77
56
|
}>;
|
|
78
|
-
protected getExperienceParams(req: NextRequest): ExperienceParams;
|
|
79
|
-
protected disabled(req: NextRequest, res: NextResponse): boolean | undefined;
|
|
80
57
|
/**
|
|
81
58
|
* Aggregates personalize executions based on the provided route personalize information and language
|
|
82
59
|
* @param {PersonalizeInfo} personalizeInfo the route personalize information
|
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
import { GraphQLRedirectsServiceConfig } from '@sitecore-content-sdk/core/site';
|
|
1
|
+
import { GraphQLRedirectsService, GraphQLRedirectsServiceConfig, RedirectInfo } from '@sitecore-content-sdk/core/site';
|
|
2
|
+
import { NextURL } from 'next/dist/server/web/next-url';
|
|
2
3
|
import { NextRequest, NextResponse } from 'next/server';
|
|
3
4
|
import { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
|
|
4
5
|
import { SitecoreConfig } from '../config';
|
|
6
|
+
type RedirectResult = RedirectInfo & {
|
|
7
|
+
matchedQueryString?: string;
|
|
8
|
+
};
|
|
5
9
|
/**
|
|
6
10
|
* extended RedirectsMiddlewareConfig config type for RedirectsMiddleware
|
|
7
11
|
*/
|
|
8
|
-
export type RedirectsMiddlewareConfig = Omit<GraphQLRedirectsServiceConfig, 'fetch'> & MiddlewareBaseConfig & SitecoreConfig['redirects']
|
|
12
|
+
export type RedirectsMiddlewareConfig = Omit<GraphQLRedirectsServiceConfig, 'fetch' | 'clientFactory'> & SitecoreConfig['api']['edge'] & MiddlewareBaseConfig & SitecoreConfig['redirects'] & {
|
|
13
|
+
redirectsService?: GraphQLRedirectsService;
|
|
14
|
+
};
|
|
9
15
|
/**
|
|
10
16
|
* Middleware / handler fetches all redirects from Sitecore instance by grapqhl service
|
|
11
17
|
* compares with current url and redirects to target url
|
|
12
18
|
*/
|
|
13
19
|
export declare class RedirectsMiddleware extends MiddlewareBase {
|
|
14
20
|
protected config: RedirectsMiddlewareConfig;
|
|
15
|
-
|
|
21
|
+
protected redirectsService: GraphQLRedirectsService;
|
|
16
22
|
private locales;
|
|
17
23
|
/**
|
|
18
24
|
* @param {RedirectsMiddlewareConfig} [config] redirects middleware config
|
|
@@ -26,7 +32,7 @@ export declare class RedirectsMiddleware extends MiddlewareBase {
|
|
|
26
32
|
* @returns Promise<RedirectInfo | undefined>
|
|
27
33
|
* @private
|
|
28
34
|
*/
|
|
29
|
-
|
|
35
|
+
protected getExistsRedirect(req: NextRequest, siteName: string): Promise<RedirectResult | undefined>;
|
|
30
36
|
/**
|
|
31
37
|
* When a user clicks on a link generated by the Link component from next/link,
|
|
32
38
|
* Next.js adds special parameters in the route called path.
|
|
@@ -34,7 +40,7 @@ export declare class RedirectsMiddleware extends MiddlewareBase {
|
|
|
34
40
|
* @param {NextURL} url
|
|
35
41
|
* @returns {string} normalize url
|
|
36
42
|
*/
|
|
37
|
-
|
|
43
|
+
protected normalizeUrl(url: NextURL): NextURL;
|
|
38
44
|
/**
|
|
39
45
|
* Helper function to create a redirect response and remove the x-middleware-next header.
|
|
40
46
|
* @param {NextURL} url The URL to redirect to.
|
|
@@ -43,5 +49,6 @@ export declare class RedirectsMiddleware extends MiddlewareBase {
|
|
|
43
49
|
* @param {string} statusText The status text of the redirect.
|
|
44
50
|
* @returns {NextResponse<unknown>} The redirect response.
|
|
45
51
|
*/
|
|
46
|
-
|
|
52
|
+
protected createRedirectResponse(url: NextURL, res: Response | undefined, status: number, statusText: string): NextResponse;
|
|
47
53
|
}
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
+
import { SitecoreClient } from '@sitecore-content-sdk/core/client';
|
|
3
|
+
/**
|
|
4
|
+
* Middleware for handling robots.txt requests in a Next.js application.
|
|
5
|
+
*/
|
|
6
|
+
export declare class RobotsMiddleware {
|
|
7
|
+
private client;
|
|
8
|
+
constructor(client: SitecoreClient);
|
|
9
|
+
getHandler(): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
10
|
+
private handler;
|
|
11
|
+
}
|