@smart-cloud/publisher-exporter 1.2.2 → 1.2.4

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.
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import g from'path';import {readFile}from'fs/promises';import {LambdaClient,InvokeCommand}from'@aws-sdk/client-lambda';import {DynamoDBClient,GetItemCommand}from'@aws-sdk/client-dynamodb';import {S3Client,GetObjectCommand,PutObjectCommand,CopyObjectCommand}from'@aws-sdk/client-s3';import {fromTemporaryCredentials,fromIni}from'@aws-sdk/credential-providers';import {createHash}from'crypto';var I=/^[A-Za-z0-9][A-Za-z0-9_.@+=,-]{0,127}$/;function m(o,e="awsProfile"){let r=String(o??"").trim();if(!r)return "";if(!I.test(r))throw new Error(`${e} must start with a letter or number and contain only letters, numbers, dot, dash, underscore, comma, plus, equals, or at-sign characters.`);return r}function O(o){return !!(String(o.AWS_ACCESS_KEY_ID??"").trim()&&String(o.AWS_SECRET_ACCESS_KEY??"").trim())}function w(o,e=process.env){let r=m(o);if(!(!r||O(e)))return fromIni({profile:r})}var u=1;function P(o){let e=String(o??"").trim().replace(/^\/+|\/+$/g,"");if(!e)return "";let r=e.split("/").filter(Boolean);if(r.some(t=>t==="."||t===".."))throw new Error("S3 prefix contains an unsafe dot path segment.");return `${r.join("/")}/`}function f(o){return createHash("sha256").update(o).digest("hex")}function p(o,e){let r=String(o??"").replace(/^\/+/,""),t=P(e);if(!r||r.includes("\0"))throw new Error("S3 object key is empty or invalid.");if(t&&!r.startsWith(t))throw new Error(`S3 object key is outside the configured workspace prefix: ${r}`);if(r.split("/").some(s=>s===".."))throw new Error("S3 object key contains an unsafe parent segment.");return r}function a(o,e,{optional:r=false}={}){if(!(r&&(o==null||o===""))){if(typeof o!="string"||!o.trim())throw new Error(`${e} must be a non-empty string.`);return o.trim()}}function A(o){if(!o||typeof o!="object")throw new Error("Remote worker config must be a JSON object.");let e=o;if(e.schemaVersion!==1)throw new Error(`Unsupported remote worker config version: ${String(e.schemaVersion)}.`);if(e.protocolVersion!==u)throw new Error(`Remote worker protocol mismatch: expected ${u}, received ${String(e.protocolVersion)}.`);let r=e.workspace,t=e.functions;if(!r||!t)throw new Error("Remote worker config requires workspace and functions objects.");let s=m(e.awsProfile,"awsProfile");return {schemaVersion:1,region:a(e.region,"region"),...s?{awsProfile:s}:{},...a(e.roleArn,"roleArn",{optional:true})?{roleArn:a(e.roleArn,"roleArn")}:{},...a(e.roleSessionName,"roleSessionName",{optional:true})?{roleSessionName:a(e.roleSessionName,"roleSessionName")}:{},workspace:{bucket:a(r.bucket,"workspace.bucket"),prefix:String(r.prefix??"")},...e.status&&typeof e.status=="object"?{status:{tableName:a(e.status.tableName,"status.tableName")}}:{},functions:{render:a(t.render,"functions.render"),...a(t.asset,"functions.asset",{optional:true})?{asset:a(t.asset,"functions.asset")}:{},rewrite:a(t.rewrite,"functions.rewrite"),"deploy-copy":a(t["deploy-copy"],"functions.deploy-copy")},targets:Array.isArray(e.targets)?e.targets.map((n,i)=>{if(!n||typeof n!="object")throw new Error(`targets[${i}] must be an object.`);let l=n;return {id:a(l.id,`targets[${i}].id`),bucketName:a(l.bucketName,`targets[${i}].bucketName`),prefix:String(l.prefix??""),region:a(l.region,`targets[${i}].region`)}}):[],protocolVersion:u}}async function k(o){let e=g.resolve(o);try{return A(JSON.parse(await readFile(e,"utf8")))}catch(r){throw new Error(`Unable to load remote worker config ${e}: ${r instanceof Error?r.message:String(r)}`,{cause:r})}}var d=class{config;lambda;s3;dynamodb;#e;constructor(e,r={},t={}){this.config=e;let n=w(e.awsProfile)??(e.roleArn?fromTemporaryCredentials({params:{RoleArn:e.roleArn,RoleSessionName:e.roleSessionName??"publisher-exporter-remote-worker"},clientConfig:{region:e.region}}):void 0);this.lambda=new LambdaClient({region:e.region,...n?{credentials:n}:{},...r}),this.s3=new S3Client({region:e.region,...n?{credentials:n}:{}}),this.dynamodb=e.status?new DynamoDBClient({region:e.region,...n?{credentials:n}:{}}):null,this.#e=t;}async#r(e){if(!this.dynamodb||!this.config.status)return null;let t=(await this.dynamodb.send(new GetItemCommand({TableName:this.config.status.tableName,ConsistentRead:true,Key:{jobId:{S:e.jobId},taskId:{S:e.taskId}}}))).Item;if(!t)return null;let s=t.operation?.S,n=t.status?.S;return !s||!["render","asset","rewrite","deploy-copy"].includes(s)||!n||!["running","succeeded","partial","failed"].includes(n)?null:{jobId:t.jobId?.S??e.jobId,taskId:t.taskId?.S??e.taskId,operation:s,status:n,completedItems:Number(t.completedItems?.N??0),failedItems:Number(t.failedItems?.N??0),totalItems:Number(t.totalItems?.N??0),sequence:Number(t.sequence?.N??0),updatedAt:t.updatedAt?.S??new Date(0).toISOString(),requestId:t.requestId?.S??null}}async#t(e,r){let t=this.lambda.send(new InvokeCommand({FunctionName:r,InvocationType:"RequestResponse",Payload:Buffer.from(JSON.stringify(e),"utf8")}));if(e.operation==="health"||!this.dynamodb||!this.#e.onProgress)return await t;let s=false,n=t.finally(()=>{s=true;}),i=Math.max(500,Math.min(3e4,this.#e.progressPollIntervalMs??2e3)),l=-1;for(;!s;){await Promise.race([n.then(()=>{},()=>{}),new Promise(c=>setTimeout(c,i))]);try{let c=await this.#r(e);c&&c.sequence>l&&(l=c.sequence,await this.#e.onProgress(c));}catch(c){await this.#e.onProgressError?.(c instanceof Error?c:new Error(String(c)));}}return await n}async invoke(e){let r=e.operation==="health"?this.config.functions.render:this.config.functions[e.operation];if(!r)throw new Error(`Remote worker configuration does not provide a ${e.operation} function. Redeploy the Lambda workers and reinstall remote-workers.json.`);let t=await this.#t(e,r),s=t.Payload?JSON.parse(new TextDecoder().decode(t.Payload)):null;if(t.FunctionError)throw new Error(`Remote ${e.operation} worker failed (${t.FunctionError}): ${JSON.stringify(s)}`);if(!s||typeof s!="object")throw new Error(`Remote ${e.operation} worker returned no JSON response.`);let n=s;if(n.schemaVersion!==u||n.operation!==e.operation||n.jobId!==e.jobId||n.taskId!==e.taskId)throw new Error(`Remote ${e.operation} worker returned a mismatched response.`);return n}async readResult(e){if(!e.resultKey)throw new Error(`Remote ${e.operation} response does not contain a resultKey.`);let r=p(e.resultKey,this.config.workspace.prefix),t=await this.s3.send(new GetObjectCommand({Bucket:this.config.workspace.bucket,Key:r}));if(!t.Body)throw new Error(`Remote worker result has no body: ${r}`);return JSON.parse(await t.Body.transformToString("utf8"))}async readObject(e){if(e.bucket!==this.config.workspace.bucket)throw new Error(`Remote worker object bucket mismatch: ${e.bucket}.`);let r=p(e.key,this.config.workspace.prefix),t=await this.s3.send(new GetObjectCommand({Bucket:this.config.workspace.bucket,Key:r,...e.versionId?{VersionId:e.versionId}:{}}));if(!t.Body)throw new Error(`Remote worker object has no body: ${r}`);let s=await t.Body.transformToByteArray();if(s.byteLength!==e.bytes)throw new Error(`Remote worker object length mismatch for ${r}: expected ${e.bytes}, received ${s.byteLength}.`);if(f(s)!==e.sha256)throw new Error(`Remote worker object checksum mismatch for ${r}.`);return s}async readObjectText(e){return new TextDecoder("utf8",{fatal:true}).decode(await this.readObject(e))}async health(e){let r=this.config.functions[e];if(!r)throw new Error(`Remote worker configuration does not provide a ${e} function.`);let t=`${e}-${Date.now()}`,s=await this.lambda.send(new InvokeCommand({FunctionName:r,InvocationType:"RequestResponse",Payload:Buffer.from(JSON.stringify({schemaVersion:u,operation:"health",jobId:"health",taskId:t}),"utf8")})),n=s.Payload?JSON.parse(new TextDecoder().decode(s.Payload)):null;if(s.FunctionError||!n||typeof n!="object")throw new Error(`Remote ${e} health check failed: ${JSON.stringify(n)}`);return n}async writeWorkspaceObject(e){let r=p(e.key,this.config.workspace.prefix),t=typeof e.body=="string"?Buffer.from(e.body,"utf8"):e.body,s=f(t),n=await this.s3.send(new PutObjectCommand({Bucket:this.config.workspace.bucket,Key:r,Body:t,ContentType:e.contentType,...e.cacheControl?{CacheControl:e.cacheControl}:{},Metadata:{sha256:s,...e.metadata??{}}}));return {bucket:this.config.workspace.bucket,key:r,sha256:s,bytes:t.byteLength,contentType:e.contentType,...n.ETag?{etag:n.ETag}:{},...n.VersionId?{versionId:n.VersionId}:{}}}async copyWorkspaceObject(e,r){if(e.bucket!==this.config.workspace.bucket)throw new Error(`Remote worker object bucket mismatch: ${e.bucket}.`);let t=p(e.key,this.config.workspace.prefix),s=p(r,this.config.workspace.prefix),n=`${e.bucket}/${t.split("/").map(l=>encodeURIComponent(l)).join("/")}`,i=await this.s3.send(new CopyObjectCommand({Bucket:e.bucket,Key:s,CopySource:n,MetadataDirective:"COPY"}));return {...e,key:s,...i.CopyObjectResult?.ETag?{etag:i.CopyObjectResult.ETag}:{},...i.VersionId?{versionId:i.VersionId}:{}}}};var h="remote-workers.json";function b(o={}){let e=String(o.explicitPath??"").trim();if(e)return g.resolve(e);let r=String(o.runtimeDir??process.env.STATIC_PUBLISHER_RUNTIME_DIR??process.env.WPSUITE_STATIC_PUBLISHER_RUNTIME_DIR??"").trim();return r?g.join(g.resolve(r),h):""}function K(o){let e=o.findIndex(i=>i==="--config"||i==="-c"),r=o.find(i=>i.startsWith("--config=")),t=o.findIndex(i=>i==="--runtime-dir"),s=o.find(i=>i.startsWith("--runtime-dir=")),n=b({explicitPath:r?.slice(9)??(e>=0?o[e+1]:void 0),runtimeDir:s?.slice(14)??(t>=0?o[t+1]:void 0)});if(!n)throw new Error(`Pass --runtime-dir <path>; ${h} must be installed there. --config remains available for diagnostic overrides.`);return g.resolve(n)}async function M(){let o=await k(K(process.argv.slice(2))),e=new d(o),r=["render",...o.functions.asset?["asset"]:[],"rewrite","deploy-copy"],t=await Promise.all(r.map(async s=>({operation:s,response:await e.health(s)})));console.log(JSON.stringify({ok:true,results:t},null,2));}M().catch(o=>{console.error(o instanceof Error?o.message:String(o)),process.exit(1);});
2
+ import g from'path';import {readFile}from'fs/promises';import {LambdaClient,InvokeCommand}from'@aws-sdk/client-lambda';import {DynamoDBClient,GetItemCommand}from'@aws-sdk/client-dynamodb';import {S3Client,GetObjectCommand,HeadObjectCommand,PutObjectCommand,CopyObjectCommand}from'@aws-sdk/client-s3';import {fromTemporaryCredentials,fromIni}from'@aws-sdk/credential-providers';import {createHash}from'crypto';var O=/^[A-Za-z0-9][A-Za-z0-9_.@+=,-]{0,127}$/;function d(o,e="awsProfile"){let r=String(o??"").trim();if(!r)return "";if(!O.test(r))throw new Error(`${e} must start with a letter or number and contain only letters, numbers, dot, dash, underscore, comma, plus, equals, or at-sign characters.`);return r}function S(o){return !!(String(o.AWS_ACCESS_KEY_ID??"").trim()&&String(o.AWS_SECRET_ACCESS_KEY??"").trim())}function w(o,e=process.env){let r=d(o);if(!(!r||S(e)))return fromIni({profile:r})}var p=1;function T(o){let e=String(o??"").trim().replace(/^\/+|\/+$/g,"");if(!e)return "";let r=e.split("/").filter(Boolean);if(r.some(t=>t==="."||t===".."))throw new Error("S3 prefix contains an unsafe dot path segment.");return `${r.join("/")}/`}function f(o){return createHash("sha256").update(o).digest("hex")}function u(o,e){let r=String(o??"").replace(/^\/+/,""),t=T(e);if(!r||r.includes("\0"))throw new Error("S3 object key is empty or invalid.");if(t&&!r.startsWith(t))throw new Error(`S3 object key is outside the configured workspace prefix: ${r}`);if(r.split("/").some(n=>n===".."))throw new Error("S3 object key contains an unsafe parent segment.");return r}function x(o){let r=Math.ceil(o/1e3);return `${r} second${r===1?"":"s"}`}async function y(o,e,r){let t=new AbortController,n=globalThis.setTimeout(()=>{t.abort(new Error(`${o} timed out after ${x(e)}.`));},e);try{return await r({abortController:t,httpOptions:{abortSignal:t.signal,requestTimeout:e}})}finally{globalThis.clearTimeout(n);}}function a(o,e,{optional:r=false}={}){if(!(r&&(o==null||o===""))){if(typeof o!="string"||!o.trim())throw new Error(`${e} must be a non-empty string.`);return o.trim()}}function K(o){if(!o||typeof o!="object")throw new Error("Remote worker config must be a JSON object.");let e=o;if(e.schemaVersion!==1)throw new Error(`Unsupported remote worker config version: ${String(e.schemaVersion)}.`);if(e.protocolVersion!==p)throw new Error(`Remote worker protocol mismatch: expected ${p}, received ${String(e.protocolVersion)}.`);let r=e.workspace,t=e.functions;if(!r||!t)throw new Error("Remote worker config requires workspace and functions objects.");let n=d(e.awsProfile,"awsProfile");return {schemaVersion:1,region:a(e.region,"region"),...n?{awsProfile:n}:{},...a(e.roleArn,"roleArn",{optional:true})?{roleArn:a(e.roleArn,"roleArn")}:{},...a(e.roleSessionName,"roleSessionName",{optional:true})?{roleSessionName:a(e.roleSessionName,"roleSessionName")}:{},workspace:{bucket:a(r.bucket,"workspace.bucket"),prefix:String(r.prefix??"")},...e.status&&typeof e.status=="object"?{status:{tableName:a(e.status.tableName,"status.tableName")}}:{},functions:{render:a(t.render,"functions.render"),...a(t.asset,"functions.asset",{optional:true})?{asset:a(t.asset,"functions.asset")}:{},rewrite:a(t.rewrite,"functions.rewrite"),"deploy-copy":a(t["deploy-copy"],"functions.deploy-copy")},targets:Array.isArray(e.targets)?e.targets.map((s,i)=>{if(!s||typeof s!="object")throw new Error(`targets[${i}] must be an object.`);let l=s;return {id:a(l.id,`targets[${i}].id`),bucketName:a(l.bucketName,`targets[${i}].bucketName`),prefix:String(l.prefix??""),region:a(l.region,`targets[${i}].region`)}}):[],protocolVersion:p}}async function R(o){let e=g.resolve(o);try{return K(JSON.parse(await readFile(e,"utf8")))}catch(r){throw new Error(`Unable to load remote worker config ${e}: ${r instanceof Error?r.message:String(r)}`,{cause:r})}}var m=class{config;lambda;s3;dynamodb;#e;constructor(e,r={},t={}){this.config=e;let s=w(e.awsProfile)??(e.roleArn?fromTemporaryCredentials({params:{RoleArn:e.roleArn,RoleSessionName:e.roleSessionName??"publisher-exporter-remote-worker"},clientConfig:{region:e.region}}):void 0);this.lambda=new LambdaClient({region:e.region,...s?{credentials:s}:{},...r}),this.s3=new S3Client({region:e.region,...s?{credentials:s}:{}}),this.dynamodb=e.status?new DynamoDBClient({region:e.region,...s?{credentials:s}:{}}):null,this.#e=t;}async#t(e){if(!this.dynamodb||!this.config.status)return null;let t=(await this.dynamodb.send(new GetItemCommand({TableName:this.config.status.tableName,ConsistentRead:true,Key:{jobId:{S:e.jobId},taskId:{S:e.taskId}}}))).Item;if(!t)return null;let n=t.operation?.S,s=t.status?.S;return !n||!["render","asset","rewrite","deploy-copy"].includes(n)||!s||!["running","succeeded","partial","failed"].includes(s)?null:{jobId:t.jobId?.S??e.jobId,taskId:t.taskId?.S??e.taskId,operation:n,status:s,completedItems:Number(t.completedItems?.N??0),failedItems:Number(t.failedItems?.N??0),totalItems:Number(t.totalItems?.N??0),sequence:Number(t.sequence?.N??0),updatedAt:t.updatedAt?.S??new Date(0).toISOString(),requestId:t.requestId?.S??null}}async#r(e,r){let t=this.lambda.send(new InvokeCommand({FunctionName:r,InvocationType:"RequestResponse",Payload:Buffer.from(JSON.stringify(e),"utf8")}));if(e.operation==="health"||!this.dynamodb||!this.#e.onProgress)return await t;let n=false,s=t.finally(()=>{n=true;}),i=Math.max(500,Math.min(3e4,this.#e.progressPollIntervalMs??2e3)),l=-1;for(;!n;){await Promise.race([s.then(()=>{},()=>{}),new Promise(c=>setTimeout(c,i))]);try{let c=await this.#t(e);c&&c.sequence>l&&(l=c.sequence,await this.#e.onProgress(c));}catch(c){await this.#e.onProgressError?.(c instanceof Error?c:new Error(String(c)));}}return await s}async invoke(e){let r=e.operation==="health"?this.config.functions.render:this.config.functions[e.operation];if(!r)throw new Error(`Remote worker configuration does not provide a ${e.operation} function. Redeploy the Lambda workers and reinstall remote-workers.json.`);let t=await this.#r(e,r),n=t.Payload?JSON.parse(new TextDecoder().decode(t.Payload)):null;if(t.FunctionError)throw new Error(`Remote ${e.operation} worker failed (${t.FunctionError}): ${JSON.stringify(n)}`);if(!n||typeof n!="object")throw new Error(`Remote ${e.operation} worker returned no JSON response.`);let s=n;if(s.schemaVersion!==p||s.operation!==e.operation||s.jobId!==e.jobId||s.taskId!==e.taskId)throw new Error(`Remote ${e.operation} worker returned a mismatched response.`);return s}async readResult(e){if(!e.resultKey)throw new Error(`Remote ${e.operation} response does not contain a resultKey.`);let r=u(e.resultKey,this.config.workspace.prefix),t=await this.s3.send(new GetObjectCommand({Bucket:this.config.workspace.bucket,Key:r}));if(!t.Body)throw new Error(`Remote worker result has no body: ${r}`);return JSON.parse(await t.Body.transformToString("utf8"))}async hasWorkspaceObject(e){if(e.bucket!==this.config.workspace.bucket)throw new Error(`Remote worker object bucket mismatch: ${e.bucket}.`);let r=u(e.key,this.config.workspace.prefix);try{let t=await y("S3 workspace object metadata",3e4,({httpOptions:n})=>this.s3.send(new HeadObjectCommand({Bucket:e.bucket,Key:r,...e.versionId?{VersionId:e.versionId}:{}}),n));return e.bytes>0&&t.ContentLength===e.bytes&&t.Metadata?.sha256===e.sha256&&(!e.etag||t.ETag===e.etag)&&(!e.versionId||t.VersionId===e.versionId)}catch(t){if(t.$metadata?.httpStatusCode===404||t instanceof Error&&(t.name==="NotFound"||t.name==="NoSuchKey"))return false;throw t}}async readObject(e){if(e.bucket!==this.config.workspace.bucket)throw new Error(`Remote worker object bucket mismatch: ${e.bucket}.`);let r=u(e.key,this.config.workspace.prefix),t=await this.s3.send(new GetObjectCommand({Bucket:this.config.workspace.bucket,Key:r,...e.versionId?{VersionId:e.versionId}:{}}));if(!t.Body)throw new Error(`Remote worker object has no body: ${r}`);let n=await t.Body.transformToByteArray();if(n.byteLength!==e.bytes)throw new Error(`Remote worker object length mismatch for ${r}: expected ${e.bytes}, received ${n.byteLength}.`);if(f(n)!==e.sha256)throw new Error(`Remote worker object checksum mismatch for ${r}.`);return n}async readObjectText(e){return new TextDecoder("utf8",{fatal:true}).decode(await this.readObject(e))}async health(e){let r=this.config.functions[e];if(!r)throw new Error(`Remote worker configuration does not provide a ${e} function.`);let t=`${e}-${Date.now()}`,n=await this.lambda.send(new InvokeCommand({FunctionName:r,InvocationType:"RequestResponse",Payload:Buffer.from(JSON.stringify({schemaVersion:p,operation:"health",jobId:"health",taskId:t}),"utf8")})),s=n.Payload?JSON.parse(new TextDecoder().decode(n.Payload)):null;if(n.FunctionError||!s||typeof s!="object")throw new Error(`Remote ${e} health check failed: ${JSON.stringify(s)}`);return s}async writeWorkspaceObject(e){let r=u(e.key,this.config.workspace.prefix),t=typeof e.body=="string"?Buffer.from(e.body,"utf8"):e.body,n=f(t),s=await this.s3.send(new PutObjectCommand({Bucket:this.config.workspace.bucket,Key:r,Body:t,ContentType:e.contentType,...e.cacheControl?{CacheControl:e.cacheControl}:{},Metadata:{sha256:n,...e.metadata??{}}}));return {bucket:this.config.workspace.bucket,key:r,sha256:n,bytes:t.byteLength,contentType:e.contentType,...s.ETag?{etag:s.ETag}:{},...s.VersionId?{versionId:s.VersionId}:{}}}async copyWorkspaceObject(e,r){if(e.bucket!==this.config.workspace.bucket)throw new Error(`Remote worker object bucket mismatch: ${e.bucket}.`);let t=u(e.key,this.config.workspace.prefix),n=u(r,this.config.workspace.prefix),s=`${e.bucket}/${t.split("/").map(l=>encodeURIComponent(l)).join("/")}`,i=await this.s3.send(new CopyObjectCommand({Bucket:e.bucket,Key:n,CopySource:s,MetadataDirective:"COPY"}));return {...e,key:n,...i.CopyObjectResult?.ETag?{etag:i.CopyObjectResult.ETag}:{},...i.VersionId?{versionId:i.VersionId}:{}}}};var h="remote-workers.json";function E(o={}){let e=String(o.explicitPath??"").trim();if(e)return g.resolve(e);let r=String(o.runtimeDir??process.env.STATIC_PUBLISHER_RUNTIME_DIR??process.env.WPSUITE_STATIC_PUBLISHER_RUNTIME_DIR??"").trim();return r?g.join(g.resolve(r),h):""}function L(o){let e=o.findIndex(i=>i==="--config"||i==="-c"),r=o.find(i=>i.startsWith("--config=")),t=o.findIndex(i=>i==="--runtime-dir"),n=o.find(i=>i.startsWith("--runtime-dir=")),s=E({explicitPath:r?.slice(9)??(e>=0?o[e+1]:void 0),runtimeDir:n?.slice(14)??(t>=0?o[t+1]:void 0)});if(!s)throw new Error(`Pass --runtime-dir <path>; ${h} must be installed there. --config remains available for diagnostic overrides.`);return g.resolve(s)}async function D(){let o=await R(L(process.argv.slice(2))),e=new m(o),r=["render",...o.functions.asset?["asset"]:[],"rewrite","deploy-copy"],t=await Promise.all(r.map(async n=>({operation:n,response:await e.health(n)})));console.log(JSON.stringify({ok:true,results:t},null,2));}D().catch(o=>{console.error(o instanceof Error?o.message:String(o)),process.exit(1);});