@nighthawk.hq/macro-sdk 0.1.3 → 0.2.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/build/index.js CHANGED
@@ -8,11 +8,23 @@ const MANIFEST = JSON.parse(readFileSync(join(HERE, '..', 'runtime-manifest.json
8
8
  const SPECIFIER = '@nighthawk.hq/macro-sdk';
9
9
  const MAX_BYTES = 256 * 1024;
10
10
 
11
+ // Manifest values are spliced into generated shim code — refuse anything that
12
+ // isn't a plain identifier / integer rather than trust the file blindly.
13
+ if (!Number.isInteger(MANIFEST.protocol)) {
14
+ throw new Error('runtime-manifest.json: protocol must be an integer');
15
+ }
16
+ for (const n of MANIFEST.exports) {
17
+ if (!/^[A-Za-z_$][\w$]*$/.test(n)) {
18
+ throw new Error(`runtime-manifest.json: invalid export name ${JSON.stringify(n)}`);
19
+ }
20
+ }
21
+
11
22
  function externalSdkPlugin() {
12
23
  const shim =
13
24
  'const s = globalThis.__nhSdk;\n' +
14
25
  "if (!s) throw new Error('Nighthawk SDK runtime not present in this realm');\n" +
15
- MANIFEST.map((n) => `export const ${n} = s.${n};`).join('\n') +
26
+ `if (s.SDK_PROTOCOL !== ${MANIFEST.protocol}) throw new Error('macro built for SDK protocol ${MANIFEST.protocol}, host provides ' + s.SDK_PROTOCOL + ' — rebuild with the current macro-sdk');\n` +
27
+ MANIFEST.exports.map((n) => `export const ${n} = s.${n};`).join('\n') +
16
28
  '\n';
17
29
  return {
18
30
  name: 'nighthawk-sdk-external',
@@ -36,6 +48,9 @@ export async function buildMacro({ id, entry, outDir, minify = false }) {
36
48
  platform: 'neutral',
37
49
  minify,
38
50
  outfile,
51
+ // Protocol stamp: the host reads this before evaluating the bundle.
52
+ // banner is applied to the output verbatim, so it survives minify.
53
+ banner: { js: `/*! nh-sdk-protocol:${MANIFEST.protocol} */` },
39
54
  plugins: [externalSdkPlugin()],
40
55
  logLevel: 'info',
41
56
  });
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { SDK_PROTOCOL } from './protocol';
1
2
  export { Macro, OnStart, OnStop, OnTick, Action, Panel, Overlay } from './decorators';
2
3
  export type { ActionOptions } from './decorators';
3
4
  export { MacroBase } from './macro-base';
@@ -16,4 +17,4 @@ export { struct, f } from './process/struct';
16
17
  export type { StructSpec } from './process/struct';
17
18
  export type { ProcessAccess } from './process/process-access';
18
19
  export type { Point, Region, RegionRatio, ColorRGB } from './geometry';
19
- export type { ScriptCtx, Target, GameId, WindowTarget, ProcessTarget, PackageDeclaration, PixelReadout, MouseButton, } from './types';
20
+ export type { ScriptCtx, Target, GameId, ProcessTarget, PackageDeclaration, MouseButton, } from './types';
@@ -0,0 +1 @@
1
+ export declare const SDK_PROTOCOL = 1;
package/lib/types.d.ts CHANGED
@@ -3,9 +3,6 @@ import type { PanelDeclaration, Widget } from './panel-types';
3
3
  import type { ProcessAccess } from './process/process-access';
4
4
  import type { RobloxOffsets } from './roblox/offsets';
5
5
  import type { SettingMap } from './settings';
6
- export type PixelReadout = ColorRGB & {
7
- hex: string;
8
- };
9
6
  export type MouseButton = 'left' | 'right' | 'middle';
10
7
  export type ScriptCtx = {
11
8
  settings: Record<string, unknown>;
@@ -17,29 +14,6 @@ export type ScriptCtx = {
17
14
  sleep(ms: number): Promise<void>;
18
15
  /** Wall-clock time in milliseconds (host-mediated; equivalent to `Date.now()`). */
19
16
  now(): number;
20
- screen: {
21
- captureRegion(name: string): Promise<Buffer>;
22
- pixelAt(name: string): Promise<PixelReadout>;
23
- pixelAtPoint(point: Point): Promise<PixelReadout>;
24
- pixelAtRatio(rx: number, ry: number): Promise<PixelReadout>;
25
- pixelMatches(settingName: string): Promise<boolean>;
26
- pixelMatches(name: string, hex: string, tolerance?: number): Promise<boolean>;
27
- pixelMatchesAt(point: Point, hex: string, tolerance?: number): Promise<boolean>;
28
- findColor(settingName: string): Promise<Array<{
29
- x: number;
30
- y: number;
31
- distance: number;
32
- }>>;
33
- findColor(regionName: string, hex: string, opts?: {
34
- tolerance?: number;
35
- limit?: number;
36
- step?: number;
37
- }): Promise<Array<{
38
- x: number;
39
- y: number;
40
- distance: number;
41
- }>>;
42
- };
43
17
  input: {
44
18
  click(name: string, button?: MouseButton): Promise<void>;
45
19
  clickAt(point: Point, button?: MouseButton): Promise<void>;
@@ -74,14 +48,6 @@ export type ScriptCtx = {
74
48
  /** Identifies which game an offset set belongs to, so the runtime knows which
75
49
  * table to fetch and inject as `ctx.offsets`. Roblox is the only game today. */
76
50
  export type GameId = 'roblox';
77
- export type WindowTarget = {
78
- kind: 'window';
79
- titlePattern: RegExp;
80
- referenceSize: {
81
- w: number;
82
- h: number;
83
- };
84
- };
85
51
  export type ProcessTarget = {
86
52
  kind: 'process';
87
53
  processName?: string;
@@ -89,7 +55,7 @@ export type ProcessTarget = {
89
55
  expectedVersion?: string;
90
56
  game?: GameId;
91
57
  };
92
- export type Target = WindowTarget | ProcessTarget;
58
+ export type Target = ProcessTarget;
93
59
  export type PackageDeclaration = {
94
60
  schemaVersion: number;
95
61
  target?: Target;
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@nighthawk.hq/macro-sdk",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
+ "packageManager": "pnpm@10.34.1",
4
5
  "description": "Nighthawk macro author SDK — types only. Runtime is provided by the host.",
5
6
  "type": "module",
6
7
  "repository": {
@@ -14,6 +15,7 @@
14
15
  },
15
16
  "files": ["lib/**/*.d.ts", "stub.js", "build/index.js", "runtime-manifest.json"],
16
17
  "scripts": {
18
+ "generate": "node scripts/generate.mjs",
17
19
  "test": "node --test test/shim.test.mjs"
18
20
  },
19
21
  "dependencies": {
@@ -1,37 +1,41 @@
1
- [
2
- "Action",
3
- "Address",
4
- "Button",
5
- "Chip",
6
- "Divider",
7
- "Group",
8
- "Image",
9
- "Instance",
10
- "Macro",
11
- "MacroBase",
12
- "Meter",
13
- "OnStart",
14
- "OnStop",
15
- "OnTick",
16
- "Overlay",
17
- "Panel",
18
- "Roblox",
19
- "Row",
20
- "Stat",
21
- "Text",
22
- "boolean",
23
- "color",
24
- "defaultsOf",
25
- "f",
26
- "findColor",
27
- "number",
28
- "offsetsFromDump",
29
- "pixelColor",
30
- "point",
31
- "ratio",
32
- "region",
33
- "robloxTarget",
34
- "select",
35
- "string",
36
- "struct"
37
- ]
1
+ {
2
+ "protocol": 1,
3
+ "exports": [
4
+ "Action",
5
+ "Address",
6
+ "Button",
7
+ "Chip",
8
+ "Divider",
9
+ "Group",
10
+ "Image",
11
+ "Instance",
12
+ "Macro",
13
+ "MacroBase",
14
+ "Meter",
15
+ "OnStart",
16
+ "OnStop",
17
+ "OnTick",
18
+ "Overlay",
19
+ "Panel",
20
+ "Roblox",
21
+ "Row",
22
+ "SDK_PROTOCOL",
23
+ "Stat",
24
+ "Text",
25
+ "boolean",
26
+ "color",
27
+ "defaultsOf",
28
+ "f",
29
+ "findColor",
30
+ "number",
31
+ "offsetsFromDump",
32
+ "pixelColor",
33
+ "point",
34
+ "ratio",
35
+ "region",
36
+ "robloxTarget",
37
+ "select",
38
+ "string",
39
+ "struct"
40
+ ]
41
+ }