@cognite/dune 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/_templates/app/new/config/eslint.config.mjs.ejs.t +96 -0
  2. package/_templates/app/new/config/tailwind.config.js.ejs.t +1 -5
  3. package/_templates/app/new/config/vite.config.ts.ejs.t +9 -10
  4. package/_templates/app/new/config/vitest.config.ts.ejs.t +4 -5
  5. package/_templates/app/new/config/vitest.setup.ts.ejs.t +1 -2
  6. package/_templates/app/new/cursor/mcp.json.ejs.t +0 -5
  7. package/_templates/app/new/cursor/rules.mdc.ejs.t +1 -2
  8. package/_templates/app/new/prompt.js +29 -29
  9. package/_templates/app/new/root/index.html.ejs.t +3 -3
  10. package/_templates/app/new/root/package.json.ejs.t +11 -5
  11. package/_templates/app/new/src/App.test.tsx.ejs.t +32 -20
  12. package/_templates/app/new/src/App.tsx.ejs.t +118 -7
  13. package/_templates/app/new/src/lib/utils.ts.ejs.t +2 -3
  14. package/_templates/app/new/src/main.tsx.ejs.t +8 -8
  15. package/_templates/app/new/src/styles.css.ejs.t +5 -19
  16. package/bin/auth/authentication-flow.js +16 -14
  17. package/bin/auth/callback-server.js +23 -23
  18. package/bin/auth/certificate-manager.js +13 -13
  19. package/bin/auth/client-credentials.js +31 -32
  20. package/bin/auth/oauth-client.js +7 -7
  21. package/bin/cli.js +31 -30
  22. package/bin/deploy-command.js +32 -32
  23. package/bin/deploy-interactive-command.js +73 -73
  24. package/bin/skills-command.js +28 -28
  25. package/bin/utils/crypto.js +7 -8
  26. package/dist/auth/index.d.ts +10 -13
  27. package/dist/auth/index.js +1 -1
  28. package/dist/{chunk-VIBN7U5H.js → chunk-53VTKDSC.js} +1 -2
  29. package/dist/deploy/index.d.ts +9 -1
  30. package/dist/deploy/index.js +89 -7
  31. package/dist/index.d.ts +2 -2
  32. package/dist/index.js +1 -1
  33. package/dist/vite/index.d.ts +1 -0
  34. package/dist/vite/index.js +5 -2
  35. package/package.json +1 -1
  36. package/src/auth/dune-auth-provider.tsx +17 -16
  37. package/src/auth/index.ts +5 -5
  38. package/src/auth/use-dune.ts +5 -4
  39. package/src/auth/utils.ts +18 -18
  40. package/src/deploy/application-deployer.ts +12 -11
  41. package/src/deploy/application-packager.ts +11 -10
  42. package/src/deploy/deploy.ts +7 -6
  43. package/src/deploy/get-sdk.ts +5 -4
  44. package/src/deploy/index.ts +6 -6
  45. package/src/deploy/login.test.ts +49 -0
  46. package/src/deploy/login.ts +134 -11
  47. package/src/deploy/types.ts +4 -0
  48. package/src/index.ts +1 -1
  49. package/src/vite/fusion-open-plugin.ts +17 -15
  50. package/src/vite/index.ts +1 -1
  51. package/_templates/app/new/config/biome.json.ejs.t +0 -54
  52. package/_templates/app/new/config/components.json.ejs.t +0 -28
@@ -4,9 +4,8 @@
4
4
  * Provides functions for generating secure random strings and PKCE code challenges.
5
5
  */
6
6
 
7
- import crypto from "node:crypto";
7
+ import crypto from 'node:crypto';
8
8
 
