apify-client 3.0.0-beta.0 → 3.0.0-beta.2

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 (84) hide show
  1. package/README.md +2 -2
  2. package/dist/apify_api_error.js +5 -9
  3. package/dist/apify_client.d.ts +27 -27
  4. package/dist/apify_client.js +86 -91
  5. package/dist/argument_validation_error.js +1 -5
  6. package/dist/base/api_client.d.ts +3 -3
  7. package/dist/base/api_client.js +6 -10
  8. package/dist/base/resource_client.d.ts +1 -1
  9. package/dist/base/resource_client.js +14 -18
  10. package/dist/base/resource_collection_client.d.ts +2 -2
  11. package/dist/base/resource_collection_client.js +6 -10
  12. package/dist/body_parser.js +6 -11
  13. package/dist/bundle.js +8 -8
  14. package/dist/bundle.js.map +1 -1
  15. package/dist/generated/api.d.ts +20522 -0
  16. package/dist/generated/api.js +5 -0
  17. package/dist/http_client.d.ts +2 -2
  18. package/dist/http_client.js +23 -28
  19. package/dist/index.d.ts +32 -32
  20. package/dist/index.js +31 -36
  21. package/dist/interceptors.d.ts +1 -1
  22. package/dist/interceptors.js +14 -19
  23. package/dist/models.d.ts +1072 -0
  24. package/dist/models.js +86 -0
  25. package/dist/resource_clients/actor.d.ts +13 -459
  26. package/dist/resource_clients/actor.js +67 -71
  27. package/dist/resource_clients/actor_collection.d.ts +7 -12
  28. package/dist/resource_clients/actor_collection.js +14 -18
  29. package/dist/resource_clients/actor_env_var.d.ts +3 -3
  30. package/dist/resource_clients/actor_env_var.js +4 -8
  31. package/dist/resource_clients/actor_env_var_collection.d.ts +4 -4
  32. package/dist/resource_clients/actor_env_var_collection.js +5 -9
  33. package/dist/resource_clients/actor_version.d.ts +7 -44
  34. package/dist/resource_clients/actor_version.js +12 -22
  35. package/dist/resource_clients/actor_version_collection.d.ts +4 -4
  36. package/dist/resource_clients/actor_version_collection.js +5 -9
  37. package/dist/resource_clients/build.d.ts +5 -80
  38. package/dist/resource_clients/build.js +11 -15
  39. package/dist/resource_clients/build_collection.d.ts +5 -5
  40. package/dist/resource_clients/build_collection.js +8 -12
  41. package/dist/resource_clients/dataset.d.ts +5 -71
  42. package/dist/resource_clients/dataset.js +72 -76
  43. package/dist/resource_clients/dataset_collection.d.ts +4 -4
  44. package/dist/resource_clients/dataset_collection.js +15 -19
  45. package/dist/resource_clients/key_value_store.d.ts +4 -73
  46. package/dist/resource_clients/key_value_store.js +60 -63
  47. package/dist/resource_clients/key_value_store_collection.d.ts +4 -4
  48. package/dist/resource_clients/key_value_store_collection.js +15 -19
  49. package/dist/resource_clients/log.d.ts +2 -2
  50. package/dist/resource_clients/log.js +15 -22
  51. package/dist/resource_clients/request_queue.d.ts +17 -176
  52. package/dist/resource_clients/request_queue.js +93 -98
  53. package/dist/resource_clients/request_queue_collection.d.ts +4 -4
  54. package/dist/resource_clients/request_queue_collection.js +13 -17
  55. package/dist/resource_clients/run.d.ts +8 -8
  56. package/dist/resource_clients/run.js +46 -50
  57. package/dist/resource_clients/run_collection.d.ts +4 -4
  58. package/dist/resource_clients/run_collection.js +13 -17
  59. package/dist/resource_clients/schedule.d.ts +6 -84
  60. package/dist/resource_clients/schedule.js +7 -18
  61. package/dist/resource_clients/schedule_collection.d.ts +4 -4
  62. package/dist/resource_clients/schedule_collection.js +10 -14
  63. package/dist/resource_clients/store_collection.d.ts +5 -33
  64. package/dist/resource_clients/store_collection.js +13 -17
  65. package/dist/resource_clients/task.d.ts +9 -79
  66. package/dist/resource_clients/task.js +44 -48
  67. package/dist/resource_clients/task_collection.d.ts +6 -5
  68. package/dist/resource_clients/task_collection.js +9 -13
  69. package/dist/resource_clients/user.d.ts +5 -181
  70. package/dist/resource_clients/user.js +8 -21
  71. package/dist/resource_clients/webhook.d.ts +6 -65
  72. package/dist/resource_clients/webhook.js +8 -12
  73. package/dist/resource_clients/webhook_collection.d.ts +4 -4
  74. package/dist/resource_clients/webhook_collection.js +10 -14
  75. package/dist/resource_clients/webhook_dispatch.d.ts +5 -38
  76. package/dist/resource_clients/webhook_dispatch.js +3 -12
  77. package/dist/resource_clients/webhook_dispatch_collection.d.ts +4 -4
  78. package/dist/resource_clients/webhook_dispatch_collection.js +8 -12
  79. package/dist/statistics.js +5 -9
  80. package/dist/timezones.js +1 -2
  81. package/dist/utils.d.ts +3 -3
  82. package/dist/utils.js +41 -56
  83. package/package.json +16 -9
  84. package/dist/index.mjs +0 -42
