@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
@@ -0,0 +1,23 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { WebCryptoHmacSigner } from "../src/signer.js";
3
+ describe("Signer", () => {
4
+ test("signResponse", async () => {
5
+ const signer = new WebCryptoHmacSigner();
6
+ const response = new Response("Hello, World!");
7
+ await signer.signResponse(response, "test");
8
+ expect(response.headers.get("shopware-app-signature")).toBe("52589bd80ccfa4acbb3f9512dfaf4f700fa5195008aae0b77a9e47dcca75beac");
9
+ await signer.signResponse(response, "test");
10
+ expect(response.headers.get("shopware-app-signature")).toBe("52589bd80ccfa4acbb3f9512dfaf4f700fa5195008aae0b77a9e47dcca75beac");
11
+ });
12
+ test("sign", async () => {
13
+ const signer = new WebCryptoHmacSigner();
14
+ expect(await signer.sign("shop-id=blaa", "test")).toBe("f2cb1044ac5a2cb807e1942b06433d23d66bcf7dfad1095b286203e5c1f39cb6");
15
+ });
16
+ test("verifyGetRequest", async () => {
17
+ const signer = new WebCryptoHmacSigner();
18
+ expect(signer.verifyGetRequest(new Request("https://example.com/?shopware-shop-signature=52589bd80ccfa4acbb3f9512dfaf4f700fa5195008aae0b77a9e47dcca75beac"), "test")).rejects.toThrowError("Missing query parameters to verify the GET request");
19
+ expect(signer.verifyGetRequest(new Request("https://example.com/?shopware-shop-signature=52589bd80ccfa4acbb3f9512dfaf4f700fa5195008aae0b77a9e47dcca75beac&a=1"), "test")).rejects.toThrowError("Invalid signature");
20
+ expect(signer.verifyGetRequest(new Request("https://example.com/?shopware-shop-signature=f2cb1044ac5a2cb807e1942b06433d23d66bcf7dfad1095b286203e5c1f39cb6&shop-id=blaa"), "test")).resolves.pass();
21
+ });
22
+ });
23
+ //# sourceMappingURL=signer.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signer.test.js","sourceRoot":"","sources":["../../src/signer.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE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AC,mBAAmB,CAAC,CAAC;QAE5C,MAAM,CACL,MAAM,CAAC,gBAAgB,CACtB,IAAI,OAAO,CACV,4HAA4H,CAC5H,EACD,MAAM,CACN,CACD,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, test } from \"bun:test\";\nimport { WebCryptoHmacSigner } from \"../src/signer.js\";\n\ndescribe(\"Signer\", () => {\n\ttest(\"signResponse\", async () => {\n\t\tconst signer = new WebCryptoHmacSigner();\n\n\t\tconst response = new Response(\"Hello, World!\");\n\n\t\tawait signer.signResponse(response, \"test\");\n\n\t\texpect(response.headers.get(\"shopware-app-signature\")).toBe(\n\t\t\t\"52589bd80ccfa4acbb3f9512dfaf4f700fa5195008aae0b77a9e47dcca75beac\",\n\t\t);\n\n\t\tawait signer.signResponse(response, \"test\");\n\n\t\texpect(response.headers.get(\"shopware-app-signature\")).toBe(\n\t\t\t\"52589bd80ccfa4acbb3f9512dfaf4f700fa5195008aae0b77a9e47dcca75beac\",\n\t\t);\n\t});\n\n\ttest(\"sign\", async () => {\n\t\tconst signer = new WebCryptoHmacSigner();\n\n\t\texpect(await signer.sign(\"shop-id=blaa\", \"test\")).toBe(\n\t\t\t\"f2cb1044ac5a2cb807e1942b06433d23d66bcf7dfad1095b286203e5c1f39cb6\",\n\t\t);\n\t});\n\n\ttest(\"verifyGetRequest\", async () => {\n\t\tconst signer = new WebCryptoHmacSigner();\n\n\t\texpect(\n\t\t\tsigner.verifyGetRequest(\n\t\t\t\tnew Request(\n\t\t\t\t\t\"https://example.com/?shopware-shop-signature=52589bd80ccfa4acbb3f9512dfaf4f700fa5195008aae0b77a9e47dcca75beac\",\n\t\t\t\t),\n\t\t\t\t\"test\",\n\t\t\t),\n\t\t).rejects.toThrowError(\n\t\t\t\"Missing query parameters to verify the GET request\",\n\t\t);\n\t\texpect(\n\t\t\tsigner.verifyGetRequest(\n\t\t\t\tnew Request(\n\t\t\t\t\t\"https://example.com/?shopware-shop-signature=52589bd80ccfa4acbb3f9512dfaf4f700fa5195008aae0b77a9e47dcca75beac&a=1\",\n\t\t\t\t),\n\t\t\t\t\"test\",\n\t\t\t),\n\t\t).rejects.toThrowError(\"Invalid signature\");\n\n\t\texpect(\n\t\t\tsigner.verifyGetRequest(\n\t\t\t\tnew Request(\n\t\t\t\t\t\"https://example.com/?shopware-shop-signature=f2cb1044ac5a2cb807e1942b06433d23d66bcf7dfad1095b286203e5c1f39cb6&shop-id=blaa\",\n\t\t\t\t),\n\t\t\t\t\"test\",\n\t\t\t),\n\t\t).resolves.pass();\n\t});\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopware-ag/app-server-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "App Server SDK for JavaScript",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -8,10 +8,6 @@
8
8
  "exports": {
9
9
  "./package.json": "./package.json",
10
10
  ".": {
11
- "deno": {
12
- "types": "./dist/deno/mod.d.ts",
13
- "default": "./dist/deno/mod.js"
14
- },
15
11
  "import": {
16
12
  "types": "./dist/esm/mod.d.ts",
17
13
  "default": "./dist/esm/mod.js"
@@ -22,10 +18,6 @@
22
18
  }
23
19
  },
24
20
  "./helper/app-actions": {
25
- "deno": {
26
- "types": "./dist/deno/helper/app-actions.d.ts",
27
- "default": "./dist/deno/helper/app-actions.js"
28
- },
29
21
  "import": {
30
22
  "types": "./dist/esm/helper/app-actions.d.ts",
31
23
  "default": "./dist/esm/helper/app-actions.js"
@@ -35,11 +27,57 @@
35
27
  "default": "./dist/commonjs/helper/app-actions.js"
36
28
  }
37
29
  },
38
- "./types": {
39
- "deno": {
40
- "types": "./dist/deno/types.d.ts",
41
- "default": "./dist/deno/types.js"
30
+ "./integration/hono": {
31
+ "import": {
32
+ "types": "./dist/esm/integration/hono.d.ts",
33
+ "default": "./dist/esm/integration/hono.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/commonjs/integration/hono.d.ts",
37
+ "default": "./dist/commonjs/integration/hono.js"
38
+ }
39
+ },
40
+ "./integration/cloudflare-kv": {
41
+ "import": {
42
+ "types": "./dist/esm/integration/cloudflare-kv.d.ts",
43
+ "default": "./dist/esm/integration/cloudflare-kv.js"
44
+ },
45
+ "require": {
46
+ "types": "./dist/commonjs/integration/cloudflare-kv.d.ts",
47
+ "default": "./dist/commonjs/integration/cloudflare-kv.js"
48
+ }
49
+ },
50
+ "./integration/deno-kv": {
51
+ "import": {
52
+ "types": "./dist/esm/integration/deno-kv.d.ts",
53
+ "default": "./dist/esm/integration/deno-kv.js"
54
+ },
55
+ "require": {
56
+ "types": "./dist/commonjs/integration/deno-kv.d.ts",
57
+ "default": "./dist/commonjs/integration/deno-kv.js"
58
+ }
59
+ },
60
+ "./integration/dynamodb": {
61
+ "import": {
62
+ "types": "./dist/esm/integration/dynamodb.d.ts",
63
+ "default": "./dist/esm/integration/dynamodb.js"
42
64
  },
65
+ "require": {
66
+ "types": "./dist/commonjs/integration/dynamodb.d.ts",
67
+ "default": "./dist/commonjs/integration/dynamodb.js"
68
+ }
69
+ },
70
+ "./integration/bun-sqlite": {
71
+ "import": {
72
+ "types": "./dist/esm/integration/bun-sqlite.d.ts",
73
+ "default": "./dist/esm/integration/bun-sqlite.js"
74
+ },
75
+ "require": {
76
+ "types": "./dist/commonjs/integration/bun-sqlite.d.ts",
77
+ "default": "./dist/commonjs/integration/bun-sqlite.js"
78
+ }
79
+ },
80
+ "./types": {
43
81
  "import": {
44
82
  "types": "./dist/esm/types.d.ts",
45
83
  "default": "./dist/esm/types.js"
@@ -54,19 +92,52 @@
54
92
  "module": "./dist/esm/mod.js",
55
93
  "types": "./dist/commonjs/mod.d.ts",
56
94
  "files": ["dist"],
95
+ "publishConfig": {
96
+ "access": "public"
97
+ },
98
+ "peerDependencies": {
99
+ "hono": "^4",
100
+ "@aws-sdk/client-dynamodb": "~3.637",
101
+ "@aws-sdk/lib-dynamodb": "~3.637"
102
+ },
103
+ "peerDependenciesMeta": {
104
+ "hono": {
105
+ "optional": true
106
+ },
107
+ "@aws-sdk/client-dynamodb": {
108
+ "optional": true
109
+ },
110
+ "@aws-sdk/lib-dynamodb": {
111
+ "optional": true
112
+ }
113
+ },
57
114
  "devDependencies": {
58
115
  "@biomejs/biome": "1.8.3",
59
116
  "@types/bun": "^1.1.6",
60
117
  "tshy": "^3.0.2",
61
- "hono": "^4.5.6"
118
+ "hono": "^4.5.6",
119
+ "@cloudflare/workers-types": "^4.20240821.1",
120
+ "@aws-sdk/client-dynamodb": "~3.637",
121
+ "@aws-sdk/lib-dynamodb": "~3.637"
62
122
  },
63
123
  "tshy": {
64
- "esmDialects": ["deno"],
65
124
  "exports": {
66
125
  "./package.json": "./package.json",
67
126
  ".": "./src/mod.ts",
68
127
  "./helper/app-actions": "./src/helper/app-actions.ts",
128
+ "./integration/hono": "./src/integration/hono.ts",
129
+ "./integration/cloudflare-kv": "./src/integration/cloudflare-kv.ts",
130
+ "./integration/deno-kv": "./src/integration/deno-kv.ts",
131
+ "./integration/dynamodb": "./src/integration/dynamodb.ts",
132
+ "./integration/bun-sqlite": "./src/integration/bun-sqlite.ts",
69
133
  "./types": "./src/types.ts"
70
134
  }
71
- }
135
+ },
136
+ "scripts": {
137
+ "init": "tshy && biome format . --write",
138
+ "lint": "biome ci .",
139
+ "lint:fix": "biome lint . --write && biome format . --write && biome check . --write",
140
+ "typecheck": "tsc --noEmit"
141
+ },
142
+ "trustedDependencies": ["@biomejs/biome"]
72
143
  }
@@ -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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e,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QAC3C,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAE3B,OAAO,MAAM,GAAG,CAAC,YAAY,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,uBAAuB,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QACpD,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAE3B,OAAO,MAAM,GAAG,CAAC,YAAY,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,IAAY,EAAE,MAAM,GAAG,GAAG;IAC/C,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;QACzC,MAAM;QACN,OAAO,EAAE;YACR,cAAc,EAAE,kBAAkB;SAClC;KACD,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,GAAW;IAChC,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAEvB,OAAO,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { AppServer } from \"../app.js\";\nimport type { Context } from \"../context-resolver.js\";\nimport type { ShopInterface, ShopRepositoryInterface } from \"../repository.js\";\n\ninterface MiddlewareConfig {\n\tappName: string | ((c: HonoContext<DataTypes>) => string);\n\tappSecret: string | ((c: HonoContext<DataTypes>) => string);\n\tappUrl?: string | null;\n\tregistrationUrl?: string | null;\n\tregisterConfirmationUrl?: string | null;\n\tappPath?: string | null;\n\tshopRepository:\n\t\t| ShopRepositoryInterface\n\t\t| ((c: HonoContext<DataTypes>) => ShopRepositoryInterface);\n}\n\ninterface DataTypes {\n\tapp: AppServer;\n\tcontext: Context<ShopInterface, unknown>;\n\tshop: ShopInterface;\n}\n\ninterface HonoContext<DataTypes> {\n\tenv: any;\n\treq: {\n\t\tpath: string;\n\t\tmethod: string;\n\t\turl: string;\n\t\traw: Request;\n\t};\n\theader: (key: string, value: string) => void;\n\tres: Response;\n\tget<K extends keyof DataTypes>(key: K): DataTypes[K];\n\tset<K extends keyof DataTypes>(key: K, value: DataTypes[K]): void;\n}\n\ninterface Hono {\n\tuse: (\n\t\tpath: string,\n\t\thandler: (ctx: HonoContext<DataTypes>, next: () => Promise<void>) => void,\n\t) => void;\n\tget: (\n\t\tpath: string,\n\t\thandler: (ctx: HonoContext<DataTypes>, next: () => void) => void,\n\t) => void;\n\tpost: (\n\t\tpath: string,\n\t\thandler: (ctx: HonoContext<DataTypes>, next: () => void) => void,\n\t) => void;\n}\n\nlet app: AppServer | null = null;\n\n/**\n * Configure the Hono server to handle the app registration and context resolution\n */\nexport function configureAppServer(\n\thonoExternal: unknown,\n\tcfg: MiddlewareConfig,\n) {\n\tconst hono = honoExternal as Hono;\n\n\tcfg.registrationUrl = cfg.registrationUrl || \"/app/register\";\n\tcfg.registerConfirmationUrl =\n\t\tcfg.registerConfirmationUrl || \"/app/register/confirm\";\n\tcfg.appPath = cfg.appPath || \"/app/*\";\n\n\thono.use(\"*\", async (ctx, next) => {\n\t\tif (app === null) {\n\t\t\tconst appUrl = cfg.appUrl || buildBaseUrl(ctx.req.url);\n\n\t\t\tif (typeof cfg.shopRepository === \"function\") {\n\t\t\t\tcfg.shopRepository = cfg.shopRepository(ctx);\n\t\t\t}\n\n\t\t\tif (typeof cfg.appName === \"function\") {\n\t\t\t\tcfg.appName = cfg.appName(ctx);\n\t\t\t}\n\n\t\t\tif (typeof cfg.appSecret === \"function\") {\n\t\t\t\tcfg.appSecret = cfg.appSecret(ctx);\n\t\t\t}\n\n\t\t\tapp = new AppServer(\n\t\t\t\t{\n\t\t\t\t\tappName: cfg.appName,\n\t\t\t\t\tappSecret: cfg.appSecret,\n\t\t\t\t\tauthorizeCallbackUrl: appUrl + cfg.registerConfirmationUrl,\n\t\t\t\t},\n\t\t\t\tcfg.shopRepository,\n\t\t\t);\n\t\t}\n\n\t\tctx.set(\"app\", app);\n\n\t\tawait next();\n\t});\n\n\thono.use(cfg.appPath, async (ctx, next) => {\n\t\tconst app = ctx.get(\"app\") as AppServer;\n\n\t\t// Don't validate signature for registration\n\t\tif (\n\t\t\tctx.req.path === cfg.registrationUrl ||\n\t\t\tctx.req.path === cfg.registerConfirmationUrl\n\t\t) {\n\t\t\tawait next();\n\t\t\treturn;\n\t\t}\n\n\t\tlet context: Context<ShopInterface, unknown>;\n\t\ttry {\n\t\t\tcontext =\n\t\t\t\tctx.req.method === \"GET\"\n\t\t\t\t\t? await app.contextResolver.fromBrowser(ctx.req.raw)\n\t\t\t\t\t: await app.contextResolver.fromAPI(ctx.req.raw);\n\t\t} catch (_e) {\n\t\t\treturn jsonResponse({ message: \"Invalid request\" }, 400);\n\t\t}\n\n\t\tctx.set(\"shop\", context.shop);\n\t\tctx.set(\"context\", context);\n\n\t\tawait next();\n\n\t\tconst cloned = ctx.res.clone();\n\n\t\tawait ctx\n\t\t\t.get(\"app\")\n\t\t\t.signer.signResponse(cloned, ctx.get(\"shop\").getShopSecret());\n\n\t\tctx.header(\n\t\t\t\"shopware-app-signature\",\n\t\t\tcloned.headers.get(\"shopware-app-signature\") as string,\n\t\t);\n\t});\n\n\thono.get(cfg.registrationUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.authorize(ctx.req.raw);\n\t});\n\n\thono.post(cfg.registerConfirmationUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.authorizeCallback(ctx.req.raw);\n\t});\n}\n\nfunction jsonResponse(body: object, status = 200): Response {\n\treturn new Response(JSON.stringify(body), {\n\t\tstatus,\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t},\n\t});\n}\n\nfunction buildBaseUrl(url: string): string {\n\tconst u = new URL(url);\n\n\treturn `${u.protocol}//${u.host}`;\n}\n"]}
@@ -1 +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,CAAC,GACjD,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC1B,GAAG,CACF,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,MAAM,GAAG,WA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I,KAAK,KAAK,IAAI,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC;QACb,CAAC;QAED,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,IAAgB;QAChC,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;IACpE,CAAC;IAES,aAAa,CAAC,IAAgB;QACvC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAES,eAAe,CAAC,IAAY;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAE7B,MAAM,IAAI,GAAG,IAAI,0BAAU,CAC1B,GAAG,CAAC,MAAM,IAAI,EAAE,EAChB,GAAG,CAAC,OAAO,IAAI,EAAE,EACjB,GAAG,CAAC,UAAU,IAAI,EAAE,CACpB,CAAC;QAEF,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,EAAE,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC;QAC5E,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAhDD,4DAgDC","sourcesContent":["import { SimpleShop } from \"../repository.js\";\nimport type { ShopInterface, ShopRepositoryInterface } from \"../repository.js\";\n\n/**\n * Cloudflare KV integration\n * @module\n */\n\n/**\n * Cloudflare KV implementation of the ShopRepositoryInterface\n */\nexport class CloudflareShopRepository\n\timplements ShopRepositoryInterface<SimpleShop>\n{\n\tconstructor(private storage: KVNamespace) {\n\t\tthis.storage = storage;\n\t}\n\n\tasync createShop(id: string, url: string, secret: string): Promise<void> {\n\t\tawait this.storage.put(\n\t\t\tid,\n\t\t\tthis.serializeShop(new SimpleShop(id, url, secret)),\n\t\t);\n\t}\n\n\tasync deleteShop(id: string): Promise<void> {\n\t\tawait this.storage.delete(id);\n\t}\n\n\tasync getShopById(id: string): Promise<SimpleShop | null> {\n\t\tconst kvObj = await this.storage.get(id);\n\n\t\tif (kvObj === null) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn this.deserializeShop(kvObj);\n\t}\n\n\tasync updateShop(shop: SimpleShop): Promise<void> {\n\t\tawait this.storage.put(shop.getShopId(), this.serializeShop(shop));\n\t}\n\n\tprotected serializeShop(shop: SimpleShop): string {\n\t\treturn JSON.stringify(shop);\n\t}\n\n\tprotected deserializeShop(data: string): SimpleShop {\n\t\tconst obj = JSON.parse(data);\n\n\t\tconst shop = new SimpleShop(\n\t\t\tobj.shopId || \"\",\n\t\t\tobj.shopUrl || \"\",\n\t\t\tobj.shopSecret || \"\",\n\t\t);\n\n\t\tshop.setShopCredentials(obj.shopClientId || \"\", obj.shopClientSecret || \"\");\n\t\treturn shop;\n\t}\n}\n\n/**\n * Cloudflare KV\n */\nexport declare interface KVNamespace<Key extends string = string> {\n\tget(\n\t\tkey: Key,\n\t\toptions?: Partial<KVNamespaceGetOptions<undefined>>,\n\t): Promise<string | null>;\n\tput(\n\t\tkey: Key,\n\t\tvalue: string | ArrayBuffer | ArrayBufferView | ReadableStream,\n\t\toptions?: KVNamespacePutOptions,\n\t): Promise<void>;\n\tdelete(key: Key): Promise<void>;\n}\n\n/**\n * Cloudflare KV get options\n */\nexport declare interface KVNamespaceGetOptions<Type> {\n\ttype: Type;\n\tcacheTtl?: number;\n}\n\n/**\n * Cloudflare KV put options\n */\nexport declare interface KVNamespacePutOptions {\n\texpiration?: number;\n\texpirationTtl?: number;\n\tmetadata?: any | null;\n}\n"]}
@@ -1 +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;AAE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CAAC;YACzB,OAAO,IAAI,CAAC;QACb,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,CAAC,KAMnB,CAAC;QAEF,MAAM,IAAI,GAAG,IAAI,0BAAU,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;AAlDD,4CAkDC","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"]}
@@ -1,31 +0,0 @@
1
- import { ContextResolver } from "./context-resolver.js";
2
- import { Registration } from "./registration.js";
3
- import type { ShopInterface, ShopRepositoryInterface } from "./repository.js";
4
- import { WebCryptoHmacSigner } from "./signer.js";
5
- /**
6
- * AppServer is the main class, this is where you start your app
7
- */
8
- export declare class AppServer<Shop extends ShopInterface = ShopInterface> {
9
- cfg: Configuration;
10
- repository: ShopRepositoryInterface<Shop>;
11
- registration: Registration;
12
- contextResolver: ContextResolver<Shop>;
13
- signer: WebCryptoHmacSigner;
14
- constructor(cfg: Configuration, repository: ShopRepositoryInterface<Shop>);
15
- }
16
- interface Configuration {
17
- /**
18
- * Your app name
19
- */
20
- appName: string;
21
- /**
22
- * Your app secret
23
- */
24
- appSecret: string;
25
- /**
26
- * URL to authorize callback url
27
- */
28
- authorizeCallbackUrl: string;
29
- }
30
- export {};
31
- //# sourceMappingURL=app.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD;;GAEG;AACH,qBAAa,SAAS,CAAC,IAAI,SAAS,aAAa,GAAG,aAAa;IAMxD,GAAG,EAAE,aAAa;IAClB,UAAU,EAAE,uBAAuB,CAAC,IAAI,CAAC;IAN1C,YAAY,EAAE,YAAY,CAAC;IAC3B,eAAe,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;IACvC,MAAM,EAAE,mBAAmB,CAAC;gBAG3B,GAAG,EAAE,aAAa,EAClB,UAAU,EAAE,uBAAuB,CAAC,IAAI,CAAC;CAMjD;AAED,UAAU,aAAa;IACtB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,oBAAoB,EAAE,MAAM,CAAC;CAC7B"}
package/dist/deno/app.js DELETED
@@ -1,21 +0,0 @@
1
- import { ContextResolver } from "./context-resolver.js";
2
- import { Registration } from "./registration.js";
3
- import { WebCryptoHmacSigner } from "./signer.js";
4
- /**
5
- * AppServer is the main class, this is where you start your app
6
- */
7
- export class AppServer {
8
- cfg;
9
- repository;
10
- registration;
11
- contextResolver;
12
- signer;
13
- constructor(cfg, repository) {
14
- this.cfg = cfg;
15
- this.repository = repository;
16
- this.registration = new Registration(this);
17
- this.contextResolver = new ContextResolver(this);
18
- this.signer = new WebCryptoHmacSigner();
19
- }
20
- }
21
- //# sourceMappingURL=app.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD;;GAEG;AACH,MAAM,OAAO,SAAS;IAMb;IACA;IAND,YAAY,CAAe;IAC3B,eAAe,CAAwB;IACvC,MAAM,CAAsB;IAEnC,YACQ,GAAkB,EAClB,UAAyC;QADzC,QAAG,GAAH,GAAG,CAAe;QAClB,eAAU,GAAV,UAAU,CAA+B;QAEhD,IAAI,CAAC,YAAY,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,CAAC,eAAe,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,GAAG,IAAI,mBAAmB,EAAE,CAAC;IACzC,CAAC;CACD","sourcesContent":["import { ContextResolver } from \"./context-resolver.js\";\nimport { Registration } from \"./registration.js\";\nimport type { ShopInterface, ShopRepositoryInterface } from \"./repository.js\";\nimport { WebCryptoHmacSigner } from \"./signer.js\";\n\n/**\n * AppServer is the main class, this is where you start your app\n */\nexport class AppServer<Shop extends ShopInterface = ShopInterface> {\n\tpublic registration: Registration;\n\tpublic contextResolver: ContextResolver<Shop>;\n\tpublic signer: WebCryptoHmacSigner;\n\n\tconstructor(\n\t\tpublic cfg: Configuration,\n\t\tpublic repository: ShopRepositoryInterface<Shop>,\n\t) {\n\t\tthis.registration = new Registration(this);\n\t\tthis.contextResolver = new ContextResolver(this);\n\t\tthis.signer = new WebCryptoHmacSigner();\n\t}\n}\n\ninterface Configuration {\n\t/**\n\t * Your app name\n\t */\n\tappName: string;\n\n\t/**\n\t * Your app secret\n\t */\n\tappSecret: string;\n\n\t/**\n\t * URL to authorize callback url\n\t */\n\tauthorizeCallbackUrl: string;\n}\n"]}
@@ -1,30 +0,0 @@
1
- import type { AppServer } from "./app.js";
2
- import { HttpClient } from "./http-client.js";
3
- import type { ShopInterface } from "./repository.js";
4
- /**
5
- * ContextResolver is a helper class to create a Context object from a request.
6
- * The context contains the shop, the payload and an instance of the HttpClient
7
- */
8
- export declare class ContextResolver<Shop extends ShopInterface = ShopInterface> {
9
- private app;
10
- constructor(app: AppServer);
11
- /**
12
- * Create a context from a request body
13
- */
14
- fromAPI<Payload = unknown>(req: Request): Promise<Context<Shop, Payload>>;
15
- /**
16
- * Create a context from a request query parameters
17
- * This is usually a module request from the shopware admin
18
- */
19
- fromBrowser<Payload = unknown>(req: Request): Promise<Context<Shop, Payload>>;
20
- }
21
- /**
22
- * Context is the parsed data from the request
23
- */
24
- export declare class Context<Shop extends ShopInterface = ShopInterface, Payload = unknown> {
25
- shop: Shop;
26
- payload: Payload;
27
- httpClient: HttpClient;
28
- constructor(shop: Shop, payload: Payload, httpClient: HttpClient);
29
- }
30
- //# sourceMappingURL=context-resolver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-resolver.d.ts","sourceRoot":"","sources":["../../src/context-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD;;;GAGG;AACH,qBAAa,eAAe,CAAC,IAAI,SAAS,aAAa,GAAG,aAAa;IAC1D,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,SAAS;IAElC;;OAEG;IACU,OAAO,CAAC,OAAO,GAAG,OAAO,EACrC,GAAG,EAAE,OAAO,GACV,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAmClC;;;OAGG;IACU,WAAW,CAAC,OAAO,GAAG,OAAO,EACzC,GAAG,EAAE,OAAO,GACV,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;CA6BlC;AAED;;GAEG;AACH,qBAAa,OAAO,CACnB,IAAI,SAAS,aAAa,GAAG,aAAa,EAC1C,OAAO,GAAG,OAAO;IAGT,IAAI,EAAE,IAAI;IACV,OAAO,EAAE,OAAO;IAChB,UAAU,EAAE,UAAU;gBAFtB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,UAAU;CAE9B"}
@@ -1,65 +0,0 @@
1
- import { HttpClient } from "./http-client.js";
2
- /**
3
- * ContextResolver is a helper class to create a Context object from a request.
4
- * The context contains the shop, the payload and an instance of the HttpClient
5
- */
6
- export class ContextResolver {
7
- app;
8
- constructor(app) {
9
- this.app = app;
10
- }
11
- /**
12
- * Create a context from a request body
13
- */
14
- async fromAPI(req) {
15
- const webHookContent = await req.text();
16
- const webHookBody = JSON.parse(webHookContent);
17
- const shop = await this.app.repository.getShopById(webHookBody.source.shopId);
18
- if (shop === null) {
19
- throw new Error(`Cannot find shop by id ${webHookBody.source.shopId}`);
20
- }
21
- const signature = req.headers.get("shopware-shop-signature");
22
- if (signature === null) {
23
- throw new Error("Missing shopware-shop-signature header");
24
- }
25
- if (!(await this.app.signer.verify(signature, webHookContent, shop.getShopSecret()))) {
26
- throw new Error("Invalid signature");
27
- }
28
- return new Context(shop, webHookBody, new HttpClient(shop));
29
- }
30
- /**
31
- * Create a context from a request query parameters
32
- * This is usually a module request from the shopware admin
33
- */
34
- async fromBrowser(req) {
35
- const url = new URL(req.url);
36
- const shopId = url.searchParams.get("shop-id");
37
- if (shopId === null) {
38
- throw new Error("Missing shop-id query parameter");
39
- }
40
- const shop = await this.app.repository.getShopById(shopId);
41
- if (shop === null) {
42
- throw new Error(`Cannot find shop by id ${shopId}`);
43
- }
44
- await this.app.signer.verifyGetRequest(req, shop.getShopSecret());
45
- const paramsObject = {};
46
- url.searchParams.forEach((value, key) => {
47
- paramsObject[key] = value;
48
- });
49
- return new Context(shop, paramsObject, new HttpClient(shop));
50
- }
51
- }
52
- /**
53
- * Context is the parsed data from the request
54
- */
55
- export class Context {
56
- shop;
57
- payload;
58
- httpClient;
59
- constructor(shop, payload, httpClient) {
60
- this.shop = shop;
61
- this.payload = payload;
62
- this.httpClient = httpClient;
63
- }
64
- }
65
- //# sourceMappingURL=context-resolver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-resolver.js","sourceRoot":"","sources":["../../src/context-resolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C;;;GAGG;AACH,MAAM,OAAO,eAAe;IACP;IAApB,YAAoB,GAAc;QAAd,QAAG,GAAH,GAAG,CAAW;IAAG,CAAC;IAEtC;;OAEG;IACI,KAAK,CAAC,OAAO,CACnB,GAAY;QAEZ,MAAM,cAAc,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QACxC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAE/C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,CACjD,WAAW,CAAC,MAAM,CAAC,MAAM,CACzB,CAAC;QAEF,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,0BAA0B,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QACxE,CAAC;QAED,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;QAE7D,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;QAC3D,CAAC;QAED,IACC,CAAC,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAC7B,SAAS,EACT,cAAc,EACd,IAAI,CAAC,aAAa,EAAE,CACpB,CAAC,EACD,CAAC;YACF,MAAM,IAAI,KA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S;QAChB,eAAU,GAAV,UAAU,CAAY;IAC3B,CAAC;CACJ","sourcesContent":["import type { AppServer } from \"./app.js\";\nimport { HttpClient } from \"./http-client.js\";\nimport type { ShopInterface } from \"./repository.js\";\n\n/**\n * ContextResolver is a helper class to create a Context object from a request.\n * The context contains the shop, the payload and an instance of the HttpClient\n */\nexport class ContextResolver<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(private app: AppServer) {}\n\n\t/**\n\t * Create a context from a request body\n\t */\n\tpublic async fromAPI<Payload = unknown>(\n\t\treq: Request,\n\t): Promise<Context<Shop, Payload>> {\n\t\tconst webHookContent = await req.text();\n\t\tconst webHookBody = JSON.parse(webHookContent);\n\n\t\tconst shop = await this.app.repository.getShopById(\n\t\t\twebHookBody.source.shopId,\n\t\t);\n\n\t\tif (shop === null) {\n\t\t\tthrow new Error(`Cannot find shop by id ${webHookBody.source.shopId}`);\n\t\t}\n\n\t\tconst signature = req.headers.get(\"shopware-shop-signature\");\n\n\t\tif (signature === null) {\n\t\t\tthrow new Error(\"Missing shopware-shop-signature header\");\n\t\t}\n\n\t\tif (\n\t\t\t!(await this.app.signer.verify(\n\t\t\t\tsignature,\n\t\t\t\twebHookContent,\n\t\t\t\tshop.getShopSecret(),\n\t\t\t))\n\t\t) {\n\t\t\tthrow new Error(\"Invalid signature\");\n\t\t}\n\n\t\treturn new Context<Shop, Payload>(\n\t\t\tshop as Shop,\n\t\t\twebHookBody,\n\t\t\tnew HttpClient(shop),\n\t\t);\n\t}\n\n\t/**\n\t * Create a context from a request query parameters\n\t * This is usually a module request from the shopware admin\n\t */\n\tpublic async fromBrowser<Payload = unknown>(\n\t\treq: Request,\n\t): Promise<Context<Shop, Payload>> {\n\t\tconst url = new URL(req.url);\n\n\t\tconst shopId = url.searchParams.get(\"shop-id\");\n\n\t\tif (shopId === null) {\n\t\t\tthrow new Error(\"Missing shop-id query parameter\");\n\t\t}\n\n\t\tconst shop = await this.app.repository.getShopById(shopId);\n\n\t\tif (shop === null) {\n\t\t\tthrow new Error(`Cannot find shop by id ${shopId}`);\n\t\t}\n\n\t\tawait this.app.signer.verifyGetRequest(req, shop.getShopSecret());\n\n\t\tconst paramsObject: Record<string, string> = {};\n\n\t\turl.searchParams.forEach((value, key) => {\n\t\t\tparamsObject[key] = value;\n\t\t});\n\n\t\treturn new Context<Shop, Payload>(\n\t\t\tshop as Shop,\n\t\t\tparamsObject as Payload,\n\t\t\tnew HttpClient(shop),\n\t\t);\n\t}\n}\n\n/**\n * Context is the parsed data from the request\n */\nexport class Context<\n\tShop extends ShopInterface = ShopInterface,\n\tPayload = unknown,\n> {\n\tconstructor(\n\t\tpublic shop: Shop,\n\t\tpublic payload: Payload,\n\t\tpublic httpClient: HttpClient,\n\t) {}\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 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AAC,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,IAAY,EAAE,MAAM,GAAG,GAAG;IAC/C,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;QACzC,MAAM;QACN,OAAO,EAAE;YACR,cAAc,EAAE,kBAAkB;SAClC;KACD,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,GAAW;IAChC,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAEvB,OAAO,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { AppServer } from \"../app.js\";\nimport type { Context } from \"../context-resolver.js\";\nimport type { ShopInterface, ShopRepositoryInterface } from \"../repository.js\";\n\ninterface MiddlewareConfig {\n\tappName: string | ((c: HonoContext<DataTypes>) => string);\n\tappSecret: string | ((c: HonoContext<DataTypes>) => string);\n\tappUrl?: string | null;\n\tregistrationUrl?: string | null;\n\tregisterConfirmationUrl?: string | null;\n\tappPath?: string | null;\n\tshopRepository:\n\t\t| ShopRepositoryInterface\n\t\t| ((c: HonoContext<DataTypes>) => ShopRepositoryInterface);\n}\n\ninterface DataTypes {\n\tapp: AppServer;\n\tcontext: Context<ShopInterface, unknown>;\n\tshop: ShopInterface;\n}\n\ninterface HonoContext<DataTypes> {\n\tenv: any;\n\treq: {\n\t\tpath: string;\n\t\tmethod: string;\n\t\turl: string;\n\t\traw: Request;\n\t};\n\theader: (key: string, value: string) => void;\n\tres: Response;\n\tget<K extends keyof DataTypes>(key: K): DataTypes[K];\n\tset<K extends keyof DataTypes>(key: K, value: DataTypes[K]): void;\n}\n\ninterface Hono {\n\tuse: (\n\t\tpath: string,\n\t\thandler: (ctx: HonoContext<DataTypes>, next: () => Promise<void>) => void,\n\t) => void;\n\tget: (\n\t\tpath: string,\n\t\thandler: (ctx: HonoContext<DataTypes>, next: () => void) => void,\n\t) => void;\n\tpost: (\n\t\tpath: string,\n\t\thandler: (ctx: HonoContext<DataTypes>, next: () => void) => void,\n\t) => void;\n}\n\nlet app: AppServer | null = null;\n\n/**\n * Configure the Hono server to handle the app registration and context resolution\n */\nexport function configureAppServer(\n\thonoExternal: unknown,\n\tcfg: MiddlewareConfig,\n) {\n\tconst hono = honoExternal as Hono;\n\n\tcfg.registrationUrl = cfg.registrationUrl || \"/app/register\";\n\tcfg.registerConfirmationUrl =\n\t\tcfg.registerConfirmationUrl || \"/app/register/confirm\";\n\tcfg.appPath = cfg.appPath || \"/app/*\";\n\n\thono.use(\"*\", async (ctx, next) => {\n\t\tif (app === null) {\n\t\t\tconst appUrl = cfg.appUrl || buildBaseUrl(ctx.req.url);\n\n\t\t\tif (typeof cfg.shopRepository === \"function\") {\n\t\t\t\tcfg.shopRepository = cfg.shopRepository(ctx);\n\t\t\t}\n\n\t\t\tif (typeof cfg.appName === \"function\") {\n\t\t\t\tcfg.appName = cfg.appName(ctx);\n\t\t\t}\n\n\t\t\tif (typeof cfg.appSecret === \"function\") {\n\t\t\t\tcfg.appSecret = cfg.appSecret(ctx);\n\t\t\t}\n\n\t\t\tapp = new AppServer(\n\t\t\t\t{\n\t\t\t\t\tappName: cfg.appName,\n\t\t\t\t\tappSecret: cfg.appSecret,\n\t\t\t\t\tauthorizeCallbackUrl: appUrl + cfg.registerConfirmationUrl,\n\t\t\t\t},\n\t\t\t\tcfg.shopRepository,\n\t\t\t);\n\t\t}\n\n\t\tctx.set(\"app\", app);\n\n\t\tawait next();\n\t});\n\n\thono.use(cfg.appPath, async (ctx, next) => {\n\t\tconst app = ctx.get(\"app\") as AppServer;\n\n\t\t// Don't validate signature for registration\n\t\tif (\n\t\t\tctx.req.path === cfg.registrationUrl ||\n\t\t\tctx.req.path === cfg.registerConfirmationUrl\n\t\t) {\n\t\t\tawait next();\n\t\t\treturn;\n\t\t}\n\n\t\tlet context: Context<ShopInterface, unknown>;\n\t\ttry {\n\t\t\tcontext =\n\t\t\t\tctx.req.method === \"GET\"\n\t\t\t\t\t? await app.contextResolver.fromBrowser(ctx.req.raw)\n\t\t\t\t\t: await app.contextResolver.fromAPI(ctx.req.raw);\n\t\t} catch (_e) {\n\t\t\treturn jsonResponse({ message: \"Invalid request\" }, 400);\n\t\t}\n\n\t\tctx.set(\"shop\", context.shop);\n\t\tctx.set(\"context\", context);\n\n\t\tawait next();\n\n\t\tconst cloned = ctx.res.clone();\n\n\t\tawait ctx\n\t\t\t.get(\"app\")\n\t\t\t.signer.signResponse(cloned, ctx.get(\"shop\").getShopSecret());\n\n\t\tctx.header(\n\t\t\t\"shopware-app-signature\",\n\t\t\tcloned.headers.get(\"shopware-app-signature\") as string,\n\t\t);\n\t});\n\n\thono.get(cfg.registrationUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.authorize(ctx.req.raw);\n\t});\n\n\thono.post(cfg.registerConfirmationUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.authorizeCallback(ctx.req.raw);\n\t});\n}\n\nfunction jsonResponse(body: object, status = 200): Response {\n\treturn new Response(JSON.stringify(body), {\n\t\tstatus,\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t},\n\t});\n}\n\nfunction buildBaseUrl(url: string): string {\n\tconst u = new URL(url);\n\n\treturn `${u.protocol}//${u.host}`;\n}\n"]}
@@ -1,13 +0,0 @@
1
- /**
2
- * Opens in the Administration a new tab to the given URL and adds the shop-id as query parameter with the signature
3
- */
4
- export declare function createNewTabResponse(redirectUrl: string): Response;
5
- /**
6
- * Shows in the Administration a new notification with the given status and message
7
- */
8
- export declare function createNotificationResponse(status: "success" | "error" | "info" | "warning", message: string): Response;
9
- /**
10
- * Opens in the Administration a new modal with the given iframe URL
11
- */
12
- export declare function createModalResponse(iframeUrl: string, size?: "small" | "medium" | "large" | "fullscreen", expand?: boolean): Response;
13
- //# sourceMappingURL=app-actions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"app-actions.d.ts","sourceRoot":"","sources":["../../../src/helper/app-actions.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,CAclE;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACzC,MAAM,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,EAChD,OAAO,EAAE,MAAM,GACb,QAAQ,CAeV;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAClC,SAAS,EAAE,MAAM,EACjB,IAAI,GAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,YAAuB,EAC5D,MAAM,UAAQ,GACZ,QAAQ,CAgBV"}
@@ -1,49 +0,0 @@
1
- /**
2
- * Opens in the Administration a new tab to the given URL and adds the shop-id as query parameter with the signature
3
- */
4
- export function createNewTabResponse(redirectUrl) {
5
- return new Response(JSON.stringify({
6
- actionType: "openNewTab",
7
- payload: {
8
- redirectUrl,
9
- },
10
- }), {
11
- headers: {
12
- "content-type": "application/json",
13
- },
14
- });
15
- }
16
- /**
17
- * Shows in the Administration a new notification with the given status and message
18
- */
19
- export function createNotificationResponse(status, message) {
20
- return new Response(JSON.stringify({
21
- actionType: "notification",
22
- payload: {
23
- status,
24
- message,
25
- },
26
- }), {
27
- headers: {
28
- "content-type": "application/json",
29
- },
30
- });
31
- }
32
- /**
33
- * Opens in the Administration a new modal with the given iframe URL
34
- */
35
- export function createModalResponse(iframeUrl, size = "medium", expand = false) {
36
- return new Response(JSON.stringify({
37
- actionType: "openModal",
38
- payload: {
39
- iframeUrl,
40
- size,
41
- expand,
42
- },
43
- }), {
44
- headers: {
45
- "content-type": "application/json",
46
- },
47
- });
48
- }
49
- //# sourceMappingURL=app-actions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"app-actions.js","sourceRoot":"","sources":["../../../src/helper/app-actions.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,WAAmB;IACvD,OAAO,IAAI,QAAQ,CAClB,IAAI,CAAC,SAAS,CAAC;QACd,UAAU,EAAE,YAAY;QACxB,OAAO,EAAE;YACR,WAAW;SACX;KACD,CAAC,EACF;QACC,OAAO,EAAE;YACR,cAAc,EAAE,kBAAkB;SAClC;KACD,CACD,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,0BAA0B,CACzC,MAAgD,EAChD,OAAe;IAEf,OAAO,IAAI,QAAQ,CAClB,IAAI,CAAC,SAAS,CAAC;QACd,UAAU,EAAE,cAAc;QAC1B,OAAO,EAAE;YACR,MAAM;YACN,OAAO;SACP;KACD,CAAC,EACF;QACC,OAAO,EAAE;YACR,cAAc,EAAE,kBAAkB;SAClC;KACD,CACD,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAClC,SAAiB,EACjB,OAAoD,QAAQ,EAC5D,MAAM,GAAG,KAAK;IAEd,OAAO,IAAI,QAAQ,CAClB,IAAI,CAAC,SAAS,CAAC;QACd,UAAU,EAAE,WAAW;QACvB,OAAO,EAAE;YACR,SAAS;YACT,IAAI;YACJ,MAAM;SACN;KACD,CAAC,EACF;QACC,OAAO,EAAE;YACR,cAAc,EAAE,kBAAkB;SAClC;KACD,CACD,CAAC;AACH,CAAC","sourcesContent":["/**\n * Opens in the Administration a new tab to the given URL and adds the shop-id as query parameter with the signature\n */\nexport function createNewTabResponse(redirectUrl: string): Response {\n\treturn new Response(\n\t\tJSON.stringify({\n\t\t\tactionType: \"openNewTab\",\n\t\t\tpayload: {\n\t\t\t\tredirectUrl,\n\t\t\t},\n\t\t}),\n\t\t{\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t},\n\t\t},\n\t);\n}\n\n/**\n * Shows in the Administration a new notification with the given status and message\n */\nexport function createNotificationResponse(\n\tstatus: \"success\" | \"error\" | \"info\" | \"warning\",\n\tmessage: string,\n): Response {\n\treturn new Response(\n\t\tJSON.stringify({\n\t\t\tactionType: \"notification\",\n\t\t\tpayload: {\n\t\t\t\tstatus,\n\t\t\t\tmessage,\n\t\t\t},\n\t\t}),\n\t\t{\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t},\n\t\t},\n\t);\n}\n\n/**\n * Opens in the Administration a new modal with the given iframe URL\n */\nexport function createModalResponse(\n\tiframeUrl: string,\n\tsize: \"small\" | \"medium\" | \"large\" | \"fullscreen\" = \"medium\",\n\texpand = false,\n): Response {\n\treturn new Response(\n\t\tJSON.stringify({\n\t\t\tactionType: \"openModal\",\n\t\t\tpayload: {\n\t\t\t\tiframeUrl,\n\t\t\t\tsize,\n\t\t\t\texpand,\n\t\t\t},\n\t\t}),\n\t\t{\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t},\n\t\t},\n\t);\n}\n"]}