@cognite/cli 1.0.0 → 1.1.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/README.md +1 -1
- package/_templates/app/new/prompt.js +3 -3
- package/_templates/app/new/root/package.json.ejs.t +2 -2
- package/_vendor/spec-kit/README.md +8 -8
- package/dist/chunk-VJMFH4MH.js +9 -0
- package/dist/cli/cli.js +64 -41
- package/dist/deploy/index.d.ts +1 -5
- package/dist/deploy/index.js +1 -9
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -1
- package/package.json +2 -13
- package/dist/auth/index.d.ts +0 -51
- package/dist/auth/index.js +0 -1
- package/dist/chunk-EI7MMDWY.js +0 -1
- package/dist/chunk-QGJ3VKXY.js +0 -1
- package/dist/vite/index.d.ts +0 -1
- package/dist/vite/index.js +0 -1
package/README.md
CHANGED
|
@@ -83,7 +83,7 @@ To test against your own app instead of the fixture:
|
|
|
83
83
|
|
|
84
84
|
```bash
|
|
85
85
|
cd apps/my-app
|
|
86
|
-
COGNITE_TOKEN=test-token COGNITE_BASE_URL=http://localhost:9090 pnpm exec
|
|
86
|
+
COGNITE_TOKEN=test-token COGNITE_BASE_URL=http://localhost:9090 pnpm exec cognite apps deploy --skip-build
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
#### Simulating error scenarios
|
|
@@ -3,7 +3,7 @@ export default [
|
|
|
3
3
|
type: 'input',
|
|
4
4
|
name: 'name',
|
|
5
5
|
message: 'What is the app name? (use kebab-case, e.g., my-awesome-app)',
|
|
6
|
-
initial: 'my-
|
|
6
|
+
initial: 'my-flows-app',
|
|
7
7
|
validate: (input) =>
|
|
8
8
|
/^[a-z][a-z0-9-]*$/.test(input)
|
|
9
9
|
? true
|
|
@@ -13,13 +13,13 @@ export default [
|
|
|
13
13
|
type: 'input',
|
|
14
14
|
name: 'displayName',
|
|
15
15
|
message: 'What is the display name? (e.g., My Awesome App)',
|
|
16
|
-
initial: 'My
|
|
16
|
+
initial: 'My Flows app',
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
type: 'input',
|
|
20
20
|
name: 'description',
|
|
21
21
|
message: 'What is the app description?',
|
|
22
|
-
initial: 'A
|
|
22
|
+
initial: 'A Flows application',
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
25
|
type: 'input',
|
|
@@ -20,8 +20,8 @@ to: '<%= useCurrentDir ? "" : ((directoryName || name) + "/") %>package.json'
|
|
|
20
20
|
"test:ui": "vitest --ui",
|
|
21
21
|
"lint": "eslint . --ext .js,.mjs,.cjs,.ts,.tsx",
|
|
22
22
|
"lint:fix": "eslint . --fix --ext .js,.mjs,.cjs,.ts,.tsx",
|
|
23
|
-
"deploy": "npx @cognite/cli@latest apps deploy --interactive
|
|
24
|
-
"
|
|
23
|
+
"deploy": "npx @cognite/cli@latest apps deploy --interactive",
|
|
24
|
+
"activate": "npx @cognite/cli@latest apps activate --interactive"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@cognite/aura": "^0.1.7",
|
|
@@ -4,25 +4,25 @@ Selected, generated files from [github/spec-kit](https://github.com/github/spec-
|
|
|
4
4
|
|
|
5
5
|
## Why this exists
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Flows app authors should not need Python, `uv`, or network access just because they pass `cognite create --spec-kit`.
|
|
8
8
|
|
|
9
|
-
Instead,
|
|
9
|
+
Instead, Flows builder app maintainers refresh spec-kit inside this monorepo, commit the selected generated files here, and let `cognite create` copy them into new apps. That keeps end-user scaffolding fast and JS/TS-only while still letting us track upstream spec-kit intentionally.
|
|
10
10
|
|
|
11
11
|
## Maintainer-only refresh
|
|
12
12
|
|
|
13
|
-
The refresh script is for
|
|
13
|
+
The refresh script is for Flows app maintainers only:
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
16
|
pnpm --filter @cognite/cli refresh-spec-kit <tag>
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
It requires `uv` locally, which provides `uvx`. That is acceptable for maintainers; it must not become a requirement for generated
|
|
19
|
+
It requires `uv` locally, which provides `uvx`. That is acceptable for maintainers; it must not become a requirement for generated Flows apps.
|
|
20
20
|
|
|
21
21
|
The script runs spec-kit's own `specify init` for the requested tag, stages the selected output in a temporary directory, and swaps it into `_vendor/spec-kit` only after all copies succeed.
|
|
22
22
|
|
|
23
23
|
## What we vendor
|
|
24
24
|
|
|
25
|
-
We vendor the parts
|
|
25
|
+
We vendor the parts Flows apps uses:
|
|
26
26
|
|
|
27
27
|
- generated `commands/speckit.{specify,clarify,plan,tasks,implement,analyze,checklist}.md`
|
|
28
28
|
- `templates/{spec,plan,tasks,checklist}-template.md`
|
|
@@ -30,10 +30,10 @@ We vendor the parts Dune uses:
|
|
|
30
30
|
|
|
31
31
|
Deliberately excluded:
|
|
32
32
|
|
|
33
|
-
- spec-kit's `AGENTS.md`, constitution command, and constitution template, because
|
|
33
|
+
- spec-kit's `AGENTS.md`, constitution command, and constitution template, because Flows apps uses the app's `AGENTS.md` as the constitution
|
|
34
34
|
- integration metadata/workflows generated by `specify init`
|
|
35
35
|
- optional commands such as taskstoissues
|
|
36
|
-
- PowerShell scripts, until
|
|
36
|
+
- PowerShell scripts, until Flows apps chooses to support a PowerShell command set
|
|
37
37
|
- spec-kit's Python CLI, tests, and docs
|
|
38
38
|
|
|
39
|
-
**Cadence:** refresh at least once per
|
|
39
|
+
**Cadence:** refresh at least once per cognite CLI minor release, sooner if upstream ships a fix we depend on.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var W=Object.defineProperty;var s=(e,t)=>W(e,"name",{value:t,configurable:!0});import Y from"fs";import gt from"path";var N="https://docs.cognite.com/cdf/access/";function m(e){return e!==null&&typeof e=="object"}s(m,"isRecord");function S(e){return e instanceof Error&&"status"in e&&typeof e.status=="number"}s(S,"isHttpError");function Z(e){switch(e){case 401:return`Your credentials are invalid or expired. Check your client ID and secret.
|
|
2
|
+
See: ${N}`;case 403:return`You don't have the required CDF capabilities. Please contact your CDF admin.
|
|
3
|
+
See: ${N}`;default:return}}s(Z,"httpStatusHint");function w(e){let t=e instanceof Error?e:new Error(String(e));if(!S(t))return null;let n=Z(t.status);return n?Object.assign(new Error(`${t.message}
|
|
4
|
+
${n}`),{cause:t}):null}s(w,"enrichedHttpError");function X(e){if(!m(e))return null;let t=e.missing;if(Array.isArray(t))return t;let n=e.data;if(m(n)){let r=n.error;if(m(r)&&Array.isArray(r.missing))return r.missing;if(Array.isArray(n.missing))return n.missing}return null}s(X,"findMissingArray");function Q(e,t){if(!S(e)||e.status!==400)return!1;let n=X(e);return n?n.some(r=>m(r)&&typeof r.externalId=="string"&&t.includes(r.externalId)):!1}s(Q,"isMissingExternalIdError");function v(e,t){return S(e)&&e.status===404||Q(e,t)}s(v,"isNotFoundError");var M=["DRAFT","PUBLISHED","DEPRECATED","ARCHIVED"],J=["ACTIVE","PREVIEW"],I=class I extends Error{constructor(t,n){super(`Version ${n} of app ${t} not found`),this.name="AppVersionNotFoundError",this.appExternalId=t,this.version=n}};s(I,"AppVersionNotFoundError");var C=I;function q(e,t){return e.includes(t)}s(q,"includesValue");function tt(e){return q(M,e)}s(tt,"isAppVersionLifecycleState");function et(e){return q(J,e)}s(et,"isAppVersionAlias");function nt(e){return typeof e.version=="string"&&tt(e.lifecycleState)&&typeof e.entrypoint=="string"&&typeof e.createdTime=="number"&&typeof e.createdBy=="string"&&typeof e.appExternalId=="string"&&(e.alias===void 0||et(e.alias))&&(e.comment===void 0||typeof e.comment=="string")}s(nt,"isAppVersion");function H(e){if(!m(e))throw new Error("Invalid version response: not an object");if(!nt(e))throw new Error("Invalid version response: missing or malformed fields");return e}s(H,"parseAppVersion");var T=class T{constructor(t){this.client=t}get appsBasePath(){return`/api/v1/projects/${encodeURIComponent(this.client.project)}/apphosting/apps`}async createApp(t,n,r){try{await this.client.post(this.appsBasePath,{data:{items:[{externalId:t,name:n,description:r}]}})}catch(o){throw w(o)??o}}async uploadVersion(t,n,r,o,i="index.html"){console.log(`\u{1F4E4} Uploading version ${n}...`);let a=new FormData;a.append("file",new Blob([new Uint8Array(r)]),o),a.append("version",n),a.append("entryPath",i);let l=encodeURIComponent(t),c=`${this.appsBasePath}/${l}/versions`,p=await this.client.authenticate(),g=`${this.client.getBaseUrl()}${c}`,u=new AbortController,G=setTimeout(()=>u.abort(),300*1e3),y;try{y=await fetch(g,{method:"POST",headers:{Authorization:`Bearer ${p}`},body:a,signal:u.signal})}catch(f){throw f instanceof Error&&f.name==="AbortError"?new Error("Upload timed out after 5 minutes"):f}finally{clearTimeout(G)}if(!y.ok){let f=await y.text(),k=f;try{let $=JSON.parse(f);if(m($)){let A=$.error;if(typeof A=="string")k=A;else if(m(A)){let E=A.message,F=A.code;k=typeof E=="string"?E:F!=null?`Unknown error (code: ${F})`:f}else{let E=$.message;k=typeof E=="string"?E:f}}}catch{}let j=y.headers.get("x-request-id"),K=j?` | X-Request-ID: ${j}`:"",B=Object.assign(new Error(`Upload failed: ${y.status} \u2014 ${k}${K}`),{status:y.status});throw w(B)??B}console.log(`\u2705 Version ${n} uploaded`)}async getVersion(t,n){let r=encodeURIComponent(t),o=encodeURIComponent(n),i=`${this.appsBasePath}/${r}/versions/${o}`;try{let a=await this.client.get(i);return H(a.data)}catch(a){throw v(a,[t,n])?new C(t,n):w(a)??a}}async getActiveVersion(t){let n=encodeURIComponent(t),r=`${this.appsBasePath}/${n}/active`;try{let o=await this.client.get(r);return H(o.data)}catch(o){if(v(o,[t]))return null;throw w(o)??o}}async updateVersions(t,n){let r=encodeURIComponent(t),o=`${this.appsBasePath}/${r}/versions/update`;try{await this.client.post(o,{data:{items:n}})}catch(i){throw w(i)??i}}};s(T,"AppHostingApi");var x=T;var b=class b{constructor(t){this.api=new x(t)}getVersion(t,n){return this.api.getVersion(t,n)}uploadVersion(t,n,r,o,i){return this.api.uploadVersion(t,n,r,o,i)}async ensureApp(t,n,r){console.log("\u{1F50D} Ensuring app exists...");try{await this.api.createApp(t,n,r),console.log(`\u2705 App '${t}' created`)}catch(o){if(S(o)&&o.status===409){console.log(`\u2705 App '${t}' already exists`);return}throw o}}async publishVersion(t,n){await this.api.updateVersions(t,[{version:n,update:{lifecycleState:{set:"PUBLISHED"}}}])}async publishAndActivate(t,n){console.log(`\u{1F680} Publishing and activating version ${n}...`),await this.api.updateVersions(t,[{version:n,update:{lifecycleState:{set:"PUBLISHED"},alias:{set:"ACTIVE"}}}]),console.log(`\u2705 Version ${n} is now PUBLISHED and ACTIVE`)}async activateVersion(t,n){let r=null;try{r=await this.api.getActiveVersion(t)}catch{r=null}let o=r&&r.version!==n?r.version:void 0;return await this.api.updateVersions(t,[{version:n,update:{alias:{set:"ACTIVE"}}}]),{supersededVersion:o}}async deploy(t,n,r,o,i,a,l=!1){console.log(`
|
|
5
|
+
\u{1F680} Deploying application via App Hosting API...
|
|
6
|
+
`);try{await this.ensureApp(t,n,r),await this.uploadVersion(t,o,i,a),l&&await this.publishAndActivate(t,o),console.log(`
|
|
7
|
+
\u2705 Deployment successful!`)}catch(c){let p=c instanceof Error?c.message:String(c);throw Object.assign(new Error(`Deployment failed: ${p}`),{cause:c})}}};s(b,"AppHostingClient");var P=b;import h from"fs";import d from"path";import{parseAndValidateManifestConfig as rt}from"@cognite/app-sdk/vite";import{BlobReader as ot,Uint8ArrayWriter as st,ZipWriter as it}from"@zip.js/zip.js";var R="package.json",D="package-lock.json",z="manifest.json",_=".cognite",L=class L{constructor(t="dist"){this.distPath=d.isAbsolute(t)?t:d.join(process.cwd(),t),this.appRoot=d.dirname(this.distPath)}validateBuildDirectory(){if(!h.existsSync(this.distPath))throw new Error(`Build directory "${this.distPath}" not found. Run build first.`);let t=d.join(this.appRoot,R);if(!h.existsSync(t))throw new Error(`"${t}" not found. It is required for deployment.`);let n=d.join(this.appRoot,D);if(!h.existsSync(n))throw new Error(`"${n}" not found. It is required for deployment.`)}async createZip(t="app.zip",n=!1){this.validateBuildDirectory(),console.log("\u{1F4E6} Packaging application...");let r=new it(new st,{level:9}),o=s(async(c,p)=>{await r.add(p,new ot(await h.openAsBlob(c))),n&&console.log(` \u{1F4C4} ${p}`)},"addFile"),i=s(async c=>{let p=await h.promises.readdir(c,{withFileTypes:!0});for(let g of p){let u=d.join(c,g.name);g.isDirectory()?await i(u):await o(u,d.relative(this.distPath,u).replace(/\\/g,"/"))}},"addDir"),a;try{await i(this.distPath);let c=d.join(this.appRoot,R);await o(c,d.posix.join(_,R));let p=d.join(this.appRoot,z);if(h.existsSync(p)){let u=h.readFileSync(p,"utf-8");rt(u,p),await o(p,d.posix.join(_,z))}let g=d.join(this.appRoot,D);await o(g,d.posix.join(_,D)),a=await r.close()}catch(c){let p=c instanceof Error?c.message:String(c);throw new Error(`Failed to create zip: ${p}`)}await h.promises.writeFile(t,a);let l=(a.byteLength/1024/1024).toFixed(2);return console.log(`\u2705 App packaged: ${t} (${l} MB)`),t}};s(L,"ApplicationPackager");var V=L;import{CogniteClient as ut}from"@cognite/sdk";var at=s(()=>{let e=process.env.DEPLOYMENT_SECRETS;if(!e)return{};try{let t=JSON.parse(e),n={};for(let[r,o]of Object.entries(t))if(typeof o=="string"){let i=r.toLowerCase().replace(/_/g,"-");n[i]=o}return n}catch(t){return console.error("Error parsing DEPLOYMENT_SECRETS:",t),{}}},"loadSecretsFromEnv"),ct=s(e=>{let t;if(process.env.DEPLOYMENT_SECRET&&(t=process.env.DEPLOYMENT_SECRET),t||(t=at()[e]),t||(t=process.env[e]),!t)throw new Error(`Secret not found in environment: ${e}`);return t},"getSecretFromEnv"),pt=s(e=>{if(!e)return"";try{return new URL(e).hostname.replace(/\.cognitedata\.com$/,"")}catch{let t=e.replace(/^https?:\/\//,"");return t=t.split("/")[0],t=t.split(":")[0],t=t.replace(/\.cognitedata\.com$/,""),t}},"extractClusterFromUrl"),lt=s(async(e,t)=>{let n=`Basic ${btoa(`${e}:${t}`)}`,r=await fetch("https://auth.cognite.com/oauth2/token",{method:"POST",headers:{Authorization:n,"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"client_credentials"})});if(!r.ok){let i=await r.text();throw new Error(`Failed to get token from CDF: ${r.status} ${r.statusText}
|
|
8
|
+
${i}`)}let o=await r.json();if(!o.access_token)throw new Error("No access token returned from CDF authentication");return o.access_token},"getTokenCdf"),dt=s(async(e,t,n,r)=>{if(!r)throw new Error("Entra ID authentication requires 'baseUrl' to be set in deployment configuration");let o=pt(r);if(!o)throw new Error(`Entra ID authentication requires 'baseUrl' to be a valid CDF URL (e.g., https://cluster.cognitedata.com), got: ${r}`);let i=`https://login.microsoftonline.com/${n}/oauth2/v2.0/token`,a=`https://${o}.cognitedata.com/.default`,l=await fetch(i,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({client_id:e,client_secret:t,scope:a,grant_type:"client_credentials"})});if(!l.ok){let p=await l.text();throw new Error(`Failed to get token from Entra ID: ${l.status} ${l.statusText}
|
|
9
|
+
${p}`)}let c=await l.json();if(!c.access_token)throw new Error("No access token returned from Entra ID authentication");return c.access_token},"getTokenEntra"),U=s(async(e,t=process.env)=>{if(t.COGNITE_TOKEN)return t.COGNITE_TOKEN;let{deployClientId:n,deploySecretName:r,idpType:o="cdf",tenantId:i,baseUrl:a}=e,l=ct(r);if(o==="entra_id"){if(!i)throw new Error("Entra ID authentication requires 'tenantId' in deployment configuration");return dt(n,l,i,a)}return lt(n,l)},"getToken");var O=s(async(e,t,n=process.env)=>{let r=await U(e,n),o=n.COGNITE_BASE_URL??e.baseUrl,i=new ut({appId:t,project:e.project,baseUrl:o,oidcTokenProvider:s(async()=>r,"oidcTokenProvider")});return await i.authenticate(),i},"getSdk");var ft=s(async(e,t,n)=>{let r=await new V(`${n}/dist`).createZip("app.zip",!0);try{let{externalId:o,name:i,description:a,versionTag:l}=t,c=await O(e,n),p=new P(c),g=Y.readFileSync(r),u=gt.basename(r);await p.deploy(o,i,a,l,g,u,e.published)}finally{try{Y.unlinkSync(r)}catch{}}},"deploy");export{P as a,V as b,U as c,O as d,ft as e};
|
package/dist/cli/cli.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as o,e as
|
|
3
|
-
See: ${
|
|
4
|
-
See: ${
|
|
5
|
-
${n}`),{cause:t}):null}o(
|
|
2
|
+
import{a as o,e as He}from"../chunk-A5ASLC6T.js";import{writeSync as Ki}from"fs";import{Command as ji}from"commander";var Be="https://docs.cognite.com/cdf/access/";function k(e){return e!==null&&typeof e=="object"}o(k,"isRecord");function G(e){return e instanceof Error&&"status"in e&&typeof e.status=="number"}o(G,"isHttpError");function $n(e){switch(e){case 401:return`Your credentials are invalid or expired. Check your client ID and secret.
|
|
3
|
+
See: ${Be}`;case 403:return`You don't have the required CDF capabilities. Please contact your CDF admin.
|
|
4
|
+
See: ${Be}`;default:return}}o($n,"httpStatusHint");function V(e){let t=e instanceof Error?e:new Error(String(e));if(!G(t))return null;let n=$n(t.status);return n?Object.assign(new Error(`${t.message}
|
|
5
|
+
${n}`),{cause:t}):null}o(V,"enrichedHttpError");function Fn(e){if(!k(e))return null;let t=e.missing;if(Array.isArray(t))return t;let n=e.data;if(k(n)){let r=n.error;if(k(r)&&Array.isArray(r.missing))return r.missing;if(Array.isArray(n.missing))return n.missing}return null}o(Fn,"findMissingArray");function Rn(e,t){if(!G(e)||e.status!==400)return!1;let n=Fn(e);return n?n.some(r=>k(r)&&typeof r.externalId=="string"&&t.includes(r.externalId)):!1}o(Rn,"isMissingExternalIdError");function ce(e,t){return G(e)&&e.status===404||Rn(e,t)}o(ce,"isNotFoundError");var Ye=["DRAFT","PUBLISHED","DEPRECATED","ARCHIVED"],Je=["ACTIVE","PREVIEW"],pe=class pe extends Error{constructor(t,n){super(`Version ${n} of app ${t} not found`),this.name="AppVersionNotFoundError",this.appExternalId=t,this.version=n}};o(pe,"AppVersionNotFoundError");var S=pe;function Xe(e,t){return e.includes(t)}o(Xe,"includesValue");function On(e){return Xe(Ye,e)}o(On,"isAppVersionLifecycleState");function _n(e){return Xe(Je,e)}o(_n,"isAppVersionAlias");function Un(e){return typeof e.version=="string"&&On(e.lifecycleState)&&typeof e.entrypoint=="string"&&typeof e.createdTime=="number"&&typeof e.createdBy=="string"&&typeof e.appExternalId=="string"&&(e.alias===void 0||_n(e.alias))&&(e.comment===void 0||typeof e.comment=="string")}o(Un,"isAppVersion");function Ge(e){if(!k(e))throw new Error("Invalid version response: not an object");if(!Un(e))throw new Error("Invalid version response: missing or malformed fields");return e}o(Ge,"parseAppVersion");var le=class le{constructor(t){this.client=t}get appsBasePath(){return`/api/v1/projects/${encodeURIComponent(this.client.project)}/apphosting/apps`}async createApp(t,n,r){try{await this.client.post(this.appsBasePath,{data:{items:[{externalId:t,name:n,description:r}]}})}catch(i){throw V(i)??i}}async uploadVersion(t,n,r,i,s="index.html"){console.log(`\u{1F4E4} Uploading version ${n}...`);let a=new FormData;a.append("file",new Blob([new Uint8Array(r)]),i),a.append("version",n),a.append("entryPath",s);let c=encodeURIComponent(t),p=`${this.appsBasePath}/${c}/versions`,l=await this.client.authenticate(),m=`${this.client.getBaseUrl()}${p}`,d=new AbortController,u=setTimeout(()=>d.abort(),300*1e3),f;try{f=await fetch(m,{method:"POST",headers:{Authorization:`Bearer ${l}`},body:a,signal:d.signal})}catch(g){throw g instanceof Error&&g.name==="AbortError"?new Error("Upload timed out after 5 minutes"):g}finally{clearTimeout(u)}if(!f.ok){let g=await f.text(),b=g;try{let _=JSON.parse(g);if(k(_)){let x=_.error;if(typeof x=="string")b=x;else if(k(x)){let A=x.message,y=x.code;b=typeof A=="string"?A:y!=null?`Unknown error (code: ${y})`:g}else{let A=_.message;b=typeof A=="string"?A:g}}}catch{}let v=f.headers.get("x-request-id"),Z=v?` | X-Request-ID: ${v}`:"",M=Object.assign(new Error(`Upload failed: ${f.status} \u2014 ${b}${Z}`),{status:f.status});throw V(M)??M}console.log(`\u2705 Version ${n} uploaded`)}async getVersion(t,n){let r=encodeURIComponent(t),i=encodeURIComponent(n),s=`${this.appsBasePath}/${r}/versions/${i}`;try{let a=await this.client.get(s);return Ge(a.data)}catch(a){throw ce(a,[t,n])?new S(t,n):V(a)??a}}async getActiveVersion(t){let n=encodeURIComponent(t),r=`${this.appsBasePath}/${n}/active`;try{let i=await this.client.get(r);return Ge(i.data)}catch(i){if(ce(i,[t]))return null;throw V(i)??i}}async updateVersions(t,n){let r=encodeURIComponent(t),i=`${this.appsBasePath}/${r}/versions/update`;try{await this.client.post(i,{data:{items:n}})}catch(s){throw V(s)??s}}};o(le,"AppHostingApi");var ee=le;var me=class me{constructor(t){this.api=new ee(t)}getVersion(t,n){return this.api.getVersion(t,n)}uploadVersion(t,n,r,i,s){return this.api.uploadVersion(t,n,r,i,s)}async ensureApp(t,n,r){console.log("\u{1F50D} Ensuring app exists...");try{await this.api.createApp(t,n,r),console.log(`\u2705 App '${t}' created`)}catch(i){if(G(i)&&i.status===409){console.log(`\u2705 App '${t}' already exists`);return}throw i}}async publishVersion(t,n){await this.api.updateVersions(t,[{version:n,update:{lifecycleState:{set:"PUBLISHED"}}}])}async publishAndActivate(t,n){console.log(`\u{1F680} Publishing and activating version ${n}...`),await this.api.updateVersions(t,[{version:n,update:{lifecycleState:{set:"PUBLISHED"},alias:{set:"ACTIVE"}}}]),console.log(`\u2705 Version ${n} is now PUBLISHED and ACTIVE`)}async activateVersion(t,n){let r=null;try{r=await this.api.getActiveVersion(t)}catch{r=null}let i=r&&r.version!==n?r.version:void 0;return await this.api.updateVersions(t,[{version:n,update:{alias:{set:"ACTIVE"}}}]),{supersededVersion:i}}async deploy(t,n,r,i,s,a,c=!1){console.log(`
|
|
6
6
|
\u{1F680} Deploying application via App Hosting API...
|
|
7
|
-
`);try{await this.ensureApp(t,n,r),await this.uploadVersion(t,i,s,a),
|
|
8
|
-
\u2705 Deployment successful!`)}catch(
|
|
9
|
-
${s}`)}let i=await r.json();if(!i.access_token)throw new Error("No access token returned from CDF authentication");return i.access_token},"getTokenCdf"),
|
|
10
|
-
${l}`)}let
|
|
7
|
+
`);try{await this.ensureApp(t,n,r),await this.uploadVersion(t,i,s,a),c&&await this.publishAndActivate(t,i),console.log(`
|
|
8
|
+
\u2705 Deployment successful!`)}catch(p){let l=p instanceof Error?p.message:String(p);throw Object.assign(new Error(`Deployment failed: ${l}`),{cause:p})}}};o(me,"AppHostingClient");var h=me;import{existsSync as Jn,readFileSync as Xn}from"fs";import{resolve as zn}from"path";import{array as Ln,boolean as Nn,check as ze,forward as We,literal as Kn,maxLength as jn,minLength as Mn,nonEmpty as H,object as qe,optional as U,picklist as Vn,pipe as D,safeParse as Hn,string as C,url as Bn}from"valibot";var de=D(C(),H("must not be empty")),ue=D(C(),H("must not be empty"),jn(256,"must be 256 characters or fewer")),ge=D(C(),H("must not be empty"),Bn("must be a valid URL")),fe=D(C(),H("must not be empty")),ye=D(C(),H("must not be empty")),Gn=D(qe({org:fe,project:ye,baseUrl:ge,deployClientId:U(C(),""),deploySecretName:U(C(),""),published:U(Nn(),!1),idpType:U(Vn(["cdf","entra_id"]),"cdf"),tenantId:U(C())}),We(ze(e=>e.idpType!=="entra_id"||!!e.tenantId,'must be set when idpType is "entra_id"'),["tenantId"]),We(ze(e=>!e.deployClientId||!!e.deploySecretName,"must be set when deployClientId is set"),["deploySecretName"])),Yn=qe({name:de,externalId:ue,versionTag:D(C(),H("must not be empty")),description:U(C(),""),deployments:D(Ln(Gn),Mn(1,"must contain at least one deployment")),infra:U(Kn("appsApi"))});function he(e){let t=Hn(Yn,e);if(t.success)return t.output;let n=t.issues[0],r=n.path?.map(s=>s.key).join(".")??"",i=r?`"${r}" `:"";throw new Error(`app.json: ${i}${n.message}`)}o(he,"validateAppConfig");function w(e,t={}){let{validator:n=he,existsSync:r=Jn,readFileSync:i=Xn}=t,s=zn(e,"app.json");if(!r(s))throw new Error("No app.json found in current directory. Make sure you're running this command from your app's root directory.");let a=i(s,"utf-8"),c;try{c=JSON.parse(a)}catch{throw new Error("Failed to parse app.json \u2014 check that it contains valid JSON.")}return n(c)}o(w,"loadAppConfig");import{CogniteClient as wr}from"@cognite/sdk";import{CogniteClient as tr}from"@cognite/sdk";var Wn=o(()=>{let e=process.env.DEPLOYMENT_SECRETS;if(!e)return{};try{let t=JSON.parse(e),n={};for(let[r,i]of Object.entries(t))if(typeof i=="string"){let s=r.toLowerCase().replace(/_/g,"-");n[s]=i}return n}catch(t){return console.error("Error parsing DEPLOYMENT_SECRETS:",t),{}}},"loadSecretsFromEnv"),qn=o(e=>{let t;if(process.env.DEPLOYMENT_SECRET&&(t=process.env.DEPLOYMENT_SECRET),t||(t=Wn()[e]),t||(t=process.env[e]),!t)throw new Error(`Secret not found in environment: ${e}`);return t},"getSecretFromEnv"),Qn=o(e=>{if(!e)return"";try{return new URL(e).hostname.replace(/\.cognitedata\.com$/,"")}catch{let t=e.replace(/^https?:\/\//,"");return t=t.split("/")[0],t=t.split(":")[0],t=t.replace(/\.cognitedata\.com$/,""),t}},"extractClusterFromUrl"),Zn=o(async(e,t)=>{let n=`Basic ${btoa(`${e}:${t}`)}`,r=await fetch("https://auth.cognite.com/oauth2/token",{method:"POST",headers:{Authorization:n,"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"client_credentials"})});if(!r.ok){let s=await r.text();throw new Error(`Failed to get token from CDF: ${r.status} ${r.statusText}
|
|
9
|
+
${s}`)}let i=await r.json();if(!i.access_token)throw new Error("No access token returned from CDF authentication");return i.access_token},"getTokenCdf"),er=o(async(e,t,n,r)=>{if(!r)throw new Error("Entra ID authentication requires 'baseUrl' to be set in deployment configuration");let i=Qn(r);if(!i)throw new Error(`Entra ID authentication requires 'baseUrl' to be a valid CDF URL (e.g., https://cluster.cognitedata.com), got: ${r}`);let s=`https://login.microsoftonline.com/${n}/oauth2/v2.0/token`,a=`https://${i}.cognitedata.com/.default`,c=await fetch(s,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({client_id:e,client_secret:t,scope:a,grant_type:"client_credentials"})});if(!c.ok){let l=await c.text();throw new Error(`Failed to get token from Entra ID: ${c.status} ${c.statusText}
|
|
10
|
+
${l}`)}let p=await c.json();if(!p.access_token)throw new Error("No access token returned from Entra ID authentication");return p.access_token},"getTokenEntra"),Ee=o(async(e,t=process.env)=>{if(t.COGNITE_TOKEN)return t.COGNITE_TOKEN;let{deployClientId:n,deploySecretName:r,idpType:i="cdf",tenantId:s,baseUrl:a}=e,c=qn(r);if(i==="entra_id"){if(!s)throw new Error("Entra ID authentication requires 'tenantId' in deployment configuration");return er(n,c,s,a)}return Zn(n,c)},"getToken");var Y=o(async(e,t,n=process.env)=>{let r=await Ee(e,n),i=n.COGNITE_BASE_URL??e.baseUrl,s=new tr({appId:t,project:e.project,baseUrl:i,oidcTokenProvider:o(async()=>r,"oidcTokenProvider")});return await s.authenticate(),s},"getSdk");import cr from"os";import pr from"path";import lr from"open";import{buildAuthorizationUrl as mr,calculatePKCECodeChallenge as dr,discovery as ur,None as gr,randomPKCECodeVerifier as fr,randomState as yr}from"openid-client";import nr from"https";import{authorizationCodeGrant as rr}from"openid-client";function Qe(e){return e.replace(/[&<>"']/g,t=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[t]??t)}o(Qe,"escapeHtml");function we(e,t,n){let r=Qe(t),i=Qe(n);return`<html><body style="font-family: system-ui; padding: 40px; text-align: center;">
|
|
11
11
|
<h1>${r}</h1><p>${i}</p><p>You can close this window.</p>${e==="success"?`<style>
|
|
12
12
|
@keyframes checkmark {
|
|
13
13
|
0% { transform: scale(0); }
|
|
@@ -16,31 +16,31 @@ ${l}`)}let c=await p.json();if(!c.access_token)throw new Error("No access token
|
|
|
16
16
|
}
|
|
17
17
|
h1 { animation: checkmark 0.5s ease-out; }
|
|
18
18
|
</style>`:""}
|
|
19
|
-
</body></html>`}o(
|
|
19
|
+
</body></html>`}o(we,"generateHtml");async function or(e,t,n,r,i,s){let a=new URL(e.url??"/",`https://${e.headers.host??"localhost"}`);if(a.pathname!=="/")return t.writeHead(404),t.end("Not found"),{shouldClose:!1};try{console.log("\u{1F504} Exchanging authorization code for tokens...");let c=await s.authorizationCodeGrant(n,a,{pkceCodeVerifier:r,expectedState:i});return t.writeHead(200,{"Content-Type":"text/html"}),t.end(we("success","Login Successful!","You can close this window and return to the terminal.")),{shouldClose:!0,tokens:c}}catch(c){let p=c instanceof Error?c:new Error(String(c));return t.writeHead(400,{"Content-Type":"text/html"}),t.end(we("error","Authentication Error",p.message)),{shouldClose:!0,error:p}}}o(or,"handleCallback");function ir(e){let t=e/6e4,n=Math.round(t*10)/10;return`${n} ${n===1?"minute":"minutes"}`}o(ir,"formatTimeoutMinutes");function Ze(e,t,n,r,i,s={createServer:nr.createServer,setTimeout:globalThis.setTimeout,clearTimeout:globalThis.clearTimeout,authorizationCodeGrant:rr}){return new Promise((a,c)=>{let p,l=s.setTimeout(()=>{p?.close(),c(new Error(`Login timeout - no response received within ${ir(e.loginTimeout)}`))},e.loginTimeout);p=s.createServer(t,async(m,d)=>{try{let u=await or(m,d,n,r,i,s);u.shouldClose&&(s.clearTimeout(l),p?.close(),u.error?c(u.error):u.tokens?a(u.tokens):c(new Error("No tokens received")))}catch(u){s.clearTimeout(l),p?.close(),c(u instanceof Error?u:new Error(String(u)))}}),p.on("error",m=>{s.clearTimeout(l),m.code==="EADDRINUSE"?console.error(`\u274C Port ${e.port} is already in use.`):console.error(`\u274C Server error: ${m.message}`),c(m)}),p.listen(e.port,"127.0.0.1",()=>{console.log(`\u{1F310} Local HTTPS server started on https://localhost:${e.port}`)})})}o(Ze,"startCallbackServer");import{execFileSync as sr}from"child_process";import Se from"fs";import et from"path";function tt(e,t,n){return{key:n.readFileSync(e),cert:n.readFileSync(t)}}o(tt,"loadCertificates");function ar(e,t,n,r){console.log("\u{1F510} Generating self-signed certificate for HTTPS..."),r.existsSync(e)||r.mkdirSync(e,{recursive:!0});try{return r.execFileSync("openssl",["req","-x509","-newkey","rsa:2048","-nodes","-sha256","-subj","/CN=localhost","-keyout",t,"-out",n,"-days","365"],{stdio:["ignore","pipe","ignore"]}),console.log("\u2705 Certificate generated and saved locally"),tt(t,n,r)}catch{throw new Error(`Failed to generate self-signed certificate. Make sure openssl is installed.
|
|
20
20
|
On macOS: openssl is pre-installed
|
|
21
21
|
On Linux: sudo apt-get install openssl
|
|
22
|
-
On Windows: Install OpenSSL or use WSL`)}}o(
|
|
23
|
-
`),n.logger.log(`\u{1F4E1} Fetching OpenID configuration from ${t.authority}...`);let r=await n.discovery(new URL(t.authority),t.clientId,void 0,
|
|
24
|
-
`);try{await n.open(
|
|
25
|
-
`),n.logger.error(
|
|
22
|
+
On Windows: Install OpenSSL or use WSL`)}}o(ar,"generateCertificate");function nt(e,t={existsSync:Se.existsSync,readFileSync:o(n=>Se.readFileSync(n),"readFileSync"),mkdirSync:o((n,r)=>{Se.mkdirSync(n,r)},"mkdirSync"),execFileSync:sr}){let n=et.join(e,"localhost-key.pem"),r=et.join(e,"localhost-cert.pem");return t.existsSync(n)&&t.existsSync(r)?tt(n,r,t):ar(e,n,r,t)}o(nt,"getOrCreateCertificates");var hr={authority:"https://auth.cognite.com",clientId:"0404baaa-0a90-43a2-aba7-a110b53fb41c",redirectUri:"https://localhost:3000/",port:3e3,loginTimeout:300*1e3,certDir:pr.join(cr.homedir(),".cdf-login")},Er={open:lr,getOrCreateCertificates:nt,startCallbackServer:Ze,discovery:ur,buildAuthorizationUrl:mr,randomPKCECodeVerifier:fr,calculatePKCECodeChallenge:dr,randomState:yr,logger:console};async function ot(e,t=hr,n){return n===void 0?rt(e,t,Er):rt(e,t,n)}o(ot,"login");async function rt(e,t,n){n.logger.log(`\u{1F510} Starting CDF login flow...
|
|
23
|
+
`),n.logger.log(`\u{1F4E1} Fetching OpenID configuration from ${t.authority}...`);let r=await n.discovery(new URL(t.authority),t.clientId,void 0,gr()),i=n.randomPKCECodeVerifier(),s=await n.calculatePKCECodeChallenge(i),a=n.randomState(),c={redirect_uri:t.redirectUri,scope:"openid profile email",code_challenge:s,code_challenge_method:"S256",state:a};e&&(c.organization_hint=e);let p=n.buildAuthorizationUrl(r,c).toString(),l=n.getOrCreateCertificates(t.certDir);e&&n.logger.log(`\u{1F3E2} Organization: ${e}`),n.logger.log(`\u{1F680} Opening browser for authentication...
|
|
24
|
+
`);try{await n.open(p)}catch(m){let d=m instanceof Error?m.message:String(m);n.logger.error("\u274C Failed to open browser automatically."),n.logger.error(` Reason: ${d}`),n.logger.error(`Please open this URL manually:
|
|
25
|
+
`),n.logger.error(p),n.logger.error("")}return n.startCallbackServer(t,l,r,i,a)}o(rt,"loginImpl");async function I(e,t,n={}){let{login:r=ot,getSdk:i=Y,createClient:s=o(a=>new wr(a),"createClient")}=n;if(t.interactive){let a=t.orgHint||e.org||void 0,c=await r(a),p=s({appId:t.appId,project:e.project,baseUrl:e.baseUrl,getToken:o(async()=>c.access_token,"getToken")});return await p.authenticate(),p}return i(e,t.appId)}o(I,"getClientForDeployment");import it from"enquirer";var st="Enter custom target...";function at(e,t){let n=t.map((r,i)=>` ${i}: ${r.org}/${r.project}`).join(`
|
|
26
26
|
`);throw new Error(`Deployment "${e}" not found. Available deployments:
|
|
27
|
-
${n}`)}o(
|
|
27
|
+
${n}`)}o(at,"deploymentNotFoundError");function P(e,t){if(e.length===0)throw new Error("No deployments configured in app.json");if(t===void 0)return e[0];if(/^\d+$/.test(t)){let r=e[Number.parseInt(t)];if(r)return r;at(t,e)}let n=e.find(r=>r.project===t||`${r.org}/${r.project}`===t);if(n)return n;at(t,e)}o(P,"findDeployment");function T(e){let t=[];return e.deployClientId||t.push("deployClientId"),e.deploySecretName||t.push("deploySecretName"),t}o(T,"getMissingCredentials");async function $(e,t){if(t.baseUrl&&t.project)return{org:t.org??"",project:t.project,baseUrl:t.baseUrl,deployClientId:"",deploySecretName:"",published:!1,idpType:"cdf"};if(t.deployment!==void 0)return P(e.deployments,t.deployment);let n=[...e.deployments.map(s=>`${s.org}/${s.project}`),st],{selected:r}=await it.prompt({type:"select",name:"selected",message:"Select deployment target",choices:n});if(r!==st){let s=e.deployments.find(a=>`${a.org}/${a.project}`===r);if(s)return s;throw new Error(`Deployment "${r}" could not be resolved from app.json.`)}let i=await it.prompt([{type:"input",name:"baseUrl",message:"CDF Base URL",initial:"https://api.cognitedata.com"},{type:"input",name:"project",message:"CDF Project",validate:o(s=>s?!0:"Project is required","validate")},{type:"input",name:"org",message:"Organization (for login hint)",initial:""}]);return{org:i.org||"",project:i.project,baseUrl:i.baseUrl,deployClientId:"",deploySecretName:"",published:!1,idpType:"cdf"}}o($,"resolveDeployment");import{existsSync as Sr}from"fs";import{resolve as Cr}from"path";import{config as vr}from"dotenv";function F(e,t={existsSync:Sr,config:vr}){let n=Cr(e,".env");t.existsSync(n)&&(console.log(`Loading environment variables from ${n}`),t.config({path:n}))}o(F,"loadEnvFile");function R(e){e.infra!=="appsApi"&&(console.error(`
|
|
28
28
|
\u26A0\uFE0F Legacy infrastructure is no longer supported.
|
|
29
29
|
|
|
30
30
|
Your app.json is missing \`"infra": "appsApi"\`, which means it was created for
|
|
31
31
|
the old CDF Application Registry. This deploy path has been removed.
|
|
32
32
|
|
|
33
33
|
To migrate: add \`"infra": "appsApi"\` to your app.json, wire up the correct authentication and re-deploy.
|
|
34
|
-
`),process.exit(1))}o(
|
|
34
|
+
`),process.exit(1))}o(R,"assertAppHostingInfra");async function xr(e){let t=process.cwd();F(t);let n=w(t);R(n);let r=e.interactive?await $(n,e):P(n.deployments,e.deployment);if(!e.interactive){let m=T(r);if(m.length>0)throw new Error(`Deployment ${r.org}/${r.project} is missing ${m.join(" and ")} in app.json. Use \`npx @cognite/cli@latest apps activate --interactive\` for browser-based authentication instead.`)}let i=await I(r,{interactive:e.interactive,appId:n.externalId,orgHint:e.org}),s=new h(i),{externalId:a,versionTag:c}=n,p;try{p=await s.getVersion(a,c)}catch(m){throw m instanceof S?new Error(`Version ${c} of ${a} has not been deployed yet. Run \`npx @cognite/cli apps deploy\` first.`):m}if(p.alias==="ACTIVE"){console.log(` ${a} @ ${c} is already ACTIVE \u2014 nothing to do.`);return}if(p.lifecycleState==="DEPRECATED"||p.lifecycleState==="ARCHIVED")throw new Error(`Cannot activate ${a} @ ${c}: version is ${p.lifecycleState} (terminal).`);p.lifecycleState==="DRAFT"&&(await s.publishVersion(a,c),console.log(`\u2713 Published ${a} @ ${c} is now PUBLISHED`));let{supersededVersion:l}=await s.activateVersion(a,c);console.log(`\u2713 Activated ${a} @ ${c} is now ACTIVE`),l&&console.log(` Superseded ${l} \u2192 PUBLISHED`)}o(xr,"handleActivate");function ct(e){return e.command("activate").description("Activate the current app version (publish if needed, then set ACTIVE alias)").argument("[path]","Path to the app folder (only `.` is currently supported)",".").option("-d, --deployment <target>","Deployment target from app.json (index or name)").option("--interactive","Use browser-based authentication instead of env-var credentials",!1).option("--base-url <url>","CDF base URL (only with --interactive)").option("--project <project>","CDF project name (only with --interactive)").option("--org <org>","Organization hint for login (only with --interactive)").addHelpText("after",`
|
|
35
35
|
Examples:
|
|
36
36
|
npx @cognite/cli apps activate . Activate using env-var auth
|
|
37
|
-
npx @cognite/cli apps activate . --interactive Activate using browser auth (no secrets needed)`).action((t,n)=>
|
|
38
|
-
`),initial:!1};async function
|
|
39
|
-
`),i=`link .specify/memory/constitution.md in specifyDir=${n}`,
|
|
37
|
+
npx @cognite/cli apps activate . --interactive Activate using browser auth (no secrets needed)`).action((t,n)=>xr(n))}o(ct,"registerActivateCommand");import{readdirSync as Ur}from"fs";import{basename as Et,dirname as Lr,normalize as Nr,resolve as X}from"path";import{fileURLToPath as Kr,pathToFileURL as jr}from"url";import{Logger as Mr,runner as Vr}from"hygen";import{safeParse as Pr}from"valibot";function J(e,t){return n=>{let r=Pr(t,n);return r.success?!0:`${e} ${r.issues[0].message}`}}o(J,"toPromptValidator");var pt={name:J("App name",ue),displayName:J("Display name",de),baseUrl:J("Base URL",ge),org:J("Org",fe),project:J("Project",ye)};function br(e,t){return e?async n=>{let r=t(n);return r===!0?e(n):r}:t}o(br,"composeValidators");function te(e){return e.map(t=>{if(!(t.name in pt))return t;let n=pt[t.name];return{...t,validate:br(t.validate,n)}})}o(te,"applySchemaValidators");import{basename as mt}from"path";import dt from"enquirer";function lt(e){return e.replace(/[A-Z]/g,(t,n)=>n===0?t.toLowerCase():`-${t.toLowerCase()}`)}o(lt,"kebabCase");var Ar={type:"confirm",name:"useSpecKit",message:["Enable spec-driven development?"," Adds the github/spec-kit slash commands (/speckit.specify, .clarify, .plan, .tasks, .implement)"," to your app for use in Claude Code or Cursor. They walk you through writing SPEC.md and"," generating a plan, tasks, and implementation."].join(`
|
|
38
|
+
`),initial:!1};async function kr(e){return!!(await e([Ar])).useSpecKit}o(kr,"promptForSpecKit");async function Dr(e,t,n){return e!==void 0?e:t?kr(n):!1}o(Dr,"resolveSpecKit");function ut({isCurrentDir:e,dirName:t,onAppName:n,onUseSpecKit:r,presets:i={},specKit:s,prompt:a=dt.prompt.bind(dt)}){return()=>({prompt:o(async c=>{if(!Array.isArray(c))return a([c]);let p=Object.fromEntries(Object.entries(i).filter(y=>y[1]!==void 0)),l=Object.keys(p).length>0,m=e?mt(process.cwd()):t?mt(t):null,d=l&&m!==null,u=!d&&m?c.map(y=>y.name==="name"?{...y,initial:m}:y):c,f=te(u),g=d?{...p,name:m}:p,b=new Set(Object.keys(g)),v=f.filter(y=>!b.has(y.name)),Z=v.findIndex(y=>y.name==="baseUrl"),M;if(Z!==-1){let y=v.filter(Tn=>Tn.name!=="baseUrl"),ae=y.length>0?await a(y):{},bn=typeof ae.cluster=="string"?ae.cluster:"",An=typeof g.cluster=="string"?g.cluster:"",kn=`https://${(bn||An).trim().replace(/\/+$/,"")||"api"}.cognitedata.com`,Dn=v[Z],In=await a([{...Dn,initial:kn}]);M={...ae,...In}}else M=v.length>0?await a(v):{};let _={...g,...M},x=typeof _.name=="string"?_.name:"";x&&n(x);let A=await Dr(s,v.length>0,a);return r?.(A),{..._,name:x,useCurrentDir:e,directoryName:e?void 0:t??void 0,useSpecKit:A}},"prompt")})}o(ut,"createAppPrompter");async function gt(e,t,n){let r=[];Object.values(t).some(s=>s!==void 0)&&n!==null&&r.push({key:"name",value:n,label:"directory"});for(let[s,a]of Object.entries(t))a!==void 0&&r.push({key:s,value:a,label:`--${lt(s)}`});for(let{key:s,value:a,label:c}of r){let p=e.find(m=>m.name===s)?.validate;if(!p)continue;let l=await p(a);if(l!==!0)throw new Error(`Invalid ${c}: ${l}`)}}o(gt,"validatePresets");import{cpSync as Tr,mkdirSync as ft,writeFileSync as $r}from"fs";import{dirname as yt,resolve as L}from"path";import{fileURLToPath as Fr}from"url";import{symlinkSync as Ir}from"fs";function ne({target:e,linkPath:t,label:n,symlink:r=Ir}){try{return r(e,t),!0}catch(i){if(i instanceof Error&&"code"in i&&i.code==="EEXIST")return!0;let s=i instanceof Error?i.message:String(i);return console.warn(`\u26A0\uFE0F Could not create ${n} symlink:`,s),!1}}o(ne,"symlinkOrWarn");var Rr=L(yt(Fr(import.meta.url)),"..","..","_vendor","spec-kit"),Or={branch_numbering:"sequential"},_r=[{from:"templates",to:".specify/templates"},{from:"scripts/bash",to:".specify/scripts/bash"},{from:"commands",to:".claude/commands"},{from:"commands",to:".cursor/commands"}];function ht({appDir:e,vendorDir:t=Rr}){let n=L(e,".specify"),r=L(n,"memory"),i=`prepare spec-kit install for appDir=${e}`;try{for(let{from:s,to:a}of _r){let c=L(e,a);i=`copy ${s} to ${a}`,ft(yt(c),{recursive:!0}),Tr(L(t,s),c,{recursive:!0})}i=`write init-options.json under specifyDir=${n}`,$r(L(n,"init-options.json"),`${JSON.stringify(Or,null,2)}
|
|
39
|
+
`),i=`link .specify/memory/constitution.md in specifyDir=${n}`,ft(r,{recursive:!0}),ne({target:"../../AGENTS.md",linkPath:L(r,"constitution.md"),label:".specify/memory/constitution.md"})}catch(s){let a=s instanceof Error?s.message:String(s);throw new Error(`installSpecKit failed while ${i} (appDir=${e}, vendorDir=${t}): ${a}`,{cause:s})}}o(ht,"installSpecKit");var wt=X(Lr(Kr(import.meta.url)),"..","..","_templates");async function Hr(){let e=X(wt,"app","new","prompt.js");return(await import(jr(e).href)).default}o(Hr,"loadPromptDefs");function Br(e,t){return!e||t?null:Nr(e)}o(Br,"resolveDirName");function Gr(e,t,n){if(e)return{cwd:process.cwd(),display:"."};let r=t??n;if(!r)throw new Error("App creation completed without a target directory or name.");return{cwd:X(process.cwd(),r),display:r}}o(Gr,"resolveAppLocation");function Yr(e,t,n){let r=` npm install
|
|
40
40
|
npm run dev`,i="To deploy your app:",s="npx @cognite/cli apps deploy --interactive",a=n?`
|
|
41
41
|
To start spec-driven development:
|
|
42
42
|
Run /speckit.specify in Claude Code or Cursor and describe your app.
|
|
43
|
-
`:"",
|
|
43
|
+
`:"",c=` # Or fully non-interactive (deploys first target from app.json):
|
|
44
44
|
npx @cognite/cli apps deploy`;if(e){console.log(`
|
|
45
45
|
\u2705 App created successfully in current directory!
|
|
46
46
|
|
|
@@ -49,7 +49,7 @@ ${r}
|
|
|
49
49
|
${a}
|
|
50
50
|
${i}
|
|
51
51
|
${s}
|
|
52
|
-
${
|
|
52
|
+
${c}
|
|
53
53
|
`);return}console.log(`
|
|
54
54
|
\u2705 App created successfully!
|
|
55
55
|
|
|
@@ -62,9 +62,9 @@ ${a}
|
|
|
62
62
|
${i}
|
|
63
63
|
cd "${t}"
|
|
64
64
|
${s}
|
|
65
|
-
${
|
|
66
|
-
`)}o(
|
|
67
|
-
${r}`)}catch(t){let n=t instanceof Error?t.message:String(t);console.warn("\u26A0\uFE0F Could not pull skills:",n)}}o(
|
|
65
|
+
${c}
|
|
66
|
+
`)}o(Yr,"printSuccessMessage");async function Jr(e){try{let{execSkillsCli:t,pullAllArgs:n}=await import("../skills-GQ5TZKCM.js");console.log("\u{1F9E0} Pulling skills into your app..."),t(n(),{cwd:e,timeout:3e4,stdio:["pipe","pipe","inherit"]});let r=X(e,".agents","skills"),i=0;try{i=Ur(r).length}catch{console.warn(`Skills directory not found after pull \u2014 no skills may have been installed (expected: ${r})`)}let s=i>0?`${i} skills`:"skills";console.log(`\u2705 Installed ${s} successfully to
|
|
67
|
+
${r}`)}catch(t){let n=t instanceof Error?t.message:String(t);console.warn("\u26A0\uFE0F Could not pull skills:",n)}}o(Jr,"pullSkillsInto");async function Xr(e,t){let n=e==="."||e==="./",r=Br(e,n),i=null,s=!1,a={displayName:t.displayName,description:t.description,org:t.org,project:t.project,cluster:t.cluster,baseUrl:t.baseUrl},c=await Hr(),p=te(c),l=n?Et(process.cwd()):r?Et(r):null;await gt(p,a,l);let m=ut({isCurrentDir:n,dirName:r,onAppName:o(u=>{i=u},"onAppName"),onUseSpecKit:o(u=>{s=u},"onUseSpecKit"),presets:a,specKit:t.specKit});await Vr(["app","new"],{templates:wt,cwd:process.cwd(),logger:new Mr(console.log.bind(console)),createPrompter:m,debug:!!process.env.DEBUG});let d=Gr(n,r,i);ne({target:"AGENTS.md",linkPath:X(d.cwd,"CLAUDE.md"),label:"CLAUDE.md"}),s&&ht({appDir:d.cwd}),Yr(n,d.display,s),await Jr(d.cwd)}o(Xr,"handleCreate");function St(e){return e.command("create").description("Create a new application.").argument("[directory]","Target directory (. for current, or subdirectory name)").option("--display-name <name>","App display name (skips the prompt)").option("--description <description>","App description (skips the prompt)").option("--org <org>","Deployment org (skips the prompt)").option("--project <project>","Deployment project (skips the prompt)").option("--cluster <cluster>","CDF cluster, e.g. greenfield (skips the prompt)").option("--base-url <url>","CDF base URL, e.g. https://greenfield.cognitedata.com (skips the prompt; defaults to cluster-derived URL when omitted)").option("--spec-kit","Install spec-kit slash commands (skips the prompt)").option("--no-spec-kit","Skip spec-kit installation (skips the prompt)").addHelpText("after",`
|
|
68
68
|
Non-interactive use (CI, scripts, AI agents):
|
|
69
69
|
Pass [directory] plus --display-name, --description, --org, --project, --cluster, --base-url
|
|
70
70
|
to skip every prompt. Missing flags fall back to the interactive prompt.
|
|
@@ -77,14 +77,14 @@ Examples:
|
|
|
77
77
|
--display-name "My App" --description "My app" \\
|
|
78
78
|
--org cog-atlas --project atlas-greenfield --cluster greenfield \\
|
|
79
79
|
--base-url https://greenfield.cognitedata.com
|
|
80
|
-
Fully non-interactive`).action(
|
|
81
|
-
`))}o(
|
|
80
|
+
Fully non-interactive`).action(Xr)}o(St,"registerCreateCommand");import{readFile as to,unlink as no}from"fs/promises";import{basename as ro}from"path";import vt from"fs";import Zr from"path";import O from"fs";import E from"path";import{parseAndValidateManifestConfig as zr}from"@cognite/app-sdk/vite";import{BlobReader as Wr,Uint8ArrayWriter as qr,ZipWriter as Qr}from"@zip.js/zip.js";var Ce="package.json",ve="package-lock.json",Ct="manifest.json",xe=".cognite",Pe=class Pe{constructor(t="dist"){this.distPath=E.isAbsolute(t)?t:E.join(process.cwd(),t),this.appRoot=E.dirname(this.distPath)}validateBuildDirectory(){if(!O.existsSync(this.distPath))throw new Error(`Build directory "${this.distPath}" not found. Run build first.`);let t=E.join(this.appRoot,Ce);if(!O.existsSync(t))throw new Error(`"${t}" not found. It is required for deployment.`);let n=E.join(this.appRoot,ve);if(!O.existsSync(n))throw new Error(`"${n}" not found. It is required for deployment.`)}async createZip(t="app.zip",n=!1){this.validateBuildDirectory(),console.log("\u{1F4E6} Packaging application...");let r=new Qr(new qr,{level:9}),i=o(async(p,l)=>{await r.add(l,new Wr(await O.openAsBlob(p))),n&&console.log(` \u{1F4C4} ${l}`)},"addFile"),s=o(async p=>{let l=await O.promises.readdir(p,{withFileTypes:!0});for(let m of l){let d=E.join(p,m.name);m.isDirectory()?await s(d):await i(d,E.relative(this.distPath,d).replace(/\\/g,"/"))}},"addDir"),a;try{await s(this.distPath);let p=E.join(this.appRoot,Ce);await i(p,E.posix.join(xe,Ce));let l=E.join(this.appRoot,Ct);if(O.existsSync(l)){let d=O.readFileSync(l,"utf-8");zr(d,l),await i(l,E.posix.join(xe,Ct))}let m=E.join(this.appRoot,ve);await i(m,E.posix.join(xe,ve)),a=await r.close()}catch(p){let l=p instanceof Error?p.message:String(p);throw new Error(`Failed to create zip: ${l}`)}await O.promises.writeFile(t,a);let c=(a.byteLength/1024/1024).toFixed(2);return console.log(`\u2705 App packaged: ${t} (${c} MB)`),t}};o(Pe,"ApplicationPackager");var N=Pe;var be=o(async(e,t,n)=>{let r=await new N(`${n}/dist`).createZip("app.zip",!0);try{let{externalId:i,name:s,description:a,versionTag:c}=t,p=await Y(e,n),l=new h(p),m=vt.readFileSync(r),d=Zr.basename(r);await l.deploy(i,s,a,c,m,d,e.published)}finally{try{vt.unlinkSync(r)}catch{}}},"deploy");import{execSync as eo}from"child_process";function Ae(e,t=!0,n={execSync:eo}){console.log("\u{1F4E6} Building app with npm..."),n.execSync("npm run build",{cwd:e,stdio:t?"inherit":"pipe"}),console.log("\u2705 Build successful")}o(Ae,"buildApp");function xt(e,t){let{org:n,project:r,baseUrl:i}=e,s;try{s=new URL(i).hostname}catch{return null}let{externalId:a,versionTag:c}=t,p=new URLSearchParams({cluster:s,customAppVersion:c,workspace:"industrial-tools"});return`https://${n}.fusion.cognite.com/${r}/flows-apps/app/${encodeURIComponent(a)}?${p}`}o(xt,"generateFusionUrl");function Pt(e,t,n){let r=n?"\u{1F680} Deploy (Interactive)":"\u{1F680} Deploy",i=n?`${t.project} @ ${t.baseUrl}`:`${t.org}/${t.project}`;console.log(["",r,"=".repeat(r.length),`App: ${e.name} (${e.externalId})`,`Version: ${e.versionTag}`,`Target: ${i}`,""].join(`
|
|
81
|
+
`))}o(Pt,"printDeployInfo");function bt(e,t){console.log(`
|
|
82
82
|
\u2705 Successfully deployed ${e.name} version ${e.versionTag} to ${t.org?`${t.org}/`:""}${t.project}`),console.log("\u{1F512} App is deployed in draft mode");let n=e.deployments.length>1?` -d ${t.project}`:"";console.log(`
|
|
83
|
-
To publish: npx @cognite/cli apps publish .${n}`),console.log(`To activate: npx @cognite/cli apps activate .${n}`);let r=
|
|
83
|
+
To publish: npx @cognite/cli apps publish .${n}`),console.log(`To activate: npx @cognite/cli apps activate .${n}`);let r=xt(t,e);r&&console.log(`
|
|
84
84
|
\u{1F517} Open your app:
|
|
85
|
-
${r}`)}o(
|
|
86
|
-
\u{1F4E4} Deploying to ${t.org}/${t.project}...`),await i({...t,published:!1},{externalId:e.externalId,name:e.name,description:e.description,versionTag:e.versionTag},n),
|
|
87
|
-
\u{1F4E4} Deploying to ${t.project}...`);let s=await new
|
|
85
|
+
${r}`)}o(bt,"printDeployResult");async function oo(e,t,n,r,i){let s=T(t);if(s.length>0)throw new Error(`Deployment ${t.org}/${t.project} is missing ${s.join(" and ")} in app.json. Use \`cognite apps deploy --interactive\` for browser-based authentication instead.`);Pt(e,t,!1),r.skipBuild||Ae(n),console.log(`
|
|
86
|
+
\u{1F4E4} Deploying to ${t.org}/${t.project}...`),await i({...t,published:!1},{externalId:e.externalId,name:e.name,description:e.description,versionTag:e.versionTag},n),bt(e,t)}o(oo,"handleDeployNonInteractive");async function io(e,t,n,r){Pt(e,t,!0),r.skipBuild||Ae(n);let i=await I(t,{interactive:!0,appId:e.externalId,orgHint:r.org});console.log(`
|
|
87
|
+
\u{1F4E4} Deploying to ${t.project}...`);let s=await new N(`${n}/dist`).createZip("app.zip",!0);try{let a=await to(s);await new h(i).deploy(e.externalId,e.name,e.description,e.versionTag,a,ro(s),!1),bt(e,t)}finally{await no(s).catch(()=>{})}}o(io,"handleDeployInteractive");async function so(e,t=process.cwd(),n={}){let{loadEnvFile:r=F,loadAppConfig:i=w,deploy:s=be}=n;r(t);let a=i(t);if(R(a),e.interactive){let p=await $(a,e);await io(a,p,t,e);return}let c=P(a.deployments,e.deployment);await oo(a,c,t,e,s)}o(so,"handleDeploy");function At(e){return e.command("deploy").description("Deploy your app to Cognite Data Fusion. Use --interactive for browser-based login (no env-var secrets required).").option("-d, --deployment <target>","Deployment target (index or project name)").option("--skip-build","Skip the build step",!1).option("--interactive","Use browser-based authentication instead of env-var credentials",!1).option("--base-url <url>","CDF base URL (only with --interactive)").option("--project <project>","CDF project name (only with --interactive)").option("--org <org>","Organization hint for login (only with --interactive)").addHelpText("after",`
|
|
88
88
|
Environment (non-interactive):
|
|
89
89
|
deployClientId and deploySecretName are configured per deployment in app.json.
|
|
90
90
|
deploySecretName is the name of the environment variable that holds the client
|
|
@@ -98,19 +98,42 @@ Examples:
|
|
|
98
98
|
npx @cognite/cli apps deploy -d my-project Deploy to project by name
|
|
99
99
|
npx @cognite/cli apps deploy --skip-build Deploy without rebuilding
|
|
100
100
|
npx @cognite/cli apps deploy --interactive Browser auth, prompts for target
|
|
101
|
-
npx @cognite/cli apps deploy --interactive -d 0 Browser auth, target chosen non-interactively`).action(t=>
|
|
101
|
+
npx @cognite/cli apps deploy --interactive -d 0 Browser auth, target chosen non-interactively`).action(t=>so(t))}o(At,"registerDeployCommand");async function ao(e){let t=process.cwd();F(t);let n=w(t);R(n);let r=e.interactive?await $(n,e):P(n.deployments,e.deployment);if(!e.interactive){let l=T(r);if(l.length>0)throw new Error(`Deployment ${r.org}/${r.project} is missing ${l.join(" and ")} in app.json. Use \`cognite apps publish --interactive\` for browser-based authentication instead.`)}let i=await I(r,{interactive:e.interactive,appId:n.externalId,orgHint:e.org}),s=new h(i),{externalId:a,versionTag:c}=n,p;try{p=await s.getVersion(a,c)}catch(l){throw l instanceof S?new Error(`Version ${c} of ${a} has not been deployed yet. Run \`npx @cognite/cli apps deploy\` first.`):l}if(p.alias==="ACTIVE"){console.log(` ${a} @ ${c} is already ACTIVE \u2014 nothing to do.`);return}if(p.lifecycleState==="PUBLISHED"){console.log(` ${a} @ ${c} is already PUBLISHED \u2014 nothing to do.`);return}if(p.lifecycleState==="DEPRECATED"||p.lifecycleState==="ARCHIVED")throw new Error(`Cannot publish ${a} @ ${c}: version is ${p.lifecycleState} (terminal).`);await s.publishVersion(a,c),console.log(`\u2713 Published ${a} @ ${c} is now PUBLISHED`),console.log(""),console.log("Run `npx @cognite/cli apps activate .` to make it active.")}o(ao,"handlePublish");function kt(e){return e.command("publish").description("Publish the current app version (transition DRAFT \u2192 PUBLISHED)").argument("[path]","Path to the app folder (only `.` is currently supported)",".").option("-d, --deployment <target>","Deployment target from app.json (index or name)").option("--interactive","Use browser-based authentication instead of env-var credentials",!1).option("--base-url <url>","CDF base URL (only with --interactive)").option("--project <project>","CDF project name (only with --interactive)").option("--org <org>","Organization hint for login (only with --interactive)").addHelpText("after",`
|
|
102
102
|
Examples:
|
|
103
103
|
npx @cognite/cli apps publish . Publish using env-var auth
|
|
104
|
-
npx @cognite/cli apps publish . --interactive Publish using browser auth (no secrets needed)`).action((t,n)=>
|
|
104
|
+
npx @cognite/cli apps publish . --interactive Publish using browser auth (no secrets needed)`).action((t,n)=>ao(n))}o(kt,"registerPublishCommand");function co(e){return e.alias==="ACTIVE"?"ACTIVE":e.lifecycleState}o(co,"describeStatus");async function po(e){let t=process.cwd();F(t);let n=w(t);R(n);let r=e.interactive?await $(n,e):P(n.deployments,e.deployment);if(!e.interactive){let a=T(r);if(a.length>0)throw new Error(`Deployment ${r.org}/${r.project} is missing ${a.join(" and ")} in app.json. Use \`cognite apps status --interactive\` for browser-based authentication instead.`)}let i=await I(r,{interactive:e.interactive,appId:n.externalId,orgHint:e.org}),s=new h(i);console.log(""),console.log(`App: ${n.name} (${n.externalId})`),console.log(`Version: ${n.versionTag} (local)`);try{let a=await s.getVersion(n.externalId,n.versionTag),c=co(a);console.log(`Status: ${c}`),a.lifecycleState==="DRAFT"&&(console.log(""),console.log("Run `npx @cognite/cli apps publish .` to publish this version."))}catch(a){if(a instanceof S){console.log("Status: not deployed yet"),console.log(""),console.log("Run `npx @cognite/cli apps deploy` to upload this version.");return}throw a}}o(po,"handleStatus");function Dt(e){return e.command("status").description("Show the deployment status of the current app version").argument("[path]","Path to the app folder (only `.` is currently supported)",".").option("-d, --deployment <target>","Deployment target from app.json (index or name)").option("--interactive","Use browser-based authentication instead of env-var credentials",!1).option("--base-url <url>","CDF base URL (only with --interactive)").option("--project <project>","CDF project name (only with --interactive)").option("--org <org>","Organization hint for login (only with --interactive)").addHelpText("after",`
|
|
105
105
|
Examples:
|
|
106
106
|
npx @cognite/cli apps status . Status using env-var auth
|
|
107
|
-
npx @cognite/cli apps status . --interactive Status using browser auth (no secrets needed)`).action((t,n)=>
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
${
|
|
115
|
-
`)},"
|
|
116
|
-
|
|
107
|
+
npx @cognite/cli apps status . --interactive Status using browser auth (no secrets needed)`).action((t,n)=>po(n))}o(Dt,"registerStatusCommand");function It(e){let t=e.command("apps").description("Manage Fusion Custom Apps \u2014 create, deploy, and manage version lifecycle");return St(t),At(t),Dt(t),kt(t),ct(t),He(t),t}o(It,"registerAppsCommand");import{existsSync as oi,mkdirSync as ii,writeFileSync as si}from"fs";import{dirname as _e,join as Ue}from"path";import{execFile as mo}from"child_process";import{promisify as uo}from"util";import{platform as lo}from"os";function K(e={}){let{platform:t=lo}=e;return t()==="darwin"}o(K,"isMacOS");var Tt="cognite-flows",go=uo(mo),$t=o((e,t)=>go(e,t),"defaultExecFile"),fo=-25300,yo=fo&255;function ho(e){if(!(e instanceof Error)||!("code"in e)||e.code!==yo)return!1;let t="stderr"in e?String(e.stderr):"";return/could not be found/i.test(t)||t===""}o(ho,"isKeychainNotFoundError");async function Ft(e,t,n={}){if(!K(n))throw new Error("Keychain storage is only supported on macOS");let{execFile:r=$t}=n;await r("security",["add-generic-password","-a",e,"-s",Tt,"-w",Buffer.from(t,"utf-8").toString("base64"),"-U"])}o(Ft,"storeKeyInKeychain");async function Rt(e,t={}){if(!K(t))return null;let{execFile:n=$t}=t;try{let{stdout:r}=await n("security",["find-generic-password","-a",e,"-s",Tt,"-w"]);return Buffer.from(r.trim(),"base64").toString("utf-8")}catch(r){if(ho(r))return null;throw r}}o(Rt,"readKeyFromKeychain");import{pbkdf2 as So,randomBytes as Co}from"crypto";import{promisify as vo}from"util";import{CompactEncrypt as xo,base64url as Po,compactDecrypt as tp}from"jose";var Eo=new TextEncoder,wo=new TextDecoder,Ot={encode:o(e=>Eo.encode(e),"encode"),decode:o(e=>wo.decode(e),"decode")};var bo=vo(So),ke=6e5,Ao="sha512",ko="PBKDF2-HMAC-SHA512",Do=16,Io="A256GCM",To=32,_t=2e6;async function $o(e,t,n){return await bo(e,t,n,To,Ao)}o($o,"deriveKey");async function Ut(e,t,n=ke){if(!Number.isInteger(n)||n<1||n>_t)throw new Error(`Invalid iterations: must be an integer between 1 and ${_t}`);let r=Co(Do),i=await $o(t,r,n);return await new xo(Ot.encode(e)).setProtectedHeader({alg:"dir",enc:Io,kdf:ko,kdf_iter:n,kdf_salt:Po.encode(r)}).encrypt(i)}o(Ut,"encryptStringAsJwe");import{calculateJwkThumbprint as Fo,exportJWK as Ro,exportPKCS8 as Oo,exportSPKI as _o,generateKeyPair as Uo}from"jose";async function Lt(){let{publicKey:e,privateKey:t}=await Uo("EdDSA",{extractable:!0}),n=await Oo(t),r=await _o(e),i=await Ro(e),s=await Fo(i);return{privateKeyPem:n,publicKeyPem:r,kid:s}}o(Lt,"generateSigningKeyPair");import{existsSync as No,readdirSync as Ko,readFileSync as jo}from"fs";import{join as re}from"path";import{homedir as Lo}from"os";import{join as Nt}from"path";function j(e={}){let{env:t=process.env,homedir:n=Lo}=e,r=t.DUNE_HOME?.trim()||Nt(n(),".dune");return{home:r,keysDir:Nt(r,"keys")}}o(j,"getConfig");var oe=".pub.pem",De=".key.jwe",Mo=".pem",Ie=".meta.json";function Kt(e){switch(e.kind){case"keychain":return"Keychain";case"encrypted-file":return e.path;case"legacy-unencrypted-file":return`${e.path} (unencrypted \u2014 rotate)`;case"public-only":return"public-only (private key missing)"}}o(Kt,"formatLocalKeySource");function Vo(e){return{existsSync:e.existsSync??No,readdirSync:e.readdirSync??Ko,readFileSync:e.readFileSync??((t,n)=>jo(t,n)),isMacOS:e.isMacOS??(()=>K()),readKeyFromKeychain:e.readKeyFromKeychain??(t=>Rt(t))}}o(Vo,"resolveDeps");function Ho(e){try{let t=JSON.parse(e);if(typeof t=="object"&&t!==null&&!Array.isArray(t)&&"email"in t&&typeof t.email=="string")return t.email}catch{}}o(Ho,"readEmailFromMeta");function Bo(e,t){return t.existsSync(e)?t.readdirSync(e).filter(n=>n.endsWith(oe)):[]}o(Bo,"publicKeyEntries");function Go(e){return e.slice(0,-oe.length)}o(Go,"kidFromPublicKeyFilename");async function Yo(e,t,n){if(n.isMacOS()&&await n.readKeyFromKeychain(e).catch(()=>null)!==null)return{kind:"keychain"};let r=re(t,`${e}${De}`);if(n.existsSync(r))return{kind:"encrypted-file",path:r};let i=re(t,`${e}${Mo}`);return n.existsSync(i)?{kind:"legacy-unencrypted-file",path:i}:{kind:"public-only"}}o(Yo,"resolveSource");async function jt(e=j().keysDir,t={}){let n=Vo(t),r=new Set,i=Bo(e,n).flatMap(s=>{let a=Go(s);return!a||r.has(a)?[]:(r.add(a),[{kid:a,entry:s}])});return Promise.all(i.map(async({kid:s,entry:a})=>{let c=await Yo(s,e,n),p=re(e,`${s}${Ie}`),l;try{l=Ho(n.readFileSync(p,"utf8"))}catch{}return{kid:s,source:c,publicKeyPath:re(e,a),email:l}}))}o(jt,"discoverLocalKeys");function Mt(e,t){let n=e.getUTCFullYear(),r=e.getUTCMonth()+t,i=new Date(Date.UTC(n,r+1,0)).getUTCDate(),s=Math.min(e.getUTCDate(),i);return new Date(Date.UTC(n,r,s))}o(Mt,"addMonthsClamped");function Te(e){return e.toISOString().slice(0,10)}o(Te,"formatIsoDate");function Vt(e=new Date){return Te(e)}o(Vt,"todayIso");import Jo,{Chalk as Xo}from"chalk";var $e=new Xo({level:0});function Ht(e){return e.isTTY?Jo:$e}o(Ht,"chalkForStream");function zo(e){return e.replace(/-----BEGIN [^-]+-----/g,"").replace(/-----END [^-]+-----/g,"").replace(/\s+/g,"")}o(zo,"pemBodyOneLine");function Bt(e,t=$e,n=new Date){let r=e.issuedAt??Vt(n),i=zo(e.publicKeyPem),s=" ",a=o((p,l)=>`${s}${t.cyan(p)}${t.dim(":")} ${l}
|
|
108
|
+
`,"kv"),c="";return c+=`
|
|
109
|
+
${t.bold("Add this entry to")} ${t.magenta("services/app-hosting/config/signing-keys.yaml")} ${t.bold("under")} ${t.cyan("public_keys:")}
|
|
110
|
+
|
|
111
|
+
`,c+=`${t.dim("-")} ${t.cyan("kid")}${t.dim(":")} ${t.green(e.kid)}
|
|
112
|
+
`,c+=a("public_key",t.green(i)),c+=a("email",t.yellow(e.email)),c+=a("capabilities",`${t.dim("[")}${t.yellow("developer")}${t.dim("]")}`),c+=a("issued_at",t.green(r)),c+=a("expires",t.green(e.expires)),c+=a("revoked_at",t.dim("null")),c}o(Bt,"renderRegistryEntry");import{email as Wo,pipe as qo,safeParse as Qo,string as Zo}from"valibot";var ei=qo(Zo(),Wo());function W(e,t="email"){let n=e.trim();if(!n)throw new Error(`${t} is required`);if(!Qo(ei,n).success)throw new Error(`${t} must look like an email (user@example.com); got "${e}"`);return n}o(W,"parseEmail");function q(e,t="--expires"){let n=Number(e);if(!Number.isInteger(n)||n<1||n>12)throw new Error(`${t} must be an integer between 1 and 12 (months); got "${e}"`);return n}o(q,"parseExpiryMonths");import ri from"enquirer";import{execFileSync as ti}from"child_process";function Gt(e={}){let{execFileSync:t=ti}=e;try{return String(t("git",["config","--get","user.email"],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]})).trim()||void 0}catch{return}}o(Gt,"gitUserEmail");var ie=3,Yt=`Key expiry in months (${1}-${12})`,Jt="Email address for the registry entry",Xt=`Passphrase for the encrypted private key (min ${15} chars)`,zt="Confirm passphrase",Wt=o(()=>`Passphrase must be at least ${15} characters`,"passphraseTooShortMsg"),qt=o(e=>`Passphrases do not match (attempt ${e}/${ie}).
|
|
113
|
+
`,"passphraseMismatchMsg"),Qt=`Passphrase confirmation failed after ${ie} attempts`;async function Oe(e){return ri.prompt(e)}o(Oe,"defaultPrompt");function Zt(e){return t=>{try{return e(t),!0}catch(n){return n instanceof Error?n.message:"Invalid"}}}o(Zt,"parserAsValidator");async function en(e={}){let{prompt:t=Oe}=e,{months:n}=await t({type:"input",name:"months",message:Yt,initial:String(6),validate:Zt(r=>q(r,"expiry"))});return q(n,"expiry")}o(en,"promptExpiryMonths");async function tn(e={}){let{prompt:t=Oe,gitUserEmail:n=Gt}=e,{email:r}=await t({type:"input",name:"email",message:Jt,initial:n(),validate:Zt(i=>W(i,"email"))});return W(r,"email")}o(tn,"promptEmail");async function nn(e={}){let{prompt:t=Oe,stderr:n=process.stderr}=e;for(let r=1;r<=ie;r+=1){let{passphrase:i}=await t({type:"password",name:"passphrase",message:Xt,validate:o(a=>a.length>=15?!0:Wt(),"validate")}),{confirm:s}=await t({type:"password",name:"confirm",message:zt});if(i===s)return i;n.write(qt(r))}throw new Error(Qt)}o(nn,"promptPassphrase");function ai(e){return{writeFileSync:e.writeFileSync??si,mkdirSync:e.mkdirSync??ii,existsSync:e.existsSync??oi,generateSigningKeyPair:e.generateSigningKeyPair??Lt,encryptStringAsJwe:e.encryptStringAsJwe??Ut,storeKeyInKeychain:e.storeKeyInKeychain??Ft,isMacOS:e.isMacOS??K,promptExpiryMonths:e.promptExpiryMonths??en,promptEmail:e.promptEmail??tn,promptPassphrase:e.promptPassphrase??nn,discoverLocalKeys:e.discoverLocalKeys??(()=>jt())}}o(ai,"resolveDeps");function on(e,t={}){let n=ai(t),r=e.command("keys").description("Manage code signing keys");r.command("generate").description("Generate an Ed25519 keypair for code signing").option("-o, --output <path>","Encrypted private key output path (forces file storage even on macOS)").option("--no-keychain","Skip macOS Keychain and write a passphrase-encrypted private key under ~/.dune/keys/ instead").option("-e, --expires <months>",`Validity in months (${1}-${12}); skips the interactive prompt`).option("--email <address>","Email address for the registry entry; skips the interactive prompt").action(i=>li(i,n)),r.command("list").description("List local signing identities and their storage location").action(()=>ci(n))}o(on,"registerKeysCommand");async function ci(e){let t=await e.discoverLocalKeys();if(t.length===0){process.stdout.write(`No signing identities found.
|
|
114
|
+
`),process.stdout.write(`Run \`cognite keys generate\` to create one (storage: ${j().keysDir}).
|
|
115
|
+
`);return}let n=["KID","SOURCE","EMAIL"],r=t.map(a=>[a.kid,Kt(a.source),a.email??"\u2014"]),i=n.map((a,c)=>Math.max(a.length,...r.map(p=>p[c].length))),s=o(a=>a.map((c,p)=>c.padEnd(i[p])).join(" ").trimEnd(),"fmt");process.stdout.write(`${s(n)}
|
|
116
|
+
`);for(let a of r)process.stdout.write(`${s(a)}
|
|
117
|
+
`)}o(ci,"handleList");function rn(e,t,n){let r=Ue(j().keysDir,`${e}${oe}`);return n.mkdirSync(_e(r),{recursive:!0}),n.writeFileSync(r,t),r}o(rn,"writePublicKey");async function pi(e,t,n,r,i){let s=r??Ue(j().keysDir,`${e}${De}`);if(i.mkdirSync(_e(s),{recursive:!0}),i.existsSync(s))throw new Error(`Refusing to overwrite existing key at ${s}. Delete it first if you really want to regenerate: rm ${s}`);let a=await i.encryptStringAsJwe(t,n);return i.writeFileSync(s,a,{mode:384}),s}o(pi,"writeEncryptedPrivateKey");async function li(e,t,n=new Date){let r=e.keychain!==!1&&t.isMacOS()&&!e.output,i=e.expires!==void 0?q(e.expires):await t.promptExpiryMonths(),s=Te(Mt(n,i)),a=e.email!==void 0?W(e.email,"--email"):await t.promptEmail(),c=r?null:await t.promptPassphrase();process.stderr.write(`
|
|
118
|
+
Generating Ed25519 keypair...
|
|
119
|
+
|
|
120
|
+
`);let{privateKeyPem:p,publicKeyPem:l,kid:m}=await t.generateSigningKeyPair();if(r){await t.storeKeyInKeychain(m,p);let f=rn(m,l,t);process.stderr.write(`Public key: ${f}
|
|
121
|
+
`),process.stderr.write(`Private key: macOS Keychain (service: cognite-dune, account: ${m})
|
|
122
|
+
`)}else{if(c===null)throw new Error("passphrase is required when not using Keychain");let f=await pi(m,p,c,e.output,t),g=rn(m,l,t);process.stderr.write(`Public key: ${g}
|
|
123
|
+
`),process.stderr.write(`Private key: ${f} (JWE, AES-256-GCM, PBKDF2-SHA512 x${ke.toLocaleString()})
|
|
124
|
+
`),t.isMacOS()||process.stderr.write(` (macOS Keychain integration is the default on darwin; on this OS we use the file.)
|
|
125
|
+
`)}let d=Ue(j().keysDir,`${m}${Ie}`);t.mkdirSync(_e(d),{recursive:!0}),t.writeFileSync(d,JSON.stringify({email:a}));let u=Ht(process.stderr);process.stderr.write(`
|
|
126
|
+
Signing identity (kid): ${u.green(m)}
|
|
127
|
+
`),process.stderr.write(`Expires: ${s} (${i} month${i===1?"":"s"} from today)
|
|
128
|
+
`),process.stderr.write(Bt({kid:m,publicKeyPem:l,email:a,expires:s},u,n)),process.stderr.write(`
|
|
129
|
+
${u.bold("Next:")} open a PR against the ${u.magenta("infrastructure")} repo with that block, then \`${u.cyan(`cognite sign -s ${m}`)}\`
|
|
130
|
+
`)}o(li,"handleGenerate");var sn=1e3,mi=new Set(["baseUrl","url","project","deployment","source","path","name","displayName","description"]);function di(e){return Object.fromEntries(Object.entries(e).map(([t,n])=>typeof n=="boolean"?[t,n]:mi.has(t)?[t,n]:[t,"[REDACTED]"]))}o(di,"sanitize");function ui(e){let t=[],n=e;for(;n;)n.parent&&t.unshift(n.name()),n=n.parent;return t.join(" ")}o(ui,"getCommandPath");function an(e){try{let t=e(process.cwd());return{appExternalId:t.externalId,appVersionTag:t.versionTag}}catch{return{}}}o(an,"tryLoadAppConfig");function Le(e){return e.filter(t=>!t.startsWith("-")).join(" ")||"unknown"}o(Le,"commandFromArgv");function cn(e,t,n=w){e.hook("postAction",async(r,i)=>{try{let s={command:ui(i),options:di(i.opts()),success:!0,...an(n)};t.track("Flows.CLI.Command",s),await t.flush(sn)}catch{}})}o(cn,"instrument");async function pn(e,t,n=w){try{let r={command:Le(t),options:{},success:!1,...an(n)};e.track("Flows.CLI.Command",r),await e.flush(sn)}catch{}}o(pn,"trackFailure");var gi="ERR_USE_AFTER_CLOSE";function mn(e){return e instanceof Error&&"code"in e&&e.code===gi}o(mn,"isReadlineClosedError");function fi(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}o(fi,"isPlainObject");function Ne(e){return e==null||mn(e)?!0:e instanceof Error?!1:!!(typeof e=="object"&&e!==null&&fi(e)&&Object.keys(e).length===0)}o(Ne,"isPromptCancel");var ln=!1;function dn(){ln||(ln=!0,process.on("uncaughtException",e=>{mn(e)&&(console.error(`
|
|
131
|
+
Cancelled.`),process.exit(130)),console.error(e),process.exit(1)}),process.on("unhandledRejection",e=>{Ne(e)&&(console.error(`
|
|
132
|
+
Cancelled.`),process.exit(130)),console.error(e),process.exit(1)}))}o(dn,"installCancelHandler");import un from"mixpanel";var yi="5c4d853e7c3b77b1eb4468d5329b278c",Q="cognite-cli",hi=2e3,gn={env:process.env,init:un.init.bind(un)},Ei={track:o(()=>{},"track"),flush:o(async()=>{},"flush")};function Ke(e=process.env){return e.COGNITE_TELEMETRY_DISABLED==="1"||e.DO_NOT_TRACK==="1"}o(Ke,"isTelemetryDisabled");function wi(e){return e.COGNITE_TELEMETRY_DEBUG==="1"}o(wi,"isDebug");function fn(e={}){let t=e.env??gn.env,n=e.init??gn.init,r=e.packageName,i=e.cliVersion,s=wi(t);if(Ke(t))return s&&process.stderr.write(`[telemetry] disabled \u2014 noop tracker
|
|
133
|
+
`),Ei;let a,c=new Set;function p(){if(a)return a;try{return a=n(yi,{geolocate:!1,keepAlive:!1}),a}catch{return}}return o(p,"getClient"),{track(l,m={}){let d=p();if(!d)return;let u={...m,applicationId:Q,...r&&{packageName:r},...i&&{cliVersion:i},nodeVersion:process.version,platform:process.platform};s&&process.stderr.write(`[telemetry] track ${l} ${JSON.stringify(u)}
|
|
134
|
+
`);let f=o(()=>{},"finish"),g=new Promise(b=>{f=b});c.add(g);try{d.track(l,u,f)}catch{f()}g.finally(()=>c.delete(g))},async flush(l=hi){if(c.size===0)return;let m,d=new Promise(u=>{m=setTimeout(u,l),m.unref?.()});try{await Promise.race([Promise.allSettled([...c]),d])}finally{m&&clearTimeout(m)}s&&process.stderr.write(`[telemetry] flush done (${c.size} still pending)
|
|
135
|
+
`)}}}o(fn,"createTelemetry");var Si=1e3,Ci="https://0a118cb02e3be57b1838bcfb5783a2bf@o4508040730968064.ingest.de.sentry.io/4510719268290640",vi={captureError:o(async()=>{},"captureError"),flush:o(async()=>{},"flush")};function xi(e){return e.packageName&&e.cliVersion?`${e.packageName}@${e.cliVersion}`:e.cliVersion??"unknown"}o(xi,"buildRelease");var Pi="192.0.2.0";function bi(e){let t={...e.user,email:void 0,username:void 0,ip_address:Pi,id:void 0};return{...e,user:t,server_name:void 0}}o(bi,"scrubPii");function yn(e={}){let t=e.env??process.env;if(Ke(t))return vi;let n=xi(e),r="production",i=null,s=null;function a(){return{dsn:Ci,release:n,environment:r,defaultIntegrations:!1,integrations:[],sendDefaultPii:!1,enableLogs:!1,initialScope:{tags:{component:"cli",applicationId:Q},contexts:{cli:{applicationId:Q,node:process.version,platform:process.platform}}},beforeSend:bi}}o(a,"buildInitOptions");async function c(){return i||(s||(s=(async()=>{try{let p=e.sdk??await import("@sentry/node");return p.init(a()),i=p,p}catch{return null}})()),s)}return o(c,"ensureSdk"),{async captureError(p,l){try{let m=await c();if(!m)return;let d={level:"fatal"};l?.command&&(d.tags={command:l.command},d.contexts={cli:{applicationId:Q,node:process.version,platform:process.platform,command:l.command}}),m.captureException(p,d)}catch{}},async flush(p=Si){try{if(!i)return;await i.flush(p)}catch{}}}}o(yn,"createErrorReporter");import{mkdirSync as Ai,readFileSync as ki,writeFileSync as Di}from"fs";import{homedir as Ii}from"os";import{resolve as se}from"path";import{debuglog as Ti}from"util";import{lt as $i,parse as hn}from"semver";var Fi="https://registry.npmjs.org/@cognite/cli/latest",Ri=1500,En="upgrade-check.json",wn=se(process.env.XDG_CACHE_HOME||se(Ii(),".cache"),"@cognite","cli"),je=Ti("cognite-flows");function Oi(e,t){return!e||!t||!hn(e)||!hn(t)?!1:$i(e,t)}o(Oi,"isOutdated");async function _i({timeout:e=Ri,registryUrl:t=Fi,fetchImpl:n=globalThis.fetch}={}){if(typeof n!="function")return null;try{let r=await n(t,{signal:AbortSignal.timeout(e)});if(!r?.ok)return null;let i=await r.json();return typeof i?.version=="string"?i.version:null}catch(r){return je("fetchLatestVersion failed (%s): %O",t,r),null}}o(_i,"fetchLatestVersion");function Ui(e=wn,t=864e5){try{let n=ki(se(e,En),"utf-8"),r=JSON.parse(n);return typeof r.latest!="string"||typeof r.fetchedAt!="number"||Date.now()-r.fetchedAt>t?null:{latest:r.latest,fetchedAt:r.fetchedAt}}catch(n){return je("readUpgradeCheckCache failed (%s): %O",e,n),null}}o(Ui,"readUpgradeCheckCache");function Li(e,t){try{Ai(e,{recursive:!0});let n={latest:t,fetchedAt:Date.now()};Di(se(e,En),JSON.stringify(n))}catch(n){je("writeUpgradeCheckCache failed (%s): %O",e,n)}}o(Li,"writeUpgradeCheckCache");async function Ni({cacheDir:e=wn,...t}={}){let n=await _i(t);n&&Li(e,n)}o(Ni,"startBackgroundUpgradeCheck");function Sn(e,{onOutdated:t,cacheDir:n,...r}={}){let i=Ui(n);if(i){Oi(e,i.latest)&&t?.(e,i.latest);return}Ni({cacheDir:n,...r})}o(Sn,"preActionUpgradeCheck");import{default as $l,chalkStderr as Cn}from"chalk";function vn(e,t){let n=[`\u26A0 Update available: ${e} -> ${t}`," Run npx @cognite/cli@latest"],r=Math.max(...n.map(c=>[...c].length))+2,i="\u2500".repeat(r),s=o(c=>`\u2502 ${c}${" ".repeat(r-1-[...c].length)}\u2502`,"pad"),a=[`\u250C${i}\u2510`,...n.map(s),`\u2514${i}\u2518`].join(`
|
|
136
|
+
`);return Cn.bold.yellow(a)}o(vn,"formatUpgradeWarning");function Mi(e){return e instanceof Error&&"code"in e&&typeof e.code=="string"&&e.code==="DEP0040"}o(Mi,"isDep0040Warning");var Ve=process,Vi=Ve.emit.bind(Ve);Ve.emit=function(e,...t){return e==="warning"&&Mi(t[0])?!1:Vi(e,...t)};dn();var B=new ji;B.name("cognite").description("Build and deploy React apps to Cognite Data Fusion").version("1.1.0").showHelpAfterError().configureOutput({writeOut:o(e=>Ki(1,e),"writeOut")});B.hook("preAction",()=>{Sn("1.1.0",{onOutdated:o((e,t)=>{console.warn(`
|
|
137
|
+
${vn(e,t)}
|
|
138
|
+
`)},"onOutdated")})});It(B);on(B);var Pn=fn({packageName:"@cognite/cli",cliVersion:"1.1.0"}),xn=yn({packageName:"@cognite/cli",cliVersion:"1.1.0"});cn(B,Pn);var Me=process.argv.slice(2);B.parseAsync(Me,{from:"user"}).catch(async e=>{await pn(Pn,Me),Ne(e)&&(console.error(`
|
|
139
|
+
Cancelled.`),process.exit(130)),await xn.captureError(e,{command:Le(Me)}),await xn.flush(),console.error(e instanceof Error?`\u274C ${e.message}`:e),process.exit(1)});
|
package/dist/deploy/index.d.ts
CHANGED
|
@@ -87,14 +87,10 @@ declare class AppHostingClient {
|
|
|
87
87
|
*
|
|
88
88
|
* Handles packaging of build directories into deployment-ready zip files.
|
|
89
89
|
*/
|
|
90
|
-
interface ApplicationPackagerOptions {
|
|
91
|
-
requireLockFile?: boolean;
|
|
92
|
-
}
|
|
93
90
|
declare class ApplicationPackager {
|
|
94
91
|
private distPath;
|
|
95
92
|
private appRoot;
|
|
96
|
-
|
|
97
|
-
constructor(distDirectory?: string, options?: ApplicationPackagerOptions);
|
|
93
|
+
constructor(distDirectory?: string);
|
|
98
94
|
validateBuildDirectory(): void;
|
|
99
95
|
createZip(outputFilename?: string, verbose?: boolean): Promise<string>;
|
|
100
96
|
}
|
package/dist/deploy/index.js
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
import{a
|
|
2
|
-
See: ${j}`;case 403:return`You don't have the required CDF capabilities. Please contact your CDF admin.
|
|
3
|
-
See: ${j}`;default:return}}s(K,"httpStatusHint");function w(e){let t=e instanceof Error?e:new Error(String(e));if(!S(t))return null;let n=K(t.status);return n?Object.assign(new Error(`${t.message}
|
|
4
|
-
${n}`),{cause:t}):null}s(w,"enrichedHttpError");function W(e){if(!f(e))return null;let t=e.missing;if(Array.isArray(t))return t;let n=e.data;if(f(n)){let r=n.error;if(f(r)&&Array.isArray(r.missing))return r.missing;if(Array.isArray(n.missing))return n.missing}return null}s(W,"findMissingArray");function Z(e,t){if(!S(e)||e.status!==400)return!1;let n=W(e);return n?n.some(r=>f(r)&&typeof r.externalId=="string"&&t.includes(r.externalId)):!1}s(Z,"isMissingExternalIdError");function x(e,t){return S(e)&&e.status===404||Z(e,t)}s(x,"isNotFoundError");var H=["DRAFT","PUBLISHED","DEPRECATED","ARCHIVED"],q=["ACTIVE","PREVIEW"],I=class I extends Error{constructor(t,n){super(`Version ${n} of app ${t} not found`),this.name="AppVersionNotFoundError",this.appExternalId=t,this.version=n}};s(I,"AppVersionNotFoundError");var C=I;function M(e,t){return e.includes(t)}s(M,"includesValue");function X(e){return M(H,e)}s(X,"isAppVersionLifecycleState");function Q(e){return M(q,e)}s(Q,"isAppVersionAlias");function tt(e){return typeof e.version=="string"&&X(e.lifecycleState)&&typeof e.entrypoint=="string"&&typeof e.createdTime=="number"&&typeof e.createdBy=="string"&&typeof e.appExternalId=="string"&&(e.alias===void 0||Q(e.alias))&&(e.comment===void 0||typeof e.comment=="string")}s(tt,"isAppVersion");function N(e){if(!f(e))throw new Error("Invalid version response: not an object");if(!tt(e))throw new Error("Invalid version response: missing or malformed fields");return e}s(N,"parseAppVersion");var T=class T{constructor(t){this.client=t}get appsBasePath(){return`/api/v1/projects/${encodeURIComponent(this.client.project)}/apphosting/apps`}async createApp(t,n,r){try{await this.client.post(this.appsBasePath,{data:{items:[{externalId:t,name:n,description:r}]}})}catch(o){throw w(o)??o}}async uploadVersion(t,n,r,o,i="index.html"){console.log(`\u{1F4E4} Uploading version ${n}...`);let c=new FormData;c.append("file",new Blob([new Uint8Array(r)]),o),c.append("version",n),c.append("entryPath",i);let p=encodeURIComponent(t),a=`${this.appsBasePath}/${p}/versions`,l=await this.client.authenticate(),h=`${this.client.getBaseUrl()}${a}`,d=new AbortController,Y=setTimeout(()=>d.abort(),300*1e3),y;try{y=await fetch(h,{method:"POST",headers:{Authorization:`Bearer ${l}`},body:c,signal:d.signal})}catch(g){throw g instanceof Error&&g.name==="AbortError"?new Error("Upload timed out after 5 minutes"):g}finally{clearTimeout(Y)}if(!y.ok){let g=await y.text(),V=g;try{let $=JSON.parse(g);if(f($)){let A=$.error;if(typeof A=="string")V=A;else if(f(A)){let E=A.message,B=A.code;V=typeof E=="string"?E:B!=null?`Unknown error (code: ${B})`:g}else{let E=$.message;V=typeof E=="string"?E:g}}}catch{}let O=y.headers.get("x-request-id"),G=O?` | X-Request-ID: ${O}`:"",U=Object.assign(new Error(`Upload failed: ${y.status} \u2014 ${V}${G}`),{status:y.status});throw w(U)??U}console.log(`\u2705 Version ${n} uploaded`)}async getVersion(t,n){let r=encodeURIComponent(t),o=encodeURIComponent(n),i=`${this.appsBasePath}/${r}/versions/${o}`;try{let c=await this.client.get(i);return N(c.data)}catch(c){throw x(c,[t,n])?new C(t,n):w(c)??c}}async getActiveVersion(t){let n=encodeURIComponent(t),r=`${this.appsBasePath}/${n}/active`;try{let o=await this.client.get(r);return N(o.data)}catch(o){if(x(o,[t]))return null;throw w(o)??o}}async updateVersions(t,n){let r=encodeURIComponent(t),o=`${this.appsBasePath}/${r}/versions/update`;try{await this.client.post(o,{data:{items:n}})}catch(i){throw w(i)??i}}};s(T,"AppHostingApi");var v=T;var b=class b{constructor(t){this.api=new v(t)}getVersion(t,n){return this.api.getVersion(t,n)}uploadVersion(t,n,r,o,i){return this.api.uploadVersion(t,n,r,o,i)}async ensureApp(t,n,r){console.log("\u{1F50D} Ensuring app exists...");try{await this.api.createApp(t,n,r),console.log(`\u2705 App '${t}' created`)}catch(o){if(S(o)&&o.status===409){console.log(`\u2705 App '${t}' already exists`);return}throw o}}async publishVersion(t,n){await this.api.updateVersions(t,[{version:n,update:{lifecycleState:{set:"PUBLISHED"}}}])}async publishAndActivate(t,n){console.log(`\u{1F680} Publishing and activating version ${n}...`),await this.api.updateVersions(t,[{version:n,update:{lifecycleState:{set:"PUBLISHED"},alias:{set:"ACTIVE"}}}]),console.log(`\u2705 Version ${n} is now PUBLISHED and ACTIVE`)}async activateVersion(t,n){let r=null;try{r=await this.api.getActiveVersion(t)}catch{r=null}let o=r&&r.version!==n?r.version:void 0;return await this.api.updateVersions(t,[{version:n,update:{alias:{set:"ACTIVE"}}}]),{supersededVersion:o}}async deploy(t,n,r,o,i,c,p=!1){console.log(`
|
|
5
|
-
\u{1F680} Deploying application via App Hosting API...
|
|
6
|
-
`);try{await this.ensureApp(t,n,r),await this.uploadVersion(t,o,i,c),p&&await this.publishAndActivate(t,o),console.log(`
|
|
7
|
-
\u2705 Deployment successful!`)}catch(a){let l=a instanceof Error?a.message:String(a);throw Object.assign(new Error(`Deployment failed: ${l}`),{cause:a})}}};s(b,"AppHostingClient");var P=b;import m from"fs";import u from"path";import{parseAndValidateManifestConfig as et}from"@cognite/app-sdk/vite";import{BlobReader as nt,Uint8ArrayWriter as rt,ZipWriter as ot}from"@zip.js/zip.js";var R="package.json",L="package-lock.json",z="manifest.json",D=class D{constructor(t="dist",n={}){this.distPath=u.isAbsolute(t)?t:u.join(process.cwd(),t),this.appRoot=u.dirname(this.distPath),this.requireLockFile=n.requireLockFile??!1}validateBuildDirectory(){if(!m.existsSync(this.distPath))throw new Error(`Build directory "${this.distPath}" not found. Run build first.`);let t=u.join(this.appRoot,R);if(!m.existsSync(t))throw new Error(`"${t}" not found. It is required for deployment.`);if(this.requireLockFile){let n=u.join(this.appRoot,L);if(!m.existsSync(n))throw new Error(`"${n}" not found. It is required for deployment.`)}}async createZip(t="app.zip",n=!1){this.validateBuildDirectory(),console.log("\u{1F4E6} Packaging application...");let r=new ot(new rt,{level:9}),o=s(async(a,l)=>{await r.add(l,new nt(await m.openAsBlob(a))),n&&console.log(` \u{1F4C4} ${l}`)},"addFile"),i=s(async a=>{let l=await m.promises.readdir(a,{withFileTypes:!0});for(let h of l){let d=u.join(a,h.name);h.isDirectory()?await i(d):await o(d,u.relative(this.distPath,d).replace(/\\/g,"/"))}},"addDir"),c;try{await i(this.distPath),await o(u.join(this.appRoot,R),R);let a=u.join(this.appRoot,z);if(m.existsSync(a)){let l=m.readFileSync(a,"utf-8");et(l,a),await o(a,z)}this.requireLockFile&&await o(u.join(this.appRoot,L),L),c=await r.close()}catch(a){let l=a instanceof Error?a.message:String(a);throw new Error(`Failed to create zip: ${l}`)}await m.promises.writeFile(t,c);let p=(c.byteLength/1024/1024).toFixed(2);return console.log(`\u2705 App packaged: ${t} (${p} MB)`),t}};s(D,"ApplicationPackager");var k=D;import{CogniteClient as lt}from"@cognite/sdk";var st=s(()=>{let e=process.env.DEPLOYMENT_SECRETS;if(!e)return{};try{let t=JSON.parse(e),n={};for(let[r,o]of Object.entries(t))if(typeof o=="string"){let i=r.toLowerCase().replace(/_/g,"-");n[i]=o}return n}catch(t){return console.error("Error parsing DEPLOYMENT_SECRETS:",t),{}}},"loadSecretsFromEnv"),it=s(e=>{let t;if(process.env.DEPLOYMENT_SECRET&&(t=process.env.DEPLOYMENT_SECRET),t||(t=st()[e]),t||(t=process.env[e]),!t)throw new Error(`Secret not found in environment: ${e}`);return t},"getSecretFromEnv"),at=s(e=>{if(!e)return"";try{return new URL(e).hostname.replace(/\.cognitedata\.com$/,"")}catch{let t=e.replace(/^https?:\/\//,"");return t=t.split("/")[0],t=t.split(":")[0],t=t.replace(/\.cognitedata\.com$/,""),t}},"extractClusterFromUrl"),ct=s(async(e,t)=>{let n=`Basic ${btoa(`${e}:${t}`)}`,r=await fetch("https://auth.cognite.com/oauth2/token",{method:"POST",headers:{Authorization:n,"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"client_credentials"})});if(!r.ok){let i=await r.text();throw new Error(`Failed to get token from CDF: ${r.status} ${r.statusText}
|
|
8
|
-
${i}`)}let o=await r.json();if(!o.access_token)throw new Error("No access token returned from CDF authentication");return o.access_token},"getTokenCdf"),pt=s(async(e,t,n,r)=>{if(!r)throw new Error("Entra ID authentication requires 'baseUrl' to be set in deployment configuration");let o=at(r);if(!o)throw new Error(`Entra ID authentication requires 'baseUrl' to be a valid CDF URL (e.g., https://cluster.cognitedata.com), got: ${r}`);let i=`https://login.microsoftonline.com/${n}/oauth2/v2.0/token`,c=`https://${o}.cognitedata.com/.default`,p=await fetch(i,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({client_id:e,client_secret:t,scope:c,grant_type:"client_credentials"})});if(!p.ok){let l=await p.text();throw new Error(`Failed to get token from Entra ID: ${p.status} ${p.statusText}
|
|
9
|
-
${l}`)}let a=await p.json();if(!a.access_token)throw new Error("No access token returned from Entra ID authentication");return a.access_token},"getTokenEntra"),_=s(async(e,t=process.env)=>{if(t.COGNITE_TOKEN)return t.COGNITE_TOKEN;let{deployClientId:n,deploySecretName:r,idpType:o="cdf",tenantId:i,baseUrl:c}=e,p=it(r);if(o==="entra_id"){if(!i)throw new Error("Entra ID authentication requires 'tenantId' in deployment configuration");return pt(n,p,i,c)}return ct(n,p)},"getToken");var F=s(async(e,t,n=process.env)=>{let r=await _(e,n),o=n.COGNITE_BASE_URL??e.baseUrl,i=new lt({appId:t,project:e.project,baseUrl:o,oidcTokenProvider:s(async()=>r,"oidcTokenProvider")});return await i.authenticate(),i},"getSdk");var dt=s(async(e,t,n)=>{let r=await new k(`${n}/dist`,{requireLockFile:!0}).createZip("app.zip",!0);try{let{externalId:o,name:i,description:c,versionTag:p}=t,a=await F(e,n),l=new P(a),h=J.readFileSync(r),d=ut.basename(r);await l.deploy(o,i,c,p,h,d,e.published)}finally{try{J.unlinkSync(r)}catch{}}},"deploy");export{P as AppHostingClient,k as ApplicationPackager,dt as deploy,F as getSdk,_ as getToken};
|
|
1
|
+
import{a,b,c,d,e}from"../chunk-VJMFH4MH.js";export{a as AppHostingClient,b as ApplicationPackager,e as deploy,d as getSdk,c as getToken};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import 'react/jsx-runtime';
|
|
3
|
-
import 'react';
|
|
1
|
+
export { App, AppHostingClient, ApplicationPackager, Deployment, deploy, getSdk, getToken } from './deploy/index.js';
|
|
4
2
|
import '@cognite/sdk';
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o,b as r,c as e,d as f,e as m
|
|
1
|
+
import{a as o,b as r,c as e,d as f,e as m}from"./chunk-VJMFH4MH.js";export{o as AppHostingClient,r as ApplicationPackager,m as deploy,f as getSdk,e as getToken};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cognite/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "CLI for Cognite Data Fusion",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Cognite",
|
|
@@ -18,21 +18,10 @@
|
|
|
18
18
|
"import": "./dist/index.js",
|
|
19
19
|
"default": "./dist/index.js"
|
|
20
20
|
},
|
|
21
|
-
"./auth": {
|
|
22
|
-
"types": "./dist/auth/index.d.ts",
|
|
23
|
-
"import": "./dist/auth/index.js",
|
|
24
|
-
"default": "./dist/auth/index.js"
|
|
25
|
-
},
|
|
26
21
|
"./deploy": {
|
|
27
22
|
"types": "./dist/deploy/index.d.ts",
|
|
28
23
|
"import": "./dist/deploy/index.js",
|
|
29
24
|
"default": "./dist/deploy/index.js"
|
|
30
|
-
},
|
|
31
|
-
"./vite": {
|
|
32
|
-
"types": "./dist/vite/index.d.ts",
|
|
33
|
-
"development": "./src/vite/index.ts",
|
|
34
|
-
"import": "./dist/vite/index.js",
|
|
35
|
-
"default": "./dist/vite/index.js"
|
|
36
25
|
}
|
|
37
26
|
},
|
|
38
27
|
"bin": {
|
|
@@ -100,7 +89,7 @@
|
|
|
100
89
|
"react-dom": "^19.2.6",
|
|
101
90
|
"tsup": "^8.4.0",
|
|
102
91
|
"typescript": "^5.0.0",
|
|
103
|
-
"vitest": "^2.
|
|
92
|
+
"vitest": "^3.2.4"
|
|
104
93
|
},
|
|
105
94
|
"engines": {
|
|
106
95
|
"node": ">=20"
|
package/dist/auth/index.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as react from 'react';
|
|
3
|
-
import { ReactNode } from 'react';
|
|
4
|
-
import { CogniteClient } from '@cognite/sdk';
|
|
5
|
-
|
|
6
|
-
interface AppSdkAuthProviderProps {
|
|
7
|
-
children: ReactNode;
|
|
8
|
-
loadingComponent?: ReactNode;
|
|
9
|
-
errorComponent?: (error: string) => ReactNode;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Auth provider for apps running in the new Fusion app host (dune-app-host).
|
|
13
|
-
* Uses @cognite/app-sdk's Comlink handshake to connect to the host and obtain
|
|
14
|
-
* tokens on-demand. Exposes the same DuneContextValue ({ sdk, isLoading,
|
|
15
|
-
* error }) as DuneAuthProvider so useDune() works unchanged.
|
|
16
|
-
*/
|
|
17
|
-
declare const AppSdkAuthProvider: ({ children, loadingComponent, errorComponent, }: AppSdkAuthProviderProps) => react_jsx_runtime.JSX.Element;
|
|
18
|
-
|
|
19
|
-
interface DuneContextValue {
|
|
20
|
-
sdk: CogniteClient;
|
|
21
|
-
isLoading: boolean;
|
|
22
|
-
error?: string;
|
|
23
|
-
}
|
|
24
|
-
declare const DuneAuthProviderContext: react.Context<DuneContextValue>;
|
|
25
|
-
interface DuneAuthProviderProps {
|
|
26
|
-
children: ReactNode;
|
|
27
|
-
useIFrameAuthentication?: boolean;
|
|
28
|
-
useLocalConfiguration?: {
|
|
29
|
-
org: string;
|
|
30
|
-
project: string;
|
|
31
|
-
baseUrl: string;
|
|
32
|
-
};
|
|
33
|
-
loadingComponent?: ReactNode;
|
|
34
|
-
errorComponent?: (error: string) => ReactNode;
|
|
35
|
-
}
|
|
36
|
-
declare const DuneAuthProvider: ({ children, loadingComponent, errorComponent, }: DuneAuthProviderProps) => react_jsx_runtime.JSX.Element;
|
|
37
|
-
|
|
38
|
-
declare const useDune: () => DuneContextValue;
|
|
39
|
-
|
|
40
|
-
interface CDFConfig {
|
|
41
|
-
project: string;
|
|
42
|
-
baseUrl: string;
|
|
43
|
-
clientId: string;
|
|
44
|
-
clientSecret: string;
|
|
45
|
-
appId?: string;
|
|
46
|
-
}
|
|
47
|
-
declare const getToken: (clientId: string, clientSecret: string) => Promise<any>;
|
|
48
|
-
declare const createCDFSDK: (config: CDFConfig) => Promise<CogniteClient>;
|
|
49
|
-
declare const EMPTY_SDK: CogniteClient;
|
|
50
|
-
|
|
51
|
-
export { AppSdkAuthProvider, type CDFConfig, DuneAuthProvider, DuneAuthProviderContext, type DuneAuthProviderProps, type DuneContextValue, EMPTY_SDK, createCDFSDK, getToken, useDune };
|
package/dist/auth/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g}from"../chunk-QGJ3VKXY.js";import"../chunk-EI7MMDWY.js";export{f as AppSdkAuthProvider,e as DuneAuthProvider,d as DuneAuthProviderContext,c as EMPTY_SDK,b as createCDFSDK,a as getToken,g as useDune};
|
package/dist/chunk-EI7MMDWY.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var c=Object.defineProperty;var d=(a,b)=>c(a,"name",{value:b,configurable:!0});export{d as a};
|
package/dist/chunk-QGJ3VKXY.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as t}from"./chunk-EI7MMDWY.js";import{connectToHostApp as b}from"@cognite/app-sdk";import{CogniteClient as U}from"@cognite/sdk";import{useEffect as N,useState as v}from"react";import{CogniteClient as R}from"@cognite/sdk";import{createContext as I,useEffect as L,useState as P}from"react";import{CogniteClient as A}from"@cognite/sdk";var D=t(async(n,e)=>{let o=`Basic ${btoa(`${n}:${e}`)}`;return(await(await fetch("https://auth.cognite.com/oauth2/token",{method:"POST",headers:{Authorization:o,"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"client_credentials"})})).json()).access_token},"getToken"),T=t(async n=>{let{project:e,baseUrl:o,clientId:r,clientSecret:d,appId:c="cdf-authentication-package"}=n;if(!e||!o||!r||!d)throw new Error("Missing required configuration. Please provide: project, baseUrl, clientId, clientSecret");let u=new A({appId:c,project:e,baseUrl:o,oidcTokenProvider:t(async()=>await D(r,d),"oidcTokenProvider")});return await u.authenticate(),u},"createCDFSDK"),p=new A({appId:"cdf-authentication-package",project:"",oidcTokenProvider:t(async()=>"","oidcTokenProvider")}),E=t(()=>{console.log("\u{1F511} Requesting credentials from parent..."),window.parent&&window.parent!==window&&window.parent.postMessage({type:"REQUEST_CREDENTIALS"},"*")},"requestCredentials"),S=t(n=>{if(n.data?.type==="PROVIDE_CREDENTIALS"&&n.data?.credentials){let e=n.data.credentials;if(e.token&&e.baseUrl&&e.project)return console.log("\u{1F389} useCredentials received credentials:",{hasToken:!!e.token,tokenLength:e.token?.length||0,project:e.project,baseUrl:e.baseUrl}),e}},"handleCredentialsResponse");import{Fragment as w,jsx as l,jsxs as x}from"react/jsx-runtime";var g=I({sdk:p,isLoading:!1}),y=t(({children:n,loadingComponent:e=l("div",{children:"Loading CDF authentication..."}),errorComponent:o=t(r=>x("div",{children:["Authentication error: ",r]}),"errorComponent")})=>l(_,{loadingComponent:e,errorComponent:o,children:n}),"DuneAuthProvider"),_=t(({children:n,loadingComponent:e=l("div",{children:"Loading CDF authentication..."}),errorComponent:o=t(r=>x("div",{children:["Authentication error: ",r]}),"errorComponent")})=>{let[r,d]=P(!0),[c,u]=P(p),[s]=P();return L(()=>{E();let f=t(async i=>{console.log("\u{1F50D} Handling message from Fusion");let a=S(i);if(!a)return;let h=new R({appId:"dune-app",project:a.project,baseUrl:a.baseUrl,oidcTokenProvider:t(async()=>a.token,"oidcTokenProvider")});await h.authenticate(),u(h),d(!1)},"handleMessage");return console.log("\u{1F50D} Adding message listener"),window.addEventListener("message",f),()=>window.removeEventListener("message",f)},[]),console.log("\u{1F50D} CDFIframeAuthenticationInnerProvider",c,r,s),s&&o?l(w,{children:o(s)}):r&&e?l(w,{children:e}):l(g.Provider,{value:{sdk:c,isLoading:r,error:s},children:n})},"FusionIframeAuthenticationInnerProvider");import{Fragment as k,jsx as C,jsxs as j}from"react/jsx-runtime";var F=t(({children:n,loadingComponent:e=C("div",{children:"Loading CDF authentication..."}),errorComponent:o=t(r=>j("div",{children:["Authentication error: ",r]}),"errorComponent")})=>{let[r,d]=v(p),[c,u]=v(!0),[s,f]=v();return N(()=>{b().then(async({api:i})=>{let[a,h]=await Promise.all([i.getProject(),i.getBaseUrl()]),m=new U({appId:"dune-app",project:a,baseUrl:h,oidcTokenProvider:t(async()=>i.getAccessToken(),"oidcTokenProvider")});await m.authenticate(),d(m),f(void 0)}).catch(i=>{let a=i instanceof Error?i.message:String(i);f(a)}).finally(()=>{u(!1)})},[]),s&&o?C(k,{children:o(s)}):c&&e?C(k,{children:e}):C(g.Provider,{value:{sdk:r,isLoading:c,error:s},children:n})},"AppSdkAuthProvider");import{useContext as M}from"react";var Y=t(()=>{let n=M(g);if(!n)throw new Error("useDune must be used within a DuneAuthProvider");return n},"useDune");export{D as a,T as b,p as c,g as d,y as e,F as f,Y as g};
|
package/dist/vite/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { CspFetchDirective, MANIFEST_VERSION, ManifestConfig, NetworkAllowlistRule, buildFrameAncestors, buildHostedAppContentSecurityPolicy, fusionOpenPlugin, getManifestNetworkRules, loadManifestConfig, manifestCspPlugin, parseAndValidateManifestConfig, validateManifestConfig } from '@cognite/app-sdk/vite';
|
package/dist/vite/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"../chunk-EI7MMDWY.js";import{fusionOpenPlugin as i,manifestCspPlugin as n,buildFrameAncestors as o,buildHostedAppContentSecurityPolicy as s,getManifestNetworkRules as a,loadManifestConfig as l,MANIFEST_VERSION as f,parseAndValidateManifestConfig as p,validateManifestConfig as r}from"@cognite/app-sdk/vite";export{f as MANIFEST_VERSION,o as buildFrameAncestors,s as buildHostedAppContentSecurityPolicy,i as fusionOpenPlugin,a as getManifestNetworkRules,l as loadManifestConfig,n as manifestCspPlugin,p as parseAndValidateManifestConfig,r as validateManifestConfig};
|