@sixb/app 0.1.2 → 0.1.3
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/README.md +3 -0
- package/dist/auth.d.ts +22 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +3 -0
- package/dist/auth.js.map +9 -0
- package/dist/build.d.ts +10 -0
- package/dist/build.d.ts.map +1 -1
- package/dist/codegen.d.ts +10 -0
- package/dist/codegen.d.ts.map +1 -1
- package/dist/createCustomApp.d.ts +7 -0
- package/dist/createCustomApp.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +231 -3
- package/dist/index.js.map +5 -5
- package/package.json +9 -3
- package/src/auth.ts +17 -0
- package/src/build.ts +77 -0
- package/src/codegen.ts +153 -0
- package/src/createCustomApp.ts +90 -3
- package/src/index.ts +2 -0
package/README.md
CHANGED
|
@@ -34,6 +34,8 @@ The generated entry also intercepts plain same-origin `<a href="/...">` clicks a
|
|
|
34
34
|
|
|
35
35
|
If `app/layout.tsx` exists, it is used as a root layout wrapper. It can also export a `metadata` object (`title`, `description`, `favicon`, `themeColor`, and `backgroundColor`). Metadata is loaded during generation and written into the static HTML and manifest, so it is available before auth and client startup. The layout module must therefore be import-safe in Bun: do not access `window` or `document` at module scope. An `app/globals.css` file is imported automatically when present.
|
|
36
36
|
|
|
37
|
+
Add an optional `app/auth.tsx` default export to customize the app audience's magic-link pages. It receives `AuthExperienceProps` from `@sixb/app/auth` with `signIn`, `checkEmail`, `confirm`, `invalidLink`, and `error` states plus framework-owned actions. Sixb builds it separately, includes `app/globals.css`, and serves it from the API's existing `/auth/*` routes. It is not wrapped by `app/layout.tsx`, and it never owns tokens, cookies, callbacks, audience validation, or return redirects. When the file is absent, the generic server login remains the fallback.
|
|
38
|
+
|
|
37
39
|
### Built-in Agent Routes
|
|
38
40
|
|
|
39
41
|
Custom apps automatically receive the shared Sixb agent chat UI at:
|
|
@@ -186,5 +188,6 @@ A file at `app/public/app.webmanifest` is ignored because the generated manifest
|
|
|
186
188
|
| --- | --- |
|
|
187
189
|
| `createCustomApp(options)` | High-level custom app toolkit for dev/build/start |
|
|
188
190
|
| `AppMetadata` | Metadata shape exported by `app/layout.tsx` |
|
|
191
|
+
| `@sixb/app/auth` | Custom auth experience states, actions, and component props |
|
|
189
192
|
| `createTailwindCssCompiler(options)` | Shared Tailwind v4 build pipeline (also used by Atlas) |
|
|
190
193
|
| `@sixb/app/agents` | Full-page agent route plus `AgentPanel`, context provider/hooks, and helpers |
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type AuthExperienceState = {
|
|
2
|
+
readonly kind: "signIn";
|
|
3
|
+
} | {
|
|
4
|
+
readonly kind: "checkEmail";
|
|
5
|
+
} | {
|
|
6
|
+
readonly kind: "confirm";
|
|
7
|
+
readonly email?: string;
|
|
8
|
+
} | {
|
|
9
|
+
readonly kind: "invalidLink";
|
|
10
|
+
} | {
|
|
11
|
+
readonly kind: "error";
|
|
12
|
+
};
|
|
13
|
+
export interface AuthExperienceActions {
|
|
14
|
+
requestMagicLink(email: string): void;
|
|
15
|
+
confirmSignIn(): void;
|
|
16
|
+
restartSignIn(): void;
|
|
17
|
+
}
|
|
18
|
+
export interface AuthExperienceProps {
|
|
19
|
+
readonly state: AuthExperienceState;
|
|
20
|
+
readonly actions: AuthExperienceActions;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;CAAE,GAC/B;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAA;CAAE,GAChC;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAA;AAE9B,MAAM,WAAW,qBAAqB;IACpC,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACrC,aAAa,IAAI,IAAI,CAAA;IACrB,aAAa,IAAI,IAAI,CAAA;CACtB;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAAA;IACnC,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAA;CACxC"}
|
package/dist/auth.js
ADDED
package/dist/auth.js.map
ADDED
package/dist/build.d.ts
CHANGED
|
@@ -13,10 +13,20 @@ export interface BuildAppResult {
|
|
|
13
13
|
outdir: string;
|
|
14
14
|
logs?: string[];
|
|
15
15
|
}
|
|
16
|
+
export interface BuildAuthExperienceOptions {
|
|
17
|
+
/** Generated HTML shell containing the auth bootstrap placeholder. */
|
|
18
|
+
entryPath: string;
|
|
19
|
+
/** Browser TypeScript entry generated alongside `entryPath`. */
|
|
20
|
+
scriptEntryPath: string;
|
|
21
|
+
/** Directory written for the API server to mount under `/auth`. */
|
|
22
|
+
outdir: string;
|
|
23
|
+
}
|
|
16
24
|
/**
|
|
17
25
|
* Builds the generated browser entry and writes a production-ready static shell and bundle.
|
|
18
26
|
*/
|
|
19
27
|
export declare function buildApp(options: BuildAppOptions): Promise<BuildAppResult>;
|
|
28
|
+
/** Builds the optional custom auth entry as API-served static assets. */
|
|
29
|
+
export declare function buildAuthExperience(options: BuildAuthExperienceOptions): Promise<BuildAppResult>;
|
|
20
30
|
export declare function prepareAppHtmlBundleEntry(entryPath: string): Promise<string>;
|
|
21
31
|
export declare function restoreAppStaticUrls(html: string): string;
|
|
22
32
|
//# sourceMappingURL=build.d.ts.map
|
package/dist/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,eAAe;IAC9B,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAA;IACjB,gEAAgE;IAChE,eAAe,EAAE,MAAM,CAAA;IACvB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAChB;AAED;;GAEG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CA2EhF;AAKD,wBAAsB,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CASlF;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzD"}
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,eAAe;IAC9B,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAA;IACjB,gEAAgE;IAChE,eAAe,EAAE,MAAM,CAAA;IACvB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAChB;AAED,MAAM,WAAW,0BAA0B;IACzC,sEAAsE;IACtE,SAAS,EAAE,MAAM,CAAA;IACjB,gEAAgE;IAChE,eAAe,EAAE,MAAM,CAAA;IACvB,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;GAEG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CA2EhF;AAED,yEAAyE;AACzE,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,cAAc,CAAC,CA+DzB;AAKD,wBAAsB,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CASlF;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzD"}
|
package/dist/codegen.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export interface BuiltInRouteManifestEntry {
|
|
|
8
8
|
export interface GenerateRouteManifestOptions {
|
|
9
9
|
readonly builtInRoutes?: readonly BuiltInRouteManifestEntry[];
|
|
10
10
|
}
|
|
11
|
+
export declare const AUTH_EXPERIENCE_BOOTSTRAP_PLACEHOLDER = "__SIXB_AUTH_BOOTSTRAP__";
|
|
11
12
|
/**
|
|
12
13
|
* Generates `.sixb/generated/routes.ts` with static route imports. Pages are
|
|
13
14
|
* eager on purpose: project-specific apps bundle small, and a single bundle
|
|
@@ -15,6 +16,15 @@ export interface GenerateRouteManifestOptions {
|
|
|
15
16
|
* late-arriving styles when navigating — matching how Atlas routes.
|
|
16
17
|
*/
|
|
17
18
|
export declare function generateRouteManifest(routes: PageRoute[], generatedDir: string, options?: GenerateRouteManifestOptions): Promise<string>;
|
|
19
|
+
/** Generates the optional browser entry served by the API for `/auth/*`. */
|
|
20
|
+
export declare function generateAuthExperienceEntry(projectRoot: string, generatedDir: string, options?: {
|
|
21
|
+
readonly appDir?: string;
|
|
22
|
+
readonly publicDir?: string;
|
|
23
|
+
readonly stylesheetPath?: string | null;
|
|
24
|
+
}): Promise<{
|
|
25
|
+
readonly htmlPath: string;
|
|
26
|
+
readonly mainPath: string;
|
|
27
|
+
} | null>;
|
|
18
28
|
/**
|
|
19
29
|
* Generates the app entry files:
|
|
20
30
|
* - `.sixb/generated/index.html` — HTML shell
|
package/dist/codegen.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../src/codegen.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAIrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAE1C,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAC7B;AAED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,yBAAyB,EAAE,CAAA;CAC9D;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,SAAS,EAAE,EACnB,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,4BAAiC,GACzC,OAAO,CAAC,MAAM,CAAC,CAyCjB;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE;IACP,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,mBAAmB,CAAA;IAC9B,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,sEAAsE;IACtE,wBAAwB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CACxC,GACL,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC,CA2avE"}
|
|
1
|
+
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../src/codegen.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAIrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAE1C,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAC7B;AAED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,yBAAyB,EAAE,CAAA;CAC9D;AAED,eAAO,MAAM,qCAAqC,4BAA4B,CAAA;AAE9E;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,SAAS,EAAE,EACnB,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,4BAAiC,GACzC,OAAO,CAAC,MAAM,CAAC,CAyCjB;AAED,4EAA4E;AAC5E,wBAAsB,2BAA2B,CAC/C,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE;IACP,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACnC,GACL,OAAO,CAAC;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CA8H1E;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE;IACP,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,mBAAmB,CAAA;IAC9B,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,sEAAsE;IACtE,wBAAwB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CACxC,GACL,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC,CA2avE"}
|
|
@@ -18,6 +18,12 @@ export interface CustomAppDevOptions {
|
|
|
18
18
|
export interface CustomAppBuildOptions {
|
|
19
19
|
outdir?: string;
|
|
20
20
|
}
|
|
21
|
+
export interface CustomAuthExperienceBuildOptions {
|
|
22
|
+
outdir?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface CustomAuthExperienceBuildResult {
|
|
25
|
+
readonly outdir: string;
|
|
26
|
+
}
|
|
21
27
|
export interface CustomAppStartOptions {
|
|
22
28
|
host?: string;
|
|
23
29
|
port?: number;
|
|
@@ -35,6 +41,7 @@ export interface CustomAppDevServer {
|
|
|
35
41
|
export interface CustomAppInstance {
|
|
36
42
|
scanRoutes(): Promise<PageRoute[]>;
|
|
37
43
|
hasRoutes(): Promise<boolean>;
|
|
44
|
+
prepareAuthExperience(options?: CustomAuthExperienceBuildOptions): Promise<CustomAuthExperienceBuildResult | null>;
|
|
38
45
|
dev(options?: CustomAppDevOptions): Promise<CustomAppDevServer>;
|
|
39
46
|
build(options?: CustomAppBuildOptions): Promise<BuildAppResult>;
|
|
40
47
|
start(options?: CustomAppStartOptions): Promise<CustomAppDevServer>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCustomApp.d.ts","sourceRoot":"","sources":["../src/createCustomApp.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AACrD,OAAO,EACL,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"createCustomApp.d.ts","sourceRoot":"","sources":["../src/createCustomApp.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AACrD,OAAO,EACL,KAAK,cAAc,EAKpB,MAAM,SAAS,CAAA;AAQhB,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,WAAW,CAAA;AAIrD,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,mBAAmB,CAAA;IAC9B,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,gCAAgC;IAC/C,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,mBAAmB,CAAA;IAC9B,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAAA;IAClC,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;IAC7B,qBAAqB,CACnB,OAAO,CAAC,EAAE,gCAAgC,GACzC,OAAO,CAAC,+BAA+B,GAAG,IAAI,CAAC,CAAA;IAClD,GAAG,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;IAC/D,KAAK,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IAC/D,KAAK,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;CACpE;AAWD,wBAAsB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAibjG"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { type CreateCustomAppOptions, type CustomAppBuildOptions, type CustomAppDevOptions, type CustomAppDevServer, type CustomAppInstance, type CustomAppStartOptions, createCustomApp, } from "./createCustomApp";
|
|
1
|
+
export { type CreateCustomAppOptions, type CustomAppBuildOptions, type CustomAppDevOptions, type CustomAppDevServer, type CustomAppInstance, type CustomAppStartOptions, type CustomAuthExperienceBuildOptions, type CustomAuthExperienceBuildResult, createCustomApp, } from "./createCustomApp";
|
|
2
2
|
export type { AppMetadata } from "./metadata";
|
|
3
3
|
export { createTailwindCssCompiler, type TailwindCssCompiler, type TailwindCssCompilerOptions, } from "./tailwind";
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,eAAe,GAChB,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EACL,yBAAyB,EACzB,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,GAChC,MAAM,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,gCAAgC,EACrC,KAAK,+BAA+B,EACpC,eAAe,GAChB,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EACL,yBAAyB,EACzB,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,GAChC,MAAM,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// src/createCustomApp.ts
|
|
3
3
|
import { watch } from "fs";
|
|
4
|
-
import { access as access2, cp, mkdir as mkdir4, readFile as readFile5, writeFile as writeFile3 } from "fs/promises";
|
|
4
|
+
import { access as access2, cp, mkdir as mkdir4, readFile as readFile5, rm as rm2, writeFile as writeFile3 } from "fs/promises";
|
|
5
5
|
import { dirname as dirname3, isAbsolute, join as join7, normalize, relative as relative3, resolve as resolve3 } from "path";
|
|
6
6
|
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
7
7
|
|
|
@@ -69,6 +69,54 @@ async function buildApp(options) {
|
|
|
69
69
|
await precompressBuildAssets(result.outputs);
|
|
70
70
|
return { success: true, outdir };
|
|
71
71
|
}
|
|
72
|
+
async function buildAuthExperience(options) {
|
|
73
|
+
const outdir = resolve(options.outdir);
|
|
74
|
+
const assetsDir = join(outdir, "assets");
|
|
75
|
+
await rm(outdir, { recursive: true, force: true });
|
|
76
|
+
await mkdir(assetsDir, { recursive: true });
|
|
77
|
+
const result = await Bun.build({
|
|
78
|
+
entrypoints: [options.scriptEntryPath],
|
|
79
|
+
outdir: assetsDir,
|
|
80
|
+
target: "browser",
|
|
81
|
+
conditions: ["bun"],
|
|
82
|
+
publicPath: "/auth/assets/",
|
|
83
|
+
minify: true,
|
|
84
|
+
splitting: true,
|
|
85
|
+
naming: {
|
|
86
|
+
entry: "auth-[hash].[ext]",
|
|
87
|
+
chunk: "chunk-[name]-[hash].[ext]",
|
|
88
|
+
asset: "asset-[name]-[hash].[ext]"
|
|
89
|
+
},
|
|
90
|
+
plugins: [extensionlessSourceImportPlugin],
|
|
91
|
+
define: { "process.env.NODE_ENV": '"production"' },
|
|
92
|
+
sourcemap: "external"
|
|
93
|
+
});
|
|
94
|
+
if (!result.success) {
|
|
95
|
+
return {
|
|
96
|
+
success: false,
|
|
97
|
+
outdir,
|
|
98
|
+
logs: result.logs.map(String)
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const script = result.outputs.find((output) => output.kind === "entry-point" && output.type.startsWith("text/javascript"));
|
|
102
|
+
const stylesheets = result.outputs.filter((output) => output.type.startsWith("text/css"));
|
|
103
|
+
if (!script || stylesheets.length > 1) {
|
|
104
|
+
throw new Error(`[SixbCustomApp] Expected one auth entry and at most one stylesheet, found ${script ? 1 : 0} entries and ${stylesheets.length} stylesheets.`);
|
|
105
|
+
}
|
|
106
|
+
const sourceHtml = await readFile(options.entryPath, "utf-8");
|
|
107
|
+
const sourceEntryPattern = /\s*<script\s+type=["']module["']\s+src=["']\.\/auth-main\.tsx["']><\/script>/;
|
|
108
|
+
if (!sourceEntryPattern.test(sourceHtml)) {
|
|
109
|
+
throw new Error("[SixbCustomApp] Generated auth shell is missing its ./auth-main.tsx entry.");
|
|
110
|
+
}
|
|
111
|
+
const assetTags = [
|
|
112
|
+
...stylesheets.map((stylesheet) => `<link rel="stylesheet" crossorigin href="/auth/assets/${basename(stylesheet.path)}">`),
|
|
113
|
+
`<script type="module" crossorigin src="/auth/assets/${basename(script.path)}"></script>`
|
|
114
|
+
].join("");
|
|
115
|
+
const html = sourceHtml.replace(sourceEntryPattern, "").replace("</head>", ` ${assetTags}</head>`);
|
|
116
|
+
await writeFile(join(outdir, "index.html"), html, "utf-8");
|
|
117
|
+
await precompressBuildAssets(result.outputs);
|
|
118
|
+
return { success: true, outdir };
|
|
119
|
+
}
|
|
72
120
|
async function prepareAppHtmlBundleEntry(entryPath) {
|
|
73
121
|
const html = await readFile(entryPath, "utf-8");
|
|
74
122
|
const bundleHtml = html.replace(/(<link\s+rel=["'](?:manifest|icon|apple-touch-icon)["']\s+href=["'])(\/[^"']*)(["'][^>]*>)/g, `$1${STATIC_ASSET_ORIGIN}$2$3`);
|
|
@@ -306,6 +354,7 @@ function renderCustomAppRuntimeScript(config) {
|
|
|
306
354
|
}
|
|
307
355
|
|
|
308
356
|
// src/codegen.ts
|
|
357
|
+
var AUTH_EXPERIENCE_BOOTSTRAP_PLACEHOLDER = "__SIXB_AUTH_BOOTSTRAP__";
|
|
309
358
|
async function generateRouteManifest(routes, generatedDir, options = {}) {
|
|
310
359
|
await mkdir2(generatedDir, { recursive: true });
|
|
311
360
|
const imports = routes.map((route, index) => {
|
|
@@ -339,6 +388,119 @@ ${routeEntries}
|
|
|
339
388
|
await writeFileIfChanged(outPath, content);
|
|
340
389
|
return outPath;
|
|
341
390
|
}
|
|
391
|
+
async function generateAuthExperienceEntry(projectRoot, generatedDir, options = {}) {
|
|
392
|
+
await mkdir2(generatedDir, { recursive: true });
|
|
393
|
+
const appDir = options.appDir ? resolve2(projectRoot, options.appDir) : join3(projectRoot, "app");
|
|
394
|
+
const authPath = join3(appDir, "auth.tsx");
|
|
395
|
+
if (!await fileExists2(authPath)) {
|
|
396
|
+
return null;
|
|
397
|
+
}
|
|
398
|
+
const publicDir = options.publicDir ? resolve2(projectRoot, options.publicDir) : join3(appDir, "public");
|
|
399
|
+
const layoutPath = join3(appDir, "layout.tsx");
|
|
400
|
+
const globalsCssPath = join3(appDir, "globals.css");
|
|
401
|
+
const metadata = await resolveAppMetadata({ layoutPath, publicDir });
|
|
402
|
+
const stylesheetPath = options.stylesheetPath !== undefined ? options.stylesheetPath : await fileExists2(globalsCssPath) ? globalsCssPath : null;
|
|
403
|
+
const stylesheetImport = stylesheetPath ? `import ${JSON.stringify(relativeTo(generatedDir, stylesheetPath))}` : "";
|
|
404
|
+
const authRel = relativeTo(generatedDir, authPath);
|
|
405
|
+
const mainContent = `import React from "react"
|
|
406
|
+
import { createRoot } from "react-dom/client"
|
|
407
|
+
import type {
|
|
408
|
+
AuthExperienceActions,
|
|
409
|
+
AuthExperienceState,
|
|
410
|
+
} from "@sixb/app/auth"
|
|
411
|
+
import AuthExperience from ${JSON.stringify(authRel)}
|
|
412
|
+
${stylesheetImport}
|
|
413
|
+
|
|
414
|
+
interface AuthExperienceBootstrap {
|
|
415
|
+
readonly state: AuthExperienceState
|
|
416
|
+
readonly signInUrl: string
|
|
417
|
+
readonly submission?: {
|
|
418
|
+
readonly kind: "requestMagicLink" | "confirmSignIn"
|
|
419
|
+
readonly action: string
|
|
420
|
+
readonly fields: Readonly<Record<string, string>>
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const root = document.getElementById("root")
|
|
425
|
+
if (!root) {
|
|
426
|
+
throw new Error("[SixbApp] Could not find the auth experience root element.")
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const encodedBootstrap = root.dataset.sixbAuth
|
|
430
|
+
if (!encodedBootstrap) {
|
|
431
|
+
throw new Error("[SixbApp] Auth experience bootstrap is missing.")
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
const bootstrap = decodeBootstrap(encodedBootstrap)
|
|
435
|
+
const actions: AuthExperienceActions = {
|
|
436
|
+
requestMagicLink(email) {
|
|
437
|
+
submit("requestMagicLink", { email })
|
|
438
|
+
},
|
|
439
|
+
confirmSignIn() {
|
|
440
|
+
submit("confirmSignIn")
|
|
441
|
+
},
|
|
442
|
+
restartSignIn() {
|
|
443
|
+
window.location.assign(bootstrap.signInUrl)
|
|
444
|
+
},
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function submit(
|
|
448
|
+
kind: NonNullable<AuthExperienceBootstrap["submission"]>["kind"],
|
|
449
|
+
additionalFields: Readonly<Record<string, string>> = {}
|
|
450
|
+
): void {
|
|
451
|
+
const submission = bootstrap.submission
|
|
452
|
+
if (!submission || submission.kind !== kind) {
|
|
453
|
+
throw new Error("[SixbApp] Auth action '" + kind + "' is not available in this state.")
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
const form = document.createElement("form")
|
|
457
|
+
form.method = "post"
|
|
458
|
+
form.action = submission.action
|
|
459
|
+
form.hidden = true
|
|
460
|
+
for (const [name, value] of Object.entries({ ...submission.fields, ...additionalFields })) {
|
|
461
|
+
const input = document.createElement("input")
|
|
462
|
+
input.type = "hidden"
|
|
463
|
+
input.name = name
|
|
464
|
+
input.value = value
|
|
465
|
+
form.append(input)
|
|
466
|
+
}
|
|
467
|
+
document.body.append(form)
|
|
468
|
+
form.submit()
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function decodeBootstrap(value: string): AuthExperienceBootstrap {
|
|
472
|
+
const base64 = value.replaceAll("-", "+").replaceAll("_", "/")
|
|
473
|
+
const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=")
|
|
474
|
+
const bytes = Uint8Array.from(atob(padded), (character) => character.charCodeAt(0))
|
|
475
|
+
return JSON.parse(new TextDecoder().decode(bytes)) as AuthExperienceBootstrap
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
createRoot(root).render(<AuthExperience state={bootstrap.state} actions={actions} />)
|
|
479
|
+
`;
|
|
480
|
+
const mainPath = join3(generatedDir, "auth-main.tsx");
|
|
481
|
+
await writeFileIfChanged(mainPath, mainContent);
|
|
482
|
+
const htmlContent = `<!DOCTYPE html>
|
|
483
|
+
<html lang="en">
|
|
484
|
+
<head>
|
|
485
|
+
<meta charset="UTF-8" />
|
|
486
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
|
487
|
+
${renderAuthMetadataHead(metadata)}
|
|
488
|
+
<style>
|
|
489
|
+
* { box-sizing: border-box; }
|
|
490
|
+
html, body, #root { margin: 0; min-height: 100%; }
|
|
491
|
+
body, #root { min-height: 100vh; min-height: 100dvh; }
|
|
492
|
+
</style>
|
|
493
|
+
</head>
|
|
494
|
+
<body>
|
|
495
|
+
<div id="root" data-sixb-auth="${AUTH_EXPERIENCE_BOOTSTRAP_PLACEHOLDER}"></div>
|
|
496
|
+
<script type="module" src="./auth-main.tsx"></script>
|
|
497
|
+
</body>
|
|
498
|
+
</html>
|
|
499
|
+
`;
|
|
500
|
+
const htmlPath = join3(generatedDir, "auth-index.html");
|
|
501
|
+
await writeFileIfChanged(htmlPath, htmlContent);
|
|
502
|
+
return { htmlPath, mainPath };
|
|
503
|
+
}
|
|
342
504
|
async function generateAppEntry(projectRoot, generatedDir, options = {}) {
|
|
343
505
|
await mkdir2(generatedDir, { recursive: true });
|
|
344
506
|
const appDir = options.appDir ? resolve2(projectRoot, options.appDir) : join3(projectRoot, "app");
|
|
@@ -761,6 +923,16 @@ function renderMetadataHead(metadata) {
|
|
|
761
923
|
return tags.join(`
|
|
762
924
|
`);
|
|
763
925
|
}
|
|
926
|
+
function renderAuthMetadataHead(metadata) {
|
|
927
|
+
const tags = [
|
|
928
|
+
` <title>${escapeHtmlText(metadata.title)}</title>`,
|
|
929
|
+
...metadata.description ? [` <meta name="description" content="${escapeHtmlAttribute(metadata.description)}" />`] : [],
|
|
930
|
+
` <meta name="theme-color" content="${escapeHtmlAttribute(metadata.themeColor)}" />`,
|
|
931
|
+
...metadata.favicon && /^(?:https?:|data:)/.test(metadata.favicon) ? [` <link rel="icon" href="${escapeHtmlAttribute(metadata.favicon)}" />`] : []
|
|
932
|
+
];
|
|
933
|
+
return tags.join(`
|
|
934
|
+
`);
|
|
935
|
+
}
|
|
764
936
|
function escapeHtmlText(value) {
|
|
765
937
|
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
766
938
|
}
|
|
@@ -1009,6 +1181,7 @@ async function createCustomApp(options) {
|
|
|
1009
1181
|
}
|
|
1010
1182
|
let tailwindCompiler = null;
|
|
1011
1183
|
let tailwindCompilerKey = null;
|
|
1184
|
+
let authTailwindCompiler = null;
|
|
1012
1185
|
let builtInAgentCssCompiler = null;
|
|
1013
1186
|
async function prepareStylesheet(stylesheet) {
|
|
1014
1187
|
stylesheet ??= await resolveCustomAppStylesheet({ appDir, generatedDir, rootDir });
|
|
@@ -1111,6 +1284,49 @@ async function createCustomApp(options) {
|
|
|
1111
1284
|
});
|
|
1112
1285
|
return { htmlPath, mainPath, manifestPath, routes };
|
|
1113
1286
|
}
|
|
1287
|
+
async function prepareAuthExperience(authOptions = {}) {
|
|
1288
|
+
const outdir = authOptions.outdir ? resolve3(rootDir, authOptions.outdir) : join7(generatedDir, "auth");
|
|
1289
|
+
if (!await pathExists(join7(appDir, "auth.tsx"))) {
|
|
1290
|
+
await rm2(outdir, { recursive: true, force: true });
|
|
1291
|
+
return null;
|
|
1292
|
+
}
|
|
1293
|
+
const stylesheet = await resolveCustomAppStylesheet({ appDir, generatedDir, rootDir });
|
|
1294
|
+
let stylesheetPath;
|
|
1295
|
+
if (stylesheet.kind === "none") {
|
|
1296
|
+
stylesheetPath = null;
|
|
1297
|
+
} else if (stylesheet.kind === "static") {
|
|
1298
|
+
stylesheetPath = stylesheet.path;
|
|
1299
|
+
} else {
|
|
1300
|
+
const outputPath = join7(generatedDir, "auth.css");
|
|
1301
|
+
authTailwindCompiler ??= createTailwindCssCompiler({
|
|
1302
|
+
inputPath: stylesheet.sourcePath,
|
|
1303
|
+
outputPath,
|
|
1304
|
+
cwd: appDir,
|
|
1305
|
+
resolveFrom: rootDir,
|
|
1306
|
+
label: "[SixbCustomApp]"
|
|
1307
|
+
});
|
|
1308
|
+
await authTailwindCompiler.compile();
|
|
1309
|
+
stylesheetPath = outputPath;
|
|
1310
|
+
}
|
|
1311
|
+
const entry = await generateAuthExperienceEntry(rootDir, generatedDir, {
|
|
1312
|
+
appDir,
|
|
1313
|
+
publicDir,
|
|
1314
|
+
stylesheetPath
|
|
1315
|
+
});
|
|
1316
|
+
if (!entry) {
|
|
1317
|
+
return null;
|
|
1318
|
+
}
|
|
1319
|
+
const result = await buildAuthExperience({
|
|
1320
|
+
entryPath: entry.htmlPath,
|
|
1321
|
+
scriptEntryPath: entry.mainPath,
|
|
1322
|
+
outdir
|
|
1323
|
+
});
|
|
1324
|
+
if (!result.success) {
|
|
1325
|
+
throw new Error(`[SixbCustomApp] Failed to build the auth experience: ${(result.logs ?? []).join(`
|
|
1326
|
+
`)}`);
|
|
1327
|
+
}
|
|
1328
|
+
return { outdir: result.outdir };
|
|
1329
|
+
}
|
|
1114
1330
|
return {
|
|
1115
1331
|
async scanRoutes() {
|
|
1116
1332
|
return await scanRoutes();
|
|
@@ -1119,10 +1335,14 @@ async function createCustomApp(options) {
|
|
|
1119
1335
|
const routes = await scanRoutes();
|
|
1120
1336
|
return routes.length > 0;
|
|
1121
1337
|
},
|
|
1338
|
+
async prepareAuthExperience(options2) {
|
|
1339
|
+
return await prepareAuthExperience(options2);
|
|
1340
|
+
},
|
|
1122
1341
|
async dev(devOptions = {}) {
|
|
1123
1342
|
const host = devOptions.host ?? "0.0.0.0";
|
|
1124
1343
|
const port = devOptions.port ?? 3001;
|
|
1125
1344
|
const { htmlPath, manifestPath } = await prepareGeneratedApp();
|
|
1345
|
+
await prepareAuthExperience();
|
|
1126
1346
|
let htmlImportVersion = 0;
|
|
1127
1347
|
let htmlBundle = await importHtmlBundle(htmlPath, htmlImportVersion);
|
|
1128
1348
|
const publicRoutes = await pathExists(publicDir) ? await createPublicRoutes(publicDir) : {};
|
|
@@ -1147,6 +1367,7 @@ async function createCustomApp(options) {
|
|
|
1147
1367
|
const enqueueRebuild = () => {
|
|
1148
1368
|
rebuildChain = rebuildChain.then(async () => {
|
|
1149
1369
|
const { htmlPath: nextHtmlPath } = await prepareGeneratedApp();
|
|
1370
|
+
await prepareAuthExperience();
|
|
1150
1371
|
htmlImportVersion++;
|
|
1151
1372
|
htmlBundle = await importHtmlBundle(nextHtmlPath, htmlImportVersion);
|
|
1152
1373
|
server.reload(serveOptions(htmlBundle));
|
|
@@ -1185,6 +1406,7 @@ async function createCustomApp(options) {
|
|
|
1185
1406
|
watcher.close();
|
|
1186
1407
|
await rebuildChain;
|
|
1187
1408
|
await tailwindCompiler?.stop();
|
|
1409
|
+
await authTailwindCompiler?.stop();
|
|
1188
1410
|
await builtInAgentCssCompiler?.stop();
|
|
1189
1411
|
server.stop(true);
|
|
1190
1412
|
}
|
|
@@ -1199,11 +1421,17 @@ async function createCustomApp(options) {
|
|
|
1199
1421
|
manifestPath,
|
|
1200
1422
|
outdir
|
|
1201
1423
|
});
|
|
1424
|
+
if (result.success) {
|
|
1425
|
+
await prepareAuthExperience({ outdir: join7(outdir, "auth") });
|
|
1426
|
+
}
|
|
1202
1427
|
if (result.success && await pathExists(publicDir)) {
|
|
1203
1428
|
await cp(publicDir, outdir, {
|
|
1204
1429
|
recursive: true,
|
|
1205
1430
|
force: true,
|
|
1206
|
-
filter: (source) =>
|
|
1431
|
+
filter: (source) => {
|
|
1432
|
+
const resolvedSource = resolve3(source);
|
|
1433
|
+
return resolvedSource !== join7(publicDir, "app.webmanifest") && resolvedSource !== join7(publicDir, "auth");
|
|
1434
|
+
}
|
|
1207
1435
|
});
|
|
1208
1436
|
}
|
|
1209
1437
|
return result;
|
|
@@ -1582,4 +1810,4 @@ export {
|
|
|
1582
1810
|
createCustomApp
|
|
1583
1811
|
};
|
|
1584
1812
|
|
|
1585
|
-
//# debugId=
|
|
1813
|
+
//# debugId=DF164E399EBD3CA764756E2164756E21
|