@cognite/cli 1.2.0 → 1.3.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/LICENSE.md ADDED
@@ -0,0 +1,6 @@
1
+ Commercial Software Licence Agreement
2
+
3
+ Copyright (c) Cognite AS 2026
4
+
5
+ See Master Subscription and Professional Services Agreement for details:
6
+ https://www.cognite.com/en/company/legal/master-subscription-services-agreement-2025
@@ -28,7 +28,54 @@ Always check `@cognite/aura/components` before reaching for a raw HTML element o
28
28
 
29
29
  ---
30
30
 
31
- ## 2. Dependency Injection
31
+ ## 2. Host integration (`@cognite/app-sdk`)
32
+
33
+ The Fusion host exposes a `HostAppAPI` (imported as `HostAppAPI` from `@cognite/app-sdk`) via `connectToHostApp(...)`. Reach for it whenever the situation calls for it — don't hand-roll an equivalent or read browser globals directly.
34
+
35
+ ### Decision rule for any new piece of state
36
+
37
+ Before adding `useState`, `useReducer`, or a store entry, ask: **"would a user expect this to survive a page reload, or to be restored when someone opens a shared link?"** If yes, it belongs in `syncInternalState` + `initialState`, **not** in plain React state.
38
+
39
+ - **Yes, host-synced:** current page / active view / route, selected tab, active filters, selected resource id, search query, sort order, expanded rows, focused row, side-panel open/closed — anything that drives what the user sees.
40
+ - **No, local-only:** in-flight form input before submit, hover/focus, transient toasts, animation state, optimistic UI mid-flight.
41
+
42
+ When in doubt, host-synced is the safer default — over-syncing is cheap, under-syncing breaks reload and share.
43
+
44
+ ### API surface
45
+
46
+ - **Host-synced UI state** → on startup, seed your state from the `initialState` string returned by `connectToHostApp`. On every change, call `api.syncInternalState(JSON.stringify(state))`. The host serializes this into the URL so reloads and shared links restore the same state. **Do not** hold state from the "host-synced" category above in plain `useState` / `useRef` / a local store.
47
+ - **Navigating elsewhere in Fusion** (another app, a Fusion route) → `api.navigateInternal({ path, queryParams, hash })`. Never set `window.location` directly.
48
+ - **Navigating to an external URL** → `api.navigateExternal({ url, openInNewTab })`. Only `https:` is allowed.
49
+ - **Needing a CDF base URL or access token** for API requests → `api.getBaseUrl()` / `api.getAccessToken()`. Never hardcode the cluster URL.
50
+ - **Needing the current CDF project name** → `api.getProject()`. Don't read it from config or URL params.
51
+ - **Exposing the app's capabilities to a Fusion agent** → register a custom agent server with `api.registerAgentServer(handle)` and clean up on unmount with `api.unregisterAgentServer(uri)`.
52
+
53
+ Get `api` once at app startup and surface it to the rest of the app via React context so view models can depend on it through the patterns below.
54
+
55
+ ### Round-trip example: host-synced state
56
+
57
+ ```typescript
58
+ import { connectToHostApp, type HostAppAPI } from '@cognite/app-sdk';
59
+
60
+ type AppState = { page: 'a' | 'b'; filters: string[] };
61
+ const DEFAULT_STATE: AppState = { page: 'a', filters: [] };
62
+
63
+ // On startup — seed from initialState, not from a hardcoded default.
64
+ const { api, initialState } = await connectToHostApp({ applicationName: '<%= name %>' });
65
+ const seeded: AppState = initialState ? (JSON.parse(initialState) as AppState) : DEFAULT_STATE;
66
+
67
+ // On every change — push the new state to the host so the URL stays in sync.
68
+ async function updateState(next: AppState, api: HostAppAPI) {
69
+ setState(next); // your local React/store setter
70
+ await api.syncInternalState(JSON.stringify(next));
71
+ }
72
+ ```
73
+
74
+ `initialState` is the JSON string the host extracted from the URL on this load — the host owns the URL plumbing, the app just reads/writes the string.
75
+
76
+ ---
77
+
78
+ ## 3. Dependency Injection
32
79
 
33
80
  Inject dependencies via React context (hooks/components) or factory-override pattern (plain functions). Never hard-code dependencies.
34
81
 
