Skip to content
Merged

V4.0 #186

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
44be20b
Merge pull request #179 from lemoncloud-io/v4
claire-lemon Jun 13, 2025
7b42952
style: apply markdownlint style fixes
claire-lemon Jun 16, 2025
47ecdf0
Merge pull request #180 from lemoncloud-io/docs/update-v4-readme
claire-lemon Jun 16, 2025
44ec571
docs: update HOW_TO_UPGRADE_V4.md with asyncCredentials usage and tes…
claire-lemon Jun 16, 2025
659d243
Merge pull request #181 from lemoncloud-io/docs/update-v4-readme
claire-lemon Jun 16, 2025
b933929
feat: add isLambda function and update awsConfig for Lambda environme…
claire-lemon Jun 27, 2025
3dc2383
fix: update isLambda to use optional chaining
claire-lemon Jun 27, 2025
eafae17
Merge pull request #182 from lemoncloud-io/feat/lambda-detect
steve-lemon Jun 27, 2025
04c6937
v4.0.4 - released
steve-lemon Jun 27, 2025
545bf8e
fix: update ProtocolService to handle Lambda response payload correct…
claire-lemon Jul 3, 2025
13de7bf
Merge pull request #183 from lemoncloud-io/feat/json-serialize-uint8a…
steve-lemon Jul 3, 2025
a8a9901
v4.0.5
steve-lemon Jul 3, 2025
f93a09a
docs: update HOW_TO_UPGRADE_V4.md with serverless.yml plugin modifica…
claire-lemon Jul 24, 2025
7726ff2
chore: comments
steve-lemon Jul 28, 2025
7e1bccb
Merge pull request #184 from lemoncloud-io/docs/update-v4-readme
claire-lemon Aug 5, 2025
a01f9e2
chore: cleanup of loadProfile
steve-lemon Aug 8, 2025
c818acd
chore: cleanup
steve-lemon Aug 8, 2025
00e6b86
v4.0.6
steve-lemon Aug 8, 2025
b888b6f
Merge pull request #185 from lemoncloud-io/feat/opt-with-devkit-6
steve-lemon Aug 8, 2025
c0eaafd
v4.0.7 - opt verify-jwt
steve-lemon Aug 14, 2025
ee5c198
chore: cleanup spec
steve-lemon Sep 16, 2025
47659c8
test: enhance controller tests: 81.63 -> 96.42
claire-lemon Sep 26, 2025
86fdbf7
test: enhance api tests: 65.23 to 95.36
claire-lemon Sep 29, 2025
31c1978
test: add aws tests
claire-lemon Nov 21, 2025
52ec3e2
test: opt controller test spec 81.9 to 97.95
claire-lemon Nov 25, 2025
2d5d644
test: opt aws test specs 40.03 to 98.35
claire-lemon Nov 25, 2025
c82cae7
test: opt cache test spec 60.06 to 97.48
claire-lemon Nov 25, 2025
38e04cd
test: opt config test spec 60.22 to 98.86
claire-lemon Nov 25, 2025
964293e
test: opt dynamo test spec 59.27 to 99.72
claire-lemon Nov 26, 2025
f957d2a
test: opt dynamo/tools test spec 35.3 to 96.93
claire-lemon Nov 26, 2025
d4155ea
test: opt elastic test 30.82 to 96.77
claire-lemon Nov 26, 2025
1525b93
test: opt engine test 71.87 to 99.86
claire-lemon Nov 26, 2025
a605e33
test: opt lambda test 80.44 to 98.31
claire-lemon Nov 26, 2025
03bc765
test: opt protocol test 58.17 to 99.46
claire-lemon Nov 26, 2025
ece0823
test: opt storage test 79.36 to 96.93
claire-lemon Nov 26, 2025
68edb2d
test: opt extended test 38 to 100
claire-lemon Nov 26, 2025
7822673
test: opt helpers test 83.6 to 100
claire-lemon Nov 26, 2025
44fd589
test: opt dynamodb-value test 40 to 100
claire-lemon Nov 26, 2025
6c4035f
test: opt tools 86.48 to 93.24
claire-lemon Nov 26, 2025
72da6ea
chore: cleanup
steve-lemon Nov 27, 2025
9d573dd
chore: fix indentation in HTTP proxy error handling test
claire-lemon Nov 27, 2025
2c3cdcf
chore: increase sleep duration in cache service tests
claire-lemon Nov 27, 2025
77cb609
test: opt environ test 69.69 to 96.96
claire-lemon Nov 27, 2025
04df717
test: opt api-service to 97.68
claire-lemon Nov 27, 2025
5a855a0
test: update waited() test to assert result directly
claire-lemon Nov 27, 2025
f93e0ec
feat: add mock error JSON, object, and string cases for testing
claire-lemon Nov 27, 2025
e48bf70
test: add case for handling module not found error in environ tests
claire-lemon Nov 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 107 additions & 42 deletions HOW_TO_UPGRADE_V4.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,141 @@

