@flagsync/nextjs-sdk 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +53 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -5
- package/dist/index.d.ts +16 -5
- package/dist/index.js +49 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -21,26 +21,54 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
SyncType: () => import_node_sdk2.SyncType,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
createIdentify: () => createIdentify
|
|
24
|
+
createAdapter: () => createAdapter,
|
|
25
|
+
createClient: () => createClient,
|
|
26
|
+
createIdentify: () => createIdentify,
|
|
27
|
+
createTypedFlag: () => createTypedFlag
|
|
27
28
|
});
|
|
28
29
|
module.exports = __toCommonJS(index_exports);
|
|
29
30
|
var import_node_sdk2 = require("@flagsync/node-sdk");
|
|
30
31
|
|
|
31
32
|
// src/adapter.ts
|
|
32
33
|
var import_node_sdk = require("@flagsync/node-sdk");
|
|
33
|
-
|
|
34
|
+
var import_next = require("flags/next");
|
|
35
|
+
function createClient(config) {
|
|
34
36
|
const instance = (0, import_node_sdk.FlagSyncFactory)({
|
|
35
37
|
...config,
|
|
36
38
|
metadata: {
|
|
37
39
|
sdkName: "@flagsync/nextjs-sdk",
|
|
38
|
-
sdkVersion: "0.
|
|
40
|
+
sdkVersion: "0.5.0"
|
|
39
41
|
}
|
|
40
42
|
});
|
|
41
43
|
return instance.client();
|
|
42
44
|
}
|
|
43
|
-
function
|
|
45
|
+
function createAdapter(client) {
|
|
46
|
+
let isReady = false;
|
|
47
|
+
const ensureReady = async () => {
|
|
48
|
+
if (!isReady) {
|
|
49
|
+
await client.waitForReady();
|
|
50
|
+
isReady = true;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
function adapter() {
|
|
54
|
+
return {
|
|
55
|
+
async decide({
|
|
56
|
+
key,
|
|
57
|
+
entities,
|
|
58
|
+
defaultValue
|
|
59
|
+
}) {
|
|
60
|
+
await ensureReady();
|
|
61
|
+
const userContext = {
|
|
62
|
+
key: "anonymous",
|
|
63
|
+
...entities ?? {}
|
|
64
|
+
};
|
|
65
|
+
return client.flag(userContext, key, defaultValue);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return adapter;
|
|
70
|
+
}
|
|
71
|
+
function createTypedAdapter(client) {
|
|
44
72
|
let isReady = false;
|
|
45
73
|
const ensureReady = async () => {
|
|
46
74
|
if (!isReady) {
|
|
@@ -66,14 +94,30 @@ function createFlagSyncAdapter(client) {
|
|
|
66
94
|
}
|
|
67
95
|
return flagSyncAdapter;
|
|
68
96
|
}
|
|
97
|
+
function createTypedFlag(client) {
|
|
98
|
+
const adapter = createTypedAdapter(client);
|
|
99
|
+
function typedFlag(options) {
|
|
100
|
+
const specificAdapter = adapter();
|
|
101
|
+
const fullFlagDeclaration = {
|
|
102
|
+
...options,
|
|
103
|
+
key: options.key,
|
|
104
|
+
adapter: specificAdapter
|
|
105
|
+
};
|
|
106
|
+
return (0, import_next.flag)(fullFlagDeclaration);
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
flag: typedFlag
|
|
110
|
+
};
|
|
111
|
+
}
|
|
69
112
|
|
|
70
113
|
// src/identify.ts
|
|
71
114
|
var createIdentify = (callback) => (params) => callback(params);
|
|
72
115
|
// Annotate the CommonJS export names for ESM import in node:
|
|
73
116
|
0 && (module.exports = {
|
|
74
117
|
SyncType,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
createIdentify
|
|
118
|
+
createAdapter,
|
|
119
|
+
createClient,
|
|
120
|
+
createIdentify,
|
|
121
|
+
createTypedFlag
|
|
78
122
|
});
|
|
79
123
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/adapter.ts","../src/identify.ts"],"sourcesContent":["export type {\n CustomAttributes,\n CustomAttributeValue,\n FsConfig,\n FsClient,\n LogLevel,\n FsUserContext,\n FeatureFlags,\n} from '@flagsync/node-sdk';\n\nexport { SyncType } from '@flagsync/node-sdk';\n\nexport type { JsonObject } from './types';\n\nexport {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/adapter.ts","../src/identify.ts"],"sourcesContent":["export type {\n CustomAttributes,\n CustomAttributeValue,\n FsConfig,\n FsClient,\n LogLevel,\n FsUserContext,\n FeatureFlags,\n} from '@flagsync/node-sdk';\n\nexport { SyncType } from '@flagsync/node-sdk';\n\nexport type { JsonObject } from './types';\n\nexport { createTypedFlag, createClient, createAdapter } from './adapter';\nexport { createIdentify } from './identify';\n","import {\n FeatureFlags,\n FlagReturnType,\n FlagSyncFactory,\n FsClient,\n type FsConfig,\n type FsUserContext,\n NoExplicitReturnType,\n} from '@flagsync/node-sdk';\nimport { Adapter, FlagDeclaration } from 'flags';\nimport { flag } from 'flags/next';\n\n/**\n * Creates a FlagSync client instance that can be used across multiple feature flags.\n * This function should be called once to create a singleton client for your application.\n */\nexport function createClient(config: FsConfig): FsClient {\n const instance = FlagSyncFactory({\n ...config,\n metadata: {\n sdkName: '@flagsync/nextjs-sdk',\n sdkVersion: '0.5.0',\n },\n });\n return instance.client();\n}\n\n/**\n * Creates an adapter factory that integrates FlagSync with Vercel's feature flag system.\n * This adapter handles the communication between your application and the FlagSync service.\n */\nexport function createAdapter(client: FsClient) {\n let isReady = false;\n\n /**\n * Ensures the FlagSync client is ready before making any flag decisions.\n * This is called internally before each flag evaluation.\n */\n const ensureReady = async () => {\n if (!isReady) {\n await client.waitForReady();\n isReady = true;\n }\n };\n\n function adapter<T = any>(): Adapter<\n FlagReturnType<T, string, FeatureFlags>,\n FsUserContext\n > {\n return {\n async decide({\n key,\n entities,\n defaultValue,\n }: {\n key: string;\n entities?: FsUserContext;\n defaultValue?: FlagReturnType<T, string, FeatureFlags>;\n }): Promise<FlagReturnType<T, string, FeatureFlags>> {\n await ensureReady();\n\n const userContext: FsUserContext = {\n key: 'anonymous',\n ...(entities ?? {}),\n };\n\n return client.flag(userContext, key, defaultValue);\n },\n };\n }\n\n return adapter;\n}\n\n/**\n * Creates an adapter factory that integrates FlagSync with Vercel's feature flag system.\n * This adapter handles the communication between your application and the FlagSync service.\n */\nfunction createTypedAdapter(client: FsClient) {\n let isReady = false;\n\n /**\n * Ensures the FlagSync client is ready before making any flag decisions.\n * This is called internally before each flag evaluation.\n */\n const ensureReady = async () => {\n if (!isReady) {\n await client.waitForReady();\n isReady = true;\n }\n };\n\n /**\n * Creates a generic adapter instance that works with any flag.\n * This function is generic over the expected return type (R) and the key type (K)\n * to correctly type the Adapter's `decide` method.\n *\n * @template R The explicit return type for the flag (e.g., `boolean`, `string`).\n * Defaults to `NoExplicitReturnType` if not provided.\n * @template K The literal string type of the flag key. Defaults to `string`.\n * @returns An `Adapter` instance with its generic `T` correctly set to `FlagReturnType<R, K, FeatureFlags>`.\n */\n function flagSyncAdapter<\n R = NoExplicitReturnType, // The explicit return type generic\n K extends string = string, // The key type generic\n >(): Adapter<FlagReturnType<R, K, FeatureFlags>, FsUserContext> {\n return {\n async decide({\n key,\n entities,\n defaultValue,\n }: {\n key: string; // The Adapter interface mandates 'string' here.\n entities?: FsUserContext;\n defaultValue?: FlagReturnType<R, K, FeatureFlags>;\n }): Promise<FlagReturnType<R, K, FeatureFlags>> {\n await ensureReady();\n\n const userContext: FsUserContext = {\n key: 'anonymous',\n ...(entities ?? {}),\n };\n\n // Call client.flag with the generics R and K.\n // We must cast 'key as K' because the Adapter's 'key' is 'string',\n // but client.flag's 'flagKey' parameter can be more restrictive (e.g., 'keyof FeatureFlags').\n // This means strict key validation for the 'key' parameter is bypassed at this point,\n // but the return type will still be correct.\n return client.flag<R, K>(userContext, key as K, defaultValue);\n },\n };\n }\n\n return flagSyncAdapter;\n}\n\n/**\n * Initializes the FlagSync typed helpers.\n * @param client An FsClient instance from createFlagSyncClient.\n * @returns An object containing the typed `flag` function.\n */\nexport function createTypedFlag(client: FsClient) {\n const adapter = createTypedAdapter(client);\n /**\n * A type-safe wrapper around Vercel's `flag` function that is\n * aware of your FeatureFlags interface.\n */\n function typedFlag<TKey extends keyof FeatureFlags>(\n options: Omit<\n FlagDeclaration<FeatureFlags[TKey], FsUserContext>,\n 'key' | 'adapter' | 'decide'\n > & {\n key: TKey;\n },\n ) {\n const specificAdapter = adapter<FeatureFlags[TKey], TKey>();\n\n const fullFlagDeclaration: FlagDeclaration<\n FeatureFlags[TKey],\n FsUserContext\n > = {\n ...options,\n key: options.key,\n adapter: specificAdapter as unknown as Adapter<\n FeatureFlags[TKey],\n FsUserContext\n >,\n };\n\n return flag(fullFlagDeclaration);\n }\n\n return {\n flag: typedFlag,\n };\n}\n","import { FsUserContext } from '@flagsync/node-sdk';\nimport { Identify } from 'flags';\n\ntype ExtractParams<T> = T extends (params: infer P) => any ? P : never;\n\nexport const createIdentify =\n (\n callback: (\n params: ExtractParams<Identify<FsUserContext>>,\n ) => Promise<FsUserContext> | FsUserContext,\n ): Identify<FsUserContext> =>\n (params) =>\n callback(params);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,IAAAA,mBAAyB;;;ACVzB,sBAQO;AAEP,kBAAqB;AAMd,SAAS,aAAa,QAA4B;AACvD,QAAM,eAAW,iCAAgB;AAAA,IAC/B,GAAG;AAAA,IACH,UAAU;AAAA,MACR,SAAS;AAAA,MACT,YAAY;AAAA,IACd;AAAA,EACF,CAAC;AACD,SAAO,SAAS,OAAO;AACzB;AAMO,SAAS,cAAc,QAAkB;AAC9C,MAAI,UAAU;AAMd,QAAM,cAAc,YAAY;AAC9B,QAAI,CAAC,SAAS;AACZ,YAAM,OAAO,aAAa;AAC1B,gBAAU;AAAA,IACZ;AAAA,EACF;AAEA,WAAS,UAGP;AACA,WAAO;AAAA,MACL,MAAM,OAAO;AAAA,QACX;AAAA,QACA;AAAA,QACA;AAAA,MACF,GAIqD;AACnD,cAAM,YAAY;AAElB,cAAM,cAA6B;AAAA,UACjC,KAAK;AAAA,UACL,GAAI,YAAY,CAAC;AAAA,QACnB;AAEA,eAAO,OAAO,KAAK,aAAa,KAAK,YAAY;AAAA,MACnD;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAMA,SAAS,mBAAmB,QAAkB;AAC5C,MAAI,UAAU;AAMd,QAAM,cAAc,YAAY;AAC9B,QAAI,CAAC,SAAS;AACZ,YAAM,OAAO,aAAa;AAC1B,gBAAU;AAAA,IACZ;AAAA,EACF;AAYA,WAAS,kBAGuD;AAC9D,WAAO;AAAA,MACL,MAAM,OAAO;AAAA,QACX;AAAA,QACA;AAAA,QACA;AAAA,MACF,GAIgD;AAC9C,cAAM,YAAY;AAElB,cAAM,cAA6B;AAAA,UACjC,KAAK;AAAA,UACL,GAAI,YAAY,CAAC;AAAA,QACnB;AAOA,eAAO,OAAO,KAAW,aAAa,KAAU,YAAY;AAAA,MAC9D;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAOO,SAAS,gBAAgB,QAAkB;AAChD,QAAM,UAAU,mBAAmB,MAAM;AAKzC,WAAS,UACP,SAMA;AACA,UAAM,kBAAkB,QAAkC;AAE1D,UAAM,sBAGF;AAAA,MACF,GAAG;AAAA,MACH,KAAK,QAAQ;AAAA,MACb,SAAS;AAAA,IAIX;AAEA,eAAO,kBAAK,mBAAmB;AAAA,EACjC;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,EACR;AACF;;;AC1KO,IAAM,iBACX,CACE,aAIF,CAAC,WACC,SAAS,MAAM;","names":["import_node_sdk"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FsClient, FeatureFlags, FsUserContext, FsConfig, FlagReturnType } from '@flagsync/node-sdk';
|
|
2
2
|
export { CustomAttributeValue, CustomAttributes, FeatureFlags, FsClient, FsConfig, FsUserContext, LogLevel, SyncType } from '@flagsync/node-sdk';
|
|
3
|
-
import
|
|
3
|
+
import * as flags_next from 'flags/next';
|
|
4
|
+
import { FlagDeclaration, Adapter, Identify } from 'flags';
|
|
4
5
|
|
|
5
6
|
type JsonPrimitive = string | number | boolean | null;
|
|
6
7
|
type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
@@ -13,14 +14,24 @@ interface JsonObject {
|
|
|
13
14
|
* Creates a FlagSync client instance that can be used across multiple feature flags.
|
|
14
15
|
* This function should be called once to create a singleton client for your application.
|
|
15
16
|
*/
|
|
16
|
-
declare function
|
|
17
|
+
declare function createClient(config: FsConfig): FsClient;
|
|
17
18
|
/**
|
|
18
19
|
* Creates an adapter factory that integrates FlagSync with Vercel's feature flag system.
|
|
19
20
|
* This adapter handles the communication between your application and the FlagSync service.
|
|
20
21
|
*/
|
|
21
|
-
declare function
|
|
22
|
+
declare function createAdapter(client: FsClient): <T = any>() => Adapter<FlagReturnType<T, string, FeatureFlags>, FsUserContext>;
|
|
23
|
+
/**
|
|
24
|
+
* Initializes the FlagSync typed helpers.
|
|
25
|
+
* @param client An FsClient instance from createFlagSyncClient.
|
|
26
|
+
* @returns An object containing the typed `flag` function.
|
|
27
|
+
*/
|
|
28
|
+
declare function createTypedFlag(client: FsClient): {
|
|
29
|
+
flag: <TKey extends keyof FeatureFlags>(options: Omit<FlagDeclaration<FeatureFlags[TKey], FsUserContext>, "key" | "adapter" | "decide"> & {
|
|
30
|
+
key: TKey;
|
|
31
|
+
}) => flags_next.Flag<FeatureFlags[TKey], FsUserContext>;
|
|
32
|
+
};
|
|
22
33
|
|
|
23
34
|
type ExtractParams<T> = T extends (params: infer P) => any ? P : never;
|
|
24
35
|
declare const createIdentify: (callback: (params: ExtractParams<Identify<FsUserContext>>) => Promise<FsUserContext> | FsUserContext) => Identify<FsUserContext>;
|
|
25
36
|
|
|
26
|
-
export { type JsonObject,
|
|
37
|
+
export { type JsonObject, createAdapter, createClient, createIdentify, createTypedFlag };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FsClient, FeatureFlags, FsUserContext, FsConfig, FlagReturnType } from '@flagsync/node-sdk';
|
|
2
2
|
export { CustomAttributeValue, CustomAttributes, FeatureFlags, FsClient, FsConfig, FsUserContext, LogLevel, SyncType } from '@flagsync/node-sdk';
|
|
3
|
-
import
|
|
3
|
+
import * as flags_next from 'flags/next';
|
|
4
|
+
import { FlagDeclaration, Adapter, Identify } from 'flags';
|
|
4
5
|
|
|
5
6
|
type JsonPrimitive = string | number | boolean | null;
|
|
6
7
|
type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
@@ -13,14 +14,24 @@ interface JsonObject {
|
|
|
13
14
|
* Creates a FlagSync client instance that can be used across multiple feature flags.
|
|
14
15
|
* This function should be called once to create a singleton client for your application.
|
|
15
16
|
*/
|
|
16
|
-
declare function
|
|
17
|
+
declare function createClient(config: FsConfig): FsClient;
|
|
17
18
|
/**
|
|
18
19
|
* Creates an adapter factory that integrates FlagSync with Vercel's feature flag system.
|
|
19
20
|
* This adapter handles the communication between your application and the FlagSync service.
|
|
20
21
|
*/
|
|
21
|
-
declare function
|
|
22
|
+
declare function createAdapter(client: FsClient): <T = any>() => Adapter<FlagReturnType<T, string, FeatureFlags>, FsUserContext>;
|
|
23
|
+
/**
|
|
24
|
+
* Initializes the FlagSync typed helpers.
|
|
25
|
+
* @param client An FsClient instance from createFlagSyncClient.
|
|
26
|
+
* @returns An object containing the typed `flag` function.
|
|
27
|
+
*/
|
|
28
|
+
declare function createTypedFlag(client: FsClient): {
|
|
29
|
+
flag: <TKey extends keyof FeatureFlags>(options: Omit<FlagDeclaration<FeatureFlags[TKey], FsUserContext>, "key" | "adapter" | "decide"> & {
|
|
30
|
+
key: TKey;
|
|
31
|
+
}) => flags_next.Flag<FeatureFlags[TKey], FsUserContext>;
|
|
32
|
+
};
|
|
22
33
|
|
|
23
34
|
type ExtractParams<T> = T extends (params: infer P) => any ? P : never;
|
|
24
35
|
declare const createIdentify: (callback: (params: ExtractParams<Identify<FsUserContext>>) => Promise<FsUserContext> | FsUserContext) => Identify<FsUserContext>;
|
|
25
36
|
|
|
26
|
-
export { type JsonObject,
|
|
37
|
+
export { type JsonObject, createAdapter, createClient, createIdentify, createTypedFlag };
|
package/dist/index.js
CHANGED
|
@@ -5,17 +5,44 @@ import { SyncType } from "@flagsync/node-sdk";
|
|
|
5
5
|
import {
|
|
6
6
|
FlagSyncFactory
|
|
7
7
|
} from "@flagsync/node-sdk";
|
|
8
|
-
|
|
8
|
+
import { flag } from "flags/next";
|
|
9
|
+
function createClient(config) {
|
|
9
10
|
const instance = FlagSyncFactory({
|
|
10
11
|
...config,
|
|
11
12
|
metadata: {
|
|
12
13
|
sdkName: "@flagsync/nextjs-sdk",
|
|
13
|
-
sdkVersion: "0.
|
|
14
|
+
sdkVersion: "0.5.0"
|
|
14
15
|
}
|
|
15
16
|
});
|
|
16
17
|
return instance.client();
|
|
17
18
|
}
|
|
18
|
-
function
|
|
19
|
+
function createAdapter(client) {
|
|
20
|
+
let isReady = false;
|
|
21
|
+
const ensureReady = async () => {
|
|
22
|
+
if (!isReady) {
|
|
23
|
+
await client.waitForReady();
|
|
24
|
+
isReady = true;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function adapter() {
|
|
28
|
+
return {
|
|
29
|
+
async decide({
|
|
30
|
+
key,
|
|
31
|
+
entities,
|
|
32
|
+
defaultValue
|
|
33
|
+
}) {
|
|
34
|
+
await ensureReady();
|
|
35
|
+
const userContext = {
|
|
36
|
+
key: "anonymous",
|
|
37
|
+
...entities ?? {}
|
|
38
|
+
};
|
|
39
|
+
return client.flag(userContext, key, defaultValue);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return adapter;
|
|
44
|
+
}
|
|
45
|
+
function createTypedAdapter(client) {
|
|
19
46
|
let isReady = false;
|
|
20
47
|
const ensureReady = async () => {
|
|
21
48
|
if (!isReady) {
|
|
@@ -41,13 +68,29 @@ function createFlagSyncAdapter(client) {
|
|
|
41
68
|
}
|
|
42
69
|
return flagSyncAdapter;
|
|
43
70
|
}
|
|
71
|
+
function createTypedFlag(client) {
|
|
72
|
+
const adapter = createTypedAdapter(client);
|
|
73
|
+
function typedFlag(options) {
|
|
74
|
+
const specificAdapter = adapter();
|
|
75
|
+
const fullFlagDeclaration = {
|
|
76
|
+
...options,
|
|
77
|
+
key: options.key,
|
|
78
|
+
adapter: specificAdapter
|
|
79
|
+
};
|
|
80
|
+
return flag(fullFlagDeclaration);
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
flag: typedFlag
|
|
84
|
+
};
|
|
85
|
+
}
|
|
44
86
|
|
|
45
87
|
// src/identify.ts
|
|
46
88
|
var createIdentify = (callback) => (params) => callback(params);
|
|
47
89
|
export {
|
|
48
90
|
SyncType,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
createIdentify
|
|
91
|
+
createAdapter,
|
|
92
|
+
createClient,
|
|
93
|
+
createIdentify,
|
|
94
|
+
createTypedFlag
|
|
52
95
|
};
|
|
53
96
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/adapter.ts","../src/identify.ts"],"sourcesContent":["export type {\n CustomAttributes,\n CustomAttributeValue,\n FsConfig,\n FsClient,\n LogLevel,\n FsUserContext,\n FeatureFlags,\n} from '@flagsync/node-sdk';\n\nexport { SyncType } from '@flagsync/node-sdk';\n\nexport type { JsonObject } from './types';\n\nexport {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/adapter.ts","../src/identify.ts"],"sourcesContent":["export type {\n CustomAttributes,\n CustomAttributeValue,\n FsConfig,\n FsClient,\n LogLevel,\n FsUserContext,\n FeatureFlags,\n} from '@flagsync/node-sdk';\n\nexport { SyncType } from '@flagsync/node-sdk';\n\nexport type { JsonObject } from './types';\n\nexport { createTypedFlag, createClient, createAdapter } from './adapter';\nexport { createIdentify } from './identify';\n","import {\n FeatureFlags,\n FlagReturnType,\n FlagSyncFactory,\n FsClient,\n type FsConfig,\n type FsUserContext,\n NoExplicitReturnType,\n} from '@flagsync/node-sdk';\nimport { Adapter, FlagDeclaration } from 'flags';\nimport { flag } from 'flags/next';\n\n/**\n * Creates a FlagSync client instance that can be used across multiple feature flags.\n * This function should be called once to create a singleton client for your application.\n */\nexport function createClient(config: FsConfig): FsClient {\n const instance = FlagSyncFactory({\n ...config,\n metadata: {\n sdkName: '@flagsync/nextjs-sdk',\n sdkVersion: '0.5.0',\n },\n });\n return instance.client();\n}\n\n/**\n * Creates an adapter factory that integrates FlagSync with Vercel's feature flag system.\n * This adapter handles the communication between your application and the FlagSync service.\n */\nexport function createAdapter(client: FsClient) {\n let isReady = false;\n\n /**\n * Ensures the FlagSync client is ready before making any flag decisions.\n * This is called internally before each flag evaluation.\n */\n const ensureReady = async () => {\n if (!isReady) {\n await client.waitForReady();\n isReady = true;\n }\n };\n\n function adapter<T = any>(): Adapter<\n FlagReturnType<T, string, FeatureFlags>,\n FsUserContext\n > {\n return {\n async decide({\n key,\n entities,\n defaultValue,\n }: {\n key: string;\n entities?: FsUserContext;\n defaultValue?: FlagReturnType<T, string, FeatureFlags>;\n }): Promise<FlagReturnType<T, string, FeatureFlags>> {\n await ensureReady();\n\n const userContext: FsUserContext = {\n key: 'anonymous',\n ...(entities ?? {}),\n };\n\n return client.flag(userContext, key, defaultValue);\n },\n };\n }\n\n return adapter;\n}\n\n/**\n * Creates an adapter factory that integrates FlagSync with Vercel's feature flag system.\n * This adapter handles the communication between your application and the FlagSync service.\n */\nfunction createTypedAdapter(client: FsClient) {\n let isReady = false;\n\n /**\n * Ensures the FlagSync client is ready before making any flag decisions.\n * This is called internally before each flag evaluation.\n */\n const ensureReady = async () => {\n if (!isReady) {\n await client.waitForReady();\n isReady = true;\n }\n };\n\n /**\n * Creates a generic adapter instance that works with any flag.\n * This function is generic over the expected return type (R) and the key type (K)\n * to correctly type the Adapter's `decide` method.\n *\n * @template R The explicit return type for the flag (e.g., `boolean`, `string`).\n * Defaults to `NoExplicitReturnType` if not provided.\n * @template K The literal string type of the flag key. Defaults to `string`.\n * @returns An `Adapter` instance with its generic `T` correctly set to `FlagReturnType<R, K, FeatureFlags>`.\n */\n function flagSyncAdapter<\n R = NoExplicitReturnType, // The explicit return type generic\n K extends string = string, // The key type generic\n >(): Adapter<FlagReturnType<R, K, FeatureFlags>, FsUserContext> {\n return {\n async decide({\n key,\n entities,\n defaultValue,\n }: {\n key: string; // The Adapter interface mandates 'string' here.\n entities?: FsUserContext;\n defaultValue?: FlagReturnType<R, K, FeatureFlags>;\n }): Promise<FlagReturnType<R, K, FeatureFlags>> {\n await ensureReady();\n\n const userContext: FsUserContext = {\n key: 'anonymous',\n ...(entities ?? {}),\n };\n\n // Call client.flag with the generics R and K.\n // We must cast 'key as K' because the Adapter's 'key' is 'string',\n // but client.flag's 'flagKey' parameter can be more restrictive (e.g., 'keyof FeatureFlags').\n // This means strict key validation for the 'key' parameter is bypassed at this point,\n // but the return type will still be correct.\n return client.flag<R, K>(userContext, key as K, defaultValue);\n },\n };\n }\n\n return flagSyncAdapter;\n}\n\n/**\n * Initializes the FlagSync typed helpers.\n * @param client An FsClient instance from createFlagSyncClient.\n * @returns An object containing the typed `flag` function.\n */\nexport function createTypedFlag(client: FsClient) {\n const adapter = createTypedAdapter(client);\n /**\n * A type-safe wrapper around Vercel's `flag` function that is\n * aware of your FeatureFlags interface.\n */\n function typedFlag<TKey extends keyof FeatureFlags>(\n options: Omit<\n FlagDeclaration<FeatureFlags[TKey], FsUserContext>,\n 'key' | 'adapter' | 'decide'\n > & {\n key: TKey;\n },\n ) {\n const specificAdapter = adapter<FeatureFlags[TKey], TKey>();\n\n const fullFlagDeclaration: FlagDeclaration<\n FeatureFlags[TKey],\n FsUserContext\n > = {\n ...options,\n key: options.key,\n adapter: specificAdapter as unknown as Adapter<\n FeatureFlags[TKey],\n FsUserContext\n >,\n };\n\n return flag(fullFlagDeclaration);\n }\n\n return {\n flag: typedFlag,\n };\n}\n","import { FsUserContext } from '@flagsync/node-sdk';\nimport { Identify } from 'flags';\n\ntype ExtractParams<T> = T extends (params: infer P) => any ? P : never;\n\nexport const createIdentify =\n (\n callback: (\n params: ExtractParams<Identify<FsUserContext>>,\n ) => Promise<FsUserContext> | FsUserContext,\n ): Identify<FsUserContext> =>\n (params) =>\n callback(params);\n"],"mappings":";AAUA,SAAS,gBAAgB;;;ACVzB;AAAA,EAGE;AAAA,OAKK;AAEP,SAAS,YAAY;AAMd,SAAS,aAAa,QAA4B;AACvD,QAAM,WAAW,gBAAgB;AAAA,IAC/B,GAAG;AAAA,IACH,UAAU;AAAA,MACR,SAAS;AAAA,MACT,YAAY;AAAA,IACd;AAAA,EACF,CAAC;AACD,SAAO,SAAS,OAAO;AACzB;AAMO,SAAS,cAAc,QAAkB;AAC9C,MAAI,UAAU;AAMd,QAAM,cAAc,YAAY;AAC9B,QAAI,CAAC,SAAS;AACZ,YAAM,OAAO,aAAa;AAC1B,gBAAU;AAAA,IACZ;AAAA,EACF;AAEA,WAAS,UAGP;AACA,WAAO;AAAA,MACL,MAAM,OAAO;AAAA,QACX;AAAA,QACA;AAAA,QACA;AAAA,MACF,GAIqD;AACnD,cAAM,YAAY;AAElB,cAAM,cAA6B;AAAA,UACjC,KAAK;AAAA,UACL,GAAI,YAAY,CAAC;AAAA,QACnB;AAEA,eAAO,OAAO,KAAK,aAAa,KAAK,YAAY;AAAA,MACnD;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAMA,SAAS,mBAAmB,QAAkB;AAC5C,MAAI,UAAU;AAMd,QAAM,cAAc,YAAY;AAC9B,QAAI,CAAC,SAAS;AACZ,YAAM,OAAO,aAAa;AAC1B,gBAAU;AAAA,IACZ;AAAA,EACF;AAYA,WAAS,kBAGuD;AAC9D,WAAO;AAAA,MACL,MAAM,OAAO;AAAA,QACX;AAAA,QACA;AAAA,QACA;AAAA,MACF,GAIgD;AAC9C,cAAM,YAAY;AAElB,cAAM,cAA6B;AAAA,UACjC,KAAK;AAAA,UACL,GAAI,YAAY,CAAC;AAAA,QACnB;AAOA,eAAO,OAAO,KAAW,aAAa,KAAU,YAAY;AAAA,MAC9D;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAOO,SAAS,gBAAgB,QAAkB;AAChD,QAAM,UAAU,mBAAmB,MAAM;AAKzC,WAAS,UACP,SAMA;AACA,UAAM,kBAAkB,QAAkC;AAE1D,UAAM,sBAGF;AAAA,MACF,GAAG;AAAA,MACH,KAAK,QAAQ;AAAA,MACb,SAAS;AAAA,IAIX;AAEA,WAAO,KAAK,mBAAmB;AAAA,EACjC;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,EACR;AACF;;;AC1KO,IAAM,iBACX,CACE,aAIF,CAAC,WACC,SAAS,MAAM;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flagsync/nextjs-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "FlagSync adapter for Vercel's Flags SDK",
|
|
5
5
|
"author": "Mike Chabot",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"flags": "^4.0.1"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@flagsync/node-sdk": "
|
|
42
|
+
"@flagsync/node-sdk": "0.7.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@trivago/prettier-plugin-sort-imports": "^5.2.2",
|