@schematichq/schematic-react 1.0.0-rc.0 → 1.0.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 ADDED
@@ -0,0 +1,86 @@
1
+ # schematic-react
2
+
3
+ `schematic-react` is a client-side React library for [Schematic](https://schematichq.com) which provides hooks to track events, check flags, and more. `schematic-react` provides the same capabilities as [schematic-js](https://github.com/schematichq/schematic-js/tree/main/js), for React apps.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @schematichq/schematic-react
9
+ # or
10
+ yarn add @schematichq/schematic-react
11
+ # or
12
+ pnpm add @schematichq/schematic-react
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ You can use the `SchematicProvider` to wrap your application and provide the Schematic instance to all components:
18
+
19
+ ```tsx
20
+ import { SchematicProvider } from "@schematichq/schematic-react";
21
+
22
+ ReactDOM.render(
23
+ <SchematicProvider publishableKey="your-publishable-key">
24
+ <App />
25
+ </SchematicProvider>,
26
+ document.getElementById("root"),
27
+ );
28
+ ```
29
+
30
+ To set the user context for events and flag checks, you can use the `identify` function provided by the `useSchematicEvents` hook:
31
+
32
+ ```tsx
33
+ import { useSchematicEvents } from "@schematichq/schematic-react";
34
+
35
+ const MyComponent = () => {
36
+ const { identify } = useSchematicEvents();
37
+
38
+ useEffect(() => {
39
+ identify({
40
+ keys: { id: "my-user-id" },
41
+ company: {
42
+ keys: { id: "my-company-id" },
43
+ traits: { location: "Atlanta, GA" },
44
+ },
45
+ });
46
+ }, []);
47
+
48
+ return <div>My Component</div>;
49
+ };
50
+ ```
51
+
52
+ Once you've set the context with `identify`, you can track events:
53
+
54
+ ```tsx
55
+ import { useSchematicEvents } from "@schematichq/schematic-react";
56
+
57
+ const MyComponent = () => {
58
+ const { track } = useSchematicEvents();
59
+
60
+ useEffect(() => {
61
+ track({ event: "query" });
62
+ }, []);
63
+
64
+ return <div>My Component</div>;
65
+ };
66
+ ```
67
+
68
+ To check a flag, you can use the `useSchematicFlags` hook:
69
+
70
+ ```tsx
71
+ import { useSchematicFlag } from "@schematichq/schematic-react";
72
+
73
+ const MyComponent = () => {
74
+ const isFeatureEnabled = useSchematicFlag("my-flag-key");
75
+
76
+ return isFeatureEnabled ? <Feature /> : <Fallback />;
77
+ };
78
+ ```
79
+
80
+ ## License
81
+
82
+ MIT
83
+
84
+ ## Support
85
+
86
+ Need help? Please open a GitHub issue or reach out to [support@schematichq.com](mailto:support@schematichq.com) and we'll be happy to assist.
@@ -230,8 +230,8 @@ var require_browser_polyfill = __commonJS({
230
230
  function readArrayBufferAsText(buf) {
231
231
  var view = new Uint8Array(buf);
232
232
  var chars = new Array(view.length);
233
- for (var i = 0; i < view.length; i++) {
234
- chars[i] = String.fromCharCode(view[i]);
233
+ for (var i2 = 0; i2 < view.length; i2++) {
234
+ chars[i2] = String.fromCharCode(view[i2]);
235
235
  }
236
236
  return chars.join("");
237
237
  }
@@ -566,6 +566,14 @@ var require_browser_polyfill = __commonJS({
566
566
  })(typeof self !== "undefined" ? self : exports);
567
567
  }
568
568
  });
569
+ var byteToHex = [];
570
+ for (i = 0; i < 256; ++i) {
571
+ byteToHex.push((i + 256).toString(16).slice(1));
572
+ }
573
+ var i;
574
+ function unsafeStringify(arr, offset = 0) {
575
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
576
+ }
569
577
  var getRandomValues;
570
578
  var rnds8 = new Uint8Array(16);
571
579
  function rng() {
@@ -577,13 +585,6 @@ function rng() {
577
585
  }
578
586
  return getRandomValues(rnds8);
579
587
  }
580
- var byteToHex = [];
581
- for (let i = 0; i < 256; ++i) {
582
- byteToHex.push((i + 256).toString(16).slice(1));
583
- }
584
- function unsafeStringify(arr, offset = 0) {
585
- return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
586
- }
587
588
  var randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
588
589
  var native_default = {
589
590
  randomUUID
@@ -593,13 +594,13 @@ function v4(options, buf, offset) {
593
594
  return native_default.randomUUID();
594
595
  }
595
596
  options = options || {};
596
- const rnds = options.random || (options.rng || rng)();
597
+ var rnds = options.random || (options.rng || rng)();
597
598
  rnds[6] = rnds[6] & 15 | 64;
598
599
  rnds[8] = rnds[8] & 63 | 128;
599
600
  if (buf) {
600
601
  offset = offset || 0;
601
- for (let i = 0; i < 16; ++i) {
602
- buf[offset + i] = rnds[i];
602
+ for (var i2 = 0; i2 < 16; ++i2) {
603
+ buf[offset + i2] = rnds[i2];
603
604
  }
604
605
  return buf;
605
606
  }
@@ -188,8 +188,8 @@ var require_browser_polyfill = __commonJS({
188
188
  function readArrayBufferAsText(buf) {
189
189
  var view = new Uint8Array(buf);
190
190
  var chars = new Array(view.length);
191
- for (var i = 0; i < view.length; i++) {
192
- chars[i] = String.fromCharCode(view[i]);
191
+ for (var i2 = 0; i2 < view.length; i2++) {
192
+ chars[i2] = String.fromCharCode(view[i2]);
193
193
  }
194
194
  return chars.join("");
195
195
  }
@@ -524,6 +524,14 @@ var require_browser_polyfill = __commonJS({
524
524
  })(typeof self !== "undefined" ? self : exports);
525
525
  }
526
526
  });
527
+ var byteToHex = [];
528
+ for (i = 0; i < 256; ++i) {
529
+ byteToHex.push((i + 256).toString(16).slice(1));
530
+ }
531
+ var i;
532
+ function unsafeStringify(arr, offset = 0) {
533
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
534
+ }
527
535
  var getRandomValues;
528
536
  var rnds8 = new Uint8Array(16);
529
537
  function rng() {
@@ -535,13 +543,6 @@ function rng() {
535
543
  }
536
544
  return getRandomValues(rnds8);
537
545
  }
538
- var byteToHex = [];
539
- for (let i = 0; i < 256; ++i) {
540
- byteToHex.push((i + 256).toString(16).slice(1));
541
- }
542
- function unsafeStringify(arr, offset = 0) {
543
- return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
544
- }
545
546
  var randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
546
547
  var native_default = {
547
548
  randomUUID
@@ -551,13 +552,13 @@ function v4(options, buf, offset) {
551
552
  return native_default.randomUUID();
552
553
  }
553
554
  options = options || {};
554
- const rnds = options.random || (options.rng || rng)();
555
+ var rnds = options.random || (options.rng || rng)();
555
556
  rnds[6] = rnds[6] & 15 | 64;
556
557
  rnds[8] = rnds[8] & 63 | 128;
557
558
  if (buf) {
558
559
  offset = offset || 0;
559
- for (let i = 0; i < 16; ++i) {
560
- buf[offset + i] = rnds[i];
560
+ for (var i2 = 0; i2 < 16; ++i2) {
561
+ buf[offset + i2] = rnds[i2];
561
562
  }
562
563
  return buf;
563
564
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schematichq/schematic-react",
3
- "version": "1.0.0-rc.0",
3
+ "version": "1.0.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",
@@ -29,7 +29,7 @@
29
29
  "tsc": "npx tsc"
30
30
  },
31
31
  "dependencies": {
32
- "@schematichq/schematic-js": "^0.1.14"
32
+ "@schematichq/schematic-js": "^1.0.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@microsoft/api-extractor": "^7.47.9",