@faststore/api 4.6.0-dev.1 → 4.6.0-dev.2

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 (36) hide show
  1. package/dist/cjs/index.js +51 -45
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/es/index.mjs +1345 -1237
  4. package/dist/es/index.mjs.map +1 -1
  5. package/dist/src/__generated__/schema.d.ts +6 -0
  6. package/dist/src/__generated__/schema.d.ts.map +1 -1
  7. package/dist/src/platforms/vtex/clients/commerce/index.d.ts +8 -1
  8. package/dist/src/platforms/vtex/clients/commerce/index.d.ts.map +1 -1
  9. package/dist/src/platforms/vtex/clients/index.d.ts +2 -1
  10. package/dist/src/platforms/vtex/clients/index.d.ts.map +1 -1
  11. package/dist/src/platforms/vtex/index.d.ts +1 -0
  12. package/dist/src/platforms/vtex/index.d.ts.map +1 -1
  13. package/dist/src/platforms/vtex/resolvers/getOrderEntryOperation.d.ts.map +1 -1
  14. package/dist/src/platforms/vtex/resolvers/index.d.ts +1 -0
  15. package/dist/src/platforms/vtex/resolvers/index.d.ts.map +1 -1
  16. package/dist/src/platforms/vtex/resolvers/mutation.d.ts +1 -0
  17. package/dist/src/platforms/vtex/resolvers/mutation.d.ts.map +1 -1
  18. package/dist/src/platforms/vtex/resolvers/query.d.ts.map +1 -1
  19. package/dist/src/platforms/vtex/resolvers/validateCart.d.ts +1 -0
  20. package/dist/src/platforms/vtex/resolvers/validateCart.d.ts.map +1 -1
  21. package/dist/src/platforms/vtex/resolvers/validateSession.d.ts.map +1 -1
  22. package/dist/src/platforms/vtex/utils/cartSalesChannel.d.ts +11 -0
  23. package/dist/src/platforms/vtex/utils/cartSalesChannel.d.ts.map +1 -0
  24. package/dist/src/platforms/vtex/utils/sessionChannel.d.ts +10 -0
  25. package/dist/src/platforms/vtex/utils/sessionChannel.d.ts.map +1 -0
  26. package/dist/src/platforms/vtex/utils/validateSessionHelpers.d.ts +88 -0
  27. package/dist/src/platforms/vtex/utils/validateSessionHelpers.d.ts.map +1 -0
  28. package/package.json +3 -3
  29. package/src/__generated__/schema.ts +6 -0
  30. package/src/platforms/vtex/clients/commerce/index.ts +17 -2
  31. package/src/platforms/vtex/resolvers/validateCart.ts +86 -8
  32. package/src/platforms/vtex/resolvers/validateSession.ts +63 -140
  33. package/src/platforms/vtex/typeDefs/order.graphql +6 -0
  34. package/src/platforms/vtex/utils/cartSalesChannel.ts +31 -0
  35. package/src/platforms/vtex/utils/sessionChannel.ts +32 -0
  36. package/src/platforms/vtex/utils/validateSessionHelpers.ts +202 -0
