@faststore/api 4.4.1-dev.0 → 4.5.0-dev.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 (52) hide show
  1. package/dist/cjs/index.js +207 -41
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/es/index.mjs +1545 -1138
  4. package/dist/es/index.mjs.map +1 -1
  5. package/dist/src/__generated__/schema.d.ts +90 -0
  6. package/dist/src/__generated__/schema.d.ts.map +1 -1
  7. package/dist/src/platforms/vtex/clients/commerce/Contract.d.ts +1 -0
  8. package/dist/src/platforms/vtex/clients/commerce/Contract.d.ts.map +1 -1
  9. package/dist/src/platforms/vtex/clients/commerce/index.d.ts +16 -0
  10. package/dist/src/platforms/vtex/clients/commerce/index.d.ts.map +1 -1
  11. package/dist/src/platforms/vtex/clients/commerce/types/Quote.d.ts +26 -0
  12. package/dist/src/platforms/vtex/clients/commerce/types/Quote.d.ts.map +1 -0
  13. package/dist/src/platforms/vtex/clients/commerce/types/RecommendationResult.d.ts +25 -0
  14. package/dist/src/platforms/vtex/clients/commerce/types/RecommendationResult.d.ts.map +1 -0
  15. package/dist/src/platforms/vtex/clients/commerce/types/Session.d.ts +10 -0
  16. package/dist/src/platforms/vtex/clients/commerce/types/Session.d.ts.map +1 -1
  17. package/dist/src/platforms/vtex/clients/index.d.ts +7 -0
  18. package/dist/src/platforms/vtex/clients/index.d.ts.map +1 -1
  19. package/dist/src/platforms/vtex/index.d.ts +33 -0
  20. package/dist/src/platforms/vtex/index.d.ts.map +1 -1
  21. package/dist/src/platforms/vtex/resolvers/getOrderEntryOperation.d.ts.map +1 -1
  22. package/dist/src/platforms/vtex/resolvers/index.d.ts +33 -0
  23. package/dist/src/platforms/vtex/resolvers/index.d.ts.map +1 -1
  24. package/dist/src/platforms/vtex/resolvers/mutation.d.ts +1 -0
  25. package/dist/src/platforms/vtex/resolvers/mutation.d.ts.map +1 -1
  26. package/dist/src/platforms/vtex/resolvers/query.d.ts +33 -1
  27. package/dist/src/platforms/vtex/resolvers/query.d.ts.map +1 -1
  28. package/dist/src/platforms/vtex/resolvers/recommendations.d.ts +18 -0
  29. package/dist/src/platforms/vtex/resolvers/recommendations.d.ts.map +1 -0
  30. package/dist/src/platforms/vtex/resolvers/startRecommendationSession.d.ts +11 -0
  31. package/dist/src/platforms/vtex/resolvers/startRecommendationSession.d.ts.map +1 -0
  32. package/dist/src/platforms/vtex/resolvers/validateSession.d.ts.map +1 -1
  33. package/dist/src/platforms/vtex/utils/contract.d.ts +59 -0
  34. package/dist/src/platforms/vtex/utils/contract.d.ts.map +1 -0
  35. package/package.json +3 -3
  36. package/src/__generated__/schema.ts +102 -0
  37. package/src/platforms/vtex/clients/commerce/Contract.ts +1 -0
  38. package/src/platforms/vtex/clients/commerce/index.ts +188 -3
  39. package/src/platforms/vtex/clients/commerce/types/Quote.ts +27 -0
  40. package/src/platforms/vtex/clients/commerce/types/RecommendationResult.ts +27 -0
  41. package/src/platforms/vtex/clients/commerce/types/Session.ts +9 -0
  42. package/src/platforms/vtex/resolvers/mutation.ts +2 -0
  43. package/src/platforms/vtex/resolvers/query.ts +137 -3
  44. package/src/platforms/vtex/resolvers/recommendations.ts +80 -0
  45. package/src/platforms/vtex/resolvers/startRecommendationSession.ts +30 -0
  46. package/src/platforms/vtex/resolvers/validateSession.ts +2 -1
  47. package/src/platforms/vtex/typeDefs/mutation.graphql +4 -0
  48. package/src/platforms/vtex/typeDefs/organization.graphql +18 -0
  49. package/src/platforms/vtex/typeDefs/query.graphql +68 -0
  50. package/src/platforms/vtex/typeDefs/quote.graphql +65 -0
  51. package/src/platforms/vtex/typeDefs/recommendation.graphql +11 -0
  52. package/src/platforms/vtex/utils/contract.ts +144 -0
