@zenmanage/nextjs 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/README.md +329 -2
- package/dist/chunk-HDORXS72.js +109 -0
- package/dist/chunk-HDORXS72.js.map +1 -0
- package/dist/chunk-PHODKVFM.js +238 -0
- package/dist/chunk-PHODKVFM.js.map +1 -0
- package/dist/client.cjs +287 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +38 -0
- package/dist/client.d.ts +38 -0
- package/dist/client.js +263 -0
- package/dist/client.js.map +1 -0
- package/dist/index.cjs +378 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +24 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware.cjs +199 -0
- package/dist/middleware.cjs.map +1 -0
- package/dist/middleware.d.cts +16 -0
- package/dist/middleware.d.ts +16 -0
- package/dist/middleware.js +10 -0
- package/dist/middleware.js.map +1 -0
- package/dist/server.cjs +183 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +35 -0
- package/dist/server.d.ts +35 -0
- package/dist/server.js +25 -0
- package/dist/server.js.map +1 -0
- package/dist/types-CFBzBNpk.d.cts +103 -0
- package/dist/types-CFBzBNpk.d.ts +103 -0
- package/package.json +137 -4
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { FlagValue, ContextData, Context, Logger, DefaultsCollection, Zenmanage, FlagManager } from '@zenmanage/sdk';
|
|
2
|
+
|
|
3
|
+
declare const DEFAULT_BOOTSTRAP_ELEMENT_ID = "__ZENMANAGE_BOOTSTRAP__";
|
|
4
|
+
/**
|
|
5
|
+
* Rules are cached in memory for this many seconds. The SDK's own default is an hour, which
|
|
6
|
+
* would leave a long-running `next start` server on stale rules; a minute keeps flag changes
|
|
7
|
+
* visible quickly while still sharing one fetch across every request and component.
|
|
8
|
+
*/
|
|
9
|
+
declare const DEFAULT_SERVER_CACHE_TTL = 60;
|
|
10
|
+
/**
|
|
11
|
+
* Widens a literal (`false`, `'control'`, `1500`) to its primitive type, so a value read with
|
|
12
|
+
* a literal fallback is `boolean`, `string` or `number` rather than the literal. Object and
|
|
13
|
+
* array values (JSON flags) pass through unchanged.
|
|
14
|
+
*/
|
|
15
|
+
type WidenFlagValue<T extends FlagValue> = T extends boolean ? boolean : T extends number ? number : T extends string ? string : T;
|
|
16
|
+
interface NextZenmanageClientOptions {
|
|
17
|
+
/** A server key (`srv_...`). Server and edge runtimes reject client keys. */
|
|
18
|
+
environmentToken: string;
|
|
19
|
+
apiEndpoint?: string;
|
|
20
|
+
/** Seconds to cache rules in memory. Defaults to {@link DEFAULT_SERVER_CACHE_TTL}. */
|
|
21
|
+
cacheTtl?: number;
|
|
22
|
+
enableUsageReporting?: boolean;
|
|
23
|
+
logger?: Logger;
|
|
24
|
+
}
|
|
25
|
+
interface ServerFlagInput extends NextZenmanageClientOptions {
|
|
26
|
+
key: string;
|
|
27
|
+
defaultValue?: FlagValue;
|
|
28
|
+
context?: Context;
|
|
29
|
+
defaults?: DefaultsCollection;
|
|
30
|
+
}
|
|
31
|
+
interface ServerFlagsInput extends NextZenmanageClientOptions {
|
|
32
|
+
context?: Context;
|
|
33
|
+
defaults?: DefaultsCollection;
|
|
34
|
+
}
|
|
35
|
+
interface ServerBootstrapInput extends ServerFlagsInput {
|
|
36
|
+
/**
|
|
37
|
+
* The flags to send to the browser. Bootstrapping every flag puts each flag's key and
|
|
38
|
+
* value in the page source, so list only what client components read.
|
|
39
|
+
*/
|
|
40
|
+
keys?: string[];
|
|
41
|
+
/** Include the evaluation context in the payload so the browser evaluates for the same user. */
|
|
42
|
+
includeContext?: boolean;
|
|
43
|
+
}
|
|
44
|
+
interface BootstrapPayload {
|
|
45
|
+
version: 1;
|
|
46
|
+
generatedAt: string;
|
|
47
|
+
flags: Record<string, FlagValue>;
|
|
48
|
+
context?: ContextData;
|
|
49
|
+
}
|
|
50
|
+
interface BuildBootstrapPayloadOptions {
|
|
51
|
+
context?: Context;
|
|
52
|
+
generatedAt?: Date;
|
|
53
|
+
}
|
|
54
|
+
interface BuildBootstrapScriptOptions {
|
|
55
|
+
elementId?: string;
|
|
56
|
+
}
|
|
57
|
+
interface RequestCookieValue {
|
|
58
|
+
value: string;
|
|
59
|
+
}
|
|
60
|
+
interface RequestCookiesLike {
|
|
61
|
+
get(name: string): RequestCookieValue | string | undefined;
|
|
62
|
+
}
|
|
63
|
+
interface RequestGeoLike {
|
|
64
|
+
country?: string;
|
|
65
|
+
region?: string;
|
|
66
|
+
city?: string;
|
|
67
|
+
}
|
|
68
|
+
interface RequestLike {
|
|
69
|
+
headers: Headers;
|
|
70
|
+
cookies?: RequestCookiesLike;
|
|
71
|
+
nextUrl?: {
|
|
72
|
+
pathname: string;
|
|
73
|
+
};
|
|
74
|
+
url?: string;
|
|
75
|
+
/** Removed from `NextRequest` in Next.js 15; the forwarding headers are used instead. */
|
|
76
|
+
ip?: string | null;
|
|
77
|
+
/** Removed from `NextRequest` in Next.js 15; the Vercel and Cloudflare headers are used instead. */
|
|
78
|
+
geo?: RequestGeoLike;
|
|
79
|
+
}
|
|
80
|
+
interface BuildRequestContextOptions {
|
|
81
|
+
contextType?: string;
|
|
82
|
+
contextName?: string;
|
|
83
|
+
identifierCookieName?: string;
|
|
84
|
+
identifierHeaderName?: string;
|
|
85
|
+
/** Add `country`, `region` and `city` attributes when the platform reports them. Default `true`. */
|
|
86
|
+
includeGeo?: boolean;
|
|
87
|
+
/** Add the visitor's IP address as an `ip` attribute. Default `false`: an IP is personal data. */
|
|
88
|
+
includeIp?: boolean;
|
|
89
|
+
additionalAttributes?: Record<string, string | string[] | undefined>;
|
|
90
|
+
}
|
|
91
|
+
interface MiddlewareFlagInput extends NextZenmanageClientOptions {
|
|
92
|
+
request: RequestLike;
|
|
93
|
+
key: string;
|
|
94
|
+
defaultValue?: FlagValue;
|
|
95
|
+
defaults?: DefaultsCollection;
|
|
96
|
+
requestContext?: BuildRequestContextOptions;
|
|
97
|
+
}
|
|
98
|
+
interface NextFlagsRuntime {
|
|
99
|
+
client: Zenmanage;
|
|
100
|
+
manager: FlagManager;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { type BuildBootstrapPayloadOptions as B, DEFAULT_BOOTSTRAP_ELEMENT_ID as D, type MiddlewareFlagInput as M, type NextFlagsRuntime as N, type RequestCookiesLike as R, type ServerBootstrapInput as S, type WidenFlagValue as W, type BootstrapPayload as a, type BuildBootstrapScriptOptions as b, type BuildRequestContextOptions as c, DEFAULT_SERVER_CACHE_TTL as d, type NextZenmanageClientOptions as e, type RequestGeoLike as f, type RequestLike as g, type ServerFlagInput as h, type ServerFlagsInput as i };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { FlagValue, ContextData, Context, Logger, DefaultsCollection, Zenmanage, FlagManager } from '@zenmanage/sdk';
|
|
2
|
+
|
|
3
|
+
declare const DEFAULT_BOOTSTRAP_ELEMENT_ID = "__ZENMANAGE_BOOTSTRAP__";
|
|
4
|
+
/**
|
|
5
|
+
* Rules are cached in memory for this many seconds. The SDK's own default is an hour, which
|
|
6
|
+
* would leave a long-running `next start` server on stale rules; a minute keeps flag changes
|
|
7
|
+
* visible quickly while still sharing one fetch across every request and component.
|
|
8
|
+
*/
|
|
9
|
+
declare const DEFAULT_SERVER_CACHE_TTL = 60;
|
|
10
|
+
/**
|
|
11
|
+
* Widens a literal (`false`, `'control'`, `1500`) to its primitive type, so a value read with
|
|
12
|
+
* a literal fallback is `boolean`, `string` or `number` rather than the literal. Object and
|
|
13
|
+
* array values (JSON flags) pass through unchanged.
|
|
14
|
+
*/
|
|
15
|
+
type WidenFlagValue<T extends FlagValue> = T extends boolean ? boolean : T extends number ? number : T extends string ? string : T;
|
|
16
|
+
interface NextZenmanageClientOptions {
|
|
17
|
+
/** A server key (`srv_...`). Server and edge runtimes reject client keys. */
|
|
18
|
+
environmentToken: string;
|
|
19
|
+
apiEndpoint?: string;
|
|
20
|
+
/** Seconds to cache rules in memory. Defaults to {@link DEFAULT_SERVER_CACHE_TTL}. */
|
|
21
|
+
cacheTtl?: number;
|
|
22
|
+
enableUsageReporting?: boolean;
|
|
23
|
+
logger?: Logger;
|
|
24
|
+
}
|
|
25
|
+
interface ServerFlagInput extends NextZenmanageClientOptions {
|
|
26
|
+
key: string;
|
|
27
|
+
defaultValue?: FlagValue;
|
|
28
|
+
context?: Context;
|
|
29
|
+
defaults?: DefaultsCollection;
|
|
30
|
+
}
|
|
31
|
+
interface ServerFlagsInput extends NextZenmanageClientOptions {
|
|
32
|
+
context?: Context;
|
|
33
|
+
defaults?: DefaultsCollection;
|
|
34
|
+
}
|
|
35
|
+
interface ServerBootstrapInput extends ServerFlagsInput {
|
|
36
|
+
/**
|
|
37
|
+
* The flags to send to the browser. Bootstrapping every flag puts each flag's key and
|
|
38
|
+
* value in the page source, so list only what client components read.
|
|
39
|
+
*/
|
|
40
|
+
keys?: string[];
|
|
41
|
+
/** Include the evaluation context in the payload so the browser evaluates for the same user. */
|
|
42
|
+
includeContext?: boolean;
|
|
43
|
+
}
|
|
44
|
+
interface BootstrapPayload {
|
|
45
|
+
version: 1;
|
|
46
|
+
generatedAt: string;
|
|
47
|
+
flags: Record<string, FlagValue>;
|
|
48
|
+
context?: ContextData;
|
|
49
|
+
}
|
|
50
|
+
interface BuildBootstrapPayloadOptions {
|
|
51
|
+
context?: Context;
|
|
52
|
+
generatedAt?: Date;
|
|
53
|
+
}
|
|
54
|
+
interface BuildBootstrapScriptOptions {
|
|
55
|
+
elementId?: string;
|
|
56
|
+
}
|
|
57
|
+
interface RequestCookieValue {
|
|
58
|
+
value: string;
|
|
59
|
+
}
|
|
60
|
+
interface RequestCookiesLike {
|
|
61
|
+
get(name: string): RequestCookieValue | string | undefined;
|
|
62
|
+
}
|
|
63
|
+
interface RequestGeoLike {
|
|
64
|
+
country?: string;
|
|
65
|
+
region?: string;
|
|
66
|
+
city?: string;
|
|
67
|
+
}
|
|
68
|
+
interface RequestLike {
|
|
69
|
+
headers: Headers;
|
|
70
|
+
cookies?: RequestCookiesLike;
|
|
71
|
+
nextUrl?: {
|
|
72
|
+
pathname: string;
|
|
73
|
+
};
|
|
74
|
+
url?: string;
|
|
75
|
+
/** Removed from `NextRequest` in Next.js 15; the forwarding headers are used instead. */
|
|
76
|
+
ip?: string | null;
|
|
77
|
+
/** Removed from `NextRequest` in Next.js 15; the Vercel and Cloudflare headers are used instead. */
|
|
78
|
+
geo?: RequestGeoLike;
|
|
79
|
+
}
|
|
80
|
+
interface BuildRequestContextOptions {
|
|
81
|
+
contextType?: string;
|
|
82
|
+
contextName?: string;
|
|
83
|
+
identifierCookieName?: string;
|
|
84
|
+
identifierHeaderName?: string;
|
|
85
|
+
/** Add `country`, `region` and `city` attributes when the platform reports them. Default `true`. */
|
|
86
|
+
includeGeo?: boolean;
|
|
87
|
+
/** Add the visitor's IP address as an `ip` attribute. Default `false`: an IP is personal data. */
|
|
88
|
+
includeIp?: boolean;
|
|
89
|
+
additionalAttributes?: Record<string, string | string[] | undefined>;
|
|
90
|
+
}
|
|
91
|
+
interface MiddlewareFlagInput extends NextZenmanageClientOptions {
|
|
92
|
+
request: RequestLike;
|
|
93
|
+
key: string;
|
|
94
|
+
defaultValue?: FlagValue;
|
|
95
|
+
defaults?: DefaultsCollection;
|
|
96
|
+
requestContext?: BuildRequestContextOptions;
|
|
97
|
+
}
|
|
98
|
+
interface NextFlagsRuntime {
|
|
99
|
+
client: Zenmanage;
|
|
100
|
+
manager: FlagManager;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { type BuildBootstrapPayloadOptions as B, DEFAULT_BOOTSTRAP_ELEMENT_ID as D, type MiddlewareFlagInput as M, type NextFlagsRuntime as N, type RequestCookiesLike as R, type ServerBootstrapInput as S, type WidenFlagValue as W, type BootstrapPayload as a, type BuildBootstrapScriptOptions as b, type BuildRequestContextOptions as c, DEFAULT_SERVER_CACHE_TTL as d, type NextZenmanageClientOptions as e, type RequestGeoLike as f, type RequestLike as g, type ServerFlagInput as h, type ServerFlagsInput as i };
|
package/package.json
CHANGED
|
@@ -1,6 +1,139 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenmanage/nextjs",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Next.js integration helpers for Zenmanage feature flags: server evaluation, middleware, and hydration-safe client bootstrap",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"nextjs",
|
|
7
|
+
"next.js",
|
|
8
|
+
"react",
|
|
9
|
+
"ssr",
|
|
10
|
+
"app-router",
|
|
11
|
+
"pages-router",
|
|
12
|
+
"middleware",
|
|
13
|
+
"feature-flags",
|
|
14
|
+
"feature-toggles",
|
|
15
|
+
"feature-management",
|
|
16
|
+
"remote-config",
|
|
17
|
+
"ab-testing",
|
|
18
|
+
"experiments",
|
|
19
|
+
"zenmanage"
|
|
20
|
+
],
|
|
21
|
+
"homepage": "https://github.com/zenmanage/zenmanage-nextjs#readme",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/zenmanage/zenmanage-nextjs/issues"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/zenmanage/zenmanage-nextjs.git"
|
|
28
|
+
},
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"author": "Zenmanage",
|
|
31
|
+
"type": "module",
|
|
32
|
+
"main": "./dist/index.cjs",
|
|
33
|
+
"module": "./dist/index.js",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"import": {
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"default": "./dist/index.js"
|
|
40
|
+
},
|
|
41
|
+
"require": {
|
|
42
|
+
"types": "./dist/index.d.cts",
|
|
43
|
+
"default": "./dist/index.cjs"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"./server": {
|
|
47
|
+
"import": {
|
|
48
|
+
"types": "./dist/server.d.ts",
|
|
49
|
+
"default": "./dist/server.js"
|
|
50
|
+
},
|
|
51
|
+
"require": {
|
|
52
|
+
"types": "./dist/server.d.cts",
|
|
53
|
+
"default": "./dist/server.cjs"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"./middleware": {
|
|
57
|
+
"import": {
|
|
58
|
+
"types": "./dist/middleware.d.ts",
|
|
59
|
+
"default": "./dist/middleware.js"
|
|
60
|
+
},
|
|
61
|
+
"require": {
|
|
62
|
+
"types": "./dist/middleware.d.cts",
|
|
63
|
+
"default": "./dist/middleware.cjs"
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"./client": {
|
|
67
|
+
"import": {
|
|
68
|
+
"types": "./dist/client.d.ts",
|
|
69
|
+
"default": "./dist/client.js"
|
|
70
|
+
},
|
|
71
|
+
"require": {
|
|
72
|
+
"types": "./dist/client.d.cts",
|
|
73
|
+
"default": "./dist/client.cjs"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"./package.json": "./package.json"
|
|
77
|
+
},
|
|
78
|
+
"files": [
|
|
79
|
+
"dist",
|
|
80
|
+
"README.md",
|
|
81
|
+
"LICENSE"
|
|
82
|
+
],
|
|
83
|
+
"sideEffects": false,
|
|
84
|
+
"scripts": {
|
|
85
|
+
"build": "rm -rf dist && tsup",
|
|
86
|
+
"clean": "rm -rf dist coverage",
|
|
87
|
+
"changeset": "changeset",
|
|
88
|
+
"version-packages": "changeset version",
|
|
89
|
+
"release": "changeset publish",
|
|
90
|
+
"lint": "eslint src tests --ext .ts,.tsx",
|
|
91
|
+
"lint:fix": "eslint src tests --ext .ts,.tsx --fix",
|
|
92
|
+
"format": "prettier --write \"src/**/*.{ts,tsx}\" \"tests/**/*.{ts,tsx}\" \"examples/**/*.{ts,tsx}\" \"examples/smoke-app/**/*.{js,jsx}\" \"scripts/**/*.mjs\" \"*.{md,json,yml,yaml,cjs}\"",
|
|
93
|
+
"format:check": "prettier --check \"src/**/*.{ts,tsx}\" \"tests/**/*.{ts,tsx}\" \"examples/**/*.{ts,tsx}\" \"examples/smoke-app/**/*.{js,jsx}\" \"scripts/**/*.mjs\" \"*.{md,json,yml,yaml,cjs}\"",
|
|
94
|
+
"type-check": "tsc --noEmit && tsc -p tsconfig.test.json --noEmit && tsc -p tsconfig.examples.json",
|
|
95
|
+
"test": "vitest run",
|
|
96
|
+
"test:watch": "vitest",
|
|
97
|
+
"test:coverage": "vitest run --coverage",
|
|
98
|
+
"test:smoke": "npm run build && node scripts/smoke.mjs",
|
|
99
|
+
"validate": "npm run format:check && npm run lint && npm run type-check && npm run test:coverage && npm run build && npm run test:smoke",
|
|
100
|
+
"prepublishOnly": "npm run validate"
|
|
101
|
+
},
|
|
102
|
+
"peerDependencies": {
|
|
103
|
+
"@zenmanage/react": "^1.0.0",
|
|
104
|
+
"@zenmanage/sdk": "^3.5.0",
|
|
105
|
+
"next": "^13.4.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
|
|
106
|
+
"react": "^18.2.0 || ^19.0.0"
|
|
107
|
+
},
|
|
108
|
+
"devDependencies": {
|
|
109
|
+
"@changesets/cli": "^2.28.1",
|
|
110
|
+
"@testing-library/react": "^16.0.1",
|
|
111
|
+
"@types/node": "^20.11.0",
|
|
112
|
+
"@types/react": "^19.2.0",
|
|
113
|
+
"@types/react-dom": "^19.2.0",
|
|
114
|
+
"@typescript-eslint/eslint-plugin": "^6.20.0",
|
|
115
|
+
"@typescript-eslint/parser": "^6.20.0",
|
|
116
|
+
"@vitest/coverage-v8": "^1.6.0",
|
|
117
|
+
"@zenmanage/react": "^1.0.0",
|
|
118
|
+
"@zenmanage/sdk": "^3.5.0",
|
|
119
|
+
"eslint": "^8.57.0",
|
|
120
|
+
"eslint-config-prettier": "^9.1.0",
|
|
121
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
122
|
+
"eslint-plugin-react-hooks": "^5.1.0",
|
|
123
|
+
"jsdom": "^24.1.1",
|
|
124
|
+
"next": "^15.5.0",
|
|
125
|
+
"prettier": "^3.3.3",
|
|
126
|
+
"react": "^19.2.0",
|
|
127
|
+
"react-dom": "^19.2.0",
|
|
128
|
+
"tsup": "^8.2.4",
|
|
129
|
+
"typescript": "^5.6.2",
|
|
130
|
+
"vitest": "^1.6.0"
|
|
131
|
+
},
|
|
132
|
+
"engines": {
|
|
133
|
+
"node": ">=18.0.0"
|
|
134
|
+
},
|
|
135
|
+
"publishConfig": {
|
|
136
|
+
"access": "public",
|
|
137
|
+
"provenance": true
|
|
138
|
+
}
|
|
139
|
+
}
|