---

### 0. Update lemon-core Version
## 0. Update lemon-core Version

```sh
$ npm install lemon-core --save
npm install lemon-core@^4.0.5 --save
```

### 1. Upgrade Node.js Version
## 1. Upgrade Node.js Version

```sh
$ nvm install 22
$ nvm use 22
```bash
nvm install 22
nvm use 22
```

* Update `.nvmrc` file to `22`

> #### Note
```diff
- 18.19.1
+ 22.15.1
```

* Update `config.js` Node.js runtime version of your profile

```diff
lemon: {
name: 'lemon-app',
- runtime: 'nodejs18.x', // Powered by the V8 JavaScript Engine (used in Chromium)
+ runtime: 'nodejs22.x',
},
```

* Update plugins in serverless.yml

```diff
plugins:
- serverless-offline
- - serverless-offline
+ #WARN - failure in nodejs 22.x due to `serverless-offline` plugin @250627
+ # - serverless-offline
- serverless-aws-documentation
- serverless-prune-plugin
- serverless-plugin-log-retention
```

> ### Note
>
> If you **don’t modify the `plugins` section** in `serverless.yml`, you may encounter the following issues:
>
> When running `npm run deploy` in a Node.js 22, you may encounter the following error:
>
> ```
> ```bash
> Error [ERR_REQUIRE_ASYNC_MODULE]: require() cannot be used on an ESM graph with top-level await. Use import() instead. To see where the top-level await comes from, use --experimental-print-required-tla.
> ```
>
> In this case:
>
> * Set only the Lambda runtime (Node.js version) to 22 in your `serverless.yml`.
> * Execute the deployment command (`npm run deploy`) in a **Node.js 18 (nvm 18)**.

## 2. Install `lemon-devkit`

* Add as a `devDependency`:

```bash
npm install --save-dev lemon-devkit
```

---

### package.json Key Changes

```diff
{
"engines": {
- "node": ">=14",
+ "node": ">=22"
},
"dependencies": {
- "lemon-core": "^3.x",
+ "lemon-core": "^4.x",
},
"devDependencies": {
+ "lemon-devkit": "^0.0.3",
"typescript": "^4.x",
"jest": "^29.x"
}
}
```

---

### 2. AWS SDK: v2 to v3 Migration
## 3. AWS SDK: v2 to v3 Migration

1. **Credential Management**

* Replace legacy `credentials` approach with `asyncCredentials()` from `lemon-core`.

* Example:

```ts
import { asyncCredentials } from 'lemon-core';
const credentials = await asyncCredentials(PROFILE);
```

* **\[express.ts Updates]**

```diff
//! dynamic loading credentials by profile. (search PROFILE -> NAME)
export const credentials = async (name?: string) => {
_log(NS, `credentials(${name})..`);
const NAME = name || ($engine.environ('NAME', '') as string);
const profile = $engine.environ('PROFILE', NAME) as string;
- return $core.tools.credentials(profile);
+ return $core.tools.asyncCredentials(profile);
};
```

* **\[Test Updates]**
* If you use `loadProfile(process)` to set up environment variables, move it **inside `it()` blocks** and `await` the call

```ts
it('should initialize credentials', async () => {
const PROFILE = await loadProfile(process);
const credentials = await asyncCredentials(PROFILE);
expect(credentials).toBeDefined();
});
```

2. **Client Initialization**

* Use `awsConfig($engine, region)` for initializing v3 clients.
* Example:

