@limrun/api 0.20.2 → 0.21.0

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 (64) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/client.d.mts +1 -1
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +1 -1
  5. package/client.d.ts.map +1 -1
  6. package/client.js +15 -17
  7. package/client.js.map +1 -1
  8. package/client.mjs +15 -17
  9. package/client.mjs.map +1 -1
  10. package/folder-sync.d.mts +1 -1
  11. package/folder-sync.d.mts.map +1 -1
  12. package/folder-sync.d.ts +1 -1
  13. package/folder-sync.d.ts.map +1 -1
  14. package/instance-client.d.mts +109 -0
  15. package/instance-client.d.mts.map +1 -1
  16. package/instance-client.d.ts +109 -0
  17. package/instance-client.d.ts.map +1 -1
  18. package/instance-client.js +262 -69
  19. package/instance-client.js.map +1 -1
  20. package/instance-client.mjs +262 -69
  21. package/instance-client.mjs.map +1 -1
  22. package/internal/utils/query.d.mts +5 -0
  23. package/internal/utils/query.d.mts.map +1 -0
  24. package/internal/utils/query.d.ts +5 -0
  25. package/internal/utils/query.d.ts.map +1 -0
  26. package/internal/utils/query.js +23 -0
  27. package/internal/utils/query.js.map +1 -0
  28. package/internal/utils/query.mjs +20 -0
  29. package/internal/utils/query.mjs.map +1 -0
  30. package/internal/utils.d.mts +1 -0
  31. package/internal/utils.d.ts +1 -0
  32. package/internal/utils.js +1 -0
  33. package/internal/utils.js.map +1 -1
  34. package/internal/utils.mjs +1 -0
  35. package/ios-client.d.mts +12 -4
  36. package/ios-client.d.mts.map +1 -1
  37. package/ios-client.d.ts +12 -4
  38. package/ios-client.d.ts.map +1 -1
  39. package/ios-client.js +7 -2
  40. package/ios-client.js.map +1 -1
  41. package/ios-client.mjs +7 -2
  42. package/ios-client.mjs.map +1 -1
  43. package/package.json +12 -1
  44. package/resources/android-instances.d.mts +1 -0
  45. package/resources/android-instances.d.mts.map +1 -1
  46. package/resources/android-instances.d.ts +1 -0
  47. package/resources/android-instances.d.ts.map +1 -1
  48. package/resources/ios-instances.d.mts +1 -1
  49. package/resources/ios-instances.d.mts.map +1 -1
  50. package/resources/ios-instances.d.ts +1 -1
  51. package/resources/ios-instances.d.ts.map +1 -1
  52. package/src/client.ts +18 -21
  53. package/src/folder-sync.ts +2 -2
  54. package/src/instance-client.ts +516 -96
  55. package/src/internal/utils/query.ts +23 -0
  56. package/src/internal/utils.ts +1 -0
  57. package/src/ios-client.ts +25 -7
  58. package/src/resources/android-instances.ts +2 -0
  59. package/src/resources/ios-instances.ts +1 -1
  60. package/src/version.ts +1 -1
  61. package/version.d.mts +1 -1
  62. package/version.d.ts +1 -1
  63. package/version.js +1 -1
  64. package/version.mjs +1 -1
package/src/client.ts CHANGED
@@ -11,6 +11,7 @@ import type { APIResponseProps } from './internal/parse';
11
11
  import { getPlatformHeaders } from './internal/detect-platform';
12
12
  import * as Shims from './internal/shims';
13
13
  import * as Opts from './internal/request-options';
14
+ import { stringifyQuery } from './internal/utils/query';
14
15
  import { VERSION } from './version';
15
16
  import * as Errors from './core/error';
16
17
  import * as Pagination from './core/pagination';
@@ -242,21 +243,8 @@ export class Limrun {
242
243
  /**
243
244
  * Basic re-implementation of `qs.stringify` for primitive types.
244
245
  */
245
- protected stringifyQuery(query: Record<string, unknown>): string {
246
- return Object.entries(query)
247
- .filter(([_, value]) => typeof value !== 'undefined')
248
- .map(([key, value]) => {
249
- if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
250
- return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
251
- }
252
- if (value === null) {
253
- return `${encodeURIComponent(key)}=`;
254
- }
255
- throw new Errors.LimrunError(
256
- `Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
257
- );
258
- })
259
- .join('&');
246
+ protected stringifyQuery(query: object | Record<string, unknown>): string {
247
+ return stringifyQuery(query);
260
248
  }
261
249
 
262
250
  private getUserAgent(): string {
@@ -288,12 +276,13 @@ export class Limrun {
288
276
  : new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
289
277
 
290
278
  const defaultQuery = this.defaultQuery();
291
- if (!isEmptyObj(defaultQuery)) {
292
- query = { ...defaultQuery, ...query };
279
+ const pathQuery = Object.fromEntries(url.searchParams);
280
+ if (!isEmptyObj(defaultQuery) || !isEmptyObj(pathQuery)) {
281
+ query = { ...pathQuery, ...defaultQuery, ...query };
293
282
  }
294
283
 
295
284
  if (typeof query === 'object' && query && !Array.isArray(query)) {
296
- url.search = this.stringifyQuery(query as Record<string, unknown>);
285
+ url.search = this.stringifyQuery(query);
297
286
  }
298
287
 
299
288
  return url.toString();
@@ -622,9 +611,9 @@ export class Limrun {
622
611
  }
623
612
  }
624
613
 
625
- // If the API asks us to wait a certain amount of time (and it's a reasonable amount),
626
- // just do what it says, but otherwise calculate a default
627
- if (!(timeoutMillis && 0 <= timeoutMillis && timeoutMillis < 60 * 1000)) {
614
+ // If the API asks us to wait a certain amount of time, just do what it
615
+ // says, but otherwise calculate a default
616
+ if (timeoutMillis === undefined) {
628
617
  const maxRetries = options.maxRetries ?? this.maxRetries;
629
618
  timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
630
619
  }
@@ -750,6 +739,14 @@ export class Limrun {
750
739
  (Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))
751
740
  ) {
752
741
  return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body as AsyncIterable<Uint8Array>) };
742
+ } else if (
743
+ typeof body === 'object' &&
744
+ headers.values.get('content-type') === 'application/x-www-form-urlencoded'
745
+ ) {
746
+ return {
747
+ bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
748
+ body: this.stringifyQuery(body),
749
+ };
753
750
  } else {
754
751
  return this.#encoder({ body, headers });
755
752
  }
@@ -25,7 +25,7 @@ export type FolderSyncOptions = {
25
25
  */
26
26
  basisCacheDir?: string;
27
27
  install?: boolean;
28
- launchMode?: 'ForegroundIfRunning' | 'RelaunchIfRunning' | 'FailIfRunning';
28
+ launchMode?: 'ForegroundIfRunning' | 'RelaunchIfRunning';
29
29
  /** If true, watch the folder and re-sync on any changes (debounced, single-flight). */
30
30
  watch?: boolean;
31
31
  /** Max patch size (bytes) to send as delta before falling back to full upload. */
@@ -72,7 +72,7 @@ type FolderSyncHttpMeta = {
72
72
  id: string;
73
73
  rootName: string;
74
74
  install?: boolean;
75
- launchMode?: 'ForegroundIfRunning' | 'RelaunchIfRunning' | 'FailIfRunning';
75
+ launchMode?: 'ForegroundIfRunning' | 'RelaunchIfRunning';
76
76
  files: { path: string; size: number; sha256: string; mode: number }[];
77
77
  payloads: FolderSyncHttpPayload[];
78
78
  };