@shushed/helpers 0.0.203 → 0.0.204-main-20251209142954

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.
@@ -62,6 +62,7 @@ class AirtableHelper extends runtime_1.default {
62
62
  fieldsToMergeOn: (options.fieldsToMergeOn ?? [this.primaryKeyFieldName]).map(x => this.dictionary[x] || x),
63
63
  },
64
64
  returnFieldsByFieldId: true,
65
+ typecast: options.typecast || false,
65
66
  records: currentBatch.map(x => {
66
67
  const recordId = x.$recordId;
67
68
  const fieldsWithoutRecordId = { ...x };
@@ -73,6 +73,14 @@ class CentraHelper extends env_1.default {
73
73
  errors.push(...userErrors.map((x) => ({ message: x.message, path: x.path })));
74
74
  return { errors, limitExceeded: response.status === 429 };
75
75
  }
76
+ if (resp.data && typeof resp.data === 'object') {
77
+ for (const key in resp.data) {
78
+ if (resp.data[key] && typeof resp.data[key] === 'object' && 'userErrors' in resp.data[key] && Array.isArray(resp.data[key].userErrors) && resp.data[key].userErrors.length > 0) {
79
+ errors.push(...resp.data[key].userErrors.map((x) => ({ message: x.message, path: x.path })));
80
+ return { errors, limitExceeded: response.status === 429 };
81
+ }
82
+ }
83
+ }
76
84
  }
77
85
  if (response.status === 429) {
78
86
  resp.limitExceeded = true;
@@ -323,7 +331,7 @@ class CentraHelper extends env_1.default {
323
331
  } while (hasNextPage);
324
332
  return result;
325
333
  }
326
- async fetchCentraMarkets(externalIds) {
334
+ async fetchCentraMarkets() {
327
335
  const result = [];
328
336
  const limit = 200;
329
337
  let page = 0;
@@ -333,15 +341,15 @@ class CentraHelper extends env_1.default {
333
341
  method: 'POST',
334
342
  body: JSON.stringify({
335
343
  query: `
336
- query GetMarkets($limit: Int, $page: Int${externalIds ? `, $externalIds: MarketsFilter` : ''}) {
337
- markets(${externalIds ? `where: $externalIds, ` : ''}limit: $limit, page: $page) {
344
+ query GetMarkets($limit: Int, $page: Int) {
345
+ markets(limit: $limit, page: $page) {
338
346
  id
339
347
  externalId
340
348
  name
341
349
  }
342
350
  }
343
351
  `,
344
- variables: { page: page, limit: limit, externalIds: { externalId: externalIds } }
352
+ variables: { page: page, limit: limit }
345
353
  })
346
354
  });
347
355
  if (CentraHelper.isCentraErrors(data)) {
@@ -471,7 +479,7 @@ class CentraHelper extends env_1.default {
471
479
  nextCursor = null;
472
480
  }
473
481
  if (data && data.data?.productConnection?.edges?.length) {
474
- for (let i = data.data.productConnection.edges.length; i < styleIds.length; i++) {
482
+ for (let i = 0; i < data.data.productConnection.edges.length; i++) {
475
483
  const { node } = data.data.productConnection.edges[i];
476
484
  result[node.externalId] = node;
477
485
  }
@@ -497,16 +505,15 @@ class CentraHelper extends env_1.default {
497
505
  edges {
498
506
  node {
499
507
  id
500
- externalId
501
508
  status
502
- url
509
+ uri
503
510
  metaTitle
504
511
  metaDescription
505
512
  name
506
513
  categories {
507
514
  id
508
515
  name
509
- url
516
+ uri
510
517
  isTopCategory
511
518
  }
512
519
  markets {
@@ -518,7 +525,7 @@ class CentraHelper extends env_1.default {
518
525
  externalId
519
526
  status
520
527
  }
521
- productVariant {
528
+ productVariants {
522
529
  id
523
530
  externalId
524
531
  status
@@ -565,8 +572,8 @@ class CentraHelper extends env_1.default {
565
572
  for (let i = 0; i < edges.length; i++) {
566
573
  const { node } = edges[i];
567
574
  if (inputIdType === 'variant') {
568
- result[+node.productVariant[0].id] = [];
569
- result[+node.productVariant[0].id].push(node);
575
+ result[+node.productVariants[0].id] = [];
576
+ result[+node.productVariants[0].id].push(node);
570
577
  }
571
578
  else {
572
579
  result[+node.product.id] = [];
@@ -790,59 +797,45 @@ class CentraHelper extends env_1.default {
790
797
  }
791
798
  return Object.assign({}, pricelistInCache, pricelistToSet);
792
799
  }
793
- async getCentraMarkets(externalIds, alwaysFetch = false) {
794
- if (externalIds && !externalIds.length) {
795
- return {};
796
- }
800
+ async getCentraMarkets(alwaysFetch = false) {
797
801
  let marketInCache = {};
798
- let dedupedExternalIds = [];
802
+ let dedupedMarketNamesInCache = [];
799
803
  let marketsToFetch = null;
800
804
  if (!alwaysFetch) {
801
- if (!externalIds) {
802
- externalIds = (await this.get(this.getCacheKeyForMarkets(), 'env', {
803
- isEphemeral: true,
804
- encrypted: false,
805
- }).then(x => x ? JSON.parse(x) : null));
806
- }
807
- if (externalIds) {
808
- dedupedExternalIds = externalIds.filter((x, index, self) => self.indexOf(x) === index);
809
- marketInCache = Object.fromEntries(Object.entries(await this.get(dedupedExternalIds.map(x => this.getCacheKeyForMarket(x)), 'env', {
805
+ const marketNamesInCache = (await this.get(this.getCacheKeyForMarkets(), 'env', {
806
+ isEphemeral: true,
807
+ encrypted: false,
808
+ }).then(x => x ? JSON.parse(x) : null));
809
+ if (marketNamesInCache) {
810
+ dedupedMarketNamesInCache = marketNamesInCache.filter((x, index, self) => self.indexOf(x) === index);
811
+ marketInCache = Object.fromEntries(Object.entries(await this.get(dedupedMarketNamesInCache.map(x => this.getCacheKeyForMarket(x)), 'env', {
810
812
  isEphemeral: true,
811
813
  encrypted: false,
812
814
  })).map(([key, value]) => [key, value ? JSON.parse(value || 'null') : undefined]).filter(([_, value]) => value));
813
- marketsToFetch = dedupedExternalIds.filter(x => !marketInCache[x]);
815
+ marketsToFetch = dedupedMarketNamesInCache.filter(x => !marketInCache[x]);
814
816
  }
815
817
  }
816
818
  const marketToSet = {};
817
819
  if (!marketsToFetch || marketsToFetch.length) {
818
- const markets = await this.fetchCentraMarkets(marketsToFetch);
820
+ const markets = await this.fetchCentraMarkets();
819
821
  if (CentraHelper.isCentraErrors(markets)) {
820
- if (marketsToFetch) {
821
- for (const marketExternalId of marketsToFetch) {
822
- marketToSet[marketExternalId] = new Error(`Failed to fetch market ${marketExternalId}: ${markets.errors.map((x) => x.message).join(', ')}`);
823
- }
824
- }
825
- else {
826
- return new Error(`Failed to fetch markets: ${markets.errors.map((x) => x.message).join(', ')}`);
827
- }
822
+ return new Error(`Failed to fetch markets: ${markets.errors.map((x) => x.message).join(', ')}`);
828
823
  }
829
824
  else {
830
825
  for (const market of markets) {
831
- marketToSet[market.externalId] = market;
826
+ marketToSet[market.name] = market;
832
827
  }
833
828
  await this.set(Object.entries(marketToSet).filter(([_, value]) => !(value instanceof Error)).map(([key, value]) => ({ name: this.getCacheKeyForMarket(key), value: JSON.stringify(value) })), 'env', {
834
829
  ephemeralMs: CACHE_EXPIRATION_MS,
835
830
  encrypted: false,
836
831
  });
837
- if (!marketsToFetch) {
838
- await this.set([{
839
- name: this.getCacheKeyForMarkets(),
840
- value: JSON.stringify(Object.keys(marketToSet)),
841
- }], 'env', {
842
- ephemeralMs: CACHE_EXPIRATION_MS,
843
- encrypted: false,
844
- });
845
- }
832
+ await this.set([{
833
+ name: this.getCacheKeyForMarkets(),
834
+ value: JSON.stringify(Object.keys(marketToSet)),
835
+ }], 'env', {
836
+ ephemeralMs: CACHE_EXPIRATION_MS,
837
+ encrypted: false,
838
+ });
846
839
  }
847
840
  }
848
841
  return Object.assign({}, marketInCache, marketToSet);
@@ -44,6 +44,7 @@ declare class AirtableHelper<T extends Record<string, string>, K extends keyof T
44
44
  }>, options?: {
45
45
  fieldsToMergeOn?: Array<keyof T>;
46
46
  primaryKeyWritable?: boolean;
47
+ typecast?: boolean;
47
48
  }, callIdx?: number, collectedResult?: {
48
49
  updatedRecords: Array<string>;
49
50
  createdRecords: Array<string>;
@@ -19,19 +19,18 @@ export type BasicCentraProduct = {
19
19
  export type BasicCentraDisplay = {
20
20
  id: number;
21
21
  name: string;
22
- externalId: string;
23
22
  status: string;
24
- url: string;
23
+ uri: string;
25
24
  metaTitle: string;
26
25
  metaDescription: string;
27
26
  categories: {
28
27
  id: number;
29
28
  name: string;
30
- url: string;
29
+ uri: string;
31
30
  isTopCategory: boolean;
32
31
  }[];
33
32
  markets: BasicCentraMarket[];
34
- productVariant: Array<{
33
+ productVariants: Array<{
35
34
  id: number;
36
35
  externalId: string;
37
36
  status: string;
@@ -77,7 +76,6 @@ export type BasicCentraCountry = {
77
76
  export type BasicCentraMarket = {
78
77
  id: number;
79
78
  name: string;
80
- externalId: string;
81
79
  };
82
80
  export type BasicCentraVariant = {
83
81
  id: number;
@@ -158,14 +156,14 @@ export default class CentraHelper extends EnvEngine {
158
156
  fetchCentraWarehouses(externalIds?: string[] | undefined | null): Promise<CentraErrors | Array<BasicCentraWarehouse>>;
159
157
  fetchCentraCampaigns(names?: string[] | undefined | null): Promise<CentraErrors | Record<string, BasicCentraCampaign | Error>>;
160
158
  fetchPricelists(names?: string[] | undefined | null): Promise<CentraErrors | Array<BasicPricelist>>;
161
- fetchCentraMarkets(externalIds?: string[] | undefined | null): Promise<CentraErrors | Array<BasicCentraMarket>>;
159
+ fetchCentraMarkets(): Promise<CentraErrors | Array<BasicCentraMarket>>;
162
160
  fetchCentraSizeCharts(externalIds?: string[] | undefined | null): Promise<CentraErrors | Array<BasicCentraSizeChart>>;
163
161
  private fetchCentraProducts;
164
162
  private fetchCentraDisplays;
165
163
  private fetchCentraVariants;
166
164
  getCentraWarehouses(externalIds?: string[] | null | undefined, alwaysFetch?: boolean): Promise<Error | Record<string, Error | BasicCentraWarehouse>>;
167
165
  getCentraPricelists(names?: string[] | null | undefined, alwaysFetch?: boolean): Promise<Error | Record<string, Error | BasicPricelist>>;
168
- getCentraMarkets(externalIds?: string[] | null | undefined, alwaysFetch?: boolean): Promise<Error | Record<string, Error | BasicCentraMarket>>;
166
+ getCentraMarkets(alwaysFetch?: boolean): Promise<Error | Record<string, Error | BasicCentraMarket>>;
169
167
  getCentraCountries(iso2Codes?: string[] | null | undefined, alwaysFetch?: boolean): Promise<Error | Record<string, Error | BasicCentraCountry>>;
170
168
  getCentraSizeCharts(externalIds?: string[] | null | undefined, alwaysFetch?: boolean): Promise<Error | Record<string, Error | BasicCentraSizeChart>>;
171
169
  getCentraProducts(styleIds: string[]): Promise<Error | Record<string, Error | BasicCentraProduct>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shushed/helpers",
3
- "version": "0.0.203",
3
+ "version": "0.0.204-main-20251209142954",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",