@faststore/api 1.10.18 → 1.10.33

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/dist/index.d.ts CHANGED
@@ -181,6 +181,7 @@ export declare const getResolvers: (options: Options) => {
181
181
  }[];
182
182
  } | null>;
183
183
  validateSession: (_: any, { session: oldSession, search }: import("./__generated__/schema").MutationValidateSessionArgs, { clients }: import("./platforms/vtex").Context) => Promise<import("./__generated__/schema").StoreSession | null>;
184
+ subscribeToNewsletter: (_: any, { data }: import("./__generated__/schema").MutationSubscribeToNewsletterArgs, { clients: { commerce } }: import("./platforms/vtex").Context) => Promise<import("./__generated__/schema").PersonNewsletter | null>;
184
185
  };
185
186
  };
186
187
  export declare const getContextFactory: (options: Options) => (ctx: any) => import("./platforms/vtex").Context;
@@ -10,6 +10,7 @@ import type { Simulation, SimulationArgs, SimulationOptions } from './types/Simu
10
10
  import type { Session } from './types/Session';
11
11
  import type { Channel } from '../../utils/channel';
12
12
  import type { SalesChannel } from './types/SalesChannel';
13
+ import { MasterDataResponse } from './types/Newsletter';
13
14
  declare type ValueOf<T> = T extends Record<string, infer K> ? K : never;
14
15
  export declare const VtexCommerce: ({ account, environment }: Options, ctx: Context) => {
15
16
  catalog: {
@@ -53,5 +54,9 @@ export declare const VtexCommerce: ({ account, environment }: Options, ctx: Cont
53
54
  region: ({ postalCode, country, salesChannel, }: RegionInput) => Promise<Region>;
54
55
  };
55
56
  session: (search: string) => Promise<Session>;
57
+ subscribeToNewsletter: (data: {
58
+ name: string;
59
+ email: string;
60
+ }) => Promise<MasterDataResponse>;
56
61
  };
57
62
  export {};
@@ -0,0 +1,4 @@
1
+ export interface MasterDataResponse {
2
+ Id: string;
3
+ Href: string;
4
+ }
@@ -49,6 +49,10 @@ export declare const getClients: (options: Options, ctx: Context) => {
49
49
  region: ({ postalCode, country, salesChannel, }: import("./commerce/types/Region").RegionInput) => Promise<import("./commerce/types/Region").Region>;
50
50
  };
51
51
  session: (search: string) => Promise<import("./commerce/types/Session").Session>;
52
+ subscribeToNewsletter: (data: {
53
+ name: string;
54
+ email: string;
55
+ }) => Promise<import("./commerce/types/Newsletter").MasterDataResponse>;
52
56
  };
53
57
  sp: {
54
58
  sendEvent: (options: import("./sp").SearchEvent) => Promise<any>;
@@ -211,6 +211,7 @@ export declare const getResolvers: (_: Options) => {
211
211
  }[];
212
212
  } | null>;
213
213
  validateSession: (_: any, { session: oldSession, search }: import("../..").MutationValidateSessionArgs, { clients }: Context) => Promise<import("../..").StoreSession | null>;
214
+ subscribeToNewsletter: (_: any, { data }: import("../..").MutationSubscribeToNewsletterArgs, { clients: { commerce } }: Context) => Promise<import("../..").PersonNewsletter | null>;
214
215
  };
215
216
  };
216
217
  export {};
@@ -57,4 +57,5 @@ export declare const Mutation: {
57
57
  }[];
58
58
  } | null>;
59
59
  validateSession: (_: any, { session: oldSession, search }: import("../../..").MutationValidateSessionArgs, { clients }: import("..").Context) => Promise<import("../../..").StoreSession | null>;
60
+ subscribeToNewsletter: (_: any, { data }: import("../../..").MutationSubscribeToNewsletterArgs, { clients: { commerce } }: import("..").Context) => Promise<import("../../..").PersonNewsletter | null>;
60
61
  };
@@ -0,0 +1,3 @@
1
+ import type { Context } from '..';
2
+ import type { MutationSubscribeToNewsletterArgs, PersonNewsletter } from '../../../__generated__/schema';
3
+ export declare const subscribeToNewsletter: (_: any, { data }: MutationSubscribeToNewsletterArgs, { clients: { commerce } }: Context) => Promise<PersonNewsletter | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "1.10.18",
3
+ "version": "1.10.33",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -37,7 +37,7 @@
37
37
  "express-graphql": "^0.12.0",
38
38
  "graphql": "^15.6.0",
39
39
  "jest-transform-graphql": "^2.1.0",
40
- "shared": "^1.10.18",
40
+ "shared": "^1.10.30",
41
41
  "ts-jest": "25.5.1",
42
42
  "tsdx": "^0.14.1",
43
43
  "tslib": "^2.3.1",
@@ -46,5 +46,5 @@
46
46
  "peerDependencies": {
47
47
  "graphql": "^15.6.0"
48
48
  },
49
- "gitHead": "a6f5e44b68bde5b811a345bffb7bec697e8f3933"
49
+ "gitHead": "a4337522ffdc57ff2ab8edb8aa97583eb0fc361f"
50
50
  }
@@ -12,6 +12,14 @@ export type Scalars = {
12
12
  ObjectOrString: any;
13
13
  };
14
14
 
15
+ /** Person data input to the newsletter. */
16
+ export type IPersonNewsletter = {
17
+ /** Person's email. */
18
+ email: Scalars['String'];
19
+ /** Person's name. */
20
+ name: Scalars['String'];
21
+ };
22
+
15
23
  /** Shopping cart input. */
