@eeplatform/core 1.8.6 → 1.8.8
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/.github/workflows/publish.yml +7 -9
- package/CHANGELOG.md +12 -0
- package/CLAUDE.md +106 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +40 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -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"
|
|
26
|
-
cache-dependency-path: yarn.lock
|
|
27
|
-
|
|
28
|
-
- run: yarn install --immutable # Install dependencies with immutable lockfile
|
|
26
|
+
cache: "yarn"
|
|
27
|
+
cache-dependency-path: yarn.lock
|
|
29
28
|
|
|
30
|
-
-
|
|
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
|
|
35
|
+
publish: yarn release
|
|
39
36
|
env:
|
|
40
37
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
38
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/CHANGELOG.md
CHANGED
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
|
@@ -762,6 +762,7 @@ declare function usePSGCRepo(): {
|
|
|
762
762
|
prefix?: string;
|
|
763
763
|
type?: string;
|
|
764
764
|
}) => Promise<TPSGC | null>;
|
|
765
|
+
setRegionProvinceName: () => Promise<"Successfully set region name as province name for cities." | undefined>;
|
|
765
766
|
};
|
|
766
767
|
|
|
767
768
|
declare function usePSGCController(): {
|
package/dist/index.js
CHANGED
|
@@ -1878,7 +1878,7 @@ function useVerificationService() {
|
|
|
1878
1878
|
to: email,
|
|
1879
1879
|
subject: "Member Invite",
|
|
1880
1880
|
html: emailContent2,
|
|
1881
|
-
from: "EEPlatform"
|
|
1881
|
+
from: `"EEPlatform" <support@goweekdays.com>`
|
|
1882
1882
|
}).catch((error) => {
|
|
1883
1883
|
import_nodejs_utils9.logger.log({
|
|
1884
1884
|
level: "error",
|
|
@@ -1900,7 +1900,7 @@ function useVerificationService() {
|
|
|
1900
1900
|
to: email,
|
|
1901
1901
|
subject: "User Invite",
|
|
1902
1902
|
html: emailContent,
|
|
1903
|
-
from: "EEPlatform"
|
|
1903
|
+
from: `"EEPlatform" <support@goweekdays.com>`
|
|
1904
1904
|
}).catch((error) => {
|
|
1905
1905
|
import_nodejs_utils9.logger.log({
|
|
1906
1906
|
level: "error",
|
|
@@ -1934,7 +1934,7 @@ function useVerificationService() {
|
|
|
1934
1934
|
mailer.sendMail({
|
|
1935
1935
|
to: email,
|
|
1936
1936
|
subject: "Forget Password",
|
|
1937
|
-
from: "EEPlatform"
|
|
1937
|
+
from: `"EEPlatform" <support@goweekdays.com>`,
|
|
1938
1938
|
html: emailContent
|
|
1939
1939
|
}).catch((error) => {
|
|
1940
1940
|
import_nodejs_utils9.logger.log({
|
|
@@ -2129,7 +2129,7 @@ function useVerificationService() {
|
|
|
2129
2129
|
to: email,
|
|
2130
2130
|
subject: "Sign Up Verification",
|
|
2131
2131
|
html: emailContent,
|
|
2132
|
-
from: "EEPlatform"
|
|
2132
|
+
from: `"EEPlatform" <support@goweekdays.com>`
|
|
2133
2133
|
}).catch((error) => {
|
|
2134
2134
|
import_nodejs_utils9.logger.log({
|
|
2135
2135
|
level: "error",
|
|
@@ -6250,6 +6250,40 @@ function usePSGCRepo() {
|
|
|
6250
6250
|
throw new import_nodejs_utils33.InternalServerError("Failed to delete PSGC.");
|
|
6251
6251
|
}
|
|
6252
6252
|
}
|
|
6253
|
+
async function setRegionProvinceName() {
|
|
6254
|
+
try {
|
|
6255
|
+
const cities = await collection.find({ type: { $in: ["City", "Mun"] } }).toArray();
|
|
6256
|
+
for (let index = 0; index < cities.length; index++) {
|
|
6257
|
+
const city = cities[index];
|
|
6258
|
+
if (city.region) {
|
|
6259
|
+
continue;
|
|
6260
|
+
}
|
|
6261
|
+
const province = await collection.findOne({
|
|
6262
|
+
type: "Prov",
|
|
6263
|
+
code: { $regex: `^${city.code.substring(0, 5)}` }
|
|
6264
|
+
});
|
|
6265
|
+
if (province) {
|
|
6266
|
+
await collection.updateOne(
|
|
6267
|
+
{ _id: city._id },
|
|
6268
|
+
{ $set: { province: province.name } }
|
|
6269
|
+
);
|
|
6270
|
+
}
|
|
6271
|
+
const region = await collection.findOne({
|
|
6272
|
+
type: "Reg",
|
|
6273
|
+
code: { $regex: `^${city.code.substring(0, 2)}` }
|
|
6274
|
+
});
|
|
6275
|
+
if (region) {
|
|
6276
|
+
await collection.updateOne(
|
|
6277
|
+
{ _id: city._id },
|
|
6278
|
+
{ $set: { region: region.name } }
|
|
6279
|
+
);
|
|
6280
|
+
}
|
|
6281
|
+
}
|
|
6282
|
+
return "Successfully set region name as province name for cities.";
|
|
6283
|
+
} catch (error) {
|
|
6284
|
+
console.log(error);
|
|
6285
|
+
}
|
|
6286
|
+
}
|
|
6253
6287
|
return {
|
|
6254
6288
|
createIndexes,
|
|
6255
6289
|
add,
|
|
@@ -6257,7 +6291,8 @@ function usePSGCRepo() {
|
|
|
6257
6291
|
getById,
|
|
6258
6292
|
updateFieldById,
|
|
6259
6293
|
deleteById,
|
|
6260
|
-
getByName
|
|
6294
|
+
getByName,
|
|
6295
|
+
setRegionProvinceName
|
|
6261
6296
|
};
|
|
6262
6297
|
}
|
|
6263
6298
|
|