@shopware-ag/app-server-sdk 1.0.0 → 1.0.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 +38 -30
- package/dist/commonjs/registration.d.ts +24 -0
- package/dist/commonjs/registration.d.ts.map +1 -1
- package/dist/commonjs/registration.js +42 -3
- package/dist/commonjs/registration.js.map +1 -1
- package/dist/commonjs/repository.d.ts +5 -1
- package/dist/commonjs/repository.d.ts.map +1 -1
- package/dist/commonjs/repository.js +7 -1
- package/dist/commonjs/repository.js.map +1 -1
- package/dist/esm/registration.d.ts +24 -0
- package/dist/esm/registration.d.ts.map +1 -1
- package/dist/esm/registration.js +42 -3
- package/dist/esm/registration.js.map +1 -1
- package/dist/esm/repository.d.ts +5 -1
- package/dist/esm/repository.d.ts.map +1 -1
- package/dist/esm/repository.js +7 -1
- package/dist/esm/repository.js.map +1 -1
- package/package.json +63 -71
- package/dist/commonjs/framework/hono.d.ts +0 -36
- package/dist/commonjs/framework/hono.d.ts.map +0 -1
- package/dist/commonjs/framework/hono.js +0 -84
- package/dist/commonjs/framework/hono.js.map +0 -1
- package/dist/commonjs/service/cloudflare.d.ts +0 -43
- package/dist/commonjs/service/cloudflare.d.ts.map +0 -1
- package/dist/commonjs/service/cloudflare.js +0 -45
- package/dist/commonjs/service/cloudflare.js.map +0 -1
- package/dist/commonjs/service/deno.d.ts +0 -18
- package/dist/commonjs/service/deno.d.ts.map +0 -1
- package/dist/commonjs/service/deno.js +0 -48
- package/dist/commonjs/service/deno.js.map +0 -1
- package/dist/deno/app.d.ts +0 -31
- package/dist/deno/app.d.ts.map +0 -1
- package/dist/deno/app.js +0 -21
- package/dist/deno/app.js.map +0 -1
- package/dist/deno/context-resolver.d.ts +0 -30
- package/dist/deno/context-resolver.d.ts.map +0 -1
- package/dist/deno/context-resolver.js +0 -65
- package/dist/deno/context-resolver.js.map +0 -1
- package/dist/deno/framework/hono.d.ts +0 -36
- package/dist/deno/framework/hono.d.ts.map +0 -1
- package/dist/deno/framework/hono.js +0 -81
- package/dist/deno/framework/hono.js.map +0 -1
- package/dist/deno/helper/app-actions.d.ts +0 -13
- package/dist/deno/helper/app-actions.d.ts.map +0 -1
- package/dist/deno/helper/app-actions.js +0 -49
- package/dist/deno/helper/app-actions.js.map +0 -1
- package/dist/deno/http-client.d.ts +0 -67
- package/dist/deno/http-client.d.ts.map +0 -1
- package/dist/deno/http-client.js +0 -148
- package/dist/deno/http-client.js.map +0 -1
- package/dist/deno/mod.d.ts +0 -6
- package/dist/deno/mod.d.ts.map +0 -1
- package/dist/deno/mod.js +0 -5
- package/dist/deno/mod.js.map +0 -1
- package/dist/deno/package.json +0 -3
- package/dist/deno/registration.d.ts +0 -18
- package/dist/deno/registration.d.ts.map +0 -1
- package/dist/deno/registration.js +0 -84
- package/dist/deno/registration.js.map +0 -1
- package/dist/deno/repository.d.ts +0 -51
- package/dist/deno/repository.d.ts.map +0 -1
- package/dist/deno/repository.js +0 -63
- package/dist/deno/repository.js.map +0 -1
- package/dist/deno/service/cloudflare.d.ts +0 -43
- package/dist/deno/service/cloudflare.d.ts.map +0 -1
- package/dist/deno/service/cloudflare.js +0 -41
- package/dist/deno/service/cloudflare.js.map +0 -1
- package/dist/deno/service/deno.d.ts +0 -18
- package/dist/deno/service/deno.d.ts.map +0 -1
- package/dist/deno/service/deno.js +0 -44
- package/dist/deno/service/deno.js.map +0 -1
- package/dist/deno/signer.d.ts +0 -12
- package/dist/deno/signer.d.ts.map +0 -1
- package/dist/deno/signer.js +0 -54
- package/dist/deno/signer.js.map +0 -1
- package/dist/deno/types.d.ts +0 -28
- package/dist/deno/types.d.ts.map +0 -1
- package/dist/deno/types.js +0 -2
- package/dist/deno/types.js.map +0 -1
- package/dist/esm/framework/hono.d.ts +0 -36
- package/dist/esm/framework/hono.d.ts.map +0 -1
- package/dist/esm/framework/hono.js +0 -81
- package/dist/esm/framework/hono.js.map +0 -1
- package/dist/esm/service/cloudflare.d.ts +0 -43
- package/dist/esm/service/cloudflare.d.ts.map +0 -1
- package/dist/esm/service/cloudflare.js +0 -41
- package/dist/esm/service/cloudflare.js.map +0 -1
- package/dist/esm/service/deno.d.ts +0 -18
- package/dist/esm/service/deno.d.ts.map +0 -1
- package/dist/esm/service/deno.js +0 -44
- package/dist/esm/service/deno.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,72 +1,64 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
"exports": {
|
|
66
|
-
"./package.json": "./package.json",
|
|
67
|
-
".": "./src/mod.ts",
|
|
68
|
-
"./helper/app-actions": "./src/helper/app-actions.ts",
|
|
69
|
-
"./types": "./src/types.ts"
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
2
|
+
"name": "@shopware-ag/app-server-sdk",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "App Server SDK for JavaScript",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"shopware",
|
|
9
|
+
"app-server"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
"./package.json": "./package.json",
|
|
13
|
+
".": {
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/esm/mod.d.ts",
|
|
16
|
+
"default": "./dist/esm/mod.js"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/commonjs/mod.d.ts",
|
|
20
|
+
"default": "./dist/commonjs/mod.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"./helper/app-actions": {
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./dist/esm/helper/app-actions.d.ts",
|
|
26
|
+
"default": "./dist/esm/helper/app-actions.js"
|
|
27
|
+
},
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./dist/commonjs/helper/app-actions.d.ts",
|
|
30
|
+
"default": "./dist/commonjs/helper/app-actions.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"./types": {
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/esm/types.d.ts",
|
|
36
|
+
"default": "./dist/esm/types.js"
|
|
37
|
+
},
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./dist/commonjs/types.d.ts",
|
|
40
|
+
"default": "./dist/commonjs/types.js"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"main": "./dist/commonjs/mod.js",
|
|
45
|
+
"module": "./dist/esm/mod.js",
|
|
46
|
+
"types": "./dist/commonjs/mod.d.ts",
|
|
47
|
+
"files": [
|
|
48
|
+
"dist"
|
|
49
|
+
],
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@biomejs/biome": "1.8.3",
|
|
52
|
+
"@types/bun": "^1.1.6",
|
|
53
|
+
"tshy": "^3.0.2",
|
|
54
|
+
"hono": "^4.5.6"
|
|
55
|
+
},
|
|
56
|
+
"tshy": {
|
|
57
|
+
"exports": {
|
|
58
|
+
"./package.json": "./package.json",
|
|
59
|
+
".": "./src/mod.ts",
|
|
60
|
+
"./helper/app-actions": "./src/helper/app-actions.ts",
|
|
61
|
+
"./types": "./src/types.ts"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { AppServer } from "../app.js";
|
|
2
|
-
import type { Context } from "../context-resolver.js";
|
|
3
|
-
import type { ShopInterface, ShopRepositoryInterface } from "../repository.js";
|
|
4
|
-
interface MiddlewareConfig {
|
|
5
|
-
appName: string | ((c: HonoContext<DataTypes>) => string);
|
|
6
|
-
appSecret: string | ((c: HonoContext<DataTypes>) => string);
|
|
7
|
-
appUrl?: string | null;
|
|
8
|
-
registrationUrl?: string | null;
|
|
9
|
-
registerConfirmationUrl?: string | null;
|
|
10
|
-
appPath?: string | null;
|
|
11
|
-
shopRepository: ShopRepositoryInterface | ((c: HonoContext<DataTypes>) => ShopRepositoryInterface);
|
|
12
|
-
}
|
|
13
|
-
interface DataTypes {
|
|
14
|
-
app: AppServer;
|
|
15
|
-
context: Context<ShopInterface, unknown>;
|
|
16
|
-
shop: ShopInterface;
|
|
17
|
-
}
|
|
18
|
-
interface HonoContext<DataTypes> {
|
|
19
|
-
env: any;
|
|
20
|
-
req: {
|
|
21
|
-
path: string;
|
|
22
|
-
method: string;
|
|
23
|
-
url: string;
|
|
24
|
-
raw: Request;
|
|
25
|
-
};
|
|
26
|
-
header: (key: string, value: string) => void;
|
|
27
|
-
res: Response;
|
|
28
|
-
get<K extends keyof DataTypes>(key: K): DataTypes[K];
|
|
29
|
-
set<K extends keyof DataTypes>(key: K, value: DataTypes[K]): void;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Configure the Hono server to handle the app registration and context resolution
|
|
33
|
-
*/
|
|
34
|
-
export declare function configureAppServer(honoExternal: unknown, cfg: MiddlewareConfig): void;
|
|
35
|
-
export {};
|
|
36
|
-
//# sourceMappingURL=hono.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hono.d.ts","sourceRoot":"","sources":["../../../src/framework/hono.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE/E,UAAU,gBAAgB;IACzB,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,KAAK,MAAM,CAAC,CAAC;IAC1D,SAAS,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,KAAK,MAAM,CAAC,CAAC;IAC5D,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,cAAc,EACX,uBAAuB,GACvB,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,KAAK,uBAAuB,CAAC,CAAC;CAC5D;AAED,UAAU,SAAS;IAClB,GAAG,EAAE,SAAS,CAAC;IACf,OAAO,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACzC,IAAI,EAAE,aAAa,CAAC;CACpB;AAED,UAAU,WAAW,CAAC,SAAS;IAC9B,GAAG,EAAE,GAAG,CAAC;IACT,GAAG,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,OAAO,CAAC;KACb,CAAC;IACF,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,GAAG,EAAE,QAAQ,CAAC;IACd,GAAG,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;IACrD,GAAG,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CAClE;AAmBD;;GAEG;AACH,wBAAgB,kBAAkB,CACjC,YAAY,EAAE,OAAO,EACrB,GAAG,EAAE,gBAAgB,QA0FrB"}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.configureAppServer = configureAppServer;
|
|
4
|
-
const app_js_1 = require("../app.js");
|
|
5
|
-
let app = null;
|
|
6
|
-
/**
|
|
7
|
-
* Configure the Hono server to handle the app registration and context resolution
|
|
8
|
-
*/
|
|
9
|
-
function configureAppServer(honoExternal, cfg) {
|
|
10
|
-
const hono = honoExternal;
|
|
11
|
-
cfg.registrationUrl = cfg.registrationUrl || "/app/register";
|
|
12
|
-
cfg.registerConfirmationUrl =
|
|
13
|
-
cfg.registerConfirmationUrl || "/app/register/confirm";
|
|
14
|
-
cfg.appPath = cfg.appPath || "/app/*";
|
|
15
|
-
hono.use("*", async (ctx, next) => {
|
|
16
|
-
if (app === null) {
|
|
17
|
-
const appUrl = cfg.appUrl || buildBaseUrl(ctx.req.url);
|
|
18
|
-
if (typeof cfg.shopRepository === "function") {
|
|
19
|
-
cfg.shopRepository = cfg.shopRepository(ctx);
|
|
20
|
-
}
|
|
21
|
-
if (typeof cfg.appName === "function") {
|
|
22
|
-
cfg.appName = cfg.appName(ctx);
|
|
23
|
-
}
|
|
24
|
-
if (typeof cfg.appSecret === "function") {
|
|
25
|
-
cfg.appSecret = cfg.appSecret(ctx);
|
|
26
|
-
}
|
|
27
|
-
app = new app_js_1.AppServer({
|
|
28
|
-
appName: cfg.appName,
|
|
29
|
-
appSecret: cfg.appSecret,
|
|
30
|
-
authorizeCallbackUrl: appUrl + cfg.registerConfirmationUrl,
|
|
31
|
-
}, cfg.shopRepository);
|
|
32
|
-
}
|
|
33
|
-
ctx.set("app", app);
|
|
34
|
-
await next();
|
|
35
|
-
});
|
|
36
|
-
hono.use(cfg.appPath, async (ctx, next) => {
|
|
37
|
-
const app = ctx.get("app");
|
|
38
|
-
// Don't validate signature for registration
|
|
39
|
-
if (ctx.req.path === cfg.registrationUrl ||
|
|
40
|
-
ctx.req.path === cfg.registerConfirmationUrl) {
|
|
41
|
-
await next();
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
let context;
|
|
45
|
-
try {
|
|
46
|
-
context =
|
|
47
|
-
ctx.req.method === "GET"
|
|
48
|
-
? await app.contextResolver.fromBrowser(ctx.req.raw)
|
|
49
|
-
: await app.contextResolver.fromAPI(ctx.req.raw);
|
|
50
|
-
}
|
|
51
|
-
catch (_e) {
|
|
52
|
-
return jsonResponse({ message: "Invalid request" }, 400);
|
|
53
|
-
}
|
|
54
|
-
ctx.set("shop", context.shop);
|
|
55
|
-
ctx.set("context", context);
|
|
56
|
-
await next();
|
|
57
|
-
const cloned = ctx.res.clone();
|
|
58
|
-
await ctx
|
|
59
|
-
.get("app")
|
|
60
|
-
.signer.signResponse(cloned, ctx.get("shop").getShopSecret());
|
|
61
|
-
ctx.header("shopware-app-signature", cloned.headers.get("shopware-app-signature"));
|
|
62
|
-
});
|
|
63
|
-
hono.get(cfg.registrationUrl, async (ctx) => {
|
|
64
|
-
const app = ctx.get("app");
|
|
65
|
-
return await app.registration.authorize(ctx.req.raw);
|
|
66
|
-
});
|
|
67
|
-
hono.post(cfg.registerConfirmationUrl, async (ctx) => {
|
|
68
|
-
const app = ctx.get("app");
|
|
69
|
-
return await app.registration.authorizeCallback(ctx.req.raw);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
function jsonResponse(body, status = 200) {
|
|
73
|
-
return new Response(JSON.stringify(body), {
|
|
74
|
-
status,
|
|
75
|
-
headers: {
|
|
76
|
-
"Content-Type": "application/json",
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
function buildBaseUrl(url) {
|
|
81
|
-
const u = new URL(url);
|
|
82
|
-
return `${u.protocol}//${u.host}`;
|
|
83
|
-
}
|
|
84
|
-
//# sourceMappingURL=hono.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hono.js","sourceRoot":"","sources":["../../../src/framework/hono.ts"],"names":[],"mappings":";;AAwDA,gDA4FC;AApJD,sCAAsC;AAmDtC,IAAI,GAAG,GAAqB,IAAI,CAAC;AAEjC;;GAEG;AACH,SAAgB,kBAAkB,CACjC,YAAqB,EACrB,GAAqB;IAErB,MAAM,IAAI,GAAG,YAAoB,CAAC;IAElC,GAAG,CAAC,eAAe,GAAG,GAAG,CAAC,eAAe,IAAI,eAAe,CAAC;IAC7D,GAAG,CAAC,uBAAuB;QAC1B,GAAG,CAAC,uBAAuB,IAAI,uBAAuB,CAAC;IACxD,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,QAAQ,CAAC;IAEtC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACjC,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;YAClB,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAEvD,IAAI,OAAO,GAAG,CAAC,cAAc,KAAK,UAAU,EAAE,CAAC;gBAC9C,GAAG,CAAC,cAAc,GAA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AAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,IAAY,EAAE,MAAM,GAAG,GAAG;IAC/C,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;QACzC,MAAM;QACN,OAAO,EAAE;YACR,cAAc,EAAE,kBAAkB;SAClC;KACD,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,GAAW;IAChC,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAEvB,OAAO,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { AppServer } from \"../app.js\";\nimport type { Context } from \"../context-resolver.js\";\nimport type { ShopInterface, ShopRepositoryInterface } from \"../repository.js\";\n\ninterface MiddlewareConfig {\n\tappName: string | ((c: HonoContext<DataTypes>) => string);\n\tappSecret: string | ((c: HonoContext<DataTypes>) => string);\n\tappUrl?: string | null;\n\tregistrationUrl?: string | null;\n\tregisterConfirmationUrl?: string | null;\n\tappPath?: string | null;\n\tshopRepository:\n\t\t| ShopRepositoryInterface\n\t\t| ((c: HonoContext<DataTypes>) => ShopRepositoryInterface);\n}\n\ninterface DataTypes {\n\tapp: AppServer;\n\tcontext: Context<ShopInterface, unknown>;\n\tshop: ShopInterface;\n}\n\ninterface HonoContext<DataTypes> {\n\tenv: any;\n\treq: {\n\t\tpath: string;\n\t\tmethod: string;\n\t\turl: string;\n\t\traw: Request;\n\t};\n\theader: (key: string, value: string) => void;\n\tres: Response;\n\tget<K extends keyof DataTypes>(key: K): DataTypes[K];\n\tset<K extends keyof DataTypes>(key: K, value: DataTypes[K]): void;\n}\n\ninterface Hono {\n\tuse: (\n\t\tpath: string,\n\t\thandler: (ctx: HonoContext<DataTypes>, next: () => Promise<void>) => void,\n\t) => void;\n\tget: (\n\t\tpath: string,\n\t\thandler: (ctx: HonoContext<DataTypes>, next: () => void) => void,\n\t) => void;\n\tpost: (\n\t\tpath: string,\n\t\thandler: (ctx: HonoContext<DataTypes>, next: () => void) => void,\n\t) => void;\n}\n\nlet app: AppServer | null = null;\n\n/**\n * Configure the Hono server to handle the app registration and context resolution\n */\nexport function configureAppServer(\n\thonoExternal: unknown,\n\tcfg: MiddlewareConfig,\n) {\n\tconst hono = honoExternal as Hono;\n\n\tcfg.registrationUrl = cfg.registrationUrl || \"/app/register\";\n\tcfg.registerConfirmationUrl =\n\t\tcfg.registerConfirmationUrl || \"/app/register/confirm\";\n\tcfg.appPath = cfg.appPath || \"/app/*\";\n\n\thono.use(\"*\", async (ctx, next) => {\n\t\tif (app === null) {\n\t\t\tconst appUrl = cfg.appUrl || buildBaseUrl(ctx.req.url);\n\n\t\t\tif (typeof cfg.shopRepository === \"function\") {\n\t\t\t\tcfg.shopRepository = cfg.shopRepository(ctx);\n\t\t\t}\n\n\t\t\tif (typeof cfg.appName === \"function\") {\n\t\t\t\tcfg.appName = cfg.appName(ctx);\n\t\t\t}\n\n\t\t\tif (typeof cfg.appSecret === \"function\") {\n\t\t\t\tcfg.appSecret = cfg.appSecret(ctx);\n\t\t\t}\n\n\t\t\tapp = new AppServer(\n\t\t\t\t{\n\t\t\t\t\tappName: cfg.appName,\n\t\t\t\t\tappSecret: cfg.appSecret,\n\t\t\t\t\tauthorizeCallbackUrl: appUrl + cfg.registerConfirmationUrl,\n\t\t\t\t},\n\t\t\t\tcfg.shopRepository,\n\t\t\t);\n\t\t}\n\n\t\tctx.set(\"app\", app);\n\n\t\tawait next();\n\t});\n\n\thono.use(cfg.appPath, async (ctx, next) => {\n\t\tconst app = ctx.get(\"app\") as AppServer;\n\n\t\t// Don't validate signature for registration\n\t\tif (\n\t\t\tctx.req.path === cfg.registrationUrl ||\n\t\t\tctx.req.path === cfg.registerConfirmationUrl\n\t\t) {\n\t\t\tawait next();\n\t\t\treturn;\n\t\t}\n\n\t\tlet context: Context<ShopInterface, unknown>;\n\t\ttry {\n\t\t\tcontext =\n\t\t\t\tctx.req.method === \"GET\"\n\t\t\t\t\t? await app.contextResolver.fromBrowser(ctx.req.raw)\n\t\t\t\t\t: await app.contextResolver.fromAPI(ctx.req.raw);\n\t\t} catch (_e) {\n\t\t\treturn jsonResponse({ message: \"Invalid request\" }, 400);\n\t\t}\n\n\t\tctx.set(\"shop\", context.shop);\n\t\tctx.set(\"context\", context);\n\n\t\tawait next();\n\n\t\tconst cloned = ctx.res.clone();\n\n\t\tawait ctx\n\t\t\t.get(\"app\")\n\t\t\t.signer.signResponse(cloned, ctx.get(\"shop\").getShopSecret());\n\n\t\tctx.header(\n\t\t\t\"shopware-app-signature\",\n\t\t\tcloned.headers.get(\"shopware-app-signature\") as string,\n\t\t);\n\t});\n\n\thono.get(cfg.registrationUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.authorize(ctx.req.raw);\n\t});\n\n\thono.post(cfg.registerConfirmationUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.authorizeCallback(ctx.req.raw);\n\t});\n}\n\nfunction jsonResponse(body: object, status = 200): Response {\n\treturn new Response(JSON.stringify(body), {\n\t\tstatus,\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t},\n\t});\n}\n\nfunction buildBaseUrl(url: string): string {\n\tconst u = new URL(url);\n\n\treturn `${u.protocol}//${u.host}`;\n}\n"]}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { SimpleShop } from "../repository.js";
|
|
2
|
-
import type { ShopRepositoryInterface } from "../repository.js";
|
|
3
|
-
/**
|
|
4
|
-
* Cloudflare KV integration
|
|
5
|
-
* @module
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Cloudflare KV implementation of the ShopRepositoryInterface
|
|
9
|
-
*/
|
|
10
|
-
export declare class CloudflareShopRepository implements ShopRepositoryInterface<SimpleShop> {
|
|
11
|
-
private storage;
|
|
12
|
-
constructor(storage: KVNamespace);
|
|
13
|
-
createShop(id: string, url: string, secret: string): Promise<void>;
|
|
14
|
-
deleteShop(id: string): Promise<void>;
|
|
15
|
-
getShopById(id: string): Promise<SimpleShop | null>;
|
|
16
|
-
updateShop(shop: SimpleShop): Promise<void>;
|
|
17
|
-
protected serializeShop(shop: SimpleShop): string;
|
|
18
|
-
protected deserializeShop(data: string): SimpleShop;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Cloudflare KV
|
|
22
|
-
*/
|
|
23
|
-
export declare interface KVNamespace<Key extends string = string> {
|
|
24
|
-
get(key: Key, options?: Partial<KVNamespaceGetOptions<undefined>>): Promise<string | null>;
|
|
25
|
-
put(key: Key, value: string | ArrayBuffer | ArrayBufferView | ReadableStream, options?: KVNamespacePutOptions): Promise<void>;
|
|
26
|
-
delete(key: Key): Promise<void>;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Cloudflare KV get options
|
|
30
|
-
*/
|
|
31
|
-
export declare interface KVNamespaceGetOptions<Type> {
|
|
32
|
-
type: Type;
|
|
33
|
-
cacheTtl?: number;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Cloudflare KV put options
|
|
37
|
-
*/
|
|
38
|
-
export declare interface KVNamespacePutOptions {
|
|
39
|
-
expiration?: number;
|
|
40
|
-
expirationTtl?: number;
|
|
41
|
-
metadata?: any | null;
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=cloudflare.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../../src/service/cloudflare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAiB,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE/E;;;GAGG;AAEH;;GAEG;AACH,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AAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;CACtB"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CloudflareShopRepository = void 0;
|
|
4
|
-
const repository_js_1 = require("../repository.js");
|
|
5
|
-
/**
|
|
6
|
-
* Cloudflare KV integration
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Cloudflare KV implementation of the ShopRepositoryInterface
|
|
11
|
-
*/
|
|
12
|
-
class CloudflareShopRepository {
|
|
13
|
-
storage;
|
|
14
|
-
constructor(storage) {
|
|
15
|
-
this.storage = storage;
|
|
16
|
-
this.storage = storage;
|
|
17
|
-
}
|
|
18
|
-
async createShop(id, url, secret) {
|
|
19
|
-
await this.storage.put(id, this.serializeShop(new repository_js_1.SimpleShop(id, url, secret)));
|
|
20
|
-
}
|
|
21
|
-
async deleteShop(id) {
|
|
22
|
-
await this.storage.delete(id);
|
|
23
|
-
}
|
|
24
|
-
async getShopById(id) {
|
|
25
|
-
const kvObj = await this.storage.get(id);
|
|
26
|
-
if (kvObj === null) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
return this.deserializeShop(kvObj);
|
|
30
|
-
}
|
|
31
|
-
async updateShop(shop) {
|
|
32
|
-
await this.storage.put(shop.getShopId(), this.serializeShop(shop));
|
|
33
|
-
}
|
|
34
|
-
serializeShop(shop) {
|
|
35
|
-
return JSON.stringify(shop);
|
|
36
|
-
}
|
|
37
|
-
deserializeShop(data) {
|
|
38
|
-
const obj = JSON.parse(data);
|
|
39
|
-
const shop = new repository_js_1.SimpleShop(obj.shopId || "", obj.shopUrl || "", obj.shopSecret || "");
|
|
40
|
-
shop.setShopCredentials(obj.shopClientId || "", obj.shopClientSecret || "");
|
|
41
|
-
return shop;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.CloudflareShopRepository = CloudflareShopRepository;
|
|
45
|
-
//# sourceMappingURL=cloudflare.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cloudflare.js","sourceRoot":"","sources":["../../../src/service/cloudflare.ts"],"names":[],"mappings":";;;AAAA,oDAA8C;AAG9C;;;GAGG;AAEH;;GAEG;AACH,MAAa,wBAAwB;IAGhB;IAApB,YAAoB,OAAoB;QAApB,YAAO,GAAP,OAAO,CAAa;QACvC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU,EAAE,GAAW,EAAE,MAAc;QACvD,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CACrB,EAAE,EACF,IAAI,CAAC,aAAa,CAAC,IAAI,0BAAU,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,CACnD,CAAC;IACH,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QAC1B,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,EAAU;QAC3B,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAEzC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC;QACb,CAAC;QAED,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,IAAgB;QAChC,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;IACpE,CAAC;IAES,aAAa,CAAC,IAAgB;QACvC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAES,eAAe,CAAC,IAAY;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAE7B,MAAM,IAAI,GAAG,IAAI,0BAAU,CAC1B,GAAG,CAAC,MAAM,IAAI,EAAE,EAChB,GAAG,CAAC,OAAO,IAAI,EAAE,EACjB,GAAG,CAAC,UAAU,IAAI,EAAE,CACpB,CAAC;QAEF,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,EAAE,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC;QAC5E,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAhDD,4DAgDC","sourcesContent":["import { SimpleShop } from \"../repository.js\";\nimport type { ShopInterface, ShopRepositoryInterface } from \"../repository.js\";\n\n/**\n * Cloudflare KV integration\n * @module\n */\n\n/**\n * Cloudflare KV implementation of the ShopRepositoryInterface\n */\nexport class CloudflareShopRepository\n\timplements ShopRepositoryInterface<SimpleShop>\n{\n\tconstructor(private storage: KVNamespace) {\n\t\tthis.storage = storage;\n\t}\n\n\tasync createShop(id: string, url: string, secret: string): Promise<void> {\n\t\tawait this.storage.put(\n\t\t\tid,\n\t\t\tthis.serializeShop(new SimpleShop(id, url, secret)),\n\t\t);\n\t}\n\n\tasync deleteShop(id: string): Promise<void> {\n\t\tawait this.storage.delete(id);\n\t}\n\n\tasync getShopById(id: string): Promise<SimpleShop | null> {\n\t\tconst kvObj = await this.storage.get(id);\n\n\t\tif (kvObj === null) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn this.deserializeShop(kvObj);\n\t}\n\n\tasync updateShop(shop: SimpleShop): Promise<void> {\n\t\tawait this.storage.put(shop.getShopId(), this.serializeShop(shop));\n\t}\n\n\tprotected serializeShop(shop: SimpleShop): string {\n\t\treturn JSON.stringify(shop);\n\t}\n\n\tprotected deserializeShop(data: string): SimpleShop {\n\t\tconst obj = JSON.parse(data);\n\n\t\tconst shop = new SimpleShop(\n\t\t\tobj.shopId || \"\",\n\t\t\tobj.shopUrl || \"\",\n\t\t\tobj.shopSecret || \"\",\n\t\t);\n\n\t\tshop.setShopCredentials(obj.shopClientId || \"\", obj.shopClientSecret || \"\");\n\t\treturn shop;\n\t}\n}\n\n/**\n * Cloudflare KV\n */\nexport declare interface KVNamespace<Key extends string = string> {\n\tget(\n\t\tkey: Key,\n\t\toptions?: Partial<KVNamespaceGetOptions<undefined>>,\n\t): Promise<string | null>;\n\tput(\n\t\tkey: Key,\n\t\tvalue: string | ArrayBuffer | ArrayBufferView | ReadableStream,\n\t\toptions?: KVNamespacePutOptions,\n\t): Promise<void>;\n\tdelete(key: Key): Promise<void>;\n}\n\n/**\n * Cloudflare KV get options\n */\nexport declare interface KVNamespaceGetOptions<Type> {\n\ttype: Type;\n\tcacheTtl?: number;\n}\n\n/**\n * Cloudflare KV put options\n */\nexport declare interface KVNamespacePutOptions {\n\texpiration?: number;\n\texpirationTtl?: number;\n\tmetadata?: any | null;\n}\n"]}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { SimpleShop } from "../repository.js";
|
|
2
|
-
import type { ShopRepositoryInterface } from "../repository.js";
|
|
3
|
-
/**
|
|
4
|
-
* Deno KV integration
|
|
5
|
-
* @module
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* DenoKVRepository is a ShopRepositoryInterface implementation that uses the Deno KV storage to save the shop data
|
|
9
|
-
*/
|
|
10
|
-
export declare class DenoKVRepository implements ShopRepositoryInterface<SimpleShop> {
|
|
11
|
-
private namespace;
|
|
12
|
-
constructor(namespace?: string);
|
|
13
|
-
createShop(id: string, url: string, secret: string): Promise<void>;
|
|
14
|
-
getShopById(id: string): Promise<SimpleShop | null>;
|
|
15
|
-
updateShop(shop: SimpleShop): Promise<void>;
|
|
16
|
-
deleteShop(id: string): Promise<void>;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=deno.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deno.d.ts","sourceRoot":"","sources":["../../../src/service/deno.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAiB,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE/E;;;GAGG;AAEH;;GAEG;AACH,qBAAa,gBAAiB,YAAW,uBAAuB,CAAC,UAAU,CAAC;IAC/D,OAAO,CAAC,SAAS;gBAAT,SAAS,SAAU;IAEjC,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOlE,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IA2BnD,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAO3C,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAM3C"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DenoKVRepository = void 0;
|
|
4
|
-
const repository_js_1 = require("../repository.js");
|
|
5
|
-
/**
|
|
6
|
-
* Deno KV integration
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* DenoKVRepository is a ShopRepositoryInterface implementation that uses the Deno KV storage to save the shop data
|
|
11
|
-
*/
|
|
12
|
-
class DenoKVRepository {
|
|
13
|
-
namespace;
|
|
14
|
-
constructor(namespace = "shops") {
|
|
15
|
-
this.namespace = namespace;
|
|
16
|
-
}
|
|
17
|
-
async createShop(id, url, secret) {
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
const kv = await Deno.openKv();
|
|
20
|
-
await kv.set([this.namespace, id], new repository_js_1.SimpleShop(id, url, secret));
|
|
21
|
-
}
|
|
22
|
-
async getShopById(id) {
|
|
23
|
-
// @ts-ignore
|
|
24
|
-
const kv = await Deno.openKv();
|
|
25
|
-
const result = await kv.get([this.namespace, id]);
|
|
26
|
-
if (result.key === null) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
const data = result.value;
|
|
30
|
-
const shop = new repository_js_1.SimpleShop(data.shopId, data.shopUrl, data.shopSecret);
|
|
31
|
-
if (data.shopClientId && data.shopClientSecret) {
|
|
32
|
-
shop.setShopCredentials(data.shopClientId, data.shopClientSecret);
|
|
33
|
-
}
|
|
34
|
-
return shop;
|
|
35
|
-
}
|
|
36
|
-
async updateShop(shop) {
|
|
37
|
-
// @ts-ignore
|
|
38
|
-
const kv = await Deno.openKv();
|
|
39
|
-
await kv.set([this.namespace, shop.getShopId()], shop);
|
|
40
|
-
}
|
|
41
|
-
async deleteShop(id) {
|
|
42
|
-
// @ts-ignore
|
|
43
|
-
const kv = await Deno.openKv();
|
|
44
|
-
await kv.delete([this.namespace, id]);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.DenoKVRepository = DenoKVRepository;
|
|
48
|
-
//# sourceMappingURL=deno.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deno.js","sourceRoot":"","sources":["../../../src/service/deno.ts"],"names":[],"mappings":";;;AAAA,oDAA8C;AAG9C;;;GAGG;AAEH;;GAEG;AACH,MAAa,gBAAgB;IACR;IAApB,YAAoB,YAAY,OAAO;QAAnB,cAAS,GAAT,SAAS,CAAU;IAAG,CAAC;IAE3C,KAAK,CAAC,UAAU,CAAC,EAAU,EAAE,GAAW,EAAE,MAAc;QACvD,aAAa;QACb,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QAE/B,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC,EAAE,IAAI,0BAAU,CAAC,EAA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repository.js\";\nimport type { ShopInterface, ShopRepositoryInterface } from \"../repository.js\";\n\n/**\n * Deno KV integration\n * @module\n */\n\n/**\n * DenoKVRepository is a ShopRepositoryInterface implementation that uses the Deno KV storage to save the shop data\n */\nexport class DenoKVRepository implements ShopRepositoryInterface<SimpleShop> {\n\tconstructor(private namespace = \"shops\") {}\n\n\tasync createShop(id: string, url: string, secret: string): Promise<void> {\n\t\t// @ts-ignore\n\t\tconst kv = await Deno.openKv();\n\n\t\tawait kv.set([this.namespace, id], new SimpleShop(id, url, secret));\n\t}\n\n\tasync getShopById(id: string): Promise<SimpleShop | null> {\n\t\t// @ts-ignore\n\t\tconst kv = await Deno.openKv();\n\n\t\tconst result = await kv.get([this.namespace, id]);\n\n\t\tif (result.key === null) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst data = result.value as {\n\t\t\tshopId: string;\n\t\t\tshopUrl: string;\n\t\t\tshopSecret: string;\n\t\t\tshopClientId: string | null;\n\t\t\tshopClientSecret: string | null;\n\t\t};\n\n\t\tconst shop = new SimpleShop(data.shopId, data.shopUrl, data.shopSecret);\n\n\t\tif (data.shopClientId && data.shopClientSecret) {\n\t\t\tshop.setShopCredentials(data.shopClientId, data.shopClientSecret);\n\t\t}\n\n\t\treturn shop;\n\t}\n\n\tasync updateShop(shop: SimpleShop): Promise<void> {\n\t\t// @ts-ignore\n\t\tconst kv = await Deno.openKv();\n\n\t\tawait kv.set([this.namespace, shop.getShopId()], shop);\n\t}\n\n\tasync deleteShop(id: string): Promise<void> {\n\t\t// @ts-ignore\n\t\tconst kv = await Deno.openKv();\n\n\t\tawait kv.delete([this.namespace, id]);\n\t}\n}\n"]}
|
package/dist/deno/app.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { ContextResolver } from "./context-resolver.js";
|
|
2
|
-
import { Registration } from "./registration.js";
|
|
3
|
-
import type { ShopInterface, ShopRepositoryInterface } from "./repository.js";
|
|
4
|
-
import { WebCryptoHmacSigner } from "./signer.js";
|
|
5
|
-
/**
|
|
6
|
-
* AppServer is the main class, this is where you start your app
|
|
7
|
-
*/
|
|
8
|
-
export declare class AppServer<Shop extends ShopInterface = ShopInterface> {
|
|
9
|
-
cfg: Configuration;
|
|
10
|
-
repository: ShopRepositoryInterface<Shop>;
|
|
11
|
-
registration: Registration;
|
|
12
|
-
contextResolver: ContextResolver<Shop>;
|
|
13
|
-
signer: WebCryptoHmacSigner;
|
|
14
|
-
constructor(cfg: Configuration, repository: ShopRepositoryInterface<Shop>);
|
|
15
|
-
}
|
|
16
|
-
interface Configuration {
|
|
17
|
-
/**
|
|
18
|
-
* Your app name
|
|
19
|
-
*/
|
|
20
|
-
appName: string;
|
|
21
|
-
/**
|
|
22
|
-
* Your app secret
|
|
23
|
-
*/
|
|
24
|
-
appSecret: string;
|
|
25
|
-
/**
|
|
26
|
-
* URL to authorize callback url
|
|
27
|
-
*/
|
|
28
|
-
authorizeCallbackUrl: string;
|
|
29
|
-
}
|
|
30
|
-
export {};
|
|
31
|
-
//# sourceMappingURL=app.d.ts.map
|
package/dist/deno/app.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD;;GAEG;AACH,qBAAa,SAAS,CAAC,IAAI,SAAS,aAAa,GAAG,aAAa;IAMxD,GAAG,EAAE,aAAa;IAClB,UAAU,EAAE,uBAAuB,CAAC,IAAI,CAAC;IAN1C,YAAY,EAAE,YAAY,CAAC;IAC3B,eAAe,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;IACvC,MAAM,EAAE,mBAAmB,CAAC;gBAG3B,GAAG,EAAE,aAAa,EAClB,UAAU,EAAE,uBAAuB,CAAC,IAAI,CAAC;CAMjD;AAED,UAAU,aAAa;IACtB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,oBAAoB,EAAE,MAAM,CAAC;CAC7B"}
|
package/dist/deno/app.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ContextResolver } from "./context-resolver.js";
|
|
2
|
-
import { Registration } from "./registration.js";
|
|
3
|
-
import { WebCryptoHmacSigner } from "./signer.js";
|
|
4
|
-
/**
|
|
5
|
-
* AppServer is the main class, this is where you start your app
|
|
6
|
-
*/
|
|
7
|
-
export class AppServer {
|
|
8
|
-
cfg;
|
|
9
|
-
repository;
|
|
10
|
-
registration;
|
|
11
|
-
contextResolver;
|
|
12
|
-
signer;
|
|
13
|
-
constructor(cfg, repository) {
|
|
14
|
-
this.cfg = cfg;
|
|
15
|
-
this.repository = repository;
|
|
16
|
-
this.registration = new Registration(this);
|
|
17
|
-
this.contextResolver = new ContextResolver(this);
|
|
18
|
-
this.signer = new WebCryptoHmacSigner();
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=app.js.map
|
package/dist/deno/app.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD;;GAEG;AACH,MAAM,OAAO,SAAS;IAMb;IACA;IAND,YAAY,CAAe;IAC3B,eAAe,CAAwB;IACvC,MAAM,CAAsB;IAEnC,YACQ,GAAkB,EAClB,UAAyC;QADzC,QAAG,GAAH,GAAG,CAAe;QAClB,eAAU,GAAV,UAAU,CAA+B;QAEhD,IAAI,CAAC,YAAY,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,CAAC,eAAe,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,GAAG,IAAI,mBAAmB,EAAE,CAAC;IACzC,CAAC;CACD","sourcesContent":["import { ContextResolver } from \"./context-resolver.js\";\nimport { Registration } from \"./registration.js\";\nimport type { ShopInterface, ShopRepositoryInterface } from \"./repository.js\";\nimport { WebCryptoHmacSigner } from \"./signer.js\";\n\n/**\n * AppServer is the main class, this is where you start your app\n */\nexport class AppServer<Shop extends ShopInterface = ShopInterface> {\n\tpublic registration: Registration;\n\tpublic contextResolver: ContextResolver<Shop>;\n\tpublic signer: WebCryptoHmacSigner;\n\n\tconstructor(\n\t\tpublic cfg: Configuration,\n\t\tpublic repository: ShopRepositoryInterface<Shop>,\n\t) {\n\t\tthis.registration = new Registration(this);\n\t\tthis.contextResolver = new ContextResolver(this);\n\t\tthis.signer = new WebCryptoHmacSigner();\n\t}\n}\n\ninterface Configuration {\n\t/**\n\t * Your app name\n\t */\n\tappName: string;\n\n\t/**\n\t * Your app secret\n\t */\n\tappSecret: string;\n\n\t/**\n\t * URL to authorize callback url\n\t */\n\tauthorizeCallbackUrl: string;\n}\n"]}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { AppServer } from "./app.js";
|
|
2
|
-
import { HttpClient } from "./http-client.js";
|
|
3
|
-
import type { ShopInterface } from "./repository.js";
|
|
4
|
-
/**
|
|
5
|
-
* ContextResolver is a helper class to create a Context object from a request.
|
|
6
|
-
* The context contains the shop, the payload and an instance of the HttpClient
|
|
7
|
-
*/
|
|
8
|
-
export declare class ContextResolver<Shop extends ShopInterface = ShopInterface> {
|
|
9
|
-
private app;
|
|
10
|
-
constructor(app: AppServer);
|
|
11
|
-
/**
|
|
12
|
-
* Create a context from a request body
|
|
13
|
-
*/
|
|
14
|
-
fromAPI<Payload = unknown>(req: Request): Promise<Context<Shop, Payload>>;
|
|
15
|
-
/**
|
|
16
|
-
* Create a context from a request query parameters
|
|
17
|
-
* This is usually a module request from the shopware admin
|
|
18
|
-
*/
|
|
19
|
-
fromBrowser<Payload = unknown>(req: Request): Promise<Context<Shop, Payload>>;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Context is the parsed data from the request
|
|
23
|
-
*/
|
|
24
|
-
export declare class Context<Shop extends ShopInterface = ShopInterface, Payload = unknown> {
|
|
25
|
-
shop: Shop;
|
|
26
|
-
payload: Payload;
|
|
27
|
-
httpClient: HttpClient;
|
|
28
|
-
constructor(shop: Shop, payload: Payload, httpClient: HttpClient);
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=context-resolver.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-resolver.d.ts","sourceRoot":"","sources":["../../src/context-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD;;;GAGG;AACH,qBAAa,eAAe,CAAC,IAAI,SAAS,aAAa,GAAG,aAAa;IAC1D,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,SAAS;IAElC;;OAEG;IACU,OAAO,CAAC,OAAO,GAAG,OAAO,EACrC,GAAG,EAAE,OAAO,GACV,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAmClC;;;OAGG;IACU,WAAW,CAAC,OAAO,GAAG,OAAO,EACzC,GAAG,EAAE,OAAO,GACV,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;CA6BlC;AAED;;GAEG;AACH,qBAAa,OAAO,CACnB,IAAI,SAAS,aAAa,GAAG,aAAa,EAC1C,OAAO,GAAG,OAAO;IAGT,IAAI,EAAE,IAAI;IACV,OAAO,EAAE,OAAO;IAChB,UAAU,EAAE,UAAU;gBAFtB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,UAAU;CAE9B"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { HttpClient } from "./http-client.js";
|
|
2
|
-
/**
|
|
3
|
-
* ContextResolver is a helper class to create a Context object from a request.
|
|
4
|
-
* The context contains the shop, the payload and an instance of the HttpClient
|
|
5
|
-
*/
|
|
6
|
-
export class ContextResolver {
|
|
7
|
-
app;
|
|
8
|
-
constructor(app) {
|
|
9
|
-
this.app = app;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Create a context from a request body
|
|
13
|
-
*/
|
|
14
|
-
async fromAPI(req) {
|
|
15
|
-
const webHookContent = await req.text();
|
|
16
|
-
const webHookBody = JSON.parse(webHookContent);
|
|
17
|
-
const shop = await this.app.repository.getShopById(webHookBody.source.shopId);
|
|
18
|
-
if (shop === null) {
|
|
19
|
-
throw new Error(`Cannot find shop by id ${webHookBody.source.shopId}`);
|
|
20
|
-
}
|
|
21
|
-
const signature = req.headers.get("shopware-shop-signature");
|
|
22
|
-
if (signature === null) {
|
|
23
|
-
throw new Error("Missing shopware-shop-signature header");
|
|
24
|
-
}
|
|
25
|
-
if (!(await this.app.signer.verify(signature, webHookContent, shop.getShopSecret()))) {
|
|
26
|
-
throw new Error("Invalid signature");
|
|
27
|
-
}
|
|
28
|
-
return new Context(shop, webHookBody, new HttpClient(shop));
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Create a context from a request query parameters
|
|
32
|
-
* This is usually a module request from the shopware admin
|
|
33
|
-
*/
|
|
34
|
-
async fromBrowser(req) {
|
|
35
|
-
const url = new URL(req.url);
|
|
36
|
-
const shopId = url.searchParams.get("shop-id");
|
|
37
|
-
if (shopId === null) {
|
|
38
|
-
throw new Error("Missing shop-id query parameter");
|
|
39
|
-
}
|
|
40
|
-
const shop = await this.app.repository.getShopById(shopId);
|
|
41
|
-
if (shop === null) {
|
|
42
|
-
throw new Error(`Cannot find shop by id ${shopId}`);
|
|
43
|
-
}
|
|
44
|
-
await this.app.signer.verifyGetRequest(req, shop.getShopSecret());
|
|
45
|
-
const paramsObject = {};
|
|
46
|
-
url.searchParams.forEach((value, key) => {
|
|
47
|
-
paramsObject[key] = value;
|
|
48
|
-
});
|
|
49
|
-
return new Context(shop, paramsObject, new HttpClient(shop));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Context is the parsed data from the request
|
|
54
|
-
*/
|
|
55
|
-
export class Context {
|
|
56
|
-
shop;
|
|
57
|
-
payload;
|
|
58
|
-
httpClient;
|
|
59
|
-
constructor(shop, payload, httpClient) {
|
|
60
|
-
this.shop = shop;
|
|
61
|
-
this.payload = payload;
|
|
62
|
-
this.httpClient = httpClient;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
//# sourceMappingURL=context-resolver.js.map
|