@shopware-ag/app-server-sdk 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/integration/better-sqlite3.d.ts +11 -0
- package/dist/commonjs/integration/better-sqlite3.d.ts.map +1 -0
- package/dist/commonjs/integration/better-sqlite3.js +58 -0
- package/dist/commonjs/integration/better-sqlite3.js.map +1 -0
- package/dist/esm/integration/better-sqlite3.d.ts +11 -0
- package/dist/esm/integration/better-sqlite3.d.ts.map +1 -0
- package/dist/esm/integration/better-sqlite3.js +51 -0
- package/dist/esm/integration/better-sqlite3.js.map +1 -0
- package/package.json +173 -141
- package/dist/commonjs/context-resolver.test.d.ts +0 -2
- package/dist/commonjs/context-resolver.test.d.ts.map +0 -1
- package/dist/commonjs/context-resolver.test.js +0 -81
- package/dist/commonjs/context-resolver.test.js.map +0 -1
- package/dist/commonjs/helper/app-actions.test.d.ts +0 -2
- package/dist/commonjs/helper/app-actions.test.d.ts.map +0 -1
- package/dist/commonjs/helper/app-actions.test.js +0 -31
- package/dist/commonjs/helper/app-actions.test.js.map +0 -1
- package/dist/commonjs/http-client.test.d.ts +0 -2
- package/dist/commonjs/http-client.test.d.ts.map +0 -1
- package/dist/commonjs/http-client.test.js +0 -71
- package/dist/commonjs/http-client.test.js.map +0 -1
- package/dist/commonjs/integration/bun-sqlite.test.d.ts +0 -2
- package/dist/commonjs/integration/bun-sqlite.test.d.ts.map +0 -1
- package/dist/commonjs/integration/bun-sqlite.test.js +0 -24
- package/dist/commonjs/integration/bun-sqlite.test.js.map +0 -1
- package/dist/commonjs/integration/cloudflare.test.d.ts +0 -2
- package/dist/commonjs/integration/cloudflare.test.d.ts.map +0 -1
- package/dist/commonjs/integration/cloudflare.test.js +0 -39
- package/dist/commonjs/integration/cloudflare.test.js.map +0 -1
- package/dist/commonjs/integration/deno.test.d.ts +0 -2
- package/dist/commonjs/integration/deno.test.d.ts.map +0 -1
- package/dist/commonjs/integration/deno.test.js +0 -48
- package/dist/commonjs/integration/deno.test.js.map +0 -1
- package/dist/commonjs/integration/dynamodb.test.d.ts +0 -2
- package/dist/commonjs/integration/dynamodb.test.d.ts.map +0 -1
- package/dist/commonjs/integration/dynamodb.test.js +0 -132
- package/dist/commonjs/integration/dynamodb.test.js.map +0 -1
- package/dist/commonjs/integration/hono.test.d.ts +0 -2
- package/dist/commonjs/integration/hono.test.d.ts.map +0 -1
- package/dist/commonjs/integration/hono.test.js +0 -86
- package/dist/commonjs/integration/hono.test.js.map +0 -1
- package/dist/commonjs/registration.test.d.ts +0 -2
- package/dist/commonjs/registration.test.d.ts.map +0 -1
- package/dist/commonjs/registration.test.js +0 -59
- package/dist/commonjs/registration.test.js.map +0 -1
- package/dist/commonjs/repository.test.d.ts +0 -2
- package/dist/commonjs/repository.test.d.ts.map +0 -1
- package/dist/commonjs/repository.test.js +0 -32
- package/dist/commonjs/repository.test.js.map +0 -1
- package/dist/commonjs/signer.test.d.ts +0 -2
- package/dist/commonjs/signer.test.d.ts.map +0 -1
- package/dist/commonjs/signer.test.js +0 -25
- package/dist/commonjs/signer.test.js.map +0 -1
- package/dist/esm/context-resolver.test.d.ts +0 -2
- package/dist/esm/context-resolver.test.d.ts.map +0 -1
- package/dist/esm/context-resolver.test.js +0 -79
- package/dist/esm/context-resolver.test.js.map +0 -1
- package/dist/esm/helper/app-actions.test.d.ts +0 -2
- package/dist/esm/helper/app-actions.test.d.ts.map +0 -1
- package/dist/esm/helper/app-actions.test.js +0 -29
- package/dist/esm/helper/app-actions.test.js.map +0 -1
- package/dist/esm/http-client.test.d.ts +0 -2
- package/dist/esm/http-client.test.d.ts.map +0 -1
- package/dist/esm/http-client.test.js +0 -69
- package/dist/esm/http-client.test.js.map +0 -1
- package/dist/esm/integration/bun-sqlite.test.d.ts +0 -2
- package/dist/esm/integration/bun-sqlite.test.d.ts.map +0 -1
- package/dist/esm/integration/bun-sqlite.test.js +0 -22
- package/dist/esm/integration/bun-sqlite.test.js.map +0 -1
- package/dist/esm/integration/cloudflare.test.d.ts +0 -2
- package/dist/esm/integration/cloudflare.test.d.ts.map +0 -1
- package/dist/esm/integration/cloudflare.test.js +0 -37
- package/dist/esm/integration/cloudflare.test.js.map +0 -1
- package/dist/esm/integration/deno.test.d.ts +0 -2
- package/dist/esm/integration/deno.test.d.ts.map +0 -1
- package/dist/esm/integration/deno.test.js +0 -46
- package/dist/esm/integration/deno.test.js.map +0 -1
- package/dist/esm/integration/dynamodb.test.d.ts +0 -2
- package/dist/esm/integration/dynamodb.test.d.ts.map +0 -1
- package/dist/esm/integration/dynamodb.test.js +0 -130
- package/dist/esm/integration/dynamodb.test.js.map +0 -1
- package/dist/esm/integration/hono.test.d.ts +0 -2
- package/dist/esm/integration/hono.test.d.ts.map +0 -1
- package/dist/esm/integration/hono.test.js +0 -84
- package/dist/esm/integration/hono.test.js.map +0 -1
- package/dist/esm/registration.test.d.ts +0 -2
- package/dist/esm/registration.test.d.ts.map +0 -1
- package/dist/esm/registration.test.js +0 -57
- package/dist/esm/registration.test.js.map +0 -1
- package/dist/esm/repository.test.d.ts +0 -2
- package/dist/esm/repository.test.d.ts.map +0 -1
- package/dist/esm/repository.test.js +0 -30
- package/dist/esm/repository.test.js.map +0 -1
- package/dist/esm/signer.test.d.ts +0 -2
- package/dist/esm/signer.test.d.ts.map +0 -1
- package/dist/esm/signer.test.js +0 -23
- package/dist/esm/signer.test.js.map +0 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ShopRepositoryInterface, SimpleShop } from "../repository.js";
|
|
2
|
+
import Database from "better-sqlite3";
|
|
3
|
+
export declare class BetterSqlite3Repository implements ShopRepositoryInterface<SimpleShop> {
|
|
4
|
+
db: Database.Database;
|
|
5
|
+
constructor(fileName: string);
|
|
6
|
+
createShop(id: string, url: string, secret: string): Promise<void>;
|
|
7
|
+
getShopById(id: string): Promise<SimpleShop | null>;
|
|
8
|
+
updateShop(shop: SimpleShop): Promise<void>;
|
|
9
|
+
deleteShop(id: string): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=better-sqlite3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"better-sqlite3.d.ts","sourceRoot":"","sources":["../../../src/integration/better-sqlite3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,uBAAuB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE5E,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAEtC,qBAAa,uBACZ,YAAW,uBAAuB,CAAC,UAAU,CAAC;IAE9C,EAAE,EAAE,QAAQ,CAAC,QAAQ,CAAC;gBACV,QAAQ,EAAE,MAAM;IAetB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYlE,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IA0BnD,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAc3C,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG3C"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BetterSqlite3Repository = void 0;
|
|
7
|
+
const repository_js_1 = require("../repository.js");
|
|
8
|
+
const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
|
|
9
|
+
class BetterSqlite3Repository {
|
|
10
|
+
db;
|
|
11
|
+
constructor(fileName) {
|
|
12
|
+
this.db = new better_sqlite3_1.default(fileName);
|
|
13
|
+
this.db.pragma("journal_mode = WAL");
|
|
14
|
+
this.db.exec(`
|
|
15
|
+
CREATE TABLE IF NOT EXISTS shop (
|
|
16
|
+
id TEXT PRIMARY KEY,
|
|
17
|
+
active BOOLEAN DEFAULT 1,
|
|
18
|
+
url TEXT NOT NULL,
|
|
19
|
+
secret TEXT NOT NULL,
|
|
20
|
+
client_id TEXT NULL,
|
|
21
|
+
client_secret TEXT NULL
|
|
22
|
+
);
|
|
23
|
+
`);
|
|
24
|
+
}
|
|
25
|
+
async createShop(id, url, secret) {
|
|
26
|
+
const shop = await this.getShopById(id);
|
|
27
|
+
if (shop) {
|
|
28
|
+
return await this.updateShop(shop);
|
|
29
|
+
}
|
|
30
|
+
this.db
|
|
31
|
+
.prepare("INSERT INTO shop (id, url, secret) VALUES (?, ?, ?)")
|
|
32
|
+
.run(id, url, secret);
|
|
33
|
+
}
|
|
34
|
+
async getShopById(id) {
|
|
35
|
+
const result = this.db
|
|
36
|
+
.prepare("SELECT * FROM shop WHERE id = ?")
|
|
37
|
+
.get(id);
|
|
38
|
+
if (!result) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const shop = new repository_js_1.SimpleShop(result.id, result.url, result.secret);
|
|
42
|
+
if (result.client_id && result.client_secret) {
|
|
43
|
+
shop.setShopCredentials(result.client_id, result.client_secret);
|
|
44
|
+
}
|
|
45
|
+
shop.setShopActive(result.active === 1);
|
|
46
|
+
return shop;
|
|
47
|
+
}
|
|
48
|
+
async updateShop(shop) {
|
|
49
|
+
this.db
|
|
50
|
+
.prepare("UPDATE shop SET url = ?, secret = ?, client_id = ?, client_secret = ?, active = ? WHERE id = ?")
|
|
51
|
+
.run(shop.getShopUrl(), shop.getShopSecret(), shop.getShopClientId(), shop.getShopClientSecret(), +shop.getShopActive(), shop.getShopId());
|
|
52
|
+
}
|
|
53
|
+
async deleteShop(id) {
|
|
54
|
+
this.db.prepare("DELETE FROM shop where id = ?").run(id);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.BetterSqlite3Repository = BetterSqlite3Repository;
|
|
58
|
+
//# sourceMappingURL=better-sqlite3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"better-sqlite3.js","sourceRoot":"","sources":["../../../src/integration/better-sqlite3.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4E;AAE5E,oEAAsC;AAEtC,MAAa,uBAAuB;IAGnC,EAAE,CAAoB;IACtB,YAAY,QAAgB;QAC3B,IAAI,CAAC,EAAE,GAAG,IAAI,wBAAQ,CAAC,QAAQ,CAAC,CAAC;QACjC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;QACrC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;;;;;;;;;OASR,CAAC,CAAC;IACR,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU,EAAE,GAAW,EAAE,MAAc;QACvD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAExC,IAAI,IAAI,EAAE,CAAC;YACV,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACpC,CAAC;QAED,IAAI,CAAC,EAAE;aACL,OAAO,CAAC,qDAAqD,CAAC;aAC9D,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,EAAU;QAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE;aACpB,OAAO,CAAC,iCAAiC,CAAC;aAC1C,GAAG,CAAC,EAAE,CAOP,CAAC;QAEF,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,OAAO,IAAI,CAAC;QACb,CAAC;QAED,MAAM,IAAI,GAAG,IAAI,0BAAU,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QAElE,IAAI,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;YAC9C,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;QACjE,CAAC;QAED,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC;QAExC,OAAO,IAAI,CAAC;IACb,CAAC;IACD,KAAK,CAAC,UAAU,CAAC,IAAgB;QAChC,IAAI,CAAC,EAAE;aACL,OAAO,CACP,gGAAgG,CAChG;aACA,GAAG,CACH,IAAI,CAAC,UAAU,EAAE,EACjB,IAAI,CAAC,aAAa,EAAE,EACpB,IAAI,CAAC,eAAe,EAAE,EACtB,IAAI,CAAC,mBAAmB,EAAE,EAC1B,CAAC,IAAI,CAAC,aAAa,EAAE,EACrB,IAAI,CAAC,SAAS,EAAE,CAChB,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,UAAU,CAAC,EAAU;QAC1B,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,+BAA+B,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC1D,CAAC;CACD;AA1ED,0DA0EC","sourcesContent":["import { type ShopRepositoryInterface, SimpleShop } from \"../repository.js\";\n\nimport Database from \"better-sqlite3\";\n\nexport class BetterSqlite3Repository\n\timplements ShopRepositoryInterface<SimpleShop>\n{\n\tdb: Database.Database;\n\tconstructor(fileName: string) {\n\t\tthis.db = new Database(fileName);\n\t\tthis.db.pragma(\"journal_mode = WAL\");\n\t\tthis.db.exec(`\n CREATE TABLE IF NOT EXISTS shop (\n id TEXT PRIMARY KEY,\n active BOOLEAN DEFAULT 1,\n url TEXT NOT NULL,\n secret TEXT NOT NULL,\n client_id TEXT NULL,\n client_secret TEXT NULL\n );\n `);\n\t}\n\n\tasync createShop(id: string, url: string, secret: string): Promise<void> {\n\t\tconst shop = await this.getShopById(id);\n\n\t\tif (shop) {\n\t\t\treturn await this.updateShop(shop);\n\t\t}\n\n\t\tthis.db\n\t\t\t.prepare(\"INSERT INTO shop (id, url, secret) VALUES (?, ?, ?)\")\n\t\t\t.run(id, url, secret);\n\t}\n\n\tasync getShopById(id: string): Promise<SimpleShop | null> {\n\t\tconst result = this.db\n\t\t\t.prepare(\"SELECT * FROM shop WHERE id = ?\")\n\t\t\t.get(id) as null | {\n\t\t\tid: string;\n\t\t\tactive: number;\n\t\t\turl: string;\n\t\t\tsecret: string;\n\t\t\tclient_id?: string;\n\t\t\tclient_secret?: string;\n\t\t};\n\n\t\tif (!result) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst shop = new SimpleShop(result.id, result.url, result.secret);\n\n\t\tif (result.client_id && result.client_secret) {\n\t\t\tshop.setShopCredentials(result.client_id, result.client_secret);\n\t\t}\n\n\t\tshop.setShopActive(result.active === 1);\n\n\t\treturn shop;\n\t}\n\tasync updateShop(shop: SimpleShop): Promise<void> {\n\t\tthis.db\n\t\t\t.prepare(\n\t\t\t\t\"UPDATE shop SET url = ?, secret = ?, client_id = ?, client_secret = ?, active = ? WHERE id = ?\",\n\t\t\t)\n\t\t\t.run(\n\t\t\t\tshop.getShopUrl(),\n\t\t\t\tshop.getShopSecret(),\n\t\t\t\tshop.getShopClientId(),\n\t\t\t\tshop.getShopClientSecret(),\n\t\t\t\t+shop.getShopActive(),\n\t\t\t\tshop.getShopId(),\n\t\t\t);\n\t}\n\tasync deleteShop(id: string): Promise<void> {\n\t\tthis.db.prepare(\"DELETE FROM shop where id = ?\").run(id);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ShopRepositoryInterface, SimpleShop } from "../repository.js";
|
|
2
|
+
import Database from "better-sqlite3";
|
|
3
|
+
export declare class BetterSqlite3Repository implements ShopRepositoryInterface<SimpleShop> {
|
|
4
|
+
db: Database.Database;
|
|
5
|
+
constructor(fileName: string);
|
|
6
|
+
createShop(id: string, url: string, secret: string): Promise<void>;
|
|
7
|
+
getShopById(id: string): Promise<SimpleShop | null>;
|
|
8
|
+
updateShop(shop: SimpleShop): Promise<void>;
|
|
9
|
+
deleteShop(id: string): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=better-sqlite3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"better-sqlite3.d.ts","sourceRoot":"","sources":["../../../src/integration/better-sqlite3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,uBAAuB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE5E,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAEtC,qBAAa,uBACZ,YAAW,uBAAuB,CAAC,UAAU,CAAC;IAE9C,EAAE,EAAE,QAAQ,CAAC,QAAQ,CAAC;gBACV,QAAQ,EAAE,MAAM;IAetB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYlE,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IA0BnD,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAc3C,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG3C"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { SimpleShop } from "../repository.js";
|
|
2
|
+
import Database from "better-sqlite3";
|
|
3
|
+
export class BetterSqlite3Repository {
|
|
4
|
+
db;
|
|
5
|
+
constructor(fileName) {
|
|
6
|
+
this.db = new Database(fileName);
|
|
7
|
+
this.db.pragma("journal_mode = WAL");
|
|
8
|
+
this.db.exec(`
|
|
9
|
+
CREATE TABLE IF NOT EXISTS shop (
|
|
10
|
+
id TEXT PRIMARY KEY,
|
|
11
|
+
active BOOLEAN DEFAULT 1,
|
|
12
|
+
url TEXT NOT NULL,
|
|
13
|
+
secret TEXT NOT NULL,
|
|
14
|
+
client_id TEXT NULL,
|
|
15
|
+
client_secret TEXT NULL
|
|
16
|
+
);
|
|
17
|
+
`);
|
|
18
|
+
}
|
|
19
|
+
async createShop(id, url, secret) {
|
|
20
|
+
const shop = await this.getShopById(id);
|
|
21
|
+
if (shop) {
|
|
22
|
+
return await this.updateShop(shop);
|
|
23
|
+
}
|
|
24
|
+
this.db
|
|
25
|
+
.prepare("INSERT INTO shop (id, url, secret) VALUES (?, ?, ?)")
|
|
26
|
+
.run(id, url, secret);
|
|
27
|
+
}
|
|
28
|
+
async getShopById(id) {
|
|
29
|
+
const result = this.db
|
|
30
|
+
.prepare("SELECT * FROM shop WHERE id = ?")
|
|
31
|
+
.get(id);
|
|
32
|
+
if (!result) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const shop = new SimpleShop(result.id, result.url, result.secret);
|
|
36
|
+
if (result.client_id && result.client_secret) {
|
|
37
|
+
shop.setShopCredentials(result.client_id, result.client_secret);
|
|
38
|
+
}
|
|
39
|
+
shop.setShopActive(result.active === 1);
|
|
40
|
+
return shop;
|
|
41
|
+
}
|
|
42
|
+
async updateShop(shop) {
|
|
43
|
+
this.db
|
|
44
|
+
.prepare("UPDATE shop SET url = ?, secret = ?, client_id = ?, client_secret = ?, active = ? WHERE id = ?")
|
|
45
|
+
.run(shop.getShopUrl(), shop.getShopSecret(), shop.getShopClientId(), shop.getShopClientSecret(), +shop.getShopActive(), shop.getShopId());
|
|
46
|
+
}
|
|
47
|
+
async deleteShop(id) {
|
|
48
|
+
this.db.prepare("DELETE FROM shop where id = ?").run(id);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=better-sqlite3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"better-sqlite3.js","sourceRoot":"","sources":["../../../src/integration/better-sqlite3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE5E,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAEt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IACb,CAAC;IACD,KAAK,CAAC,UAAU,CAAC,IAAgB;QAChC,IAAI,CAAC,EAAE;aACL,OAAO,CACP,gGAAgG,CAChG;aACA,GAAG,CACH,IAAI,CAAC,UAAU,EAAE,EACjB,IAAI,CAAC,aAAa,EAAE,EACpB,IAAI,CAAC,eAAe,EAAE,EACtB,IAAI,CAAC,mBAAmB,EAAE,EAC1B,CAAC,IAAI,CAAC,aAAa,EAAE,EACrB,IAAI,CAAC,SAAS,EAAE,CAChB,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,UAAU,CAAC,EAAU;QAC1B,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,+BAA+B,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC1D,CAAC;CACD","sourcesContent":["import { type ShopRepositoryInterface, SimpleShop } from \"../repository.js\";\n\nimport Database from \"better-sqlite3\";\n\nexport class BetterSqlite3Repository\n\timplements ShopRepositoryInterface<SimpleShop>\n{\n\tdb: Database.Database;\n\tconstructor(fileName: string) {\n\t\tthis.db = new Database(fileName);\n\t\tthis.db.pragma(\"journal_mode = WAL\");\n\t\tthis.db.exec(`\n CREATE TABLE IF NOT EXISTS shop (\n id TEXT PRIMARY KEY,\n active BOOLEAN DEFAULT 1,\n url TEXT NOT NULL,\n secret TEXT NOT NULL,\n client_id TEXT NULL,\n client_secret TEXT NULL\n );\n `);\n\t}\n\n\tasync createShop(id: string, url: string, secret: string): Promise<void> {\n\t\tconst shop = await this.getShopById(id);\n\n\t\tif (shop) {\n\t\t\treturn await this.updateShop(shop);\n\t\t}\n\n\t\tthis.db\n\t\t\t.prepare(\"INSERT INTO shop (id, url, secret) VALUES (?, ?, ?)\")\n\t\t\t.run(id, url, secret);\n\t}\n\n\tasync getShopById(id: string): Promise<SimpleShop | null> {\n\t\tconst result = this.db\n\t\t\t.prepare(\"SELECT * FROM shop WHERE id = ?\")\n\t\t\t.get(id) as null | {\n\t\t\tid: string;\n\t\t\tactive: number;\n\t\t\turl: string;\n\t\t\tsecret: string;\n\t\t\tclient_id?: string;\n\t\t\tclient_secret?: string;\n\t\t};\n\n\t\tif (!result) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst shop = new SimpleShop(result.id, result.url, result.secret);\n\n\t\tif (result.client_id && result.client_secret) {\n\t\t\tshop.setShopCredentials(result.client_id, result.client_secret);\n\t\t}\n\n\t\tshop.setShopActive(result.active === 1);\n\n\t\treturn shop;\n\t}\n\tasync updateShop(shop: SimpleShop): Promise<void> {\n\t\tthis.db\n\t\t\t.prepare(\n\t\t\t\t\"UPDATE shop SET url = ?, secret = ?, client_id = ?, client_secret = ?, active = ? WHERE id = ?\",\n\t\t\t)\n\t\t\t.run(\n\t\t\t\tshop.getShopUrl(),\n\t\t\t\tshop.getShopSecret(),\n\t\t\t\tshop.getShopClientId(),\n\t\t\t\tshop.getShopClientSecret(),\n\t\t\t\t+shop.getShopActive(),\n\t\t\t\tshop.getShopId(),\n\t\t\t);\n\t}\n\tasync deleteShop(id: string): Promise<void> {\n\t\tthis.db.prepare(\"DELETE FROM shop where id = ?\").run(id);\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,143 +1,175 @@
|
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
2
|
+
"name": "@shopware-ag/app-server-sdk",
|
|
3
|
+
"version": "1.1.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
|
+
"./integration/hono": {
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/esm/integration/hono.d.ts",
|
|
36
|
+
"default": "./dist/esm/integration/hono.js"
|
|
37
|
+
},
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./dist/commonjs/integration/hono.d.ts",
|
|
40
|
+
"default": "./dist/commonjs/integration/hono.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"./integration/cloudflare-kv": {
|
|
44
|
+
"import": {
|
|
45
|
+
"types": "./dist/esm/integration/cloudflare-kv.d.ts",
|
|
46
|
+
"default": "./dist/esm/integration/cloudflare-kv.js"
|
|
47
|
+
},
|
|
48
|
+
"require": {
|
|
49
|
+
"types": "./dist/commonjs/integration/cloudflare-kv.d.ts",
|
|
50
|
+
"default": "./dist/commonjs/integration/cloudflare-kv.js"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"./integration/deno-kv": {
|
|
54
|
+
"import": {
|
|
55
|
+
"types": "./dist/esm/integration/deno-kv.d.ts",
|
|
56
|
+
"default": "./dist/esm/integration/deno-kv.js"
|
|
57
|
+
},
|
|
58
|
+
"require": {
|
|
59
|
+
"types": "./dist/commonjs/integration/deno-kv.d.ts",
|
|
60
|
+
"default": "./dist/commonjs/integration/deno-kv.js"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"./integration/dynamodb": {
|
|
64
|
+
"import": {
|
|
65
|
+
"types": "./dist/esm/integration/dynamodb.d.ts",
|
|
66
|
+
"default": "./dist/esm/integration/dynamodb.js"
|
|
67
|
+
},
|
|
68
|
+
"require": {
|
|
69
|
+
"types": "./dist/commonjs/integration/dynamodb.d.ts",
|
|
70
|
+
"default": "./dist/commonjs/integration/dynamodb.js"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"./integration/bun-sqlite": {
|
|
74
|
+
"import": {
|
|
75
|
+
"types": "./dist/esm/integration/bun-sqlite.d.ts",
|
|
76
|
+
"default": "./dist/esm/integration/bun-sqlite.js"
|
|
77
|
+
},
|
|
78
|
+
"require": {
|
|
79
|
+
"types": "./dist/commonjs/integration/bun-sqlite.d.ts",
|
|
80
|
+
"default": "./dist/commonjs/integration/bun-sqlite.js"
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"./integration/better-sqlite3": {
|
|
84
|
+
"import": {
|
|
85
|
+
"types": "./dist/esm/integration/better-sqlite3.d.ts",
|
|
86
|
+
"default": "./dist/esm/integration/better-sqlite3.js"
|
|
87
|
+
},
|
|
88
|
+
"require": {
|
|
89
|
+
"types": "./dist/commonjs/integration/better-sqlite3.d.ts",
|
|
90
|
+
"default": "./dist/commonjs/integration/better-sqlite3.js"
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"./types": {
|
|
94
|
+
"import": {
|
|
95
|
+
"types": "./dist/esm/types.d.ts",
|
|
96
|
+
"default": "./dist/esm/types.js"
|
|
97
|
+
},
|
|
98
|
+
"require": {
|
|
99
|
+
"types": "./dist/commonjs/types.d.ts",
|
|
100
|
+
"default": "./dist/commonjs/types.js"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"main": "./dist/commonjs/mod.js",
|
|
105
|
+
"module": "./dist/esm/mod.js",
|
|
106
|
+
"types": "./dist/commonjs/mod.d.ts",
|
|
107
|
+
"files": [
|
|
108
|
+
"dist"
|
|
109
|
+
],
|
|
110
|
+
"publishConfig": {
|
|
111
|
+
"access": "public",
|
|
112
|
+
"provenance": true
|
|
113
|
+
},
|
|
114
|
+
"repository": {
|
|
115
|
+
"url": "https://github.com/shopware/app-sdk-js"
|
|
116
|
+
},
|
|
117
|
+
"peerDependencies": {
|
|
118
|
+
"@aws-sdk/client-dynamodb": "~3.637",
|
|
119
|
+
"@aws-sdk/lib-dynamodb": "~3.637",
|
|
120
|
+
"better-sqlite3": "^11",
|
|
121
|
+
"hono": "^4"
|
|
122
|
+
},
|
|
123
|
+
"peerDependenciesMeta": {
|
|
124
|
+
"hono": {
|
|
125
|
+
"optional": true
|
|
126
|
+
},
|
|
127
|
+
"@aws-sdk/client-dynamodb": {
|
|
128
|
+
"optional": true
|
|
129
|
+
},
|
|
130
|
+
"@aws-sdk/lib-dynamodb": {
|
|
131
|
+
"optional": true
|
|
132
|
+
},
|
|
133
|
+
"better-sqlite3": {
|
|
134
|
+
"optional": true
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
"devDependencies": {
|
|
138
|
+
"@aws-sdk/client-dynamodb": "~3.637",
|
|
139
|
+
"@aws-sdk/lib-dynamodb": "~3.637",
|
|
140
|
+
"@biomejs/biome": "1.8.3",
|
|
141
|
+
"@cloudflare/workers-types": "^4.20240821.1",
|
|
142
|
+
"@types/better-sqlite3": "^7.6.11",
|
|
143
|
+
"@types/bun": "^1.1.6",
|
|
144
|
+
"better-sqlite3": "^11",
|
|
145
|
+
"hono": "^4.5.6",
|
|
146
|
+
"tshy": "^3.0.2"
|
|
147
|
+
},
|
|
148
|
+
"tshy": {
|
|
149
|
+
"exports": {
|
|
150
|
+
"./package.json": "./package.json",
|
|
151
|
+
".": "./src/mod.ts",
|
|
152
|
+
"./helper/app-actions": "./src/helper/app-actions.ts",
|
|
153
|
+
"./integration/hono": "./src/integration/hono.ts",
|
|
154
|
+
"./integration/cloudflare-kv": "./src/integration/cloudflare-kv.ts",
|
|
155
|
+
"./integration/deno-kv": "./src/integration/deno-kv.ts",
|
|
156
|
+
"./integration/dynamodb": "./src/integration/dynamodb.ts",
|
|
157
|
+
"./integration/bun-sqlite": "./src/integration/bun-sqlite.ts",
|
|
158
|
+
"./integration/better-sqlite3": "./src/integration/better-sqlite3.ts",
|
|
159
|
+
"./types": "./src/types.ts"
|
|
160
|
+
},
|
|
161
|
+
"exclude": [
|
|
162
|
+
"src/**/*.test.ts"
|
|
163
|
+
]
|
|
164
|
+
},
|
|
165
|
+
"scripts": {
|
|
166
|
+
"init": "tshy && biome format . --write",
|
|
167
|
+
"lint": "biome ci .",
|
|
168
|
+
"lint:fix": "biome lint . --write && biome format . --write && biome check . --write",
|
|
169
|
+
"typecheck": "tsc --noEmit"
|
|
170
|
+
},
|
|
171
|
+
"trustedDependencies": [
|
|
172
|
+
"@biomejs/biome",
|
|
173
|
+
"better-sqlite3"
|
|
174
|
+
]
|
|
143
175
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-resolver.test.d.ts","sourceRoot":"","sources":["../../src/context-resolver.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const bun_test_1 = require("bun:test");
|
|
4
|
-
const app_js_1 = require("../src/app.js");
|
|
5
|
-
const context_resolver_js_1 = require("../src/context-resolver.js");
|
|
6
|
-
const repository_js_1 = require("../src/repository.js");
|
|
7
|
-
(0, bun_test_1.describe)("Context Resolver", async () => {
|
|
8
|
-
const app = new app_js_1.AppServer({
|
|
9
|
-
appName: "test",
|
|
10
|
-
appSecret: "test",
|
|
11
|
-
authorizeCallbackUrl: "test",
|
|
12
|
-
}, new repository_js_1.InMemoryShopRepository());
|
|
13
|
-
await app.repository.createShop("blaa", "test", "test");
|
|
14
|
-
const contextResolver = new context_resolver_js_1.ContextResolver(app);
|
|
15
|
-
(0, bun_test_1.test)("fromBrowser: shop does not exist", async () => {
|
|
16
|
-
(0, bun_test_1.expect)(contextResolver.fromBrowser(new Request("https://example.com/?shop-id=test&shopware-shop-signature=aaa"))).rejects.toThrowError("Cannot find shop by id test");
|
|
17
|
-
});
|
|
18
|
-
(0, bun_test_1.test)("fromBrowser: missing header", async () => {
|
|
19
|
-
(0, bun_test_1.expect)(contextResolver.fromBrowser(new Request("https://example.com/?shop-id=blaa"))).rejects.toThrowError("Missing shopware-shop-signature query parameter");
|
|
20
|
-
});
|
|
21
|
-
(0, bun_test_1.test)("fromBrowser: shop exists", async () => {
|
|
22
|
-
app.signer.verifyGetRequest = bun_test_1.jest.fn().mockResolvedValue(true);
|
|
23
|
-
const context = await contextResolver.fromBrowser(new Request("https://example.com/?shop-id=blaa&shopware-shop-signature=aaa"));
|
|
24
|
-
(0, bun_test_1.expect)(context.payload).toEqual({
|
|
25
|
-
"shop-id": "blaa",
|
|
26
|
-
"shopware-shop-signature": "aaa",
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
(0, bun_test_1.test)("fromSource: missing signature header", async () => {
|
|
30
|
-
(0, bun_test_1.expect)(contextResolver.fromAPI(new Request("https://example.com/", {
|
|
31
|
-
body: JSON.stringify({
|
|
32
|
-
source: {
|
|
33
|
-
shopId: "blaa",
|
|
34
|
-
},
|
|
35
|
-
}),
|
|
36
|
-
}))).rejects.toThrowError("Missing shopware-shop-signature header");
|
|
37
|
-
});
|
|
38
|
-
(0, bun_test_1.test)("fromSource: shop does not exists", async () => {
|
|
39
|
-
(0, bun_test_1.expect)(contextResolver.fromAPI(new Request("https://example.com/", {
|
|
40
|
-
headers: {
|
|
41
|
-
"shopware-shop-signature": "aaa",
|
|
42
|
-
},
|
|
43
|
-
body: JSON.stringify({
|
|
44
|
-
source: {
|
|
45
|
-
shopId: "test",
|
|
46
|
-
},
|
|
47
|
-
}),
|
|
48
|
-
}))).rejects.toThrowError("Cannot find shop by id test");
|
|
49
|
-
});
|
|
50
|
-
(0, bun_test_1.test)("fromSource: invalid signature", async () => {
|
|
51
|
-
(0, bun_test_1.expect)(contextResolver.fromAPI(new Request("https://example.com/", {
|
|
52
|
-
headers: {
|
|
53
|
-
"shopware-shop-signature": "aaa",
|
|
54
|
-
},
|
|
55
|
-
body: JSON.stringify({
|
|
56
|
-
source: {
|
|
57
|
-
shopId: "blaa",
|
|
58
|
-
},
|
|
59
|
-
}),
|
|
60
|
-
}))).rejects.toThrowError("Invalid signature");
|
|
61
|
-
});
|
|
62
|
-
(0, bun_test_1.test)("fromSource: resolved", async () => {
|
|
63
|
-
app.signer.verify = bun_test_1.jest.fn().mockResolvedValue(true);
|
|
64
|
-
const ctx = await contextResolver.fromAPI(new Request("https://example.com/", {
|
|
65
|
-
headers: {
|
|
66
|
-
"shopware-shop-signature": "aaa",
|
|
67
|
-
},
|
|
68
|
-
body: JSON.stringify({
|
|
69
|
-
source: {
|
|
70
|
-
shopId: "blaa",
|
|
71
|
-
},
|
|
72
|
-
}),
|
|
73
|
-
}));
|
|
74
|
-
(0, bun_test_1.expect)(ctx.payload).toEqual({
|
|
75
|
-
source: {
|
|
76
|
-
shopId: "blaa",
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
//# sourceMappingURL=context-resolver.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-resolver.test.js","sourceRoot":"","sources":["../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AC,sBAAsB,EAAE,KAAK,IAAI,EAAE;QACvC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,eAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAEtD,MAAM,GAAG,GAAG,MAAM,eAAe,CAAC,OAAO,CACxC,IAAI,OAAO,CAAC,sBAAsB,EAAE;YACnC,OAAO,EAAE;gBACR,yBAAyB,EAAE,KAAK;aAChC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACpB,MAAM,EAAE;oBACP,MAAM,EAAE,MAAM;iBACd;aACD,CAAC;SACF,CAAC,CACF,CAAC;QAEF,IAAA,iBAAM,EAAC,GAAG,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;YAC3B,MAAM,EAAE;gBACP,MAAM,EAAE,MAAM;aACd;SACD,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, jest, test } from \"bun:test\";\nimport { AppServer } from \"../src/app.js\";\nimport { ContextResolver } from \"../src/context-resolver.js\";\nimport { InMemoryShopRepository, SimpleShop } from \"../src/repository.js\";\n\ndescribe(\"Context Resolver\", async () => {\n\tconst app = new AppServer(\n\t\t{\n\t\t\tappName: \"test\",\n\t\t\tappSecret: \"test\",\n\t\t\tauthorizeCallbackUrl: \"test\",\n\t\t},\n\t\tnew InMemoryShopRepository(),\n\t);\n\n\tawait app.repository.createShop(\"blaa\", \"test\", \"test\");\n\n\tconst contextResolver = new ContextResolver(app);\n\n\ttest(\"fromBrowser: shop does not exist\", async () => {\n\t\texpect(\n\t\t\tcontextResolver.fromBrowser(\n\t\t\t\tnew Request(\n\t\t\t\t\t\"https://example.com/?shop-id=test&shopware-shop-signature=aaa\",\n\t\t\t\t),\n\t\t\t),\n\t\t).rejects.toThrowError(\"Cannot find shop by id test\");\n\t});\n\n\ttest(\"fromBrowser: missing header\", async () => {\n\t\texpect(\n\t\t\tcontextResolver.fromBrowser(\n\t\t\t\tnew Request(\"https://example.com/?shop-id=blaa\"),\n\t\t\t),\n\t\t).rejects.toThrowError(\"Missing shopware-shop-signature query parameter\");\n\t});\n\n\ttest(\"fromBrowser: shop exists\", async () => {\n\t\tapp.signer.verifyGetRequest = jest.fn().mockResolvedValue(true);\n\n\t\tconst context = await contextResolver.fromBrowser(\n\t\t\tnew Request(\n\t\t\t\t\"https://example.com/?shop-id=blaa&shopware-shop-signature=aaa\",\n\t\t\t),\n\t\t);\n\n\t\texpect(context.payload).toEqual({\n\t\t\t\"shop-id\": \"blaa\",\n\t\t\t\"shopware-shop-signature\": \"aaa\",\n\t\t});\n\t});\n\n\ttest(\"fromSource: missing signature header\", async () => {\n\t\texpect(\n\t\t\tcontextResolver.fromAPI(\n\t\t\t\tnew Request(\"https://example.com/\", {\n\t\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t\tsource: {\n\t\t\t\t\t\t\tshopId: \"blaa\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t),\n\t\t).rejects.toThrowError(\"Missing shopware-shop-signature header\");\n\t});\n\n\ttest(\"fromSource: shop does not exists\", async () => {\n\t\texpect(\n\t\t\tcontextResolver.fromAPI(\n\t\t\t\tnew Request(\"https://example.com/\", {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"shopware-shop-signature\": \"aaa\",\n\t\t\t\t\t},\n\t\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t\tsource: {\n\t\t\t\t\t\t\tshopId: \"test\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t),\n\t\t).rejects.toThrowError(\"Cannot find shop by id test\");\n\t});\n\n\ttest(\"fromSource: invalid signature\", async () => {\n\t\texpect(\n\t\t\tcontextResolver.fromAPI(\n\t\t\t\tnew Request(\"https://example.com/\", {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"shopware-shop-signature\": \"aaa\",\n\t\t\t\t\t},\n\t\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t\tsource: {\n\t\t\t\t\t\t\tshopId: \"blaa\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t),\n\t\t).rejects.toThrowError(\"Invalid signature\");\n\t});\n\n\ttest(\"fromSource: resolved\", async () => {\n\t\tapp.signer.verify = jest.fn().mockResolvedValue(true);\n\n\t\tconst ctx = await contextResolver.fromAPI(\n\t\t\tnew Request(\"https://example.com/\", {\n\t\t\t\theaders: {\n\t\t\t\t\t\"shopware-shop-signature\": \"aaa\",\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tsource: {\n\t\t\t\t\t\tshopId: \"blaa\",\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t}),\n\t\t);\n\n\t\texpect(ctx.payload).toEqual({\n\t\t\tsource: {\n\t\t\t\tshopId: \"blaa\",\n\t\t\t},\n\t\t});\n\t});\n});\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"app-actions.test.d.ts","sourceRoot":"","sources":["../../../src/helper/app-actions.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const bun_test_1 = require("bun:test");
|
|
4
|
-
const app_actions_js_1 = require("../../src/helper/app-actions.js");
|
|
5
|
-
(0, bun_test_1.describe)("AppActions", async () => {
|
|
6
|
-
(0, bun_test_1.test)("createNewTabResponse", async () => {
|
|
7
|
-
const resp = (0, app_actions_js_1.createNewTabResponse)("test");
|
|
8
|
-
(0, bun_test_1.expect)(resp.headers.get("content-type")).toBe("application/json");
|
|
9
|
-
(0, bun_test_1.expect)(await resp.text()).toBe(JSON.stringify({
|
|
10
|
-
actionType: "openNewTab",
|
|
11
|
-
payload: { redirectUrl: "test" },
|
|
12
|
-
}));
|
|
13
|
-
});
|
|
14
|
-
(0, bun_test_1.test)("createNotificationResponse", async () => {
|
|
15
|
-
const resp = (0, app_actions_js_1.createNotificationResponse)("success", "test");
|
|
16
|
-
(0, bun_test_1.expect)(resp.headers.get("content-type")).toBe("application/json");
|
|
17
|
-
(0, bun_test_1.expect)(await resp.text()).toBe(JSON.stringify({
|
|
18
|
-
actionType: "notification",
|
|
19
|
-
payload: { status: "success", message: "test" },
|
|
20
|
-
}));
|
|
21
|
-
});
|
|
22
|
-
(0, bun_test_1.test)("createModalResponse", async () => {
|
|
23
|
-
const resp = (0, app_actions_js_1.createModalResponse)("test", "small", true);
|
|
24
|
-
(0, bun_test_1.expect)(resp.headers.get("content-type")).toBe("application/json");
|
|
25
|
-
(0, bun_test_1.expect)(await resp.text()).toBe(JSON.stringify({
|
|
26
|
-
actionType: "openModal",
|
|
27
|
-
payload: { iframeUrl: "test", size: "small", expand: true },
|
|
28
|
-
}));
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
//# sourceMappingURL=app-actions.test.js.map
|