@aws-lite/client
Advanced tools
Comparing version 0.19.0 to 0.20.0-RC.0
{ | ||
"name": "@aws-lite/client", | ||
"version": "0.19.0", | ||
"version": "0.20.0-RC.0", | ||
"description": "A simple, fast, extensible AWS client", | ||
@@ -23,5 +23,5 @@ "homepage": "https://github.com/architect/aws-lite", | ||
"test:live": "cross-env tape 'test/live/**/*-test.js' | tap-arc", | ||
"test:plugins": "cross-env tape 'plugins/**/test/**/*-test.*js' | tap-arc", | ||
"test:plugins": "cross-env tape 'plugins/**/test/**/*-test.mjs' | tap-arc", | ||
"test:precommit": "cross-env PRECOMMIT=true npm run gen && npm run lint", | ||
"test:unit": "cross-env tape 'test/unit/**/*-test.js' | tap-arc", | ||
"test:unit": "cross-env tape 'test/unit/**/*-test.mjs' | tap-arc", | ||
"test": "npm run lint && npm run gen && npm run test:plugins && npm run coverage" | ||
@@ -81,2 +81,5 @@ }, | ||
"global-require": "off" | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 13 | ||
} | ||
@@ -83,0 +86,0 @@ }, |
@@ -162,3 +162,3 @@ let request = require('./request') | ||
// If a payload property isn't included, it _is_ the payload | ||
let unmarshalled = awsjson.unmarshall(pluginRes.payload || pluginRes, unmarshalling) | ||
let unmarshalled = awsjson.unmarshall(pluginRes.payload || pluginRes, unmarshalling, config) | ||
response = pluginRes.payload | ||
@@ -165,0 +165,0 @@ ? { ...pluginRes, payload: unmarshalled } |
@@ -39,3 +39,3 @@ // Service API plugin getter | ||
let { exists } = require('../lib') | ||
let { join } = require('path') | ||
let { join } = require('node:path') | ||
@@ -69,3 +69,3 @@ let dedupe = arr => [ ...new Set(arr) ] | ||
else if (await exists(packageJsonFile)) { | ||
let { readFile } = require('fs/promises') | ||
let { readFile } = require('node:fs/promises') | ||
let packageJson = JSON.parse(await readFile(packageJsonFile)) | ||
@@ -121,4 +121,4 @@ let { dependencies: deps } = packageJson | ||
let found = [] | ||
let { join } = require('path') | ||
let { readdir } = require('fs/promises') | ||
let { join } = require('node:path') | ||
let { readdir } = require('node:fs/promises') | ||
let mods = await readdir(dir) | ||
@@ -125,0 +125,0 @@ // Find first-party plugins |
@@ -7,3 +7,2 @@ interface AwsLiteConfig { | ||
profile?: string; | ||
verifyService?: boolean; | ||
autoloadPlugins?: boolean; | ||
@@ -23,2 +22,3 @@ awsConfigFile?: boolean | string; | ||
retries?: number; | ||
verifyService?: boolean; | ||
} | ||
@@ -25,0 +25,0 @@ |
@@ -15,4 +15,3 @@ let getPlugins = require('./config/get-plugins') | ||
* @param {string} [config.profile='default'] AWS config + credentials profile; if not provided, defaults to `AWS_PROFILE` env var, and then to the `default` profile, if present | ||
* @param {boolean} [config.verifyService=true] Validate service name against aws-lite's known services | ||
* @param {boolean} [config.autoloadPlugins=false] Automatically load installed `@aws-lite/*` + `aws-lite-plugin-*` plugins; not suggested for production use | ||
* @param {boolean} [config.autoloadPlugins=false] Automatically load installed `@aws-lite/*` + `aws-lite-plugin-*` plugins; not suggested for production use | ||
* @param {boolean|string} [config.awsConfigFile=false] Load configuration via ~/.aws/config (boolean), or via a passed file path | ||
@@ -29,3 +28,4 @@ * @param {boolean} [config.debug] Enable debug logging to console | ||
* @param {number} [config.retries=5] Set the maximum number of request retries; set to 0 to disable retrying | ||
* | ||
* @param {boolean} [config.verifyService=true] Validate service name against aws-lite's known services | ||
* | ||
* @returns {Promise<function>} Client async function | ||
@@ -32,0 +32,0 @@ */ |
let aws, ini, xml | ||
// AWS-flavored JSON stuff | ||
function marshaller (method, obj, awsjsonSetting) { | ||
function marshaller (method, obj, awsjsonSetting, config) { | ||
if (!aws) { | ||
@@ -10,6 +10,14 @@ // Only require the vendor if + when it's actually needed | ||
// Allow arbitrary AWS JSON marshalling options | ||
let { awsjsonMarshall, awsjsonUnmarshall } = config | ||
let marshallOptions = method === 'marshall' ? awsjsonMarshall : awsjsonUnmarshall | ||
if (marshallOptions) { | ||
let { is } = require('./validate') | ||
if (!is.object(marshallOptions)) throw ReferenceError('AWS JSON marshall/unmarshall options must be an object') | ||
} | ||
// We may not be able to AWS JSON-[en|de]code the whole payload, check for specified keys | ||
if (Array.isArray(awsjsonSetting)) { | ||
return Object.entries(obj).reduce((acc, [ k, v ]) => { | ||
if (awsjsonSetting.includes(k)) acc[k] = aws[method](v) | ||
if (awsjsonSetting.includes(k)) acc[k] = aws[method](v, marshallOptions) | ||
else acc[k] = v | ||
@@ -20,3 +28,3 @@ return acc | ||
// Otherwise, just AWS JSON-[en|de]code the whole thing | ||
return aws[method](obj) | ||
return aws[method](obj, marshallOptions) | ||
} | ||
@@ -29,3 +37,3 @@ let awsjson = { | ||
async function exists (file) { | ||
let { stat } = require('fs/promises') | ||
let { stat } = require('node:fs/promises') | ||
try { await stat(file); return true } | ||
@@ -92,4 +100,4 @@ catch { return false } | ||
let { join } = require('path') | ||
let os = require('os') | ||
let { join } = require('node:path') | ||
let os = require('node:os') | ||
let home = os.homedir() | ||
@@ -107,3 +115,3 @@ | ||
let { readFile } = require('fs/promises') | ||
let { readFile } = require('node:fs/promises') | ||
if (!ini) ini = require('ini') | ||
@@ -118,3 +126,3 @@ | ||
function tidyQuery (obj) { | ||
let qs = require('querystring') | ||
let qs = require('node:querystring') | ||
let tidied = {} | ||
@@ -208,5 +216,14 @@ Object.entries(obj).forEach(([ k, v ]) => { | ||
} | ||
function buildXML (obj) { | ||
function buildXML (obj, params) { | ||
instantiateXml() | ||
return xml.builder.build(obj) | ||
let payload = xml.builder.build(obj) | ||
// We may need to repeat this (or make a more generic interface) for `xmlns:xsi`, `xsi:type`, etc. | ||
if (params?.xmlns) { | ||
let parent = Object.keys(obj)[0] | ||
payload = payload.replace( | ||
`<${parent}>`, | ||
`<${parent} xmlns="${params.xmlns}">` | ||
) | ||
} | ||
return payload | ||
} | ||
@@ -213,0 +230,0 @@ function parseXML (body) { |
@@ -20,3 +20,3 @@ let { awsjson, buildXML, getEndpointParams, tidyQuery, validateProtocol, AwsJSONContentType, XMLContentType } = require('../lib') | ||
async function makeRequest (params, creds, region, config, metadata) { | ||
let overrides = getEndpointParams(params) | ||
let overrides = getEndpointParams(params) | ||
let protocol = overrides.protocol || config.protocol | ||
@@ -74,3 +74,3 @@ let host = overrides.host || config.host | ||
if (XMLContentType(contentType)) { | ||
params.body = buildXML(body) | ||
params.body = buildXML(body, params) | ||
} | ||
@@ -81,3 +81,3 @@ else { | ||
let awsjsonEncode = params.awsjson || | ||
(AwsJSONContentType(contentType) && params.awsjson !== false) | ||
(AwsJSONContentType(contentType) && params.awsjson !== false) | ||
if (awsjsonEncode) { | ||
@@ -88,3 +88,3 @@ // Backfill content-type header yet again | ||
} | ||
body = awsjson.marshall(body, params.awsjson) | ||
body = awsjson.marshall(body, params.awsjson, config) | ||
} | ||
@@ -132,11 +132,14 @@ // Final JSON encoding | ||
let { debug } = config | ||
let { type, cursor, token, accumulator } = params.paginator | ||
let { type = 'payload', cursor, token, accumulator } = params.paginator | ||
let nestedAccumulator = accumulator.split('.').length > 1 | ||
if (!cursor || typeof cursor !== 'string') { | ||
throw ReferenceError(`aws-lite paginator requires a cursor property name (string)`) | ||
if (!cursor || (!is.string(cursor) && !is.array(cursor))) { | ||
throw ReferenceError(`aws-lite paginator requires a cursor property name (string) or cursor property array`) | ||
} | ||
if (!token || typeof token !== 'string') { | ||
throw ReferenceError(`aws-lite paginator requires a token property name (string)`) | ||
if (!token || (!is.string(token) && !is.array(token))) { | ||
throw ReferenceError(`aws-lite paginator requires a token property name (string) or token property array`) | ||
} | ||
if (typeof cursor !== typeof token) { | ||
throw ReferenceError(`aws-lite paginator requires a token and cursor properties to both be a string or array`) | ||
} | ||
if (!accumulator || typeof accumulator !== 'string') { | ||
@@ -187,21 +190,26 @@ throw ReferenceError(`aws-lite paginator requires an accumulator property name (string)`) | ||
if (is.string(cursor) && is.string(token)) { | ||
cursor = [ cursor ] | ||
token = [ token ] | ||
} | ||
if (cursor.length !== token.length) { | ||
throw ReferenceError(`aws-lite paginator requires an equal number of cursor and token properties`) | ||
} | ||
// Some services will just keep re-sending the final page with the final token | ||
// Exit here to prevent infinite loops if cursors match | ||
if (result.payload[token] && (type === 'payload' || !type) && | ||
result.payload[token] === params.payload[cursor]) { | ||
let checkPageEquality = (t, i) => result.payload[t] && | ||
result.payload[t] === params[type][cursor[i]] | ||
if (token.every(checkPageEquality)) { | ||
return | ||
} | ||
if (result.payload[token] && (type === 'query') && | ||
result.payload[token] === params.query[cursor]) { | ||
return | ||
} | ||
items.push(...accumulated) | ||
if (result.payload[token]) { | ||
if (token.every(t => result.payload[t])) { | ||
if (type === 'payload' || !type) { | ||
params.payload[cursor] = result.payload[token] | ||
token.forEach((t, i) => params.payload[cursor[i]] = result.payload[t]) | ||
} | ||
if (type === 'query') { | ||
params.query = params.query || {} | ||
params.query[cursor] = result.payload[token] | ||
token.forEach((t, i) => params.query[cursor[i]] = result.payload[t]) | ||
} | ||
@@ -208,0 +216,0 @@ page++ |
@@ -92,3 +92,3 @@ let aws4 = require('aws4') | ||
/* istanbul ignore next */ | ||
let http = isHTTPS ? require('https') : require('http') | ||
let http = isHTTPS ? require('node:https') : require('node:http') | ||
@@ -162,3 +162,3 @@ // Port configuration | ||
try { | ||
payload = awsjson.unmarshall(payload) | ||
payload = awsjson.unmarshall(payload, null, config) | ||
} | ||
@@ -165,0 +165,0 @@ catch { /* noop, it's already parsed */ } |
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
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
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
134333
2507
12
1