@apounited/mac 0.1.1
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/README.md +53 -0
- package/dist/main.js +2 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/apounited/.github/refs/heads/main/assets/apounited/icon/color.svg" alt="" width="80" height="auto">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# @apounited/mac
|
|
6
|
+
|
|
7
|
+
> MAC (Mauve API-Crawler)
|
|
8
|
+
|
|
9
|
+
Crawls and extracts data from the [Mauve API](https://api.mauve.de)
|
|
10
|
+
|
|
11
|
+
## Commands
|
|
12
|
+
|
|
13
|
+
### Crawl
|
|
14
|
+
|
|
15
|
+
The crawlers can be invoked via `bunx` or `npx` with `@apounited/mac`.
|
|
16
|
+
|
|
17
|
+
> Data is saved to `./storage` relative to the execution path.
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
bunx @apounited/mac crawl customers --username demo --password demo
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Available crawlers: `customers`, `orders`, `products`.
|
|
24
|
+
|
|
25
|
+
| Options | Short | Required | Values | Description |
|
|
26
|
+
| ---------------- | ----- | ---------- | ---------- | -------------------------------- |
|
|
27
|
+
| `--username` | `-u` | `true` | `demo` | Mauve Customer ID |
|
|
28
|
+
| `--password` | `-p` | `true` | `demo` | Mauve API Password |
|
|
29
|
+
| `--max-requests` | `-r` | `optional` | `<NUMBER>` | Maximum number of crawl requests |
|
|
30
|
+
|
|
31
|
+
### Clean
|
|
32
|
+
|
|
33
|
+
Deletes `./storage` directory relative to the execution path.
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
bunx @apounited/mac clean
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Development
|
|
40
|
+
|
|
41
|
+
Run the main CLI entry point without building:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
bun dev
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Production
|
|
48
|
+
|
|
49
|
+
Build dist files:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
bun run build
|
|
53
|
+
```
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var G=Object.defineProperty;var C=(o)=>o;function F(o,n){this[o]=C.bind(null,n)}var S=(o,n)=>{for(var t in n)G(o,t,{get:n[t],enumerable:!0,configurable:!0,set:F.bind(n,t)})};var U=(o,n)=>()=>(o&&(n=o(o=0)),n);function x({username:o,password:n}){return{auth:Buffer.from(`${o}:${n}`).toString("base64")}}function g({baseUrl:o="https://api.mauve.de",endpoint:n="/",limit:t=1000,offset:m=0}){return{id:n.split("/").filter(Boolean).join("-"),params:{limit:t,offset:m},req:function(f){let p=new URLSearchParams(f).toString();return`${o.replace(/\/$/,"")}/${n.replace(/^\//,"")}?${p}`}}}var I={};S(I,{crawler:()=>O});import{BasicCrawler as K}from"@crawlee/basic";async function O({username:o,password:n,maxRequests:t}){let{auth:m}=x({username:o,password:n}),{id:c,params:i,req:l}=g({endpoint:"/customers"}),f=new K({maxConcurrency:1,maxRequestsPerCrawl:t,async requestHandler({sendRequest:p,addRequests:y,pushData:v,log:b}){let{body:k}=await p({responseType:"json",http2:!1,headers:{Authorization:`Basic ${m}`}}),r=k.customers;if(i.offset+=r.length,i.offset&&r.length===i.limit)await y([l(i)]);await v(r),b.info(`Fetched ${r.length} ${c} (total: ${i.offset})`)}});await f.run([l(i)]),await f.exportData(`storage/data/${o.toLowerCase()}/${c}.json`)}var L=()=>{};var P={};S(P,{crawler:()=>V});import{BasicCrawler as Q}from"@crawlee/basic";async function V({username:o,password:n,maxRequests:t}){let{auth:m}=x({username:o,password:n}),{params:c,req:i}=g({endpoint:"/documents"}),l="orders",f=new Q({maxConcurrency:1,maxRequestsPerCrawl:t,async requestHandler({sendRequest:p,addRequests:y,pushData:v,log:b}){let{body:k}=await p({responseType:"json",http2:!1,headers:{Authorization:`Basic ${m}`}}),r=k.documents;if(c.offset+=r.length,c.offset&&r.length===c.limit)await y([i({...c,documentTypes:"Bestellung"})]);await v(r),b.info(`Fetched ${r.length} orders (total: ${c.offset})`)}});await f.run([i({...c,documentTypes:"Bestellung"})]),await f.exportData(`storage/data/${o.toLowerCase()}/orders.json`)}var E=()=>{};var M={};S(M,{crawler:()=>X});import{BasicCrawler as W}from"@crawlee/basic";async function X({username:o,password:n,maxRequests:t}){let{auth:m}=x({username:o,password:n}),{id:c,params:i,req:l}=g({endpoint:"/products"}),f=new W({maxConcurrency:1,maxRequestsPerCrawl:t,async requestHandler({sendRequest:p,addRequests:y,pushData:v,log:b}){let{body:k}=await p({responseType:"json",http2:!1,headers:{Authorization:`Basic ${m}`}}),r=k.products;if(i.offset+=r.length,i.offset&&r.length===i.limit)await y([l(i)]);await v(r),b.info(`Fetched ${r.length} ${c} (total: ${i.offset})`)}});await f.run([l(i)]),await f.exportData(`storage/data/${o.toLowerCase()}/${c}.json`)}var N=()=>{};var w={};S(w,{clean:()=>Z});import{rimraf as Y}from"rimraf";async function Z(){await Y("storage")}var z=()=>{};import _ from"cac";var $={name:"@apounited/mac",version:"0.1.0",license:"UNLICENSED",author:"Sergej Samsonenko",description:"Crawls and extracts data from the Mauve API.",type:"module",keywords:["mauve","api","crawler"],files:["dist"],publishConfig:{access:"public"},main:"./dist/main.js",bin:{mac:"./dist/main.js"},scripts:{build:"bun build.ts",dev:"bun src/main.ts",lint:"bunx oxlint",fmt:"bunx oxfmt",clean:"bunx rimraf storage",deps:"(bunx taze -r -w) && (bun i)",postinstall:"bunx simple-git-hooks"},dependencies:{"@crawlee/basic":"^3.16.0",cac:"^7.0.0",rimraf:"^6.1.3"},devDependencies:{"@apify/tsconfig":"^0.1.2","@types/bun":"latest","oxlint-tsgolint":"^0.22.1",typescript:"^6.0.3"},"simple-git-hooks":{"pre-commit":"bunx lint-staged","commit-msg":"bunx @apounited/verify-commit-msg $1"},"lint-staged":{"*.{js,ts}":["bunx oxlint --fix"],"*":["bunx oxfmt --no-error-on-unmatched-pattern","git add"]}};var j=_($.name);j.command("crawl <value>","Specify the crawler to run (customers, orders, products)").option("-u, --username <username>","Username for authentication").option("-p, --password <password>","Password for authentication").option("-r, --max-requests [number]","Maximum number of requests to make").example("crawl customers --username demo --password demo --max-requests 5").action(async(o,n)=>{let{username:t,password:m,maxRequests:c}=n;if(!t||!m)console.error("Error: Username and password are required."),process.exit(1);let i={customers:()=>Promise.resolve().then(() => (L(),I)),orders:()=>Promise.resolve().then(() => (E(),P)),products:()=>Promise.resolve().then(() => (N(),M))},{crawler:l}=await i[o]();await l({username:t,password:m,maxRequests:c})});j.command("clean","Delete ./storage directory and all its contents").action(async()=>{let{clean:o}=await Promise.resolve().then(() => (z(),w));await o()});j.help();j.version($.version);j.parse();
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@apounited/mac",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"license": "UNLICENSED",
|
|
5
|
+
"author": "Sergej Samsonenko",
|
|
6
|
+
"description": "Crawls and extracts data from the Mauve API.",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"mauve",
|
|
10
|
+
"api",
|
|
11
|
+
"crawler"
|
|
12
|
+
],
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"main": "./dist/main.js",
|
|
20
|
+
"bin": {
|
|
21
|
+
"mac": "./dist/main.js"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "bun build.ts",
|
|
25
|
+
"dev": "bun src/main.ts",
|
|
26
|
+
"lint": "bunx oxlint",
|
|
27
|
+
"fmt": "bunx oxfmt",
|
|
28
|
+
"clean": "bunx rimraf storage",
|
|
29
|
+
"deps": "(bunx taze -r -w) && (bun i)",
|
|
30
|
+
"postinstall": "bunx simple-git-hooks"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@crawlee/basic": "^3.16.0",
|
|
34
|
+
"cac": "^7.0.0",
|
|
35
|
+
"rimraf": "^6.1.3"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@apify/tsconfig": "^0.1.2",
|
|
39
|
+
"@types/bun": "latest",
|
|
40
|
+
"oxlint-tsgolint": "^0.22.1",
|
|
41
|
+
"typescript": "^6.0.3"
|
|
42
|
+
},
|
|
43
|
+
"simple-git-hooks": {
|
|
44
|
+
"pre-commit": "bunx lint-staged",
|
|
45
|
+
"commit-msg": "bunx @apounited/verify-commit-msg $1"
|
|
46
|
+
},
|
|
47
|
+
"lint-staged": {
|
|
48
|
+
"*.{js,ts}": [
|
|
49
|
+
"bunx oxlint --fix"
|
|
50
|
+
],
|
|
51
|
+
"*": [
|
|
52
|
+
"bunx oxfmt --no-error-on-unmatched-pattern",
|
|
53
|
+
"git add"
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
}
|