@vyriy/scripts 0.7.0 → 0.7.1

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 CHANGED
@@ -1,10 +1,14 @@
1
1
  # @vyriy/scripts
2
2
 
3
- Shared scripts package for Vyriy projects.
3
+ Shared script factories for Vyriy projects.
4
4
 
5
5
  ## Purpose
6
6
 
7
- This package exposes reusable CDK deployment, smoke-test, and e2e script factories used by Vyriy projects.
7
+ This package collects reusable deployment, build, smoke-test, and post-deploy script factories.
8
+
9
+ Every export is built on `@vyriy/script`, the common process wrapper used by Vyriy scripts. The wrapper keeps script execution consistent by centralizing process lifecycle behavior such as logging, timeout handling, and error reporting.
10
+
11
+ The package is meant for CI/CD and project-local automation where a project needs small, composable scripts instead of one large deployment framework.
8
12
 
9
13
  ## Install
10
14
 
@@ -20,75 +24,102 @@ With Yarn:
20
24
  yarn add @vyriy/scripts
21
25
  ```
22
26
 
23
- ## Exports
27
+ ## Script Groups
28
+
29
+ ### API Smoke Scripts
30
+
31
+ - `lambda` invokes a Lambda function directly with the shared smoke payload. Run this first when an API is backed by Lambda, because it shows whether the function is alive and its dependencies can load.
32
+ - `healthcheck` calls the standard API Gateway healthcheck endpoint. This is the narrow API smoke check and is a good next step after `lambda`.
33
+ - `api` resolves the API Gateway URL and passes it to a callback for custom API smoke scenarios across one or more endpoints.
34
+
35
+ ### Deployment Scripts
36
+
37
+ - `deploy` runs AWS CDK synth, diff, and deploy in CI mode.
38
+ - `docker` builds and pushes a Docker image to ECR with Docker Buildx.
39
+ - `kaniko` builds and pushes a Docker image to ECR with Kaniko, usually for container-native CI.
40
+
41
+ `docker` and `kaniko` can be part of a deployment flow for services such as AWS Fargate tasks.
42
+
43
+ ### Static Smoke Scripts
24
44
 
25
- - `api` for API smoke checks
26
- - `deploy` for CDK synth, diff, and deploy execution
27
- - `docker` for Docker image build and push to ECR
28
- - `e2e` for custom end-to-end scenarios
29
- - `kaniko` for container build and push with Kaniko
30
- - `lambda` for Lambda smoke checks
31
- - `ui` for static UI smoke checks
32
- - `webhooks` for webhook execution
45
+ - `mfe` checks a static MFE distribution by requesting the distribution URL, `index.html`, and `index.js`.
46
+ - `site` checks a static website by requesting the site URL, `robots.txt`, `sitemap.xml`, and every URL listed in the sitemap.
33
47
 
34
- ## Usage
48
+ Both scripts are smoke tests, but at different static delivery levels: `mfe` is focused on a widget/application bundle, while `site` is focused on a complete static website.
35
49
 
36
- Import from the package root:
50
+ ### Post-Deploy Scripts
51
+
52
+ - `webhooks` triggers API webhook endpoints after deployment.
53
+
54
+ Use `webhooks` for environment preparation after a deployment. For example, a feature environment may need to call API webhooks that generate translations, warm content, or start a Fargate task before manual or automated testing begins.
55
+
56
+ ## Exports
37
57
 
38
58
  ```ts
39
- import { api, deploy, docker, e2e, kaniko, lambda, ui, webhooks } from '@vyriy/scripts';
59
+ import { api, deploy, docker, healthcheck, kaniko, lambda, mfe, site, webhooks } from '@vyriy/scripts';
40
60
  ```
41
61
 
42
- Or use subpath exports:
62
+ Subpath imports are also supported:
43
63
 
44
64
  ```ts
45
65
  import { api } from '@vyriy/scripts/api';
46
66
  import { deploy } from '@vyriy/scripts/deploy';
47
67
  import { docker } from '@vyriy/scripts/docker';
48
- import { e2e } from '@vyriy/scripts/e2e';
68
+ import { healthcheck } from '@vyriy/scripts/healthcheck';
49
69
  import { kaniko } from '@vyriy/scripts/kaniko';
50
70
  import { lambda } from '@vyriy/scripts/lambda';
51
- import { ui } from '@vyriy/scripts/ui';
71
+ import { mfe } from '@vyriy/scripts/mfe';
72
+ import { site } from '@vyriy/scripts/site';
52
73
  import { webhooks } from '@vyriy/scripts/webhooks';
