@oneblink/sdk
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -5,2 +5,12 @@ # Changelog | ||
## 0.2.1 (2018-09-04) | ||
### Added | ||
- Pre filled data argument to `forms.generateFormUrl()` function | ||
### Fixed | ||
- Path of forms renderer URL to match `/forms/{formId}` | ||
## 0.2.0 (2018-08-07) | ||
@@ -7,0 +17,0 @@ |
@@ -17,2 +17,3 @@ // @flow | ||
const OneBlinkAPI = require('./one-blink-api.js') | ||
const setPreFillData = require('./pre-fill-data') | ||
@@ -31,32 +32,37 @@ module.exports = class Forms extends OneBlinkAPI { | ||
generateFormUrl ( | ||
async generateFormUrl ( | ||
formId /* : ?mixed */, | ||
externalId /* : ?mixed */ | ||
externalId /* : ?mixed */, | ||
preFillData /* : ?mixed */ | ||
) /* : Promise<{ expiry: string, formUrl: string }> */ { | ||
return super.searchRequest(`/organisations`) | ||
.then((results) => { | ||
if (typeof formId !== 'number') { | ||
throw new TypeError('Must supply "formId" as a number') | ||
} | ||
if (externalId && typeof externalId !== 'string') { | ||
throw new TypeError('Must supply "externalId" as a string or not at all') | ||
} | ||
if (!results.organisations || !results.organisations.length) { | ||
throw new Error('Access Denied. The "accessKey" and "secretKey" provided may have been revoked.') | ||
} | ||
const organisationsResults = await super.searchRequest(`/organisations`) | ||
if (typeof formId !== 'number') { | ||
throw new TypeError('Must supply "formId" as a number') | ||
} | ||
if (externalId && typeof externalId !== 'string') { | ||
throw new TypeError('Must supply "externalId" as a string or not at all') | ||
} | ||
if (!organisationsResults.organisations || !organisationsResults.organisations.length) { | ||
throw new Error('Access Denied. The "accessKey" and "secretKey" provided may have been revoked.') | ||
} | ||
// Default expiry for token is 8 hours | ||
const jwtExpiry = 28800 | ||
let preFillFormDataId | ||
if (preFillData) { | ||
const preFillMeta = await super.getRequest(`/forms/${formId}/pre-fill-credentials`) | ||
await setPreFillData(preFillMeta, preFillData) | ||
preFillFormDataId = preFillMeta.preFillFormDataId | ||
} | ||
// Default expiry for token is 8 hours | ||
const jwtExpiry = 28800 | ||
const token = generateJWT(this.accessKey, this.secretKey, jwtExpiry) | ||
const token = generateJWT(this.accessKey, this.secretKey, jwtExpiry) | ||
const formUrl = generateFormUrl(`https://${results.organisations[0].formsHostname}`, formId, token, externalId) | ||
const formUrl = generateFormUrl(`https://${organisationsResults.organisations[0].formsHostname}/forms`, formId, token, externalId, preFillFormDataId) | ||
const expiry = new Date(Date.now() + (jwtExpiry * 1000)).toISOString() | ||
const expiry = new Date(Date.now() + (jwtExpiry * 1000)).toISOString() | ||
return { | ||
formUrl, | ||
expiry | ||
} | ||
}) | ||
return { | ||
formUrl, | ||
expiry | ||
} | ||
} | ||
@@ -63,0 +69,0 @@ |
@@ -10,3 +10,4 @@ // @flow | ||
token /* : string */, | ||
externalId /* : mixed */ | ||
externalId /* : mixed */, | ||
preFillFormDataId /* : ?string */ | ||
) { | ||
@@ -22,2 +23,5 @@ if (!formId) { | ||
} | ||
if (preFillFormDataId) { | ||
searchParams = Object.assign({}, searchParams, { preFillFormDataId }) | ||
} | ||
const search = querystring.stringify(searchParams) | ||
@@ -24,0 +28,0 @@ return `${endpoint}/${formId}?${search}` |
{ | ||
"name": "@oneblink/sdk", | ||
"description": "OneBlink SDK to serve as an entry point for all OneBlink Services in NodeJS", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"bugs": { | ||
@@ -6,0 +6,0 @@ "url": "https://github.com/blinkmobile/oneblink-sdk-js/issues" |
@@ -26,2 +26,11 @@ // @flow | ||
export type PreFillMeta = { | ||
credentials: AWSCredentials, | ||
s3: { | ||
bucket: string, | ||
key: string, | ||
region: string | ||
} | ||
} | ||
export type BaseSearchResult = { | ||
@@ -28,0 +37,0 @@ meta: { |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
13759
12
361
0