9
- // biome-ignore lint/complexity/noStaticOnlyClass: Utility class pattern
10
9
  export class CryptoUtils {
11
10
  /**
12
11
  * Generate a cryptographically secure random string
@@ -16,10 +15,10 @@ export class CryptoUtils {
16
15
  static generateRandomString(length) {
17
16
  const bytes = crypto.randomBytes(length);
18
17
  return bytes
19
- .toString("base64")
20
- .replace(/\+/g, "-")
21
- .replace(/\//g, "_")
22
- .replace(/=/g, "")
18
+ .toString('base64')
19
+ .replace(/\+/g, '-')
20
+ .replace(/\//g, '_')
21
+ .replace(/=/g, '')
23
22
  .slice(0, length);
24
23
  }
25
24
 
@@ -29,7 +28,7 @@ export class CryptoUtils {
29
28
  * @returns {string} Base64url-encoded SHA256 hash of the verifier
30
29
  */
31
30
  static generateCodeChallenge(verifier) {
32
- const hash = crypto.createHash("sha256").update(verifier).digest();
33
- return hash.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
31
+ const hash = crypto.createHash('sha256').update(verifier).digest();
32
+ return hash.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
34
33
  }
35
34
  }
@@ -1,31 +1,28 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import * as _cognite_sdk from '@cognite/sdk';
2
+ import * as react from 'react';
3
+ import { ReactNode } from 'react';
3
4
  import { CogniteClient } from '@cognite/sdk';
4
- import React from 'react';
5
5
 
6
- declare const DuneAuthProviderContext: React.Context<{
6
+ interface DuneContextValue {
7
7
  sdk: CogniteClient;
8
8
  isLoading: boolean;
9
9
  error?: string;
10
- }>;
10
+ }
11
+ declare const DuneAuthProviderContext: react.Context<DuneContextValue>;
11
12
  interface DuneAuthProviderProps {
12
- children: React.ReactNode;
13
+ children: ReactNode;
13
14
  useIFrameAuthentication?: boolean;
14
15
  useLocalConfiguration?: {
15
16
  org: string;
16
17
  project: string;
17
18
  baseUrl: string;
18
19
  };
19
- loadingComponent?: React.ReactNode;
20
- errorComponent?: (error: string) => React.ReactNode;
20
+ loadingComponent?: ReactNode;
21
+ errorComponent?: (error: string) => ReactNode;
21
22
  }
22
23
  declare const DuneAuthProvider: ({ children, loadingComponent, errorComponent, }: DuneAuthProviderProps) => react_jsx_runtime.JSX.Element;
23
24
 
24
- declare const useDune: () => {
25
- sdk: _cognite_sdk.CogniteClient;
26
- isLoading: boolean;
27
- error?: string;
28
- };
25
+ declare const useDune: () => DuneContextValue;
29
26
 
