@begin/data
Advanced tools
Comparing version 3.0.4 to 4.0.0-RC.0
# Begin Data changelog | ||
--- | ||
## [4.0.0] 2022-02-07 | ||
### Changed | ||
- Breaking change: Begin Data no longer relies on or makes direct use of `NODE_ENV` or other legacy Architect env vars. `@begin/data` v4+ now requires Architect v10 / Sandbox v5 or later. | ||
- Improved table lookup performance | ||
--- | ||
## [3.0.4] 2021-10-18 | ||
@@ -8,3 +18,3 @@ | ||
- Fixed issue so that if present ARC_ENV takes precedence over NODE_ENV for stage. | ||
- Fixed issue so that if present `ARC_ENV` takes precedence over `NODE_ENV` for stage. | ||
@@ -11,0 +21,0 @@ --- |
{ | ||
"name": "@begin/data", | ||
"version": "3.0.4", | ||
"version": "4.0.0-RC.0", | ||
"description": "Begin Data is a durable and fast key/value document store built on top of DynamoDB", | ||
@@ -29,8 +29,8 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@architect/eslint-config": "^1.0.1", | ||
"@architect/sandbox": "^4.2.1", | ||
"eslint": "^8.0.1", | ||
"@architect/eslint-config": "^2.0.1", | ||
"@architect/sandbox": "^5.0.0-RC.9", | ||
"eslint": "^8.8.0", | ||
"tap-spec": "^5.0.0", | ||
"tape": "^5.3.1", | ||
"tiny-json-http": "^7.3.0" | ||
"tape": "^5.5.0", | ||
"tiny-json-http": "^7.3.1" | ||
}, | ||
@@ -37,0 +37,0 @@ "eslintConfig": { |
@@ -12,2 +12,3 @@ /** | ||
module.exports = function createKey (table, callback) { | ||
let { ARC_APP_NAME = 'sandbox', BEGIN_DATA_SCOPE_ID } = process.env | ||
waterfall([ | ||
@@ -25,3 +26,3 @@ getTableName, | ||
Key: { | ||
'scopeID': { S: process.env.BEGIN_DATA_SCOPE_ID || process.env.ARC_APP_NAME || 'sandbox' }, | ||
'scopeID': { S: BEGIN_DATA_SCOPE_ID || ARC_APP_NAME }, | ||
'dataID': { S: `${table}-seq` } | ||
@@ -28,0 +29,0 @@ }, |
@@ -9,8 +9,13 @@ let aws = require('aws-sdk') | ||
if (!type) throw ReferenceError('Must supply Dynamo service interface type') | ||
let { ARC_ENV, ARC_SANDBOX, AWS_REGION } = process.env | ||
let testing = process.env.ARC_ENV ? process.env.ARC_ENV === 'testing' : process.env.NODE_ENV === 'testing' | ||
let port = process.env.ARC_TABLES_PORT || 5000 | ||
let local = { | ||
endpoint: new aws.Endpoint(`http://localhost:${port}`), | ||
region: process.env.AWS_REGION || 'us-west-2' // Do not assume region is set! | ||
let testing = ARC_ENV === 'testing' | ||
let local | ||
if (testing) { | ||
let { ports } = JSON.parse(ARC_SANDBOX) | ||
let port = ports.tables | ||
local = { | ||
endpoint: new aws.Endpoint(`http://localhost:${port}`), | ||
region: AWS_REGION || 'us-west-2' // Do not assume region is set! | ||
} | ||
} | ||
@@ -21,3 +26,3 @@ let DB = aws.DynamoDB | ||
function updateConfig () { | ||
if (!testing) { | ||
let agent = new https.Agent({ | ||
@@ -35,5 +40,2 @@ keepAlive: true, | ||
if (type === 'db') { | ||
if (!testing) { | ||
updateConfig() | ||
} | ||
dynamo = testing | ||
@@ -45,5 +47,2 @@ ? new DB(local) | ||
if (type === 'doc') { | ||
if (!testing) { | ||
updateConfig() | ||
} | ||
dynamo = testing | ||
@@ -50,0 +49,0 @@ ? new Doc(local) |
@@ -14,7 +14,8 @@ /** | ||
let { table, key } = params | ||
let env = process.env.ARC_ENV || process.env.NODE_ENV | ||
let { ARC_APP_NAME, ARC_ENV, BEGIN_DATA_SCOPE_ID } = process.env | ||
let env = ARC_ENV | ||
let envKey = env === 'testing' ? 'staging' : (env || 'staging') | ||
let scopeID = process.env.BEGIN_DATA_SCOPE_ID || process.env.ARC_APP_NAME || 'sandbox' | ||
let scopeID = BEGIN_DATA_SCOPE_ID || ARC_APP_NAME || 'sandbox' | ||
let dataID = `${envKey}#${table}#${key}` | ||
return { scopeID, dataID } | ||
} |
@@ -6,8 +6,6 @@ let aws = require('aws-sdk') | ||
module.exports = function getTableName (callback) { | ||
let override = process.env.BEGIN_DATA_TABLE_NAME | ||
// ARC_CLOUDFORMATION is present in live AWS deploys with Architect 6+ | ||
let arc6 = process.env.ARC_CLOUDFORMATION || process.env.ARC_HTTP === 'aws_proxy' || process.env.ARC_ENV | ||
let { ARC_APP_NAME, ARC_ENV, ARC_SANDBOX, AWS_REGION, BEGIN_DATA_TABLE_NAME } = process.env | ||
if (override) { | ||
callback(null, process.env.BEGIN_DATA_TABLE_NAME) | ||
if (BEGIN_DATA_TABLE_NAME) { | ||
callback(null, BEGIN_DATA_TABLE_NAME) | ||
} | ||
@@ -18,11 +16,12 @@ // Use cached value | ||
} | ||
else if (arc6) { | ||
let isLocal = process.env.ARC_ENV ? process.env.ARC_ENV === 'testing' : process.env.NODE_ENV === 'testing' | ||
else { | ||
let isLocal = ARC_ENV === 'testing' | ||
let config | ||
if (isLocal) { | ||
// If running in Sandbox, use its SSM service discovery mock | ||
let port = process.env.ARC_INTERNAL || 3332 | ||
let { ports } = JSON.parse(ARC_SANDBOX) | ||
let port = ports._arc | ||
config = { | ||
endpoint: new aws.Endpoint(`http://localhost:${port}/_arc/ssm`), | ||
region: process.env.AWS_REGION || 'us-west-2', | ||
region: AWS_REGION || 'us-west-2', | ||
httpOptions: { agent: new http.Agent() } | ||
@@ -32,3 +31,4 @@ } | ||
let ssm = new aws.SSM(config) | ||
let Path = `/${process.env.ARC_CLOUDFORMATION || 'sandbox'}` | ||
let appName = toLogicalID(`${ARC_APP_NAME}-${ARC_ENV}`) | ||
let Path = `/${appName}/tables` | ||
ssm.getParametersByPath({ Path, Recursive: true }, function done (err, result) { | ||
@@ -52,5 +52,16 @@ if (err) callback(err) | ||
} | ||
else { | ||
throw ReferenceError('begin/data could not find the data table') | ||
} | ||
function toLogicalID (str) { | ||
str = str.replace(/([A-Z])/g, ' $1') | ||
if (str.length === 1) { | ||
return str.toUpperCase() | ||
} | ||
str = str.replace(/^[\W_]+|[\W_]+$/g, '').toLowerCase() | ||
str = str.charAt(0).toUpperCase() + str.slice(1) | ||
str = str.replace(/[\W_]+(\w|$)/g, (_, ch) => ch.toUpperCase()) | ||
if (str === 'Get') { | ||
return 'GetIndex' | ||
} | ||
return str | ||
} |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 11 instances in 1 package
3
35432
26
923
1