@@ -1,8 +1,9 @@
1
- import type { WEBHOOK_EVENT_TYPES } from '@apify/consts';
2
- import type { ApiClientSubResourceOptions } from '../base/api_client';
3
- import { ResourceClient } from '../base/resource_client';
4
- import type { WebhookDispatch } from './webhook_dispatch';
5
- import { WebhookDispatchCollectionClient } from './webhook_dispatch_collection';
1
+ import type { ApiClientSubResourceOptions } from '../base/api_client.js';
2
+ import { ResourceClient } from '../base/resource_client.js';
3
+ import type { Webhook, WebhookEventType } from '../models.js';
4
+ import type { WebhookDispatch } from './webhook_dispatch.js';
5
+ import { WebhookDispatchCollectionClient } from './webhook_dispatch_collection.js';
6
+ export type { Webhook, WebhookAnyRunOfActorCondition, WebhookAnyRunOfActorTaskCondition, WebhookCertainRunCondition, WebhookCondition, WebhookEventType, WebhookLastDispatch, WebhookStats, } from '../models.js';
6
7
  /**
7
8
  * Client for managing a specific webhook.
8
9
  *
@@ -72,43 +73,6 @@ export declare class WebhookClient extends ResourceClient {
72
73
  */
73
74
  dispatches(): WebhookDispatchCollectionClient;
74
75
  }
75
- /**
76
- * Represents a webhook for receiving notifications about Actor events.
77
- *
78
- * Webhooks send HTTP POST requests to specified URLs when certain events occur
79
- * (e.g., Actor run succeeds, fails, or times out).
80
- */
81
- export interface Webhook {
82
- id: string;
83
- userId: string;
84
- createdAt: Date;
85
- modifiedAt: Date;
86
- isAdHoc: boolean;
87
- eventTypes: WebhookEventType[];
88
- condition: WebhookCondition;
89
- ignoreSslErrors: boolean;
90
- doNotRetry: boolean;
91
- requestUrl: string;
92
- payloadTemplate: string;
93
- lastDispatch: string;
94
- stats: WebhookStats;
95
- /**
96
- * @since Added in 2.7.2
97
- */
98
- shouldInterpolateStrings: boolean;
99
- /**
100
- * @since Added in 2.9.4
101
- */
102
- isApifyIntegration?: boolean;
103
- /**
104
- * @since Added in 2.8.1
105
- */
106
- headersTemplate?: string;
107
- /**
108
- * @since Added in 2.8.1
109
- */
110
- description?: string;
111
- }
112
76
  export interface WebhookIdempotencyKey {
113
77
  idempotencyKey?: string;
114
78
  }
