@mondaycom/apps-sdk
Advanced tools
Comparing version 3.0.2 to 3.0.3-beta.1
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
exports.__esModule = true; | ||
exports.EnvironmentVariablesManager = void 0; | ||
var fs_1 = __importDefault(require("fs")); | ||
var process = __importStar(require("process")); | ||
var guards_1 = require("../types/guards.js"); | ||
var env_1 = require("../utils/env.js"); | ||
var logger_1 = require("../utils/logger.js"); | ||
var key_value_manager_abstract_1 = require("../key-value-manager/key-value-manager.abstract.js"); | ||
var string_manipulations_1 = require("../utils/string-manipulations.js"); | ||
var logger = new logger_1.Logger('EnvironmentVariablesManager', { mondayInternal: true }); | ||
var readEnvironmentData = function () { | ||
var _a; | ||
var environmentDataFileName = (_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.SECRET_NAME; | ||
if (!(0, guards_1.isDefined)(environmentDataFileName)) { | ||
logger.error('[EnvironmentVariablesManager] Environment file name is not defined'); | ||
return; | ||
} | ||
var environmentDataFilePath = "/secrets/".concat(environmentDataFileName); | ||
var isEnvironmentFileExists = fs_1["default"].existsSync(environmentDataFilePath); | ||
if (!isEnvironmentFileExists) { | ||
logger.error('[EnvironmentVariablesManager] Environment file does not exist in path'); | ||
return; | ||
} | ||
var environmentData = fs_1["default"].readFileSync(environmentDataFilePath, 'utf8'); | ||
try { | ||
return JSON.parse(environmentData); | ||
} | ||
catch (error) { | ||
logger.error('[EnvironmentVariablesManager] Corrupted Environment file. File is not in JSON format'); | ||
return; | ||
} | ||
}; | ||
var EnvironmentVariablesManager = /** @class */ (function () { | ||
var EnvironmentVariablesManager = /** @class */ (function (_super) { | ||
__extends(EnvironmentVariablesManager, _super); | ||
function EnvironmentVariablesManager(options) { | ||
this.shouldUpdateProcessEnv = !!(options === null || options === void 0 ? void 0 : options.updateProcessEnv); | ||
this.initEnv(options); | ||
if ((0, env_1.isLocalEnvironment)()) { | ||
logger.info('[EnvironmentVariablesManager] Running in development environment, Using process.env', { mondayInternal: false }); | ||
} | ||
var _this = this; | ||
var dataFileName = process.env.SECRET_NAME; | ||
_this = _super.call(this, 'EnvironmentVariablesManager', dataFileName, 'secrets') || this; | ||
_this.shouldUpdateProcessEnv = Boolean(options === null || options === void 0 ? void 0 : options.updateProcessEnv); | ||
_this.initData(); | ||
return _this; | ||
} | ||
EnvironmentVariablesManager.prototype.initEnvIfNeeded = function (options) { | ||
var _a; | ||
var shouldInvalidate = (_a = options === null || options === void 0 ? void 0 : options.invalidate) !== null && _a !== void 0 ? _a : true; | ||
if (shouldInvalidate || !this.cachedEnvironmentData) { | ||
this.initEnv(); | ||
} | ||
}; | ||
EnvironmentVariablesManager.prototype.initEnv = function (options) { | ||
if (options === void 0) { options = {}; } | ||
if ((0, env_1.isLocalEnvironment)()) { | ||
this.cachedEnvironmentData = process.env; | ||
return; | ||
} | ||
var updateProcessEnv = options.updateProcessEnv; | ||
this.shouldUpdateProcessEnv = updateProcessEnv !== null && updateProcessEnv !== void 0 ? updateProcessEnv : this.shouldUpdateProcessEnv; | ||
this.cachedEnvironmentData = readEnvironmentData(); | ||
if (!(0, guards_1.isDefined)(this.cachedEnvironmentData)) { | ||
return; | ||
} | ||
EnvironmentVariablesManager.prototype.initData = function () { | ||
_super.prototype.initData.call(this); | ||
if (this.shouldUpdateProcessEnv) { | ||
Object.entries(this.cachedEnvironmentData).forEach(function (_a) { | ||
Object.entries(this.cachedData).forEach(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
@@ -93,23 +40,7 @@ var snakeCaseKey = (0, string_manipulations_1.snakeCase)(key, { upperCase: true }); | ||
} | ||
logger.info('[EnvironmentVariablesManager] Initialized environment variables data', { mondayInternal: true }); | ||
this.logger.info("[".concat(this.tag, "] Successfully updated process.env with data from file"), { mondayInternal: true }); | ||
}; | ||
EnvironmentVariablesManager.prototype.getKeys = function (options) { | ||
this.initEnvIfNeeded(options); | ||
if (!(0, guards_1.isDefined)(this.cachedEnvironmentData)) { | ||
logger.error('[EnvironmentVariablesManager.getKeys] There is an issue with loading keys', { mondayInternal: false }); | ||
return []; | ||
} | ||
return Object.keys(this.cachedEnvironmentData); | ||
}; | ||
EnvironmentVariablesManager.prototype.get = function (key, options) { | ||
this.initEnvIfNeeded(options); | ||
if (!(0, guards_1.isDefined)(this.cachedEnvironmentData)) { | ||
logger.error('[EnvironmentVariablesManager.get] There is an issue with loading data for key', { mondayInternal: false }); | ||
return null; | ||
} | ||
return this.cachedEnvironmentData[key] || process.env[key]; | ||
}; | ||
return EnvironmentVariablesManager; | ||
}()); | ||
}(key_value_manager_abstract_1.KeyValueManager)); | ||
exports.EnvironmentVariablesManager = EnvironmentVariablesManager; | ||
//# sourceMappingURL=environment-variables-manager.js.map |
"use strict"; | ||
exports.__esModule = true; | ||
exports.Queue = exports.Logger = exports.EnvironmentVariablesManager = exports.Period = exports.Storage = exports.SecureStorage = void 0; | ||
exports.Queue = exports.SecretsManager = exports.Logger = exports.EnvironmentVariablesManager = exports.Period = exports.Storage = exports.SecureStorage = void 0; | ||
var environment_variables_manager_1 = require("./environment-variables-manager/index.js"); | ||
@@ -10,2 +10,4 @@ exports.EnvironmentVariablesManager = environment_variables_manager_1.EnvironmentVariablesManager; | ||
exports.Queue = queue_1.Queue; | ||
var secrets_manager_1 = require("./secrets-manager/index.js"); | ||
exports.SecretsManager = secrets_manager_1.SecretsManager; | ||
var secure_storage_1 = require("./secure-storage/index.js"); | ||
@@ -12,0 +14,0 @@ exports.SecureStorage = secure_storage_1.SecureStorage; |
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = { name: '@mondaycom/apps-sdk', version: '3.0.2' }; | ||
exports["default"] = { name: '@mondaycom/apps-sdk', version: '3.0.3-beta.1' }; | ||
//# sourceMappingURL=minimal-package.js.map |
{ | ||
"name": "@mondaycom/apps-sdk", | ||
"version": "3.0.2", | ||
"version": "3.0.3-beta.1", | ||
"description": "monday apps SDK for NodeJS", | ||
@@ -5,0 +5,0 @@ "main": "./dist/cjs/index.js", |
@@ -51,5 +51,9 @@ "use strict"; | ||
}; | ||
var localDB = null; | ||
var LocalSecureStorage = /** @class */ (function () { | ||
function LocalSecureStorage() { | ||
this.db = (0, local_db_1.initDb)('local-secure-storage.db'); | ||
if (!localDB) { | ||
localDB = (0, local_db_1.initDb)('local-secure-storage.db'); | ||
} | ||
this.db = localDB; | ||
} | ||
@@ -56,0 +60,0 @@ LocalSecureStorage.prototype["delete"] = function (key) { |
@@ -1,59 +0,32 @@ | ||
import fs from 'fs'; | ||
import * as process from 'process'; | ||
import { isDefined } from '../types/guards.js'; | ||
import { isLocalEnvironment } from '../utils/env.js'; | ||
import { Logger } from '../utils/logger.js'; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
import { KeyValueManager } from '../key-value-manager/key-value-manager.abstract.js'; | ||
import { snakeCase } from '../utils/string-manipulations.js'; | ||
var logger = new Logger('EnvironmentVariablesManager', { mondayInternal: true }); | ||
var readEnvironmentData = function () { | ||
var _a; | ||
var environmentDataFileName = (_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.SECRET_NAME; | ||
if (!isDefined(environmentDataFileName)) { | ||
logger.error('[EnvironmentVariablesManager] Environment file name is not defined'); | ||
return; | ||
} | ||
var environmentDataFilePath = "/secrets/".concat(environmentDataFileName); | ||
var isEnvironmentFileExists = fs.existsSync(environmentDataFilePath); | ||
if (!isEnvironmentFileExists) { | ||
logger.error('[EnvironmentVariablesManager] Environment file does not exist in path'); | ||
return; | ||
} | ||
var environmentData = fs.readFileSync(environmentDataFilePath, 'utf8'); | ||
try { | ||
return JSON.parse(environmentData); | ||
} | ||
catch (error) { | ||
logger.error('[EnvironmentVariablesManager] Corrupted Environment file. File is not in JSON format'); | ||
return; | ||
} | ||
}; | ||
var EnvironmentVariablesManager = /** @class */ (function () { | ||
var EnvironmentVariablesManager = /** @class */ (function (_super) { | ||
__extends(EnvironmentVariablesManager, _super); | ||
function EnvironmentVariablesManager(options) { | ||
this.shouldUpdateProcessEnv = !!(options === null || options === void 0 ? void 0 : options.updateProcessEnv); | ||
this.initEnv(options); | ||
if (isLocalEnvironment()) { | ||
logger.info('[EnvironmentVariablesManager] Running in development environment, Using process.env', { mondayInternal: false }); | ||
} | ||
var _this = this; | ||
var dataFileName = process.env.SECRET_NAME; | ||
_this = _super.call(this, 'EnvironmentVariablesManager', dataFileName, 'secrets') || this; | ||
_this.shouldUpdateProcessEnv = Boolean(options === null || options === void 0 ? void 0 : options.updateProcessEnv); | ||
_this.initData(); | ||
return _this; | ||
} | ||
EnvironmentVariablesManager.prototype.initEnvIfNeeded = function (options) { | ||
var _a; | ||
var shouldInvalidate = (_a = options === null || options === void 0 ? void 0 : options.invalidate) !== null && _a !== void 0 ? _a : true; | ||
if (shouldInvalidate || !this.cachedEnvironmentData) { | ||
this.initEnv(); | ||
} | ||
}; | ||
EnvironmentVariablesManager.prototype.initEnv = function (options) { | ||
if (options === void 0) { options = {}; } | ||
if (isLocalEnvironment()) { | ||
this.cachedEnvironmentData = process.env; | ||
return; | ||
} | ||
var updateProcessEnv = options.updateProcessEnv; | ||
this.shouldUpdateProcessEnv = updateProcessEnv !== null && updateProcessEnv !== void 0 ? updateProcessEnv : this.shouldUpdateProcessEnv; | ||
this.cachedEnvironmentData = readEnvironmentData(); | ||
if (!isDefined(this.cachedEnvironmentData)) { | ||
return; | ||
} | ||
EnvironmentVariablesManager.prototype.initData = function () { | ||
_super.prototype.initData.call(this); | ||
if (this.shouldUpdateProcessEnv) { | ||
Object.entries(this.cachedEnvironmentData).forEach(function (_a) { | ||
Object.entries(this.cachedData).forEach(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
@@ -64,23 +37,7 @@ var snakeCaseKey = snakeCase(key, { upperCase: true }); | ||
} | ||
logger.info('[EnvironmentVariablesManager] Initialized environment variables data', { mondayInternal: true }); | ||
this.logger.info("[".concat(this.tag, "] Successfully updated process.env with data from file"), { mondayInternal: true }); | ||
}; | ||
EnvironmentVariablesManager.prototype.getKeys = function (options) { | ||
this.initEnvIfNeeded(options); | ||
if (!isDefined(this.cachedEnvironmentData)) { | ||
logger.error('[EnvironmentVariablesManager.getKeys] There is an issue with loading keys', { mondayInternal: false }); | ||
return []; | ||
} | ||
return Object.keys(this.cachedEnvironmentData); | ||
}; | ||
EnvironmentVariablesManager.prototype.get = function (key, options) { | ||
this.initEnvIfNeeded(options); | ||
if (!isDefined(this.cachedEnvironmentData)) { | ||
logger.error('[EnvironmentVariablesManager.get] There is an issue with loading data for key', { mondayInternal: false }); | ||
return null; | ||
} | ||
return this.cachedEnvironmentData[key] || process.env[key]; | ||
}; | ||
return EnvironmentVariablesManager; | ||
}()); | ||
}(KeyValueManager)); | ||
export { EnvironmentVariablesManager }; | ||
//# sourceMappingURL=environment-variables-manager.js.map |
import { EnvironmentVariablesManager } from './environment-variables-manager/index.js'; | ||
import { Logger } from './logger/index.js'; | ||
import { Queue } from './queue/index.js'; | ||
import { SecretsManager } from './secrets-manager/index.js'; | ||
import { SecureStorage } from './secure-storage/index.js'; | ||
import { Period, Storage } from './storage/index.js'; | ||
export { SecureStorage, Storage, Period, EnvironmentVariablesManager, Logger, Queue }; | ||
export { SecureStorage, Storage, Period, EnvironmentVariablesManager, Logger, SecretsManager, Queue }; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
export default { name: '@mondaycom/apps-sdk', version: '3.0.2' }; | ||
export default { name: '@mondaycom/apps-sdk', version: '3.0.3-beta.1' }; | ||
//# sourceMappingURL=minimal-package.js.map |
{ | ||
"name": "@mondaycom/apps-sdk", | ||
"version": "3.0.2", | ||
"version": "3.0.3-beta.1", | ||
"description": "monday apps SDK for NodeJS", | ||
@@ -5,0 +5,0 @@ "main": "./dist/cjs/index.js", |
@@ -48,5 +48,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
var localDB = null; | ||
var LocalSecureStorage = /** @class */ (function () { | ||
function LocalSecureStorage() { | ||
this.db = initDb('local-secure-storage.db'); | ||
if (!localDB) { | ||
localDB = initDb('local-secure-storage.db'); | ||
} | ||
this.db = localDB; | ||
} | ||
@@ -53,0 +57,0 @@ LocalSecureStorage.prototype["delete"] = function (key) { |
@@ -1,11 +0,7 @@ | ||
import { JsonValue } from '../types/general'; | ||
import { GetOptions, IEnvironmentVariablesManager, Options } from '../types/environment-variables-manager'; | ||
export declare class EnvironmentVariablesManager implements IEnvironmentVariablesManager { | ||
private cachedEnvironmentData?; | ||
private shouldUpdateProcessEnv; | ||
import { KeyValueManager } from '../key-value-manager/key-value-manager.abstract'; | ||
import { Options } from '../types/key-value-manager'; | ||
export declare class EnvironmentVariablesManager extends KeyValueManager { | ||
private readonly shouldUpdateProcessEnv; | ||
constructor(options?: Options); | ||
private initEnvIfNeeded; | ||
private initEnv; | ||
getKeys(options?: GetOptions): Array<string>; | ||
get(key: string, options?: GetOptions): JsonValue; | ||
protected initData(): void; | ||
} |
import { EnvironmentVariablesManager } from './environment-variables-manager'; | ||
import { Logger } from './logger'; | ||
import { Queue } from './queue'; | ||
import { SecretsManager } from './secrets-manager'; | ||
import { SecureStorage } from './secure-storage'; | ||
import { Period, Storage } from './storage'; | ||
export { SecureStorage, Storage, Period, EnvironmentVariablesManager, Logger, Queue }; | ||
export { SecureStorage, Storage, Period, EnvironmentVariablesManager, Logger, SecretsManager, Queue }; |
{ | ||
"name": "@mondaycom/apps-sdk", | ||
"version": "3.0.2", | ||
"version": "3.0.3-beta.1", | ||
"description": "monday apps SDK for NodeJS", | ||
@@ -5,0 +5,0 @@ "main": "./dist/cjs/index.js", |
@@ -129,3 +129,2 @@ <h3 style="color:red"><b>Public access to this SDK is currently restricted but will become available in the next few months</b></h3> | ||
``` | ||
- This environment variables are stored in a secure manner and can be used to store sensitive data (i.e. DB connection string, API keys, etc.) | ||
- The environment variables are on the **app** level which means that they are accessible by all the **versions** of the app | ||
@@ -171,2 +170,49 @@ | ||
## Secrets manager | ||
<details> | ||
<summary>Read secrets in monday-code projects</summary> | ||
- This is the way to **read** secrets for your app in a project deployed `<monday-code/>`. | ||
- Secrets are set via [@mondaycom/apps-cli](https://www.npmjs.com/package/@mondaycom/apps-cli) | ||
```shell | ||
$ mapps code:secrets -m set -k <key> -v <value> | ||
``` | ||
- These secrets are stored in a secure manner and can be used to store sensitive data (i.e. DB connection string, API keys, etc.) | ||
- The secrets are on the **app** level which means that they are accessible by all the **versions** of the app | ||
### Secrets manager API | ||
There are two methods exposed to manage the secrets - `get` and `getKeys` | ||
#### initialize | ||
```typescript | ||
import { SecretsManager } from '@mondaycom/apps-sdk'; | ||
const secretsManager = new SecretsManager(); | ||
``` | ||
#### get | ||
```typescript | ||
// Get cached secrets | ||
const cachedValue = secretsManager.get(key, { invalidate: false }); | ||
// Get the latest version of a secret | ||
const latestValue = secretsManager.get(key); | ||
``` | ||
#### getKeys | ||
```typescript | ||
// Get all cached secrets keys | ||
const cachedKeys = secretsManager.getKeys({ invalidate: false }); | ||
// Get all secrets keys | ||
const latestKeys = secretsManager.getKeys(); | ||
``` | ||
</details> | ||
## Logger | ||
@@ -173,0 +219,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
295925
210
4045
269
1078
1
32