jazz-tools 0.18.3 → 0.18.5
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/.turbo/turbo-build.log +34 -34
- package/CHANGELOG.md +22 -0
- package/dist/better-auth/auth/react.d.ts +5 -2
- package/dist/better-auth/auth/react.d.ts.map +1 -1
- package/dist/better-auth/auth/server.d.ts +21 -1
- package/dist/better-auth/auth/server.d.ts.map +1 -1
- package/dist/better-auth/auth/server.js +10 -5
- package/dist/better-auth/auth/server.js.map +1 -1
- package/dist/browser/createBrowserContext.d.ts.map +1 -1
- package/dist/browser/index.js +7 -0
- package/dist/browser/index.js.map +1 -1
- package/dist/{chunk-IERUTUXB.js → chunk-3LE7N6TH.js} +121 -36
- package/dist/chunk-3LE7N6TH.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/react-core/index.js +120 -35
- package/dist/react-core/index.js.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/tools/coValues/account.d.ts.map +1 -1
- package/dist/tools/coValues/coFeed.d.ts +12 -0
- package/dist/tools/coValues/coFeed.d.ts.map +1 -1
- package/dist/tools/coValues/coMap.d.ts.map +1 -1
- package/dist/tools/implementation/anonymousJazzAgent.d.ts +1 -1
- package/dist/tools/implementation/anonymousJazzAgent.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/coExport.d.ts +2 -0
- package/dist/tools/implementation/zodSchema/coExport.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +19 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/CoFieldSchemaInit.d.ts +4 -0
- package/dist/tools/implementation/zodSchema/typeConverters/CoFieldSchemaInit.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/TypeOfZodSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/unionUtils.d.ts.map +1 -1
- package/dist/tools/subscribe/CoValueCoreSubscription.d.ts +61 -11
- package/dist/tools/subscribe/CoValueCoreSubscription.d.ts.map +1 -1
- package/dist/tools/subscribe/CoValueCoreSubscription.test.d.ts +2 -0
- package/dist/tools/subscribe/CoValueCoreSubscription.test.d.ts.map +1 -0
- package/dist/tools/testing.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/better-auth/auth/server.ts +38 -7
- package/src/better-auth/auth/tests/server.test.ts +95 -7
- package/src/browser/createBrowserContext.ts +8 -0
- package/src/tools/coValues/account.ts +3 -1
- package/src/tools/coValues/coFeed.ts +5 -0
- package/src/tools/coValues/coMap.ts +3 -1
- package/src/tools/implementation/anonymousJazzAgent.ts +1 -1
- package/src/tools/implementation/zodSchema/coExport.ts +2 -0
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +19 -0
- package/src/tools/implementation/zodSchema/typeConverters/CoFieldSchemaInit.ts +8 -1
- package/src/tools/implementation/zodSchema/typeConverters/TypeOfZodSchema.ts +0 -1
- package/src/tools/implementation/zodSchema/unionUtils.ts +0 -1
- package/src/tools/subscribe/CoValueCoreSubscription.test.ts +1000 -0
- package/src/tools/subscribe/CoValueCoreSubscription.ts +179 -43
- package/src/tools/tests/account.test.ts +12 -0
- package/src/tools/tests/coFeed.test.ts +25 -0
- package/src/tools/tests/coList.test-d.ts +17 -0
- package/src/tools/tests/coList.test.ts +20 -0
- package/src/tools/tests/coMap.record.test-d.ts +18 -0
- package/src/tools/tests/coMap.record.test.ts +1 -0
- package/src/tools/tests/coMap.test-d.ts +15 -0
- package/src/tools/tests/coMap.test.ts +12 -2
- package/dist/chunk-IERUTUXB.js.map +0 -1
@@ -1,13 +1,54 @@
|
|
1
1
|
import { betterAuth } from "better-auth";
|
2
2
|
import { memoryAdapter } from "better-auth/adapters/memory";
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
afterAll,
|
5
|
+
beforeAll,
|
6
|
+
beforeEach,
|
7
|
+
describe,
|
8
|
+
expect,
|
9
|
+
it,
|
10
|
+
vi,
|
11
|
+
type Mock,
|
12
|
+
} from "vitest";
|
13
|
+
import { OAuth2Server } from "oauth2-mock-server";
|
4
14
|
import { jazzPlugin } from "../server.js";
|
15
|
+
import { genericOAuth } from "better-auth/plugins";
|
5
16
|
|
6
|
-
describe("Better Auth - Signup and Login Tests", () => {
|
7
|
-
|
17
|
+
describe("Better Auth - Signup and Login Tests", async () => {
|
18
|
+
const providerId = "test";
|
19
|
+
const clientId = "test-client-id";
|
20
|
+
const clientSecret = "test-client-secret";
|
21
|
+
const server = new OAuth2Server();
|
22
|
+
await server.start();
|
23
|
+
const oauthPort = Number(server.issuer.url?.split(":")[2]!);
|
24
|
+
|
25
|
+
let auth: ReturnType<
|
26
|
+
typeof betterAuth<{
|
27
|
+
plugins: ReturnType<typeof jazzPlugin | typeof genericOAuth>[];
|
28
|
+
}>
|
29
|
+
>;
|
8
30
|
let accountCreationSpy: Mock;
|
9
31
|
let verificationCreationSpy: Mock;
|
10
32
|
|
33
|
+
beforeAll(async () => {
|
34
|
+
await server.issuer.keys.generate("RS256");
|
35
|
+
|
36
|
+
server.service.on("beforeUserinfo", (userInfoResponse) => {
|
37
|
+
userInfoResponse.body = {
|
38
|
+
email: "oauth2@test.com",
|
39
|
+
name: "OAuth2 Test",
|
40
|
+
sub: "oauth2",
|
41
|
+
picture: "https://test.com/picture.png",
|
42
|
+
email_verified: true,
|
43
|
+
};
|
44
|
+
userInfoResponse.statusCode = 200;
|
45
|
+
});
|
46
|
+
});
|
47
|
+
|
48
|
+
afterAll(async () => {
|
49
|
+
await server.stop();
|
50
|
+
});
|
51
|
+
|
11
52
|
beforeEach(() => {
|
12
53
|
accountCreationSpy = vi.fn();
|
13
54
|
verificationCreationSpy = vi.fn();
|
@@ -20,7 +61,22 @@ describe("Better Auth - Signup and Login Tests", () => {
|
|
20
61
|
verification: [],
|
21
62
|
account: [],
|
22
63
|
}),
|
23
|
-
|
64
|
+
baseURL: "http://localhost:3000",
|
65
|
+
plugins: [
|
66
|
+
jazzPlugin(),
|
67
|
+
genericOAuth({
|
68
|
+
config: [
|
69
|
+
{
|
70
|
+
providerId,
|
71
|
+
discoveryUrl: `http://localhost:${oauthPort}/.well-known/openid-configuration`,
|
72
|
+
authorizationUrl: `http://localhost:${oauthPort}/authorize`,
|
73
|
+
clientId: clientId,
|
74
|
+
clientSecret: clientSecret,
|
75
|
+
pkce: true,
|
76
|
+
},
|
77
|
+
],
|
78
|
+
}),
|
79
|
+
],
|
24
80
|
emailAndPassword: {
|
25
81
|
enabled: true,
|
26
82
|
requireEmailVerification: false, // Disable for testing
|
@@ -219,8 +275,40 @@ describe("Better Auth - Signup and Login Tests", () => {
|
|
219
275
|
);
|
220
276
|
});
|
221
277
|
|
222
|
-
it
|
223
|
-
|
224
|
-
|
278
|
+
it("should create a new account with jazz auth when using social provider", async () => {
|
279
|
+
const response = await auth.api.signInSocial({
|
280
|
+
body: {
|
281
|
+
provider: providerId,
|
282
|
+
callbackURL: "http://localhost:3000/api/auth/sign-in/social/callback",
|
283
|
+
newUserCallbackURL:
|
284
|
+
"http://localhost:3000/api/auth/sign-in/social/callback",
|
285
|
+
},
|
286
|
+
headers: {
|
287
|
+
"x-jazz-auth": JSON.stringify({
|
288
|
+
accountID: "123",
|
289
|
+
secretSeed: [1, 2, 3],
|
290
|
+
accountSecret: "123",
|
291
|
+
}),
|
292
|
+
},
|
293
|
+
});
|
294
|
+
|
295
|
+
const oauthres = await fetch(response.url as string, {
|
296
|
+
redirect: "manual",
|
297
|
+
});
|
298
|
+
|
299
|
+
const resURL = new URL(oauthres.headers.get("Location") as string);
|
300
|
+
|
301
|
+
const callbackRes = await auth.handler(new Request(resURL));
|
302
|
+
|
303
|
+
expect(callbackRes.headers.getSetCookie()[0]).toMatch(
|
304
|
+
"better-auth.session_token=",
|
305
|
+
);
|
306
|
+
|
307
|
+
expect(accountCreationSpy).toHaveBeenCalledTimes(1);
|
308
|
+
expect(accountCreationSpy).toHaveBeenCalledWith(
|
309
|
+
expect.objectContaining({ accountID: "123" }),
|
310
|
+
expect.any(Object),
|
311
|
+
);
|
312
|
+
});
|
225
313
|
});
|
226
314
|
});
|
@@ -214,6 +214,14 @@ export function provideBrowserLockSession(
|
|
214
214
|
accountID: ID<Account> | AgentID,
|
215
215
|
crypto: CryptoProvider,
|
216
216
|
) {
|
217
|
+
if (typeof navigator === "undefined" || !navigator.locks?.request) {
|
218
|
+
// Fallback to random session ID for each tab session
|
219
|
+
return Promise.resolve({
|
220
|
+
sessionID: crypto.newRandomSessionID(accountID as RawAccountID | AgentID),
|
221
|
+
sessionDone: () => {},
|
222
|
+
});
|
223
|
+
}
|
224
|
+
|
217
225
|
let sessionDone!: () => void;
|
218
226
|
const donePromise = new Promise<void>((resolve) => {
|
219
227
|
sessionDone = resolve;
|
@@ -274,7 +274,9 @@ export class Account extends CoValueBase implements CoValue {
|
|
274
274
|
|
275
275
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
276
276
|
toJSON(): object | any[] {
|
277
|
-
return {
|
277
|
+
return {
|
278
|
+
$jazz: { id: this.$jazz.id },
|
279
|
+
};
|
278
280
|
}
|
279
281
|
|
280
282
|
[inspect]() {
|
@@ -228,6 +228,7 @@ export class CoFeed<out Item = any> extends CoValueBase implements CoValue {
|
|
228
228
|
* @category
|
229
229
|
*/
|
230
230
|
toJSON(): {
|
231
|
+
$jazz: { id: string };
|
231
232
|
[key: string]: unknown;
|
232
233
|
in: { [key: string]: unknown };
|
233
234
|
} {
|
@@ -240,6 +241,7 @@ export class CoFeed<out Item = any> extends CoValueBase implements CoValue {
|
|
240
241
|
: (v: unknown) => v && (v as CoValue).$jazz.id;
|
241
242
|
|
242
243
|
return {
|
244
|
+
$jazz: { id: this.$jazz.id },
|
243
245
|
...Object.fromEntries(
|
244
246
|
Object.entries(this).map(([account, entry]) => [
|
245
247
|
account,
|
@@ -257,6 +259,7 @@ export class CoFeed<out Item = any> extends CoValueBase implements CoValue {
|
|
257
259
|
|
258
260
|
/** @internal */
|
259
261
|
[inspect](): {
|
262
|
+
$jazz: { id: string };
|
260
263
|
[key: string]: unknown;
|
261
264
|
in: { [key: string]: unknown };
|
262
265
|
} {
|
@@ -928,6 +931,7 @@ export class FileStream extends CoValueBase implements CoValue {
|
|
928
931
|
* @category Content
|
929
932
|
*/
|
930
933
|
toJSON(): {
|
934
|
+
$jazz: { id: string };
|
931
935
|
mimeType?: string;
|
932
936
|
totalSizeBytes?: number;
|
933
937
|
fileName?: string;
|
@@ -935,6 +939,7 @@ export class FileStream extends CoValueBase implements CoValue {
|
|
935
939
|
finished?: boolean;
|
936
940
|
} {
|
937
941
|
return {
|
942
|
+
$jazz: { id: this.$jazz.id },
|
938
943
|
...this.getChunks(),
|
939
944
|
};
|
940
945
|
}
|
@@ -185,7 +185,9 @@ export class CoMap extends CoValueBase implements CoValue {
|
|
185
185
|
*/
|
186
186
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
187
187
|
toJSON(_key?: string, processedValues?: ID<CoValue>[]): any {
|
188
|
-
const result = {
|
188
|
+
const result = {
|
189
|
+
$jazz: { id: this.$jazz.id },
|
190
|
+
} as Record<string, any>;
|
189
191
|
|
190
192
|
for (const key of this.$jazz.raw.keys()) {
|
191
193
|
const tKey = key as CoKeys<this>;
|
@@ -1,4 +1,5 @@
|
|
1
1
|
export { Loaded as loaded } from "./zodSchema.js";
|
2
|
+
export { Loaded as output } from "./zodSchema.js";
|
2
3
|
export { CoMapSchema as Map } from "./schemaTypes/CoMapSchema.js";
|
3
4
|
export { CoRecordSchema as Record } from "./schemaTypes/CoRecordSchema.js";
|
4
5
|
export { CoListSchema as List } from "./schemaTypes/CoListSchema.js";
|
@@ -6,6 +7,7 @@ export { CoFeedSchema as Feed } from "./schemaTypes/CoFeedSchema.js";
|
|
6
7
|
export { PlainTextSchema as PlainText } from "./schemaTypes/PlainTextSchema.js";
|
7
8
|
export { RichTextSchema as RichText } from "./schemaTypes/RichTextSchema.js";
|
8
9
|
export { FileStreamSchema as FileStream } from "./schemaTypes/FileStreamSchema.js";
|
10
|
+
export { CoInput as input } from "./typeConverters/CoFieldSchemaInit.js";
|
9
11
|
export {
|
10
12
|
AccountSchema as Account,
|
11
13
|
CoProfileSchema as Profile,
|
@@ -131,6 +131,25 @@ export interface CoMapSchema<
|
|
131
131
|
R
|
132
132
|
> | null>;
|
133
133
|
|
134
|
+
/**
|
135
|
+
* @deprecated Use `co.map().catchall` will be removed in an upcoming version.
|
136
|
+
*
|
137
|
+
* Use a `co.record` nested inside a `co.map` if you need to store key-value properties.
|
138
|
+
*
|
139
|
+
* @example
|
140
|
+
* ```ts
|
141
|
+
* // Instead of:
|
142
|
+
* const Image = co.map({
|
143
|
+
* original: co.fileStream(),
|
144
|
+
* }).catchall(co.fileStream());
|
145
|
+
*
|
146
|
+
* // Use:
|
147
|
+
* const Image = co.map({
|
148
|
+
* original: co.fileStream(),
|
149
|
+
* resolutions: co.record(z.string(), co.fileStream()),
|
150
|
+
* });
|
151
|
+
* ```
|
152
|
+
*/
|
134
153
|
catchall<T extends AnyZodOrCoValueSchema>(schema: T): CoMapSchema<Shape, T>;
|
135
154
|
|
136
155
|
withMigration(
|
@@ -6,7 +6,6 @@ import {
|
|
6
6
|
CoreCoMapSchema,
|
7
7
|
CoreCoRecordSchema,
|
8
8
|
CorePlainTextSchema,
|
9
|
-
PartialOnUndefined,
|
10
9
|
Simplify,
|
11
10
|
} from "../../../internal.js";
|
12
11
|
import { CoreCoOptionalSchema } from "../schemaTypes/CoOptionalSchema.js";
|
@@ -76,3 +75,11 @@ export type CoListSchemaInit<T extends AnyZodOrCoValueSchema> = Simplify<
|
|
76
75
|
export type CoFeedSchemaInit<T extends AnyZodOrCoValueSchema> = Simplify<
|
77
76
|
ReadonlyArray<CoFieldSchemaInit<T>>
|
78
77
|
>;
|
78
|
+
|
79
|
+
/**
|
80
|
+
* The convenience type for extracting the init type of a CoValue schema.
|
81
|
+
*/
|
82
|
+
export type CoInput<S extends CoValueClass | AnyZodOrCoValueSchema> =
|
83
|
+
S extends CoreCoValueSchema
|
84
|
+
? Exclude<CoFieldSchemaInit<S>, Loaded<S>>
|
85
|
+
: CoFieldSchemaInit<S>;
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import { JsonValue } from "cojson";
|
2
|
-
import { PartialOnUndefined } from "../../../internal.js";
|
3
2
|
import { z } from "../zodReExport.js";
|
4
3
|
|
5
4
|
// Copied from https://github.com/colinhacks/zod/blob/7e7e3461aceecf3633e158df50d6bc852e7cdf45/packages/zod/src/v4/core/schemas.ts#L1591,
|