@airtop/sdk 0.1.5 → 0.1.7

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.
Files changed (199) hide show
  1. package/Client.d.ts +3 -3
  2. package/Client.js +9 -9
  3. package/README.md +6 -6
  4. package/api/resources/index.d.ts +3 -3
  5. package/api/resources/index.js +4 -4
  6. package/api/resources/profiles/client/Client.js +4 -4
  7. package/api/resources/sessions/client/Client.js +10 -10
  8. package/api/resources/windows/client/Client.d.ts +37 -3
  9. package/api/resources/windows/client/Client.js +206 -19
  10. package/api/resources/windows/client/requests/CreateWindowInputV1Body.d.ts +1 -1
  11. package/api/resources/windows/client/requests/SessionClickHandlerRequestBody.d.ts +25 -0
  12. package/api/resources/windows/client/requests/SessionHoverHandlerRequestBody.d.ts +23 -0
  13. package/api/resources/windows/client/requests/SessionTypeHandlerRequestBody.d.ts +29 -0
  14. package/api/resources/windows/client/requests/WindowLoadUrlV1Body.d.ts +1 -1
  15. package/api/resources/windows/client/requests/index.d.ts +3 -0
  16. package/api/resources/windows/types/CreateWindowInputV1BodyWaitUntil.d.ts +3 -2
  17. package/api/resources/windows/types/CreateWindowInputV1BodyWaitUntil.js +1 -0
  18. package/api/resources/windows/types/WindowLoadUrlV1BodyWaitUntil.d.ts +3 -2
  19. package/api/resources/windows/types/WindowLoadUrlV1BodyWaitUntil.js +1 -0
  20. package/api/types/ClickConfig.d.ts +8 -0
  21. package/api/types/CustomProxy.d.ts +1 -1
  22. package/api/types/Issue.d.ts +2 -0
  23. package/{dist/api/types/EmptyResponseJson.d.ts → api/types/OperationOutcome.d.ts} +1 -1
  24. package/api/types/{EmptyResponse.d.ts → OperationOutcomeResponse.d.ts} +3 -3
  25. package/api/types/PageQueryConfig.d.ts +3 -0
  26. package/api/types/SessionConfigV1Proxy.d.ts +4 -1
  27. package/api/types/SummaryConfig.d.ts +2 -0
  28. package/api/types/VisualAnalysisConfig.d.ts +12 -0
  29. package/api/types/VisualAnalysisConfig.js +5 -0
  30. package/api/types/VisualAnalysisConfigPartitionDirection.d.ts +12 -0
  31. package/api/types/VisualAnalysisConfigPartitionDirection.js +11 -0
  32. package/api/types/VisualAnalysisConfigScope.d.ts +11 -0
  33. package/api/types/VisualAnalysisConfigScope.js +10 -0
  34. package/api/types/index.d.ts +6 -4
  35. package/api/types/index.js +6 -4
  36. package/dist/Client.d.ts +3 -3
  37. package/dist/Client.js +9 -9
  38. package/dist/api/resources/index.d.ts +3 -3
  39. package/dist/api/resources/index.js +4 -4
  40. package/dist/api/resources/profiles/client/Client.js +4 -4
  41. package/dist/api/resources/sessions/client/Client.js +10 -10
  42. package/dist/api/resources/windows/client/Client.d.ts +37 -3
  43. package/dist/api/resources/windows/client/Client.js +206 -19
  44. package/dist/api/resources/windows/client/requests/CreateWindowInputV1Body.d.ts +1 -1
  45. package/dist/api/resources/windows/client/requests/SessionClickHandlerRequestBody.d.ts +25 -0
  46. package/dist/api/resources/windows/client/requests/SessionClickHandlerRequestBody.js +5 -0
  47. package/dist/api/resources/windows/client/requests/SessionHoverHandlerRequestBody.d.ts +23 -0
  48. package/dist/api/resources/windows/client/requests/SessionHoverHandlerRequestBody.js +5 -0
  49. package/dist/api/resources/windows/client/requests/SessionTypeHandlerRequestBody.d.ts +29 -0
  50. package/dist/api/resources/windows/client/requests/SessionTypeHandlerRequestBody.js +5 -0
  51. package/dist/api/resources/windows/client/requests/WindowLoadUrlV1Body.d.ts +1 -1
  52. package/dist/api/resources/windows/client/requests/index.d.ts +3 -0
  53. package/dist/api/resources/windows/types/CreateWindowInputV1BodyWaitUntil.d.ts +3 -2
  54. package/dist/api/resources/windows/types/CreateWindowInputV1BodyWaitUntil.js +1 -0
  55. package/dist/api/resources/windows/types/WindowLoadUrlV1BodyWaitUntil.d.ts +3 -2
  56. package/dist/api/resources/windows/types/WindowLoadUrlV1BodyWaitUntil.js +1 -0
  57. package/dist/api/types/ClickConfig.d.ts +8 -0
  58. package/dist/api/types/ClickConfig.js +5 -0
  59. package/dist/api/types/CustomProxy.d.ts +1 -1
  60. package/dist/api/types/Issue.d.ts +2 -0
  61. package/{api/types/EmptyResponseJson.d.ts → dist/api/types/OperationOutcome.d.ts} +1 -1
  62. package/dist/api/types/OperationOutcome.js +5 -0
  63. package/dist/api/types/{EmptyResponse.d.ts → OperationOutcomeResponse.d.ts} +3 -3
  64. package/dist/api/types/OperationOutcomeResponse.js +5 -0
  65. package/dist/api/types/PageQueryConfig.d.ts +3 -0
  66. package/dist/api/types/SessionConfigV1Proxy.d.ts +4 -1
  67. package/dist/api/types/SummaryConfig.d.ts +2 -0
  68. package/dist/api/types/VisualAnalysisConfig.d.ts +12 -0
  69. package/dist/api/types/VisualAnalysisConfig.js +5 -0
  70. package/dist/api/types/VisualAnalysisConfigPartitionDirection.d.ts +12 -0
  71. package/dist/api/types/VisualAnalysisConfigPartitionDirection.js +11 -0
  72. package/dist/api/types/VisualAnalysisConfigScope.d.ts +11 -0
  73. package/dist/api/types/VisualAnalysisConfigScope.js +10 -0
  74. package/dist/api/types/index.d.ts +6 -4
  75. package/dist/api/types/index.js +6 -4
  76. package/dist/index.d.ts +1 -0
  77. package/dist/index.js +4 -0
  78. package/dist/serialization/resources/index.d.ts +3 -3
  79. package/dist/serialization/resources/index.js +4 -4
  80. package/dist/serialization/resources/windows/client/requests/SessionClickHandlerRequestBody.d.ts +17 -0
  81. package/{serialization/types/EnvelopeStatusDefaultMeta.js → dist/serialization/resources/windows/client/requests/SessionClickHandlerRequestBody.js} +9 -6
  82. package/dist/serialization/resources/windows/client/requests/SessionHoverHandlerRequestBody.d.ts +17 -0
  83. package/dist/serialization/resources/windows/client/requests/SessionHoverHandlerRequestBody.js +38 -0
  84. package/dist/serialization/resources/windows/client/requests/SessionTypeHandlerRequestBody.d.ts +19 -0
  85. package/dist/serialization/resources/windows/client/requests/SessionTypeHandlerRequestBody.js +40 -0
  86. package/dist/serialization/resources/windows/client/requests/index.d.ts +3 -0
  87. package/dist/serialization/resources/windows/client/requests/index.js +7 -1
  88. package/dist/serialization/resources/windows/types/CreateWindowInputV1BodyWaitUntil.d.ts +1 -1
  89. package/dist/serialization/resources/windows/types/CreateWindowInputV1BodyWaitUntil.js +1 -1
  90. package/dist/serialization/resources/windows/types/WindowLoadUrlV1BodyWaitUntil.d.ts +1 -1
  91. package/dist/serialization/resources/windows/types/WindowLoadUrlV1BodyWaitUntil.js +1 -1
  92. package/dist/serialization/types/ClickConfig.d.ts +13 -0
  93. package/dist/serialization/types/ClickConfig.js +34 -0
  94. package/dist/serialization/types/Issue.d.ts +1 -0
  95. package/dist/serialization/types/Issue.js +1 -0
  96. package/{serialization/types/EmptyResponseJson.d.ts → dist/serialization/types/OperationOutcome.d.ts} +2 -2
  97. package/{serialization/types/EmptyResponseJson.js → dist/serialization/types/OperationOutcome.js} +2 -2
  98. package/dist/serialization/types/OperationOutcomeResponse.d.ts +18 -0
  99. package/dist/serialization/types/{EmptyResponse.js → OperationOutcomeResponse.js} +6 -6
  100. package/dist/serialization/types/PageQueryConfig.d.ts +2 -0
  101. package/dist/serialization/types/PageQueryConfig.js +2 -0
  102. package/dist/serialization/types/SessionConfigV1Proxy.d.ts +1 -1
  103. package/dist/serialization/types/SessionConfigV1Proxy.js +5 -1
  104. package/dist/serialization/types/SummaryConfig.d.ts +2 -0
  105. package/dist/serialization/types/SummaryConfig.js +2 -0
  106. package/dist/serialization/types/VisualAnalysisConfig.d.ts +16 -0
  107. package/dist/serialization/types/{EnvelopeStatusDefaultMeta.js → VisualAnalysisConfig.js} +7 -5
  108. package/dist/serialization/types/VisualAnalysisConfigPartitionDirection.d.ts +10 -0
  109. package/dist/serialization/types/VisualAnalysisConfigPartitionDirection.js +31 -0
  110. package/dist/serialization/types/VisualAnalysisConfigScope.d.ts +10 -0
  111. package/dist/serialization/types/{EnvelopeStatusDefaultMetaStatus.js → VisualAnalysisConfigScope.js} +2 -2
  112. package/dist/serialization/types/index.d.ts +6 -4
  113. package/dist/serialization/types/index.js +6 -4
  114. package/dist/utils/batch-operate/SessionQueue.d.ts +46 -0
  115. package/dist/utils/batch-operate/SessionQueue.js +223 -0
  116. package/dist/utils/batch-operate/WindowQueue.d.ts +25 -0
  117. package/dist/utils/batch-operate/WindowQueue.js +201 -0
  118. package/dist/utils/batch-operate/batch-util.d.ts +3 -0
  119. package/dist/utils/batch-operate/batch-util.js +51 -0
  120. package/dist/utils/batch-operate/helpers.d.ts +2 -0
  121. package/dist/utils/batch-operate/helpers.js +19 -0
  122. package/dist/utils/batch-operate/types.d.ts +29 -0
  123. package/dist/utils/batch-operate/types.js +2 -0
  124. package/dist/utils/index.d.ts +2 -0
  125. package/dist/utils/index.js +18 -0
  126. package/dist/wrapper/AirtopClient.d.ts +3 -0
  127. package/dist/wrapper/AirtopClient.js +16 -0
  128. package/index.d.ts +1 -0
  129. package/index.js +4 -0
  130. package/package.json +3 -2
  131. package/reference.md +344 -148
  132. package/serialization/resources/index.d.ts +3 -3
  133. package/serialization/resources/index.js +4 -4
  134. package/serialization/resources/windows/client/requests/SessionClickHandlerRequestBody.d.ts +17 -0
  135. package/serialization/resources/windows/client/requests/SessionClickHandlerRequestBody.js +38 -0
  136. package/serialization/resources/windows/client/requests/SessionHoverHandlerRequestBody.d.ts +17 -0
  137. package/serialization/resources/windows/client/requests/SessionHoverHandlerRequestBody.js +38 -0
  138. package/serialization/resources/windows/client/requests/SessionTypeHandlerRequestBody.d.ts +19 -0
  139. package/serialization/resources/windows/client/requests/SessionTypeHandlerRequestBody.js +40 -0
  140. package/serialization/resources/windows/client/requests/index.d.ts +3 -0
  141. package/serialization/resources/windows/client/requests/index.js +7 -1
  142. package/serialization/resources/windows/types/CreateWindowInputV1BodyWaitUntil.d.ts +1 -1
  143. package/serialization/resources/windows/types/CreateWindowInputV1BodyWaitUntil.js +1 -1
  144. package/serialization/resources/windows/types/WindowLoadUrlV1BodyWaitUntil.d.ts +1 -1
  145. package/serialization/resources/windows/types/WindowLoadUrlV1BodyWaitUntil.js +1 -1
  146. package/serialization/types/ClickConfig.d.ts +13 -0
  147. package/serialization/types/ClickConfig.js +34 -0
  148. package/serialization/types/Issue.d.ts +1 -0
  149. package/serialization/types/Issue.js +1 -0
  150. package/{dist/serialization/types/EmptyResponseJson.d.ts → serialization/types/OperationOutcome.d.ts} +2 -2
  151. package/{dist/serialization/types/EmptyResponseJson.js → serialization/types/OperationOutcome.js} +2 -2
  152. package/serialization/types/OperationOutcomeResponse.d.ts +18 -0
  153. package/serialization/types/{EmptyResponse.js → OperationOutcomeResponse.js} +6 -6
  154. package/serialization/types/PageQueryConfig.d.ts +2 -0
  155. package/serialization/types/PageQueryConfig.js +2 -0
  156. package/serialization/types/SessionConfigV1Proxy.d.ts +1 -1
  157. package/serialization/types/SessionConfigV1Proxy.js +5 -1
  158. package/serialization/types/SummaryConfig.d.ts +2 -0
  159. package/serialization/types/SummaryConfig.js +2 -0
  160. package/serialization/types/VisualAnalysisConfig.d.ts +16 -0
  161. package/serialization/types/VisualAnalysisConfig.js +37 -0
  162. package/serialization/types/VisualAnalysisConfigPartitionDirection.d.ts +10 -0
  163. package/serialization/types/VisualAnalysisConfigPartitionDirection.js +31 -0
  164. package/serialization/types/VisualAnalysisConfigScope.d.ts +10 -0
  165. package/serialization/types/{EnvelopeStatusDefaultMetaStatus.js → VisualAnalysisConfigScope.js} +2 -2
  166. package/serialization/types/index.d.ts +6 -4
  167. package/serialization/types/index.js +6 -4
  168. package/utils/batch-operate/SessionQueue.d.ts +46 -0
  169. package/utils/batch-operate/SessionQueue.js +223 -0
  170. package/utils/batch-operate/WindowQueue.d.ts +25 -0
  171. package/utils/batch-operate/WindowQueue.js +201 -0
  172. package/utils/batch-operate/batch-util.d.ts +3 -0
  173. package/utils/batch-operate/batch-util.js +51 -0
  174. package/utils/batch-operate/helpers.d.ts +2 -0
  175. package/utils/batch-operate/helpers.js +19 -0
  176. package/utils/batch-operate/types.d.ts +29 -0
  177. package/utils/batch-operate/types.js +2 -0
  178. package/utils/index.d.ts +2 -0
  179. package/utils/index.js +18 -0
  180. package/wrapper/AirtopClient.d.ts +3 -0
  181. package/wrapper/AirtopClient.js +16 -0
  182. package/api/types/EnvelopeStatusDefaultMeta.d.ts +0 -8
  183. package/api/types/EnvelopeStatusDefaultMetaStatus.d.ts +0 -9
  184. package/api/types/EnvelopeStatusDefaultMetaStatus.js +0 -11
  185. package/dist/api/types/EnvelopeStatusDefaultMeta.d.ts +0 -8
  186. package/dist/api/types/EnvelopeStatusDefaultMetaStatus.d.ts +0 -9
  187. package/dist/api/types/EnvelopeStatusDefaultMetaStatus.js +0 -11
  188. package/dist/serialization/types/EmptyResponse.d.ts +0 -18
  189. package/dist/serialization/types/EnvelopeStatusDefaultMeta.d.ts +0 -14
  190. package/dist/serialization/types/EnvelopeStatusDefaultMetaStatus.d.ts +0 -10
  191. package/serialization/types/EmptyResponse.d.ts +0 -18
  192. package/serialization/types/EnvelopeStatusDefaultMeta.d.ts +0 -14
  193. package/serialization/types/EnvelopeStatusDefaultMetaStatus.d.ts +0 -10
  194. /package/api/{types/EmptyResponse.js → resources/windows/client/requests/SessionClickHandlerRequestBody.js} +0 -0
  195. /package/api/{types/EmptyResponseJson.js → resources/windows/client/requests/SessionHoverHandlerRequestBody.js} +0 -0
  196. /package/api/{types/EnvelopeStatusDefaultMeta.js → resources/windows/client/requests/SessionTypeHandlerRequestBody.js} +0 -0
  197. /package/{dist/api/types/EmptyResponse.js → api/types/ClickConfig.js} +0 -0
  198. /package/{dist/api/types/EmptyResponseJson.js → api/types/OperationOutcome.js} +0 -0
  199. /package/{dist/api/types/EnvelopeStatusDefaultMeta.js → api/types/OperationOutcomeResponse.js} +0 -0
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /**
3
+ * This file was auto-generated by Fern from our API Definition.
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.VisualAnalysisConfigPartitionDirection = void 0;
30
+ const core = __importStar(require("../../core"));
31
+ exports.VisualAnalysisConfigPartitionDirection = core.serialization.enum_(["vertical", "horizontal", "bidirectional"]);
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ import * as serializers from "../index";
5
+ import * as Airtop from "../../api/index";
6
+ import * as core from "../../core";
7
+ export declare const VisualAnalysisConfigScope: core.serialization.Schema<serializers.VisualAnalysisConfigScope.Raw, Airtop.VisualAnalysisConfigScope>;
8
+ export declare namespace VisualAnalysisConfigScope {
9
+ type Raw = "viewport" | "page";
10
+ }
@@ -26,6 +26,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
26
26
  return result;
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.EnvelopeStatusDefaultMetaStatus = void 0;
29
+ exports.VisualAnalysisConfigScope = void 0;
30
30
  const core = __importStar(require("../../core"));
31
- exports.EnvelopeStatusDefaultMetaStatus = core.serialization.enum_(["success", " failure", " timeout"]);
31
+ exports.VisualAnalysisConfigScope = core.serialization.enum_(["viewport", "page"]);
@@ -1,11 +1,8 @@
1
1
  export * from "./AiPromptResponse";
2
2
  export * from "./AiResponseEnvelope";
3
+ export * from "./ClickConfig";
3
4
  export * from "./ClientProvidedResponseMetadata";
4
- export * from "./EmptyResponse";
5
- export * from "./EmptyResponseJson";
6
5
  export * from "./EnvelopeDefaultMeta";
7
- export * from "./EnvelopeStatusDefaultMetaStatus";
8
- export * from "./EnvelopeStatusDefaultMeta";
9
6
  export * from "./ErrorDetail";
10
7
  export * from "./ErrorMessage";
11
8
  export * from "./ErrorModel";
@@ -16,6 +13,8 @@ export * from "./ExternalSessionAiResponseMetadataUsage";
16
13
  export * from "./ExternalSessionConfig";
17
14
  export * from "./ExternalSessionWithConnectionInfo";
18
15
  export * from "./Issue";
16
+ export * from "./OperationOutcome";
17
+ export * from "./OperationOutcomeResponse";
19
18
  export * from "./PageQueryConfig";
20
19
  export * from "./PageQueryExperimentalConfig";
21
20
  export * from "./Pagination";
@@ -37,6 +36,9 @@ export * from "./StatusMessageStatus";
37
36
  export * from "./StatusMessage";
38
37
  export * from "./SummaryConfig";
39
38
  export * from "./SummaryExperimentalConfig";
39
+ export * from "./VisualAnalysisConfigPartitionDirection";
40
+ export * from "./VisualAnalysisConfigScope";
41
+ export * from "./VisualAnalysisConfig";
40
42
  export * from "./Window";
41
43
  export * from "./WindowId";
42
44
  export * from "./WindowIdResponse";
@@ -16,12 +16,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./AiPromptResponse"), exports);
18
18
  __exportStar(require("./AiResponseEnvelope"), exports);
19
+ __exportStar(require("./ClickConfig"), exports);
19
20
  __exportStar(require("./ClientProvidedResponseMetadata"), exports);
20
- __exportStar(require("./EmptyResponse"), exports);
21
- __exportStar(require("./EmptyResponseJson"), exports);
22
21
  __exportStar(require("./EnvelopeDefaultMeta"), exports);
23
- __exportStar(require("./EnvelopeStatusDefaultMetaStatus"), exports);
24
- __exportStar(require("./EnvelopeStatusDefaultMeta"), exports);
25
22
  __exportStar(require("./ErrorDetail"), exports);
26
23
  __exportStar(require("./ErrorMessage"), exports);
27
24
  __exportStar(require("./ErrorModel"), exports);
@@ -32,6 +29,8 @@ __exportStar(require("./ExternalSessionAiResponseMetadataUsage"), exports);
32
29
  __exportStar(require("./ExternalSessionConfig"), exports);
33
30
  __exportStar(require("./ExternalSessionWithConnectionInfo"), exports);
34
31
  __exportStar(require("./Issue"), exports);
32
+ __exportStar(require("./OperationOutcome"), exports);
33
+ __exportStar(require("./OperationOutcomeResponse"), exports);
35
34
  __exportStar(require("./PageQueryConfig"), exports);
36
35
  __exportStar(require("./PageQueryExperimentalConfig"), exports);
37
36
  __exportStar(require("./Pagination"), exports);
@@ -53,6 +52,9 @@ __exportStar(require("./StatusMessageStatus"), exports);
53
52
  __exportStar(require("./StatusMessage"), exports);
54
53
  __exportStar(require("./SummaryConfig"), exports);
55
54
  __exportStar(require("./SummaryExperimentalConfig"), exports);
55
+ __exportStar(require("./VisualAnalysisConfigPartitionDirection"), exports);
56
+ __exportStar(require("./VisualAnalysisConfigScope"), exports);
57
+ __exportStar(require("./VisualAnalysisConfig"), exports);
56
58
  __exportStar(require("./Window"), exports);
57
59
  __exportStar(require("./WindowId"), exports);
58
60
  __exportStar(require("./WindowIdResponse"), exports);
@@ -0,0 +1,46 @@
1
+ /// <reference types="node" />
2
+ import type { AirtopClient } from "wrapper/AirtopClient";
3
+ import type { BatchOperationError, BatchOperationInput, BatchOperationResponse, BatchOperationUrl } from "./types";
4
+ import type { EventEmitter } from "node:events";
5
+ import type { AirtopSessionConfigV1 } from "wrapper/AirtopSessions";
6
+ export declare class SessionQueue<T> {
7
+ private activePromises;
8
+ private activePromisesMutex;
9
+ private maxConcurrentSessions;
10
+ private runEmitter;
11
+ private maxWindowsPerSession;
12
+ private sessionConfig?;
13
+ private initialBatches;
14
+ private operation;
15
+ private onError?;
16
+ private isHalted;
17
+ private batchQueue;
18
+ private batchQueueMutex;
19
+ private latestProcessingPromise;
20
+ private processingPromisesCount;
21
+ private client;
22
+ private sessionPool;
23
+ private sessionPoolMutex;
24
+ private results;
25
+ constructor({ maxConcurrentSessions, runEmitter, maxWindowsPerSession, initialBatches, operation, client, sessionConfig, onError, }: {
26
+ maxConcurrentSessions: number;
27
+ runEmitter: EventEmitter;
28
+ maxWindowsPerSession: number;
29
+ initialBatches: BatchOperationUrl[][];
30
+ operation: (input: BatchOperationInput) => Promise<BatchOperationResponse<T>>;
31
+ client: AirtopClient;
32
+ sessionConfig?: AirtopSessionConfigV1;
33
+ onError?: (error: BatchOperationError) => Promise<void>;
34
+ });
35
+ handleHaltEvent(): void;
36
+ addUrlsToBatchQueue(newBatch: BatchOperationUrl[]): Promise<void>;
37
+ processInitialBatches(): Promise<void>;
38
+ waitForProcessingToComplete(): Promise<T[]>;
39
+ private terminateAllSessions;
40
+ private processPendingBatches;
41
+ private handleErrorWithCallback;
42
+ private logErrorForUrls;
43
+ private safelyTerminateSession;
44
+ private formatError;
45
+ private handleErrorAndWarningResponses;
46
+ }
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SessionQueue = void 0;
13
+ const helpers_1 = require("./helpers");
14
+ const WindowQueue_1 = require("./WindowQueue");
15
+ const async_mutex_1 = require("async-mutex");
16
+ class SessionQueue {
17
+ constructor({ maxConcurrentSessions, runEmitter, maxWindowsPerSession, initialBatches, operation, client, sessionConfig, onError, }) {
18
+ this.activePromises = [];
19
+ this.activePromisesMutex = new async_mutex_1.Mutex();
20
+ this.initialBatches = [];
21
+ this.batchQueue = [];
22
+ this.batchQueueMutex = new async_mutex_1.Mutex();
23
+ this.latestProcessingPromise = null;
24
+ this.processingPromisesCount = 0;
25
+ this.sessionPool = [];
26
+ this.sessionPoolMutex = new async_mutex_1.Mutex();
27
+ if (!Number.isInteger(maxConcurrentSessions) ||
28
+ maxConcurrentSessions <= 0) {
29
+ throw new Error("maxConcurrentSessions must be a positive integer");
30
+ }
31
+ this.maxConcurrentSessions = maxConcurrentSessions;
32
+ this.runEmitter = runEmitter;
33
+ this.maxWindowsPerSession = maxWindowsPerSession;
34
+ this.sessionConfig = sessionConfig;
35
+ this.initialBatches = initialBatches;
36
+ this.operation = operation;
37
+ this.onError = onError;
38
+ this.latestProcessingPromise = null;
39
+ this.results = [];
40
+ this.client = client;
41
+ this.isHalted = false;
42
+ }
43
+ handleHaltEvent() {
44
+ this.client.log("Halt event received");
45
+ this.isHalted = true;
46
+ }
47
+ addUrlsToBatchQueue(newBatch) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ // Distribute new URLs across batches
50
+ const newBatches = (0, helpers_1.distributeUrlsToBatches)(newBatch, this.maxConcurrentSessions);
51
+ this.client.log(`Adding new batches to queue: ${JSON.stringify(newBatches)}`);
52
+ // Add new batches to the queue
53
+ yield this.batchQueueMutex.runExclusive(() => {
54
+ this.batchQueue.push(...newBatches);
55
+ });
56
+ // Update existing processing promise
57
+ this.processingPromisesCount++;
58
+ this.latestProcessingPromise = this.processPendingBatches();
59
+ });
60
+ }
61
+ processInitialBatches() {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ yield this.batchQueueMutex.runExclusive(() => {
64
+ this.batchQueue = [...this.initialBatches];
65
+ });
66
+ this.processingPromisesCount++;
67
+ this.runEmitter.on("halt", this.handleHaltEvent.bind(this));
68
+ this.latestProcessingPromise = this.processPendingBatches();
69
+ yield this.latestProcessingPromise;
70
+ });
71
+ }
72
+ waitForProcessingToComplete() {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ while (this.processingPromisesCount > 0) {
75
+ yield this.latestProcessingPromise;
76
+ }
77
+ yield this.terminateAllSessions();
78
+ this.runEmitter.removeListener("halt", this.handleHaltEvent);
79
+ return this.results;
80
+ });
81
+ }
82
+ terminateAllSessions() {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ for (const sessionId of this.sessionPool) {
85
+ this.safelyTerminateSession(sessionId);
86
+ }
87
+ });
88
+ }
89
+ processPendingBatches() {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ try {
92
+ while (this.batchQueue.length > 0) {
93
+ // Wait for any session to complete before starting a new one
94
+ let shouldContinue = false;
95
+ yield this.activePromisesMutex.runExclusive(() => __awaiter(this, void 0, void 0, function* () {
96
+ if (this.activePromises.length >= this.maxConcurrentSessions) {
97
+ yield Promise.race(this.activePromises);
98
+ shouldContinue = true;
99
+ }
100
+ }));
101
+ if (shouldContinue)
102
+ continue;
103
+ let batch;
104
+ yield this.batchQueueMutex.runExclusive(() => {
105
+ batch = this.batchQueue.shift();
106
+ });
107
+ if (!batch || batch.length === 0)
108
+ break;
109
+ const promise = (() => __awaiter(this, void 0, void 0, function* () {
110
+ if (this.isHalted) {
111
+ this.client.log("Halt event received, skipping batch");
112
+ return;
113
+ }
114
+ let sessionId;
115
+ try {
116
+ // Check if there's an available session in the pool
117
+ yield this.sessionPoolMutex.runExclusive(() => {
118
+ if (this.sessionPool.length > 0) {
119
+ sessionId = this.sessionPool.pop();
120
+ }
121
+ });
122
+ // Otherwise, create a new session
123
+ if (!sessionId) {
124
+ const { data: session, warnings, errors } = yield this.client.sessions.create({
125
+ configuration: this.sessionConfig,
126
+ });
127
+ sessionId = session.id;
128
+ this.handleErrorAndWarningResponses({ warnings, errors, sessionId, batch });
129
+ }
130
+ const queue = new WindowQueue_1.WindowQueue(this.maxWindowsPerSession, this.runEmitter, sessionId, this.client, this.operation, this.onError, this.isHalted);
131
+ const windowResults = yield queue.processInBatches(batch);
132
+ this.results.push(...windowResults);
133
+ // Return the session to the pool
134
+ yield this.sessionPoolMutex.runExclusive(() => {
135
+ if (!sessionId) {
136
+ throw new Error("Missing sessionId, cannot return to pool");
137
+ }
138
+ this.sessionPool.push(sessionId);
139
+ });
140
+ }
141
+ catch (error) {
142
+ if (this.onError) {
143
+ yield this.handleErrorWithCallback({ originalError: error, batch, sessionId, callback: this.onError });
144
+ }
145
+ else {
146
+ // By default, log the error and continue
147
+ const urls = batch.map((url) => url.url);
148
+ this.logErrorForUrls(urls, error);
149
+ }
150
+ // Clean up the session in case of error
151
+ if (sessionId) {
152
+ this.safelyTerminateSession(sessionId);
153
+ }
154
+ }
155
+ }))();
156
+ yield this.activePromisesMutex.runExclusive(() => {
157
+ this.activePromises.push(promise);
158
+ });
159
+ // Remove the promise when it completes
160
+ promise.finally(() => __awaiter(this, void 0, void 0, function* () {
161
+ yield this.activePromisesMutex.runExclusive(() => {
162
+ const index = this.activePromises.indexOf(promise);
163
+ if (index > -1) {
164
+ this.activePromises.splice(index, 1);
165
+ }
166
+ });
167
+ }));
168
+ }
169
+ // Wait for all remaining sessions to complete
170
+ yield Promise.allSettled(this.activePromises);
171
+ }
172
+ finally {
173
+ this.processingPromisesCount--;
174
+ }
175
+ });
176
+ }
177
+ handleErrorWithCallback({ originalError, batch, sessionId, callback, }) {
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ // Catch any errors in the onError callback to avoid halting the entire process
180
+ try {
181
+ yield callback({
182
+ error: this.formatError(originalError),
183
+ operationUrls: batch,
184
+ sessionId,
185
+ });
186
+ }
187
+ catch (newError) {
188
+ this.client.error(`Error in onError callback: ${this.formatError(newError)}. Original error: ${this.formatError(originalError)}`);
189
+ }
190
+ });
191
+ }
192
+ logErrorForUrls(urls, error) {
193
+ const message = `Error for URLs ${JSON.stringify(urls)}: ${this.formatError(error)}`;
194
+ this.client.error(message);
195
+ }
196
+ safelyTerminateSession(sessionId) {
197
+ // Do not await since we don't want to block the main thread
198
+ this.client.sessions.terminate(sessionId).catch((error) => {
199
+ this.client.error(`Error terminating session ${sessionId}: ${this.formatError(error)}`);
200
+ });
201
+ }
202
+ formatError(error) {
203
+ return error instanceof Error ? error.message : String(error);
204
+ }
205
+ handleErrorAndWarningResponses({ warnings, errors, sessionId, batch }) {
206
+ if (!warnings && !errors)
207
+ return;
208
+ const details = {
209
+ sessionId,
210
+ urls: batch,
211
+ };
212
+ if (warnings) {
213
+ details.warnings = warnings;
214
+ this.client.warn(`Received warnings creating session: ${JSON.stringify(details)}`);
215
+ }
216
+ // Log an object with the errors and the URL
217
+ if (errors) {
218
+ details.errors = errors;
219
+ this.client.error(`Received errors creating session: ${JSON.stringify(details)}`);
220
+ }
221
+ }
222
+ }
223
+ exports.SessionQueue = SessionQueue;
@@ -0,0 +1,25 @@
1
+ /// <reference types="node" />
2
+ import type { AirtopClient } from "wrapper/AirtopClient";
3
+ import type { BatchOperationError, BatchOperationInput, BatchOperationResponse, BatchOperationUrl } from "./types";
4
+ import type { EventEmitter } from "node:events";
5
+ export declare class WindowQueue<T> {
6
+ private activePromises;
7
+ private urlQueue;
8
+ private activePromisesMutex;
9
+ private urlQueueMutex;
10
+ private maxWindowsPerSession;
11
+ private runEmitter;
12
+ private sessionId;
13
+ private client;
14
+ private operation;
15
+ private onError?;
16
+ private isHalted;
17
+ constructor(maxWindowsPerSession: number, runEmitter: EventEmitter, sessionId: string, client: AirtopClient, operation: (input: BatchOperationInput) => Promise<BatchOperationResponse<T>>, onError?: (error: BatchOperationError) => Promise<void>, isHalted?: boolean);
18
+ addUrlToQueue(url: BatchOperationUrl): Promise<void>;
19
+ private handleHaltEvent;
20
+ processInBatches(urls: BatchOperationUrl[]): Promise<T[]>;
21
+ private handleErrorWithCallback;
22
+ private safelyTerminateWindow;
23
+ private formatError;
24
+ private handleErrorAndWarningResponses;
25
+ }
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.WindowQueue = void 0;
13
+ const async_mutex_1 = require("async-mutex");
14
+ class WindowQueue {
15
+ constructor(maxWindowsPerSession, runEmitter, sessionId, client, operation, onError, isHalted = false) {
16
+ this.activePromises = [];
17
+ this.urlQueue = [];
18
+ this.activePromisesMutex = new async_mutex_1.Mutex();
19
+ this.urlQueueMutex = new async_mutex_1.Mutex();
20
+ if (!Number.isInteger(maxWindowsPerSession) || maxWindowsPerSession <= 0) {
21
+ throw new Error("maxWindowsPerSession must be a positive integer");
22
+ }
23
+ this.maxWindowsPerSession = maxWindowsPerSession;
24
+ this.runEmitter = runEmitter;
25
+ this.sessionId = sessionId;
26
+ this.client = client;
27
+ this.operation = operation;
28
+ this.onError = onError;
29
+ this.isHalted = isHalted;
30
+ }
31
+ addUrlToQueue(url) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ yield this.urlQueueMutex.runExclusive(() => {
34
+ this.urlQueue.push(url);
35
+ });
36
+ });
37
+ }
38
+ handleHaltEvent() {
39
+ this.client.log("Halt event received");
40
+ this.isHalted = true;
41
+ }
42
+ processInBatches(urls) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const results = [];
45
+ this.runEmitter.on("halt", this.handleHaltEvent.bind(this));
46
+ yield this.urlQueueMutex.runExclusive(() => {
47
+ this.urlQueue = [...urls];
48
+ });
49
+ this.client.log(`Processing batch: ${JSON.stringify(urls)} for session ${this.sessionId}`);
50
+ while (this.urlQueue.length > 0) {
51
+ // Wait for any window to complete before starting a new one
52
+ let shouldContinue = false;
53
+ yield this.activePromisesMutex.runExclusive(() => __awaiter(this, void 0, void 0, function* () {
54
+ if (this.activePromises.length >= this.maxWindowsPerSession) {
55
+ yield Promise.race(this.activePromises);
56
+ shouldContinue = true;
57
+ }
58
+ }));
59
+ if (shouldContinue)
60
+ continue;
61
+ let urlData;
62
+ yield this.urlQueueMutex.runExclusive(() => {
63
+ urlData = this.urlQueue.shift(); // Take the next url from the queue
64
+ });
65
+ if (!urlData)
66
+ break; // No more urls to process
67
+ // If we have less than the max concurrent operations, start a new one
68
+ const promise = (() => __awaiter(this, void 0, void 0, function* () {
69
+ // Do not process any more urls if the processing has been halted
70
+ if (this.isHalted) {
71
+ this.client.log(`Processing halted, skipping window creation for ${urlData.url}`);
72
+ return;
73
+ }
74
+ let windowId;
75
+ let liveViewUrl;
76
+ try {
77
+ // Create a new window pointed to the url
78
+ this.client.log(`Creating window for ${urlData.url} in session ${this.sessionId}`);
79
+ const { data, errors, warnings } = yield this.client.windows.create(this.sessionId, {
80
+ url: urlData.url,
81
+ });
82
+ windowId = data.windowId;
83
+ this.handleErrorAndWarningResponses({ warnings, errors, sessionId: this.sessionId, url: urlData, operation: "window creation" });
84
+ if (!windowId) {
85
+ throw new Error(`WindowId not found, errors: ${JSON.stringify(errors)}`);
86
+ }
87
+ const { data: windowInfo, warnings: windowWarnings, errors: windowErrors } = yield this.client.windows.getWindowInfo(this.sessionId, windowId);
88
+ liveViewUrl = windowInfo.liveViewUrl;
89
+ this.handleErrorAndWarningResponses({ warnings: windowWarnings, errors: windowErrors, sessionId: this.sessionId, url: urlData, operation: "window info retrieval" });
90
+ // Run the operation on the window
91
+ const result = yield this.operation({
92
+ windowId,
93
+ sessionId: this.sessionId,
94
+ liveViewUrl,
95
+ operationUrl: urlData,
96
+ });
97
+ if (result) {
98
+ const { shouldHaltBatch, additionalUrls, data } = result;
99
+ if (data) {
100
+ results.push(data);
101
+ }
102
+ if (shouldHaltBatch) {
103
+ this.client.log("Emitting halt event");
104
+ this.runEmitter.emit("halt");
105
+ }
106
+ if (additionalUrls && additionalUrls.length > 0) {
107
+ this.client.log(`Emitting addUrls event with urls: ${JSON.stringify(additionalUrls)}`);
108
+ this.runEmitter.emit("addUrls", additionalUrls);
109
+ }
110
+ }
111
+ }
112
+ catch (error) {
113
+ if (this.onError) {
114
+ yield this.handleErrorWithCallback({
115
+ originalError: error,
116
+ url: urlData,
117
+ callback: this.onError,
118
+ windowId,
119
+ liveViewUrl,
120
+ });
121
+ }
122
+ else {
123
+ // By default, log the error and continue
124
+ const message = `Error for URL ${urlData.url}: ${this.formatError(error)}`;
125
+ this.client.error(message);
126
+ }
127
+ }
128
+ finally {
129
+ if (windowId) {
130
+ yield this.safelyTerminateWindow(windowId);
131
+ }
132
+ }
133
+ }))();
134
+ yield this.activePromisesMutex.runExclusive(() => {
135
+ this.activePromises.push(promise);
136
+ });
137
+ // Remove the promise from the active list when it resolves
138
+ promise.finally(() => __awaiter(this, void 0, void 0, function* () {
139
+ yield this.activePromisesMutex.runExclusive(() => {
140
+ const index = this.activePromises.indexOf(promise);
141
+ if (index > -1) {
142
+ this.activePromises.splice(index, 1);
143
+ }
144
+ });
145
+ }));
146
+ }
147
+ // Wait for all processes to complete
148
+ yield Promise.allSettled(this.activePromises);
149
+ // Remove the halt listener
150
+ this.runEmitter.removeListener("halt", this.handleHaltEvent);
151
+ return results;
152
+ });
153
+ }
154
+ handleErrorWithCallback({ originalError, url, windowId, liveViewUrl, callback, }) {
155
+ return __awaiter(this, void 0, void 0, function* () {
156
+ // Catch any errors in the onError callback to avoid halting the entire process
157
+ try {
158
+ yield callback({
159
+ error: this.formatError(originalError),
160
+ operationUrls: [url],
161
+ sessionId: this.sessionId,
162
+ windowId,
163
+ liveViewUrl,
164
+ });
165
+ }
166
+ catch (newError) {
167
+ this.client.error(`Error in onError callback: ${this.formatError(newError)}. Original error: ${this.formatError(originalError)}`);
168
+ }
169
+ });
170
+ }
171
+ safelyTerminateWindow(windowId) {
172
+ return __awaiter(this, void 0, void 0, function* () {
173
+ try {
174
+ yield this.client.windows.close(this.sessionId, windowId);
175
+ }
176
+ catch (error) {
177
+ this.client.error(`Error closing window ${windowId}: ${this.formatError(error)}`);
178
+ }
179
+ });
180
+ }
181
+ formatError(error) {
182
+ return error instanceof Error ? error.message : String(error);
183
+ }
184
+ handleErrorAndWarningResponses({ warnings, errors, sessionId, url, operation }) {
185
+ if (!warnings && !errors)
186
+ return;
187
+ const details = {
188
+ sessionId,
189
+ url,
190
+ };
191
+ if (warnings) {
192
+ details.warnings = warnings;
193
+ this.client.warn(`Received warnings for ${operation}: ${JSON.stringify(details)}`);
194
+ }
195
+ if (errors) {
196
+ details.errors = errors;
197
+ this.client.error(`Received errors for ${operation}: ${JSON.stringify(details)}`);
198
+ }
199
+ }
200
+ }
201
+ exports.WindowQueue = WindowQueue;
@@ -0,0 +1,3 @@
1
+ import type { AirtopClient } from "wrapper/AirtopClient";
2
+ import type { BatchOperateConfig, BatchOperationInput, BatchOperationResponse, BatchOperationUrl } from "./types";
3
+ export declare const batchOperate: <T>(urls: BatchOperationUrl[], operation: (input: BatchOperationInput) => Promise<BatchOperationResponse<T>>, client: AirtopClient, config?: BatchOperateConfig | undefined) => Promise<T[]>;