@nexly/core 0.4.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 +10 -0
- package/dist/nexly.d.ts +10 -1
- package/dist/nexly.d.ts.map +1 -1
- package/dist/nexly.js +15 -1
- package/package.json +1 -1
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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** Options for {@link Nexly}. `key` is the ingest API token (sent as `api_token` on the wire). */
|
|
2
2
|
export type NexlyInit = {
|
|
3
|
-
|
|
3
|
+
/** Override the ingest endpoint. Defaults to the Nexly production gateway. */
|
|
4
|
+
collectUrl?: string;
|
|
4
5
|
appId: string;
|
|
5
6
|
key: string;
|
|
6
7
|
};
|
|
@@ -15,6 +16,14 @@ export type NexlyEventInput = {
|
|
|
15
16
|
* High-level browser client: page views, custom events, optional engagement auto-tracking.
|
|
16
17
|
*/
|
|
17
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;
|
|
18
27
|
readonly collectUrl: string;
|
|
19
28
|
readonly appId: string;
|
|
20
29
|
readonly key: string;
|
package/dist/nexly.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nexly.d.ts","sourceRoot":"","sources":["../src/nexly.ts"],"names":[],"mappings":"
|
|
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,CAAC,CAAA;IAC9B,oGAAoG;IACpG,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAClC,CAAA;AAED;;GAEG;AACH,qBAAa,KAAK;IAChB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAqB;IAE5C;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,GAAG,KAAK;IAKtC,uFAAuF;IACvF,MAAM,CAAC,WAAW,IAAI,KAAK,GAAG,IAAI;IAIlC,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
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
import { collectBrowserMeta } from './browser-meta.js';
|
|
2
2
|
import { sendBeaconCollect } from './collect.js';
|
|
3
3
|
import { getDefaultPathname, sendPageViewBeacon, startEngagementTracking } from './events/index.js';
|
|
4
|
+
const DEFAULT_COLLECT_URL = 'https://gate.nexly.to/v1/collect';
|
|
4
5
|
/**
|
|
5
6
|
* High-level browser client: page views, custom events, optional engagement auto-tracking.
|
|
6
7
|
*/
|
|
7
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
|
+
}
|
|
8
22
|
collectUrl;
|
|
9
23
|
appId;
|
|
10
24
|
key;
|
|
11
25
|
constructor(init) {
|
|
12
|
-
this.collectUrl = init.collectUrl.trim();
|
|
26
|
+
this.collectUrl = (init.collectUrl ?? DEFAULT_COLLECT_URL).trim();
|
|
13
27
|
this.appId = init.appId.trim();
|
|
14
28
|
this.key = init.key.trim();
|
|
15
29
|
}
|