@uniformdev/context-next 20.88.0 → 20.89.1-alpha.78.sha-248d2fa520
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +19 -55
- package/package.json +12 -16
- package/dist/index.d.mts +0 -29
- package/dist/index.esm.js +0 -61
- package/dist/index.mjs +0 -61
package/dist/index.js
CHANGED
|
@@ -1,52 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
NextCookieTransitionDataStore: () => NextCookieTransitionDataStore,
|
|
34
|
-
enableNextSsr: () => enableNextSsr
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(index_exports);
|
|
37
|
-
|
|
38
1
|
// src/enableNextSsr.tsx
|
|
39
|
-
|
|
40
|
-
|
|
2
|
+
import { parse } from "cookie";
|
|
3
|
+
import * as React from "react";
|
|
41
4
|
function enableNextSsr(ctx, context) {
|
|
42
|
-
var _a;
|
|
43
5
|
const originalRenderPage = ctx.renderPage;
|
|
44
6
|
const { req } = ctx;
|
|
45
7
|
if (req) {
|
|
46
8
|
context.update({
|
|
47
9
|
// note: https and unknown here are ok, because nothing is matching on host or protocol in the tracker
|
|
48
|
-
url: new URL(`https://${
|
|
49
|
-
cookies: req.headers.cookie ?
|
|
10
|
+
url: new URL(`https://${req.headers.host ?? "unknown"}${req.url}`),
|
|
11
|
+
cookies: req.headers.cookie ? parse(req.headers.cookie) : void 0
|
|
50
12
|
});
|
|
51
13
|
}
|
|
52
14
|
ctx.renderPage = (opts) => originalRenderPage({
|
|
@@ -61,35 +23,37 @@ function enableNextSsr(ctx, context) {
|
|
|
61
23
|
}
|
|
62
24
|
|
|
63
25
|
// src/NextCookieTransitionDataStore.ts
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
26
|
+
import {
|
|
27
|
+
CookieTransitionDataStore,
|
|
28
|
+
UNIFORM_DEFAULT_COOKIE_NAME,
|
|
29
|
+
UNIFORM_DEFAULT_QUIRK_COOKIE_NAME
|
|
30
|
+
} from "@uniformdev/context";
|
|
31
|
+
import { parse as parse2 } from "cookie";
|
|
32
|
+
var NextCookieTransitionDataStore = class extends CookieTransitionDataStore {
|
|
67
33
|
constructor({ serverContext, ...options }) {
|
|
68
34
|
super({
|
|
69
35
|
...options,
|
|
70
36
|
serverCookieValue: getNextServerCookieValue(serverContext),
|
|
71
|
-
quirkCookieValue: options.
|
|
37
|
+
quirkCookieValue: options.quirksEnabled ? getNextServerCookieValue(
|
|
72
38
|
serverContext,
|
|
73
|
-
options.quirkCookieName ||
|
|
39
|
+
options.quirkCookieName || UNIFORM_DEFAULT_QUIRK_COOKIE_NAME
|
|
74
40
|
) : void 0
|
|
75
41
|
});
|
|
76
42
|
}
|
|
77
43
|
};
|
|
78
|
-
function getNextServerCookieValue(serverContext, cookieName =
|
|
79
|
-
var _a, _b, _c;
|
|
44
|
+
function getNextServerCookieValue(serverContext, cookieName = UNIFORM_DEFAULT_COOKIE_NAME) {
|
|
80
45
|
if (!serverContext) return void 0;
|
|
81
|
-
let cookies = (
|
|
82
|
-
if (
|
|
46
|
+
let cookies = parse2(serverContext.req?.headers.cookie ?? "");
|
|
47
|
+
if (serverContext?.res?.getHeaders) {
|
|
83
48
|
const resHeaders = serverContext.res.getHeaders();
|
|
84
49
|
const resCookies = resHeaders["set-cookie"];
|
|
85
50
|
if (resCookies) {
|
|
86
|
-
cookies = { ...cookies, ...(
|
|
51
|
+
cookies = { ...cookies, ...parse2(Array.isArray(resCookies) ? resCookies[0] : resCookies.toString()) };
|
|
87
52
|
}
|
|
88
53
|
}
|
|
89
54
|
return cookies[cookieName];
|
|
90
55
|
}
|
|
91
|
-
|
|
92
|
-
0 && (module.exports = {
|
|
56
|
+
export {
|
|
93
57
|
NextCookieTransitionDataStore,
|
|
94
58
|
enableNextSsr
|
|
95
|
-
}
|
|
59
|
+
};
|
package/package.json
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/context-next",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.89.1-alpha.78.sha-248d2fa520",
|
|
4
4
|
"description": "Uniform Context Next.js integration package",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
6
|
+
"type": "module",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
|
-
"
|
|
10
|
-
"types": "./dist/index.d.
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
},
|
|
14
|
-
"require": "./dist/index.js"
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
15
13
|
},
|
|
16
|
-
"types": "./dist/index.d.ts",
|
|
17
14
|
"sideEffects": false,
|
|
18
15
|
"scripts": {
|
|
19
16
|
"build": "tsup",
|
|
@@ -24,18 +21,17 @@
|
|
|
24
21
|
},
|
|
25
22
|
"devDependencies": {
|
|
26
23
|
"@types/react": "19.2.17",
|
|
27
|
-
"next": "16.
|
|
24
|
+
"next": "16.4.5",
|
|
28
25
|
"react": "19.2.1",
|
|
29
26
|
"react-dom": "19.2.1"
|
|
30
27
|
},
|
|
31
28
|
"dependencies": {
|
|
32
|
-
"@uniformdev/context": "20.
|
|
29
|
+
"@uniformdev/context": "20.89.1-alpha.78.sha-248d2fa520",
|
|
33
30
|
"cookie": "^1.1.1"
|
|
34
31
|
},
|
|
35
32
|
"peerDependencies": {
|
|
36
|
-
"next": ">=
|
|
37
|
-
"react": "
|
|
38
|
-
"react-dom": ">=16.13.1"
|
|
33
|
+
"next": ">=15",
|
|
34
|
+
"react": "^18.2 || ^19"
|
|
39
35
|
},
|
|
40
36
|
"files": [
|
|
41
37
|
"/dist"
|
|
@@ -43,5 +39,5 @@
|
|
|
43
39
|
"publishConfig": {
|
|
44
40
|
"access": "public"
|
|
45
41
|
},
|
|
46
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "248d2fa520900b3e84fd1f7beaf2b3dd8d9100e4"
|
|
47
43
|
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Context, CookieTransitionDataStore, CookieTransitionDataStoreOptions } from '@uniformdev/context';
|
|
2
|
-
import { AppProps } from 'next/app';
|
|
3
|
-
import { DocumentContext } from 'next/document';
|
|
4
|
-
import { NextPageContext } from 'next';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Enables request-data tracking during server-side rendering passes,
|
|
8
|
-
* and sending that data back up to the client.
|
|
9
|
-
*
|
|
10
|
-
* This function must be called in a custom Next _document's `getInitialProps`
|
|
11
|
-
* function to work properly.
|
|
12
|
-
*/
|
|
13
|
-
declare function enableNextSsr(ctx: DocumentContext, context: Context): void;
|
|
14
|
-
/** Type of <App> props if enableNextSsr() is setup in _document. */
|
|
15
|
-
type UniformAppProps<P = {}> = AppProps<P> & {
|
|
16
|
-
serverUniformContext?: Context;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
type NextCookieTransitionDataStoreOptions = Omit<CookieTransitionDataStoreOptions, 'serverCookieValue'> & {
|
|
20
|
-
serverContext: NextPageContext | undefined;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Provides client-to-server score transition using cookies for Next.js SSR
|
|
24
|
-
*/
|
|
25
|
-
declare class NextCookieTransitionDataStore extends CookieTransitionDataStore {
|
|
26
|
-
constructor({ serverContext, ...options }: NextCookieTransitionDataStoreOptions);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { NextCookieTransitionDataStore, type NextCookieTransitionDataStoreOptions, type UniformAppProps, enableNextSsr };
|
package/dist/index.esm.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
// src/enableNextSsr.tsx
|
|
2
|
-
import { parse } from "cookie";
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
function enableNextSsr(ctx, context) {
|
|
5
|
-
var _a;
|
|
6
|
-
const originalRenderPage = ctx.renderPage;
|
|
7
|
-
const { req } = ctx;
|
|
8
|
-
if (req) {
|
|
9
|
-
context.update({
|
|
10
|
-
// note: https and unknown here are ok, because nothing is matching on host or protocol in the tracker
|
|
11
|
-
url: new URL(`https://${(_a = req.headers.host) != null ? _a : "unknown"}${req.url}`),
|
|
12
|
-
cookies: req.headers.cookie ? parse(req.headers.cookie) : void 0
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
ctx.renderPage = (opts) => originalRenderPage({
|
|
16
|
-
...opts,
|
|
17
|
-
enhanceApp: (App) => {
|
|
18
|
-
const UniformSSREnhancer = (props) => {
|
|
19
|
-
return /* @__PURE__ */ React.createElement(App, { ...props, serverUniformContext: context });
|
|
20
|
-
};
|
|
21
|
-
return UniformSSREnhancer;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// src/NextCookieTransitionDataStore.ts
|
|
27
|
-
import {
|
|
28
|
-
CookieTransitionDataStore,
|
|
29
|
-
UNIFORM_DEFAULT_COOKIE_NAME,
|
|
30
|
-
UNIFORM_DEFAULT_QUIRK_COOKIE_NAME
|
|
31
|
-
} from "@uniformdev/context";
|
|
32
|
-
import { parse as parse2 } from "cookie";
|
|
33
|
-
var NextCookieTransitionDataStore = class extends CookieTransitionDataStore {
|
|
34
|
-
constructor({ serverContext, ...options }) {
|
|
35
|
-
super({
|
|
36
|
-
...options,
|
|
37
|
-
serverCookieValue: getNextServerCookieValue(serverContext),
|
|
38
|
-
quirkCookieValue: options.experimental_quirksEnabled ? getNextServerCookieValue(
|
|
39
|
-
serverContext,
|
|
40
|
-
options.quirkCookieName || UNIFORM_DEFAULT_QUIRK_COOKIE_NAME
|
|
41
|
-
) : void 0
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
function getNextServerCookieValue(serverContext, cookieName = UNIFORM_DEFAULT_COOKIE_NAME) {
|
|
46
|
-
var _a, _b, _c;
|
|
47
|
-
if (!serverContext) return void 0;
|
|
48
|
-
let cookies = parse2((_b = (_a = serverContext.req) == null ? void 0 : _a.headers.cookie) != null ? _b : "");
|
|
49
|
-
if ((_c = serverContext == null ? void 0 : serverContext.res) == null ? void 0 : _c.getHeaders) {
|
|
50
|
-
const resHeaders = serverContext.res.getHeaders();
|
|
51
|
-
const resCookies = resHeaders["set-cookie"];
|
|
52
|
-
if (resCookies) {
|
|
53
|
-
cookies = { ...cookies, ...parse2(Array.isArray(resCookies) ? resCookies[0] : resCookies.toString()) };
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return cookies[cookieName];
|
|
57
|
-
}
|
|
58
|
-
export {
|
|
59
|
-
NextCookieTransitionDataStore,
|
|
60
|
-
enableNextSsr
|
|
61
|
-
};
|
package/dist/index.mjs
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
// src/enableNextSsr.tsx
|
|
2
|
-
import { parse } from "cookie";
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
function enableNextSsr(ctx, context) {
|
|
5
|
-
var _a;
|
|
6
|
-
const originalRenderPage = ctx.renderPage;
|
|
7
|
-
const { req } = ctx;
|
|
8
|
-
if (req) {
|
|
9
|
-
context.update({
|
|
10
|
-
// note: https and unknown here are ok, because nothing is matching on host or protocol in the tracker
|
|
11
|
-
url: new URL(`https://${(_a = req.headers.host) != null ? _a : "unknown"}${req.url}`),
|
|
12
|
-
cookies: req.headers.cookie ? parse(req.headers.cookie) : void 0
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
ctx.renderPage = (opts) => originalRenderPage({
|
|
16
|
-
...opts,
|
|
17
|
-
enhanceApp: (App) => {
|
|
18
|
-
const UniformSSREnhancer = (props) => {
|
|
19
|
-
return /* @__PURE__ */ React.createElement(App, { ...props, serverUniformContext: context });
|
|
20
|
-
};
|
|
21
|
-
return UniformSSREnhancer;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// src/NextCookieTransitionDataStore.ts
|
|
27
|
-
import {
|
|
28
|
-
CookieTransitionDataStore,
|
|
29
|
-
UNIFORM_DEFAULT_COOKIE_NAME,
|
|
30
|
-
UNIFORM_DEFAULT_QUIRK_COOKIE_NAME
|
|
31
|
-
} from "@uniformdev/context";
|
|
32
|
-
import { parse as parse2 } from "cookie";
|
|
33
|
-
var NextCookieTransitionDataStore = class extends CookieTransitionDataStore {
|
|
34
|
-
constructor({ serverContext, ...options }) {
|
|
35
|
-
super({
|
|
36
|
-
...options,
|
|
37
|
-
serverCookieValue: getNextServerCookieValue(serverContext),
|
|
38
|
-
quirkCookieValue: options.experimental_quirksEnabled ? getNextServerCookieValue(
|
|
39
|
-
serverContext,
|
|
40
|
-
options.quirkCookieName || UNIFORM_DEFAULT_QUIRK_COOKIE_NAME
|
|
41
|
-
) : void 0
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
function getNextServerCookieValue(serverContext, cookieName = UNIFORM_DEFAULT_COOKIE_NAME) {
|
|
46
|
-
var _a, _b, _c;
|
|
47
|
-
if (!serverContext) return void 0;
|
|
48
|
-
let cookies = parse2((_b = (_a = serverContext.req) == null ? void 0 : _a.headers.cookie) != null ? _b : "");
|
|
49
|
-
if ((_c = serverContext == null ? void 0 : serverContext.res) == null ? void 0 : _c.getHeaders) {
|
|
50
|
-
const resHeaders = serverContext.res.getHeaders();
|
|
51
|
-
const resCookies = resHeaders["set-cookie"];
|
|
52
|
-
if (resCookies) {
|
|
53
|
-
cookies = { ...cookies, ...parse2(Array.isArray(resCookies) ? resCookies[0] : resCookies.toString()) };
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return cookies[cookieName];
|
|
57
|
-
}
|
|
58
|
-
export {
|
|
59
|
-
NextCookieTransitionDataStore,
|
|
60
|
-
enableNextSsr
|
|
61
|
-
};
|