@iyio/aws-s3 0.0.29 → 0.1.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.
@@ -0,0 +1,4 @@
1
+ {
2
+ "sideEffects": false,
3
+ "type": "module"
4
+ }
@@ -0,0 +1,3 @@
1
+ export * from './lib/S3Client';
2
+ export * from './lib/S3StoreAdapter';
3
+ export * from './lib/_types.aws-s3';
@@ -0,0 +1,4 @@
1
+ export * from './lib/S3Client';
2
+ export * from './lib/S3StoreAdapter';
3
+ export * from './lib/_types.aws-s3';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/aws-s3/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { S3Client as AwsS3Client, S3ClientConfig } from "@aws-sdk/client-s3";
2
+ import { CancelToken, IWithStoreAdapter, Scope } from "@iyio/common";
3
+ import { S3StoreAdapter, S3StoreAdapterOptions } from "./S3StoreAdapter";
4
+ export declare class S3Client implements IWithStoreAdapter {
5
+ static fromScope(scope: Scope, storeAdapterOptions?: S3StoreAdapterOptions): S3Client;
6
+ readonly clientConfig: Readonly<S3ClientConfig>;
7
+ constructor(clientConfig: S3ClientConfig, storeAdapterOptions?: S3StoreAdapterOptions);
8
+ private client;
9
+ getClient(): AwsS3Client;
10
+ private readonly storeAdapterOptions;
11
+ private storeAdapter;
12
+ getStoreAdapter(): S3StoreAdapter;
13
+ getAsync<T>(bucket: string, key: string, cancel?: CancelToken): Promise<T | undefined>;
14
+ putAsync<T>(bucket: string, key: string, value: T): Promise<void>;
15
+ deleteAsync(bucket: string, key: string): Promise<boolean | undefined>;
16
+ }
@@ -0,0 +1,105 @@
1
+ import { __awaiter } from "tslib";
2
+ import { DeleteObjectCommand, GetObjectCommand, PutObjectCommand, S3Client as AwsS3Client } from "@aws-sdk/client-s3";
3
+ import { AwsAuthProviders, awsRegionParam } from '@iyio/aws';
4
+ import { BinaryStoreValue } from "@iyio/common";
5
+ import { S3StoreAdapter } from "./S3StoreAdapter";
6
+ export class S3Client {
7
+ constructor(clientConfig, storeAdapterOptions = {}) {
8
+ this.client = null;
9
+ this.storeAdapter = null;
10
+ this.storeAdapterOptions = storeAdapterOptions;
11
+ this.clientConfig = clientConfig;
12
+ }
13
+ static fromScope(scope, storeAdapterOptions) {
14
+ var _a;
15
+ return new S3Client({
16
+ region: awsRegionParam(scope),
17
+ credentials: (_a = scope.get(AwsAuthProviders)) === null || _a === void 0 ? void 0 : _a.getAuthProvider()
18
+ }, storeAdapterOptions);
19
+ }
20
+ getClient() {
21
+ if (this.client) {
22
+ return this.client;
23
+ }
24
+ this.client = new AwsS3Client(this.clientConfig);
25
+ return this.client;
26
+ }
27
+ getStoreAdapter() {
28
+ if (this.storeAdapter) {
29
+ return this.storeAdapter;
30
+ }
31
+ this.storeAdapter = new S3StoreAdapter(this, this.storeAdapterOptions);
32
+ return this.storeAdapter;
33
+ }
34
+ getAsync(bucket, key, cancel) {
35
+ var _a, _b, _c, _d;
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ let r;
38
+ try {
39
+ r = yield this.getClient().send(new GetObjectCommand({
40
+ Key: key,
41
+ Bucket: bucket,
42
+ }));
43
+ }
44
+ catch (ex) {
45
+ if ((ex === null || ex === void 0 ? void 0 : ex.Code) === 'NoSuchKey') {
46
+ return undefined;
47
+ }
48
+ throw ex;
49
+ }
50
+ if (cancel === null || cancel === void 0 ? void 0 : cancel.isCanceled) {
51
+ return;
52
+ }
53
+ const contentType = (_b = (_a = r.ContentType) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) !== null && _b !== void 0 ? _b : '';
54
+ if (contentType === 'application/json' || contentType.startsWith('text/')) {
55
+ if (contentType.endsWith('/json')) {
56
+ if (r.Body) {
57
+ return JSON.parse(yield r.Body.transformToString());
58
+ }
59
+ else {
60
+ return undefined;
61
+ }
62
+ }
63
+ else {
64
+ return (_c = r.Body) === null || _c === void 0 ? void 0 : _c.toString();
65
+ }
66
+ }
67
+ else {
68
+ if (r.Body) {
69
+ return new BinaryStoreValue((_d = r.ContentType) !== null && _d !== void 0 ? _d : 'application/octet-stream', yield r.Body.transformToByteArray());
70
+ }
71
+ else {
72
+ return undefined;
73
+ }
74
+ }
75
+ });
76
+ }
77
+ putAsync(bucket, key, value) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ yield this.getClient().send((value instanceof BinaryStoreValue) ?
80
+ new PutObjectCommand({
81
+ Key: key,
82
+ Bucket: bucket,
83
+ Body: value.content,
84
+ ContentType: value.contentType,
85
+ })
86
+ :
87
+ new PutObjectCommand({
88
+ Key: key,
89
+ Bucket: bucket,
90
+ Body: JSON.stringify(value),
91
+ ContentType: 'application/json',
92
+ }));
93
+ });
94
+ }
95
+ deleteAsync(bucket, key) {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ yield this.getClient().send(new DeleteObjectCommand({
98
+ Key: key,
99
+ Bucket: bucket,
100
+ }));
101
+ return true;
102
+ });
103
+ }
104
+ }
105
+ //# sourceMappingURL=S3Client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"S3Client.js","sourceRoot":"","sources":["../../../../../../packages/aws-s3/src/lib/S3Client.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAA0B,gBAAgB,EAAE,QAAQ,IAAI,WAAW,EAAkB,MAAM,oBAAoB,CAAC;AAC9J,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAyC,MAAM,cAAc,CAAC;AACvF,OAAO,EAAE,cAAc,EAAyB,MAAM,kBAAkB,CAAC;AAIzE,MAAM,OAAO,QAAQ;IAajB,YACI,YAA2B,EAC3B,sBAA0C,EAAE;QAOxC,WAAM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,GAAG,EAAC,GAAG;wBACP,MAAM,EAAC,MAAM;wBACb,IAAI,EAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;wBAC1B,WAAW,EAAC,kBAAkB;qBACjC,CAAC,CACL,CAAA;QACL,CAAC;KAAA;IAEY,WAAW,CAAC,MAAa,EAAC,GAAU;;YAE7C,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,IAAI,mBAAmB,CAAC;gBAChD,GAAG,EAAC,GAAG;gBACP,MAAM,EAAC,MAAM;aAChB,CAAC,CAAC,CAAC;YAEJ,OAAO,IAAI,CAAC;QAChB,CAAC;KAAA;CACJ"}
@@ -0,0 +1,17 @@
1
+ import { BaseStore, CancelToken, StoreKeyScope } from "@iyio/common";
2
+ import { S3Client } from "./S3Client";
3
+ export interface S3StoreAdapterOptions extends StoreKeyScope {
4
+ /**
5
+ * The default bucket to use
6
+ */
7
+ bucket?: string;
8
+ }
9
+ export declare class S3StoreAdapter<T = any> extends BaseStore<T> {
10
+ private readonly client;
11
+ private readonly options;
12
+ constructor(client: S3Client, options: S3StoreAdapterOptions);
13
+ private parseKey;
14
+ getAsync(key: string, cancel?: CancelToken): Promise<T | undefined>;
15
+ putAsync(key: string, value: T): Promise<void>;
16
+ deleteAsync(key: string): Promise<boolean | undefined>;
17
+ }
@@ -0,0 +1,43 @@
1
+ import { __awaiter } from "tslib";
2
+ import { BaseStore } from "@iyio/common";
3
+ export class S3StoreAdapter extends BaseStore {
4
+ constructor(client, options) {
5
+ super(options);
6
+ this.client = client;
7
+ this.options = Object.assign({}, options);
8
+ }
9
+ parseKey(key) {
10
+ if (this.options.bucket) {
11
+ return {
12
+ mappedBucket: this.options.bucket,
13
+ mappedKey: key
14
+ };
15
+ }
16
+ else {
17
+ const [bucket, objKey] = key.split('/', 2);
18
+ return {
19
+ mappedBucket: bucket,
20
+ mappedKey: objKey || 'NO_KEY'
21
+ };
22
+ }
23
+ }
24
+ getAsync(key, cancel) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const { mappedBucket, mappedKey } = this.parseKey(key);
27
+ return yield this.client.getAsync(mappedBucket, mappedKey, cancel);
28
+ });
29
+ }
30
+ putAsync(key, value) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const { mappedBucket, mappedKey } = this.parseKey(key);
33
+ yield this.client.putAsync(mappedBucket, mappedKey, value);
34
+ });
35
+ }
36
+ deleteAsync(key) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ const { mappedBucket, mappedKey } = this.parseKey(key);
39
+ return yield this.client.deleteAsync(mappedBucket, mappedKey);
40
+ });
41
+ }
42
+ }
43
+ //# sourceMappingURL=S3StoreAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"S3StoreAdapter.js","sourceRoot":"","sources":["../../../../../../packages/aws-s3/src/lib/S3StoreAdapter.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAA8B,MAAM,cAAc,CAAC;AAarE,MAAM,OAAO,cAAsB,SAAQ,SAAY;IAOnD,YAAmB,MAAe,EAAC,OAA6B;QAE5D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,MAAM,GAAC,MAAM,CAAC;QACnB,IAAI,CAAC,OAAO,qBAAK,OAAO,CAAC,CAAC;IAC9B,CAAC;IAEO,QAAQ,CAAC,GAAU;QACvB,IAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAC;YACnB,OAAO;gBACH,YAAY,EAAC,IAAI,CAAC,OAAO,CAAC,MAAM;gBAChC,SAAS,EAAC,GAAG;aAChB,CAAA;SACJ;aAAI;YACD,MAAM,CAAC,MAAM,EAAC,MAAM,CAAC,GAAC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAC,CAAC,CAAC,CAAA;YACtC,OAAO;gBACH,YAAY,EAAC,MAAM;gBACnB,SAAS,EAAC,MAAM,IAAE,QAAQ;aAC7B,CAAA;SACJ;IACL,CAAC;IAEY,QAAQ,CAAC,GAAU,EAAC,MAAmB;;YAEhD,MAAM,EAAC,YAAY,EAAC,SAAS,EAAC,GAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YAClD,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,EAAC,SAAS,EAAC,MAAM,CAAC,CAAC;QACrE,CAAC;KAAA;IAGY,QAAQ,CAAC,GAAU,EAAC,KAAO;;YAEpC,MAAM,EAAC,YAAY,EAAC,SAAS,EAAC,GAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YAClD,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,EAAC,SAAS,EAAC,KAAK,CAAC,CAAC;QAC7D,CAAC;KAAA;IAEY,WAAW,CAAC,GAAU;;YAE/B,MAAM,EAAC,YAAY,EAAC,SAAS,EAAC,GAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YAClD,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,YAAY,EAAC,SAAS,CAAC,CAAC;QACjE,CAAC;KAAA;CACJ"}
@@ -0,0 +1,2 @@
1
+ import { S3Client } from "./S3Client";
2
+ export declare const s3Client: import("@iyio/common").ClientTypeDef<S3Client>;
@@ -0,0 +1,4 @@
1
+ import { defineClient } from "@iyio/common";
2
+ import { S3Client } from "./S3Client";
3
+ export const s3Client = defineClient('s3Client', scope => S3Client.fromScope(scope));
4
+ //# sourceMappingURL=_types.aws-s3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_types.aws-s3.js","sourceRoot":"","sources":["../../../../../../packages/aws-s3/src/lib/_types.aws-s3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,CAAC,MAAM,QAAQ,GAAC,YAAY,CAAW,UAAU,EAAC,KAAK,CAAA,EAAE,CAAA,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,19 +1,22 @@
1
1
  {
2
2
  "name": "@iyio/aws-s3",
3
- "version": "0.0.29",
3
+ "version": "0.1.0",
4
4
  "type": "commonjs",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
7
7
  "dependencies": {},
8
8
  "peerDependencies": {
9
- "@iyio/common": "0.0.31",
9
+ "@iyio/common": "0.1.0",
10
10
  "rxjs": "^7.5.7",
11
+ "date-fns": "^2.29.3",
11
12
  "uuid": "^9.0.0",
12
- "@iyio/aws-credential-providers": "0.0.29",
13
- "@iyio/aws": "0.0.29",
13
+ "@iyio/aws-credential-providers": "0.1.0",
14
+ "@iyio/aws": "0.1.0",
14
15
  "@aws-sdk/credential-providers": "^3.199.0",
15
16
  "amazon-cognito-identity-js": "^5.2.12",
16
17
  "@aws-sdk/client-s3": "^3.200.0",
17
18
  "tslib": "^2.3.0"
18
- }
19
+ },
20
+ "sideEffects": false,
21
+ "module": "./esm/src/index.js"
19
22
  }
@@ -0,0 +1,4 @@
1
+ {
2
+ "type": "commonjs",
3
+ "sideEffects": false
4
+ }