@moblog/browser 0.1.0 → 0.1.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 +2 -2
- package/dist/client.d.ts +1 -1
- package/dist/index.js +13 -2
- package/dist/types.d.ts +2 -0
- package/dist/util.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -79,6 +79,6 @@ other.log("warn", "from a widget");
|
|
|
79
79
|
|
|
80
80
|
Published by hand, from an up-to-date `main`, by a member of the npm organization `moblog`:
|
|
81
81
|
|
|
82
|
-
1. Set the version in `package.json` and `VERSION` in `src/client.ts` (a test checks they match), and merge that.
|
|
82
|
+
1. Set the version in `package.json` and `VERSION` in `src/client.ts` (a test checks they match), add it to `CHANGELOG.md`, and merge that.
|
|
83
83
|
2. `npm login` (once), then from `packages/browser`: `npm publish`. It runs the type check, the tests, the build and the size check first (`prepublishOnly`); `npm publish --dry-run` shows what would be sent.
|
|
84
|
-
3. Tag the commit: `git tag browser-v0.1.
|
|
84
|
+
3. Tag the commit: `git tag browser-v0.1.1 && git push origin browser-v0.1.1`.
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Attributes, Level, Options } from "./types";
|
|
2
|
-
export declare const VERSION = "0.1.
|
|
2
|
+
export declare const VERSION = "0.1.1";
|
|
3
3
|
/** A moblog client: queues events, sends them in batches, and keeps them until they are stored. */
|
|
4
4
|
export declare class Client {
|
|
5
5
|
private readonly o;
|
package/dist/index.js
CHANGED
|
@@ -2,8 +2,18 @@
|
|
|
2
2
|
/** A random UUID; crypto.randomUUID needs a secure context, getRandomValues doesn't. */
|
|
3
3
|
function uuid() {
|
|
4
4
|
if (typeof crypto.randomUUID === "function") return crypto.randomUUID();
|
|
5
|
+
return format(crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16)), 64);
|
|
6
|
+
}
|
|
7
|
+
/** A UUIDv7: the time in Unix milliseconds, then random bits, so IDs sort by when they were made. */
|
|
8
|
+
function uuid7(ms) {
|
|
5
9
|
const b = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16));
|
|
6
|
-
|
|
10
|
+
const t = Number.isFinite(ms) && ms > 0 ? Math.floor(ms) : 0;
|
|
11
|
+
for (let i = 0; i < 6; i++) b[i] = Math.floor(t / 2 ** (40 - 8 * i)) % 256;
|
|
12
|
+
return format(b, 112);
|
|
13
|
+
}
|
|
14
|
+
/** 16 bytes as a UUID of a version (0x40, 0x70), with RFC 9562's variant. */
|
|
15
|
+
function format(b, version) {
|
|
16
|
+
b[6] = b[6] & 15 | version;
|
|
7
17
|
b[8] = b[8] & 63 | 128;
|
|
8
18
|
const h = Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
|
|
9
19
|
return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
|
|
@@ -55,7 +65,7 @@ function text(v) {
|
|
|
55
65
|
}
|
|
56
66
|
//#endregion
|
|
57
67
|
//#region src/client.ts
|
|
58
|
-
var VERSION = "0.1.
|
|
68
|
+
var VERSION = "0.1.1";
|
|
59
69
|
var LEVELS = [
|
|
60
70
|
"trace",
|
|
61
71
|
"debug",
|
|
@@ -158,6 +168,7 @@ var Client = class {
|
|
|
158
168
|
e = null;
|
|
159
169
|
}
|
|
160
170
|
if (!e) return;
|
|
171
|
+
if (!e.event_id) e.event_id = uuid7(e.timestamp);
|
|
161
172
|
try {
|
|
162
173
|
JSON.stringify(e);
|
|
163
174
|
} catch {
|
package/dist/types.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export type Attributes = Record<string, unknown>;
|
|
|
5
5
|
export interface MoblogEvent {
|
|
6
6
|
/** Unix milliseconds. */
|
|
7
7
|
timestamp: number;
|
|
8
|
+
/** A UUID the SDK gives the event after beforeSend (unless it set one): ingest stores an event once by it. */
|
|
9
|
+
event_id?: string;
|
|
8
10
|
level: Level;
|
|
9
11
|
message: string;
|
|
10
12
|
session_id: string;
|
package/dist/util.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** A random UUID; crypto.randomUUID needs a secure context, getRandomValues doesn't. */
|
|
2
2
|
export declare function uuid(): string;
|
|
3
|
+
/** A UUIDv7: the time in Unix milliseconds, then random bits, so IDs sort by when they were made. */
|
|
4
|
+
export declare function uuid7(ms: number): string;
|
|
3
5
|
/** Storage that may be missing (privacy modes, sandboxed frames) or full: failures are ignored. */
|
|
4
6
|
export declare function store(kind: "localStorage" | "sessionStorage", on: boolean): {
|
|
5
7
|
get(k: string): string | null;
|