Skip to content

Commit ae884c1

Browse files
committed
Fix sdk compatibility across browser nodejs and modules
1 parent 8a19a96 commit ae884c1

File tree

7 files changed

+197
-650
lines changed

7 files changed

+197
-650
lines changed

package-lock.json

Lines changed: 54 additions & 475 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@
1212
"agentic-ai"
1313
],
1414
"type": "module",
15-
"main": "./dist/index.js",
16-
"module": "./dist/index.esm.js",
15+
"main": "./dist/index.cjs",
16+
"module": "./dist/index.mjs",
1717
"types": "./dist/index.d.ts",
1818
"exports": {
1919
".": {
20-
"import": "./dist/index.esm.js",
21-
"require": "./dist/index.js",
22-
"types": "./dist/index.d.ts"
20+
"import": {
21+
"types": "./dist/index.d.mts",
22+
"default": "./dist/index.mjs"
23+
},
24+
"require": {
25+
"types": "./dist/index.d.cts",
26+
"default": "./dist/index.cjs"
27+
}
2328
}
2429
},
2530
"files": [
@@ -28,38 +33,29 @@
2833
],
2934
"scripts": {
3035
"build": "rollup -c",
36+
"build:watch": "rollup -c -w",
3137
"clean": "rimraf dist && rimraf node_modules && rimraf package-lock.json",
3238
"docs:api": "typedoc"
3339
},
3440
"dependencies": {
3541
"@opentelemetry/sdk-logs": "^0.204.0",
3642
"axios": "^1.12.0",
37-
"eventemitter3": "^5.0.1",
38-
"file-type": "^21.0.0",
39-
"mime-types": "^3.0.1",
40-
"uuid": "^9.0.1",
41-
"ws": "^8.16.0",
42-
"zod": "^3.22.4",
43-
"typedoc": "^0.28.13",
44-
"typedoc-plugin-markdown": "^4.8.1",
45-
"rimraf": "^6.0.1"
43+
"zod": "^3.22.4"
4644
},
4745
"devDependencies": {
4846
"@rollup/plugin-commonjs": "^25.0.0",
4947
"@rollup/plugin-json": "^6.0.0",
5048
"@rollup/plugin-node-resolve": "^15.2.0",
5149
"@rollup/plugin-typescript": "^11.1.0",
52-
"@types/jest": "^29.5.14",
53-
"@types/mime-types": "^3.0.1",
5450
"@types/node": "^20.11.19",
5551
"@types/uuid": "^9.0.8",
56-
"@types/ws": "^8.5.10",
5752
"builtin-modules": "^3.3.0",
5853
"dotenv": "^17.2.0",
59-
"jest": "^29.7.0",
54+
"rimraf": "^6.0.1",
6055
"rollup": "^4.0.0",
6156
"rollup-plugin-dts": "^6.1.0",
62-
"ts-jest": "^29.4.0",
57+
"typedoc": "^0.28.13",
58+
"typedoc-plugin-markdown": "^4.8.1",
6359
"typescript": "^5.3.3"
6460
},
6561
"repository": {
@@ -69,4 +65,4 @@
6965
"workspaces": [
7066
"packages/*"
7167
]
72-
}
68+
}

rollup.config.js

Lines changed: 87 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,126 @@
1-
import resolve from '@rollup/plugin-node-resolve';
2-
import commonjs from '@rollup/plugin-commonjs';
3-
import typescript from '@rollup/plugin-typescript';
4-
import dts from 'rollup-plugin-dts';
5-
import json from '@rollup/plugin-json';
6-
import builtins from 'builtin-modules';
7-
import { readFileSync } from 'fs';
1+
import resolve from '@rollup/plugin-node-resolve'; // Resolves node_modules dependencies
2+
import commonjs from '@rollup/plugin-commonjs'; // Converts CommonJS modules to ES6
3+
import typescript from '@rollup/plugin-typescript'; // Compiles TypeScript to JavaScript
4+
import dts from 'rollup-plugin-dts'; // Generates TypeScript declaration files
5+
import json from '@rollup/plugin-json'; // Imports JSON files as ES6 modules
6+
import builtins from 'builtin-modules'; // List of Node.js built-in modules (fs, crypto, etc.)
7+
import { readFileSync } from 'fs';
88

99
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
1010

11-
// Get all dependencies from package.json
1211
const allDependencies = [
1312
...Object.keys(pkg.dependencies || {}),
14-
...Object.keys(pkg.peerDependencies || {}),
15-
...builtins // Node.js built-in modules
13+
...Object.keys(pkg.optionalDependencies || {}),
14+
...builtins // Node.js built-in modules - part of Node.js core, no installation needed (crypto, fs, path, etc.)
1615
];
1716

