@schematichq/schematic-react 0.1.3 → 0.1.5
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 +19 -19
- package/dist/schematic-react.d.ts +3 -0
- package/dist/schematic-react.esm.js +19 -19
- package/package.json +2 -2
|
@@ -72,8 +72,9 @@ var v4_default = v4;
|
|
|
72
72
|
var anonymousIdKey = "schematicId";
|
|
73
73
|
var Schematic = class {
|
|
74
74
|
apiKey;
|
|
75
|
-
apiUrl = "api.schematichq.com";
|
|
76
|
-
|
|
75
|
+
apiUrl = "https://api.schematichq.com";
|
|
76
|
+
webSocketUrl = "wss://api.schematichq.com";
|
|
77
|
+
eventUrl = "https://c.schematichq.com";
|
|
77
78
|
conn = null;
|
|
78
79
|
context = {};
|
|
79
80
|
eventQueue;
|
|
@@ -97,6 +98,9 @@ var Schematic = class {
|
|
|
97
98
|
if (options?.eventUrl !== void 0) {
|
|
98
99
|
this.eventUrl = options.eventUrl;
|
|
99
100
|
}
|
|
101
|
+
if (options?.webSocketUrl !== void 0) {
|
|
102
|
+
this.webSocketUrl = options.webSocketUrl;
|
|
103
|
+
}
|
|
100
104
|
if (typeof window !== "undefined") {
|
|
101
105
|
window.addEventListener("beforeunload", () => {
|
|
102
106
|
this.flushEventQueue();
|
|
@@ -110,7 +114,7 @@ var Schematic = class {
|
|
|
110
114
|
const contextVals = this.values[contextString(context)] ?? {};
|
|
111
115
|
return typeof contextVals[key] === "undefined" ? fallback : contextVals[key];
|
|
112
116
|
}
|
|
113
|
-
const requestUrl = this.
|
|
117
|
+
const requestUrl = `${this.apiUrl}/flags/${key}/check`;
|
|
114
118
|
return fetch(requestUrl, {
|
|
115
119
|
method: "POST",
|
|
116
120
|
headers: {
|
|
@@ -133,7 +137,7 @@ var Schematic = class {
|
|
|
133
137
|
// Make a REST API call to fetch all flag values for a given context
|
|
134
138
|
checkFlags = async (context) => {
|
|
135
139
|
context = context || this.context;
|
|
136
|
-
const requestUrl = this.
|
|
140
|
+
const requestUrl = `${this.apiUrl}/flags/check`;
|
|
137
141
|
const requestBody = JSON.stringify(context);
|
|
138
142
|
return fetch(requestUrl, {
|
|
139
143
|
method: "POST",
|
|
@@ -189,16 +193,6 @@ var Schematic = class {
|
|
|
189
193
|
track = (body) => {
|
|
190
194
|
this.handleEvent("track", body);
|
|
191
195
|
};
|
|
192
|
-
getUrl = (domain, path, urlType) => {
|
|
193
|
-
let scheme = "http";
|
|
194
|
-
if (urlType === "ws") {
|
|
195
|
-
scheme = "ws";
|
|
196
|
-
}
|
|
197
|
-
if (typeof window === "undefined" || window.location.protocol === "https:") {
|
|
198
|
-
return `${scheme}s://${domain}/${path}`;
|
|
199
|
-
}
|
|
200
|
-
return `${scheme}://${domain}/${path}`;
|
|
201
|
-
};
|
|
202
196
|
flushEventQueue = () => {
|
|
203
197
|
while (this.eventQueue.length > 0) {
|
|
204
198
|
const event = this.eventQueue.shift();
|
|
@@ -235,7 +229,7 @@ var Schematic = class {
|
|
|
235
229
|
}
|
|
236
230
|
};
|
|
237
231
|
sendEvent = (event) => {
|
|
238
|
-
const captureUrl = this.
|
|
232
|
+
const captureUrl = `${this.eventUrl}/e`;
|
|
239
233
|
const payload = JSON.stringify(event);
|
|
240
234
|
fetch(captureUrl, {
|
|
241
235
|
method: "POST",
|
|
@@ -261,7 +255,7 @@ var Schematic = class {
|
|
|
261
255
|
if (this.conn) {
|
|
262
256
|
resolve();
|
|
263
257
|
}
|
|
264
|
-
const wsUrl = this.
|
|
258
|
+
const wsUrl = `${this.webSocketUrl}/flags/bootstrap`;
|
|
265
259
|
const webSocket = new WebSocket(wsUrl);
|
|
266
260
|
this.conn = webSocket;
|
|
267
261
|
webSocket.onopen = () => {
|
|
@@ -343,8 +337,11 @@ var SchematicContext = (0, import_react.createContext)({
|
|
|
343
337
|
flagValues: {}
|
|
344
338
|
});
|
|
345
339
|
var SchematicProvider = ({
|
|
340
|
+
apiUrl,
|
|
341
|
+
children,
|
|
342
|
+
eventUrl,
|
|
346
343
|
publishableKey,
|
|
347
|
-
|
|
344
|
+
webSocketUrl
|
|
348
345
|
}) => {
|
|
349
346
|
const [client, setClient] = (0, import_react.useState)();
|
|
350
347
|
const [flagValues, setFlagValues] = (0, import_react.useState)({});
|
|
@@ -353,12 +350,15 @@ var SchematicProvider = ({
|
|
|
353
350
|
return;
|
|
354
351
|
}
|
|
355
352
|
const client2 = new Schematic(publishableKey, {
|
|
353
|
+
apiUrl,
|
|
354
|
+
eventUrl,
|
|
356
355
|
flagListener: setFlagValues,
|
|
357
|
-
useWebSocket: true
|
|
356
|
+
useWebSocket: true,
|
|
357
|
+
webSocketUrl
|
|
358
358
|
});
|
|
359
359
|
setClient(client2);
|
|
360
360
|
return client2.cleanup;
|
|
361
|
-
}, [publishableKey]);
|
|
361
|
+
}, [apiUrl, eventUrl, publishableKey, webSocketUrl]);
|
|
362
362
|
const contextValue = {
|
|
363
363
|
client,
|
|
364
364
|
flagValues
|
|
@@ -47,6 +47,9 @@ export declare const SchematicProvider: React_2.FC<SchematicProviderProps>;
|
|
|
47
47
|
declare interface SchematicProviderProps {
|
|
48
48
|
children: ReactNode;
|
|
49
49
|
publishableKey?: string;
|
|
50
|
+
apiUrl?: string;
|
|
51
|
+
eventUrl?: string;
|
|
52
|
+
webSocketUrl?: string;
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
export { Traits }
|
|
@@ -42,8 +42,9 @@ var v4_default = v4;
|
|
|
42
42
|
var anonymousIdKey = "schematicId";
|
|
43
43
|
var Schematic = class {
|
|
44
44
|
apiKey;
|
|
45
|
-
apiUrl = "api.schematichq.com";
|
|
46
|
-
|
|
45
|
+
apiUrl = "https://api.schematichq.com";
|
|
46
|
+
webSocketUrl = "wss://api.schematichq.com";
|
|
47
|
+
eventUrl = "https://c.schematichq.com";
|
|
47
48
|
conn = null;
|
|
48
49
|
context = {};
|
|
49
50
|
eventQueue;
|
|
@@ -67,6 +68,9 @@ var Schematic = class {
|
|
|
67
68
|
if (options?.eventUrl !== void 0) {
|
|
68
69
|
this.eventUrl = options.eventUrl;
|
|
69
70
|
}
|
|
71
|
+
if (options?.webSocketUrl !== void 0) {
|
|
72
|
+
this.webSocketUrl = options.webSocketUrl;
|
|
73
|
+
}
|
|
70
74
|
if (typeof window !== "undefined") {
|
|
71
75
|
window.addEventListener("beforeunload", () => {
|
|
72
76
|
this.flushEventQueue();
|
|
@@ -80,7 +84,7 @@ var Schematic = class {
|
|
|
80
84
|
const contextVals = this.values[contextString(context)] ?? {};
|
|
81
85
|
return typeof contextVals[key] === "undefined" ? fallback : contextVals[key];
|
|
82
86
|
}
|
|
83
|
-
const requestUrl = this.
|
|
87
|
+
const requestUrl = `${this.apiUrl}/flags/${key}/check`;
|
|
84
88
|
return fetch(requestUrl, {
|
|
85
89
|
method: "POST",
|
|
86
90
|
headers: {
|
|
@@ -103,7 +107,7 @@ var Schematic = class {
|
|
|
103
107
|
// Make a REST API call to fetch all flag values for a given context
|
|
104
108
|
checkFlags = async (context) => {
|
|
105
109
|
context = context || this.context;
|
|
106
|
-
const requestUrl = this.
|
|
110
|
+
const requestUrl = `${this.apiUrl}/flags/check`;
|
|
107
111
|
const requestBody = JSON.stringify(context);
|
|
108
112
|
return fetch(requestUrl, {
|
|
109
113
|
method: "POST",
|
|
@@ -159,16 +163,6 @@ var Schematic = class {
|
|
|
159
163
|
track = (body) => {
|
|
160
164
|
this.handleEvent("track", body);
|
|
161
165
|
};
|
|
162
|
-
getUrl = (domain, path, urlType) => {
|
|
163
|
-
let scheme = "http";
|
|
164
|
-
if (urlType === "ws") {
|
|
165
|
-
scheme = "ws";
|
|
166
|
-
}
|
|
167
|
-
if (typeof window === "undefined" || window.location.protocol === "https:") {
|
|
168
|
-
return `${scheme}s://${domain}/${path}`;
|
|
169
|
-
}
|
|
170
|
-
return `${scheme}://${domain}/${path}`;
|
|
171
|
-
};
|
|
172
166
|
flushEventQueue = () => {
|
|
173
167
|
while (this.eventQueue.length > 0) {
|
|
174
168
|
const event = this.eventQueue.shift();
|
|
@@ -205,7 +199,7 @@ var Schematic = class {
|
|
|
205
199
|
}
|
|
206
200
|
};
|
|
207
201
|
sendEvent = (event) => {
|
|
208
|
-
const captureUrl = this.
|
|
202
|
+
const captureUrl = `${this.eventUrl}/e`;
|
|
209
203
|
const payload = JSON.stringify(event);
|
|
210
204
|
fetch(captureUrl, {
|
|
211
205
|
method: "POST",
|
|
@@ -231,7 +225,7 @@ var Schematic = class {
|
|
|
231
225
|
if (this.conn) {
|
|
232
226
|
resolve();
|
|
233
227
|
}
|
|
234
|
-
const wsUrl = this.
|
|
228
|
+
const wsUrl = `${this.webSocketUrl}/flags/bootstrap`;
|
|
235
229
|
const webSocket = new WebSocket(wsUrl);
|
|
236
230
|
this.conn = webSocket;
|
|
237
231
|
webSocket.onopen = () => {
|
|
@@ -318,8 +312,11 @@ var SchematicContext = createContext({
|
|
|
318
312
|
flagValues: {}
|
|
319
313
|
});
|
|
320
314
|
var SchematicProvider = ({
|
|
315
|
+
apiUrl,
|
|
316
|
+
children,
|
|
317
|
+
eventUrl,
|
|
321
318
|
publishableKey,
|
|
322
|
-
|
|
319
|
+
webSocketUrl
|
|
323
320
|
}) => {
|
|
324
321
|
const [client, setClient] = useState();
|
|
325
322
|
const [flagValues, setFlagValues] = useState({});
|
|
@@ -328,12 +325,15 @@ var SchematicProvider = ({
|
|
|
328
325
|
return;
|
|
329
326
|
}
|
|
330
327
|
const client2 = new Schematic(publishableKey, {
|
|
328
|
+
apiUrl,
|
|
329
|
+
eventUrl,
|
|
331
330
|
flagListener: setFlagValues,
|
|
332
|
-
useWebSocket: true
|
|
331
|
+
useWebSocket: true,
|
|
332
|
+
webSocketUrl
|
|
333
333
|
});
|
|
334
334
|
setClient(client2);
|
|
335
335
|
return client2.cleanup;
|
|
336
|
-
}, [publishableKey]);
|
|
336
|
+
}, [apiUrl, eventUrl, publishableKey, webSocketUrl]);
|
|
337
337
|
const contextValue = {
|
|
338
338
|
client,
|
|
339
339
|
flagValues
|
package/package.json
CHANGED
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"test": "jest --config jest.config.js"
|
|
43
43
|
},
|
|
44
44
|
"types": "dist/schematic-react.d.ts",
|
|
45
|
-
"version": "0.1.
|
|
45
|
+
"version": "0.1.5",
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@schematichq/schematic-js": "^0.1.
|
|
47
|
+
"@schematichq/schematic-js": "^0.1.5"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"react": ">=18"
|