@atproto/aws 0.1.2 → 0.1.3
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.
- package/CHANGELOG.md +8 -0
- package/dist/bunny.d.ts +11 -0
- package/dist/cloudfront.d.ts +1 -3
- package/dist/index.d.ts +3 -0
- package/dist/index.js +135 -62
- package/dist/index.js.map +3 -3
- package/dist/types.d.ts +3 -0
- package/dist/util.d.ts +6 -0
- package/package.json +3 -2
- package/src/bunny.ts +36 -0
- package/src/cloudfront.ts +1 -6
- package/src/index.ts +3 -0
- package/src/types.ts +5 -0
- package/src/util.ts +14 -0
package/dist/types.d.ts
ADDED
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.
|
|
3
|
+
"version": "0.1.3",
|
|
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/common": "^0.3.2",
|
|
26
27
|
"@atproto/crypto": "^0.2.2",
|
|
27
|
-
"@atproto/repo": "^0.3.
|
|
28
|
+
"@atproto/repo": "^0.3.3"
|
|
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
package/src/types.ts
ADDED
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
|
+
}
|