@shopware-ag/app-server-sdk 1.0.1 → 1.1.0

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.
Files changed (130) hide show
  1. package/README.md +52 -41
  2. package/dist/commonjs/context-resolver.test.d.ts +2 -0
  3. package/dist/commonjs/context-resolver.test.d.ts.map +1 -0
  4. package/dist/commonjs/context-resolver.test.js +81 -0
  5. package/dist/commonjs/context-resolver.test.js.map +1 -0
  6. package/dist/commonjs/helper/app-actions.test.d.ts +2 -0
  7. package/dist/commonjs/helper/app-actions.test.d.ts.map +1 -0
  8. package/dist/commonjs/helper/app-actions.test.js +31 -0
  9. package/dist/commonjs/helper/app-actions.test.js.map +1 -0
  10. package/dist/commonjs/http-client.test.d.ts +2 -0
  11. package/dist/commonjs/http-client.test.d.ts.map +1 -0
  12. package/dist/commonjs/http-client.test.js +71 -0
  13. package/dist/commonjs/http-client.test.js.map +1 -0
  14. package/dist/commonjs/integration/bun-sqlite.d.ts +11 -0
  15. package/dist/commonjs/integration/bun-sqlite.d.ts.map +1 -0
  16. package/dist/commonjs/integration/bun-sqlite.js +60 -0
  17. package/dist/commonjs/integration/bun-sqlite.js.map +1 -0
  18. package/dist/commonjs/integration/bun-sqlite.test.d.ts +2 -0
  19. package/dist/commonjs/integration/bun-sqlite.test.d.ts.map +1 -0
  20. package/dist/commonjs/integration/bun-sqlite.test.js +24 -0
  21. package/dist/commonjs/integration/bun-sqlite.test.js.map +1 -0
  22. package/dist/commonjs/integration/cloudflare-kv.d.ts +20 -0
  23. package/dist/commonjs/integration/cloudflare-kv.d.ts.map +1 -0
  24. package/dist/commonjs/integration/cloudflare-kv.js +49 -0
  25. package/dist/commonjs/integration/cloudflare-kv.js.map +1 -0
  26. package/dist/commonjs/integration/cloudflare.test.d.ts +2 -0
  27. package/dist/commonjs/integration/cloudflare.test.d.ts.map +1 -0
  28. package/dist/commonjs/integration/cloudflare.test.js +39 -0
  29. package/dist/commonjs/integration/cloudflare.test.js.map +1 -0
  30. package/dist/commonjs/integration/deno-kv.d.ts +18 -0
  31. package/dist/commonjs/integration/deno-kv.d.ts.map +1 -0
  32. package/dist/commonjs/integration/deno-kv.js +52 -0
  33. package/dist/commonjs/integration/deno-kv.js.map +1 -0
  34. package/dist/commonjs/integration/deno.test.d.ts +2 -0
  35. package/dist/commonjs/integration/deno.test.d.ts.map +1 -0
  36. package/dist/commonjs/integration/deno.test.js +48 -0
  37. package/dist/commonjs/integration/deno.test.js.map +1 -0
  38. package/dist/commonjs/integration/dynamodb.d.ts +13 -0
  39. package/dist/commonjs/integration/dynamodb.d.ts.map +1 -0
  40. package/dist/commonjs/integration/dynamodb.js +73 -0
  41. package/dist/commonjs/integration/dynamodb.js.map +1 -0
  42. package/dist/commonjs/integration/dynamodb.test.d.ts +2 -0
  43. package/dist/commonjs/integration/dynamodb.test.d.ts.map +1 -0
  44. package/dist/commonjs/integration/dynamodb.test.js +132 -0
  45. package/dist/commonjs/integration/dynamodb.test.js.map +1 -0
  46. package/dist/commonjs/integration/hono.d.ts +29 -0
  47. package/dist/commonjs/integration/hono.d.ts.map +1 -0
  48. package/dist/commonjs/integration/hono.js +105 -0
  49. package/dist/commonjs/integration/hono.js.map +1 -0
  50. package/dist/commonjs/integration/hono.test.d.ts +2 -0
  51. package/dist/commonjs/integration/hono.test.d.ts.map +1 -0
  52. package/dist/commonjs/integration/hono.test.js +86 -0
  53. package/dist/commonjs/integration/hono.test.js.map +1 -0
  54. package/dist/commonjs/registration.test.d.ts +2 -0
  55. package/dist/commonjs/registration.test.d.ts.map +1 -0
  56. package/dist/commonjs/registration.test.js +59 -0
  57. package/dist/commonjs/registration.test.js.map +1 -0
  58. package/dist/commonjs/repository.test.d.ts +2 -0
  59. package/dist/commonjs/repository.test.d.ts.map +1 -0
  60. package/dist/commonjs/repository.test.js +32 -0
  61. package/dist/commonjs/repository.test.js.map +1 -0
  62. package/dist/commonjs/signer.test.d.ts +2 -0
  63. package/dist/commonjs/signer.test.d.ts.map +1 -0
  64. package/dist/commonjs/signer.test.js +25 -0
  65. package/dist/commonjs/signer.test.js.map +1 -0
  66. package/dist/esm/context-resolver.test.d.ts +2 -0
  67. package/dist/esm/context-resolver.test.d.ts.map +1 -0
  68. package/dist/esm/context-resolver.test.js +79 -0
  69. package/dist/esm/context-resolver.test.js.map +1 -0
  70. package/dist/esm/helper/app-actions.test.d.ts +2 -0
  71. package/dist/esm/helper/app-actions.test.d.ts.map +1 -0
  72. package/dist/esm/helper/app-actions.test.js +29 -0
  73. package/dist/esm/helper/app-actions.test.js.map +1 -0
  74. package/dist/esm/http-client.test.d.ts +2 -0
  75. package/dist/esm/http-client.test.d.ts.map +1 -0
  76. package/dist/esm/http-client.test.js +69 -0
  77. package/dist/esm/http-client.test.js.map +1 -0
  78. package/dist/esm/integration/bun-sqlite.d.ts +11 -0
  79. package/dist/esm/integration/bun-sqlite.d.ts.map +1 -0
  80. package/dist/esm/integration/bun-sqlite.js +56 -0
  81. package/dist/esm/integration/bun-sqlite.js.map +1 -0
  82. package/dist/esm/integration/bun-sqlite.test.d.ts +2 -0
  83. package/dist/esm/integration/bun-sqlite.test.d.ts.map +1 -0
  84. package/dist/esm/integration/bun-sqlite.test.js +22 -0
  85. package/dist/esm/integration/bun-sqlite.test.js.map +1 -0
  86. package/dist/esm/integration/cloudflare-kv.d.ts +20 -0
  87. package/dist/esm/integration/cloudflare-kv.d.ts.map +1 -0
  88. package/dist/esm/integration/cloudflare-kv.js +45 -0
  89. package/dist/esm/integration/cloudflare-kv.js.map +1 -0
  90. package/dist/esm/integration/cloudflare.test.d.ts +2 -0
  91. package/dist/esm/integration/cloudflare.test.d.ts.map +1 -0
  92. package/dist/esm/integration/cloudflare.test.js +37 -0
  93. package/dist/esm/integration/cloudflare.test.js.map +1 -0
  94. package/dist/esm/integration/deno-kv.d.ts +18 -0
  95. package/dist/esm/integration/deno-kv.d.ts.map +1 -0
  96. package/dist/esm/integration/deno-kv.js +48 -0
  97. package/dist/esm/integration/deno-kv.js.map +1 -0
  98. package/dist/esm/integration/deno.test.d.ts +2 -0
  99. package/dist/esm/integration/deno.test.d.ts.map +1 -0
  100. package/dist/esm/integration/deno.test.js +46 -0
  101. package/dist/esm/integration/deno.test.js.map +1 -0
  102. package/dist/esm/integration/dynamodb.d.ts +13 -0
  103. package/dist/esm/integration/dynamodb.d.ts.map +1 -0
  104. package/dist/esm/integration/dynamodb.js +69 -0
  105. package/dist/esm/integration/dynamodb.js.map +1 -0
  106. package/dist/esm/integration/dynamodb.test.d.ts +2 -0
  107. package/dist/esm/integration/dynamodb.test.d.ts.map +1 -0
  108. package/dist/esm/integration/dynamodb.test.js +130 -0
  109. package/dist/esm/integration/dynamodb.test.js.map +1 -0
  110. package/dist/esm/integration/hono.d.ts +29 -0
  111. package/dist/esm/integration/hono.d.ts.map +1 -0
  112. package/dist/esm/integration/hono.js +102 -0
  113. package/dist/esm/integration/hono.js.map +1 -0
  114. package/dist/esm/integration/hono.test.d.ts +2 -0
  115. package/dist/esm/integration/hono.test.d.ts.map +1 -0
  116. package/dist/esm/integration/hono.test.js +84 -0
  117. package/dist/esm/integration/hono.test.js.map +1 -0
  118. package/dist/esm/registration.test.d.ts +2 -0
  119. package/dist/esm/registration.test.d.ts.map +1 -0
  120. package/dist/esm/registration.test.js +57 -0
  121. package/dist/esm/registration.test.js.map +1 -0
  122. package/dist/esm/repository.test.d.ts +2 -0
  123. package/dist/esm/repository.test.d.ts.map +1 -0
  124. package/dist/esm/repository.test.js +30 -0
  125. package/dist/esm/repository.test.js.map +1 -0
  126. package/dist/esm/signer.test.d.ts +2 -0
  127. package/dist/esm/signer.test.d.ts.map +1 -0
  128. package/dist/esm/signer.test.js +23 -0
  129. package/dist/esm/signer.test.js.map +1 -0
  130. package/package.json +142 -63
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bun-sqlite.js","sourceRoot":"","sources":["../../../src/integration/bun-sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,UAAU,EAAE,MA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QAElC,OAAO,IAAI,CAAC;IACb,CAAC;IACD,KAAK,CAAC,UAAU,CAAC,IAAgB;QAChC,IAAI,CAAC,EAAE,CAAC,IAAI,CACX,gGAAgG,EAChG;YACC,IAAI,CAAC,UAAU,EAAE;YACjB,IAAI,CAAC,aAAa,EAAE;YACpB,IAAI,CAAC,eAAe,EAAE;YACtB,IAAI,CAAC,mBAAmB,EAAE;YAC1B,IAAI,CAAC,aAAa,EAAE;YACpB,IAAI,CAAC,SAAS,EAAE;SAChB,CACD,CAAC;IACH,CAAC;IACD,KAAK,CAAC,UAAU,CAAC,EAAU;QAC1B,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,+BAA+B,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC;CACD","sourcesContent":["import { type ShopRepositoryInterface, SimpleShop } from \"../repository.js\";\n\nimport { Database } from \"bun:sqlite\";\n\nexport class BunSqliteRepository\n\timplements ShopRepositoryInterface<SimpleShop>\n{\n\tdb: Database;\n\tconstructor(fileName: string) {\n\t\tthis.db = new Database(fileName);\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.exec(\"INSERT INTO shop (id, url, secret) VALUES (?, ?, ?)\", [\n\t\t\tid,\n\t\t\turl,\n\t\t\tsecret,\n\t\t]);\n\t}\n\n\tasync getShopById(id: string): Promise<SimpleShop | null> {\n\t\tconst query = this.db.query<\n\t\t\t{\n\t\t\t\tid: string;\n\t\t\t\tactive: boolean;\n\t\t\t\turl: string;\n\t\t\t\tsecret: string;\n\t\t\t\tclient_id?: string;\n\t\t\t\tclient_secret?: string;\n\t\t\t},\n\t\t\tstring\n\t\t>(\"SELECT * FROM shop WHERE id = ?\");\n\t\tconst result = query.get(id);\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);\n\n\t\treturn shop;\n\t}\n\tasync updateShop(shop: SimpleShop): Promise<void> {\n\t\tthis.db.exec(\n\t\t\t\"UPDATE shop SET url = ?, secret = ?, client_id = ?, client_secret = ?, active = ? WHERE id = ?\",\n\t\t\t[\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\tshop.getShopActive(),\n\t\t\t\tshop.getShopId(),\n\t\t\t],\n\t\t);\n\t}\n\tasync deleteShop(id: string): Promise<void> {\n\t\tthis.db.exec(\"DELETE FROM shop where id = ?\", [id]);\n\t}\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=bun-sqlite.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bun-sqlite.test.d.ts","sourceRoot":"","sources":["../../../src/integration/bun-sqlite.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { SimpleShop } from "../repository.js";
3
+ import { BunSqliteRepository } from "./bun-sqlite.js";
4
+ describe("Bun SQLite", async () => {
5
+ test("createShop", async () => {
6
+ const repo = new BunSqliteRepository(":memory:");
7
+ await repo.createShop("test", "test", "test");
8
+ const shop = await repo.getShopById("test");
9
+ expect(shop).not.toBeNull();
10
+ expect(shop?.getShopId()).toBe("test");
11
+ expect(shop?.getShopUrl()).toBe("test");
12
+ expect(shop?.getShopSecret()).toBe("test");
13
+ await repo.deleteShop("test");
14
+ expect(repo.getShopById("test")).resolves.toBeNull();
15
+ await repo.createShop("test", "test", "test");
16
+ expect(repo.getShopById("test")).resolves.not.toBeNull();
17
+ await repo.updateShop(new SimpleShop("test", "foo.com", "test"));
18
+ const updatedShop = await repo.getShopById("test");
19
+ expect(updatedShop?.getShopUrl()).toBe("foo.com");
20
+ });
21
+ });
22
+ //# sourceMappingURL=bun-sqlite.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bun-sqlite.test.js","sourceRoot":"","sources":["../../../src/integration/bun-sqlite.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,QAAQ,CAAC,YAAY,EAAE,KAAK,IAAI,EAAE;IACjC,IAAI,CAAC,YAAY,EAAE,KAAK,IAAI,EAAE;QAC7B,MAAM,IAAI,GAAG,IAAI,mBAAmB,CAAC,UAAU,CAAC,CAAC;QAEjD,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAE9C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAE5C,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;QAE5B,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvC,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxC,MAAM,CAAC,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE3C,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAE9B,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAErD,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAE9C,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;QAEzD,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;QAEjE,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAEnD,MAAM,CAAC,WAAW,EAAE,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, test } from \"bun:test\";\nimport { SimpleShop } from \"../repository.js\";\nimport { BunSqliteRepository } from \"./bun-sqlite.js\";\n\ndescribe(\"Bun SQLite\", async () => {\n\ttest(\"createShop\", async () => {\n\t\tconst repo = new BunSqliteRepository(\":memory:\");\n\n\t\tawait repo.createShop(\"test\", \"test\", \"test\");\n\n\t\tconst shop = await repo.getShopById(\"test\");\n\n\t\texpect(shop).not.toBeNull();\n\n\t\texpect(shop?.getShopId()).toBe(\"test\");\n\t\texpect(shop?.getShopUrl()).toBe(\"test\");\n\t\texpect(shop?.getShopSecret()).toBe(\"test\");\n\n\t\tawait repo.deleteShop(\"test\");\n\n\t\texpect(repo.getShopById(\"test\")).resolves.toBeNull();\n\n\t\tawait repo.createShop(\"test\", \"test\", \"test\");\n\n\t\texpect(repo.getShopById(\"test\")).resolves.not.toBeNull();\n\n\t\tawait repo.updateShop(new SimpleShop(\"test\", \"foo.com\", \"test\"));\n\n\t\tconst updatedShop = await repo.getShopById(\"test\");\n\n\t\texpect(updatedShop?.getShopUrl()).toBe(\"foo.com\");\n\t});\n});\n"]}
@@ -0,0 +1,20 @@
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
+ //# sourceMappingURL=cloudflare-kv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare-kv.d.ts","sourceRoot":"","sources":["../../../src/integration/cloudflare-kv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAEhE;;;GAGG;AAEH;;GAEG;AACH,qBAAa,wBACZ,YAAW,uBAAuB,CAAC,UAAU,CAAC;IAElC,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,WAAW;IAIlC,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOlE,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrC,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAUnD,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjD,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM;IAIjD,SAAS,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU;CAmBnD"}
@@ -0,0 +1,45 @@
1
+ import { SimpleShop } from "../repository.js";
2
+ /**
3
+ * Cloudflare KV integration
4
+ * @module
5
+ */
6
+ /**
7
+ * Cloudflare KV implementation of the ShopRepositoryInterface
8
+ */
9
+ export class CloudflareShopRepository {
10
+ storage;
11
+ constructor(storage) {
12
+ this.storage = storage;
13
+ this.storage = storage;
14
+ }
15
+ async createShop(id, url, secret) {
16
+ await this.storage.put(id, this.serializeShop(new SimpleShop(id, url, secret)));
17
+ }
18
+ async deleteShop(id) {
19
+ await this.storage.delete(id);
20
+ }
21
+ async getShopById(id) {
22
+ const kvObj = await this.storage.get(id);
23
+ if (kvObj === null) {
24
+ return null;
25
+ }
26
+ return this.deserializeShop(kvObj);
27
+ }
28
+ async updateShop(shop) {
29
+ await this.storage.put(shop.getShopId(), this.serializeShop(shop));
30
+ }
31
+ serializeShop(shop) {
32
+ return JSON.stringify(shop);
33
+ }
34
+ deserializeShop(data) {
35
+ const obj = JSON.parse(data);
36
+ const shop = new SimpleShop(obj.shopId || "", obj.shopUrl || "", obj.shopSecret || "");
37
+ shop.setShopCredentials(obj.shopClientId || "", obj.shopClientSecret || "");
38
+ if (obj.shopActive === undefined) {
39
+ obj.shopActive = true;
40
+ }
41
+ shop.setShopActive(obj.shopActive);
42
+ return shop;
43
+ }
44
+ }
45
+ //# sourceMappingURL=cloudflare-kv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare-kv.js","sourceRoot":"","sources":["../../../src/integration/cloudflare-kv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C;;;GAGG;AAEH;;GAEG;AACH,MAAM,OAAO,wBAAwB;IAGhB;IAApB,YAAoB,OAAoB;QAApB,YAAO,GAAP,OAAO,CAAa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AE,EAAE,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC;QAE5E,IAAI,GAAG,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YAClC,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,CAAC;QAED,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAEnC,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["import { SimpleShop } from \"../repository.js\";\nimport type { 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\n\t\tif (obj.shopActive === undefined) {\n\t\t\tobj.shopActive = true;\n\t\t}\n\n\t\tshop.setShopActive(obj.shopActive);\n\n\t\treturn shop;\n\t}\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=cloudflare.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare.test.d.ts","sourceRoot":"","sources":["../../../src/integration/cloudflare.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,37 @@
1
+ //
2
+ import { describe, expect, test } from "bun:test";
3
+ import { CloudflareShopRepository } from "../../src/integration/cloudflare-kv.js";
4
+ import { SimpleShop } from "../../src/repository.js";
5
+ describe("Cloudflare", async () => {
6
+ test("createShop", async () => {
7
+ const repo = new CloudflareShopRepository(new MockedKVNamespace());
8
+ await repo.createShop("test", "test", "test");
9
+ const shop = await repo.getShopById("test");
10
+ expect(shop).not.toBeNull();
11
+ expect(shop?.getShopId()).toBe("test");
12
+ expect(shop?.getShopUrl()).toBe("test");
13
+ expect(shop?.getShopSecret()).toBe("test");
14
+ await repo.deleteShop("test");
15
+ expect(repo.getShopById("test")).resolves.toBeNull();
16
+ await repo.updateShop(new SimpleShop("test", "test", "test"));
17
+ expect(repo.getShopById("test")).resolves.not.toBeNull();
18
+ });
19
+ });
20
+ class MockedKVNamespace {
21
+ storage;
22
+ constructor() {
23
+ this.storage = new Map();
24
+ }
25
+ get(key, options) {
26
+ return Promise.resolve(this.storage.get(key) || null);
27
+ }
28
+ put(key, value, options) {
29
+ this.storage.set(key, value);
30
+ return Promise.resolve();
31
+ }
32
+ delete(key) {
33
+ this.storage.delete(key);
34
+ return Promise.resolve();
35
+ }
36
+ }
37
+ //# sourceMappingURL=cloudflare.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare.test.js","sourceRoot":"","sources":["../../../src/integration/cloudflare.test.ts"],"names":[],"mappings":"AAAA,EAAE;AACF,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD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OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;IAC1B,CAAC;IAED,GAAG,CACF,GAAW,EACX,OAAmD;QAEnD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC;IACvD,CAAC;IACD,GAAG,CACF,GAAW,EACX,KAA8D,EAC9D,OAA+B;QAE/B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAe,CAAC,CAAC;QACvC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;IACD,MAAM,CAAC,GAAW;QACjB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACzB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;CACD","sourcesContent":["//\nimport { describe, expect, test } from \"bun:test\";\nimport { CloudflareShopRepository } from \"../../src/integration/cloudflare-kv.js\";\nimport { SimpleShop } from \"../../src/repository.js\";\n\ndescribe(\"Cloudflare\", async () => {\n\ttest(\"createShop\", async () => {\n\t\tconst repo = new CloudflareShopRepository(\n\t\t\tnew MockedKVNamespace() as unknown as KVNamespace,\n\t\t);\n\n\t\tawait repo.createShop(\"test\", \"test\", \"test\");\n\n\t\tconst shop = await repo.getShopById(\"test\");\n\n\t\texpect(shop).not.toBeNull();\n\n\t\texpect(shop?.getShopId()).toBe(\"test\");\n\t\texpect(shop?.getShopUrl()).toBe(\"test\");\n\t\texpect(shop?.getShopSecret()).toBe(\"test\");\n\n\t\tawait repo.deleteShop(\"test\");\n\n\t\texpect(repo.getShopById(\"test\")).resolves.toBeNull();\n\n\t\tawait repo.updateShop(new SimpleShop(\"test\", \"test\", \"test\"));\n\n\t\texpect(repo.getShopById(\"test\")).resolves.not.toBeNull();\n\t});\n});\n\nclass MockedKVNamespace {\n\tstorage: Map<string, string>;\n\tconstructor() {\n\t\tthis.storage = new Map();\n\t}\n\n\tget(\n\t\tkey: string,\n\t\toptions?: Partial<KVNamespaceGetOptions<undefined>>,\n\t): Promise<string | null> {\n\t\treturn Promise.resolve(this.storage.get(key) || null);\n\t}\n\tput(\n\t\tkey: string,\n\t\tvalue: string | ArrayBuffer | ArrayBufferView | ReadableStream,\n\t\toptions?: KVNamespacePutOptions,\n\t): Promise<void> {\n\t\tthis.storage.set(key, value as string);\n\t\treturn Promise.resolve();\n\t}\n\tdelete(key: string): Promise<void> {\n\t\tthis.storage.delete(key);\n\t\treturn Promise.resolve();\n\t}\n}\n"]}
@@ -0,0 +1,18 @@
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-kv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deno-kv.d.ts","sourceRoot":"","sources":["../../../src/integration/deno-kv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAEhE;;;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;IAiCnD,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAO3C,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAM3C"}
@@ -0,0 +1,48 @@
1
+ import { SimpleShop } from "../repository.js";
2
+ /**
3
+ * Deno KV integration
4
+ * @module
5
+ */
6
+ /**
7
+ * DenoKVRepository is a ShopRepositoryInterface implementation that uses the Deno KV storage to save the shop data
8
+ */
9
+ export class DenoKVRepository {
10
+ namespace;
11
+ constructor(namespace = "shops") {
12
+ this.namespace = namespace;
13
+ }
14
+ async createShop(id, url, secret) {
15
+ // @ts-ignore
16
+ const kv = await Deno.openKv();
17
+ await kv.set([this.namespace, id], new SimpleShop(id, url, secret));
18
+ }
19
+ async getShopById(id) {
20
+ // @ts-ignore
21
+ const kv = await Deno.openKv();
22
+ const result = await kv.get([this.namespace, id]);
23
+ if (result.key === null) {
24
+ return null;
25
+ }
26
+ const data = result.value;
27
+ if (data.shopActive === undefined) {
28
+ data.shopActive = true;
29
+ }
30
+ const shop = new SimpleShop(data.shopId, data.shopUrl, data.shopSecret);
31
+ shop.setShopActive(data.shopActive);
32
+ if (data.shopClientId && data.shopClientSecret) {
33
+ shop.setShopCredentials(data.shopClientId, data.shopClientSecret);
34
+ }
35
+ return shop;
36
+ }
37
+ async updateShop(shop) {
38
+ // @ts-ignore
39
+ const kv = await Deno.openKv();
40
+ await kv.set([this.namespace, shop.getShopId()], shop);
41
+ }
42
+ async deleteShop(id) {
43
+ // @ts-ignore
44
+ const kv = await Deno.openKv();
45
+ await kv.delete([this.namespace, id]);
46
+ }
47
+ }
48
+ //# sourceMappingURL=deno-kv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deno-kv.js","sourceRoot":"","sources":["../../../src/integration/deno-kv.ts"],"names":[],"mappings":"AAA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EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACnE,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,IAAgB;QAChC,aAAa;QACb,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QAE/B,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QAC1B,aAAa;QACb,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QAE/B,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;IACvC,CAAC;CACD","sourcesContent":["import { SimpleShop } from \"../repository.js\";\nimport type { 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\tshopActive: boolean | undefined;\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\tif (data.shopActive === undefined) {\n\t\t\tdata.shopActive = true;\n\t\t}\n\n\t\tconst shop = new SimpleShop(data.shopId, data.shopUrl, data.shopSecret);\n\t\tshop.setShopActive(data.shopActive);\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"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=deno.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deno.test.d.ts","sourceRoot":"","sources":["../../../src/integration/deno.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,46 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { SimpleShop } from "../repository.js";
3
+ import { DenoKVRepository } from "./deno-kv.js";
4
+ describe("Deno", async () => {
5
+ const kv = {
6
+ storage: new Map(),
7
+ set(key, value) {
8
+ this.storage.set(key.join(""), value);
9
+ },
10
+ get(key) {
11
+ if (!this.storage.has(key.join(""))) {
12
+ return {
13
+ key: null,
14
+ value: null,
15
+ };
16
+ }
17
+ return Promise.resolve({
18
+ key: key.join(""),
19
+ value: this.storage.get(key.join("")),
20
+ });
21
+ },
22
+ delete(key) {
23
+ this.storage.delete(key.join(""));
24
+ },
25
+ };
26
+ // @ts-ignore
27
+ globalThis.Deno = {
28
+ openKv() {
29
+ return Promise.resolve(kv);
30
+ },
31
+ };
32
+ test("test repository", async () => {
33
+ const repo = new DenoKVRepository();
34
+ await repo.createShop("test", "test", "test");
35
+ const shop = await repo.getShopById("test");
36
+ expect(shop).not.toBeNull();
37
+ expect(shop?.getShopId()).toBe("test");
38
+ expect(shop?.getShopUrl()).toBe("test");
39
+ expect(shop?.getShopSecret()).toBe("test");
40
+ await repo.deleteShop("test");
41
+ expect(repo.getShopById("test")).resolves.toBeNull();
42
+ await repo.updateShop(new SimpleShop("test", "test", "test"));
43
+ expect(repo.getShopById("test")).resolves.not.toBeNull();
44
+ });
45
+ });
46
+ //# sourceMappingURL=deno.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deno.test.js","sourceRoot":"","sources":["../../../src/integration/deno.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,QAAQ,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE;IAC3B,MAAM,EAAE,GAAG;QACV,OAAO,EAAE,IAAI,GAAG,EAAE;QAClB,GAAG,CAAC,GAAa,EAAE,KAAa;YAC/B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;QACvC,CAAC;QAED,GAAG,CAAC,GAAa;YAChB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;gBACrC,OAAO;oBACN,GAAG,EAAE,IAAI;oBACT,KAAK,EAAE,IAAI;iBACX,CAAC;YACH,CAAC;YAED,OAAO,OAAO,CAAC,OAAO,CAAC;gBACtB,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACjB,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;aACrC,CAAC,CAAC;QACJ,CAAC;QAED,MAAM,CAAC,GAA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C,CAAC","sourcesContent":["import { describe, expect, test } from \"bun:test\";\nimport { SimpleShop } from \"../repository.js\";\nimport { DenoKVRepository } from \"./deno-kv.js\";\n\ndescribe(\"Deno\", async () => {\n\tconst kv = {\n\t\tstorage: new Map(),\n\t\tset(key: string[], value: string) {\n\t\t\tthis.storage.set(key.join(\"\"), value);\n\t\t},\n\n\t\tget(key: string[]) {\n\t\t\tif (!this.storage.has(key.join(\"\"))) {\n\t\t\t\treturn {\n\t\t\t\t\tkey: null,\n\t\t\t\t\tvalue: null,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn Promise.resolve({\n\t\t\t\tkey: key.join(\"\"),\n\t\t\t\tvalue: this.storage.get(key.join(\"\")),\n\t\t\t});\n\t\t},\n\n\t\tdelete(key: string[]) {\n\t\t\tthis.storage.delete(key.join(\"\"));\n\t\t},\n\t};\n\n\t// @ts-ignore\n\tglobalThis.Deno = {\n\t\topenKv() {\n\t\t\treturn Promise.resolve(kv);\n\t\t},\n\t};\n\n\ttest(\"test repository\", async () => {\n\t\tconst repo = new DenoKVRepository();\n\n\t\tawait repo.createShop(\"test\", \"test\", \"test\");\n\n\t\tconst shop = await repo.getShopById(\"test\");\n\n\t\texpect(shop).not.toBeNull();\n\n\t\texpect(shop?.getShopId()).toBe(\"test\");\n\t\texpect(shop?.getShopUrl()).toBe(\"test\");\n\t\texpect(shop?.getShopSecret()).toBe(\"test\");\n\n\t\tawait repo.deleteShop(\"test\");\n\n\t\texpect(repo.getShopById(\"test\")).resolves.toBeNull();\n\n\t\tawait repo.updateShop(new SimpleShop(\"test\", \"test\", \"test\"));\n\n\t\texpect(repo.getShopById(\"test\")).resolves.not.toBeNull();\n\t});\n});\n"]}
@@ -0,0 +1,13 @@
1
+ import type { DynamoDBClient } from "@aws-sdk/client-dynamodb";
2
+ import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
3
+ import { type ShopRepositoryInterface, SimpleShop } from "../repository.js";
4
+ export declare class DynamoDBRepository implements ShopRepositoryInterface<SimpleShop> {
5
+ docClient: DynamoDBDocumentClient;
6
+ tableName: string;
7
+ constructor(client: DynamoDBClient, tableName: string);
8
+ createShop(id: string, url: string, secret: string): Promise<void>;
9
+ getShopById(id: string): Promise<SimpleShop | null>;
10
+ updateShop(shop: SimpleShop): Promise<void>;
11
+ deleteShop(id: string): Promise<void>;
12
+ }
13
+ //# sourceMappingURL=dynamodb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamodb.d.ts","sourceRoot":"","sources":["../../../src/integration/dynamodb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAEN,sBAAsB,EAGtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,uBAAuB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE5E,qBAAa,kBAAmB,YAAW,uBAAuB,CAAC,UAAU,CAAC;IAC7E,SAAS,EAAE,sBAAsB,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;gBAEN,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM;IAK/C,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBlE,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAoCnD,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB3C,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAU3C"}
@@ -0,0 +1,69 @@
1
+ import { DeleteCommand, DynamoDBDocumentClient, GetCommand, PutCommand, } from "@aws-sdk/lib-dynamodb";
2
+ import { SimpleShop } from "../repository.js";
3
+ export class DynamoDBRepository {
4
+ docClient;
5
+ tableName;
6
+ constructor(client, tableName) {
7
+ this.tableName = tableName;
8
+ this.docClient = DynamoDBDocumentClient.from(client);
9
+ }
10
+ async createShop(id, url, secret) {
11
+ const cmd = new PutCommand({
12
+ TableName: this.tableName,
13
+ Item: {
14
+ id: id,
15
+ active: true,
16
+ url: url,
17
+ secret: secret,
18
+ clientId: null,
19
+ clientSecret: null,
20
+ },
21
+ });
22
+ await this.docClient.send(cmd);
23
+ }
24
+ async getShopById(id) {
25
+ const cmd = new GetCommand({
26
+ TableName: this.tableName,
27
+ Key: {
28
+ id: id,
29
+ },
30
+ });
31
+ const response = await this.docClient.send(cmd);
32
+ if (!response.Item) {
33
+ return null;
34
+ }
35
+ const shop = new SimpleShop(response.Item.id, response.Item.url, response.Item.secret);
36
+ if (response.Item.active === undefined) {
37
+ response.Item.active = true;
38
+ }
39
+ shop.setShopActive(response.Item.active);
40
+ if (response.Item.clientId) {
41
+ shop.setShopCredentials(response.Item.clientId, response.Item.clientSecret);
42
+ }
43
+ return shop;
44
+ }
45
+ async updateShop(shop) {
46
+ const cmd = new PutCommand({
47
+ TableName: this.tableName,
48
+ Item: {
49
+ id: shop.getShopId(),
50
+ active: shop.getShopActive(),
51
+ url: shop.getShopUrl(),
52
+ secret: shop.getShopSecret(),
53
+ clientId: shop.getShopClientId(),
54
+ clientSecret: shop.getShopClientSecret(),
55
+ },
56
+ });
57
+ await this.docClient.send(cmd);
58
+ }
59
+ async deleteShop(id) {
60
+ const cmd = new DeleteCommand({
61
+ TableName: this.tableName,
62
+ Key: {
63
+ id: id,
64
+ },
65
+ });
66
+ await this.docClient.send(cmd);
67
+ }
68
+ }
69
+ //# sourceMappingURL=dynamodb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamodb.js","sourceRoot":"","sources":["../../../src/integration/dynamodb.ts"],"names":[],"mappings":"AACA,OAAO,EACN,aAAa,EACb,sBAAsB,EACtB,UAAU,EACV,UAAU,GACV,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAgC,UAAU,EAAE,MAAM,k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from \"@aws-sdk/lib-dynamodb\";\nimport { type ShopRepositoryInterface, SimpleShop } from \"../repository.js\";\n\nexport class DynamoDBRepository implements ShopRepositoryInterface<SimpleShop> {\n\tdocClient: DynamoDBDocumentClient;\n\ttableName: string;\n\n\tconstructor(client: DynamoDBClient, tableName: string) {\n\t\tthis.tableName = tableName;\n\t\tthis.docClient = DynamoDBDocumentClient.from(client);\n\t}\n\n\tasync createShop(id: string, url: string, secret: string): Promise<void> {\n\t\tconst cmd = new PutCommand({\n\t\t\tTableName: this.tableName,\n\t\t\tItem: {\n\t\t\t\tid: id,\n\t\t\t\tactive: true,\n\t\t\t\turl: url,\n\t\t\t\tsecret: secret,\n\t\t\t\tclientId: null,\n\t\t\t\tclientSecret: null,\n\t\t\t},\n\t\t});\n\n\t\tawait this.docClient.send(cmd);\n\t}\n\n\tasync getShopById(id: string): Promise<SimpleShop | null> {\n\t\tconst cmd = new GetCommand({\n\t\t\tTableName: this.tableName,\n\t\t\tKey: {\n\t\t\t\tid: id,\n\t\t\t},\n\t\t});\n\n\t\tconst response = await this.docClient.send(cmd);\n\n\t\tif (!response.Item) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst shop = new SimpleShop(\n\t\t\tresponse.Item.id,\n\t\t\tresponse.Item.url,\n\t\t\tresponse.Item.secret,\n\t\t);\n\n\t\tif (response.Item.active === undefined) {\n\t\t\tresponse.Item.active = true;\n\t\t}\n\n\t\tshop.setShopActive(response.Item.active);\n\n\t\tif (response.Item.clientId) {\n\t\t\tshop.setShopCredentials(\n\t\t\t\tresponse.Item.clientId,\n\t\t\t\tresponse.Item.clientSecret,\n\t\t\t);\n\t\t}\n\n\t\treturn shop;\n\t}\n\n\tasync updateShop(shop: SimpleShop): Promise<void> {\n\t\tconst cmd = new PutCommand({\n\t\t\tTableName: this.tableName,\n\t\t\tItem: {\n\t\t\t\tid: shop.getShopId(),\n\t\t\t\tactive: shop.getShopActive(),\n\t\t\t\turl: shop.getShopUrl(),\n\t\t\t\tsecret: shop.getShopSecret(),\n\t\t\t\tclientId: shop.getShopClientId(),\n\t\t\t\tclientSecret: shop.getShopClientSecret(),\n\t\t\t},\n\t\t});\n\n\t\tawait this.docClient.send(cmd);\n\t}\n\n\tasync deleteShop(id: string): Promise<void> {\n\t\tconst cmd = new DeleteCommand({\n\t\t\tTableName: this.tableName,\n\t\t\tKey: {\n\t\t\t\tid: id,\n\t\t\t},\n\t\t});\n\n\t\tawait this.docClient.send(cmd);\n\t}\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=dynamodb.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamodb.test.d.ts","sourceRoot":"","sources":["../../../src/integration/dynamodb.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,130 @@
1
+ import { describe, expect, mock, test } from "bun:test";
2
+ import { DynamoDBRepository } from "./dynamodb.js";
3
+ import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
4
+ import { SimpleShop } from "../repository.js";
5
+ describe("DynamoDB", async () => {
6
+ test("getShopById does not exists", async () => {
7
+ mock.module("@aws-sdk/lib-dynamodb", () => {
8
+ return {
9
+ DynamoDBDocumentClient: {
10
+ from() {
11
+ return {
12
+ async send() {
13
+ return {};
14
+ },
15
+ };
16
+ },
17
+ },
18
+ };
19
+ });
20
+ const repo = new DynamoDBRepository(new DynamoDBClient(), "foo");
21
+ expect(repo.getShopById("test")).resolves.toBeNull();
22
+ });
23
+ test("getShopById exists", async () => {
24
+ mock.module("@aws-sdk/lib-dynamodb", () => {
25
+ return {
26
+ DynamoDBDocumentClient: {
27
+ from() {
28
+ return {
29
+ async send() {
30
+ return {
31
+ Item: {
32
+ id: "a",
33
+ url: "b",
34
+ secret: "c",
35
+ },
36
+ };
37
+ },
38
+ };
39
+ },
40
+ },
41
+ };
42
+ });
43
+ const repo = new DynamoDBRepository(new DynamoDBClient(), "foo");
44
+ expect(repo.getShopById("test")).resolves.not.toBeNull();
45
+ });
46
+ test("createShop", async () => {
47
+ let cmd;
48
+ mock.module("@aws-sdk/lib-dynamodb", () => {
49
+ return {
50
+ DynamoDBDocumentClient: {
51
+ from() {
52
+ return {
53
+ async send(inner) {
54
+ cmd = inner;
55
+ return {};
56
+ },
57
+ };
58
+ },
59
+ },
60
+ };
61
+ });
62
+ const repo = new DynamoDBRepository(new DynamoDBClient(), "foo");
63
+ await repo.createShop("a", "b", "c");
64
+ // @ts-expect-error
65
+ expect(cmd).toBeDefined();
66
+ // @ts-expect-error
67
+ expect(cmd.input.Item).toEqual({
68
+ id: "a",
69
+ active: true,
70
+ url: "b",
71
+ secret: "c",
72
+ clientId: null,
73
+ clientSecret: null,
74
+ });
75
+ });
76
+ test("updateShop", async () => {
77
+ let cmd;
78
+ mock.module("@aws-sdk/lib-dynamodb", () => {
79
+ return {
80
+ DynamoDBDocumentClient: {
81
+ from() {
82
+ return {
83
+ async send(inner) {
84
+ cmd = inner;
85
+ return {};
86
+ },
87
+ };
88
+ },
89
+ },
90
+ };
91
+ });
92
+ const repo = new DynamoDBRepository(new DynamoDBClient(), "foo");
93
+ await repo.updateShop(new SimpleShop("a", "b", "c"));
94
+ // @ts-expect-error
95
+ expect(cmd).toBeDefined();
96
+ // @ts-expect-error
97
+ expect(cmd.input.Item).toEqual({
98
+ id: "a",
99
+ active: true,
100
+ url: "b",
101
+ secret: "c",
102
+ clientId: null,
103
+ clientSecret: null,
104
+ });
105
+ });
106
+ test("deleteShop", async () => {
107
+ let cmd;
108
+ mock.module("@aws-sdk/lib-dynamodb", () => {
109
+ return {
110
+ DynamoDBDocumentClient: {
111
+ from() {
112
+ return {
113
+ async send(inner) {
114
+ cmd = inner;
115
+ return {};
116
+ },
117
+ };
118
+ },
119
+ },
120
+ };
121
+ });
122
+ const repo = new DynamoDBRepository(new DynamoDBClient(), "foo");
123
+ await repo.deleteShop("a");
124
+ // @ts-expect-error
125
+ expect(cmd).toBeDefined();
126
+ // @ts-expect-error
127
+ expect(cmd.input.Key).toEqual({ id: "a" });
128
+ });
129
+ });
130
+ //# sourceMappingURL=dynamodb.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamodb.test.js","sourceRoot":"","sources":["../../../src/integration/dynamodb.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,QAAQ,CAAC,UAAU,EAAE,KAAK,IAAI,EAAE;IAC/B,IAAI,CAAC,6BAA6B,EAAE,KAAK,IAAI,EAAE;QAC9C,IAAI,CAAC,MAAM,CAAC,uBAAuB,EAAE,GAAG,EAAE;YACzC,OAAO;gBACN,sBAAsB,EAAE;oBACvB,IAAI;wBACH,OAAO;4BACN,KAAK,CAAC,IAAI;gCACT,OAAO,EAAE,CAAC;4BACX,CAAC;yBACD,CAAC;oBACH,CAAC;iBACD;aACD,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,IAAI,kBAAkB,CAAC,IAAI,cAAc,EAAE,EAAE,KAAK,CAAC,CAAC;QAEjE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,oBAAoB,EAAE,KAAK,IAAI,EAAE;QACrC,IAAI,CAAC,MAAM,CAAC,uBAAuB,EAAE,GAAG,EAAE;YACzC,OAAO;gBACN,sBAAsB,EAAE;oBACvB,IAAI;wBACH,OAAO;4BACN,KAAK,CAAC,IAAI;gCACT,OAAO;oCACN,IAAI,EAAE;wCACL,EAAE,EAAE,GAAG;wCACP,GAAG,EAAE,GAAG;wCACR,MAAM,EAAE,GAAG;q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kBAAkB,CAAC,IAAI,cAAc,EAAE,EAAE,KAAK,CAAC,CAAC;QAEjE,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAE3B,mBAAmB;QACnB,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;QAC1B,mBAAmB;QACnB,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, mock, test } from \"bun:test\";\nimport { DynamoDBRepository } from \"./dynamodb.js\";\n\nimport { DynamoDBClient } from \"@aws-sdk/client-dynamodb\";\nimport type { DeleteCommand, PutCommand } from \"@aws-sdk/lib-dynamodb\";\nimport { SimpleShop } from \"../repository.js\";\n\ndescribe(\"DynamoDB\", async () => {\n\ttest(\"getShopById does not exists\", async () => {\n\t\tmock.module(\"@aws-sdk/lib-dynamodb\", () => {\n\t\t\treturn {\n\t\t\t\tDynamoDBDocumentClient: {\n\t\t\t\t\tfrom() {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tasync send() {\n\t\t\t\t\t\t\t\treturn {};\n\t\t\t\t\t\t\t},\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});\n\n\t\tconst repo = new DynamoDBRepository(new DynamoDBClient(), \"foo\");\n\n\t\texpect(repo.getShopById(\"test\")).resolves.toBeNull();\n\t});\n\n\ttest(\"getShopById exists\", async () => {\n\t\tmock.module(\"@aws-sdk/lib-dynamodb\", () => {\n\t\t\treturn {\n\t\t\t\tDynamoDBDocumentClient: {\n\t\t\t\t\tfrom() {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tasync send() {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tItem: {\n\t\t\t\t\t\t\t\t\t\tid: \"a\",\n\t\t\t\t\t\t\t\t\t\turl: \"b\",\n\t\t\t\t\t\t\t\t\t\tsecret: \"c\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t},\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});\n\n\t\tconst repo = new DynamoDBRepository(new DynamoDBClient(), \"foo\");\n\n\t\texpect(repo.getShopById(\"test\")).resolves.not.toBeNull();\n\t});\n\n\ttest(\"createShop\", async () => {\n\t\tlet cmd: PutCommand;\n\n\t\tmock.module(\"@aws-sdk/lib-dynamodb\", () => {\n\t\t\treturn {\n\t\t\t\tDynamoDBDocumentClient: {\n\t\t\t\t\tfrom() {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tasync send(inner: PutCommand) {\n\t\t\t\t\t\t\t\tcmd = inner;\n\t\t\t\t\t\t\t\treturn {};\n\t\t\t\t\t\t\t},\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});\n\n\t\tconst repo = new DynamoDBRepository(new DynamoDBClient(), \"foo\");\n\n\t\tawait repo.createShop(\"a\", \"b\", \"c\");\n\n\t\t// @ts-expect-error\n\t\texpect(cmd).toBeDefined();\n\t\t// @ts-expect-error\n\t\texpect(cmd.input.Item).toEqual({\n\t\t\tid: \"a\",\n\t\t\tactive: true,\n\t\t\turl: \"b\",\n\t\t\tsecret: \"c\",\n\t\t\tclientId: null,\n\t\t\tclientSecret: null,\n\t\t});\n\t});\n\n\ttest(\"updateShop\", async () => {\n\t\tlet cmd: PutCommand;\n\n\t\tmock.module(\"@aws-sdk/lib-dynamodb\", () => {\n\t\t\treturn {\n\t\t\t\tDynamoDBDocumentClient: {\n\t\t\t\t\tfrom() {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tasync send(inner: PutCommand) {\n\t\t\t\t\t\t\t\tcmd = inner;\n\t\t\t\t\t\t\t\treturn {};\n\t\t\t\t\t\t\t},\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});\n\n\t\tconst repo = new DynamoDBRepository(new DynamoDBClient(), \"foo\");\n\n\t\tawait repo.updateShop(new SimpleShop(\"a\", \"b\", \"c\"));\n\n\t\t// @ts-expect-error\n\t\texpect(cmd).toBeDefined();\n\t\t// @ts-expect-error\n\t\texpect(cmd.input.Item).toEqual({\n\t\t\tid: \"a\",\n\t\t\tactive: true,\n\t\t\turl: \"b\",\n\t\t\tsecret: \"c\",\n\t\t\tclientId: null,\n\t\t\tclientSecret: null,\n\t\t});\n\t});\n\n\ttest(\"deleteShop\", async () => {\n\t\tlet cmd: DeleteCommand;\n\n\t\tmock.module(\"@aws-sdk/lib-dynamodb\", () => {\n\t\t\treturn {\n\t\t\t\tDynamoDBDocumentClient: {\n\t\t\t\t\tfrom() {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tasync send(inner: DeleteCommand) {\n\t\t\t\t\t\t\t\tcmd = inner;\n\t\t\t\t\t\t\t\treturn {};\n\t\t\t\t\t\t\t},\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});\n\n\t\tconst repo = new DynamoDBRepository(new DynamoDBClient(), \"foo\");\n\n\t\tawait repo.deleteShop(\"a\");\n\n\t\t// @ts-expect-error\n\t\texpect(cmd).toBeDefined();\n\t\t// @ts-expect-error\n\t\texpect(cmd.input.Key).toEqual({ id: \"a\" });\n\t});\n});\n"]}
@@ -0,0 +1,29 @@
1
+ import { AppServer } from "../app.js";
2
+ import type { Context } from "../context-resolver.js";
3
+ import type { ShopInterface, ShopRepositoryInterface } from "../repository.js";
4
+ import type { Hono, Context as HonoContext } from "hono";
5
+ declare module "hono" {
6
+ interface ContextVariableMap {
7
+ app: AppServer<ShopInterface>;
8
+ shop: ShopInterface;
9
+ context: Context<ShopInterface, unknown>;
10
+ }
11
+ }
12
+ interface MiddlewareConfig {
13
+ appName: string | ((c: HonoContext) => string);
14
+ appSecret: string | ((c: HonoContext) => string);
15
+ appUrl?: string | null;
16
+ registrationUrl?: string | null;
17
+ registerConfirmationUrl?: string | null;
18
+ appActivateUrl?: string | null;
19
+ appDeactivateUrl?: string | null;
20
+ appDeleteUrl?: string | null;
21
+ appPath?: string | null;
22
+ shopRepository: ShopRepositoryInterface | ((c: HonoContext) => ShopRepositoryInterface);
23
+ }
24
+ /**
25
+ * Configure the Hono server to handle the app registration and context resolution
26
+ */
27
+ export declare function configureAppServer(hono: Hono, cfg: MiddlewareConfig): void;
28
+ export {};
29
+ //# sourceMappingURL=hono.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hono.d.ts","sourceRoot":"","sources":["../../../src/integration/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,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,MAAM,CAAC;AAEzD,OAAO,QAAQ,MAAM,CAAC;IACrB,UAAU,kBAAkB;QAE3B,GAAG,EAAE,SAAS,CAAC,aAAa,CAAC,CAAC;QAC9B,IAAI,EAAE,aAAa,CAAC;QAEpB,OAAO,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;KACzC;CACD;AAED,UAAU,gBAAgB;IACzB,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,WAAW,KAAK,MAAM,CAAC,CAAC;IAC/C,SAAS,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,WAAW,KAAK,MAAM,CAAC,CAAC;IACjD,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC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