-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathitemToToken.ts
More file actions
41 lines (36 loc) · 1.1 KB
/
itemToToken.ts
File metadata and controls
41 lines (36 loc) · 1.1 KB
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
/**
* @author Labs64 <netlicensing@labs64.com>
* @license Apache-2.0
* @link https://netlicensing.io
* @copyright 2017 Labs64 NetLicensing
*/
import itemToObject from '@/converters/itemToObject';
import Token from '@/entities/Token';
// types
import { Item } from '@/types/api/response';
import { TokenProps } from '@/types/entities/Token';
export default <T extends object = TokenProps>(item?: Item) => {
const props = itemToObject<Record<string, unknown>>(item, {
active: 'boolean',
number: 'string',
expirationTime: 'string',
tokenType: 'string',
licenseeNumber: 'string',
action: 'string',
apiKeyRole: 'string',
bundleNumber: 'string',
bundlePrice: 'number',
productNumber: 'string',
predefinedShoppingItem: 'string',
successURL: 'string',
successURLTitle: 'string',
cancelURL: 'string',
cancelURLTitle: 'string',
shopURL: 'string',
});
const { expirationTime } = props;
if (expirationTime && typeof expirationTime === 'string') {
props.expirationTime = new Date(expirationTime);
}
return Token<T>(props as TokenProps<T>);
};