@vyriy/services 0.2.1 → 0.3.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.
- package/README.md +13 -0
- package/cloudfront/actions.js +2 -1
- package/cloudfront/client.d.ts +2 -2
- package/cloudfront/client.js +1 -1
- package/dynamodb/actions.js +9 -1
- package/dynamodb/client.d.ts +2 -2
- package/dynamodb/client.js +9 -7
- package/ecs/actions.js +2 -1
- package/ecs/client.d.ts +2 -2
- package/ecs/client.js +4 -2
- package/lambda/actions.js +2 -1
- package/lambda/client.d.ts +2 -2
- package/lambda/client.js +4 -2
- package/package.json +13 -13
- package/s3/actions.js +4 -1
- package/s3/client.d.ts +2 -2
- package/s3/client.js +10 -8
- package/sns/actions.js +2 -1
- package/sns/client.d.ts +2 -2
- package/sns/client.js +1 -1
- package/ssm/actions.js +3 -1
- package/ssm/client.d.ts +2 -2
- package/ssm/client.js +1 -1
package/README.md
CHANGED
|
@@ -46,6 +46,9 @@ Some clients are prepared for local AWS-compatible development:
|
|
|
46
46
|
- `cloudfront`, `lambda`, `sns`, and `ssm` currently use their normal AWS SDK
|
|
47
47
|
client configuration.
|
|
48
48
|
|
|
49
|
+
Service clients are created lazily inside each helper call. Importing
|
|
50
|
+
`@vyriy/services` or a service subpath does not construct AWS SDK clients.
|
|
51
|
+
|
|
49
52
|
LocalStack defaults come from `@vyriy/env`:
|
|
50
53
|
|
|
51
54
|
- `LOCALSTACK_HOST`: defaults to `localhost`
|
|
@@ -73,6 +76,16 @@ const apiUrl = await getParameter('/app/api-url');
|
|
|
73
76
|
await upload('assets-bucket', 'config/api-url.txt', apiUrl, 'text/plain');
|
|
74
77
|
```
|
|
75
78
|
|
|
79
|
+
Client factories are also exported from service subpaths when direct AWS SDK
|
|
80
|
+
access is needed. The service path gives the generic `createClient` name its
|
|
81
|
+
context:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { createClient } from '@vyriy/services/s3';
|
|
85
|
+
|
|
86
|
+
const client = createClient({ region: 'eu-central-1' });
|
|
87
|
+
```
|
|
88
|
+
|
|
76
89
|
## Examples
|
|
77
90
|
|
|
78
91
|
Invalidate CloudFront after publishing static files:
|
package/cloudfront/actions.js
CHANGED
|
@@ -2,9 +2,10 @@ import { CreateInvalidationCommand, GetInvalidationCommand } from '@aws-sdk/clie
|
|
|
2
2
|
import { createLogger } from '@vyriy/logger';
|
|
3
3
|
import { pause } from '@vyriy/pause';
|
|
4
4
|
import { toError } from '@vyriy/error';
|
|
5
|
-
import {
|
|
5
|
+
import { createClient } from './client.js';
|
|
6
6
|
export const invalidate = async (distribution, paths, shouldWait = false) => {
|
|
7
7
|
try {
|
|
8
|
+
const client = createClient();
|
|
8
9
|
const logger = createLogger();
|
|
9
10
|
logger.info('Distribution:', distribution);
|
|
10
11
|
logger.info('Paths:', paths);
|
package/cloudfront/client.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CloudFrontClient } from '@aws-sdk/client-cloudfront';
|
|
2
|
-
export declare const
|
|
1
|
+
import { CloudFrontClient, type CloudFrontClientConfig } from '@aws-sdk/client-cloudfront';
|
|
2
|
+
export declare const createClient: (options?: CloudFrontClientConfig) => CloudFrontClient;
|
package/cloudfront/client.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { CloudFrontClient } from '@aws-sdk/client-cloudfront';
|
|
2
|
-
export const
|
|
2
|
+
export const createClient = (options = {}) => new CloudFrontClient(options);
|
package/dynamodb/actions.js
CHANGED
|
@@ -2,9 +2,10 @@ import { CreateTableCommand } from '@aws-sdk/client-dynamodb';
|
|
|
2
2
|
import { DeleteCommand, GetCommand, PutCommand, QueryCommand, ScanCommand, UpdateCommand } from '@aws-sdk/lib-dynamodb';
|
|
3
3
|
import { createLogger } from '@vyriy/logger';
|
|
4
4
|
import { toError } from '@vyriy/error';
|
|
5
|
-
import {
|
|
5
|
+
import { createClient } from './client.js';
|
|
6
6
|
export const createTable = async (params) => {
|
|
7
7
|
try {
|
|
8
|
+
const client = createClient();
|
|
8
9
|
createLogger().log('CreateTableCommand:', params);
|
|
9
10
|
await client.send(new CreateTableCommand(params));
|
|
10
11
|
}
|
|
@@ -14,6 +15,7 @@ export const createTable = async (params) => {
|
|
|
14
15
|
};
|
|
15
16
|
export const createItem = async (TableName, Item, options = {}) => {
|
|
16
17
|
try {
|
|
18
|
+
const client = createClient();
|
|
17
19
|
createLogger().log('PutCommand:', { TableName, Item, ...options });
|
|
18
20
|
await client.send(new PutCommand({ TableName, Item, ...options }));
|
|
19
21
|
}
|
|
@@ -23,6 +25,7 @@ export const createItem = async (TableName, Item, options = {}) => {
|
|
|
23
25
|
};
|
|
24
26
|
export const updateItem = async (TableName, Key, UpdateExpression, ExpressionAttributeValues, options = {}) => {
|
|
25
27
|
try {
|
|
28
|
+
const client = createClient();
|
|
26
29
|
const logger = createLogger();
|
|
27
30
|
const params = {
|
|
28
31
|
TableName,
|
|
@@ -40,6 +43,7 @@ export const updateItem = async (TableName, Key, UpdateExpression, ExpressionAtt
|
|
|
40
43
|
};
|
|
41
44
|
export const getItem = async (TableName, Key, options = {}) => {
|
|
42
45
|
try {
|
|
46
|
+
const client = createClient();
|
|
43
47
|
createLogger().log('GetCommand:', { TableName, Key, ...options });
|
|
44
48
|
return await client.send(new GetCommand({ TableName, Key, ...options })).then(({ Item }) => Item);
|
|
45
49
|
}
|
|
@@ -49,6 +53,7 @@ export const getItem = async (TableName, Key, options = {}) => {
|
|
|
49
53
|
};
|
|
50
54
|
export const deleteItem = async (TableName, Key, options = {}) => {
|
|
51
55
|
try {
|
|
56
|
+
const client = createClient();
|
|
52
57
|
createLogger().log('DeleteCommand:', { TableName, Key, ...options });
|
|
53
58
|
await client.send(new DeleteCommand({ TableName, Key, ...options }));
|
|
54
59
|
}
|
|
@@ -58,6 +63,7 @@ export const deleteItem = async (TableName, Key, options = {}) => {
|
|
|
58
63
|
};
|
|
59
64
|
export const getItems = async (TableName, keys, options = {}) => {
|
|
60
65
|
try {
|
|
66
|
+
const client = createClient();
|
|
61
67
|
const logger = createLogger();
|
|
62
68
|
const expressionList = [];
|
|
63
69
|
const ExpressionAttributeNames = {};
|
|
@@ -93,6 +99,7 @@ export const getItems = async (TableName, keys, options = {}) => {
|
|
|
93
99
|
};
|
|
94
100
|
export const getAllItems = async (TableName, options = {}) => {
|
|
95
101
|
try {
|
|
102
|
+
const client = createClient();
|
|
96
103
|
const logger = createLogger();
|
|
97
104
|
const params = { TableName, ...options };
|
|
98
105
|
const items = [];
|
|
@@ -113,6 +120,7 @@ export const getAllItems = async (TableName, options = {}) => {
|
|
|
113
120
|
};
|
|
114
121
|
export const getAllItemsWithHandler = async (TableName, handler, options = {}) => {
|
|
115
122
|
try {
|
|
123
|
+
const client = createClient();
|
|
116
124
|
const logger = createLogger();
|
|
117
125
|
const params = { TableName, ...options };
|
|
118
126
|
const scanUntilDone = async (ExclusiveStartKey) => {
|
package/dynamodb/client.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
2
|
-
export declare const
|
|
1
|
+
import { DynamoDBClient, type DynamoDBClientConfig } from '@aws-sdk/client-dynamodb';
|
|
2
|
+
export declare const createClient: (options?: DynamoDBClientConfig) => DynamoDBClient;
|
package/dynamodb/client.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
2
2
|
import { getLocalstackHost, getLocalstackPort, getRegion, isLocal } from '@vyriy/env';
|
|
3
|
-
const options =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
export const createClient = (options = {}) => {
|
|
4
|
+
const defaultOptions = isLocal()
|
|
5
|
+
? {
|
|
6
|
+
region: getRegion(),
|
|
7
|
+
endpoint: `http://${getLocalstackHost()}:${getLocalstackPort()}`,
|
|
8
|
+
}
|
|
9
|
+
: {};
|
|
10
|
+
return new DynamoDBClient({ ...defaultOptions, ...options });
|
|
11
|
+
};
|
package/ecs/actions.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RunTaskCommand } from '@aws-sdk/client-ecs';
|
|
2
2
|
import { getEcsClusterName, getEcsTaskDefinition, getVpcSecurityGroup, getVpcSubnets } from '@vyriy/env';
|
|
3
3
|
import { createLogger } from '@vyriy/logger';
|
|
4
|
-
import {
|
|
4
|
+
import { createClient } from './client.js';
|
|
5
5
|
export const runTask = async (task, environment = [], taskDefinition = getEcsTaskDefinition()) => {
|
|
6
6
|
const cluster = getEcsClusterName();
|
|
7
7
|
const subnets = getVpcSubnets();
|
|
@@ -46,5 +46,6 @@ export const runTask = async (task, environment = [], taskDefinition = getEcsTas
|
|
|
46
46
|
},
|
|
47
47
|
};
|
|
48
48
|
createLogger().info('Params:', params);
|
|
49
|
+
const client = createClient();
|
|
49
50
|
await client.send(new RunTaskCommand(params));
|
|
50
51
|
};
|
package/ecs/client.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ECSClient } from '@aws-sdk/client-ecs';
|
|
2
|
-
export declare const
|
|
1
|
+
import { ECSClient, type ECSClientConfig } from '@aws-sdk/client-ecs';
|
|
2
|
+
export declare const createClient: (options?: ECSClientConfig) => ECSClient;
|
package/ecs/client.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ECSClient } from '@aws-sdk/client-ecs';
|
|
2
2
|
import { getRegion, isLocal } from '@vyriy/env';
|
|
3
|
-
const
|
|
4
|
-
|
|
3
|
+
export const createClient = (options = {}) => {
|
|
4
|
+
const defaultOptions = isLocal() ? { region: getRegion() } : {};
|
|
5
|
+
return new ECSClient({ ...defaultOptions, ...options });
|
|
6
|
+
};
|
package/lambda/actions.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { InvokeCommand } from '@aws-sdk/client-lambda';
|
|
2
2
|
import { createLogger } from '@vyriy/logger';
|
|
3
|
-
import {
|
|
3
|
+
import { createClient } from './client.js';
|
|
4
4
|
export const invoke = async (functionName, payload, options = {}) => {
|
|
5
|
+
const client = createClient();
|
|
5
6
|
const logger = createLogger();
|
|
6
7
|
logger.info('functionName:', functionName);
|
|
7
8
|
logger.info('payload:', payload);
|
package/lambda/client.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { LambdaClient } from '@aws-sdk/client-lambda';
|
|
2
|
-
export declare const
|
|
1
|
+
import { LambdaClient, type LambdaClientConfig } from '@aws-sdk/client-lambda';
|
|
2
|
+
export declare const createClient: (options?: LambdaClientConfig) => LambdaClient;
|
package/lambda/client.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { LambdaClient } from '@aws-sdk/client-lambda';
|
|
2
2
|
import { getRegion } from '@vyriy/env';
|
|
3
|
-
const options = {
|
|
4
|
-
|
|
3
|
+
export const createClient = (options = {}) => {
|
|
4
|
+
const defaultOptions = { region: getRegion() };
|
|
5
|
+
return new LambdaClient({ ...defaultOptions, ...options });
|
|
6
|
+
};
|
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vyriy/services",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Shared services package for Vyriy projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@aws-sdk/client-cloudfront": "^3.
|
|
9
|
-
"@aws-sdk/client-dynamodb": "^3.
|
|
10
|
-
"@aws-sdk/client-ecs": "^3.
|
|
11
|
-
"@aws-sdk/client-lambda": "^3.
|
|
12
|
-
"@aws-sdk/client-s3": "^3.
|
|
13
|
-
"@aws-sdk/client-sns": "^3.
|
|
14
|
-
"@aws-sdk/client-ssm": "^3.
|
|
15
|
-
"@aws-sdk/lib-dynamodb": "^3.
|
|
8
|
+
"@aws-sdk/client-cloudfront": "^3.1046.0",
|
|
9
|
+
"@aws-sdk/client-dynamodb": "^3.1046.0",
|
|
10
|
+
"@aws-sdk/client-ecs": "^3.1046.0",
|
|
11
|
+
"@aws-sdk/client-lambda": "^3.1046.0",
|
|
12
|
+
"@aws-sdk/client-s3": "^3.1046.0",
|
|
13
|
+
"@aws-sdk/client-sns": "^3.1046.0",
|
|
14
|
+
"@aws-sdk/client-ssm": "^3.1046.0",
|
|
15
|
+
"@aws-sdk/lib-dynamodb": "^3.1046.0",
|
|
16
16
|
"@aws-sdk/util-dynamodb": "^3.996.2",
|
|
17
|
-
"@vyriy/env": "0.
|
|
18
|
-
"@vyriy/error": "0.
|
|
19
|
-
"@vyriy/logger": "0.
|
|
20
|
-
"@vyriy/pause": "0.
|
|
17
|
+
"@vyriy/env": "0.3.0",
|
|
18
|
+
"@vyriy/error": "0.3.0",
|
|
19
|
+
"@vyriy/logger": "0.3.0",
|
|
20
|
+
"@vyriy/pause": "0.3.0"
|
|
21
21
|
},
|
|
22
22
|
"agents": "./AGENTS.md",
|
|
23
23
|
"license": "MIT",
|
package/s3/actions.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { GetObjectCommand, HeadObjectCommand, PutObjectCommand } from '@aws-sdk/client-s3';
|
|
2
2
|
import { createLogger } from '@vyriy/logger';
|
|
3
3
|
import { toError } from '@vyriy/error';
|
|
4
|
-
import {
|
|
4
|
+
import { createClient } from './client.js';
|
|
5
5
|
export const download = async (bucketName, path, options = {}) => {
|
|
6
6
|
try {
|
|
7
|
+
const client = createClient();
|
|
7
8
|
const logger = createLogger();
|
|
8
9
|
logger.log('GetObjectCommand:', { Bucket: bucketName, Key: path, ...options });
|
|
9
10
|
const response = await client.send(new GetObjectCommand({ Bucket: bucketName, Key: path, ...options }));
|
|
@@ -18,6 +19,7 @@ export const download = async (bucketName, path, options = {}) => {
|
|
|
18
19
|
};
|
|
19
20
|
export const upload = async (bucketName, path, body, mimeType = 'application/json;charset=utf-8', options = {}) => {
|
|
20
21
|
try {
|
|
22
|
+
const client = createClient();
|
|
21
23
|
createLogger().log('PutObjectCommand:', {
|
|
22
24
|
Bucket: bucketName,
|
|
23
25
|
Key: path,
|
|
@@ -40,6 +42,7 @@ export const upload = async (bucketName, path, body, mimeType = 'application/jso
|
|
|
40
42
|
};
|
|
41
43
|
export const exists = async (bucketName, path, options = {}) => {
|
|
42
44
|
try {
|
|
45
|
+
const client = createClient();
|
|
43
46
|
createLogger().log('HeadObjectCommand:', {
|
|
44
47
|
Bucket: bucketName,
|
|
45
48
|
Key: path,
|
package/s3/client.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { S3Client } from '@aws-sdk/client-s3';
|
|
2
|
-
export declare const
|
|
1
|
+
import { S3Client, type S3ClientConfig } from '@aws-sdk/client-s3';
|
|
2
|
+
export declare const createClient: (options?: S3ClientConfig) => S3Client;
|
package/s3/client.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { S3Client } from '@aws-sdk/client-s3';
|
|
2
2
|
import { getRegion, getLocalstackHost, getLocalstackPort, isLocal } from '@vyriy/env';
|
|
3
|
-
const options =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
export const createClient = (options = {}) => {
|
|
4
|
+
const defaultOptions = isLocal()
|
|
5
|
+
? {
|
|
6
|
+
region: getRegion(),
|
|
7
|
+
endpoint: `http://${getLocalstackHost()}:${getLocalstackPort()}`,
|
|
8
|
+
forcePathStyle: true,
|
|
9
|
+
}
|
|
10
|
+
: {};
|
|
11
|
+
return new S3Client({ ...defaultOptions, ...options });
|
|
12
|
+
};
|
package/sns/actions.js
CHANGED
package/sns/client.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SNS } from '@aws-sdk/client-sns';
|
|
2
|
-
export declare const
|
|
1
|
+
import { SNS, type SNSClientConfig } from '@aws-sdk/client-sns';
|
|
2
|
+
export declare const createClient: (options?: SNSClientConfig) => SNS;
|
package/sns/client.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { SNS } from '@aws-sdk/client-sns';
|
|
2
|
-
export const
|
|
2
|
+
export const createClient = (options = {}) => new SNS(options);
|
package/ssm/actions.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { GetParameterCommand, GetParametersCommand } from '@aws-sdk/client-ssm';
|
|
2
2
|
import { createLogger } from '@vyriy/logger';
|
|
3
3
|
import { toError } from '@vyriy/error';
|
|
4
|
-
import {
|
|
4
|
+
import { createClient } from './client.js';
|
|
5
5
|
export const getParameter = async (parameterName, decrypted = true) => {
|
|
6
6
|
try {
|
|
7
|
+
const client = createClient();
|
|
7
8
|
const logger = createLogger();
|
|
8
9
|
logger.log('GetParameterCommand:', parameterName, decrypted);
|
|
9
10
|
const response = await client.send(new GetParameterCommand({ Name: parameterName, WithDecryption: decrypted }));
|
|
@@ -18,6 +19,7 @@ export const getParameter = async (parameterName, decrypted = true) => {
|
|
|
18
19
|
};
|
|
19
20
|
export const getParameters = async (parameterNames, decrypted = true) => {
|
|
20
21
|
try {
|
|
22
|
+
const client = createClient();
|
|
21
23
|
const logger = createLogger();
|
|
22
24
|
logger.log('GetParametersCommand:', parameterNames, decrypted);
|
|
23
25
|
const response = await client.send(new GetParametersCommand({ Names: parameterNames, WithDecryption: decrypted }));
|
package/ssm/client.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SSMClient } from '@aws-sdk/client-ssm';
|
|
2
|
-
export declare const
|
|
1
|
+
import { SSMClient, type SSMClientConfig } from '@aws-sdk/client-ssm';
|
|
2
|
+
export declare const createClient: (options?: SSMClientConfig) => SSMClient;
|
package/ssm/client.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { SSMClient } from '@aws-sdk/client-ssm';
|
|
2
|
-
export const
|
|
2
|
+
export const createClient = (options = {}) => new SSMClient(options);
|