@convex-dev/better-auth 0.11.5 → 0.12.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.
Files changed (103) hide show
  1. package/dist/auth-options.d.ts.map +1 -1
  2. package/dist/auth-options.js +1 -0
  3. package/dist/auth-options.js.map +1 -1
  4. package/dist/client/adapter-utils.d.ts +8 -2
  5. package/dist/client/adapter-utils.d.ts.map +1 -1
  6. package/dist/client/adapter-utils.js +8 -3
  7. package/dist/client/adapter-utils.js.map +1 -1
  8. package/dist/client/adapter.d.ts +0 -1
  9. package/dist/client/adapter.d.ts.map +1 -1
  10. package/dist/client/adapter.js +5 -0
  11. package/dist/client/adapter.js.map +1 -1
  12. package/dist/client/create-api.d.ts +6 -0
  13. package/dist/client/create-api.d.ts.map +1 -1
  14. package/dist/client/create-api.js +1 -0
  15. package/dist/client/create-api.js.map +1 -1
  16. package/dist/client/create-client.d.ts +0 -2
  17. package/dist/client/create-client.d.ts.map +1 -1
  18. package/dist/client/create-client.js.map +1 -1
  19. package/dist/client/create-schema.d.ts.map +1 -1
  20. package/dist/client/create-schema.js +38 -8
  21. package/dist/client/create-schema.js.map +1 -1
  22. package/dist/component/_generated/api.d.ts +0 -2
  23. package/dist/component/_generated/api.d.ts.map +1 -1
  24. package/dist/component/_generated/api.js.map +1 -1
  25. package/dist/component/_generated/component.d.ts +543 -31
  26. package/dist/component/_generated/component.d.ts.map +1 -1
  27. package/dist/component/adapter.d.ts +6 -0
  28. package/dist/component/adapter.d.ts.map +1 -1
  29. package/dist/component/schema.d.ts +9 -4
  30. package/dist/component/schema.d.ts.map +1 -1
  31. package/dist/component/schema.js +4 -2
  32. package/dist/component/schema.js.map +1 -1
  33. package/dist/component/testProfiles/adapterAdditionalFields.d.ts +6 -0
  34. package/dist/component/testProfiles/adapterAdditionalFields.d.ts.map +1 -1
  35. package/dist/component/testProfiles/adapterOrganizationJoins.d.ts +6 -0
  36. package/dist/component/testProfiles/adapterOrganizationJoins.d.ts.map +1 -1
  37. package/dist/component/testProfiles/adapterPluginTable.d.ts +6 -0
  38. package/dist/component/testProfiles/adapterPluginTable.d.ts.map +1 -1
  39. package/dist/component/testProfiles/adapterRenameField.d.ts +6 -0
  40. package/dist/component/testProfiles/adapterRenameField.d.ts.map +1 -1
  41. package/dist/component/testProfiles/adapterRenameUserCustom.d.ts +6 -0
  42. package/dist/component/testProfiles/adapterRenameUserCustom.d.ts.map +1 -1
  43. package/dist/component/testProfiles/adapterRenameUserTable.d.ts +6 -0
  44. package/dist/component/testProfiles/adapterRenameUserTable.d.ts.map +1 -1
  45. package/dist/component/testProfiles/schema.profile-additional-fields.d.ts +3 -1
  46. package/dist/component/testProfiles/schema.profile-additional-fields.d.ts.map +1 -1
  47. package/dist/component/testProfiles/schema.profile-plugin-table.d.ts +3 -1
  48. package/dist/component/testProfiles/schema.profile-plugin-table.d.ts.map +1 -1
  49. package/dist/plugins/convex/client.d.ts +1 -0
  50. package/dist/plugins/convex/client.d.ts.map +1 -1
  51. package/dist/plugins/convex/client.js +2 -0
  52. package/dist/plugins/convex/client.js.map +1 -1
  53. package/dist/plugins/convex/index.d.ts +2 -1
  54. package/dist/plugins/convex/index.d.ts.map +1 -1
  55. package/dist/plugins/convex/index.js +15 -2
  56. package/dist/plugins/convex/index.js.map +1 -1
  57. package/dist/plugins/cross-domain/client.d.ts +1 -12
  58. package/dist/plugins/cross-domain/client.d.ts.map +1 -1
  59. package/dist/plugins/cross-domain/client.js +35 -27
  60. package/dist/plugins/cross-domain/client.js.map +1 -1
  61. package/dist/plugins/cross-domain/index.d.ts +1 -0
  62. package/dist/plugins/cross-domain/index.d.ts.map +1 -1
  63. package/dist/plugins/cross-domain/index.js +15 -4
  64. package/dist/plugins/cross-domain/index.js.map +1 -1
  65. package/dist/test/adapter-factory/basic.d.ts +4 -0
  66. package/dist/test/adapter-factory/basic.d.ts.map +1 -1
  67. package/dist/test/adapter-factory/convex-custom.d.ts +1 -1
  68. package/dist/test/adapter-factory/convex-custom.d.ts.map +1 -1
  69. package/dist/test/adapter-factory/convex-custom.js +20 -0
  70. package/dist/test/adapter-factory/convex-custom.js.map +1 -1
  71. package/dist/utils/index.d.ts +1 -0
  72. package/dist/utils/index.d.ts.map +1 -1
  73. package/dist/utils/index.js +6 -1
  74. package/dist/utils/index.js.map +1 -1
  75. package/dist/version.d.ts +2 -0
  76. package/dist/version.d.ts.map +1 -0
  77. package/dist/version.js +2 -0
  78. package/dist/version.js.map +1 -0
  79. package/package.json +6 -6
  80. package/src/auth-options.ts +1 -0
  81. package/src/client/adapter-utils.ts +13 -5
  82. package/src/client/adapter.test.ts +225 -2
  83. package/src/client/adapter.ts +7 -1
  84. package/src/client/create-api.ts +3 -0
  85. package/src/client/create-client.ts +0 -2
  86. package/src/client/create-schema.ts +46 -8
  87. package/src/component/_generated/api.ts +0 -2
  88. package/src/component/_generated/component.ts +718 -38
  89. package/src/component/schema.ts +5 -3
  90. package/src/plugins/convex/client.ts +2 -0
  91. package/src/plugins/convex/index.ts +16 -3
  92. package/src/plugins/cross-domain/client.test.ts +58 -28
  93. package/src/plugins/cross-domain/client.ts +44 -45
  94. package/src/plugins/cross-domain/index.test.ts +129 -51
  95. package/src/plugins/cross-domain/index.ts +20 -7
  96. package/src/test/adapter-factory/convex-custom.ts +23 -0
  97. package/src/utils/index.ts +7 -1
  98. package/src/version.ts +1 -0
  99. package/dist/component/adapterTest.d.ts +0 -3
  100. package/dist/component/adapterTest.d.ts.map +0 -1
  101. package/dist/component/adapterTest.js +0 -202
  102. package/dist/component/adapterTest.js.map +0 -1
  103. package/src/component/adapterTest.ts +0 -275
