@apify/utilities 2.9.6 → 2.9.8
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/{index.js → cjs/index.cjs} +1 -1
- package/cjs/index.cjs.map +1 -0
- package/cjs/index.d.ts +540 -0
- package/esm/index.d.mts +540 -0
- package/esm/index.mjs.map +1 -0
- package/package.json +16 -11
- package/code_hash_manager.d.ts +0 -34
- package/crypto.d.ts +0 -36
- package/exponential_backoff.d.ts +0 -12
- package/health_checker.d.ts +0 -61
- package/index.d.ts +0 -10
- package/index.js.map +0 -1
- package/index.mjs.map +0 -1
- package/parse_jsonl_stream.d.ts +0 -26
- package/streams_utilities.d.ts +0 -12
- package/url_params_utils.d.ts +0 -7
- package/utilities.client.d.ts +0 -125
- package/utilities.d.ts +0 -113
- package/webhook_payload_template.d.ts +0 -114
- /package/{index.mjs → esm/index.mjs} +0 -0
package/utilities.client.d.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* This module contains various client-side utility and helper functions.
|
|
3
|
-
*
|
|
4
|
-
* Author: Jan Curn (jan@apify.com)
|
|
5
|
-
* Copyright(c) 2016 Apify. All rights reserved.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Returns true if object equals null or undefined, otherwise returns false.
|
|
10
|
-
*/
|
|
11
|
-
export declare function isNullOrUndefined(obj: unknown): boolean;
|
|
12
|
-
export declare function isBuffer(obj: any): boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Converts Date object to ISO string.
|
|
15
|
-
*/
|
|
16
|
-
export declare function dateToString(date: Date, middleT: boolean): string;
|
|
17
|
-
/**
|
|
18
|
-
* Ensures a string is shorter than a specified number of character, and truncates it if not,
|
|
19
|
-
* appending a specific suffix to it.
|
|
20
|
-
* @param str
|
|
21
|
-
* @param maxLength
|
|
22
|
-
* @param [suffix] Suffix to be appended to truncated string. Defaults to "...[truncated]".
|
|
23
|
-
*/
|
|
24
|
-
export declare function truncate(str: string, maxLength: number, suffix?: string): string;
|
|
25
|
-
/**
|
|
26
|
-
* Gets ordinal suffix for a number (e.g. "nd" for 2).
|
|
27
|
-
*/
|
|
28
|
-
export declare function getOrdinalSuffix(num: number): string;
|
|
29
|
-
interface Uri {
|
|
30
|
-
protocol?: string;
|
|
31
|
-
host?: string;
|
|
32
|
-
path?: string;
|
|
33
|
-
query?: string;
|
|
34
|
-
fragment?: string;
|
|
35
|
-
fragmentKey?: Record<string, unknown>;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* @deprecated use `new URL()` instead
|
|
39
|
-
*/
|
|
40
|
-
export declare function parseUrl(str: string): Uri;
|
|
41
|
-
export declare function normalizeUrl(url: string, keepFragment?: boolean): string | null;
|
|
42
|
-
export declare function markedSetNofollowLinks(href: string, title: string, text: string): string;
|
|
43
|
-
export declare function markedDecreaseHeadsLevel(text: string, level: number): string;
|
|
44
|
-
/**
|
|
45
|
-
* Converts integer version number previously generated by buildNumberToInt() or versionNumberToInt()
|
|
46
|
-
* to string in a form 'MAJOR.MINOR' or 'MAJOR.MINOR.BUILD' in case build number is non-zero.
|
|
47
|
-
*/
|
|
48
|
-
export declare function buildOrVersionNumberIntToStr(int: number): string | null;
|
|
49
|
-
/**
|
|
50
|
-
* If a property name is invalid for MongoDB or BSON, the function transforms
|
|
51
|
-
* it to a valid form, which can be (most of the time) reversed back using unescapePropertyName().
|
|
52
|
-
* For a detailed list of transformations, see escapeForBson().
|
|
53
|
-
* @private
|
|
54
|
-
*/
|
|
55
|
-
export declare function escapePropertyName(name: string): string;
|
|
56
|
-
/**
|
|
57
|
-
* Reverses a string transformed using escapePropertyName() back to its original form.
|
|
58
|
-
* Note that the reverse transformation might not be 100% correct for certain unlikely-to-occur strings
|
|
59
|
-
* (e.g. string contain null chars).
|
|
60
|
-
* @private
|
|
61
|
-
*/
|
|
62
|
-
export declare function unescapePropertyName(name: string): string;
|
|
63
|
-
/**
|
|
64
|
-
* Traverses an object, creates a deep clone if requested and transforms object keys and values using a provided function.
|
|
65
|
-
* The `traverseObject` is recursive, hence if the input object has circular references, the function will run into
|
|
66
|
-
* and infinite recursion and crash the Node.js process.
|
|
67
|
-
* @param obj Object to traverse, it must not contain circular references!
|
|
68
|
-
* @param clone If true, object is not modified but cloned.
|
|
69
|
-
* @param transformFunc Function used to transform the property names na value.
|
|
70
|
-
* It has the following signature: `(key, value) => [key, value]`.
|
|
71
|
-
* Beware that the transformed value is only set if it !== old value.
|
|
72
|
-
* @returns {*}
|
|
73
|
-
* @private
|
|
74
|
-
*/
|
|
75
|
-
export declare function traverseObject(obj: Record<string, any>, clone: boolean, transformFunc: (key: string, value: unknown) => [string, unknown]): any[] | Record<string, any>;
|
|
76
|
-
/**
|
|
77
|
-
* Transforms an object so that it can be stored to MongoDB or serialized to BSON.
|
|
78
|
-
* It does so by transforming prohibited property names (e.g. names starting with "$",
|
|
79
|
-
* containing "." or null char, equal to "toBSON" or "_bsontype") to equivalent full-width Unicode chars
|
|
80
|
-
* which are normally allowed. To revert this transformation, use unescapeFromBson().
|
|
81
|
-
* @param obj Object to be transformed. It must not contain circular references or any complex types (e.g. Maps, Promises etc.)!
|
|
82
|
-
* @param clone If true, the function transforms a deep clone of the object rather than the original object.
|
|
83
|
-
* @returns {*} Transformed object
|
|
84
|
-
*/
|
|
85
|
-
export declare function escapeForBson(obj: Record<string, any>, clone?: boolean): any[] | Record<string, any>;
|
|
86
|
-
/**
|
|
87
|
-
* Reverts a transformation of object property names performed by escapeForBson().
|
|
88
|
-
* Note that the reverse transformation might not be 100% equal to the original object
|
|
89
|
-
* for certain unlikely-to-occur property name (e.g. one contain null chars or full-width Unicode chars).
|
|
90
|
-
* @param obj Object to be transformed. It must not contain circular references or any complex types (e.g. Maps, Promises etc.)!
|
|
91
|
-
* @param clone If true, the function transforms a deep clone of the object rather than the original object.
|
|
92
|
-
* @returns {*} Transformed object.
|
|
93
|
-
*/
|
|
94
|
-
export declare function unescapeFromBson(obj: Record<string, any>, clone?: boolean): Record<string, any>;
|
|
95
|
-
/**
|
|
96
|
-
* Determines whether an object contains property names that cannot be stored to MongoDB.
|
|
97
|
-
* See escapeForBson() for more details.
|
|
98
|
-
* Note that this function only works with objects that are serializable to JSON!
|
|
99
|
-
* @param obj Object to be checked. It must not contain circular references or any complex types (e.g. Maps, Promises etc.)!
|
|
100
|
-
* @returns {boolean} Returns true if object is invalid, otherwise it returns false.
|
|
101
|
-
*/
|
|
102
|
-
export declare function isBadForMongo(obj: Record<string, any>): boolean;
|
|
103
|
-
export declare class JsonVariable {
|
|
104
|
-
readonly name: string;
|
|
105
|
-
constructor(name: string);
|
|
106
|
-
getToken(): string;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Stringifies provided value to JSON with a difference that supports functions that
|
|
110
|
-
* are stringified using .toString() method.
|
|
111
|
-
*
|
|
112
|
-
* In addition to that supports instances of JsonVariable('my.token') that are replaced
|
|
113
|
-
* with a {{my.token}}.
|
|
114
|
-
*/
|
|
115
|
-
export declare function jsonStringifyExtended(value: Record<string, any>, replacer?: ((k: string, val: unknown) => unknown) | null, space?: number): string;
|
|
116
|
-
/**
|
|
117
|
-
* Splits a full name into the first name and last name, trimming all internal and external spaces.
|
|
118
|
-
* Returns an array with two elements or null if splitting is not possible.
|
|
119
|
-
*/
|
|
120
|
-
export declare function splitFullName(fullName: string): (string | null)[];
|
|
121
|
-
/**
|
|
122
|
-
* Perform a Regex test on a given URL to see if it is relative.
|
|
123
|
-
*/
|
|
124
|
-
export declare function isUrlRelative(url: string): boolean;
|
|
125
|
-
export {};
|
package/utilities.d.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* This module contains various server utility and helper functions.
|
|
3
|
-
* Note that it automatically exports functions from utilities.client.js
|
|
4
|
-
*
|
|
5
|
-
* Author: Jan Curn (jan@apify.com)
|
|
6
|
-
* Copyright(c) 2015 Apify. All rights reserved.
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
import { Log } from '@apify/log';
|
|
10
|
-
/**
|
|
11
|
-
* Generates a random cryptographically strong string consisting of 17 alphanumeric characters.
|
|
12
|
-
* This string is similar to MongoDB ObjectIds generated by Meteor.
|
|
13
|
-
*/
|
|
14
|
-
export declare function cryptoRandomObjectId(length?: number): string;
|
|
15
|
-
/**
|
|
16
|
-
* Generates unique, deterministic record ID from the provided key with given length (defaults to 17).
|
|
17
|
-
*/
|
|
18
|
-
export declare function deterministicUniqueId(key: string, length?: number): string;
|
|
19
|
-
/**
|
|
20
|
-
* Returns a random integer between 0 and max (excluded, unless it is also 0).
|
|
21
|
-
* @param {number} maxExcluded
|
|
22
|
-
* @returns {number}
|
|
23
|
-
*/
|
|
24
|
-
export declare function getRandomInt(maxExcluded: number): number;
|
|
25
|
-
/**
|
|
26
|
-
* If 'date' is a String, this function converts and returns it as a Date object.
|
|
27
|
-
* Otherwise, the function returns the original 'date' argument.
|
|
28
|
-
* This function is useful to convert dates transfered via JSON which doesn't natively support dates.
|
|
29
|
-
*/
|
|
30
|
-
export declare function parseDateFromJson(date: string | Date): Date;
|
|
31
|
-
/**
|
|
32
|
-
* Returns a Promise object that will wait a specific number of milliseconds.
|
|
33
|
-
* @param {number} millis Time to wait. If the value is not larger than zero, the promise resolves immediately.
|
|
34
|
-
*/
|
|
35
|
-
export declare function delayPromise(millis: number): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* Removes an element from an array.
|
|
38
|
-
*/
|
|
39
|
-
export declare function removeFromArray<T>(array: T[], element: T): boolean;
|
|
40
|
-
interface RequestLike {
|
|
41
|
-
url: string;
|
|
42
|
-
}
|
|
43
|
-
interface ResponseLike {
|
|
44
|
-
status: (code: number) => void;
|
|
45
|
-
send: (payload: string) => void;
|
|
46
|
-
headersSent?: boolean;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* A default route for HTTP 404 error page for API endpoints.
|
|
50
|
-
*/
|
|
51
|
-
export declare function http404Route(req: RequestLike, res: ResponseLike): void;
|
|
52
|
-
/**
|
|
53
|
-
* Default error handler of Express API endpoints.
|
|
54
|
-
*/
|
|
55
|
-
export declare function expressErrorHandler(err: Error, req: RequestLike, res: ResponseLike, next: (...a: unknown[]) => unknown): unknown;
|
|
56
|
-
export type BetterIntervalID = {
|
|
57
|
-
_betterClearInterval: () => void;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Similar to setInterval() but with two important differences:
|
|
61
|
-
* First, it assumes the function is asynchronous and only schedules its next invocation AFTER the asynchronous function finished.
|
|
62
|
-
* Second, it invokes the function immediately.
|
|
63
|
-
* @param func Asynchronous function to be periodically executed. It must take a single argument with a callback that
|
|
64
|
-
* the function must invoke after it's done.
|
|
65
|
-
* @param delay The number of milliseconds to wait to next invocation of the function.
|
|
66
|
-
* @returns Object that can be passed to betterClearInterval()
|
|
67
|
-
*/
|
|
68
|
-
export declare function betterSetInterval(func: (a: (...args: unknown[]) => unknown) => void, delay: number): BetterIntervalID;
|
|
69
|
-
export declare function betterClearInterval(intervalID: BetterIntervalID): void;
|
|
70
|
-
/**
|
|
71
|
-
* Escapes a string so that it can be used in regular expression (e.g. converts "myfile.*" to "myfile\\.\\*").
|
|
72
|
-
*/
|
|
73
|
-
export declare function escapeRegExp(str: string): string;
|
|
74
|
-
/**
|
|
75
|
-
* String left pad
|
|
76
|
-
*/
|
|
77
|
-
export declare function leftpad(str: string, len: number, ch?: string | number): string;
|
|
78
|
-
/**
|
|
79
|
-
* Computes weighted average of 2 values.
|
|
80
|
-
*/
|
|
81
|
-
export declare function weightedAverage(val1: number, weight1: number, val2: number, weight2: number): number;
|
|
82
|
-
/**
|
|
83
|
-
* Checks whether username is listed in FORBIDDEN_USERNAMES
|
|
84
|
-
* or matches any root route path.
|
|
85
|
-
*/
|
|
86
|
-
export declare function isForbiddenUsername(username: string): boolean;
|
|
87
|
-
/**
|
|
88
|
-
* Executes array of promises in sequence and then returns array where Nth item is result of Nth promise.
|
|
89
|
-
*/
|
|
90
|
-
export declare function sequentializePromises<T>(promises: (Promise<T> | (() => Promise<T>))[]): Promise<T[]>;
|
|
91
|
-
/**
|
|
92
|
-
* Helper function for validation if parameter is an instance of given prototype or multiple prototypes.
|
|
93
|
-
*/
|
|
94
|
-
export declare function checkParamPrototypeOrThrow(paramVal: any, paramName: string, prototypes: any, prototypeName: string, isOptional?: boolean): void;
|
|
95
|
-
interface Server {
|
|
96
|
-
removeListener(event: string, cb: (...params: any[]) => any): unknown;
|
|
97
|
-
on(event: string, cb: (...params: any[]) => any): unknown;
|
|
98
|
-
listen(port: number): unknown;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Starts listening at a port specified in the constructor.
|
|
102
|
-
* Unfortunately server.listen() is not a normal function that fails on error, so we need this trickery.
|
|
103
|
-
* Returns a function that calls `server.listen(port)` and resolves once server starts listening.
|
|
104
|
-
*
|
|
105
|
-
* Usage: `promisifyServerListen(server)(1234)`;
|
|
106
|
-
*/
|
|
107
|
-
export declare function promisifyServerListen<T extends Server>(server: T): (port: number) => Promise<void>;
|
|
108
|
-
export declare function configureLogger(givenLog: Log, isProduction?: boolean): void;
|
|
109
|
-
/**
|
|
110
|
-
* Wraps given promise with timeout.
|
|
111
|
-
*/
|
|
112
|
-
export declare function timeoutPromise<T>(promise: Promise<T>, timeoutMillis: number, errorMessage?: string): Promise<unknown>;
|
|
113
|
-
export {};
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { JsonVariable } from './utilities.client';
|
|
2
|
-
declare class WebhookPayloadTemplateError extends Error {
|
|
3
|
-
constructor(message?: string);
|
|
4
|
-
}
|
|
5
|
-
export declare class InvalidJsonError extends WebhookPayloadTemplateError {
|
|
6
|
-
constructor(originalError: Error);
|
|
7
|
-
}
|
|
8
|
-
export declare class InvalidVariableError extends Error {
|
|
9
|
-
constructor(variable?: string);
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* WebhookPayloadTemplate enables creation and parsing of webhook payload template strings.
|
|
13
|
-
* Template strings are JSON that may include template variables enclosed in double
|
|
14
|
-
* curly brackets: `{{variable}}`. When the template is parsed, variables are replaced
|
|
15
|
-
* with values from a provided context.
|
|
16
|
-
*
|
|
17
|
-
* This is useful to create dynamic webhook payloads where a template is saved on webhook
|
|
18
|
-
* creation and then variables are dynamically added on webhook dispatch.
|
|
19
|
-
*
|
|
20
|
-
* **Example:**
|
|
21
|
-
* ```js
|
|
22
|
-
* const payloadTemplate = `{
|
|
23
|
-
* "id": "some-id",
|
|
24
|
-
* "createdAt": "2019-05-08T15:22:21.095Z",
|
|
25
|
-
* "dataToSend": {{data}}
|
|
26
|
-
* }`
|
|
27
|
-
*
|
|
28
|
-
* const data = {
|
|
29
|
-
* status: 200,
|
|
30
|
-
* body: 'hello world'
|
|
31
|
-
* }
|
|
32
|
-
*
|
|
33
|
-
* const payloadObject = WebhookPayloadTemplate.parse(payloadTemplate, null, { data })
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* **Produces:**
|
|
37
|
-
* ```js
|
|
38
|
-
* {
|
|
39
|
-
* id: "some-id",
|
|
40
|
-
* createdAt: '2019-05-08T15:22:21.095Z',
|
|
41
|
-
* dataToSend: {
|
|
42
|
-
* status: 200,
|
|
43
|
-
* body: 'hello world'
|
|
44
|
-
* }
|
|
45
|
-
* }
|
|
46
|
-
* ```
|
|
47
|
-
* @hideconstructor
|
|
48
|
-
*/
|
|
49
|
-
export declare class WebhookPayloadTemplate {
|
|
50
|
-
private readonly template;
|
|
51
|
-
private readonly allowedVariables;
|
|
52
|
-
private readonly context;
|
|
53
|
-
private payload;
|
|
54
|
-
readonly replacedVariables: {
|
|
55
|
-
variableName: string;
|
|
56
|
-
replacement: string;
|
|
57
|
-
}[];
|
|
58
|
-
constructor(template: string, allowedVariables?: Set<string> | null, context?: Record<string, any>);
|
|
59
|
-
/**
|
|
60
|
-
* Parse existing webhook payload template string into an object, replacing
|
|
61
|
-
* template variables using the provided context.
|
|
62
|
-
*
|
|
63
|
-
* Parse also validates the template structure, so it can be used
|
|
64
|
-
* to check validity of the template JSON and usage of allowedVariables.
|
|
65
|
-
*/
|
|
66
|
-
static parse(payloadTemplate: string, allowedVariables?: Set<string> | null, context?: Record<string, any>, options?: {
|
|
67
|
-
interpolateStrings?: boolean;
|
|
68
|
-
}): Record<string, any>;
|
|
69
|
-
/**
|
|
70
|
-
* Stringify an object into a webhook payload template.
|
|
71
|
-
* Values created using `getTemplateVariable('foo.bar')`
|
|
72
|
-
* will be stringified to `{{foo.bar}}` template variable.
|
|
73
|
-
*/
|
|
74
|
-
static stringify(objectTemplate: Record<string, any>, replacer?: ((_: any) => string) | null, indent?: number): string;
|
|
75
|
-
/**
|
|
76
|
-
* Produces an instance of a template variable that can be used
|
|
77
|
-
* in objects and will be stringified into `{{variableName}}` syntax.
|
|
78
|
-
*
|
|
79
|
-
* **Example:**
|
|
80
|
-
* ```js
|
|
81
|
-
* const resourceVariable = WebhookPayloadTemplate.getVariable('resource');
|
|
82
|
-
* const objectTemplate = {
|
|
83
|
-
* foo: 'foo',
|
|
84
|
-
* bar: ['bar'],
|
|
85
|
-
* res: resourceVariable,
|
|
86
|
-
* }
|
|
87
|
-
*
|
|
88
|
-
* const payloadTemplate = WebhookPayloadTemplate.stringify(objectTemplate);
|
|
89
|
-
* ```
|
|
90
|
-
*
|
|
91
|
-
* **Produces:**
|
|
92
|
-
* ```json
|
|
93
|
-
* {
|
|
94
|
-
* "foo": "foo",
|
|
95
|
-
* "bar": ["bar"],
|
|
96
|
-
* "res": {{resource}},
|
|
97
|
-
* }
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
static getVariable(variableName: string): JsonVariable;
|
|
101
|
-
private _parse;
|
|
102
|
-
private _interpolate;
|
|
103
|
-
private _interpolateString;
|
|
104
|
-
private _interpolateObject;
|
|
105
|
-
private _interpolateArray;
|
|
106
|
-
private _findPositionOfNextVariable;
|
|
107
|
-
private _isVariableInsideString;
|
|
108
|
-
private _countUnescapedDoubleQuotesUpToIndex;
|
|
109
|
-
private _replaceVariable;
|
|
110
|
-
private _validateVariableName;
|
|
111
|
-
private _getVariableValue;
|
|
112
|
-
private _getVariableReplacement;
|
|
113
|
-
}
|
|
114
|
-
export {};
|
|
File without changes
|