@@ -118,26 +82,3 @@ export interface WebhookIdempotencyKey {
118
82
  export type WebhookUpdateData = Partial<Pick<Webhook, 'isAdHoc' | 'condition' | 'ignoreSslErrors' | 'doNotRetry' | 'requestUrl' | 'payloadTemplate' | 'shouldInterpolateStrings' | 'isApifyIntegration' | 'headersTemplate' | 'description'> & {
119
83
  eventTypes: readonly WebhookEventType[];
120
84
  }> & WebhookIdempotencyKey;
121
- /**
122
- * Statistics about webhook usage.
123
- */
124
- export interface WebhookStats {
125
- totalDispatches: number;
126
- }
127
- /**
128
- * Event types that can trigger webhooks.
129
- */
130
- export type WebhookEventType = (typeof WEBHOOK_EVENT_TYPES)[keyof typeof WEBHOOK_EVENT_TYPES];
131
- /**
132
- * Condition that determines when a webhook should be triggered.
133
- */
134
- export type WebhookCondition = WebhookAnyRunOfActorCondition | WebhookAnyRunOfActorTaskCondition | WebhookCertainRunCondition;
135
- export interface WebhookAnyRunOfActorCondition {
136
- actorId: string;
137
- }
138
- export interface WebhookAnyRunOfActorTaskCondition {
139
- actorTaskId: string;
140
- }
141
- export interface WebhookCertainRunCondition {
142
- actorRunId: string;
143
- }
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebhookClient = void 0;
4
- const resource_client_1 = require("../base/resource_client");
5
- const utils_1 = require("../utils");
6
- const webhook_dispatch_collection_1 = require("./webhook_dispatch_collection");
1
+ import { ResourceClient } from '../base/resource_client.js';
2
+ import { anyObjectSchema, cast, catchNotFoundOrThrow, parseArgument, parseDateFields, pluckData } from '../utils.js';
3
+ import { WebhookDispatchCollectionClient } from './webhook_dispatch_collection.js';
7
4
  /**
8
5
  * Client for managing a specific webhook.
9
6
  *
@@ -32,7 +29,7 @@ const webhook_dispatch_collection_1 = require("./webhook_dispatch_collection");
32
29
  *
33
30
  * @see https://docs.apify.com/platform/integrations/webhooks
34
31
  */
35
- class WebhookClient extends resource_client_1.ResourceClient {
32
+ export class WebhookClient extends ResourceClient {
36
33
  /**
37
34
  * @hidden
38
35
  */
@@ -59,7 +56,7 @@ class WebhookClient extends resource_client_1.ResourceClient {
59
56
  * @see https://docs.apify.com/api/v2/webhook-put
60
57
  */
61
58
  async update(newFields) {
62
- (0, utils_1.parseArgument)(newFields, utils_1.anyObjectSchema);
59
+ parseArgument(newFields, anyObjectSchema);
63
60
  return this._update(newFields);
64
61
  }
65
62
  /**
@@ -84,10 +81,10 @@ class WebhookClient extends resource_client_1.ResourceClient {
84
81
  };
85
82
  try {
86
83
  const response = await this.httpClient.call(request);
87
- return (0, utils_1.cast)((0, utils_1.parseDateFields)((0, utils_1.pluckData)(response.data)));
84
+ return cast(parseDateFields(pluckData(response.data)));
88
85
  }
89
86
  catch (err) {
90
- (0, utils_1.catchNotFoundOrThrow)(err);
87
+ catchNotFoundOrThrow(err);
91
88
  }
92
89
  return undefined;
93
90
  }
@@ -98,9 +95,8 @@ class WebhookClient extends resource_client_1.ResourceClient {
98
95
  * @see https://docs.apify.com/api/v2/webhook-webhook-dispatches-get
99
96
  */
100
97
  dispatches() {
101
- return new webhook_dispatch_collection_1.WebhookDispatchCollectionClient(this._subResourceOptions({
98
+ return new WebhookDispatchCollectionClient(this._subResourceOptions({
102
99
  resourcePath: 'dispatches',
103
100
  }));
104
101
  }
105
102
  }
106
- exports.WebhookClient = WebhookClient;
@@ -1,7 +1,7 @@
1
- import type { ApiClientSubResourceOptions } from '../base/api_client';
2
- import { ResourceCollectionClient } from '../base/resource_collection_client';
3
- import type { PaginatedIterator, PaginationOptions } from '../utils';
4
- import type { Webhook, WebhookUpdateData } from './webhook';
1
+ import type { ApiClientSubResourceOptions } from '../base/api_client.js';
2
+ import { ResourceCollectionClient } from '../base/resource_collection_client.js';
3
+ import type { PaginatedIterator, PaginationOptions } from '../utils.js';
4
+ import type { Webhook, WebhookUpdateData } from './webhook.js';
5
5
  /**
6
6
  * Client for managing the collection of Webhooks.
7
7
  *
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebhookCollectionClient = void 0;
4
- const zod_1 = require("zod");
5
- const resource_collection_client_1 = require("../base/resource_collection_client");
6
- const utils_1 = require("../utils");
7
- const listOptionsSchema = zod_1.z.strictObject({
8
- ...utils_1.paginationOptionsShape,
9
- desc: zod_1.z.boolean().optional(),
1
+ import { z } from 'zod';
2
+ import { ResourceCollectionClient } from '../base/resource_collection_client.js';
3
+ import { anyObjectSchema, paginationOptionsShape, parseArgument } from '../utils.js';
4
+ const listOptionsSchema = z.strictObject({
5
+ ...paginationOptionsShape,
6
+ desc: z.boolean().optional(),
10
7
  });
11
- const webhookCreateSchema = utils_1.anyObjectSchema.optional();
8
+ const webhookCreateSchema = anyObjectSchema.optional();
12
9
  /**
13
10
  * Client for managing the collection of Webhooks.
14
11
  *
@@ -32,7 +29,7 @@ const webhookCreateSchema = utils_1.anyObjectSchema.optional();
32
29
  *
33
30
  * @see https://docs.apify.com/platform/integrations/webhooks
34
31
  */
35
- class WebhookCollectionClient extends resource_collection_client_1.ResourceCollectionClient {
32
+ export class WebhookCollectionClient extends ResourceCollectionClient {
36
33
  /**
37
34
  * @hidden
38
35
  */
@@ -63,7 +60,7 @@ class WebhookCollectionClient extends resource_collection_client_1.ResourceColle
63
60
  * @see https://docs.apify.com/api/v2/webhooks-get
64
61
  */
65
62
  list(options = {}) {
66
- const parsed = (0, utils_1.parseArgument)(options, listOptionsSchema, 'WebhookCollectionListOptions');
63
+ const parsed = parseArgument(options, listOptionsSchema, 'WebhookCollectionListOptions');
67
64
  return this._listPaginated(parsed);
68
65
  }
69
66
  /**
@@ -74,8 +71,7 @@ class WebhookCollectionClient extends resource_collection_client_1.ResourceColle
74
71
  * @see https://docs.apify.com/api/v2/webhooks-post
75
72
  */
76
73
  async create(webhook) {
77
- (0, utils_1.parseArgument)(webhook, webhookCreateSchema);
74
+ parseArgument(webhook, webhookCreateSchema);
78
75
  return this._create(webhook);
79
76
  }
80
77
  }
81
- exports.WebhookCollectionClient = WebhookCollectionClient;
@@ -1,6 +1,8 @@
1
- import type { ApiClientSubResourceOptions } from '../base/api_client';
2
- import { ResourceClient } from '../base/resource_client';
3
- import type { Webhook, WebhookEventType } from './webhook';
1
+ import type { ApiClientSubResourceOptions } from '../base/api_client.js';
2
+ import { ResourceClient } from '../base/resource_client.js';
3
+ import type { WebhookDispatch } from '../models.js';
4
+ export type { WebhookDispatch, WebhookDispatchCall, WebhookDispatchEventData, WebhookDispatchWebhookSummary, } from '../models.js';
5
+ export { WebhookDispatchStatus } from '../models.js';
4
6
  /**
5
7
  * Client for managing a specific webhook dispatch.
6
8
  *
@@ -32,38 +34,3 @@ export declare class WebhookDispatchClient extends ResourceClient {
32
34
  */
33
35
  get(): Promise<WebhookDispatch | undefined>;
34
36
  }
35
- export interface WebhookDispatch {
36
- id: string;
37
- userId: string;
38
- webhookId: string;
39
- createdAt: Date;
40
- status: WebhookDispatchStatus;
41
- eventType: WebhookEventType;
42
- calls: WebhookDispatchCall[];
43
- webhook: Pick<Webhook, 'requestUrl' | 'isAdHoc'>;
44
- /**
45
- * @since Added in 2.13.0
46
- */
47
- eventData: WebhookDispatchEventData | null;
48
- }
49
- export declare enum WebhookDispatchStatus {
50
- Active = "ACTIVE",
51
- Succeeded = "SUCCEEDED",
52
- Failed = "FAILED"
53
- }
54
- export interface WebhookDispatchCall {
55
- startedAt: Date;
56
- finishedAt: Date;
57
- errorMessage: string | null;
58
- responseStatus: number | null;
59
- responseBody: string | null;
60
- }
61
- /**
62
- * @since Added in 2.13.0
63
- */
64
- export interface WebhookDispatchEventData {
65
- actorRunId?: string;
66
- actorId?: string;
67
- actorTaskId?: string;
68
- actorBuildId?: string;
69
- }
@@ -1,7 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebhookDispatchStatus = exports.WebhookDispatchClient = void 0;
4
- const resource_client_1 = require("../base/resource_client");
1
+ import { ResourceClient } from '../base/resource_client.js';
2
+ export { WebhookDispatchStatus } from '../models.js';
5
3
  /**
6
4
  * Client for managing a specific webhook dispatch.
7
5
  *
@@ -20,7 +18,7 @@ const resource_client_1 = require("../base/resource_client");
20
18
  *
21
19
  * @see https://docs.apify.com/platform/integrations/webhooks
22
20
  */
23
- class WebhookDispatchClient extends resource_client_1.ResourceClient {
21
+ export class WebhookDispatchClient extends ResourceClient {
24
22
  /**
25
23
  * @hidden
26
24
  */
@@ -40,10 +38,3 @@ class WebhookDispatchClient extends resource_client_1.ResourceClient {
40
38
  return this._get();
41
39
  }
42
40
  }
43
- exports.WebhookDispatchClient = WebhookDispatchClient;
44
- var WebhookDispatchStatus;
45
- (function (WebhookDispatchStatus) {
46
- WebhookDispatchStatus["Active"] = "ACTIVE";
47
- WebhookDispatchStatus["Succeeded"] = "SUCCEEDED";
48
- WebhookDispatchStatus["Failed"] = "FAILED";
49
- })(WebhookDispatchStatus || (exports.WebhookDispatchStatus = WebhookDispatchStatus = {}));
@@ -1,7 +1,7 @@
1
- import type { ApiClientSubResourceOptions } from '../base/api_client';
2
- import { ResourceCollectionClient } from '../base/resource_collection_client';
3
- import type { PaginatedIterator, PaginationOptions } from '../utils';
4
- import type { WebhookDispatch } from './webhook_dispatch';
1
+ import type { ApiClientSubResourceOptions } from '../base/api_client.js';
2
+ import { ResourceCollectionClient } from '../base/resource_collection_client.js';
3
+ import type { PaginatedIterator, PaginationOptions } from '../utils.js';
4
+ import type { WebhookDispatch } from './webhook_dispatch.js';
5
5
  /**
6
6
  * Client for managing the collection of webhook dispatches.
7
7
  *
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebhookDispatchCollectionClient = void 0;
4
- const zod_1 = require("zod");
5
- const resource_collection_client_1 = require("../base/resource_collection_client");
6
- const utils_1 = require("../utils");
7
- const listOptionsSchema = zod_1.z.strictObject({
8
- ...utils_1.paginationOptionsShape,
9
- desc: zod_1.z.boolean().optional(),
1
+ import { z } from 'zod';
2
+ import { ResourceCollectionClient } from '../base/resource_collection_client.js';
3
+ import { paginationOptionsShape, parseArgument } from '../utils.js';
4
+ const listOptionsSchema = z.strictObject({
5
+ ...paginationOptionsShape,
6
+ desc: z.boolean().optional(),
10
7
  });
11
8
  /**
12
9
  * Client for managing the collection of webhook dispatches.
@@ -26,7 +23,7 @@ const listOptionsSchema = zod_1.z.strictObject({
26
23
  *
27
24
  * @see https://docs.apify.com/platform/integrations/webhooks
28
25
  */
29
- class WebhookDispatchCollectionClient extends resource_collection_client_1.ResourceCollectionClient {
26
+ export class WebhookDispatchCollectionClient extends ResourceCollectionClient {
30
27
  /**
31
28
  * @hidden
32
29
  */
@@ -57,8 +54,7 @@ class WebhookDispatchCollectionClient extends resource_collection_client_1.Resou
57
54
  * @see https://docs.apify.com/api/v2/webhook-dispatches-get
58
55
  */
59
56
  list(options = {}) {
60
- const parsed = (0, utils_1.parseArgument)(options, listOptionsSchema, 'WebhookDispatchCollectionListOptions');
57
+ const parsed = parseArgument(options, listOptionsSchema, 'WebhookDispatchCollectionListOptions');
61
58
  return this._listPaginated(parsed);
62
59
  }
63
60
  }
64
- exports.WebhookDispatchCollectionClient = WebhookDispatchCollectionClient;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Statistics = void 0;
4
- const zod_1 = require("zod");
5
- const utils_1 = require("./utils");
6
- const attemptSchema = zod_1.z.number().gt(0);
7
- class Statistics {
1
+ import { z } from 'zod';
2
+ import { parseArgument } from './utils.js';
3
+ const attemptSchema = z.number().gt(0);
4
+ export class Statistics {
8
5
  /**
9
6
  * Number of Apify client function calls
10
7
  */
@@ -19,7 +16,7 @@ class Statistics {
19
16
  */
20
17
  rateLimitErrors = [];
21
18
  addRateLimitError(attempt) {
22
- (0, utils_1.parseArgument)(attempt, attemptSchema);
19
+ parseArgument(attempt, attemptSchema);
23
20
  // attempt is never 0,
24
21
  // but we don't want index 0 empty
25
22
  const index = attempt - 1;
@@ -41,4 +38,3 @@ class Statistics {
41
38
  }
42
39
  }
43
40
  }
44
- exports.Statistics = Statistics;
package/dist/timezones.js CHANGED
@@ -1,8 +1,6 @@
1
- "use strict";
2
1
  // This contains exactly the list of timezones supported by 'moment-timezone' package, you can fetch it using:
3
2
  // require('moment-timzone').tz.names()
4
3
  // This should be kept in sync with timezones.js in storage
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
4
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
7
5
  const timezones = [
8
6
  'Africa/Abidjan',
@@ -599,3 +597,4 @@ const timezones = [
599
597
  'WET',
600
598
  'Zulu',
601
599
  ];
600
+ export {};
package/dist/utils.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { Readable } from 'node:stream';
2
2
  import type { JsonValue, TypedArray } from 'type-fest';
3
3
  import { z } from 'zod';
4
- import type { ApifyApiError } from './apify_api_error';
5
- import type { RequestQueueClientListRequestsOptions, RequestQueueClientListRequestsResult } from './resource_clients/request_queue';
6
- import type { WebhookUpdateData } from './resource_clients/webhook';
4
+ import type { ApifyApiError } from './apify_api_error.js';
5
+ import type { RequestQueueClientListRequestsOptions, RequestQueueClientListRequestsResult } from './resource_clients/request_queue.js';
6
+ import type { WebhookUpdateData } from './resource_clients/webhook.js';
7
7
  /**
8
8
  * Parses `value` with `schema`, returning the typed result (with schema defaults applied).
9
9
  * Throws {@link ArgumentValidationError} on failure.
package/dist/utils.js CHANGED
@@ -1,25 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mutuallyExclusive = exports.paginationOptionsShape = exports.RequestQueuePaginationIterator = exports.anyObjectSchema = void 0;
4
- exports.parseArgument = parseArgument;
5
- exports.isNonArrayObject = isNonArrayObject;
6
- exports.pluckData = pluckData;
7
- exports.catchNotFoundOrThrow = catchNotFoundOrThrow;
8
- exports.parseDateFields = parseDateFields;
9
- exports.stringifyWebhooksToBase64 = stringifyWebhooksToBase64;
10
- exports.maybeCompressValue = maybeCompressValue;
11
- exports.sliceArrayByByteLength = sliceArrayByByteLength;
12
- exports.isNode = isNode;
13
- exports.isBuffer = isBuffer;
14
- exports.isStream = isStream;
15
- exports.getVersionData = getVersionData;
16
- exports.cast = cast;
17
- exports.asArray = asArray;
18
- exports.applyQueryParamsToUrl = applyQueryParamsToUrl;
19
- exports.toPathSegment = toPathSegment;
20
- exports.toPath = toPath;
21
- const zod_1 = require("zod");
22
- const argument_validation_error_1 = require("./argument_validation_error");
1
+ import { z } from 'zod';
2
+ import { ArgumentValidationError } from './argument_validation_error.js';
3
+ // @ts-ignore if we enable `resolveJsonModule`, we end up with a `src` folder in `dist`
4
+ import packageJson from '../package.json' with { type: 'json' };
23
5
  const NOT_FOUND_STATUS_CODE = 404;
24
6
  const RECORD_NOT_FOUND_TYPE = 'record-not-found';
25
7
  const RECORD_OR_TOKEN_NOT_FOUND_TYPE = 'record-or-token-not-found';
@@ -27,7 +9,7 @@ const MIN_COMPRESS_BYTES = 1024;
27
9
  // Zod installs its English locale as a module-level side effect but ships `"sideEffects": false`, so
28
10
  // any tree-shaking bundler drops it and every message degrades to a bare "Invalid input". Passing it
29
11
  // in per parse keeps them intact without reaching into the zod config the whole process shares.
30
- const { localeError } = zod_1.z.locales.en();
12
+ const { localeError } = z.locales.en();
31
13
  /**
32
14
  * Parses `value` with `schema`, returning the typed result (with schema defaults applied).
33
15
  * Throws {@link ArgumentValidationError} on failure.
@@ -36,10 +18,10 @@ const { localeError } = zod_1.z.locales.en();
36
18
  * (e.g. ``... at `memory` in `ActorStartOptions` ``).
37
19
  * @internal
38
20
  */
39
- function parseArgument(value, schema, label) {
21
+ export function parseArgument(value, schema, label) {
40
22
  const result = schema.safeParse(value, { error: localeError });
41
23
  if (!result.success) {
42
- throw new argument_validation_error_1.ArgumentValidationError(result.error, value, label);
24
+ throw new ArgumentValidationError(result.error, value, label);
43
25
  }
44
26
  return result.data;
45
27
  }
@@ -47,7 +29,7 @@ function parseArgument(value, schema, label) {
47
29
  * Accepts any non-null, non-array object as a predicate for `z.custom()`.
48
30
  * @internal
49
31
  */
50
- function isNonArrayObject(value) {
32
+ export function isNonArrayObject(value) {
51
33
  return typeof value === 'object' && value !== null && !Array.isArray(value);
52
34
  }
53
35
  /**
@@ -56,14 +38,14 @@ function isNonArrayObject(value) {
56
38
  * the value itself instead of a copy.
57
39
  * @internal
58
40
  */
59
- exports.anyObjectSchema = zod_1.z.custom(isNonArrayObject, {
41
+ export const anyObjectSchema = z.custom(isNonArrayObject, {
60
42
  error: 'Invalid input: expected an object',
61
43
  });
62
44
  /**
63
45
  * Returns object's 'data' property or throws if parameter is not an object,
64
46
  * or an object without a 'data' property.
65
47
  */
66
- function pluckData(obj) {
48
+ export function pluckData(obj) {
67
49
  if (typeof obj === 'object' && obj) {
68
50
  if (typeof obj.data !== 'undefined')
69
51
  return obj.data;
@@ -74,7 +56,7 @@ function pluckData(obj) {
74
56
  * If given HTTP error has NOT_FOUND_STATUS_CODE status code then returns undefined.
75
57
  * Otherwise rethrows error.
76
58
  */
77
- function catchNotFoundOrThrow(err) {
59
+ export function catchNotFoundOrThrow(err) {
78
60
  const isNotFoundStatus = err.statusCode === NOT_FOUND_STATUS_CODE;
79
61
  const isNotFoundMessage = err.type === RECORD_NOT_FOUND_TYPE || err.type === RECORD_OR_TOKEN_NOT_FOUND_TYPE || err.httpMethod === 'head';
80
62
  const isNotFoundError = isNotFoundStatus && isNotFoundMessage;
@@ -91,11 +73,17 @@ function catchNotFoundOrThrow(err) {
91
73
  *
92
74
  * If the field cannot be converted to Date, it is left as is.
93
75
  */
94
- function parseDateFields(input, shouldParseField = null, depth = 0) {
95
- // Don't go too deep to avoid stack overflows (especially if there is a circular reference). The depth of 3
96
- // corresponds to obj.data.someArrayField.[x].field and should be generally enough.
76
+ export function parseDateFields(input, shouldParseField = null, depth = 0) {
77
+ // Don't go too deep to avoid stack overflows (especially if there is a circular reference). The depth of 4
78
+ // corresponds to obj.items.[x].someArrayField.[y].field, which is what a list response looks like: it
79
+ // nests one level deeper than the single resource it wraps, because both the item array and the nested
80
+ // array spend a level.
81
+ //
82
+ // In a list response it also reaches one level into caller-owned blobs the API stores verbatim, so a
83
+ // listed request's `userData.foo.somethingAt` comes back as a `Date` rather than the string it was
84
+ // written as.
97
85
  // TODO: Consider removing this limitation. It might came across as an annoying surprise as it's not communicated.
98
- if (depth > 3) {
86
+ if (depth > 4) {
99
87
  return input;
100
88
  }
101
89
  if (Array.isArray(input))
@@ -125,7 +113,7 @@ function parseDateFields(input, shouldParseField = null, depth = 0) {
125
113
  /**
126
114
  * Helper function that converts array of webhooks to base64 string
127
115
  */
128
- function stringifyWebhooksToBase64(webhooks) {
116
+ export function stringifyWebhooksToBase64(webhooks) {
129
117
  if (!webhooks)
130
118
  return;
131
119
  const webhooksJson = JSON.stringify(webhooks);
@@ -166,7 +154,7 @@ async function gzipValue(value) {
166
154
  * Compress the passed value using brotli, falling back to gzip. Returns undefined if the data is
167
155
  * too small / wrong type, or if neither algorithm is available.
168
156
  */
169
- async function maybeCompressValue(value) {
157
+ export async function maybeCompressValue(value) {
170
158
  if (!isNode())
171
159
  return undefined;
172
160
  // Request compression is not that important so let's
@@ -195,7 +183,7 @@ async function maybeCompressValue(value) {
195
183
  /**
196
184
  * Helper function slice the items from array to fit the max byte length.
197
185
  */
198
- function sliceArrayByByteLength(array, maxByteLength, startIndex) {
186
+ export function sliceArrayByByteLength(array, maxByteLength, startIndex) {
199
187
  const stringByteLength = (str) => (isNode() ? Buffer.byteLength(str) : new Blob([str]).size);
200
188
  const arrayByteLength = stringByteLength(JSON.stringify(array));
201
189
  if (arrayByteLength < maxByteLength)
@@ -216,12 +204,12 @@ function sliceArrayByByteLength(array, maxByteLength, startIndex) {
216
204
  }
217
205
  return slicedArray;
218
206
  }
219
- function isNode() {
207
+ export function isNode() {
220
208
  if (typeof BROWSER_BUILD !== 'undefined')
221
209
  return false;
222
210
  return !!(typeof process !== 'undefined' && process.versions && process.versions.node);
223
211
  }
224
- function isBuffer(value) {
212
+ export function isBuffer(value) {
225
213
  // Tag checks rather than `instanceof`, to also match buffers from another realm. `isView()`
226
214
  // additionally covers `DataView`, which is not raw binary content.
227
215
  if (ArrayBuffer.isView(value))
@@ -231,23 +219,22 @@ function isBuffer(value) {
231
219
  function isTagged(value, tag) {
232
220
  return Object.prototype.toString.call(value) === `[object ${tag}]`;
233
221
  }
234
- function isStream(value) {
222
+ export function isStream(value) {
235
223
  if (value === null || typeof value !== 'object')
236
224
  return false;
237
225
  const { on, pipe } = value;
238
226
  return typeof on === 'function' && typeof pipe === 'function';
239
227
  }
240
- function getVersionData() {
228
+ export function getVersionData() {
241
229
  if (typeof BROWSER_BUILD !== 'undefined') {
242
230
  return { version: VERSION };
243
231
  }
244
- // eslint-disable-next-line
245
- return require('../package.json');
232
+ return packageJson;
246
233
  }
247
234
  /**
248
235
  * Helper class to create async iterators from paginated list endpoints with exclusive start key.
249
236
  */
250
- class RequestQueuePaginationIterator {
237
+ export class RequestQueuePaginationIterator {
251
238
  maxPageLimit;
252
239
  getPage;
253
240
  limit;
@@ -287,21 +274,20 @@ class RequestQueuePaginationIterator {
287
274
  }
288
275
  }
289
276
  }
290
- exports.RequestQueuePaginationIterator = RequestQueuePaginationIterator;
291
277
  /**
292
278
  * Schema shape of {@link PaginationOptions}, to spread into every paginating client's list schema. One
293
279
  * copy stops it drifting from the interface.
294
280
  * @internal
295
281
  */
296
- exports.paginationOptionsShape = {
297
- limit: zod_1.z.number().min(0).optional(),
298
- offset: zod_1.z.number().min(0).optional(),
299
- chunkSize: zod_1.z.number().positive().optional(),
282
+ export const paginationOptionsShape = {
283
+ limit: z.number().min(0).optional(),
284
+ offset: z.number().min(0).optional(),
285
+ chunkSize: z.number().positive().optional(),
300
286
  };
301
- function cast(input) {
287
+ export function cast(input) {
302
288
  return input;
303
289
  }
304
- function asArray(value) {
290
+ export function asArray(value) {
305
291
  if (Array.isArray(value)) {
306
292
  return value;
307
293
  }
@@ -310,7 +296,7 @@ function asArray(value) {
310
296
  /**
311
297
  * Adds query parameters to a given URL based on the provided options object.
312
298
  */
313
- function applyQueryParamsToUrl(url, options) {
299
+ export function applyQueryParamsToUrl(url, options) {
314
300
  for (const [key, value] of Object.entries(options ?? {})) {
315
301
  // skip undefined values
316
302
  if (value === undefined)
@@ -329,12 +315,11 @@ function applyQueryParamsToUrl(url, options) {
329
315
  * is present. Pass the options interface as `T`, so that a misspelled key is a type error.
330
316
  * @internal
331
317
  */
332
- const mutuallyExclusive = (...keys) => [
318
+ export const mutuallyExclusive = (...keys) => [
333
319
  (value) => keys.filter((key) => typeof value[key] !== 'undefined').length <= 1,
334
320
  `At most one of the following fields is allowed: ${keys.join(', ')}`,
335
321
  ];
336
- exports.mutuallyExclusive = mutuallyExclusive;
337
- const pathSegmentSchema = zod_1.z
322
+ const pathSegmentSchema = z
338
323
  .string()
339
324
  .nonempty()
340
325
  .refine((v) => v !== '.' && v !== '..', { error: 'URL path must not contain dot segments' });
@@ -344,7 +329,7 @@ const pathSegmentSchema = zod_1.z
344
329
  * Empty strings and dot segments are rejected instead of encoded, because URL parsers resolve
345
330
  * dot segments after decoding - `records/%2E%2E` collapses to the parent endpoint just like `records/..`.
346
331
  */
347
- function toPathSegment(value) {
332
+ export function toPathSegment(value) {
348
333
  const valueParsed = parseArgument(value, pathSegmentSchema);
349
334
  return encodeURIComponent(valueParsed);
350
335
  }
@@ -352,6 +337,6 @@ function toPathSegment(value) {
352
337
  * Builds a URL path from segments. A plain string is used as-is, so literal paths such as
353
338
  * `requests/batch` keep their separators; an array has each of its segments encoded individually.
354
339
  */
355
- function toPath(path) {
340
+ export function toPath(path) {
356
341
  return Array.isArray(path) ? path.map(toPathSegment).join('/') : path;
357
342
  }