@eeplatform/core 1.8.7 → 1.8.9

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.
@@ -15,26 +15,24 @@ jobs:
15
15
  publish:
16
16
  if: ${{ github.event.workflow_run.conclusion == 'success' }}
17
17
  runs-on: ubuntu-latest
18
- environment: production
19
18
  steps:
20
19
  - uses: actions/checkout@v4
20
+ with:
21
+ fetch-depth: 0
21
22
 
22
23
  - uses: actions/setup-node@v4
23
24
  with:
24
25
  node-version: 20.x
25
- cache: "yarn" # Use yarn for caching
26
- cache-dependency-path: yarn.lock # Cache Yarn lockfile
27
-
28
- - run: yarn install --immutable # Install dependencies with immutable lockfile
26
+ cache: "yarn"
27
+ cache-dependency-path: yarn.lock
29
28
 
30
- - name: Create .npmrc for publishing
31
- run: |
32
- echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}' > ~/.npmrc
29
+ - run: yarn install --immutable
33
30
 
34
31
  - name: Create Release Pull Request or Publish
35
32
  id: changesets
36
33
  uses: changesets/action@v1
37
34
  with:
38
- publish: yarn release # Use yarn for publishing
35
+ publish: yarn release
39
36
  env:
40
37
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @eeplatform/core
2
2
 
3
+ ## 1.8.9
4
+
5
+ ### Patch Changes
6
+
7
+ - a899c41: Add app management and revise roles and permission management
8
+
9
+ ## 1.8.8
10
+
11
+ ### Patch Changes
12
+
13
+ - 6a72a1c: Update dependencies
14
+
3
15
  ## 1.8.7
4
16
 
5
17
  ### Patch Changes
package/CLAUDE.md ADDED
@@ -0,0 +1,106 @@
1
+ # server-core-module (`@goweekdays/core`)
2
+
3
+ Shared server module exported as a package consumed by all app servers.
4
+ Built with Express + MongoDB (Atlas) + TypeScript.
5
+
6
+ ## Resource Layer Pattern
7
+
8
+ Each resource lives under `src/resources/<resource-name>/` and follows this structure:
9
+
10
+ ```
11
+ resource-name/
12
+ resource.model.ts # Types and validation schema
13
+ resource.repository.ts # Direct database interaction
14
+ resource.service.ts # Business logic (optional — see below)
15
+ resource.controller.ts # API request handler
16
+ index.ts # Barrel export
17
+ ```
18
+
19
+ ### `.model.ts`
20
+
21
+ Defines the TypeScript type and Joi validation schema for the resource. This is the source of truth for the shape of the data.
22
+
23
+ ### `.repository.ts`
24
+
25
+ Contains all functions that directly interact with the database (MongoDB). No business logic here — only reads and writes.
26
+
27
+ ### `.service.ts`
28
+
29
+ Builds business logic by composing repository functions and third-party integrations (e.g. hashing, email, S3, transactions). Never accesses the database directly — all DB interaction goes through the repository. **This layer is optional** — if a resource only needs basic CRUD with no business logic, a service file is not required.
30
+
31
+ ### `.controller.ts`
32
+
33
+ Handles incoming API requests. Validates the request input, then delegates to the service layer if business logic exists, or calls the repository directly if the resource has no service.
34
+
35
+ ### `index.ts`
36
+
37
+ Re-exports all layers so consumers can import from the resource folder directly.
38
+
39
+ ```typescript
40
+ export * from "./user.model";
41
+ export * from "./user.repository";
42
+ export * from "./user.service";
43
+ export * from "./user.controller";
44
+ ```
45
+
46
+ ---
47
+
48
+ ## Naming Conventions
49
+
50
+ | Layer | Pattern | Example |
51
+ | ---------- | --------------------------- | ---------------------------------------------------- |
52
+ | File | `<resource>.<layer>.ts` | `user.model.ts`, `finance.journal.config.service.ts` |
53
+ | Type | `T<Resource>` | `TUser`, `TJobPost` |
54
+ | Schema | `schema<Resource>` | `schemaUser`, `schemaJobPost` |
55
+ | Model fn | `model<Resource>()` | `modelUser()`, `modelJobPost()` |
56
+ | Repository | `use<Resource>Repo()` | `useUserRepo()`, `useOrgRepo()` |
57
+ | Service | `use<Resource>Service()` | `useUserService()`, `useOrgService()` |
58
+ | Controller | `use<Resource>Controller()` | `useUserController()` |
59
+
60
+ Multi-word resource names use dot notation in file names: `finance.journal.config.model.ts`, `job.post.repository.ts`.
61
+
62
+ ---
63
+
64
+ ## Error Handling
65
+
66
+ Always use the typed error classes from `@eeplatform/nodejs-utils` — never throw a generic `new Error()`.
67
+
68
+ - `BadRequestError` — invalid input or a violated business rule
69
+ - `NotFoundError` — resource does not exist
70
+ - `InternalServerError` — unexpected DB or system failure
71
+ - `AppError` — base class; use `instanceof AppError` in catch blocks to re-throw typed errors as-is
72
+
73
+ ---
74
+
75
+ ## Controller Input Extraction
76
+
77
+ Validate the entire `req.body` against a Joi schema to ensure no unexpected keys are passed. Extract only the fields you need after validation.
78
+
79
+ 1. Define a Joi schema that describes exactly the expected shape
80
+ 2. Validate `req.body` (or `req.params` / `req.query`) against it — reject if invalid
81
+ 3. Destructure only the needed fields from the validated result
82
+ 4. Delegate to the service or repository
83
+
84
+ This prevents unexpected or extra fields from leaking into the database.
85
+
86
+ ---
87
+
88
+ ## Transactions
89
+
90
+ Use a MongoDB session whenever a service function writes to more than one collection. The pattern is always:
91
+
92
+ 1. Start session and transaction
93
+ 2. Pass `session` down to every repo call
94
+ 3. Commit on success, abort on error, and always end the session in `finally`
95
+
96
+ Transactions belong in the service layer only — never in a controller or repository.
97
+
98
+ ---
99
+
100
+ ## What Not To Do
101
+
102
+ - **No business logic in controllers** — controllers only handle HTTP input/output and delegate
103
+ - **No direct DB access in controllers or services** — all DB interaction belongs in the repository only
104
+ - **No generic `Error` throws** — use the typed error classes above
105
+ - **No Zod** — validation is done with Joi throughout this module
106
+ - **No extra fields into the DB** — always validate the full request body before using any of it
package/dist/index.d.ts CHANGED
@@ -88,8 +88,7 @@ declare class MUser implements TUser {
88
88
  }
