@hyperscale0/create 1.0.0-alpha.1 → 1.0.0-alpha.3

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
@@ -8,6 +8,8 @@ a `hello.mjs` that makes the product's first read call.
8
8
 
9
9
  ## Use
10
10
 
11
+ Request access at https://hyperscale0.ai/request-access.
12
+
11
13
  ```bash
12
14
  export HYPERSCALE_API_KEY=<your Product API key>
13
15
 
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{spawn as R}from"node:child_process";import{existsSync as x,mkdirSync as U,readdirSync as b,writeFileSync as P}from"node:fs";import{basename as L,join as K,resolve as $}from"node:path";const f="https://hyperscale0.ai",v="sandbox",E="hyperscale-app",T=`create-hyperscale [directory] [options]
2
+ import{spawn as b}from"node:child_process";import{existsSync as x,mkdirSync as P,readdirSync as T,writeFileSync as L}from"node:fs";import{basename as K,join as O,resolve as v}from"node:path";const E="https://hyperscale0.ai",S="sandbox",k="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
@@ -8,8 +8,8 @@ your environment, and hello.mjs making the product's first read call.
8
8
 
9
9
  Options:
10
10
  --api-key <key> Product API key (default: $HYPERSCALE_API_KEY)
11
- --base-url <url> API origin (default: $HYPERSCALE_BASE_URL, else ${f})
12
- --environment <name> sandbox or live (default: $HYPERSCALE_ENVIRONMENT, else ${v})
11
+ --base-url <url> API origin (default: $HYPERSCALE_BASE_URL, else ${E})
12
+ --environment <name> sandbox or live (default: $HYPERSCALE_ENVIRONMENT, else ${S})
13
13
  --no-install Write the project without running npm install
14
14
  --json Print a machine-readable summary
15
15
  --version Print the launcher version
@@ -20,11 +20,14 @@ pasting a one-off into a throwaway shell. There are no prompts: every input
20
20
  is a flag or an environment variable, so the launcher runs the same way in a
21
21
  terminal, a script, and an agent.
22
22
 
23
+ Request access at https://hyperscale0.ai/request-access.
24
+
23
25
  Examples:
24
26
  npm create @hyperscale0
25
27
  bunx @hyperscale0/create my-product