53
74
  ```
54
75
 
55
76
  ## Examples
56
77
 
57
- ### API smoke test
78
+ ### Lambda Smoke Test
58
79
 
59
80
  ```ts
60
- import { api } from '@vyriy/scripts/api';
81
+ import { lambda } from '@vyriy/scripts/lambda';
61
82
 
62
- await api();
83
+ await lambda('my-function');
63
84
  ```
64
85
 
65
- ### CDK deployment
86
+ ### API Healthcheck
66
87
 
67
88
  ```ts
68
- import { deploy } from '@vyriy/scripts/deploy';
89
+ import { healthcheck } from '@vyriy/scripts/healthcheck';
69
90
 
70
- await deploy();
91
+ await healthcheck();
92
+ await healthcheck('CustomApiUrl', 'status');
71
93
  ```
72
94
 
73
- ### Docker deployment
95
+ ### API Scenario
74
96
 
75
97
  ```ts
76
- import { docker } from '@vyriy/scripts/docker';
98
+ import { api } from '@vyriy/scripts/api';
77
99
 
78
- await docker('./apps/api');
100
+ await api(async (url) => {
101
+ await fetch(`${url}healthcheck`);
102
+ await fetch(`${url}users/me`);
103
+ });
79
104
  ```
80
105
 
81
- ### E2E scenario
106
+ ### CDK Deployment
82
107
 
83
108
  ```ts
84
- import { e2e } from '@vyriy/scripts/e2e';
109
+ import { deploy } from '@vyriy/scripts/deploy';
85
110
 
86
- await e2e(async (url) => {
87
- await fetch(`${url}healthcheck`);
88
- });
111
+ await deploy();
89
112
  ```
90
113
 
91
- ### Kaniko deployment
114
+ ### Docker Image Deployment
115
+
116
+ ```ts
117
+ import { docker } from '@vyriy/scripts/docker';
118
+
119
+ await docker('./apps/api');
120
+ ```
121
+
122
+ ### Kaniko Image Deployment
92
123
 
93
124
  ```ts
94
125
  import { kaniko } from '@vyriy/scripts/kaniko';
@@ -96,24 +127,25 @@ import { kaniko } from '@vyriy/scripts/kaniko';
96
127
  await kaniko('./apps/api');
97
128
  ```
98
129
 
99
- ### Lambda smoke test
130
+ ### MFE Smoke Test
100
131
 
101
132
  ```ts
102
- import { lambda } from '@vyriy/scripts/lambda';
133
+ import { mfe } from '@vyriy/scripts/mfe';
103
134
 
104
- await lambda('my-function');
135
+ await mfe();
136
+ await mfe('CustomDistributionUrl');
105
137
  ```
106
138
 
107
- ### UI smoke test
139
+ ### Static Site Smoke Test
108
140
 
109
141
  ```ts
110
- import { ui } from '@vyriy/scripts/ui';
142
+ import { site } from '@vyriy/scripts/site';
111
143
 
112
- await ui();
113
- await ui('DistributionUrl', false); // skip index.js for HTML-only output
144
+ await site();
145
+ await site('CustomSiteUrl');
114
146
  ```
115
147
 
116
- ### Webhook execution
148
+ ### Webhook Execution
117
149
 
118
150
  ```ts
119
151
  import { webhooks } from '@vyriy/scripts/webhooks';
package/api.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const api: (stackApiResource?: string, healthcheckUrl?: string) => import("@vyriy/script").Result;
1
+ export declare const api: (callback: (url: string) => Promise<void>, resourceName?: string) => import("@vyriy/script").Result;
package/api.js CHANGED
@@ -1,15 +1,11 @@
1
- import { script } from '@vyriy/script';
2
1
  import { createLogger } from '@vyriy/logger';
3
- import { retry } from '@vyriy/retry';
4
- import { request } from '@vyriy/request';
5
2
  import { output } from '@vyriy/cdk';
