Skip to content

Commit

Permalink
[AUT-1778] Replace ky with fetch (#51)
Browse files Browse the repository at this point in the history
* Replace ky with fetch

* Bump version
  • Loading branch information
hwhmeikle committed Feb 15, 2024
1 parent d502603 commit dec4c6c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 34 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@authsignal/browser",
"version": "0.3.6",
"version": "0.3.7",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
Expand Down Expand Up @@ -28,9 +28,9 @@
},
"dependencies": {
"@fingerprintjs/fingerprintjs": "^3.3.6",
"@simplewebauthn/browser": "^8.2.1",
"@simplewebauthn/browser": "^9.0.1",
"@simplewebauthn/types": "^9.0.1",
"a11y-dialog": "^7.5.2",
"ky": "^0.33.3",
"uuid": "^9.0.0"
},
"devDependencies": {
Expand Down
38 changes: 19 additions & 19 deletions src/api/passkey-api-client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import ky from "ky";
import {KyInstance} from "ky/distribution/types/ky";
import {
AddAuthenticatorRequest,
AddAuthenticatorResponse,
Expand All @@ -18,56 +16,58 @@ type PasskeyApiClientOptions = {

export class PasskeyApiClient {
tenantId: string;
api: KyInstance;
baseUrl: string;

constructor({baseUrl, tenantId}: PasskeyApiClientOptions) {
this.tenantId = tenantId;

this.api = ky.create({
prefixUrl: baseUrl,
});
this.baseUrl = baseUrl;
}

async registrationOptions({token, userName}: RegistrationOptsRequest): Promise<RegistrationOptsResponse> {
const response = await this.api.post("client/user-authenticators/passkey/registration-options", {
json: {username: userName},
const request = fetch(`${this.baseUrl}/client/user-authenticators/passkey/registration-options`, {
method: "POST",
headers: this.buildHeaders(token),
body: JSON.stringify({username: userName}),
});

return response.json();
return (await request).json();
}

async authenticationOptions({token}: AuthenticationOptsRequest): Promise<AuthenticationOptsResponse> {
const response = await this.api.post("client/user-authenticators/passkey/authentication-options", {
json: {},
const request = fetch(`${this.baseUrl}/client/user-authenticators/passkey/authentication-options`, {
method: "POST",
headers: this.buildHeaders(token),
body: JSON.stringify({}),
});

return response.json();
return (await request).json();
}

async addAuthenticator({token, ...rest}: AddAuthenticatorRequest): Promise<AddAuthenticatorResponse> {
const response = await this.api.post("client/user-authenticators/passkey", {
json: rest,
const request = fetch(`${this.baseUrl}/client/user-authenticators/passkey`, {
method: "POST",
headers: this.buildHeaders(token),
body: JSON.stringify(rest),
});

return response.json();
return (await request).json();
}

async verify({token, ...rest}: VerifyRequest): Promise<VerifyResponse> {
const response = await this.api.post("client/verify/passkey", {
json: rest,
const request = fetch(`${this.baseUrl}/client/verify/passkey`, {
method: "POST",
headers: this.buildHeaders(token),
body: JSON.stringify(rest),
});

return response.json();
return (await request).json();
}

private buildHeaders(token?: string) {
const authorizationHeader = token ? `Bearer ${token}` : `Basic ${window.btoa(encodeURIComponent(this.tenantId))}`;

return {
"Content-Type": "application/json",
Authorization: authorizationHeader,
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
AuthenticationResponseJSON,
PublicKeyCredentialCreationOptionsJSON,
RegistrationResponseJSON,
} from "@simplewebauthn/typescript-types";
} from "@simplewebauthn/types";

export type RegistrationOptsRequest = {
userName?: string;
Expand Down
4 changes: 3 additions & 1 deletion src/authsignal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ export class Authsignal {
}
}

initAdvancedProfiling(baseUrl?: string): undefined {
initAdvancedProfiling(baseUrl?: string) {
const profilingId = uuidv4();

this.profilingId = profilingId;

setCookie({
name: DEFAULT_PROFILING_COOKIE_NAME,
value: profilingId,
Expand Down
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,17 @@
estree-walker "^1.0.1"
picomatch "^2.2.2"

"@simplewebauthn/browser@^8.2.1":
version "8.2.1"
resolved "https://registry.npmjs.org/@simplewebauthn/browser/-/browser-8.2.1.tgz#feb9f9553dd10e5e4349d58753e5c3bf8bf52957"
integrity sha512-s8A2ADEpULrPcKBbewzWECgyUe4sOu06OwBN4UzSO5PmBj4TG9nXaz+Ihy7ZT8eK6lF+lPy/tKebfjc/7dY2HA==
"@simplewebauthn/browser@^9.0.1":
version "9.0.1"
resolved "https://registry.npmjs.org/@simplewebauthn/browser/-/browser-9.0.1.tgz#46a12c2bcefcb199f7fcb6a7e883531cd6efde17"
integrity sha512-wD2WpbkaEP4170s13/HUxPcAV5y4ZXaKo1TfNklS5zDefPinIgXOpgz1kpEvobAsaLPa2KeH7AKKX/od1mrBJw==
dependencies:
"@simplewebauthn/typescript-types" "^8.0.0"
"@simplewebauthn/types" "^9.0.1"

"@simplewebauthn/types@^9.0.1":
version "9.0.1"
resolved "https://registry.npmjs.org/@simplewebauthn/types/-/types-9.0.1.tgz#3a68d50e63d8821cf2067de3324c68d5e8120d0c"
integrity sha512-tGSRP1QvsAvsJmnOlRQyw/mvK9gnPtjEc5fg2+m8n+QUa+D7rvrKkOYyfpy42GTs90X3RDOnqJgfHt+qO67/+w==

"@simplewebauthn/typescript-types@^8.0.0":
version "8.0.0"
Expand Down Expand Up @@ -822,11 +827,6 @@ json-stable-stringify-without-jsonify@^1.0.1:
resolved "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"
integrity sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==

ky@^0.33.3:
version "0.33.3"
resolved "https://registry.npmjs.org/ky/-/ky-0.33.3.tgz#bf1ad322a3f2c3428c13cfa4b3af95e6c4a2f543"
integrity sha512-CasD9OCEQSFIam2U8efFK81Yeg8vNMTBUqtMOHlrcWQHqUX3HeCl9Dr31u4toV7emlH8Mymk5+9p0lL6mKb/Xw==

levn@^0.4.1:
version "0.4.1"
resolved "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz#ae4562c007473b932a6200d403268dd2fffc6ade"
Expand Down

0 comments on commit dec4c6c

Please sign in to comment.