@phpsandbox/sdk 0.0.44 → 0.0.46

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 (42) hide show
  1. package/dist/auth.js.map +1 -1
  2. package/dist/beacon/index.d.ts.map +1 -1
  3. package/dist/beacon/index.js +3 -2
  4. package/dist/beacon/index.js.map +1 -1
  5. package/dist/beacon/navigator.js.map +1 -1
  6. package/dist/beacon/types.d.ts +15 -0
  7. package/dist/beacon/types.d.ts.map +1 -1
  8. package/dist/beacon/types.js.map +1 -1
  9. package/dist/browser/phpsandbox-sdk.esm.js +50 -308
  10. package/dist/browser/phpsandbox-sdk.esm.js.map +4 -4
  11. package/dist/browser/phpsandbox-sdk.esm.min.js +2 -2
  12. package/dist/browser/phpsandbox-sdk.esm.min.js.map +4 -4
  13. package/dist/browser/phpsandbox-sdk.iife.js +50 -296
  14. package/dist/browser/phpsandbox-sdk.iife.js.map +4 -4
  15. package/dist/browser/phpsandbox-sdk.iife.min.js +2 -2
  16. package/dist/browser/phpsandbox-sdk.iife.min.js.map +4 -4
  17. package/dist/composer.js.map +1 -1
  18. package/dist/config.js.map +1 -1
  19. package/dist/container.js.map +1 -1
  20. package/dist/errors/index.js.map +1 -1
  21. package/dist/events/index.js.map +1 -1
  22. package/dist/filesystem.js.map +1 -1
  23. package/dist/git.js.map +1 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/laravel.js.map +1 -1
  26. package/dist/log.js.map +1 -1
  27. package/dist/lsp.js.map +1 -1
  28. package/dist/repl.js.map +1 -1
  29. package/dist/services.js.map +1 -1
  30. package/dist/shell.js.map +1 -1
  31. package/dist/socket/index.js +1 -1
  32. package/dist/socket/index.js.map +1 -1
  33. package/dist/terminal.js.map +1 -1
  34. package/dist/types.js.map +1 -1
  35. package/dist/utils/disposable.js.map +1 -1
  36. package/dist/utils/promise.js.map +1 -1
  37. package/dist/utils/retry.d.ts +12 -0
  38. package/dist/utils/retry.d.ts.map +1 -0
  39. package/dist/utils/retry.js +46 -0
  40. package/dist/utils/retry.js.map +1 -0
  41. package/dist/utils/websocket.js.map +1 -1
  42. package/package.json +1 -3
@@ -1,311 +1,12 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
1
  var __typeError = (msg) => {
8
2
  throw TypeError(msg);
9
3
  };
