querysub 0.432.0 → 0.436.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.
Files changed (74) hide show
  1. package/.eslintrc.js +50 -50
  2. package/bin/deploy.js +0 -0
  3. package/bin/function.js +0 -0
  4. package/bin/server.js +0 -0
  5. package/costsBenefits.txt +115 -115
  6. package/deploy.ts +2 -2
  7. package/package.json +1 -1
  8. package/spec.txt +1192 -1192
  9. package/src/-a-archives/archives.ts +202 -202
  10. package/src/-a-archives/archivesBackBlaze.ts +1 -0
  11. package/src/-a-archives/archivesDisk.ts +454 -454
  12. package/src/-a-auth/certs.ts +540 -540
  13. package/src/-a-auth/node-forge-ed25519.d.ts +16 -16
  14. package/src/-b-authorities/dnsAuthority.ts +138 -138
  15. package/src/-c-identity/IdentityController.ts +258 -258
  16. package/src/-d-trust/NetworkTrust2.ts +180 -180
  17. package/src/-e-certs/EdgeCertController.ts +252 -252
  18. package/src/-e-certs/certAuthority.ts +201 -201
  19. package/src/-f-node-discovery/NodeDiscovery.ts +640 -640
  20. package/src/-g-core-values/NodeCapabilities.ts +200 -200
  21. package/src/-h-path-value-serialize/stringSerializer.ts +175 -175
  22. package/src/0-path-value-core/PathValueCommitter.ts +468 -468
  23. package/src/0-path-value-core/pathValueCore.ts +2 -2
  24. package/src/2-proxy/PathValueProxyWatcher.ts +2542 -2542
  25. package/src/2-proxy/TransactionDelayer.ts +94 -94
  26. package/src/2-proxy/pathDatabaseProxyBase.ts +36 -36
  27. package/src/2-proxy/pathValueProxy.ts +159 -159
  28. package/src/3-path-functions/PathFunctionRunnerMain.ts +87 -87
  29. package/src/3-path-functions/pathFunctionLoader.ts +516 -512
  30. package/src/3-path-functions/tests/rejectTest.ts +76 -76
  31. package/src/4-deploy/deployCheck.ts +6 -6
  32. package/src/4-dom/css.tsx +29 -29
  33. package/src/4-dom/cssTypes.d.ts +211 -211
  34. package/src/4-dom/qreact.tsx +2799 -2799
  35. package/src/4-dom/qreactTest.tsx +410 -410
  36. package/src/4-querysub/permissions.ts +335 -335
  37. package/src/4-querysub/querysubPrediction.ts +483 -483
  38. package/src/5-diagnostics/qreactDebug.tsx +346 -346
  39. package/src/TestController.ts +34 -34
  40. package/src/bits.ts +104 -104
  41. package/src/buffers.ts +69 -69
  42. package/src/diagnostics/ActionsHistory.ts +57 -57
  43. package/src/diagnostics/listenOnDebugger.ts +71 -71
  44. package/src/diagnostics/periodic.ts +111 -111
  45. package/src/diagnostics/trackResources.ts +91 -91
  46. package/src/diagnostics/watchdog.ts +120 -120
  47. package/src/errors.ts +133 -133
  48. package/src/forceProduction.ts +2 -2
  49. package/src/fs.ts +80 -80
  50. package/src/functional/diff.ts +857 -857
  51. package/src/functional/promiseCache.ts +78 -78
  52. package/src/functional/random.ts +8 -8
  53. package/src/functional/stats.ts +60 -60
  54. package/src/heapDumps.ts +665 -665
  55. package/src/https.ts +1 -1
  56. package/src/library-components/AspectSizedComponent.tsx +87 -87
  57. package/src/library-components/ButtonSelector.tsx +64 -64
  58. package/src/library-components/DropdownCustom.tsx +150 -150
  59. package/src/library-components/DropdownSelector.tsx +31 -31
  60. package/src/library-components/InlinePopup.tsx +66 -66
  61. package/src/misc/color.ts +29 -29
  62. package/src/misc/hash.ts +83 -83
  63. package/src/misc/ipPong.js +13 -13
  64. package/src/misc/networking.ts +1 -1
  65. package/src/misc/random.ts +44 -44
  66. package/src/misc.ts +196 -196
  67. package/src/path.ts +255 -255
  68. package/src/persistentLocalStore.ts +41 -41
  69. package/src/promise.ts +14 -14
  70. package/src/storage/fileSystemPointer.ts +71 -71
  71. package/src/test/heapProcess.ts +35 -35
  72. package/src/zip.ts +15 -15
  73. package/tsconfig.json +26 -26
  74. package/yarnSpec.txt +56 -56