@@ -57,7 +104,7 @@ export const doWork = async (props: Props, overrides?: Partial<Deps>) => {
57
104
 
58
105
  ---
59
106
 
60
- ## 3. Interface-Based Services
107
+ ## 4. Interface-Based Services
61
108
 
62
109
  Define an interface; implement with a class. Never reference the concrete class outside its own file.
63
110
 
@@ -74,7 +121,7 @@ export class ApiDataService implements DataService {
74
121
 
75
122
  ---
76
123
 
77
- ## 4. ViewModel Pattern
124
+ ## 5. ViewModel Pattern
78
125
 
79
126
  Business logic lives in `use<Name>ViewModel`. Components only render.
80
127
 
@@ -95,9 +142,26 @@ export const TodoView = () => {
95
142
  };
96
143
  ```
97
144
 
145
+ ### Where state lives
146
+
147
+ A ViewModel hook must **not** hold state with `useState` / `useReducer` directly. State lives in a shared storage layer — a context-backed hook (like `useTodoStorage` above), a store, or a `*StateProvider` rendered once near the root of the view tree. The ViewModel composes that storage with commands and derivations; it is itself stateless.
148
+
149
+ This matters because each call to a `useState`-backed hook creates an **independent** piece of React state. Two components calling the same ViewModel hook would each get their own copy and never sync.
150
+
151
+ > ⚠️ Anti-pattern: `useState` inside `useFooViewModel`, then two sibling components each call `useFooViewModel()`. Clicks update one copy; the other renders stale data.
152
+
153
+ ### How many times to call a ViewModel hook
154
+
155
+ - **Backed by shared context / store** → multiple components may call the hook; they all observe the same value. This is the default for non-trivial views.
156
+ - **Not backed by shared state** → call the hook **once** at the top of the view tree and pass values down as props. Never call it twice and expect them to stay in sync.
157
+
158
+ ### Host-synced state inside a ViewModel
159
+
160
+ When a ViewModel exposes state that falls under §2's "host-synced" category, the **ViewModel** — not the view component — is responsible for seeding from `initialState` and pushing changes via `syncInternalState`. The state itself still lives in the shared storage layer described above; the ViewModel just owns the read/write contract with the host.
161
+
98
162
  ---
99
163
 
100
- ## 5. Test-First Development
164
+ ## 6. Test-First Development
101
165
 
102
166
  Write tests before implementation for all non-trivial behavior changes.
103
167
 
@@ -193,7 +257,7 @@ Place reusable factories in `src/__mocks__/`. Use `.test` TLD for fake URLs (RFC
193
257
 
194
258
  ---
195
259
 
196
- ## 6. TypeScript Rules
260
+ ## 7. TypeScript Rules
197
261
 
198
262
  - Never use `any`; prefer `unknown` or explicit strong types
199
263
  - Never use `as unknown as T`; for partial test doubles use `{ ...defaults, ...overrides } as T`
@@ -207,7 +271,14 @@ function createMockWindow(overrides: Partial<Window> = {}): Window {
207
271
 
208
272
  ---
209
273
 
210
- ## 7. Commits and pull requests
274
+ ## 7. CogniteClient / authentication
275
+
276
+ Auth is handled by `CogniteSdkProvider` from `@cognite/app-sdk/react` (see `App.tsx`). Nested components get the client via `useCogniteSdk()`. To wire up or migrate auth, run the `/setup-flows-auth` skill.
277
+
278
+ ---
279
+
280
+
281
+ ## 8. Commits and pull requests
211
282
 
212
283
  Use [Conventional Commits v1.0.0](https://www.conventionalcommits.org/en/v1.0.0/).
213
284
 
@@ -27,7 +27,7 @@ to: '<%= useCurrentDir ? "" : ((directoryName || name) + "/") %>package.json'
27
27
  "dependencies": {
28
28
  "@cognite/aura": "^0.1.7",
29
29
  "@cognite/sdk": "^10.3.0",
30
- "@cognite/app-sdk": "^0.4.0",
30
+ "@cognite/app-sdk": "^0.5.1",
31
31
  "@tabler/icons-react": "^3.35.0",
32
32
  "@tanstack/react-query": "^5.90.10",
33
33
  "clsx": "^2.1.1",
@@ -1,13 +1,45 @@
1
1
  ---
2
2
  to: '<%= useCurrentDir ? "" : ((directoryName || name) + "/") %>src/App.test.tsx'
3
3
  ---
4
- import * as appSdk from '@cognite/app-sdk';
5
4
  import { render, screen, waitFor } from '@testing-library/react';
6
5
  import { beforeEach, describe, expect, it, vi } from 'vitest';
6
+ import type { HostAppAPI, ConnectToHostAppResult } from '@cognite/app-sdk';
7
+ import { CogniteClient } from '@cognite/sdk';
8
+ import type { ComponentProps } from 'react';
7
9
 
8
10
  import App from './App';
9
11
 
10
- vi.mock(import('@cognite/app-sdk'));
12
+ type AppDeps = NonNullable<ComponentProps<typeof App>['deps']>;
13
+
14
+ function makeApi(): HostAppAPI {
15
+ return {
16
+ getProject: vi.fn<HostAppAPI['getProject']>(() => Promise.resolve('<%= project %>')),
17
+ getBaseUrl: vi.fn<HostAppAPI['getBaseUrl']>(() => Promise.resolve('https://cognite.test')),
18
+ getAccessToken: vi.fn<HostAppAPI['getAccessToken']>(() => Promise.resolve('test-token')),
19
+ getAppId: vi.fn<HostAppAPI['getAppId']>(() => Promise.resolve('test-app-id')),
20
+ syncInternalState: vi.fn<HostAppAPI['syncInternalState']>(() => Promise.resolve(true)),
21
+ navigateInternal: vi.fn<HostAppAPI['navigateInternal']>(() => Promise.resolve(true)),
22
+ navigateExternal: vi.fn<HostAppAPI['navigateExternal']>(() => Promise.resolve(true)),
23
+ registerAgentServer: vi.fn<HostAppAPI['registerAgentServer']>(() => Promise.resolve()),
24
+ unregisterAgentServer: vi.fn<HostAppAPI['unregisterAgentServer']>(() => Promise.resolve()),
25
+ sendAgentLayoutMode: vi.fn<HostAppAPI['sendAgentLayoutMode']>(() => Promise.resolve()),
26
+ sendAgentMessage: vi.fn<HostAppAPI['sendAgentMessage']>(() => Promise.resolve()),
27
+ };
28
+ }
29
+
30
+ function makeLoadingDeps(): AppDeps {
31
+ return {
32
+ connectToHostApp: vi.fn<AppDeps['connectToHostApp']>(() => new Promise<ConnectToHostAppResult>(() => undefined)),
33
+ createClient: vi.fn<AppDeps['createClient']>((config) => new CogniteClient(config)),
34
+ };
35
+ }
36
+
37
+ function makeConnectedDeps(): AppDeps {
38
+ return {
39
+ connectToHostApp: vi.fn<AppDeps['connectToHostApp']>(() => Promise.resolve({ api: makeApi() })),
40
+ createClient: vi.fn<AppDeps['createClient']>((config) => new CogniteClient(config)),
41
+ };
42
+ }
11
43
 
12
44
  describe('App', () => {
13
45
  beforeEach(() => {
@@ -15,19 +47,13 @@ describe('App', () => {
15
47
  });
16
48
 
17
49
  it('renders loading state', () => {
18
- vi.mocked(appSdk.connectToHostApp).mockReturnValue(new Promise(() => {}));
19
-
20
- render(<App />);
50
+ render(<App deps={makeLoadingDeps()} />);
21
51
  expect(screen.getByText('Loading project...')).toBeInTheDocument();
22
52
  });
23
53
 
24
54
  it('renders splash with deployment targets and checklist copy', async () => {
25
- vi.mocked(appSdk.connectToHostApp).mockResolvedValue({
26
- api: { getProject: vi.fn().mockResolvedValue('my-test-project') } as Partial<appSdk.HostAppAPI> as appSdk.HostAppAPI,
27
- });
28
-
29
- render(<App />);
30
- await waitFor(() => expect(screen.getByText('Welcome to Flows')).toBeInTheDocument());
55
+ render(<App deps={makeConnectedDeps()} />);
56
+ await waitFor(() => expect(screen.getByText('Welcome to Flows custom apps')).toBeInTheDocument());
31
57
  expect(screen.getByText('App deployment checklist')).toBeInTheDocument();
32
58
  expect(screen.getByText('Plan')).toBeInTheDocument();
33
59
  expect(screen.getByText('Explore')).toBeInTheDocument();
@@ -1,7 +1,8 @@
1
1
  ---
2
2
  to: '<%= useCurrentDir ? "" : ((directoryName || name) + "/") %>src/App.tsx'
3
3
  ---
4
- import { connectToHostApp } from '@cognite/app-sdk';
4
+ import type { ComponentProps } from 'react';
5
+ import { CogniteSdkProvider, useCogniteSdk } from '@cognite/app-sdk/react';
5
6
  import {
6
7
  Alert,
7
8
  AlertDescription,
@@ -18,7 +19,6 @@ import {
18
19
  Separator,
19
20
  } from '@cognite/aura/components';
20
21
  import { IconCaretUpDown, IconRocket } from '@tabler/icons-react';
21
- import { useEffect, useState } from 'react';
22
22
 
23
23
  import appConfig from '../app.json';
24
24
 
@@ -62,71 +62,41 @@ const CHECKLIST_STEPS = [
62
62
  },
63
63
  ] as const;
64
64
 
65
- function App() {
66
- // Connect to the Fusion host via @cognite/app-sdk. The handshake is
67
- // asynchronous `project` is only populated after Comlink finishes
68
- // exposing the host API, so we render a loader until then.
69
- const [project, setProject] = useState<string | null>(null);
70
- const [isLoading, setIsLoading] = useState(true);
71
- const [error, setError] = useState<string | undefined>();
72
-
73
- useEffect(() => {
74
- let cancelled = false;
75
- connectToHostApp({ applicationName: '<%= name %>' })
76
- .then(async ({ api }) => {
77
- if (cancelled) return;
78
- const proj = await api.getProject();
79
- if (cancelled) return;
80
- setProject(proj);
81
- })
82
- .catch((err: unknown) => {
83
- if (cancelled) return;
84
- setError(err instanceof Error ? err.message : String(err));
85
- })
86
- .finally(() => {
87
- if (!cancelled) setIsLoading(false);
88
- });
89
- return () => {
90
- cancelled = true;
91
- };
92
- }, []);
93
-
94
- if (isLoading) {
95
- return (
96
- <main className="min-h-screen bg-muted/50 text-foreground">
97
- <section className="mx-auto flex min-h-screen w-full max-w-lg flex-col justify-center p-4 sm:p-8">
98
- <div className="mx-auto w-full max-w-sm">
99
- <Card aria-label="Loading project" aria-live="polite">
100
- <CardContent>
101
- <div className="inline-flex items-center gap-3 text-muted-foreground">
102
- <Loader size={20} />
103
- <span>Loading project...</span>
104
- </div>
105
- </CardContent>
106
- </Card>
107
- </div>
108
- </section>
109
- </main>
110
- );
111
- }
112
-
113
- if (error) {
114
- return (
115
- <main className="min-h-screen bg-muted/50 text-foreground">
116
- <section className="mx-auto flex min-h-screen w-full max-w-lg flex-col justify-center p-4 sm:p-8">
117
- <div className="mx-auto w-full max-w-sm">
118
- <Alert>
119
- <AlertDescription>Failed to connect to Fusion host: {error}</AlertDescription>
120
- </Alert>
121
- </div>
122
- </section>
123
- </main>
124
- );
125
- }
65
+ const loadingFallback = (
66
+ <main className="min-h-screen bg-muted/50 text-foreground">
67
+ <section className="mx-auto flex min-h-screen w-full max-w-lg flex-col justify-center p-4 sm:p-8">
68
+ <div className="mx-auto w-full max-w-sm">
69
+ <Card aria-label="Loading project" aria-live="polite">
70
+ <CardContent>
71
+ <div className="inline-flex items-center gap-3 text-muted-foreground">
72
+ <Loader size={20} />
73
+ <span>Loading project...</span>
74
+ </div>
75
+ </CardContent>
76
+ </Card>
77
+ </div>
78
+ </section>
79
+ </main>
80
+ );
81
+
82
+ const errorFallback = (
83
+ <main className="min-h-screen bg-muted/50 text-foreground">
84
+ <section className="mx-auto flex min-h-screen w-full max-w-lg flex-col justify-center p-4 sm:p-8">
85
+ <div className="mx-auto w-full max-w-sm">
86
+ <Alert>
87
+ <AlertDescription>Failed to connect to Fusion host</AlertDescription>
88
+ </Alert>
89
+ </div>
90
+ </section>
91
+ </main>
92
+ );
93
+
94
+ function AppContent() {
95
+ const client = useCogniteSdk();
126
96
 
127
97
  const deployment = appConfig.deployments?.[0];
128
98
  const orgLabel = deployment?.org ?? '';
129
- const projectLabel = deployment?.project ?? project ?? '';
99
+ const projectLabel = deployment?.project ?? client.project ?? '';
130
100
 
131
101
  return (
132
102
  <main className="min-h-screen bg-muted/50 text-foreground">
@@ -230,4 +200,16 @@ function App() {
230
200
  );
231
201
  }
232
202
 
203
+ type AppProps = {
204
+ deps?: ComponentProps<typeof CogniteSdkProvider>['deps'];
205
+ };
206
+
207
+ function App({ deps }: AppProps) {
208
+ return (
209
+ <CogniteSdkProvider loadingFallback={loadingFallback} errorFallback={errorFallback} deps={deps}>
210
+ <AppContent />
211
+ </CogniteSdkProvider>
212
+ );
213
+ }
214
+
233
215
  export default App;
@@ -1,9 +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 A(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(A,"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 $(e,t){return S(e)&&e.status===404||Q(e,t)}s($,"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 V=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 A(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),h;try{h=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(!h.ok){let f=await h.text(),k=f;try{let x=JSON.parse(f);if(m(x)){let w=x.error;if(typeof w=="string")k=w;else if(m(w)){let E=w.message,F=w.code;k=typeof E=="string"?E:F!=null?`Unknown error (code: ${F})`:f}else{let E=x.message;k=typeof E=="string"?E:f}}}catch{}let j=h.headers.get("x-request-id"),K=j?` | X-Request-ID: ${j}`:"",B=Object.assign(new Error(`Upload failed: ${h.status} \u2014 ${k}${K}`),{status:h.status});throw A(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 $(a,[t,n])?new V(t,n):A(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($(o,[t]))return null;throw A(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 A(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,a,l=!1){console.log(`
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 F="https://docs.cognite.com/cdf/access/";function m(e){return e!==null&&typeof e=="object"}s(m,"isRecord");function P(e){return e instanceof Error&&"status"in e&&typeof e.status=="number"}s(P,"isHttpError");function Z(e){switch(e){case 401:return`Your credentials are invalid or expired. Check your client ID and secret.
2
+ See: ${F}`;case 403:return`You don't have the required CDF capabilities. Please contact your CDF admin.
3
+ See: ${F}`;default:return}}s(Z,"httpStatusHint");function A(e){let t=e instanceof Error?e:new Error(String(e));if(!P(t))return null;let n=Z(t.status);return n?Object.assign(new Error(`${t.message}
4
+ ${n}`),{cause:t}):null}s(A,"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(!P(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 $(e,t){return P(e)&&e.status===404||Q(e,t)}s($,"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 k=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 A(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),h;try{h=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(!h.ok){let f=await h.text(),V=f;try{let x=JSON.parse(f);if(m(x)){let w=x.error;if(typeof w=="string")V=w;else if(m(w)){let E=w.message,B=w.code;V=typeof E=="string"?E:B!=null?`Unknown error (code: ${B})`:f}else{let E=x.message;V=typeof E=="string"?E:f}}}catch{}let j=h.headers.get("x-request-id"),K=j?` | X-Request-ID: ${j}`:"",N=Object.assign(new Error(`Upload failed: ${h.status} \u2014 ${V}${K}`),{status:h.status});throw A(N)??N}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 $(a,[t,n])?new k(t,n):A(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($(o,[t]))return null;throw A(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 A(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(P(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`)}getActiveVersion(t){return this.api.getActiveVersion(t)}async deactivateVersion(t,n){await this.api.updateVersions(t,[{version:n,update:{alias:{setNull:!0}}}])}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
5
  \u{1F680} Deploying application via App Hosting API...
6
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 y 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(!y.existsSync(this.distPath))throw new Error(`Build directory "${this.distPath}" not found. Run build first.`);let t=d.join(this.appRoot,R);if(!y.existsSync(t))throw new Error(`"${t}" not found. It is required for deployment.`);let n=d.join(this.appRoot,D);if(!y.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 y.openAsBlob(c))),n&&console.log(` \u{1F4C4} ${p}`)},"addFile"),i=s(async c=>{let p=await y.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(y.existsSync(p)){let u=y.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 y.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 C=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}
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 S=b;import y 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(!y.existsSync(this.distPath))throw new Error(`Build directory "${this.distPath}" not found. Run build first.`);let t=d.join(this.appRoot,R);if(!y.existsSync(t))throw new Error(`"${t}" not found. It is required for deployment.`);let n=d.join(this.appRoot,D);if(!y.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 y.openAsBlob(c))),n&&console.log(` \u{1F4C4} ${p}`)},"addFile"),i=s(async c=>{let p=await y.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(y.existsSync(p)){let u=y.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 y.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 C=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
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"),O=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");async function U(e,t,n=process.env,r){let o=await O(e,n),i=n.COGNITE_BASE_URL??e.baseUrl,a=(r??(l=>new ut(l)))({appId:t,project:e.project,baseUrl:i,oidcTokenProvider:s(async()=>o,"oidcTokenProvider")});return await a.authenticate(),a}s(U,"getSdk");var ft=s(async(e,t,n)=>{let r=await new C(`${n}/dist`).createZip("app.zip",!0);try{let{externalId:o,name:i,description:a,versionTag:l}=t,c=await U(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,C as b,O as c,U as d,ft as e};
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"),O=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");async function U(e,t,n=process.env,r){let o=await O(e,n),i=n.COGNITE_BASE_URL??e.baseUrl,a=(r??(l=>new ut(l)))({appId:t,project:e.project,baseUrl:i,oidcTokenProvider:s(async()=>o,"oidcTokenProvider")});return await a.authenticate(),a}s(U,"getSdk");var ft=s(async(e,t,n)=>{let r=await new C(`${n}/dist`).createZip("app.zip",!0);try{let{externalId:o,name:i,description:a,versionTag:l}=t,c=await U(e,n),p=new S(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{S as a,C as b,O as c,U 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 Be}from"../chunk-A5ASLC6T.js";import{writeSync as Yi}from"fs";import{Command as Ji}from"commander";var Ye="https://docs.cognite.com/cdf/access/";function k(e){return e!==null&&typeof e=="object"}o(k,"isRecord");function B(e){return e instanceof Error&&"status"in e&&typeof e.status=="number"}o(B,"isHttpError");function Ln(e){switch(e){case 401:return`Your credentials are invalid or expired. Check your client ID and secret.
3
- See: ${Ye}`;case 403:return`You don't have the required CDF capabilities. Please contact your CDF admin.
4
- See: ${Ye}`;default:return}}o(Ln,"httpStatusHint");function V(e){let t=e instanceof Error?e:new Error(String(e));if(!B(t))return null;let n=Ln(t.status);return n?Object.assign(new Error(`${t.message}
5
- ${n}`),{cause:t}):null}o(V,"enrichedHttpError");function Nn(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(Nn,"findMissingArray");function Kn(e,t){if(!B(e)||e.status!==400)return!1;let n=Nn(e);return n?n.some(r=>k(r)&&typeof r.externalId=="string"&&t.includes(r.externalId)):!1}o(Kn,"isMissingExternalIdError");function le(e,t){return B(e)&&e.status===404||Kn(e,t)}o(le,"isNotFoundError");var Xe=["DRAFT","PUBLISHED","DEPRECATED","ARCHIVED"],ze=["ACTIVE","PREVIEW"],me=class me extends Error{constructor(t,n){super(`Version ${n} of app ${t} not found`),this.name="AppVersionNotFoundError",this.appExternalId=t,this.version=n}};o(me,"AppVersionNotFoundError");var E=me;function We(e,t){return e.includes(t)}o(We,"includesValue");function jn(e){return We(Xe,e)}o(jn,"isAppVersionLifecycleState");function Mn(e){return We(ze,e)}o(Mn,"isAppVersionAlias");function Vn(e){return typeof e.version=="string"&&jn(e.lifecycleState)&&typeof e.entrypoint=="string"&&typeof e.createdTime=="number"&&typeof e.createdBy=="string"&&typeof e.appExternalId=="string"&&(e.alias===void 0||Mn(e.alias))&&(e.comment===void 0||typeof e.comment=="string")}o(Vn,"isAppVersion");function Je(e){if(!k(e))throw new Error("Invalid version response: not an object");if(!Vn(e))throw new Error("Invalid version response: missing or malformed fields");return e}o(Je,"parseAppVersion");var de=class de{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 Je(a.data)}catch(a){throw le(a,[t,n])?new E(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 Je(i.data)}catch(i){if(le(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(de,"AppHostingApi");var ee=de;var ue=class ue{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(B(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(`
2
+ import{a as o,e as qe}from"../chunk-A5ASLC6T.js";import{writeSync as os}from"fs";import{Command as is}from"commander";var Qe="https://docs.cognite.com/cdf/access/";function _(e){return e!==null&&typeof e=="object"}o(_,"isRecord");function z(e){return e instanceof Error&&"status"in e&&typeof e.status=="number"}o(z,"isHttpError");function Yn(e){switch(e){case 401:return`Your credentials are invalid or expired. Check your client ID and secret.
3
+ See: ${Qe}`;case 403:return`You don't have the required CDF capabilities. Please contact your CDF admin.
4
+ See: ${Qe}`;default:return}}o(Yn,"httpStatusHint");function B(e){let t=e instanceof Error?e:new Error(String(e));if(!z(t))return null;let n=Yn(t.status);return n?Object.assign(new Error(`${t.message}
5
+ ${n}`),{cause:t}):null}o(B,"enrichedHttpError");function Jn(e){if(!_(e))return null;let t=e.missing;if(Array.isArray(t))return t;let n=e.data;if(_(n)){let r=n.error;if(_(r)&&Array.isArray(r.missing))return r.missing;if(Array.isArray(n.missing))return n.missing}return null}o(Jn,"findMissingArray");function Xn(e,t){if(!z(e)||e.status!==400)return!1;let n=Jn(e);return n?n.some(r=>_(r)&&typeof r.externalId=="string"&&t.includes(r.externalId)):!1}o(Xn,"isMissingExternalIdError");function ye(e,t){return z(e)&&e.status===404||Xn(e,t)}o(ye,"isNotFoundError");var et=["DRAFT","PUBLISHED","DEPRECATED","ARCHIVED"],tt=["ACTIVE","PREVIEW"],he=class he extends Error{constructor(t,n){super(`Version ${n} of app ${t} not found`),this.name="AppVersionNotFoundError",this.appExternalId=t,this.version=n}};o(he,"AppVersionNotFoundError");var k=he;function nt(e,t){return e.includes(t)}o(nt,"includesValue");function zn(e){return nt(et,e)}o(zn,"isAppVersionLifecycleState");function Wn(e){return nt(tt,e)}o(Wn,"isAppVersionAlias");function qn(e){return typeof e.version=="string"&&zn(e.lifecycleState)&&typeof e.entrypoint=="string"&&typeof e.createdTime=="number"&&typeof e.createdBy=="string"&&typeof e.appExternalId=="string"&&(e.alias===void 0||Wn(e.alias))&&(e.comment===void 0||typeof e.comment=="string")}o(qn,"isAppVersion");function Ze(e){if(!_(e))throw new Error("Invalid version response: not an object");if(!qn(e))throw new Error("Invalid version response: missing or malformed fields");return e}o(Ze,"parseAppVersion");var Ce=class Ce{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 B(i)??i}}async uploadVersion(t,n,r,i,a="index.html"){console.log(`\u{1F4E4} Uploading version ${n}...`);let s=new FormData;s.append("file",new Blob([new Uint8Array(r)]),i),s.append("version",n),s.append("entryPath",a);let p=encodeURIComponent(t),c=`${this.appsBasePath}/${p}/versions`,l=await this.client.authenticate(),m=`${this.client.getBaseUrl()}${c}`,d=new AbortController,u=setTimeout(()=>d.abort(),300*1e3),C;try{C=await fetch(m,{method:"POST",headers:{Authorization:`Bearer ${l}`},body:s,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(!C.ok){let g=await C.text(),E=g;try{let A=JSON.parse(g);if(_(A)){let x=A.error;if(typeof x=="string")E=x;else if(_(x)){let P=x.message,f=x.code;E=typeof P=="string"?P:f!=null?`Unknown error (code: ${f})`:g}else{let P=A.message;E=typeof P=="string"?P:g}}}catch{}let S=C.headers.get("x-request-id"),y=S?` | X-Request-ID: ${S}`:"",R=Object.assign(new Error(`Upload failed: ${C.status} \u2014 ${E}${y}`),{status:C.status});throw B(R)??R}console.log(`\u2705 Version ${n} uploaded`)}async getVersion(t,n){let r=encodeURIComponent(t),i=encodeURIComponent(n),a=`${this.appsBasePath}/${r}/versions/${i}`;try{let s=await this.client.get(a);return Ze(s.data)}catch(s){throw ye(s,[t,n])?new k(t,n):B(s)??s}}async getActiveVersion(t){let n=encodeURIComponent(t),r=`${this.appsBasePath}/${n}/active`;try{let i=await this.client.get(r);return Ze(i.data)}catch(i){if(ye(i,[t]))return null;throw B(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(a){throw B(a)??a}}};o(Ce,"AppHostingApi");var ie=Ce;var we=class we{constructor(t){this.api=new ie(t)}getVersion(t,n){return this.api.getVersion(t,n)}uploadVersion(t,n,r,i,a){return this.api.uploadVersion(t,n,r,i,a)}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(z(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`)}getActiveVersion(t){return this.api.getActiveVersion(t)}async deactivateVersion(t,n){await this.api.updateVersions(t,[{version:n,update:{alias:{setNull:!0}}}])}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,a,s,p=!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),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(ue,"AppHostingClient");var h=ue;import{existsSync as Zn,readFileSync as er}from"fs";import{resolve as tr}from"path";import{array as Hn,boolean as Gn,check as qe,forward as Qe,literal as Bn,maxLength as Yn,minLength as Jn,nonEmpty as H,object as Ze,optional as U,picklist as Xn,pipe as D,safeParse as zn,string as S,url as Wn}from"valibot";var ge=D(S(),H("must not be empty")),fe=D(S(),H("must not be empty"),Yn(256,"must be 256 characters or fewer")),ye=D(S(),H("must not be empty"),Wn("must be a valid URL")),he=D(S(),H("must not be empty")),we=D(S(),H("must not be empty")),qn=D(Ze({org:he,project:we,baseUrl:ye,deployClientId:U(S(),""),deploySecretName:U(S(),""),published:U(Gn(),!1),idpType:U(Xn(["cdf","entra_id"]),"cdf"),tenantId:U(S())}),Qe(qe(e=>e.idpType!=="entra_id"||!!e.tenantId,'must be set when idpType is "entra_id"'),["tenantId"]),Qe(qe(e=>!e.deployClientId||!!e.deploySecretName,"must be set when deployClientId is set"),["deploySecretName"])),Qn=Ze({name:ge,externalId:fe,versionTag:D(S(),H("must not be empty")),description:U(S(),""),deployments:D(Hn(qn),Jn(1,"must contain at least one deployment")),infra:U(Bn("appsApi"))});function Ce(e){let t=zn(Qn,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(Ce,"validateAppConfig");function C(e,t={}){let{validator:n=Ce,existsSync:r=Zn,readFileSync:i=er}=t,s=tr(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(C,"loadAppConfig");import{CogniteClient as br}from"@cognite/sdk";import{CogniteClient as ar}from"@cognite/sdk";var nr=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"),rr=o(e=>{let t;if(process.env.DEPLOYMENT_SECRET&&(t=process.env.DEPLOYMENT_SECRET),t||(t=nr()[e]),t||(t=process.env[e]),!t)throw new Error(`Secret not found in environment: ${e}`);return t},"getSecretFromEnv"),or=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"),ir=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"),sr=o(async(e,t,n,r)=>{if(!r)throw new Error("Entra ID authentication requires 'baseUrl' to be set in deployment configuration");let i=or(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=rr(r);if(i==="entra_id"){if(!s)throw new Error("Entra ID authentication requires 'tenantId' in deployment configuration");return sr(n,c,s,a)}return ir(n,c)},"getToken");async function Y(e,t,n=process.env,r){let i=await Ee(e,n),s=n.COGNITE_BASE_URL??e.baseUrl,a=(r??(c=>new ar(c)))({appId:t,project:e.project,baseUrl:s,oidcTokenProvider:o(async()=>i,"oidcTokenProvider")});return await a.authenticate(),a}o(Y,"getSdk");import gr from"os";import fr from"path";import yr from"open";import{buildAuthorizationUrl as hr,calculatePKCECodeChallenge as wr,discovery as Cr,None as Er,randomPKCECodeVerifier as Sr,randomState as vr}from"openid-client";import cr from"https";import{authorizationCodeGrant as pr}from"openid-client";function et(e){return e.replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t]??t)}o(et,"escapeHtml");function Se(e,t,n){let r=et(t),i=et(n);return`<html><body style="font-family: system-ui; padding: 40px; text-align: center;">
7
+ `);try{await this.ensureApp(t,n,r),await this.uploadVersion(t,i,a,s),p&&await this.publishAndActivate(t,i),console.log(`
8
+ \u2705 Deployment successful!`)}catch(c){let l=c instanceof Error?c.message:String(c);throw Object.assign(new Error(`Deployment failed: ${l}`),{cause:c})}}};o(we,"AppHostingClient");var h=we;import{existsSync as pr,readFileSync as cr}from"fs";import{resolve as lr}from"path";import{array as Qn,boolean as Zn,check as rt,forward as ot,literal as er,maxLength as tr,minLength as nr,nonEmpty as Y,object as it,optional as M,picklist as rr,pipe as U,safeParse as or,string as D,url as ir}from"valibot";var ve=U(D(),Y("must not be empty")),Ee=U(D(),Y("must not be empty"),tr(256,"must be 256 characters or fewer")),Se=U(D(),Y("must not be empty"),ir("must be a valid URL")),xe=U(D(),Y("must not be empty")),Pe=U(D(),Y("must not be empty")),sr=U(it({org:xe,project:Pe,baseUrl:Se,deployClientId:M(D(),""),deploySecretName:M(D(),""),published:M(Zn(),!1),idpType:M(rr(["cdf","entra_id"]),"cdf"),tenantId:M(D())}),ot(rt(e=>e.idpType!=="entra_id"||!!e.tenantId,'must be set when idpType is "entra_id"'),["tenantId"]),ot(rt(e=>!e.deployClientId||!!e.deploySecretName,"must be set when deployClientId is set"),["deploySecretName"])),ar=it({name:ve,externalId:Ee,versionTag:U(D(),Y("must not be empty")),description:M(D(),""),deployments:U(Qn(sr),nr(1,"must contain at least one deployment")),infra:M(er("appsApi"))});function be(e){let t=or(ar,e);if(t.success)return t.output;let n=t.issues[0],r=n.path?.map(a=>a.key).join(".")??"",i=r?`"${r}" `:"";throw new Error(`app.json: ${i}${n.message}`)}o(be,"validateAppConfig");function w(e,t={}){let{validator:n=be,existsSync:r=pr,readFileSync:i=cr}=t,a=lr(e,"app.json");if(!r(a))throw new Error("No app.json found in current directory. Make sure you're running this command from your app's root directory.");let s=i(a,"utf-8"),p;try{p=JSON.parse(s)}catch{throw new Error("Failed to parse app.json \u2014 check that it contains valid JSON.")}return n(p)}o(w,"loadAppConfig");import{CogniteClient as Rr}from"@cognite/sdk";import{CogniteClient as yr}from"@cognite/sdk";var mr=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 a=r.toLowerCase().replace(/_/g,"-");n[a]=i}return n}catch(t){return console.error("Error parsing DEPLOYMENT_SECRETS:",t),{}}},"loadSecretsFromEnv"),dr=o(e=>{let t;if(process.env.DEPLOYMENT_SECRET&&(t=process.env.DEPLOYMENT_SECRET),t||(t=mr()[e]),t||(t=process.env[e]),!t)throw new Error(`Secret not found in environment: ${e}`);return t},"getSecretFromEnv"),ur=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"),gr=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 a=await r.text();throw new Error(`Failed to get token from CDF: ${r.status} ${r.statusText}
9
+ ${a}`)}let i=await r.json();if(!i.access_token)throw new Error("No access token returned from CDF authentication");return i.access_token},"getTokenCdf"),fr=o(async(e,t,n,r)=>{if(!r)throw new Error("Entra ID authentication requires 'baseUrl' to be set in deployment configuration");let i=ur(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 a=`https://login.microsoftonline.com/${n}/oauth2/v2.0/token`,s=`https://${i}.cognitedata.com/.default`,p=await fetch(a,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({client_id:e,client_secret:t,scope:s,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}
10
+ ${l}`)}let c=await p.json();if(!c.access_token)throw new Error("No access token returned from Entra ID authentication");return c.access_token},"getTokenEntra"),Ae=o(async(e,t=process.env)=>{if(t.COGNITE_TOKEN)return t.COGNITE_TOKEN;let{deployClientId:n,deploySecretName:r,idpType:i="cdf",tenantId:a,baseUrl:s}=e,p=dr(r);if(i==="entra_id"){if(!a)throw new Error("Entra ID authentication requires 'tenantId' in deployment configuration");return fr(n,p,a,s)}return gr(n,p)},"getToken");async function W(e,t,n=process.env,r){let i=await Ae(e,n),a=n.COGNITE_BASE_URL??e.baseUrl,s=(r??(p=>new yr(p)))({appId:t,project:e.project,baseUrl:a,oidcTokenProvider:o(async()=>i,"oidcTokenProvider")});return await s.authenticate(),s}o(W,"getSdk");import xr from"os";import Pr from"path";import br from"open";import{buildAuthorizationUrl as Ar,calculatePKCECodeChallenge as kr,discovery as Dr,None as Ir,randomPKCECodeVerifier as Tr,randomState as $r}from"openid-client";import hr from"https";import{authorizationCodeGrant as Cr}from"openid-client";function st(e){return e.replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t]??t)}o(st,"escapeHtml");function ke(e,t,n){let r=st(t),i=st(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,40 +16,40 @@ ${l}`)}let p=await c.json();if(!p.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(Se,"generateHtml");async function lr(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(Se("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(Se("error","Authentication Error",p.message)),{shouldClose:!0,error:p}}}o(lr,"handleCallback");function mr(e){let t=e/6e4,n=Math.round(t*10)/10;return`${n} ${n===1?"minute":"minutes"}`}o(mr,"formatTimeoutMinutes");function tt(e,t,n,r,i,s={createServer:cr.createServer,setTimeout:globalThis.setTimeout,clearTimeout:globalThis.clearTimeout,authorizationCodeGrant:pr}){return new Promise((a,c)=>{let p,l=s.setTimeout(()=>{p?.close(),c(new Error(`Login timeout - no response received within ${mr(e.loginTimeout)}`))},e.loginTimeout);p=s.createServer(t,async(m,d)=>{try{let u=await lr(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(tt,"startCallbackServer");import{execFileSync as dr}from"child_process";import ve from"fs";import nt from"path";function rt(e,t,n){return{key:n.readFileSync(e),cert:n.readFileSync(t)}}o(rt,"loadCertificates");function ur(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"),rt(t,n,r)}catch{throw new Error(`Failed to generate self-signed certificate. Make sure openssl is installed.
19
+ </body></html>`}o(ke,"generateHtml");async function wr(e,t,n,r,i,a){let s=new URL(e.url??"/",`https://${e.headers.host??"localhost"}`);if(s.pathname!=="/")return t.writeHead(404),t.end("Not found"),{shouldClose:!1};try{console.log("\u{1F504} Exchanging authorization code for tokens...");let p=await a.authorizationCodeGrant(n,s,{pkceCodeVerifier:r,expectedState:i});return t.writeHead(200,{"Content-Type":"text/html"}),t.end(ke("success","Login Successful!","You can close this window and return to the terminal.")),{shouldClose:!0,tokens:p}}catch(p){let c=p instanceof Error?p:new Error(String(p));return t.writeHead(400,{"Content-Type":"text/html"}),t.end(ke("error","Authentication Error",c.message)),{shouldClose:!0,error:c}}}o(wr,"handleCallback");function vr(e){let t=e/6e4,n=Math.round(t*10)/10;return`${n} ${n===1?"minute":"minutes"}`}o(vr,"formatTimeoutMinutes");function at(e,t,n,r,i,a={createServer:hr.createServer,setTimeout:globalThis.setTimeout,clearTimeout:globalThis.clearTimeout,authorizationCodeGrant:Cr}){return new Promise((s,p)=>{let c,l=a.setTimeout(()=>{c?.close(),p(new Error(`Login timeout - no response received within ${vr(e.loginTimeout)}`))},e.loginTimeout);c=a.createServer(t,async(m,d)=>{try{let u=await wr(m,d,n,r,i,a);u.shouldClose&&(a.clearTimeout(l),c?.close(),u.error?p(u.error):u.tokens?s(u.tokens):p(new Error("No tokens received")))}catch(u){a.clearTimeout(l),c?.close(),p(u instanceof Error?u:new Error(String(u)))}}),c.on("error",m=>{a.clearTimeout(l),m.code==="EADDRINUSE"?console.error(`\u274C Port ${e.port} is already in use.`):console.error(`\u274C Server error: ${m.message}`),p(m)}),c.listen(e.port,"127.0.0.1",()=>{console.log(`\u{1F310} Local HTTPS server started on https://localhost:${e.port}`)})})}o(at,"startCallbackServer");import{execFileSync as Er}from"child_process";import De from"fs";import pt from"path";function ct(e,t,n){return{key:n.readFileSync(e),cert:n.readFileSync(t)}}o(ct,"loadCertificates");function Sr(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"),ct(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(ur,"generateCertificate");function ot(e,t={existsSync:ve.existsSync,readFileSync:o(n=>ve.readFileSync(n),"readFileSync"),mkdirSync:o((n,r)=>{ve.mkdirSync(n,r)},"mkdirSync"),execFileSync:dr}){let n=nt.join(e,"localhost-key.pem"),r=nt.join(e,"localhost-cert.pem");return t.existsSync(n)&&t.existsSync(r)?rt(n,r,t):ur(e,n,r,t)}o(ot,"getOrCreateCertificates");var xr={authority:"https://auth.cognite.com",clientId:"0404baaa-0a90-43a2-aba7-a110b53fb41c",redirectUri:"https://localhost:3000/",port:3e3,loginTimeout:300*1e3,certDir:fr.join(gr.homedir(),".cdf-login")},Pr={open:yr,getOrCreateCertificates:ot,startCallbackServer:tt,discovery:Cr,buildAuthorizationUrl:hr,randomPKCECodeVerifier:Sr,calculatePKCECodeChallenge:wr,randomState:vr,logger:console};async function st(e,t=xr,n){return n===void 0?it(e,t,Pr):it(e,t,n)}o(st,"login");async function it(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,Er()),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(it,"loginImpl");async function I(e,t,n={}){let{login:r=st,getSdk:i=Y,createClient:s=o(a=>new br(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 at from"enquirer";var ct="Enter custom target...";function pt(e,t){let n=t.map((r,i)=>` ${i}: ${r.org}/${r.project}`).join(`
22
+ On Windows: Install OpenSSL or use WSL`)}}o(Sr,"generateCertificate");function lt(e,t={existsSync:De.existsSync,readFileSync:o(n=>De.readFileSync(n),"readFileSync"),mkdirSync:o((n,r)=>{De.mkdirSync(n,r)},"mkdirSync"),execFileSync:Er}){let n=pt.join(e,"localhost-key.pem"),r=pt.join(e,"localhost-cert.pem");return t.existsSync(n)&&t.existsSync(r)?ct(n,r,t):Sr(e,n,r,t)}o(lt,"getOrCreateCertificates");var Fr={authority:"https://auth.cognite.com",clientId:"0404baaa-0a90-43a2-aba7-a110b53fb41c",redirectUri:"https://localhost:3000/",port:3e3,loginTimeout:300*1e3,certDir:Pr.join(xr.homedir(),".cdf-login")},Or={open:br,getOrCreateCertificates:lt,startCallbackServer:at,discovery:Dr,buildAuthorizationUrl:Ar,randomPKCECodeVerifier:Tr,calculatePKCECodeChallenge:kr,randomState:$r,logger:console};async function dt(e,t=Fr,n){return n===void 0?mt(e,t,Or):mt(e,t,n)}o(dt,"login");async function mt(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,Ir()),i=n.randomPKCECodeVerifier(),a=await n.calculatePKCECodeChallenge(i),s=n.randomState(),p={redirect_uri:t.redirectUri,scope:"openid profile email",code_challenge:a,code_challenge_method:"S256",state:s};e&&(p.organization_hint=e);let c=n.buildAuthorizationUrl(r,p).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(c)}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(c),n.logger.error("")}return n.startCallbackServer(t,l,r,i,s)}o(mt,"loginImpl");async function I(e,t,n={}){let{login:r=dt,getSdk:i=W,createClient:a=o(s=>new Rr(s),"createClient")}=n;if(t.interactive){let s=t.orgHint||e.org||void 0,p=await r(s),c=a({appId:t.appId,project:e.project,baseUrl:e.baseUrl,getToken:o(async()=>p.access_token,"getToken")});return await c.authenticate(),c}return i(e,t.appId)}o(I,"getClientForDeployment");import ut from"enquirer";var gt="Enter custom target...";function ft(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(pt,"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;pt(t,e)}let n=e.find(r=>r.project===t||`${r.org}/${r.project}`===t);if(n)return n;pt(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}`),ct],{selected:r}=await at.prompt({type:"select",name:"selected",message:"Select deployment target",choices:n});if(r!==ct){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 at.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 Ar}from"fs";import{resolve as kr}from"path";import{config as Dr}from"dotenv";function F(e,t={existsSync:Ar,config:Dr}){let n=kr(e,".env");t.existsSync(n)&&(console.log(`Loading environment variables from ${n}`),t.config({path:n}))}o(F,"loadEnvFile");function O(e){e.infra!=="appsApi"&&(console.error(`
27
+ ${n}`)}o(ft,"deploymentNotFoundError");function b(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;ft(t,e)}let n=e.find(r=>r.project===t||`${r.org}/${r.project}`===t);if(n)return n;ft(t,e)}o(b,"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 b(e.deployments,t.deployment);let n=[...e.deployments.map(a=>`${a.org}/${a.project}`),gt],{selected:r}=await ut.prompt({type:"select",name:"selected",message:"Select deployment target",choices:n});if(r!==gt){let a=e.deployments.find(s=>`${s.org}/${s.project}`===r);if(a)return a;throw new Error(`Deployment "${r}" could not be resolved from app.json.`)}let i=await ut.prompt([{type:"input",name:"baseUrl",message:"CDF Base URL",initial:"https://api.cognitedata.com"},{type:"input",name:"project",message:"CDF Project",validate:o(a=>a?!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 _r}from"fs";import{resolve as Ur}from"path";import{config as Lr}from"dotenv";function F(e,t={existsSync:_r,config:Lr}){let n=Ur(e,".env");t.existsSync(n)&&(console.log(`Loading environment variables from ${n}`),t.config({path:n}))}o(F,"loadEnvFile");function O(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(O,"assertAppHostingInfra");async function Ir(e){let t=process.cwd();F(t);let n=C(t);O(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 E?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(Ir,"handleActivate");function lt(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",`
34
+ `),process.exit(1))}o(O,"assertAppHostingInfra");async function Nr(e){let t=process.cwd();F(t);let n=w(t);O(n);let r=e.interactive?await $(n,e):b(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}),a=new h(i),{externalId:s,versionTag:p}=n,c;try{c=await a.getVersion(s,p)}catch(m){throw m instanceof k?new Error(`Version ${p} of ${s} has not been deployed yet. Run \`npx @cognite/cli apps deploy\` first.`):m}if(c.alias==="ACTIVE"){console.log(` ${s} @ ${p} is already ACTIVE \u2014 nothing to do.`);return}if(c.lifecycleState==="DEPRECATED"||c.lifecycleState==="ARCHIVED")throw new Error(`Cannot activate ${s} @ ${p}: version is ${c.lifecycleState} (terminal).`);c.lifecycleState==="DRAFT"&&(await a.publishVersion(s,p),console.log(`\u2713 Published ${s} @ ${p} is now PUBLISHED`));let{supersededVersion:l}=await a.activateVersion(s,p);console.log(`\u2713 Activated ${s} @ ${p} is now ACTIVE`),l&&console.log(` Superseded ${l} \u2192 PUBLISHED`)}o(Nr,"handleActivate");function yt(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)=>Ir(n))}o(lt,"registerActivateCommand");import{readdirSync as Vr}from"fs";import{basename as Pt,dirname as Hr,normalize as Gr,resolve as X}from"path";import{fileURLToPath as Br,pathToFileURL as Yr}from"url";import{Logger as Jr,runner as Xr}from"hygen";import{safeParse as Tr}from"valibot";function J(e,t){return n=>{let r=Tr(t,n);return r.success?!0:`${e} ${r.issues[0].message}`}}o(J,"toPromptValidator");var mt={name:J("App name",fe),displayName:J("Display name",ge),baseUrl:J("Base URL",ye),org:J("Org",he),project:J("Project",we)};function $r(e,t){return e?async n=>{let r=t(n);return r===!0?e(n):r}:t}o($r,"composeValidators");function te(e){return e.map(t=>{if(!(t.name in mt))return t;let n=mt[t.name];return{...t,validate:$r(t.validate,n)}})}o(te,"applySchemaValidators");import{execFileSync as ne}from"child_process";function dt(e={}){let{execFileSync:t=ne}=e;try{return t("git",["--version"],{stdio:"ignore"}),!0}catch{return!1}}o(dt,"isGitInstalled");function ut(e,t={}){let{execFileSync:n=ne}=t;try{return n("git",["-C",e,"status"],{stdio:"ignore"}),!0}catch{return!1}}o(ut,"isInsideGitRepo");function gt(e,t={}){let{execFileSync:n=ne}=t;n("git",["-C",e,"init"],{stdio:"pipe"}),n("git",["-C",e,"add","."],{stdio:"pipe"}),n("git",["-C",e,"commit","-m","Initial commit","--no-gpg-sign","--no-verify"],{stdio:"pipe"})}o(gt,"gitInitAndCommit");function ft(e={}){let{execFileSync:t=ne}=e;try{return String(t("git",["config","--get","user.email"],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]})).trim()||void 0}catch{return}}o(ft,"gitUserEmail");import{basename as ht}from"path";import wt from"enquirer";function yt(e){return e.replace(/[A-Z]/g,(t,n)=>n===0?t.toLowerCase():`-${t.toLowerCase()}`)}o(yt,"kebabCase");var Fr={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 Or(e){return!!(await e([Fr])).useSpecKit}o(Or,"promptForSpecKit");async function Rr(e,t,n){return e!==void 0?e:t?Or(n):!1}o(Rr,"resolveSpecKit");function Ct({isCurrentDir:e,dirName:t,onAppName:n,onUseSpecKit:r,presets:i={},specKit:s,prompt:a=wt.prompt.bind(wt)}){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?ht(process.cwd()):t?ht(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(Un=>Un.name!=="baseUrl"),pe=y.length>0?await a(y):{},$n=typeof pe.cluster=="string"?pe.cluster:"",Fn=typeof g.cluster=="string"?g.cluster:"",On=`https://${($n||Fn).trim().replace(/\/+$/,"")||"api"}.cognitedata.com`,Rn=v[Z],_n=await a([{...Rn,initial:On}]);M={...pe,..._n}}else M=v.length>0?await a(v):{};let _={...g,...M},x=typeof _.name=="string"?_.name:"";x&&n(x);let A=await Rr(s,v.length>0,a);return r?.(A),{..._,name:x,useCurrentDir:e,directoryName:e?void 0:t??void 0,useSpecKit:A}},"prompt")})}o(Ct,"createAppPrompter");async function Et(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:`--${yt(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(Et,"validatePresets");import{cpSync as Ur,mkdirSync as St,writeFileSync as Lr}from"fs";import{dirname as vt,resolve as L}from"path";import{fileURLToPath as Nr}from"url";import{symlinkSync as _r}from"fs";function re({target:e,linkPath:t,label:n,symlink:r=_r}){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(re,"symlinkOrWarn");var Kr=L(vt(Nr(import.meta.url)),"..","..","_vendor","spec-kit"),jr={branch_numbering:"sequential"},Mr=[{from:"templates",to:".specify/templates"},{from:"scripts/bash",to:".specify/scripts/bash"},{from:"commands",to:".claude/commands"},{from:"commands",to:".cursor/commands"}];function xt({appDir:e,vendorDir:t=Kr}){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 Mr){let c=L(e,a);i=`copy ${s} to ${a}`,St(vt(c),{recursive:!0}),Ur(L(t,s),c,{recursive:!0})}i=`write init-options.json under specifyDir=${n}`,Lr(L(n,"init-options.json"),`${JSON.stringify(jr,null,2)}
39
- `),i=`link .specify/memory/constitution.md in specifyDir=${n}`,St(r,{recursive:!0}),re({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(xt,"installSpecKit");var bt=X(Hr(Br(import.meta.url)),"..","..","_templates");async function zr(){let e=X(bt,"app","new","prompt.js");return(await import(Yr(e).href)).default}o(zr,"loadPromptDefs");function Wr(e,t){return!e||t?null:Gr(e)}o(Wr,"resolveDirName");function qr(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(qr,"resolveAppLocation");function Qr(e,t,n){let r=` npm install
40
- npm run dev`,i="To deploy your app:",s="npx @cognite/cli apps deploy --interactive",a=n?`
37
+ npx @cognite/cli apps activate . --interactive Activate using browser auth (no secrets needed)`).action((t,n)=>Nr(n))}o(yt,"registerActivateCommand");import{readdirSync as to}from"fs";import{basename as $t,dirname as no,normalize as ro,resolve as Q}from"path";import{fileURLToPath as oo,pathToFileURL as io}from"url";import{Logger as so,runner as ao}from"hygen";import{execFileSync as se}from"child_process";function ht(e={}){let{execFileSync:t=se}=e;try{return t("git",["--version"],{stdio:"ignore"}),!0}catch{return!1}}o(ht,"isGitInstalled");function Ct(e,t={}){let{execFileSync:n=se}=t;try{return n("git",["-C",e,"status"],{stdio:"ignore"}),!0}catch{return!1}}o(Ct,"isInsideGitRepo");function wt(e,t={}){let{execFileSync:n=se}=t;n("git",["-C",e,"init"],{stdio:"pipe"}),n("git",["-C",e,"add","."],{stdio:"pipe"}),n("git",["-C",e,"commit","-m","Initial commit","--no-gpg-sign","--no-verify"],{stdio:"pipe"})}o(wt,"gitInitAndCommit");function vt(e={}){let{execFileSync:t=se}=e;try{return String(t("git",["config","--get","user.email"],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]})).trim()||void 0}catch{return}}o(vt,"gitUserEmail");import{safeParse as jr}from"valibot";function q(e,t){return n=>{let r=jr(t,n);return r.success?!0:`${e} ${r.issues[0].message}`}}o(q,"toPromptValidator");var Et={name:q("App name",Ee),displayName:q("Display name",ve),baseUrl:q("Base URL",Se),org:q("Org",xe),project:q("Project",Pe)};function Kr(e,t){return e?async n=>{let r=t(n);return r===!0?e(n):r}:t}o(Kr,"composeValidators");function ae(e){return e.map(t=>{if(!(t.name in Et))return t;let n=Et[t.name];return{...t,validate:Kr(t.validate,n)}})}o(ae,"applySchemaValidators");import{basename as xt}from"path";import Pt from"enquirer";function St(e){return e.replace(/[A-Z]/g,(t,n)=>n===0?t.toLowerCase():`-${t.toLowerCase()}`)}o(St,"kebabCase");var Mr={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 Vr(e){return!!(await e([Mr])).useSpecKit}o(Vr,"promptForSpecKit");async function Hr(e,t,n){return e!==void 0?e:t?Vr(n):!1}o(Hr,"resolveSpecKit");function bt({isCurrentDir:e,dirName:t,onAppName:n,onUseSpecKit:r,presets:i={},specKit:a,prompt:s=Pt.prompt.bind(Pt)}){return()=>({prompt:o(async p=>{if(!Array.isArray(p))return s([p]);let c=Object.fromEntries(Object.entries(i).filter(f=>f[1]!==void 0)),l=Object.keys(c).length>0,m=e?xt(process.cwd()):t?xt(t):null,d=l&&m!==null,u=!d&&m?p.map(f=>f.name==="name"?{...f,initial:m}:f):p,C=ae(u),g=d?{...c,name:m}:c,E=new Set(Object.keys(g)),S=C.filter(f=>!E.has(f.name)),y=S.findIndex(f=>f.name==="baseUrl"),R;if(y!==-1){let f=S.filter(Bn=>Bn.name!=="baseUrl"),j=f.length>0?await s(f):{},oe=typeof j.cluster=="string"?j.cluster:"",K=typeof g.cluster=="string"?g.cluster:"",Vn=`https://${(oe||K).trim().replace(/\/+$/,"")||"api"}.cognitedata.com`,Hn=S[y],Gn=await s([{...Hn,initial:Vn}]);R={...j,...Gn}}else R=S.length>0?await s(S):{};let A={...g,...R},x=typeof A.name=="string"?A.name:"";x&&n(x);let P=await Hr(a,S.length>0,s);return r?.(P),{...A,name:x,useCurrentDir:e,directoryName:e?void 0:t??void 0,useSpecKit:P}},"prompt")})}o(bt,"createAppPrompter");async function At(e,t,n){let r=[];Object.values(t).some(a=>a!==void 0)&&n!==null&&r.push({key:"name",value:n,label:"directory"});for(let[a,s]of Object.entries(t))s!==void 0&&r.push({key:a,value:s,label:`--${St(a)}`});for(let{key:a,value:s,label:p}of r){let c=e.find(m=>m.name===a)?.validate;if(!c)continue;let l=await c(s);if(l!==!0)throw new Error(`Invalid ${p}: ${l}`)}}o(At,"validatePresets");import{cpSync as zr,mkdirSync as Dt,writeFileSync as Wr}from"fs";import{dirname as It,resolve as V}from"path";import{fileURLToPath as qr}from"url";import{copyFileSync as Gr,symlinkSync as Br}from"fs";import{dirname as Yr,join as Jr}from"path";function Xr(e){if(e&&typeof e=="object"&&"code"in e&&typeof e.code=="string")return e.code}o(Xr,"errno");function kt(e){return e instanceof Error?e.message:String(e)}o(kt,"messageOf");function pe({target:e,linkPath:t,label:n,symlink:r=Br,copyFile:i=Gr}){try{return r(e,t),!0}catch(a){let s=Xr(a);if(s==="EEXIST")return!0;let p=kt(a);if(s==="EPERM"||s==="EACCES")try{let c=Jr(Yr(t),e);return i(c,t),console.log(`\u2139\uFE0F Wrote ${n} as a copy of ${e} (symlinks need Developer Mode or an elevated shell on Windows).`),!0}catch(c){return console.warn(`\u26A0\uFE0F Could not create ${n} symlink: ${p} (copy fallback also failed: ${kt(c)})`),!1}return console.warn(`\u26A0\uFE0F Could not create ${n} symlink:`,p),!1}}o(pe,"linkOrCopyOrWarn");var Qr=V(It(qr(import.meta.url)),"..","..","_vendor","spec-kit"),Zr={branch_numbering:"sequential"},eo=[{from:"templates",to:".specify/templates"},{from:"scripts/bash",to:".specify/scripts/bash"},{from:"commands",to:".claude/commands"},{from:"commands",to:".cursor/commands"}];function Tt({appDir:e,vendorDir:t=Qr}){let n=V(e,".specify"),r=V(n,"memory"),i=`prepare spec-kit install for appDir=${e}`;try{for(let{from:a,to:s}of eo){let p=V(e,s);i=`copy ${a} to ${s}`,Dt(It(p),{recursive:!0}),zr(V(t,a),p,{recursive:!0})}i=`write init-options.json under specifyDir=${n}`,Wr(V(n,"init-options.json"),`${JSON.stringify(Zr,null,2)}
39
+ `),i=`link .specify/memory/constitution.md in specifyDir=${n}`,Dt(r,{recursive:!0}),pe({target:"../../AGENTS.md",linkPath:V(r,"constitution.md"),label:".specify/memory/constitution.md"})}catch(a){let s=a instanceof Error?a.message:String(a);throw new Error(`installSpecKit failed while ${i} (appDir=${e}, vendorDir=${t}): ${s}`,{cause:a})}}o(Tt,"installSpecKit");var Ft=Q(no(oo(import.meta.url)),"..","..","_templates");async function po(){let e=Q(Ft,"app","new","prompt.js");return(await import(io(e).href)).default}o(po,"loadPromptDefs");function co(e,t){return!e||t?null:ro(e)}o(co,"resolveDirName");function lo(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:Q(process.cwd(),r),display:r}}o(lo,"resolveAppLocation");function mo(e,t,n){let r=` npm install
40
+ npm run dev`,i="To deploy your app:",a="npx @cognite/cli apps deploy --interactive",s=n?`
41
41
  To start spec-driven development:
42
42
  Run /speckit.specify in Claude Code or Cursor and describe your app.
43
- `:"",c=` # Or fully non-interactive (deploys first target from app.json):
43
+ `:"",p=` # 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
 
47
47
  Next steps:
48
48
  ${r}
49
- ${a}
49
+ ${s}
50
50
  ${i}
51
- ${s}
52
- ${c}
51
+ ${a}
52
+ ${p}
53
53
  `);return}console.log(`
54
54
  \u2705 App created successfully!
55
55
 
@@ -58,13 +58,13 @@ To open in Cursor:
58
58
  Or:
59
59
  cd "${t}"
60
60
  ${r}
61
- ${a}
61
+ ${s}
62
62
  ${i}
63
63
  cd "${t}"
64
- ${s}
65
- ${c}
66
- `)}o(Qr,"printSuccessMessage");async function Zr(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=Vr(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(Zr,"pullSkillsInto");function eo(e,t={}){let{isGitInstalled:n=dt,isInsideGitRepo:r=ut,gitInitAndCommit:i=gt}=t;if(!n()){console.warn("git not found \u2014 skipping git repository initialisation");return}if(!r(e)){console.log("Initialising git repository...");try{i(e)}catch(s){let c=(s&&typeof s=="object"&&"stderr"in s&&s.stderr?String(s.stderr).trim():"")||(s instanceof Error?s.message:String(s));console.warn("Could not initialise git repository:",c)}}}o(eo,"maybeInitGit");async function to(e,t){let n=e==="."||e==="./",r=Wr(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 zr(),p=te(c),l=n?Pt(process.cwd()):r?Pt(r):null;await Et(p,a,l);let m=Ct({isCurrentDir:n,dirName:r,onAppName:o(u=>{i=u},"onAppName"),onUseSpecKit:o(u=>{s=u},"onUseSpecKit"),presets:a,specKit:t.specKit});await Xr(["app","new"],{templates:bt,cwd:process.cwd(),logger:new Jr(console.log.bind(console)),createPrompter:m,debug:!!process.env.DEBUG});let d=qr(n,r,i);re({target:"AGENTS.md",linkPath:X(d.cwd,"CLAUDE.md"),label:"CLAUDE.md"}),s&&xt({appDir:d.cwd}),await Zr(d.cwd),eo(d.cwd),Qr(n,d.display,s)}o(to,"handleCreate");function At(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",`
64
+ ${a}
65
+ ${p}
66
+ `)}o(mo,"printSuccessMessage");async function uo(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=Q(e,".agents","skills"),i=0;try{i=to(r).length}catch{console.warn(`Skills directory not found after pull \u2014 no skills may have been installed (expected: ${r})`)}let a=i>0?`${i} skills`:"skills";console.log(`\u2705 Installed ${a} 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(uo,"pullSkillsInto");function go(e,t={}){let{isGitInstalled:n=ht,isInsideGitRepo:r=Ct,gitInitAndCommit:i=wt}=t;if(!n()){console.warn("git not found \u2014 skipping git repository initialisation");return}if(!r(e)){console.log("Initialising git repository...");try{i(e)}catch(a){let p=(a&&typeof a=="object"&&"stderr"in a&&a.stderr?String(a.stderr).trim():"")||(a instanceof Error?a.message:String(a));console.warn("Could not initialise git repository:",p)}}}o(go,"maybeInitGit");async function fo(e,t){let n=e==="."||e==="./",r=co(e,n),i=null,a=!1,s={displayName:t.displayName,description:t.description,org:t.org,project:t.project,cluster:t.cluster,baseUrl:t.baseUrl},p=await po(),c=ae(p),l=n?$t(process.cwd()):r?$t(r):null;await At(c,s,l);let m=bt({isCurrentDir:n,dirName:r,onAppName:o(u=>{i=u},"onAppName"),onUseSpecKit:o(u=>{a=u},"onUseSpecKit"),presets:s,specKit:t.specKit});await ao(["app","new"],{templates:Ft,cwd:process.cwd(),logger:new so(console.log.bind(console)),createPrompter:m,debug:!!process.env.DEBUG});let d=lo(n,r,i);pe({target:"AGENTS.md",linkPath:Q(d.cwd,"CLAUDE.md"),label:"CLAUDE.md"}),a&&Tt({appDir:d.cwd}),await uo(d.cwd),go(d.cwd),mo(n,d.display,a)}o(fo,"handleCreate");function Ot(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,17 @@ 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(to)}o(At,"registerCreateCommand");import{readFile as co,unlink as po}from"fs/promises";import{basename as lo}from"path";import Dt from"fs";import so from"path";import R from"fs";import w from"path";import{parseAndValidateManifestConfig as no}from"@cognite/app-sdk/vite";import{BlobReader as ro,Uint8ArrayWriter as oo,ZipWriter as io}from"@zip.js/zip.js";var xe="package.json",Pe="package-lock.json",kt="manifest.json",be=".cognite",Ae=class Ae{constructor(t="dist"){this.distPath=w.isAbsolute(t)?t:w.join(process.cwd(),t),this.appRoot=w.dirname(this.distPath)}validateBuildDirectory(){if(!R.existsSync(this.distPath))throw new Error(`Build directory "${this.distPath}" not found. Run build first.`);let t=w.join(this.appRoot,xe);if(!R.existsSync(t))throw new Error(`"${t}" not found. It is required for deployment.`);let n=w.join(this.appRoot,Pe);if(!R.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 io(new oo,{level:9}),i=o(async(p,l)=>{await r.add(l,new ro(await R.openAsBlob(p))),n&&console.log(` \u{1F4C4} ${l}`)},"addFile"),s=o(async p=>{let l=await R.promises.readdir(p,{withFileTypes:!0});for(let m of l){let d=w.join(p,m.name);m.isDirectory()?await s(d):await i(d,w.relative(this.distPath,d).replace(/\\/g,"/"))}},"addDir"),a;try{await s(this.distPath);let p=w.join(this.appRoot,xe);await i(p,w.posix.join(be,xe));let l=w.join(this.appRoot,kt);if(R.existsSync(l)){let d=R.readFileSync(l,"utf-8");no(d,l),await i(l,w.posix.join(be,kt))}let m=w.join(this.appRoot,Pe);await i(m,w.posix.join(be,Pe)),a=await r.close()}catch(p){let l=p instanceof Error?p.message:String(p);throw new Error(`Failed to create zip: ${l}`)}await R.promises.writeFile(t,a);let c=(a.byteLength/1024/1024).toFixed(2);return console.log(`\u2705 App packaged: ${t} (${c} MB)`),t}};o(Ae,"ApplicationPackager");var N=Ae;var ke=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=Dt.readFileSync(r),d=so.basename(r);await l.deploy(i,s,a,c,m,d,e.published)}finally{try{Dt.unlinkSync(r)}catch{}}},"deploy");import{execSync as ao}from"child_process";function De(e,t=!0,n={execSync:ao}){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(De,"buildApp");function It(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(It,"generateFusionUrl");function Tt(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(Tt,"printDeployInfo");function $t(e,t){console.log(`
80
+ Fully non-interactive`).action(fo)}o(Ot,"registerCreateCommand");import yo from"path";async function ho(e,t,n){let r=await I(e,{interactive:t.interactive,appId:n,orgHint:t.org});return new h(r)}o(ho,"defaultGetApiClient");async function Co(e,t,n={}){let{loadEnvFile:r=F,loadAppConfig:i=w,getApiClient:a=ho}=n,s=yo.resolve(process.cwd(),e);r(s);let p=i(s);O(p);let c=t.interactive?await $(p,t):b(p.deployments,t.deployment);if(!t.interactive){let u=T(c);if(u.length>0)throw new Error(`Deployment ${c.org}/${c.project} is missing ${u.join(" and ")} in app.json. Use \`npx @cognite/cli@latest apps deactivate --interactive\` for browser-based authentication instead.`)}let l=await a(c,t,p.externalId),{externalId:m}=p,d=await l.getActiveVersion(m);if(!d){console.log(` ${m} has no active version \u2014 nothing to deactivate.`);return}await l.deactivateVersion(m,d.version),console.log(`\u2713 Deactivated ${m} @ ${d.version} \u2014 active alias removed`)}o(Co,"handleDeactivate");function Rt(e){return e.command("deactivate").description("Deactivate the app by removing its active version from service").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",`
81
+ Examples:
82
+ npx @cognite/cli apps deactivate . Deactivate using env-var auth
83
+ npx @cognite/cli apps deactivate . --interactive Deactivate using browser auth (no secrets needed)`).action((t,n)=>Co(t,n))}o(Rt,"registerDeactivateCommand");import{readFile as bo,unlink as Ao}from"fs/promises";import{basename as ko}from"path";import Ut from"fs";import xo from"path";import L from"fs";import v from"path";import{parseAndValidateManifestConfig as wo}from"@cognite/app-sdk/vite";import{BlobReader as vo,Uint8ArrayWriter as Eo,ZipWriter as So}from"@zip.js/zip.js";var Ie="package.json",Te="package-lock.json",_t="manifest.json",$e=".cognite",Fe=class Fe{constructor(t="dist"){this.distPath=v.isAbsolute(t)?t:v.join(process.cwd(),t),this.appRoot=v.dirname(this.distPath)}validateBuildDirectory(){if(!L.existsSync(this.distPath))throw new Error(`Build directory "${this.distPath}" not found. Run build first.`);let t=v.join(this.appRoot,Ie);if(!L.existsSync(t))throw new Error(`"${t}" not found. It is required for deployment.`);let n=v.join(this.appRoot,Te);if(!L.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 So(new Eo,{level:9}),i=o(async(c,l)=>{await r.add(l,new vo(await L.openAsBlob(c))),n&&console.log(` \u{1F4C4} ${l}`)},"addFile"),a=o(async c=>{let l=await L.promises.readdir(c,{withFileTypes:!0});for(let m of l){let d=v.join(c,m.name);m.isDirectory()?await a(d):await i(d,v.relative(this.distPath,d).replace(/\\/g,"/"))}},"addDir"),s;try{await a(this.distPath);let c=v.join(this.appRoot,Ie);await i(c,v.posix.join($e,Ie));let l=v.join(this.appRoot,_t);if(L.existsSync(l)){let d=L.readFileSync(l,"utf-8");wo(d,l),await i(l,v.posix.join($e,_t))}let m=v.join(this.appRoot,Te);await i(m,v.posix.join($e,Te)),s=await r.close()}catch(c){let l=c instanceof Error?c.message:String(c);throw new Error(`Failed to create zip: ${l}`)}await L.promises.writeFile(t,s);let p=(s.byteLength/1024/1024).toFixed(2);return console.log(`\u2705 App packaged: ${t} (${p} MB)`),t}};o(Fe,"ApplicationPackager");var H=Fe;var Oe=o(async(e,t,n)=>{let r=await new H(`${n}/dist`).createZip("app.zip",!0);try{let{externalId:i,name:a,description:s,versionTag:p}=t,c=await W(e,n),l=new h(c),m=Ut.readFileSync(r),d=xo.basename(r);await l.deploy(i,a,s,p,m,d,e.published)}finally{try{Ut.unlinkSync(r)}catch{}}},"deploy");import{execSync as Po}from"child_process";function Re(e,t=!0,n={execSync:Po}){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(Re,"buildApp");function Lt(e,t){let{org:n,project:r,baseUrl:i}=e,a;try{a=new URL(i).hostname}catch{return null}let{externalId:s,versionTag:p}=t,c=new URLSearchParams({cluster:a,customAppVersion:p,workspace:"industrial-tools"});return`https://${n}.fusion.cognite.com/${r}/flows-apps/app/${encodeURIComponent(s)}?${c}`}o(Lt,"generateFusionUrl");function Nt(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(`
84
+ `))}o(Nt,"printDeployInfo");function jt(e,t){console.log(`
82
85
  \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=It(t,e);r&&console.log(`
86
+ To publish: npx @cognite/cli apps publish .${n}`),console.log(`To activate: npx @cognite/cli apps activate .${n}`);let r=Lt(t,e);r&&console.log(`
84
87
  \u{1F517} Open your app:
85
- ${r}`)}o($t,"printDeployResult");async function mo(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.`);Tt(e,t,!1),r.skipBuild||De(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),$t(e,t)}o(mo,"handleDeployNonInteractive");async function uo(e,t,n,r){Tt(e,t,!0),r.skipBuild||De(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 co(s);await new h(i).deploy(e.externalId,e.name,e.description,e.versionTag,a,lo(s),!1),$t(e,t)}finally{await po(s).catch(()=>{})}}o(uo,"handleDeployInteractive");async function go(e,t=process.cwd(),n={}){let{loadEnvFile:r=F,loadAppConfig:i=C,deploy:s=ke}=n;r(t);let a=i(t);if(O(a),e.interactive){let p=await $(a,e);await uo(a,p,t,e);return}let c=P(a.deployments,e.deployment);await mo(a,c,t,e,s)}o(go,"handleDeploy");function Ft(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
+ ${r}`)}o(jt,"printDeployResult");async function Do(e,t,n,r,i){let a=T(t);if(a.length>0)throw new Error(`Deployment ${t.org}/${t.project} is missing ${a.join(" and ")} in app.json. Use \`cognite apps deploy --interactive\` for browser-based authentication instead.`);Nt(e,t,!1),r.skipBuild||Re(n),console.log(`
89
+ \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),jt(e,t)}o(Do,"handleDeployNonInteractive");async function Io(e,t,n,r){Nt(e,t,!0),r.skipBuild||Re(n);let i=await I(t,{interactive:!0,appId:e.externalId,orgHint:r.org});console.log(`
90
+ \u{1F4E4} Deploying to ${t.project}...`);let a=await new H(`${n}/dist`).createZip("app.zip",!0);try{let s=await bo(a);await new h(i).deploy(e.externalId,e.name,e.description,e.versionTag,s,ko(a),!1),jt(e,t)}finally{await Ao(a).catch(()=>{})}}o(Io,"handleDeployInteractive");async function To(e,t=process.cwd(),n={}){let{loadEnvFile:r=F,loadAppConfig:i=w,deploy:a=Oe}=n;r(t);let s=i(t);if(O(s),e.interactive){let c=await $(s,e);await Io(s,c,t,e);return}let p=b(s.deployments,e.deployment);await Do(s,p,t,e,a)}o(To,"handleDeploy");function Kt(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
91
  Environment (non-interactive):
89
92
  deployClientId and deploySecretName are configured per deployment in app.json.
90
93
  deploySecretName is the name of the environment variable that holds the client
@@ -98,42 +101,43 @@ Examples:
98
101
  npx @cognite/cli apps deploy -d my-project Deploy to project by name
99
102
  npx @cognite/cli apps deploy --skip-build Deploy without rebuilding
100
103
  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=>go(t))}o(Ft,"registerDeployCommand");async function fo(e){let t=process.cwd();F(t);let n=C(t);O(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 E?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(fo,"handlePublish");function Ot(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",`
104
+ npx @cognite/cli apps deploy --interactive -d 0 Browser auth, target chosen non-interactively`).action(t=>To(t))}o(Kt,"registerDeployCommand");async function $o(e){let t=process.cwd();F(t);let n=w(t);O(n);let r=e.interactive?await $(n,e):b(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}),a=new h(i),{externalId:s,versionTag:p}=n,c;try{c=await a.getVersion(s,p)}catch(l){throw l instanceof k?new Error(`Version ${p} of ${s} has not been deployed yet. Run \`npx @cognite/cli apps deploy\` first.`):l}if(c.alias==="ACTIVE"){console.log(` ${s} @ ${p} is already ACTIVE \u2014 nothing to do.`);return}if(c.lifecycleState==="PUBLISHED"){console.log(` ${s} @ ${p} is already PUBLISHED \u2014 nothing to do.`);return}if(c.lifecycleState==="DEPRECATED"||c.lifecycleState==="ARCHIVED")throw new Error(`Cannot publish ${s} @ ${p}: version is ${c.lifecycleState} (terminal).`);await a.publishVersion(s,p),console.log(`\u2713 Published ${s} @ ${p} is now PUBLISHED`),console.log(""),console.log("Run `npx @cognite/cli apps activate .` to make it active.")}o($o,"handlePublish");function Mt(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
105
  Examples:
103
106
  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)=>fo(n))}o(Ot,"registerPublishCommand");function yo(e){return e.alias==="ACTIVE"?"ACTIVE":e.lifecycleState}o(yo,"describeStatus");async function ho(e){let t=process.cwd();F(t);let n=C(t);O(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=yo(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 E){console.log("Status: not deployed yet"),console.log(""),console.log("Run `npx @cognite/cli apps deploy` to upload this version.");return}throw a}}o(ho,"handleStatus");function Rt(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",`
107
+ npx @cognite/cli apps publish . --interactive Publish using browser auth (no secrets needed)`).action((t,n)=>$o(n))}o(Mt,"registerPublishCommand");function Fo(e){return e.alias==="ACTIVE"?"ACTIVE":e.lifecycleState}o(Fo,"describeStatus");async function Oo(e){let t=process.cwd();F(t);let n=w(t);O(n);let r=e.interactive?await $(n,e):b(n.deployments,e.deployment);if(!e.interactive){let s=T(r);if(s.length>0)throw new Error(`Deployment ${r.org}/${r.project} is missing ${s.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}),a=new h(i);console.log(""),console.log(`App: ${n.name} (${n.externalId})`),console.log(`Version: ${n.versionTag} (local)`);try{let s=await a.getVersion(n.externalId,n.versionTag),p=Fo(s);console.log(`Status: ${p}`),s.lifecycleState==="DRAFT"&&(console.log(""),console.log("Run `npx @cognite/cli apps publish .` to publish this version."))}catch(s){if(s instanceof k){console.log("Status: not deployed yet"),console.log(""),console.log("Run `npx @cognite/cli apps deploy` to upload this version.");return}throw s}}o(Oo,"handleStatus");function Vt(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
108
  Examples:
106
109
  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)=>ho(n))}o(Rt,"registerStatusCommand");function _t(e){let t=e.command("apps").description("Manage Fusion Custom Apps \u2014 create, deploy, and manage version lifecycle");return At(t),Ft(t),Rt(t),Ot(t),lt(t),Be(t),t}o(_t,"registerAppsCommand");import{existsSync as li,mkdirSync as mi,writeFileSync as di}from"fs";import{dirname as Le,join as Ne}from"path";import{execFile as Co}from"child_process";import{promisify as Eo}from"util";import{platform as wo}from"os";function K(e={}){let{platform:t=wo}=e;return t()==="darwin"}o(K,"isMacOS");var Ut="cognite-flows",So=Eo(Co),Lt=o((e,t)=>So(e,t),"defaultExecFile"),vo=-25300,xo=vo&255;function Po(e){if(!(e instanceof Error)||!("code"in e)||e.code!==xo)return!1;let t="stderr"in e?String(e.stderr):"";return/could not be found/i.test(t)||t===""}o(Po,"isKeychainNotFoundError");async function Nt(e,t,n={}){if(!K(n))throw new Error("Keychain storage is only supported on macOS");let{execFile:r=Lt}=n;await r("security",["add-generic-password","-a",e,"-s",Ut,"-w",Buffer.from(t,"utf-8").toString("base64"),"-U"])}o(Nt,"storeKeyInKeychain");async function Kt(e,t={}){if(!K(t))return null;let{execFile:n=Lt}=t;try{let{stdout:r}=await n("security",["find-generic-password","-a",e,"-s",Ut,"-w"]);return Buffer.from(r.trim(),"base64").toString("utf-8")}catch(r){if(Po(r))return null;throw r}}o(Kt,"readKeyFromKeychain");import{pbkdf2 as ko,randomBytes as Do}from"crypto";import{promisify as Io}from"util";import{CompactEncrypt as To,base64url as $o,compactDecrypt as dp}from"jose";var bo=new TextEncoder,Ao=new TextDecoder,jt={encode:o(e=>bo.encode(e),"encode"),decode:o(e=>Ao.decode(e),"decode")};var Fo=Io(ko),Ie=6e5,Oo="sha512",Ro="PBKDF2-HMAC-SHA512",_o=16,Uo="A256GCM",Lo=32,Mt=2e6;async function No(e,t,n){return await Fo(e,t,n,Lo,Oo)}o(No,"deriveKey");async function Vt(e,t,n=Ie){if(!Number.isInteger(n)||n<1||n>Mt)throw new Error(`Invalid iterations: must be an integer between 1 and ${Mt}`);let r=Do(_o),i=await No(t,r,n);return await new To(jt.encode(e)).setProtectedHeader({alg:"dir",enc:Uo,kdf:Ro,kdf_iter:n,kdf_salt:$o.encode(r)}).encrypt(i)}o(Vt,"encryptStringAsJwe");import{calculateJwkThumbprint as Ko,exportJWK as jo,exportPKCS8 as Mo,exportSPKI as Vo,generateKeyPair as Ho}from"jose";async function Ht(){let{publicKey:e,privateKey:t}=await Ho("EdDSA",{extractable:!0}),n=await Mo(t),r=await Vo(e),i=await jo(e),s=await Ko(i);return{privateKeyPem:n,publicKeyPem:r,kid:s}}o(Ht,"generateSigningKeyPair");import{existsSync as Bo,readdirSync as Yo,readFileSync as Jo}from"fs";import{join as oe}from"path";import{homedir as Go}from"os";import{join as Gt}from"path";function j(e={}){let{env:t=process.env,homedir:n=Go}=e,r=t.DUNE_HOME?.trim()||Gt(n(),".dune");return{home:r,keysDir:Gt(r,"keys")}}o(j,"getConfig");var ie=".pub.pem",Te=".key.jwe",Xo=".pem",$e=".meta.json";function Bt(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(Bt,"formatLocalKeySource");function zo(e){return{existsSync:e.existsSync??Bo,readdirSync:e.readdirSync??Yo,readFileSync:e.readFileSync??((t,n)=>Jo(t,n)),isMacOS:e.isMacOS??(()=>K()),readKeyFromKeychain:e.readKeyFromKeychain??(t=>Kt(t))}}o(zo,"resolveDeps");function Wo(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(Wo,"readEmailFromMeta");function qo(e,t){return t.existsSync(e)?t.readdirSync(e).filter(n=>n.endsWith(ie)):[]}o(qo,"publicKeyEntries");function Qo(e){return e.slice(0,-ie.length)}o(Qo,"kidFromPublicKeyFilename");async function Zo(e,t,n){if(n.isMacOS()&&await n.readKeyFromKeychain(e).catch(()=>null)!==null)return{kind:"keychain"};let r=oe(t,`${e}${Te}`);if(n.existsSync(r))return{kind:"encrypted-file",path:r};let i=oe(t,`${e}${Xo}`);return n.existsSync(i)?{kind:"legacy-unencrypted-file",path:i}:{kind:"public-only"}}o(Zo,"resolveSource");async function Yt(e=j().keysDir,t={}){let n=zo(t),r=new Set,i=qo(e,n).flatMap(s=>{let a=Qo(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 Zo(s,e,n),p=oe(e,`${s}${$e}`),l;try{l=Wo(n.readFileSync(p,"utf8"))}catch{}return{kid:s,source:c,publicKeyPath:oe(e,a),email:l}}))}o(Yt,"discoverLocalKeys");function Jt(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(Jt,"addMonthsClamped");function Fe(e){return e.toISOString().slice(0,10)}o(Fe,"formatIsoDate");function Xt(e=new Date){return Fe(e)}o(Xt,"todayIso");import ei,{Chalk as ti}from"chalk";var Oe=new ti({level:0});function zt(e){return e.isTTY?ei:Oe}o(zt,"chalkForStream");function ni(e){return e.replace(/-----BEGIN [^-]+-----/g,"").replace(/-----END [^-]+-----/g,"").replace(/\s+/g,"")}o(ni,"pemBodyOneLine");function Wt(e,t=Oe,n=new Date){let r=e.issuedAt??Xt(n),i=ni(e.publicKeyPem),s=" ",a=o((p,l)=>`${s}${t.cyan(p)}${t.dim(":")} ${l}
108
- `,"kv"),c="";return c+=`
110
+ npx @cognite/cli apps status . --interactive Status using browser auth (no secrets needed)`).action((t,n)=>Oo(n))}o(Vt,"registerStatusCommand");function Ht(e){let t=e.command("apps").description("Manage Fusion Custom Apps \u2014 create, deploy, and manage version lifecycle");return Ot(t),Kt(t),Vt(t),Mt(t),yt(t),Rt(t),qe(t),t}o(Ht,"registerAppsCommand");import{existsSync as Ei,mkdirSync as Si,writeFileSync as xi}from"fs";import{dirname as He,join as ue}from"path";import{generateSigningKeyPair as Pi}from"@cognite/app-sdk/codesigning";import{execFile as _o}from"child_process";import{promisify as Uo}from"util";import{platform as Ro}from"os";function G(e={}){let{platform:t=Ro}=e;return t()==="darwin"}o(G,"isMacOS");var Gt="cognite-flows",Lo=Uo(_o),Bt=o((e,t)=>Lo(e,t),"defaultExecFile"),No=-25300,jo=No&255;function Ko(e){if(!(e instanceof Error)||!("code"in e)||e.code!==jo)return!1;let t="stderr"in e?String(e.stderr):"";return/could not be found/i.test(t)||t===""}o(Ko,"isKeychainNotFoundError");async function Yt(e,t,n={}){if(!G(n))throw new Error("Keychain storage is only supported on macOS");let{execFile:r=Bt}=n;await r("security",["add-generic-password","-a",e,"-s",Gt,"-w",Buffer.from(t,"utf-8").toString("base64"),"-U"])}o(Yt,"storeKeyInKeychain");async function Jt(e,t={}){if(!G(t))return null;let{execFile:n=Bt}=t;try{let{stdout:r}=await n("security",["find-generic-password","-a",e,"-s",Gt,"-w"]);return Buffer.from(r.trim(),"base64").toString("utf-8")}catch(r){if(Ko(r))return null;throw r}}o(Jt,"readKeyFromKeychain");import{pbkdf2 as Ho,randomBytes as Go}from"crypto";import{promisify as Bo}from"util";import{CompactEncrypt as Yo,base64url as Jo,compactDecrypt as Oc}from"jose";var Mo=new TextEncoder,Vo=new TextDecoder,Xt={encode:o(e=>Mo.encode(e),"encode"),decode:o(e=>Vo.decode(e),"decode")};var Xo=Bo(Ho),_e=6e5,zo="sha512",Wo="PBKDF2-HMAC-SHA512",qo=16,Qo="A256GCM",Zo=32,zt=2e6;async function ei(e,t,n){return await Xo(e,t,n,Zo,zo)}o(ei,"deriveKey");async function Wt(e,t,n=_e){if(!Number.isInteger(n)||n<1||n>zt)throw new Error(`Invalid iterations: must be an integer between 1 and ${zt}`);let r=Go(qo),i=await ei(t,r,n);return await new Yo(Xt.encode(e)).setProtectedHeader({alg:"dir",enc:Qo,kdf:Wo,kdf_iter:n,kdf_salt:Jo.encode(r)}).encrypt(i)}o(Wt,"encryptStringAsJwe");import{existsSync as ni,readdirSync as ri,readFileSync as oi}from"fs";import{join as ce}from"path";import{homedir as ti}from"os";import{join as qt}from"path";function N(e={}){let{env:t=process.env,homedir:n=ti}=e,r=t.DUNE_HOME?.trim()||qt(n(),".dune");return{home:r,keysDir:qt(r,"keys")}}o(N,"getConfig");var ee=".pub.pem",Ue=".key.jwe",ii=".pem",Le=".meta.json";function Qt(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(Qt,"formatLocalKeySource");function si(e){return{existsSync:e.existsSync??ni,readdirSync:e.readdirSync??ri,readFileSync:e.readFileSync??((t,n)=>oi(t,n)),isMacOS:e.isMacOS??(()=>G()),readKeyFromKeychain:e.readKeyFromKeychain??(t=>Jt(t))}}o(si,"resolveDeps");function ai(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(ai,"readEmailFromMeta");function pi(e,t){return t.existsSync(e)?t.readdirSync(e).filter(n=>n.endsWith(ee)):[]}o(pi,"publicKeyEntries");function ci(e){return e.slice(0,-ee.length)}o(ci,"kidFromPublicKeyFilename");async function li(e,t,n){if(n.isMacOS()&&await n.readKeyFromKeychain(e).catch(()=>null)!==null)return{kind:"keychain"};let r=ce(t,`${e}${Ue}`);if(n.existsSync(r))return{kind:"encrypted-file",path:r};let i=ce(t,`${e}${ii}`);return n.existsSync(i)?{kind:"legacy-unencrypted-file",path:i}:{kind:"public-only"}}o(li,"resolveSource");async function Zt(e=N().keysDir,t={}){let n=si(t),r=new Set,i=pi(e,n).flatMap(a=>{let s=ci(a);return!s||r.has(s)?[]:(r.add(s),[{kid:s,entry:a}])});return Promise.all(i.map(async({kid:a,entry:s})=>{let p=await li(a,e,n),c=ce(e,`${a}${Le}`),l;try{l=ai(n.readFileSync(c,"utf8"))}catch{}return{kid:a,source:p,publicKeyPath:ce(e,s),email:l}}))}o(Zt,"discoverLocalKeys");function en(e,t){let n=e.getUTCFullYear(),r=e.getUTCMonth()+t,i=new Date(Date.UTC(n,r+1,0)).getUTCDate(),a=Math.min(e.getUTCDate(),i);return new Date(Date.UTC(n,r,a))}o(en,"addMonthsClamped");function Ne(e){return e.toISOString().slice(0,10)}o(Ne,"formatIsoDate");function tn(e=new Date){return Ne(e)}o(tn,"todayIso");import mi,{Chalk as di}from"chalk";var je=new di({level:0});function nn(e){return e.isTTY?mi:je}o(nn,"chalkForStream");function ui(e){return e.replace(/-----BEGIN [^-]+-----/g,"").replace(/-----END [^-]+-----/g,"").replace(/\s+/g,"")}o(ui,"pemBodyOneLine");function rn(e,t=je,n=new Date){let r=e.issuedAt??tn(n),i=ui(e.publicKeyPem),a=" ",s=o((c,l)=>`${a}${t.cyan(c)}${t.dim(":")} ${l}
111
+ `,"kv"),p="";return p+=`
109
112
  ${t.bold("Add this entry to")} ${t.magenta("services/app-hosting/config/signing-keys.yaml")} ${t.bold("under")} ${t.cyan("public_keys:")}
110
113
 
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(Wt,"renderRegistryEntry");import{email as ri,pipe as oi,safeParse as ii,string as si}from"valibot";var ai=oi(si(),ri());function W(e,t="email"){let n=e.trim();if(!n)throw new Error(`${t} is required`);if(!ii(ai,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 pi from"enquirer";var se=3,qt=`Key expiry in months (${1}-${12})`,Qt="Email address for the registry entry",Zt=`Passphrase for the encrypted private key (min ${15} chars)`,en="Confirm passphrase",tn=o(()=>`Passphrase must be at least ${15} characters`,"passphraseTooShortMsg"),nn=o(e=>`Passphrases do not match (attempt ${e}/${se}).
113
- `,"passphraseMismatchMsg"),rn=`Passphrase confirmation failed after ${se} attempts`;async function Ue(e){return pi.prompt(e)}o(Ue,"defaultPrompt");function on(e){return t=>{try{return e(t),!0}catch(n){return n instanceof Error?n.message:"Invalid"}}}o(on,"parserAsValidator");async function sn(e={}){let{prompt:t=Ue}=e,{months:n}=await t({type:"input",name:"months",message:qt,initial:String(6),validate:on(r=>q(r,"expiry"))});return q(n,"expiry")}o(sn,"promptExpiryMonths");async function an(e={}){let{prompt:t=Ue,gitUserEmail:n=ft}=e,{email:r}=await t({type:"input",name:"email",message:Qt,initial:n(),validate:on(i=>W(i,"email"))});return W(r,"email")}o(an,"promptEmail");async function cn(e={}){let{prompt:t=Ue,stderr:n=process.stderr}=e;for(let r=1;r<=se;r+=1){let{passphrase:i}=await t({type:"password",name:"passphrase",message:Zt,validate:o(a=>a.length>=15?!0:tn(),"validate")}),{confirm:s}=await t({type:"password",name:"confirm",message:en});if(i===s)return i;n.write(nn(r))}throw new Error(rn)}o(cn,"promptPassphrase");function ui(e){return{writeFileSync:e.writeFileSync??di,mkdirSync:e.mkdirSync??mi,existsSync:e.existsSync??li,generateSigningKeyPair:e.generateSigningKeyPair??Ht,encryptStringAsJwe:e.encryptStringAsJwe??Vt,storeKeyInKeychain:e.storeKeyInKeychain??Nt,isMacOS:e.isMacOS??K,promptExpiryMonths:e.promptExpiryMonths??sn,promptEmail:e.promptEmail??an,promptPassphrase:e.promptPassphrase??cn,discoverLocalKeys:e.discoverLocalKeys??(()=>Yt())}}o(ui,"resolveDeps");function ln(e,t={}){let n=ui(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=>yi(i,n)),r.command("list").description("List local signing identities and their storage location").action(()=>gi(n))}o(ln,"registerKeysCommand");async function gi(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,Bt(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(gi,"handleList");function pn(e,t,n){let r=Ne(j().keysDir,`${e}${ie}`);return n.mkdirSync(Le(r),{recursive:!0}),n.writeFileSync(r,t),r}o(pn,"writePublicKey");async function fi(e,t,n,r,i){let s=r??Ne(j().keysDir,`${e}${Te}`);if(i.mkdirSync(Le(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(fi,"writeEncryptedPrivateKey");async function yi(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=Fe(Jt(n,i)),a=e.email!==void 0?W(e.email,"--email"):await t.promptEmail(),c=r?null:await t.promptPassphrase();process.stderr.write(`
114
+ `,p+=`${t.dim("-")} ${t.cyan("kid")}${t.dim(":")} ${t.green(e.kid)}
115
+ `,p+=s("public_key",t.green(i)),p+=s("email",t.yellow(e.email)),p+=s("capabilities",`${t.dim("[")}${t.yellow("developer")}${t.dim("]")}`),p+=s("issued_at",t.green(r)),p+=s("expires",t.green(e.expires)),p+=s("revoked_at",t.dim("null")),p}o(rn,"renderRegistryEntry");import{email as gi,pipe as fi,safeParse as yi,string as hi}from"valibot";var Ci=fi(hi(),gi());function te(e,t="email"){let n=e.trim();if(!n)throw new Error(`${t} is required`);if(!yi(Ci,n).success)throw new Error(`${t} must look like an email (user@example.com); got "${e}"`);return n}o(te,"parseEmail");function ne(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(ne,"parseExpiryMonths");import gn from"enquirer";var le=3,on="Signing identity (kid) \u2014 e.g. jsmith-dev-001 (lowercase letters, digits, hyphens)",sn=`Key expiry in months (${1}-${12})`,an="Email address for the registry entry",pn=`Passphrase for the encrypted private key (min ${15} chars)`,cn="Confirm passphrase",ln=o(()=>`Passphrase must be at least ${15} characters`,"passphraseTooShortMsg"),mn=o(e=>`Passphrases do not match (attempt ${e}/${le}).
116
+ `,"passphraseMismatchMsg"),dn=`Passphrase confirmation failed after ${le} attempts`,un=o(e=>`A signing key with kid "${e}" already exists. Overwrite it?`,"confirmOverwriteMsg");async function de(e){return gn.prompt(e)}o(de,"defaultPrompt");function Ve(e){return t=>{try{return e(t),!0}catch(n){return n instanceof Error?n.message:"Invalid"}}}o(Ve,"parserAsValidator");var vi=/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;function me(e){let t=e.trim();if(!t)throw new Error("--kid must not be empty");if(t.length>64)throw new Error("--kid must be 64 characters or fewer");if(!vi.test(t))throw new Error("--kid must contain only lowercase letters, digits, and hyphens, and must not start or end with a hyphen (e.g. jsmith-dev-001)");return t}o(me,"parseKid");async function fn(e={}){let{prompt:t=de}=e,{kid:n}=await t({type:"input",name:"kid",message:on,validate:Ve(me)});return me(n)}o(fn,"promptKid");async function yn(e={}){let{prompt:t=de}=e,{months:n}=await t({type:"input",name:"months",message:sn,initial:String(6),validate:Ve(r=>ne(r,"expiry"))});return ne(n,"expiry")}o(yn,"promptExpiryMonths");async function hn(e={}){let{prompt:t=de,gitUserEmail:n=vt}=e,{email:r}=await t({type:"input",name:"email",message:an,initial:n(),validate:Ve(i=>te(i,"email"))});return te(r,"email")}o(hn,"promptEmail");async function Cn(e={}){let{prompt:t=de,stderr:n=process.stderr}=e;for(let r=1;r<=le;r+=1){let{passphrase:i}=await t({type:"password",name:"passphrase",message:pn,validate:o(s=>s.length>=15?!0:ln(),"validate")}),{confirm:a}=await t({type:"password",name:"confirm",message:cn});if(i===a)return i;n.write(mn(r))}throw new Error(dn)}o(Cn,"promptPassphrase");async function wn(e,t={}){let{prompt:n=o(i=>gn.prompt(i),"prompt")}=t,{confirmed:r}=await n({type:"confirm",name:"confirmed",message:un(e),initial:!1});return r}o(wn,"promptConfirmOverwrite");function bi(e){return{writeFileSync:e.writeFileSync??xi,mkdirSync:e.mkdirSync??Si,existsSync:e.existsSync??Ei,generateSigningKeyPair:e.generateSigningKeyPair??Pi,encryptStringAsJwe:e.encryptStringAsJwe??Wt,storeKeyInKeychain:e.storeKeyInKeychain??Yt,isMacOS:e.isMacOS??G,promptKid:e.promptKid??fn,promptExpiryMonths:e.promptExpiryMonths??yn,promptEmail:e.promptEmail??hn,promptPassphrase:e.promptPassphrase??Cn,promptConfirmOverwrite:e.promptConfirmOverwrite??wn,discoverLocalKeys:e.discoverLocalKeys??(()=>Zt())}}o(bi,"resolveDeps");function En(e,t={}){let n=bi(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").option("--kid <identifier>","Signing identity name for the registry (e.g. jsmith-dev-001); skips the interactive prompt").option("--force","Overwrite an existing key without prompting for confirmation").action(i=>Di(i,n)),r.command("list").description("List local signing identities and their storage location").action(()=>Ai(n))}o(En,"registerKeysCommand");async function Ai(e){let t=await e.discoverLocalKeys();if(t.length===0){process.stdout.write(`No signing identities found.
117
+ `),process.stdout.write(`Run \`cognite keys generate\` to create one (storage: ${N().keysDir}).
118
+ `);return}let n=["KID","SOURCE","EMAIL"],r=t.map(s=>[s.kid,Qt(s.source),s.email??"\u2014"]),i=n.map((s,p)=>Math.max(s.length,...r.map(c=>c[p].length))),a=o(s=>s.map((p,c)=>p.padEnd(i[c])).join(" ").trimEnd(),"fmt");process.stdout.write(`${a(n)}
119
+ `);for(let s of r)process.stdout.write(`${a(s)}
120
+ `)}o(Ai,"handleList");function vn(e,t,n){let r=ue(N().keysDir,`${e}${ee}`);return n.mkdirSync(He(r),{recursive:!0}),n.writeFileSync(r,t),r}o(vn,"writePublicKey");async function ki(e,t,n,r,i,{force:a=!1}={}){let s=r??ue(N().keysDir,`${e}${Ue}`);if(i.mkdirSync(He(s),{recursive:!0}),!a&&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 p=await i.encryptStringAsJwe(t,n);return i.writeFileSync(s,p,{mode:384}),s}o(ki,"writeEncryptedPrivateKey");async function Di(e,t,n=new Date){let{isMacOS:r,existsSync:i,mkdirSync:a,writeFileSync:s,generateSigningKeyPair:p,storeKeyInKeychain:c,promptExpiryMonths:l,promptKid:m,promptEmail:d,promptPassphrase:u,promptConfirmOverwrite:C}=t,g=e.keychain!==!1&&r()&&!e.output,E=e.expires!==void 0?ne(e.expires):await l(),S=Ne(en(n,E)),y=e.kid!==void 0?me(e.kid):await m(),R=ue(N().keysDir,`${y}${ee}`),A=i(R);if(A&&!e.force&&!await C(y)){process.stderr.write(`Aborted.
121
+ `);return}let x=e.email!==void 0?te(e.email,"--email"):await d(),P=g?null:await u();process.stderr.write(`
118
122
  Generating Ed25519 keypair...
119
123
 
120
- `);let{privateKeyPem:p,publicKeyPem:l,kid:m}=await t.generateSigningKeyPair();if(r){await t.storeKeyInKeychain(m,p);let f=pn(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 fi(m,p,c,e.output,t),g=pn(m,l,t);process.stderr.write(`Public key: ${g}
123
- `),process.stderr.write(`Private key: ${f} (JWE, AES-256-GCM, PBKDF2-SHA512 x${Ie.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=Ne(j().keysDir,`${m}${$e}`);t.mkdirSync(Le(d),{recursive:!0}),t.writeFileSync(d,JSON.stringify({email:a}));let u=zt(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(Wt({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(yi,"handleGenerate");var mn=1e3,hi=new Set(["baseUrl","url","project","deployment","source","path","name","displayName","description"]);function wi(e){return Object.fromEntries(Object.entries(e).map(([t,n])=>typeof n=="boolean"?[t,n]:hi.has(t)?[t,n]:[t,"[REDACTED]"]))}o(wi,"sanitize");function Ci(e){let t=[],n=e;for(;n;)n.parent&&t.unshift(n.name()),n=n.parent;return t.join(" ")}o(Ci,"getCommandPath");function dn(e){try{let t=e(process.cwd());return{appExternalId:t.externalId,appVersionTag:t.versionTag}}catch{return{}}}o(dn,"tryLoadAppConfig");function Ke(e){return e.filter(t=>!t.startsWith("-")).join(" ")||"unknown"}o(Ke,"commandFromArgv");function un(e,t,n=C){e.hook("postAction",async(r,i)=>{try{let s={command:Ci(i),options:wi(i.opts()),success:!0,...dn(n)};t.track("Flows.CLI.Command",s),await t.flush(mn)}catch{}})}o(un,"instrument");async function gn(e,t,n=C){try{let r={command:Ke(t),options:{},success:!1,...dn(n)};e.track("Flows.CLI.Command",r),await e.flush(mn)}catch{}}o(gn,"trackFailure");var Ei="ERR_USE_AFTER_CLOSE";function yn(e){return e instanceof Error&&"code"in e&&e.code===Ei}o(yn,"isReadlineClosedError");function Si(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}o(Si,"isPlainObject");function je(e){return e==null||yn(e)?!0:e instanceof Error?!1:!!(typeof e=="object"&&e!==null&&Si(e)&&Object.keys(e).length===0)}o(je,"isPromptCancel");var fn=!1;function hn(){fn||(fn=!0,process.on("uncaughtException",e=>{yn(e)&&(console.error(`
131
- Cancelled.`),process.exit(130)),console.error(e),process.exit(1)}),process.on("unhandledRejection",e=>{je(e)&&(console.error(`
132
- Cancelled.`),process.exit(130)),console.error(e),process.exit(1)}))}o(hn,"installCancelHandler");import{homedir as Ai}from"os";import wn from"mixpanel";var vi="5c4d853e7c3b77b1eb4468d5329b278c",Q="cognite-cli",xi=2e3,Cn={env:process.env,init:wn.init.bind(wn)},Pi={track:o(()=>{},"track"),flush:o(async()=>{},"flush")};function Me(e=process.env){return e.COGNITE_TELEMETRY_DISABLED==="1"||e.DO_NOT_TRACK==="1"}o(Me,"isTelemetryDisabled");function bi(e){return e.COGNITE_TELEMETRY_DEBUG==="1"}o(bi,"isDebug");function En(e={}){let t=e.env??Cn.env,n=e.init??Cn.init,r=e.packageName,i=e.cliVersion,s=bi(t);if(Me(t))return s&&process.stderr.write(`[telemetry] disabled \u2014 noop tracker
133
- `),Pi;let a,c=new Set;function p(){if(a)return a;try{return a=n(vi,{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=xi){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(En,"createTelemetry");var ae=Ai();function Sn(e,t=ae){if(!t||t==="/")return e;let n=e.replaceAll(t,"~"),r=t.replaceAll("\\","/");return r!==t&&(n=n.replaceAll(r,"~")),n}o(Sn,"redactHomedir");var ki=1e3,Di="https://0a118cb02e3be57b1838bcfb5783a2bf@o4508040730968064.ingest.de.sentry.io/4510719268290640",Ii={captureError:o(async()=>{},"captureError"),flush:o(async()=>{},"flush")};function Ti(e){return e.packageName&&e.cliVersion?`${e.packageName}@${e.cliVersion}`:e.cliVersion??"unknown"}o(Ti,"buildRelease");var $i="192.0.2.0";function Fi(e){let t={...e.user,email:void 0,username:void 0,ip_address:$i,id:void 0},n=e.exception?.values?.map(r=>({...r,value:r.value!==void 0?Sn(r.value):r.value}));return{...e,message:e.message!==void 0?Sn(e.message):e.message,user:t,server_name:void 0,...n!==void 0&&{exception:{...e.exception,values:n}}}}o(Fi,"scrubPii");function vn(e={}){let t=e.env??process.env;if(Me(t))return Ii;let n=Ti(e),r="production",i=null,s=null;function a(p){let l=ae&&ae!=="/"?[p.rewriteFramesIntegration({root:ae})]:[];return{dsn:Di,release:n,environment:r,defaultIntegrations:!1,integrations:l,sendDefaultPii:!1,enableLogs:!1,initialScope:{tags:{component:"cli",applicationId:Q},contexts:{cli:{applicationId:Q,node:process.version,platform:process.platform}}},beforeSend:Fi}}o(a,"buildInitOptions");async function c(){return i||(s||(s=(async()=>{try{let p=e.sdk??await import("@sentry/node");return p.init(a(p)),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=ki){try{if(!i)return;await i.flush(p)}catch{}}}}o(vn,"createErrorReporter");import{mkdirSync as Oi,readFileSync as Ri,writeFileSync as _i}from"fs";import{homedir as Ui}from"os";import{resolve as ce}from"path";import{debuglog as Li}from"util";import{lt as Ni,parse as xn}from"semver";var Ki="https://registry.npmjs.org/@cognite/cli/latest",ji=1500,Pn="upgrade-check.json",bn=ce(process.env.XDG_CACHE_HOME||ce(Ui(),".cache"),"@cognite","cli"),Ve=Li("cognite-flows");function Mi(e,t){return!e||!t||!xn(e)||!xn(t)?!1:Ni(e,t)}o(Mi,"isOutdated");async function Vi({timeout:e=ji,registryUrl:t=Ki,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 Ve("fetchLatestVersion failed (%s): %O",t,r),null}}o(Vi,"fetchLatestVersion");function Hi(e=bn,t=864e5){try{let n=Ri(ce(e,Pn),"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 Ve("readUpgradeCheckCache failed (%s): %O",e,n),null}}o(Hi,"readUpgradeCheckCache");function Gi(e,t){try{Oi(e,{recursive:!0});let n={latest:t,fetchedAt:Date.now()};_i(ce(e,Pn),JSON.stringify(n))}catch(n){Ve("writeUpgradeCheckCache failed (%s): %O",e,n)}}o(Gi,"writeUpgradeCheckCache");async function Bi({cacheDir:e=bn,...t}={}){let n=await Vi(t);n&&Gi(e,n)}o(Bi,"startBackgroundUpgradeCheck");function An(e,{onOutdated:t,cacheDir:n,...r}={}){let i=Hi(n);if(i){Mi(e,i.latest)&&t?.(e,i.latest);return}Bi({cacheDir:n,...r})}o(An,"preActionUpgradeCheck");import{default as jl,chalkStderr as kn}from"chalk";function Dn(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 kn.bold.yellow(a)}o(Dn,"formatUpgradeWarning");function Xi(e){return e instanceof Error&&"code"in e&&typeof e.code=="string"&&e.code==="DEP0040"}o(Xi,"isDep0040Warning");var Ge=process,zi=Ge.emit.bind(Ge);Ge.emit=function(e,...t){return e==="warning"&&Xi(t[0])?!1:zi(e,...t)};hn();var G=new Ji;G.name("cognite").description("Build and deploy React apps to Cognite Data Fusion").version("1.2.0").showHelpAfterError().configureOutput({writeOut:o(e=>Yi(1,e),"writeOut")});G.hook("preAction",()=>{An("1.2.0",{onOutdated:o((e,t)=>{console.warn(`
137
- ${Dn(e,t)}
138
- `)},"onOutdated")})});_t(G);ln(G);var Tn=En({packageName:"@cognite/cli",cliVersion:"1.2.0"}),In=vn({packageName:"@cognite/cli",cliVersion:"1.2.0"});un(G,Tn);var He=process.argv.slice(2);G.parseAsync(He,{from:"user"}).catch(async e=>{await gn(Tn,He),je(e)&&(console.error(`
139
- Cancelled.`),process.exit(130)),await In.captureError(e,{command:Ke(He)}),await In.flush(),console.error(e instanceof Error?`\u274C ${e.message}`:e),process.exit(1)});
124
+ `);let{privateKeyPem:f,publicKeyPem:j}=await p(y);if(g){await c(y,f);let X=vn(y,j,t);process.stderr.write(`Public key: ${X}
125
+ `),process.stderr.write(`Private key: macOS Keychain (service: cognite-dune, account: ${y})
126
+ `)}else{if(P===null)throw new Error("passphrase is required when not using Keychain");let X=await ki(y,f,P,e.output,t,{force:A}),We=vn(y,j,t);process.stderr.write(`Public key: ${We}
127
+ `),process.stderr.write(`Private key: ${X} (JWE, AES-256-GCM, PBKDF2-SHA512 x${_e.toLocaleString()})
128
+ `),r()||process.stderr.write(` (macOS Keychain integration is the default on darwin; on this OS we use the file.)
129
+ `)}let oe=ue(N().keysDir,`${y}${Le}`);a(He(oe),{recursive:!0}),s(oe,JSON.stringify({email:x}));let K=nn(process.stderr);process.stderr.write(`
130
+ Signing identity (kid): ${K.green(y)}
131
+ `),process.stderr.write(`Expires: ${S} (${E} month${E===1?"":"s"} from today)
132
+ `),process.stderr.write(rn({kid:y,publicKeyPem:j,email:x,expires:S},K,n)),process.stderr.write(`
133
+ ${K.bold("Next:")} open a PR against the ${K.magenta("infrastructure")} repo with that block, then \`${K.cyan(`cognite sign -s ${y}`)}\`
134
+ `)}o(Di,"handleGenerate");var Sn=1e3,Ii=new Set(["baseUrl","url","project","deployment","source","path","name","displayName","description"]);function Ti(e){return Object.fromEntries(Object.entries(e).map(([t,n])=>typeof n=="boolean"?[t,n]:Ii.has(t)?[t,n]:[t,"[REDACTED]"]))}o(Ti,"sanitize");function $i(e){let t=[],n=e;for(;n;)n.parent&&t.unshift(n.name()),n=n.parent;return t.join(" ")}o($i,"getCommandPath");function xn(e){try{let t=e(process.cwd());return{appExternalId:t.externalId,appVersionTag:t.versionTag}}catch{return{}}}o(xn,"tryLoadAppConfig");function Ge(e){return e.filter(t=>!t.startsWith("-")).join(" ")||"unknown"}o(Ge,"commandFromArgv");function Pn(e,t,n=w){e.hook("postAction",async(r,i)=>{try{let a={command:$i(i),options:Ti(i.opts()),success:!0,...xn(n)};t.track("Flows.CLI.Command",a),await t.flush(Sn)}catch{}})}o(Pn,"instrument");async function bn(e,t,n=w){try{let r={command:Ge(t),options:{},success:!1,...xn(n)};e.track("Flows.CLI.Command",r),await e.flush(Sn)}catch{}}o(bn,"trackFailure");var Fi="ERR_USE_AFTER_CLOSE";function kn(e){return e instanceof Error&&"code"in e&&e.code===Fi}o(kn,"isReadlineClosedError");function Oi(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}o(Oi,"isPlainObject");function Be(e){return e==null||kn(e)?!0:e instanceof Error?!1:!!(typeof e=="object"&&e!==null&&Oi(e)&&Object.keys(e).length===0)}o(Be,"isPromptCancel");var An=!1;function Dn(){An||(An=!0,process.on("uncaughtException",e=>{kn(e)&&(console.error(`
135
+ Cancelled.`),process.exit(130)),console.error(e),process.exit(1)}),process.on("unhandledRejection",e=>{Be(e)&&(console.error(`
136
+ Cancelled.`),process.exit(130)),console.error(e),process.exit(1)}))}o(Dn,"installCancelHandler");import{homedir as Ni}from"os";import In from"mixpanel";var Ri="5c4d853e7c3b77b1eb4468d5329b278c",re="cognite-cli",_i=2e3,Tn={env:process.env,init:In.init.bind(In)},Ui={track:o(()=>{},"track"),flush:o(async()=>{},"flush")};function Ye(e=process.env){return e.COGNITE_TELEMETRY_DISABLED==="1"||e.DO_NOT_TRACK==="1"}o(Ye,"isTelemetryDisabled");function Li(e){return e.COGNITE_TELEMETRY_DEBUG==="1"}o(Li,"isDebug");function $n(e={}){let t=e.env??Tn.env,n=e.init??Tn.init,r=e.packageName,i=e.cliVersion,a=Li(t);if(Ye(t))return a&&process.stderr.write(`[telemetry] disabled \u2014 noop tracker
137
+ `),Ui;let s,p=new Set;function c(){if(s)return s;try{return s=n(Ri,{geolocate:!1,keepAlive:!1}),s}catch{return}}return o(c,"getClient"),{track(l,m={}){let d=c();if(!d)return;let u={...m,applicationId:re,...r&&{packageName:r},...i&&{cliVersion:i},nodeVersion:process.version,platform:process.platform};a&&process.stderr.write(`[telemetry] track ${l} ${JSON.stringify(u)}
138
+ `);let C=o(()=>{},"finish"),g=new Promise(E=>{C=E});p.add(g);try{d.track(l,u,C)}catch{C()}g.finally(()=>p.delete(g))},async flush(l=_i){if(p.size===0)return;let m,d=new Promise(u=>{m=setTimeout(u,l),m.unref?.()});try{await Promise.race([Promise.allSettled([...p]),d])}finally{m&&clearTimeout(m)}a&&process.stderr.write(`[telemetry] flush done (${p.size} still pending)
139
+ `)}}}o($n,"createTelemetry");var ge=Ni();function Fn(e,t=ge){if(!t||t==="/")return e;let n=e.replaceAll(t,"~"),r=t.replaceAll("\\","/");return r!==t&&(n=n.replaceAll(r,"~")),n}o(Fn,"redactHomedir");var ji=1e3,Ki="https://0a118cb02e3be57b1838bcfb5783a2bf@o4508040730968064.ingest.de.sentry.io/4510719268290640",Mi={captureError:o(async()=>{},"captureError"),flush:o(async()=>{},"flush")};function Vi(e){return e.packageName&&e.cliVersion?`${e.packageName}@${e.cliVersion}`:e.cliVersion??"unknown"}o(Vi,"buildRelease");var Hi="192.0.2.0";function Gi(e){let t={...e.user,email:void 0,username:void 0,ip_address:Hi,id:void 0},n=e.exception?.values?.map(r=>({...r,value:r.value!==void 0?Fn(r.value):r.value}));return{...e,message:e.message!==void 0?Fn(e.message):e.message,user:t,server_name:void 0,...n!==void 0&&{exception:{...e.exception,values:n}}}}o(Gi,"scrubPii");function On(e={}){let t=e.env??process.env;if(Ye(t))return Mi;let n=Vi(e),r="production",i=null,a=null;function s(c){let l=ge&&ge!=="/"?[c.rewriteFramesIntegration({root:ge})]:[];return{dsn:Ki,release:n,environment:r,defaultIntegrations:!1,integrations:l,sendDefaultPii:!1,enableLogs:!1,initialScope:{tags:{component:"cli",applicationId:re},contexts:{cli:{applicationId:re,node:process.version,platform:process.platform}}},beforeSend:Gi}}o(s,"buildInitOptions");async function p(){return i||(a||(a=(async()=>{try{let c=e.sdk??await import("@sentry/node");return c.init(s(c)),i=c,c}catch{return null}})()),a)}return o(p,"ensureSdk"),{async captureError(c,l){try{let m=await p();if(!m)return;let d={level:"fatal"};l?.command&&(d.tags={command:l.command},d.contexts={cli:{applicationId:re,node:process.version,platform:process.platform,command:l.command}}),m.captureException(c,d)}catch{}},async flush(c=ji){try{if(!i)return;await i.flush(c)}catch{}}}}o(On,"createErrorReporter");import{mkdirSync as Bi,readFileSync as Yi,writeFileSync as Ji}from"fs";import{homedir as Xi}from"os";import{resolve as fe}from"path";import{debuglog as zi}from"util";import{lt as Wi,parse as Rn}from"semver";var qi="https://registry.npmjs.org/@cognite/cli/latest",Qi=1500,_n="upgrade-check.json",Un=fe(process.env.XDG_CACHE_HOME||fe(Xi(),".cache"),"@cognite","cli"),Je=zi("cognite-flows");function Zi(e,t){return!e||!t||!Rn(e)||!Rn(t)?!1:Wi(e,t)}o(Zi,"isOutdated");async function es({timeout:e=Qi,registryUrl:t=qi,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(es,"fetchLatestVersion");function ts(e=Un,t=864e5){try{let n=Yi(fe(e,_n),"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(ts,"readUpgradeCheckCache");function ns(e,t){try{Bi(e,{recursive:!0});let n={latest:t,fetchedAt:Date.now()};Ji(fe(e,_n),JSON.stringify(n))}catch(n){Je("writeUpgradeCheckCache failed (%s): %O",e,n)}}o(ns,"writeUpgradeCheckCache");async function rs({cacheDir:e=Un,...t}={}){let n=await es(t);n&&ns(e,n)}o(rs,"startBackgroundUpgradeCheck");function Ln(e,{onOutdated:t,cacheDir:n,...r}={}){let i=ts(n);if(i){Zi(e,i.latest)&&t?.(e,i.latest);return}rs({cacheDir:n,...r})}o(Ln,"preActionUpgradeCheck");import{default as om,chalkStderr as Nn}from"chalk";function jn(e,t){let n=[`\u26A0 Update available: ${e} -> ${t}`," Run npx @cognite/cli@latest"],r=Math.max(...n.map(p=>[...p].length))+2,i="\u2500".repeat(r),a=o(p=>`\u2502 ${p}${" ".repeat(r-1-[...p].length)}\u2502`,"pad"),s=[`\u250C${i}\u2510`,...n.map(a),`\u2514${i}\u2518`].join(`
140
+ `);return Nn.bold.yellow(s)}o(jn,"formatUpgradeWarning");function ss(e){return e instanceof Error&&"code"in e&&typeof e.code=="string"&&e.code==="DEP0040"}o(ss,"isDep0040Warning");var ze=process,as=ze.emit.bind(ze);ze.emit=function(e,...t){return e==="warning"&&ss(t[0])?!1:as(e,...t)};Dn();var J=new is;J.name("cognite").description("Build and deploy React apps to Cognite Data Fusion").version("1.3.0").showHelpAfterError().configureOutput({writeOut:o(e=>os(1,e),"writeOut")});J.hook("preAction",()=>{Ln("1.3.0",{onOutdated:o((e,t)=>{console.warn(`
141
+ ${jn(e,t)}
142
+ `)},"onOutdated")})});Ht(J);En(J);var Mn=$n({packageName:"@cognite/cli",cliVersion:"1.3.0"}),Kn=On({packageName:"@cognite/cli",cliVersion:"1.3.0"});Pn(J,Mn);var Xe=process.argv.slice(2);J.parseAsync(Xe,{from:"user"}).catch(async e=>{await bn(Mn,Xe),Be(e)&&(console.error(`
143
+ Cancelled.`),process.exit(130)),await Kn.captureError(e,{command:Ge(Xe)}),await Kn.flush(),console.error(e instanceof Error?`\u274C ${e.message}`:e),process.exit(1)});
@@ -60,6 +60,9 @@ declare class AppHostingClient {
60
60
  publishVersion(appExternalId: string, version: string): Promise<void>;
61
61
  /** Publish the version and immediately set it as the ACTIVE alias. */
62
62
  publishAndActivate(appExternalId: string, version: string): Promise<void>;
63
+ getActiveVersion(appExternalId: string): Promise<AppVersion | null>;
64
+ /** Remove the ACTIVE alias from a version, taking it out of service without changing its lifecycle state. */
65
+ deactivateVersion(appExternalId: string, version: string): Promise<void>;
63
66
  /**
64
67
  * Set the ACTIVE alias on a version. Returns the version that was
65
68
  * previously active (if any) so callers can surface "Superseded X"
@@ -1 +1 @@
1
- import{a,b,c,d,e}from"../chunk-PT2DTNGD.js";export{a as AppHostingClient,b as ApplicationPackager,e as deploy,d as getSdk,c as getToken};
1
+ import{a,b,c,d,e}from"../chunk-QOJVLP7E.js";export{a as AppHostingClient,b as ApplicationPackager,e as deploy,d as getSdk,c as getToken};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as o,b as r,c as e,d as f,e as m}from"./chunk-PT2DTNGD.js";export{o as AppHostingClient,r as ApplicationPackager,m as deploy,f as getSdk,e as getToken};
1
+ import{a as o,b as r,c as e,d as f,e as m}from"./chunk-QOJVLP7E.js";export{o as AppHostingClient,r as ApplicationPackager,m as deploy,f as getSdk,e as getToken};
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@cognite/cli",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "CLI for Cognite Data Fusion",
5
- "license": "Apache-2.0",
5
+ "license": "SEE LICENSE IN LICENSE.md",
6
6
  "author": "Cognite",
7
7
  "repository": {
8
8
  "type": "git",
@@ -44,7 +44,7 @@
44
44
  "refresh-spec-kit": "bash scripts/refresh-spec-kit.sh"
45
45
  },
46
46
  "dependencies": {
47
- "@cognite/app-sdk": "^0.4.0",
47
+ "@cognite/app-sdk": "^0.5.1",
48
48
  "@cognite/sdk": "^10.10.0",
49
49
  "@sentry/node": "^10.51.0",
50
50
  "@zip.js/zip.js": "^2.7.0",