forked from queueit/KnownUser.V3.Akamai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
akamaiEnqueueTokenProvider.ts
43 lines (37 loc) · 1.32 KB
/
akamaiEnqueueTokenProvider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { IEnqueueTokenProvider } from "queueit-knownuser";
import { QueueITHelper, Settings } from "./QueueITHelpers.js";
import { Token, Payload } from "./sdk/queueToken.js";
export class AkamaiEnqueueTokenProvider implements IEnqueueTokenProvider {
_settings: Settings;
_validityTime: Number;
_clientIp: string;
_customData: any;
public constructor(
setting: Settings,
validityTime: Number,
clientIp?: string,
customData?: any
) {
this._settings = setting;
this._validityTime = validityTime;
this._clientIp = clientIp;
this._customData = `{ ${(customData !== null) ? `,"cd":"${customData}"` : ''} }`;
}
public getEnqueueToken(wrId: string): string {
if (!this._settings || this._validityTime < -1 || !this._clientIp) {
return null;
}
const token = Token.Enqueue(this._settings.CustomerId)
.WithPayload(
Payload.Enqueue()
.WithKey(QueueITHelper.generateUUID())
.WithCustomData(this._customData)
.Generate()
)
.WithEventId(wrId)
.WithIpAddress(this._clientIp)
.WithValidity(this._validityTime)
.Generate(this._settings.SecretKey);
return token.Token;
}
}