@djangocfg/api 2.1.626 → 2.1.628

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djangocfg/api",
3
- "version": "2.1.626",
3
+ "version": "2.1.628",
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",
@@ -91,7 +91,7 @@
91
91
  "zod": "^4.3.6"
92
92
  },
93
93
  "devDependencies": {
94
- "@djangocfg/typescript-config": "^2.1.626",
94
+ "@djangocfg/typescript-config": "^2.1.628",
95
95
  "@testing-library/react": "^16.3.3",
96
96
  "@types/node": "^25.9.5",
97
97
  "@types/react": "19.3.0",
@@ -1,7 +1,7 @@
1
1
  // @vitest-environment jsdom
2
2
  import { beforeEach, describe, expect, it } from 'vitest';
3
3
 
4
- import { authTrace, clearAuthTrace, dumpAuthTrace, readAuthTrace } from '../trace';
4
+ import { authTrace, clearAuthTrace, dumpAuthTrace, readAuthTrace, registerAuthCopy } from '../trace';
5
5
 
6
6
  describe('auth trace', () => {
7
7
  beforeEach(() => {
@@ -9,6 +9,18 @@ describe('auth trace', () => {
9
9
  clearAuthTrace();
10
10
  });
11
11
 
12
+ it('loading the module does not count a copy; registerAuthCopy does, and a second one is a dup', () => {
13
+ const g = globalThis as Record<string, unknown>;
14
+ delete g.__cfgAuthCopies;
15
+ registerAuthCopy();
16
+ expect(g.__cfgAuthCopies).toBe(1);
17
+ expect(readAuthTrace().some((e) => e.ev === 'dup.copy')).toBe(false);
18
+ registerAuthCopy();
19
+ expect(g.__cfgAuthCopies).toBe(2);
20
+ expect(readAuthTrace().some((e) => e.ev === 'dup.copy')).toBe(true);
21
+ delete g.__cfgAuthCopies;
22
+ });
23
+
12
24
  it('drops sensitive keys and cuts long strings', () => {
13
25
  authTrace('x', { token: 'abc', email: 'a@b.c', otp: '123456', path: '/auth', long: 'y'.repeat(300), ok: true });
14
26
  const f = readAuthTrace()[0]!.f!;
package/src/auth/index.ts CHANGED
@@ -29,6 +29,8 @@ export * from './constants';
29
29
 
30
30
  // Persisted auth trace: `authTrace(ev, fields)` and the readers behind `window.__cfgAuth`.
31
31
  export * from './trace';
32
+ import { registerAuthCopy } from './trace';
33
+ registerAuthCopy();
32
34
 
33
35
  // Contexts
34
36
  export * from './context';
package/src/auth/trace.ts CHANGED
@@ -233,8 +233,9 @@ export function installAuthTrace(): void {
233
233
  * Count the copies of this package in the page. More than one means the bundle holds duplicates (pnpm peer-set
234
234
  * variants, a dual ESM/CJS load): the contexts are shared (`sharedContext`), but the build should still be fixed.
235
235
  * Visible as `dup.copy` in the trace and once in the console.
236
+ * Called once by the auth entry (`src/auth/index.ts`), not by this module (see below).
236
237
  */
237
- function registerCopy(): void {
238
+ export function registerAuthCopy(): void {
238
239
  if (!hasWindow) return;
239
240
  const g = globalThis as Record<string, unknown>;
240
241
  const n = ((g.__cfgAuthCopies as number | undefined) ?? 0) + 1;
@@ -247,7 +248,9 @@ function registerCopy(): void {
247
248
  }
248
249
  }
249
250
  }
250
- registerCopy();
251
+ // NOT called here: `src/index.ts` and `src/auth/index.ts` are separate bundles that each carry this module, so
252
+ // counting at load made every healthy page report `copies: 2`. `src/auth/index.ts` (the client entry, which holds
253
+ // the contexts that must be single) calls `registerAuthCopy()`, so only a second copy of that entry counts.
251
254
 
252
255
  // The reader is installed as soon as the package loads, so a trace exists from the first event.
253
256
  installAuthTrace();