@atproto/aws 0.1.2 → 0.1.4

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.
@@ -0,0 +1,3 @@
1
+ export interface ImageInvalidator {
2
+ invalidate(subject: string, paths: string[]): Promise<void>;
3
+ }
package/dist/util.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { ImageInvalidator } from './types';
2
+ export declare class MultiImageInvalidator implements ImageInvalidator {
3
+ invalidators: ImageInvalidator[];
4
+ constructor(invalidators: ImageInvalidator[]);
5
+ invalidate(subject: string, paths: string[]): Promise<void>;
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/aws",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "license": "MIT",
5
5
  "description": "Shared AWS cloud API helpers for atproto services",
6
6
  "keywords": [
@@ -23,8 +23,9 @@
23
23
  "key-encoder": "^2.0.3",
24
24
  "multiformats": "^9.9.0",
25
25
  "uint8arrays": "3.0.0",
26
- "@atproto/crypto": "^0.2.2",
27
- "@atproto/repo": "^0.3.2"
26
+ "@atproto/common": "^0.3.3",
27
+ "@atproto/crypto": "^0.2.3",
28
+ "@atproto/repo": "^0.3.4"
28
29
  },
29
30
  "scripts": {
30
31
  "build": "node ./build.js",
package/src/bunny.ts ADDED
@@ -0,0 +1,36 @@
1
+ import { handleAllSettledErrors } from '@atproto/common'
2
+ import { ImageInvalidator } from './types'
3
+
4
+ export type BunnyConfig = {
5
+ accessKey: string
6
+ urlPrefix: string
7
+ }
8
+
9
+ const API_PURGE_URL = 'https://api.bunny.net/purge'
10
+
11
+ export class BunnyInvalidator implements ImageInvalidator {
12
+ constructor(public cfg: BunnyConfig) {}
13
+ async invalidate(_subject: string, paths: string[]) {
14
+ const results = await Promise.allSettled(
15
+ paths.map(async (path) =>
16
+ purgeUrl({
17
+ url: this.cfg.urlPrefix + path,
18
+ accessKey: this.cfg.accessKey,
19
+ }),
20
+ ),
21
+ )
22
+ handleAllSettledErrors(results)
23
+ }
24
+ }
25
+
26
+ export default BunnyInvalidator
27
+
28
+ async function purgeUrl(opts: { accessKey: string; url: string }) {
29
+ const search = new URLSearchParams()
30
+ search.set('async', 'true')
31
+ search.set('url', opts.url)
32
+ await fetch(API_PURGE_URL + '?' + search.toString(), {
33
+ method: 'post',
34
+ headers: { AccessKey: opts.accessKey },
35
+ })
36
+ }
package/src/cloudfront.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as aws from '@aws-sdk/client-cloudfront'
2
+ import { ImageInvalidator } from './types'
2
3
 
3
4
  export type CloudfrontConfig = {
4
5
  distributionId: string
@@ -33,9 +34,3 @@ export class CloudfrontInvalidator implements ImageInvalidator {
33
34
  }
34
35
 
35
36
  export default CloudfrontInvalidator
36
-
37
- // @NOTE keep in sync with same interface in pds/src/image/invalidator.ts
38
- // this is separate to avoid the dependency on @atproto/pds.
39
- interface ImageInvalidator {
40
- invalidate(subject: string, paths: string[]): Promise<void>
41
- }
package/src/index.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  export * from './kms'
2
2
  export * from './s3'
3
3
  export * from './cloudfront'
4
+ export * from './bunny'
5
+ export * from './util'
6
+ export * from './types'
package/src/types.ts ADDED
@@ -0,0 +1,5 @@
1
+ // @NOTE keep in sync with same interface in bsky/src/image/invalidator.ts
2
+ // this is separate to avoid the dependency on @atproto/bsky.
3
+ export interface ImageInvalidator {
4
+ invalidate(subject: string, paths: string[]): Promise<void>
5
+ }
package/src/util.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { handleAllSettledErrors } from '@atproto/common'
2
+ import { ImageInvalidator } from './types'
3
+
4
+ export class MultiImageInvalidator implements ImageInvalidator {
5
+ constructor(public invalidators: ImageInvalidator[]) {}
6
+ async invalidate(subject: string, paths: string[]) {
7
+ const results = await Promise.allSettled(
8
+ this.invalidators.map((invalidator) =>
9
+ invalidator.invalidate(subject, paths),
10
+ ),
11
+ )
12
+ handleAllSettledErrors(results)
13
+ }
14
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2022-2023 Bluesky PBC
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.