@@ -430,6 +430,46 @@ type Query {
430
430
  @auth
431
431
  @cacheControl(scope: "private", sMaxAge: 300, staleWhileRevalidate: 3600)
432
432
 
433
+ """
434
+ Returns the list of Quotes that the authenticated Buyer can view.
435
+ """
436
+ listUserQuotes(
437
+ """
438
+ Page number (1-based).
439
+ """
440
+ page: Int
441
+ """
442
+ Number of items per page.
443
+ """
444
+ perPage: Int
445
+ """
446
+ Filter by quote status values.
447
+ """
448
+ status: [String]
449
+ """
450
+ Filter quotes created on or after this ISO 8601 date-time.
451
+ """
452
+ createdAtFrom: String
453
+ """
454
+ Filter quotes created on or before this ISO 8601 date-time.
455
+ """
456
+ createdAtTo: String
457
+ """
458
+ Filter quotes expiring on or after this ISO 8601 date-time.
459
+ """
460
+ expiresAtFrom: String
461
+ """
462
+ Filter quotes expiring on or before this ISO 8601 date-time.
463
+ """
464
+ expiresAtTo: String
465
+ """
466
+ Filter quotes by label (partial match).
467
+ """
468
+ label: String
469
+ ): UserQuoteListResult
470
+ @auth
471
+ @cacheControl(scope: "private", sMaxAge: 300, staleWhileRevalidate: 3600)
472
+
433
473
  """
434
474
  Returns information about the current user details.
435
475
  """
@@ -451,6 +491,25 @@ type Query {
451
491
  @auth
452
492
  @cacheControl(scope: "private", sMaxAge: 300, staleWhileRevalidate: 3600)
453
493
 
494
+ """
495
+ Lists the commercial contracts associated with the given Organization Unit,
496
+ resolved to human-readable corporate names. Governed: only contracts associated
497
+ with the authenticated buyer's Organization Unit are returned.
498
+ """
499
+ availableContracts(
500
+ """
501
+ The Organization Unit identifier whose contracts will be listed.
502
+ """
503
+ orgUnitId: String!
504
+ ): [StoreContract!]! @auth @cacheControl(scope: "private", sMaxAge: 0)
505
+
506
+ """
507
+ Returns whether the current authenticated user belongs to a B2B organization unit.
508
+ """
509
+ isOrganizationMember: Boolean!
510
+ @auth
511
+ @cacheControl(scope: "private", sMaxAge: 300, staleWhileRevalidate: 3600)
512
+
454
513
  """
455
514
  Returns a list of pickup points near to the given geo coordinates.
456
515
  """
@@ -470,6 +529,15 @@ type Query {
470
529
  Returns the items in an orderForm by its ID.
471
530
  """
472
531
  orderFormItems(orderFormId: String!): [StoreOrderFormCartItem!]! @auth
532
+ """
533
+ Returns personalized product recommendations for a given campaign.
534
+ """
535
+ recommendations(
536
+ campaignVrn: String!
537
+ userId: String
538
+ products: [String!]
539
+ ): RecommendationResponse!
540
+ @cacheControl(scope: "private", sMaxAge: 120, staleWhileRevalidate: 3600)
473
541
  }
474
542
 
475
543
  type ValidateUserData {
@@ -0,0 +1,65 @@
1
+ """
2
+ Summary of a quote returned in list results.
3
+ """
4
+ type UserQuoteSummary {
5
+ """
6
+ Unique identifier of the quote.
7
+ """
8
+ id: String!
9
+ """
10
+ Status of the quote.
11
+ """
12
+ status: String!
13
+ """
14
+ Optional label assigned to the quote.
15
+ """
16
+ label: String
17
+ """
18
+ ISO 8601 date-time when the quote was created.
19
+ """
20
+ createdAt: String!
21
+ """
22
+ ISO 8601 date-time when the quote expires.
23
+ """
24
+ expiresAt: String!
25
+ """
26
+ Total amount of the quote.
27
+ """
28
+ amount: Float!
29
+ """
30
+ Name or email of the user who created the quote.
31
+ """
32
+ createdBy: String
33
+ }
34
+
35
+ """
36
+ Result returned by the listUserQuotes query.
37
+ """
38
+ type UserQuoteListResult {
39
+ """
40
+ Array of quote summaries for the current page.
41
+ """
42
+ list: [UserQuoteSummary!]!
43
+ """
44
+ Pagination information.
45
+ """
46
+ paging: UserQuoteListPaging!
47
+ }
48
+
49
+ """
50
+ Pagination metadata for the quotes list.
51
+ """
52
+ type UserQuoteListPaging {
53
+ """
54
+ Total number of quotes matching the query.
55
+ """
56
+ total: Int!
57
+ """
58
+ Current page number (1-based).
59
+ """
60
+ currentPage: Int!
61
+ """
62
+ Number of items per page.
63
+ """
64
+ perPage: Int!
65
+ }
@@ -0,0 +1,11 @@
1
+ type RecommendationResponse {
2
+ products: [StoreProduct!]!
3
+ correlationId: String!
4
+ campaign: RecommendationCampaign!
5
+ }
6
+
7
+ type RecommendationCampaign {
8
+ id: String!
9
+ title: String
10
+ type: String!
11
+ }
@@ -0,0 +1,144 @@
1
+ import type { ContractResponse } from '../clients/commerce/Contract'
2
+ import type {
3
+ SessionAvailableContract,
4
+ Shopper,
5
+ } from '../clients/commerce/types/Session'
6
+
7
+ type ProfileNameFields = {
8
+ firstName?: { value?: string | null } | null
9
+ lastName?: { value?: string | null } | null
10
+ } | null
11
+
12
+ /**
13
+ * Display name from Master Data, aligned with buyer-portal `personalDataToContract`.
14
+ */
15
+ export const resolveContractDisplayNameFromMd = (
16
+ contract: ContractResponse | null | undefined
17
+ ): string => {
18
+ const corporateName = (contract?.corporateName ?? '').trim()
19
+
20
+ if (corporateName) {
21
+ return corporateName
22
+ }
23
+
24
+ return (contract?.firstName ?? '').trim()
25
+ }
26
+
27
+ const isSessionAvailableContract = (
28
+ value: unknown
29
+ ): value is SessionAvailableContract => {
30
+ if (!value || typeof value !== 'object') {
31
+ return false
32
+ }
33
+
34
+ const contract = value as Record<string, unknown>
35
+
36
+ return (
37
+ typeof contract.customerId === 'string' &&
38
+ contract.customerId.trim() !== '' &&
39
+ typeof contract.contractName === 'string' &&
40
+ typeof contract.isActive === 'boolean' &&
41
+ typeof contract.isCurrent === 'boolean'
42
+ )
43
+ }
44
+
45
+ /**
46
+ * Parses VTEX session `shopper.availableContracts` into a typed list.
47
+ */
48
+ export const parseSessionAvailableContracts = (
49
+ shopper: Shopper | null | undefined
50
+ ): SessionAvailableContract[] => {
51
+ const raw = shopper?.availableContracts?.value
52
+
53
+ if (!Array.isArray(raw)) {
54
+ return []
55
+ }
56
+
57
+ return raw.filter(isSessionAvailableContract)
58
+ }
59
+
60
+ /**
61
+ * Whether a session contract is eligible for the switcher list.
62
+ */
63
+ export const isSwitchableSessionContract = (
64
+ contract: SessionAvailableContract | null | undefined
65
+ ): boolean => {
66
+ if (!contract?.customerId) {
67
+ return false
68
+ }
69
+
70
+ const name = (contract.contractName ?? '').trim()
71
+
72
+ return Boolean(name && contract.isActive)
73
+ }
74
+
75
+ /**
76
+ * Resolves the active contract id from VTEX session namespaces.
77
+ */
78
+ export const resolveActiveContractIdFromSession = (
79
+ sessionData: {
80
+ namespaces?: {
81
+ shopper?: Shopper | null
82
+ authentication?: { customerId?: { value?: string | null } | null } | null
83
+ profile?: { id?: { value?: string | null } | null } | null
84
+ } | null
85
+ } | null
86
+ ): string => {
87
+ return (
88
+ sessionData?.namespaces?.shopper?.activeContractId?.value?.trim() ??
89
+ sessionData?.namespaces?.authentication?.customerId?.value?.trim() ??
90
+ sessionData?.namespaces?.profile?.id?.value?.trim() ??
91
+ ''
92
+ )
93
+ }
94
+
95
+ /**
96
+ * Maps session contracts to GraphQL `StoreContract` entries.
97
+ */
98
+ export const mapSessionContractsToStoreContracts = (
99
+ contracts: SessionAvailableContract[],
100
+ activeContractId = ''
101
+ ): Array<{ id: string; corporateName: string; isActive: boolean }> => {
102
+ const normalizedActiveId = activeContractId.trim()
103
+
104
+ return contracts.filter(isSwitchableSessionContract).map((contract) => ({
105
+ id: contract.customerId,
106
+ corporateName: contract.contractName.trim(),
107
+ isActive: normalizedActiveId
108
+ ? contract.customerId === normalizedActiveId
109
+ : contract.isCurrent,
110
+ }))
111
+ }
112
+
113
+ /**
114
+ * Whether a CL record is eligible for contract switcher summaries (attached list).
115
+ */
116
+ export const isSwitchableContractSummary = (
117
+ contract: ContractResponse | null | undefined
118
+ ): boolean => {
119
+ if (!contract) {
120
+ return false
121
+ }
122
+
123
+ const name = resolveContractDisplayNameFromMd(contract)
124
+ const email = (contract.email ?? '').trim()
125
+
126
+ return Boolean(name && email)
127
+ }
128
+
129
+ /**
130
+ * Resolves the active contract name: Master Data first, then VTEX session profile.
131
+ * Matches `accountProfile` / buyer-portal behavior when CL lookup fails.
132
+ */
133
+ export const resolveActiveContractDisplayName = (
134
+ contract: ContractResponse | null | undefined,
135
+ profile: ProfileNameFields
136
+ ): string => {
137
+ const fromMasterData = resolveContractDisplayNameFromMd(contract)
138
+
139
+ if (fromMasterData) {
140
+ return fromMasterData
141
+ }
142
+
143
+ return (profile?.firstName?.value ?? '').trim()
144
+ }