-
Notifications
You must be signed in to change notification settings - Fork 5
/
akamaiEnqueueTokenProvider.ts
51 lines (43 loc) · 1.44 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
44
45
46
47
48
49
50
51
import { IEnqueueTokenProvider } from "queueit-knownuser";
import { QueueITHelper } from "./queueitHelpers.js";
import { Token, Payload } from "./sdk/queueToken.js";
export class AkamaiEnqueueTokenProvider implements IEnqueueTokenProvider {
_customerId: string;
_secretKey: string;
_validityTime: Number;
_clientIp: string | null;
_customData: any;
_withKey: boolean;
public constructor(
customerId: string,
secretKey: string,
validityTime: Number,
clientIp: string | null,
withKey: boolean,
customData?: any
) {
this._customerId = customerId;
this._secretKey = secretKey;
this._validityTime = validityTime;
this._clientIp = clientIp;
this._customData = `{ ${(customData !== null) ? `,"cd":"${customData}"` : ''} }`;
this._withKey = withKey;
}
public getEnqueueToken(wrId: string): string {
var payLoad = Payload.Enqueue()
.WithCustomData(this._customData);
if (this._withKey)
{
payLoad = payLoad.WithKey(QueueITHelper.generateUUID());
}
const token = Token.Enqueue(this._customerId)
.WithPayload(
payLoad.Generate()
)
.WithEventId(wrId)
.WithIpAddress(this._clientIp)
.WithValidity(this._validityTime)
.Generate(this._secretKey);
return token.Token;
}
}