burnrate 0.1.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/LICENSE +21 -0
- package/README.md +507 -0
- package/dist/cli/format.d.ts +13 -0
- package/dist/cli/format.js +319 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.js +1121 -0
- package/dist/cli/setup.d.ts +8 -0
- package/dist/cli/setup.js +143 -0
- package/dist/core/async-engine.d.ts +411 -0
- package/dist/core/async-engine.js +2274 -0
- package/dist/core/async-worldgen.d.ts +19 -0
- package/dist/core/async-worldgen.js +221 -0
- package/dist/core/engine.d.ts +154 -0
- package/dist/core/engine.js +1104 -0
- package/dist/core/pathfinding.d.ts +38 -0
- package/dist/core/pathfinding.js +146 -0
- package/dist/core/types.d.ts +489 -0
- package/dist/core/types.js +359 -0
- package/dist/core/worldgen.d.ts +22 -0
- package/dist/core/worldgen.js +292 -0
- package/dist/db/database.d.ts +83 -0
- package/dist/db/database.js +829 -0
- package/dist/db/turso-database.d.ts +177 -0
- package/dist/db/turso-database.js +1586 -0
- package/dist/mcp/server.d.ts +7 -0
- package/dist/mcp/server.js +1877 -0
- package/dist/server/api.d.ts +8 -0
- package/dist/server/api.js +1234 -0
- package/dist/server/async-tick-server.d.ts +5 -0
- package/dist/server/async-tick-server.js +63 -0
- package/dist/server/errors.d.ts +78 -0
- package/dist/server/errors.js +156 -0
- package/dist/server/rate-limit.d.ts +22 -0
- package/dist/server/rate-limit.js +134 -0
- package/dist/server/tick-server.d.ts +9 -0
- package/dist/server/tick-server.js +114 -0
- package/dist/server/validation.d.ts +194 -0
- package/dist/server/validation.js +114 -0
- package/package.json +65 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BURNRATE API Validation Schemas
|
|
3
|
+
* Using Zod for runtime validation
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
export declare const ResourceSchema: z.ZodEnum<{
|
|
7
|
+
ore: "ore";
|
|
8
|
+
fuel: "fuel";
|
|
9
|
+
grain: "grain";
|
|
10
|
+
fiber: "fiber";
|
|
11
|
+
metal: "metal";
|
|
12
|
+
chemicals: "chemicals";
|
|
13
|
+
rations: "rations";
|
|
14
|
+
textiles: "textiles";
|
|
15
|
+
ammo: "ammo";
|
|
16
|
+
medkits: "medkits";
|
|
17
|
+
parts: "parts";
|
|
18
|
+
comms: "comms";
|
|
19
|
+
}>;
|
|
20
|
+
export declare const InventoryItemSchema: z.ZodEnum<{
|
|
21
|
+
ore: "ore";
|
|
22
|
+
fuel: "fuel";
|
|
23
|
+
grain: "grain";
|
|
24
|
+
fiber: "fiber";
|
|
25
|
+
metal: "metal";
|
|
26
|
+
chemicals: "chemicals";
|
|
27
|
+
rations: "rations";
|
|
28
|
+
textiles: "textiles";
|
|
29
|
+
ammo: "ammo";
|
|
30
|
+
medkits: "medkits";
|
|
31
|
+
parts: "parts";
|
|
32
|
+
comms: "comms";
|
|
33
|
+
credits: "credits";
|
|
34
|
+
}>;
|
|
35
|
+
export declare const ShipmentTypeSchema: z.ZodEnum<{
|
|
36
|
+
courier: "courier";
|
|
37
|
+
freight: "freight";
|
|
38
|
+
convoy: "convoy";
|
|
39
|
+
}>;
|
|
40
|
+
export declare const ContractTypeSchema: z.ZodEnum<{
|
|
41
|
+
haul: "haul";
|
|
42
|
+
supply: "supply";
|
|
43
|
+
scout: "scout";
|
|
44
|
+
}>;
|
|
45
|
+
export declare const FactionRankSchema: z.ZodEnum<{
|
|
46
|
+
founder: "founder";
|
|
47
|
+
officer: "officer";
|
|
48
|
+
member: "member";
|
|
49
|
+
}>;
|
|
50
|
+
export declare const JoinSchema: z.ZodObject<{
|
|
51
|
+
name: z.ZodString;
|
|
52
|
+
}, z.core.$strip>;
|
|
53
|
+
export declare const TravelSchema: z.ZodObject<{
|
|
54
|
+
to: z.ZodString;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
export declare const ExtractSchema: z.ZodObject<{
|
|
57
|
+
quantity: z.ZodNumber;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
export declare const ProduceSchema: z.ZodObject<{
|
|
60
|
+
output: z.ZodString;
|
|
61
|
+
quantity: z.ZodNumber;
|
|
62
|
+
}, z.core.$strip>;
|
|
63
|
+
export declare const CargoSchema: z.ZodRecord<z.ZodEnum<{
|
|
64
|
+
ore: "ore";
|
|
65
|
+
fuel: "fuel";
|
|
66
|
+
grain: "grain";
|
|
67
|
+
fiber: "fiber";
|
|
68
|
+
metal: "metal";
|
|
69
|
+
chemicals: "chemicals";
|
|
70
|
+
rations: "rations";
|
|
71
|
+
textiles: "textiles";
|
|
72
|
+
ammo: "ammo";
|
|
73
|
+
medkits: "medkits";
|
|
74
|
+
parts: "parts";
|
|
75
|
+
comms: "comms";
|
|
76
|
+
}>, z.ZodNumber>;
|
|
77
|
+
export declare const ShipSchema: z.ZodObject<{
|
|
78
|
+
type: z.ZodEnum<{
|
|
79
|
+
courier: "courier";
|
|
80
|
+
freight: "freight";
|
|
81
|
+
convoy: "convoy";
|
|
82
|
+
}>;
|
|
83
|
+
path: z.ZodArray<z.ZodString>;
|
|
84
|
+
cargo: z.ZodRecord<z.ZodEnum<{
|
|
85
|
+
ore: "ore";
|
|
86
|
+
fuel: "fuel";
|
|
87
|
+
grain: "grain";
|
|
88
|
+
fiber: "fiber";
|
|
89
|
+
metal: "metal";
|
|
90
|
+
chemicals: "chemicals";
|
|
91
|
+
rations: "rations";
|
|
92
|
+
textiles: "textiles";
|
|
93
|
+
ammo: "ammo";
|
|
94
|
+
medkits: "medkits";
|
|
95
|
+
parts: "parts";
|
|
96
|
+
comms: "comms";
|
|
97
|
+
}>, z.ZodNumber>;
|
|
98
|
+
}, z.core.$strip>;
|
|
99
|
+
export declare const MarketOrderSchema: z.ZodObject<{
|
|
100
|
+
resource: z.ZodEnum<{
|
|
101
|
+
ore: "ore";
|
|
102
|
+
fuel: "fuel";
|
|
103
|
+
grain: "grain";
|
|
104
|
+
fiber: "fiber";
|
|
105
|
+
metal: "metal";
|
|
106
|
+
chemicals: "chemicals";
|
|
107
|
+
rations: "rations";
|
|
108
|
+
textiles: "textiles";
|
|
109
|
+
ammo: "ammo";
|
|
110
|
+
medkits: "medkits";
|
|
111
|
+
parts: "parts";
|
|
112
|
+
comms: "comms";
|
|
113
|
+
}>;
|
|
114
|
+
side: z.ZodEnum<{
|
|
115
|
+
buy: "buy";
|
|
116
|
+
sell: "sell";
|
|
117
|
+
}>;
|
|
118
|
+
price: z.ZodNumber;
|
|
119
|
+
quantity: z.ZodNumber;
|
|
120
|
+
}, z.core.$strip>;
|
|
121
|
+
export declare const ScanSchema: z.ZodObject<{
|
|
122
|
+
targetType: z.ZodEnum<{
|
|
123
|
+
zone: "zone";
|
|
124
|
+
route: "route";
|
|
125
|
+
}>;
|
|
126
|
+
targetId: z.ZodString;
|
|
127
|
+
}, z.core.$strip>;
|
|
128
|
+
export declare const SupplySchema: z.ZodObject<{
|
|
129
|
+
amount: z.ZodNumber;
|
|
130
|
+
}, z.core.$strip>;
|
|
131
|
+
export declare const EscortAssignSchema: z.ZodObject<{
|
|
132
|
+
shipmentId: z.ZodString;
|
|
133
|
+
}, z.core.$strip>;
|
|
134
|
+
export declare const RaiderDeploySchema: z.ZodObject<{
|
|
135
|
+
routeId: z.ZodString;
|
|
136
|
+
}, z.core.$strip>;
|
|
137
|
+
export declare const UnitSellSchema: z.ZodObject<{
|
|
138
|
+
price: z.ZodNumber;
|
|
139
|
+
}, z.core.$strip>;
|
|
140
|
+
export declare const FactionCreateSchema: z.ZodObject<{
|
|
141
|
+
name: z.ZodString;
|
|
142
|
+
tag: z.ZodString;
|
|
143
|
+
}, z.core.$strip>;
|
|
144
|
+
export declare const ContractCreateSchema: z.ZodObject<{
|
|
145
|
+
type: z.ZodEnum<{
|
|
146
|
+
haul: "haul";
|
|
147
|
+
supply: "supply";
|
|
148
|
+
scout: "scout";
|
|
149
|
+
}>;
|
|
150
|
+
fromZoneId: z.ZodOptional<z.ZodString>;
|
|
151
|
+
toZoneId: z.ZodOptional<z.ZodString>;
|
|
152
|
+
resource: z.ZodOptional<z.ZodEnum<{
|
|
153
|
+
ore: "ore";
|
|
154
|
+
fuel: "fuel";
|
|
155
|
+
grain: "grain";
|
|
156
|
+
fiber: "fiber";
|
|
157
|
+
metal: "metal";
|
|
158
|
+
chemicals: "chemicals";
|
|
159
|
+
rations: "rations";
|
|
160
|
+
textiles: "textiles";
|
|
161
|
+
ammo: "ammo";
|
|
162
|
+
medkits: "medkits";
|
|
163
|
+
parts: "parts";
|
|
164
|
+
comms: "comms";
|
|
165
|
+
}>>;
|
|
166
|
+
quantity: z.ZodOptional<z.ZodNumber>;
|
|
167
|
+
reward: z.ZodNumber;
|
|
168
|
+
deadline: z.ZodNumber;
|
|
169
|
+
bonus: z.ZodOptional<z.ZodNumber>;
|
|
170
|
+
bonusDeadline: z.ZodOptional<z.ZodNumber>;
|
|
171
|
+
}, z.core.$strip>;
|
|
172
|
+
export declare const WebhookCreateSchema: z.ZodObject<{
|
|
173
|
+
url: z.ZodString;
|
|
174
|
+
events: z.ZodArray<z.ZodEnum<{
|
|
175
|
+
shipment_arrived: "shipment_arrived";
|
|
176
|
+
shipment_intercepted: "shipment_intercepted";
|
|
177
|
+
zone_captured: "zone_captured";
|
|
178
|
+
contract_completed: "contract_completed";
|
|
179
|
+
zone_critical: "zone_critical";
|
|
180
|
+
market_order_filled: "market_order_filled";
|
|
181
|
+
under_attack: "under_attack";
|
|
182
|
+
}>>;
|
|
183
|
+
}, z.core.$strip>;
|
|
184
|
+
export type JoinRequest = z.infer<typeof JoinSchema>;
|
|
185
|
+
export type TravelRequest = z.infer<typeof TravelSchema>;
|
|
186
|
+
export type ExtractRequest = z.infer<typeof ExtractSchema>;
|
|
187
|
+
export type ProduceRequest = z.infer<typeof ProduceSchema>;
|
|
188
|
+
export type ShipRequest = z.infer<typeof ShipSchema>;
|
|
189
|
+
export type MarketOrderRequest = z.infer<typeof MarketOrderSchema>;
|
|
190
|
+
export type ScanRequest = z.infer<typeof ScanSchema>;
|
|
191
|
+
export type SupplyRequest = z.infer<typeof SupplySchema>;
|
|
192
|
+
export type FactionCreateRequest = z.infer<typeof FactionCreateSchema>;
|
|
193
|
+
export type ContractCreateRequest = z.infer<typeof ContractCreateSchema>;
|
|
194
|
+
export type WebhookCreateRequest = z.infer<typeof WebhookCreateSchema>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BURNRATE API Validation Schemas
|
|
3
|
+
* Using Zod for runtime validation
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// COMMON SCHEMAS
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Tradeable resources (excluding credits which is currency)
|
|
10
|
+
export const ResourceSchema = z.enum([
|
|
11
|
+
'ore', 'fuel', 'grain', 'fiber',
|
|
12
|
+
'metal', 'chemicals', 'rations', 'textiles',
|
|
13
|
+
'ammo', 'medkits', 'parts', 'comms'
|
|
14
|
+
]);
|
|
15
|
+
// All inventory items including credits
|
|
16
|
+
export const InventoryItemSchema = z.enum([
|
|
17
|
+
'ore', 'fuel', 'grain', 'fiber',
|
|
18
|
+
'metal', 'chemicals', 'rations', 'textiles',
|
|
19
|
+
'ammo', 'medkits', 'parts', 'comms',
|
|
20
|
+
'credits'
|
|
21
|
+
]);
|
|
22
|
+
export const ShipmentTypeSchema = z.enum(['courier', 'freight', 'convoy']);
|
|
23
|
+
export const ContractTypeSchema = z.enum(['haul', 'supply', 'scout']);
|
|
24
|
+
export const FactionRankSchema = z.enum(['founder', 'officer', 'member']);
|
|
25
|
+
// ============================================================================
|
|
26
|
+
// REQUEST SCHEMAS
|
|
27
|
+
// ============================================================================
|
|
28
|
+
export const JoinSchema = z.object({
|
|
29
|
+
name: z.string()
|
|
30
|
+
.min(2, 'Name must be at least 2 characters')
|
|
31
|
+
.max(20, 'Name must be at most 20 characters')
|
|
32
|
+
.regex(/^[a-zA-Z0-9_-]+$/, 'Name can only contain letters, numbers, underscores, and hyphens')
|
|
33
|
+
});
|
|
34
|
+
export const TravelSchema = z.object({
|
|
35
|
+
to: z.string().min(1, 'Destination zone ID required')
|
|
36
|
+
});
|
|
37
|
+
export const ExtractSchema = z.object({
|
|
38
|
+
quantity: z.number().int().min(1, 'Quantity must be at least 1').max(1000, 'Quantity cannot exceed 1000')
|
|
39
|
+
});
|
|
40
|
+
export const ProduceSchema = z.object({
|
|
41
|
+
output: z.string().min(1, 'Output type required'),
|
|
42
|
+
quantity: z.number().int().min(1, 'Quantity must be at least 1').max(100, 'Quantity cannot exceed 100')
|
|
43
|
+
});
|
|
44
|
+
export const CargoSchema = z.record(ResourceSchema, z.number().int().min(0).max(10000)).refine((cargo) => Object.values(cargo).some(v => v > 0), 'Cargo must contain at least one resource');
|
|
45
|
+
export const ShipSchema = z.object({
|
|
46
|
+
type: ShipmentTypeSchema,
|
|
47
|
+
path: z.array(z.string()).min(2, 'Path must have at least origin and destination'),
|
|
48
|
+
cargo: CargoSchema
|
|
49
|
+
});
|
|
50
|
+
export const MarketOrderSchema = z.object({
|
|
51
|
+
resource: ResourceSchema,
|
|
52
|
+
side: z.enum(['buy', 'sell']),
|
|
53
|
+
price: z.number().int().min(1, 'Price must be at least 1').max(100000, 'Price cannot exceed 100000'),
|
|
54
|
+
quantity: z.number().int().min(1, 'Quantity must be at least 1').max(10000, 'Quantity cannot exceed 10000')
|
|
55
|
+
});
|
|
56
|
+
export const ScanSchema = z.object({
|
|
57
|
+
targetType: z.enum(['zone', 'route']),
|
|
58
|
+
targetId: z.string().min(1, 'Target ID required')
|
|
59
|
+
});
|
|
60
|
+
export const SupplySchema = z.object({
|
|
61
|
+
amount: z.number().int().min(1, 'Amount must be at least 1').max(1000, 'Amount cannot exceed 1000')
|
|
62
|
+
});
|
|
63
|
+
export const EscortAssignSchema = z.object({
|
|
64
|
+
shipmentId: z.string().min(1, 'Shipment ID required')
|
|
65
|
+
});
|
|
66
|
+
export const RaiderDeploySchema = z.object({
|
|
67
|
+
routeId: z.string().min(1, 'Route ID required')
|
|
68
|
+
});
|
|
69
|
+
export const UnitSellSchema = z.object({
|
|
70
|
+
price: z.number().int().min(1, 'Price must be at least 1').max(100000, 'Price cannot exceed 100000')
|
|
71
|
+
});
|
|
72
|
+
export const FactionCreateSchema = z.object({
|
|
73
|
+
name: z.string()
|
|
74
|
+
.min(3, 'Faction name must be at least 3 characters')
|
|
75
|
+
.max(30, 'Faction name must be at most 30 characters'),
|
|
76
|
+
tag: z.string()
|
|
77
|
+
.min(2, 'Tag must be at least 2 characters')
|
|
78
|
+
.max(5, 'Tag must be at most 5 characters')
|
|
79
|
+
.regex(/^[A-Z0-9]+$/, 'Tag must be uppercase letters and numbers only')
|
|
80
|
+
});
|
|
81
|
+
export const ContractCreateSchema = z.object({
|
|
82
|
+
type: ContractTypeSchema,
|
|
83
|
+
fromZoneId: z.string().optional(),
|
|
84
|
+
toZoneId: z.string().optional(),
|
|
85
|
+
resource: ResourceSchema.optional(),
|
|
86
|
+
quantity: z.number().int().min(1).max(10000).optional(),
|
|
87
|
+
reward: z.number().int().min(1, 'Reward must be at least 1').max(100000),
|
|
88
|
+
deadline: z.number().int().min(10, 'Deadline must be at least 10 ticks').max(1000, 'Deadline cannot exceed 1000 ticks'),
|
|
89
|
+
bonus: z.number().int().min(0).max(100000).optional(),
|
|
90
|
+
bonusDeadline: z.number().int().min(1).optional()
|
|
91
|
+
}).refine((data) => {
|
|
92
|
+
if (data.type === 'haul') {
|
|
93
|
+
return data.fromZoneId && data.toZoneId && data.resource && data.quantity;
|
|
94
|
+
}
|
|
95
|
+
if (data.type === 'supply') {
|
|
96
|
+
return data.toZoneId && data.quantity;
|
|
97
|
+
}
|
|
98
|
+
if (data.type === 'scout') {
|
|
99
|
+
return data.toZoneId;
|
|
100
|
+
}
|
|
101
|
+
return false;
|
|
102
|
+
}, 'Missing required fields for contract type');
|
|
103
|
+
export const WebhookCreateSchema = z.object({
|
|
104
|
+
url: z.string().url('Invalid webhook URL'),
|
|
105
|
+
events: z.array(z.enum([
|
|
106
|
+
'shipment_arrived',
|
|
107
|
+
'shipment_intercepted',
|
|
108
|
+
'zone_critical',
|
|
109
|
+
'zone_captured',
|
|
110
|
+
'contract_completed',
|
|
111
|
+
'market_order_filled',
|
|
112
|
+
'under_attack'
|
|
113
|
+
])).min(1, 'Must subscribe to at least one event')
|
|
114
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "burnrate",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A logistics war MMO for Claude Code. The front doesn't feed itself.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/cli/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"burnrate": "./dist/cli/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist/",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"dev": "tsx src/cli/index.ts",
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"start": "node dist/cli/index.js",
|
|
19
|
+
"setup": "node dist/cli/setup.js",
|
|
20
|
+
"api": "node dist/server/api.js",
|
|
21
|
+
"api:dev": "tsx src/server/api.ts",
|
|
22
|
+
"mcp": "node dist/mcp/server.js",
|
|
23
|
+
"tick": "node dist/server/async-tick-server.js",
|
|
24
|
+
"tick:fast": "BURNRATE_TICK_INTERVAL=1000 node dist/server/async-tick-server.js",
|
|
25
|
+
"tick:legacy": "node dist/server/tick-server.js",
|
|
26
|
+
"server": "node dist/server/api.js",
|
|
27
|
+
"test": "tsx --test src/**/*.test.ts"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"game",
|
|
31
|
+
"mmo",
|
|
32
|
+
"logistics",
|
|
33
|
+
"claude",
|
|
34
|
+
"cli",
|
|
35
|
+
"claude-code",
|
|
36
|
+
"strategy"
|
|
37
|
+
],
|
|
38
|
+
"author": "burnrate-cc",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/burnrate-cc/burnrate.git"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/burnrate-cc/burnrate#readme",
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/burnrate-cc/burnrate/issues"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@hono/node-server": "^1.19.9",
|
|
50
|
+
"@libsql/client": "^0.17.0",
|
|
51
|
+
"@modelcontextprotocol/sdk": "^1.25.3",
|
|
52
|
+
"better-sqlite3": "^12.6.2",
|
|
53
|
+
"commander": "^14.0.2",
|
|
54
|
+
"hono": "^4.11.7",
|
|
55
|
+
"tsx": "^4.21.0",
|
|
56
|
+
"typescript": "^5.9.3",
|
|
57
|
+
"uuid": "^13.0.0",
|
|
58
|
+
"zod": "^4.3.6"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
62
|
+
"@types/node": "^25.0.10",
|
|
63
|
+
"@types/uuid": "^11.0.0"
|
|
64
|
+
}
|
|
65
|
+
}
|