@temboplus/afloat 0.1.31 → 0.1.33
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/esm/mod.d.ts +1 -0
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +1 -0
- package/esm/src/features/admin/contract.d.ts +648 -0
- package/esm/src/features/admin/contract.d.ts.map +1 -0
- package/esm/src/features/admin/contract.js +184 -0
- package/esm/src/features/admin/index.d.ts +4 -0
- package/esm/src/features/admin/index.d.ts.map +1 -0
- package/esm/src/features/admin/index.js +3 -0
- package/esm/src/features/admin/repository.d.ts +104 -0
- package/esm/src/features/admin/repository.d.ts.map +1 -0
- package/esm/src/features/admin/repository.js +224 -0
- package/esm/src/features/admin/schemas.d.ts +119 -0
- package/esm/src/features/admin/schemas.d.ts.map +1 -0
- package/esm/src/features/admin/schemas.js +172 -0
- package/esm/src/models/index.d.ts +1 -0
- package/esm/src/models/index.d.ts.map +1 -1
- package/esm/src/models/index.js +1 -0
- package/esm/src/models/permission.d.ts +11 -1
- package/esm/src/models/permission.d.ts.map +1 -1
- package/esm/src/models/permission.js +10 -0
- package/esm/src/models/role.d.ts +21 -0
- package/esm/src/models/role.d.ts.map +1 -0
- package/esm/src/models/role.js +73 -0
- package/esm/src/models/user/{user.d.ts → authenticated-user.d.ts} +1 -1
- package/esm/src/models/user/authenticated-user.d.ts.map +1 -0
- package/esm/src/models/user/index.d.ts +2 -1
- package/esm/src/models/user/index.d.ts.map +1 -1
- package/esm/src/models/user/index.js +2 -1
- package/esm/src/models/user/managed-user.d.ts +102 -0
- package/esm/src/models/user/managed-user.d.ts.map +1 -0
- package/esm/src/models/user/managed-user.js +226 -0
- package/package.json +2 -2
- package/script/mod.d.ts +1 -0
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +1 -0
- package/script/src/features/admin/contract.d.ts +648 -0
- package/script/src/features/admin/contract.d.ts.map +1 -0
- package/script/src/features/admin/contract.js +187 -0
- package/script/src/features/admin/index.d.ts +4 -0
- package/script/src/features/admin/index.d.ts.map +1 -0
- package/script/src/features/admin/index.js +19 -0
- package/script/src/features/admin/repository.d.ts +104 -0
- package/script/src/features/admin/repository.d.ts.map +1 -0
- package/script/src/features/admin/repository.js +228 -0
- package/script/src/features/admin/schemas.d.ts +119 -0
- package/script/src/features/admin/schemas.d.ts.map +1 -0
- package/script/src/features/admin/schemas.js +175 -0
- package/script/src/models/index.d.ts +1 -0
- package/script/src/models/index.d.ts.map +1 -1
- package/script/src/models/index.js +1 -0
- package/script/src/models/permission.d.ts +11 -1
- package/script/src/models/permission.d.ts.map +1 -1
- package/script/src/models/permission.js +10 -0
- package/script/src/models/role.d.ts +21 -0
- package/script/src/models/role.d.ts.map +1 -0
- package/script/src/models/role.js +77 -0
- package/script/src/models/user/{user.d.ts → authenticated-user.d.ts} +1 -1
- package/script/src/models/user/authenticated-user.d.ts.map +1 -0
- package/script/src/models/user/index.d.ts +2 -1
- package/script/src/models/user/index.d.ts.map +1 -1
- package/script/src/models/user/index.js +2 -1
- package/script/src/models/user/managed-user.d.ts +102 -0
- package/script/src/models/user/managed-user.d.ts.map +1 -0
- package/script/src/models/user/managed-user.js +231 -0
- package/esm/src/models/user/user.d.ts.map +0 -1
- package/script/src/models/user/user.d.ts.map +0 -1
- /package/esm/src/models/user/{user.js → authenticated-user.js} +0 -0
- /package/script/src/models/user/{user.js → authenticated-user.js} +0 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// deno-lint-ignore-file no-explicit-any
|
|
2
|
+
// ====================== Base User Entity ====================== //
|
|
3
|
+
import { Role } from "../role.js";
|
|
4
|
+
/**
|
|
5
|
+
* Base user entity - represents a user in the system
|
|
6
|
+
*/
|
|
7
|
+
export class UserEntity {
|
|
8
|
+
constructor(data) {
|
|
9
|
+
Object.defineProperty(this, "id", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: void 0
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(this, "name", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: void 0
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(this, "identity", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: void 0
|
|
26
|
+
}); // email or phone
|
|
27
|
+
Object.defineProperty(this, "profileId", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: void 0
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(this, "permissions", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: void 0
|
|
38
|
+
});
|
|
39
|
+
this.id = data.id;
|
|
40
|
+
this.name = data.name;
|
|
41
|
+
this.identity = data.identity;
|
|
42
|
+
this.profileId = data.profileId;
|
|
43
|
+
this.permissions = new Set(data.permissions);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if user has a specific permission
|
|
47
|
+
*/
|
|
48
|
+
can(permission) {
|
|
49
|
+
return this.permissions.has(permission);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Check if user has any of the specified permissions
|
|
53
|
+
*/
|
|
54
|
+
canAny(permissions) {
|
|
55
|
+
return permissions.some(p => this.permissions.has(p));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Check if user has all of the specified permissions
|
|
59
|
+
*/
|
|
60
|
+
canAll(permissions) {
|
|
61
|
+
return permissions.every(p => this.permissions.has(p));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Represents a user from the admin management perspective.
|
|
66
|
+
* Same person as AuthenticatedUser but with management metadata and capabilities.
|
|
67
|
+
*/
|
|
68
|
+
export class ManagedUser extends UserEntity {
|
|
69
|
+
constructor(data) {
|
|
70
|
+
super({
|
|
71
|
+
id: data.id,
|
|
72
|
+
name: data.name,
|
|
73
|
+
identity: data.identity,
|
|
74
|
+
profileId: data.profileId,
|
|
75
|
+
permissions: data.role.access,
|
|
76
|
+
});
|
|
77
|
+
Object.defineProperty(this, "type", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
configurable: true,
|
|
80
|
+
writable: true,
|
|
81
|
+
value: void 0
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(this, "roleId", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
configurable: true,
|
|
86
|
+
writable: true,
|
|
87
|
+
value: void 0
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(this, "resetPassword", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
configurable: true,
|
|
92
|
+
writable: true,
|
|
93
|
+
value: void 0
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(this, "isActive", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
configurable: true,
|
|
98
|
+
writable: true,
|
|
99
|
+
value: void 0
|
|
100
|
+
});
|
|
101
|
+
Object.defineProperty(this, "role", {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
configurable: true,
|
|
104
|
+
writable: true,
|
|
105
|
+
value: void 0
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(this, "createdAt", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
configurable: true,
|
|
110
|
+
writable: true,
|
|
111
|
+
value: void 0
|
|
112
|
+
});
|
|
113
|
+
Object.defineProperty(this, "updatedAt", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
configurable: true,
|
|
116
|
+
writable: true,
|
|
117
|
+
value: void 0
|
|
118
|
+
});
|
|
119
|
+
this.type = data.type;
|
|
120
|
+
this.roleId = data.roleId;
|
|
121
|
+
this.resetPassword = data.resetPassword;
|
|
122
|
+
this.isActive = data.isActive;
|
|
123
|
+
this.role = new Role(data.role);
|
|
124
|
+
this.createdAt = new Date(data.createdAt);
|
|
125
|
+
this.updatedAt = new Date(data.updatedAt);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Check if user account is active
|
|
129
|
+
*/
|
|
130
|
+
isAccountActive() {
|
|
131
|
+
return this.isActive;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Check if user needs to reset password
|
|
135
|
+
*/
|
|
136
|
+
needsPasswordReset() {
|
|
137
|
+
return this.resetPassword;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get comprehensive account status
|
|
141
|
+
*/
|
|
142
|
+
getAccountStatus() {
|
|
143
|
+
if (!this.isActive) {
|
|
144
|
+
return {
|
|
145
|
+
status: 'inactive',
|
|
146
|
+
label: 'Inactive',
|
|
147
|
+
color: 'error',
|
|
148
|
+
description: 'Account has been deactivated by an administrator'
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
if (this.resetPassword) {
|
|
152
|
+
return {
|
|
153
|
+
status: 'password_reset_required',
|
|
154
|
+
label: 'Password Reset Required',
|
|
155
|
+
color: 'warning',
|
|
156
|
+
description: 'User must reset their password on next login'
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
status: 'active',
|
|
161
|
+
label: 'Active',
|
|
162
|
+
color: 'success',
|
|
163
|
+
description: 'Account is active and ready to use'
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Get role display name
|
|
168
|
+
*/
|
|
169
|
+
getRoleName() {
|
|
170
|
+
return this.role.name;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Get formatted creation date
|
|
174
|
+
*/
|
|
175
|
+
getCreatedDate() {
|
|
176
|
+
return this.createdAt.toLocaleDateString();
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Get time since last update
|
|
180
|
+
*/
|
|
181
|
+
getLastUpdateInfo() {
|
|
182
|
+
const now = new Date();
|
|
183
|
+
const diffMs = now.getTime() - this.updatedAt.getTime();
|
|
184
|
+
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
|
|
185
|
+
if (diffDays === 0)
|
|
186
|
+
return 'Today';
|
|
187
|
+
if (diffDays === 1)
|
|
188
|
+
return 'Yesterday';
|
|
189
|
+
if (diffDays < 7)
|
|
190
|
+
return `${diffDays} days ago`;
|
|
191
|
+
if (diffDays < 30)
|
|
192
|
+
return `${Math.floor(diffDays / 7)} weeks ago`;
|
|
193
|
+
return this.updatedAt.toLocaleDateString();
|
|
194
|
+
}
|
|
195
|
+
static from(data) {
|
|
196
|
+
try {
|
|
197
|
+
if (!data?.id || !data?.name || !data?.identity || !data?.role) {
|
|
198
|
+
console.error("Missing required ManagedUser fields:", data);
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
return new ManagedUser(data);
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
console.error("Error creating ManagedUser:", error);
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
static createMany(dataArray) {
|
|
209
|
+
return dataArray.map(data => ManagedUser.from(data)).filter(Boolean);
|
|
210
|
+
}
|
|
211
|
+
toJSON() {
|
|
212
|
+
return {
|
|
213
|
+
id: this.id,
|
|
214
|
+
name: this.name,
|
|
215
|
+
identity: this.identity,
|
|
216
|
+
type: this.type,
|
|
217
|
+
profileId: this.profileId,
|
|
218
|
+
roleId: this.roleId,
|
|
219
|
+
resetPassword: this.resetPassword,
|
|
220
|
+
isActive: this.isActive,
|
|
221
|
+
role: this.role.toJSON(),
|
|
222
|
+
createdAt: this.createdAt.toISOString(),
|
|
223
|
+
updatedAt: this.updatedAt.toISOString(),
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temboplus/afloat",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.33",
|
|
4
4
|
"description": "A JavaScript/TypeScript package providing common utilities and logic shared across all Temboplus-Afloat Projects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"private": false,
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@temboplus/frontend-core": "^0.2.
|
|
26
|
+
"@temboplus/frontend-core": "^0.2.9",
|
|
27
27
|
"@ts-rest/core": "^3.52.1",
|
|
28
28
|
"antd": "^5.24.5",
|
|
29
29
|
"uuid": "^11.1.0",
|
package/script/mod.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./src/features/auth/index.js";
|
|
|
2
2
|
export * from "./src/features/contact/index.js";
|
|
3
3
|
export * from "./src/features/wallet/index.js";
|
|
4
4
|
export * from "./src/features/payout/index.js";
|
|
5
|
+
export * from "./src/features/admin/index.js";
|
|
5
6
|
export * from "./src/errors/index.js";
|
|
6
7
|
export * from "./src/models/index.js";
|
|
7
8
|
//# sourceMappingURL=mod.d.ts.map
|
package/script/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAE9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}
|
package/script/mod.js
CHANGED
|
@@ -18,5 +18,6 @@ __exportStar(require("./src/features/auth/index.js"), exports);
|
|
|
18
18
|
__exportStar(require("./src/features/contact/index.js"), exports);
|
|
19
19
|
__exportStar(require("./src/features/wallet/index.js"), exports);
|
|
20
20
|
__exportStar(require("./src/features/payout/index.js"), exports);
|
|
21
|
+
__exportStar(require("./src/features/admin/index.js"), exports);
|
|
21
22
|
__exportStar(require("./src/errors/index.js"), exports);
|
|
22
23
|
__exportStar(require("./src/models/index.js"), exports);
|