Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 0 additions & 27 deletions README.md

This file was deleted.

43 changes: 43 additions & 0 deletions sdks/javascript/BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,51 @@ generated/

These files are stable, version-locked, and derived from the AsyncAPI specification. They're ready to use as-is.

## Build System Architecture

### Platform-Specific Build Targets

- **Webpack**: Bundles to multiple formats (ESM and UMD) with optimization and minification
- **Target Environments**: Modern JavaScript support (ES6+) without transpilation
- **Browser**: Chrome 80+, Firefox 74+, Safari 14.1+, Edge 80+ (`target: 'web'`)
- Based on usage of class field declarations and optional chaining operator
- Chrome 80+ (February 2020), Firefox 74+ (March 2020), Safari 14.1+ (April 2021), Edge 80+ (February 2020)
- **Node.js**: 20.0.0+ (`target: 'node'`)
- **Output**: Multiple build formats (browser.mjs, server.mjs, browser.umd.js, server.umd.js)
- **CSP Compliance**: Browser builds exclude AJV and use platform-specific implementations to prevent CSP violations, ensuring compatibility with strict Content Security Policy environments like Salesforce Lightning
- **Platform Architecture**: Runtime organized under `runtime/core/` (shared) and `runtime/platform/browser/` and `runtime/platform/node/` for environment-specific optimizations

### Build Architecture Principles

**Important**: UMD builds are specifically designed for constrained environments (CSP compliance, Salesforce Lightning) and deliberately exclude certain dependencies regardless of target platform. Server UMD ≠ server ESM in terms of bundling strategy.

Always examine:
- Build-comparison tests
- CSP compliance tests
- `BUILD-TESTING.md` documentation

Before modifying externals configuration.

### External Dependency Resolution

When tests fail due to external dependency resolution (like crypto module), fix the TEST ENVIRONMENT, never change the production build configuration. Mock missing externals in test contexts rather than bundling them into production builds. The test environment should adapt to the build architecture, not vice versa.

## Build Scripts

### Available Build Commands

**Development Build**: `npm run build` or `npm run build:all:dev` - Complete build with validation, analysis, and governance checks
**Production Build**: `npm run build:all:prod` - Optimized build for production (skips dev-only checks)
**Full Build**: `npm run build:all:full` - Build with detailed webpack bundles (FULL=1 flag)

All builds compile the SDK using webpack into multiple build targets:
- `dist/browser.mjs` - Browser ES module
- `dist/server.mjs` - Server ES module
- `dist/browser.umd.js` - Browser UMD bundle
- `dist/server.umd.js` - Server UMD bundle

**Dependencies**: `npm install` - Installs all dependencies

### Production Build (Recommended)

