Skip to content

Commit

Permalink
chore(sdk-client-v3): remove crypto module from SDK
Browse files Browse the repository at this point in the history
- remove crypto module reference from SDK
- fix type errors and return type values
  • Loading branch information
ajimae committed Oct 4, 2024
1 parent 55298aa commit 91598d5
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function createAuthMiddlewareForAnonymousSessionFlow(
})

let tokenCacheObject: TokenStore
let tokenFetchPromise: Promise<TokenCache> | null = null
let tokenFetchPromise: Promise<boolean> | null = null
const tokenCacheKey = buildTokenCacheKey(options)

return (next: Next) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export async function executeRequest(options: executeRequestOptions) {

// cache new generated token, refreshToken and expiration time
tokenCache.set({ token, expirationTime, refreshToken })
return Promise.resolve(tokenCache)
return Promise.resolve(true)
}

// bubble up the error for the catch block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function createAuthMiddlewareForClientCredentialsFlow(
})

let tokenCacheObject: TokenStore
let tokenFetchPromise: Promise<TokenCache> | null = null
let tokenFetchPromise: Promise<boolean> | null = null
const tokenCacheKey = buildTokenCacheKey(options)

return (next: Next) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function createAuthMiddlewareForPasswordFlow(
})

let tokenCacheObject: TokenStore
let tokenFetchPromise: Promise<TokenCache> | null = null
let tokenFetchPromise: Promise<boolean> | null = null
const tokenCacheKey = buildTokenCacheKey(options)

return (next: Next) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function createAuthMiddlewareForRefreshTokenFlow(
})

let tokenCacheObject: TokenStore
let tokenFetchPromise: Promise<TokenCache> | null = null
let tokenFetchPromise: Promise<boolean> | null = null
const tokenCacheKey = buildTokenCacheKey(options)

return (next: Next) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function createConcurrentModificationMiddleware(

// update the resource version here
if (version) {
if (modifierFunction) {
if (modifierFunction && typeof modifierFunction == 'function') {
request.body = await modifierFunction(version, request, response)
} else {
request.body =
Expand Down
14 changes: 5 additions & 9 deletions packages/sdk-client-v3/src/utils/generateID.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
export default function generateID() {
// @ts-ignore
const str = ([1e6] + -1e3 + -4e3 + -8e3 + -1e11).replace(
/[018]/g,
(c: number) =>
(
c ^
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
).toString(16)
return ([1e6] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c: string) =>
(
parseInt(c) ^
(Math.floor(Math.random() * 256) & (15 >> (parseInt(c) / 4)))
).toString(16)
)

return 'abcdef'[Math.floor(Math.random() * 'abcdef'.length)] + '' + str
}

0 comments on commit 91598d5

Please sign in to comment.