storybooker 0.19.3 → 0.22.0-canary.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 (215) hide show
  1. package/README.md +40 -18
  2. package/dist/adapters/_internal/queue.d.mts +127 -0
  3. package/dist/aws-dynamodb.d.mts +22 -0
  4. package/dist/aws-dynamodb.mjs +118 -0
  5. package/dist/aws-dynamodb.mjs.map +1 -0
  6. package/dist/aws-s3.d.mts +20 -0
  7. package/dist/aws-s3.mjs +96 -0
  8. package/dist/aws-s3.mjs.map +1 -0
  9. package/dist/azure-blob-storage.d.mts +20 -0
  10. package/dist/azure-blob-storage.mjs +126 -0
  11. package/dist/azure-blob-storage.mjs.map +1 -0
  12. package/dist/azure-cosmos-db.d.mts +23 -0
  13. package/dist/azure-cosmos-db.mjs +87 -0
  14. package/dist/azure-cosmos-db.mjs.map +1 -0
  15. package/dist/azure-data-tables.d.mts +23 -0
  16. package/dist/azure-data-tables.mjs +127 -0
  17. package/dist/azure-data-tables.mjs.map +1 -0
  18. package/dist/azure-easy-auth.d.mts +50 -0
  19. package/dist/azure-easy-auth.mjs +88 -0
  20. package/dist/azure-easy-auth.mjs.map +1 -0
  21. package/dist/azure-functions.d.mts +62 -0
  22. package/dist/azure-functions.mjs +147 -0
  23. package/dist/azure-functions.mjs.map +1 -0
  24. package/dist/fs.d.mts +37 -0
  25. package/dist/fs.mjs +240 -0
  26. package/dist/fs.mjs.map +1 -0
  27. package/dist/gcp-big-table.d.mts +23 -0
  28. package/dist/gcp-big-table.mjs +92 -0
  29. package/dist/gcp-big-table.mjs.map +1 -0
  30. package/dist/gcp-firestore.d.mts +22 -0
  31. package/dist/gcp-firestore.mjs +87 -0
  32. package/dist/gcp-firestore.mjs.map +1 -0
  33. package/dist/gcp-storage.d.mts +20 -0
  34. package/dist/gcp-storage.mjs +96 -0
  35. package/dist/gcp-storage.mjs.map +1 -0
  36. package/dist/handlers/handle-process-zip.mjs +90 -0
  37. package/dist/handlers/handle-process-zip.mjs.map +1 -0
  38. package/dist/handlers/handle-purge.d.mts +12 -0
  39. package/dist/handlers/handle-purge.mjs +36 -0
  40. package/dist/handlers/handle-purge.mjs.map +1 -0
  41. package/dist/handlers/handle-serve-storybook.mjs +94 -0
  42. package/dist/handlers/handle-serve-storybook.mjs.map +1 -0
  43. package/dist/index.d.mts +28 -0
  44. package/dist/index.mjs +62 -0
  45. package/dist/index.mjs.map +1 -0
  46. package/dist/models/builds-model.mjs +248 -0
  47. package/dist/models/builds-model.mjs.map +1 -0
  48. package/dist/models/builds-schema.d.mts +171 -0
  49. package/dist/models/builds-schema.mjs +67 -0
  50. package/dist/models/builds-schema.mjs.map +1 -0
  51. package/dist/models/projects-model.mjs +122 -0
  52. package/dist/models/projects-model.mjs.map +1 -0
  53. package/dist/models/projects-schema.d.mts +70 -0
  54. package/dist/models/projects-schema.mjs +37 -0
  55. package/dist/models/projects-schema.mjs.map +1 -0
  56. package/dist/models/tags-model.mjs +110 -0
  57. package/dist/models/tags-model.mjs.map +1 -0
  58. package/dist/models/tags-schema.d.mts +76 -0
  59. package/dist/models/tags-schema.mjs +34 -0
  60. package/dist/models/tags-schema.mjs.map +1 -0
  61. package/dist/models/~model.mjs +43 -0
  62. package/dist/models/~model.mjs.map +1 -0
  63. package/dist/models/~shared-schema.d.mts +1 -0
  64. package/dist/models/~shared-schema.mjs +20 -0
  65. package/dist/models/~shared-schema.mjs.map +1 -0
  66. package/dist/mysql.d.mts +39 -0
  67. package/dist/mysql.mjs +151 -0
  68. package/dist/mysql.mjs.map +1 -0
  69. package/dist/redis.d.mts +33 -0
  70. package/dist/redis.mjs +118 -0
  71. package/dist/redis.mjs.map +1 -0
  72. package/dist/routers/account-router.mjs +91 -0
  73. package/dist/routers/account-router.mjs.map +1 -0
  74. package/dist/routers/builds-router.mjs +347 -0
  75. package/dist/routers/builds-router.mjs.map +1 -0
  76. package/dist/routers/projects-router.mjs +236 -0
  77. package/dist/routers/projects-router.mjs.map +1 -0
  78. package/dist/routers/root-router.mjs +108 -0
  79. package/dist/routers/root-router.mjs.map +1 -0
  80. package/dist/routers/tags-router.mjs +269 -0
  81. package/dist/routers/tags-router.mjs.map +1 -0
  82. package/dist/routers/tasks-router.mjs +71 -0
  83. package/dist/routers/tasks-router.mjs.map +1 -0
  84. package/dist/urls.d.mts +47 -0
  85. package/dist/urls.mjs +208 -0
  86. package/dist/urls.mjs.map +1 -0
  87. package/dist/utils/adapter-utils.d.mts +14 -0
  88. package/dist/utils/adapter-utils.mjs +14 -0
  89. package/dist/utils/adapter-utils.mjs.map +1 -0
  90. package/dist/utils/auth.mjs +25 -0
  91. package/dist/utils/auth.mjs.map +1 -0
  92. package/dist/utils/error.d.mts +21 -0
  93. package/dist/utils/error.mjs +109 -0
  94. package/dist/utils/error.mjs.map +1 -0
  95. package/dist/utils/file-utils.mjs +16 -0
  96. package/dist/utils/file-utils.mjs.map +1 -0
  97. package/dist/utils/openapi-utils.mjs +45 -0
  98. package/dist/utils/openapi-utils.mjs.map +1 -0
  99. package/dist/utils/request.mjs +35 -0
  100. package/dist/utils/request.mjs.map +1 -0
  101. package/dist/utils/response.mjs +24 -0
  102. package/dist/utils/response.mjs.map +1 -0
  103. package/dist/utils/store.mjs +54 -0
  104. package/dist/utils/store.mjs.map +1 -0
  105. package/dist/utils/ui-utils.mjs +38 -0
  106. package/dist/utils/ui-utils.mjs.map +1 -0
  107. package/dist/utils/url-utils.d.mts +10 -0
  108. package/dist/utils/url-utils.mjs +54 -0
  109. package/dist/utils/url-utils.mjs.map +1 -0
  110. package/dist/~internal/adapter/auth.d.mts +123 -0
  111. package/dist/~internal/adapter/auth.mjs +20 -0
  112. package/dist/~internal/adapter/auth.mjs.map +1 -0
  113. package/dist/~internal/adapter/database.d.mts +240 -0
  114. package/dist/~internal/adapter/database.mjs +63 -0
  115. package/dist/~internal/adapter/database.mjs.map +1 -0
  116. package/dist/~internal/adapter/logger.d.mts +34 -0
  117. package/dist/~internal/adapter/logger.mjs +13 -0
  118. package/dist/~internal/adapter/logger.mjs.map +1 -0
  119. package/dist/~internal/adapter/storage.d.mts +208 -0
  120. package/dist/~internal/adapter/storage.mjs +63 -0
  121. package/dist/~internal/adapter/storage.mjs.map +1 -0
  122. package/dist/~internal/adapter/ui.d.mts +109 -0
  123. package/dist/~internal/adapter/ui.mjs +1 -0
  124. package/dist/~internal/adapter.d.mts +8 -0
  125. package/dist/~internal/adapter.mjs +6 -0
  126. package/dist/~internal/constants.d.mts +24 -0
  127. package/dist/~internal/constants.mjs +32 -0
  128. package/dist/~internal/constants.mjs.map +1 -0
  129. package/dist/~internal/mimes.d.mts +449 -0
  130. package/dist/~internal/mimes.mjs +454 -0
  131. package/dist/~internal/mimes.mjs.map +1 -0
  132. package/dist/~internal/router.d.mts +1651 -0
  133. package/dist/~internal/router.mjs +39 -0
  134. package/dist/~internal/router.mjs.map +1 -0
  135. package/dist/~internal/types.d.mts +77 -0
  136. package/dist/~internal/types.mjs +1 -0
  137. package/dist/~internal/utils.d.mts +4 -0
  138. package/dist/~internal/utils.mjs +5 -0
  139. package/openapi.json +3162 -0
  140. package/package.json +148 -27
  141. package/src/adapters/_internal/auth.ts +135 -0
  142. package/src/adapters/_internal/database.ts +241 -0
  143. package/src/adapters/_internal/index.ts +8 -0
  144. package/src/adapters/_internal/logger.ts +41 -0
  145. package/src/adapters/_internal/queue.ts +151 -0
  146. package/src/adapters/_internal/storage.ts +197 -0
  147. package/src/adapters/_internal/ui.ts +103 -0
  148. package/src/adapters/aws-dynamodb.ts +201 -0
  149. package/src/adapters/aws-s3.ts +160 -0
  150. package/src/adapters/azure-blob-storage.ts +223 -0
  151. package/src/adapters/azure-cosmos-db.ts +158 -0
  152. package/src/adapters/azure-data-tables.ts +223 -0
  153. package/src/adapters/azure-easy-auth.ts +174 -0
  154. package/src/adapters/azure-functions.ts +242 -0
  155. package/src/adapters/fs.ts +398 -0
  156. package/src/adapters/gcp-big-table.ts +157 -0
  157. package/src/adapters/gcp-firestore.ts +146 -0
  158. package/src/adapters/gcp-storage.ts +141 -0
  159. package/src/adapters/mysql.ts +296 -0
  160. package/src/adapters/redis.ts +242 -0
  161. package/src/handlers/handle-process-zip.ts +117 -0
  162. package/src/handlers/handle-purge.ts +65 -0
  163. package/src/handlers/handle-serve-storybook.ts +101 -0
  164. package/src/index.ts +81 -16
  165. package/src/mocks/mock-auth-service.ts +51 -0
  166. package/src/mocks/mock-store.ts +26 -0
  167. package/src/models/builds-model.ts +373 -0
  168. package/src/models/builds-schema.ts +84 -0
  169. package/src/models/projects-model.ts +177 -0
  170. package/src/models/projects-schema.ts +69 -0
  171. package/src/models/tags-model.ts +138 -0
  172. package/src/models/tags-schema.ts +45 -0
  173. package/src/models/~model.ts +79 -0
  174. package/src/models/~shared-schema.ts +14 -0
  175. package/src/routers/_app-router.ts +57 -0
  176. package/src/routers/account-router.ts +136 -0
  177. package/src/routers/builds-router.ts +464 -0
  178. package/src/routers/projects-router.ts +309 -0
  179. package/src/routers/root-router.ts +127 -0
  180. package/src/routers/tags-router.ts +339 -0
  181. package/src/routers/tasks-router.ts +75 -0
  182. package/src/types.ts +107 -0
  183. package/src/urls.ts +327 -0
  184. package/src/utils/adapter-utils.ts +26 -0
  185. package/src/utils/auth.test.ts +71 -0
  186. package/src/utils/auth.ts +39 -0
  187. package/src/utils/constants.ts +31 -0
  188. package/src/utils/date-utils.ts +10 -0
  189. package/src/utils/error.test.ts +86 -0
  190. package/src/utils/error.ts +140 -0
  191. package/src/utils/file-utils.test.ts +65 -0
  192. package/src/utils/file-utils.ts +43 -0
  193. package/src/utils/index.ts +3 -0
  194. package/src/utils/mime-utils.ts +457 -0
  195. package/src/utils/openapi-utils.ts +49 -0
  196. package/src/utils/request.ts +97 -0
  197. package/src/utils/response.ts +20 -0
  198. package/src/utils/store.ts +85 -0
  199. package/src/utils/story-utils.ts +42 -0
  200. package/src/utils/text-utils.ts +10 -0
  201. package/src/utils/ui-utils.ts +57 -0
  202. package/src/utils/url-utils.ts +113 -0
  203. package/dist/index.js +0 -554
  204. package/src/commands/create.ts +0 -263
  205. package/src/commands/purge.ts +0 -70
  206. package/src/commands/test.ts +0 -42
  207. package/src/service-schema.d.ts +0 -2023
  208. package/src/utils/auth-utils.ts +0 -31
  209. package/src/utils/pkg-utils.ts +0 -37
  210. package/src/utils/sb-build.ts +0 -55
  211. package/src/utils/sb-test.ts +0 -115
  212. package/src/utils/schema-utils.ts +0 -123
  213. package/src/utils/stream-utils.ts +0 -72
  214. package/src/utils/types.ts +0 -4
  215. package/src/utils/zip.ts +0 -77
