@intuned/runtime-dev 1.3.8-deploy.6 → 1.3.8-deploy.8

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,17 @@ 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"));
18
19
  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
20
  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
21
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
22
  async function runDeployProject(projectName, auth) {
22
23
  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();
24
+ const shouldPromptFirstRunExperience = result?.state === "UNPUBLISHED";
25
+ let firstRunInfo = undefined;
26
+ const settings = await (0, _helpers.loadIntunedJson)();
27
+ if (shouldPromptFirstRunExperience) {
28
+ firstRunInfo = await promptFirstRunExperience(settings);
27
29
  }
28
30
  const {
29
31
  workspaceId,
@@ -39,7 +41,7 @@ async function runDeployProject(projectName, auth) {
39
41
  headers,
40
42
  method: "POST",
41
43
  body: JSON.stringify({
42
- firstRun
44
+ firstRunInfo
43
45
  })
44
46
  });
45
47
  if (!response.ok) {
@@ -97,12 +99,22 @@ async function runDeployProject(projectName, auth) {
97
99
  }
98
100
  if (status === "completed") {
99
101
  const url = (0, _helpers.getBaseUrl)();
102
+ const hasDefaultJob = await getDefaultJobExists({
103
+ baseUrl,
104
+ workspaceId,
105
+ projectName,
106
+ apiKey
107
+ });
100
108
  const projectUrl = `${url}/projects/${projectId}`;
101
109
  (0, _terminal.terminal)(`\n^g^+Project deployed successfully!^:\n`);
102
110
  (0, _terminal.terminal)(`^+View project:^s ^c^_${projectUrl}/runs^:\n`);
103
- (0, _terminal.terminal)(`^+Run playground:^s ^c^_${projectUrl}/runs?playground=open^:\n`);
111
+ if (settings.apiAccess.enabled) {
112
+ (0, _terminal.terminal)(`^+Run playground:^s ^c^_${projectUrl}/runs?playground=open^:\n`);
113
+ }
104
114
  (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`);
115
+ if (hasDefaultJob) {
116
+ (0, _terminal.terminal)(`^+Trigger default job:^s ^c^_${projectUrl}/jobs/default?action=trigger^:\n`);
117
+ }
106
118
  return;
107
119
  }
108
120
  let errorMessage = `^r^+An error occurred while deploying project:^:\n^R${message}^:\n`;
@@ -154,13 +166,12 @@ const checkIntunedProjectDeployStatus = async (workspaceId, projectName, apiKey)
154
166
  };
155
167
  };
156
168
  {}
157
- async function handleFirstRunExperience() {
169
+ async function promptFirstRunExperience(settings) {
158
170
  let testAuthSessionInput = undefined;
159
- const settings = await (0, _helpers.loadIntunedJson)();
160
171
  const shouldPromptForTestAuthSession = settings.authSessions.enabled && settings.authSessions.type === "API";
161
172
  let shouldPromptForDefaultJob = true;
162
173
  if (shouldPromptForTestAuthSession) {
163
- testAuthSessionInput = await getFirstRunExperienceTestAuthSessionParameters({
174
+ testAuthSessionInput = await promptFirstRunExperienceTestAuthSessionParameters({
164
175
  shouldPromptForDefaultJob
165
176
  });
166
177
  if (!testAuthSessionInput) {
@@ -169,12 +180,12 @@ async function handleFirstRunExperience() {
169
180
  }
170
181
  return {
171
182
  testAuthSessionInput,
172
- defaultJobInput: shouldPromptForDefaultJob ? await getFirstRunExperienceDefaultJobParameters({
183
+ defaultJobInput: shouldPromptForDefaultJob ? await promptFirstRunExperienceDefaultJobParameters({
173
184
  defaultJobInput: settings["metadata"].defaultJobInput
174
185
  }) : undefined
175
186
  };
176
187
  }
177
- async function getFirstRunExperienceTestAuthSessionParameters({
188
+ async function promptFirstRunExperienceTestAuthSessionParameters({
178
189
  shouldPromptForDefaultJob
179
190
  }) {
180
191
  const authSessionsDirectoryPath = _path.default.join(process.cwd(), _constants2.AUTH_SESSIONS_INSTANCES_FOLDER_NAME);
@@ -184,33 +195,56 @@ async function getFirstRunExperienceTestAuthSessionParameters({
184
195
  metadata
185
196
  } = await (0, _helpers.loadAuthSessionInstance)(authSessionId);
186
197
  if (metadata.authSessionInput) {
187
- const message = shouldPromptForDefaultJob ? "^+Create a test auth session using ^:^+%s^:^+'s parameters?^ :^/(required for creating default job)^:" : "^+Create a test auth session using ^:^+%s^:^+'s parameters?^:";
188
- (0, _terminal.terminal)(message, authSessionId);
189
- const answer = await _terminal.terminal.yesOrNo({
190
- yes: ["y", "ENTER"],
191
- no: ["n"],
192
- echoYes: " ^g^+Yes^:",
193
- echoNo: " ^r^+No^:"
194
- }).promise;
195
- (0, _terminal.terminal)("\n");
196
- if (answer) {
198
+ const message = shouldPromptForDefaultJob ? `Create a test auth session using ${authSessionId} parameters? (required for creating default job)` : `Create a test auth session using ${authSessionId} parameters?`;
199
+ const {
200
+ value
201
+ } = await (0, _prompts.default)({
202
+ type: "confirm",
203
+ name: "value",
204
+ message,
205
+ initial: true
206
+ });
207
+ if (value) {
197
208
  return metadata.authSessionInput;
198
209
  }
199
210
  }
200
211
  }
201
212
  }
202
- async function getFirstRunExperienceDefaultJobParameters({
213
+ async function promptFirstRunExperienceDefaultJobParameters({
203
214
  defaultJobInput
204
215
  }) {
205
- (0, _terminal.terminal)("\n^+Create a default job?^:");
206
- const answer = await _terminal.terminal.yesOrNo({
207
- yes: ["y", "ENTER"],
208
- no: ["n"],
209
- echoYes: " ^g^+Yes^:",
210
- echoNo: " ^r^+No^:"
211
- }).promise;
212
- (0, _terminal.terminal)("\n");
213
- if (answer) {
216
+ const {
217
+ value
218
+ } = await (0, _prompts.default)({
219
+ type: "confirm",
220
+ name: "value",
221
+ message: `Create a default job with sample parameters?`,
222
+ initial: true
223
+ });
224
+ if (value) {
214
225
  return defaultJobInput;
215
226
  }
227
+ }
228
+ async function getDefaultJobExists({
229
+ baseUrl,
230
+ workspaceId,
231
+ projectName,
232
+ apiKey
233
+ }) {
234
+ const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/${projectName}/jobs/default`;
235
+ const headers = {
236
+ [_constants2.API_KEY_HEADER_NAME]: apiKey,
237
+ "Content-Type": "application/json"
238
+ };
239
+ const response = await fetch(url, {
240
+ headers,
241
+ method: "GET"
242
+ });
243
+ if (response.status === 404) {
244
+ return false;
245
+ }
246
+ if (!response.ok) {
247
+ throw new _helpers.CLIError(`Error checking default job existence ${response.status}: ${await response.text()}`);
248
+ }
249
+ return true;
216
250
  }
@@ -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, {
@@ -1,30 +1,43 @@
1
1
  import { z } from "zod";
2
- export declare const intunedJsonSchema: z.ZodObject<{
3
- authSessions: z.ZodUnion<[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<{
4
13
  enabled: z.ZodLiteral<false>;
5
14
  }, "strip", z.ZodTypeAny, {
6
15
  enabled: false;
7
16
  }, {
8
17
  enabled: false;
9
- }>, z.ZodObject<{
10
- enabled: z.ZodLiteral<true>;
11
- type: z.ZodEnum<["MANUAL", "API"]>;
12
- startUrl: z.ZodOptional<z.ZodString>;
13
- finishUrl: z.ZodOptional<z.ZodString>;
18
+ }>;
19
+ apiAccess: z.ZodObject<{
20
+ enabled: z.ZodLiteral<false>;
14
21
  }, "strip", z.ZodTypeAny, {
15
- type: "API" | "MANUAL";
16
- enabled: true;
17
- startUrl?: string | undefined;
18
- finishUrl?: string | undefined;
22
+ enabled: false;
19
23
  }, {
20
- type: "API" | "MANUAL";
21
- enabled: true;
22
- startUrl?: string | undefined;
23
- finishUrl?: string | undefined;
24
- }>]>;
25
- projectName: z.ZodOptional<z.ZodString>;
26
- workspaceId: z.ZodOptional<z.ZodString>;
27
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
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<{
28
41
  authSessions: z.ZodUnion<[z.ZodObject<{
29
42
  enabled: z.ZodLiteral<false>;
30
43
  }, "strip", z.ZodTypeAny, {
@@ -47,62 +60,65 @@ export declare const intunedJsonSchema: z.ZodObject<{
47
60
  startUrl?: string | undefined;
48
61
  finishUrl?: string | undefined;
49
62
  }>]>;
50
- projectName: z.ZodOptional<z.ZodString>;
51
- workspaceId: z.ZodOptional<z.ZodString>;
52
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
53
- authSessions: z.ZodUnion<[z.ZodObject<{
54
- enabled: z.ZodLiteral<false>;
63
+ apiAccess: z.ZodObject<{
64
+ enabled: z.ZodLiteral<true>;
55
65
  }, "strip", z.ZodTypeAny, {
56
- enabled: false;
66
+ enabled: true;
57
67
  }, {
68
+ enabled: true;
69
+ }>;
70
+ }, "strip", z.ZodTypeAny, {
71
+ authSessions: {
58
72
  enabled: false;
59
- }>, z.ZodObject<{
60
- enabled: z.ZodLiteral<true>;
61
- type: z.ZodEnum<["MANUAL", "API"]>;
62
- startUrl: z.ZodOptional<z.ZodString>;
63
- finishUrl: z.ZodOptional<z.ZodString>;
64
- }, "strip", z.ZodTypeAny, {
73
+ } | {
65
74
  type: "API" | "MANUAL";
66
75
  enabled: true;
67
76
  startUrl?: string | undefined;
68
77
  finishUrl?: string | undefined;
69
- }, {
78
+ };
79
+ apiAccess: {
80
+ enabled: true;
81
+ };
82
+ }, {
83
+ authSessions: {
84
+ enabled: false;
85
+ } | {
70
86
  type: "API" | "MANUAL";
71
87
  enabled: true;
72
88
  startUrl?: string | undefined;
73
89
  finishUrl?: string | undefined;
74
- }>]>;
75
- projectName: z.ZodOptional<z.ZodString>;
76
- workspaceId: z.ZodOptional<z.ZodString>;
77
- }, z.ZodTypeAny, "passthrough">>;
90
+ };
91
+ apiAccess: {
92
+ enabled: true;
93
+ };
94
+ }>]>>;
78
95
  export type IntunedJson = z.infer<typeof intunedJsonSchema>;
79
96
  export declare const intunedSettingsFileNames: readonly ["Intuned.json", "Intuned.jsonc", "Intuned.yaml", "Intuned.yml", "Intuned.toml"];
80
- export declare function loadIntunedJson(): Promise<z.objectOutputType<{
81
- authSessions: z.ZodUnion<[z.ZodObject<{
82
- enabled: z.ZodLiteral<false>;
83
- }, "strip", z.ZodTypeAny, {
97
+ export declare function loadIntunedJson(): Promise<{
98
+ projectName?: string | undefined;
99
+ workspaceId?: string | undefined;
100
+ } & {
101
+ [k: string]: unknown;
102
+ } & ({
103
+ authSessions: {
84
104
  enabled: false;
85
- }, {
105
+ };
106
+ apiAccess: {
86
107
  enabled: false;
87
- }>, z.ZodObject<{
88
- enabled: z.ZodLiteral<true>;
89
- type: z.ZodEnum<["MANUAL", "API"]>;
90
- startUrl: z.ZodOptional<z.ZodString>;
91
- finishUrl: z.ZodOptional<z.ZodString>;
92
- }, "strip", z.ZodTypeAny, {
108
+ };
109
+ } | {
110
+ authSessions: {
111
+ enabled: false;
112
+ } | {
93
113
  type: "API" | "MANUAL";
94
114
  enabled: true;
95
115
  startUrl?: string | undefined;
96
116
  finishUrl?: string | undefined;
97
- }, {
98
- type: "API" | "MANUAL";
117
+ };
118
+ apiAccess: {
99
119
  enabled: true;
100
- startUrl?: string | undefined;
101
- finishUrl?: string | undefined;
102
- }>]>;
103
- projectName: z.ZodOptional<z.ZodString>;
104
- workspaceId: z.ZodOptional<z.ZodString>;
105
- }, z.ZodTypeAny, "passthrough">>;
120
+ };
121
+ })>;
106
122
  export declare function getIntunedSettingsFile(): Promise<{
107
123
  name: typeof intunedSettingsFileNames[number];
108
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
- }).passthrough();
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.6",
3
+ "version": "1.3.8-deploy.8",
4
4
  "description": "Intuned runtime",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -83,6 +83,7 @@
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",
@@ -108,6 +109,7 @@
108
109
  "@types/jsdom": "^21.1.1",
109
110
  "@types/ms": "^2.1.0",
110
111
  "@types/promptly": "^3.0.4",
112
+ "@types/prompts": "^2.4.9",
111
113
  "@types/terminal-kit": "^2.5.7",
112
114
  "@types/wait-on": "^5.3.4",
113
115
  "@typescript-eslint/eslint-plugin": "^5.47.1",