@schematichq/schematic-js 0.0.12 → 0.0.13
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";(()=>{var d,v=new Uint8Array(16);function y(){if(!d&&(d=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!d))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return d(v)}var o=[];for(let t=0;t<256;++t)o.push((t+256).toString(16).slice(1));function h(t,e=0){return o[t[e+0]]+o[t[e+1]]+o[t[e+2]]+o[t[e+3]]+"-"+o[t[e+4]]+o[t[e+5]]+"-"+o[t[e+6]]+o[t[e+7]]+"-"+o[t[e+8]]+o[t[e+9]]+"-"+o[t[e+10]]+o[t[e+11]]+o[t[e+12]]+o[t[e+13]]+o[t[e+14]]+o[t[e+15]]}var
|
|
1
|
+
"use strict";(()=>{var d,v=new Uint8Array(16);function y(){if(!d&&(d=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!d))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return d(v)}var o=[];for(let t=0;t<256;++t)o.push((t+256).toString(16).slice(1));function h(t,e=0){return o[t[e+0]]+o[t[e+1]]+o[t[e+2]]+o[t[e+3]]+"-"+o[t[e+4]]+o[t[e+5]]+"-"+o[t[e+6]]+o[t[e+7]]+"-"+o[t[e+8]]+o[t[e+9]]+"-"+o[t[e+10]]+o[t[e+11]]+o[t[e+12]]+o[t[e+13]]+o[t[e+14]]+o[t[e+15]]}var g=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),c={randomUUID:g};function m(t,e,r){if(c.randomUUID&&!e&&!t)return c.randomUUID();t=t||{};let i=t.random||(t.rng||y)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,e){r=r||0;for(let n=0;n<16;++n)e[r+n]=i[n];return e}return h(i)}var a=m;var l="schematicId";var p=class{apiKey;eventQueue;storage;constructor(e,r){this.apiKey=e,this.eventQueue=[],r?this.storage=r:typeof localStorage<"u"&&(this.storage=localStorage),typeof window<"u"&&window.addEventListener("beforeunload",()=>{this.flushEventQueue()})}sendEvent(e){let r="https://c.schematichq.com/e",i=JSON.stringify(e);fetch(r,{method:"POST",headers:{"Content-Type":"application/json;charset=UTF-8"},body:i}).then(n=>{if(!n.ok)throw new Error(`Network response was not ok: ${n.statusText}`)}).catch(n=>{console.error("There was a problem with the fetch operation:",n)})}flushEventQueue(){for(;this.eventQueue.length>0;){let e=this.eventQueue.shift();e&&this.sendEvent(e)}}storeEvent(e){this.eventQueue.push(e)}handleEvent(e,r){let i={api_key:this.apiKey,body:r,sent_at:new Date().toISOString(),tracker_event_id:a(),tracker_user_id:this.getAnonymousId(),type:e};typeof document<"u"&&document.hidden?this.storeEvent(i):this.sendEvent(i)}getAnonymousId(){if(!this.storage)return a();let e=this.storage.getItem(l);if(typeof e<"u")return e;let r=a();return this.storage.setItem(l,r),r}async checkFlag(e,r){let i=`https://api.schematichq.com/flags/${e}/check`,n=JSON.stringify(r);return fetch(i,{method:"POST",headers:{"X-Schematic-Api-Key":this.apiKey,"Content-Type":"application/json;charset=UTF-8"},body:n}).then(s=>{if(!s.ok)throw new Error("Network response was not ok");return s.json()}).then(s=>s.data.value).catch(s=>(console.error("There was a problem with the fetch operation:",s),!1))}async checkFlags(e){let r="https://api.schematichq.com/flags/check",i=JSON.stringify(e);return fetch(r,{method:"POST",headers:{"Content-Type":"application/json;charset=UTF-8","X-Schematic-Api-Key":this.apiKey},body:i}).then(n=>{if(!n.ok)throw new Error("Network response was not ok");return n.json()}).then(n=>n.data.flags.reduce((s,u)=>(s[u.flag]=u.value,s),{})).catch(n=>(console.error("There was a problem with the fetch operation:",n),!1))}identify(e){this.handleEvent("identify",e)}track(e){this.handleEvent("track",e)}};window.Schematic=p;})();
|
|
2
2
|
/* @preserve */
|
package/dist/schematic.cjs.js
CHANGED
|
@@ -150,9 +150,6 @@ var Schematic = class {
|
|
|
150
150
|
return generatedAnonymousId;
|
|
151
151
|
}
|
|
152
152
|
async checkFlag(key, context) {
|
|
153
|
-
if (!context.company) {
|
|
154
|
-
return Promise.resolve(false);
|
|
155
|
-
}
|
|
156
153
|
const requestUrl = `https://api.schematichq.com/flags/${key}/check`;
|
|
157
154
|
const requestBody = JSON.stringify(context);
|
|
158
155
|
return fetch(requestUrl, {
|
|
@@ -175,9 +172,6 @@ var Schematic = class {
|
|
|
175
172
|
});
|
|
176
173
|
}
|
|
177
174
|
async checkFlags(context) {
|
|
178
|
-
if (!context.company) {
|
|
179
|
-
return Promise.resolve({});
|
|
180
|
-
}
|
|
181
175
|
const requestUrl = "https://api.schematichq.com/flags/check";
|
|
182
176
|
const requestBody = JSON.stringify(context);
|
|
183
177
|
return fetch(requestUrl, {
|
package/dist/schematic.esm.js
CHANGED
|
@@ -124,9 +124,6 @@ var Schematic = class {
|
|
|
124
124
|
return generatedAnonymousId;
|
|
125
125
|
}
|
|
126
126
|
async checkFlag(key, context) {
|
|
127
|
-
if (!context.company) {
|
|
128
|
-
return Promise.resolve(false);
|
|
129
|
-
}
|
|
130
127
|
const requestUrl = `https://api.schematichq.com/flags/${key}/check`;
|
|
131
128
|
const requestBody = JSON.stringify(context);
|
|
132
129
|
return fetch(requestUrl, {
|
|
@@ -149,9 +146,6 @@ var Schematic = class {
|
|
|
149
146
|
});
|
|
150
147
|
}
|
|
151
148
|
async checkFlags(context) {
|
|
152
|
-
if (!context.company) {
|
|
153
|
-
return Promise.resolve({});
|
|
154
|
-
}
|
|
155
149
|
const requestUrl = "https://api.schematichq.com/flags/check";
|
|
156
150
|
const requestBody = JSON.stringify(context);
|
|
157
151
|
return fetch(requestUrl, {
|
package/package.json
CHANGED