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

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 (117) hide show
  1. package/dist/commonjs/helper/admin-api.d.ts +56 -0
  2. package/dist/commonjs/helper/admin-api.d.ts.map +1 -0
  3. package/dist/commonjs/helper/admin-api.js +126 -0
  4. package/dist/commonjs/helper/admin-api.js.map +1 -0
  5. package/dist/commonjs/helper/criteria.d.ts +377 -0
  6. package/dist/commonjs/helper/criteria.d.ts.map +1 -0
  7. package/dist/commonjs/helper/criteria.js +456 -0
  8. package/dist/commonjs/helper/criteria.js.map +1 -0
  9. package/dist/commonjs/http-client.js +2 -1
  10. package/dist/commonjs/http-client.js.map +1 -1
  11. package/dist/commonjs/integration/better-sqlite3.d.ts +11 -0
  12. package/dist/commonjs/integration/better-sqlite3.d.ts.map +1 -0
  13. package/dist/commonjs/integration/better-sqlite3.js +58 -0
  14. package/dist/commonjs/integration/better-sqlite3.js.map +1 -0
  15. package/dist/esm/helper/admin-api.d.ts +56 -0
  16. package/dist/esm/helper/admin-api.d.ts.map +1 -0
  17. package/dist/esm/helper/admin-api.js +117 -0
  18. package/dist/esm/helper/admin-api.js.map +1 -0
  19. package/dist/esm/helper/criteria.d.ts +377 -0
  20. package/dist/esm/helper/criteria.d.ts.map +1 -0
  21. package/dist/esm/helper/criteria.js +452 -0
  22. package/dist/esm/helper/criteria.js.map +1 -0
  23. package/dist/esm/http-client.js +2 -1
  24. package/dist/esm/http-client.js.map +1 -1
  25. package/dist/esm/integration/better-sqlite3.d.ts +11 -0
  26. package/dist/esm/integration/better-sqlite3.d.ts.map +1 -0
  27. package/dist/esm/integration/better-sqlite3.js +51 -0
  28. package/dist/esm/integration/better-sqlite3.js.map +1 -0
  29. package/package.json +206 -141
  30. package/dist/commonjs/context-resolver.test.d.ts +0 -2
  31. package/dist/commonjs/context-resolver.test.d.ts.map +0 -1
  32. package/dist/commonjs/context-resolver.test.js +0 -81
  33. package/dist/commonjs/context-resolver.test.js.map +0 -1
  34. package/dist/commonjs/helper/app-actions.test.d.ts +0 -2
  35. package/dist/commonjs/helper/app-actions.test.d.ts.map +0 -1
  36. package/dist/commonjs/helper/app-actions.test.js +0 -31
  37. package/dist/commonjs/helper/app-actions.test.js.map +0 -1
  38. package/dist/commonjs/http-client.test.d.ts +0 -2
  39. package/dist/commonjs/http-client.test.d.ts.map +0 -1
  40. package/dist/commonjs/http-client.test.js +0 -71
  41. package/dist/commonjs/http-client.test.js.map +0 -1
  42. package/dist/commonjs/integration/bun-sqlite.test.d.ts +0 -2
  43. package/dist/commonjs/integration/bun-sqlite.test.d.ts.map +0 -1
  44. package/dist/commonjs/integration/bun-sqlite.test.js +0 -24
  45. package/dist/commonjs/integration/bun-sqlite.test.js.map +0 -1
  46. package/dist/commonjs/integration/cloudflare.test.d.ts +0 -2
  47. package/dist/commonjs/integration/cloudflare.test.d.ts.map +0 -1
  48. package/dist/commonjs/integration/cloudflare.test.js +0 -39
  49. package/dist/commonjs/integration/cloudflare.test.js.map +0 -1
  50. package/dist/commonjs/integration/deno.test.d.ts +0 -2
  51. package/dist/commonjs/integration/deno.test.d.ts.map +0 -1
  52. package/dist/commonjs/integration/deno.test.js +0 -48
  53. package/dist/commonjs/integration/deno.test.js.map +0 -1
  54. package/dist/commonjs/integration/dynamodb.test.d.ts +0 -2
  55. package/dist/commonjs/integration/dynamodb.test.d.ts.map +0 -1
  56. package/dist/commonjs/integration/dynamodb.test.js +0 -132
  57. package/dist/commonjs/integration/dynamodb.test.js.map +0 -1
  58. package/dist/commonjs/integration/hono.test.d.ts +0 -2
  59. package/dist/commonjs/integration/hono.test.d.ts.map +0 -1
  60. package/dist/commonjs/integration/hono.test.js +0 -86
  61. package/dist/commonjs/integration/hono.test.js.map +0 -1
  62. package/dist/commonjs/registration.test.d.ts +0 -2
  63. package/dist/commonjs/registration.test.d.ts.map +0 -1
  64. package/dist/commonjs/registration.test.js +0 -59
  65. package/dist/commonjs/registration.test.js.map +0 -1
  66. package/dist/commonjs/repository.test.d.ts +0 -2
  67. package/dist/commonjs/repository.test.d.ts.map +0 -1
  68. package/dist/commonjs/repository.test.js +0 -32
  69. package/dist/commonjs/repository.test.js.map +0 -1
  70. package/dist/commonjs/signer.test.d.ts +0 -2
  71. package/dist/commonjs/signer.test.d.ts.map +0 -1
  72. package/dist/commonjs/signer.test.js +0 -25
  73. package/dist/commonjs/signer.test.js.map +0 -1
  74. package/dist/esm/context-resolver.test.d.ts +0 -2
  75. package/dist/esm/context-resolver.test.d.ts.map +0 -1
  76. package/dist/esm/context-resolver.test.js +0 -79
  77. package/dist/esm/context-resolver.test.js.map +0 -1
  78. package/dist/esm/helper/app-actions.test.d.ts +0 -2
  79. package/dist/esm/helper/app-actions.test.d.ts.map +0 -1
  80. package/dist/esm/helper/app-actions.test.js +0 -29
  81. package/dist/esm/helper/app-actions.test.js.map +0 -1
  82. package/dist/esm/http-client.test.d.ts +0 -2
  83. package/dist/esm/http-client.test.d.ts.map +0 -1
  84. package/dist/esm/http-client.test.js +0 -69
  85. package/dist/esm/http-client.test.js.map +0 -1
  86. package/dist/esm/integration/bun-sqlite.test.d.ts +0 -2
  87. package/dist/esm/integration/bun-sqlite.test.d.ts.map +0 -1
  88. package/dist/esm/integration/bun-sqlite.test.js +0 -22
  89. package/dist/esm/integration/bun-sqlite.test.js.map +0 -1
  90. package/dist/esm/integration/cloudflare.test.d.ts +0 -2
  91. package/dist/esm/integration/cloudflare.test.d.ts.map +0 -1
  92. package/dist/esm/integration/cloudflare.test.js +0 -37
  93. package/dist/esm/integration/cloudflare.test.js.map +0 -1
  94. package/dist/esm/integration/deno.test.d.ts +0 -2
  95. package/dist/esm/integration/deno.test.d.ts.map +0 -1
  96. package/dist/esm/integration/deno.test.js +0 -46
  97. package/dist/esm/integration/deno.test.js.map +0 -1
  98. package/dist/esm/integration/dynamodb.test.d.ts +0 -2
  99. package/dist/esm/integration/dynamodb.test.d.ts.map +0 -1
  100. package/dist/esm/integration/dynamodb.test.js +0 -130
  101. package/dist/esm/integration/dynamodb.test.js.map +0 -1
  102. package/dist/esm/integration/hono.test.d.ts +0 -2
  103. package/dist/esm/integration/hono.test.d.ts.map +0 -1
  104. package/dist/esm/integration/hono.test.js +0 -84
  105. package/dist/esm/integration/hono.test.js.map +0 -1
  106. package/dist/esm/registration.test.d.ts +0 -2
  107. package/dist/esm/registration.test.d.ts.map +0 -1
  108. package/dist/esm/registration.test.js +0 -57
  109. package/dist/esm/registration.test.js.map +0 -1
  110. package/dist/esm/repository.test.d.ts +0 -2
  111. package/dist/esm/repository.test.d.ts.map +0 -1
  112. package/dist/esm/repository.test.js +0 -30
  113. package/dist/esm/repository.test.js.map +0 -1
  114. package/dist/esm/signer.test.d.ts +0 -2
  115. package/dist/esm/signer.test.d.ts.map +0 -1
  116. package/dist/esm/signer.test.js +0 -23
  117. package/dist/esm/signer.test.js.map +0 -1
