@hyperscale0/create 1.0.0-alpha.3 → 1.0.0-alpha.5
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 +3 -2
- package/create-hyperscale.js +18 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,8 @@ The Hyperscale project launcher: `npm create @hyperscale0` scaffolds a
|
|
|
4
4
|
minimal project wired to your Product's hosted TypeScript SDK. It pins the
|
|
5
5
|
SDK version the registry serves today, writes the project `.npmrc` for the
|
|
6
6
|
authenticated registry, puts your key in a gitignored `.env`, and generates
|
|
7
|
-
a `hello.mjs` that
|
|
7
|
+
a `hello.mjs` that calls the selected parameterless SDK read or points to the
|
|
8
|
+
SDK's tailored first-call example.
|
|
8
9
|
|
|
9
10
|
## Use
|
|
10
11
|
|
|
@@ -21,4 +22,4 @@ bunx @hyperscale0/create my-product
|
|
|
21
22
|
There are no prompts: every input is a flag or an environment variable.
|
|
22
23
|
Point it at another host with `--base-url`, and at the live plane with
|
|
23
24
|
`--environment live`. Run `bunx @hyperscale0/create --help` for the full
|
|
24
|
-
option list.
|
|
25
|
+
option list. Add `--json` for machine-readable success and failure output.
|
package/create-hyperscale.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{spawn as
|
|
2
|
+
import{spawn as U}from"node:child_process";import{existsSync as K,mkdirSync as P,readdirSync as T,writeFileSync as L}from"node:fs";import{basename as O,join as D,resolve as S}from"node:path";const E="https://hyperscale0.ai",k="sandbox",A="hyperscale-app",I=3e4,C=`bunx @hyperscale0/create [directory] [options]
|
|
3
3
|
|
|
4
4
|
Scaffolds a minimal project wired to your Product's hosted TypeScript SDK:
|
|
5
5
|
a package.json pinned to the SDK version the registry serves today, a
|
|
6
6
|
project .npmrc for the authenticated registry, a .env carrying the key from
|
|
7
|
-
your environment, and hello.mjs
|
|
7
|
+
your environment, and hello.mjs calling the selected parameterless SDK read or
|
|
8
|
+
pointing to the SDK's tailored first-call example.
|
|
8
9
|
|
|
9
10
|
Options:
|
|
10
11
|
--api-key <key> Product API key (default: $HYPERSCALE_API_KEY)
|
|
11
12
|
--base-url <url> API origin (default: $HYPERSCALE_BASE_URL, else ${E})
|
|
12
|
-
--environment <name> sandbox or live (default: $HYPERSCALE_ENVIRONMENT, else ${
|
|
13
|
+
--environment <name> sandbox or live (default: $HYPERSCALE_ENVIRONMENT, else ${k})
|
|
13
14
|
--no-install Write the project without running npm install
|
|
14
15
|
--json Print a machine-readable summary
|
|
15
16
|
--version Print the launcher version
|
|
@@ -26,8 +27,8 @@ Examples:
|
|
|
26
27
|
npm create @hyperscale0
|
|
27
28
|
bunx @hyperscale0/create my-product
|
|
28
29
|
bunx @hyperscale0/create my-product --no-install
|
|
29
|
-
`;class a extends Error{}const j=new Set(["--api-key","--base-url","--environment"]),
|
|
30
|
-
\r`.includes(t)?t:"")}function B(e){try{return new URL(e).origin}catch{return null}}async function
|
|
30
|
+
`;class a extends Error{}const j=new Set(["--api-key","--base-url","--environment"]),H=new Set(["--help","--json","--no-install","--version"]);function F(e){const t=[],n={};for(let r=0;r<e.length;r+=1){const s=e[r];if(!s.startsWith("--")){t.push(s);continue}if(j.has(s)){const o=e[r+1];if(o===void 0)throw new a(`${s} needs a value`);n[s]=o,r+=1;continue}if(H.has(s)){n[s]=!0;continue}throw new a(`Unknown option: ${s}`)}return{flags:n,positional:t}}function Y(e,t){const n=e["--api-key"]??t.HYPERSCALE_API_KEY;if(!n)throw new a("No API key. Set HYPERSCALE_API_KEY, or pass --api-key. Request access at https://hyperscale0.ai/request-access.");const r=e["--environment"]??t.HYPERSCALE_ENVIRONMENT??k;if(r!=="sandbox"&&r!=="live")throw new a(`Unknown environment: ${r}. Use sandbox or live.`);const s=(e["--base-url"]??t.HYPERSCALE_BASE_URL??E).replace(/\/+$/,"");return{apiKey:n,baseUrl:s,environment:r}}async function N(e,t){try{const n=await fetch(t,{headers:{accept:"application/json",authorization:`Bearer ${e.apiKey}`,"x-hyperscale-environment":e.environment},signal:AbortSignal.timeout(I),redirect:"manual"});if(n.status>=300&&n.status<400)throw new a(`${t} redirected, so the key was not sent on. Point --base-url at the origin the API answers on; the usual cause is http:// where it serves https://.`);return{response:n,text:J(await n.text())}}catch(n){throw n instanceof a?n:new a(`Could not reach ${t}: ${n.message}`)}}async function V(e){const{response:t,text:n}=await N(e,`${e.baseUrl}/v1/llms.txt`);if(!t.ok)throw R(t,n,[e.apiKey]);const r=/^# (.+)$/m.exec(n),s=/^## Operations \((\d+)\)$/m.exec(n),o=/^- Auth: \S+ \(secret via (\S+)\)$/m.exec(n);if(!r||!s||!o)throw new Error("The product document is not in the expected format; upgrade the launcher.");const i=o[1];if(!/^HYPERSCALE_[A-Z0-9_]*$/.test(i))throw new a(`The product document names an invalid auth environment variable (${i}); refusing to scaffold.`);const c=[],d=/^- ([A-Z]+) (\S+) · (\S+) \((\S+); idempotency (\S+)\)$/gm;for(const u of n.matchAll(d))c.push({method:u[1],operationId:u[4],path:u[2]});const h=Number(s[1]);if(c.length!==h)throw new Error(`The product document declares ${h} operations but ${c.length} parsed; upgrade the launcher.`);const l=new Map,x=/^ {2}\d+\. (\S+) \(([^)]+)\)$/gm;for(const u of n.matchAll(x)){const y=u[1];if(!/^[A-Za-z_$][\w$]*$/.test(y))throw new a(`The product document names an invalid SDK function (${y}); refusing to scaffold.`);const[v,b]=u[2].split("; ");b!=="gap"&&!l.has(v)&&l.set(v,y)}const w=/^- Package: (.+)$/m.exec(n),$=/^- Registry: (\S+)$/m.exec(n);if(!w||!$)throw new a("This Product has no hosted SDK yet. Build it in the composer, then rerun.");const m=w[1].trim();if(!/^@hyperscale\/[a-z0-9][a-z0-9._-]*$/.test(m))throw new a(`The product document names an invalid SDK package (${m}); refusing to scaffold.`);const f=$[1].replace(/\/+$/,"");if(B(f)!==new URL(e.baseUrl).origin)throw new a(`The product document names a registry on another origin (${f}); refusing to scaffold.`);return{apiKeyEnvVar:i,operations:c,packageName:m,registryUrl:f,sdkFunctionByOperationId:l,title:r[1].trim()}}function J(e){return e.replace(/\p{Cc}/gu,t=>`
|
|
31
|
+
\r`.includes(t)?t:"")}function B(e){try{return new URL(e).origin}catch{return null}}async function M(e,t){const n=encodeURIComponent(t.packageName).replace("%40","@"),{response:r,text:s}=await N(e,`${t.registryUrl}/${n}`);if(!r.ok)throw R(r,s,[e.apiKey]);let o;try{o=JSON.parse(s)["dist-tags"]?.latest}catch{o=void 0}if(typeof o!="string")throw new a(`The registry packument for ${t.packageName} names no latest version; upgrade the launcher.`);if(!/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)*$/.test(o))throw new a(`The registry packument for ${t.packageName} names ${o} as its latest version, which is not a version; refusing to scaffold.`);return o}function _(e,t){let n=e;for(const r of t)typeof r=="string"&&r.length>0&&(n=n.replaceAll(r,"[redacted]"));return n}function R(e,t,n=[]){let r=_(t.trim(),n);try{const s=JSON.parse(t);s&&s.error&&typeof s.error.message=="string"&&(r=_(`${s.error.code}: ${s.error.message}`,n))}catch{}return new a(`HTTP ${e.status}${r?` \xB7 ${r}`:""}`)}function g(e){const t=e.operations.find(n=>n.method==="GET"&&!n.path.includes("{")&&e.sdkFunctionByOperationId.has(n.operationId));if(t)return e.sdkFunctionByOperationId.get(t.operationId)}function z(e,t){const n=`// Generated by @hyperscale0/create for ${e.title}.
|
|
31
32
|
// Run with: npm run hello (reads ${e.apiKeyEnvVar} from .env)
|
|
32
33
|
import { createHyperscaleSdk } from ${JSON.stringify(e.packageName)};
|
|
33
34
|
|
|
@@ -41,11 +42,11 @@ const client = createHyperscaleSdk({
|
|
|
41
42
|
...(process.env.HYPERSCALE_BASE_URL
|
|
42
43
|
? { baseUrl: process.env.HYPERSCALE_BASE_URL }
|
|
43
44
|
: {}),
|
|
44
|
-
});`,r=
|
|
45
|
+
});`,r=g(e);if(!r){const s=`SDK client ready for ${e.title}.`,o=`node_modules/${e.packageName}/README.md`;return`${n}
|
|
45
46
|
|
|
46
47
|
console.log(${JSON.stringify(s)});
|
|
47
48
|
console.log(
|
|
48
|
-
"
|
|
49
|
+
"No callable parameterless SDK read was selected; see the first-call example in",
|
|
49
50
|
${JSON.stringify(o)},
|
|
50
51
|
);
|
|
51
52
|
`}return`${n}
|
|
@@ -56,13 +57,13 @@ if (result.error) {
|
|
|
56
57
|
process.exit(1);
|
|
57
58
|
}
|
|
58
59
|
console.log(JSON.stringify(result.data, null, 2));
|
|
59
|
-
`}function
|
|
60
|
+
`}function q(e){const t=new URL(e.registryUrl),n=t.pathname.endsWith("/")?t.pathname:`${t.pathname}/`;return`@hyperscale:registry=${e.registryUrl}
|
|
60
61
|
//${t.host}${n}:_authToken=\${${e.apiKeyEnvVar}}
|
|
61
62
|
ignore-scripts=true
|
|
62
|
-
`}function
|
|
63
|
+
`}function G(e,t){return`${e.apiKeyEnvVar}=${t.apiKey}
|
|
63
64
|
HYPERSCALE_BASE_URL=${t.baseUrl}
|
|
64
|
-
`}function
|
|
65
|
-
`}function
|
|
65
|
+
`}function W(e){return O(S(e)).toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^[-._]+/,"")||A}function Z(e,t,n){return`${JSON.stringify({name:W(e),version:"0.0.0",private:!0,type:"module",scripts:{hello:"node --env-file=.env hello.mjs"},engines:{node:">=20.6"},dependencies:{[t.packageName]:n}},null,2)}
|
|
66
|
+
`}function Q(e,t){const n=g(e)?"makes the product's first read call through the SDK":"constructs the SDK client and points to its tailored first-call example";return`# ${e.title}
|
|
66
67
|
|
|
67
68
|
A minimal project wired to the hosted Hyperscale SDK for this product.
|
|
68
69
|
|
|
@@ -72,7 +73,7 @@ A minimal project wired to the hosted Hyperscale SDK for this product.
|
|
|
72
73
|
reads the key from \`${e.apiKeyEnvVar}\`.
|
|
73
74
|
- \`.env\` carries the key and the API host this project was created with. It
|
|
74
75
|
is gitignored; rotate the key from the Developers desk whenever you need to.
|
|
75
|
-
- \`hello.mjs\`
|
|
76
|
+
- \`hello.mjs\` ${n}.
|
|
76
77
|
|
|
77
78
|
## Run
|
|
78
79
|
|
|
@@ -90,8 +91,9 @@ bunx @hyperscale0/cli ops list
|
|
|
90
91
|
\`\`\`
|
|
91
92
|
|
|
92
93
|
Needs Node 20.6 or newer (\`--env-file\`).
|
|
93
|
-
`}function
|
|
94
|
+
`}function X(e,t,n,r){return[{path:".gitignore",contents:`node_modules/
|
|
94
95
|
.env
|
|
95
|
-
`},{path:".npmrc",contents:
|
|
96
|
-
`)}async function
|
|
97
|
-
`):console.error(e)
|
|
96
|
+
`},{path:".env",contents:G(t,n),mode:384},{path:".npmrc",contents:q(t)},{path:"README.md",contents:Q(t,r)},{path:"hello.mjs",contents:z(t,n.environment)},{path:"package.json",contents:Z(e,t,r)}]}function ee(e,t){const n=S(e);if(K(n)&&T(n).length>0)throw new a(`${e} already exists and is not empty. Pick a new directory.`);P(n,{recursive:!0});for(const r of t)L(D(n,r.path),r.contents,r.mode?{mode:r.mode}:{});return n}function ne(e,t,n,r){return new Promise((s,o)=>{const i=U("npm",["install","--no-audit","--no-fund","--ignore-scripts","--registry",t.registryUrl,"--prefer-online","--offline=false"],{cwd:e,env:{...process.env,[t.apiKeyEnvVar]:n.apiKey},stdio:r?["ignore","ignore","ignore"]:["ignore",2,2]});i.on("error",c=>{o(new a(`npm install could not start: ${c.message}. The project is written; fix the cause and run npm install in it.`))}),i.on("exit",c=>{if(c===0){s();return}o(new a(`npm install failed with exit code ${c}. The project is written; fix the cause and run npm install in it.`))})})}function p(e){process.stdout.write(`${e}
|
|
97
|
+
`)}async function te(){const{readFileSync:e}=await import("node:fs");return JSON.parse(e(new URL("./package.json",import.meta.url),"utf8")).version}async function re(e,t){const{flags:n,positional:r}=F(e);if(n["--version"])return p(await te()),0;if(n["--help"])return process.stdout.write(C),0;if(r.length>1)throw new a("At most one directory argument is allowed.");const s=r[0]??A,o=Y(n,t),i=await V(o),c=await M(o,i),d=ee(s,X(s,i,o,c)),h=!n["--no-install"];h&&await ne(d,i,o,n["--json"]);const l=g(i);return n["--json"]?(p(JSON.stringify({baseUrl:o.baseUrl,directory:d,environment:o.environment,helloOperation:l??null,installed:h,packageName:i.packageName,product:i.title,version:c},null,2)),0):(p(`Created ${s} for ${i.title}.`),p(""),p(` ${i.packageName}@${c} (${o.environment})`),h||p(" npm install"),p(l?` npm run hello calls ${l}`:" npm run hello constructs the client; see README.md for the first call"),0)}function se(e,t){if(!t.includes("--json")){e instanceof a?process.stderr.write(`${e.message}
|
|
98
|
+
`):console.error(e);return}const n=e instanceof a;process.stderr.write(`${JSON.stringify({error:{code:n?"user_error":"internal_error",message:n?e.message:"The launcher failed unexpectedly.",fix:n?'Follow the message, or run "bunx @hyperscale0/create --help" for option usage.':"Report the failure without including credentials."}})}
|
|
99
|
+
`)}re(process.argv.slice(2),process.env).then(e=>{process.exitCode=e},e=>{se(e,process.argv.slice(2)),process.exitCode=1});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperscale0/create",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.5",
|
|
4
4
|
"description": "The Hyperscale project launcher: scaffold a minimal project wired to one Product's hosted SDK.",
|
|
5
5
|
"license": "LicenseRef-Hyperscale-Proprietary",
|
|
6
6
|
"author": "Hyperscale LLC",
|