@noldova/browser.protocol 0.0.0-stage → 0.0.2
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/LICENSE +21 -0
- package/README.md +6 -2
- package/package.json +44 -4
- package/src/api/index.d.ts +1767 -0
- package/src/api/index.js +35 -0
- package/src/enums/address-kind.js +14 -0
- package/src/enums/page-action.js +15 -0
- package/src/enums/page-activity-state.js +12 -0
- package/src/enums/typed-address-answer-kind.js +11 -0
- package/src/enums/typed-address-refusal.js +15 -0
- package/src/models/address-kinds.js +62 -0
- package/src/models/browser-events.js +10 -0
- package/src/models/browser-methods.js +23 -0
- package/src/models/browser-tool-names.js +30 -0
- package/src/models/browsing-data-request.js +25 -0
- package/src/models/held-pages.js +29 -0
- package/src/models/local-sites.js +46 -0
- package/src/models/open-pages-request.js +25 -0
- package/src/models/page-activity.js +69 -0
- package/src/models/page-agent.js +27 -0
- package/src/models/page-box.js +43 -0
- package/src/models/page-change-script.js +53 -0
- package/src/models/page-claim.js +40 -0
- package/src/models/page-point.js +32 -0
- package/src/models/page-record.js +29 -0
- package/src/models/page-refusal.js +33 -0
- package/src/models/page-request.js +25 -0
- package/src/models/page-stop-request.js +27 -0
- package/src/models/typed-address-allowed.js +30 -0
- package/src/models/typed-address-refused.js +32 -0
- package/src/models/typed-address-request.js +27 -0
- package/src/models/typed-redirect-request.js +29 -0
- package/src/resources.js +73 -0
- package/src/services/typed-address-answer.reader.js +19 -0
- package/src/services/wire-contract.js +28 -0
- package/src/types/browser-tool-name.js +8 -0
- package/src/types/typed-address-answer.js +8 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { ArgumentException } from "@noldova/context.exceptions";
|
|
9
|
+
import { JsonReader } from "@noldova/context.json";
|
|
10
|
+
import { Resources } from "../resources.js";
|
|
11
|
+
import { WireContract } from "../services/wire-contract.js";
|
|
12
|
+
export class PageRefusal {
|
|
13
|
+
static FIELDS = [Resources.urlField, Resources.originField];
|
|
14
|
+
url;
|
|
15
|
+
origin;
|
|
16
|
+
constructor(url, origin) {
|
|
17
|
+
const parsed = URL.parse(url);
|
|
18
|
+
if (parsed === null || !Resources.webSchemes.includes(parsed.protocol))
|
|
19
|
+
throw new ArgumentException(Resources.refusalUrlNotWeb, Resources.urlField);
|
|
20
|
+
if (parsed.origin !== origin)
|
|
21
|
+
throw new ArgumentException(Resources.refusalOriginDiffers, Resources.originField);
|
|
22
|
+
this.url = url;
|
|
23
|
+
this.origin = origin;
|
|
24
|
+
}
|
|
25
|
+
static fromJson(value, path) {
|
|
26
|
+
const reader = JsonReader.fromValue(value, path);
|
|
27
|
+
WireContract.requireKnownFields(reader, PageRefusal.FIELDS);
|
|
28
|
+
return WireContract.create(reader, () => new PageRefusal(reader.readString(Resources.urlField), reader.readString(Resources.originField)));
|
|
29
|
+
}
|
|
30
|
+
toJson() {
|
|
31
|
+
return { [Resources.urlField]: this.url, [Resources.originField]: this.origin };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { WireContract } from "../services/wire-contract.js";
|
|
11
|
+
export class PageRequest {
|
|
12
|
+
static FIELDS = [Resources.instanceField];
|
|
13
|
+
instance;
|
|
14
|
+
constructor(instance) {
|
|
15
|
+
this.instance = instance;
|
|
16
|
+
}
|
|
17
|
+
static fromJson(value, path) {
|
|
18
|
+
const reader = JsonReader.fromValue(value, path);
|
|
19
|
+
WireContract.requireKnownFields(reader, PageRequest.FIELDS);
|
|
20
|
+
return new PageRequest(reader.readString(Resources.instanceField));
|
|
21
|
+
}
|
|
22
|
+
toJson() {
|
|
23
|
+
return { [Resources.instanceField]: this.instance };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { WireContract } from "../services/wire-contract.js";
|
|
11
|
+
export class PageStopRequest {
|
|
12
|
+
static FIELDS = [Resources.instanceField, Resources.isTakingOverField];
|
|
13
|
+
instance;
|
|
14
|
+
isTakingOver;
|
|
15
|
+
constructor(instance, isTakingOver) {
|
|
16
|
+
this.instance = instance;
|
|
17
|
+
this.isTakingOver = isTakingOver;
|
|
18
|
+
}
|
|
19
|
+
static fromJson(value, path) {
|
|
20
|
+
const reader = JsonReader.fromValue(value, path);
|
|
21
|
+
WireContract.requireKnownFields(reader, PageStopRequest.FIELDS);
|
|
22
|
+
return new PageStopRequest(reader.readString(Resources.instanceField), reader.readBoolean(Resources.isTakingOverField));
|
|
23
|
+
}
|
|
24
|
+
toJson() {
|
|
25
|
+
return { [Resources.instanceField]: this.instance, [Resources.isTakingOverField]: this.isTakingOver };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { TypedAddressAnswerKind } from "../enums/typed-address-answer-kind.js";
|
|
10
|
+
import { Resources } from "../resources.js";
|
|
11
|
+
import { WireContract } from "../services/wire-contract.js";
|
|
12
|
+
export class TypedAddressAllowed {
|
|
13
|
+
static FIELDS = [Resources.kindField, Resources.originField];
|
|
14
|
+
static KINDS = [TypedAddressAnswerKind.Allowed];
|
|
15
|
+
kind;
|
|
16
|
+
origin;
|
|
17
|
+
constructor(origin) {
|
|
18
|
+
this.kind = TypedAddressAnswerKind.Allowed;
|
|
19
|
+
this.origin = origin;
|
|
20
|
+
}
|
|
21
|
+
static fromJson(value, path) {
|
|
22
|
+
const reader = JsonReader.fromValue(value, path);
|
|
23
|
+
WireContract.requireKnownFields(reader, TypedAddressAllowed.FIELDS);
|
|
24
|
+
reader.readOneOf(Resources.kindField, TypedAddressAllowed.KINDS);
|
|
25
|
+
return new TypedAddressAllowed(reader.readString(Resources.originField));
|
|
26
|
+
}
|
|
27
|
+
toJson() {
|
|
28
|
+
return { [Resources.kindField]: this.kind, [Resources.originField]: this.origin };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { TypedAddressAnswerKind } from "../enums/typed-address-answer-kind.js";
|
|
10
|
+
import { TypedAddressRefusal } from "../enums/typed-address-refusal.js";
|
|
11
|
+
import { Resources } from "../resources.js";
|
|
12
|
+
import { WireContract } from "../services/wire-contract.js";
|
|
13
|
+
export class TypedAddressRefused {
|
|
14
|
+
static FIELDS = [Resources.kindField, Resources.reasonField];
|
|
15
|
+
static KINDS = [TypedAddressAnswerKind.Refused];
|
|
16
|
+
static REASONS = Object.values(TypedAddressRefusal);
|
|
17
|
+
kind;
|
|
18
|
+
reason;
|
|
19
|
+
constructor(reason) {
|
|
20
|
+
this.kind = TypedAddressAnswerKind.Refused;
|
|
21
|
+
this.reason = reason;
|
|
22
|
+
}
|
|
23
|
+
static fromJson(value, path) {
|
|
24
|
+
const reader = JsonReader.fromValue(value, path);
|
|
25
|
+
WireContract.requireKnownFields(reader, TypedAddressRefused.FIELDS);
|
|
26
|
+
reader.readOneOf(Resources.kindField, TypedAddressRefused.KINDS);
|
|
27
|
+
return new TypedAddressRefused(reader.readOneOf(Resources.reasonField, TypedAddressRefused.REASONS));
|
|
28
|
+
}
|
|
29
|
+
toJson() {
|
|
30
|
+
return { [Resources.kindField]: this.kind, [Resources.reasonField]: this.reason };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { WireContract } from "../services/wire-contract.js";
|
|
11
|
+
export class TypedAddressRequest {
|
|
12
|
+
static FIELDS = [Resources.profileKeyField, Resources.urlField];
|
|
13
|
+
profileKey;
|
|
14
|
+
url;
|
|
15
|
+
constructor(profileKey, url) {
|
|
16
|
+
this.profileKey = profileKey;
|
|
17
|
+
this.url = url;
|
|
18
|
+
}
|
|
19
|
+
static fromJson(value, path) {
|
|
20
|
+
const reader = JsonReader.fromValue(value, path);
|
|
21
|
+
WireContract.requireKnownFields(reader, TypedAddressRequest.FIELDS);
|
|
22
|
+
return new TypedAddressRequest(reader.readString(Resources.profileKeyField), reader.readString(Resources.urlField));
|
|
23
|
+
}
|
|
24
|
+
toJson() {
|
|
25
|
+
return { [Resources.profileKeyField]: this.profileKey, [Resources.urlField]: this.url };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { WireContract } from "../services/wire-contract.js";
|
|
11
|
+
export class TypedRedirectRequest {
|
|
12
|
+
static FIELDS = [Resources.instanceField, Resources.profileKeyField, Resources.urlField];
|
|
13
|
+
instance;
|
|
14
|
+
profileKey;
|
|
15
|
+
url;
|
|
16
|
+
constructor(instance, profileKey, url) {
|
|
17
|
+
this.instance = instance;
|
|
18
|
+
this.profileKey = profileKey;
|
|
19
|
+
this.url = url;
|
|
20
|
+
}
|
|
21
|
+
static fromJson(value, path) {
|
|
22
|
+
const reader = JsonReader.fromValue(value, path);
|
|
23
|
+
WireContract.requireKnownFields(reader, TypedRedirectRequest.FIELDS);
|
|
24
|
+
return new TypedRedirectRequest(reader.readString(Resources.instanceField), reader.readString(Resources.profileKeyField), reader.readString(Resources.urlField));
|
|
25
|
+
}
|
|
26
|
+
toJson() {
|
|
27
|
+
return { [Resources.instanceField]: this.instance, [Resources.profileKeyField]: this.profileKey, [Resources.urlField]: this.url };
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/resources.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export class Resources {
|
|
9
|
+
static ipv4Pattern = /^\d{1,3}(?:\.\d{1,3}){3}$/u;
|
|
10
|
+
static ipv4PartSeparator = ".";
|
|
11
|
+
static ipv4PartMaximum = 255;
|
|
12
|
+
static ipv4LoopbackNetwork = 127;
|
|
13
|
+
static ipv4PrivateRanges = [[10, 0, 255], [172, 16, 31], [192, 168, 168], [100, 64, 127]];
|
|
14
|
+
static ipv4LinkLocalRange = [169, 254, 254];
|
|
15
|
+
static ipv6Opening = "[";
|
|
16
|
+
static ipv6ZeroRun = "::";
|
|
17
|
+
static ipv6PieceSeparator = ":";
|
|
18
|
+
static loopbackName = "localhost";
|
|
19
|
+
static loopbackSuffix = ".localhost";
|
|
20
|
+
static trailingDotsPattern = /\.+$/u;
|
|
21
|
+
static ipv4Bits = 32n;
|
|
22
|
+
static ipv4Mask = 0xffffffffn;
|
|
23
|
+
static mappedPrefix = 0xffffn;
|
|
24
|
+
static nat64Prefix = 0x0064ff9b0000000000000000n;
|
|
25
|
+
static uniqueLocalPrefix = 0xfc00n >> 9n;
|
|
26
|
+
static uniqueLocalShift = 121n;
|
|
27
|
+
static linkLocalPrefix = 0xfe80n >> 6n;
|
|
28
|
+
static linkLocalShift = 118n;
|
|
29
|
+
static localSitesSeparator = ",";
|
|
30
|
+
static webSchemes = ["http:", "https:"];
|
|
31
|
+
static wildcardPattern = /[*%]/u;
|
|
32
|
+
static emptyLabelPattern = /^\.|\.\./u;
|
|
33
|
+
static actionField = "action";
|
|
34
|
+
static activityField = "activity";
|
|
35
|
+
static agentNameField = "agentName";
|
|
36
|
+
static agentsField = "agents";
|
|
37
|
+
static boxField = "box";
|
|
38
|
+
static heightField = "height";
|
|
39
|
+
static instanceField = "instance";
|
|
40
|
+
static instancesField = "instances";
|
|
41
|
+
static isClaimedField = "isClaimed";
|
|
42
|
+
static isHandedOverField = "isHandedOver";
|
|
43
|
+
static isHereField = "isHere";
|
|
44
|
+
static isTakingOverField = "isTakingOver";
|
|
45
|
+
static kindField = "kind";
|
|
46
|
+
static originField = "origin";
|
|
47
|
+
static pointField = "point";
|
|
48
|
+
static profileKeyField = "profileKey";
|
|
49
|
+
static reasonField = "reason";
|
|
50
|
+
static recordField = "record";
|
|
51
|
+
static refusalField = "refusal";
|
|
52
|
+
static refusedField = "refused";
|
|
53
|
+
static stateField = "state";
|
|
54
|
+
static urlField = "url";
|
|
55
|
+
static widthField = "width";
|
|
56
|
+
static xField = "x";
|
|
57
|
+
static yField = "y";
|
|
58
|
+
static fieldPathSeparator = ".";
|
|
59
|
+
static unknownField = "The field isn't part of the message.";
|
|
60
|
+
static coordinateNotFinite = "The coordinate isn't a finite number.";
|
|
61
|
+
static sizeNegative = "The size isn't a finite number of zero or more.";
|
|
62
|
+
static refusalUrlNotWeb = "The address isn't an http or https address.";
|
|
63
|
+
static refusalOriginDiffers = "The origin isn't the address's origin.";
|
|
64
|
+
static formatFieldPath(parent, name) {
|
|
65
|
+
return `${parent}${Resources.fieldPathSeparator}${name}`;
|
|
66
|
+
}
|
|
67
|
+
static formatHexPiece(piece) {
|
|
68
|
+
return `0x${piece}`;
|
|
69
|
+
}
|
|
70
|
+
static formatOriginRoot(origin) {
|
|
71
|
+
return `${origin}/`;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { TypedAddressAnswerKind } from "../enums/typed-address-answer-kind.js";
|
|
10
|
+
import { TypedAddressAllowed } from "../models/typed-address-allowed.js";
|
|
11
|
+
import { TypedAddressRefused } from "../models/typed-address-refused.js";
|
|
12
|
+
import { Resources } from "../resources.js";
|
|
13
|
+
export class TypedAddressAnswerReader {
|
|
14
|
+
static KINDS = Object.values(TypedAddressAnswerKind);
|
|
15
|
+
static read(value, path) {
|
|
16
|
+
const kind = JsonReader.fromValue(value, path).readOneOf(Resources.kindField, TypedAddressAnswerReader.KINDS);
|
|
17
|
+
return kind === TypedAddressAnswerKind.Allowed ? TypedAddressAllowed.fromJson(value, path) : TypedAddressRefused.fromJson(value, path);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { ArgumentException, ExceptionOptions } from "@noldova/context.exceptions";
|
|
9
|
+
import { JsonException } from "@noldova/context.json";
|
|
10
|
+
import { Resources } from "../resources.js";
|
|
11
|
+
export class WireContract {
|
|
12
|
+
static requireKnownFields(reader, fields) {
|
|
13
|
+
const unknown = Object.keys(reader.toJson()).find(t => !fields.includes(t));
|
|
14
|
+
if (unknown !== undefined)
|
|
15
|
+
throw new JsonException(Resources.unknownField, Resources.formatFieldPath(reader.path, unknown));
|
|
16
|
+
}
|
|
17
|
+
static create(reader, factory) {
|
|
18
|
+
try {
|
|
19
|
+
return factory();
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (!(error instanceof ArgumentException))
|
|
23
|
+
throw error;
|
|
24
|
+
const path = error.parameterName === undefined ? reader.path : Resources.formatFieldPath(reader.path, error.parameterName);
|
|
25
|
+
throw new JsonException(error.message, path, new ExceptionOptions(error));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|