@oneblink/apps
Advanced tools
Comparing version 0.1.0-beta.9 to 0.1.0-beta.10
@@ -24,3 +24,4 @@ // Type definitions for @oneblink/apps 0.1 | ||
function getUserFriendlyName(): string | null | ||
function getIssuerFromJWT(jwt: string | NoU): string | void | ||
function getFormsKeyId(): string | void | ||
function setFormsKeyToken(formsKeyToken: string): void | ||
function isAuthorised(formsAppId: number): Promise<boolean> | ||
@@ -62,9 +63,7 @@ function requestAccess(formsAppId: number): Promise<void> | ||
newDraft: FormTypes.NewFormsAppDraft, | ||
draftSubmission: FormTypes.DraftSubmission, | ||
accessKey: NoU | string | ||
draftSubmission: FormTypes.DraftSubmission | ||
): Promise<void> | ||
function updateDraft( | ||
draft: FormTypes.FormsAppDraft, | ||
draftSubmission: FormTypes.DraftSubmission, | ||
accessKey: NoU | string | ||
draftSubmission: FormTypes.DraftSubmission | ||
): Promise<void> | ||
@@ -128,3 +127,2 @@ function getDrafts(): Promise<FormTypes.FormsAppDraft[]> | ||
formSubmission: FormTypes.FormSubmission | ||
accessKey?: string | ||
paymentReceiptUrl?: string | ||
@@ -131,0 +129,0 @@ submissionId?: string |
{ | ||
"name": "@oneblink/apps", | ||
"description": "Helper functions for OneBlink apps in JavaScript.", | ||
"version": "0.1.0-beta.9", | ||
"version": "0.1.0-beta.10", | ||
"author": "OneBlink <developers@oneblink.io> (https://oneblink.io)", | ||
@@ -6,0 +6,0 @@ "bugs": { |
// @flow | ||
'use strict' | ||
import jwtDecode from 'jwt-decode' | ||
import OneBlinkAppsError from './services/errors/oneBlinkAppsError' | ||
import { | ||
getIdToken, | ||
getFormsKeyId, | ||
setFormsKeyToken, | ||
} from './services/forms-key' | ||
import { | ||
init as initCognito, | ||
@@ -12,3 +15,2 @@ isLoggedIn, | ||
handleAuthentication, | ||
getIdToken, | ||
logout, | ||
@@ -27,2 +29,4 @@ getUserProfile, | ||
logout, | ||
getFormsKeyId, | ||
setFormsKeyToken, | ||
} | ||
@@ -67,19 +71,9 @@ | ||
export function getIssuerFromJWT( | ||
jwtToken /* : ?string */ | ||
) /* : string | void */ { | ||
if (jwtToken) { | ||
console.log('Attempting to decode JWT') | ||
try { | ||
const tokenPayload = jwtDecode(jwtToken) | ||
return tokenPayload.iss | ||
} catch (error) { | ||
console.warn('Could not decode JWT', error) | ||
} | ||
} | ||
} | ||
export async function isAuthorised( | ||
formsAppId /* : number */ | ||
) /* : Promise<boolean> */ { | ||
if (getFormsKeyId()) { | ||
return true | ||
} | ||
const userProfile = getUserProfile() | ||
@@ -86,0 +80,0 @@ |
@@ -11,3 +11,3 @@ // @flow | ||
import { getUsername, isLoggedIn } from './services/cognito' | ||
import { getIssuerFromJWT } from './auth-service' | ||
import { getFormsKeyId } from './auth-service' | ||
import { uploadDraftData, putDrafts } from './services/api/drafts' | ||
@@ -82,4 +82,3 @@ import { getPendingQueueSubmissions } from './services/pending-queue' | ||
newDraft /* : NewFormsAppDraft */, | ||
draftSubmission /* : DraftSubmission */, | ||
accessKey /* : ?string */ | ||
draftSubmission /* : DraftSubmission */ | ||
) /* : Promise<void> */ { | ||
@@ -91,3 +90,3 @@ const draft /* : FormsAppDraft */ = { | ||
} | ||
draftSubmission.keyId = getIssuerFromJWT(accessKey) | ||
draftSubmission.keyId = getFormsKeyId() | ||
if (draftSubmission.keyId) { | ||
@@ -131,6 +130,5 @@ await upsertDraftByKey(draft, draftSubmission) | ||
draft /* : FormsAppDraft */, | ||
draftSubmission /* : DraftSubmission */, | ||
accessKey /* : ?string */ | ||
draftSubmission /* : DraftSubmission */ | ||
) /* : Promise<void> */ { | ||
draftSubmission.keyId = getIssuerFromJWT(accessKey) | ||
draftSubmission.keyId = getFormsKeyId() | ||
if (draftSubmission.keyId) { | ||
@@ -137,0 +135,0 @@ await upsertDraftByKey(draft, draftSubmission) |
@@ -147,3 +147,3 @@ // @flow | ||
export async function getIdToken() /* : Promise<string | void> */ { | ||
export async function getCognitoIdToken() /* : Promise<string | void> */ { | ||
if (!isLoggedIn()) { | ||
@@ -150,0 +150,0 @@ return |
@@ -5,12 +5,4 @@ // @flow | ||
import { getIdToken } from './cognito' | ||
import { getIdToken } from './forms-key' | ||
let faasToken = null | ||
export function init({ faasKey } /* : { | ||
faasKey: ?string | ||
} */) { | ||
faasToken = faasKey | ||
} | ||
async function generateHeaders() { | ||
@@ -22,10 +14,2 @@ const headers = { | ||
// Check for a token for FaaS | ||
if (faasToken) { | ||
return { | ||
...headers, | ||
Authorization: `Bearer ${faasToken}`, | ||
} | ||
} | ||
// Check auth service for a token if user is logged in | ||
@@ -32,0 +16,0 @@ const idToken = await getIdToken() |
@@ -5,3 +5,3 @@ // @flow | ||
import { isOffline } from './offline-service' | ||
import { getIssuerFromJWT, isLoggedIn } from './auth-service' | ||
import { getFormsKeyId, isLoggedIn } from './auth-service' | ||
import { | ||
@@ -109,3 +109,2 @@ registerPendingQueueListener, | ||
formSubmission, | ||
accessKey, | ||
paymentReceiptUrl, | ||
@@ -115,3 +114,2 @@ submissionId, | ||
formSubmission: FormSubmission, | ||
accessKey?: string, | ||
paymentReceiptUrl?: string, | ||
@@ -121,3 +119,3 @@ submissionId?: string, | ||
) /* : Promise<FormSubmissionResult> */ { | ||
formSubmission.keyId = getIssuerFromJWT(accessKey) | ||
formSubmission.keyId = getFormsKeyId() | ||
const submissionEvents = formSubmission.definition.submissionEvents || [] | ||
@@ -124,0 +122,0 @@ const paymentSubmissionEvent = submissionEvents.reduce( |
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
167057
36
4275