@ops-ai/vue-feature-flags-toggly 1.0.1 → 1.0.2

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.
@@ -0,0 +1,40 @@
1
+ declare const _default: import("vue").DefineComponent<{
2
+ featureKey: {
3
+ type: StringConstructor;
4
+ };
5
+ featureKeys: {
6
+ type: ArrayConstructor;
7
+ };
8
+ requirement: {
9
+ type: StringConstructor;
10
+ default: string;
11
+ };
12
+ negate: {
13
+ type: BooleanConstructor;
14
+ default: boolean;
15
+ };
16
+ }, unknown, {
17
+ shouldShow: boolean;
18
+ isLoading: boolean;
19
+ }, {}, {
20
+ checkIfShouldShow(): Promise<void>;
21
+ }, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
22
+ featureKey: {
23
+ type: StringConstructor;
24
+ };
25
+ featureKeys: {
26
+ type: ArrayConstructor;
27
+ };
28
+ requirement: {
29
+ type: StringConstructor;
30
+ default: string;
31
+ };
32
+ negate: {
33
+ type: BooleanConstructor;
34
+ default: boolean;
35
+ };
36
+ }>>, {
37
+ requirement: string;
38
+ negate: boolean;
39
+ }>;
40
+ export default _default;
@@ -0,0 +1 @@
1
+ export { default as toggly } from './plugins/toggly';
@@ -0,0 +1,5 @@
1
+ import { TogglyOptions } from './toggly.service';
2
+ declare const _default: {
3
+ install: (app: any, options: TogglyOptions) => void;
4
+ };
5
+ export default _default;
@@ -0,0 +1,45 @@
1
+ export interface TogglyOptions {
2
+ baseURI?: string;
3
+ appKey?: string;
4
+ environment?: string;
5
+ identity?: string;
6
+ featureDefaults?: {
7
+ [key: string]: boolean;
8
+ };
9
+ showFeatureDuringEvaluation?: boolean;
10
+ }
11
+ export interface TogglyService {
12
+ shouldShowFeatureDuringEvaluation: boolean;
13
+ init: (options: TogglyOptions) => this;
14
+ _loadFeatures: () => Promise<{
15
+ [key: string]: boolean;
16
+ } | null>;
17
+ _featuresLoaded: () => Promise<{
18
+ [key: string]: boolean;
19
+ } | null>;
20
+ _evaluateFeatureGate: (gate: string[], requirement: string, negate: boolean) => Promise<boolean>;
21
+ evaluateFeatureGate: (featureKeys: string[], requirement: string, negate: boolean) => Promise<boolean>;
22
+ isFeatureOn: (featureKey: string) => Promise<boolean>;
23
+ isFeatureOff: (featureKey: string) => Promise<boolean>;
24
+ }
25
+ export declare class Toggly implements TogglyService {
26
+ private _config;
27
+ private _features;
28
+ private _loadingFeatures;
29
+ shouldShowFeatureDuringEvaluation: boolean;
30
+ init: (options: TogglyOptions) => this;
31
+ _loadFeatures: () => Promise<{
32
+ [key: string]: boolean;
33
+ } | null>;
34
+ _featuresLoaded: () => Promise<{
35
+ [key: string]: boolean;
36
+ } | null>;
37
+ _evaluateFeatureGate: (gate: string[], requirement?: string, negate?: boolean) => Promise<boolean>;
38
+ evaluateFeatureGate: (featureKeys: string[], requirement?: string, negate?: boolean) => Promise<boolean>;
39
+ isFeatureOn: (featureKey: string) => Promise<boolean>;
40
+ isFeatureOff: (featureKey: string) => Promise<boolean>;
41
+ setIdentity: (identity: string) => void;
42
+ clearIdentity: () => void;
43
+ }
44
+ declare const toggly: Toggly;
45
+ export default toggly;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vite").UserConfigExport;
2
+ export default _default;
@@ -6,7 +6,7 @@ class f {
6
6
  };
