@whizzes/wbsc 0.0.1-early-dev-10 → 0.0.1-early-dev-11

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-10",
3
+ "version": "0.0.1-early-dev-11",
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 ContentImagesList($channel: ChannelCode!) {
2
+ contentImages(channelCode: $channel) {
3
+ edges {
4
+ node {
5
+ ...ContentImagesListFields
6
+ }
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,21 @@
1
+ fragment ContentImagesListFields on ContentImage {
2
+ channelCode
3
+ slug
4
+ imageId
5
+ image {
6
+ id
7
+ channelCode
8
+ alt
9
+ height
10
+ width
11
+ url
12
+ thumbnailUrl
13
+ size
14
+ mimeType
15
+ useCase
16
+ createdAt
17
+ updatedAt
18
+ }
19
+ createdAt
20
+ updatedAt
21
+ }
@@ -0,0 +1,9 @@
1
+ query EntriesList($channel: ChannelCode!, $filter: EntriesFilterInput!) {
2
+ entries(channelCode: $channel, filter: $filter) {
3
+ edges {
4
+ node {
5
+ ...EntriesListFields
6
+ }
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,8 @@
1
+ fragment EntriesListFields on Entry {
2
+ channelCode
3
+ id
4
+ collectionSlug
5
+ value
6
+ createdAt
7
+ updatedAt
8
+ }
@@ -0,0 +1,11 @@
1
+ mutation EntryCreate($channel: ChannelCode!, $input: EntryCreateInput!) {
2
+ entryCreate(channel: $channel, input: $input) {
3
+ entry {
4
+ ...EntriesListFields
5
+ }
6
+ error {
7
+ code
8
+ message
9
+ }
10
+ }
11
+ }
@@ -0,0 +1 @@
1
+ export { CmsService } from './service';
@@ -0,0 +1,74 @@
1
+ import { WizardGraphQLClient } from "../../client";
2
+ import {
3
+ ContentImagesListDocument,
4
+ EntriesListDocument,
5
+ EntryCreateDocument,
6
+ } from "../../types";
7
+
8
+ import type { Client } from "@urql/core";
9
+ import type {
10
+ ContentImagesListFieldsFragment,
11
+ EntriesFilterInput,
12
+ EntriesListFieldsFragment,
13
+ EntryCreateInput,
14
+ } from "../../types";
15
+
16
+ export class CmsService extends WizardGraphQLClient<unknown> {
17
+ private channel: string;
18
+
19
+ constructor(urqlClient: Client, channel: string) {
20
+ super(urqlClient);
21
+
22
+ this.channel = channel;
23
+ }
24
+
25
+ async listEntries(
26
+ filter: EntriesFilterInput,
27
+ ): Promise<EntriesListFieldsFragment[]> {
28
+ const response = await this.client
29
+ .query(EntriesListDocument, {
30
+ channel: this.channel,
31
+ filter,
32
+ })
33
+ .toPromise();
34
+
35
+ this.unwrapError(response, "entries");
36
+
37
+ return (
38
+ response.data?.entries?.edges?.map(
39
+ (edge: { node: EntriesListFieldsFragment }) => edge.node,
40
+ ) || []
41
+ );
42
+ }
43
+
44
+ async listContentImages(): Promise<ContentImagesListFieldsFragment[]> {
45
+ const response = await this.client
46
+ .query(ContentImagesListDocument, {
47
+ channel: this.channel,
48
+ })
49
+ .toPromise();
50
+
51
+ this.unwrapError(response, "contentImages");
52
+
53
+ return (
54
+ response.data?.contentImages?.edges?.map(
55
+ (edge: { node: ContentImagesListFieldsFragment }) => edge.node,
56
+ ) || []
57
+ );
58
+ }
59
+
60
+ async createEntry(
61
+ input: EntryCreateInput,
62
+ ): Promise<EntriesListFieldsFragment> {
63
+ const response = await this.client
64
+ .mutation(EntryCreateDocument, {
65
+ channel: this.channel,
66
+ input,
67
+ })
68
+ .toPromise();
69
+
70
+ this.unwrapError(response, "entryCreate");
71
+
72
+ return response.data.entryCreate?.entry || null;
73
+ }
74
+ }
package/src/index.ts CHANGED
@@ -1,17 +1,41 @@
1
- export * from './core/product';
1
+ import { cacheExchange, createClient, fetchExchange } from '@urql/core';
2
2
 
3
- import { ProductService } from './core/product';
3
+ import { CmsService } from './core/cms';
4
4
 
5
5
  import type { Client as URQLClient } from '@urql/core';
6
6
 
7
+ export * from './core/cms';
8
+
7
9
  export class WizardStorefrontClient {
8
- readonly baseURL: URL;
10
+ readonly serverURL: URL;
9
11
  readonly urqlClient: URQLClient;
10
- readonly product: ProductService;
12
+ readonly channelCode: string;
13
+ readonly apiToken: string;
14
+
15
+ // Application Services
16
+ readonly cms: CmsService;
17
+
18
+ constructor(serverURL: URL, channelCode: string, apiToken: string) {
19
+ const url = new URL(serverURL);
20
+ url.pathname = '/api/v0/backstore/graphql';
21
+
22
+ const graphQLClient = createClient({
23
+ url: url.toString(),
24
+ exchanges: [cacheExchange, fetchExchange],
25
+ fetchOptions() {
26
+ return {
27
+ headers: {
28
+ 'Authorization': `Bearer ${apiToken}`,
29
+ 'X-Channel-Code': channelCode,
30
+ },
31
+ };
32
+ },
33
+ });
11
34
 
12
- constructor(baseURL: URL, graphQLClient: URQLClient) {
13
- this.baseURL = baseURL;
35
+ this.apiToken = apiToken;
36
+ this.channelCode = channelCode;
37
+ this.serverURL = serverURL;
14
38
  this.urqlClient = graphQLClient;
15
- this.product = new ProductService(graphQLClient);
39
+ this.cms = new CmsService(graphQLClient, channelCode);
16
40
  }
17
41
  }
@@ -629,8 +629,6 @@ export type Mutation = {
629
629
  * This will update the order status to `Address` or `Payment` depending on the order type.
630
630
  */
631
631
  startCheckout: OrderStartCheckout;
632
- /** List Users */
633
- userCreate: UserCreate;
634
632
  /** Uploads an Image and attaches it to a Product Variant */
635
633
  variantImageUpload: VariantImageUpload;
636
634
  /** Creates a price for a Product Variant */
@@ -747,11 +745,6 @@ export type MutationStartCheckoutArgs = {
747
745
  };
748
746
 
749
747
 
750
- export type MutationUserCreateArgs = {
751
- channelCode: Scalars['ChannelCode']['input'];
752
- };
753
-
754
-
755
748
  export type MutationVariantImageUploadArgs = {
756
749
  channel: Scalars['ChannelCode']['input'];
757
750
  input: VariantImageUploadInput;
@@ -1024,8 +1017,6 @@ export type Query = {
1024
1017
  orders: OrderConnection;
1025
1018
  /** Retrieves Products */
1026
1019
  products: ProductConnection;
1027
- /** List Users */
1028
- users: Scalars['String']['output'];
1029
1020
  };
1030
1021
 
1031
1022
 
@@ -1118,11 +1109,6 @@ export type QueryProductsArgs = {
1118
1109
  last?: InputMaybe<Scalars['Int']['input']>;
1119
1110
  };
1120
1111
 
1121
-
1122
- export type QueryUsersArgs = {
1123
- channelCode: Scalars['ChannelCode']['input'];
1124
- };
1125
-
1126
1112
  /**
1127
1113
  * Channel Role is a role that a user can have in a channel.
1128
1114
  * The roles are:
@@ -1164,22 +1150,6 @@ export type User = {
1164
1150
  updatedAt: Scalars['DateTime']['output'];
1165
1151
  };
1166
1152
 
1167
- export type UserCreate = {
1168
- __typename?: 'UserCreate';
1169
- error?: Maybe<UserError>;
1170
- user?: Maybe<User>;
1171
- };
1172
-
1173
- export type UserError = {
1174
- __typename?: 'UserError';
1175
- code: UserErrorCode;
1176
- message: Scalars['String']['output'];
1177
- };
1178
-
1179
- export enum UserErrorCode {
1180
- DatabaseError = 'DATABASE_ERROR'
1181
- }
1182
-
1183
1153
  /** Platform Product Variant */
1184
1154
  export type Variant = {
1185
1155
  __typename?: 'Variant';
@@ -1229,71 +1199,98 @@ export type VariantPriceCreateInput = {
1229
1199
  variantId: Scalars['UUID']['input'];
1230
1200
  };
1231
1201
 
1232
- export type ProductsListQueryVariables = Exact<{
1202
+ export type ContentImagesListQueryVariables = Exact<{
1203
+ channel: Scalars['ChannelCode']['input'];
1204
+ }>;
1205
+
1206
+
1207
+ export type ContentImagesListQuery = { __typename?: 'Query', contentImages: { __typename?: 'ContentImageConnection', edges: Array<{ __typename?: 'ContentImageEdge', node: { __typename?: 'ContentImage', channelCode: any, slug: any, imageId: any, createdAt: any, updatedAt: any, image: { __typename?: 'Image', id: any, channelCode: any, alt?: string | null, height: number, width: number, url: string, thumbnailUrl?: string | null, size: number, mimeType: MimeType, useCase: UseCase, createdAt: any, updatedAt: any } } }> } };
1208
+
1209
+ export type ContentImagesListFieldsFragment = { __typename?: 'ContentImage', channelCode: any, slug: any, imageId: any, createdAt: any, updatedAt: any, image: { __typename?: 'Image', id: any, channelCode: any, alt?: string | null, height: number, width: number, url: string, thumbnailUrl?: string | null, size: number, mimeType: MimeType, useCase: UseCase, createdAt: any, updatedAt: any } };
1210
+
1211
+ export type EntriesListQueryVariables = Exact<{
1233
1212
  channel: Scalars['ChannelCode']['input'];
1213
+ filter: EntriesFilterInput;
1234
1214
  }>;
1235
1215
 
1236
1216
 
1237
- 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 }> } }> } };
1217
+ export type EntriesListQuery = { __typename?: 'Query', entries: { __typename?: 'EntryConnection', edges: Array<{ __typename?: 'EntryEdge', node: { __typename?: 'Entry', channelCode: any, id: any, collectionSlug: any, value: any, createdAt: any, updatedAt: any } }> } };
1238
1218
 
1239
- 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 }> };
1219
+ export type EntriesListFieldsFragment = { __typename?: 'Entry', channelCode: any, id: any, collectionSlug: any, value: any, createdAt: any, updatedAt: any };
1240
1220
 
1241
- export const ProductsListFieldsFragmentDoc = gql`
1242
- fragment ProductsListFields on Product {
1221
+ export type EntryCreateMutationVariables = Exact<{
1222
+ channel: Scalars['ChannelCode']['input'];
1223
+ input: EntryCreateInput;
1224
+ }>;
1225
+
1226
+
1227
+ 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
+
1229
+ export const ContentImagesListFieldsFragmentDoc = gql`
1230
+ fragment ContentImagesListFields on ContentImage {
1243
1231
  channelCode
1244
- id
1245
- name
1246
1232
  slug
1247
- description
1248
- metadata
1249
- defaultVariantId
1250
- defaultVariant {
1233
+ imageId
1234
+ image {
1251
1235
  id
1252
1236
  channelCode
1253
- sku
1254
- productId
1255
- requiresShipping
1256
- images {
1257
- id
1258
- channelCode
1259
- height
1260
- width
1261
- url
1262
- thumbnailUrl
1263
- size
1264
- mimeType
1265
- useCase
1266
- createdAt
1267
- updatedAt
1268
- }
1269
- prices {
1270
- variantId
1271
- channelCode
1272
- currency
1273
- price
1274
- }
1275
- }
1276
- position
1277
- categories {
1278
- id
1279
- name
1280
- path
1281
- position
1282
- pathString
1283
- isActive
1237
+ alt
1238
+ height
1239
+ width
1240
+ url
1241
+ thumbnailUrl
1242
+ size
1243
+ mimeType
1244
+ useCase
1284
1245
  createdAt
1285
1246
  updatedAt
1286
1247
  }
1248
+ createdAt
1249
+ updatedAt
1250
+ }
1251
+ `;
1252
+ export const EntriesListFieldsFragmentDoc = gql`
1253
+ fragment EntriesListFields on Entry {
1254
+ channelCode
1255
+ id
1256
+ collectionSlug
1257
+ value
1258
+ createdAt
1259
+ updatedAt
1287
1260
  }
1288
1261
  `;
1289
- export const ProductsListDocument = gql`
1290
- query ProductsList($channel: ChannelCode!) {
1291
- products(channelCode: $channel) {
1262
+ export const ContentImagesListDocument = gql`
1263
+ query ContentImagesList($channel: ChannelCode!) {
1264
+ contentImages(channelCode: $channel) {
1265
+ edges {
1266
+ node {
1267
+ ...ContentImagesListFields
1268
+ }
1269
+ }
1270
+ }
1271
+ }
1272
+ ${ContentImagesListFieldsFragmentDoc}`;
1273
+ export const EntriesListDocument = gql`
1274
+ query EntriesList($channel: ChannelCode!, $filter: EntriesFilterInput!) {
1275
+ entries(channelCode: $channel, filter: $filter) {
1292
1276
  edges {
1293
1277
  node {
1294
- ...ProductsListFields
1278
+ ...EntriesListFields
1295
1279
  }
1296
1280
  }
1297
1281
  }
1298
1282
  }
1299
- ${ProductsListFieldsFragmentDoc}`;
1283
+ ${EntriesListFieldsFragmentDoc}`;
1284
+ export const EntryCreateDocument = gql`
1285
+ mutation EntryCreate($channel: ChannelCode!, $input: EntryCreateInput!) {
1286
+ entryCreate(channel: $channel, input: $input) {
1287
+ entry {
1288
+ ...EntriesListFields
1289
+ }
1290
+ error {
1291
+ code
1292
+ message
1293
+ }
1294
+ }
1295
+ }
1296
+ ${EntriesListFieldsFragmentDoc}`;
@@ -1,9 +0,0 @@
1
- query ProductsList($channel: ChannelCode!) {
2
- products(channelCode: $channel) {
3
- edges {
4
- node {
5
- ...ProductsListFields
6
- }
7
- }
8
- }
9
- }
@@ -1,46 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- export { ProductService } from './service';
@@ -1,34 +0,0 @@
1
- import { WizardGraphQLClient } from '../../client';
2
- import {
3
- ProductsListDocument
4
- } from '../../types';
5
-
6
- import type { Client } from '@urql/core';
7
- import type {
8
- ProductErrorCode,
9
- ProductsListFieldsFragment
10
- } from '../../types';
11
-
12
- export class ProductService extends WizardGraphQLClient<ProductErrorCode> {
13
- constructor(urqlClient: Client) {
14
- super(urqlClient);
15
- }
16
-
17
- async listProducts(
18
- channel: string,
19
- ): Promise<ProductsListFieldsFragment[]> {
20
- const response = await this.client
21
- .query(ProductsListDocument, {
22
- channel
23
- })
24
- .toPromise();
25
-
26
- this.unwrapError(response, 'products');
27
-
28
- return (
29
- response.data?.products?.edges?.map(
30
- (edge: { node: ProductsListFieldsFragment }) => edge.node
31
- ) || []
32
- );
33
- }
34
- }