@cryptexlabs/codex-nodejs-common 0.1.18 → 0.1.22
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/lib/package.json +3 -1
- package/lib/src/auth/http-authz.action-to-sub-objects.guard.util.d.ts +11 -0
- package/lib/src/auth/http-authz.action-to-sub-objects.guard.util.js +55 -0
- package/lib/src/auth/http-authz.action-to-sub-objects.guard.util.js.map +1 -0
- package/lib/src/auth/http-authz.attach-objects.guard.util.d.ts +10 -0
- package/lib/src/auth/http-authz.attach-objects.guard.util.js +24 -0
- package/lib/src/auth/http-authz.attach-objects.guard.util.js.map +1 -0
- package/lib/src/auth/http-authz.detach-objects.guard.util.d.ts +10 -0
- package/lib/src/auth/http-authz.detach-objects.guard.util.js +24 -0
- package/lib/src/auth/http-authz.detach-objects.guard.util.js.map +1 -0
- package/lib/src/auth/{http-authz-guard.util.d.ts → http-authz.guard.util.d.ts} +0 -0
- package/lib/src/auth/{http-authz-guard.util.js → http-authz.guard.util.js} +1 -1
- package/lib/src/auth/{http-authz-guard.util.js.map → http-authz.guard.util.js.map} +1 -1
- package/lib/src/auth/http-authz.list-sub-objects.guard.util.d.ts +10 -0
- package/lib/src/auth/http-authz.list-sub-objects.guard.util.js +47 -0
- package/lib/src/auth/http-authz.list-sub-objects.guard.util.js.map +1 -0
- package/lib/src/auth/index.d.ts +5 -1
- package/lib/src/auth/index.js +5 -1
- package/lib/src/auth/index.js.map +1 -1
- package/lib/src/index.d.ts +1 -0
- package/lib/src/index.js +1 -0
- package/lib/src/index.js.map +1 -1
- package/lib/src/response/http-paginated-response-meta.d.ts +9 -0
- package/lib/src/response/http-paginated-response-meta.js +13 -0
- package/lib/src/response/http-paginated-response-meta.js.map +1 -0
- package/lib/src/response/index.d.ts +2 -0
- package/lib/src/response/index.js +2 -0
- package/lib/src/response/index.js.map +1 -1
- package/lib/src/response/rest.paginated.response.d.ts +10 -0
- package/lib/src/response/rest.paginated.response.js +18 -0
- package/lib/src/response/rest.paginated.response.js.map +1 -0
- package/lib/src/result/index.d.ts +1 -0
- package/lib/src/result/index.js +14 -0
- package/lib/src/result/index.js.map +1 -0
- package/lib/src/result/paginated.results.d.ts +4 -0
- package/lib/src/result/paginated.results.js +3 -0
- package/lib/src/result/paginated.results.js.map +1 -0
- package/package.json +3 -1
- package/src/auth/http-authz.action-to-sub-objects.guard.util.ts +78 -0
- package/src/auth/http-authz.attach-objects.guard.util.spec.ts +369 -0
- package/src/auth/http-authz.attach-objects.guard.util.ts +48 -0
- package/src/auth/http-authz.detach-objects.guard.util.spec.ts +369 -0
- package/src/auth/http-authz.detach-objects.guard.util.ts +48 -0
- package/src/auth/{http-authz-guard.util.spec.ts → http-authz.guard.util.spec.ts} +1 -1
- package/src/auth/{http-authz-guard.util.ts → http-authz.guard.util.ts} +0 -0
- package/src/auth/http-authz.list-sub-objects.guard.util.spec.ts +323 -0
- package/src/auth/http-authz.list-sub-objects.guard.util.ts +67 -0
- package/src/auth/index.ts +5 -1
- package/src/index.ts +1 -0
- package/src/response/http-paginated-response-meta.ts +24 -0
- package/src/response/index.ts +2 -0
- package/src/response/rest.paginated.response.ts +40 -0
- package/src/result/index.ts +1 -0
- package/src/result/paginated.results.ts +4 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { ExecutionContext } from "@nestjs/common";
|
|
2
|
+
import * as jwt from "jsonwebtoken";
|
|
3
|
+
import { HttpAuthzListSubObjectsGuardUtil } from "./http-authz.list-sub-objects.guard.util";
|
|
4
|
+
|
|
5
|
+
describe(HttpAuthzListSubObjectsGuardUtil.name, () => {
|
|
6
|
+
it("Should allow super admin to list a group for a user", () => {
|
|
7
|
+
const token = jwt.sign(
|
|
8
|
+
{
|
|
9
|
+
scopes: [`cool-app:::any:any:any:any:any:any`],
|
|
10
|
+
},
|
|
11
|
+
"hello"
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const context = {
|
|
15
|
+
switchToHttp: () => ({
|
|
16
|
+
getRequest: () => ({
|
|
17
|
+
headers: {
|
|
18
|
+
authorization: `Bearer ${token}`,
|
|
19
|
+
},
|
|
20
|
+
params: {
|
|
21
|
+
userId: "4d2114ca-24e2-43e5-bddb-d9a6688b8340",
|
|
22
|
+
},
|
|
23
|
+
body: ["680dddec-f0b9-4a01-b8b5-be725f946935"],
|
|
24
|
+
}),
|
|
25
|
+
}),
|
|
26
|
+
} as ExecutionContext;
|
|
27
|
+
|
|
28
|
+
const util = new HttpAuthzListSubObjectsGuardUtil(context);
|
|
29
|
+
|
|
30
|
+
expect(
|
|
31
|
+
util.isAuthorized(
|
|
32
|
+
"user",
|
|
33
|
+
"4d2114ca-24e2-43e5-bddb-d9a6688b8340",
|
|
34
|
+
"group",
|
|
35
|
+
"cool-app"
|
|
36
|
+
)
|
|
37
|
+
).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("Should allow someone with permission to list groups for a user to list a group for the user", () => {
|
|
41
|
+
const token = jwt.sign(
|
|
42
|
+
{
|
|
43
|
+
scopes: [
|
|
44
|
+
`cool-app:::user:4d2114ca-24e2-43e5-bddb-d9a6688b8340::group:any:list`,
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
"hello"
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const context = {
|
|
51
|
+
switchToHttp: () => ({
|
|
52
|
+
getRequest: () => ({
|
|
53
|
+
headers: {
|
|
54
|
+
authorization: `Bearer ${token}`,
|
|
55
|
+
},
|
|
56
|
+
}),
|
|
57
|
+
}),
|
|
58
|
+
} as ExecutionContext;
|
|
59
|
+
|
|
60
|
+
const util = new HttpAuthzListSubObjectsGuardUtil(context);
|
|
61
|
+
|
|
62
|
+
expect(
|
|
63
|
+
util.isAuthorized(
|
|
64
|
+
"user",
|
|
65
|
+
"4d2114ca-24e2-43e5-bddb-d9a6688b8340",
|
|
66
|
+
"group",
|
|
67
|
+
"cool-app"
|
|
68
|
+
)
|
|
69
|
+
).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("Should allow someone with permission to do anything to any group on a user to list a group for the user", () => {
|
|
73
|
+
const token = jwt.sign(
|
|
74
|
+
{
|
|
75
|
+
scopes: [
|
|
76
|
+
`cool-app:::user:4d2114ca-24e2-43e5-bddb-d9a6688b8340::group:any:any`,
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
"hello"
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const context = {
|
|
83
|
+
switchToHttp: () => ({
|
|
84
|
+
getRequest: () => ({
|
|
85
|
+
headers: {
|
|
86
|
+
authorization: `Bearer ${token}`,
|
|
87
|
+
},
|
|
88
|
+
params: {
|
|
89
|
+
userId: "4d2114ca-24e2-43e5-bddb-d9a6688b8340",
|
|
90
|
+
},
|
|
91
|
+
body: ["680dddec-f0b9-4a01-b8b5-be725f946935"],
|
|
92
|
+
}),
|
|
93
|
+
}),
|
|
94
|
+
} as ExecutionContext;
|
|
95
|
+
|
|
96
|
+
const util = new HttpAuthzListSubObjectsGuardUtil(context);
|
|
97
|
+
|
|
98
|
+
expect(
|
|
99
|
+
util.isAuthorized(
|
|
100
|
+
"user",
|
|
101
|
+
"4d2114ca-24e2-43e5-bddb-d9a6688b8340",
|
|
102
|
+
"group",
|
|
103
|
+
"cool-app"
|
|
104
|
+
)
|
|
105
|
+
).toBe(true);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("Should allow someone with permission to do anything to any sub object for a user to list a group for the user", () => {
|
|
109
|
+
const token = jwt.sign(
|
|
110
|
+
{
|
|
111
|
+
scopes: [
|
|
112
|
+
`cool-app:::user:4d2114ca-24e2-43e5-bddb-d9a6688b8340::any:any:any`,
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
"hello"
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const context = {
|
|
119
|
+
switchToHttp: () => ({
|
|
120
|
+
getRequest: () => ({
|
|
121
|
+
headers: {
|
|
122
|
+
authorization: `Bearer ${token}`,
|
|
123
|
+
},
|
|
124
|
+
params: {
|
|
125
|
+
userId: "4d2114ca-24e2-43e5-bddb-d9a6688b8340",
|
|
126
|
+
},
|
|
127
|
+
body: ["680dddec-f0b9-4a01-b8b5-be725f946935"],
|
|
128
|
+
}),
|
|
129
|
+
}),
|
|
130
|
+
} as ExecutionContext;
|
|
131
|
+
|
|
132
|
+
const util = new HttpAuthzListSubObjectsGuardUtil(context);
|
|
133
|
+
|
|
134
|
+
expect(
|
|
135
|
+
util.isAuthorized(
|
|
136
|
+
"user",
|
|
137
|
+
"4d2114ca-24e2-43e5-bddb-d9a6688b8340",
|
|
138
|
+
"group",
|
|
139
|
+
"cool-app"
|
|
140
|
+
)
|
|
141
|
+
).toBe(true);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("Should allow someone with permission to list a specific group for a user to list the groups to the user", () => {
|
|
145
|
+
const token = jwt.sign(
|
|
146
|
+
{
|
|
147
|
+
scopes: [
|
|
148
|
+
`cool-app:::user:4d2114ca-24e2-43e5-bddb-d9a6688b8340::group::list`,
|
|
149
|
+
],
|
|
150
|
+
},
|
|
151
|
+
"hello"
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const context = {
|
|
155
|
+
switchToHttp: () => ({
|
|
156
|
+
getRequest: () => ({
|
|
157
|
+
headers: {
|
|
158
|
+
authorization: `Bearer ${token}`,
|
|
159
|
+
},
|
|
160
|
+
params: {
|
|
161
|
+
userId: "4d2114ca-24e2-43e5-bddb-d9a6688b8340",
|
|
162
|
+
},
|
|
163
|
+
body: ["680dddec-f0b9-4a01-b8b5-be725f946935"],
|
|
164
|
+
}),
|
|
165
|
+
}),
|
|
166
|
+
} as ExecutionContext;
|
|
167
|
+
|
|
168
|
+
const util = new HttpAuthzListSubObjectsGuardUtil(context);
|
|
169
|
+
|
|
170
|
+
expect(
|
|
171
|
+
util.isAuthorized(
|
|
172
|
+
"user",
|
|
173
|
+
"4d2114ca-24e2-43e5-bddb-d9a6688b8340",
|
|
174
|
+
"group",
|
|
175
|
+
"cool-app"
|
|
176
|
+
)
|
|
177
|
+
).toBe(true);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("Should not allow someone with permission to list groups to a different user to list a group for the user", () => {
|
|
181
|
+
const token = jwt.sign(
|
|
182
|
+
{
|
|
183
|
+
scopes: [
|
|
184
|
+
`cool-app:::user:55854a66-5a73-4416-b03a-eba4417b691c::group:any:create`,
|
|
185
|
+
],
|
|
186
|
+
},
|
|
187
|
+
"hello"
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
const context = {
|
|
191
|
+
switchToHttp: () => ({
|
|
192
|
+
getRequest: () => ({
|
|
193
|
+
headers: {
|
|
194
|
+
authorization: `Bearer ${token}`,
|
|
195
|
+
},
|
|
196
|
+
params: {
|
|
197
|
+
userId: "001d4f53-798b-4a0b-8ef7-330a7bf72147",
|
|
198
|
+
},
|
|
199
|
+
body: ["680dddec-f0b9-4a01-b8b5-be725f946935"],
|
|
200
|
+
}),
|
|
201
|
+
}),
|
|
202
|
+
} as ExecutionContext;
|
|
203
|
+
|
|
204
|
+
const util = new HttpAuthzListSubObjectsGuardUtil(context);
|
|
205
|
+
|
|
206
|
+
expect(
|
|
207
|
+
util.isAuthorized(
|
|
208
|
+
"user",
|
|
209
|
+
"4d2114ca-24e2-43e5-bddb-d9a6688b8340",
|
|
210
|
+
"group",
|
|
211
|
+
"cool-app"
|
|
212
|
+
)
|
|
213
|
+
).toBe(false);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("Should not allow someone with permission to do anything to a different user to list a group for the user", () => {
|
|
217
|
+
const token = jwt.sign(
|
|
218
|
+
{
|
|
219
|
+
scopes: [
|
|
220
|
+
`cool-app:::user:55854a66-5a73-4416-b03a-eba4417b691c::group:any:any`,
|
|
221
|
+
],
|
|
222
|
+
},
|
|
223
|
+
"hello"
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
const context = {
|
|
227
|
+
switchToHttp: () => ({
|
|
228
|
+
getRequest: () => ({
|
|
229
|
+
headers: {
|
|
230
|
+
authorization: `Bearer ${token}`,
|
|
231
|
+
},
|
|
232
|
+
params: {
|
|
233
|
+
userId: "001d4f53-798b-4a0b-8ef7-330a7bf72147",
|
|
234
|
+
},
|
|
235
|
+
body: ["680dddec-f0b9-4a01-b8b5-be725f946935"],
|
|
236
|
+
}),
|
|
237
|
+
}),
|
|
238
|
+
} as ExecutionContext;
|
|
239
|
+
|
|
240
|
+
const util = new HttpAuthzListSubObjectsGuardUtil(context);
|
|
241
|
+
|
|
242
|
+
expect(
|
|
243
|
+
util.isAuthorized(
|
|
244
|
+
"user",
|
|
245
|
+
"4d2114ca-24e2-43e5-bddb-d9a6688b8340",
|
|
246
|
+
"group",
|
|
247
|
+
"cool-app"
|
|
248
|
+
)
|
|
249
|
+
).toBe(false);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it("Should not allow someone with permission to do anything to any sub object for a different user to list a group for the user", () => {
|
|
253
|
+
const token = jwt.sign(
|
|
254
|
+
{
|
|
255
|
+
scopes: [
|
|
256
|
+
`cool-app:::user:55854a66-5a73-4416-b03a-eba4417b691c::any:any:any`,
|
|
257
|
+
],
|
|
258
|
+
},
|
|
259
|
+
"hello"
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
const context = {
|
|
263
|
+
switchToHttp: () => ({
|
|
264
|
+
getRequest: () => ({
|
|
265
|
+
headers: {
|
|
266
|
+
authorization: `Bearer ${token}`,
|
|
267
|
+
},
|
|
268
|
+
params: {
|
|
269
|
+
userId: "001d4f53-798b-4a0b-8ef7-330a7bf72147",
|
|
270
|
+
},
|
|
271
|
+
body: ["680dddec-f0b9-4a01-b8b5-be725f946935"],
|
|
272
|
+
}),
|
|
273
|
+
}),
|
|
274
|
+
} as ExecutionContext;
|
|
275
|
+
|
|
276
|
+
const util = new HttpAuthzListSubObjectsGuardUtil(context);
|
|
277
|
+
|
|
278
|
+
expect(
|
|
279
|
+
util.isAuthorized(
|
|
280
|
+
"user",
|
|
281
|
+
"4d2114ca-24e2-43e5-bddb-d9a6688b8340",
|
|
282
|
+
"group",
|
|
283
|
+
"cool-app"
|
|
284
|
+
)
|
|
285
|
+
).toBe(false);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("Should not allow someone with permission to list a different specific permission for a user to list the groups to the user", () => {
|
|
289
|
+
const token = jwt.sign(
|
|
290
|
+
{
|
|
291
|
+
scopes: [
|
|
292
|
+
`cool-app:::user:4d2114ca-24e2-43e5-bddb-d9a6688b8340::group:any:create`,
|
|
293
|
+
],
|
|
294
|
+
},
|
|
295
|
+
"hello"
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
const context = {
|
|
299
|
+
switchToHttp: () => ({
|
|
300
|
+
getRequest: () => ({
|
|
301
|
+
headers: {
|
|
302
|
+
authorization: `Bearer ${token}`,
|
|
303
|
+
},
|
|
304
|
+
params: {
|
|
305
|
+
userId: "4d2114ca-24e2-43e5-bddb-d9a6688b8340",
|
|
306
|
+
},
|
|
307
|
+
body: ["5be3176f-c066-4418-b682-18e16fd07b84"],
|
|
308
|
+
}),
|
|
309
|
+
}),
|
|
310
|
+
} as ExecutionContext;
|
|
311
|
+
|
|
312
|
+
const util = new HttpAuthzListSubObjectsGuardUtil(context);
|
|
313
|
+
|
|
314
|
+
expect(
|
|
315
|
+
util.isAuthorized(
|
|
316
|
+
"user",
|
|
317
|
+
"4d2114ca-24e2-43e5-bddb-d9a6688b8340",
|
|
318
|
+
"group",
|
|
319
|
+
"cool-app"
|
|
320
|
+
)
|
|
321
|
+
).toBe(false);
|
|
322
|
+
});
|
|
323
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ExecutionContext } from "@nestjs/common";
|
|
2
|
+
import { HttpAuthzActionToSubObjectsGuardUtil } from "./http-authz.action-to-sub-objects.guard.util";
|
|
3
|
+
import { HttpAuthzGuardUtil } from "./http-authz.guard.util";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Authorizes detachment of objects to another object by object id
|
|
7
|
+
*/
|
|
8
|
+
export class HttpAuthzListSubObjectsGuardUtil {
|
|
9
|
+
private _util: HttpAuthzGuardUtil;
|
|
10
|
+
|
|
11
|
+
constructor(private readonly context: ExecutionContext) {
|
|
12
|
+
this._util = new HttpAuthzGuardUtil(context);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {string} object The object name of object A
|
|
17
|
+
* @param {string} objectId The object ID of object A
|
|
18
|
+
* @param {string} detachObject The object name of objects B
|
|
19
|
+
* @param {string?} namespace (Optional) The namespace of objects A and B
|
|
20
|
+
*/
|
|
21
|
+
public isAuthorized(
|
|
22
|
+
object: string,
|
|
23
|
+
objectId: string,
|
|
24
|
+
subObject: string,
|
|
25
|
+
namespace?: string
|
|
26
|
+
) {
|
|
27
|
+
let requests = [];
|
|
28
|
+
|
|
29
|
+
if (namespace) {
|
|
30
|
+
requests = [
|
|
31
|
+
{
|
|
32
|
+
action: "",
|
|
33
|
+
object: namespace,
|
|
34
|
+
objectId: "",
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
requests = [
|
|
40
|
+
...requests,
|
|
41
|
+
{
|
|
42
|
+
action: "",
|
|
43
|
+
object,
|
|
44
|
+
objectId,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
action: "list",
|
|
48
|
+
object: subObject,
|
|
49
|
+
objectId: "",
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
return this._util.isAuthorized(...requests);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public get params() {
|
|
57
|
+
return this._util.params;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public get query() {
|
|
61
|
+
return this._util.query;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public get body() {
|
|
65
|
+
return this._util.body;
|
|
66
|
+
}
|
|
67
|
+
}
|
package/src/auth/index.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export * from "./authenticator.interface";
|
|
2
2
|
export * from "./topic-authorizor.interface";
|
|
3
3
|
export * from "./fake-authenticator";
|
|
4
|
-
export * from "./http-authz
|
|
4
|
+
export * from "./http-authz.guard.util";
|
|
5
|
+
export * from "./http-authz.attach-objects.guard.util";
|
|
6
|
+
export * from "./http-authz.detach-objects.guard.util";
|
|
7
|
+
export * from "./http-authz.action-to-sub-objects.guard.util";
|
|
8
|
+
export * from "./http-authz.list-sub-objects.guard.util";
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HttpStatus } from "@nestjs/common";
|
|
2
|
+
import {
|
|
3
|
+
LocaleInterface,
|
|
4
|
+
MessageMetaInterface,
|
|
5
|
+
} from "@cryptexlabs/codex-data-model";
|
|
6
|
+
import { DefaultConfig } from "../config";
|
|
7
|
+
import { MessageMeta } from "../message";
|
|
8
|
+
|
|
9
|
+
export class HttpPaginatedResponseMeta
|
|
10
|
+
extends MessageMeta
|
|
11
|
+
implements MessageMetaInterface
|
|
12
|
+
{
|
|
13
|
+
constructor(
|
|
14
|
+
public readonly status: HttpStatus,
|
|
15
|
+
public readonly totalRecords: number,
|
|
16
|
+
type: string,
|
|
17
|
+
locale: LocaleInterface,
|
|
18
|
+
config: DefaultConfig,
|
|
19
|
+
correlationId: string,
|
|
20
|
+
started: Date
|
|
21
|
+
) {
|
|
22
|
+
super(type, locale, config, correlationId, started);
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/response/index.ts
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { HttpStatus } from "@nestjs/common";
|
|
2
|
+
import {
|
|
3
|
+
MessageInterface,
|
|
4
|
+
MessageMetaInterface,
|
|
5
|
+
} from "@cryptexlabs/codex-data-model";
|
|
6
|
+
import { JsonSerializableInterface } from "../message";
|
|
7
|
+
import { Context } from "../context";
|
|
8
|
+
import { HttpResponseMeta } from "./http-response-meta";
|
|
9
|
+
import { HttpPaginatedResponseMeta } from "./http-paginated-response-meta";
|
|
10
|
+
|
|
11
|
+
export class RestPaginatedResponse
|
|
12
|
+
implements JsonSerializableInterface<MessageInterface<string>>
|
|
13
|
+
{
|
|
14
|
+
public readonly meta: MessageMetaInterface;
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
context: Context,
|
|
18
|
+
status: HttpStatus,
|
|
19
|
+
totalRecords: number,
|
|
20
|
+
type: string,
|
|
21
|
+
public readonly data: any
|
|
22
|
+
) {
|
|
23
|
+
this.meta = new HttpPaginatedResponseMeta(
|
|
24
|
+
status,
|
|
25
|
+
totalRecords,
|
|
26
|
+
type,
|
|
27
|
+
context.locale,
|
|
28
|
+
context.config,
|
|
29
|
+
context.correlationId,
|
|
30
|
+
context.started
|
|
31
|
+
) as MessageMetaInterface;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public toJSON(): MessageInterface<any> {
|
|
35
|
+
return {
|
|
36
|
+
meta: this.meta,
|
|
37
|
+
data: this.data,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./paginated.results";
|