@cognite/cli 1.3.1 → 1.3.2-alpha.53
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/_templates/app/new/root/.npmrc.ejs.t +0 -1
- package/_templates/app/new/root/AGENTS.md.ejs.t +60 -12
- package/_templates/app/new/root/SPEC.md.ejs.t +17 -15
- package/_templates/app/new/root/package.json.ejs.t +3 -0
- package/dist/chunk-6C2Y3XBZ.js +9 -0
- package/dist/chunk-EI7MMDWY.js +1 -0
- package/dist/chunk-EILVJ2ZW.js +1 -0
- package/dist/chunk-VTE66IK5.js +8 -0
- package/dist/cli/cli.js +178 -61
- package/dist/deploy/index.d.ts +26 -1
- package/dist/deploy/index.js +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -1
- package/dist/sdk-runtime/index.d.ts +199 -0
- package/dist/sdk-runtime/index.js +1 -0
- package/dist/{skills-GQ5TZKCM.js → skills-SV7BPHAZ.js} +1 -1
- package/package.json +14 -3
- package/dist/chunk-A5ASLC6T.js +0 -7
- package/dist/chunk-QOJVLP7E.js +0 -9
package/dist/deploy/index.d.ts
CHANGED
|
@@ -56,6 +56,13 @@ declare class AppHostingClient {
|
|
|
56
56
|
* success so the call is safe to repeat.
|
|
57
57
|
*/
|
|
58
58
|
ensureApp(externalId: string, name: string, description: string): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Submit verified compact-JWS signatures for a version uploaded earlier.
|
|
61
|
+
* No-op when `items` is empty so callers can wire it unconditionally.
|
|
62
|
+
* The backend accepts and stores well-formed tokens; tier-policy
|
|
63
|
+
* verification happens on the subsequent publish step.
|
|
64
|
+
*/
|
|
65
|
+
submitSignatures(appExternalId: string, version: string, items: string[]): Promise<void>;
|
|
59
66
|
/** Transition a version from DRAFT to PUBLISHED. */
|
|
60
67
|
publishVersion(appExternalId: string, version: string): Promise<void>;
|
|
61
68
|
/** Publish the version and immediately set it as the ACTIVE alias. */
|
|
@@ -111,4 +118,22 @@ declare function getSdk<C extends Authenticatable>(deployment: Deployment, folde
|
|
|
111
118
|
*/
|
|
112
119
|
declare const getToken: (deployment: Deployment, env?: NodeJS.ProcessEnv) => Promise<string>;
|
|
113
120
|
|
|
114
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Sibling-file discovery for bundle signatures written by `cognite sign`.
|
|
123
|
+
*
|
|
124
|
+
* <bundle>.dev.sig — developer signature
|
|
125
|
+
* <bundle>.cert.sig — certifier counter-signature (`--as-certifier`)
|
|
126
|
+
*
|
|
127
|
+
* Tokens are passed verbatim to the App Hosting `/signatures` endpoint; the
|
|
128
|
+
* backend verifies them against its key registry and tier policy.
|
|
129
|
+
*
|
|
130
|
+
* Collaborators are injected via `deps` so tests can stub fs without `vi.mock`.
|
|
131
|
+
*/
|
|
132
|
+
declare const SIGNATURE_SUFFIXES: readonly [".dev.sig", ".cert.sig"];
|
|
133
|
+
type DiscoverSignaturesDeps = {
|
|
134
|
+
existsSync?: (path: string) => boolean;
|
|
135
|
+
readFileSync?: (path: string, encoding: 'utf8') => string;
|
|
136
|
+
};
|
|
137
|
+
declare function discoverSignatures(bundlePath: string, deps?: DiscoverSignaturesDeps): string[];
|
|
138
|
+
|
|
139
|
+
export { type App, AppHostingClient, ApplicationPackager, type Deployment, SIGNATURE_SUFFIXES, deploy, discoverSignatures, getSdk, getToken };
|
package/dist/deploy/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e}from"../chunk-
|
|
1
|
+
import{a,b,c,d,e,f,g}from"../chunk-6C2Y3XBZ.js";import"../chunk-EI7MMDWY.js";export{a as AppHostingClient,b as ApplicationPackager,f as SIGNATURE_SUFFIXES,e as deploy,g as discoverSignatures,d as getSdk,c as getToken};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export { App, AppHostingClient, ApplicationPackager, Deployment, deploy, getSdk, getToken } from './deploy/index.js';
|
|
1
|
+
export { App, AppHostingClient, ApplicationPackager, Deployment, SIGNATURE_SUFFIXES, deploy, discoverSignatures, getSdk, getToken } from './deploy/index.js';
|
|
2
|
+
export { DuneRuntime, createDuneRuntime, createDuneRuntimeFromViews } from './sdk-runtime/index.js';
|
|
2
3
|
import '@cognite/sdk';
|
|
4
|
+
import 'graphql';
|
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-
|
|
1
|
+
import{a as o,b as r,c as e,d as f,e as m,f as p,g as t}from"./chunk-6C2Y3XBZ.js";import{a as x,b as a}from"./chunk-EILVJ2ZW.js";import"./chunk-EI7MMDWY.js";export{o as AppHostingClient,r as ApplicationPackager,p as SIGNATURE_SUFFIXES,x as createDuneRuntime,a as createDuneRuntimeFromViews,m as deploy,t as discoverSignatures,f as getSdk,e as getToken};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { ViewReference, FilterDefinition, SearchSort, AggregationDefinition, AggregatedResultItem, InstancesAPI, CogniteClient, ViewDefinition } from '@cognite/sdk';
|
|
2
|
+
import { DocumentNode, GraphQLSchema } from 'graphql';
|
|
3
|
+
|
|
4
|
+
interface GenerateSdkConfig {
|
|
5
|
+
name: string;
|
|
6
|
+
space: string;
|
|
7
|
+
dataModelExternalId: string;
|
|
8
|
+
dataModelVersion: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface SharedViewId {
|
|
12
|
+
space: string;
|
|
13
|
+
externalId: string;
|
|
14
|
+
version: string;
|
|
15
|
+
}
|
|
16
|
+
type PropertyDescriptor = {
|
|
17
|
+
kind: 'scalar';
|
|
18
|
+
isList?: boolean;
|
|
19
|
+
graphqlType?: string;
|
|
20
|
+
} | {
|
|
21
|
+
kind: 'enum';
|
|
22
|
+
values: string[];
|
|
23
|
+
valueNames: Record<string, string>;
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'directRelation';
|
|
26
|
+
targetView: SharedViewId;
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'reverseDirect';
|
|
29
|
+
sourceView: SharedViewId;
|
|
30
|
+
throughProperty: string;
|
|
31
|
+
} | {
|
|
32
|
+
kind: 'reverseList';
|
|
33
|
+
sourceView: SharedViewId;
|
|
34
|
+
throughProperty: string;
|
|
35
|
+
} | {
|
|
36
|
+
kind: 'edge';
|
|
37
|
+
targetView: SharedViewId;
|
|
38
|
+
direction: 'outwards' | 'inwards';
|
|
39
|
+
};
|
|
40
|
+
interface SchemaView {
|
|
41
|
+
view: SharedViewId;
|
|
42
|
+
properties: Map<string, PropertyDescriptor>;
|
|
43
|
+
}
|
|
44
|
+
interface SchemaKnowledge {
|
|
45
|
+
view(ref: SharedViewId): SchemaView;
|
|
46
|
+
property(ref: SharedViewId, prop: string): PropertyDescriptor | undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Matches the Requester type emitted by @graphql-codegen/typescript-generic-sdk,
|
|
51
|
+
* so the return of createDuneRequester can be passed directly to getSdk().
|
|
52
|
+
*/
|
|
53
|
+
type DuneRequester = <TData, TVariables>(doc: DocumentNode, variables?: TVariables) => Promise<TData>;
|
|
54
|
+
|
|
55
|
+
interface PropertyRef {
|
|
56
|
+
view: ViewReference;
|
|
57
|
+
property: string;
|
|
58
|
+
}
|
|
59
|
+
interface ConnectionSelection {
|
|
60
|
+
limit?: number;
|
|
61
|
+
select: SelectionTree;
|
|
62
|
+
}
|
|
63
|
+
interface SelectionTree {
|
|
64
|
+
scalars: string[];
|
|
65
|
+
connections: Map<string, ConnectionSelection>;
|
|
66
|
+
}
|
|
67
|
+
interface SortClause {
|
|
68
|
+
property: PropertyRef;
|
|
69
|
+
direction: 'ascending' | 'descending';
|
|
70
|
+
/** When true, nulls sort before non-nulls. Defaults to false. */
|
|
71
|
+
nullsFirst?: boolean;
|
|
72
|
+
}
|
|
73
|
+
/** Pre-translated DMS logical filter (output of translateFilter in resolver layer). */
|
|
74
|
+
type LogicalFilter = FilterDefinition;
|
|
75
|
+
interface QueryInput {
|
|
76
|
+
view: ViewReference;
|
|
77
|
+
filter?: LogicalFilter;
|
|
78
|
+
sort?: SortClause[];
|
|
79
|
+
select: SelectionTree;
|
|
80
|
+
/** Page size. Defaults to INITIAL_BATCH_LIMIT if omitted. */
|
|
81
|
+
limit?: number;
|
|
82
|
+
/** Opaque cursor from a previous ListResult.pageInfo.endCursor. */
|
|
83
|
+
cursor?: string;
|
|
84
|
+
}
|
|
85
|
+
interface ListResult<T = Record<string, unknown>> {
|
|
86
|
+
items: T[];
|
|
87
|
+
pageInfo: {
|
|
88
|
+
endCursor: string | null;
|
|
89
|
+
hasNextPage: boolean;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
interface SearchInput {
|
|
94
|
+
view: ViewReference;
|
|
95
|
+
/** Full-text search term. */
|
|
96
|
+
query?: string;
|
|
97
|
+
filter?: LogicalFilter;
|
|
98
|
+
sort?: SearchSort[];
|
|
99
|
+
select: SelectionTree;
|
|
100
|
+
/** Max items to return. Defaults to searchLimit config. */
|
|
101
|
+
limit?: number;
|
|
102
|
+
/** Restrict search to specific property names within the view. */
|
|
103
|
+
properties?: string[];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
interface AggregateInput {
|
|
107
|
+
view: ViewReference;
|
|
108
|
+
filter?: LogicalFilter;
|
|
109
|
+
aggregates: AggregationDefinition[];
|
|
110
|
+
groupBy?: string[];
|
|
111
|
+
/** Optional full-text query to scope which instances are aggregated. */
|
|
112
|
+
query?: string;
|
|
113
|
+
}
|
|
114
|
+
interface AggregateOutput {
|
|
115
|
+
items: AggregatedResultItem[];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
type DmsClient = Pick<InstancesAPI, 'query' | 'search' | 'aggregate' | 'retrieve' | 'upsert' | 'delete' | 'sync' | 'inspect'>;
|
|
119
|
+
interface PlannerConfig {
|
|
120
|
+
initialBatchLimit: number;
|
|
121
|
+
maxBatchLimit: number;
|
|
122
|
+
searchLimit: number;
|
|
123
|
+
inFilterChunkSize: number;
|
|
124
|
+
previewLimit: number;
|
|
125
|
+
nestedDetailLimit: number;
|
|
126
|
+
enableRemoveNotConnected: boolean;
|
|
127
|
+
max408Retries: number;
|
|
128
|
+
max429Retries: number;
|
|
129
|
+
retryBaseDelayMs: number;
|
|
130
|
+
maxConcurrentRequests: number;
|
|
131
|
+
/** Maximum SelectionTree nesting depth. Throws PlannerValidationError if exceeded. */
|
|
132
|
+
maxNestingDepth: number;
|
|
133
|
+
/** Hard ceiling for listAll without an explicit maxTotal. Throws rather than silently truncating. */
|
|
134
|
+
maxTotalItems: number;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
declare class QueryRunner {
|
|
138
|
+
private readonly dms;
|
|
139
|
+
private readonly schema;
|
|
140
|
+
private readonly config;
|
|
141
|
+
private readonly executor;
|
|
142
|
+
get schemaKnowledge(): SchemaKnowledge | undefined;
|
|
143
|
+
constructor(dms: DmsClient, schema?: SchemaKnowledge, config?: Partial<PlannerConfig>);
|
|
144
|
+
query<T = Record<string, unknown>>(input: QueryInput): Promise<ListResult<T>>;
|
|
145
|
+
/**
|
|
146
|
+
* Collects all pages until exhaustion. `input.limit` is the page size.
|
|
147
|
+
* `maxTotal` sets an explicit ceiling — without it, throws at `config.maxTotalItems`
|
|
148
|
+
* to prevent unbounded fetches.
|
|
149
|
+
*/
|
|
150
|
+
queryAll<T = Record<string, unknown>>(input: Omit<QueryInput, 'cursor'>, maxTotal?: number): Promise<T[]>;
|
|
151
|
+
/**
|
|
152
|
+
* Full-text or filter-based search returning a single (non-paginated) result set.
|
|
153
|
+
* Use for top-level discovery; DMS search has eventual consistency — do not use
|
|
154
|
+
* for writes-then-reads or where strong consistency is required.
|
|
155
|
+
*/
|
|
156
|
+
search<T = Record<string, unknown>>(input: SearchInput): Promise<ListResult<T>>;
|
|
157
|
+
/**
|
|
158
|
+
* Fetches specific nodes by space+externalId. Returns an empty array when ids is empty.
|
|
159
|
+
* Extracts view-scoped properties before returning, matching the shape of list results.
|
|
160
|
+
*/
|
|
161
|
+
getByIds<T = Record<string, unknown>>(ids: Array<{
|
|
162
|
+
space: string;
|
|
163
|
+
externalId: string;
|
|
164
|
+
}>, view: ViewReference): Promise<T[]>;
|
|
165
|
+
/**
|
|
166
|
+
* Returns the total count of instances matching the filter.
|
|
167
|
+
* Wraps the filter with hasData so only instances with data in the view are counted.
|
|
168
|
+
*/
|
|
169
|
+
count(input: {
|
|
170
|
+
view: ViewReference;
|
|
171
|
+
filter?: LogicalFilter;
|
|
172
|
+
}): Promise<number>;
|
|
173
|
+
aggregate(input: AggregateInput): Promise<AggregateOutput>;
|
|
174
|
+
/**
|
|
175
|
+
* Async generator — yields one ListResult<T> per page.
|
|
176
|
+
* Lets callers stream results or stop early without fetching remaining pages.
|
|
177
|
+
*/
|
|
178
|
+
queryPages<T = Record<string, unknown>>(input: Omit<QueryInput, 'cursor'>): AsyncGenerator<ListResult<T>>;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
interface DuneRuntime {
|
|
182
|
+
schema: GraphQLSchema;
|
|
183
|
+
rootValue: Record<string, unknown>;
|
|
184
|
+
runner: QueryRunner;
|
|
185
|
+
/** Pass directly to the generated getSdk() function. */
|
|
186
|
+
requester: DuneRequester;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Builds the full runtime from a data model config. Fetches views from CDF,
|
|
190
|
+
* builds the GraphQL schema, wires resolvers, and returns a ready requester.
|
|
191
|
+
*/
|
|
192
|
+
declare function createDuneRuntime(config: GenerateSdkConfig, client: CogniteClient): Promise<DuneRuntime>;
|
|
193
|
+
/**
|
|
194
|
+
* Builds the runtime directly from an array of ViewDefinition objects — skips the
|
|
195
|
+
* data model lookup. Useful when you already have views from sdk.views.list().
|
|
196
|
+
*/
|
|
197
|
+
declare function createDuneRuntimeFromViews(views: ViewDefinition[], client: CogniteClient): DuneRuntime;
|
|
198
|
+
|
|
199
|
+
export { type DuneRuntime, createDuneRuntime, createDuneRuntimeFromViews };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b}from"../chunk-EILVJ2ZW.js";import"../chunk-EI7MMDWY.js";export{a as createDuneRuntime,b as createDuneRuntimeFromViews};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as a,c as b,d as c,e as d}from"./chunk-
|
|
1
|
+
import{b as a,c as b,d as c,e as d}from"./chunk-VTE66IK5.js";export{c as buildPullArgs,a as execSkillsCli,b as pullAllArgs,d as registerSkillsCommand};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cognite/cli",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2-alpha.53",
|
|
4
4
|
"description": "CLI for Cognite Data Fusion",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"author": "Cognite",
|
|
@@ -22,6 +22,11 @@
|
|
|
22
22
|
"types": "./dist/deploy/index.d.ts",
|
|
23
23
|
"import": "./dist/deploy/index.js",
|
|
24
24
|
"default": "./dist/deploy/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./sdk-runtime": {
|
|
27
|
+
"types": "./dist/sdk-runtime/index.d.ts",
|
|
28
|
+
"import": "./dist/sdk-runtime/index.js",
|
|
29
|
+
"default": "./dist/sdk-runtime/index.js"
|
|
25
30
|
}
|
|
26
31
|
},
|
|
27
32
|
"bin": {
|
|
@@ -46,13 +51,19 @@
|
|
|
46
51
|
"dependencies": {
|
|
47
52
|
"@cognite/app-sdk": "^0.5.1",
|
|
48
53
|
"@cognite/sdk": "^10.10.0",
|
|
54
|
+
"@graphql-codegen/cli": "^7.0.0",
|
|
55
|
+
"@graphql-codegen/typescript": "^6.0.1",
|
|
56
|
+
"@graphql-codegen/typescript-generic-sdk": "^5.0.1",
|
|
57
|
+
"@graphql-codegen/typescript-operations": "^6.0.2",
|
|
49
58
|
"@sentry/node": "^10.51.0",
|
|
50
59
|
"@zip.js/zip.js": "^2.7.0",
|
|
51
60
|
"chalk": "^5.6.2",
|
|
61
|
+
"clipboardy": "5.3.1",
|
|
52
62
|
"commander": "^14.0.3",
|
|
53
63
|
"dotenv": "^17.4.2",
|
|
54
64
|
"enquirer": "^2.4.1",
|
|
55
65
|
"execa": "^5.1.1",
|
|
66
|
+
"graphql": "^16.13.2",
|
|
56
67
|
"hygen": "^6.2.11",
|
|
57
68
|
"jose": "^6.2.2",
|
|
58
69
|
"mixpanel": "^0.21.0",
|
|
@@ -75,14 +86,14 @@
|
|
|
75
86
|
}
|
|
76
87
|
},
|
|
77
88
|
"devDependencies": {
|
|
78
|
-
"@types/ejs": "^3.1.5",
|
|
79
|
-
"ejs": "^3.1.10",
|
|
80
89
|
"@mswjs/http-middleware": "^0.10.3",
|
|
90
|
+
"@types/ejs": "^3.1.5",
|
|
81
91
|
"@types/express": "^5.0.6",
|
|
82
92
|
"@types/node": "^24.10.1",
|
|
83
93
|
"@types/react": "^19.2.6",
|
|
84
94
|
"@types/react-dom": "^19.2.3",
|
|
85
95
|
"@types/semver": "^7.7.0",
|
|
96
|
+
"ejs": "^3.1.10",
|
|
86
97
|
"express": "^5.2.1",
|
|
87
98
|
"msw": "^2.13.6",
|
|
88
99
|
"react": "^19.2.6",
|
package/dist/chunk-A5ASLC6T.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
var r=Object.defineProperty;var s=(l,i)=>r(l,"name",{value:i,configurable:!0});import{execFileSync as c}from"child_process";import{createRequire as a}from"module";import{InvalidArgumentError as p}from"commander";var e="cognitedata/builder-skills",o=["claude-code","cursor"],t=o.flatMap(l=>["-a",l]),u=a(import.meta.url).resolve("skills/bin/cli.mjs");function n(l,i={}){c(process.execPath,[u,...l],{stdio:"inherit",cwd:process.cwd(),...i})}s(n,"execSkillsCli");function S(){return["add",e,...t,"--skill","*","-y"]}s(S,"pullAllArgs");function d(l){if(!/^[\w.-]+\/[\w.-]+$/.test(l))throw new p("Expected owner/repo format (e.g., cognitedata/builder-skills)");return l}s(d,"validateSource");function m(l){let i=["add",l.source,...t];return l.skill?i.push("--skill",l.skill):l.interactive||i.push("--skill","*","-y"),l.global&&i.push("--global"),i}s(m,"buildPullArgs");function k(l){console.log(`\u{1F504} Pulling skills from ${l.source}...`),n(m(l)),console.log(`
|
|
2
|
-
\u2705 Skills pulled successfully`)}s(k,"handlePull");function P(l){let i=l.command("skills").summary("Manage AI agent skills for your app").description(`Manage AI agent skills for your app.
|
|
3
|
-
Supports: ${o.join(", ")}`).addHelpText("after",`
|
|
4
|
-
Examples:
|
|
5
|
-
npx @cognite/cli apps skills pull Pull all skills
|
|
6
|
-
npx @cognite/cli apps skills pull --skill create-client-tool Pull a specific skill
|
|
7
|
-
npx @cognite/cli apps skills list List installed skills`);return i.command("pull").description("Pull all skills into your project").option("--source <owner/repo>","Skills repository",d,e).option("--skill <name>","Pull a specific skill by name").option("-i, --interactive","Interactively select which skills to install",!1).option("--global","Install skills globally",!1).action(k),i.command("list").description("List installed skills").action(()=>{n(["list"])}),i}s(P,"registerSkillsCommand");export{s as a,n as b,S as c,m as d,P as e};
|
package/dist/chunk-QOJVLP7E.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
\u{1F680} Deploying application via App Hosting API...
|
|
6
|
-
`);try{await this.ensureApp(t,n,r),await this.uploadVersion(t,o,i,a),l&&await this.publishAndActivate(t,o),console.log(`
|
|
7
|
-
\u2705 Deployment successful!`)}catch(c){let p=c instanceof Error?c.message:String(c);throw Object.assign(new Error(`Deployment failed: ${p}`),{cause:c})}}};s(b,"AppHostingClient");var 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
|
-
${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 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};
|