• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Fdawgs / ydh-myydh-crud-api / 4417510579

pending completion
4417510579

push

github

GitHub
chore(main): release 11.0.7 (#1221)

259 of 259 branches covered (100.0%)

Branch coverage included in aggregate %.

527 of 527 relevant lines covered (100.0%)

14.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/routes/admin/access/bearer-token/schema.js
1
const S = require("fluent-json-schema");
2✔
2

3
const security = [{ basicAuth: [] }];
2✔
4
const tags = ["System administration"];
2✔
5

6
/**
7
 * JSON Schema expects a String, `fluent-json-schema` converts this from
8
 * a RegExp to a String. JSON Schema does not support Regex flags
9
 */
10
const dateTimeSearchPattern =
11
        // eslint-disable-next-line security/detect-unsafe-regex
12
        /^(?:eq|ne|ge|le|gt|lt|sa|eb|ap|)\d{4}-[0-1]\d-[0-3]\d(?:T(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:Z|[+-]\d\d(?::?\d\d)?))?$/m;
2✔
13

14
const dateTimeSearchPatternExamples = [
2✔
15
        "2022-01-13",
16
        "2022-01-13T00:00:01Z",
17
        "2022-01-13T00:00:01.001Z",
18
        "2022-01-13T00:00:01+01:00",
19
        "ge2022-01-13",
20
        "ge2022-01-13T00:00:01Z",
21
        "ge2022-01-13T00:00:01.001Z",
22
        "ge2022-01-13T00:00:01+01:00",
23
];
24

25
const accessRecordScopes = [
2✔
26
        "documents/receipt.delete",
27
        "documents/receipt.put",
28
        "documents/register.search",
29
        "preferences/options.search",
30
        "preferences/user.put",
31
        "preferences/user.read",
32
];
33

34
const accessRecordBaseSchema = S.object()
2✔
35
        .prop("id", S.string().format("uuid"))
36
        .prop(
37
                "access",
38
                S.object()
39
                        .additionalProperties(false)
40
                        .prop(
41
                                "name",
42
                                S.string().description(
43
                                        "Name of client or service accessing API"
44
                                )
45
                        )
46
                        .prop(
47
                                "email",
48
                                S.string()
49
                                        .format("email")
50
                                        .description(
51
                                                "Contact email of client or service accessing API"
52
                                        )
53
                        )
54
                        .prop(
55
                                "expires",
56
                                S.string()
57
                                        .description("Expiry date of bearer token")
58
                                        .examples(["2022-01-13T14:05:54.000Z"])
59
                                        .format("date-time")
60
                        )
61
                        .prop("hash", S.string().description("Bcrypt-hashed bearer token"))
62
                        .prop(
63
                                "scopes",
64
                                S.array()
65
                                        .items(S.string().enum(accessRecordScopes))
66
                                        .uniqueItems(true)
67
                                        .description(
68
                                                "Actions the bearer token has been granted access to perform"
69
                                        )
70
                        )
71
        )
72
        .prop(
73
                "meta",
74
                S.object()
75
                        .additionalProperties(false)
76
                        .prop(
77
                                "created",
78
                                S.string()
79
                                        .examples(["2022-01-13T14:05:54.000Z"])
80
                                        .format("date-time")
81
                        )
82
                        .prop(
83
                                "last_updated",
84
                                S.string()
85
                                        .examples(["2022-01-13T14:05:54.000Z"])
86
                                        .format("date-time")
87
                        )
88
        )
89
        .required(["access"]);
90

91
/**
92
 * Fastify uses AJV for JSON Schema Validation,
93
 * see https://fastify.io/docs/latest/Reference/Validation-and-Serialization/
94
 *
95
 * Input validation protects against XSS, HPP, and most injection attacks
96
 */
97
const accessDeleteSchema = {
2✔
98
        tags,
99
        summary: "Delete bearer token",
100
        description: "Delete a bearer token record.",
101
        operationId: "deleteAccess",
102
        produces: ["application/json", "application/xml"],
103
        params: S.object()
104
                .prop(
105
                        "id",
106
                        S.string()
107
                                .description("Unique identifier of bearer token record")
108
                                .examples(["A972C577-DFB0-064E-1189-0154C99310DAAC12"])
109
                                .format("uuid")
110
                )
111
                .required(["id"]),
112
        response: {
113
                204: S.string().raw({ nullable: true }).description("No Content"),
114
                400: S.ref("responses#/properties/badRequest").description(
115
                        "Bad Request"
116
                ),
117
                401: S.ref("responses#/properties/unauthorized").description(
118
                        "Unauthorized"
119
                ),
120
                404: S.ref("responses#/properties/notFoundDbResults").description(
121
                        "Not Found"
122
                ),
123
                406: S.ref("responses#/properties/notAcceptable").description(
124
                        "Not Acceptable"
125
                ),
126
                429: S.ref("responses#/properties/tooManyRequests").description(
127
                        "Too Many Requests"
128
                ),
129
                500: S.ref("responses#/properties/internalServerError").description(
130
                        "Internal Server Error"
131
                ),
132
                503: S.ref("responses#/properties/serviceUnavailable").description(
133
                        "Service Unavailable"
134
                ),
135
        },
136
        security,
137
};
138

139
const accessGetReadSchema = {
2✔
140
        tags,
141
        summary: "Read bearer token record",
142
        description: "Return a single bearer token record.",
143
        operationId: "getReadAccess",
144
        produces: ["application/json", "application/xml"],
145
        params: S.object()
146
                .prop(
147
                        "id",
148
                        S.string()
149
                                .description("Unique identifier of bearer token record")
150
                                .examples(["A972C577-DFB0-064E-1189-0154C99310DAAC12"])
151
                                .format("uuid")
152
                )
153
                .required(["id"]),
154
        response: {
155
                200: accessRecordBaseSchema,
156
                400: S.ref("responses#/properties/badRequest").description(
157
                        "Bad Request"
158
                ),
159
                401: S.ref("responses#/properties/unauthorized").description(
160
                        "Unauthorized"
161
                ),
162
                404: S.ref("responses#/properties/notFoundDbResults").description(
163
                        "Not Found"
164
                ),
165
                406: S.ref("responses#/properties/notAcceptable").description(
166
                        "Not Acceptable"
167
                ),
168
                429: S.ref("responses#/properties/tooManyRequests").description(
169
                        "Too Many Requests"
170
                ),
171
                500: S.ref("responses#/properties/internalServerError").description(
172
                        "Internal Server Error"
173
                ),
174
                503: S.ref("responses#/properties/serviceUnavailable").description(
175
                        "Service Unavailable"
176
                ),
177
        },
178
        security,
179
};
180

181
const accessGetSearchSchema = {
2✔
182
        tags,
183
        summary: "Search bearer token records",
184
        description: "Return bearer token records.",
185
        operationId: "getSearchAccess",
186
        produces: ["application/json", "application/xml"],
187
        query: S.object()
188
                .additionalProperties(false)
189
                .prop(
190
                        "access.name",
191
                        S.string().description(
192
                                "Name of client or service granted access to API, case-insensitive and supports `*` wildcards"
193
                        )
194
                )
195
                .prop(
196
                        "access.email",
197
                        S.string()
198
                                .format("email")
199
                                .description(
200
                                        "Contact email of client or service granted access to API, case-insensitive and supports `*` wildcards"
201
                                )
202
                )
203
                .prop(
204
                        "access.expires",
205
                        S.anyOf([
206
                                S.string()
207
                                        .description("Datetime when bearer token expires")
208
                                        .examples(dateTimeSearchPatternExamples)
209
                                        .pattern(dateTimeSearchPattern),
210
                                S.array()
211
                                        .items(
212
                                                S.string()
213
                                                        .description("Datetime when bearer token expires")
214
                                                        .examples(dateTimeSearchPatternExamples)
215
                                                        .pattern(dateTimeSearchPattern)
216
                                        )
217
                                        .minItems(2)
218
                                        .maxItems(2)
219
                                        .uniqueItems(true),
220
                        ])
221
                )
222
                .prop(
223
                        "access.scopes",
224
                        S.anyOf([
225
                                S.string()
226
                                        .enum(accessRecordScopes)
227
                                        .description("An action the bearer token can perform"),
228
                                S.array()
229
                                        .items(
230
                                                S.string()
231
                                                        .enum(accessRecordScopes)
232
                                                        .description(
233
                                                                "An action the bearer token can perform"
234
                                                        )
235
                                        )
236
                                        .minItems(2)
237
                                        .uniqueItems(true),
238
                        ])
239
                )
240
                .prop(
241
                        "meta.created",
242
                        S.anyOf([
243
                                S.string()
244
                                        .description(
245
                                                "Datetime when bearer token record was created"
246
                                        )
247
                                        .examples(dateTimeSearchPatternExamples)
248
                                        .pattern(dateTimeSearchPattern),
249
                                S.array()
250
                                        .items(
251
                                                S.string()
252
                                                        .description(
253
                                                                "Datetime when bearer token record was created"
254
                                                        )
255
                                                        .examples(dateTimeSearchPatternExamples)
256
                                                        .pattern(dateTimeSearchPattern)
257
                                        )
258
                                        .minItems(2)
259
                                        .maxItems(2)
260
                                        .uniqueItems(true),
261
                        ])
262
                )
263
                .prop(
264
                        "meta.last_updated",
265
                        S.anyOf([
266
                                S.string()
267
                                        .description(
268
                                                "Last modified datetime of bearer token record"
269
                                        )
270
                                        .examples(dateTimeSearchPatternExamples)
271
                                        .pattern(dateTimeSearchPattern),
272
                                S.array()
273
                                        .items(
274
                                                S.string()
275
                                                        .description(
276
                                                                "Last modified datetime of bearer token record"
277
                                                        )
278
                                                        .examples(dateTimeSearchPatternExamples)
279
                                                        .pattern(dateTimeSearchPattern)
280
                                        )
281
                                        .minItems(2)
282
                                        .maxItems(2)
283
                                        .uniqueItems(true),
284
                        ])
285
                )
286
                .prop(
287
                        "page",
288
                        S.number()
289
                                .description("Page to retrieve")
290
                                .default(1)
291
                                .examples([1, 10])
292
                                .minimum(1)
293
                )
294
                .prop(
295
                        "per_page",
296
                        S.number()
297
                                .description(
298
                                        "Number of bearer token records to return per page"
299
                                )
300
                                .default(1)
301
                                .examples([1, 10])
302
                                .minimum(1)
303
                                .maximum(100)
304
                ),
305
        response: {
306
                200: S.object()
307
                        .additionalProperties(false)
308
                        .prop("link", S.string().format("uri"))
309
                        .prop(
310
                                "entry",
311
                                S.array().items(
312
                                        S.object()
313
                                                .prop("url", S.string().format("uri"))
314
                                                .extend(accessRecordBaseSchema)
315
                                )
316
                        )
317
                        .prop(
318
                                "meta",
319
                                S.object()
320
                                        .additionalProperties(false)
321
                                        .prop(
322
                                                "pagination",
323
                                                S.object()
324
                                                        .additionalProperties(false)
325
                                                        .prop("total", S.number().examples([0, 1, 10]))
326
                                                        .prop(
327
                                                                "per_page",
328
                                                                S.number()
329
                                                                        .default(1)
330
                                                                        .examples([1, 10])
331
                                                                        .minimum(1)
332
                                                                        .maximum(100)
333
                                                        )
334
                                                        .prop(
335
                                                                "current_page",
336
                                                                S.number()
337
                                                                        .default(1)
338
                                                                        .examples([1, 10])
339
                                                                        .minimum(1)
340
                                                        )
341
                                                        .prop("total_pages", S.number().examples([1, 10]))
342
                                        )
343
                        ),
344
                400: S.ref("responses#/properties/badRequest").description(
345
                        "Bad Request"
346
                ),
347
                401: S.ref("responses#/properties/unauthorized").description(
348
                        "Unauthorized"
349
                ),
350
                404: S.ref("responses#/properties/notFoundDbResults").description(
351
                        "Not Found"
352
                ),
353
                406: S.ref("responses#/properties/notAcceptable").description(
354
                        "Not Acceptable"
355
                ),
356
                429: S.ref("responses#/properties/tooManyRequests").description(
357
                        "Too Many Requests"
358
                ),
359
                500: S.ref("responses#/properties/internalServerError").description(
360
                        "Internal Server Error"
361
                ),
362
                503: S.ref("responses#/properties/serviceUnavailable").description(
363
                        "Service Unavailable"
364
                ),
365
        },
366
        security,
367
};
368

369
const accessPostSchema = {
2✔
370
        tags,
371
        summary: "Create a bearer token",
372
        description: "Generate a new bearer token that grants access to the API.",
373
        operationId: "postAccess",
374
        consumes: ["application/json"],
375
        produces: ["application/json", "application/xml"],
376
        body: S.object()
377
                .additionalProperties(false)
378
                .prop(
379
                        "name",
380
                        S.string().description(
381
                                "Name of client or service being granted access to API"
382
                        )
383
                )
384
                .prop(
385
                        "email",
386
                        S.string()
387
                                .format("email")
388
                                .description(
389
                                        "Contact email of client or service being granted access to API"
390
                                )
391
                )
392
                .prop(
393
                        "expires",
394
                        S.string()
395
                                .description("Expiry date of bearer token")
396
                                .examples([
397
                                        "2022-01-13",
398
                                        "2022-01-13T00:00:01",
399
                                        "2022-01-13T00:00:01.001",
400
                                        "2022-01-13T00:00:01Z",
401
                                        "2022-01-13T00:00:01.001Z",
402
                                ])
403
                                .pattern(
404
                                        /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}|)(?:.\d{3}|)(?:Z|)$/im
405
                                )
406
                )
