@supermetry/node 0.1.0 → 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.
package/README.md CHANGED
@@ -15,14 +15,13 @@ import { Supermetry } from "@supermetry/node";
15
15
 
16
16
  const supermetry = new Supermetry({
17
17
  site: "your-site-id",
18
- host: "https://analytics.example.com",
19
- url: "https://shop.example.com/", // optional default page URL
18
+ url: "https://shop.supermetry.com/", // optional default page URL
20
19
  onError: (error) => console.error(error),
21
20
  });
22
21
 
23
22
  // Fire-and-forget: never throws, never rejects.
24
23
  supermetry.track("Signup", {
25
- url: "https://shop.example.com/signup",
24
+ url: "https://shop.supermetry.com/signup",
26
25
  props: { plan: "pro", seats: 3 },
27
26
  revenue: { amount: "49.90", currency: "USD" },
28
27
  profileId: "user_42",
@@ -44,10 +43,10 @@ Every call returns a `Promise<SendResult>` (`{ ok, status?, error? }`) that neve
44
43
  | option | default | |
45
44
  |---|---|---|
46
45
  | `site` | required | Public site ID |
47
- | `host` | required | Supermetry origin; events go to `host + /api/public/v1/events` |
46
+ | `host` | `https://app.supermetry.com` | Supermetry origin; set it when self-hosting. Events go to `host + /api/public/v1/events` |
48
47
  | `endpoint` | | Full endpoint URL override |
49
48
  | `url` | | Default event URL; base for relative event URLs |
50
- | `userAgent` | `supermetry-node/0.1.0` | UA when the call does not forward a visitor UA |
49
+ | `userAgent` | `supermetry-node/0.2.0` | UA when the call does not forward a visitor UA |
51
50
  | `disabled` | `false` | Send nothing |
52
51
  | `onError` | no-op | Receives a `SupermetryError` (validation, network, HTTP status) |
53
52
  | `fetch` | `globalThis.fetch` | Custom fetch |
@@ -59,7 +58,7 @@ Per-call context (`track`, `pageview`, third argument of `identify`): `url`, `re
59
58
 
60
59
  ## Notes
61
60
 
62
- - **User-Agent matters.** Generic HTTP-client UAs (`node-fetch`, `axios`, `undici`…) are filtered as bots. Forward the visitor's UA when you have it; otherwise the SDK sends `supermetry-node/0.1.0`.
61
+ - **User-Agent matters.** Generic HTTP-client UAs (`node-fetch`, `axios`, `undici`…) are filtered as bots. Forward the visitor's UA when you have it; otherwise the SDK sends `supermetry-node/0.2.0`.
63
62
  - **Visitor IP** is sent as `X-Forwarded-For`. The Supermetry server only trusts it from addresses listed in `SUPERMETRY_TRUSTED_PROXIES`; add your app servers there, or every event counts as one visitor.
64
63
  - **Strict origin**: turn it off for sites that receive server-side events (or set `sendOrigin: true`).
65
64
  - **`identify` does not store the profile ID.** A server client is shared across visitors, so a stored ID would leak between users. Pass `profileId` on every call for identified users. `identify` sends the traits (string values, max 20; invalid traits are dropped locally since the server rejects the whole event otherwise).
package/dist/index.cjs CHANGED
@@ -39,6 +39,7 @@ var __export = (target, all) => {
39
39
  // src/index.ts
40
40
  var exports_src = {};
41
41
  __export(exports_src, {
42
+ DEFAULT_HOST: () => DEFAULT_HOST,
42
43
  DEFAULT_USER_AGENT: () => DEFAULT_USER_AGENT,
43
44
  EVENTS_PATH: () => EVENTS_PATH,
44
45
  Supermetry: () => Supermetry,
@@ -171,9 +172,10 @@ function sanitizeRevenue(revenue) {
171
172
  }
172
173
 
173
174
  // src/index.ts
174
- var VERSION = "0.1.0";
175
+ var VERSION = "0.2.1";
175
176
  var DEFAULT_USER_AGENT = `supermetry-node/${VERSION}`;
176
177
  var EVENTS_PATH = "/api/public/v1/events";
178
+ var DEFAULT_HOST = "https://app.supermetry.com";
177
179
 
178
180
  class SupermetryError extends Error {
179
181
  status;
@@ -200,12 +202,12 @@ class Supermetry {
200
202
  if (!options || typeof options.site !== "string" || options.site === "") {
201
203
  throw new TypeError("@supermetry/node: `site` is required");
202
204
  }
203
- if (!options.endpoint && (typeof options.host !== "string" || options.host === "")) {
204
- throw new TypeError("@supermetry/node: `host` is required");
205
+ if (!options.endpoint && options.host !== undefined && (typeof options.host !== "string" || options.host === "")) {
206
+ throw new TypeError("@supermetry/node: `host` must be a non-empty string");
205
207
  }
206
208
  this.options = options;
207
209
  this.site = options.site;
208
- this.endpoint = options.endpoint ?? options.host.replace(/\/+$/, "") + EVENTS_PATH;
210
+ this.endpoint = options.endpoint ?? (options.host ?? DEFAULT_HOST).replace(/\/+$/, "") + EVENTS_PATH;
209
211
  }
210
212
  track(name, options = {}) {
211
213
  return this.capture(() => {
package/dist/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import { type PropValue, type Props, type Revenue, type Traits } from "./validate.js";
2
2
  export type { PropValue, Props, Revenue, Traits } from "./validate.js";
3
3
  export { sanitizeProps, sanitizeRevenue, sanitizeTraits } from "./validate.js";
4
- export declare const VERSION = "0.1.0";
5
- export declare const DEFAULT_USER_AGENT = "supermetry-node/0.1.0";
4
+ export declare const VERSION = "0.2.1";
5
+ export declare const DEFAULT_USER_AGENT = "supermetry-node/0.2.1";
6
6
  export declare const EVENTS_PATH = "/api/public/v1/events";
7
+ /** Supermetry Cloud, used when `host` is omitted. */
8
+ export declare const DEFAULT_HOST = "https://app.supermetry.com";
7
9
  /** The JSON body sent to `POST /api/public/v1/events`. */
8
10
  export interface EventPayload {
9
11
  v: 1;
@@ -25,13 +27,13 @@ export interface EventPayload {
25
27
  export interface SupermetryOptions {
26
28
  /** Public site ID. */
27
29
  site: string;
28
- /** Supermetry origin, e.g. `https://analytics.example.com`. */
29
- host: string;
30
+ /** Supermetry origin. Defaults to Supermetry Cloud (`https://app.supermetry.com`); set it when self-hosting. */
31
+ host?: string;
30
32
  /** Full events endpoint; defaults to `host + "/api/public/v1/events"`. */
31
33
  endpoint?: string;
32
34
  /** Default page URL for events that do not pass one. Relative event URLs resolve against it. */
33
35
  url?: string;
34
- /** User-Agent used when no visitor UA is forwarded. Defaults to `supermetry-node/0.1.0`. */
36
+ /** User-Agent used when no visitor UA is forwarded. Defaults to `supermetry-node/0.2.1`. */
35
37
  userAgent?: string;
36
38
  /** Send nothing (every call resolves immediately). */
37
39
  disabled?: boolean;
package/dist/index.js CHANGED
@@ -119,9 +119,10 @@ function sanitizeRevenue(revenue) {
119
119
  }
120
120
 
121
121
  // src/index.ts
122
- var VERSION = "0.1.0";
122
+ var VERSION = "0.2.1";
123
123
  var DEFAULT_USER_AGENT = `supermetry-node/${VERSION}`;
124
124
  var EVENTS_PATH = "/api/public/v1/events";
125
+ var DEFAULT_HOST = "https://app.supermetry.com";
125
126
 
126
127
  class SupermetryError extends Error {
127
128
  status;
@@ -148,12 +149,12 @@ class Supermetry {
148
149
  if (!options || typeof options.site !== "string" || options.site === "") {
149
150
  throw new TypeError("@supermetry/node: `site` is required");
150
151
  }
151
- if (!options.endpoint && (typeof options.host !== "string" || options.host === "")) {
152
- throw new TypeError("@supermetry/node: `host` is required");
152
+ if (!options.endpoint && options.host !== undefined && (typeof options.host !== "string" || options.host === "")) {
153
+ throw new TypeError("@supermetry/node: `host` must be a non-empty string");
153
154
  }
154
155
  this.options = options;
155
156
  this.site = options.site;
156
- this.endpoint = options.endpoint ?? options.host.replace(/\/+$/, "") + EVENTS_PATH;
157
+ this.endpoint = options.endpoint ?? (options.host ?? DEFAULT_HOST).replace(/\/+$/, "") + EVENTS_PATH;
157
158
  }
158
159
  track(name, options = {}) {
159
160
  return this.capture(() => {
@@ -300,6 +301,7 @@ function createSupermetry(options) {
300
301
  return new Supermetry(options);
301
302
  }
302
303
  export {
304
+ DEFAULT_HOST,
303
305
  DEFAULT_USER_AGENT,
304
306
  EVENTS_PATH,
305
307
  Supermetry,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supermetry/node",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Server-side Node.js SDK for Supermetry self-hosted web analytics",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -8,7 +8,7 @@
8
8
  "url": "git+https://github.com/velixio/supermetry.git",
9
9
  "directory": "sdk/node"
10
10
  },
11
- "homepage": "https://github.com/velixio/supermetry/tree/main/sdk/node#readme",
11
+ "homepage": "https://supermetry.com",
12
12
  "bugs": {
13
13
  "url": "https://github.com/velixio/supermetry/issues"
14
14
  },