16
24
  export type IStoreCart = {
17
25
  /** Order information, including `orderNumber` and `acceptedOffer`. */
@@ -122,6 +130,8 @@ export type IStoreSession = {
122
130
 
123
131
  export type Mutation = {
124
132
  __typename?: 'Mutation';
133
+ /** Subscribes a new person to the newsletter list. */
134
+ subscribeToNewsletter?: Maybe<PersonNewsletter>;
125
135
  /** Checks for changes between the cart presented in the UI and the cart stored in the ecommerce platform. If changes are detected, it returns the cart stored on the platform. Otherwise, it returns `null`. */
126
136
  validateCart?: Maybe<StoreCart>;
127
137
  /** Updates a web session with the specified values. */
@@ -129,6 +139,11 @@ export type Mutation = {
129
139
  };
130
140
 
131
141
 
142
+ export type MutationSubscribeToNewsletterArgs = {
143
+ data: IPersonNewsletter;
144
+ };
145
+
146
+
132
147
  export type MutationValidateCartArgs = {
133
148
  cart: IStoreCart;
134
149
  };
@@ -139,6 +154,13 @@ export type MutationValidateSessionArgs = {
139
154
  session: IStoreSession;
140
155
  };
141
156
 
157
+ /** Newsletter information. */
158
+ export type PersonNewsletter = {
159
+ __typename?: 'PersonNewsletter';
160
+ /** Person's ID in the newsletter list. */
161
+ id: Scalars['String'];
162
+ };
163
+
142
164
  export type Query = {
143
165
  __typename?: 'Query';
144
166
  /** Returns information about all collections. */
@@ -16,6 +16,7 @@ import type {
16
16
  import type { Session } from './types/Session'
17
17
  import type { Channel } from '../../utils/channel'
18
18
  import type { SalesChannel } from './types/SalesChannel'
19
+ import { MasterDataResponse } from './types/Newsletter'
19
20
 
20
21
  type ValueOf<T> = T extends Record<string, infer K> ? K : never
21
22
 
@@ -178,5 +179,15 @@ export const VtexCommerce = (
178
179
  body: '{}',
179
180
  })
180
181
  },
182
+ subscribeToNewsletter: (data: {
183
+ name: string
184
+ email: string
185
+ }): Promise<MasterDataResponse> => {
186
+ return fetchAPI(`${base}/api/dataentities/NL/documents/`, {
187
+ ...BASE_INIT,
188
+ body: JSON.stringify({ ...data, isNewsletterOptIn: true }),
189
+ method: 'PATCH',
190
+ })
191
+ },
181
192
  }
182
193
  }
@@ -0,0 +1,4 @@
1
+ export interface MasterDataResponse {
2
+ Id: string
3
+ Href: string
4
+ }
@@ -11,8 +11,11 @@ const isBrand = (x: any): x is Brand | CollectionPageType =>
11
11
  x.type === 'brand' ||
12
12
  (isCollectionPageType(x) && x.pageType.toLowerCase() === 'brand')
13
13
 
14
+ const isCollection = (x: Root): x is CollectionPageType =>
15
+ isCollectionPageType(x) && x.pageType.toLowerCase() === 'collection'
16
+
14
17
  const slugifyRoot = (root: Root) => {
15
- if (isBrand(root)) {
18
+ if (isBrand(root) || isCollection(root)) {
16
19
  return slugify(root.name)
17
20
  }
18
21
 
@@ -1,7 +1,9 @@
1
+ import { subscribeToNewsletter } from './subscribeToNewsletter'
1
2
  import { validateCart } from './validateCart'
2
3
  import { validateSession } from './validateSession'
3
4
 
4
5
  export const Mutation = {
5
6
  validateCart,
6
7
  validateSession,
8
+ subscribeToNewsletter,
7
9
  }
@@ -0,0 +1,14 @@
1
+ import type { Context } from '..'
2
+ import type {
3
+ MutationSubscribeToNewsletterArgs,
4
+ PersonNewsletter,
5
+ } from '../../../__generated__/schema'
6
+
7
+ export const subscribeToNewsletter = async (
8
+ _: any,
9
+ { data }: MutationSubscribeToNewsletterArgs,
10
+ { clients: { commerce } }: Context
11
+ ): Promise<PersonNewsletter | null> => {
12
+ const response = await commerce.subscribeToNewsletter(data)
13
+ return { id: response?.Id }
14
+ }
@@ -24,6 +24,7 @@ import PropertyValue from './propertyValue.graphql'
24
24
  import Person from './person.graphql'
25
25
  import ObjectOrString from './objectOrString.graphql'
26
26
  import Session from './session.graphql'
27
+ import Newsletter from './newsletter.graphql'
27
28
 
28
29
  export const typeDefs = [
29
30
  Query,
@@ -50,6 +51,7 @@ export const typeDefs = [
50
51
  Person,
51
52
  ObjectOrString,
52
53
  Session,
54
+ Newsletter
53
55
  ]
54
56
  .map(print)
55
57
  .join('\n')
@@ -7,4 +7,8 @@ type Mutation {
7
7
  Updates a web session with the specified values.
8
8
  """
9
9
  validateSession(session: IStoreSession!, search: String!): StoreSession
10
+ """
11
+ Subscribes a new person to the newsletter list.
12
+ """
13
+ subscribeToNewsletter(data: IPersonNewsletter!): PersonNewsletter
10
14
  }
@@ -0,0 +1,24 @@
1
+ """
2
+ Newsletter information.
3
+ """
4
+
5
+ type PersonNewsletter {
6
+ """
7
+ Person's ID in the newsletter list.
8
+ """
9
+ id: String!
10
+ }
11
+
12
+ """
13
+ Person data input to the newsletter.
14
+ """
15
+ input IPersonNewsletter {
16
+ """
17
+ Person's name.
18
+ """
19
+ name: String!
20
+ """
21
+ Person's email.
22
+ """
23
+ email: String!
24
+ }