@schematichq/schematic-vue 1.2.16 → 1.4.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 +1 -2
- package/README.md +98 -0
- package/dist/schematic-vue.cjs.js +221 -100
- package/dist/schematic-vue.d.ts +905 -28
- package/dist/schematic-vue.esm.js +221 -100
- package/package.json +6 -5
|
@@ -606,6 +606,36 @@ function v4(options, buf, offset) {
|
|
|
606
606
|
}
|
|
607
607
|
var v4_default = v4;
|
|
608
608
|
var import_polyfill = __toESM(require_browser_polyfill());
|
|
609
|
+
function EntitlementValueTypeFromJSON(json) {
|
|
610
|
+
return EntitlementValueTypeFromJSONTyped(json, false);
|
|
611
|
+
}
|
|
612
|
+
function EntitlementValueTypeFromJSONTyped(json, ignoreDiscriminator) {
|
|
613
|
+
return json;
|
|
614
|
+
}
|
|
615
|
+
function FeatureEntitlementFromJSON(json) {
|
|
616
|
+
return FeatureEntitlementFromJSONTyped(json, false);
|
|
617
|
+
}
|
|
618
|
+
function FeatureEntitlementFromJSONTyped(json, ignoreDiscriminator) {
|
|
619
|
+
if (json == null) {
|
|
620
|
+
return json;
|
|
621
|
+
}
|
|
622
|
+
return {
|
|
623
|
+
allocation: json["allocation"] == null ? void 0 : json["allocation"],
|
|
624
|
+
creditId: json["credit_id"] == null ? void 0 : json["credit_id"],
|
|
625
|
+
creditRemaining: json["credit_remaining"] == null ? void 0 : json["credit_remaining"],
|
|
626
|
+
creditTotal: json["credit_total"] == null ? void 0 : json["credit_total"],
|
|
627
|
+
creditUsed: json["credit_used"] == null ? void 0 : json["credit_used"],
|
|
628
|
+
eventName: json["event_name"] == null ? void 0 : json["event_name"],
|
|
629
|
+
featureId: json["feature_id"],
|
|
630
|
+
featureKey: json["feature_key"],
|
|
631
|
+
metricPeriod: json["metric_period"] == null ? void 0 : json["metric_period"],
|
|
632
|
+
metricResetAt: json["metric_reset_at"] == null ? void 0 : new Date(json["metric_reset_at"]),
|
|
633
|
+
monthReset: json["month_reset"] == null ? void 0 : json["month_reset"],
|
|
634
|
+
softLimit: json["soft_limit"] == null ? void 0 : json["soft_limit"],
|
|
635
|
+
usage: json["usage"] == null ? void 0 : json["usage"],
|
|
636
|
+
valueType: EntitlementValueTypeFromJSON(json["value_type"])
|
|
637
|
+
};
|
|
638
|
+
}
|
|
609
639
|
function CheckFlagResponseDataFromJSON(json) {
|
|
610
640
|
return CheckFlagResponseDataFromJSONTyped(json, false);
|
|
611
641
|
}
|
|
@@ -615,6 +645,7 @@ function CheckFlagResponseDataFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
615
645
|
}
|
|
616
646
|
return {
|
|
617
647
|
companyId: json["company_id"] == null ? void 0 : json["company_id"],
|
|
648
|
+
entitlement: json["entitlement"] == null ? void 0 : FeatureEntitlementFromJSON(json["entitlement"]),
|
|
618
649
|
error: json["error"] == null ? void 0 : json["error"],
|
|
619
650
|
featureAllocation: json["feature_allocation"] == null ? void 0 : json["feature_allocation"],
|
|
620
651
|
featureUsage: json["feature_usage"] == null ? void 0 : json["feature_usage"],
|
|
@@ -630,26 +661,6 @@ function CheckFlagResponseDataFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
630
661
|
value: json["value"]
|
|
631
662
|
};
|
|
632
663
|
}
|
|
633
|
-
function EventBodyFlagCheckToJSON(json) {
|
|
634
|
-
return EventBodyFlagCheckToJSONTyped(json, false);
|
|
635
|
-
}
|
|
636
|
-
function EventBodyFlagCheckToJSONTyped(value, ignoreDiscriminator = false) {
|
|
637
|
-
if (value == null) {
|
|
638
|
-
return value;
|
|
639
|
-
}
|
|
640
|
-
return {
|
|
641
|
-
company_id: value["companyId"],
|
|
642
|
-
error: value["error"],
|
|
643
|
-
flag_id: value["flagId"],
|
|
644
|
-
flag_key: value["flagKey"],
|
|
645
|
-
reason: value["reason"],
|
|
646
|
-
req_company: value["reqCompany"],
|
|
647
|
-
req_user: value["reqUser"],
|
|
648
|
-
rule_id: value["ruleId"],
|
|
649
|
-
user_id: value["userId"],
|
|
650
|
-
value: value["value"]
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
664
|
function CheckFlagResponseFromJSON(json) {
|
|
654
665
|
return CheckFlagResponseFromJSONTyped(json, false);
|
|
655
666
|
}
|
|
@@ -662,6 +673,26 @@ function CheckFlagResponseFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
662
673
|
params: json["params"]
|
|
663
674
|
};
|
|
664
675
|
}
|
|
676
|
+
function TrialStatusFromJSON(json) {
|
|
677
|
+
return TrialStatusFromJSONTyped(json, false);
|
|
678
|
+
}
|
|
679
|
+
function TrialStatusFromJSONTyped(json, ignoreDiscriminator) {
|
|
680
|
+
return json;
|
|
681
|
+
}
|
|
682
|
+
function DatastreamCompanyPlanFromJSON(json) {
|
|
683
|
+
return DatastreamCompanyPlanFromJSONTyped(json, false);
|
|
684
|
+
}
|
|
685
|
+
function DatastreamCompanyPlanFromJSONTyped(json, ignoreDiscriminator) {
|
|
686
|
+
if (json == null) {
|
|
687
|
+
return json;
|
|
688
|
+
}
|
|
689
|
+
return {
|
|
690
|
+
id: json["id"],
|
|
691
|
+
name: json["name"],
|
|
692
|
+
trialEndDate: json["trial_end_date"] == null ? void 0 : new Date(json["trial_end_date"]),
|
|
693
|
+
trialStatus: json["trial_status"] == null ? void 0 : TrialStatusFromJSON(json["trial_status"])
|
|
694
|
+
};
|
|
695
|
+
}
|
|
665
696
|
function CheckFlagsResponseDataFromJSON(json) {
|
|
666
697
|
return CheckFlagsResponseDataFromJSONTyped(json, false);
|
|
667
698
|
}
|
|
@@ -670,7 +701,8 @@ function CheckFlagsResponseDataFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
670
701
|
return json;
|
|
671
702
|
}
|
|
672
703
|
return {
|
|
673
|
-
flags: json["flags"].map(CheckFlagResponseDataFromJSON)
|
|
704
|
+
flags: json["flags"].map(CheckFlagResponseDataFromJSON),
|
|
705
|
+
plan: json["plan"] == null ? void 0 : DatastreamCompanyPlanFromJSON(json["plan"])
|
|
674
706
|
};
|
|
675
707
|
}
|
|
676
708
|
function CheckFlagsResponseFromJSON(json) {
|
|
@@ -685,6 +717,26 @@ function CheckFlagsResponseFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
685
717
|
params: json["params"]
|
|
686
718
|
};
|
|
687
719
|
}
|
|
720
|
+
function EventBodyFlagCheckToJSON(json) {
|
|
721
|
+
return EventBodyFlagCheckToJSONTyped(json, false);
|
|
722
|
+
}
|
|
723
|
+
function EventBodyFlagCheckToJSONTyped(value, ignoreDiscriminator = false) {
|
|
724
|
+
if (value == null) {
|
|
725
|
+
return value;
|
|
726
|
+
}
|
|
727
|
+
return {
|
|
728
|
+
company_id: value["companyId"],
|
|
729
|
+
error: value["error"],
|
|
730
|
+
flag_id: value["flagId"],
|
|
731
|
+
flag_key: value["flagKey"],
|
|
732
|
+
reason: value["reason"],
|
|
733
|
+
req_company: value["reqCompany"],
|
|
734
|
+
req_user: value["reqUser"],
|
|
735
|
+
rule_id: value["ruleId"],
|
|
736
|
+
user_id: value["userId"],
|
|
737
|
+
value: value["value"]
|
|
738
|
+
};
|
|
739
|
+
}
|
|
688
740
|
var RuleType = /* @__PURE__ */ ((RuleType2) => {
|
|
689
741
|
RuleType2["GLOBAL_OVERRIDE"] = "global_override";
|
|
690
742
|
RuleType2["COMPANY_OVERRIDE"] = "company_override";
|
|
@@ -705,6 +757,7 @@ var UsagePeriod = /* @__PURE__ */ ((UsagePeriod2) => {
|
|
|
705
757
|
var CheckFlagReturnFromJSON = (json) => {
|
|
706
758
|
const {
|
|
707
759
|
companyId,
|
|
760
|
+
entitlement,
|
|
708
761
|
error,
|
|
709
762
|
featureAllocation,
|
|
710
763
|
featureUsage,
|
|
@@ -722,24 +775,40 @@ var CheckFlagReturnFromJSON = (json) => {
|
|
|
722
775
|
const featureUsageExceeded = !value && // if flag is not false, then we haven't exceeded usage
|
|
723
776
|
(ruleType == "company_override_usage_exceeded" || // if the rule type is one of these, then we have exceeded usage
|
|
724
777
|
ruleType == "plan_entitlement_usage_exceeded");
|
|
778
|
+
const resolvedAllocation = entitlement?.allocation ?? featureAllocation;
|
|
779
|
+
const resolvedUsage = entitlement?.usage ?? featureUsage;
|
|
780
|
+
const resolvedEvent = entitlement?.eventName ?? featureUsageEvent;
|
|
781
|
+
const resolvedPeriod = entitlement?.metricPeriod ?? featureUsagePeriod;
|
|
782
|
+
const resolvedResetAt = entitlement?.metricResetAt ?? featureUsageResetAt;
|
|
725
783
|
return {
|
|
726
784
|
featureUsageExceeded,
|
|
727
785
|
companyId: companyId == null ? void 0 : companyId,
|
|
786
|
+
creditRemaining: entitlement?.creditRemaining == null ? void 0 : entitlement.creditRemaining,
|
|
728
787
|
error: error == null ? void 0 : error,
|
|
729
|
-
featureAllocation:
|
|
730
|
-
featureUsage:
|
|
731
|
-
featureUsageEvent:
|
|
732
|
-
featureUsagePeriod:
|
|
733
|
-
featureUsageResetAt:
|
|
788
|
+
featureAllocation: resolvedAllocation == null ? void 0 : resolvedAllocation,
|
|
789
|
+
featureUsage: resolvedUsage == null ? void 0 : resolvedUsage,
|
|
790
|
+
featureUsageEvent: resolvedEvent == null ? void 0 : resolvedEvent,
|
|
791
|
+
featureUsagePeriod: resolvedPeriod == null ? void 0 : resolvedPeriod,
|
|
792
|
+
featureUsageResetAt: resolvedResetAt == null ? void 0 : resolvedResetAt,
|
|
734
793
|
flag,
|
|
735
794
|
flagId: flagId == null ? void 0 : flagId,
|
|
736
795
|
reason,
|
|
737
796
|
ruleId: ruleId == null ? void 0 : ruleId,
|
|
738
797
|
ruleType: ruleType == null ? void 0 : ruleType,
|
|
798
|
+
softLimit: entitlement?.softLimit == null ? void 0 : entitlement.softLimit,
|
|
739
799
|
userId: userId == null ? void 0 : userId,
|
|
740
800
|
value
|
|
741
801
|
};
|
|
742
802
|
};
|
|
803
|
+
var CheckPlanReturnFromJSON = (json) => {
|
|
804
|
+
const { id, name, trialEndDate, trialStatus } = DatastreamCompanyPlanFromJSON(json);
|
|
805
|
+
return {
|
|
806
|
+
id,
|
|
807
|
+
name,
|
|
808
|
+
trialEndDate: trialEndDate == null ? void 0 : trialEndDate,
|
|
809
|
+
trialStatus: trialStatus == null ? void 0 : trialStatus
|
|
810
|
+
};
|
|
811
|
+
};
|
|
743
812
|
function contextString(context) {
|
|
744
813
|
const sortedContext = Object.keys(context).reduce((acc, key) => {
|
|
745
814
|
const sortedKeys = Object.keys(
|
|
@@ -754,7 +823,7 @@ function contextString(context) {
|
|
|
754
823
|
}, {});
|
|
755
824
|
return JSON.stringify(sortedContext);
|
|
756
825
|
}
|
|
757
|
-
var version = "1.
|
|
826
|
+
var version = "1.4.0";
|
|
758
827
|
var anonymousIdKey = "schematicId";
|
|
759
828
|
var Schematic = class {
|
|
760
829
|
additionalHeaders = {};
|
|
@@ -771,10 +840,12 @@ var Schematic = class {
|
|
|
771
840
|
flagValueListeners = {};
|
|
772
841
|
isPending = true;
|
|
773
842
|
isPendingListeners = /* @__PURE__ */ new Set();
|
|
843
|
+
planListeners = /* @__PURE__ */ new Set();
|
|
774
844
|
storage;
|
|
775
845
|
useWebSocket = false;
|
|
776
846
|
checks = {};
|
|
777
847
|
featureUsageEventMap = {};
|
|
848
|
+
planChecks = {};
|
|
778
849
|
webSocketUrl = "wss://api.schematichq.com";
|
|
779
850
|
webSocketConnectionTimeout = 1e4;
|
|
780
851
|
webSocketReconnect = true;
|
|
@@ -800,6 +871,7 @@ var Schematic = class {
|
|
|
800
871
|
retryTimer = null;
|
|
801
872
|
flagValueDefaults = {};
|
|
802
873
|
flagCheckDefaults = {};
|
|
874
|
+
fallbackCheckCache = {};
|
|
803
875
|
constructor(apiKey, options) {
|
|
804
876
|
this.apiKey = apiKey;
|
|
805
877
|
this.eventQueue = [];
|
|
@@ -968,8 +1040,8 @@ var Schematic = class {
|
|
|
968
1040
|
/**
|
|
969
1041
|
* Get value for a single flag.
|
|
970
1042
|
* In WebSocket mode, returns cached values if connection is active, otherwise establishes
|
|
971
|
-
* new connection and then returns the
|
|
972
|
-
* connection fails.
|
|
1043
|
+
* new connection and then returns the requested value. Falls back to preconfigured fallback
|
|
1044
|
+
* values if WebSocket connection fails.
|
|
973
1045
|
* In REST mode, makes an API call for each check.
|
|
974
1046
|
*/
|
|
975
1047
|
async checkFlag(options) {
|
|
@@ -1038,10 +1110,17 @@ var Schematic = class {
|
|
|
1038
1110
|
await this.setContext(context);
|
|
1039
1111
|
} catch (error) {
|
|
1040
1112
|
console.warn(
|
|
1041
|
-
"WebSocket connection failed,
|
|
1113
|
+
"WebSocket connection failed, using fallback value:",
|
|
1042
1114
|
error
|
|
1043
1115
|
);
|
|
1044
|
-
|
|
1116
|
+
const errorResult = this.resolveFallbackCheckFlagReturn(
|
|
1117
|
+
key,
|
|
1118
|
+
fallback,
|
|
1119
|
+
"WebSocket connection failed",
|
|
1120
|
+
error instanceof Error ? error.message : String(error)
|
|
1121
|
+
);
|
|
1122
|
+
this.submitFlagCheckEvent(key, errorResult, context);
|
|
1123
|
+
return errorResult.value;
|
|
1045
1124
|
}
|
|
1046
1125
|
const contextVals = this.checks[contextStr] ?? {};
|
|
1047
1126
|
const flagCheck = contextVals[key];
|
|
@@ -1052,6 +1131,13 @@ var Schematic = class {
|
|
|
1052
1131
|
);
|
|
1053
1132
|
if (typeof flagCheck !== "undefined") {
|
|
1054
1133
|
this.submitFlagCheckEvent(key, flagCheck, context);
|
|
1134
|
+
} else {
|
|
1135
|
+
const fallbackResult = this.resolveFallbackCheckFlagReturn(
|
|
1136
|
+
key,
|
|
1137
|
+
fallback,
|
|
1138
|
+
"No flag values available"
|
|
1139
|
+
);
|
|
1140
|
+
this.submitFlagCheckEvent(key, fallbackResult, context);
|
|
1055
1141
|
}
|
|
1056
1142
|
return result;
|
|
1057
1143
|
} catch (error) {
|
|
@@ -1092,28 +1178,32 @@ var Schematic = class {
|
|
|
1092
1178
|
this.checks[contextStr] = {};
|
|
1093
1179
|
}
|
|
1094
1180
|
this.checks[contextStr][flagCheck.flag] = flagCheck;
|
|
1095
|
-
this.debug(`WebSocket flag update:`, {
|
|
1096
|
-
flag: flagCheck.flag,
|
|
1097
|
-
value: flagCheck.value,
|
|
1098
|
-
flagCheck
|
|
1099
|
-
});
|
|
1100
1181
|
if (typeof flagCheck.featureUsageEvent === "string") {
|
|
1101
1182
|
this.updateFeatureUsageEventMap(flagCheck);
|
|
1102
1183
|
}
|
|
1103
1184
|
if ((this.flagCheckListeners[flag.flag]?.size ?? 0) > 0 || (this.flagValueListeners[flag.flag]?.size ?? 0) > 0) {
|
|
1104
1185
|
this.submitFlagCheckEvent(flagCheck.flag, flagCheck, context);
|
|
1105
1186
|
}
|
|
1106
|
-
this.debug(
|
|
1107
|
-
flag
|
|
1108
|
-
|
|
1109
|
-
|
|
1187
|
+
this.debug(
|
|
1188
|
+
`WebSocket flag update received. Notifying listeners for ${flag.flag}`,
|
|
1189
|
+
{
|
|
1190
|
+
flag: flag.flag,
|
|
1191
|
+
value: flagCheck.value,
|
|
1192
|
+
flagCheck
|
|
1193
|
+
}
|
|
1194
|
+
);
|
|
1110
1195
|
this.notifyFlagCheckListeners(flag.flag, flagCheck);
|
|
1111
1196
|
this.notifyFlagValueListeners(flag.flag, flagCheck.value);
|
|
1112
|
-
this.debug(`Finished notifying listeners for flag ${flag.flag}`, {
|
|
1113
|
-
flag: flag.flag,
|
|
1114
|
-
value: flagCheck.value
|
|
1115
|
-
});
|
|
1116
1197
|
});
|
|
1198
|
+
if (message.plan !== void 0 && message.plan !== null) {
|
|
1199
|
+
const plan = CheckPlanReturnFromJSON(message.plan);
|
|
1200
|
+
const contextStr = contextString(context);
|
|
1201
|
+
this.planChecks[contextStr] = plan;
|
|
1202
|
+
this.debug(`WebSocket plan update received. Notifying listeners`, {
|
|
1203
|
+
plan
|
|
1204
|
+
});
|
|
1205
|
+
this.notifyPlanListeners(plan);
|
|
1206
|
+
}
|
|
1117
1207
|
this.flushContextDependentEventQueue();
|
|
1118
1208
|
this.setIsPending(false);
|
|
1119
1209
|
};
|
|
@@ -1144,53 +1234,6 @@ var Schematic = class {
|
|
|
1144
1234
|
this.debug(`submitting flag check event:`, eventBody);
|
|
1145
1235
|
return this.handleEvent("flag_check", EventBodyFlagCheckToJSON(eventBody));
|
|
1146
1236
|
}
|
|
1147
|
-
/**
|
|
1148
|
-
* Helper method for falling back to REST API when WebSocket connection fails
|
|
1149
|
-
*/
|
|
1150
|
-
async fallbackToRest(key, context, fallback) {
|
|
1151
|
-
if (this.isOffline()) {
|
|
1152
|
-
const resolvedFallback = this.resolveFallbackValue(key, fallback);
|
|
1153
|
-
this.debug(`fallbackToRest offline result: ${key}`, {
|
|
1154
|
-
value: resolvedFallback,
|
|
1155
|
-
offlineMode: true
|
|
1156
|
-
});
|
|
1157
|
-
return resolvedFallback;
|
|
1158
|
-
}
|
|
1159
|
-
try {
|
|
1160
|
-
const requestUrl = `${this.apiUrl}/flags/${key}/check`;
|
|
1161
|
-
const response = await fetch(requestUrl, {
|
|
1162
|
-
method: "POST",
|
|
1163
|
-
headers: {
|
|
1164
|
-
...this.additionalHeaders ?? {},
|
|
1165
|
-
"Content-Type": "application/json;charset=UTF-8",
|
|
1166
|
-
"X-Schematic-Api-Key": this.apiKey
|
|
1167
|
-
},
|
|
1168
|
-
body: JSON.stringify(context)
|
|
1169
|
-
});
|
|
1170
|
-
if (!response.ok) {
|
|
1171
|
-
throw new Error("Network response was not ok");
|
|
1172
|
-
}
|
|
1173
|
-
const responseJson = await response.json();
|
|
1174
|
-
const data = CheckFlagResponseFromJSON(responseJson);
|
|
1175
|
-
this.debug(`fallbackToRest result: ${key}`, data);
|
|
1176
|
-
const result = CheckFlagReturnFromJSON(data.data);
|
|
1177
|
-
if (typeof result.featureUsageEvent === "string") {
|
|
1178
|
-
this.updateFeatureUsageEventMap(result);
|
|
1179
|
-
}
|
|
1180
|
-
this.submitFlagCheckEvent(key, result, context);
|
|
1181
|
-
return result.value;
|
|
1182
|
-
} catch (error) {
|
|
1183
|
-
console.warn("REST API call failed, using fallback value:", error);
|
|
1184
|
-
const errorResult = this.resolveFallbackCheckFlagReturn(
|
|
1185
|
-
key,
|
|
1186
|
-
fallback,
|
|
1187
|
-
"API request failed (fallback)",
|
|
1188
|
-
error instanceof Error ? error.message : String(error)
|
|
1189
|
-
);
|
|
1190
|
-
this.submitFlagCheckEvent(key, errorResult, context);
|
|
1191
|
-
return errorResult.value;
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
1237
|
/**
|
|
1195
1238
|
* Make an API call to fetch all flag values for a given context.
|
|
1196
1239
|
* Recommended for use in REST mode only.
|
|
@@ -1264,6 +1307,9 @@ var Schematic = class {
|
|
|
1264
1307
|
this.setIsPending(false);
|
|
1265
1308
|
return Promise.resolve();
|
|
1266
1309
|
}
|
|
1310
|
+
if (contextString(context) === contextString(this.context) && this.conn !== null && !this.isPending) {
|
|
1311
|
+
return;
|
|
1312
|
+
}
|
|
1267
1313
|
try {
|
|
1268
1314
|
this.setIsPending(true);
|
|
1269
1315
|
if (!this.conn) {
|
|
@@ -1303,7 +1349,10 @@ var Schematic = class {
|
|
|
1303
1349
|
await this.wsSendMessage(socket, context);
|
|
1304
1350
|
} catch (error) {
|
|
1305
1351
|
console.warn("Failed to establish WebSocket connection:", error);
|
|
1306
|
-
|
|
1352
|
+
this.context = context;
|
|
1353
|
+
this.flushContextDependentEventQueue();
|
|
1354
|
+
this.setIsPending(false);
|
|
1355
|
+
this.attemptReconnect();
|
|
1307
1356
|
}
|
|
1308
1357
|
};
|
|
1309
1358
|
/**
|
|
@@ -1944,7 +1993,10 @@ var Schematic = class {
|
|
|
1944
1993
|
clearTimeout(timeoutId);
|
|
1945
1994
|
}
|
|
1946
1995
|
this.debug(`WebSocket connection ${connectionId} error:`, error);
|
|
1947
|
-
|
|
1996
|
+
const wrappedError = new Error(
|
|
1997
|
+
"WebSocket connection failed during handshake"
|
|
1998
|
+
);
|
|
1999
|
+
reject(wrappedError);
|
|
1948
2000
|
};
|
|
1949
2001
|
webSocket.onclose = () => {
|
|
1950
2002
|
if (timeoutId !== null) {
|
|
@@ -1991,6 +2043,20 @@ var Schematic = class {
|
|
|
1991
2043
|
}
|
|
1992
2044
|
};
|
|
1993
2045
|
socket.addEventListener("message", messageHandler);
|
|
2046
|
+
socket.addEventListener("close", (event) => {
|
|
2047
|
+
if (!resolved) {
|
|
2048
|
+
resolved = true;
|
|
2049
|
+
if (event.code === 4001) {
|
|
2050
|
+
reject(
|
|
2051
|
+
new Error(
|
|
2052
|
+
`Authentication failed: ${event.reason !== "" ? event.reason : "Invalid API key"}`
|
|
2053
|
+
)
|
|
2054
|
+
);
|
|
2055
|
+
} else {
|
|
2056
|
+
reject(new Error("WebSocket connection closed unexpectedly"));
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
});
|
|
1994
2060
|
this.currentWebSocket = socket;
|
|
1995
2061
|
const clientVersion = this.additionalHeaders["X-Schematic-Client-Version"] ?? `schematic-js@${version}`;
|
|
1996
2062
|
const messagePayload = {
|
|
@@ -2027,11 +2093,17 @@ var Schematic = class {
|
|
|
2027
2093
|
};
|
|
2028
2094
|
};
|
|
2029
2095
|
setIsPending = (isPending) => {
|
|
2096
|
+
if (this.isPending === isPending) return;
|
|
2030
2097
|
this.isPending = isPending;
|
|
2031
2098
|
this.isPendingListeners.forEach(
|
|
2032
2099
|
(listener) => notifyPendingListener(listener, isPending)
|
|
2033
2100
|
);
|
|
2034
2101
|
};
|
|
2102
|
+
getPlan = () => {
|
|
2103
|
+
const contextStr = contextString(this.context);
|
|
2104
|
+
const plan = this.planChecks[contextStr];
|
|
2105
|
+
return plan;
|
|
2106
|
+
};
|
|
2035
2107
|
// flag checks state
|
|
2036
2108
|
getFlagCheck = (flagKey) => {
|
|
2037
2109
|
const contextStr = contextString(this.context);
|
|
@@ -2041,11 +2113,14 @@ var Schematic = class {
|
|
|
2041
2113
|
return check;
|
|
2042
2114
|
}
|
|
2043
2115
|
if (flagKey in this.flagCheckDefaults || flagKey in this.flagValueDefaults) {
|
|
2044
|
-
|
|
2045
|
-
flagKey
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2116
|
+
if (!(flagKey in this.fallbackCheckCache)) {
|
|
2117
|
+
this.fallbackCheckCache[flagKey] = this.resolveFallbackCheckFlagReturn(
|
|
2118
|
+
flagKey,
|
|
2119
|
+
void 0,
|
|
2120
|
+
"Default value used"
|
|
2121
|
+
);
|
|
2122
|
+
}
|
|
2123
|
+
return this.fallbackCheckCache[flagKey];
|
|
2049
2124
|
}
|
|
2050
2125
|
return void 0;
|
|
2051
2126
|
};
|
|
@@ -2082,6 +2157,12 @@ var Schematic = class {
|
|
|
2082
2157
|
this.flagCheckListeners[flagKey].delete(listener);
|
|
2083
2158
|
};
|
|
2084
2159
|
};
|
|
2160
|
+
addPlanListener = (listener) => {
|
|
2161
|
+
this.planListeners.add(listener);
|
|
2162
|
+
return () => {
|
|
2163
|
+
this.planListeners.delete(listener);
|
|
2164
|
+
};
|
|
2165
|
+
};
|
|
2085
2166
|
notifyFlagCheckListeners = (flagKey, check) => {
|
|
2086
2167
|
const listeners = this.flagCheckListeners?.[flagKey] ?? [];
|
|
2087
2168
|
if (listeners.size > 0) {
|
|
@@ -2130,6 +2211,21 @@ var Schematic = class {
|
|
|
2130
2211
|
});
|
|
2131
2212
|
});
|
|
2132
2213
|
};
|
|
2214
|
+
notifyPlanListeners = (value) => {
|
|
2215
|
+
const listeners = this.planListeners ?? [];
|
|
2216
|
+
if (listeners.size > 0) {
|
|
2217
|
+
this.debug(`Notifying ${listeners.size} plan listeners`, { value });
|
|
2218
|
+
}
|
|
2219
|
+
listeners.forEach((listener, index) => {
|
|
2220
|
+
this.debug(`Calling listener ${index} for plan`, {
|
|
2221
|
+
value
|
|
2222
|
+
});
|
|
2223
|
+
notifyPlanListener(listener, value);
|
|
2224
|
+
this.debug(`Listener ${index} for plan completed`, {
|
|
2225
|
+
value
|
|
2226
|
+
});
|
|
2227
|
+
});
|
|
2228
|
+
};
|
|
2133
2229
|
};
|
|
2134
2230
|
var notifyPendingListener = (listener, value) => {
|
|
2135
2231
|
if (listener.length > 0) {
|
|
@@ -2152,12 +2248,19 @@ var notifyFlagValueListener = (listener, value) => {
|
|
|
2152
2248
|
listener();
|
|
2153
2249
|
}
|
|
2154
2250
|
};
|
|
2251
|
+
var notifyPlanListener = (listener, value) => {
|
|
2252
|
+
if (listener.length > 0) {
|
|
2253
|
+
listener(value);
|
|
2254
|
+
} else {
|
|
2255
|
+
listener();
|
|
2256
|
+
}
|
|
2257
|
+
};
|
|
2155
2258
|
|
|
2156
2259
|
// src/context/schematic.ts
|
|
2157
2260
|
import { inject, onScopeDispose } from "vue";
|
|
2158
2261
|
|
|
2159
2262
|
// src/version.ts
|
|
2160
|
-
var version2 = "1.
|
|
2263
|
+
var version2 = "1.4.1";
|
|
2161
2264
|
|
|
2162
2265
|
// src/context/schematic.ts
|
|
2163
2266
|
var SchematicSymbol = Symbol("schematic");
|
|
@@ -2273,6 +2376,23 @@ var useSchematicEntitlement = (key, opts) => {
|
|
|
2273
2376
|
userId: computed(() => flagCheck.value.userId)
|
|
2274
2377
|
};
|
|
2275
2378
|
};
|
|
2379
|
+
var useSchematicPlan = (opts) => {
|
|
2380
|
+
const client = useSchematicClient(opts);
|
|
2381
|
+
const fallback = opts?.fallback;
|
|
2382
|
+
const plan = ref(
|
|
2383
|
+
client.getPlan() ?? fallback
|
|
2384
|
+
);
|
|
2385
|
+
let unsubscribe = null;
|
|
2386
|
+
onMounted(() => {
|
|
2387
|
+
unsubscribe = client.addPlanListener((value) => {
|
|
2388
|
+
plan.value = value;
|
|
2389
|
+
});
|
|
2390
|
+
});
|
|
2391
|
+
onScopeDispose2(() => {
|
|
2392
|
+
unsubscribe?.();
|
|
2393
|
+
});
|
|
2394
|
+
return plan;
|
|
2395
|
+
};
|
|
2276
2396
|
var useSchematicIsPending = (opts) => {
|
|
2277
2397
|
const client = useSchematicClient(opts);
|
|
2278
2398
|
const isPending = ref(client.getIsPending());
|
|
@@ -2298,7 +2418,8 @@ export {
|
|
|
2298
2418
|
useSchematicEntitlement,
|
|
2299
2419
|
useSchematicEvents,
|
|
2300
2420
|
useSchematicFlag,
|
|
2301
|
-
useSchematicIsPending
|
|
2421
|
+
useSchematicIsPending,
|
|
2422
|
+
useSchematicPlan
|
|
2302
2423
|
};
|
|
2303
2424
|
/*! Bundled license information:
|
|
2304
2425
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schematichq/schematic-vue",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"main": "dist/schematic-vue.cjs.js",
|
|
5
5
|
"module": "dist/schematic-vue.esm.js",
|
|
6
6
|
"types": "dist/schematic-vue.d.ts",
|
|
@@ -28,17 +28,14 @@
|
|
|
28
28
|
"tsc": "npx tsc",
|
|
29
29
|
"prepare": "husky"
|
|
30
30
|
},
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"@schematichq/schematic-js": "^1.2.16"
|
|
33
|
-
},
|
|
34
31
|
"devDependencies": {
|
|
35
32
|
"@eslint/js": "^9.24.0",
|
|
36
33
|
"@microsoft/api-extractor": "^7.52.2",
|
|
34
|
+
"@schematichq/schematic-js": "^1.4.0",
|
|
37
35
|
"@testing-library/dom": "^10.4.1",
|
|
38
36
|
"@types/jest": "^30.0.0",
|
|
39
37
|
"@vue/test-utils": "^2.4.6",
|
|
40
38
|
"esbuild": "^0.25.2",
|
|
41
|
-
"esbuild-jest": "^0.5.0",
|
|
42
39
|
"eslint": "^9.24.0",
|
|
43
40
|
"eslint-plugin-import": "^2.32.0",
|
|
44
41
|
"eslint-plugin-vue": "^9.30.0",
|
|
@@ -56,5 +53,9 @@
|
|
|
56
53
|
"peerDependencies": {
|
|
57
54
|
"vue": ">=3.3"
|
|
58
55
|
},
|
|
56
|
+
"resolutions": {
|
|
57
|
+
"handlebars": ">=4.7.9",
|
|
58
|
+
"minimatch": ">=3.1.3"
|
|
59
|
+
},
|
|
59
60
|
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
60
61
|
}
|