@phpsandbox/sdk 0.0.45 → 0.0.47

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 (41) hide show
  1. package/dist/auth.js.map +1 -1
  2. package/dist/beacon/index.js +1 -1
  3. package/dist/beacon/index.js.map +1 -1
  4. package/dist/beacon/navigator.js.map +1 -1
  5. package/dist/beacon/types.js.map +1 -1
  6. package/dist/browser/phpsandbox-sdk.esm.js +48 -307
  7. package/dist/browser/phpsandbox-sdk.esm.js.map +4 -4
  8. package/dist/browser/phpsandbox-sdk.esm.min.js +2 -2
  9. package/dist/browser/phpsandbox-sdk.esm.min.js.map +4 -4
  10. package/dist/browser/phpsandbox-sdk.iife.js +48 -295
  11. package/dist/browser/phpsandbox-sdk.iife.js.map +4 -4
  12. package/dist/browser/phpsandbox-sdk.iife.min.js +2 -2
  13. package/dist/browser/phpsandbox-sdk.iife.min.js.map +4 -4
  14. package/dist/composer.js.map +1 -1
  15. package/dist/config.js.map +1 -1
  16. package/dist/container.js.map +1 -1
  17. package/dist/errors/index.js.map +1 -1
  18. package/dist/events/index.js.map +1 -1
  19. package/dist/filesystem.js.map +1 -1
  20. package/dist/git.js.map +1 -1
  21. package/dist/index.d.ts +8 -4
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js.map +1 -1
  24. package/dist/laravel.js.map +1 -1
  25. package/dist/log.js.map +1 -1
  26. package/dist/lsp.js.map +1 -1
  27. package/dist/repl.js.map +1 -1
  28. package/dist/services.js.map +1 -1
  29. package/dist/shell.js.map +1 -1
  30. package/dist/socket/index.js +1 -1
  31. package/dist/socket/index.js.map +1 -1
  32. package/dist/terminal.js.map +1 -1
  33. package/dist/types.js.map +1 -1
  34. package/dist/utils/disposable.js.map +1 -1
  35. package/dist/utils/promise.js.map +1 -1
  36. package/dist/utils/retry.d.ts +12 -0
  37. package/dist/utils/retry.d.ts.map +1 -0
  38. package/dist/utils/retry.js +46 -0
  39. package/dist/utils/retry.js.map +1 -0
  40. package/dist/utils/websocket.js.map +1 -1
  41. package/package.json +1 -3
