@faststore/api 3.64.0 → 3.65.1

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.
Files changed (88) hide show
  1. package/dist/cjs/package.json +1 -1
  2. package/dist/cjs/src/__generated__/schema.d.ts +249 -0
  3. package/dist/cjs/src/__generated__/schema.d.ts.map +1 -1
  4. package/dist/cjs/src/__generated__/schema.js +1 -0
  5. package/dist/cjs/src/__generated__/schema.js.map +1 -1
  6. package/dist/cjs/src/index.d.ts +18 -0
  7. package/dist/cjs/src/index.d.ts.map +1 -1
  8. package/dist/cjs/src/platforms/vtex/clients/commerce/index.d.ts +10 -1
  9. package/dist/cjs/src/platforms/vtex/clients/commerce/index.d.ts.map +1 -1
  10. package/dist/cjs/src/platforms/vtex/clients/commerce/index.js +32 -4
  11. package/dist/cjs/src/platforms/vtex/clients/commerce/index.js.map +1 -1
  12. package/dist/cjs/src/platforms/vtex/clients/index.d.ts +9 -0
  13. package/dist/cjs/src/platforms/vtex/clients/index.d.ts.map +1 -1
  14. package/dist/cjs/src/platforms/vtex/index.d.ts +18 -0
  15. package/dist/cjs/src/platforms/vtex/index.d.ts.map +1 -1
  16. package/dist/cjs/src/platforms/vtex/resolvers/mutation.d.ts +3 -0
  17. package/dist/cjs/src/platforms/vtex/resolvers/mutation.d.ts.map +1 -1
  18. package/dist/cjs/src/platforms/vtex/resolvers/mutation.js +2 -0
  19. package/dist/cjs/src/platforms/vtex/resolvers/mutation.js.map +1 -1
  20. package/dist/cjs/src/platforms/vtex/resolvers/processOrderAuthorization.d.ts +6 -0
  21. package/dist/cjs/src/platforms/vtex/resolvers/processOrderAuthorization.d.ts.map +1 -0
  22. package/dist/cjs/src/platforms/vtex/resolvers/processOrderAuthorization.js +18 -0
  23. package/dist/cjs/src/platforms/vtex/resolvers/processOrderAuthorization.js.map +1 -0
  24. package/dist/cjs/src/platforms/vtex/resolvers/query.d.ts +14 -1
  25. package/dist/cjs/src/platforms/vtex/resolvers/query.d.ts.map +1 -1
  26. package/dist/cjs/src/platforms/vtex/resolvers/query.js +64 -0
  27. package/dist/cjs/src/platforms/vtex/resolvers/query.js.map +1 -1
  28. package/dist/cjs/src/platforms/vtex/resolvers/validateCart.d.ts.map +1 -1
  29. package/dist/cjs/src/platforms/vtex/resolvers/validateCart.js +8 -4
  30. package/dist/cjs/src/platforms/vtex/resolvers/validateCart.js.map +1 -1
  31. package/dist/cjs/src/platforms/vtex/utils/commercialAuth.d.ts +12 -0
  32. package/dist/cjs/src/platforms/vtex/utils/commercialAuth.d.ts.map +1 -0
  33. package/dist/cjs/src/platforms/vtex/utils/commercialAuth.js +44 -0
  34. package/dist/cjs/src/platforms/vtex/utils/commercialAuth.js.map +1 -0
  35. package/dist/cjs/src/typeDefs/mutation.graphql +6 -0
  36. package/dist/cjs/src/typeDefs/orderCommercialAuthorizaton.graphql +399 -0
  37. package/dist/cjs/src/typeDefs/query.graphql +43 -0
  38. package/dist/cjs/src/typeDefs/userOrder.graphql +4 -0
  39. package/dist/esm/package.json +1 -1
  40. package/dist/esm/src/__generated__/schema.d.ts +249 -0
  41. package/dist/esm/src/__generated__/schema.d.ts.map +1 -1
  42. package/dist/esm/src/__generated__/schema.js +1 -0
  43. package/dist/esm/src/__generated__/schema.js.map +1 -1
  44. package/dist/esm/src/index.d.ts +18 -0
  45. package/dist/esm/src/index.d.ts.map +1 -1
  46. package/dist/esm/src/platforms/vtex/clients/commerce/index.d.ts +10 -1
  47. package/dist/esm/src/platforms/vtex/clients/commerce/index.d.ts.map +1 -1
  48. package/dist/esm/src/platforms/vtex/clients/commerce/index.js +32 -4
  49. package/dist/esm/src/platforms/vtex/clients/commerce/index.js.map +1 -1
  50. package/dist/esm/src/platforms/vtex/clients/index.d.ts +9 -0
  51. package/dist/esm/src/platforms/vtex/clients/index.d.ts.map +1 -1
  52. package/dist/esm/src/platforms/vtex/index.d.ts +18 -0
  53. package/dist/esm/src/platforms/vtex/index.d.ts.map +1 -1
  54. package/dist/esm/src/platforms/vtex/resolvers/mutation.d.ts +3 -0
  55. package/dist/esm/src/platforms/vtex/resolvers/mutation.d.ts.map +1 -1
  56. package/dist/esm/src/platforms/vtex/resolvers/mutation.js +2 -0
  57. package/dist/esm/src/platforms/vtex/resolvers/mutation.js.map +1 -1
  58. package/dist/esm/src/platforms/vtex/resolvers/processOrderAuthorization.d.ts +6 -0
  59. package/dist/esm/src/platforms/vtex/resolvers/processOrderAuthorization.d.ts.map +1 -0
  60. package/dist/esm/src/platforms/vtex/resolvers/processOrderAuthorization.js +14 -0
  61. package/dist/esm/src/platforms/vtex/resolvers/processOrderAuthorization.js.map +1 -0
  62. package/dist/esm/src/platforms/vtex/resolvers/query.d.ts +14 -1
  63. package/dist/esm/src/platforms/vtex/resolvers/query.d.ts.map +1 -1
  64. package/dist/esm/src/platforms/vtex/resolvers/query.js +64 -0
  65. package/dist/esm/src/platforms/vtex/resolvers/query.js.map +1 -1
  66. package/dist/esm/src/platforms/vtex/resolvers/validateCart.d.ts.map +1 -1
  67. package/dist/esm/src/platforms/vtex/resolvers/validateCart.js +8 -4
  68. package/dist/esm/src/platforms/vtex/resolvers/validateCart.js.map +1 -1
  69. package/dist/esm/src/platforms/vtex/utils/commercialAuth.d.ts +12 -0
  70. package/dist/esm/src/platforms/vtex/utils/commercialAuth.d.ts.map +1 -0
  71. package/dist/esm/src/platforms/vtex/utils/commercialAuth.js +39 -0
  72. package/dist/esm/src/platforms/vtex/utils/commercialAuth.js.map +1 -0
  73. package/dist/esm/src/typeDefs/mutation.graphql +6 -0
  74. package/dist/esm/src/typeDefs/orderCommercialAuthorizaton.graphql +399 -0
  75. package/dist/esm/src/typeDefs/query.graphql +43 -0
  76. package/dist/esm/src/typeDefs/userOrder.graphql +4 -0
  77. package/package.json +2 -2
  78. package/src/__generated__/schema.ts +268 -0
  79. package/src/platforms/vtex/clients/commerce/index.ts +65 -4
  80. package/src/platforms/vtex/resolvers/mutation.ts +2 -0
  81. package/src/platforms/vtex/resolvers/processOrderAuthorization.ts +30 -0
  82. package/src/platforms/vtex/resolvers/query.ts +87 -0
  83. package/src/platforms/vtex/resolvers/validateCart.ts +9 -4
  84. package/src/platforms/vtex/utils/commercialAuth.ts +55 -0
  85. package/src/typeDefs/mutation.graphql +6 -0
  86. package/src/typeDefs/orderCommercialAuthorizaton.graphql +399 -0
  87. package/src/typeDefs/query.graphql +43 -0
  88. package/src/typeDefs/userOrder.graphql +4 -0
