From ac812db4fc125832ca3cc59a58cb917981d6f1ec Mon Sep 17 00:00:00 2001 From: Achraf B <98611284+ab116699@users.noreply.github.com> Date: Mon, 9 Sep 2024 09:27:18 -0400 Subject: [PATCH] feat: Introduce tokenize client side API (#123) --- lib/edge/tokenize.ts | 27 +++++++++++++++++++++++++++ lib/sdk.ts | 6 ++++++ 2 files changed, 33 insertions(+) create mode 100644 lib/edge/tokenize.ts diff --git a/lib/edge/tokenize.ts b/lib/edge/tokenize.ts new file mode 100644 index 0000000..53c20d5 --- /dev/null +++ b/lib/edge/tokenize.ts @@ -0,0 +1,27 @@ +import type { OptableConfig } from "../config"; +import { fetch } from "../core/network"; +import { User } from "./rtb2"; + +type TokenizeResponse = { + User: User; +}; + +type TokenizeRequest = { + id: string; +}; + +function Tokenize(config: Required, id: string): Promise { + let request: TokenizeRequest = { + id: id, + }; + return fetch("/v1/tokenize", config, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(request), + }); +} + +export { Tokenize, TokenizeRequest, TokenizeResponse }; +export default Tokenize; diff --git a/lib/sdk.ts b/lib/sdk.ts index 60c20a8..d7da74b 100644 --- a/lib/sdk.ts +++ b/lib/sdk.ts @@ -18,6 +18,7 @@ import { import { Witness } from "./edge/witness"; import { Profile } from "./edge/profile"; import { sha256 } from "js-sha256"; +import { Tokenize, TokenizeResponse } from "./edge/tokenize"; class OptableSDK { public static version = buildInfo.version; @@ -98,6 +99,11 @@ class OptableSDK { return Profile(this.dcn, traits); } + async tokenize(id: string): Promise { + await this.init; + return Tokenize(this.dcn, id); + } + static eid(email: string): string { return email ? "e:" + sha256.hex(email.toLowerCase().trim()) : ""; }