@pmate/log-sdk 0.2.2 → 0.3.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/dist/browser.d.ts CHANGED
@@ -11,6 +11,7 @@ export type BrowserLogger = ReturnType<typeof createLogger>;
11
11
  export declare function createLogger(options: BrowserLoggerOptions): {
12
12
  captureError(error: unknown, context?: Parameters<typeof errorInput>[1]): void;
13
13
  getContext: () => LogContext;
14
+ track(name: string, properties?: Record<string, unknown>): void;
14
15
  setProfileId(value?: string | null): void;
15
16
  append(topic: string, input: LogInput | string): void;
16
17
  /** Explicit request wrapper: never patches global fetch or decorates unlisted origins. */
package/dist/browser.js CHANGED
@@ -66,6 +66,10 @@ export function createLogger(options) {
66
66
  this.append("error", errorInput(error, context));
67
67
  },
68
68
  getContext: context,
69
+ track(name, properties = {}) { if (!closed) {
70
+ access.touch();
71
+ transport.track(name, properties);
72
+ } },
69
73
  setProfileId(value) {
70
74
  if (closed)
71
75
  return;
package/dist/node.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { errorInput } from "./errors.js";
2
2
  import { type LogContext, type LogEntry, type LogInput } from "./shared.js";
3
3
  export type LogBatch = {
4
+ category: "app";
4
5
  serviceId: string;
5
6
  environment: string;
6
7
  topic: string;
package/dist/node.js CHANGED
@@ -56,7 +56,7 @@ export function createLogger(options) {
56
56
  budget -= selected.length;
57
57
  const controller = new AbortController();
58
58
  let timeout;
59
- const writing = Promise.resolve().then(() => sink({ serviceId: options.serviceId, environment: options.environment, topic, items: selected.map(item => item.entry) }, controller.signal));
59
+ const writing = Promise.resolve().then(() => sink({ category: "app", serviceId: options.serviceId, environment: options.environment, topic, items: selected.map(item => item.entry) }, controller.signal));
60
60
  void writing.then(() => { stalled = false; }, () => { stalled = false; });
61
61
  try {
62
62
  await Promise.race([writing, new Promise((_, reject) => {
package/dist/react.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Component, type ErrorInfo, type ReactNode } from "react";
2
2
  import { type BrowserLogger, type BrowserLoggerOptions } from "./browser.js";
3
- export type ReactLogger = Pick<BrowserLogger, "append" | "fetch" | "flush" | "captureError">;
3
+ export type ReactLogger = Pick<BrowserLogger, "append" | "fetch" | "flush" | "captureError" | "track">;
4
4
  /** Keep options stable for the Provider's lifetime. Update identity through profileId. */
5
5
  export declare function LogProvider({ options, profileId, children }: {
6
6
  options: Omit<BrowserLoggerOptions, "profileId">;
package/dist/react.js CHANGED
@@ -16,6 +16,11 @@ export function LogProvider({ options, profileId, children }) {
16
16
  const buffered = useRef([]);
17
17
  identity.current = profileId;
18
18
  const value = useMemo(() => ({
19
+ track(name, properties) {
20
+ if (!/^[a-zA-Z0-9_.-]{1,64}$/.test(name))
21
+ throw Error("Invalid behavior event");
22
+ void ready.promise.then(instance => { instance?.setProfileId(identity.current); instance?.track(name, properties); });
23
+ },
19
24
  captureError(error, context) { value.append("error", errorInput(error, context)); },
20
25
  append(topic, input) {
21
26
  if (logger.current) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/log-sdk",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "PMate browser, React and Node logs with access and profile context",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -27,7 +27,7 @@
27
27
  }
28
28
  },
29
29
  "dependencies": {
30
- "@pmate/log": "0.1.2"
30
+ "@pmate/log": "0.2.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "react": ">=18"