flagmint-js-sdk 2.2.1 → 2.2.2
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/README.md +1 -1
- package/dist/flagmint.cjs.js +140 -21
- package/dist/flagmint.cjs.js.map +1 -1
- package/dist/flagmint.es.js +140 -21
- package/dist/flagmint.es.js.map +1 -1
- package/dist/flagmint.umd.js +140 -21
- package/dist/flagmint.umd.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/sdk/core/config-sync/evaluateSdkFlag.d.ts +24 -1
- package/dist/sdk/core/config-sync/index.d.ts +4 -2
- package/dist/sdk/core/config-sync/piiHash.d.ts +87 -0
- package/dist/sdk/core/config-sync/rulesStore.d.ts +3 -0
- package/dist/sdk/core/config-sync/types.d.ts +12 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -12,5 +12,5 @@ export { evaluateFlagValue } from './sdk/core/evaluation/evaluateFlagValue';
|
|
|
12
12
|
export { evaluateRollout } from './sdk/core/evaluation/evaluateRollout';
|
|
13
13
|
export { isInSegment } from './sdk/core/evaluation/isInSegment';
|
|
14
14
|
export * from './sdk/core/evaluation/rolloutUtils';
|
|
15
|
-
export { RulesStore, createEmptyRulesState, reduceRules, performAslHandshake, generateAslClientKeyPair, deriveAslMacKey, signConfigPayload, verifyConfigPayloadSignature, canonicalizeForSigning, isConfigPayloadExpired, evaluateSdkFlag, evaluateAllSdkFlags, coerceType, evaluateRule, evaluateFlagWithTargetingRules, applyRolloutStrategy, computeCurrentPercentage, defaultHash, flattenEvaluationContext, stringHash, hashPercent, } from './sdk/core/config-sync';
|
|
16
|
-
export type { SdkFlagConfig, SdkSegment, RulesState, RulesCacheSnapshot, ConfigSyncPayload, LeasePayload, FullConfigPayload, DeltaConfigPayload, DeltasCatchUpPayload, ApplyResult, AslHandshakeSuccess, } from './sdk/core/config-sync';
|
|
15
|
+
export { RulesStore, createEmptyRulesState, reduceRules, performAslHandshake, generateAslClientKeyPair, deriveAslMacKey, signConfigPayload, verifyConfigPayloadSignature, canonicalizeForSigning, isConfigPayloadExpired, evaluateSdkFlag, evaluateAllSdkFlags, coerceType, evaluateRule, evaluateFlagWithTargetingRules, applyRolloutStrategy, computeCurrentPercentage, defaultHash, flattenEvaluationContext, prepareContextForLocalEval, hashPiiValue, applyPiiHashToFlatContext, stringHash, hashPercent, } from './sdk/core/config-sync';
|
|
16
|
+
export type { SdkFlagConfig, SdkSegment, RulesState, RulesCacheSnapshot, ConfigSyncPayload, LeasePayload, FullConfigPayload, DeltaConfigPayload, DeltasCatchUpPayload, ApplyResult, AslHandshakeSuccess, PiiWireOptions, } from './sdk/core/config-sync';
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* using the ported `flagEvaluator` (spec = utils/flag-evaluator.ts).
|
|
4
4
|
*/
|
|
5
5
|
import { type FlagEvaluationResult } from './flagEvaluator';
|
|
6
|
+
import { type PiiWireOptions } from './piiHash';
|
|
6
7
|
import type { SdkFlagConfig, SdkSegment } from './types';
|
|
7
8
|
/** ES2018-safe Map → record (avoids Object.fromEntries / ES2019 lib). */
|
|
8
9
|
export declare function mapToRecord<V>(map: Map<string, V>): Record<string, V>;
|
|
@@ -16,11 +17,33 @@ export declare function mapToRecord<V>(map: Map<string, V>): Record<string, V>;
|
|
|
16
17
|
* and organization is not dropped.
|
|
17
18
|
*/
|
|
18
19
|
export declare function prepareContextForEvaluator(context: Record<string, unknown> | null | undefined): Record<string, unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* Flatten prepared context, then hash PII fields so they match hashed rule
|
|
22
|
+
* values on the config-sync wire (FF-EU Phase B / SDK Phase C).
|
|
23
|
+
*
|
|
24
|
+
* @param context Evaluation or flat context
|
|
25
|
+
* @param pii PII wire options from the rules store (null/undefined = no-op)
|
|
26
|
+
*/
|
|
27
|
+
export declare function prepareContextForLocalEval(context: Record<string, unknown> | null | undefined, pii?: PiiWireOptions | null): Record<string, unknown>;
|
|
19
28
|
/**
|
|
20
29
|
* Evaluate one SdkFlagConfig against context (server RuleEngine order).
|
|
30
|
+
*
|
|
31
|
+
* @param flag Compiled flag config
|
|
32
|
+
* @param context Evaluation context (plaintext PII is hashed when `pii` is set)
|
|
33
|
+
* @param segments Segment map for segment rules
|
|
34
|
+
* @param pii Optional PII wire options from the signed config
|
|
35
|
+
*/
|
|
36
|
+
export declare function evaluateSdkFlag(flag: SdkFlagConfig, context: Record<string, unknown>, segments: Map<string, SdkSegment> | Record<string, SdkSegment>, pii?: PiiWireOptions | null): FlagEvaluationResult;
|
|
37
|
+
/**
|
|
38
|
+
* Evaluate every flag in a map/list against one context.
|
|
39
|
+
*
|
|
40
|
+
* @param flags Flag configs
|
|
41
|
+
* @param context Shared evaluation context
|
|
42
|
+
* @param segments Segment map
|
|
43
|
+
* @param options Fail-closed and PII wire options
|
|
21
44
|
*/
|
|
22
|
-
export declare function evaluateSdkFlag(flag: SdkFlagConfig, context: Record<string, unknown>, segments: Map<string, SdkSegment> | Record<string, SdkSegment>): FlagEvaluationResult;
|
|
23
45
|
export declare function evaluateAllSdkFlags<T = unknown>(flags: Map<string, SdkFlagConfig> | SdkFlagConfig[], context: Record<string, unknown>, segments: Map<string, SdkSegment> | Record<string, SdkSegment>, options?: {
|
|
24
46
|
failClosedDefaultsOnly?: boolean;
|
|
47
|
+
pii?: PiiWireOptions | null;
|
|
25
48
|
}): Record<string, T>;
|
|
26
49
|
export { coerceType } from './flagEvaluator';
|
|
@@ -3,10 +3,12 @@ export type { AslClientKeyPair, AslDerivedMac } from './aslEcdh';
|
|
|
3
3
|
export { canonicalizeForSigning, isConfigPayloadExpired, signConfigPayload, verifyConfigPayloadSignature, } from './signPayload';
|
|
4
4
|
export { RulesStore, createEmptyRulesState, reduceRules, } from './rulesStore';
|
|
5
5
|
export type { ApplyResult, RulesState } from './rulesStore';
|
|
6
|
-
export type { ConfigSyncPayload, DeltaConfigPayload, DeltasCatchUpPayload, FullConfigPayload, LeasePayload, RulesCacheSnapshot, SdkFlagConfig, SdkSegment, SignableConfigBody, } from './types';
|
|
6
|
+
export type { ConfigSyncPayload, DeltaConfigPayload, DeltasCatchUpPayload, FullConfigPayload, LeasePayload, PiiWireMetadata, RulesCacheSnapshot, SdkFlagConfig, SdkSegment, SignableConfigBody, } from './types';
|
|
7
7
|
export { performAslHandshake } from './handshake';
|
|
8
8
|
export type { AslHandshakeSuccess } from './handshake';
|
|
9
|
-
export { evaluateSdkFlag, evaluateAllSdkFlags, coerceType, prepareContextForEvaluator, mapToRecord, } from './evaluateSdkFlag';
|
|
9
|
+
export { evaluateSdkFlag, evaluateAllSdkFlags, coerceType, prepareContextForEvaluator, prepareContextForLocalEval, mapToRecord, } from './evaluateSdkFlag';
|
|
10
|
+
export { PII_VALUE_ENCODING, normalizePiiString, hashPiiValue, isPiiAttribute, payloadHasExplicitPiiFields, piiWireOptionsFromPayload, resolvePiiWireForDelta, applyPiiHashToFlatContext, } from './piiHash';
|
|
11
|
+
export type { PiiWireOptions, ApplyPiiHashMode } from './piiHash';
|
|
10
12
|
export { evaluateRule, evaluateKillSwitch, evaluateOnVariation, evaluateFlagWithTargetingRules, applyRolloutStrategy, applyPercentageRollout, applyVariantRollout, applyGradualRollout, computeCurrentPercentage, defaultHash, getContextAttribute, } from './flagEvaluator';
|
|
11
13
|
export type { ExpectedFlagType, FlagEvaluationResult, Condition, TargetingRule, Rollout, Variation, Segment, EvaluationDeps, } from './flagEvaluator';
|
|
12
14
|
export { flattenContext, flattenEvaluationContext } from './flattenContext';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/** Must match FF-EU `PII_VALUE_ENCODING`. */
|
|
2
|
+
export declare const PII_VALUE_ENCODING: "hmac-v1";
|
|
3
|
+
/**
|
|
4
|
+
* Client PII wire options from signed `fullConfig` / `delta`.
|
|
5
|
+
*/
|
|
6
|
+
export type PiiWireOptions = {
|
|
7
|
+
piiAttributes: string[];
|
|
8
|
+
piiSalt: string;
|
|
9
|
+
piiValueEncoding?: typeof PII_VALUE_ENCODING | string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Extra apply options. Prefer plaintext context; only set `alreadyHashed`
|
|
13
|
+
* when callers intentionally supply wire digests (do not infer from hex shape).
|
|
14
|
+
*/
|
|
15
|
+
export type ApplyPiiHashMode = {
|
|
16
|
+
/** When true, leave PII string fields unchanged (caller supplied digests). */
|
|
17
|
+
alreadyHashed?: boolean;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Normalize a string before PII hashing (trim + lowercase).
|
|
21
|
+
* Must match FF-EU `normalizePiiString`.
|
|
22
|
+
*
|
|
23
|
+
* @param value Raw attribute value
|
|
24
|
+
*/
|
|
25
|
+
export declare function normalizePiiString(value: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* HMAC-SHA256 hex digest of a normalized PII string.
|
|
28
|
+
* Must match FF-EU `hashPiiValue`.
|
|
29
|
+
*
|
|
30
|
+
* @param value Plaintext value
|
|
31
|
+
* @param salt Client-visible salt from the signed config
|
|
32
|
+
*/
|
|
33
|
+
export declare function hashPiiValue(value: string, salt: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Whether a context / rule attribute key is PII.
|
|
36
|
+
* Matches bare keys (`email`) and kind-prefixed forms (`user.email`).
|
|
37
|
+
*
|
|
38
|
+
* @param attribute Attribute key from context or rule
|
|
39
|
+
* @param piiAttributes Keys from signed config
|
|
40
|
+
*/
|
|
41
|
+
export declare function isPiiAttribute(attribute: string | undefined | null, piiAttributes: readonly string[]): boolean;
|
|
42
|
+
/** Payload fields that carry PII wire metadata. */
|
|
43
|
+
export type PiiWirePayloadFields = {
|
|
44
|
+
piiAttributes?: unknown;
|
|
45
|
+
piiSalt?: unknown;
|
|
46
|
+
piiValueEncoding?: unknown;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Whether a payload explicitly includes any PII wire field (vs omitting all).
|
|
50
|
+
* Used so deltas that omit PII metadata keep the previous options, while
|
|
51
|
+
* deltas that send unusable fields clear them.
|
|
52
|
+
*
|
|
53
|
+
* @param payload Signed fullConfig / delta fields
|
|
54
|
+
*/
|
|
55
|
+
export declare function payloadHasExplicitPiiFields(payload: PiiWirePayloadFields | null | undefined): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Parse PII wire options from a config-sync payload body.
|
|
58
|
+
*
|
|
59
|
+
* @param payload Signed fullConfig / delta fields
|
|
60
|
+
* @returns Options when salt + encoding are usable; otherwise null
|
|
61
|
+
*/
|
|
62
|
+
export declare function piiWireOptionsFromPayload(payload: PiiWirePayloadFields | null | undefined): PiiWireOptions | null;
|
|
63
|
+
/**
|
|
64
|
+
* Resolve PII wire options for a delta: keep prior when all PII fields are
|
|
65
|
+
* absent; otherwise parse after merging omitted fields from `previous`.
|
|
66
|
+
*
|
|
67
|
+
* FF-EU `piiMetadata` always emits the full triple (or nothing). Merge is
|
|
68
|
+
* defensive so a salt-only / attrs-only delta cannot wipe the other fields.
|
|
69
|
+
* Explicit empty salt or unknown encoding still clears to null.
|
|
70
|
+
*
|
|
71
|
+
* @param previous Current store options
|
|
72
|
+
* @param action Delta (or similar) payload fields
|
|
73
|
+
*/
|
|
74
|
+
export declare function resolvePiiWireForDelta(previous: PiiWireOptions | null, action: PiiWirePayloadFields | null | undefined): PiiWireOptions | null;
|
|
75
|
+
/**
|
|
76
|
+
* Hash PII string fields on a flat evaluation context so they match hashed
|
|
77
|
+
* rule values on the wire.
|
|
78
|
+
*
|
|
79
|
+
* Always hashes plaintext strings (including values that look like 64-char hex).
|
|
80
|
+
* Pass `{ alreadyHashed: true }` only when the caller already supplied digests.
|
|
81
|
+
*
|
|
82
|
+
* @param context Flat context map (after prepare / flatten)
|
|
83
|
+
* @param options PII options from the rules store
|
|
84
|
+
* @param mode Optional apply mode (`alreadyHashed` skips hashing)
|
|
85
|
+
* @returns New context object with PII strings hashed (or the input if no-op)
|
|
86
|
+
*/
|
|
87
|
+
export declare function applyPiiHashToFlatContext(context: Record<string, unknown>, options: PiiWireOptions | null | undefined, mode?: ApplyPiiHashMode): Record<string, unknown>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PiiWireOptions } from './piiHash';
|
|
1
2
|
import type { ConfigSyncPayload, DeltaConfigPayload, DeltasCatchUpPayload, FullConfigPayload, LeasePayload, RulesCacheSnapshot, SdkFlagConfig, SdkSegment } from './types';
|
|
2
3
|
export type RulesState = {
|
|
3
4
|
version: number;
|
|
@@ -8,6 +9,8 @@ export type RulesState = {
|
|
|
8
9
|
ready: boolean;
|
|
9
10
|
/** Set when a delta's fromVersion does not match — reconnect with fullConfig. */
|
|
10
11
|
needsFullConfig: boolean;
|
|
12
|
+
/** PII hash options from the last fullConfig/delta (null when absent). */
|
|
13
|
+
piiWire: PiiWireOptions | null;
|
|
11
14
|
};
|
|
12
15
|
export type ApplyResult = {
|
|
13
16
|
ok: true;
|
|
@@ -33,6 +33,12 @@ export type LeasePayload = {
|
|
|
33
33
|
expiresAt: number;
|
|
34
34
|
signature: string;
|
|
35
35
|
};
|
|
36
|
+
/** PII hashing metadata on client-bound config (FF-EU Phase B). */
|
|
37
|
+
export type PiiWireMetadata = {
|
|
38
|
+
piiAttributes?: string[];
|
|
39
|
+
piiSalt?: string;
|
|
40
|
+
piiValueEncoding?: string;
|
|
41
|
+
};
|
|
36
42
|
export type FullConfigPayload = {
|
|
37
43
|
type: 'fullConfig';
|
|
38
44
|
version: number;
|
|
@@ -42,7 +48,7 @@ export type FullConfigPayload = {
|
|
|
42
48
|
segments: Record<string, SdkSegment>;
|
|
43
49
|
warnings?: string[];
|
|
44
50
|
signature: string;
|
|
45
|
-
};
|
|
51
|
+
} & PiiWireMetadata;
|
|
46
52
|
export type DeltaConfigPayload = {
|
|
47
53
|
type: 'delta';
|
|
48
54
|
fromVersion: number;
|
|
@@ -53,7 +59,7 @@ export type DeltaConfigPayload = {
|
|
|
53
59
|
deletes: string[];
|
|
54
60
|
segments: Record<string, SdkSegment>;
|
|
55
61
|
signature: string;
|
|
56
|
-
};
|
|
62
|
+
} & PiiWireMetadata;
|
|
57
63
|
export type DeltasCatchUpPayload = {
|
|
58
64
|
type: 'deltas';
|
|
59
65
|
fromVersion: number;
|
|
@@ -69,4 +75,8 @@ export type RulesCacheSnapshot = {
|
|
|
69
75
|
expiresAt: number;
|
|
70
76
|
flags: SdkFlagConfig[];
|
|
71
77
|
segments: Record<string, SdkSegment>;
|
|
78
|
+
/** PII wire options so offline hydrate still hashes context correctly. */
|
|
79
|
+
piiAttributes?: string[];
|
|
80
|
+
piiSalt?: string;
|
|
81
|
+
piiValueEncoding?: string;
|
|
72
82
|
};
|
package/package.json
CHANGED