26
- create-hyperscale my-product --no-install
27
- `;class i extends Error{}const I=new Set(["--api-key","--base-url","--environment"]),O=new Set(["--help","--json","--no-install","--version"]);function j(e){const t=[],n={};for(let r=0;r<e.length;r+=1){const o=e[r];if(!o.startsWith("--")){t.push(o);continue}if(I.has(o)){const s=e[r+1];if(s===void 0)throw new i(`${o} needs a value`);n[o]=s,r+=1;continue}if(O.has(o)){n[o]=!0;continue}throw new i(`Unknown option: ${o}`)}return{flags:n,positional:t}}function C(e,t){const n=e["--api-key"]??t.HYPERSCALE_API_KEY;if(!n)throw new i("No API key. Set HYPERSCALE_API_KEY, or pass --api-key. Mint a Product API key on the Developers desk.");const r=e["--environment"]??t.HYPERSCALE_ENVIRONMENT??v;if(r!=="sandbox"&&r!=="live")throw new i(`Unknown environment: ${r}. Use sandbox or live.`);const o=(e["--base-url"]??t.HYPERSCALE_BASE_URL??f).replace(/\/+$/,"");return{apiKey:n,baseUrl:o,environment:r}}async function S(e,t){let n;try{n=await fetch(t,{headers:{accept:"application/json",authorization:`Bearer ${e.apiKey}`,"x-hyperscale-environment":e.environment}})}catch(o){throw new i(`Could not reach ${t}: ${o.message}`)}const r=await n.text();return{response:n,text:r}}async function D(e){const{response:t,text:n}=await S(e,`${e.baseUrl}/v1/llms.txt`);if(!t.ok)throw k(t,n);const r=/^# (.+)$/m.exec(n),o=/^## Operations \((\d+)\)$/m.exec(n),s=/^- Auth: \S+ \(secret via (\S+)\)$/m.exec(n);if(!r||!o||!s)throw new Error("The product document is not in the expected format; upgrade the launcher.");const a=s[1];if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(a))throw new Error(`The product document names an invalid auth environment variable (${a}); refusing to scaffold.`);const c=[],m=/^- ([A-Z]+) (\S+) · (\S+) \((\S+); idempotency (\S+)\)$/gm;for(const u of n.matchAll(m))c.push({method:u[1],operationId:u[4],path:u[2]});const h=Number(o[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,N=/^ {2}\d+\. (\S+) \(([^)]+)\)$/gm;for(const u of n.matchAll(N)){const d=u[1];if(!/^[A-Za-z_$][\w$]*$/.test(d))throw new Error(`The product document names an invalid SDK function (${d}); refusing to scaffold.`);const[w,_]=u[2].split("; ");_!=="gap"&&!l.has(w)&&l.set(w,d)}const y=/^- Package: (.+)$/m.exec(n),g=/^- Registry: (\S+)$/m.exec(n);if(!y||!g)throw new i("This Product has no hosted SDK yet. Build it in the composer, then rerun.");return{apiKeyEnvVar:a,operations:c,packageName:y[1].trim(),registryUrl:g[1].replace(/\/+$/,""),sdkFunctionByOperationId:l,title:r[1].trim()}}async function H(e,t){const n=encodeURIComponent(t.packageName).replace("%40","@"),{response:r,text:o}=await S(e,`${t.registryUrl}/${n}`);if(!r.ok)throw k(r,o);let s;try{s=JSON.parse(o)["dist-tags"]?.latest}catch{s=void 0}if(typeof s!="string")throw new Error(`The registry packument for ${t.packageName} names no latest version; upgrade the launcher.`);return s}function k(e,t){let n=t.trim();try{const r=JSON.parse(t);r&&r.error&&typeof r.error.message=="string"&&(n=`${r.error.code}: ${r.error.message}`)}catch{}return new i(`HTTP ${e.status}${n?` \xB7 ${n}`:""}`)}function A(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 F(e,t){const n=`// Generated by create-hyperscale for ${e.title}.
28
+ bunx @hyperscale0/create my-product --no-install
29
+ `;class a extends Error{}const j=new Set(["--api-key","--base-url","--environment"]),D=new Set(["--help","--json","--no-install","--version"]);function H(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(D.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??S;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 A(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:V(await n.text())}}catch(n){throw n instanceof a?n:new a(`Could not reach ${t}: ${n.message}`)}}async function F(e){const{response:t,text:n}=await A(e,`${e.baseUrl}/v1/llms.txt`);if(!t.ok)throw N(t,n);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,_=/^ {2}\d+\. (\S+) \(([^)]+)\)$/gm;for(const u of n.matchAll(_)){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[$,U]=u[2].split("; ");U!=="gap"&&!l.has($)&&l.set($,y)}const g=/^- Package: (.+)$/m.exec(n),w=/^- Registry: (\S+)$/m.exec(n);if(!g||!w)throw new a("This Product has no hosted SDK yet. Build it in the composer, then rerun.");const m=g[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=w[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 V(e){return e.replace(/\p{Cc}/gu,t=>`
30
+ \r`.includes(t)?t:"")}function B(e){try{return new URL(e).origin}catch{return null}}async function J(e,t){const n=encodeURIComponent(t.packageName).replace("%40","@"),{response:r,text:s}=await A(e,`${t.registryUrl}/${n}`);if(!r.ok)throw N(r,s);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 N(e,t){let n=t.trim();try{const r=JSON.parse(t);r&&r.error&&typeof r.error.message=="string"&&(n=`${r.error.code}: ${r.error.message}`)}catch{}return new a(`HTTP ${e.status}${n?` \xB7 ${n}`:""}`)}function R(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 M(e,t){const n=`// Generated by @hyperscale0/create for ${e.title}.
28
31
  // Run with: npm run hello (reads ${e.apiKeyEnvVar} from .env)
