@shopware-ag/app-server-sdk 1.0.0 → 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 (210) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +23 -4
  3. package/dist/commonjs/context-resolver.test.d.ts +2 -0
  4. package/dist/commonjs/context-resolver.test.d.ts.map +1 -0
  5. package/dist/commonjs/context-resolver.test.js +81 -0
  6. package/dist/commonjs/context-resolver.test.js.map +1 -0
  7. package/dist/commonjs/helper/app-actions.test.d.ts +2 -0
  8. package/dist/commonjs/helper/app-actions.test.d.ts.map +1 -0
  9. package/dist/commonjs/helper/app-actions.test.js +31 -0
  10. package/dist/commonjs/helper/app-actions.test.js.map +1 -0
  11. package/dist/commonjs/http-client.test.d.ts +2 -0
  12. package/dist/commonjs/http-client.test.d.ts.map +1 -0
  13. package/dist/commonjs/http-client.test.js +71 -0
  14. package/dist/commonjs/http-client.test.js.map +1 -0
  15. package/dist/commonjs/integration/bun-sqlite.d.ts +11 -0
  16. package/dist/commonjs/integration/bun-sqlite.d.ts.map +1 -0
  17. package/dist/commonjs/integration/bun-sqlite.js +60 -0
  18. package/dist/commonjs/integration/bun-sqlite.js.map +1 -0
  19. package/dist/commonjs/integration/bun-sqlite.test.d.ts +2 -0
  20. package/dist/commonjs/integration/bun-sqlite.test.d.ts.map +1 -0
  21. package/dist/commonjs/integration/bun-sqlite.test.js +24 -0
  22. package/dist/commonjs/integration/bun-sqlite.test.js.map +1 -0
  23. package/dist/{deno/service/cloudflare.d.ts → commonjs/integration/cloudflare-kv.d.ts} +1 -24
  24. package/dist/commonjs/integration/cloudflare-kv.d.ts.map +1 -0
  25. package/dist/commonjs/{service/cloudflare.js → integration/cloudflare-kv.js} +5 -1
  26. package/dist/commonjs/integration/cloudflare-kv.js.map +1 -0
  27. package/dist/commonjs/integration/cloudflare.test.d.ts +2 -0
  28. package/dist/commonjs/integration/cloudflare.test.d.ts.map +1 -0
  29. package/dist/commonjs/integration/cloudflare.test.js +39 -0
  30. package/dist/commonjs/integration/cloudflare.test.js.map +1 -0
  31. package/dist/{esm/service/deno.d.ts → commonjs/integration/deno-kv.d.ts} +1 -1
  32. package/dist/commonjs/integration/deno-kv.d.ts.map +1 -0
  33. package/dist/commonjs/{service/deno.js → integration/deno-kv.js} +5 -1
  34. package/dist/commonjs/integration/deno-kv.js.map +1 -0
  35. package/dist/commonjs/integration/deno.test.d.ts +2 -0
  36. package/dist/commonjs/integration/deno.test.d.ts.map +1 -0
  37. package/dist/commonjs/integration/deno.test.js +48 -0
  38. package/dist/commonjs/integration/deno.test.js.map +1 -0
  39. package/dist/commonjs/integration/dynamodb.d.ts +13 -0
  40. package/dist/commonjs/integration/dynamodb.d.ts.map +1 -0
  41. package/dist/commonjs/integration/dynamodb.js +73 -0
  42. package/dist/commonjs/integration/dynamodb.js.map +1 -0
  43. package/dist/commonjs/integration/dynamodb.test.d.ts +2 -0
  44. package/dist/commonjs/integration/dynamodb.test.d.ts.map +1 -0
  45. package/dist/commonjs/integration/dynamodb.test.js +132 -0
  46. package/dist/commonjs/integration/dynamodb.test.js.map +1 -0
  47. package/dist/commonjs/integration/hono.d.ts +29 -0
  48. package/dist/commonjs/integration/hono.d.ts.map +1 -0
  49. package/dist/commonjs/{framework → integration}/hono.js +25 -4
  50. package/dist/commonjs/integration/hono.js.map +1 -0
  51. package/dist/commonjs/integration/hono.test.d.ts +2 -0
  52. package/dist/commonjs/integration/hono.test.d.ts.map +1 -0
  53. package/dist/commonjs/integration/hono.test.js +86 -0
  54. package/dist/commonjs/integration/hono.test.js.map +1 -0
  55. package/dist/commonjs/registration.d.ts +24 -0
  56. package/dist/commonjs/registration.d.ts.map +1 -1
  57. package/dist/commonjs/registration.js +42 -3
  58. package/dist/commonjs/registration.js.map +1 -1
  59. package/dist/commonjs/registration.test.d.ts +2 -0
  60. package/dist/commonjs/registration.test.d.ts.map +1 -0
  61. package/dist/commonjs/registration.test.js +59 -0
  62. package/dist/commonjs/registration.test.js.map +1 -0
  63. package/dist/commonjs/repository.d.ts +5 -1
  64. package/dist/commonjs/repository.d.ts.map +1 -1
  65. package/dist/commonjs/repository.js +7 -1
  66. package/dist/commonjs/repository.js.map +1 -1
  67. package/dist/commonjs/repository.test.d.ts +2 -0
  68. package/dist/commonjs/repository.test.d.ts.map +1 -0
  69. package/dist/commonjs/repository.test.js +32 -0
  70. package/dist/commonjs/repository.test.js.map +1 -0
  71. package/dist/commonjs/signer.test.d.ts +2 -0
  72. package/dist/commonjs/signer.test.d.ts.map +1 -0
  73. package/dist/commonjs/signer.test.js +25 -0
  74. package/dist/commonjs/signer.test.js.map +1 -0
  75. package/dist/esm/context-resolver.test.d.ts +2 -0
  76. package/dist/esm/context-resolver.test.d.ts.map +1 -0
  77. package/dist/esm/context-resolver.test.js +79 -0
  78. package/dist/esm/context-resolver.test.js.map +1 -0
  79. package/dist/esm/helper/app-actions.test.d.ts +2 -0
  80. package/dist/esm/helper/app-actions.test.d.ts.map +1 -0
  81. package/dist/esm/helper/app-actions.test.js +29 -0
  82. package/dist/esm/helper/app-actions.test.js.map +1 -0
  83. package/dist/esm/http-client.test.d.ts +2 -0
  84. package/dist/esm/http-client.test.d.ts.map +1 -0
  85. package/dist/esm/http-client.test.js +69 -0
  86. package/dist/esm/http-client.test.js.map +1 -0
  87. package/dist/esm/integration/bun-sqlite.d.ts +11 -0
  88. package/dist/esm/integration/bun-sqlite.d.ts.map +1 -0
  89. package/dist/esm/integration/bun-sqlite.js +56 -0
  90. package/dist/esm/integration/bun-sqlite.js.map +1 -0
  91. package/dist/esm/integration/bun-sqlite.test.d.ts +2 -0
  92. package/dist/esm/integration/bun-sqlite.test.d.ts.map +1 -0
  93. package/dist/esm/integration/bun-sqlite.test.js +22 -0
  94. package/dist/esm/integration/bun-sqlite.test.js.map +1 -0
  95. package/dist/{commonjs/service/cloudflare.d.ts → esm/integration/cloudflare-kv.d.ts} +1 -24
  96. package/dist/esm/integration/cloudflare-kv.d.ts.map +1 -0
  97. package/dist/esm/{service/cloudflare.js → integration/cloudflare-kv.js} +5 -1
  98. package/dist/esm/integration/cloudflare-kv.js.map +1 -0
  99. package/dist/esm/integration/cloudflare.test.d.ts +2 -0
  100. package/dist/esm/integration/cloudflare.test.d.ts.map +1 -0
  101. package/dist/esm/integration/cloudflare.test.js +37 -0
  102. package/dist/esm/integration/cloudflare.test.js.map +1 -0
  103. package/dist/{commonjs/service/deno.d.ts → esm/integration/deno-kv.d.ts} +1 -1
  104. package/dist/esm/integration/deno-kv.d.ts.map +1 -0
  105. package/dist/{deno/service/deno.js → esm/integration/deno-kv.js} +5 -1
  106. package/dist/esm/integration/deno-kv.js.map +1 -0
  107. package/dist/esm/integration/deno.test.d.ts +2 -0
  108. package/dist/esm/integration/deno.test.d.ts.map +1 -0
  109. package/dist/esm/integration/deno.test.js +46 -0
  110. package/dist/esm/integration/deno.test.js.map +1 -0
  111. package/dist/esm/integration/dynamodb.d.ts +13 -0
  112. package/dist/esm/integration/dynamodb.d.ts.map +1 -0
  113. package/dist/esm/integration/dynamodb.js +69 -0
  114. package/dist/esm/integration/dynamodb.js.map +1 -0
  115. package/dist/esm/integration/dynamodb.test.d.ts +2 -0
  116. package/dist/esm/integration/dynamodb.test.d.ts.map +1 -0
  117. package/dist/esm/integration/dynamodb.test.js +130 -0
  118. package/dist/esm/integration/dynamodb.test.js.map +1 -0
  119. package/dist/esm/integration/hono.d.ts +29 -0
  120. package/dist/esm/integration/hono.d.ts.map +1 -0
  121. package/dist/{deno/framework → esm/integration}/hono.js +25 -4
  122. package/dist/esm/integration/hono.js.map +1 -0
  123. package/dist/esm/integration/hono.test.d.ts +2 -0
  124. package/dist/esm/integration/hono.test.d.ts.map +1 -0
  125. package/dist/esm/integration/hono.test.js +84 -0
  126. package/dist/esm/integration/hono.test.js.map +1 -0
  127. package/dist/esm/registration.d.ts +24 -0
  128. package/dist/esm/registration.d.ts.map +1 -1
  129. package/dist/esm/registration.js +42 -3
  130. package/dist/esm/registration.js.map +1 -1
  131. package/dist/esm/registration.test.d.ts +2 -0
  132. package/dist/esm/registration.test.d.ts.map +1 -0
  133. package/dist/esm/registration.test.js +57 -0
  134. package/dist/esm/registration.test.js.map +1 -0
  135. package/dist/esm/repository.d.ts +5 -1
  136. package/dist/esm/repository.d.ts.map +1 -1
  137. package/dist/esm/repository.js +7 -1
  138. package/dist/esm/repository.js.map +1 -1
  139. package/dist/esm/repository.test.d.ts +2 -0
  140. package/dist/esm/repository.test.d.ts.map +1 -0
  141. package/dist/esm/repository.test.js +30 -0
  142. package/dist/esm/repository.test.js.map +1 -0
  143. package/dist/esm/signer.test.d.ts +2 -0
  144. package/dist/esm/signer.test.d.ts.map +1 -0
  145. package/dist/esm/signer.test.js +23 -0
  146. package/dist/esm/signer.test.js.map +1 -0
  147. package/package.json +87 -16
  148. package/dist/commonjs/framework/hono.d.ts +0 -36
  149. package/dist/commonjs/framework/hono.d.ts.map +0 -1
  150. package/dist/commonjs/framework/hono.js.map +0 -1
  151. package/dist/commonjs/service/cloudflare.d.ts.map +0 -1
  152. package/dist/commonjs/service/cloudflare.js.map +0 -1
  153. package/dist/commonjs/service/deno.d.ts.map +0 -1
  154. package/dist/commonjs/service/deno.js.map +0 -1
  155. package/dist/deno/app.d.ts +0 -31
  156. package/dist/deno/app.d.ts.map +0 -1
  157. package/dist/deno/app.js +0 -21
  158. package/dist/deno/app.js.map +0 -1
  159. package/dist/deno/context-resolver.d.ts +0 -30
  160. package/dist/deno/context-resolver.d.ts.map +0 -1
  161. package/dist/deno/context-resolver.js +0 -65
  162. package/dist/deno/context-resolver.js.map +0 -1
  163. package/dist/deno/framework/hono.d.ts +0 -36
  164. package/dist/deno/framework/hono.d.ts.map +0 -1
  165. package/dist/deno/framework/hono.js.map +0 -1
  166. package/dist/deno/helper/app-actions.d.ts +0 -13
  167. package/dist/deno/helper/app-actions.d.ts.map +0 -1
  168. package/dist/deno/helper/app-actions.js +0 -49
  169. package/dist/deno/helper/app-actions.js.map +0 -1
  170. package/dist/deno/http-client.d.ts +0 -67
  171. package/dist/deno/http-client.d.ts.map +0 -1
  172. package/dist/deno/http-client.js +0 -148
  173. package/dist/deno/http-client.js.map +0 -1
  174. package/dist/deno/mod.d.ts +0 -6
  175. package/dist/deno/mod.d.ts.map +0 -1
  176. package/dist/deno/mod.js +0 -5
  177. package/dist/deno/mod.js.map +0 -1
  178. package/dist/deno/package.json +0 -3
  179. package/dist/deno/registration.d.ts +0 -18
  180. package/dist/deno/registration.d.ts.map +0 -1
  181. package/dist/deno/registration.js +0 -84
  182. package/dist/deno/registration.js.map +0 -1
  183. package/dist/deno/repository.d.ts +0 -51
  184. package/dist/deno/repository.d.ts.map +0 -1
  185. package/dist/deno/repository.js +0 -63
  186. package/dist/deno/repository.js.map +0 -1
  187. package/dist/deno/service/cloudflare.d.ts.map +0 -1
  188. package/dist/deno/service/cloudflare.js +0 -41
  189. package/dist/deno/service/cloudflare.js.map +0 -1
  190. package/dist/deno/service/deno.d.ts +0 -18
  191. package/dist/deno/service/deno.d.ts.map +0 -1
  192. package/dist/deno/service/deno.js.map +0 -1
  193. package/dist/deno/signer.d.ts +0 -12
  194. package/dist/deno/signer.d.ts.map +0 -1
  195. package/dist/deno/signer.js +0 -54
  196. package/dist/deno/signer.js.map +0 -1
  197. package/dist/deno/types.d.ts +0 -28
  198. package/dist/deno/types.d.ts.map +0 -1
  199. package/dist/deno/types.js +0 -2
  200. package/dist/deno/types.js.map +0 -1
  201. package/dist/esm/framework/hono.d.ts +0 -36
  202. package/dist/esm/framework/hono.d.ts.map +0 -1
  203. package/dist/esm/framework/hono.js +0 -81
  204. package/dist/esm/framework/hono.js.map +0 -1
  205. package/dist/esm/service/cloudflare.d.ts +0 -43
  206. package/dist/esm/service/cloudflare.d.ts.map +0 -1
  207. package/dist/esm/service/cloudflare.js.map +0 -1
  208. package/dist/esm/service/deno.d.ts.map +0 -1
  209. package/dist/esm/service/deno.js +0 -44
  210. package/dist/esm/service/deno.js.map +0 -1
