Skip to content

Commit

Permalink
Merge pull request #18 from oneblink/ON-39766
Browse files Browse the repository at this point in the history
ON-39766 # Fixed prefill response type and  authorisation header for requests
  • Loading branch information
Zaxist authored Apr 22, 2024
2 parents f7bc665 + b58c422 commit 312455b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/OneBlinkUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,9 @@ export default class OneBlinkUploader {
/** The prefill data to upload */
prefillData: SubmissionTypes.NewS3SubmissionData['submission']
}) {
return await uploadToS3({
return await uploadToS3<{
preFillFormDataId: string
}>({
...this,
contentType: 'application/json',
body: JSON.stringify(prefillData),
Expand Down
1 change: 1 addition & 0 deletions src/http-handlers/NodeJsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class OneBlinkNodeJsHandler<T>
}

switch (result.response.headers['content-type']) {
case 'application/json; charset=utf-8':
case 'application/json': {
const { Readable } = await import('stream')
if (result.response.body instanceof Readable) {
Expand Down
10 changes: 7 additions & 3 deletions src/http-handlers/handleRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,32 @@ export async function prepareRequest<T>(
oneBlinkRequestHandler: IOneBlinkRequestHandler<T>,
request: HttpRequest,
) {
delete request.headers['authorization']

const token = await oneBlinkRequestHandler.getIdToken()
if (token) {
request.headers['x-oneblink-authorization'] = 'Bearer ' + token
request.headers['authorization'] = 'Bearer ' + token
}

if (oneBlinkRequestHandler.requestBodyHeader) {
request.headers['x-oneblink-request-body'] = JSON.stringify(
oneBlinkRequestHandler.requestBodyHeader,
)
}

if (oneBlinkRequestHandler.oneblinkResponse) {
request.query['key'] = oneBlinkRequestHandler.oneblinkResponse.s3.key
}

console.log('S3 upload request', request)
console.log('S3 upload request path', request.path)
}

export async function handleResponse<T>(
oneBlinkRequestHandler: IOneBlinkRequestHandler<T>,
request: HttpRequest,
response: HttpResponse,
) {
console.log('S3 upload result for request path', request.path, response)
console.log('S3 upload result for request path', request.path)

const oneblinkResponse = response.headers['x-oneblink-response']
if (typeof oneblinkResponse === 'string') {
Expand Down
2 changes: 1 addition & 1 deletion src/uploadToS3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async function uploadToS3<T>({
// new S3 bucket domain concept with includes the bucket in the
// domain instead of the path. We need it in the path to use the
// API as the domain.
Bucket: 'storage.oneblink.io',
Bucket: apiOrigin.split('.').slice(-2).join('.'),
Key: key,
Body: body,
ContentType: contentType,
Expand Down

0 comments on commit 312455b

Please sign in to comment.