diff --git a/package.json b/package.json index cb77014..513201f 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": { diff --git a/src/api/passkey-api-client.ts b/src/api/passkey-api-client.ts index 7b890a9..7d23068 100644 --- a/src/api/passkey-api-client.ts +++ b/src/api/passkey-api-client.ts @@ -1,5 +1,3 @@ -import ky from "ky"; -import {KyInstance} from "ky/distribution/types/ky"; import { AddAuthenticatorRequest, AddAuthenticatorResponse, @@ -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 { - 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 { - 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 { - 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 { - 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, }; } diff --git a/src/api/types.ts b/src/api/types.ts index a6ee2c4..d4f0b0e 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -2,7 +2,7 @@ import { AuthenticationResponseJSON, PublicKeyCredentialCreationOptionsJSON, RegistrationResponseJSON, -} from "@simplewebauthn/typescript-types"; +} from "@simplewebauthn/types"; export type RegistrationOptsRequest = { userName?: string; diff --git a/src/authsignal.ts b/src/authsignal.ts index 6abe227..6746026 100644 --- a/src/authsignal.ts +++ b/src/authsignal.ts @@ -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, diff --git a/yarn.lock b/yarn.lock index a728084..0228124 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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"