@makeswift/hono-react 0.0.7-canary.0 → 0.1.0-canary.2
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/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/runtime.js +38 -0
- package/dist/cjs/runtime.js.map +1 -0
- package/dist/cjs/server/api-handler.js +1 -2
- package/dist/cjs/server/api-handler.js.map +1 -1
- package/dist/cjs/server/preview.js +2 -3
- package/dist/cjs/server/preview.js.map +1 -1
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/runtime.js +14 -0
- package/dist/esm/runtime.js.map +1 -0
- package/dist/esm/server/api-handler.js +1 -2
- package/dist/esm/server/api-handler.js.map +1 -1
- package/dist/esm/server/preview.js +2 -3
- package/dist/esm/server/preview.js.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/runtime.d.ts +9 -0
- package/dist/types/runtime.d.ts.map +1 -0
- package/dist/types/server/api-handler.d.ts +1 -1
- package/dist/types/server/api-handler.d.ts.map +1 -1
- package/dist/types/server/preview.d.ts +2 -3
- package/dist/types/server/preview.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -21,7 +21,7 @@ __export(src_exports, {
|
|
|
21
21
|
Makeswift: () => import_client.Makeswift,
|
|
22
22
|
MakeswiftComponent: () => import_unstable_framework_support.MakeswiftComponent,
|
|
23
23
|
Page: () => import_unstable_framework_support.Page,
|
|
24
|
-
ReactRuntime: () =>
|
|
24
|
+
ReactRuntime: () => import_runtime.HonoReactRuntime,
|
|
25
25
|
ReactRuntimeProvider: () => import_unstable_framework_support.RuntimeProvider,
|
|
26
26
|
RootStyleRegistry: () => import_root_style_registry.ReactRootStyleRegistry,
|
|
27
27
|
Slot: () => import_unstable_framework_support.Slot
|
|
@@ -30,6 +30,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
30
30
|
var import_unstable_framework_support = require("@makeswift/runtime/unstable-framework-support");
|
|
31
31
|
var import_client = require("./client");
|
|
32
32
|
var import_root_style_registry = require("./root-style-registry");
|
|
33
|
+
var import_runtime = require("./runtime");
|
|
33
34
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
35
|
0 && (module.exports = {
|
|
35
36
|
Makeswift,
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n type SiteVersion,\n MakeswiftComponent,\n Page,\n Slot,\n RuntimeProvider as ReactRuntimeProvider,\n
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n type SiteVersion,\n MakeswiftComponent,\n Page,\n Slot,\n RuntimeProvider as ReactRuntimeProvider,\n} from '@makeswift/runtime/unstable-framework-support'\n\nexport { Makeswift } from './client'\nexport { ReactRootStyleRegistry as RootStyleRegistry } from './root-style-registry'\nexport { HonoReactRuntime as ReactRuntime } from './runtime'\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wCAMO;AAEP,oBAA0B;AAC1B,iCAA4D;AAC5D,qBAAiD;","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var runtime_exports = {};
|
|
20
|
+
__export(runtime_exports, {
|
|
21
|
+
HonoReactRuntime: () => HonoReactRuntime
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(runtime_exports);
|
|
24
|
+
var import_unstable_framework_support = require("@makeswift/runtime/unstable-framework-support");
|
|
25
|
+
class HonoReactRuntime extends import_unstable_framework_support.ReactRuntime {
|
|
26
|
+
constructor(args = {}) {
|
|
27
|
+
super({
|
|
28
|
+
...args,
|
|
29
|
+
fetch: (url, init) => fetch(url, init)
|
|
30
|
+
// TODO: revalidation support
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
HonoReactRuntime
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/runtime.ts"],"sourcesContent":["import { type Breakpoints, ReactRuntime } from '@makeswift/runtime/unstable-framework-support'\n\nexport class HonoReactRuntime extends ReactRuntime {\n constructor(args: { appOrigin?: string; apiOrigin?: string; breakpoints?: Breakpoints } = {}) {\n super({\n ...args,\n fetch: (url, init) => fetch(url, init), // TODO: revalidation support\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wCAA+C;AAExC,MAAM,yBAAyB,+CAAa;AAAA,EACjD,YAAY,OAA8E,CAAC,GAAG;AAC5F,UAAM;AAAA,MACJ,GAAG;AAAA,MACH,OAAO,CAAC,KAAK,SAAS,MAAM,KAAK,IAAI;AAAA;AAAA,IACvC,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -27,7 +27,6 @@ const API_PATH_PREFIX = "/api/makeswift/";
|
|
|
27
27
|
function createApiHandler({
|
|
28
28
|
apiKey,
|
|
29
29
|
runtime,
|
|
30
|
-
apiOrigin,
|
|
31
30
|
revalidationHandler,
|
|
32
31
|
...userConfig
|
|
33
32
|
}) {
|
|
@@ -36,7 +35,7 @@ function createApiHandler({
|
|
|
36
35
|
return next();
|
|
37
36
|
}
|
|
38
37
|
const route = `/${c.req.path.replace(API_PATH_PREFIX, "")}`;
|
|
39
|
-
const client = new import_client.Makeswift(apiKey, {
|
|
38
|
+
const client = new import_client.Makeswift(apiKey, { runtime });
|
|
40
39
|
const apiHandler2 = (0, import_unstable_framework_support.createApiHandler)(apiKey, {
|
|
41
40
|
...userConfig,
|
|
42
41
|
previewCookieNames: [import_unstable_framework_support.MAKESWIFT_SITE_VERSION_COOKIE],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/api-handler.ts"],"sourcesContent":["import { type Context, type MiddlewareHandler, type Next } from 'hono'\n\nimport {\n type ApiHandlerUserConfig,\n MAKESWIFT_SITE_VERSION_COOKIE,\n createApiHandler as createMakeswiftApiHandler,\n} from '@makeswift/runtime/unstable-framework-support'\n\nimport { Makeswift as MakeswiftClient } from '../client'\n\nimport { type Env } from './env'\n\nconst API_PATH_PREFIX = '/api/makeswift/'\n\ntype UserConfig = ApiHandlerUserConfig & {\n apiKey: string\n revalidationHandler?: (path?: string) => Promise<void>\n}\n\nexport function createApiHandler<E extends Env>({\n apiKey,\n runtime,\n
|
|
1
|
+
{"version":3,"sources":["../../../src/server/api-handler.ts"],"sourcesContent":["import { type Context, type MiddlewareHandler, type Next } from 'hono'\n\nimport {\n type ApiHandlerUserConfig,\n MAKESWIFT_SITE_VERSION_COOKIE,\n createApiHandler as createMakeswiftApiHandler,\n} from '@makeswift/runtime/unstable-framework-support'\n\nimport { Makeswift as MakeswiftClient } from '../client'\n\nimport { type Env } from './env'\n\nconst API_PATH_PREFIX = '/api/makeswift/'\n\ntype UserConfig = ApiHandlerUserConfig & {\n apiKey: string\n revalidationHandler?: (path?: string) => Promise<void>\n}\n\nexport function createApiHandler<E extends Env>({\n apiKey,\n runtime,\n revalidationHandler,\n ...userConfig\n}: UserConfig): MiddlewareHandler {\n return async function apiHandler(c: Context<E>, next: Next): Promise<Response | void> {\n if (!c.req.path.startsWith(API_PATH_PREFIX)) {\n return next()\n }\n\n const route = `/${c.req.path.replace(API_PATH_PREFIX, '')}`\n const client = new MakeswiftClient(apiKey, { runtime })\n\n const apiHandler = createMakeswiftApiHandler(apiKey, {\n ...userConfig,\n previewCookieNames: [MAKESWIFT_SITE_VERSION_COOKIE],\n revalidationHandler: revalidationHandler ?? (() => Promise.resolve()),\n runtime,\n client,\n })\n\n return await apiHandler(c.req.raw, route)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,wCAIO;AAEP,oBAA6C;AAI7C,MAAM,kBAAkB;AAOjB,SAAS,iBAAgC;AAAA,EAC9C;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAkC;AAChC,SAAO,eAAe,WAAW,GAAe,MAAsC;AACpF,QAAI,CAAC,EAAE,IAAI,KAAK,WAAW,eAAe,GAAG;AAC3C,aAAO,KAAK;AAAA,IACd;AAEA,UAAM,QAAQ,IAAI,EAAE,IAAI,KAAK,QAAQ,iBAAiB,EAAE,CAAC;AACzD,UAAM,SAAS,IAAI,cAAAA,UAAgB,QAAQ,EAAE,QAAQ,CAAC;AAEtD,UAAMC,kBAAa,kCAAAC,kBAA0B,QAAQ;AAAA,MACnD,GAAG;AAAA,MACH,oBAAoB,CAAC,+DAA6B;AAAA,MAClD,qBAAqB,wBAAwB,MAAM,QAAQ,QAAQ;AAAA,MACnE;AAAA,MACA;AAAA,IACF,CAAC;AAED,WAAO,MAAMD,YAAW,EAAE,IAAI,KAAK,KAAK;AAAA,EAC1C;AACF;","names":["MakeswiftClient","apiHandler","createMakeswiftApiHandler"]}
|
|
@@ -39,8 +39,7 @@ async function requestedSiteVersion({
|
|
|
39
39
|
}
|
|
40
40
|
function createPreviewMiddleware({
|
|
41
41
|
apiKey,
|
|
42
|
-
runtime
|
|
43
|
-
apiOrigin
|
|
42
|
+
runtime
|
|
44
43
|
}) {
|
|
45
44
|
return async function apiHandler(c, next) {
|
|
46
45
|
const { pathname, searchParams } = new URL(c.req.url, `https://example.com`);
|
|
@@ -50,7 +49,7 @@ function createPreviewMiddleware({
|
|
|
50
49
|
previewCookieNames: [import_unstable_framework_support.MAKESWIFT_SITE_VERSION_COOKIE]
|
|
51
50
|
});
|
|
52
51
|
}
|
|
53
|
-
const client = new import_client.Makeswift(apiKey, {
|
|
52
|
+
const client = new import_client.Makeswift(apiKey, { runtime });
|
|
54
53
|
const siteVersion = await requestedSiteVersion({ searchParams, client });
|
|
55
54
|
if (siteVersion == null)
|
|
56
55
|
return next();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/preview.ts"],"sourcesContent":["import { type Context, type MiddlewareHandler, type Next } from 'hono'\nimport { setCookie } from 'hono/cookie'\n\nimport {\n type SiteVersion,\n MAKESWIFT_SITE_VERSION_COOKIE,\n REDIRECT_SEARCH_PARAM,\n cookieSettingOptions,\n redirectLiveHandler,\n SearchParams,\n secondsUntilSiteVersionExpiration,\n serializeSiteVersion,\n} from '@makeswift/runtime/unstable-framework-support'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/server/preview.ts"],"sourcesContent":["import { type Context, type MiddlewareHandler, type Next } from 'hono'\nimport { setCookie } from 'hono/cookie'\n\nimport {\n type SiteVersion,\n MAKESWIFT_SITE_VERSION_COOKIE,\n REDIRECT_SEARCH_PARAM,\n cookieSettingOptions,\n redirectLiveHandler,\n SearchParams,\n secondsUntilSiteVersionExpiration,\n serializeSiteVersion,\n ReactRuntime,\n} from '@makeswift/runtime/unstable-framework-support'\n\nimport { Makeswift as MakeswiftClient } from '../client'\n\nimport { type Env } from './env'\n\nasync function requestedSiteVersion({\n searchParams,\n client,\n}: {\n searchParams: URLSearchParams\n client: MakeswiftClient\n}): Promise<SiteVersion | null> {\n const previewToken = searchParams.get(SearchParams.PreviewToken)\n if (previewToken == null) return null\n\n const verifiedToken = await client.readPreviewToken(previewToken)\n if (verifiedToken == null) return null\n\n const { payload } = verifiedToken\n\n return { version: payload.version, token: previewToken }\n}\n\nexport function createPreviewMiddleware<E extends Env>({\n apiKey,\n runtime,\n}: {\n apiKey: string\n runtime: ReactRuntime\n}): MiddlewareHandler {\n return async function apiHandler(c: Context<E>, next: Next): Promise<Response | void> {\n const { pathname, searchParams } = new URL(c.req.url, `https://example.com`)\n\n const redirectLive = searchParams.get(REDIRECT_SEARCH_PARAM)\n if (redirectLive != null) {\n return await redirectLiveHandler(c.req.raw, {\n previewCookieNames: [MAKESWIFT_SITE_VERSION_COOKIE],\n })\n }\n\n const client = new MakeswiftClient(apiKey, { runtime })\n\n const siteVersion = await requestedSiteVersion({ searchParams, client })\n if (siteVersion == null) return next()\n\n const serializedSiteVersion = serializeSiteVersion(siteVersion)\n const secondsUntilExpiration = secondsUntilSiteVersionExpiration(siteVersion)\n\n setCookie(c, MAKESWIFT_SITE_VERSION_COOKIE, serializedSiteVersion, {\n ...cookieSettingOptions,\n maxAge: secondsUntilExpiration,\n })\n\n return c.redirect(pathname)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA0B;AAE1B,wCAUO;AAEP,oBAA6C;AAI7C,eAAe,qBAAqB;AAAA,EAClC;AAAA,EACA;AACF,GAGgC;AAC9B,QAAM,eAAe,aAAa,IAAI,+CAAa,YAAY;AAC/D,MAAI,gBAAgB;AAAM,WAAO;AAEjC,QAAM,gBAAgB,MAAM,OAAO,iBAAiB,YAAY;AAChE,MAAI,iBAAiB;AAAM,WAAO;AAElC,QAAM,EAAE,QAAQ,IAAI;AAEpB,SAAO,EAAE,SAAS,QAAQ,SAAS,OAAO,aAAa;AACzD;AAEO,SAAS,wBAAuC;AAAA,EACrD;AAAA,EACA;AACF,GAGsB;AACpB,SAAO,eAAe,WAAW,GAAe,MAAsC;AACpF,UAAM,EAAE,UAAU,aAAa,IAAI,IAAI,IAAI,EAAE,IAAI,KAAK,qBAAqB;AAE3E,UAAM,eAAe,aAAa,IAAI,uDAAqB;AAC3D,QAAI,gBAAgB,MAAM;AACxB,aAAO,UAAM,uDAAoB,EAAE,IAAI,KAAK;AAAA,QAC1C,oBAAoB,CAAC,+DAA6B;AAAA,MACpD,CAAC;AAAA,IACH;AAEA,UAAM,SAAS,IAAI,cAAAA,UAAgB,QAAQ,EAAE,QAAQ,CAAC;AAEtD,UAAM,cAAc,MAAM,qBAAqB,EAAE,cAAc,OAAO,CAAC;AACvE,QAAI,eAAe;AAAM,aAAO,KAAK;AAErC,UAAM,4BAAwB,wDAAqB,WAAW;AAC9D,UAAM,6BAAyB,qEAAkC,WAAW;AAE5E,iCAAU,GAAG,iEAA+B,uBAAuB;AAAA,MACjE,GAAG;AAAA,MACH,QAAQ;AAAA,IACV,CAAC;AAED,WAAO,EAAE,SAAS,QAAQ;AAAA,EAC5B;AACF;","names":["MakeswiftClient"]}
|
package/dist/esm/index.js
CHANGED
|
@@ -2,16 +2,16 @@ import {
|
|
|
2
2
|
MakeswiftComponent,
|
|
3
3
|
Page,
|
|
4
4
|
Slot,
|
|
5
|
-
RuntimeProvider
|
|
6
|
-
ReactRuntime
|
|
5
|
+
RuntimeProvider
|
|
7
6
|
} from "@makeswift/runtime/unstable-framework-support";
|
|
8
7
|
import { Makeswift } from "./client";
|
|
9
8
|
import { ReactRootStyleRegistry } from "./root-style-registry";
|
|
9
|
+
import { HonoReactRuntime } from "./runtime";
|
|
10
10
|
export {
|
|
11
11
|
Makeswift,
|
|
12
12
|
MakeswiftComponent,
|
|
13
13
|
Page,
|
|
14
|
-
ReactRuntime,
|
|
14
|
+
HonoReactRuntime as ReactRuntime,
|
|
15
15
|
RuntimeProvider as ReactRuntimeProvider,
|
|
16
16
|
ReactRootStyleRegistry as RootStyleRegistry,
|
|
17
17
|
Slot
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n type SiteVersion,\n MakeswiftComponent,\n Page,\n Slot,\n RuntimeProvider as ReactRuntimeProvider,\n
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n type SiteVersion,\n MakeswiftComponent,\n Page,\n Slot,\n RuntimeProvider as ReactRuntimeProvider,\n} from '@makeswift/runtime/unstable-framework-support'\n\nexport { Makeswift } from './client'\nexport { ReactRootStyleRegistry as RootStyleRegistry } from './root-style-registry'\nexport { HonoReactRuntime as ReactRuntime } from './runtime'\n"],"mappings":"AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACmB;AAAA,OACd;AAEP,SAAS,iBAAiB;AAC1B,SAAmC,8BAAyB;AAC5D,SAA6B,wBAAoB;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ReactRuntime } from "@makeswift/runtime/unstable-framework-support";
|
|
2
|
+
class HonoReactRuntime extends ReactRuntime {
|
|
3
|
+
constructor(args = {}) {
|
|
4
|
+
super({
|
|
5
|
+
...args,
|
|
6
|
+
fetch: (url, init) => fetch(url, init)
|
|
7
|
+
// TODO: revalidation support
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
HonoReactRuntime
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/runtime.ts"],"sourcesContent":["import { type Breakpoints, ReactRuntime } from '@makeswift/runtime/unstable-framework-support'\n\nexport class HonoReactRuntime extends ReactRuntime {\n constructor(args: { appOrigin?: string; apiOrigin?: string; breakpoints?: Breakpoints } = {}) {\n super({\n ...args,\n fetch: (url, init) => fetch(url, init), // TODO: revalidation support\n })\n }\n}\n"],"mappings":"AAAA,SAA2B,oBAAoB;AAExC,MAAM,yBAAyB,aAAa;AAAA,EACjD,YAAY,OAA8E,CAAC,GAAG;AAC5F,UAAM;AAAA,MACJ,GAAG;AAAA,MACH,OAAO,CAAC,KAAK,SAAS,MAAM,KAAK,IAAI;AAAA;AAAA,IACvC,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -7,7 +7,6 @@ const API_PATH_PREFIX = "/api/makeswift/";
|
|
|
7
7
|
function createApiHandler({
|
|
8
8
|
apiKey,
|
|
9
9
|
runtime,
|
|
10
|
-
apiOrigin,
|
|
11
10
|
revalidationHandler,
|
|
12
11
|
...userConfig
|
|
13
12
|
}) {
|
|
@@ -16,7 +15,7 @@ function createApiHandler({
|
|
|
16
15
|
return next();
|
|
17
16
|
}
|
|
18
17
|
const route = `/${c.req.path.replace(API_PATH_PREFIX, "")}`;
|
|
19
|
-
const client = new MakeswiftClient(apiKey, {
|
|
18
|
+
const client = new MakeswiftClient(apiKey, { runtime });
|
|
20
19
|
const apiHandler2 = createMakeswiftApiHandler(apiKey, {
|
|
21
20
|
...userConfig,
|
|
22
21
|
previewCookieNames: [MAKESWIFT_SITE_VERSION_COOKIE],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/api-handler.ts"],"sourcesContent":["import { type Context, type MiddlewareHandler, type Next } from 'hono'\n\nimport {\n type ApiHandlerUserConfig,\n MAKESWIFT_SITE_VERSION_COOKIE,\n createApiHandler as createMakeswiftApiHandler,\n} from '@makeswift/runtime/unstable-framework-support'\n\nimport { Makeswift as MakeswiftClient } from '../client'\n\nimport { type Env } from './env'\n\nconst API_PATH_PREFIX = '/api/makeswift/'\n\ntype UserConfig = ApiHandlerUserConfig & {\n apiKey: string\n revalidationHandler?: (path?: string) => Promise<void>\n}\n\nexport function createApiHandler<E extends Env>({\n apiKey,\n runtime,\n
|
|
1
|
+
{"version":3,"sources":["../../../src/server/api-handler.ts"],"sourcesContent":["import { type Context, type MiddlewareHandler, type Next } from 'hono'\n\nimport {\n type ApiHandlerUserConfig,\n MAKESWIFT_SITE_VERSION_COOKIE,\n createApiHandler as createMakeswiftApiHandler,\n} from '@makeswift/runtime/unstable-framework-support'\n\nimport { Makeswift as MakeswiftClient } from '../client'\n\nimport { type Env } from './env'\n\nconst API_PATH_PREFIX = '/api/makeswift/'\n\ntype UserConfig = ApiHandlerUserConfig & {\n apiKey: string\n revalidationHandler?: (path?: string) => Promise<void>\n}\n\nexport function createApiHandler<E extends Env>({\n apiKey,\n runtime,\n revalidationHandler,\n ...userConfig\n}: UserConfig): MiddlewareHandler {\n return async function apiHandler(c: Context<E>, next: Next): Promise<Response | void> {\n if (!c.req.path.startsWith(API_PATH_PREFIX)) {\n return next()\n }\n\n const route = `/${c.req.path.replace(API_PATH_PREFIX, '')}`\n const client = new MakeswiftClient(apiKey, { runtime })\n\n const apiHandler = createMakeswiftApiHandler(apiKey, {\n ...userConfig,\n previewCookieNames: [MAKESWIFT_SITE_VERSION_COOKIE],\n revalidationHandler: revalidationHandler ?? (() => Promise.resolve()),\n runtime,\n client,\n })\n\n return await apiHandler(c.req.raw, route)\n }\n}\n"],"mappings":"AAEA;AAAA,EAEE;AAAA,EACA,oBAAoB;AAAA,OACf;AAEP,SAAS,aAAa,uBAAuB;AAI7C,MAAM,kBAAkB;AAOjB,SAAS,iBAAgC;AAAA,EAC9C;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAkC;AAChC,SAAO,eAAe,WAAW,GAAe,MAAsC;AACpF,QAAI,CAAC,EAAE,IAAI,KAAK,WAAW,eAAe,GAAG;AAC3C,aAAO,KAAK;AAAA,IACd;AAEA,UAAM,QAAQ,IAAI,EAAE,IAAI,KAAK,QAAQ,iBAAiB,EAAE,CAAC;AACzD,UAAM,SAAS,IAAI,gBAAgB,QAAQ,EAAE,QAAQ,CAAC;AAEtD,UAAMA,cAAa,0BAA0B,QAAQ;AAAA,MACnD,GAAG;AAAA,MACH,oBAAoB,CAAC,6BAA6B;AAAA,MAClD,qBAAqB,wBAAwB,MAAM,QAAQ,QAAQ;AAAA,MACnE;AAAA,MACA;AAAA,IACF,CAAC;AAED,WAAO,MAAMA,YAAW,EAAE,IAAI,KAAK,KAAK;AAAA,EAC1C;AACF;","names":["apiHandler"]}
|
|
@@ -24,8 +24,7 @@ async function requestedSiteVersion({
|
|
|
24
24
|
}
|
|
25
25
|
function createPreviewMiddleware({
|
|
26
26
|
apiKey,
|
|
27
|
-
runtime
|
|
28
|
-
apiOrigin
|
|
27
|
+
runtime
|
|
29
28
|
}) {
|
|
30
29
|
return async function apiHandler(c, next) {
|
|
31
30
|
const { pathname, searchParams } = new URL(c.req.url, `https://example.com`);
|
|
@@ -35,7 +34,7 @@ function createPreviewMiddleware({
|
|
|
35
34
|
previewCookieNames: [MAKESWIFT_SITE_VERSION_COOKIE]
|
|
36
35
|
});
|
|
37
36
|
}
|
|
38
|
-
const client = new MakeswiftClient(apiKey, {
|
|
37
|
+
const client = new MakeswiftClient(apiKey, { runtime });
|
|
39
38
|
const siteVersion = await requestedSiteVersion({ searchParams, client });
|
|
40
39
|
if (siteVersion == null)
|
|
41
40
|
return next();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/preview.ts"],"sourcesContent":["import { type Context, type MiddlewareHandler, type Next } from 'hono'\nimport { setCookie } from 'hono/cookie'\n\nimport {\n type SiteVersion,\n MAKESWIFT_SITE_VERSION_COOKIE,\n REDIRECT_SEARCH_PARAM,\n cookieSettingOptions,\n redirectLiveHandler,\n SearchParams,\n secondsUntilSiteVersionExpiration,\n serializeSiteVersion,\n} from '@makeswift/runtime/unstable-framework-support'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/server/preview.ts"],"sourcesContent":["import { type Context, type MiddlewareHandler, type Next } from 'hono'\nimport { setCookie } from 'hono/cookie'\n\nimport {\n type SiteVersion,\n MAKESWIFT_SITE_VERSION_COOKIE,\n REDIRECT_SEARCH_PARAM,\n cookieSettingOptions,\n redirectLiveHandler,\n SearchParams,\n secondsUntilSiteVersionExpiration,\n serializeSiteVersion,\n ReactRuntime,\n} from '@makeswift/runtime/unstable-framework-support'\n\nimport { Makeswift as MakeswiftClient } from '../client'\n\nimport { type Env } from './env'\n\nasync function requestedSiteVersion({\n searchParams,\n client,\n}: {\n searchParams: URLSearchParams\n client: MakeswiftClient\n}): Promise<SiteVersion | null> {\n const previewToken = searchParams.get(SearchParams.PreviewToken)\n if (previewToken == null) return null\n\n const verifiedToken = await client.readPreviewToken(previewToken)\n if (verifiedToken == null) return null\n\n const { payload } = verifiedToken\n\n return { version: payload.version, token: previewToken }\n}\n\nexport function createPreviewMiddleware<E extends Env>({\n apiKey,\n runtime,\n}: {\n apiKey: string\n runtime: ReactRuntime\n}): MiddlewareHandler {\n return async function apiHandler(c: Context<E>, next: Next): Promise<Response | void> {\n const { pathname, searchParams } = new URL(c.req.url, `https://example.com`)\n\n const redirectLive = searchParams.get(REDIRECT_SEARCH_PARAM)\n if (redirectLive != null) {\n return await redirectLiveHandler(c.req.raw, {\n previewCookieNames: [MAKESWIFT_SITE_VERSION_COOKIE],\n })\n }\n\n const client = new MakeswiftClient(apiKey, { runtime })\n\n const siteVersion = await requestedSiteVersion({ searchParams, client })\n if (siteVersion == null) return next()\n\n const serializedSiteVersion = serializeSiteVersion(siteVersion)\n const secondsUntilExpiration = secondsUntilSiteVersionExpiration(siteVersion)\n\n setCookie(c, MAKESWIFT_SITE_VERSION_COOKIE, serializedSiteVersion, {\n ...cookieSettingOptions,\n maxAge: secondsUntilExpiration,\n })\n\n return c.redirect(pathname)\n }\n}\n"],"mappings":"AACA,SAAS,iBAAiB;AAE1B;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,aAAa,uBAAuB;AAI7C,eAAe,qBAAqB;AAAA,EAClC;AAAA,EACA;AACF,GAGgC;AAC9B,QAAM,eAAe,aAAa,IAAI,aAAa,YAAY;AAC/D,MAAI,gBAAgB;AAAM,WAAO;AAEjC,QAAM,gBAAgB,MAAM,OAAO,iBAAiB,YAAY;AAChE,MAAI,iBAAiB;AAAM,WAAO;AAElC,QAAM,EAAE,QAAQ,IAAI;AAEpB,SAAO,EAAE,SAAS,QAAQ,SAAS,OAAO,aAAa;AACzD;AAEO,SAAS,wBAAuC;AAAA,EACrD;AAAA,EACA;AACF,GAGsB;AACpB,SAAO,eAAe,WAAW,GAAe,MAAsC;AACpF,UAAM,EAAE,UAAU,aAAa,IAAI,IAAI,IAAI,EAAE,IAAI,KAAK,qBAAqB;AAE3E,UAAM,eAAe,aAAa,IAAI,qBAAqB;AAC3D,QAAI,gBAAgB,MAAM;AACxB,aAAO,MAAM,oBAAoB,EAAE,IAAI,KAAK;AAAA,QAC1C,oBAAoB,CAAC,6BAA6B;AAAA,MACpD,CAAC;AAAA,IACH;AAEA,UAAM,SAAS,IAAI,gBAAgB,QAAQ,EAAE,QAAQ,CAAC;AAEtD,UAAM,cAAc,MAAM,qBAAqB,EAAE,cAAc,OAAO,CAAC;AACvE,QAAI,eAAe;AAAM,aAAO,KAAK;AAErC,UAAM,wBAAwB,qBAAqB,WAAW;AAC9D,UAAM,yBAAyB,kCAAkC,WAAW;AAE5E,cAAU,GAAG,+BAA+B,uBAAuB;AAAA,MACjE,GAAG;AAAA,MACH,QAAQ;AAAA,IACV,CAAC;AAED,WAAO,EAAE,SAAS,QAAQ;AAAA,EAC5B;AACF;","names":[]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { type SiteVersion, MakeswiftComponent, Page, Slot, RuntimeProvider as ReactRuntimeProvider,
|
|
1
|
+
export { type SiteVersion, MakeswiftComponent, Page, Slot, RuntimeProvider as ReactRuntimeProvider, } from '@makeswift/runtime/unstable-framework-support';
|
|
2
2
|
export { Makeswift } from './client';
|
|
3
3
|
export { ReactRootStyleRegistry as RootStyleRegistry } from './root-style-registry';
|
|
4
|
+
export { HonoReactRuntime as ReactRuntime } from './runtime';
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAChB,kBAAkB,EAClB,IAAI,EACJ,IAAI,EACJ,eAAe,IAAI,oBAAoB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAChB,kBAAkB,EAClB,IAAI,EACJ,IAAI,EACJ,eAAe,IAAI,oBAAoB,GACxC,MAAM,+CAA+C,CAAA;AAEtD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,sBAAsB,IAAI,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACnF,OAAO,EAAE,gBAAgB,IAAI,YAAY,EAAE,MAAM,WAAW,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Breakpoints, ReactRuntime } from '@makeswift/runtime/unstable-framework-support';
|
|
2
|
+
export declare class HonoReactRuntime extends ReactRuntime {
|
|
3
|
+
constructor(args?: {
|
|
4
|
+
appOrigin?: string;
|
|
5
|
+
apiOrigin?: string;
|
|
6
|
+
breakpoints?: Breakpoints;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAA;AAE9F,qBAAa,gBAAiB,SAAQ,YAAY;gBACpC,IAAI,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,WAAW,CAAA;KAAO;CAM7F"}
|
|
@@ -5,6 +5,6 @@ type UserConfig = ApiHandlerUserConfig & {
|
|
|
5
5
|
apiKey: string;
|
|
6
6
|
revalidationHandler?: (path?: string) => Promise<void>;
|
|
7
7
|
};
|
|
8
|
-
export declare function createApiHandler<E extends Env>({ apiKey, runtime,
|
|
8
|
+
export declare function createApiHandler<E extends Env>({ apiKey, runtime, revalidationHandler, ...userConfig }: UserConfig): MiddlewareHandler;
|
|
9
9
|
export {};
|
|
10
10
|
//# sourceMappingURL=api-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-handler.d.ts","sourceRoot":"","sources":["../../../src/server/api-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,iBAAiB,EAAa,MAAM,MAAM,CAAA;AAEtE,OAAO,EACL,KAAK,oBAAoB,EAG1B,MAAM,+CAA+C,CAAA;AAItD,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,OAAO,CAAA;AAIhC,KAAK,UAAU,GAAG,oBAAoB,GAAG;IACvC,MAAM,EAAE,MAAM,CAAA;IACd,mBAAmB,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CACvD,CAAA;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,GAAG,EAAE,EAC9C,MAAM,EACN,OAAO,EACP,
|
|
1
|
+
{"version":3,"file":"api-handler.d.ts","sourceRoot":"","sources":["../../../src/server/api-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,iBAAiB,EAAa,MAAM,MAAM,CAAA;AAEtE,OAAO,EACL,KAAK,oBAAoB,EAG1B,MAAM,+CAA+C,CAAA;AAItD,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,OAAO,CAAA;AAIhC,KAAK,UAAU,GAAG,oBAAoB,GAAG;IACvC,MAAM,EAAE,MAAM,CAAA;IACd,mBAAmB,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CACvD,CAAA;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,GAAG,EAAE,EAC9C,MAAM,EACN,OAAO,EACP,mBAAmB,EACnB,GAAG,UAAU,EACd,EAAE,UAAU,GAAG,iBAAiB,CAmBhC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { type MiddlewareHandler } from 'hono';
|
|
2
|
-
import { ReactRuntime } from '@makeswift/runtime/
|
|
2
|
+
import { ReactRuntime } from '@makeswift/runtime/unstable-framework-support';
|
|
3
3
|
import { type Env } from './env';
|
|
4
|
-
export declare function createPreviewMiddleware<E extends Env>({ apiKey, runtime,
|
|
4
|
+
export declare function createPreviewMiddleware<E extends Env>({ apiKey, runtime, }: {
|
|
5
5
|
apiKey: string;
|
|
6
6
|
runtime: ReactRuntime;
|
|
7
|
-
apiOrigin?: string;
|
|
8
7
|
}): MiddlewareHandler;
|
|
9
8
|
//# sourceMappingURL=preview.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../../src/server/preview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,iBAAiB,EAAa,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../../src/server/preview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,iBAAiB,EAAa,MAAM,MAAM,CAAA;AAGtE,OAAO,EASL,YAAY,EACb,MAAM,+CAA+C,CAAA;AAItD,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,OAAO,CAAA;AAoBhC,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,GAAG,EAAE,EACrD,MAAM,EACN,OAAO,GACR,EAAE;IACD,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,YAAY,CAAA;CACtB,GAAG,iBAAiB,CA0BpB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@makeswift/hono-react",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0-canary.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "makeswift/makeswift",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"cookie": "^1.0.2",
|
|
31
|
-
"@makeswift/runtime": "0.
|
|
31
|
+
"@makeswift/runtime": "0.27.0-canary.2"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@types/react": "^19.0.0",
|