@archbase/feature-flags 3.0.0
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/archbase-feature-flags-3.0.0.tgz +0 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useArchbaseFeatureFlag.d.ts +2 -0
- package/dist/hooks/useArchbaseVariant.d.ts +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +344 -0
- package/dist/providers/ArchbaseFeatureFlagsProvider.d.ts +2 -0
- package/dist/providers/index.d.ts +1 -0
- package/dist/types/feature-flags.types.d.ts +42 -0
- package/dist/types/index.d.ts +37 -0
- package/package.json +42 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useArchbaseFeatureFlag.ts +14 -0
- package/src/hooks/useArchbaseVariant.ts +21 -0
- package/src/index.ts +13 -0
- package/src/providers/ArchbaseFeatureFlagsProvider.tsx +54 -0
- package/src/providers/index.ts +1 -0
- package/src/types/feature-flags.types.ts +44 -0
- package/src/types/index.ts +38 -0
|
Binary file
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import te, { useState as g, useMemo as ne, useEffect as j } from "react";
|
|
2
|
+
import { FlagProvider as ae, useFlag as oe, useVariant as se } from "@unleash/proxy-client-react";
|
|
3
|
+
import { useArchbaseTranslation as ue } from "@archbase/core";
|
|
4
|
+
var k = { exports: {} }, _ = {};
|
|
5
|
+
/**
|
|
6
|
+
* @license React
|
|
7
|
+
* react-jsx-runtime.production.js
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
10
|
+
*
|
|
11
|
+
* This source code is licensed under the MIT license found in the
|
|
12
|
+
* LICENSE file in the root directory of this source tree.
|
|
13
|
+
*/
|
|
14
|
+
var M;
|
|
15
|
+
function le() {
|
|
16
|
+
if (M)
|
|
17
|
+
return _;
|
|
18
|
+
M = 1;
|
|
19
|
+
var s = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
|
|
20
|
+
function u(i, l, c) {
|
|
21
|
+
var d = null;
|
|
22
|
+
if (c !== void 0 && (d = "" + c), l.key !== void 0 && (d = "" + l.key), "key" in l) {
|
|
23
|
+
c = {};
|
|
24
|
+
for (var f in l)
|
|
25
|
+
f !== "key" && (c[f] = l[f]);
|
|
26
|
+
} else
|
|
27
|
+
c = l;
|
|
28
|
+
return l = c.ref, {
|
|
29
|
+
$$typeof: s,
|
|
30
|
+
type: i,
|
|
31
|
+
key: d,
|
|
32
|
+
ref: l !== void 0 ? l : null,
|
|
33
|
+
props: c
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return _.Fragment = t, _.jsx = u, _.jsxs = u, _;
|
|
37
|
+
}
|
|
38
|
+
var b = {};
|
|
39
|
+
/**
|
|
40
|
+
* @license React
|
|
41
|
+
* react-jsx-runtime.development.js
|
|
42
|
+
*
|
|
43
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
44
|
+
*
|
|
45
|
+
* This source code is licensed under the MIT license found in the
|
|
46
|
+
* LICENSE file in the root directory of this source tree.
|
|
47
|
+
*/
|
|
48
|
+
var W;
|
|
49
|
+
function ce() {
|
|
50
|
+
return W || (W = 1, process.env.NODE_ENV !== "production" && function() {
|
|
51
|
+
function s(e) {
|
|
52
|
+
if (e == null)
|
|
53
|
+
return null;
|
|
54
|
+
if (typeof e == "function")
|
|
55
|
+
return e.$$typeof === K ? null : e.displayName || e.name || null;
|
|
56
|
+
if (typeof e == "string")
|
|
57
|
+
return e;
|
|
58
|
+
switch (e) {
|
|
59
|
+
case h:
|
|
60
|
+
return "Fragment";
|
|
61
|
+
case J:
|
|
62
|
+
return "Profiler";
|
|
63
|
+
case q:
|
|
64
|
+
return "StrictMode";
|
|
65
|
+
case B:
|
|
66
|
+
return "Suspense";
|
|
67
|
+
case H:
|
|
68
|
+
return "SuspenseList";
|
|
69
|
+
case Q:
|
|
70
|
+
return "Activity";
|
|
71
|
+
}
|
|
72
|
+
if (typeof e == "object")
|
|
73
|
+
switch (typeof e.tag == "number" && console.error(
|
|
74
|
+
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
75
|
+
), e.$$typeof) {
|
|
76
|
+
case V:
|
|
77
|
+
return "Portal";
|
|
78
|
+
case G:
|
|
79
|
+
return e.displayName || "Context";
|
|
80
|
+
case z:
|
|
81
|
+
return (e._context.displayName || "Context") + ".Consumer";
|
|
82
|
+
case X:
|
|
83
|
+
var r = e.render;
|
|
84
|
+
return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
85
|
+
case Z:
|
|
86
|
+
return r = e.displayName || null, r !== null ? r : s(e.type) || "Memo";
|
|
87
|
+
case x:
|
|
88
|
+
r = e._payload, e = e._init;
|
|
89
|
+
try {
|
|
90
|
+
return s(e(r));
|
|
91
|
+
} catch {
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
function t(e) {
|
|
97
|
+
return "" + e;
|
|
98
|
+
}
|
|
99
|
+
function u(e) {
|
|
100
|
+
try {
|
|
101
|
+
t(e);
|
|
102
|
+
var r = !1;
|
|
103
|
+
} catch {
|
|
104
|
+
r = !0;
|
|
105
|
+
}
|
|
106
|
+
if (r) {
|
|
107
|
+
r = console;
|
|
108
|
+
var n = r.error, a = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
109
|
+
return n.call(
|
|
110
|
+
r,
|
|
111
|
+
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
112
|
+
a
|
|
113
|
+
), t(e);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function i(e) {
|
|
117
|
+
if (e === h)
|
|
118
|
+
return "<>";
|
|
119
|
+
if (typeof e == "object" && e !== null && e.$$typeof === x)
|
|
120
|
+
return "<...>";
|
|
121
|
+
try {
|
|
122
|
+
var r = s(e);
|
|
123
|
+
return r ? "<" + r + ">" : "<...>";
|
|
124
|
+
} catch {
|
|
125
|
+
return "<...>";
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function l() {
|
|
129
|
+
var e = y.A;
|
|
130
|
+
return e === null ? null : e.getOwner();
|
|
131
|
+
}
|
|
132
|
+
function c() {
|
|
133
|
+
return Error("react-stack-top-frame");
|
|
134
|
+
}
|
|
135
|
+
function d(e) {
|
|
136
|
+
if (F.call(e, "key")) {
|
|
137
|
+
var r = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
138
|
+
if (r && r.isReactWarning)
|
|
139
|
+
return !1;
|
|
140
|
+
}
|
|
141
|
+
return e.key !== void 0;
|
|
142
|
+
}
|
|
143
|
+
function f(e, r) {
|
|
144
|
+
function n() {
|
|
145
|
+
Y || (Y = !0, console.error(
|
|
146
|
+
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
147
|
+
r
|
|
148
|
+
));
|
|
149
|
+
}
|
|
150
|
+
n.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
151
|
+
get: n,
|
|
152
|
+
configurable: !0
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function A() {
|
|
156
|
+
var e = s(this.type);
|
|
157
|
+
return I[e] || (I[e] = !0, console.error(
|
|
158
|
+
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
159
|
+
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
160
|
+
}
|
|
161
|
+
function w(e, r, n, a, T, S) {
|
|
162
|
+
var o = n.ref;
|
|
163
|
+
return e = {
|
|
164
|
+
$$typeof: C,
|
|
165
|
+
type: e,
|
|
166
|
+
key: r,
|
|
167
|
+
props: n,
|
|
168
|
+
_owner: a
|
|
169
|
+
}, (o !== void 0 ? o : null) !== null ? Object.defineProperty(e, "ref", {
|
|
170
|
+
enumerable: !1,
|
|
171
|
+
get: A
|
|
172
|
+
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
173
|
+
configurable: !1,
|
|
174
|
+
enumerable: !1,
|
|
175
|
+
writable: !0,
|
|
176
|
+
value: 0
|
|
177
|
+
}), Object.defineProperty(e, "_debugInfo", {
|
|
178
|
+
configurable: !1,
|
|
179
|
+
enumerable: !1,
|
|
180
|
+
writable: !0,
|
|
181
|
+
value: null
|
|
182
|
+
}), Object.defineProperty(e, "_debugStack", {
|
|
183
|
+
configurable: !1,
|
|
184
|
+
enumerable: !1,
|
|
185
|
+
writable: !0,
|
|
186
|
+
value: T
|
|
187
|
+
}), Object.defineProperty(e, "_debugTask", {
|
|
188
|
+
configurable: !1,
|
|
189
|
+
enumerable: !1,
|
|
190
|
+
writable: !0,
|
|
191
|
+
value: S
|
|
192
|
+
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
193
|
+
}
|
|
194
|
+
function v(e, r, n, a, T, S) {
|
|
195
|
+
var o = r.children;
|
|
196
|
+
if (o !== void 0)
|
|
197
|
+
if (a)
|
|
198
|
+
if (ee(o)) {
|
|
199
|
+
for (a = 0; a < o.length; a++)
|
|
200
|
+
p(o[a]);
|
|
201
|
+
Object.freeze && Object.freeze(o);
|
|
202
|
+
} else
|
|
203
|
+
console.error(
|
|
204
|
+
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
205
|
+
);
|
|
206
|
+
else
|
|
207
|
+
p(o);
|
|
208
|
+
if (F.call(r, "key")) {
|
|
209
|
+
o = s(e);
|
|
210
|
+
var E = Object.keys(r).filter(function(re) {
|
|
211
|
+
return re !== "key";
|
|
212
|
+
});
|
|
213
|
+
a = 0 < E.length ? "{key: someKey, " + E.join(": ..., ") + ": ...}" : "{key: someKey}", D[o + a] || (E = 0 < E.length ? "{" + E.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
214
|
+
`A props object containing a "key" prop is being spread into JSX:
|
|
215
|
+
let props = %s;
|
|
216
|
+
<%s {...props} />
|
|
217
|
+
React keys must be passed directly to JSX without using spread:
|
|
218
|
+
let props = %s;
|
|
219
|
+
<%s key={someKey} {...props} />`,
|
|
220
|
+
a,
|
|
221
|
+
o,
|
|
222
|
+
E,
|
|
223
|
+
o
|
|
224
|
+
), D[o + a] = !0);
|
|
225
|
+
}
|
|
226
|
+
if (o = null, n !== void 0 && (u(n), o = "" + n), d(r) && (u(r.key), o = "" + r.key), "key" in r) {
|
|
227
|
+
n = {};
|
|
228
|
+
for (var P in r)
|
|
229
|
+
P !== "key" && (n[P] = r[P]);
|
|
230
|
+
} else
|
|
231
|
+
n = r;
|
|
232
|
+
return o && f(
|
|
233
|
+
n,
|
|
234
|
+
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
235
|
+
), w(
|
|
236
|
+
e,
|
|
237
|
+
o,
|
|
238
|
+
n,
|
|
239
|
+
l(),
|
|
240
|
+
T,
|
|
241
|
+
S
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
function p(e) {
|
|
245
|
+
N(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === x && (e._payload.status === "fulfilled" ? N(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
|
|
246
|
+
}
|
|
247
|
+
function N(e) {
|
|
248
|
+
return typeof e == "object" && e !== null && e.$$typeof === C;
|
|
249
|
+
}
|
|
250
|
+
var R = te, C = Symbol.for("react.transitional.element"), V = Symbol.for("react.portal"), h = Symbol.for("react.fragment"), q = Symbol.for("react.strict_mode"), J = Symbol.for("react.profiler"), z = Symbol.for("react.consumer"), G = Symbol.for("react.context"), X = Symbol.for("react.forward_ref"), B = Symbol.for("react.suspense"), H = Symbol.for("react.suspense_list"), Z = Symbol.for("react.memo"), x = Symbol.for("react.lazy"), Q = Symbol.for("react.activity"), K = Symbol.for("react.client.reference"), y = R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, F = Object.prototype.hasOwnProperty, ee = Array.isArray, O = console.createTask ? console.createTask : function() {
|
|
251
|
+
return null;
|
|
252
|
+
};
|
|
253
|
+
R = {
|
|
254
|
+
react_stack_bottom_frame: function(e) {
|
|
255
|
+
return e();
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
var Y, I = {}, $ = R.react_stack_bottom_frame.bind(
|
|
259
|
+
R,
|
|
260
|
+
c
|
|
261
|
+
)(), L = O(i(c)), D = {};
|
|
262
|
+
b.Fragment = h, b.jsx = function(e, r, n) {
|
|
263
|
+
var a = 1e4 > y.recentlyCreatedOwnerStacks++;
|
|
264
|
+
return v(
|
|
265
|
+
e,
|
|
266
|
+
r,
|
|
267
|
+
n,
|
|
268
|
+
!1,
|
|
269
|
+
a ? Error("react-stack-top-frame") : $,
|
|
270
|
+
a ? O(i(e)) : L
|
|
271
|
+
);
|
|
272
|
+
}, b.jsxs = function(e, r, n) {
|
|
273
|
+
var a = 1e4 > y.recentlyCreatedOwnerStacks++;
|
|
274
|
+
return v(
|
|
275
|
+
e,
|
|
276
|
+
r,
|
|
277
|
+
n,
|
|
278
|
+
!0,
|
|
279
|
+
a ? Error("react-stack-top-frame") : $,
|
|
280
|
+
a ? O(i(e)) : L
|
|
281
|
+
);
|
|
282
|
+
};
|
|
283
|
+
}()), b;
|
|
284
|
+
}
|
|
285
|
+
var U;
|
|
286
|
+
function ie() {
|
|
287
|
+
return U || (U = 1, process.env.NODE_ENV === "production" ? k.exports = le() : k.exports = ce()), k.exports;
|
|
288
|
+
}
|
|
289
|
+
var m = ie();
|
|
290
|
+
function Ee({
|
|
291
|
+
children: s,
|
|
292
|
+
config: t,
|
|
293
|
+
startClient: u = !0,
|
|
294
|
+
errorComponent: i,
|
|
295
|
+
loadingComponent: l
|
|
296
|
+
}) {
|
|
297
|
+
const { t: c } = ue(), [d, f] = g(!1), [A, w] = g(null), v = ne(() => ({
|
|
298
|
+
url: t.url,
|
|
299
|
+
clientKey: t.clientKey,
|
|
300
|
+
appName: t.appName,
|
|
301
|
+
environment: t.environment || "production",
|
|
302
|
+
refreshInterval: t.refreshInterval || 3e4,
|
|
303
|
+
context: t.context
|
|
304
|
+
}), [t]);
|
|
305
|
+
return j(() => {
|
|
306
|
+
if (!u) {
|
|
307
|
+
f(!0);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
const p = setTimeout(() => f(!0), 100);
|
|
311
|
+
return () => clearTimeout(p);
|
|
312
|
+
}, [u]), A ? /* @__PURE__ */ m.jsx(m.Fragment, { children: i || /* @__PURE__ */ m.jsx("div", { children: String(c("Error loading feature flags")) }) }) : d ? /* @__PURE__ */ m.jsx(
|
|
313
|
+
ae,
|
|
314
|
+
{
|
|
315
|
+
config: v,
|
|
316
|
+
startClient: u,
|
|
317
|
+
children: s
|
|
318
|
+
}
|
|
319
|
+
) : /* @__PURE__ */ m.jsx(m.Fragment, { children: l || /* @__PURE__ */ m.jsx("div", { children: String(c("Loading feature flags...")) }) });
|
|
320
|
+
}
|
|
321
|
+
function _e(s) {
|
|
322
|
+
const t = oe(s), [u, i] = g(!0);
|
|
323
|
+
return j(() => {
|
|
324
|
+
i(!1);
|
|
325
|
+
}, [s]), { enabled: t, loading: u };
|
|
326
|
+
}
|
|
327
|
+
function be(s) {
|
|
328
|
+
const t = se(s), [u, i] = g(!0);
|
|
329
|
+
return j(() => {
|
|
330
|
+
i(!1);
|
|
331
|
+
}, [s]), {
|
|
332
|
+
variant: t != null && t.name && (t != null && t.enabled) ? {
|
|
333
|
+
name: t.name,
|
|
334
|
+
enabled: t.enabled,
|
|
335
|
+
payload: t.payload
|
|
336
|
+
} : void 0,
|
|
337
|
+
loading: u
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
export {
|
|
341
|
+
Ee as ArchbaseFeatureFlagsProvider,
|
|
342
|
+
_e as useArchbaseFeatureFlag,
|
|
343
|
+
be as useArchbaseVariant
|
|
344
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ArchbaseFeatureFlagsProvider } from './ArchbaseFeatureFlagsProvider';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export interface UnleashConfig {
|
|
3
|
+
url: string;
|
|
4
|
+
clientKey: string;
|
|
5
|
+
appName: string;
|
|
6
|
+
environment?: 'development' | 'production' | 'staging';
|
|
7
|
+
refreshInterval?: number;
|
|
8
|
+
context?: {
|
|
9
|
+
userId?: string;
|
|
10
|
+
sessionId?: string;
|
|
11
|
+
properties?: Record<string, string>;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface ArchbaseFeatureFlagsProviderProps {
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
config: UnleashConfig;
|
|
17
|
+
startClient?: boolean;
|
|
18
|
+
errorComponent?: ReactNode;
|
|
19
|
+
loadingComponent?: ReactNode;
|
|
20
|
+
}
|
|
21
|
+
export interface UseFeatureFlagResult {
|
|
22
|
+
enabled: boolean;
|
|
23
|
+
loading: boolean;
|
|
24
|
+
error?: Error;
|
|
25
|
+
}
|
|
26
|
+
export interface UseVariantResult<T = any> {
|
|
27
|
+
variant: {
|
|
28
|
+
name: string;
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
payload: {
|
|
31
|
+
type: string;
|
|
32
|
+
value: string;
|
|
33
|
+
};
|
|
34
|
+
} | undefined;
|
|
35
|
+
loading: boolean;
|
|
36
|
+
error?: Error;
|
|
37
|
+
}
|
|
38
|
+
export interface UseFeatureFlagsResult {
|
|
39
|
+
flags: Record<string, boolean>;
|
|
40
|
+
loading: boolean;
|
|
41
|
+
error?: Error;
|
|
42
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export interface UnleashConfig {
|
|
3
|
+
url: string;
|
|
4
|
+
clientKey: string;
|
|
5
|
+
appName: string;
|
|
6
|
+
environment?: 'development' | 'production' | 'staging';
|
|
7
|
+
refreshInterval?: number;
|
|
8
|
+
context?: {
|
|
9
|
+
userId?: string;
|
|
10
|
+
sessionId?: string;
|
|
11
|
+
properties?: Record<string, string>;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface ArchbaseFeatureFlagsProviderProps {
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
config: UnleashConfig;
|
|
17
|
+
startClient?: boolean;
|
|
18
|
+
errorComponent?: ReactNode;
|
|
19
|
+
loadingComponent?: ReactNode;
|
|
20
|
+
}
|
|
21
|
+
export interface UseFeatureFlagResult {
|
|
22
|
+
enabled: boolean;
|
|
23
|
+
loading: boolean;
|
|
24
|
+
error?: Error;
|
|
25
|
+
}
|
|
26
|
+
export interface UseVariantResult<T = any> {
|
|
27
|
+
variant: {
|
|
28
|
+
name: string;
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
payload?: {
|
|
31
|
+
type: string;
|
|
32
|
+
value: string;
|
|
33
|
+
};
|
|
34
|
+
} | undefined;
|
|
35
|
+
loading: boolean;
|
|
36
|
+
error?: Error;
|
|
37
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@archbase/feature-flags",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "Feature flags integration for Archbase React v3 using Unleash",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"src"
|
|
19
|
+
],
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"@mantine/core": "8.3.12",
|
|
22
|
+
"react": "^18.3.0 || ^19.0.0",
|
|
23
|
+
"react-dom": "^18.3.0 || ^19.0.0"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@unleash/proxy-client-react": "^3.6.0",
|
|
27
|
+
"@archbase/core": "3.0.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/react": "^19.0.6",
|
|
31
|
+
"@types/react-dom": "^19.0.2",
|
|
32
|
+
"typescript": "^5.8.0",
|
|
33
|
+
"vite": "^6.4.1",
|
|
34
|
+
"vite-plugin-dts": "^4.5.0"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "vite build && tsc --emitDeclarationOnly || true",
|
|
38
|
+
"dev": "vite build --watch",
|
|
39
|
+
"lint": "eslint src",
|
|
40
|
+
"typecheck": "tsc --noEmit"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useFlag } from '@unleash/proxy-client-react';
|
|
2
|
+
import { useState, useEffect } from 'react';
|
|
3
|
+
import type { UseFeatureFlagResult } from '../types';
|
|
4
|
+
|
|
5
|
+
export function useArchbaseFeatureFlag(featureName: string): UseFeatureFlagResult {
|
|
6
|
+
const enabled = useFlag(featureName);
|
|
7
|
+
const [loading, setLoading] = useState(true);
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
setLoading(false);
|
|
11
|
+
}, [featureName]);
|
|
12
|
+
|
|
13
|
+
return { enabled, loading };
|
|
14
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useVariant } from '@unleash/proxy-client-react';
|
|
2
|
+
import { useState, useEffect } from 'react';
|
|
3
|
+
import type { UseVariantResult } from '../types';
|
|
4
|
+
|
|
5
|
+
export function useArchbaseVariant<T = any>(featureName: string): UseVariantResult<T> {
|
|
6
|
+
const variant = useVariant(featureName);
|
|
7
|
+
const [loading, setLoading] = useState(true);
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
setLoading(false);
|
|
11
|
+
}, [featureName]);
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
variant: variant?.name && variant?.enabled ? {
|
|
15
|
+
name: variant.name,
|
|
16
|
+
enabled: variant.enabled,
|
|
17
|
+
payload: variant.payload as { type: string; value: string },
|
|
18
|
+
} : undefined,
|
|
19
|
+
loading,
|
|
20
|
+
};
|
|
21
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Providers
|
|
2
|
+
export { ArchbaseFeatureFlagsProvider } from './providers';
|
|
3
|
+
|
|
4
|
+
// Hooks
|
|
5
|
+
export { useArchbaseFeatureFlag, useArchbaseVariant } from './hooks';
|
|
6
|
+
|
|
7
|
+
// Types
|
|
8
|
+
export type {
|
|
9
|
+
ArchbaseFeatureFlagsProviderProps,
|
|
10
|
+
UnleashConfig,
|
|
11
|
+
UseFeatureFlagResult,
|
|
12
|
+
UseVariantResult,
|
|
13
|
+
} from './types';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React, { useState, useEffect, useMemo } from 'react';
|
|
2
|
+
import { FlagProvider } from '@unleash/proxy-client-react';
|
|
3
|
+
import { useArchbaseTranslation } from '@archbase/core';
|
|
4
|
+
import type {
|
|
5
|
+
ArchbaseFeatureFlagsProviderProps,
|
|
6
|
+
} from '../types';
|
|
7
|
+
|
|
8
|
+
export function ArchbaseFeatureFlagsProvider({
|
|
9
|
+
children,
|
|
10
|
+
config,
|
|
11
|
+
startClient = true,
|
|
12
|
+
errorComponent,
|
|
13
|
+
loadingComponent,
|
|
14
|
+
}: ArchbaseFeatureFlagsProviderProps) {
|
|
15
|
+
const { t } = useArchbaseTranslation();
|
|
16
|
+
const [isReady, setIsReady] = useState(false);
|
|
17
|
+
const [error, setError] = useState<Error | null>(null);
|
|
18
|
+
|
|
19
|
+
const unleashConfig = useMemo(() => ({
|
|
20
|
+
url: config.url,
|
|
21
|
+
clientKey: config.clientKey,
|
|
22
|
+
appName: config.appName,
|
|
23
|
+
environment: config.environment || 'production',
|
|
24
|
+
refreshInterval: config.refreshInterval || 30000,
|
|
25
|
+
context: config.context,
|
|
26
|
+
}), [config]);
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!startClient) {
|
|
30
|
+
setIsReady(true);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const timer = setTimeout(() => setIsReady(true), 100);
|
|
35
|
+
return () => clearTimeout(timer);
|
|
36
|
+
}, [startClient]);
|
|
37
|
+
|
|
38
|
+
if (error) {
|
|
39
|
+
return <>{errorComponent || <div>{String(t('Error loading feature flags'))}</div>}</>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!isReady) {
|
|
43
|
+
return <>{loadingComponent || <div>{String(t('Loading feature flags...'))}</div>}</>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<FlagProvider
|
|
48
|
+
config={unleashConfig}
|
|
49
|
+
startClient={startClient}
|
|
50
|
+
>
|
|
51
|
+
{children}
|
|
52
|
+
</FlagProvider>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ArchbaseFeatureFlagsProvider } from './ArchbaseFeatureFlagsProvider';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface UnleashConfig {
|
|
4
|
+
url: string;
|
|
5
|
+
clientKey: string;
|
|
6
|
+
appName: string;
|
|
7
|
+
environment?: 'development' | 'production' | 'staging';
|
|
8
|
+
refreshInterval?: number;
|
|
9
|
+
context?: {
|
|
10
|
+
userId?: string;
|
|
11
|
+
sessionId?: string;
|
|
12
|
+
properties?: Record<string, string>;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ArchbaseFeatureFlagsProviderProps {
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
config: UnleashConfig;
|
|
19
|
+
startClient?: boolean;
|
|
20
|
+
errorComponent?: ReactNode;
|
|
21
|
+
loadingComponent?: ReactNode;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface UseFeatureFlagResult {
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
loading: boolean;
|
|
27
|
+
error?: Error;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface UseVariantResult<T = any> {
|
|
31
|
+
variant: {
|
|
32
|
+
name: string;
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
payload: { type: string; value: string };
|
|
35
|
+
} | undefined;
|
|
36
|
+
loading: boolean;
|
|
37
|
+
error?: Error;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface UseFeatureFlagsResult {
|
|
41
|
+
flags: Record<string, boolean>;
|
|
42
|
+
loading: boolean;
|
|
43
|
+
error?: Error;
|
|
44
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface UnleashConfig {
|
|
4
|
+
url: string;
|
|
5
|
+
clientKey: string;
|
|
6
|
+
appName: string;
|
|
7
|
+
environment?: 'development' | 'production' | 'staging';
|
|
8
|
+
refreshInterval?: number;
|
|
9
|
+
context?: {
|
|
10
|
+
userId?: string;
|
|
11
|
+
sessionId?: string;
|
|
12
|
+
properties?: Record<string, string>;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ArchbaseFeatureFlagsProviderProps {
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
config: UnleashConfig;
|
|
19
|
+
startClient?: boolean;
|
|
20
|
+
errorComponent?: ReactNode;
|
|
21
|
+
loadingComponent?: ReactNode;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface UseFeatureFlagResult {
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
loading: boolean;
|
|
27
|
+
error?: Error;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface UseVariantResult<T = any> {
|
|
31
|
+
variant: {
|
|
32
|
+
name: string;
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
payload?: { type: string; value: string };
|
|
35
|
+
} | undefined;
|
|
36
|
+
loading: boolean;
|
|
37
|
+
error?: Error;
|
|
38
|
+
}
|