@paakd/api 0.0.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.
- package/dist/src/index.js +21 -0
- package/package.json +59 -0
- package/src/address.spec.ts +662 -0
- package/src/address.ts +300 -0
- package/src/auth.spec.ts +771 -0
- package/src/auth.ts +168 -0
- package/src/compressor/brotli.ts +26 -0
- package/src/index.ts +5 -0
- package/src/interceptors.spec.ts +1343 -0
- package/src/interceptors.ts +224 -0
- package/src/policies.spec.ts +595 -0
- package/src/policies.ts +431 -0
- package/src/products.spec.ts +710 -0
- package/src/products.ts +112 -0
- package/src/profile.spec.ts +626 -0
- package/src/profile.ts +169 -0
- package/src/proto/auth/v1/entities/auth.proto +140 -0
- package/src/proto/auth/v1/entities/policy.proto +57 -0
- package/src/proto/auth/v1/service.proto +26 -0
- package/src/proto/customers/v1/entities/address.proto +101 -0
- package/src/proto/customers/v1/entities/profile.proto +118 -0
- package/src/proto/customers/v1/service.proto +36 -0
- package/src/proto/files/v1/entities/file.proto +62 -0
- package/src/proto/files/v1/service.proto +19 -0
- package/src/proto/products/v1/entities/category.proto +98 -0
- package/src/proto/products/v1/entities/collection.proto +72 -0
- package/src/proto/products/v1/entities/product/create.proto +41 -0
- package/src/proto/products/v1/entities/product/option.proto +17 -0
- package/src/proto/products/v1/entities/product/shared.proto +255 -0
- package/src/proto/products/v1/entities/product/update.proto +66 -0
- package/src/proto/products/v1/entities/tag.proto +73 -0
- package/src/proto/products/v1/entities/taxonomy.proto +146 -0
- package/src/proto/products/v1/entities/type.proto +98 -0
- package/src/proto/products/v1/entities/variant.proto +127 -0
- package/src/proto/products/v1/service.proto +78 -0
- package/src/proto/promotions/v1/entities/campaign.proto +145 -0
- package/src/proto/promotions/v1/service.proto +17 -0
- package/src/proto/stocknodes/v1/entities/stocknode.proto +167 -0
- package/src/proto/stocknodes/v1/service.proto +21 -0
- package/src/registration.ts +170 -0
- package/src/test-utils.ts +176 -0
package/src/products.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Code, ConnectError, createClient } from '@connectrpc/connect'
|
|
2
|
+
import { createGrpcTransport } from '@connectrpc/connect-node'
|
|
3
|
+
import { getCheckoutConfig } from '@paakd/config'
|
|
4
|
+
import { ProductsService } from '../gen/src/proto/products/v1/service_pb'
|
|
5
|
+
import type { CreateCollectionRequest } from '../gen/src/proto/products/v1/entities/collection_pb'
|
|
6
|
+
import { brotliCompression } from './compressor/brotli'
|
|
7
|
+
import {
|
|
8
|
+
createAuthenticationInterceptor,
|
|
9
|
+
createHeadersInterceptor,
|
|
10
|
+
} from './interceptors'
|
|
11
|
+
|
|
12
|
+
export interface GetCollectionByIDProps {
|
|
13
|
+
body: {
|
|
14
|
+
collectionId: string
|
|
15
|
+
}
|
|
16
|
+
headers: Record<string, string | null>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface CreateCollectionProps {
|
|
20
|
+
body: Omit<CreateCollectionRequest, '$typeName'>
|
|
21
|
+
headers: Record<string, string | null>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function getCollectionByID({
|
|
25
|
+
body: { collectionId },
|
|
26
|
+
headers,
|
|
27
|
+
}: GetCollectionByIDProps) {
|
|
28
|
+
try {
|
|
29
|
+
const checkoutConfig = await getCheckoutConfig()
|
|
30
|
+
const productClient = createClient(
|
|
31
|
+
ProductsService,
|
|
32
|
+
createGrpcTransport({
|
|
33
|
+
baseUrl: checkoutConfig.enterpriseURL,
|
|
34
|
+
interceptors: [
|
|
35
|
+
createHeadersInterceptor(headers),
|
|
36
|
+
createAuthenticationInterceptor(checkoutConfig),
|
|
37
|
+
],
|
|
38
|
+
acceptCompression: [brotliCompression],
|
|
39
|
+
sendCompression: brotliCompression,
|
|
40
|
+
})
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
const value = await productClient.getCollectionByID({
|
|
44
|
+
id: collectionId,
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
value,
|
|
49
|
+
status: 'success',
|
|
50
|
+
}
|
|
51
|
+
} catch (err) {
|
|
52
|
+
if (err instanceof ConnectError) {
|
|
53
|
+
return {
|
|
54
|
+
code: err.code,
|
|
55
|
+
rawMessage: err.rawMessage,
|
|
56
|
+
message: err.rawMessage,
|
|
57
|
+
status: 'failed',
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
code: Code.Internal,
|
|
63
|
+
rawMessage: 'An unexpected error occurred while fetching the collection.',
|
|
64
|
+
message: 'An unexpected error occurred while fetching the collection.',
|
|
65
|
+
status: 'failed',
|
|
66
|
+
} as unknown as ConnectError
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function createCollection({
|
|
71
|
+
body,
|
|
72
|
+
headers,
|
|
73
|
+
}: CreateCollectionProps) {
|
|
74
|
+
try {
|
|
75
|
+
const checkoutConfig = await getCheckoutConfig()
|
|
76
|
+
const productClient = createClient(
|
|
77
|
+
ProductsService,
|
|
78
|
+
createGrpcTransport({
|
|
79
|
+
baseUrl: checkoutConfig.enterpriseURL,
|
|
80
|
+
interceptors: [
|
|
81
|
+
createHeadersInterceptor(headers),
|
|
82
|
+
createAuthenticationInterceptor(checkoutConfig),
|
|
83
|
+
],
|
|
84
|
+
acceptCompression: [brotliCompression],
|
|
85
|
+
sendCompression: brotliCompression,
|
|
86
|
+
})
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
const value = await productClient.createCollection(body)
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
value,
|
|
93
|
+
status: 'success',
|
|
94
|
+
}
|
|
95
|
+
} catch (err) {
|
|
96
|
+
if (err instanceof ConnectError) {
|
|
97
|
+
return {
|
|
98
|
+
code: err.code,
|
|
99
|
+
rawMessage: err.rawMessage,
|
|
100
|
+
message: err.rawMessage,
|
|
101
|
+
status: 'failed',
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
code: Code.Internal,
|
|
107
|
+
rawMessage: 'An unexpected error occurred while creating the collection.',
|
|
108
|
+
message: 'An unexpected error occurred while creating the collection.',
|
|
109
|
+
status: 'failed',
|
|
110
|
+
} as unknown as ConnectError
|
|
111
|
+
}
|
|
112
|
+
}
|