@schematichq/schematic-react 1.2.21 → 1.3.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/schematic-react.cjs.js +116 -37
- package/dist/schematic-react.d.ts +9 -0
- package/dist/schematic-react.esm.js +116 -37
- package/package.json +13 -8
|
@@ -39,7 +39,8 @@ __export(index_exports, {
|
|
|
39
39
|
useSchematicEntitlement: () => useSchematicEntitlement,
|
|
40
40
|
useSchematicEvents: () => useSchematicEvents,
|
|
41
41
|
useSchematicFlag: () => useSchematicFlag,
|
|
42
|
-
useSchematicIsPending: () => useSchematicIsPending
|
|
42
|
+
useSchematicIsPending: () => useSchematicIsPending,
|
|
43
|
+
useSchematicPlan: () => useSchematicPlan
|
|
43
44
|
});
|
|
44
45
|
module.exports = __toCommonJS(index_exports);
|
|
45
46
|
|
|
@@ -706,26 +707,6 @@ function CheckFlagResponseDataFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
706
707
|
value: json["value"]
|
|
707
708
|
};
|
|
708
709
|
}
|
|
709
|
-
function EventBodyFlagCheckToJSON(json) {
|
|
710
|
-
return EventBodyFlagCheckToJSONTyped(json, false);
|
|
711
|
-
}
|
|
712
|
-
function EventBodyFlagCheckToJSONTyped(value, ignoreDiscriminator = false) {
|
|
713
|
-
if (value == null) {
|
|
714
|
-
return value;
|
|
715
|
-
}
|
|
716
|
-
return {
|
|
717
|
-
company_id: value["companyId"],
|
|
718
|
-
error: value["error"],
|
|
719
|
-
flag_id: value["flagId"],
|
|
720
|
-
flag_key: value["flagKey"],
|
|
721
|
-
reason: value["reason"],
|
|
722
|
-
req_company: value["reqCompany"],
|
|
723
|
-
req_user: value["reqUser"],
|
|
724
|
-
rule_id: value["ruleId"],
|
|
725
|
-
user_id: value["userId"],
|
|
726
|
-
value: value["value"]
|
|
727
|
-
};
|
|
728
|
-
}
|
|
729
710
|
function CheckFlagResponseFromJSON(json) {
|
|
730
711
|
return CheckFlagResponseFromJSONTyped(json, false);
|
|
731
712
|
}
|
|
@@ -738,6 +719,19 @@ function CheckFlagResponseFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
738
719
|
params: json["params"]
|
|
739
720
|
};
|
|
740
721
|
}
|
|
722
|
+
function DatastreamCompanyPlanFromJSON(json) {
|
|
723
|
+
return DatastreamCompanyPlanFromJSONTyped(json, false);
|
|
724
|
+
}
|
|
725
|
+
function DatastreamCompanyPlanFromJSONTyped(json, ignoreDiscriminator) {
|
|
726
|
+
if (json == null) {
|
|
727
|
+
return json;
|
|
728
|
+
}
|
|
729
|
+
return {
|
|
730
|
+
id: json["id"],
|
|
731
|
+
name: json["name"],
|
|
732
|
+
trialEndDate: json["trial_end_date"] == null ? void 0 : new Date(json["trial_end_date"])
|
|
733
|
+
};
|
|
734
|
+
}
|
|
741
735
|
function CheckFlagsResponseDataFromJSON(json) {
|
|
742
736
|
return CheckFlagsResponseDataFromJSONTyped(json, false);
|
|
743
737
|
}
|
|
@@ -746,7 +740,8 @@ function CheckFlagsResponseDataFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
746
740
|
return json;
|
|
747
741
|
}
|
|
748
742
|
return {
|
|
749
|
-
flags: json["flags"].map(CheckFlagResponseDataFromJSON)
|
|
743
|
+
flags: json["flags"].map(CheckFlagResponseDataFromJSON),
|
|
744
|
+
plan: json["plan"] == null ? void 0 : DatastreamCompanyPlanFromJSON(json["plan"])
|
|
750
745
|
};
|
|
751
746
|
}
|
|
752
747
|
function CheckFlagsResponseFromJSON(json) {
|
|
@@ -761,6 +756,26 @@ function CheckFlagsResponseFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
761
756
|
params: json["params"]
|
|
762
757
|
};
|
|
763
758
|
}
|
|
759
|
+
function EventBodyFlagCheckToJSON(json) {
|
|
760
|
+
return EventBodyFlagCheckToJSONTyped(json, false);
|
|
761
|
+
}
|
|
762
|
+
function EventBodyFlagCheckToJSONTyped(value, ignoreDiscriminator = false) {
|
|
763
|
+
if (value == null) {
|
|
764
|
+
return value;
|
|
765
|
+
}
|
|
766
|
+
return {
|
|
767
|
+
company_id: value["companyId"],
|
|
768
|
+
error: value["error"],
|
|
769
|
+
flag_id: value["flagId"],
|
|
770
|
+
flag_key: value["flagKey"],
|
|
771
|
+
reason: value["reason"],
|
|
772
|
+
req_company: value["reqCompany"],
|
|
773
|
+
req_user: value["reqUser"],
|
|
774
|
+
rule_id: value["ruleId"],
|
|
775
|
+
user_id: value["userId"],
|
|
776
|
+
value: value["value"]
|
|
777
|
+
};
|
|
778
|
+
}
|
|
764
779
|
var RuleType = /* @__PURE__ */ ((RuleType2) => {
|
|
765
780
|
RuleType2["GLOBAL_OVERRIDE"] = "global_override";
|
|
766
781
|
RuleType2["COMPANY_OVERRIDE"] = "company_override";
|
|
@@ -816,6 +831,14 @@ var CheckFlagReturnFromJSON = (json) => {
|
|
|
816
831
|
value
|
|
817
832
|
};
|
|
818
833
|
};
|
|
834
|
+
var CheckPlanReturnFromJSON = (json) => {
|
|
835
|
+
const { id, name, trialEndDate } = DatastreamCompanyPlanFromJSON(json);
|
|
836
|
+
return {
|
|
837
|
+
id,
|
|
838
|
+
name,
|
|
839
|
+
trialEndDate: trialEndDate == null ? void 0 : trialEndDate
|
|
840
|
+
};
|
|
841
|
+
};
|
|
819
842
|
function contextString(context) {
|
|
820
843
|
const sortedContext = Object.keys(context).reduce((acc, key) => {
|
|
821
844
|
const sortedKeys = Object.keys(
|
|
@@ -830,7 +853,7 @@ function contextString(context) {
|
|
|
830
853
|
}, {});
|
|
831
854
|
return JSON.stringify(sortedContext);
|
|
832
855
|
}
|
|
833
|
-
var version = "1.
|
|
856
|
+
var version = "1.3.0";
|
|
834
857
|
var anonymousIdKey = "schematicId";
|
|
835
858
|
var Schematic = class {
|
|
836
859
|
additionalHeaders = {};
|
|
@@ -847,10 +870,12 @@ var Schematic = class {
|
|
|
847
870
|
flagValueListeners = {};
|
|
848
871
|
isPending = true;
|
|
849
872
|
isPendingListeners = /* @__PURE__ */ new Set();
|
|
873
|
+
planListeners = /* @__PURE__ */ new Set();
|
|
850
874
|
storage;
|
|
851
875
|
useWebSocket = false;
|
|
852
876
|
checks = {};
|
|
853
877
|
featureUsageEventMap = {};
|
|
878
|
+
planChecks = {};
|
|
854
879
|
webSocketUrl = "wss://api.schematichq.com";
|
|
855
880
|
webSocketConnectionTimeout = 1e4;
|
|
856
881
|
webSocketReconnect = true;
|
|
@@ -1183,28 +1208,32 @@ var Schematic = class {
|
|
|
1183
1208
|
this.checks[contextStr] = {};
|
|
1184
1209
|
}
|
|
1185
1210
|
this.checks[contextStr][flagCheck.flag] = flagCheck;
|
|
1186
|
-
this.debug(`WebSocket flag update:`, {
|
|
1187
|
-
flag: flagCheck.flag,
|
|
1188
|
-
value: flagCheck.value,
|
|
1189
|
-
flagCheck
|
|
1190
|
-
});
|
|
1191
1211
|
if (typeof flagCheck.featureUsageEvent === "string") {
|
|
1192
1212
|
this.updateFeatureUsageEventMap(flagCheck);
|
|
1193
1213
|
}
|
|
1194
1214
|
if ((this.flagCheckListeners[flag.flag]?.size ?? 0) > 0 || (this.flagValueListeners[flag.flag]?.size ?? 0) > 0) {
|
|
1195
1215
|
this.submitFlagCheckEvent(flagCheck.flag, flagCheck, context);
|
|
1196
1216
|
}
|
|
1197
|
-
this.debug(
|
|
1198
|
-
flag
|
|
1199
|
-
|
|
1200
|
-
|
|
1217
|
+
this.debug(
|
|
1218
|
+
`WebSocket flag update received. Notifying listeners for ${flag.flag}`,
|
|
1219
|
+
{
|
|
1220
|
+
flag: flag.flag,
|
|
1221
|
+
value: flagCheck.value,
|
|
1222
|
+
flagCheck
|
|
1223
|
+
}
|
|
1224
|
+
);
|
|
1201
1225
|
this.notifyFlagCheckListeners(flag.flag, flagCheck);
|
|
1202
1226
|
this.notifyFlagValueListeners(flag.flag, flagCheck.value);
|
|
1203
|
-
this.debug(`Finished notifying listeners for flag ${flag.flag}`, {
|
|
1204
|
-
flag: flag.flag,
|
|
1205
|
-
value: flagCheck.value
|
|
1206
|
-
});
|
|
1207
1227
|
});
|
|
1228
|
+
if (message.plan !== void 0 && message.plan !== null) {
|
|
1229
|
+
const plan = CheckPlanReturnFromJSON(message.plan);
|
|
1230
|
+
const contextStr = contextString(context);
|
|
1231
|
+
this.planChecks[contextStr] = plan;
|
|
1232
|
+
this.debug(`WebSocket plan update received. Notifying listeners`, {
|
|
1233
|
+
plan
|
|
1234
|
+
});
|
|
1235
|
+
this.notifyPlanListeners(plan);
|
|
1236
|
+
}
|
|
1208
1237
|
this.flushContextDependentEventQueue();
|
|
1209
1238
|
this.setIsPending(false);
|
|
1210
1239
|
};
|
|
@@ -2100,6 +2129,11 @@ var Schematic = class {
|
|
|
2100
2129
|
(listener) => notifyPendingListener(listener, isPending)
|
|
2101
2130
|
);
|
|
2102
2131
|
};
|
|
2132
|
+
getPlan = () => {
|
|
2133
|
+
const contextStr = contextString(this.context);
|
|
2134
|
+
const plan = this.planChecks[contextStr];
|
|
2135
|
+
return plan;
|
|
2136
|
+
};
|
|
2103
2137
|
// flag checks state
|
|
2104
2138
|
getFlagCheck = (flagKey) => {
|
|
2105
2139
|
const contextStr = contextString(this.context);
|
|
@@ -2153,6 +2187,12 @@ var Schematic = class {
|
|
|
2153
2187
|
this.flagCheckListeners[flagKey].delete(listener);
|
|
2154
2188
|
};
|
|
2155
2189
|
};
|
|
2190
|
+
addPlanListener = (listener) => {
|
|
2191
|
+
this.planListeners.add(listener);
|
|
2192
|
+
return () => {
|
|
2193
|
+
this.planListeners.delete(listener);
|
|
2194
|
+
};
|
|
2195
|
+
};
|
|
2156
2196
|
notifyFlagCheckListeners = (flagKey, check) => {
|
|
2157
2197
|
const listeners = this.flagCheckListeners?.[flagKey] ?? [];
|
|
2158
2198
|
if (listeners.size > 0) {
|
|
@@ -2201,6 +2241,21 @@ var Schematic = class {
|
|
|
2201
2241
|
});
|
|
2202
2242
|
});
|
|
2203
2243
|
};
|
|
2244
|
+
notifyPlanListeners = (value) => {
|
|
2245
|
+
const listeners = this.planListeners ?? [];
|
|
2246
|
+
if (listeners.size > 0) {
|
|
2247
|
+
this.debug(`Notifying ${listeners.size} plan listeners`, { value });
|
|
2248
|
+
}
|
|
2249
|
+
listeners.forEach((listener, index) => {
|
|
2250
|
+
this.debug(`Calling listener ${index} for plan`, {
|
|
2251
|
+
value
|
|
2252
|
+
});
|
|
2253
|
+
notifyPlanListener(listener, value);
|
|
2254
|
+
this.debug(`Listener ${index} for plan completed`, {
|
|
2255
|
+
value
|
|
2256
|
+
});
|
|
2257
|
+
});
|
|
2258
|
+
};
|
|
2204
2259
|
};
|
|
2205
2260
|
var notifyPendingListener = (listener, value) => {
|
|
2206
2261
|
if (listener.length > 0) {
|
|
@@ -2223,12 +2278,19 @@ var notifyFlagValueListener = (listener, value) => {
|
|
|
2223
2278
|
listener();
|
|
2224
2279
|
}
|
|
2225
2280
|
};
|
|
2281
|
+
var notifyPlanListener = (listener, value) => {
|
|
2282
|
+
if (listener.length > 0) {
|
|
2283
|
+
listener(value);
|
|
2284
|
+
} else {
|
|
2285
|
+
listener();
|
|
2286
|
+
}
|
|
2287
|
+
};
|
|
2226
2288
|
|
|
2227
2289
|
// src/context/schematic.tsx
|
|
2228
2290
|
var import_react = __toESM(require("react"));
|
|
2229
2291
|
|
|
2230
2292
|
// src/version.ts
|
|
2231
|
-
var version2 = "1.
|
|
2293
|
+
var version2 = "1.3.0";
|
|
2232
2294
|
|
|
2233
2295
|
// src/context/schematic.tsx
|
|
2234
2296
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -2349,6 +2411,23 @@ var useSchematicEntitlement = (key, opts) => {
|
|
|
2349
2411
|
}, [client, key, fallbackCheck]);
|
|
2350
2412
|
return (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, () => fallbackCheck);
|
|
2351
2413
|
};
|
|
2414
|
+
var useSchematicPlan = (opts) => {
|
|
2415
|
+
const client = useSchematicClient(opts);
|
|
2416
|
+
const fallback = opts?.fallback;
|
|
2417
|
+
const fallbackPlan = (0, import_react2.useMemo)(
|
|
2418
|
+
() => fallback,
|
|
2419
|
+
[fallback?.id, fallback?.name, fallback?.trialEndDate?.getTime()]
|
|
2420
|
+
);
|
|
2421
|
+
const subscribe = (0, import_react2.useCallback)(
|
|
2422
|
+
(callback) => client.addPlanListener(callback),
|
|
2423
|
+
[client]
|
|
2424
|
+
);
|
|
2425
|
+
const getSnapshot = (0, import_react2.useCallback)(() => {
|
|
2426
|
+
const plan = client.getPlan();
|
|
2427
|
+
return plan ?? fallbackPlan;
|
|
2428
|
+
}, [client, fallbackPlan]);
|
|
2429
|
+
return (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, () => fallbackPlan);
|
|
2430
|
+
};
|
|
2352
2431
|
var useSchematicIsPending = (opts) => {
|
|
2353
2432
|
const client = useSchematicClient(opts);
|
|
2354
2433
|
const subscribe = (0, import_react2.useCallback)(
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CheckFlagReturn } from '@schematichq/schematic-js';
|
|
2
|
+
import { CheckPlanReturn } from '@schematichq/schematic-js';
|
|
2
3
|
import { Event as Event_2 } from '@schematichq/schematic-js';
|
|
3
4
|
import { EventBody } from '@schematichq/schematic-js';
|
|
4
5
|
import { EventBodyIdentify } from '@schematichq/schematic-js';
|
|
@@ -21,6 +22,8 @@ declare type BaseSchematicProviderProps = Omit<SchematicJS.SchematicOptions, "cl
|
|
|
21
22
|
|
|
22
23
|
export { CheckFlagReturn }
|
|
23
24
|
|
|
25
|
+
export { CheckPlanReturn }
|
|
26
|
+
|
|
24
27
|
export { Event_2 as Event }
|
|
25
28
|
|
|
26
29
|
export { EventBody }
|
|
@@ -90,4 +93,10 @@ export declare type UseSchematicFlagOpts = SchematicHookOpts & {
|
|
|
90
93
|
|
|
91
94
|
export declare const useSchematicIsPending: (opts?: SchematicHookOpts) => boolean;
|
|
92
95
|
|
|
96
|
+
export declare const useSchematicPlan: (opts?: UseSchematicPlanOpts) => SchematicJS.CheckPlanReturn | undefined;
|
|
97
|
+
|
|
98
|
+
export declare type UseSchematicPlanOpts = SchematicHookOpts & {
|
|
99
|
+
fallback?: SchematicJS.CheckPlanReturn;
|
|
100
|
+
};
|
|
101
|
+
|
|
93
102
|
export { }
|
|
@@ -661,26 +661,6 @@ function CheckFlagResponseDataFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
661
661
|
value: json["value"]
|
|
662
662
|
};
|
|
663
663
|
}
|
|
664
|
-
function EventBodyFlagCheckToJSON(json) {
|
|
665
|
-
return EventBodyFlagCheckToJSONTyped(json, false);
|
|
666
|
-
}
|
|
667
|
-
function EventBodyFlagCheckToJSONTyped(value, ignoreDiscriminator = false) {
|
|
668
|
-
if (value == null) {
|
|
669
|
-
return value;
|
|
670
|
-
}
|
|
671
|
-
return {
|
|
672
|
-
company_id: value["companyId"],
|
|
673
|
-
error: value["error"],
|
|
674
|
-
flag_id: value["flagId"],
|
|
675
|
-
flag_key: value["flagKey"],
|
|
676
|
-
reason: value["reason"],
|
|
677
|
-
req_company: value["reqCompany"],
|
|
678
|
-
req_user: value["reqUser"],
|
|
679
|
-
rule_id: value["ruleId"],
|
|
680
|
-
user_id: value["userId"],
|
|
681
|
-
value: value["value"]
|
|
682
|
-
};
|
|
683
|
-
}
|
|
684
664
|
function CheckFlagResponseFromJSON(json) {
|
|
685
665
|
return CheckFlagResponseFromJSONTyped(json, false);
|
|
686
666
|
}
|
|
@@ -693,6 +673,19 @@ function CheckFlagResponseFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
693
673
|
params: json["params"]
|
|
694
674
|
};
|
|
695
675
|
}
|
|
676
|
+
function DatastreamCompanyPlanFromJSON(json) {
|
|
677
|
+
return DatastreamCompanyPlanFromJSONTyped(json, false);
|
|
678
|
+
}
|
|
679
|
+
function DatastreamCompanyPlanFromJSONTyped(json, ignoreDiscriminator) {
|
|
680
|
+
if (json == null) {
|
|
681
|
+
return json;
|
|
682
|
+
}
|
|
683
|
+
return {
|
|
684
|
+
id: json["id"],
|
|
685
|
+
name: json["name"],
|
|
686
|
+
trialEndDate: json["trial_end_date"] == null ? void 0 : new Date(json["trial_end_date"])
|
|
687
|
+
};
|
|
688
|
+
}
|
|
696
689
|
function CheckFlagsResponseDataFromJSON(json) {
|
|
697
690
|
return CheckFlagsResponseDataFromJSONTyped(json, false);
|
|
698
691
|
}
|
|
@@ -701,7 +694,8 @@ function CheckFlagsResponseDataFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
701
694
|
return json;
|
|
702
695
|
}
|
|
703
696
|
return {
|
|
704
|
-
flags: json["flags"].map(CheckFlagResponseDataFromJSON)
|
|
697
|
+
flags: json["flags"].map(CheckFlagResponseDataFromJSON),
|
|
698
|
+
plan: json["plan"] == null ? void 0 : DatastreamCompanyPlanFromJSON(json["plan"])
|
|
705
699
|
};
|
|
706
700
|
}
|
|
707
701
|
function CheckFlagsResponseFromJSON(json) {
|
|
@@ -716,6 +710,26 @@ function CheckFlagsResponseFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
716
710
|
params: json["params"]
|
|
717
711
|
};
|
|
718
712
|
}
|
|
713
|
+
function EventBodyFlagCheckToJSON(json) {
|
|
714
|
+
return EventBodyFlagCheckToJSONTyped(json, false);
|
|
715
|
+
}
|
|
716
|
+
function EventBodyFlagCheckToJSONTyped(value, ignoreDiscriminator = false) {
|
|
717
|
+
if (value == null) {
|
|
718
|
+
return value;
|
|
719
|
+
}
|
|
720
|
+
return {
|
|
721
|
+
company_id: value["companyId"],
|
|
722
|
+
error: value["error"],
|
|
723
|
+
flag_id: value["flagId"],
|
|
724
|
+
flag_key: value["flagKey"],
|
|
725
|
+
reason: value["reason"],
|
|
726
|
+
req_company: value["reqCompany"],
|
|
727
|
+
req_user: value["reqUser"],
|
|
728
|
+
rule_id: value["ruleId"],
|
|
729
|
+
user_id: value["userId"],
|
|
730
|
+
value: value["value"]
|
|
731
|
+
};
|
|
732
|
+
}
|
|
719
733
|
var RuleType = /* @__PURE__ */ ((RuleType2) => {
|
|
720
734
|
RuleType2["GLOBAL_OVERRIDE"] = "global_override";
|
|
721
735
|
RuleType2["COMPANY_OVERRIDE"] = "company_override";
|
|
@@ -771,6 +785,14 @@ var CheckFlagReturnFromJSON = (json) => {
|
|
|
771
785
|
value
|
|
772
786
|
};
|
|
773
787
|
};
|
|
788
|
+
var CheckPlanReturnFromJSON = (json) => {
|
|
789
|
+
const { id, name, trialEndDate } = DatastreamCompanyPlanFromJSON(json);
|
|
790
|
+
return {
|
|
791
|
+
id,
|
|
792
|
+
name,
|
|
793
|
+
trialEndDate: trialEndDate == null ? void 0 : trialEndDate
|
|
794
|
+
};
|
|
795
|
+
};
|
|
774
796
|
function contextString(context) {
|
|
775
797
|
const sortedContext = Object.keys(context).reduce((acc, key) => {
|
|
776
798
|
const sortedKeys = Object.keys(
|
|
@@ -785,7 +807,7 @@ function contextString(context) {
|
|
|
785
807
|
}, {});
|
|
786
808
|
return JSON.stringify(sortedContext);
|
|
787
809
|
}
|
|
788
|
-
var version = "1.
|
|
810
|
+
var version = "1.3.0";
|
|
789
811
|
var anonymousIdKey = "schematicId";
|
|
790
812
|
var Schematic = class {
|
|
791
813
|
additionalHeaders = {};
|
|
@@ -802,10 +824,12 @@ var Schematic = class {
|
|
|
802
824
|
flagValueListeners = {};
|
|
803
825
|
isPending = true;
|
|
804
826
|
isPendingListeners = /* @__PURE__ */ new Set();
|
|
827
|
+
planListeners = /* @__PURE__ */ new Set();
|
|
805
828
|
storage;
|
|
806
829
|
useWebSocket = false;
|
|
807
830
|
checks = {};
|
|
808
831
|
featureUsageEventMap = {};
|
|
832
|
+
planChecks = {};
|
|
809
833
|
webSocketUrl = "wss://api.schematichq.com";
|
|
810
834
|
webSocketConnectionTimeout = 1e4;
|
|
811
835
|
webSocketReconnect = true;
|
|
@@ -1138,28 +1162,32 @@ var Schematic = class {
|
|
|
1138
1162
|
this.checks[contextStr] = {};
|
|
1139
1163
|
}
|
|
1140
1164
|
this.checks[contextStr][flagCheck.flag] = flagCheck;
|
|
1141
|
-
this.debug(`WebSocket flag update:`, {
|
|
1142
|
-
flag: flagCheck.flag,
|
|
1143
|
-
value: flagCheck.value,
|
|
1144
|
-
flagCheck
|
|
1145
|
-
});
|
|
1146
1165
|
if (typeof flagCheck.featureUsageEvent === "string") {
|
|
1147
1166
|
this.updateFeatureUsageEventMap(flagCheck);
|
|
1148
1167
|
}
|
|
1149
1168
|
if ((this.flagCheckListeners[flag.flag]?.size ?? 0) > 0 || (this.flagValueListeners[flag.flag]?.size ?? 0) > 0) {
|
|
1150
1169
|
this.submitFlagCheckEvent(flagCheck.flag, flagCheck, context);
|
|
1151
1170
|
}
|
|
1152
|
-
this.debug(
|
|
1153
|
-
flag
|
|
1154
|
-
|
|
1155
|
-
|
|
1171
|
+
this.debug(
|
|
1172
|
+
`WebSocket flag update received. Notifying listeners for ${flag.flag}`,
|
|
1173
|
+
{
|
|
1174
|
+
flag: flag.flag,
|
|
1175
|
+
value: flagCheck.value,
|
|
1176
|
+
flagCheck
|
|
1177
|
+
}
|
|
1178
|
+
);
|
|
1156
1179
|
this.notifyFlagCheckListeners(flag.flag, flagCheck);
|
|
1157
1180
|
this.notifyFlagValueListeners(flag.flag, flagCheck.value);
|
|
1158
|
-
this.debug(`Finished notifying listeners for flag ${flag.flag}`, {
|
|
1159
|
-
flag: flag.flag,
|
|
1160
|
-
value: flagCheck.value
|
|
1161
|
-
});
|
|
1162
1181
|
});
|
|
1182
|
+
if (message.plan !== void 0 && message.plan !== null) {
|
|
1183
|
+
const plan = CheckPlanReturnFromJSON(message.plan);
|
|
1184
|
+
const contextStr = contextString(context);
|
|
1185
|
+
this.planChecks[contextStr] = plan;
|
|
1186
|
+
this.debug(`WebSocket plan update received. Notifying listeners`, {
|
|
1187
|
+
plan
|
|
1188
|
+
});
|
|
1189
|
+
this.notifyPlanListeners(plan);
|
|
1190
|
+
}
|
|
1163
1191
|
this.flushContextDependentEventQueue();
|
|
1164
1192
|
this.setIsPending(false);
|
|
1165
1193
|
};
|
|
@@ -2055,6 +2083,11 @@ var Schematic = class {
|
|
|
2055
2083
|
(listener) => notifyPendingListener(listener, isPending)
|
|
2056
2084
|
);
|
|
2057
2085
|
};
|
|
2086
|
+
getPlan = () => {
|
|
2087
|
+
const contextStr = contextString(this.context);
|
|
2088
|
+
const plan = this.planChecks[contextStr];
|
|
2089
|
+
return plan;
|
|
2090
|
+
};
|
|
2058
2091
|
// flag checks state
|
|
2059
2092
|
getFlagCheck = (flagKey) => {
|
|
2060
2093
|
const contextStr = contextString(this.context);
|
|
@@ -2108,6 +2141,12 @@ var Schematic = class {
|
|
|
2108
2141
|
this.flagCheckListeners[flagKey].delete(listener);
|
|
2109
2142
|
};
|
|
2110
2143
|
};
|
|
2144
|
+
addPlanListener = (listener) => {
|
|
2145
|
+
this.planListeners.add(listener);
|
|
2146
|
+
return () => {
|
|
2147
|
+
this.planListeners.delete(listener);
|
|
2148
|
+
};
|
|
2149
|
+
};
|
|
2111
2150
|
notifyFlagCheckListeners = (flagKey, check) => {
|
|
2112
2151
|
const listeners = this.flagCheckListeners?.[flagKey] ?? [];
|
|
2113
2152
|
if (listeners.size > 0) {
|
|
@@ -2156,6 +2195,21 @@ var Schematic = class {
|
|
|
2156
2195
|
});
|
|
2157
2196
|
});
|
|
2158
2197
|
};
|
|
2198
|
+
notifyPlanListeners = (value) => {
|
|
2199
|
+
const listeners = this.planListeners ?? [];
|
|
2200
|
+
if (listeners.size > 0) {
|
|
2201
|
+
this.debug(`Notifying ${listeners.size} plan listeners`, { value });
|
|
2202
|
+
}
|
|
2203
|
+
listeners.forEach((listener, index) => {
|
|
2204
|
+
this.debug(`Calling listener ${index} for plan`, {
|
|
2205
|
+
value
|
|
2206
|
+
});
|
|
2207
|
+
notifyPlanListener(listener, value);
|
|
2208
|
+
this.debug(`Listener ${index} for plan completed`, {
|
|
2209
|
+
value
|
|
2210
|
+
});
|
|
2211
|
+
});
|
|
2212
|
+
};
|
|
2159
2213
|
};
|
|
2160
2214
|
var notifyPendingListener = (listener, value) => {
|
|
2161
2215
|
if (listener.length > 0) {
|
|
@@ -2178,12 +2232,19 @@ var notifyFlagValueListener = (listener, value) => {
|
|
|
2178
2232
|
listener();
|
|
2179
2233
|
}
|
|
2180
2234
|
};
|
|
2235
|
+
var notifyPlanListener = (listener, value) => {
|
|
2236
|
+
if (listener.length > 0) {
|
|
2237
|
+
listener(value);
|
|
2238
|
+
} else {
|
|
2239
|
+
listener();
|
|
2240
|
+
}
|
|
2241
|
+
};
|
|
2181
2242
|
|
|
2182
2243
|
// src/context/schematic.tsx
|
|
2183
2244
|
import React, { createContext, useEffect, useMemo, useRef } from "react";
|
|
2184
2245
|
|
|
2185
2246
|
// src/version.ts
|
|
2186
|
-
var version2 = "1.
|
|
2247
|
+
var version2 = "1.3.0";
|
|
2187
2248
|
|
|
2188
2249
|
// src/context/schematic.tsx
|
|
2189
2250
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -2304,6 +2365,23 @@ var useSchematicEntitlement = (key, opts) => {
|
|
|
2304
2365
|
}, [client, key, fallbackCheck]);
|
|
2305
2366
|
return useSyncExternalStore(subscribe, getSnapshot, () => fallbackCheck);
|
|
2306
2367
|
};
|
|
2368
|
+
var useSchematicPlan = (opts) => {
|
|
2369
|
+
const client = useSchematicClient(opts);
|
|
2370
|
+
const fallback = opts?.fallback;
|
|
2371
|
+
const fallbackPlan = useMemo2(
|
|
2372
|
+
() => fallback,
|
|
2373
|
+
[fallback?.id, fallback?.name, fallback?.trialEndDate?.getTime()]
|
|
2374
|
+
);
|
|
2375
|
+
const subscribe = useCallback(
|
|
2376
|
+
(callback) => client.addPlanListener(callback),
|
|
2377
|
+
[client]
|
|
2378
|
+
);
|
|
2379
|
+
const getSnapshot = useCallback(() => {
|
|
2380
|
+
const plan = client.getPlan();
|
|
2381
|
+
return plan ?? fallbackPlan;
|
|
2382
|
+
}, [client, fallbackPlan]);
|
|
2383
|
+
return useSyncExternalStore(subscribe, getSnapshot, () => fallbackPlan);
|
|
2384
|
+
};
|
|
2307
2385
|
var useSchematicIsPending = (opts) => {
|
|
2308
2386
|
const client = useSchematicClient(opts);
|
|
2309
2387
|
const subscribe = useCallback(
|
|
@@ -2323,7 +2401,8 @@ export {
|
|
|
2323
2401
|
useSchematicEntitlement,
|
|
2324
2402
|
useSchematicEvents,
|
|
2325
2403
|
useSchematicFlag,
|
|
2326
|
-
useSchematicIsPending
|
|
2404
|
+
useSchematicIsPending,
|
|
2405
|
+
useSchematicPlan
|
|
2327
2406
|
};
|
|
2328
2407
|
/*! Bundled license information:
|
|
2329
2408
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schematichq/schematic-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"main": "dist/schematic-react.cjs.js",
|
|
5
5
|
"module": "dist/schematic-react.esm.js",
|
|
6
6
|
"types": "dist/schematic-react.d.ts",
|
|
@@ -31,34 +31,39 @@
|
|
|
31
31
|
"prepare": "husky"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@schematichq/schematic-js": "^1.
|
|
34
|
+
"@schematichq/schematic-js": "^1.3.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@eslint/js": "^10.0.1",
|
|
38
|
-
"@microsoft/api-extractor": "^7.57.
|
|
38
|
+
"@microsoft/api-extractor": "^7.57.7",
|
|
39
39
|
"@testing-library/dom": "^10.4.1",
|
|
40
40
|
"@testing-library/jest-dom": "^6.9.1",
|
|
41
41
|
"@testing-library/react": "^16.3.2",
|
|
42
42
|
"@types/react": "^19.2.14",
|
|
43
43
|
"@vitest/browser": "^4.0.18",
|
|
44
|
-
"esbuild": "^0.27.
|
|
45
|
-
"eslint": "^10.0.
|
|
44
|
+
"esbuild": "^0.27.4",
|
|
45
|
+
"eslint": "^10.0.3",
|
|
46
46
|
"eslint-plugin-import": "^2.32.0",
|
|
47
47
|
"eslint-plugin-react": "^7.37.5",
|
|
48
48
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
49
49
|
"globals": "^17.4.0",
|
|
50
|
-
"happy-dom": "^20.8.
|
|
50
|
+
"happy-dom": "^20.8.4",
|
|
51
51
|
"husky": "^9.1.7",
|
|
52
|
-
"jsdom": "^
|
|
52
|
+
"jsdom": "^29.0.0",
|
|
53
53
|
"prettier": "^3.8.1",
|
|
54
54
|
"react": "^19.2.4",
|
|
55
55
|
"react-dom": "^19.2.4",
|
|
56
56
|
"typescript": "^5.9.3",
|
|
57
|
-
"typescript-eslint": "^8.
|
|
57
|
+
"typescript-eslint": "^8.57.1",
|
|
58
58
|
"vitest": "^4.0.18"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"react": ">=18"
|
|
62
62
|
},
|
|
63
|
+
"resolutions": {
|
|
64
|
+
"minimatch": ">=3.1.3",
|
|
65
|
+
"rollup": ">=4.59.0",
|
|
66
|
+
"undici": ">=7.24.0"
|
|
67
|
+
},
|
|
63
68
|
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
64
69
|
}
|