@seekora-ai/search-sdk 1.0.0
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/README.md +213 -0
- package/cdn/.htaccess +37 -0
- package/cdn/README.md +130 -0
- package/cdn/_headers +25 -0
- package/cdn/example.html +299 -0
- package/cdn/seekora-sdk.js +4651 -0
- package/cdn/seekora-sdk.min.js +17 -0
- package/cdn/ui-sdk-integration-example.html +183 -0
- package/dist/cdn.d.ts +16 -0
- package/dist/cdn.js +26 -0
- package/dist/client.d.ts +401 -0
- package/dist/client.js +991 -0
- package/dist/config-loader.d.ts +43 -0
- package/dist/config-loader.js +147 -0
- package/dist/config.d.ts +22 -0
- package/dist/config.js +58 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +40 -0
- package/dist/logger.d.ts +61 -0
- package/dist/logger.js +172 -0
- package/dist/src/cdn.d.ts +16 -0
- package/dist/src/cdn.js +26 -0
- package/dist/src/client.d.ts +401 -0
- package/dist/src/client.js +991 -0
- package/dist/src/config-loader.d.ts +43 -0
- package/dist/src/config-loader.js +147 -0
- package/dist/src/config.d.ts +22 -0
- package/dist/src/config.js +58 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.js +40 -0
- package/dist/src/logger.d.ts +61 -0
- package/dist/src/logger.js +172 -0
- package/dist/src/utils.d.ts +20 -0
- package/dist/src/utils.js +73 -0
- package/dist/utils.d.ts +20 -0
- package/dist/utils.js +73 -0
- package/package.json +47 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Loader
|
|
3
|
+
*
|
|
4
|
+
* Loads SDK configuration from file or environment variables
|
|
5
|
+
*/
|
|
6
|
+
import type { SeekoraClientConfig } from './client';
|
|
7
|
+
import type { LogLevel } from './logger';
|
|
8
|
+
export interface FileConfig {
|
|
9
|
+
storeId?: string;
|
|
10
|
+
readSecret?: string;
|
|
11
|
+
writeSecret?: string;
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
environment?: 'local' | 'stage' | 'production';
|
|
14
|
+
timeout?: number;
|
|
15
|
+
logLevel?: LogLevel;
|
|
16
|
+
logger?: {
|
|
17
|
+
level?: LogLevel;
|
|
18
|
+
enableConsole?: boolean;
|
|
19
|
+
enableFile?: boolean;
|
|
20
|
+
filePath?: string;
|
|
21
|
+
format?: 'json' | 'text';
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Load configuration from file
|
|
26
|
+
* Note: File loading is only available in Node.js environment
|
|
27
|
+
* In browser, this will always return null
|
|
28
|
+
*/
|
|
29
|
+
export declare function loadConfigFromFile(filePath?: string): FileConfig | null;
|
|
30
|
+
/**
|
|
31
|
+
* Load configuration from environment variables
|
|
32
|
+
* Note: In browser, environment variables are not available via process.env
|
|
33
|
+
* Use window.SEEKORA_CONFIG or pass config directly to client
|
|
34
|
+
*/
|
|
35
|
+
export declare function loadConfigFromEnv(): Partial<FileConfig>;
|
|
36
|
+
/**
|
|
37
|
+
* Merge configurations (file config < env config < code config)
|
|
38
|
+
*/
|
|
39
|
+
export declare function mergeConfig(fileConfig: FileConfig | null, envConfig: Partial<FileConfig>, codeConfig: Partial<SeekoraClientConfig>): SeekoraClientConfig;
|
|
40
|
+
/**
|
|
41
|
+
* Load and merge all configuration sources
|
|
42
|
+
*/
|
|
43
|
+
export declare function loadConfig(codeConfig?: Partial<SeekoraClientConfig>): SeekoraClientConfig;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration Loader
|
|
4
|
+
*
|
|
5
|
+
* Loads SDK configuration from file or environment variables
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.loadConfigFromFile = loadConfigFromFile;
|
|
9
|
+
exports.loadConfigFromEnv = loadConfigFromEnv;
|
|
10
|
+
exports.mergeConfig = mergeConfig;
|
|
11
|
+
exports.loadConfig = loadConfig;
|
|
12
|
+
// Browser-safe imports - only import fs/path if in Node.js environment
|
|
13
|
+
let fs;
|
|
14
|
+
let path;
|
|
15
|
+
try {
|
|
16
|
+
// Only import in Node.js environment
|
|
17
|
+
if (typeof window === 'undefined' && typeof require !== 'undefined') {
|
|
18
|
+
fs = require('fs');
|
|
19
|
+
path = require('path');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
// Ignore - we're in browser environment
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Default config file paths (checked in order)
|
|
27
|
+
*/
|
|
28
|
+
function getDefaultConfigPaths() {
|
|
29
|
+
const paths = [
|
|
30
|
+
'.seekora.json',
|
|
31
|
+
'.seekora.yaml',
|
|
32
|
+
'.seekora.yml',
|
|
33
|
+
'seekora.config.json',
|
|
34
|
+
'seekora.config.yaml',
|
|
35
|
+
'seekora.config.yml',
|
|
36
|
+
];
|
|
37
|
+
// Only add home directory paths if we're in Node.js
|
|
38
|
+
if (path && typeof process !== 'undefined' && process.env) {
|
|
39
|
+
const home = process.env.HOME || process.env.USERPROFILE || '';
|
|
40
|
+
if (home) {
|
|
41
|
+
paths.push(path.join(home, '.seekora.json'), path.join(home, '.seekora.yaml'));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return paths;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Load configuration from file
|
|
48
|
+
* Note: File loading is only available in Node.js environment
|
|
49
|
+
* In browser, this will always return null
|
|
50
|
+
*/
|
|
51
|
+
function loadConfigFromFile(filePath) {
|
|
52
|
+
// File system access is not available in browser
|
|
53
|
+
if (!fs || typeof window !== 'undefined') {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const pathsToCheck = filePath
|
|
57
|
+
? [filePath]
|
|
58
|
+
: getDefaultConfigPaths();
|
|
59
|
+
for (const configPath of pathsToCheck) {
|
|
60
|
+
if (!configPath)
|
|
61
|
+
continue;
|
|
62
|
+
try {
|
|
63
|
+
// Check if file exists
|
|
64
|
+
if (!fs.existsSync(configPath)) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const content = fs.readFileSync(configPath, 'utf-8');
|
|
68
|
+
let config;
|
|
69
|
+
// Parse based on file extension
|
|
70
|
+
if (configPath.endsWith('.yaml') || configPath.endsWith('.yml')) {
|
|
71
|
+
// Try to parse YAML (would need yaml package)
|
|
72
|
+
// For now, fallback to JSON
|
|
73
|
+
try {
|
|
74
|
+
config = JSON.parse(content);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// If JSON parse fails, try to use a simple YAML parser
|
|
78
|
+
// For production, use 'yaml' or 'js-yaml' package
|
|
79
|
+
throw new Error('YAML parsing not fully supported. Use JSON or install yaml package.');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
config = JSON.parse(content);
|
|
84
|
+
}
|
|
85
|
+
return config;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
// Continue to next file if this one fails
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Load configuration from environment variables
|
|
96
|
+
* Note: In browser, environment variables are not available via process.env
|
|
97
|
+
* Use window.SEEKORA_CONFIG or pass config directly to client
|
|
98
|
+
*/
|
|
99
|
+
function loadConfigFromEnv() {
|
|
100
|
+
// In browser, try to get config from window object
|
|
101
|
+
if (typeof window !== 'undefined' && window.SEEKORA_CONFIG) {
|
|
102
|
+
return window.SEEKORA_CONFIG;
|
|
103
|
+
}
|
|
104
|
+
// In Node.js, use process.env
|
|
105
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
106
|
+
return {
|
|
107
|
+
storeId: process.env.SEEKORA_STORE_ID,
|
|
108
|
+
readSecret: process.env.SEEKORA_READ_SECRET,
|
|
109
|
+
writeSecret: process.env.SEEKORA_WRITE_SECRET,
|
|
110
|
+
baseUrl: process.env.SEEKORA_BASE_URL,
|
|
111
|
+
environment: process.env.SEEKORA_ENV,
|
|
112
|
+
timeout: process.env.SEEKORA_TIMEOUT ? parseInt(process.env.SEEKORA_TIMEOUT, 10) : undefined,
|
|
113
|
+
logLevel: process.env.SEEKORA_LOG_LEVEL,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return {};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Merge configurations (file config < env config < code config)
|
|
120
|
+
*/
|
|
121
|
+
function mergeConfig(fileConfig, envConfig, codeConfig) {
|
|
122
|
+
const merged = {};
|
|
123
|
+
// Start with file config
|
|
124
|
+
if (fileConfig) {
|
|
125
|
+
Object.assign(merged, fileConfig);
|
|
126
|
+
}
|
|
127
|
+
// Override with env config
|
|
128
|
+
Object.assign(merged, envConfig);
|
|
129
|
+
// Override with code config (highest priority)
|
|
130
|
+
Object.assign(merged, codeConfig);
|
|
131
|
+
// Validate required fields
|
|
132
|
+
if (!merged.storeId) {
|
|
133
|
+
throw new Error('storeId is required. Provide it in config file, environment variable, or code.');
|
|
134
|
+
}
|
|
135
|
+
if (!merged.readSecret) {
|
|
136
|
+
throw new Error('readSecret is required. Provide it in config file, environment variable, or code.');
|
|
137
|
+
}
|
|
138
|
+
return merged;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Load and merge all configuration sources
|
|
142
|
+
*/
|
|
143
|
+
function loadConfig(codeConfig = {}) {
|
|
144
|
+
const fileConfig = loadConfigFromFile(codeConfig.configFile);
|
|
145
|
+
const envConfig = loadConfigFromEnv();
|
|
146
|
+
return mergeConfig(fileConfig, envConfig, codeConfig);
|
|
147
|
+
}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seekora SDK Configuration
|
|
3
|
+
*
|
|
4
|
+
* Environment-based configuration for different deployment targets
|
|
5
|
+
*/
|
|
6
|
+
export type SeekoraEnvironment = 'local' | 'stage' | 'production';
|
|
7
|
+
export interface EnvironmentConfig {
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
name: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Environment configurations
|
|
13
|
+
*/
|
|
14
|
+
export declare const ENVIRONMENTS: Record<SeekoraEnvironment, EnvironmentConfig>;
|
|
15
|
+
/**
|
|
16
|
+
* Get base URL for environment
|
|
17
|
+
*/
|
|
18
|
+
export declare function getBaseUrl(environment?: SeekoraEnvironment, customBaseUrl?: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Get current environment from config or env var
|
|
21
|
+
*/
|
|
22
|
+
export declare function getEnvironment(environment?: SeekoraEnvironment): SeekoraEnvironment;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Seekora SDK Configuration
|
|
4
|
+
*
|
|
5
|
+
* Environment-based configuration for different deployment targets
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.ENVIRONMENTS = void 0;
|
|
9
|
+
exports.getBaseUrl = getBaseUrl;
|
|
10
|
+
exports.getEnvironment = getEnvironment;
|
|
11
|
+
/**
|
|
12
|
+
* Environment configurations
|
|
13
|
+
*/
|
|
14
|
+
exports.ENVIRONMENTS = {
|
|
15
|
+
local: {
|
|
16
|
+
baseUrl: 'http://localhost:3000',
|
|
17
|
+
name: 'Local Development',
|
|
18
|
+
},
|
|
19
|
+
stage: {
|
|
20
|
+
baseUrl: 'https://stage-api.seekora.ai/api',
|
|
21
|
+
name: 'Staging',
|
|
22
|
+
},
|
|
23
|
+
production: {
|
|
24
|
+
baseUrl: 'https://api.seekora.com/api',
|
|
25
|
+
name: 'Production',
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Get base URL for environment
|
|
30
|
+
*/
|
|
31
|
+
function getBaseUrl(environment, customBaseUrl) {
|
|
32
|
+
if (customBaseUrl) {
|
|
33
|
+
return customBaseUrl;
|
|
34
|
+
}
|
|
35
|
+
// Check environment variable first (Node.js) or window variable (browser)
|
|
36
|
+
let envFromVar;
|
|
37
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
38
|
+
envFromVar = process.env.SEEKORA_ENV;
|
|
39
|
+
}
|
|
40
|
+
else if (typeof window !== 'undefined' && window.SEEKORA_ENV) {
|
|
41
|
+
envFromVar = window.SEEKORA_ENV;
|
|
42
|
+
}
|
|
43
|
+
const env = environment || envFromVar || 'stage';
|
|
44
|
+
return exports.ENVIRONMENTS[env]?.baseUrl || exports.ENVIRONMENTS.stage.baseUrl;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get current environment from config or env var
|
|
48
|
+
*/
|
|
49
|
+
function getEnvironment(environment) {
|
|
50
|
+
let envFromVar;
|
|
51
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
52
|
+
envFromVar = process.env.SEEKORA_ENV;
|
|
53
|
+
}
|
|
54
|
+
else if (typeof window !== 'undefined' && window.SEEKORA_ENV) {
|
|
55
|
+
envFromVar = window.SEEKORA_ENV;
|
|
56
|
+
}
|
|
57
|
+
return environment || envFromVar || 'stage';
|
|
58
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seekora Search SDK
|
|
3
|
+
*
|
|
4
|
+
* Main entry point for the SDK
|
|
5
|
+
*/
|
|
6
|
+
export { SeekoraClient, type SeekoraClientConfig, type SearchOptions, type SearchResponse, type SearchContext, type ExtendedEventPayload, type QuerySuggestionsFullResponse } from './client';
|
|
7
|
+
export type { SeekoraEnvironment } from './config';
|
|
8
|
+
export { ENVIRONMENTS, getBaseUrl, getEnvironment, type EnvironmentConfig } from './config';
|
|
9
|
+
export { Logger, createLogger, getLogLevelFromEnv, type LogLevel, type LoggerConfig } from './logger';
|
|
10
|
+
export { loadConfig, loadConfigFromFile, loadConfigFromEnv, type FileConfig } from './config-loader';
|
|
11
|
+
export * from '../generated';
|
|
12
|
+
export { SeekoraClient as default } from './client';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Seekora Search SDK
|
|
4
|
+
*
|
|
5
|
+
* Main entry point for the SDK
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.default = exports.loadConfigFromEnv = exports.loadConfigFromFile = exports.loadConfig = exports.getLogLevelFromEnv = exports.createLogger = exports.Logger = exports.getEnvironment = exports.getBaseUrl = exports.ENVIRONMENTS = exports.SeekoraClient = void 0;
|
|
23
|
+
var client_1 = require("./client");
|
|
24
|
+
Object.defineProperty(exports, "SeekoraClient", { enumerable: true, get: function () { return client_1.SeekoraClient; } });
|
|
25
|
+
var config_1 = require("./config");
|
|
26
|
+
Object.defineProperty(exports, "ENVIRONMENTS", { enumerable: true, get: function () { return config_1.ENVIRONMENTS; } });
|
|
27
|
+
Object.defineProperty(exports, "getBaseUrl", { enumerable: true, get: function () { return config_1.getBaseUrl; } });
|
|
28
|
+
Object.defineProperty(exports, "getEnvironment", { enumerable: true, get: function () { return config_1.getEnvironment; } });
|
|
29
|
+
var logger_1 = require("./logger");
|
|
30
|
+
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
|
|
31
|
+
Object.defineProperty(exports, "createLogger", { enumerable: true, get: function () { return logger_1.createLogger; } });
|
|
32
|
+
Object.defineProperty(exports, "getLogLevelFromEnv", { enumerable: true, get: function () { return logger_1.getLogLevelFromEnv; } });
|
|
33
|
+
var config_loader_1 = require("./config-loader");
|
|
34
|
+
Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return config_loader_1.loadConfig; } });
|
|
35
|
+
Object.defineProperty(exports, "loadConfigFromFile", { enumerable: true, get: function () { return config_loader_1.loadConfigFromFile; } });
|
|
36
|
+
Object.defineProperty(exports, "loadConfigFromEnv", { enumerable: true, get: function () { return config_loader_1.loadConfigFromEnv; } });
|
|
37
|
+
__exportStar(require("../generated"), exports);
|
|
38
|
+
// Default export
|
|
39
|
+
var client_2 = require("./client");
|
|
40
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return client_2.SeekoraClient; } });
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seekora SDK Logger
|
|
3
|
+
*
|
|
4
|
+
* Provides structured logging with configurable levels:
|
|
5
|
+
* - VERBOSE: Detailed debugging information
|
|
6
|
+
* - INFO: General informational messages (default)
|
|
7
|
+
* - WARN: Warning messages
|
|
8
|
+
* - ERROR: Error messages
|
|
9
|
+
* - SILENT: No logging
|
|
10
|
+
*
|
|
11
|
+
* Configurable via SEEKORA_LOG_LEVEL environment variable
|
|
12
|
+
*/
|
|
13
|
+
export type LogLevel = 'verbose' | 'info' | 'warn' | 'error' | 'silent';
|
|
14
|
+
export interface LoggerConfig {
|
|
15
|
+
level?: LogLevel;
|
|
16
|
+
enableConsole?: boolean;
|
|
17
|
+
enableFile?: boolean;
|
|
18
|
+
filePath?: string;
|
|
19
|
+
format?: 'json' | 'text';
|
|
20
|
+
enableTimestamp?: boolean;
|
|
21
|
+
prefix?: string;
|
|
22
|
+
enablePrefix?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get log level from environment variable or default
|
|
26
|
+
*/
|
|
27
|
+
export declare function getLogLevelFromEnv(): LogLevel;
|
|
28
|
+
/**
|
|
29
|
+
* Logger implementation with configurable levels and formatting
|
|
30
|
+
*/
|
|
31
|
+
export declare class Logger {
|
|
32
|
+
private level;
|
|
33
|
+
private levelValue;
|
|
34
|
+
private enableConsole;
|
|
35
|
+
private enableFile;
|
|
36
|
+
private filePath?;
|
|
37
|
+
private format;
|
|
38
|
+
private enableTimestamp;
|
|
39
|
+
private prefix;
|
|
40
|
+
private enablePrefix;
|
|
41
|
+
constructor(config?: LoggerConfig);
|
|
42
|
+
private shouldLog;
|
|
43
|
+
private formatMessage;
|
|
44
|
+
private write;
|
|
45
|
+
verbose(message: string, meta?: any): void;
|
|
46
|
+
info(message: string, meta?: any): void;
|
|
47
|
+
warn(message: string, meta?: any): void;
|
|
48
|
+
error(message: string, meta?: any): void;
|
|
49
|
+
debug(message: string, meta?: any): void;
|
|
50
|
+
fatal(message: string, meta?: any): void;
|
|
51
|
+
setLevel(level: LogLevel): void;
|
|
52
|
+
getLevel(): LogLevel;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create a logger instance
|
|
56
|
+
*/
|
|
57
|
+
export declare function createLogger(config?: LoggerConfig): Logger;
|
|
58
|
+
/**
|
|
59
|
+
* Default logger instance
|
|
60
|
+
*/
|
|
61
|
+
export declare const defaultLogger: Logger;
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Seekora SDK Logger
|
|
4
|
+
*
|
|
5
|
+
* Provides structured logging with configurable levels:
|
|
6
|
+
* - VERBOSE: Detailed debugging information
|
|
7
|
+
* - INFO: General informational messages (default)
|
|
8
|
+
* - WARN: Warning messages
|
|
9
|
+
* - ERROR: Error messages
|
|
10
|
+
* - SILENT: No logging
|
|
11
|
+
*
|
|
12
|
+
* Configurable via SEEKORA_LOG_LEVEL environment variable
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.defaultLogger = exports.Logger = void 0;
|
|
16
|
+
exports.getLogLevelFromEnv = getLogLevelFromEnv;
|
|
17
|
+
exports.createLogger = createLogger;
|
|
18
|
+
const LOG_LEVELS = {
|
|
19
|
+
verbose: 0,
|
|
20
|
+
info: 1,
|
|
21
|
+
warn: 2,
|
|
22
|
+
error: 3,
|
|
23
|
+
silent: 4,
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Get log level from environment variable or default
|
|
27
|
+
*/
|
|
28
|
+
function getLogLevelFromEnv() {
|
|
29
|
+
let envLevel;
|
|
30
|
+
// Try to get from process.env (Node.js) or window (browser)
|
|
31
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
32
|
+
envLevel = process.env.SEEKORA_LOG_LEVEL?.toLowerCase();
|
|
33
|
+
}
|
|
34
|
+
else if (typeof window !== 'undefined' && window.SEEKORA_LOG_LEVEL) {
|
|
35
|
+
envLevel = String(window.SEEKORA_LOG_LEVEL).toLowerCase();
|
|
36
|
+
}
|
|
37
|
+
// Support both old and new level names
|
|
38
|
+
const levelMap = {
|
|
39
|
+
'verbose': 'verbose',
|
|
40
|
+
'info': 'info',
|
|
41
|
+
'warn': 'warn',
|
|
42
|
+
'warning': 'warn',
|
|
43
|
+
'error': 'error',
|
|
44
|
+
'silent': 'silent',
|
|
45
|
+
// Legacy support
|
|
46
|
+
'debug': 'verbose',
|
|
47
|
+
'fatal': 'error',
|
|
48
|
+
};
|
|
49
|
+
if (envLevel && levelMap[envLevel]) {
|
|
50
|
+
return levelMap[envLevel];
|
|
51
|
+
}
|
|
52
|
+
// Default: INFO in production, VERBOSE in debug mode
|
|
53
|
+
const nodeEnv = typeof process !== 'undefined' && process.env
|
|
54
|
+
? process.env.NODE_ENV
|
|
55
|
+
: undefined;
|
|
56
|
+
const debug = typeof process !== 'undefined' && process.env
|
|
57
|
+
? process.env.DEBUG
|
|
58
|
+
: undefined;
|
|
59
|
+
if (nodeEnv === 'development' || debug) {
|
|
60
|
+
return 'verbose';
|
|
61
|
+
}
|
|
62
|
+
return 'info';
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Logger implementation with configurable levels and formatting
|
|
66
|
+
*/
|
|
67
|
+
class Logger {
|
|
68
|
+
constructor(config = {}) {
|
|
69
|
+
this.level = config.level || getLogLevelFromEnv();
|
|
70
|
+
this.levelValue = LOG_LEVELS[this.level];
|
|
71
|
+
this.enableConsole = config.enableConsole !== false;
|
|
72
|
+
this.enableFile = config.enableFile || false;
|
|
73
|
+
this.filePath = config.filePath;
|
|
74
|
+
this.format = config.format || 'text';
|
|
75
|
+
this.enableTimestamp = config.enableTimestamp !== false;
|
|
76
|
+
this.prefix = config.prefix || '[Seekora SDK]';
|
|
77
|
+
this.enablePrefix = config.enablePrefix !== false;
|
|
78
|
+
}
|
|
79
|
+
shouldLog(level) {
|
|
80
|
+
if (this.level === 'silent') {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return LOG_LEVELS[level] >= this.levelValue;
|
|
84
|
+
}
|
|
85
|
+
formatMessage(level, message, meta) {
|
|
86
|
+
const parts = [];
|
|
87
|
+
// Add timestamp if enabled
|
|
88
|
+
if (this.enableTimestamp) {
|
|
89
|
+
const timestamp = new Date().toISOString();
|
|
90
|
+
parts.push(`[${timestamp}]`);
|
|
91
|
+
}
|
|
92
|
+
// Add prefix if enabled
|
|
93
|
+
if (this.enablePrefix && this.prefix) {
|
|
94
|
+
parts.push(this.prefix);
|
|
95
|
+
}
|
|
96
|
+
// Add log level
|
|
97
|
+
parts.push(`[${level.toUpperCase()}]`);
|
|
98
|
+
// Add message
|
|
99
|
+
parts.push(message);
|
|
100
|
+
// Add metadata if present
|
|
101
|
+
if (meta && Object.keys(meta).length > 0) {
|
|
102
|
+
if (this.format === 'json') {
|
|
103
|
+
return JSON.stringify({
|
|
104
|
+
timestamp: this.enableTimestamp ? new Date().toISOString() : undefined,
|
|
105
|
+
level,
|
|
106
|
+
message,
|
|
107
|
+
...meta,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
parts.push(JSON.stringify(meta, null, 2));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return parts.join(' ');
|
|
115
|
+
}
|
|
116
|
+
write(level, message, meta) {
|
|
117
|
+
if (!this.shouldLog(level)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const formatted = this.formatMessage(level, message, meta);
|
|
121
|
+
if (this.enableConsole) {
|
|
122
|
+
const consoleMethod = level === 'error'
|
|
123
|
+
? console.error
|
|
124
|
+
: level === 'warn'
|
|
125
|
+
? console.warn
|
|
126
|
+
: console.log;
|
|
127
|
+
consoleMethod(formatted);
|
|
128
|
+
}
|
|
129
|
+
if (this.enableFile && this.filePath) {
|
|
130
|
+
// File logging would require fs module
|
|
131
|
+
// In production, you might want to use winston or similar
|
|
132
|
+
// For now, we'll just log to console
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
verbose(message, meta) {
|
|
136
|
+
this.write('verbose', message, meta);
|
|
137
|
+
}
|
|
138
|
+
info(message, meta) {
|
|
139
|
+
this.write('info', message, meta);
|
|
140
|
+
}
|
|
141
|
+
warn(message, meta) {
|
|
142
|
+
this.write('warn', message, meta);
|
|
143
|
+
}
|
|
144
|
+
error(message, meta) {
|
|
145
|
+
this.write('error', message, meta);
|
|
146
|
+
}
|
|
147
|
+
// Legacy support methods
|
|
148
|
+
debug(message, meta) {
|
|
149
|
+
this.verbose(message, meta);
|
|
150
|
+
}
|
|
151
|
+
fatal(message, meta) {
|
|
152
|
+
this.error(message, meta);
|
|
153
|
+
}
|
|
154
|
+
setLevel(level) {
|
|
155
|
+
this.level = level;
|
|
156
|
+
this.levelValue = LOG_LEVELS[level];
|
|
157
|
+
}
|
|
158
|
+
getLevel() {
|
|
159
|
+
return this.level;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.Logger = Logger;
|
|
163
|
+
/**
|
|
164
|
+
* Create a logger instance
|
|
165
|
+
*/
|
|
166
|
+
function createLogger(config) {
|
|
167
|
+
return new Logger(config);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Default logger instance
|
|
171
|
+
*/
|
|
172
|
+
exports.defaultLogger = createLogger();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CDN Entry Point for Seekora Search SDK
|
|
3
|
+
*
|
|
4
|
+
* This file is used to create a browser-compatible bundle that can be
|
|
5
|
+
* loaded via a <script> tag and accessed via a global variable.
|
|
6
|
+
*/
|
|
7
|
+
import { SeekoraClient } from './client';
|
|
8
|
+
import { ENVIRONMENTS, getBaseUrl, getEnvironment } from './config';
|
|
9
|
+
import { Logger, createLogger, getLogLevelFromEnv } from './logger';
|
|
10
|
+
import { loadConfig, loadConfigFromFile, loadConfigFromEnv } from './config-loader';
|
|
11
|
+
export type { SeekoraClientConfig, SearchOptions, SearchResponse, SearchContext, ExtendedEventPayload } from './client';
|
|
12
|
+
export type { SeekoraEnvironment, EnvironmentConfig } from './config';
|
|
13
|
+
export type { LogLevel, LoggerConfig } from './logger';
|
|
14
|
+
export type { FileConfig } from './config-loader';
|
|
15
|
+
export { SeekoraClient, ENVIRONMENTS, getBaseUrl, getEnvironment, Logger, createLogger, getLogLevelFromEnv, loadConfig, loadConfigFromFile, loadConfigFromEnv, };
|
|
16
|
+
export default SeekoraClient;
|
package/dist/src/cdn.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CDN Entry Point for Seekora Search SDK
|
|
4
|
+
*
|
|
5
|
+
* This file is used to create a browser-compatible bundle that can be
|
|
6
|
+
* loaded via a <script> tag and accessed via a global variable.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.loadConfigFromEnv = exports.loadConfigFromFile = exports.loadConfig = exports.getLogLevelFromEnv = exports.createLogger = exports.Logger = exports.getEnvironment = exports.getBaseUrl = exports.ENVIRONMENTS = exports.SeekoraClient = void 0;
|
|
10
|
+
// Import all exports
|
|
11
|
+
const client_1 = require("./client");
|
|
12
|
+
Object.defineProperty(exports, "SeekoraClient", { enumerable: true, get: function () { return client_1.SeekoraClient; } });
|
|
13
|
+
const config_1 = require("./config");
|
|
14
|
+
Object.defineProperty(exports, "ENVIRONMENTS", { enumerable: true, get: function () { return config_1.ENVIRONMENTS; } });
|
|
15
|
+
Object.defineProperty(exports, "getBaseUrl", { enumerable: true, get: function () { return config_1.getBaseUrl; } });
|
|
16
|
+
Object.defineProperty(exports, "getEnvironment", { enumerable: true, get: function () { return config_1.getEnvironment; } });
|
|
17
|
+
const logger_1 = require("./logger");
|
|
18
|
+
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
|
|
19
|
+
Object.defineProperty(exports, "createLogger", { enumerable: true, get: function () { return logger_1.createLogger; } });
|
|
20
|
+
Object.defineProperty(exports, "getLogLevelFromEnv", { enumerable: true, get: function () { return logger_1.getLogLevelFromEnv; } });
|
|
21
|
+
const config_loader_1 = require("./config-loader");
|
|
22
|
+
Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return config_loader_1.loadConfig; } });
|
|
23
|
+
Object.defineProperty(exports, "loadConfigFromFile", { enumerable: true, get: function () { return config_loader_1.loadConfigFromFile; } });
|
|
24
|
+
Object.defineProperty(exports, "loadConfigFromEnv", { enumerable: true, get: function () { return config_loader_1.loadConfigFromEnv; } });
|
|
25
|
+
// Default export
|
|
26
|
+
exports.default = client_1.SeekoraClient;
|