better-auth 0.2.8-beta.8 → 0.2.8
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/.DS_Store +0 -0
- package/dist/access.js +13 -2
- package/dist/adapters/drizzle.d.ts +1 -1
- package/dist/adapters/drizzle.js +13 -23
- package/dist/adapters/mongodb.d.ts +1 -1
- package/dist/adapters/mongodb.js +3 -2
- package/dist/adapters/prisma.d.ts +1 -1
- package/dist/adapters/prisma.js +3 -280
- package/dist/api.d.ts +1 -1
- package/dist/api.js +407 -269
- package/dist/cli.js +213 -55
- package/dist/client/plugins.d.ts +5 -3
- package/dist/client/plugins.js +49 -34
- package/dist/client.d.ts +3 -1
- package/dist/client.js +34 -32
- package/dist/{index-CKn-Zrry.d.ts → index-C9S3KShG.d.ts} +50 -63
- package/dist/{index-DtRHPoYF.d.ts → index-UOcOxfoL.d.ts} +6 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +501 -372
- package/dist/next-js.d.ts +1 -1
- package/dist/next-js.js +6 -5
- package/dist/node.d.ts +1 -1
- package/dist/node.js +5 -5
- package/dist/plugins.d.ts +8 -5
- package/dist/plugins.js +716 -498
- package/dist/react.d.ts +4 -2
- package/dist/react.js +37 -33
- package/dist/social.js +116 -68
- package/dist/solid-start.d.ts +1 -1
- package/dist/solid-start.js +3 -2
- package/dist/solid.d.ts +2 -1
- package/dist/solid.js +35 -32
- package/dist/svelte-kit.d.ts +1 -1
- package/dist/svelte-kit.js +6 -4
- package/dist/svelte.d.ts +2 -1
- package/dist/svelte.js +33 -32
- package/dist/types.d.ts +2 -2
- package/dist/types.js +0 -1
- package/dist/vue.d.ts +3 -1
- package/dist/vue.js +35 -32
- package/package.json +2 -3
- package/dist/hide-metadata-DEHJp1rk.d.ts +0 -5
- package/dist/utils.d.ts +0 -51
- package/dist/utils.js +0 -426
package/dist/cli.js
CHANGED
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Command } from 'commander';
|
|
3
|
-
import 'dotenv/config';
|
|
4
|
-
import { loadConfig } from 'c12';
|
|
5
|
-
import { createConsola } from 'consola';
|
|
6
|
-
import path3 from 'path';
|
|
7
|
-
import babelPresetTypescript from '@babel/preset-typescript';
|
|
8
|
-
import babelPresetReact from '@babel/preset-react';
|
|
9
|
-
import { z } from 'zod';
|
|
10
|
-
import { existsSync } from 'fs';
|
|
11
|
-
import { SqliteDialect, MysqlDialect, PostgresDialect, Kysely } from 'kysely';
|
|
12
|
-
import ora2 from 'ora';
|
|
13
|
-
import chalk from 'chalk';
|
|
14
|
-
import prompts3 from 'prompts';
|
|
15
|
-
import 'oslo';
|
|
16
|
-
import 'nanoid';
|
|
17
|
-
import 'oslo/oauth2';
|
|
18
|
-
import '@antfu/ni';
|
|
19
|
-
import 'execa';
|
|
20
|
-
import fs from 'fs/promises';
|
|
21
2
|
|
|
3
|
+
// src/cli/index.ts
|
|
4
|
+
import { Command as Command3 } from "commander";
|
|
5
|
+
import "dotenv/config";
|
|
6
|
+
|
|
7
|
+
// src/cli/commands/migrate.ts
|
|
8
|
+
import { Command } from "commander";
|
|
9
|
+
|
|
10
|
+
// src/cli/get-config.ts
|
|
11
|
+
import { loadConfig } from "c12";
|
|
12
|
+
|
|
13
|
+
// src/utils/logger.ts
|
|
14
|
+
import { createConsola } from "consola";
|
|
22
15
|
var consola = createConsola({
|
|
23
16
|
formatOptions: {
|
|
24
17
|
date: false,
|
|
@@ -32,32 +25,37 @@ var consola = createConsola({
|
|
|
32
25
|
var createLogger = (options) => {
|
|
33
26
|
return {
|
|
34
27
|
log: (...args) => {
|
|
35
|
-
consola.log("", ...args);
|
|
28
|
+
!options?.disabled && consola.log("", ...args);
|
|
36
29
|
},
|
|
37
30
|
error: (...args) => {
|
|
38
|
-
consola.error("", ...args);
|
|
31
|
+
!options?.disabled && consola.error("", ...args);
|
|
39
32
|
},
|
|
40
33
|
warn: (...args) => {
|
|
41
|
-
consola.warn("", ...args);
|
|
34
|
+
!options?.disabled && consola.warn("", ...args);
|
|
42
35
|
},
|
|
43
36
|
info: (...args) => {
|
|
44
|
-
consola.info("", ...args);
|
|
37
|
+
!options?.disabled && consola.info("", ...args);
|
|
45
38
|
},
|
|
46
39
|
debug: (...args) => {
|
|
47
|
-
consola.debug("", ...args);
|
|
40
|
+
!options?.disabled && consola.debug("", ...args);
|
|
48
41
|
},
|
|
49
42
|
box: (...args) => {
|
|
50
|
-
consola.box("", ...args);
|
|
43
|
+
!options?.disabled && consola.box("", ...args);
|
|
51
44
|
},
|
|
52
45
|
success: (...args) => {
|
|
53
|
-
consola.success("", ...args);
|
|
46
|
+
!options?.disabled && consola.success("", ...args);
|
|
54
47
|
},
|
|
55
48
|
break: (...args) => {
|
|
56
|
-
console.log("\n");
|
|
49
|
+
!options?.disabled && console.log("\n");
|
|
57
50
|
}
|
|
58
51
|
};
|
|
59
52
|
};
|
|
60
53
|
var logger = createLogger();
|
|
54
|
+
|
|
55
|
+
// src/cli/get-config.ts
|
|
56
|
+
import path from "path";
|
|
57
|
+
import babelPresetTypescript from "@babel/preset-typescript";
|
|
58
|
+
import babelPresetReact from "@babel/preset-react";
|
|
61
59
|
var possiblePaths = ["auth.ts", "auth.tsx"];
|
|
62
60
|
possiblePaths = [
|
|
63
61
|
...possiblePaths,
|
|
@@ -84,7 +82,7 @@ async function getConfig({
|
|
|
84
82
|
let configFile = null;
|
|
85
83
|
if (configPath) {
|
|
86
84
|
const { config } = await loadConfig({
|
|
87
|
-
configFile:
|
|
85
|
+
configFile: path.join(cwd, configPath),
|
|
88
86
|
dotenv: true,
|
|
89
87
|
jitiOptions
|
|
90
88
|
});
|
|
@@ -128,6 +126,19 @@ async function getConfig({
|
|
|
128
126
|
process.exit(1);
|
|
129
127
|
}
|
|
130
128
|
}
|
|
129
|
+
|
|
130
|
+
// src/cli/commands/migrate.ts
|
|
131
|
+
import { z } from "zod";
|
|
132
|
+
import { existsSync } from "fs";
|
|
133
|
+
import path2 from "path";
|
|
134
|
+
|
|
135
|
+
// src/adapters/kysely-adapter/dialect.ts
|
|
136
|
+
import { Kysely } from "kysely";
|
|
137
|
+
import {
|
|
138
|
+
MysqlDialect,
|
|
139
|
+
PostgresDialect,
|
|
140
|
+
SqliteDialect
|
|
141
|
+
} from "kysely";
|
|
131
142
|
var createKyselyAdapter = async (config) => {
|
|
132
143
|
const db = config.database;
|
|
133
144
|
let dialect = void 0;
|
|
@@ -169,6 +180,14 @@ var createKyselyAdapter = async (config) => {
|
|
|
169
180
|
};
|
|
170
181
|
};
|
|
171
182
|
|
|
183
|
+
// src/cli/commands/migrate.ts
|
|
184
|
+
import ora2 from "ora";
|
|
185
|
+
import chalk from "chalk";
|
|
186
|
+
import prompts2 from "prompts";
|
|
187
|
+
|
|
188
|
+
// src/cli/utils/get-migration.ts
|
|
189
|
+
import "kysely";
|
|
190
|
+
|
|
172
191
|
// src/db/get-tables.ts
|
|
173
192
|
var getAuthTables = (options) => {
|
|
174
193
|
const pluginSchema = options.plugins?.reduce(
|
|
@@ -539,6 +558,16 @@ var BetterAuthError = class extends Error {
|
|
|
539
558
|
}
|
|
540
559
|
};
|
|
541
560
|
|
|
561
|
+
// src/cli/utils/install-dep.ts
|
|
562
|
+
import ora from "ora";
|
|
563
|
+
import prompts from "prompts";
|
|
564
|
+
|
|
565
|
+
// src/cli/utils/get-package-manager.ts
|
|
566
|
+
import { detect } from "@antfu/ni";
|
|
567
|
+
|
|
568
|
+
// src/cli/utils/install-dep.ts
|
|
569
|
+
import { execa } from "execa";
|
|
570
|
+
|
|
542
571
|
// src/cli/commands/migrate.ts
|
|
543
572
|
var migrate = new Command("migrate").option(
|
|
544
573
|
"-c, --cwd <cwd>",
|
|
@@ -552,7 +581,7 @@ var migrate = new Command("migrate").option(
|
|
|
552
581
|
cwd: z.string(),
|
|
553
582
|
config: z.string().optional()
|
|
554
583
|
}).parse(opts);
|
|
555
|
-
const cwd =
|
|
584
|
+
const cwd = path2.resolve(options.cwd);
|
|
556
585
|
if (!existsSync(cwd)) {
|
|
557
586
|
logger.error(`The directory "${cwd}" does not exist.`);
|
|
558
587
|
process.exit(1);
|
|
@@ -593,7 +622,7 @@ var migrate = new Command("migrate").option(
|
|
|
593
622
|
chalk.white("table.")
|
|
594
623
|
);
|
|
595
624
|
}
|
|
596
|
-
const { migrate: migrate2 } = await
|
|
625
|
+
const { migrate: migrate2 } = await prompts2({
|
|
597
626
|
type: "confirm",
|
|
598
627
|
name: "migrate",
|
|
599
628
|
message: "Are you sure you want to run these migrations?",
|
|
@@ -610,6 +639,14 @@ var migrate = new Command("migrate").option(
|
|
|
610
639
|
process.exit(0);
|
|
611
640
|
});
|
|
612
641
|
|
|
642
|
+
// src/cli/commands/generate.ts
|
|
643
|
+
import { Command as Command2 } from "commander";
|
|
644
|
+
import { z as z2 } from "zod";
|
|
645
|
+
import { existsSync as existsSync3 } from "fs";
|
|
646
|
+
import path4 from "path";
|
|
647
|
+
import ora3 from "ora";
|
|
648
|
+
import prompts3 from "prompts";
|
|
649
|
+
|
|
613
650
|
// src/adapters/kysely-adapter/index.ts
|
|
614
651
|
function convertWhere(w) {
|
|
615
652
|
if (!w)
|
|
@@ -805,7 +842,113 @@ async function getAdapter(options, isCli) {
|
|
|
805
842
|
}
|
|
806
843
|
});
|
|
807
844
|
}
|
|
808
|
-
|
|
845
|
+
|
|
846
|
+
// src/cli/commands/generate.ts
|
|
847
|
+
import fs2 from "fs/promises";
|
|
848
|
+
import chalk2 from "chalk";
|
|
849
|
+
|
|
850
|
+
// src/adapters/prisma-adapter/generate-cli.ts
|
|
851
|
+
import { produceSchema } from "@mrleebo/prisma-ast";
|
|
852
|
+
import { existsSync as existsSync2 } from "fs";
|
|
853
|
+
import path3 from "path";
|
|
854
|
+
import fs from "fs/promises";
|
|
855
|
+
|
|
856
|
+
// src/utils/misc.ts
|
|
857
|
+
function capitalizeFirstLetter(str) {
|
|
858
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
// src/adapters/prisma-adapter/generate-cli.ts
|
|
862
|
+
async function generatePrismaSchema({
|
|
863
|
+
provider,
|
|
864
|
+
options,
|
|
865
|
+
file
|
|
866
|
+
}) {
|
|
867
|
+
const tables = getAuthTables(options);
|
|
868
|
+
const filePath = file || "./prisma/schema.prisma";
|
|
869
|
+
const schemaPrismaExist = existsSync2(path3.join(process.cwd(), filePath));
|
|
870
|
+
let schemaPrisma = "";
|
|
871
|
+
if (schemaPrismaExist) {
|
|
872
|
+
schemaPrisma = await fs.readFile(
|
|
873
|
+
path3.join(process.cwd(), filePath),
|
|
874
|
+
"utf-8"
|
|
875
|
+
);
|
|
876
|
+
} else {
|
|
877
|
+
schemaPrisma = getNewPrisma(provider);
|
|
878
|
+
}
|
|
879
|
+
const schema = produceSchema(schemaPrisma, (builder) => {
|
|
880
|
+
for (const table in tables) {
|
|
881
|
+
let getType2 = function(type, isOptional) {
|
|
882
|
+
if (type === "string") {
|
|
883
|
+
return isOptional ? "String?" : "String";
|
|
884
|
+
}
|
|
885
|
+
if (type === "number") {
|
|
886
|
+
return isOptional ? "Int?" : "Int";
|
|
887
|
+
}
|
|
888
|
+
if (type === "boolean") {
|
|
889
|
+
return isOptional ? "Boolean?" : "Boolean";
|
|
890
|
+
}
|
|
891
|
+
if (type === "date") {
|
|
892
|
+
return isOptional ? "DateTime?" : "DateTime";
|
|
893
|
+
}
|
|
894
|
+
};
|
|
895
|
+
var getType = getType2;
|
|
896
|
+
const fields = tables[table].fields;
|
|
897
|
+
const originalTable = tables[table].tableName;
|
|
898
|
+
const tableName = capitalizeFirstLetter(originalTable);
|
|
899
|
+
const prismaModel = builder.findByType("model", {
|
|
900
|
+
name: tableName
|
|
901
|
+
});
|
|
902
|
+
!prismaModel && builder.model(tableName).field("id", "String").attribute("id");
|
|
903
|
+
for (const field in fields) {
|
|
904
|
+
const attr = fields[field];
|
|
905
|
+
if (prismaModel) {
|
|
906
|
+
const isAlreadyExist = builder.findByType("field", {
|
|
907
|
+
name: field,
|
|
908
|
+
within: prismaModel.properties
|
|
909
|
+
});
|
|
910
|
+
if (isAlreadyExist) {
|
|
911
|
+
continue;
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
builder.model(tableName).field(field, getType2(attr.type, !attr.required));
|
|
915
|
+
if (attr.unique) {
|
|
916
|
+
builder.model(tableName).blockAttribute(`unique([${field}])`);
|
|
917
|
+
}
|
|
918
|
+
if (attr.references) {
|
|
919
|
+
builder.model(tableName).field(
|
|
920
|
+
`${attr.references.model.toLowerCase()}s`,
|
|
921
|
+
capitalizeFirstLetter(attr.references.model)
|
|
922
|
+
).attribute(
|
|
923
|
+
`relation(fields: [${field}], references: [${attr.references.field}], onDelete: Cascade)`
|
|
924
|
+
);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
const hasAttribute = builder.findByType("attribute", {
|
|
928
|
+
name: "map",
|
|
929
|
+
within: prismaModel?.properties
|
|
930
|
+
});
|
|
931
|
+
if (originalTable !== tableName && !hasAttribute) {
|
|
932
|
+
builder.model(tableName).blockAttribute("map", originalTable);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
});
|
|
936
|
+
return {
|
|
937
|
+
code: schema.trim() === schemaPrisma.trim() ? "" : schema,
|
|
938
|
+
fileName: filePath
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
var getNewPrisma = (provider) => `generator client {
|
|
942
|
+
provider = "prisma-client-js"
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
datasource db {
|
|
946
|
+
provider = "${provider}"
|
|
947
|
+
url = ${provider === "sqlite" ? `"file:./dev.db"` : `env("DATABASE_URL")`}
|
|
948
|
+
}`;
|
|
949
|
+
|
|
950
|
+
// src/cli/commands/generate.ts
|
|
951
|
+
var generate = new Command2("generate").option(
|
|
809
952
|
"-c, --cwd <cwd>",
|
|
810
953
|
"the working directory. defaults to the current directory.",
|
|
811
954
|
process.cwd()
|
|
@@ -813,14 +956,14 @@ var generate = new Command("generate").option(
|
|
|
813
956
|
"--config <config>",
|
|
814
957
|
"the path to the configuration file. defaults to the first configuration file found."
|
|
815
958
|
).option("--output <output>", "the file to output to the generated schema").option("--y", "").action(async (opts) => {
|
|
816
|
-
const options =
|
|
817
|
-
cwd:
|
|
818
|
-
config:
|
|
819
|
-
output:
|
|
959
|
+
const options = z2.object({
|
|
960
|
+
cwd: z2.string(),
|
|
961
|
+
config: z2.string().optional(),
|
|
962
|
+
output: z2.string().optional()
|
|
820
963
|
}).parse(opts);
|
|
821
|
-
const spinner =
|
|
822
|
-
const cwd =
|
|
823
|
-
if (!
|
|
964
|
+
const spinner = ora3("preparing schema...").start();
|
|
965
|
+
const cwd = path4.resolve(options.cwd);
|
|
966
|
+
if (!existsSync3(cwd)) {
|
|
824
967
|
logger.error(`The directory "${cwd}" does not exist.`);
|
|
825
968
|
process.exit(1);
|
|
826
969
|
}
|
|
@@ -834,19 +977,34 @@ var generate = new Command("generate").option(
|
|
|
834
977
|
);
|
|
835
978
|
return;
|
|
836
979
|
}
|
|
837
|
-
const adapter = await getAdapter(config).catch((e) => {
|
|
980
|
+
const adapter = await getAdapter(config, true).catch((e) => {
|
|
838
981
|
logger.error(e.message);
|
|
839
982
|
process.exit(1);
|
|
840
983
|
});
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
984
|
+
let code = "";
|
|
985
|
+
let fileName = "";
|
|
986
|
+
let append = false;
|
|
987
|
+
let overwrite = false;
|
|
988
|
+
if (adapter.id === "prisma") {
|
|
989
|
+
spinner.text = "generating schema...";
|
|
990
|
+
const result = await generatePrismaSchema({
|
|
991
|
+
options: config,
|
|
992
|
+
file: options.output,
|
|
993
|
+
provider: adapter.options?.provider || "pg"
|
|
994
|
+
});
|
|
995
|
+
code = result.code;
|
|
996
|
+
fileName = result.fileName;
|
|
997
|
+
} else {
|
|
998
|
+
if (!adapter.createSchema) {
|
|
999
|
+
logger.error("The adapter does not support schema generation.");
|
|
1000
|
+
process.exit(1);
|
|
1001
|
+
}
|
|
1002
|
+
const result = await adapter.createSchema(config, options.output);
|
|
1003
|
+
code = result.code;
|
|
1004
|
+
fileName = result.fileName;
|
|
1005
|
+
append = result.append || false;
|
|
1006
|
+
overwrite = result.overwrite || false;
|
|
844
1007
|
}
|
|
845
|
-
spinner.text = "generating schema...";
|
|
846
|
-
const { code, fileName, append, overwrite } = await adapter.createSchema(
|
|
847
|
-
config,
|
|
848
|
-
options.output
|
|
849
|
-
);
|
|
850
1008
|
spinner.stop();
|
|
851
1009
|
if (!code) {
|
|
852
1010
|
logger.success("Your schema is already up to date.");
|
|
@@ -856,15 +1014,15 @@ var generate = new Command("generate").option(
|
|
|
856
1014
|
const { confirm: confirm2 } = await prompts3({
|
|
857
1015
|
type: "confirm",
|
|
858
1016
|
name: "confirm",
|
|
859
|
-
message: `The file ${fileName} already exists. Do you want to ${
|
|
1017
|
+
message: `The file ${fileName} already exists. Do you want to ${chalk2.yellow(
|
|
860
1018
|
`${overwrite ? "overwrite" : "append"}`
|
|
861
1019
|
)} the schema to the file?`
|
|
862
1020
|
});
|
|
863
1021
|
if (confirm2) {
|
|
864
1022
|
if (overwrite) {
|
|
865
|
-
await
|
|
1023
|
+
await fs2.writeFile(path4.join(cwd, fileName), code);
|
|
866
1024
|
} else {
|
|
867
|
-
await
|
|
1025
|
+
await fs2.appendFile(path4.join(cwd, fileName), code);
|
|
868
1026
|
}
|
|
869
1027
|
logger.success(`\u{1F680} schema was appended successfully!`);
|
|
870
1028
|
process.exit(0);
|
|
@@ -876,7 +1034,7 @@ var generate = new Command("generate").option(
|
|
|
876
1034
|
const { confirm } = await prompts3({
|
|
877
1035
|
type: "confirm",
|
|
878
1036
|
name: "confirm",
|
|
879
|
-
message: `Do you want to generate the schema to ${
|
|
1037
|
+
message: `Do you want to generate the schema to ${chalk2.yellow(
|
|
880
1038
|
fileName
|
|
881
1039
|
)}?`
|
|
882
1040
|
});
|
|
@@ -884,20 +1042,20 @@ var generate = new Command("generate").option(
|
|
|
884
1042
|
logger.error("Schema generation aborted.");
|
|
885
1043
|
process.exit(1);
|
|
886
1044
|
}
|
|
887
|
-
const dirExist =
|
|
1045
|
+
const dirExist = existsSync3(path4.dirname(path4.join(cwd, fileName)));
|
|
888
1046
|
if (!dirExist) {
|
|
889
|
-
await
|
|
1047
|
+
await fs2.mkdir(path4.dirname(path4.join(cwd, fileName)), {
|
|
890
1048
|
recursive: true
|
|
891
1049
|
});
|
|
892
1050
|
}
|
|
893
|
-
await
|
|
1051
|
+
await fs2.writeFile(options.output || path4.join(cwd, fileName), code);
|
|
894
1052
|
logger.success(`\u{1F680} schema was generated successfully!`);
|
|
895
1053
|
process.exit(0);
|
|
896
1054
|
});
|
|
897
1055
|
|
|
898
1056
|
// src/cli/index.ts
|
|
899
1057
|
async function main() {
|
|
900
|
-
const program = new
|
|
1058
|
+
const program = new Command3().name("better-auth");
|
|
901
1059
|
program.addCommand(migrate).addCommand(generate).version("0.0.1").description("Better Auth CLI");
|
|
902
1060
|
program.parse();
|
|
903
1061
|
}
|
package/dist/client/plugins.d.ts
CHANGED
|
@@ -2,14 +2,14 @@ import * as nanostores from 'nanostores';
|
|
|
2
2
|
import { A as AccessControl, S as StatementsPrimitive, R as Role } from '../statement-CfnyN34h.js';
|
|
3
3
|
import * as _better_fetch_fetch from '@better-fetch/fetch';
|
|
4
4
|
import { BetterFetchOption } from '@better-fetch/fetch';
|
|
5
|
-
import { o as organization, e as Organization, M as Member, I as Invitation, u as username, m as magicLink, d as phoneNumber } from '../index-
|
|
6
|
-
export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-
|
|
5
|
+
import { o as organization, e as Organization, M as Member, I as Invitation, u as username, m as magicLink, d as phoneNumber } from '../index-UOcOxfoL.js';
|
|
6
|
+
export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-UOcOxfoL.js';
|
|
7
7
|
import { P as Prettify } from '../helper-DPDj8Nix.js';
|
|
8
8
|
import '../index-JM-i6hLs.js';
|
|
9
9
|
import 'arctic';
|
|
10
10
|
import 'zod';
|
|
11
11
|
import 'better-call';
|
|
12
|
-
import '../index-
|
|
12
|
+
import '../index-C9S3KShG.js';
|
|
13
13
|
import 'kysely';
|
|
14
14
|
import 'better-sqlite3';
|
|
15
15
|
import 'mysql2';
|
|
@@ -109,6 +109,7 @@ declare const organizationClient: <O extends OrganizationClientOptions>(options?
|
|
|
109
109
|
}> | null;
|
|
110
110
|
error: null | _better_fetch_fetch.BetterFetchError;
|
|
111
111
|
isPending: boolean;
|
|
112
|
+
isRefetching: boolean;
|
|
112
113
|
}>;
|
|
113
114
|
listOrganizations: nanostores.PreinitializedWritableAtom<{
|
|
114
115
|
data: {
|
|
@@ -121,6 +122,7 @@ declare const organizationClient: <O extends OrganizationClientOptions>(options?
|
|
|
121
122
|
}[] | null;
|
|
122
123
|
error: null | _better_fetch_fetch.BetterFetchError;
|
|
123
124
|
isPending: boolean;
|
|
125
|
+
isRefetching: boolean;
|
|
124
126
|
}>;
|
|
125
127
|
};
|
|
126
128
|
atomListeners: ({
|
package/dist/client/plugins.js
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
import { atom, onMount } from 'nanostores';
|
|
2
|
-
import '@better-fetch/fetch';
|
|
3
|
-
import 'oslo';
|
|
4
|
-
import 'nanoid';
|
|
5
|
-
import { createConsola } from 'consola';
|
|
6
|
-
import 'oslo/oauth2';
|
|
7
|
-
import 'zod';
|
|
8
|
-
import { startAuthentication, startRegistration, WebAuthnError } from '@simplewebauthn/browser';
|
|
9
|
-
|
|
10
1
|
// src/plugins/organization/client.ts
|
|
2
|
+
import { atom as atom3 } from "nanostores";
|
|
11
3
|
|
|
12
4
|
// src/plugins/organization/access/src/access.ts
|
|
13
5
|
var ParsingError = class extends Error {
|
|
@@ -96,36 +88,41 @@ var defaultStatements = {
|
|
|
96
88
|
invitation: ["create", "cancel"]
|
|
97
89
|
};
|
|
98
90
|
var defaultAc = createAccessControl(defaultStatements);
|
|
99
|
-
defaultAc.newRole({
|
|
91
|
+
var adminAc = defaultAc.newRole({
|
|
100
92
|
organization: ["update"],
|
|
101
93
|
invitation: ["create", "cancel"],
|
|
102
94
|
member: ["create", "update", "delete"]
|
|
103
95
|
});
|
|
104
|
-
defaultAc.newRole({
|
|
96
|
+
var ownerAc = defaultAc.newRole({
|
|
105
97
|
organization: ["update", "delete"],
|
|
106
98
|
member: ["create", "update", "delete"],
|
|
107
99
|
invitation: ["create", "cancel"]
|
|
108
100
|
});
|
|
109
|
-
defaultAc.newRole({
|
|
101
|
+
var memberAc = defaultAc.newRole({
|
|
110
102
|
organization: [],
|
|
111
103
|
member: [],
|
|
112
104
|
invitation: []
|
|
113
105
|
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
106
|
+
|
|
107
|
+
// src/client/config.ts
|
|
108
|
+
import { createFetch } from "@better-fetch/fetch";
|
|
109
|
+
import "nanostores";
|
|
110
|
+
|
|
111
|
+
// src/client/fetch-plugins.ts
|
|
112
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
113
|
+
|
|
114
|
+
// src/client/session-atom.ts
|
|
115
|
+
import { atom as atom2 } from "nanostores";
|
|
116
|
+
|
|
117
|
+
// src/client/query.ts
|
|
118
|
+
import "@better-fetch/fetch";
|
|
119
|
+
import { atom, onMount } from "nanostores";
|
|
124
120
|
var useAuthQuery = (initializedAtom, path, $fetch, options) => {
|
|
125
121
|
const value = atom({
|
|
126
122
|
data: null,
|
|
127
123
|
error: null,
|
|
128
|
-
isPending: false
|
|
124
|
+
isPending: false,
|
|
125
|
+
isRefetching: false
|
|
129
126
|
});
|
|
130
127
|
const fn = () => {
|
|
131
128
|
const opts = typeof options === "function" ? options({
|
|
@@ -139,24 +136,27 @@ var useAuthQuery = (initializedAtom, path, $fetch, options) => {
|
|
|
139
136
|
value.set({
|
|
140
137
|
data: context.data,
|
|
141
138
|
error: null,
|
|
142
|
-
isPending: false
|
|
139
|
+
isPending: false,
|
|
140
|
+
isRefetching: false
|
|
143
141
|
});
|
|
144
142
|
await opts?.onSuccess?.(context);
|
|
145
143
|
},
|
|
146
144
|
async onError(context) {
|
|
147
145
|
value.set({
|
|
148
146
|
error: context.error,
|
|
149
|
-
data:
|
|
150
|
-
isPending: false
|
|
147
|
+
data: value.get().data,
|
|
148
|
+
isPending: false,
|
|
149
|
+
isRefetching: false
|
|
151
150
|
});
|
|
152
151
|
await opts?.onError?.(context);
|
|
153
152
|
},
|
|
154
153
|
async onRequest(context) {
|
|
155
154
|
const currentValue = value.get();
|
|
156
155
|
value.set({
|
|
157
|
-
isPending:
|
|
156
|
+
isPending: currentValue.data === null,
|
|
158
157
|
data: currentValue.data,
|
|
159
|
-
error:
|
|
158
|
+
error: null,
|
|
159
|
+
isRefetching: true
|
|
160
160
|
});
|
|
161
161
|
await opts?.onRequest?.(context);
|
|
162
162
|
}
|
|
@@ -185,9 +185,9 @@ var useAuthQuery = (initializedAtom, path, $fetch, options) => {
|
|
|
185
185
|
|
|
186
186
|
// src/plugins/organization/client.ts
|
|
187
187
|
var organizationClient = (options) => {
|
|
188
|
-
const activeOrgId =
|
|
189
|
-
const _listOrg =
|
|
190
|
-
const _activeOrgSignal =
|
|
188
|
+
const activeOrgId = atom3(void 0);
|
|
189
|
+
const _listOrg = atom3(false);
|
|
190
|
+
const _activeOrgSignal = atom3(false);
|
|
191
191
|
return {
|
|
192
192
|
id: "organization",
|
|
193
193
|
$InferServerPlugin: {},
|
|
@@ -265,6 +265,14 @@ var usernameClient = () => {
|
|
|
265
265
|
$InferServerPlugin: {}
|
|
266
266
|
};
|
|
267
267
|
};
|
|
268
|
+
|
|
269
|
+
// src/plugins/passkey/client.ts
|
|
270
|
+
import {
|
|
271
|
+
WebAuthnError,
|
|
272
|
+
startAuthentication,
|
|
273
|
+
startRegistration
|
|
274
|
+
} from "@simplewebauthn/browser";
|
|
275
|
+
import { atom as atom4 } from "nanostores";
|
|
268
276
|
var getPasskeyActions = ($fetch, {
|
|
269
277
|
_listPasskeys
|
|
270
278
|
}) => {
|
|
@@ -386,7 +394,7 @@ var getPasskeyActions = ($fetch, {
|
|
|
386
394
|
};
|
|
387
395
|
};
|
|
388
396
|
var passkeyClient = () => {
|
|
389
|
-
const _listPasskeys =
|
|
397
|
+
const _listPasskeys = atom4();
|
|
390
398
|
return {
|
|
391
399
|
id: "passkey",
|
|
392
400
|
$InferServerPlugin: {},
|
|
@@ -485,5 +493,12 @@ var phoneNumberClient = () => {
|
|
|
485
493
|
]
|
|
486
494
|
};
|
|
487
495
|
};
|
|
488
|
-
|
|
489
|
-
|
|
496
|
+
export {
|
|
497
|
+
getPasskeyActions,
|
|
498
|
+
magicLinkClient,
|
|
499
|
+
organizationClient,
|
|
500
|
+
passkeyClient,
|
|
501
|
+
phoneNumberClient,
|
|
502
|
+
twoFactorClient,
|
|
503
|
+
usernameClient
|
|
504
|
+
};
|
package/dist/client.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { BetterFetch, BetterFetchError, BetterFetchOption } from '@better-fetch/
|
|
|
6
6
|
import { U as UnionToIntersection, P as Prettify, S as StripEmptyObjects } from './helper-DPDj8Nix.js';
|
|
7
7
|
import { ClientOptions, InferClientAPI, InferActions, InferAdditionalFromClient, InferSessionFromClient, InferUserFromClient, BetterAuthClientPlugin, IsSignal } from './types.js';
|
|
8
8
|
export { AtomListener, InferPluginsFromClient } from './types.js';
|
|
9
|
-
import './index-
|
|
9
|
+
import './index-C9S3KShG.js';
|
|
10
10
|
import 'kysely';
|
|
11
11
|
import './index-JM-i6hLs.js';
|
|
12
12
|
import 'arctic';
|
|
@@ -39,6 +39,7 @@ declare function createAuthClient<Option extends ClientOptions>(options?: Option
|
|
|
39
39
|
} | null;
|
|
40
40
|
error: null | _better_fetch_fetch.BetterFetchError;
|
|
41
41
|
isPending: boolean;
|
|
42
|
+
isRefetching: boolean;
|
|
42
43
|
}>;
|
|
43
44
|
$fetch: _better_fetch_fetch.BetterFetch<{
|
|
44
45
|
plugins: (_better_fetch_fetch.BetterFetchPlugin | {
|
|
@@ -268,6 +269,7 @@ declare const useAuthQuery: <T>(initializedAtom: PreinitializedWritableAtom<any>
|
|
|
268
269
|
data: null | T;
|
|
269
270
|
error: null | BetterFetchError;
|
|
270
271
|
isPending: boolean;
|
|
272
|
+
isRefetching: boolean;
|
|
271
273
|
}>;
|
|
272
274
|
|
|
273
275
|
export { BetterAuthClientPlugin, ClientOptions, InferActions, InferAdditionalFromClient, InferClientAPI, InferSessionFromClient, InferUserFromClient, IsSignal, createAuthClient, useAuthQuery };
|