@@ -0,0 +1,457 @@
1
+ // oxlint-disable id-length
2
+ // oxlint-disable sort-keys
3
+ const mimes = {
4
+ "3g2": "video/3gpp2",
5
+ "3gp": "video/3gpp",
6
+ "3gpp": "video/3gpp",
7
+ "3mf": "model/3mf",
8
+ aac: "audio/aac",
9
+ ac: "application/pkix-attr-cert",
10
+ adp: "audio/adpcm",
11
+ adts: "audio/aac",
12
+ ai: "application/postscript",
13
+ aml: "application/automationml-aml+xml",
14
+ amlx: "application/automationml-amlx+zip",
15
+ amr: "audio/amr",
16
+ apng: "image/apng",
17
+ appcache: "text/cache-manifest",
18
+ appinstaller: "application/appinstaller",
19
+ appx: "application/appx",
20
+ appxbundle: "application/appxbundle",
21
+ asc: "application/pgp-keys",
22
+ atom: "application/atom+xml",
23
+ atomcat: "application/atomcat+xml",
24
+ atomdeleted: "application/atomdeleted+xml",
25
+ atomsvc: "application/atomsvc+xml",
26
+ au: "audio/basic",
27
+ avci: "image/avci",
28
+ avcs: "image/avcs",
29
+ avif: "image/avif",
30
+ aw: "application/applixware",
31
+ bdoc: "application/bdoc",
32
+ bin: "application/octet-stream",
33
+ bmp: "image/bmp",
34
+ bpk: "application/octet-stream",
35
+ btf: "image/prs.btif",
36
+ btif: "image/prs.btif",
37
+ buffer: "application/octet-stream",
38
+ ccxml: "application/ccxml+xml",
39
+ cdfx: "application/cdfx+xml",
40
+ cdmia: "application/cdmi-capability",
41
+ cdmic: "application/cdmi-container",
42
+ cdmid: "application/cdmi-domain",
43
+ cdmio: "application/cdmi-object",
44
+ cdmiq: "application/cdmi-queue",
45
+ cer: "application/pkix-cert",
46
+ cgm: "image/cgm",
47
+ cjs: "application/node",
48
+ class: "application/java-vm",
49
+ coffee: "text/coffeescript",
50
+ conf: "text/plain",
51
+ cpl: "application/cpl+xml",
52
+ cpt: "application/mac-compactpro",
53
+ crl: "application/pkix-crl",
54
+ css: "text/css",
55
+ csv: "text/csv",
56
+ cu: "application/cu-seeme",
57
+ cwl: "application/cwl",
58
+ cww: "application/prs.cww",
59
+ davmount: "application/davmount+xml",
60
+ dbk: "application/docbook+xml",
61
+ deb: "application/octet-stream",
62
+ def: "text/plain",
63
+ deploy: "application/octet-stream",
64
+ dib: "image/bmp",
65
+ "disposition-notification": "message/disposition-notification",
66
+ dist: "application/octet-stream",
67
+ distz: "application/octet-stream",
68
+ dll: "application/octet-stream",
69
+ dmg: "application/octet-stream",
70
+ dms: "application/octet-stream",
71
+ doc: "application/msword",
72
+ dot: "application/msword",
73
+ dpx: "image/dpx",
74
+ drle: "image/dicom-rle",
75
+ dsc: "text/prs.lines.tag",
76
+ dssc: "application/dssc+der",
77
+ dtd: "application/xml-dtd",
78
+ dump: "application/octet-stream",
79
+ dwd: "application/atsc-dwd+xml",
80
+ ear: "application/java-archive",
81
+ ecma: "application/ecmascript",
82
+ elc: "application/octet-stream",
83
+ emf: "image/emf",
84
+ eml: "message/rfc822",
85
+ emma: "application/emma+xml",
86
+ emotionml: "application/emotionml+xml",
87
+ eps: "application/postscript",
88
+ epub: "application/epub+zip",
89
+ exe: "application/octet-stream",
90
+ exi: "application/exi",
91
+ exp: "application/express",
92
+ exr: "image/aces",
93
+ ez: "application/andrew-inset",
94
+ fdf: "application/fdf",
95
+ fdt: "application/fdt+xml",
96
+ fits: "image/fits",
97
+ g3: "image/g3fax",
98
+ gbr: "application/rpki-ghostbusters",
99
+ geojson: "application/geo+json",
100
+ gif: "image/gif",
101
+ glb: "model/gltf-binary",
102
+ gltf: "model/gltf+json",
103
+ gml: "application/gml+xml",
104
+ gpx: "application/gpx+xml",
105
+ gram: "application/srgs",
106
+ grxml: "application/srgs+xml",
107
+ gxf: "application/gxf",
108
+ gz: "application/gzip",
109
+ h261: "video/h261",
110
+ h263: "video/h263",
111
+ h264: "video/h264",
112
+ heic: "image/heic",
113
+ heics: "image/heic-sequence",
114
+ heif: "image/heif",
115
+ heifs: "image/heif-sequence",
116
+ hej2: "image/hej2k",
117
+ held: "application/atsc-held+xml",
118
+ hjson: "application/hjson",
119
+ hlp: "application/winhlp",
120
+ hqx: "application/mac-binhex40",
121
+ hsj2: "image/hsj2",
122
+ htm: "text/html",
123
+ html: "text/html",
124
+ ics: "text/calendar",
125
+ ief: "image/ief",
126
+ ifb: "text/calendar",
127
+ iges: "model/iges",
128
+ igs: "model/iges",
129
+ img: "application/octet-stream",
130
+ in: "text/plain",
131
+ ini: "text/plain",
132
+ ink: "application/inkml+xml",
133
+ inkml: "application/inkml+xml",
134
+ ipfix: "application/ipfix",
135
+ iso: "application/octet-stream",
136
+ its: "application/its+xml",
137
+ jade: "text/jade",
138
+ jar: "application/java-archive",
139
+ jhc: "image/jphc",
140
+ jls: "image/jls",
141
+ jp2: "image/jp2",
142
+ jpe: "image/jpeg",
143
+ jpeg: "image/jpeg",
144
+ jpf: "image/jpx",
145
+ jpg: "image/jpeg",
146
+ jpg2: "image/jp2",
147
+ jpgm: "image/jpm",
148
+ jpgv: "video/jpeg",
149
+ jph: "image/jph",
150
+ jpm: "image/jpm",
151
+ jpx: "image/jpx",
152
+ js: "text/javascript",
153
+ json: "application/json",
154
+ json5: "application/json5",
155
+ jsonld: "application/ld+json",
156
+ jsonml: "application/jsonml+json",
157
+ jsx: "text/jsx",
158
+ jt: "model/jt",
159
+ jxl: "image/jxl",
160
+ jxr: "image/jxr",
161
+ jxra: "image/jxra",
162
+ jxrs: "image/jxrs",
163
+ jxs: "image/jxs",
164
+ jxsc: "image/jxsc",
165
+ jxsi: "image/jxsi",
166
+ jxss: "image/jxss",
167
+ kar: "audio/midi",
168
+ ktx: "image/ktx",
169
+ ktx2: "image/ktx2",
170
+ less: "text/less",
171
+ lgr: "application/lgr+xml",
172
+ list: "text/plain",
173
+ litcoffee: "text/coffeescript",
174
+ log: "text/plain",
175
+ lostxml: "application/lost+xml",
176
+ lrf: "application/octet-stream",
177
+ m1v: "video/mpeg",
178
+ m21: "application/mp21",
179
+ m2a: "audio/mpeg",
180
+ m2t: "video/mp2t",
181
+ m2ts: "video/mp2t",
182
+ m2v: "video/mpeg",
183
+ m3a: "audio/mpeg",
184
+ m4a: "audio/mp4",
185
+ m4p: "application/mp4",
186
+ m4s: "video/iso.segment",
187
+ ma: "application/mathematica",
188
+ mads: "application/mads+xml",
189
+ maei: "application/mmt-aei+xml",
190
+ man: "text/troff",
191
+ manifest: "text/cache-manifest",
192
+ map: "application/json",
193
+ mar: "application/octet-stream",
194
+ markdown: "text/markdown",
195
+ mathml: "application/mathml+xml",
196
+ mb: "application/mathematica",
197
+ mbox: "application/mbox",
198
+ md: "text/markdown",
199
+ mdx: "text/mdx",
200
+ me: "text/troff",
201
+ mesh: "model/mesh",
202
+ meta4: "application/metalink4+xml",
203
+ metalink: "application/metalink+xml",
204
+ mets: "application/mets+xml",
205
+ mft: "application/rpki-manifest",
206
+ mid: "audio/midi",
207
+ midi: "audio/midi",
208
+ mime: "message/rfc822",
209
+ mj2: "video/mj2",
210
+ mjp2: "video/mj2",
211
+ mjs: "text/javascript",
212
+ mml: "text/mathml",
213
+ mods: "application/mods+xml",
214
+ mov: "video/quicktime",
215
+ mp2: "audio/mpeg",
216
+ mp21: "application/mp21",
217
+ mp2a: "audio/mpeg",
218
+ mp3: "audio/mpeg",
219
+ mp4: "video/mp4",
220
+ mp4a: "audio/mp4",
221
+ mp4s: "application/mp4",
222
+ mp4v: "video/mp4",
223
+ mpd: "application/dash+xml",
224
+ mpe: "video/mpeg",
225
+ mpeg: "video/mpeg",
226
+ mpf: "application/media-policy-dataset+xml",
227
+ mpg: "video/mpeg",
228
+ mpg4: "video/mp4",
229
+ mpga: "audio/mpeg",
230
+ mpp: "application/dash-patch+xml",
231
+ mrc: "application/marc",
232
+ mrcx: "application/marcxml+xml",
233
+ ms: "text/troff",
234
+ mscml: "application/mediaservercontrol+xml",
235
+ msh: "model/mesh",
236
+ msi: "application/octet-stream",
237
+ msix: "application/msix",
238
+ msixbundle: "application/msixbundle",
239
+ msm: "application/octet-stream",
240
+ msp: "application/octet-stream",
241
+ mtl: "model/mtl",
242
+ mts: "video/mp2t",
243
+ musd: "application/mmt-usd+xml",
244
+ mxf: "application/mxf",
245
+ mxmf: "audio/mobile-xmf",
246
+ mxml: "application/xv+xml",
247
+ n3: "text/n3",
248
+ nb: "application/mathematica",
249
+ nq: "application/n-quads",
250
+ nt: "application/n-triples",
251
+ obj: "model/obj",
252
+ oda: "application/oda",
253
+ oga: "audio/ogg",
254
+ ogg: "audio/ogg",
255
+ ogv: "video/ogg",
256
+ ogx: "application/ogg",
257
+ omdoc: "application/omdoc+xml",
258
+ onepkg: "application/onenote",
259
+ onetmp: "application/onenote",
260
+ onetoc: "application/onenote",
261
+ onetoc2: "application/onenote",
262
+ opf: "application/oebps-package+xml",
263
+ opus: "audio/ogg",
264
+ otf: "font/otf",
265
+ owl: "application/rdf+xml",
266
+ oxps: "application/oxps",
267
+ p10: "application/pkcs10",
268
+ p7c: "application/pkcs7-mime",
269
+ p7m: "application/pkcs7-mime",
270
+ p7s: "application/pkcs7-signature",
271
+ p8: "application/pkcs8",
272
+ pdf: "application/pdf",
273
+ pfr: "application/font-tdpfr",
274
+ pgp: "application/pgp-encrypted",
275
+ pkg: "application/octet-stream",
276
+ pki: "application/pkixcmp",
277
+ pkipath: "application/pkix-pkipath",
278
+ pls: "application/pls+xml",
279
+ png: "image/png",
280
+ prc: "model/prc",
281
+ prf: "application/pics-rules",
282
+ provx: "application/provenance+xml",
283
+ ps: "application/postscript",
284
+ pskcxml: "application/pskc+xml",
285
+ pti: "image/prs.pti",
286
+ qt: "video/quicktime",
287
+ raml: "application/raml+yaml",
288
+ rapd: "application/route-apd+xml",
289
+ rdf: "application/rdf+xml",
290
+ relo: "application/p2p-overlay+xml",
291
+ rif: "application/reginfo+xml",
292
+ rl: "application/resource-lists+xml",
293
+ rld: "application/resource-lists-diff+xml",
294
+ rmi: "audio/midi",
295
+ rnc: "application/relax-ng-compact-syntax",
296
+ rng: "application/xml",
297
+ roa: "application/rpki-roa",
298
+ roff: "text/troff",
299
+ rq: "application/sparql-query",
300
+ rs: "application/rls-services+xml",
301
+ rsat: "application/atsc-rsat+xml",
302
+ rsd: "application/rsd+xml",
303
+ rsheet: "application/urc-ressheet+xml",
304
+ rss: "application/rss+xml",
305
+ rtf: "text/rtf",
306
+ rtx: "text/richtext",
307
+ rusd: "application/route-usd+xml",
308
+ s3m: "audio/s3m",
309
+ sbml: "application/sbml+xml",
310
+ scq: "application/scvp-cv-request",
311
+ scs: "application/scvp-cv-response",
312
+ sdp: "application/sdp",
313
+ senmlx: "application/senml+xml",
314
+ sensmlx: "application/sensml+xml",
315
+ ser: "application/java-serialized-object",
316
+ setpay: "application/set-payment-initiation",
317
+ setreg: "application/set-registration-initiation",
318
+ sgi: "image/sgi",
319
+ sgm: "text/sgml",
320
+ sgml: "text/sgml",
321
+ shex: "text/shex",
322
+ shf: "application/shf+xml",
323
+ shtml: "text/html",
324
+ sieve: "application/sieve",
325
+ sig: "application/pgp-signature",
326
+ sil: "audio/silk",
327
+ silo: "model/mesh",
328
+ siv: "application/sieve",
329
+ slim: "text/slim",
330
+ slm: "text/slim",
331
+ sls: "application/route-s-tsid+xml",
332
+ smi: "application/smil+xml",
333
+ smil: "application/smil+xml",
334
+ snd: "audio/basic",
335
+ so: "application/octet-stream",
336
+ spdx: "text/spdx",
337
+ spp: "application/scvp-vp-response",
338
+ spq: "application/scvp-vp-request",
339
+ spx: "audio/ogg",
340
+ sql: "application/sql",
341
+ sru: "application/sru+xml",
342
+ srx: "application/sparql-results+xml",
343
+ ssdl: "application/ssdl+xml",
344
+ ssml: "application/ssml+xml",
345
+ stk: "application/hyperstudio",
346
+ stl: "model/stl",
347
+ stpx: "model/step+xml",
348
+ stpxz: "model/step-xml+zip",
349
+ stpz: "model/step+zip",
350
+ styl: "text/stylus",
351
+ stylus: "text/stylus",
352
+ svg: "image/svg+xml",
353
+ svgz: "image/svg+xml",
354
+ swidtag: "application/swid+xml",
355
+ t: "text/troff",
356
+ t38: "image/t38",
357
+ td: "application/urc-targetdesc+xml",
358
+ tei: "application/tei+xml",
359
+ teicorpus: "application/tei+xml",
360
+ text: "text/plain",
361
+ tfi: "application/thraud+xml",
362
+ tfx: "image/tiff-fx",
363
+ tif: "image/tiff",
364
+ tiff: "image/tiff",
365
+ toml: "application/toml",
366
+ tr: "text/troff",
367
+ trig: "application/trig",
368
+ ts: "video/mp2t",
369
+ tsd: "application/timestamped-data",
370
+ tsv: "text/tab-separated-values",
371
+ ttc: "font/collection",
372
+ ttf: "font/ttf",
373
+ ttl: "text/turtle",
374
+ ttml: "application/ttml+xml",
375
+ txt: "text/plain",
376
+ u3d: "model/u3d",
377
+ u8dsn: "message/global-delivery-status",
378
+ u8hdr: "message/global-headers",
379
+ u8mdn: "message/global-disposition-notification",
380
+ u8msg: "message/global",
381
+ ubj: "application/ubjson",
382
+ uri: "text/uri-list",
383
+ uris: "text/uri-list",
384
+ urls: "text/uri-list",
385
+ vcard: "text/vcard",
386
+ vrml: "model/vrml",
387
+ vtt: "text/vtt",
388
+ vxml: "application/voicexml+xml",
389
+ war: "application/java-archive",
390
+ wasm: "application/wasm",
391
+ wav: "audio/wav",
392
+ weba: "audio/webm",
393
+ webm: "video/webm",
394
+ webmanifest: "application/manifest+json",
395
+ webp: "image/webp",
396
+ wgsl: "text/wgsl",
397
+ wgt: "application/widget",
398
+ wif: "application/watcherinfo+xml",
399
+ wmf: "image/wmf",
400
+ woff: "font/woff",
401
+ woff2: "font/woff2",
402
+ wrl: "model/vrml",
403
+ wsdl: "application/wsdl+xml",
404
+ wspolicy: "application/wspolicy+xml",
405
+ x3d: "model/x3d+xml",
406
+ x3db: "model/x3d+fastinfoset",
407
+ x3dbz: "model/x3d+binary",
408
+ x3dv: "model/x3d-vrml",
409
+ x3dvz: "model/x3d+vrml",
410
+ x3dz: "model/x3d+xml",
411
+ xaml: "application/xaml+xml",
412
+ xav: "application/xcap-att+xml",
413
+ xca: "application/xcap-caps+xml",
414
+ xcs: "application/calendar+xml",
415
+ xdf: "application/xcap-diff+xml",
416
+ xdssc: "application/dssc+xml",
417
+ xel: "application/xcap-el+xml",
418
+ xenc: "application/xenc+xml",
419
+ xer: "application/patch-ops-error+xml",
420
+ xfdf: "application/xfdf",
421
+ xht: "application/xhtml+xml",
422
+ xhtml: "application/xhtml+xml",
423
+ xhvml: "application/xv+xml",
424
+ xlf: "application/xliff+xml",
425
+ xm: "audio/xm",
426
+ xml: "text/xml",
427
+ xns: "application/xcap-ns+xml",
428
+ xop: "application/xop+xml",
429
+ xpl: "application/xproc+xml",
430
+ xsd: "application/xml",
431
+ xsf: "application/prs.xsf+xml",
432
+ xsl: "application/xml",
433
+ xslt: "application/xml",
434
+ xspf: "application/xspf+xml",
435
+ xvm: "application/xv+xml",
436
+ xvml: "application/xv+xml",
437
+ yaml: "text/yaml",
438
+ yang: "application/yang",
439
+ yin: "application/yin+xml",
440
+ yml: "text/yaml",
441
+ zip: "application/zip",
442
+ any: "*/*",
443
+ "*": "application/octet-stream",
444
+ formEncoded: "application/x-www-form-urlencoded",
445
+ formMultipart: "multipart/form-data",
446
+ } as const satisfies Record<string, string>;
447
+
448
+ function getMimeType(extn: string): string {
449
+ // oxlint-disable-next-line prefer-template
450
+ let tmp = String(extn).trim().toLowerCase();
451
+ let idx = tmp.lastIndexOf(".");
452
+ // oxlint-disable-next-line no-bitwise no-negated-condition no-plusplus
453
+ const key = (!~idx ? tmp : tmp.slice(++idx)) as keyof typeof mimes;
454
+ return mimes[key] || mimes["*"];
455
+ }
456
+
457
+ export { getMimeType, mimes };
@@ -0,0 +1,49 @@
1
+ import type { ResponseConfig, ZodContentObject } from "@asteasolutions/zod-to-openapi";
2
+ import { z } from "@hono/zod-openapi";
3
+ import { mimes } from "./mime-utils.ts";
4
+
5
+ export const openapiResponsesHtml = {
6
+ [mimes.html]: { schema: z.string().openapi({ example: "<!DOCTYPE html>" }) },
7
+ } as const satisfies ZodContentObject;
8
+
9
+ export function openapiResponseRedirect(description: string): ResponseConfig {
10
+ return {
11
+ description,
12
+ headers: {
13
+ location: {
14
+ description: "Location/URL to redirect.",
15
+ schema: { type: "string" },
16
+ required: true,
17
+ },
18
+ "hx-location": {
19
+ description: "Location/URL to redirect using HTMX.",
20
+ schema: { type: "string" },
21
+ required: false,
22
+ },
23
+ },
24
+ };
25
+ }
26
+
27
+ export const openapiErrorResponseContent: ZodContentObject = {
28
+ [mimes.json]: {
29
+ schema: z.object({ errorMessage: z.string() }).meta({ id: "ResponseError" }),
30
+ },
31
+ };
32
+ export const openapiCommonErrorResponses: Record<number | string, ResponseConfig> = {
33
+ 400: {
34
+ content: openapiErrorResponseContent,
35
+ description: "Invalid request data",
36
+ },
37
+ 401: {
38
+ content: openapiErrorResponseContent,
39
+ description: "Unauthenticated access",
40
+ },
41
+ 403: {
42
+ content: openapiErrorResponseContent,
43
+ description: "Unauthorised access",
44
+ },
45
+ 500: {
46
+ content: openapiErrorResponseContent,
47
+ description: "An unexpected server-error occurred.",
48
+ },
49
+ };
@@ -0,0 +1,97 @@
1
+ import { SuperHeaders } from "@remix-run/headers";
2
+ import { getStore } from "../utils/store.ts";
3
+ import { mimes } from "./mime-utils.ts";
4
+
5
+ interface ErrorObject {
6
+ message: string;
7
+ status: number;
8
+ }
9
+
10
+ export function checkIsHXRequest(request?: Request): boolean {
11
+ const req = request ?? getStore().request;
12
+ return req.headers.get("hx-request") === "true";
13
+ }
14
+
15
+ export function checkIsHTMLRequest(checkHX?: boolean, request?: Request): boolean {
16
+ const req = request ?? getStore().request;
17
+
18
+ const accept = req.headers.get("accept");
19
+ if (checkHX && checkIsHXRequest(req)) {
20
+ return true;
21
+ }
22
+ return Boolean(accept?.includes(mimes.html));
23
+ }
24
+
25
+ export function validateIsFormEncodedRequest(request?: Request): undefined | ErrorObject {
26
+ const store = getStore();
27
+ const { contentType } = request ? new SuperHeaders(request.headers) : store.headers;
28
+
29
+ if (!contentType) {
30
+ return {
31
+ message: "Content-Length header is required",
32
+ status: 400,
33
+ };
34
+ }
35
+
36
+ if (!contentType.mediaType?.includes(mimes.formEncoded)) {
37
+ return {
38
+ message: `Content-Type header is invalid, Expected: ${mimes.formEncoded}`,
39
+ status: 415,
40
+ };
41
+ }
42
+
43
+ return undefined;
44
+ }
45
+
46
+ export function validateBuildUploadZipBody(request: Request): ErrorObject | undefined {
47
+ const { headers: storeHeaders } = getStore();
48
+ const { body } = request;
49
+
50
+ if (!body) {
51
+ return {
52
+ message: "Request body is required",
53
+ status: 400,
54
+ };
55
+ }
56
+
57
+ const { contentLength } = request ? new SuperHeaders(request.headers) : storeHeaders;
58
+
59
+ if (contentLength === null) {
60
+ return {
61
+ message: "Content-Length header is required",
62
+ status: 411,
63
+ };
64
+ }
65
+ if (contentLength === 0) {
66
+ return {
67
+ message: "Content-Length should be greater than 0",
68
+ status: 400,
69
+ };
70
+ }
71
+
72
+ return undefined;
73
+ }
74
+
75
+ export function parseRequestCookieHeader(
76
+ cookieHeaderOrRequest: string | Request,
77
+ ): Record<string, string> {
78
+ const cookieHeader =
79
+ typeof cookieHeaderOrRequest === "string"
80
+ ? cookieHeaderOrRequest
81
+ : new Headers(cookieHeaderOrRequest.headers).get("cookie");
82
+
83
+ const cookies: Record<string, string> = {};
84
+
85
+ if (!cookieHeader) {
86
+ return cookies;
87
+ }
88
+
89
+ for (const cookie of cookieHeader.split(";")) {
90
+ const [key, value] = cookie.split("=");
91
+ if (key !== undefined && value !== undefined) {
92
+ cookies[decodeURIComponent(key.trim())] = decodeURIComponent(value.trim());
93
+ }
94
+ }
95
+
96
+ return cookies;
97
+ }
@@ -0,0 +1,20 @@
1
+ import type { MiddlewareHandler } from "hono";
2
+ import { checkIsHXRequest } from "../utils/request.ts";
3
+
4
+ /**
5
+ * Middleware to handle htmx redirects.
6
+ * If the response status is a redirect (3xx) and the request is an htmx request,
7
+ * it sets the "HX-redirect" header with the redirect location and removes the "Location" header.
8
+ */
9
+ export function htmxRedirectResponse(): MiddlewareHandler {
10
+ return async (ctx, next) => {
11
+ await next();
12
+ if (ctx.res.status >= 300 && ctx.res.status < 400) {
13
+ const location = ctx.res.headers.get("Location");
14
+ if (location && checkIsHXRequest(ctx.req.raw)) {
15
+ ctx.res.headers.set("HX-redirect", location);
16
+ ctx.res.headers.delete("Location");
17
+ }
18
+ }
19
+ };
20
+ }