|
1 |
| -import { UID2 } from './uid2Sdk'; |
| 1 | +import { UID2SdkBase } from './uid2Sdk'; |
2 | 2 | import { isValidIdentity, Uid2Identity } from './Uid2Identity';
|
3 | 3 | import { UID2CstgBox } from './uid2CstgBox';
|
4 | 4 | import { exportPublicKey } from './uid2CstgCrypto';
|
5 | 5 | import { ClientSideIdentityOptions, stripPublicKeyPrefix } from './uid2ClientSideIdentityOptions';
|
6 |
| -import { base64ToBytes, bytesToBase64 } from './uid2Base64'; |
| 6 | +import { base64ToBytes, bytesToBase64 } from './encoding/uid2Base64'; |
7 | 7 |
|
8 | 8 | export type RefreshResultWithoutIdentity = {
|
9 | 9 | status: ResponseStatusWithoutBody;
|
@@ -100,10 +100,12 @@ export type Uid2ApiClientOptions = {
|
100 | 100 | export class Uid2ApiClient {
|
101 | 101 | private _baseUrl: string;
|
102 | 102 | private _clientVersion: string;
|
| 103 | + private _productName: string; |
103 | 104 | private _requestsInFlight: XMLHttpRequest[] = [];
|
104 |
| - constructor(opts: Uid2ApiClientOptions) { |
105 |
| - this._baseUrl = opts.baseUrl ?? 'https://prod.uidapi.com'; |
106 |
| - this._clientVersion = 'uid2-sdk-' + UID2.VERSION; |
| 105 | + constructor(opts: Uid2ApiClientOptions, defaultBaseUrl: string, productName: string) { |
| 106 | + this._baseUrl = opts.baseUrl ?? defaultBaseUrl; |
| 107 | + this._productName = productName; |
| 108 | + this._clientVersion = productName.toLowerCase() + '-sdk-' + UID2SdkBase.VERSION; |
107 | 109 | }
|
108 | 110 |
|
109 | 111 | public hasActiveRequests() {
|
@@ -133,7 +135,7 @@ export class Uid2ApiClient {
|
133 | 135 | this._requestsInFlight.push(req);
|
134 | 136 | req.overrideMimeType('text/plain');
|
135 | 137 | req.open('POST', url, true);
|
136 |
| - req.setRequestHeader('X-UID2-Client-Version', this._clientVersion); |
| 138 | + req.setRequestHeader('X-UID2-Client-Version', this._clientVersion); // TODO: EUID |
137 | 139 | let resolvePromise: (result: RefreshResult) => void;
|
138 | 140 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
139 | 141 | let rejectPromise: (reason?: any) => void;
|
@@ -181,10 +183,10 @@ export class Uid2ApiClient {
|
181 | 183 | if (typeof result === 'string') rejectPromise(result);
|
182 | 184 | else resolvePromise(result);
|
183 | 185 | },
|
184 |
| - (reason) => rejectPromise(`Call to UID2 API failed: ` + reason) |
| 186 | + (reason) => rejectPromise(`Call to ${this._productName} API failed: ` + reason) |
185 | 187 | );
|
186 | 188 | },
|
187 |
| - (reason) => rejectPromise(`Call to UID2 API failed: ` + reason) |
| 189 | + (reason) => rejectPromise(`Call to ${this._productName} API failed: ` + reason) |
188 | 190 | );
|
189 | 191 | }
|
190 | 192 | } catch (err) {
|
|
0 commit comments