@nexussdk/sdk 0.0.1 → 0.0.4
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/README.md +162 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.mts +41 -45
- package/dist/index.d.ts +41 -45
- package/dist/index.global.js +4 -4
- package/dist/index.mjs +2 -2
- package/dist/react.cjs +2 -2
- package/dist/react.d.mts +111 -76
- package/dist/react.d.ts +111 -76
- package/dist/react.mjs +2 -2
- package/dist/vue.cjs +2 -0
- package/dist/vue.d.mts +234 -0
- package/dist/vue.d.ts +234 -0
- package/dist/vue.mjs +2 -0
- package/package.json +62 -9
- package/.turbo/turbo-build.log +0 -45
- package/dist/index.cjs.map +0 -1
- package/dist/index.global.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/react.cjs.map +0 -1
- package/dist/react.mjs.map +0 -1
- package/src/index.ts +0 -27
- package/src/nexus.ts +0 -208
- package/src/react.tsx +0 -204
- package/tsconfig.json +0 -10
- package/tsup.config.ts +0 -40
package/dist/vue.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var vue=require('vue'),flags=require('@nexussdk/flags'),tracker=require('@nexussdk/tracker');var p=class e{static instance=null;static vitalsCleanup=null;flags;tracker;constructor(t={}){let{apiKey:n,baseUrl:r,user:o,environment:a,tags:s,autoCapture:i,sampling:f,transport:x,vitals:l,devServer:c,flags:g,tracker:C}=t;this.flags=new flags.NexusFlagsClient({apiKey:n,baseUrl:r,user:o,...g});let m=r,I=x;if(c?.enabled){let d=c.port??4567;m=`http://${c.host??"localhost"}:${d}`;}if(this.tracker=new tracker.NexusTrackerClient({apiKey:n,baseUrl:m,environment:a,tags:s,autoCapture:i,sampling:f,transport:I,...C}),l){let d=typeof l=="object"?l:{};e.vitalsCleanup=tracker.attachWebVitals(this.tracker,d);}}static init(t={}){return e.instance||(e.instance=new e(t)),e.instance}static getInstance(){if(!e.instance)throw new Error('[Nexus SDK] Not initialized. Call Nexus.init({ apiKey: "..." }) first.');return e.instance}static isEnabled(t,n=false){return e.getInstance().flags.isEnabled(t,n)}static getVariant(t,n,r){return e.getInstance().flags.getVariant(t,n,r)}static captureError(t,n){e.getInstance().tracker.captureError(t,n);}static captureMessage(t,n="info",r){e.getInstance().tracker.captureMessage(t,n,r);}static addBreadcrumb(t){e.getInstance().tracker.addBreadcrumb(t);}static setExtra(t,n){e.getInstance().tracker.setExtra(t,n);}static attachWebVitals(t){return tracker.attachWebVitals(e.getInstance().tracker,t)}static async identify(t){let n=e.getInstance();n.tracker.setUser(t),await n.flags.identify(t);}static reset(){let t=e.getInstance();t.tracker.setUser(null),t.flags.reset();}static async destroy(){e.vitalsCleanup&&(e.vitalsCleanup(),e.vitalsCleanup=null),e.instance&&(await e.instance.tracker.flush(),e.instance.tracker.destroy(),e.instance.flags.destroy(),e.instance=null);}};var y=Symbol("NexusSDK"),H={install(e,t={}){let n=p.init(t),r={flags:n.flags,tracker:n.tracker,nexus:n};e.provide(y,r);let o=e.config.errorHandler;e.config.errorHandler=(a,s,i)=>{n.tracker.captureError(a,{componentStack:i,tags:{framework:"vue3",component:s?.$options?.name||"AnonymousComponent"}}),o&&o(a,s,i);},e.component("NexusGuard",R);}};function N(){let e=vue.inject(y);if(e)return e;let t=p.getInstance();return {flags:t.flags,tracker:t.tracker,nexus:t}}function A(e,t=false){let{flags:n}=N(),r=vue.ref(n.isEnabled(e,t)),o=vue.shallowRef(null),a=n.onFlagChange(e,s=>{r.value=s.enabled,o.value=s;});return vue.onUnmounted(()=>{a();}),{enabled:r,getVariant:(s,i)=>n.getVariant(e,s,i),result:o}}var R=vue.defineComponent({name:"NexusGuard",props:{onError:{type:Function,default:void 0},tags:{type:Object,default:()=>({})}},setup(e,{slots:t}){let n=vue.ref(false),r=vue.shallowRef(null),o=()=>{n.value=false,r.value=null;};return vue.onErrorCaptured((a,s,i)=>{let f=tracker.parseStackTrace(a.stack),l=`NX-${tracker.computeFingerprint(a.name,a.message,f[0]).replace(/^fp_/,"").slice(0,8).toUpperCase()}`,c={error:a,errorId:l,componentStack:i,reset:o};n.value=true,r.value=c;try{let{tracker:g}=N();g.captureError(a,{componentStack:i,tags:{...e.tags,guardErrorId:l,framework:"vue3",component:s?.$options?.name||"AnonymousComponent"}});}catch{}if(e.onError)try{e.onError(a,c);}catch{}return false}),()=>n.value&&r.value?t.fallback?t.fallback(r.value):vue.h("div",{role:"alert",style:{padding:"16px 20px",margin:"12px 0",borderRadius:"8px",backgroundColor:"#1f1315",border:"1px solid #7f1d1d",color:"#fca5a5",fontFamily:"-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, sans-serif",fontSize:"14px"}},[vue.h("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"8px"}},[vue.h("strong",{style:{color:"#ef4444"}},"Vue Component Crash Protected"),vue.h("span",{style:{fontFamily:"monospace",fontSize:"12px",background:"#450a0a",padding:"2px 8px",borderRadius:"4px"}},r.value.errorId)]),vue.h("p",{style:{margin:"0 0 12px 0",color:"#fecaca"}},r.value.error.message),vue.h("button",{type:"button",onClick:o,style:{background:"#b91c1c",border:"none",color:"#fff",padding:"6px 14px",borderRadius:"6px",fontSize:"13px",cursor:"pointer",fontWeight:"500"}},"Retry Component")]):t.default?t.default():null}});
|
|
2
|
+
exports.NEXUS_KEY=y;exports.NexusGuardVue=R;exports.NexusPlugin=H;exports.useFlag=A;exports.useNexus=N;
|
package/dist/vue.d.mts
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { InjectionKey, Plugin, Ref } from 'vue';
|
|
3
|
+
import { NexusFlagsClient, NexusFlagsOptions } from '@nexussdk/flags';
|
|
4
|
+
import { NexusTrackerClient, NexusTrackerOptions } from '@nexussdk/tracker';
|
|
5
|
+
import { UserContext, SamplingConfig, TransportPlugin, PerformanceVitalsOptions, SeverityLevel, Breadcrumb, NexusErrorInfo, FlagEvaluationResult } from '@nexussdk/contracts';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @fileoverview Unified Nexus singleton facade wrapping Flags and Tracker clients.
|
|
9
|
+
* @module @nexus/sdk/nexus
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Dev server routing configuration.
|
|
14
|
+
*/
|
|
15
|
+
interface NexusDevServerOptions {
|
|
16
|
+
/** Enable local dev server ingestion mode. Auto-enabled in development if true. */
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
/** Port the dev server is listening on. Defaults to 4567. */
|
|
19
|
+
port?: number;
|
|
20
|
+
/** Host the dev server is bound to. Defaults to 'localhost'. */
|
|
21
|
+
host?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Unified initialization options for the Nexus SDK umbrella.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* Nexus.init({
|
|
28
|
+
* apiKey: 'pk_live_...',
|
|
29
|
+
* user: { id: 'usr_12345', country: 'VN' },
|
|
30
|
+
* environment: 'production',
|
|
31
|
+
* autoCapture: true,
|
|
32
|
+
* devServer: { enabled: process.env.NODE_ENV === 'development' },
|
|
33
|
+
* });
|
|
34
|
+
*/
|
|
35
|
+
interface NexusInitOptions {
|
|
36
|
+
/** Public API key. Resolved from env if omitted. */
|
|
37
|
+
apiKey?: string;
|
|
38
|
+
/** Base URL for all API calls. */
|
|
39
|
+
baseUrl?: string;
|
|
40
|
+
/** Initial user context for flag targeting and error attribution. */
|
|
41
|
+
user?: UserContext;
|
|
42
|
+
/** Target environment for telemetry routing. Defaults to 'production'. */
|
|
43
|
+
environment?: string;
|
|
44
|
+
/** Global tags attached to all telemetry events. */
|
|
45
|
+
tags?: Record<string, string>;
|
|
46
|
+
/** Toggle automated global error capture. Defaults to true. */
|
|
47
|
+
autoCapture?: boolean;
|
|
48
|
+
/** Client-side rate limiting and deduplication sampling options. */
|
|
49
|
+
sampling?: SamplingConfig;
|
|
50
|
+
/** Pluggable transport adapter ('fetch', 'console', 'localStorage', custom fn). */
|
|
51
|
+
transport?: TransportPlugin;
|
|
52
|
+
/** Web Vitals performance observer options, or true for default observation. */
|
|
53
|
+
vitals?: boolean | PerformanceVitalsOptions;
|
|
54
|
+
/** Local dev server auto-routing configuration. */
|
|
55
|
+
devServer?: NexusDevServerOptions;
|
|
56
|
+
/** Additional flags-specific options. */
|
|
57
|
+
flags?: Partial<NexusFlagsOptions>;
|
|
58
|
+
/** Additional tracker-specific options. */
|
|
59
|
+
tracker?: Partial<NexusTrackerOptions>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The Nexus singleton class — the primary unified entry point for the SDK.
|
|
63
|
+
*
|
|
64
|
+
* Provides access to both the feature flags client and the error tracker client.
|
|
65
|
+
* Initialize once, then use throughout your application.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* // Initialize (call once at app startup)
|
|
69
|
+
* Nexus.init({ apiKey: 'pk_live_...' });
|
|
70
|
+
*
|
|
71
|
+
* // Feature flags
|
|
72
|
+
* const showBanner = Nexus.isEnabled('promo_banner_v2', false);
|
|
73
|
+
*
|
|
74
|
+
* // Error tracking
|
|
75
|
+
* Nexus.captureError(new Error('Something went wrong'));
|
|
76
|
+
*
|
|
77
|
+
* // Update user context
|
|
78
|
+
* await Nexus.identify({ id: 'usr_12345', country: 'VN' });
|
|
79
|
+
*/
|
|
80
|
+
declare class Nexus {
|
|
81
|
+
private static instance;
|
|
82
|
+
private static vitalsCleanup;
|
|
83
|
+
/** The underlying feature flags client instance. */
|
|
84
|
+
readonly flags: NexusFlagsClient;
|
|
85
|
+
/** The underlying error tracker client instance. */
|
|
86
|
+
readonly tracker: NexusTrackerClient;
|
|
87
|
+
private constructor();
|
|
88
|
+
/**
|
|
89
|
+
* Initializes the Nexus SDK singleton.
|
|
90
|
+
* Must be called before any other SDK methods.
|
|
91
|
+
* Safe to call multiple times — returns existing instance after first init.
|
|
92
|
+
*
|
|
93
|
+
* @param options - SDK configuration options.
|
|
94
|
+
* @returns The initialized Nexus singleton instance.
|
|
95
|
+
*/
|
|
96
|
+
static init(options?: NexusInitOptions): Nexus;
|
|
97
|
+
/**
|
|
98
|
+
* Returns the current Nexus singleton instance.
|
|
99
|
+
*
|
|
100
|
+
* @returns The active Nexus instance.
|
|
101
|
+
* @throws {Error} If `Nexus.init()` has not been called yet.
|
|
102
|
+
*/
|
|
103
|
+
static getInstance(): Nexus;
|
|
104
|
+
/**
|
|
105
|
+
* Convenience method: Check if a feature flag is enabled.
|
|
106
|
+
*/
|
|
107
|
+
static isEnabled(key: string, defaultValue?: boolean): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Convenience method: Get a flag variant value.
|
|
110
|
+
*/
|
|
111
|
+
static getVariant<T = unknown>(key: string, variantKey: string, defaultValue?: T): T;
|
|
112
|
+
/**
|
|
113
|
+
* Convenience method: Capture an error manually.
|
|
114
|
+
*/
|
|
115
|
+
static captureError(error: unknown, extra?: Record<string, unknown>): void;
|
|
116
|
+
/**
|
|
117
|
+
* Convenience method: Capture an informational or warning message event.
|
|
118
|
+
*/
|
|
119
|
+
static captureMessage(message: string, level?: SeverityLevel, extra?: Record<string, unknown>): void;
|
|
120
|
+
/**
|
|
121
|
+
* Convenience method: Add a breadcrumb manually.
|
|
122
|
+
*/
|
|
123
|
+
static addBreadcrumb(breadcrumb: Breadcrumb): void;
|
|
124
|
+
/**
|
|
125
|
+
* Convenience method: Set extra contextual metadata.
|
|
126
|
+
*/
|
|
127
|
+
static setExtra(key: string, value: unknown): void;
|
|
128
|
+
/**
|
|
129
|
+
* Convenience method: Attach Web Vitals observer to tracker.
|
|
130
|
+
*/
|
|
131
|
+
static attachWebVitals(options?: PerformanceVitalsOptions): () => void;
|
|
132
|
+
/**
|
|
133
|
+
* Convenience method: Update user context for both flags and tracker.
|
|
134
|
+
*/
|
|
135
|
+
static identify(user: UserContext): Promise<void>;
|
|
136
|
+
/**
|
|
137
|
+
* Resets user context to anonymous state (e.g. on logout).
|
|
138
|
+
*/
|
|
139
|
+
static reset(): void;
|
|
140
|
+
/**
|
|
141
|
+
* Gracefully tears down both clients, closing SSE connections and flushing pending events.
|
|
142
|
+
*/
|
|
143
|
+
static destroy(): Promise<void>;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
interface NexusVueContext {
|
|
147
|
+
flags: NexusFlagsClient;
|
|
148
|
+
tracker: NexusTrackerClient;
|
|
149
|
+
nexus: Nexus;
|
|
150
|
+
}
|
|
151
|
+
declare const NEXUS_KEY: InjectionKey<NexusVueContext>;
|
|
152
|
+
/**
|
|
153
|
+
* Vue 3 Plugin for initializing Nexus SDK and setting up global error handling.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* // main.ts
|
|
157
|
+
* import { createApp } from 'vue';
|
|
158
|
+
* import { NexusPlugin } from '@nexussdk/sdk/vue';
|
|
159
|
+
* import App from './App.vue';
|
|
160
|
+
*
|
|
161
|
+
* const app = createApp(App);
|
|
162
|
+
* app.use(NexusPlugin, {
|
|
163
|
+
* apiKey: 'pk_live_...',
|
|
164
|
+
* environment: 'production',
|
|
165
|
+
* });
|
|
166
|
+
* app.mount('#app');
|
|
167
|
+
*/
|
|
168
|
+
declare const NexusPlugin: Plugin;
|
|
169
|
+
/**
|
|
170
|
+
* Returns the Nexus context in a Vue component setup function.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* const { flags, tracker } = useNexus();
|
|
174
|
+
* tracker.captureMessage('Button clicked', 'info');
|
|
175
|
+
*/
|
|
176
|
+
declare function useNexus(): NexusVueContext;
|
|
177
|
+
interface UseFlagVueResult {
|
|
178
|
+
enabled: Ref<boolean>;
|
|
179
|
+
getVariant: <T = unknown>(variantKey: string, defaultValue?: T) => T;
|
|
180
|
+
result: Ref<FlagEvaluationResult | null>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Vue 3 composable for subscribing to real-time feature flag changes.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* const { enabled, getVariant } = useFlag('promo_banner_v2');
|
|
187
|
+
*/
|
|
188
|
+
declare function useFlag(key: string, defaultEnabled?: boolean): UseFlagVueResult;
|
|
189
|
+
/**
|
|
190
|
+
* Vue 3 Error Boundary component using `onErrorCaptured`.
|
|
191
|
+
* Traps unhandled errors from child components, prevents crash propagation,
|
|
192
|
+
* and renders a customizable fallback via scoped slots or props.
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* <!-- App.vue -->
|
|
196
|
+
* <NexusGuard>
|
|
197
|
+
* <template #fallback="{ error, errorId, reset }">
|
|
198
|
+
* <div class="custom-error">
|
|
199
|
+
* <h3>Error: {{ error.message }}</h3>
|
|
200
|
+
* <p>Ref: {{ errorId }}</p>
|
|
201
|
+
* <button @click="reset">Retry</button>
|
|
202
|
+
* </div>
|
|
203
|
+
* </template>
|
|
204
|
+
* <MyWidget />
|
|
205
|
+
* </NexusGuard>
|
|
206
|
+
*/
|
|
207
|
+
declare const NexusGuardVue: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
208
|
+
onError: {
|
|
209
|
+
type: () => (error: Error, info: NexusErrorInfo) => void;
|
|
210
|
+
default: undefined;
|
|
211
|
+
};
|
|
212
|
+
tags: {
|
|
213
|
+
type: () => Record<string, string>;
|
|
214
|
+
default: () => {};
|
|
215
|
+
};
|
|
216
|
+
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
217
|
+
[key: string]: any;
|
|
218
|
+
}> | vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
219
|
+
[key: string]: any;
|
|
220
|
+
}>[] | null, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
221
|
+
onError: {
|
|
222
|
+
type: () => (error: Error, info: NexusErrorInfo) => void;
|
|
223
|
+
default: undefined;
|
|
224
|
+
};
|
|
225
|
+
tags: {
|
|
226
|
+
type: () => Record<string, string>;
|
|
227
|
+
default: () => {};
|
|
228
|
+
};
|
|
229
|
+
}>> & Readonly<{}>, {
|
|
230
|
+
onError: (error: Error, info: NexusErrorInfo) => void;
|
|
231
|
+
tags: Record<string, string>;
|
|
232
|
+
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
233
|
+
|
|
234
|
+
export { NEXUS_KEY, NexusGuardVue, NexusPlugin, type NexusVueContext, type UseFlagVueResult, useFlag, useNexus };
|
package/dist/vue.d.ts
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { InjectionKey, Plugin, Ref } from 'vue';
|
|
3
|
+
import { NexusFlagsClient, NexusFlagsOptions } from '@nexussdk/flags';
|
|
4
|
+
import { NexusTrackerClient, NexusTrackerOptions } from '@nexussdk/tracker';
|
|
5
|
+
import { UserContext, SamplingConfig, TransportPlugin, PerformanceVitalsOptions, SeverityLevel, Breadcrumb, NexusErrorInfo, FlagEvaluationResult } from '@nexussdk/contracts';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @fileoverview Unified Nexus singleton facade wrapping Flags and Tracker clients.
|
|
9
|
+
* @module @nexus/sdk/nexus
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Dev server routing configuration.
|
|
14
|
+
*/
|
|
15
|
+
interface NexusDevServerOptions {
|
|
16
|
+
/** Enable local dev server ingestion mode. Auto-enabled in development if true. */
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
/** Port the dev server is listening on. Defaults to 4567. */
|
|
19
|
+
port?: number;
|
|
20
|
+
/** Host the dev server is bound to. Defaults to 'localhost'. */
|
|
21
|
+
host?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Unified initialization options for the Nexus SDK umbrella.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* Nexus.init({
|
|
28
|
+
* apiKey: 'pk_live_...',
|
|
29
|
+
* user: { id: 'usr_12345', country: 'VN' },
|
|
30
|
+
* environment: 'production',
|
|
31
|
+
* autoCapture: true,
|
|
32
|
+
* devServer: { enabled: process.env.NODE_ENV === 'development' },
|
|
33
|
+
* });
|
|
34
|
+
*/
|
|
35
|
+
interface NexusInitOptions {
|
|
36
|
+
/** Public API key. Resolved from env if omitted. */
|
|
37
|
+
apiKey?: string;
|
|
38
|
+
/** Base URL for all API calls. */
|
|
39
|
+
baseUrl?: string;
|
|
40
|
+
/** Initial user context for flag targeting and error attribution. */
|
|
41
|
+
user?: UserContext;
|
|
42
|
+
/** Target environment for telemetry routing. Defaults to 'production'. */
|
|
43
|
+
environment?: string;
|
|
44
|
+
/** Global tags attached to all telemetry events. */
|
|
45
|
+
tags?: Record<string, string>;
|
|
46
|
+
/** Toggle automated global error capture. Defaults to true. */
|
|
47
|
+
autoCapture?: boolean;
|
|
48
|
+
/** Client-side rate limiting and deduplication sampling options. */
|
|
49
|
+
sampling?: SamplingConfig;
|
|
50
|
+
/** Pluggable transport adapter ('fetch', 'console', 'localStorage', custom fn). */
|
|
51
|
+
transport?: TransportPlugin;
|
|
52
|
+
/** Web Vitals performance observer options, or true for default observation. */
|
|
53
|
+
vitals?: boolean | PerformanceVitalsOptions;
|
|
54
|
+
/** Local dev server auto-routing configuration. */
|
|
55
|
+
devServer?: NexusDevServerOptions;
|
|
56
|
+
/** Additional flags-specific options. */
|
|
57
|
+
flags?: Partial<NexusFlagsOptions>;
|
|
58
|
+
/** Additional tracker-specific options. */
|
|
59
|
+
tracker?: Partial<NexusTrackerOptions>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The Nexus singleton class — the primary unified entry point for the SDK.
|
|
63
|
+
*
|
|
64
|
+
* Provides access to both the feature flags client and the error tracker client.
|
|
65
|
+
* Initialize once, then use throughout your application.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* // Initialize (call once at app startup)
|
|
69
|
+
* Nexus.init({ apiKey: 'pk_live_...' });
|
|
70
|
+
*
|
|
71
|
+
* // Feature flags
|
|
72
|
+
* const showBanner = Nexus.isEnabled('promo_banner_v2', false);
|
|
73
|
+
*
|
|
74
|
+
* // Error tracking
|
|
75
|
+
* Nexus.captureError(new Error('Something went wrong'));
|
|
76
|
+
*
|
|
77
|
+
* // Update user context
|
|
78
|
+
* await Nexus.identify({ id: 'usr_12345', country: 'VN' });
|
|
79
|
+
*/
|
|
80
|
+
declare class Nexus {
|
|
81
|
+
private static instance;
|
|
82
|
+
private static vitalsCleanup;
|
|
83
|
+
/** The underlying feature flags client instance. */
|
|
84
|
+
readonly flags: NexusFlagsClient;
|
|
85
|
+
/** The underlying error tracker client instance. */
|
|
86
|
+
readonly tracker: NexusTrackerClient;
|
|
87
|
+
private constructor();
|
|
88
|
+
/**
|
|
89
|
+
* Initializes the Nexus SDK singleton.
|
|
90
|
+
* Must be called before any other SDK methods.
|
|
91
|
+
* Safe to call multiple times — returns existing instance after first init.
|
|
92
|
+
*
|
|
93
|
+
* @param options - SDK configuration options.
|
|
94
|
+
* @returns The initialized Nexus singleton instance.
|
|
95
|
+
*/
|
|
96
|
+
static init(options?: NexusInitOptions): Nexus;
|
|
97
|
+
/**
|
|
98
|
+
* Returns the current Nexus singleton instance.
|
|
99
|
+
*
|
|
100
|
+
* @returns The active Nexus instance.
|
|
101
|
+
* @throws {Error} If `Nexus.init()` has not been called yet.
|
|
102
|
+
*/
|
|
103
|
+
static getInstance(): Nexus;
|
|
104
|
+
/**
|
|
105
|
+
* Convenience method: Check if a feature flag is enabled.
|
|
106
|
+
*/
|
|
107
|
+
static isEnabled(key: string, defaultValue?: boolean): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Convenience method: Get a flag variant value.
|
|
110
|
+
*/
|
|
111
|
+
static getVariant<T = unknown>(key: string, variantKey: string, defaultValue?: T): T;
|
|
112
|
+
/**
|
|
113
|
+
* Convenience method: Capture an error manually.
|
|
114
|
+
*/
|
|
115
|
+
static captureError(error: unknown, extra?: Record<string, unknown>): void;
|
|
116
|
+
/**
|
|
117
|
+
* Convenience method: Capture an informational or warning message event.
|
|
118
|
+
*/
|
|
119
|
+
static captureMessage(message: string, level?: SeverityLevel, extra?: Record<string, unknown>): void;
|
|
120
|
+
/**
|
|
121
|
+
* Convenience method: Add a breadcrumb manually.
|
|
122
|
+
*/
|
|
123
|
+
static addBreadcrumb(breadcrumb: Breadcrumb): void;
|
|
124
|
+
/**
|
|
125
|
+
* Convenience method: Set extra contextual metadata.
|
|
126
|
+
*/
|
|
127
|
+
static setExtra(key: string, value: unknown): void;
|
|
128
|
+
/**
|
|
129
|
+
* Convenience method: Attach Web Vitals observer to tracker.
|
|
130
|
+
*/
|
|
131
|
+
static attachWebVitals(options?: PerformanceVitalsOptions): () => void;
|
|
132
|
+
/**
|
|
133
|
+
* Convenience method: Update user context for both flags and tracker.
|
|
134
|
+
*/
|
|
135
|
+
static identify(user: UserContext): Promise<void>;
|
|
136
|
+
/**
|
|
137
|
+
* Resets user context to anonymous state (e.g. on logout).
|
|
138
|
+
*/
|
|
139
|
+
static reset(): void;
|
|
140
|
+
/**
|
|
141
|
+
* Gracefully tears down both clients, closing SSE connections and flushing pending events.
|
|
142
|
+
*/
|
|
143
|
+
static destroy(): Promise<void>;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
interface NexusVueContext {
|
|
147
|
+
flags: NexusFlagsClient;
|
|
148
|
+
tracker: NexusTrackerClient;
|
|
149
|
+
nexus: Nexus;
|
|
150
|
+
}
|
|
151
|
+
declare const NEXUS_KEY: InjectionKey<NexusVueContext>;
|
|
152
|
+
/**
|
|
153
|
+
* Vue 3 Plugin for initializing Nexus SDK and setting up global error handling.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* // main.ts
|
|
157
|
+
* import { createApp } from 'vue';
|
|
158
|
+
* import { NexusPlugin } from '@nexussdk/sdk/vue';
|
|
159
|
+
* import App from './App.vue';
|
|
160
|
+
*
|
|
161
|
+
* const app = createApp(App);
|
|
162
|
+
* app.use(NexusPlugin, {
|
|
163
|
+
* apiKey: 'pk_live_...',
|
|
164
|
+
* environment: 'production',
|
|
165
|
+
* });
|
|
166
|
+
* app.mount('#app');
|
|
167
|
+
*/
|
|
168
|
+
declare const NexusPlugin: Plugin;
|
|
169
|
+
/**
|
|
170
|
+
* Returns the Nexus context in a Vue component setup function.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* const { flags, tracker } = useNexus();
|
|
174
|
+
* tracker.captureMessage('Button clicked', 'info');
|
|
175
|
+
*/
|
|
176
|
+
declare function useNexus(): NexusVueContext;
|
|
177
|
+
interface UseFlagVueResult {
|
|
178
|
+
enabled: Ref<boolean>;
|
|
179
|
+
getVariant: <T = unknown>(variantKey: string, defaultValue?: T) => T;
|
|
180
|
+
result: Ref<FlagEvaluationResult | null>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Vue 3 composable for subscribing to real-time feature flag changes.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* const { enabled, getVariant } = useFlag('promo_banner_v2');
|
|
187
|
+
*/
|
|
188
|
+
declare function useFlag(key: string, defaultEnabled?: boolean): UseFlagVueResult;
|
|
189
|
+
/**
|
|
190
|
+
* Vue 3 Error Boundary component using `onErrorCaptured`.
|
|
191
|
+
* Traps unhandled errors from child components, prevents crash propagation,
|
|
192
|
+
* and renders a customizable fallback via scoped slots or props.
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* <!-- App.vue -->
|
|
196
|
+
* <NexusGuard>
|
|
197
|
+
* <template #fallback="{ error, errorId, reset }">
|
|
198
|
+
* <div class="custom-error">
|
|
199
|
+
* <h3>Error: {{ error.message }}</h3>
|
|
200
|
+
* <p>Ref: {{ errorId }}</p>
|
|
201
|
+
* <button @click="reset">Retry</button>
|
|
202
|
+
* </div>
|
|
203
|
+
* </template>
|
|
204
|
+
* <MyWidget />
|
|
205
|
+
* </NexusGuard>
|
|
206
|
+
*/
|
|
207
|
+
declare const NexusGuardVue: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
208
|
+
onError: {
|
|
209
|
+
type: () => (error: Error, info: NexusErrorInfo) => void;
|
|
210
|
+
default: undefined;
|
|
211
|
+
};
|
|
212
|
+
tags: {
|
|
213
|
+
type: () => Record<string, string>;
|
|
214
|
+
default: () => {};
|
|
215
|
+
};
|
|
216
|
+
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
217
|
+
[key: string]: any;
|
|
218
|
+
}> | vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
219
|
+
[key: string]: any;
|
|
220
|
+
}>[] | null, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
221
|
+
onError: {
|
|
222
|
+
type: () => (error: Error, info: NexusErrorInfo) => void;
|
|
223
|
+
default: undefined;
|
|
224
|
+
};
|
|
225
|
+
tags: {
|
|
226
|
+
type: () => Record<string, string>;
|
|
227
|
+
default: () => {};
|
|
228
|
+
};
|
|
229
|
+
}>> & Readonly<{}>, {
|
|
230
|
+
onError: (error: Error, info: NexusErrorInfo) => void;
|
|
231
|
+
tags: Record<string, string>;
|
|
232
|
+
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
233
|
+
|
|
234
|
+
export { NEXUS_KEY, NexusGuardVue, NexusPlugin, type NexusVueContext, type UseFlagVueResult, useFlag, useNexus };
|
package/dist/vue.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {defineComponent,ref,shallowRef,onErrorCaptured,h,inject,onUnmounted}from'vue';import {NexusFlagsClient}from'@nexussdk/flags';import {parseStackTrace,computeFingerprint,NexusTrackerClient,attachWebVitals}from'@nexussdk/tracker';var p=class e{static instance=null;static vitalsCleanup=null;flags;tracker;constructor(t={}){let{apiKey:n,baseUrl:r,user:o,environment:a,tags:s,autoCapture:i,sampling:f,transport:x,vitals:l,devServer:c,flags:g,tracker:C}=t;this.flags=new NexusFlagsClient({apiKey:n,baseUrl:r,user:o,...g});let m=r,I=x;if(c?.enabled){let d=c.port??4567;m=`http://${c.host??"localhost"}:${d}`;}if(this.tracker=new NexusTrackerClient({apiKey:n,baseUrl:m,environment:a,tags:s,autoCapture:i,sampling:f,transport:I,...C}),l){let d=typeof l=="object"?l:{};e.vitalsCleanup=attachWebVitals(this.tracker,d);}}static init(t={}){return e.instance||(e.instance=new e(t)),e.instance}static getInstance(){if(!e.instance)throw new Error('[Nexus SDK] Not initialized. Call Nexus.init({ apiKey: "..." }) first.');return e.instance}static isEnabled(t,n=false){return e.getInstance().flags.isEnabled(t,n)}static getVariant(t,n,r){return e.getInstance().flags.getVariant(t,n,r)}static captureError(t,n){e.getInstance().tracker.captureError(t,n);}static captureMessage(t,n="info",r){e.getInstance().tracker.captureMessage(t,n,r);}static addBreadcrumb(t){e.getInstance().tracker.addBreadcrumb(t);}static setExtra(t,n){e.getInstance().tracker.setExtra(t,n);}static attachWebVitals(t){return attachWebVitals(e.getInstance().tracker,t)}static async identify(t){let n=e.getInstance();n.tracker.setUser(t),await n.flags.identify(t);}static reset(){let t=e.getInstance();t.tracker.setUser(null),t.flags.reset();}static async destroy(){e.vitalsCleanup&&(e.vitalsCleanup(),e.vitalsCleanup=null),e.instance&&(await e.instance.tracker.flush(),e.instance.tracker.destroy(),e.instance.flags.destroy(),e.instance=null);}};var y=Symbol("NexusSDK"),H={install(e,t={}){let n=p.init(t),r={flags:n.flags,tracker:n.tracker,nexus:n};e.provide(y,r);let o=e.config.errorHandler;e.config.errorHandler=(a,s,i)=>{n.tracker.captureError(a,{componentStack:i,tags:{framework:"vue3",component:s?.$options?.name||"AnonymousComponent"}}),o&&o(a,s,i);},e.component("NexusGuard",R);}};function N(){let e=inject(y);if(e)return e;let t=p.getInstance();return {flags:t.flags,tracker:t.tracker,nexus:t}}function A(e,t=false){let{flags:n}=N(),r=ref(n.isEnabled(e,t)),o=shallowRef(null),a=n.onFlagChange(e,s=>{r.value=s.enabled,o.value=s;});return onUnmounted(()=>{a();}),{enabled:r,getVariant:(s,i)=>n.getVariant(e,s,i),result:o}}var R=defineComponent({name:"NexusGuard",props:{onError:{type:Function,default:void 0},tags:{type:Object,default:()=>({})}},setup(e,{slots:t}){let n=ref(false),r=shallowRef(null),o=()=>{n.value=false,r.value=null;};return onErrorCaptured((a,s,i)=>{let f=parseStackTrace(a.stack),l=`NX-${computeFingerprint(a.name,a.message,f[0]).replace(/^fp_/,"").slice(0,8).toUpperCase()}`,c={error:a,errorId:l,componentStack:i,reset:o};n.value=true,r.value=c;try{let{tracker:g}=N();g.captureError(a,{componentStack:i,tags:{...e.tags,guardErrorId:l,framework:"vue3",component:s?.$options?.name||"AnonymousComponent"}});}catch{}if(e.onError)try{e.onError(a,c);}catch{}return false}),()=>n.value&&r.value?t.fallback?t.fallback(r.value):h("div",{role:"alert",style:{padding:"16px 20px",margin:"12px 0",borderRadius:"8px",backgroundColor:"#1f1315",border:"1px solid #7f1d1d",color:"#fca5a5",fontFamily:"-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, sans-serif",fontSize:"14px"}},[h("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"8px"}},[h("strong",{style:{color:"#ef4444"}},"Vue Component Crash Protected"),h("span",{style:{fontFamily:"monospace",fontSize:"12px",background:"#450a0a",padding:"2px 8px",borderRadius:"4px"}},r.value.errorId)]),h("p",{style:{margin:"0 0 12px 0",color:"#fecaca"}},r.value.error.message),h("button",{type:"button",onClick:o,style:{background:"#b91c1c",border:"none",color:"#fff",padding:"6px 14px",borderRadius:"6px",fontSize:"13px",cursor:"pointer",fontWeight:"500"}},"Retry Component")]):t.default?t.default():null}});
|
|
2
|
+
export{y as NEXUS_KEY,R as NexusGuardVue,H as NexusPlugin,A as useFlag,N as useNexus};
|
package/package.json
CHANGED
|
@@ -1,11 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexussdk/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"description": "Unified umbrella SDK for Nexus Platform — feature flags + error tracking + React hooks",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": "Nexus",
|
|
11
|
+
"contributors": [
|
|
12
|
+
{
|
|
13
|
+
"name": "Hồ Huỳnh Dũng",
|
|
14
|
+
"email": "hohuynhdung@gmail.com",
|
|
15
|
+
"url": "https://github.com/Huynhdung295"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/Huynhdung295/NexusSDK.git",
|
|
21
|
+
"directory": "packages/sdk"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/Huynhdung295/NexusSDK#readme",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/Huynhdung295/NexusSDK/issues"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"nexus",
|
|
29
|
+
"nexussdk",
|
|
30
|
+
"feature-flags",
|
|
31
|
+
"feature-management",
|
|
32
|
+
"remote-config",
|
|
33
|
+
"telemetry",
|
|
34
|
+
"error-tracking",
|
|
35
|
+
"error-monitoring",
|
|
36
|
+
"error-boundary",
|
|
37
|
+
"web-vitals",
|
|
38
|
+
"pii-sanitizer",
|
|
39
|
+
"react",
|
|
40
|
+
"vue",
|
|
41
|
+
"nextjs",
|
|
42
|
+
"nuxt",
|
|
43
|
+
"sdk",
|
|
44
|
+
"zero-dependencies"
|
|
45
|
+
],
|
|
46
|
+
"files": [
|
|
47
|
+
"dist",
|
|
48
|
+
"README.md"
|
|
49
|
+
],
|
|
9
50
|
"main": "./dist/index.cjs",
|
|
10
51
|
"module": "./dist/index.mjs",
|
|
11
52
|
"types": "./dist/index.d.ts",
|
|
@@ -19,28 +60,40 @@
|
|
|
19
60
|
"types": "./dist/react.d.ts",
|
|
20
61
|
"import": "./dist/react.mjs",
|
|
21
62
|
"require": "./dist/react.cjs"
|
|
63
|
+
},
|
|
64
|
+
"./vue": {
|
|
65
|
+
"types": "./dist/vue.d.ts",
|
|
66
|
+
"import": "./dist/vue.mjs",
|
|
67
|
+
"require": "./dist/vue.cjs"
|
|
22
68
|
}
|
|
23
69
|
},
|
|
24
70
|
"dependencies": {
|
|
25
|
-
"@nexussdk/
|
|
26
|
-
"@nexussdk/
|
|
27
|
-
"@nexussdk/
|
|
28
|
-
"@nexussdk/
|
|
71
|
+
"@nexussdk/contracts": "0.0.4",
|
|
72
|
+
"@nexussdk/core": "0.0.4",
|
|
73
|
+
"@nexussdk/flags": "0.0.4",
|
|
74
|
+
"@nexussdk/tracker": "0.0.4"
|
|
29
75
|
},
|
|
30
76
|
"peerDependencies": {
|
|
31
|
-
"react": ">=18.0.0"
|
|
77
|
+
"react": ">=18.0.0",
|
|
78
|
+
"vue": ">=3.0.0"
|
|
32
79
|
},
|
|
33
80
|
"peerDependenciesMeta": {
|
|
34
81
|
"react": {
|
|
35
82
|
"optional": true
|
|
83
|
+
},
|
|
84
|
+
"vue": {
|
|
85
|
+
"optional": true
|
|
36
86
|
}
|
|
37
87
|
},
|
|
38
88
|
"devDependencies": {
|
|
39
|
-
"@types/react": "^
|
|
40
|
-
"react": "^
|
|
89
|
+
"@types/react": "^19.0.0",
|
|
90
|
+
"@types/react-dom": "^19.0.0",
|
|
91
|
+
"react": "^19.0.0",
|
|
92
|
+
"react-dom": "^19.0.0",
|
|
93
|
+
"rimraf": "^5.0.5",
|
|
41
94
|
"tsup": "^8.0.2",
|
|
42
95
|
"typescript": "^5.4.5",
|
|
43
|
-
"
|
|
96
|
+
"vue": "^3.5.42"
|
|
44
97
|
},
|
|
45
98
|
"scripts": {
|
|
46
99
|
"build": "tsup",
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @nexussdk/sdk@0.0.1 build /home/runner/work/NexusSDK/NexusSDK/packages/sdk
|
|
3
|
-
> tsup
|
|
4
|
-
|
|
5
|
-
[34mCLI[39m Building entry: {"react":"src/react.tsx"}
|
|
6
|
-
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
-
[34mCLI[39m tsup v8.5.1
|
|
8
|
-
[34mCLI[39m Using tsup config: /home/runner/work/NexusSDK/NexusSDK/packages/sdk/tsup.config.ts
|
|
9
|
-
[34mCLI[39m Building entry: src/index.ts
|
|
10
|
-
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
11
|
-
[34mCLI[39m tsup v8.5.1
|
|
12
|
-
[34mCLI[39m Using tsup config: /home/runner/work/NexusSDK/NexusSDK/packages/sdk/tsup.config.ts
|
|
13
|
-
[34mCLI[39m Target: es2022
|
|
14
|
-
[34mESM[39m Build start
|
|
15
|
-
[34mCJS[39m Build start
|
|
16
|
-
[34mCLI[39m Target: es2022
|
|
17
|
-
[34mCLI[39m Cleaning output folder
|
|
18
|
-
[34mESM[39m Build start
|
|
19
|
-
[34mCJS[39m Build start
|
|
20
|
-
[34mIIFE[39m Build start
|
|
21
|
-
dist/react.cjs (1:0): Module level directives cause errors when bundled, "use client" in "dist/react.cjs" was ignored.
|
|
22
|
-
dist/react.mjs (1:0): Module level directives cause errors when bundled, "use client" in "dist/react.mjs" was ignored.
|
|
23
|
-
[32mCJS[39m [1mdist/index.cjs [22m[32m1.45 KB[39m
|
|
24
|
-
[32mCJS[39m [1mdist/index.cjs.map [22m[32m8.39 KB[39m
|
|
25
|
-
[32mCJS[39m ⚡️ Build success in 473ms
|
|
26
|
-
[32mCJS[39m [1mdist/react.cjs [22m[32m2.26 KB[39m
|
|
27
|
-
[32mCJS[39m [1mdist/react.cjs.map [22m[32m16.56 KB[39m
|
|
28
|
-
[32mCJS[39m ⚡️ Build success in 483ms
|
|
29
|
-
[32mESM[39m [1mdist/react.mjs [22m[32m2.17 KB[39m
|
|
30
|
-
[32mESM[39m [1mdist/react.mjs.map [22m[32m16.56 KB[39m
|
|
31
|
-
[32mESM[39m ⚡️ Build success in 484ms
|
|
32
|
-
[32mIIFE[39m [1mdist/index.global.js [22m[32m19.65 KB[39m
|
|
33
|
-
[32mIIFE[39m [1mdist/index.global.js.map [22m[32m116.63 KB[39m
|
|
34
|
-
[32mIIFE[39m ⚡️ Build success in 475ms
|
|
35
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m1.31 KB[39m
|
|
36
|
-
[32mESM[39m [1mdist/index.mjs.map [22m[32m8.39 KB[39m
|
|
37
|
-
[32mESM[39m ⚡️ Build success in 475ms
|
|
38
|
-
[34mDTS[39m Build start
|
|
39
|
-
[34mDTS[39m Build start
|
|
40
|
-
[32mDTS[39m ⚡️ Build success in 1445ms
|
|
41
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[32m5.12 KB[39m
|
|
42
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m5.12 KB[39m
|
|
43
|
-
[32mDTS[39m ⚡️ Build success in 1567ms
|
|
44
|
-
[32mDTS[39m [1mdist/react.d.mts [22m[32m8.12 KB[39m
|
|
45
|
-
[32mDTS[39m [1mdist/react.d.ts [22m[32m8.12 KB[39m
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/nexus.ts"],"names":["Nexus","_Nexus","options","apiKey","baseUrl","user","environment","tags","autoCapture","flagsOpts","trackerOpts","NexusFlagsClient","NexusTrackerClient","key","defaultValue","variantKey","error","extra","instance"],"mappings":"uFA6DO,IAAMA,CAAAA,CAAN,MAAMC,CAAM,CACjB,OAAe,QAAA,CAAyB,IAAA,CAGxB,KAAA,CAEA,OAAA,CAER,WAAA,CAAYC,CAAAA,CAA4B,EAAC,CAAG,CAClD,GAAM,CAAE,MAAA,CAAAC,CAAAA,CAAQ,OAAA,CAAAC,EAAS,IAAA,CAAAC,CAAAA,CAAM,WAAA,CAAAC,CAAAA,CAAa,IAAA,CAAAC,CAAAA,CAAM,YAAAC,CAAAA,CAAa,KAAA,CAAOC,CAAAA,CAAW,OAAA,CAASC,CAAY,CAAA,CAAIR,EAE1G,IAAA,CAAK,KAAA,CAAQ,IAAIS,sBAAAA,CAAiB,CAChC,MAAA,CAAAR,CAAAA,CACA,OAAA,CAAAC,CAAAA,CACA,IAAA,CAAAC,CAAAA,CACA,GAAGI,CACL,CAAC,EAED,IAAA,CAAK,OAAA,CAAU,IAAIG,0BAAAA,CAAmB,CACpC,MAAA,CAAAT,EACA,OAAA,CAAAC,CAAAA,CACA,WAAA,CAAAE,CAAAA,CACA,IAAA,CAAAC,CAAAA,CACA,YAAAC,CAAAA,CACA,GAAGE,CACL,CAAC,EACH,CAaA,OAAc,IAAA,CAAKR,CAAAA,CAA4B,EAAC,CAAU,CACxD,OAAKD,CAAAA,CAAM,WACTA,CAAAA,CAAM,QAAA,CAAW,IAAIA,CAAAA,CAAMC,CAAO,CAAA,CAAA,CAE7BD,EAAM,QACf,CAYA,OAAc,WAAA,EAAqB,CACjC,GAAI,CAACA,CAAAA,CAAM,QAAA,CACT,MAAM,IAAI,KAAA,CAAM,wEAAwE,CAAA,CAE1F,OAAOA,CAAAA,CAAM,QACf,CAYA,OAAc,SAAA,CAAUY,CAAAA,CAAaC,EAAe,KAAA,CAAgB,CAClE,OAAOb,CAAAA,CAAM,WAAA,EAAY,CAAE,MAAM,SAAA,CAAUY,CAAAA,CAAKC,CAAY,CAC9D,CAaA,OAAc,WAAwBD,CAAAA,CAAaE,CAAAA,CAAoBD,CAAAA,CAAqB,CAC1F,OAAOb,CAAAA,CAAM,WAAA,EAAY,CAAE,KAAA,CAAM,UAAA,CAAcY,CAAAA,CAAKE,CAAAA,CAAYD,CAAY,CAC9E,CAWA,OAAc,YAAA,CAAaE,CAAAA,CAAgBC,CAAAA,CAAuC,CAChFhB,CAAAA,CAAM,aAAY,CAAE,OAAA,CAAQ,YAAA,CAAae,CAAAA,CAAOC,CAAK,EACvD,CAWA,aAAoB,QAAA,CAASZ,CAAAA,CAAkC,CAC7D,IAAMa,CAAAA,CAAWjB,CAAAA,CAAM,WAAA,EAAY,CACnCiB,CAAAA,CAAS,OAAA,CAAQ,OAAA,CAAQb,CAAI,CAAA,CAC7B,MAAMa,CAAAA,CAAS,KAAA,CAAM,QAAA,CAASb,CAAI,EACpC,CAQA,OAAc,KAAA,EAAc,CAC1B,IAAMa,CAAAA,CAAWjB,CAAAA,CAAM,WAAA,GACvBiB,CAAAA,CAAS,OAAA,CAAQ,OAAA,CAAQ,IAAI,CAAA,CAC7BA,CAAAA,CAAS,KAAA,CAAM,KAAA,GACjB,CAQA,aAAoB,OAAA,EAAyB,CACvCjB,CAAAA,CAAM,WACR,MAAMA,CAAAA,CAAM,QAAA,CAAS,OAAA,CAAQ,KAAA,EAAM,CACnCA,CAAAA,CAAM,QAAA,CAAS,OAAA,CAAQ,OAAA,EAAQ,CAC/BA,CAAAA,CAAM,QAAA,CAAS,KAAA,CAAM,SAAQ,CAC7BA,CAAAA,CAAM,QAAA,CAAW,IAAA,EAErB,CACF","file":"index.cjs","sourcesContent":["/**\n * @fileoverview Unified Nexus singleton facade wrapping Flags and Tracker clients.\n * @module @nexus/sdk/nexus\n */\n\nimport { NexusFlagsClient } from '@nexussdk/flags';\nimport type { NexusFlagsOptions } from '@nexussdk/flags';\nimport { NexusTrackerClient } from '@nexussdk/tracker';\nimport type { NexusTrackerOptions } from '@nexussdk/tracker';\nimport type { UserContext } from '@nexussdk/contracts';\n\n/**\n * Unified initialization options for the Nexus SDK umbrella.\n *\n * @example\n * Nexus.init({\n * apiKey: 'pk_live_...',\n * baseUrl: 'http://localhost:8080',\n * user: { id: 'usr_12345', country: 'VN' },\n * environment: 'production',\n * autoCapture: true,\n * });\n */\nexport interface NexusInitOptions {\n /** Public API key. Resolved from env if omitted. */\n apiKey?: string;\n /** Base URL for all API calls. */\n baseUrl?: string;\n /** Initial user context for flag targeting and error attribution. */\n user?: UserContext;\n /** Target environment for telemetry routing. Defaults to 'production'. */\n environment?: string;\n /** Global tags attached to all telemetry events. */\n tags?: Record<string, string>;\n /** Toggle automated global error capture. Defaults to true. */\n autoCapture?: boolean;\n /** Additional flags-specific options. */\n flags?: Partial<NexusFlagsOptions>;\n /** Additional tracker-specific options. */\n tracker?: Partial<NexusTrackerOptions>;\n}\n\n/**\n * The Nexus singleton class — the primary unified entry point for the SDK.\n *\n * Provides access to both the feature flags client and the error tracker client.\n * Initialize once, then use throughout your application.\n *\n * @example\n * // Initialize (call once at app startup)\n * Nexus.init({ apiKey: 'pk_live_...' });\n *\n * // Feature flags\n * const showBanner = Nexus.isEnabled('promo_banner_v2', false);\n *\n * // Error tracking\n * Nexus.captureError(new Error('Something went wrong'));\n *\n * // Update user context\n * await Nexus.identify({ id: 'usr_12345', country: 'VN' });\n */\nexport class Nexus {\n private static instance: Nexus | null = null;\n\n /** The underlying feature flags client instance. */\n public readonly flags: NexusFlagsClient;\n /** The underlying error tracker client instance. */\n public readonly tracker: NexusTrackerClient;\n\n private constructor(options: NexusInitOptions = {}) {\n const { apiKey, baseUrl, user, environment, tags, autoCapture, flags: flagsOpts, tracker: trackerOpts } = options;\n\n this.flags = new NexusFlagsClient({\n apiKey,\n baseUrl,\n user,\n ...flagsOpts,\n });\n\n this.tracker = new NexusTrackerClient({\n apiKey,\n baseUrl,\n environment,\n tags,\n autoCapture,\n ...trackerOpts,\n });\n }\n\n /**\n * Initializes the Nexus SDK singleton.\n * Must be called before any other SDK methods.\n * Safe to call multiple times — returns existing instance after first init.\n *\n * @param options - SDK configuration options.\n * @returns The initialized Nexus singleton instance.\n *\n * @example\n * const nexus = Nexus.init({ apiKey: 'pk_live_...' });\n */\n public static init(options: NexusInitOptions = {}): Nexus {\n if (!Nexus.instance) {\n Nexus.instance = new Nexus(options);\n }\n return Nexus.instance;\n }\n\n /**\n * Returns the current Nexus singleton instance.\n *\n * @returns The active Nexus instance.\n * @throws {Error} If `Nexus.init()` has not been called yet.\n *\n * @example\n * const nexus = Nexus.getInstance();\n * nexus.flags.isEnabled('checkout_v2');\n */\n public static getInstance(): Nexus {\n if (!Nexus.instance) {\n throw new Error('[Nexus SDK] Not initialized. Call Nexus.init({ apiKey: \"...\" }) first.');\n }\n return Nexus.instance;\n }\n\n /**\n * Convenience method: Check if a feature flag is enabled.\n *\n * @param key - Flag identifier.\n * @param defaultValue - Fallback if flag is missing.\n * @returns Boolean enabled state.\n *\n * @example\n * if (Nexus.isEnabled('checkout_redesign')) { ... }\n */\n public static isEnabled(key: string, defaultValue = false): boolean {\n return Nexus.getInstance().flags.isEnabled(key, defaultValue);\n }\n\n /**\n * Convenience method: Get a flag variant value.\n *\n * @param key - Flag identifier.\n * @param variantKey - Variant property name.\n * @param defaultValue - Fallback value.\n * @returns Variant value cast to type T.\n *\n * @example\n * const rate = Nexus.getVariant<number>('promo_banner_v2', 'discount_rate', 10);\n */\n public static getVariant<T = unknown>(key: string, variantKey: string, defaultValue?: T): T {\n return Nexus.getInstance().flags.getVariant<T>(key, variantKey, defaultValue);\n }\n\n /**\n * Convenience method: Capture an error manually.\n *\n * @param error - Error instance, string, or unknown value.\n * @param extra - Optional metadata tags.\n *\n * @example\n * Nexus.captureError(new TypeError('Cannot read properties of null'));\n */\n public static captureError(error: unknown, extra?: Record<string, unknown>): void {\n Nexus.getInstance().tracker.captureError(error, extra);\n }\n\n /**\n * Convenience method: Update user context for both flags and tracker.\n *\n * @param user - New user context (merged with existing).\n * @returns Promise resolving after flags refresh.\n *\n * @example\n * await Nexus.identify({ id: 'usr_12345', country: 'VN' });\n */\n public static async identify(user: UserContext): Promise<void> {\n const instance = Nexus.getInstance();\n instance.tracker.setUser(user);\n await instance.flags.identify(user);\n }\n\n /**\n * Resets user context to anonymous state (e.g. on logout).\n *\n * @example\n * Nexus.reset(); // called on user logout\n */\n public static reset(): void {\n const instance = Nexus.getInstance();\n instance.tracker.setUser(null);\n instance.flags.reset();\n }\n\n /**\n * Gracefully tears down both clients, closing SSE connections and flushing pending events.\n *\n * @example\n * await Nexus.destroy();\n */\n public static async destroy(): Promise<void> {\n if (Nexus.instance) {\n await Nexus.instance.tracker.flush();\n Nexus.instance.tracker.destroy();\n Nexus.instance.flags.destroy();\n Nexus.instance = null;\n }\n }\n}\n"]}
|