89
89
 
90
90
  declare function useUserRepo(): {
91
- createTextIndex: () => Promise<void>;
92
- createUniqueIndex: () => Promise<void>;
91
+ createIndexes: () => Promise<void>;
93
92
  createUser: (value: TUser, session?: ClientSession) => Promise<ObjectId>;
94
93
  getUserByEmail: (email: string) => Promise<TUser | null>;
95
94
  getUserById: (_id: string | ObjectId) => Promise<TUser | null>;
@@ -246,6 +245,199 @@ declare function useOrgController(): {
246
245
  getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
247
246
  };
248
247
 
248
+ type TApp = {
249
+ _id?: ObjectId;
250
+ code: string;
251
+ name: string;
252
+ description: string;
253
+ type?: string;
254
+ status?: string;
255
+ createdAt?: string | Date;
256
+ updatedAt?: string | Date;
257
+ deletedAt?: string | Date;
258
+ };
259
+ declare const schemaApp: Joi.ObjectSchema<any>;
260
+ declare const schemaAppUpdate: Joi.ObjectSchema<any>;
261
+ declare function modelApp(value: TApp): TApp;
262
+
263
+ declare function useAppRepo(): {
264
+ createIndexes: () => Promise<void>;
265
+ add: (value: TApp, session?: ClientSession) => Promise<ObjectId>;
266
+ getAll: ({ search, page, limit, sort, status, type, }?: {
267
+ search?: string;
268
+ page?: number;
269
+ limit?: number;
270
+ sort?: Record<string, any>;
271
+ status?: string;
272
+ type?: string | string[];
273
+ }) => Promise<Record<string, any> | {
274
+ items: any[];
275
+ pages: number;
276
+ pageRange: string;
277
+ }>;
278
+ getById: (_id: string | ObjectId) => Promise<TApp | null>;
279
+ getByCode: (code: string) => Promise<TApp | null>;
280
+ updateById: (_id: ObjectId | string, value: {
281
+ name: string;
282
+ description: string;
283
+ }, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
284
+ deleteById: (_id: string | ObjectId, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
285
+ };
286
+
287
+ declare function useAppService(): {
288
+ addDefaultApps: () => Promise<void>;
289
+ deleteById: (id: string) => Promise<string>;
290
+ };
291
+
292
+ declare function useAppController(): {
293
+ add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
294
+ updateById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
295
+ getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
296
+ getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
297
+ deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
298
+ };
299
+
300
+ type TPermission = {
301
+ _id?: ObjectId;
302
+ app: string;
303
+ key: string;
304
+ name: string;
305
+ group: string;
306
+ description: string;
307
+ deprecated?: boolean;
308
+ status?: string;
309
+ createdAt?: string | Date;
310
+ updatedAt?: string | Date;
311
+ deletedAt?: string | Date;
312
+ };
313
+ declare const schemaPermission: Joi.ObjectSchema<any>;
314
+ declare const schemaPermissionUpdate: Joi.ObjectSchema<any>;
315
+ declare function modelPermission(value: TPermission): TPermission;
316
+
317
+ declare function usePermissionRepo(): {
318
+ createIndexes: () => Promise<void>;
319
+ add: (value: TPermission, session?: ClientSession) => Promise<ObjectId>;
320
+ getAll: ({ search, page, limit, sort, app, status, }?: {
321
+ search?: string | undefined;
322
+ page?: number | undefined;
323
+ limit?: number | undefined;
324
+ sort?: {} | undefined;
325
+ app?: string | undefined;
326
+ status?: string | undefined;
327
+ }) => Promise<Record<string, any> | {
328
+ items: any[];
329
+ pages: number;
330
+ pageRange: string;
331
+ }>;
332
+ getById: (_id: string | ObjectId) => Promise<TPermission | null>;
333
+ getByKey: (key: string, group?: string, app?: string) => Promise<TPermission | null>;
334
+ updateById: (_id: ObjectId | string, value: {
335
+ key?: string;
336
+ group?: string;
337
+ description?: string;
338
+ }, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
339
+ deleteById: (_id: string | ObjectId, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
340
+ countByGroup: (group: string) => Promise<number>;
341
+ };
342
+
343
+ declare function usePermissionService(): {
344
+ deleteById: (id: string) => Promise<string>;
345
+ };
346
+
347
+ declare function usePermissionController(): {
348
+ add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
349
+ getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
350
+ getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
351
+ deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
352
+ updateById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
353
+ };
354
+
355
+ type TPermissionGroup = {
356
+ _id?: ObjectId;
357
+ app: string;
358
+ key: string;
359
+ label: string;
360
+ order?: number;
361
+ status?: string;
362
+ createdAt?: string | Date;
363
+ updatedAt?: string | Date;
364
+ deletedAt?: string | Date;
365
+ };
366
+ declare const schemaPermissionGroup: Joi.ObjectSchema<any>;
367
+ declare const schemaPermissionGroupUpdate: Joi.ObjectSchema<any>;
368
+ declare function modelPermissionGroup(value: TPermissionGroup): TPermissionGroup;
369
+
370
+ declare function usePermissionGroupRepo(): {
371
+ createIndexes: () => Promise<void>;
372
+ add: (value: TPermissionGroup, session?: ClientSession) => Promise<ObjectId>;
373
+ getAll: ({ search, page, limit, sort, app, status, }?: {
374
+ search?: string | undefined;
375
+ page?: number | undefined;
376
+ limit?: number | undefined;
377
+ sort?: {} | undefined;
378
+ app?: string | undefined;
379
+ status?: string | undefined;
380
+ }) => Promise<Record<string, any> | {
381
+ items: any[];
382
+ pages: number;
383
+ pageRange: string;
384
+ }>;
385
+ getById: (_id: string | ObjectId) => Promise<TPermissionGroup | null>;
386
+ getByKey: (key: string, app?: string) => Promise<TPermissionGroup | null>;
387
+ updateById: (_id: ObjectId | string, value: {
388
+ name: string;
389
+ serial: string;
390
+ levels: number;
391
+ }, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
392
+ deleteById: (_id: string | ObjectId, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
393
+ };
394
+
395
+ declare function usePermissionGroupService(): {
396
+ addDefaultModule: () => Promise<void>;
397
+ deleteById: (id: string) => Promise<string>;
398
+ };
399
+
400
+ declare function usePermissionGroupController(): {
401
+ add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
402
+ getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
403
+ getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
404
+ deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
405
+ updateById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
406
+ };
407
+
408
+ type TFile = {
409
+ _id?: ObjectId;
410
+ name: string;
411
+ type?: string;
412
+ status?: string;
413
+ createdAt: string;
414
+ };
415
+ declare class MFile implements TFile {
416
+ _id?: ObjectId;
417
+ name: string;
418
+ type?: string;
419
+ status?: string;
420
+ createdAt: string;
421
+ constructor(value: TFile);
422
+ }
423
+
424
+ declare function useFileRepo(): {
425
+ createFile: (value: TFile, session?: ClientSession) => Promise<string>;
426
+ deleteFileById: (_id: string | ObjectId, session?: ClientSession) => Promise<string>;
427
+ getAllDraftedFiles: () => Promise<any[]>;
428
+ };
429
+
430
+ declare function useFileService(): {
431
+ createFile: (value: Express.Multer.File) => Promise<string>;
432
+ deleteFile: (id: string) => Promise<string>;
433
+ deleteDraft: () => void;
434
+ };
435
+
436
+ declare function useFileController(): {
437
+ upload: (req: Request, res: Response, next: NextFunction) => Promise<void>;
438
+ deleteFile: (req: Request, res: Response, next: NextFunction) => Promise<void>;
439
+ };
440
+
249
441
  type TRole = {
250
442
  _id?: ObjectId;
251
443
  id?: string | ObjectId;
@@ -278,8 +470,7 @@ declare class MRole implements TRole {
278
470
  }
279
471
 
280
472
  declare function useRoleRepo(): {
281
- createIndex: () => Promise<void>;
282
- createTextIndex: () => Promise<void>;
473
+ createIndexes: () => Promise<void>;
283
474
  createUniqueIndex: () => Promise<void>;
284
475
  addRole: (value: TRole, session?: ClientSession, clearCache?: boolean) => Promise<ObjectId>;
285
476
  getRoles: ({ search, page, limit, sort, type, id, }?: {
@@ -313,39 +504,6 @@ declare function useRoleController(): {
313
504
  updatePermissionsById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
314
505
  };
315
506
 
316
- type TFile = {
317
- _id?: ObjectId;
318
- name: string;
319
- type?: string;
320
- status?: string;
321
- createdAt: string;
322
- };
323
- declare class MFile implements TFile {
324
- _id?: ObjectId;
325
- name: string;
326
- type?: string;
327
- status?: string;
328
- createdAt: string;
329
- constructor(value: TFile);
330
- }
331
-
332
- declare function useFileRepo(): {
333
- createFile: (value: TFile, session?: ClientSession) => Promise<string>;
334
- deleteFileById: (_id: string | ObjectId, session?: ClientSession) => Promise<string>;
335
- getAllDraftedFiles: () => Promise<any[]>;
336
- };
337
-
338
- declare function useFileService(): {
339
- createFile: (value: Express.Multer.File) => Promise<string>;
340
- deleteFile: (id: string) => Promise<string>;
341
- deleteDraft: () => void;
342
- };
343
-
344
- declare function useFileController(): {
345
- upload: (req: Request, res: Response, next: NextFunction) => Promise<void>;
346
- deleteFile: (req: Request, res: Response, next: NextFunction) => Promise<void>;
347
- };
348
-
349
507
  type TVerificationMetadata = {
350
508
  name?: string;
351
509
  app?: string;
@@ -488,9 +646,7 @@ type TMember = {
488
646
  declare function MMember(value: TMember): TMember;
489
647
 
490
648
  declare function useMemberRepo(): {
491
- createIndex: () => Promise<void>;
492
- createUniqueIndex: () => Promise<void>;
493
- createTextIndex: () => Promise<void>;
649
+ createIndexes: () => Promise<void>;
494
650
  add: (value: TMember, session?: ClientSession) => Promise<string>;
495
651
  getById: (_id: string | ObjectId) => Promise<TMember | null>;
496
652
  getByOrg: (org: string | ObjectId) => Promise<TMember | null>;
@@ -523,7 +679,7 @@ declare function useMemberRepo(): {
523
679
  name: string;
524
680
  }[]>;
525
681
  updateStatusByUserId: (user: string | ObjectId, status: string) => Promise<string>;
526
- updateName: (value: Pick<TMember, "user" | "name">, session?: ClientSession) => Promise<string>;
682
+ updateName: (value: Pick<TMember, "name" | "user">, session?: ClientSession) => Promise<string>;
527
683
  getByUserId: (user: string | ObjectId) => Promise<TMember | null>;
528
684
  getOrgsByMembership: ({ search, limit, page, user }?: {
529
685
  search: string;
@@ -813,4 +969,4 @@ declare const GEMINI_API_KEY: string;
813
969
  declare const ASSEMBLY_AI_API_KEY: string;
814
970
  declare const DOMAIN: string;
815
971
 
816
- export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, ASSEMBLY_AI_API_KEY, AudioFileData, AudioTranscriptionOptions, AudioTranscriptionResult, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, DOMAIN, GEMINI_API_KEY, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MAddress, MFile, MMember, MONGO_DB, MONGO_URI, MOrg, MRole, MToken, MUser, MUserRole, MVerification, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PORT, PhonemeMatchOptions, PhonemeMatchResult, REDIS_HOST, REDIS_PASSWORD, REDIS_PORT, REFRESH_TOKEN_EXPIRY, REFRESH_TOKEN_SECRET, SECRET_KEY, SPACES_ACCESS_KEY, SPACES_BUCKET, SPACES_ENDPOINT, SPACES_REGION, SPACES_SECRET_KEY, TAddress, TCounter, TFile, TMember, TMiniRole, TOrg, TPSGC, TRole, TToken, TUser, TUserRole, TVerification, TVerificationMetadata, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, addressSchema, isDev, modelPSGC, schemaOrg, schemaPSGC, transactionSchema, useAddressController, useAddressRepo, useAudioTranscriptionController, useAuthController, useAuthService, useCounterModel, useCounterRepo, useFileController, useFileRepo, useFileService, useGeminiAiService, useGitHubService, useMemberController, useMemberRepo, useOrgController, useOrgRepo, useOrgService, usePSGCController, usePSGCRepo, useRoleController, useRoleRepo, useTokenRepo, useTranscribeService, useUserController, useUserRepo, useUserService, useUtilController, useVerificationController, useVerificationRepo, useVerificationService };
972
+ export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, ASSEMBLY_AI_API_KEY, AudioFileData, AudioTranscriptionOptions, AudioTranscriptionResult, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, DOMAIN, GEMINI_API_KEY, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MAddress, MFile, MMember, MONGO_DB, MONGO_URI, MOrg, MRole, MToken, MUser, MUserRole, MVerification, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PORT, PhonemeMatchOptions, PhonemeMatchResult, REDIS_HOST, REDIS_PASSWORD, REDIS_PORT, REFRESH_TOKEN_EXPIRY, REFRESH_TOKEN_SECRET, SECRET_KEY, SPACES_ACCESS_KEY, SPACES_BUCKET, SPACES_ENDPOINT, SPACES_REGION, SPACES_SECRET_KEY, TAddress, TApp, TCounter, TFile, TMember, TMiniRole, TOrg, TPSGC, TPermission, TPermissionGroup, TRole, TToken, TUser, TUserRole, TVerification, TVerificationMetadata, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, addressSchema, isDev, modelApp, modelPSGC, modelPermission, modelPermissionGroup, schemaApp, schemaAppUpdate, schemaOrg, schemaPSGC, schemaPermission, schemaPermissionGroup, schemaPermissionGroupUpdate, schemaPermissionUpdate, transactionSchema, useAddressController, useAddressRepo, useAppController, useAppRepo, useAppService, useAudioTranscriptionController, useAuthController, useAuthService, useCounterModel, useCounterRepo, useFileController, useFileRepo, useFileService, useGeminiAiService, useGitHubService, useMemberController, useMemberRepo, useOrgController, useOrgRepo, useOrgService, usePSGCController, usePSGCRepo, usePermissionController, usePermissionGroupController, usePermissionGroupRepo, usePermissionGroupService, usePermissionRepo, usePermissionService, useRoleController, useRoleRepo, useTokenRepo, useTranscribeService, useUserController, useUserRepo, useUserService, useUtilController, useVerificationController, useVerificationRepo, useVerificationService };