@apify/input_secrets 1.1.37 → 1.1.39

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 CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
7
  var __export = (target, all) => {
@@ -18,14 +16,6 @@ var __copyProps = (to, from, except, desc) => {
18
16
  }
19
17
  return to;
20
18
  };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
20
 
31
21
  // src/index.ts
@@ -39,9 +29,14 @@ __export(src_exports, {
39
29
  module.exports = __toCommonJS(src_exports);
40
30
 
41
31
  // src/input_secrets.ts
42
- var import_ow = __toESM(require("ow"));
43
32
  var import_crypto = require("crypto");
44
33
  var import_utilities = require("@apify/utilities");
34
+
35
+ // src/ow.ts
36
+ var defOw = require("ow");
37
+ var ow = defOw.default;
38
+
39
+ // src/input_secrets.ts
45
40
  var BASE64_REGEXP = /[-A-Za-z0-9+/]*={0,3}/;
46
41
  var ENCRYPTED_INPUT_VALUE_PREFIX = "ENCRYPTED_VALUE";
47
42
  var ENCRYPTED_INPUT_VALUE_REGEXP = new RegExp(`^${ENCRYPTED_INPUT_VALUE_PREFIX}:(${BASE64_REGEXP.source}):(${BASE64_REGEXP.source})$`);
@@ -50,23 +45,23 @@ function getInputSchemaSecretFieldKeys(inputSchema) {
50
45
  }
51
46
  __name(getInputSchemaSecretFieldKeys, "getInputSchemaSecretFieldKeys");
52
47
  function encryptInputSecretValue({ value, publicKey }) {
53
- (0, import_ow.default)(value, import_ow.default.string);
54
- (0, import_ow.default)(publicKey, import_ow.default.object.instanceOf(import_crypto.KeyObject));
48
+ ow(value, ow.string);
49
+ ow(publicKey, ow.object.instanceOf(import_crypto.KeyObject));
55
50
  const { encryptedValue, encryptedPassword } = (0, import_utilities.publicEncrypt)({ value, publicKey });
56
51
  return `${ENCRYPTED_INPUT_VALUE_PREFIX}:${encryptedPassword}:${encryptedValue}`;
57
52
  }
58
53
  __name(encryptInputSecretValue, "encryptInputSecretValue");
59
54
  function encryptInputSecrets({ input, inputSchema, publicKey }) {
60
- (0, import_ow.default)(input, import_ow.default.object);
61
- (0, import_ow.default)(inputSchema, import_ow.default.object);
62
- (0, import_ow.default)(publicKey, import_ow.default.object.instanceOf(import_crypto.KeyObject));
55
+ ow(input, ow.object);
56
+ ow(inputSchema, ow.object);
57
+ ow(publicKey, ow.object.instanceOf(import_crypto.KeyObject));
63
58
  const secretsInInputKeys = getInputSchemaSecretFieldKeys(inputSchema);
64
59
  if (secretsInInputKeys.length === 0)
65
60
  return input;
66
61
  const encryptedInput = {};
67
62
  for (const key of secretsInInputKeys) {
68
63
  const value = input[key];
69
- if (value && import_ow.default.isValid(value, import_ow.default.string) && !ENCRYPTED_INPUT_VALUE_REGEXP.test(value)) {
64
+ if (value && ow.isValid(value, ow.string) && !ENCRYPTED_INPUT_VALUE_REGEXP.test(value)) {
70
65
  encryptedInput[key] = encryptInputSecretValue({ value: input[key], publicKey });
71
66
  }
72
67
  }
@@ -74,11 +69,11 @@ function encryptInputSecrets({ input, inputSchema, publicKey }) {
74
69
  }
75
70
  __name(encryptInputSecrets, "encryptInputSecrets");
76
71
  function decryptInputSecrets({ input, privateKey }) {
77
- (0, import_ow.default)(input, import_ow.default.object);
78
- (0, import_ow.default)(privateKey, import_ow.default.object.instanceOf(import_crypto.KeyObject));
72
+ ow(input, ow.object);
73
+ ow(privateKey, ow.object.instanceOf(import_crypto.KeyObject));
79
74
  const decryptedInput = {};
80
75
  for (const [key, value] of Object.entries(input)) {
81
- if (import_ow.default.isValid(value, import_ow.default.string) && ENCRYPTED_INPUT_VALUE_REGEXP.test(value)) {
76
+ if (ow.isValid(value, ow.string) && ENCRYPTED_INPUT_VALUE_REGEXP.test(value)) {
82
77
  const match = value.match(ENCRYPTED_INPUT_VALUE_REGEXP);
83
78
  if (!match)
84
79
  continue;
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/input_secrets.ts"],"sourcesContent":["export * from './input_secrets';\n","import ow from 'ow';\nimport { KeyObject } from 'crypto';\nimport { privateDecrypt, publicEncrypt } from '@apify/utilities';\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,gBAAe;AACf,oBAA0B;AAC1B,uBAA8C;AAE9C,IAAM,gBAAgB;AACtB,IAAM,+BAA+B;AACrC,IAAM,+BAA+B,IAAI,OAAO,I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AS,CAAC;AAE9C,QAAM,iBAAiB,CAAC;AACxB,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,GAAG;AAC9C,QAAI,UAAAA,QAAG,QAAQ,OAAO,UAAAA,QAAG,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,QAAI,iCAAe,EAAE,YAAY,mBAAmB,eAAe,CAAC;AAAA,MAC1F,SAAS,KAAP;AACE,cAAM,IAAI,MAAM,oBAAoB,sGACb,KAAK;AAAA,MAChC;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO,EAAE,GAAG,OAAO,GAAG,eAAe;AACzC;AAtBgB;","names":["ow"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/input_secrets.ts","../src/ow.ts"],"sourcesContent":["export * from './input_secrets';\n","import { KeyObject } from 'crypto';\nimport { privateDecrypt, publicEncrypt } from '@apify/utilities';\n\nimport { ow } from './ow';\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","// This file is needed to solve ow's false representation of the package in older versions.\n\n// In CJS, to use ow, you need to call ow.default\n// In ESM, you'd think `import ow from 'ow'` works, but it doesn't, because you need to import ow and use the default PROPERTY, not export.\n\nimport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AClF;AAAA,EACJ;AAEA,SAAO,EAAE,GAAG,OAAO,GAAG,eAAe;AACzC;AArBgB;AA6BT,SAAS,oBACZ,EAAE,OAAO,WAAW,GACnB;AACD,KAAG,OAAO,GAAG,MAAM;AACnB,KAAG,YAAY,GAAG,OAAO,WAAW,uBAAS,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,QAAI,iCAAe,EAAE,YAAY,mBAAmB,eAAe,CAAC;AAAA,MAC1F,SAAS,KAAP;AACE,cAAM,IAAI,MAAM,oBAAoB,sGACb,KAAK;AAAA,MAChC;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO,EAAE,GAAG,OAAO,GAAG,eAAe;AACzC;AAtBgB;","names":[]}
package/index.mjs CHANGED
@@ -1,10 +1,22 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
4
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
5
+ }) : x)(function(x) {
6
+ if (typeof require !== "undefined")
7
+ return require.apply(this, arguments);
8
+ throw new Error('Dynamic require of "' + x + '" is not supported');
9
+ });
3
10
 
4
11
  // src/input_secrets.ts
5
- import ow from "ow";
6
12
  import { KeyObject } from "crypto";
7
13
  import { privateDecrypt, publicEncrypt } from "@apify/utilities";
14
+
15
+ // src/ow.ts
16
+ var defOw = __require("ow");
17
+ var ow = defOw.default;
18
+
19
+ // src/input_secrets.ts
8
20
  var BASE64_REGEXP = /[-A-Za-z0-9+/]*={0,3}/;
9
21
  var ENCRYPTED_INPUT_VALUE_PREFIX = "ENCRYPTED_VALUE";
10
22
  var ENCRYPTED_INPUT_VALUE_REGEXP = new RegExp(`^${ENCRYPTED_INPUT_VALUE_PREFIX}:(${BASE64_REGEXP.source}):(${BASE64_REGEXP.source})$`);
package/index.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/input_secrets.ts"],"sourcesContent":["import ow from 'ow';\nimport { KeyObject } from 'crypto';\nimport { privateDecrypt, publicEncrypt } from '@apify/utilities';\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,OAAO,QAAQ;AACf,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB,qBAAqB;AAE9C,IAAM,gBAAgB;AACtB,IAAM,+BAA+B;AACrC,IAAM,+BAA+B,IAAI,OAAO,IAAI,iCAAiC,cAAc,YAAY,cAAc,UAAU;AAKhI,SAAS,8BAA8B,aAA4B;AACtE,SAAO,OAAO,KAAK,YAAY,UAAU,EACpC,OAAO,CAAC,QAAQ,CAAC,CAAC,YAAY,WAAW,GAAG,EAAE,QAAQ;AAC/D;AAHgB;AAQT,SAAS,wBAAwB,EAAE,OAAO,UAAU,GAAoD;AAC3G,KAAG,OAAO,GAAG,MAAM;AACnB,KAAG,WAAW,GAAG,OAAO,WAAW,SA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AAAA,MAChC;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO,EAAE,GAAG,OAAO,GAAG,eAAe;AACzC;AAtBgB;","names":[]}
1
+ {"version":3,"sources":["../src/input_secrets.ts","../src/ow.ts"],"sourcesContent":["import { KeyObject } from 'crypto';\nimport { privateDecrypt, publicEncrypt } from '@apify/utilities';\n\nimport { ow } from './ow';\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","// This file is needed to solve ow's false representation of the package in older versions.\n\n// In CJS, to use ow, you need to call ow.default\n// In ESM, you'd think `import ow from 'ow'` works, but it doesn't, because you need to import ow and use the default PROPERTY, not export.\n\nimport type { Ow } from 'ow';\nimport defOw = require('ow');\n\nexport const ow: Ow = defOw.default as Ow;\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB,qBAAqB;;;ACK9C,IAAO,QAAQ,UAAQ;AAEhB,IAAM,KAAS,MAAM;;;ADH5B,IAAM,gBAAgB;AACtB,IAAM,+BAA+B;AACrC,IAAM,+BAA+B,IAAI,OAAO,IAAI,iCAAiC,cAAc,YAAY,cAAc,UAAU;AAKhI,SAAS,8BAA8B,aAA4B;AACtE,SAAO,OAAO,KAAK,YAAY,UAAU,EACpC,OAAO,CAAC,QAAQ,CAAC,CAAC,YAAY,WAAW,GAAG,EAAE,QAAQ;AAC/D;AAHgB;AAQT,SAAS,wBAAwB,E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AAY,mBAAmB,eAAe,CAAC;AAAA,MAC1F,SAAS,KAAP;AACE,cAAM,IAAI,MAAM,oBAAoB,sGACb,KAAK;AAAA,MAChC;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO,EAAE,GAAG,OAAO,GAAG,eAAe;AACzC;AAtBgB;","names":[]}
package/ow.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import type { Ow } from 'ow';
2
+ export declare const ow: Ow;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apify/input_secrets",
3
- "version": "1.1.37",
3
+ "version": "1.1.39",
4
4
  "description": "Package to encrypt and decrypt apify actor input secrets.",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -39,9 +39,9 @@
39
39
  "access": "public"
40
40
  },
41
41
  "dependencies": {
42
- "@apify/log": "^2.4.2",
43
- "@apify/utilities": "^2.9.2",
42
+ "@apify/log": "^2.4.3",
43
+ "@apify/utilities": "^2.9.3",
44
44
  "ow": "^0.28.2"
45
45
  },
46
- "gitHead": "21d32adc11f053bfd319589dff8115b2b36c7da6"
46
+ "gitHead": "0789d3119ac297898becb02821f8fbbc19908612"
47
47
  }