@faststore/api 4.3.0-dev.0 → 4.3.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.
- package/dist/cjs/index.js +124 -39
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.mjs +832 -595
- package/dist/es/index.mjs.map +1 -1
- package/dist/src/__generated__/schema.d.ts +79 -0
- package/dist/src/__generated__/schema.d.ts.map +1 -1
- package/dist/src/platforms/vtex/clients/commerce/index.d.ts +36 -0
- package/dist/src/platforms/vtex/clients/commerce/index.d.ts.map +1 -1
- package/dist/src/platforms/vtex/clients/index.d.ts +36 -0
- package/dist/src/platforms/vtex/clients/index.d.ts.map +1 -1
- package/dist/src/platforms/vtex/index.d.ts +27 -0
- package/dist/src/platforms/vtex/index.d.ts.map +1 -1
- package/dist/src/platforms/vtex/resolvers/getOrderEntryOperation.d.ts +13 -0
- package/dist/src/platforms/vtex/resolvers/getOrderEntryOperation.d.ts.map +1 -0
- package/dist/src/platforms/vtex/resolvers/getOrderFormItems.d.ts +14 -0
- package/dist/src/platforms/vtex/resolvers/getOrderFormItems.d.ts.map +1 -0
- package/dist/src/platforms/vtex/resolvers/index.d.ts +27 -0
- package/dist/src/platforms/vtex/resolvers/index.d.ts.map +1 -1
- package/dist/src/platforms/vtex/resolvers/mutation.d.ts +6 -0
- package/dist/src/platforms/vtex/resolvers/mutation.d.ts.map +1 -1
- package/dist/src/platforms/vtex/resolvers/query.d.ts +21 -0
- package/dist/src/platforms/vtex/resolvers/query.d.ts.map +1 -1
- package/dist/src/platforms/vtex/resolvers/startOrderEntryOperation.d.ts +6 -0
- package/dist/src/platforms/vtex/resolvers/startOrderEntryOperation.d.ts.map +1 -0
- package/dist/src/platforms/vtex/resolvers/uploadFileToOrderEntry.d.ts +6 -0
- package/dist/src/platforms/vtex/resolvers/uploadFileToOrderEntry.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/__generated__/schema.ts +94 -0
- package/src/platforms/vtex/clients/commerce/index.ts +153 -0
- package/src/platforms/vtex/resolvers/getOrderEntryOperation.ts +15 -0
- package/src/platforms/vtex/resolvers/getOrderFormItems.ts +26 -0
- package/src/platforms/vtex/resolvers/mutation.ts +4 -0
- package/src/platforms/vtex/resolvers/query.ts +4 -0
- package/src/platforms/vtex/resolvers/startOrderEntryOperation.ts +23 -0
- package/src/platforms/vtex/resolvers/uploadFileToOrderEntry.ts +45 -0
- package/src/platforms/vtex/typeDefs/mutation.graphql +14 -0
- package/src/platforms/vtex/typeDefs/orderEntry.graphql +61 -0
- package/src/platforms/vtex/typeDefs/query.graphql +9 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { GraphqlContext } from '..'
|
|
2
|
+
import type { QueryOrderEntryOperationArgs } from '../../../__generated__/schema'
|
|
3
|
+
import { BadRequestError } from '../../errors'
|
|
4
|
+
|
|
5
|
+
export const getOrderEntryOperation = async (
|
|
6
|
+
_: unknown,
|
|
7
|
+
{ operationId }: QueryOrderEntryOperationArgs,
|
|
8
|
+
{ clients: { commerce } }: GraphqlContext
|
|
9
|
+
) => {
|
|
10
|
+
if (!operationId) {
|
|
11
|
+
throw new BadRequestError('Missing operationId')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return commerce.orderEntry.getOperation({ operationId })
|
|
15
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { GraphqlContext } from '..'
|
|
2
|
+
import type { QueryOrderFormItemsArgs } from '../../../__generated__/schema'
|
|
3
|
+
import { BadRequestError } from '../../errors'
|
|
4
|
+
|
|
5
|
+
export const getOrderFormItems = async (
|
|
6
|
+
_: unknown,
|
|
7
|
+
{ orderFormId }: QueryOrderFormItemsArgs,
|
|
8
|
+
{ clients: { commerce } }: GraphqlContext
|
|
9
|
+
) => {
|
|
10
|
+
if (!orderFormId) {
|
|
11
|
+
throw new BadRequestError('Missing orderFormId')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const { items } = await commerce.orderEntry.getOrderFormItems({ orderFormId })
|
|
15
|
+
return (items ?? []).map((item) => ({
|
|
16
|
+
id: item.id,
|
|
17
|
+
name: item.name,
|
|
18
|
+
price: item.price,
|
|
19
|
+
listPrice: item.listPrice,
|
|
20
|
+
quantity: item.quantity,
|
|
21
|
+
imageUrl: item.imageUrl ?? null,
|
|
22
|
+
availability: item.availability,
|
|
23
|
+
seller: item.seller,
|
|
24
|
+
unitMultiplier: item.unitMultiplier ?? 1,
|
|
25
|
+
}))
|
|
26
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { cancelOrder } from './cancelOrder'
|
|
2
2
|
import { processOrderAuthorization } from './processOrderAuthorization'
|
|
3
|
+
import { startOrderEntryOperation } from './startOrderEntryOperation'
|
|
3
4
|
import { subscribeToNewsletter } from './subscribeToNewsletter'
|
|
5
|
+
import { uploadFileToOrderEntry } from './uploadFileToOrderEntry'
|
|
4
6
|
import { validateCart } from './validateCart'
|
|
5
7
|
import { validateSession } from './validateSession'
|
|
6
8
|
|
|
@@ -10,4 +12,6 @@ export const Mutation = {
|
|
|
10
12
|
subscribeToNewsletter,
|
|
11
13
|
cancelOrder,
|
|
12
14
|
processOrderAuthorization,
|
|
15
|
+
uploadFileToOrderEntry,
|
|
16
|
+
startOrderEntryOperation,
|
|
13
17
|
}
|
|
@@ -16,6 +16,8 @@ import type {
|
|
|
16
16
|
QueryUserOrderArgs,
|
|
17
17
|
UserOrderFromList,
|
|
18
18
|
} from '../../../__generated__/schema'
|
|
19
|
+
import { getOrderEntryOperation } from './getOrderEntryOperation'
|
|
20
|
+
import { getOrderFormItems } from './getOrderFormItems'
|
|
19
21
|
import {
|
|
20
22
|
BadRequestError,
|
|
21
23
|
ForbiddenError,
|
|
@@ -671,4 +673,6 @@ export const Query = {
|
|
|
671
673
|
|
|
672
674
|
return result
|
|
673
675
|
},
|
|
676
|
+
orderEntryOperation: getOrderEntryOperation,
|
|
677
|
+
orderFormItems: getOrderFormItems,
|
|
674
678
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { GraphqlContext } from '..'
|
|
2
|
+
import type { MutationStartOrderEntryOperationArgs } from '../../../__generated__/schema'
|
|
3
|
+
import { BadRequestError } from '../../errors'
|
|
4
|
+
|
|
5
|
+
export const startOrderEntryOperation = async (
|
|
6
|
+
_: unknown,
|
|
7
|
+
{ data }: MutationStartOrderEntryOperationArgs,
|
|
8
|
+
{ clients: { commerce } }: GraphqlContext
|
|
9
|
+
) => {
|
|
10
|
+
if (!data?.objectKey) {
|
|
11
|
+
throw new BadRequestError('Missing objectKey')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const orderFormId =
|
|
15
|
+
data.orderFormId ||
|
|
16
|
+
(await commerce.orderEntry.createOrderForm()).orderFormId
|
|
17
|
+
|
|
18
|
+
return commerce.orderEntry.startOperation({
|
|
19
|
+
objectKey: data.objectKey,
|
|
20
|
+
orderFormId,
|
|
21
|
+
sessionToken: data.sessionToken ?? undefined,
|
|
22
|
+
})
|
|
23
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { GraphqlContext } from '..'
|
|
2
|
+
import type { MutationUploadFileToOrderEntryArgs } from '../../../__generated__/schema'
|
|
3
|
+
import { BadRequestError } from '../../errors'
|
|
4
|
+
|
|
5
|
+
export const uploadFileToOrderEntry = async (
|
|
6
|
+
_: unknown,
|
|
7
|
+
{ data }: MutationUploadFileToOrderEntryArgs,
|
|
8
|
+
{ clients: { commerce } }: GraphqlContext
|
|
9
|
+
) => {
|
|
10
|
+
const { fileContent, fileName, mimeType } = data
|
|
11
|
+
|
|
12
|
+
if (!fileContent || !fileName || !mimeType) {
|
|
13
|
+
throw new BadRequestError(
|
|
14
|
+
'Missing required fields: fileContent, fileName, mimeType'
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const normalized = fileContent.replaceAll(/\s/g, '')
|
|
19
|
+
|
|
20
|
+
const MAX_FILE_BYTES = 5 * 1024 * 1024
|
|
21
|
+
const estimatedBytes = Math.floor((normalized.length * 3) / 4)
|
|
22
|
+
|
|
23
|
+
if (estimatedBytes > MAX_FILE_BYTES) {
|
|
24
|
+
throw new BadRequestError('File exceeds maximum allowed size of 5MB')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const isValidBase64 =
|
|
28
|
+
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(
|
|
29
|
+
normalized
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
if (!isValidBase64) {
|
|
33
|
+
throw new BadRequestError('Invalid Base64 fileContent')
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const fileBuffer = Buffer.from(normalized, 'base64')
|
|
37
|
+
|
|
38
|
+
const result = await commerce.orderEntry.uploadFile({
|
|
39
|
+
fileBuffer,
|
|
40
|
+
fileName,
|
|
41
|
+
mimeType,
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
return result
|
|
45
|
+
}
|
|
@@ -21,4 +21,18 @@ type Mutation {
|
|
|
21
21
|
processOrderAuthorization(
|
|
22
22
|
data: IProcessOrderAuthorization!
|
|
23
23
|
): ProcessOrderAuthorizationResponse
|
|
24
|
+
"""
|
|
25
|
+
Uploads a file to the Order Entry Service and returns the S3 object key.
|
|
26
|
+
The file must be Base64-encoded and passed via the `data` input.
|
|
27
|
+
The returned `objectKey` is required to start an order entry operation.
|
|
28
|
+
"""
|
|
29
|
+
uploadFileToOrderEntry(data: IOrderEntryUpload!): StoreOrderEntryUploadResult
|
|
30
|
+
@auth
|
|
31
|
+
"""
|
|
32
|
+
Submits an uploaded file for bulk import into a VTEX cart via the Order Entry Service.
|
|
33
|
+
Returns an operationId to poll for the operation status.
|
|
34
|
+
"""
|
|
35
|
+
startOrderEntryOperation(
|
|
36
|
+
data: IOrderEntryOperation!
|
|
37
|
+
): StoreOrderEntryOperationResult @auth
|
|
24
38
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Input for uploading a file to the Order Entry Service.
|
|
3
|
+
The file is transmitted as a Base64-encoded string so it can travel
|
|
4
|
+
through the standard GraphQL JSON pipeline without multipart support.
|
|
5
|
+
"""
|
|
6
|
+
input IOrderEntryUpload {
|
|
7
|
+
"""
|
|
8
|
+
Base64-encoded file content.
|
|
9
|
+
"""
|
|
10
|
+
fileContent: String!
|
|
11
|
+
"""
|
|
12
|
+
Original file name (e.g. "order.csv").
|
|
13
|
+
"""
|
|
14
|
+
fileName: String!
|
|
15
|
+
"""
|
|
16
|
+
MIME type of the file (e.g. "text/csv", "image/png").
|
|
17
|
+
"""
|
|
18
|
+
mimeType: String!
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
"""
|
|
22
|
+
Result returned after uploading a file to the Order Entry Service.
|
|
23
|
+
"""
|
|
24
|
+
type StoreOrderEntryUploadResult {
|
|
25
|
+
objectKey: String!
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
input IOrderEntryOperation {
|
|
29
|
+
objectKey: String!
|
|
30
|
+
orderFormId: String
|
|
31
|
+
sessionToken: String
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type StoreOrderEntryOperationResult {
|
|
35
|
+
operationId: String!
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type StoreOrderEntryMissingItem {
|
|
39
|
+
itemId: String!
|
|
40
|
+
itemName: String
|
|
41
|
+
reason: String!
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type StoreOrderEntryOperationStatus {
|
|
45
|
+
status: String!
|
|
46
|
+
entityId: String
|
|
47
|
+
message: String
|
|
48
|
+
missingItems: [StoreOrderEntryMissingItem!]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type StoreOrderFormCartItem {
|
|
52
|
+
id: String!
|
|
53
|
+
name: String!
|
|
54
|
+
price: Int!
|
|
55
|
+
listPrice: Int!
|
|
56
|
+
quantity: Int!
|
|
57
|
+
imageUrl: String
|
|
58
|
+
availability: String!
|
|
59
|
+
seller: String!
|
|
60
|
+
unitMultiplier: Float
|
|
61
|
+
}
|
|
@@ -461,6 +461,15 @@ type Query {
|
|
|
461
461
|
geoCoordinates: IStoreGeoCoordinates
|
|
462
462
|
): PickupPoints
|
|
463
463
|
@cacheControl(scope: "public", sMaxAge: 300, staleWhileRevalidate: 3600)
|
|
464
|
+
"""
|
|
465
|
+
Returns the status of an Order Entry Service operation by its ID.
|
|
466
|
+
"""
|
|
467
|
+
orderEntryOperation(operationId: String!): StoreOrderEntryOperationStatus
|
|
468
|
+
@auth
|
|
469
|
+
"""
|
|
470
|
+
Returns the items in an orderForm by its ID.
|
|
471
|
+
"""
|
|
472
|
+
orderFormItems(orderFormId: String!): [StoreOrderFormCartItem!]! @auth
|
|
464
473
|
}
|
|
465
474
|
|
|
466
475
|
type ValidateUserData {
|