@vyriy/services 0.2.0 → 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/AGENTS.md ADDED
@@ -0,0 +1,65 @@
1
+ # Vyriy Package Agent Guide
2
+
3
+ This package belongs to the Vyriy toolkit. Keep changes calm, explicit, reusable, and easy to reason about.
4
+
5
+ ## Architecture
6
+
7
+ - Prefer simple modules over clever frameworks or hidden conventions.
8
+ - Keep package boundaries explicit and avoid project-specific coupling.
9
+ - Extract only proven reusable behavior.
10
+ - Keep public APIs small, typed, documented, and stable.
11
+ - Prefer SSR-friendly and SSG-friendly code paths.
12
+ - Keep integrations replaceable and avoid hard coupling to a CMS or runtime host.
13
+ - Prefer AWS serverless-compatible assumptions when infrastructure concerns appear.
14
+
15
+ ## File Shape
16
+
17
+ - Prefer one exported runtime method, component, or helper per production file when it stays readable.
18
+ - Prefer one matching test file per production file, for example `feature.ts` and `feature.test.ts`.
19
+ - Use focused folders when behavior naturally splits into several related files.
20
+ - Keep `index.ts` as a public re-export surface only. Do not place implementation logic in it.
21
+ - Use `.js` relative import and export specifiers in TypeScript source where package style requires it.
22
+ - Add `types.ts` when public shared types are part of the package contract.
23
+ - Keep constants near the code that owns them unless they are shared or clarify repeated behavior.
24
+
25
+ ## Public Surface
26
+
27
+ - Every new public export should be re-exported from `index.ts`.
28
+ - Add or update `index.test.ts` when the public export surface changes.
29
+ - Add JSDoc for public exports when behavior, parameters, return values, or usage expectations need explanation.
30
+ - Do not hand-maintain source package `exports` maps unless the package has a real custom publishing need.
31
+
32
+ ## Tests
33
+
34
+ - Tests use Jest and `@jest/globals`.
35
+ - Cover public behavior and meaningful edge cases.
36
+ - Prefer behavior-focused tests over private implementation lock-in.
37
+ - When mocking modules, install mocks before loading the module under test.
38
+ - Use focused validation when changing package behavior:
39
+
40
+ ```bash
41
+ yarn jest packages/<package> --runInBand --coverage=false
42
+ ```
43
+
44
+ ## Documentation
45
+
46
+ - Keep `README.md` concise and usage-oriented.
47
+ - Start package READMEs with `# @vyriy/<package>`.
48
+ - Document real public exports, supported options, and examples that actually work.
49
+ - Keep `doc.mdx` as the Storybook/docs wrapper for the README when the package participates in docs.
50
+ - For component packages, include Storybook coverage for supported states and common usage.
51
+
52
+ ## Components
53
+
54
+ - Prefer lightweight React 19+ components with TypeScript.
55
+ - Keep components SSR-friendly and avoid browser globals during render.
56
+ - Prefer composable props and Bootstrap-compatible ergonomics where practical.
57
+ - Put each public component in its own file with a matching test.
58
+ - Add Storybook stories when a component has visual states, variants, or interaction states.
59
+
60
+ ## Change Discipline
61
+
62
+ - Keep changes scoped to the requested behavior.
63
+ - Avoid unrelated refactors and metadata churn.
64
+ - Sync implementation, tests, README, `doc.mdx`, and public re-exports together.
65
+ - Prefer the option that is simpler to explain, easier to evolve, and calmer to maintain.
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:
@@ -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 { client } from './client.js';
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);
@@ -1,2 +1,2 @@
1
- import { CloudFrontClient } from '@aws-sdk/client-cloudfront';
2
- export declare const client: CloudFrontClient;
1
+ import { CloudFrontClient, type CloudFrontClientConfig } from '@aws-sdk/client-cloudfront';
2
+ export declare const createClient: (options?: CloudFrontClientConfig) => CloudFrontClient;
@@ -1,2 +1,2 @@
1
1
  import { CloudFrontClient } from '@aws-sdk/client-cloudfront';
2
- export const client = new CloudFrontClient({});
2
+ export const createClient = (options = {}) => new CloudFrontClient(options);
@@ -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 { client } from './client.js';
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) => {
@@ -1,2 +1,2 @@
1
- import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
2
- export declare const client: DynamoDBClient;
1
+ import { DynamoDBClient, type DynamoDBClientConfig } from '@aws-sdk/client-dynamodb';
2
+ export declare const createClient: (options?: DynamoDBClientConfig) => DynamoDBClient;
@@ -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 = isLocal()
4
- ? {
5
- region: getRegion(),
6
- endpoint: `http://${getLocalstackHost()}:${getLocalstackPort()}`,
7
- }
8
- : {};
9
- export const client = new DynamoDBClient(options);
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 { client } from './client.js';
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 client: ECSClient;
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 options = isLocal() ? { region: getRegion() } : {};
4
- export const client = new ECSClient(options);
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 { client } from './client.js';
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);
@@ -1,2 +1,2 @@
1
- import { LambdaClient } from '@aws-sdk/client-lambda';
2
- export declare const client: LambdaClient;
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 = { region: getRegion() };
4
- export const client = new LambdaClient(options);
3
+ export const createClient = (options = {}) => {
4
+ const defaultOptions = { region: getRegion() };
5
+ return new LambdaClient({ ...defaultOptions, ...options });
6
+ };
package/package.json CHANGED
@@ -1,24 +1,25 @@
1
1
  {
2
2
  "name": "@vyriy/services",
3
- "version": "0.2.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.1045.0",
9
- "@aws-sdk/client-dynamodb": "^3.1045.0",
10
- "@aws-sdk/client-ecs": "^3.1045.0",
11
- "@aws-sdk/client-lambda": "^3.1045.0",
12
- "@aws-sdk/client-s3": "^3.1045.0",
13
- "@aws-sdk/client-sns": "^3.1045.0",
14
- "@aws-sdk/client-ssm": "^3.1045.0",
15
- "@aws-sdk/lib-dynamodb": "^3.1045.0",
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.2.0",
18
- "@vyriy/error": "0.2.0",
19
- "@vyriy/logger": "0.2.0",
20
- "@vyriy/pause": "0.2.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
+ "agents": "./AGENTS.md",
22
23
  "license": "MIT",
23
24
  "repository": {
24
25
  "type": "git",
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 { client } from './client.js';
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 client: S3Client;
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 = isLocal()
4
- ? {
5
- region: getRegion(),
6
- endpoint: `http://${getLocalstackHost()}:${getLocalstackPort()}`,
7
- forcePathStyle: true,
8
- }
9
- : {};
10
- export const client = new S3Client(options);
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
@@ -1,5 +1,6 @@
1
- import { client } from './client.js';
1
+ import { createClient } from './client.js';
2
2
  export const publish = async (topicArn, message, options = {}) => {
3
+ const client = createClient();
3
4
  await client.publish({
4
5
  TopicArn: topicArn,
5
6
  Message: message,
package/sns/client.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { SNS } from '@aws-sdk/client-sns';
2
- export declare const client: SNS;
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 client = new SNS({});
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 { client } from './client.js';
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 client: SSMClient;
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 client = new SSMClient({});
2
+ export const createClient = (options = {}) => new SSMClient(options);