@attlaz/client 1.132.0 → 1.133.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.
@@ -0,0 +1,13 @@
1
+ import { ApiRecord } from '../../Model/ApiRecord.js';
2
+ import { CatalogProductWithMatches } from './CatalogProductWithMatches.js';
3
+ import { MarketPosition } from './MarketPosition.js';
4
+ /**
5
+ * One own product — `/pulse/catalogs/:catalogId/products/:catalogProductId`: the same product a
6
+ * Products list row carries, plus its market position (null before the first recompute).
7
+ */
8
+ export declare class CatalogProductDetail {
9
+ readonly product: CatalogProductWithMatches;
10
+ readonly marketPosition: MarketPosition | null;
11
+ constructor(product: CatalogProductWithMatches, marketPosition: MarketPosition | null);
12
+ static parse(raw: ApiRecord): CatalogProductDetail;
13
+ }
@@ -0,0 +1,18 @@
1
+ import { CatalogProductWithMatches } from './CatalogProductWithMatches.js';
2
+ import { MarketPosition } from './MarketPosition.js';
3
+ /**
4
+ * One own product — `/pulse/catalogs/:catalogId/products/:catalogProductId`: the same product a
5
+ * Products list row carries, plus its market position (null before the first recompute).
6
+ */
7
+ export class CatalogProductDetail {
8
+ product;
9
+ marketPosition;
10
+ constructor(product, marketPosition) {
11
+ this.product = product;
12
+ this.marketPosition = marketPosition;
13
+ }
14
+ static parse(raw) {
15
+ const position = raw.market_position ?? null;
16
+ return new CatalogProductDetail(CatalogProductWithMatches.parse(raw), position === null ? null : MarketPosition.parse(position));
17
+ }
18
+ }
@@ -14,20 +14,32 @@ export type PriceProposal = {
14
14
  * the caller, since what counts as margin differs per client.
15
15
  */
16
16
  export declare class CatalogProductWithMatches {
17
+ /** The own vendor product's id. */
17
18
  id: string;
19
+ /** This product in this catalog; null when the vendor product was never added to the catalog. */
20
+ catalogProductId: string | null;
18
21
  name: string;
22
+ sku: string | null;
19
23
  image: string | null;
20
24
  gtin: string | null;
21
25
  brand: string | null;
22
26
  url: string | null;
23
27
  price: number;
28
+ /** The price before a promotion; null when not on promotion. */
29
+ originalPrice: number | null;
30
+ currency: string | null;
24
31
  costPrice: number | null;
32
+ /** Market median from the last recompute, the figure every other view uses; null before one. */
33
+ medianCompetitorPrice: number | null;
25
34
  priceProposal: PriceProposal | null;
26
35
  matches: MatchedVendorProduct[];
27
36
  constructor(id: string);
28
37
  /** The matches a comparison rests on — every match except the unconfirmed suggestions. */
29
38
  get countedMatches(): MatchedVendorProduct[];
30
- /** Mean price of the counted competitor products; null when none is counted. */
39
+ /**
40
+ * Mean price of the counted competitor products; null when none is counted.
41
+ * @deprecated Ignores stock, zero prices and one-per-shop; use `medianCompetitorPrice`.
42
+ */
31
43
  get matchesAveragePrice(): number | null;
32
44
  static parse(raw: ApiRecord): CatalogProductWithMatches;
33
45
  }
@@ -7,14 +7,23 @@ import { MatchedVendorProduct } from './MatchedVendorProduct.js';
7
7
  * the caller, since what counts as margin differs per client.
8
8
  */
9
9
  export class CatalogProductWithMatches {
10
+ /** The own vendor product's id. */
10
11
  id;
12
+ /** This product in this catalog; null when the vendor product was never added to the catalog. */
13
+ catalogProductId = null;
11
14
  name = '';
15
+ sku = null;
12
16
  image = null;
13
17
  gtin = null;
14
18
  brand = null;
15
19
  url = null;
16
20
  price = 0;
21
+ /** The price before a promotion; null when not on promotion. */
22
+ originalPrice = null;
23
+ currency = null;
17
24
  costPrice = null;
25
+ /** Market median from the last recompute, the figure every other view uses; null before one. */
26
+ medianCompetitorPrice = null;
18
27
  priceProposal = null;
19
28
  matches = [];
20
29
  constructor(id) {
@@ -24,7 +33,10 @@ export class CatalogProductWithMatches {
24
33
  get countedMatches() {
25
34
  return this.matches.filter((match) => !match.isUnconfirmed);
26
35
  }
27
- /** Mean price of the counted competitor products; null when none is counted. */
36
+ /**
37
+ * Mean price of the counted competitor products; null when none is counted.
38
+ * @deprecated Ignores stock, zero prices and one-per-shop; use `medianCompetitorPrice`.
39
+ */
28
40
  get matchesAveragePrice() {
29
41
  const counted = this.countedMatches;
30
42
  if (counted.length === 0) {
@@ -35,13 +47,18 @@ export class CatalogProductWithMatches {
35
47
  }
36
48
  static parse(raw) {
37
49
  const product = new CatalogProductWithMatches(raw.id);
50
+ product.catalogProductId = raw.catalog_product ?? null;
38
51
  product.name = raw.name ?? '';
52
+ product.sku = raw.sku ?? null;
53
+ product.originalPrice = raw.original_price === null || raw.original_price === undefined ? null : Number(raw.original_price);
54
+ product.currency = raw.currency ?? null;
39
55
  product.image = raw.image ?? null;
40
56
  product.gtin = raw.gtin ?? null;
41
57
  product.brand = raw.brand ?? null;
42
58
  product.url = raw.url ?? null;
43
59
  product.price = parseFloat(raw.price) || 0;
44
60
  product.costPrice = raw.cost_price ?? null;
61
+ product.medianCompetitorPrice = raw.median_competitor_price === null || raw.median_competitor_price === undefined ? null : Number(raw.median_competitor_price);
45
62
  const proposal = raw.price_proposal ?? null;
46
63
  product.priceProposal = proposal === null ? null : {
47
64
  price: proposal.price,
@@ -0,0 +1,26 @@
1
+ import { ApiRecord } from '../../Model/ApiRecord.js';
2
+ import { PositionBucket } from './PositionBucket.js';
3
+ /**
4
+ * One product against the market, as stored by the last recompute (`computedAt`) — not live. The
5
+ * competitor figures cover the counted competitors only: accepted, in stock, priced, one per shop.
6
+ */
7
+ export declare class MarketPosition {
8
+ catalogProductId: string;
9
+ computedAt: Date;
10
+ cheapestCompetitorPrice: number | null;
11
+ averageCompetitorPrice: number | null;
12
+ /** The reference price `positionBucket` is derived from. */
13
+ medianCompetitorPrice: number | null;
14
+ mostExpensiveCompetitorPrice: number | null;
15
+ priceVsCheapestPct: number | null;
16
+ priceVsAveragePct: number | null;
17
+ /** Null means the gap was too wide to represent, never zero. Do not render it as a number. */
18
+ priceVsMedianPct: number | null;
19
+ /** 1 is the cheapest of us and the counted competitors. */
20
+ rank: number | null;
21
+ competitorCount: number;
22
+ positionBucket: PositionBucket | null;
23
+ marginPct: number | null;
24
+ hasActivePromotion: boolean;
25
+ static parse(raw: ApiRecord): MarketPosition;
26
+ }
@@ -0,0 +1,42 @@
1
+ const nullableNumber = (value) => value === null || value === undefined ? null : Number(value);
2
+ /**
3
+ * One product against the market, as stored by the last recompute (`computedAt`) — not live. The
4
+ * competitor figures cover the counted competitors only: accepted, in stock, priced, one per shop.
5
+ */
6
+ export class MarketPosition {
7
+ catalogProductId;
8
+ computedAt;
9
+ cheapestCompetitorPrice = null;
10
+ averageCompetitorPrice = null;
11
+ /** The reference price `positionBucket` is derived from. */
12
+ medianCompetitorPrice = null;
13
+ mostExpensiveCompetitorPrice = null;
14
+ priceVsCheapestPct = null;
15
+ priceVsAveragePct = null;
16
+ /** Null means the gap was too wide to represent, never zero. Do not render it as a number. */
17
+ priceVsMedianPct = null;
18
+ /** 1 is the cheapest of us and the counted competitors. */
19
+ rank = null;
20
+ competitorCount = 0;
21
+ positionBucket = null;
22
+ marginPct = null;
23
+ hasActivePromotion = false;
24
+ static parse(raw) {
25
+ const position = new MarketPosition();
26
+ position.catalogProductId = raw.catalog_product;
27
+ position.computedAt = new Date(raw.computed_at);
28
+ position.cheapestCompetitorPrice = nullableNumber(raw.cheapest_competitor_price);
29
+ position.averageCompetitorPrice = nullableNumber(raw.average_competitor_price);
30
+ position.medianCompetitorPrice = nullableNumber(raw.median_competitor_price);
31
+ position.mostExpensiveCompetitorPrice = nullableNumber(raw.most_expensive_competitor_price);
32
+ position.priceVsCheapestPct = nullableNumber(raw.price_vs_cheapest_pct);
33
+ position.priceVsAveragePct = nullableNumber(raw.price_vs_average_pct);
34
+ position.priceVsMedianPct = nullableNumber(raw.price_vs_median_pct);
35
+ position.rank = nullableNumber(raw.rank);
36
+ position.competitorCount = Number(raw.competitor_count ?? 0);
37
+ position.positionBucket = raw.position_bucket ?? null;
38
+ position.marginPct = nullableNumber(raw.margin_pct);
39
+ position.hasActivePromotion = raw.has_active_promotion === true;
40
+ return position;
41
+ }
42
+ }
@@ -3,6 +3,7 @@ import { FilterNode } from '../../Model/Filter/FilterNode.js';
3
3
  import { CursorPagination } from '../../Model/Pagination/CursorPagination.js';
4
4
  import { CollectionResult } from '../../Model/Result/CollectionResult.js';
5
5
  import { Endpoint } from '../../Service/Endpoint.js';
6
+ import { CatalogProductDetail } from '../Model/CatalogProductDetail.js';
6
7
  import { CatalogProductWithMatches } from '../Model/CatalogProductWithMatches.js';
7
8
  import { PulseCatalogProductFilterOptions } from '../Model/PulseCatalogProductFilterOptions.js';
8
9
  import { PulseCatalogProductFilters } from '../Model/PulseCatalogProductFilters.js';
@@ -18,6 +19,8 @@ export declare class PulseCatalogProductEndpoint extends Endpoint {
18
19
  * anything the simple filters cannot express.
19
20
  */
20
21
  getProducts(catalogId: CatalogId | string, pagination?: CursorPagination | null, filters?: PulseCatalogProductFilters, filter?: FilterNode | null): Promise<CollectionResult<CatalogProductWithMatches>>;
22
+ /** One product with its matches and market position; null when it is not in this catalog. */
23
+ getProduct(catalogId: CatalogId | string, catalogProductId: string, includePending?: boolean): Promise<CatalogProductDetail | null>;
21
24
  getFilterOptions(catalogId: CatalogId | string): Promise<PulseCatalogProductFilterOptions>;
22
25
  /** Recalculate the catalog's cached statistics (price index, match counts, segments). */
23
26
  recomputeStatistics(catalogId: CatalogId | string): Promise<void>;
@@ -1,6 +1,7 @@
1
1
  import { path } from '../../Http/Data/Path.js';
2
2
  import { QueryString } from '../../Http/Data/QueryString.js';
3
3
  import { Endpoint } from '../../Service/Endpoint.js';
4
+ import { CatalogProductDetail } from '../Model/CatalogProductDetail.js';
4
5
  import { CatalogProductWithMatches } from '../Model/CatalogProductWithMatches.js';
5
6
  /**
6
7
  * A catalog's own products as Market Pulse sees them — with the competitor products matched to
@@ -45,6 +46,18 @@ export class PulseCatalogProductEndpoint extends Endpoint {
45
46
  queryString.addPagination(pagination);
46
47
  return await this.requestCollection(queryString, CatalogProductWithMatches.parse);
47
48
  }
49
+ /** One product with its matches and market position; null when it is not in this catalog. */
50
+ async getProduct(catalogId, catalogProductId, includePending = false) {
51
+ const queryString = new QueryString(path('/pulse/catalogs/:catalogId/products/:catalogProductId', {
52
+ catalogId: catalogId.toString(),
53
+ catalogProductId,
54
+ }));
55
+ if (includePending) {
56
+ queryString.set('include_pending', 'true');
57
+ }
58
+ const result = await this.requestObject(queryString, null, CatalogProductDetail.parse, 'GET');
59
+ return result.getData();
60
+ }
48
61
  async getFilterOptions(catalogId) {
49
62
  const result = await this.requestObject(path('/pulse/catalogs/:catalogId/filter-options', { catalogId: catalogId.toString() }), null, (raw) => ({
50
63
  brands: raw.brands ?? [],
package/dist/index.d.ts CHANGED
@@ -106,6 +106,8 @@ export { Competitor } from './MarketPulse/Model/Competitor.js';
106
106
  export { ProductMatch, ProductMatchStatus } from './MarketPulse/Model/ProductMatch.js';
107
107
  export { MatchedVendorProduct } from './MarketPulse/Model/MatchedVendorProduct.js';
108
108
  export { CatalogProductWithMatches, PriceProposal } from './MarketPulse/Model/CatalogProductWithMatches.js';
109
+ export { CatalogProductDetail } from './MarketPulse/Model/CatalogProductDetail.js';
110
+ export { MarketPosition } from './MarketPulse/Model/MarketPosition.js';
109
111
  export { ReviewMatch, ReviewProduct, ReviewCompetitorProduct } from './MarketPulse/Model/ReviewMatch.js';
110
112
  export { TopCompetitor } from './MarketPulse/Model/TopCompetitor.js';
111
113
  export { PriceIndexSnapshotEntry } from './MarketPulse/Model/PriceIndexSnapshotEntry.js';
package/dist/index.js CHANGED
@@ -90,6 +90,8 @@ export { Competitor } from './MarketPulse/Model/Competitor.js';
90
90
  export { ProductMatch } from './MarketPulse/Model/ProductMatch.js';
91
91
  export { MatchedVendorProduct } from './MarketPulse/Model/MatchedVendorProduct.js';
92
92
  export { CatalogProductWithMatches } from './MarketPulse/Model/CatalogProductWithMatches.js';
93
+ export { CatalogProductDetail } from './MarketPulse/Model/CatalogProductDetail.js';
94
+ export { MarketPosition } from './MarketPulse/Model/MarketPosition.js';
93
95
  export { ReviewMatch } from './MarketPulse/Model/ReviewMatch.js';
94
96
  export { TopCompetitor } from './MarketPulse/Model/TopCompetitor.js';
95
97
  export { PriceIndexSnapshotEntry } from './MarketPulse/Model/PriceIndexSnapshotEntry.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@attlaz/client",
3
- "version": "1.132.0",
3
+ "version": "1.133.0",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",
@@ -55,16 +55,16 @@
55
55
  "registry": "https://registry.npmjs.org"
56
56
  },
57
57
  "devDependencies": {
58
- "@types/node": "^26.6.6",
58
+ "@types/node": "^26.6.11",
59
59
  "@typescript/native": "npm:typescript@^7.0.2",
60
- "eslint": "^10.14.0",
60
+ "eslint": "^10.16.0",
61
61
  "eslint-config-attlaz-base": "^1.11.0",
62
62
  "eslint-import-resolver-typescript": "^4.4.5",
63
63
  "eslint-plugin-barrel-files": "^3.0.1",
64
- "eslint-plugin-import-x": "^4.17.1",
64
+ "eslint-plugin-import-x": "^4.18.1",
65
65
  "rimraf": "^6.1.4",
66
66
  "typescript": "npm:@typescript/typescript6@^6.0.2",
67
- "vitest": "^5.1.0"
67
+ "vitest": "^5.1.2"
68
68
  },
69
69
  "directories": {
70
70
  "test": "test"