@parseapi/sdk 1.0.0 → 1.2.0
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 +23 -3
- package/dist/index.cjs +13 -9
- package/dist/index.d.cts +110 -1
- package/dist/index.d.ts +110 -1
- package/dist/index.js +13 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,14 +17,30 @@ Get a key at [parseapi.com](https://parseapi.com). The client also reads `PARSEA
|
|
|
17
17
|
|
|
18
18
|
## API versions
|
|
19
19
|
|
|
20
|
-
Version 1.
|
|
20
|
+
Version 1.2.0 explicitly selects the API contract supported by this SDK. It sends `Parse-Version: 2.0.0` on every lookup so responses match the API contract supported by the package. Your key and the team's saved default stay the same.
|
|
21
21
|
|
|
22
22
|
Upgrade the dependency in staging, review the [release notes](https://parseapi.com/docs/releases), and test the application before deploying the same code and dependency version to production. Commit your dependency lockfile so the tested package travels with your deployment. Future major SDK upgrades can select a newer API contract.
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
SDK packages older than 1.0.0 keep their existing behavior and use the team's default. Requests without `Parse-Version` also use that default, managed in [Dashboard API version](https://parseapi.com/dashboard/versions). Keep it unchanged while older applications depend on it. Rolling back to an SDK without a version header restores the team default, so rollback only restores the old contract when that default has stayed unchanged.
|
|
25
25
|
|
|
26
26
|
The package owns its supported API version. For direct HTTP integrations, an explicit `Parse-Version` header selects a supported contract. See [API versions and migration](https://parseapi.com/docs/versioning).
|
|
27
27
|
|
|
28
|
+
## Task preflight
|
|
29
|
+
|
|
30
|
+
Use a secret key to estimate access, advisory capacity and additional charges before a task. Preflight is available with API contract `2.0.0`.
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
const estimate = await parse.preflight({
|
|
34
|
+
operations: [{ operation: 'email', count: 100, deep: true }],
|
|
35
|
+
budget_usd: '2.50',
|
|
36
|
+
});
|
|
37
|
+
console.log(estimate.permitted, estimate.cost, estimate.capacity, estimate.budget);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Preflight accepts Email, Domain, DNS, MX and Country, with at most 20 rows and 100,000 total lookups. Supply operation counts without personal data or lookup inputs. Monetary values use decimal strings. The maximum assumes included Email checks are exhausted. The projection uses currently unallocated included checks. Rates come from the credential's accepted terms.
|
|
41
|
+
|
|
42
|
+
Check `permitted`, `cost.status`, `capacity` and the optional `budget.within_maximum` together. Unknown values remain null. Capacity can change with concurrent work. Preflight reserves no units or money, performs no paid checks and does not enforce the supplied budget. It uses the normal request rate limit. Estimates allow up to three attempts per ordinary lookup and one per Email Deep lookup. Extra retries or calls require a new estimate. Subscription fees, tax and model costs are excluded.
|
|
43
|
+
|
|
28
44
|
## Weather from a postal code
|
|
29
45
|
|
|
30
46
|
Start with the postal code, then pass its coordinates to weather. Reuse the client from the example above.
|
|
@@ -194,7 +210,7 @@ Choose enrichment for the question you need answered.
|
|
|
194
210
|
|---|---|
|
|
195
211
|
| IP | Richer IP fields included with a paid plan. No separate check meter. |
|
|
196
212
|
| Domain | Registration dates, registrar, status and DNSSEC, included with a paid plan. Use `dns` for DNS records and `mx` for mail routing. |
|
|
197
|
-
| Email | A metered
|
|
213
|
+
| Email | A metered mailbox check with deliverability, catch-all, status, reason and address hints, using included email checks or enabled on-demand usage. |
|
|
198
214
|
| VAT | A metered registry check where supported, using included VAT checks or enabled on-demand usage. |
|
|
199
215
|
| Phone, Time, Date, Currency, Language, Emoji, IBAN, Point | Optional detail in the same pooled request on every plan. |
|
|
200
216
|
| Country, State, District, City, Postal | The place profile on paid plans, including demographic and tax facts where held. |
|
|
@@ -203,6 +219,10 @@ Choose enrichment for the question you need answered.
|
|
|
203
219
|
| Weather | Specialist current measurements and the existing forecast, alert, air and history bag on paid plans. |
|
|
204
220
|
| Carrier, HLR | Optional diagnostic detail within the same metered core unit, including Free allowance units. No second gate or additional check. |
|
|
205
221
|
|
|
222
|
+
Email deep includes mailbox status and the reason for the result, plus a suggested first name, no-reply flag, plus-address tag and mail service. The suggested name is not a verified identity. Unavailable details are null.
|
|
223
|
+
|
|
224
|
+
Reasons include `accepted`, `invalid_format`, `invalid_domain`, `no_mail_server`, `mailbox_not_found`, `mailbox_disabled`, `mailbox_full`, `catchall`, `disposable`, `temporary_failure`, `rejected` and `unconfirmed`.
|
|
225
|
+
|
|
206
226
|
Carrier, caller, and HLR are separate metered operations. Choose them explicitly when you need their answers. Ordinary lookups retry twice by default. Metered checks use one attempt by default. Setting retries explicitly can repeat paid usage.
|
|
207
227
|
|
|
208
228
|
Without `deep`, the response omits that key. When requested, it is an empty object if access is locked or the operation has no deep fields. Otherwise it contains the available fields. A missing or null field means unknown.
|
package/dist/index.cjs
CHANGED
|
@@ -24,7 +24,7 @@ __export(index_exports, {
|
|
|
24
24
|
parseAPI: () => parseAPI
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
|
-
var VERSION = "1.
|
|
27
|
+
var VERSION = "1.2.0";
|
|
28
28
|
var API_VERSION = "2.0.0";
|
|
29
29
|
var DEFAULT_BASE_URL = "https://api.parseapi.com";
|
|
30
30
|
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
@@ -107,13 +107,14 @@ function parseAPI(apiKey, options = {}) {
|
|
|
107
107
|
validateTimeout(timeoutMs);
|
|
108
108
|
validateRetries(configuredRetries);
|
|
109
109
|
const doFetch = options.fetch ?? fetch;
|
|
110
|
-
async function request(path, query, headers, controls = {}) {
|
|
110
|
+
async function request(path, query, headers, controls = {}, json) {
|
|
111
111
|
const signal = controls.signal;
|
|
112
112
|
signal?.throwIfAborted();
|
|
113
113
|
const attemptTimeout = controls.timeoutMs ?? timeoutMs;
|
|
114
114
|
const retries = controls.retries ?? configuredRetries ?? (metered(path, query) ? 0 : DEFAULT_RETRIES);
|
|
115
115
|
validateTimeout(attemptTimeout);
|
|
116
116
|
validateRetries(retries);
|
|
117
|
+
const body = json === void 0 ? void 0 : JSON.stringify(json);
|
|
117
118
|
const url = new URL(baseUrl + path);
|
|
118
119
|
if (controls.lang !== void 0) url.searchParams.set("lang", controls.lang);
|
|
119
120
|
for (const [name, value] of Object.entries(query ?? {})) {
|
|
@@ -131,7 +132,8 @@ function parseAPI(apiKey, options = {}) {
|
|
|
131
132
|
try {
|
|
132
133
|
res = await doFetch(url, {
|
|
133
134
|
redirect: "manual",
|
|
134
|
-
|
|
135
|
+
...body === void 0 ? {} : { method: "POST", body },
|
|
136
|
+
headers: { "X-API-Key": key, "User-Agent": `parseapi-node/${VERSION}`, ...body === void 0 ? {} : { "Content-Type": "application/json" }, ...headers, "Parse-Version": API_VERSION },
|
|
135
137
|
signal: controller.signal
|
|
136
138
|
});
|
|
137
139
|
} catch (error) {
|
|
@@ -155,20 +157,20 @@ function parseAPI(apiKey, options = {}) {
|
|
|
155
157
|
await res.body?.cancel().catch(() => {
|
|
156
158
|
});
|
|
157
159
|
} else if (res) {
|
|
158
|
-
let
|
|
160
|
+
let body2 = {};
|
|
159
161
|
try {
|
|
160
162
|
const parsed = await res.json();
|
|
161
|
-
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed))
|
|
163
|
+
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) body2 = parsed;
|
|
162
164
|
} catch {
|
|
163
165
|
controller.signal.throwIfAborted();
|
|
164
166
|
}
|
|
165
167
|
signal?.throwIfAborted();
|
|
166
168
|
throw new ParseAPIError(
|
|
167
169
|
res.status,
|
|
168
|
-
typeof
|
|
169
|
-
typeof
|
|
170
|
-
typeof
|
|
171
|
-
typeof
|
|
170
|
+
typeof body2.code === "string" ? body2.code : "unknown_error",
|
|
171
|
+
typeof body2.message === "string" ? body2.message : `Request failed with status ${res.status}`,
|
|
172
|
+
typeof body2.docs === "string" ? body2.docs : null,
|
|
173
|
+
typeof body2.request_id === "string" ? body2.request_id : null
|
|
172
174
|
);
|
|
173
175
|
}
|
|
174
176
|
} finally {
|
|
@@ -181,6 +183,8 @@ function parseAPI(apiKey, options = {}) {
|
|
|
181
183
|
const enc = encodeURIComponent;
|
|
182
184
|
const deepQuery = (opts) => opts?.deep ? { deep: true } : {};
|
|
183
185
|
return {
|
|
186
|
+
/** Estimate task access, capacity and additional charges. Requires a secret key. Reserves no units or money and does not enforce the supplied budget. */
|
|
187
|
+
preflight: (task, opts) => request("/preflight", void 0, void 0, opts, task),
|
|
184
188
|
/** Look up an IP. `deep: true` adds enrichment included with a paid plan, without a separate check meter. */
|
|
185
189
|
ip: Object.assign(
|
|
186
190
|
(ip, opts) => request(`/ip/${enc(ip)}`, deepQuery(opts), void 0, opts),
|
package/dist/index.d.cts
CHANGED
|
@@ -250,8 +250,19 @@ interface PostalDistance {
|
|
|
250
250
|
distance_mi: number;
|
|
251
251
|
}
|
|
252
252
|
interface EmailDeep {
|
|
253
|
+
/** Suggested first name. Not a verified identity. */
|
|
254
|
+
first_name?: string | null;
|
|
255
|
+
no_reply?: boolean | null;
|
|
256
|
+
/** Plus-address tag, without the plus sign. */
|
|
257
|
+
tag?: string | null;
|
|
258
|
+
/** Mail service handling the address, such as Google or Microsoft. */
|
|
259
|
+
mail_provider?: string | null;
|
|
253
260
|
deliverable: boolean | null;
|
|
254
261
|
catchall: boolean | null;
|
|
262
|
+
/** Mailbox status: deliverable, undeliverable or risky. Null when unavailable. */
|
|
263
|
+
status?: string | null;
|
|
264
|
+
/** Why the address received this result, such as mailbox_full or mailbox_not_found. Null when unavailable. */
|
|
265
|
+
reason?: string | null;
|
|
255
266
|
}
|
|
256
267
|
interface Email {
|
|
257
268
|
email: string;
|
|
@@ -1243,6 +1254,102 @@ interface PropertyTax {
|
|
|
1243
1254
|
period: string;
|
|
1244
1255
|
}
|
|
1245
1256
|
|
|
1257
|
+
/** A proposed task contains operation counts, never lookup inputs. */
|
|
1258
|
+
interface PreflightOperation {
|
|
1259
|
+
operation: 'email' | 'domain' | 'dns' | 'mx' | 'country';
|
|
1260
|
+
/** Positive integer, at most 100000. */
|
|
1261
|
+
count: number;
|
|
1262
|
+
deep?: boolean;
|
|
1263
|
+
}
|
|
1264
|
+
interface PreflightTask {
|
|
1265
|
+
/** One to twenty rows, totaling at most 100000 lookups. */
|
|
1266
|
+
operations: PreflightOperation[];
|
|
1267
|
+
/** Nonnegative USD decimal string with at most two fractional digits. Advisory, never an enforced cap. */
|
|
1268
|
+
budget_usd?: string;
|
|
1269
|
+
}
|
|
1270
|
+
interface PreflightOperationEstimate {
|
|
1271
|
+
operation: string;
|
|
1272
|
+
count: number;
|
|
1273
|
+
deep: boolean;
|
|
1274
|
+
permitted: boolean;
|
|
1275
|
+
reason: string | null;
|
|
1276
|
+
/** Attempts per lookup under the default SDK retry policy. */
|
|
1277
|
+
max_http_attempts: number;
|
|
1278
|
+
pooled_requests_max: number;
|
|
1279
|
+
metered_units_max: number;
|
|
1280
|
+
}
|
|
1281
|
+
interface PreflightCost {
|
|
1282
|
+
currency: string;
|
|
1283
|
+
status: string;
|
|
1284
|
+
minimum_usd: string;
|
|
1285
|
+
/** Additional charges assuming included units are exhausted. Null when the effective rate is unknown. */
|
|
1286
|
+
maximum_usd: string | null;
|
|
1287
|
+
/** Additional charges using currently unallocated included units. */
|
|
1288
|
+
projected_maximum_usd: string | null;
|
|
1289
|
+
on_demand_unit_price_usd: string | null;
|
|
1290
|
+
}
|
|
1291
|
+
interface PreflightPooledCapacity {
|
|
1292
|
+
advisory: true;
|
|
1293
|
+
required_max: number;
|
|
1294
|
+
policy: string | null;
|
|
1295
|
+
limit: number | null;
|
|
1296
|
+
used_at_snapshot: number | null;
|
|
1297
|
+
remaining_at_snapshot: number | null;
|
|
1298
|
+
/** Unix seconds, or null when no active grace deadline is known. */
|
|
1299
|
+
grace_until: number | null;
|
|
1300
|
+
/** Unix seconds. */
|
|
1301
|
+
reset_at: number;
|
|
1302
|
+
allowed_at_snapshot: boolean | null;
|
|
1303
|
+
status: string;
|
|
1304
|
+
}
|
|
1305
|
+
interface PreflightEmailCapacity {
|
|
1306
|
+
advisory: true;
|
|
1307
|
+
required_max: number;
|
|
1308
|
+
included_limit: number;
|
|
1309
|
+
reserved_at_snapshot: number | null;
|
|
1310
|
+
unallocated_included_at_snapshot: number | null;
|
|
1311
|
+
projected_overage_units_max: number | null;
|
|
1312
|
+
on_demand_enabled: boolean | null;
|
|
1313
|
+
fits_unallocated_capacity: boolean | null;
|
|
1314
|
+
/** Unix seconds. */
|
|
1315
|
+
reset_at: number;
|
|
1316
|
+
}
|
|
1317
|
+
interface PreflightSpendCapacity {
|
|
1318
|
+
advisory: true;
|
|
1319
|
+
currency: string;
|
|
1320
|
+
cap_usd: string | null;
|
|
1321
|
+
cap_status: string;
|
|
1322
|
+
reserved_usd_at_snapshot: string | null;
|
|
1323
|
+
unallocated_usd_at_snapshot: string | null;
|
|
1324
|
+
/** Unix seconds. */
|
|
1325
|
+
reset_at: number;
|
|
1326
|
+
}
|
|
1327
|
+
/** A credential-specific estimate. Counters are advisory and can change during execution. */
|
|
1328
|
+
interface Preflight {
|
|
1329
|
+
schema_version: string;
|
|
1330
|
+
api_version: string;
|
|
1331
|
+
/** ISO 8601 evaluation time. */
|
|
1332
|
+
evaluated_at: string;
|
|
1333
|
+
estimate_only: true;
|
|
1334
|
+
supported: boolean;
|
|
1335
|
+
/** Permission for the requested features, separate from available capacity. */
|
|
1336
|
+
permitted: boolean;
|
|
1337
|
+
operations: PreflightOperationEstimate[];
|
|
1338
|
+
cost: PreflightCost;
|
|
1339
|
+
capacity: {
|
|
1340
|
+
pooled_requests: PreflightPooledCapacity;
|
|
1341
|
+
email_verifications: PreflightEmailCapacity;
|
|
1342
|
+
shared_on_demand_spend: PreflightSpendCapacity;
|
|
1343
|
+
};
|
|
1344
|
+
budget?: {
|
|
1345
|
+
amount_usd: string;
|
|
1346
|
+
within_maximum: boolean | null;
|
|
1347
|
+
enforced: false;
|
|
1348
|
+
};
|
|
1349
|
+
assumptions: string[];
|
|
1350
|
+
warnings: string[];
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1246
1353
|
/** Every non-2xx response from the API. Branch on `code`, never on `message`. */
|
|
1247
1354
|
declare class ParseAPIError extends Error {
|
|
1248
1355
|
/** HTTP status */
|
|
@@ -1461,6 +1568,8 @@ interface DeepOption {
|
|
|
1461
1568
|
deep?: boolean;
|
|
1462
1569
|
}
|
|
1463
1570
|
declare function parseAPI(apiKey?: string, options?: ParseAPIOptions): {
|
|
1571
|
+
/** Estimate task access, capacity and additional charges. Requires a secret key. Reserves no units or money and does not enforce the supplied budget. */
|
|
1572
|
+
preflight: (task: PreflightTask, opts?: RequestOptions) => Promise<Preflight>;
|
|
1464
1573
|
/** Look up an IP. `deep: true` adds enrichment included with a paid plan, without a separate check meter. */
|
|
1465
1574
|
ip: ((ip: string, opts?: IpOptions) => Promise<Ip>) & {
|
|
1466
1575
|
/** Look up the public IP making this request. On a server, this is the server's IP. */
|
|
@@ -1566,4 +1675,4 @@ declare function parseAPI(apiKey?: string, options?: ParseAPIOptions): {
|
|
|
1566
1675
|
};
|
|
1567
1676
|
type ParseAPIClient = ReturnType<typeof parseAPI>;
|
|
1568
1677
|
|
|
1569
|
-
export { type Address, type AddressOptions, type AddressSearch, type AddressSearchOptions, type AddressSuggestion, type Asn, type AsnOptions, type Bin, type BinOptions, type Bloc, type BlocCountries, type BlocCountriesOptions, type BlocCountryItem, type BlocOptions, type Caller, type CallerOptions, type Carrier, type CarrierDeep, type CarrierOptions, type City, type CityDeep, type CityIdOptions, type CityNearby, type CityNearbyOptions, type CityNearest, type CityNearestOptions, type CityOptions, type CitySearch, type CitySearchOptions, type Company, type CompanyCountry, type CompanyDeep, type CompanyOptions, type Continent, type ContinentCountries, type ContinentCountriesOptions, type ContinentCountryItem, type ContinentOptions, type Country, type CountryDeep, type CountryElevationPoint, type CountryEmergency, type CountryOptions, type CountryStateItem, type CountryStates, type CountryStatesOptions, type Currency, type CurrencyDeep, type CurrencyOptions, type CurrencyRate, type CurrencyRateOptions, type DateInfo, type DateInfoDeep, type DateOptions, type DateTodayOptions, type Deep, type District, type DistrictDeep, type DistrictOptions, type Dns, type DnsOptions, type DnsRecord, type Domain, type DomainDeep, type DomainOptions, type DomainRegistration, type Elevation, type ElevationOptions, type Email, type EmailDeep, type EmailOptions, type Emoji, type EmojiDeep, type EmojiOptions, type EmojiSearch, type EmojiSearchOptions, type EmojiSkin, type Hlr, type HlrDeep, type HlrOptions, type Holiday, type HolidayDate, type HolidayDateOptions, type HolidayOptions, type HolidayYear, type Iban, type IbanDeep, type IbanOptions, type Ip, type IpDeep, type IpOptions, type IpSelfOptions, type Language, type LanguageDeep, type LanguageOption, type LanguageOptions, type Mac, type MacOptions, type Measure, type MeasureChoice, type MeasureOptions, type MeasureUnit, type MeasureUnits, type MeasureUnitsOptions, type Mx, type MxOptions, type MxRecord, type Naics, type NaicsChild, type NaicsCorrection, type NaicsDeep, type NaicsExclusion, type NaicsMatch, type NaicsOptions, type NaicsSearch, type NaicsSearchItem, type NaicsSearchOptions, type Name, type NameDeep, type NameOptions, type Npi, type NpiDeep, type NpiEnrollment, type NpiOptions, type ParseAPIClient, ParseAPIError, type ParseAPIOptions, type Phone, type PhoneDeep, type PhoneOptions, type Point, type PointCity, type PointDeep, type PointOptions, type Postal, type PostalDeep, type PostalDistance, type PostalDistanceEnd, type PostalDistanceOptions, type PostalMetro, type PostalMetrosDeep, type PostalNearby, type PostalNearbyItem, type PostalNearbyOptions, type PostalOptions, type PropertyTax, type RequestOptions, type State, type StateDeep, type StateDistrictDeep, type StateDistrictItem, type StateDistricts, type StateDistrictsOptions, type StateOptions, type Tariff, type TariffDeep, type TariffMeasure, type TariffOptions, type TariffSearch, type TariffSearchHit, type TariffSearchOptions, type Time, type TimeAtOptions, type TimeOptions, type Timezone, type TimezoneAtOptions, type TimezoneConversionTarget, type TimezoneConversionTargetDeep, type TimezoneDeep, type TimezoneNextDst, type TimezoneOptions, type Useragent, type UseragentBrowserBrand, type UseragentBrowserDeep, type UseragentDeep, type UseragentDeviceDeep, type UseragentEngineDeep, type UseragentOptions, type UseragentOsDeep, type Vat, type VatAddress, type VatDeep, type VatOptions, type Vin, type VinDeep, type VinOptions, type VinRecall, type Weather, type WeatherAir, type WeatherAlert, type WeatherCurrent, type WeatherCurrentDeep, type WeatherDay, type WeatherDeep, type WeatherForecastPeriod, type WeatherHistory, type WeatherHour, type WeatherMinute, type WeatherOptions, type WeatherStation, parseAPI };
|
|
1678
|
+
export { type Address, type AddressOptions, type AddressSearch, type AddressSearchOptions, type AddressSuggestion, type Asn, type AsnOptions, type Bin, type BinOptions, type Bloc, type BlocCountries, type BlocCountriesOptions, type BlocCountryItem, type BlocOptions, type Caller, type CallerOptions, type Carrier, type CarrierDeep, type CarrierOptions, type City, type CityDeep, type CityIdOptions, type CityNearby, type CityNearbyOptions, type CityNearest, type CityNearestOptions, type CityOptions, type CitySearch, type CitySearchOptions, type Company, type CompanyCountry, type CompanyDeep, type CompanyOptions, type Continent, type ContinentCountries, type ContinentCountriesOptions, type ContinentCountryItem, type ContinentOptions, type Country, type CountryDeep, type CountryElevationPoint, type CountryEmergency, type CountryOptions, type CountryStateItem, type CountryStates, type CountryStatesOptions, type Currency, type CurrencyDeep, type CurrencyOptions, type CurrencyRate, type CurrencyRateOptions, type DateInfo, type DateInfoDeep, type DateOptions, type DateTodayOptions, type Deep, type District, type DistrictDeep, type DistrictOptions, type Dns, type DnsOptions, type DnsRecord, type Domain, type DomainDeep, type DomainOptions, type DomainRegistration, type Elevation, type ElevationOptions, type Email, type EmailDeep, type EmailOptions, type Emoji, type EmojiDeep, type EmojiOptions, type EmojiSearch, type EmojiSearchOptions, type EmojiSkin, type Hlr, type HlrDeep, type HlrOptions, type Holiday, type HolidayDate, type HolidayDateOptions, type HolidayOptions, type HolidayYear, type Iban, type IbanDeep, type IbanOptions, type Ip, type IpDeep, type IpOptions, type IpSelfOptions, type Language, type LanguageDeep, type LanguageOption, type LanguageOptions, type Mac, type MacOptions, type Measure, type MeasureChoice, type MeasureOptions, type MeasureUnit, type MeasureUnits, type MeasureUnitsOptions, type Mx, type MxOptions, type MxRecord, type Naics, type NaicsChild, type NaicsCorrection, type NaicsDeep, type NaicsExclusion, type NaicsMatch, type NaicsOptions, type NaicsSearch, type NaicsSearchItem, type NaicsSearchOptions, type Name, type NameDeep, type NameOptions, type Npi, type NpiDeep, type NpiEnrollment, type NpiOptions, type ParseAPIClient, ParseAPIError, type ParseAPIOptions, type Phone, type PhoneDeep, type PhoneOptions, type Point, type PointCity, type PointDeep, type PointOptions, type Postal, type PostalDeep, type PostalDistance, type PostalDistanceEnd, type PostalDistanceOptions, type PostalMetro, type PostalMetrosDeep, type PostalNearby, type PostalNearbyItem, type PostalNearbyOptions, type PostalOptions, type Preflight, type PreflightCost, type PreflightEmailCapacity, type PreflightOperation, type PreflightOperationEstimate, type PreflightPooledCapacity, type PreflightSpendCapacity, type PreflightTask, type PropertyTax, type RequestOptions, type State, type StateDeep, type StateDistrictDeep, type StateDistrictItem, type StateDistricts, type StateDistrictsOptions, type StateOptions, type Tariff, type TariffDeep, type TariffMeasure, type TariffOptions, type TariffSearch, type TariffSearchHit, type TariffSearchOptions, type Time, type TimeAtOptions, type TimeOptions, type Timezone, type TimezoneAtOptions, type TimezoneConversionTarget, type TimezoneConversionTargetDeep, type TimezoneDeep, type TimezoneNextDst, type TimezoneOptions, type Useragent, type UseragentBrowserBrand, type UseragentBrowserDeep, type UseragentDeep, type UseragentDeviceDeep, type UseragentEngineDeep, type UseragentOptions, type UseragentOsDeep, type Vat, type VatAddress, type VatDeep, type VatOptions, type Vin, type VinDeep, type VinOptions, type VinRecall, type Weather, type WeatherAir, type WeatherAlert, type WeatherCurrent, type WeatherCurrentDeep, type WeatherDay, type WeatherDeep, type WeatherForecastPeriod, type WeatherHistory, type WeatherHour, type WeatherMinute, type WeatherOptions, type WeatherStation, parseAPI };
|
package/dist/index.d.ts
CHANGED
|
@@ -250,8 +250,19 @@ interface PostalDistance {
|
|
|
250
250
|
distance_mi: number;
|
|
251
251
|
}
|
|
252
252
|
interface EmailDeep {
|
|
253
|
+
/** Suggested first name. Not a verified identity. */
|
|
254
|
+
first_name?: string | null;
|
|
255
|
+
no_reply?: boolean | null;
|
|
256
|
+
/** Plus-address tag, without the plus sign. */
|
|
257
|
+
tag?: string | null;
|
|
258
|
+
/** Mail service handling the address, such as Google or Microsoft. */
|
|
259
|
+
mail_provider?: string | null;
|
|
253
260
|
deliverable: boolean | null;
|
|
254
261
|
catchall: boolean | null;
|
|
262
|
+
/** Mailbox status: deliverable, undeliverable or risky. Null when unavailable. */
|
|
263
|
+
status?: string | null;
|
|
264
|
+
/** Why the address received this result, such as mailbox_full or mailbox_not_found. Null when unavailable. */
|
|
265
|
+
reason?: string | null;
|
|
255
266
|
}
|
|
256
267
|
interface Email {
|
|
257
268
|
email: string;
|
|
@@ -1243,6 +1254,102 @@ interface PropertyTax {
|
|
|
1243
1254
|
period: string;
|
|
1244
1255
|
}
|
|
1245
1256
|
|
|
1257
|
+
/** A proposed task contains operation counts, never lookup inputs. */
|
|
1258
|
+
interface PreflightOperation {
|
|
1259
|
+
operation: 'email' | 'domain' | 'dns' | 'mx' | 'country';
|
|
1260
|
+
/** Positive integer, at most 100000. */
|
|
1261
|
+
count: number;
|
|
1262
|
+
deep?: boolean;
|
|
1263
|
+
}
|
|
1264
|
+
interface PreflightTask {
|
|
1265
|
+
/** One to twenty rows, totaling at most 100000 lookups. */
|
|
1266
|
+
operations: PreflightOperation[];
|
|
1267
|
+
/** Nonnegative USD decimal string with at most two fractional digits. Advisory, never an enforced cap. */
|
|
1268
|
+
budget_usd?: string;
|
|
1269
|
+
}
|
|
1270
|
+
interface PreflightOperationEstimate {
|
|
1271
|
+
operation: string;
|
|
1272
|
+
count: number;
|
|
1273
|
+
deep: boolean;
|
|
1274
|
+
permitted: boolean;
|
|
1275
|
+
reason: string | null;
|
|
1276
|
+
/** Attempts per lookup under the default SDK retry policy. */
|
|
1277
|
+
max_http_attempts: number;
|
|
1278
|
+
pooled_requests_max: number;
|
|
1279
|
+
metered_units_max: number;
|
|
1280
|
+
}
|
|
1281
|
+
interface PreflightCost {
|
|
1282
|
+
currency: string;
|
|
1283
|
+
status: string;
|
|
1284
|
+
minimum_usd: string;
|
|
1285
|
+
/** Additional charges assuming included units are exhausted. Null when the effective rate is unknown. */
|
|
1286
|
+
maximum_usd: string | null;
|
|
1287
|
+
/** Additional charges using currently unallocated included units. */
|
|
1288
|
+
projected_maximum_usd: string | null;
|
|
1289
|
+
on_demand_unit_price_usd: string | null;
|
|
1290
|
+
}
|
|
1291
|
+
interface PreflightPooledCapacity {
|
|
1292
|
+
advisory: true;
|
|
1293
|
+
required_max: number;
|
|
1294
|
+
policy: string | null;
|
|
1295
|
+
limit: number | null;
|
|
1296
|
+
used_at_snapshot: number | null;
|
|
1297
|
+
remaining_at_snapshot: number | null;
|
|
1298
|
+
/** Unix seconds, or null when no active grace deadline is known. */
|
|
1299
|
+
grace_until: number | null;
|
|
1300
|
+
/** Unix seconds. */
|
|
1301
|
+
reset_at: number;
|
|
1302
|
+
allowed_at_snapshot: boolean | null;
|
|
1303
|
+
status: string;
|
|
1304
|
+
}
|
|
1305
|
+
interface PreflightEmailCapacity {
|
|
1306
|
+
advisory: true;
|
|
1307
|
+
required_max: number;
|
|
1308
|
+
included_limit: number;
|
|
1309
|
+
reserved_at_snapshot: number | null;
|
|
1310
|
+
unallocated_included_at_snapshot: number | null;
|
|
1311
|
+
projected_overage_units_max: number | null;
|
|
1312
|
+
on_demand_enabled: boolean | null;
|
|
1313
|
+
fits_unallocated_capacity: boolean | null;
|
|
1314
|
+
/** Unix seconds. */
|
|
1315
|
+
reset_at: number;
|
|
1316
|
+
}
|
|
1317
|
+
interface PreflightSpendCapacity {
|
|
1318
|
+
advisory: true;
|
|
1319
|
+
currency: string;
|
|
1320
|
+
cap_usd: string | null;
|
|
1321
|
+
cap_status: string;
|
|
1322
|
+
reserved_usd_at_snapshot: string | null;
|
|
1323
|
+
unallocated_usd_at_snapshot: string | null;
|
|
1324
|
+
/** Unix seconds. */
|
|
1325
|
+
reset_at: number;
|
|
1326
|
+
}
|
|
1327
|
+
/** A credential-specific estimate. Counters are advisory and can change during execution. */
|
|
1328
|
+
interface Preflight {
|
|
1329
|
+
schema_version: string;
|
|
1330
|
+
api_version: string;
|
|
1331
|
+
/** ISO 8601 evaluation time. */
|
|
1332
|
+
evaluated_at: string;
|
|
1333
|
+
estimate_only: true;
|
|
1334
|
+
supported: boolean;
|
|
1335
|
+
/** Permission for the requested features, separate from available capacity. */
|
|
1336
|
+
permitted: boolean;
|
|
1337
|
+
operations: PreflightOperationEstimate[];
|
|
1338
|
+
cost: PreflightCost;
|
|
1339
|
+
capacity: {
|
|
1340
|
+
pooled_requests: PreflightPooledCapacity;
|
|
1341
|
+
email_verifications: PreflightEmailCapacity;
|
|
1342
|
+
shared_on_demand_spend: PreflightSpendCapacity;
|
|
1343
|
+
};
|
|
1344
|
+
budget?: {
|
|
1345
|
+
amount_usd: string;
|
|
1346
|
+
within_maximum: boolean | null;
|
|
1347
|
+
enforced: false;
|
|
1348
|
+
};
|
|
1349
|
+
assumptions: string[];
|
|
1350
|
+
warnings: string[];
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1246
1353
|
/** Every non-2xx response from the API. Branch on `code`, never on `message`. */
|
|
1247
1354
|
declare class ParseAPIError extends Error {
|
|
1248
1355
|
/** HTTP status */
|
|
@@ -1461,6 +1568,8 @@ interface DeepOption {
|
|
|
1461
1568
|
deep?: boolean;
|
|
1462
1569
|
}
|
|
1463
1570
|
declare function parseAPI(apiKey?: string, options?: ParseAPIOptions): {
|
|
1571
|
+
/** Estimate task access, capacity and additional charges. Requires a secret key. Reserves no units or money and does not enforce the supplied budget. */
|
|
1572
|
+
preflight: (task: PreflightTask, opts?: RequestOptions) => Promise<Preflight>;
|
|
1464
1573
|
/** Look up an IP. `deep: true` adds enrichment included with a paid plan, without a separate check meter. */
|
|
1465
1574
|
ip: ((ip: string, opts?: IpOptions) => Promise<Ip>) & {
|
|
1466
1575
|
/** Look up the public IP making this request. On a server, this is the server's IP. */
|
|
@@ -1566,4 +1675,4 @@ declare function parseAPI(apiKey?: string, options?: ParseAPIOptions): {
|
|
|
1566
1675
|
};
|
|
1567
1676
|
type ParseAPIClient = ReturnType<typeof parseAPI>;
|
|
1568
1677
|
|
|
1569
|
-
export { type Address, type AddressOptions, type AddressSearch, type AddressSearchOptions, type AddressSuggestion, type Asn, type AsnOptions, type Bin, type BinOptions, type Bloc, type BlocCountries, type BlocCountriesOptions, type BlocCountryItem, type BlocOptions, type Caller, type CallerOptions, type Carrier, type CarrierDeep, type CarrierOptions, type City, type CityDeep, type CityIdOptions, type CityNearby, type CityNearbyOptions, type CityNearest, type CityNearestOptions, type CityOptions, type CitySearch, type CitySearchOptions, type Company, type CompanyCountry, type CompanyDeep, type CompanyOptions, type Continent, type ContinentCountries, type ContinentCountriesOptions, type ContinentCountryItem, type ContinentOptions, type Country, type CountryDeep, type CountryElevationPoint, type CountryEmergency, type CountryOptions, type CountryStateItem, type CountryStates, type CountryStatesOptions, type Currency, type CurrencyDeep, type CurrencyOptions, type CurrencyRate, type CurrencyRateOptions, type DateInfo, type DateInfoDeep, type DateOptions, type DateTodayOptions, type Deep, type District, type DistrictDeep, type DistrictOptions, type Dns, type DnsOptions, type DnsRecord, type Domain, type DomainDeep, type DomainOptions, type DomainRegistration, type Elevation, type ElevationOptions, type Email, type EmailDeep, type EmailOptions, type Emoji, type EmojiDeep, type EmojiOptions, type EmojiSearch, type EmojiSearchOptions, type EmojiSkin, type Hlr, type HlrDeep, type HlrOptions, type Holiday, type HolidayDate, type HolidayDateOptions, type HolidayOptions, type HolidayYear, type Iban, type IbanDeep, type IbanOptions, type Ip, type IpDeep, type IpOptions, type IpSelfOptions, type Language, type LanguageDeep, type LanguageOption, type LanguageOptions, type Mac, type MacOptions, type Measure, type MeasureChoice, type MeasureOptions, type MeasureUnit, type MeasureUnits, type MeasureUnitsOptions, type Mx, type MxOptions, type MxRecord, type Naics, type NaicsChild, type NaicsCorrection, type NaicsDeep, type NaicsExclusion, type NaicsMatch, type NaicsOptions, type NaicsSearch, type NaicsSearchItem, type NaicsSearchOptions, type Name, type NameDeep, type NameOptions, type Npi, type NpiDeep, type NpiEnrollment, type NpiOptions, type ParseAPIClient, ParseAPIError, type ParseAPIOptions, type Phone, type PhoneDeep, type PhoneOptions, type Point, type PointCity, type PointDeep, type PointOptions, type Postal, type PostalDeep, type PostalDistance, type PostalDistanceEnd, type PostalDistanceOptions, type PostalMetro, type PostalMetrosDeep, type PostalNearby, type PostalNearbyItem, type PostalNearbyOptions, type PostalOptions, type PropertyTax, type RequestOptions, type State, type StateDeep, type StateDistrictDeep, type StateDistrictItem, type StateDistricts, type StateDistrictsOptions, type StateOptions, type Tariff, type TariffDeep, type TariffMeasure, type TariffOptions, type TariffSearch, type TariffSearchHit, type TariffSearchOptions, type Time, type TimeAtOptions, type TimeOptions, type Timezone, type TimezoneAtOptions, type TimezoneConversionTarget, type TimezoneConversionTargetDeep, type TimezoneDeep, type TimezoneNextDst, type TimezoneOptions, type Useragent, type UseragentBrowserBrand, type UseragentBrowserDeep, type UseragentDeep, type UseragentDeviceDeep, type UseragentEngineDeep, type UseragentOptions, type UseragentOsDeep, type Vat, type VatAddress, type VatDeep, type VatOptions, type Vin, type VinDeep, type VinOptions, type VinRecall, type Weather, type WeatherAir, type WeatherAlert, type WeatherCurrent, type WeatherCurrentDeep, type WeatherDay, type WeatherDeep, type WeatherForecastPeriod, type WeatherHistory, type WeatherHour, type WeatherMinute, type WeatherOptions, type WeatherStation, parseAPI };
|
|
1678
|
+
export { type Address, type AddressOptions, type AddressSearch, type AddressSearchOptions, type AddressSuggestion, type Asn, type AsnOptions, type Bin, type BinOptions, type Bloc, type BlocCountries, type BlocCountriesOptions, type BlocCountryItem, type BlocOptions, type Caller, type CallerOptions, type Carrier, type CarrierDeep, type CarrierOptions, type City, type CityDeep, type CityIdOptions, type CityNearby, type CityNearbyOptions, type CityNearest, type CityNearestOptions, type CityOptions, type CitySearch, type CitySearchOptions, type Company, type CompanyCountry, type CompanyDeep, type CompanyOptions, type Continent, type ContinentCountries, type ContinentCountriesOptions, type ContinentCountryItem, type ContinentOptions, type Country, type CountryDeep, type CountryElevationPoint, type CountryEmergency, type CountryOptions, type CountryStateItem, type CountryStates, type CountryStatesOptions, type Currency, type CurrencyDeep, type CurrencyOptions, type CurrencyRate, type CurrencyRateOptions, type DateInfo, type DateInfoDeep, type DateOptions, type DateTodayOptions, type Deep, type District, type DistrictDeep, type DistrictOptions, type Dns, type DnsOptions, type DnsRecord, type Domain, type DomainDeep, type DomainOptions, type DomainRegistration, type Elevation, type ElevationOptions, type Email, type EmailDeep, type EmailOptions, type Emoji, type EmojiDeep, type EmojiOptions, type EmojiSearch, type EmojiSearchOptions, type EmojiSkin, type Hlr, type HlrDeep, type HlrOptions, type Holiday, type HolidayDate, type HolidayDateOptions, type HolidayOptions, type HolidayYear, type Iban, type IbanDeep, type IbanOptions, type Ip, type IpDeep, type IpOptions, type IpSelfOptions, type Language, type LanguageDeep, type LanguageOption, type LanguageOptions, type Mac, type MacOptions, type Measure, type MeasureChoice, type MeasureOptions, type MeasureUnit, type MeasureUnits, type MeasureUnitsOptions, type Mx, type MxOptions, type MxRecord, type Naics, type NaicsChild, type NaicsCorrection, type NaicsDeep, type NaicsExclusion, type NaicsMatch, type NaicsOptions, type NaicsSearch, type NaicsSearchItem, type NaicsSearchOptions, type Name, type NameDeep, type NameOptions, type Npi, type NpiDeep, type NpiEnrollment, type NpiOptions, type ParseAPIClient, ParseAPIError, type ParseAPIOptions, type Phone, type PhoneDeep, type PhoneOptions, type Point, type PointCity, type PointDeep, type PointOptions, type Postal, type PostalDeep, type PostalDistance, type PostalDistanceEnd, type PostalDistanceOptions, type PostalMetro, type PostalMetrosDeep, type PostalNearby, type PostalNearbyItem, type PostalNearbyOptions, type PostalOptions, type Preflight, type PreflightCost, type PreflightEmailCapacity, type PreflightOperation, type PreflightOperationEstimate, type PreflightPooledCapacity, type PreflightSpendCapacity, type PreflightTask, type PropertyTax, type RequestOptions, type State, type StateDeep, type StateDistrictDeep, type StateDistrictItem, type StateDistricts, type StateDistrictsOptions, type StateOptions, type Tariff, type TariffDeep, type TariffMeasure, type TariffOptions, type TariffSearch, type TariffSearchHit, type TariffSearchOptions, type Time, type TimeAtOptions, type TimeOptions, type Timezone, type TimezoneAtOptions, type TimezoneConversionTarget, type TimezoneConversionTargetDeep, type TimezoneDeep, type TimezoneNextDst, type TimezoneOptions, type Useragent, type UseragentBrowserBrand, type UseragentBrowserDeep, type UseragentDeep, type UseragentDeviceDeep, type UseragentEngineDeep, type UseragentOptions, type UseragentOsDeep, type Vat, type VatAddress, type VatDeep, type VatOptions, type Vin, type VinDeep, type VinOptions, type VinRecall, type Weather, type WeatherAir, type WeatherAlert, type WeatherCurrent, type WeatherCurrentDeep, type WeatherDay, type WeatherDeep, type WeatherForecastPeriod, type WeatherHistory, type WeatherHour, type WeatherMinute, type WeatherOptions, type WeatherStation, parseAPI };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
var VERSION = "1.
|
|
2
|
+
var VERSION = "1.2.0";
|
|
3
3
|
var API_VERSION = "2.0.0";
|
|
4
4
|
var DEFAULT_BASE_URL = "https://api.parseapi.com";
|
|
5
5
|
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
@@ -82,13 +82,14 @@ function parseAPI(apiKey, options = {}) {
|
|
|
82
82
|
validateTimeout(timeoutMs);
|
|
83
83
|
validateRetries(configuredRetries);
|
|
84
84
|
const doFetch = options.fetch ?? fetch;
|
|
85
|
-
async function request(path, query, headers, controls = {}) {
|
|
85
|
+
async function request(path, query, headers, controls = {}, json) {
|
|
86
86
|
const signal = controls.signal;
|
|
87
87
|
signal?.throwIfAborted();
|
|
88
88
|
const attemptTimeout = controls.timeoutMs ?? timeoutMs;
|
|
89
89
|
const retries = controls.retries ?? configuredRetries ?? (metered(path, query) ? 0 : DEFAULT_RETRIES);
|
|
90
90
|
validateTimeout(attemptTimeout);
|
|
91
91
|
validateRetries(retries);
|
|
92
|
+
const body = json === void 0 ? void 0 : JSON.stringify(json);
|
|
92
93
|
const url = new URL(baseUrl + path);
|
|
93
94
|
if (controls.lang !== void 0) url.searchParams.set("lang", controls.lang);
|
|
94
95
|
for (const [name, value] of Object.entries(query ?? {})) {
|
|
@@ -106,7 +107,8 @@ function parseAPI(apiKey, options = {}) {
|
|
|
106
107
|
try {
|
|
107
108
|
res = await doFetch(url, {
|
|
108
109
|
redirect: "manual",
|
|
109
|
-
|
|
110
|
+
...body === void 0 ? {} : { method: "POST", body },
|
|
111
|
+
headers: { "X-API-Key": key, "User-Agent": `parseapi-node/${VERSION}`, ...body === void 0 ? {} : { "Content-Type": "application/json" }, ...headers, "Parse-Version": API_VERSION },
|
|
110
112
|
signal: controller.signal
|
|
111
113
|
});
|
|
112
114
|
} catch (error) {
|
|
@@ -130,20 +132,20 @@ function parseAPI(apiKey, options = {}) {
|
|
|
130
132
|
await res.body?.cancel().catch(() => {
|
|
131
133
|
});
|
|
132
134
|
} else if (res) {
|
|
133
|
-
let
|
|
135
|
+
let body2 = {};
|
|
134
136
|
try {
|
|
135
137
|
const parsed = await res.json();
|
|
136
|
-
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed))
|
|
138
|
+
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) body2 = parsed;
|
|
137
139
|
} catch {
|
|
138
140
|
controller.signal.throwIfAborted();
|
|
139
141
|
}
|
|
140
142
|
signal?.throwIfAborted();
|
|
141
143
|
throw new ParseAPIError(
|
|
142
144
|
res.status,
|
|
143
|
-
typeof
|
|
144
|
-
typeof
|
|
145
|
-
typeof
|
|
146
|
-
typeof
|
|
145
|
+
typeof body2.code === "string" ? body2.code : "unknown_error",
|
|
146
|
+
typeof body2.message === "string" ? body2.message : `Request failed with status ${res.status}`,
|
|
147
|
+
typeof body2.docs === "string" ? body2.docs : null,
|
|
148
|
+
typeof body2.request_id === "string" ? body2.request_id : null
|
|
147
149
|
);
|
|
148
150
|
}
|
|
149
151
|
} finally {
|
|
@@ -156,6 +158,8 @@ function parseAPI(apiKey, options = {}) {
|
|
|
156
158
|
const enc = encodeURIComponent;
|
|
157
159
|
const deepQuery = (opts) => opts?.deep ? { deep: true } : {};
|
|
158
160
|
return {
|
|
161
|
+
/** Estimate task access, capacity and additional charges. Requires a secret key. Reserves no units or money and does not enforce the supplied budget. */
|
|
162
|
+
preflight: (task, opts) => request("/preflight", void 0, void 0, opts, task),
|
|
159
163
|
/** Look up an IP. `deep: true` adds enrichment included with a paid plan, without a separate check meter. */
|
|
160
164
|
ip: Object.assign(
|
|
161
165
|
(ip, opts) => request(`/ip/${enc(ip)}`, deepQuery(opts), void 0, opts),
|