@apify/utilities 2.35.11 → 3.0.0-beta.1

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 (52) hide show
  1. package/code_hash_manager.d.ts +34 -0
  2. package/code_hash_manager.js +66 -0
  3. package/code_hash_manager.js.map +1 -0
  4. package/crypto.d.ts +35 -0
  5. package/crypto.js +58 -0
  6. package/crypto.js.map +1 -0
  7. package/exponential_backoff.d.ts +9 -0
  8. package/exponential_backoff.js +47 -0
  9. package/exponential_backoff.js.map +1 -0
  10. package/health_checker.d.ts +61 -0
  11. package/health_checker.js +132 -0
  12. package/health_checker.js.map +1 -0
  13. package/hmac.d.ts +20 -0
  14. package/hmac.js +59 -0
  15. package/hmac.js.map +1 -0
  16. package/index.d.ts +14 -0
  17. package/index.js +15 -0
  18. package/index.js.map +1 -0
  19. package/package.json +16 -21
  20. package/parse_boolean.d.ts +10 -0
  21. package/parse_boolean.js +25 -0
  22. package/parse_boolean.js.map +1 -0
  23. package/parse_jsonl_stream.d.ts +25 -0
  24. package/parse_jsonl_stream.js +79 -0
  25. package/parse_jsonl_stream.js.map +1 -0
  26. package/storages.d.ts +29 -0
  27. package/storages.js +37 -0
  28. package/storages.js.map +1 -0
  29. package/streams_utilities.d.ts +10 -0
  30. package/streams_utilities.js +26 -0
  31. package/streams_utilities.js.map +1 -0
  32. package/url_params_utils.d.ts +7 -0
  33. package/url_params_utils.js +11 -0
  34. package/url_params_utils.js.map +1 -0
  35. package/usernames.d.ts +10 -0
  36. package/usernames.js +1137 -0
  37. package/usernames.js.map +1 -0
  38. package/utilities.client.d.ts +125 -0
  39. package/utilities.client.js +408 -0
  40. package/utilities.client.js.map +1 -0
  41. package/utilities.d.ts +111 -0
  42. package/utilities.js +263 -0
  43. package/utilities.js.map +1 -0
  44. package/webhook_payload_template.d.ts +114 -0
  45. package/webhook_payload_template.js +245 -0
  46. package/webhook_payload_template.js.map +1 -0
  47. package/cjs/index.cjs +0 -2402
  48. package/cjs/index.cjs.map +0 -1
  49. package/cjs/index.d.ts +0 -609
  50. package/esm/index.d.mts +0 -609
  51. package/esm/index.mjs +0 -2314
  52. package/esm/index.mjs.map +0 -1
package/package.json CHANGED
@@ -1,21 +1,16 @@
1
1
  {
2
2
  "name": "@apify/utilities",
3
- "version": "2.35.11",
3
+ "version": "3.0.0-beta.1",
4
4
  "description": "Tools and constants shared across Apify projects.",
5
- "main": "./cjs/index.cjs",
6
- "module": "./esm/index.mjs",
7
- "typings": "./cjs/index.d.ts",
5
+ "type": "module",
6
+ "main": "./index.js",
7
+ "types": "./index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "import": {
11
- "types": "./esm/index.d.mts",
12
- "default": "./esm/index.mjs"
13
- },
14
- "require": {
15
- "types": "./cjs/index.d.ts",
16
- "default": "./cjs/index.cjs"
17
- }
18
- }
10
+ "types": "./index.d.ts",
11
+ "default": "./index.js"
12
+ },
13
+ "./package.json": "./package.json"
19
14
  },
