@shushed/helpers 0.0.253 → 0.0.255

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.
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const schema = { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Category Tree", "additionalProperties": false, "type": "object", "$defs": { "categoryNode": { "type": "object", "additionalProperties": false, "properties": { "id": { "type": "string" }, "branchId": { "type": "string" }, "name": { "type": "string" }, "path": { "type": "array", "items": { "type": "string" } }, "parentCategory": { "type": ["string", "null"] }, "displayPath": { "type": "string" }, "pathId": { "type": "array", "items": { "type": "string" } }, "children": { "type": "array", "items": { "$ref": "#/$defs/categoryNode" } } }, "required": ["id", "branchId", "name", "path", "pathId", "children"] } }, "properties": { "children": { "type": "array", "items": { "$ref": "#/$defs/categoryNode" } } }, "required": ["children"], "$id": "https://shushed.example.com/category-tree.schema.json" };
3
+ const schema = { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Category Tree", "additionalProperties": false, "type": "object", "$defs": { "categoryNode": { "type": "object", "additionalProperties": false, "properties": { "id": { "type": "string" }, "branchId": { "type": "string" }, "name": { "type": "string" }, "path": { "type": "array", "items": { "type": "string" } }, "slug": { "type": "string" }, "parentCategory": { "type": ["string", "null"] }, "displayPath": { "type": "string" }, "pathId": { "type": "array", "items": { "type": "string" } }, "children": { "type": "array", "items": { "$ref": "#/$defs/categoryNode" } } }, "required": ["id", "branchId", "name", "path", "pathId", "children"] } }, "properties": { "children": { "type": "array", "items": { "$ref": "#/$defs/categoryNode" } } }, "required": ["children"], "$id": "https://shushed.example.com/category-tree.schema.json" };
4
4
  exports.default = schema;
@@ -533,6 +533,17 @@ class CentraHelper extends env_1.default {
533
533
  name
534
534
  uri
535
535
  isTopCategory
536
+ attributes {
537
+ description
538
+ elements {
539
+ key
540
+ description
541
+ kind
542
+ ... on AttributeStringElement {
543
+ value
544
+ }
545
+ }
546
+ }
536
547
  }
537
548
  canonicalCategory {
538
549
  id
@@ -1109,7 +1120,7 @@ class CentraHelper extends env_1.default {
1109
1120
  }
1110
1121
  return centraSizeName;
1111
1122
  }
1112
- async fetchCentraCategories(categoryIds) {
1123
+ async fetchCentraCategories() {
1113
1124
  const result = [];
1114
1125
  const limit = 200;
1115
1126
  let page = 0;
@@ -1119,19 +1130,32 @@ class CentraHelper extends env_1.default {
1119
1130
  method: 'POST',
1120
1131
  body: JSON.stringify({
1121
1132
  query: `
1122
- query GetCategories($limit: Int, $page: Int${categoryIds ? `, $categoryIds: CategoryFilter` : ''}) {
1123
- categories(${categoryIds ? `where: $categoryIds, ` : ''}limit: $limit, page: $page) {
1133
+ query GetCategories($limit: Int, $page: Int, $filter: CategoryFilter) {
1134
+ categories(where: $filter, limit: $limit, page: $page) {
1124
1135
  id
1125
1136
  name
1126
1137
  uri
1127
1138
  isTopCategory
1139
+ attributes {
1140
+ description
1141
+ elements {
1142
+ key
1143
+ description
1144
+ kind
1145
+ ... on AttributeStringElement {
1146
+ value
1147
+ }
1148
+ }
1149
+ }
1128
1150
  }
1129
1151
  }
1130
1152
  `,
1131
1153
  variables: {
1132
1154
  page,
1133
1155
  limit,
1134
- categoryIds: categoryIds ? { uri: { equals: categoryIds } } : undefined
1156
+ filter: {
1157
+ status: ['ACTIVE']
1158
+ }
1135
1159
  }
1136
1160
  })
1137
1161
  });
@@ -1149,67 +1173,23 @@ class CentraHelper extends env_1.default {
1149
1173
  id: category.id,
1150
1174
  name: category.name,
1151
1175
  uri: category.uri,
1152
- isTopCategory: category.isTopCategory
1176
+ isTopCategory: category.isTopCategory,
1177
+ attributes: category.attributes,
1153
1178
  });
1154
1179
  }
1155
1180
  } while (hasNextPage);
1156
1181
  return result;
1157
1182
  }
