keepa-api 0.2.3 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +31 -3
  2. package/dist/index.cjs +398 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +206 -0
  5. package/dist/index.d.ts +206 -8
  6. package/dist/index.js +346 -7
  7. package/dist/index.js.map +1 -1
  8. package/package.json +14 -5
  9. package/dist/client.d.ts +0 -21
  10. package/dist/client.d.ts.map +0 -1
  11. package/dist/client.js +0 -38
  12. package/dist/client.js.map +0 -1
  13. package/dist/core/error.d.ts +0 -27
  14. package/dist/core/error.d.ts.map +0 -1
  15. package/dist/core/error.js +0 -61
  16. package/dist/core/error.js.map +0 -1
  17. package/dist/core/request.d.ts +0 -15
  18. package/dist/core/request.d.ts.map +0 -1
  19. package/dist/core/request.js +0 -36
  20. package/dist/core/request.js.map +0 -1
  21. package/dist/core/resource.d.ts +0 -6
  22. package/dist/core/resource.d.ts.map +0 -1
  23. package/dist/core/resource.js +0 -7
  24. package/dist/core/resource.js.map +0 -1
  25. package/dist/index.d.ts.map +0 -1
  26. package/dist/lib/asin.d.ts +0 -10
  27. package/dist/lib/asin.d.ts.map +0 -1
  28. package/dist/lib/asin.js +0 -19
  29. package/dist/lib/asin.js.map +0 -1
  30. package/dist/lib/marketplace.d.ts +0 -17
  31. package/dist/lib/marketplace.d.ts.map +0 -1
  32. package/dist/lib/marketplace.js +0 -27
  33. package/dist/lib/marketplace.js.map +0 -1
  34. package/dist/resources/index.d.ts +0 -2
  35. package/dist/resources/index.d.ts.map +0 -1
  36. package/dist/resources/index.js +0 -2
  37. package/dist/resources/index.js.map +0 -1
  38. package/dist/resources/products/constant.d.ts +0 -7
  39. package/dist/resources/products/constant.d.ts.map +0 -1
  40. package/dist/resources/products/constant.js +0 -15
  41. package/dist/resources/products/constant.js.map +0 -1
  42. package/dist/resources/products/error.d.ts +0 -10
  43. package/dist/resources/products/error.d.ts.map +0 -1
  44. package/dist/resources/products/error.js +0 -14
  45. package/dist/resources/products/error.js.map +0 -1
  46. package/dist/resources/products/index.d.ts +0 -6
  47. package/dist/resources/products/index.d.ts.map +0 -1
  48. package/dist/resources/products/index.js +0 -8
  49. package/dist/resources/products/index.js.map +0 -1
  50. package/dist/resources/products/product.raw.type.d.ts +0 -36
  51. package/dist/resources/products/product.raw.type.d.ts.map +0 -1
  52. package/dist/resources/products/product.raw.type.js +0 -6
  53. package/dist/resources/products/product.raw.type.js.map +0 -1
  54. package/dist/resources/products/product.type.d.ts +0 -48
  55. package/dist/resources/products/product.type.d.ts.map +0 -1
  56. package/dist/resources/products/product.type.js +0 -2
  57. package/dist/resources/products/product.type.js.map +0 -1
  58. package/dist/resources/products/product.util.d.ts +0 -15
  59. package/dist/resources/products/product.util.d.ts.map +0 -1
  60. package/dist/resources/products/product.util.js +0 -56
  61. package/dist/resources/products/product.util.js.map +0 -1
  62. package/dist/resources/products/products.d.ts +0 -9
  63. package/dist/resources/products/products.d.ts.map +0 -1
  64. package/dist/resources/products/products.js +0 -40
  65. package/dist/resources/products/products.js.map +0 -1
  66. package/dist/version.d.ts +0 -2
  67. package/dist/version.d.ts.map +0 -1
  68. package/dist/version.js +0 -2
  69. package/dist/version.js.map +0 -1