```ts
import { SQSClient } from '@aws-sdk/client-sqs';
import $engine from 'lemon-core';
import $engine, { awsConfig } from 'lemon-core';

async function createSqsClient() {
const region = 'ap-northeast-2';
Expand All @@ -59,51 +146,29 @@ $ nvm use 22

---

### 3. Install `lemon-devkit`
## 4. Update src/cores

* Add as a `devDependency`:

```sh
$ npm install --save-dev lemon-devkit
```

---
To update the src/cores directory in your project using the latest version from [lemon-templates-api](https://github.com/lemoncloud-io/lemon-templates-api), follow these steps:

### package.json Key Changes

```diff
{
"engines": {
- "node": ">=14",
+ "node": ">=22"
},
"dependencies": {
- "lemon-core": "^3.x",
+ "lemon-core": "^4.x",
},
"devDependencies": {
+ "lemon-devkit": "^0.0.3",
"typescript": "^4.x",
"jest": "^29.x"
}
}
```
1. In your project: Delete the existing src/cores folder.
2. From lemon-templates-api: Copy the entire src/cores directory.
3. In your project: Paste the copied src/cores directory into the same path (src/cores).

---

### At-a-Glance Checklist
## At-a-Glance Checklist

* [ ] **Upgrade lemon-core**
* [ ] **Upgrade to Node.js 22**

* Change `nvm` version, update `.nvmrc`
* When using Node.js 22, `npm run deploy` may fail due to module loading errors.
For deployment, use Node.js 18 instead.
* Change node.js runtime version of your profile, update `config.js`
* Update plugins in serverless.yml
* [ ] **Install lemon-devkit** (devDependency)
* [ ] **Review AWS SDK v3 migration changes**

* **Credentials**: Replace old `credentials` code with `asyncCredentials()`
* **Client Initialization**: Use `awsConfig($engine, region)`
* [ ] **Install lemon-devkit** (devDependency)
* [ ] **Update src/cores**
* [ ] **Review CI/CD environments**

* Ensure Node.js 22 is set in `serverless.yml`, `Dockerfile`, etc.
Expand Down
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
[![npm version](https://badge.fury.io/js/lemon-core.svg)](https://badge.fury.io/js/lemon-core)
[![GitHub version](https://badge.fury.io/gh/lemoncloud-io%2Flemon-core.svg)](https://badge.fury.io/gh/lemoncloud-io%2Flemon-core)


# lemon-core / V4

Lemon Core Bootloader for Serverless Micro-Service
Expand All @@ -14,7 +13,6 @@ Lemon Core Bootloader for Serverless Micro-Service

![](assets/2019-11-26-23-43-47.png)


## Architecture

Basic MicroService Architecutre with `API` + `SNS` + `SQS`.
Expand All @@ -25,7 +23,6 @@ Basic MicroService Architecutre with `API` + `SNS` + `SQS`.

![](assets/lemon-core-ms-arch.png)


### Protocol Service

- support inter-communication between micro services
Expand All @@ -51,30 +48,31 @@ const queueId = await service.enqueue(protocol, callback, 30);
1. install `lemon-core` module (>= 2.1.0).

```sh
$ npm install lemon-core --save
npm install lemon-core --save
```

TODO - TBD in detail.



## Contribution

Plz, request PR.
Plz, request PR.

See [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md)


## LICENSE

[MIT](LICENSE) - (C) 2019 LemonCloud Co Ltd. - All Rights Reserved.


----------------
# VERSION INFO #

## VERSION INFO

| Version | Description
|-- |--
| 4.0.7 | optimized `verifyJWT()` w/ more detail error.
| 4.0.6 | optimized `loadProfile()` as sync call.
| 4.0.5 | improve `$protocol` w/ `lambda` invoke.
| 4.0.0 | optimized with `nodejs22`.
| 3.2.16 | improve `ALBHandler` to support `elb` event.
| 3.2.15 | improve `NextContext` to support `referer` and `origin` header.
| 3.2.13 | improve `createSigV4Proxy()` to support the sig-v4 request to AWS.
Expand Down Expand Up @@ -134,4 +132,3 @@ See [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md)
| 2.0.0 | improve `lemon-engine`, and support `typescript` fully.
| 1.2.15 | improve `doReportError` with error message
| 1.2.12 | support `doReportMetric()` for saving metric data.

10 changes: 10 additions & 0 deletions data/mocks/mock.error-json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"!": "error case with JSON string",
"param": {
"method": "GET",
"endpoint": "https://api.lemoncloud.io/hello/test",
"id": "error-json"
},
"data": null,
"error": "{\"message\":\"JSON error\",\"code\":500}"
}
13 changes: 13 additions & 0 deletions data/mocks/mock.error-object.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"!": "error case with error object",
"param": {
"method": "GET",
"endpoint": "https://api.lemoncloud.io/hello/test",
"id": "error-object"
},
"data": null,
"error": {
"message": "Error object",
"statusCode": 400
}
}
10 changes: 10 additions & 0 deletions data/mocks/mock.error-string.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"!": "error case with plain string",
"param": {
"method": "GET",
"endpoint": "https://api.lemoncloud.io/hello/test",
"id": "error-string"
},
"data": null,
"error": "Plain string error message"
}
Loading