@trackunit/iris-app 2.3.9-alpha-90b6c9b97dd.0 → 2.3.9

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/CHANGELOG.md CHANGED
@@ -1,3 +1,77 @@
1
+ ## 2.3.9 (2026-08-06)
2
+
3
+ ### 🧱 Updated Dependencies
4
+
5
+ - Updated iris-app-build-utilities to 2.2.7
6
+ - Updated iris-app-api to 2.2.7
7
+ - Updated react-vite-test-setup to 0.0.93
8
+ - Updated react-graphql-tools to 1.14.94
9
+ - Updated shared-utils to 1.15.95
10
+
11
+ ## 2.3.8 (2026-08-06)
12
+
13
+ ### 🧱 Updated Dependencies
14
+
15
+ - Updated iris-app-build-utilities to 2.2.6
16
+ - Updated iris-app-api to 2.2.6
17
+ - Updated react-vite-test-setup to 0.0.92
18
+ - Updated react-graphql-tools to 1.14.93
19
+ - Updated shared-utils to 1.15.94
20
+
21
+ ## 2.3.7 (2026-08-05)
22
+
23
+ ### 🩹 Fixes
24
+
25
+ - use menuItem.image instead of deprecated icon in scaffolded extension templates [GLU-1568] ([#24599](https://github.com/Trackunit/manager/pull/24599))
26
+
27
+ ### ❤️ Thank You
28
+
29
+ - Cursor @cursoragent
30
+ - Mikkel Thorbjørn Andersen @mta-trackunit
31
+
32
+ ## 2.3.6 (2026-08-05)
33
+
34
+ ### 🧱 Updated Dependencies
35
+
36
+ - Updated iris-app-build-utilities to 2.2.5
37
+ - Updated iris-app-api to 2.2.5
38
+ - Updated react-vite-test-setup to 0.0.91
39
+ - Updated react-graphql-tools to 1.14.92
40
+ - Updated shared-utils to 1.15.93
41
+
42
+ ## 2.3.5 (2026-08-04)
43
+
44
+ ### 🧱 Updated Dependencies
45
+
46
+ - Updated iris-app-build-utilities to 2.2.4
47
+ - Updated iris-app-api to 2.2.4
48
+ - Updated react-vite-test-setup to 0.0.90
49
+ - Updated react-graphql-tools to 1.14.91
50
+ - Updated shared-utils to 1.15.92
51
+
52
+ ## 2.3.4 (2026-08-04)
53
+
54
+ This was a version bump only for iris-app to align it with other projects, there were no code changes.
55
+
56
+ ## 2.3.3 (2026-08-04)
57
+
58
+ ### 🧱 Updated Dependencies
59
+
60
+ - Updated iris-app-build-utilities to 2.2.3
61
+ - Updated iris-app-api to 2.2.3
62
+ - Updated react-vite-test-setup to 0.0.89
63
+ - Updated react-graphql-tools to 1.14.90
64
+ - Updated shared-utils to 1.15.91
65
+
66
+ ## 2.3.2 (2026-08-03)
67
+
68
+ ### 🧱 Updated Dependencies
69
+
70
+ - Updated iris-app-build-utilities to 2.2.2
71
+ - Updated iris-app-api to 2.2.2
72
+ - Updated react-vite-test-setup to 0.0.88
73
+ - Updated shared-utils to 1.15.90
74
+
1
75
  ## 2.3.1 (2026-08-03)
2
76
 
3
77
  ### 🧱 Updated Dependencies
package/README.md CHANGED
@@ -11,6 +11,24 @@ For more info and a full guide on Iris App SDK Development, please visit our [De
11
11
 
12
12
  Run through the easy getting started guide here: [Getting Started](https://developers.trackunit.com/docs/getting-started)
13
13
 
14
+ ## Serverside GraphQL scaffolding
15
+
16
+ Typed access to the Trackunit public GraphQL API is optional for serverside API extensions:
17
+
18
+ ```bash
19
+ npx nx generate @trackunit/iris-app:extend \
20
+ --type=SERVERSIDE_API_EXTENSION \
21
+ --graphql
22
+ ```
23
+
24
+ The option is off by default. It reuses the standard `graphql-hooks` target, configures React-free code generation against the public schema, and adds a named typed asset query example. Regenerate documents after editing `.graphql` files:
25
+
26
+ ```bash
27
+ npx nx run <project>:graphql-hooks
28
+ ```
29
+
30
+ Local requests must include a user bearer token. Set `SDK_ENVIRONMENT=DEV` or `STAGE` in the extension's `.env` to target a non-production public API; unset defaults to production.
31
+
14
32
  ## Testing Local Changes
15
33
 
16
34
  To test changes to the SDK generators locally, you can verify them in a full, temporary workspace environment.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/iris-app",
3
- "version": "2.3.9-alpha-90b6c9b97dd.0",
3
+ "version": "2.3.9",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "main": "src/index.js",
6
6
  "generators": "./generators.json",
@@ -23,8 +23,10 @@
23
23
  "@nx/react": "23.1.0",
24
24
  "@npmcli/arborist": "^9.1.9",
25
25
  "win-ca": "^3.5.1",
26
- "@trackunit/shared-utils": "1.15.95-alpha-90b6c9b97dd.0",
27
- "@trackunit/iris-app-api": "2.2.7-alpha-90b6c9b97dd.0",
26
+ "@trackunit/iris-app-build-utilities": "2.2.7",
27
+ "@trackunit/react-graphql-tools": "1.14.94",
28
+ "@trackunit/shared-utils": "1.15.95",
29
+ "@trackunit/iris-app-api": "2.2.7",
28
30
  "tslib": "^2.6.2",
29
31
  "@clack/prompts": "^1.0.0",
30
32
  "@npm/types": "^1.0.2",
@@ -15,12 +15,81 @@ const irisAppServerSettings_1 = require("../utils/irisAppServerSettings");
15
15
  class NpmConflictError extends Error {
16
16
  }
17
17
  class NpmGeneralError extends Error {
18
+ constructor(message, statusCode, code, type) {
19
+ super(message);
20
+ this.statusCode = statusCode;
21
+ this.code = code;
22
+ this.type = type;
23
+ }
18
24
  }
19
25
  class ApproveError extends Error {
26
+ constructor(message, statusCode, code) {
27
+ super(message);
28
+ this.statusCode = statusCode;
29
+ this.code = code;
30
+ }
20
31
  }
21
32
  function sleep(time) {
22
33
  return new Promise(resolve => setTimeout(resolve, time));
23
34
  }
35
+ // Errno-style codes that indicate the request never reached the registry at all
36
+ // (DNS/connection/timeout failures at the transport layer), as opposed to local
37
+ // validation errors (e.g. libnpmpublish's EPRIVATE/EBADSEMVER/EUSAGE) which carry
38
+ // a code but are permanent and can never succeed on retry. Kept aligned with
39
+ // make-fetch-happen's own RETRY_ERRORS list (used by the submit path) plus the
40
+ // undici error codes doApproveApp's native fetch can raise.
41
+ //
42
+ // ENOTFOUND (DNS failure) is deliberately included even though make-fetch-happen
43
+ // itself excludes it as "bad hostname, or offline" - a DNS blip during a VPN/
44
+ // network transition is common enough in practice that failing fast here would
45
+ // trade one wasted-wait problem for developers hitting spurious permanent
46
+ // failures on flaky networks. This is a judgment call, not a clear-cut default.
47
+ const RETRYABLE_TRANSPORT_CODES = new Set([
48
+ "ENOTFOUND",
49
+ "ECONNRESET",
50
+ "ECONNREFUSED",
51
+ "ETIMEDOUT",
52
+ "EAI_AGAIN",
53
+ "ERR_SOCKET_TIMEOUT",
54
+ "EADDRINUSE",
55
+ // from @npmcli/agent, surfaced through make-fetch-happen
56
+ "ECONNECTIONTIMEOUT",
57
+ "EIDLETIMEOUT",
58
+ "ERESPONSETIMEOUT",
59
+ "ETRANSFERTIMEOUT",
60
+ // doApproveApp uses Node's native fetch (undici), which raises its own
61
+ // codes distinct from the classic Node errno codes above.
62
+ "UND_ERR_CONNECT_TIMEOUT",
63
+ "UND_ERR_HEADERS_TIMEOUT",
64
+ "UND_ERR_BODY_TIMEOUT",
65
+ "UND_ERR_SOCKET", // e.g. "other side closed" on a reused keep-alive connection
66
+ ]);
67
+ /**
68
+ * Decide whether a failed submit/approve attempt is worth retrying.
69
+ *
70
+ * This is an allowlist, not a denylist: only failures with a real chance of
71
+ * succeeding on a later attempt are retried - 5xx responses, 408/429 (timeout/
72
+ * rate-limited), a transport-level failure that never reached the registry at
73
+ * all (identified by a known transient errno code), or a minipass-fetch request
74
+ * timeout (which surfaces with the generic code FETCH_ERROR, distinguishable
75
+ * only via its `type: "request-timeout"`). Everything else - permanent 4xx
76
+ * errors, local validation errors with an unrelated code (e.g. EBADSEMVER), or
77
+ * any other unrecognized error shape - is treated as non-retryable by default.
78
+ *
79
+ * @param {number} [statusCode] The HTTP status code of the failed attempt, if any.
80
+ * @param {string} [code] The error's errno-style code, if any (no statusCode implies no HTTP response was received).
81
+ * @param {string} [type] The error's `type` field, if any. Only consulted when `code === "FETCH_ERROR"`, since that's the one code minipass-fetch's FetchError uses generically for several failure kinds - `type` is what distinguishes a timeout from the others.
82
+ * @returns {boolean} Whether the attempt should be retried.
83
+ */
84
+ function isRetryableError(statusCode, code, type) {
85
+ if (statusCode !== undefined) {
86
+ return statusCode >= 500 || statusCode === 408 || statusCode === 429;
87
+ }
88
+ if (code === undefined) {
89
+ return false;
90
+ }
91
+ return RETRYABLE_TRANSPORT_CODES.has(code) || (code === "FETCH_ERROR" && type === "request-timeout");
92
+ }
24
93
  /**
25
94
  * Submit the package to the npm registry.
26
95
  *
@@ -72,16 +141,24 @@ async function doUploadAppWithRetry(accessToken, manifest, tarData, settings, re
72
141
  console.error("❌ Unable to ship app package. Cannot submit over existing version.");
73
142
  return { success: false };
74
143
  }
144
+ if (!(e instanceof NpmGeneralError)) {
145
+ // An error shape we don't recognize (e.g. a bug elsewhere in this function) -
146
+ // log the full error/stack rather than a bare message so it stays debuggable.
147
+ console.error("❌ Unable to ship app package. Got error from Iris App SDK repository.", e);
148
+ return { success: false };
149
+ }
150
+ if (!isRetryableError(e.statusCode, e.code, e.type)) {
151
+ console.error("❌ Unable to ship app package.", e.message);
152
+ return { success: false };
153
+ }
154
+ if (retryCount > 1) {
155
+ console.error("⚠️ Unable to ship app package. Got error from Iris App SDK repository. Retrying submit...", e.message);
156
+ await sleep(30000);
157
+ return await doUploadAppWithRetry(accessToken, manifest, tarData, settings, retryCount - 1);
158
+ }
75
159
  else {
76
- if (retryCount > 1) {
77
- console.error("⚠️ Unable to ship app package. Got error from Iris App SDK repository. Retrying submit...", e);
78
- await sleep(30000);
79
- return await doUploadAppWithRetry(accessToken, manifest, tarData, settings, retryCount - 1);
80
- }
81
- else {
82
- console.error("❌ Unable to ship app package. Got error from Iris App SDK repository.", e);
83
- return { success: false };
84
- }
160
+ console.error("❌ Unable to ship app package. Got error from Iris App SDK repository.", e.message);
161
+ return { success: false };
85
162
  }
86
163
  }
87
164
  }
@@ -102,6 +179,9 @@ async function doUploadApp(accessToken, manifest, tarData, settings) {
102
179
  else {
103
180
  return {
104
181
  ok: false,
182
+ statusCode: err.statusCode,
183
+ code: err.code,
184
+ type: err.type,
105
185
  headers: new Headers(err.headers),
106
186
  statusText: `Error`,
107
187
  text: () => Promise.resolve(`${err.name} ${err.message}`),
@@ -130,7 +210,7 @@ async function doUploadApp(accessToken, manifest, tarData, settings) {
130
210
  " " +
131
211
  (await submitResult.text()) +
132
212
  ". Trace ID: " +
133
- submitResult.headers.get("trace-id"));
213
+ submitResult.headers.get("trace-id"), "statusCode" in submitResult ? submitResult.statusCode : undefined, "code" in submitResult ? submitResult.code : undefined, "type" in submitResult ? submitResult.type : undefined);
134
214
  }
135
215
  }
136
216
  async function promptUserForInput(query) {
@@ -150,19 +230,21 @@ async function doApproveAppWithRetry(token, manifest, settings, retryCount) {
150
230
  return await doApproveApp(token, manifest, settings);
151
231
  }
152
232
  catch (e) {
153
- if (e instanceof ApproveError) {
154
- if (retryCount > 1) {
155
- console.error("⚠️ Unable to approve app package. Got approve error from Iris App SDK repository. Retrying approve...", e);
156
- await sleep(30000);
157
- return await doApproveAppWithRetry(token, manifest, settings, retryCount - 1);
158
- }
159
- else {
160
- console.error("❌ Unable to approve app package. Got approve error from Iris App SDK repository.", e);
161
- return { success: false };
162
- }
233
+ if (!(e instanceof ApproveError)) {
234
+ console.error("❌ Unable to approve app package. Got error from Iris App SDK repository.", e);
235
+ return { success: false };
236
+ }
237
+ if (!isRetryableError(e.statusCode, e.code)) {
238
+ console.error("❌ Unable to approve app package.", e.message);
239
+ return { success: false };
240
+ }
241
+ if (retryCount > 1) {
242
+ console.error("⚠️ Unable to approve app package. Got approve error from Iris App SDK repository. Retrying approve...", e.message);
243
+ await sleep(30000);
244
+ return await doApproveAppWithRetry(token, manifest, settings, retryCount - 1);
163
245
  }
164
246
  else {
165
- console.error("❌ Unable to approve app package. Got error from Iris App SDK repository.", e);
247
+ console.error("❌ Unable to approve app package. Got approve error from Iris App SDK repository.", e.message);
166
248
  return { success: false };
167
249
  }
168
250
  }
@@ -170,18 +252,29 @@ async function doApproveAppWithRetry(token, manifest, settings, retryCount) {
170
252
  async function doApproveApp(token, manifest, settings) {
171
253
  if (process.env.TU_APPROVE === "true") {
172
254
  console.log(`🖋️ Approving the app...`);
255
+ // A rejection here (e.g. DNS/connection/timeout failure) never produced an HTTP
256
+ // response, so it's re-thrown as an ApproveError with no statusCode - carrying
257
+ // the underlying cause's errno code (if any) so isRetryableError can recognize
258
+ // genuine transport failures, and the cause's message so the log doesn't just
259
+ // say "fetch failed" with no indication of what actually broke.
173
260
  const approveResult = await fetch(new URL(`${manifest.name}@${manifest.version}`, settings.approvalUrl), {
174
261
  method: "PUT",
175
262
  headers: {
176
263
  Authorization: `Bearer ${token}`,
177
264
  },
265
+ }).catch((err) => {
266
+ const cause = err.cause instanceof Error ? err.cause : undefined;
267
+ const causeCode = cause && "code" in cause ? cause.code : undefined;
268
+ const code = typeof causeCode === "string" ? causeCode : undefined;
269
+ const reason = cause ? `${err.message}: ${cause.message}` : err.message;
270
+ throw new ApproveError(reason, undefined, code);
178
271
  });
179
272
  if (approveResult.ok) {
180
273
  console.log(`✅ Approved version ${manifest.version} of ${manifest.name}.`);
181
274
  return { success: true };
182
275
  }
183
276
  else {
184
- throw new ApproveError(`${approveResult.statusText}, ${await approveResult.text()}, Trace ID: ${approveResult.headers.get("trace-id")}`);
277
+ throw new ApproveError(`${approveResult.statusText}, ${await approveResult.text()}, Trace ID: ${approveResult.headers.get("trace-id")}`, approveResult.status);
185
278
  }
186
279
  }
187
280
  else {
@@ -4,8 +4,8 @@ exports.IrisAppGenerator = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const internal_1 = require("@nx/js/internal");
7
- const pacote = tslib_1.__importStar(require("pacote"));
8
7
  const path = tslib_1.__importStar(require("path"));
8
+ const get_package_manifest_1 = require("../utils/get-package-manifest");
9
9
  function normalizeOptions(tree, options) {
10
10
  const name = (0, devkit_1.names)(options.name).fileName;
11
11
  const projectDirectory = options.directory ? path.join(options.directory, name) : name;
@@ -36,9 +36,6 @@ function addFiles(tree, options, packageJson) {
36
36
  };
37
37
  (0, devkit_1.generateFiles)(tree, path.join(__dirname, "files"), options.projectRoot, templateOptions);
38
38
  }
39
- const getManifest = (packageName) => {
40
- return pacote.manifest(packageName, process.env.TU_NPM_REGISTRY ? { registry: process.env.TU_NPM_REGISTRY } : undefined);
41
- };
42
39
  /**
43
40
  * Iris App Generator.
44
41
  * This generator will create a new iris app, you can call this from your own generator.
@@ -49,24 +46,24 @@ const getManifest = (packageName) => {
49
46
  */
50
47
  const IrisAppGenerator = async function (tree, options) {
51
48
  const normalizedOptions = normalizeOptions(tree, options);
52
- const packageJsonFromNpm = await getManifest("@trackunit/iris-app");
49
+ const packageJsonFromNpm = await (0, get_package_manifest_1.getPackageManifest)("@trackunit/iris-app");
53
50
  const packageJsonLocally = (0, devkit_1.readJsonFile)(path.join(__dirname, "..", "..", "..", "package.json"));
54
51
  if (options.updatePackageJson) {
55
52
  if (packageJsonFromNpm.version !== packageJsonLocally.version) {
56
53
  // eslint-disable-next-line no-console
57
54
  console.warn(`⚠️ This version of the iris-app package does not match the version of the iris-app package from NPM JS. Please update using: npm i @trackunit/iris-app@${packageJsonFromNpm.version}`);
58
55
  }
59
- const reactComponentsPackageJsonFromNpm = getManifest("@trackunit/react-components");
60
- const reactCoreContextsPackageJsonFromNpm = getManifest("@trackunit/react-core-contexts");
61
- const cssCorePackageJsonFromNpm = getManifest("@trackunit/css-core");
56
+ const reactComponentsPackageJsonFromNpm = (0, get_package_manifest_1.getPackageManifest)("@trackunit/react-components");
57
+ const reactCoreContextsPackageJsonFromNpm = (0, get_package_manifest_1.getPackageManifest)("@trackunit/react-core-contexts");
58
+ const cssCorePackageJsonFromNpm = (0, get_package_manifest_1.getPackageManifest)("@trackunit/css-core");
62
59
  const tuDependencies = {
63
60
  "@trackunit/react-components": (await reactComponentsPackageJsonFromNpm).version,
64
61
  "@trackunit/react-core-contexts": (await reactCoreContextsPackageJsonFromNpm).version,
65
62
  "@trackunit/css-core": (await cssCorePackageJsonFromNpm).version,
66
63
  };
67
- const irisAppSdkVitePackageJsonFromNpm = getManifest("@trackunit/iris-app-sdk-vite");
68
- const reactCoreContextsTestPackageJsonFromNpm = getManifest("@trackunit/react-core-contexts-test");
69
- const reactTestSetupPackageJsonFromNpm = getManifest("@trackunit/react-test-setup");
64
+ const irisAppSdkVitePackageJsonFromNpm = (0, get_package_manifest_1.getPackageManifest)("@trackunit/iris-app-sdk-vite");
65
+ const reactCoreContextsTestPackageJsonFromNpm = (0, get_package_manifest_1.getPackageManifest)("@trackunit/react-core-contexts-test");
66
+ const reactTestSetupPackageJsonFromNpm = (0, get_package_manifest_1.getPackageManifest)("@trackunit/react-test-setup");
70
67
  const tuDevDependencies = {
71
68
  "@trackunit/iris-app-sdk-vite": (await irisAppSdkVitePackageJsonFromNpm).version,
72
69
  "@trackunit/react-core-contexts-test": (await reactCoreContextsTestPackageJsonFromNpm).version,
@@ -7,7 +7,7 @@ const fleetExtensionManifest: FleetExtensionManifest = {
7
7
 
8
8
  menuItem: {
9
9
  name: "<%= projectName %>",
10
- icon: "QuestionMarkCircle"
10
+ image: { name: "QuestionMarkCircle" }
11
11
  }
12
12
  };
13
13
 
@@ -0,0 +1,6 @@
1
+ query <%= className %>AssetById($id: ID!) {
2
+ asset(id: $id) {
3
+ id
4
+ name
5
+ }
6
+ }
@@ -0,0 +1,31 @@
1
+ import { createTrackunitGraphqlClient, getUserToken } from "@trackunit/serverside-utils";
2
+ import { Hono } from "hono";
3
+ import { <%= className %>AssetByIdDocument } from "./generated/graphql-api/graphql";
4
+
5
+ const app = new Hono();
6
+
7
+ app.get("/health", c => {
8
+ return c.json({
9
+ status: "ok",
10
+ timestamp: new Date().toISOString(),
11
+ service: "<%= projectName %>",
12
+ });
13
+ });
14
+
15
+ app.get("/assets/:id", async c => {
16
+ const token = getUserToken({ context: c });
17
+ if (!token) {
18
+ return c.json({ error: "Unauthorized" }, 401);
19
+ }
20
+
21
+ const client = createTrackunitGraphqlClient({ context: c });
22
+ const data = await client.request({
23
+ document: <%= className %>AssetByIdDocument,
24
+ variables: { id: c.req.param("id") },
25
+ signal: c.req.raw.signal,
26
+ });
27
+
28
+ return c.json(data);
29
+ });
30
+
31
+ export default app.fetch;
@@ -16,7 +16,7 @@ const widgetExtensionManifest: WidgetExtensionManifest = {
16
16
 
17
17
  header: {
18
18
  name: "<%= projectName %>",
19
- icon: "QuestionMarkCircle"
19
+ image: { name: "QuestionMarkCircle" }
20
20
  },
21
21
 
22
22
  supportedFilters: {},
@@ -1,5 +1,15 @@
1
1
  import { Tree } from "@nx/devkit";
2
2
  import { IrisAppExtensionGeneratorSchema } from "./schema";
3
+ type ServersideGraphqlOptions = {
4
+ readonly projectName: string;
5
+ readonly projectRoot: string;
6
+ readonly className: string;
7
+ readonly serversideUtilsVersion: string;
8
+ };
9
+ /**
10
+ * Adds public-schema codegen and a typed Hono example to a generated serverside extension.
11
+ */
12
+ export declare const addServersideGraphql: (tree: Tree, options: ServersideGraphqlOptions) => Promise<void>;
3
13
  /**
4
14
  * Ensures that jest.preset.js exists and includes the required @trackunit/react-test-setup preset.
5
15
  * If the file doesn't exist, creates it. If it exists but doesn't include the preset, updates it.
@@ -13,3 +23,4 @@ export declare function ensureJestPresetConfiguration(tree: Tree, templateOption
13
23
  * @returns { Promise<void> } void
14
24
  */
15
25
  export declare const IrisAppExtensionGenerator: (tree: Tree, options: IrisAppExtensionGeneratorSchema) => Promise<() => void>;
26
+ export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IrisAppExtensionGenerator = void 0;
3
+ exports.IrisAppExtensionGenerator = exports.addServersideGraphql = void 0;
4
4
  exports.ensureJestPresetConfiguration = ensureJestPresetConfiguration;
5
5
  const tslib_1 = require("tslib");
6
6
  const devkit_1 = require("@nx/devkit");
@@ -9,12 +9,53 @@ const js_1 = require("@nx/js");
9
9
  const internal_1 = require("@nx/js/internal");
10
10
  const react_1 = require("@nx/react");
11
11
  const iris_app_api_1 = require("@trackunit/iris-app-api");
12
+ const react_graphql_tools_1 = require("@trackunit/react-graphql-tools");
12
13
  const fs = tslib_1.__importStar(require("fs"));
13
14
  const path = tslib_1.__importStar(require("path"));
14
15
  const string_ts_1 = require("string-ts");
15
16
  const ts_morph_1 = require("ts-morph");
16
17
  const astUtils_1 = require("../../utils/ast/astUtils");
18
+ const get_package_manifest_1 = require("../utils/get-package-manifest");
17
19
  const dependencies_1 = require("./dependencies");
20
+ const addGraphqlDependency = (target) => {
21
+ if (!target) {
22
+ return;
23
+ }
24
+ const dependsOn = target.dependsOn ?? [];
25
+ if (!dependsOn.includes("graphql-hooks")) {
26
+ target.dependsOn = [...dependsOn, "graphql-hooks"];
27
+ }
28
+ };
29
+ /**
30
+ * Adds public-schema codegen and a typed Hono example to a generated serverside extension.
31
+ */
32
+ const addServersideGraphql = async (tree, options) => {
33
+ await (0, react_graphql_tools_1.addGraphqlGenerator)(tree, {
34
+ project: options.projectName,
35
+ schemaSource: "public",
36
+ generateMocks: false,
37
+ });
38
+ (0, devkit_1.generateFiles)(tree, path.join(__dirname, "files", "SERVERSIDE_API_EXTENSION_GRAPHQL"), options.projectRoot, {
39
+ ...options,
40
+ template: "",
41
+ });
42
+ (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, "project.json"), projectJson => {
43
+ addGraphqlDependency(projectJson.targets.build);
44
+ addGraphqlDependency(projectJson.targets.test);
45
+ addGraphqlDependency(projectJson.targets.serve);
46
+ addGraphqlDependency(projectJson.targets["tsc-validate"]);
47
+ return projectJson;
48
+ });
49
+ (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, "package.json"), packageJson => {
50
+ packageJson.dependencies = {
51
+ ...packageJson.dependencies,
52
+ "@trackunit/serverside-utils": options.serversideUtilsVersion,
53
+ };
54
+ return packageJson;
55
+ });
56
+ };
57
+ exports.addServersideGraphql = addServersideGraphql;
58
+ const getPackageVersion = async (packageName) => (await (0, get_package_manifest_1.getPackageManifest)(packageName)).version;
18
59
  function normalizeOptions(tree, options) {
19
60
  const name = (0, devkit_1.names)(options.name).fileName;
20
61
  const projectDirectory = options.directory ? `${(0, devkit_1.names)(options.directory).fileName}/${name}` : name;
@@ -86,6 +127,9 @@ const IrisAppExtensionGenerator = async function (tree, options) {
86
127
  template: "",
87
128
  };
88
129
  const irisAppExtensionType = normalizedOptions.type;
130
+ if (normalizedOptions.graphql && irisAppExtensionType !== "SERVERSIDE_API_EXTENSION") {
131
+ throw new Error("GraphQL setup is only supported for SERVERSIDE_API_EXTENSION");
132
+ }
89
133
  if (!tree.exists(`${(0, devkit_1.getWorkspaceLayout)(tree).appsDir}/${normalizedOptions.app}`)) {
90
134
  throw new Error(`The app does not exist: ${(0, devkit_1.getWorkspaceLayout)(tree).appsDir}/${normalizedOptions.app} make sure you enter the right app name`);
91
135
  }
@@ -193,6 +237,14 @@ const IrisAppExtensionGenerator = async function (tree, options) {
193
237
  return projectJson;
194
238
  });
195
239
  }
240
+ if (normalizedOptions.graphql) {
241
+ await (0, exports.addServersideGraphql)(tree, {
242
+ projectName: normalizedOptions.projectName,
243
+ projectRoot: normalizedOptions.projectRoot,
244
+ className: (0, devkit_1.names)(normalizedOptions.name).className,
245
+ serversideUtilsVersion: await getPackageVersion("@trackunit/serverside-utils"),
246
+ });
247
+ }
196
248
  //TODO: Change the following to update the manifest in the virtual Tree - not on the file system.
197
249
  const project = new ts_morph_1.Project({
198
250
  tsConfigFilePath: `${(0, devkit_1.getWorkspaceLayout)(tree).appsDir}/${normalizedOptions.app}/tsconfig.app.json`,
@@ -16,4 +16,5 @@ export interface IrisAppExtensionGeneratorSchema {
16
16
  | "LIFECYCLE_EXTENSION"
17
17
  | "SERVERSIDE_API_EXTENSION";
18
18
  extendJestPreset?: boolean;
19
+ graphql?: boolean;
19
20
  }
@@ -64,6 +64,11 @@
64
64
  "type": "boolean",
65
65
  "description": "If the root jest.preset.js should be extended with the Iris app preset",
66
66
  "default": true
67
+ },
68
+ "graphql": {
69
+ "type": "boolean",
70
+ "description": "Add typed Trackunit public GraphQL support (SERVERSIDE_API_EXTENSION only)",
71
+ "default": false
67
72
  }
68
73
  },
69
74
  "required": ["name", "directory", "type"]
@@ -0,0 +1,5 @@
1
+ import * as pacote from "pacote";
2
+ /**
3
+ * Keeps Trackunit registry overrides consistent across package-consuming generators.
4
+ */
5
+ export declare const getPackageManifest: (packageName: string) => Promise<pacote.AbbreviatedManifest & pacote.ManifestResult>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPackageManifest = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pacote = tslib_1.__importStar(require("pacote"));
6
+ /**
7
+ * Keeps Trackunit registry overrides consistent across package-consuming generators.
8
+ */
9
+ const getPackageManifest = (packageName) => pacote.manifest(packageName, process.env.TU_NPM_REGISTRY ? { registry: process.env.TU_NPM_REGISTRY } : undefined);
10
+ exports.getPackageManifest = getPackageManifest;
11
+ //# sourceMappingURL=get-package-manifest.js.map