@@ -1 +1 @@
1
- {"version":3,"file":"getOrderEntryOperation.d.ts","sourceRoot":"","sources":["../../../../../src/platforms/vtex/resolvers/getOrderEntryOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,IAAI,CAAA;AACxC,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAA;AAGjF,eAAO,MAAM,sBAAsB,GACjC,GAAG,OAAO,EACV,iBAAiB,4BAA4B,EAC7C,2BAA2B,cAAc;;;;;;gBAQ49/B,CAAC;;;EADvggC,CAAA"}
1
+ {"version":3,"file":"getOrderEntryOperation.d.ts","sourceRoot":"","sources":["../../../../../src/platforms/vtex/resolvers/getOrderEntryOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,IAAI,CAAA;AACxC,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAA;AAGjF,eAAO,MAAM,sBAAsB,GACjC,GAAG,OAAO,EACV,iBAAiB,4BAA4B,EAC7C,2BAA2B,cAAc;;;;;;gBAQ+phC,CAAC;;;EAD1shC,CAAA"}
@@ -219,6 +219,7 @@ export declare const getResolvers: () => {
219
219
  Mutation: {
220
220
  validateCart: (_: unknown, { cart: { order }, session }: import('../../..').MutationValidateCartArgs, ctx: import('..').GraphqlContext) => Promise<{
221
221
  order: {
222
+ salesChannel?: string | undefined;
222
223
  orderNumber: string;
223
224
  acceptedOffer: Promise<{
224
225
  product: import('../utils/enhanceSku').EnhancedSku;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/platforms/vtex/resolvers/index.ts"],"names":[],"mappings":"AA0CA,eAAO,MAAM,YAAY;;;;;;oJAC8pF,mCAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAA+if,CAAC;mBAAsB,CAAC;kBAAqB,CAAC;yBAA8B,CAAC;uBAA0B,CAAC;yBAA4B,CAAC;uBAA0B,CAAC;iBAAoB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAAwzZ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADpr+B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/platforms/vtex/resolvers/index.ts"],"names":[],"mappings":"AA0CA,eAAO,MAAM,YAAY;;;;;;oJAC8pF,mCAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAA+if,CAAC;mBAAsB,CAAC;kBAAqB,CAAC;yBAA8B,CAAC;uBAA0B,CAAC;yBAA4B,CAAC;uBAA0B,CAAC;iBAAoB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAA2/a,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADv3/B,CAAA"}
@@ -1,6 +1,7 @@
1
1
  export declare const Mutation: {
2
2
  validateCart: (_: unknown, { cart: { order }, session }: import('../../..').MutationValidateCartArgs, ctx: import('..').GraphqlContext) => Promise<{
3
3
  order: {
4
+ salesChannel?: string | undefined;
4
5
  orderNumber: string;
5
6
  acceptedOffer: Promise<{
6
7
  product: import('../utils/enhanceSku').EnhancedSku;
@@ -1 +1 @@
1
- {"version":3,"file":"mutation.d.ts","sourceRoot":"","sources":["../../../../../src/platforms/vtex/resolvers/mutation.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CASpB,CAAA"}
1
+ {"version":3,"file":"mutation.d.ts","sourceRoot":"","sources":["../../../../../src/platforms/vtex/resolvers/mutation.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CASpB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../../../src/platforms/vtex/resolvers/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,uBAAuB,EACvB,oBAAoB,EACpB,2BAA2B,EAC3B,mBAAmB,EACnB,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EAEd,MAAM,+BAA+B,CAAA;AAUtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AACvE,OAAO,KAAK,EAAE,UAAU,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K,CAAC,EAAE,MAAM,CAAA;KACf,OACI,cAAc;;;;;;;;;;;;;;;;sBAoDG,OAAO,MAAM,OAAO,QAAQ,cAAc;;;8BAQ7D,OAAO,MACN,OAAO,OACN,cAAc;qBAWE,OAAO,MAAM,OAAO,OAAO,cAAc;;;;;;;;wBAqCtC,OAAO,MAAM,OAAO,OAAO,cAAc;;;;;4BA2E9D,OAAO,iBACK,2BAA2B,OACrC,cAAc,KAClB,OAAO,CAAC,aAAa,EAAE,CAAC;sBA4CtB,OAAO,sBACU,qBAAqB,OACpC,cAAc;;;;;;;oBAgBolM,CAAC;;;;;;;;;;;;;;;;;;;;CAD3mM,CAAA"}
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../../../src/platforms/vtex/resolvers/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,uBAAuB,EACvB,oBAAoB,EACpB,2BAA2B,EAC3B,mBAAmB,EACnB,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EAEd,MAAM,+BAA+B,CAAA;AAUtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAA;AACtF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,uBAAuB,CAAA;AAU9B,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAA;AA4HlE,eAAO,MAAM,KAAK;iBAEX,OAAO,eACG,gBAAgB,OACxB,cAAc;oBAyChB,OAAO,YACA,mBAAm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gBuxN,CAAC;;;;;;;;;;;;;;;;;;;;CAD9yN,CAAA"}
@@ -15,6 +15,7 @@ import { MutationValidateCartArgs } from '../../../__generated__/schema';
15
15
  */
16
16
  export declare const validateCart: (_: unknown, { cart: { order }, session }: MutationValidateCartArgs, ctx: GraphqlContext) => Promise<{
17
17
  order: {
18
+ salesChannel?: string | undefined;
18
19
  orderNumber: string;
19
20
  acceptedOffer: Promise<{
20
21
  product: import('../utils/enhanceSku').EnhancedSku;
@@ -1 +1 @@
1
- {"version":3,"file":"validateCart.d.ts","sourceRoot":"","sources":["../../../../../src/platforms/vtex/resolvers/validateCart.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,IAAI,CAAA;AACxC,OAAO,KAAK,EAMV,wBAAwB,EACzB,MAAM,+BAA+B,CAAA;AA+TtC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GACvB,GAAG,OAAO,EACV,8BAA8B,wBAAwB,EACtD,KAAK,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAkMpB,CAAA"}
1
+ {"version":3,"file":"validateCart.d.ts","sourceRoot":"","sources":["../../../../../src/platforms/vtex/resolvers/validateCart.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,IAAI,CAAA;AACxC,OAAO,KAAK,EAMV,wBAAwB,EACzB,MAAM,+BAA+B,CAAA;AAiWtC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GACvB,GAAG,OAAO,EACV,8BAA8B,wBAAwB,EACtD,KAAK,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SA6OpB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"validateSession.d.ts","sourceRoot":"","sources":["../../../../../src/platforms/vtex/resolvers/validateSession.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,IAAI,CAAA;AACxC,OAAO,KAAK,EACV,2BAA2B,EAE3B,YAAY,EACb,MAAM,+BAA+B,CAAA;AAiCtC,eAAO,MAAM,eAAe,GAC1B,GAAG,GAAG,EACN,iCAAiC,2BAA2B,EAC5D,+BAA+B,cAAc,KAC5C,OAAO,CAAC,YAAY,GAAG,IAAI,CAuL7B,CAAA"}
1
+ {"version":3,"file":"validateSession.d.ts","sourceRoot":"","sources":["../../../../../src/platforms/vtex/resolvers/validateSession.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,IAAI,CAAA;AACxC,OAAO,KAAK,EACV,2BAA2B,EAC3B,YAAY,EACb,MAAM,+BAA+B,CAAA;AAwBtC,eAAO,MAAM,eAAe,GAC1B,GAAG,GAAG,EACN,iCAAiC,2BAA2B,EAC5D,+BAA+B,cAAc,KAC5C,OAAO,CAAC,YAAY,GAAG,IAAI,CAoH7B,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { Channel } from './channel';
2
+ /**
3
+ * When session SC and orderForm SC diverge, keep Checkout on the orderForm
4
+ * trade policy. Used after external cart changes (stale etag / Quick Order) and
5
+ * on later validations while the browser session still lags.
6
+ *
7
+ * Forcing the session SC (refetch / item updates with `sc=session`) would drop
8
+ * items that exist only on the orderForm's sales channel.
9
+ */
10
+ export declare function channelWhenSessionDivergesFromOrderForm(currentChannel: Required<Channel>, orderFormSalesChannel: string | null | undefined): string | null;
11
+ //# sourceMappingURL=cartSalesChannel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cartSalesChannel.d.ts","sourceRoot":"","sources":["../../../../../src/platforms/vtex/utils/cartSalesChannel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGxC;;;;;;;GAOG;AACH,wBAAgB,uCAAuC,CACrD,cAAc,EAAE,QAAQ,CAAC,OAAO,CAAC,EACjC,qBAAqB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC/C,MAAM,GAAG,IAAI,CAgBf"}
@@ -0,0 +1,10 @@
1
+ import { Channel } from './channel';
2
+ /**
3
+ * Builds the session `channel` string after Session Manager responds.
4
+ *
5
+ * When the client already pinned an explicit SC (e.g. adopted from the
6
+ * orderForm after Quick Order), keep it. Session Manager often still reports
7
+ * the default SC and would otherwise overwrite the adoption.
8
+ */
9
+ export declare function channelAfterSessionManager(channel: Required<Channel>, storeChannelValue: string | null | undefined, regionId: string | null | undefined, sellerId: string | undefined): string;
10
+ //# sourceMappingURL=sessionChannel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessionChannel.d.ts","sourceRoot":"","sources":["../../../../../src/platforms/vtex/utils/sessionChannel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGxC;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,EAC1B,iBAAiB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC5C,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACnC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B,MAAM,CAgBR"}
@@ -0,0 +1,88 @@
1
+ import { GraphqlContext } from '..';
2
+ import { StoreMarketingData, StoreSession } from '../../../__generated__/schema';
3
+ import { Channel } from './channel';
4
+ import { resolveActiveContractDisplayName } from './contract';
5
+ export declare function getPreciseLocationData(clients: GraphqlContext['clients'], country: string, postalCode: string): Promise<{
6
+ city: string | null;
7
+ geoCoordinates: {
8
+ latitude: number;
9
+ longitude: number;
10
+ } | null;
11
+ }>;
12
+ export declare function buildSessionSearchParams(search: string, channel: Required<Channel>, postalCode: string, country: string, geoCoordinates: StoreSession['geoCoordinates'], locale: string): URLSearchParams;
13
+ export declare function buildMarketingData(params: URLSearchParams, oldMarketingData: StoreSession['marketingData']): StoreMarketingData;
14
+ export declare function resolveJwtClaims(clients: GraphqlContext['clients'], cookie: string | undefined, account: string): Promise<{
15
+ isRepresentative: boolean;
16
+ customerId: any;
17
+ unitId: any;
18
+ }>;
19
+ export declare function resolveSellerInRegion(clients: GraphqlContext['clients'], channel: Required<Channel>, postalCode: string, geoCoordinates: StoreSession['geoCoordinates'], country: string, salesChannel: string): Promise<string | undefined>;
20
+ export declare function buildB2bSession(args: {
21
+ isRepresentative: boolean;
22
+ authentication: {
23
+ customerId?: {
24
+ value?: string | null;
25
+ } | null;
26
+ unitName?: {
27
+ value?: string | null;
28
+ } | null;
29
+ unitId?: {
30
+ value?: string | null;
31
+ } | null;
32
+ storeUserEmail?: {
33
+ value?: string | null;
34
+ } | null;
35
+ } | null;
36
+ shopper: {
37
+ firstName?: {
38
+ value?: unknown;
39
+ } | null;
40
+ lastName?: {
41
+ value?: unknown;
42
+ } | null;
43
+ organizationManager?: {
44
+ value?: boolean | null;
45
+ } | null;
46
+ } | null;
47
+ publicData: {
48
+ postalCode?: {
49
+ value?: string | null;
50
+ } | null;
51
+ } | null;
52
+ profile: Parameters<typeof resolveActiveContractDisplayName>[1];
53
+ contract: Parameters<typeof resolveActiveContractDisplayName>[0];
54
+ customerId?: string;
55
+ unitId?: string;
56
+ }): {
57
+ isRepresentative: boolean;
58
+ customerId: string;
59
+ unitName: string;
60
+ unitId: string;
61
+ firstName: string;
62
+ lastName: string;
63
+ userName: string;
64
+ userEmail: string;
65
+ savedPostalCode: string;
66
+ contractName: string;
67
+ organizationManager: boolean;
68
+ } | null;
69
+ export declare function buildPersonFromProfile(profile: {
70
+ id?: {
71
+ value?: string | null;
72
+ } | null;
73
+ email?: {
74
+ value?: string | null;
75
+ } | null;
76
+ firstName?: {
77
+ value?: string | null;
78
+ } | null;
79
+ lastName?: {
80
+ value?: string | null;
81
+ } | null;
82
+ } | null): {
83
+ id: string;
84
+ email: string;
85
+ givenName: string;
86
+ familyName: string;
87
+ } | null;
88
+ //# sourceMappingURL=validateSessionHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateSessionHelpers.d.ts","sourceRoot":"","sources":["../../../../../src/platforms/vtex/utils/validateSessionHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,IAAI,CAAA;AACxC,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACb,MAAM,+BAA+B,CAAA;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,gCAAgC,EAAE,MAAM,YAAY,CAAA;AAG7D,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,EAClC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM;;;;;;GAuBnB;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,EAC1B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,YAAY,CAAC,gBAAgB,CAAC,EAC9C,MAAM,EAAE,MAAM,mBA8Bf;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,eAAe,EACvB,gBAAgB,EAAE,YAAY,CAAC,eAAe,CAAC,GAC9C,kBAAkB,CAUpB;AAED,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,EAClC,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,MAAM;;;;GAoBhB;AAED,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,EAClC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,EAC1B,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,YAAY,CAAC,gBAAgB,CAAC,EAC9C,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,+BAerB;AAMD,wBAAgB,eAAe,CAAC,IAAI,EAAE;IACpC,gBAAgB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AAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAA;IACrC,KAAK,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAA;IACxC,SAAS,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAA;IAC5C,QAAQ,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAA;CAC5C,GAAG,IAAI;;;;;SAYT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "4.6.0-dev.1",
3
+ "version": "4.6.0-dev.2",
4
4
  "license": "MIT",
5
5
  "main": "dist/cjs/index.js",
6
6
  "typings": "dist/src/index.d.ts",
@@ -58,11 +58,11 @@
58
58
  "vite": "7.1.5",
59
59
  "vite-plugin-dts": "4.5.4",
60
60
  "vitest": "4.0.18",
61
- "@faststore/diagnostics": "^4.6.0-dev.1"
61
+ "@faststore/diagnostics": "^4.6.0-dev.2"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "graphql": "16.11.0",
65
- "@faststore/diagnostics": "4.6.0-dev.1"
65
+ "@faststore/diagnostics": "4.6.0-dev.2"
66
66
  },
67
67
  "publishConfig": {
68
68
  "access": "public"
@@ -1616,6 +1616,12 @@ export type StoreOrder = {
1616
1616
  acceptedOffer: Array<StoreOffer>;
1617
1617
  /** ID of the order in [VTEX order management](https://help.vtex.com/en/tutorial/license-manager-resources-oms--60QcBsvWeum02cFi3GjBzg#). */
1618
1618
  orderNumber: Scalars['String']['output'];
1619
+ /**
1620
+ * Sales channel of the underlying orderForm when FastStore adopted it because
1621
+ * the browser session was stale (e.g. after Quick Order). Clients should align
1622
+ * `session.channel` to this value. Null when no SC adoption happened.
1623
+ */
1624
+ salesChannel?: Maybe<Scalars['String']['output']>;
1619
1625
  /** Indicates whether or not items with attachments should be split. */
1620
1626
  shouldSplitItem?: Maybe<Scalars['Boolean']['output']>;
1621
1627
  };
@@ -435,21 +435,36 @@ export const VtexCommerce = (
435
435
  id,
436
436
  refreshOutdatedData = true,
437
437
  channel = ctx.storage.channel,
438
+ preserveSalesChannel = false,
438
439
  }: {
439
440
  id?: string
440
441
  refreshOutdatedData?: boolean
441
442
  channel?: Required<Channel>
443
+ /**
444
+ * When true, omit the `sc` query param so Checkout keeps the cart's
445
+ * current sales channel. Use this when the session SC may be stale
446
+ * relative to an external flow (e.g. Quick Order) that already
447
+ * advanced the orderForm.
448
+ */
449
+ preserveSalesChannel?: boolean
442
450
  }): Promise<OrderForm> => {
443
451
  const { salesChannel } = channel
444
452
  const headers: HeadersInit = withCookie({
445
453
  'content-type': 'application/json',
446
454
  'X-FORWARDED-HOST': forwardedHost,
447
455
  })
448
- const params = new URLSearchParams({ sc: salesChannel })
456
+ const params = new URLSearchParams()
457
+ // New carts (no id) always need an explicit SC. Existing carts may
458
+ // omit it so Checkout does not recalculate under a stale session SC.
459
+ if (!preserveSalesChannel || !id) {
460
+ params.set('sc', salesChannel)
461
+ }
449
462
  if (id) {
450
463
  params.set('refreshOutdatedData', refreshOutdatedData.toString())
451
464
  }
452
- const url = `${base}/api/checkout/pub/orderForm${id ? `/${id}` : ''}?${params.toString()}`
465
+ const orderFormPath = id ? `/${id}` : ''
466
+ // Always has at least `sc` (new cart) or `refreshOutdatedData` (existing).
467
+ const url = `${base}/api/checkout/pub/orderForm${orderFormPath}?${params}`
453
468
 
454
469
  return fetchAPI(
455
470
  url,
@@ -1,6 +1,7 @@
1
1
  import deepEquals from 'fast-deep-equal'
2
2
 
3
3
  import { parse } from 'cookie'
4
+ import { channelWhenSessionDivergesFromOrderForm } from '../utils/cartSalesChannel'
4
5
  import { mutateChannelContext, mutateLocaleContext } from '../utils/contex'
5
6
  import { md5 } from '../utils/md5'
6
7
  import {
@@ -175,7 +176,8 @@ const joinItems = (form: OrderForm) => {
175
176
  const orderFormToCart = async (
176
177
  form: OrderForm,
177
178
  skuLoader: GraphqlContext['loaders']['skuLoader'],
178
- shouldSplitItem?: boolean | null
179
+ shouldSplitItem?: boolean | null,
180
+ adoptedSalesChannel?: string | null
179
181
  ) => {
180
182
  return {
181
183
  order: {
@@ -185,6 +187,7 @@ const orderFormToCart = async (
185
187
  product: await skuLoader.load(`${item.id}-invisibleItems`),
186
188
  })),
187
189
  shouldSplitItem,
190
+ ...(adoptedSalesChannel ? { salesChannel: adoptedSalesChannel } : {}),
188
191
  },
189
192
  messages: form.messages.map(({ text, status }) => ({
190
193
  text,
@@ -336,6 +339,38 @@ const getCookieCheckoutOrderNumber = (ctx: string, nameCookie: string) => {
336
339
  return cookieValue ? cookieValue.split('=')[1] : ''
337
340
  }
338
341
 
342
+ /** Keep Checkout on the orderForm SC when the browser session lags behind it. */
343
+ const adoptOrderFormSalesChannelWhenSessionDiverges = (
344
+ ctx: GraphqlContext,
345
+ orderForm: OrderForm
346
+ ): string | null => {
347
+ const adoptedChannel = channelWhenSessionDivergesFromOrderForm(
348
+ ctx.storage.channel,
349
+ orderForm.salesChannel
350
+ )
351
+
352
+ if (adoptedChannel) {
353
+ mutateChannelContext(ctx, adoptedChannel)
354
+ return orderForm.salesChannel ? String(orderForm.salesChannel) : null
355
+ }
356
+
357
+ return null
358
+ }
359
+
360
+ /** Return a cart only when an SC was adopted (so the client can sync session). */
361
+ const cartWhenSalesChannelAdoptedOrNull = (
362
+ form: OrderForm,
363
+ skuLoader: GraphqlContext['loaders']['skuLoader'],
364
+ shouldSplitItem: boolean | null | undefined,
365
+ adoptedSalesChannel: string | null
366
+ ) => {
367
+ if (!adoptedSalesChannel) {
368
+ return null
369
+ }
370
+
371
+ return orderFormToCart(form, skuLoader, shouldSplitItem, adoptedSalesChannel)
372
+ }
373
+
339
374
  /**
340
375
  * This resolver implements the optimistic cart behavior. The main idea in here
341
376
  * is that we receive a cart from the UI (as query params) and we validate it with
@@ -374,10 +409,17 @@ export const validateCart = async (
374
409
  mutateLocaleContext(ctx, locale)
375
410
  }
376
411
 
377
- // Step1: Get OrderForm from VTEX Commerce
412
+ // Step1: Get OrderForm from VTEX Commerce.
413
+ // For existing carts (`orderFormId` present), omit `sc` on the first GET so
414
+ // Checkout keeps the orderForm's current sales channel. Passing a stale
415
+ // session SC (e.g. after Quick Order) would recalculate the cart and drop
416
+ // items only available in the orderForm's trade policy. New carts still
417
+ // send `sc` from the session (see commerce.checkout.orderForm).
418
+ const orderFormId = orderFormIdFromCookie || undefined
378
419
  const orderForm = await commerce.checkout.orderForm({
379
- id: orderFormIdFromCookie || undefined,
420
+ id: orderFormId,
380
421
  channel: ctx.storage.channel,
422
+ preserveSalesChannel: Boolean(orderFormId),
381
423
  })
382
424
  const orderNumber = orderForm.orderFormId
383
425
 
@@ -398,16 +440,36 @@ export const validateCart = async (
398
440
  const isStale = isOrderFormStale(orderForm, sessionJwt)
399
441
 
400
442
  if (isStale) {
443
+ // Adopt the orderForm SC so subsequent checkout calls (etag, etc.) stay
444
+ // on the trade policy that actually owns the items.
445
+ const adoptedSalesChannel = adoptOrderFormSalesChannelWhenSessionDiverges(
446
+ ctx,
447
+ orderForm
448
+ )
449
+
401
450
  const newOrderForm = await setOrderFormEtag(
402
451
  orderForm,
403
452
  commerce,
404
453
  sessionJwt
405
454
  ).then(joinItems)
406
455
  if (orderNumber) {
407
- return orderFormToCart(newOrderForm, skuLoader, shouldSplitItem)
456
+ return orderFormToCart(
457
+ newOrderForm,
458
+ skuLoader,
459
+ shouldSplitItem,
460
+ adoptedSalesChannel
461
+ )
408
462
  }
409
463
  }
410
464
 
465
+ // Keep Checkout on the orderForm trade policy when the browser session still
466
+ // has a stale SC (Quick Order). Refetching with `sc=session` would wipe
467
+ // items that exist only on the orderForm's sales channel.
468
+ const adoptedSalesChannel = adoptOrderFormSalesChannelWhenSessionDiverges(
469
+ ctx,
470
+ orderForm
471
+ )
472
+
411
473
  // Step2: Process items from both browser and checkout so they have the same shape
412
474
  const browserItemsById = groupById(acceptedOffer)
413
475
  const originItemsById = groupById(orderForm.items.map(orderFormItemToOffer))
@@ -470,9 +532,15 @@ export const validateCart = async (
470
532
  ? shouldUpdateShippingData(orderForm, session)
471
533
  : { updateShipping: false }
472
534
 
473
- // If there are no item changes and no shipping data updates needed, return null
535
+ // If there are no item/shipping changes: still return the cart when we
536
+ // adopted the orderForm SC so the client can align `fs::session`.
474
537
  if (changes.length === 0 && !updateShipping) {
475
- return null
538
+ return cartWhenSalesChannelAdoptedOrNull(
539
+ orderForm,
540
+ skuLoader,
541
+ shouldSplitItem,
542
+ adoptedSalesChannel
543
+ )
476
544
  }
477
545
 
478
546
  // Step4: Apply delta changes to order form
@@ -541,9 +609,19 @@ export const validateCart = async (
541
609
 
542
610
  // Step5: If no changes detected before/after updating orderForm, the order is validated
543
611
  if (equals(order, updatedOrderForm) && equalMessages) {
544
- return null
612
+ return cartWhenSalesChannelAdoptedOrNull(
613
+ updatedOrderForm,
614
+ skuLoader,
615
+ shouldSplitItem,
616
+ adoptedSalesChannel
617
+ )
545
618
  }
546
619
 
547
620
  // Step6: There were changes, convert orderForm to StoreCart
548
- return orderFormToCart(updatedOrderForm, skuLoader, shouldSplitItem)
621
+ return orderFormToCart(
622
+ updatedOrderForm,
623
+ skuLoader,
624
+ shouldSplitItem,
625
+ adoptedSalesChannel
626
+ )
549
627
  }