@mark1russell7/market-sources 0.3.3 → 0.3.4
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 +32 -1
- package/build/index.d.ts +105 -10
- package/build/index.d.ts.map +1 -1
- package/build/index.js +212 -3
- package/build/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -39,6 +39,7 @@ for (const note of result.notes) console.warn(note);
|
|
|
39
39
|
| `parseAzureRetailPrices` | one page of the Azure Retail Prices API: `GET /api/retail/prices` |
|
|
40
40
|
| `parseAzureRetailPricePages` | all the pages of one read of the Azure Retail Prices API |
|
|
41
41
|
| `parsePlanLists` | all the pages of the plan list of a provider record, for example `GET /v2/plans` of the Vultr API |
|
|
42
|
+
| `parseBlsSeries` | version 1 of the BLS Public Data API: `POST /publicAPI/v1/timeseries/data/` |
|
|
42
43
|
|
|
43
44
|
Each parser takes the JSON of the answer and the instant `at` of the answer. It gives one of two results:
|
|
44
45
|
|
|
@@ -140,6 +141,34 @@ A plan list is an API that gives each plan of virtual machines with its prices a
|
|
|
140
141
|
|
|
141
142
|
`parsePlanLists(provider, { plans, regions }, at)` takes the pages of the plan list. A record with regions of the kind `list` also needs the pages of that list. The field `next` of the result is always `null`, because the client reads each page before the parse.
|
|
142
143
|
|
|
144
|
+
### BLS average prices
|
|
145
|
+
|
|
146
|
+
The Consumer Price Index of the U.S. Bureau of Labor Statistics (BLS) publishes the average price of some foods each month. These are the series of the survey AP. An average price is not an offer of a seller. Thus `parseBlsSeries` gives average prices of `@mark1russell7/market`, not observations. Its result is `{ ok: true, prices, notes }` or `{ ok: false, problems }`.
|
|
147
|
+
|
|
148
|
+
The answer of version 1 gives no title of a series. Thus the parser takes the item, the area and the unit of each series from a list of known series. The default list is `BLS_STAPLES`.
|
|
149
|
+
|
|
150
|
+
| Series | Item | Area |
|
|
151
|
+
| --- | --- | --- |
|
|
152
|
+
| `APU0000701312` | Rice, white, long grain, uncooked, per lb. | U.S. city average |
|
|
153
|
+
| `APU0000701111` | Flour, white, all purpose, per lb. | U.S. city average |
|
|
154
|
+
| `APU0000714233` | Beans, dried, any type, all sizes, per lb. | U.S. city average |
|
|
155
|
+
| `APU0000715211` | Sugar, white, all sizes, per lb. | U.S. city average |
|
|
156
|
+
| `APU0000701322` | Spaghetti and macaroni, per lb. | U.S. city average |
|
|
157
|
+
|
|
158
|
+
| Field | Rule |
|
|
159
|
+
| --- | --- |
|
|
160
|
+
| Price | The value of a month, in `USD` for each unit of the item, for example `{ value: 1.101, unit: "USD/lb" }`. `valueIn(price, "USD/kg")` of `@mark1russell7/quantity` gives the price of a kilogram. |
|
|
161
|
+
| Month | The period `M01` to `M12` of a year, as `YYYY-MM`. Another period, for example the annual average `M13`, gives a note. |
|
|
162
|
+
| No value | A value that is not a decimal, for example `-`, gives a note and no price. The price stays no read. It does not become 0. |
|
|
163
|
+
| Messages | Each message of the answer gives a note, for example "No Data Available" for a year. |
|
|
164
|
+
| Footnotes | The texts of the footnotes of a value, for example `Preliminary`. |
|
|
165
|
+
| Status | An answer with a status that is not `REQUEST_SUCCEEDED` gives problems, with its messages. |
|
|
166
|
+
| Daily threshold | When a message of a failed answer names the daily threshold, the result also has `threshold: true`. Then a loop waits for the next day. The documentation of BLS does not give the shape of this answer. |
|
|
167
|
+
|
|
168
|
+
The Northeast series of these items exist, but they have no value since 2023. Thus the list has only the U.S. city average. `blsRequest(series, years)` gives the request: 25 series and 10 years at most.
|
|
169
|
+
|
|
170
|
+
The terms make two things necessary for each user of the data: the date of the retrieval, and the statement `BLS_STATEMENT`. The field `at` of each price is the instant of the read. No field of the record has the statement. The layer that shows the prices, for example a page or a printed list, shows it with the date.
|
|
171
|
+
|
|
143
172
|
## The clients
|
|
144
173
|
|
|
145
174
|
| Client | Methods | Pace | Access |
|
|
@@ -149,6 +178,7 @@ A plan list is an API that gives each plan of virtual machines with its prices a
|
|
|
149
178
|
| `createBestBuyClient` | `product(sku)`, `search(words, pageSize)`, `openBox(sku)` | 1 s | the API key in the query |
|
|
150
179
|
| `createAzureClient` | `prices(filter, { pages, currency })`, `more(next, pages)` | 6 s | no key |
|
|
151
180
|
| `createPlanClient` | `plans(provider, { pages })` | the pace of the record, 2 s for each record of the package | no key |
|
|
181
|
+
| `createBlsClient` | `averages(series, years)` | 72 min: 20 queries each day in one process, under the limit of 25 | no key (version 1) |
|
|
152
182
|
|
|
153
183
|
```ts
|
|
154
184
|
import { HostScheduler, realClock } from "polite-crawler/politeness";
|
|
@@ -198,8 +228,9 @@ Each source has its terms as a `SourceTerms` record of `@mark1russell7/market`,
|
|
|
198
228
|
| `azure` | `AZURE_TERMS` | no limit | kept | yes |
|
|
199
229
|
| `linode` | `LINODE_TERMS` | no store | not applicable | no |
|
|
200
230
|
| `vultr` | `VULTR_TERMS` | no store | not applicable | no |
|
|
231
|
+
| `bls-ap` | `BLS_TERMS` | no limit | not applicable | yes |
|
|
201
232
|
|
|
202
|
-
`SOURCE_TERMS` has the
|
|
233
|
+
`SOURCE_TERMS` has the seven records.
|
|
203
234
|
|
|
204
235
|
The terms pages of Vultr and of Akamai refused an automated read on 2026-11-18. Thus `LINODE_TERMS` and `VULTR_TERMS` have the strictest rules: no store and no model of prices. A person reads the terms before a rule changes. The Linode API reference tells that the reads of the plan list need no permissions.
|
|
205
236
|
|
package/build/index.d.ts
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
* gives the current offers and price readings as records of `@mark1russell7/market`. A parser keeps no store,
|
|
4
4
|
* and it sends no request. Each source also has the terms of its API. The Azure parser gives the metered prices
|
|
5
5
|
* of cloud resources as metered offers. The plan parser reads the plan list of each provider record as metered offers.
|
|
6
|
+
* The BLS parser reads the average prices of the Consumer Price Index as average prices of `@mark1russell7/market`.
|
|
6
7
|
*
|
|
7
8
|
* Each client sends the requests of one API through a transport that its host gives. The scheduler of
|
|
8
9
|
* `polite-crawler/api` keeps the pace of each host. A client keeps no store, and no message of a client has a key.
|
|
9
10
|
*/
|
|
10
|
-
import { Condition, MeteredObservation, Observation, PriceTerm, SourceTerms } from "@mark1russell7/market";
|
|
11
|
+
import { AveragePrice, Condition, MeteredObservation, Observation, PriceTerm, SourceTerms } from "@mark1russell7/market";
|
|
11
12
|
import "@mark1russell7/quantity";
|
|
12
13
|
import { z } from "zod";
|
|
13
14
|
import { ApiError, ApiScheduler, Exchange, Pace, Reply, Signal, Transport } from "polite-crawler/api";
|
|
@@ -98,6 +99,108 @@ export declare function parseAzureRetailPrices(answer: unknown, at: string): Met
|
|
|
98
99
|
* @throws RangeError when `at` is not an instant in UTC in the ISO 8601 form.
|
|
99
100
|
*/
|
|
100
101
|
export declare function parseAzureRetailPricePages(answers: readonly unknown[], at: string): MeteredParseResult;
|
|
102
|
+
/** The name of the source. */
|
|
103
|
+
export declare const BLS_SOURCE = "bls-ap";
|
|
104
|
+
/** The statement that the terms of the API make necessary for each user of the data. The layer that shows the prices shows it. */
|
|
105
|
+
export declare const BLS_STATEMENT = "BLS.gov cannot vouch for the data or analyses derived from these data after the data have been retrieved from BLS.gov.";
|
|
106
|
+
/** The terms of the BLS Public Data API. They set no limit on the time or the use of the data. */
|
|
107
|
+
export declare const BLS_TERMS: SourceTerms;
|
|
108
|
+
/** The address of version 1 of the BLS Public Data API, for one or more series. */
|
|
109
|
+
export declare const BLS_API_URL = "https://api.bls.gov/publicAPI/v1/timeseries/data/";
|
|
110
|
+
/** The most series of one query of version 1. */
|
|
111
|
+
export declare const BLS_SERIES_LIMIT = 25;
|
|
112
|
+
/** The most years of one query of version 1. */
|
|
113
|
+
export declare const BLS_YEAR_LIMIT = 10;
|
|
114
|
+
/** A known series of average prices: its id, its item and its area as BLS names them, and the unit of the item. */
|
|
115
|
+
interface BlsSeries {
|
|
116
|
+
readonly series: string;
|
|
117
|
+
readonly item: string;
|
|
118
|
+
readonly area: string;
|
|
119
|
+
/** The unit of the amount of the item, a unit of `@mark1russell7/quantity`, for example `lb`. */
|
|
120
|
+
readonly unit: string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The average prices of some dry staples, in the U.S. city average. The titles are from the BLS data viewer of each
|
|
124
|
+
* series, read on 2026-11-22. The series of the Northeast for these items exist, but they have no value since 2023.
|
|
125
|
+
*/
|
|
126
|
+
export declare const BLS_STAPLES: readonly BlsSeries[];
|
|
127
|
+
/**
|
|
128
|
+
* The result of the parser of average prices. With `ok`, each price is valid under `averagePriceSchema`, and each
|
|
129
|
+
* note tells why the parser skipped a value. Without `ok`, the answer does not have the documented shape.
|
|
130
|
+
*/
|
|
131
|
+
type AverageParseResult = {
|
|
132
|
+
readonly ok: true;
|
|
133
|
+
readonly prices: readonly AveragePrice[];
|
|
134
|
+
readonly notes: readonly string[];
|
|
135
|
+
} | (Refused & {
|
|
136
|
+
readonly threshold?: true | undefined;
|
|
137
|
+
});
|
|
138
|
+
/**
|
|
139
|
+
* This function gives the request of version 1 of the API for some series, from a first year to a last year. The
|
|
140
|
+
* API gives the last three years when the request has no years.
|
|
141
|
+
*
|
|
142
|
+
* @throws RangeError when the count of series is not from 1 to `BLS_SERIES_LIMIT`, or when an id is not an id of BLS.
|
|
143
|
+
* It also throws when the years are not whole numbers in order, or when they are more than `BLS_YEAR_LIMIT` years.
|
|
144
|
+
*/
|
|
145
|
+
export declare function blsRequest(series: readonly string[], years?: {
|
|
146
|
+
readonly start: number;
|
|
147
|
+
readonly end: number;
|
|
148
|
+
}): {
|
|
149
|
+
readonly method: "POST";
|
|
150
|
+
readonly url: string;
|
|
151
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
152
|
+
readonly body: string;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* This function reads an answer of version 1 of the BLS Public Data API for series of average prices.
|
|
156
|
+
*
|
|
157
|
+
* - Each value of a month of a known series becomes an average price, in US dollars for each unit of its item.
|
|
158
|
+
* - A series that is not in `known` gives a note, and no price.
|
|
159
|
+
* - A value that is not a decimal, for example `-` for no data, gives a note. So does a period that is not a month.
|
|
160
|
+
* - Each message of the answer gives a note, for example "No Data Available" for a year.
|
|
161
|
+
* - An answer that did not succeed gives problems. When a message names the daily threshold, the result also has
|
|
162
|
+
* `threshold: true`. Then a loop waits for the next day. The documentation does not give the shape of this answer.
|
|
163
|
+
*
|
|
164
|
+
* @param json - The JSON of the answer
|
|
165
|
+
* @param at - The instant of the answer
|
|
166
|
+
* @param known - The known series. The default is `BLS_STAPLES`.
|
|
167
|
+
* @throws RangeError when `at` is not an ISO 8601 instant in UTC
|
|
168
|
+
*/
|
|
169
|
+
export declare function parseBlsSeries(json: unknown, at: string, known?: readonly BlsSeries[]): AverageParseResult;
|
|
170
|
+
/** The text in the place of a secret in a message. */
|
|
171
|
+
export declare const SECRET_MARK = "[secret]";
|
|
172
|
+
/**
|
|
173
|
+
* This function puts `SECRET_MARK` in the place of each secret and of its forms in a URL and in a form body.
|
|
174
|
+
* It uses `redactSecrets` of `@mark1russell7/text`. Then it cuts the text to `MESSAGE_LIMIT`. Each client gives
|
|
175
|
+
* it to the send as its `redact`.
|
|
176
|
+
*/
|
|
177
|
+
export declare function redact(text: string, secrets: readonly string[]): string;
|
|
178
|
+
/** The host of the BLS Public Data API. */
|
|
179
|
+
export declare const BLS_HOST = "api.bls.gov";
|
|
180
|
+
/**
|
|
181
|
+
* The client sends one request each 72 minutes at most: 20 queries in each day. Version 1 of the API permits 25
|
|
182
|
+
* queries each day to a user with no key. Thus the pace keeps a margin of 5 queries in one process. Another process
|
|
183
|
+
* from the same address also counts, and the pace does not see it. One query reads up to 25 series and 10 years.
|
|
184
|
+
*/
|
|
185
|
+
export declare const BLS_PACE_MS: number;
|
|
186
|
+
/** The options of a BLS client. Version 1 of the API needs no key. */
|
|
187
|
+
interface BlsClientOptions<S extends Signal> {
|
|
188
|
+
readonly transport: Transport<S>;
|
|
189
|
+
readonly pace: Pace<S>;
|
|
190
|
+
}
|
|
191
|
+
/** A client of the average prices of the BLS Public Data API. */
|
|
192
|
+
interface BlsClient<S extends Signal> {
|
|
193
|
+
/**
|
|
194
|
+
* This method reads the average prices of some known series in one query. Without years, the API gives the last
|
|
195
|
+
* three years. The default series are `BLS_STAPLES`.
|
|
196
|
+
*/
|
|
197
|
+
averages(series?: readonly BlsSeries[], years?: {
|
|
198
|
+
readonly start: number;
|
|
199
|
+
readonly end: number;
|
|
200
|
+
}, signal?: S): Promise<AverageParseResult>;
|
|
201
|
+
}
|
|
202
|
+
/** This function makes a client of the average prices of the BLS Public Data API, version 1. */
|
|
203
|
+
export declare function createBlsClient<S extends Signal>(options: BlsClientOptions<S>): BlsClient<S>;
|
|
101
204
|
/** The name of the Best Buy Products API and Open Box API as a source of offers. */
|
|
102
205
|
export declare const BEST_BUY_SOURCE = "bestbuy";
|
|
103
206
|
/**
|
|
@@ -184,14 +287,6 @@ export declare function parseEbayItem(answer: unknown, at: string): ParseResult;
|
|
|
184
287
|
* @throws RangeError when `at` is not an instant in UTC in the ISO 8601 form.
|
|
185
288
|
*/
|
|
186
289
|
export declare function parseEbaySearch(answer: unknown, at: string): ParseResult;
|
|
187
|
-
/** The text in the place of a secret in a message. */
|
|
188
|
-
export declare const SECRET_MARK = "[secret]";
|
|
189
|
-
/**
|
|
190
|
-
* This function puts `SECRET_MARK` in the place of each secret and of its forms in a URL and in a form body.
|
|
191
|
-
* It uses `redactSecrets` of `@mark1russell7/text`. Then it cuts the text to `MESSAGE_LIMIT`. Each client gives
|
|
192
|
-
* it to the send as its `redact`.
|
|
193
|
-
*/
|
|
194
|
-
export declare function redact(text: string, secrets: readonly string[]): string;
|
|
195
290
|
/** The host of the Digi-Key APIs. */
|
|
196
291
|
export declare const DIGIKEY_HOST = "api.digikey.com";
|
|
197
292
|
/** The host of the sandbox of the Digi-Key APIs. Its answers have example data. */
|
|
@@ -540,5 +635,5 @@ interface PlanClient<S extends Signal> {
|
|
|
540
635
|
export declare function createPlanClient<S extends Signal>(options: PlanClientOptions<S>): PlanClient<S>;
|
|
541
636
|
/** The terms of each source of this package: the sellers in the order of the hand crawl, then Azure, then the plan lists. */
|
|
542
637
|
export declare const SOURCE_TERMS: readonly SourceTerms[];
|
|
543
|
-
export { ApiError, type ApiScheduler, type AzureClient, type AzureClientOptions, type AzureFilter, type AzureFilterField, type AzureReadOptions, type AzureUnit, type BestBuyClient, type BestBuyClientOptions, type DigiKeyClient, type DigiKeyClientOptions, type DigiKeyLocale, type EbayClient, type EbayClientOptions, type Exchange, type MeteredObservation, type MeteredParseResult, type Observation, type Pace, type ParseResult, type PlanAnswers, type PlanClient, type PlanClientOptions, type PlanListRead, type PlanNextPage, type PlanPaging, type PlanProvider, type PlanProviderRead, type PlanReadOptions, type PlanRegionPrices, type PlanRegions, type PlanSpec, type PlanTerm, type Reply, type Signal, type Transport };
|
|
638
|
+
export { ApiError, type ApiScheduler, type AverageParseResult, type AzureClient, type AzureClientOptions, type AzureFilter, type AzureFilterField, type AzureReadOptions, type AzureUnit, type BestBuyClient, type BestBuyClientOptions, type BlsClient, type BlsClientOptions, type BlsSeries, type DigiKeyClient, type DigiKeyClientOptions, type DigiKeyLocale, type EbayClient, type EbayClientOptions, type Exchange, type MeteredObservation, type MeteredParseResult, type Observation, type Pace, type ParseResult, type PlanAnswers, type PlanClient, type PlanClientOptions, type PlanListRead, type PlanNextPage, type PlanPaging, type PlanProvider, type PlanProviderRead, type PlanReadOptions, type PlanRegionPrices, type PlanRegions, type PlanSpec, type PlanTerm, type Reply, type Signal, type Transport };
|
|
544
639
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/parse.ts","../src/azure.ts","../src/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/parse.ts","../src/azure.ts","../src/bls.ts","../src/client.ts","../src/bls-client.ts","../src/bestbuy.ts","../src/digikey.ts","../src/ebay.ts","../src/digikey-client.ts","../src/ebay-client.ts","../src/azure-client.ts","../src/bestbuy-client.ts","../src/plans.ts","../src/providers.ts","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UAAU;WACrB,MAAM,KAAK;;;UAIL;;WAEN;;;UAIM,WAAW,UAAU;;EAEpC,MAAM,UAAU,cAAc,UAAU,iBAAiB,SAAS,IAAI,QAAQ;;;;;;;wBAiBhE,iBAAiB,UAAU,QAAQ,SAAS,kBAAkB,KAAK,WAAW;;qBC4EjF,uBAAuB"}
|
package/build/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { instantSchema, meteredKindOf, meteredObservationSchema, moneySchema, offerId, offerSchema, parseGtin, priceReadingSchema, priceTermSchema, sourceSchema, sourceTermsSchema, textSchema } from "@mark1russell7/market";
|
|
1
|
+
import { averagePriceId, averagePriceSchema, instantSchema, meteredKindOf, meteredObservationSchema, moneySchema, offerId, offerSchema, parseGtin, priceReadingSchema, priceTermSchema, sourceSchema, sourceTermsSchema, textSchema } from "@mark1russell7/market";
|
|
2
2
|
import { canonicalUnit, rationals } from "@mark1russell7/quantity";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { redactSecrets } from "@mark1russell7/text/redact";
|
|
@@ -855,6 +855,185 @@ function parseBestBuyOpenBox(answer, at) {
|
|
|
855
855
|
const notes = [];
|
|
856
856
|
return done(results.flatMap((result, index) => mapOpenBox(result, `results[${index}]`, at, notes)), notes);
|
|
857
857
|
}
|
|
858
|
+
// src/bls.ts
|
|
859
|
+
/** The name of the source. */
|
|
860
|
+
const BLS_SOURCE = "bls-ap";
|
|
861
|
+
/** The statement that the terms of the API make necessary for each user of the data. The layer that shows the prices shows it. */
|
|
862
|
+
const BLS_STATEMENT = "BLS.gov cannot vouch for the data or analyses derived from these data after the data have been retrieved from BLS.gov.";
|
|
863
|
+
/** The terms of the BLS Public Data API. They set no limit on the time or the use of the data. */
|
|
864
|
+
const BLS_TERMS = {
|
|
865
|
+
source: BLS_SOURCE,
|
|
866
|
+
retention: { kind: "keep" },
|
|
867
|
+
deleteWhenEnded: false,
|
|
868
|
+
priceModel: true,
|
|
869
|
+
clause: "BLS Public Data API Terms of Service, last modified 2023-08-30, read on 2026-11-22: no control over the end use, cite the date of the retrieval, give BLS_STATEMENT, and do not change the content"
|
|
870
|
+
};
|
|
871
|
+
/** The address of version 1 of the BLS Public Data API, for one or more series. */
|
|
872
|
+
const BLS_API_URL = "https://api.bls.gov/publicAPI/v1/timeseries/data/";
|
|
873
|
+
/** The most series of one query of version 1. */
|
|
874
|
+
const BLS_SERIES_LIMIT = 25;
|
|
875
|
+
/** The most years of one query of version 1. */
|
|
876
|
+
const BLS_YEAR_LIMIT = 10;
|
|
877
|
+
const US = "U.S. city average";
|
|
878
|
+
/**
|
|
879
|
+
* The average prices of some dry staples, in the U.S. city average. The titles are from the BLS data viewer of each
|
|
880
|
+
* series, read on 2026-11-22. The series of the Northeast for these items exist, but they have no value since 2023.
|
|
881
|
+
*/
|
|
882
|
+
const BLS_STAPLES = [
|
|
883
|
+
{
|
|
884
|
+
series: "APU0000701312",
|
|
885
|
+
item: "Rice, white, long grain, uncooked, per lb. (453.6 gm)",
|
|
886
|
+
area: US,
|
|
887
|
+
unit: "lb"
|
|
888
|
+
},
|
|
889
|
+
{
|
|
890
|
+
series: "APU0000701111",
|
|
891
|
+
item: "Flour, white, all purpose, per lb. (453.6 gm)",
|
|
892
|
+
area: US,
|
|
893
|
+
unit: "lb"
|
|
894
|
+
},
|
|
895
|
+
{
|
|
896
|
+
series: "APU0000714233",
|
|
897
|
+
item: "Beans, dried, any type, all sizes, per lb. (453.6 gm)",
|
|
898
|
+
area: US,
|
|
899
|
+
unit: "lb"
|
|
900
|
+
},
|
|
901
|
+
{
|
|
902
|
+
series: "APU0000715211",
|
|
903
|
+
item: "Sugar, white, all sizes, per lb. (453.6 gm)",
|
|
904
|
+
area: US,
|
|
905
|
+
unit: "lb"
|
|
906
|
+
},
|
|
907
|
+
{
|
|
908
|
+
series: "APU0000701322",
|
|
909
|
+
item: "Spaghetti and macaroni, per lb. (453.6 gm)",
|
|
910
|
+
area: US,
|
|
911
|
+
unit: "lb"
|
|
912
|
+
}
|
|
913
|
+
];
|
|
914
|
+
/** A message of BLS that tells that the daily threshold of the user is reached. */
|
|
915
|
+
const THRESHOLD = /threshold/i;
|
|
916
|
+
const SERIES_ID = /^[A-Z0-9]{1,30}$/;
|
|
917
|
+
/**
|
|
918
|
+
* This function gives the request of version 1 of the API for some series, from a first year to a last year. The
|
|
919
|
+
* API gives the last three years when the request has no years.
|
|
920
|
+
*
|
|
921
|
+
* @throws RangeError when the count of series is not from 1 to `BLS_SERIES_LIMIT`, or when an id is not an id of BLS.
|
|
922
|
+
* It also throws when the years are not whole numbers in order, or when they are more than `BLS_YEAR_LIMIT` years.
|
|
923
|
+
*/
|
|
924
|
+
function blsRequest(series, years) {
|
|
925
|
+
if (series.length < 1 || series.length > 25) throw new RangeError(`The count of series is not from 1 to 25.`);
|
|
926
|
+
for (const id of series) if (typeof id !== "string" || !SERIES_ID.test(id)) throw new RangeError(`The series ${show(id)} is not an id of BLS.`);
|
|
927
|
+
if (new Set(series).size !== series.length) throw new RangeError("A series is two times in the request.");
|
|
928
|
+
let body = { seriesid: series };
|
|
929
|
+
if (years !== void 0) {
|
|
930
|
+
const { start, end } = years;
|
|
931
|
+
if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start > end || end - start + 1 > 10) throw new RangeError(`The years are not whole numbers in order, with 10 years at most.`);
|
|
932
|
+
body = {
|
|
933
|
+
seriesid: series,
|
|
934
|
+
startyear: String(start),
|
|
935
|
+
endyear: String(end)
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
return {
|
|
939
|
+
method: "POST",
|
|
940
|
+
url: BLS_API_URL,
|
|
941
|
+
headers: {
|
|
942
|
+
accept: "application/json",
|
|
943
|
+
"content-type": "application/json"
|
|
944
|
+
},
|
|
945
|
+
body: JSON.stringify(body)
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
const MONTH = /^M(0[1-9]|1[0-2])$/;
|
|
949
|
+
const YEAR = /^\d{4}$/;
|
|
950
|
+
/** This function gives the texts of the footnotes of a value. A footnote with no text is not a footnote. */
|
|
951
|
+
function footnotesOf(value) {
|
|
952
|
+
return (list(value) ?? []).map((note) => text(field(note, "text"))).filter((note) => note !== void 0);
|
|
953
|
+
}
|
|
954
|
+
/**
|
|
955
|
+
* This function reads an answer of version 1 of the BLS Public Data API for series of average prices.
|
|
956
|
+
*
|
|
957
|
+
* - Each value of a month of a known series becomes an average price, in US dollars for each unit of its item.
|
|
958
|
+
* - A series that is not in `known` gives a note, and no price.
|
|
959
|
+
* - A value that is not a decimal, for example `-` for no data, gives a note. So does a period that is not a month.
|
|
960
|
+
* - Each message of the answer gives a note, for example "No Data Available" for a year.
|
|
961
|
+
* - An answer that did not succeed gives problems. When a message names the daily threshold, the result also has
|
|
962
|
+
* `threshold: true`. Then a loop waits for the next day. The documentation does not give the shape of this answer.
|
|
963
|
+
*
|
|
964
|
+
* @param json - The JSON of the answer
|
|
965
|
+
* @param at - The instant of the answer
|
|
966
|
+
* @param known - The known series. The default is `BLS_STAPLES`.
|
|
967
|
+
* @throws RangeError when `at` is not an ISO 8601 instant in UTC
|
|
968
|
+
*/
|
|
969
|
+
function parseBlsSeries(json, at, known = BLS_STAPLES) {
|
|
970
|
+
checkAt(at);
|
|
971
|
+
const status = field(json, "status");
|
|
972
|
+
const messages = (list(field(json, "message")) ?? []).map((message) => text(message)).filter((message) => message !== void 0);
|
|
973
|
+
if (status !== "REQUEST_SUCCEEDED") {
|
|
974
|
+
const problems = refused(`The status of the answer is ${show(status)}, not "REQUEST_SUCCEEDED".`, ...messages.map((message) => `BLS: ${message}`));
|
|
975
|
+
return messages.some((message) => THRESHOLD.test(message)) ? {
|
|
976
|
+
...problems,
|
|
977
|
+
threshold: true
|
|
978
|
+
} : problems;
|
|
979
|
+
}
|
|
980
|
+
const series = list(field(field(json, "Results"), "series"));
|
|
981
|
+
if (series === void 0) return refused("The answer has no list Results.series.");
|
|
982
|
+
const byId = new Map(known.map((each) => [each.series, each]));
|
|
983
|
+
const notes = messages.map((message) => `BLS: ${message}`);
|
|
984
|
+
const prices = [];
|
|
985
|
+
const seen = /* @__PURE__ */ new Set();
|
|
986
|
+
for (const entry of series) {
|
|
987
|
+
const id = text(field(entry, "seriesID"));
|
|
988
|
+
const meta = id === void 0 ? void 0 : byId.get(id);
|
|
989
|
+
if (meta === void 0) {
|
|
990
|
+
notes.push(`The series ${show(id)} is skipped: it is not a known series.`);
|
|
991
|
+
continue;
|
|
992
|
+
}
|
|
993
|
+
for (const point of list(field(entry, "data")) ?? []) {
|
|
994
|
+
const year = text(field(point, "year"));
|
|
995
|
+
const period = text(field(point, "period"));
|
|
996
|
+
if (year === void 0 || period === void 0 || !YEAR.test(year) || !MONTH.test(period)) {
|
|
997
|
+
notes.push(`A value of the series ${meta.series} is skipped: the period ${show(year)} ${show(period)} is not a month.`);
|
|
998
|
+
continue;
|
|
999
|
+
}
|
|
1000
|
+
const month = `${year}-${period.slice(1)}`;
|
|
1001
|
+
const value = decimal(field(point, "value"));
|
|
1002
|
+
if (value === void 0) {
|
|
1003
|
+
notes.push(`The value of the series ${meta.series} for ${month} is skipped: ${show(field(point, "value"))} is not a decimal.`);
|
|
1004
|
+
continue;
|
|
1005
|
+
}
|
|
1006
|
+
const footnotes = footnotesOf(field(point, "footnotes"));
|
|
1007
|
+
const record = compact({
|
|
1008
|
+
id: averagePriceId(BLS_SOURCE, meta.series, month),
|
|
1009
|
+
source: BLS_SOURCE,
|
|
1010
|
+
series: meta.series,
|
|
1011
|
+
item: meta.item,
|
|
1012
|
+
area: meta.area,
|
|
1013
|
+
period: month,
|
|
1014
|
+
price: {
|
|
1015
|
+
value,
|
|
1016
|
+
unit: `USD/${meta.unit}`
|
|
1017
|
+
},
|
|
1018
|
+
at,
|
|
1019
|
+
footnotes: footnotes.length === 0 ? void 0 : footnotes
|
|
1020
|
+
});
|
|
1021
|
+
const checked = averagePriceSchema.safeParse(record);
|
|
1022
|
+
if (!checked.success) {
|
|
1023
|
+
notes.push(`The value of the series ${meta.series} for ${month} is skipped: the schema refuses it.`);
|
|
1024
|
+
continue;
|
|
1025
|
+
}
|
|
1026
|
+
if (seen.has(checked.data.id)) continue;
|
|
1027
|
+
seen.add(checked.data.id);
|
|
1028
|
+
prices.push(checked.data);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
return {
|
|
1032
|
+
ok: true,
|
|
1033
|
+
prices,
|
|
1034
|
+
notes
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
858
1037
|
// src/digikey.ts
|
|
859
1038
|
/** The name of the Digi-Key Product Information API v4 as a source of offers. */
|
|
860
1039
|
const DIGIKEY_SOURCE = "digikey";
|
|
@@ -1501,6 +1680,35 @@ function readAnswer(answer, input, parse, at) {
|
|
|
1501
1680
|
function instantOf(ms) {
|
|
1502
1681
|
return new Date(ms).toISOString();
|
|
1503
1682
|
}
|
|
1683
|
+
// src/bls-client.ts
|
|
1684
|
+
/** The host of the BLS Public Data API. */
|
|
1685
|
+
const BLS_HOST = "api.bls.gov";
|
|
1686
|
+
/**
|
|
1687
|
+
* The client sends one request each 72 minutes at most: 20 queries in each day. Version 1 of the API permits 25
|
|
1688
|
+
* queries each day to a user with no key. Thus the pace keeps a margin of 5 queries in one process. Another process
|
|
1689
|
+
* from the same address also counts, and the pace does not see it. One query reads up to 25 series and 10 years.
|
|
1690
|
+
*/
|
|
1691
|
+
const BLS_PACE_MS = 432e4;
|
|
1692
|
+
const SOURCE$4 = "BLS Public Data API";
|
|
1693
|
+
/** This function makes a client of the average prices of the BLS Public Data API, version 1. */
|
|
1694
|
+
function createBlsClient(options) {
|
|
1695
|
+
const { pace, transport } = options;
|
|
1696
|
+
return { async averages(series = BLS_STAPLES, years, signal) {
|
|
1697
|
+
const exchange = blsRequest(series.map((each) => each.series), years);
|
|
1698
|
+
const what = `the average prices of ${series.length} series`;
|
|
1699
|
+
const input = {
|
|
1700
|
+
source: SOURCE$4,
|
|
1701
|
+
host: BLS_HOST,
|
|
1702
|
+
minIntervalMs: BLS_PACE_MS,
|
|
1703
|
+
what,
|
|
1704
|
+
secrets: [],
|
|
1705
|
+
redact,
|
|
1706
|
+
exchange
|
|
1707
|
+
};
|
|
1708
|
+
const json = readJson(await send(pace, transport, input, signal), input);
|
|
1709
|
+
return json.ok ? parseBlsSeries(json.json, instantOf(pace.now()), series) : json;
|
|
1710
|
+
} };
|
|
1711
|
+
}
|
|
1504
1712
|
// src/digikey-client.ts
|
|
1505
1713
|
/** The host of the Digi-Key APIs. */
|
|
1506
1714
|
const DIGIKEY_HOST = "api.digikey.com";
|
|
@@ -2296,8 +2504,9 @@ const SOURCE_TERMS = [
|
|
|
2296
2504
|
DIGIKEY_TERMS,
|
|
2297
2505
|
AZURE_TERMS,
|
|
2298
2506
|
LINODE_TERMS,
|
|
2299
|
-
VULTR_TERMS
|
|
2507
|
+
VULTR_TERMS,
|
|
2508
|
+
BLS_TERMS
|
|
2300
2509
|
];
|
|
2301
|
-
export { AZURE_API_VERSION, AZURE_FILTER_FIELDS, AZURE_HOST, AZURE_PACE_MS, AZURE_PAGE_LIMIT, AZURE_PRICES_URL, AZURE_PROVIDER, AZURE_SOURCE, AZURE_TERMS, ApiError, BEST_BUY_HOST, BEST_BUY_PACE_MS, BEST_BUY_PAGE_LIMIT, BEST_BUY_SOURCE, BEST_BUY_TERMS, DIGIKEY_HOST, DIGIKEY_PACE_MS, DIGIKEY_SANDBOX_HOST, DIGIKEY_SEARCH_LIMIT, DIGIKEY_SELLER, DIGIKEY_SOURCE, DIGIKEY_TERMS, DIGIKEY_US, EBAY_HOST, EBAY_PACE_MS, EBAY_SANDBOX_HOST, EBAY_SCOPE, EBAY_SEARCH_LIMIT, EBAY_SOURCE, EBAY_TERMS, EBAY_US, LINODE_PLANS, LINODE_SOURCE, LINODE_TERMS, PLAN_METER, PLAN_PAGE_LIMIT, PLAN_PRICING_SPEC, PLAN_PROVIDERS, SECRET_MARK, SOURCE_TERMS, VULTR_PLANS, VULTR_SOURCE, VULTR_TERMS, azureNextPage, azurePricesUrl, azureUnit, bestBuyCondition, createAzureClient, createBestBuyClient, createDigiKeyClient, createEbayClient, createPlanClient, ebayCondition, isAzurePricesUrl, parseAzureRetailPricePages, parseAzureRetailPrices, parseBestBuyOpenBox, parseBestBuyProduct, parseBestBuyProducts, parseDigiKeyKeywordSearch, parseDigiKeyProductDetails, parseEbayItem, parseEbaySearch, parsePlanLists, parsePlanProvider, planListUrl, planNextPage, planProviderSchema, redact };
|
|
2510
|
+
export { AZURE_API_VERSION, AZURE_FILTER_FIELDS, AZURE_HOST, AZURE_PACE_MS, AZURE_PAGE_LIMIT, AZURE_PRICES_URL, AZURE_PROVIDER, AZURE_SOURCE, AZURE_TERMS, ApiError, BEST_BUY_HOST, BEST_BUY_PACE_MS, BEST_BUY_PAGE_LIMIT, BEST_BUY_SOURCE, BEST_BUY_TERMS, BLS_API_URL, BLS_HOST, BLS_PACE_MS, BLS_SERIES_LIMIT, BLS_SOURCE, BLS_STAPLES, BLS_STATEMENT, BLS_TERMS, BLS_YEAR_LIMIT, DIGIKEY_HOST, DIGIKEY_PACE_MS, DIGIKEY_SANDBOX_HOST, DIGIKEY_SEARCH_LIMIT, DIGIKEY_SELLER, DIGIKEY_SOURCE, DIGIKEY_TERMS, DIGIKEY_US, EBAY_HOST, EBAY_PACE_MS, EBAY_SANDBOX_HOST, EBAY_SCOPE, EBAY_SEARCH_LIMIT, EBAY_SOURCE, EBAY_TERMS, EBAY_US, LINODE_PLANS, LINODE_SOURCE, LINODE_TERMS, PLAN_METER, PLAN_PAGE_LIMIT, PLAN_PRICING_SPEC, PLAN_PROVIDERS, SECRET_MARK, SOURCE_TERMS, VULTR_PLANS, VULTR_SOURCE, VULTR_TERMS, azureNextPage, azurePricesUrl, azureUnit, bestBuyCondition, blsRequest, createAzureClient, createBestBuyClient, createBlsClient, createDigiKeyClient, createEbayClient, createPlanClient, ebayCondition, isAzurePricesUrl, parseAzureRetailPricePages, parseAzureRetailPrices, parseBestBuyOpenBox, parseBestBuyProduct, parseBestBuyProducts, parseBlsSeries, parseDigiKeyKeywordSearch, parseDigiKeyProductDetails, parseEbayItem, parseEbaySearch, parsePlanLists, parsePlanProvider, planListUrl, planNextPage, planProviderSchema, redact };
|
|
2302
2511
|
|
|
2303
2512
|
//# sourceMappingURL=index.js.map
|