@@ -0,0 +1,206 @@
1
+ type QueryValue = string | number | string[] | number[] | undefined;
2
+ type QueryParams = Record<string, QueryValue>;
3
+ interface RequestArgs {
4
+ path: string;
5
+ query?: QueryParams;
6
+ context: string;
7
+ }
8
+
9
+ declare abstract class APIResource {
10
+ protected _client: KeepaClient;
11
+ constructor(client: KeepaClient);
12
+ }
13
+
14
+ declare const MARKETPLACE_DOMAINS: {
15
+ readonly US: 1;
16
+ readonly GB: 2;
17
+ readonly DE: 3;
18
+ readonly FR: 4;
19
+ readonly JP: 5;
20
+ readonly CA: 6;
21
+ readonly IT: 8;
22
+ readonly ES: 9;
23
+ readonly IN: 10;
24
+ readonly MX: 11;
25
+ readonly BR: 12;
26
+ };
27
+ type Marketplace = keyof typeof MARKETPLACE_DOMAINS;
28
+ type DomainId = (typeof MARKETPLACE_DOMAINS)[Marketplace];
29
+ declare function resolveDomainId(marketplace: string | undefined): DomainId;
30
+
31
+ interface ProductRequestOptions {
32
+ /** Case-insensitive at runtime. Defaults to 'US'. */
33
+ marketplace?: Marketplace;
34
+ /** Defaults to 1. */
35
+ days?: number;
36
+ /** When true, populates `history.price.*` and the scalar `price` / `listPrice`
37
+ * fields on each returned product. Increases token cost. */
38
+ history?: boolean;
39
+ }
40
+ interface ProductListParams extends ProductRequestOptions {
41
+ asins: string[];
42
+ }
43
+ interface ProductRetrieveParams extends ProductRequestOptions {
44
+ asin: string;
45
+ }
46
+ interface KeepaCategoryNode {
47
+ catId: number;
48
+ name: string;
49
+ }
50
+ interface KeepaVariationAttribute {
51
+ dimension: string;
52
+ value: string;
53
+ }
54
+ interface KeepaVariation {
55
+ asin: string;
56
+ attributes?: KeepaVariationAttribute[];
57
+ }
58
+ interface PriceHistoryEntry {
59
+ timestamp: Date;
60
+ /** Marketplace's major unit — dollars for US, pounds for GB, yen for JP, etc. */
61
+ price: number;
62
+ }
63
+ /** Flag-gated fields (`price`, `listPrice`, `history.price.*`) are always present
64
+ * on the type and default to empty/null when the corresponding request flag
65
+ * wasn't set. */
66
+ interface KeepaProduct {
67
+ asin: string;
68
+ title?: string;
69
+ description?: string;
70
+ parentAsin?: string;
71
+ categoryTree?: KeepaCategoryNode[];
72
+ rootCategory?: number;
73
+ salesRanks?: Record<string, number[]>;
74
+ variations?: KeepaVariation[];
75
+ features?: string[];
76
+ images: string[];
77
+ /** Null when missing or every history entry is Keepa's `-1` no-data sentinel. */
78
+ bsr: number | null;
79
+ /** Latest entry from `history.price.amazon`; null when history wasn't
80
+ * requested or Keepa has no data. Marketplace's major unit. */
81
+ price: number | null;
82
+ /** Latest entry from `history.price.list`; null when unavailable.
83
+ * Marketplace's major unit. */
84
+ listPrice: number | null;
85
+ history: {
86
+ price: {
87
+ /** Empty when `history: false`. Sentinel-filtered. */
88
+ amazon: PriceHistoryEntry[];
89
+ /** Empty when `history: false`. Sentinel-filtered. */
90
+ list: PriceHistoryEntry[];
91
+ };
92
+ };
93
+ }
94
+
95
+ declare class Products extends APIResource {
96
+ list(params: ProductListParams): Promise<KeepaProduct[]>;
97
+ /** Throws `ProductNotFoundError` when Keepa returns no product or a stub. */
98
+ retrieve(params: ProductRetrieveParams): Promise<KeepaProduct>;
99
+ }
100
+
101
+ interface ClientOptions {
102
+ /** Falls back to `process.env.KEEPA_API_KEY` when omitted. */
103
+ apiKey?: string;
104
+ baseURL?: string;
105
+ fetch?: typeof globalThis.fetch;
106
+ }
107
+ declare class KeepaClient {
108
+ readonly apiKey: string;
109
+ readonly baseURL: string;
110
+ readonly fetch: typeof globalThis.fetch;
111
+ readonly products: Products;
112
+ constructor(options?: ClientOptions);
113
+ _request<T>(args: RequestArgs): Promise<T>;
114
+ }
115
+
116
+ declare class KeepaError extends Error {
117
+ constructor(message: string);
118
+ }
119
+ declare class APIError extends KeepaError {
120
+ readonly status: number;
121
+ readonly context: string;
122
+ readonly body: string;
123
+ constructor(status: number, context: string, body: string, message?: string);
124
+ static from(response: Response, context: string): Promise<APIError>;
125
+ }
126
+ declare class RateLimitError extends APIError {
127
+ constructor(context: string, body: string);
128
+ }
129
+ declare class AuthenticationError extends APIError {
130
+ constructor(context: string, body: string);
131
+ }
132
+ declare class NetworkError extends KeepaError {
133
+ readonly context: string;
134
+ readonly cause: unknown;
135
+ constructor(context: string, cause: unknown);
136
+ }
137
+
138
+ declare const ASIN_LENGTH = 10;
139
+ declare const ASIN_REGEX: RegExp;
140
+ /** Structural check only — a passing ASIN may still not exist in Keepa's
141
+ * database; use `isFoundProduct` for that. */
142
+ declare function isValidAsin(value: string): boolean;
143
+ declare function normalizeAsins(asins: string[]): string[];
144
+
145
+ declare function parsePriceHistory(series: number[] | undefined): PriceHistoryEntry[];
146
+ /** Stubs for unknown ASINs come back with `title: null`. */
147
+ declare function isFoundProduct(product: KeepaProduct): boolean;
148
+ /** Latest non-sentinel rank from Keepa's `[ts, rank, ts, rank, ...]` salesRanks
149
+ * series for the product's rootCategory. */
150
+ declare function extractBsr(salesRanks: Record<string, number[]> | undefined, rootCategory: number | undefined): number | null;
151
+
152
+ /** Thrown when Keepa returns no product, or returns a stub (title === null).
153
+ * `asin` carries the caller's original input unchanged. */
154
+ declare class ProductNotFoundError extends KeepaError {
155
+ readonly asin: string;
156
+ constructor(asin: string);
157
+ }
158
+
159
+ declare const PRODUCT_PATH = "/product";
160
+ declare const PRODUCT_LIST_CONTEXT = "products.list";
161
+ declare const DEFAULT_DAYS = 1;
162
+ declare const AMAZON_IMAGE_BASE = "https://m.media-amazon.com/images/I";
163
+ declare const KEEPA_NO_DATA_SENTINEL = -1;
164
+ declare const CsvType: {
165
+ readonly AMAZON: 0;
166
+ readonly NEW: 1;
167
+ readonly USED: 2;
168
+ readonly SALES: 3;
169
+ readonly LISTPRICE: 4;
170
+ readonly COLLECTIBLE: 5;
171
+ readonly REFURBISHED: 6;
172
+ readonly NEW_FBM_SHIPPING: 7;
173
+ readonly LIGHTNING_DEAL: 8;
174
+ readonly WAREHOUSE: 9;
175
+ readonly NEW_FBA: 10;
176
+ readonly COUNT_NEW: 11;
177
+ readonly COUNT_USED: 12;
178
+ readonly COUNT_REFURBISHED: 13;
179
+ readonly COUNT_COLLECTIBLE: 14;
180
+ readonly EXTRA_INFO_UPDATES: 15;
181
+ readonly RATING: 16;
182
+ readonly COUNT_REVIEWS: 17;
183
+ readonly BUY_BOX_SHIPPING: 18;
184
+ readonly USED_NEW_SHIPPING: 19;
185
+ readonly USED_VERY_GOOD_SHIPPING: 20;
186
+ readonly USED_GOOD_SHIPPING: 21;
187
+ readonly USED_ACCEPTABLE_SHIPPING: 22;
188
+ readonly COLLECTIBLE_NEW_SHIPPING: 23;
189
+ readonly COLLECTIBLE_VERY_GOOD_SHIPPING: 24;
190
+ readonly COLLECTIBLE_GOOD_SHIPPING: 25;
191
+ readonly COLLECTIBLE_ACCEPTABLE_SHIPPING: 26;
192
+ readonly REFURBISHED_SHIPPING: 27;
193
+ readonly EBAY_NEW_SHIPPING: 28;
194
+ readonly EBAY_USED_SHIPPING: 29;
195
+ readonly TRADE_IN: 30;
196
+ readonly RENTAL: 31;
197
+ readonly BUY_BOX_USED_SHIPPING: 32;
198
+ readonly PRIME_EXCL: 33;
199
+ readonly COUNT_NEW_FBA: 34;
200
+ readonly COUNT_NEW_FBM: 35;
201
+ };
202
+ type CsvType = (typeof CsvType)[keyof typeof CsvType];
203
+
204
+ declare const VERSION = "0.1.0";
205
+
206
+ export { AMAZON_IMAGE_BASE, APIError, APIResource, ASIN_LENGTH, ASIN_REGEX, AuthenticationError, type ClientOptions, CsvType, DEFAULT_DAYS, type DomainId, KEEPA_NO_DATA_SENTINEL, type KeepaCategoryNode, KeepaClient, KeepaError, type KeepaProduct, type KeepaVariation, type KeepaVariationAttribute, MARKETPLACE_DOMAINS, type Marketplace, NetworkError, PRODUCT_LIST_CONTEXT, PRODUCT_PATH, type PriceHistoryEntry, type ProductListParams, ProductNotFoundError, type ProductRequestOptions, type ProductRetrieveParams, Products, RateLimitError, VERSION, KeepaClient as default, extractBsr, isFoundProduct, isValidAsin, normalizeAsins, parsePriceHistory, resolveDomainId };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,206 @@
1
- export { KeepaClient as default, KeepaClient, type ClientOptions } from './client.js';
2
- export { KeepaError, APIError, RateLimitError, AuthenticationError, NetworkError, } from './core/error.js';
3
- export { APIResource } from './core/resource.js';
4
- export { MARKETPLACE_DOMAINS, resolveDomainId, type Marketplace, type DomainId, } from './lib/marketplace.js';
5
- export { ASIN_LENGTH, ASIN_REGEX, isValidAsin, normalizeAsins, } from './lib/asin.js';
6
- export * from './resources/index.js';
7
- export { VERSION } from './version.js';
8
- //# sourceMappingURL=index.d.ts.map
1
+ type QueryValue = string | number | string[] | number[] | undefined;
2
+ type QueryParams = Record<string, QueryValue>;
3
+ interface RequestArgs {
4
+ path: string;
5
+ query?: QueryParams;
6
+ context: string;
7
+ }
8
+
9
+ declare abstract class APIResource {
10
+ protected _client: KeepaClient;
11
+ constructor(client: KeepaClient);
12
+ }
13
+
14
+ declare const MARKETPLACE_DOMAINS: {
15
+ readonly US: 1;
16
+ readonly GB: 2;
17
+ readonly DE: 3;
18
+ readonly FR: 4;
19
+ readonly JP: 5;
20
+ readonly CA: 6;
21
+ readonly IT: 8;
22
+ readonly ES: 9;
23
+ readonly IN: 10;
24
+ readonly MX: 11;
25
+ readonly BR: 12;
26
+ };
27
+ type Marketplace = keyof typeof MARKETPLACE_DOMAINS;
28
+ type DomainId = (typeof MARKETPLACE_DOMAINS)[Marketplace];
29
+ declare function resolveDomainId(marketplace: string | undefined): DomainId;
30
+
31
+ interface ProductRequestOptions {
32
+ /** Case-insensitive at runtime. Defaults to 'US'. */
33
+ marketplace?: Marketplace;
34
+ /** Defaults to 1. */
35
+ days?: number;
36
+ /** When true, populates `history.price.*` and the scalar `price` / `listPrice`
37
+ * fields on each returned product. Increases token cost. */
38
+ history?: boolean;
39
+ }
40
+ interface ProductListParams extends ProductRequestOptions {
41
+ asins: string[];
42
+ }
43
+ interface ProductRetrieveParams extends ProductRequestOptions {
44
+ asin: string;
45
+ }
46
+ interface KeepaCategoryNode {
47
+ catId: number;
48
+ name: string;
49
+ }
50
+ interface KeepaVariationAttribute {
51
+ dimension: string;
52
+ value: string;
53
+ }
54
+ interface KeepaVariation {
55
+ asin: string;
56
+ attributes?: KeepaVariationAttribute[];
57
+ }
58
+ interface PriceHistoryEntry {
59
+ timestamp: Date;
60
+ /** Marketplace's major unit — dollars for US, pounds for GB, yen for JP, etc. */
61
+ price: number;
62
+ }
63
+ /** Flag-gated fields (`price`, `listPrice`, `history.price.*`) are always present
64
+ * on the type and default to empty/null when the corresponding request flag
65
+ * wasn't set. */
66
+ interface KeepaProduct {
67
+ asin: string;
68
+ title?: string;
69
+ description?: string;
70
+ parentAsin?: string;
71
+ categoryTree?: KeepaCategoryNode[];
72
+ rootCategory?: number;
73
+ salesRanks?: Record<string, number[]>;
74
+ variations?: KeepaVariation[];
75
+ features?: string[];
76
+ images: string[];
77
+ /** Null when missing or every history entry is Keepa's `-1` no-data sentinel. */
78
+ bsr: number | null;
79
+ /** Latest entry from `history.price.amazon`; null when history wasn't
80
+ * requested or Keepa has no data. Marketplace's major unit. */
81
+ price: number | null;
82
+ /** Latest entry from `history.price.list`; null when unavailable.
83
+ * Marketplace's major unit. */
84
+ listPrice: number | null;
85
+ history: {
86
+ price: {
87
+ /** Empty when `history: false`. Sentinel-filtered. */
88
+ amazon: PriceHistoryEntry[];
89
+ /** Empty when `history: false`. Sentinel-filtered. */
90
+ list: PriceHistoryEntry[];
91
+ };
92
+ };
93
+ }
94
+
95
+ declare class Products extends APIResource {
96
+ list(params: ProductListParams): Promise<KeepaProduct[]>;
97
+ /** Throws `ProductNotFoundError` when Keepa returns no product or a stub. */
98
+ retrieve(params: ProductRetrieveParams): Promise<KeepaProduct>;
99
+ }
100
+
101
+ interface ClientOptions {
102
+ /** Falls back to `process.env.KEEPA_API_KEY` when omitted. */
103
+ apiKey?: string;
104
+ baseURL?: string;
105
+ fetch?: typeof globalThis.fetch;
106
+ }
107
+ declare class KeepaClient {
108
+ readonly apiKey: string;
109
+ readonly baseURL: string;
110
+ readonly fetch: typeof globalThis.fetch;
111
+ readonly products: Products;
112
+ constructor(options?: ClientOptions);
113
+ _request<T>(args: RequestArgs): Promise<T>;
114
+ }
115
+
116
+ declare class KeepaError extends Error {
117
+ constructor(message: string);
118
+ }
119
+ declare class APIError extends KeepaError {
120
+ readonly status: number;
121
+ readonly context: string;
122
+ readonly body: string;
123
+ constructor(status: number, context: string, body: string, message?: string);
124
+ static from(response: Response, context: string): Promise<APIError>;
125
+ }
126
+ declare class RateLimitError extends APIError {
127
+ constructor(context: string, body: string);
128
+ }
129
+ declare class AuthenticationError extends APIError {
130
+ constructor(context: string, body: string);
131
+ }
132
+ declare class NetworkError extends KeepaError {
133
+ readonly context: string;
134
+ readonly cause: unknown;
135
+ constructor(context: string, cause: unknown);
136
+ }
137
+
138
+ declare const ASIN_LENGTH = 10;
139
+ declare const ASIN_REGEX: RegExp;
140
+ /** Structural check only — a passing ASIN may still not exist in Keepa's
141
+ * database; use `isFoundProduct` for that. */
142
+ declare function isValidAsin(value: string): boolean;
143
+ declare function normalizeAsins(asins: string[]): string[];
144
+
145
+ declare function parsePriceHistory(series: number[] | undefined): PriceHistoryEntry[];
146
+ /** Stubs for unknown ASINs come back with `title: null`. */
147
+ declare function isFoundProduct(product: KeepaProduct): boolean;
148
+ /** Latest non-sentinel rank from Keepa's `[ts, rank, ts, rank, ...]` salesRanks
149
+ * series for the product's rootCategory. */
150
+ declare function extractBsr(salesRanks: Record<string, number[]> | undefined, rootCategory: number | undefined): number | null;
151
+
152
+ /** Thrown when Keepa returns no product, or returns a stub (title === null).
153
+ * `asin` carries the caller's original input unchanged. */
154
+ declare class ProductNotFoundError extends KeepaError {
155
+ readonly asin: string;
156
+ constructor(asin: string);
157
+ }
158
+
159
+ declare const PRODUCT_PATH = "/product";
160
+ declare const PRODUCT_LIST_CONTEXT = "products.list";
161
+ declare const DEFAULT_DAYS = 1;
162
+ declare const AMAZON_IMAGE_BASE = "https://m.media-amazon.com/images/I";
163
+ declare const KEEPA_NO_DATA_SENTINEL = -1;
164
+ declare const CsvType: {
165
+ readonly AMAZON: 0;
166
+ readonly NEW: 1;
167
+ readonly USED: 2;
168
+ readonly SALES: 3;
169
+ readonly LISTPRICE: 4;
170
+ readonly COLLECTIBLE: 5;
171
+ readonly REFURBISHED: 6;
172
+ readonly NEW_FBM_SHIPPING: 7;
173
+ readonly LIGHTNING_DEAL: 8;
174
+ readonly WAREHOUSE: 9;
175
+ readonly NEW_FBA: 10;
176
+ readonly COUNT_NEW: 11;
177
+ readonly COUNT_USED: 12;
178
+ readonly COUNT_REFURBISHED: 13;
179
+ readonly COUNT_COLLECTIBLE: 14;
180
+ readonly EXTRA_INFO_UPDATES: 15;
181
+ readonly RATING: 16;
182
+ readonly COUNT_REVIEWS: 17;
183
+ readonly BUY_BOX_SHIPPING: 18;
184
+ readonly USED_NEW_SHIPPING: 19;
185
+ readonly USED_VERY_GOOD_SHIPPING: 20;
186
+ readonly USED_GOOD_SHIPPING: 21;
187
+ readonly USED_ACCEPTABLE_SHIPPING: 22;
188
+ readonly COLLECTIBLE_NEW_SHIPPING: 23;
189
+ readonly COLLECTIBLE_VERY_GOOD_SHIPPING: 24;
190
+ readonly COLLECTIBLE_GOOD_SHIPPING: 25;
191
+ readonly COLLECTIBLE_ACCEPTABLE_SHIPPING: 26;
192
+ readonly REFURBISHED_SHIPPING: 27;
193
+ readonly EBAY_NEW_SHIPPING: 28;
194
+ readonly EBAY_USED_SHIPPING: 29;
195
+ readonly TRADE_IN: 30;
196
+ readonly RENTAL: 31;
197
+ readonly BUY_BOX_USED_SHIPPING: 32;
198
+ readonly PRIME_EXCL: 33;
199
+ readonly COUNT_NEW_FBA: 34;
200
+ readonly COUNT_NEW_FBM: 35;
201
+ };
202
+ type CsvType = (typeof CsvType)[keyof typeof CsvType];
203
+
204
+ declare const VERSION = "0.1.0";
205
+
206
+ export { AMAZON_IMAGE_BASE, APIError, APIResource, ASIN_LENGTH, ASIN_REGEX, AuthenticationError, type ClientOptions, CsvType, DEFAULT_DAYS, type DomainId, KEEPA_NO_DATA_SENTINEL, type KeepaCategoryNode, KeepaClient, KeepaError, type KeepaProduct, type KeepaVariation, type KeepaVariationAttribute, MARKETPLACE_DOMAINS, type Marketplace, NetworkError, PRODUCT_LIST_CONTEXT, PRODUCT_PATH, type PriceHistoryEntry, type ProductListParams, ProductNotFoundError, type ProductRequestOptions, type ProductRetrieveParams, Products, RateLimitError, VERSION, KeepaClient as default, extractBsr, isFoundProduct, isValidAsin, normalizeAsins, parsePriceHistory, resolveDomainId };