@@ -1,54 +0,0 @@
1
- export class WebCryptoHmacSigner {
2
- encoder;
3
- keyCache;
4
- constructor() {
5
- this.encoder = new TextEncoder();
6
- this.keyCache = new Map();
7
- }
8
- async signResponse(response, secret) {
9
- response.headers.set("shopware-app-signature", await this.sign(await response.clone().text(), secret));
10
- }
11
- async verifyGetRequest(request, secret) {
12
- const url = new URL(request.url);
13
- const signature = url.searchParams.get("shopware-shop-signature");
14
- if (signature === null) {
15
- throw new Error("Missing shopware-shop-signature query parameter");
16
- }
17
- url.searchParams.delete("shopware-shop-signature");
18
- let body = "";
19
- for (const searchKey of url.searchParams.keys()) {
20
- body += `${searchKey}=${decodeURIComponent(url.searchParams.get(searchKey))}&`;
21
- }
22
- body = body.slice(0, -1);
23
- if (body === "") {
24
- throw new Error("Missing query parameters to verify the GET request");
25
- }
26
- if (!(await this.verify(signature, body, secret))) {
27
- throw new Error("Invalid signature");
28
- }
29
- }
30
- async getKeyForSecret(secret) {
31
- if (this.keyCache.has(secret)) {
32
- return this.keyCache.get(secret);
33
- }
34
- const secretKeyData = this.encoder.encode(secret);
35
- const key = await crypto.subtle.importKey("raw", secretKeyData, { name: "HMAC", hash: "SHA-256" }, false, ["sign", "verify"]);
36
- this.keyCache.set(secret, key);
37
- return key;
38
- }
39
- async sign(message, secret) {
40
- const key = await this.getKeyForSecret(secret);
41
- const mac = await crypto.subtle.sign("HMAC", key, this.encoder.encode(message));
42
- return this.buf2hex(mac);
43
- }
44
- async verify(signature, data, secret) {
45
- const signed = await this.sign(data, secret);
46
- return signature === signed;
47
- }
48
- buf2hex(buf) {
49
- return Array.prototype.map
50
- .call(new Uint8Array(buf), (x) => `00${x.toString(16)}`.slice(-2))
51
- .join("");
52
- }
53
- }
54
- //# sourceMappingURL=signer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"signer.js","sourceRoot":"","sources":["../../src/signer.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,mBAAmB;IACvB,OAAO,CAAc;IACrB,QAAQ,CAAyB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,GAAgB;QACvB,OAAO,KAAK,CAAC,SAAS,CAAC,GAAG;aACxB,IAAI,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;aACjE,IAAI,CAAC,EAAE,CAAC,CAAC;IACZ,CAAC;CACD","sourcesContent":["export class WebCryptoHmacSigner {\n\tprivate encoder: TextEncoder;\n\tprivate keyCache: Map<string, CryptoKey>;\n\n\tconstructor() {\n\t\tthis.encoder = new TextEncoder();\n\t\tthis.keyCache = new Map<string, CryptoKey>();\n\t}\n\n\tasync signResponse(response: Response, secret: string): Promise<void> {\n\t\tresponse.headers.set(\n\t\t\t\"shopware-app-signature\",\n\t\t\tawait this.sign(await response.clone().text(), secret),\n\t\t);\n\t}\n\n\tasync verifyGetRequest(request: Request, secret: string): Promise<void> {\n\t\tconst url = new URL(request.url);\n\t\tconst signature = url.searchParams.get(\"shopware-shop-signature\");\n\n\t\tif (signature === null) {\n\t\t\tthrow new Error(\"Missing shopware-shop-signature query parameter\");\n\t\t}\n\n\t\turl.searchParams.delete(\"shopware-shop-signature\");\n\n\t\tlet body = \"\";\n\n\t\tfor (const searchKey of url.searchParams.keys()) {\n\t\t\tbody += `${searchKey}=${decodeURIComponent(url.searchParams.get(searchKey) as string)}&`;\n\t\t}\n\n\t\tbody = body.slice(0, -1);\n\n\t\tif (body === \"\") {\n\t\t\tthrow new Error(\"Missing query parameters to verify the GET request\");\n\t\t}\n\n\t\tif (!(await this.verify(signature, body, secret))) {\n\t\t\tthrow new Error(\"Invalid signature\");\n\t\t}\n\t}\n\n\tasync getKeyForSecret(secret: string): Promise<CryptoKey> {\n\t\tif (this.keyCache.has(secret)) {\n\t\t\treturn this.keyCache.get(secret) as CryptoKey;\n\t\t}\n\n\t\tconst secretKeyData = this.encoder.encode(secret);\n\t\tconst key = await crypto.subtle.importKey(\n\t\t\t\"raw\",\n\t\t\tsecretKeyData,\n\t\t\t{ name: \"HMAC\", hash: \"SHA-256\" },\n\t\t\tfalse,\n\t\t\t[\"sign\", \"verify\"],\n\t\t);\n\n\t\tthis.keyCache.set(secret, key);\n\n\t\treturn key;\n\t}\n\n\tasync sign(message: string, secret: string): Promise<string> {\n\t\tconst key = await this.getKeyForSecret(secret);\n\n\t\tconst mac = await crypto.subtle.sign(\n\t\t\t\"HMAC\",\n\t\t\tkey as CryptoKey,\n\t\t\tthis.encoder.encode(message),\n\t\t);\n\n\t\treturn this.buf2hex(mac);\n\t}\n\n\tasync verify(\n\t\tsignature: string,\n\t\tdata: string,\n\t\tsecret: string,\n\t): Promise<boolean> {\n\t\tconst signed = await this.sign(data, secret);\n\n\t\treturn signature === signed;\n\t}\n\n\tbuf2hex(buf: ArrayBuffer): string {\n\t\treturn Array.prototype.map\n\t\t\t.call(new Uint8Array(buf), (x) => `00${x.toString(16)}`.slice(-2))\n\t\t\t.join(\"\");\n\t}\n}\n"]}
@@ -1,28 +0,0 @@
1
- export type BrowserAppModuleRequest = {
2
- "shop-id": string;
3
- "shop-url": string;
4
- timestamp: string;
5
- "sw-version": string;
6
- "sw-context-language": string;
7
- "sw-user-language": string;
8
- };
9
- export type Source = {
10
- url: string;
11
- shopId: string;
12
- appVersion: string;
13
- };
14
- export type Meta = {
15
- timestamp: number;
16
- reference: string;
17
- language: string;
18
- };
19
- export type ActionButtonRequest = {
20
- source: Source;
21
- data: {
22
- ids: string[];
23
- entity: string;
24
- action: string;
25
- };
26
- meta: Meta;
27
- };
28
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,uBAAuB,GAAG;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,kBAAkB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE;QACL,GAAG,EAAE,MAAM,EAAE,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;KACf,CAAC;IACF,IAAI,EAAE,IAAI,CAAC;CACX,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export type BrowserAppModuleRequest = {\n\t\"shop-id\": string;\n\t\"shop-url\": string;\n\ttimestamp: string;\n\t\"sw-version\": string;\n\t\"sw-context-language\": string;\n\t\"sw-user-language\": string;\n};\n\nexport type Source = {\n\turl: string;\n\tshopId: string;\n\tappVersion: string;\n};\n\nexport type Meta = {\n\ttimestamp: number;\n\treference: string;\n\tlanguage: string;\n};\n\nexport type ActionButtonRequest = {\n\tsource: Source;\n\tdata: {\n\t\tids: string[];\n\t\tentity: string;\n\t\taction: string;\n\t};\n\tmeta: Meta;\n};\n"]}
@@ -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,81 +0,0 @@
1
- import { AppServer } from "../app.js";
2
- let app = null;
3
- /**
4
- * Configure the Hono server to handle the app registration and context resolution
5
- */
6
- export function configureAppServer(honoExternal, cfg) {
7
- const hono = honoExternal;
8
- cfg.registrationUrl = cfg.registrationUrl || "/app/register";
9
- cfg.registerConfirmationUrl =
10
- cfg.registerConfirmationUrl || "/app/register/confirm";
11
- cfg.appPath = cfg.appPath || "/app/*";
12
- hono.use("*", async (ctx, next) => {
13
- if (app === null) {
14
- const appUrl = cfg.appUrl || buildBaseUrl(ctx.req.url);
15
- if (typeof cfg.shopRepository === "function") {
16
- cfg.shopRepository = cfg.shopRepository(ctx);
17
- }
18
- if (typeof cfg.appName === "function") {
19
- cfg.appName = cfg.appName(ctx);
20
- }
21
- if (typeof cfg.appSecret === "function") {
22
- cfg.appSecret = cfg.appSecret(ctx);
23
- }
24
- app = new AppServer({
25
- appName: cfg.appName,
26
- appSecret: cfg.appSecret,
27
- authorizeCallbackUrl: appUrl + cfg.registerConfirmationUrl,
28
- }, cfg.shopRepository);
29
- }
30
- ctx.set("app", app);
31
- await next();
32
- });
33
- hono.use(cfg.appPath, async (ctx, next) => {
34
- const app = ctx.get("app");
35
- // Don't validate signature for registration
36
- if (ctx.req.path === cfg.registrationUrl ||
37
- ctx.req.path === cfg.registerConfirmationUrl) {
38
- await next();
39
- return;
40
- }
41
- let context;
42
- try {
43
- context =
44
- ctx.req.method === "GET"
45
- ? await app.contextResolver.fromBrowser(ctx.req.raw)
46
- : await app.contextResolver.fromAPI(ctx.req.raw);
47
- }
48
- catch (_e) {
49
- return jsonResponse({ message: "Invalid request" }, 400);
50
- }
51
- ctx.set("shop", context.shop);
52
- ctx.set("context", context);
53
- await next();
54
- const cloned = ctx.res.clone();
55
- await ctx
56
- .get("app")
57
- .signer.signResponse(cloned, ctx.get("shop").getShopSecret());
58
- ctx.header("shopware-app-signature", cloned.headers.get("shopware-app-signature"));
59
- });
60
- hono.get(cfg.registrationUrl, async (ctx) => {
61
- const app = ctx.get("app");
62
- return await app.registration.authorize(ctx.req.raw);
63
- });
64
- hono.post(cfg.registerConfirmationUrl, async (ctx) => {
65
- const app = ctx.get("app");
66
- return await app.registration.authorizeCallback(ctx.req.raw);
67
- });
68
- }
69
- function jsonResponse(body, status = 200) {
70
- return new Response(JSON.stringify(body), {
71
- status,
72
- headers: {
73
- "Content-Type": "application/json",
74
- },
75
- });
76
- }
77
- function buildBaseUrl(url) {
78
- const u = new URL(url);
79
- return `${u.protocol}//${u.host}`;
80
- }
81
- //# sourceMappingURL=hono.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hono.js","sourceRoot":"","sources":["../../../src/framework/hono.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAmDtC,IAAI,GAAG,GAAqB,IAAI,CAAC;AAEjC;;GAEG;AACH,MAAM,UAAU,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,GAAG,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;YAC9C,CAAC;YAED,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;gBACvC,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAChC,CAAC;YAED,IAAI,OAAO,GAAG,CAAC,SAAS,KAAK,UAAU,EAAE,CAAC;gBACzC,GAAG,CAAC,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACpC,CAAC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ChC,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,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;CAYnD;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,WAAW,WAAW,CAAC,GAAG,SAAS,MAAM,GAAG,MAAM;IAC/D,GAAG,CACF,GAAG,EAAE,GAAG,EACR,OAAO,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,SAAS,CAAC,C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E,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,UAAU,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","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 +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,44 +0,0 @@
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
- const shop = new SimpleShop(data.shopId, data.shopUrl, data.shopSecret);
28
- if (data.shopClientId && data.shopClientSecret) {
29
- shop.setShopCredentials(data.shopClientId, data.shopClientSecret);
30
- }
31
- return shop;
32
- }
33
- async updateShop(shop) {
34
- // @ts-ignore
35
- const kv = await Deno.openKv();
36
- await kv.set([this.namespace, shop.getShopId()], shop);
37
- }
38
- async deleteShop(id) {
39
- // @ts-ignore
40
- const kv = await Deno.openKv();
41
- await kv.delete([this.namespace, id]);
42
- }
43
- }
44
- //# sourceMappingURL=deno.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deno.js","sourceRoot":"","sources":["../../../src/service/deno.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C;;;GAGG;AAEH;;GAEG;AACH,MAAM,OAAO,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,UAAU,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,EAAU;QAC3B,aAAa;QACb,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QAE/B,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;QAElD,IAAI,MAAM,CAAC,GAAG,KAAK,IAAI,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC;QACb,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,CAAC,KAMnB,CAAC;QAEF,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAExE,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAChD,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,YAAY,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 { 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"]}