@account-kit/logging 4.59.1 → 4.60.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/dist/esm/index.js CHANGED
@@ -1,18 +1,8 @@
1
- import { createClientLogger } from "./client.js";
2
1
  import { noopLogger } from "./noop.js";
3
- import { createServerLogger } from "./server.js";
4
- export function createLogger(context) {
5
- const innerLogger = (() => {
6
- try {
7
- return typeof window === "undefined"
8
- ? createServerLogger(context)
9
- : createClientLogger(context);
10
- }
11
- catch (e) {
12
- console.error("[Safe to ignore] failed to initialize metrics", e);
13
- return noopLogger;
14
- }
15
- })();
2
+ export function createLogger(_context) {
3
+ // We are currently not logging events from the SDK (as Sept 2, 2025), so
4
+ // a no-op logger is always used. This will be further explored in v5.
5
+ const innerLogger = noopLogger;
16
6
  const logger = {
17
7
  ...innerLogger,
18
8
  profiled(name, func) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AASjD,MAAM,UAAU,YAAY,CAAC,OAAsB;IACjD,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE;QACxB,IAAI,CAAC;YACH,OAAO,OAAO,MAAM,KAAK,WAAW;gBAClC,CAAC,CAAC,kBAAkB,CAAC,OAAO,CAAC;gBAC7B,CAAC,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,+CAA+C,EAAE,CAAC,CAAC,CAAC;YAClE,OAAO,UAAU,CAAC;QACpB,CAAC;IACH,CAAC,CAAC,EAAE,CAAC;IAEL,MAAM,MAAM,GAAgB;QAC1B,GAAG,WAAW;QACd,QAAQ,CACN,IAAY,EACZ,IAA8B;YAE9B,OAAO,UAAqB,GAAG,IAAW;gBACxC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;gBACzB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBACtC,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;oBAC9B,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;wBACzB,WAAW,CAAC,UAAU,CAAC;4BACrB,IAAI,EAAE,aAAa;4BACnB,IAAI,EAAE;gCACJ,eAAe,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;gCACnC,YAAY,EAAE,IAAI;6BACnB;yBACF,CAAC,CAAC;wBAEH,OAAO,GAAG,CAAC;oBACb,CAAC,CAAS,CAAC;gBACb,CAAC;gBAED,WAAW,CAAC,UAAU,CAAC;oBACrB,IAAI,EAAE,aAAa;oBACnB,IAAI,EAAE;wBACJ,eAAe,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;wBACnC,YAAY,EAAE,IAAI;qBACnB;iBACF,CAAC,CAAC;gBACH,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { createClientLogger } from \"./client.js\";\nimport { noopLogger } from \"./noop.js\";\nimport { createServerLogger } from \"./server.js\";\nimport type { EventLogger, EventsSchema, LoggerContext } from \"./types\";\n\nexport type * from \"./types.js\";\n\nexport function createLogger<Schema extends EventsSchema = []>(\n context: LoggerContext,\n): EventLogger<Schema>;\n\nexport function createLogger(context: LoggerContext): EventLogger {\n const innerLogger = (() => {\n try {\n return typeof window === \"undefined\"\n ? createServerLogger(context)\n : createClientLogger(context);\n } catch (e) {\n console.error(\"[Safe to ignore] failed to initialize metrics\", e);\n return noopLogger;\n }\n })();\n\n const logger: EventLogger = {\n ...innerLogger,\n profiled<TArgs extends any[], TRet>(\n name: string,\n func: (...args: TArgs) => TRet,\n ): (...args: TArgs) => TRet {\n return function (this: any, ...args: TArgs): TRet {\n const start = Date.now();\n const result = func.apply(this, args);\n if (result instanceof Promise) {\n return result.then((res) => {\n innerLogger.trackEvent({\n name: \"performance\",\n data: {\n executionTimeMs: Date.now() - start,\n functionName: name,\n },\n });\n\n return res;\n }) as TRet;\n }\n\n innerLogger.trackEvent({\n name: \"performance\",\n data: {\n executionTimeMs: Date.now() - start,\n functionName: name,\n },\n });\n return result;\n };\n },\n };\n\n return logger;\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AASvC,MAAM,UAAU,YAAY,CAAC,QAAuB;IAClD,yEAAyE;IACzE,sEAAsE;IACtE,MAAM,WAAW,GAAG,UAAU,CAAC;IAE/B,MAAM,MAAM,GAAgB;QAC1B,GAAG,WAAW;QACd,QAAQ,CACN,IAAY,EACZ,IAA8B;YAE9B,OAAO,UAAqB,GAAG,IAAW;gBACxC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;gBACzB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBACtC,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;oBAC9B,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;wBACzB,WAAW,CAAC,UAAU,CAAC;4BACrB,IAAI,EAAE,aAAa;4BACnB,IAAI,EAAE;gCACJ,eAAe,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;gCACnC,YAAY,EAAE,IAAI;6BACnB;yBACF,CAAC,CAAC;wBAEH,OAAO,GAAG,CAAC;oBACb,CAAC,CAAS,CAAC;gBACb,CAAC;gBAED,WAAW,CAAC,UAAU,CAAC;oBACrB,IAAI,EAAE,aAAa;oBACnB,IAAI,EAAE;wBACJ,eAAe,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;wBACnC,YAAY,EAAE,IAAI;qBACnB;iBACF,CAAC,CAAC;gBACH,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { noopLogger } from \"./noop.js\";\nimport type { EventLogger, EventsSchema, LoggerContext } from \"./types\";\n\nexport type * from \"./types.js\";\n\nexport function createLogger<Schema extends EventsSchema = []>(\n context: LoggerContext,\n): EventLogger<Schema>;\n\nexport function createLogger(_context: LoggerContext): EventLogger {\n // We are currently not logging events from the SDK (as Sept 2, 2025), so\n // a no-op logger is always used. This will be further explored in v5.\n const innerLogger = noopLogger;\n\n const logger: EventLogger = {\n ...innerLogger,\n profiled<TArgs extends any[], TRet>(\n name: string,\n func: (...args: TArgs) => TRet,\n ): (...args: TArgs) => TRet {\n return function (this: any, ...args: TArgs): TRet {\n const start = Date.now();\n const result = func.apply(this, args);\n if (result instanceof Promise) {\n return result.then((res) => {\n innerLogger.trackEvent({\n name: \"performance\",\n data: {\n executionTimeMs: Date.now() - start,\n functionName: name,\n },\n });\n\n return res;\n }) as TRet;\n }\n\n innerLogger.trackEvent({\n name: \"performance\",\n data: {\n executionTimeMs: Date.now() - start,\n functionName: name,\n },\n });\n return result;\n };\n },\n };\n\n return logger;\n}\n"]}
@@ -1 +1 @@
1
- export declare const VERSION = "4.59.1";
1
+ export declare const VERSION = "4.60.1";
@@ -1,4 +1,4 @@
1
1
  // This file is autogenerated by inject-version.ts. Any changes will be
2
2
  // overwritten on commit!
3
- export const VERSION = "4.59.1";
3
+ export const VERSION = "4.60.1";
4
4
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.59.1\";\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.60.1\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExE,mBAAmB,YAAY,CAAC;AAEhC,wBAAgB,YAAY,CAAC,MAAM,SAAS,YAAY,GAAG,EAAE,EAC3D,OAAO,EAAE,aAAa,GACrB,WAAW,CAAC,MAAM,CAAC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExE,mBAAmB,YAAY,CAAC;AAEhC,wBAAgB,YAAY,CAAC,MAAM,SAAS,YAAY,GAAG,EAAE,EAC3D,OAAO,EAAE,aAAa,GACrB,WAAW,CAAC,MAAM,CAAC,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "4.59.1";
1
+ export declare const VERSION = "4.60.1";
2
2
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@account-kit/logging",
3
- "version": "4.59.1",
3
+ "version": "4.60.1",
4
4
  "description": "Core logging library for Account Kit packages",
5
5
  "author": "Alchemy",
6
6
  "license": "MIT",
@@ -60,5 +60,5 @@
60
60
  "@segment/analytics-next": "1.74.0",
61
61
  "uuid": "^11.0.2"
62
62
  },
