@abtnode/core 1.17.7-beta-20251227-001958-ea2ba3f5 → 1.17.7-beta-20251229-085620-84f09930

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 (39) hide show
  1. package/lib/blocklet/manager/disk.js +73 -32
  2. package/lib/blocklet/manager/ensure-blocklet-running.js +1 -1
  3. package/lib/blocklet/manager/helper/blue-green-start-blocklet.js +1 -1
  4. package/lib/blocklet/manager/helper/install-application-from-general.js +2 -3
  5. package/lib/blocklet/manager/helper/install-component-from-url.js +7 -4
  6. package/lib/blocklet/migration-dist/migration.cjs +5 -4
  7. package/lib/blocklet/passport/index.js +10 -3
  8. package/lib/blocklet/project/index.js +7 -2
  9. package/lib/blocklet/security/index.js +2 -2
  10. package/lib/cert.js +6 -3
  11. package/lib/event/index.js +98 -87
  12. package/lib/event/util.js +7 -13
  13. package/lib/index.js +15 -26
  14. package/lib/migrations/1.5.0-site.js +3 -7
  15. package/lib/migrations/1.5.15-site.js +3 -7
  16. package/lib/monitor/blocklet-runtime-monitor.js +37 -5
  17. package/lib/monitor/node-runtime-monitor.js +4 -4
  18. package/lib/router/helper.js +525 -452
  19. package/lib/router/index.js +280 -104
  20. package/lib/router/manager.js +14 -28
  21. package/lib/states/blocklet-child.js +93 -1
  22. package/lib/states/blocklet-extras.js +1 -1
  23. package/lib/states/blocklet.js +429 -197
  24. package/lib/states/node.js +0 -10
  25. package/lib/states/site.js +87 -4
  26. package/lib/team/manager.js +2 -21
  27. package/lib/util/blocklet.js +39 -19
  28. package/lib/util/get-accessible-external-node-ip.js +21 -6
  29. package/lib/util/index.js +3 -3
  30. package/lib/util/ip.js +15 -1
  31. package/lib/util/launcher.js +11 -11
  32. package/lib/util/ready.js +2 -9
  33. package/lib/util/reset-node.js +6 -5
  34. package/lib/validators/router.js +0 -3
  35. package/lib/webhook/sender/api/index.js +5 -0
  36. package/package.json +23 -25
  37. package/lib/migrations/1.0.36-snapshot.js +0 -10
  38. package/lib/migrations/1.1.9-snapshot.js +0 -7
  39. package/lib/states/routing-snapshot.js +0 -146
@@ -1,146 +0,0 @@
1
- const fs = require('fs-extra');
2
- const path = require('path');
3
- const get = require('lodash/get');
4
- const TimeMachine = require('@abtnode/timemachine');
5
- const logger = require('@abtnode/logger')('@abtnode/core:states:routing-snapshot');
6
-
7
- module.exports = class RoutingSnapshot {
8
- constructor({ baseDir, getRoutingData }) {
9
- if (typeof getRoutingData !== 'function') {
10
- throw new Error('Must provide a valid getRoutingData function when create new RoutingSnapshot');
11
- }
12
-
13
- this.metaFile = path.join(baseDir, 'routing_snapshots_tag');
14
- this.getRoutingData = getRoutingData;
15
- this.timemachine = new TimeMachine({
16
- sources: async () => {
17
- const { sites = [] } = await this.getRoutingData();
18
-
19
- sites.forEach((r) => delete r.updatedAt);
20
- sites.sort((x, y) => {
21
- try {
22
- return new Date(x.createdAt).getTime() - new Date(y.createdAt).getTime();
23
- } catch (error) {
24
- logger.error('compare routing rule failed', { error });
25
- return 0;
26
- }
27
- });
28
-
29
- // Note: we should keep lines indented
30
- return JSON.stringify(
31
- {
32
- meta: {
33
- tag: fs.readFileSync(this.metaFile).toString(),
34
- },
35
- sites,
36
- },
37
- null,
38
- 2
39
- );
40
- },
41
- targetDir: path.join(baseDir, 'routing_snapshots'),
42
- });
43
-
44
- if (!fs.existsSync(this.metaFile)) {
45
- fs.createFileSync(this.metaFile);
46
- }
47
- }
48
-
49
- init() {
50
- return this.timemachine
51
- .getLastSnapshot(true)
52
- .then((hash) => {
53
- if (hash) {
54
- return hash;
55
- }
56
-
57
- return this.timemachine
58
- .takeSnapshot('Initial snapshot')
59
- .then((initialHash) => {
60
- logger.info('initial snapshot for routing rules', { initialHash });
61
- return initialHash;
62
- })
63
- .catch((err) => {
64
- logger.error('Cannot take initial routing snapshot', { error: err });
65
- return null;
66
- });
67
- })
68
- .catch((err) => {
69
- logger.error('Cannot get latest routing snapshot', { error: err });
70
- });
71
- }
72
-
73
- getLastSnapshot(shallow = true) {
74
- return this.timemachine.getLastSnapshot(shallow);
75
- }
76
-
77
- hasSnapshot(hash) {
78
- return this.timemachine.hasSnapshot(hash);
79
- }
80
-
81
- async readSnapshot(hash) {
82
- if (!hash || !(await this.hasSnapshot(hash))) {
83
- return {};
84
- }
85
-
86
- const result = await this.timemachine.exportSnapshot(hash).then((content) => JSON.parse(content));
87
- if (!result) {
88
- return {};
89
- }
90
-
91
- return result;
92
- }
93
-
94
- async readSnapshotSites(hash) {
95
- const { sites = [] } = await this.readSnapshot(hash);
96
- return sites;
97
- }
98
-
99
- takeSnapshot(message, dryRun = true) {
100
- if (!dryRun) {
101
- fs.writeFileSync(this.metaFile, Date.now().toString());
102
- }
103
-
104
- return this.timemachine.takeSnapshot(message, undefined, dryRun);
105
- }
106
-
107
- /**
108
- * @deprecated
109
- * @param {string} hash
110
- */
111
- exportSnapshot(hash) {
112
- return this.timemachine.exportSnapshot(hash).then((content) => JSON.parse(content));
113
- }
114
-
115
- // eslint-disable-next-line no-unused-vars
116
- listSnapshots({ limit = 5, trimFirst = true } = {}, context) {
117
- return new Promise((resolve) => {
118
- this.timemachine.listSnapshots(limit + 1).then((stream) => {
119
- const snapshots = [];
120
-
121
- stream.on('data', (snapshot) => {
122
- snapshots.push({
123
- hash: snapshot.hash,
124
- tree: snapshot.tree,
125
- message: snapshot.message,
126
- author: snapshot.author.name,
127
- createdAt: new Date(snapshot.author.date.seconds * 1000),
128
- });
129
- });
130
-
131
- stream.on('end', () => {
132
- if (snapshots.length > 0 && trimFirst) {
133
- snapshots.pop();
134
- }
135
-
136
- return resolve(snapshots);
137
- });
138
- });
139
- });
140
- }
141
-
142
- restoreMetaData(meta) {
143
- logger.info('restore meta data');
144
- fs.writeFileSync(this.metaFile, get(meta, 'tag') || '');
145
- }
146
- };