29
32
  import { createHyperscaleSdk } from ${JSON.stringify(e.packageName)};
30
33
 
@@ -38,7 +41,14 @@ const client = createHyperscaleSdk({
38
41
  ...(process.env.HYPERSCALE_BASE_URL
39
42
  ? { baseUrl: process.env.HYPERSCALE_BASE_URL }
40
43
  : {}),
41
- });`,r=A(e);return r?`${n}
44
+ });`,r=R(e);if(!r){const s=`SDK client ready for ${e.title}.`,o=`node_modules/${e.packageName}/README.md`;return`${n}
45
+
46
+ console.log(${JSON.stringify(s)});
47
+ console.log(
48
+ "This product has no parameterless read; see the first-call example in",
49
+ ${JSON.stringify(o)},
50
+ );
51
+ `}return`${n}
42
52
 
43
53
  const result = await client[${JSON.stringify(r)}]();
44
54
  if (result.error) {
@@ -46,19 +56,13 @@ if (result.error) {
46
56
  process.exit(1);
47
57
  }
48
58
  console.log(JSON.stringify(result.data, null, 2));
49
- `:`${n}
50
-
51
- console.log("SDK client ready for ${e.title}.");
52
- console.log(
53
- "This product has no parameterless read; see the first-call example in",
54
- "node_modules/${e.packageName}/README.md",
55
- );
56
- `}function V(e){const t=new URL(e.registryUrl),n=t.pathname.endsWith("/")?t.pathname:`${t.pathname}/`;return`@hyperscale:registry=${e.registryUrl}
59
+ `}function z(e){const t=new URL(e.registryUrl),n=t.pathname.endsWith("/")?t.pathname:`${t.pathname}/`;return`@hyperscale:registry=${e.registryUrl}
57
60
  //${t.host}${n}:_authToken=\${${e.apiKeyEnvVar}}
58
- `}function Y(e,t){const n=t.baseUrl===f?"":`HYPERSCALE_BASE_URL=${t.baseUrl}
59
- `;return`${e.apiKeyEnvVar}=${t.apiKey}
60
- ${n}`}function B(e){return L($(e)).toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^[-._]+/,"")||E}function J(e,t,n){return`${JSON.stringify({name:B(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)}
61
- `}function M(e,t){return`# ${e.title}
61
+ ignore-scripts=true
62
+ `}function q(e,t){return`${e.apiKeyEnvVar}=${t.apiKey}
63
+ HYPERSCALE_BASE_URL=${t.baseUrl}
64
+ `}function G(e){return K(v(e)).toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^[-._]+/,"")||k}function W(e,t,n){return`${JSON.stringify({name:G(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)}
65
+ `}function Z(e,t){return`# ${e.title}
62
66
 
63
67
  A minimal project wired to the hosted Hyperscale SDK for this product.
64
68
 
@@ -66,8 +70,8 @@ A minimal project wired to the hosted Hyperscale SDK for this product.
66
70
  registry served when this project was created.
67
71
  - \`.npmrc\` points the \`@hyperscale\` scope at the product's registry and
68
72
  reads the key from \`${e.apiKeyEnvVar}\`.
69
- - \`.env\` carries the key this project was created with. It is gitignored;
70
- rotate it from the Developers desk whenever you need to.
73
+ - \`.env\` carries the key and the API host this project was created with. It
74
+ is gitignored; rotate the key from the Developers desk whenever you need to.
71
75
  - \`hello.mjs\` makes the product's first read call through the SDK.
72
76
 
73
77
  ## Run
@@ -82,12 +86,12 @@ carries the full first-call, retries, pagination, and webhook guidance. The
82
86
  Hyperscale CLI drives the same surface from the shell:
83
87
 
84
88
  \`\`\`bash
85
- bunx @hyperscale/cli ops list
89
+ bunx @hyperscale0/cli ops list
86
90
  \`\`\`
87
91
 
88
92
  Needs Node 20.6 or newer (\`--env-file\`).
89
- `}function z(e,t,n,r){return[{path:".env",contents:Y(t,n)},{path:".gitignore",contents:`node_modules/
93
+ `}function Q(e,t,n,r){return[{path:".env",contents:q(t,n)},{path:".gitignore",contents:`node_modules/
90
94
  .env
91
- `},{path:".npmrc",contents:V(t)},{path:"README.md",contents:M(t,r)},{path:"hello.mjs",contents:F(t,n.environment)},{path:"package.json",contents:J(e,t,r)}]}function G(e,t){const n=$(e);if(x(n)&&b(n).length>0)throw new i(`${e} already exists and is not empty. Pick a new directory.`);U(n,{recursive:!0});for(const r of t)P(K(n,r.path),r.contents);return n}function W(e,t,n){return new Promise((r,o)=>{const s=R("npm",["install","--no-audit","--no-fund"],{cwd:e,env:{...process.env,[t.apiKeyEnvVar]:n.apiKey},stdio:["ignore",2,2]});s.on("error",a=>{o(new i(`npm install could not start: ${a.message}. The project is written; fix the cause and run npm install in it.`))}),s.on("exit",a=>{if(a===0){r();return}o(new i(`npm install failed with exit code ${a}. The project is written; fix the cause and run npm install in it.`))})})}function p(e){process.stdout.write(`${e}
92
- `)}async function Z(){const{readFileSync:e}=await import("node:fs");return JSON.parse(e(new URL("./package.json",import.meta.url),"utf8")).version}async function q(e,t){const{flags:n,positional:r}=j(e);if(n["--version"])return p(await Z()),0;if(n["--help"])return process.stdout.write(T),0;if(r.length>1)throw new i("At most one directory argument is allowed.");const o=r[0]??E,s=C(n,t),a=await D(s),c=await H(s,a),m=G(o,z(o,a,s,c)),h=!n["--no-install"];h&&await W(m,a,s);const l=A(a);return n["--json"]?(p(JSON.stringify({baseUrl:s.baseUrl,directory:m,environment:s.environment,helloOperation:l??null,installed:h,packageName:a.packageName,product:a.title,version:c},null,2)),0):(p(`Created ${o} for ${a.title}.`),p(""),p(` ${a.packageName}@${c} (${s.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)}q(process.argv.slice(2),process.env).then(e=>{process.exitCode=e},e=>{e instanceof i?process.stderr.write(`${e.message}
95
+ `},{path:".npmrc",contents:z(t)},{path:"README.md",contents:Z(t,r)},{path:"hello.mjs",contents:M(t,n.environment)},{path:"package.json",contents:W(e,t,r)}]}function X(e,t){const n=v(e);if(x(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(O(n,r.path),r.contents);return n}function ee(e,t,n){return new Promise((r,s)=>{const o=b("npm",["install","--no-audit","--no-fund","--ignore-scripts"],{cwd:e,env:{...process.env,[t.apiKeyEnvVar]:n.apiKey},stdio:["ignore",2,2]});o.on("error",i=>{s(new a(`npm install could not start: ${i.message}. The project is written; fix the cause and run npm install in it.`))}),o.on("exit",i=>{if(i===0){r();return}s(new a(`npm install failed with exit code ${i}. The project is written; fix the cause and run npm install in it.`))})})}function p(e){process.stdout.write(`${e}
96
+ `)}async function ne(){const{readFileSync:e}=await import("node:fs");return JSON.parse(e(new URL("./package.json",import.meta.url),"utf8")).version}async function te(e,t){const{flags:n,positional:r}=H(e);if(n["--version"])return p(await ne()),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]??k,o=Y(n,t),i=await F(o),c=await J(o,i),d=X(s,Q(s,i,o,c)),h=!n["--no-install"];h&&await ee(d,i,o);const l=R(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)}te(process.argv.slice(2),process.env).then(e=>{process.exitCode=e},e=>{e instanceof a?process.stderr.write(`${e.message}
93
97
  `):console.error(e),process.exitCode=1});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperscale0/create",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.3",
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",