@microlink/function 0.0.0 → 0.1.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.
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright © 2021 <josefrancisco.verdu@gmail.com> ()
3
+ Copyright © 2021 Microlink <hello@microlink.io> (microlink.io)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,76 +1,185 @@
1
1
  <div align="center">
2
- <img src="https://cdn.microlink.io/logo/banner.png"">
2
+ <img src="https://cdn.microlink.io/logo/banner.png">
3
+ <br>
4
+ <br>
5
+ <br>
6
+ <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>
3
7
  </div>
4
8
 
5
- > JavaScript runtime functions made simple.
9
+ <div align="center">
10
+ <img src="https://i.imgur.com/4PWrzx2.png" width="700px">
11
+ </div>
12
+
13
+ ## Highlights
14
+
15
+ - Starts from \$0/mo.
16
+ - Run Serverless Javascript functions (also [locally](https://github.com/microlinkhq/local)).
17
+ - Ability to require to require any of the [allowed](#npm-packages) NPM packages.
18
+ - Headless Chromium browser access in the same request cycle.
19
+ - No servers to maintain, no hidden cost or infrastructure complexity.
20
+
21
+ ## Contents
22
+
23
+ - [How it works](#how-it-works)
24
+ - [Installation](#installation)
25
+ - [from NPM](#from-npm)
26
+ - [from CDN](#from-cdn)
27
+ - [Get Started](#get-started)
28
+ - [Input](#input)
29
+ - [NPM packages](#npm-packages)
30
+ - [Output](#output)
31
+ - [Examples](#examples)
32
+ - [Pricing](#pricing)
33
+ - [API](#api)
34
+ - [License](#license)
35
+
36
+ ## How it works
6
37
 
7
- ## Install
38
+ Every time you call a **Microlink Function**, the code function will be compiled and executed remotely in a safe V8 sandbox.
39
+
40
+ 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.
41
+
42
+ **Microlink Function** can be invoked in frontend or backend side. There is nothing to deploy or hidden infrastructure cost associated.
43
+
44
+ ## Installation
45
+
46
+ ### from NPM
47
+
48
+ It's available as [npm package](https://www.npmjs.com/package/@microlink/function):
8
49
 
9
50
  ```bash
10
51
  $ npm install @microlink/function --save
11
52
  ```
12
53
 
13
- ## Usage
54
+ ### from CDN
14
55
 
15
- ### Interact with the page
56
+ Load directly in the browser from your favorite CDN:
16
57
 
17
- ```js
18
- const microlinkFunction = require('@microlink/function')
58
+ ```html
59
+ <script src="https://cdn.jsdelivr.net/npm/@microlink/function/dist/microlink-function.min.js"></script>
60
+ ```
19
61
 
20
- const fn = microlinkFunction(({ page }) => page.title())
62
+ ## Get Started
21
63
 
22
- const result = await fn('https://google.com')
64
+ ### Input
23
65
 
24
- console.log(result)
25
- // {
26
- // isFulfilled: true,
27
- // isRejected: false,
28
- // value: 'Google'
29
- // }
66
+ Let say you have a JavaScript like this:
67
+
68
+ ```js
69
+ const ping = ({ statusCode, response }) =>
70
+ statusCode ? response.status() : response.statusText()
30
71
  ```
31
72
 
32
- ### Interact with the response
73
+ To run the previous code as **Microlink Function**, all you need to do is wrap the function with the `microlink` decorator:
33
74
 
34
75
  ```js
35
- const microlinkFunction = require('@microlink/function')
76
+ const microlink = require('@microlink/function')
77
+
78
+ const ping = microlink({ response }) => statusCode
79
+ ? response.status()
80
+ : response.statusText()
81
+ )
82
+ ```
36
83
 
37
- const fn = microlinkFunction(({ page }) => response.status())
84
+ Then, just call the function as you would normally:
38
85
 
39
- const result = await fn('https://google.com')
86
+ ```js
87
+ const result = await ping('https://example.com', { statusCode: true })
40
88
 
41
89
  console.log(result)
90
+
42
91
  // {
43
- // isFulfilled: true,
92
+ // isFullfilled: true,
44
93
  // isRejected: false,
45
94
  // value: 200
46
95
  // }
47
96
  ```
48
97
 
49
- ### Interact with the query
98
+ When a function is wrapped by **Microlink Function** the function execution is done remotely, giving back the result.
99
+
100
+ Any **Microlink Function** will receive the following parameters:
101
+
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).
105
+
106
+ #### NPM packages
107
+
108
+ Additionally, you can require a allowed list of common NPM packages inside your code blocks:
50
109
 
51
110
  ```js
52
- const microlinkFunction = require('@microlink/function')
111
+ const microlink = require('@microlink/function')
53
112
 
54
- const fn = microlinkFunction(({ query }) => query.greetings)
113
+ const ping = microlink(({ statusCode, response }) => {
114
+ const { result } = require('lodash')
115
+ return result(response, statusCode ? 'status' : 'statusText')
116
+ })
117
+ ```
55
118
 
56
- const result = await fn('https://google.com', { greetings: 'hello world' })
119
+ The list of allowed NPM packages are:
57
120
 
58
- console.log(result)
59
- // {
60
- // isFulfilled: true,
61
- // isRejected: false,
62
- // value: 'hello world'
63
- // }
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)
137
+
138
+ Do you miss any NPM modules there? open a [new issue](/issues/new) and we make it available.
139
+
140
+ ### Output
141
+
142
+ When a **Microlink Function** is executed, the result response object has the following interface:
143
+
144
+ - `isFulfilled`
145
+ - `isRejected`
146
+ - `value` or `reason`, depending on whether the promise fulfilled or rejected.
147
+
148
+ ## Testing
149
+
150
+ Check [`@microlink/local`](https://github.com/microlinkhq/local) for executing your Microlink Functions locally.
151
+
152
+ ## Examples
153
+
154
+ Check [examples](/examples).
155
+
156
+ ## Pricing
157
+
158
+ **Microlink Function** has been designed to be cheap and affordable.
159
+
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).
161
+
162
+ For [authenticating](https://microlink.io/docs/api/basics/authentication) your requests, you should to provide your API key:
163
+
164
+ ```js
165
+ const microlink = require('@microlink/function')
166
+
167
+ const code = ({ statusCode, response }) => {
168
+ const { result } = require('lodash')
169
+ return result(response, statusCode ? 'status' : 'statusText')
170
+ }
171
+
172
+ const ping = microlink(code, { apiKey: process.env.MICROLINK_API_KEY })
64
173
  ```
65
174
 
66
175
  ## API
67
176
 
68
- ### microlinkFunction(fn, [mqlOpts], [gotoOpts])
177
+ ### microlink(fn, [mqlOpts], [gotoOpts])
69
178
 
70
179
  #### fn
71
180
 
72
- *Required*<br>
73
- Type: `string`
181
+ _Required_<br>
182
+ Type: `function`
74
183
 
75
184
  The function that be executed inside Microlink API browser.
76
185
 
@@ -90,7 +199,7 @@ Any option passed here will bypass to [browserless#goto](https://browserless.js.
90
199
 
91
200
  ## License
92
201
 
93
- **microlink-function** © [](), released under the [MIT](https://github.com/microlink/microlink-function/blob/master/LICENSE.md) License.<br>
94
- Authored and maintained by []() with help from [contributors](https://github.com/microlink/microlink-function/contributors).
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).
95
204
 
96
- > []() · GitHub [](https://github.com/microlink) · Twitter [@microlink](https://twitter.com/microlink)
205
+ > [microlink.io](https://microlink.io) · GitHub [@MicrolinkHQ](https://github.com/microlinkhq) · Twitter [@microlinkhq](https://twitter.com/microlinkhq)