@mockatoo/sv 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +136 -2
- package/dist/index.mjs +152 -0
- package/dist/sv-utils-Cf0Uu0bl.mjs +41205 -0
- package/dist/sv-utils.mjs +1 -0
- package/package.json +64 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 GlobalUnderdog
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,137 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="mockatoo-logo.png" alt="Mockatoo" width="128" height="128">
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
<h1 align="center">Mockatoo</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<picture>
|
|
9
|
+
<source media="(prefers-color-scheme: dark)" srcset="readme-headline-dark.svg">
|
|
10
|
+
<img src="readme-headline-light.svg" alt="Test Google, Microsoft, GitHub, Apple, Discord, LinkedIn, X and Facebook sign-in in CI, without getting blocked. One free OAuth provider for agentic development, E2E tests, and CI. No app registration, no bot checks, no fragile workarounds." width="880">
|
|
11
|
+
</picture>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="https://github.com/mockatoo/sv/actions/workflows/ci.yml"><img src="https://github.com/mockatoo/sv/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
<p align="center">
|
|
19
|
+
<a href="https://mockatoo.globalunderdog.com">Website</a> ·
|
|
20
|
+
<a href="https://mockatoo.globalunderdog.com/docs">Documentation</a> ·
|
|
21
|
+
<a href="https://github.com/mockatoo/connectors">Connectors</a> ·
|
|
22
|
+
<a href="https://app.mockatoo.globalunderdog.com">Create a free test account</a>
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
# @mockatoo/sv
|
|
26
|
+
|
|
27
|
+
**GitHub sign-in that works the moment you run `pnpm dev`, with no GitHub OAuth app.** A [Svelte CLI](https://svelte.dev/docs/cli/overview) community add-on that sets up [Better Auth](https://www.better-auth.com) with a GitHub demo, and signs in through Mockatoo's free hosted GitHub mock in development.
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npx sv add @mockatoo
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
> [!IMPORTANT]
|
|
34
|
+
> Svelte maintainers have not reviewed community add-ons for malicious code. The CLI says so and asks before it runs this one. The source is all in [`src/index.js`](src/index.js).
|
|
35
|
+
|
|
36
|
+
## What it does
|
|
37
|
+
|
|
38
|
+
**It only sets up new auth.** It never edits an auth setup you already have.
|
|
39
|
+
|
|
40
|
+
| Your project | What happens |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| **No auth yet** (a new `sv create` app, or an existing app without auth) | Adds [Better Auth](https://www.better-auth.com) with its GitHub demo (and [Drizzle](https://orm.drizzle.team), if you have no database), then makes the GitHub demo sign in through Mockatoo in development. |
|
|
43
|
+
| **Already has auth**: Better Auth, Auth.js, Lucia, Arctic, Supabase, Clerk, Kinde, WorkOS, or a `src/lib/server/auth.(ts\|js)` file | **Changes nothing.** It stops with a message pointing to the Mockatoo skill and the matching example (see [Already have auth?](#already-have-auth)). |
|
|
44
|
+
| **Not SvelteKit** | Changes nothing. The add-on requires SvelteKit. |
|
|
45
|
+
|
|
46
|
+
On a project with no auth, `npx sv add @mockatoo`:
|
|
47
|
+
|
|
48
|
+
1. **Adds Better Auth with the GitHub demo** through the official `better-auth` add-on, as if you'd run `npx sv add better-auth="demo:github"`. You get its usual files: `src/lib/server/auth.ts`, the demo at `/demo/better-auth`, and `.env` entries. If the project has no database, the official add-on also adds Drizzle and asks which database to use.
|
|
49
|
+
2. **Gates GitHub on SvelteKit's `dev`** in `src/lib/server/auth.ts`:
|
|
50
|
+
|
|
51
|
+
```diff
|
|
52
|
+
+ import { dev } from '$app/env'; // '$app/environment' on SvelteKit 2
|
|
53
|
+
+ import { mockGitHub } from '@mockatoo/connect-better-auth';
|
|
54
|
+
...
|
|
55
|
+
- socialProviders: {
|
|
56
|
+
+ socialProviders: dev
|
|
57
|
+
+ ? {}
|
|
58
|
+
+ : {
|
|
59
|
+
github: { clientId: GITHUB_CLIENT_ID, clientSecret: GITHUB_CLIENT_SECRET }
|
|
60
|
+
},
|
|
61
|
+
plugins: [
|
|
62
|
+
+ ...(dev ? [mockGitHub()] : []),
|
|
63
|
+
sveltekitCookies(getRequestEvent)
|
|
64
|
+
]
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
3. **Adds [`@mockatoo/connect-better-auth`](https://github.com/mockatoo/connectors/tree/main/packages/connect-better-auth)**, a Better Auth plugin that registers Mockatoo's GitHub mock under the provider id `github`. The demo's "Sign in with GitHub" button and `auth.api.signInSocial({ provider: 'github' })` work unchanged.
|
|
68
|
+
4. **On SvelteKit 3**, adds `{ external: true }` to the demo's sign-in redirect, because the mock is on another origin.
|
|
69
|
+
|
|
70
|
+
If `auth.ts` isn't in the shape the official add-on generates (for example, you chose a demo without GitHub in the same command), it stops and changes nothing in it.
|
|
71
|
+
|
|
72
|
+
**Production is unchanged.** `dev` is `false` in production builds, so they use the real GitHub provider with `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET`, and the mock plugin isn't added.
|
|
73
|
+
|
|
74
|
+
## Try it
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
npx sv create my-app --template minimal --types ts
|
|
78
|
+
cd my-app
|
|
79
|
+
npx sv add @mockatoo
|
|
80
|
+
pnpm auth:schema && pnpm db:push # create the auth tables
|
|
81
|
+
pnpm dev
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Open `/demo/better-auth/login` and click **Sign in with GitHub**. You land on Mockatoo's login page: sign in with a [free Mockatoo account](https://app.mockatoo.globalunderdog.com), click **Authorize**, and you're back in the app, signed in as a GitHub user.
|
|
85
|
+
|
|
86
|
+
## Test sign-in in CI
|
|
87
|
+
|
|
88
|
+
The mock behaves like GitHub's OAuth, so a Playwright test can run the whole flow without bot checks or real accounts. Store your Mockatoo test account in `MOCKATOO_TEST_EMAIL` and `MOCKATOO_TEST_PASSWORD`, then:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
await page.goto('/demo/better-auth/login');
|
|
92
|
+
await page.getByRole('button', { name: 'Sign in with GitHub' }).click();
|
|
93
|
+
await page.locator('#email').fill(process.env.MOCKATOO_TEST_EMAIL!);
|
|
94
|
+
await page.locator('#password').fill(process.env.MOCKATOO_TEST_PASSWORD!);
|
|
95
|
+
await page.getByRole('button', { name: 'Log in with password' }).click();
|
|
96
|
+
await page.getByRole('button', { name: 'Authorize' }).click();
|
|
97
|
+
await expect(page.locator('h1')).toContainText('Hi,');
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The dev server must use the same host as `ORIGIN` in `.env`, such as `127.0.0.1` for both, or Better Auth rejects the state cookie. See the [Playwright guide](https://mockatoo.globalunderdog.com/docs/playwright) and the [CI guide](https://mockatoo.globalunderdog.com/docs/ci).
|
|
101
|
+
|
|
102
|
+
## Already have auth?
|
|
103
|
+
|
|
104
|
+
The add-on won't edit an existing auth setup: auth code varies too much for a blind edit to be safe. Instead, let your coding agent add Mockatoo to the code you have:
|
|
105
|
+
|
|
106
|
+
```sh
|
|
107
|
+
npx skills add mockatoo/connectors --skill mockatoo
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Then ask it to add Mockatoo for development and tests. Working examples:
|
|
111
|
+
|
|
112
|
+
- [Better Auth + SvelteKit](https://github.com/mockatoo/examples/tree/main/better-auth-sveltekit)
|
|
113
|
+
- [Auth.js + SvelteKit](https://github.com/mockatoo/examples/tree/main/authjs-sveltekit)
|
|
114
|
+
- [All examples](https://github.com/mockatoo/examples) (Next.js, Nuxt, Remix, Hono, Flask, Django, Laravel, Spring Boot)
|
|
115
|
+
|
|
116
|
+
## Options
|
|
117
|
+
|
|
118
|
+
None. Run it without arguments: `npx sv add @mockatoo`. It installs as `@mockatoo` or `@mockatoo/sv`, and `npx sv add @mockatoo/sv@0.1.0` pins a version.
|
|
119
|
+
|
|
120
|
+
## Development
|
|
121
|
+
|
|
122
|
+
```sh
|
|
123
|
+
pnpm install
|
|
124
|
+
pnpm typecheck
|
|
125
|
+
pnpm test # refusal tests, plus a generated app on each SvelteKit variant
|
|
126
|
+
pnpm cli:check # the real CLI: `sv create` + `sv add file:.`, type check, build, refusal
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
`pnpm test` signs in to the hosted mock when `MOCKATOO_TEST_EMAIL` and `MOCKATOO_TEST_PASSWORD` are set. Without them, it checks the redirect to Mockatoo's login page and skips the full sign-in with a notice. To try it by hand: `pnpm demo-create`, then `pnpm demo-add`.
|
|
130
|
+
|
|
131
|
+
## Releasing
|
|
132
|
+
|
|
133
|
+
Bump `version` in `package.json`, then push a matching tag (`v0.1.1`). [`release.yml`](.github/workflows/release.yml) re-runs every check, including the full sign-in, and publishes to npm with [trusted publishing](https://docs.npmjs.com/trusted-publishers): no npm token, and the package gets a provenance attestation. A prerelease version (`0.2.0-beta.1`) publishes under the `next` tag.
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
MIT. Mockatoo is free; the hosted service is at [app.mockatoo.globalunderdog.com](https://app.mockatoo.globalunderdog.com).
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import fs$1 from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { defineAddon, defineAddonOptions } from "sv";
|
|
4
|
+
import { A as isKit3, S as script, o as defineDemoPage, s as defineEnv } from "./sv-utils-Cf0Uu0bl.mjs";
|
|
5
|
+
// src/index.js
|
|
6
|
+
const CONNECTOR = "@mockatoo/connect-better-auth";
|
|
7
|
+
const CONNECTOR_VERSION = "^0.3.3";
|
|
8
|
+
const SKILL = "npx skills add mockatoo/connectors --skill mockatoo";
|
|
9
|
+
const EXAMPLES = "https://github.com/mockatoo/examples";
|
|
10
|
+
/**
|
|
11
|
+
* Auth libraries this add-on refuses to touch, with the closest Mockatoo example for each.
|
|
12
|
+
* @type {Array<[pkg: string, example: string]>}
|
|
13
|
+
*/
|
|
14
|
+
const EXISTING_AUTH = [
|
|
15
|
+
["better-auth", `${EXAMPLES}/tree/main/better-auth-sveltekit`],
|
|
16
|
+
["@auth/sveltekit", `${EXAMPLES}/tree/main/authjs-sveltekit`],
|
|
17
|
+
["@auth/core", `${EXAMPLES}/tree/main/authjs-sveltekit`],
|
|
18
|
+
["lucia", EXAMPLES],
|
|
19
|
+
["arctic", EXAMPLES],
|
|
20
|
+
["@supabase/ssr", EXAMPLES],
|
|
21
|
+
["@supabase/auth-helpers-sveltekit", EXAMPLES],
|
|
22
|
+
["svelte-clerk", EXAMPLES],
|
|
23
|
+
["clerk-sveltekit", EXAMPLES],
|
|
24
|
+
["@kinde-oss/kinde-auth-sveltekit", EXAMPLES],
|
|
25
|
+
["@workos-inc/authkit-sveltekit", EXAMPLES]
|
|
26
|
+
];
|
|
27
|
+
/**
|
|
28
|
+
* Why this project already has auth, or `undefined` when it has none.
|
|
29
|
+
* @param {{ cwd: string, dependencyVersion: (pkg: string) => string | undefined, directory: { lib: string } }} workspace
|
|
30
|
+
*/
|
|
31
|
+
function existingAuthReason({ cwd, dependencyVersion, directory }) {
|
|
32
|
+
const found = EXISTING_AUTH.find(([pkg]) => dependencyVersion(pkg));
|
|
33
|
+
const authFile = ["ts", "js"].map((ext) => `${directory.lib}/server/auth.${ext}`).find((file) => fs$1.existsSync(path.resolve(cwd, file)));
|
|
34
|
+
if (!found && !authFile) return void 0;
|
|
35
|
+
const what = found ? `\`${found[0]}\`` : `\`${authFile}\``;
|
|
36
|
+
const example = found ? found[1] : EXAMPLES;
|
|
37
|
+
return `This project already has auth (${what}), and @mockatoo/sv only sets up new auth, so it changed nothing. To add Mockatoo to your existing setup, install the Mockatoo skill (${SKILL}) and ask your coding agent to add it. Example: ${example}`;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Edits the generated Better Auth config: real GitHub in production, Mockatoo's GitHub mock in `dev`.
|
|
41
|
+
* Returns `false` (no change) when the file isn't the shape the official add-on generates.
|
|
42
|
+
* @param {{ ast: any, js: any }} file
|
|
43
|
+
* @param {(ast: any, js: any, imports: string[]) => void} importEnv
|
|
44
|
+
*/
|
|
45
|
+
function gateGitHub({ ast, js }, importEnv) {
|
|
46
|
+
/** @type {any} */
|
|
47
|
+
let config;
|
|
48
|
+
visit(ast, (node) => {
|
|
49
|
+
if (config || node.type !== "ObjectExpression") return;
|
|
50
|
+
const plugins = findProperty(node, "plugins");
|
|
51
|
+
if (plugins?.value.type === "ArrayExpression" && plugins.value.elements.some((el) => el?.type === "CallExpression" && el.callee.name === "sveltekitCookies")) config = node;
|
|
52
|
+
});
|
|
53
|
+
if (!config) return false;
|
|
54
|
+
const social = findProperty(config, "socialProviders");
|
|
55
|
+
if (social?.value.type !== "ObjectExpression" || !findProperty(social.value, "github")) return false;
|
|
56
|
+
const gated = js.common.parseExpression("dev ? {} : {}");
|
|
57
|
+
gated.alternate = social.value;
|
|
58
|
+
social.value = gated;
|
|
59
|
+
const mock = js.common.parseExpression("[...(dev ? [mockGitHub()] : [])]").elements[0];
|
|
60
|
+
findProperty(config, "plugins").value.elements.unshift(mock);
|
|
61
|
+
js.imports.addNamed(ast, {
|
|
62
|
+
from: CONNECTOR,
|
|
63
|
+
imports: ["mockGitHub"]
|
|
64
|
+
});
|
|
65
|
+
importEnv(ast, js, ["dev"]);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Kit 3 refuses to redirect to another origin unless asked, and the mock lives on one.
|
|
69
|
+
* @param {{ ast: any }} file
|
|
70
|
+
*/
|
|
71
|
+
function allowExternalRedirect({ ast }) {
|
|
72
|
+
let changed = false;
|
|
73
|
+
visit(ast, (node) => {
|
|
74
|
+
if (node.type === "CallExpression" && node.callee.name === "redirect" && node.arguments.length === 2 && node.arguments[1].type === "MemberExpression" && node.arguments[1].object.name === "result" && node.arguments[1].property.name === "url") {
|
|
75
|
+
node.arguments.push({
|
|
76
|
+
type: "ObjectExpression",
|
|
77
|
+
properties: [{
|
|
78
|
+
type: "Property",
|
|
79
|
+
kind: "init",
|
|
80
|
+
method: false,
|
|
81
|
+
shorthand: false,
|
|
82
|
+
computed: false,
|
|
83
|
+
key: {
|
|
84
|
+
type: "Identifier",
|
|
85
|
+
name: "external"
|
|
86
|
+
},
|
|
87
|
+
value: {
|
|
88
|
+
type: "Literal",
|
|
89
|
+
value: true
|
|
90
|
+
}
|
|
91
|
+
}]
|
|
92
|
+
});
|
|
93
|
+
changed = true;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
if (!changed) return false;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* @param {any} node
|
|
100
|
+
* @param {(node: any) => void} fn
|
|
101
|
+
*/
|
|
102
|
+
function visit(node, fn) {
|
|
103
|
+
if (!node || typeof node.type !== "string") return;
|
|
104
|
+
fn(node);
|
|
105
|
+
for (const value of Object.values(node)) if (Array.isArray(value)) value.forEach((child) => visit(child, fn));
|
|
106
|
+
else if (value && typeof value === "object") visit(value, fn);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* @param {any} object
|
|
110
|
+
* @param {string} name
|
|
111
|
+
*/
|
|
112
|
+
function findProperty(object, name) {
|
|
113
|
+
return object.properties.find((p) => p.type === "Property" && (p.key.name === name || p.key.value === name));
|
|
114
|
+
}
|
|
115
|
+
var src_default = defineAddon({
|
|
116
|
+
id: "@mockatoo/sv",
|
|
117
|
+
shortDescription: "GitHub sign-in in dev without an OAuth app (Mockatoo)",
|
|
118
|
+
homepage: "https://github.com/mockatoo/sv",
|
|
119
|
+
options: defineAddonOptions().build(),
|
|
120
|
+
setup: (workspace) => {
|
|
121
|
+
if (!workspace.isKit) return workspace.unsupported("Requires SvelteKit");
|
|
122
|
+
const reason = existingAuthReason(workspace);
|
|
123
|
+
if (reason) return workspace.unsupported(reason);
|
|
124
|
+
workspace.dependsOn("better-auth", { demo: ["github"] });
|
|
125
|
+
},
|
|
126
|
+
run: ({ sv, cwd, language, directory, dependencyVersion, cancel }) => {
|
|
127
|
+
const env = defineEnv({
|
|
128
|
+
sv,
|
|
129
|
+
cwd,
|
|
130
|
+
dependencyVersion
|
|
131
|
+
});
|
|
132
|
+
const authFile = `${directory.lib}/server/auth.${language}`;
|
|
133
|
+
let gated = false;
|
|
134
|
+
sv.file(authFile, script((file) => {
|
|
135
|
+
if (file.content.includes("@mockatoo/connect-better-auth")) return false;
|
|
136
|
+
if (gateGitHub(file, env.importEnv) === false) return false;
|
|
137
|
+
gated = true;
|
|
138
|
+
}));
|
|
139
|
+
if (!gated) return cancel(`Couldn't find Better Auth's GitHub demo config in ${authFile}, so nothing was changed. Run \`npx sv add better-auth="demo:github" @mockatoo\`, or use the Mockatoo skill: ${SKILL}`);
|
|
140
|
+
sv.devDependency(CONNECTOR, CONNECTOR_VERSION);
|
|
141
|
+
if (isKit3(dependencyVersion("@sveltejs/kit"))) {
|
|
142
|
+
const demo = defineDemoPage("better-auth", language, directory.kitRoutes);
|
|
143
|
+
sv.file(`${demo.addonPath}/login/+page.server.${language}`, script((file) => allowExternalRedirect(file)));
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
nextSteps: () => [
|
|
147
|
+
"Run the dev server and open /demo/better-auth/login, then click \"Sign in with GitHub\"",
|
|
148
|
+
"Sign in with a free Mockatoo account (https://app.mockatoo.globalunderdog.com); no GitHub OAuth app is needed in development",
|
|
149
|
+
"GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET are only needed for production builds, which use real GitHub"
|
|
150
|
+
]
|
|
151
|
+
});
|
|
152
|
+
export { CONNECTOR, CONNECTOR_VERSION, EXISTING_AUTH, allowExternalRedirect, src_default as default, existingAuthReason, gateGitHub };
|