@nexly/core 0.5.0 → 0.6.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
@@ -23,6 +23,16 @@ nexly.event({ name: 'click', type: 'engagement', data: { id: 'x' } })
23
23
 
24
24
  Constructor options use the `NexlyInit` type from the published typings.
25
25
 
26
+ ### Singleton
27
+
28
+ When using a provider (`@nexly/react-web` or `@nexly/next`), the client is also available as a singleton — useful for plain functions outside the React tree:
29
+
30
+ ```ts
31
+ import { Nexly } from '@nexly/core'
32
+
33
+ Nexly.getInstance()?.event({ name: 'click', type: 'engagement' })
34
+ ```
35
+
26
36
  ## API
27
37
 
28
38
  The package ships `.d.ts` files; use your editor or `node_modules` typings for the full export list.
package/dist/nexly.d.ts CHANGED
@@ -16,6 +16,14 @@ export type NexlyEventInput = {
16
16
  * High-level browser client: page views, custom events, optional engagement auto-tracking.
17
17
  */
18
18
  export declare class Nexly {
19
+ private static instance;
20
+ /**
21
+ * Creates (or replaces) the global singleton and returns it.
22
+ * The provider calls this; plain functions use {@link getInstance}.
23
+ */
24
+ static init(options: NexlyInit): Nexly;
25
+ /** Returns the singleton created by {@link init}, or `null` if not yet initialized. */
26
+ static getInstance(): Nexly | null;
19
27
  readonly collectUrl: string;
20
28
  readonly appId: string;
21
29
  readonly key: string;
@@ -1 +1 @@
1
- {"version":3,"file":"nexly.d.ts","sourceRoot":"","sources":["../src/nexly.ts"],"names":[],"mappings":"AAMA,kGAAkG;AAClG,MAAM,MAAM,SAAS,GAAG;IACtB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,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C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;gBAER,IAAI,EAAE,SAAS;IAM3B,OAAO,KAAK,WAAW,GAMtB;IAED,OAAO,CAAC,cAAc;IAOtB;;OAEG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO;IAIhC;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO;IActC;;OAEG;IACH,eAAe,IAAI,MAAM,IAAI;CAG9B"}
package/dist/nexly.js CHANGED
@@ -6,6 +6,19 @@ const DEFAULT_COLLECT_URL = 'https://gate.nexly.to/v1/collect';
6
6
  * High-level browser client: page views, custom events, optional engagement auto-tracking.
7
7
  */
8
8
  export class Nexly {
9
+ static instance = null;
10
+ /**
11
+ * Creates (or replaces) the global singleton and returns it.
12
+ * The provider calls this; plain functions use {@link getInstance}.
13
+ */
14
+ static init(options) {
15
+ Nexly.instance = new Nexly(options);
16
+ return Nexly.instance;
17
+ }
18
+ /** Returns the singleton created by {@link init}, or `null` if not yet initialized. */
19
+ static getInstance() {
20
+ return Nexly.instance;
21
+ }
9
22
  collectUrl;
10
23
  appId;
11
24
  key;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexly/core",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Nexly browser ingest core (sendBeacon, Nexly client, context, engagement)",
5
5
  "license": "MIT",
6
6
  "keywords": [