@arcote.tech/arc-auth 0.4.9 → 0.4.11
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcote.tech/arc-auth",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.11",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Reusable authentication module for Arc framework — aggregate-based auth with factory pattern",
|
|
7
7
|
"main": "./src/index.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"type-check": "tsc --noEmit"
|
|
11
11
|
},
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"@arcote.tech/arc": "^0.4.
|
|
13
|
+
"@arcote.tech/arc": "^0.4.11",
|
|
14
14
|
"react": "^18.0.0 || ^19.0.0",
|
|
15
15
|
"typescript": "^5.0.0"
|
|
16
16
|
},
|
|
@@ -41,6 +41,8 @@ export const createAccountAggregate = <
|
|
|
41
41
|
const { accountId, token, customFields } = data;
|
|
42
42
|
const tokenFields = data.tokenFields ?? [];
|
|
43
43
|
|
|
44
|
+
const name = data.name as Data['name'];
|
|
45
|
+
|
|
44
46
|
/** Build JWT params from account — includes accountId + tokenFields */
|
|
45
47
|
const buildTokenParams = (account: any) => {
|
|
46
48
|
const params: any = { accountId: account._id };
|
|
@@ -51,7 +53,7 @@ export const createAccountAggregate = <
|
|
|
51
53
|
};
|
|
52
54
|
|
|
53
55
|
return (
|
|
54
|
-
aggregate(`${
|
|
56
|
+
aggregate(`${name}Accounts`, accountId, {
|
|
55
57
|
email: string().email(),
|
|
56
58
|
isEmailVerified: boolean(),
|
|
57
59
|
passwordHash: string().optional(),
|
|
@@ -63,7 +65,7 @@ export const createAccountAggregate = <
|
|
|
63
65
|
// --- Public Events ---
|
|
64
66
|
|
|
65
67
|
.publicEvent(
|
|
66
|
-
|
|
68
|
+
`${name}AccountRegistered`,
|
|
67
69
|
{
|
|
68
70
|
accountId,
|
|
69
71
|
email: string().email(),
|
|
@@ -90,7 +92,7 @@ export const createAccountAggregate = <
|
|
|
90
92
|
)
|
|
91
93
|
|
|
92
94
|
.publicEvent(
|
|
93
|
-
|
|
95
|
+
`${name}AccountRegisteredViaOAuth`,
|
|
94
96
|
{
|
|
95
97
|
accountId,
|
|
96
98
|
email: string().email(),
|
|
@@ -119,7 +121,7 @@ export const createAccountAggregate = <
|
|
|
119
121
|
)
|
|
120
122
|
|
|
121
123
|
.publicEvent(
|
|
122
|
-
|
|
124
|
+
`${name}SignedIn`,
|
|
123
125
|
{ accountId, email: string().email() },
|
|
124
126
|
async (ctx, event) => {
|
|
125
127
|
await ctx.modify(
|
|
@@ -131,7 +133,7 @@ export const createAccountAggregate = <
|
|
|
131
133
|
},
|
|
132
134
|
)
|
|
133
135
|
|
|
134
|
-
.publicEvent(
|
|
136
|
+
.publicEvent(`${name}EmailVerified`, { accountId }, async (ctx, event) => {
|
|
135
137
|
await ctx.modify(
|
|
136
138
|
event.payload.accountId as any,
|
|
137
139
|
{
|
|
@@ -143,7 +145,7 @@ export const createAccountAggregate = <
|
|
|
143
145
|
// --- Mutate Methods ---
|
|
144
146
|
|
|
145
147
|
/**
|
|
146
|
-
* register — server-only. Hashes password, emits
|
|
148
|
+
* register — server-only. Hashes password, emits `${name}AccountRegistered`.
|
|
147
149
|
*/
|
|
148
150
|
.mutateMethod(
|
|
149
151
|
"register",
|
|
@@ -165,7 +167,7 @@ export const createAccountAggregate = <
|
|
|
165
167
|
const pwHash = await hashPassword(params.password);
|
|
166
168
|
const { email, password: _pw, ...custom } = params;
|
|
167
169
|
|
|
168
|
-
await ctx.
|
|
170
|
+
await ctx[`${name}AccountRegistered`].emit({
|
|
169
171
|
accountId: id,
|
|
170
172
|
email,
|
|
171
173
|
passwordHash: pwHash,
|
|
@@ -212,7 +214,7 @@ export const createAccountAggregate = <
|
|
|
212
214
|
|
|
213
215
|
const jwtToken = token.generateJWT(buildTokenParams(account));
|
|
214
216
|
|
|
215
|
-
await ctx.
|
|
217
|
+
await ctx[`${name}SignedIn`].emit({
|
|
216
218
|
accountId: account._id,
|
|
217
219
|
email: params.email,
|
|
218
220
|
});
|
|
@@ -255,7 +257,7 @@ export const createAccountAggregate = <
|
|
|
255
257
|
const id = accountId.generate();
|
|
256
258
|
const { email, provider, providerUserId, ...custom } = params;
|
|
257
259
|
|
|
258
|
-
await ctx.
|
|
260
|
+
await ctx[`${name}AccountRegisteredViaOAuth`].emit({
|
|
259
261
|
accountId: id,
|
|
260
262
|
email,
|
|
261
263
|
provider,
|
|
@@ -296,7 +298,7 @@ export const createAccountAggregate = <
|
|
|
296
298
|
|
|
297
299
|
const jwtToken = token.generateJWT(buildTokenParams(account));
|
|
298
300
|
|
|
299
|
-
await ctx.
|
|
301
|
+
await ctx[`${name}SignedIn`].emit({
|
|
300
302
|
accountId: account._id,
|
|
301
303
|
email: params.email,
|
|
302
304
|
});
|
|
@@ -14,8 +14,9 @@ export const createOAuthIdentityAggregate = <
|
|
|
14
14
|
data: Data,
|
|
15
15
|
) => {
|
|
16
16
|
const { oauthIdentityId, accountId } = data;
|
|
17
|
+
const name = data.name as Data['name'];
|
|
17
18
|
|
|
18
|
-
return aggregate(`${
|
|
19
|
+
return aggregate(`${name}OAuthIdentities`, oauthIdentityId, {
|
|
19
20
|
accountId,
|
|
20
21
|
provider: string(),
|
|
21
22
|
providerUserId: string(),
|
|
@@ -24,7 +25,7 @@ export const createOAuthIdentityAggregate = <
|
|
|
24
25
|
lastUsedAt: date().optional(),
|
|
25
26
|
})
|
|
26
27
|
.publicEvent(
|
|
27
|
-
|
|
28
|
+
`${name}OauthIdentityLinked`,
|
|
28
29
|
{
|
|
29
30
|
oauthIdentityId,
|
|
30
31
|
accountId,
|
|
@@ -52,7 +53,7 @@ export const createOAuthIdentityAggregate = <
|
|
|
52
53
|
)
|
|
53
54
|
|
|
54
55
|
.publicEvent(
|
|
55
|
-
|
|
56
|
+
`${name}OauthIdentityUsed`,
|
|
56
57
|
{ oauthIdentityId },
|
|
57
58
|
async (ctx, event) => {
|
|
58
59
|
await ctx.modify(event.payload.oauthIdentityId as any, {
|
|
@@ -62,7 +63,7 @@ export const createOAuthIdentityAggregate = <
|
|
|
62
63
|
)
|
|
63
64
|
|
|
64
65
|
.publicEvent(
|
|
65
|
-
|
|
66
|
+
`${name}OauthIdentityUnlinked`,
|
|
66
67
|
{ oauthIdentityId },
|
|
67
68
|
async (ctx, event) => {
|
|
68
69
|
await ctx.remove(event.payload.oauthIdentityId as any);
|
|
@@ -81,7 +82,6 @@ export const createOAuthIdentityAggregate = <
|
|
|
81
82
|
},
|
|
82
83
|
ONLY_SERVER &&
|
|
83
84
|
(async (ctx: any, params: any) => {
|
|
84
|
-
// Check for duplicate (same provider + providerUserId)
|
|
85
85
|
const existing = await ctx.$query.findOne({
|
|
86
86
|
provider: params.provider,
|
|
87
87
|
providerUserId: params.providerUserId,
|
|
@@ -92,7 +92,7 @@ export const createOAuthIdentityAggregate = <
|
|
|
92
92
|
|
|
93
93
|
const id = oauthIdentityId.generate();
|
|
94
94
|
|
|
95
|
-
await ctx.
|
|
95
|
+
await ctx[`${name}OauthIdentityLinked`].emit({
|
|
96
96
|
oauthIdentityId: id,
|
|
97
97
|
accountId: params.accountId,
|
|
98
98
|
provider: params.provider,
|
|
@@ -109,7 +109,7 @@ export const createOAuthIdentityAggregate = <
|
|
|
109
109
|
{ params: { oauthIdentityId } },
|
|
110
110
|
ONLY_SERVER &&
|
|
111
111
|
(async (ctx: any, params: any) => {
|
|
112
|
-
await ctx.
|
|
112
|
+
await ctx[`${name}OauthIdentityUsed`].emit({
|
|
113
113
|
oauthIdentityId: params.oauthIdentityId,
|
|
114
114
|
});
|
|
115
115
|
}),
|