@sealkeeper/schema 0.4.8 → 0.4.9
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/api.d.ts +4178 -906
- package/dist/api.js +1438 -40
- package/dist/blocks.d.ts +21 -0
- package/dist/blocks.js +43 -0
- package/dist/cli-version.d.ts +7 -0
- package/dist/cli-version.js +89 -0
- package/dist/credential.d.ts +518 -10
- package/dist/credential.js +160 -28
- package/dist/dimensions.d.ts +6 -6
- package/dist/dimensions.js +11 -7
- package/dist/fingerprint.d.ts +1 -0
- package/dist/fingerprint.js +12 -0
- package/dist/game.d.ts +100 -0
- package/dist/game.js +190 -0
- package/dist/goal.d.ts +7 -1
- package/dist/goal.js +26 -6
- package/dist/handshake.js +5 -4
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/model-comparison.d.ts +70 -0
- package/dist/model-comparison.js +208 -0
- package/dist/model-name.d.ts +3 -0
- package/dist/model-name.js +48 -0
- package/dist/moderation.d.ts +2 -0
- package/dist/moderation.js +14 -8
- package/dist/policy.d.ts +1 -1
- package/dist/policy.js +1 -1
- package/dist/seal-conformance.js +120 -3
- package/dist/standing.d.ts +29 -0
- package/dist/standing.js +126 -14
- package/dist/task-templates.d.ts +2 -1
- package/dist/task-templates.js +6 -1
- package/dist/tasks.d.ts +57 -3
- package/dist/tasks.js +135 -8
- package/dist/top-dimensions.js +7 -3
- package/package.json +1 -1
package/dist/blocks.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const BLOCK: {
|
|
2
|
+
readonly gapMinutes: 15;
|
|
3
|
+
readonly maxTasks: 50;
|
|
4
|
+
readonly latest: 10;
|
|
5
|
+
readonly confirmers: 3;
|
|
6
|
+
};
|
|
7
|
+
export declare const BLOCK_TITLE_BANDS: readonly [{
|
|
8
|
+
readonly fromHour: 5;
|
|
9
|
+
readonly title: 'Morning block';
|
|
10
|
+
}, {
|
|
11
|
+
readonly fromHour: 12;
|
|
12
|
+
readonly title: 'Afternoon block';
|
|
13
|
+
}, {
|
|
14
|
+
readonly fromHour: 18;
|
|
15
|
+
readonly title: 'Evening block';
|
|
16
|
+
}, {
|
|
17
|
+
readonly fromHour: 23;
|
|
18
|
+
readonly title: 'Overnight block';
|
|
19
|
+
}];
|
|
20
|
+
export type BlockTitle = (typeof BLOCK_TITLE_BANDS)[number]['title'];
|
|
21
|
+
export declare function blockTitle(startedAt: Date | string): BlockTitle;
|
package/dist/blocks.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Blocks (D-UI-9, VOU-550). A block is a run of verified tasks by one
|
|
3
|
+
* agent in one category, close together in time. The API writes it as a
|
|
4
|
+
* task verifies (apps/api/src/blocks.ts), and every time on it is a
|
|
5
|
+
* server time, the tasks' verified_at.
|
|
6
|
+
*
|
|
7
|
+
* A verified task joins the agent's latest block when that block is of
|
|
8
|
+
* the task's category, ended under gapMinutes before the task verified
|
|
9
|
+
* and holds fewer than maxTasks tasks. Otherwise it starts a new block. So
|
|
10
|
+
* a change of category ends a block, and so does the cap. latest is how
|
|
11
|
+
* many blocks GET /v1/blocks/latest returns, for the home page.
|
|
12
|
+
* confirmers is how many posters of its tasks a block keeps (VOU-583),
|
|
13
|
+
* the first to have a task of theirs join it, for its confirmed by line.
|
|
14
|
+
*/
|
|
15
|
+
export const BLOCK = {
|
|
16
|
+
gapMinutes: 15,
|
|
17
|
+
maxTasks: 50,
|
|
18
|
+
latest: 10,
|
|
19
|
+
confirmers: 3,
|
|
20
|
+
};
|
|
21
|
+
/*
|
|
22
|
+
* The title of a block, worked out from its start by the UTC time of day,
|
|
23
|
+
* so a block has one title for every visitor and in every link preview.
|
|
24
|
+
* Each band runs from its hour to the next band's. No text from the agent,
|
|
25
|
+
* and not stored, so a changed band needs no migration.
|
|
26
|
+
*/
|
|
27
|
+
export const BLOCK_TITLE_BANDS = [
|
|
28
|
+
{ fromHour: 5, title: 'Morning block' },
|
|
29
|
+
{ fromHour: 12, title: 'Afternoon block' },
|
|
30
|
+
{ fromHour: 18, title: 'Evening block' },
|
|
31
|
+
{ fromHour: 23, title: 'Overnight block' },
|
|
32
|
+
];
|
|
33
|
+
// The title of a block that started at startedAt. Before the first band's
|
|
34
|
+
// hour it is still the night before, so overnight.
|
|
35
|
+
export function blockTitle(startedAt) {
|
|
36
|
+
const hour = new Date(startedAt).getUTCHours();
|
|
37
|
+
let title = 'Overnight block';
|
|
38
|
+
for (const band of BLOCK_TITLE_BANDS) {
|
|
39
|
+
if (hour >= band.fromHour)
|
|
40
|
+
title = band.title;
|
|
41
|
+
}
|
|
42
|
+
return title;
|
|
43
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const CLI_VERSION_HEADER = "X-SealKeeper-CLI-Version";
|
|
3
|
+
export declare const CLI_VERSION_MAX = 32;
|
|
4
|
+
export declare const NO_CLI_VERSION = "none";
|
|
5
|
+
export declare const CliVersion: z.ZodString;
|
|
6
|
+
export type CliVersion = z.infer<typeof CliVersion>;
|
|
7
|
+
export declare function compareCliVersions(a: string, b: string): number;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// Which CLI signed a request (VOU-454). The CLI sends its own version in
|
|
3
|
+
// this header on every signed request, and the API keeps one row per agent
|
|
4
|
+
// and version with the first and last UTC day it was seen, so it can tell
|
|
5
|
+
// when no CLI older than SEAL_V3_FIRST_CLI is left. Defined once here so
|
|
6
|
+
// the CLI and the API name the header and read its value the same way.
|
|
7
|
+
//
|
|
8
|
+
// The header is not signed, so the version is only what the caller says it
|
|
9
|
+
// is. It measures a rollout, and no trust decision ever reads it.
|
|
10
|
+
export const CLI_VERSION_HEADER = 'X-SealKeeper-CLI-Version';
|
|
11
|
+
// The most characters a CLI version may have. Room for a prerelease tag,
|
|
12
|
+
// and small, so a header can never grow a stored row.
|
|
13
|
+
export const CLI_VERSION_MAX = 32;
|
|
14
|
+
// What the API stores for a signed request with no valid version, a CLI
|
|
15
|
+
// from before the header or a value CliVersion refuses. A version starts
|
|
16
|
+
// with a digit, so this word can never be one.
|
|
17
|
+
export const NO_CLI_VERSION = 'none';
|
|
18
|
+
// A version as npm writes it, the semver.org grammar. Three numbers, an
|
|
19
|
+
// optional prerelease after a hyphen and optional build metadata after a
|
|
20
|
+
// plus. No number has a leading zero. Each of the three has at most 9
|
|
21
|
+
// digits, so it stays exact as a JavaScript number.
|
|
22
|
+
const NUM = '(?:0|[1-9]\\d{0,8})';
|
|
23
|
+
const PRE = '(?:0|[1-9]\\d*|\\d*[A-Za-z-][0-9A-Za-z-]*)';
|
|
24
|
+
const BUILD = '[0-9A-Za-z-]+';
|
|
25
|
+
const VERSION = new RegExp(`^(${NUM})\\.(${NUM})\\.(${NUM})(?:-(${PRE}(?:\\.${PRE})*))?(?:\\+${BUILD}(?:\\.${BUILD})*)?$`);
|
|
26
|
+
// The header's value. Anything else, an empty or over long value or one
|
|
27
|
+
// with a space or a control character, fails, and the API then treats the
|
|
28
|
+
// request as one with no header.
|
|
29
|
+
export const CliVersion = z
|
|
30
|
+
.string()
|
|
31
|
+
.max(CLI_VERSION_MAX)
|
|
32
|
+
.regex(VERSION, 'Expected a version such as 0.4.14');
|
|
33
|
+
function partsOf(version) {
|
|
34
|
+
const m = VERSION.exec(version);
|
|
35
|
+
if (!m)
|
|
36
|
+
throw new TypeError('Not a CLI version');
|
|
37
|
+
return {
|
|
38
|
+
core: [Number(m[1]), Number(m[2]), Number(m[3])],
|
|
39
|
+
pre: m[4] === undefined ? [] : m[4].split('.'),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const DIGITS = /^\d+$/;
|
|
43
|
+
// Two prerelease identifiers. Numbers compare as numbers and come before
|
|
44
|
+
// words, words compare in ASCII order. A number has no leading zero, so the
|
|
45
|
+
// longer one is the larger.
|
|
46
|
+
function compareIdentifiers(a, b) {
|
|
47
|
+
const an = DIGITS.test(a);
|
|
48
|
+
const bn = DIGITS.test(b);
|
|
49
|
+
if (an !== bn)
|
|
50
|
+
return an ? -1 : 1;
|
|
51
|
+
if (an && a.length !== b.length)
|
|
52
|
+
return a.length < b.length ? -1 : 1;
|
|
53
|
+
if (a === b)
|
|
54
|
+
return 0;
|
|
55
|
+
return a < b ? -1 : 1;
|
|
56
|
+
}
|
|
57
|
+
/*
|
|
58
|
+
* -1, 0 or 1 as version a comes before, with or after version b, by the
|
|
59
|
+
* semver.org precedence rules. The three numbers compare as numbers, so
|
|
60
|
+
* 0.4.9 comes before 0.4.11, which a text comparison gets wrong. A
|
|
61
|
+
* prerelease comes before its release, 0.4.11-rc.1 before 0.4.11, and
|
|
62
|
+
* build metadata is ignored. Both must be CliVersion values. Anything else,
|
|
63
|
+
* NO_CLI_VERSION included, throws a TypeError, so the caller decides what a
|
|
64
|
+
* missing version means.
|
|
65
|
+
*/
|
|
66
|
+
export function compareCliVersions(a, b) {
|
|
67
|
+
const x = partsOf(a);
|
|
68
|
+
const y = partsOf(b);
|
|
69
|
+
for (let i = 0; i < 3; i++) {
|
|
70
|
+
const d = x.core[i] - y.core[i];
|
|
71
|
+
if (d !== 0)
|
|
72
|
+
return Math.sign(d);
|
|
73
|
+
}
|
|
74
|
+
if (x.pre.length === 0 || y.pre.length === 0) {
|
|
75
|
+
return Math.sign(y.pre.length) - Math.sign(x.pre.length);
|
|
76
|
+
}
|
|
77
|
+
for (let i = 0; i < Math.max(x.pre.length, y.pre.length); i++) {
|
|
78
|
+
const p = x.pre[i];
|
|
79
|
+
const q = y.pre[i];
|
|
80
|
+
if (p === undefined)
|
|
81
|
+
return -1;
|
|
82
|
+
if (q === undefined)
|
|
83
|
+
return 1;
|
|
84
|
+
const d = compareIdentifiers(p, q);
|
|
85
|
+
if (d !== 0)
|
|
86
|
+
return d;
|
|
87
|
+
}
|
|
88
|
+
return 0;
|
|
89
|
+
}
|