@whizzes/wsfc 0.0.1-early-dev-9 → 0.0.1-early-dev-10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whizzes/wsfc",
3
- "version": "0.0.1-early-dev-9",
3
+ "version": "0.0.1-early-dev-10",
4
4
  "main": "./src/index.ts",
5
5
  "module": "./src/index.ts",
6
6
  "types": "./src/index.d.ts",
@@ -0,0 +1,9 @@
1
+ query CategoriesList($channel: ChannelCode!) {
2
+ categories(channelCode: $channel) {
3
+ edges {
4
+ node {
5
+ ...CategoriesListFields
6
+ }
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,11 @@
1
+ fragment CategoriesListFields on Category {
2
+ channelCode
3
+ id
4
+ name
5
+ description
6
+ path
7
+ position
8
+ isActive
9
+ createdAt
10
+ updatedAt
11
+ }
@@ -0,0 +1 @@
1
+ export { CategoryService } from './service';
@@ -0,0 +1,31 @@
1
+ import { WizardGraphQLClient } from "../../client";
2
+ import { CategoriesListDocument } from "../../types";
3
+
4
+ import type { Client } from "@urql/core";
5
+ import type { CategoriesListFieldsFragment } from "../../types";
6
+
7
+ export class CategoryService extends WizardGraphQLClient<unknown> {
8
+ private channel: string;
9
+
10
+ constructor(urqlClient: Client, channel: string) {
11
+ super(urqlClient);
12
+
13
+ this.channel = channel;
14
+ }
15
+
16
+ async listCategories(): Promise<CategoriesListFieldsFragment[]> {
17
+ const response = await this.client
18
+ .query(CategoriesListDocument, {
19
+ channel: this.channel,
20
+ })
21
+ .toPromise();
22
+
23
+ this.unwrapError(response, "categories");
24
+
25
+ return (
26
+ response.data?.categories?.edges?.map(
27
+ (edge: { node: CategoriesListFieldsFragment }) => edge.node,
28
+ ) || []
29
+ );
30
+ }
31
+ }
@@ -5,21 +5,20 @@ import {
5
5
 
6
6
  import type { Client } from '@urql/core';
7
7
  import type {
8
- ProductErrorCode,
9
8
  ProductsListFieldsFragment
10
9
  } from '../../types';
11
10
 
12
- export class ProductService extends WizardGraphQLClient<ProductErrorCode> {
13
- constructor(urqlClient: Client) {
11
+ export class ProductService extends WizardGraphQLClient<unknown> {
12
+ private channel: string;
13
+
14
+ constructor(urqlClient: Client, channel: string) {
14
15
  super(urqlClient);
15
16
  }
16
17
 
17
- async listProducts(
18
- channel: string,
19
- ): Promise<ProductsListFieldsFragment[]> {
18
+ async listProducts(): Promise<ProductsListFieldsFragment[]> {
20
19
  const response = await this.client
21
20
  .query(ProductsListDocument, {
22
- channel
21
+ channel: this.channel
23
22
  })
24
23
  .toPromise();
25
24
 
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './core/product';
2
2
 
3
+ import { CategoryService } from './core/category';
3
4
  import { ProductService } from './core/product';
4
5
 
5
6
  import type { Client as URQLClient } from '@urql/core';
@@ -7,11 +8,13 @@ import type { Client as URQLClient } from '@urql/core';
7
8
  export class WizardStorefrontClient {
8
9
  readonly baseURL: URL;
9
10
  readonly urqlClient: URQLClient;
11
+ readonly category: CategoryService;
10
12
  readonly product: ProductService;
11
13
 
12
- constructor(baseURL: URL, graphQLClient: URQLClient) {
14
+ constructor(baseURL: URL, graphQLClient: URQLClient, channelCode: string) {
13
15
  this.baseURL = baseURL;
14
16
  this.urqlClient = graphQLClient;
15
- this.product = new ProductService(graphQLClient);
17
+ this.category = new CategoryService(graphQLClient, channelCode);
18
+ this.product = new ProductService(graphQLClient, channelCode);
16
19
  }
17
20
  }
@@ -28,6 +28,7 @@ export type Category = {
28
28
  __typename?: 'Category';
29
29
  channelCode: Scalars['ChannelCode']['output'];
30
30
  createdAt: Scalars['DateTime']['output'];
31
+ description: Scalars['JsonString']['output'];
31
32
  id: Scalars['UUID']['output'];
32
33
  isActive: Scalars['Boolean']['output'];
33
34
  name: Scalars['String']['output'];
@@ -36,9 +37,31 @@ export type Category = {
36
37
  updatedAt: Scalars['DateTime']['output'];
37
38
  };
38
39
 
40
+ export type CategoryConnection = {
41
+ __typename?: 'CategoryConnection';
42
+ /** A list of edges. */
43
+ edges: Array<CategoryEdge>;
44
+ /** A list of nodes. */
45
+ nodes: Array<Category>;
46
+ /** Information to aid in pagination. */
47
+ pageInfo: PageInfo;
48
+ totalCount: Scalars['Int']['output'];
49
+ totalPages: Scalars['Int']['output'];
50
+ };
51
+
52
+ /** An edge in a connection. */
53
+ export type CategoryEdge = {
54
+ __typename?: 'CategoryEdge';
55
+ /** A cursor for use in pagination */
56
+ cursor: Scalars['String']['output'];
57
+ /** The item at the end of the edge */
58
+ node: Category;
59
+ };
60
+
39
61
  /** Platform Image */
40
62
  export type Image = {
41
63
  __typename?: 'Image';
64
+ alt?: Maybe<Scalars['String']['output']>;
42
65
  channelCode: Scalars['ChannelCode']['output'];
43
66
  createdAt: Scalars['DateTime']['output'];
44
67
  height: Scalars['Int']['output'];
@@ -167,11 +190,22 @@ export type ProductEdge = {
167
190
 
168
191
  export type Query = {
169
192
  __typename?: 'Query';
193
+ /** Retrieves Categories */
194
+ categories: CategoryConnection;
170
195
  /** Retrieves Products */
171
196
  products: ProductConnection;
172
197
  };
173
198
 
174
199
 
200
+ export type QueryCategoriesArgs = {
201
+ after?: InputMaybe<Scalars['String']['input']>;
202
+ before?: InputMaybe<Scalars['String']['input']>;
203
+ channelCode: Scalars['ChannelCode']['input'];
204
+ first?: InputMaybe<Scalars['Int']['input']>;
205
+ last?: InputMaybe<Scalars['Int']['input']>;
206
+ };
207
+
208
+
175
209
  export type QueryProductsArgs = {
176
210
  after?: InputMaybe<Scalars['String']['input']>;
177
211
  before?: InputMaybe<Scalars['String']['input']>;
@@ -183,6 +217,8 @@ export type QueryProductsArgs = {
183
217
  export enum UseCase {
184
218
  /** Profile Picture for a user instance */
185
219
  Avatar = 'AVATAR',
220
+ /** Image associated to a CMS resource */
221
+ Cms = 'CMS',
186
222
  /** Logo associated to a brand */
187
223
  Logo = 'LOGO',
188
224
  /** Image associated to a product variant */
@@ -204,6 +240,15 @@ export type Variant = {
204
240
  updatedAt: Scalars['DateTime']['output'];
205
241
  };
206
242
 
243
+ export type CategoriesListQueryVariables = Exact<{
244
+ channel: Scalars['ChannelCode']['input'];
245
+ }>;
246
+
247
+
248
+ export type CategoriesListQuery = { __typename?: 'Query', categories: { __typename?: 'CategoryConnection', edges: Array<{ __typename?: 'CategoryEdge', node: { __typename?: 'Category', channelCode: any, id: any, name: string, description: any, path: Array<any>, position: number, isActive: boolean, createdAt: any, updatedAt: any } }> } };
249
+
250
+ export type CategoriesListFieldsFragment = { __typename?: 'Category', channelCode: any, id: any, name: string, description: any, path: Array<any>, position: number, isActive: boolean, createdAt: any, updatedAt: any };
251
+
207
252
  export type ProductsListQueryVariables = Exact<{
208
253
  channel: Scalars['ChannelCode']['input'];
209
254
  }>;
@@ -213,6 +258,19 @@ export type ProductsListQuery = { __typename?: 'Query', products: { __typename?:
213
258
 
214
259
  export type ProductsListFieldsFragment = { __typename?: 'Product', channelCode: any, id: any, name: string, slug: any, description: any, metadata?: any | null, defaultVariantId: any, position: number, defaultVariant: { __typename?: 'Variant', id: any, channelCode: any, sku?: string | null, productId: any, requiresShipping: boolean, images: Array<{ __typename?: 'Image', id: any, channelCode: any, height: number, width: number, url: string, thumbnailUrl?: string | null, size: number, mimeType: MimeType, useCase: UseCase, createdAt: any, updatedAt: any }>, prices: Array<{ __typename?: 'Price', variantId: any, channelCode: any, currency: Iso4217, price: any }> }, categories: Array<{ __typename?: 'Category', id: any, name: string, path: Array<any>, position: number, isActive: boolean, createdAt: any, updatedAt: any }> };
215
260
 
261
+ export const CategoriesListFieldsFragmentDoc = gql`
262
+ fragment CategoriesListFields on Category {
263
+ channelCode
264
+ id
265
+ name
266
+ description
267
+ path
268
+ position
269
+ isActive
270
+ createdAt
271
+ updatedAt
272
+ }
273
+ `;
216
274
  export const ProductsListFieldsFragmentDoc = gql`
217
275
  fragment ProductsListFields on Product {
218
276
  channelCode
@@ -260,6 +318,17 @@ export const ProductsListFieldsFragmentDoc = gql`
260
318
  }
261
319
  }
262
320
  `;
321
+ export const CategoriesListDocument = gql`
322
+ query CategoriesList($channel: ChannelCode!) {
323
+ categories(channelCode: $channel) {
324
+ edges {
325
+ node {
326
+ ...CategoriesListFields
327
+ }
328
+ }
329
+ }
330
+ }
331
+ ${CategoriesListFieldsFragmentDoc}`;
263
332
  export const ProductsListDocument = gql`
264
333
  query ProductsList($channel: ChannelCode!) {
265
334
  products(channelCode: $channel) {