@nextlytics/core 0.2.1-canary.62 → 0.2.1

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.
@@ -23,14 +23,15 @@ __export(segment_exports, {
23
23
  module.exports = __toCommonJS(segment_exports);
24
24
  function segmentBackend(config) {
25
25
  const host = (config.host ?? "https://api.segment.io").replace(/\/$/, "");
26
- async function send(batch) {
27
- const res = await fetch(`${host}/v1/batch`, {
26
+ const authHeader = "Basic " + btoa(config.writeKey + ":");
27
+ async function send(endpoint, payload) {
28
+ const res = await fetch(`${host}${endpoint}`, {
28
29
  method: "POST",
29
30
  headers: {
30
31
  "Content-Type": "application/json",
31
- "X-Write-Key": config.writeKey
32
+ Authorization: authHeader
32
33
  },
33
- body: JSON.stringify({ batch })
34
+ body: JSON.stringify(payload)
34
35
  });
35
36
  if (!res.ok) {
36
37
  const text = await res.text();
@@ -79,18 +80,26 @@ function segmentBackend(config) {
79
80
  async onEvent(event) {
80
81
  const context = buildContext(event);
81
82
  const properties = buildProperties(event);
82
- const basePayload = {
83
- messageId: event.eventId,
84
- anonymousId: event.anonymousUserId,
85
- userId: event.userContext?.userId,
86
- timestamp: event.collectedAt,
87
- context,
88
- properties
89
- };
90
83
  if (event.type === "pageView") {
91
- await send([{ type: "page", name: event.serverContext.path, ...basePayload }]);
84
+ await send("/v1/page", {
85
+ messageId: event.eventId,
86
+ anonymousId: event.anonymousUserId,
87
+ userId: event.userContext?.userId,
88
+ name: event.serverContext.path,
89
+ timestamp: event.collectedAt,
90
+ context,
91
+ properties
92
+ });
92
93
  } else {
93
- await send([{ type: "track", event: event.type, ...basePayload }]);
94
+ await send("/v1/track", {
95
+ messageId: event.eventId,
96
+ anonymousId: event.anonymousUserId,
97
+ userId: event.userContext?.userId,
98
+ event: event.type,
99
+ timestamp: event.collectedAt,
100
+ context,
101
+ properties
102
+ });
94
103
  }
95
104
  },
96
105
  updateEvent() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextlytics/core",
3
- "version": "0.2.1-canary.62",
3
+ "version": "0.2.1",
4
4
  "description": "Analytics library for Next.js",
5
5
  "license": "MIT",
6
6
  "repository": {