@flagdeck/angular 0.0.0-stage → 1.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/README.md CHANGED
@@ -1,3 +1,53 @@
1
- # Temporary Holding Version
1
+ # @flagdeck/angular
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Angular integration for [Flagdeck](https://flagdeck.com) feature flags. Flags are
4
+ exposed as Angular **signals**, kept live by the realtime (SSE) connection, with
5
+ the same key-only re-evaluate contract as `@flagdeck/react` and `@flagdeck/vue`.
6
+
7
+ Requires Angular 17+ (standalone + signals).
8
+
9
+ ## Setup
10
+
11
+ ```ts
12
+ // app.config.ts
13
+ import { provideFlagdeck } from '@flagdeck/angular';
14
+
15
+ export const appConfig: ApplicationConfig = {
16
+ providers: [
17
+ provideFlagdeck({
18
+ clientOptions: { apiKey: 'YOUR_SDK_KEY', realTimeUpdates: true },
19
+ context: { userId: 'user-1', attributes: { plan: 'free' } },
20
+ }),
21
+ ],
22
+ };
23
+ ```
24
+
25
+ ## Use
26
+
27
+ ```ts
28
+ import { Component, inject } from '@angular/core';
29
+ import { FlagdeckService, FdFlagDirective } from '@flagdeck/angular';
30
+
31
+ @Component({
32
+ standalone: true,
33
+ imports: [FdFlagDirective],
34
+ template: `
35
+ <p>New checkout: {{ newCheckout() ? 'on' : 'off' }}</p>
36
+ <div *fdFlag="'banner'; else off">banner on</div>
37
+ <ng-template #off>banner off</ng-template>
38
+ `,
39
+ })
40
+ export class DemoComponent {
41
+ private fd = inject(FlagdeckService);
42
+ // Call flag()/flagValue() in a field initializer (an injection context).
43
+ newCheckout = this.fd.flag('new-checkout', false);
44
+ copy = this.fd.flagValue<string>('headline', 'Welcome');
45
+ }
46
+ ```
47
+
48
+ `flag()` and `flagValue()` return signals that re-evaluate when the context
49
+ changes (`fd.setContext(...)`) and when the flag changes in the dashboard. For a
50
+ one-off evaluation with an explicit context (e.g. a targeting tester), use
51
+ `fd.evaluate(key, context)`, which returns the full result (value, source, reason).
52
+
53
+ The public API only ever gains fields; it never renames or removes them.
@@ -0,0 +1,198 @@
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, inject, signal, DestroyRef, effect, Injectable, makeEnvironmentProviders, TemplateRef, ViewContainerRef, Input, Directive } from '@angular/core';
3
+ import { Flagdeck } from '@flagdeck/js';
4
+
5
+ /** DI token holding the provider options; read by FlagdeckService. */
6
+ const FLAGDECK_OPTIONS = new InjectionToken('FLAGDECK_OPTIONS');
7
+
8
+ /**
9
+ * The Flagdeck client as an Angular service, exposing flags as signals.
10
+ *
11
+ * Realtime is a key-only signal: a `change:<key>` from the server tells the
12
+ * service to re-evaluate that flag for the current context, and the returned
13
+ * signal updates — never trusting a value off the wire (rollout/targeting
14
+ * resolve server-side). The same model as the react hooks and vue composables.
15
+ */
16
+ class FlagdeckService {
17
+ /** The underlying browser client, for advanced use. */
18
+ client;
19
+ _context;
20
+ /** The current evaluation context as a signal. */
21
+ context;
22
+ constructor() {
23
+ const options = inject(FLAGDECK_OPTIONS);
24
+ this.client = new Flagdeck(options.clientOptions);
25
+ this._context = signal(options.context ?? {});
26
+ this.context = this._context.asReadonly();
27
+ }
28
+ /** Replace the evaluation context; every flag signal re-evaluates. */
29
+ setContext(context) {
30
+ this._context.set(context);
31
+ }
32
+ /** Whether the realtime (SSE) connection is currently open. */
33
+ isRealTime() {
34
+ return this.client.areRealTimeUpdatesEnabled?.() ?? false;
35
+ }
36
+ /**
37
+ * One-off evaluation for an explicit context (used by targeting UIs). Does not
38
+ * create a subscription; returns the full result (value, source, reason).
39
+ */
40
+ evaluate(flagKey, context) {
41
+ return this.client.evaluateFlag(flagKey, context ?? this._context());
42
+ }
43
+ /** A boolean flag as a live signal. Call in an injection context. */
44
+ flag(flagKey, defaultValue = false) {
45
+ return this.toSignal(flagKey, defaultValue, (r) => Boolean(r.value));
46
+ }
47
+ /** A typed flag value as a live signal, with a code fallback. Call in an injection context. */
48
+ flagValue(flagKey, defaultValue) {
49
+ return this.toSignal(flagKey, defaultValue, (r) => r.value ?? defaultValue);
50
+ }
51
+ // A signal that evaluates `flagKey` for the current context and keeps itself
52
+ // fresh: re-evaluating when the context changes and when a realtime
53
+ // change:<key> arrives. Must be called in an injection context (a component
54
+ // field/constructor) so the subscription and effect are torn down with it.
55
+ toSignal(flagKey, defaultValue, pick) {
56
+ const destroyRef = inject(DestroyRef);
57
+ const out = signal(defaultValue);
58
+ const tick = signal(0);
59
+ const bump = () => tick.update((n) => n + 1);
60
+ this.client.onFlagChange(flagKey, bump);
61
+ destroyRef.onDestroy(() => this.client.off(`change:${flagKey}`, bump));
62
+ effect((onCleanup) => {
63
+ const ctx = this._context(); // track context changes
64
+ tick(); // track realtime changes
65
+ let cancelled = false;
66
+ void this.client
67
+ .evaluateFlag(flagKey, ctx)
68
+ .then((r) => {
69
+ if (!cancelled)
70
+ out.set(pick(r));
71
+ })
72
+ .catch(() => {
73
+ if (!cancelled)
74
+ out.set(defaultValue);
75
+ });
76
+ onCleanup(() => {
77
+ cancelled = true;
78
+ });
79
+ });
80
+ return out.asReadonly();
81
+ }
82
+ ngOnDestroy() {
83
+ this.client.destroy?.();
84
+ }
85
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: FlagdeckService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
86
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: FlagdeckService });
87
+ }
88
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: FlagdeckService, decorators: [{
89
+ type: Injectable
90
+ }], ctorParameters: () => [] });
91
+
92
+ /**
93
+ * Register Flagdeck for a standalone Angular app. Add to `app.config.ts`:
94
+ *
95
+ * providers: [provideFlagdeck({ clientOptions: { apiKey, realTimeUpdates: true } })]
96
+ *
97
+ * Creates a single shared client for the app and tears it down on destroy.
98
+ */
99
+ function provideFlagdeck(options) {
100
+ return makeEnvironmentProviders([
101
+ { provide: FLAGDECK_OPTIONS, useValue: options },
102
+ FlagdeckService,
103
+ ]);
104
+ }
105
+
106
+ /**
107
+ * Structural directive: render content when a flag is on, with an optional
108
+ * `;else` template. Re-renders live on context and realtime changes.
109
+ *
110
+ * <div *fdFlag="'new-ui'; else legacy">new</div>
111
+ * <ng-template #legacy>old</ng-template>
112
+ */
113
+ class FdFlagDirective {
114
+ tpl = inject((TemplateRef));
115
+ vcr = inject(ViewContainerRef);
116
+ fd = inject(FlagdeckService);
117
+ destroyRef = inject(DestroyRef);
118
+ key = signal('');
119
+ tick = signal(0);
120
+ on = signal(false);
121
+ elseTpl = null;
122
+ subscribedKey = null;
123
+ bump = () => this.tick.update((n) => n + 1);
124
+ set fdFlag(key) {
125
+ this.key.set(key);
126
+ }
127
+ set fdFlagElse(tpl) {
128
+ this.elseTpl = tpl;
129
+ this.render();
130
+ }
131
+ constructor() {
132
+ effect((onCleanup) => {
133
+ const key = this.key();
134
+ const ctx = this.fd.context();
135
+ this.tick(); // track realtime bumps
136
+ if (this.subscribedKey !== key) {
137
+ if (this.subscribedKey) {
138
+ this.fd.client.off(`change:${this.subscribedKey}`, this.bump);
139
+ }
140
+ if (key)
141
+ this.fd.client.onFlagChange(key, this.bump);
142
+ this.subscribedKey = key;
143
+ }
144
+ if (!key)
145
+ return;
146
+ let cancelled = false;
147
+ void this.fd.client
148
+ .evaluateFlag(key, ctx)
149
+ .then((r) => {
150
+ if (cancelled)
151
+ return;
152
+ this.on.set(Boolean(r.value));
153
+ this.render();
154
+ })
155
+ .catch(() => {
156
+ if (cancelled)
157
+ return;
158
+ this.on.set(false);
159
+ this.render();
160
+ });
161
+ onCleanup(() => {
162
+ cancelled = true;
163
+ });
164
+ });
165
+ this.destroyRef.onDestroy(() => {
166
+ if (this.subscribedKey) {
167
+ this.fd.client.off(`change:${this.subscribedKey}`, this.bump);
168
+ }
169
+ });
170
+ }
171
+ render() {
172
+ this.vcr.clear();
173
+ if (this.on()) {
174
+ this.vcr.createEmbeddedView(this.tpl);
175
+ }
176
+ else if (this.elseTpl) {
177
+ this.vcr.createEmbeddedView(this.elseTpl);
178
+ }
179
+ }
180
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: FdFlagDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
181
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.25", type: FdFlagDirective, isStandalone: true, selector: "[fdFlag]", inputs: { fdFlag: "fdFlag", fdFlagElse: "fdFlagElse" }, ngImport: i0 });
182
+ }
183
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: FdFlagDirective, decorators: [{
184
+ type: Directive,
185
+ args: [{ selector: '[fdFlag]', standalone: true }]
186
+ }], ctorParameters: () => [], propDecorators: { fdFlag: [{
187
+ type: Input,
188
+ args: [{ required: true }]
189
+ }], fdFlagElse: [{
190
+ type: Input
191
+ }] } });
192
+
193
+ /**
194
+ * Generated bundle index. Do not edit.
195
+ */
196
+
197
+ export { FLAGDECK_OPTIONS, FdFlagDirective, FlagdeckService, provideFlagdeck };
198
+ //# sourceMappingURL=flagdeck-angular.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flagdeck-angular.mjs","sources":["../../src/lib/tokens.ts","../../src/lib/flagdeck.service.ts","../../src/lib/provide-flagdeck.ts","../../src/lib/fd-flag.directive.ts","../../src/flagdeck-angular.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\nimport type { FlagdeckProviderOptions } from './types';\n\n/** DI token holding the provider options; read by FlagdeckService. */\nexport const FLAGDECK_OPTIONS = new InjectionToken<FlagdeckProviderOptions>(\n 'FLAGDECK_OPTIONS',\n);\n","import {\n DestroyRef,\n Injectable,\n OnDestroy,\n Signal,\n effect,\n inject,\n signal,\n} from '@angular/core';\nimport {\n Flagdeck,\n type EvaluationContext,\n type EvaluationResult,\n type FlagdeckClient,\n} from '@flagdeck/js';\nimport { FLAGDECK_OPTIONS } from './tokens';\n\n/**\n * The Flagdeck client as an Angular service, exposing flags as signals.\n *\n * Realtime is a key-only signal: a `change:<key>` from the server tells the\n * service to re-evaluate that flag for the current context, and the returned\n * signal updates — never trusting a value off the wire (rollout/targeting\n * resolve server-side). The same model as the react hooks and vue composables.\n */\n@Injectable()\nexport class FlagdeckService implements OnDestroy {\n /** The underlying browser client, for advanced use. */\n readonly client: FlagdeckClient;\n\n private readonly _context;\n /** The current evaluation context as a signal. */\n readonly context: Signal<Partial<EvaluationContext>>;\n\n constructor() {\n const options = inject(FLAGDECK_OPTIONS);\n this.client = new Flagdeck(\n options.clientOptions,\n ) as unknown as FlagdeckClient;\n this._context = signal<Partial<EvaluationContext>>(options.context ?? {});\n this.context = this._context.asReadonly();\n }\n\n /** Replace the evaluation context; every flag signal re-evaluates. */\n setContext(context: Partial<EvaluationContext>): void {\n this._context.set(context);\n }\n\n /** Whether the realtime (SSE) connection is currently open. */\n isRealTime(): boolean {\n return this.client.areRealTimeUpdatesEnabled?.() ?? false;\n }\n\n /**\n * One-off evaluation for an explicit context (used by targeting UIs). Does not\n * create a subscription; returns the full result (value, source, reason).\n */\n evaluate(\n flagKey: string,\n context?: Partial<EvaluationContext>,\n ): Promise<EvaluationResult> {\n return this.client.evaluateFlag(flagKey, context ?? this._context());\n }\n\n /** A boolean flag as a live signal. Call in an injection context. */\n flag(flagKey: string, defaultValue = false): Signal<boolean> {\n return this.toSignal(flagKey, defaultValue, (r) => Boolean(r.value));\n }\n\n /** A typed flag value as a live signal, with a code fallback. Call in an injection context. */\n flagValue<T>(flagKey: string, defaultValue: T): Signal<T> {\n return this.toSignal<T>(\n flagKey,\n defaultValue,\n (r) => (r.value as T) ?? defaultValue,\n );\n }\n\n // A signal that evaluates `flagKey` for the current context and keeps itself\n // fresh: re-evaluating when the context changes and when a realtime\n // change:<key> arrives. Must be called in an injection context (a component\n // field/constructor) so the subscription and effect are torn down with it.\n private toSignal<T>(\n flagKey: string,\n defaultValue: T,\n pick: (r: EvaluationResult) => T,\n ): Signal<T> {\n const destroyRef = inject(DestroyRef);\n const out = signal<T>(defaultValue);\n const tick = signal(0);\n const bump = (): void => tick.update((n) => n + 1);\n\n this.client.onFlagChange(flagKey, bump);\n destroyRef.onDestroy(() => this.client.off(`change:${flagKey}`, bump));\n\n effect((onCleanup) => {\n const ctx = this._context(); // track context changes\n tick(); // track realtime changes\n let cancelled = false;\n void this.client\n .evaluateFlag(flagKey, ctx)\n .then((r) => {\n if (!cancelled) out.set(pick(r));\n })\n .catch(() => {\n if (!cancelled) out.set(defaultValue);\n });\n onCleanup(() => {\n cancelled = true;\n });\n });\n\n return out.asReadonly();\n }\n\n ngOnDestroy(): void {\n this.client.destroy?.();\n }\n}\n","import {\n EnvironmentProviders,\n makeEnvironmentProviders,\n} from '@angular/core';\nimport { FlagdeckService } from './flagdeck.service';\nimport { FLAGDECK_OPTIONS } from './tokens';\nimport type { FlagdeckProviderOptions } from './types';\n\nexport { FLAGDECK_OPTIONS };\n\n/**\n * Register Flagdeck for a standalone Angular app. Add to `app.config.ts`:\n *\n * providers: [provideFlagdeck({ clientOptions: { apiKey, realTimeUpdates: true } })]\n *\n * Creates a single shared client for the app and tears it down on destroy.\n */\nexport function provideFlagdeck(\n options: FlagdeckProviderOptions,\n): EnvironmentProviders {\n return makeEnvironmentProviders([\n { provide: FLAGDECK_OPTIONS, useValue: options },\n FlagdeckService,\n ]);\n}\n","import {\n DestroyRef,\n Directive,\n Input,\n TemplateRef,\n ViewContainerRef,\n effect,\n inject,\n signal,\n} from '@angular/core';\nimport { FlagdeckService } from './flagdeck.service';\n\n/**\n * Structural directive: render content when a flag is on, with an optional\n * `;else` template. Re-renders live on context and realtime changes.\n *\n * <div *fdFlag=\"'new-ui'; else legacy\">new</div>\n * <ng-template #legacy>old</ng-template>\n */\n@Directive({ selector: '[fdFlag]', standalone: true })\nexport class FdFlagDirective {\n private readonly tpl = inject(TemplateRef<unknown>);\n private readonly vcr = inject(ViewContainerRef);\n private readonly fd = inject(FlagdeckService);\n private readonly destroyRef = inject(DestroyRef);\n\n private readonly key = signal('');\n private readonly tick = signal(0);\n private readonly on = signal(false);\n private elseTpl: TemplateRef<unknown> | null = null;\n private subscribedKey: string | null = null;\n private readonly bump = (): void => this.tick.update((n) => n + 1);\n\n @Input({ required: true }) set fdFlag(key: string) {\n this.key.set(key);\n }\n @Input() set fdFlagElse(tpl: TemplateRef<unknown> | null) {\n this.elseTpl = tpl;\n this.render();\n }\n\n constructor() {\n effect((onCleanup) => {\n const key = this.key();\n const ctx = this.fd.context();\n this.tick(); // track realtime bumps\n\n if (this.subscribedKey !== key) {\n if (this.subscribedKey) {\n this.fd.client.off(`change:${this.subscribedKey}`, this.bump);\n }\n if (key) this.fd.client.onFlagChange(key, this.bump);\n this.subscribedKey = key;\n }\n if (!key) return;\n\n let cancelled = false;\n void this.fd.client\n .evaluateFlag(key, ctx)\n .then((r) => {\n if (cancelled) return;\n this.on.set(Boolean(r.value));\n this.render();\n })\n .catch(() => {\n if (cancelled) return;\n this.on.set(false);\n this.render();\n });\n onCleanup(() => {\n cancelled = true;\n });\n });\n\n this.destroyRef.onDestroy(() => {\n if (this.subscribedKey) {\n this.fd.client.off(`change:${this.subscribedKey}`, this.bump);\n }\n });\n }\n\n private render(): void {\n this.vcr.clear();\n if (this.on()) {\n this.vcr.createEmbeddedView(this.tpl);\n } else if (this.elseTpl) {\n this.vcr.createEmbeddedView(this.elseTpl);\n }\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;AAGA;MACa,gBAAgB,GAAG,IAAI,cAAc,CAChD,kBAAkB;;ACYpB;;;;;;;AAOG;MAEU,eAAe,CAAA;;AAEjB,IAAA,MAAM;AAEE,IAAA,QAAQ;;AAEhB,IAAA,OAAO;AAEhB,IAAA,WAAA,GAAA;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Q,MAAM,GAAA;AACZ,QAAA,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE;AAChB,QAAA,IAAI,IAAI,CAAC,EAAE,EAAE,EAAE;YACb,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC;QACvC;AAAO,aAAA,IAAI,IAAI,CAAC,OAAO,EAAE;YACvB,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC;QAC3C;IACF;wGApEW,eAAe,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;4FAAf,eAAe,EAAA,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,UAAA,EAAA,MAAA,EAAA,EAAA,MAAA,EAAA,QAAA,EAAA,UAAA,EAAA,YAAA,EAAA,EAAA,QAAA,EAAA,EAAA,EAAA,CAAA;;4FAAf,eAAe,EAAA,UAAA,EAAA,CAAA;kBAD3B,SAAS;AAAC,YAAA,IAAA,EAAA,CAAA,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE;wDAcpB,MAAM,EAAA,CAAA;sBAApC,KAAK;uBAAC,EAAE,QAAQ,EAAE,IAAI,EAAE;gBAGZ,UAAU,EAAA,CAAA;sBAAtB;;;ACpCH;;AAEG;;"}
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generated bundle index. Do not edit.
3
+ */
4
+ /// <amd-module name="@flagdeck/angular" />
5
+ export * from './public-api';
@@ -0,0 +1,27 @@
1
+ import { TemplateRef } from '@angular/core';
2
+ import * as i0 from "@angular/core";
3
+ /**
4
+ * Structural directive: render content when a flag is on, with an optional
5
+ * `;else` template. Re-renders live on context and realtime changes.
6
+ *
7
+ * <div *fdFlag="'new-ui'; else legacy">new</div>
8
+ * <ng-template #legacy>old</ng-template>
9
+ */
10
+ export declare class FdFlagDirective {
11
+ private readonly tpl;
12
+ private readonly vcr;
13
+ private readonly fd;
14
+ private readonly destroyRef;
15
+ private readonly key;
16
+ private readonly tick;
17
+ private readonly on;
18
+ private elseTpl;
19
+ private subscribedKey;
20
+ private readonly bump;
21
+ set fdFlag(key: string);
22
+ set fdFlagElse(tpl: TemplateRef<unknown> | null);
23
+ constructor();
24
+ private render;
25
+ static ɵfac: i0.ɵɵFactoryDeclaration<FdFlagDirective, never>;
26
+ static ɵdir: i0.ɵɵDirectiveDeclaration<FdFlagDirective, "[fdFlag]", never, { "fdFlag": { "alias": "fdFlag"; "required": true; }; "fdFlagElse": { "alias": "fdFlagElse"; "required": false; }; }, {}, never, never, true, never>;
27
+ }
@@ -0,0 +1,36 @@
1
+ import { OnDestroy, Signal } from '@angular/core';
2
+ import { type EvaluationContext, type EvaluationResult, type FlagdeckClient } from '@flagdeck/js';
3
+ import * as i0 from "@angular/core";
4
+ /**
5
+ * The Flagdeck client as an Angular service, exposing flags as signals.
6
+ *
7
+ * Realtime is a key-only signal: a `change:<key>` from the server tells the
8
+ * service to re-evaluate that flag for the current context, and the returned
9
+ * signal updates — never trusting a value off the wire (rollout/targeting
10
+ * resolve server-side). The same model as the react hooks and vue composables.
11
+ */
12
+ export declare class FlagdeckService implements OnDestroy {
13
+ /** The underlying browser client, for advanced use. */
14
+ readonly client: FlagdeckClient;
15
+ private readonly _context;
16
+ /** The current evaluation context as a signal. */
17
+ readonly context: Signal<Partial<EvaluationContext>>;
18
+ constructor();
19
+ /** Replace the evaluation context; every flag signal re-evaluates. */
20
+ setContext(context: Partial<EvaluationContext>): void;
21
+ /** Whether the realtime (SSE) connection is currently open. */
22
+ isRealTime(): boolean;
23
+ /**
24
+ * One-off evaluation for an explicit context (used by targeting UIs). Does not
25
+ * create a subscription; returns the full result (value, source, reason).
26
+ */
27
+ evaluate(flagKey: string, context?: Partial<EvaluationContext>): Promise<EvaluationResult>;
28
+ /** A boolean flag as a live signal. Call in an injection context. */
29
+ flag(flagKey: string, defaultValue?: boolean): Signal<boolean>;
30
+ /** A typed flag value as a live signal, with a code fallback. Call in an injection context. */
31
+ flagValue<T>(flagKey: string, defaultValue: T): Signal<T>;
32
+ private toSignal;
33
+ ngOnDestroy(): void;
34
+ static ɵfac: i0.ɵɵFactoryDeclaration<FlagdeckService, never>;
35
+ static ɵprov: i0.ɵɵInjectableDeclaration<FlagdeckService>;
36
+ }
@@ -0,0 +1,12 @@
1
+ import { EnvironmentProviders } from '@angular/core';
2
+ import { FLAGDECK_OPTIONS } from './tokens';
3
+ import type { FlagdeckProviderOptions } from './types';
4
+ export { FLAGDECK_OPTIONS };
5
+ /**
6
+ * Register Flagdeck for a standalone Angular app. Add to `app.config.ts`:
7
+ *
8
+ * providers: [provideFlagdeck({ clientOptions: { apiKey, realTimeUpdates: true } })]
9
+ *
10
+ * Creates a single shared client for the app and tears it down on destroy.
11
+ */
12
+ export declare function provideFlagdeck(options: FlagdeckProviderOptions): EnvironmentProviders;
@@ -0,0 +1,4 @@
1
+ import { InjectionToken } from '@angular/core';
2
+ import type { FlagdeckProviderOptions } from './types';
3
+ /** DI token holding the provider options; read by FlagdeckService. */
4
+ export declare const FLAGDECK_OPTIONS: InjectionToken<FlagdeckProviderOptions>;
package/lib/types.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { EvaluationContext, FlagdeckOptions } from '@flagdeck/js';
2
+ export interface FlagdeckProviderOptions {
3
+ /** Options passed straight to the Flagdeck browser client (apiKey, realTimeUpdates, debug, …). */
4
+ clientOptions: FlagdeckOptions;
5
+ /** The initial evaluation context (userId, attributes). Change it later with FlagdeckService.setContext(). */
6
+ context?: Partial<EvaluationContext>;
7
+ }
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "@flagdeck/angular",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0",
4
+ "description": "Angular integration for Flagdeck feature flags",
5
+ "keywords": [
6
+ "flagdeck",
7
+ "feature-flags",
8
+ "angular",
9
+ "signals",
10
+ "feature-toggles",
11
+ "ab-testing"
12
+ ],
13
+ "peerDependencies": {
14
+ "@angular/common": "^17.0.0 || ^18.0.0 || ^19.0.0",
15
+ "@angular/core": "^17.0.0 || ^18.0.0 || ^19.0.0"
16
+ },
17
+ "dependencies": {
18
+ "@flagdeck/js": "^1.0.0",
19
+ "tslib": "^2.8.0"
20
+ },
21
+ "license": "MIT",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/flagdeck/flagdeck.git",
25
+ "directory": "packages/@flagdeck/angular"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public",
29
+ "directory": "dist"
30
+ },
31
+ "author": "Flagdeck Team",
32
+ "module": "fesm2022/flagdeck-angular.mjs",
33
+ "typings": "index.d.ts",
34
+ "exports": {
35
+ "./package.json": {
36
+ "default": "./package.json"
37
+ },
38
+ ".": {
39
+ "types": "./index.d.ts",
40
+ "default": "./fesm2022/flagdeck-angular.mjs"
41
+ }
42
+ },
43
+ "sideEffects": false
6
44
  }
@@ -0,0 +1,5 @@
1
+ export { provideFlagdeck, FLAGDECK_OPTIONS } from './lib/provide-flagdeck';
2
+ export { FlagdeckService } from './lib/flagdeck.service';
3
+ export { FdFlagDirective } from './lib/fd-flag.directive';
4
+ export type { FlagdeckProviderOptions } from './lib/types';
5
+ export type { FlagdeckOptions, EvaluationContext, EvaluationResult, } from '@flagdeck/js';