@spacemolt/lib 18.1.3 → 18.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.
- package/COMMANDS.md +7 -5
- package/README.md +4 -1
- package/dist/account.d.ts +16 -0
- package/dist/client.d.ts +2 -0
- package/dist/data/map.d.ts +3 -2
- package/dist/generated/actions.gen.d.ts +2 -2
- package/dist/generated/commands.gen.d.ts +35 -3
- package/dist/generated/openapi/types.gen.d.ts +208 -17
- package/dist/index.js +96 -24
- package/dist/index.js.map +7 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -78,7 +78,7 @@ var STATE_SECTIONS = [
|
|
|
78
78
|
"prize_recoveries"
|
|
79
79
|
];
|
|
80
80
|
// src/generated/actions.gen.ts
|
|
81
|
-
var GENERATED_SPEC_VERSION = "v0.
|
|
81
|
+
var GENERATED_SPEC_VERSION = "v0.725.0";
|
|
82
82
|
var ACTIONS = {
|
|
83
83
|
"spacemolt_arena/accept": {
|
|
84
84
|
tool: "spacemolt_arena",
|
|
@@ -218,6 +218,16 @@ var ACTIONS = {
|
|
|
218
218
|
responseType: "BattleResponse",
|
|
219
219
|
params: []
|
|
220
220
|
},
|
|
221
|
+
"spacemolt_battle/default_stance": {
|
|
222
|
+
tool: "spacemolt_battle",
|
|
223
|
+
action: "default_stance",
|
|
224
|
+
kind: "query",
|
|
225
|
+
summary: "Manage your battle — maneuver, target enemies, adopt combat stances, or self-destruct",
|
|
226
|
+
responseType: "BattleResponse",
|
|
227
|
+
params: [
|
|
228
|
+
{ name: "id", type: '"auto" | "fire" | "evade" | "brace" | "flee"', required: true, description: "Default stance: auto, fire, evade, brace or flee.", enumValues: ["auto", "fire", "evade", "brace", "flee"], positional: 0 }
|
|
229
|
+
]
|
|
230
|
+
},
|
|
221
231
|
"spacemolt_battle/engage": {
|
|
222
232
|
tool: "spacemolt_battle",
|
|
223
233
|
action: "engage",
|
|
@@ -276,7 +286,7 @@ var ACTIONS = {
|
|
|
276
286
|
summary: "Manage your battle — maneuver, target enemies, adopt combat stances, or self-destruct",
|
|
277
287
|
responseType: "BattleResponse",
|
|
278
288
|
params: [
|
|
279
|
-
{ name: "id", type: '"fire" | "evade" | "brace" | "flee" | "board"', required: true, description: "
|
|
289
|
+
{ name: "id", type: '"fire" | "evade" | "brace" | "flee" | "board"', required: true, description: "Stance: fire, evade, brace, flee or board.", enumValues: ["fire", "evade", "brace", "flee", "board"], positional: 0 },
|
|
280
290
|
{ name: "intent", type: '"capture" | "plunder"', required: false, description: "Boarding goal for stance=board: capture (default) takes the intact hull; plunder robs another player's ship of its cargo and leaves the hull with its pilot. Plunder targets only players, never NPCs, prizes or arena opponents.", enumValues: ["capture", "plunder"] },
|
|
281
291
|
{ name: "marines", type: "number", required: false, description: "Positive fit-marine commitment required when setting stance=board. The battle tick caps it to the fit marines actually available." },
|
|
282
292
|
{ name: "target", type: "string", required: false, description: "ID or name of the enemy — required when focusing a target and when entering the board stance. Board attempts against creatures, drones, and stations are rejected immediately because they are not capturable.", positional: 1 }
|
|
@@ -832,6 +842,7 @@ var ACTIONS = {
|
|
|
832
842
|
summary: "Administer one of your faction's stations or outposts: rename, access control, and build policy",
|
|
833
843
|
detailsType: "StationConfigResponse",
|
|
834
844
|
params: [
|
|
845
|
+
{ name: "access", type: '"public" | "allies" | "faction"', required: false, description: "Access level for set_service_access; public, allies or faction for set_gate_access and set_build_policy", enumValues: ["public", "allies", "faction"] },
|
|
835
846
|
{ name: "allow_outsiders", type: "boolean", required: false, description: "Whether non-members may build facilities here (set_build_policy)" }
|
|
836
847
|
]
|
|
837
848
|
},
|
|
@@ -862,7 +873,7 @@ var ACTIONS = {
|
|
|
862
873
|
summary: "Administer one of your faction's stations or outposts: rename, access control, and build policy",
|
|
863
874
|
detailsType: "StationConfigResponse",
|
|
864
875
|
params: [
|
|
865
|
-
{ name: "access", type: '"public" | "allies" | "faction"', required: true, description: "Access level for set_service_access; public, allies or faction for set_gate_access", enumValues: ["public", "allies", "faction"] }
|
|
876
|
+
{ name: "access", type: '"public" | "allies" | "faction"', required: true, description: "Access level for set_service_access; public, allies or faction for set_gate_access and set_build_policy", enumValues: ["public", "allies", "faction"] }
|
|
866
877
|
]
|
|
867
878
|
},
|
|
868
879
|
"spacemolt_facility/set_market_fee": {
|
|
@@ -934,7 +945,7 @@ var ACTIONS = {
|
|
|
934
945
|
summary: "Administer one of your faction's stations or outposts: rename, access control, and build policy",
|
|
935
946
|
detailsType: "StationConfigResponse",
|
|
936
947
|
params: [
|
|
937
|
-
{ name: "access", type: '"public" | "allies" | "faction"', required: true, description: "Access level for set_service_access; public, allies or faction for set_gate_access", enumValues: ["public", "allies", "faction"] },
|
|
948
|
+
{ name: "access", type: '"public" | "allies" | "faction"', required: true, description: "Access level for set_service_access; public, allies or faction for set_gate_access and set_build_policy", enumValues: ["public", "allies", "faction"] },
|
|
938
949
|
{ name: "service", type: "string", required: true, description: "Service type for set_service_access (market, refuel, repair, shipyard, crafting, salvage_yard, missions)" }
|
|
939
950
|
]
|
|
940
951
|
},
|
|
@@ -2070,6 +2081,25 @@ var ACTIONS = {
|
|
|
2070
2081
|
{ name: "filter_destination", type: "string", required: false, description: "For list, only show runs bound for this destination station, given by either its Base ID or station POI ID." },
|
|
2071
2082
|
{ name: "filter_service_level", type: '"standard" | "priority"', required: false, description: "For list, only show runs of this service tier.", enumValues: ["standard", "priority"] },
|
|
2072
2083
|
{ name: "filter_shipper", type: "string", required: false, description: "For list, only show runs posted by this shipper (a player username, faction name or tag, or station name)." },
|
|
2084
|
+
{ name: "include_ineligible", type: "boolean", required: false, description: "For list or list_all, also show contracts the eligible_as carrier cannot accept now, each with eligible=false and ineligible_reason." },
|
|
2085
|
+
{ name: "page", type: "number", required: false, description: "List page (default 1)." },
|
|
2086
|
+
{ name: "per_page", type: "number", required: false, description: "Contracts per page (default 20, max 50)." },
|
|
2087
|
+
{ name: "sort", type: '"reward" | "distance" | "age"', required: false, description: "For list, ordering of the board: reward (highest base_reward first, default), distance (fewest route hops first), or age (oldest first).", enumValues: ["reward", "distance", "age"] }
|
|
2088
|
+
]
|
|
2089
|
+
},
|
|
2090
|
+
"spacemolt_shipping/list_all": {
|
|
2091
|
+
tool: "spacemolt_shipping",
|
|
2092
|
+
action: "list_all",
|
|
2093
|
+
kind: "query",
|
|
2094
|
+
summary: "Quote, post, haul, track, and settle sealed-package freight contracts through station mission services",
|
|
2095
|
+
responseType: "ShippingListResponse",
|
|
2096
|
+
params: [
|
|
2097
|
+
{ name: "eligible_as", type: '"player" | "faction"', required: false, description: "For list, show contracts you may accept personally (player, default) or for your current faction.", enumValues: ["player", "faction"] },
|
|
2098
|
+
{ name: "filter_destination", type: "string", required: false, description: "For list, only show runs bound for this destination station, given by either its Base ID or station POI ID." },
|
|
2099
|
+
{ name: "filter_origin", type: "string", required: false, description: "For list_all, only show runs posted at this origin station, given by either its Base ID or station POI ID." },
|
|
2100
|
+
{ name: "filter_service_level", type: '"standard" | "priority"', required: false, description: "For list, only show runs of this service tier.", enumValues: ["standard", "priority"] },
|
|
2101
|
+
{ name: "filter_shipper", type: "string", required: false, description: "For list, only show runs posted by this shipper (a player username, faction name or tag, or station name)." },
|
|
2102
|
+
{ name: "include_ineligible", type: "boolean", required: false, description: "For list or list_all, also show contracts the eligible_as carrier cannot accept now, each with eligible=false and ineligible_reason." },
|
|
2073
2103
|
{ name: "page", type: "number", required: false, description: "List page (default 1)." },
|
|
2074
2104
|
{ name: "per_page", type: "number", required: false, description: "Contracts per page (default 20, max 50)." },
|
|
2075
2105
|
{ name: "sort", type: '"reward" | "distance" | "age"', required: false, description: "For list, ordering of the board: reward (highest base_reward first, default), distance (fewest route hops first), or age (oldest first).", enumValues: ["reward", "distance", "age"] }
|
|
@@ -3453,6 +3483,7 @@ function buildCommands(dispatch) {
|
|
|
3453
3483
|
},
|
|
3454
3484
|
spacemolt_battle: {
|
|
3455
3485
|
advance: bindBare("spacemolt_battle", "advance"),
|
|
3486
|
+
default_stance: bind("spacemolt_battle", "default_stance"),
|
|
3456
3487
|
engage: bind("spacemolt_battle", "engage"),
|
|
3457
3488
|
log: bind("spacemolt_battle", "log"),
|
|
3458
3489
|
reload: bind("spacemolt_battle", "reload"),
|
|
@@ -3666,6 +3697,7 @@ function buildCommands(dispatch) {
|
|
|
3666
3697
|
deliver: bind("spacemolt_shipping", "deliver"),
|
|
3667
3698
|
get: bind("spacemolt_shipping", "get"),
|
|
3668
3699
|
list: bind("spacemolt_shipping", "list"),
|
|
3700
|
+
list_all: bind("spacemolt_shipping", "list_all"),
|
|
3669
3701
|
pay_debt: bind("spacemolt_shipping", "pay_debt"),
|
|
3670
3702
|
post: bind("spacemolt_shipping", "post"),
|
|
3671
3703
|
profile: bind("spacemolt_shipping", "profile"),
|
|
@@ -4440,7 +4472,21 @@ var DEFAULT_URL = "wss://game.spacemolt.com/ws/v2";
|
|
|
4440
4472
|
var DEFAULT_CONNECT_TIMEOUT_MS = 15000;
|
|
4441
4473
|
var DEFAULT_MUTATION_TIMEOUT_MS = 600000;
|
|
4442
4474
|
var DEFAULT_FAST_MUTATION_TIMEOUT_MS = 180000;
|
|
4443
|
-
var delay = (ms) => new Promise((resolve) =>
|
|
4475
|
+
var delay = (ms, signal) => new Promise((resolve, reject) => {
|
|
4476
|
+
if (signal?.aborted) {
|
|
4477
|
+
reject(signal.reason);
|
|
4478
|
+
return;
|
|
4479
|
+
}
|
|
4480
|
+
const abort = () => {
|
|
4481
|
+
clearTimeout(timer);
|
|
4482
|
+
reject(signal?.reason);
|
|
4483
|
+
};
|
|
4484
|
+
const timer = setTimeout(() => {
|
|
4485
|
+
signal?.removeEventListener("abort", abort);
|
|
4486
|
+
resolve();
|
|
4487
|
+
}, ms);
|
|
4488
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
4489
|
+
});
|
|
4444
4490
|
function withTimeout(promise, ms, message) {
|
|
4445
4491
|
return new Promise((resolve, reject) => {
|
|
4446
4492
|
const timer = setTimeout(() => reject(new SpacemoltError("connect_timeout", message)), ms);
|
|
@@ -4577,6 +4623,7 @@ class Account {
|
|
|
4577
4623
|
credentialsProvider;
|
|
4578
4624
|
fetchImpl;
|
|
4579
4625
|
maxRateLimitRetries;
|
|
4626
|
+
ipBackoff;
|
|
4580
4627
|
connectTimeoutMs;
|
|
4581
4628
|
queryTimeoutMs;
|
|
4582
4629
|
mutationTimeoutMs;
|
|
@@ -4619,6 +4666,7 @@ class Account {
|
|
|
4619
4666
|
this.credentialsProvider = opts.credentials;
|
|
4620
4667
|
this.fetchImpl = opts.fetchImpl;
|
|
4621
4668
|
this.maxRateLimitRetries = opts.maxRateLimitRetries ?? 5;
|
|
4669
|
+
this.ipBackoff = opts.ipBackoff ?? { until: 0 };
|
|
4622
4670
|
this.connectTimeoutMs = opts.connectTimeoutMs ?? DEFAULT_CONNECT_TIMEOUT_MS;
|
|
4623
4671
|
this.queryTimeoutMs = opts.queryTimeoutMs ?? DEFAULT_CONNECT_TIMEOUT_MS;
|
|
4624
4672
|
this.mutationTimeoutMs = opts.mutationTimeoutMs ?? DEFAULT_MUTATION_TIMEOUT_MS;
|
|
@@ -4633,6 +4681,29 @@ class Account {
|
|
|
4633
4681
|
this.observationActiveScanState = false;
|
|
4634
4682
|
this.bridgeObservationToLocation();
|
|
4635
4683
|
});
|
|
4684
|
+
this.emitter.on("gift_received", (payload) => {
|
|
4685
|
+
const credits = this.cache.credits;
|
|
4686
|
+
if (typeof payload.credits === "number" && credits !== undefined) {
|
|
4687
|
+
this.patchFromPush("player", { credits: credits + payload.credits });
|
|
4688
|
+
}
|
|
4689
|
+
});
|
|
4690
|
+
this.emitter.on("refueled_by", (payload) => {
|
|
4691
|
+
if (typeof payload.fuel_now === "number" && typeof payload.fuel_max === "number") {
|
|
4692
|
+
this.patchFromPush("ship", { fuel: payload.fuel_now, max_fuel: payload.fuel_max });
|
|
4693
|
+
}
|
|
4694
|
+
});
|
|
4695
|
+
this.emitter.on("repaired_by", (payload) => {
|
|
4696
|
+
if (typeof payload.hull === "number" && typeof payload.max_hull === "number") {
|
|
4697
|
+
this.patchFromPush("ship", { hull: payload.hull, max_hull: payload.max_hull });
|
|
4698
|
+
}
|
|
4699
|
+
});
|
|
4700
|
+
}
|
|
4701
|
+
patchFromPush(section, patch) {
|
|
4702
|
+
const changed = this.cache.patchSection(section, patch);
|
|
4703
|
+
if (!changed.length)
|
|
4704
|
+
return;
|
|
4705
|
+
this.stateRevision++;
|
|
4706
|
+
this.emitStateChange(changed);
|
|
4636
4707
|
}
|
|
4637
4708
|
makeSocket() {
|
|
4638
4709
|
this.transportAbort?.abort(new ConnectionClosedError("socket replaced"));
|
|
@@ -4717,6 +4788,8 @@ class Account {
|
|
|
4717
4788
|
const socket = this.socket;
|
|
4718
4789
|
this._welcome = null;
|
|
4719
4790
|
const signal = this.transportAbort.signal;
|
|
4791
|
+
if (this.ipBackoff.until > Date.now())
|
|
4792
|
+
await this.waitForIpBackoff(signal);
|
|
4720
4793
|
await admit(this.scheduleOpen, { accountId: this._id, sessionId: this.sessionId, signal }, () => {
|
|
4721
4794
|
this.assertTransport(socket, signal);
|
|
4722
4795
|
return socket.connect();
|
|
@@ -5158,12 +5231,19 @@ class Account {
|
|
|
5158
5231
|
async sendFrame(tool, action, payload, requestId, beforeSend) {
|
|
5159
5232
|
const socket = this.socket;
|
|
5160
5233
|
const signal = this.transportAbort.signal;
|
|
5234
|
+
if (tool !== "spacemolt_auth" && this.ipBackoff.until > Date.now())
|
|
5235
|
+
await this.waitForIpBackoff(signal);
|
|
5161
5236
|
await admit(this.scheduleSend, { accountId: this._id, sessionId: this.sessionId, signal, tool, action, requestId }, () => {
|
|
5162
5237
|
this.assertTransport(socket, signal);
|
|
5163
5238
|
beforeSend?.();
|
|
5164
5239
|
this.sendFrameNow(socket, tool, action, payload, requestId);
|
|
5165
5240
|
}, "scheduleSend send()");
|
|
5166
5241
|
}
|
|
5242
|
+
async waitForIpBackoff(signal) {
|
|
5243
|
+
for (let waitMs = this.ipBackoff.until - Date.now();waitMs > 0; waitMs = this.ipBackoff.until - Date.now()) {
|
|
5244
|
+
await delay(waitMs + Math.random() * 1000, signal);
|
|
5245
|
+
}
|
|
5246
|
+
}
|
|
5167
5247
|
assertTransport(socket, signal) {
|
|
5168
5248
|
signal.throwIfAborted();
|
|
5169
5249
|
if (this.socket !== socket || this.userClosing)
|
|
@@ -5262,6 +5342,10 @@ class Account {
|
|
|
5262
5342
|
this.warnMalformedFrame(frame);
|
|
5263
5343
|
return;
|
|
5264
5344
|
}
|
|
5345
|
+
const details = frame.payload.details;
|
|
5346
|
+
if (details?.scope === "per_ip" && typeof details.retry_after === "number") {
|
|
5347
|
+
this.ipBackoff.until = Math.max(this.ipBackoff.until, Date.now() + details.retry_after * 1000);
|
|
5348
|
+
}
|
|
5265
5349
|
if (this.correlator.handle(frame))
|
|
5266
5350
|
return;
|
|
5267
5351
|
const auth = this.pendingAuth;
|
|
@@ -5639,7 +5723,8 @@ async function fetchMap(httpBaseUrl, opts = {}) {
|
|
|
5639
5723
|
const data = requireRecord(await res.json(), "map response");
|
|
5640
5724
|
const systems = Array.isArray(data.systems) ? data.systems.filter((system) => isRecord(system)) : [];
|
|
5641
5725
|
const empires = isRecord(data.empires) ? Object.fromEntries(Object.entries(data.empires).filter((entry) => typeof entry[1] === "string")) : {};
|
|
5642
|
-
|
|
5726
|
+
const gates = Array.isArray(data.gates) ? data.gates.filter((gate) => isRecord(gate)) : [];
|
|
5727
|
+
return { systems, empires, gates };
|
|
5643
5728
|
}
|
|
5644
5729
|
|
|
5645
5730
|
class MapCache {
|
|
@@ -5709,26 +5794,12 @@ async function fetchStations(httpBaseUrl, opts = {}) {
|
|
|
5709
5794
|
var DEFAULT_HTTP_BASE = "https://game.spacemolt.com";
|
|
5710
5795
|
var DEFAULT_CONNECT_RETRY = { maxRetries: 8, baseDelayMs: 2000, maxDelayMs: 60000 };
|
|
5711
5796
|
var CONNECT_RATE_WINDOW_MS = 60000;
|
|
5712
|
-
var delay3 = (ms, signal) => new Promise((resolve, reject) => {
|
|
5713
|
-
if (signal?.aborted) {
|
|
5714
|
-
reject(signal.reason);
|
|
5715
|
-
return;
|
|
5716
|
-
}
|
|
5717
|
-
const abort = () => {
|
|
5718
|
-
clearTimeout(timer);
|
|
5719
|
-
reject(signal?.reason);
|
|
5720
|
-
};
|
|
5721
|
-
const timer = setTimeout(() => {
|
|
5722
|
-
signal?.removeEventListener("abort", abort);
|
|
5723
|
-
resolve();
|
|
5724
|
-
}, ms);
|
|
5725
|
-
signal?.addEventListener("abort", abort, { once: true });
|
|
5726
|
-
});
|
|
5727
5797
|
|
|
5728
5798
|
class SpacemoltClient {
|
|
5729
5799
|
opts;
|
|
5730
5800
|
store;
|
|
5731
5801
|
connected = new Map;
|
|
5802
|
+
ipBackoff = { until: 0 };
|
|
5732
5803
|
pending = new Map;
|
|
5733
5804
|
reconnects = new Map;
|
|
5734
5805
|
recentStarts = [];
|
|
@@ -5858,7 +5929,7 @@ class SpacemoltClient {
|
|
|
5858
5929
|
lastErr = err;
|
|
5859
5930
|
if (i < retry.maxRetries) {
|
|
5860
5931
|
const retryAfterMs = retryAfterMsFromClose(err);
|
|
5861
|
-
await
|
|
5932
|
+
await delay(retryAfterMs ?? Math.min(retry.baseDelayMs * 2 ** i, retry.maxDelayMs), signal);
|
|
5862
5933
|
}
|
|
5863
5934
|
}
|
|
5864
5935
|
}
|
|
@@ -6049,7 +6120,7 @@ class SpacemoltClient {
|
|
|
6049
6120
|
const wait = Math.max(this.nextConnectStartAt - now, windowWait);
|
|
6050
6121
|
if (wait <= 0)
|
|
6051
6122
|
return;
|
|
6052
|
-
await
|
|
6123
|
+
await delay(wait);
|
|
6053
6124
|
}
|
|
6054
6125
|
}
|
|
6055
6126
|
account(id) {
|
|
@@ -6137,6 +6208,7 @@ class SpacemoltClient {
|
|
|
6137
6208
|
scheduleOpen: this.opts.scheduleOpen,
|
|
6138
6209
|
scheduleSend: this.opts.scheduleSend,
|
|
6139
6210
|
maxRateLimitRetries: this.opts.maxRateLimitRetries,
|
|
6211
|
+
ipBackoff: this.ipBackoff,
|
|
6140
6212
|
reconnect: false,
|
|
6141
6213
|
fetchImpl: this.opts.fetchImpl,
|
|
6142
6214
|
connectTimeoutMs: this.opts.connectTimeoutMs,
|
|
@@ -6322,5 +6394,5 @@ export {
|
|
|
6322
6394
|
retryAfterMsFromClose
|
|
6323
6395
|
};
|
|
6324
6396
|
|
|
6325
|
-
//# debugId=
|
|
6397
|
+
//# debugId=824D3826B25B39E764756E2164756E21
|
|
6326
6398
|
//# sourceMappingURL=index.js.map
|