@@ -759,5 +759,28 @@ export const convexCustomTestSuite = createTestSuite(
759
759
  ).toEqual(user);
760
760
  expect(typeof user.createdAt).toBe("number");
761
761
  },
762
+
763
+ "should reject case-insensitive where clauses": async () => {
764
+ await adapter.create({
765
+ model: "user",
766
+ data: {
767
+ name: "foo",
768
+ email: "foo@bar.com",
769
+ },
770
+ });
771
+ await expect(
772
+ adapter.findOne({
773
+ model: "user",
774
+ where: [
775
+ {
776
+ field: "email",
777
+ value: "FOO@BAR.COM",
778
+ operator: "eq",
779
+ mode: "insensitive",
780
+ },
781
+ ],
782
+ }),
783
+ ).rejects.toThrow(/mode: "insensitive"/);
784
+ },
762
785
  }),
763
786
  );
@@ -122,6 +122,7 @@ export const requireRunMutationCtx = <DataModel extends GenericDataModel>(
122
122
  };
123
123
 
124
124
  export type GetTokenOptions = {
125
+ basePath?: string;
125
126
  forceRefresh?: boolean;
126
127
  cookiePrefix?: string;
127
128
  jwtCache?: {
@@ -136,9 +137,14 @@ export const getToken = async (
136
137
  headers: Headers,
137
138
  opts?: GetTokenOptions
138
139
  ) => {
140
+ headers.set("host", new URL(siteUrl).host)
139
141
  const fetchToken = async () => {
142
+ const basePath = opts?.basePath
143
+ ? (opts.basePath.startsWith("/") ? opts.basePath : `/${opts.basePath}`)
144
+ .replace(/\/+$/, "")
145
+ : "/api/auth";
140
146
  const { data } = await betterFetch<{ token: string }>(
141
- "/api/auth/convex/token",
147
+ `${basePath}/convex/token`,
142
148
  {
143
149
  baseURL: siteUrl,
144
150
  headers,
package/src/version.ts ADDED
@@ -0,0 +1 @@
1
+ export const VERSION = "0.12.1";
@@ -1,3 +0,0 @@
1
- import type { EmptyObject } from "convex-helpers";
2
- export declare const runTests: import("convex/server").RegisteredAction<"public", EmptyObject, Promise<void>>;
3
- //# sourceMappingURL=adapterTest.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"adapterTest.d.ts","sourceRoot":"","sources":["../../src/component/adapterTest.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAyGlD,eAAO,MAAM,QAAQ,gFAoKpB,CAAC"}
@@ -1,202 +0,0 @@
1
- import { createClient } from "../client/index.js";
2
- import { internal } from "./_generated/api.js";
3
- import { action } from "./_generated/server.js";
4
- // Tests need to run inside of a Convex function to use the Convex adapter.
5
- // Test dependencies are dynamically imported to keep them out of the
6
- // production bundle. convex-test runs in the vitest process, so vitest
7
- // globals are available through dynamic imports.
8
- const NORMAL_DISABLED_TESTS = [
9
- // dynamic-schema-plugin-table/dynamic-schema-additional-fields:
10
- // Convex validators are static in this harness, so runtime schema mutation
11
- // tests are validated in dedicated profiles instead.
12
- "create - should apply default values to fields",
13
- "create - should return null for nullable foreign keys",
14
- "create - should support arrays",
15
- "create - should support json",
16
- // convex-id-generation:
17
- // Convex controls generated IDs at write time.
18
- "create - should use generateId if provided",
19
- // offset-unsupported:
20
- // Convex adapter rejects offset pagination.
21
- "findMany - should be able to perform a complex limited join",
22
- "findMany - should find many models with limit and offset",
23
- "findMany - should find many models with offset",
24
- "findMany - should find many models with sortBy and limit and offset",
25
- "findMany - should find many models with sortBy and limit and offset and where",
26
- "findMany - should find many models with sortBy and offset",
27
- "findMany - should find many with both one-to-one and one-to-many joins",
28
- "findMany - should find many with join and offset",
29
- "findMany - should find many with join, where, limit, and offset",
30
- "findMany - should find many with one-to-one join",
31
- "findMany - should handle mixed joins correctly when some are missing",
32
- "findMany - should return empty array when base records don't exist with joins",
33
- "findMany - should return null for one-to-one join when joined records don't exist",
34
- "findMany - should select fields with one-to-one join",
35
- // profile-specific coverage:
36
- // These are intentionally exercised in dedicated profile suites.
37
- "findOne - backwards join with modified field name (session base, users-table join)",
38
- "findOne - multiple joins should return result even when some joined tables have no matching rows",
39
- "findOne - should find a model with modified field name",
40
- "findOne - should find a model with modified model name",
41
- "findOne - should join a model with modified field name",
42
- "findOne - should not apply defaultValue if value not found",
43
- "findOne - should return an object for one-to-one joins",
44
- "findOne - should return null for failed base model lookup that has joins",
45
- "findOne - should return null for one-to-one join when joined record doesn't exist",
46
- "findOne - should select fields with one-to-one join",
47
- "findOne - should work with both one-to-one and one-to-many joins",
48
- ];
49
- const toDisableMap = (testNames) => Object.fromEntries(testNames.map((testName) => [testName, true]));
50
- const toEnableOnlyMap = (testNames) => ({
51
- ALL: true,
52
- ...Object.fromEntries(testNames.map((testName) => [testName, false])),
53
- });
54
- const UUID_SUITE_TESTS = ["init - tests"];
55
- const getOverrideBetterAuthOptions = (opts) => ({
56
- ...opts,
57
- advanced: {
58
- ...opts.advanced,
59
- database: {
60
- ...opts.advanced?.database,
61
- generateId: "uuid",
62
- },
63
- },
64
- });
65
- const internalWithTestProfiles = internal;
66
- const baseProfileApi = {
67
- adapter: internalWithTestProfiles.adapter,
68
- adapterTest: internalWithTestProfiles.adapterTest,
69
- };
70
- const profileApi = (name) => {
71
- return { adapter: internalWithTestProfiles.testProfiles[name] };
72
- };
73
- const additionalFieldsProfileApi = profileApi("adapterAdditionalFields");
74
- const pluginTableProfileApi = profileApi("adapterPluginTable");
75
- const renameFieldProfileApi = profileApi("adapterRenameField");
76
- const renameUserCustomProfileApi = profileApi("adapterRenameUserCustom");
77
- const renameUserTableProfileApi = profileApi("adapterRenameUserTable");
78
- const organizationJoinsProfileApi = profileApi("adapterOrganizationJoins");
79
- export const runTests = action(async (ctx, _args) => {
80
- const testUtilsImport = "@better-auth/test-utils/adapter";
81
- const { testAdapter, transactionsTestSuite, uuidTestSuite } = await import(testUtilsImport);
82
- const adapterFactoryImport = "../test/adapter-factory/index.js";
83
- const { coreNormalTestSuite, coreAuthFlowTestSuite, additionalFieldsNormalTestSuite, additionalFieldsAuthFlowTestSuite, pluginTableNormalTestSuite, renameFieldAndJoinTestSuite, renameModelUserCustomTestSuite, renameModelUserTableTestSuite, multiJoinsMissingRowsTestSuite, convexCustomTestSuite, } = await import(adapterFactoryImport);
84
- const baseProfileClient = createClient(baseProfileApi, {
85
- verbose: false,
86
- });
87
- const additionalFieldsProfileClient = createClient(additionalFieldsProfileApi, {
88
- verbose: false,
89
- });
90
- const pluginTableProfileClient = createClient(pluginTableProfileApi, {
91
- verbose: false,
92
- });
93
- const renameFieldProfileClient = createClient(renameFieldProfileApi, {
94
- verbose: false,
95
- });
96
- const renameUserCustomProfileClient = createClient(renameUserCustomProfileApi, {
97
- verbose: false,
98
- });
99
- const renameUserTableProfileClient = createClient(renameUserTableProfileApi, {
100
- verbose: false,
101
- });
102
- const organizationJoinsProfileClient = createClient(organizationJoinsProfileApi, {
103
- verbose: false,
104
- });
105
- const { execute: executeBaseProfile } = await testAdapter({
106
- adapter: () => {
107
- return baseProfileClient.adapter(ctx);
108
- },
109
- runMigrations: () => {
110
- // Convex schema is static — no migrations needed.
111
- },
112
- overrideBetterAuthOptions: getOverrideBetterAuthOptions,
113
- tests: [
114
- coreNormalTestSuite({
115
- disableTests: toDisableMap(NORMAL_DISABLED_TESTS),
116
- }),
117
- uuidTestSuite({
118
- disableTests: toEnableOnlyMap(UUID_SUITE_TESTS),
119
- }),
120
- transactionsTestSuite({ disableTests: { ALL: true } }),
121
- coreAuthFlowTestSuite(),
122
- convexCustomTestSuite(),
123
- ],
124
- });
125
- const { execute: executeAdditionalFieldsProfile } = await testAdapter({
126
- adapter: () => {
127
- return additionalFieldsProfileClient.adapter(ctx);
128
- },
129
- runMigrations: () => {
130
- // Convex schema is static — no migrations needed.
131
- },
132
- overrideBetterAuthOptions: getOverrideBetterAuthOptions,
133
- prefixTests: "profile:additional-fields",
134
- tests: [
135
- additionalFieldsNormalTestSuite(),
136
- additionalFieldsAuthFlowTestSuite(),
137
- ],
138
- });
139
- const { execute: executePluginTableProfile } = await testAdapter({
140
- adapter: () => {
141
- return pluginTableProfileClient.adapter(ctx);
142
- },
143
- runMigrations: () => {
144
- // Convex schema is static — no migrations needed.
145
- },
146
- overrideBetterAuthOptions: getOverrideBetterAuthOptions,
147
- prefixTests: "profile:plugin-table",
148
- tests: [pluginTableNormalTestSuite()],
149
- });
150
- const { execute: executeRenameFieldProfile } = await testAdapter({
151
- adapter: () => {
152
- return renameFieldProfileClient.adapter(ctx);
153
- },
154
- runMigrations: () => {
155
- // Convex schema is static — no migrations needed.
156
- },
157
- overrideBetterAuthOptions: getOverrideBetterAuthOptions,
158
- prefixTests: "profile:rename-field-join",
159
- tests: [renameFieldAndJoinTestSuite()],
160
- });
161
- const { execute: executeRenameUserCustomProfile } = await testAdapter({
162
- adapter: () => {
163
- return renameUserCustomProfileClient.adapter(ctx);
164
- },
165
- runMigrations: () => {
166
- // Convex schema is static — no migrations needed.
167
- },
168
- overrideBetterAuthOptions: getOverrideBetterAuthOptions,
169
- prefixTests: "profile:rename-user-custom",
170
- tests: [renameModelUserCustomTestSuite()],
171
- });
172
- const { execute: executeRenameUserTableProfile } = await testAdapter({
173
- adapter: () => {
174
- return renameUserTableProfileClient.adapter(ctx);
175
- },
176
- runMigrations: () => {
177
- // Convex schema is static — no migrations needed.
178
- },
179
- overrideBetterAuthOptions: getOverrideBetterAuthOptions,
180
- prefixTests: "profile:rename-user-table",
181
- tests: [renameModelUserTableTestSuite()],
182
- });
183
- const { execute: executeOrganizationJoinsProfile } = await testAdapter({
184
- adapter: () => {
185
- return organizationJoinsProfileClient.adapter(ctx);
186
- },
187
- runMigrations: () => {
188
- // Convex schema is static — no migrations needed.
189
- },
190
- overrideBetterAuthOptions: getOverrideBetterAuthOptions,
191
- prefixTests: "profile:organization-joins",
192
- tests: [multiJoinsMissingRowsTestSuite()],
193
- });
194
- await executeBaseProfile();
195
- await executeAdditionalFieldsProfile();
196
- await executePluginTableProfile();
197
- await executeRenameFieldProfile();
198
- await executeRenameUserCustomProfile();
199
- await executeRenameUserTableProfile();
200
- await executeOrganizationJoinsProfile();
201
- });
202
- //# sourceMappingURL=adapterTest.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"adapterTest.js","sourceRoot":"","sources":["../../src/component/adapterTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAOhD,2EAA2E;AAC3E,qEAAqE;AACrE,uEAAuE;AACvE,iDAAiD;AAEjD,MAAM,qBAAqB,GAAG;IAC5B,gEAAg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B,EAAE,4BAA4B;QACvD,WAAW,EAAE,4BAA4B;QACzC,KAAK,EAAE,CAAC,8BAA8B,EAAE,CAAC;KAC1C,CAAC,CAAC;IAEH,MAAM,EAAE,OAAO,EAAE,6BAA6B,EAAE,GAAG,MAAM,WAAW,CAAC;QACnE,OAAO,EAAE,GAAG,EAAE;YACZ,OAAO,4BAA4B,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACnD,CAAC;QACD,aAAa,EAAE,GAAG,EAAE;YAClB,kDAAkD;QACpD,CAAC;QACD,yBAAyB,EAAE,4BAA4B;QACvD,WAAW,EAAE,2BAA2B;QACxC,KAAK,EAAE,CAAC,6BAA6B,EAAE,CAAC;KACzC,CAAC,CAAC;IAEH,MAAM,EAAE,OAAO,EAAE,+BAA+B,EAAE,GAAG,MAAM,WAAW,CAAC;QACrE,OAAO,EAAE,GAAG,EAAE;YACZ,OAAO,8BAA8B,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACrD,CAAC;QACD,aAAa,EAAE,GAAG,EAAE;YAClB,kDAAkD;QACpD,CAAC;QACD,yBAAyB,EAAE,4BAA4B;QACvD,WAAW,EAAE,4BAA4B;QACzC,KAAK,EAAE,CAAC,8BAA8B,EAAE,CAAC;KAC1C,CAAC,CAAC;IAEH,MAAM,kBAAkB,EAAE,CAAC;IAC3B,MAAM,8BAA8B,EAAE,CAAC;IACvC,MAAM,yBAAyB,EAAE,CAAC;IAClC,MAAM,yBAAyB,EAAE,CAAC;IAClC,MAAM,8BAA8B,EAAE,CAAC;IACvC,MAAM,6BAA6B,EAAE,CAAC;IACtC,MAAM,+BAA+B,EAAE,CAAC;AAC1C,CAAC,CACF,CAAC"}
@@ -1,275 +0,0 @@
1
- import { createClient } from "../client/index.js";
2
- import { internal } from "./_generated/api.js";
3
- import { action } from "./_generated/server.js";
4
- import type { GenericActionCtx } from "convex/server";
5
- import type { DataModel } from "./_generated/dataModel.js";
6
- import type { EmptyObject } from "convex-helpers";
7
- import type { BetterAuthOptions } from "better-auth";
8
- import type { ComponentApi } from "./_generated/component.js";
9
-
10
- // Tests need to run inside of a Convex function to use the Convex adapter.
11
- // Test dependencies are dynamically imported to keep them out of the
12
- // production bundle. convex-test runs in the vitest process, so vitest
13
- // globals are available through dynamic imports.
14
-
15
- const NORMAL_DISABLED_TESTS = [
16
- // dynamic-schema-plugin-table/dynamic-schema-additional-fields:
17
- // Convex validators are static in this harness, so runtime schema mutation
18
- // tests are validated in dedicated profiles instead.
19
- "create - should apply default values to fields",
20
- "create - should return null for nullable foreign keys",
21
- "create - should support arrays",
22
- "create - should support json",
23
- // convex-id-generation:
24
- // Convex controls generated IDs at write time.
25
- "create - should use generateId if provided",
26
- // offset-unsupported:
27
- // Convex adapter rejects offset pagination.
28
- "findMany - should be able to perform a complex limited join",
29
- "findMany - should find many models with limit and offset",
30
- "findMany - should find many models with offset",
31
- "findMany - should find many models with sortBy and limit and offset",
32
- "findMany - should find many models with sortBy and limit and offset and where",
33
- "findMany - should find many models with sortBy and offset",
34
- "findMany - should find many with both one-to-one and one-to-many joins",
35
- "findMany - should find many with join and offset",
36
- "findMany - should find many with join, where, limit, and offset",
37
- "findMany - should find many with one-to-one join",
38
- "findMany - should handle mixed joins correctly when some are missing",
39
- "findMany - should return empty array when base records don't exist with joins",
40
- "findMany - should return null for one-to-one join when joined records don't exist",
41
- "findMany - should select fields with one-to-one join",
42
- // profile-specific coverage:
43
- // These are intentionally exercised in dedicated profile suites.
44
- "findOne - backwards join with modified field name (session base, users-table join)",
45
- "findOne - multiple joins should return result even when some joined tables have no matching rows",
46
- "findOne - should find a model with modified field name",
47
- "findOne - should find a model with modified model name",
48
- "findOne - should join a model with modified field name",
49
- "findOne - should not apply defaultValue if value not found",
50
- "findOne - should return an object for one-to-one joins",
51
- "findOne - should return null for failed base model lookup that has joins",
52
- "findOne - should return null for one-to-one join when joined record doesn't exist",
53
- "findOne - should select fields with one-to-one join",
54
- "findOne - should work with both one-to-one and one-to-many joins",
55
- ] as const;
56
-
57
- const toDisableMap = (testNames: readonly string[]) =>
58
- Object.fromEntries(testNames.map((testName) => [testName, true]));
59
-
60
- const toEnableOnlyMap = (testNames: readonly string[]) => ({
61
- ALL: true,
62
- ...Object.fromEntries(testNames.map((testName) => [testName, false])),
63
- });
64
-
65
- const UUID_SUITE_TESTS = ["init - tests"] as const;
66
-
67
- const getOverrideBetterAuthOptions = (opts: BetterAuthOptions) => ({
68
- ...opts,
69
- advanced: {
70
- ...opts.advanced,
71
- database: {
72
- ...opts.advanced?.database,
73
- generateId: "uuid",
74
- },
75
- },
76
- });
77
-
78
- type AdapterModule = ComponentApi["adapter"];
79
- type TestProfileName =
80
- | "adapterAdditionalFields"
81
- | "adapterPluginTable"
82
- | "adapterRenameField"
83
- | "adapterRenameUserCustom"
84
- | "adapterRenameUserTable"
85
- | "adapterOrganizationJoins";
86
-
87
- type InternalWithTestProfiles = {
88
- adapter: AdapterModule;
89
- adapterTest?: ComponentApi["adapterTest"];
90
- testProfiles: Record<TestProfileName, AdapterModule>;
91
- };
92
-
93
- const internalWithTestProfiles = internal as unknown as InternalWithTestProfiles;
94
-
95
- const baseProfileApi = {
96
- adapter: internalWithTestProfiles.adapter,
97
- adapterTest: internalWithTestProfiles.adapterTest,
98
- };
99
-
100
- const profileApi = (name: TestProfileName): { adapter: AdapterModule } => {
101
- return { adapter: internalWithTestProfiles.testProfiles[name] };
102
- };
103
-
104
- const additionalFieldsProfileApi = profileApi("adapterAdditionalFields");
105
- const pluginTableProfileApi = profileApi("adapterPluginTable");
106
- const renameFieldProfileApi = profileApi("adapterRenameField");
107
- const renameUserCustomProfileApi = profileApi("adapterRenameUserCustom");
108
- const renameUserTableProfileApi = profileApi("adapterRenameUserTable");
109
- const organizationJoinsProfileApi = profileApi("adapterOrganizationJoins");
110
-
111
- export const runTests = action(
112
- async (ctx: GenericActionCtx<DataModel>, _args: EmptyObject) => {
113
- const testUtilsImport = "@better-auth/test-utils/adapter";
114
- const { testAdapter, transactionsTestSuite, uuidTestSuite } = await import(
115
- testUtilsImport
116
- );
117
- const adapterFactoryImport = "../test/adapter-factory/index.js";
118
- const {
119
- coreNormalTestSuite,
120
- coreAuthFlowTestSuite,
121
- additionalFieldsNormalTestSuite,
122
- additionalFieldsAuthFlowTestSuite,
123
- pluginTableNormalTestSuite,
124
- renameFieldAndJoinTestSuite,
125
- renameModelUserCustomTestSuite,
126
- renameModelUserTableTestSuite,
127
- multiJoinsMissingRowsTestSuite,
128
- convexCustomTestSuite,
129
- } = await import(adapterFactoryImport);
130
-
131
- const baseProfileClient = createClient<DataModel>(baseProfileApi, {
132
- verbose: false,
133
- });
134
- const additionalFieldsProfileClient = createClient<DataModel>(
135
- additionalFieldsProfileApi,
136
- {
137
- verbose: false,
138
- }
139
- );
140
- const pluginTableProfileClient = createClient<DataModel>(
141
- pluginTableProfileApi,
142
- {
143
- verbose: false,
144
- }
145
- );
146
- const renameFieldProfileClient = createClient<DataModel>(
147
- renameFieldProfileApi,
148
- {
149
- verbose: false,
150
- }
151
- );
152
- const renameUserCustomProfileClient = createClient<DataModel>(
153
- renameUserCustomProfileApi,
154
- {
155
- verbose: false,
156
- }
157
- );
158
- const renameUserTableProfileClient = createClient<DataModel>(
159
- renameUserTableProfileApi,
160
- {
161
- verbose: false,
162
- }
163
- );
164
- const organizationJoinsProfileClient = createClient<DataModel>(
165
- organizationJoinsProfileApi,
166
- {
167
- verbose: false,
168
- }
169
- );
170
-
171
- const { execute: executeBaseProfile } = await testAdapter({
172
- adapter: () => {
173
- return baseProfileClient.adapter(ctx);
174
- },
175
- runMigrations: () => {
176
- // Convex schema is static — no migrations needed.
177
- },
178
- overrideBetterAuthOptions: getOverrideBetterAuthOptions,
179
- tests: [
180
- coreNormalTestSuite({
181
- disableTests: toDisableMap(NORMAL_DISABLED_TESTS),
182
- }),
183
- uuidTestSuite({
184
- disableTests: toEnableOnlyMap(UUID_SUITE_TESTS),
185
- }),
186
- transactionsTestSuite({ disableTests: { ALL: true } }),
187
- coreAuthFlowTestSuite(),
188
- convexCustomTestSuite(),
189
- ],
190
- });
191
-
192
- const { execute: executeAdditionalFieldsProfile } = await testAdapter({
193
- adapter: () => {
194
- return additionalFieldsProfileClient.adapter(ctx);
195
- },
196
- runMigrations: () => {
197
- // Convex schema is static — no migrations needed.
198
- },
199
- overrideBetterAuthOptions: getOverrideBetterAuthOptions,
200
- prefixTests: "profile:additional-fields",
201
- tests: [
202
- additionalFieldsNormalTestSuite(),
203
- additionalFieldsAuthFlowTestSuite(),
204
- ],
205
- });
206
-
207
- const { execute: executePluginTableProfile } = await testAdapter({
208
- adapter: () => {
209
- return pluginTableProfileClient.adapter(ctx);
210
- },
211
- runMigrations: () => {
212
- // Convex schema is static — no migrations needed.
213
- },
214
- overrideBetterAuthOptions: getOverrideBetterAuthOptions,
215
- prefixTests: "profile:plugin-table",
216
- tests: [pluginTableNormalTestSuite()],
217
- });
218
-
219
- const { execute: executeRenameFieldProfile } = await testAdapter({
220
- adapter: () => {
221
- return renameFieldProfileClient.adapter(ctx);
222
- },
223
- runMigrations: () => {
224
- // Convex schema is static — no migrations needed.
225
- },
226
- overrideBetterAuthOptions: getOverrideBetterAuthOptions,
227
- prefixTests: "profile:rename-field-join",
228
- tests: [renameFieldAndJoinTestSuite()],
229
- });
230
-
231
- const { execute: executeRenameUserCustomProfile } = await testAdapter({
232
- adapter: () => {
233
- return renameUserCustomProfileClient.adapter(ctx);
234
- },
235
- runMigrations: () => {
236
- // Convex schema is static — no migrations needed.
237
- },
238
- overrideBetterAuthOptions: getOverrideBetterAuthOptions,
239
- prefixTests: "profile:rename-user-custom",
240
- tests: [renameModelUserCustomTestSuite()],
241
- });
242
-
243
- const { execute: executeRenameUserTableProfile } = await testAdapter({
244
- adapter: () => {
245
- return renameUserTableProfileClient.adapter(ctx);
246
- },
247
- runMigrations: () => {
248
- // Convex schema is static — no migrations needed.
249
- },
250
- overrideBetterAuthOptions: getOverrideBetterAuthOptions,
251
- prefixTests: "profile:rename-user-table",
252
- tests: [renameModelUserTableTestSuite()],
253
- });
254
-
255
- const { execute: executeOrganizationJoinsProfile } = await testAdapter({
256
- adapter: () => {
257
- return organizationJoinsProfileClient.adapter(ctx);
258
- },
259
- runMigrations: () => {
260
- // Convex schema is static — no migrations needed.
261
- },
262
- overrideBetterAuthOptions: getOverrideBetterAuthOptions,
263
- prefixTests: "profile:organization-joins",
264
- tests: [multiJoinsMissingRowsTestSuite()],
265
- });
266
-
267
- await executeBaseProfile();
268
- await executeAdditionalFieldsProfile();
269
- await executePluginTableProfile();
270
- await executeRenameFieldProfile();
271
- await executeRenameUserCustomProfile();
272
- await executeRenameUserTableProfile();
273
- await executeOrganizationJoinsProfile();
274
- }
275
- );