basketeer 0.1.1 → 0.1.2

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
@@ -141,6 +141,7 @@ The full grocery lifecycle, typed end to end:
141
141
 
142
142
  - **Nutrition** — typed macros and structured micros, normalized from a product's on-pack rows when present; filter and rank a search by nutrition (anonymous)
143
143
  - **Catalogue** — `search`, `getProduct`, `browseCategory` (anonymous); `favourites` / "my usuals" (authed)
144
+ - **Product images** — `imageUrl` on every product/result; `resizeImageUrl(url, { width, height })` for thumbnails (anonymous)
144
145
  - **Basket** — `add`, `set`, `remove`, `get`
145
146
  - **Slots** — delivery and collection: `list` / `book` / `release`
146
147
  - **Orders** — `list`, `amend`, `cancel`, `lastFulfilled` (reorder)
@@ -0,0 +1,5 @@
1
+ export interface ImageSize {
2
+ width: number;
3
+ height: number;
4
+ }
5
+ export declare function resizeImageUrl(imageUrl: string | null, size: ImageSize): string | null;
package/dist/images.js ADDED
@@ -0,0 +1,15 @@
1
+ function assertPositiveInteger(value, name) {
2
+ if (!Number.isInteger(value) || value < 1) {
3
+ throw new RangeError(`${name} must be a positive integer`);
4
+ }
5
+ }
6
+ export function resizeImageUrl(imageUrl, size) {
7
+ if (imageUrl === null)
8
+ return null;
9
+ assertPositiveInteger(size.width, "width");
10
+ assertPositiveInteger(size.height, "height");
11
+ const url = new URL(imageUrl);
12
+ url.searchParams.set("w", String(size.width));
13
+ url.searchParams.set("h", String(size.height));
14
+ return url.toString();
15
+ }
package/dist/index.d.ts CHANGED
@@ -3,6 +3,8 @@ export type { AuthBackend, Credentials, OtpProvider } from "./auth/types.js";
3
3
  export type { Amendment, BasketeerOptions, BasketItemInput } from "./client.js";
4
4
  export { Basketeer } from "./client.js";
5
5
  export { ApiKeyError, AuthExpiredError, BasketeerError, GraphQLRequestError, LineRejectedError, NotFoundError, RateLimitedError, } from "./errors.js";
6
+ export type { ImageSize } from "./images.js";
7
+ export { resizeImageUrl } from "./images.js";
6
8
  export type { Basket, BasketLine, BookedSlot, MacroFilterKey, Macros, Micronutrient, Nutrition, NutritionBasis, NutritionFilter, NutritionSort, Order, OrderAddress, OrderItem, OrderSlot, PackSize, Price, Product, Promotion, Range, SearchPage, SearchResult, Session, Slot, } from "./models.js";
7
9
  export { filterByNutrition, parseNutrition } from "./nutrition.js";
8
10
  export type { FulfilmentType, OrderContext } from "./operations.js";
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ export { keepCookie, sessionFromCookies } from "./auth/harvest.js";
4
4
  export { Basketeer } from "./client.js";
5
5
  // Errors
6
6
  export { ApiKeyError, AuthExpiredError, BasketeerError, GraphQLRequestError, LineRejectedError, NotFoundError, RateLimitedError, } from "./errors.js";
7
+ export { resizeImageUrl } from "./images.js";
7
8
  // Nutrition
8
9
  export { filterByNutrition, parseNutrition } from "./nutrition.js";
9
10
  // Config & helpers
package/dist/models.d.ts CHANGED
@@ -22,6 +22,7 @@ export interface Product {
22
22
  tpnb: string | null;
23
23
  title: string;
24
24
  brand: string | null;
25
+ imageUrl: string | null;
25
26
  price: Price;
26
27
  packSize: PackSize | null;
27
28
  promotions: Promotion[];
@@ -36,6 +37,7 @@ export interface SearchResult {
36
37
  tpnb: string | null;
37
38
  title: string;
38
39
  brand: string | null;
40
+ imageUrl: string | null;
39
41
  price: Price;
40
42
  onOffer: boolean;
41
43
  promotions: Promotion[];
package/dist/parsers.js CHANGED
@@ -43,6 +43,7 @@ export function parseProduct(v) {
43
43
  tpnb: id(node.tpnb),
44
44
  title: str(node.title) ?? "",
45
45
  brand: str(node.brandName),
46
+ imageUrl: str(node.defaultImageUrl),
46
47
  price: parsePrice(node.price),
47
48
  packSize: parsePackSize(details.packSize),
48
49
  promotions: parsePromotions(node.promotions),
@@ -67,6 +68,7 @@ export function parseProductNode(v) {
67
68
  tpnb: id(node.tpnb),
68
69
  title: str(node.title) ?? "",
69
70
  brand: str(node.brandName),
71
+ imageUrl: str(node.defaultImageUrl),
70
72
  price: parsePrice(seller.price),
71
73
  onOffer: promotions.length > 0,
72
74
  promotions,
package/dist/queries.js CHANGED
@@ -5,7 +5,7 @@
5
5
  export const GET_PRODUCT = `
6
6
  query GetProduct($tpnc: String!) {
7
7
  product(tpnc: $tpnc) {
8
- tpnb tpnc title brandName
8
+ tpnb tpnc title brandName defaultImageUrl
9
9
  price { actual unitPrice unitOfMeasure }
10
10
  promotions {
11
11
  description
@@ -28,7 +28,7 @@ query Search($query: String!, $page: Int = 1, $count: Int) {
28
28
  node {
29
29
  __typename
30
30
  ... on ProductInterface {
31
- tpnc tpnb title brandName
31
+ tpnc tpnb title brandName defaultImageUrl
32
32
  sellers {
33
33
  results {
34
34
  price { actual unitPrice unitOfMeasure }
@@ -53,7 +53,7 @@ query GetCategoryProducts($facet: ID, $page: Int = 1, $count: Int) {
53
53
  node {
54
54
  __typename
55
55
  ... on ProductInterface {
56
- tpnc tpnb title brandName
56
+ tpnc tpnb title brandName defaultImageUrl
57
57
  sellers {
58
58
  results {
59
59
  price { actual unitPrice unitOfMeasure }
@@ -71,7 +71,7 @@ query GetFavourites($page: Int = 1, $count: Int, $sortBy: String) {
71
71
  products {
72
72
  __typename
73
73
  ... on ProductInterface {
74
- tpnc tpnb title brandName
74
+ tpnc tpnb title brandName defaultImageUrl
75
75
  sellers {
76
76
  results {
77
77
  price { actual unitPrice unitOfMeasure }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "basketeer",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Typed, pure-HTTP TypeScript SDK for your own Tesco grocery account — search, basket, delivery slots, and orders over plain fetch. Browser only for login + payment.",
5
5
  "type": "module",
6
6
  "license": "MIT",