10
- var __commonJS = (cb, mod) => function __require() {
11
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
4
  var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
30
5
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
31
6
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
32
7
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
33
8
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
34
9
 
35
- // node_modules/retry/lib/retry_operation.js
36
- var require_retry_operation = __commonJS({
37
- "node_modules/retry/lib/retry_operation.js"(exports, module) {
38
- function RetryOperation(timeouts, options) {
39
- if (typeof options === "boolean") {
40
- options = { forever: options };
41
- }
42
- this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
43
- this._timeouts = timeouts;
44
- this._options = options || {};
45
- this._maxRetryTime = options && options.maxRetryTime || Infinity;
46
- this._fn = null;
47
- this._errors = [];
48
- this._attempts = 1;
49
- this._operationTimeout = null;
50
- this._operationTimeoutCb = null;
51
- this._timeout = null;
52
- this._operationStart = null;
53
- this._timer = null;
54
- if (this._options.forever) {
55
- this._cachedTimeouts = this._timeouts.slice(0);
56
- }
57
- }
58
- module.exports = RetryOperation;
59
- RetryOperation.prototype.reset = function() {
60
- this._attempts = 1;
61
- this._timeouts = this._originalTimeouts.slice(0);
62
- };
63
- RetryOperation.prototype.stop = function() {
64
- if (this._timeout) {
65
- clearTimeout(this._timeout);
66
- }
67
- if (this._timer) {
68
- clearTimeout(this._timer);
69
- }
70
- this._timeouts = [];
71
- this._cachedTimeouts = null;
72
- };
73
- RetryOperation.prototype.retry = function(err) {
74
- if (this._timeout) {
75
- clearTimeout(this._timeout);
76
- }
77
- if (!err) {
78
- return false;
79
- }
80
- var currentTime = (/* @__PURE__ */ new Date()).getTime();
81
- if (err && currentTime - this._operationStart >= this._maxRetryTime) {
82
- this._errors.push(err);
83
- this._errors.unshift(new Error("RetryOperation timeout occurred"));
84
- return false;
85
- }
86
- this._errors.push(err);
87
- var timeout2 = this._timeouts.shift();
88
- if (timeout2 === void 0) {
89
- if (this._cachedTimeouts) {
90
- this._errors.splice(0, this._errors.length - 1);
91
- timeout2 = this._cachedTimeouts.slice(-1);
92
- } else {
93
- return false;
94
- }
95
- }
96
- var self2 = this;
97
- this._timer = setTimeout(function() {
98
- self2._attempts++;
99
- if (self2._operationTimeoutCb) {
100
- self2._timeout = setTimeout(function() {
101
- self2._operationTimeoutCb(self2._attempts);
102
- }, self2._operationTimeout);
103
- if (self2._options.unref) {
104
- self2._timeout.unref();
105
- }
106
- }
107
- self2._fn(self2._attempts);
108
- }, timeout2);
109
- if (this._options.unref) {
110
- this._timer.unref();
111
- }
112
- return true;
113
- };
114
- RetryOperation.prototype.attempt = function(fn, timeoutOps) {
115
- this._fn = fn;
116
- if (timeoutOps) {
117
- if (timeoutOps.timeout) {
118
- this._operationTimeout = timeoutOps.timeout;
119
- }
120
- if (timeoutOps.cb) {
121
- this._operationTimeoutCb = timeoutOps.cb;
122
- }
123
- }
124
- var self2 = this;
125
- if (this._operationTimeoutCb) {
126
- this._timeout = setTimeout(function() {
127
- self2._operationTimeoutCb();
128
- }, self2._operationTimeout);
129
- }
130
- this._operationStart = (/* @__PURE__ */ new Date()).getTime();
131
- this._fn(this._attempts);
132
- };
133
- RetryOperation.prototype.try = function(fn) {
134
- console.log("Using RetryOperation.try() is deprecated");
135
- this.attempt(fn);
136
- };
137
- RetryOperation.prototype.start = function(fn) {
138
- console.log("Using RetryOperation.start() is deprecated");
139
- this.attempt(fn);
140
- };
141
- RetryOperation.prototype.start = RetryOperation.prototype.try;
142
- RetryOperation.prototype.errors = function() {
143
- return this._errors;
144
- };
145
- RetryOperation.prototype.attempts = function() {
146
- return this._attempts;
147
- };
148
- RetryOperation.prototype.mainError = function() {
149
- if (this._errors.length === 0) {
150
- return null;
151
- }
152
- var counts = {};
153
- var mainError = null;
154
- var mainErrorCount = 0;
155
- for (var i = 0; i < this._errors.length; i++) {
156
- var error = this._errors[i];
157
- var message = error.message;
158
- var count = (counts[message] || 0) + 1;
159
- counts[message] = count;
160
- if (count >= mainErrorCount) {
161
- mainError = error;
162
- mainErrorCount = count;
163
- }
164
- }
165
- return mainError;
166
- };
167
- }
168
- });
169
-
170
- // node_modules/retry/lib/retry.js
171
- var require_retry = __commonJS({
172
- "node_modules/retry/lib/retry.js"(exports) {
173
- var RetryOperation = require_retry_operation();
174
- exports.operation = function(options) {
175
- var timeouts = exports.timeouts(options);
176
- return new RetryOperation(timeouts, {
177
- forever: options && (options.forever || options.retries === Infinity),
178
- unref: options && options.unref,
179
- maxRetryTime: options && options.maxRetryTime
180
- });
181
- };
182
- exports.timeouts = function(options) {
183
- if (options instanceof Array) {
184
- return [].concat(options);
185
- }
186
- var opts = {
187
- retries: 10,
188
- factor: 2,
189
- minTimeout: 1 * 1e3,
190
- maxTimeout: Infinity,
191
- randomize: false
192
- };
193
- for (var key in options) {
194
- opts[key] = options[key];
195
- }
196
- if (opts.minTimeout > opts.maxTimeout) {
197
- throw new Error("minTimeout is greater than maxTimeout");
198
- }
199
- var timeouts = [];
200
- for (var i = 0; i < opts.retries; i++) {
201
- timeouts.push(this.createTimeout(i, opts));
202
- }
203
- if (options && options.forever && !timeouts.length) {
204
- timeouts.push(this.createTimeout(i, opts));
205
- }
206
- timeouts.sort(function(a, b) {
207
- return a - b;
208
- });
209
- return timeouts;
210
- };
211
- exports.createTimeout = function(attempt, opts) {
212
- var random = opts.randomize ? Math.random() + 1 : 1;
213
- var timeout2 = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
214
- timeout2 = Math.min(timeout2, opts.maxTimeout);
215
- return timeout2;
216
- };
217
- exports.wrap = function(obj, options, methods) {
218
- if (options instanceof Array) {
219
- methods = options;
220
- options = null;
221
- }
222
- if (!methods) {
223
- methods = [];
224
- for (var key in obj) {
225
- if (typeof obj[key] === "function") {
226
- methods.push(key);
227
- }
228
- }
229
- }
230
- for (var i = 0; i < methods.length; i++) {
231
- var method = methods[i];
232
- var original = obj[method];
233
- obj[method] = function retryWrapper(original2) {
234
- var op = exports.operation(options);
235
- var args = Array.prototype.slice.call(arguments, 1);
236
- var callback = args.pop();
237
- args.push(function(err) {
238
- if (op.retry(err)) {
239
- return;
240
- }
241
- if (err) {
242
- arguments[0] = op.mainError();
243
- }
244
- callback.apply(this, arguments);
245
- });
246
- op.attempt(function() {
247
- original2.apply(obj, args);
248
- });
249
- }.bind(obj, original);
250
- obj[method].options = options;
251
- }
252
- };
253
- }
254
- });
255
-
256
- // node_modules/retry/index.js
257
- var require_retry2 = __commonJS({
258
- "node_modules/retry/index.js"(exports, module) {
259
- module.exports = require_retry();
260
- }
261
- });
262
-
263
- // node_modules/async-retry/lib/index.js
264
- var require_lib = __commonJS({
265
- "node_modules/async-retry/lib/index.js"(exports, module) {
266
- var retrier = require_retry2();
267
- function retry3(fn, opts) {
268
- function run(resolve, reject) {
269
- var options = opts || {};
270
- var op;
271
- if (!("randomize" in options)) {
272
- options.randomize = true;
273
- }
274
- op = retrier.operation(options);
275
- function bail(err) {
276
- reject(err || new Error("Aborted"));
277
- }
278
- function onError(err, num) {
279
- if (err.bail) {
280
- bail(err);
281
- return;
282
- }
283
- if (!op.retry(err)) {
284
- reject(op.mainError());
285
- } else if (options.onRetry) {
286
- options.onRetry(err, num);
287
- }
288
- }
289
- function runAttempt(num) {
290
- var val;
291
- try {
292
- val = fn(bail, num);
293
- } catch (err) {
294
- onError(err, num);
295
- return;
296
- }
297
- Promise.resolve(val).then(resolve).catch(function catchIt(err) {
298
- onError(err, num);
299
- });
300
- }
301
- op.attempt(runAttempt);
302
- }
303
- return new Promise(run);
304
- }
305
- module.exports = retry3;
306
- }
307
- });
308
-
309
10
  // src/types.ts
310
11
  var ErrorEvent = class extends Error {
311
12
  constructor(code, message, raw = {}) {
@@ -2626,8 +2327,51 @@ function decode(buffer, options) {
2626
2327
  return decoder.decode(buffer);
2627
2328
  }
2628
2329
 
2629
- // src/socket/index.ts
2630
- var import_async_retry = __toESM(require_lib(), 1);
2330
+ // src/utils/retry.ts
2331
+ var RetryBailError = class {
2332
+ constructor(error) {
2333
+ this.error = error;
2334
+ }
2335
+ };
2336
+ var sleep = (duration) => {
2337
+ return new Promise((resolve) => {
2338
+ setTimeout(resolve, duration);
2339
+ });
2340
+ };
2341
+ var getRetryDelay = (attempt, options) => {
2342
+ const randomized = options.randomize ? Math.random() + 1 : 1;
2343
+ const exponentialDelay = Math.max(options.minTimeout, 1) * Math.pow(options.factor, attempt - 1);
2344
+ return Math.round(Math.min(randomized * exponentialDelay, options.maxTimeout));
2345
+ };
2346
+ async function retry(fn, options = {}) {
2347
+ const resolvedOptions = {
2348
+ retries: options.retries ?? 10,
2349
+ minTimeout: options.minTimeout ?? 1e3,
2350
+ maxTimeout: options.maxTimeout ?? Infinity,
2351
+ factor: options.factor ?? 2,
2352
+ randomize: options.randomize ?? true
2353
+ };
2354
+ const bail = (error) => {
2355
+ throw new RetryBailError(error ?? new Error("Aborted"));
2356
+ };
2357
+ let lastError;
2358
+ for (let attempt = 1; attempt <= resolvedOptions.retries + 1; attempt++) {
2359
+ try {
2360
+ return await fn(bail, attempt);
2361
+ } catch (error) {
2362
+ if (error instanceof RetryBailError) {
2363
+ throw error.error;
2364
+ }
2365
+ lastError = error;
2366
+ if (attempt > resolvedOptions.retries) {
2367
+ throw error;
2368
+ }
2369
+ await options.onRetry?.(error, attempt);
2370
+ await sleep(getRetryDelay(attempt, resolvedOptions));
2371
+ }
2372
+ }
2373
+ throw lastError;
2374
+ }
2631
2375
 
2632
2376
  // node_modules/reconnecting-websocket/dist/reconnecting-websocket-mjs.js
2633
2377
  var extendStatics = function(d, b) {
@@ -3744,7 +3488,7 @@ var Transport = class {
3744
3488
  return new Blob([encode(data)]);
3745
3489
  }
3746
3490
  sendWithRetry(sender, retries = 10) {
3747
- return (0, import_async_retry.default)(
3491
+ return retry(
3748
3492
  async (bail, attempt) => {
3749
3493
  try {
3750
3494
  return await sender();
@@ -4300,9 +4044,6 @@ var Git = class {
4300
4044
  }
4301
4045
  };
4302
4046
 
4303
- // src/beacon/index.ts
4304
- var import_async_retry2 = __toESM(require_lib(), 1);
4305
-
4306
4047
  // src/beacon/navigator.ts
4307
4048
  var Navigator = class {
4308
4049
  constructor(onEvent, onceEvent, beacon) {
@@ -4710,7 +4451,7 @@ var Beacon = class {
4710
4451
  * Wait for beacon to be ready - simplified approach
4711
4452
  */
4712
4453
  waitForBeaconReady() {
4713
- return (0, import_async_retry2.default)(
4454
+ return retry(
4714
4455
  async () => {
4715
4456
  return new Promise((resolve, reject) => {
4716
4457
  if (this.isBeaconReady && this.channelEstablished) {
@@ -4775,7 +4516,7 @@ var Beacon = class {
4775
4516
  */
4776
4517
  async sendAndWaitFor(sendType, responseType, payload = {}, timeoutMs) {
4777
4518
  await this.ready();
4778
- return (0, import_async_retry2.default)(
4519
+ return retry(
4779
4520
  async (bail) => {
4780
4521
  return new Promise((resolve, reject) => {
4781
4522
  const actualTimeout = timeoutMs || this.options.timeout;
@@ -4938,7 +4679,8 @@ var Beacon = class {
4938
4679
  * Capture the current beacon document, optionally clipped to a viewport or document rectangle.
4939
4680
  */
4940
4681
  async captureScreenshot(request = {}) {
4941
- const timeoutMs = (request.timeout || 3e4) + 5e3;
4682
+ const mediaTimeoutMs = request.mediaTimeoutMs ?? request.timeout ?? 3e4;
4683
+ const timeoutMs = request.transportTimeoutMs ?? mediaTimeoutMs + 5e3;
4942
4684
  return this.sendAndWaitFor("captureScreenshot", "screenshotResult", request, timeoutMs);
4943
4685
  }
4944
4686
  /**