63
- "gitHead": "7347ebda8464447d1624a1094f141e2647078baa"
63
+ "gitHead": "a12e3557ed0067bfe432d427280b8b4495a8a748"
64
64
  }
package/src/index.ts CHANGED
@@ -1,6 +1,4 @@
1
- import { createClientLogger } from "./client.js";
2
1
  import { noopLogger } from "./noop.js";
3
- import { createServerLogger } from "./server.js";
4
2
  import type { EventLogger, EventsSchema, LoggerContext } from "./types";
5
3
 
6
4
  export type * from "./types.js";
@@ -9,17 +7,10 @@ export function createLogger<Schema extends EventsSchema = []>(
9
7
  context: LoggerContext,
10
8
  ): EventLogger<Schema>;
11
9
 
12
- export function createLogger(context: LoggerContext): EventLogger {
13
- const innerLogger = (() => {
14
- try {
15
- return typeof window === "undefined"
16
- ? createServerLogger(context)
17
- : createClientLogger(context);
18
- } catch (e) {
19
- console.error("[Safe to ignore] failed to initialize metrics", e);
20
- return noopLogger;
21
- }
22
- })();
10
+ export function createLogger(_context: LoggerContext): EventLogger {
11
+ // We are currently not logging events from the SDK (as Sept 2, 2025), so
12
+ // a no-op logger is always used. This will be further explored in v5.
13
+ const innerLogger = noopLogger;
23
14
 
24
15
  const logger: EventLogger = {
25
16
  ...innerLogger,
package/src/version.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // This file is autogenerated by inject-version.ts. Any changes will be
2
2
  // overwritten on commit!
3
- export const VERSION = "4.59.1";
3
+ export const VERSION = "4.60.1";
@@ -1 +0,0 @@
1
- export declare const WRITE_IN_DEV: boolean;
@@ -1,3 +0,0 @@
1
- // this gets replaced after the build completes if it's present in the Environment
2
- export const WRITE_IN_DEV = false;
3
- //# sourceMappingURL=_writeKey.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_writeKey.js","sourceRoot":"","sources":["../../src/_writeKey.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,MAAM,CAAC,MAAM,YAAY,GAAY,KAAK,CAAC","sourcesContent":["// this gets replaced after the build completes if it's present in the Environment\nexport const WRITE_IN_DEV: boolean = false;\n"]}
@@ -1,2 +0,0 @@
1
- import type { EventsSchema, InnerLogger, LoggerContext } from "./types";
2
- export declare function createClientLogger<Schema extends EventsSchema = []>(context: LoggerContext): InnerLogger<Schema>;
@@ -1,86 +0,0 @@
1
- import { AnalyticsBrowser } from "@segment/analytics-next";
2
- import { v4 as uuid } from "uuid";
3
- import { WRITE_IN_DEV } from "./_writeKey.js";
4
- import { fetchRemoteWriteKey } from "./fetchRemoteWriteKey.js";
5
- import { noopLogger } from "./noop.js";
6
- import { ContextAllowlistPlugin } from "./plugins/contextAllowlist.js";
7
- import { DevDestinationPlugin } from "./plugins/devDestination.js";
8
- import { isClientDevMode } from "./utils.js";
9
- const ANON_ID_STORAGE_KEY = "account-kit:anonId";
10
- function getOrCreateAnonId() {
11
- let anon = JSON.parse(localStorage.getItem(ANON_ID_STORAGE_KEY) ?? "null");
12
- if (!anon || anon.expiresMs < Date.now()) {
13
- anon = {
14
- id: uuid(),
15
- // expires a month from now (30days * 24hrs/day * 60min/hr * 60sec/min * 1000ms/sec)
16
- expiresMs: Date.now() + 30 * 24 * 60 * 60 * 1000,
17
- };
18
- localStorage.setItem(ANON_ID_STORAGE_KEY, JSON.stringify(anon));
19
- }
20
- return anon;
21
- }
22
- export function createClientLogger(context) {
23
- const isDev = isClientDevMode();
24
- if (isDev && !WRITE_IN_DEV) {
25
- // If we don't have a write key, we don't want to log anything
26
- // This is useful for dev so we don't log dev metrics
27
- //
28
- // We also don't allow logging on localhost unless WRITE_IN_DEV is set to true
29
- // WRITE_IN_DEV is only ever true if you're building from source with env vars set to true
30
- return noopLogger;
31
- }
32
- const analytics = new AnalyticsBrowser();
33
- const writeKey = fetchRemoteWriteKey();
34
- const { id: anonId } = getOrCreateAnonId();
35
- analytics.setAnonymousId(anonId);
36
- analytics.register(ContextAllowlistPlugin);
37
- analytics.debug(isDev);
38
- if (isDev) {
39
- // Super weird behaviour, but if I don't add some kind of log here,
40
- // then I don't actually get logs in the console
41
- console.log(`[Metrics] metrics initialized for ${context.package}`);
42
- }
43
- // This lets us log events in the console
44
- if (isDev) {
45
- analytics.register(DevDestinationPlugin);
46
- }
47
- const ready = writeKey.then((writeKey) => {
48
- if (writeKey == null) {
49
- return;
50
- }
51
- analytics.load({
52
- writeKey,
53
- // we disable these settings in dev so we don't fetch anything from segment
54
- cdnSettings: isDev
55
- ? {
56
- integrations: {},
57
- }
58
- : undefined,
59
- },
60
- // further we disable the segment integration dev
61
- {
62
- disableClientPersistence: true,
63
- integrations: {
64
- "Segment.io": !isDev,
65
- },
66
- });
67
- return analytics.ready();
68
- });
69
- return {
70
- _internal: {
71
- ready,
72
- anonId,
73
- },
74
- trackEvent: async ({ name, data }) => {
75
- if (!(await writeKey)) {
76
- return noopLogger.trackEvent({
77
- name,
78
- // @ts-expect-error
79
- data,
80
- });
81
- }
82
- await analytics.track(name, { ...data, ...context });
83
- },
84
- };
85
- }
86
- //# sourceMappingURL=client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"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","sourcesContent":["import { AnalyticsBrowser } from \"@segment/analytics-next\";\nimport { v4 as uuid } from \"uuid\";\nimport { WRITE_IN_DEV } from \"./_writeKey.js\";\nimport { fetchRemoteWriteKey } from \"./fetchRemoteWriteKey.js\";\nimport { noopLogger } from \"./noop.js\";\nimport { ContextAllowlistPlugin } from \"./plugins/contextAllowlist.js\";\nimport { DevDestinationPlugin } from \"./plugins/devDestination.js\";\nimport type { EventsSchema, InnerLogger, LoggerContext } from \"./types\";\nimport { isClientDevMode } from \"./utils.js\";\n\nconst ANON_ID_STORAGE_KEY = \"account-kit:anonId\";\n\ntype AnonId = { id: string; expiresMs: number };\n\nfunction getOrCreateAnonId(): AnonId {\n let anon: AnonId | null = JSON.parse(\n localStorage.getItem(ANON_ID_STORAGE_KEY) ?? \"null\",\n );\n\n if (!anon || anon.expiresMs < Date.now()) {\n anon = {\n id: uuid(),\n // expires a month from now (30days * 24hrs/day * 60min/hr * 60sec/min * 1000ms/sec)\n expiresMs: Date.now() + 30 * 24 * 60 * 60 * 1000,\n };\n localStorage.setItem(ANON_ID_STORAGE_KEY, JSON.stringify(anon));\n }\n\n return anon;\n}\n\nexport function createClientLogger<Schema extends EventsSchema = []>(\n context: LoggerContext,\n): InnerLogger<Schema> {\n const isDev = isClientDevMode();\n if (isDev && !WRITE_IN_DEV) {\n // If we don't have a write key, we don't want to log anything\n // This is useful for dev so we don't log dev metrics\n //\n // We also don't allow logging on localhost unless WRITE_IN_DEV is set to true\n // WRITE_IN_DEV is only ever true if you're building from source with env vars set to true\n return noopLogger;\n }\n\n const analytics = new AnalyticsBrowser();\n const writeKey = fetchRemoteWriteKey();\n\n const { id: anonId } = getOrCreateAnonId();\n analytics.setAnonymousId(anonId);\n analytics.register(ContextAllowlistPlugin);\n analytics.debug(isDev);\n\n if (isDev) {\n // Super weird behaviour, but if I don't add some kind of log here,\n // then I don't actually get logs in the console\n console.log(`[Metrics] metrics initialized for ${context.package}`);\n }\n\n // This lets us log events in the console\n if (isDev) {\n analytics.register(DevDestinationPlugin);\n }\n\n const ready: Promise<unknown> = writeKey.then((writeKey) => {\n if (writeKey == null) {\n return;\n }\n\n analytics.load(\n {\n writeKey,\n // we disable these settings in dev so we don't fetch anything from segment\n cdnSettings: isDev\n ? {\n integrations: {},\n }\n : undefined,\n },\n // further we disable the segment integration dev\n {\n disableClientPersistence: true,\n integrations: {\n \"Segment.io\": !isDev,\n },\n },\n );\n\n return analytics.ready();\n });\n\n return {\n _internal: {\n ready,\n anonId,\n },\n trackEvent: async ({ name, data }) => {\n if (!(await writeKey)) {\n return noopLogger.trackEvent({\n name,\n // @ts-expect-error\n data,\n });\n }\n\n await analytics.track(name, { ...data, ...context });\n },\n };\n}\n"]}
@@ -1 +0,0 @@
1
- export declare function fetchRemoteWriteKey(): Promise<string | undefined>;
@@ -1,12 +0,0 @@
1
- export async function fetchRemoteWriteKey() {
2
- try {
3
- const res = await fetch("https://ws-accounkit-assets.s3.us-west-1.amazonaws.com/logger_config_v1.json");
4
- const json = await res.json();
5
- return json.writeKey;
6
- }
7
- catch (e) {
8
- console.warn("failed to fetch write key");
9
- return undefined;
10
- }
11
- }
12
- //# sourceMappingURL=fetchRemoteWriteKey.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetchRemoteWriteKey.js","sourceRoot":"","sources":["../../src/fetchRemoteWriteKey.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACvC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,KAAK,CACrB,8EAA8E,CAC/E,CAAC;QACF,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC,QAA8B,CAAC;IAC7C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;QAC1C,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["export async function fetchRemoteWriteKey(): Promise<string | undefined> {\n try {\n const res = await fetch(\n \"https://ws-accounkit-assets.s3.us-west-1.amazonaws.com/logger_config_v1.json\",\n );\n const json = await res.json();\n return json.writeKey as string | undefined;\n } catch (e) {\n console.warn(\"failed to fetch write key\");\n return undefined;\n }\n}\n"]}
@@ -1,2 +0,0 @@
1
- import type { EventsSchema, InnerLogger, LoggerContext } from "./types";
2
- export declare function createServerLogger<Schema extends EventsSchema = []>(_context: LoggerContext): InnerLogger<Schema>;
@@ -1,8 +0,0 @@
1
- import { noopLogger } from "./noop.js";
2
- export function createServerLogger(_context) {
3
- // TODO: there is an analytics js node package that we can use, but we'll come back to that later
4
- // this is harder than client, because on the client we can filter out events that are originating from localhost,
5
- // whereas here we can't do that as easily
6
- return noopLogger;
7
- }
8
- //# sourceMappingURL=server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGvC,MAAM,UAAU,kBAAkB,CAChC,QAAuB;IAEvB,iGAAiG;IACjG,kHAAkH;IAClH,0CAA0C;IAC1C,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import { noopLogger } from \"./noop.js\";\nimport type { EventsSchema, InnerLogger, LoggerContext } from \"./types\";\n\nexport function createServerLogger<Schema extends EventsSchema = []>(\n _context: LoggerContext,\n): InnerLogger<Schema> {\n // TODO: there is an analytics js node package that we can use, but we'll come back to that later\n // this is harder than client, because on the client we can filter out events that are originating from localhost,\n // whereas here we can't do that as easily\n return noopLogger;\n}\n"]}
@@ -1,2 +0,0 @@
1
- export declare const WRITE_IN_DEV: boolean;
2
- //# sourceMappingURL=_writeKey.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_writeKey.d.ts","sourceRoot":"","sources":["../../src/_writeKey.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,YAAY,EAAE,OAAe,CAAC"}
@@ -1,3 +0,0 @@
1
- import type { EventsSchema, InnerLogger, LoggerContext } from "./types";
2
- export declare function createClientLogger<Schema extends EventsSchema = []>(context: LoggerContext): InnerLogger<Schema>;
3
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAwBxE,wBAAgB,kBAAkB,CAAC,MAAM,SAAS,YAAY,GAAG,EAAE,EACjE,OAAO,EAAE,aAAa,GACrB,WAAW,CAAC,MAAM,CAAC,CA0ErB"}
@@ -1,2 +0,0 @@
1
- export declare function fetchRemoteWriteKey(): Promise<string | undefined>;
2
- //# sourceMappingURL=fetchRemoteWriteKey.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetchRemoteWriteKey.d.ts","sourceRoot":"","sources":["../../src/fetchRemoteWriteKey.ts"],"names":[],"mappings":"AAAA,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAWvE"}
@@ -1,3 +0,0 @@
1
- import type { EventsSchema, InnerLogger, LoggerContext } from "./types";
2
- export declare function createServerLogger<Schema extends EventsSchema = []>(_context: LoggerContext): InnerLogger<Schema>;
3
- //# sourceMappingURL=server.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExE,wBAAgB,kBAAkB,CAAC,MAAM,SAAS,YAAY,GAAG,EAAE,EACjE,QAAQ,EAAE,aAAa,GACtB,WAAW,CAAC,MAAM,CAAC,CAKrB"}
package/src/_writeKey.ts DELETED
@@ -1,2 +0,0 @@
1
- // this gets replaced after the build completes if it's present in the Environment
2
- export const WRITE_IN_DEV: boolean = false;
package/src/client.ts DELETED
@@ -1,108 +0,0 @@
1
- import { AnalyticsBrowser } from "@segment/analytics-next";
2
- import { v4 as uuid } from "uuid";
3
- import { WRITE_IN_DEV } from "./_writeKey.js";
4
- import { fetchRemoteWriteKey } from "./fetchRemoteWriteKey.js";
5
- import { noopLogger } from "./noop.js";
6
- import { ContextAllowlistPlugin } from "./plugins/contextAllowlist.js";
7
- import { DevDestinationPlugin } from "./plugins/devDestination.js";
8
- import type { EventsSchema, InnerLogger, LoggerContext } from "./types";
9
- import { isClientDevMode } from "./utils.js";
10
-
11
- const ANON_ID_STORAGE_KEY = "account-kit:anonId";
12
-
13
- type AnonId = { id: string; expiresMs: number };
14
-
15
- function getOrCreateAnonId(): AnonId {
16
- let anon: AnonId | null = JSON.parse(
17
- localStorage.getItem(ANON_ID_STORAGE_KEY) ?? "null",
18
- );
19
-
20
- if (!anon || anon.expiresMs < Date.now()) {
21
- anon = {
22
- id: uuid(),
23
- // expires a month from now (30days * 24hrs/day * 60min/hr * 60sec/min * 1000ms/sec)
24
- expiresMs: Date.now() + 30 * 24 * 60 * 60 * 1000,
25
- };
26
- localStorage.setItem(ANON_ID_STORAGE_KEY, JSON.stringify(anon));
27
- }
28
-
29
- return anon;
30
- }
31
-
32
- export function createClientLogger<Schema extends EventsSchema = []>(
33
- context: LoggerContext,
34
- ): InnerLogger<Schema> {
35
- const isDev = isClientDevMode();
36
- if (isDev && !WRITE_IN_DEV) {
37
- // If we don't have a write key, we don't want to log anything
38
- // This is useful for dev so we don't log dev metrics
39
- //
40
- // We also don't allow logging on localhost unless WRITE_IN_DEV is set to true
41
- // WRITE_IN_DEV is only ever true if you're building from source with env vars set to true
42
- return noopLogger;
43
- }
44
-
45
- const analytics = new AnalyticsBrowser();
46
- const writeKey = fetchRemoteWriteKey();
47
-
48
- const { id: anonId } = getOrCreateAnonId();
49
- analytics.setAnonymousId(anonId);
50
- analytics.register(ContextAllowlistPlugin);
51
- analytics.debug(isDev);
52
-
53
- if (isDev) {
54
- // Super weird behaviour, but if I don't add some kind of log here,
55
- // then I don't actually get logs in the console
56
- console.log(`[Metrics] metrics initialized for ${context.package}`);
57
- }
58
-
59
- // This lets us log events in the console
60
- if (isDev) {
61
- analytics.register(DevDestinationPlugin);
62
- }
63
-
64
- const ready: Promise<unknown> = writeKey.then((writeKey) => {
65
- if (writeKey == null) {
66
- return;
67
- }
68
-
69
- analytics.load(
70
- {
71
- writeKey,
72
- // we disable these settings in dev so we don't fetch anything from segment
73
- cdnSettings: isDev
74
- ? {
75
- integrations: {},
76
- }
77
- : undefined,
78
- },
79
- // further we disable the segment integration dev
80
- {
81
- disableClientPersistence: true,
82
- integrations: {
83
- "Segment.io": !isDev,
84
- },
85
- },
86
- );
87
-
88
- return analytics.ready();
89
- });
90
-
91
- return {
92
- _internal: {
93
- ready,
94
- anonId,
95
- },
96
- trackEvent: async ({ name, data }) => {
97
- if (!(await writeKey)) {
98
- return noopLogger.trackEvent({
99
- name,
100
- // @ts-expect-error
101
- data,
102
- });
103
- }
104
-
105
- await analytics.track(name, { ...data, ...context });
106
- },
107
- };
108
- }
@@ -1,12 +0,0 @@
1
- export async function fetchRemoteWriteKey(): Promise<string | undefined> {
2
- try {
3
- const res = await fetch(
4
- "https://ws-accounkit-assets.s3.us-west-1.amazonaws.com/logger_config_v1.json",
5
- );
6
- const json = await res.json();
7
- return json.writeKey as string | undefined;
8
- } catch (e) {
9
- console.warn("failed to fetch write key");
10
- return undefined;
11
- }
12
- }
package/src/server.ts DELETED
@@ -1,11 +0,0 @@
1
- import { noopLogger } from "./noop.js";
2
- import type { EventsSchema, InnerLogger, LoggerContext } from "./types";
3
-
4
- export function createServerLogger<Schema extends EventsSchema = []>(
5
- _context: LoggerContext,
6
- ): InnerLogger<Schema> {
7
- // TODO: there is an analytics js node package that we can use, but we'll come back to that later
8
- // this is harder than client, because on the client we can filter out events that are originating from localhost,
9
- // whereas here we can't do that as easily
10
- return noopLogger;
11
- }