@intuned/runtime-dev 1.3.8-deploy.0 → 1.3.8-deploy.10

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.
@@ -15,15 +15,18 @@ var _save = require("./save");
15
15
  var _constants2 = require("../../../common/constants");
16
16
  var _path = _interopRequireDefault(require("path"));
17
17
  var fs = _interopRequireWildcard(require("fs-extra"));
18
+ var _prompts = _interopRequireDefault(require("prompts"));
19
+ var _terminalLink = _interopRequireDefault(require("terminal-link"));
18
20
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
19
21
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
20
22
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
23
  async function runDeployProject(projectName, auth) {
22
24
  const result = await (0, _save.runSaveProject)(projectName, auth);
23
- const state = result?.state ?? "not-deployed";
24
- let firstRun = undefined;
25
- if (state === "not-deployed") {
26
- firstRun = await handleFirstRunExperience();
25
+ const shouldPromptFirstRunExperience = result?.state === "UNPUBLISHED";
26
+ let firstRunInfo = undefined;
27
+ const settings = await (0, _helpers.loadIntunedJson)();
28
+ if (shouldPromptFirstRunExperience) {
29
+ firstRunInfo = await promptFirstRunExperience(settings);
27
30
  }
28
31
  const {
29
32
  workspaceId,
@@ -39,7 +42,7 @@ async function runDeployProject(projectName, auth) {
39
42
  headers,
40
43
  method: "POST",
41
44
  body: JSON.stringify({
42
- firstRun: firstRun
45
+ firstRunInfo
43
46
  })
44
47
  });
45
48
  if (!response.ok) {
@@ -97,12 +100,38 @@ async function runDeployProject(projectName, auth) {
97
100
  }
98
101
  if (status === "completed") {
99
102
  const url = (0, _helpers.getBaseUrl)();
100
- const projectUrl = `${url}/projects/${projectId}`;
103
+ const hasDefaultJob = await getDefaultJobExists({
104
+ baseUrl,
105
+ workspaceId,
106
+ projectName,
107
+ apiKey
108
+ });
101
109
  (0, _terminal.terminal)(`\n^g^+Project deployed successfully!^:\n`);
102
- (0, _terminal.terminal)(`^+View project:^s ^c^_${projectUrl}/runs^:\n`);
103
- (0, _terminal.terminal)(`^+Run playground:^s ^c^_${projectUrl}/runs?playground=open^:\n`);
104
- (0, _terminal.terminal)(`^+Manage jobs:^s ^c^_${projectUrl}/jobs^:\n`);
105
- (0, _terminal.terminal)(`^+Trigger default job:^s ^c^_${projectUrl}/jobs/default?action=trigger^:\n`);
110
+ const projectUrl = `${url}/projects/${projectId}`;
111
+ const runsUrl = `${projectUrl}/runs`;
112
+ const jobsUrl = `${projectUrl}/jobs`;
113
+ const runsPlaygroundUrl = `${runsUrl}?playground=open`;
114
+ const defaultJobTriggerUrl = `${jobsUrl}/default?action=trigger`;
115
+ if (_terminalLink.default.isSupported) {
116
+ (0, _terminal.terminal)(`^+[${(0, _terminalLink.default)("View project", projectUrl)}]^ `);
117
+ if (settings.apiAccess.enabled) {
118
+ (0, _terminal.terminal)(`^+[${(0, _terminalLink.default)("Run playground", runsPlaygroundUrl)}]^ `);
119
+ }
120
+ (0, _terminal.terminal)(`^+[${(0, _terminalLink.default)("Manage jobs", jobsUrl)}]^ `);
121
+ if (hasDefaultJob) {
122
+ (0, _terminal.terminal)(`^+[${(0, _terminalLink.default)("Trigger default job", defaultJobTriggerUrl)}]^ `);
123
+ }
124
+ (0, _terminal.terminal)("\n");
125
+ } else {
126
+ (0, _terminal.terminal)(`^+View project:^s ^c^_${projectUrl}/runs^:\n`);
127
+ if (settings.apiAccess.enabled) {
128
+ (0, _terminal.terminal)(`^+Run playground:^s ^c^_${projectUrl}/runs?playground=open^:\n`);
129
+ }
130
+ (0, _terminal.terminal)(`^+Manage jobs:^s ^c^_${projectUrl}/jobs^:\n`);
131
+ if (hasDefaultJob) {
132
+ (0, _terminal.terminal)(`^+Trigger default job:^s ^c^_${projectUrl}/jobs/default?action=trigger^:\n`);
133
+ }
134
+ }
106
135
  return;
107
136
  }
108
137
  let errorMessage = `^r^+An error occurred while deploying project:^:\n^R${message}^:\n`;
@@ -154,13 +183,12 @@ const checkIntunedProjectDeployStatus = async (workspaceId, projectName, apiKey)
154
183
  };
155
184
  };
156
185
  {}
157
- async function handleFirstRunExperience() {
158
- let testAuthSessionInput = null;
159
- const settings = await (0, _helpers.loadIntunedJson)();
186
+ async function promptFirstRunExperience(settings) {
187
+ let testAuthSessionInput = undefined;
160
188
  const shouldPromptForTestAuthSession = settings.authSessions.enabled && settings.authSessions.type === "API";
161
189
  let shouldPromptForDefaultJob = true;
162
190
  if (shouldPromptForTestAuthSession) {
163
- testAuthSessionInput = getFirstRunExperienceTestAuthSessionParameters({
191
+ testAuthSessionInput = await promptFirstRunExperienceTestAuthSessionParameters({
164
192
  shouldPromptForDefaultJob
165
193
  });
166
194
  if (!testAuthSessionInput) {
@@ -169,10 +197,12 @@ async function handleFirstRunExperience() {
169
197
  }
170
198
  return {
171
199
  testAuthSessionInput,
172
- defaultJobInput: shouldPromptForDefaultJob ? getFirstRunExperienceDefaultJobParameters(settings["metadata"].defaultJobInput) : undefined
200
+ defaultJobInput: shouldPromptForDefaultJob ? await promptFirstRunExperienceDefaultJobParameters({
201
+ defaultJobInput: settings["metadata"].defaultJobInput
202
+ }) : undefined
173
203
  };
174
204
  }
175
- async function getFirstRunExperienceTestAuthSessionParameters({
205
+ async function promptFirstRunExperienceTestAuthSessionParameters({
176
206
  shouldPromptForDefaultJob
177
207
  }) {
178
208
  const authSessionsDirectoryPath = _path.default.join(process.cwd(), _constants2.AUTH_SESSIONS_INSTANCES_FOLDER_NAME);
@@ -182,29 +212,56 @@ async function getFirstRunExperienceTestAuthSessionParameters({
182
212
  metadata
183
213
  } = await (0, _helpers.loadAuthSessionInstance)(authSessionId);
184
214
  if (metadata.authSessionInput) {
185
- const message = shouldPromptForDefaultJob ? "\n^cCreate a test auth session using ^:^+%s^:^c's parameters? (required for creating default job)^ " : "\n^cCreate a test auth session using ^:^+%s^:^c's parameters?^ ";
186
- (0, _terminal.terminal)(message, authSessionId);
187
- const answer = await _terminal.terminal.yesOrNo({
188
- yes: ["y", "ENTER"],
189
- no: ["n"]
190
- }).promise;
191
- (0, _terminal.terminal)("\n");
192
- if (answer) {
215
+ const message = shouldPromptForDefaultJob ? `^:^+Create a test auth session using^ ^c${authSessionId}^:^+ parameters?^ ^/(required for creating default job)^:` : `^:^+Create a test auth session using^ ^c${authSessionId}^:^+ parameters?^:`;
216
+ const {
217
+ value
218
+ } = await (0, _prompts.default)({
219
+ type: "confirm",
220
+ name: "value",
221
+ message: _terminal.terminal.str(message).toString(),
222
+ initial: true
223
+ });
224
+ if (value) {
193
225
  return metadata.authSessionInput;
194
226
  }
195
227
  }
196
228
  }
197
229
  }
198
- async function getFirstRunExperienceDefaultJobParameters({
230
+ async function promptFirstRunExperienceDefaultJobParameters({
199
231
  defaultJobInput
200
232
  }) {
201
- (0, _terminal.terminal)("\n^cCreate a default job?^");
202
- const answer = await _terminal.terminal.yesOrNo({
203
- yes: ["y", "ENTER"],
204
- no: ["n"]
205
- }).promise;
206
- (0, _terminal.terminal)("\n");
207
- if (answer) {
233
+ const {
234
+ value
235
+ } = await (0, _prompts.default)({
236
+ type: "confirm",
237
+ name: "value",
238
+ message: _terminal.terminal.str(`^:^+Create a default job with sample parameters?^:`).toString(),
239
+ initial: true
240
+ });
241
+ if (value) {
208
242
  return defaultJobInput;
209
243
  }
244
+ }
245
+ async function getDefaultJobExists({
246
+ baseUrl,
247
+ workspaceId,
248
+ projectName,
249
+ apiKey
250
+ }) {
251
+ const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/${projectName}/jobs/default`;
252
+ const headers = {
253
+ [_constants2.API_KEY_HEADER_NAME]: apiKey,
254
+ "Content-Type": "application/json"
255
+ };
256
+ const response = await fetch(url, {
257
+ headers,
258
+ method: "GET"
259
+ });
260
+ if (response.status === 404) {
261
+ return false;
262
+ }
263
+ if (!response.ok) {
264
+ throw new _helpers.CLIError(`Error checking default job existence ${response.status}: ${await response.text()}`);
265
+ }
266
+ return true;
210
267
  }
@@ -2,7 +2,7 @@ import { z } from "zod";
2
2
  import type { AuthCredentials } from "../types";
3
3
  export declare function runSaveProject(projectName: string, auth: AuthCredentials): Promise<{
4
4
  projectId: string;
5
- state: string;
5
+ state: string | undefined;
6
6
  } | undefined>;
7
7
  export declare const projectNameSchema: z.ZodEffects<z.ZodString, string, string>;
8
8
  export declare const validateProjectName: (projectName: string) => {
@@ -33,7 +33,8 @@ const saveProjectApiResponseSchema = _zod.z.string().transform((val, ctx) => {
33
33
  return _zod.z.NEVER;
34
34
  }
35
35
  }).pipe(_zod.z.object({
36
- id: _zod.z.string().uuid()
36
+ id: _zod.z.string().uuid(),
37
+ state: _zod.z.string().optional()
37
38
  }));
38
39
  async function runSaveProject(projectName, auth) {
39
40
  const {
@@ -86,7 +87,8 @@ async function runSaveProject(projectName, auth) {
86
87
  return;
87
88
  }
88
89
  const {
89
- id: projectId
90
+ id: projectId,
91
+ state
90
92
  } = parseResult.data;
91
93
  const dotEnvPath = path.join(projectPath, ".env");
92
94
  if (!(await fs.exists(dotEnvPath))) {
@@ -113,7 +115,7 @@ ${_constants2.API_KEY_ENV_VAR_KEY}=${apiKey}`);
113
115
  }
114
116
  return {
115
117
  projectId,
116
- state: "not-deployed"
118
+ state
117
119
  };
118
120
  }
119
121
  const projectNameSchema = exports.projectNameSchema = _zod.z.string().min(1, "Project Name is required").max(200, "Name must be 200 characters or less").regex(/^[a-z0-9]+(?:[-_][a-z0-9]+)*$/, "Name can only contain lowercase letters, numbers, hyphens, and underscores in between").refine(value => !_zod.z.string().uuid().safeParse(value).success, {
@@ -23,5 +23,5 @@ async function getAuthCredentials(options) {
23
23
  };
24
24
  }
25
25
  function getBaseUrl() {
26
- return process.env[_constants.API_BASE_URL_ENV_VAR_KEY] || process.env.INTUNED_API_DOMAIN || `https://app.intuned.io`;
26
+ return new URL(process.env[_constants.API_BASE_URL_ENV_VAR_KEY] || process.env.INTUNED_API_DOMAIN || `https://app.intuned.io`).origin;
27
27
  }
@@ -1,5 +1,43 @@
1
1
  import { z } from "zod";
2
- export declare const intunedJsonSchema: z.ZodObject<{
2
+ export declare const intunedJsonSchema: z.ZodIntersection<z.ZodObject<{
3
+ projectName: z.ZodOptional<z.ZodString>;
4
+ workspaceId: z.ZodOptional<z.ZodString>;
5
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
6
+ projectName: z.ZodOptional<z.ZodString>;
7
+ workspaceId: z.ZodOptional<z.ZodString>;
8
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
9
+ projectName: z.ZodOptional<z.ZodString>;
10
+ workspaceId: z.ZodOptional<z.ZodString>;
11
+ }, z.ZodTypeAny, "passthrough">>, z.ZodUnion<[z.ZodObject<{
12
+ authSessions: z.ZodObject<{
13
+ enabled: z.ZodLiteral<false>;
14
+ }, "strip", z.ZodTypeAny, {
15
+ enabled: false;
16
+ }, {
17
+ enabled: false;
18
+ }>;
19
+ apiAccess: z.ZodObject<{
20
+ enabled: z.ZodLiteral<false>;
21
+ }, "strip", z.ZodTypeAny, {
22
+ enabled: false;
23
+ }, {
24
+ enabled: false;
25
+ }>;
26
+ }, "strip", z.ZodTypeAny, {
27
+ authSessions: {
28
+ enabled: false;
29
+ };
30
+ apiAccess: {
31
+ enabled: false;
32
+ };
33
+ }, {
34
+ authSessions: {
35
+ enabled: false;
36
+ };
37
+ apiAccess: {
38
+ enabled: false;
39
+ };
40
+ }>, z.ZodObject<{
3
41
  authSessions: z.ZodUnion<[z.ZodObject<{
4
42
  enabled: z.ZodLiteral<false>;
5
43
  }, "strip", z.ZodTypeAny, {
@@ -22,8 +60,13 @@ export declare const intunedJsonSchema: z.ZodObject<{
22
60
  startUrl?: string | undefined;
23
61
  finishUrl?: string | undefined;
24
62
  }>]>;
25
- projectName: z.ZodOptional<z.ZodString>;
26
- workspaceId: z.ZodOptional<z.ZodString>;
63
+ apiAccess: z.ZodObject<{
64
+ enabled: z.ZodLiteral<true>;
65
+ }, "strip", z.ZodTypeAny, {
66
+ enabled: true;
67
+ }, {
68
+ enabled: true;
69
+ }>;
27
70
  }, "strip", z.ZodTypeAny, {
28
71
  authSessions: {
29
72
  enabled: false;
@@ -33,8 +76,9 @@ export declare const intunedJsonSchema: z.ZodObject<{
33
76
  startUrl?: string | undefined;
34
77
  finishUrl?: string | undefined;
35
78
  };
36
- projectName?: string | undefined;
37
- workspaceId?: string | undefined;
79
+ apiAccess: {
80
+ enabled: true;
81
+ };
38
82
  }, {
39
83
  authSessions: {
40
84
  enabled: false;
@@ -44,12 +88,25 @@ export declare const intunedJsonSchema: z.ZodObject<{
44
88
  startUrl?: string | undefined;
45
89
  finishUrl?: string | undefined;
46
90
  };
47
- projectName?: string | undefined;
48
- workspaceId?: string | undefined;
49
- }>;
91
+ apiAccess: {
92
+ enabled: true;
93
+ };
94
+ }>]>>;
50
95
  export type IntunedJson = z.infer<typeof intunedJsonSchema>;
51
96
  export declare const intunedSettingsFileNames: readonly ["Intuned.json", "Intuned.jsonc", "Intuned.yaml", "Intuned.yml", "Intuned.toml"];
52
97
  export declare function loadIntunedJson(): Promise<{
98
+ projectName?: string | undefined;
99
+ workspaceId?: string | undefined;
100
+ } & {
101
+ [k: string]: unknown;
102
+ } & ({
103
+ authSessions: {
104
+ enabled: false;
105
+ };
106
+ apiAccess: {
107
+ enabled: false;
108
+ };
109
+ } | {
53
110
  authSessions: {
54
111
  enabled: false;
55
112
  } | {
@@ -58,9 +115,10 @@ export declare function loadIntunedJson(): Promise<{
58
115
  startUrl?: string | undefined;
59
116
  finishUrl?: string | undefined;
60
117
  };
61
- projectName?: string | undefined;
62
- workspaceId?: string | undefined;
63
- }>;
118
+ apiAccess: {
119
+ enabled: true;
120
+ };
121
+ })>;
64
122
  export declare function getIntunedSettingsFile(): Promise<{
65
123
  name: typeof intunedSettingsFileNames[number];
66
124
  path: string;
@@ -18,6 +18,16 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
18
18
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
19
19
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
20
  const intunedJsonSchema = exports.intunedJsonSchema = _zod.z.object({
21
+ projectName: _zod.z.string().optional(),
22
+ workspaceId: _zod.z.string().optional()
23
+ }).passthrough().and(_zod.z.union([_zod.z.object({
24
+ authSessions: _zod.z.object({
25
+ enabled: _zod.z.literal(false)
26
+ }),
27
+ apiAccess: _zod.z.object({
28
+ enabled: _zod.z.literal(false)
29
+ })
30
+ }), _zod.z.object({
21
31
  authSessions: _zod.z.union([_zod.z.object({
22
32
  enabled: _zod.z.literal(false)
23
33
  }), _zod.z.object({
@@ -26,9 +36,10 @@ const intunedJsonSchema = exports.intunedJsonSchema = _zod.z.object({
26
36
  startUrl: _zod.z.string().optional(),
27
37
  finishUrl: _zod.z.string().optional()
28
38
  })]),
29
- projectName: _zod.z.string().optional(),
30
- workspaceId: _zod.z.string().optional()
31
- });
39
+ apiAccess: _zod.z.object({
40
+ enabled: _zod.z.literal(true)
41
+ })
42
+ })]));
32
43
  const intunedSettingsFileNames = exports.intunedSettingsFileNames = ["Intuned.json", "Intuned.jsonc", "Intuned.yaml", "Intuned.yml", "Intuned.toml"];
33
44
  async function loadIntunedJson() {
34
45
  const settingsFile = await getIntunedSettingsFile();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intuned/runtime-dev",
3
- "version": "1.3.8-deploy.0",
3
+ "version": "1.3.8-deploy.10",
4
4
  "description": "Intuned runtime",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -83,10 +83,12 @@
83
83
  "portfinder": "^1.0.37",
84
84
  "prettier": "2.8.0",
85
85
  "promptly": "3.2.0",
86
+ "prompts": "^2.4.2",
86
87
  "rollup": "3.26.2",
87
88
  "smol-toml": "^1.4.2",
88
89
  "source-map": "0.7.4",
89
90
  "terminal-kit": "^3.1.2",
91
+ "terminal-link": "^5.0.0",
90
92
  "ts-morph": "21.0.1",
91
93
  "ts-node": "10.9.1",
92
94
  "tslib": "2.6.0",
@@ -108,6 +110,7 @@
108
110
  "@types/jsdom": "^21.1.1",
109
111
  "@types/ms": "^2.1.0",
110
112
  "@types/promptly": "^3.0.4",
113
+ "@types/prompts": "^2.4.9",
111
114
  "@types/terminal-kit": "^2.5.7",
112
115
  "@types/wait-on": "^5.3.4",
113
116
  "@typescript-eslint/eslint-plugin": "^5.47.1",