New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@harnessio/ff-javascript-client-sdk

Package Overview
Dependencies
Maintainers
6
Versions
113
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@harnessio/ff-javascript-client-sdk - npm Package Compare versions

Comparing version 1.19.0-rc.5 to 1.19.1

1

dist/sdk.client-iife.js
var HarnessFFSDK=(()=>{var _=Object.defineProperty,De=Object.defineProperties,Ce=Object.getOwnPropertyDescriptor,Ae=Object.getOwnPropertyDescriptors,Fe=Object.getOwnPropertyNames,oe=Object.getOwnPropertySymbols;var le=Object.prototype.hasOwnProperty,xe=Object.prototype.propertyIsEnumerable;var se=(t,e,i)=>e in t?_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,O=(t,e)=>{for(var i in e||(e={}))le.call(e,i)&&se(t,i,e[i]);if(oe)for(var i of oe(e))xe.call(e,i)&&se(t,i,e[i]);return t},j=(t,e)=>De(t,Ae(e));var Pe=(t,e)=>{for(var i in e)_(t,i,{get:e[i],enumerable:!0})},ke=(t,e,i,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Fe(e))!le.call(t,s)&&s!==i&&_(t,s,{get:()=>e[s],enumerable:!(r=Ce(e,s))||r.enumerable});return t};var Ne=t=>ke(_({},"__esModule",{value:!0}),t);var D=(t,e,i)=>new Promise((r,s)=>{var d=R=>{try{b(i.next(R))}catch(c){s(c)}},h=R=>{try{b(i.throw(R))}catch(c){s(c)}},b=R=>R.done?r(R.value):Promise.resolve(R.value).then(d,h);b((i=i.apply(t,e)).next())});var $e={};Pe($e,{Event:()=>x,initialize:()=>Be});function J(t){this.message=t}J.prototype=new Error,J.prototype.name="InvalidCharacterError";var ce=typeof window!="undefined"&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new J("'atob' failed: The string to be decoded is not correctly encoded.");for(var i,r,s=0,d=0,h="";r=e.charAt(d++);~r&&(i=s%4?64*i+r:r,s++%4)?h+=String.fromCharCode(255&i>>(-2*s&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return h};function Ve(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(i){return decodeURIComponent(ce(i).replace(/(.)/g,function(r,s){var d=s.charCodeAt(0).toString(16).toUpperCase();return d.length<2&&(d="0"+d),"%"+d}))}(e)}catch(i){return ce(e)}}function M(t){this.message=t}function _e(t,e){if(typeof t!="string")throw new M("Invalid token specified");var i=(e=e||{}).header===!0?0:1;try{return JSON.parse(Ve(t.split(".")[i]))}catch(r){throw new M("Invalid token specified: "+r.message)}}M.prototype=new Error,M.prototype.name="InvalidTokenError";var de=_e;function ue(t){return{all:t=t||new Map,on:function(e,i){var r=t.get(e);r&&r.push(i)||t.set(e,[i])},off:function(e,i){var r=t.get(e);r&&r.splice(r.indexOf(i)>>>0,1)},emit:function(e,i){(t.get(e)||[]).slice().map(function(r){r(i)}),(t.get("*")||[]).slice().map(function(r){r(e,i)})}}}var x=(g=>(g.READY="ready",g.CONNECTED="connected",g.DISCONNECTED="disconnected",g.STOPPED="stopped",g.POLLING="polling",g.POLLING_STOPPED="polling stopped",g.FLAGS_LOADED="flags loaded",g.CACHE_LOADED="cache loaded",g.CHANGED="changed",g.ERROR="error",g.ERROR_METRICS="metrics error",g.ERROR_AUTH="auth error",g.ERROR_FETCH_FLAGS="fetch flags error",g.ERROR_FETCH_FLAG="fetch flag error",g.ERROR_STREAM="stream error",g))(x||{});var Me={debug:!1,baseUrl:"https://config.ff.harness.io/api/1.0",eventUrl:"https://events.ff.harness.io/api/1.0",eventsSyncInterval:6e4,pollingInterval:6e4,streamEnabled:!0,allAttributesPrivate:!1,privateAttributeNames:[],cache:!1},fe=t=>{let e=O(O({},Me),t);return e.pollingEnabled===void 0&&(e.pollingEnabled=e.streamEnabled),e},y=(t,...e)=>console.error(`[FF-SDK] ${t}`,...e),W=(t,e=!0)=>{e?setTimeout(t,0):t()},L=(t,e)=>Math.round(Math.random()*(e-t)+t);function Y(t){return"HARNESS_FF_CACHE_"+t}function H(t,e={}){let i=Y(t),r=parseInt(window.localStorage.getItem(i+".ts"));if(e!=null&&e.ttl&&!isNaN(r)&&r+e.ttl<Date.now())return Le(t),[];let s=window.localStorage.getItem(i);if(s)try{return JSON.parse(s)}catch(d){}return[]}function G(t,e){let i=Y(t);window.localStorage.setItem(i,JSON.stringify(e)),window.localStorage.setItem(i+".ts",Date.now().toString())}function ge(t,e){let i=H(t),r=i.find(({flag:s})=>s===e.flag);r?Object.assign(r,e):i.push(e),G(t,i)}function he(t,e){let i=H(t),r=i.findIndex(({flag:s})=>s===e);r>-1&&(i.splice(r,1),G(t,i))}function Le(t){let e=Y(t);window.localStorage.removeItem(e),window.localStorage.removeItem(e+".ts")}function X(t){return function(...i){let[r,s]=t(i);return fetch(r,s)}}var pe=3e4,B=class{constructor(e,i,r,s,d,h,b){this.closed=!1;this.connectionOpened=!1;this.disconnectEventEmitted=!1;this.eventBus=e,this.configurations=i,this.url=r,this.apiKey=s,this.standardHeaders=d,this.eventCallback=b,this.fallbackPoller=h}start(){let e=c=>{c.toString().split(/\r?\n/).forEach(i)},i=c=>{if(c.startsWith("data:")){let w=JSON.parse(c.substring(5));this.logDebug("Received event from stream: ",w),this.eventCallback(w)}},r=()=>{this.logDebug("Stream connected"),this.eventBus.emit("connected")},s=()=>{clearInterval(this.readTimeoutCheckerId);let c=L(1e3,1e4);this.logDebug("Stream disconnected, will reconnect in "+c+"ms"),this.disconnectEventEmitted||(this.eventBus.emit("disconnected"),this.disconnectEventEmitted=!0),setTimeout(()=>this.start(),c)},d=c=>{c&&y("Stream has issue",c),this.fallBackToPolling(),this.eventBus.emit("stream error",c),this.eventBus.emit("error",c),s()},h=O({"Cache-Control":"no-cache",Accept:"text/event-stream","API-Key":this.apiKey},this.standardHeaders);this.logDebug("SSE HTTP start request",this.url),this.xhr=new XMLHttpRequest,this.xhr.open("GET",this.url);for(let[c,w]of Object.entries(h))this.xhr.setRequestHeader(c,w);this.xhr.timeout=24*60*60*1e3,this.xhr.onerror=()=>{this.connectionOpened=!1,d("XMLHttpRequest error on SSE stream")},this.xhr.onabort=()=>{this.connectionOpened=!1,this.logDebug("SSE aborted"),this.closed||d(null)},this.xhr.ontimeout=()=>{this.connectionOpened=!1,d("SSE timeout")},this.xhr.onload=()=>{if(this.xhr.status>=400&&this.xhr.status<=599){d(`HTTP code ${this.xhr.status}`);return}this.connectionOpened||(r(),this.connectionOpened=!0,this.disconnectEventEmitted=!1)};let b=0,R=Date.now();this.xhr.onprogress=()=>{this.connectionOpened||(r(),this.connectionOpened=!0,this.disconnectEventEmitted=!1),this.stopFallBackPolling(),R=Date.now();let c=this.xhr.responseText.slice(b);b+=c.length,this.logDebug("SSE GOT: "+c),e(c)},this.readTimeoutCheckerId=setInterval(()=>{R<Date.now()-pe&&(y("SSE read timeout"),this.xhr.abort())},pe),this.xhr.send()}close(){this.connectionOpened=!1,this.closed=!0,this.xhr&&this.xhr.abort(),clearInterval(this.readTimeoutCheckerId),this.eventBus.emit("stopped"),this.stopFallBackPolling()}fallBackToPolling(){!this.fallbackPoller.isPolling()&&this.configurations.pollingEnabled&&(this.logDebug("Falling back to polling mode while stream recovers"),this.fallbackPoller.start())}stopFallBackPolling(){this.fallbackPoller.isPolling()&&(this.logDebug("Stopping fallback polling mode"),this.fallbackPoller.stop())}logDebug(e,...i){this.configurations.debug&&console.debug(`[FF-SDK] Streaming: ${e}`,...i)}};function ve(t,e,i,r,s){let d=t in i,h=d?i[t]:e;return d&&r(t,h),s?{value:h,isDefaultValue:!d}:h}var P=class{constructor(e,i,r){this.fetchFlagsFn=e;this.configurations=i;this.eventBus=r;this.maxAttempts=5}start(){if(this.isPolling()){this.logDebug("Already polling.");return}this.isRunning=!0,this.eventBus.emit("polling"),this.logDebug(`Starting poller, first poll will be in ${this.configurations.pollingInterval}ms`),this.timeoutId=setTimeout(()=>this.poll(),this.configurations.pollingInterval)}poll(){this.attemptFetch().finally(()=>{this.timeoutId=setTimeout(()=>this.poll(),this.configurations.pollingInterval)})}attemptFetch(){return D(this,null,function*(){for(let e=1;e<=this.maxAttempts;e++){let i=yield this.fetchFlagsFn();if(i.type==="success"){this.logDebug(`Successfully polled for flag updates, next poll in ${this.configurations.pollingInterval}ms. `);return}if(y("Error when polling for flag updates",i.error),e>=this.maxAttempts){this.logDebug(`Maximum attempts reached for polling for flags. Next poll in ${this.configurations.pollingInterval}ms.`);return}this.logDebug(`Polling for flags attempt #${e} failed. Remaining attempts: ${this.maxAttempts-e}`,i.error);let r=L(1e3,1e4);yield new Promise(s=>setTimeout(s,r))}})}stop(){this.timeoutId&&(clearTimeout(this.timeoutId),this.timeoutId=void 0,this.isRunning=!1,this.eventBus.emit("polling stopped"),this.logDebug("Polling stopped"))}isPolling(){return this.isRunning}logDebug(e,...i){this.configurations.debug&&console.debug(`[FF-SDK] Poller: ${e}`,...i)}};var Re="1.16.0",be=`Javascript ${Re} Client`,He=500,Ge=globalThis.fetch,z=!!globalThis.Proxy,Q=t=>{let{value:e}=t;try{switch(t.kind.toLowerCase()){case"int":case"number":e=Number(e);break;case"boolean":e=e.toString().toLowerCase()==="true";break;case"json":e=JSON.parse(e);break}}catch(i){y(i)}return e},Be=(t,e,i)=>{let r=!1,s,d,h,b,R,c,w=!0,F={},k=X(n=>n),Z=0,ee=!1,g=()=>{w=!1},N=()=>{w=!0},S=[],u=ue(),f=fe(i);f.eventsSyncInterval<6e4&&(f.eventsSyncInterval=6e4),f.pollingInterval<6e4&&(f.pollingInterval=6e4);let v=(n,...a)=>{f.debug&&console.debug(`[FF-SDK] ${n}`,...a)},$=n=>{if(w){let a=Date.now();a-n.lastAccessed>He&&(n.count++,n.lastAccessed=a)}};globalThis.onbeforeunload=()=>{S.length&&globalThis.localStorage&&(g(),globalThis.localStorage.HARNESS_FF_METRICS=JSON.stringify(S),N())};let Se=(n,a)=>D(void 0,null,function*(){return(yield(yield Ge(`${a.baseUrl}/client/auth`,{method:"POST",headers:{"Content-Type":"application/json","Harness-SDK-Info":be},body:JSON.stringify({apiKey:n,target:j(O({},e),{identifier:String(e.identifier)})})})).json()).authToken}),K=0,U=()=>{if(S.length){v("Sending metrics...",{metrics:S,evaluations:I});let n={metricsData:S.map(a=>({timestamp:Date.now(),count:a.count,metricsType:"FFMETRICS",attributes:[{key:"featureIdentifier",value:a.featureIdentifier},{key:"featureName",value:a.featureIdentifier},{key:"variationIdentifier",value:a.variationIdentifier},{key:"target",value:e.identifier},{key:"SDK_NAME",value:"JavaScript"},{key:"SDK_LANGUAGE",value:"JavaScript"},{key:"SDK_TYPE",value:"client"},{key:"SDK_VERSION",value:Re}]}))};k(`${f.eventUrl}/metrics/${s}?cluster=${d}`,{method:"POST",headers:O({"Content-Type":"application/json"},F),body:JSON.stringify(n)}).then(()=>{S=[],K=0}).catch(a=>{K++&&(S=[],K=0),v(a),u.emit("metrics error",a)}).finally(()=>{c=window.setTimeout(U,f.eventsSyncInterval)})}else c=window.setTimeout(U,f.eventsSyncInterval)},I={},Ie=n=>{v("Sending event for",n.flag),z?u.emit("changed",new Proxy(n,{get(a,l){var m;if(w&&a.hasOwnProperty(l)&&l==="value"){let E=a.flag,o=n.value,p=S.find(A=>A.featureIdentifier===E&&A.featureValue===o);p?($(p),p.variationIdentifier=((m=I[E])==null?void 0:m.identifier)||""):S.push({featureIdentifier:E,featureValue:String(o),variationIdentifier:I[E].identifier||"",count:1,lastAccessed:Date.now()}),v("Metrics event: Flag",l,"has been read with value via stream update",o)}return l==="value"?Q(n):n[l]}})):u.emit("changed",{deleted:n.deleted,flag:n.flag,value:Q(n)})},te=function(){return z?new Proxy({},{get(n,a){var m,E,o;let l=n[a];if(w&&n.hasOwnProperty(a)){let p=n[a],A=S.find(re=>re.featureIdentifier===a&&p===re.featureValue);A?(A.variationIdentifier=((m=I[a])==null?void 0:m.identifier)||"",$(A)):S.push({featureIdentifier:a,featureValue:p,variationIdentifier:((E=I[a])==null?void 0:E.identifier)||"",count:1,lastAccessed:Date.now()}),v("Metrics event: Flag:",a,"has been read with value:",p,"variationIdentifier:",(o=I[a])==null?void 0:o.identifier)}return l}}):{}},T=te();Se(t,f).then(n=>D(void 0,null,function*(){if(r)return;R=n;let a=de(n);if(F={Authorization:`Bearer ${R}`,"Harness-AccountID":a.accountID,"Harness-EnvironmentID":a.environmentIdentifier,"Harness-SDK-Info":be},v("Authenticated",a),globalThis.localStorage&&globalThis.localStorage.HARNESS_FF_METRICS)try{delete globalThis.localStorage.HARNESS_FF_METRICS,v("Picking up metrics from previous session")}catch(E){}c=window.setTimeout(U,f.eventsSyncInterval),s=a.environment,d=a.clusterIdentifier;let l=!!Object.keys(I).length;if((yield V()).type==="success"&&v("Fetch all flags ok",T),!r){if(f.streamEnabled?(v("Streaming mode enabled"),ye()):f.pollingEnabled?(v("Polling mode enabled"),we()):v("Streaming and polling mode disabled"),!l){g();let E=O({},T);N(),u.emit("ready",E)}ee=!0}})).catch(n=>{y("Authentication error: ",n),u.emit("auth error",n),u.emit("error",n)});let V=()=>D(void 0,null,function*(){try{let n=yield k(`${f.baseUrl}/client/env/${s}/target/${e.identifier}/evaluations?cluster=${d}`,{headers:F});if(n.ok){let a=yield n.json();return a.forEach(C),u.emit("flags loaded",a),{type:"success",data:a}}else return y("Features fetch operation error: ",n),u.emit("fetch flags error",n),u.emit("error",n),{type:"error",error:n}}catch(n){return y("Features fetch operation error: ",n),u.emit("fetch flags error",n),u.emit("error",n),{type:"error",error:n}}}),ie=n=>D(void 0,null,function*(){try{let a=yield k(`${f.baseUrl}/client/env/${s}/target/${e.identifier}/evaluations/${n}?cluster=${d}`,{headers:F});if(a.ok){let l=yield a.json();C(l)}else y("Feature fetch operation error: ",a),u.emit("fetch flag error",a),u.emit("error",a)}catch(a){y("Feature fetch operation error: ",a),u.emit("fetch flag error",a),u.emit("error",a)}}),C=n=>{g();let a=Q(n);a!==T[n.flag]&&(v("Flag variation has changed for ",n.identifier),T[n.flag]=a,I[n.flag]=j(O({},n),{value:a}),Ie(n)),N()};b=new P(V,f,u);let ye=()=>{let n=o=>{switch(o.event){case"create":l(o.evaluations)?o.evaluations.forEach(p=>{C(p)}):setTimeout(()=>ie(o.identifier),1e3);break;case"patch":l(o.evaluations)?o.evaluations.forEach(p=>{C(p)}):ie(o.identifier);break;case"delete":delete T[o.identifier],u.emit("changed",{flag:o.identifier,value:void 0,deleted:!0}),v("Evaluation deleted",{message:o,storage:T});break}},a=o=>!(!o||!o.flag||!o.identifier||!o.kind||!o.value),l=o=>!(!o||o.length==0||!o.every(p=>a(p))),m=o=>{o.event==="patch"&&(l(o.evaluations)?o.evaluations.forEach(p=>{C(p)}):V())},E=`${f.baseUrl}/stream?cluster=${d}`;h=new B(u,f,E,t,F,b,o=>{o.domain==="flag"?n(o):o.domain==="target-segment"&&m(o)}),h.start()},we=()=>{b.start()},q=(n,a)=>u.on(n,a),Oe=(n,a)=>{n?u.off(n,a):ne()},Te=(n,a)=>{var o;if(!w||z||a===void 0)return;let l=a,m=n,E=S.find(p=>p.featureIdentifier===m&&p.featureValue===l);E?($(E),E.variationIdentifier=((o=I[m])==null?void 0:o.identifier)||""):S.push({featureIdentifier:m,featureValue:l,count:1,variationIdentifier:I[m].identifier||"",lastAccessed:Date.now()})},ne=()=>{r=!0,f.streamEnabled&&(v("Closing event stream"),typeof(h==null?void 0:h.close)=="function"&&h.close(),u.all.clear()),f.pollingEnabled&&b.isPolling()&&(v("Closing Poller"),b.stop()),T=te(),I={},clearTimeout(c)},ae=(n,a=!0)=>{n.length&&W(()=>{let l=!!Object.keys(I).length;if(n.forEach(C),!l){g();let m=O({},T);N(),u.emit("ready",m)}},a)};if(f.cache&&"localStorage"in window){let n=!0,a=H(e.identifier,typeof f.cache=="boolean"?{}:f.cache);a!=null&&a.length&&W(()=>{v("loading from cache",a),ae(a,!1),u.emit("cache loaded",a)}),q("flags loaded",l=>{G(e.identifier,l),n=!1}),q("changed",l=>{n||(l.deleted?he(e.identifier,l.flag):ge(e.identifier,l))})}return{on:q,off:Oe,close:ne,setEvaluations:ae,registerAPIRequestMiddleware:n=>{k=X(n)},refreshEvaluations:()=>{ee&&!r&&Date.now()-Z>=6e4&&(V(),Z=Date.now())},variation:(n,a,l=!1)=>ve(n,a,T,Te,l)}};return Ne($e);})();
//# sourceMappingURL=sdk.client-iife.js.map

4

package.json
{
"name": "@harnessio/ff-javascript-client-sdk",
"version": "1.19.0-rc.5",
"version": "1.19.1",
"author": "Harness",

@@ -14,3 +14,3 @@ "license": "Apache-2.0",

"scripts": {
"build:client": "esbuild ./src/index.ts --minify --bundle --sourcemap --target=es2016 --format=iife --global-name=HarnessFFSDK --outfile=./dist/sdk.client-iife.js",
"build:client": "esbuild ./src/index.ts --minify --bundle --target=es2016 --format=iife --global-name=HarnessFFSDK --outfile=./dist/sdk.client-iife.js",
"build:client-esm": "esbuild ./src/index.ts --minify --bundle --target=es2016 --format=esm --outfile=./dist/sdk.client.js",

@@ -17,0 +17,0 @@ "build:esm": "esbuild ./src/index.ts --minify --bundle --target=es2016 --format=esm --external:jwt-decode --external:mitt --external:event-source-polyfill --outfile=./dist/sdk.esm.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc