@oneblink/sdk
Advanced tools
Comparing version 0.2.4 to 0.2.5
@@ -5,2 +5,8 @@ # Changelog | ||
## 0.2.5 (2018-01-14) | ||
### Changed | ||
- Changed `generateFormUrl()` function to get hostname via `appId` | ||
## 0.2.4 (2018-10-24) | ||
@@ -7,0 +13,0 @@ |
@@ -37,13 +37,12 @@ // @flow | ||
) /* : Promise<{ expiry: string, formUrl: string }> */ { | ||
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.') | ||
} | ||
const hostname = await this.getHostname(formId) | ||
let preFillFormDataId | ||
@@ -60,3 +59,3 @@ if (preFillData) { | ||
const formUrl = generateFormUrl(`https://${organisationsResults.organisations[0].formsHostname}/forms`, formId, token, externalId, preFillFormDataId) | ||
const formUrl = generateFormUrl(`https://${hostname}/forms`, formId, token, externalId, preFillFormDataId) | ||
@@ -71,2 +70,28 @@ const expiry = new Date(Date.now() + (jwtExpiry * 1000)).toISOString() | ||
async getHostname ( | ||
formId /* : number */ | ||
) { | ||
try { | ||
const formResults = await super.getRequest(`/forms/${formId}`) | ||
if (!formResults || !formResults.formsAppIds.length) { | ||
throw new Error('Access Denied. The "accessKey" and "secretKey" provided may have been revoked.') | ||
} | ||
const appResults = await super.getRequest(`/forms-apps/${formResults.formsAppIds[0]}`) | ||
if (!appResults || !appResults.hostname) { | ||
throw new Error('Access Denied. The "accessKey" and "secretKey" provided may have been revoked.') | ||
} | ||
return appResults.hostname | ||
} catch (e) { | ||
const organisationsResults = await super.searchRequest(`/organisations`) | ||
if (!organisationsResults.organisations || !organisationsResults.organisations.length) { | ||
throw new Error('Access Denied. The "accessKey" and "secretKey" provided may have been revoked.') | ||
} | ||
return organisationsResults.organisations[0].formsHostname | ||
} | ||
} | ||
async generateSubmissionDataUrl ( | ||
@@ -73,0 +98,0 @@ formId /* : ?mixed */, |
{ | ||
"name": "@oneblink/sdk", | ||
"description": "OneBlink SDK to serve as an entry point for all OneBlink Services in NodeJS", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"bugs": { | ||
@@ -6,0 +6,0 @@ "url": "https://github.com/blinkmobile/oneblink-sdk-js/issues" |
18351
513