@friendsofshopware/app-server-sdk-hono
Advanced tools
Comparing version 0.0.35 to 0.0.36
@@ -11,4 +11,3 @@ import { HTTPException } from "hono/http-exception"; | ||
if (app === null) { | ||
const appUrl = cfg.appUrl || | ||
ctx.req.url.substring(0, ctx.req.url.length - (new URL(ctx.req.url).pathname.length)); | ||
const appUrl = cfg.appUrl || buildBaseUrl(ctx.req.url); | ||
if (typeof cfg.shopRepository === "function") { | ||
@@ -24,3 +23,2 @@ // @ts-ignore | ||
} | ||
// @ts-ignore | ||
ctx.set("app", app); | ||
@@ -30,3 +28,2 @@ await next(); | ||
hono.use(cfg.appPath, async (ctx, next) => { | ||
// @ts-ignore | ||
const app = ctx.get("app"); | ||
@@ -49,13 +46,10 @@ // Don't validate signature for registration | ||
} | ||
// @ts-ignore | ||
ctx.set("shop", context.shop); | ||
// @ts-ignore | ||
ctx.set("context", context); | ||
await next(); | ||
const cloned = ctx.res.clone(); | ||
await app.signer.signResponse(cloned, context.shop.getShopSecret()); | ||
await ctx.get("app").signer.signResponse(cloned, ctx.get("shop").getShopSecret()); | ||
ctx.header("shopware-app-signature", cloned.headers.get("shopware-app-signature")); | ||
}); | ||
hono.get(cfg.registrationUrl, async (ctx) => { | ||
// @ts-ignore | ||
const app = ctx.get("app"); | ||
@@ -72,3 +66,2 @@ try { | ||
hono.post(cfg.registerConfirmationUrl, async (ctx) => { | ||
// @ts-ignore | ||
const app = ctx.get("app"); | ||
@@ -85,1 +78,5 @@ try { | ||
} | ||
function buildBaseUrl(url) { | ||
const u = new URL(url); | ||
return `${u.protocol}//${u.host}`; | ||
} |
@@ -5,3 +5,3 @@ { | ||
"name": "@friendsofshopware/app-server-sdk-hono", | ||
"version": "0.0.35", | ||
"version": "0.0.36", | ||
"description": "Hono Integration for Shopware App Server SDK", | ||
@@ -8,0 +8,0 @@ "license": "MIT", |
import type { Context as HonoContext, Hono } from "hono"; | ||
import { ShopRepositoryInterface } from "@friendsofshopware/app-server-sdk"; | ||
import { AppServer, Context, ShopInterface, ShopRepositoryInterface } from "@friendsofshopware/app-server-sdk"; | ||
interface MiddlewareConfig { | ||
@@ -12,3 +12,10 @@ appName: string; | ||
} | ||
export declare function configureAppServer(hono: Hono, cfg: MiddlewareConfig): void; | ||
type Variables = { | ||
app: AppServer; | ||
shop: ShopInterface; | ||
context: Context; | ||
}; | ||
export declare function configureAppServer(hono: Hono<{ | ||
Variables: Variables; | ||
}>, cfg: MiddlewareConfig): void; | ||
export {}; |
4098
96