@celljs/ta-gateway 0.0.0-stage → 4.9.1

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 (60) hide show
  1. package/README.en.md +80 -0
  2. package/README.md +79 -2
  3. package/esm/node/command-sandbox.d.ts +28 -0
  4. package/esm/node/command-sandbox.js +83 -0
  5. package/esm/node/docker-engine.d.ts +56 -0
  6. package/esm/node/docker-engine.js +151 -0
  7. package/esm/node/docker-sandbox.d.ts +45 -0
  8. package/esm/node/docker-sandbox.js +110 -0
  9. package/esm/node/environments.d.ts +68 -0
  10. package/esm/node/environments.js +237 -0
  11. package/esm/node/gateway-cli.d.ts +9 -0
  12. package/esm/node/gateway-cli.js +99 -0
  13. package/esm/node/gateway-server.d.ts +67 -0
  14. package/esm/node/gateway-server.js +288 -0
  15. package/esm/node/gateway-service.d.ts +58 -0
  16. package/esm/node/gateway-service.js +187 -0
  17. package/esm/node/gateway-socket.d.ts +33 -0
  18. package/esm/node/gateway-socket.js +143 -0
  19. package/esm/node/index.d.ts +13 -0
  20. package/esm/node/index.js +14 -0
  21. package/esm/node/local-sandbox.d.ts +23 -0
  22. package/esm/node/local-sandbox.js +73 -0
  23. package/esm/node/sandbox-provider.d.ts +72 -0
  24. package/esm/node/sandbox-provider.js +83 -0
  25. package/esm/node/sign-in-links.d.ts +25 -0
  26. package/esm/node/sign-in-links.js +44 -0
  27. package/esm/node/ta-sandbox.d.ts +23 -0
  28. package/esm/node/ta-sandbox.js +47 -0
  29. package/esm/node/tenant-store.d.ts +36 -0
  30. package/esm/node/tenant-store.js +83 -0
  31. package/esm/package.json +3 -0
  32. package/lib/node/command-sandbox.d.ts +29 -0
  33. package/lib/node/command-sandbox.js +87 -0
  34. package/lib/node/docker-engine.d.ts +57 -0
  35. package/lib/node/docker-engine.js +156 -0
  36. package/lib/node/docker-sandbox.d.ts +46 -0
  37. package/lib/node/docker-sandbox.js +114 -0
  38. package/lib/node/environments.d.ts +69 -0
  39. package/lib/node/environments.js +242 -0
  40. package/lib/node/gateway-cli.d.ts +10 -0
  41. package/lib/node/gateway-cli.js +102 -0
  42. package/lib/node/gateway-server.d.ts +68 -0
  43. package/lib/node/gateway-server.js +292 -0
  44. package/lib/node/gateway-service.d.ts +59 -0
  45. package/lib/node/gateway-service.js +192 -0
  46. package/lib/node/gateway-socket.d.ts +34 -0
  47. package/lib/node/gateway-socket.js +147 -0
  48. package/lib/node/index.d.ts +14 -0
  49. package/lib/node/index.js +30 -0
  50. package/lib/node/local-sandbox.d.ts +24 -0
  51. package/lib/node/local-sandbox.js +77 -0
  52. package/lib/node/sandbox-provider.d.ts +73 -0
  53. package/lib/node/sandbox-provider.js +87 -0
  54. package/lib/node/sign-in-links.d.ts +26 -0
  55. package/lib/node/sign-in-links.js +48 -0
  56. package/lib/node/ta-sandbox.d.ts +24 -0
  57. package/lib/node/ta-sandbox.js +51 -0
  58. package/lib/node/tenant-store.d.ts +37 -0
  59. package/lib/node/tenant-store.js +88 -0
  60. package/package.json +57 -4
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TenantStore = exports.TenantUtil = void 0;
4
+ exports.writePrivate = writePrivate;
5
+ const node_crypto_1 = require("node:crypto");
6
+ const node_fs_1 = require("node:fs");
7
+ const node_path_1 = require("node:path");
8
+ /** Files written whole or not at all, readable by this user only. */
9
+ function writePrivate(file, data) {
10
+ const temporary = `${file}.${process.pid}.tmp`;
11
+ (0, node_fs_1.writeFileSync)(temporary, JSON.stringify(data, undefined, 2), { mode: 0o600 });
12
+ (0, node_fs_1.chmodSync)(temporary, 0o600);
13
+ (0, node_fs_1.renameSync)(temporary, file);
14
+ }
15
+ var TenantUtil;
16
+ (function (TenantUtil) {
17
+ /** Stable, and fit for the names of containers and volumes. */
18
+ function id(account) {
19
+ return (0, node_crypto_1.createHash)('sha256').update(account).digest('hex').slice(0, 16);
20
+ }
21
+ TenantUtil.id = id;
22
+ })(TenantUtil || (exports.TenantUtil = TenantUtil = {}));
23
+ /** `<gateway>/tenants/<id>.json`, one per account, made on its first sign-in. */
24
+ class TenantStore {
25
+ constructor(root) {
26
+ this.cache = new Map();
27
+ this.dir = (0, node_path_1.join)(root, 'tenants');
28
+ (0, node_fs_1.mkdirSync)(this.dir, { recursive: true, mode: 0o700 });
29
+ }
30
+ get(id) {
31
+ if (!/^[0-9a-f]{16}$/.test(id)) {
32
+ return undefined;
33
+ }
34
+ let tenant = this.cache.get(id);
35
+ if (!tenant) {
36
+ try {
37
+ tenant = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(this.dir, `${id}.json`), 'utf8'));
38
+ this.cache.set(id, tenant);
39
+ }
40
+ catch (_a) {
41
+ return undefined;
42
+ }
43
+ }
44
+ return tenant;
45
+ }
46
+ /** The tenant of the account, made when it has none. */
47
+ ensure(account, now = Date.now()) {
48
+ const id = TenantUtil.id(account.id);
49
+ const known = this.get(id);
50
+ if (known) {
51
+ if (account.name && (known.name !== account.name || known.avatar !== account.avatar)) {
52
+ return this.update(id, { name: account.name, avatar: account.avatar });
53
+ }
54
+ return known;
55
+ }
56
+ const tenant = {
57
+ id,
58
+ account: account.id,
59
+ name: account.name,
60
+ avatar: account.avatar,
61
+ token: (0, node_crypto_1.randomBytes)(32).toString('base64url'),
62
+ createdAt: now,
63
+ };
64
+ this.save(tenant);
65
+ return tenant;
66
+ }
67
+ update(id, change) {
68
+ const tenant = this.get(id);
69
+ if (!tenant) {
70
+ throw new Error(`No tenant ${id}`);
71
+ }
72
+ const next = { ...tenant, ...change };
73
+ this.save(next);
74
+ return next;
75
+ }
76
+ list() {
77
+ return (0, node_fs_1.readdirSync)(this.dir)
78
+ .filter(name => /^[0-9a-f]{16}\.json$/.test(name))
79
+ .map(name => this.get(name.slice(0, -5)))
80
+ .filter((tenant) => tenant !== undefined);
81
+ }
82
+ save(tenant) {
83
+ writePrivate((0, node_path_1.join)(this.dir, `${tenant.id}.json`), tenant);
84
+ this.cache.set(tenant.id, tenant);
85
+ }
86
+ }
87
+ exports.TenantStore = TenantStore;
88
+ //# sourceMappingURL=tenant-store.js.map
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "@celljs/ta-gateway",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "4.9.1",
4
+ "description": "ta gateway: one Ta per account, each in a sandbox of its own, behind one sign-in",
5
+ "homepage": "https://github.com/cellbang/cell",
6
+ "bugs": {
7
+ "url": "https://github.com/cellbang/cell/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/cellbang/cell.git"
12
+ },
13
+ "license": "MIT",
14
+ "engines": {
15
+ "node": ">=22.19.0"
16
+ },
17
+ "main": "lib/node/index.js",
18
+ "typings": "lib/node/index.d.ts",
19
+ "files": [
20
+ "lib",
21
+ "esm",
22
+ "!lib/**/*.spec.*",
23
+ "!**/*.map"
24
+ ],
25
+ "scripts": {
26
+ "build": "tsc -b && bun ../../scripts/build-esm.ts",
27
+ "clean": "rm -rf lib esm *.tsbuildinfo",
28
+ "test": "bun test ./lib",
29
+ "watch": "tsc -b -w --preserveWatchOutput"
30
+ },
31
+ "dependencies": {
32
+ "@celljs/rpc": "4.9.1",
33
+ "@celljs/ta-host": "4.9.1",
34
+ "@celljs/ta-protocol": "4.9.1"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "exports": {
40
+ ".": {
41
+ "import": "./esm/node/index.js",
42
+ "default": "./lib/node/index.js"
43
+ },
44
+ "./package.json": "./package.json",
45
+ "./lib/node": {
46
+ "import": "./esm/node/index.js",
47
+ "default": "./lib/node/index.js"
48
+ },
49
+ "./lib/*.js": {
50
+ "import": "./esm/*.js",
51
+ "default": "./lib/*.js"
52
+ },
53
+ "./lib/*": {
54
+ "import": "./esm/*.js",
55
+ "default": "./lib/*.js"
56
+ },
57
+ "./*": "./*"
58
+ }
59
+ }