@schematichq/schematic-react 1.3.0 → 1.4.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/LICENSE +1 -1
- package/README.md +39 -0
- package/dist/schematic-react.cjs.js +38 -11
- package/dist/schematic-react.d.ts +3 -0
- package/dist/schematic-react.esm.js +38 -11
- package/package.json +14 -16
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -136,6 +136,45 @@ const MyComponent = () => {
|
|
|
136
136
|
|
|
137
137
|
*Note: `useSchematicIsPending` is checking if entitlement data has been loaded, typically via `identify`. It should, therefore, be used to wrap flag and entitlement checks, but never the initial call to `identify`.*
|
|
138
138
|
|
|
139
|
+
### Company plan information
|
|
140
|
+
|
|
141
|
+
To access the current company's plan and trial status, you can use the `useSchematicPlan` hook:
|
|
142
|
+
|
|
143
|
+
```tsx
|
|
144
|
+
import { useSchematicPlan } from "@schematichq/schematic-react";
|
|
145
|
+
|
|
146
|
+
const MyComponent = () => {
|
|
147
|
+
const plan = useSchematicPlan();
|
|
148
|
+
|
|
149
|
+
if (!plan) {
|
|
150
|
+
return <div>No plan assigned</div>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<div>
|
|
155
|
+
<p>Current plan: {plan.name}</p>
|
|
156
|
+
|
|
157
|
+
{plan.trialStatus === "active" && (
|
|
158
|
+
<p>Trial ends: {plan.trialEndDate?.toLocaleDateString()}</p>
|
|
159
|
+
)}
|
|
160
|
+
|
|
161
|
+
{plan.trialStatus === "expired" && (
|
|
162
|
+
<p>Your trial has ended. <a href="/upgrade">Upgrade now</a></p>
|
|
163
|
+
)}
|
|
164
|
+
</div>
|
|
165
|
+
);
|
|
166
|
+
};
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
The hook returns an object with the following properties:
|
|
170
|
+
|
|
171
|
+
| Property | Type | Description |
|
|
172
|
+
| --- | --- | --- |
|
|
173
|
+
| `id` | `string` | The plan ID |
|
|
174
|
+
| `name` | `string` | The plan name |
|
|
175
|
+
| `trialEndDate` | `Date \| undefined` | The trial end date, if the company has or had a trial |
|
|
176
|
+
| `trialStatus` | `"active" \| "expired" \| "converted" \| undefined` | The company's trial status: `active` if the trial is ongoing, `expired` if the trial ended without conversion, `converted` if the company converted to a paid plan, or `undefined` if the company has never trialed |
|
|
177
|
+
|
|
139
178
|
## Fallback Behavior
|
|
140
179
|
|
|
141
180
|
The SDK includes built-in fallback behavior you can use to ensure your application continues to function even when unable to reach Schematic (e.g., during service disruptions or network issues).
|
|
@@ -33,6 +33,7 @@ __export(index_exports, {
|
|
|
33
33
|
RuleType: () => RuleType,
|
|
34
34
|
Schematic: () => Schematic,
|
|
35
35
|
SchematicProvider: () => SchematicProvider,
|
|
36
|
+
TrialStatus: () => TrialStatus,
|
|
36
37
|
UsagePeriod: () => UsagePeriod,
|
|
37
38
|
useSchematic: () => useSchematic,
|
|
38
39
|
useSchematicContext: () => useSchematicContext,
|
|
@@ -719,6 +720,17 @@ function CheckFlagResponseFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
719
720
|
params: json["params"]
|
|
720
721
|
};
|
|
721
722
|
}
|
|
723
|
+
var TrialStatus = {
|
|
724
|
+
Active: "active",
|
|
725
|
+
Converted: "converted",
|
|
726
|
+
Expired: "expired"
|
|
727
|
+
};
|
|
728
|
+
function TrialStatusFromJSON(json) {
|
|
729
|
+
return TrialStatusFromJSONTyped(json, false);
|
|
730
|
+
}
|
|
731
|
+
function TrialStatusFromJSONTyped(json, ignoreDiscriminator) {
|
|
732
|
+
return json;
|
|
733
|
+
}
|
|
722
734
|
function DatastreamCompanyPlanFromJSON(json) {
|
|
723
735
|
return DatastreamCompanyPlanFromJSONTyped(json, false);
|
|
724
736
|
}
|
|
@@ -729,7 +741,8 @@ function DatastreamCompanyPlanFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
729
741
|
return {
|
|
730
742
|
id: json["id"],
|
|
731
743
|
name: json["name"],
|
|
732
|
-
trialEndDate: json["trial_end_date"] == null ? void 0 : new Date(json["trial_end_date"])
|
|
744
|
+
trialEndDate: json["trial_end_date"] == null ? void 0 : new Date(json["trial_end_date"]),
|
|
745
|
+
trialStatus: json["trial_status"] == null ? void 0 : TrialStatusFromJSON(json["trial_status"])
|
|
733
746
|
};
|
|
734
747
|
}
|
|
735
748
|
function CheckFlagsResponseDataFromJSON(json) {
|
|
@@ -796,6 +809,7 @@ var UsagePeriod = /* @__PURE__ */ ((UsagePeriod2) => {
|
|
|
796
809
|
var CheckFlagReturnFromJSON = (json) => {
|
|
797
810
|
const {
|
|
798
811
|
companyId,
|
|
812
|
+
entitlement,
|
|
799
813
|
error,
|
|
800
814
|
featureAllocation,
|
|
801
815
|
featureUsage,
|
|
@@ -813,30 +827,38 @@ var CheckFlagReturnFromJSON = (json) => {
|
|
|
813
827
|
const featureUsageExceeded = !value && // if flag is not false, then we haven't exceeded usage
|
|
814
828
|
(ruleType == "company_override_usage_exceeded" || // if the rule type is one of these, then we have exceeded usage
|
|
815
829
|
ruleType == "plan_entitlement_usage_exceeded");
|
|
830
|
+
const resolvedAllocation = entitlement?.allocation ?? featureAllocation;
|
|
831
|
+
const resolvedUsage = entitlement?.usage ?? featureUsage;
|
|
832
|
+
const resolvedEvent = entitlement?.eventName ?? featureUsageEvent;
|
|
833
|
+
const resolvedPeriod = entitlement?.metricPeriod ?? featureUsagePeriod;
|
|
834
|
+
const resolvedResetAt = entitlement?.metricResetAt ?? featureUsageResetAt;
|
|
816
835
|
return {
|
|
817
836
|
featureUsageExceeded,
|
|
818
837
|
companyId: companyId == null ? void 0 : companyId,
|
|
838
|
+
creditRemaining: entitlement?.creditRemaining == null ? void 0 : entitlement.creditRemaining,
|
|
819
839
|
error: error == null ? void 0 : error,
|
|
820
|
-
featureAllocation:
|
|
821
|
-
featureUsage:
|
|
822
|
-
featureUsageEvent:
|
|
823
|
-
featureUsagePeriod:
|
|
824
|
-
featureUsageResetAt:
|
|
840
|
+
featureAllocation: resolvedAllocation == null ? void 0 : resolvedAllocation,
|
|
841
|
+
featureUsage: resolvedUsage == null ? void 0 : resolvedUsage,
|
|
842
|
+
featureUsageEvent: resolvedEvent == null ? void 0 : resolvedEvent,
|
|
843
|
+
featureUsagePeriod: resolvedPeriod == null ? void 0 : resolvedPeriod,
|
|
844
|
+
featureUsageResetAt: resolvedResetAt == null ? void 0 : resolvedResetAt,
|
|
825
845
|
flag,
|
|
826
846
|
flagId: flagId == null ? void 0 : flagId,
|
|
827
847
|
reason,
|
|
828
848
|
ruleId: ruleId == null ? void 0 : ruleId,
|
|
829
849
|
ruleType: ruleType == null ? void 0 : ruleType,
|
|
850
|
+
softLimit: entitlement?.softLimit == null ? void 0 : entitlement.softLimit,
|
|
830
851
|
userId: userId == null ? void 0 : userId,
|
|
831
852
|
value
|
|
832
853
|
};
|
|
833
854
|
};
|
|
834
855
|
var CheckPlanReturnFromJSON = (json) => {
|
|
835
|
-
const { id, name, trialEndDate } = DatastreamCompanyPlanFromJSON(json);
|
|
856
|
+
const { id, name, trialEndDate, trialStatus } = DatastreamCompanyPlanFromJSON(json);
|
|
836
857
|
return {
|
|
837
858
|
id,
|
|
838
859
|
name,
|
|
839
|
-
trialEndDate: trialEndDate == null ? void 0 : trialEndDate
|
|
860
|
+
trialEndDate: trialEndDate == null ? void 0 : trialEndDate,
|
|
861
|
+
trialStatus: trialStatus == null ? void 0 : trialStatus
|
|
840
862
|
};
|
|
841
863
|
};
|
|
842
864
|
function contextString(context) {
|
|
@@ -853,7 +875,7 @@ function contextString(context) {
|
|
|
853
875
|
}, {});
|
|
854
876
|
return JSON.stringify(sortedContext);
|
|
855
877
|
}
|
|
856
|
-
var version = "1.
|
|
878
|
+
var version = "1.4.0";
|
|
857
879
|
var anonymousIdKey = "schematicId";
|
|
858
880
|
var Schematic = class {
|
|
859
881
|
additionalHeaders = {};
|
|
@@ -2290,7 +2312,7 @@ var notifyPlanListener = (listener, value) => {
|
|
|
2290
2312
|
var import_react = __toESM(require("react"));
|
|
2291
2313
|
|
|
2292
2314
|
// src/version.ts
|
|
2293
|
-
var version2 = "1.
|
|
2315
|
+
var version2 = "1.4.0";
|
|
2294
2316
|
|
|
2295
2317
|
// src/context/schematic.tsx
|
|
2296
2318
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -2416,7 +2438,12 @@ var useSchematicPlan = (opts) => {
|
|
|
2416
2438
|
const fallback = opts?.fallback;
|
|
2417
2439
|
const fallbackPlan = (0, import_react2.useMemo)(
|
|
2418
2440
|
() => fallback,
|
|
2419
|
-
[
|
|
2441
|
+
[
|
|
2442
|
+
fallback?.id,
|
|
2443
|
+
fallback?.name,
|
|
2444
|
+
fallback?.trialEndDate?.getTime(),
|
|
2445
|
+
fallback?.trialStatus
|
|
2446
|
+
]
|
|
2420
2447
|
);
|
|
2421
2448
|
const subscribe = (0, import_react2.useCallback)(
|
|
2422
2449
|
(callback) => client.addPlanListener(callback),
|
|
@@ -14,6 +14,7 @@ import * as SchematicJS from '@schematichq/schematic-js';
|
|
|
14
14
|
import { SchematicOptions } from '@schematichq/schematic-js';
|
|
15
15
|
import { StoragePersister } from '@schematichq/schematic-js';
|
|
16
16
|
import { Traits } from '@schematichq/schematic-js';
|
|
17
|
+
import { TrialStatus } from '@schematichq/schematic-js';
|
|
17
18
|
import { UsagePeriod } from '@schematichq/schematic-js';
|
|
18
19
|
|
|
19
20
|
declare type BaseSchematicProviderProps = Omit<SchematicJS.SchematicOptions, "client" | "publishableKey" | "useWebSocket"> & {
|
|
@@ -70,6 +71,8 @@ export { StoragePersister }
|
|
|
70
71
|
|
|
71
72
|
export { Traits }
|
|
72
73
|
|
|
74
|
+
export { TrialStatus }
|
|
75
|
+
|
|
73
76
|
export { UsagePeriod }
|
|
74
77
|
|
|
75
78
|
export declare const useSchematic: () => SchematicContextProps;
|
|
@@ -673,6 +673,17 @@ function CheckFlagResponseFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
673
673
|
params: json["params"]
|
|
674
674
|
};
|
|
675
675
|
}
|
|
676
|
+
var TrialStatus = {
|
|
677
|
+
Active: "active",
|
|
678
|
+
Converted: "converted",
|
|
679
|
+
Expired: "expired"
|
|
680
|
+
};
|
|
681
|
+
function TrialStatusFromJSON(json) {
|
|
682
|
+
return TrialStatusFromJSONTyped(json, false);
|
|
683
|
+
}
|
|
684
|
+
function TrialStatusFromJSONTyped(json, ignoreDiscriminator) {
|
|
685
|
+
return json;
|
|
686
|
+
}
|
|
676
687
|
function DatastreamCompanyPlanFromJSON(json) {
|
|
677
688
|
return DatastreamCompanyPlanFromJSONTyped(json, false);
|
|
678
689
|
}
|
|
@@ -683,7 +694,8 @@ function DatastreamCompanyPlanFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
683
694
|
return {
|
|
684
695
|
id: json["id"],
|
|
685
696
|
name: json["name"],
|
|
686
|
-
trialEndDate: json["trial_end_date"] == null ? void 0 : new Date(json["trial_end_date"])
|
|
697
|
+
trialEndDate: json["trial_end_date"] == null ? void 0 : new Date(json["trial_end_date"]),
|
|
698
|
+
trialStatus: json["trial_status"] == null ? void 0 : TrialStatusFromJSON(json["trial_status"])
|
|
687
699
|
};
|
|
688
700
|
}
|
|
689
701
|
function CheckFlagsResponseDataFromJSON(json) {
|
|
@@ -750,6 +762,7 @@ var UsagePeriod = /* @__PURE__ */ ((UsagePeriod2) => {
|
|
|
750
762
|
var CheckFlagReturnFromJSON = (json) => {
|
|
751
763
|
const {
|
|
752
764
|
companyId,
|
|
765
|
+
entitlement,
|
|
753
766
|
error,
|
|
754
767
|
featureAllocation,
|
|
755
768
|
featureUsage,
|
|
@@ -767,30 +780,38 @@ var CheckFlagReturnFromJSON = (json) => {
|
|
|
767
780
|
const featureUsageExceeded = !value && // if flag is not false, then we haven't exceeded usage
|
|
768
781
|
(ruleType == "company_override_usage_exceeded" || // if the rule type is one of these, then we have exceeded usage
|
|
769
782
|
ruleType == "plan_entitlement_usage_exceeded");
|
|
783
|
+
const resolvedAllocation = entitlement?.allocation ?? featureAllocation;
|
|
784
|
+
const resolvedUsage = entitlement?.usage ?? featureUsage;
|
|
785
|
+
const resolvedEvent = entitlement?.eventName ?? featureUsageEvent;
|
|
786
|
+
const resolvedPeriod = entitlement?.metricPeriod ?? featureUsagePeriod;
|
|
787
|
+
const resolvedResetAt = entitlement?.metricResetAt ?? featureUsageResetAt;
|
|
770
788
|
return {
|
|
771
789
|
featureUsageExceeded,
|
|
772
790
|
companyId: companyId == null ? void 0 : companyId,
|
|
791
|
+
creditRemaining: entitlement?.creditRemaining == null ? void 0 : entitlement.creditRemaining,
|
|
773
792
|
error: error == null ? void 0 : error,
|
|
774
|
-
featureAllocation:
|
|
775
|
-
featureUsage:
|
|
776
|
-
featureUsageEvent:
|
|
777
|
-
featureUsagePeriod:
|
|
778
|
-
featureUsageResetAt:
|
|
793
|
+
featureAllocation: resolvedAllocation == null ? void 0 : resolvedAllocation,
|
|
794
|
+
featureUsage: resolvedUsage == null ? void 0 : resolvedUsage,
|
|
795
|
+
featureUsageEvent: resolvedEvent == null ? void 0 : resolvedEvent,
|
|
796
|
+
featureUsagePeriod: resolvedPeriod == null ? void 0 : resolvedPeriod,
|
|
797
|
+
featureUsageResetAt: resolvedResetAt == null ? void 0 : resolvedResetAt,
|
|
779
798
|
flag,
|
|
780
799
|
flagId: flagId == null ? void 0 : flagId,
|
|
781
800
|
reason,
|
|
782
801
|
ruleId: ruleId == null ? void 0 : ruleId,
|
|
783
802
|
ruleType: ruleType == null ? void 0 : ruleType,
|
|
803
|
+
softLimit: entitlement?.softLimit == null ? void 0 : entitlement.softLimit,
|
|
784
804
|
userId: userId == null ? void 0 : userId,
|
|
785
805
|
value
|
|
786
806
|
};
|
|
787
807
|
};
|
|
788
808
|
var CheckPlanReturnFromJSON = (json) => {
|
|
789
|
-
const { id, name, trialEndDate } = DatastreamCompanyPlanFromJSON(json);
|
|
809
|
+
const { id, name, trialEndDate, trialStatus } = DatastreamCompanyPlanFromJSON(json);
|
|
790
810
|
return {
|
|
791
811
|
id,
|
|
792
812
|
name,
|
|
793
|
-
trialEndDate: trialEndDate == null ? void 0 : trialEndDate
|
|
813
|
+
trialEndDate: trialEndDate == null ? void 0 : trialEndDate,
|
|
814
|
+
trialStatus: trialStatus == null ? void 0 : trialStatus
|
|
794
815
|
};
|
|
795
816
|
};
|
|
796
817
|
function contextString(context) {
|
|
@@ -807,7 +828,7 @@ function contextString(context) {
|
|
|
807
828
|
}, {});
|
|
808
829
|
return JSON.stringify(sortedContext);
|
|
809
830
|
}
|
|
810
|
-
var version = "1.
|
|
831
|
+
var version = "1.4.0";
|
|
811
832
|
var anonymousIdKey = "schematicId";
|
|
812
833
|
var Schematic = class {
|
|
813
834
|
additionalHeaders = {};
|
|
@@ -2244,7 +2265,7 @@ var notifyPlanListener = (listener, value) => {
|
|
|
2244
2265
|
import React, { createContext, useEffect, useMemo, useRef } from "react";
|
|
2245
2266
|
|
|
2246
2267
|
// src/version.ts
|
|
2247
|
-
var version2 = "1.
|
|
2268
|
+
var version2 = "1.4.0";
|
|
2248
2269
|
|
|
2249
2270
|
// src/context/schematic.tsx
|
|
2250
2271
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -2370,7 +2391,12 @@ var useSchematicPlan = (opts) => {
|
|
|
2370
2391
|
const fallback = opts?.fallback;
|
|
2371
2392
|
const fallbackPlan = useMemo2(
|
|
2372
2393
|
() => fallback,
|
|
2373
|
-
[
|
|
2394
|
+
[
|
|
2395
|
+
fallback?.id,
|
|
2396
|
+
fallback?.name,
|
|
2397
|
+
fallback?.trialEndDate?.getTime(),
|
|
2398
|
+
fallback?.trialStatus
|
|
2399
|
+
]
|
|
2374
2400
|
);
|
|
2375
2401
|
const subscribe = useCallback(
|
|
2376
2402
|
(callback) => client.addPlanListener(callback),
|
|
@@ -2395,6 +2421,7 @@ export {
|
|
|
2395
2421
|
RuleType,
|
|
2396
2422
|
Schematic,
|
|
2397
2423
|
SchematicProvider,
|
|
2424
|
+
TrialStatus,
|
|
2398
2425
|
UsagePeriod,
|
|
2399
2426
|
useSchematic,
|
|
2400
2427
|
useSchematicContext,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schematichq/schematic-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.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",
|
|
@@ -30,31 +30,29 @@
|
|
|
30
30
|
"tsc": "npx tsc",
|
|
31
31
|
"prepare": "husky"
|
|
32
32
|
},
|
|
33
|
-
"dependencies": {
|
|
34
|
-
"@schematichq/schematic-js": "^1.3.0"
|
|
35
|
-
},
|
|
36
33
|
"devDependencies": {
|
|
37
34
|
"@eslint/js": "^10.0.1",
|
|
38
|
-
"@microsoft/api-extractor": "^7.
|
|
35
|
+
"@microsoft/api-extractor": "^7.58.2",
|
|
36
|
+
"@schematichq/schematic-js": "^1.4.0",
|
|
39
37
|
"@testing-library/dom": "^10.4.1",
|
|
40
38
|
"@testing-library/jest-dom": "^6.9.1",
|
|
41
39
|
"@testing-library/react": "^16.3.2",
|
|
42
40
|
"@types/react": "^19.2.14",
|
|
43
41
|
"@vitest/browser": "^4.0.18",
|
|
44
|
-
"esbuild": "^0.
|
|
45
|
-
"eslint": "^10.0
|
|
42
|
+
"esbuild": "^0.28.0",
|
|
43
|
+
"eslint": "^10.2.0",
|
|
46
44
|
"eslint-plugin-import": "^2.32.0",
|
|
47
45
|
"eslint-plugin-react": "^7.37.5",
|
|
48
|
-
"eslint-plugin-react-hooks": "^7.0
|
|
49
|
-
"globals": "^17.
|
|
50
|
-
"happy-dom": "^20.
|
|
46
|
+
"eslint-plugin-react-hooks": "^7.1.0",
|
|
47
|
+
"globals": "^17.5.0",
|
|
48
|
+
"happy-dom": "^20.9.0",
|
|
51
49
|
"husky": "^9.1.7",
|
|
52
|
-
"jsdom": "^29.0.
|
|
53
|
-
"prettier": "^3.8.
|
|
54
|
-
"react": "^19.2.
|
|
55
|
-
"react-dom": "^19.2.
|
|
56
|
-
"typescript": "^
|
|
57
|
-
"typescript-eslint": "^8.
|
|
50
|
+
"jsdom": "^29.0.2",
|
|
51
|
+
"prettier": "^3.8.3",
|
|
52
|
+
"react": "^19.2.5",
|
|
53
|
+
"react-dom": "^19.2.5",
|
|
54
|
+
"typescript": "^6.0.3",
|
|
55
|
+
"typescript-eslint": "^8.58.2",
|
|
58
56
|
"vitest": "^4.0.18"
|
|
59
57
|
},
|
|
60
58
|
"peerDependencies": {
|