```bash
Expand Down
10 changes: 5 additions & 5 deletions sdks/javascript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ The SDK provides four optimized builds, each tailored for specific deployment en
| Build | Module Format | Allows clientSecret | AJV Validation | CSP Safe | Intended Environments | Size (Uncompressed) | Size (Gzipped) |
|-------|---------------|-------------------|----------------|----------|---------------------|-------------------|----------------|
| **Browser ESM** | ES Module | ❌ No | ❌ External Only | ✅ Yes | Modern browsers, Vite, Webpack 5+, bundled apps | ~47KB | ~14KB |
| **Browser UMD** | UMD | ❌ No | ❌ External Only | ✅ Yes | Salesforce Lightning, CDN, legacy browsers, CSP environments | ~50KB | ~14KB |
| **Browser UMD** | UMD | ❌ No | ❌ External Only | ✅ Yes | Salesforce Lightning, CDN, legacy browsers, CSP environments | ~54KB | ~15KB |
| **Server ESM** | ES Module | ✅ Yes | ✅ Full AJV | ❌ No | Node.js servers, microservices, backend APIs | ~164KB | ~25KB |
| **Server UMD** | UMD | ✅ Yes | ❌ CSP-Safe Only | ✅ Yes | Salesforce backend, mixed browser environments, internal tooling | ~55KB | ~16KB |
| **Server UMD** | UMD | ✅ Yes | ❌ External Only | ✅ Yes | Node.js CommonJS, legacy servers, mixed Node.js environments | ~49KB | ~14KB |

### Build Selection Guide

Expand All @@ -100,7 +100,7 @@ The SDK provides four optimized builds, each tailored for specific deployment en
**⚙️ Validation Strategy**
- **Browser builds**: Use lightweight, CSP-safe validation (no AJV)
- **Server ESM**: Includes full AJV schema validation for data integrity
- **Server UMD**: Uses CSP-safe validation (no AJV) for Salesforce compatibility
- **Server UMD**: Uses CSP-safe validation (no AJV) for maximum compatibility
- All builds validate required fields and basic payload structure

### Automatic Build Selection
Expand Down Expand Up @@ -1118,8 +1118,8 @@ The SDK provides several static methods and constants for accessing metadata and
import OptaveJavaScriptSDK from '@optave/client-sdk';

// Version information
const sdkVersion = OptaveJavaScriptSDK.getSdkVersion(); // e.g., "3.2.1"
const specVersion = OptaveJavaScriptSDK.getSpecVersion(); // e.g., "3.2.1"
const sdkVersion = OptaveJavaScriptSDK.getSdkVersion(); // e.g., "3.3.1" (SDK implementation version)
const specVersion = OptaveJavaScriptSDK.getSpecVersion(); // Returns: "1.0.0" (AsyncAPI protocol version - static)
const schemaRef = OptaveJavaScriptSDK.getSchemaRef(); // e.g., "optave.message.v3"

// Constants
Expand Down
2 changes: 1 addition & 1 deletion sdks/javascript/dist/browser.mjs

Large diffs are not rendered by default.

104 changes: 55 additions & 49 deletions sdks/javascript/dist/browser.umd.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions sdks/javascript/dist/browser.umd.js.map

Large diffs are not rendered by default.

59 changes: 35 additions & 24 deletions sdks/javascript/dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,54 @@ module.exports = __toCommonJS(index_exports);

// generated/connection-config.ts
var DEFAULT_CONFIG = {
websocketUrl: "wss://{wsEnv}.oco.optave.tech/",
authUrl: "https://{authEnv}.oco.optave.tech/auth/oauth2",
// Base URL - SDK will append /token
supportedAuthTransports: ["subprotocol", "query", "oauth2"]
websocketUrl: "wss://{wsEnv}.{baseDomain}/",
authUrl: "https://{authEnv}.{baseDomain}/auth/oauth2",
supportedAuthTransports: ["subprotocol", "query"]
};
var OAUTH2_TOKEN_URL = DEFAULT_CONFIG.authUrl;

// runtime/core/index.ts
var createDefaultConfig = () => ({
websocketUrl: "wss://default.oco.optave.tech/",
authUrl: "https://default.oco.optave.tech/auth/oauth2/",
supportedAuthTransports: ["subprotocol", "query"],
OptaveTraceChatSessionId: void 0
});
var DEFAULT_CONFIG2 = createDefaultConfig();
var SERVER_ENVIRONMENTS = {
websocket: {
wsEnv: {
default: "default",
examples: ["default", "staging", "production"]
default: "ws-incubator",
examples: ["ws-incubator", "ws-sandbox", "ws-prod"]
},
baseDomain: {
default: "oco.optave.tech",
examples: ["oco.optave.tech"]
}
},
auth: {
authEnv: {
default: "default",
examples: ["default", "staging", "production"]
default: "incubator",
examples: ["incubator", "sandbox", "prod"]
},
baseDomain: {
default: "oco.optave.tech",
examples: ["oco.optave.tech"]
}
}
};
function buildWebSocketUrl(environment) {
const env = environment || "default";
return `wss://${env}.oco.optave.tech/`;
function buildWebSocketUrl(wsEnv = SERVER_ENVIRONMENTS.websocket.wsEnv?.default, baseDomain = SERVER_ENVIRONMENTS.websocket.baseDomain?.default) {
let url = DEFAULT_CONFIG.websocketUrl;
url = url.replace("{wsEnv}", wsEnv);
url = url.replace("{baseDomain}", baseDomain);
return url;
}
function buildAuthUrl(environment) {
const env = environment || "default";
return `https://${env}.oco.optave.tech/auth/oauth2/`;
function buildAuthUrl(authEnv = SERVER_ENVIRONMENTS.auth.authEnv?.default, baseDomain = SERVER_ENVIRONMENTS.auth.baseDomain?.default) {
let url = DEFAULT_CONFIG.authUrl;
url = url.replace("{authEnv}", authEnv);
url = url.replace("{baseDomain}", baseDomain);
return url;
}
var OAUTH2_TOKEN_URL = buildAuthUrl();

// runtime/core/index.ts
var createDefaultConfig = () => ({
websocketUrl: buildWebSocketUrl(),
authUrl: buildAuthUrl(),
supportedAuthTransports: ["subprotocol", "query"],
OptaveTraceChatSessionId: void 0
});
var DEFAULT_CONFIG2 = createDefaultConfig();
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
DEFAULT_CONFIG,
Expand Down
44 changes: 27 additions & 17 deletions sdks/javascript/dist/index.d.cts
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,46 @@ declare class OptaveJavaScriptSDK {
elevate(params: any): Promise<any>;
customerInteraction(params: any): Promise<any>;
interaction(params: any): Promise<any>;
assistant(params: any): Promise<any>;
reception(params: any): Promise<any>;
summarize(params: any): Promise<any>;
translate(params: any): Promise<any>;
recommend(params: any): Promise<any>;
insights(params: any): Promise<any>;
assistantAsync(params: any, opts?: any): Promise<any>;
disconnect(): void;
isConnected(): boolean;
on(event: string, listener: (...args: any[]) => void): this;
emit(event: string, ...args: any[]): boolean;
}

type AuthTransport = 'subprotocol' | 'query';
declare const SERVER_ENVIRONMENTS: {
websocket: {
wsEnv: {
default: string;
examples: string[];
};
baseDomain: {
default: string;
examples: string[];
};
};
auth: {
authEnv: {
default: string;
examples: string[];
};
baseDomain: {
default: string;
examples: string[];
};
};
};
declare function buildWebSocketUrl(wsEnv?: string, baseDomain?: string): string;
declare function buildAuthUrl(authEnv?: string, baseDomain?: string): string;
declare const OAUTH2_TOKEN_URL: string;

type AuthTransport = 'subprotocol' | 'query';
interface GeneratedClientConfig {
websocketUrl: string;
authUrl: string;
Expand All @@ -86,21 +112,5 @@ interface GeneratedClientConfig {
}
declare const createDefaultConfig: () => GeneratedClientConfig;
declare const DEFAULT_CONFIG: GeneratedClientConfig;
declare const SERVER_ENVIRONMENTS: {
readonly websocket: {
readonly wsEnv: {
readonly default: "default";
readonly examples: readonly ["default", "staging", "production"];
};
};
readonly auth: {
readonly authEnv: {
readonly default: "default";
readonly examples: readonly ["default", "staging", "production"];
};
};
};
declare function buildWebSocketUrl(environment?: string): string;
declare function buildAuthUrl(environment?: string): string;

export { type AuthCredentials, type AuthTokenResponse, type AuthTransport, DEFAULT_CONFIG, type GeneratedClientConfig, type Logger, type MessageEnvelope, OAUTH2_TOKEN_URL, OptaveJavaScriptSDK, type Opts, SERVER_ENVIRONMENTS, type SdkEvents, type WebSocketOptions, buildAuthUrl, buildWebSocketUrl, createDefaultConfig };
44 changes: 27 additions & 17 deletions sdks/javascript/dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,46 @@ declare class OptaveJavaScriptSDK {
elevate(params: any): Promise<any>;
customerInteraction(params: any): Promise<any>;
interaction(params: any): Promise<any>;
assistant(params: any): Promise<any>;
reception(params: any): Promise<any>;
summarize(params: any): Promise<any>;
translate(params: any): Promise<any>;
recommend(params: any): Promise<any>;
insights(params: any): Promise<any>;
assistantAsync(params: any, opts?: any): Promise<any>;
disconnect(): void;
isConnected(): boolean;
on(event: string, listener: (...args: any[]) => void): this;
emit(event: string, ...args: any[]): boolean;
}

type AuthTransport = 'subprotocol' | 'query';
declare const SERVER_ENVIRONMENTS: {
websocket: {
wsEnv: {
default: string;
examples: string[];
};
baseDomain: {
default: string;
examples: string[];
};
};
auth: {
authEnv: {
default: string;
examples: string[];
};
baseDomain: {
default: string;
examples: string[];
};
};
};
declare function buildWebSocketUrl(wsEnv?: string, baseDomain?: string): string;
declare function buildAuthUrl(authEnv?: string, baseDomain?: string): string;
declare const OAUTH2_TOKEN_URL: string;

type AuthTransport = 'subprotocol' | 'query';
interface GeneratedClientConfig {
websocketUrl: string;
authUrl: string;
Expand All @@ -86,21 +112,5 @@ interface GeneratedClientConfig {
}
declare const createDefaultConfig: () => GeneratedClientConfig;
declare const DEFAULT_CONFIG: GeneratedClientConfig;
declare const SERVER_ENVIRONMENTS: {
readonly websocket: {
readonly wsEnv: {
readonly default: "default";
readonly examples: readonly ["default", "staging", "production"];
};
};
readonly auth: {
readonly authEnv: {
readonly default: "default";
readonly examples: readonly ["default", "staging", "production"];
};
};
};
declare function buildWebSocketUrl(environment?: string): string;
declare function buildAuthUrl(environment?: string): string;

export { type AuthCredentials, type AuthTokenResponse, type AuthTransport, DEFAULT_CONFIG, type GeneratedClientConfig, type Logger, type MessageEnvelope, OAUTH2_TOKEN_URL, OptaveJavaScriptSDK, type Opts, SERVER_ENVIRONMENTS, type SdkEvents, type WebSocketOptions, buildAuthUrl, buildWebSocketUrl, createDefaultConfig };
Loading