@reactionary/core 0.2.1 → 0.2.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/package.json +1 -1
- package/schemas/models/profile.model.js +1 -1
- package/schemas/mutations/profile.mutation.js +31 -3
- package/schemas/queries/profile.query.js +5 -2
- package/src/providers/profile.provider.d.ts +65 -4
- package/src/schemas/models/profile.model.d.ts +2 -2
- package/src/schemas/mutations/profile.mutation.d.ts +78 -0
- package/src/schemas/queries/profile.query.d.ts +6 -2
package/package.json
CHANGED
|
@@ -22,7 +22,7 @@ const ProfileSchema = BaseModelSchema.extend({
|
|
|
22
22
|
updatedAt: z.string(),
|
|
23
23
|
shippingAddress: AddressSchema.optional(),
|
|
24
24
|
billingAddress: AddressSchema.optional(),
|
|
25
|
-
alternateShippingAddresses: z.array(AddressSchema)
|
|
25
|
+
alternateShippingAddresses: z.array(AddressSchema).default(() => [])
|
|
26
26
|
});
|
|
27
27
|
export {
|
|
28
28
|
AddressSchema,
|
|
@@ -1,9 +1,37 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { BaseMutationSchema } from "./base.mutation.js";
|
|
3
|
+
import { AddressIdentifierSchema, IdentityIdentifierSchema } from "../models/identifiers.model.js";
|
|
4
|
+
import { AddressSchema } from "../models/profile.model.js";
|
|
3
5
|
const ProfileMutationUpdateSchema = BaseMutationSchema.extend({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
identifier: IdentityIdentifierSchema,
|
|
7
|
+
email: z.email().describe("The main contact email of the profile"),
|
|
8
|
+
phone: z.string().describe("The main phone number of the profile")
|
|
9
|
+
});
|
|
10
|
+
const ProfileMutationAddShippingAddressSchema = BaseMutationSchema.extend({
|
|
11
|
+
identifier: IdentityIdentifierSchema,
|
|
12
|
+
address: AddressSchema
|
|
13
|
+
});
|
|
14
|
+
const ProfileMutationRemoveShippingAddressSchema = BaseMutationSchema.extend({
|
|
15
|
+
identifier: IdentityIdentifierSchema,
|
|
16
|
+
addressIdentifier: AddressIdentifierSchema
|
|
17
|
+
});
|
|
18
|
+
const ProfileMutationUpdateShippingAddressSchema = BaseMutationSchema.extend({
|
|
19
|
+
identifier: IdentityIdentifierSchema,
|
|
20
|
+
address: AddressSchema
|
|
21
|
+
});
|
|
22
|
+
const ProfileMutationMakeShippingAddressDefaultSchema = BaseMutationSchema.extend({
|
|
23
|
+
identifier: IdentityIdentifierSchema,
|
|
24
|
+
addressIdentifier: AddressIdentifierSchema
|
|
25
|
+
});
|
|
26
|
+
const ProfileMutationSetBillingAddressSchema = BaseMutationSchema.extend({
|
|
27
|
+
identifier: IdentityIdentifierSchema,
|
|
28
|
+
address: AddressSchema
|
|
6
29
|
});
|
|
7
30
|
export {
|
|
8
|
-
|
|
31
|
+
ProfileMutationAddShippingAddressSchema,
|
|
32
|
+
ProfileMutationMakeShippingAddressDefaultSchema,
|
|
33
|
+
ProfileMutationRemoveShippingAddressSchema,
|
|
34
|
+
ProfileMutationSetBillingAddressSchema,
|
|
35
|
+
ProfileMutationUpdateSchema,
|
|
36
|
+
ProfileMutationUpdateShippingAddressSchema
|
|
9
37
|
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { BaseQuerySchema } from "./base.query.js";
|
|
2
|
-
|
|
2
|
+
import { IdentityIdentifierSchema } from "../models/identifiers.model.js";
|
|
3
|
+
const ProfileQueryByIdSchema = BaseQuerySchema.extend({
|
|
4
|
+
identifier: IdentityIdentifierSchema
|
|
5
|
+
});
|
|
3
6
|
export {
|
|
4
|
-
|
|
7
|
+
ProfileQueryByIdSchema
|
|
5
8
|
};
|
|
@@ -1,10 +1,71 @@
|
|
|
1
|
+
import type { NotFoundError } from '../schemas/index.js';
|
|
1
2
|
import type { Profile } from '../schemas/models/index.js';
|
|
2
|
-
import type { ProfileMutationUpdate } from '../schemas/mutations/index.js';
|
|
3
|
-
import type { ProfileQuerySelf } from '../schemas/queries/index.js';
|
|
3
|
+
import type { ProfileMutationAddShippingAddress, ProfileMutationMakeShippingAddressDefault, ProfileMutationRemoveShippingAddress, ProfileMutationSetBillingAddress, ProfileMutationUpdate, ProfileMutationUpdateShippingAddress } from '../schemas/mutations/index.js';
|
|
4
|
+
import type { ProfileQuerySelf as ProfileQueryById } from '../schemas/queries/index.js';
|
|
4
5
|
import type { Result } from '../schemas/result.js';
|
|
5
6
|
import { BaseProvider } from './base.provider.js';
|
|
6
7
|
export declare abstract class ProfileProvider extends BaseProvider {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Returns the profile of the currently authenticated (registered) user.
|
|
10
|
+
*
|
|
11
|
+
* Usecase: Fetch the profile of the logged-in user for display in header, or account settings.
|
|
12
|
+
* @param payload
|
|
13
|
+
*/
|
|
14
|
+
abstract getById(payload: ProfileQueryById): Promise<Result<Profile, NotFoundError>>;
|
|
15
|
+
/**
|
|
16
|
+
* Updates the base profile information of the currently authenticated (registered) user.
|
|
17
|
+
*
|
|
18
|
+
* TODO: This should include first/lastname.
|
|
19
|
+
* TODO: In some systems, updating email/phone may require re-verification.
|
|
20
|
+
* TODO: Handle conflicts if email/phone is already in use by another user.
|
|
21
|
+
* TODO: In some systems the email might not be editable.
|
|
22
|
+
*
|
|
23
|
+
* Usecase: Update the user's name, email, or phone number.
|
|
24
|
+
* @param payload
|
|
25
|
+
*/
|
|
26
|
+
abstract update(payload: ProfileMutationUpdate): Promise<Result<Profile, NotFoundError>>;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new shipping address for the currently authenticated (registered) user.
|
|
29
|
+
* Does not set it as default automatically.
|
|
30
|
+
*
|
|
31
|
+
* Usecase: User adds a new shipping address in their profile or during checkout. Ideally, any address manipulation
|
|
32
|
+
* done at checkout should be considered local to that session, unless the addressbook is empty.
|
|
33
|
+
* @param payload
|
|
34
|
+
*/
|
|
35
|
+
abstract addShippingAddress(payload: ProfileMutationAddShippingAddress): Promise<Result<Profile, NotFoundError>>;
|
|
36
|
+
/**
|
|
37
|
+
* Updates an existing shipping address for the currently authenticated (registered) user.
|
|
38
|
+
*
|
|
39
|
+
* Usecase: User edits an existing shipping address in their profile. Ideally, any address manipulation
|
|
40
|
+
* done at checkout should be considered local to that session/order, unless the addressbook is empty.
|
|
41
|
+
* @param payload
|
|
42
|
+
*/
|
|
43
|
+
abstract updateShippingAddress(payload: ProfileMutationUpdateShippingAddress): Promise<Result<Profile, NotFoundError>>;
|
|
44
|
+
/**
|
|
45
|
+
* Removes an existing shipping address for the currently authenticated (registered) user.
|
|
46
|
+
*
|
|
47
|
+
* If the removed address was the default shipping address, the default shipping address is set to a random other address.
|
|
48
|
+
*
|
|
49
|
+
* Usecase: User deletes a shipping address from their profile.
|
|
50
|
+
* @param payload
|
|
51
|
+
*/
|
|
52
|
+
abstract removeShippingAddress(payload: ProfileMutationRemoveShippingAddress): Promise<Result<Profile, NotFoundError>>;
|
|
53
|
+
/**
|
|
54
|
+
* Configures an existing shipping address as the default shipping address for the currently authenticated (registered) user.
|
|
55
|
+
*
|
|
56
|
+
* Usecase: User selects a default shipping address in their profile.
|
|
57
|
+
* @param payload
|
|
58
|
+
*/
|
|
59
|
+
abstract makeShippingAddressDefault(payload: ProfileMutationMakeShippingAddressDefault): Promise<Result<Profile, NotFoundError>>;
|
|
60
|
+
/**
|
|
61
|
+
* Sets the current/active billing address for the currently authenticated (registered) user.
|
|
62
|
+
*
|
|
63
|
+
* Usecase: User sets or updates their billing address in their profile or during checkout.
|
|
64
|
+
*
|
|
65
|
+
* It was a design decision not to support multiple billing addresses. The billing address represents who you are as the commercial
|
|
66
|
+
* entity being billed, and as such it makes sense to have a single authoritative billing address.
|
|
67
|
+
* @param payload
|
|
68
|
+
*/
|
|
69
|
+
abstract setBillingAddress(payload: ProfileMutationSetBillingAddress): Promise<Result<Profile, NotFoundError>>;
|
|
9
70
|
protected getResourceName(): string;
|
|
10
71
|
}
|
|
@@ -49,7 +49,7 @@ export declare const ProfileSchema: z.ZodObject<{
|
|
|
49
49
|
postalCode: z.ZodString;
|
|
50
50
|
countryCode: z.ZodString;
|
|
51
51
|
}, z.core.$loose>>;
|
|
52
|
-
alternateShippingAddresses: z.ZodArray<z.ZodObject<{
|
|
52
|
+
alternateShippingAddresses: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
53
53
|
identifier: z.ZodDefault<z.ZodObject<{
|
|
54
54
|
nickName: z.ZodString;
|
|
55
55
|
}, z.core.$loose>>;
|
|
@@ -61,7 +61,7 @@ export declare const ProfileSchema: z.ZodObject<{
|
|
|
61
61
|
region: z.ZodString;
|
|
62
62
|
postalCode: z.ZodString;
|
|
63
63
|
countryCode: z.ZodString;
|
|
64
|
-
}, z.core.$loose
|
|
64
|
+
}, z.core.$loose>>>;
|
|
65
65
|
}, z.core.$loose>;
|
|
66
66
|
export type Address = InferType<typeof AddressSchema>;
|
|
67
67
|
export type Profile = InferType<typeof ProfileSchema>;
|
|
@@ -1,7 +1,85 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { InferType } from '../../zod-utils.js';
|
|
3
3
|
export declare const ProfileMutationUpdateSchema: z.ZodObject<{
|
|
4
|
+
identifier: z.ZodObject<{
|
|
5
|
+
userId: z.ZodString;
|
|
6
|
+
}, z.core.$loose>;
|
|
4
7
|
email: z.ZodEmail;
|
|
5
8
|
phone: z.ZodString;
|
|
6
9
|
}, z.core.$loose>;
|
|
10
|
+
export declare const ProfileMutationAddShippingAddressSchema: z.ZodObject<{
|
|
11
|
+
identifier: z.ZodObject<{
|
|
12
|
+
userId: z.ZodString;
|
|
13
|
+
}, z.core.$loose>;
|
|
14
|
+
address: z.ZodObject<{
|
|
15
|
+
identifier: z.ZodDefault<z.ZodObject<{
|
|
16
|
+
nickName: z.ZodString;
|
|
17
|
+
}, z.core.$loose>>;
|
|
18
|
+
firstName: z.ZodString;
|
|
19
|
+
lastName: z.ZodString;
|
|
20
|
+
streetAddress: z.ZodString;
|
|
21
|
+
streetNumber: z.ZodString;
|
|
22
|
+
city: z.ZodString;
|
|
23
|
+
region: z.ZodString;
|
|
24
|
+
postalCode: z.ZodString;
|
|
25
|
+
countryCode: z.ZodString;
|
|
26
|
+
}, z.core.$loose>;
|
|
27
|
+
}, z.core.$loose>;
|
|
28
|
+
export declare const ProfileMutationRemoveShippingAddressSchema: z.ZodObject<{
|
|
29
|
+
identifier: z.ZodObject<{
|
|
30
|
+
userId: z.ZodString;
|
|
31
|
+
}, z.core.$loose>;
|
|
32
|
+
addressIdentifier: z.ZodObject<{
|
|
33
|
+
nickName: z.ZodString;
|
|
34
|
+
}, z.core.$loose>;
|
|
35
|
+
}, z.core.$loose>;
|
|
36
|
+
export declare const ProfileMutationUpdateShippingAddressSchema: z.ZodObject<{
|
|
37
|
+
identifier: z.ZodObject<{
|
|
38
|
+
userId: z.ZodString;
|
|
39
|
+
}, z.core.$loose>;
|
|
40
|
+
address: z.ZodObject<{
|
|
41
|
+
identifier: z.ZodDefault<z.ZodObject<{
|
|
42
|
+
nickName: z.ZodString;
|
|
43
|
+
}, z.core.$loose>>;
|
|
44
|
+
firstName: z.ZodString;
|
|
45
|
+
lastName: z.ZodString;
|
|
46
|
+
streetAddress: z.ZodString;
|
|
47
|
+
streetNumber: z.ZodString;
|
|
48
|
+
city: z.ZodString;
|
|
49
|
+
region: z.ZodString;
|
|
50
|
+
postalCode: z.ZodString;
|
|
51
|
+
countryCode: z.ZodString;
|
|
52
|
+
}, z.core.$loose>;
|
|
53
|
+
}, z.core.$loose>;
|
|
54
|
+
export declare const ProfileMutationMakeShippingAddressDefaultSchema: z.ZodObject<{
|
|
55
|
+
identifier: z.ZodObject<{
|
|
56
|
+
userId: z.ZodString;
|
|
57
|
+
}, z.core.$loose>;
|
|
58
|
+
addressIdentifier: z.ZodObject<{
|
|
59
|
+
nickName: z.ZodString;
|
|
60
|
+
}, z.core.$loose>;
|
|
61
|
+
}, z.core.$loose>;
|
|
62
|
+
export declare const ProfileMutationSetBillingAddressSchema: z.ZodObject<{
|
|
63
|
+
identifier: z.ZodObject<{
|
|
64
|
+
userId: z.ZodString;
|
|
65
|
+
}, z.core.$loose>;
|
|
66
|
+
address: z.ZodObject<{
|
|
67
|
+
identifier: z.ZodDefault<z.ZodObject<{
|
|
68
|
+
nickName: z.ZodString;
|
|
69
|
+
}, z.core.$loose>>;
|
|
70
|
+
firstName: z.ZodString;
|
|
71
|
+
lastName: z.ZodString;
|
|
72
|
+
streetAddress: z.ZodString;
|
|
73
|
+
streetNumber: z.ZodString;
|
|
74
|
+
city: z.ZodString;
|
|
75
|
+
region: z.ZodString;
|
|
76
|
+
postalCode: z.ZodString;
|
|
77
|
+
countryCode: z.ZodString;
|
|
78
|
+
}, z.core.$loose>;
|
|
79
|
+
}, z.core.$loose>;
|
|
7
80
|
export type ProfileMutationUpdate = InferType<typeof ProfileMutationUpdateSchema>;
|
|
81
|
+
export type ProfileMutationAddShippingAddress = InferType<typeof ProfileMutationAddShippingAddressSchema>;
|
|
82
|
+
export type ProfileMutationRemoveShippingAddress = InferType<typeof ProfileMutationRemoveShippingAddressSchema>;
|
|
83
|
+
export type ProfileMutationMakeShippingAddressDefault = InferType<typeof ProfileMutationMakeShippingAddressDefaultSchema>;
|
|
84
|
+
export type ProfileMutationSetBillingAddress = InferType<typeof ProfileMutationSetBillingAddressSchema>;
|
|
85
|
+
export type ProfileMutationUpdateShippingAddress = InferType<typeof ProfileMutationUpdateShippingAddressSchema>;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { z } from 'zod';
|
|
2
2
|
import type { InferType } from '../../zod-utils.js';
|
|
3
|
-
export declare const
|
|
4
|
-
|
|
3
|
+
export declare const ProfileQueryByIdSchema: z.ZodObject<{
|
|
4
|
+
identifier: z.ZodObject<{
|
|
5
|
+
userId: z.ZodString;
|
|
6
|
+
}, z.core.$loose>;
|
|
7
|
+
}, z.core.$loose>;
|
|
8
|
+
export type ProfileQuerySelf = InferType<typeof ProfileQueryByIdSchema>;
|