@apify/input_secrets 1.1.52 → 1.1.54

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/README.md CHANGED
@@ -15,7 +15,6 @@ package | version
15
15
  `@apify/markdown` | [![NPM version](https://img.shields.io/npm/v/@apify/markdown.svg)](https://www.npmjs.com/package/@apify/markdown)
16
16
  `@apify/payment_qr_codes` | [![NPM version](https://img.shields.io/npm/v/@apify/payment_qr_codes.svg)](https://www.npmjs.com/package/@apify/payment_qr_codes)
17
17
  `@apify/pseudo_url` | [![NPM version](https://img.shields.io/npm/v/@apify/pseudo_url.svg)](https://www.npmjs.com/package/@apify/pseudo_url)
18
- `@apify/salesforce_client` | [![NPM version](https://img.shields.io/npm/v/@apify/salesforce_client.svg)](https://www.npmjs.com/package/@apify/salesforce_client)
19
18
  `@apify/utilities` | [![NPM version](https://img.shields.io/npm/v/@apify/utilities.svg)](https://www.npmjs.com/package/@apify/utilities)
20
19
  `@apify/timeout` | [![NPM version](https://img.shields.io/npm/v/@apify/timeout.svg)](https://www.npmjs.com/package/@apify/timeout)
21
20
 
package/cjs/index.cjs CHANGED
@@ -64,8 +64,7 @@ function encryptInputSecrets({ input, inputSchema, publicKey }) {
64
64
  ow(inputSchema, ow.object);
65
65
  ow(publicKey, ow.object.instanceOf(import_crypto.KeyObject));
66
66
  const secretsInInputKeys = getInputSchemaSecretFieldKeys(inputSchema);
67
- if (secretsInInputKeys.length === 0)
68
- return input;
67
+ if (secretsInInputKeys.length === 0) return input;
69
68
  const encryptedInput = {};
70
69
  for (const key of secretsInInputKeys) {
71
70
  const value = input[key];
@@ -83,8 +82,7 @@ function decryptInputSecrets({ input, privateKey }) {
83
82
  for (const [key, value] of Object.entries(input)) {
84
83
  if (ow.isValid(value, ow.string) && ENCRYPTED_INPUT_VALUE_REGEXP.test(value)) {
85
84
  const match = value.match(ENCRYPTED_INPUT_VALUE_REGEXP);
86
- if (!match)
87
- continue;
85
+ if (!match) continue;
88
86
  const [, encryptedPassword, encryptedValue] = match;
89
87
  try {
90
88
  decryptedInput[key] = (0, import_utilities.privateDecrypt)({ privateKey, encryptedPassword, encryptedValue });
package/cjs/index.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/input_secrets.ts"],"sourcesContent":["export * from './input_secrets';\n","import { KeyObject } from 'crypto';\nimport { privateDecrypt, publicEncrypt } from '@apify/utilities';\nimport _testOw, { type Ow } from 'ow';\n\n// eslint-disable-next-line no-underscore-dangle\ndeclare const __injectedOw: Ow;\n\nconst ow: Ow = typeof __injectedOw === 'undefined' ? _testOw : __injectedOw || _testOw;\n\nconst BASE64_REGEXP = /[-A-Za-z0-9+/]*={0,3}/;\nconst ENCRYPTED_INPUT_VALUE_PREFIX = 'ENCRYPTED_VALUE';\nconst ENCRYPTED_INPUT_VALUE_REGEXP = new RegExp(`^${ENCRYPTED_INPUT_VALUE_PREFIX}:(${BASE64_REGEXP.source}):(${BASE64_REGEXP.source})$`);\n\n/**\n * Get keys of secret fields from input schema\n */\nexport function getInputSchemaSecretFieldKeys(inputSchema: any): string[] {\n return Object.keys(inputSchema.properties)\n .filter((key) => !!inputSchema.properties[key].isSecret);\n}\n\n/**\n * Encrypts input secret value\n */\nexport function encryptInputSecretValue({ value, publicKey }: { value: string, publicKey: KeyObject }): string {\n ow(value, ow.string);\n ow(publicKey, ow.object.instanceOf(KeyObject));\n\n const { encryptedValue, encryptedPassword } = publicEncrypt({ value, publicKey });\n return `${ENCRYPTED_INPUT_VALUE_PREFIX}:${encryptedPassword}:${encryptedValue}`;\n}\n\n/**\n * Encrypts actor input secrets\n */\nexport function encryptInputSecrets<T>(\n { input, inputSchema, publicKey }: { input: T, inputSchema: object, publicKey: KeyObject },\n): T {\n ow(input, ow.object);\n ow(inputSchema, ow.object);\n ow(publicKey, ow.object.instanceOf(KeyObject));\n\n const secretsInInputKeys = getInputSchemaSecretFieldKeys(inputSchema);\n if (secretsInInputKeys.length === 0) return input;\n\n const encryptedInput = {};\n for (const key of secretsInInputKeys) {\n const value = input[key];\n // NOTE: Skips already encrypted values. It can happens in case client already encrypted values, before\n // sending them using API. Or input was takes from task, run console or scheduler, where input is stored encrypted.\n if (value && ow.isValid(value, ow.string) && !ENCRYPTED_INPUT_VALUE_REGEXP.test(value)) {\n encryptedInput[key] = encryptInputSecretValue({ value: input[key], publicKey });\n }\n }\n\n return { ...input, ...encryptedInput };\n}\n\n/**\n * Decrypts actor input secrets\n * @param {Object} input\n * @param {KeyObject} privateKey\n * @returns Object\n */\nexport function decryptInputSecrets<T>(\n { input, privateKey }: { input: T, privateKey: KeyObject },\n): T {\n ow(input, ow.object);\n ow(privateKey, ow.object.instanceOf(KeyObject));\n\n const decryptedInput = {};\n for (const [key, value] of Object.entries(input)) {\n if (ow.isValid(value, ow.string) && ENCRYPTED_INPUT_VALUE_REGEXP.test(value)) {\n const match = value.match(ENCRYPTED_INPUT_VALUE_REGEXP);\n if (!match) continue;\n const [, encryptedPassword, encryptedValue] = match;\n try {\n decryptedInput[key] = privateDecrypt({ privateKey, encryptedPassword, encryptedValue });\n } catch (err) {\n throw new Error(`The input field \"${key}\" could not be decrypted. Try updating the field's value in the input editor. `\n + `Decryption error: ${err}`);\n }\n }\n }\n\n return { ...input, ...decryptedInput };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAA0B;AAC1B,uBAA8C;AAC9C,gBAAiC;AAKjC,IAAM,KAAS,OAAO,iBAAiB,cAAc,UAAAA,UAAU,gBAAgB,UAAAA;AAE/E,IAAM,gBAAgB;AACtB,IAAM,+BAA+B;AACrC,IAAM,+BAA+B,IAAI,OAAO,IAAI,4BAA4B,KAAK,cAAc,MAAM,MAAM,cAAc,MAAM,IAAI;AAKhI,SAAS,8BAA8B,aAA4B;AACtE,SAAO,OAAO,KAAK,YAAY,UAAU,EACpC,OAAO,C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,UAAI,CAAC;AAAO;AACZ,YAAM,CAAC,EAAE,mBAAmB,cAAc,IAAI;AAC9C,UAAI;AACA,uBAAe,GAAG,QAAI,iCAAe,EAAE,YAAY,mBAAmB,eAAe,CAAC;AAAA,MAC1F,SAAS,KAAK;AACV,cAAM,IAAI,MAAM,oBAAoB,GAAG,mGAChB,GAAG,EAAE;AAAA,MAChC;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO,EAAE,GAAG,OAAO,GAAG,eAAe;AACzC;AAtBgB;","names":["_testOw"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/input_secrets.ts"],"sourcesContent":["export * from './input_secrets';\n","import { KeyObject } from 'crypto';\n\nimport { privateDecrypt, publicEncrypt } from '@apify/utilities';\nimport _testOw, { type Ow } from 'ow';\n\n// eslint-disable-next-line no-underscore-dangle\ndeclare const __injectedOw: Ow;\n\nconst ow: Ow = typeof __injectedOw === 'undefined' ? _testOw : __injectedOw || _testOw;\n\nconst BASE64_REGEXP = /[-A-Za-z0-9+/]*={0,3}/;\nconst ENCRYPTED_INPUT_VALUE_PREFIX = 'ENCRYPTED_VALUE';\nconst ENCRYPTED_INPUT_VALUE_REGEXP = new RegExp(`^${ENCRYPTED_INPUT_VALUE_PREFIX}:(${BASE64_REGEXP.source}):(${BASE64_REGEXP.source})$`);\n\n/**\n * Get keys of secret fields from input schema\n */\nexport function getInputSchemaSecretFieldKeys(inputSchema: any): string[] {\n return Object.keys(inputSchema.properties)\n .filter((key) => !!inputSchema.properties[key].isSecret);\n}\n\n/**\n * Encrypts input secret value\n */\nexport function encryptInputSecretValue({ value, publicKey }: { value: string, publicKey: KeyObject }): string {\n ow(value, ow.string);\n ow(publicKey, ow.object.instanceOf(KeyObject));\n\n const { encryptedValue, encryptedPassword } = publicEncrypt({ value, publicKey });\n return `${ENCRYPTED_INPUT_VALUE_PREFIX}:${encryptedPassword}:${encryptedValue}`;\n}\n\n/**\n * Encrypts actor input secrets\n */\nexport function encryptInputSecrets<T extends Record<string, any>>(\n { input, inputSchema, publicKey }: { input: T, inputSchema: object, publicKey: KeyObject },\n): T {\n ow(input, ow.object);\n ow(inputSchema, ow.object);\n ow(publicKey, ow.object.instanceOf(KeyObject));\n\n const secretsInInputKeys = getInputSchemaSecretFieldKeys(inputSchema);\n if (secretsInInputKeys.length === 0) return input;\n\n const encryptedInput = {} as Record<string, any>;\n for (const key of secretsInInputKeys) {\n const value = input[key];\n // NOTE: Skips already encrypted values. It can happens in case client already encrypted values, before\n // sending them using API. Or input was takes from task, run console or scheduler, where input is stored encrypted.\n if (value && ow.isValid(value, ow.string) && !ENCRYPTED_INPUT_VALUE_REGEXP.test(value)) {\n encryptedInput[key] = encryptInputSecretValue({ value: input[key], publicKey });\n }\n }\n\n return { ...input, ...encryptedInput };\n}\n\n/**\n * Decrypts actor input secrets\n * @param {Object} input\n * @param {KeyObject} privateKey\n * @returns Object\n */\nexport function decryptInputSecrets<T>(\n { input, privateKey }: { input: T, privateKey: KeyObject },\n): T {\n ow(input, ow.object);\n ow(privateKey, ow.object.instanceOf(KeyObject));\n\n const decryptedInput = {} as Record<string, any>;\n for (const [key, value] of Object.entries(input)) {\n if (ow.isValid(value, ow.string) && ENCRYPTED_INPUT_VALUE_REGEXP.test(value)) {\n const match = value.match(ENCRYPTED_INPUT_VALUE_REGEXP);\n if (!match) continue;\n const [, encryptedPassword, encryptedValue] = match;\n try {\n decryptedInput[key] = privateDecrypt({ privateKey, encryptedPassword, encryptedValue });\n } catch (err) {\n throw new Error(`The input field \"${key}\" could not be decrypted. Try updating the field's value in the input editor. `\n + `Decryption error: ${err}`);\n }\n }\n }\n\n return { ...input, ...decryptedInput };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAA0B;AAE1B,uBAA8C;AAC9C,gBAAiC;AAKjC,IAAM,KAAS,OAAO,iBAAiB,cAAc,UAAAA,UAAU,gBAAgB,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AAC;AAE9C,QAAM,iBAAiB,CAAC;AACxB,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,GAAG;AAC9C,QAAI,GAAG,QAAQ,OAAO,GAAG,MAAM,KAAK,6BAA6B,KAAK,KAAK,GAAG;AAC1E,YAAM,QAAQ,MAAM,MAAM,4BAA4B;AACtD,UAAI,CAAC,MAAO;AACZ,YAAM,CAAC,EAAE,mBAAmB,cAAc,IAAI;AAC9C,UAAI;AACA,uBAAe,GAAG,QAAI,iCAAe,EAAE,YAAY,mBAAmB,eAAe,CAAC;AAAA,MAC1F,SAAS,KAAK;AACV,cAAM,IAAI,MAAM,oBAAoB,GAAG,mGAChB,GAAG,EAAE;AAAA,MAChC;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO,EAAE,GAAG,OAAO,GAAG,eAAe;AACzC;AAtBgB;","names":["_testOw"]}
package/cjs/index.d.ts CHANGED
@@ -14,7 +14,7 @@ declare function encryptInputSecretValue({ value, publicKey }: {
14
14
  /**
15
15
  * Encrypts actor input secrets
16
16
  */
17
- declare function encryptInputSecrets<T>({ input, inputSchema, publicKey }: {
17
+ declare function encryptInputSecrets<T extends Record<string, any>>({ input, inputSchema, publicKey }: {
18
18
  input: T;
19
19
  inputSchema: object;
20
20
  publicKey: KeyObject;
package/esm/index.d.mts CHANGED
@@ -14,7 +14,7 @@ declare function encryptInputSecretValue({ value, publicKey }: {
14
14
  /**
15
15
  * Encrypts actor input secrets
16
16
  */
17
- declare function encryptInputSecrets<T>({ input, inputSchema, publicKey }: {
17
+ declare function encryptInputSecrets<T extends Record<string, any>>({ input, inputSchema, publicKey }: {
18
18
  input: T;
19
19
  inputSchema: object;
20
20
  publicKey: KeyObject;
package/esm/index.mjs CHANGED
@@ -27,8 +27,7 @@ function encryptInputSecrets({ input, inputSchema, publicKey }) {
27
27
  ow(inputSchema, ow.object);
28
28
  ow(publicKey, ow.object.instanceOf(KeyObject));
29
29
  const secretsInInputKeys = getInputSchemaSecretFieldKeys(inputSchema);
30
- if (secretsInInputKeys.length === 0)
31
- return input;
30
+ if (secretsInInputKeys.length === 0) return input;
32
31
  const encryptedInput = {};
33
32
  for (const key of secretsInInputKeys) {
34
33
  const value = input[key];
@@ -46,8 +45,7 @@ function decryptInputSecrets({ input, privateKey }) {
46
45
  for (const [key, value] of Object.entries(input)) {
47
46
  if (ow.isValid(value, ow.string) && ENCRYPTED_INPUT_VALUE_REGEXP.test(value)) {
48
47
  const match = value.match(ENCRYPTED_INPUT_VALUE_REGEXP);
49
- if (!match)
50
- continue;
48
+ if (!match) continue;
51
49
  const [, encryptedPassword, encryptedValue] = match;
52
50
  try {
53
51
  decryptedInput[key] = privateDecrypt({ privateKey, encryptedPassword, encryptedValue });
package/esm/index.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/input_secrets.ts"],"sourcesContent":["import { KeyObject } from 'crypto';\nimport { privateDecrypt, publicEncrypt } from '@apify/utilities';\nimport _testOw, { type Ow } from 'ow';\n\n// eslint-disable-next-line no-underscore-dangle\ndeclare const __injectedOw: Ow;\n\nconst ow: Ow = typeof __injectedOw === 'undefined' ? _testOw : __injectedOw || _testOw;\n\nconst BASE64_REGEXP = /[-A-Za-z0-9+/]*={0,3}/;\nconst ENCRYPTED_INPUT_VALUE_PREFIX = 'ENCRYPTED_VALUE';\nconst ENCRYPTED_INPUT_VALUE_REGEXP = new RegExp(`^${ENCRYPTED_INPUT_VALUE_PREFIX}:(${BASE64_REGEXP.source}):(${BASE64_REGEXP.source})$`);\n\n/**\n * Get keys of secret fields from input schema\n */\nexport function getInputSchemaSecretFieldKeys(inputSchema: any): string[] {\n return Object.keys(inputSchema.properties)\n .filter((key) => !!inputSchema.properties[key].isSecret);\n}\n\n/**\n * Encrypts input secret value\n */\nexport function encryptInputSecretValue({ value, publicKey }: { value: string, publicKey: KeyObject }): string {\n ow(value, ow.string);\n ow(publicKey, ow.object.instanceOf(KeyObject));\n\n const { encryptedValue, encryptedPassword } = publicEncrypt({ value, publicKey });\n return `${ENCRYPTED_INPUT_VALUE_PREFIX}:${encryptedPassword}:${encryptedValue}`;\n}\n\n/**\n * Encrypts actor input secrets\n */\nexport function encryptInputSecrets<T>(\n { input, inputSchema, publicKey }: { input: T, inputSchema: object, publicKey: KeyObject },\n): T {\n ow(input, ow.object);\n ow(inputSchema, ow.object);\n ow(publicKey, ow.object.instanceOf(KeyObject));\n\n const secretsInInputKeys = getInputSchemaSecretFieldKeys(inputSchema);\n if (secretsInInputKeys.length === 0) return input;\n\n const encryptedInput = {};\n for (const key of secretsInInputKeys) {\n const value = input[key];\n // NOTE: Skips already encrypted values. It can happens in case client already encrypted values, before\n // sending them using API. Or input was takes from task, run console or scheduler, where input is stored encrypted.\n if (value && ow.isValid(value, ow.string) && !ENCRYPTED_INPUT_VALUE_REGEXP.test(value)) {\n encryptedInput[key] = encryptInputSecretValue({ value: input[key], publicKey });\n }\n }\n\n return { ...input, ...encryptedInput };\n}\n\n/**\n * Decrypts actor input secrets\n * @param {Object} input\n * @param {KeyObject} privateKey\n * @returns Object\n */\nexport function decryptInputSecrets<T>(\n { input, privateKey }: { input: T, privateKey: KeyObject },\n): T {\n ow(input, ow.object);\n ow(privateKey, ow.object.instanceOf(KeyObject));\n\n const decryptedInput = {};\n for (const [key, value] of Object.entries(input)) {\n if (ow.isValid(value, ow.string) && ENCRYPTED_INPUT_VALUE_REGEXP.test(value)) {\n const match = value.match(ENCRYPTED_INPUT_VALUE_REGEXP);\n if (!match) continue;\n const [, encryptedPassword, encryptedValue] = match;\n try {\n decryptedInput[key] = privateDecrypt({ privateKey, encryptedPassword, encryptedValue });\n } catch (err) {\n throw new Error(`The input field \"${key}\" could not be decrypted. Try updating the field's value in the input editor. `\n + `Decryption error: ${err}`);\n }\n }\n }\n\n return { ...input, ...decryptedInput };\n}\n"],"mappings":";;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB,qBAAqB;AAC9C,OAAO,aAA0B;AAKjC,IAAM,KAAS,O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G,OAAO,WAAW,SAAS,CAAC;AAE9C,QAAM,iBAAiB,CAAC;AACxB,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,GAAG;AAC9C,QAAI,GAAG,QAAQ,OAAO,GAAG,MAAM,KAAK,6BAA6B,KAAK,KAAK,GAAG;AAC1E,YAAM,QAAQ,MAAM,MAAM,4BAA4B;AACtD,UAAI,CAAC;AAAO;AACZ,YAAM,CAAC,EAAE,mBAAmB,cAAc,IAAI;AAC9C,UAAI;AACA,uBAAe,GAAG,IAAI,eAAe,EAAE,YAAY,mBAAmB,eAAe,CAAC;AAAA,MAC1F,SAAS,KAAK;AACV,cAAM,IAAI,MAAM,oBAAoB,GAAG,mGAChB,GAAG,EAAE;AAAA,MAChC;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO,EAAE,GAAG,OAAO,GAAG,eAAe;AACzC;AAtBgB;","names":[]}
1
+ {"version":3,"sources":["../../src/input_secrets.ts"],"sourcesContent":["import { KeyObject } from 'crypto';\n\nimport { privateDecrypt, publicEncrypt } from '@apify/utilities';\nimport _testOw, { type Ow } from 'ow';\n\n// eslint-disable-next-line no-underscore-dangle\ndeclare const __injectedOw: Ow;\n\nconst ow: Ow = typeof __injectedOw === 'undefined' ? _testOw : __injectedOw || _testOw;\n\nconst BASE64_REGEXP = /[-A-Za-z0-9+/]*={0,3}/;\nconst ENCRYPTED_INPUT_VALUE_PREFIX = 'ENCRYPTED_VALUE';\nconst ENCRYPTED_INPUT_VALUE_REGEXP = new RegExp(`^${ENCRYPTED_INPUT_VALUE_PREFIX}:(${BASE64_REGEXP.source}):(${BASE64_REGEXP.source})$`);\n\n/**\n * Get keys of secret fields from input schema\n */\nexport function getInputSchemaSecretFieldKeys(inputSchema: any): string[] {\n return Object.keys(inputSchema.properties)\n .filter((key) => !!inputSchema.properties[key].isSecret);\n}\n\n/**\n * Encrypts input secret value\n */\nexport function encryptInputSecretValue({ value, publicKey }: { value: string, publicKey: KeyObject }): string {\n ow(value, ow.string);\n ow(publicKey, ow.object.instanceOf(KeyObject));\n\n const { encryptedValue, encryptedPassword } = publicEncrypt({ value, publicKey });\n return `${ENCRYPTED_INPUT_VALUE_PREFIX}:${encryptedPassword}:${encryptedValue}`;\n}\n\n/**\n * Encrypts actor input secrets\n */\nexport function encryptInputSecrets<T extends Record<string, any>>(\n { input, inputSchema, publicKey }: { input: T, inputSchema: object, publicKey: KeyObject },\n): T {\n ow(input, ow.object);\n ow(inputSchema, ow.object);\n ow(publicKey, ow.object.instanceOf(KeyObject));\n\n const secretsInInputKeys = getInputSchemaSecretFieldKeys(inputSchema);\n if (secretsInInputKeys.length === 0) return input;\n\n const encryptedInput = {} as Record<string, any>;\n for (const key of secretsInInputKeys) {\n const value = input[key];\n // NOTE: Skips already encrypted values. It can happens in case client already encrypted values, before\n // sending them using API. Or input was takes from task, run console or scheduler, where input is stored encrypted.\n if (value && ow.isValid(value, ow.string) && !ENCRYPTED_INPUT_VALUE_REGEXP.test(value)) {\n encryptedInput[key] = encryptInputSecretValue({ value: input[key], publicKey });\n }\n }\n\n return { ...input, ...encryptedInput };\n}\n\n/**\n * Decrypts actor input secrets\n * @param {Object} input\n * @param {KeyObject} privateKey\n * @returns Object\n */\nexport function decryptInputSecrets<T>(\n { input, privateKey }: { input: T, privateKey: KeyObject },\n): T {\n ow(input, ow.object);\n ow(privateKey, ow.object.instanceOf(KeyObject));\n\n const decryptedInput = {} as Record<string, any>;\n for (const [key, value] of Object.entries(input)) {\n if (ow.isValid(value, ow.string) && ENCRYPTED_INPUT_VALUE_REGEXP.test(value)) {\n const match = value.match(ENCRYPTED_INPUT_VALUE_REGEXP);\n if (!match) continue;\n const [, encryptedPassword, encryptedValue] = match;\n try {\n decryptedInput[key] = privateDecrypt({ privateKey, encryptedPassword, encryptedValue });\n } catch (err) {\n throw new Error(`The input field \"${key}\" could not be decrypted. Try updating the field's value in the input editor. `\n + `Decryption error: ${err}`);\n }\n }\n }\n\n return { ...input, ...decryptedInput };\n}\n"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zC;AArBgB;AA6BT,SAAS,oBACZ,EAAE,OAAO,WAAW,GACnB;AACD,KAAG,OAAO,GAAG,MAAM;AACnB,KAAG,YAAY,GAAG,OAAO,WAAW,SAAS,CAAC;AAE9C,QAAM,iBAAiB,CAAC;AACxB,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,GAAG;AAC9C,QAAI,GAAG,QAAQ,OAAO,GAAG,MAAM,KAAK,6BAA6B,KAAK,KAAK,GAAG;AAC1E,YAAM,QAAQ,MAAM,MAAM,4BAA4B;AACtD,UAAI,CAAC,MAAO;AACZ,YAAM,CAAC,EAAE,mBAAmB,cAAc,IAAI;AAC9C,UAAI;AACA,uBAAe,GAAG,IAAI,eAAe,EAAE,YAAY,mBAAmB,eAAe,CAAC;AAAA,MAC1F,SAAS,KAAK;AACV,cAAM,IAAI,MAAM,oBAAoB,GAAG,mGAChB,GAAG,EAAE;AAAA,MAChC;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO,EAAE,GAAG,OAAO,GAAG,eAAe;AACzC;AAtBgB;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apify/input_secrets",
3
- "version": "1.1.52",
3
+ "version": "1.1.54",
4
4
  "description": "Package to encrypt and decrypt apify actor input secrets.",
5
5
  "main": "./cjs/index.cjs",
6
6
  "module": "./esm/index.mjs",
@@ -44,9 +44,9 @@
44
44
  "access": "public"
45
45
  },
46
46
  "dependencies": {
47
- "@apify/log": "^2.5.4",
48
- "@apify/utilities": "^2.10.5",
47
+ "@apify/log": "^2.5.6",
48
+ "@apify/utilities": "^2.10.7",
49
49
  "ow": "^0.28.2"
50
50
  },
51
- "gitHead": "a8e54286093c840cb2b3c398d4fa97db23ca5770"
51
+ "gitHead": "86858349350cc21833853c786964e15080aa9226"
52
52
  }