@whizzes/wbsc 0.0.1-early-dev-12 → 0.0.1-early-dev-14

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/wbsc",
3
- "version": "0.0.1-early-dev-12",
3
+ "version": "0.0.1-early-dev-14",
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
+ }
@@ -63,7 +63,10 @@ export class CmsService extends WizardGraphQLClient<unknown> {
63
63
  const response = await this.client
64
64
  .mutation(EntryCreateDocument, {
65
65
  channel: this.channel,
66
- input,
66
+ input: {
67
+ ...input,
68
+ value: JSON.stringify(input.value),
69
+ },
67
70
  })
68
71
  .toPromise();
69
72
 
@@ -0,0 +1,9 @@
1
+ query ProductsList($channel: ChannelCode!) {
2
+ products(channelCode: $channel) {
3
+ edges {
4
+ node {
5
+ ...ProductsListFields
6
+ }
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,46 @@
1
+ fragment ProductsListFields on Product {
2
+ channelCode
3
+ id
4
+ name
5
+ slug
6
+ description
7
+ metadata
8
+ defaultVariantId
9
+ defaultVariant {
10
+ id
11
+ channelCode
12
+ sku
13
+ productId
14
+ requiresShipping
15
+ images {
16
+ id
17
+ channelCode
18
+ height
19
+ width
20
+ url
21
+ thumbnailUrl
22
+ size
23
+ mimeType
24
+ useCase
25
+ createdAt
26
+ updatedAt
27
+ }
28
+ prices {
29
+ variantId
30
+ channelCode
31
+ currency
32
+ price
33
+ }
34
+ }
35
+ position
36
+ categories {
37
+ id
38
+ name
39
+ path
40
+ position
41
+ pathString
42
+ isActive
43
+ createdAt
44
+ updatedAt
45
+ }
46
+ }
@@ -0,0 +1 @@
1
+ export { ProductService } from './service';
@@ -0,0 +1,35 @@
1
+ import { WizardGraphQLClient } from '../../client';
2
+ import {
3
+ ProductsListDocument
4
+ } from '../../types';
5
+
6
+ import type { Client } from '@urql/core';
7
+ import type {
8
+ ProductsListFieldsFragment
9
+ } from '../../types';
10
+
11
+ export class ProductService extends WizardGraphQLClient<unknown> {
12
+ private channel: string;
13
+
14
+ constructor(urqlClient: Client, channel: string) {
15
+ super(urqlClient);
16
+
17
+ this.channel = channel;
18
+ }
19
+
20
+ async listProducts(): Promise<ProductsListFieldsFragment[]> {
21
+ const response = await this.client
22
+ .query(ProductsListDocument, {
23
+ channel: this.channel
24
+ })
25
+ .toPromise();
26
+
27
+ this.unwrapError(response, 'products');
28
+
29
+ return (
30
+ response.data?.products?.edges?.map(
31
+ (edge: { node: ProductsListFieldsFragment }) => edge.node
32
+ ) || []
33
+ );
34
+ }
35
+ }
package/src/index.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { cacheExchange, createClient, fetchExchange } from '@urql/core';
2
2
 
3
3
  import { CmsService } from './core/cms';
4
+ import { CategoryService } from './core/category';
5
+ import { ProductService } from './core/product';
4
6
 
5
7
  import type { Client as URQLClient } from '@urql/core';
6
8
 
@@ -13,7 +15,9 @@ export class WizardBackstoreClient {
13
15
  readonly apiToken: string;
14
16
 
15
17
  // Application Services
18
+ readonly category: CategoryService;
16
19
  readonly cms: CmsService;
20
+ readonly product: ProductService;
17
21
 
18
22
  constructor(serverURL: URL, channelCode: string, apiToken: string) {
19
23
  const url = new URL(serverURL);
@@ -36,6 +40,10 @@ export class WizardBackstoreClient {
36
40
  this.channelCode = channelCode;
37
41
  this.serverURL = serverURL;
38
42
  this.urqlClient = graphQLClient;
43
+
44
+ // Application Services
45
+ this.category = new CategoryService(graphQLClient, channelCode);
39
46
  this.cms = new CmsService(graphQLClient, channelCode);
47
+ this.product = new ProductService(graphQLClient, channelCode);
40
48
  }
41
49
  }
@@ -1199,6 +1199,15 @@ export type VariantPriceCreateInput = {
1199
1199
  variantId: Scalars['UUID']['input'];
1200
1200
  };
1201
1201
 
1202
+ export type CategoriesListQueryVariables = Exact<{
1203
+ channel: Scalars['ChannelCode']['input'];
1204
+ }>;
1205
+
1206
+
1207
+ 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 } }> } };
1208
+
1209
+ export type CategoriesListFieldsFragment = { __typename?: 'Category', channelCode: any, id: any, name: string, description: any, path: Array<any>, position: number, isActive: boolean, createdAt: any, updatedAt: any };
1210
+
1202
1211
  export type ContentImagesListQueryVariables = Exact<{
1203
1212
  channel: Scalars['ChannelCode']['input'];
1204
1213
  }>;
@@ -1226,6 +1235,28 @@ export type EntryCreateMutationVariables = Exact<{
1226
1235
 
1227
1236
  export type EntryCreateMutation = { __typename?: 'Mutation', entryCreate: { __typename?: 'EntryCreate', entry?: { __typename?: 'Entry', channelCode: any, id: any, collectionSlug: any, value: any, createdAt: any, updatedAt: any } | null, error?: { __typename?: 'CmsError', code: CmsErrorCode, message: string } | null } };
1228
1237
 
1238
+ export type ProductsListQueryVariables = Exact<{
1239
+ channel: Scalars['ChannelCode']['input'];
1240
+ }>;
1241
+
1242
+
1243
+ export type ProductsListQuery = { __typename?: 'Query', products: { __typename?: 'ProductConnection', edges: Array<{ __typename?: 'ProductEdge', node: { __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, pathString: string, isActive: boolean, createdAt: any, updatedAt: any }> } }> } };
1244
+
1245
+ 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, pathString: string, isActive: boolean, createdAt: any, updatedAt: any }> };
1246
+
1247
+ export const CategoriesListFieldsFragmentDoc = gql`
1248
+ fragment CategoriesListFields on Category {
1249
+ channelCode
1250
+ id
1251
+ name
1252
+ description
1253
+ path
1254
+ position
1255
+ isActive
1256
+ createdAt
1257
+ updatedAt
1258
+ }
1259
+ `;
1229
1260
  export const ContentImagesListFieldsFragmentDoc = gql`
1230
1261
  fragment ContentImagesListFields on ContentImage {
1231
1262
  channelCode
@@ -1259,6 +1290,65 @@ export const EntriesListFieldsFragmentDoc = gql`
1259
1290
  updatedAt
