@signap/signals-angular 2.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/LICENSE ADDED
@@ -0,0 +1,143 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+ (b) You must cause any modified files to carry prominent notices
97
+ stating that You changed the files; and
98
+ (c) You must retain, in the Source form of any Derivative Works
99
+ that You distribute, all copyright, patent, trademark, and
100
+ attribution notices from the Source form of the Work; and
101
+ (d) If the Work includes a "NOTICE" text file as part of its
102
+ distribution, then any Derivative Works that You distribute must
103
+ include a readable copy of the attribution notices contained
104
+ within such NOTICE file.
105
+
106
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
107
+ any Contribution intentionally submitted for inclusion in the Work
108
+ by You to the Licensor shall be under the terms and conditions of
109
+ this License, without any additional terms or conditions.
110
+
111
+ 6. Trademarks. This License does not grant permission to use the trade
112
+ names, trademarks, service marks, or product names of the Licensor.
113
+
114
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed
115
+ to in writing, Licensor provides the Work on an "AS IS" BASIS,
116
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
117
+
118
+ 8. Limitation of Liability. In no event and under no legal theory shall
119
+ any Contributor be liable to You for damages, including any direct,
120
+ indirect, special, incidental, or consequential damages of any
121
+ character arising as a result of this License or out of the use or
122
+ inability to use the Work.
123
+
124
+ 9. Accepting Warranty or Additional Liability. While redistributing the
125
+ Work or Derivative Works thereof, You may choose to offer, and charge
126
+ a fee for, acceptance of support, warranty, indemnity, or other
127
+ liability obligations and/or rights consistent with this License.
128
+
129
+ END OF TERMS AND CONDITIONS
130
+
131
+ Copyright 2026 Signap Technology
132
+
133
+ Licensed under the Apache License, Version 2.0 (the "License");
134
+ you may not use this file except in compliance with the License.
135
+ You may obtain a copy of the License at
136
+
137
+ http://www.apache.org/licenses/LICENSE-2.0
138
+
139
+ Unless required by applicable law or agreed to in writing, software
140
+ distributed under the License is distributed on an "AS IS" BASIS,
141
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
142
+ See the License for the specific language governing permissions and
143
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # @signap/signals-angular
2
+
3
+ Angular (standalone) wrapper for `@signap/signals-web` — a `provideSignals()`
4
+ provider plus an `injectVisitorData()` helper that mirror the React hook and Vue
5
+ composable.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add @signap/signals-angular
11
+ # @angular/core and @angular/common are peerDependencies (>=17 <21)
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ Register the agent once with `provideSignals()` at bootstrap, then call
17
+ `injectVisitorData()` in any component below it.
18
+
19
+ ### Provider (app bootstrap)
20
+
21
+ ```ts
22
+ // main.ts
23
+ import { bootstrapApplication } from "@angular/platform-browser";
24
+ import { provideSignals } from "@signap/signals-angular";
25
+ import { AppComponent } from "./app.component";
26
+
27
+ bootstrapApplication(AppComponent, {
28
+ providers: [
29
+ provideSignals({
30
+ apiKey: "pk_live_...",
31
+ endpoint: "https://ingest.signap.example",
32
+ }),
33
+ ],
34
+ });
35
+ ```
36
+
37
+ ### Consume (`injectVisitorData`)
38
+
39
+ ```ts
40
+ // visitor-badge.component.ts
41
+ import { Component } from "@angular/core";
42
+ import { injectVisitorData } from "@signap/signals-angular";
43
+
44
+ @Component({
45
+ selector: "visitor-badge",
46
+ standalone: true,
47
+ template: `
48
+ @if (visitor.isLoading()) {
49
+ <p>Identifying…</p>
50
+ } @else if (visitor.error()) {
51
+ <p>Failed: {{ visitor.error()?.message }}</p>
52
+ } @else {
53
+ <p>visitor: {{ visitor.data()?.visitorId }}</p>
54
+ <p>confidence: {{ visitor.data()?.confidence }}</p>
55
+ <button (click)="visitor.refetch()">Re-identify</button>
56
+ }
57
+ `,
58
+ })
59
+ export class VisitorBadgeComponent {
60
+ // Field initializers run in the injection context, so injectVisitorData() is valid here.
61
+ readonly visitor = injectVisitorData({ tag: "page-view" });
62
+ }
63
+ ```
64
+
65
+ ## Helper shape (v2)
66
+
67
+ `injectVisitorData()` runs `agent.identify()` once when the agent is ready and
68
+ exposes the resolved visitor as Angular **signals**. ADR §A2 means one
69
+ round-trip — no separate ack/lookup transition.
70
+
71
+ | field | type | when populated |
72
+ |-------------|------------------------------------------|----------------------------------------|
73
+ | `data` | `Signal<IdentifyResult \| undefined>` | once `agent.identify()` resolves |
74
+ | `isLoading` | `Signal<boolean>` | true between call time and `data` |
75
+ | `error` | `Signal<Error \| null>` | last failure (load / identify) |
76
+ | `refetch` | `() => Promise<void>` | re-run `agent.identify()` |
77
+
78
+ Read each signal by calling it (`visitor.data()`), in a template or a
79
+ `computed`/`effect`.
80
+
81
+ SSR-safe: `provideSignals()` gates `SignalsAgent.load()` behind
82
+ `isPlatformBrowser(PLATFORM_ID)`, so it never runs during Angular Universal /
83
+ prerender server rendering.
84
+
85
+ ## Endpoint (required)
86
+
87
+ `provideSignals()` takes the underlying `AgentLoadOptions`. `endpoint` is
88
+ **required** — the published SDK ships no baked default host (the region→host map
89
+ is empty in this alpha), so pass an explicit `endpoint` (a string or a callback).
90
+ See the `@signap/signals-web` README (Endpoint section).
91
+
92
+ > `opts` is snapshotted at bootstrap (later changes are ignored — re-bootstrap to
93
+ > swap apiKey/endpoint), the same contract as the React/Vue wrappers.
94
+
95
+ ## Why decorator-free
96
+
97
+ The package ships a functional provider, an `inject()` helper, and a plain class
98
+ wired through a DI factory — no `@Injectable`/`@Component` decorators. That keeps
99
+ it AOT-safe under a plain `tsup` build (no ng-packagr / partial-Ivy step needed)
100
+ and importable from any Angular 17+ app.
package/dist/index.cjs ADDED
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ SIGNALS_CLIENT: () => SIGNALS_CLIENT,
24
+ SdkError: () => import_signals_web2.SdkError,
25
+ SignalsClient: () => SignalsClient,
26
+ WEB_SDK_VERSION: () => import_signals_web2.VERSION,
27
+ injectVisitorData: () => injectVisitorData,
28
+ provideSignals: () => provideSignals
29
+ });
30
+ module.exports = __toCommonJS(index_exports);
31
+ var import_signals_web2 = require("@signap/signals-web");
32
+
33
+ // src/client.ts
34
+ var import_core = require("@angular/core");
35
+ var import_signals_web = require("@signap/signals-web");
36
+ var SignalsClient = class {
37
+ agentState = (0, import_core.signal)(null);
38
+ loadErrorState = (0, import_core.signal)(null);
39
+ /** Resolved agent, or `null` until `SignalsAgent.load()` settles. */
40
+ agent = this.agentState.asReadonly();
41
+ /** Non-null if `SignalsAgent.load()` rejected. */
42
+ loadError = this.loadErrorState.asReadonly();
43
+ /**
44
+ * Resolves once `load()` has settled (agent set OR loadError set). Lets
45
+ * `injectVisitorData()` await readiness without an Angular `effect`, so the
46
+ * auto-identify fires exactly once regardless of change-detection timing.
47
+ */
48
+ ready;
49
+ /**
50
+ * @param opts forwarded verbatim to `SignalsAgent.load()`.
51
+ * @param browser whether we're running in a browser; `load()` only fires
52
+ * client-side so SSR / prerender never touches
53
+ * window/document/WebCrypto (the Angular analog of the Vue
54
+ * plugin's `typeof window` guard).
55
+ */
56
+ constructor(opts, browser) {
57
+ if (!browser) {
58
+ this.ready = Promise.resolve();
59
+ return;
60
+ }
61
+ this.ready = import_signals_web.SignalsAgent.load(opts).then((loaded) => {
62
+ this.agentState.set(loaded);
63
+ }).catch((err) => {
64
+ this.loadErrorState.set(err instanceof Error ? err : new Error(String(err)));
65
+ });
66
+ }
67
+ };
68
+
69
+ // src/provide-signals.ts
70
+ var import_common = require("@angular/common");
71
+ var import_core3 = require("@angular/core");
72
+
73
+ // src/tokens.ts
74
+ var import_core2 = require("@angular/core");
75
+ var SIGNALS_CLIENT = new import_core2.InjectionToken("signap.signals.client");
76
+
77
+ // src/provide-signals.ts
78
+ function provideSignals(opts) {
79
+ return (0, import_core3.makeEnvironmentProviders)([
80
+ {
81
+ provide: SIGNALS_CLIENT,
82
+ useFactory: () => new SignalsClient(opts, (0, import_common.isPlatformBrowser)((0, import_core3.inject)(import_core3.PLATFORM_ID)))
83
+ }
84
+ ]);
85
+ }
86
+
87
+ // src/inject-visitor-data.ts
88
+ var import_core4 = require("@angular/core");
89
+ function injectVisitorData(opts) {
90
+ (0, import_core4.assertInInjectionContext)(injectVisitorData);
91
+ const client = (0, import_core4.inject)(SIGNALS_CLIENT, { optional: true });
92
+ if (!client) {
93
+ throw new Error(
94
+ "[@signap/signals-angular] injectVisitorData() requires provideSignals() in the application (or component) providers"
95
+ );
96
+ }
97
+ const data = (0, import_core4.signal)(void 0);
98
+ const error = (0, import_core4.signal)(null);
99
+ const isLoading = (0, import_core4.signal)(client.agent() === null && client.loadError() === null);
100
+ let token = { cancelled: false };
101
+ (0, import_core4.inject)(import_core4.DestroyRef).onDestroy(() => {
102
+ token.cancelled = true;
103
+ });
104
+ const run = async () => {
105
+ const agent = client.agent();
106
+ if (!agent) {
107
+ const loadError = client.loadError();
108
+ if (loadError) {
109
+ error.set(loadError);
110
+ isLoading.set(false);
111
+ }
112
+ return;
113
+ }
114
+ token.cancelled = true;
115
+ const my = { cancelled: false };
116
+ token = my;
117
+ isLoading.set(true);
118
+ error.set(null);
119
+ data.set(void 0);
120
+ try {
121
+ const res = await agent.identify(opts);
122
+ if (my.cancelled) return;
123
+ data.set(res);
124
+ } catch (err) {
125
+ if (my.cancelled) return;
126
+ error.set(err instanceof Error ? err : new Error(String(err)));
127
+ } finally {
128
+ if (!my.cancelled) isLoading.set(false);
129
+ }
130
+ };
131
+ void client.ready.then(() => run());
132
+ return { data, isLoading, error, refetch: run };
133
+ }
134
+ // Annotate the CommonJS export names for ESM import in node:
135
+ 0 && (module.exports = {
136
+ SIGNALS_CLIENT,
137
+ SdkError,
138
+ SignalsClient,
139
+ WEB_SDK_VERSION,
140
+ injectVisitorData,
141
+ provideSignals
142
+ });
143
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/client.ts","../src/provide-signals.ts","../src/tokens.ts","../src/inject-visitor-data.ts"],"sourcesContent":["export {\n type AgentLoadOptions,\n type IdentifyOptions,\n type IdentifyResult,\n SdkError,\n type SdkErrorCode,\n VERSION as WEB_SDK_VERSION,\n} from \"@signap/signals-web\";\n\nexport { SignalsClient } from \"./client\";\nexport { provideSignals } from \"./provide-signals\";\nexport { SIGNALS_CLIENT } from \"./tokens\";\nexport {\n injectVisitorData,\n type InjectVisitorDataOptions,\n type InjectVisitorDataResult,\n} from \"./inject-visitor-data\";\n","import { type Signal, signal } from \"@angular/core\";\nimport { type AgentLoadOptions, SignalsAgent } from \"@signap/signals-web\";\n\n/**\n * Holds a single lazily-loaded SignalsAgent and exposes its readiness as Angular\n * signals — the framework-native analog of the Vue wrapper's provide/inject refs\n * and the React wrapper's context. `agent()` is `null` until `SignalsAgent.load()`\n * settles; `loadError()` is non-null if it rejected (e.g. an invalid apiKey).\n *\n * Deliberately NOT `@Injectable`: a decorator-free class keeps this package\n * AOT-safe under a plain tsup build (no ngtsc / ng-packagr partial-Ivy metadata\n * step). It is wired into DI by the factory in `provideSignals()`.\n */\nexport class SignalsClient {\n private readonly agentState = signal<SignalsAgent | null>(null);\n private readonly loadErrorState = signal<Error | null>(null);\n\n /** Resolved agent, or `null` until `SignalsAgent.load()` settles. */\n readonly agent: Signal<SignalsAgent | null> = this.agentState.asReadonly();\n /** Non-null if `SignalsAgent.load()` rejected. */\n readonly loadError: Signal<Error | null> = this.loadErrorState.asReadonly();\n /**\n * Resolves once `load()` has settled (agent set OR loadError set). Lets\n * `injectVisitorData()` await readiness without an Angular `effect`, so the\n * auto-identify fires exactly once regardless of change-detection timing.\n */\n readonly ready: Promise<void>;\n\n /**\n * @param opts forwarded verbatim to `SignalsAgent.load()`.\n * @param browser whether we're running in a browser; `load()` only fires\n * client-side so SSR / prerender never touches\n * window/document/WebCrypto (the Angular analog of the Vue\n * plugin's `typeof window` guard).\n */\n constructor(opts: AgentLoadOptions, browser: boolean) {\n if (!browser) {\n this.ready = Promise.resolve();\n return;\n }\n this.ready = SignalsAgent.load(opts)\n .then((loaded) => {\n this.agentState.set(loaded);\n })\n .catch((err: unknown) => {\n this.loadErrorState.set(err instanceof Error ? err : new Error(String(err)));\n });\n }\n}\n","import { isPlatformBrowser } from \"@angular/common\";\nimport {\n type EnvironmentProviders,\n PLATFORM_ID,\n inject,\n makeEnvironmentProviders,\n} from \"@angular/core\";\nimport type { AgentLoadOptions } from \"@signap/signals-web\";\nimport { SignalsClient } from \"./client\";\nimport { SIGNALS_CLIENT } from \"./tokens\";\n\n/**\n * Registers a single app-wide SignalsAgent — the idiomatic standalone-Angular\n * entry point, analogous to React's `<SignalsProvider>` and Vue's\n * `app.use(SignalsPlugin)`:\n *\n * ```ts\n * bootstrapApplication(AppComponent, {\n * providers: [\n * provideSignals({ apiKey: \"pk_live_...\", endpoint: \"https://ingest.example\" }),\n * ],\n * });\n * ```\n *\n * SSR-safe: the factory injects `PLATFORM_ID` and only lets the client call\n * `SignalsAgent.load()` in a browser, so a server render / prerender never loads\n * the agent.\n *\n * `opts` is snapshotted here at bootstrap; to swap apiKey/endpoint, re-bootstrap\n * (same snapshot-at-init contract as the React/Vue wrappers).\n */\nexport function provideSignals(opts: AgentLoadOptions): EnvironmentProviders {\n return makeEnvironmentProviders([\n {\n provide: SIGNALS_CLIENT,\n useFactory: () => new SignalsClient(opts, isPlatformBrowser(inject(PLATFORM_ID))),\n },\n ]);\n}\n","import { InjectionToken } from \"@angular/core\";\nimport type { SignalsClient } from \"./client\";\n\n/**\n * DI token the app-wide {@link SignalsClient} is registered under (by\n * `provideSignals()`) and that `injectVisitorData()` resolves. Most consumers\n * don't inject this directly — call `injectVisitorData()`. It is exported for\n * advanced use (e.g. `inject(SIGNALS_CLIENT).agent()` to read the raw agent).\n */\nexport const SIGNALS_CLIENT = new InjectionToken<SignalsClient>(\"signap.signals.client\");\n","import { DestroyRef, type Signal, assertInInjectionContext, inject, signal } from \"@angular/core\";\nimport type { IdentifyOptions, IdentifyResult } from \"@signap/signals-web\";\nimport { SIGNALS_CLIENT } from \"./tokens\";\n\nexport type InjectVisitorDataOptions = IdentifyOptions;\n\nexport interface InjectVisitorDataResult {\n /**\n * Resolved visitor from `agent.identify()`. Under ADR §A2 the call is a single\n * synchronous round-trip — `visitorId`/`confidence`/`identifiedAt` arrive\n * together, no polling. A `Signal`, so read it as `data()` (in a template or a\n * `computed`/`effect`).\n */\n data: Signal<IdentifyResult | undefined>;\n /** True between call time and the identify() resolution (or `error`). */\n isLoading: Signal<boolean>;\n error: Signal<Error | null>;\n /** Re-run `agent.identify()` (e.g. from a button click). */\n refetch: () => Promise<void>;\n}\n\n/**\n * Auto-identifies once the provider's agent is ready, then exposes the resolved\n * visitor as Angular signals — the framework-native analog of React's\n * `useVisitorData()` hook and Vue's `useVisitorData()` composable.\n *\n * Must be called in an injection context (a component/directive constructor or a\n * field initializer, or inside `runInInjectionContext`) below `provideSignals()`.\n */\nexport function injectVisitorData(opts?: InjectVisitorDataOptions): InjectVisitorDataResult {\n assertInInjectionContext(injectVisitorData);\n\n const client = inject(SIGNALS_CLIENT, { optional: true });\n if (!client) {\n throw new Error(\n \"[@signap/signals-angular] injectVisitorData() requires provideSignals() in the application (or component) providers\",\n );\n }\n\n const data = signal<IdentifyResult | undefined>(undefined);\n const error = signal<Error | null>(null);\n // Loading until the agent (or a load error) settles.\n const isLoading = signal(client.agent() === null && client.loadError() === null);\n\n // Supersede token so a slow response from a call that refetch() replaced (or a\n // response arriving after teardown) is discarded.\n let token = { cancelled: false };\n inject(DestroyRef).onDestroy(() => {\n token.cancelled = true;\n });\n\n const run = async (): Promise<void> => {\n const agent = client.agent();\n if (!agent) {\n const loadError = client.loadError();\n if (loadError) {\n error.set(loadError);\n isLoading.set(false);\n }\n return;\n }\n token.cancelled = true;\n const my = { cancelled: false };\n token = my;\n isLoading.set(true);\n error.set(null);\n data.set(undefined);\n try {\n const res = await agent.identify(opts);\n if (my.cancelled) return;\n data.set(res);\n } catch (err) {\n if (my.cancelled) return;\n error.set(err instanceof Error ? err : new Error(String(err)));\n } finally {\n if (!my.cancelled) isLoading.set(false);\n }\n };\n\n // Auto-run exactly once, after load() settles. `ready` resolves whether load()\n // succeeded or failed; even if it already resolved, `.then` defers to a\n // microtask so the returned signals are wired up before the first run().\n void client.ready.then(() => run());\n\n return { data, isLoading, error, refetch: run };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,sBAOO;;;ACPP,kBAAoC;AACpC,yBAAoD;AAY7C,IAAM,gBAAN,MAAoB;AAAA,EACR,iBAAa,oBAA4B,IAAI;AAAA,EAC7C,qBAAiB,oBAAqB,IAAI;AAAA;AAAA,EAGlD,QAAqC,KAAK,WAAW,WAAW;AAAA;AAAA,EAEhE,YAAkC,KAAK,eAAe,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMjE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAST,YAAY,MAAwB,SAAkB;AACpD,QAAI,CAAC,SAAS;AACZ,WAAK,QAAQ,QAAQ,QAAQ;AAC7B;AAAA,IACF;AACA,SAAK,QAAQ,gCAAa,KAAK,IAAI,EAChC,KAAK,CAAC,WAAW;AAChB,WAAK,WAAW,IAAI,MAAM;AAAA,IAC5B,CAAC,EACA,MAAM,CAAC,QAAiB;AACvB,WAAK,eAAe,IAAI,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC;AAAA,IAC7E,CAAC;AAAA,EACL;AACF;;;AChDA,oBAAkC;AAClC,IAAAC,eAKO;;;ACNP,IAAAC,eAA+B;AASxB,IAAM,iBAAiB,IAAI,4BAA8B,uBAAuB;;;ADsBhF,SAAS,eAAe,MAA8C;AAC3E,aAAO,uCAAyB;AAAA,IAC9B;AAAA,MACE,SAAS;AAAA,MACT,YAAY,MAAM,IAAI,cAAc,UAAM,qCAAkB,qBAAO,wBAAW,CAAC,CAAC;AAAA,IAClF;AAAA,EACF,CAAC;AACH;;;AEtCA,IAAAC,eAAkF;AA6B3E,SAAS,kBAAkB,MAA0D;AAC1F,6CAAyB,iBAAiB;AAE1C,QAAM,aAAS,qBAAO,gBAAgB,EAAE,UAAU,KAAK,CAAC;AACxD,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,WAAO,qBAAmC,MAAS;AACzD,QAAM,YAAQ,qBAAqB,IAAI;AAEvC,QAAM,gBAAY,qBAAO,OAAO,MAAM,MAAM,QAAQ,OAAO,UAAU,MAAM,IAAI;AAI/E,MAAI,QAAQ,EAAE,WAAW,MAAM;AAC/B,2BAAO,uBAAU,EAAE,UAAU,MAAM;AACjC,UAAM,YAAY;AAAA,EACpB,CAAC;AAED,QAAM,MAAM,YAA2B;AACrC,UAAM,QAAQ,OAAO,MAAM;AAC3B,QAAI,CAAC,OAAO;AACV,YAAM,YAAY,OAAO,UAAU;AACnC,UAAI,WAAW;AACb,cAAM,IAAI,SAAS;AACnB,kBAAU,IAAI,KAAK;AAAA,MACrB;AACA;AAAA,IACF;AACA,UAAM,YAAY;AAClB,UAAM,KAAK,EAAE,WAAW,MAAM;AAC9B,YAAQ;AACR,cAAU,IAAI,IAAI;AAClB,UAAM,IAAI,IAAI;AACd,SAAK,IAAI,MAAS;AAClB,QAAI;AACF,YAAM,MAAM,MAAM,MAAM,SAAS,IAAI;AACrC,UAAI,GAAG,UAAW;AAClB,WAAK,IAAI,GAAG;AAAA,IACd,SAAS,KAAK;AACZ,UAAI,GAAG,UAAW;AAClB,YAAM,IAAI,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC;AAAA,IAC/D,UAAE;AACA,UAAI,CAAC,GAAG,UAAW,WAAU,IAAI,KAAK;AAAA,IACxC;AAAA,EACF;AAKA,OAAK,OAAO,MAAM,KAAK,MAAM,IAAI,CAAC;AAElC,SAAO,EAAE,MAAM,WAAW,OAAO,SAAS,IAAI;AAChD;","names":["import_signals_web","import_core","import_core","import_core"]}
@@ -0,0 +1,93 @@
1
+ import { SignalsAgent, AgentLoadOptions, IdentifyOptions, IdentifyResult } from '@signap/signals-web';
2
+ export { AgentLoadOptions, IdentifyOptions, IdentifyResult, SdkError, SdkErrorCode, VERSION as WEB_SDK_VERSION } from '@signap/signals-web';
3
+ import { Signal, EnvironmentProviders, InjectionToken } from '@angular/core';
4
+
5
+ /**
6
+ * Holds a single lazily-loaded SignalsAgent and exposes its readiness as Angular
7
+ * signals — the framework-native analog of the Vue wrapper's provide/inject refs
8
+ * and the React wrapper's context. `agent()` is `null` until `SignalsAgent.load()`
9
+ * settles; `loadError()` is non-null if it rejected (e.g. an invalid apiKey).
10
+ *
11
+ * Deliberately NOT `@Injectable`: a decorator-free class keeps this package
12
+ * AOT-safe under a plain tsup build (no ngtsc / ng-packagr partial-Ivy metadata
13
+ * step). It is wired into DI by the factory in `provideSignals()`.
14
+ */
15
+ declare class SignalsClient {
16
+ private readonly agentState;
17
+ private readonly loadErrorState;
18
+ /** Resolved agent, or `null` until `SignalsAgent.load()` settles. */
19
+ readonly agent: Signal<SignalsAgent | null>;
20
+ /** Non-null if `SignalsAgent.load()` rejected. */
21
+ readonly loadError: Signal<Error | null>;
22
+ /**
23
+ * Resolves once `load()` has settled (agent set OR loadError set). Lets
24
+ * `injectVisitorData()` await readiness without an Angular `effect`, so the
25
+ * auto-identify fires exactly once regardless of change-detection timing.
26
+ */
27
+ readonly ready: Promise<void>;
28
+ /**
29
+ * @param opts forwarded verbatim to `SignalsAgent.load()`.
30
+ * @param browser whether we're running in a browser; `load()` only fires
31
+ * client-side so SSR / prerender never touches
32
+ * window/document/WebCrypto (the Angular analog of the Vue
33
+ * plugin's `typeof window` guard).
34
+ */
35
+ constructor(opts: AgentLoadOptions, browser: boolean);
36
+ }
37
+
38
+ /**
39
+ * Registers a single app-wide SignalsAgent — the idiomatic standalone-Angular
40
+ * entry point, analogous to React's `<SignalsProvider>` and Vue's
41
+ * `app.use(SignalsPlugin)`:
42
+ *
43
+ * ```ts
44
+ * bootstrapApplication(AppComponent, {
45
+ * providers: [
46
+ * provideSignals({ apiKey: "pk_live_...", endpoint: "https://ingest.example" }),
47
+ * ],
48
+ * });
49
+ * ```
50
+ *
51
+ * SSR-safe: the factory injects `PLATFORM_ID` and only lets the client call
52
+ * `SignalsAgent.load()` in a browser, so a server render / prerender never loads
53
+ * the agent.
54
+ *
55
+ * `opts` is snapshotted here at bootstrap; to swap apiKey/endpoint, re-bootstrap
56
+ * (same snapshot-at-init contract as the React/Vue wrappers).
57
+ */
58
+ declare function provideSignals(opts: AgentLoadOptions): EnvironmentProviders;
59
+
60
+ /**
61
+ * DI token the app-wide {@link SignalsClient} is registered under (by
62
+ * `provideSignals()`) and that `injectVisitorData()` resolves. Most consumers
63
+ * don't inject this directly — call `injectVisitorData()`. It is exported for
64
+ * advanced use (e.g. `inject(SIGNALS_CLIENT).agent()` to read the raw agent).
65
+ */
66
+ declare const SIGNALS_CLIENT: InjectionToken<SignalsClient>;
67
+
68
+ type InjectVisitorDataOptions = IdentifyOptions;
69
+ interface InjectVisitorDataResult {
70
+ /**
71
+ * Resolved visitor from `agent.identify()`. Under ADR §A2 the call is a single
72
+ * synchronous round-trip — `visitorId`/`confidence`/`identifiedAt` arrive
73
+ * together, no polling. A `Signal`, so read it as `data()` (in a template or a
74
+ * `computed`/`effect`).
75
+ */
76
+ data: Signal<IdentifyResult | undefined>;
77
+ /** True between call time and the identify() resolution (or `error`). */
78
+ isLoading: Signal<boolean>;
79
+ error: Signal<Error | null>;
80
+ /** Re-run `agent.identify()` (e.g. from a button click). */
81
+ refetch: () => Promise<void>;
82
+ }
83
+ /**
84
+ * Auto-identifies once the provider's agent is ready, then exposes the resolved
85
+ * visitor as Angular signals — the framework-native analog of React's
86
+ * `useVisitorData()` hook and Vue's `useVisitorData()` composable.
87
+ *
88
+ * Must be called in an injection context (a component/directive constructor or a
89
+ * field initializer, or inside `runInInjectionContext`) below `provideSignals()`.
90
+ */
91
+ declare function injectVisitorData(opts?: InjectVisitorDataOptions): InjectVisitorDataResult;
92
+
93
+ export { type InjectVisitorDataOptions, type InjectVisitorDataResult, SIGNALS_CLIENT, SignalsClient, injectVisitorData, provideSignals };
@@ -0,0 +1,93 @@
1
+ import { SignalsAgent, AgentLoadOptions, IdentifyOptions, IdentifyResult } from '@signap/signals-web';
2
+ export { AgentLoadOptions, IdentifyOptions, IdentifyResult, SdkError, SdkErrorCode, VERSION as WEB_SDK_VERSION } from '@signap/signals-web';
3
+ import { Signal, EnvironmentProviders, InjectionToken } from '@angular/core';
4
+
5
+ /**
6
+ * Holds a single lazily-loaded SignalsAgent and exposes its readiness as Angular
7
+ * signals — the framework-native analog of the Vue wrapper's provide/inject refs
8
+ * and the React wrapper's context. `agent()` is `null` until `SignalsAgent.load()`
9
+ * settles; `loadError()` is non-null if it rejected (e.g. an invalid apiKey).
10
+ *
11
+ * Deliberately NOT `@Injectable`: a decorator-free class keeps this package
12
+ * AOT-safe under a plain tsup build (no ngtsc / ng-packagr partial-Ivy metadata
13
+ * step). It is wired into DI by the factory in `provideSignals()`.
14
+ */
15
+ declare class SignalsClient {
16
+ private readonly agentState;
17
+ private readonly loadErrorState;
18
+ /** Resolved agent, or `null` until `SignalsAgent.load()` settles. */
19
+ readonly agent: Signal<SignalsAgent | null>;
20
+ /** Non-null if `SignalsAgent.load()` rejected. */
21
+ readonly loadError: Signal<Error | null>;
22
+ /**
23
+ * Resolves once `load()` has settled (agent set OR loadError set). Lets
24
+ * `injectVisitorData()` await readiness without an Angular `effect`, so the
25
+ * auto-identify fires exactly once regardless of change-detection timing.
26
+ */
27
+ readonly ready: Promise<void>;
28
+ /**
29
+ * @param opts forwarded verbatim to `SignalsAgent.load()`.
30
+ * @param browser whether we're running in a browser; `load()` only fires
31
+ * client-side so SSR / prerender never touches
32
+ * window/document/WebCrypto (the Angular analog of the Vue
33
+ * plugin's `typeof window` guard).
34
+ */
35
+ constructor(opts: AgentLoadOptions, browser: boolean);
36
+ }
37
+
38
+ /**
39
+ * Registers a single app-wide SignalsAgent — the idiomatic standalone-Angular
40
+ * entry point, analogous to React's `<SignalsProvider>` and Vue's
41
+ * `app.use(SignalsPlugin)`:
42
+ *
43
+ * ```ts
44
+ * bootstrapApplication(AppComponent, {
45
+ * providers: [
46
+ * provideSignals({ apiKey: "pk_live_...", endpoint: "https://ingest.example" }),
47
+ * ],
48
+ * });
49
+ * ```
50
+ *
51
+ * SSR-safe: the factory injects `PLATFORM_ID` and only lets the client call
52
+ * `SignalsAgent.load()` in a browser, so a server render / prerender never loads
53
+ * the agent.
54
+ *
55
+ * `opts` is snapshotted here at bootstrap; to swap apiKey/endpoint, re-bootstrap
56
+ * (same snapshot-at-init contract as the React/Vue wrappers).
57
+ */
58
+ declare function provideSignals(opts: AgentLoadOptions): EnvironmentProviders;
59
+
60
+ /**
61
+ * DI token the app-wide {@link SignalsClient} is registered under (by
62
+ * `provideSignals()`) and that `injectVisitorData()` resolves. Most consumers
63
+ * don't inject this directly — call `injectVisitorData()`. It is exported for
64
+ * advanced use (e.g. `inject(SIGNALS_CLIENT).agent()` to read the raw agent).
65
+ */
66
+ declare const SIGNALS_CLIENT: InjectionToken<SignalsClient>;
67
+
68
+ type InjectVisitorDataOptions = IdentifyOptions;
69
+ interface InjectVisitorDataResult {
70
+ /**
71
+ * Resolved visitor from `agent.identify()`. Under ADR §A2 the call is a single
72
+ * synchronous round-trip — `visitorId`/`confidence`/`identifiedAt` arrive
73
+ * together, no polling. A `Signal`, so read it as `data()` (in a template or a
74
+ * `computed`/`effect`).
75
+ */
76
+ data: Signal<IdentifyResult | undefined>;
77
+ /** True between call time and the identify() resolution (or `error`). */
78
+ isLoading: Signal<boolean>;
79
+ error: Signal<Error | null>;
80
+ /** Re-run `agent.identify()` (e.g. from a button click). */
81
+ refetch: () => Promise<void>;
82
+ }
83
+ /**
84
+ * Auto-identifies once the provider's agent is ready, then exposes the resolved
85
+ * visitor as Angular signals — the framework-native analog of React's
86
+ * `useVisitorData()` hook and Vue's `useVisitorData()` composable.
87
+ *
88
+ * Must be called in an injection context (a component/directive constructor or a
89
+ * field initializer, or inside `runInInjectionContext`) below `provideSignals()`.
90
+ */
91
+ declare function injectVisitorData(opts?: InjectVisitorDataOptions): InjectVisitorDataResult;
92
+
93
+ export { type InjectVisitorDataOptions, type InjectVisitorDataResult, SIGNALS_CLIENT, SignalsClient, injectVisitorData, provideSignals };
package/dist/index.js ADDED
@@ -0,0 +1,120 @@
1
+ // src/index.ts
2
+ import {
3
+ SdkError,
4
+ VERSION
5
+ } from "@signap/signals-web";
6
+
7
+ // src/client.ts
8
+ import { signal } from "@angular/core";
9
+ import { SignalsAgent } from "@signap/signals-web";
10
+ var SignalsClient = class {
11
+ agentState = signal(null);
12
+ loadErrorState = signal(null);
13
+ /** Resolved agent, or `null` until `SignalsAgent.load()` settles. */
14
+ agent = this.agentState.asReadonly();
15
+ /** Non-null if `SignalsAgent.load()` rejected. */
16
+ loadError = this.loadErrorState.asReadonly();
17
+ /**
18
+ * Resolves once `load()` has settled (agent set OR loadError set). Lets
19
+ * `injectVisitorData()` await readiness without an Angular `effect`, so the
20
+ * auto-identify fires exactly once regardless of change-detection timing.
21
+ */
22
+ ready;
23
+ /**
24
+ * @param opts forwarded verbatim to `SignalsAgent.load()`.
25
+ * @param browser whether we're running in a browser; `load()` only fires
26
+ * client-side so SSR / prerender never touches
27
+ * window/document/WebCrypto (the Angular analog of the Vue
28
+ * plugin's `typeof window` guard).
29
+ */
30
+ constructor(opts, browser) {
31
+ if (!browser) {
32
+ this.ready = Promise.resolve();
33
+ return;
34
+ }
35
+ this.ready = SignalsAgent.load(opts).then((loaded) => {
36
+ this.agentState.set(loaded);
37
+ }).catch((err) => {
38
+ this.loadErrorState.set(err instanceof Error ? err : new Error(String(err)));
39
+ });
40
+ }
41
+ };
42
+
43
+ // src/provide-signals.ts
44
+ import { isPlatformBrowser } from "@angular/common";
45
+ import {
46
+ PLATFORM_ID,
47
+ inject,
48
+ makeEnvironmentProviders
49
+ } from "@angular/core";
50
+
51
+ // src/tokens.ts
52
+ import { InjectionToken } from "@angular/core";
53
+ var SIGNALS_CLIENT = new InjectionToken("signap.signals.client");
54
+
55
+ // src/provide-signals.ts
56
+ function provideSignals(opts) {
57
+ return makeEnvironmentProviders([
58
+ {
59
+ provide: SIGNALS_CLIENT,
60
+ useFactory: () => new SignalsClient(opts, isPlatformBrowser(inject(PLATFORM_ID)))
61
+ }
62
+ ]);
63
+ }
64
+
65
+ // src/inject-visitor-data.ts
66
+ import { DestroyRef, assertInInjectionContext, inject as inject2, signal as signal2 } from "@angular/core";
67
+ function injectVisitorData(opts) {
68
+ assertInInjectionContext(injectVisitorData);
69
+ const client = inject2(SIGNALS_CLIENT, { optional: true });
70
+ if (!client) {
71
+ throw new Error(
72
+ "[@signap/signals-angular] injectVisitorData() requires provideSignals() in the application (or component) providers"
73
+ );
74
+ }
75
+ const data = signal2(void 0);
76
+ const error = signal2(null);
77
+ const isLoading = signal2(client.agent() === null && client.loadError() === null);
78
+ let token = { cancelled: false };
79
+ inject2(DestroyRef).onDestroy(() => {
80
+ token.cancelled = true;
81
+ });
82
+ const run = async () => {
83
+ const agent = client.agent();
84
+ if (!agent) {
85
+ const loadError = client.loadError();
86
+ if (loadError) {
87
+ error.set(loadError);
88
+ isLoading.set(false);
89
+ }
90
+ return;
91
+ }
92
+ token.cancelled = true;
93
+ const my = { cancelled: false };
94
+ token = my;
95
+ isLoading.set(true);
96
+ error.set(null);
97
+ data.set(void 0);
98
+ try {
99
+ const res = await agent.identify(opts);
100
+ if (my.cancelled) return;
101
+ data.set(res);
102
+ } catch (err) {
103
+ if (my.cancelled) return;
104
+ error.set(err instanceof Error ? err : new Error(String(err)));
105
+ } finally {
106
+ if (!my.cancelled) isLoading.set(false);
107
+ }
108
+ };
109
+ void client.ready.then(() => run());
110
+ return { data, isLoading, error, refetch: run };
111
+ }
112
+ export {
113
+ SIGNALS_CLIENT,
114
+ SdkError,
115
+ SignalsClient,
116
+ VERSION as WEB_SDK_VERSION,
117
+ injectVisitorData,
118
+ provideSignals
119
+ };
120
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/client.ts","../src/provide-signals.ts","../src/tokens.ts","../src/inject-visitor-data.ts"],"sourcesContent":["export {\n type AgentLoadOptions,\n type IdentifyOptions,\n type IdentifyResult,\n SdkError,\n type SdkErrorCode,\n VERSION as WEB_SDK_VERSION,\n} from \"@signap/signals-web\";\n\nexport { SignalsClient } from \"./client\";\nexport { provideSignals } from \"./provide-signals\";\nexport { SIGNALS_CLIENT } from \"./tokens\";\nexport {\n injectVisitorData,\n type InjectVisitorDataOptions,\n type InjectVisitorDataResult,\n} from \"./inject-visitor-data\";\n","import { type Signal, signal } from \"@angular/core\";\nimport { type AgentLoadOptions, SignalsAgent } from \"@signap/signals-web\";\n\n/**\n * Holds a single lazily-loaded SignalsAgent and exposes its readiness as Angular\n * signals — the framework-native analog of the Vue wrapper's provide/inject refs\n * and the React wrapper's context. `agent()` is `null` until `SignalsAgent.load()`\n * settles; `loadError()` is non-null if it rejected (e.g. an invalid apiKey).\n *\n * Deliberately NOT `@Injectable`: a decorator-free class keeps this package\n * AOT-safe under a plain tsup build (no ngtsc / ng-packagr partial-Ivy metadata\n * step). It is wired into DI by the factory in `provideSignals()`.\n */\nexport class SignalsClient {\n private readonly agentState = signal<SignalsAgent | null>(null);\n private readonly loadErrorState = signal<Error | null>(null);\n\n /** Resolved agent, or `null` until `SignalsAgent.load()` settles. */\n readonly agent: Signal<SignalsAgent | null> = this.agentState.asReadonly();\n /** Non-null if `SignalsAgent.load()` rejected. */\n readonly loadError: Signal<Error | null> = this.loadErrorState.asReadonly();\n /**\n * Resolves once `load()` has settled (agent set OR loadError set). Lets\n * `injectVisitorData()` await readiness without an Angular `effect`, so the\n * auto-identify fires exactly once regardless of change-detection timing.\n */\n readonly ready: Promise<void>;\n\n /**\n * @param opts forwarded verbatim to `SignalsAgent.load()`.\n * @param browser whether we're running in a browser; `load()` only fires\n * client-side so SSR / prerender never touches\n * window/document/WebCrypto (the Angular analog of the Vue\n * plugin's `typeof window` guard).\n */\n constructor(opts: AgentLoadOptions, browser: boolean) {\n if (!browser) {\n this.ready = Promise.resolve();\n return;\n }\n this.ready = SignalsAgent.load(opts)\n .then((loaded) => {\n this.agentState.set(loaded);\n })\n .catch((err: unknown) => {\n this.loadErrorState.set(err instanceof Error ? err : new Error(String(err)));\n });\n }\n}\n","import { isPlatformBrowser } from \"@angular/common\";\nimport {\n type EnvironmentProviders,\n PLATFORM_ID,\n inject,\n makeEnvironmentProviders,\n} from \"@angular/core\";\nimport type { AgentLoadOptions } from \"@signap/signals-web\";\nimport { SignalsClient } from \"./client\";\nimport { SIGNALS_CLIENT } from \"./tokens\";\n\n/**\n * Registers a single app-wide SignalsAgent — the idiomatic standalone-Angular\n * entry point, analogous to React's `<SignalsProvider>` and Vue's\n * `app.use(SignalsPlugin)`:\n *\n * ```ts\n * bootstrapApplication(AppComponent, {\n * providers: [\n * provideSignals({ apiKey: \"pk_live_...\", endpoint: \"https://ingest.example\" }),\n * ],\n * });\n * ```\n *\n * SSR-safe: the factory injects `PLATFORM_ID` and only lets the client call\n * `SignalsAgent.load()` in a browser, so a server render / prerender never loads\n * the agent.\n *\n * `opts` is snapshotted here at bootstrap; to swap apiKey/endpoint, re-bootstrap\n * (same snapshot-at-init contract as the React/Vue wrappers).\n */\nexport function provideSignals(opts: AgentLoadOptions): EnvironmentProviders {\n return makeEnvironmentProviders([\n {\n provide: SIGNALS_CLIENT,\n useFactory: () => new SignalsClient(opts, isPlatformBrowser(inject(PLATFORM_ID))),\n },\n ]);\n}\n","import { InjectionToken } from \"@angular/core\";\nimport type { SignalsClient } from \"./client\";\n\n/**\n * DI token the app-wide {@link SignalsClient} is registered under (by\n * `provideSignals()`) and that `injectVisitorData()` resolves. Most consumers\n * don't inject this directly — call `injectVisitorData()`. It is exported for\n * advanced use (e.g. `inject(SIGNALS_CLIENT).agent()` to read the raw agent).\n */\nexport const SIGNALS_CLIENT = new InjectionToken<SignalsClient>(\"signap.signals.client\");\n","import { DestroyRef, type Signal, assertInInjectionContext, inject, signal } from \"@angular/core\";\nimport type { IdentifyOptions, IdentifyResult } from \"@signap/signals-web\";\nimport { SIGNALS_CLIENT } from \"./tokens\";\n\nexport type InjectVisitorDataOptions = IdentifyOptions;\n\nexport interface InjectVisitorDataResult {\n /**\n * Resolved visitor from `agent.identify()`. Under ADR §A2 the call is a single\n * synchronous round-trip — `visitorId`/`confidence`/`identifiedAt` arrive\n * together, no polling. A `Signal`, so read it as `data()` (in a template or a\n * `computed`/`effect`).\n */\n data: Signal<IdentifyResult | undefined>;\n /** True between call time and the identify() resolution (or `error`). */\n isLoading: Signal<boolean>;\n error: Signal<Error | null>;\n /** Re-run `agent.identify()` (e.g. from a button click). */\n refetch: () => Promise<void>;\n}\n\n/**\n * Auto-identifies once the provider's agent is ready, then exposes the resolved\n * visitor as Angular signals — the framework-native analog of React's\n * `useVisitorData()` hook and Vue's `useVisitorData()` composable.\n *\n * Must be called in an injection context (a component/directive constructor or a\n * field initializer, or inside `runInInjectionContext`) below `provideSignals()`.\n */\nexport function injectVisitorData(opts?: InjectVisitorDataOptions): InjectVisitorDataResult {\n assertInInjectionContext(injectVisitorData);\n\n const client = inject(SIGNALS_CLIENT, { optional: true });\n if (!client) {\n throw new Error(\n \"[@signap/signals-angular] injectVisitorData() requires provideSignals() in the application (or component) providers\",\n );\n }\n\n const data = signal<IdentifyResult | undefined>(undefined);\n const error = signal<Error | null>(null);\n // Loading until the agent (or a load error) settles.\n const isLoading = signal(client.agent() === null && client.loadError() === null);\n\n // Supersede token so a slow response from a call that refetch() replaced (or a\n // response arriving after teardown) is discarded.\n let token = { cancelled: false };\n inject(DestroyRef).onDestroy(() => {\n token.cancelled = true;\n });\n\n const run = async (): Promise<void> => {\n const agent = client.agent();\n if (!agent) {\n const loadError = client.loadError();\n if (loadError) {\n error.set(loadError);\n isLoading.set(false);\n }\n return;\n }\n token.cancelled = true;\n const my = { cancelled: false };\n token = my;\n isLoading.set(true);\n error.set(null);\n data.set(undefined);\n try {\n const res = await agent.identify(opts);\n if (my.cancelled) return;\n data.set(res);\n } catch (err) {\n if (my.cancelled) return;\n error.set(err instanceof Error ? err : new Error(String(err)));\n } finally {\n if (!my.cancelled) isLoading.set(false);\n }\n };\n\n // Auto-run exactly once, after load() settles. `ready` resolves whether load()\n // succeeded or failed; even if it already resolved, `.then` defers to a\n // microtask so the returned signals are wired up before the first run().\n void client.ready.then(() => run());\n\n return { data, isLoading, error, refetch: run };\n}\n"],"mappings":";AAAA;AAAA,EAIE;AAAA,EAEW;AAAA,OACN;;;ACPP,SAAsB,cAAc;AACpC,SAAgC,oBAAoB;AAY7C,IAAM,gBAAN,MAAoB;AAAA,EACR,aAAa,OAA4B,IAAI;AAAA,EAC7C,iBAAiB,OAAqB,IAAI;AAAA;AAAA,EAGlD,QAAqC,KAAK,WAAW,WAAW;AAAA;AAAA,EAEhE,YAAkC,KAAK,eAAe,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMjE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAST,YAAY,MAAwB,SAAkB;AACpD,QAAI,CAAC,SAAS;AACZ,WAAK,QAAQ,QAAQ,QAAQ;AAC7B;AAAA,IACF;AACA,SAAK,QAAQ,aAAa,KAAK,IAAI,EAChC,KAAK,CAAC,WAAW;AAChB,WAAK,WAAW,IAAI,MAAM;AAAA,IAC5B,CAAC,EACA,MAAM,CAAC,QAAiB;AACvB,WAAK,eAAe,IAAI,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC;AAAA,IAC7E,CAAC;AAAA,EACL;AACF;;;AChDA,SAAS,yBAAyB;AAClC;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACNP,SAAS,sBAAsB;AASxB,IAAM,iBAAiB,IAAI,eAA8B,uBAAuB;;;ADsBhF,SAAS,eAAe,MAA8C;AAC3E,SAAO,yBAAyB;AAAA,IAC9B;AAAA,MACE,SAAS;AAAA,MACT,YAAY,MAAM,IAAI,cAAc,MAAM,kBAAkB,OAAO,WAAW,CAAC,CAAC;AAAA,IAClF;AAAA,EACF,CAAC;AACH;;;AEtCA,SAAS,YAAyB,0BAA0B,UAAAA,SAAQ,UAAAC,eAAc;AA6B3E,SAAS,kBAAkB,MAA0D;AAC1F,2BAAyB,iBAAiB;AAE1C,QAAM,SAASC,QAAO,gBAAgB,EAAE,UAAU,KAAK,CAAC;AACxD,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,OAAOC,QAAmC,MAAS;AACzD,QAAM,QAAQA,QAAqB,IAAI;AAEvC,QAAM,YAAYA,QAAO,OAAO,MAAM,MAAM,QAAQ,OAAO,UAAU,MAAM,IAAI;AAI/E,MAAI,QAAQ,EAAE,WAAW,MAAM;AAC/B,EAAAD,QAAO,UAAU,EAAE,UAAU,MAAM;AACjC,UAAM,YAAY;AAAA,EACpB,CAAC;AAED,QAAM,MAAM,YAA2B;AACrC,UAAM,QAAQ,OAAO,MAAM;AAC3B,QAAI,CAAC,OAAO;AACV,YAAM,YAAY,OAAO,UAAU;AACnC,UAAI,WAAW;AACb,cAAM,IAAI,SAAS;AACnB,kBAAU,IAAI,KAAK;AAAA,MACrB;AACA;AAAA,IACF;AACA,UAAM,YAAY;AAClB,UAAM,KAAK,EAAE,WAAW,MAAM;AAC9B,YAAQ;AACR,cAAU,IAAI,IAAI;AAClB,UAAM,IAAI,IAAI;AACd,SAAK,IAAI,MAAS;AAClB,QAAI;AACF,YAAM,MAAM,MAAM,MAAM,SAAS,IAAI;AACrC,UAAI,GAAG,UAAW;AAClB,WAAK,IAAI,GAAG;AAAA,IACd,SAAS,KAAK;AACZ,UAAI,GAAG,UAAW;AAClB,YAAM,IAAI,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC;AAAA,IAC/D,UAAE;AACA,UAAI,CAAC,GAAG,UAAW,WAAU,IAAI,KAAK;AAAA,IACxC;AAAA,EACF;AAKA,OAAK,OAAO,MAAM,KAAK,MAAM,IAAI,CAAC;AAElC,SAAO,EAAE,MAAM,WAAW,OAAO,SAAS,IAAI;AAChD;","names":["inject","signal","inject","signal"]}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@signap/signals-angular",
3
+ "version": "2.0.0",
4
+ "description": "Angular provider + inject() helper wrapper for @signap/signals-web",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "sideEffects": false,
20
+ "peerDependencies": {
21
+ "@angular/common": ">=17 <21",
22
+ "@angular/core": ">=17 <21"
23
+ },
24
+ "dependencies": {
25
+ "@signap/signals-web": "2.2.0"
26
+ },
27
+ "devDependencies": {
28
+ "@angular/common": "^19.0.0",
29
+ "@angular/compiler": "^19.0.0",
30
+ "@angular/core": "^19.0.0",
31
+ "@angular/platform-browser": "^19.0.0",
32
+ "@angular/platform-browser-dynamic": "^19.0.0",
33
+ "@biomejs/biome": "^1.9.0",
34
+ "happy-dom": "^15.11.0",
35
+ "rxjs": "^7.8.0",
36
+ "tsup": "^8.3.0",
37
+ "typescript": "^5.7.0",
38
+ "vitest": "^2.1.0",
39
+ "zone.js": "^0.15.0"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "license": "Apache-2.0",
45
+ "scripts": {
46
+ "build": "tsup",
47
+ "test": "vitest run",
48
+ "typecheck": "tsc --noEmit",
49
+ "lint": "biome check src test"
50
+ }
51
+ }