@hira-core/sdk 1.0.0 → 1.0.2

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 (3) hide show
  1. package/README.md +232 -0
  2. package/dist/index.js +1 -1
  3. package/package.json +11 -3
package/README.md ADDED
@@ -0,0 +1,232 @@
1
+ # @hira-core/sdk
2
+
3
+ SDK for building **Hira** automation flows with TypeScript. Provides type-safe base classes, browser utilities, and logger for running flows inside the Hira Agent sandbox.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @hira-core/sdk
9
+ # or
10
+ pnpm add @hira-core/sdk
11
+ ```
12
+
13
+ > **Peer dependency:** Requires `puppeteer-core` to be available at runtime (provided by the Hira Agent).
14
+
15
+ ---
16
+
17
+ ## Quick Start
18
+
19
+ ### 1. Define your Flow Config
20
+
21
+ ```typescript
22
+ import {
23
+ AntidetectBaseFlow,
24
+ AntidetectProvider,
25
+ IFlowConfig,
26
+ IScriptContext,
27
+ BrowserUtils,
28
+ FlowLogger,
29
+ } from "@hira-core/sdk";
30
+
31
+ const config = {
32
+ globalInput: [
33
+ { key: "targetUrl", label: "Target URL", type: "text" as const, required: true },
34
+ { key: "delay", label: "Delay (ms)", type: "number" as const, defaultValue: 2000 },
35
+ ],
36
+ profileInput: [
37
+ { key: "username", label: "Username", type: "text" as const },
38
+ { key: "password", label: "Password", type: "text" as const },
39
+ ],
40
+ } as const satisfies IFlowConfig;
41
+
42
+ type MyConfig = typeof config;
43
+ ```
44
+
45
+ ### 2. Implement your Flow class
46
+
47
+ ```typescript
48
+ export class MyFlow extends AntidetectBaseFlow<MyConfig> {
49
+ constructor() {
50
+ super(AntidetectProvider.GPM, new FlowLogger(MyFlow.name), config);
51
+ }
52
+
53
+ async script(context: IScriptContext<MyConfig>): Promise<void> {
54
+ const { page, logger, globalInput, profileInput } = context;
55
+ const utils = new BrowserUtils(context);
56
+
57
+ await utils.goto(globalInput.targetUrl);
58
+ logger.info(`Logging in as: ${profileInput.username}`);
59
+
60
+ await utils.type("#username", profileInput.username);
61
+ await utils.type("#password", profileInput.password);
62
+ await utils.click("#login-btn");
63
+
64
+ const title = await page.title();
65
+ logger.success(`✅ Done — page: ${title}`);
66
+ }
67
+ }
68
+
69
+ export default MyFlow;
70
+ ```
71
+
72
+ ### 3. Run locally (for development)
73
+
74
+ ```typescript
75
+ import MyFlow from "./index";
76
+
77
+ const flow = new MyFlow();
78
+
79
+ await flow.run(
80
+ flow.createRunParams({
81
+ antidetect: {
82
+ name: "GPM",
83
+ profileSettings: [
84
+ flow.createProfileSetting("ProfileA", { username: "user1", password: "pass1" }),
85
+ ],
86
+ },
87
+ execution: { concurrency: 2, maxRetries: 1 },
88
+ globalInput: { targetUrl: "https://example.com", delay: 2000 },
89
+ window: { width: 1280, height: 720, scale: 1 },
90
+ })
91
+ );
92
+ ```
93
+
94
+ ---
95
+
96
+ ## API Reference
97
+
98
+ ### `AntidetectBaseFlow<TConfig>`
99
+
100
+ Abstract base class for browser automation flows.
101
+
102
+ | Method / Property | Description |
103
+ |---|---|
104
+ | `abstract script(context)` | Your automation logic — implement this |
105
+ | `run(params)` | Start the flow (called by Hira Agent) |
106
+ | `createRunParams(params)` | Type-safe helper to build run params |
107
+ | `createProfileSetting(name, data?)` | Type-safe helper to build profile settings |
108
+ | `flowConfig` | The declared config schema (embedded in `.hira`) |
109
+
110
+ ### `AntidetectProvider`
111
+
112
+ ```typescript
113
+ enum AntidetectProvider {
114
+ GPM = "gpm", // GPM Login antidetect browser
115
+ HIDEMIUM = "hidemium", // coming soon
116
+ GENLOGIN = "genlogin", // coming soon
117
+ }
118
+ ```
119
+
120
+ ### `IScriptContext<TConfig>`
121
+
122
+ Injected into `script()` by the runtime:
123
+
124
+ | Field | Type | Description |
125
+ |---|---|---|
126
+ | `browser` | `Browser` | Puppeteer browser instance |
127
+ | `page` | `Page` | Active page |
128
+ | `profile` | `IGpmProfile` | Current GPM profile info |
129
+ | `index` | `number` | Profile index in the batch |
130
+ | `globalInput` | `InferGlobalInput<TConfig>` | Typed global inputs |
131
+ | `profileInput` | `InferProfileInput<TConfig>` | Typed per-profile inputs |
132
+ | `logger` | `ILogger` | Bound logger (auto-tagged with profile name) |
133
+
134
+ ### `BrowserUtils`
135
+
136
+ Helper class for common browser actions. All methods auto-log and respect the abort signal.
137
+
138
+ ```typescript
139
+ const utils = new BrowserUtils(context);
140
+ ```
141
+
142
+ | Method | Description |
143
+ |---|---|
144
+ | `utils.goto(url)` | Navigate to URL |
145
+ | `utils.click(selector)` | Wait + scroll + click |
146
+ | `utils.type(selector, text)` | Wait + clear + type |
147
+ | `utils.getText(selector)` | Get text content |
148
+ | `utils.exists(selector, timeout?)` | Check element exists |
149
+ | `utils.waitForElement(selector, timeout?)` | Wait for element |
150
+ | `utils.waitForNavigation()` | Wait for page navigation |
151
+ | `utils.screenshot(path?)` | Take screenshot |
152
+ | `utils.switchToPopup(matcher)` | Switch to popup tab |
153
+ | `utils.switchToTabIndex(index)` | Switch to tab by index |
154
+ | `utils.closeCurrentTab()` | Close current tab |
155
+ | `utils.closeOtherTabs()` | Close all other tabs |
156
+ | `utils.sleep(ms)` | Delay (respects abort signal) |
157
+ | `utils.logGlobalInput()` | Log all global inputs |
158
+ | `utils.logProfileInput()` | Log all profile inputs |
159
+
160
+ ### `FlowLogger`
161
+
162
+ Logger that works both in standalone mode (console) and inside Hira Agent worker (postMessage).
163
+
164
+ ```typescript
165
+ const logger = new FlowLogger("MyFlow");
166
+
167
+ logger.info("message");
168
+ logger.success("done");
169
+ logger.warn("warning");
170
+ logger.error("error");
171
+ logger.debug("debug");
172
+ ```
173
+
174
+ ### `IFlowConfig`
175
+
176
+ Schema declaration for your flow's inputs:
177
+
178
+ ```typescript
179
+ interface IFlowConfig {
180
+ globalInput: readonly IInputField[]; // shared across all profiles
181
+ profileInput: readonly IInputField[]; // per-profile data
182
+ }
183
+
184
+ interface IInputField {
185
+ key: string;
186
+ label: string;
187
+ type: "text" | "number" | "boolean" | "select" | "textarea";
188
+ required?: boolean;
189
+ defaultValue?: string | number | boolean;
190
+ placeholder?: string;
191
+ options?: { label: string; value: string | number }[];
192
+ }
193
+ ```
194
+
195
+ ---
196
+
197
+ ## Type Inference
198
+
199
+ The SDK automatically infers TypeScript types from your config at compile time:
200
+
201
+ ```typescript
202
+ const config = {
203
+ globalInput: [
204
+ { key: "url", type: "text" as const },
205
+ { key: "count", type: "number" as const },
206
+ ],
207
+ profileInput: [
208
+ { key: "username", type: "text" as const },
209
+ ],
210
+ } as const satisfies IFlowConfig;
211
+
212
+ // Inside script():
213
+ // globalInput.url → string ✅
214
+ // globalInput.count → number ✅
215
+ // profileInput.username → string ✅
216
+ ```
217
+
218
+ ---
219
+
220
+ ## Building & Publishing a Flow
221
+
222
+ Use [`@hira-core/cli`](https://www.npmjs.com/package/@hira-core/cli) to package your flow:
223
+
224
+ ```bash
225
+ npx @hira-core/cli build
226
+ ```
227
+
228
+ ---
229
+
230
+ ## License
231
+
232
+ ISC