@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
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
DEFAULT_BOOTSTRAP_ELEMENT_ID: () => DEFAULT_BOOTSTRAP_ELEMENT_ID,
|
|
24
|
+
DEFAULT_SERVER_CACHE_TTL: () => DEFAULT_SERVER_CACHE_TTL,
|
|
25
|
+
buildBootstrapPayload: () => buildBootstrapPayload,
|
|
26
|
+
buildBootstrapScript: () => buildBootstrapScript,
|
|
27
|
+
buildContextFromRequest: () => buildContextFromRequest,
|
|
28
|
+
clearServerClients: () => clearServerClients,
|
|
29
|
+
contextFromBootstrapPayload: () => contextFromBootstrapPayload,
|
|
30
|
+
createServerClient: () => createServerClient,
|
|
31
|
+
createServerManager: () => createServerManager,
|
|
32
|
+
createServerRuntime: () => createServerRuntime,
|
|
33
|
+
defaultsFromBootstrapDocument: () => defaultsFromBootstrapDocument,
|
|
34
|
+
defaultsFromBootstrapPayload: () => defaultsFromBootstrapPayload,
|
|
35
|
+
deserializeBootstrapPayload: () => deserializeBootstrapPayload,
|
|
36
|
+
evaluateMiddlewareFlag: () => evaluateMiddlewareFlag,
|
|
37
|
+
getBootstrapPayload: () => getBootstrapPayload,
|
|
38
|
+
getFlagValue: () => getFlagValue,
|
|
39
|
+
getServerFlag: () => getServerFlag,
|
|
40
|
+
getServerFlags: () => getServerFlags,
|
|
41
|
+
mergeDefaults: () => mergeDefaults,
|
|
42
|
+
preloadServerFlags: () => preloadServerFlags,
|
|
43
|
+
readBootstrapPayloadFromDocument: () => readBootstrapPayloadFromDocument,
|
|
44
|
+
serializeBootstrapPayload: () => serializeBootstrapPayload
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(index_exports);
|
|
47
|
+
|
|
48
|
+
// src/types.ts
|
|
49
|
+
var DEFAULT_BOOTSTRAP_ELEMENT_ID = "__ZENMANAGE_BOOTSTRAP__";
|
|
50
|
+
var DEFAULT_SERVER_CACHE_TTL = 60;
|
|
51
|
+
|
|
52
|
+
// src/bootstrap.ts
|
|
53
|
+
var import_sdk = require("@zenmanage/sdk");
|
|
54
|
+
var ELEMENT_ID_PATTERN = /^[A-Za-z_][\w:.-]*$/;
|
|
55
|
+
function escapeForScriptTag(value) {
|
|
56
|
+
return value.replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
57
|
+
}
|
|
58
|
+
function isPlainObject(value) {
|
|
59
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
60
|
+
}
|
|
61
|
+
function isFlagValue(value) {
|
|
62
|
+
return typeof value === "boolean" || typeof value === "string" || typeof value === "number" && Number.isFinite(value) || typeof value === "object" && value !== null;
|
|
63
|
+
}
|
|
64
|
+
function buildBootstrapPayload(flags, options = {}) {
|
|
65
|
+
const values = Array.isArray(flags) ? Object.fromEntries(flags.map((flag) => [flag.getKey(), flag.getValue()])) : flags;
|
|
66
|
+
return {
|
|
67
|
+
version: 1,
|
|
68
|
+
generatedAt: (options.generatedAt ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
69
|
+
flags: values,
|
|
70
|
+
...options.context ? { context: options.context.toJSON() } : {}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function serializeBootstrapPayload(payload) {
|
|
74
|
+
return escapeForScriptTag(JSON.stringify(payload));
|
|
75
|
+
}
|
|
76
|
+
function deserializeBootstrapPayload(serializedPayload) {
|
|
77
|
+
try {
|
|
78
|
+
const parsed = JSON.parse(serializedPayload);
|
|
79
|
+
if (!isPlainObject(parsed) || parsed.version !== 1 || !isPlainObject(parsed.flags) || typeof parsed.generatedAt !== "string") {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
const flags = Object.fromEntries(
|
|
83
|
+
Object.entries(parsed.flags).filter(([, value]) => isFlagValue(value))
|
|
84
|
+
);
|
|
85
|
+
return {
|
|
86
|
+
version: 1,
|
|
87
|
+
generatedAt: parsed.generatedAt,
|
|
88
|
+
flags,
|
|
89
|
+
...isPlainObject(parsed.context) ? { context: parsed.context } : {}
|
|
90
|
+
};
|
|
91
|
+
} catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function buildBootstrapScript(payload, options = {}) {
|
|
96
|
+
const elementId = options.elementId ?? DEFAULT_BOOTSTRAP_ELEMENT_ID;
|
|
97
|
+
if (!ELEMENT_ID_PATTERN.test(elementId)) {
|
|
98
|
+
throw new Error(`Invalid bootstrap element id "${elementId}".`);
|
|
99
|
+
}
|
|
100
|
+
const serialized = serializeBootstrapPayload(payload);
|
|
101
|
+
return `<script id="${elementId}" type="application/json">${serialized}</script>`;
|
|
102
|
+
}
|
|
103
|
+
function readBootstrapPayloadFromDocument(elementId = DEFAULT_BOOTSTRAP_ELEMENT_ID) {
|
|
104
|
+
if (typeof document === "undefined") {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
const element = document.getElementById(elementId);
|
|
108
|
+
if (!element) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
const text = element.textContent ?? "";
|
|
112
|
+
return deserializeBootstrapPayload(text);
|
|
113
|
+
}
|
|
114
|
+
function defaultsFromBootstrapPayload(payload) {
|
|
115
|
+
if (!payload) {
|
|
116
|
+
return void 0;
|
|
117
|
+
}
|
|
118
|
+
return import_sdk.DefaultsCollection.fromObject(payload.flags);
|
|
119
|
+
}
|
|
120
|
+
function defaultsFromBootstrapDocument(elementId = DEFAULT_BOOTSTRAP_ELEMENT_ID) {
|
|
121
|
+
return defaultsFromBootstrapPayload(readBootstrapPayloadFromDocument(elementId));
|
|
122
|
+
}
|
|
123
|
+
function contextFromBootstrapPayload(payload) {
|
|
124
|
+
if (!payload?.context) {
|
|
125
|
+
return void 0;
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
return import_sdk.Context.fromObject(payload.context);
|
|
129
|
+
} catch {
|
|
130
|
+
return void 0;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/defaults.ts
|
|
135
|
+
var import_sdk2 = require("@zenmanage/sdk");
|
|
136
|
+
function mergeDefaults(base, bootstrap) {
|
|
137
|
+
if (!base && !bootstrap) {
|
|
138
|
+
return void 0;
|
|
139
|
+
}
|
|
140
|
+
const merged = new import_sdk2.DefaultsCollection();
|
|
141
|
+
for (const source of [bootstrap, base]) {
|
|
142
|
+
if (!source) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
for (const key of source.keys()) {
|
|
146
|
+
const value = source.get(key);
|
|
147
|
+
if (value !== void 0) {
|
|
148
|
+
merged.set(key, value);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return merged;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/server.ts
|
|
156
|
+
var import_sdk3 = require("@zenmanage/sdk");
|
|
157
|
+
|
|
158
|
+
// package.json
|
|
159
|
+
var version = "1.0.1";
|
|
160
|
+
|
|
161
|
+
// src/identity.ts
|
|
162
|
+
var CLIENT_AGENT = "zenmanage-nextjs";
|
|
163
|
+
var PACKAGE_VERSION = version;
|
|
164
|
+
|
|
165
|
+
// src/server.ts
|
|
166
|
+
function buildClient(options) {
|
|
167
|
+
const builder = import_sdk3.ConfigBuilder.create().withEnvironmentToken(options.environmentToken).withClientAgent(CLIENT_AGENT).withSdkVersion(PACKAGE_VERSION).withCacheTtl(options.cacheTtl ?? DEFAULT_SERVER_CACHE_TTL);
|
|
168
|
+
if (options.apiEndpoint) {
|
|
169
|
+
builder.withApiEndpoint(options.apiEndpoint);
|
|
170
|
+
}
|
|
171
|
+
if (typeof options.enableUsageReporting === "boolean") {
|
|
172
|
+
builder.withUsageReporting(options.enableUsageReporting);
|
|
173
|
+
}
|
|
174
|
+
if (options.logger) {
|
|
175
|
+
builder.withLogger(options.logger);
|
|
176
|
+
}
|
|
177
|
+
return new import_sdk3.Zenmanage(builder.build());
|
|
178
|
+
}
|
|
179
|
+
var clientsWithoutLogger = /* @__PURE__ */ new Map();
|
|
180
|
+
var clientsByLogger = /* @__PURE__ */ new WeakMap();
|
|
181
|
+
function configurationKey(options) {
|
|
182
|
+
return JSON.stringify([
|
|
183
|
+
options.environmentToken,
|
|
184
|
+
options.apiEndpoint ?? null,
|
|
185
|
+
options.cacheTtl ?? null,
|
|
186
|
+
options.enableUsageReporting ?? null
|
|
187
|
+
]);
|
|
188
|
+
}
|
|
189
|
+
function createServerClient(options) {
|
|
190
|
+
let clients = clientsWithoutLogger;
|
|
191
|
+
if (options.logger) {
|
|
192
|
+
clients = clientsByLogger.get(options.logger) ?? /* @__PURE__ */ new Map();
|
|
193
|
+
clientsByLogger.set(options.logger, clients);
|
|
194
|
+
}
|
|
195
|
+
const key = configurationKey(options);
|
|
196
|
+
let client = clients.get(key);
|
|
197
|
+
if (!client) {
|
|
198
|
+
client = buildClient(options);
|
|
199
|
+
clients.set(key, client);
|
|
200
|
+
}
|
|
201
|
+
return client;
|
|
202
|
+
}
|
|
203
|
+
function clearServerClients() {
|
|
204
|
+
clientsWithoutLogger.clear();
|
|
205
|
+
clientsByLogger = /* @__PURE__ */ new WeakMap();
|
|
206
|
+
}
|
|
207
|
+
function createServerRuntime(options) {
|
|
208
|
+
const client = createServerClient(options);
|
|
209
|
+
let manager = client.flags().withDefaults(options.defaults ?? new import_sdk3.DefaultsCollection());
|
|
210
|
+
if (options.context) {
|
|
211
|
+
manager = manager.withContext(options.context);
|
|
212
|
+
}
|
|
213
|
+
return { client, manager };
|
|
214
|
+
}
|
|
215
|
+
function createServerManager(options) {
|
|
216
|
+
return createServerRuntime(options).manager;
|
|
217
|
+
}
|
|
218
|
+
async function getServerFlag(input) {
|
|
219
|
+
const manager = createServerManager(input);
|
|
220
|
+
return manager.single(input.key, input.defaultValue);
|
|
221
|
+
}
|
|
222
|
+
async function getServerFlags(input) {
|
|
223
|
+
const manager = createServerManager(input);
|
|
224
|
+
return manager.all();
|
|
225
|
+
}
|
|
226
|
+
async function preloadServerFlags(input) {
|
|
227
|
+
const manager = createServerManager(input);
|
|
228
|
+
await manager.all();
|
|
229
|
+
return manager;
|
|
230
|
+
}
|
|
231
|
+
async function getFlagValue(input, fallback) {
|
|
232
|
+
const hasOwnDefault = input.defaultValue !== void 0 || input.defaults?.has(input.key) === true;
|
|
233
|
+
const flag = await getServerFlag(hasOwnDefault ? input : { ...input, defaultValue: fallback });
|
|
234
|
+
if (typeof fallback === "boolean") {
|
|
235
|
+
return flag.asBool();
|
|
236
|
+
}
|
|
237
|
+
if (typeof fallback === "number") {
|
|
238
|
+
return flag.asNumber();
|
|
239
|
+
}
|
|
240
|
+
if (typeof fallback === "string") {
|
|
241
|
+
return flag.asString();
|
|
242
|
+
}
|
|
243
|
+
return flag.asJson();
|
|
244
|
+
}
|
|
245
|
+
async function getBootstrapPayload(input) {
|
|
246
|
+
const flags = await getServerFlags(input);
|
|
247
|
+
const wanted = input.keys ? new Set(input.keys) : null;
|
|
248
|
+
return buildBootstrapPayload(
|
|
249
|
+
flags.filter((flag) => wanted === null || wanted.has(flag.getKey())),
|
|
250
|
+
{ context: input.includeContext ? input.context : void 0 }
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// src/middleware.ts
|
|
255
|
+
var import_sdk4 = require("@zenmanage/sdk");
|
|
256
|
+
function getCookieValue(cookies, name) {
|
|
257
|
+
if (!cookies) {
|
|
258
|
+
return void 0;
|
|
259
|
+
}
|
|
260
|
+
const value = cookies.get(name);
|
|
261
|
+
if (typeof value === "string") {
|
|
262
|
+
return value;
|
|
263
|
+
}
|
|
264
|
+
return value?.value;
|
|
265
|
+
}
|
|
266
|
+
function getRequestPath(request) {
|
|
267
|
+
if (request.nextUrl?.pathname) {
|
|
268
|
+
return request.nextUrl.pathname;
|
|
269
|
+
}
|
|
270
|
+
if (request.url) {
|
|
271
|
+
return new URL(request.url).pathname;
|
|
272
|
+
}
|
|
273
|
+
return "/";
|
|
274
|
+
}
|
|
275
|
+
function decodeHeader(value) {
|
|
276
|
+
if (!value) {
|
|
277
|
+
return void 0;
|
|
278
|
+
}
|
|
279
|
+
try {
|
|
280
|
+
return decodeURIComponent(value);
|
|
281
|
+
} catch {
|
|
282
|
+
return value;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function getIp(request) {
|
|
286
|
+
if (request.ip) {
|
|
287
|
+
return request.ip;
|
|
288
|
+
}
|
|
289
|
+
const forwarded = request.headers.get("x-forwarded-for")?.split(",")[0]?.trim();
|
|
290
|
+
return forwarded || request.headers.get("x-real-ip") || void 0;
|
|
291
|
+
}
|
|
292
|
+
function getGeo(request) {
|
|
293
|
+
const { headers, geo } = request;
|
|
294
|
+
return {
|
|
295
|
+
country: geo?.country || headers.get("x-vercel-ip-country") || headers.get("cf-ipcountry") || void 0,
|
|
296
|
+
region: geo?.region || headers.get("x-vercel-ip-country-region") || void 0,
|
|
297
|
+
city: geo?.city || decodeHeader(headers.get("x-vercel-ip-city"))
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
function buildContextFromRequest(request, options = {}) {
|
|
301
|
+
const identifierCookieName = options.identifierCookieName ?? "zenmanage_user_id";
|
|
302
|
+
const identifierHeaderName = options.identifierHeaderName ?? "x-zenmanage-user-id";
|
|
303
|
+
const includeGeo = options.includeGeo ?? true;
|
|
304
|
+
const includeIp = options.includeIp ?? false;
|
|
305
|
+
const identifier = getCookieValue(request.cookies, identifierCookieName) ?? request.headers.get(identifierHeaderName) ?? void 0;
|
|
306
|
+
const context = new import_sdk4.Context(options.contextType ?? "user", options.contextName, identifier);
|
|
307
|
+
const userAgent = request.headers.get("user-agent");
|
|
308
|
+
if (userAgent) {
|
|
309
|
+
context.addAttribute(new import_sdk4.Attribute("user-agent", [userAgent]));
|
|
310
|
+
}
|
|
311
|
+
context.addAttribute(new import_sdk4.Attribute("path", [getRequestPath(request)]));
|
|
312
|
+
const ip = includeIp ? getIp(request) : void 0;
|
|
313
|
+
if (ip) {
|
|
314
|
+
context.addAttribute(new import_sdk4.Attribute("ip", [ip]));
|
|
315
|
+
}
|
|
316
|
+
if (includeGeo) {
|
|
317
|
+
const geo = getGeo(request);
|
|
318
|
+
if (geo.country) {
|
|
319
|
+
context.addAttribute(new import_sdk4.Attribute("country", [geo.country]));
|
|
320
|
+
}
|
|
321
|
+
if (geo.region) {
|
|
322
|
+
context.addAttribute(new import_sdk4.Attribute("region", [geo.region]));
|
|
323
|
+
}
|
|
324
|
+
if (geo.city) {
|
|
325
|
+
context.addAttribute(new import_sdk4.Attribute("city", [geo.city]));
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
if (options.additionalAttributes) {
|
|
329
|
+
for (const [key, value] of Object.entries(options.additionalAttributes)) {
|
|
330
|
+
if (!value) {
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
const values = Array.isArray(value) ? value : [value];
|
|
334
|
+
context.addAttribute(new import_sdk4.Attribute(key, values));
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return context;
|
|
338
|
+
}
|
|
339
|
+
async function evaluateMiddlewareFlag(input) {
|
|
340
|
+
const context = buildContextFromRequest(input.request, input.requestContext);
|
|
341
|
+
return getServerFlag({
|
|
342
|
+
environmentToken: input.environmentToken,
|
|
343
|
+
apiEndpoint: input.apiEndpoint,
|
|
344
|
+
cacheTtl: input.cacheTtl,
|
|
345
|
+
enableUsageReporting: input.enableUsageReporting,
|
|
346
|
+
logger: input.logger,
|
|
347
|
+
key: input.key,
|
|
348
|
+
defaultValue: input.defaultValue,
|
|
349
|
+
defaults: input.defaults,
|
|
350
|
+
context
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
354
|
+
0 && (module.exports = {
|
|
355
|
+
DEFAULT_BOOTSTRAP_ELEMENT_ID,
|
|
356
|
+
DEFAULT_SERVER_CACHE_TTL,
|
|
357
|
+
buildBootstrapPayload,
|
|
358
|
+
buildBootstrapScript,
|
|
359
|
+
buildContextFromRequest,
|
|
360
|
+
clearServerClients,
|
|
361
|
+
contextFromBootstrapPayload,
|
|
362
|
+
createServerClient,
|
|
363
|
+
createServerManager,
|
|
364
|
+
createServerRuntime,
|
|
365
|
+
defaultsFromBootstrapDocument,
|
|
366
|
+
defaultsFromBootstrapPayload,
|
|
367
|
+
deserializeBootstrapPayload,
|
|
368
|
+
evaluateMiddlewareFlag,
|
|
369
|
+
getBootstrapPayload,
|
|
370
|
+
getFlagValue,
|
|
371
|
+
getServerFlag,
|
|
372
|
+
getServerFlags,
|
|
373
|
+
mergeDefaults,
|
|
374
|
+
preloadServerFlags,
|
|
375
|
+
readBootstrapPayloadFromDocument,
|
|
376
|
+
serializeBootstrapPayload
|
|
377
|
+
});
|
|
378
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/types.ts","../src/bootstrap.ts","../src/defaults.ts","../src/server.ts","../package.json","../src/identity.ts","../src/middleware.ts"],"sourcesContent":["export {\n DEFAULT_BOOTSTRAP_ELEMENT_ID,\n DEFAULT_SERVER_CACHE_TTL,\n type BootstrapPayload,\n type BuildBootstrapPayloadOptions,\n type BuildBootstrapScriptOptions,\n type BuildRequestContextOptions,\n type MiddlewareFlagInput,\n type NextFlagsRuntime,\n type NextZenmanageClientOptions,\n type RequestCookiesLike,\n type RequestGeoLike,\n type RequestLike,\n type ServerBootstrapInput,\n type ServerFlagInput,\n type ServerFlagsInput,\n type WidenFlagValue,\n} from './types';\n\nexport {\n buildBootstrapPayload,\n buildBootstrapScript,\n contextFromBootstrapPayload,\n defaultsFromBootstrapDocument,\n defaultsFromBootstrapPayload,\n deserializeBootstrapPayload,\n readBootstrapPayloadFromDocument,\n serializeBootstrapPayload,\n} from './bootstrap';\n\nexport { mergeDefaults } from './defaults';\n\nexport {\n clearServerClients,\n createServerClient,\n createServerManager,\n createServerRuntime,\n getBootstrapPayload,\n getFlagValue,\n getServerFlag,\n getServerFlags,\n preloadServerFlags,\n} from './server';\n\nexport { buildContextFromRequest, evaluateMiddlewareFlag } from './middleware';\n","import type {\n Context,\n ContextData,\n DefaultsCollection,\n FlagManager,\n FlagValue,\n Logger,\n Zenmanage,\n} from '@zenmanage/sdk';\nimport type { FlagsProviderProps } from '@zenmanage/react';\n\nexport const DEFAULT_BOOTSTRAP_ELEMENT_ID = '__ZENMANAGE_BOOTSTRAP__';\n\n/**\n * Rules are cached in memory for this many seconds. The SDK's own default is an hour, which\n * would leave a long-running `next start` server on stale rules; a minute keeps flag changes\n * visible quickly while still sharing one fetch across every request and component.\n */\nexport const DEFAULT_SERVER_CACHE_TTL = 60;\n\n/**\n * Widens a literal (`false`, `'control'`, `1500`) to its primitive type, so a value read with\n * a literal fallback is `boolean`, `string` or `number` rather than the literal. Object and\n * array values (JSON flags) pass through unchanged.\n */\nexport type WidenFlagValue<T extends FlagValue> = T extends boolean\n ? boolean\n : T extends number\n ? number\n : T extends string\n ? string\n : T;\n\nexport interface NextZenmanageClientOptions {\n /** A server key (`srv_...`). Server and edge runtimes reject client keys. */\n environmentToken: string;\n apiEndpoint?: string;\n /** Seconds to cache rules in memory. Defaults to {@link DEFAULT_SERVER_CACHE_TTL}. */\n cacheTtl?: number;\n enableUsageReporting?: boolean;\n logger?: Logger;\n}\n\nexport interface ServerFlagInput extends NextZenmanageClientOptions {\n key: string;\n defaultValue?: FlagValue;\n context?: Context;\n defaults?: DefaultsCollection;\n}\n\nexport interface ServerFlagsInput extends NextZenmanageClientOptions {\n context?: Context;\n defaults?: DefaultsCollection;\n}\n\nexport interface ServerBootstrapInput extends ServerFlagsInput {\n /**\n * The flags to send to the browser. Bootstrapping every flag puts each flag's key and\n * value in the page source, so list only what client components read.\n */\n keys?: string[];\n /** Include the evaluation context in the payload so the browser evaluates for the same user. */\n includeContext?: boolean;\n}\n\nexport interface BootstrapPayload {\n version: 1;\n generatedAt: string;\n flags: Record<string, FlagValue>;\n context?: ContextData;\n}\n\nexport interface BuildBootstrapPayloadOptions {\n context?: Context;\n generatedAt?: Date;\n}\n\nexport interface BuildBootstrapScriptOptions {\n elementId?: string;\n}\n\nexport interface RequestCookieValue {\n value: string;\n}\n\nexport interface RequestCookiesLike {\n get(name: string): RequestCookieValue | string | undefined;\n}\n\nexport interface RequestGeoLike {\n country?: string;\n region?: string;\n city?: string;\n}\n\nexport interface RequestLike {\n headers: Headers;\n cookies?: RequestCookiesLike;\n nextUrl?: { pathname: string };\n url?: string;\n /** Removed from `NextRequest` in Next.js 15; the forwarding headers are used instead. */\n ip?: string | null;\n /** Removed from `NextRequest` in Next.js 15; the Vercel and Cloudflare headers are used instead. */\n geo?: RequestGeoLike;\n}\n\nexport interface BuildRequestContextOptions {\n contextType?: string;\n contextName?: string;\n identifierCookieName?: string;\n identifierHeaderName?: string;\n /** Add `country`, `region` and `city` attributes when the platform reports them. Default `true`. */\n includeGeo?: boolean;\n /** Add the visitor's IP address as an `ip` attribute. Default `false`: an IP is personal data. */\n includeIp?: boolean;\n additionalAttributes?: Record<string, string | string[] | undefined>;\n}\n\nexport interface MiddlewareFlagInput extends NextZenmanageClientOptions {\n request: RequestLike;\n key: string;\n defaultValue?: FlagValue;\n defaults?: DefaultsCollection;\n requestContext?: BuildRequestContextOptions;\n}\n\nexport interface NextFlagsProviderProps extends Omit<FlagsProviderProps, 'defaults'> {\n defaults?: DefaultsCollection;\n /**\n * Flags evaluated on the server. Pass it as a prop so the server render and the first\n * client render see the same value, which is what keeps hydration clean.\n */\n bootstrapPayload?: BootstrapPayload | null;\n /** Read the payload from a `<script>` tag with this id when `bootstrapPayload` isn't set. */\n bootstrapElementId?: string;\n}\n\nexport interface NextFlagsRuntime {\n client: Zenmanage;\n manager: FlagManager;\n}\n","import {\n Context,\n DefaultsCollection,\n type ContextData,\n type Flag,\n type FlagValue,\n} from '@zenmanage/sdk';\nimport type {\n BootstrapPayload,\n BuildBootstrapPayloadOptions,\n BuildBootstrapScriptOptions,\n} from './types';\nimport { DEFAULT_BOOTSTRAP_ELEMENT_ID } from './types';\n\nconst ELEMENT_ID_PATTERN = /^[A-Za-z_][\\w:.-]*$/;\n\nfunction escapeForScriptTag(value: string): string {\n return value\n .replace(/</g, '\\\\u003c')\n .replace(/>/g, '\\\\u003e')\n .replace(/&/g, '\\\\u0026')\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029');\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction isFlagValue(value: unknown): value is FlagValue {\n return (\n typeof value === 'boolean' ||\n typeof value === 'string' ||\n (typeof value === 'number' && Number.isFinite(value)) ||\n (typeof value === 'object' && value !== null)\n );\n}\n\n/**\n * Builds the payload `NextFlagsProvider` reads. Accepts the flags straight from\n * `getServerFlags`, or a plain `{ key: value }` record.\n */\nexport function buildBootstrapPayload(\n flags: Flag[] | Record<string, FlagValue>,\n options: BuildBootstrapPayloadOptions = {}\n): BootstrapPayload {\n const values = Array.isArray(flags)\n ? Object.fromEntries(flags.map((flag) => [flag.getKey(), flag.getValue()]))\n : flags;\n\n // `context` is left out rather than set to undefined: Next.js refuses undefined in the props\n // `getServerSideProps` returns, and this payload is meant to be passed there.\n return {\n version: 1,\n generatedAt: (options.generatedAt ?? new Date()).toISOString(),\n flags: values,\n ...(options.context ? { context: options.context.toJSON() } : {}),\n };\n}\n\nexport function serializeBootstrapPayload(payload: BootstrapPayload): string {\n return escapeForScriptTag(JSON.stringify(payload));\n}\n\nexport function deserializeBootstrapPayload(serializedPayload: string): BootstrapPayload | null {\n try {\n const parsed: unknown = JSON.parse(serializedPayload);\n\n if (\n !isPlainObject(parsed) ||\n parsed.version !== 1 ||\n !isPlainObject(parsed.flags) ||\n typeof parsed.generatedAt !== 'string'\n ) {\n return null;\n }\n\n const flags = Object.fromEntries(\n Object.entries(parsed.flags).filter(([, value]) => isFlagValue(value))\n ) as Record<string, FlagValue>;\n\n return {\n version: 1,\n generatedAt: parsed.generatedAt,\n flags,\n ...(isPlainObject(parsed.context)\n ? { context: parsed.context as unknown as ContextData }\n : {}),\n };\n } catch {\n return null;\n }\n}\n\n/**\n * Renders the payload as a JSON `<script>` tag for pages that can't pass props to the provider.\n * Prefer the `bootstrapPayload` prop: only a prop is identical on the server and in the browser.\n */\nexport function buildBootstrapScript(\n payload: BootstrapPayload,\n options: BuildBootstrapScriptOptions = {}\n): string {\n const elementId = options.elementId ?? DEFAULT_BOOTSTRAP_ELEMENT_ID;\n\n if (!ELEMENT_ID_PATTERN.test(elementId)) {\n throw new Error(`Invalid bootstrap element id \"${elementId}\".`);\n }\n\n const serialized = serializeBootstrapPayload(payload);\n return `<script id=\"${elementId}\" type=\"application/json\">${serialized}</script>`;\n}\n\nexport function readBootstrapPayloadFromDocument(\n elementId = DEFAULT_BOOTSTRAP_ELEMENT_ID\n): BootstrapPayload | null {\n if (typeof document === 'undefined') {\n return null;\n }\n\n const element = document.getElementById(elementId);\n if (!element) {\n return null;\n }\n\n const text = element.textContent ?? '';\n return deserializeBootstrapPayload(text);\n}\n\nexport function defaultsFromBootstrapPayload(\n payload: BootstrapPayload | null | undefined\n): DefaultsCollection | undefined {\n if (!payload) {\n return undefined;\n }\n\n return DefaultsCollection.fromObject(payload.flags);\n}\n\nexport function defaultsFromBootstrapDocument(\n elementId = DEFAULT_BOOTSTRAP_ELEMENT_ID\n): DefaultsCollection | undefined {\n return defaultsFromBootstrapPayload(readBootstrapPayloadFromDocument(elementId));\n}\n\nexport function contextFromBootstrapPayload(\n payload: BootstrapPayload | null | undefined\n): Context | undefined {\n if (!payload?.context) {\n return undefined;\n }\n\n try {\n return Context.fromObject(payload.context);\n } catch {\n return undefined;\n }\n}\n","import { DefaultsCollection } from '@zenmanage/sdk';\n\n/** Combines two collections. `base` wins where both define a key. */\nexport function mergeDefaults(\n base?: DefaultsCollection,\n bootstrap?: DefaultsCollection\n): DefaultsCollection | undefined {\n if (!base && !bootstrap) {\n return undefined;\n }\n\n const merged = new DefaultsCollection();\n\n for (const source of [bootstrap, base]) {\n if (!source) {\n continue;\n }\n\n for (const key of source.keys()) {\n const value = source.get(key);\n if (value !== undefined) {\n merged.set(key, value);\n }\n }\n }\n\n return merged;\n}\n","import {\n ConfigBuilder,\n DefaultsCollection,\n Zenmanage,\n type Flag,\n type FlagManager,\n type FlagValue,\n type Logger,\n} from '@zenmanage/sdk';\nimport { buildBootstrapPayload } from './bootstrap';\nimport { CLIENT_AGENT, PACKAGE_VERSION } from './identity';\nimport {\n DEFAULT_SERVER_CACHE_TTL,\n type BootstrapPayload,\n type NextFlagsRuntime,\n type NextZenmanageClientOptions,\n type ServerBootstrapInput,\n type ServerFlagInput,\n type ServerFlagsInput,\n type WidenFlagValue,\n} from './types';\n\nexport { mergeDefaults } from './defaults';\n\nfunction buildClient(options: NextZenmanageClientOptions): Zenmanage {\n const builder = ConfigBuilder.create()\n .withEnvironmentToken(options.environmentToken)\n .withClientAgent(CLIENT_AGENT)\n .withSdkVersion(PACKAGE_VERSION)\n .withCacheTtl(options.cacheTtl ?? DEFAULT_SERVER_CACHE_TTL);\n\n if (options.apiEndpoint) {\n builder.withApiEndpoint(options.apiEndpoint);\n }\n\n if (typeof options.enableUsageReporting === 'boolean') {\n builder.withUsageReporting(options.enableUsageReporting);\n }\n\n if (options.logger) {\n builder.withLogger(options.logger);\n }\n\n return new Zenmanage(builder.build());\n}\n\n// A client owns the rules cache, so building one per call would refetch the rules for every\n// flag on every request. Clients are shared per configuration instead, for the life of the\n// server process (or edge isolate). Loggers are compared by identity, hence the WeakMap.\nconst clientsWithoutLogger = new Map<string, Zenmanage>();\nlet clientsByLogger = new WeakMap<Logger, Map<string, Zenmanage>>();\n\nfunction configurationKey(options: NextZenmanageClientOptions): string {\n return JSON.stringify([\n options.environmentToken,\n options.apiEndpoint ?? null,\n options.cacheTtl ?? null,\n options.enableUsageReporting ?? null,\n ]);\n}\n\n/**\n * Returns the client for this configuration, creating it on first use. Calls with the same\n * token, endpoint, TTL, usage setting and logger share one client and so one rules cache.\n */\nexport function createServerClient(options: NextZenmanageClientOptions): Zenmanage {\n let clients = clientsWithoutLogger;\n\n if (options.logger) {\n clients = clientsByLogger.get(options.logger) ?? new Map<string, Zenmanage>();\n clientsByLogger.set(options.logger, clients);\n }\n\n const key = configurationKey(options);\n let client = clients.get(key);\n\n if (!client) {\n client = buildClient(options);\n clients.set(key, client);\n }\n\n return client;\n}\n\n/** Forgets every shared client, and with them their cached rules. Mostly useful in tests. */\nexport function clearServerClients(): void {\n clientsWithoutLogger.clear();\n clientsByLogger = new WeakMap();\n}\n\nexport function createServerRuntime(options: ServerFlagsInput): NextFlagsRuntime {\n const client = createServerClient(options);\n\n // A manager loads its rules once and keeps them, whatever the cache TTL. Handing out the\n // client's own manager would pin the first rules it saw for the life of the process, so\n // every call gets a copy that reads the shared cache (and so honors the TTL) instead.\n let manager = client.flags().withDefaults(options.defaults ?? new DefaultsCollection());\n\n if (options.context) {\n manager = manager.withContext(options.context);\n }\n\n return { client, manager };\n}\n\nexport function createServerManager(options: ServerFlagsInput): FlagManager {\n return createServerRuntime(options).manager;\n}\n\nexport async function getServerFlag(input: ServerFlagInput): Promise<Flag> {\n const manager = createServerManager(input);\n return manager.single(input.key, input.defaultValue);\n}\n\nexport async function getServerFlags(input: ServerFlagsInput): Promise<Flag[]> {\n const manager = createServerManager(input);\n return manager.all();\n}\n\nexport async function preloadServerFlags(input: ServerFlagsInput): Promise<FlagManager> {\n const manager = createServerManager(input);\n await manager.all();\n return manager;\n}\n\n/**\n * Evaluates a flag and returns its value as the type of `fallback`: a boolean, number or\n * string, or a JSON object or array. A literal fallback (`'control'`, `false`) gives the\n * widened type (`string`, `boolean`), so the result can be compared with other values.\n *\n * `fallback` is also the default, for a flag that doesn't exist or when the API can't be\n * reached. A `defaultValue` in `input`, or an entry for the key in `input.defaults`, is more\n * specific and wins over it.\n */\nexport async function getFlagValue<T extends FlagValue>(\n input: ServerFlagInput,\n fallback: T\n): Promise<WidenFlagValue<T>> {\n // The SDK prefers an inline default over a defaults collection, so the fallback only goes in\n // when nothing else would supply one. Otherwise it would override the collection's entry.\n const hasOwnDefault = input.defaultValue !== undefined || input.defaults?.has(input.key) === true;\n const flag = await getServerFlag(hasOwnDefault ? input : { ...input, defaultValue: fallback });\n\n if (typeof fallback === 'boolean') {\n return flag.asBool() as WidenFlagValue<T>;\n }\n\n if (typeof fallback === 'number') {\n return flag.asNumber() as WidenFlagValue<T>;\n }\n\n if (typeof fallback === 'string') {\n return flag.asString() as WidenFlagValue<T>;\n }\n\n return flag.asJson() as WidenFlagValue<T>;\n}\n\n/**\n * Evaluates flags on the server and packages them for `NextFlagsProvider`. Pass `keys` to\n * send only the flags client components read.\n */\nexport async function getBootstrapPayload(input: ServerBootstrapInput): Promise<BootstrapPayload> {\n const flags = await getServerFlags(input);\n const wanted = input.keys ? new Set(input.keys) : null;\n\n return buildBootstrapPayload(\n flags.filter((flag) => wanted === null || wanted.has(flag.getKey())),\n { context: input.includeContext ? input.context : undefined }\n );\n}\n","{\n \"name\": \"@zenmanage/nextjs\",\n \"version\": \"1.0.1\",\n \"description\": \"Next.js integration helpers for Zenmanage feature flags: server evaluation, middleware, and hydration-safe client bootstrap\",\n \"keywords\": [\n \"nextjs\",\n \"next.js\",\n \"react\",\n \"ssr\",\n \"app-router\",\n \"pages-router\",\n \"middleware\",\n \"feature-flags\",\n \"feature-toggles\",\n \"feature-management\",\n \"remote-config\",\n \"ab-testing\",\n \"experiments\",\n \"zenmanage\"\n ],\n \"homepage\": \"https://github.com/zenmanage/zenmanage-nextjs#readme\",\n \"bugs\": {\n \"url\": \"https://github.com/zenmanage/zenmanage-nextjs/issues\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/zenmanage/zenmanage-nextjs.git\"\n },\n \"license\": \"MIT\",\n \"author\": \"Zenmanage\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"import\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/index.d.cts\",\n \"default\": \"./dist/index.cjs\"\n }\n },\n \"./server\": {\n \"import\": {\n \"types\": \"./dist/server.d.ts\",\n \"default\": \"./dist/server.js\"\n },\n \"require\": {\n \"types\": \"./dist/server.d.cts\",\n \"default\": \"./dist/server.cjs\"\n }\n },\n \"./middleware\": {\n \"import\": {\n \"types\": \"./dist/middleware.d.ts\",\n \"default\": \"./dist/middleware.js\"\n },\n \"require\": {\n \"types\": \"./dist/middleware.d.cts\",\n \"default\": \"./dist/middleware.cjs\"\n }\n },\n \"./client\": {\n \"import\": {\n \"types\": \"./dist/client.d.ts\",\n \"default\": \"./dist/client.js\"\n },\n \"require\": {\n \"types\": \"./dist/client.d.cts\",\n \"default\": \"./dist/client.cjs\"\n }\n },\n \"./package.json\": \"./package.json\"\n },\n \"files\": [\n \"dist\",\n \"README.md\",\n \"LICENSE\"\n ],\n \"sideEffects\": false,\n \"scripts\": {\n \"build\": \"rm -rf dist && tsup\",\n \"clean\": \"rm -rf dist coverage\",\n \"changeset\": \"changeset\",\n \"version-packages\": \"changeset version\",\n \"release\": \"changeset publish\",\n \"lint\": \"eslint src tests --ext .ts,.tsx\",\n \"lint:fix\": \"eslint src tests --ext .ts,.tsx --fix\",\n \"format\": \"prettier --write \\\"src/**/*.{ts,tsx}\\\" \\\"tests/**/*.{ts,tsx}\\\" \\\"examples/**/*.{ts,tsx}\\\" \\\"examples/smoke-app/**/*.{js,jsx}\\\" \\\"scripts/**/*.mjs\\\" \\\"*.{md,json,yml,yaml,cjs}\\\"\",\n \"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}\\\"\",\n \"type-check\": \"tsc --noEmit && tsc -p tsconfig.test.json --noEmit && tsc -p tsconfig.examples.json\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"test:coverage\": \"vitest run --coverage\",\n \"test:smoke\": \"npm run build && node scripts/smoke.mjs\",\n \"validate\": \"npm run format:check && npm run lint && npm run type-check && npm run test:coverage && npm run build && npm run test:smoke\",\n \"prepublishOnly\": \"npm run validate\"\n },\n \"peerDependencies\": {\n \"@zenmanage/react\": \"^1.0.0\",\n \"@zenmanage/sdk\": \"^3.5.0\",\n \"next\": \"^13.4.0 || ^14.0.0 || ^15.0.0 || ^16.0.0\",\n \"react\": \"^18.2.0 || ^19.0.0\"\n },\n \"devDependencies\": {\n \"@changesets/cli\": \"^2.28.1\",\n \"@testing-library/react\": \"^16.0.1\",\n \"@types/node\": \"^20.11.0\",\n \"@types/react\": \"^19.2.0\",\n \"@types/react-dom\": \"^19.2.0\",\n \"@typescript-eslint/eslint-plugin\": \"^6.20.0\",\n \"@typescript-eslint/parser\": \"^6.20.0\",\n \"@vitest/coverage-v8\": \"^1.6.0\",\n \"@zenmanage/react\": \"^1.0.0\",\n \"@zenmanage/sdk\": \"^3.5.0\",\n \"eslint\": \"^8.57.0\",\n \"eslint-config-prettier\": \"^9.1.0\",\n \"eslint-plugin-prettier\": \"^5.2.1\",\n \"eslint-plugin-react-hooks\": \"^5.1.0\",\n \"jsdom\": \"^24.1.1\",\n \"next\": \"^15.5.0\",\n \"prettier\": \"^3.3.3\",\n \"react\": \"^19.2.0\",\n \"react-dom\": \"^19.2.0\",\n \"tsup\": \"^8.2.4\",\n \"typescript\": \"^5.6.2\",\n \"vitest\": \"^1.6.0\"\n },\n \"engines\": {\n \"node\": \">=18.0.0\"\n },\n \"publishConfig\": {\n \"access\": \"public\",\n \"provenance\": true\n }\n}\n","import { version } from '../package.json';\n\n/** The client agent the API registers this package under (see the api's EnsureClientAgentIsValid). */\nexport const CLIENT_AGENT = 'zenmanage-nextjs';\n\nexport const PACKAGE_VERSION: string = version;\n","import { Attribute, Context, type Flag } from '@zenmanage/sdk';\nimport { getServerFlag } from './server';\nimport type {\n BuildRequestContextOptions,\n MiddlewareFlagInput,\n RequestCookiesLike,\n RequestLike,\n} from './types';\n\nfunction getCookieValue(cookies: RequestCookiesLike | undefined, name: string): string | undefined {\n if (!cookies) {\n return undefined;\n }\n\n const value = cookies.get(name);\n if (typeof value === 'string') {\n return value;\n }\n\n return value?.value;\n}\n\nfunction getRequestPath(request: RequestLike): string {\n if (request.nextUrl?.pathname) {\n return request.nextUrl.pathname;\n }\n\n if (request.url) {\n return new URL(request.url).pathname;\n }\n\n return '/';\n}\n\nfunction decodeHeader(value: string | null): string | undefined {\n if (!value) {\n return undefined;\n }\n\n try {\n return decodeURIComponent(value);\n } catch {\n return value;\n }\n}\n\n// Next.js 15 removed `request.ip` and `request.geo`, so read what the platform forwards.\nfunction getIp(request: RequestLike): string | undefined {\n if (request.ip) {\n return request.ip;\n }\n\n const forwarded = request.headers.get('x-forwarded-for')?.split(',')[0]?.trim();\n return forwarded || request.headers.get('x-real-ip') || undefined;\n}\n\nfunction getGeo(request: RequestLike): { country?: string; region?: string; city?: string } {\n const { headers, geo } = request;\n\n // Next.js 14 and earlier set `request.geo` even when nothing fills it in (it is `{}` when\n // self-hosted), so each field falls back to the headers on its own.\n return {\n country:\n geo?.country ||\n headers.get('x-vercel-ip-country') ||\n headers.get('cf-ipcountry') ||\n undefined,\n region: geo?.region || headers.get('x-vercel-ip-country-region') || undefined,\n city: geo?.city || decodeHeader(headers.get('x-vercel-ip-city')),\n };\n}\n\n/**\n * Builds an evaluation context from a request: an identifier (cookie, then header), the path,\n * the user agent and, when the platform reports it, the visitor's location. Works with\n * `NextRequest` and with a plain `Request`.\n */\nexport function buildContextFromRequest(\n request: RequestLike,\n options: BuildRequestContextOptions = {}\n): Context {\n const identifierCookieName = options.identifierCookieName ?? 'zenmanage_user_id';\n const identifierHeaderName = options.identifierHeaderName ?? 'x-zenmanage-user-id';\n const includeGeo = options.includeGeo ?? true;\n const includeIp = options.includeIp ?? false;\n\n const identifier =\n getCookieValue(request.cookies, identifierCookieName) ??\n request.headers.get(identifierHeaderName) ??\n undefined;\n\n const context = new Context(options.contextType ?? 'user', options.contextName, identifier);\n\n const userAgent = request.headers.get('user-agent');\n if (userAgent) {\n context.addAttribute(new Attribute('user-agent', [userAgent]));\n }\n\n context.addAttribute(new Attribute('path', [getRequestPath(request)]));\n\n const ip = includeIp ? getIp(request) : undefined;\n if (ip) {\n context.addAttribute(new Attribute('ip', [ip]));\n }\n\n if (includeGeo) {\n const geo = getGeo(request);\n\n if (geo.country) {\n context.addAttribute(new Attribute('country', [geo.country]));\n }\n\n if (geo.region) {\n context.addAttribute(new Attribute('region', [geo.region]));\n }\n\n if (geo.city) {\n context.addAttribute(new Attribute('city', [geo.city]));\n }\n }\n\n if (options.additionalAttributes) {\n for (const [key, value] of Object.entries(options.additionalAttributes)) {\n if (!value) {\n continue;\n }\n\n const values = Array.isArray(value) ? value : [value];\n context.addAttribute(new Attribute(key, values));\n }\n }\n\n return context;\n}\n\n/**\n * Evaluates one flag for the request. Runs on the Edge runtime (`middleware.ts`) and on the\n * Node.js runtime (`proxy.ts` in Next.js 16), and needs a server key in both.\n */\nexport async function evaluateMiddlewareFlag(input: MiddlewareFlagInput): Promise<Flag> {\n const context = buildContextFromRequest(input.request, input.requestContext);\n\n return getServerFlag({\n environmentToken: input.environmentToken,\n apiEndpoint: input.apiEndpoint,\n cacheTtl: input.cacheTtl,\n enableUsageReporting: input.enableUsageReporting,\n logger: input.logger,\n key: input.key,\n defaultValue: input.defaultValue,\n defaults: input.defaults,\n context,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACWO,IAAM,+BAA+B;AAOrC,IAAM,2BAA2B;;;AClBxC,iBAMO;AAQP,IAAM,qBAAqB;AAE3B,SAAS,mBAAmB,OAAuB;AACjD,SAAO,MACJ,QAAQ,MAAM,SAAS,EACvB,QAAQ,MAAM,SAAS,EACvB,QAAQ,MAAM,SAAS,EACvB,QAAQ,WAAW,SAAS,EAC5B,QAAQ,WAAW,SAAS;AACjC;AAEA,SAAS,cAAc,OAAkD;AACvE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,YAAY,OAAoC;AACvD,SACE,OAAO,UAAU,aACjB,OAAO,UAAU,YAChB,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,KAClD,OAAO,UAAU,YAAY,UAAU;AAE5C;AAMO,SAAS,sBACd,OACA,UAAwC,CAAC,GACvB;AAClB,QAAM,SAAS,MAAM,QAAQ,KAAK,IAC9B,OAAO,YAAY,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,IACxE;AAIJ,SAAO;AAAA,IACL,SAAS;AAAA,IACT,cAAc,QAAQ,eAAe,oBAAI,KAAK,GAAG,YAAY;AAAA,IAC7D,OAAO;AAAA,IACP,GAAI,QAAQ,UAAU,EAAE,SAAS,QAAQ,QAAQ,OAAO,EAAE,IAAI,CAAC;AAAA,EACjE;AACF;AAEO,SAAS,0BAA0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,aAAa,IAAI,sBAAU,MAAM,CAAC,EAAE,CAAC,CAAC;AAAA,EAChD;AAEA,MAAI,YAAY;AACd,UAAM,MAAM,OAAO,OAAO;AAE1B,QAAI,IAAI,SAAS;AACf,cAAQ,aAAa,IAAI,sBAAU,WAAW,CAAC,IAAI,OAAO,CAAC,CAAC;AAAA,IAC9D;AAEA,QAAI,IAAI,QAAQ;AACd,cAAQ,aAAa,IAAI,sBAAU,UAAU,CAAC,IAAI,MAAM,CAAC,CAAC;AAAA,IAC5D;AAEA,QAAI,IAAI,MAAM;AACZ,cAAQ,aAAa,IAAI,sBAAU,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAC;AAAA,IACxD;AAAA,EACF;AAEA,MAAI,QAAQ,sBAAsB;AAChC,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,QAAQ,oBAAoB,GAAG;AACvE,UAAI,CAAC,OAAO;AACV;AAAA,MACF;AAEA,YAAM,SAAS,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK;AACpD,cAAQ,aAAa,IAAI,sBAAU,KAAK,MAAM,CAAC;AAAA,IACjD;AAAA,EACF;AAEA,SAAO;AACT;AAMA,eAAsB,uBAAuB,OAA2C;AACtF,QAAM,UAAU,wBAAwB,MAAM,SAAS,MAAM,cAAc;AAE3E,SAAO,cAAc;AAAA,IACnB,kBAAkB,MAAM;AAAA,IACxB,aAAa,MAAM;AAAA,IACnB,UAAU,MAAM;AAAA,IAChB,sBAAsB,MAAM;AAAA,IAC5B,QAAQ,MAAM;AAAA,IACd,KAAK,MAAM;AAAA,IACX,cAAc,MAAM;AAAA,IACpB,UAAU,MAAM;AAAA,IAChB;AAAA,EACF,CAAC;AACH;","names":["import_sdk","import_sdk","import_sdk"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { B as BuildBootstrapPayloadOptions, a as BootstrapPayload, b as BuildBootstrapScriptOptions } from './types-CFBzBNpk.cjs';
|
|
2
|
+
export { c as BuildRequestContextOptions, D as DEFAULT_BOOTSTRAP_ELEMENT_ID, d as DEFAULT_SERVER_CACHE_TTL, M as MiddlewareFlagInput, N as NextFlagsRuntime, e as NextZenmanageClientOptions, R as RequestCookiesLike, f as RequestGeoLike, g as RequestLike, S as ServerBootstrapInput, h as ServerFlagInput, i as ServerFlagsInput, W as WidenFlagValue } from './types-CFBzBNpk.cjs';
|
|
3
|
+
import { Flag, FlagValue, Context, DefaultsCollection } from '@zenmanage/sdk';
|
|
4
|
+
export { clearServerClients, createServerClient, createServerManager, createServerRuntime, getBootstrapPayload, getFlagValue, getServerFlag, getServerFlags, mergeDefaults, preloadServerFlags } from './server.cjs';
|
|
5
|
+
export { buildContextFromRequest, evaluateMiddlewareFlag } from './middleware.cjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Builds the payload `NextFlagsProvider` reads. Accepts the flags straight from
|
|
9
|
+
* `getServerFlags`, or a plain `{ key: value }` record.
|
|
10
|
+
*/
|
|
11
|
+
declare function buildBootstrapPayload(flags: Flag[] | Record<string, FlagValue>, options?: BuildBootstrapPayloadOptions): BootstrapPayload;
|
|
12
|
+
declare function serializeBootstrapPayload(payload: BootstrapPayload): string;
|
|
13
|
+
declare function deserializeBootstrapPayload(serializedPayload: string): BootstrapPayload | null;
|
|
14
|
+
/**
|
|
15
|
+
* Renders the payload as a JSON `<script>` tag for pages that can't pass props to the provider.
|
|
16
|
+
* Prefer the `bootstrapPayload` prop: only a prop is identical on the server and in the browser.
|
|
17
|
+
*/
|
|
18
|
+
declare function buildBootstrapScript(payload: BootstrapPayload, options?: BuildBootstrapScriptOptions): string;
|
|
19
|
+
declare function readBootstrapPayloadFromDocument(elementId?: string): BootstrapPayload | null;
|
|
20
|
+
declare function defaultsFromBootstrapPayload(payload: BootstrapPayload | null | undefined): DefaultsCollection | undefined;
|
|
21
|
+
declare function defaultsFromBootstrapDocument(elementId?: string): DefaultsCollection | undefined;
|
|
22
|
+
declare function contextFromBootstrapPayload(payload: BootstrapPayload | null | undefined): Context | undefined;
|
|
23
|
+
|
|
24
|
+
export { BootstrapPayload, BuildBootstrapPayloadOptions, BuildBootstrapScriptOptions, buildBootstrapPayload, buildBootstrapScript, contextFromBootstrapPayload, defaultsFromBootstrapDocument, defaultsFromBootstrapPayload, deserializeBootstrapPayload, readBootstrapPayloadFromDocument, serializeBootstrapPayload };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { B as BuildBootstrapPayloadOptions, a as BootstrapPayload, b as BuildBootstrapScriptOptions } from './types-CFBzBNpk.js';
|
|
2
|
+
export { c as BuildRequestContextOptions, D as DEFAULT_BOOTSTRAP_ELEMENT_ID, d as DEFAULT_SERVER_CACHE_TTL, M as MiddlewareFlagInput, N as NextFlagsRuntime, e as NextZenmanageClientOptions, R as RequestCookiesLike, f as RequestGeoLike, g as RequestLike, S as ServerBootstrapInput, h as ServerFlagInput, i as ServerFlagsInput, W as WidenFlagValue } from './types-CFBzBNpk.js';
|
|
3
|
+
import { Flag, FlagValue, Context, DefaultsCollection } from '@zenmanage/sdk';
|
|
4
|
+
export { clearServerClients, createServerClient, createServerManager, createServerRuntime, getBootstrapPayload, getFlagValue, getServerFlag, getServerFlags, mergeDefaults, preloadServerFlags } from './server.js';
|
|
5
|
+
export { buildContextFromRequest, evaluateMiddlewareFlag } from './middleware.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Builds the payload `NextFlagsProvider` reads. Accepts the flags straight from
|
|
9
|
+
* `getServerFlags`, or a plain `{ key: value }` record.
|
|
10
|
+
*/
|
|
11
|
+
declare function buildBootstrapPayload(flags: Flag[] | Record<string, FlagValue>, options?: BuildBootstrapPayloadOptions): BootstrapPayload;
|
|
12
|
+
declare function serializeBootstrapPayload(payload: BootstrapPayload): string;
|
|
13
|
+
declare function deserializeBootstrapPayload(serializedPayload: string): BootstrapPayload | null;
|
|
14
|
+
/**
|
|
15
|
+
* Renders the payload as a JSON `<script>` tag for pages that can't pass props to the provider.
|
|
16
|
+
* Prefer the `bootstrapPayload` prop: only a prop is identical on the server and in the browser.
|
|
17
|
+
*/
|
|
18
|
+
declare function buildBootstrapScript(payload: BootstrapPayload, options?: BuildBootstrapScriptOptions): string;
|
|
19
|
+
declare function readBootstrapPayloadFromDocument(elementId?: string): BootstrapPayload | null;
|
|
20
|
+
declare function defaultsFromBootstrapPayload(payload: BootstrapPayload | null | undefined): DefaultsCollection | undefined;
|
|
21
|
+
declare function defaultsFromBootstrapDocument(elementId?: string): DefaultsCollection | undefined;
|
|
22
|
+
declare function contextFromBootstrapPayload(payload: BootstrapPayload | null | undefined): Context | undefined;
|
|
23
|
+
|
|
24
|
+
export { BootstrapPayload, BuildBootstrapPayloadOptions, BuildBootstrapScriptOptions, buildBootstrapPayload, buildBootstrapScript, contextFromBootstrapPayload, defaultsFromBootstrapDocument, defaultsFromBootstrapPayload, deserializeBootstrapPayload, readBootstrapPayloadFromDocument, serializeBootstrapPayload };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildContextFromRequest,
|
|
3
|
+
evaluateMiddlewareFlag
|
|
4
|
+
} from "./chunk-HDORXS72.js";
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_BOOTSTRAP_ELEMENT_ID,
|
|
7
|
+
DEFAULT_SERVER_CACHE_TTL,
|
|
8
|
+
buildBootstrapPayload,
|
|
9
|
+
buildBootstrapScript,
|
|
10
|
+
clearServerClients,
|
|
11
|
+
contextFromBootstrapPayload,
|
|
12
|
+
createServerClient,
|
|
13
|
+
createServerManager,
|
|
14
|
+
createServerRuntime,
|
|
15
|
+
defaultsFromBootstrapDocument,
|
|
16
|
+
defaultsFromBootstrapPayload,
|
|
17
|
+
deserializeBootstrapPayload,
|
|
18
|
+
getBootstrapPayload,
|
|
19
|
+
getFlagValue,
|
|
20
|
+
getServerFlag,
|
|
21
|
+
getServerFlags,
|
|
22
|
+
mergeDefaults,
|
|
23
|
+
preloadServerFlags,
|
|
24
|
+
readBootstrapPayloadFromDocument,
|
|
25
|
+
serializeBootstrapPayload
|
|
26
|
+
} from "./chunk-PHODKVFM.js";
|
|
27
|
+
export {
|
|
28
|
+
DEFAULT_BOOTSTRAP_ELEMENT_ID,
|
|
29
|
+
DEFAULT_SERVER_CACHE_TTL,
|
|
30
|
+
buildBootstrapPayload,
|
|
31
|
+
buildBootstrapScript,
|
|
32
|
+
buildContextFromRequest,
|
|
33
|
+
clearServerClients,
|
|
34
|
+
contextFromBootstrapPayload,
|
|
35
|
+
createServerClient,
|
|
36
|
+
createServerManager,
|
|
37
|
+
createServerRuntime,
|
|
38
|
+
defaultsFromBootstrapDocument,
|
|
39
|
+
defaultsFromBootstrapPayload,
|
|
40
|
+
deserializeBootstrapPayload,
|
|
41
|
+
evaluateMiddlewareFlag,
|
|
42
|
+
getBootstrapPayload,
|
|
43
|
+
getFlagValue,
|
|
44
|
+
getServerFlag,
|
|
45
|
+
getServerFlags,
|
|
46
|
+
mergeDefaults,
|
|
47
|
+
preloadServerFlags,
|
|
48
|
+
readBootstrapPayloadFromDocument,
|
|
49
|
+
serializeBootstrapPayload
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|