@@ -1,17 +1,17 @@
1
-
2
-
3
- declare module "node-forge" {
4
- declare type Ed25519PublicKey = {
5
- publicKeyBytes: Buffer;
6
- } & Buffer;
7
- declare type Ed25519PrivateKey = {
8
- privateKeyBytes: Buffer;
9
- } & Buffer;
10
- class ed25519 {
11
- static generateKeyPair(): { publicKey: Ed25519PublicKey, privateKey: Ed25519PrivateKey };
12
- static privateKeyToPem(key: Ed25519PrivateKey): string;
13
- static privateKeyFromPem(pem: string): Ed25519PrivateKey;
14
- static publicKeyToPem(key: Ed25519PublicKey): string;
15
- static publicKeyFromPem(pem: string): Ed25519PublicKey;
16
- }
1
+
2
+
3
+ declare module "node-forge" {
4
+ declare type Ed25519PublicKey = {
5
+ publicKeyBytes: Buffer;
6
+ } & Buffer;
7
+ declare type Ed25519PrivateKey = {
8
+ privateKeyBytes: Buffer;
9
+ } & Buffer;
10
+ class ed25519 {
11
+ static generateKeyPair(): { publicKey: Ed25519PublicKey, privateKey: Ed25519PrivateKey };
12
+ static privateKeyToPem(key: Ed25519PrivateKey): string;
13
+ static privateKeyFromPem(pem: string): Ed25519PrivateKey;
14
+ static publicKeyToPem(key: Ed25519PublicKey): string;
15
+ static publicKeyFromPem(pem: string): Ed25519PublicKey;
16
+ }
17
17
  }
@@ -1,139 +1,139 @@
1
- import os from "os";
2
- import * as fs from "fs";
3
- import { cache, lazy } from "socket-function/src/caching";
4
- import { isNode, isNodeTrue } from "socket-function/src/misc";
5
- import { httpsRequest } from "../https";
6
- import { getStorageDir } from "../fs";
7
- import { SocketFunction } from "socket-function/SocketFunction";
8
- import { delay } from "socket-function/src/batching";
9
- import debugbreak from "debugbreak";
10
- import { isClient } from "../config2";
11
- import { getArchives } from "../-a-archives/archives";
12
- import { cloudflareCall, cloudflareGETCall, cloudflarePOSTCall, getCloudflareCreds } from "./cloudflareHelpers";
13
- import { magenta } from "socket-function/src/formatting/logColors";
14
-
15
- const DNS_TTLSeconds = {
16
- "TXT": 60,
17
- "A": 60,
18
- };
19
-
20
- export const hasDNSWritePermissions = lazy(async () => {
21
- if (!isNode()) return false;
22
- if (isClient()) return false;
23
- try {
24
- await getCloudflareCreds();
25
- return true;
26
- } catch {
27
- return false;
28
- }
29
- });
30
-
31
- export const getZoneId = cache(async (rootDomain: string): Promise<string> => {
32
- let zones = await cloudflareGETCall<{ id: string; name: string }[]>("/zones", {});
33
- let selected = zones.find(x => x.name === rootDomain);
34
- if (!selected) {
35
- throw new Error(`Could not find zone for ${rootDomain}. Found ${zones.map(x => x.name).join(", ")}`);
36
- }
37
- return selected.id;
38
- });
39
-
40
- function getRootDomain(key: string) {
41
- if (key.endsWith(".")) {
42
- key = key.slice(0, -1);
43
- }
44
- return key.split(".").slice(-2).join(".");
45
- }
46
-
47
- export async function getRecordsRaw(type: string, key: string) {
48
- if (key.endsWith(".")) key = key.slice(0, -1);
49
- let zoneId = await getZoneId(getRootDomain(key));
50
- let results = await cloudflareGETCall<{
51
- id: string;
52
- type: string;
53
- name: string;
54
- content: string;
55
- proxied: boolean;
56
- }[]>(`/zones/${zoneId}/dns_records`);
57
- return results.filter(x => x.type === type && x.name === key);
58
- }
59
- export async function getRecords(type: string, key: string) {
60
- if (key.endsWith(".")) key = key.slice(0, -1);
61
- let raw = await getRecordsRaw(type, key);
62
- return raw.map(x => x.content);
63
- }
64
- export async function deleteRecord(type: string, key: string, value: string) {
65
- if (key.endsWith(".")) key = key.slice(0, -1);
66
- let zoneId = await getZoneId(getRootDomain(key));
67
- let prevValues = await getRecordsRaw(type, key);
68
- prevValues = prevValues.filter(x => x.content === value);
69
- if (prevValues.length === 0) {
70
- if (!SocketFunction.silent) {
71
- console.log(`No need to delete record, it was not found. ${JSON.stringify(value)} value was not in ${type} for ${key}, values ${JSON.stringify(prevValues.map(x => x.content))}`);
72
- }
73
- return;
74
- }
75
-
76
- console.log(`Removing records of ${type} for ${key}, values ${JSON.stringify(prevValues.map(x => x.content))}`);
77
- for (let value of prevValues) {
78
- await cloudflareCall(`/zones/${zoneId}/dns_records/${value.id}`, Buffer.from([]), "DELETE");
79
- }
80
- }
81
- /** Removes all existing records (unless the record is already present) */
82
- export async function setRecord(type: string, key: string, value: string, proxied?: "proxied") {
83
- let stack = new Error();
84
- if (key.endsWith(".")) key = key.slice(0, -1);
85
- let zoneId = await getZoneId(getRootDomain(key));
86
- let prevValues = await getRecordsRaw(type, key);
87
- // NOTE: Apparently if we try to update by just changing proxied, cloudflare complains and
88
- // says "an identical record already exists", even though it doesn't, we changed the proxied value...
89
- if (prevValues.some(x => x.content === value)) return;
90
-
91
- console.log(magenta(`Removing previous records of ${type} for ${key} ${JSON.stringify(prevValues.map(x => x.content))}`));
92
- let didDeletions = false;
93
- for (let value of prevValues) {
94
- didDeletions = true;
95
- await cloudflareCall(`/zones/${zoneId}/dns_records/${value.id}`, Buffer.from([]), "DELETE");
96
- }
97
-
98
- console.log(magenta(`Setting ${type} record for ${key} to ${value} (previously had ${JSON.stringify(prevValues.map(x => x.content))})`));
99
- const ttl = DNS_TTLSeconds[type as "A"] || 60;
100
- await cloudflarePOSTCall(`/zones/${zoneId}/dns_records`, {
101
- type: type,
102
- name: key,
103
- content: value,
104
- ttl,
105
- proxied: proxied === "proxied",
106
- });
107
- // NOTE: Apparently... even if the record didn't exist, we still have to wait...
108
- console.log(`Waiting ${ttl} seconds for DNS to propagate...`);
109
- for (let ttlLeft = ttl; ttlLeft > 0; ttlLeft--) {
110
- await delay(1000);
111
- console.log(`${ttlLeft} seconds left...`);
112
- }
113
- console.log(`Done waiting for DNS to update.`);
114
-
115
- }
116
- /** Keeps existing records */
117
- export async function addRecord(type: string, key: string, value: string, proxied?: "proxied") {
118
- if (key.endsWith(".")) key = key.slice(0, -1);
119
- let zoneId = await getZoneId(getRootDomain(key));
120
- let prevValues = await getRecordsRaw(type, key);
121
- // NOTE: Apparently if we try to update by just changing proxied, cloudflare complains and
122
- // says "an identical record already exists", even though it doesn't, we changed the proxied value...
123
- if (prevValues.some(x => x.content === value)) return;
124
- console.log(`Adding ${type} record for ${key} to ${value} (previously had ${JSON.stringify(prevValues.map(x => x.content))})`);
125
- const ttl = DNS_TTLSeconds[type as "A"] || 60;
126
- await cloudflarePOSTCall(`/zones/${zoneId}/dns_records`, {
127
- type: type,
128
- name: key,
129
- content: value,
130
- ttl,
131
- proxied: proxied === "proxied",
132
- });
133
- console.log(`Waiting ${ttl} seconds for DNS to propagate...`);
134
- for (let ttlLeft = ttl; ttlLeft > 0; ttlLeft--) {
135
- await delay(1000);
136
- console.log(`${ttlLeft} seconds left...`);
137
- }
138
- console.log(`Done waiting for DNS to update.`);
1
+ import os from "os";
2
+ import * as fs from "fs";
3
+ import { cache, lazy } from "socket-function/src/caching";
4
+ import { isNode, isNodeTrue } from "socket-function/src/misc";
5
+ import { httpsRequest } from "../https";
6
+ import { getStorageDir } from "../fs";
7
+ import { SocketFunction } from "socket-function/SocketFunction";
8
+ import { delay } from "socket-function/src/batching";
9
+ import debugbreak from "debugbreak";
10
+ import { isClient } from "../config2";
11
+ import { getArchives } from "../-a-archives/archives";
12
+ import { cloudflareCall, cloudflareGETCall, cloudflarePOSTCall, getCloudflareCreds } from "./cloudflareHelpers";
13
+ import { magenta } from "socket-function/src/formatting/logColors";
14
+
15
+ const DNS_TTLSeconds = {
16
+ "TXT": 60,
17
+ "A": 60,
18
+ };
19
+
20
+ export const hasDNSWritePermissions = lazy(async () => {
21
+ if (!isNode()) return false;
22
+ if (isClient()) return false;
23
+ try {
24
+ await getCloudflareCreds();
25
+ return true;
26
+ } catch {
27
+ return false;
28
+ }
29
+ });
30
+
31
+ export const getZoneId = cache(async (rootDomain: string): Promise<string> => {
32
+ let zones = await cloudflareGETCall<{ id: string; name: string }[]>("/zones", {});
33
+ let selected = zones.find(x => x.name === rootDomain);
34
+ if (!selected) {
35
+ throw new Error(`Could not find zone for ${rootDomain}. Found ${zones.map(x => x.name).join(", ")}`);
36
+ }
37
+ return selected.id;
38
+ });
39
+
40
+ function getRootDomain(key: string) {
41
+ if (key.endsWith(".")) {
42
+ key = key.slice(0, -1);
43
+ }
44
+ return key.split(".").slice(-2).join(".");
45
+ }
46
+
47
+ export async function getRecordsRaw(type: string, key: string) {
48
+ if (key.endsWith(".")) key = key.slice(0, -1);
49
+ let zoneId = await getZoneId(getRootDomain(key));
50
+ let results = await cloudflareGETCall<{
51
+ id: string;
52
+ type: string;
53
+ name: string;
54
+ content: string;
55
+ proxied: boolean;
56
+ }[]>(`/zones/${zoneId}/dns_records`);
57
+ return results.filter(x => x.type === type && x.name === key);
58
+ }
59
+ export async function getRecords(type: string, key: string) {
60
+ if (key.endsWith(".")) key = key.slice(0, -1);
61
+ let raw = await getRecordsRaw(type, key);
62
+ return raw.map(x => x.content);
63
+ }
64
+ export async function deleteRecord(type: string, key: string, value: string) {
65
+ if (key.endsWith(".")) key = key.slice(0, -1);
66
+ let zoneId = await getZoneId(getRootDomain(key));
67
+ let prevValues = await getRecordsRaw(type, key);
68
+ prevValues = prevValues.filter(x => x.content === value);
69
+ if (prevValues.length === 0) {
70
+ if (!SocketFunction.silent) {
71
+ console.log(`No need to delete record, it was not found. ${JSON.stringify(value)} value was not in ${type} for ${key}, values ${JSON.stringify(prevValues.map(x => x.content))}`);
72
+ }
73
+ return;
74
+ }
75
+
76
+ console.log(`Removing records of ${type} for ${key}, values ${JSON.stringify(prevValues.map(x => x.content))}`);
77
+ for (let value of prevValues) {
78
+ await cloudflareCall(`/zones/${zoneId}/dns_records/${value.id}`, Buffer.from([]), "DELETE");
79
+ }
80
+ }
81
+ /** Removes all existing records (unless the record is already present) */
82
+ export async function setRecord(type: string, key: string, value: string, proxied?: "proxied") {
83
+ let stack = new Error();
84
+ if (key.endsWith(".")) key = key.slice(0, -1);
85
+ let zoneId = await getZoneId(getRootDomain(key));
86
+ let prevValues = await getRecordsRaw(type, key);
87
+ // NOTE: Apparently if we try to update by just changing proxied, cloudflare complains and
88
+ // says "an identical record already exists", even though it doesn't, we changed the proxied value...
89
+ if (prevValues.some(x => x.content === value)) return;
90
+
91
+ console.log(magenta(`Removing previous records of ${type} for ${key} ${JSON.stringify(prevValues.map(x => x.content))}`));
92
+ let didDeletions = false;
93
+ for (let value of prevValues) {
94
+ didDeletions = true;
95
+ await cloudflareCall(`/zones/${zoneId}/dns_records/${value.id}`, Buffer.from([]), "DELETE");
96
+ }
97
+
98
+ console.log(magenta(`Setting ${type} record for ${key} to ${value} (previously had ${JSON.stringify(prevValues.map(x => x.content))})`));
99
+ const ttl = DNS_TTLSeconds[type as "A"] || 60;
100
+ await cloudflarePOSTCall(`/zones/${zoneId}/dns_records`, {
101
+ type: type,
102
+ name: key,
103
+ content: value,
104
+ ttl,
105
+ proxied: proxied === "proxied",
106
+ });
107
+ // NOTE: Apparently... even if the record didn't exist, we still have to wait...
108
+ console.log(`Waiting ${ttl} seconds for DNS to propagate...`);
109
+ for (let ttlLeft = ttl; ttlLeft > 0; ttlLeft--) {
110
+ await delay(1000);
111
+ console.log(`${ttlLeft} seconds left...`);
112
+ }
113
+ console.log(`Done waiting for DNS to update.`);
114
+
115
+ }
116
+ /** Keeps existing records */
117
+ export async function addRecord(type: string, key: string, value: string, proxied?: "proxied") {
118
+ if (key.endsWith(".")) key = key.slice(0, -1);
119
+ let zoneId = await getZoneId(getRootDomain(key));
120
+ let prevValues = await getRecordsRaw(type, key);
121
+ // NOTE: Apparently if we try to update by just changing proxied, cloudflare complains and
122
+ // says "an identical record already exists", even though it doesn't, we changed the proxied value...
123
+ if (prevValues.some(x => x.content === value)) return;
124
+ console.log(`Adding ${type} record for ${key} to ${value} (previously had ${JSON.stringify(prevValues.map(x => x.content))})`);
125
+ const ttl = DNS_TTLSeconds[type as "A"] || 60;
126
+ await cloudflarePOSTCall(`/zones/${zoneId}/dns_records`, {
127
+ type: type,
128
+ name: key,
129
+ content: value,
130
+ ttl,
131
+ proxied: proxied === "proxied",
132
+ });
133
+ console.log(`Waiting ${ttl} seconds for DNS to propagate...`);
134
+ for (let ttlLeft = ttl; ttlLeft > 0; ttlLeft--) {
135
+ await delay(1000);
136
+ console.log(`${ttlLeft} seconds left...`);
137
+ }
138
+ console.log(`Done waiting for DNS to update.`);
139
139
  }