js-dos 7.2.7 → 7.3.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 (46) hide show
  1. package/3rdparty/zip.js/zip-no-worker-inflate.min.js +1 -0
  2. package/README.md +74 -13
  3. package/dist/js-dos.css +71 -8
  4. package/dist/js-dos.js +2 -2
  5. package/dist/js-dos.js.map +1 -1
  6. package/dist/types/src/backend/{jj → v7}/latency.d.ts +0 -0
  7. package/dist/types/src/backend/v7/v7-config.d.ts +12 -4
  8. package/dist/types/src/components/action-save-or-exit.d.ts +2 -0
  9. package/dist/types/src/components/sidebar/token/token-add-time.d.ts +2 -0
  10. package/dist/types/src/components/sidebar/token/token-select.d.ts +2 -0
  11. package/dist/types/src/components/sidebar/token/token.d.ts +15 -0
  12. package/dist/types/src/icons.d.ts +3 -0
  13. package/dist/types/src/player-app.d.ts +3 -4
  14. package/dist/types/src/request.d.ts +1 -0
  15. package/dist/wdosbox.js +2 -2
  16. package/dist/wdosbox.js.symbols +3129 -3133
  17. package/dist/wdosbox.wasm +0 -0
  18. package/examples/digger/index.html +1 -0
  19. package/package.json +2 -2
  20. package/.github/workflows/codeql-analysis.yml +0 -70
  21. package/.github/workflows/yarn-gulp.yml +0 -30
  22. package/dist/types/src/backend/jj/jj-config.d.ts +0 -6
  23. package/dist/types/src/components/action-exit.d.ts +0 -2
  24. package/dist/types/src/components/sidebar/active-token.d.ts +0 -2
  25. package/dist/types/src/components/sidebar/create-token.d.ts +0 -2
  26. package/v7-services/.env +0 -6
  27. package/v7-services/ok.yaml +0 -24
  28. package/v7-services/package.json +0 -17
  29. package/v7-services/redeploy-ok.sh +0 -25
  30. package/v7-services/serverless.yml +0 -140
  31. package/v7-services/src/networking/day.ts +0 -5
  32. package/v7-services/src/networking/get-free-token.ts +0 -33
  33. package/v7-services/src/networking/get-token-cost.ts +0 -31
  34. package/v7-services/src/networking/get-token-info.ts +0 -16
  35. package/v7-services/src/networking/ipx/put-ipx-ip.ts +0 -20
  36. package/v7-services/src/networking/ipx/start-ipx.ts +0 -16
  37. package/v7-services/src/networking/ipx/stop-ipx.ts +0 -19
  38. package/v7-services/src/networking/limits.ts +0 -3
  39. package/v7-services/src/networking/token.ts +0 -238
  40. package/v7-services/src/ok.ts +0 -7
  41. package/v7-services/src/personal-acl.ts +0 -33
  42. package/v7-services/src/personal-put.ts +0 -35
  43. package/v7-services/src/personal.ts +0 -18
  44. package/v7-services/src/responses.ts +0 -28
  45. package/v7-services/src/user.ts +0 -3
  46. package/v7-services/yarn.lock +0 -4400
