@deliverart/sdk-js-customer 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/.changeset/config.json +11 -0
- package/.github/workflows/workflow.yml +47 -0
- package/.prettierrc +7 -0
- package/CHANGELOG.md +37 -0
- package/README.md +3 -0
- package/dist/index.cjs +747 -0
- package/dist/index.d.cts +4485 -0
- package/dist/index.d.ts +4485 -0
- package/dist/index.js +667 -0
- package/eslint.config.js +41 -0
- package/package.json +48 -0
- package/src/index.ts +3 -0
- package/src/models.ts +102 -0
- package/src/requests/customer-addresses/CreateCustomerAddress.ts +36 -0
- package/src/requests/customer-addresses/DeleteCustomerAddress.ts +27 -0
- package/src/requests/customer-addresses/GetCustomerAddressDetails.ts +33 -0
- package/src/requests/customer-addresses/GetCustomerAddresses.ts +57 -0
- package/src/requests/customer-addresses/GetCustomerAddressesForCustomer.ts +55 -0
- package/src/requests/customer-addresses/UpdateCustomerAddress.ts +39 -0
- package/src/requests/customer-addresses/index.ts +6 -0
- package/src/requests/customer-business-profiles/CreateCustomerBusinessProfile.ts +39 -0
- package/src/requests/customer-business-profiles/DeleteCustomerBusinessProfile.ts +27 -0
- package/src/requests/customer-business-profiles/GetCustomerBusinessProfileDetails.ts +33 -0
- package/src/requests/customer-business-profiles/GetCustomerBusinessProfiles.ts +67 -0
- package/src/requests/customer-business-profiles/GetCustomerBusinessProfilesForCustomer.ts +61 -0
- package/src/requests/customer-business-profiles/UpdateCustomerBusinessProfile.ts +42 -0
- package/src/requests/customer-business-profiles/index.ts +6 -0
- package/src/requests/customers/CreateCustomer.ts +32 -0
- package/src/requests/customers/DeleteCustomer.ts +27 -0
- package/src/requests/customers/GetCustomerDetails.ts +30 -0
- package/src/requests/customers/GetCustomers.ts +72 -0
- package/src/requests/customers/UpdateCustomer.ts +35 -0
- package/src/requests/customers/index.ts +5 -0
- package/src/requests/index.ts +3 -0
- package/src/types.ts +66 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AbstractApiRequest } from '@deliverart/sdk-js-core'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
CustomerBusinessProfileDetails,
|
|
6
|
+
customerBusinessProfileDetailsSchema,
|
|
7
|
+
writableCustomerBusinessProfileSchema,
|
|
8
|
+
} from '../../models'
|
|
9
|
+
|
|
10
|
+
export const updateCustomerBusinessProfileInputSchema =
|
|
11
|
+
writableCustomerBusinessProfileSchema.partial()
|
|
12
|
+
export type UpdateCustomerBusinessProfileInput = z.infer<
|
|
13
|
+
typeof updateCustomerBusinessProfileInputSchema
|
|
14
|
+
>
|
|
15
|
+
|
|
16
|
+
export const updateCustomerBusinessProfileResponseSchema = customerBusinessProfileDetailsSchema
|
|
17
|
+
export type UpdateCustomerBusinessProfileResponse = CustomerBusinessProfileDetails
|
|
18
|
+
|
|
19
|
+
export class UpdateCustomerBusinessProfile extends AbstractApiRequest<
|
|
20
|
+
UpdateCustomerBusinessProfileInput,
|
|
21
|
+
UpdateCustomerBusinessProfileResponse
|
|
22
|
+
> {
|
|
23
|
+
readonly method = 'PATCH'
|
|
24
|
+
readonly contentType = 'application/merge-patch+json'
|
|
25
|
+
readonly accept = 'application/json'
|
|
26
|
+
|
|
27
|
+
readonly inputSchema = updateCustomerBusinessProfileInputSchema
|
|
28
|
+
readonly outputSchema = updateCustomerBusinessProfileResponseSchema
|
|
29
|
+
readonly querySchema = undefined
|
|
30
|
+
readonly headersSchema = undefined
|
|
31
|
+
|
|
32
|
+
private readonly customerId: string
|
|
33
|
+
|
|
34
|
+
constructor(customerId: string, input: UpdateCustomerBusinessProfileInput) {
|
|
35
|
+
super(input)
|
|
36
|
+
this.customerId = customerId
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getPath(): string {
|
|
40
|
+
return `/customers/business_profiles/${this.customerId}`
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './CreateCustomerBusinessProfile'
|
|
2
|
+
export * from './DeleteCustomerBusinessProfile'
|
|
3
|
+
export * from './GetCustomerBusinessProfileDetails'
|
|
4
|
+
export * from './GetCustomerBusinessProfiles'
|
|
5
|
+
export * from './GetCustomerBusinessProfilesForCustomer'
|
|
6
|
+
export * from './UpdateCustomerBusinessProfile'
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AbstractApiRequest } from '@deliverart/sdk-js-core'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
import { CustomerDetails, customerDetailsSchema, writableCreateCustomerSchema } from '../../models'
|
|
5
|
+
|
|
6
|
+
export const createCustomerInputSchema = writableCreateCustomerSchema.required()
|
|
7
|
+
export type CreateCustomerInput = z.infer<typeof createCustomerInputSchema>
|
|
8
|
+
|
|
9
|
+
export const createCustomerResponseSchema = customerDetailsSchema
|
|
10
|
+
export type CreateCustomerResponse = CustomerDetails
|
|
11
|
+
|
|
12
|
+
export class CreateCustomer extends AbstractApiRequest<
|
|
13
|
+
CreateCustomerInput,
|
|
14
|
+
CreateCustomerResponse
|
|
15
|
+
> {
|
|
16
|
+
readonly method = 'POST'
|
|
17
|
+
readonly contentType = 'application/json'
|
|
18
|
+
readonly accept = 'application/json'
|
|
19
|
+
|
|
20
|
+
readonly inputSchema = createCustomerInputSchema
|
|
21
|
+
readonly outputSchema = createCustomerResponseSchema
|
|
22
|
+
readonly querySchema = undefined
|
|
23
|
+
readonly headersSchema = undefined
|
|
24
|
+
|
|
25
|
+
constructor(input: CreateCustomerInput) {
|
|
26
|
+
super(input)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
getPath(): string {
|
|
30
|
+
return '/customers'
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AbstractApiRequest } from '@deliverart/sdk-js-core'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
export const deleteCustomerInputSchema = z.undefined()
|
|
5
|
+
export const deleteCustomerResponseSchema = z.undefined()
|
|
6
|
+
|
|
7
|
+
export class DeleteCustomer extends AbstractApiRequest<void, void> {
|
|
8
|
+
readonly method = 'DELETE'
|
|
9
|
+
readonly contentType = 'application/json'
|
|
10
|
+
readonly accept = 'application/json'
|
|
11
|
+
|
|
12
|
+
readonly inputSchema = deleteCustomerInputSchema
|
|
13
|
+
readonly outputSchema = deleteCustomerResponseSchema
|
|
14
|
+
readonly querySchema = undefined
|
|
15
|
+
readonly headersSchema = undefined
|
|
16
|
+
|
|
17
|
+
private readonly customerId: string
|
|
18
|
+
|
|
19
|
+
constructor(customerId: string) {
|
|
20
|
+
super()
|
|
21
|
+
this.customerId = customerId
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getPath(): string {
|
|
25
|
+
return `/customers/${this.customerId}`
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AbstractApiRequest } from '@deliverart/sdk-js-core'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
import { CustomerDetails, customerDetailsSchema } from '../../models'
|
|
5
|
+
|
|
6
|
+
export const getCustomerDetailsInputSchema = z.undefined()
|
|
7
|
+
|
|
8
|
+
export const getCustomerDetailsResponseSchema = customerDetailsSchema
|
|
9
|
+
export type GetCustomerDetailsResponse = CustomerDetails
|
|
10
|
+
|
|
11
|
+
export class GetCustomerDetails extends AbstractApiRequest<void, GetCustomerDetailsResponse> {
|
|
12
|
+
readonly method = 'GET'
|
|
13
|
+
readonly contentType = 'application/json'
|
|
14
|
+
readonly accept = 'application/json'
|
|
15
|
+
readonly inputSchema = getCustomerDetailsInputSchema
|
|
16
|
+
readonly outputSchema = getCustomerDetailsResponseSchema
|
|
17
|
+
readonly querySchema = undefined
|
|
18
|
+
readonly headersSchema = undefined
|
|
19
|
+
|
|
20
|
+
private readonly customerId: string
|
|
21
|
+
|
|
22
|
+
constructor(customerId: string) {
|
|
23
|
+
super()
|
|
24
|
+
this.customerId = customerId
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getPath(): string {
|
|
28
|
+
return `/customers/${this.customerId}`
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { AbstractApiRequest } from '@deliverart/sdk-js-core'
|
|
2
|
+
import {
|
|
3
|
+
createPaginatedSchema,
|
|
4
|
+
Paginated,
|
|
5
|
+
responseToPagination,
|
|
6
|
+
sortDirSchema,
|
|
7
|
+
timestampsFilterSchema,
|
|
8
|
+
} from '@deliverart/sdk-js-global-types'
|
|
9
|
+
import { AxiosResponse } from 'axios'
|
|
10
|
+
import { z } from 'zod'
|
|
11
|
+
|
|
12
|
+
import { Customer, customerSchema } from '../../models'
|
|
13
|
+
|
|
14
|
+
export const getCustomersQuerySchema = z
|
|
15
|
+
.object({
|
|
16
|
+
firstName: z.string().optional(),
|
|
17
|
+
lastName: z.string().optional(),
|
|
18
|
+
email: z.string().optional(),
|
|
19
|
+
phoneNumber: z.string().optional(),
|
|
20
|
+
hasBusinessProfiles: z.coerce.boolean().optional(),
|
|
21
|
+
hasAddresses: z.coerce.boolean().optional(),
|
|
22
|
+
'ordersPlaced[between]': z.coerce.number().optional(),
|
|
23
|
+
'ordersPlaced[gt]': z.coerce.number().optional(),
|
|
24
|
+
'ordersPlaced[gte]': z.coerce.number().optional(),
|
|
25
|
+
'ordersPlaced[lt]': z.coerce.number().optional(),
|
|
26
|
+
'ordersPlaced[lte]': z.coerce.number().optional(),
|
|
27
|
+
'totalSpent[between]': z.coerce.number().optional(),
|
|
28
|
+
'totalSpent[gt]': z.coerce.number().optional(),
|
|
29
|
+
'totalSpent[gte]': z.coerce.number().optional(),
|
|
30
|
+
'totalSpent[lt]': z.coerce.number().optional(),
|
|
31
|
+
'totalSpent[lte]': z.coerce.number().optional(),
|
|
32
|
+
'order[firstName]': sortDirSchema.optional(),
|
|
33
|
+
'order[lastName]': sortDirSchema.optional(),
|
|
34
|
+
'order[createdAt]': sortDirSchema.optional(),
|
|
35
|
+
'order[updatedAt]': sortDirSchema.optional(),
|
|
36
|
+
page: z.coerce.number().optional(),
|
|
37
|
+
})
|
|
38
|
+
.merge(timestampsFilterSchema)
|
|
39
|
+
export type GetCustomersQueryParams = z.infer<typeof getCustomersQuerySchema>
|
|
40
|
+
|
|
41
|
+
export const getCustomersResponseSchema = createPaginatedSchema(customerSchema)
|
|
42
|
+
export type GetCustomersResponse = z.infer<typeof getCustomersResponseSchema>
|
|
43
|
+
|
|
44
|
+
export const getCustomersInputSchema = z.undefined()
|
|
45
|
+
|
|
46
|
+
export class GetCustomers extends AbstractApiRequest<
|
|
47
|
+
void,
|
|
48
|
+
GetCustomersResponse,
|
|
49
|
+
GetCustomersQueryParams
|
|
50
|
+
> {
|
|
51
|
+
readonly method = 'GET'
|
|
52
|
+
readonly contentType = 'application/json'
|
|
53
|
+
readonly accept = 'application/json'
|
|
54
|
+
|
|
55
|
+
readonly inputSchema = getCustomersInputSchema
|
|
56
|
+
readonly outputSchema = getCustomersResponseSchema
|
|
57
|
+
readonly querySchema = getCustomersQuerySchema
|
|
58
|
+
readonly headersSchema = undefined
|
|
59
|
+
|
|
60
|
+
constructor(options?: { query?: GetCustomersQueryParams }) {
|
|
61
|
+
super(undefined, options)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getPath(): string {
|
|
65
|
+
return '/customers'
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
parseResponse(data: unknown, rawResponse: AxiosResponse): Paginated<Customer> {
|
|
69
|
+
const customers = z.array(customerSchema).parse(data)
|
|
70
|
+
return this.validateOutput({ data: customers, pagination: responseToPagination(rawResponse) })
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AbstractApiRequest } from '@deliverart/sdk-js-core'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
import { CustomerDetails, customerDetailsSchema, writableCustomerSchema } from '../../models'
|
|
5
|
+
|
|
6
|
+
export const updateCustomerInputSchema = writableCustomerSchema.partial()
|
|
7
|
+
export type UpdateCustomerInput = z.infer<typeof updateCustomerInputSchema>
|
|
8
|
+
|
|
9
|
+
export const updateCustomerResponseSchema = customerDetailsSchema
|
|
10
|
+
export type UpdateCustomerResponse = CustomerDetails
|
|
11
|
+
|
|
12
|
+
export class UpdateCustomer extends AbstractApiRequest<
|
|
13
|
+
UpdateCustomerInput,
|
|
14
|
+
UpdateCustomerResponse
|
|
15
|
+
> {
|
|
16
|
+
readonly method = 'PATCH'
|
|
17
|
+
readonly contentType = 'application/merge-patch+json'
|
|
18
|
+
readonly accept = 'application/json'
|
|
19
|
+
|
|
20
|
+
readonly inputSchema = updateCustomerInputSchema
|
|
21
|
+
readonly outputSchema = updateCustomerResponseSchema
|
|
22
|
+
readonly querySchema = undefined
|
|
23
|
+
readonly headersSchema = undefined
|
|
24
|
+
|
|
25
|
+
private readonly customerId: string
|
|
26
|
+
|
|
27
|
+
constructor(customerId: string, input: UpdateCustomerInput) {
|
|
28
|
+
super(input)
|
|
29
|
+
this.customerId = customerId
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getPath(): string {
|
|
33
|
+
return `/customers/${this.customerId}`
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
export const customerPathSchema = z
|
|
4
|
+
.string()
|
|
5
|
+
.refine(val => /^\/customers\/[a-z_]+\/[0-9a-fA-F-]{36}$/.test(val), {
|
|
6
|
+
message: 'Invalid customer path format',
|
|
7
|
+
})
|
|
8
|
+
export type CustomerPath = z.infer<typeof customerPathSchema>
|
|
9
|
+
|
|
10
|
+
export const customerNullablePathSchema = z
|
|
11
|
+
.string()
|
|
12
|
+
.nullable()
|
|
13
|
+
.refine(
|
|
14
|
+
val => {
|
|
15
|
+
if (!val) return true
|
|
16
|
+
return /^\/customers\/[a-z_]+\/[0-9a-fA-F-]{36}$/.test(val)
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
message: 'Invalid customer path format',
|
|
20
|
+
},
|
|
21
|
+
)
|
|
22
|
+
export type CustomerNullablePath = z.infer<typeof customerNullablePathSchema>
|
|
23
|
+
|
|
24
|
+
export const customerAddressPathSchema = z
|
|
25
|
+
.string()
|
|
26
|
+
.refine(val => /^\/customers\/addresses\/[a-z_]+\/[0-9a-fA-F-]{36}$/.test(val), {
|
|
27
|
+
message: 'Invalid customerAddress path format',
|
|
28
|
+
})
|
|
29
|
+
export type CustomerAddressPath = z.infer<typeof customerAddressPathSchema>
|
|
30
|
+
|
|
31
|
+
export const customerAddressNullablePathSchema = z
|
|
32
|
+
.string()
|
|
33
|
+
.nullable()
|
|
34
|
+
.refine(
|
|
35
|
+
val => {
|
|
36
|
+
if (!val) return true
|
|
37
|
+
return /^\/customers\/addresses\/[a-z_]+\/[0-9a-fA-F-]{36}$/.test(val)
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
message: 'Invalid customerAddress path format',
|
|
41
|
+
},
|
|
42
|
+
)
|
|
43
|
+
export type CustomerAddressNullablePath = z.infer<typeof customerAddressNullablePathSchema>
|
|
44
|
+
|
|
45
|
+
export const customerBusinessProfilePathSchema = z
|
|
46
|
+
.string()
|
|
47
|
+
.refine(val => /^\/customers\/business_profiles\/[a-z_]+\/[0-9a-fA-F-]{36}$/.test(val), {
|
|
48
|
+
message: 'Invalid customerBusinessProfile path format',
|
|
49
|
+
})
|
|
50
|
+
export type CustomerBusinessProfilePath = z.infer<typeof customerBusinessProfilePathSchema>
|
|
51
|
+
|
|
52
|
+
export const customerBusinessProfileNullablePathSchema = z
|
|
53
|
+
.string()
|
|
54
|
+
.nullable()
|
|
55
|
+
.refine(
|
|
56
|
+
val => {
|
|
57
|
+
if (!val) return true
|
|
58
|
+
return /^\/customers\/business_profiles\/[a-z_]+\/[0-9a-fA-F-]{36}$/.test(val)
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
message: 'Invalid customerBusinessProfile path format',
|
|
62
|
+
},
|
|
63
|
+
)
|
|
64
|
+
export type CustomerBusinessProfileNullablePath = z.infer<
|
|
65
|
+
typeof customerBusinessProfileNullablePathSchema
|
|
66
|
+
>
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Node",
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"forceConsistentCasingInFileNames": true,
|
|
8
|
+
"strict": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"outDir": "dist",
|
|
11
|
+
"declaration": true,
|
|
12
|
+
"declarationMap": true
|
|
13
|
+
},
|
|
14
|
+
"include": ["src"]
|
|
15
|
+
}
|