@23blocks/block-authentication 1.0.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +2095 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/lib/authentication.block.d.ts +149 -0
- package/dist/src/lib/authentication.block.d.ts.map +1 -0
- package/dist/src/lib/mappers/api-key.mapper.d.ts +11 -0
- package/dist/src/lib/mappers/api-key.mapper.d.ts.map +1 -0
- package/dist/src/lib/mappers/app.mapper.d.ts +15 -0
- package/dist/src/lib/mappers/app.mapper.d.ts.map +1 -0
- package/dist/src/lib/mappers/company.mapper.d.ts +23 -0
- package/dist/src/lib/mappers/company.mapper.d.ts.map +1 -0
- package/dist/src/lib/mappers/geography.mapper.d.ts +23 -0
- package/dist/src/lib/mappers/geography.mapper.d.ts.map +1 -0
- package/dist/src/lib/mappers/guest.mapper.d.ts +27 -0
- package/dist/src/lib/mappers/guest.mapper.d.ts.map +1 -0
- package/dist/{lib/mappers/index.js → src/lib/mappers/index.d.ts} +2 -11
- package/dist/src/lib/mappers/index.d.ts.map +1 -0
- package/dist/src/lib/mappers/subscription.mapper.d.ts +15 -0
- package/dist/src/lib/mappers/subscription.mapper.d.ts.map +1 -0
- package/dist/src/lib/mappers/user.mapper.d.ts +23 -0
- package/dist/src/lib/mappers/user.mapper.d.ts.map +1 -0
- package/dist/src/lib/mappers/utils.d.ts +21 -0
- package/dist/src/lib/mappers/utils.d.ts.map +1 -0
- package/dist/src/lib/services/api-keys.service.d.ts +65 -0
- package/dist/src/lib/services/api-keys.service.d.ts.map +1 -0
- package/dist/src/lib/services/apps.service.d.ts +87 -0
- package/dist/src/lib/services/apps.service.d.ts.map +1 -0
- package/dist/src/lib/services/auth.service.d.ts +69 -0
- package/dist/src/lib/services/auth.service.d.ts.map +1 -0
- package/dist/src/lib/services/geography.service.d.ts +125 -0
- package/dist/src/lib/services/geography.service.d.ts.map +1 -0
- package/dist/src/lib/services/guests.service.d.ts +166 -0
- package/dist/src/lib/services/guests.service.d.ts.map +1 -0
- package/dist/src/lib/services/index.d.ts +9 -0
- package/dist/src/lib/services/index.d.ts.map +1 -0
- package/dist/src/lib/services/roles.service.d.ts +82 -0
- package/dist/src/lib/services/roles.service.d.ts.map +1 -0
- package/dist/src/lib/services/subscriptions.service.d.ts +102 -0
- package/dist/src/lib/services/subscriptions.service.d.ts.map +1 -0
- package/dist/src/lib/services/users.service.d.ts +85 -0
- package/dist/src/lib/services/users.service.d.ts.map +1 -0
- package/dist/src/lib/types/api-key.d.ts +71 -0
- package/dist/src/lib/types/api-key.d.ts.map +1 -0
- package/dist/src/lib/types/app.d.ts +86 -0
- package/dist/src/lib/types/app.d.ts.map +1 -0
- package/dist/src/lib/types/auth.d.ts +138 -0
- package/dist/src/lib/types/auth.d.ts.map +1 -0
- package/dist/src/lib/types/company.d.ts +73 -0
- package/dist/src/lib/types/company.d.ts.map +1 -0
- package/dist/src/lib/types/geography.d.ts +73 -0
- package/dist/src/lib/types/geography.d.ts.map +1 -0
- package/dist/src/lib/types/guest.d.ts +136 -0
- package/dist/src/lib/types/guest.d.ts.map +1 -0
- package/dist/src/lib/types/index.d.ts +9 -0
- package/dist/src/lib/types/index.d.ts.map +1 -0
- package/dist/src/lib/types/subscription.d.ts +78 -0
- package/dist/src/lib/types/subscription.d.ts.map +1 -0
- package/dist/src/lib/types/user.d.ts +108 -0
- package/dist/src/lib/types/user.d.ts.map +1 -0
- package/package.json +10 -8
- package/dist/index.js +0 -6
- package/dist/index.js.map +0 -1
- package/dist/lib/authentication.block.js +0 -102
- package/dist/lib/authentication.block.js.map +0 -1
- package/dist/lib/mappers/api-key.mapper.js +0 -57
- package/dist/lib/mappers/api-key.mapper.js.map +0 -1
- package/dist/lib/mappers/app.mapper.js +0 -98
- package/dist/lib/mappers/app.mapper.js.map +0 -1
- package/dist/lib/mappers/company.mapper.js +0 -128
- package/dist/lib/mappers/company.mapper.js.map +0 -1
- package/dist/lib/mappers/geography.mapper.js +0 -129
- package/dist/lib/mappers/geography.mapper.js.map +0 -1
- package/dist/lib/mappers/guest.mapper.js +0 -176
- package/dist/lib/mappers/guest.mapper.js.map +0 -1
- package/dist/lib/mappers/index.js.map +0 -1
- package/dist/lib/mappers/subscription.mapper.js +0 -134
- package/dist/lib/mappers/subscription.mapper.js.map +0 -1
- package/dist/lib/mappers/user.mapper.js +0 -163
- package/dist/lib/mappers/user.mapper.js.map +0 -1
- package/dist/lib/mappers/utils.js +0 -54
- package/dist/lib/mappers/utils.js.map +0 -1
- package/dist/lib/services/api-keys.service.js +0 -93
- package/dist/lib/services/api-keys.service.js.map +0 -1
- package/dist/lib/services/apps.service.js +0 -139
- package/dist/lib/services/apps.service.js.map +0 -1
- package/dist/lib/services/auth.service.js +0 -147
- package/dist/lib/services/auth.service.js.map +0 -1
- package/dist/lib/services/geography.service.js +0 -151
- package/dist/lib/services/geography.service.js.map +0 -1
- package/dist/lib/services/guests.service.js +0 -219
- package/dist/lib/services/guests.service.js.map +0 -1
- package/dist/lib/services/index.js +0 -14
- package/dist/lib/services/index.js.map +0 -1
- package/dist/lib/services/roles.service.js +0 -91
- package/dist/lib/services/roles.service.js.map +0 -1
- package/dist/lib/services/subscriptions.service.js +0 -146
- package/dist/lib/services/subscriptions.service.js.map +0 -1
- package/dist/lib/services/users.service.js +0 -116
- package/dist/lib/services/users.service.js.map +0 -1
- package/dist/lib/types/api-key.js +0 -5
- package/dist/lib/types/api-key.js.map +0 -1
- package/dist/lib/types/app.js +0 -5
- package/dist/lib/types/app.js.map +0 -1
- package/dist/lib/types/auth.js +0 -5
- package/dist/lib/types/auth.js.map +0 -1
- package/dist/lib/types/company.js +0 -5
- package/dist/lib/types/company.js.map +0 -1
- package/dist/lib/types/geography.js +0 -5
- package/dist/lib/types/geography.js.map +0 -1
- package/dist/lib/types/guest.js +0 -5
- package/dist/lib/types/guest.js.map +0 -1
- package/dist/lib/types/index.js +0 -4
- package/dist/lib/types/index.js.map +0 -1
- package/dist/lib/types/subscription.js +0 -5
- package/dist/lib/types/subscription.js.map +0 -1
- package/dist/lib/types/user.js +0 -13
- package/dist/lib/types/user.js.map +0 -1
|
@@ -0,0 +1,2095 @@
|
|
|
1
|
+
import { resolveRelationship, resolveRelationshipMany, decodeOne, decodePageResult, decodeMany } from '@23blocks/jsonapi-codec';
|
|
2
|
+
import { _ } from '@swc/helpers/_/_extends';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Parse a string value, returning null for empty/undefined
|
|
6
|
+
*/ function parseString(value) {
|
|
7
|
+
if (value === null || value === undefined) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const str = String(value);
|
|
11
|
+
return str.length > 0 ? str : null;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Parse a date value
|
|
15
|
+
*/ function parseDate(value) {
|
|
16
|
+
if (value === null || value === undefined) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
if (value instanceof Date) {
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
23
|
+
const date = new Date(value);
|
|
24
|
+
return isNaN(date.getTime()) ? null : date;
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Parse a boolean value
|
|
30
|
+
*/ function parseBoolean(value) {
|
|
31
|
+
if (typeof value === 'boolean') {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
if (value === 'true' || value === '1' || value === 1) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Parse an array of strings
|
|
41
|
+
*/ function parseStringArray(value) {
|
|
42
|
+
if (Array.isArray(value)) {
|
|
43
|
+
return value.map(String);
|
|
44
|
+
}
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Parse a number value
|
|
49
|
+
*/ function parseNumber(value) {
|
|
50
|
+
if (value === null || value === undefined) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const num = Number(value);
|
|
54
|
+
return isNaN(num) ? null : num;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Permission mapper
|
|
59
|
+
*/ const permissionMapper = {
|
|
60
|
+
type: 'permission',
|
|
61
|
+
map (resource, _included) {
|
|
62
|
+
var _resource_attributes;
|
|
63
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
64
|
+
var _attrs_status, _parseDate, _parseDate1;
|
|
65
|
+
return {
|
|
66
|
+
id: resource.id,
|
|
67
|
+
uniqueId: parseString(attrs.unique_id),
|
|
68
|
+
name: parseString(attrs.name),
|
|
69
|
+
level: Number(attrs.level) || 0,
|
|
70
|
+
parentId: parseString(attrs.parent_id),
|
|
71
|
+
description: parseString(attrs.description),
|
|
72
|
+
status: (_attrs_status = attrs.status) != null ? _attrs_status : 'active',
|
|
73
|
+
category: parseString(attrs.category),
|
|
74
|
+
riskLevel: parseString(attrs.risk_level),
|
|
75
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
76
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date()
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Role mapper
|
|
82
|
+
*/ const roleMapper = {
|
|
83
|
+
type: 'role',
|
|
84
|
+
map (resource, _included) {
|
|
85
|
+
var _resource_attributes;
|
|
86
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
87
|
+
var _attrs_status, _parseDate, _parseDate1;
|
|
88
|
+
return {
|
|
89
|
+
id: resource.id,
|
|
90
|
+
uniqueId: parseString(attrs.unique_id),
|
|
91
|
+
name: parseString(attrs.name),
|
|
92
|
+
code: parseString(attrs.code),
|
|
93
|
+
description: parseString(attrs.description),
|
|
94
|
+
status: (_attrs_status = attrs.status) != null ? _attrs_status : 'active',
|
|
95
|
+
payload: attrs.payload,
|
|
96
|
+
onBoardingUniqueId: parseString(attrs.on_boarding_unique_id),
|
|
97
|
+
onBoardingUrl: parseString(attrs.on_boarding_url),
|
|
98
|
+
onBoardingPayload: attrs.on_boarding_payload,
|
|
99
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
100
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
101
|
+
// Note: permissions are typically not included in role responses
|
|
102
|
+
permissions: []
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* User avatar mapper
|
|
108
|
+
*/ const userAvatarMapper = {
|
|
109
|
+
type: 'UserAvatar',
|
|
110
|
+
map (resource, _included) {
|
|
111
|
+
var _resource_attributes;
|
|
112
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
113
|
+
var _attrs_status, _parseDate, _parseDate1;
|
|
114
|
+
return {
|
|
115
|
+
id: resource.id,
|
|
116
|
+
uniqueId: parseString(attrs.unique_id),
|
|
117
|
+
userUniqueId: parseString(attrs.user_unique_id),
|
|
118
|
+
bucket: parseString(attrs.bucket),
|
|
119
|
+
originalName: parseString(attrs.original_name),
|
|
120
|
+
name: parseString(attrs.name),
|
|
121
|
+
url: parseString(attrs.url),
|
|
122
|
+
thumbnail: parseString(attrs.thumbnail),
|
|
123
|
+
fileType: parseString(attrs.file_type),
|
|
124
|
+
fileSize: attrs.file_size != null ? Number(attrs.file_size) : null,
|
|
125
|
+
description: parseString(attrs.description),
|
|
126
|
+
originalFile: parseString(attrs.original_file),
|
|
127
|
+
status: (_attrs_status = attrs.status) != null ? _attrs_status : 'active',
|
|
128
|
+
isPublic: parseBoolean(attrs.is_public),
|
|
129
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
130
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date()
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* User profile mapper
|
|
136
|
+
*/ const userProfileMapper = {
|
|
137
|
+
type: 'UserProfile',
|
|
138
|
+
map (resource, _included) {
|
|
139
|
+
var _resource_attributes;
|
|
140
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
141
|
+
var _attrs_status, _parseDate, _parseDate1;
|
|
142
|
+
return {
|
|
143
|
+
id: resource.id,
|
|
144
|
+
uniqueId: parseString(attrs.unique_id),
|
|
145
|
+
userUniqueId: parseString(attrs.user_unique_id),
|
|
146
|
+
firstName: parseString(attrs.first_name),
|
|
147
|
+
middleName: parseString(attrs.middle_name),
|
|
148
|
+
lastName: parseString(attrs.last_name),
|
|
149
|
+
gender: parseString(attrs.gender),
|
|
150
|
+
ethnicity: parseString(attrs.ethnicity),
|
|
151
|
+
zipcode: parseString(attrs.zipcode),
|
|
152
|
+
maritalStatus: parseString(attrs.marital_status),
|
|
153
|
+
birthdate: parseDate(attrs.birthdate),
|
|
154
|
+
hhi: parseString(attrs.hhi),
|
|
155
|
+
children: attrs.children != null ? Number(attrs.children) : null,
|
|
156
|
+
source: parseString(attrs.source),
|
|
157
|
+
status: (_attrs_status = attrs.status) != null ? _attrs_status : 'active',
|
|
158
|
+
phoneNumber: parseString(attrs.phone_number),
|
|
159
|
+
email: parseString(attrs.email),
|
|
160
|
+
preferredDevice: parseString(attrs.preferred_device),
|
|
161
|
+
preferredLanguage: parseString(attrs.preferred_language),
|
|
162
|
+
webSite: parseString(attrs.web_site),
|
|
163
|
+
twitter: parseString(attrs.twitter),
|
|
164
|
+
fb: parseString(attrs.fb),
|
|
165
|
+
instagram: parseString(attrs.instagram),
|
|
166
|
+
linkedin: parseString(attrs.linkedin),
|
|
167
|
+
youtube: parseString(attrs.youtube),
|
|
168
|
+
blog: parseString(attrs.blog),
|
|
169
|
+
networkA: parseString(attrs.network_a),
|
|
170
|
+
networkB: parseString(attrs.network_b),
|
|
171
|
+
payload: attrs.payload,
|
|
172
|
+
timeZone: parseString(attrs.time_zone),
|
|
173
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
174
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date()
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* User mapper
|
|
180
|
+
*/ const userMapper = {
|
|
181
|
+
type: 'User',
|
|
182
|
+
map (resource, included) {
|
|
183
|
+
var _resource_attributes;
|
|
184
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
185
|
+
var _parseString, _parseString1, _attrs_status, _parseDate, _parseDate1;
|
|
186
|
+
return {
|
|
187
|
+
id: resource.id,
|
|
188
|
+
uniqueId: parseString(attrs.unique_id),
|
|
189
|
+
email: parseString(attrs.email),
|
|
190
|
+
username: parseString(attrs.username),
|
|
191
|
+
name: parseString(attrs.name),
|
|
192
|
+
nickname: parseString(attrs.nickname),
|
|
193
|
+
bio: parseString(attrs.bio),
|
|
194
|
+
provider: (_parseString = parseString(attrs.provider)) != null ? _parseString : 'email',
|
|
195
|
+
uid: (_parseString1 = parseString(attrs.uid)) != null ? _parseString1 : attrs.email,
|
|
196
|
+
roleId: parseString(attrs.role_id),
|
|
197
|
+
status: (_attrs_status = attrs.status) != null ? _attrs_status : 'active',
|
|
198
|
+
mailStatus: parseString(attrs.mail_status),
|
|
199
|
+
phoneStatus: parseString(attrs.phone_status),
|
|
200
|
+
allowPasswordChange: parseBoolean(attrs.allow_password_change),
|
|
201
|
+
lastSignInAt: parseDate(attrs.last_sign_in_at),
|
|
202
|
+
confirmedAt: parseDate(attrs.confirmed_at),
|
|
203
|
+
unconfirmedEmail: parseString(attrs.unconfirmed_email),
|
|
204
|
+
invitationSentAt: parseDate(attrs.invitation_sent_at),
|
|
205
|
+
invitationAcceptedAt: parseDate(attrs.invitation_accepted_at),
|
|
206
|
+
invitationCreatedAt: parseDate(attrs.invitation_created_at),
|
|
207
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
208
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
209
|
+
// Resolve relationships from included resources
|
|
210
|
+
role: resolveRelationship(resource, 'role', included, roleMapper),
|
|
211
|
+
avatar: resolveRelationship(resource, 'user_avatar', included, userAvatarMapper),
|
|
212
|
+
profile: resolveRelationship(resource, 'user_profile', included, userProfileMapper)
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Company detail mapper
|
|
219
|
+
*/ const companyDetailMapper = {
|
|
220
|
+
type: 'CompanyDetail',
|
|
221
|
+
map (resource, _included) {
|
|
222
|
+
var _resource_attributes;
|
|
223
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
224
|
+
var _parseString, _parseString1, _parseDate, _parseDate1;
|
|
225
|
+
return {
|
|
226
|
+
id: resource.id,
|
|
227
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
228
|
+
companyUniqueId: (_parseString1 = parseString(attrs.company_unique_id)) != null ? _parseString1 : '',
|
|
229
|
+
address: parseString(attrs.address),
|
|
230
|
+
city: parseString(attrs.city),
|
|
231
|
+
state: parseString(attrs.state),
|
|
232
|
+
zipcode: parseString(attrs.zipcode),
|
|
233
|
+
country: parseString(attrs.country),
|
|
234
|
+
phone: parseString(attrs.phone),
|
|
235
|
+
email: parseString(attrs.email),
|
|
236
|
+
website: parseString(attrs.website),
|
|
237
|
+
description: parseString(attrs.description),
|
|
238
|
+
logoUrl: parseString(attrs.logo_url),
|
|
239
|
+
payload: attrs.payload,
|
|
240
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
241
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date()
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* Company block mapper
|
|
247
|
+
*/ const companyBlockMapper = {
|
|
248
|
+
type: 'CompanyBlock',
|
|
249
|
+
map (resource, _included) {
|
|
250
|
+
var _resource_attributes;
|
|
251
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
252
|
+
var _parseString, _parseString1, _parseString2, _parseString3, _attrs_status, _parseDate, _parseDate1;
|
|
253
|
+
return {
|
|
254
|
+
id: resource.id,
|
|
255
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
256
|
+
companyUniqueId: (_parseString1 = parseString(attrs.company_unique_id)) != null ? _parseString1 : '',
|
|
257
|
+
blockId: (_parseString2 = parseString(attrs.block_id)) != null ? _parseString2 : '',
|
|
258
|
+
blockName: (_parseString3 = parseString(attrs.block_name)) != null ? _parseString3 : '',
|
|
259
|
+
status: (_attrs_status = attrs.status) != null ? _attrs_status : 'active',
|
|
260
|
+
payload: attrs.payload,
|
|
261
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
262
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date()
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
* Company key mapper
|
|
268
|
+
*/ const companyKeyMapper = {
|
|
269
|
+
type: 'CompanyKey',
|
|
270
|
+
map (resource, _included) {
|
|
271
|
+
var _resource_attributes;
|
|
272
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
273
|
+
var _parseString, _parseString1, _parseString2, _parseString3, _attrs_status, _parseDate, _parseDate1;
|
|
274
|
+
return {
|
|
275
|
+
id: resource.id,
|
|
276
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
277
|
+
companyUniqueId: (_parseString1 = parseString(attrs.company_unique_id)) != null ? _parseString1 : '',
|
|
278
|
+
name: (_parseString2 = parseString(attrs.name)) != null ? _parseString2 : '',
|
|
279
|
+
keyId: (_parseString3 = parseString(attrs.key_id)) != null ? _parseString3 : '',
|
|
280
|
+
status: (_attrs_status = attrs.status) != null ? _attrs_status : 'active',
|
|
281
|
+
expiresAt: parseDate(attrs.expires_at),
|
|
282
|
+
lastUsedAt: parseDate(attrs.last_used_at),
|
|
283
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
284
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date()
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Company mapper
|
|
290
|
+
*/ const companyMapper = {
|
|
291
|
+
type: 'Company',
|
|
292
|
+
map (resource, included) {
|
|
293
|
+
var _resource_attributes;
|
|
294
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
295
|
+
var _parseString, _parseString1, _parseString2, _attrs_status, _parseDate, _parseDate1, _parseString3, _parseString4, _parseString5, _parseString6, _parseString7;
|
|
296
|
+
return {
|
|
297
|
+
id: resource.id,
|
|
298
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
299
|
+
name: (_parseString1 = parseString(attrs.name)) != null ? _parseString1 : '',
|
|
300
|
+
code: (_parseString2 = parseString(attrs.code)) != null ? _parseString2 : '',
|
|
301
|
+
preferredLanguage: parseString(attrs.preferred_language),
|
|
302
|
+
preferredDomain: parseString(attrs.preferred_domain),
|
|
303
|
+
apiUrl: parseString(attrs.api_url),
|
|
304
|
+
apiAccessKey: parseString(attrs.api_access_key),
|
|
305
|
+
payload: attrs.payload,
|
|
306
|
+
status: (_attrs_status = attrs.status) != null ? _attrs_status : 'active',
|
|
307
|
+
publicStorageUrl: parseString(attrs.public_storage_url),
|
|
308
|
+
storageUrl: parseString(attrs.storage_url),
|
|
309
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
310
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
311
|
+
// Conditional admin-only attributes
|
|
312
|
+
schemaName: (_parseString3 = parseString(attrs.schema_name)) != null ? _parseString3 : undefined,
|
|
313
|
+
urlId: (_parseString4 = parseString(attrs.url_id)) != null ? _parseString4 : undefined,
|
|
314
|
+
slackHook: (_parseString5 = parseString(attrs.slack_hook)) != null ? _parseString5 : undefined,
|
|
315
|
+
slackChannel: (_parseString6 = parseString(attrs.slack_channel)) != null ? _parseString6 : undefined,
|
|
316
|
+
slackUsername: (_parseString7 = parseString(attrs.slack_username)) != null ? _parseString7 : undefined,
|
|
317
|
+
openAccess: attrs.open_access != null ? parseBoolean(attrs.open_access) : undefined,
|
|
318
|
+
// Resolve relationships
|
|
319
|
+
companyDetail: resolveRelationship(resource, 'company_detail', included, companyDetailMapper),
|
|
320
|
+
companyBlocks: resolveRelationshipMany(resource, 'company_blocks', included, companyBlockMapper),
|
|
321
|
+
companyKeys: resolveRelationshipMany(resource, 'company_keys', included, companyKeyMapper)
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
326
|
+
* Tenant mapper
|
|
327
|
+
*/ const tenantMapper = {
|
|
328
|
+
type: 'Tenant',
|
|
329
|
+
map (resource, _included) {
|
|
330
|
+
var _resource_attributes;
|
|
331
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
332
|
+
var _parseString, _parseString1, _parseString2;
|
|
333
|
+
return {
|
|
334
|
+
gatewayUrl: (_parseString = parseString(attrs.gateway_url)) != null ? _parseString : '',
|
|
335
|
+
tenantAccessKey: (_parseString1 = parseString(attrs.tenant_access_key)) != null ? _parseString1 : '',
|
|
336
|
+
tenantUrlId: (_parseString2 = parseString(attrs.tenant_url_id)) != null ? _parseString2 : '',
|
|
337
|
+
payload: attrs.payload
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* API Key mapper
|
|
344
|
+
*/ const apiKeyMapper = {
|
|
345
|
+
type: 'ApiKey',
|
|
346
|
+
map (resource, _included) {
|
|
347
|
+
var _resource_attributes;
|
|
348
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
349
|
+
var _parseString, _parseString1, _parseString2, _attrs_status, _parseNumber, _parseDate, _parseDate1, _parseNumber1, _parseNumber2, _parseNumber3;
|
|
350
|
+
return {
|
|
351
|
+
id: resource.id,
|
|
352
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
353
|
+
keyId: (_parseString1 = parseString(attrs.key_id)) != null ? _parseString1 : '',
|
|
354
|
+
name: (_parseString2 = parseString(attrs.name)) != null ? _parseString2 : '',
|
|
355
|
+
description: parseString(attrs.description),
|
|
356
|
+
status: (_attrs_status = attrs.status) != null ? _attrs_status : 'active',
|
|
357
|
+
serviceAccount: parseBoolean(attrs.service_account),
|
|
358
|
+
scopes: parseStringArray(attrs.scopes),
|
|
359
|
+
expiresAt: parseDate(attrs.expires_at),
|
|
360
|
+
rateLimitPerMinute: parseNumber(attrs.rate_limit_per_minute),
|
|
361
|
+
rateLimitPerHour: parseNumber(attrs.rate_limit_per_hour),
|
|
362
|
+
rateLimitPerDay: parseNumber(attrs.rate_limit_per_day),
|
|
363
|
+
allowedOrigins: parseStringArray(attrs.allowed_origins),
|
|
364
|
+
allowedIps: parseStringArray(attrs.allowed_ips),
|
|
365
|
+
lastUsedAt: parseDate(attrs.last_used_at),
|
|
366
|
+
usageCount: (_parseNumber = parseNumber(attrs.usage_count)) != null ? _parseNumber : 0,
|
|
367
|
+
revokedAt: parseDate(attrs.revoked_at),
|
|
368
|
+
revocationReason: parseString(attrs.revocation_reason),
|
|
369
|
+
payload: attrs.payload,
|
|
370
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
371
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
372
|
+
// Computed attributes
|
|
373
|
+
isExpired: parseBoolean(attrs.is_expired),
|
|
374
|
+
daysUntilExpiry: parseNumber(attrs.days_until_expiry),
|
|
375
|
+
usageToday: (_parseNumber1 = parseNumber(attrs.usage_today)) != null ? _parseNumber1 : 0,
|
|
376
|
+
usageThisWeek: (_parseNumber2 = parseNumber(attrs.usage_this_week)) != null ? _parseNumber2 : 0,
|
|
377
|
+
usageThisMonth: (_parseNumber3 = parseNumber(attrs.usage_this_month)) != null ? _parseNumber3 : 0
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
/**
|
|
382
|
+
* API Key with secret mapper (only used on create/regenerate)
|
|
383
|
+
*/ const apiKeyWithSecretMapper = {
|
|
384
|
+
type: 'ApiKey',
|
|
385
|
+
map (resource, included) {
|
|
386
|
+
var _resource_attributes;
|
|
387
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
388
|
+
const baseKey = apiKeyMapper.map(resource, included);
|
|
389
|
+
var _parseString;
|
|
390
|
+
return _({}, baseKey, {
|
|
391
|
+
secretKey: (_parseString = parseString(attrs.secret_key)) != null ? _parseString : ''
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Mapper for App resources
|
|
398
|
+
*/ const appMapper = {
|
|
399
|
+
type: 'apps',
|
|
400
|
+
map (resource, _included) {
|
|
401
|
+
var _resource_attributes;
|
|
402
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
403
|
+
var _parseString, _parseDate, _parseDate1, _attrs_name, _attrs_app_type, _parseString1, _parseNumber, _parseNumber1, _parseNumber2, _parseNumber3, _parseNumber4;
|
|
404
|
+
return {
|
|
405
|
+
id: resource.id,
|
|
406
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
407
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
408
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
409
|
+
name: String((_attrs_name = attrs.name) != null ? _attrs_name : ''),
|
|
410
|
+
description: parseString(attrs.description),
|
|
411
|
+
appType: String((_attrs_app_type = attrs.app_type) != null ? _attrs_app_type : 'web'),
|
|
412
|
+
status: (_parseString1 = parseString(attrs.status)) != null ? _parseString1 : 'active',
|
|
413
|
+
appIcon: parseString(attrs.app_icon),
|
|
414
|
+
oauthEnabled: parseBoolean(attrs.oauth_enabled),
|
|
415
|
+
oauthAccessTokenLifetimeHours: (_parseNumber = parseNumber(attrs.oauth_access_token_lifetime_hours)) != null ? _parseNumber : 24,
|
|
416
|
+
oauthRefreshTokenLifetimeDays: (_parseNumber1 = parseNumber(attrs.oauth_refresh_token_lifetime_days)) != null ? _parseNumber1 : 30,
|
|
417
|
+
oauthRefreshTokenRotation: parseBoolean(attrs.oauth_refresh_token_rotation),
|
|
418
|
+
oauthMaxRefreshTokensPerDevice: (_parseNumber2 = parseNumber(attrs.oauth_max_refresh_tokens_per_device)) != null ? _parseNumber2 : 5,
|
|
419
|
+
oauthDeviceManagement: parseBoolean(attrs.oauth_device_management),
|
|
420
|
+
rateLimitPerMinute: parseNumber(attrs.rate_limit_per_minute),
|
|
421
|
+
rateLimitPerHour: parseNumber(attrs.rate_limit_per_hour),
|
|
422
|
+
webhookUrl: parseString(attrs.webhook_url),
|
|
423
|
+
webhookSecret: parseString(attrs.webhook_secret),
|
|
424
|
+
allowedOrigins: parseStringArray(attrs.allowed_origins),
|
|
425
|
+
metadata: attrs.metadata,
|
|
426
|
+
payload: attrs.payload,
|
|
427
|
+
apiKeyCount: (_parseNumber3 = parseNumber(attrs.api_key_count)) != null ? _parseNumber3 : 0,
|
|
428
|
+
activeApiKeyCount: (_parseNumber4 = parseNumber(attrs.active_api_key_count)) != null ? _parseNumber4 : 0
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
/**
|
|
433
|
+
* Mapper for Block resources
|
|
434
|
+
*/ const blockMapper = {
|
|
435
|
+
type: 'blocks',
|
|
436
|
+
map (resource, _included) {
|
|
437
|
+
var _resource_attributes;
|
|
438
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
439
|
+
var _parseString, _parseDate, _parseDate1, _attrs_company_unique_id, _attrs_block_unique_id, _attrs_block_code, _attrs_block_name, _parseString1;
|
|
440
|
+
return {
|
|
441
|
+
id: resource.id,
|
|
442
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
443
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
444
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
445
|
+
companyUniqueId: String((_attrs_company_unique_id = attrs.company_unique_id) != null ? _attrs_company_unique_id : ''),
|
|
446
|
+
blockUniqueId: String((_attrs_block_unique_id = attrs.block_unique_id) != null ? _attrs_block_unique_id : ''),
|
|
447
|
+
blockCode: String((_attrs_block_code = attrs.block_code) != null ? _attrs_block_code : ''),
|
|
448
|
+
blockName: String((_attrs_block_name = attrs.block_name) != null ? _attrs_block_name : ''),
|
|
449
|
+
addedAt: parseDate(attrs.added_at),
|
|
450
|
+
status: (_parseString1 = parseString(attrs.status)) != null ? _parseString1 : 'active',
|
|
451
|
+
subscriptionModel: parseString(attrs.subscription_model),
|
|
452
|
+
subscriptionPlan: parseString(attrs.subscription_plan),
|
|
453
|
+
subscriptionFee: parseNumber(attrs.subscription_fee),
|
|
454
|
+
subscriptionTaxes: parseNumber(attrs.subscription_taxes),
|
|
455
|
+
subscriptionTotal: parseNumber(attrs.subscription_total),
|
|
456
|
+
lastPaymentAt: parseDate(attrs.last_payment_at),
|
|
457
|
+
nextPaymentAt: parseDate(attrs.next_payment_at),
|
|
458
|
+
payload: attrs.payload
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
/**
|
|
463
|
+
* Mapper for Service resources
|
|
464
|
+
*/ const serviceMapper = {
|
|
465
|
+
type: 'services',
|
|
466
|
+
map (resource, _included) {
|
|
467
|
+
var _resource_attributes;
|
|
468
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
469
|
+
var _parseString, _parseDate, _parseDate1, _attrs_name, _attrs_code, _parseString1;
|
|
470
|
+
return {
|
|
471
|
+
id: resource.id,
|
|
472
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
473
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
474
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
475
|
+
name: String((_attrs_name = attrs.name) != null ? _attrs_name : ''),
|
|
476
|
+
code: String((_attrs_code = attrs.code) != null ? _attrs_code : ''),
|
|
477
|
+
description: parseString(attrs.description),
|
|
478
|
+
homePageUrl: parseString(attrs.home_page_url),
|
|
479
|
+
healthCheckUrl: parseString(attrs.health_check_url),
|
|
480
|
+
statusPageUrl: parseString(attrs.status_page_url),
|
|
481
|
+
status: (_parseString1 = parseString(attrs.status)) != null ? _parseString1 : 'active',
|
|
482
|
+
registeredAt: parseDate(attrs.registered_at),
|
|
483
|
+
host: parseString(attrs.host),
|
|
484
|
+
port: parseNumber(attrs.port),
|
|
485
|
+
uri: parseString(attrs.uri),
|
|
486
|
+
groupName: parseString(attrs.group_name),
|
|
487
|
+
ipaddress: parseString(attrs.ipaddress)
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Mapper for SubscriptionModel resources
|
|
494
|
+
*/ const subscriptionModelMapper = {
|
|
495
|
+
type: 'subscription_models',
|
|
496
|
+
map (resource, _included) {
|
|
497
|
+
var _resource_attributes;
|
|
498
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
499
|
+
var _parseString, _parseDate, _parseDate1, _attrs_code, _parseString1;
|
|
500
|
+
return {
|
|
501
|
+
id: resource.id,
|
|
502
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
503
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
504
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
505
|
+
code: String((_attrs_code = attrs.code) != null ? _attrs_code : ''),
|
|
506
|
+
status: (_parseString1 = parseString(attrs.status)) != null ? _parseString1 : 'active',
|
|
507
|
+
description: parseString(attrs.description),
|
|
508
|
+
promotional: parseBoolean(attrs.promotional),
|
|
509
|
+
programCode: parseString(attrs.program_code),
|
|
510
|
+
duration: parseNumber(attrs.duration),
|
|
511
|
+
durationUnit: parseString(attrs.duration_unit),
|
|
512
|
+
durationDescription: parseString(attrs.duration_description),
|
|
513
|
+
recurringPaymentFees: parseNumber(attrs.recurring_payment_fees),
|
|
514
|
+
recurringPaymentAmount: parseNumber(attrs.recurring_payment_amount),
|
|
515
|
+
contentLink: parseString(attrs.content_link),
|
|
516
|
+
startAt: parseDate(attrs.start_at),
|
|
517
|
+
endAt: parseDate(attrs.end_at),
|
|
518
|
+
isChannel: parseBoolean(attrs.is_channel),
|
|
519
|
+
maxTenants: parseNumber(attrs.max_tenants),
|
|
520
|
+
initialPayment: parseNumber(attrs.initial_payment),
|
|
521
|
+
subscriptionType: parseString(attrs.subscription_type),
|
|
522
|
+
payments: parseNumber(attrs.payments),
|
|
523
|
+
payload: attrs.payload,
|
|
524
|
+
maxItems: parseNumber(attrs.max_items)
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
/**
|
|
529
|
+
* Mapper for UserSubscription resources
|
|
530
|
+
*/ const userSubscriptionMapper = {
|
|
531
|
+
type: 'user_subscriptions',
|
|
532
|
+
map (resource, included) {
|
|
533
|
+
var _resource_relationships_subscription_model, _resource_relationships;
|
|
534
|
+
var _resource_attributes;
|
|
535
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
536
|
+
var _parseString, _parseDate, _parseDate1, _attrs_code, _attrs_user_unique_id, _parseNumber, _parseString1, _parseNumber1;
|
|
537
|
+
const subscription = {
|
|
538
|
+
id: resource.id,
|
|
539
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
540
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
541
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
542
|
+
code: String((_attrs_code = attrs.code) != null ? _attrs_code : ''),
|
|
543
|
+
userUniqueId: String((_attrs_user_unique_id = attrs.user_unique_id) != null ? _attrs_user_unique_id : ''),
|
|
544
|
+
programCode: parseString(attrs.program_code),
|
|
545
|
+
recurringPaymentFees: parseNumber(attrs.recurring_payment_fees),
|
|
546
|
+
recurringPaymentAmount: parseNumber(attrs.recurring_payment_amount),
|
|
547
|
+
subscriptionNumber: parseString(attrs.subscription_number),
|
|
548
|
+
subscribedAt: parseDate(attrs.subscribed_at),
|
|
549
|
+
closedAt: parseDate(attrs.closed_at),
|
|
550
|
+
lastPaymentAt: parseDate(attrs.last_payment_at),
|
|
551
|
+
nextPaymentAt: parseDate(attrs.next_payment_at),
|
|
552
|
+
lastPayment: parseNumber(attrs.last_payment),
|
|
553
|
+
paymentsMade: (_parseNumber = parseNumber(attrs.payments_made)) != null ? _parseNumber : 0,
|
|
554
|
+
status: (_parseString1 = parseString(attrs.status)) != null ? _parseString1 : 'active',
|
|
555
|
+
bankruptcy: parseBoolean(attrs.bankruptcy),
|
|
556
|
+
initialPayment: parseNumber(attrs.initial_payment),
|
|
557
|
+
subscriptionType: parseString(attrs.subscription_type),
|
|
558
|
+
payments: parseNumber(attrs.payments),
|
|
559
|
+
payload: attrs.payload,
|
|
560
|
+
maxItems: parseNumber(attrs.max_items),
|
|
561
|
+
consumption: (_parseNumber1 = parseNumber(attrs.consumption)) != null ? _parseNumber1 : 0
|
|
562
|
+
};
|
|
563
|
+
// Resolve subscription_model relationship if included
|
|
564
|
+
if (included && ((_resource_relationships = resource.relationships) == null ? void 0 : (_resource_relationships_subscription_model = _resource_relationships.subscription_model) == null ? void 0 : _resource_relationships_subscription_model.data)) {
|
|
565
|
+
const relData = resource.relationships.subscription_model.data;
|
|
566
|
+
if (!Array.isArray(relData)) {
|
|
567
|
+
const modelResource = included.get(`${relData.type}:${relData.id}`);
|
|
568
|
+
if (modelResource) {
|
|
569
|
+
subscription.subscriptionModel = subscriptionModelMapper.map(modelResource, included);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
return subscription;
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
/**
|
|
577
|
+
* Mapper for CompanySubscription resources
|
|
578
|
+
*/ const companySubscriptionMapper = {
|
|
579
|
+
type: 'company_subscriptions',
|
|
580
|
+
map (resource, included) {
|
|
581
|
+
var _resource_relationships_subscription_model, _resource_relationships;
|
|
582
|
+
var _resource_attributes;
|
|
583
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
584
|
+
var _parseString, _parseDate, _parseDate1, _attrs_code, _attrs_company_unique_id, _parseNumber, _parseString1, _parseNumber1;
|
|
585
|
+
const subscription = {
|
|
586
|
+
id: resource.id,
|
|
587
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
588
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
589
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
590
|
+
code: String((_attrs_code = attrs.code) != null ? _attrs_code : ''),
|
|
591
|
+
companyUniqueId: String((_attrs_company_unique_id = attrs.company_unique_id) != null ? _attrs_company_unique_id : ''),
|
|
592
|
+
programCode: parseString(attrs.program_code),
|
|
593
|
+
recurringPaymentFees: parseNumber(attrs.recurring_payment_fees),
|
|
594
|
+
recurringPaymentAmount: parseNumber(attrs.recurring_payment_amount),
|
|
595
|
+
subscriptionNumber: parseString(attrs.subscription_number),
|
|
596
|
+
subscribedAt: parseDate(attrs.subscribed_at),
|
|
597
|
+
closedAt: parseDate(attrs.closed_at),
|
|
598
|
+
lastPaymentAt: parseDate(attrs.last_payment_at),
|
|
599
|
+
nextPaymentAt: parseDate(attrs.next_payment_at),
|
|
600
|
+
lastPayment: parseNumber(attrs.last_payment),
|
|
601
|
+
paymentsMade: (_parseNumber = parseNumber(attrs.payments_made)) != null ? _parseNumber : 0,
|
|
602
|
+
status: (_parseString1 = parseString(attrs.status)) != null ? _parseString1 : 'active',
|
|
603
|
+
bankruptcy: parseBoolean(attrs.bankruptcy),
|
|
604
|
+
initialPayment: parseNumber(attrs.initial_payment),
|
|
605
|
+
subscriptionType: parseString(attrs.subscription_type),
|
|
606
|
+
payload: attrs.payload,
|
|
607
|
+
maxItems: parseNumber(attrs.max_items),
|
|
608
|
+
consumption: (_parseNumber1 = parseNumber(attrs.consumption)) != null ? _parseNumber1 : 0
|
|
609
|
+
};
|
|
610
|
+
// Resolve subscription_model relationship if included
|
|
611
|
+
if (included && ((_resource_relationships = resource.relationships) == null ? void 0 : (_resource_relationships_subscription_model = _resource_relationships.subscription_model) == null ? void 0 : _resource_relationships_subscription_model.data)) {
|
|
612
|
+
const relData = resource.relationships.subscription_model.data;
|
|
613
|
+
if (!Array.isArray(relData)) {
|
|
614
|
+
const modelResource = included.get(`${relData.type}:${relData.id}`);
|
|
615
|
+
if (modelResource) {
|
|
616
|
+
subscription.subscriptionModel = subscriptionModelMapper.map(modelResource, included);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
return subscription;
|
|
621
|
+
}
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* Mapper for Country resources
|
|
626
|
+
*/ const countryMapper = {
|
|
627
|
+
type: 'countries',
|
|
628
|
+
map (resource, _included) {
|
|
629
|
+
var _resource_attributes;
|
|
630
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
631
|
+
var _parseString, _parseDate, _parseDate1, _attrs_country_unique_id, _attrs_name, _parseString1;
|
|
632
|
+
return {
|
|
633
|
+
id: resource.id,
|
|
634
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
635
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
636
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
637
|
+
countryUniqueId: String((_attrs_country_unique_id = attrs.country_unique_id) != null ? _attrs_country_unique_id : resource.id),
|
|
638
|
+
name: String((_attrs_name = attrs.name) != null ? _attrs_name : ''),
|
|
639
|
+
areaCode: parseString(attrs.area_code),
|
|
640
|
+
isoCode: parseString(attrs.iso_code),
|
|
641
|
+
capital: parseString(attrs.capital),
|
|
642
|
+
continent: parseString(attrs.continent),
|
|
643
|
+
tld: parseString(attrs.tld),
|
|
644
|
+
currencyCode: parseString(attrs.currency_code),
|
|
645
|
+
currencyName: parseString(attrs.currency_name),
|
|
646
|
+
postalCodeFormat: parseString(attrs.postal_code_format),
|
|
647
|
+
postalCodeRegex: parseString(attrs.postal_code_regex),
|
|
648
|
+
status: (_parseString1 = parseString(attrs.status)) != null ? _parseString1 : 'active',
|
|
649
|
+
language: parseString(attrs.language),
|
|
650
|
+
payload: attrs.payload
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
/**
|
|
655
|
+
* Mapper for State resources
|
|
656
|
+
*/ const stateMapper = {
|
|
657
|
+
type: 'states',
|
|
658
|
+
map (resource, _included) {
|
|
659
|
+
var _resource_attributes;
|
|
660
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
661
|
+
var _parseString, _parseDate, _parseDate1, _attrs_state_unique_id, _attrs_name, _parseString1;
|
|
662
|
+
return {
|
|
663
|
+
id: resource.id,
|
|
664
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
665
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
666
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
667
|
+
stateUniqueId: String((_attrs_state_unique_id = attrs.state_unique_id) != null ? _attrs_state_unique_id : resource.id),
|
|
668
|
+
name: String((_attrs_name = attrs.name) != null ? _attrs_name : ''),
|
|
669
|
+
abbreviation: parseString(attrs.abbreviation),
|
|
670
|
+
status: (_parseString1 = parseString(attrs.status)) != null ? _parseString1 : 'active',
|
|
671
|
+
language: parseString(attrs.language),
|
|
672
|
+
countryName: parseString(attrs.country_name),
|
|
673
|
+
countryId: parseString(attrs.country_id),
|
|
674
|
+
payload: attrs.payload
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
/**
|
|
679
|
+
* Mapper for County resources
|
|
680
|
+
*/ const countyMapper = {
|
|
681
|
+
type: 'counties',
|
|
682
|
+
map (resource, _included) {
|
|
683
|
+
var _resource_attributes;
|
|
684
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
685
|
+
var _parseString, _parseDate, _parseDate1, _attrs_county_unique_id, _attrs_name, _parseString1;
|
|
686
|
+
return {
|
|
687
|
+
id: resource.id,
|
|
688
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
689
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
690
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
691
|
+
countyUniqueId: String((_attrs_county_unique_id = attrs.county_unique_id) != null ? _attrs_county_unique_id : resource.id),
|
|
692
|
+
name: String((_attrs_name = attrs.name) != null ? _attrs_name : ''),
|
|
693
|
+
status: (_parseString1 = parseString(attrs.status)) != null ? _parseString1 : 'active',
|
|
694
|
+
stateName: parseString(attrs.state_name),
|
|
695
|
+
stateId: parseString(attrs.state_id),
|
|
696
|
+
language: parseString(attrs.language),
|
|
697
|
+
payload: attrs.payload
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
/**
|
|
702
|
+
* Mapper for City resources
|
|
703
|
+
*/ const cityMapper = {
|
|
704
|
+
type: 'cities',
|
|
705
|
+
map (resource, _included) {
|
|
706
|
+
var _resource_attributes;
|
|
707
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
708
|
+
var _parseString, _parseDate, _parseDate1, _attrs_name, _parseString1;
|
|
709
|
+
return {
|
|
710
|
+
id: resource.id,
|
|
711
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
712
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
713
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
714
|
+
name: String((_attrs_name = attrs.name) != null ? _attrs_name : ''),
|
|
715
|
+
stateName: parseString(attrs.state_name),
|
|
716
|
+
stateId: parseString(attrs.state_id),
|
|
717
|
+
countryName: parseString(attrs.country_name),
|
|
718
|
+
countryId: parseString(attrs.country_id),
|
|
719
|
+
countyName: parseString(attrs.county_name),
|
|
720
|
+
countyId: parseString(attrs.county_id),
|
|
721
|
+
status: (_parseString1 = parseString(attrs.status)) != null ? _parseString1 : 'active',
|
|
722
|
+
language: parseString(attrs.language),
|
|
723
|
+
payload: attrs.payload
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
/**
|
|
728
|
+
* Mapper for Currency resources
|
|
729
|
+
*/ const currencyMapper = {
|
|
730
|
+
type: 'currencies',
|
|
731
|
+
map (resource, _included) {
|
|
732
|
+
var _resource_attributes;
|
|
733
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
734
|
+
var _parseString, _parseDate, _parseDate1, _attrs_currency_unique_id, _attrs_code, _attrs_name, _parseString1;
|
|
735
|
+
return {
|
|
736
|
+
id: resource.id,
|
|
737
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
738
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
739
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
740
|
+
currencyUniqueId: String((_attrs_currency_unique_id = attrs.currency_unique_id) != null ? _attrs_currency_unique_id : resource.id),
|
|
741
|
+
code: String((_attrs_code = attrs.code) != null ? _attrs_code : ''),
|
|
742
|
+
name: String((_attrs_name = attrs.name) != null ? _attrs_name : ''),
|
|
743
|
+
symbol: parseString(attrs.symbol),
|
|
744
|
+
status: (_parseString1 = parseString(attrs.status)) != null ? _parseString1 : 'active',
|
|
745
|
+
language: parseString(attrs.language),
|
|
746
|
+
payload: attrs.payload
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* Mapper for Guest resources
|
|
753
|
+
*/ const guestMapper = {
|
|
754
|
+
type: 'guests',
|
|
755
|
+
map (resource, _included) {
|
|
756
|
+
var _resource_attributes;
|
|
757
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
758
|
+
var _parseString, _parseDate, _parseDate1, _parseString1;
|
|
759
|
+
return {
|
|
760
|
+
id: resource.id,
|
|
761
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
762
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
763
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
764
|
+
email: parseString(attrs.email),
|
|
765
|
+
username: parseString(attrs.username),
|
|
766
|
+
name: parseString(attrs.name),
|
|
767
|
+
currentVisitingAt: parseDate(attrs.current_visiting_at),
|
|
768
|
+
currentVisitingIp: parseString(attrs.current_visiting_ip),
|
|
769
|
+
lastVisitingAt: parseDate(attrs.last_visiting_at),
|
|
770
|
+
lastVisitingIp: parseString(attrs.last_visiting_ip),
|
|
771
|
+
status: (_parseString1 = parseString(attrs.status)) != null ? _parseString1 : 'active',
|
|
772
|
+
registeredAt: parseDate(attrs.registered_at),
|
|
773
|
+
userUniqueId: parseString(attrs.user_unique_id),
|
|
774
|
+
accessToken: parseString(attrs.access_token)
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
};
|
|
778
|
+
/**
|
|
779
|
+
* Mapper for MagicLink resources
|
|
780
|
+
*/ const magicLinkMapper = {
|
|
781
|
+
type: 'magic_links',
|
|
782
|
+
map (resource, _included) {
|
|
783
|
+
var _resource_attributes;
|
|
784
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
785
|
+
var _parseString, _parseDate, _parseDate1, _attrs_user_unique_id, _attrs_token, _parseDate2, _parseString1;
|
|
786
|
+
return {
|
|
787
|
+
id: resource.id,
|
|
788
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
789
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
790
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
791
|
+
userUniqueId: String((_attrs_user_unique_id = attrs.user_unique_id) != null ? _attrs_user_unique_id : ''),
|
|
792
|
+
userName: parseString(attrs.user_name),
|
|
793
|
+
userEmail: parseString(attrs.user_email),
|
|
794
|
+
token: String((_attrs_token = attrs.token) != null ? _attrs_token : ''),
|
|
795
|
+
expiresAt: (_parseDate2 = parseDate(attrs.expires_at)) != null ? _parseDate2 : new Date(),
|
|
796
|
+
targetUrl: parseString(attrs.target_url),
|
|
797
|
+
expiredUrl: parseString(attrs.expired_url),
|
|
798
|
+
status: (_parseString1 = parseString(attrs.status)) != null ? _parseString1 : 'active',
|
|
799
|
+
validationUrl: parseString(attrs.validation_url),
|
|
800
|
+
description: parseString(attrs.description),
|
|
801
|
+
thumbnailUrl: parseString(attrs.thumbnail_url),
|
|
802
|
+
contentUrl: parseString(attrs.content_url),
|
|
803
|
+
mediaUrl: parseString(attrs.media_url),
|
|
804
|
+
imageUrl: parseString(attrs.image_url),
|
|
805
|
+
payload: attrs.payload
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
/**
|
|
810
|
+
* Mapper for RefreshToken resources
|
|
811
|
+
*/ const refreshTokenMapper = {
|
|
812
|
+
type: 'refresh_tokens',
|
|
813
|
+
map (resource, _included) {
|
|
814
|
+
var _resource_attributes;
|
|
815
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
816
|
+
var _parseString, _parseDate, _parseDate1, _attrs_token, _parseDate2, _parseString1, _parseNumber, _parseNumber1;
|
|
817
|
+
return {
|
|
818
|
+
id: resource.id,
|
|
819
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
820
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
821
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
822
|
+
token: String((_attrs_token = attrs.token) != null ? _attrs_token : ''),
|
|
823
|
+
expiresAt: (_parseDate2 = parseDate(attrs.expires_at)) != null ? _parseDate2 : new Date(),
|
|
824
|
+
status: (_parseString1 = parseString(attrs.status)) != null ? _parseString1 : 'active',
|
|
825
|
+
revoked: parseBoolean(attrs.revoked),
|
|
826
|
+
scopes: parseStringArray(attrs.scopes),
|
|
827
|
+
deviceId: parseString(attrs.device_id),
|
|
828
|
+
userAgent: parseString(attrs.user_agent),
|
|
829
|
+
ipAddress: parseString(attrs.ip_address),
|
|
830
|
+
lastUsedAt: parseDate(attrs.last_used_at),
|
|
831
|
+
expired: parseBoolean(attrs.expired),
|
|
832
|
+
active: parseBoolean(attrs.active),
|
|
833
|
+
expiresInSeconds: (_parseNumber = parseNumber(attrs.expires_in_seconds)) != null ? _parseNumber : 0,
|
|
834
|
+
daysUntilExpiry: (_parseNumber1 = parseNumber(attrs.days_until_expiry)) != null ? _parseNumber1 : 0
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
/**
|
|
839
|
+
* Mapper for UserDevice resources
|
|
840
|
+
*/ const userDeviceMapper = {
|
|
841
|
+
type: 'user_devices',
|
|
842
|
+
map (resource, _included) {
|
|
843
|
+
var _resource_attributes;
|
|
844
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
845
|
+
var _parseString, _parseDate, _parseDate1, _attrs_user_unique_id, _parseString1;
|
|
846
|
+
return {
|
|
847
|
+
id: resource.id,
|
|
848
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
849
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
850
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
851
|
+
userUniqueId: String((_attrs_user_unique_id = attrs.user_unique_id) != null ? _attrs_user_unique_id : ''),
|
|
852
|
+
status: (_parseString1 = parseString(attrs.status)) != null ? _parseString1 : 'active',
|
|
853
|
+
deviceType: parseString(attrs.device_type),
|
|
854
|
+
pushId: parseString(attrs.push_id),
|
|
855
|
+
osType: parseString(attrs.os_type),
|
|
856
|
+
defaultDevice: parseBoolean(attrs.default_device),
|
|
857
|
+
locationEnabled: parseBoolean(attrs.location_enabled),
|
|
858
|
+
notificationsEnabled: parseBoolean(attrs.notifications_enabled)
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
/**
|
|
863
|
+
* Mapper for TenantUser resources (not a standard REST resource)
|
|
864
|
+
*/ const tenantUserMapper = {
|
|
865
|
+
type: 'tenant_users',
|
|
866
|
+
map (resource, _included) {
|
|
867
|
+
var _resource_attributes;
|
|
868
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
869
|
+
var _attrs_gateway_url, _attrs_user_id, _attrs_user_unique_id, _attrs_tenant_id, _attrs_tenant_unique_id, _attrs_tenant_access_key, _attrs_tenant_url_id;
|
|
870
|
+
return {
|
|
871
|
+
gatewayUrl: String((_attrs_gateway_url = attrs.gateway_url) != null ? _attrs_gateway_url : ''),
|
|
872
|
+
userId: String((_attrs_user_id = attrs.user_id) != null ? _attrs_user_id : ''),
|
|
873
|
+
userUniqueId: String((_attrs_user_unique_id = attrs.user_unique_id) != null ? _attrs_user_unique_id : ''),
|
|
874
|
+
userEmail: parseString(attrs.user_email),
|
|
875
|
+
userName: parseString(attrs.user_name),
|
|
876
|
+
roleUniqueId: parseString(attrs.role_unique_id),
|
|
877
|
+
roleName: parseString(attrs.role_name),
|
|
878
|
+
roleId: parseString(attrs.role_id),
|
|
879
|
+
tenantId: String((_attrs_tenant_id = attrs.tenant_id) != null ? _attrs_tenant_id : ''),
|
|
880
|
+
tenantUniqueId: String((_attrs_tenant_unique_id = attrs.tenant_unique_id) != null ? _attrs_tenant_unique_id : ''),
|
|
881
|
+
tenantAccessKey: String((_attrs_tenant_access_key = attrs.tenant_access_key) != null ? _attrs_tenant_access_key : ''),
|
|
882
|
+
tenantUrlId: String((_attrs_tenant_url_id = attrs.tenant_url_id) != null ? _attrs_tenant_url_id : ''),
|
|
883
|
+
payload: attrs.payload,
|
|
884
|
+
onboardingCompleted: parseBoolean(attrs.onboarding_completed),
|
|
885
|
+
purchaseCompleted: parseBoolean(attrs.purchase_completed),
|
|
886
|
+
parentOnboardingCompleted: parseBoolean(attrs.parent_onboarding_completed),
|
|
887
|
+
parentPurchaseCompleted: parseBoolean(attrs.parent_purchase_completed)
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
};
|
|
891
|
+
/**
|
|
892
|
+
* Mapper for MailTemplate resources
|
|
893
|
+
*/ const mailTemplateMapper = {
|
|
894
|
+
type: 'mail_templates',
|
|
895
|
+
map (resource, _included) {
|
|
896
|
+
var _resource_attributes;
|
|
897
|
+
const attrs = (_resource_attributes = resource.attributes) != null ? _resource_attributes : {};
|
|
898
|
+
var _parseString, _parseDate, _parseDate1, _attrs_event_name, _attrs_name, _parseString1;
|
|
899
|
+
return {
|
|
900
|
+
id: resource.id,
|
|
901
|
+
uniqueId: (_parseString = parseString(attrs.unique_id)) != null ? _parseString : resource.id,
|
|
902
|
+
createdAt: (_parseDate = parseDate(attrs.created_at)) != null ? _parseDate : new Date(),
|
|
903
|
+
updatedAt: (_parseDate1 = parseDate(attrs.updated_at)) != null ? _parseDate1 : new Date(),
|
|
904
|
+
eventName: String((_attrs_event_name = attrs.event_name) != null ? _attrs_event_name : ''),
|
|
905
|
+
name: String((_attrs_name = attrs.name) != null ? _attrs_name : ''),
|
|
906
|
+
source: parseString(attrs.source),
|
|
907
|
+
sourceAlias: parseString(attrs.source_alias),
|
|
908
|
+
sourceId: parseString(attrs.source_id),
|
|
909
|
+
sourceType: parseString(attrs.source_type),
|
|
910
|
+
templateName: parseString(attrs.template_name),
|
|
911
|
+
templateHtml: parseString(attrs.template_html),
|
|
912
|
+
templateText: parseString(attrs.template_text),
|
|
913
|
+
fromDomain: parseString(attrs.from_domain),
|
|
914
|
+
fromAddress: parseString(attrs.from_address),
|
|
915
|
+
fromName: parseString(attrs.from_name),
|
|
916
|
+
fromSubject: parseString(attrs.from_subject),
|
|
917
|
+
payload: attrs.payload,
|
|
918
|
+
preferredLanguage: parseString(attrs.preferred_language),
|
|
919
|
+
status: (_parseString1 = parseString(attrs.status)) != null ? _parseString1 : 'active',
|
|
920
|
+
provider: parseString(attrs.provider)
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
|
|
925
|
+
/**
|
|
926
|
+
* Create the auth service
|
|
927
|
+
*/ function createAuthService(transport, _config) {
|
|
928
|
+
return {
|
|
929
|
+
async signIn (request) {
|
|
930
|
+
var _response_meta, _response_meta1, _response_meta2, _response_meta3;
|
|
931
|
+
const response = await transport.post('/auth/sign_in', {
|
|
932
|
+
email: request.email,
|
|
933
|
+
password: request.password
|
|
934
|
+
});
|
|
935
|
+
const user = decodeOne(response, userMapper);
|
|
936
|
+
var _response_meta_access_token, _ref;
|
|
937
|
+
return {
|
|
938
|
+
user,
|
|
939
|
+
accessToken: (_ref = (_response_meta_access_token = (_response_meta = response.meta) == null ? void 0 : _response_meta.access_token) != null ? _response_meta_access_token : (_response_meta1 = response.meta) == null ? void 0 : _response_meta1.token) != null ? _ref : '',
|
|
940
|
+
refreshToken: (_response_meta2 = response.meta) == null ? void 0 : _response_meta2.refresh_token,
|
|
941
|
+
tokenType: 'Bearer',
|
|
942
|
+
expiresIn: (_response_meta3 = response.meta) == null ? void 0 : _response_meta3.expires_in
|
|
943
|
+
};
|
|
944
|
+
},
|
|
945
|
+
async signUp (request) {
|
|
946
|
+
var _response_meta, _response_meta1, _response_meta2;
|
|
947
|
+
const response = await transport.post('/auth', {
|
|
948
|
+
email: request.email,
|
|
949
|
+
password: request.password,
|
|
950
|
+
password_confirmation: request.passwordConfirmation,
|
|
951
|
+
name: request.name,
|
|
952
|
+
username: request.username,
|
|
953
|
+
role_id: request.roleId
|
|
954
|
+
});
|
|
955
|
+
const user = decodeOne(response, userMapper);
|
|
956
|
+
var _response_meta_access_token;
|
|
957
|
+
return {
|
|
958
|
+
user,
|
|
959
|
+
accessToken: (_response_meta_access_token = (_response_meta = response.meta) == null ? void 0 : _response_meta.access_token) != null ? _response_meta_access_token : (_response_meta1 = response.meta) == null ? void 0 : _response_meta1.token,
|
|
960
|
+
message: (_response_meta2 = response.meta) == null ? void 0 : _response_meta2.message
|
|
961
|
+
};
|
|
962
|
+
},
|
|
963
|
+
async signOut () {
|
|
964
|
+
await transport.delete('/auth/sign_out');
|
|
965
|
+
},
|
|
966
|
+
async validateToken () {
|
|
967
|
+
const response = await transport.get('/auth/validate_token');
|
|
968
|
+
const user = decodeOne(response, userMapper);
|
|
969
|
+
return {
|
|
970
|
+
user,
|
|
971
|
+
valid: true
|
|
972
|
+
};
|
|
973
|
+
},
|
|
974
|
+
async getCurrentUser () {
|
|
975
|
+
const response = await transport.get('/auth/validate_token', {
|
|
976
|
+
params: {
|
|
977
|
+
include: 'role,user_avatar,user_profile'
|
|
978
|
+
}
|
|
979
|
+
});
|
|
980
|
+
return decodeOne(response, userMapper);
|
|
981
|
+
},
|
|
982
|
+
async requestPasswordReset (request) {
|
|
983
|
+
await transport.post('/auth/password', {
|
|
984
|
+
email: request.email,
|
|
985
|
+
redirect_url: request.redirectUrl
|
|
986
|
+
});
|
|
987
|
+
},
|
|
988
|
+
async updatePassword (request) {
|
|
989
|
+
await transport.put('/auth/password', {
|
|
990
|
+
password: request.password,
|
|
991
|
+
password_confirmation: request.passwordConfirmation,
|
|
992
|
+
reset_password_token: request.resetPasswordToken,
|
|
993
|
+
current_password: request.currentPassword
|
|
994
|
+
});
|
|
995
|
+
},
|
|
996
|
+
async refreshToken (request) {
|
|
997
|
+
const response = await transport.post('/auth/refresh', {
|
|
998
|
+
refresh_token: request.refreshToken
|
|
999
|
+
});
|
|
1000
|
+
return {
|
|
1001
|
+
accessToken: response.meta.access_token,
|
|
1002
|
+
refreshToken: response.meta.refresh_token,
|
|
1003
|
+
tokenType: 'Bearer',
|
|
1004
|
+
expiresIn: response.meta.expires_in
|
|
1005
|
+
};
|
|
1006
|
+
},
|
|
1007
|
+
async requestMagicLink (request) {
|
|
1008
|
+
await transport.post('/auth/magic_link', {
|
|
1009
|
+
email: request.email,
|
|
1010
|
+
redirect_url: request.redirectUrl
|
|
1011
|
+
});
|
|
1012
|
+
},
|
|
1013
|
+
async verifyMagicLink (request) {
|
|
1014
|
+
var _response_meta, _response_meta1, _response_meta2;
|
|
1015
|
+
const response = await transport.post('/auth/magic_link/verify', {
|
|
1016
|
+
token: request.token
|
|
1017
|
+
});
|
|
1018
|
+
const user = decodeOne(response, userMapper);
|
|
1019
|
+
var _response_meta_access_token;
|
|
1020
|
+
return {
|
|
1021
|
+
user,
|
|
1022
|
+
accessToken: (_response_meta_access_token = (_response_meta = response.meta) == null ? void 0 : _response_meta.access_token) != null ? _response_meta_access_token : '',
|
|
1023
|
+
refreshToken: (_response_meta1 = response.meta) == null ? void 0 : _response_meta1.refresh_token,
|
|
1024
|
+
tokenType: 'Bearer',
|
|
1025
|
+
expiresIn: (_response_meta2 = response.meta) == null ? void 0 : _response_meta2.expires_in
|
|
1026
|
+
};
|
|
1027
|
+
},
|
|
1028
|
+
async sendInvitation (request) {
|
|
1029
|
+
await transport.post('/auth/invitation', {
|
|
1030
|
+
email: request.email,
|
|
1031
|
+
role_id: request.roleId,
|
|
1032
|
+
redirect_url: request.redirectUrl
|
|
1033
|
+
});
|
|
1034
|
+
},
|
|
1035
|
+
async acceptInvitation (request) {
|
|
1036
|
+
var _response_meta, _response_meta1, _response_meta2;
|
|
1037
|
+
const response = await transport.put('/auth/invitation', {
|
|
1038
|
+
invitation_token: request.invitationToken,
|
|
1039
|
+
password: request.password,
|
|
1040
|
+
password_confirmation: request.passwordConfirmation,
|
|
1041
|
+
name: request.name
|
|
1042
|
+
});
|
|
1043
|
+
const user = decodeOne(response, userMapper);
|
|
1044
|
+
var _response_meta_access_token;
|
|
1045
|
+
return {
|
|
1046
|
+
user,
|
|
1047
|
+
accessToken: (_response_meta_access_token = (_response_meta = response.meta) == null ? void 0 : _response_meta.access_token) != null ? _response_meta_access_token : '',
|
|
1048
|
+
refreshToken: (_response_meta1 = response.meta) == null ? void 0 : _response_meta1.refresh_token,
|
|
1049
|
+
tokenType: 'Bearer',
|
|
1050
|
+
expiresIn: (_response_meta2 = response.meta) == null ? void 0 : _response_meta2.expires_in
|
|
1051
|
+
};
|
|
1052
|
+
},
|
|
1053
|
+
async confirmEmail (token) {
|
|
1054
|
+
const response = await transport.get('/auth/confirmation', {
|
|
1055
|
+
params: {
|
|
1056
|
+
confirmation_token: token
|
|
1057
|
+
}
|
|
1058
|
+
});
|
|
1059
|
+
return decodeOne(response, userMapper);
|
|
1060
|
+
},
|
|
1061
|
+
async resendConfirmation (email) {
|
|
1062
|
+
await transport.post('/auth/confirmation', {
|
|
1063
|
+
email
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
/**
|
|
1070
|
+
* Build filter params for list operations
|
|
1071
|
+
*/ function buildListParams$4(params) {
|
|
1072
|
+
if (!params) return {};
|
|
1073
|
+
const queryParams = {};
|
|
1074
|
+
if (params.page) {
|
|
1075
|
+
queryParams['page[number]'] = params.page;
|
|
1076
|
+
}
|
|
1077
|
+
if (params.perPage) {
|
|
1078
|
+
queryParams['page[size]'] = params.perPage;
|
|
1079
|
+
}
|
|
1080
|
+
if (params.sort) {
|
|
1081
|
+
const sorts = Array.isArray(params.sort) ? params.sort : [
|
|
1082
|
+
params.sort
|
|
1083
|
+
];
|
|
1084
|
+
queryParams['sort'] = sorts.map((s)=>s.direction === 'desc' ? `-${s.field}` : s.field).join(',');
|
|
1085
|
+
}
|
|
1086
|
+
if (params.filter) {
|
|
1087
|
+
for (const [key, value] of Object.entries(params.filter)){
|
|
1088
|
+
queryParams[`filter[${key}]`] = value;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
if (params.include) {
|
|
1092
|
+
queryParams['include'] = params.include.join(',');
|
|
1093
|
+
}
|
|
1094
|
+
return queryParams;
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Create the users service
|
|
1098
|
+
*/ function createUsersService(transport, _config) {
|
|
1099
|
+
return {
|
|
1100
|
+
async list (params) {
|
|
1101
|
+
const response = await transport.get('/users', {
|
|
1102
|
+
params: buildListParams$4(params)
|
|
1103
|
+
});
|
|
1104
|
+
return decodePageResult(response, userMapper);
|
|
1105
|
+
},
|
|
1106
|
+
async get (id) {
|
|
1107
|
+
const response = await transport.get(`/users/${id}`, {
|
|
1108
|
+
params: {
|
|
1109
|
+
include: 'role,user_avatar,user_profile'
|
|
1110
|
+
}
|
|
1111
|
+
});
|
|
1112
|
+
return decodeOne(response, userMapper);
|
|
1113
|
+
},
|
|
1114
|
+
async getByUniqueId (uniqueId) {
|
|
1115
|
+
const response = await transport.get(`/users/by_unique_id/${uniqueId}`, {
|
|
1116
|
+
params: {
|
|
1117
|
+
include: 'role,user_avatar,user_profile'
|
|
1118
|
+
}
|
|
1119
|
+
});
|
|
1120
|
+
return decodeOne(response, userMapper);
|
|
1121
|
+
},
|
|
1122
|
+
async update (id, request) {
|
|
1123
|
+
const response = await transport.patch(`/users/${id}`, {
|
|
1124
|
+
name: request.name,
|
|
1125
|
+
username: request.username,
|
|
1126
|
+
nickname: request.nickname,
|
|
1127
|
+
bio: request.bio,
|
|
1128
|
+
role_id: request.roleId,
|
|
1129
|
+
status: request.status
|
|
1130
|
+
});
|
|
1131
|
+
return decodeOne(response, userMapper);
|
|
1132
|
+
},
|
|
1133
|
+
async updateProfile (userId, request) {
|
|
1134
|
+
const response = await transport.patch(`/users/${userId}/profile`, {
|
|
1135
|
+
first_name: request.firstName,
|
|
1136
|
+
middle_name: request.middleName,
|
|
1137
|
+
last_name: request.lastName,
|
|
1138
|
+
gender: request.gender,
|
|
1139
|
+
zipcode: request.zipcode,
|
|
1140
|
+
phone_number: request.phoneNumber,
|
|
1141
|
+
preferred_language: request.preferredLanguage,
|
|
1142
|
+
time_zone: request.timeZone,
|
|
1143
|
+
web_site: request.webSite,
|
|
1144
|
+
twitter: request.twitter,
|
|
1145
|
+
fb: request.fb,
|
|
1146
|
+
instagram: request.instagram,
|
|
1147
|
+
linkedin: request.linkedin,
|
|
1148
|
+
youtube: request.youtube,
|
|
1149
|
+
blog: request.blog,
|
|
1150
|
+
payload: request.payload
|
|
1151
|
+
});
|
|
1152
|
+
return decodeOne(response, userMapper);
|
|
1153
|
+
},
|
|
1154
|
+
async delete (id) {
|
|
1155
|
+
await transport.delete(`/users/${id}`);
|
|
1156
|
+
},
|
|
1157
|
+
async activate (id) {
|
|
1158
|
+
const response = await transport.post(`/users/${id}/activate`);
|
|
1159
|
+
return decodeOne(response, userMapper);
|
|
1160
|
+
},
|
|
1161
|
+
async deactivate (id) {
|
|
1162
|
+
const response = await transport.post(`/users/${id}/deactivate`);
|
|
1163
|
+
return decodeOne(response, userMapper);
|
|
1164
|
+
},
|
|
1165
|
+
async changeRole (id, roleId) {
|
|
1166
|
+
const response = await transport.patch(`/users/${id}/role`, {
|
|
1167
|
+
role_id: roleId
|
|
1168
|
+
});
|
|
1169
|
+
return decodeOne(response, userMapper);
|
|
1170
|
+
},
|
|
1171
|
+
async search (query, params) {
|
|
1172
|
+
const queryParams = buildListParams$4(params);
|
|
1173
|
+
queryParams['q'] = query;
|
|
1174
|
+
const response = await transport.get('/users/search', {
|
|
1175
|
+
params: queryParams
|
|
1176
|
+
});
|
|
1177
|
+
return decodePageResult(response, userMapper);
|
|
1178
|
+
}
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
/**
|
|
1183
|
+
* Create the roles service
|
|
1184
|
+
*/ function createRolesService(transport, _config) {
|
|
1185
|
+
return {
|
|
1186
|
+
async list (params) {
|
|
1187
|
+
const queryParams = {};
|
|
1188
|
+
if (params == null ? void 0 : params.page) queryParams['page[number]'] = params.page;
|
|
1189
|
+
if (params == null ? void 0 : params.perPage) queryParams['page[size]'] = params.perPage;
|
|
1190
|
+
if (params == null ? void 0 : params.include) queryParams['include'] = params.include.join(',');
|
|
1191
|
+
const response = await transport.get('/roles', {
|
|
1192
|
+
params: queryParams
|
|
1193
|
+
});
|
|
1194
|
+
return decodePageResult(response, roleMapper);
|
|
1195
|
+
},
|
|
1196
|
+
async get (id) {
|
|
1197
|
+
const response = await transport.get(`/roles/${id}`, {
|
|
1198
|
+
params: {
|
|
1199
|
+
include: 'permissions'
|
|
1200
|
+
}
|
|
1201
|
+
});
|
|
1202
|
+
return decodeOne(response, roleMapper);
|
|
1203
|
+
},
|
|
1204
|
+
async getByCode (code) {
|
|
1205
|
+
const response = await transport.get(`/roles/by_code/${code}`, {
|
|
1206
|
+
params: {
|
|
1207
|
+
include: 'permissions'
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
return decodeOne(response, roleMapper);
|
|
1211
|
+
},
|
|
1212
|
+
async create (request) {
|
|
1213
|
+
const response = await transport.post('/roles', {
|
|
1214
|
+
name: request.name,
|
|
1215
|
+
code: request.code,
|
|
1216
|
+
description: request.description,
|
|
1217
|
+
payload: request.payload,
|
|
1218
|
+
on_boarding_unique_id: request.onBoardingUniqueId,
|
|
1219
|
+
on_boarding_url: request.onBoardingUrl,
|
|
1220
|
+
on_boarding_payload: request.onBoardingPayload
|
|
1221
|
+
});
|
|
1222
|
+
return decodeOne(response, roleMapper);
|
|
1223
|
+
},
|
|
1224
|
+
async update (id, request) {
|
|
1225
|
+
const response = await transport.patch(`/roles/${id}`, {
|
|
1226
|
+
name: request.name,
|
|
1227
|
+
code: request.code,
|
|
1228
|
+
description: request.description,
|
|
1229
|
+
status: request.status,
|
|
1230
|
+
payload: request.payload,
|
|
1231
|
+
on_boarding_unique_id: request.onBoardingUniqueId,
|
|
1232
|
+
on_boarding_url: request.onBoardingUrl,
|
|
1233
|
+
on_boarding_payload: request.onBoardingPayload
|
|
1234
|
+
});
|
|
1235
|
+
return decodeOne(response, roleMapper);
|
|
1236
|
+
},
|
|
1237
|
+
async delete (id) {
|
|
1238
|
+
await transport.delete(`/roles/${id}`);
|
|
1239
|
+
},
|
|
1240
|
+
async getPermissions (roleId) {
|
|
1241
|
+
const response = await transport.get(`/roles/${roleId}/permissions`);
|
|
1242
|
+
return decodeMany(response, permissionMapper);
|
|
1243
|
+
},
|
|
1244
|
+
async setPermissions (roleId, permissionIds) {
|
|
1245
|
+
const response = await transport.put(`/roles/${roleId}/permissions`, {
|
|
1246
|
+
permission_ids: permissionIds
|
|
1247
|
+
});
|
|
1248
|
+
return decodeOne(response, roleMapper);
|
|
1249
|
+
},
|
|
1250
|
+
async addPermission (roleId, permissionId) {
|
|
1251
|
+
const response = await transport.post(`/roles/${roleId}/permissions/${permissionId}`);
|
|
1252
|
+
return decodeOne(response, roleMapper);
|
|
1253
|
+
},
|
|
1254
|
+
async removePermission (roleId, permissionId) {
|
|
1255
|
+
const response = await transport.delete(`/roles/${roleId}/permissions/${permissionId}`);
|
|
1256
|
+
return decodeOne(response, roleMapper);
|
|
1257
|
+
},
|
|
1258
|
+
async listPermissions (params) {
|
|
1259
|
+
const queryParams = {};
|
|
1260
|
+
if (params == null ? void 0 : params.page) queryParams['page[number]'] = params.page;
|
|
1261
|
+
if (params == null ? void 0 : params.perPage) queryParams['page[size]'] = params.perPage;
|
|
1262
|
+
const response = await transport.get('/permissions', {
|
|
1263
|
+
params: queryParams
|
|
1264
|
+
});
|
|
1265
|
+
return decodePageResult(response, permissionMapper);
|
|
1266
|
+
}
|
|
1267
|
+
};
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
/**
|
|
1271
|
+
* Create the API keys service
|
|
1272
|
+
*/ function createApiKeysService(transport, _config) {
|
|
1273
|
+
return {
|
|
1274
|
+
async list (params) {
|
|
1275
|
+
const queryParams = {};
|
|
1276
|
+
if (params == null ? void 0 : params.page) queryParams['page[number]'] = params.page;
|
|
1277
|
+
if (params == null ? void 0 : params.perPage) queryParams['page[size]'] = params.perPage;
|
|
1278
|
+
if (params == null ? void 0 : params.filter) {
|
|
1279
|
+
for (const [key, value] of Object.entries(params.filter)){
|
|
1280
|
+
queryParams[`filter[${key}]`] = value;
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
const response = await transport.get('/api_keys', {
|
|
1284
|
+
params: queryParams
|
|
1285
|
+
});
|
|
1286
|
+
return decodePageResult(response, apiKeyMapper);
|
|
1287
|
+
},
|
|
1288
|
+
async get (id) {
|
|
1289
|
+
const response = await transport.get(`/api_keys/${id}`);
|
|
1290
|
+
return decodeOne(response, apiKeyMapper);
|
|
1291
|
+
},
|
|
1292
|
+
async getByKeyId (keyId) {
|
|
1293
|
+
const response = await transport.get(`/api_keys/by_key_id/${keyId}`);
|
|
1294
|
+
return decodeOne(response, apiKeyMapper);
|
|
1295
|
+
},
|
|
1296
|
+
async create (request) {
|
|
1297
|
+
const response = await transport.post('/api_keys', {
|
|
1298
|
+
name: request.name,
|
|
1299
|
+
description: request.description,
|
|
1300
|
+
service_account: request.serviceAccount,
|
|
1301
|
+
scopes: request.scopes,
|
|
1302
|
+
expires_at: request.expiresAt,
|
|
1303
|
+
rate_limit_per_minute: request.rateLimitPerMinute,
|
|
1304
|
+
rate_limit_per_hour: request.rateLimitPerHour,
|
|
1305
|
+
rate_limit_per_day: request.rateLimitPerDay,
|
|
1306
|
+
allowed_origins: request.allowedOrigins,
|
|
1307
|
+
allowed_ips: request.allowedIps,
|
|
1308
|
+
payload: request.payload
|
|
1309
|
+
});
|
|
1310
|
+
return decodeOne(response, apiKeyWithSecretMapper);
|
|
1311
|
+
},
|
|
1312
|
+
async update (id, request) {
|
|
1313
|
+
const response = await transport.patch(`/api_keys/${id}`, {
|
|
1314
|
+
name: request.name,
|
|
1315
|
+
description: request.description,
|
|
1316
|
+
scopes: request.scopes,
|
|
1317
|
+
rate_limit_per_minute: request.rateLimitPerMinute,
|
|
1318
|
+
rate_limit_per_hour: request.rateLimitPerHour,
|
|
1319
|
+
rate_limit_per_day: request.rateLimitPerDay,
|
|
1320
|
+
allowed_origins: request.allowedOrigins,
|
|
1321
|
+
allowed_ips: request.allowedIps,
|
|
1322
|
+
payload: request.payload
|
|
1323
|
+
});
|
|
1324
|
+
return decodeOne(response, apiKeyMapper);
|
|
1325
|
+
},
|
|
1326
|
+
async regenerate (id) {
|
|
1327
|
+
const response = await transport.post(`/api_keys/${id}/regenerate`);
|
|
1328
|
+
return decodeOne(response, apiKeyWithSecretMapper);
|
|
1329
|
+
},
|
|
1330
|
+
async revoke (id, request) {
|
|
1331
|
+
const response = await transport.post(`/api_keys/${id}/revoke`, {
|
|
1332
|
+
reason: request == null ? void 0 : request.reason
|
|
1333
|
+
});
|
|
1334
|
+
return decodeOne(response, apiKeyMapper);
|
|
1335
|
+
},
|
|
1336
|
+
async delete (id) {
|
|
1337
|
+
await transport.delete(`/api_keys/${id}`);
|
|
1338
|
+
},
|
|
1339
|
+
async getUsage (id, period = 'week') {
|
|
1340
|
+
const response = await transport.get(`/api_keys/${id}/usage`, {
|
|
1341
|
+
params: {
|
|
1342
|
+
period
|
|
1343
|
+
}
|
|
1344
|
+
});
|
|
1345
|
+
const attrs = response.data.attributes;
|
|
1346
|
+
return {
|
|
1347
|
+
apiKeyId: attrs.api_key_id,
|
|
1348
|
+
period: attrs.period,
|
|
1349
|
+
totalRequests: attrs.total_requests,
|
|
1350
|
+
successfulRequests: attrs.successful_requests,
|
|
1351
|
+
failedRequests: attrs.failed_requests,
|
|
1352
|
+
averageLatency: attrs.average_latency,
|
|
1353
|
+
requestsByEndpoint: attrs.requests_by_endpoint,
|
|
1354
|
+
requestsByDay: attrs.requests_by_day
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
};
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
/**
|
|
1361
|
+
* Build filter params for list operations
|
|
1362
|
+
*/ function buildListParams$3(params) {
|
|
1363
|
+
if (!params) return {};
|
|
1364
|
+
const queryParams = {};
|
|
1365
|
+
if (params.page) {
|
|
1366
|
+
queryParams['page[number]'] = params.page;
|
|
1367
|
+
}
|
|
1368
|
+
if (params.perPage) {
|
|
1369
|
+
queryParams['page[size]'] = params.perPage;
|
|
1370
|
+
}
|
|
1371
|
+
if (params.sort) {
|
|
1372
|
+
const sorts = Array.isArray(params.sort) ? params.sort : [
|
|
1373
|
+
params.sort
|
|
1374
|
+
];
|
|
1375
|
+
queryParams['sort'] = sorts.map((s)=>s.direction === 'desc' ? `-${s.field}` : s.field).join(',');
|
|
1376
|
+
}
|
|
1377
|
+
if (params.filter) {
|
|
1378
|
+
for (const [key, value] of Object.entries(params.filter)){
|
|
1379
|
+
queryParams[`filter[${key}]`] = value;
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
if (params.include) {
|
|
1383
|
+
queryParams['include'] = params.include.join(',');
|
|
1384
|
+
}
|
|
1385
|
+
return queryParams;
|
|
1386
|
+
}
|
|
1387
|
+
/**
|
|
1388
|
+
* Create the apps service
|
|
1389
|
+
*/ function createAppsService(transport, _config) {
|
|
1390
|
+
return {
|
|
1391
|
+
async list (params) {
|
|
1392
|
+
const response = await transport.get('/apps', {
|
|
1393
|
+
params: buildListParams$3(params)
|
|
1394
|
+
});
|
|
1395
|
+
return decodePageResult(response, appMapper);
|
|
1396
|
+
},
|
|
1397
|
+
async get (id) {
|
|
1398
|
+
const response = await transport.get(`/apps/${id}`);
|
|
1399
|
+
return decodeOne(response, appMapper);
|
|
1400
|
+
},
|
|
1401
|
+
async create (request) {
|
|
1402
|
+
const response = await transport.post('/apps', {
|
|
1403
|
+
name: request.name,
|
|
1404
|
+
description: request.description,
|
|
1405
|
+
app_type: request.appType,
|
|
1406
|
+
oauth_enabled: request.oauthEnabled,
|
|
1407
|
+
oauth_access_token_lifetime_hours: request.oauthAccessTokenLifetimeHours,
|
|
1408
|
+
oauth_refresh_token_lifetime_days: request.oauthRefreshTokenLifetimeDays,
|
|
1409
|
+
rate_limit_per_minute: request.rateLimitPerMinute,
|
|
1410
|
+
rate_limit_per_hour: request.rateLimitPerHour,
|
|
1411
|
+
webhook_url: request.webhookUrl,
|
|
1412
|
+
allowed_origins: request.allowedOrigins,
|
|
1413
|
+
metadata: request.metadata
|
|
1414
|
+
});
|
|
1415
|
+
return decodeOne(response, appMapper);
|
|
1416
|
+
},
|
|
1417
|
+
async update (id, request) {
|
|
1418
|
+
const response = await transport.patch(`/apps/${id}`, {
|
|
1419
|
+
name: request.name,
|
|
1420
|
+
description: request.description,
|
|
1421
|
+
app_type: request.appType,
|
|
1422
|
+
oauth_enabled: request.oauthEnabled,
|
|
1423
|
+
oauth_access_token_lifetime_hours: request.oauthAccessTokenLifetimeHours,
|
|
1424
|
+
oauth_refresh_token_lifetime_days: request.oauthRefreshTokenLifetimeDays,
|
|
1425
|
+
rate_limit_per_minute: request.rateLimitPerMinute,
|
|
1426
|
+
rate_limit_per_hour: request.rateLimitPerHour,
|
|
1427
|
+
webhook_url: request.webhookUrl,
|
|
1428
|
+
allowed_origins: request.allowedOrigins,
|
|
1429
|
+
metadata: request.metadata,
|
|
1430
|
+
status: request.status
|
|
1431
|
+
});
|
|
1432
|
+
return decodeOne(response, appMapper);
|
|
1433
|
+
},
|
|
1434
|
+
async delete (id) {
|
|
1435
|
+
await transport.delete(`/apps/${id}`);
|
|
1436
|
+
},
|
|
1437
|
+
async regenerateWebhookSecret (id) {
|
|
1438
|
+
const response = await transport.post(`/apps/${id}/regenerate_webhook_secret`);
|
|
1439
|
+
return decodeOne(response, appMapper);
|
|
1440
|
+
}
|
|
1441
|
+
};
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* Create the blocks service
|
|
1445
|
+
*/ function createBlocksService(transport, _config) {
|
|
1446
|
+
return {
|
|
1447
|
+
async list (companyId, params) {
|
|
1448
|
+
const queryParams = buildListParams$3(params);
|
|
1449
|
+
queryParams['filter[company_unique_id]'] = companyId;
|
|
1450
|
+
const response = await transport.get('/blocks', {
|
|
1451
|
+
params: queryParams
|
|
1452
|
+
});
|
|
1453
|
+
return decodePageResult(response, blockMapper);
|
|
1454
|
+
},
|
|
1455
|
+
async get (id) {
|
|
1456
|
+
const response = await transport.get(`/blocks/${id}`);
|
|
1457
|
+
return decodeOne(response, blockMapper);
|
|
1458
|
+
},
|
|
1459
|
+
async add (companyId, blockCode) {
|
|
1460
|
+
const response = await transport.post('/blocks', {
|
|
1461
|
+
company_unique_id: companyId,
|
|
1462
|
+
block_code: blockCode
|
|
1463
|
+
});
|
|
1464
|
+
return decodeOne(response, blockMapper);
|
|
1465
|
+
},
|
|
1466
|
+
async remove (id) {
|
|
1467
|
+
await transport.delete(`/blocks/${id}`);
|
|
1468
|
+
}
|
|
1469
|
+
};
|
|
1470
|
+
}
|
|
1471
|
+
/**
|
|
1472
|
+
* Create the services registry service
|
|
1473
|
+
*/ function createServicesRegistryService(transport, _config) {
|
|
1474
|
+
return {
|
|
1475
|
+
async list (params) {
|
|
1476
|
+
const response = await transport.get('/services', {
|
|
1477
|
+
params: buildListParams$3(params)
|
|
1478
|
+
});
|
|
1479
|
+
return decodePageResult(response, serviceMapper);
|
|
1480
|
+
},
|
|
1481
|
+
async get (id) {
|
|
1482
|
+
const response = await transport.get(`/services/${id}`);
|
|
1483
|
+
return decodeOne(response, serviceMapper);
|
|
1484
|
+
},
|
|
1485
|
+
async getByCode (code) {
|
|
1486
|
+
const response = await transport.get(`/services/by_code/${code}`);
|
|
1487
|
+
return decodeOne(response, serviceMapper);
|
|
1488
|
+
},
|
|
1489
|
+
async healthCheck () {
|
|
1490
|
+
const response = await transport.get('/services/health');
|
|
1491
|
+
return decodeMany(response, serviceMapper);
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
/**
|
|
1497
|
+
* Build filter params for list operations
|
|
1498
|
+
*/ function buildListParams$2(params) {
|
|
1499
|
+
if (!params) return {};
|
|
1500
|
+
const queryParams = {};
|
|
1501
|
+
if (params.page) {
|
|
1502
|
+
queryParams['page[number]'] = params.page;
|
|
1503
|
+
}
|
|
1504
|
+
if (params.perPage) {
|
|
1505
|
+
queryParams['page[size]'] = params.perPage;
|
|
1506
|
+
}
|
|
1507
|
+
if (params.sort) {
|
|
1508
|
+
const sorts = Array.isArray(params.sort) ? params.sort : [
|
|
1509
|
+
params.sort
|
|
1510
|
+
];
|
|
1511
|
+
queryParams['sort'] = sorts.map((s)=>s.direction === 'desc' ? `-${s.field}` : s.field).join(',');
|
|
1512
|
+
}
|
|
1513
|
+
if (params.filter) {
|
|
1514
|
+
for (const [key, value] of Object.entries(params.filter)){
|
|
1515
|
+
queryParams[`filter[${key}]`] = value;
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
if (params.include) {
|
|
1519
|
+
queryParams['include'] = params.include.join(',');
|
|
1520
|
+
}
|
|
1521
|
+
return queryParams;
|
|
1522
|
+
}
|
|
1523
|
+
/**
|
|
1524
|
+
* Create the subscription models service
|
|
1525
|
+
*/ function createSubscriptionModelsService(transport, _config) {
|
|
1526
|
+
return {
|
|
1527
|
+
async list (params) {
|
|
1528
|
+
const response = await transport.get('/subscription_models', {
|
|
1529
|
+
params: buildListParams$2(params)
|
|
1530
|
+
});
|
|
1531
|
+
return decodePageResult(response, subscriptionModelMapper);
|
|
1532
|
+
},
|
|
1533
|
+
async get (id) {
|
|
1534
|
+
const response = await transport.get(`/subscription_models/${id}`);
|
|
1535
|
+
return decodeOne(response, subscriptionModelMapper);
|
|
1536
|
+
},
|
|
1537
|
+
async getByCode (code) {
|
|
1538
|
+
const response = await transport.get(`/subscription_models/by_code/${code}`);
|
|
1539
|
+
return decodeOne(response, subscriptionModelMapper);
|
|
1540
|
+
},
|
|
1541
|
+
async promotional () {
|
|
1542
|
+
const response = await transport.get('/subscription_models/promotional');
|
|
1543
|
+
return decodeMany(response, subscriptionModelMapper);
|
|
1544
|
+
}
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1547
|
+
/**
|
|
1548
|
+
* Create the user subscriptions service
|
|
1549
|
+
*/ function createUserSubscriptionsService(transport, _config) {
|
|
1550
|
+
return {
|
|
1551
|
+
async list (params) {
|
|
1552
|
+
const response = await transport.get('/user_subscriptions', {
|
|
1553
|
+
params: _({}, buildListParams$2(params), {
|
|
1554
|
+
include: 'subscription_model'
|
|
1555
|
+
})
|
|
1556
|
+
});
|
|
1557
|
+
return decodePageResult(response, userSubscriptionMapper);
|
|
1558
|
+
},
|
|
1559
|
+
async get (id) {
|
|
1560
|
+
const response = await transport.get(`/user_subscriptions/${id}`, {
|
|
1561
|
+
params: {
|
|
1562
|
+
include: 'subscription_model'
|
|
1563
|
+
}
|
|
1564
|
+
});
|
|
1565
|
+
return decodeOne(response, userSubscriptionMapper);
|
|
1566
|
+
},
|
|
1567
|
+
async forUser (userUniqueId) {
|
|
1568
|
+
const response = await transport.get(`/users/${userUniqueId}/subscriptions`, {
|
|
1569
|
+
params: {
|
|
1570
|
+
include: 'subscription_model'
|
|
1571
|
+
}
|
|
1572
|
+
});
|
|
1573
|
+
return decodeMany(response, userSubscriptionMapper);
|
|
1574
|
+
},
|
|
1575
|
+
async subscribe (userUniqueId, request) {
|
|
1576
|
+
const response = await transport.post(`/users/${userUniqueId}/subscriptions`, {
|
|
1577
|
+
subscription_model_code: request.subscriptionModelCode,
|
|
1578
|
+
initial_payment: request.initialPayment
|
|
1579
|
+
});
|
|
1580
|
+
return decodeOne(response, userSubscriptionMapper);
|
|
1581
|
+
},
|
|
1582
|
+
async cancel (id) {
|
|
1583
|
+
const response = await transport.post(`/user_subscriptions/${id}/cancel`);
|
|
1584
|
+
return decodeOne(response, userSubscriptionMapper);
|
|
1585
|
+
},
|
|
1586
|
+
async reactivate (id) {
|
|
1587
|
+
const response = await transport.post(`/user_subscriptions/${id}/reactivate`);
|
|
1588
|
+
return decodeOne(response, userSubscriptionMapper);
|
|
1589
|
+
}
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
/**
|
|
1593
|
+
* Create the company subscriptions service
|
|
1594
|
+
*/ function createCompanySubscriptionsService(transport, _config) {
|
|
1595
|
+
return {
|
|
1596
|
+
async list (params) {
|
|
1597
|
+
const response = await transport.get('/company_subscriptions', {
|
|
1598
|
+
params: _({}, buildListParams$2(params), {
|
|
1599
|
+
include: 'subscription_model'
|
|
1600
|
+
})
|
|
1601
|
+
});
|
|
1602
|
+
return decodePageResult(response, companySubscriptionMapper);
|
|
1603
|
+
},
|
|
1604
|
+
async get (id) {
|
|
1605
|
+
const response = await transport.get(`/company_subscriptions/${id}`, {
|
|
1606
|
+
params: {
|
|
1607
|
+
include: 'subscription_model'
|
|
1608
|
+
}
|
|
1609
|
+
});
|
|
1610
|
+
return decodeOne(response, companySubscriptionMapper);
|
|
1611
|
+
},
|
|
1612
|
+
async forCompany (companyUniqueId) {
|
|
1613
|
+
const response = await transport.get(`/companies/${companyUniqueId}/subscriptions`, {
|
|
1614
|
+
params: {
|
|
1615
|
+
include: 'subscription_model'
|
|
1616
|
+
}
|
|
1617
|
+
});
|
|
1618
|
+
return decodeMany(response, companySubscriptionMapper);
|
|
1619
|
+
},
|
|
1620
|
+
async subscribe (companyUniqueId, request) {
|
|
1621
|
+
const response = await transport.post(`/companies/${companyUniqueId}/subscriptions`, {
|
|
1622
|
+
subscription_model_code: request.subscriptionModelCode,
|
|
1623
|
+
initial_payment: request.initialPayment
|
|
1624
|
+
});
|
|
1625
|
+
return decodeOne(response, companySubscriptionMapper);
|
|
1626
|
+
},
|
|
1627
|
+
async cancel (id) {
|
|
1628
|
+
const response = await transport.post(`/company_subscriptions/${id}/cancel`);
|
|
1629
|
+
return decodeOne(response, companySubscriptionMapper);
|
|
1630
|
+
},
|
|
1631
|
+
async reactivate (id) {
|
|
1632
|
+
const response = await transport.post(`/company_subscriptions/${id}/reactivate`);
|
|
1633
|
+
return decodeOne(response, companySubscriptionMapper);
|
|
1634
|
+
}
|
|
1635
|
+
};
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
/**
|
|
1639
|
+
* Build filter params for list operations
|
|
1640
|
+
*/ function buildListParams$1(params) {
|
|
1641
|
+
if (!params) return {};
|
|
1642
|
+
const queryParams = {};
|
|
1643
|
+
if (params.page) {
|
|
1644
|
+
queryParams['page[number]'] = params.page;
|
|
1645
|
+
}
|
|
1646
|
+
if (params.perPage) {
|
|
1647
|
+
queryParams['page[size]'] = params.perPage;
|
|
1648
|
+
}
|
|
1649
|
+
if (params.sort) {
|
|
1650
|
+
const sorts = Array.isArray(params.sort) ? params.sort : [
|
|
1651
|
+
params.sort
|
|
1652
|
+
];
|
|
1653
|
+
queryParams['sort'] = sorts.map((s)=>s.direction === 'desc' ? `-${s.field}` : s.field).join(',');
|
|
1654
|
+
}
|
|
1655
|
+
if (params.filter) {
|
|
1656
|
+
for (const [key, value] of Object.entries(params.filter)){
|
|
1657
|
+
queryParams[`filter[${key}]`] = value;
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
if (params.include) {
|
|
1661
|
+
queryParams['include'] = params.include.join(',');
|
|
1662
|
+
}
|
|
1663
|
+
return queryParams;
|
|
1664
|
+
}
|
|
1665
|
+
/**
|
|
1666
|
+
* Create the countries service
|
|
1667
|
+
*/ function createCountriesService(transport, _config) {
|
|
1668
|
+
return {
|
|
1669
|
+
async list (params) {
|
|
1670
|
+
const response = await transport.get('/countries', {
|
|
1671
|
+
params: buildListParams$1(params)
|
|
1672
|
+
});
|
|
1673
|
+
return decodePageResult(response, countryMapper);
|
|
1674
|
+
},
|
|
1675
|
+
async get (id) {
|
|
1676
|
+
const response = await transport.get(`/countries/${id}`);
|
|
1677
|
+
return decodeOne(response, countryMapper);
|
|
1678
|
+
},
|
|
1679
|
+
async getByIsoCode (isoCode) {
|
|
1680
|
+
const response = await transport.get(`/countries/by_iso_code/${isoCode}`);
|
|
1681
|
+
return decodeOne(response, countryMapper);
|
|
1682
|
+
},
|
|
1683
|
+
async all () {
|
|
1684
|
+
const response = await transport.get('/countries/all');
|
|
1685
|
+
return decodeMany(response, countryMapper);
|
|
1686
|
+
}
|
|
1687
|
+
};
|
|
1688
|
+
}
|
|
1689
|
+
/**
|
|
1690
|
+
* Create the states service
|
|
1691
|
+
*/ function createStatesService(transport, _config) {
|
|
1692
|
+
return {
|
|
1693
|
+
async list (params) {
|
|
1694
|
+
const response = await transport.get('/states', {
|
|
1695
|
+
params: buildListParams$1(params)
|
|
1696
|
+
});
|
|
1697
|
+
return decodePageResult(response, stateMapper);
|
|
1698
|
+
},
|
|
1699
|
+
async get (id) {
|
|
1700
|
+
const response = await transport.get(`/states/${id}`);
|
|
1701
|
+
return decodeOne(response, stateMapper);
|
|
1702
|
+
},
|
|
1703
|
+
async forCountry (countryId) {
|
|
1704
|
+
const response = await transport.get(`/countries/${countryId}/states`);
|
|
1705
|
+
return decodeMany(response, stateMapper);
|
|
1706
|
+
}
|
|
1707
|
+
};
|
|
1708
|
+
}
|
|
1709
|
+
/**
|
|
1710
|
+
* Create the counties service
|
|
1711
|
+
*/ function createCountiesService(transport, _config) {
|
|
1712
|
+
return {
|
|
1713
|
+
async list (params) {
|
|
1714
|
+
const response = await transport.get('/counties', {
|
|
1715
|
+
params: buildListParams$1(params)
|
|
1716
|
+
});
|
|
1717
|
+
return decodePageResult(response, countyMapper);
|
|
1718
|
+
},
|
|
1719
|
+
async get (id) {
|
|
1720
|
+
const response = await transport.get(`/counties/${id}`);
|
|
1721
|
+
return decodeOne(response, countyMapper);
|
|
1722
|
+
},
|
|
1723
|
+
async forState (stateId) {
|
|
1724
|
+
const response = await transport.get(`/states/${stateId}/counties`);
|
|
1725
|
+
return decodeMany(response, countyMapper);
|
|
1726
|
+
}
|
|
1727
|
+
};
|
|
1728
|
+
}
|
|
1729
|
+
/**
|
|
1730
|
+
* Create the cities service
|
|
1731
|
+
*/ function createCitiesService(transport, _config) {
|
|
1732
|
+
return {
|
|
1733
|
+
async list (params) {
|
|
1734
|
+
const response = await transport.get('/cities', {
|
|
1735
|
+
params: buildListParams$1(params)
|
|
1736
|
+
});
|
|
1737
|
+
return decodePageResult(response, cityMapper);
|
|
1738
|
+
},
|
|
1739
|
+
async get (id) {
|
|
1740
|
+
const response = await transport.get(`/cities/${id}`);
|
|
1741
|
+
return decodeOne(response, cityMapper);
|
|
1742
|
+
},
|
|
1743
|
+
async forState (stateId) {
|
|
1744
|
+
const response = await transport.get(`/states/${stateId}/cities`);
|
|
1745
|
+
return decodeMany(response, cityMapper);
|
|
1746
|
+
},
|
|
1747
|
+
async forCounty (countyId) {
|
|
1748
|
+
const response = await transport.get(`/counties/${countyId}/cities`);
|
|
1749
|
+
return decodeMany(response, cityMapper);
|
|
1750
|
+
},
|
|
1751
|
+
async search (query, params) {
|
|
1752
|
+
const queryParams = buildListParams$1(params);
|
|
1753
|
+
queryParams['q'] = query;
|
|
1754
|
+
const response = await transport.get('/cities/search', {
|
|
1755
|
+
params: queryParams
|
|
1756
|
+
});
|
|
1757
|
+
return decodePageResult(response, cityMapper);
|
|
1758
|
+
}
|
|
1759
|
+
};
|
|
1760
|
+
}
|
|
1761
|
+
/**
|
|
1762
|
+
* Create the currencies service
|
|
1763
|
+
*/ function createCurrenciesService(transport, _config) {
|
|
1764
|
+
return {
|
|
1765
|
+
async list (params) {
|
|
1766
|
+
const response = await transport.get('/currencies', {
|
|
1767
|
+
params: buildListParams$1(params)
|
|
1768
|
+
});
|
|
1769
|
+
return decodePageResult(response, currencyMapper);
|
|
1770
|
+
},
|
|
1771
|
+
async get (id) {
|
|
1772
|
+
const response = await transport.get(`/currencies/${id}`);
|
|
1773
|
+
return decodeOne(response, currencyMapper);
|
|
1774
|
+
},
|
|
1775
|
+
async getByCode (code) {
|
|
1776
|
+
const response = await transport.get(`/currencies/by_code/${code}`);
|
|
1777
|
+
return decodeOne(response, currencyMapper);
|
|
1778
|
+
},
|
|
1779
|
+
async all () {
|
|
1780
|
+
const response = await transport.get('/currencies/all');
|
|
1781
|
+
return decodeMany(response, currencyMapper);
|
|
1782
|
+
}
|
|
1783
|
+
};
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
/**
|
|
1787
|
+
* Build filter params for list operations
|
|
1788
|
+
*/ function buildListParams(params) {
|
|
1789
|
+
if (!params) return {};
|
|
1790
|
+
const queryParams = {};
|
|
1791
|
+
if (params.page) {
|
|
1792
|
+
queryParams['page[number]'] = params.page;
|
|
1793
|
+
}
|
|
1794
|
+
if (params.perPage) {
|
|
1795
|
+
queryParams['page[size]'] = params.perPage;
|
|
1796
|
+
}
|
|
1797
|
+
if (params.sort) {
|
|
1798
|
+
const sorts = Array.isArray(params.sort) ? params.sort : [
|
|
1799
|
+
params.sort
|
|
1800
|
+
];
|
|
1801
|
+
queryParams['sort'] = sorts.map((s)=>s.direction === 'desc' ? `-${s.field}` : s.field).join(',');
|
|
1802
|
+
}
|
|
1803
|
+
if (params.filter) {
|
|
1804
|
+
for (const [key, value] of Object.entries(params.filter)){
|
|
1805
|
+
queryParams[`filter[${key}]`] = value;
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
if (params.include) {
|
|
1809
|
+
queryParams['include'] = params.include.join(',');
|
|
1810
|
+
}
|
|
1811
|
+
return queryParams;
|
|
1812
|
+
}
|
|
1813
|
+
/**
|
|
1814
|
+
* Create the guests service
|
|
1815
|
+
*/ function createGuestsService(transport, _config) {
|
|
1816
|
+
return {
|
|
1817
|
+
async list (params) {
|
|
1818
|
+
const response = await transport.get('/guests', {
|
|
1819
|
+
params: buildListParams(params)
|
|
1820
|
+
});
|
|
1821
|
+
return decodePageResult(response, guestMapper);
|
|
1822
|
+
},
|
|
1823
|
+
async get (id) {
|
|
1824
|
+
const response = await transport.get(`/guests/${id}`);
|
|
1825
|
+
return decodeOne(response, guestMapper);
|
|
1826
|
+
},
|
|
1827
|
+
async track () {
|
|
1828
|
+
const response = await transport.post('/guests/track');
|
|
1829
|
+
return decodeOne(response, guestMapper);
|
|
1830
|
+
},
|
|
1831
|
+
async convert (id) {
|
|
1832
|
+
const response = await transport.post(`/guests/${id}/convert`);
|
|
1833
|
+
return decodeOne(response, guestMapper);
|
|
1834
|
+
}
|
|
1835
|
+
};
|
|
1836
|
+
}
|
|
1837
|
+
/**
|
|
1838
|
+
* Create the magic links service
|
|
1839
|
+
*/ function createMagicLinksService(transport, _config) {
|
|
1840
|
+
return {
|
|
1841
|
+
async list (params) {
|
|
1842
|
+
const response = await transport.get('/magic_links', {
|
|
1843
|
+
params: buildListParams(params)
|
|
1844
|
+
});
|
|
1845
|
+
return decodePageResult(response, magicLinkMapper);
|
|
1846
|
+
},
|
|
1847
|
+
async get (id) {
|
|
1848
|
+
const response = await transport.get(`/magic_links/${id}`);
|
|
1849
|
+
return decodeOne(response, magicLinkMapper);
|
|
1850
|
+
},
|
|
1851
|
+
async create (request) {
|
|
1852
|
+
const response = await transport.post('/magic_links', {
|
|
1853
|
+
user_unique_id: request.userUniqueId,
|
|
1854
|
+
email: request.email,
|
|
1855
|
+
target_url: request.targetUrl,
|
|
1856
|
+
expired_url: request.expiredUrl,
|
|
1857
|
+
expires_in_hours: request.expiresInHours,
|
|
1858
|
+
description: request.description,
|
|
1859
|
+
payload: request.payload
|
|
1860
|
+
});
|
|
1861
|
+
return decodeOne(response, magicLinkMapper);
|
|
1862
|
+
},
|
|
1863
|
+
async validate (token) {
|
|
1864
|
+
const response = await transport.post('/magic_links/validate', {
|
|
1865
|
+
token
|
|
1866
|
+
});
|
|
1867
|
+
return decodeOne(response, magicLinkMapper);
|
|
1868
|
+
},
|
|
1869
|
+
async expire (id) {
|
|
1870
|
+
const response = await transport.post(`/magic_links/${id}/expire`);
|
|
1871
|
+
return decodeOne(response, magicLinkMapper);
|
|
1872
|
+
}
|
|
1873
|
+
};
|
|
1874
|
+
}
|
|
1875
|
+
/**
|
|
1876
|
+
* Create the refresh tokens service
|
|
1877
|
+
*/ function createRefreshTokensService(transport, _config) {
|
|
1878
|
+
return {
|
|
1879
|
+
async list (params) {
|
|
1880
|
+
const response = await transport.get('/refresh_tokens', {
|
|
1881
|
+
params: buildListParams(params)
|
|
1882
|
+
});
|
|
1883
|
+
return decodePageResult(response, refreshTokenMapper);
|
|
1884
|
+
},
|
|
1885
|
+
async get (id) {
|
|
1886
|
+
const response = await transport.get(`/refresh_tokens/${id}`);
|
|
1887
|
+
return decodeOne(response, refreshTokenMapper);
|
|
1888
|
+
},
|
|
1889
|
+
async revoke (id) {
|
|
1890
|
+
const response = await transport.post(`/refresh_tokens/${id}/revoke`);
|
|
1891
|
+
return decodeOne(response, refreshTokenMapper);
|
|
1892
|
+
},
|
|
1893
|
+
async revokeAll () {
|
|
1894
|
+
await transport.post('/refresh_tokens/revoke_all');
|
|
1895
|
+
},
|
|
1896
|
+
async revokeOthers () {
|
|
1897
|
+
await transport.post('/refresh_tokens/revoke_others');
|
|
1898
|
+
}
|
|
1899
|
+
};
|
|
1900
|
+
}
|
|
1901
|
+
/**
|
|
1902
|
+
* Create the user devices service
|
|
1903
|
+
*/ function createUserDevicesService(transport, _config) {
|
|
1904
|
+
return {
|
|
1905
|
+
async list (params) {
|
|
1906
|
+
const response = await transport.get('/user_devices', {
|
|
1907
|
+
params: buildListParams(params)
|
|
1908
|
+
});
|
|
1909
|
+
return decodePageResult(response, userDeviceMapper);
|
|
1910
|
+
},
|
|
1911
|
+
async get (id) {
|
|
1912
|
+
const response = await transport.get(`/user_devices/${id}`);
|
|
1913
|
+
return decodeOne(response, userDeviceMapper);
|
|
1914
|
+
},
|
|
1915
|
+
async register (request) {
|
|
1916
|
+
const response = await transport.post('/user_devices', {
|
|
1917
|
+
device_type: request.deviceType,
|
|
1918
|
+
push_id: request.pushId,
|
|
1919
|
+
os_type: request.osType,
|
|
1920
|
+
default_device: request.defaultDevice,
|
|
1921
|
+
location_enabled: request.locationEnabled,
|
|
1922
|
+
notifications_enabled: request.notificationsEnabled
|
|
1923
|
+
});
|
|
1924
|
+
return decodeOne(response, userDeviceMapper);
|
|
1925
|
+
},
|
|
1926
|
+
async update (id, request) {
|
|
1927
|
+
const response = await transport.patch(`/user_devices/${id}`, {
|
|
1928
|
+
device_type: request.deviceType,
|
|
1929
|
+
push_id: request.pushId,
|
|
1930
|
+
os_type: request.osType,
|
|
1931
|
+
default_device: request.defaultDevice,
|
|
1932
|
+
location_enabled: request.locationEnabled,
|
|
1933
|
+
notifications_enabled: request.notificationsEnabled
|
|
1934
|
+
});
|
|
1935
|
+
return decodeOne(response, userDeviceMapper);
|
|
1936
|
+
},
|
|
1937
|
+
async unregister (id) {
|
|
1938
|
+
await transport.delete(`/user_devices/${id}`);
|
|
1939
|
+
},
|
|
1940
|
+
async setDefault (id) {
|
|
1941
|
+
const response = await transport.post(`/user_devices/${id}/set_default`);
|
|
1942
|
+
return decodeOne(response, userDeviceMapper);
|
|
1943
|
+
}
|
|
1944
|
+
};
|
|
1945
|
+
}
|
|
1946
|
+
/**
|
|
1947
|
+
* Create the tenant users service
|
|
1948
|
+
*/ function createTenantUsersService(transport, _config) {
|
|
1949
|
+
return {
|
|
1950
|
+
async current () {
|
|
1951
|
+
const response = await transport.get('/tenant_users/current');
|
|
1952
|
+
return decodeOne(response, tenantUserMapper);
|
|
1953
|
+
},
|
|
1954
|
+
async get (userUniqueId) {
|
|
1955
|
+
const response = await transport.get(`/tenant_users/${userUniqueId}`);
|
|
1956
|
+
return decodeOne(response, tenantUserMapper);
|
|
1957
|
+
},
|
|
1958
|
+
async list (params) {
|
|
1959
|
+
const response = await transport.get('/tenant_users', {
|
|
1960
|
+
params: buildListParams(params)
|
|
1961
|
+
});
|
|
1962
|
+
return decodeMany(response, tenantUserMapper);
|
|
1963
|
+
}
|
|
1964
|
+
};
|
|
1965
|
+
}
|
|
1966
|
+
/**
|
|
1967
|
+
* Create the mail templates service
|
|
1968
|
+
*/ function createMailTemplatesService(transport, _config) {
|
|
1969
|
+
return {
|
|
1970
|
+
async list (params) {
|
|
1971
|
+
const response = await transport.get('/mail_templates', {
|
|
1972
|
+
params: buildListParams(params)
|
|
1973
|
+
});
|
|
1974
|
+
return decodePageResult(response, mailTemplateMapper);
|
|
1975
|
+
},
|
|
1976
|
+
async get (id) {
|
|
1977
|
+
const response = await transport.get(`/mail_templates/${id}`);
|
|
1978
|
+
return decodeOne(response, mailTemplateMapper);
|
|
1979
|
+
},
|
|
1980
|
+
async getByEvent (eventName) {
|
|
1981
|
+
const response = await transport.get(`/mail_templates/by_event/${eventName}`);
|
|
1982
|
+
return decodeOne(response, mailTemplateMapper);
|
|
1983
|
+
},
|
|
1984
|
+
async update (id, template) {
|
|
1985
|
+
const response = await transport.patch(`/mail_templates/${id}`, {
|
|
1986
|
+
template_name: template.templateName,
|
|
1987
|
+
template_html: template.templateHtml,
|
|
1988
|
+
template_text: template.templateText,
|
|
1989
|
+
from_domain: template.fromDomain,
|
|
1990
|
+
from_address: template.fromAddress,
|
|
1991
|
+
from_name: template.fromName,
|
|
1992
|
+
from_subject: template.fromSubject,
|
|
1993
|
+
payload: template.payload,
|
|
1994
|
+
preferred_language: template.preferredLanguage,
|
|
1995
|
+
provider: template.provider
|
|
1996
|
+
});
|
|
1997
|
+
return decodeOne(response, mailTemplateMapper);
|
|
1998
|
+
}
|
|
1999
|
+
};
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
/**
|
|
2003
|
+
* Create the Authentication block
|
|
2004
|
+
*
|
|
2005
|
+
* @example
|
|
2006
|
+
* ```typescript
|
|
2007
|
+
* import { createAuthenticationBlock } from '@23blocks/block-authentication';
|
|
2008
|
+
* import { createHttpTransport } from '@23blocks/transport-http';
|
|
2009
|
+
*
|
|
2010
|
+
* const transport = createHttpTransport({
|
|
2011
|
+
* baseUrl: 'https://api.example.com',
|
|
2012
|
+
* headers: () => ({
|
|
2013
|
+
* 'Authorization': `Bearer ${getToken()}`,
|
|
2014
|
+
* 'x-api-key': 'your-app-id',
|
|
2015
|
+
* }),
|
|
2016
|
+
* });
|
|
2017
|
+
*
|
|
2018
|
+
* const auth = createAuthenticationBlock(transport, { appId: 'your-app-id' });
|
|
2019
|
+
*
|
|
2020
|
+
* // Sign in
|
|
2021
|
+
* const { user, accessToken } = await auth.auth.signIn({
|
|
2022
|
+
* email: 'user@example.com',
|
|
2023
|
+
* password: 'password',
|
|
2024
|
+
* });
|
|
2025
|
+
*
|
|
2026
|
+
* // List users
|
|
2027
|
+
* const users = await auth.users.list({ page: 1, perPage: 20 });
|
|
2028
|
+
*
|
|
2029
|
+
* // Get roles
|
|
2030
|
+
* const roles = await auth.roles.list();
|
|
2031
|
+
* ```
|
|
2032
|
+
*/ function createAuthenticationBlock(transport, config) {
|
|
2033
|
+
return {
|
|
2034
|
+
auth: createAuthService(transport),
|
|
2035
|
+
users: createUsersService(transport),
|
|
2036
|
+
roles: createRolesService(transport),
|
|
2037
|
+
apiKeys: createApiKeysService(transport),
|
|
2038
|
+
apps: createAppsService(transport),
|
|
2039
|
+
blocks: createBlocksService(transport),
|
|
2040
|
+
services: createServicesRegistryService(transport),
|
|
2041
|
+
subscriptionModels: createSubscriptionModelsService(transport),
|
|
2042
|
+
userSubscriptions: createUserSubscriptionsService(transport),
|
|
2043
|
+
companySubscriptions: createCompanySubscriptionsService(transport),
|
|
2044
|
+
countries: createCountriesService(transport),
|
|
2045
|
+
states: createStatesService(transport),
|
|
2046
|
+
counties: createCountiesService(transport),
|
|
2047
|
+
cities: createCitiesService(transport),
|
|
2048
|
+
currencies: createCurrenciesService(transport),
|
|
2049
|
+
guests: createGuestsService(transport),
|
|
2050
|
+
magicLinks: createMagicLinksService(transport),
|
|
2051
|
+
refreshTokens: createRefreshTokensService(transport),
|
|
2052
|
+
userDevices: createUserDevicesService(transport),
|
|
2053
|
+
tenantUsers: createTenantUsersService(transport),
|
|
2054
|
+
mailTemplates: createMailTemplatesService(transport)
|
|
2055
|
+
};
|
|
2056
|
+
}
|
|
2057
|
+
/**
|
|
2058
|
+
* Block metadata
|
|
2059
|
+
*/ const authenticationBlockMetadata = {
|
|
2060
|
+
name: 'authentication',
|
|
2061
|
+
version: '0.0.1',
|
|
2062
|
+
description: 'Authentication, users, roles, API keys, subscriptions, geography, and device management',
|
|
2063
|
+
resourceTypes: [
|
|
2064
|
+
'User',
|
|
2065
|
+
'Role',
|
|
2066
|
+
'Permission',
|
|
2067
|
+
'UserAvatar',
|
|
2068
|
+
'UserProfile',
|
|
2069
|
+
'Company',
|
|
2070
|
+
'CompanyDetail',
|
|
2071
|
+
'CompanyBlock',
|
|
2072
|
+
'CompanyKey',
|
|
2073
|
+
'Tenant',
|
|
2074
|
+
'ApiKey',
|
|
2075
|
+
'App',
|
|
2076
|
+
'Block',
|
|
2077
|
+
'Service',
|
|
2078
|
+
'SubscriptionModel',
|
|
2079
|
+
'UserSubscription',
|
|
2080
|
+
'CompanySubscription',
|
|
2081
|
+
'Country',
|
|
2082
|
+
'State',
|
|
2083
|
+
'County',
|
|
2084
|
+
'City',
|
|
2085
|
+
'Currency',
|
|
2086
|
+
'Guest',
|
|
2087
|
+
'MagicLink',
|
|
2088
|
+
'RefreshToken',
|
|
2089
|
+
'UserDevice',
|
|
2090
|
+
'TenantUser',
|
|
2091
|
+
'MailTemplate'
|
|
2092
|
+
]
|
|
2093
|
+
};
|
|
2094
|
+
|
|
2095
|
+
export { apiKeyMapper, apiKeyWithSecretMapper, authenticationBlockMetadata, companyBlockMapper, companyDetailMapper, companyKeyMapper, companyMapper, createAuthenticationBlock, permissionMapper, roleMapper, tenantMapper, userAvatarMapper, userMapper, userProfileMapper };
|