Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions .github/workflows/manual-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ on:

jobs:
cleanup:
permissions:
contents: write
pull-requests: write
name: Disk Cleanup
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/scc-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:

jobs:
scc-check:
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
Expand Down
56 changes: 56 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,59 @@
## [2.3.0-stage.5](https://github.com/aziontech/lib/compare/v2.3.0-stage.4...v2.3.0-stage.5) (2025-12-03)


### Bug Fixes

* add support for ArrayBuffer and Uint8Array content types in Storage API (#323) ([2623b63](https://github.com/aziontech/lib/commit/2623b63837f2f9bd12672282599ee627645cc3d2))

## [2.3.0-stage.4](https://github.com/aziontech/lib/compare/v2.3.0-stage.3...v2.3.0-stage.4) (2025-11-28)


### Bug Fixes

* adjust Node.js Polyfills and add Unicode Character Sanitization (#320) ([8bd151e](https://github.com/aziontech/lib/commit/8bd151ead39ff6c0879865aeb99a19512100bf2d))

## [2.3.0-stage.3](https://github.com/aziontech/lib/compare/v2.3.0-stage.2...v2.3.0-stage.3) (2025-11-21)


### Features

* add AsyncLocalStorage snapshot polyfill and zlib inflateSync support (#317) ([e507301](https://github.com/aziontech/lib/commit/e507301be5ee6ba8875d1918bdbdbd710408d32b))

## [2.3.0-stage.2](https://github.com/aziontech/lib/compare/v2.3.0-stage.1...v2.3.0-stage.2) (2025-11-18)


### Features

* add SvelteKit preset with custom adapter (#315) ([b46122b](https://github.com/aziontech/lib/commit/b46122b2a18c5f9f8c83e5c3ed2a4a56074b2d43))

## [2.3.0-stage.1](https://github.com/aziontech/lib/compare/v2.2.4-stage.3...v2.3.0-stage.1) (2025-11-13)


### Features

* improve validation error messages with detailed formatting and fix cache settings (#314) ([f6a53cf](https://github.com/aziontech/lib/commit/f6a53cf768aab395039b679a10a544252593b1b3))

### [2.2.4-stage.3](https://github.com/aziontech/lib/compare/v2.2.4-stage.2...v2.2.4-stage.3) (2025-11-11)


### Bug Fixes

* add required field validation for config schema (#313) ([b223cfd](https://github.com/aziontech/lib/commit/b223cfdf7f2f04187eb9326e603922fa9c9b96f2))

### [2.2.4-stage.2](https://github.com/aziontech/lib/compare/v2.2.4-stage.1...v2.2.4-stage.2) (2025-11-11)


### Bug Fixes

* cmd manifest transform (#312) ([18b516a](https://github.com/aziontech/lib/commit/18b516ac28cb0d818e1b569df58c6e18538b4c4f))

### [2.2.4-stage.1](https://github.com/aziontech/lib/compare/v2.2.3...v2.2.4-stage.1) (2025-11-10)


### Bug Fixes

* improve performance of pem cleanup in the jws package (#311) ([4e24b26](https://github.com/aziontech/lib/commit/4e24b266882692c37488295f500068dbffc59a0d))

### [2.2.3](https://github.com/aziontech/lib/compare/v2.2.2...v2.2.3) (2025-11-06)


Expand Down
93 changes: 93 additions & 0 deletions docs/release-diagram.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Release Workflow Diagram

```mermaid
graph TD
A[Open PR to main or stage]
A --> B[Run CI]
B --> C[Lint and build]
C --> D[Unit tests]
D --> E[E2E tests]
E --> F[PR approved and merged]

F --> G[Push to main or stage]
G --> H[Release job]
H --> I[Checkout]
I --> J[Setup Node 20]
J --> K[Install deps]
K --> L[Build npm run compile]
L --> M[Semantic release]
M --> M2[Publish package to npm]

M2 --> N{Branch is main}
N -->|No| O[End]
N -->|Yes| P[Sync stage job]
P --> Q[Checkout]
Q --> R[Configure Git]
R --> S[Fetch and pull main]
S --> T[Checkout stage]
T --> U[Merge main into stage]
U --> V[Push stage]

style A fill:#0d47a1,stroke:#0b3c87,stroke-width:1px,color:#ffffff
style B fill:#1565c0,stroke:#0d47a1,stroke-width:1px,color:#ffffff
style C fill:#1565c0,stroke:#0d47a1,stroke-width:1px,color:#ffffff
style D fill:#1565c0,stroke:#0d47a1,stroke-width:1px,color:#ffffff
style E fill:#1565c0,stroke:#0d47a1,stroke-width:1px,color:#ffffff
style F fill:#1976d2,stroke:#0d47a1,stroke-width:1px,color:#ffffff

style G fill:#1b5e20,stroke:#0d3a12,stroke-width:1px,color:#ffffff
style H fill:#2e7d32,stroke:#1b5e20,stroke-width:1px,color:#ffffff
style I fill:#2e7d32,stroke:#1b5e20,stroke-width:1px,color:#ffffff
style J fill:#2e7d32,stroke:#1b5e20,stroke-width:1px,color:#ffffff
style K fill:#2e7d32,stroke:#1b5e20,stroke-width:1px,color:#ffffff
style L fill:#2e7d32,stroke:#1b5e20,stroke-width:1px,color:#ffffff
style M fill:#388e3c,stroke:#1b5e20,stroke-width:1px,color:#ffffff
style M2 fill:#004d40,stroke:#00251a,stroke-width:1px,color:#ffffff

style N fill:#e65100,stroke:#bf360c,stroke-width:1px,color:#ffffff
style O fill:#424242,stroke:#212121,stroke-width:1px,color:#ffffff
style P fill:#f9a825,stroke:#f57f17,stroke-width:1px,color:#000000
style Q fill:#f9a825,stroke:#f57f17,stroke-width:1px,color:#000000
style R fill:#f9a825,stroke:#f57f17,stroke-width:1px,color:#000000
style S fill:#f9a825,stroke:#f57f17,stroke-width:1px,color:#000000
style T fill:#f9a825,stroke:#f57f17,stroke-width:1px,color:#000000
style U fill:#f9a825,stroke:#f57f17,stroke-width:1px,color:#000000
style V fill:#f9a825,stroke:#f57f17,stroke-width:1px,color:#000000
```

## Description

This GitHub Actions workflow automates the CI and release process for the project.

- **Trigger conditions**

- CI (`ci.yml`) runs on pull requests targeting `main` or `stage`.
- Release (`release.yml`) runs on every `push` to the `main` or `stage` branches.

- **Release flow (simplified)**

- Checkout code and configure Node.js 20.
- Install dependencies and build the project (`npm run compile`).
- Run `semantic-release` to determine the next version and generate release artifacts.
- **Publish the package to the npm registry** using the configured npm token.
- If the push is on `main`, run the `sync-stage` job to merge `main` into `stage` and push the updated `stage` branch.

- **Release job** (runs on every push to `main` or `stage`)

- **Checkout** the repository with full history (`fetch-depth: 0`) using the `CUSTOM_GITHUB_TOKEN`.
- **Setup Node.js** version 20 and enable npm cache for faster installs.
- **Install dependencies** using `npm install`.
- **Build the project** by running `npm run compile`.
- **Publish a release** using `npx semantic-release`, authenticated with `CUSTOM_GITHUB_TOKEN` and `NPM_TOKEN`.

- **Sync-stage job** (runs only when the push is to `main`)
- Declared with `needs: release`, so it runs only if the `release` job completes successfully.
- Additionally guarded by `if: github.ref == 'refs/heads/main'`, so it is skipped for pushes to `stage`.
- **Checkout** the repository with full history using `CUSTOM_GITHUB_TOKEN`.
- **Configure Git** user name and email for automated commits.
- **Synchronize branches** by merging `main` into `stage`:
- Fetch latest changes from `origin`.
- Pull the latest `main` branch.
- Check out the `stage` branch.
- Merge `main` into `stage` with a predefined commit message (including `[skip ci]`) and conflict strategy `-Xtheirs`.
- Push the updated `stage` branch back to `origin`.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azion",
"version": "2.2.3",
"version": "2.3.0-stage.5",
"description": "Azion Packages for Edge Computing.",
"scripts": {
"prepare": "husky",
Expand Down Expand Up @@ -77,7 +77,8 @@
"packages/unenv-preset/src/polyfills/*",
"packages/bundler/src/polyfills/*",
"packages/presets/src/presets/next/*",
"packages/presets/src/presets/nuxt/nitro/*"
"packages/presets/src/presets/nuxt/nitro/*",
"packages/presets/src/presets/svelte/kit/*"
],
"exports": {
".": {
Expand All @@ -90,6 +91,8 @@
},
"./presets/preset/*": "./packages/presets/dist/presets/*",
"./preset/nuxt/*": "./packages/presets/src/presets/nuxt/nitro/*/index.js",
"./preset/sveltekit": "./packages/presets/src/presets/svelte/kit/index.js",
"./preset/sveltekit/cache": "./packages/presets/src/presets/svelte/kit/cache/index.js",
"./bundler": {
"require": "./packages/bundler/dist/index.cjs",
"import": "./packages/bundler/dist/index.js"
Expand Down
3 changes: 3 additions & 0 deletions packages/bundler/src/bundlers/esbuild/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import AzionEsbuildConfig from './esbuild.config';
import AzionPolyfillPlugin from './plugins/azion-polyfills';
import OptionalChainingAssignmentPlugin from './plugins/babel-custom';
import NodePolyfillPlugin from './plugins/node-polyfills';
import SanitizeWorker from './plugins/sanitize-worker';

// eslint-disable-next-line
interface ESBuildConfig extends esbuild.BuildOptions {}
Expand All @@ -23,13 +24,15 @@ interface ESBuildPluginClasses {
NodePolyfillsPlugin: (isProduction: boolean) => ESBuildPlugin;
AzionPolyfillsPlugin: (isProduction: boolean) => ESBuildPlugin;
OptionalChainingAssignmentPlugin: () => ESBuildPlugin;
SanitizeWorker: (sanitize: boolean, options?: { outfile?: string }) => ESBuildPlugin;
}

// Create esbuild-specific plugins
const bundlerPlugins = createBundlerPlugins<ESBuildPluginClasses, ESBuildConfiguration>({
NodePolyfillsPlugin: NodePolyfillPlugin,
AzionPolyfillsPlugin: AzionPolyfillPlugin,
OptionalChainingAssignmentPlugin: OptionalChainingAssignmentPlugin,
SanitizeWorker: SanitizeWorker,
});

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import SanitizeWorker from './sanitize-worker';

export default SanitizeWorker;
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Plugin, PluginBuild } from 'esbuild';
import fs from 'fs';

const SanitizeWorker = (sanitize: boolean, options?: { outfile?: string }): Plugin => {
const NAME = 'sanitize-worker';

const sanitizeUTF8 = (content: string) => {
let escapedCount = 0;
const chars = Array.from(content);
const result = chars
.map((char) => {
const codePoint = char.codePointAt(0)!;
// Escape caracteres fora do Basic Multilingual Plane (BMP)
if (codePoint >= 0x10000) {
escapedCount++;
return `\\u{${codePoint.toString(16)}}`;
}
return char;
})
.join('');
return { result, escapedCount };
};

const processFile = (filePath: string) => {
const content = fs.readFileSync(filePath, 'utf-8');
const { result, escapedCount } = sanitizeUTF8(content);

if (escapedCount > 0) {
console.log(`[sanitize-worker] Escaped ${escapedCount} Unicode character(s) in ${filePath}`);
fs.writeFileSync(filePath, result, 'utf-8');
}
};

return {
name: NAME,
setup(build: PluginBuild) {
build.onEnd(async (result) => {
if (!sanitize || result.errors.length > 0) {
return;
}
if (build.initialOptions.entryPoints) {
for (const filePath of Object.keys(build.initialOptions.entryPoints)) {
processFile(`${filePath}.js`);
}
} else {
const outfile = options?.outfile || build.initialOptions.outfile;
if (outfile) {
processFile(outfile);
}
}
});
},
};
};

export default SanitizeWorker;
12 changes: 12 additions & 0 deletions packages/bundler/src/helpers/bundler-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ export const createBundlerPlugins = <
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
[(pluginsClasses as any).OptionalChainingAssignmentPlugin()]
: []),
// Add sanitize worker plugin if available (esbuild only)
...('SanitizeWorker' in pluginsClasses
? [
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(pluginsClasses as any).SanitizeWorker(process.env.AZ_ENABLE_SANITIZE_WORKER ?? false, {
options: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
outfile: (config as any).outfile,
},
}),
]
: []),
] as unknown as typeof config.plugins;
return config;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class StorageContext {
* Stores a object in the storage.
* @async
* @param {string} key - The key to store the value under.
* @param {ReadableStream|string} value - The value to store (can be a ReadableStream or a string).
* @param {ArrayBuffer | Uint8Array | ReadableStream} value - The value to store (can be a ReadableStream, ArrayBuffer, or Uint8Array).
* @param {object} options - Additional options for storing the object.
* @returns {Promise<object>} A promise that resolves to an object representing the stored data.
* @throws {Error} Throws an error if the storing process fails.
Expand All @@ -57,7 +57,8 @@ class StorageContext {
const writeStream = fs.createWriteStream(`${this.#pathBucket}/${key}`);
await pipeline(value, writeStream);
} else {
await fs.promises.writeFile(`${this.#pathBucket}/${key}`, value);
const fileContent = value instanceof ArrayBuffer ? Buffer.from(value) : value;
await fs.promises.writeFile(`${this.#pathBucket}/${key}`, fileContent);
}

const responseMetadata = await StorageContext.putMetadata(this.#pathBucket, key, options, this.#metadataPrefix);
Expand Down Expand Up @@ -103,7 +104,7 @@ class StorageContext {
* Generates a response object for the retrieved asset.
* @static
* @async
* @param {ReadableStream|string} value - The value of the asset.
* @param {ArrayBuffer | Uint8Array | ReadableStream} value - The value of the asset.
* @param {object} metadataStore - Metadata associated with the asset.
* @returns {Promise<object>} A promise that resolves to an object representing the response asset.
*/
Expand Down
42 changes: 6 additions & 36 deletions packages/bundler/src/polyfills/crypto/context/crypto.context.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as crypto from 'node:crypto';

export default crypto;
export var { Cipher } = crypto;
export var { Decipher } = crypto;
export var { DiffieHellman } = crypto;
Expand Down Expand Up @@ -35,39 +36,8 @@ export var { getRandomValues } = crypto;
export var { randomUUID } = crypto;
export var { generateKeyPair } = crypto;

export default {
Cipher,
Decipher,
DiffieHellman,
DiffieHellmanGroup,
Hash,
Hmac,
Sign,
Verify,
constants,
createCipheriv,
createDecipheriv,
createDiffieHellman,
createDiffieHellmanGroup,
createECDH,
createHash,
createHmac,
createSign,
createVerify,
getCiphers,
getDiffieHellman,
getHashes,
pbkdf2,
pbkdf2Sync,
privateDecrypt,
privateEncrypt,
pseudoRandomBytes,
publicDecrypt,
publicEncrypt,
randomBytes,
randomFill,
randomFillSync,
getRandomValues,
randomUUID,
generateKeyPair,
};
// Export Web Crypto API from globalThis.crypto (edge runtime)
export var webcrypto = (typeof globalThis !== 'undefined' && globalThis.crypto) || crypto.webcrypto;
export var subtle = webcrypto?.subtle;
export var CryptoKey = (typeof globalThis !== 'undefined' && globalThis.CryptoKey) || crypto.CryptoKey;
export var KeyObject = crypto.KeyObject;
Loading
Loading