1158
- async getCentraCategories(categoryIds, alwaysFetch = false) {
1159
- if (categoryIds && !categoryIds.length) {
1160
- return {};
1161
- }
1162
- let categoryInCache = {};
1163
- let dedupedCategoryIds = [];
1164
- let categoriesToFetch = null;
1165
- if (!alwaysFetch) {
1166
- if (!categoryIds) {
1167
- categoryIds = await this.get(this.getCacheKeyForCentraCategories(), 'env', {
1168
- isEphemeral: true,
1169
- encrypted: false,
1170
- }).then(x => x ? JSON.parse(x) : null);
1171
- }
1172
- if (categoryIds) {
1173
- dedupedCategoryIds = categoryIds.filter((x, index, self) => self.indexOf(x) === index);
1174
- const cachedValues = await this.get(dedupedCategoryIds.map(x => this.getCacheKeyForCentraCategory(x)), 'env', {
1175
- isEphemeral: true,
1176
- encrypted: false,
1177
- });
1178
- categoryInCache = Object.fromEntries(Object.entries(cachedValues)
1179
- .map(([key, value]) => [key, value ? JSON.parse(value || 'null') : undefined])
1180
- .filter((entry) => entry[1]));
1181
- categoriesToFetch = dedupedCategoryIds.filter(x => !categoryInCache[x]);
1182
- }
1183
+ async getCentraCategories() {
1184
+ const categoriesFetched = await this.fetchCentraCategories();
1185
+ if (CentraHelper.isCentraErrors(categoriesFetched)) {
1186
+ return new Error(`Failed to fetch categories: ${categoriesFetched.errors.map((x) => x.message).join(', ')}`);
1183
1187
  }
1184
- const categoryToSet = {};
1185
- if (!categoriesToFetch || categoriesToFetch.length) {
1186
- const categoriesFetched = await this.fetchCentraCategories(categoriesToFetch);
1187
- if (CentraHelper.isCentraErrors(categoriesFetched)) {
1188
- if (categoriesToFetch) {
1189
- for (const categoryId of categoriesToFetch) {
1190
- categoryToSet[categoryId] = new Error(`Failed to fetch category ${categoryId}: ${categoriesFetched.errors.map((x) => x.message).join(', ')}`);
1191
- }
1192
- }
1193
- else {
1194
- return new Error(`Failed to fetch categories: ${categoriesFetched.errors.map((x) => x.message).join(', ')}`);
1195
- }
1196
- }
1197
- else {
1198
- for (const category of categoriesFetched) {
1199
- categoryToSet[category.uri] = category;
1200
- }
1201
- await this.set(Object.entries(categoryToSet)
1202
- .filter((entry) => !(entry[1] instanceof Error))
1203
- .map(([key, value]) => ({ name: this.getCacheKeyForCentraCategory(key), value: JSON.stringify(value) })), 'env', { ephemeralMs: CACHE_EXPIRATION_MS, encrypted: false });
1204
- if (!categoriesToFetch) {
1205
- await this.set([{
1206
- name: this.getCacheKeyForCentraCategories(),
1207
- value: JSON.stringify(Object.keys(categoryToSet)),
1208
- }], 'env', { ephemeralMs: CACHE_EXPIRATION_MS, encrypted: false });
1209
- }
1210
- }
1188
+ const categoryMap = {};
1189
+ for (const category of categoriesFetched) {
1190
+ categoryMap[category.id] = category;
1211
1191
  }
1212
- return Object.assign({}, categoryInCache, categoryToSet);
1192
+ return categoryMap;
1213
1193
  }
1214
1194
  async fetchCentraMeasurementCharts() {
1215
1195
  const result = [];
@@ -23,6 +23,9 @@ declare const schema: {
23
23
  readonly type: "string";
24
24
  };
25
25
  };
26
+ readonly slug: {
27
+ readonly type: "string";
28
+ };
26
29
  readonly parentCategory: {
27
30
  readonly type: readonly ["string", "null"];
28
31
  };
@@ -6,6 +6,7 @@ export interface CategoryNode {
6
6
  branchId: string;
7
7
  name: string;
8
8
  path: string[];
9
+ slug?: string;
9
10
  parentCategory?: (string | null);
10
11
  displayPath?: string;
11
12
  pathId: string[];
@@ -5,6 +5,15 @@ export type BasicCentraCategory = {
5
5
  name: string;
6
6
  uri: string;
7
7
  isTopCategory: boolean;
8
+ attributes?: Array<{
9
+ elements?: Array<{
10
+ key: string;
11
+ kind: string;
12
+ value?: string;
13
+ description: string;
14
+ }>;
15
+ description: string;
16
+ }>;
8
17
  };
9
18
  export type BasicCentraMeasurementChart = {
10
19
  id: number;
@@ -51,6 +60,15 @@ export type BasicCentraDisplay = {
51
60
  name: string;
52
61
  uri: string;
53
62
  isTopCategory: boolean;
63
+ attributes?: Array<{
64
+ description: string;
65
+ elements?: Array<{
66
+ kind: string;
67
+ key: string;
68
+ description: string;
69
+ value?: string;
70
+ }>;
71
+ }>;
54
72
  }[];
55
73
  canonicalCategory: {
56
74
  id: number;
@@ -205,8 +223,8 @@ export default class CentraHelper extends EnvEngine {
205
223
  getCentraDisplaysByProductIds(centraProductIds: number[]): Promise<Record<string, BasicCentraDisplay[] | Error>>;
206
224
  getCentraVariants(productIds: string[]): Promise<Record<string, BasicCentraVariant | Error>>;
207
225
  static centraSizeNameToSize(centraSizeName: string): string;
208
- fetchCentraCategories(categoryIds?: string[] | null): Promise<CentraErrors | BasicCentraCategory[]>;
209
- getCentraCategories(categoryIds?: string[] | null, alwaysFetch?: boolean): Promise<Error | Record<string, Error | BasicCentraCategory>>;
226
+ fetchCentraCategories(): Promise<CentraErrors | BasicCentraCategory[]>;
227
+ getCentraCategories(): Promise<Error | Record<string, Error | BasicCentraCategory>>;
210
228
  fetchCentraMeasurementCharts(): Promise<CentraErrors | BasicCentraMeasurementChart[]>;
211
229
  getCentraMeasurementCharts(alwaysFetch?: boolean): Promise<Error | Record<string, Error | BasicCentraMeasurementChart>>;
212
230
  getCentraDisplaysByUris(uris: string[]): Promise<Record<string, BasicCentraDisplayForSlugCheck[]> | Error>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shushed/helpers",
3
- "version": "0.0.253",
3
+ "version": "0.0.255",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",