7
7
  _features = null;
8
8
  _loadingFeatures = !1;
9
- shouldShowFeatureDuringEvaluation;
9
+ shouldShowFeatureDuringEvaluation = !1;
10
10
  init = (e) => (e.appKey ? e.environment || (e.environment = "Production", console.warn(
11
11
  "Toggly --- Using Production environment as no environment provided when initializing the Toggly"
12
12
  )) : e.featureDefaults ? (this._features = e.featureDefaults ?? {}, console.warn(
@@ -16,10 +16,10 @@ class f {
16
16
  ), this._config = Object.assign({}, this._config, e), this.shouldShowFeatureDuringEvaluation = this._config.showFeatureDuringEvaluation, this);
17
17
  _loadFeatures = async () => {
18
18
  if (this._loadingFeatures && await new Promise((a) => {
19
- const i = () => {
20
- this._loadingFeatures ? setTimeout(i, 100) : a();
19
+ const s = () => {
20
+ this._loadingFeatures ? setTimeout(s, 100) : a();
21
21
  };
22
- i();
22
+ s();
23
23
  }), this._features !== null)
24
24
  return this._features;
25
25
  this._loadingFeatures = !0;
@@ -38,17 +38,23 @@ class f {
38
38
  return this._features;
39
39
  };
40
40
  _featuresLoaded = async () => this._features ?? await this._loadFeatures();
41
- _evaluateFeatureGate = async (e, a = "all", i = !1) => {
41
+ _evaluateFeatureGate = async (e, a = "all", s = !1) => {
42
42
  if (await this._featuresLoaded(), !this._features || Object.keys(this._features).length === 0)
43
43
  return !0;
44
- var s;
45
- return a === "any" ? s = e.reduce((n, r) => n || this._features[r] && this._features[r] === !0, !1) : s = e.reduce((n, r) => n && this._features[r] && this._features[r] === !0, !0), s = i ? !s : s, s;
44
+ var i;
45
+ return a === "any" ? i = e.reduce((r, n) => r || this._features[n] && this._features[n] === !0, !1) : i = e.reduce((r, n) => r && this._features[n] && this._features[n] === !0, !0), i = s ? !i : i, i;
46
46
  };
47
- evaluateFeatureGate = async (e, a = "all", i = !1) => await this._evaluateFeatureGate(e, a, i);
47
+ evaluateFeatureGate = async (e, a = "all", s = !1) => await this._evaluateFeatureGate(e, a, s);
48
48
  isFeatureOn = async (e) => await this._evaluateFeatureGate([e]);
49
49
  isFeatureOff = async (e) => await this._evaluateFeatureGate([e], "all", !0);
50
+ setIdentity = (e) => {
51
+ this._features = null, this._config.identity = e;
52
+ };
53
+ clearIdentity = () => {
54
+ this._features = null, this._config.identity = void 0;
55
+ };
50
56
  }
51
- const g = new f(), c = {
57
+ const c = new f(), g = {
52
58
  inject: ["$toggly"],
53
59
  props: {
54
60
  featureKey: {
@@ -84,19 +90,19 @@ const g = new f(), c = {
84
90
  }
85
91
  }, d = (t, e) => {
86
92
  const a = t.__vccOpts || t;
87
- for (const [i, s] of e)
88
- a[i] = s;
93
+ for (const [s, i] of e)
94
+ a[s] = i;
89
95
  return a;
90
96
  }, _ = { key: 0 };
91
- function y(t, e, a, i, s, n) {
92
- return s.shouldShow ? (o(), u("div", _, [
97
+ function y(t, e, a, s, i, r) {
98
+ return i.shouldShow ? (o(), u("div", _, [
93
99
  l(t.$slots, "default")
94
100
  ])) : h("", !0);
95
101
  }
96
- const w = /* @__PURE__ */ d(c, [["render", y]]), p = {
102
+ const v = /* @__PURE__ */ d(g, [["render", y]]), p = {
97
103
  install: (t, e) => {
98
- const a = g.init(e);
99
- t.provide("$toggly", a), t.component("Feature", w);
104
+ const a = c.init(e);
105
+ t.provide("$toggly", a), t.component("Feature", v);
100
106
  }
101
107
  };
102
108
  export {
@@ -1 +1 @@
1
- (function(r,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r.VueFeatureFlagsToggly={},r.Vue))})(this,function(r,n){"use strict";class l{_config={baseURI:"https://client.toggly.io",showFeatureDuringEvaluation:!1};_features=null;_loadingFeatures=!1;shouldShowFeatureDuringEvaluation;init=e=>(e.appKey?e.environment||(e.environment="Production",console.warn("Toggly --- Using Production environment as no environment provided when initializing the Toggly")):e.featureDefaults?(this._features=e.featureDefaults??{},console.warn("Toggly --- Using feature defaults as no application key provided when initializing the Toggly")):console.warn("Toggly --- A valid application key is required to connect to your Toggly.io application for evaluating your features."),this._config=Object.assign({},this._config,e),this.shouldShowFeatureDuringEvaluation=this._config.showFeatureDuringEvaluation,this);_loadFeatures=async()=>{if(this._loadingFeatures&&await new Promise(a=>{const s=()=>{this._loadingFeatures?setTimeout(s,100):a()};s()}),this._features!==null)return this._features;this._loadingFeatures=!0;try{var e=`${this._config.baseURI}/${this._config.appKey}-${this._config.environment}/defs`;this._config.identity&&(e+=`?u=${this._config.identity}`);const a=await fetch(e);this._features=await a.json()}catch{this._features=this._config.featureDefaults??{},console.warn("Toggly --- Using feature defaults as features could not be loaded from the Toggly API")}finally{this._loadingFeatures=!1}return this._features};_featuresLoaded=async()=>this._features??await this._loadFeatures();_evaluateFeatureGate=async(e,a="all",s=!1)=>{if(await this._featuresLoaded(),!this._features||Object.keys(this._features).length===0)return!0;var i;return a==="any"?i=e.reduce((u,o)=>u||this._features[o]&&this._features[o]===!0,!1):i=e.reduce((u,o)=>u&&this._features[o]&&this._features[o]===!0,!0),i=s?!i:i,i};evaluateFeatureGate=async(e,a="all",s=!1)=>await this._evaluateFeatureGate(e,a,s);isFeatureOn=async e=>await this._evaluateFeatureGate([e]);isFeatureOff=async e=>await this._evaluateFeatureGate([e],"all",!0)}const f=new l,h={inject:["$toggly"],props:{featureKey:{type:String},featureKeys:{type:Array},requirement:{type:String,default:"all"},negate:{type:Boolean,default:!1}},data(){return{shouldShow:!1,isLoading:!1}},mounted(){this.checkIfShouldShow()},methods:{async checkIfShouldShow(){this.isLoading=!0,this.shouldShow=this.$toggly.shouldShowFeatureDuringEvaluation;var t=[];this.featureKey&&t.push(this.featureKey),this.featureKeys&&(t=t.concat(this.featureKeys)),this.shouldShow=t.length>0?await this.$toggly.evaluateFeatureGate(t,this.requirement,this.negate):!0,this.isLoading=!1}}},g=(t,e)=>{const a=t.__vccOpts||t;for(const[s,i]of e)a[s]=i;return a},c={key:0};function d(t,e,a,s,i,u){return i.shouldShow?(n.openBlock(),n.createElementBlock("div",c,[n.renderSlot(t.$slots,"default")])):n.createCommentVNode("",!0)}const y=g(h,[["render",d]]),_={install:(t,e)=>{const a=f.init(e);t.provide("$toggly",a),t.component("Feature",y)}};r.toggly=_,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
1
+ (function(r,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r.VueFeatureFlagsToggly={},r.Vue))})(this,function(r,n){"use strict";class l{_config={baseURI:"https://client.toggly.io",showFeatureDuringEvaluation:!1};_features=null;_loadingFeatures=!1;shouldShowFeatureDuringEvaluation=!1;init=e=>(e.appKey?e.environment||(e.environment="Production",console.warn("Toggly --- Using Production environment as no environment provided when initializing the Toggly")):e.featureDefaults?(this._features=e.featureDefaults??{},console.warn("Toggly --- Using feature defaults as no application key provided when initializing the Toggly")):console.warn("Toggly --- A valid application key is required to connect to your Toggly.io application for evaluating your features."),this._config=Object.assign({},this._config,e),this.shouldShowFeatureDuringEvaluation=this._config.showFeatureDuringEvaluation,this);_loadFeatures=async()=>{if(this._loadingFeatures&&await new Promise(a=>{const s=()=>{this._loadingFeatures?setTimeout(s,100):a()};s()}),this._features!==null)return this._features;this._loadingFeatures=!0;try{var e=`${this._config.baseURI}/${this._config.appKey}-${this._config.environment}/defs`;this._config.identity&&(e+=`?u=${this._config.identity}`);const a=await fetch(e);this._features=await a.json()}catch{this._features=this._config.featureDefaults??{},console.warn("Toggly --- Using feature defaults as features could not be loaded from the Toggly API")}finally{this._loadingFeatures=!1}return this._features};_featuresLoaded=async()=>this._features??await this._loadFeatures();_evaluateFeatureGate=async(e,a="all",s=!1)=>{if(await this._featuresLoaded(),!this._features||Object.keys(this._features).length===0)return!0;var i;return a==="any"?i=e.reduce((u,o)=>u||this._features[o]&&this._features[o]===!0,!1):i=e.reduce((u,o)=>u&&this._features[o]&&this._features[o]===!0,!0),i=s?!i:i,i};evaluateFeatureGate=async(e,a="all",s=!1)=>await this._evaluateFeatureGate(e,a,s);isFeatureOn=async e=>await this._evaluateFeatureGate([e]);isFeatureOff=async e=>await this._evaluateFeatureGate([e],"all",!0);setIdentity=e=>{this._features=null,this._config.identity=e};clearIdentity=()=>{this._features=null,this._config.identity=void 0}}const f=new l,h={inject:["$toggly"],props:{featureKey:{type:String},featureKeys:{type:Array},requirement:{type:String,default:"all"},negate:{type:Boolean,default:!1}},data(){return{shouldShow:!1,isLoading:!1}},mounted(){this.checkIfShouldShow()},methods:{async checkIfShouldShow(){this.isLoading=!0,this.shouldShow=this.$toggly.shouldShowFeatureDuringEvaluation;var t=[];this.featureKey&&t.push(this.featureKey),this.featureKeys&&(t=t.concat(this.featureKeys)),this.shouldShow=t.length>0?await this.$toggly.evaluateFeatureGate(t,this.requirement,this.negate):!0,this.isLoading=!1}}},g=(t,e)=>{const a=t.__vccOpts||t;for(const[s,i]of e)a[s]=i;return a},c={key:0};function d(t,e,a,s,i,u){return i.shouldShow?(n.openBlock(),n.createElementBlock("div",c,[n.renderSlot(t.$slots,"default")])):n.createCommentVNode("",!0)}const y=g(h,[["render",d]]),_={install:(t,e)=>{const a=f.init(e);t.provide("$toggly",a),t.component("Feature",y)}};r.toggly=_,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -34,7 +34,7 @@
34
34
  "test": "exit 0"
35
35
  },
36
36
  "name": "@ops-ai/vue-feature-flags-toggly",
37
- "version": "1.0.1",
37
+ "version": "1.0.2",
38
38
  "description": "Provides feature flags support for Vue.js applications allowing you to enable and disable features easily. Can be used with or without Toggly.io.",
39
39
  "type": "module",
40
40
  "dependencies": {