lexmount 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.js +75 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -171,6 +171,28 @@ interface SessionCreateOptions {
|
|
|
171
171
|
* Optional upstream proxy configuration.
|
|
172
172
|
*/
|
|
173
173
|
proxy?: SessionProxyConfig;
|
|
174
|
+
/**
|
|
175
|
+
* Forward weak_lock to the API when creating sessions with read-write contexts.
|
|
176
|
+
*/
|
|
177
|
+
weakLock?: boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Use the async create API (`POST /instance/v2`) and poll until active.
|
|
180
|
+
*
|
|
181
|
+
* Defaults to true. Set to false to use the legacy synchronous `POST /instance`.
|
|
182
|
+
*/
|
|
183
|
+
asyncCreate?: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Delay between async create status polls in milliseconds.
|
|
186
|
+
*
|
|
187
|
+
* Defaults to 1000.
|
|
188
|
+
*/
|
|
189
|
+
pollIntervalMs?: number;
|
|
190
|
+
/**
|
|
191
|
+
* Maximum time to wait for async create activation in milliseconds.
|
|
192
|
+
*
|
|
193
|
+
* Defaults to 600000.
|
|
194
|
+
*/
|
|
195
|
+
pollTimeoutMs?: number;
|
|
174
196
|
}
|
|
175
197
|
/**
|
|
176
198
|
* Session list options.
|
|
@@ -566,6 +588,7 @@ declare class SessionsResource {
|
|
|
566
588
|
* Create a new browser session.
|
|
567
589
|
*/
|
|
568
590
|
create(options?: SessionCreateOptions): Promise<SessionCreateResponse>;
|
|
591
|
+
private createAsync;
|
|
569
592
|
/**
|
|
570
593
|
* Fetch one session by id.
|
|
571
594
|
*
|
|
@@ -592,6 +615,7 @@ declare class SessionsResource {
|
|
|
592
615
|
*/
|
|
593
616
|
_getWebSocketDebuggerUrl(sessionId: string): Promise<string | null>;
|
|
594
617
|
private normalizeProxy;
|
|
618
|
+
private handleAsyncCreateFailed;
|
|
595
619
|
private handleCreateError;
|
|
596
620
|
private handleGetError;
|
|
597
621
|
private handleListError;
|
|
@@ -748,6 +772,6 @@ declare class TimeoutError extends LexmountError {
|
|
|
748
772
|
/**
|
|
749
773
|
* Lexmount Node.js SDK.
|
|
750
774
|
*/
|
|
751
|
-
declare const VERSION = "0.5.
|
|
775
|
+
declare const VERSION = "0.5.3";
|
|
752
776
|
|
|
753
777
|
export { APIError, AuthenticationError, type BrowserMode, type CatalogInfo, type ContextAccessMode, type ContextCreateOptions, ContextInfo, type ContextListOptions, ContextListResponse, ContextLockedError, type ContextMetadata, ContextNotFoundError, type ContextStatus, ContextsResource, ExtensionInfo, type ExtensionInfoShape, type ExtensionListOptions, type ExtensionUploadOptions, ExtensionsResource, type ForceReleaseResponse, Lexmount, type LexmountConfig, LexmountError, LexmountLogger, type LogLevel, NetworkError, PaginationInfo, type PaginationInfoShape, type RegionCatalogEntry, type RegionInfo, type SessionContext, type SessionCreateOptions, type SessionCreateResponse, type SessionDeleteOptions, SessionDownloadInfo, type SessionDownloadInfoShape, SessionDownloadsDeleteResponse, type SessionDownloadsDeleteResponseShape, SessionDownloadsListResponse, type SessionDownloadsListResponseShape, SessionDownloadsResource, SessionInfo, type SessionListOptions, SessionListResponse, SessionNotFoundError, type SessionProxyConfig, type SessionStatus, SessionTargetInfo, type SessionTargetInfoShape, SessionsResource, TimeoutError, VERSION, ValidationError, Lexmount as default, disableLogging, enableLogging, getLogger, setLogLevel };
|
package/dist/index.d.ts
CHANGED
|
@@ -171,6 +171,28 @@ interface SessionCreateOptions {
|
|
|
171
171
|
* Optional upstream proxy configuration.
|
|
172
172
|
*/
|
|
173
173
|
proxy?: SessionProxyConfig;
|
|
174
|
+
/**
|
|
175
|
+
* Forward weak_lock to the API when creating sessions with read-write contexts.
|
|
176
|
+
*/
|
|
177
|
+
weakLock?: boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Use the async create API (`POST /instance/v2`) and poll until active.
|
|
180
|
+
*
|
|
181
|
+
* Defaults to true. Set to false to use the legacy synchronous `POST /instance`.
|
|
182
|
+
*/
|
|
183
|
+
asyncCreate?: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Delay between async create status polls in milliseconds.
|
|
186
|
+
*
|
|
187
|
+
* Defaults to 1000.
|
|
188
|
+
*/
|
|
189
|
+
pollIntervalMs?: number;
|
|
190
|
+
/**
|
|
191
|
+
* Maximum time to wait for async create activation in milliseconds.
|
|
192
|
+
*
|
|
193
|
+
* Defaults to 600000.
|
|
194
|
+
*/
|
|
195
|
+
pollTimeoutMs?: number;
|
|
174
196
|
}
|
|
175
197
|
/**
|
|
176
198
|
* Session list options.
|
|
@@ -566,6 +588,7 @@ declare class SessionsResource {
|
|
|
566
588
|
* Create a new browser session.
|
|
567
589
|
*/
|
|
568
590
|
create(options?: SessionCreateOptions): Promise<SessionCreateResponse>;
|
|
591
|
+
private createAsync;
|
|
569
592
|
/**
|
|
570
593
|
* Fetch one session by id.
|
|
571
594
|
*
|
|
@@ -592,6 +615,7 @@ declare class SessionsResource {
|
|
|
592
615
|
*/
|
|
593
616
|
_getWebSocketDebuggerUrl(sessionId: string): Promise<string | null>;
|
|
594
617
|
private normalizeProxy;
|
|
618
|
+
private handleAsyncCreateFailed;
|
|
595
619
|
private handleCreateError;
|
|
596
620
|
private handleGetError;
|
|
597
621
|
private handleListError;
|
|
@@ -748,6 +772,6 @@ declare class TimeoutError extends LexmountError {
|
|
|
748
772
|
/**
|
|
749
773
|
* Lexmount Node.js SDK.
|
|
750
774
|
*/
|
|
751
|
-
declare const VERSION = "0.5.
|
|
775
|
+
declare const VERSION = "0.5.3";
|
|
752
776
|
|
|
753
777
|
export { APIError, AuthenticationError, type BrowserMode, type CatalogInfo, type ContextAccessMode, type ContextCreateOptions, ContextInfo, type ContextListOptions, ContextListResponse, ContextLockedError, type ContextMetadata, ContextNotFoundError, type ContextStatus, ContextsResource, ExtensionInfo, type ExtensionInfoShape, type ExtensionListOptions, type ExtensionUploadOptions, ExtensionsResource, type ForceReleaseResponse, Lexmount, type LexmountConfig, LexmountError, LexmountLogger, type LogLevel, NetworkError, PaginationInfo, type PaginationInfoShape, type RegionCatalogEntry, type RegionInfo, type SessionContext, type SessionCreateOptions, type SessionCreateResponse, type SessionDeleteOptions, SessionDownloadInfo, type SessionDownloadInfoShape, SessionDownloadsDeleteResponse, type SessionDownloadsDeleteResponseShape, SessionDownloadsListResponse, type SessionDownloadsListResponseShape, SessionDownloadsResource, SessionInfo, type SessionListOptions, SessionListResponse, SessionNotFoundError, type SessionProxyConfig, type SessionStatus, SessionTargetInfo, type SessionTargetInfoShape, SessionsResource, TimeoutError, VERSION, ValidationError, Lexmount as default, disableLogging, enableLogging, getLogger, setLogLevel };
|
package/dist/index.js
CHANGED
|
@@ -620,6 +620,11 @@ function normalizeContextMode(mode) {
|
|
|
620
620
|
}
|
|
621
621
|
return "read_only";
|
|
622
622
|
}
|
|
623
|
+
function delay(ms) {
|
|
624
|
+
return new Promise((resolve) => {
|
|
625
|
+
setTimeout(resolve, ms);
|
|
626
|
+
});
|
|
627
|
+
}
|
|
623
628
|
var PaginationInfo = class {
|
|
624
629
|
constructor(shape) {
|
|
625
630
|
this.currentPage = shape.currentPage;
|
|
@@ -851,7 +856,6 @@ var SessionsResource = class {
|
|
|
851
856
|
* Create a new browser session.
|
|
852
857
|
*/
|
|
853
858
|
async create(options = {}) {
|
|
854
|
-
const url = `${this.client.baseUrl}/instance`;
|
|
855
859
|
const payload = {
|
|
856
860
|
api_key: this.client.apiKey,
|
|
857
861
|
project_id: options.projectId ?? this.client.projectId,
|
|
@@ -875,6 +879,13 @@ var SessionsResource = class {
|
|
|
875
879
|
if (options.proxy) {
|
|
876
880
|
payload.proxy = this.normalizeProxy(options.proxy);
|
|
877
881
|
}
|
|
882
|
+
if (options.weakLock) {
|
|
883
|
+
payload.weak_lock = true;
|
|
884
|
+
}
|
|
885
|
+
if (options.asyncCreate !== false) {
|
|
886
|
+
return this.createAsync(payload, options);
|
|
887
|
+
}
|
|
888
|
+
const url = `${this.client.baseUrl}/instance`;
|
|
878
889
|
const response = await this.client._post(url, payload);
|
|
879
890
|
if (response.status >= 400) {
|
|
880
891
|
this.handleCreateError(response);
|
|
@@ -905,6 +916,60 @@ var SessionsResource = class {
|
|
|
905
916
|
client: this.client
|
|
906
917
|
});
|
|
907
918
|
}
|
|
919
|
+
async createAsync(payload, options) {
|
|
920
|
+
const response = await this.client._post(`${this.client.baseUrl}/instance/v2`, payload);
|
|
921
|
+
if (response.status >= 400) {
|
|
922
|
+
this.handleCreateError(response);
|
|
923
|
+
}
|
|
924
|
+
const result = asRecord3(response.data);
|
|
925
|
+
const sessionId = getString3(result.session_id);
|
|
926
|
+
if (!sessionId) {
|
|
927
|
+
throw new APIError("Failed to create session: session_id missing from response", {
|
|
928
|
+
statusCode: response.status,
|
|
929
|
+
response: response.data
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
const projectId = options.projectId ?? this.client.projectId;
|
|
933
|
+
const pollIntervalMs = options.pollIntervalMs ?? 1e3;
|
|
934
|
+
const pollTimeoutMs = options.pollTimeoutMs ?? 6e5;
|
|
935
|
+
const deadline = Date.now() + pollTimeoutMs;
|
|
936
|
+
while (Date.now() < deadline) {
|
|
937
|
+
const info = await this.get(sessionId, projectId);
|
|
938
|
+
if (info.status === "active") {
|
|
939
|
+
const wsUrl = await this._getWebSocketDebuggerUrl(sessionId);
|
|
940
|
+
getLogger().info(`Session created successfully (async): id=${sessionId}`);
|
|
941
|
+
return new SessionInfo({
|
|
942
|
+
id: sessionId,
|
|
943
|
+
status: "active",
|
|
944
|
+
apiKey: this.client.apiKey,
|
|
945
|
+
projectId,
|
|
946
|
+
browserType: info.browserType || (options.browserMode ?? "normal"),
|
|
947
|
+
createdAt: info.createdAt,
|
|
948
|
+
inspectUrl: info.inspectUrl,
|
|
949
|
+
containerId: info.containerId,
|
|
950
|
+
ws: wsUrl ?? info.ws,
|
|
951
|
+
client: this.client
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
if (info.status === "create_failed") {
|
|
955
|
+
this.handleAsyncCreateFailed(payload);
|
|
956
|
+
throw new APIError("Session creation failed", {
|
|
957
|
+
statusCode: 500,
|
|
958
|
+
response: { session_id: sessionId, status: info.status }
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
if (info.status === "closed") {
|
|
962
|
+
throw new APIError("Session closed before activation", {
|
|
963
|
+
statusCode: 500,
|
|
964
|
+
response: { session_id: sessionId, status: info.status }
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
await delay(pollIntervalMs);
|
|
968
|
+
}
|
|
969
|
+
throw new TimeoutError(
|
|
970
|
+
`Timed out waiting for session ${sessionId} to become active after ${pollTimeoutMs}ms`
|
|
971
|
+
);
|
|
972
|
+
}
|
|
908
973
|
/**
|
|
909
974
|
* Fetch one session by id.
|
|
910
975
|
*
|
|
@@ -1021,6 +1086,14 @@ var SessionsResource = class {
|
|
|
1021
1086
|
}
|
|
1022
1087
|
return normalizedProxy;
|
|
1023
1088
|
}
|
|
1089
|
+
handleAsyncCreateFailed(payload) {
|
|
1090
|
+
const context = asRecord3(payload.context);
|
|
1091
|
+
const contextId = getString3(context.id);
|
|
1092
|
+
const contextMode = getString3(context.mode);
|
|
1093
|
+
if (contextId && contextMode === "read_write" && payload.weak_lock !== true) {
|
|
1094
|
+
throw new ContextLockedError("Context is locked by another active session");
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1024
1097
|
handleCreateError(response) {
|
|
1025
1098
|
const errorData = asRecord3(response.data);
|
|
1026
1099
|
const errorMessage = getString3(errorData.error) ?? getString3(errorData.message) ?? "Unknown error";
|
|
@@ -1422,7 +1495,7 @@ var Lexmount = class {
|
|
|
1422
1495
|
};
|
|
1423
1496
|
|
|
1424
1497
|
// src/index.ts
|
|
1425
|
-
var VERSION = "0.5.
|
|
1498
|
+
var VERSION = "0.5.3";
|
|
1426
1499
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1427
1500
|
0 && (module.exports = {
|
|
1428
1501
|
APIError,
|