@fastly/compute-js-static-publish 7.0.1 → 8.0.0-beta.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 (256) hide show
  1. package/README.md +13 -4
  2. package/README.short.md +13 -4
  3. package/build/cli/cli/commands/manage/clean.d.ts.map +1 -0
  4. package/build/cli/{commands → cli/commands}/manage/clean.js +62 -108
  5. package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -0
  6. package/build/cli/{commands → cli/commands}/manage/collections/delete.js +50 -72
  7. package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -0
  8. package/build/cli/{commands → cli/commands}/manage/collections/index.js +15 -1
  9. package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -0
  10. package/build/cli/{commands → cli/commands}/manage/collections/list.js +45 -73
  11. package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -0
  12. package/build/cli/{commands → cli/commands}/manage/collections/promote.js +56 -93
  13. package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -0
  14. package/build/cli/{commands → cli/commands}/manage/collections/update-expiration.js +48 -77
  15. package/build/cli/cli/commands/manage/index.d.ts.map +1 -0
  16. package/build/cli/{commands → cli/commands}/manage/index.js +15 -1
  17. package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -0
  18. package/build/cli/{commands → cli/commands}/manage/publish-content.js +90 -187
  19. package/build/cli/{commands → cli/commands}/scaffold/index.d.ts +4 -0
  20. package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -0
  21. package/build/cli/{commands → cli/commands}/scaffold/index.js +262 -38
  22. package/build/cli/cli/compression/brotli.d.ts.map +1 -0
  23. package/build/cli/cli/compression/gzip.d.ts.map +1 -0
  24. package/build/cli/cli/compression/index.d.ts.map +1 -0
  25. package/build/cli/{index.d.ts.map → cli/index.d.ts.map} +1 -1
  26. package/build/cli/{index.js → cli/index.js} +8 -0
  27. package/build/cli/cli/storage/kv-store-local-provider.d.ts +20 -0
  28. package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -0
  29. package/build/cli/cli/storage/kv-store-local-provider.js +86 -0
  30. package/build/cli/cli/storage/kv-store-provider.d.ts +24 -0
  31. package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -0
  32. package/build/cli/cli/storage/kv-store-provider.js +182 -0
  33. package/build/cli/cli/storage/s3-storage-provider.d.ts +30 -0
  34. package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -0
  35. package/build/cli/cli/storage/s3-storage-provider.js +201 -0
  36. package/build/cli/cli/storage/storage-provider.d.ts +44 -0
  37. package/build/cli/cli/storage/storage-provider.d.ts.map +1 -0
  38. package/build/cli/cli/storage/storage-provider.js +26 -0
  39. package/build/cli/cli/util/api-token.d.ts.map +1 -0
  40. package/build/cli/cli/util/args.d.ts.map +1 -0
  41. package/build/cli/cli/util/aws-credentials.d.ts +12 -0
  42. package/build/cli/cli/util/aws-credentials.d.ts.map +1 -0
  43. package/build/cli/cli/util/aws-credentials.js +67 -0
  44. package/build/cli/{util → cli/util}/config.d.ts +1 -1
  45. package/build/cli/cli/util/config.d.ts.map +1 -0
  46. package/build/cli/{util → cli/util}/config.js +36 -20
  47. package/build/cli/cli/util/content-types.d.ts.map +1 -0
  48. package/build/cli/cli/util/data.d.ts.map +1 -0
  49. package/build/cli/cli/util/fastly-toml.d.ts.map +1 -0
  50. package/build/cli/cli/util/files.d.ts.map +1 -0
  51. package/build/cli/{util → cli/util}/files.js +15 -0
  52. package/build/cli/cli/util/kv-store-items.d.ts +5 -0
  53. package/build/cli/cli/util/kv-store-items.d.ts.map +1 -0
  54. package/build/cli/{util → cli/util}/kv-store-items.js +3 -42
  55. package/build/cli/{util → cli/util}/kv-store-local-server.d.ts +4 -7
  56. package/build/cli/cli/util/kv-store-local-server.d.ts.map +1 -0
  57. package/build/cli/{util → cli/util}/kv-store.d.ts +7 -10
  58. package/build/cli/cli/util/kv-store.d.ts.map +1 -0
  59. package/build/cli/cli/util/node.d.ts.map +1 -0
  60. package/build/cli/cli/util/package.d.ts.map +1 -0
  61. package/build/cli/{util → cli/util}/package.js +1 -1
  62. package/build/cli/{util → cli/util}/retryable.d.ts +3 -0
  63. package/build/cli/cli/util/retryable.d.ts.map +1 -0
  64. package/build/cli/cli/util/retryable.js +76 -0
  65. package/build/cli/cli/util/s3.d.ts +7 -0
  66. package/build/cli/cli/util/s3.d.ts.map +1 -0
  67. package/build/cli/cli/util/s3.js +43 -0
  68. package/build/cli/cli/util/variants.d.ts.map +1 -0
  69. package/build/{models/assets/kvstore-assets.d.ts → cli/models/assets/index.d.ts} +5 -5
  70. package/build/cli/models/assets/index.d.ts.map +1 -0
  71. package/build/cli/models/assets/index.js +33 -0
  72. package/build/cli/models/compression/index.d.ts.map +1 -0
  73. package/build/cli/models/config/kv-store-config.d.ts +6 -0
  74. package/build/cli/models/config/kv-store-config.d.ts.map +1 -0
  75. package/build/cli/models/config/kv-store-config.js +15 -0
  76. package/build/{models → cli/models}/config/publish-content-config.d.ts +4 -3
  77. package/build/cli/models/config/publish-content-config.d.ts.map +1 -0
  78. package/build/cli/models/config/publisher-server-config.d.ts.map +1 -0
  79. package/build/cli/models/config/s3-storage-config.d.ts +8 -0
  80. package/build/cli/models/config/s3-storage-config.d.ts.map +1 -0
  81. package/build/cli/models/config/s3-storage-config.js +11 -0
  82. package/build/cli/models/config/static-publish-rc.d.ts +31 -0
  83. package/build/cli/models/config/static-publish-rc.d.ts.map +1 -0
  84. package/build/cli/models/config/static-publish-rc.js +39 -0
  85. package/build/cli/models/metadata/index.d.ts +2 -0
  86. package/build/cli/models/metadata/index.d.ts.map +1 -0
  87. package/build/cli/models/metadata/index.js +8 -0
  88. package/build/cli/models/server/index.d.ts +7 -0
  89. package/build/cli/models/server/index.d.ts.map +1 -0
  90. package/build/cli/models/server/index.js +26 -0
  91. package/build/cli/models/time/index.d.ts.map +1 -0
  92. package/build/{models → cli/models}/time/index.js +5 -5
  93. package/build/server/models/assets/index.d.ts +17 -0
  94. package/build/server/models/assets/index.d.ts.map +1 -0
  95. package/build/server/models/assets/index.js +33 -0
  96. package/build/server/models/compression/index.d.ts +4 -0
  97. package/build/server/models/compression/index.d.ts.map +1 -0
  98. package/build/server/models/compression/index.js +11 -0
  99. package/build/server/models/config/kv-store-config.d.ts +6 -0
  100. package/build/server/models/config/kv-store-config.d.ts.map +1 -0
  101. package/build/server/models/config/kv-store-config.js +15 -0
  102. package/build/server/models/config/publish-content-config.d.ts +40 -0
  103. package/build/server/models/config/publish-content-config.d.ts.map +1 -0
  104. package/build/server/models/config/publisher-server-config.d.ts +20 -0
  105. package/build/server/models/config/publisher-server-config.d.ts.map +1 -0
  106. package/build/server/models/config/s3-storage-config.d.ts +8 -0
  107. package/build/server/models/config/s3-storage-config.d.ts.map +1 -0
  108. package/build/server/models/config/s3-storage-config.js +11 -0
  109. package/build/server/models/config/static-publish-rc.d.ts +31 -0
  110. package/build/server/models/config/static-publish-rc.d.ts.map +1 -0
  111. package/build/server/models/config/static-publish-rc.js +39 -0
  112. package/build/server/models/metadata/index.d.ts +2 -0
  113. package/build/server/models/metadata/index.d.ts.map +1 -0
  114. package/build/server/models/metadata/index.js +8 -0
  115. package/build/server/models/server/index.d.ts +7 -0
  116. package/build/server/models/server/index.d.ts.map +1 -0
  117. package/build/server/models/server/index.js +26 -0
  118. package/build/server/models/time/index.d.ts +8 -0
  119. package/build/server/models/time/index.d.ts.map +1 -0
  120. package/build/server/models/time/index.js +54 -0
  121. package/build/server/server/collection-selector/from-config-store.d.ts.map +1 -0
  122. package/build/server/server/collection-selector/from-cookie.d.ts.map +1 -0
  123. package/build/server/server/collection-selector/from-request.d.ts.map +1 -0
  124. package/build/server/server/collection-selector/index.d.ts.map +1 -0
  125. package/build/server/server/collection-selector/request-collection-selector.d.ts.map +1 -0
  126. package/build/server/server/collection-selector/request-collection-selector.js +5 -0
  127. package/build/server/server/index.d.ts +8 -0
  128. package/build/server/server/index.d.ts.map +1 -0
  129. package/build/server/server/index.js +15 -0
  130. package/build/server/{publisher-server → server/publisher-server}/index.d.ts +14 -14
  131. package/build/server/server/publisher-server/index.d.ts.map +1 -0
  132. package/build/server/{publisher-server → server/publisher-server}/index.js +60 -61
  133. package/build/server/server/publisher-server/serve-preconditions/if-modified-since.d.ts.map +1 -0
  134. package/build/server/server/publisher-server/serve-preconditions/if-none-match.d.ts.map +1 -0
  135. package/build/server/server/storage/kv-store-provider.d.ts +8 -0
  136. package/build/server/server/storage/kv-store-provider.d.ts.map +1 -0
  137. package/build/server/server/storage/kv-store-provider.js +24 -0
  138. package/build/server/server/storage/s3-storage-provider.d.ts +26 -0
  139. package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -0
  140. package/build/server/server/storage/s3-storage-provider.js +110 -0
  141. package/build/server/server/storage/storage-provider.d.ts +48 -0
  142. package/build/server/server/storage/storage-provider.d.ts.map +1 -0
  143. package/build/server/{util/kv-store.js → server/storage/storage-provider.js} +17 -39
  144. package/build/server/server/util/cookies.d.ts.map +1 -0
  145. package/build/server/server/util/kv-store.d.ts.map +1 -0
  146. package/build/server/server/util/kv-store.js +40 -0
  147. package/package.json +9 -5
  148. package/build/cli/commands/manage/clean.d.ts.map +0 -1
  149. package/build/cli/commands/manage/collections/delete.d.ts.map +0 -1
  150. package/build/cli/commands/manage/collections/index.d.ts.map +0 -1
  151. package/build/cli/commands/manage/collections/list.d.ts.map +0 -1
  152. package/build/cli/commands/manage/collections/promote.d.ts.map +0 -1
  153. package/build/cli/commands/manage/collections/update-expiration.d.ts.map +0 -1
  154. package/build/cli/commands/manage/index.d.ts.map +0 -1
  155. package/build/cli/commands/manage/publish-content.d.ts.map +0 -1
  156. package/build/cli/commands/scaffold/index.d.ts.map +0 -1
  157. package/build/cli/compression/brotli.d.ts.map +0 -1
  158. package/build/cli/compression/gzip.d.ts.map +0 -1
  159. package/build/cli/compression/index.d.ts.map +0 -1
  160. package/build/cli/util/api-token.d.ts.map +0 -1
  161. package/build/cli/util/args.d.ts.map +0 -1
  162. package/build/cli/util/config.d.ts.map +0 -1
  163. package/build/cli/util/content-types.d.ts.map +0 -1
  164. package/build/cli/util/data.d.ts.map +0 -1
  165. package/build/cli/util/fastly-toml.d.ts.map +0 -1
  166. package/build/cli/util/files.d.ts.map +0 -1
  167. package/build/cli/util/kv-store-items.d.ts +0 -13
  168. package/build/cli/util/kv-store-items.d.ts.map +0 -1
  169. package/build/cli/util/kv-store-local-server.d.ts.map +0 -1
  170. package/build/cli/util/kv-store.d.ts.map +0 -1
  171. package/build/cli/util/node.d.ts.map +0 -1
  172. package/build/cli/util/package.d.ts.map +0 -1
  173. package/build/cli/util/retryable.d.ts.map +0 -1
  174. package/build/cli/util/retryable.js +0 -43
  175. package/build/cli/util/variants.d.ts.map +0 -1
  176. package/build/index.d.ts +0 -6
  177. package/build/index.d.ts.map +0 -1
  178. package/build/index.js +0 -7
  179. package/build/models/assets/kvstore-assets.d.ts.map +0 -1
  180. package/build/models/assets/kvstore-assets.js +0 -28
  181. package/build/models/compression/index.d.ts.map +0 -1
  182. package/build/models/config/publish-content-config.d.ts.map +0 -1
  183. package/build/models/config/publisher-server-config.d.ts.map +0 -1
  184. package/build/models/config/static-publish-rc.d.ts +0 -7
  185. package/build/models/config/static-publish-rc.d.ts.map +0 -1
  186. package/build/models/server/index.d.ts +0 -5
  187. package/build/models/server/index.d.ts.map +0 -1
  188. package/build/models/server/index.js +0 -1
  189. package/build/models/time/index.d.ts.map +0 -1
  190. package/build/server/collection-selector/from-config-store.d.ts.map +0 -1
  191. package/build/server/collection-selector/from-cookie.d.ts.map +0 -1
  192. package/build/server/collection-selector/from-request.d.ts.map +0 -1
  193. package/build/server/collection-selector/index.d.ts.map +0 -1
  194. package/build/server/collection-selector/request-collection-selector.d.ts.map +0 -1
  195. package/build/server/publisher-server/index.d.ts.map +0 -1
  196. package/build/server/publisher-server/serve-preconditions/if-modified-since.d.ts.map +0 -1
  197. package/build/server/publisher-server/serve-preconditions/if-none-match.d.ts.map +0 -1
  198. package/build/server/util/cookies.d.ts.map +0 -1
  199. package/build/server/util/kv-store.d.ts.map +0 -1
  200. /package/build/cli/{commands → cli/commands}/manage/clean.d.ts +0 -0
  201. /package/build/cli/{commands → cli/commands}/manage/collections/delete.d.ts +0 -0
  202. /package/build/cli/{commands → cli/commands}/manage/collections/index.d.ts +0 -0
  203. /package/build/cli/{commands → cli/commands}/manage/collections/list.d.ts +0 -0
  204. /package/build/cli/{commands → cli/commands}/manage/collections/promote.d.ts +0 -0
  205. /package/build/cli/{commands → cli/commands}/manage/collections/update-expiration.d.ts +0 -0
  206. /package/build/cli/{commands → cli/commands}/manage/index.d.ts +0 -0
  207. /package/build/cli/{commands → cli/commands}/manage/publish-content.d.ts +0 -0
  208. /package/build/cli/{compression → cli/compression}/brotli.d.ts +0 -0
  209. /package/build/cli/{compression → cli/compression}/brotli.js +0 -0
  210. /package/build/cli/{compression → cli/compression}/gzip.d.ts +0 -0
  211. /package/build/cli/{compression → cli/compression}/gzip.js +0 -0
  212. /package/build/cli/{compression → cli/compression}/index.d.ts +0 -0
  213. /package/build/cli/{compression → cli/compression}/index.js +0 -0
  214. /package/build/cli/{index.d.ts → cli/index.d.ts} +0 -0
  215. /package/build/cli/{util → cli/util}/api-token.d.ts +0 -0
  216. /package/build/cli/{util → cli/util}/api-token.js +0 -0
  217. /package/build/cli/{util → cli/util}/args.d.ts +0 -0
  218. /package/build/cli/{util → cli/util}/args.js +0 -0
  219. /package/build/cli/{util → cli/util}/content-types.d.ts +0 -0
  220. /package/build/cli/{util → cli/util}/content-types.js +0 -0
  221. /package/build/cli/{util → cli/util}/data.d.ts +0 -0
  222. /package/build/cli/{util → cli/util}/data.js +0 -0
  223. /package/build/cli/{util → cli/util}/fastly-toml.d.ts +0 -0
  224. /package/build/cli/{util → cli/util}/fastly-toml.js +0 -0
  225. /package/build/cli/{util → cli/util}/files.d.ts +0 -0
  226. /package/build/cli/{util → cli/util}/kv-store-local-server.js +0 -0
  227. /package/build/cli/{util → cli/util}/kv-store.js +0 -0
  228. /package/build/cli/{util → cli/util}/node.d.ts +0 -0
  229. /package/build/cli/{util → cli/util}/node.js +0 -0
  230. /package/build/cli/{util → cli/util}/package.d.ts +0 -0
  231. /package/build/cli/{util → cli/util}/variants.d.ts +0 -0
  232. /package/build/cli/{util → cli/util}/variants.js +0 -0
  233. /package/build/{models → cli/models}/compression/index.d.ts +0 -0
  234. /package/build/{models → cli/models}/compression/index.js +0 -0
  235. /package/build/{models → cli/models}/config/publish-content-config.js +0 -0
  236. /package/build/{models → cli/models}/config/publisher-server-config.d.ts +0 -0
  237. /package/build/{models → cli/models}/config/publisher-server-config.js +0 -0
  238. /package/build/{models → cli/models}/time/index.d.ts +0 -0
  239. /package/build/{models/config/static-publish-rc.js → server/models/config/publish-content-config.js} +0 -0
  240. /package/build/server/{collection-selector/request-collection-selector.js → models/config/publisher-server-config.js} +0 -0
  241. /package/build/server/{collection-selector → server/collection-selector}/from-config-store.d.ts +0 -0
  242. /package/build/server/{collection-selector → server/collection-selector}/from-config-store.js +0 -0
  243. /package/build/server/{collection-selector → server/collection-selector}/from-cookie.d.ts +0 -0
  244. /package/build/server/{collection-selector → server/collection-selector}/from-cookie.js +0 -0
  245. /package/build/server/{collection-selector → server/collection-selector}/from-request.d.ts +0 -0
  246. /package/build/server/{collection-selector → server/collection-selector}/from-request.js +0 -0
  247. /package/build/server/{collection-selector → server/collection-selector}/index.d.ts +0 -0
  248. /package/build/server/{collection-selector → server/collection-selector}/index.js +0 -0
  249. /package/build/server/{collection-selector → server/collection-selector}/request-collection-selector.d.ts +0 -0
  250. /package/build/server/{publisher-server → server/publisher-server}/serve-preconditions/if-modified-since.d.ts +0 -0
  251. /package/build/server/{publisher-server → server/publisher-server}/serve-preconditions/if-modified-since.js +0 -0
  252. /package/build/server/{publisher-server → server/publisher-server}/serve-preconditions/if-none-match.d.ts +0 -0
  253. /package/build/server/{publisher-server → server/publisher-server}/serve-preconditions/if-none-match.js +0 -0
  254. /package/build/server/{util → server/util}/cookies.d.ts +0 -0
  255. /package/build/server/{util → server/util}/cookies.js +0 -0
  256. /package/build/server/{util → server/util}/kv-store.d.ts +0 -0
