@parseapi/sdk 1.0.0 → 1.1.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 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.0.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.
20
+ Version 1.1.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
- Previously published SDKs 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.
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.
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.0.0";
27
+ var VERSION = "1.1.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
- headers: { "X-API-Key": key, "User-Agent": `parseapi-node/${VERSION}`, ...headers, "Parse-Version": API_VERSION },
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 body = {};
160
+ let body2 = {};
159
161
  try {
160
162
  const parsed = await res.json();
161
- if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) body = 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 body.code === "string" ? body.code : "unknown_error",
169
- typeof body.message === "string" ? body.message : `Request failed with status ${res.status}`,
170
- typeof body.docs === "string" ? body.docs : null,
171
- typeof body.request_id === "string" ? body.request_id : null
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
@@ -1243,6 +1243,102 @@ interface PropertyTax {
1243
1243
  period: string;
1244
1244
  }
1245
1245
 
1246
+ /** A proposed task contains operation counts, never lookup inputs. */
1247
+ interface PreflightOperation {
1248
+ operation: 'email' | 'domain' | 'dns' | 'mx' | 'country';
1249
+ /** Positive integer, at most 100000. */
1250
+ count: number;
1251
+ deep?: boolean;
1252
+ }
1253
+ interface PreflightTask {
1254
+ /** One to twenty rows, totaling at most 100000 lookups. */
1255
+ operations: PreflightOperation[];
1256
+ /** Nonnegative USD decimal string with at most two fractional digits. Advisory, never an enforced cap. */
1257
+ budget_usd?: string;
1258
+ }
1259
+ interface PreflightOperationEstimate {
1260
+ operation: string;
1261
+ count: number;
1262
+ deep: boolean;
1263
+ permitted: boolean;
1264
+ reason: string | null;
1265
+ /** Attempts per lookup under the default SDK retry policy. */
1266
+ max_http_attempts: number;
1267
+ pooled_requests_max: number;
1268
+ metered_units_max: number;
1269
+ }
1270
+ interface PreflightCost {
1271
+ currency: string;
1272
+ status: string;
1273
+ minimum_usd: string;
1274
+ /** Additional charges assuming included units are exhausted. Null when the effective rate is unknown. */
1275
+ maximum_usd: string | null;
1276
+ /** Additional charges using currently unallocated included units. */
1277
+ projected_maximum_usd: string | null;
1278
+ on_demand_unit_price_usd: string | null;
1279
+ }
1280
+ interface PreflightPooledCapacity {
1281
+ advisory: true;
1282
+ required_max: number;
1283
+ policy: string | null;
1284
+ limit: number | null;
1285
+ used_at_snapshot: number | null;
1286
+ remaining_at_snapshot: number | null;
1287
+ /** Unix seconds, or null when no active grace deadline is known. */
1288
+ grace_until: number | null;
1289
+ /** Unix seconds. */
1290
+ reset_at: number;
1291
+ allowed_at_snapshot: boolean | null;
1292
+ status: string;
1293
+ }
1294
+ interface PreflightEmailCapacity {
1295
+ advisory: true;
1296
+ required_max: number;
1297
+ included_limit: number;
1298
+ reserved_at_snapshot: number | null;
1299
+ unallocated_included_at_snapshot: number | null;
1300
+ projected_overage_units_max: number | null;
1301
+ on_demand_enabled: boolean | null;
1302
+ fits_unallocated_capacity: boolean | null;
1303
+ /** Unix seconds. */
1304
+ reset_at: number;
1305
+ }
1306
+ interface PreflightSpendCapacity {
1307
+ advisory: true;
1308
+ currency: string;
1309
+ cap_usd: string | null;
1310
+ cap_status: string;
1311
+ reserved_usd_at_snapshot: string | null;
1312
+ unallocated_usd_at_snapshot: string | null;
1313
+ /** Unix seconds. */
1314
+ reset_at: number;
1315
+ }
1316
+ /** A credential-specific estimate. Counters are advisory and can change during execution. */
1317
+ interface Preflight {
1318
+ schema_version: string;
1319
+ api_version: string;
1320
+ /** ISO 8601 evaluation time. */
1321
+ evaluated_at: string;
1322
+ estimate_only: true;
1323
+ supported: boolean;
1324
+ /** Permission for the requested features, separate from available capacity. */
1325
+ permitted: boolean;
1326
+ operations: PreflightOperationEstimate[];
1327
+ cost: PreflightCost;
1328
+ capacity: {
1329
+ pooled_requests: PreflightPooledCapacity;
1330
+ email_verifications: PreflightEmailCapacity;
1331
+ shared_on_demand_spend: PreflightSpendCapacity;
1332
+ };
1333
+ budget?: {
1334
+ amount_usd: string;
1335
+ within_maximum: boolean | null;
1336
+ enforced: false;
1337
+ };
1338
+ assumptions: string[];
1339
+ warnings: string[];
1340
+ }
1341
+
1246
1342
  /** Every non-2xx response from the API. Branch on `code`, never on `message`. */