6
- export const api = (stackApiResource = 'ApiGatewayUrl', healthcheckUrl = 'healthcheck') => script(async () => {
3
+ import { script } from '@vyriy/script';
4
+ export const api = (callback, resourceName = 'ApiGatewayUrl') => script(async () => {
7
5
  const logger = createLogger();
8
6
  logger.info('API Smoke testing...');
9
- const url = output()[stackApiResource];
10
- logger.info('API url:', url);
11
- const testingUrl = `${url}${healthcheckUrl}`;
12
- logger.info(`Testing: ${testingUrl}`);
13
- await retry(async () => request(testingUrl), { retries: 2, delay: 2000 });
7
+ const apiGatewayUrl = output()[resourceName];
8
+ logger.info('API Gateway url:', apiGatewayUrl);
9
+ await callback(apiGatewayUrl);
14
10
  logger.info('API Smoke testing finished!');
15
11
  });
@@ -0,0 +1 @@
1
+ export declare const healthcheck: (stackApiResource?: string, healthcheckUrl?: string) => import("@vyriy/script").Result;
package/healthcheck.js ADDED
@@ -0,0 +1,15 @@
1
+ import { script } from '@vyriy/script';
2
+ import { createLogger } from '@vyriy/logger';
3
+ import { retry } from '@vyriy/retry';
4
+ import { request } from '@vyriy/request';
5
+ import { output } from '@vyriy/cdk';
6
+ export const healthcheck = (stackApiResource = 'ApiGatewayUrl', healthcheckUrl = 'healthcheck') => script(async () => {
7
+ const logger = createLogger();
8
+ logger.info('API Healthcheck testing...');
9
+ const url = output()[stackApiResource];
10
+ logger.info('API url:', url);
11
+ const testingUrl = `${url}${healthcheckUrl}`;
12
+ logger.info(`Testing: ${testingUrl}`);
13
+ await retry(async () => request(testingUrl), { retries: 2, delay: 2000 });
14
+ logger.info('API Healthcheck testing finished!');
15
+ });
package/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  export * from './api.js';
2
2
  export * from './deploy.js';
3
3
  export * from './docker.js';
4
- export * from './e2e.js';
4
+ export * from './healthcheck.js';
5
5
  export * from './kaniko.js';
6
6
  export * from './lambda.js';
7
- export * from './ui.js';
7
+ export * from './mfe.js';
8
+ export * from './site.js';
8
9
  export * from './webhooks.js';
package/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  export * from './api.js';
2
2
  export * from './deploy.js';
3
3
  export * from './docker.js';
4
- export * from './e2e.js';
4
+ export * from './healthcheck.js';
5
5
  export * from './kaniko.js';
6
6
  export * from './lambda.js';
7
- export * from './ui.js';
7
+ export * from './mfe.js';
8
+ export * from './site.js';
8
9
  export * from './webhooks.js';
package/mfe.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const mfe: (resourceName?: string) => import("@vyriy/script").Result;
package/mfe.js ADDED
@@ -0,0 +1,28 @@
1
+ import { createLogger } from '@vyriy/logger';
2
+ import { output } from '@vyriy/cdk';
3
+ import { script } from '@vyriy/script';
4
+ import { request } from '@vyriy/request';
5
+ import { retry } from '@vyriy/retry';
6
+ export const mfe = (resourceName = 'DistributionUrl') => script(async () => {
7
+ const logger = createLogger();
8
+ logger.info('MFE Smoke testing...');
9
+ const retryOptions = {
10
+ retries: 2,
11
+ delay: 2000,
12
+ };
13
+ const mfeUrl = output()[resourceName];
14
+ logger.info('MFE domain:', mfeUrl);
15
+ await retry(async () => {
16
+ logger.info(`Testing: ${mfeUrl}`);
17
+ await request(mfeUrl);
18
+ }, retryOptions);
19
+ await retry(async () => {
20
+ logger.info(`Testing: ${mfeUrl}index.html`);
21
+ await request(`${mfeUrl}index.html`);
22
+ }, retryOptions);
23
+ await retry(async () => {
24
+ logger.info(`Testing: ${mfeUrl}index.js`);
25
+ await request(`${mfeUrl}index.js`);
26
+ }, retryOptions);
27
+ logger.info('MFE Smoke testing finished!');
28
+ });
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "@vyriy/scripts",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Shared scripts package for Vyriy projects",
5
5
  "type": "module",
6
6
  "dependencies": {
7
- "@vyriy/cdk": "0.7.0",
8
- "@vyriy/exec": "0.7.0",
9
- "@vyriy/logger": "0.7.0",
10
- "@vyriy/request": "0.7.0",
11
- "@vyriy/retry": "0.7.0",
12
- "@vyriy/script": "0.7.0",
13
- "@vyriy/services": "0.7.0",
14
- "@vyriy/smoke": "0.7.0"
7
+ "@vyriy/cdk": "0.7.1",
8
+ "@vyriy/exec": "0.7.1",
9
+ "@vyriy/logger": "0.7.1",
10
+ "@vyriy/recursive": "0.7.1",
11
+ "@vyriy/request": "0.7.1",
12
+ "@vyriy/retry": "0.7.1",
13
+ "@vyriy/script": "0.7.1",
14
+ "@vyriy/services": "0.7.1",
15
+ "@vyriy/smoke": "0.7.1"
15
16
  },
16
17
  "agents": "./AGENTS.md",
17
18
  "license": "MIT",
@@ -58,15 +59,15 @@
58
59
  "import": "./docker.js",
59
60
  "default": "./docker.js"
60
61
  },
61
- "./e2e": {
62
- "types": "./e2e.d.ts",
63
- "import": "./e2e.js",
64
- "default": "./e2e.js"
62
+ "./healthcheck": {
63
+ "types": "./healthcheck.d.ts",
64
+ "import": "./healthcheck.js",
65
+ "default": "./healthcheck.js"
65
66
  },
66
- "./e2e.js": {
67
- "types": "./e2e.d.ts",
68
- "import": "./e2e.js",
69
- "default": "./e2e.js"
67
+ "./healthcheck.js": {
68
+ "types": "./healthcheck.d.ts",
69
+ "import": "./healthcheck.js",
70
+ "default": "./healthcheck.js"
70
71
  },
71
72
  "./index": {
72
73
  "types": "./index.d.ts",
@@ -98,15 +99,25 @@
98
99
  "import": "./lambda.js",
99
100
  "default": "./lambda.js"
100
101
  },
101
- "./ui": {
102
- "types": "./ui.d.ts",
103
- "import": "./ui.js",
104
- "default": "./ui.js"
105
- },
106
- "./ui.js": {
107
- "types": "./ui.d.ts",
108
- "import": "./ui.js",
109
- "default": "./ui.js"
102
+ "./mfe": {
103
+ "types": "./mfe.d.ts",
104
+ "import": "./mfe.js",
105
+ "default": "./mfe.js"
106
+ },
107
+ "./mfe.js": {
108
+ "types": "./mfe.d.ts",
109
+ "import": "./mfe.js",
110
+ "default": "./mfe.js"
111
+ },
112
+ "./site": {
113
+ "types": "./site.d.ts",
114
+ "import": "./site.js",
115
+ "default": "./site.js"
116
+ },
117
+ "./site.js": {
118
+ "types": "./site.d.ts",
119
+ "import": "./site.js",
120
+ "default": "./site.js"
110
121
  },
111
122
  "./webhooks": {
112
123
  "types": "./webhooks.d.ts",
package/site.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const site: (resourceName?: string) => import("@vyriy/script").Result;
package/site.js ADDED
@@ -0,0 +1,81 @@
1
+ import { createLogger } from '@vyriy/logger';
2
+ import { output } from '@vyriy/cdk';
3
+ import { script } from '@vyriy/script';
4
+ import { request } from '@vyriy/request';
5
+ import { retry } from '@vyriy/retry';
6
+ import { recursive } from '@vyriy/recursive';
7
+ const toUrl = (baseUrl, path) => new URL(path, baseUrl).toString();
8
+ const locTag = '<loc>';
9
+ const locEndTag = '</loc>';
10
+ const sitemapIndexTag = '<sitemapindex';
11
+ const isTagBoundary = (character) => !character || character === '>' || character === '/' || character <= ' ';
12
+ const parseSitemapUrls = (sitemap) => {
13
+ const urls = [];
14
+ const normalizedSitemap = sitemap.toLowerCase();
15
+ let searchIndex = 0;
16
+ while (searchIndex < sitemap.length) {
17
+ const locStartIndex = normalizedSitemap.indexOf(locTag, searchIndex);
18
+ if (locStartIndex === -1) {
19
+ break;
20
+ }
21
+ const urlStartIndex = locStartIndex + locTag.length;
22
+ const locEndIndex = normalizedSitemap.indexOf(locEndTag, urlStartIndex);
23
+ if (locEndIndex === -1) {
24
+ break;
25
+ }
26
+ const url = sitemap.slice(urlStartIndex, locEndIndex).trim();
27
+ if (url) {
28
+ urls.push(url);
29
+ }
30
+ searchIndex = locEndIndex + locEndTag.length;
31
+ }
32
+ return urls;
33
+ };
34
+ const isSitemapIndex = (sitemap) => {
35
+ const normalizedSitemap = sitemap.toLowerCase();
36
+ const tagIndex = normalizedSitemap.indexOf(sitemapIndexTag);
37
+ return tagIndex !== -1 && isTagBoundary(normalizedSitemap[tagIndex + sitemapIndexTag.length]);
38
+ };
39
+ const requestText = (url) => request(url);
40
+ export const site = (resourceName = 'SiteUrl') => script(async () => {
41
+ const logger = createLogger();
42
+ logger.info('Site Smoke testing...');
43
+ const retryOptions = {
44
+ retries: 2,
45
+ delay: 2000,
46
+ };
47
+ const siteUrl = output()[resourceName];
48
+ const robotsUrl = toUrl(siteUrl, 'robots.txt');
49
+ const sitemapUrl = toUrl(siteUrl, 'sitemap.xml');
50
+ logger.info('Site url:', siteUrl);
51
+ await retry(async () => {
52
+ logger.info(`Testing: ${siteUrl}`);
53
+ await request(siteUrl);
54
+ }, retryOptions);
55
+ await retry(async () => {
56
+ logger.info(`Testing: ${robotsUrl}`);
57
+ await request(robotsUrl);
58
+ }, retryOptions);
59
+ const sitemap = (await retry(async () => {
60
+ logger.info(`Testing: ${sitemapUrl}`);
61
+ return requestText(sitemapUrl);
62
+ }, retryOptions));
63
+ const sitemapUrls = parseSitemapUrls(sitemap);
64
+ const pageUrls = isSitemapIndex(sitemap)
65
+ ? (await Promise.all(sitemapUrls.map((nestedSitemapUrl) => retry(async () => {
66
+ logger.info(`Testing: ${nestedSitemapUrl}`);
67
+ const nestedSitemap = await requestText(nestedSitemapUrl);
68
+ return parseSitemapUrls(nestedSitemap);
69
+ }, retryOptions)))).flat()
70
+ : sitemapUrls;
71
+ if (!pageUrls.length) {
72
+ throw new Error(`Sitemap has no URLs: ${sitemapUrl}`);
73
+ }
74
+ await recursive(async (pageUrl) => {
75
+ await retry(async () => {
76
+ logger.info(`Testing: ${pageUrl}`);
77
+ await request(pageUrl);
78
+ }, retryOptions);
79
+ }, pageUrls);
80
+ logger.info('Site Smoke testing finished!');
81
+ });
package/e2e.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const e2e: (callback: (url: string) => Promise<void>, resourceName?: string) => import("@vyriy/script").Result;
package/e2e.js DELETED
@@ -1,11 +0,0 @@
1
- import { createLogger } from '@vyriy/logger';
2
- import { output } from '@vyriy/cdk';
3
- import { script } from '@vyriy/script';
4
- export const e2e = (callback, resourceName = 'ApiGatewayUrl') => script(async () => {
5
- const logger = createLogger();
6
- logger.info('E2E testing...');
7
- const apiGatewayUrl = output()[resourceName];
8
- logger.info('API Gateway url:', apiGatewayUrl);
9
- await callback(apiGatewayUrl);
10
- logger.info('E2E testing finished!');
11
- });
package/ui.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const ui: (resourceName?: string, hasJs?: boolean) => import("@vyriy/script").Result;
package/ui.js DELETED
@@ -1,34 +0,0 @@
1
- import { createLogger } from '@vyriy/logger';
2
- import { output } from '@vyriy/cdk';
3
- import { script } from '@vyriy/script';
4
- import { request } from '@vyriy/request';
5
- import { retry } from '@vyriy/retry';
6
- export const ui = (resourceName = 'DistributionUrl', hasJs = true) => script(async () => {
7
- const logger = createLogger();
8
- logger.info('UI Smoke testing...');
9
- const retryOptions = {
10
- retries: 2,
11
- delay: 2000,
12
- };
13
- const uiUrl = output()[resourceName];
14
- logger.info('UI domain:', uiUrl);
15
- await retry(async () => {
16
- logger.info(`Testing: ${uiUrl}`);
17
- await request(uiUrl);
18
- }, retryOptions);
19
- await retry(async () => {
20
- logger.info(`Testing: ${uiUrl}index.html`);
21
- await request(`${uiUrl}index.html`);
22
- }, retryOptions);
23
- if (hasJs) {
24
- await retry(async () => {
25
- logger.info(`Testing: ${uiUrl}index.js`);
26
- await request(`${uiUrl}index.js`);
27
- }, retryOptions);
28
- }
29
- await retry(async () => {
30
- logger.info(`Testing: ${uiUrl}robots.txt`);
31
- await request(`${uiUrl}robots.txt`);
32
- }, retryOptions);
33
- logger.info('UI Smoke testing finished!');
34
- });