@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/address.ts
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { Code, ConnectError, createClient } from '@connectrpc/connect'
|
|
2
|
+
import { createGrpcTransport } from '@connectrpc/connect-node'
|
|
3
|
+
import { getCheckoutConfig } from '@paakd/config'
|
|
4
|
+
import { CustomerService } from '../gen/src/proto/customers/v1/service_pb'
|
|
5
|
+
import type {
|
|
6
|
+
AddAddressRequest,
|
|
7
|
+
UpdateAddressRequest,
|
|
8
|
+
GetAddressResponse,
|
|
9
|
+
DeleteAddressResponse,
|
|
10
|
+
} from '../gen/src/proto/customers/v1/entities/address_pb'
|
|
11
|
+
import { brotliCompression } from './compressor/brotli'
|
|
12
|
+
import {
|
|
13
|
+
createAuthenticationInterceptor,
|
|
14
|
+
createCustomerAuthenticationInterceptor,
|
|
15
|
+
createHeadersInterceptor,
|
|
16
|
+
} from './interceptors'
|
|
17
|
+
|
|
18
|
+
export interface GetAddressProps {
|
|
19
|
+
body: {
|
|
20
|
+
customerId: string
|
|
21
|
+
addressId: string
|
|
22
|
+
jwt: string
|
|
23
|
+
}
|
|
24
|
+
headers: Record<string, string | null>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface GetAddressesProps {
|
|
28
|
+
body: {
|
|
29
|
+
customerId: string
|
|
30
|
+
jwt: string
|
|
31
|
+
}
|
|
32
|
+
headers: Record<string, string | null>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface AddAddressProps {
|
|
36
|
+
body: Omit<AddAddressRequest, '$typeName'> & { jwt: string }
|
|
37
|
+
headers: Record<string, string | null>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface UpdateAddressProps {
|
|
41
|
+
body: Omit<UpdateAddressRequest, '$typeName'> & { jwt: string }
|
|
42
|
+
headers: Record<string, string | null>
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface DeleteAddressProps {
|
|
46
|
+
body: {
|
|
47
|
+
customerId: string
|
|
48
|
+
addressId: string
|
|
49
|
+
jwt: string
|
|
50
|
+
}
|
|
51
|
+
headers: Record<string, string | null>
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Success and error response types with discriminated unions
|
|
55
|
+
export type SuccessResponse<T> = {
|
|
56
|
+
value: T
|
|
57
|
+
status: 'success'
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type ErrorResponse = {
|
|
61
|
+
code: number
|
|
62
|
+
rawMessage: string
|
|
63
|
+
message: string
|
|
64
|
+
status: 'failed'
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type ApiResponse<T> = SuccessResponse<T> | ErrorResponse
|
|
68
|
+
|
|
69
|
+
export async function getAddresses({
|
|
70
|
+
body: { customerId, jwt },
|
|
71
|
+
headers,
|
|
72
|
+
}: GetAddressesProps): Promise<ApiResponse<GetAddressResponse[]>> {
|
|
73
|
+
try {
|
|
74
|
+
const checkoutConfig = await getCheckoutConfig()
|
|
75
|
+
const addressClient = createClient(
|
|
76
|
+
CustomerService,
|
|
77
|
+
createGrpcTransport({
|
|
78
|
+
baseUrl: checkoutConfig.enterpriseURL,
|
|
79
|
+
interceptors: [
|
|
80
|
+
createHeadersInterceptor(headers),
|
|
81
|
+
createAuthenticationInterceptor(checkoutConfig),
|
|
82
|
+
createCustomerAuthenticationInterceptor(jwt),
|
|
83
|
+
],
|
|
84
|
+
acceptCompression: [brotliCompression],
|
|
85
|
+
sendCompression: brotliCompression,
|
|
86
|
+
})
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
const { addresses } = await addressClient.getAddresses({
|
|
90
|
+
customerId,
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
value: addresses,
|
|
95
|
+
status: 'success',
|
|
96
|
+
}
|
|
97
|
+
} catch (err: unknown) {
|
|
98
|
+
if (err instanceof ConnectError) {
|
|
99
|
+
return {
|
|
100
|
+
code: err.code,
|
|
101
|
+
rawMessage: err.rawMessage,
|
|
102
|
+
message: err.rawMessage,
|
|
103
|
+
status: 'failed',
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
code: Code.Internal,
|
|
109
|
+
rawMessage: 'error fetching addresses.',
|
|
110
|
+
message: 'error fetching addresses.',
|
|
111
|
+
status: 'failed',
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export async function getAddress({
|
|
117
|
+
body: { customerId, addressId, jwt },
|
|
118
|
+
headers,
|
|
119
|
+
}: GetAddressProps): Promise<ApiResponse<GetAddressResponse>> {
|
|
120
|
+
try {
|
|
121
|
+
const checkoutConfig = await getCheckoutConfig()
|
|
122
|
+
const addressClient = createClient(
|
|
123
|
+
CustomerService,
|
|
124
|
+
createGrpcTransport({
|
|
125
|
+
baseUrl: checkoutConfig.enterpriseURL,
|
|
126
|
+
interceptors: [
|
|
127
|
+
createHeadersInterceptor(headers),
|
|
128
|
+
createAuthenticationInterceptor(checkoutConfig),
|
|
129
|
+
createCustomerAuthenticationInterceptor(jwt),
|
|
130
|
+
],
|
|
131
|
+
acceptCompression: [brotliCompression],
|
|
132
|
+
sendCompression: brotliCompression,
|
|
133
|
+
})
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
const value = await addressClient.getAddress({
|
|
137
|
+
customerId,
|
|
138
|
+
addressId,
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
value,
|
|
143
|
+
status: 'success',
|
|
144
|
+
}
|
|
145
|
+
} catch (err: unknown) {
|
|
146
|
+
if (err instanceof ConnectError) {
|
|
147
|
+
return {
|
|
148
|
+
code: err.code,
|
|
149
|
+
rawMessage: err.rawMessage,
|
|
150
|
+
message: err.rawMessage,
|
|
151
|
+
status: 'failed',
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
code: Code.Internal,
|
|
157
|
+
rawMessage: 'error fetching address.',
|
|
158
|
+
message: 'error fetching address.',
|
|
159
|
+
status: 'failed',
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export async function addAddress({
|
|
165
|
+
body: { jwt, ...val },
|
|
166
|
+
headers,
|
|
167
|
+
}: AddAddressProps): Promise<ApiResponse<GetAddressResponse | undefined>> {
|
|
168
|
+
try {
|
|
169
|
+
const checkoutConfig = await getCheckoutConfig()
|
|
170
|
+
const addressClient = createClient(
|
|
171
|
+
CustomerService,
|
|
172
|
+
createGrpcTransport({
|
|
173
|
+
baseUrl: checkoutConfig.enterpriseURL,
|
|
174
|
+
interceptors: [
|
|
175
|
+
createHeadersInterceptor(headers),
|
|
176
|
+
createAuthenticationInterceptor(checkoutConfig),
|
|
177
|
+
createCustomerAuthenticationInterceptor(jwt),
|
|
178
|
+
],
|
|
179
|
+
acceptCompression: [brotliCompression],
|
|
180
|
+
sendCompression: brotliCompression,
|
|
181
|
+
})
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
const { address } = await addressClient.addAddress(val)
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
value: address,
|
|
188
|
+
status: 'success',
|
|
189
|
+
}
|
|
190
|
+
} catch (err: unknown) {
|
|
191
|
+
if (err instanceof ConnectError) {
|
|
192
|
+
return {
|
|
193
|
+
code: err.code,
|
|
194
|
+
rawMessage: err.rawMessage,
|
|
195
|
+
message: err.rawMessage,
|
|
196
|
+
status: 'failed',
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return {
|
|
201
|
+
code: Code.Internal,
|
|
202
|
+
rawMessage: 'error adding address.',
|
|
203
|
+
message: 'error adding address.',
|
|
204
|
+
status: 'failed',
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export async function deleteAddress({
|
|
210
|
+
body: { customerId, addressId, jwt },
|
|
211
|
+
headers,
|
|
212
|
+
}: DeleteAddressProps): Promise<ApiResponse<DeleteAddressResponse>> {
|
|
213
|
+
try {
|
|
214
|
+
const checkoutConfig = await getCheckoutConfig()
|
|
215
|
+
const addressClient = createClient(
|
|
216
|
+
CustomerService,
|
|
217
|
+
createGrpcTransport({
|
|
218
|
+
baseUrl: checkoutConfig.enterpriseURL,
|
|
219
|
+
interceptors: [
|
|
220
|
+
createHeadersInterceptor(headers),
|
|
221
|
+
createAuthenticationInterceptor(checkoutConfig),
|
|
222
|
+
createCustomerAuthenticationInterceptor(jwt),
|
|
223
|
+
],
|
|
224
|
+
acceptCompression: [brotliCompression],
|
|
225
|
+
sendCompression: brotliCompression,
|
|
226
|
+
})
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
const value = await addressClient.deleteAddress({
|
|
230
|
+
customerId,
|
|
231
|
+
addressId,
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
value,
|
|
236
|
+
status: 'success',
|
|
237
|
+
}
|
|
238
|
+
} catch (err: unknown) {
|
|
239
|
+
if (err instanceof ConnectError) {
|
|
240
|
+
return {
|
|
241
|
+
code: err.code,
|
|
242
|
+
rawMessage: err.rawMessage,
|
|
243
|
+
message: err.rawMessage,
|
|
244
|
+
status: 'failed',
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return {
|
|
249
|
+
code: Code.Internal,
|
|
250
|
+
rawMessage: 'error deleting address.',
|
|
251
|
+
message: 'error deleting address.',
|
|
252
|
+
status: 'failed',
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export async function updateAddress({
|
|
258
|
+
body: { jwt, ...val },
|
|
259
|
+
headers,
|
|
260
|
+
}: UpdateAddressProps): Promise<ApiResponse<GetAddressResponse | undefined>> {
|
|
261
|
+
try {
|
|
262
|
+
const checkoutConfig = await getCheckoutConfig()
|
|
263
|
+
const addressClient = createClient(
|
|
264
|
+
CustomerService,
|
|
265
|
+
createGrpcTransport({
|
|
266
|
+
baseUrl: checkoutConfig.enterpriseURL,
|
|
267
|
+
interceptors: [
|
|
268
|
+
createHeadersInterceptor(headers),
|
|
269
|
+
createAuthenticationInterceptor(checkoutConfig),
|
|
270
|
+
createCustomerAuthenticationInterceptor(jwt),
|
|
271
|
+
],
|
|
272
|
+
acceptCompression: [brotliCompression],
|
|
273
|
+
sendCompression: brotliCompression,
|
|
274
|
+
})
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
const { address } = await addressClient.updateAddress(val)
|
|
278
|
+
|
|
279
|
+
return {
|
|
280
|
+
value: address,
|
|
281
|
+
status: 'success',
|
|
282
|
+
}
|
|
283
|
+
} catch (err: unknown) {
|
|
284
|
+
if (err instanceof ConnectError) {
|
|
285
|
+
return {
|
|
286
|
+
code: err.code,
|
|
287
|
+
rawMessage: err.rawMessage,
|
|
288
|
+
message: err.rawMessage,
|
|
289
|
+
status: 'failed',
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return {
|
|
294
|
+
code: Code.Internal,
|
|
295
|
+
rawMessage: 'error updating address.',
|
|
296
|
+
message: 'error updating address.',
|
|
297
|
+
status: 'failed',
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|