407
                .prop(
408
                        "scopes",
409
                        S.array()
410
                                .items(S.string().enum(accessRecordScopes))
411
                                .uniqueItems(true)
412
                                .description("Actions the bearer token can perform")
413
                )
414
                .required(["name", "scopes"]),
415
        response: {
416
                201: S.object()
417
                        .prop(
418
                                "id",
419
                                S.string()
420
                                        .description(
421
                                                "Unique identifier of newly created bearer token record"
422
                                        )
423
                                        .examples(["A972C577-DFB0-064E-1189-0154C99310DAAC12"])
424
                                        .format("uuid")
425
                        )
426
                        .prop(
427
                                "access",
428
                                S.object()
429
                                        .additionalProperties(false)
430
                                        .prop(
431
                                                "token",
432
                                                S.string()
433
                                                        .description("Newly created bearer token")
434
                                                        .examples([
435
                                                                "ydhmyydh_3e8c3d19-fd60-460e-9c44-2e74cfa3545a",
436
                                                        ])
437
                                                        .format("uuid")
438
                                        )
439
                                        .prop(
440
                                                "scopes",
441
                                                S.array()
442
                                                        .items(S.string().enum(accessRecordScopes))
443
                                                        .uniqueItems(true)
444
                                                        .description(
445
                                                                "Actions the bearer token has been granted access to perform"
446
                                                        )
447
                                        )
448
                        )
449
                        .required(["access"]),
450
                400: S.ref("responses#/properties/badRequest").description(
451
                        "Bad Request"
452
                ),
453
                401: S.ref("responses#/properties/unauthorized").description(
454
                        "Unauthorized"
455
                ),
456
                406: S.ref("responses#/properties/notAcceptable").description(
457
                        "Not Acceptable"
458
                ),
459
                415: S.ref("responses#/properties/unsupportedMediaType").description(
460
                        "Unsupported Media Type"
461
                ),
462
                429: S.ref("responses#/properties/tooManyRequests").description(
463
                        "Too Many Requests"
464
                ),
465
                500: S.ref("responses#/properties/internalServerError").description(
466
                        "Internal Server Error"
467
                ),
468
                503: S.ref("responses#/properties/serviceUnavailable").description(
469
                        "Service Unavailable"
470
                ),
471
        },
472
        security,
473
};
474

475
module.exports = {
2✔
476
        accessDeleteSchema,
477
        accessGetReadSchema,
478
        accessGetSearchSchema,
479
        accessPostSchema,
480
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc