Skip to content

Commit

Permalink
feat: Introduce tokenize client side API (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
ab116699 authored Sep 9, 2024
1 parent 15f718a commit ac812db
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/edge/tokenize.ts
Original file line number Diff line number Diff line change
@@ -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<OptableConfig>, id: string): Promise<TokenizeResponse> {
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;
6 changes: 6 additions & 0 deletions lib/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -98,6 +99,11 @@ class OptableSDK {
return Profile(this.dcn, traits);
}

async tokenize(id: string): Promise<TokenizeResponse> {
await this.init;
return Tokenize(this.dcn, id);
}

static eid(email: string): string {
return email ? "e:" + sha256.hex(email.toLowerCase().trim()) : "";
}
Expand Down

0 comments on commit ac812db

Please sign in to comment.