@djangocfg/api 2.1.469 → 2.1.471
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/auth.cjs +18 -8
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +26 -13
- package/dist/auth.d.ts +26 -13
- package/dist/auth.mjs +18 -8
- package/dist/auth.mjs.map +1 -1
- package/package.json +2 -2
- package/src/auth/utils/analytics.ts +43 -20
- package/src/auth/utils/index.ts +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/api",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.471",
|
|
4
4
|
"description": "Auto-generated TypeScript API client with React hooks, SWR integration, and Zod validation for Django REST Framework backends",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"django",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"zod": "^4.3.6"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
87
|
+
"@djangocfg/typescript-config": "^2.1.471",
|
|
88
88
|
"@testing-library/react": "^16.3.2",
|
|
89
89
|
"@types/node": "^25.9.5",
|
|
90
90
|
"@types/react": "19.2.15",
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { isDev } from "./env";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* Provides minimal analytics interface without external dependencies
|
|
3
|
+
* Auth analytics — a dependency-free SINK, not an implementation.
|
|
5
4
|
*
|
|
6
|
-
*
|
|
5
|
+
* `@djangocfg/api` cannot depend on `@djangocfg/analytics`: analytics reads auth
|
|
6
|
+
* state (to attribute events to a signed-in user), so importing it here would
|
|
7
|
+
* close a dependency cycle. Instead this module owns the *interface* and lets a
|
|
8
|
+
* real implementation be injected at runtime — `@djangocfg/analytics` calls
|
|
9
|
+
* `setAnalyticsSink()` when its provider mounts.
|
|
10
|
+
*
|
|
11
|
+
* Before this, the object below was a hardcoded stub that console.logged in dev
|
|
12
|
+
* and did NOTHING in production. Every auth event it "tracked" —
|
|
13
|
+
* AUTH_LOGIN_SUCCESS, AUTH_OAUTH_FAIL, AUTH_SESSION_EXPIRED — was silently
|
|
14
|
+
* discarded. The events were fired, the calls looked right, and nothing ever
|
|
15
|
+
* arrived anywhere.
|
|
7
16
|
*/
|
|
8
17
|
|
|
9
18
|
export enum AnalyticsEvent {
|
|
@@ -32,32 +41,46 @@ interface AnalyticsEventParams {
|
|
|
32
41
|
[key: string]: any;
|
|
33
42
|
}
|
|
34
43
|
|
|
44
|
+
/** What an analytics implementation must provide to receive auth events. */
|
|
45
|
+
export interface AnalyticsSink {
|
|
46
|
+
event(name: string, params?: Record<string, any>): void;
|
|
47
|
+
setUser(userId: string | null): void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let sink: AnalyticsSink | null = null;
|
|
51
|
+
|
|
35
52
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
53
|
+
* Install the real analytics implementation.
|
|
54
|
+
*
|
|
55
|
+
* Called by `@djangocfg/analytics` when its provider mounts. Pass `null` to
|
|
56
|
+
* uninstall (on unmount), so a torn-down provider does not keep receiving events.
|
|
38
57
|
*/
|
|
58
|
+
export function setAnalyticsSink(next: AnalyticsSink | null): void {
|
|
59
|
+
sink = next;
|
|
60
|
+
}
|
|
61
|
+
|
|
39
62
|
export const Analytics = {
|
|
40
|
-
/**
|
|
41
|
-
* Track an analytics event
|
|
42
|
-
*/
|
|
63
|
+
/** Track an auth event. Delivered to the installed sink, if any. */
|
|
43
64
|
event(eventName: AnalyticsEventType, params?: AnalyticsEventParams) {
|
|
65
|
+
if (sink) {
|
|
66
|
+
sink.event(eventName, params);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// No sink installed: the app is not using @djangocfg/analytics. Say so in
|
|
70
|
+
// dev rather than pretending the event went somewhere.
|
|
44
71
|
if (isDev) {
|
|
45
|
-
console.log('[Analytics]', eventName, params);
|
|
72
|
+
console.log('[Analytics:no-sink]', eventName, params);
|
|
46
73
|
}
|
|
47
|
-
|
|
48
|
-
// You can extend this to send to your analytics service
|
|
49
|
-
// Example: window.gtag?.('event', eventName, params);
|
|
50
74
|
},
|
|
51
75
|
|
|
52
|
-
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
76
|
+
/** Attach the signed-in user. Pass null on logout. */
|
|
77
|
+
setUser(userId: string | null) {
|
|
78
|
+
if (sink) {
|
|
79
|
+
sink.setUser(userId);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
56
82
|
if (isDev) {
|
|
57
|
-
console.log('[Analytics] Set user:', userId);
|
|
83
|
+
console.log('[Analytics:no-sink] Set user:', userId);
|
|
58
84
|
}
|
|
59
|
-
|
|
60
|
-
// You can extend this to send to your analytics service
|
|
61
|
-
// Example: window.gtag?.('set', { user_id: userId });
|
|
62
85
|
},
|
|
63
86
|
};
|
package/src/auth/utils/index.ts
CHANGED
|
@@ -12,6 +12,10 @@ export {
|
|
|
12
12
|
Analytics,
|
|
13
13
|
AnalyticsEvent,
|
|
14
14
|
AnalyticsCategory,
|
|
15
|
+
// Lets @djangocfg/analytics inject the real implementation without api having
|
|
16
|
+
// to depend on it (which would be a cycle — analytics reads auth state).
|
|
17
|
+
setAnalyticsSink,
|
|
18
|
+
type AnalyticsSink,
|
|
15
19
|
type AnalyticsEventType,
|
|
16
20
|
type AnalyticsCategoryType,
|
|
17
21
|
} from './analytics';
|