30
27
  interface CDFConfig {
31
28
  project: string;
@@ -38,4 +35,4 @@ declare const getToken: (clientId: string, clientSecret: string) => Promise<any>
38
35
  declare const createCDFSDK: (config: CDFConfig) => Promise<CogniteClient>;
39
36
  declare const EMPTY_SDK: CogniteClient;
40
37
 
41
- export { type CDFConfig, DuneAuthProvider, DuneAuthProviderContext, type DuneAuthProviderProps, EMPTY_SDK, createCDFSDK, getToken, useDune };
38
+ export { type CDFConfig, DuneAuthProvider, DuneAuthProviderContext, type DuneAuthProviderProps, type DuneContextValue, EMPTY_SDK, createCDFSDK, getToken, useDune };
@@ -5,7 +5,7 @@ import {
5
5
  createCDFSDK,
6
6
  getToken,
7
7
  useDune
8
- } from "../chunk-VIBN7U5H.js";
8
+ } from "../chunk-53VTKDSC.js";
9
9
  export {
10
10
  DuneAuthProvider,
11
11
  DuneAuthProviderContext,
@@ -1,7 +1,6 @@
1
1
  // src/auth/dune-auth-provider.tsx
2
2
  import { CogniteClient as CogniteClient2 } from "@cognite/sdk";
3
- import { createContext, useEffect } from "react";
4
- import { useState } from "react";
3
+ import { createContext, useEffect, useState } from "react";
5
4
 
6
5
  // src/auth/utils.ts
7
6
  import { CogniteClient } from "@cognite/sdk";
@@ -7,6 +7,10 @@ type Deployment = {
7
7
  deployClientId: string;
8
8
  deploySecretName: string;
9
9
  published: boolean;
10
+ /** Identity provider type. Defaults to "cdf" if not specified */
11
+ idpType?: "cdf" | "entra_id";
12
+ /** Tenant ID for Entra ID authentication. Required when idpType is "entra_id" */
13
+ tenantId?: string;
10
14
  };
11
15
  type App = {
12
16
  externalId: string;
@@ -85,6 +89,10 @@ declare class ApplicationPackager {
85
89
 
86
90
  declare const getSdk: (deployment: Deployment, folder: string) => Promise<CogniteClient>;
87
91
 
88
- declare const getToken: (deployClientId: string, deploySecretName: string) => Promise<any>;
92
+ /**
93
+ * Get access token for deployment using the appropriate identity provider.
94
+ * Supports both CDF OAuth and Entra ID (Azure AD) authentication.
95
+ */
96
+ declare const getToken: (deployment: Deployment) => Promise<string>;
89
97
 
90
98
  export { type App, ApplicationPackager, CdfApplicationDeployer, type Deployment, deploy, getSdk, getToken };
@@ -187,22 +187,39 @@ var loadSecretsFromEnv = () => {
187
187
  return {};
188
188
  }
189
189
  };
190
- var getToken = async (deployClientId, deploySecretName) => {
190
+ var getSecretFromEnv = (secretEnvVarName) => {
191
191
  let deploySecret;
192
192
  if (process.env.DEPLOYMENT_SECRET) {
193
193
  deploySecret = process.env.DEPLOYMENT_SECRET;
194
194
  }
195
195
  if (!deploySecret) {
196
196
  const secrets = loadSecretsFromEnv();
197
- deploySecret = secrets[deploySecretName];
197
+ deploySecret = secrets[secretEnvVarName];
198
198
  }
199
199
  if (!deploySecret) {
200
- deploySecret = process.env[deploySecretName];
200
+ deploySecret = process.env[secretEnvVarName];
201
201
  }
202
202
  if (!deploySecret) {
203
- throw new Error(`Deployment secret not found in environment: ${deploySecretName}`);
203
+ throw new Error(`Secret not found in environment: ${secretEnvVarName}`);
204
204
  }
205
- const header = `Basic ${btoa(`${deployClientId}:${deploySecret}`)}`;
205
+ return deploySecret;
206
+ };
207
+ var extractClusterFromUrl = (url) => {
208
+ if (!url) return "";
209
+ try {
210
+ const urlObj = new URL(url);
211
+ const hostname = urlObj.hostname;
212
+ return hostname.replace(/\.cognitedata\.com$/, "");
213
+ } catch {
214
+ let cluster = url.replace(/^https?:\/\//, "");
215
+ cluster = cluster.split("/")[0];
216
+ cluster = cluster.split(":")[0];
217
+ cluster = cluster.replace(/\.cognitedata\.com$/, "");
218
+ return cluster;
219
+ }
220
+ };
221
+ var getTokenCdf = async (clientId, clientSecret) => {
222
+ const header = `Basic ${btoa(`${clientId}:${clientSecret}`)}`;
206
223
  const response = await fetch("https://auth.cognite.com/oauth2/token", {
207
224
  method: "POST",
208
225
  headers: {
@@ -212,15 +229,80 @@ var getToken = async (deployClientId, deploySecretName) => {
212
229
  body: new URLSearchParams({ grant_type: "client_credentials" })
213
230
  });
214
231
  if (!response.ok) {
215
- throw new Error(`Failed to get token: ${response.status} ${response.statusText}`);
232
+ const errorText = await response.text();
233
+ throw new Error(
234
+ `Failed to get token from CDF: ${response.status} ${response.statusText}
235
+ ${errorText}`
236
+ );
216
237
  }
217
238
  const data = await response.json();
239
+ if (!data.access_token) {
240
+ throw new Error("No access token returned from CDF authentication");
241
+ }
218
242
  return data.access_token;
219
243
  };
244
+ var getTokenEntra = async (clientId, clientSecret, tenantId, baseUrl) => {
245
+ if (!baseUrl) {
246
+ throw new Error(
247
+ "Entra ID authentication requires 'baseUrl' to be set in deployment configuration"
248
+ );
249
+ }
250
+ const cluster = extractClusterFromUrl(baseUrl);
251
+ if (!cluster) {
252
+ throw new Error(
253
+ `Entra ID authentication requires 'baseUrl' to be a valid CDF URL (e.g., https://cluster.cognitedata.com), got: ${baseUrl}`
254
+ );
255
+ }
256
+ const tokenUrl = `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/token`;
257
+ const scope = `https://${cluster}.cognitedata.com/.default`;
258
+ const response = await fetch(tokenUrl, {
259
+ method: "POST",
260
+ headers: {
261
+ "Content-Type": "application/x-www-form-urlencoded"
262
+ },
263
+ body: new URLSearchParams({
264
+ client_id: clientId,
265
+ client_secret: clientSecret,
266
+ scope,
267
+ grant_type: "client_credentials"
268
+ })
269
+ });
270
+ if (!response.ok) {
271
+ const errorText = await response.text();
272
+ throw new Error(
273
+ `Failed to get token from Entra ID: ${response.status} ${response.statusText}
274
+ ${errorText}`
275
+ );
276
+ }
277
+ const data = await response.json();
278
+ if (!data.access_token) {
279
+ throw new Error("No access token returned from Entra ID authentication");
280
+ }
281
+ return data.access_token;
282
+ };
283
+ var getToken = async (deployment) => {
284
+ const {
285
+ deployClientId,
286
+ deploySecretName,
287
+ idpType = "cdf",
288
+ tenantId,
289
+ baseUrl
290
+ } = deployment;
291
+ const deploySecret = getSecretFromEnv(deploySecretName);
292
+ if (idpType === "entra_id") {
293
+ if (!tenantId) {
294
+ throw new Error(
295
+ "Entra ID authentication requires 'tenantId' in deployment configuration"
296
+ );
297
+ }
298
+ return getTokenEntra(deployClientId, deploySecret, tenantId, baseUrl);
299
+ }
300
+ return getTokenCdf(deployClientId, deploySecret);
301
+ };
220
302
 
221
303
  // src/deploy/get-sdk.ts
222
304
  var getSdk = async (deployment, folder) => {
223
- const token = await getToken(deployment.deployClientId, deployment.deploySecretName);
305
+ const token = await getToken(deployment);
224
306
  const sdk = new CogniteClient({
225
307
  appId: folder,
226
308
  project: deployment.project,
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { CDFConfig, DuneAuthProvider, DuneAuthProviderContext, DuneAuthProviderProps, EMPTY_SDK, createCDFSDK, getToken, useDune } from './auth/index.js';
1
+ export { CDFConfig, DuneAuthProvider, DuneAuthProviderContext, DuneAuthProviderProps, DuneContextValue, EMPTY_SDK, createCDFSDK, getToken, useDune } from './auth/index.js';
2
2
  import 'react/jsx-runtime';
3
- import '@cognite/sdk';
4
3
  import 'react';
4
+ import '@cognite/sdk';
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  createCDFSDK,
6
6
  getToken,
7
7
  useDune
8
- } from "./chunk-VIBN7U5H.js";
8
+ } from "./chunk-53VTKDSC.js";
9
9
  export {
10
10
  DuneAuthProvider,
11
11
  DuneAuthProviderContext,
@@ -5,6 +5,7 @@ interface ViteDevServer {
5
5
  } | string | null;
6
6
  on: (event: string, callback: () => void) => void;
7
7
  } | null;
8
+ printUrls: () => void;
8
9
  }
9
10
  declare const fusionOpenPlugin: () => {
10
11
  name: string;
@@ -14,7 +14,7 @@ var fusionOpenPlugin = () => {
14
14
  return {
15
15
  name: "fusion-open",
16
16
  configureServer(server) {
17
- server.httpServer?.on("listening", () => {
17
+ server.printUrls = () => {
18
18
  const address = server.httpServer?.address();
19
19
  const port = address && typeof address === "object" ? address.port : 3001;
20
20
  const appJsonPath = path.join(process.cwd(), "app.json");
@@ -26,13 +26,16 @@ var fusionOpenPlugin = () => {
26
26
  const parsedBaseUrl = baseUrl?.split("//")[1];
27
27
  if (org && project && baseUrl) {
28
28
  const fusionUrl = `https://${org}.fusion.cognite.com/${project}/streamlit-apps/dune/development/${port}?cluster=${parsedBaseUrl}&workspace=industrial-tools`;
29
+ console.log(` \u279C Fusion: ${fusionUrl}`);
29
30
  openUrl(fusionUrl);
31
+ return;
30
32
  }
31
33
  } catch (error) {
32
34
  console.warn("Failed to read app.json for Fusion URL", error);
33
35
  }
34
36
  }
35
- });
37
+ console.warn(" \u279C No valid app.json found \u2014 cannot determine Fusion URL");
38
+ };
36
39
  }
37
40
  };
38
41
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cognite/dune",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Build and deploy React apps to Cognite Data Fusion",
5
5
  "keywords": ["cognite", "dune", "cdf", "fusion", "react", "scaffold", "deploy"],
6
6
  "license": "Apache-2.0",
@@ -1,24 +1,25 @@
1
- import { CogniteClient } from "@cognite/sdk";
2
- import type React from "react";
3
- import { createContext, useEffect } from "react";
4
- import { useState } from "react";
5
- import { EMPTY_SDK, handleCredentialsResponse, requestCredentials } from "./utils";
1
+ import { CogniteClient } from '@cognite/sdk';
2
+ import { createContext, useEffect, useState, type ReactNode } from 'react';
6
3
 
7
- export const DuneAuthProviderContext = createContext<{
4
+ import { EMPTY_SDK, handleCredentialsResponse, requestCredentials } from './utils';
5
+
6
+ export interface DuneContextValue {
8
7
  sdk: CogniteClient;
9
8
  isLoading: boolean;
10
9
  error?: string;
11
- }>({
10
+ }
11
+
12
+ export const DuneAuthProviderContext = createContext<DuneContextValue>({
12
13
  sdk: EMPTY_SDK,
13
14
  isLoading: false,
14
15
  });
15
16
 
16
17
  export interface DuneAuthProviderProps {
17
- children: React.ReactNode;
18
+ children: ReactNode;
18
19
  useIFrameAuthentication?: boolean;
19
20
  useLocalConfiguration?: { org: string; project: string; baseUrl: string };
20
- loadingComponent?: React.ReactNode;
21
- errorComponent?: (error: string) => React.ReactNode;
21
+ loadingComponent?: ReactNode;
22
+ errorComponent?: (error: string) => ReactNode;
22
23
  }
23
24
 
24
25
  export const DuneAuthProvider = ({
@@ -50,7 +51,7 @@ export const FusionIframeAuthenticationInnerProvider = ({
50
51
  requestCredentials();
51
52
 
52
53
  const handleMessage = async (event: MessageEvent) => {
53
- console.log("šŸ” Handling message from Fusion");
54
+ console.log('šŸ” Handling message from Fusion');
54
55
 
55
56
  const credentials = handleCredentialsResponse(event);
56
57
 
@@ -60,7 +61,7 @@ export const FusionIframeAuthenticationInnerProvider = ({
60
61
 
61
62
  // Process credentials (initial or refresh)
62
63
  const sdk = new CogniteClient({
63
- appId: "dune-app",
64
+ appId: 'dune-app',
64
65
  project: credentials.project,
65
66
  baseUrl: credentials.baseUrl,
66
67
  oidcTokenProvider: async () => {
@@ -74,12 +75,12 @@ export const FusionIframeAuthenticationInnerProvider = ({
74
75
  setIsLoading(false);
75
76
  };
76
77
 
77
- console.log("šŸ” Adding message listener");
78
- window.addEventListener("message", handleMessage);
79
- return () => window.removeEventListener("message", handleMessage);
78
+ console.log('šŸ” Adding message listener');
79
+ window.addEventListener('message', handleMessage);
80
+ return () => window.removeEventListener('message', handleMessage);
80
81
  }, []);
81
82
 
82
- console.log("šŸ” CDFIframeAuthenticationInnerProvider", sdk, isLoading, error);
83
+ console.log('šŸ” CDFIframeAuthenticationInnerProvider', sdk, isLoading, error);
83
84
 
84
85
  if (error && errorComponent) {
85
86
  return <>{errorComponent(error)}</>;
package/src/auth/index.ts CHANGED
@@ -2,10 +2,10 @@
2
2
  export {
3
3
  DuneAuthProvider,
4
4
  DuneAuthProviderContext,
5
- } from "./dune-auth-provider";
6
- export { useDune } from "./use-dune";
7
- export { getToken, createCDFSDK, EMPTY_SDK } from "./utils";
5
+ } from './dune-auth-provider';
6
+ export { useDune } from './use-dune';
7
+ export { getToken, createCDFSDK, EMPTY_SDK } from './utils';
8
8
 
9
9
  // Type exports
10
- export type { CDFConfig } from "./utils";
11
- export type { DuneAuthProviderProps } from "./dune-auth-provider";
10
+ export type { CDFConfig } from './utils';
11
+ export type { DuneAuthProviderProps, DuneContextValue } from './dune-auth-provider';
@@ -1,11 +1,12 @@
1
- import { useContext } from "react";
2
- import { DuneAuthProviderContext } from "./dune-auth-provider";
1
+ import { useContext } from 'react';
3
2
 
4
- export const useDune = () => {
3
+ import { DuneAuthProviderContext, type DuneContextValue } from './dune-auth-provider';
4
+
5
+ export const useDune = (): DuneContextValue => {
5
6
  const context = useContext(DuneAuthProviderContext);
6
7
 
7
8
  if (!context) {
8
- throw new Error("useDune must be used within a DuneAuthProvider");
9
+ throw new Error('useDune must be used within a DuneAuthProvider');
9
10
  }
10
11
 
11
12
  return context;
package/src/auth/utils.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { CogniteClient } from "@cognite/sdk";
1
+ import { CogniteClient } from '@cognite/sdk';
2
2
 
3
3
  export const MESSAGE_TYPES = {
4
- APP_HOST_READY: "APP_HOST_READY",
5
- APP_READY: "APP_READY",
6
- CREDENTIALS: "CREDENTIALS",
7
- REQUEST_CREDENTIALS: "REQUEST_CREDENTIALS",
4
+ APP_HOST_READY: 'APP_HOST_READY',
5
+ APP_READY: 'APP_READY',
6
+ CREDENTIALS: 'CREDENTIALS',
7
+ REQUEST_CREDENTIALS: 'REQUEST_CREDENTIALS',
8
8
  } as const;
9
9
 
10
10
  export interface CDFConfig {
@@ -18,14 +18,14 @@ export interface CDFConfig {
18
18
  export const getToken = async (clientId: string, clientSecret: string) => {
19
19
  const header = `Basic ${btoa(`${clientId}:${clientSecret}`)}`;
20
20
 
21
- const response = await fetch("https://auth.cognite.com/oauth2/token", {
22
- method: "POST",
21
+ const response = await fetch('https://auth.cognite.com/oauth2/token', {
22
+ method: 'POST',
23
23
  headers: {
24
24
  Authorization: header,
25
- "Content-Type": "application/x-www-form-urlencoded",
25
+ 'Content-Type': 'application/x-www-form-urlencoded',
26
26
  },
27
27
  body: new URLSearchParams({
28
- grant_type: "client_credentials",
28
+ grant_type: 'client_credentials',
29
29
  }),
30
30
  });
31
31
 
@@ -34,11 +34,11 @@ export const getToken = async (clientId: string, clientSecret: string) => {
34
34
  };
35
35
 
36
36
  export const createCDFSDK = async (config: CDFConfig) => {
37
- const { project, baseUrl, clientId, clientSecret, appId = "cdf-authentication-package" } = config;
37
+ const { project, baseUrl, clientId, clientSecret, appId = 'cdf-authentication-package' } = config;
38
38
 
39
39
  if (!project || !baseUrl || !clientId || !clientSecret) {
40
40
  throw new Error(
41
- "Missing required configuration. Please provide: project, baseUrl, clientId, clientSecret"
41
+ 'Missing required configuration. Please provide: project, baseUrl, clientId, clientSecret'
42
42
  );
43
43
  }
44
44
 
@@ -56,9 +56,9 @@ export const createCDFSDK = async (config: CDFConfig) => {
56
56
  };
57
57
 
58
58
  export const EMPTY_SDK = new CogniteClient({
59
- appId: "cdf-authentication-package",
60
- project: "",
61
- oidcTokenProvider: async () => "",
59
+ appId: 'cdf-authentication-package',
60
+ project: '',
61
+ oidcTokenProvider: async () => '',
62
62
  });
63
63
 
64
64
  interface Credentials {
@@ -68,18 +68,18 @@ interface Credentials {
68
68
  }
69
69
 
70
70
  export const requestCredentials = () => {
71
- console.log("šŸ”‘ Requesting credentials from parent...");
71
+ console.log('šŸ”‘ Requesting credentials from parent...');
72
72
  if (window.parent && window.parent !== window) {
73
- window.parent.postMessage({ type: "REQUEST_CREDENTIALS" }, "*");
73
+ window.parent.postMessage({ type: 'REQUEST_CREDENTIALS' }, '*');
74
74
  }
75
75
  };
76
76
 
77
77
  export const handleCredentialsResponse = (event: MessageEvent) => {
78
78
  // Check if this is a credentials message (wrapped in type/credentials format)
79
- if (event.data?.type === "PROVIDE_CREDENTIALS" && event.data?.credentials) {
79
+ if (event.data?.type === 'PROVIDE_CREDENTIALS' && event.data?.credentials) {
80
80
  const creds = event.data.credentials;
81
81
  if (creds.token && creds.baseUrl && creds.project) {
82
- console.log("šŸŽ‰ useCredentials received credentials:", {
82
+ console.log('šŸŽ‰ useCredentials received credentials:', {
83
83
  hasToken: !!creds.token,
84
84
  tokenLength: creds.token?.length || 0,
85
85
  project: creds.project,
@@ -4,8 +4,9 @@
4
4
  * Handles deployment of packaged applications to CDF.
5
5
  */
6
6
 
7
- import fs from "node:fs";
8
- import type { CogniteClient } from "@cognite/sdk";
7
+ import fs from 'node:fs';
8
+
9
+ import type { CogniteClient } from '@cognite/sdk';
9
10
 
10
11
  export class CdfApplicationDeployer {
11
12
  private client: CogniteClient;
@@ -17,7 +18,7 @@ export class CdfApplicationDeployer {
17
18
  this.client = client;
18
19
  }
19
20
 
20
- private DATA_SET_EXTERNAL_ID = "published-custom-apps";
21
+ private DATA_SET_EXTERNAL_ID = 'published-custom-apps';
21
22
 
22
23
  /**
23
24
  * Validate that the required data set exists and is accessible
@@ -36,8 +37,8 @@ export class CdfApplicationDeployer {
36
37
  const created = await this.client.datasets.create([
37
38
  {
38
39
  externalId: this.DATA_SET_EXTERNAL_ID,
39
- name: "Published Custom Apps",
40
- description: "Published Custom Apps",
40
+ name: 'Published Custom Apps',
41
+ description: 'Published Custom Apps',
41
42
  writeProtected: false,
42
43
  },
43
44
  ]);
@@ -69,11 +70,11 @@ export class CdfApplicationDeployer {
69
70
  published = false
70
71
  ): Promise<void> {
71
72
  // Validate data set exists and get its ID
72
- console.log("šŸ” Validating data set access...");
73
+ console.log('šŸ” Validating data set access...');
73
74
  const dataSetId = await this.validateDataSet();
74
75
  console.log(`āœ… Data set '${this.DATA_SET_EXTERNAL_ID}' validated (ID: ${dataSetId})\n`);
75
76
 
76
- console.log("šŸ“ Creating file record...");
77
+ console.log('šŸ“ Creating file record...');
77
78
 
78
79
  const fileContent = fs.readFileSync(zipFilename);
79
80
  const metadata = {
@@ -88,7 +89,7 @@ export class CdfApplicationDeployer {
88
89
  {
89
90
  name: `${appExternalId}-${versionTag}.zip`,
90
91
  externalId: `${appExternalId}-${versionTag}`,
91
- directory: "/dune-apps",
92
+ directory: '/dune-apps',
92
93
  metadata: metadata,
93
94
  dataSetId: dataSetId,
94
95
  },
@@ -97,7 +98,7 @@ export class CdfApplicationDeployer {
97
98
  true // waitUntilAcknowledged
98
99
  );
99
100
 
100
- console.log("āœ… File record created");
101
+ console.log('āœ… File record created');
101
102
  }
102
103
 
103
104
  /**
@@ -117,7 +118,7 @@ export class CdfApplicationDeployer {
117
118
  zipFilename: string,
118
119
  published = false
119
120
  ): Promise<void> {
120
- console.log("\nšŸš€ Deploying application to CDF...\n");
121
+ console.log('\nšŸš€ Deploying application to CDF...\n');
121
122
 
122
123
  try {
123
124
  // Upload to Files API
@@ -130,7 +131,7 @@ export class CdfApplicationDeployer {
130
131
  published
131
132
  );
132
133
 
133
- console.log("\nāœ… Deployment successful!");
134
+ console.log('\nāœ… Deployment successful!');
134
135
  } catch (error: unknown) {
135
136
  const message = error instanceof Error ? error.message : String(error);
136
137
  throw new Error(`Deployment failed: ${message}`);
@@ -4,9 +4,10 @@
4
4
  * Handles packaging of build directories into deployment-ready zip files.
5
5
  */
6
6
 
7
- import fs from "node:fs";
8
- import path from "node:path";
9
- import archiver from "archiver";
7
+ import fs from 'node:fs';
8
+ import path from 'node:path';
9
+
10
+ import archiver from 'archiver';
10
11
 
11
12
  export class ApplicationPackager {
12
13
  private distPath: string;
@@ -14,7 +15,7 @@ export class ApplicationPackager {
14
15
  /**
15
16
  * @param {string} distDirectory - Build directory to package (can be relative or absolute)
16
17
  */
17
- constructor(distDirectory = "dist") {
18
+ constructor(distDirectory = 'dist') {
18
19
  // If distDirectory is already an absolute path, use it as-is
19
20
  // Otherwise, join it with the current working directory
20
21
  this.distPath = path.isAbsolute(distDirectory)
@@ -38,29 +39,29 @@ export class ApplicationPackager {
38
39
  * @param {boolean} verbose - Enable verbose logging
39
40
  * @returns {Promise<string>} Path to created zip file
40
41
  */
41
- async createZip(outputFilename = "app.zip", verbose = false): Promise<string> {
42
+ async createZip(outputFilename = 'app.zip', verbose = false): Promise<string> {
42
43
  this.validateBuildDirectory();
43
44
 
44
- console.log("šŸ“¦ Packaging application...");
45
+ console.log('šŸ“¦ Packaging application...');
45
46
 
46
47
  return new Promise((resolve, reject) => {
47
48
  const output = fs.createWriteStream(outputFilename);
48
- const archive = archiver("zip", {
49
+ const archive = archiver('zip', {
49
50
  zlib: { level: 9 }, // Maximum compression
50
51
  });
51
52
 
52
- output.on("close", () => {
53
+ output.on('close', () => {
53
54
  const sizeMB = (archive.pointer() / 1024 / 1024).toFixed(2);
54
55
  console.log(`āœ… App packaged: ${outputFilename} (${sizeMB} MB)`);
55
56
  resolve(outputFilename);
56
57
  });
57
58
 
58
- archive.on("error", (err: Error) => {
59
+ archive.on('error', (err: Error) => {
59
60
  reject(new Error(`Failed to create zip: ${err.message}`));
60
61
  });
61
62
 
62
63
  if (verbose) {
63
- archive.on("entry", (entry: archiver.EntryData) => {
64
+ archive.on('entry', (entry: archiver.EntryData) => {
64
65
  console.log(` šŸ“„ ${entry.name}`);
65
66
  });
66
67
  }