package/package.json CHANGED
@@ -1,143 +1,208 @@
1
1
  {
2
- "name": "@shopware-ag/app-server-sdk",
3
- "version": "1.1.0",
4
- "description": "App Server SDK for JavaScript",
5
- "type": "module",
6
- "license": "MIT",
7
- "keywords": ["shopware", "app-server"],
8
- "exports": {
9
- "./package.json": "./package.json",
10
- ".": {
11
- "import": {
12
- "types": "./dist/esm/mod.d.ts",
13
- "default": "./dist/esm/mod.js"
14
- },
15
- "require": {
16
- "types": "./dist/commonjs/mod.d.ts",
17
- "default": "./dist/commonjs/mod.js"
18
- }
19
- },
20
- "./helper/app-actions": {
21
- "import": {
22
- "types": "./dist/esm/helper/app-actions.d.ts",
23
- "default": "./dist/esm/helper/app-actions.js"
24
- },
25
- "require": {
26
- "types": "./dist/commonjs/helper/app-actions.d.ts",
27
- "default": "./dist/commonjs/helper/app-actions.js"
28
- }
29
- },
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"
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": {
81
- "import": {
82
- "types": "./dist/esm/types.d.ts",
83
- "default": "./dist/esm/types.js"
84
- },
85
- "require": {
86
- "types": "./dist/commonjs/types.d.ts",
87
- "default": "./dist/commonjs/types.js"
88
- }
89
- }
90
- },
91
- "main": "./dist/commonjs/mod.js",
92
- "module": "./dist/esm/mod.js",
93
- "types": "./dist/commonjs/mod.d.ts",
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
- },
114
- "devDependencies": {
115
- "@biomejs/biome": "1.8.3",
116
- "@types/bun": "^1.1.6",
117
- "tshy": "^3.0.2",
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"
122
- },
123
- "tshy": {
124
- "exports": {
125
- "./package.json": "./package.json",
126
- ".": "./src/mod.ts",
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",
133
- "./types": "./src/types.ts"
134
- }
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"]
2
+ "name": "@shopware-ag/app-server-sdk",
3
+ "version": "1.1.2",
4
+ "description": "App Server SDK for JavaScript",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "keywords": [
8
+ "shopware",
9
+ "app-server"
10
+ ],
11
+ "exports": {
12
+ "./package.json": "./package.json",
13
+ ".": {
14
+ "import": {
15
+ "types": "./dist/esm/mod.d.ts",
16
+ "default": "./dist/esm/mod.js"
17
+ },
18
+ "require": {
19
+ "types": "./dist/commonjs/mod.d.ts",
20
+ "default": "./dist/commonjs/mod.js"
21
+ }
22
+ },
23
+ "./helper/app-actions": {
24
+ "import": {
25
+ "types": "./dist/esm/helper/app-actions.d.ts",
26
+ "default": "./dist/esm/helper/app-actions.js"
27
+ },
28
+ "require": {
29
+ "types": "./dist/commonjs/helper/app-actions.d.ts",
30
+ "default": "./dist/commonjs/helper/app-actions.js"
31
+ }
32
+ },
33
+ "./helper/criteria": {
34
+ "import": {
35
+ "types": "./dist/esm/helper/criteria.d.ts",
36
+ "default": "./dist/esm/helper/criteria.js"
37
+ },
38
+ "require": {
39
+ "types": "./dist/commonjs/helper/criteria.d.ts",
40
+ "default": "./dist/commonjs/helper/criteria.js"
41
+ }
42
+ },
43
+ "./helper/admin-api": {
44
+ "import": {
45
+ "types": "./dist/esm/helper/admin-api.d.ts",
46
+ "default": "./dist/esm/helper/admin-api.js"
47
+ },
48
+ "require": {
49
+ "types": "./dist/commonjs/helper/admin-api.d.ts",
50
+ "default": "./dist/commonjs/helper/admin-api.js"
51
+ }
52
+ },
53
+ "./helper/uuid": {
54
+ "import": {
55
+ "types": "./dist/esm/helper/uuid.d.ts",
56
+ "default": "./dist/esm/helper/uuid.js"
57
+ },
58
+ "require": {
59
+ "types": "./dist/commonjs/helper/uuid.d.ts",
60
+ "default": "./dist/commonjs/helper/uuid.js"
61
+ }
62
+ },
63
+ "./integration/hono": {
64
+ "import": {
65
+ "types": "./dist/esm/integration/hono.d.ts",
66
+ "default": "./dist/esm/integration/hono.js"
67
+ },
68
+ "require": {
69
+ "types": "./dist/commonjs/integration/hono.d.ts",
70
+ "default": "./dist/commonjs/integration/hono.js"
71
+ }
72
+ },
73
+ "./integration/cloudflare-kv": {
74
+ "import": {
75
+ "types": "./dist/esm/integration/cloudflare-kv.d.ts",
76
+ "default": "./dist/esm/integration/cloudflare-kv.js"
77
+ },
78
+ "require": {
79
+ "types": "./dist/commonjs/integration/cloudflare-kv.d.ts",
80
+ "default": "./dist/commonjs/integration/cloudflare-kv.js"
81
+ }
82
+ },
83
+ "./integration/deno-kv": {
84
+ "import": {
85
+ "types": "./dist/esm/integration/deno-kv.d.ts",
86
+ "default": "./dist/esm/integration/deno-kv.js"
87
+ },
88
+ "require": {
89
+ "types": "./dist/commonjs/integration/deno-kv.d.ts",
90
+ "default": "./dist/commonjs/integration/deno-kv.js"
91
+ }
92
+ },
93
+ "./integration/dynamodb": {
94
+ "import": {
95
+ "types": "./dist/esm/integration/dynamodb.d.ts",
96
+ "default": "./dist/esm/integration/dynamodb.js"
97
+ },
98
+ "require": {
99
+ "types": "./dist/commonjs/integration/dynamodb.d.ts",
100
+ "default": "./dist/commonjs/integration/dynamodb.js"
101
+ }
102
+ },
103
+ "./integration/bun-sqlite": {
104
+ "import": {
105
+ "types": "./dist/esm/integration/bun-sqlite.d.ts",
106
+ "default": "./dist/esm/integration/bun-sqlite.js"
107
+ },
108
+ "require": {
109
+ "types": "./dist/commonjs/integration/bun-sqlite.d.ts",
110
+ "default": "./dist/commonjs/integration/bun-sqlite.js"
111
+ }
112
+ },
113
+ "./integration/better-sqlite3": {
114
+ "import": {
115
+ "types": "./dist/esm/integration/better-sqlite3.d.ts",
116
+ "default": "./dist/esm/integration/better-sqlite3.js"
117
+ },
118
+ "require": {
119
+ "types": "./dist/commonjs/integration/better-sqlite3.d.ts",
120
+ "default": "./dist/commonjs/integration/better-sqlite3.js"
121
+ }
122
+ },
123
+ "./types": {
124
+ "import": {
125
+ "types": "./dist/esm/types.d.ts",
126
+ "default": "./dist/esm/types.js"
127
+ },
128
+ "require": {
129
+ "types": "./dist/commonjs/types.d.ts",
130
+ "default": "./dist/commonjs/types.js"
131
+ }
132
+ }
133
+ },
134
+ "main": "./dist/commonjs/mod.js",
135
+ "module": "./dist/esm/mod.js",
136
+ "types": "./dist/commonjs/mod.d.ts",
137
+ "files": [
138
+ "dist"
139
+ ],
140
+ "publishConfig": {
141
+ "access": "public",
142
+ "provenance": true
143
+ },
144
+ "repository": {
145
+ "url": "https://github.com/shopware/app-sdk-js"
146
+ },
147
+ "peerDependencies": {
148
+ "@aws-sdk/client-dynamodb": "~3.637",
149
+ "@aws-sdk/lib-dynamodb": "~3.637",
150
+ "better-sqlite3": "^11",
151
+ "hono": "^4"
152
+ },
153
+ "peerDependenciesMeta": {
154
+ "hono": {
155
+ "optional": true
156
+ },
157
+ "@aws-sdk/client-dynamodb": {
158
+ "optional": true
159
+ },
160
+ "@aws-sdk/lib-dynamodb": {
161
+ "optional": true
162
+ },
163
+ "better-sqlite3": {
164
+ "optional": true
165
+ }
166
+ },
167
+ "devDependencies": {
168
+ "@aws-sdk/client-dynamodb": "~3.637",
169
+ "@aws-sdk/lib-dynamodb": "~3.637",
170
+ "@biomejs/biome": "1.8.3",
171
+ "@cloudflare/workers-types": "^4.20240821.1",
172
+ "@types/better-sqlite3": "^7.6.11",
173
+ "@types/bun": "^1.1.6",
174
+ "better-sqlite3": "^11",
175
+ "hono": "^4.5.6",
176
+ "tshy": "^3.0.2"
177
+ },
178
+ "tshy": {
179
+ "exports": {
180
+ "./package.json": "./package.json",
181
+ ".": "./src/mod.ts",
182
+ "./helper/app-actions": "./src/helper/app-actions.ts",
183
+ "./helper/criteria": "./src/helper/criteria.ts",
184
+ "./helper/admin-api": "./src/helper/admin-api.ts",
185
+ "./helper/uuid": "./src/helper/uuid.ts",
186
+ "./integration/hono": "./src/integration/hono.ts",
187
+ "./integration/cloudflare-kv": "./src/integration/cloudflare-kv.ts",
188
+ "./integration/deno-kv": "./src/integration/deno-kv.ts",
189
+ "./integration/dynamodb": "./src/integration/dynamodb.ts",
190
+ "./integration/bun-sqlite": "./src/integration/bun-sqlite.ts",
191
+ "./integration/better-sqlite3": "./src/integration/better-sqlite3.ts",
192
+ "./types": "./src/types.ts"
193
+ },
194
+ "exclude": [
195
+ "src/**/*.test.ts"
196
+ ]
197
+ },
198
+ "scripts": {
199
+ "init": "tshy && biome format . --write",
200
+ "lint": "biome ci .",
201
+ "lint:fix": "biome lint . --write && biome format . --write && biome check . --write",
202
+ "typecheck": "tsc --noEmit"
203
+ },
204
+ "trustedDependencies": [
205
+ "@biomejs/biome",
206
+ "better-sqlite3"
207
+ ]
143
208
  }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=context-resolver.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-resolver.test.d.ts","sourceRoot":"","sources":["../../src/context-resolver.test.ts"],"names":[],"mappings":""}