1260
1291
  }
1261
1292
  `;
1293
+ export const ProductsListFieldsFragmentDoc = gql`
1294
+ fragment ProductsListFields on Product {
1295
+ channelCode
1296
+ id
1297
+ name
1298
+ slug
1299
+ description
1300
+ metadata
1301
+ defaultVariantId
1302
+ defaultVariant {
1303
+ id
1304
+ channelCode
1305
+ sku
1306
+ productId
1307
+ requiresShipping
1308
+ images {
1309
+ id
1310
+ channelCode
1311
+ height
1312
+ width
1313
+ url
1314
+ thumbnailUrl
1315
+ size
1316
+ mimeType
1317
+ useCase
1318
+ createdAt
1319
+ updatedAt
1320
+ }
1321
+ prices {
1322
+ variantId
1323
+ channelCode
1324
+ currency
1325
+ price
1326
+ }
1327
+ }
1328
+ position
1329
+ categories {
1330
+ id
1331
+ name
1332
+ path
1333
+ position
1334
+ pathString
1335
+ isActive
1336
+ createdAt
1337
+ updatedAt
1338
+ }
1339
+ }
1340
+ `;
1341
+ export const CategoriesListDocument = gql`
1342
+ query CategoriesList($channel: ChannelCode!) {
1343
+ categories(channelCode: $channel) {
1344
+ edges {
1345
+ node {
1346
+ ...CategoriesListFields
1347
+ }
1348
+ }
1349
+ }
1350
+ }
1351
+ ${CategoriesListFieldsFragmentDoc}`;
1262
1352
  export const ContentImagesListDocument = gql`
1263
1353
  query ContentImagesList($channel: ChannelCode!) {
1264
1354
  contentImages(channelCode: $channel) {
@@ -1293,4 +1383,15 @@ export const EntryCreateDocument = gql`
1293
1383
  }
1294
1384
  }
1295
1385
  }
1296
- ${EntriesListFieldsFragmentDoc}`;
1386
+ ${EntriesListFieldsFragmentDoc}`;
1387
+ export const ProductsListDocument = gql`
1388
+ query ProductsList($channel: ChannelCode!) {
1389
+ products(channelCode: $channel) {
1390
+ edges {
1391
+ node {
1392
+ ...ProductsListFields
1393
+ }
1394
+ }
1395
+ }
1396
+ }
1397
+ ${ProductsListFieldsFragmentDoc}`;