@microlink/function 0.2.4 → 0.2.6

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 +336 -110
  2. package/package.json +15 -58
  3. package/src/index.d.ts +40 -14
package/README.md CHANGED
@@ -4,202 +4,428 @@
4
4
  <br>
5
5
  <br>
6
6
  <br>
7
- <p style="max-width: 400px;"><b>Microlink Function</b> allows you to run JavaScript Serverless functions with <a target="_blank" href="https://browserless.js.org">Headless Chromium</a> programmatic access.</p>
8
- </div>
9
-
10
- <div align="center">
11
- <img src="https://i.imgur.com/4PWrzx2.png" width="700px">
7
+ <p style="max-width: 400px;"><b>@microlink/function</b> lets you write normal JavaScript functions and run them remotely with the <a href="https://microlink.io/docs/api/parameters/function">Microlink function</a> parameter — full Puppeteer access, npm packages, and zero infrastructure.</p>
12
8
  </div>
13
9
 
14
10
  ## Highlights
15
11
 
16
12
  - Starts from \$0/mo.
17
- - Run Serverless Javascript functions (also [locally](https://github.com/microlinkhq/local)).
18
- - Ability to require to require any of the [allowed](#npm-packages) NPM packages.
19
- - Headless Chromium browser access in the same request cycle.
20
- - No servers to maintain, no hidden cost or infrastructure complexity.
13
+ - Run JavaScript remotely with no servers, bundles, or browser fleet to manage.
14
+ - Full Puppeteer access when your function references `page`.
15
+ - `require()` any npm package dependencies are detected and installed on-the-fly.
16
+ - Automatic serialization and compression of function bodies.
17
+ - Execution metrics at `result.profiling`.
21
18
 
22
- ## Contents
19
+ ## Documentation
23
20
 
24
- - [How it works](#how-it-works)
25
- - [Installation](#installation)
26
- - [from NPM](#from-npm)
27
- - [from CDN](#from-cdn)
28
- - [Get Started](#get-started)
29
- - [Input](#input)
30
- - [NPM packages](#npm-packages)
31
- - [Output](#output)
32
- - [Examples](#examples)
33
- - [Pricing](#pricing)
34
- - [API](#api)
35
- - [License](#license)
21
+ The full guides live on [microlink.io](https://microlink.io/docs/guides/function):
36
22
 
37
- ## How it works
23
+ - [Function](https://microlink.io/docs/guides/function) — overview and when to use it.
24
+ - [Writing functions](https://microlink.io/docs/guides/function/writing-functions) — return values, custom parameters, and npm packages.
25
+ - [Browser interaction](https://microlink.io/docs/guides/function/browser-interaction) — Puppeteer helpers and page automation.
26
+ - [Profiling and performance](https://microlink.io/docs/guides/function/profiling-and-performance) — execution phases, plan limits, and optimization.
27
+ - [Troubleshooting](https://microlink.io/docs/guides/function/troubleshooting) — error handling and common failure modes.
38
28
 
39
- Every time you call a **Microlink Function**, the code function will be compiled and executed remotely in a safe V8 sandbox.
29
+ ## Installation
40
30
 
41
- It's pretty similar to AWS Lambda, but rather than bundle your code, all the code will be executed remotely, giving the result of the execution back to you.
31
+ ```bash
32
+ npm install @microlink/function
33
+ ```
42
34
 
43
- **Microlink Function** can be invoked in frontend or backend side. There is nothing to deploy or hidden infrastructure cost associated.
35
+ Load directly in the browser from a CDN:
44
36
 
45
- ## Installation
37
+ ```html
38
+ <script src="https://cdn.jsdelivr.net/npm/@microlink/function/dist/microlink-function.min.js"></script>
39
+ ```
46
40
 
47
- ### from NPM
41
+ ## Your first function
48
42
 
49
- It's available as [npm package](https://www.npmjs.com/package/@microlink/function):
43
+ Pass a JavaScript function and a target URL. The library handles serialization, compression, and the API call:
50
44
 
51
- ```bash
52
- $ npm install @microlink/function --save
45
+ ```js
46
+ const microlink = require('@microlink/function')
47
+
48
+ const fn = microlink(() => 40 + 2)
49
+
50
+ const result = await fn('https://example.com')
51
+
52
+ console.log(result.isFulfilled) // true
53
+ console.log(result.value) // 42
54
+ console.log(result.profiling) // { phases: { ... }, cpu, memory, size }
53
55
  ```
54
56
 
55
- ### from CDN
57
+ When your function references `page`, Microlink starts a headless browser and gives you full Puppeteer access:
56
58
 
57
- Load directly in the browser from your favorite CDN:
59
+ ```js
60
+ const microlink = require('@microlink/function')
58
61
 
59
- ```html
60
- <script src="https://cdn.jsdelivr.net/npm/@microlink/function/dist/microlink-function.min.js"></script>
62
+ const getTitle = ({ page }) => page.title()
63
+
64
+ const fn = microlink(getTitle)
65
+
66
+ const result = await fn('https://example.com')
67
+
68
+ console.log(result.value) // 'Example Domain'
61
69
  ```
62
70
 
63
- ## Get Started
71
+ When your function does **not** reference `page`, no browser is started — execution is faster and cheaper.
72
+
73
+ ## Writing functions
64
74
 
65
- ### Input
75
+ ### Return any value
66
76
 
67
- Let say you have a JavaScript like this:
77
+ Functions can return strings, numbers, booleans, arrays, or plain objects:
68
78
 
69
79
  ```js
70
- const ping = ({ statusCode, response }) =>
71
- statusCode ? response.status() : response.statusText()
80
+ const microlink = require('@microlink/function')
81
+
82
+ const fn = microlink(() => ({
83
+ greeting: 'Hello',
84
+ items: [1, 2, 3],
85
+ nested: { works: true }
86
+ }))
87
+
88
+ const result = await fn('https://example.com')
89
+
90
+ console.log(result.value)
91
+ // { greeting: 'Hello', items: [1, 2, 3], nested: { works: true } }
72
92
  ```
73
93
 
74
- To run the previous code as **Microlink Function**, all you need to do is wrap the function with the `microlink` decorator:
94
+ The return value is always at `result.value`. If the function throws, `result.isFulfilled` is `false` and `result.value` contains the error details.
95
+
96
+ ### Custom parameters
97
+
98
+ Any extra option you pass to the returned function is forwarded to your code:
75
99
 
76
100
  ```js
77
101
  const microlink = require('@microlink/function')
78
102
 
79
- const ping = microlink(({ response }) =>
80
- statusCode ? response.status() : response.statusText()
81
- )
103
+ const greet = ({ name, greeting }) => `${greeting}, ${name}!`
104
+
105
+ const fn = microlink(greet)
106
+
107
+ const result = await fn('https://example.com', {
108
+ name: 'Kiko',
109
+ greeting: 'Hello'
110
+ })
111
+
112
+ console.log(result.value) // 'Hello, Kiko!'
82
113
  ```
83
114
 
84
- Then, just call the function as you would normally:
115
+ ### npm packages
116
+
117
+ You can `require()` any npm package inside your function. Dependencies are detected automatically and installed on-the-fly:
85
118
 
86
119
  ```js
87
- const result = await ping('https://example.com', { statusCode: true })
120
+ const microlink = require('@microlink/function')
88
121
 
89
- console.log(result)
122
+ const fn = microlink(() => {
123
+ const { kebabCase } = require('lodash')
124
+ return kebabCase('Hello World')
125
+ })
90
126
 
91
- // {
92
- // isFullfilled: true,
93
- // isRejected: false,
94
- // value: 200
95
- // }
127
+ const result = await fn('https://example.com')
128
+
129
+ console.log(result.value) // 'hello-world'
130
+ ```
131
+
132
+ Pin a version by appending it to the package name:
133
+
134
+ ```js
135
+ const cheerio = require('cheerio@1.0.0')
136
+ ```
137
+
138
+ When no version is specified, the latest version is installed. Check `result.profiling.phases` — a high `install` value on the first run is normal and drops to zero once cached.
139
+
140
+ ### Security restrictions
141
+
142
+ The runtime restricts certain system capabilities. Operations such as spawning child processes or writing to the filesystem outside the sandbox are not permitted:
143
+
144
+ ```json
145
+ {
146
+ "isFulfilled": false,
147
+ "value": {
148
+ "name": "Error",
149
+ "code": "ERR_ACCESS_DENIED",
150
+ "permission": "ChildProcess",
151
+ "message": "Access to this API has been restricted."
152
+ }
153
+ }
154
+ ```
155
+
156
+ ## Browser interaction
157
+
158
+ When your function references `page`, you get the full Puppeteer `Page` object:
159
+
160
+ ```js
161
+ const microlink = require('@microlink/function')
162
+
163
+ const scrape = ({ page }) =>
164
+ page.$eval('h1', el => el.textContent.trim())
165
+
166
+ const fn = microlink(scrape)
167
+
168
+ const result = await fn('https://example.com')
169
+
170
+ console.log(result.value) // 'Example Domain'
96
171
  ```
97
172
 
98
- When a function is wrapped by **Microlink Function** the function execution is done remotely, giving back the result.
173
+ Start with the high-level helpers before reaching for lower-level APIs:
99
174
 
100
- Any **Microlink Function** will receive the following parameters:
175
+ - `page.title()` document title.
176
+ - `page.$eval()` — run a function on the first matching element.
177
+ - `page.$$eval()` — run a function on all matching elements.
178
+ - `page.url()` — current URL.
179
+ - `page.content()` — full page HTML.
101
180
 
102
- - `html`: When [meta](https://microlink.io/docs/api/parameters/meta) is enabled, the HTML markup of the website is provided.
103
- - `page`: The [`puppeteer#page`](https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#class-page) instance to interact with the headless browser.
104
- - `response`: The [`puppeteer#response`](https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#class-httpresponse) as result of the implicit [`page.goto`](https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagegotourl-options).
181
+ Any [Puppeteer Page method](https://pptr.dev/api/puppeteer.page) is available.
105
182
 
106
- #### NPM packages
183
+ ### What your function receives
107
184
 
108
- Additionally, you can require a allowed list of common NPM packages inside your code blocks:
185
+ | Property | Description |
186
+ | --- | --- |
187
+ | `page` | Full Puppeteer access. Microlink navigates to the URL before calling your function. |
188
+ | `response` | The HTTP response from the implicit navigation. Only available when the function uses `page`. |
189
+ | `headers` | Request headers used to fetch the target URL. |
190
+ | any extra parameter | Custom inputs forwarded from the request options. |
191
+
192
+ ### Click, wait, and navigate
193
+
194
+ ```js
195
+ const microlink = require('@microlink/function')
196
+
197
+ const scrapeAfterClick = ({ page }) =>
198
+ page.click('button.load-more')
199
+ .then(() => page.waitForSelector('.results'))
200
+ .then(() => page.$$eval('.results li', items =>
201
+ items.map(el => el.textContent.trim())
202
+ ))
203
+
204
+ const fn = microlink(scrapeAfterClick)
205
+
206
+ const result = await fn('https://example.com')
207
+ ```
208
+
209
+ Replace fixed waits like `page.waitForTimeout(3000)` with `page.waitForSelector()` or `page.waitForNavigation()` whenever possible.
210
+
211
+ ### Combine with other parameters
212
+
213
+ Because `function` is just another Microlink parameter, you can prepare the page before your function runs using `scripts`, `modules`, `click`, or `waitForSelector`:
109
214
 
110
215
  ```js
111
216
  const microlink = require('@microlink/function')
112
217
 
113
- const ping = microlink(({ statusCode, response }) => {
114
- const { result } = require('lodash')
115
- return result(response, statusCode ? 'status' : 'statusText')
218
+ const fn = microlink(
219
+ ({ page }) => page.evaluate('jQuery.fn.jquery'),
220
+ { meta: false }
221
+ )
222
+
223
+ const result = await fn('https://microlink.io', {
224
+ scripts: ['https://code.jquery.com/jquery-3.5.0.min.js']
116
225
  })
226
+
227
+ console.log(result.value) // jQuery version string
117
228
  ```
118
229
 
119
- The list of allowed NPM packages are:
230
+ ## Profiling and performance
120
231
 
121
- - [`path`](https://nodejs.org/api/path.html)
122
- - [`url`](https://nodejs.org/api/url.html)
123
- - [`@aws-sdk/client-s3`](https://npm.im/@aws-sdk/client-s3)
124
- - [`@metascraper`](https://npm.im/@metascraper)
125
- - [`@mozilla/readability`](https://npm.im/@mozilla/readability)
126
- - [`async`](https://npm.im/async)
127
- - [`cheerio`](https://npm.im/cheerio)
128
- - [`extract-email-address`](https://npm.im/extract-email-address)
129
- - [`got`](https://npm.im/got)
130
- - [`ioredis`](https://npm.im/ioredis)
131
- - [`jsdom`](https://npm.im/jsdom)
132
- - [`lodash`](https://npm.im/lodash)
133
- - [`metascraper`](https://npm.im/metascraper)
134
- - [`p-reflect`](https://npm.im/p-reflect)
135
- - [`p-retry`](https://npm.im/p-retry)
136
- - [`p-timeout`](https://npm.im/p-timeout)
232
+ Every function response includes profiling data:
137
233
 
138
- Do you miss any NPM modules there? open a [new issue](/issues/new) and we make it available.
234
+ ```js
235
+ const result = await fn('https://example.com')
139
236
 
140
- ### Output
237
+ console.log(result.profiling)
238
+ // {
239
+ // phases: { install: 0, build: 120, spawn: 45, run: 890, total: 1055 },
240
+ // cpu: 234,
241
+ // memory: 8,
242
+ // size: 156
243
+ // }
244
+ ```
141
245
 
142
- When a **Microlink Function** is executed, the result response object has the following interface:
246
+ | Field | Description |
247
+ | --- | --- |
248
+ | `phases.install` | Time spent installing npm dependencies (0 when none are used). |
249
+ | `phases.build` | Time spent bundling the function code. |
250
+ | `phases.spawn` | Time spent starting the isolated process. |
251
+ | `phases.run` | Time spent executing the function. |
252
+ | `phases.total` | Wall-clock time from start to finish. |
253
+ | `cpu` | Peak CPU time in milliseconds. |
254
+ | `memory` | Peak memory usage in MB. |
255
+ | `size` | Bundled code size in bytes. |
143
256
 
144
- - `isFulfilled`
145
- - `isRejected`
146
- - `value` or `reason`, depending on whether the promise fulfilled or rejected.
257
+ ### Plan limits
147
258
 
148
- ## Testing
259
+ | | Free | Pro |
260
+ | --- | --- | --- |
261
+ | Timeout | 5 seconds | Up to 28 seconds |
262
+ | Memory | 16 MB | 32 MB |
263
+ | Code size | 1024 bytes | Unlimited |
264
+ | Concurrency | 1 per IP | Unlimited |
149
265
 
150
- Check [`@microlink/local`](https://github.com/microlinkhq/local) for executing your Microlink Functions locally.
266
+ The free plan is enough to prototype workflows. For production workloads that need more time, memory, or parameters such as `headers`, `proxy`, `ttl`, or `staleTtl`, use a [pro plan](https://microlink.io/#pricing).
151
267
 
152
- ## Examples
268
+ ### Skip metadata
153
269
 
154
- Check [examples](/examples).
270
+ Most function-only workflows do not need normalized metadata. Set `meta: false` to skip it — this is usually the biggest speedup:
155
271
 
156
- ## Pricing
272
+ ```js
273
+ const fn = microlink(({ page }) => page.title(), { meta: false })
274
+ ```
157
275
 
158
- **Microlink Function** has been designed to be cheap and affordable.
276
+ If you still need the rendered markup, call `page.content()` inside the function.
159
277
 
160
- The first 50 [uncached](https://microlink.io/blog/edge-cdn/) requests of every day are **free**. If you need more, you should to buy a [pro plan](https://microlink.io/#pricing).
278
+ ### Compression
161
279
 
162
- For [authenticating](https://microlink.io/docs/api/basics/authentication) your requests, you should to provide your API key:
280
+ `@microlink/function` compresses function bodies automatically before sending them to the API. You can also compress manually via `microlink.compress()` — useful when calling MQL directly:
281
+
282
+ ```js
283
+ const compressed = await microlink.compress(({ page }) => page.title())
284
+ // 'br#...' on Node.js (brotli), 'lz#...' as fallback
285
+ ```
286
+
287
+ Supported prefixes: `lz#` (lz-string), `br#` (brotli), `gz#` (gzip).
288
+
289
+ ### Optimization checklist
290
+
291
+ 1. Set `meta: false` unless you need normalized metadata.
292
+ 2. Use `page.title()` and `page.$eval()` instead of `page.evaluate()` when possible.
293
+ 3. Replace fixed waits with `page.waitForSelector()`.
294
+ 4. Check `result.profiling.phases` to find the bottleneck.
295
+ 5. Minimize dependencies — each `require()` adds install and build time.
296
+
297
+ ## Troubleshooting
298
+
299
+ ### Error handling
300
+
301
+ When a function throws, the result comes back with `isFulfilled: false` and the error details at `result.value`:
302
+
303
+ ```js
304
+ const failing = ({ name }) => name()
305
+
306
+ const fn = microlink(failing)
307
+
308
+ const result = await fn('https://example.com', { name: 'Kiko' })
309
+
310
+ console.log(result.isFulfilled) // false
311
+ console.log(result.value.name) // 'TypeError'
312
+ console.log(result.value.message) // 'name is not a function'
313
+ ```
314
+
315
+ Non-Error throws (like `throw 'oh no'`) are normalized into a `NonError` with the thrown value as the message.
316
+
317
+ ### Resource errors
318
+
319
+ When a function exceeds its plan limits, the API returns a descriptive error:
320
+
321
+ | Error | Trigger |
322
+ | --- | --- |
323
+ | `TimeoutError` | Wall-clock time exceeded the plan limit. |
324
+ | `CpuTimeError` | CPU time exceeded the plan limit. |
325
+ | `MemoryError` | Memory usage exceeded the plan limit. |
326
+ | `CodeSizeError` | Code exceeds the 1024 bytes free plan limit. |
327
+ | `ConcurrencyError` | Too many concurrent executions for the free plan (1 per IP). |
328
+ | `OutgoingRequestError` | Cross-origin network request on the free plan. |
329
+
330
+ ### Function-specific errors
331
+
332
+ - **EINVALFUNCTION** — invalid JavaScript syntax in the function string.
333
+ - **EINVALEVAL** — the function executed but threw at runtime.
334
+
335
+ ### Debugging tips
336
+
337
+ 1. Start simple — reduce the function to `({ page }) => page.title()` to isolate the problem.
338
+ 2. Set `meta: false` unless metadata is required.
339
+ 3. Inspect `result.profiling` to see where time is spent.
340
+ 4. Keep orchestration in the outer function and DOM-only code inside `page.evaluate()`.
341
+ 5. Watch for null — DOM queries return null when the element does not exist.
342
+
343
+ See the [troubleshooting guide](https://microlink.io/docs/guides/function/troubleshooting) for detailed remediation steps.
344
+
345
+ ## Choose the lightest tool
346
+
347
+ Use `function` when the built-in parameters stop being expressive enough, not as the default for every workflow.
348
+
349
+ | If you need | Best option | Why |
350
+ | --- | --- | --- |
351
+ | Simple field extraction from the DOM | `data` | Declarative rules are shorter and easier to maintain. |
352
+ | Inject CSS or JavaScript before another workflow | `styles`, `modules`, or `scripts` | Lighter than full browser automation. |
353
+ | Click, wait, compute, reshape, or orchestrate custom logic | `function` | Puppeteer access plus any npm package. |
354
+
355
+ ## Authentication
356
+
357
+ Pass your API key via the third argument (`gotOpts`):
163
358
 
164
359
  ```js
165
360
  const microlink = require('@microlink/function')
166
361
 
167
- const code = ({ statusCode, response }) => {
168
- const { result } = require('lodash')
169
- return result(response, statusCode ? 'status' : 'statusText')
170
- }
362
+ const fn = microlink(
363
+ ({ page }) => page.title(),
364
+ {},
365
+ { headers: { 'x-api-key': process.env.MICROLINK_API_KEY } }
366
+ )
171
367
 
172
- const ping = microlink(code, { apiKey: process.env.MICROLINK_API_KEY })
368
+ const result = await fn('https://example.com')
173
369
  ```
174
370
 
371
+ See [authentication](https://microlink.io/docs/api/basics/authentication) for endpoint and quota details.
372
+
373
+ ## Examples
374
+
375
+ See [examples](/examples).
376
+
175
377
  ## API
176
378
 
177
- ### microlink(fn, [mqlOpts], [gotoOpts])
379
+ ### `microlink(fn, [mqlOpts], [gotOpts])`
178
380
 
179
- #### fn
381
+ Returns an async function `(url, [mqlOpts], [gotOpts]) => Promise<FunctionResponse>`.
180
382
 
181
- _Required_<br>
383
+ #### `fn`
384
+
385
+ _Required_
182
386
  Type: `function`
183
387
 
184
- The function that be executed inside Microlink API browser.
388
+ The function to execute remotely.
185
389
 
186
- #### mqlOpts
390
+ #### `mqlOpts`
187
391
 
188
392
  Type: `object`
189
393
 
190
- The function that be executed inside Microlink API browser.
191
-
192
- Any option passed here will bypass to [mql](https://github.com/microlinkhq/mql).
394
+ Default options forwarded to [@microlink/mql](https://github.com/microlinkhq/mql). Per-call options merge on top.
193
395
 
194
- #### gotoOpts
396
+ #### `gotOpts`
195
397
 
196
398
  Type: `object`
197
399
 
198
- Any option passed here will bypass to [browserless#goto](https://browserless.js.org/#/?id=options-5).
400
+ HTTP client options forwarded to `got` inside MQL — use this for authentication headers and other request settings.
401
+
402
+ ### Response shape
403
+
404
+ ```ts
405
+ type FunctionResponse =
406
+ | {
407
+ isFulfilled: true
408
+ value: any
409
+ profiling: FunctionProfiling
410
+ logging: Record<string, unknown>
411
+ }
412
+ | {
413
+ isFulfilled: false
414
+ value: { name: string; message: string; [key: string]: unknown }
415
+ profiling: FunctionProfiling
416
+ logging: Record<string, unknown>
417
+ }
418
+ ```
419
+
420
+ ### Static properties
421
+
422
+ - `microlink.compress(code)` — compress a function body for manual MQL usage.
423
+ - `microlink.mql` — the underlying [@microlink/mql](https://github.com/microlinkhq/mql) client.
424
+ - `microlink.version` — package version string.
199
425
 
200
426
  ## License
201
427
 
202
- **microlink-function** © [Microlink](https://microlink.io), released under the [MIT](https://github.com/microlink/microlink-function/blob/master/LICENSE.md) License.<br>
203
- Authored and maintained by [Kiko Beats](https://kikobeats.com) with help from [contributors](https://github.com/microlink/microlink-function/contributors).
428
+ **@microlink/function** © [Microlink](https://microlink.io), released under the [MIT](https://github.com/microlinkhq/function/blob/master/LICENSE.md) License.<br>
429
+ Authored and maintained by [Kiko Beats](https://kikobeats.com) with help from [contributors](https://github.com/microlinkhq/function/contributors).
204
430
 
205
431
  > [microlink.io](https://microlink.io) · GitHub [@MicrolinkHQ](https://github.com/microlinkhq) · X [@microlinkhq](https://x.com/microlinkhq)
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@microlink/function",
3
- "description": "Browser functions as Service. Interacting with browser pages, remotely.",
3
+ "description": "Write JavaScript functions and run them remotely with Microlink — Puppeteer access, npm packages, and zero infrastructure.",
4
4
  "homepage": "https://function.microlink.io",
5
- "version": "0.2.4",
5
+ "version": "0.2.6",
6
6
  "types": "src/index.d.ts",
7
7
  "exports": {
8
8
  "types": "./src/index.d.ts",
@@ -16,11 +16,12 @@
16
16
  "url": "https://github.com/Kikobeats"
17
17
  },
18
18
  "repository": {
19
+ "directory": "packages/function",
19
20
  "type": "git",
20
- "url": "git+https://github.com/microlinkhq/function.git"
21
+ "url": "git+https://github.com/microlinkhq/microlink.git"
21
22
  },
22
23
  "bugs": {
23
- "url": "https://github.com/microlinkhq/function/issues"
24
+ "url": "https://github.com/microlinkhq/microlink/issues"
24
25
  },
25
26
  "keywords": [
26
27
  "browserless",
@@ -33,32 +34,21 @@
33
34
  "serverless"
34
35
  ],
35
36
  "dependencies": {
36
- "@microlink/mql": "~0.16.0",
37
+ "@microlink/mql": "0.17.0",
37
38
  "lz-ts": "~1.1.2"
38
39
  },
39
40
  "devDependencies": {
40
- "@commitlint/cli": "latest",
41
- "@commitlint/config-conventional": "latest",
42
- "@ksmithut/prettier-standard": "latest",
43
41
  "@rollup/plugin-commonjs": "latest",
44
42
  "@rollup/plugin-node-resolve": "latest",
45
43
  "@rollup/plugin-replace": "latest",
46
44
  "@rollup/plugin-terser": "latest",
47
45
  "async-listen": "latest",
48
46
  "ava": "latest",
49
- "c8": "latest",
50
- "ci-publish": "latest",
47
+ "cheerio": "latest",
51
48
  "execa": "latest",
52
- "git-authors-cli": "latest",
53
- "github-generate-release": "latest",
54
- "nano-staged": "latest",
55
- "prettier-standard": "latest",
56
49
  "puppeteer-core": "latest",
57
50
  "rollup": "latest",
58
51
  "rollup-plugin-filesize": "latest",
59
- "simple-git-hooks": "latest",
60
- "standard": "latest",
61
- "standard-version": "latest",
62
52
  "tinyspawn": "latest",
63
53
  "tsd": "latest"
64
54
  },
@@ -70,52 +60,18 @@
70
60
  ],
71
61
  "scripts": {
72
62
  "build": "rollup -c rollup.config.js --bundleConfigAsCjs",
73
- "clean": "rm -rf node_modules",
74
63
  "clean:build": "rm -rf dist/index.js",
75
- "contributors": "(npx git-authors-cli && npx finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
76
- "dev": "npm run build -- -w",
77
- "lint": "standard && tsd",
78
- "postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)",
79
- "prebuild": "npm run clean:build",
80
- "prepublishOnly": "npm run build",
81
- "pretest": "npm run lint && npm run build",
82
- "release": "standard-version -a",
83
- "release:github": "github-generate-release",
84
- "release:tags": "git push --follow-tags origin HEAD:master",
85
- "test": "c8 ava --verbose"
64
+ "dev": "pnpm run build -- -w",
65
+ "lint": "tsd",
66
+ "prebuild": "pnpm run clean:build",
67
+ "prepublishOnly": "pnpm run build",
68
+ "pretest": "pnpm run lint && pnpm run build",
69
+ "test": "ava --verbose"
86
70
  },
87
71
  "license": "MIT",
88
72
  "ava": {
89
73
  "timeout": "1m"
90
74
  },
91
- "commitlint": {
92
- "extends": [
93
- "@commitlint/config-conventional"
94
- ],
95
- "rules": {
96
- "body-max-line-length": [
97
- 0
98
- ]
99
- }
100
- },
101
- "nano-staged": {
102
- "*.js": [
103
- "prettier-standard",
104
- "standard --fix"
105
- ],
106
- "package.json": [
107
- "finepack"
108
- ]
109
- },
110
- "simple-git-hooks": {
111
- "commit-msg": "npx commitlint --edit",
112
- "pre-commit": "npx nano-staged"
113
- },
114
- "standard": {
115
- "ignore": [
116
- "dist"
117
- ]
118
- },
119
75
  "tsd": {
120
76
  "compilerOptions": {
121
77
  "baseUrl": ".",
@@ -126,5 +82,6 @@
126
82
  }
127
83
  },
128
84
  "directory": "test"
129
- }
85
+ },
86
+ "gitHead": "b28aa7d6434ac1bb43b084d7e329efec97dab36a"
130
87
  }
package/src/index.d.ts CHANGED
@@ -1,24 +1,44 @@
1
1
  import { MqlOptions } from '@microlink/mql'
2
2
  import { Page, HTTPResponse } from 'puppeteer-core'
3
3
 
4
- export type FunctionResponse = {
5
- isFulfilled: true,
6
- isRejected: false,
4
+ export type FunctionProfiling = {
5
+ phases?: {
6
+ install?: number
7
+ build?: number
8
+ spawn?: number
9
+ run?: number
10
+ total?: number
11
+ }
12
+ cpu?: number
13
+ memory?: number
14
+ size?: number
15
+ }
16
+
17
+ export type FunctionFulfilled = {
18
+ isFulfilled: true
7
19
  value: any
20
+ profiling: FunctionProfiling
21
+ logging: Record<string, unknown>
8
22
  }
9
23
 
10
- export type FunctionArgs = {
11
- page: object;
12
- response: object;
13
- url: string;
24
+ export type FunctionRejected = {
25
+ isFulfilled: false
26
+ value: {
27
+ name: string
28
+ message: string
29
+ [key: string]: unknown
30
+ }
31
+ profiling: FunctionProfiling
32
+ logging: Record<string, unknown>
14
33
  }
15
34
 
16
- export type FunctionInput = (args: {
17
- page: Page;
18
- response: HTTPResponse;
19
- [key: string]: any;
20
- }) => any;
35
+ export type FunctionResponse = FunctionFulfilled | FunctionRejected
21
36
 
37
+ export type FunctionInput = (args: {
38
+ page: Page
39
+ response: HTTPResponse
40
+ [key: string]: any
41
+ }) => any
22
42
 
23
43
  declare function microlinkFunction(
24
44
  fn: FunctionInput,
@@ -28,6 +48,12 @@ declare function microlinkFunction(
28
48
  url: string,
29
49
  mqlOpts?: MqlOptions,
30
50
  gotOpts?: object
31
- ) => Promise<FunctionResponse>;
51
+ ) => Promise<FunctionResponse>
52
+
53
+ declare namespace microlinkFunction {
54
+ function compress(code: FunctionInput | string): Promise<string>
55
+ const mql: typeof import('@microlink/mql').default
56
+ const version: string
57
+ }
32
58
 
33
- export default microlinkFunction;
59
+ export default microlinkFunction