18-
// Base plugins configuration
17+
// Base plugins configuration for Node.js and ESM/CJS builds
1918
const createPlugins = (isBrowser) => [
2019
resolve({
21-
browser: isBrowser,
22-
preferBuiltins: !isBrowser
20+
browser: isBrowser, // When true: resolve browser-compatible versions of modules (e.g., polyfills)
21+
preferBuiltins: !isBrowser // When false: prefer Node.js built-ins (crypto, fs) over browser polyfills
22+
}),
23+
commonjs({
24+
transformMixedEsModules: true, // Handle packages that mix ESM and CommonJS
25+
ignoreTryCatch: false // Don't ignore try-catch when transforming
26+
}),
27+
json(), // Allow importing JSON files as modules
28+
typescript({
29+
tsconfig: './tsconfig.json',
30+
declaration: false,
31+
sourceMap: false,
32+
declarationMap: false
33+
})
34+
];
35+
36+
// Browser-specific plugins for UMD build
37+
const createBrowserPlugins = () => [
38+
resolve({
39+
browser: true,
40+
preferBuiltins: false
41+
}),
42+
commonjs({
43+
transformMixedEsModules: true,
44+
ignoreTryCatch: false
2345
}),
24-
commonjs(),
2546
json(),
2647
typescript({
2748
tsconfig: './tsconfig.json',
28-
declaration: false
49+
declaration: false,
50+
sourceMap: false,
51+
declarationMap: false
2952
})
3053
];
3154

55+
// Rollup build configurations for different output formats
3256
const configs = [
33-
// ESM bundle
57+
// ESM bundle (for Node.js and modern bundlers like Vite, Webpack etc.)
3458
{
35-
input: 'src/index.ts',
59+
input: 'src/index.ts', // Entry point of the SDK
3660
output: {
37-
file: 'dist/index.esm.js',
38-
format: 'es'
61+
file: 'dist/index.mjs', // Output as .mjs for explicit ESM
62+
format: 'es',
63+
inlineDynamicImports: true
3964
},
4065
plugins: createPlugins(false),
4166
external: allDependencies
4267
},
43-
// CommonJS bundle
68+
69+
// CommonJS bundle (for Node.js and older bundlers)
4470
{
45-
input: 'src/index.ts',
71+
input: 'src/index.ts', // Entry point of the SDK
4672
output: {
47-
file: 'dist/index.js',
73+
file: 'dist/index.cjs', // Output as .cjs for explicit CommonJS
4874
format: 'cjs',
49-
exports: 'named'
75+
exports: 'named',
76+
inlineDynamicImports: true
5077
},
5178
plugins: createPlugins(false),
5279
external: allDependencies
5380
},
54-
// Type definitions
81+
82+
// UMD bundle (for browsers via script tag or older bundlers)
83+
{
84+
input: 'src/index.ts', // Entry point of the SDK
85+
output: {
86+
file: 'dist/index.umd.js', // Output as UMD for universal compatibility
87+
format: 'umd', // Universal Module Definition format
88+
name: 'UiPath', // Global variable name when loaded via script tag
89+
inlineDynamicImports: true
90+
},
91+
plugins: createBrowserPlugins()
92+
},
93+
94+
// Type definitions for ESM (.mts extension for ESM types)
95+
{
96+
input: 'src/index.ts', // Entry point for types
97+
output: {
98+
file: 'dist/index.d.mts', // TypeScript declaration file for ESM
99+
format: 'es'
100+
},
101+
plugins: [dts()]
102+
},
103+
104+
// Type definitions for CommonJS (.cts extension for CJS types)
105+
{
106+
input: 'src/index.ts', // Entry point for types
107+
output: {
108+
file: 'dist/index.d.cts', // TypeScript declaration file for CJS
109+
format: 'es'
110+
},
111+
plugins: [dts()]
112+
},
113+
114+
// Main type definitions (for legacy TypeScript and package.json "types" field)
55115
{
56-
input: 'src/index.ts',
116+
input: 'src/index.ts', // Entry point for types
57117
output: {
58-
file: 'dist/index.d.ts',
118+
file: 'dist/index.d.ts', // Main TypeScript declaration file
59119
format: 'es'
60120
},
61121
plugins: [dts()]
62122
}
63123
];
64124

125+
// Export all build configurations
65126
export default configs;

src/models/orchestrator/buckets.models.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,13 @@ export interface BucketServiceModel {
145145
* content: file
146146
* });
147147
*
148-
* // In Node env with explicit content type
148+
* // In Node env with Buffer
149149
* const buffer = Buffer.from('file content');
150150
* const result = await sdk.buckets.uploadFile({
151151
* bucketId: <bucketId>,
152152
* folderId: <folderId>,
153153
* path: '/folder/example.txt',
154154
* content: buffer,
155-
* contentType: 'text/plain'
156155
* });
157156
* ```
158157
*/

src/models/orchestrator/buckets.types.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,6 @@ export interface BucketGetUriOptions extends BaseOptions {
9393
*/
9494
export type BucketGetReadUriOptions = BucketGetUriOptions;
9595

96-
/**
97-
* Request options for getting a write URI for a file in a bucket
98-
*/
99-
export interface BucketGetWriteUriOptions extends BucketGetUriOptions {
100-
/**
101-
* ContentType for S3 access policy
102-
*/
103-
contentType?: string;
104-
}
105-
10696
/**
10797
* Request options for getting files in a bucket
10898
*/
@@ -181,12 +171,6 @@ export interface BucketUploadFileOptions {
181171
* File content to upload
182172
*/
183173
content: Blob | Buffer | File;
184-
185-
/**
186-
* Optional MIME type of the file
187-
* If not provided, it will be auto-detected
188-
*/
189-
contentType?: string;
190174
}
191175

192176
/**

0 commit comments

Comments
 (0)