@@ -1,81 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const bun_test_1 = require("bun:test");
4
- const app_js_1 = require("../src/app.js");
5
- const context_resolver_js_1 = require("../src/context-resolver.js");
6
- const repository_js_1 = require("../src/repository.js");
7
- (0, bun_test_1.describe)("Context Resolver", async () => {
8
- const app = new app_js_1.AppServer({
9
- appName: "test",
10
- appSecret: "test",
11
- authorizeCallbackUrl: "test",
12
- }, new repository_js_1.InMemoryShopRepository());
13
- await app.repository.createShop("blaa", "test", "test");
14
- const contextResolver = new context_resolver_js_1.ContextResolver(app);
15
- (0, bun_test_1.test)("fromBrowser: shop does not exist", async () => {
16
- (0, bun_test_1.expect)(contextResolver.fromBrowser(new Request("https://example.com/?shop-id=test&shopware-shop-signature=aaa"))).rejects.toThrowError("Cannot find shop by id test");
17
- });
18
- (0, bun_test_1.test)("fromBrowser: missing header", async () => {
19
- (0, bun_test_1.expect)(contextResolver.fromBrowser(new Request("https://example.com/?shop-id=blaa"))).rejects.toThrowError("Missing shopware-shop-signature query parameter");
20
- });
21
- (0, bun_test_1.test)("fromBrowser: shop exists", async () => {
22
- app.signer.verifyGetRequest = bun_test_1.jest.fn().mockResolvedValue(true);
23
- const context = await contextResolver.fromBrowser(new Request("https://example.com/?shop-id=blaa&shopware-shop-signature=aaa"));
24
- (0, bun_test_1.expect)(context.payload).toEqual({
25
- "shop-id": "blaa",
26
- "shopware-shop-signature": "aaa",
27
- });
28
- });
29
- (0, bun_test_1.test)("fromSource: missing signature header", async () => {
30
- (0, bun_test_1.expect)(contextResolver.fromAPI(new Request("https://example.com/", {
31
- body: JSON.stringify({
32
- source: {
33
- shopId: "blaa",
34
- },
35
- }),
36
- }))).rejects.toThrowError("Missing shopware-shop-signature header");
37
- });
38
- (0, bun_test_1.test)("fromSource: shop does not exists", async () => {
39
- (0, bun_test_1.expect)(contextResolver.fromAPI(new Request("https://example.com/", {
40
- headers: {
41
- "shopware-shop-signature": "aaa",
42
- },
43
- body: JSON.stringify({
44
- source: {
45
- shopId: "test",
46
- },
47
- }),
48
- }))).rejects.toThrowError("Cannot find shop by id test");
49
- });
50
- (0, bun_test_1.test)("fromSource: invalid signature", async () => {
51
- (0, bun_test_1.expect)(contextResolver.fromAPI(new Request("https://example.com/", {
52
- headers: {
53
- "shopware-shop-signature": "aaa",
54
- },
55
- body: JSON.stringify({
56
- source: {
57
- shopId: "blaa",
58
- },
59
- }),
60
- }))).rejects.toThrowError("Invalid signature");
61
- });
62
- (0, bun_test_1.test)("fromSource: resolved", async () => {
63
- app.signer.verify = bun_test_1.jest.fn().mockResolvedValue(true);
64
- const ctx = await contextResolver.fromAPI(new Request("https://example.com/", {
65
- headers: {
66
- "shopware-shop-signature": "aaa",
67
- },
68
- body: JSON.stringify({
69
- source: {
70
- shopId: "blaa",
71
- },
72
- }),
73
- }));
74
- (0, bun_test_1.expect)(ctx.payload).toEqual({
75
- source: {
76
- shopId: "blaa",
77
- },
78
- });
79
- });
80
- });
81
- //# sourceMappingURL=context-resolver.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-resolver.test.js","sourceRoot":"","sources":["../../src/context-resolver.test.ts"],"names":[],"mappings":";;AAAA,uCAAwD;AACxD,0CAA0C;AAC1C,oEAA6D;AAC7D,wDAA0E;AAE1E,IAAA,mBAAQ,EAAC,kBAAkB,EAAE,KAAK,IAAI,EAAE;IACvC,MAAM,GAAG,GAAG,IAAI,kBAAS,CACxB;QACC,OAAO,EAAE,MAAM;QACf,SAAS,EAAE,MAAM;QACjB,oBAAoB,EAAE,MAAM;KAC5B,EACD,IAAI,sCAAsB,EAAE,CAC5B,CAAC;IAEF,MAAM,GAAG,CAAC,UAAU,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,MAAM,EAAE,MAAM;iBACd;aACD,CAAC;SACF,CAAC,CACF,CAAC;QAEF,IAAA,iBAAM,EAAC,GAAG,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;YAC3B,MAAM,EAAE;gBACP,MAAM,EAAE,MAAM;aACd;SACD,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, jest, test } from \"bun:test\";\nimport { AppServer } from \"../src/app.js\";\nimport { ContextResolver } from \"../src/context-resolver.js\";\nimport { InMemoryShopRepository, SimpleShop } from \"../src/repository.js\";\n\ndescribe(\"Context Resolver\", async () => {\n\tconst app = new AppServer(\n\t\t{\n\t\t\tappName: \"test\",\n\t\t\tappSecret: \"test\",\n\t\t\tauthorizeCallbackUrl: \"test\",\n\t\t},\n\t\tnew InMemoryShopRepository(),\n\t);\n\n\tawait app.repository.createShop(\"blaa\", \"test\", \"test\");\n\n\tconst contextResolver = new ContextResolver(app);\n\n\ttest(\"fromBrowser: shop does not exist\", async () => {\n\t\texpect(\n\t\t\tcontextResolver.fromBrowser(\n\t\t\t\tnew Request(\n\t\t\t\t\t\"https://example.com/?shop-id=test&shopware-shop-signature=aaa\",\n\t\t\t\t),\n\t\t\t),\n\t\t).rejects.toThrowError(\"Cannot find shop by id test\");\n\t});\n\n\ttest(\"fromBrowser: missing header\", async () => {\n\t\texpect(\n\t\t\tcontextResolver.fromBrowser(\n\t\t\t\tnew Request(\"https://example.com/?shop-id=blaa\"),\n\t\t\t),\n\t\t).rejects.toThrowError(\"Missing shopware-shop-signature query parameter\");\n\t});\n\n\ttest(\"fromBrowser: shop exists\", async () => {\n\t\tapp.signer.verifyGetRequest = jest.fn().mockResolvedValue(true);\n\n\t\tconst context = await contextResolver.fromBrowser(\n\t\t\tnew Request(\n\t\t\t\t\"https://example.com/?shop-id=blaa&shopware-shop-signature=aaa\",\n\t\t\t),\n\t\t);\n\n\t\texpect(context.payload).toEqual({\n\t\t\t\"shop-id\": \"blaa\",\n\t\t\t\"shopware-shop-signature\": \"aaa\",\n\t\t});\n\t});\n\n\ttest(\"fromSource: missing signature header\", async () => {\n\t\texpect(\n\t\t\tcontextResolver.fromAPI(\n\t\t\t\tnew Request(\"https://example.com/\", {\n\t\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t\tsource: {\n\t\t\t\t\t\t\tshopId: \"blaa\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t),\n\t\t).rejects.toThrowError(\"Missing shopware-shop-signature header\");\n\t});\n\n\ttest(\"fromSource: shop does not exists\", async () => {\n\t\texpect(\n\t\t\tcontextResolver.fromAPI(\n\t\t\t\tnew Request(\"https://example.com/\", {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"shopware-shop-signature\": \"aaa\",\n\t\t\t\t\t},\n\t\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t\tsource: {\n\t\t\t\t\t\t\tshopId: \"test\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t),\n\t\t).rejects.toThrowError(\"Cannot find shop by id test\");\n\t});\n\n\ttest(\"fromSource: invalid signature\", async () => {\n\t\texpect(\n\t\t\tcontextResolver.fromAPI(\n\t\t\t\tnew Request(\"https://example.com/\", {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"shopware-shop-signature\": \"aaa\",\n\t\t\t\t\t},\n\t\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t\tsource: {\n\t\t\t\t\t\t\tshopId: \"blaa\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t),\n\t\t).rejects.toThrowError(\"Invalid signature\");\n\t});\n\n\ttest(\"fromSource: resolved\", async () => {\n\t\tapp.signer.verify = jest.fn().mockResolvedValue(true);\n\n\t\tconst ctx = await contextResolver.fromAPI(\n\t\t\tnew Request(\"https://example.com/\", {\n\t\t\t\theaders: {\n\t\t\t\t\t\"shopware-shop-signature\": \"aaa\",\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tsource: {\n\t\t\t\t\t\tshopId: \"blaa\",\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t}),\n\t\t);\n\n\t\texpect(ctx.payload).toEqual({\n\t\t\tsource: {\n\t\t\t\tshopId: \"blaa\",\n\t\t\t},\n\t\t});\n\t});\n});\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=app-actions.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"app-actions.test.d.ts","sourceRoot":"","sources":["../../../src/helper/app-actions.test.ts"],"names":[],"mappings":""}
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const bun_test_1 = require("bun:test");
4
- const app_actions_js_1 = require("../../src/helper/app-actions.js");
5
- (0, bun_test_1.describe)("AppActions", async () => {
6
- (0, bun_test_1.test)("createNewTabResponse", async () => {
7
- const resp = (0, app_actions_js_1.createNewTabResponse)("test");
8
- (0, bun_test_1.expect)(resp.headers.get("content-type")).toBe("application/json");
9
- (0, bun_test_1.expect)(await resp.text()).toBe(JSON.stringify({
10
- actionType: "openNewTab",
11
- payload: { redirectUrl: "test" },
12
- }));
13
- });
14
- (0, bun_test_1.test)("createNotificationResponse", async () => {
15
- const resp = (0, app_actions_js_1.createNotificationResponse)("success", "test");
16
- (0, bun_test_1.expect)(resp.headers.get("content-type")).toBe("application/json");
17
- (0, bun_test_1.expect)(await resp.text()).toBe(JSON.stringify({
18
- actionType: "notification",
19
- payload: { status: "success", message: "test" },
20
- }));
21
- });
22
- (0, bun_test_1.test)("createModalResponse", async () => {
23
- const resp = (0, app_actions_js_1.createModalResponse)("test", "small", true);
24
- (0, bun_test_1.expect)(resp.headers.get("content-type")).toBe("application/json");
25
- (0, bun_test_1.expect)(await resp.text()).toBe(JSON.stringify({
26
- actionType: "openModal",
27
- payload: { iframeUrl: "test", size: "small", expand: true },
28
- }));
29
- });
30
- });
31
- //# sourceMappingURL=app-actions.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"app-actions.test.js","sourceRoot":"","sources":["../../../src/helper/app-actions.test.ts"],"names":[],"mappings":";;AAAA,uCAAkD;AAClD,oEAIyC;AAEzC,IAAA,mBAAQ,EAAC,YAAY,EAAE,KAAK,IAAI,EAAE;IACjC,IAAA,eAAI,EAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;QACvC,MAAM,IAAI,GAAG,IAAA,qCAAoB,EAAC,MAAM,CAAC,CAAC;QAE1C,IAAA,iBAAM,EAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAClE,IAAA,iBAAM,EAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAC7B,IAAI,CAAC,SAAS,CAAC;YACd,UAAU,EAAE,YAAY;YACxB,OAAO,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE;SAChC,CAAC,CACF,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,IAAA,eAAI,EAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;QAC7C,MAAM,IAAI,GAAG,IAAA,2CAA0B,EAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAE3D,IAAA,iBAAM,EAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAClE,IAAA,iBAAM,EAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAC7B,IAAI,CAAC,SAAS,CAAC;YACd,UAAU,EAAE,cAAc;YAC1B,OAAO,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE;SAC/C,CAAC,CACF,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,IAAA,eAAI,EAAC,qBAAqB,EAAE,KAAK,IAAI,EAAE;QACtC,MAAM,IAAI,GAAG,IAAA,oCAAmB,EAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QAExD,IAAA,iBAAM,EAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAClE,IAAA,iBAAM,EAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAC7B,IAAI,CAAC,SAAS,CAAC;YACd,UAAU,EAAE,WAAW;YACvB,OAAO,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE;SAC3D,CAAC,CACF,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, test } from \"bun:test\";\nimport {\n\tcreateModalResponse,\n\tcreateNewTabResponse,\n\tcreateNotificationResponse,\n} from \"../../src/helper/app-actions.js\";\n\ndescribe(\"AppActions\", async () => {\n\ttest(\"createNewTabResponse\", async () => {\n\t\tconst resp = createNewTabResponse(\"test\");\n\n\t\texpect(resp.headers.get(\"content-type\")).toBe(\"application/json\");\n\t\texpect(await resp.text()).toBe(\n\t\t\tJSON.stringify({\n\t\t\t\tactionType: \"openNewTab\",\n\t\t\t\tpayload: { redirectUrl: \"test\" },\n\t\t\t}),\n\t\t);\n\t});\n\n\ttest(\"createNotificationResponse\", async () => {\n\t\tconst resp = createNotificationResponse(\"success\", \"test\");\n\n\t\texpect(resp.headers.get(\"content-type\")).toBe(\"application/json\");\n\t\texpect(await resp.text()).toBe(\n\t\t\tJSON.stringify({\n\t\t\t\tactionType: \"notification\",\n\t\t\t\tpayload: { status: \"success\", message: \"test\" },\n\t\t\t}),\n\t\t);\n\t});\n\n\ttest(\"createModalResponse\", async () => {\n\t\tconst resp = createModalResponse(\"test\", \"small\", true);\n\n\t\texpect(resp.headers.get(\"content-type\")).toBe(\"application/json\");\n\t\texpect(await resp.text()).toBe(\n\t\t\tJSON.stringify({\n\t\t\t\tactionType: \"openModal\",\n\t\t\t\tpayload: { iframeUrl: \"test\", size: \"small\", expand: true },\n\t\t\t}),\n\t\t);\n\t});\n});\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=http-client.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http-client.test.d.ts","sourceRoot":"","sources":["../../src/http-client.test.ts"],"names":[],"mappings":""}
@@ -1,71 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const bun_test_1 = require("bun:test");
4
- const http_client_js_1 = require("../src/http-client.js");
5
- const repository_js_1 = require("../src/repository.js");
6
- (0, bun_test_1.describe)("HTTP Client", async () => {
7
- (0, bun_test_1.test)("getToken", async () => {
8
- const mockFetch = (0, bun_test_1.spyOn)(global, "fetch").mockImplementation(() => Promise.resolve(new Response('{"access_token": "test", "expires_in": 3600}')));
9
- const client = new http_client_js_1.HttpClient(new repository_js_1.SimpleShop("blaa", "test", "test"));
10
- (0, bun_test_1.expect)(client.getToken()).resolves.toBe("test");
11
- // We fetched already once the token, so the second time we should get it from the storage
12
- await client.getToken();
13
- (0, bun_test_1.expect)(mockFetch.mock.calls).toBeArrayOfSize(1);
14
- mockFetch.mockRestore();
15
- });
16
- (0, bun_test_1.test)("getToken: failed request", async () => {
17
- const mockFetch = (0, bun_test_1.spyOn)(global, "fetch").mockImplementation(() => Promise.resolve(new Response('{"error": "invalid_grant"}', { status: 400 })));
18
- const client = new http_client_js_1.HttpClient(new repository_js_1.SimpleShop("blaa", "test", "test"));
19
- (0, bun_test_1.expect)(client.getToken()).rejects.toThrowError("The api client authentication to shop with id: blaa");
20
- mockFetch.mockRestore();
21
- });
22
- (0, bun_test_1.test)("getToken: expired refetch", async () => {
23
- const mockFetch = (0, bun_test_1.spyOn)(global, "fetch").mockImplementation(() => Promise.resolve(new Response('{"access_token": "test", "expires_in": -500}')));
24
- const client = new http_client_js_1.HttpClient(new repository_js_1.SimpleShop("blaa", "test", "test"));
25
- (0, bun_test_1.expect)(client.getToken()).resolves.toBe("test");
26
- (0, bun_test_1.expect)(mockFetch.mock.calls).toBeArrayOfSize(1);
27
- (0, bun_test_1.expect)(client.getToken()).resolves.toBe("test");
28
- (0, bun_test_1.expect)(mockFetch.mock.calls).toBeArrayOfSize(2);
29
- mockFetch.mockRestore();
30
- });
31
- (0, bun_test_1.test)("get, post, put, patch, delete", async () => {
32
- const mockFetch = (0, bun_test_1.spyOn)(global, "fetch").mockImplementationOnce(() => Promise.resolve(new Response('{"access_token": "test", "expires_in": 5000}')));
33
- const client = new http_client_js_1.HttpClient(new repository_js_1.SimpleShop("blaa", "test", "test"));
34
- mockFetch.mockImplementation(() => Promise.resolve(new Response('{"data": "test"}')));
35
- (0, bun_test_1.expect)(client.get("/test")).resolves.toEqual({
36
- body: { data: "test" },
37
- headers: new Headers(),
38
- statusCode: 200,
39
- });
40
- (0, bun_test_1.expect)(client.post("/test", { data: "test" })).resolves.toEqual({
41
- body: { data: "test" },
42
- headers: new Headers(),
43
- statusCode: 200,
44
- });
45
- (0, bun_test_1.expect)(client.put("/test", { data: "test" })).resolves.toEqual({
46
- body: { data: "test" },
47
- headers: new Headers(),
48
- statusCode: 200,
49
- });
50
- (0, bun_test_1.expect)(client.patch("/test", { data: "test" })).resolves.toEqual({
51
- body: { data: "test" },
52
- headers: new Headers(),
53
- statusCode: 200,
54
- });
55
- (0, bun_test_1.expect)(client.delete("/test")).resolves.toEqual({
56
- body: { data: "test" },
57
- headers: new Headers(),
58
- statusCode: 200,
59
- });
60
- (0, bun_test_1.expect)(mockFetch.mock.calls).toBeArrayOfSize(6);
61
- mockFetch.mockRestore();
62
- });
63
- (0, bun_test_1.test)("get: request failed", async () => {
64
- const mockFetch = (0, bun_test_1.spyOn)(global, "fetch").mockImplementationOnce(() => Promise.resolve(new Response('{"access_token": "test", "expires_in": 5000}')));
65
- const client = new http_client_js_1.HttpClient(new repository_js_1.SimpleShop("blaa", "test", "test"));
66
- mockFetch.mockImplementation(() => Promise.resolve(new Response('{"data": "test"}', { status: 400 })));
67
- (0, bun_test_1.expect)(client.get("/test")).rejects.toThrowError("The api request failed with status code: 400 for shop with id: blaa");
68
- mockFetch.mockRestore();
69
- });
70
- });
71
- //# sourceMappingURL=http-client.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http-client.test.js","sourceRoot":"","sources":["../../src/http-client.test.ts"],"names":[],"mappings":";;AAAA,uCAAyD;AACzD,0DAAmD;AACnD,wDAAkD;AAElD,IAAA,mBAAQ,EAAC,aAAa,EAAE,KAAK,IAAI,EAAE;IAClC,IAAA,eAAI,EAAC,UAAU,EAAE,KAAK,IAAI,EAAE;QAC3B,MAAM,SAAS,GAAG,IAAA,gBAAK,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAChE,OAAO,CAAC,OAAO,CACd,IAAI,QAAQ,CAAC,8CAA8C,CAAC,CAC5D,CACD,CAAC;QAEF,MAAM,MAAM,GAAG,IAAI,2BAAU,CAAC,IAAI,0BAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;QACtE,IAAA,iBAAM,EAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAEhD,0FAA0F;QAC1F,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAC;QAExB,IAAA,iBAAM,EAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QAEhD,SAAS,CAAC,WAAW,EAAE,CAAC;IACzB,CAAC,CAAC,CAAC;IAEH,IAAA,eAAI,EAAC,0BAA0B,EAAE,KAAK,IAAI,EAAE;QAC3C,MAAM,SAAS,GAAG,IAAA,gBAAK,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC,kBAAk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AAY,CAC/C,qEAAqE,CACrE,CAAC;QAEF,SAAS,CAAC,WAAW,EAAE,CAAC;IACzB,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, spyOn, test } from \"bun:test\";\nimport { HttpClient } from \"../src/http-client.js\";\nimport { SimpleShop } from \"../src/repository.js\";\n\ndescribe(\"HTTP Client\", async () => {\n\ttest(\"getToken\", async () => {\n\t\tconst mockFetch = spyOn(global, \"fetch\").mockImplementation(() =>\n\t\t\tPromise.resolve(\n\t\t\t\tnew Response('{\"access_token\": \"test\", \"expires_in\": 3600}'),\n\t\t\t),\n\t\t);\n\n\t\tconst client = new HttpClient(new SimpleShop(\"blaa\", \"test\", \"test\"));\n\t\texpect(client.getToken()).resolves.toBe(\"test\");\n\n\t\t// We fetched already once the token, so the second time we should get it from the storage\n\t\tawait client.getToken();\n\n\t\texpect(mockFetch.mock.calls).toBeArrayOfSize(1);\n\n\t\tmockFetch.mockRestore();\n\t});\n\n\ttest(\"getToken: failed request\", async () => {\n\t\tconst mockFetch = spyOn(global, \"fetch\").mockImplementation(() =>\n\t\t\tPromise.resolve(\n\t\t\t\tnew Response('{\"error\": \"invalid_grant\"}', { status: 400 }),\n\t\t\t),\n\t\t);\n\n\t\tconst client = new HttpClient(new SimpleShop(\"blaa\", \"test\", \"test\"));\n\t\texpect(client.getToken()).rejects.toThrowError(\n\t\t\t\"The api client authentication to shop with id: blaa\",\n\t\t);\n\n\t\tmockFetch.mockRestore();\n\t});\n\n\ttest(\"getToken: expired refetch\", async () => {\n\t\tconst mockFetch = spyOn(global, \"fetch\").mockImplementation(() =>\n\t\t\tPromise.resolve(\n\t\t\t\tnew Response('{\"access_token\": \"test\", \"expires_in\": -500}'),\n\t\t\t),\n\t\t);\n\n\t\tconst client = new HttpClient(new SimpleShop(\"blaa\", \"test\", \"test\"));\n\t\texpect(client.getToken()).resolves.toBe(\"test\");\n\n\t\texpect(mockFetch.mock.calls).toBeArrayOfSize(1);\n\n\t\texpect(client.getToken()).resolves.toBe(\"test\");\n\n\t\texpect(mockFetch.mock.calls).toBeArrayOfSize(2);\n\n\t\tmockFetch.mockRestore();\n\t});\n\n\ttest(\"get, post, put, patch, delete\", async () => {\n\t\tconst mockFetch = spyOn(global, \"fetch\").mockImplementationOnce(() =>\n\t\t\tPromise.resolve(\n\t\t\t\tnew Response('{\"access_token\": \"test\", \"expires_in\": 5000}'),\n\t\t\t),\n\t\t);\n\n\t\tconst client = new HttpClient(new SimpleShop(\"blaa\", \"test\", \"test\"));\n\n\t\tmockFetch.mockImplementation(() =>\n\t\t\tPromise.resolve(new Response('{\"data\": \"test\"}')),\n\t\t);\n\n\t\texpect(client.get(\"/test\")).resolves.toEqual({\n\t\t\tbody: { data: \"test\" },\n\t\t\theaders: new Headers(),\n\t\t\tstatusCode: 200,\n\t\t});\n\t\texpect(client.post(\"/test\", { data: \"test\" })).resolves.toEqual({\n\t\t\tbody: { data: \"test\" },\n\t\t\theaders: new Headers(),\n\t\t\tstatusCode: 200,\n\t\t});\n\t\texpect(client.put(\"/test\", { data: \"test\" })).resolves.toEqual({\n\t\t\tbody: { data: \"test\" },\n\t\t\theaders: new Headers(),\n\t\t\tstatusCode: 200,\n\t\t});\n\t\texpect(client.patch(\"/test\", { data: \"test\" })).resolves.toEqual({\n\t\t\tbody: { data: \"test\" },\n\t\t\theaders: new Headers(),\n\t\t\tstatusCode: 200,\n\t\t});\n\t\texpect(client.delete(\"/test\")).resolves.toEqual({\n\t\t\tbody: { data: \"test\" },\n\t\t\theaders: new Headers(),\n\t\t\tstatusCode: 200,\n\t\t});\n\n\t\texpect(mockFetch.mock.calls).toBeArrayOfSize(6);\n\n\t\tmockFetch.mockRestore();\n\t});\n\n\ttest(\"get: request failed\", async () => {\n\t\tconst mockFetch = spyOn(global, \"fetch\").mockImplementationOnce(() =>\n\t\t\tPromise.resolve(\n\t\t\t\tnew Response('{\"access_token\": \"test\", \"expires_in\": 5000}'),\n\t\t\t),\n\t\t);\n\n\t\tconst client = new HttpClient(new SimpleShop(\"blaa\", \"test\", \"test\"));\n\n\t\tmockFetch.mockImplementation(() =>\n\t\t\tPromise.resolve(new Response('{\"data\": \"test\"}', { status: 400 })),\n\t\t);\n\n\t\texpect(client.get(\"/test\")).rejects.toThrowError(\n\t\t\t\"The api request failed with status code: 400 for shop with id: blaa\",\n\t\t);\n\n\t\tmockFetch.mockRestore();\n\t});\n});\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=bun-sqlite.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bun-sqlite.test.d.ts","sourceRoot":"","sources":["../../../src/integration/bun-sqlite.test.ts"],"names":[],"mappings":""}