cognite-create 0.2.39 → 0.2.42

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/bin/index.js CHANGED
@@ -79,11 +79,9 @@ async function main() {
79
79
  }
80
80
 
81
81
  // Skip install and start prompts - we'll install our own dependencies
82
- const hasNoInstallFlag = additionalArgs.some(
83
- (arg) => arg === "--no-install" || arg === "--install"
84
- );
85
- if (!hasNoInstallFlag) {
86
- additionalArgs.push("--no-install");
82
+ const hasImmediateFlag = additionalArgs.some((arg) => arg === "--immediate");
83
+ if (!hasImmediateFlag) {
84
+ additionalArgs.push("--immediate", "false");
87
85
  }
88
86
 
89
87
  const createArgs = ["create-vite@latest", projectDir, ...additionalArgs];
package/bin/index.test.js CHANGED
@@ -135,7 +135,7 @@ describe("CLI Command Tests", () => {
135
135
  ]);
136
136
  });
137
137
 
138
- it("should add --no-rolldown and --no-install flags by default", () => {
138
+ it("should add --no-rolldown and --immediate false flags by default", () => {
139
139
  const args = ["my-project"];
140
140
  let projectDir;
141
141
  let additionalArgs = [];
@@ -164,11 +164,11 @@ describe("CLI Command Tests", () => {
164
164
  }
165
165
 
166
166
  // Skip install and start prompts - we'll install our own dependencies
167
- const hasNoInstallFlag = additionalArgs.some(
168
- (arg) => arg === "--no-install" || arg === "--install"
167
+ const hasImmediateFlag = additionalArgs.some(
168
+ (arg) => arg === "--immediate"
169
169
  );
170
- if (!hasNoInstallFlag) {
171
- additionalArgs.push("--no-install");
170
+ if (!hasImmediateFlag) {
171
+ additionalArgs.push("--immediate", "false");
172
172
  }
173
173
 
174
174
  const createArgs = ["create-vite@latest", projectDir, ...additionalArgs];
@@ -178,7 +178,8 @@ describe("CLI Command Tests", () => {
178
178
  "--template",
179
179
  "react-ts",
180
180
  "--no-rolldown",
181
- "--no-install",
181
+ "--immediate",
182
+ "false",
182
183
  ]);
183
184
  expect(createArgs).toEqual([
184
185
  "create-vite@latest",
@@ -186,7 +187,8 @@ describe("CLI Command Tests", () => {
186
187
  "--template",
187
188
  "react-ts",
188
189
  "--no-rolldown",
189
- "--no-install",
190
+ "--immediate",
191
+ "false",
190
192
  ]);
191
193
  });
192
194
 
@@ -219,11 +221,11 @@ describe("CLI Command Tests", () => {
219
221
  }
220
222
 
221
223
  // Skip install and start prompts
222
- const hasNoInstallFlag = additionalArgs.some(
223
- (arg) => arg === "--no-install" || arg === "--install"
224
+ const hasImmediateFlag = additionalArgs.some(
225
+ (arg) => arg === "--immediate"
224
226
  );
225
- if (!hasNoInstallFlag) {
226
- additionalArgs.push("--no-install");
227
+ if (!hasImmediateFlag) {
228
+ additionalArgs.push("--immediate", "false");
227
229
  }
228
230
 
229
231
  const createArgs = ["create-vite@latest", projectDir, ...additionalArgs];
@@ -233,7 +235,8 @@ describe("CLI Command Tests", () => {
233
235
  "--rolldown",
234
236
  "--template",
235
237
  "react-ts",
236
- "--no-install",
238
+ "--immediate",
239
+ "false",
237
240
  ]);
238
241
  expect(createArgs).toEqual([
239
242
  "create-vite@latest",
@@ -241,7 +244,8 @@ describe("CLI Command Tests", () => {
241
244
  "--rolldown",
242
245
  "--template",
243
246
  "react-ts",
244
- "--no-install",
247
+ "--immediate",
248
+ "false",
245
249
  ]);
246
250
  });
247
251
 
@@ -274,11 +278,11 @@ describe("CLI Command Tests", () => {
274
278
  }
275
279
 
276
280
  // Skip install and start prompts
277
- const hasNoInstallFlag = additionalArgs.some(
278
- (arg) => arg === "--no-install" || arg === "--install"
281
+ const hasImmediateFlag = additionalArgs.some(
282
+ (arg) => arg === "--immediate"
279
283
  );
280
- if (!hasNoInstallFlag) {
281
- additionalArgs.push("--no-install");
284
+ if (!hasImmediateFlag) {
285
+ additionalArgs.push("--immediate", "false");
282
286
  }
283
287
 
284
288
  const createArgs = ["create-vite@latest", projectDir, ...additionalArgs];
@@ -288,7 +292,8 @@ describe("CLI Command Tests", () => {
288
292
  "--no-rolldown",
289
293
  "--template",
290
294
  "react-ts",
291
- "--no-install",
295
+ "--immediate",
296
+ "false",
292
297
  ]);
293
298
  expect(createArgs).toEqual([
294
299
  "create-vite@latest",
@@ -296,7 +301,8 @@ describe("CLI Command Tests", () => {
296
301
  "--no-rolldown",
297
302
  "--template",
298
303
  "react-ts",
299
- "--no-install",
304
+ "--immediate",
305
+ "false",
300
306
  ]);
301
307
  });
302
308
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cognite-create",
3
- "version": "0.2.39",
3
+ "version": "0.2.42",
4
4
  "description": "Create a Next.js app preconfigured with Cognite defaults.",
5
5
  "bin": {
6
6
  "cognite-create": "./bin/index.js"
@@ -11,79 +11,72 @@ Always use semantic Tailwind color classes (e.g., bg-primary, text-primary, bord
11
11
  Layout & Components
12
12
  Make sure to put the components together in a cohesive manner.
13
13
  Make sure to properly handle x and y values to proper scales.
14
- Make sure you are properly handling timezoned dates between client and server.
14
+ Make sure you are properly handling timezoned dates.
15
15
 
16
16
  Chart Rendering Rules
17
- Use direct hex colors: Avoid CSS variables like var(--color-*) in stroke properties
17
+ Use direct hex colors: Avoid CSS variables like var(--color-\*) in stroke properties
18
18
  Make sure charts have properly formatted value properties to display data.
19
19
  Use real Cognite data from the SDK.
20
20
  Be really careful with x chart values and make sure you are rendering them correctly. Keep consistent with date and timestamp formatting as this can cause rendering issues.
21
21
 
22
22
  CogniteSDK Rules
23
23
 
24
- Environment Variables
25
- # Cognite Configuration
26
- NEXT_PUBLIC_COGNITE_PROJECT=
27
- NEXT_PUBLIC_COGNITE_BASE_URL=
24
+ This is a client-side only application. All Cognite SDK calls are made directly from the browser.
28
25
 
29
- # OIDC Authentication (Required for production)
30
- NEXT_PUBLIC_COGNITE_CLIENT_ID=
31
- COGNITE_CLIENT_SECRET=
26
+ Environment Variables
32
27
 
33
- Make sure to build fallbacks for any error or empty states.
28
+ # Cognite Configuration
34
29
 
35
- All CogniteSDK calls should be done server side in server actions or in server components.
30
+ COGNITE_PROJECT=
31
+ COGNITE_BASE_URL=
36
32
 
37
- We can't use the cognite sdk in the browser as the COGNITE_CLIENT_SECRET is private.
33
+ # OIDC Authentication (Required for production)
38
34
 
39
- Prefer server actions over API routes.
35
+ COGNITE_CLIENT_ID=
40
36
 
41
- When setting up auth rememeber to set up the oidcTokenProvider.
37
+ SDK Usage
42
38
 
43
- Use this function to get the token string:
39
+ The Cognite SDK is initialized and provided through the infrastructure components. Use the `useCDF` hook to access the authenticated SDK client in any component:
44
40
 
45
- export const getToken = async (clientId: string, clientSecret: string) => {
46
- const header = "Basic " + btoa(`${clientId}:${clientSecret}`);
41
+ ```tsx
42
+ import { useCDF } from "@/infrastructure/hooks/useCDF";
47
43
 
48
- const response = await fetch("https://auth.cognite.com/oauth2/token", {
49
- method: "POST",
50
- headers: {
51
- Authorization: header,
52
- "Content-Type": "application/x-www-form-urlencoded",
53
- },
54
- body: new URLSearchParams({
55
- grant_type: "client_credentials",
56
- }),
57
- });
44
+ function MyComponent() {
45
+ const sdk = useCDF();
58
46
 
59
- const data = await response.json();
47
+ // Use sdk to make API calls
48
+ const timeSeries = await sdk.timeseries.list().autoPagingToArray();
49
+ }
50
+ ```
60
51
 
61
- console.log("Token response:", data);
62
- return data.access_token;
63
- };
52
+ All data fetching happens client-side. Use React Query for managing async data:
64
53
 
65
- Always run `pnpm lint` after you make changes to make sure you have fixed all potential errors.
54
+ - Wrap SDK calls in custom hooks using `useQuery` or `useMutation`
55
+ - Handle loading and error states appropriately
56
+ - Cache data effectively to minimize API calls
66
57
 
67
- Make sure all client and server components are handled properly and you are not passing client events from server components.
58
+ Authentication is handled by the infrastructure layer - use the provided components from `/src/infrastructure`. The infrastructure handles token management and SDK initialization automatically.
68
59
 
69
- Security Fix: Moved Cognite SDK authentication to server-side API routes (/api/cognite/*) to keep client secrets secure, with client-side service using fetch() calls to these routes.
60
+ Make sure to build fallbacks for any error or empty states.
70
61
 
71
- Date Format Fix: Converted Date objects to Unix timestamps (milliseconds) before sending to Cognite API, as it doesn't accept ISO strings.
62
+ Always run `npm run lint` after you make changes to make sure you have fixed all potential errors.
72
63
 
73
- Granularity/Aggregates Fix: Ensured aggregates are always provided when granularity is specified (Cognite API requirement), defaulting to "average" aggregation.
64
+ Date Format Fix: Convert Date objects to Unix timestamps (milliseconds) before sending to Cognite API, as it doesn't accept ISO strings.
74
65
 
75
- Aggregated Data Display: Updated chart component to handle both regular datapoints (value) and aggregated datapoints (average, max, min, etc.) since granularity returns aggregated data.
66
+ Granularity/Aggregates Fix: Ensure aggregates are always provided when granularity is specified (Cognite API requirement), defaulting to "average" aggregation.
76
67
 
77
- UI Enhancement: Replaced search dialog with dropdown interface for time series selection, providing better UX with automatic loading and filtering of available time series.
68
+ Aggregated Data Display: Update chart components to handle both regular datapoints (value) and aggregated datapoints (average, max, min, etc.) since granularity returns aggregated data.
78
69
 
79
- Prefer select dropdowns with in built search
70
+ UI Enhancement: Prefer select dropdowns with built-in search for better user experience.
80
71
 
81
72
  WATCH OUT FOR THIS BUG WITH SHADCN SELECTS:
82
73
  A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.
83
74
 
84
75
  src/components/ui/cognite/select.tsx (107:5) @ SelectItem
85
76
 
77
+ 105 | }: React.ComponentProps<typeof SelectPrimitive.Item>) {
78
+ 106 | return (
79
+
80
+ > 107 | <SelectPrimitive.Item
86
81
 
87
- 105 | }: React.ComponentProps<typeof SelectPrimitive.Item>) {
88
- 106 | return (
89
- > 107 | <SelectPrimitive.Item
82
+ Use React best practices when calling useEffect, make sure we are using useMemo and useCallback effectively to avoid re-renders.
@@ -0,0 +1,7 @@
1
+ # Cognite Configuration
2
+ VITE_COGNITE_PROJECT=
3
+ VITE_COGNITE_BASE_URL=
4
+
5
+ # OIDC Authentication (Required for production)
6
+ VITE_COGNITE_CLIENT_ID=
7
+ VITE_COGNITE_CLIENT_SECRET=