@attlaz/client 1.89.0 → 1.90.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.
@@ -3,6 +3,8 @@ import { CollectionResult } from '../../Model/Result/CollectionResult.js';
3
3
  import { Endpoint } from '../../Service/Endpoint.js';
4
4
  import { PriceIndexSnapshotEntry } from '../Model/PriceIndexSnapshotEntry.js';
5
5
  import { TopCompetitor } from '../Model/TopCompetitor.js';
6
+ /** Which axis the products are bucketed on. */
7
+ export type ProductSegmentType = 'price' | 'profit';
6
8
  /** How many products fall in a segment now versus the previous period. */
7
9
  export type ProductsSegment = {
8
10
  code: string;
@@ -24,9 +26,19 @@ export declare class PulseStatisticsEndpoint extends Endpoint {
24
26
  /** Headline figures (products tracked, matches, competitors …) against the previous period. */
25
27
  getAccountSummary(catalogId: CatalogId | string): Promise<CollectionResult<MarketSummaryEntry>>;
26
28
  /** Distribution of the catalog's products across price or profit segments. */
27
- getProductSegments(catalogId: CatalogId | string): Promise<CollectionResult<ProductsSegment>>;
28
- /** The competitors with the most matches against this catalog. */
29
- getTopCompetitors(catalogId: CatalogId | string): Promise<CollectionResult<TopCompetitor>>;
30
- /** Price index per competitor over time, for charting. */
31
- getPriceIndexHistory(catalogId: CatalogId | string, competitor?: string | null): Promise<CollectionResult<PriceIndexSnapshotEntry>>;
29
+ getProductSegments(catalogId: CatalogId | string, type?: ProductSegmentType | null): Promise<CollectionResult<ProductsSegment>>;
30
+ /**
31
+ * The competitors with the most matches against this catalog. `period` is the number of days
32
+ * the comparison against the previous period spans.
33
+ */
34
+ getTopCompetitors(catalogId: CatalogId | string, limit?: number | null, period?: number | null): Promise<CollectionResult<TopCompetitor>>;
35
+ /**
36
+ * Price index per competitor over time, for charting. Pass the competitors to include, and
37
+ * optionally a product group to scope to and a date range (`YYYY-MM-DD`).
38
+ */
39
+ getPriceIndexHistory(catalogId: CatalogId | string, competitorIds?: string[], options?: {
40
+ group?: string;
41
+ from?: string;
42
+ to?: string;
43
+ }): Promise<CollectionResult<PriceIndexSnapshotEntry>>;
32
44
  }
@@ -17,22 +17,48 @@ export class PulseStatisticsEndpoint extends Endpoint {
17
17
  }));
18
18
  }
19
19
  /** Distribution of the catalog's products across price or profit segments. */
20
- async getProductSegments(catalogId) {
21
- return await this.requestCollection('/pulse/catalogs/' + catalogId.toString() + '/statistics/product-segments', (raw) => ({
20
+ async getProductSegments(catalogId, type = null) {
21
+ const queryString = new QueryString('/pulse/catalogs/' + catalogId.toString() + '/statistics/product-segments');
22
+ if (type !== null) {
23
+ queryString.set('type', type);
24
+ }
25
+ return await this.requestCollection(queryString, (raw) => ({
22
26
  code: raw.code,
23
27
  current: raw.current ?? 0,
24
28
  previous: raw.previous ?? 0,
25
29
  }));
26
30
  }
27
- /** The competitors with the most matches against this catalog. */
28
- async getTopCompetitors(catalogId) {
29
- return await this.requestCollection('/pulse/catalogs/' + catalogId.toString() + '/statistics/top-competitors', TopCompetitor.parse);
31
+ /**
32
+ * The competitors with the most matches against this catalog. `period` is the number of days
33
+ * the comparison against the previous period spans.
34
+ */
35
+ async getTopCompetitors(catalogId, limit = null, period = null) {
36
+ const queryString = new QueryString('/pulse/catalogs/' + catalogId.toString() + '/statistics/top-competitors');
37
+ if (limit !== null) {
38
+ queryString.set('limit', limit);
39
+ }
40
+ if (period !== null) {
41
+ queryString.set('period', period);
42
+ }
43
+ return await this.requestCollection(queryString, TopCompetitor.parse);
30
44
  }
31
- /** Price index per competitor over time, for charting. */
32
- async getPriceIndexHistory(catalogId, competitor = null) {
45
+ /**
46
+ * Price index per competitor over time, for charting. Pass the competitors to include, and
47
+ * optionally a product group to scope to and a date range (`YYYY-MM-DD`).
48
+ */
49
+ async getPriceIndexHistory(catalogId, competitorIds = [], options = {}) {
33
50
  const queryString = new QueryString('/pulse/catalogs/' + catalogId.toString() + '/statistics/price-index-history');
34
- if (competitor !== null) {
35
- queryString.set('competitor', competitor);
51
+ if (competitorIds.length > 0) {
52
+ queryString.set('competitor', competitorIds.join(','));
53
+ }
54
+ if (options.group) {
55
+ queryString.set('group', options.group);
56
+ }
57
+ if (options.from) {
58
+ queryString.set('from', options.from);
59
+ }
60
+ if (options.to) {
61
+ queryString.set('to', options.to);
36
62
  }
37
63
  return await this.requestCollection(queryString, PriceIndexSnapshotEntry.parse);
38
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@attlaz/client",
3
- "version": "1.89.0",
3
+ "version": "1.90.0",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",