Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

launchdarkly-react-client-sdk

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

launchdarkly-react-client-sdk - npm Package Compare versions

Comparing version 3.3.2 to 3.4.0

2

lib/cjs/index.js

@@ -1,2 +0,2 @@

"use strict";var e=require("react"),t=require("launchdarkly-js-client-sdk"),r=require("lodash.camelcase"),n=require("hoist-non-react-statics");function o(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s=o(e);const i={useCamelCaseFlagKeys:!0,sendEventsOnFlagRead:!0},a=e.createContext({flags:{},flagKeyMap:{},ldClient:void 0}),{Provider:l,Consumer:c}=a,u=e=>{var t;return null!=(t=e.context)?t:e.user},p=e=>{const t={};for(const n in e)0!==n.indexOf("$")&&(t[r(n)]=e[n]);return t},f=(e,t)=>{const r={};for(const n in e)t&&void 0===t[n]||(r[n]=e[n].current);return r},d=(e,t)=>{const r=e.allFlags();return t?Object.keys(t).reduce(((e,n)=>(e[n]=Object.prototype.hasOwnProperty.call(r,n)?r[n]:t[n],e)),{}):r};function y(e,t,n=i,o){const s=function(e,t){if(void 0===t)return e;return Object.keys(t).reduce(((t,r)=>(h(e,r)&&(t[r]=e[r]),t)),{})}(t,o),{useCamelCaseFlagKeys:a=!0}=n,[l,c={}]=a?function(e){const t={},n={};for(const o in e){if(0===o.indexOf("$"))continue;const s=r(o);t[s]=e[o],n[s]=o}return[t,n]}(s):[s];return{flags:n.sendEventsOnFlagRead?O(e,l,c,a):l,flagKeyMap:c}}function h(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function O(e,t,r,n){return new Proxy(t,{get(t,o,s){const i=Reflect.get(t,o,s),a=n&&h(r,o)||h(t,o);if("symbol"==typeof o||!a)return i;if(void 0===i)return;const l=n?r[o]:o;return e.variation(l,i)}})}p.camelCaseKeys=p;const b={wrapperName:"react-client-sdk",wrapperVersion:"3.3.2",sendEventsOnlyForVariation:!0};var g=Object.defineProperty,v=Object.defineProperties,m=Object.getOwnPropertyDescriptors,x=Object.getOwnPropertySymbols,j=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable,P=(e,t,r)=>t in e?g(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,w=(e,t)=>{for(var r in t||(t={}))j.call(t,r)&&P(e,r,t[r]);if(x)for(var r of x(t))C.call(t,r)&&P(e,r,t[r]);return e},F=(e,t)=>v(e,m(t)),E=(e,t,r)=>new Promise(((n,o)=>{var s=e=>{try{a(r.next(e))}catch(e){o(e)}},i=e=>{try{a(r.throw(e))}catch(e){o(e)}},a=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,i);a((r=r.apply(e,t)).next())}));class D extends e.Component{constructor(e){super(e),this.getReactOptions=()=>w(w({},i),this.props.reactOptions),this.subscribeToChanges=e=>{const{flags:t}=this.props;e.on("change",(r=>{const n=this.getReactOptions(),o=f(r,t),s=w(w({},this.state.unproxiedFlags),o);Object.keys(o).length>0&&this.setState((r=>w(F(w({},r),{unproxiedFlags:s}),y(e,s,n,t))))}))},this.onFailed=(e,t)=>{this.setState((e=>F(w({},e),{error:t})))},this.onReady=(e,t,r)=>{const n=d(e,r);this.setState((o=>w(F(w({},o),{unproxiedFlags:n}),y(e,n,t,r))))},this.prepareLDClient=()=>E(this,null,(function*(){var e;const{clientSideID:r,flags:n,options:o}=this.props;let s=yield this.props.ldClient;const i=this.getReactOptions();let a,l=this.state.unproxiedFlags;if(s)l=d(s,n);else{const c=null!=(e=u(this.props))?e:{anonymous:!0,kind:"user"};s=t.initialize(r,c,w(w({},b),o));try{yield s.waitForInitialization(this.props.timeout),l=d(s,n)}catch(e){a=e,(null==a?void 0:a.name.toLowerCase().includes("timeout"))&&(s.on("failed",this.onFailed),s.on("ready",(()=>{this.onReady(s,i,n)})))}}this.setState((e=>F(w(F(w({},e),{unproxiedFlags:l}),y(s,l,i,n)),{ldClient:s,error:a}))),this.subscribeToChanges(s)}));const{options:r}=e;if(this.state={flags:{},unproxiedFlags:{},flagKeyMap:{}},r){const{bootstrap:e}=r;if(e&&"localStorage"!==e){const{useCamelCaseFlagKeys:t}=this.getReactOptions();this.state={flags:t?p(e):e,unproxiedFlags:e,flagKeyMap:{}}}}}componentDidMount(){return E(this,null,(function*(){const{deferInitialization:e}=this.props;e&&!u(this.props)||(yield this.prepareLDClient())}))}componentDidUpdate(e){return E(this,null,(function*(){const{deferInitialization:t}=this.props,r=!u(e)&&u(this.props);t&&r&&(yield this.prepareLDClient())}))}render(){const{flags:t,flagKeyMap:r,ldClient:n,error:o}=this.state;return e.createElement(l,{value:{flags:t,flagKeyMap:r,ldClient:n,error:o}},this.props.children)}}var S=Object.defineProperty,k=Object.defineProperties,K=Object.getOwnPropertyDescriptors,L=Object.getOwnPropertySymbols,I=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,z=(e,t,r)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,M=(e,t)=>{for(var r in t||(t={}))I.call(t,r)&&z(e,r,t[r]);if(L)for(var r of L(t))R.call(t,r)&&z(e,r,t[r]);return e};var q=Object.defineProperty,T=Object.defineProperties,V=Object.getOwnPropertyDescriptors,$=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,W=(e,t,r)=>t in e?q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,A=(e,t)=>{for(var r in t||(t={}))N.call(t,r)&&W(e,r,t[r]);if($)for(var r of $(t))U.call(t,r)&&W(e,r,t[r]);return e},B=(e,t)=>T(e,V(t));var G=Object.defineProperty,H=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable,X=(e,t,r)=>t in e?G(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Y=(e,t)=>{for(var r in t||(t={}))J.call(t,r)&&X(e,r,t[r]);if(H)for(var r of H(t))Q.call(t,r)&&X(e,r,t[r]);return e};exports.LDProvider=D,exports.asyncWithLDProvider=function(r){return n=this,o=null,s=function*(){var n;const{clientSideID:o,flags:s,options:a,reactOptions:c}=r,p=A(A({},i),c),h=null!=(n=u(r))?n:{anonymous:!0,kind:"user"};let O,g={};const v=t.initialize(o,h,A(A({},b),a));try{yield v.waitForInitialization(r.timeout),g=d(v,s)}catch(e){O=e}const m=(null==a?void 0:a.bootstrap)&&"localStorage"!==a.bootstrap?a.bootstrap:g;return({children:t})=>{const[r,n]=e.useState((()=>B(A({unproxiedFlags:m},y(v,m,p,s)),{ldClient:v,error:O})));e.useEffect((()=>{function e(e){const t=f(e,s);Object.keys(t).length>0&&n((e=>{const r=A(A({},e.unproxiedFlags),t);return A(B(A({},e),{unproxiedFlags:r}),y(v,r,p,s))}))}function t(){const e=d(v,s);n((t=>A(B(A({},t),{unproxiedFlags:e}),y(v,e,p,s))))}function r(e){n((t=>B(A({},t),{error:e})))}return v.on("change",e),(null==O?void 0:O.name.toLowerCase().includes("timeout"))&&(v.on("failed",r),v.on("ready",t)),function(){v.off("change",e),v.off("failed",r),v.off("ready",t)}}),[]);const o=((e,t)=>{var r={};for(var n in e)N.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&$)for(var n of $(e))t.indexOf(n)<0&&U.call(e,n)&&(r[n]=e[n]);return r})(r,["unproxiedFlags"]);return e.createElement(l,{value:o},t)}},new Promise(((e,t)=>{var r=e=>{try{a(s.next(e))}catch(e){t(e)}},i=e=>{try{a(s.throw(e))}catch(e){t(e)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(r,i);a((s=s.apply(n,o)).next())}));var n,o,s},exports.camelCaseKeys=p,exports.defaultReactOptions=i,exports.useFlags=()=>{const{flags:t}=e.useContext(a);return t},exports.useLDClient=()=>{const{ldClient:t}=e.useContext(a);return t},exports.useLDClientError=function(){const{error:t}=e.useContext(a);return t},exports.withLDConsumer=function(e={clientOnly:!1}){return function(t){return r=>s.createElement(c,null,(({flags:n,ldClient:o})=>e.clientOnly?s.createElement(t,Y({ldClient:o},r)):s.createElement(t,Y({flags:n,ldClient:o},r))))}},exports.withLDProvider=function(e){return function(t){const{reactOptions:r}=e,o=M(M({},i),r),a=(l=M({},e),k(l,K({reactOptions:o})));var l;function c(e){return s.createElement(D,M({},a),s.createElement(t,M({},e)))}return n(c,t),c}},Object.keys(t).forEach((function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})}));
"use strict";var e=require("react"),t=require("launchdarkly-js-client-sdk"),r=require("lodash.camelcase"),n=require("hoist-non-react-statics");function o(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s=o(e);const i={useCamelCaseFlagKeys:!0,sendEventsOnFlagRead:!0},a=e.createContext({flags:{},flagKeyMap:{},ldClient:void 0}),{Provider:l,Consumer:c}=a,u=e=>{var t;return null!=(t=e.context)?t:e.user},p=e=>{const t={};for(const n in e)0!==n.indexOf("$")&&(t[r(n)]=e[n]);return t},f=(e,t)=>{const r={};for(const n in e)t&&void 0===t[n]||(r[n]=e[n].current);return r},d=(e,t)=>{const r=e.allFlags();return t?Object.keys(t).reduce(((e,n)=>(e[n]=Object.prototype.hasOwnProperty.call(r,n)?r[n]:t[n],e)),{}):r};function y(e,t,n=i,o){const s=function(e,t){if(void 0===t)return e;return Object.keys(t).reduce(((t,r)=>(h(e,r)&&(t[r]=e[r]),t)),{})}(t,o),{useCamelCaseFlagKeys:a=!0}=n,[l,c={}]=a?function(e){const t={},n={};for(const o in e){if(0===o.indexOf("$"))continue;const s=r(o);t[s]=e[o],n[s]=o}return[t,n]}(s):[s];return{flags:n.sendEventsOnFlagRead?O(e,l,c,a):l,flagKeyMap:c}}function h(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function O(e,t,r,n){return new Proxy(t,{get(t,o,s){const i=Reflect.get(t,o,s),a=n&&h(r,o)||h(t,o);if("symbol"==typeof o||!a)return i;if(void 0===i)return;const l=n?r[o]:o;return e.variation(l,i)}})}p.camelCaseKeys=p;const b={wrapperName:"react-client-sdk",wrapperVersion:"3.4.0",sendEventsOnlyForVariation:!0};var g=Object.defineProperty,v=Object.defineProperties,m=Object.getOwnPropertyDescriptors,x=Object.getOwnPropertySymbols,j=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable,P=(e,t,r)=>t in e?g(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,w=(e,t)=>{for(var r in t||(t={}))j.call(t,r)&&P(e,r,t[r]);if(x)for(var r of x(t))C.call(t,r)&&P(e,r,t[r]);return e},F=(e,t)=>v(e,m(t)),E=(e,t,r)=>new Promise(((n,o)=>{var s=e=>{try{a(r.next(e))}catch(e){o(e)}},i=e=>{try{a(r.throw(e))}catch(e){o(e)}},a=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,i);a((r=r.apply(e,t)).next())}));class D extends e.Component{constructor(e){super(e),this.getReactOptions=()=>w(w({},i),this.props.reactOptions),this.subscribeToChanges=e=>{const{flags:t}=this.props;e.on("change",(r=>{const n=this.getReactOptions(),o=f(r,t),s=w(w({},this.state.unproxiedFlags),o);Object.keys(o).length>0&&this.setState((r=>w(F(w({},r),{unproxiedFlags:s}),y(e,s,n,t))))}))},this.onFailed=(e,t)=>{this.setState((e=>F(w({},e),{error:t})))},this.onReady=(e,t,r)=>{const n=d(e,r);this.setState((o=>w(F(w({},o),{unproxiedFlags:n}),y(e,n,t,r))))},this.prepareLDClient=()=>E(this,null,(function*(){var e;const{clientSideID:r,flags:n,options:o}=this.props;let s=yield this.props.ldClient;const i=this.getReactOptions();let a,l=this.state.unproxiedFlags;if(s)l=d(s,n);else{const c=null!=(e=u(this.props))?e:{anonymous:!0,kind:"user"};s=t.initialize(r,c,w(w({},b),o));try{yield s.waitForInitialization(this.props.timeout),l=d(s,n)}catch(e){a=e,(null==a?void 0:a.name.toLowerCase().includes("timeout"))&&(s.on("failed",this.onFailed),s.on("ready",(()=>{this.onReady(s,i,n)})))}}this.setState((e=>F(w(F(w({},e),{unproxiedFlags:l}),y(s,l,i,n)),{ldClient:s,error:a}))),this.subscribeToChanges(s)}));const{options:r}=e;if(this.state={flags:{},unproxiedFlags:{},flagKeyMap:{}},r){const{bootstrap:e}=r;if(e&&"localStorage"!==e){const{useCamelCaseFlagKeys:t}=this.getReactOptions();this.state={flags:t?p(e):e,unproxiedFlags:e,flagKeyMap:{}}}}}componentDidMount(){return E(this,null,(function*(){const{deferInitialization:e}=this.props;e&&!u(this.props)||(yield this.prepareLDClient())}))}componentDidUpdate(e){return E(this,null,(function*(){const{deferInitialization:t}=this.props,r=!u(e)&&u(this.props);t&&r&&(yield this.prepareLDClient())}))}render(){const{flags:t,flagKeyMap:r,ldClient:n,error:o}=this.state;return e.createElement(l,{value:{flags:t,flagKeyMap:r,ldClient:n,error:o}},this.props.children)}}var S=Object.defineProperty,k=Object.defineProperties,K=Object.getOwnPropertyDescriptors,L=Object.getOwnPropertySymbols,I=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,z=(e,t,r)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,M=(e,t)=>{for(var r in t||(t={}))I.call(t,r)&&z(e,r,t[r]);if(L)for(var r of L(t))R.call(t,r)&&z(e,r,t[r]);return e};var q=Object.defineProperty,T=Object.defineProperties,V=Object.getOwnPropertyDescriptors,$=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,W=(e,t,r)=>t in e?q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,A=(e,t)=>{for(var r in t||(t={}))N.call(t,r)&&W(e,r,t[r]);if($)for(var r of $(t))U.call(t,r)&&W(e,r,t[r]);return e},B=(e,t)=>T(e,V(t));var G=Object.defineProperty,H=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable,X=(e,t,r)=>t in e?G(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Y=(e,t)=>{for(var r in t||(t={}))J.call(t,r)&&X(e,r,t[r]);if(H)for(var r of H(t))Q.call(t,r)&&X(e,r,t[r]);return e};exports.LDProvider=D,exports.asyncWithLDProvider=function(r){return n=this,o=null,s=function*(){var n,o;const{clientSideID:s,flags:a,options:c,reactOptions:p}=r,h=A(A({},i),p),O=null!=(n=u(r))?n:{anonymous:!0,kind:"user"};let g,v={};const m=null!=(o=yield r.ldClient)?o:t.initialize(s,O,A(A({},b),c));try{yield m.waitForInitialization(r.timeout),v=d(m,a)}catch(e){g=e}const x=(null==c?void 0:c.bootstrap)&&"localStorage"!==c.bootstrap?c.bootstrap:v;return({children:t})=>{const[r,n]=e.useState((()=>B(A({unproxiedFlags:x},y(m,x,h,a)),{ldClient:m,error:g})));e.useEffect((()=>{function e(e){const t=f(e,a);Object.keys(t).length>0&&n((e=>{const r=A(A({},e.unproxiedFlags),t);return A(B(A({},e),{unproxiedFlags:r}),y(m,r,h,a))}))}function t(){const e=d(m,a);n((t=>A(B(A({},t),{unproxiedFlags:e}),y(m,e,h,a))))}function r(e){n((t=>B(A({},t),{error:e})))}return m.on("change",e),(null==g?void 0:g.name.toLowerCase().includes("timeout"))&&(m.on("failed",r),m.on("ready",t)),function(){m.off("change",e),m.off("failed",r),m.off("ready",t)}}),[]);const o=((e,t)=>{var r={};for(var n in e)N.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&$)for(var n of $(e))t.indexOf(n)<0&&U.call(e,n)&&(r[n]=e[n]);return r})(r,["unproxiedFlags"]);return e.createElement(l,{value:o},t)}},new Promise(((e,t)=>{var r=e=>{try{a(s.next(e))}catch(e){t(e)}},i=e=>{try{a(s.throw(e))}catch(e){t(e)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(r,i);a((s=s.apply(n,o)).next())}));var n,o,s},exports.camelCaseKeys=p,exports.defaultReactOptions=i,exports.useFlags=()=>{const{flags:t}=e.useContext(a);return t},exports.useLDClient=()=>{const{ldClient:t}=e.useContext(a);return t},exports.useLDClientError=function(){const{error:t}=e.useContext(a);return t},exports.withLDConsumer=function(e={clientOnly:!1}){return function(t){return r=>s.createElement(c,null,(({flags:n,ldClient:o})=>e.clientOnly?s.createElement(t,Y({ldClient:o},r)):s.createElement(t,Y({flags:n,ldClient:o},r))))}},exports.withLDProvider=function(e){return function(t){const{reactOptions:r}=e,o=M(M({},i),r),a=(l=M({},e),k(l,K({reactOptions:o})));var l;function c(e){return s.createElement(D,M({},a),s.createElement(t,M({},e)))}return n(c,t),c}},Object.keys(t).forEach((function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})}));
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import*as e from"react";import t,{createContext as r,Component as n,useState as o,useEffect as s,useContext as i}from"react";import{initialize as a}from"launchdarkly-js-client-sdk";export*from"launchdarkly-js-client-sdk";import l from"lodash.camelcase";import c from"hoist-non-react-statics";const p={useCamelCaseFlagKeys:!0,sendEventsOnFlagRead:!0},u=r({flags:{},flagKeyMap:{},ldClient:void 0}),{Provider:f,Consumer:d}=u,y=e=>{var t;return null!=(t=e.context)?t:e.user},h=e=>{const t={};for(const r in e)0!==r.indexOf("$")&&(t[l(r)]=e[r]);return t},g=(e,t)=>{const r={};for(const n in e)t&&void 0===t[n]||(r[n]=e[n].current);return r},O=(e,t)=>{const r=e.allFlags();return t?Object.keys(t).reduce(((e,n)=>(e[n]=Object.prototype.hasOwnProperty.call(r,n)?r[n]:t[n],e)),{}):r};function b(e,t,r=p,n){const o=function(e,t){if(void 0===t)return e;return Object.keys(t).reduce(((t,r)=>(m(e,r)&&(t[r]=e[r]),t)),{})}(t,n),{useCamelCaseFlagKeys:s=!0}=r,[i,a={}]=s?function(e){const t={},r={};for(const n in e){if(0===n.indexOf("$"))continue;const o=l(n);t[o]=e[n],r[o]=n}return[t,r]}(o):[o];return{flags:r.sendEventsOnFlagRead?v(e,i,a,s):i,flagKeyMap:a}}function m(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function v(e,t,r,n){return new Proxy(t,{get(t,o,s){const i=Reflect.get(t,o,s),a=n&&m(r,o)||m(t,o);if("symbol"==typeof o||!a)return i;if(void 0===i)return;const l=n?r[o]:o;return e.variation(l,i)}})}h.camelCaseKeys=h;const j={wrapperName:"react-client-sdk",wrapperVersion:"3.3.2",sendEventsOnlyForVariation:!0};var w=Object.defineProperty,P=Object.defineProperties,x=Object.getOwnPropertyDescriptors,C=Object.getOwnPropertySymbols,F=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable,S=(e,t,r)=>t in e?w(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,k=(e,t)=>{for(var r in t||(t={}))F.call(t,r)&&S(e,r,t[r]);if(C)for(var r of C(t))E.call(t,r)&&S(e,r,t[r]);return e},D=(e,t)=>P(e,x(t)),I=(e,t,r)=>new Promise(((n,o)=>{var s=e=>{try{a(r.next(e))}catch(e){o(e)}},i=e=>{try{a(r.throw(e))}catch(e){o(e)}},a=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,i);a((r=r.apply(e,t)).next())}));class K extends n{constructor(e){super(e),this.getReactOptions=()=>k(k({},p),this.props.reactOptions),this.subscribeToChanges=e=>{const{flags:t}=this.props;e.on("change",(r=>{const n=this.getReactOptions(),o=g(r,t),s=k(k({},this.state.unproxiedFlags),o);Object.keys(o).length>0&&this.setState((r=>k(D(k({},r),{unproxiedFlags:s}),b(e,s,n,t))))}))},this.onFailed=(e,t)=>{this.setState((e=>D(k({},e),{error:t})))},this.onReady=(e,t,r)=>{const n=O(e,r);this.setState((o=>k(D(k({},o),{unproxiedFlags:n}),b(e,n,t,r))))},this.prepareLDClient=()=>I(this,null,(function*(){var e;const{clientSideID:t,flags:r,options:n}=this.props;let o=yield this.props.ldClient;const s=this.getReactOptions();let i,l=this.state.unproxiedFlags;if(o)l=O(o,r);else{const c=null!=(e=y(this.props))?e:{anonymous:!0,kind:"user"};o=a(t,c,k(k({},j),n));try{yield o.waitForInitialization(this.props.timeout),l=O(o,r)}catch(e){i=e,(null==i?void 0:i.name.toLowerCase().includes("timeout"))&&(o.on("failed",this.onFailed),o.on("ready",(()=>{this.onReady(o,s,r)})))}}this.setState((e=>D(k(D(k({},e),{unproxiedFlags:l}),b(o,l,s,r)),{ldClient:o,error:i}))),this.subscribeToChanges(o)}));const{options:t}=e;if(this.state={flags:{},unproxiedFlags:{},flagKeyMap:{}},t){const{bootstrap:e}=t;if(e&&"localStorage"!==e){const{useCamelCaseFlagKeys:t}=this.getReactOptions();this.state={flags:t?h(e):e,unproxiedFlags:e,flagKeyMap:{}}}}}componentDidMount(){return I(this,null,(function*(){const{deferInitialization:e}=this.props;e&&!y(this.props)||(yield this.prepareLDClient())}))}componentDidUpdate(e){return I(this,null,(function*(){const{deferInitialization:t}=this.props,r=!y(e)&&y(this.props);t&&r&&(yield this.prepareLDClient())}))}render(){const{flags:e,flagKeyMap:r,ldClient:n,error:o}=this.state;return t.createElement(f,{value:{flags:e,flagKeyMap:r,ldClient:n,error:o}},this.props.children)}}var R=Object.defineProperty,M=Object.defineProperties,L=Object.getOwnPropertyDescriptors,z=Object.getOwnPropertySymbols,T=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable,$=(e,t,r)=>t in e?R(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,N=(e,t)=>{for(var r in t||(t={}))T.call(t,r)&&$(e,r,t[r]);if(z)for(var r of z(t))V.call(t,r)&&$(e,r,t[r]);return e};function U(t){return function(r){const{reactOptions:n}=t,o=N(N({},p),n),s=(i=N({},t),M(i,L({reactOptions:o})));var i;function a(t){return e.createElement(K,N({},s),e.createElement(r,N({},t)))}return c(a,r),a}}var q=Object.defineProperty,A=Object.defineProperties,B=Object.getOwnPropertyDescriptors,G=Object.getOwnPropertySymbols,H=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable,Q=(e,t,r)=>t in e?q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,W=(e,t)=>{for(var r in t||(t={}))H.call(t,r)&&Q(e,r,t[r]);if(G)for(var r of G(t))J.call(t,r)&&Q(e,r,t[r]);return e},X=(e,t)=>A(e,B(t));function Y(e){return r=this,n=null,i=function*(){var r;const{clientSideID:n,flags:i,options:l,reactOptions:c}=e,u=W(W({},p),c),d=null!=(r=y(e))?r:{anonymous:!0,kind:"user"};let h,m={};const v=a(n,d,W(W({},j),l));try{yield v.waitForInitialization(e.timeout),m=O(v,i)}catch(e){h=e}const w=(null==l?void 0:l.bootstrap)&&"localStorage"!==l.bootstrap?l.bootstrap:m;return({children:e})=>{const[r,n]=o((()=>X(W({unproxiedFlags:w},b(v,w,u,i)),{ldClient:v,error:h})));s((()=>{function e(e){const t=g(e,i);Object.keys(t).length>0&&n((e=>{const r=W(W({},e.unproxiedFlags),t);return W(X(W({},e),{unproxiedFlags:r}),b(v,r,u,i))}))}function t(){const e=O(v,i);n((t=>W(X(W({},t),{unproxiedFlags:e}),b(v,e,u,i))))}function r(e){n((t=>X(W({},t),{error:e})))}return v.on("change",e),(null==h?void 0:h.name.toLowerCase().includes("timeout"))&&(v.on("failed",r),v.on("ready",t)),function(){v.off("change",e),v.off("failed",r),v.off("ready",t)}}),[]);const a=((e,t)=>{var r={};for(var n in e)H.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&G)for(var n of G(e))t.indexOf(n)<0&&J.call(e,n)&&(r[n]=e[n]);return r})(r,["unproxiedFlags"]);return t.createElement(f,{value:a},e)}},new Promise(((e,t)=>{var o=e=>{try{a(i.next(e))}catch(e){t(e)}},s=e=>{try{a(i.throw(e))}catch(e){t(e)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(o,s);a((i=i.apply(r,n)).next())}));var r,n,i}var Z=Object.defineProperty,_=Object.getOwnPropertySymbols,ee=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable,re=(e,t,r)=>t in e?Z(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ne=(e,t)=>{for(var r in t||(t={}))ee.call(t,r)&&re(e,r,t[r]);if(_)for(var r of _(t))te.call(t,r)&&re(e,r,t[r]);return e};function oe(t={clientOnly:!1}){return function(r){return n=>e.createElement(d,null,(({flags:o,ldClient:s})=>t.clientOnly?e.createElement(r,ne({ldClient:s},n)):e.createElement(r,ne({flags:o,ldClient:s},n))))}}const se=()=>{const{flags:e}=i(u);return e},ie=()=>{const{ldClient:e}=i(u);return e};function ae(){const{error:e}=i(u);return e}export{K as LDProvider,Y as asyncWithLDProvider,h as camelCaseKeys,p as defaultReactOptions,se as useFlags,ie as useLDClient,ae as useLDClientError,oe as withLDConsumer,U as withLDProvider};
import*as e from"react";import t,{createContext as r,Component as n,useState as o,useEffect as i,useContext as s}from"react";import{initialize as a}from"launchdarkly-js-client-sdk";export*from"launchdarkly-js-client-sdk";import l from"lodash.camelcase";import c from"hoist-non-react-statics";const p={useCamelCaseFlagKeys:!0,sendEventsOnFlagRead:!0},u=r({flags:{},flagKeyMap:{},ldClient:void 0}),{Provider:f,Consumer:d}=u,y=e=>{var t;return null!=(t=e.context)?t:e.user},h=e=>{const t={};for(const r in e)0!==r.indexOf("$")&&(t[l(r)]=e[r]);return t},g=(e,t)=>{const r={};for(const n in e)t&&void 0===t[n]||(r[n]=e[n].current);return r},O=(e,t)=>{const r=e.allFlags();return t?Object.keys(t).reduce(((e,n)=>(e[n]=Object.prototype.hasOwnProperty.call(r,n)?r[n]:t[n],e)),{}):r};function b(e,t,r=p,n){const o=function(e,t){if(void 0===t)return e;return Object.keys(t).reduce(((t,r)=>(m(e,r)&&(t[r]=e[r]),t)),{})}(t,n),{useCamelCaseFlagKeys:i=!0}=r,[s,a={}]=i?function(e){const t={},r={};for(const n in e){if(0===n.indexOf("$"))continue;const o=l(n);t[o]=e[n],r[o]=n}return[t,r]}(o):[o];return{flags:r.sendEventsOnFlagRead?v(e,s,a,i):s,flagKeyMap:a}}function m(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function v(e,t,r,n){return new Proxy(t,{get(t,o,i){const s=Reflect.get(t,o,i),a=n&&m(r,o)||m(t,o);if("symbol"==typeof o||!a)return s;if(void 0===s)return;const l=n?r[o]:o;return e.variation(l,s)}})}h.camelCaseKeys=h;const j={wrapperName:"react-client-sdk",wrapperVersion:"3.4.0",sendEventsOnlyForVariation:!0};var w=Object.defineProperty,C=Object.defineProperties,P=Object.getOwnPropertyDescriptors,x=Object.getOwnPropertySymbols,F=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable,S=(e,t,r)=>t in e?w(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,k=(e,t)=>{for(var r in t||(t={}))F.call(t,r)&&S(e,r,t[r]);if(x)for(var r of x(t))E.call(t,r)&&S(e,r,t[r]);return e},D=(e,t)=>C(e,P(t)),I=(e,t,r)=>new Promise(((n,o)=>{var i=e=>{try{a(r.next(e))}catch(e){o(e)}},s=e=>{try{a(r.throw(e))}catch(e){o(e)}},a=e=>e.done?n(e.value):Promise.resolve(e.value).then(i,s);a((r=r.apply(e,t)).next())}));class K extends n{constructor(e){super(e),this.getReactOptions=()=>k(k({},p),this.props.reactOptions),this.subscribeToChanges=e=>{const{flags:t}=this.props;e.on("change",(r=>{const n=this.getReactOptions(),o=g(r,t),i=k(k({},this.state.unproxiedFlags),o);Object.keys(o).length>0&&this.setState((r=>k(D(k({},r),{unproxiedFlags:i}),b(e,i,n,t))))}))},this.onFailed=(e,t)=>{this.setState((e=>D(k({},e),{error:t})))},this.onReady=(e,t,r)=>{const n=O(e,r);this.setState((o=>k(D(k({},o),{unproxiedFlags:n}),b(e,n,t,r))))},this.prepareLDClient=()=>I(this,null,(function*(){var e;const{clientSideID:t,flags:r,options:n}=this.props;let o=yield this.props.ldClient;const i=this.getReactOptions();let s,l=this.state.unproxiedFlags;if(o)l=O(o,r);else{const c=null!=(e=y(this.props))?e:{anonymous:!0,kind:"user"};o=a(t,c,k(k({},j),n));try{yield o.waitForInitialization(this.props.timeout),l=O(o,r)}catch(e){s=e,(null==s?void 0:s.name.toLowerCase().includes("timeout"))&&(o.on("failed",this.onFailed),o.on("ready",(()=>{this.onReady(o,i,r)})))}}this.setState((e=>D(k(D(k({},e),{unproxiedFlags:l}),b(o,l,i,r)),{ldClient:o,error:s}))),this.subscribeToChanges(o)}));const{options:t}=e;if(this.state={flags:{},unproxiedFlags:{},flagKeyMap:{}},t){const{bootstrap:e}=t;if(e&&"localStorage"!==e){const{useCamelCaseFlagKeys:t}=this.getReactOptions();this.state={flags:t?h(e):e,unproxiedFlags:e,flagKeyMap:{}}}}}componentDidMount(){return I(this,null,(function*(){const{deferInitialization:e}=this.props;e&&!y(this.props)||(yield this.prepareLDClient())}))}componentDidUpdate(e){return I(this,null,(function*(){const{deferInitialization:t}=this.props,r=!y(e)&&y(this.props);t&&r&&(yield this.prepareLDClient())}))}render(){const{flags:e,flagKeyMap:r,ldClient:n,error:o}=this.state;return t.createElement(f,{value:{flags:e,flagKeyMap:r,ldClient:n,error:o}},this.props.children)}}var R=Object.defineProperty,M=Object.defineProperties,L=Object.getOwnPropertyDescriptors,z=Object.getOwnPropertySymbols,T=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable,$=(e,t,r)=>t in e?R(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,N=(e,t)=>{for(var r in t||(t={}))T.call(t,r)&&$(e,r,t[r]);if(z)for(var r of z(t))V.call(t,r)&&$(e,r,t[r]);return e};function U(t){return function(r){const{reactOptions:n}=t,o=N(N({},p),n),i=(s=N({},t),M(s,L({reactOptions:o})));var s;function a(t){return e.createElement(K,N({},i),e.createElement(r,N({},t)))}return c(a,r),a}}var q=Object.defineProperty,A=Object.defineProperties,B=Object.getOwnPropertyDescriptors,G=Object.getOwnPropertySymbols,H=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable,Q=(e,t,r)=>t in e?q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,W=(e,t)=>{for(var r in t||(t={}))H.call(t,r)&&Q(e,r,t[r]);if(G)for(var r of G(t))J.call(t,r)&&Q(e,r,t[r]);return e},X=(e,t)=>A(e,B(t));function Y(e){return r=this,n=null,s=function*(){var r,n;const{clientSideID:s,flags:l,options:c,reactOptions:u}=e,d=W(W({},p),u),h=null!=(r=y(e))?r:{anonymous:!0,kind:"user"};let m,v={};const w=null!=(n=yield e.ldClient)?n:a(s,h,W(W({},j),c));try{yield w.waitForInitialization(e.timeout),v=O(w,l)}catch(e){m=e}const C=(null==c?void 0:c.bootstrap)&&"localStorage"!==c.bootstrap?c.bootstrap:v;return({children:e})=>{const[r,n]=o((()=>X(W({unproxiedFlags:C},b(w,C,d,l)),{ldClient:w,error:m})));i((()=>{function e(e){const t=g(e,l);Object.keys(t).length>0&&n((e=>{const r=W(W({},e.unproxiedFlags),t);return W(X(W({},e),{unproxiedFlags:r}),b(w,r,d,l))}))}function t(){const e=O(w,l);n((t=>W(X(W({},t),{unproxiedFlags:e}),b(w,e,d,l))))}function r(e){n((t=>X(W({},t),{error:e})))}return w.on("change",e),(null==m?void 0:m.name.toLowerCase().includes("timeout"))&&(w.on("failed",r),w.on("ready",t)),function(){w.off("change",e),w.off("failed",r),w.off("ready",t)}}),[]);const s=((e,t)=>{var r={};for(var n in e)H.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&G)for(var n of G(e))t.indexOf(n)<0&&J.call(e,n)&&(r[n]=e[n]);return r})(r,["unproxiedFlags"]);return t.createElement(f,{value:s},e)}},new Promise(((e,t)=>{var o=e=>{try{a(s.next(e))}catch(e){t(e)}},i=e=>{try{a(s.throw(e))}catch(e){t(e)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(o,i);a((s=s.apply(r,n)).next())}));var r,n,s}var Z=Object.defineProperty,_=Object.getOwnPropertySymbols,ee=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable,re=(e,t,r)=>t in e?Z(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ne=(e,t)=>{for(var r in t||(t={}))ee.call(t,r)&&re(e,r,t[r]);if(_)for(var r of _(t))te.call(t,r)&&re(e,r,t[r]);return e};function oe(t={clientOnly:!1}){return function(r){return n=>e.createElement(d,null,(({flags:o,ldClient:i})=>t.clientOnly?e.createElement(r,ne({ldClient:i},n)):e.createElement(r,ne({flags:o,ldClient:i},n))))}}const ie=()=>{const{flags:e}=s(u);return e},se=()=>{const{ldClient:e}=s(u);return e};function ae(){const{error:e}=s(u);return e}export{K as LDProvider,Y as asyncWithLDProvider,h as camelCaseKeys,p as defaultReactOptions,ie as useFlags,se as useLDClient,ae as useLDClientError,oe as withLDConsumer,U as withLDProvider};
//# sourceMappingURL=index.js.map

@@ -84,6 +84,9 @@ import * as React from 'react';

/**
* Optionally, the ldClient can be initialised outside of the provider
* and passed in, instead of being initialised by the provider.
* Optionally, the ldClient can be initialized outside of the provider
* and passed in, instead of being initialized by the provider.
*
* Note: it should only be passed in when it has emitted the 'ready'
* event, to ensure that the flags are properly set.
* event when using withLDProvider, to ensure that the flags are properly set.
* If using with asyncWithLDProvider, then it will wait internally, so
* it is not required that the client have emitted the 'ready' event.
*/

@@ -143,5 +146,3 @@ ldClient?: LDClient | Promise<LDClient | undefined>;

*/
interface LDFlagKeyMap {
[camelCasedKey: string]: string;
}
type LDFlagKeyMap = Record<string, string>;

@@ -181,3 +182,3 @@ interface ProviderState {

subscribeToChanges: (ldClient: LDClient) => void;
onFailed: (ldClient: LDClient, e: Error) => void;
onFailed: (_ldClient: LDClient, e: Error) => void;
onReady: (ldClient: LDClient, reactOptions: LDReactOptions, targetFlags?: LDFlagSet) => void;

@@ -184,0 +185,0 @@ prepareLDClient: () => Promise<void>;

{
"name": "launchdarkly-react-client-sdk",
"version": "3.3.2",
"version": "3.4.0",
"description": "LaunchDarkly SDK for React",

@@ -30,9 +30,8 @@ "author": "LaunchDarkly <team@launchdarkly.com>",

"test": "jest",
"test:junit": "jest --ci --reporters=default --reporters=jest-junit",
"test:junit": "jest --ci --reporters=default",
"clean": "rimraf lib/*",
"rb": "rollup -c --configPlugin typescript",
"rbw": "yarn rb --watch",
"build": "yarn clean && yarn rb",
"lint": "tslint -p tsconfig.json 'src/**/*.ts*'",
"lint:all": "npm run lint",
"rbw": "npm run rb --watch",
"build": "npm run clean && npm run rb",
"lint": "eslint ./src",
"check-typescript": "tsc",

@@ -42,3 +41,4 @@ "prepublishOnly": "npm run build",

"link-dev": "./link-dev.sh",
"check": "npm i && npm run prettier && npm run lint && tsc && npm run test"
"check": "npm i && npm run prettier && npm run lint && tsc && npm run test",
"doc": "typedoc"
},

@@ -51,2 +51,3 @@ "repository": {

"devDependencies": {
"@eslint/js": "^9.7.0",
"@rollup/plugin-json": "^6.0.0",

@@ -56,6 +57,8 @@ "@rollup/plugin-node-resolve": "^15.1.0",

"@rollup/plugin-typescript": "^11.1.2",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^15.0.7",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.4.8",
"@testing-library/react": "^16.0.0",
"@types/eslint__js": "^8.42.3",
"@types/hoist-non-react-statics": "^3.3.1",
"@types/jest": "^27.5.2",
"@types/jest": "^29.5.12",
"@types/lodash.camelcase": "^4.3.6",

@@ -67,8 +70,8 @@ "@types/node": "^20.12.12",

"@types/react-test-renderer": "^18.0.0",
"esbuild": "^0.21.3",
"jest": "^27.5.1",
"jest-environment-jsdom": "^27.4.4",
"esbuild": "^0.23.0",
"eslint": "^8.57.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-environment-jsdom-global": "^4.0.0",
"jest-junit": "^16.0.0",
"prettier": "^1.18.2",
"prettier": "^3.3.3",
"prop-types": "^15.7.2",

@@ -78,12 +81,11 @@ "react": "^18.0.0",

"react-test-renderer": "^18.0.0",
"rimraf": "^5.0.7",
"rollup": "^3.26.2",
"rimraf": "^6.0.1",
"rollup": "^4.19.0",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-esbuild": "^6.1.1",
"rollup-plugin-filesize": "^10.0.0",
"ts-jest": "^27.1.1",
"ts-jest": "^29.2.2",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.3.0",
"typescript": "^4.5.3"
"typedoc": "^0.26.5",
"typescript": "^5.5.4",
"typescript-eslint": "^8.0.0"
},

@@ -90,0 +92,0 @@ "dependencies": {

@@ -88,6 +88,9 @@ import { LDClient, LDContext, LDFlagSet, LDOptions } from 'launchdarkly-js-client-sdk';

/**
* Optionally, the ldClient can be initialised outside of the provider
* and passed in, instead of being initialised by the provider.
* Optionally, the ldClient can be initialized outside of the provider
* and passed in, instead of being initialized by the provider.
*
* Note: it should only be passed in when it has emitted the 'ready'
* event, to ensure that the flags are properly set.
* event when using withLDProvider, to ensure that the flags are properly set.
* If using with asyncWithLDProvider, then it will wait internally, so
* it is not required that the client have emitted the 'ready' event.
*/

@@ -125,5 +128,3 @@ ldClient?: LDClient | Promise<LDClient | undefined>;

subscribeToChanges(ldClient: LDClient): void;
// tslint:disable-next-line:invalid-void
componentDidMount(): Promise<void>;
// tslint:disable-next-line:invalid-void
componentDidUpdate(prevProps: ProviderConfig): Promise<void>;

@@ -157,6 +158,4 @@ }

*/
export interface LDFlagKeyMap {
[camelCasedKey: string]: string;
}
export type LDFlagKeyMap = Record<string, string>;
export * from 'launchdarkly-js-client-sdk';
import { useContext } from 'react';
import context from './context';
// tslint:disable:max-line-length
/**

@@ -13,3 +12,2 @@ * `useLDClient` is a custom hook which returns the underlying [LaunchDarkly JavaScript SDK client object](https://launchdarkly.github.io/js-client-sdk/interfaces/LDClient.html).

*/
// tslint:enable:max-line-length
const useLDClient = () => {

@@ -16,0 +14,0 @@ const { ldClient } = useContext(context);

@@ -23,3 +23,3 @@ import { LDClient, LDContext, LDFlagChangeset, LDFlagSet } from 'launchdarkly-js-client-sdk';

if (rawFlag.indexOf('$') !== 0) {
flags[camelCase(rawFlag)] = rawFlags[rawFlag]; // tslint:disable-line:no-unsafe-any
flags[camelCase(rawFlag)] = rawFlags[rawFlag];
}

@@ -80,5 +80,4 @@ }

*/
// tslint:disable-next-line deprecation
camelCaseKeys.camelCaseKeys = camelCaseKeys;
export default { camelCaseKeys, getFlattenedFlagsFromChangeset, fetchFlags };

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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