@intuned/runtime-dev 1.0.4-refactor.0 → 1.0.4-remove-playwright.1

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.
@@ -22,7 +22,13 @@ export async function createAuthSession({
22
22
  }) {
23
23
  const isAuthSessionEnabled = (await fs.readJSON("./Intuned.json"))
24
24
  .authSessions?.enabled;
25
-
25
+ return {
26
+ status: 400,
27
+ body: {
28
+ error: "its working",
29
+ message: "its working",
30
+ },
31
+ };
26
32
  if (!isAuthSessionEnabled) {
27
33
  return {
28
34
  status: 400,
@@ -15,6 +15,7 @@ var _unixSocket = require("../common/utils/unixSocket");
15
15
  var _promises = require("timers/promises");
16
16
  var _jwtTokenManager = require("../../common/jwtTokenManager");
17
17
  var _formatZodError = require("../../common/formatZodError");
18
+ var _stream = require("stream");
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 && Object.prototype.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(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -60,133 +61,116 @@ function runAutomationCLI(importFunction) {
60
61
  let generator = null;
61
62
  const abortController = new AbortController();
62
63
  client.on("error", err => {
63
- var _generator;
64
- void ((_generator = generator) === null || _generator === void 0 ? void 0 : _generator.throw(err).catch(() => undefined));
64
+ var _generator2;
65
+ void ((_generator2 = generator) === null || _generator2 === void 0 ? void 0 : _generator2.throw(err).catch(() => undefined));
65
66
  });
66
67
  process.on("SIGINT", () => {
67
- var _generator2;
68
- void ((_generator2 = generator) === null || _generator2 === void 0 ? void 0 : _generator2.throw(new Error("Interrupted")).catch(() => undefined));
68
+ var _generator3;
69
+ void ((_generator3 = generator) === null || _generator3 === void 0 ? void 0 : _generator3.throw(new Error("Interrupted")).catch(() => undefined));
69
70
  client.end();
70
71
  process.exit(1);
71
72
  });
72
73
  process.on("SIGTERM", () => {
73
- var _generator3;
74
- void ((_generator3 = generator) === null || _generator3 === void 0 ? void 0 : _generator3.throw(new Error("Interrupted")).catch(() => undefined));
74
+ var _generator4;
75
+ void ((_generator4 = generator) === null || _generator4 === void 0 ? void 0 : _generator4.throw(new Error("Interrupted")).catch(() => undefined));
75
76
  client.end();
76
77
  process.exit(1);
77
78
  });
78
79
  const jsonUnixSocket = new _unixSocket.JSONUnixSocket(client);
79
- const messagesGenerator = jsonUnixSocket.receiveJSON();
80
- async function receiveMessages() {
81
- const data = await messagesGenerator.next();
82
- if (data.done) {
83
- return;
84
- }
85
- const inputParseResult = inputSchema.safeParse(data.value);
86
- if (!inputParseResult.success) {
87
- console.error("Validation error:", (0, _formatZodError.formatZodError)(inputParseResult.error));
88
- return {
89
- type: "error",
90
- error: new _runApi.InternalInvalidInputError("Invalid input", (0, _formatZodError.formatZodError)(inputParseResult.error))
91
- };
92
- }
93
- const input = inputParseResult.data;
94
- return input;
95
- }
96
- let resultPromise = null;
97
- async function handleMessage(input) {
98
- if (input.type === "abort") {
99
- abortController.abort();
100
- return;
101
- }
102
- if (input.type === "tokenUpdate") {
103
- _jwtTokenManager.backendFunctionsTokenManager.token = input.parameters.functionsToken;
104
- return;
105
- }
106
- if (input.type === "start") {
107
- generator = (0, _runApi.runApiGenerator)({
108
- ...input.parameters,
109
- abortSignal: abortController.signal,
110
- importFunction
111
- });
112
- context = {
113
- extendedPayloads: [],
114
- runEnvironment: input.parameters.runOptions.environment === "standalone" ? _enums.RunEnvironment.DEPLOYED : _enums.RunEnvironment.IDE,
115
- timeoutInfo: {
116
- extendTimeoutCallback: async () => {
117
- if (Date.now() - timeoutTimestamp < throttleTime) return;
118
- timeoutTimestamp = Date.now();
119
- jsonUnixSocket.sendJSON({
120
- type: "extend"
121
- });
122
- }
123
- },
124
- ...(input.parameters.context ?? {}),
125
- proxy: getProxyUrlFromRunOptions(input.parameters.runOptions)
126
- };
127
- _jwtTokenManager.backendFunctionsTokenManager.token = input.parameters.functionsToken;
128
- resultPromise = (0, _asyncLocalStorage.runWithContext)(context, async () => {
129
- return await generator.next();
130
- });
131
- }
132
- if (input.type === "next") {
133
- if (!generator) {
134
- throw new Error("generator not started");
135
- }
136
- resultPromise = (0, _asyncLocalStorage.runWithContext)(context, async () => {
137
- return await generator.next(input.parameters.value);
80
+ async function runGeneratorAndSendResult(next) {
81
+ const _generator = generator;
82
+ if (_generator == null) return {
83
+ done: true
84
+ };
85
+ const result = await (0, _asyncLocalStorage.runWithContext)(context, () => _generator.next(next));
86
+ if (result.done) {
87
+ const resultToSend = result.value.isOk() ? result.value.value : result.value.error.json;
88
+ const success = result.value.isOk();
89
+ jsonUnixSocket.sendJSON({
90
+ type: "done",
91
+ result: resultToSend,
92
+ success
138
93
  });
139
- }
140
- }
141
- async function handleResult(generatorResult) {
142
- if (!generatorResult.done) {
94
+ } else {
143
95
  jsonUnixSocket.sendJSON({
144
96
  type: "yield",
145
- result: generatorResult.value
97
+ result: result.value
146
98
  });
147
- return;
148
99
  }
149
- const result = generatorResult.value;
150
- const success = result.isOk();
151
- const resultToSend = success ? result.value : result.error.json;
152
- jsonUnixSocket.sendJSON({
153
- type: "done",
154
- result: resultToSend,
155
- success
156
- });
100
+ return {
101
+ done: result.done ?? false
102
+ };
157
103
  }
158
- let receiveMessagesPromise = receiveMessages();
159
- while (true) {
160
- const messageOrResult = await Promise.race([receiveMessagesPromise.then(message => ({
161
- type: "message",
162
- message
163
- })), ...(resultPromise ? [resultPromise.then(result => ({
164
- type: "result",
165
- result
166
- }))] : [])]);
167
- if (messageOrResult.type === "message") {
168
- const {
169
- message
170
- } = messageOrResult;
171
- if (message === undefined) {
172
- break;
173
- }
174
- if (message.type === "error") {
104
+ const stream = new _stream.PassThrough({
105
+ objectMode: true
106
+ });
107
+ async function messagesLoop() {
108
+ for await (const data of jsonUnixSocket.receiveJSON()) {
109
+ const inputParseResult = inputSchema.safeParse(data);
110
+ if (!inputParseResult.success) {
111
+ console.error("Validation error:", (0, _formatZodError.formatZodError)(inputParseResult.error));
175
112
  jsonUnixSocket.sendJSON({
176
113
  type: "done",
177
- result: message.error.json,
114
+ result: new _runApi.InternalInvalidInputError("Invalid input", (0, _formatZodError.formatZodError)(inputParseResult.error)).json,
178
115
  success: false
179
116
  });
180
117
  break;
181
118
  }
182
- await handleMessage(message);
183
- receiveMessagesPromise = receiveMessages();
184
- continue;
119
+ const input = inputParseResult.data;
120
+ if (input.type === "abort") {
121
+ abortController.abort();
122
+ break;
123
+ }
124
+ if (input.type === "tokenUpdate") {
125
+ _jwtTokenManager.backendFunctionsTokenManager.token = input.parameters.functionsToken;
126
+ continue;
127
+ }
128
+ if (input.type === "start") {
129
+ _jwtTokenManager.backendFunctionsTokenManager.token = input.parameters.functionsToken;
130
+ generator = (0, _runApi.runApiGenerator)({
131
+ ...input.parameters,
132
+ abortSignal: abortController.signal,
133
+ importFunction
134
+ });
135
+ context = {
136
+ extendedPayloads: [],
137
+ runEnvironment: input.parameters.runOptions.environment === "standalone" ? _enums.RunEnvironment.DEPLOYED : _enums.RunEnvironment.IDE,
138
+ timeoutInfo: {
139
+ extendTimeoutCallback: async () => {
140
+ if (Date.now() - timeoutTimestamp < throttleTime) return;
141
+ timeoutTimestamp = Date.now();
142
+ jsonUnixSocket.sendJSON({
143
+ type: "extend"
144
+ });
145
+ }
146
+ },
147
+ ...(input.parameters.context ?? {}),
148
+ proxy: getProxyUrlFromRunOptions(input.parameters.runOptions)
149
+ };
150
+ stream.write({});
151
+ continue;
152
+ }
153
+ if (input.type === "next") {
154
+ if (!generator) {
155
+ throw new Error("generator not started");
156
+ }
157
+ stream.write({
158
+ value: input.parameters.value
159
+ });
160
+ continue;
161
+ }
185
162
  }
163
+ stream.end();
164
+ client.end();
165
+ }
166
+ void messagesLoop();
167
+ for await (const {
168
+ value
169
+ } of stream) {
186
170
  const {
187
- result
188
- } = messageOrResult;
189
- await handleResult(result);
171
+ done
172
+ } = await runGeneratorAndSendResult(value);
173
+ if (done) break;
190
174
  }
191
175
  if (!client.closed) {
192
176
  client.end();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intuned/runtime-dev",
3
- "version": "1.0.4-refactor.0",
3
+ "version": "1.0.4-remove-playwright.1",
4
4
  "description": "Intuned runtime",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
package/WebTemplate.zip DELETED
Binary file
@@ -1 +0,0 @@
1
- export declare function runAutomationCLI(importFunction?: (path: string) => Promise<any>): void;
@@ -1,210 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.runAutomationCLI = runAutomationCLI;
7
- var _commander = require("commander");
8
- var _dotenv = _interopRequireDefault(require("dotenv"));
9
- var _asyncLocalStorage = require("../../common/asyncLocalStorage");
10
- var net = _interopRequireWildcard(require("net"));
11
- var _zod = _interopRequireDefault(require("zod"));
12
- var _runApi = require("../../common/runApi");
13
- var _enums = require("../../runtime/enums");
14
- var _unixSocket = require("../common/utils/unixSocket");
15
- var _promises = require("timers/promises");
16
- var _jwtTokenManager = require("../../common/jwtTokenManager");
17
- var _formatZodError = require("../../common/formatZodError");
18
- 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
- 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 && Object.prototype.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
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
- const startRunApiSchema = _zod.default.object({
22
- type: _zod.default.literal("start"),
23
- parameters: _runApi.runApiParametersSchema.extend({
24
- retrieveSession: _zod.default.boolean(),
25
- functionsToken: _zod.default.string().optional(),
26
- context: _zod.default.object({
27
- jobId: _zod.default.string().optional(),
28
- jobRunId: _zod.default.string().optional(),
29
- runId: _zod.default.string().optional(),
30
- queueId: _zod.default.string().optional()
31
- }).optional()
32
- })
33
- });
34
- const nextRunApiSchema = _zod.default.object({
35
- type: _zod.default.literal("next"),
36
- parameters: _zod.default.object({
37
- value: _zod.default.string()
38
- })
39
- });
40
- const abortRunApiSchema = _zod.default.object({
41
- type: _zod.default.literal("abort"),
42
- parameters: _zod.default.object({}).optional()
43
- });
44
- const tokenUpdateSchema = _zod.default.object({
45
- type: _zod.default.literal("tokenUpdate"),
46
- parameters: _zod.default.object({
47
- functionsToken: _zod.default.string()
48
- })
49
- });
50
- const inputSchema = _zod.default.union([startRunApiSchema, nextRunApiSchema, abortRunApiSchema, tokenUpdateSchema]);
51
- _dotenv.default.config({
52
- path: `.env`
53
- });
54
- function runAutomationCLI(importFunction) {
55
- _commander.program.description("run user automation and communicate using unix socket").argument("<socket-path>", "path to unix socket").action(async socketPath => {
56
- let context;
57
- const throttleTime = 60 * 1000;
58
- let timeoutTimestamp = Date.now();
59
- const client = net.createConnection(socketPath);
60
- let generator = null;
61
- const abortController = new AbortController();
62
- client.on("error", err => {
63
- var _generator;
64
- void ((_generator = generator) === null || _generator === void 0 ? void 0 : _generator.throw(err).catch(() => undefined));
65
- });
66
- process.on("SIGINT", () => {
67
- var _generator2;
68
- void ((_generator2 = generator) === null || _generator2 === void 0 ? void 0 : _generator2.throw(new Error("Interrupted")).catch(() => undefined));
69
- client.end();
70
- process.exit(1);
71
- });
72
- process.on("SIGTERM", () => {
73
- var _generator3;
74
- void ((_generator3 = generator) === null || _generator3 === void 0 ? void 0 : _generator3.throw(new Error("Interrupted")).catch(() => undefined));
75
- client.end();
76
- process.exit(1);
77
- });
78
- const jsonUnixSocket = new _unixSocket.JSONUnixSocket(client);
79
- const messagesGenerator = jsonUnixSocket.receiveJSON();
80
- async function receiveMessages() {
81
- const data = await messagesGenerator.next();
82
- if (data.done) {
83
- return;
84
- }
85
- const inputParseResult = inputSchema.safeParse(data.value);
86
- if (!inputParseResult.success) {
87
- console.error("Validation error:", (0, _formatZodError.formatZodError)(inputParseResult.error));
88
- return {
89
- type: "error",
90
- error: new _runApi.InternalInvalidInputError("Invalid input", (0, _formatZodError.formatZodError)(inputParseResult.error))
91
- };
92
- }
93
- const input = inputParseResult.data;
94
- return input;
95
- }
96
- let resultPromise = null;
97
- async function handleMessage(input) {
98
- if (input.type === "abort") {
99
- abortController.abort();
100
- return "aborted";
101
- }
102
- if (input.type === "tokenUpdate") {
103
- _jwtTokenManager.backendFunctionsTokenManager.token = input.parameters.functionsToken;
104
- return;
105
- }
106
- if (input.type === "start") {
107
- generator = (0, _runApi.runApiGenerator)({
108
- ...input.parameters,
109
- abortSignal: abortController.signal,
110
- importFunction
111
- });
112
- context = {
113
- extendedPayloads: [],
114
- runEnvironment: input.parameters.runOptions.environment === "standalone" ? _enums.RunEnvironment.DEPLOYED : _enums.RunEnvironment.IDE,
115
- timeoutInfo: {
116
- extendTimeoutCallback: async () => {
117
- if (Date.now() - timeoutTimestamp < throttleTime) return;
118
- timeoutTimestamp = Date.now();
119
- jsonUnixSocket.sendJSON({
120
- type: "extend"
121
- });
122
- }
123
- },
124
- ...(input.parameters.context ?? {}),
125
- proxy: getProxyUrlFromRunOptions(input.parameters.runOptions)
126
- };
127
- _jwtTokenManager.backendFunctionsTokenManager.token = input.parameters.functionsToken;
128
- resultPromise = (0, _asyncLocalStorage.runWithContext)(context, async () => {
129
- return await generator.next();
130
- });
131
- }
132
- if (input.type === "next") {
133
- if (!generator) {
134
- throw new Error("generator not started");
135
- }
136
- resultPromise = (0, _asyncLocalStorage.runWithContext)(context, async () => {
137
- return await generator.next(input.parameters.value);
138
- });
139
- }
140
- }
141
- async function handleResult(generatorResult) {
142
- if (!generatorResult.done) {
143
- jsonUnixSocket.sendJSON({
144
- type: "yield",
145
- result: generatorResult.value
146
- });
147
- return;
148
- }
149
- const result = generatorResult.value;
150
- const success = result.isOk();
151
- const resultToSend = success ? result.value : result.error.json;
152
- jsonUnixSocket.sendJSON({
153
- type: "done",
154
- result: resultToSend,
155
- success
156
- });
157
- }
158
- let receiveMessagesPromise = receiveMessages();
159
- while (true) {
160
- const messageOrResult = await Promise.race([receiveMessagesPromise.then(message => ({
161
- type: "message",
162
- message
163
- })), ...(resultPromise ? [resultPromise.then(result => ({
164
- type: "result",
165
- result
166
- }))] : [])]);
167
- if (messageOrResult.type === "message") {
168
- const {
169
- message
170
- } = messageOrResult;
171
- if (message === undefined) {
172
- break;
173
- }
174
- if (message.type === "error") {
175
- jsonUnixSocket.sendJSON({
176
- type: "done",
177
- result: message.error.json,
178
- success: false
179
- });
180
- break;
181
- }
182
- await handleMessage(message);
183
- receiveMessagesPromise = receiveMessages();
184
- continue;
185
- }
186
- const {
187
- result
188
- } = messageOrResult;
189
- await handleResult(result);
190
- }
191
- if (!client.closed) {
192
- client.end();
193
- await Promise.race([new Promise(resolve => client.once("close", resolve)), new Promise(resolve => client.once("error", resolve)), (0, _promises.setTimeout)(3000)]);
194
- }
195
- process.exit(0);
196
- });
197
- _commander.program.parse(process.argv);
198
- }
199
- function getProxyUrlFromRunOptions(runOptions) {
200
- if ((runOptions === null || runOptions === void 0 ? void 0 : runOptions.environment) !== "standalone") return undefined;
201
- const proxy = runOptions.proxy;
202
- if (!proxy) return undefined;
203
- const url = new URL(proxy.server);
204
- url.username = proxy.username;
205
- url.password = proxy.password;
206
- return url.toString();
207
- }
208
- if (require.main === module) {
209
- runAutomationCLI();
210
- }