@@ -1,238 +0,0 @@
1
- import * as AWS from "aws-sdk";
2
- import { freeTierHardLimit, freeTierSec, freeTierSoftLimit } from "./limits";
3
- import { customAlphabet } from "nanoid/async";
4
-
5
- const dynamoDb = new AWS.DynamoDB.DocumentClient();
6
- const NETWORKING_TABLE = process.env.NETWORKING_TABLE as string;
7
-
8
- const lambda = new AWS.Lambda();
9
- const RunInstanceLambda = process.env.RUN_INSTANCE as string;
10
-
11
- const nanoid = customAlphabet("0123456789abcdefghijklmnopqrstuvwxyz", 6);
12
-
13
- interface Token {
14
- day: number,
15
- region: string,
16
- endTime: number,
17
- ttlSec: number,
18
- }
19
-
20
- export type TaskType = "ipx";
21
-
22
- export async function getFreeTierSoftCount(namespace: string, id: string, day: number): Promise<number> {
23
- const freeTierSoftKey = getFreeTierSoftKey(namespace, id, day);
24
- const response = await dynamoDb.get({
25
- TableName: NETWORKING_TABLE,
26
- Key: {
27
- key: freeTierSoftKey,
28
- },
29
- }).promise();
30
-
31
- return response.Item?.count || 0;
32
- }
33
-
34
- export async function getFreeTierHardCount(day: number): Promise<number> {
35
- const freeTierHardKey = getFreeTierHardKey(day);
36
- const response = await dynamoDb.get({
37
- TableName: NETWORKING_TABLE,
38
- Key: {
39
- key: freeTierHardKey,
40
- },
41
- }).promise();
42
-
43
- return response.Item?.count || 0;
44
- }
45
-
46
- export async function createFreeToken(namespace: string, id: string, day: number, region: string): Promise<string> {
47
- const freeTierSoftKey = getFreeTierSoftKey(namespace, id, day);
48
- const freeTierHardKey = getFreeTierHardKey(day);
49
-
50
- const inc = async (key: string, inc: number) => {
51
- const updateParams: AWS.DynamoDB.DocumentClient.UpdateItemInput = {
52
- TableName: NETWORKING_TABLE,
53
- Key: {
54
- key,
55
- },
56
- UpdateExpression: "ADD #count :inc",
57
- ExpressionAttributeNames: {
58
- "#count": "count",
59
- },
60
- ExpressionAttributeValues: {
61
- ":inc": inc,
62
- },
63
- ReturnValues: "ALL_NEW",
64
- };
65
-
66
- const response = await dynamoDb.update(updateParams).promise();
67
- if (typeof response.Attributes?.count !== "number") {
68
- console.error("Can't get updated count value for key " + key, response);
69
- throw new Error("Can't get updated count value for key " + key);
70
- }
71
-
72
- return response.Attributes?.count as number;
73
- };
74
-
75
- const [softCount, hardCount] = await Promise.all([inc(freeTierSoftKey, 1), inc(freeTierHardKey, 1)]);
76
-
77
- try {
78
- if (softCount > freeTierSoftLimit) {
79
- throw new Error("free-soft-limit");
80
- }
81
-
82
- if (hardCount > freeTierHardLimit) {
83
- throw new Error("free-hard-limit");
84
- }
85
- } catch (e: any) {
86
- // rollback
87
- await Promise.all([inc(freeTierSoftKey, -1), inc(freeTierHardKey, -1)]);
88
- throw e;
89
- }
90
-
91
- return createToken(namespace, id, day, region, freeTierSec);
92
- }
93
-
94
- export async function getToken(token: string): Promise<Token> {
95
- const item = (await dynamoDb.get({
96
- TableName: NETWORKING_TABLE,
97
- Key: {
98
- key: getTokenKey(token),
99
- },
100
- }).promise()).Item as Token | undefined;
101
-
102
- if (item === undefined) {
103
- throw new Error("not-found");
104
- }
105
-
106
- item.ttlSec = Math.round((item.endTime - new Date().getTime()) / 1000);
107
-
108
- return item;
109
- }
110
-
111
- export async function createToken(namespace: string, id: string, day: number,
112
- region: string, durationSec: number): Promise<string> {
113
- let token: string | null = null;
114
- while (token === null) {
115
- token = await nanoid();
116
-
117
- const createParams: AWS.DynamoDB.DocumentClient.PutItemInput = {
118
- TableName: NETWORKING_TABLE,
119
- Item: {
120
- "key": getTokenKey(token),
121
- namespace,
122
- id,
123
- day,
124
- region,
125
- durationSec,
126
- "createdAt": new Date().getTime(),
127
- "endTime": new Date().getTime() + durationSec * 1000,
128
- },
129
- ConditionExpression: "attribute_not_exists(#key)",
130
- ExpressionAttributeNames: {
131
- "#key": "key",
132
- },
133
- };
134
-
135
- try {
136
- await dynamoDb.put(createParams).promise();
137
- } catch (e) {
138
- console.error(e);
139
- token = null;
140
- }
141
- }
142
-
143
- return token;
144
- }
145
-
146
- export async function newTask(tokenId: string, task: TaskType) {
147
- const token = await getToken(tokenId);
148
-
149
- if (token.ttlSec < 60) { // 1min to start container
150
- throw new Error("ended");
151
- }
152
-
153
- const result = await lambda.invoke({
154
- FunctionName: RunInstanceLambda,
155
- Payload: JSON.stringify({
156
- token: tokenId,
157
- region: token.region,
158
- task,
159
- }),
160
- }).promise();
161
-
162
- if (!result.Payload) {
163
- throw new Error("unable-to-start-task");
164
- }
165
-
166
- const payload = JSON.parse(JSON.parse(result.Payload as string).body);
167
-
168
- if (payload.success === false) {
169
- throw new Error(payload.errorCode);
170
- }
171
-
172
- const arn = payload.arn;
173
-
174
- if (arn === undefined) {
175
- throw new Error("ARN missed in runInstanceV2 response");
176
- }
177
-
178
- const updateParams: AWS.DynamoDB.DocumentClient.UpdateItemInput = {
179
- TableName: NETWORKING_TABLE,
180
- Key: {
181
- key: getTokenKey(tokenId),
182
- },
183
- UpdateExpression: `SET ${task}Arn = :arn`,
184
- ExpressionAttributeValues: {
185
- ":arn": arn,
186
- },
187
- };
188
-
189
- await dynamoDb.update(updateParams).promise();
190
-
191
- return arn;
192
- }
193
-
194
- export async function putIp(token: string, arn: string, ip: string, task: TaskType) {
195
- const updateParams: AWS.DynamoDB.DocumentClient.UpdateItemInput = {
196
- TableName: NETWORKING_TABLE,
197
- Key: {
198
- key: getTokenKey(token),
199
- },
200
- UpdateExpression: `SET ${task}Ip = :ip`,
201
- ConditionExpression: `${task}Arn = :arn`,
202
- ExpressionAttributeValues: {
203
- ":arn": arn,
204
- ":ip": ip,
205
- },
206
- };
207
-
208
- await dynamoDb.update(updateParams).promise();
209
- }
210
-
211
- export async function stopTask(token: string, arn: string, task: TaskType) {
212
- const updateParams: AWS.DynamoDB.DocumentClient.UpdateItemInput = {
213
- TableName: NETWORKING_TABLE,
214
- Key: {
215
- key: getTokenKey(token),
216
- },
217
- UpdateExpression: `REMOVE ${task}Arn, ${task}Ip`,
218
- ConditionExpression: `${task}Arn = :arn`,
219
- ExpressionAttributeValues: {
220
- ":arn": arn,
221
- },
222
- };
223
-
224
- await dynamoDb.update(updateParams).promise();
225
- }
226
-
227
-
228
- function getFreeTierSoftKey(namespace: string, id: string, day: number) {
229
- return "free-soft " + day + " " + id + "@" + namespace;
230
- }
231
-
232
- function getFreeTierHardKey(day: number) {
233
- return "free-hard " + day;
234
- }
235
-
236
- function getTokenKey(token: string) {
237
- return "token " + token;
238
- }
@@ -1,7 +0,0 @@
1
- import { Handler } from "aws-lambda";
2
-
3
- import { success } from "./responses";
4
-
5
- export const ok: Handler = async (event: any) => {
6
- return success({});
7
- };
@@ -1,33 +0,0 @@
1
- import { Handler } from "aws-lambda";
2
-
3
- import { badRequest, noSession, success } from "./responses";
4
-
5
- import * as AWS from "aws-sdk";
6
- import { validateUser } from "./user";
7
- import { getPersonalBundleKey, uploadsS3Bucket } from "./personal";
8
-
9
- const s3 = new AWS.S3();
10
-
11
- export const personalAcl: Handler = async (event: any) => {
12
- const namespace = event.queryStringParameters.namespace;
13
- const id = event.queryStringParameters.id;
14
- const bundleUrl = event.queryStringParameters.bundleUrl;
15
-
16
- if (!bundleUrl || bundleUrl.length === 0) {
17
- return badRequest();
18
- }
19
-
20
- if (!validateUser(namespace, id)) {
21
- return noSession();
22
- }
23
-
24
- const personalKey = getPersonalBundleKey(namespace, id, bundleUrl);
25
-
26
- await s3.putObjectAcl({
27
- Bucket: uploadsS3Bucket,
28
- Key: personalKey,
29
- ACL: "public-read",
30
- }).promise();
31
-
32
- return success({});
33
- };
@@ -1,35 +0,0 @@
1
- import { Handler } from "aws-lambda";
2
-
3
- import { badRequest, noSession, success } from "./responses";
4
- import { validateUser } from "./user";
5
-
6
- import * as AWS from "aws-sdk";
7
- import { getPersonalBundleUrl } from "./personal";
8
-
9
- const PutCurlLambda = process.env.PUT_CURL as string;
10
- const lambda = new AWS.Lambda();
11
-
12
- export const personalPut: Handler = async (event: any) => {
13
- const namespace = event.queryStringParameters.namespace;
14
- const id = event.queryStringParameters.id;
15
- const bundleUrl = event.queryStringParameters.bundleUrl;
16
-
17
- if (!bundleUrl || bundleUrl.length === 0) {
18
- return badRequest();
19
- }
20
-
21
- if (!validateUser(namespace, id)) {
22
- return noSession();
23
- }
24
-
25
- const personalUrl = getPersonalBundleUrl(namespace, id, bundleUrl);
26
-
27
- const result = await lambda.invoke({
28
- FunctionName: PutCurlLambda,
29
- Payload: JSON.stringify({
30
- bundleUrl: personalUrl,
31
- }),
32
- }).promise();
33
-
34
- return success({ payload: result.Payload });
35
- };
@@ -1,18 +0,0 @@
1
- export const uploadsS3Bucket = "doszone-uploads";
2
-
3
- const uploadsS3Url = "https://doszone-uploads.s3.dualstack.eu-central-1.amazonaws.com";
4
-
5
- export function getPersonalBundleKey(namespace: string, id: string, bundleUrl: string): string {
6
- const index = bundleUrl.lastIndexOf("/");
7
- const basename = bundleUrl.substr(index + 1);
8
- if (namespace === "doszone") {
9
- return "personal/" + id + "/" + basename;
10
- } else {
11
- return "personal-v2/" + namespace + "/" + id + "/" + basename;
12
- }
13
- }
14
-
15
- export function getPersonalBundleUrl(namespace: string, id: string, bundleUrl: string): string {
16
- const personalBundleKey = getPersonalBundleKey(namespace, id, bundleUrl);
17
- return uploadsS3Url + "/" + personalBundleKey;
18
- }
@@ -1,28 +0,0 @@
1
- export function success(body: any) {
2
- return response200(body, true);
3
- }
4
-
5
- export function error(errorCode: string) {
6
- return response200({ errorCode }, false);
7
- }
8
-
9
- export function badRequest() {
10
- return error("error_bad_request");
11
- }
12
-
13
- export function noSession() {
14
- return error("error_no_session");
15
- }
16
-
17
- function response200(body: any, success: boolean) {
18
- body.success = success;
19
-
20
- return {
21
- statusCode: 200,
22
- headers: {
23
- "Access-Control-Allow-Origin": "*",
24
- "Access-Control-Allow-Credentials": true,
25
- },
26
- body: JSON.stringify(body, null, 2),
27
- };
28
- }
@@ -1,3 +0,0 @@
1
- export function validateUser(namespace: string, id: string): boolean {
2
- return typeof namespace === "string" && typeof id === "string" && namespace.length > 0 && id.length > 0;
3
- }