zitejs 0.9.115 → 0.9.116
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/cjs/auth/useAuth.test.d.ts +1 -0
- package/dist/cjs/auth/useAuth.test.js +96 -0
- package/dist/cjs/bundle/index.js +2 -0
- package/dist/esm/auth/useAuth.test.d.ts +1 -0
- package/dist/esm/auth/useAuth.test.js +94 -0
- package/dist/esm/bundle/index.js +2 -0
- package/dist/esm/cli.js +0 -0
- package/package.json +2 -2
- package/dist/cjs/api/index.js +0 -5
- package/dist/cjs/db/index.js +0 -5
- package/dist/esm/api/index.d.ts +0 -2
- package/dist/esm/api/index.js +0 -1
- package/dist/esm/db/index.d.ts +0 -2
- package/dist/esm/db/index.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
/**
|
|
5
|
+
* The signed-out redirect on internal apps.
|
|
6
|
+
*
|
|
7
|
+
* A separate file from `index.test.ts` because it has to replace
|
|
8
|
+
* `better-auth/react` wholesale to drive `useSession`, and that would strip the
|
|
9
|
+
* real client the export tests next door assert against.
|
|
10
|
+
*
|
|
11
|
+
* The value here is entirely in WHICH signed-out renders it reacts to. An
|
|
12
|
+
* external app has a real logged-out state, and an app built before the
|
|
13
|
+
* platform sent an access mode tells us nothing — redirecting either turns a
|
|
14
|
+
* working public page into a forced sign-in.
|
|
15
|
+
*/
|
|
16
|
+
const { useSessionMock } = vitest_1.vi.hoisted(() => ({ useSessionMock: vitest_1.vi.fn() }));
|
|
17
|
+
vitest_1.vi.mock('better-auth/react', () => ({
|
|
18
|
+
createAuthClient: () => ({
|
|
19
|
+
useSession: useSessionMock,
|
|
20
|
+
signIn: {},
|
|
21
|
+
signUp: {},
|
|
22
|
+
signOut: vitest_1.vi.fn(),
|
|
23
|
+
updateUser: vitest_1.vi.fn(),
|
|
24
|
+
}),
|
|
25
|
+
}));
|
|
26
|
+
vitest_1.vi.mock('better-auth/client/plugins', () => ({
|
|
27
|
+
magicLinkClient: () => ({}),
|
|
28
|
+
inferAdditionalFields: () => ({}),
|
|
29
|
+
}));
|
|
30
|
+
// `useAuth` takes only `useEffect` from React. Running it inline is the whole
|
|
31
|
+
// of what a render would do here, and avoids pulling in a renderer.
|
|
32
|
+
vitest_1.vi.mock('react', () => ({ useEffect: (fn) => fn() }));
|
|
33
|
+
const index_js_1 = require("./index.js");
|
|
34
|
+
const APP_URL = 'https://app.zite.so/dashboard';
|
|
35
|
+
function stubLocation(href) {
|
|
36
|
+
const location = { pathname: new URL(href).pathname, href };
|
|
37
|
+
vitest_1.vi.stubGlobal('window', { location });
|
|
38
|
+
return location;
|
|
39
|
+
}
|
|
40
|
+
const signedOut = { data: null, isPending: false };
|
|
41
|
+
(0, vitest_1.beforeEach)(() => {
|
|
42
|
+
delete process.env.ZITE_ACCESS_MODE;
|
|
43
|
+
});
|
|
44
|
+
(0, vitest_1.afterEach)(() => {
|
|
45
|
+
delete process.env.ZITE_ACCESS_MODE;
|
|
46
|
+
vitest_1.vi.unstubAllGlobals();
|
|
47
|
+
useSessionMock.mockReset();
|
|
48
|
+
});
|
|
49
|
+
const render = (session, { accessMode, href = APP_URL } = {}) => {
|
|
50
|
+
if (accessMode !== undefined)
|
|
51
|
+
process.env.ZITE_ACCESS_MODE = accessMode;
|
|
52
|
+
const location = stubLocation(href);
|
|
53
|
+
useSessionMock.mockReturnValue(session);
|
|
54
|
+
return { result: (0, index_js_1.useAuth)(), location };
|
|
55
|
+
};
|
|
56
|
+
(0, vitest_1.describe)('useAuth signed-out handling', () => {
|
|
57
|
+
(0, vitest_1.it)('sends a signed-out visitor on an internal app to sign-in', () => {
|
|
58
|
+
const { result, location } = render(signedOut, { accessMode: 'internal' });
|
|
59
|
+
(0, vitest_1.expect)(location.href.startsWith('/auth/login')).toBe(true);
|
|
60
|
+
// Reported as loading rather than signed out: the signed-out branch of an
|
|
61
|
+
// internal app is the empty screen this exists to prevent.
|
|
62
|
+
(0, vitest_1.expect)(result.isLoading).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
(0, vitest_1.it)('leaves a signed-out visitor on an external app alone', () => {
|
|
65
|
+
const { result, location } = render(signedOut, { accessMode: 'external' });
|
|
66
|
+
(0, vitest_1.expect)(location.href).toBe(APP_URL);
|
|
67
|
+
(0, vitest_1.expect)(result.isLoading).toBe(false);
|
|
68
|
+
(0, vitest_1.expect)(result.user).toBe(null);
|
|
69
|
+
});
|
|
70
|
+
// Every app published before the platform started sending an access mode.
|
|
71
|
+
(0, vitest_1.it)('leaves an app that never declared an access mode alone', () => {
|
|
72
|
+
const { result, location } = render(signedOut);
|
|
73
|
+
(0, vitest_1.expect)(location.href).toBe(APP_URL);
|
|
74
|
+
(0, vitest_1.expect)(result.isLoading).toBe(false);
|
|
75
|
+
});
|
|
76
|
+
(0, vitest_1.it)('does not redirect while the session is still resolving', () => {
|
|
77
|
+
const { result, location } = render({ data: null, isPending: true }, { accessMode: 'internal' });
|
|
78
|
+
(0, vitest_1.expect)(location.href).toBe(APP_URL);
|
|
79
|
+
(0, vitest_1.expect)(result.isLoading).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
(0, vitest_1.it)('does not redirect a signed-in visitor', () => {
|
|
82
|
+
const { result, location } = render({ data: { user: { id: 'u1', email: 'a@b.com' } }, isPending: false }, { accessMode: 'internal' });
|
|
83
|
+
(0, vitest_1.expect)(location.href).toBe(APP_URL);
|
|
84
|
+
(0, vitest_1.expect)(result.isLoading).toBe(false);
|
|
85
|
+
(0, vitest_1.expect)(result.user).toMatchObject({ id: 'u1' });
|
|
86
|
+
});
|
|
87
|
+
// `loginWithRedirect` refuses to navigate away from an auth page, so claiming
|
|
88
|
+
// a redirect here would hang the caller on `isLoading` forever.
|
|
89
|
+
(0, vitest_1.it)('does not claim to be loading on an auth page it cannot leave', () => {
|
|
90
|
+
const { result } = render(signedOut, {
|
|
91
|
+
accessMode: 'internal',
|
|
92
|
+
href: 'https://app.zite.so/auth/login',
|
|
93
|
+
});
|
|
94
|
+
(0, vitest_1.expect)(result.isLoading).toBe(false);
|
|
95
|
+
});
|
|
96
|
+
});
|
package/dist/cjs/bundle/index.js
CHANGED
|
@@ -94,6 +94,8 @@ const PREBUNDLED_LIBS = {
|
|
|
94
94
|
'intercom-client': '__intercom__.js',
|
|
95
95
|
'@google/generative-ai': '__gemini__.js',
|
|
96
96
|
'@elevenlabs/elevenlabs-js': '__elevenlabs__.js',
|
|
97
|
+
'resend': '__resend__.js',
|
|
98
|
+
'@clickhouse/client-web': '__clickhouse__.js',
|
|
97
99
|
};
|
|
98
100
|
exports.BASE_BUILD_OPTIONS = {
|
|
99
101
|
bundle: true,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach, beforeEach, vi } from 'vitest';
|
|
2
|
+
/**
|
|
3
|
+
* The signed-out redirect on internal apps.
|
|
4
|
+
*
|
|
5
|
+
* A separate file from `index.test.ts` because it has to replace
|
|
6
|
+
* `better-auth/react` wholesale to drive `useSession`, and that would strip the
|
|
7
|
+
* real client the export tests next door assert against.
|
|
8
|
+
*
|
|
9
|
+
* The value here is entirely in WHICH signed-out renders it reacts to. An
|
|
10
|
+
* external app has a real logged-out state, and an app built before the
|
|
11
|
+
* platform sent an access mode tells us nothing — redirecting either turns a
|
|
12
|
+
* working public page into a forced sign-in.
|
|
13
|
+
*/
|
|
14
|
+
const { useSessionMock } = vi.hoisted(() => ({ useSessionMock: vi.fn() }));
|
|
15
|
+
vi.mock('better-auth/react', () => ({
|
|
16
|
+
createAuthClient: () => ({
|
|
17
|
+
useSession: useSessionMock,
|
|
18
|
+
signIn: {},
|
|
19
|
+
signUp: {},
|
|
20
|
+
signOut: vi.fn(),
|
|
21
|
+
updateUser: vi.fn(),
|
|
22
|
+
}),
|
|
23
|
+
}));
|
|
24
|
+
vi.mock('better-auth/client/plugins', () => ({
|
|
25
|
+
magicLinkClient: () => ({}),
|
|
26
|
+
inferAdditionalFields: () => ({}),
|
|
27
|
+
}));
|
|
28
|
+
// `useAuth` takes only `useEffect` from React. Running it inline is the whole
|
|
29
|
+
// of what a render would do here, and avoids pulling in a renderer.
|
|
30
|
+
vi.mock('react', () => ({ useEffect: (fn) => fn() }));
|
|
31
|
+
import { useAuth } from './index.js';
|
|
32
|
+
const APP_URL = 'https://app.zite.so/dashboard';
|
|
33
|
+
function stubLocation(href) {
|
|
34
|
+
const location = { pathname: new URL(href).pathname, href };
|
|
35
|
+
vi.stubGlobal('window', { location });
|
|
36
|
+
return location;
|
|
37
|
+
}
|
|
38
|
+
const signedOut = { data: null, isPending: false };
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
delete process.env.ZITE_ACCESS_MODE;
|
|
41
|
+
});
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
delete process.env.ZITE_ACCESS_MODE;
|
|
44
|
+
vi.unstubAllGlobals();
|
|
45
|
+
useSessionMock.mockReset();
|
|
46
|
+
});
|
|
47
|
+
const render = (session, { accessMode, href = APP_URL } = {}) => {
|
|
48
|
+
if (accessMode !== undefined)
|
|
49
|
+
process.env.ZITE_ACCESS_MODE = accessMode;
|
|
50
|
+
const location = stubLocation(href);
|
|
51
|
+
useSessionMock.mockReturnValue(session);
|
|
52
|
+
return { result: useAuth(), location };
|
|
53
|
+
};
|
|
54
|
+
describe('useAuth signed-out handling', () => {
|
|
55
|
+
it('sends a signed-out visitor on an internal app to sign-in', () => {
|
|
56
|
+
const { result, location } = render(signedOut, { accessMode: 'internal' });
|
|
57
|
+
expect(location.href.startsWith('/auth/login')).toBe(true);
|
|
58
|
+
// Reported as loading rather than signed out: the signed-out branch of an
|
|
59
|
+
// internal app is the empty screen this exists to prevent.
|
|
60
|
+
expect(result.isLoading).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
it('leaves a signed-out visitor on an external app alone', () => {
|
|
63
|
+
const { result, location } = render(signedOut, { accessMode: 'external' });
|
|
64
|
+
expect(location.href).toBe(APP_URL);
|
|
65
|
+
expect(result.isLoading).toBe(false);
|
|
66
|
+
expect(result.user).toBe(null);
|
|
67
|
+
});
|
|
68
|
+
// Every app published before the platform started sending an access mode.
|
|
69
|
+
it('leaves an app that never declared an access mode alone', () => {
|
|
70
|
+
const { result, location } = render(signedOut);
|
|
71
|
+
expect(location.href).toBe(APP_URL);
|
|
72
|
+
expect(result.isLoading).toBe(false);
|
|
73
|
+
});
|
|
74
|
+
it('does not redirect while the session is still resolving', () => {
|
|
75
|
+
const { result, location } = render({ data: null, isPending: true }, { accessMode: 'internal' });
|
|
76
|
+
expect(location.href).toBe(APP_URL);
|
|
77
|
+
expect(result.isLoading).toBe(true);
|
|
78
|
+
});
|
|
79
|
+
it('does not redirect a signed-in visitor', () => {
|
|
80
|
+
const { result, location } = render({ data: { user: { id: 'u1', email: 'a@b.com' } }, isPending: false }, { accessMode: 'internal' });
|
|
81
|
+
expect(location.href).toBe(APP_URL);
|
|
82
|
+
expect(result.isLoading).toBe(false);
|
|
83
|
+
expect(result.user).toMatchObject({ id: 'u1' });
|
|
84
|
+
});
|
|
85
|
+
// `loginWithRedirect` refuses to navigate away from an auth page, so claiming
|
|
86
|
+
// a redirect here would hang the caller on `isLoading` forever.
|
|
87
|
+
it('does not claim to be loading on an auth page it cannot leave', () => {
|
|
88
|
+
const { result } = render(signedOut, {
|
|
89
|
+
accessMode: 'internal',
|
|
90
|
+
href: 'https://app.zite.so/auth/login',
|
|
91
|
+
});
|
|
92
|
+
expect(result.isLoading).toBe(false);
|
|
93
|
+
});
|
|
94
|
+
});
|
package/dist/esm/bundle/index.js
CHANGED
|
@@ -57,6 +57,8 @@ const PREBUNDLED_LIBS = {
|
|
|
57
57
|
'intercom-client': '__intercom__.js',
|
|
58
58
|
'@google/generative-ai': '__gemini__.js',
|
|
59
59
|
'@elevenlabs/elevenlabs-js': '__elevenlabs__.js',
|
|
60
|
+
'resend': '__resend__.js',
|
|
61
|
+
'@clickhouse/client-web': '__clickhouse__.js',
|
|
60
62
|
};
|
|
61
63
|
export const BASE_BUILD_OPTIONS = {
|
|
62
64
|
bundle: true,
|
package/dist/esm/cli.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zitejs",
|
|
3
|
-
"version": "0.9.
|
|
4
|
-
"description": "The Zite framework
|
|
3
|
+
"version": "0.9.116",
|
|
4
|
+
"description": "The Zite framework \u2014 build apps on Zite Database",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
7
7
|
"module": "./dist/esm/index.js",
|
package/dist/cjs/api/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createCaller = void 0;
|
|
4
|
-
var index_js_1 = require("../caller/index.js");
|
|
5
|
-
Object.defineProperty(exports, "createCaller", { enumerable: true, get: function () { return index_js_1.createCaller; } });
|
package/dist/cjs/db/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTableClient = void 0;
|
|
4
|
-
var index_js_1 = require("../runtime/index.js");
|
|
5
|
-
Object.defineProperty(exports, "createTableClient", { enumerable: true, get: function () { return index_js_1.createTableClient; } });
|
package/dist/esm/api/index.d.ts
DELETED
package/dist/esm/api/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { createCaller } from '../caller/index.js';
|
package/dist/esm/db/index.d.ts
DELETED
package/dist/esm/db/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { createTableClient } from '../runtime/index.js';
|