@@ -129,6 +129,200 @@ export type AvailableDeliveryWindows = {
129
129
  tax?: Maybe<Scalars['Int']>;
130
130
  };
131
131
 
132
+ /** Commercial Authorization dimension status. */
133
+ export type CommercialAuthorizationDimensionStatus = {
134
+ __typename?: 'CommercialAuthorizationDimensionStatus';
135
+ /** Creation date. */
136
+ creationDate: Scalars['String'];
137
+ /** Creation environment. */
138
+ creationEnvironment: Scalars['String'];
139
+ /** Creation version. */
140
+ creationVersion: Scalars['String'];
141
+ /** Dimension status ID. */
142
+ id: Scalars['String'];
143
+ /** Dimension status name. */
144
+ name: Scalars['String'];
145
+ /** Priority level. */
146
+ priority: Scalars['Int'];
147
+ /** Indicates if all rules acceptance is required. */
148
+ requireAllRulesAcceptance: Scalars['Boolean'];
149
+ /** Collection of rules for this dimension. */
150
+ ruleCollection: Array<CommercialAuthorizationRule>;
151
+ /** Dimension score. */
152
+ score: Scalars['Float'];
153
+ /** Indicates if simulation should be performed. */
154
+ shouldSimulate: Scalars['Boolean'];
155
+ /** Current status of the dimension. */
156
+ status: CommercialAuthorizationStatus;
157
+ /** Unit ID, if applicable. */
158
+ unitId?: Maybe<Scalars['String']>;
159
+ };
160
+
161
+ /** Commercial Authorization item. */
162
+ export type CommercialAuthorizationItem = {
163
+ __typename?: 'CommercialAuthorizationItem';
164
+ /** Additional information as key-value pairs. */
165
+ additionalInfo: Scalars['JSONObject'];
166
+ /** Item ID. */
167
+ id: Scalars['String'];
168
+ /** Item price. */
169
+ price: Scalars['Float'];
170
+ /** Item quantity. */
171
+ quantity: Scalars['Int'];
172
+ /** Item SKU. */
173
+ sku: Scalars['String'];
174
+ /** Total manual discount applied. */
175
+ totalManualDiscount: Scalars['Float'];
176
+ /** Total system discount applied. */
177
+ totalSystemDiscount: Scalars['Float'];
178
+ };
179
+
180
+ /** Commercial Authorization response. */
181
+ export type CommercialAuthorizationResponse = {
182
+ __typename?: 'CommercialAuthorizationResponse';
183
+ /** Additional information as key-value pairs. */
184
+ additionalInfo: Scalars['JSONObject'];
185
+ /** Callback endpoint URL. */
186
+ callbackEndpoint: Scalars['String'];
187
+ /** Creation environment. */
188
+ creationEnvironment: Scalars['String'];
189
+ /** Creation version. */
190
+ creationVersion: Scalars['String'];
191
+ /** Dimension status information. */
192
+ dimensionStatus: Array<CommercialAuthorizationDimensionStatus>;
193
+ /** Commercial Authorization ID. */
194
+ id: Scalars['String'];
195
+ /** Collection of items in the commercial authorization. */
196
+ itemCollection: Array<CommercialAuthorizationItem>;
197
+ /** Marketplace payment value. */
198
+ marketPlacePaymentValue: Scalars['Float'];
199
+ /** Order ID associated with the commercial authorization. */
200
+ orderId: Scalars['String'];
201
+ /** Current status of the commercial authorization. */
202
+ status: CommercialAuthorizationStatus;
203
+ /** Total order value desired by the seller. */
204
+ totalOrderValueDesiredBySeller: Scalars['Float'];
205
+ /** List of units. */
206
+ units: Array<Scalars['String']>;
207
+ /** User profile ID. */
208
+ userProfileId: Scalars['String'];
209
+ /** Workflow instance ID. */
210
+ workflowInstanceId: Scalars['String'];
211
+ };
212
+
213
+ /** Commercial Authorization rule. */
214
+ export type CommercialAuthorizationRule = {
215
+ __typename?: 'CommercialAuthorizationRule';
216
+ /** Authorization data, if available. */
217
+ authorizationData?: Maybe<CommercialAuthorizationRuleAuthorizationData>;
218
+ /** List of authorized email addresses. */
219
+ authorizedEmails: Array<Scalars['String']>;
220
+ /** DO ID, if applicable. */
221
+ doId?: Maybe<Scalars['String']>;
222
+ /** Rule ID. */
223
+ id: Scalars['String'];
224
+ /**
225
+ * Indicates that the user is listed as one of the possible approvers,
226
+ * but does not necessarily mean that he or she is the next in the chain to approve.
227
+ */
228
+ isUserAuthorized: Scalars['Boolean'];
229
+ /**
230
+ * Indicates that the user is next in the approval chain.
231
+ * This means that they must take an approval or rejection action.
232
+ */
233
+ isUserNextAuthorizer: Scalars['Boolean'];
234
+ /** Rule name. */
235
+ name: Scalars['String'];
236
+ /** Indicates if notification is enabled. */
237
+ notification: Scalars['Boolean'];
238
+ /** Rule priority. */
239
+ priority: Scalars['Int'];
240
+ /** Score interval configuration. */
241
+ scoreInterval: CommercialAuthorizationRuleScoreInterval;
242
+ /** Current status of the rule. */
243
+ status: CommercialAuthorizationStatus;
244
+ /** Timeout value. */
245
+ timeout: Scalars['Int'];
246
+ /** Rule trigger configuration. */
247
+ trigger: CommercialAuthorizationRuleTrigger;
248
+ };
249
+
250
+ /** Commercial Authorization rule authorization data. */
251
+ export type CommercialAuthorizationRuleAuthorizationData = {
252
+ __typename?: 'CommercialAuthorizationRuleAuthorizationData';
253
+ /** List of authorizers. */
254
+ authorizers: Array<CommercialAuthorizationRuleAuthorizer>;
255
+ /** Indicates if all approvals are required. */
256
+ requireAllApprovals: Scalars['Boolean'];
257
+ };
258
+
259
+ /** Commercial Authorization rule authorizer. */
260
+ export type CommercialAuthorizationRuleAuthorizer = {
261
+ __typename?: 'CommercialAuthorizationRuleAuthorizer';
262
+ /** Authorization date. */
263
+ authorizationDate?: Maybe<Scalars['String']>;
264
+ /** Authorizer email. */
265
+ email?: Maybe<Scalars['String']>;
266
+ /** Authorizer ID. */
267
+ id: Scalars['String'];
268
+ /** Authorizer type. */
269
+ type: Scalars['String'];
270
+ };
271
+
272
+ /** Commercial Authorization rule score interval. */
273
+ export type CommercialAuthorizationRuleScoreInterval = {
274
+ __typename?: 'CommercialAuthorizationRuleScoreInterval';
275
+ /** Accept score threshold. */
276
+ accept: Scalars['Float'];
277
+ /** Deny score threshold. */
278
+ deny: Scalars['Float'];
279
+ };
280
+
281
+ /** Commercial Authorization rule trigger. */
282
+ export type CommercialAuthorizationRuleTrigger = {
283
+ __typename?: 'CommercialAuthorizationRuleTrigger';
284
+ /** Trigger condition. */
285
+ condition: CommercialAuthorizationRuleTriggerCondition;
286
+ /** Trigger effect. */
287
+ effect: CommercialAuthorizationRuleTriggerEffect;
288
+ };
289
+
290
+ /** Commercial Authorization rule trigger condition. */
291
+ export type CommercialAuthorizationRuleTriggerCondition = {
292
+ __typename?: 'CommercialAuthorizationRuleTriggerCondition';
293
+ /** Condition type. */
294
+ conditionType: Scalars['Int'];
295
+ /** Condition description. */
296
+ description?: Maybe<Scalars['String']>;
297
+ /** Condition expression. */
298
+ expression?: Maybe<Scalars['String']>;
299
+ /** Greater than value. */
300
+ greatherThan?: Maybe<Scalars['Float']>;
301
+ /** Less than value. */
302
+ lessThan?: Maybe<Scalars['Float']>;
303
+ };
304
+
305
+ /** Commercial Authorization rule trigger effect. */
306
+ export type CommercialAuthorizationRuleTriggerEffect = {
307
+ __typename?: 'CommercialAuthorizationRuleTriggerEffect';
308
+ /** Effect description. */
309
+ description?: Maybe<Scalars['String']>;
310
+ /** Effect type. */
311
+ effectType: Scalars['Int'];
312
+ /** Function path. */
313
+ funcPath?: Maybe<Scalars['String']>;
314
+ };
315
+
316
+ /** Commercial Authorization status. */
317
+ export const enum CommercialAuthorizationStatus {
318
+ /** Authorization has been accepted. */
319
+ Accepted = 'accepted',
320
+ /** Authorization has been denied. */
321
+ Denied = 'denied',
322
+ /** Authorization is pending. */
323
+ Pending = 'pending'
324
+ };
325
+
132
326
  export type DeliveryIds = {
133
327
  __typename?: 'DeliveryIds';
134
328
  /** DeliveryIds courier id */
@@ -143,6 +337,12 @@ export type DeliveryIds = {
143
337
  warehouseId?: Maybe<Scalars['String']>;
144
338
  };
145
339
 
340
+ /** Input to get commercial authorizations by order ID. */
341
+ export type ICommercialAuthorizationByOrderId = {
342
+ /** Order ID to get commercial authorizations for. */
343
+ orderId: Scalars['String'];
344
+ };
345
+
146
346
  export type IGeoCoordinates = {
147
347
  /** The latitude of the geographic coordinates. */
148
348
  latitude: Scalars['Float'];
@@ -158,6 +358,18 @@ export type IPersonNewsletter = {
158
358
  name: Scalars['String'];
159
359
  };
160
360
 
361
+ /** Input to process order authorization (approve or reject). */
362
+ export type IProcessOrderAuthorization = {
363
+ /** Whether the authorization is approved (true) or rejected (false). */
364
+ approved: Scalars['Boolean'];
365
+ /** Dimension ID associated with the authorization. */
366
+ dimensionId: Scalars['String'];
367
+ /** Order authorization ID. */
368
+ orderAuthorizationId: Scalars['String'];
369
+ /** Rule ID associated with the authorization. */
370
+ ruleId: Scalars['String'];
371
+ };
372
+
161
373
  /** Shipping Simulation item input. */
162
374
  export type IShippingItem = {
163
375
  /** ShippingItem ID / Sku. */
@@ -413,6 +625,8 @@ export type Mutation = {
413
625
  __typename?: 'Mutation';
414
626
  /** Cancels user order */
415
627
  cancelOrder?: Maybe<UserOrderCancel>;
628
+ /** Process Order Authorization */
629
+ processOrderAuthorization?: Maybe<ProcessOrderAuthorizationResponse>;
416
630
  /** Subscribes a new person to the newsletter list. */
417
631
  subscribeToNewsletter?: Maybe<PersonNewsletter>;
418
632
  /** 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`. */
@@ -427,6 +641,11 @@ export type MutationCancelOrderArgs = {
427
641
  };
428
642
 
429
643
 
644
+ export type MutationProcessOrderAuthorizationArgs = {
645
+ data: IProcessOrderAuthorization;
646
+ };
647
+
648
+
430
649
  export type MutationSubscribeToNewsletterArgs = {
431
650
  data: IPersonNewsletter;
432
651
  };
@@ -494,6 +713,26 @@ export type PickupStoreInfo = {
494
713
  isPickupStore?: Maybe<Scalars['Boolean']>;
495
714
  };
496
715
 
716
+ /** Process Order Authorization response. */
717
+ export type ProcessOrderAuthorizationResponse = {
718
+ __typename?: 'ProcessOrderAuthorizationResponse';
719
+ /** Indicates if authorization is pending for other authorizers. */
720
+ isPendingForOtherAuthorizer: Scalars['Boolean'];
721
+ /** The updated rule for authorization, if any. */
722
+ ruleForAuthorization?: Maybe<ProcessOrderAuthorizationRule>;
723
+ };
724
+
725
+ /** Extended Commercial Authorization rule with additional process context. */
726
+ export type ProcessOrderAuthorizationRule = {
727
+ __typename?: 'ProcessOrderAuthorizationRule';
728
+ /** Dimension ID. */
729
+ dimensionId: Scalars['String'];
730
+ /** Order authorization ID. */
731
+ orderAuthorizationId: Scalars['String'];
732
+ /** Base rule information. */
733
+ rule: CommercialAuthorizationRule;
734
+ };
735
+
497
736
  export type ProductCountResult = {
498
737
  __typename?: 'ProductCountResult';
499
738
  /** Total product count. */
@@ -540,6 +779,8 @@ export type Query = {
540
779
  __typename?: 'Query';
541
780
  /** Returns the account name of the current user or the B2B contract name if applicable. */
542
781
  accountName?: Maybe<Scalars['String']>;
782
+ /** Returns the account profile information for the current authenticated user (b2b or b2c user). */
783
+ accountProfile: StoreAccountProfile;
543
784
  /** Returns information about all collections. */
544
785
  allCollections: StoreCollectionConnection;
545
786
  /** Returns information about all products. */
@@ -562,6 +803,8 @@ export type Query = {
562
803
  sellers?: Maybe<SellersData>;
563
804
  /** Returns information about shipping simulation. */
564
805
  shipping?: Maybe<ShippingData>;
806
+ /** Returns information about the current user details. */
807
+ userDetails: StoreUserDetails;
565
808
  /** Returns information about the Details of an User Order. */
566
809
  userOrder?: Maybe<UserOrderResult>;
567
810
  /** Returns information about the user validation. */
@@ -763,6 +1006,14 @@ export type SkuVariantsSlugsMapArgs = {
763
1006
  dominantVariantName?: Maybe<Scalars['String']>;
764
1007
  };
765
1008
 
1009
+ /** Account profile information. */
1010
+ export type StoreAccountProfile = {
1011
+ __typename?: 'StoreAccountProfile';
1012
+ email?: Maybe<Scalars['String']>;
1013
+ id?: Maybe<Scalars['String']>;
1014
+ name?: Maybe<Scalars['String']>;
1015
+ };
1016
+
766
1017
  /** Aggregate offer information, for a given SKU that is available to be fulfilled by multiple sellers. */
767
1018
  export type StoreAggregateOffer = {
768
1019
  __typename?: 'StoreAggregateOffer';
@@ -1336,6 +1587,19 @@ export type StoreSuggestions = {
1336
1587
  terms: Array<StoreSuggestionTerm>;
1337
1588
  };
1338
1589
 
1590
+ /** User details information. */
1591
+ export type StoreUserDetails = {
1592
+ __typename?: 'StoreUserDetails';
1593
+ /** User's email. */
1594
+ email?: Maybe<Scalars['String']>;
1595
+ /** User's name. */
1596
+ name?: Maybe<Scalars['String']>;
1597
+ /** User's organizational unit. */
1598
+ orgUnit?: Maybe<Scalars['String']>;
1599
+ /** User's role. */
1600
+ role?: Maybe<Array<Maybe<Scalars['String']>>>;
1601
+ };
1602
+
1339
1603
  export type UserOrder = {
1340
1604
  __typename?: 'UserOrder';
1341
1605
  affiliateId?: Maybe<Scalars['String']>;
@@ -1343,6 +1607,7 @@ export type UserOrder = {
1343
1607
  allowEdition?: Maybe<Scalars['Boolean']>;
1344
1608
  authorizedDate?: Maybe<Scalars['String']>;
1345
1609
  callCenterOperatorData?: Maybe<Scalars['String']>;
1610
+ canProcessOrderAuthorization?: Maybe<Scalars['Boolean']>;
1346
1611
  cancelReason?: Maybe<Scalars['String']>;
1347
1612
  cancellationData?: Maybe<UserOrderCancellationData>;
1348
1613
  cancellationRequests?: Maybe<Array<Maybe<UserOrderCancellationRequest>>>;
@@ -1381,6 +1646,7 @@ export type UserOrder = {
1381
1646
  paymentData?: Maybe<UserOrderPaymentData>;
1382
1647
  ratesAndBenefitsData?: Maybe<UserOrderRatesAndBenefitsData>;
1383
1648
  roundingError?: Maybe<Scalars['Int']>;
1649
+ ruleForAuthorization?: Maybe<ProcessOrderAuthorizationRule>;
1384
1650
  salesChannel?: Maybe<Scalars['String']>;
1385
1651
  sellerOrderId?: Maybe<Scalars['String']>;
1386
1652
  sellers?: Maybe<Array<Maybe<UserOrderStoreSellers>>>;
@@ -2051,6 +2317,7 @@ export type UserOrderRestitutions = {
2051
2317
  export type UserOrderResult = {
2052
2318
  __typename?: 'UserOrderResult';
2053
2319
  allowCancellation?: Maybe<Scalars['Boolean']>;
2320
+ canProcessOrderAuthorization?: Maybe<Scalars['Boolean']>;
2054
2321
  clientProfileData?: Maybe<UserOrderClientProfileData>;
2055
2322
  customData?: Maybe<UserOrderCustomData>;
2056
2323
  customFields?: Maybe<Array<Maybe<UserOrderCustomFieldsGrouped>>>;
@@ -2058,6 +2325,7 @@ export type UserOrderResult = {
2058
2325
  items?: Maybe<Array<Maybe<UserOrderItems>>>;
2059
2326
  orderId?: Maybe<Scalars['String']>;
2060
2327
  paymentData?: Maybe<UserOrderPaymentData>;
2328
+ ruleForAuthorization?: Maybe<ProcessOrderAuthorizationRule>;
2061
2329
  shippingData?: Maybe<UserOrderShippingData>;
2062
2330
  status?: Maybe<Scalars['String']>;
2063
2331
  statusDescription?: Maybe<Scalars['String']>;
@@ -3,6 +3,9 @@ import type { FACET_CROSS_SELLING_MAP } from '../../utils/facets'
3
3
  import { fetchAPI } from '../fetch'
4
4
 
5
5
  import type {
6
+ CommercialAuthorizationResponse,
7
+ ICommercialAuthorizationByOrderId,
8
+ IProcessOrderAuthorization,
6
9
  IUserOrderCancel,
7
10
  QueryListUserOrdersArgs,
8
11
  StoreMarketingData,
@@ -441,10 +444,7 @@ export const VtexCommerce = (
441
444
  },
442
445
  oms: {
443
446
  userOrder: ({ orderId }: { orderId: string }): Promise<UserOrder> => {
444
- const headers: HeadersInit = withCookie({
445
- 'content-type': 'application/json',
446
- 'X-FORWARDED-HOST': forwardedHost,
447
- })
447
+ const headers: HeadersInit = withAutCookie(forwardedHost, account)
448
448
 
449
449
  return fetchAPI(
450
450
  `${base}/api/oms/user/orders/${orderId}`,
@@ -520,6 +520,49 @@ export const VtexCommerce = (
520
520
  { storeCookies }
521
521
  )
522
522
  },
523
+ getCommercialAuthorizationsByOrderId: ({
524
+ orderId,
525
+ }: ICommercialAuthorizationByOrderId): Promise<CommercialAuthorizationResponse> => {
526
+ const headers: HeadersInit = withAutCookie(forwardedHost, account)
527
+
528
+ return fetchAPI(
529
+ `${base}/${account}/commercial-authorizations/order/${orderId}`,
530
+ {
531
+ method: 'GET',
532
+ headers,
533
+ },
534
+ { storeCookies }
535
+ )
536
+ },
537
+ processOrderAuthorization: async ({
538
+ orderAuthorizationId,
539
+ dimensionId,
540
+ ruleId,
541
+ approved,
542
+ }: IProcessOrderAuthorization): Promise<CommercialAuthorizationResponse> => {
543
+ const headers: HeadersInit = withAutCookie(forwardedHost, account)
544
+
545
+ const APPROVAL_SCORE = 100
546
+ const REJECTION_SCORE = 0
547
+
548
+ const body = {
549
+ params: {
550
+ ruleId,
551
+ dimensionId,
552
+ score: approved ? APPROVAL_SCORE : REJECTION_SCORE,
553
+ },
554
+ }
555
+
556
+ return fetchAPI(
557
+ `${base}/${account}/commercial-authorizations/${orderAuthorizationId}/callback`,
558
+ {
559
+ method: 'POST',
560
+ headers,
561
+ body: JSON.stringify(body),
562
+ },
563
+ { storeCookies }
564
+ )
565
+ },
523
566
  },
524
567
  units: {
525
568
  getUnitByUserId: ({
@@ -584,6 +627,24 @@ export const VtexCommerce = (
584
627
  {}
585
628
  )
586
629
  },
630
+ getUserByEmail: ({
631
+ email,
632
+ }: { email: string }): Promise<{
633
+ id: string
634
+ name: string
635
+ email: string
636
+ }> => {
637
+ const headers: HeadersInit = withAutCookie(forwardedHost, account)
638
+
639
+ return fetchAPI(
640
+ `${base}/api/license-manager/pvt/users/${email}`,
641
+ {
642
+ method: 'GET',
643
+ headers,
644
+ },
645
+ {}
646
+ )
647
+ },
587
648
  },
588
649
  masterData: {
589
650
  getContractById: ({
@@ -1,4 +1,5 @@
1
1
  import { cancelOrder } from './cancelOrder'
2
+ import { processOrderAuthorization } from './processOrderAuthorization'
2
3
  import { subscribeToNewsletter } from './subscribeToNewsletter'
3
4
  import { validateCart } from './validateCart'
4
5
  import { validateSession } from './validateSession'
@@ -8,4 +9,5 @@ export const Mutation = {
8
9
  validateSession,
9
10
  subscribeToNewsletter,
10
11
  cancelOrder,
12
+ processOrderAuthorization,
11
13
  }
@@ -0,0 +1,30 @@
1
+ import type { Context } from '..'
2
+ import type {
3
+ ProcessOrderAuthorizationResponse,
4
+ IProcessOrderAuthorization,
5
+ } from '../../../__generated__/schema'
6
+ import {
7
+ extractRuleForAuthorization,
8
+ isPendingForOtherAuthorizer,
9
+ } from '../utils/commercialAuth'
10
+
11
+ export const processOrderAuthorization = async (
12
+ _: any,
13
+ { data }: { data: IProcessOrderAuthorization },
14
+ { clients: { commerce } }: Context
15
+ ): Promise<ProcessOrderAuthorizationResponse | null> => {
16
+ // Process the authorization
17
+ const commercialAuth = await commerce.oms.processOrderAuthorization(data)
18
+
19
+ // Extract pending authorization for current user
20
+ const ruleForAuthorization = extractRuleForAuthorization(commercialAuth)
21
+
22
+ // Check if there are pending authorizations for other users
23
+ const isPendingForOther =
24
+ !ruleForAuthorization && isPendingForOtherAuthorizer(commercialAuth)
25
+
26
+ return {
27
+ isPendingForOtherAuthorizer: isPendingForOther,
28
+ ruleForAuthorization,
29
+ }
30
+ }
@@ -1,4 +1,5 @@
1
1
  import type {
2
+ ProcessOrderAuthorizationRule,
2
3
  QueryAllCollectionsArgs,
3
4
  QueryAllProductsArgs,
4
5
  QueryCollectionArgs,
@@ -32,6 +33,7 @@ import {
32
33
  import { isValidSkuId, pickBestSku } from '../utils/sku'
33
34
  import { SORT_MAP } from '../utils/sort'
34
35
  import { FACET_CROSS_SELLING_MAP } from './../utils/facets'
36
+ import { extractRuleForAuthorization } from '../utils/commercialAuth'
35
37
  import { StoreCollection } from './collection'
36
38
 
37
39
  export const Query = {
@@ -400,6 +402,20 @@ export const Query = {
400
402
  throw new NotFoundError(`No order found for id ${orderId}`)
401
403
  }
402
404
 
405
+ let ruleForAuthorization: ProcessOrderAuthorizationRule | null = null
406
+
407
+ try {
408
+ /**
409
+ * This endpoint could return a 404 error if has not an authorization
410
+ * for the order, so we catch the error and return null
411
+ * instead of throwing an error.
412
+ */
413
+ const commercialAuth =
414
+ await commerce.oms.getCommercialAuthorizationsByOrderId({ orderId })
415
+
416
+ ruleForAuthorization = extractRuleForAuthorization(commercialAuth)
417
+ } catch (err: any) {}
418
+
403
419
  return {
404
420
  orderId: order.orderId,
405
421
  totals: order.totals,
@@ -412,6 +428,11 @@ export const Query = {
412
428
  allowCancellation: order.allowCancellation,
413
429
  storePreferencesData: order.storePreferencesData,
414
430
  clientProfileData: order.clientProfileData,
431
+ canProcessOrderAuthorization:
432
+ (order.status === 'waiting-for-confirmation' ||
433
+ order.status === 'waiting-for-authorization') &&
434
+ !!ruleForAuthorization,
435
+ ruleForAuthorization,
415
436
  }
416
437
  } catch (error) {
417
438
  const result = JSON.parse((error as Error).message).error as {
@@ -514,4 +535,70 @@ export const Query = {
514
535
  throw new ForbiddenError('You are not allowed to access this resource')
515
536
  }
516
537
  },
538
+ // only b2b users
539
+ userDetails: async (_: unknown, __: unknown, ctx: Context) => {
540
+ const {
541
+ clients: { commerce },
542
+ } = ctx
543
+
544
+ // const params = new URLSearchParams()
545
+ const sessionData = await commerce.session('').catch(() => null)
546
+
547
+ const shopper = sessionData?.namespaces.shopper ?? null
548
+ const authentication = sessionData?.namespaces.authentication ?? null
549
+
550
+ return {
551
+ name: shopper?.firstName?.value ?? '',
552
+ email: authentication?.storeUserEmail.value ?? '',
553
+ role: ['Admin'], // TODO change when implemented roles,
554
+ orgUnit: authentication?.unitName?.value ?? '',
555
+ }
556
+ },
557
+ // If isRepresentative, return b2b information.
558
+ // If not, return b2c user information
559
+ accountProfile: async (_: unknown, __: unknown, ctx: Context) => {
560
+ const {
561
+ account,
562
+ headers,
563
+ clients: { commerce },
564
+ } = ctx
565
+
566
+ const jwt = parseJwt(getAuthCookie(headers?.cookie ?? '', account))
567
+
568
+ if (!jwt?.userId) {
569
+ return null
570
+ }
571
+
572
+ if (jwt?.isRepresentative) {
573
+ const sessionData = await commerce.session('').catch(() => null)
574
+
575
+ if (!sessionData) {
576
+ return null
577
+ }
578
+
579
+ const profile = sessionData.namespaces.profile ?? null
580
+
581
+ return {
582
+ name:
583
+ `${(profile?.firstName?.value ?? '').trim()} ${(profile?.lastName?.value ?? '').trim()}`.trim() ||
584
+ '',
585
+ email: profile?.email?.value || '',
586
+ id: profile?.id?.value || '',
587
+ // createdAt: '',
588
+ }
589
+ }
590
+
591
+ const user = await commerce.licenseManager
592
+ .getUserById({
593
+ userId: jwt?.userId,
594
+ })
595
+ .catch(() => null)
596
+
597
+ return {
598
+ name: user?.name || '',
599
+ email: user?.email || '',
600
+ id: user?.id || '',
601
+ // createdAt: '',
602
+ }
603
+ },
517
604
  }
@@ -1,5 +1,6 @@
1
1
  import deepEquals from 'fast-deep-equal'
2
2
 
3
+ import { parse } from 'cookie'
3
4
  import { mutateChannelContext, mutateLocaleContext } from '../utils/contex'
4
5
  import { md5 } from '../utils/md5'
5
6
  import {
@@ -7,7 +8,6 @@ import {
7
8
  getPropertyId,
8
9
  VALUE_REFERENCES,
9
10
  } from '../utils/propertyValue'
10
- import { parse } from 'cookie'
11
11
 
12
12
  import type { Context } from '..'
13
13
  import type {
@@ -23,10 +23,10 @@ import type {
23
23
  OrderFormInputItem,
24
24
  OrderFormItem,
25
25
  } from '../clients/commerce/types/OrderForm'
26
- import { shouldUpdateShippingData } from '../utils/shouldUpdateShippingData'
27
- import { getAddressOrderForm } from '../utils/getAddressOrderForm'
28
26
  import type { SelectedAddress } from '../clients/commerce/types/ShippingData'
29
27
  import { createNewAddress } from '../utils/createNewAddress'
28
+ import { getAddressOrderForm } from '../utils/getAddressOrderForm'
29
+ import { shouldUpdateShippingData } from '../utils/shouldUpdateShippingData'
30
30
 
31
31
  type Indexed<T> = T & { index?: number }
32
32
 
@@ -453,9 +453,14 @@ export const validateCart = async (
453
453
  // update marketingData
454
454
  .then((form: OrderForm) => {
455
455
  if (session?.marketingData) {
456
+ const updatedMarketingData = {
457
+ ...form.marketingData,
458
+ ...session.marketingData,
459
+ }
460
+
456
461
  return commerce.checkout.marketingData({
457
462
  id: orderForm.orderFormId,
458
- marketingData: session.marketingData,
463
+ marketingData: updatedMarketingData,
459
464
  })
460
465
  }
461
466