@@ -1,11 +1,11 @@
1
- import { type KVStoreEntry } from 'fastly:kv-store';
2
1
  import { type StaticPublishRc } from '../../models/config/static-publish-rc.js';
3
2
  import { type PublisherServerConfigNormalized } from '../../models/config/publisher-server-config.js';
4
3
  import { type ContentCompressionTypes } from '../../models/compression/index.js';
5
- import { type KVAssetEntry, type KVAssetEntryMap, type KVAssetVariantMetadata } from '../../models/assets/kvstore-assets.js';
6
- type KVAssetVariant = {
7
- kvStoreEntry: KVStoreEntry;
8
- } & KVAssetVariantMetadata;
4
+ import { type AssetEntry, type AssetEntryMap, type AssetVariantMetadata } from '../../models/assets/index.js';
5
+ import { type StorageEntry, type StorageProvider } from '../storage/storage-provider.js';
6
+ type AssetVariant = {
7
+ storageEntry: StorageEntry;
8
+ } & AssetVariantMetadata;
9
9
  export declare function buildHeadersSubset(responseHeaders: Headers, keys: Readonly<string[]>): Headers;
10
10
  type AssetInit = {
11
11
  status?: number;
@@ -13,27 +13,27 @@ type AssetInit = {
13
13
  cache?: 'extended' | 'never' | null;
14
14
  };
15
15
  export declare class PublisherServer {
16
- constructor(publishId: string, kvStoreName: string, defaultCollectionName: string);
16
+ constructor(publishId: string, storageProvider: StorageProvider, defaultCollectionName: string);
17
17
  static fromStaticPublishRc(config: StaticPublishRc): PublisherServer;
18
18
  publishId: string;
19
- kvStoreName: string;
19
+ storageProvider: StorageProvider;
20
20
  defaultCollectionName: string;
21
21
  activeCollectionName: string;
22
22
  collectionNameHeader: string | null;
23
23
  settingsCached: PublisherServerConfigNormalized | null | undefined;
24
- kvAssetsIndex: KVAssetEntryMap | null | undefined;
24
+ assetEntryMapCache: AssetEntryMap | null | undefined;
25
25
  setActiveCollectionName(collectionName: string): void;
26
26
  setCollectionNameHeader(collectionHeader: string | null): void;
27
27
  getServerConfig(): Promise<PublisherServerConfigNormalized | null>;
28
28
  getStaticItems(): Promise<(string | RegExp)[]>;
29
- getKvAssetsIndex(): Promise<KVAssetEntryMap | null>;
30
- getMatchingAsset(assetKey: string, applyAuto?: boolean): Promise<KVAssetEntry | null>;
29
+ getAssetEntryMap(): Promise<AssetEntryMap | null>;
30
+ getMatchingAsset(assetKey: string, applyAuto?: boolean): Promise<AssetEntry | null>;
31
31
  findAcceptEncodingsGroups(request: Request): Promise<ContentCompressionTypes[][]>;
32
32
  testExtendedCache(pathname: string): Promise<boolean>;
33
- handlePreconditions(request: Request, asset: KVAssetEntry, responseHeaders: Headers): Response | null;
34
- loadKvAssetVariant(entry: KVAssetEntry, variant: ContentCompressionTypes | null): Promise<KVAssetVariant | null>;
35
- private findKVAssetVariantForAcceptEncodingsGroups;
36
- serveAsset(request: Request, asset: KVAssetEntry, init?: AssetInit): Promise<Response>;
33
+ handlePreconditions(request: Request, asset: AssetEntry, responseHeaders: Headers): Response | null;
34
+ loadAssetVariant(entry: AssetEntry, variant: ContentCompressionTypes | null): Promise<AssetVariant | null>;
35
+ private findAssetVariantForAcceptEncodingsGroups;
36
+ serveAsset(request: Request, asset: AssetEntry, init?: AssetInit): Promise<Response>;
37
37
  serveRequest(request: Request): Promise<Response | null>;
38
38
  }
39
39
  export {};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/publisher-server/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,eAAe,EACrB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,KAAK,+BAA+B,EACrC,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACL,KAAK,uBAAuB,EAC7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,oBAAoB,EAE1B,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EAErB,MAAM,gCAAgC,CAAC;AAIxC,KAAK,YAAY,GAAG;IAClB,YAAY,EAAE,YAAY,CAAC;CAC5B,GAAG,oBAAoB,CAAC;AAEzB,wBAAgB,kBAAkB,CAAC,eAAe,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,WAWpF;AAmBD,KAAK,SAAS,GAAG;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,UAAU,GAAG,OAAO,GAAG,IAAI,CAAC;CACrC,CAAC;AAEF,qBAAa,eAAe;gBAExB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,eAAe,EAChC,qBAAqB,EAAE,MAAM;IAS/B,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,eAAe;IASlD,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,eAAe,CAAC;IACjC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IAGpC,cAAc,EAAE,+BAA+B,GAAG,IAAI,GAAG,SAAS,CAAC;IAGnE,kBAAkB,EAAE,aAAa,GAAG,IAAI,GAAG,SAAS,CAAC;IAErD,uBAAuB,CAAC,cAAc,EAAE,MAAM;IAM9C,uBAAuB,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI;IAKjD,eAAe;IAgBf,cAAc;IAoBd,gBAAgB;IAuChB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IA2D1F,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC;IAoDjF,iBAAiB,CAAC,QAAQ,EAAE,MAAM;IAcxC,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,OAAO,GAAG,QAAQ,GAAG,IAAI;IA6DtF,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,uBAAuB,GAAG,IAAI,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;YA8BzG,wCAAwC;IAyChD,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;IAiDpF,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CAqE/D"}
@@ -2,13 +2,12 @@
2
2
  * Copyright Fastly, Inc.
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
- /// <reference types="@fastly/js-compute" />
6
- import { KVStore } from 'fastly:kv-store';
7
- import { isKVAssetVariantMetadata, } from '../../models/assets/kvstore-assets.js';
8
- import { getKVStoreEntry } from '../util/kv-store.js';
5
+ import { decodeAssetVariantMetadata, } from '../../models/assets/index.js';
6
+ import { decodeIndexMetadata, } from '../../models/server/index.js';
7
+ import { isExpired } from '../../models/time/index.js';
8
+ import { loadStorageProviderFromStaticPublishRc, } from '../storage/storage-provider.js';
9
9
  import { checkIfModifiedSince, getIfModifiedSinceHeader } from './serve-preconditions/if-modified-since.js';
10
10
  import { checkIfNoneMatch, getIfNoneMatchHeader } from './serve-preconditions/if-none-match.js';
11
- import { isExpired } from "../../models/time/index.js";
12
11
  export function buildHeadersSubset(responseHeaders, keys) {
13
12
  const resultHeaders = new Headers();
14
13
  for (const value of keys) {
@@ -37,32 +36,32 @@ function requestAcceptsTextHtml(req) {
37
36
  return true;
38
37
  }
39
38
  export class PublisherServer {
40
- constructor(publishId, kvStoreName, defaultCollectionName) {
39
+ constructor(publishId, storageProvider, defaultCollectionName) {
41
40
  this.publishId = publishId;
42
- this.kvStoreName = kvStoreName;
41
+ this.storageProvider = storageProvider;
43
42
  this.defaultCollectionName = defaultCollectionName;
44
43
  this.activeCollectionName = this.defaultCollectionName;
45
44
  this.collectionNameHeader = 'X-Publisher-Server-Collection';
46
45
  }
47
46
  static fromStaticPublishRc(config) {
48
- return new PublisherServer(config.publishId, config.kvStoreName, config.defaultCollectionName);
47
+ const storeProvider = loadStorageProviderFromStaticPublishRc(config);
48
+ return new PublisherServer(config.publishId, storeProvider, config.defaultCollectionName);
49
49
  }
50
50
  setActiveCollectionName(collectionName) {
51
51
  this.activeCollectionName = collectionName;
52
52
  this.settingsCached = undefined;
53
- this.kvAssetsIndex = undefined;
53
+ this.assetEntryMapCache = undefined;
54
54
  }
55
55
  setCollectionNameHeader(collectionHeader) {
56
56
  this.collectionNameHeader = collectionHeader;
57
57
  }
58
- // Server config is obtained from the KV Store, and cached for the duration of this object.
58
+ // Server config is obtained from storage, and cached for the duration of this object.
59
59
  async getServerConfig() {
60
60
  if (this.settingsCached !== undefined) {
61
61
  return this.settingsCached;
62
62
  }
63
63
  const settingsFileKey = `${this.publishId}_settings_${this.activeCollectionName}`;
64
- const kvStore = new KVStore(this.kvStoreName);
65
- const settingsFile = await getKVStoreEntry(kvStore, settingsFileKey);
64
+ const settingsFile = await this.storageProvider.getEntry(settingsFileKey);
66
65
  if (settingsFile == null) {
67
66
  console.error(`Settings File not found at ${settingsFileKey}.`);
68
67
  console.error(`You may need to publish your application.`);
@@ -92,51 +91,54 @@ export class PublisherServer {
92
91
  })
93
92
  .filter(x => Boolean(x));
94
93
  }
95
- async getKvAssetsIndex() {
96
- if (this.kvAssetsIndex !== undefined) {
97
- return this.kvAssetsIndex;
94
+ async getAssetEntryMap() {
95
+ if (this.assetEntryMapCache !== undefined) {
96
+ return this.assetEntryMapCache;
98
97
  }
99
98
  const indexFileKey = `${this.publishId}_index_${this.activeCollectionName}`;
100
- const kvStore = new KVStore(this.kvStoreName);
101
- const indexFile = await getKVStoreEntry(kvStore, indexFileKey);
99
+ const indexFile = await this.storageProvider.getEntry(indexFileKey);
102
100
  if (indexFile == null) {
103
101
  console.error(`Index File not found at ${indexFileKey}.`);
104
102
  console.error(`You may need to publish your application.`);
105
- this.kvAssetsIndex = null;
103
+ this.assetEntryMapCache = null;
106
104
  return null;
107
105
  }
108
106
  let collectionIsExpired = false;
109
107
  if (this.activeCollectionName !== this.defaultCollectionName) {
108
+ let metadata;
110
109
  const metadataText = indexFile.metadataText();
111
110
  if (metadataText != null) {
112
111
  try {
113
- const metadata = JSON.parse(metadataText);
114
- collectionIsExpired = metadata.expirationTime != null && isExpired(metadata.expirationTime);
112
+ metadata = JSON.parse(metadataText);
115
113
  }
116
114
  catch {
117
115
  }
116
+ metadata = decodeIndexMetadata(metadata);
117
+ }
118
+ if (metadata != null) {
119
+ collectionIsExpired = metadata.expirationTime != null && isExpired(metadata.expirationTime);
118
120
  }
119
121
  }
120
122
  if (collectionIsExpired) {
121
123
  console.error(`Requested collection expired at ${indexFileKey}.`);
122
- this.kvAssetsIndex = null;
124
+ this.assetEntryMapCache = null;
123
125
  return null;
124
126
  }
125
- this.kvAssetsIndex = (await indexFile.json());
126
- return this.kvAssetsIndex;
127
+ this.assetEntryMapCache = (await indexFile.json());
128
+ return this.assetEntryMapCache;
127
129
  }
128
130
  async getMatchingAsset(assetKey, applyAuto = false) {
129
131
  const serverConfig = await this.getServerConfig();
130
132
  if (serverConfig == null) {
131
133
  return null;
132
134
  }
133
- const kvAssetsIndex = await this.getKvAssetsIndex();
134
- if (kvAssetsIndex == null) {
135
+ const assetEntryMap = await this.getAssetEntryMap();
136
+ if (assetEntryMap == null) {
135
137
  return null;
136
138
  }
137
139
  if (!assetKey.endsWith('/')) {
138
140
  // A path that does not end in a slash can match an asset directly
139
- const asset = kvAssetsIndex[assetKey];
141
+ const asset = assetEntryMap[assetKey];
140
142
  if (asset != null) {
141
143
  return asset;
142
144
  }
@@ -145,7 +147,7 @@ export class PublisherServer {
145
147
  // looks for an asset that has the specified suffix (usually extension, such as .html)
146
148
  for (const extEntry of serverConfig.autoExt) {
147
149
  let assetKeyWithExt = assetKey + extEntry;
148
- const asset = kvAssetsIndex[assetKeyWithExt];
150
+ const asset = assetEntryMap[assetKeyWithExt];
149
151
  if (asset != null) {
150
152
  return asset;
151
153
  }
@@ -165,7 +167,7 @@ export class PublisherServer {
165
167
  assetNameAsDir = assetNameAsDir + '/';
166
168
  for (const indexEntry of serverConfig.autoIndex) {
167
169
  let assetKeyIndex = assetNameAsDir + indexEntry;
168
- const asset = kvAssetsIndex[assetKeyIndex];
170
+ const asset = assetEntryMap[assetKeyIndex];
169
171
  if (asset != null) {
170
172
  return asset;
171
173
  }
@@ -290,17 +292,16 @@ export class PublisherServer {
290
292
  // - perform the requested method and respond according to its success or failure.
291
293
  return null;
292
294
  }
293
- async loadKvAssetVariant(entry, variant) {
294
- const kvStore = new KVStore(this.kvStoreName);
295
+ async loadAssetVariant(entry, variant) {
295
296
  const baseHash = entry.key.slice(7);
296
297
  const baseKey = `${this.publishId}_files_sha256_${baseHash}`;
297
298
  const variantKey = variant != null ? `${baseKey}_${variant}` : baseKey;
298
- const kvStoreEntry = await getKVStoreEntry(kvStore, variantKey);
299
- if (kvStoreEntry == null) {
299
+ const storageEntry = await this.storageProvider.getEntry(variantKey);
300
+ if (storageEntry == null) {
300
301
  return null;
301
302
  }
302
- const metadataText = kvStoreEntry.metadataText() ?? '';
303
- if (metadataText === '') {
303
+ const metadataText = storageEntry.metadataText();
304
+ if (metadataText == null) {
304
305
  return null;
305
306
  }
306
307
  let metadata;
@@ -310,18 +311,16 @@ export class PublisherServer {
310
311
  catch {
311
312
  return null;
312
313
  }
313
- if (!isKVAssetVariantMetadata(metadata)) {
314
- return null;
315
- }
316
- if (metadata.size == null) {
314
+ metadata = decodeAssetVariantMetadata(metadata);
315
+ if (metadata == null) {
317
316
  return null;
318
317
  }
319
318
  return {
320
- kvStoreEntry,
319
+ storageEntry,
321
320
  ...metadata,
322
321
  };
323
322
  }
324
- async findKVAssetVariantForAcceptEncodingsGroups(entry, acceptEncodingsGroups = []) {
323
+ async findAssetVariantForAcceptEncodingsGroups(entry, acceptEncodingsGroups = []) {
325
324
  if (!entry.key.startsWith('sha256:')) {
326
325
  throw new TypeError(`Key must start with 'sha256:': ${entry.key}`);
327
326
  }
@@ -329,29 +328,29 @@ export class PublisherServer {
329
328
  // with the highest first
330
329
  for (const encodingGroup of acceptEncodingsGroups) {
331
330
  let smallestSize = undefined;
332
- let smallestEntry = undefined;
331
+ let smallestVariant = undefined;
333
332
  for (const encoding of encodingGroup) {
334
333
  if (!entry.variants.includes(encoding)) {
335
334
  continue;
336
335
  }
337
- const variantKvStoreEntry = await this.loadKvAssetVariant(entry, encoding);
338
- if (variantKvStoreEntry == null) {
336
+ const assetVariant = await this.loadAssetVariant(entry, encoding);
337
+ if (assetVariant == null) {
339
338
  continue;
340
339
  }
341
- if (smallestSize == null || variantKvStoreEntry.size < smallestSize) {
342
- smallestSize = variantKvStoreEntry.size;
343
- smallestEntry = variantKvStoreEntry;
340
+ if (smallestSize == null || assetVariant.size < smallestSize) {
341
+ smallestSize = assetVariant.size;
342
+ smallestVariant = assetVariant;
344
343
  }
345
344
  }
346
- if (smallestEntry != null) {
347
- return smallestEntry;
345
+ if (smallestVariant != null) {
346
+ return smallestVariant;
348
347
  }
349
348
  }
350
- const baseKvStoreEntry = await this.loadKvAssetVariant(entry, null);
351
- if (baseKvStoreEntry == null) {
349
+ const baseAssetVariant = await this.loadAssetVariant(entry, null);
350
+ if (baseAssetVariant == null) {
352
351
  throw new TypeError('Key not found: ' + entry.key);
353
352
  }
354
- return baseKvStoreEntry;
353
+ return baseAssetVariant;
355
354
  }
356
355
  async serveAsset(request, asset, init) {
357
356
  const headers = new Headers(init?.headers);
@@ -373,11 +372,11 @@ export class PublisherServer {
373
372
  headers.append('Cache-Control', cacheControlValue);
374
373
  }
375
374
  const acceptEncodings = await this.findAcceptEncodingsGroups(request);
376
- const kvAssetVariant = await this.findKVAssetVariantForAcceptEncodingsGroups(asset, acceptEncodings);
377
- if (kvAssetVariant.contentEncoding != null) {
378
- headers.append('Content-Encoding', kvAssetVariant.contentEncoding);
375
+ const assetVariant = await this.findAssetVariantForAcceptEncodingsGroups(asset, acceptEncodings);
376
+ if (assetVariant.contentEncoding != null) {
377
+ headers.append('Content-Encoding', assetVariant.contentEncoding);
379
378
  }
380
- headers.set('ETag', `"${kvAssetVariant.hash}"`);
379
+ headers.set('ETag', `"${assetVariant.hash}"`);
381
380
  if (asset.lastModifiedTime !== 0) {
382
381
  headers.set('Last-Modified', (new Date(asset.lastModifiedTime * 1000)).toUTCString());
383
382
  }
@@ -385,8 +384,8 @@ export class PublisherServer {
385
384
  if (preconditionResponse != null) {
386
385
  return preconditionResponse;
387
386
  }
388
- const kvStoreEntry = kvAssetVariant.kvStoreEntry;
389
- return new Response(kvStoreEntry.body, {
387
+ const storageEntry = assetVariant.storageEntry;
388
+ return new Response(storageEntry.body, {
390
389
  status: init?.status ?? 200,
391
390
  headers,
392
391
  });
@@ -419,14 +418,14 @@ export class PublisherServer {
419
418
  }
420
419
  // fallback HTML responses, like SPA and "not found" pages
421
420
  if (requestAcceptsTextHtml(request)) {
422
- const kvAssetsIndex = await this.getKvAssetsIndex();
423
- if (kvAssetsIndex == null) {
421
+ const assetEntryMap = await this.getAssetEntryMap();
422
+ if (assetEntryMap == null) {
424
423
  return null;
425
424
  }
426
425
  // These are raw asset paths, not relative to public path
427
426
  const { spaFile } = serverConfig;
428
427
  if (spaFile != null) {
429
- const asset = kvAssetsIndex[spaFile];
428
+ const asset = assetEntryMap[spaFile];
430
429
  if (asset != null) {
431
430
  return this.serveAsset(request, asset, {
432
431
  cache: 'never',
@@ -435,7 +434,7 @@ export class PublisherServer {
435
434
  }
436
435
  const { notFoundPageFile } = serverConfig;
437
436
  if (notFoundPageFile != null) {
438
- const asset = kvAssetsIndex[notFoundPageFile];
437
+ const asset = assetEntryMap[notFoundPageFile];
439
438
  if (asset != null) {
440
439
  return this.serveAsset(request, asset, {
441
440
  status: 404,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"if-modified-since.d.ts","sourceRoot":"","sources":["../../../../../src/server/publisher-server/serve-preconditions/if-modified-since.ts"],"names":[],"mappings":"AAOA,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAgBxE;AAED,wBAAgB,oBAAoB,CAAC,gBAAgB,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAW/F"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"if-none-match.d.ts","sourceRoot":"","sources":["../../../../../src/server/publisher-server/serve-preconditions/if-none-match.ts"],"names":[],"mappings":"AAOA,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,EAAE,CAO/D;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAmB7E"}
@@ -0,0 +1,8 @@
1
+ import { type StorageProvider, type StorageProviderBuilder } from './storage-provider.js';
2
+ export declare const buildStoreProvider: StorageProviderBuilder;
3
+ export declare class KvStoreProvider implements StorageProvider {
4
+ constructor(kvStoreName: string);
5
+ readonly kvStoreName: string;
6
+ getEntry(key: string): Promise<import("fastly:kv-store").KVStoreEntry | null>;
7
+ }
8
+ //# sourceMappingURL=kv-store-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kv-store-provider.d.ts","sourceRoot":"","sources":["../../../../src/server/storage/kv-store-provider.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC5B,MAAM,uBAAuB,CAAC;AAK/B,eAAO,MAAM,kBAAkB,EAAE,sBAMhC,CAAC;AAEF,qBAAa,eAAgB,YAAW,eAAe;gBACzC,WAAW,EAAE,MAAM;IAI/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAEvB,QAAQ,CAAC,GAAG,EAAE,MAAM;CAI3B"}
@@ -0,0 +1,24 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import { isKvStoreConfigRc, } from '../../models/config/static-publish-rc.js';
6
+ import { getKvStoreConfigFromRc } from '../../models/config/kv-store-config.js';
7
+ import { KVStore } from 'fastly:kv-store';
8
+ import { getKVStoreEntry } from '../util/kv-store.js';
9
+ export const buildStoreProvider = (config) => {
10
+ if (!isKvStoreConfigRc(config)) {
11
+ return null;
12
+ }
13
+ const kvStoreConfig = getKvStoreConfigFromRc(config);
14
+ return new KvStoreProvider(kvStoreConfig.kvStoreName);
15
+ };
16
+ export class KvStoreProvider {
17
+ constructor(kvStoreName) {
18
+ this.kvStoreName = kvStoreName;
19
+ }
20
+ async getEntry(key) {
21
+ const kvStore = new KVStore(this.kvStoreName);
22
+ return await getKVStoreEntry(kvStore, key);
23
+ }
24
+ }
@@ -0,0 +1,26 @@
1
+ import { S3Client } from '@aws-sdk/client-s3';
2
+ import { type StorageEntry, type StorageProvider, StorageProviderBuilder } from './storage-provider.js';
3
+ export type AwsCredentials = {
4
+ accessKeyId: string;
5
+ secretAccessKey: string;
6
+ };
7
+ export type AwsCredentialsBuilder = () => (AwsCredentials | Promise<AwsCredentials>);
8
+ export declare const buildStoreProvider: StorageProviderBuilder;
9
+ export declare function setSecretStoreForAwsCredentials(secretStoreName: string): void;
10
+ export declare function setSecretStoreKeyForAwsAccessKeyId(secretStoreKey: string): void;
11
+ export declare function setSecretStoreKeyForAwsSecretAccessKey(secretStoreKey: string): void;
12
+ export declare function buildAwsCredentialsFromSecretStore(): Promise<{
13
+ accessKeyId: string;
14
+ secretAccessKey: string;
15
+ }>;
16
+ export declare function setAwsCredentialsBuilder(awsCredentialsBuilder: AwsCredentialsBuilder): void;
17
+ export declare class S3StorageProvider implements StorageProvider {
18
+ constructor(s3Region: string, s3Bucket: string, s3Endpoint?: string);
19
+ private readonly s3Region;
20
+ private readonly s3Bucket;
21
+ private readonly s3Endpoint?;
22
+ private s3Client?;
23
+ getS3Client(): Promise<S3Client>;
24
+ getEntry(key: string): Promise<StorageEntry | null>;
25
+ }
26
+ //# sourceMappingURL=s3-storage-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/server/storage/s3-storage-provider.ts"],"names":[],"mappings":"AAOA,OAAO,EAIL,QAAQ,EAET,MAAM,oBAAoB,CAAC;AAS5B,OAAO,EAEL,KAAK,YAAY,EAEjB,KAAK,eAAe,EACpB,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,MAAM,cAAc,GAAG;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC;AAErF,eAAO,MAAM,kBAAkB,EAAE,sBAUhC,CAAC;AAMF,wBAAgB,+BAA+B,CAAC,eAAe,EAAE,MAAM,QAEtE;AAED,wBAAgB,kCAAkC,CAAC,cAAc,EAAE,MAAM,QAExE;AAED,wBAAgB,sCAAsC,CAAC,cAAc,EAAE,MAAM,QAE5E;AAED,wBAAsB,kCAAkC;;;GAuBvD;AAGD,wBAAgB,wBAAwB,CAAC,qBAAqB,EAAE,qBAAqB,QAEpF;AAED,qBAAa,iBAAkB,YAAW,eAAe;gBAErD,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM;IAOrB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAS;IAErC,OAAO,CAAC,QAAQ,CAAC,CAAW;IACtB,WAAW;IAqBX,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;CA4B1D"}
@@ -0,0 +1,110 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import { SecretStore } from 'fastly:secret-store';
6
+ import { FetchHttpHandler } from '@smithy/fetch-http-handler';
7
+ import { GetObjectCommand, S3Client, S3ServiceException } from '@aws-sdk/client-s3';
8
+ import { isS3StorageConfigRc, } from '../../models/config/static-publish-rc.js';
9
+ import { getS3StorageConfigFromRc, } from '../../models/config/s3-storage-config.js';
10
+ import { concatReadableStreams, StorageEntryImpl, } from './storage-provider.js';
11
+ export const buildStoreProvider = (config) => {
12
+ if (!isS3StorageConfigRc(config)) {
13
+ return null;
14
+ }
15
+ const s3StorageConfig = getS3StorageConfigFromRc(config);
16
+ return new S3StorageProvider(s3StorageConfig.region, s3StorageConfig.bucket, s3StorageConfig.endpoint);
17
+ };
18
+ let _secretStoreForAwsCredentials = 'AWS_CREDENTIALS';
19
+ let _secretStoreKeyForAwsAccessKeyId = 'AWS_ACCESS_KEY_ID';
20
+ let _secretStoreKeyForAwsSecretAccessKey = 'AWS_SECRET_ACCESS_KEY';
21
+ export function setSecretStoreForAwsCredentials(secretStoreName) {
22
+ _secretStoreForAwsCredentials = secretStoreName;
23
+ }
24
+ export function setSecretStoreKeyForAwsAccessKeyId(secretStoreKey) {
25
+ _secretStoreKeyForAwsAccessKeyId = secretStoreKey;
26
+ }
27
+ export function setSecretStoreKeyForAwsSecretAccessKey(secretStoreKey) {
28
+ _secretStoreKeyForAwsSecretAccessKey = secretStoreKey;
29
+ }
30
+ export async function buildAwsCredentialsFromSecretStore() {
31
+ let secretStore;
32
+ try {
33
+ secretStore = new SecretStore(_secretStoreForAwsCredentials);
34
+ }
35
+ catch {
36
+ throw new Error(`Could not open secret store for AWS credentials: ${_secretStoreForAwsCredentials}`);
37
+ }
38
+ const accessKeyIdEntry = await secretStore.get(_secretStoreKeyForAwsAccessKeyId);
39
+ if (accessKeyIdEntry == null) {
40
+ throw new Error(`Could not retrieve value '${_secretStoreKeyForAwsAccessKeyId}' in secret store '${_secretStoreForAwsCredentials}'`);
41
+ }
42
+ const accessKeyId = accessKeyIdEntry.plaintext();
43
+ const secretAccessKeyEntry = await secretStore.get(_secretStoreKeyForAwsSecretAccessKey);
44
+ if (secretAccessKeyEntry == null) {
45
+ throw new Error(`Could not retrieve value '${_secretStoreKeyForAwsSecretAccessKey}' in secret store '${_secretStoreForAwsCredentials}'`);
46
+ }
47
+ const secretAccessKey = secretAccessKeyEntry.plaintext();
48
+ return {
49
+ accessKeyId,
50
+ secretAccessKey,
51
+ };
52
+ }
53
+ let _awsCredentialsBuilder = buildAwsCredentialsFromSecretStore;
54
+ export function setAwsCredentialsBuilder(awsCredentialsBuilder) {
55
+ _awsCredentialsBuilder = awsCredentialsBuilder;
56
+ }
57
+ export class S3StorageProvider {
58
+ constructor(s3Region, s3Bucket, s3Endpoint) {
59
+ this.s3Region = s3Region;
60
+ this.s3Bucket = s3Bucket;
61
+ this.s3Endpoint = s3Endpoint;
62
+ }
63
+ async getS3Client() {
64
+ if (this.s3Client != null) {
65
+ return this.s3Client;
66
+ }
67
+ const awsCredentials = await _awsCredentialsBuilder();
68
+ this.s3Client = new S3Client({
69
+ region: this.s3Region,
70
+ endpoint: this.s3Endpoint,
71
+ forcePathStyle: this.s3Endpoint != null,
72
+ credentials: {
73
+ accessKeyId: awsCredentials.accessKeyId,
74
+ secretAccessKey: awsCredentials.secretAccessKey,
75
+ },
76
+ maxAttempts: 1,
77
+ requestHandler: new FetchHttpHandler({
78
+ requestInit() { return { backend: "aws" }; }
79
+ }),
80
+ });
81
+ return this.s3Client;
82
+ }
83
+ async getEntry(key) {
84
+ const input = {
85
+ Bucket: this.s3Bucket, // required
86
+ Key: key, // required
87
+ };
88
+ const command = new GetObjectCommand(input);
89
+ let response;
90
+ try {
91
+ const s3Client = await this.getS3Client();
92
+ response = await s3Client.send(command);
93
+ }
94
+ catch (err) {
95
+ if (err instanceof S3ServiceException && (err.name === "NotFound" || err.name === "NoSuchKey")) {
96
+ console.log("Object does not exist");
97
+ return null;
98
+ }
99
+ else {
100
+ throw err; // some other problem (auth, network, etc.)
101
+ }
102
+ }
103
+ if (response.Body == null) {
104
+ return null;
105
+ }
106
+ const body = concatReadableStreams([response.Body.transformToWebStream()]);
107
+ const metadataText = JSON.stringify(response.Metadata ?? {});
108
+ return new StorageEntryImpl(body, metadataText);
109
+ }
110
+ }
@@ -0,0 +1,48 @@
1
+ import { type StaticPublishRc } from '../../models/config/static-publish-rc.js';
2
+ export interface StorageProvider {
3
+ getEntry(key: string): Promise<StorageEntry | null>;
4
+ }
5
+ export type StorageProviderBuilder = (config: StaticPublishRc) => (StorageProvider | null);
6
+ export interface StorageEntry {
7
+ /**
8
+ * A ReadableStream with the contents of the entry.
9
+ */
10
+ get body(): ReadableStream;
11
+ /**
12
+ * A boolean value that indicates whether the body has been read from already.
13
+ */
14
+ get bodyUsed(): boolean;
15
+ /**
16
+ * Reads the body and returns it as a promise that resolves with a string.
17
+ * The response is always decoded using UTF-8.
18
+ */
19
+ text(): Promise<string>;
20
+ /**
21
+ * Reads the body and returns it as a promise that resolves with the result of parsing the body text as JSON.
22
+ */
23
+ json(): Promise<object>;
24
+ /**
25
+ * Reads the body and returns it as a promise that resolves with an ArrayBuffer.
26
+ */
27
+ arrayBuffer(): Promise<ArrayBuffer>;
28
+ /**
29
+ * Metadata associated with this entry
30
+ */
31
+ metadata(): ArrayBuffer | null;
32
+ /**
33
+ * Metadata string associated with this entry
34
+ * Throws an error for invalid UTF-8
35
+ */
36
+ metadataText(): string | null;
37
+ }
38
+ export declare class StorageEntryImpl extends Response implements StorageEntry {
39
+ constructor(body: BodyInit, metadataText: string);
40
+ private readonly metadataTextValue;
41
+ get body(): ReadableStream<Uint8Array>;
42
+ metadata(): ArrayBuffer | null;
43
+ metadataText(): string | null;
44
+ }
45
+ export declare function concatReadableStreams(streams: ReadableStream<Uint8Array>[]): ReadableStream<Uint8Array>;
46
+ export declare function registerStorageProviderBuilder(builder: StorageProviderBuilder): void;
47
+ export declare function loadStorageProviderFromStaticPublishRc(config: StaticPublishRc): StorageProvider;
48
+ //# sourceMappingURL=storage-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/server/storage/storage-provider.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,eAAe,EACrB,MAAM,0CAA0C,CAAC;AAElD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;CACrD;AAED,MAAM,MAAM,sBAAsB,GAAG,CAAC,MAAM,EAAE,eAAe,KAAK,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;AAE3F,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,IAAI,IAAI,cAAc,CAAC;IAE3B;;OAEG;IACH,IAAI,QAAQ,IAAI,OAAO,CAAC;IAExB;;;OAGG;IACH,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAExB;;OAEG;IACH,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAExB;;OAEG;IACH,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IAEpC;;OAEG;IACH,QAAQ,IAAI,WAAW,GAAG,IAAI,CAAC;IAE/B;;;OAGG;IACH,YAAY,IAAI,MAAM,GAAG,IAAI,CAAC;CAC/B;AAKD,qBAAa,gBAAiB,SAAQ,QAAS,YAAW,YAAY;gBACxD,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM;IAKhD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,IAAI,IAAI,IAAI,cAAc,CAAC,UAAU,CAAC,CAErC;IAED,QAAQ,IAAI,WAAW,GAAG,IAAI;IAG9B,YAAY,IAAI,MAAM,GAAG,IAAI;CAG9B;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,cAAc,CAAC,UAAU,CAAC,EAAE,GAAG,cAAc,CAAC,UAAU,CAAC,CAuCvG;AAGD,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,sBAAsB,QAE7E;AAED,wBAAgB,sCAAsC,CAAC,MAAM,EAAE,eAAe,mBAS7E"}