@mark1russell7/market-sources 0.0.0-bootstrap.0 → 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/LICENSE +21 -0
- package/README.md +147 -1
- package/build/index.d.ts +243 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +1123 -0
- package/build/index.js.map +1 -0
- package/package.json +60 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mark Russell
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,149 @@
|
|
|
1
1
|
# @mark1russell7/market-sources
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The adapters of the sellers of a market. Each parser reads the answer of an official API at one instant. It gives the current offers and their price readings as records of [`@mark1russell7/market`](../market/README.md).
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pnpm add @mark1russell7/market-sources
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
A parser is a pure function. It sends no request, it keeps no store, and it reads no key.
|
|
10
|
+
|
|
11
|
+
A client sends the requests of one API, and gives the result of a parser. Its host gives the transport, the keys and the clock. The scheduler of [`polite-crawler`](https://www.npmjs.com/package/polite-crawler) keeps the pace of each host.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { parseEbayItem, EBAY_TERMS } from "@mark1russell7/market-sources";
|
|
17
|
+
import { isKept } from "@mark1russell7/market";
|
|
18
|
+
|
|
19
|
+
const at = new Date().toISOString();
|
|
20
|
+
const result = parseEbayItem(await answer.json(), at);
|
|
21
|
+
if (!result.ok) throw new Error(result.problems.join(" "));
|
|
22
|
+
for (const { offer, reading } of result.observations) {
|
|
23
|
+
console.log(offer.title, reading.price, isKept(EBAY_TERMS, reading, at));
|
|
24
|
+
}
|
|
25
|
+
for (const note of result.notes) console.warn(note);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## The parsers
|
|
29
|
+
|
|
30
|
+
| Parser | The answer that it reads |
|
|
31
|
+
| --- | --- |
|
|
32
|
+
| `parseEbayItem` | `getItem` of the eBay Browse API: `GET /buy/browse/v1/item/{item_id}` |
|
|
33
|
+
| `parseEbaySearch` | `search` of the eBay Browse API: `GET /buy/browse/v1/item_summary/search` |
|
|
34
|
+
| `parseBestBuyProduct` | one product of the Best Buy Products API: `GET /v1/products/{sku}.json` |
|
|
35
|
+
| `parseBestBuyProducts` | a search of the Best Buy Products API: `GET /v1/products(...)?format=json` |
|
|
36
|
+
| `parseBestBuyOpenBox` | the Best Buy Open Box API: `GET /beta/products/{sku}/openBox` |
|
|
37
|
+
| `parseDigiKeyProductDetails` | `ProductDetails` of the Digi-Key Product Information API v4 |
|
|
38
|
+
| `parseDigiKeyKeywordSearch` | `KeywordSearch` of the Digi-Key Product Information API v4 |
|
|
39
|
+
|
|
40
|
+
Each parser takes the JSON of the answer and the instant `at` of the answer. It gives one of two results:
|
|
41
|
+
|
|
42
|
+
- `{ ok: true, observations, notes }`. The answer has the documented shape. Each observation is an offer and its reading, and the schemas of `@mark1russell7/market` accept both. Each note tells why the parser skipped a record or a field.
|
|
43
|
+
- `{ ok: false, problems }`. The answer does not have the documented shape, for example the error body of an API.
|
|
44
|
+
|
|
45
|
+
A parser throws a `RangeError` only when `at` is not an ISO 8601 instant in UTC. It does not throw on the answer, for any JSON value.
|
|
46
|
+
|
|
47
|
+
## The rules of the parsers
|
|
48
|
+
|
|
49
|
+
- **Money.** A price is an exact decimal. A text, for example `"129.99"`, must have digits, and a point and digits as an option. The parser refuses an exponent, a sign and a space. The currency must be a money unit of [`@mark1russell7/quantity`](https://www.npmjs.com/package/@mark1russell7/quantity). At this time, that unit is `USD` only.
|
|
50
|
+
- **Absent values.** The parsers accept `null`, an empty text and a missing key as an absent value.
|
|
51
|
+
- **List prices.** A reading has a list price only when the list price is more than the price, in the same currency.
|
|
52
|
+
- **Repeated offers.** An offer that an answer repeats counts once.
|
|
53
|
+
- **The records are final.** Each observation goes through `offerSchema` and `priceReadingSchema`. A record that a schema refuses becomes a note, and the parser skips it.
|
|
54
|
+
|
|
55
|
+
### eBay
|
|
56
|
+
|
|
57
|
+
| Field | Rule |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| Format | With `FIXED_PRICE` in `buyingOptions`, the offer is `fixed-price`, because a buyer can pay the price at once. With `AUCTION` only, the offer is an `auction`, and its price is `currentBidPrice`. With no buying options, the offer is `fixed-price`, the default of search. Other options give a note. |
|
|
60
|
+
| Condition | The condition id of eBay maps to a condition, for example `3000` gives `used`. The text of eBay is the `grade`. |
|
|
61
|
+
| Shipping | The cheapest `FIXED` option. A cost of 0 is `free`. With no fixed option, a `CALCULATED` option gives `calculated`. Else the shipping is `unknown`. |
|
|
62
|
+
| Stock | `IN_STOCK`, `LIMITED_STOCK` and `OUT_OF_STOCK` give `in-stock`, `low-stock` and `out-of-stock`. The count is the estimated quantity, but not with the threshold `MORE_THAN`. A count that does not agree with the status gives a note. |
|
|
63
|
+
| Ended listings | A listing that ended at or before `at` gives a note, and no observation. The terms delete it. |
|
|
64
|
+
| Identifiers | A valid GTIN, the brand and the MPN. The placeholder `Does not apply` gives no identifier. |
|
|
65
|
+
|
|
66
|
+
A search answer has no GTIN, no part number, no aspects and no stock. A `getItem` call gives them.
|
|
67
|
+
|
|
68
|
+
### Best Buy
|
|
69
|
+
|
|
70
|
+
| Field | Rule |
|
|
71
|
+
| --- | --- |
|
|
72
|
+
| Price | `salePrice`. The list price is `regularPrice` when it is more. The field `onSale` is not used, because it can be `true` with equal prices. |
|
|
73
|
+
| Shipping | `freeShipping` gives `free`. A `shippingCost` above 0, as a number or a text, gives `fixed`. Else the shipping is `unknown`. |
|
|
74
|
+
| Stock | `onlineAvailability: false` or `active: false` gives `out-of-stock`. `orderable: "Available"` gives `in-stock`. Other values give `unknown`. |
|
|
75
|
+
| Open box | Each open-box offer of a SKU is its own offer, with the source id `{sku}/open-box/{listingId}`, the condition `open-box` and the grade of Best Buy. |
|
|
76
|
+
|
|
77
|
+
The US APIs of Best Buy give each price in US dollars.
|
|
78
|
+
|
|
79
|
+
### Digi-Key
|
|
80
|
+
|
|
81
|
+
| Field | Rule |
|
|
82
|
+
| --- | --- |
|
|
83
|
+
| Offers | Each variation of a product (a package type) is one offer. Its source id is the Digi-Key product number. |
|
|
84
|
+
| Seller | `Digi-Key`, or the supplier of a marketplace variation. |
|
|
85
|
+
| Price breaks | The minimum is the larger of `MinimumOrderQuantity` and the lowest break. The price is the price of the largest break at or below the minimum. The breaks above the minimum are the `priceBreaks` of the reading. |
|
|
86
|
+
| Stock | `QuantityAvailableforPackageType`: above 0 gives `in-stock`, and 0 gives `out-of-stock`. |
|
|
87
|
+
| Currency | The currency is `SearchLocaleUsed.Currency`. An answer with no currency gives a problem. |
|
|
88
|
+
|
|
89
|
+
The API has no GTIN and no shipping cost. The shipping of a reading is `unknown`.
|
|
90
|
+
|
|
91
|
+
## The clients
|
|
92
|
+
|
|
93
|
+
| Client | Methods | Pace | Access |
|
|
94
|
+
| --- | --- | --- | --- |
|
|
95
|
+
| `createDigiKeyClient` | `productDetails(productNumber)`, `keywordSearch(keywords, limit)` | 500 ms | OAuth 2.0 client credentials, the client id in a header |
|
|
96
|
+
| `createEbayClient` | `item(itemId)`, `search(words, limit)` | 1 s | OAuth 2.0 client credentials with Basic, the scope `api_scope` |
|
|
97
|
+
| `createBestBuyClient` | `product(sku)`, `search(words, pageSize)`, `openBox(sku)` | 1 s | the API key in the query |
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import { HostScheduler, realClock } from "polite-crawler/politeness";
|
|
101
|
+
import { createDigiKeyClient, type Transport } from "@mark1russell7/market-sources";
|
|
102
|
+
|
|
103
|
+
const transport: Transport<AbortSignal> = async (exchange, signal) => {
|
|
104
|
+
const answer = await fetch(exchange.url, { ...exchange, redirect: "manual", signal });
|
|
105
|
+
return { status: answer.status, statusText: answer.statusText, headers: Object.fromEntries(answer.headers), body: await answer.text() };
|
|
106
|
+
};
|
|
107
|
+
const pace = { scheduler: new HostScheduler(realClock, 4), now: realClock.now };
|
|
108
|
+
const digiKey = createDigiKeyClient({ clientId, clientSecret, transport, pace });
|
|
109
|
+
const result = await digiKey.productDetails("P5555-ND");
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
The package uses no type of a platform. Thus the host gives each port:
|
|
113
|
+
|
|
114
|
+
- **The transport** sends one exchange: a method, a URL, headers with lowercase names, and a body. It gives the status, the headers and the body of the answer. It does not follow a redirect.
|
|
115
|
+
- **The pace** is a `HostScheduler` of `polite-crawler` and its clock. Give one pace to the clients of one process, thus each host keeps one pace.
|
|
116
|
+
- **The eBay client** also takes a `base64` function for the Basic header.
|
|
117
|
+
|
|
118
|
+
### The rules of the clients
|
|
119
|
+
|
|
120
|
+
- **Pace.** Before each request, the scheduler waits the rest of its host. After each answer, the host rests for the pace of the table, or for a longer `Retry-After`.
|
|
121
|
+
- **Answers to wait.** A 429, 502, 503 or 504 parks the host for its `Retry-After`, or for a backoff with jitter. A `Retry-After` above 1 hour stops the host.
|
|
122
|
+
- **Stops.** A 401 or a 403 stops the host for 1 hour. A 402 and a bot challenge stop it for 24 hours. A request to a stopped host throws an `ApiError` of `polite-crawler/api`.
|
|
123
|
+
- **Failures.** An error 5xx and a request with no answer are failures. After 5 failures in sequence, the host stops for 1 hour.
|
|
124
|
+
- **Tokens.** A client keeps its token until 1 minute before its end. After a 401, it gets a new token and sends the request one more time.
|
|
125
|
+
- **Answers.** An answer that is not a 2xx gives `{ ok: false, problems }` with its status line. The problem has no part of the body.
|
|
126
|
+
- **Secrets.** No message of a client has a key, a secret or a token. The text `[secret]` is in the place of each one, also in its URL form, its form-body form and its Basic form. `redact` uses `redactSecrets` of `@mark1russell7/text`.
|
|
127
|
+
- **Inputs.** A client refuses a bad key, a bad product number, a bad SKU and a limit out of range with a `RangeError`, before a request.
|
|
128
|
+
|
|
129
|
+
The clients send each request with `send` of `polite-crawler/api`. It has the scheduler, the classifier and the reaction of the crawler to an answer, with no page store. The entry also gives the token store and the grant. The clients do not use the `Crawler`. The crawler keeps a copy of each page, and the terms of Digi-Key permit no store. The crawler also sends only `GET`, and a token request is a `POST`.
|
|
130
|
+
|
|
131
|
+
## The terms of each source
|
|
132
|
+
|
|
133
|
+
Each source has its terms as a `SourceTerms` record of `@mark1russell7/market`, from the hand crawl ([`docs/HAND-CRAWL.md`](../../docs/HAND-CRAWL.md)). A store examines a reading with `isKept` before it keeps or shows the reading.
|
|
134
|
+
|
|
135
|
+
| Source | Terms | Retention | Ended offers | Model of prices |
|
|
136
|
+
| --- | --- | --- | --- | --- |
|
|
137
|
+
| `ebay` | `EBAY_TERMS` | 6 hours | deleted | no |
|
|
138
|
+
| `bestbuy` | `BEST_BUY_TERMS` | 72 hours | kept until the limit | no |
|
|
139
|
+
| `digikey` | `DIGIKEY_TERMS` | no store | not applicable | no |
|
|
140
|
+
|
|
141
|
+
`SOURCE_TERMS` has the three records.
|
|
142
|
+
|
|
143
|
+
## Tests
|
|
144
|
+
|
|
145
|
+
- Each parser has a test of the documented answer of its API, and tests of each rule above.
|
|
146
|
+
- Property tests with `fast-check` mutate each documented answer: they delete fields, and put edge values and random JSON in their place. Each result has only valid records, and each reading belongs to its offer.
|
|
147
|
+
- A property test gives each parser random JSON values. No parser throws.
|
|
148
|
+
- The tests of the clients use a fake transport and a real scheduler of `polite-crawler` on a fake clock. They hold each rule of the clients: the pace, the waits, the stops, the tokens and the secrets. `polite-crawler/api` has the tests of the send and of the token store.
|
|
149
|
+
- A property test puts a random secret in random texts. No text that `redact` gives has the secret.
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The adapters of the sellers of a market. Each parser reads the answer of an official API at one instant, and
|
|
3
|
+
* gives the current offers and price readings as records of `@mark1russell7/market`. A parser keeps no store,
|
|
4
|
+
* and it sends no request. Each source also has the terms of its API.
|
|
5
|
+
*
|
|
6
|
+
* Each client sends the requests of one API through a transport that its host gives. The scheduler of
|
|
7
|
+
* `polite-crawler/api` keeps the pace of each host. A client keeps no store, and no message of a client has a key.
|
|
8
|
+
*/
|
|
9
|
+
import { Condition, Observation, SourceTerms } from "@mark1russell7/market";
|
|
10
|
+
import { ApiError, ApiScheduler, Exchange, Pace, Reply, Signal, Transport } from "polite-crawler/api";
|
|
11
|
+
import "@mark1russell7/quantity";
|
|
12
|
+
/**
|
|
13
|
+
* The result of a parser. With `ok`, the answer has the documented shape. Each observation is valid under the
|
|
14
|
+
* schemas of `@mark1russell7/market`, and each note tells why the parser skipped a record or a field. Without
|
|
15
|
+
* `ok`, the answer does not have the documented shape, and `problems` tells why.
|
|
16
|
+
*/
|
|
17
|
+
type ParseResult = {
|
|
18
|
+
readonly ok: true;
|
|
19
|
+
readonly observations: readonly Observation[];
|
|
20
|
+
readonly notes: readonly string[];
|
|
21
|
+
} | {
|
|
22
|
+
readonly ok: false;
|
|
23
|
+
readonly problems: readonly string[];
|
|
24
|
+
};
|
|
25
|
+
/** The name of the Best Buy Products API and Open Box API as a source of offers. */
|
|
26
|
+
export declare const BEST_BUY_SOURCE = "bestbuy";
|
|
27
|
+
/**
|
|
28
|
+
* The terms of the Best Buy APIs: a cache keeps the content for 72 hours at most, and nothing analyzes the prices
|
|
29
|
+
* of Best Buy for a third party.
|
|
30
|
+
*/
|
|
31
|
+
export declare const BEST_BUY_TERMS: SourceTerms;
|
|
32
|
+
/**
|
|
33
|
+
* This function gives the condition of a product of the Best Buy Products API. The text `New` gives `new`, a
|
|
34
|
+
* text with `refurbished` gives `refurbished`, and a pre-owned product gives `used`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function bestBuyCondition(condition: unknown, preowned: unknown): Condition;
|
|
37
|
+
/**
|
|
38
|
+
* This function reads the answer of one product of the Best Buy Products API (`GET /v1/products/{sku}.json`) at
|
|
39
|
+
* the instant `at`.
|
|
40
|
+
*
|
|
41
|
+
* @throws RangeError when `at` is not an instant in UTC in the ISO 8601 form.
|
|
42
|
+
*/
|
|
43
|
+
export declare function parseBestBuyProduct(answer: unknown, at: string): ParseResult;
|
|
44
|
+
/**
|
|
45
|
+
* This function reads the answer of a search of the Best Buy Products API (`GET /v1/products(...)?format=json`)
|
|
46
|
+
* at the instant `at`. The answer has its products in the list `products`, in the page form and in the cursor form.
|
|
47
|
+
*
|
|
48
|
+
* @throws RangeError when `at` is not an instant in UTC in the ISO 8601 form.
|
|
49
|
+
*/
|
|
50
|
+
export declare function parseBestBuyProducts(answer: unknown, at: string): ParseResult;
|
|
51
|
+
/**
|
|
52
|
+
* This function reads the answer of the Best Buy Open Box API (`GET /beta/products/{sku}/openBox`, or a search of
|
|
53
|
+
* `/beta/products/openBox(...)`) at the instant `at`. Each open-box offer of a SKU gives one observation, with the
|
|
54
|
+
* source id `{sku}/open-box/{listingId}`.
|
|
55
|
+
*
|
|
56
|
+
* @throws RangeError when `at` is not an instant in UTC in the ISO 8601 form.
|
|
57
|
+
*/
|
|
58
|
+
export declare function parseBestBuyOpenBox(answer: unknown, at: string): ParseResult;
|
|
59
|
+
/** The name of the Digi-Key Product Information API v4 as a source of offers. */
|
|
60
|
+
export declare const DIGIKEY_SOURCE = "digikey";
|
|
61
|
+
/** The name of the seller of an offer that Digi-Key ships itself. */
|
|
62
|
+
export declare const DIGIKEY_SELLER = "Digi-Key";
|
|
63
|
+
/**
|
|
64
|
+
* The terms of the Digi-Key Product Information API: nothing makes or updates a database of its data. Thus a
|
|
65
|
+
* reading serves one request, and no store keeps it.
|
|
66
|
+
*/
|
|
67
|
+
export declare const DIGIKEY_TERMS: SourceTerms;
|
|
68
|
+
/**
|
|
69
|
+
* This function reads the answer of `ProductDetails` of the Digi-Key Product Information API v4
|
|
70
|
+
* (`GET /products/v4/search/{productNumber}/productdetails`) at the instant `at`. Each variation of the
|
|
71
|
+
* product (a package type) gives one observation. The currency comes from `SearchLocaleUsed.Currency`.
|
|
72
|
+
*
|
|
73
|
+
* @throws RangeError when `at` is not an instant in UTC in the ISO 8601 form.
|
|
74
|
+
*/
|
|
75
|
+
export declare function parseDigiKeyProductDetails(answer: unknown, at: string): ParseResult;
|
|
76
|
+
/**
|
|
77
|
+
* This function reads the answer of `KeywordSearch` of the Digi-Key Product Information API v4
|
|
78
|
+
* (`POST /products/v4/search/keyword`) at the instant `at`. It reads the lists `Products` and `ExactMatches`,
|
|
79
|
+
* and an offer in both lists counts once.
|
|
80
|
+
*
|
|
81
|
+
* @throws RangeError when `at` is not an instant in UTC in the ISO 8601 form.
|
|
82
|
+
*/
|
|
83
|
+
export declare function parseDigiKeyKeywordSearch(answer: unknown, at: string): ParseResult;
|
|
84
|
+
/** The name of the eBay Browse API as a source of offers. */
|
|
85
|
+
export declare const EBAY_SOURCE = "ebay";
|
|
86
|
+
/**
|
|
87
|
+
* The terms of the eBay Browse API. A display shows no data older than 6 hours. An application deletes the data of
|
|
88
|
+
* an ended listing, and nothing models the prices of eBay.
|
|
89
|
+
*/
|
|
90
|
+
export declare const EBAY_TERMS: SourceTerms;
|
|
91
|
+
/**
|
|
92
|
+
* This function gives the condition of an eBay condition id, for example `3000` gives `used`. An id that the
|
|
93
|
+
* table of eBay does not have gives `unknown`.
|
|
94
|
+
*/
|
|
95
|
+
export declare function ebayCondition(conditionId: unknown): Condition;
|
|
96
|
+
/**
|
|
97
|
+
* This function reads the answer of `getItem` of the eBay Browse API (`GET /buy/browse/v1/item/{item_id}`)
|
|
98
|
+
* at the instant `at`. It gives one observation, or a note when the item does not map to an offer.
|
|
99
|
+
*
|
|
100
|
+
* @throws RangeError when `at` is not an instant in UTC in the ISO 8601 form.
|
|
101
|
+
*/
|
|
102
|
+
export declare function parseEbayItem(answer: unknown, at: string): ParseResult;
|
|
103
|
+
/**
|
|
104
|
+
* This function reads the answer of `search` of the eBay Browse API (`GET /buy/browse/v1/item_summary/search`)
|
|
105
|
+
* at the instant `at`. An answer with no results has the `total` 0 and no `itemSummaries`, and it gives no
|
|
106
|
+
* observations.
|
|
107
|
+
*
|
|
108
|
+
* @throws RangeError when `at` is not an instant in UTC in the ISO 8601 form.
|
|
109
|
+
*/
|
|
110
|
+
export declare function parseEbaySearch(answer: unknown, at: string): ParseResult;
|
|
111
|
+
/** The text in the place of a secret in a message. */
|
|
112
|
+
export declare const SECRET_MARK = "[secret]";
|
|
113
|
+
/**
|
|
114
|
+
* This function puts `SECRET_MARK` in the place of each secret and of its forms in a URL and in a form body.
|
|
115
|
+
* It uses `redactSecrets` of `@mark1russell7/text`. Then it cuts the text to `MESSAGE_LIMIT`. Each client gives
|
|
116
|
+
* it to the send as its `redact`.
|
|
117
|
+
*/
|
|
118
|
+
export declare function redact(text: string, secrets: readonly string[]): string;
|
|
119
|
+
/** The host of the Digi-Key APIs. */
|
|
120
|
+
export declare const DIGIKEY_HOST = "api.digikey.com";
|
|
121
|
+
/** The host of the sandbox of the Digi-Key APIs. Its answers have example data. */
|
|
122
|
+
export declare const DIGIKEY_SANDBOX_HOST = "sandbox-api.digikey.com";
|
|
123
|
+
/** The burst limit of Product Information v4 is 120 requests each minute. Thus the client sends one request each 500 ms at most. */
|
|
124
|
+
export declare const DIGIKEY_PACE_MS = 500;
|
|
125
|
+
/** The most products of one `KeywordSearch`. */
|
|
126
|
+
export declare const DIGIKEY_SEARCH_LIMIT = 50;
|
|
127
|
+
/** The locale of the answers: the site, the language and the currency of the prices. */
|
|
128
|
+
interface DigiKeyLocale {
|
|
129
|
+
readonly site: string;
|
|
130
|
+
readonly language: string;
|
|
131
|
+
readonly currency: string;
|
|
132
|
+
}
|
|
133
|
+
/** The locale of the US site, with prices in US dollars. */
|
|
134
|
+
export declare const DIGIKEY_US: DigiKeyLocale;
|
|
135
|
+
/** The options of a Digi-Key client. */
|
|
136
|
+
interface DigiKeyClientOptions<S extends Signal> {
|
|
137
|
+
/** The client id of the API application. */
|
|
138
|
+
readonly clientId: string;
|
|
139
|
+
/** The client secret of the API application. */
|
|
140
|
+
readonly clientSecret: string;
|
|
141
|
+
readonly transport: Transport<S>;
|
|
142
|
+
readonly pace: Pace<S>;
|
|
143
|
+
/** With true, the client uses the sandbox host. */
|
|
144
|
+
readonly sandbox?: boolean | undefined;
|
|
145
|
+
/** The default is `DIGIKEY_US`. */
|
|
146
|
+
readonly locale?: DigiKeyLocale | undefined;
|
|
147
|
+
}
|
|
148
|
+
/** A client of the Digi-Key Product Information API v4. Each method gives the result of a parser of this package. */
|
|
149
|
+
interface DigiKeyClient<S extends Signal> {
|
|
150
|
+
/** This method reads `ProductDetails` of a Digi-Key or maker product number. */
|
|
151
|
+
productDetails(productNumber: string, signal?: S): Promise<ParseResult>;
|
|
152
|
+
/** This method reads `KeywordSearch` of the keywords, with `limit` products at most (1 to 50, the default 10). */
|
|
153
|
+
keywordSearch(keywords: string, limit?: number, signal?: S): Promise<ParseResult>;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* This function makes a client of the Digi-Key Product Information API v4. The client gets a token with the
|
|
157
|
+
* 2-legged OAuth flow (the client credentials grant), and it keeps the token until 1 minute before its end. Each
|
|
158
|
+
* request sends the token, the client id and the locale.
|
|
159
|
+
*
|
|
160
|
+
* @throws RangeError when the client id or the client secret is not a key. The message does not show the value.
|
|
161
|
+
*/
|
|
162
|
+
export declare function createDigiKeyClient<S extends Signal>(options: DigiKeyClientOptions<S>): DigiKeyClient<S>;
|
|
163
|
+
/** The host of the eBay APIs. */
|
|
164
|
+
export declare const EBAY_HOST = "api.ebay.com";
|
|
165
|
+
/** The host of the sandbox of the eBay APIs. */
|
|
166
|
+
export declare const EBAY_SANDBOX_HOST = "api.sandbox.ebay.com";
|
|
167
|
+
/** The scope of an application token for the Browse API. */
|
|
168
|
+
export declare const EBAY_SCOPE = "https://api.ebay.com/oauth/api_scope";
|
|
169
|
+
/**
|
|
170
|
+
* The client sends one request each second at most: the API interval of the policy of `polite-crawler`. The
|
|
171
|
+
* Browse API documents a count of calls each day, but no pace.
|
|
172
|
+
*/
|
|
173
|
+
export declare const EBAY_PACE_MS = 1e3;
|
|
174
|
+
/** The most items of one page of `search`. */
|
|
175
|
+
export declare const EBAY_SEARCH_LIMIT = 200;
|
|
176
|
+
/** The marketplace of the US. */
|
|
177
|
+
export declare const EBAY_US = "EBAY_US";
|
|
178
|
+
/** The options of an eBay client. */
|
|
179
|
+
interface EbayClientOptions<S extends Signal> {
|
|
180
|
+
/** The client id (the App ID) of the application. */
|
|
181
|
+
readonly clientId: string;
|
|
182
|
+
/** The client secret (the Cert ID) of the application. */
|
|
183
|
+
readonly clientSecret: string;
|
|
184
|
+
/** This function encodes a text in UTF-8, and gives its Base64 form. The host gives it, for example with `Buffer`. */
|
|
185
|
+
readonly base64: (text: string) => string;
|
|
186
|
+
readonly transport: Transport<S>;
|
|
187
|
+
readonly pace: Pace<S>;
|
|
188
|
+
/** With true, the client uses the sandbox host. */
|
|
189
|
+
readonly sandbox?: boolean | undefined;
|
|
190
|
+
/** The marketplace of the answers. The default is `EBAY_US`. */
|
|
191
|
+
readonly marketplace?: string | undefined;
|
|
192
|
+
}
|
|
193
|
+
/** A client of the eBay Browse API. Each method gives the result of a parser of this package. */
|
|
194
|
+
interface EbayClient<S extends Signal> {
|
|
195
|
+
/** This method reads `getItem` of a RESTful item id, for example `v1|110000000001|0`. */
|
|
196
|
+
item(itemId: string, signal?: S): Promise<ParseResult>;
|
|
197
|
+
/** This method reads one page of `search` of the words, with `limit` items at most (1 to 200, the default 50). */
|
|
198
|
+
search(words: string, limit?: number, signal?: S): Promise<ParseResult>;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* This function makes a client of the eBay Browse API. The client gets an application token with the client
|
|
202
|
+
* credentials grant, and it keeps the token until 1 minute before its end. Each request sends the token and the
|
|
203
|
+
* marketplace.
|
|
204
|
+
*
|
|
205
|
+
* @throws RangeError when the client id or the client secret is not a key, or the marketplace is not valid.
|
|
206
|
+
*/
|
|
207
|
+
export declare function createEbayClient<S extends Signal>(options: EbayClientOptions<S>): EbayClient<S>;
|
|
208
|
+
/** The host of the Best Buy APIs. */
|
|
209
|
+
export declare const BEST_BUY_HOST = "api.bestbuy.com";
|
|
210
|
+
/**
|
|
211
|
+
* The client sends one request each second at most: the API interval of the policy of `polite-crawler`. The
|
|
212
|
+
* documentation of Best Buy gives no pace. It answers 403 when a key passes its limit of calls.
|
|
213
|
+
*/
|
|
214
|
+
export declare const BEST_BUY_PACE_MS = 1e3;
|
|
215
|
+
/** The most products of one page of a search. */
|
|
216
|
+
export declare const BEST_BUY_PAGE_LIMIT = 100;
|
|
217
|
+
/** The options of a Best Buy client. */
|
|
218
|
+
interface BestBuyClientOptions<S extends Signal> {
|
|
219
|
+
/** The API key. It goes in the query of each request, and no message has it. */
|
|
220
|
+
readonly apiKey: string;
|
|
221
|
+
readonly transport: Transport<S>;
|
|
222
|
+
readonly pace: Pace<S>;
|
|
223
|
+
}
|
|
224
|
+
/** A client of the Best Buy Products API and Open Box API. Each method gives the result of a parser of this package. */
|
|
225
|
+
interface BestBuyClient<S extends Signal> {
|
|
226
|
+
/** This method reads one product of a SKU. */
|
|
227
|
+
product(sku: string, signal?: S): Promise<ParseResult>;
|
|
228
|
+
/** This method reads the first page of a search of the words, with `pageSize` products at most (1 to 100, the default 10). */
|
|
229
|
+
search(words: string, pageSize?: number, signal?: S): Promise<ParseResult>;
|
|
230
|
+
/** This method reads the open-box offers of a SKU. */
|
|
231
|
+
openBox(sku: string, signal?: S): Promise<ParseResult>;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* This function makes a client of the Best Buy APIs. The API key goes in the query of each request. A 401 or a
|
|
235
|
+
* 403 stops the host for 1 hour, because Best Buy gives a 403 for a key that passed its limit.
|
|
236
|
+
*
|
|
237
|
+
* @throws RangeError when the API key is not a key. The message does not show the value.
|
|
238
|
+
*/
|
|
239
|
+
export declare function createBestBuyClient<S extends Signal>(options: BestBuyClientOptions<S>): BestBuyClient<S>;
|
|
240
|
+
/** The terms of each source of this package, in the order of the hand crawl. */
|
|
241
|
+
export declare const SOURCE_TERMS: readonly SourceTerms[];
|
|
242
|
+
export { ApiError, type ApiScheduler, type BestBuyClient, type BestBuyClientOptions, type DigiKeyClient, type DigiKeyClientOptions, type DigiKeyLocale, type EbayClient, type EbayClientOptions, type Exchange, type Observation, type Pace, type ParseResult, type Reply, type Signal, type Transport };
|
|
243
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/parse.ts","../src/bestbuy.ts","../src/digikey.ts","../src/ebay.ts","../src/client.ts","../src/digikey-client.ts","../src/ebay-client.ts","../src/bestbuy-client.ts","../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;KAoBY;WACG;WAAmB,uBAAuB;WAAwB;;WAClE;WAAoB;;;qBCOtB;;;;;qBAMA,gBAAgB;;;;;wBAeb,iBAAiB,oBAAoB,oBAAoB;;;;;;;wBA0GzD,oBAAoB,iBAAiB,aAAa;;;;;;;wBAclD,qBAAqB,iBAAiB,aAAa;;;;;;;;wBAyFnD,oBAAoB,iBAAiB,aAAa;;qBC7OrD;;qBAGA;;;;;qBAMA,eAAe;;;;;;;;wBAsIZ,2BAA2B,iBAAiB,aAAa;;;;;;;;wBAiBzD,0BAA0B,iBAAiB,aAAa;;qBCnJ3D;;;;;qBAMA,YAAY;;;;;wBA+BT,cAAc,uBAAuB;;;;;;;wBAwJrC,cAAc,iBAAiB,aAAa;;;;;;;;wBAe5C,gBAAgB,iBAAiB,aAAa;;qBC3MjD;;;;;;wBAqCG,OAAO,cAAc;;qBCtDxB;;qBAGA;;qBAGA;;qBAGA;;UAGI;WACN;WACA;WACA;;;qBAIE,YAAY;;UAGR,qBAAqB,UAAU;;WAErC;;WAEA;WACA,WAAW,UAAU;WACrB,MAAM,KAAK;;WAEX;;WAEA,SAAS;;;UAIH,cAAc,UAAU;;EAEvC,eAAe,uBAAuB,SAAS,IAAI,QAAQ;;EAE3D,cAAc,kBAAkB,gBAAgB,SAAS,IAAI,QAAQ;;;;;;;;;wBAYvD,oBAAoB,UAAU,QAAQ,SAAS,qBAAqB,KAAK,cAAc;;qBCpD1F;;qBAGA;;qBAGA;;;;;qBAMA;;qBAGA;;qBAGA;;UAGI,kBAAkB,UAAU;;WAElC;;WAEA;;WAEA,SAAS;WACT,WAAW,UAAU;WACrB,MAAM,KAAK;;WAEX;;WAEA;;;UAIM,WAAW,UAAU;;EAEpC,KAAK,gBAAgB,SAAS,IAAI,QAAQ;;EAE1C,OAAO,eAAe,gBAAgB,SAAS,IAAI,QAAQ;;;;;;;;;wBAe7C,iBAAiB,UAAU,QAAQ,SAAS,kBAAkB,KAAK,WAAW;;qBCtEjF;;;;;qBAMA;;qBAGA;;UAGI,qBAAqB,UAAU;;WAErC;WACA,WAAW,UAAU;WACrB,MAAM,KAAK;;;UAIL,cAAc,UAAU;;EAEvC,QAAQ,aAAa,SAAS,IAAI,QAAQ;;EAE1C,OAAO,eAAe,mBAAmB,SAAS,IAAI,QAAQ;;EAE9D,QAAQ,aAAa,SAAS,IAAI,QAAQ;;;;;;;;wBAoB5B,oBAAoB,UAAU,QAAQ,SAAS,qBAAqB,KAAK,cAAc;;qBCI1F,uBAAuB"}
|