20
15
  "keywords": [
21
16
  "apify"
@@ -40,19 +35,19 @@
40
35
  "homepage": "https://apify.com",
41
36
  "scripts": {
42
37
  "build": "pnpm clean && pnpm compile && pnpm copy",
43
- "clean": "rimraf ./dist",
44
- "compile": "tsup",
45
- "copy": "ts-node -T ../../scripts/copy.ts"
38
+ "clean": "node ../../scripts/clean.ts",
39
+ "compile": "tsc -p tsconfig.build.json",
40
+ "copy": "node ../../scripts/copy.ts"
46
41
  },
47
42
  "publishConfig": {
48
43
  "access": "public"
49
44
  },
50
45
  "dependencies": {
51
- "@apify/consts": "^2.58.1",
52
- "@apify/log": "^2.5.54"
46
+ "@apify/consts": "^3.0.0-beta.1",
47
+ "@apify/log": "^3.0.0-beta.1"
53
48
  },
54
- "devDependencies": {
55
- "@types/create-hmac": "^1.1.3"
49
+ "engines": {
50
+ "node": ">=22"
56
51
  },
57
52
  "lerna": {
58
53
  "command": {
@@ -61,5 +56,5 @@
61
56
  }
62
57
  }
63
58
  },
64
- "gitHead": "9bb07e2e7f78ee5875851077416d077469e69772"
59
+ "gitHead": "6cfbef528c1448fa1a94f1430fd3fc4854935a51"
65
60
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Strictly parses a value to a boolean, returning `null` if the value is invalid.
3
+ * - Returns `true` for: `true`, `1`, `'1'`, `'true'` (case-insensitive).
4
+ * - Returns `false` for: `false`, `0`, `'0'`, `'false'` (case-insensitive).
5
+ * - Returns `null` for any other value.
6
+ *
7
+ * @param value - The value to parse (unknown type).
8
+ * @returns {boolean | null} The parsed boolean or null if the input is invalid.
9
+ */
10
+ export declare const parseBooleanOrNull: (value: unknown) => boolean | null;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Strictly parses a value to a boolean, returning `null` if the value is invalid.
3
+ * - Returns `true` for: `true`, `1`, `'1'`, `'true'` (case-insensitive).
4
+ * - Returns `false` for: `false`, `0`, `'0'`, `'false'` (case-insensitive).
5
+ * - Returns `null` for any other value.
6
+ *
7
+ * @param value - The value to parse (unknown type).
8
+ * @returns {boolean | null} The parsed boolean or null if the input is invalid.
9
+ */
10
+ export const parseBooleanOrNull = (value) => {
11
+ if (value === true || value === 1)
12
+ return true;
13
+ if (value === false || value === 0)
14
+ return false;
15
+ if (typeof value === 'string') {
16
+ const lowerValue = value.trim().toLowerCase();
17
+ if (lowerValue === 'true' || lowerValue === '1')
18
+ return true;
19
+ if (lowerValue === 'false' || lowerValue === '0')
20
+ return false;
21
+ }
22
+ // Return null for invalid/ambiguous input
23
+ return null;
24
+ };
25
+ //# sourceMappingURL=parse_boolean.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse_boolean.js","sourceRoot":"","sources":["../src/parse_boolean.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAc,EAAkB,EAAE;IACjE,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC/C,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAEjD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAC9C,IAAI,UAAU,KAAK,MAAM,IAAI,UAAU,KAAK,GAAG;YAAE,OAAO,IAAI,CAAC;QAC7D,IAAI,UAAU,KAAK,OAAO,IAAI,UAAU,KAAK,GAAG;YAAE,OAAO,KAAK,CAAC;IACnE,CAAC;IAED,0CAA0C;IAC1C,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC","sourcesContent":["/**\n * Strictly parses a value to a boolean, returning `null` if the value is invalid.\n * - Returns `true` for: `true`, `1`, `'1'`, `'true'` (case-insensitive).\n * - Returns `false` for: `false`, `0`, `'0'`, `'false'` (case-insensitive).\n * - Returns `null` for any other value.\n *\n * @param value - The value to parse (unknown type).\n * @returns {boolean | null} The parsed boolean or null if the input is invalid.\n */\nexport const parseBooleanOrNull = (value: unknown): boolean | null => {\n if (value === true || value === 1) return true;\n if (value === false || value === 0) return false;\n\n if (typeof value === 'string') {\n const lowerValue = value.trim().toLowerCase();\n if (lowerValue === 'true' || lowerValue === '1') return true;\n if (lowerValue === 'false' || lowerValue === '0') return false;\n }\n\n // Return null for invalid/ambiguous input\n return null;\n};\n"]}
@@ -0,0 +1,25 @@
1
+ import type { TransformCallback } from 'node:stream';
2
+ import { Transform } from 'node:stream';
3
+ /**
4
+ * A transforming stream which accepts string/Buffer data with JSON Lines objects on input
5
+ * and emits 'object' event for every parsed JavaScript objects.
6
+ * The stream passes through the original data.
7
+ * Each JSON object is expected to be on a separate line, some lines might be empty or contain whitespace.
8
+ * After each JSON object there needs to be '\n' or end of stream.
9
+ * This stream is especially useful for processing stream from Docker engine, such as:
10
+ *
11
+ * <pre>
12
+ * {"status":"Preparing","progressDetail":{},"id":"e0380bb6c0bb"}
13
+ * {"status":"Preparing","progressDetail":{},"id":"9f8566ee5135"}
14
+ * {"errorDetail":{"message":"no basic auth credentials"},"error":"no basic auth credentials"}
15
+ * </pre>
16
+ *
17
+ * **WARNING**: You still need to consume the `data` event from the transformed stream,
18
+ * otherwise the internal buffers will get full and the stream might be corked.
19
+ */
20
+ export declare class ParseJsonlStream extends Transform {
21
+ private pendingChunk;
22
+ parseLineAndEmitObject(line: string): void;
23
+ _transform(chunk: any, encoding: BufferEncoding, callback: TransformCallback): void;
24
+ _flush(callback: TransformCallback): void;
25
+ }
@@ -0,0 +1,79 @@
1
+ import { Transform } from 'node:stream';
2
+ // TODO: Fix the issue with the separate 'data' and 'object' event - see below.
3
+ // For example, we could just have 'data' and it would just pass the object.
4
+ // For that, you can use the 'objectMode' param
5
+ /**
6
+ * A transforming stream which accepts string/Buffer data with JSON Lines objects on input
7
+ * and emits 'object' event for every parsed JavaScript objects.
8
+ * The stream passes through the original data.
9
+ * Each JSON object is expected to be on a separate line, some lines might be empty or contain whitespace.
10
+ * After each JSON object there needs to be '\n' or end of stream.
11
+ * This stream is especially useful for processing stream from Docker engine, such as:
12
+ *
13
+ * <pre>
14
+ * {"status":"Preparing","progressDetail":{},"id":"e0380bb6c0bb"}
15
+ * {"status":"Preparing","progressDetail":{},"id":"9f8566ee5135"}
16
+ * {"errorDetail":{"message":"no basic auth credentials"},"error":"no basic auth credentials"}
17
+ * </pre>
18
+ *
19
+ * **WARNING**: You still need to consume the `data` event from the transformed stream,
20
+ * otherwise the internal buffers will get full and the stream might be corked.
21
+ */
22
+ export class ParseJsonlStream extends Transform {
23
+ pendingChunk = null;
24
+ parseLineAndEmitObject(line) {
25
+ line = line.trim();
26
+ if (!line) {
27
+ return;
28
+ }
29
+ try {
30
+ const obj = JSON.parse(line);
31
+ this.emit('object', obj);
32
+ }
33
+ catch (e) {
34
+ throw new Error(`Cannot parse JSON stream data ('${String(line)}'): ${String(e)}`);
35
+ }
36
+ }
37
+ _transform(chunk, encoding, callback) {
38
+ let allData;
39
+ if (this.pendingChunk) {
40
+ allData = this.pendingChunk + chunk;
41
+ this.pendingChunk = null;
42
+ }
43
+ else {
44
+ allData = chunk;
45
+ }
46
+ const lines = allData.toString().split('\n');
47
+ // One line can span multiple chunks, so if the new chunk doesn't end with '\n',
48
+ // store the last part and later concat it with the new chunk
49
+ if (lines[lines.length - 1] !== '') {
50
+ this.pendingChunk = lines.pop();
51
+ }
52
+ try {
53
+ for (let i = 0; i < lines.length; i++) {
54
+ this.parseLineAndEmitObject(lines[i]);
55
+ }
56
+ }
57
+ catch (err) {
58
+ callback(err, null);
59
+ return;
60
+ }
61
+ callback(null, chunk);
62
+ }
63
+ // This function is called right after stream.end() is called by the writer.
64
+ // It just tries to process the pending chunk and returns an error if that fails.
65
+ _flush(callback) {
66
+ if (this.pendingChunk) {
67
+ try {
68
+ this.parseLineAndEmitObject(this.pendingChunk);
69
+ this.pendingChunk = null;
70
+ }
71
+ catch (err) {
72
+ callback(err, null);
73
+ return;
74
+ }
75
+ }
76
+ callback();
77
+ }
78
+ }
79
+ //# sourceMappingURL=parse_jsonl_stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse_jsonl_stream.js","sourceRoot":"","sources":["../src/parse_jsonl_stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,+EAA+E;AAC/E,4EAA4E;AAC5E,+CAA+C;AAE/C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,gBAAiB,SAAQ,SAAS;IACnC,YAAY,GAAkB,IAAI,CAAC;IAE3C,sBAAsB,CAAC,IAAY;QAC/B,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAEnB,IAAI,CAAC,IAAI,EAAE,CAAC;YACR,OAAO;QACX,CAAC;QAED,IAAI,CAAC;YACD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC7B,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE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AAC;gBACD,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;gBAC/C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;YAC7B,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACX,QAAQ,CAAC,GAAY,EAAE,IAAI,CAAC,CAAC;gBAC7B,OAAO;YACX,CAAC;QACL,CAAC;QACD,QAAQ,EAAE,CAAC;IACf,CAAC;CACJ","sourcesContent":["import type { TransformCallback } from 'node:stream';\nimport { Transform } from 'node:stream';\n\n// TODO: Fix the issue with the separate 'data' and 'object' event - see below.\n// For example, we could just have 'data' and it would just pass the object.\n// For that, you can use the 'objectMode' param\n\n/**\n * A transforming stream which accepts string/Buffer data with JSON Lines objects on input\n * and emits 'object' event for every parsed JavaScript objects.\n * The stream passes through the original data.\n * Each JSON object is expected to be on a separate line, some lines might be empty or contain whitespace.\n * After each JSON object there needs to be '\\n' or end of stream.\n * This stream is especially useful for processing stream from Docker engine, such as:\n *\n * <pre>\n * {\"status\":\"Preparing\",\"progressDetail\":{},\"id\":\"e0380bb6c0bb\"}\n * {\"status\":\"Preparing\",\"progressDetail\":{},\"id\":\"9f8566ee5135\"}\n * {\"errorDetail\":{\"message\":\"no basic auth credentials\"},\"error\":\"no basic auth credentials\"}\n * </pre>\n *\n * **WARNING**: You still need to consume the `data` event from the transformed stream,\n * otherwise the internal buffers will get full and the stream might be corked.\n */\nexport class ParseJsonlStream extends Transform {\n private pendingChunk: string | null = null;\n\n parseLineAndEmitObject(line: string): void {\n line = line.trim();\n\n if (!line) {\n return;\n }\n\n try {\n const obj = JSON.parse(line);\n this.emit('object', obj);\n } catch (e) {\n throw new Error(`Cannot parse JSON stream data ('${String(line)}'): ${String(e)}`);\n }\n }\n\n _transform(chunk: any, encoding: BufferEncoding, callback: TransformCallback): void {\n let allData;\n if (this.pendingChunk) {\n allData = this.pendingChunk + chunk;\n this.pendingChunk = null;\n } else {\n allData = chunk;\n }\n\n const lines = allData.toString().split('\\n');\n\n // One line can span multiple chunks, so if the new chunk doesn't end with '\\n',\n // store the last part and later concat it with the new chunk\n if (lines[lines.length - 1] !== '') {\n this.pendingChunk = lines.pop();\n }\n\n try {\n for (let i = 0; i < lines.length; i++) {\n this.parseLineAndEmitObject(lines[i]);\n }\n } catch (err) {\n callback(err as Error, null);\n return;\n }\n\n callback(null, chunk);\n }\n\n // This function is called right after stream.end() is called by the writer.\n // It just tries to process the pending chunk and returns an error if that fails.\n _flush(callback: TransformCallback): void {\n if (this.pendingChunk) {\n try {\n this.parseLineAndEmitObject(this.pendingChunk);\n this.pendingChunk = null;\n } catch (err) {\n callback(err as Error, null);\n return;\n }\n }\n callback();\n }\n}\n"]}
package/storages.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Creates a secure signature for a resource like a dataset or key-value store.
3
+ * This signature is used to generate a signed URL for authenticated access, which can be expiring or permanent.
4
+ * The signature is created using HMAC with the provided secret key and includes the resource ID, expiration time, and version.
5
+ *
6
+ * Note: expiresInMillis is optional. If not provided, the signature will not expire.
7
+ *
8
+ * @deprecated Use {@link createStorageContentSignatureAsync} instead, which uses Web Crypto API and
9
+ * is available in both Node.js and browsers without the need for polyfills.
10
+ */
11
+ export declare function createStorageContentSignature({ resourceId, urlSigningSecretKey, expiresInMillis, version, }: {
12
+ resourceId: string;
13
+ urlSigningSecretKey: string;
14
+ expiresInMillis?: number;
15
+ version?: number;
16
+ }): string;
17
+ /**
18
+ * Creates a secure signature for a resource like a dataset or key-value store.
19
+ * This signature is used to generate a signed URL for authenticated access, which can be expiring or permanent.
20
+ * The signature is created using HMAC with the provided secret key and includes the resource ID, expiration time, and version.
21
+ *
22
+ * Note: expiresInMillis is optional. If not provided, the signature will not expire.
23
+ */
24
+ export declare function createStorageContentSignatureAsync({ resourceId, urlSigningSecretKey, expiresInMillis, version, }: {
25
+ resourceId: string;
26
+ urlSigningSecretKey: string;
27
+ expiresInMillis?: number;
28
+ version?: number;
29
+ }): Promise<string>;
package/storages.js ADDED
@@ -0,0 +1,37 @@
1
+ import { createHmacSignature, createHmacSignatureAsync } from './hmac.js';
2
+ /**
3
+ * Creates a secure signature for a resource like a dataset or key-value store.
4
+ * This signature is used to generate a signed URL for authenticated access, which can be expiring or permanent.
5
+ * The signature is created using HMAC with the provided secret key and includes the resource ID, expiration time, and version.
6
+ *
7
+ * Note: expiresInMillis is optional. If not provided, the signature will not expire.
8
+ *
9
+ * @deprecated Use {@link createStorageContentSignatureAsync} instead, which uses Web Crypto API and
10
+ * is available in both Node.js and browsers without the need for polyfills.
11
+ */
12
+ export function createStorageContentSignature({ resourceId, urlSigningSecretKey, expiresInMillis, version = 0, }) {
13
+ const expiresAt = expiresInMillis ? new Date().getTime() + expiresInMillis : 0;
14
+ const hmac = createHmacSignature(urlSigningSecretKey, `${version}.${expiresAt}.${resourceId}`);
15
+ return Buffer.from(`${version}.${expiresAt}.${hmac}`).toString('base64url');
16
+ }
17
+ function typedArrayToBase64Url(typedArray) {
18
+ let binary = '';
19
+ for (let i = 0; i < typedArray.length; i++) {
20
+ binary += String.fromCharCode(typedArray[i]);
21
+ }
22
+ const base64 = btoa(binary);
23
+ return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
24
+ }
25
+ /**
26
+ * Creates a secure signature for a resource like a dataset or key-value store.
27
+ * This signature is used to generate a signed URL for authenticated access, which can be expiring or permanent.
28
+ * The signature is created using HMAC with the provided secret key and includes the resource ID, expiration time, and version.
29
+ *
30
+ * Note: expiresInMillis is optional. If not provided, the signature will not expire.
31
+ */
32
+ export async function createStorageContentSignatureAsync({ resourceId, urlSigningSecretKey, expiresInMillis, version = 0, }) {
33
+ const expiresAt = expiresInMillis ? new Date().getTime() + expiresInMillis : 0;
34
+ const hmac = await createHmacSignatureAsync(urlSigningSecretKey, `${version}.${expiresAt}.${resourceId}`);
35
+ return typedArrayToBase64Url(new TextEncoder().encode(`${version}.${expiresAt}.${hmac}`));
36
+ }
37
+ //# sourceMappingURL=storages.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CAAC,GAMd;IACG,MAAM,SAAS,GAAG,eAAe,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/E,MAAM,IAAI,GAAG,MAAM,wBAAwB,CAAC,mBAAmB,EAAE,GAAG,OAAO,IAAI,SAAS,IAAI,UAAU,EAAE,CAAC,CAAC;IAC1G,OAAO,qBAAqB,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,OAAO,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC;AAC9F,CAAC","sourcesContent":["import { createHmacSignature, createHmacSignatureAsync } from './hmac.js';\n\n/**\n * Creates a secure signature for a resource like a dataset or key-value store.\n * This signature is used to generate a signed URL for authenticated access, which can be expiring or permanent.\n * The signature is created using HMAC with the provided secret key and includes the resource ID, expiration time, and version.\n *\n * Note: expiresInMillis is optional. If not provided, the signature will not expire.\n *\n * @deprecated Use {@link createStorageContentSignatureAsync} instead, which uses Web Crypto API and\n * is available in both Node.js and browsers without the need for polyfills.\n */\nexport function createStorageContentSignature({\n resourceId,\n urlSigningSecretKey,\n expiresInMillis,\n version = 0,\n}: {\n resourceId: string;\n urlSigningSecretKey: string;\n expiresInMillis?: number;\n version?: number;\n}) {\n const expiresAt = expiresInMillis ? new Date().getTime() + expiresInMillis : 0;\n const hmac = createHmacSignature(urlSigningSecretKey, `${version}.${expiresAt}.${resourceId}`);\n return Buffer.from(`${version}.${expiresAt}.${hmac}`).toString('base64url');\n}\n\nfunction typedArrayToBase64Url(typedArray: Uint8Array): string {\n let binary = '';\n for (let i = 0; i < typedArray.length; i++) {\n binary += String.fromCharCode(typedArray[i]);\n }\n const base64 = btoa(binary);\n return base64.replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '');\n}\n\n/**\n * Creates a secure signature for a resource like a dataset or key-value store.\n * This signature is used to generate a signed URL for authenticated access, which can be expiring or permanent.\n * The signature is created using HMAC with the provided secret key and includes the resource ID, expiration time, and version.\n *\n * Note: expiresInMillis is optional. If not provided, the signature will not expire.\n */\nexport async function createStorageContentSignatureAsync({\n resourceId,\n urlSigningSecretKey,\n expiresInMillis,\n version = 0,\n}: {\n resourceId: string;\n urlSigningSecretKey: string;\n expiresInMillis?: number;\n version?: number;\n}): Promise<string> {\n const expiresAt = expiresInMillis ? new Date().getTime() + expiresInMillis : 0;\n const hmac = await createHmacSignatureAsync(urlSigningSecretKey, `${version}.${expiresAt}.${resourceId}`);\n return typedArrayToBase64Url(new TextEncoder().encode(`${version}.${expiresAt}.${hmac}`));\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { PassThrough, Readable } from 'node:stream';
2
+ /**
3
+ * Concat data from stream to Buffer
4
+ */
5
+ export declare function concatStreamToBuffer(stream: Readable | PassThrough): Promise<Buffer>;
6
+ /**
7
+ * Flushes the provided stream into a Buffer and transforms
8
+ * it to a String using the provided encoding or utf-8 as default.
9
+ */
10
+ export declare function readStreamToString(stream: Readable | PassThrough, encoding?: BufferEncoding): Promise<string>;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Concat data from stream to Buffer
3
+ */
4
+ export async function concatStreamToBuffer(stream) {
5
+ return new Promise((resolve, reject) => {
6
+ const chunks = [];
7
+ stream
8
+ .on('data', (chunk) => {
9
+ chunks.push(chunk);
10
+ })
11
+ .on('error', (e) => reject(e))
12
+ .on('end', () => {
13
+ const buffer = Buffer.concat(chunks);
14
+ return resolve(buffer);
15
+ });
16
+ });
17
+ }
18
+ /**
19
+ * Flushes the provided stream into a Buffer and transforms
20
+ * it to a String using the provided encoding or utf-8 as default.
21
+ */
22
+ export async function readStreamToString(stream, encoding) {
23
+ const buffer = await concatStreamToBuffer(stream);
24
+ return buffer.toString(encoding);
25
+ }
26
+ //# sourceMappingURL=streams_utilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streams_utilities.js","sourceRoot":"","sources":["../src/streams_utilities.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,MAA8B;IACrE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,MAAM,MAAM,GAAiB,EAAE,CAAC;QAChC,MAAM;aACD,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;YAClB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC,CAAC;aACD,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;aAC7B,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YACZ,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACrC,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;IACX,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,MAA8B,EAAE,QAAyB;IAC9F,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAClD,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import type { PassThrough, Readable } from 'node:stream';\n\n/**\n * Concat data from stream to Buffer\n */\nexport async function concatStreamToBuffer(stream: Readable | PassThrough): Promise<Buffer> {\n return new Promise((resolve, reject) => {\n const chunks: Uint8Array[] = [];\n stream\n .on('data', (chunk) => {\n chunks.push(chunk);\n })\n .on('error', (e) => reject(e))\n .on('end', () => {\n const buffer = Buffer.concat(chunks);\n return resolve(buffer);\n });\n });\n}\n\n/**\n * Flushes the provided stream into a Buffer and transforms\n * it to a String using the provided encoding or utf-8 as default.\n */\nexport async function readStreamToString(stream: Readable | PassThrough, encoding?: BufferEncoding): Promise<string> {\n const buffer = await concatStreamToBuffer(stream);\n return buffer.toString(encoding);\n}\n"]}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Extract import statements from the code.
3
+ */
4
+ export declare function separateImports(code: string): {
5
+ code: string;
6
+ imports: string;
7
+ };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Extract import statements from the code.
3
+ */
4
+ export function separateImports(code) {
5
+ const lines = code.split('\n');
6
+ return {
7
+ code: lines.filter((line) => !line.trim().startsWith('import')).join('\n'),
8
+ imports: lines.filter((line) => line.trim().startsWith('import')).join('\n'),
9
+ };
10
+ }
11
+ //# sourceMappingURL=url_params_utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url_params_utils.js","sourceRoot":"","sources":["../src/url_params_utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IACxC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO;QACH,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAC1E,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;KAC/E,CAAC;AACN,CAAC","sourcesContent":["/**\n * Extract import statements from the code.\n */\nexport function separateImports(code: string): { code: string; imports: string } {\n const lines = code.split('\\n');\n return {\n code: lines.filter((line) => !line.trim().startsWith('import')).join('\\n'),\n imports: lines.filter((line) => line.trim().startsWith('import')).join('\\n'),\n };\n}\n"]}
package/usernames.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Checks whether username is listed in the forbidden username list
3
+ * or looks like an Apify ID.
4
+ *
5
+ * NOTE: The forbidden list may expand over time, so a username that was
6
+ * previously permitted may later become forbidden. Use this function only
7
+ * when validating a username change, not as part of normal authentication
8
+ * or authorization flow.
9
+ */
10
+ export declare function isForbiddenUsername(username: string): boolean;