1247
1343
  declare class ParseAPIError extends Error {
1248
1344
  /** HTTP status */
@@ -1461,6 +1557,8 @@ interface DeepOption {
1461
1557
  deep?: boolean;
1462
1558
  }
1463
1559
  declare function parseAPI(apiKey?: string, options?: ParseAPIOptions): {
1560
+ /** Estimate task access, capacity and additional charges. Requires a secret key. Reserves no units or money and does not enforce the supplied budget. */
1561
+ preflight: (task: PreflightTask, opts?: RequestOptions) => Promise<Preflight>;
1464
1562
  /** Look up an IP. `deep: true` adds enrichment included with a paid plan, without a separate check meter. */
1465
1563
  ip: ((ip: string, opts?: IpOptions) => Promise<Ip>) & {
1466
1564
  /** Look up the public IP making this request. On a server, this is the server's IP. */
@@ -1566,4 +1664,4 @@ declare function parseAPI(apiKey?: string, options?: ParseAPIOptions): {
1566
1664
  };
1567
1665
  type ParseAPIClient = ReturnType<typeof parseAPI>;
1568
1666
 
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 };
1667
+ 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
@@ -1243,6 +1243,102 @@ interface PropertyTax {
1243
1243
  period: string;
1244
1244
  }
1245
1245
 
1246
+ /** A proposed task contains operation counts, never lookup inputs. */
1247
+ interface PreflightOperation {
1248
+ operation: 'email' | 'domain' | 'dns' | 'mx' | 'country';
1249
+ /** Positive integer, at most 100000. */
1250
+ count: number;
1251
+ deep?: boolean;
1252
+ }
1253
+ interface PreflightTask {
1254
+ /** One to twenty rows, totaling at most 100000 lookups. */
1255
+ operations: PreflightOperation[];
1256
+ /** Nonnegative USD decimal string with at most two fractional digits. Advisory, never an enforced cap. */
1257
+ budget_usd?: string;
1258
+ }
1259
+ interface PreflightOperationEstimate {
1260
+ operation: string;
1261
+ count: number;
1262
+ deep: boolean;
1263
+ permitted: boolean;
1264
+ reason: string | null;
1265
+ /** Attempts per lookup under the default SDK retry policy. */
1266
+ max_http_attempts: number;
1267
+ pooled_requests_max: number;
1268
+ metered_units_max: number;
1269
+ }
1270
+ interface PreflightCost {
1271
+ currency: string;
1272
+ status: string;
1273
+ minimum_usd: string;
1274
+ /** Additional charges assuming included units are exhausted. Null when the effective rate is unknown. */
1275
+ maximum_usd: string | null;
1276
+ /** Additional charges using currently unallocated included units. */
1277
+ projected_maximum_usd: string | null;
1278
+ on_demand_unit_price_usd: string | null;
1279
+ }
1280
+ interface PreflightPooledCapacity {
1281
+ advisory: true;
1282
+ required_max: number;
1283
+ policy: string | null;
1284
+ limit: number | null;
1285
+ used_at_snapshot: number | null;
1286
+ remaining_at_snapshot: number | null;
1287
+ /** Unix seconds, or null when no active grace deadline is known. */
1288
+ grace_until: number | null;
1289
+ /** Unix seconds. */
1290
+ reset_at: number;
1291
+ allowed_at_snapshot: boolean | null;
1292
+ status: string;
1293
+ }
1294
+ interface PreflightEmailCapacity {
1295
+ advisory: true;
1296
+ required_max: number;
1297
+ included_limit: number;
1298
+ reserved_at_snapshot: number | null;
1299
+ unallocated_included_at_snapshot: number | null;
1300
+ projected_overage_units_max: number | null;
1301
+ on_demand_enabled: boolean | null;
1302
+ fits_unallocated_capacity: boolean | null;
1303
+ /** Unix seconds. */
1304
+ reset_at: number;
1305
+ }
1306
+ interface PreflightSpendCapacity {
1307
+ advisory: true;
1308
+ currency: string;
1309
+ cap_usd: string | null;
1310
+ cap_status: string;
1311
+ reserved_usd_at_snapshot: string | null;
1312
+ unallocated_usd_at_snapshot: string | null;
1313
+ /** Unix seconds. */
1314
+ reset_at: number;
1315
+ }
1316
+ /** A credential-specific estimate. Counters are advisory and can change during execution. */
1317
+ interface Preflight {
1318
+ schema_version: string;
1319
+ api_version: string;
1320
+ /** ISO 8601 evaluation time. */
1321
+ evaluated_at: string;
1322
+ estimate_only: true;
1323
+ supported: boolean;
1324
+ /** Permission for the requested features, separate from available capacity. */
1325
+ permitted: boolean;
1326
+ operations: PreflightOperationEstimate[];
1327
+ cost: PreflightCost;
1328
+ capacity: {
1329
+ pooled_requests: PreflightPooledCapacity;
1330
+ email_verifications: PreflightEmailCapacity;
1331
+ shared_on_demand_spend: PreflightSpendCapacity;
1332
+ };
1333
+ budget?: {
1334
+ amount_usd: string;
1335
+ within_maximum: boolean | null;
1336
+ enforced: false;
1337
+ };
1338
+ assumptions: string[];
1339
+ warnings: string[];
1340
+ }
1341
+
1246
1342
  /** Every non-2xx response from the API. Branch on `code`, never on `message`. */
1247
1343
  declare class ParseAPIError extends Error {
1248
1344
  /** HTTP status */
@@ -1461,6 +1557,8 @@ interface DeepOption {
1461
1557
  deep?: boolean;
1462
1558
  }
1463
1559
  declare function parseAPI(apiKey?: string, options?: ParseAPIOptions): {
1560
+ /** Estimate task access, capacity and additional charges. Requires a secret key. Reserves no units or money and does not enforce the supplied budget. */
1561
+ preflight: (task: PreflightTask, opts?: RequestOptions) => Promise<Preflight>;
1464
1562
  /** Look up an IP. `deep: true` adds enrichment included with a paid plan, without a separate check meter. */
1465
1563
  ip: ((ip: string, opts?: IpOptions) => Promise<Ip>) & {
1466
1564
  /** Look up the public IP making this request. On a server, this is the server's IP. */
@@ -1566,4 +1664,4 @@ declare function parseAPI(apiKey?: string, options?: ParseAPIOptions): {
1566
1664
  };
1567
1665
  type ParseAPIClient = ReturnType<typeof parseAPI>;
1568
1666
 
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 };
1667
+ 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.0.0";
2
+ var VERSION = "1.1.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
- headers: { "X-API-Key": key, "User-Agent": `parseapi-node/${VERSION}`, ...headers, "Parse-Version": API_VERSION },
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 body = {};
135
+ let body2 = {};
134
136
  try {
135
137
  const parsed = await res.json();
136
- if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) body = 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 body.code === "string" ? body.code : "unknown_error",
144
- typeof body.message === "string" ? body.message : `Request failed with status ${res.status}`,
145
- typeof body.docs === "string" ? body.docs : null,
146
- typeof body.request_id === "string" ? body.request_id : null
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),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parseapi/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Official ParseAPI client for Node and TypeScript. One key, minimal JSON, fast.",
5
5
  "keywords": [
6
6
  "parseapi",