remove isStringValue
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { useCallback, useMemo } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
import { isPlainObject, isStringValue } from '../../utils/typeGuards';
|
import { isPlainObject } from '../../utils/typeGuards';
|
||||||
|
|
||||||
type ApiClient = {
|
type ApiClient = {
|
||||||
post: (path: string, body?: unknown) => Promise<{ data: unknown }>;
|
post: (path: string, body?: unknown) => Promise<{ data: unknown }>;
|
||||||
@@ -127,7 +127,7 @@ const useDocumentCorrespondentActions = ({
|
|||||||
if (isPlainObject(option) && 'id' in option) {
|
if (isPlainObject(option) && 'id' in option) {
|
||||||
return option as CorrespondentOption;
|
return option as CorrespondentOption;
|
||||||
}
|
}
|
||||||
if (isStringValue(option)) {
|
if (typeof option === 'string') {
|
||||||
const trimmed = option.trim();
|
const trimmed = option.trim();
|
||||||
if (trimmed) {
|
if (trimmed) {
|
||||||
return { id: null, name: trimmed };
|
return { id: null, name: trimmed };
|
||||||
|
|||||||
@@ -3,5 +3,4 @@ const objectToString = Object.prototype.toString;
|
|||||||
export const isPlainObject = (value: unknown): value is Record<string, unknown> =>
|
export const isPlainObject = (value: unknown): value is Record<string, unknown> =>
|
||||||
value !== null && !Array.isArray(value) && Object(value) === value;
|
value !== null && !Array.isArray(value) && Object(value) === value;
|
||||||
|
|
||||||
export const isStringValue = (value: unknown): value is string =>
|
|
||||||
objectToString.call(value) === '[object String]';
|
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ type AuthenticationCredential = PublicKeyCredential & {
|
|||||||
response: AuthenticatorAssertionResponse;
|
response: AuthenticatorAssertionResponse;
|
||||||
};
|
};
|
||||||
|
|
||||||
import { isStringValue } from './typeGuards';
|
|
||||||
|
|
||||||
const base64urlToBase64 = (value: string = ''): string => {
|
const base64urlToBase64 = (value: string = ''): string => {
|
||||||
const normalized = value.replace(/-/g, '+').replace(/_/g, '/');
|
const normalized = value.replace(/-/g, '+').replace(/_/g, '/');
|
||||||
const padding = normalized.length % 4;
|
const padding = normalized.length % 4;
|
||||||
@@ -103,14 +101,14 @@ export const preparePublicKeyCreationOptions = (
|
|||||||
|
|
||||||
const publicKey: PublicKeyCredentialCreationOptions = { ...challengeResponse.publicKey };
|
const publicKey: PublicKeyCredentialCreationOptions = { ...challengeResponse.publicKey };
|
||||||
|
|
||||||
if (publicKey.challenge && isStringValue(publicKey.challenge)) {
|
if (publicKey.challenge && typeof publicKey.challenge === 'string') {
|
||||||
publicKey.challenge = base64urlToBufferSource(publicKey.challenge);
|
publicKey.challenge = base64urlToBufferSource(publicKey.challenge);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (publicKey.user?.id) {
|
if (publicKey.user?.id) {
|
||||||
publicKey.user = {
|
publicKey.user = {
|
||||||
...publicKey.user,
|
...publicKey.user,
|
||||||
id: isStringValue(publicKey.user.id)
|
id: typeof publicKey.user.id === 'string'
|
||||||
? base64urlToBufferSource(publicKey.user.id)
|
? base64urlToBufferSource(publicKey.user.id)
|
||||||
: publicKey.user.id,
|
: publicKey.user.id,
|
||||||
};
|
};
|
||||||
@@ -119,7 +117,7 @@ export const preparePublicKeyCreationOptions = (
|
|||||||
if (Array.isArray(publicKey.excludeCredentials)) {
|
if (Array.isArray(publicKey.excludeCredentials)) {
|
||||||
publicKey.excludeCredentials = publicKey.excludeCredentials.map((descriptor) => ({
|
publicKey.excludeCredentials = publicKey.excludeCredentials.map((descriptor) => ({
|
||||||
...descriptor,
|
...descriptor,
|
||||||
id: isStringValue(descriptor.id)
|
id: typeof descriptor.id === 'string'
|
||||||
? base64urlToBufferSource(descriptor.id)
|
? base64urlToBufferSource(descriptor.id)
|
||||||
: descriptor.id,
|
: descriptor.id,
|
||||||
}));
|
}));
|
||||||
@@ -141,14 +139,14 @@ export const preparePublicKeyRequestOptions = (
|
|||||||
|
|
||||||
const publicKey: PublicKeyCredentialRequestOptions = { ...challengeResponse.publicKey };
|
const publicKey: PublicKeyCredentialRequestOptions = { ...challengeResponse.publicKey };
|
||||||
|
|
||||||
if (publicKey.challenge && isStringValue(publicKey.challenge)) {
|
if (publicKey.challenge && typeof publicKey.challenge === 'string') {
|
||||||
publicKey.challenge = base64urlToBufferSource(publicKey.challenge);
|
publicKey.challenge = base64urlToBufferSource(publicKey.challenge);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(publicKey.allowCredentials)) {
|
if (Array.isArray(publicKey.allowCredentials)) {
|
||||||
publicKey.allowCredentials = publicKey.allowCredentials.map((descriptor) => ({
|
publicKey.allowCredentials = publicKey.allowCredentials.map((descriptor) => ({
|
||||||
...descriptor,
|
...descriptor,
|
||||||
id: isStringValue(descriptor.id)
|
id: typeof descriptor.id === 'string'
|
||||||
? base64urlToBufferSource(descriptor.id)
|
? base64urlToBufferSource(descriptor.id)
|
||||||
: descriptor.id,
|
: descriptor.id,
|
||||||
}));
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user