@@ -1,16 +1,11 @@
1
1
  var PHPSandbox = (() => {
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __typeError = (msg) => {
9
7
  throw TypeError(msg);
10
8
  };
11
- var __commonJS = (cb, mod) => function __require() {
12
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
- };
14
9
  var __export = (target, all) => {
15
10
  for (var name in all)
16
11
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -23,14 +18,6 @@ var PHPSandbox = (() => {
23
18
  }
24
19
  return to;
25
20
  };
26
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
- // If the importer is in node compatibility mode or this is not an ESM
28
- // file that has been converted to a CommonJS file using a Babel-
29
- // compatible transform (i.e. "__esModule" has not been set), then set
30
- // "default" to the CommonJS "module.exports" for node compatibility.
31
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
- mod
33
- ));
34
21
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
22
  var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
36
23
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
@@ -38,280 +25,6 @@ var PHPSandbox = (() => {
38
25
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
39
26
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
40
27
 
41
- // node_modules/retry/lib/retry_operation.js
42
- var require_retry_operation = __commonJS({
43
- "node_modules/retry/lib/retry_operation.js"(exports, module) {
44
- function RetryOperation(timeouts, options) {
45
- if (typeof options === "boolean") {
46
- options = { forever: options };
47
- }
48
- this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
49
- this._timeouts = timeouts;
50
- this._options = options || {};
51
- this._maxRetryTime = options && options.maxRetryTime || Infinity;
52
- this._fn = null;
53
- this._errors = [];
54
- this._attempts = 1;
55
- this._operationTimeout = null;
56
- this._operationTimeoutCb = null;
57
- this._timeout = null;
58
- this._operationStart = null;
59
- this._timer = null;
60
- if (this._options.forever) {
61
- this._cachedTimeouts = this._timeouts.slice(0);
62
- }
63
- }
64
- module.exports = RetryOperation;
65
- RetryOperation.prototype.reset = function() {
66
- this._attempts = 1;
67
- this._timeouts = this._originalTimeouts.slice(0);
68
- };
69
- RetryOperation.prototype.stop = function() {
70
- if (this._timeout) {
71
- clearTimeout(this._timeout);
72
- }
73
- if (this._timer) {
74
- clearTimeout(this._timer);
75
- }
76
- this._timeouts = [];
77
- this._cachedTimeouts = null;
78
- };
79
- RetryOperation.prototype.retry = function(err) {
80
- if (this._timeout) {
81
- clearTimeout(this._timeout);
82
- }
83
- if (!err) {
84
- return false;
85
- }
86
- var currentTime = (/* @__PURE__ */ new Date()).getTime();
87
- if (err && currentTime - this._operationStart >= this._maxRetryTime) {
88
- this._errors.push(err);
89
- this._errors.unshift(new Error("RetryOperation timeout occurred"));
90
- return false;
91
- }
92
- this._errors.push(err);
93
- var timeout2 = this._timeouts.shift();
94
- if (timeout2 === void 0) {
95
- if (this._cachedTimeouts) {
96
- this._errors.splice(0, this._errors.length - 1);
97
- timeout2 = this._cachedTimeouts.slice(-1);
98
- } else {
99
- return false;
100
- }
101
- }
102
- var self2 = this;
103
- this._timer = setTimeout(function() {
104
- self2._attempts++;
105
- if (self2._operationTimeoutCb) {
106
- self2._timeout = setTimeout(function() {
107
- self2._operationTimeoutCb(self2._attempts);
108
- }, self2._operationTimeout);
109
- if (self2._options.unref) {
110
- self2._timeout.unref();
111
- }
112
- }
113
- self2._fn(self2._attempts);
114
- }, timeout2);
115
- if (this._options.unref) {
116
- this._timer.unref();
117
- }
118
- return true;
119
- };
120
- RetryOperation.prototype.attempt = function(fn, timeoutOps) {
121
- this._fn = fn;
122
- if (timeoutOps) {
123
- if (timeoutOps.timeout) {
124
- this._operationTimeout = timeoutOps.timeout;
125
- }
126
- if (timeoutOps.cb) {
127
- this._operationTimeoutCb = timeoutOps.cb;
128
- }
129
- }
130
- var self2 = this;
131
- if (this._operationTimeoutCb) {
132
- this._timeout = setTimeout(function() {
133
- self2._operationTimeoutCb();
134
- }, self2._operationTimeout);
135
- }
136
- this._operationStart = (/* @__PURE__ */ new Date()).getTime();
137
- this._fn(this._attempts);
138
- };
139
- RetryOperation.prototype.try = function(fn) {
140
- console.log("Using RetryOperation.try() is deprecated");
141
- this.attempt(fn);
142
- };
143
- RetryOperation.prototype.start = function(fn) {
144
- console.log("Using RetryOperation.start() is deprecated");
145
- this.attempt(fn);
146
- };
147
- RetryOperation.prototype.start = RetryOperation.prototype.try;
148
- RetryOperation.prototype.errors = function() {
149
- return this._errors;
150
- };
151
- RetryOperation.prototype.attempts = function() {
152
- return this._attempts;
153
- };
154
- RetryOperation.prototype.mainError = function() {
155
- if (this._errors.length === 0) {
156
- return null;
157
- }
158
- var counts = {};
159
- var mainError = null;
160
- var mainErrorCount = 0;
161
- for (var i = 0; i < this._errors.length; i++) {
162
- var error = this._errors[i];
163
- var message = error.message;
164
- var count = (counts[message] || 0) + 1;
165
- counts[message] = count;
166
- if (count >= mainErrorCount) {
167
- mainError = error;
168
- mainErrorCount = count;
169
- }
170
- }
171
- return mainError;
172
- };
173
- }
174
- });
175
-
176
- // node_modules/retry/lib/retry.js
177
- var require_retry = __commonJS({
178
- "node_modules/retry/lib/retry.js"(exports) {
179
- var RetryOperation = require_retry_operation();
180
- exports.operation = function(options) {
181
- var timeouts = exports.timeouts(options);
182
- return new RetryOperation(timeouts, {
183
- forever: options && (options.forever || options.retries === Infinity),
184
- unref: options && options.unref,
185
- maxRetryTime: options && options.maxRetryTime
186
- });
187
- };
188
- exports.timeouts = function(options) {
189
- if (options instanceof Array) {
190
- return [].concat(options);
191
- }
192
- var opts = {
193
- retries: 10,
194
- factor: 2,
195
- minTimeout: 1 * 1e3,
196
- maxTimeout: Infinity,
197
- randomize: false
198
- };
199
- for (var key in options) {
200
- opts[key] = options[key];
201
- }
202
- if (opts.minTimeout > opts.maxTimeout) {
203
- throw new Error("minTimeout is greater than maxTimeout");
204
- }
205
- var timeouts = [];
206
- for (var i = 0; i < opts.retries; i++) {
207
- timeouts.push(this.createTimeout(i, opts));
208
- }
209
- if (options && options.forever && !timeouts.length) {
210
- timeouts.push(this.createTimeout(i, opts));
211
- }
212
- timeouts.sort(function(a, b) {
213
- return a - b;
214
- });
215
- return timeouts;
216
- };
217
- exports.createTimeout = function(attempt, opts) {
218
- var random = opts.randomize ? Math.random() + 1 : 1;
219
- var timeout2 = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
220
- timeout2 = Math.min(timeout2, opts.maxTimeout);
221
- return timeout2;
222
- };
223
- exports.wrap = function(obj, options, methods) {
224
- if (options instanceof Array) {
225
- methods = options;
226
- options = null;
227
- }
228
- if (!methods) {
229
- methods = [];
230
- for (var key in obj) {
231
- if (typeof obj[key] === "function") {
232
- methods.push(key);
233
- }
234
- }
235
- }
236
- for (var i = 0; i < methods.length; i++) {
237
- var method = methods[i];
238
- var original = obj[method];
239
- obj[method] = function retryWrapper(original2) {
240
- var op = exports.operation(options);
241
- var args = Array.prototype.slice.call(arguments, 1);
242
- var callback = args.pop();
243
- args.push(function(err) {
244
- if (op.retry(err)) {
245
- return;
246
- }
247
- if (err) {
248
- arguments[0] = op.mainError();
249
- }
250
- callback.apply(this, arguments);
251
- });
252
- op.attempt(function() {
253
- original2.apply(obj, args);
254
- });
255
- }.bind(obj, original);
256
- obj[method].options = options;
257
- }
258
- };
259
- }
260
- });
261
-
262
- // node_modules/retry/index.js
263
- var require_retry2 = __commonJS({
264
- "node_modules/retry/index.js"(exports, module) {
265
- module.exports = require_retry();
266
- }
267
- });
268
-
269
- // node_modules/async-retry/lib/index.js
270
- var require_lib = __commonJS({
271
- "node_modules/async-retry/lib/index.js"(exports, module) {
272
- var retrier = require_retry2();
273
- function retry3(fn, opts) {
274
- function run(resolve, reject) {
275
- var options = opts || {};
276
- var op;
277
- if (!("randomize" in options)) {
278
- options.randomize = true;
279
- }
280
- op = retrier.operation(options);
281
- function bail(err) {
282
- reject(err || new Error("Aborted"));
283
- }
284
- function onError(err, num) {
285
- if (err.bail) {
286
- bail(err);
287
- return;
288
- }
289
- if (!op.retry(err)) {
290
- reject(op.mainError());
291
- } else if (options.onRetry) {
292
- options.onRetry(err, num);
293
- }
294
- }
295
- function runAttempt(num) {
296
- var val;
297
- try {
298
- val = fn(bail, num);
299
- } catch (err) {
300
- onError(err, num);
301
- return;
302
- }
303
- Promise.resolve(val).then(resolve).catch(function catchIt(err) {
304
- onError(err, num);
305
- });
306
- }
307
- op.attempt(runAttempt);
308
- }
309
- return new Promise(run);
310
- }
311
- module.exports = retry3;
312
- }
313
- });
314
-
315
28
  // src/index.ts
316
29
  var index_exports = {};
317
30
  __export(index_exports, {
@@ -2675,8 +2388,51 @@ var PHPSandbox = (() => {
2675
2388
  return decoder.decode(buffer);
2676
2389
  }
2677
2390
 
2678
- // src/socket/index.ts
2679
- var import_async_retry = __toESM(require_lib(), 1);
2391
+ // src/utils/retry.ts
2392
+ var RetryBailError = class {
2393
+ constructor(error) {
2394
+ this.error = error;
2395
+ }
2396
+ };
2397
+ var sleep = (duration) => {
2398
+ return new Promise((resolve) => {
2399
+ setTimeout(resolve, duration);
2400
+ });
2401
+ };
2402
+ var getRetryDelay = (attempt, options) => {
2403
+ const randomized = options.randomize ? Math.random() + 1 : 1;
2404
+ const exponentialDelay = Math.max(options.minTimeout, 1) * Math.pow(options.factor, attempt - 1);
2405
+ return Math.round(Math.min(randomized * exponentialDelay, options.maxTimeout));
2406
+ };
2407
+ async function retry(fn, options = {}) {
2408
+ const resolvedOptions = {
2409
+ retries: options.retries ?? 10,
2410
+ minTimeout: options.minTimeout ?? 1e3,
2411
+ maxTimeout: options.maxTimeout ?? Infinity,
2412
+ factor: options.factor ?? 2,
2413
+ randomize: options.randomize ?? true
2414
+ };
2415
+ const bail = (error) => {
2416
+ throw new RetryBailError(error ?? new Error("Aborted"));
2417
+ };
2418
+ let lastError;
2419
+ for (let attempt = 1; attempt <= resolvedOptions.retries + 1; attempt++) {
2420
+ try {
2421
+ return await fn(bail, attempt);
2422
+ } catch (error) {
2423
+ if (error instanceof RetryBailError) {
2424
+ throw error.error;
2425
+ }
2426
+ lastError = error;
2427
+ if (attempt > resolvedOptions.retries) {
2428
+ throw error;
2429
+ }
2430
+ await options.onRetry?.(error, attempt);
2431
+ await sleep(getRetryDelay(attempt, resolvedOptions));
2432
+ }
2433
+ }
2434
+ throw lastError;
2435
+ }
2680
2436
 
2681
2437
  // node_modules/reconnecting-websocket/dist/reconnecting-websocket-mjs.js
2682
2438
  var extendStatics = function(d, b) {
@@ -3793,7 +3549,7 @@ var PHPSandbox = (() => {
3793
3549
  return new Blob([encode(data)]);
3794
3550
  }
3795
3551
  sendWithRetry(sender, retries = 10) {
3796
- return (0, import_async_retry.default)(
3552
+ return retry(
3797
3553
  async (bail, attempt) => {
3798
3554
  try {
3799
3555
  return await sender();
@@ -4349,9 +4105,6 @@ var PHPSandbox = (() => {
4349
4105
  }
4350
4106
  };
4351
4107
 
4352
- // src/beacon/index.ts
4353
- var import_async_retry2 = __toESM(require_lib(), 1);
4354
-
4355
4108
  // src/beacon/navigator.ts
4356
4109
  var Navigator = class {
4357
4110
  constructor(onEvent, onceEvent, beacon) {
@@ -4759,7 +4512,7 @@ var PHPSandbox = (() => {
4759
4512
  * Wait for beacon to be ready - simplified approach
4760
4513
  */
4761
4514
  waitForBeaconReady() {
4762
- return (0, import_async_retry2.default)(
4515
+ return retry(
4763
4516
  async () => {
4764
4517
  return new Promise((resolve, reject) => {
4765
4518
  if (this.isBeaconReady && this.channelEstablished) {
@@ -4824,7 +4577,7 @@ var PHPSandbox = (() => {
4824
4577
  */
4825
4578
  async sendAndWaitFor(sendType, responseType, payload = {}, timeoutMs) {
4826
4579
  await this.ready();
4827
- return (0, import_async_retry2.default)(
4580
+ return retry(
4828
4581
  async (bail) => {
4829
4582
  return new Promise((resolve, reject) => {
4830
4583
  const actualTimeout = timeoutMs || this.options.timeout;