@schematichq/schematic-react 1.3.1 → 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/README.md +39 -0
- package/dist/schematic-react.cjs.js +15 -7
- package/dist/schematic-react.esm.js +15 -7
- package/package.json +12 -14
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).
|
|
@@ -809,6 +809,7 @@ var UsagePeriod = /* @__PURE__ */ ((UsagePeriod2) => {
|
|
|
809
809
|
var CheckFlagReturnFromJSON = (json) => {
|
|
810
810
|
const {
|
|
811
811
|
companyId,
|
|
812
|
+
entitlement,
|
|
812
813
|
error,
|
|
813
814
|
featureAllocation,
|
|
814
815
|
featureUsage,
|
|
@@ -826,20 +827,27 @@ var CheckFlagReturnFromJSON = (json) => {
|
|
|
826
827
|
const featureUsageExceeded = !value && // if flag is not false, then we haven't exceeded usage
|
|
827
828
|
(ruleType == "company_override_usage_exceeded" || // if the rule type is one of these, then we have exceeded usage
|
|
828
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;
|
|
829
835
|
return {
|
|
830
836
|
featureUsageExceeded,
|
|
831
837
|
companyId: companyId == null ? void 0 : companyId,
|
|
838
|
+
creditRemaining: entitlement?.creditRemaining == null ? void 0 : entitlement.creditRemaining,
|
|
832
839
|
error: error == null ? void 0 : error,
|
|
833
|
-
featureAllocation:
|
|
834
|
-
featureUsage:
|
|
835
|
-
featureUsageEvent:
|
|
836
|
-
featureUsagePeriod:
|
|
837
|
-
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,
|
|
838
845
|
flag,
|
|
839
846
|
flagId: flagId == null ? void 0 : flagId,
|
|
840
847
|
reason,
|
|
841
848
|
ruleId: ruleId == null ? void 0 : ruleId,
|
|
842
849
|
ruleType: ruleType == null ? void 0 : ruleType,
|
|
850
|
+
softLimit: entitlement?.softLimit == null ? void 0 : entitlement.softLimit,
|
|
843
851
|
userId: userId == null ? void 0 : userId,
|
|
844
852
|
value
|
|
845
853
|
};
|
|
@@ -867,7 +875,7 @@ function contextString(context) {
|
|
|
867
875
|
}, {});
|
|
868
876
|
return JSON.stringify(sortedContext);
|
|
869
877
|
}
|
|
870
|
-
var version = "1.
|
|
878
|
+
var version = "1.4.0";
|
|
871
879
|
var anonymousIdKey = "schematicId";
|
|
872
880
|
var Schematic = class {
|
|
873
881
|
additionalHeaders = {};
|
|
@@ -2304,7 +2312,7 @@ var notifyPlanListener = (listener, value) => {
|
|
|
2304
2312
|
var import_react = __toESM(require("react"));
|
|
2305
2313
|
|
|
2306
2314
|
// src/version.ts
|
|
2307
|
-
var version2 = "1.
|
|
2315
|
+
var version2 = "1.4.0";
|
|
2308
2316
|
|
|
2309
2317
|
// src/context/schematic.tsx
|
|
2310
2318
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -762,6 +762,7 @@ var UsagePeriod = /* @__PURE__ */ ((UsagePeriod2) => {
|
|
|
762
762
|
var CheckFlagReturnFromJSON = (json) => {
|
|
763
763
|
const {
|
|
764
764
|
companyId,
|
|
765
|
+
entitlement,
|
|
765
766
|
error,
|
|
766
767
|
featureAllocation,
|
|
767
768
|
featureUsage,
|
|
@@ -779,20 +780,27 @@ var CheckFlagReturnFromJSON = (json) => {
|
|
|
779
780
|
const featureUsageExceeded = !value && // if flag is not false, then we haven't exceeded usage
|
|
780
781
|
(ruleType == "company_override_usage_exceeded" || // if the rule type is one of these, then we have exceeded usage
|
|
781
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;
|
|
782
788
|
return {
|
|
783
789
|
featureUsageExceeded,
|
|
784
790
|
companyId: companyId == null ? void 0 : companyId,
|
|
791
|
+
creditRemaining: entitlement?.creditRemaining == null ? void 0 : entitlement.creditRemaining,
|
|
785
792
|
error: error == null ? void 0 : error,
|
|
786
|
-
featureAllocation:
|
|
787
|
-
featureUsage:
|
|
788
|
-
featureUsageEvent:
|
|
789
|
-
featureUsagePeriod:
|
|
790
|
-
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,
|
|
791
798
|
flag,
|
|
792
799
|
flagId: flagId == null ? void 0 : flagId,
|
|
793
800
|
reason,
|
|
794
801
|
ruleId: ruleId == null ? void 0 : ruleId,
|
|
795
802
|
ruleType: ruleType == null ? void 0 : ruleType,
|
|
803
|
+
softLimit: entitlement?.softLimit == null ? void 0 : entitlement.softLimit,
|
|
796
804
|
userId: userId == null ? void 0 : userId,
|
|
797
805
|
value
|
|
798
806
|
};
|
|
@@ -820,7 +828,7 @@ function contextString(context) {
|
|
|
820
828
|
}, {});
|
|
821
829
|
return JSON.stringify(sortedContext);
|
|
822
830
|
}
|
|
823
|
-
var version = "1.
|
|
831
|
+
var version = "1.4.0";
|
|
824
832
|
var anonymousIdKey = "schematicId";
|
|
825
833
|
var Schematic = class {
|
|
826
834
|
additionalHeaders = {};
|
|
@@ -2257,7 +2265,7 @@ var notifyPlanListener = (listener, value) => {
|
|
|
2257
2265
|
import React, { createContext, useEffect, useMemo, useRef } from "react";
|
|
2258
2266
|
|
|
2259
2267
|
// src/version.ts
|
|
2260
|
-
var version2 = "1.
|
|
2268
|
+
var version2 = "1.4.0";
|
|
2261
2269
|
|
|
2262
2270
|
// src/context/schematic.tsx
|
|
2263
2271
|
import { jsx } from "react/jsx-runtime";
|
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,12 +30,10 @@
|
|
|
30
30
|
"tsc": "npx tsc",
|
|
31
31
|
"prepare": "husky"
|
|
32
32
|
},
|
|
33
|
-
"dependencies": {
|
|
34
|
-
"@schematichq/schematic-js": "^1.3.1"
|
|
35
|
-
},
|
|
36
33
|
"devDependencies": {
|
|
37
34
|
"@eslint/js": "^10.0.1",
|
|
38
|
-
"@microsoft/api-extractor": "^7.58.
|
|
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",
|
|
@@ -45,16 +43,16 @@
|
|
|
45
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": "^6.0.
|
|
57
|
-
"typescript-eslint": "^8.58.
|
|
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": {
|