@nexly/react-native 0.9.0 → 0.10.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.
@@ -1,6 +1,7 @@
1
1
  import { type IngestCredentials } from '@nexly/core';
2
2
  type EngagementCreds = {
3
3
  collectUrl: string;
4
+ client?: string;
4
5
  } & IngestCredentials;
5
6
  type StopFn = () => void;
6
7
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"engagement.d.ts","sourceRoot":"","sources":["../src/engagement.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAQzE,KAAK,eAAe,GAAG;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG,iBAAiB,CAAA;AAoBjE,KAAK,MAAM,GAAG,MAAM,IAAI,CAAA;AAExB;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAyCtE"}
1
+ {"version":3,"file":"engagement.d.ts","sourceRoot":"","sources":["../src/engagement.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAQzE,KAAK,eAAe,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,iBAAiB,CAAA;AAqBlF,KAAK,MAAM,GAAG,MAAM,IAAI,CAAA;AAExB;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAyCtE"}
@@ -8,6 +8,7 @@ const KEEPALIVE_INTERVAL_MS = 60_000;
8
8
  function send(creds, eventName, eventType, data, sessionContext) {
9
9
  const payload = buildCollectPayload({
10
10
  credentials: { appId: creds.appId, apiToken: creds.apiToken },
11
+ client: creds.client,
11
12
  eventName,
12
13
  eventType,
13
14
  context: collectEventMeta(),
@@ -1 +1 @@
1
- {"version":3,"file":"nexly.d.ts","source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I,EAAE,MAAM,GAAG,OAAO;cAKd,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO;cAIpD,mBAAmB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;cAI9C,qBAAqB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAI1D,cAAc,IAAI,MAAM;IAIxB,eAAe,IAAI,MAAM,IAAI;CASvC"}
package/dist/nexly.js CHANGED
@@ -1,8 +1,12 @@
1
1
  import { NexlyBase } from '@nexly/core';
2
+ import { Platform } from 'react-native';
2
3
  import { collectEventMeta, collectSessionMeta } from './device-meta.js';
3
4
  import { startEngagementTracking } from './engagement.js';
4
5
  import { prewarmIds } from './session.js';
5
6
  import { sendPayloadFetch } from './transport.js';
7
+ function defaultClient() {
8
+ return `rn-${Platform.OS}`;
9
+ }
6
10
  /**
7
11
  * React Native Nexly client. Implements transport via `fetch({ keepalive: true })`
8
12
  * and metadata via `Platform` / `Dimensions` / `AsyncStorage`.
@@ -17,7 +21,7 @@ export class Nexly extends NexlyBase {
17
21
  * `NexlyProvider` awaits this before exposing a client via context.
18
22
  */
19
23
  static async init(options) {
20
- const instance = new Nexly(options);
24
+ const instance = new Nexly({ ...options, client: options.client ?? defaultClient() });
21
25
  Nexly.setInstance(instance);
22
26
  if (instance.appId && instance.key) {
23
27
  await prewarmIds();
@@ -60,6 +64,7 @@ export class Nexly extends NexlyBase {
60
64
  collectUrl: this.collectUrl,
61
65
  appId: this.appId,
62
66
  apiToken: this.key,
67
+ client: this.client,
63
68
  });
64
69
  }
65
70
  }
@@ -2,6 +2,11 @@
2
2
  * Fire-and-forget JSON POST to the collector. Uses `fetch` with `keepalive: true`
3
3
  * so requests survive app backgrounding on supported runtimes; errors are swallowed
4
4
  * (analytics must not crash the host app).
5
+ *
6
+ * Sets a synthetic `Origin: nexlyrn://device` header — React Native does not send
7
+ * `Origin` by default, but the collector enforces an allowlist; add this origin
8
+ * once per app in the dashboard to authorize native events.
5
9
  */
10
+ export declare const NATIVE_ORIGIN = "nexlyrn://device";
6
11
  export declare function sendPayloadFetch(url: string, payload: Record<string, unknown>): boolean;
7
12
  //# sourceMappingURL=transport.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAavF"}
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,qBAAqB,CAAA;AAE/C,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAgBvF"}
package/dist/transport.js CHANGED
@@ -2,14 +2,22 @@
2
2
  * Fire-and-forget JSON POST to the collector. Uses `fetch` with `keepalive: true`
3
3
  * so requests survive app backgrounding on supported runtimes; errors are swallowed
4
4
  * (analytics must not crash the host app).
5
+ *
6
+ * Sets a synthetic `Origin: nexlyrn://device` header — React Native does not send
7
+ * `Origin` by default, but the collector enforces an allowlist; add this origin
8
+ * once per app in the dashboard to authorize native events.
5
9
  */
10
+ export const NATIVE_ORIGIN = 'nexlyrn://device';
6
11
  export function sendPayloadFetch(url, payload) {
7
12
  if (!url)
8
13
  return false;
9
14
  try {
10
15
  void fetch(url, {
11
16
  method: 'POST',
12
- headers: { 'Content-Type': 'application/json' },
17
+ headers: {
18
+ 'Content-Type': 'application/json',
19
+ Origin: NATIVE_ORIGIN,
20
+ },
13
21
  body: JSON.stringify(payload),
14
22
  keepalive: true,
15
23
  }).catch(() => { });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexly/react-native",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "React Native bindings for Nexly: fetch transport, AsyncStorage IDs, AppState engagement on top of @nexly/core",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -43,7 +43,7 @@
43
43
  "react-native": ">=0.72.0"
44
44
  },
45
45
  "dependencies": {
46
- "@nexly/core": "0.9.0"
46
+ "@nexly/core": "0.10.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@react-native-async-storage/async-storage": "^2.1.2",