@leaguebrain/provenance 0.0.0-stage → 0.14.0
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/LICENSE +7 -0
- package/README.md +135 -2
- package/dist/context-C2cW461e.d.ts +84 -0
- package/dist/helpers/index.d.ts +35 -0
- package/dist/helpers/index.js +113 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/index-CPpCO-Oc.d.ts +103 -0
- package/dist/index.d.ts +210 -0
- package/dist/index.js +551 -0
- package/dist/index.js.map +1 -0
- package/dist/initiatives/index.d.ts +19 -0
- package/dist/initiatives/index.js +74 -0
- package/dist/initiatives/index.js.map +1 -0
- package/dist/providers/index.d.ts +2 -0
- package/dist/providers/index.js +377 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/vite/index.d.ts +87 -0
- package/dist/vite/index.js +171 -0
- package/dist/vite/index.js.map +1 -0
- package/package.json +85 -3
- package/src/vite/sveltekit/runtime/js.d.ts +62 -0
- package/src/vite/sveltekit/runtime/js.js +412 -0
- package/src/vite/sveltekit/runtime/ts.ts +432 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/vite/index.ts
|
|
9
|
+
import path2 from "path";
|
|
10
|
+
import fs2 from "fs";
|
|
11
|
+
import fsPromises from "fs/promises";
|
|
12
|
+
import { spawn } from "child_process";
|
|
13
|
+
|
|
14
|
+
// src/vite/write.ts
|
|
15
|
+
import path from "path";
|
|
16
|
+
import fs from "fs/promises";
|
|
17
|
+
var copyTypes = async (runtimeDir, dir, filename) => {
|
|
18
|
+
await fs.copyFile(path.join(runtimeDir, "js.d.ts"), path.join(dir, filename));
|
|
19
|
+
};
|
|
20
|
+
var copyJSRuntime = async (runtimeDir, dir, filename) => {
|
|
21
|
+
await fs.copyFile(path.join(runtimeDir, "js.js"), path.join(dir, filename));
|
|
22
|
+
};
|
|
23
|
+
var copyTSRuntime = async (runtimeDir, dir, filename) => {
|
|
24
|
+
await fs.copyFile(path.join(runtimeDir, "ts.ts"), path.join(dir, filename));
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// src/vite/index.ts
|
|
28
|
+
var getDefaultOptions = (o) => {
|
|
29
|
+
if (o?.runtime != "js") {
|
|
30
|
+
const options = {
|
|
31
|
+
postUpdateRun: o?.postUpdateRun,
|
|
32
|
+
dir: o?.dir ?? "src/lib/server",
|
|
33
|
+
filename: o?.filename ?? "PROVENANCE",
|
|
34
|
+
framework: "sveltekit",
|
|
35
|
+
runtime: "ts"
|
|
36
|
+
};
|
|
37
|
+
return options;
|
|
38
|
+
} else {
|
|
39
|
+
const options = {
|
|
40
|
+
postUpdateRun: o?.postUpdateRun,
|
|
41
|
+
dir: o?.dir ?? "src/lib/server",
|
|
42
|
+
filename: o?.filename ?? "PROVENANCE",
|
|
43
|
+
framework: "sveltekit",
|
|
44
|
+
generateTypes: o?.generateTypes ?? true,
|
|
45
|
+
runtime: "js"
|
|
46
|
+
};
|
|
47
|
+
return options;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var findModule = async (pkg, currentLocation) => {
|
|
51
|
+
const pathEndingBy = ["node_modules", pkg];
|
|
52
|
+
let locationFound = path2.join(currentLocation, ...pathEndingBy);
|
|
53
|
+
let previousLocation = "";
|
|
54
|
+
const backFolder = [];
|
|
55
|
+
const exists = (location) => fsPromises.stat(location).then(
|
|
56
|
+
() => true,
|
|
57
|
+
() => false
|
|
58
|
+
);
|
|
59
|
+
while (previousLocation !== locationFound && !await exists(locationFound)) {
|
|
60
|
+
previousLocation = locationFound;
|
|
61
|
+
backFolder.push("../");
|
|
62
|
+
locationFound = path2.join(currentLocation, ...backFolder, ...pathEndingBy);
|
|
63
|
+
}
|
|
64
|
+
if (previousLocation === locationFound) {
|
|
65
|
+
throw new Error("Could not find any node_modules/@leaguebrain/provenance folder");
|
|
66
|
+
}
|
|
67
|
+
return locationFound;
|
|
68
|
+
};
|
|
69
|
+
var runtimePaths = async (framework) => {
|
|
70
|
+
const packageName = "@leaguebrain/provenance";
|
|
71
|
+
try {
|
|
72
|
+
const rootPath = process.cwd();
|
|
73
|
+
if (process.versions.pnp) {
|
|
74
|
+
const { findPnpApi } = __require("module");
|
|
75
|
+
const pnp = findPnpApi(rootPath);
|
|
76
|
+
const js2 = path2.dirname(
|
|
77
|
+
pnp.resolveRequest(`${packageName}/${framework}/runtime/js`, rootPath, {
|
|
78
|
+
conditions: /* @__PURE__ */ new Set(["import"])
|
|
79
|
+
})
|
|
80
|
+
);
|
|
81
|
+
const declaration2 = path2.dirname(
|
|
82
|
+
pnp.resolveRequest(`${packageName}/${framework}/runtime/js`, rootPath, {
|
|
83
|
+
conditions: /* @__PURE__ */ new Set(["types"])
|
|
84
|
+
})
|
|
85
|
+
);
|
|
86
|
+
const ts2 = path2.dirname(
|
|
87
|
+
pnp.resolveRequest(`${packageName}/${framework}/runtime/ts`, rootPath, {
|
|
88
|
+
conditions: /* @__PURE__ */ new Set(["default"])
|
|
89
|
+
})
|
|
90
|
+
);
|
|
91
|
+
return {
|
|
92
|
+
js: js2,
|
|
93
|
+
declaration: declaration2,
|
|
94
|
+
ts: ts2
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const packageDirectory = await findModule(packageName, rootPath);
|
|
98
|
+
const packageJsonSrc = await fsPromises.readFile(
|
|
99
|
+
path2.join(packageDirectory, "package.json"),
|
|
100
|
+
"utf-8"
|
|
101
|
+
);
|
|
102
|
+
if (!packageJsonSrc) {
|
|
103
|
+
throw new Error("skip");
|
|
104
|
+
}
|
|
105
|
+
const packageJson = JSON.parse(packageJsonSrc);
|
|
106
|
+
if (!packageJson.exports?.[`./${framework}/runtime/js`]?.import || !packageJson.exports?.[`./${framework}/runtime/js`]?.types || !packageJson.exports?.[`./${framework}/runtime/ts`]?.default) {
|
|
107
|
+
throw new Error("Exports not found in package.json");
|
|
108
|
+
}
|
|
109
|
+
const js = path2.dirname(
|
|
110
|
+
path2.join(packageDirectory, packageJson.exports[`./${framework}/runtime/js`].import)
|
|
111
|
+
);
|
|
112
|
+
const declaration = path2.dirname(
|
|
113
|
+
path2.join(packageDirectory, packageJson.exports[`./${framework}/runtime/js`].types)
|
|
114
|
+
);
|
|
115
|
+
const ts = path2.dirname(
|
|
116
|
+
path2.join(packageDirectory, packageJson.exports[`./${framework}/runtime/ts`].default)
|
|
117
|
+
);
|
|
118
|
+
return {
|
|
119
|
+
js,
|
|
120
|
+
declaration,
|
|
121
|
+
ts
|
|
122
|
+
};
|
|
123
|
+
} catch (e) {
|
|
124
|
+
console.error(e);
|
|
125
|
+
throw new Error(
|
|
126
|
+
`Could not find ${packageName}. Are you sure its installed? If so, please open a ticket on GitHub.`
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var run = async (o, generateTypes) => {
|
|
131
|
+
const options = getDefaultOptions(o);
|
|
132
|
+
const outDir = path2.resolve(".", options.dir);
|
|
133
|
+
if (!fs2.existsSync(outDir)) {
|
|
134
|
+
fs2.mkdirSync(outDir, { recursive: true });
|
|
135
|
+
}
|
|
136
|
+
const { ts, js, declaration } = await runtimePaths(options.framework);
|
|
137
|
+
if (options.runtime == "ts") {
|
|
138
|
+
await copyTSRuntime(ts, outDir, `${options.filename}.${options.runtime}`);
|
|
139
|
+
} else {
|
|
140
|
+
await copyJSRuntime(js, outDir, `${options.filename}.${options.runtime}`);
|
|
141
|
+
if (generateTypes !== false && options.generateTypes) {
|
|
142
|
+
copyTypes(declaration, outDir, `${options.filename}.d.ts`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (options.postUpdateRun) {
|
|
146
|
+
const child = spawn(options.postUpdateRun, { shell: true });
|
|
147
|
+
const exitPromise = new Promise((resolve) => {
|
|
148
|
+
child.on("close", () => resolve());
|
|
149
|
+
});
|
|
150
|
+
await exitPromise;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
function provenance(o) {
|
|
154
|
+
return [
|
|
155
|
+
{
|
|
156
|
+
name: "vite-plugin-provenance",
|
|
157
|
+
enforce: "pre",
|
|
158
|
+
async buildStart() {
|
|
159
|
+
await run(o, false);
|
|
160
|
+
},
|
|
161
|
+
// types are only necessary (and not dynamic) for dev mode
|
|
162
|
+
async configureServer() {
|
|
163
|
+
await run(o);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
];
|
|
167
|
+
}
|
|
168
|
+
export {
|
|
169
|
+
provenance
|
|
170
|
+
};
|
|
171
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/vite/index.ts","../../src/vite/write.ts"],"sourcesContent":["import path from 'node:path';\nimport fs from 'node:fs';\nimport fsPromises from 'node:fs/promises';\n\nimport { spawn } from 'child_process';\n\nimport type { Plugin } from 'vite';\n\nimport { copyTypes, copyJSRuntime, copyTSRuntime } from './write';\n\nconst frameworks = ['sveltekit'] as const;\ntype Framework = (typeof frameworks)[number];\n\ntype BaseOptions = {\n\t/**\n\t * run any command after an update of some routes.\n\t *\n\t * @example\n\t * ```ts\n\t * 'npm exec prettier ./src/lib/server/PROVENANCE.ts -- -w'\n\t * ```\n\t */\n\tpostUpdateRun: string | undefined;\n\tdir: string;\n\tfilename: string;\n\tframework: Framework;\n};\n\nexport type TSOptions = BaseOptions & {\n\truntime: 'ts';\n};\n\nexport type JSOptions = BaseOptions & {\n\tgenerateTypes: boolean;\n\truntime: 'js';\n};\n\nconst getDefaultOptions = (o?: Partial<TSOptions | JSOptions>): TSOptions | JSOptions => {\n\tif (o?.runtime != 'js') {\n\t\tconst options: TSOptions = {\n\t\t\tpostUpdateRun: o?.postUpdateRun,\n\t\t\tdir: o?.dir ?? 'src/lib/server',\n\t\t\tfilename: o?.filename ?? 'PROVENANCE',\n\t\t\tframework: 'sveltekit',\n\t\t\truntime: 'ts'\n\t\t};\n\t\treturn options;\n\t} else {\n\t\tconst options: JSOptions = {\n\t\t\tpostUpdateRun: o?.postUpdateRun,\n\t\t\tdir: o?.dir ?? 'src/lib/server',\n\t\t\tfilename: o?.filename ?? 'PROVENANCE',\n\t\t\tframework: 'sveltekit',\n\t\t\tgenerateTypes: o?.generateTypes ?? true,\n\t\t\truntime: 'js'\n\t\t};\n\t\treturn options;\n\t}\n};\n\nconst findModule = async (pkg: string, currentLocation: string) => {\n\tconst pathEndingBy = ['node_modules', pkg];\n\n\t// Build the first possible location\n\tlet locationFound = path.join(currentLocation, ...pathEndingBy);\n\n\t// previousLocation is nothing\n\tlet previousLocation = '';\n\tconst backFolder: string[] = [];\n\n\tconst exists = (location: string) =>\n\t\tfsPromises.stat(location).then(\n\t\t\t() => true,\n\t\t\t() => false\n\t\t);\n\n\t// if previousLocation !== locationFound that mean that we can go upper\n\t// if the directory doesn't exist, let's go upper.\n\twhile (previousLocation !== locationFound && !(await exists(locationFound))) {\n\t\t// save the previous path\n\t\tpreviousLocation = locationFound;\n\n\t\t// add a back folder\n\t\tbackFolder.push('../');\n\n\t\t// set the new location\n\t\tlocationFound = path.join(currentLocation, ...backFolder, ...pathEndingBy);\n\t}\n\n\tif (previousLocation === locationFound) {\n\t\tthrow new Error('Could not find any node_modules/@leaguebrain/provenance folder');\n\t}\n\n\treturn locationFound;\n};\n\nconst runtimePaths = async (\n\tframework: Framework\n): Promise<{ js: string; declaration: string; ts: string }> => {\n\tconst packageName = '@leaguebrain/provenance';\n\ttry {\n\t\tconst rootPath = process.cwd();\n\n\t\t// check if we are in a PnP environment\n\t\tif (process.versions.pnp) {\n\t\t\t// retrieve the PnP API (Yarn injects the `findPnpApi` into `node:module` builtin module in runtime)\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\t\t\tconst { findPnpApi } = require('node:module');\n\n\t\t\t// this will traverse the file system to find the closest `.pnp.cjs` file and return the PnP API based on it\n\t\t\t// normally it will reside at the same level as the cwd, so it is unlikely that traversing the whole file system will happen\n\t\t\tconst pnp = findPnpApi(rootPath);\n\n\t\t\t// this directly returns the ESM export of the corresponding module, thanks to the PnP API\n\t\t\t// it will throw if the module isn't found in the project's dependencies\n\t\t\tconst js = path.dirname(\n\t\t\t\tpnp.resolveRequest(`${packageName}/${framework}/runtime/js`, rootPath, {\n\t\t\t\t\tconditions: new Set(['import'])\n\t\t\t\t})\n\t\t\t);\n\t\t\tconst declaration = path.dirname(\n\t\t\t\tpnp.resolveRequest(`${packageName}/${framework}/runtime/js`, rootPath, {\n\t\t\t\t\tconditions: new Set(['types'])\n\t\t\t\t})\n\t\t\t);\n\t\t\tconst ts = path.dirname(\n\t\t\t\tpnp.resolveRequest(`${packageName}/${framework}/runtime/ts`, rootPath, {\n\t\t\t\t\tconditions: new Set(['default'])\n\t\t\t\t})\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tjs,\n\t\t\t\tdeclaration,\n\t\t\t\tts\n\t\t\t};\n\t\t}\n\n\t\t// otherwise we have to hunt the module down relative to the current path\n\t\tconst packageDirectory = await findModule(packageName, rootPath);\n\n\t\t// load up the package json\n\t\tconst packageJsonSrc = await fsPromises.readFile(\n\t\t\tpath.join(packageDirectory, 'package.json'),\n\t\t\t'utf-8'\n\t\t);\n\t\tif (!packageJsonSrc) {\n\t\t\tthrow new Error('skip');\n\t\t}\n\t\tconst packageJson = JSON.parse(packageJsonSrc);\n\n\t\t// the esm target to import is defined at exports['.'].import\n\t\tif (\n\t\t\t!packageJson.exports?.[`./${framework}/runtime/js`]?.import ||\n\t\t\t!packageJson.exports?.[`./${framework}/runtime/js`]?.types ||\n\t\t\t!packageJson.exports?.[`./${framework}/runtime/ts`]?.default\n\t\t) {\n\t\t\tthrow new Error('Exports not found in package.json');\n\t\t}\n\n\t\tconst js = path.dirname(\n\t\t\tpath.join(packageDirectory, packageJson.exports[`./${framework}/runtime/js`].import)\n\t\t);\n\t\tconst declaration = path.dirname(\n\t\t\tpath.join(packageDirectory, packageJson.exports[`./${framework}/runtime/js`].types)\n\t\t);\n\t\tconst ts = path.dirname(\n\t\t\tpath.join(packageDirectory, packageJson.exports[`./${framework}/runtime/ts`].default)\n\t\t);\n\n\t\treturn {\n\t\t\tjs,\n\t\t\tdeclaration,\n\t\t\tts\n\t\t};\n\t} catch (e) {\n\t\tconsole.error(e);\n\n\t\tthrow new Error(\n\t\t\t`Could not find ${packageName}. Are you sure its installed? If so, please open a ticket on GitHub.`\n\t\t);\n\t}\n};\n\nconst run = async (o?: Partial<TSOptions | JSOptions>, generateTypes?: boolean) => {\n\tconst options = getDefaultOptions(o);\n\n\tconst outDir = path.resolve('.', options.dir);\n\n\tif (!fs.existsSync(outDir)) {\n\t\tfs.mkdirSync(outDir, { recursive: true });\n\t}\n\n\tconst { ts, js, declaration } = await runtimePaths(options.framework);\n\n\tif (options.runtime == 'ts') {\n\t\tawait copyTSRuntime(ts, outDir, `${options.filename}.${options.runtime}`);\n\t} else {\n\t\tawait copyJSRuntime(js, outDir, `${options.filename}.${options.runtime}`);\n\n\t\tif (generateTypes !== false && options.generateTypes) {\n\t\t\tcopyTypes(declaration, outDir, `${options.filename}.d.ts`);\n\t\t}\n\t}\n\n\tif (options.postUpdateRun) {\n\t\tconst child = spawn(options.postUpdateRun, { shell: true });\n\n\t\tconst exitPromise = new Promise<void>((resolve) => {\n\t\t\tchild.on('close', () => resolve());\n\t\t});\n\n\t\tawait exitPromise;\n\t}\n};\n\n/**\n * ### register this plugin in vite config\n *\n * `vite.config.[ts|js]`\n * ```ts title=\"vite.config.[ts|js]\"\n *\timport { sveltekit } from '@sveltejs/kit/vite';\n *\timport { provenance } from '@leaguebrain/provenance/vite';\n *\timport { defineConfig } from 'vite';\n\n *\texport default defineConfig({\n *\t\tplugins: [provenance(), sveltekit()]\n *\t});\n * ```\n *\n * ### create an auth object that provides a handle hook and a function to protect routes\n *\n * `src/lib/server/auth.ts`\n * ```ts title=\"src/lib/server/auth.ts\"\n *\timport { provenance } from './PROVENANCE';\n *\timport { github } from '@leaguebrain/provenance/providers';\n *\n *\timport { GH_CLIENT_ID, GH_CLIENT_SECRET } from '$env/static/private';\n *\n *\texport const auth = provenance(\n *\t\tgithub({ clientId: GH_CLIENT_ID, clientSecret: GH_CLIENT_SECRET })\n *\t);\n * ```\n *\n * ### register the handle provided by the auth object\n *\n * `src/hooks.server.ts`\n * ```ts title=\"hooks.server.ts\"\n *\timport { auth } from '$lib/server/auth';\n *\n *\texport const handle = auth.handle;\n * ```\n *\n * `handle` will programmatically create 3 routes:\n * - `redirectUri` to handle redirects from the auth server as part of the oauth authorization flow\n * - `login` to redirect the user to the proper oauth url when navigated\n * - `logout` to destroy the oauth and cookie session when navigated\n *\n * other handle functionality will manage session cookies, provide session in locals, refresh an access token,\n * and keep track of the last path to which the user navigated (for redirecting back to protected routes after authenticating)\n *\n * ### protect server routes in load functions\n *\n * `src/routes/protected/+page.server.ts`\n * ```ts title=\"src/routes/protected/+page.server.ts\"\n *\timport { auth } from '$lib/server/auth';\n *\timport { PageServerLoad } from './types'\n *\n *\texport const load: PageServerLoad = async (event) => {\n *\t\tconst session = await auth.protectRoute(event);\n *\t};\n * ```\n *\n * `auth.protectRoute` can be awaited in `+page.server.ts` load functions to send the user to the login route if a session is required\n */\nexport function provenance(o?: Partial<TSOptions | JSOptions>): Plugin[] {\n\treturn [\n\t\t{\n\t\t\tname: 'vite-plugin-provenance',\n\t\t\tenforce: 'pre',\n\t\t\tasync buildStart() {\n\t\t\t\tawait run(o, false);\n\t\t\t},\n\t\t\t// types are only necessary (and not dynamic) for dev mode\n\t\t\tasync configureServer() {\n\t\t\t\tawait run(o);\n\t\t\t}\n\t\t}\n\t];\n}\n","import path from 'node:path';\nimport fs from 'node:fs/promises';\n\nexport const copyTypes = async (runtimeDir: string, dir: string, filename: string) => {\n\tawait fs.copyFile(path.join(runtimeDir, 'js.d.ts'), path.join(dir, filename));\n};\n\nexport const copyJSRuntime = async (runtimeDir: string, dir: string, filename: string) => {\n\tawait fs.copyFile(path.join(runtimeDir, 'js.js'), path.join(dir, filename));\n};\n\nexport const copyTSRuntime = async (runtimeDir: string, dir: string, filename: string) => {\n\tawait fs.copyFile(path.join(runtimeDir, 'ts.ts'), path.join(dir, filename));\n};\n"],"mappings":";;;;;;;;AAAA,OAAOA,WAAU;AACjB,OAAOC,SAAQ;AACf,OAAO,gBAAgB;AAEvB,SAAS,aAAa;;;ACJtB,OAAO,UAAU;AACjB,OAAO,QAAQ;AAER,IAAM,YAAY,OAAO,YAAoB,KAAa,aAAqB;AACrF,QAAM,GAAG,SAAS,KAAK,KAAK,YAAY,SAAS,GAAG,KAAK,KAAK,KAAK,QAAQ,CAAC;AAC7E;AAEO,IAAM,gBAAgB,OAAO,YAAoB,KAAa,aAAqB;AACzF,QAAM,GAAG,SAAS,KAAK,KAAK,YAAY,OAAO,GAAG,KAAK,KAAK,KAAK,QAAQ,CAAC;AAC3E;AAEO,IAAM,gBAAgB,OAAO,YAAoB,KAAa,aAAqB;AACzF,QAAM,GAAG,SAAS,KAAK,KAAK,YAAY,OAAO,GAAG,KAAK,KAAK,KAAK,QAAQ,CAAC;AAC3E;;;ADwBA,IAAM,oBAAoB,CAAC,MAA8D;AACxF,MAAI,GAAG,WAAW,MAAM;AACvB,UAAM,UAAqB;AAAA,MAC1B,eAAe,GAAG;AAAA,MAClB,KAAK,GAAG,OAAO;AAAA,MACf,UAAU,GAAG,YAAY;AAAA,MACzB,WAAW;AAAA,MACX,SAAS;AAAA,IACV;AACA,WAAO;AAAA,EACR,OAAO;AACN,UAAM,UAAqB;AAAA,MAC1B,eAAe,GAAG;AAAA,MAClB,KAAK,GAAG,OAAO;AAAA,MACf,UAAU,GAAG,YAAY;AAAA,MACzB,WAAW;AAAA,MACX,eA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K,QAAQ,GAAG;AAE5C,MAAI,CAACI,IAAG,WAAW,MAAM,GAAG;AAC3B,IAAAA,IAAG,UAAU,QAAQ,EAAE,WAAW,KAAK,CAAC;AAAA,EACzC;AAEA,QAAM,EAAE,IAAI,IAAI,YAAY,IAAI,MAAM,aAAa,QAAQ,SAAS;AAEpE,MAAI,QAAQ,WAAW,MAAM;AAC5B,UAAM,cAAc,IAAI,QAAQ,GAAG,QAAQ,QAAQ,IAAI,QAAQ,OAAO,EAAE;AAAA,EACzE,OAAO;AACN,UAAM,cAAc,IAAI,QAAQ,GAAG,QAAQ,QAAQ,IAAI,QAAQ,OAAO,EAAE;AAExE,QAAI,kBAAkB,SAAS,QAAQ,eAAe;AACrD,gBAAU,aAAa,QAAQ,GAAG,QAAQ,QAAQ,OAAO;AAAA,IAC1D;AAAA,EACD;AAEA,MAAI,QAAQ,eAAe;AAC1B,UAAM,QAAQ,MAAM,QAAQ,eAAe,EAAE,OAAO,KAAK,CAAC;AAE1D,UAAM,cAAc,IAAI,QAAc,CAAC,YAAY;AAClD,YAAM,GAAG,SAAS,MAAM,QAAQ,CAAC;AAAA,IAClC,CAAC;AAED,UAAM;AAAA,EACP;AACD;AA6DO,SAAS,WAAW,GAA8C;AACxE,SAAO;AAAA,IACN;AAAA,MACC,MAAM;AAAA,MACN,SAAS;AAAA,MACT,MAAM,aAAa;AAClB,cAAM,IAAI,GAAG,KAAK;AAAA,MACnB;AAAA;AAAA,MAEA,MAAM,kBAAkB;AACvB,cAAM,IAAI,CAAC;AAAA,MACZ;AAAA,IACD;AAAA,EACD;AACD;","names":["path","fs","path","js","declaration","ts","fs"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,88 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leaguebrain/provenance",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.14.0",
|
|
4
|
+
"description": "server-side SvelteKit auth",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/LeagueBrain/provenance.git",
|
|
8
|
+
"directory": "packages/provenance"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/LeagueBrain/provenance/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/LeagueBrain/provenance",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"sveltekit",
|
|
17
|
+
"authentication",
|
|
18
|
+
"oauth"
|
|
19
|
+
],
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"@sveltejs/kit": "^2",
|
|
22
|
+
"vite": "^7 || ^8"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"cookie": "1.0.2",
|
|
26
|
+
"@types/node": "22",
|
|
27
|
+
"dedent": "1.7.0",
|
|
28
|
+
"tslib": "2.8.1",
|
|
29
|
+
"tsup": "8.5.1",
|
|
30
|
+
"vite": "8.0.16"
|
|
31
|
+
},
|
|
32
|
+
"type": "module",
|
|
33
|
+
"module": "./dist/index.js",
|
|
34
|
+
"main": "./dist/index.js",
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"import": "./dist/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./package.json": "./package.json",
|
|
42
|
+
"./vite": {
|
|
43
|
+
"types": "./dist/vite/index.d.ts",
|
|
44
|
+
"import": "./dist/vite/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./sveltekit/runtime/ts": {
|
|
47
|
+
"default": "./src/vite/sveltekit/runtime/ts.ts"
|
|
48
|
+
},
|
|
49
|
+
"./sveltekit/runtime/js": {
|
|
50
|
+
"types": "./src/vite/sveltekit/runtime/js.d.ts",
|
|
51
|
+
"import": "./src/vite/sveltekit/runtime/js.js"
|
|
52
|
+
},
|
|
53
|
+
"./providers": {
|
|
54
|
+
"types": "./dist/providers/index.d.ts",
|
|
55
|
+
"import": "./dist/providers/index.js"
|
|
56
|
+
},
|
|
57
|
+
"./initiatives": {
|
|
58
|
+
"types": "./dist/initiatives/index.d.ts",
|
|
59
|
+
"import": "./dist/initiatives/index.js"
|
|
60
|
+
},
|
|
61
|
+
"./helpers": {
|
|
62
|
+
"types": "./dist/helpers/index.d.ts",
|
|
63
|
+
"import": "./dist/helpers/index.js"
|
|
64
|
+
},
|
|
65
|
+
"./modules": {
|
|
66
|
+
"types": "./dist/modules/index.d.ts",
|
|
67
|
+
"import": "./dist/modules/index.js"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"typesVersions": {
|
|
71
|
+
"*": {
|
|
72
|
+
"vite": [
|
|
73
|
+
"./dist/vite/index.d.ts"
|
|
74
|
+
],
|
|
75
|
+
"providers": [
|
|
76
|
+
"./dist/providers/index.d.ts"
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"files": [
|
|
81
|
+
"dist",
|
|
82
|
+
"src/vite/**/runtime"
|
|
83
|
+
],
|
|
84
|
+
"scripts": {
|
|
85
|
+
"build": "tsup",
|
|
86
|
+
"dev": "tsup --watch"
|
|
87
|
+
}
|
|
6
88
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Handle, RequestEvent } from '@sveltejs/kit';
|
|
2
|
+
import type {
|
|
3
|
+
Context,
|
|
4
|
+
Provider,
|
|
5
|
+
AuthOptions,
|
|
6
|
+
OAuthModule,
|
|
7
|
+
SessionModule,
|
|
8
|
+
RoutesModule,
|
|
9
|
+
ChecksModule
|
|
10
|
+
} from '@leaguebrain/provenance';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param getDomain use event data to return a value for the session cookie's domain attributes
|
|
14
|
+
* @param logging whether to log in handle routes (will use setting for \`dev\` if not provided)
|
|
15
|
+
* @param options provide options to configure things like pathnames and cookie names (all fields are optional with sensible defaults)
|
|
16
|
+
*/
|
|
17
|
+
export type ProvenanceConfig = {
|
|
18
|
+
getDomain?: (event: RequestEvent) => string | undefined;
|
|
19
|
+
logging?: boolean;
|
|
20
|
+
options?: AuthOptions;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
declare function createContext<ProviderSession>(
|
|
24
|
+
event: RequestEvent,
|
|
25
|
+
modules: {
|
|
26
|
+
oauth: OAuthModule;
|
|
27
|
+
session: SessionModule<ProviderSession>;
|
|
28
|
+
routes: RoutesModule;
|
|
29
|
+
checks: ChecksModule<{ referrer?: string }>;
|
|
30
|
+
},
|
|
31
|
+
config: {
|
|
32
|
+
logging: boolean;
|
|
33
|
+
getDomain?: (event: RequestEvent) => string | undefined;
|
|
34
|
+
}
|
|
35
|
+
): Context<ProviderSession, App.Session>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param provider configuration for your OAuth provider ([see](@leaguebrain/provenance/providers/index.ts))
|
|
39
|
+
* @param config optional extra configuration options for provenance behaviour
|
|
40
|
+
* @returns an auth object with handle to be used in \`hooks.server.ts\` and \`protectRoute\` to redirect to login from \`+page.server.ts\` load functions if user is not authenticated
|
|
41
|
+
*/
|
|
42
|
+
export declare function provenance<ProviderSession>(
|
|
43
|
+
provider: Provider<ProviderSession>,
|
|
44
|
+
config?: ProvenanceConfig
|
|
45
|
+
): {
|
|
46
|
+
handle: Handle;
|
|
47
|
+
options: AuthOptions;
|
|
48
|
+
createContext: (event: RequestEvent) => ReturnType<typeof createContext>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
declare global {
|
|
52
|
+
namespace App {
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
54
|
+
interface Session {}
|
|
55
|
+
|
|
56
|
+
interface Locals {
|
|
57
|
+
session: Session | null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export {};
|