@sogni-ai/sogni-client-wrapper 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/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = exports.formatDuration = exports.formatBytes = exports.retry = exports.sleep = exports.validateProjectConfig = exports.validateClientConfig = exports.generateAppId = exports.SogniNetworkError = exports.SogniModelNotFoundError = exports.SogniConfigurationError = exports.SogniValidationError = exports.SogniBalanceError = exports.SogniTimeoutError = exports.SogniProjectError = exports.SogniAuthenticationError = exports.SogniConnectionError = exports.SogniError = exports.ClientEvent = exports.SogniClientWrapper = void 0;
4
+ var SogniClientWrapper_1 = require("./client/SogniClientWrapper");
5
+ Object.defineProperty(exports, "SogniClientWrapper", { enumerable: true, get: function () { return SogniClientWrapper_1.SogniClientWrapper; } });
6
+ var types_1 = require("./types");
7
+ Object.defineProperty(exports, "ClientEvent", { enumerable: true, get: function () { return types_1.ClientEvent; } });
8
+ var errors_1 = require("./utils/errors");
9
+ Object.defineProperty(exports, "SogniError", { enumerable: true, get: function () { return errors_1.SogniError; } });
10
+ Object.defineProperty(exports, "SogniConnectionError", { enumerable: true, get: function () { return errors_1.SogniConnectionError; } });
11
+ Object.defineProperty(exports, "SogniAuthenticationError", { enumerable: true, get: function () { return errors_1.SogniAuthenticationError; } });
12
+ Object.defineProperty(exports, "SogniProjectError", { enumerable: true, get: function () { return errors_1.SogniProjectError; } });
13
+ Object.defineProperty(exports, "SogniTimeoutError", { enumerable: true, get: function () { return errors_1.SogniTimeoutError; } });
14
+ Object.defineProperty(exports, "SogniBalanceError", { enumerable: true, get: function () { return errors_1.SogniBalanceError; } });
15
+ Object.defineProperty(exports, "SogniValidationError", { enumerable: true, get: function () { return errors_1.SogniValidationError; } });
16
+ Object.defineProperty(exports, "SogniConfigurationError", { enumerable: true, get: function () { return errors_1.SogniConfigurationError; } });
17
+ Object.defineProperty(exports, "SogniModelNotFoundError", { enumerable: true, get: function () { return errors_1.SogniModelNotFoundError; } });
18
+ Object.defineProperty(exports, "SogniNetworkError", { enumerable: true, get: function () { return errors_1.SogniNetworkError; } });
19
+ var helpers_1 = require("./utils/helpers");
20
+ Object.defineProperty(exports, "generateAppId", { enumerable: true, get: function () { return helpers_1.generateAppId; } });
21
+ Object.defineProperty(exports, "validateClientConfig", { enumerable: true, get: function () { return helpers_1.validateClientConfig; } });
22
+ Object.defineProperty(exports, "validateProjectConfig", { enumerable: true, get: function () { return helpers_1.validateProjectConfig; } });
23
+ Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return helpers_1.sleep; } });
24
+ Object.defineProperty(exports, "retry", { enumerable: true, get: function () { return helpers_1.retry; } });
25
+ Object.defineProperty(exports, "formatBytes", { enumerable: true, get: function () { return helpers_1.formatBytes; } });
26
+ Object.defineProperty(exports, "formatDuration", { enumerable: true, get: function () { return helpers_1.formatDuration; } });
27
+ var SogniClientWrapper_2 = require("./client/SogniClientWrapper");
28
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return SogniClientWrapper_2.SogniClientWrapper; } });
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAMA,kEAAiE;AAAxD,wHAAA,kBAAkB,OAAA;AA+B3B,iCAAsC;AAA7B,oGAAA,WAAW,OAAA;AAGpB,yCAWwB;AAVtB,oGAAA,UAAU,OAAA;AACV,8GAAA,oBAAoB,OAAA;AACpB,kHAAA,wBAAwB,OAAA;AACxB,2GAAA,iBAAiB,OAAA;AACjB,2GAAA,iBAAiB,OAAA;AACjB,2GAAA,iBAAiB,OAAA;AACjB,8GAAA,oBAAoB,OAAA;AACpB,iHAAA,uBAAuB,OAAA;AACvB,iHAAA,uBAAuB,OAAA;AACvB,2GAAA,iBAAiB,OAAA;AAInB,2CAQyB;AAPvB,wGAAA,aAAa,OAAA;AACb,+GAAA,oBAAoB,OAAA;AACpB,gHAAA,qBAAqB,OAAA;AACrB,gGAAA,KAAK,OAAA;AACL,gGAAA,KAAK,OAAA;AACL,sGAAA,WAAW,OAAA;AACX,yGAAA,cAAc,OAAA;AAIhB,kEAA4E;AAAnE,6GAAA,kBAAkB,OAAW"}
@@ -0,0 +1,120 @@
1
+ import type { Project, Job, AvailableModel, ProjectParams as SogniProjectParams, SupernetType, TokenType, OutputFormat, Scheduler, TimeStepSpacing } from '@sogni-ai/sogni-client';
2
+ import type { ControlNetParams, ControlNetName, ControlNetMode } from '@sogni-ai/sogni-client/dist/Projects/types/ControlNetParams';
3
+ export type { Project, Job, AvailableModel, SupernetType, TokenType, OutputFormat, Scheduler, TimeStepSpacing, ControlNetParams, ControlNetName, ControlNetMode, };
4
+ export interface SogniClientConfig {
5
+ username: string;
6
+ password: string;
7
+ appId?: string;
8
+ network?: SupernetType;
9
+ autoConnect?: boolean;
10
+ reconnect?: boolean;
11
+ reconnectInterval?: number;
12
+ timeout?: number;
13
+ debug?: boolean;
14
+ }
15
+ export interface ProjectConfig extends Omit<SogniProjectParams, 'modelId' | 'negativePrompt' | 'stylePrompt'> {
16
+ modelId: string;
17
+ negativePrompt?: string;
18
+ stylePrompt?: string;
19
+ waitForCompletion?: boolean;
20
+ timeout?: number;
21
+ onProgress?: (progress: ProjectProgress) => void;
22
+ onJobCompleted?: (job: Job) => void;
23
+ onJobFailed?: (job: Job) => void;
24
+ }
25
+ export interface ProjectResult {
26
+ project: Project;
27
+ imageUrls?: string[];
28
+ jobs?: Job[];
29
+ completed: boolean;
30
+ error?: ErrorData;
31
+ }
32
+ export interface ProjectProgress {
33
+ projectId: string;
34
+ percentage: number;
35
+ completedJobs: number;
36
+ totalJobs: number;
37
+ estimatedTimeRemaining?: number;
38
+ }
39
+ export interface ErrorData {
40
+ code: string;
41
+ message: string;
42
+ statusCode?: number;
43
+ details?: any;
44
+ originalError?: Error;
45
+ }
46
+ export declare enum ConnectionStatus {
47
+ DISCONNECTED = "disconnected",
48
+ CONNECTING = "connecting",
49
+ CONNECTED = "connected",
50
+ RECONNECTING = "reconnecting",
51
+ FAILED = "failed"
52
+ }
53
+ export interface ConnectionState {
54
+ status: ConnectionStatus;
55
+ isConnected: boolean;
56
+ isConnecting: boolean;
57
+ reconnectAttempts: number;
58
+ lastError?: ErrorData;
59
+ connectedAt?: Date;
60
+ }
61
+ export interface SizePreset {
62
+ id: string;
63
+ label: string;
64
+ width: number;
65
+ height: number;
66
+ ratio: string;
67
+ aspect: string;
68
+ }
69
+ export interface ModelInfo extends AvailableModel {
70
+ isAvailable: boolean;
71
+ recommendedSettings?: {
72
+ steps?: number;
73
+ guidance?: number;
74
+ scheduler?: Scheduler;
75
+ };
76
+ }
77
+ export interface BalanceInfo {
78
+ sogni: number;
79
+ spark: number;
80
+ usdEquivalent?: number;
81
+ lastUpdated: Date;
82
+ }
83
+ export declare const ClientEvent: {
84
+ readonly CONNECTED: "connected";
85
+ readonly DISCONNECTED: "disconnected";
86
+ readonly RECONNECTING: "reconnecting";
87
+ readonly RECONNECTED: "reconnected";
88
+ readonly ERROR: "error";
89
+ readonly MODELS_UPDATED: "modelsUpdated";
90
+ readonly BALANCE_UPDATED: "balanceUpdated";
91
+ readonly PROJECT_CREATED: "projectCreated";
92
+ readonly PROJECT_PROGRESS: "projectProgress";
93
+ readonly PROJECT_COMPLETED: "projectCompleted";
94
+ readonly PROJECT_FAILED: "projectFailed";
95
+ };
96
+ export type ClientEvent = typeof ClientEvent[keyof typeof ClientEvent];
97
+ export interface ClientEventCallbacks {
98
+ [ClientEvent.CONNECTED]: () => void;
99
+ [ClientEvent.DISCONNECTED]: () => void;
100
+ [ClientEvent.RECONNECTING]: (attempt: number) => void;
101
+ [ClientEvent.RECONNECTED]: () => void;
102
+ [ClientEvent.ERROR]: (error: ErrorData) => void;
103
+ [ClientEvent.MODELS_UPDATED]: (models: ModelInfo[]) => void;
104
+ [ClientEvent.BALANCE_UPDATED]: (balance: BalanceInfo) => void;
105
+ [ClientEvent.PROJECT_CREATED]: (project: Project) => void;
106
+ [ClientEvent.PROJECT_PROGRESS]: (progress: ProjectProgress) => void;
107
+ [ClientEvent.PROJECT_COMPLETED]: (result: ProjectResult) => void;
108
+ [ClientEvent.PROJECT_FAILED]: (error: ErrorData) => void;
109
+ }
110
+ export interface GetModelsOptions {
111
+ network?: SupernetType;
112
+ minWorkers?: number;
113
+ sortByWorkers?: boolean;
114
+ }
115
+ export interface CreateProjectOptions extends ProjectConfig {
116
+ retry?: boolean;
117
+ retryAttempts?: number;
118
+ retryDelay?: number;
119
+ }
120
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,OAAO,EACP,GAAG,EACH,cAAc,EACd,aAAa,IAAI,kBAAkB,EACnC,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,SAAS,EACT,eAAe,EAChB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACd,cAAc,EACf,MAAM,6DAA6D,CAAC;AAGrE,YAAY,EACV,OAAO,EACP,GAAG,EACH,cAAc,EACd,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,cAAc,GACf,CAAC;AAKF,MAAM,WAAW,iBAAiB;IAEhC,QAAQ,EAAE,MAAM,CAAC;IAGjB,QAAQ,EAAE,MAAM,CAAC;IAGjB,KAAK,CAAC,EAAE,MAAM,CAAC;IAGf,OAAO,CAAC,EAAE,YAAY,CAAC;IAGvB,WAAW,CAAC,EAAE,OAAO,CAAC;IAGtB,SAAS,CAAC,EAAE,OAAO,CAAC;IAGpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAG3B,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,KAAK,CAAC,EAAE,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C,EAAE,MAAM,IAAI,CAAC;IACtC,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IAChD,CAAC,WAAW,CAAC,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,IAAI,CAAC;IAC5D,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;IAC9D,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAC1D,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAC;IACpE,CAAC,WAAW,CAAC,iBAAiB,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;IACjE,CAAC,WAAW,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;CAC1D;AAKD,MAAM,WAAW,gBAAgB;IAE/B,OAAO,CAAC,EAAE,YAAY,CAAC;IAGvB,UAAU,CAAC,EAAE,MAAM,CAAC;IAGpB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAKD,MAAM,WAAW,oBAAqB,SAAQ,aAAa;IAEzD,KAAK,CAAC,EAAE,OAAO,CAAC;IAGhB,aAAa,CAAC,EAAE,MAAM,CAAC;IAGvB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClientEvent = exports.ConnectionStatus = void 0;
4
+ var ConnectionStatus;
5
+ (function (ConnectionStatus) {
6
+ ConnectionStatus["DISCONNECTED"] = "disconnected";
7
+ ConnectionStatus["CONNECTING"] = "connecting";
8
+ ConnectionStatus["CONNECTED"] = "connected";
9
+ ConnectionStatus["RECONNECTING"] = "reconnecting";
10
+ ConnectionStatus["FAILED"] = "failed";
11
+ })(ConnectionStatus || (exports.ConnectionStatus = ConnectionStatus = {}));
12
+ exports.ClientEvent = {
13
+ CONNECTED: 'connected',
14
+ DISCONNECTED: 'disconnected',
15
+ RECONNECTING: 'reconnecting',
16
+ RECONNECTED: 'reconnected',
17
+ ERROR: 'error',
18
+ MODELS_UPDATED: 'modelsUpdated',
19
+ BALANCE_UPDATED: 'balanceUpdated',
20
+ PROJECT_CREATED: 'projectCreated',
21
+ PROJECT_PROGRESS: 'projectProgress',
22
+ PROJECT_COMPLETED: 'projectCompleted',
23
+ PROJECT_FAILED: 'projectFailed',
24
+ };
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;AAiKA,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC1B,iDAA6B,CAAA;IAC7B,6CAAyB,CAAA;IACzB,2CAAuB,CAAA;IACvB,iDAA6B,CAAA;IAC7B,qCAAiB,CAAA;AACnB,CAAC,EANW,gBAAgB,gCAAhB,gBAAgB,QAM3B;AAmFY,QAAA,WAAW,GAAG;IACzB,SAAS,EAAE,WAAW;IACtB,YAAY,EAAE,cAAc;IAC5B,YAAY,EAAE,cAAc;IAC5B,WAAW,EAAE,aAAa;IAC1B,KAAK,EAAE,OAAO;IACd,cAAc,EAAE,eAAe;IAC/B,eAAe,EAAE,gBAAgB;IACjC,eAAe,EAAE,gBAAgB;IACjC,gBAAgB,EAAE,iBAAiB;IACnC,iBAAiB,EAAE,kBAAkB;IACrC,cAAc,EAAE,eAAe;CACvB,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { ErrorData } from '../types';
2
+ export declare class SogniError extends Error {
3
+ readonly code: string;
4
+ readonly statusCode?: number;
5
+ readonly details?: any;
6
+ readonly originalError?: Error;
7
+ constructor(message: string, code: string, statusCode?: number, details?: any, originalError?: Error);
8
+ toErrorData(): ErrorData;
9
+ static fromError(error: unknown, code?: string): SogniError;
10
+ }
11
+ export declare class SogniConnectionError extends SogniError {
12
+ constructor(message: string, details?: any, originalError?: Error);
13
+ }
14
+ export declare class SogniAuthenticationError extends SogniError {
15
+ constructor(message: string, details?: any, originalError?: Error);
16
+ }
17
+ export declare class SogniProjectError extends SogniError {
18
+ constructor(message: string, details?: any, originalError?: Error);
19
+ }
20
+ export declare class SogniTimeoutError extends SogniError {
21
+ constructor(message: string, timeoutMs: number, details?: any);
22
+ }
23
+ export declare class SogniBalanceError extends SogniError {
24
+ constructor(message: string, details?: any);
25
+ }
26
+ export declare class SogniValidationError extends SogniError {
27
+ constructor(message: string, details?: any);
28
+ }
29
+ export declare class SogniConfigurationError extends SogniError {
30
+ constructor(message: string, details?: any);
31
+ }
32
+ export declare class SogniModelNotFoundError extends SogniError {
33
+ constructor(modelId: string);
34
+ }
35
+ export declare class SogniNetworkError extends SogniError {
36
+ constructor(message: string, details?: any, originalError?: Error);
37
+ }
38
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAK1C,qBAAa,UAAW,SAAQ,KAAK;IACnC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpC,SAAgB,OAAO,CAAC,EAAE,GAAG,CAAC;IAC9B,SAAgB,aAAa,CAAC,EAAE,KAAK,CAAC;gBAE1B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,EAAE,KAAK;IAiBpG,WAAW,IAAI,SAAS;IAaxB,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,GAAE,MAAwB,GAAG,UAAU;CAW7E;AAKD,qBAAa,oBAAqB,SAAQ,UAAU;gBACtC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,EAAE,KAAK;CAIlE;AAKD,qBAAa,wBAAyB,SAAQ,UAAU;gBAC1C,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,EAAE,KAAK;CAIlE;AAKD,qBAAa,iBAAkB,SAAQ,UAAU;gBACnC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,EAAE,KAAK;CAIlE;AAKD,qBAAa,iBAAkB,SAAQ,UAAU;gBACnC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG;CAI9D;AAKD,qBAAa,iBAAkB,SAAQ,UAAU;gBACnC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG;CAI3C;AAKD,qBAAa,oBAAqB,SAAQ,UAAU;gBACtC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG;CAI3C;AAKD,qBAAa,uBAAwB,SAAQ,UAAU;gBACzC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG;CAI3C;AAKD,qBAAa,uBAAwB,SAAQ,UAAU;gBACzC,OAAO,EAAE,MAAM;CAI5B;AAKD,qBAAa,iBAAkB,SAAQ,UAAU;gBACnC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,EAAE,KAAK;CAIlE"}
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SogniNetworkError = exports.SogniModelNotFoundError = exports.SogniConfigurationError = exports.SogniValidationError = exports.SogniBalanceError = exports.SogniTimeoutError = exports.SogniProjectError = exports.SogniAuthenticationError = exports.SogniConnectionError = exports.SogniError = void 0;
4
+ class SogniError extends Error {
5
+ constructor(message, code, statusCode, details, originalError) {
6
+ super(message);
7
+ this.name = 'SogniError';
8
+ this.code = code;
9
+ this.statusCode = statusCode;
10
+ this.details = details;
11
+ this.originalError = originalError;
12
+ if (Error.captureStackTrace) {
13
+ Error.captureStackTrace(this, this.constructor);
14
+ }
15
+ }
16
+ toErrorData() {
17
+ return {
18
+ code: this.code,
19
+ message: this.message,
20
+ statusCode: this.statusCode,
21
+ details: this.details,
22
+ originalError: this.originalError,
23
+ };
24
+ }
25
+ static fromError(error, code = 'UNKNOWN_ERROR') {
26
+ if (error instanceof SogniError) {
27
+ return error;
28
+ }
29
+ if (error instanceof Error) {
30
+ return new SogniError(error.message, code, undefined, undefined, error);
31
+ }
32
+ return new SogniError(String(error), code);
33
+ }
34
+ }
35
+ exports.SogniError = SogniError;
36
+ class SogniConnectionError extends SogniError {
37
+ constructor(message, details, originalError) {
38
+ super(message, 'CONNECTION_ERROR', undefined, details, originalError);
39
+ this.name = 'SogniConnectionError';
40
+ }
41
+ }
42
+ exports.SogniConnectionError = SogniConnectionError;
43
+ class SogniAuthenticationError extends SogniError {
44
+ constructor(message, details, originalError) {
45
+ super(message, 'AUTHENTICATION_ERROR', 401, details, originalError);
46
+ this.name = 'SogniAuthenticationError';
47
+ }
48
+ }
49
+ exports.SogniAuthenticationError = SogniAuthenticationError;
50
+ class SogniProjectError extends SogniError {
51
+ constructor(message, details, originalError) {
52
+ super(message, 'PROJECT_ERROR', undefined, details, originalError);
53
+ this.name = 'SogniProjectError';
54
+ }
55
+ }
56
+ exports.SogniProjectError = SogniProjectError;
57
+ class SogniTimeoutError extends SogniError {
58
+ constructor(message, timeoutMs, details) {
59
+ super(message, 'TIMEOUT_ERROR', 408, { ...details, timeoutMs }, undefined);
60
+ this.name = 'SogniTimeoutError';
61
+ }
62
+ }
63
+ exports.SogniTimeoutError = SogniTimeoutError;
64
+ class SogniBalanceError extends SogniError {
65
+ constructor(message, details) {
66
+ super(message, 'INSUFFICIENT_BALANCE', 402, details, undefined);
67
+ this.name = 'SogniBalanceError';
68
+ }
69
+ }
70
+ exports.SogniBalanceError = SogniBalanceError;
71
+ class SogniValidationError extends SogniError {
72
+ constructor(message, details) {
73
+ super(message, 'VALIDATION_ERROR', 400, details, undefined);
74
+ this.name = 'SogniValidationError';
75
+ }
76
+ }
77
+ exports.SogniValidationError = SogniValidationError;
78
+ class SogniConfigurationError extends SogniError {
79
+ constructor(message, details) {
80
+ super(message, 'CONFIGURATION_ERROR', undefined, details, undefined);
81
+ this.name = 'SogniConfigurationError';
82
+ }
83
+ }
84
+ exports.SogniConfigurationError = SogniConfigurationError;
85
+ class SogniModelNotFoundError extends SogniError {
86
+ constructor(modelId) {
87
+ super(`Model not found: ${modelId}`, 'MODEL_NOT_FOUND', 404, { modelId }, undefined);
88
+ this.name = 'SogniModelNotFoundError';
89
+ }
90
+ }
91
+ exports.SogniModelNotFoundError = SogniModelNotFoundError;
92
+ class SogniNetworkError extends SogniError {
93
+ constructor(message, details, originalError) {
94
+ super(message, 'NETWORK_ERROR', undefined, details, originalError);
95
+ this.name = 'SogniNetworkError';
96
+ }
97
+ }
98
+ exports.SogniNetworkError = SogniNetworkError;
99
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":";;;AASA,MAAa,UAAW,SAAQ,KAAK;IAMnC,YAAY,OAAe,EAAE,IAAY,EAAE,UAAmB,EAAE,OAAa,EAAE,aAAqB;QAClG,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QAGnC,IAAI,KAAK,CAAC,iBAAiB,EAAE,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BAAoB,OAAO,EAAE,EAAE,iBAAiB,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;QACrF,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AALD,0DAKC;AAKD,MAAa,iBAAkB,SAAQ,UAAU;IAC/C,YAAY,OAAe,EAAE,OAAa,EAAE,aAAqB;QAC/D,KAAK,CAAC,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;QACnE,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AALD,8CAKC"}
@@ -0,0 +1,27 @@
1
+ import type { ProjectConfig, SogniClientConfig } from '../types';
2
+ export declare function generateAppId(): string;
3
+ export declare function validateClientConfig(config: SogniClientConfig): void;
4
+ export declare function validateProjectConfig(config: ProjectConfig): void;
5
+ export declare function createTimeoutPromise<T>(timeoutMs: number, errorMessage?: string): Promise<T>;
6
+ export declare function waitFor(condition: () => boolean | Promise<boolean>, options?: {
7
+ timeout?: number;
8
+ interval?: number;
9
+ timeoutMessage?: string;
10
+ }): Promise<void>;
11
+ export declare function sleep(ms: number): Promise<void>;
12
+ export declare function retry<T>(fn: () => Promise<T>, options?: {
13
+ maxAttempts?: number;
14
+ initialDelay?: number;
15
+ maxDelay?: number;
16
+ backoffFactor?: number;
17
+ onRetry?: (attempt: number, error: Error) => void;
18
+ }): Promise<T>;
19
+ export declare function formatBytes(bytes: number, decimals?: number): string;
20
+ export declare function formatDuration(ms: number): string;
21
+ export declare function deepClone<T>(obj: T): T;
22
+ export declare function isPlainObject(value: any): value is Record<string, any>;
23
+ export declare function deepMerge<T extends Record<string, any>>(target: T, ...sources: Partial<T>[]): T;
24
+ export declare function sanitizeForLog(str: string, keysToHide?: string[]): string;
25
+ export declare function debounce<T extends (...args: any[]) => any>(func: T, waitMs: number): (...args: Parameters<T>) => void;
26
+ export declare function throttle<T extends (...args: any[]) => any>(func: T, limitMs: number): (...args: Parameters<T>) => void;
27
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAMjE,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAKD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAoBpE;AAKD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CA8CjE;AAKD,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,GAAE,MAA8B,GAAG,OAAO,CAAC,CAAC,CAAC,CAMnH;AAKD,wBAAsB,OAAO,CAC3B,SAAS,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,EAC3C,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;CACpB,GACL,OAAO,CAAC,IAAI,CAAC,CAiBf;AAKD,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAKD,wBAAsB,KAAK,CAAC,CAAC,EAC3B,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,GAAE;IACP,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAC9C,GACL,OAAO,CAAC,CAAC,CAAC,CAgCZ;AAKD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAUvE;AAKD,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAYjD;AAKD,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAEtC;AAKD,wBAAgB,aAAa,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAEtE;AAKD,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAkB/F;AAKD,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,GAAE,MAAM,EAAoC,GAAG,MAAM,CAS1G;AAKD,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACxD,IAAI,EAAE,CAAC,EACP,MAAM,EAAE,MAAM,GACb,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAYlC;AAKD,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACxD,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,MAAM,GACd,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAYlC"}
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateAppId = generateAppId;
4
+ exports.validateClientConfig = validateClientConfig;
5
+ exports.validateProjectConfig = validateProjectConfig;
6
+ exports.createTimeoutPromise = createTimeoutPromise;
7
+ exports.waitFor = waitFor;
8
+ exports.sleep = sleep;
9
+ exports.retry = retry;
10
+ exports.formatBytes = formatBytes;
11
+ exports.formatDuration = formatDuration;
12
+ exports.deepClone = deepClone;
13
+ exports.isPlainObject = isPlainObject;
14
+ exports.deepMerge = deepMerge;
15
+ exports.sanitizeForLog = sanitizeForLog;
16
+ exports.debounce = debounce;
17
+ exports.throttle = throttle;
18
+ const crypto_1 = require("crypto");
19
+ const errors_1 = require("./errors");
20
+ function generateAppId() {
21
+ return (0, crypto_1.randomUUID)();
22
+ }
23
+ function validateClientConfig(config) {
24
+ if (!config.username || typeof config.username !== 'string') {
25
+ throw new errors_1.SogniValidationError('Username is required and must be a string');
26
+ }
27
+ if (!config.password || typeof config.password !== 'string') {
28
+ throw new errors_1.SogniValidationError('Password is required and must be a string');
29
+ }
30
+ if (config.network && !['fast', 'relaxed'].includes(config.network)) {
31
+ throw new errors_1.SogniValidationError('Network must be either "fast" or "relaxed"');
32
+ }
33
+ if (config.timeout !== undefined && (typeof config.timeout !== 'number' || config.timeout <= 0)) {
34
+ throw new errors_1.SogniValidationError('Timeout must be a positive number');
35
+ }
36
+ if (config.reconnectInterval !== undefined && (typeof config.reconnectInterval !== 'number' || config.reconnectInterval <= 0)) {
37
+ throw new errors_1.SogniValidationError('Reconnect interval must be a positive number');
38
+ }
39
+ }
40
+ function validateProjectConfig(config) {
41
+ if (!config.modelId || typeof config.modelId !== 'string') {
42
+ throw new errors_1.SogniValidationError('Model ID is required and must be a string');
43
+ }
44
+ if (!config.positivePrompt || typeof config.positivePrompt !== 'string') {
45
+ throw new errors_1.SogniValidationError('Positive prompt is required and must be a string');
46
+ }
47
+ if (config.numberOfImages !== undefined) {
48
+ if (typeof config.numberOfImages !== 'number' || config.numberOfImages < 1 || config.numberOfImages > 10) {
49
+ throw new errors_1.SogniValidationError('Number of images must be between 1 and 10');
50
+ }
51
+ }
52
+ if (config.steps !== undefined) {
53
+ if (typeof config.steps !== 'number' || config.steps < 1 || config.steps > 100) {
54
+ throw new errors_1.SogniValidationError('Steps must be between 1 and 100');
55
+ }
56
+ }
57
+ if (config.guidance !== undefined) {
58
+ if (typeof config.guidance !== 'number' || config.guidance < 0 || config.guidance > 30) {
59
+ throw new errors_1.SogniValidationError('Guidance must be between 0 and 30');
60
+ }
61
+ }
62
+ if (config.width !== undefined) {
63
+ if (typeof config.width !== 'number' || config.width < 256 || config.width > 2048) {
64
+ throw new errors_1.SogniValidationError('Width must be between 256 and 2048');
65
+ }
66
+ }
67
+ if (config.height !== undefined) {
68
+ if (typeof config.height !== 'number' || config.height < 256 || config.height > 2048) {
69
+ throw new errors_1.SogniValidationError('Height must be between 256 and 2048');
70
+ }
71
+ }
72
+ if (config.tokenType && !['sogni', 'spark'].includes(config.tokenType)) {
73
+ throw new errors_1.SogniValidationError('Token type must be either "sogni" or "spark"');
74
+ }
75
+ if (config.outputFormat && !['png', 'jpg'].includes(config.outputFormat)) {
76
+ throw new errors_1.SogniValidationError('Output format must be either "png" or "jpg"');
77
+ }
78
+ }
79
+ function createTimeoutPromise(timeoutMs, errorMessage = 'Operation timed out') {
80
+ return new Promise((_, reject) => {
81
+ setTimeout(() => {
82
+ reject(new Error(errorMessage));
83
+ }, timeoutMs);
84
+ });
85
+ }
86
+ async function waitFor(condition, options = {}) {
87
+ const { timeout = 30000, interval = 100, timeoutMessage = 'Wait condition timed out' } = options;
88
+ const startTime = Date.now();
89
+ while (true) {
90
+ const result = await Promise.resolve(condition());
91
+ if (result) {
92
+ return;
93
+ }
94
+ if (Date.now() - startTime >= timeout) {
95
+ throw new Error(timeoutMessage);
96
+ }
97
+ await sleep(interval);
98
+ }
99
+ }
100
+ function sleep(ms) {
101
+ return new Promise((resolve) => setTimeout(resolve, ms));
102
+ }
103
+ async function retry(fn, options = {}) {
104
+ const { maxAttempts = 3, initialDelay = 1000, maxDelay = 10000, backoffFactor = 2, onRetry, } = options;
105
+ let lastError;
106
+ let delay = initialDelay;
107
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
108
+ try {
109
+ return await fn();
110
+ }
111
+ catch (error) {
112
+ lastError = error instanceof Error ? error : new Error(String(error));
113
+ if (attempt === maxAttempts) {
114
+ throw lastError;
115
+ }
116
+ if (onRetry) {
117
+ onRetry(attempt, lastError);
118
+ }
119
+ await sleep(delay);
120
+ delay = Math.min(delay * backoffFactor, maxDelay);
121
+ }
122
+ }
123
+ throw lastError;
124
+ }
125
+ function formatBytes(bytes, decimals = 2) {
126
+ if (bytes === 0)
127
+ return '0 Bytes';
128
+ const k = 1024;
129
+ const dm = decimals < 0 ? 0 : decimals;
130
+ const sizes = ['Bytes', 'KB', 'MB', 'GB'];
131
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
132
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
133
+ }
134
+ function formatDuration(ms) {
135
+ const seconds = Math.floor(ms / 1000);
136
+ const minutes = Math.floor(seconds / 60);
137
+ const hours = Math.floor(minutes / 60);
138
+ if (hours > 0) {
139
+ return `${hours}h ${minutes % 60}m`;
140
+ }
141
+ if (minutes > 0) {
142
+ return `${minutes}m ${seconds % 60}s`;
143
+ }
144
+ return `${seconds}s`;
145
+ }
146
+ function deepClone(obj) {
147
+ return JSON.parse(JSON.stringify(obj));
148
+ }
149
+ function isPlainObject(value) {
150
+ return value !== null && typeof value === 'object' && value.constructor === Object;
151
+ }
152
+ function deepMerge(target, ...sources) {
153
+ if (!sources.length)
154
+ return target;
155
+ const source = sources.shift();
156
+ if (!source)
157
+ return target;
158
+ if (isPlainObject(target) && isPlainObject(source)) {
159
+ for (const key in source) {
160
+ if (isPlainObject(source[key])) {
161
+ if (!target[key])
162
+ Object.assign(target, { [key]: {} });
163
+ deepMerge(target[key], source[key]);
164
+ }
165
+ else {
166
+ Object.assign(target, { [key]: source[key] });
167
+ }
168
+ }
169
+ }
170
+ return deepMerge(target, ...sources);
171
+ }
172
+ function sanitizeForLog(str, keysToHide = ['password', 'apiKey', 'token']) {
173
+ let sanitized = str;
174
+ keysToHide.forEach(key => {
175
+ const regex = new RegExp(`(${key}["\']?\\s*[:=]\\s*["\']?)([^"',}\\s]+)`, 'gi');
176
+ sanitized = sanitized.replace(regex, '$1***');
177
+ });
178
+ return sanitized;
179
+ }
180
+ function debounce(func, waitMs) {
181
+ let timeoutId = null;
182
+ return function (...args) {
183
+ if (timeoutId) {
184
+ clearTimeout(timeoutId);
185
+ }
186
+ timeoutId = setTimeout(() => {
187
+ func.apply(this, args);
188
+ }, waitMs);
189
+ };
190
+ }
191
+ function throttle(func, limitMs) {
192
+ let inThrottle = false;
193
+ return function (...args) {
194
+ if (!inThrottle) {
195
+ func.apply(this, args);
196
+ inThrottle = true;
197
+ setTimeout(() => {
198
+ inThrottle = false;
199
+ }, limitMs);
200
+ }
201
+ };
202
+ }
203
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":";;AAWA,sCAEC;AAKD,oDAoBC;AAKD,sDA8CC;AAKD,oDAMC;AAKD,0BAwBC;AAKD,sBAEC;AAKD,sBAyCC;AAKD,kCAUC;AAKD,wCAYC;AAKD,8BAEC;AAKD,sCAEC;AAKD,8BAkBC;AAKD,wCASC;AAKD,4BAeC;AAKD,4BAeC;AA7SD,mCAAoC;AAEpC,qCAAgD;AAKhD,SAAgB,aAAa;IAC3B,OAAO,IAAA,mBAAU,GAAE,CAAC;AACtB,CAAC;AAKD,SAAgB,oBAAoB,CAAC,MAAyB;IAC5D,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC5D,MAAM,IAAI,6BAAoB,CAAC,2CAA2C,CAAC,CAAC;IAC9E,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC5D,MAAM,IAAI,6BAAoB,CAAC,2CAA2C,CAA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AAO,SAAS,CAAC;AACnB,CAAC;AAKD,SAAgB,QAAQ,CACtB,IAAO,EACP,MAAc;IAEd,IAAI,SAAS,GAA0B,IAAI,CAAC;IAE5C,OAAO,UAAqB,GAAG,IAAmB;QAChD,IAAI,SAAS,EAAE,CAAC;YACd,YAAY,CAAC,SAAS,CAAC,CAAC;QAC1B,CAAC;QAED,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;YAC1B,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACzB,CAAC,EAAE,MAAM,CAAC,CAAC;IACb,CAAC,CAAC;AACJ,CAAC;AAKD,SAAgB,QAAQ,CACtB,IAAO,EACP,OAAe;IAEf,IAAI,UAAU,GAAY,KAAK,CAAC;IAEhC,OAAO,UAAqB,GAAG,IAAmB;QAChD,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACvB,UAAU,GAAG,IAAI,CAAC;YAClB,UAAU,CAAC,GAAG,EAAE;gBACd,UAAU,GAAG,KAAK,CAAC;YACrB,CAAC,EAAE,OAAO,CAAC,CAAC;QACd,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@sogni-ai/sogni-client-wrapper",
3
+ "version": "1.0.0",
4
+ "description": "Enhanced Node.js wrapper for Sogni AI SDK with n8n compatibility and improved developer experience",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "build:watch": "tsc --watch",
10
+ "dev": "tsc --watch",
11
+ "prepublishOnly": "npm run build",
12
+ "test": "tsx test/basic-tests.ts",
13
+ "test:e2e": "tsx test/e2e-test.ts",
14
+ "test:all": "npm run test && npm run test:e2e"
15
+ },
16
+ "keywords": [
17
+ "sogni",
18
+ "ai",
19
+ "image-generation",
20
+ "n8n",
21
+ "workflow",
22
+ "automation",
23
+ "depin",
24
+ "stable-diffusion",
25
+ "flux"
26
+ ],
27
+ "author": "Sogni AI",
28
+ "license": "MIT",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/sogni-ai/sogni-client-wrapper.git"
32
+ },
33
+ "bugs": {
34
+ "url": "https://github.com/sogni-ai/sogni-client-wrapper/issues"
35
+ },
36
+ "homepage": "https://github.com/sogni-ai/sogni-client-wrapper#readme",
37
+ "dependencies": {
38
+ "@sogni-ai/sogni-client": "latest"
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "^22.0.0",
42
+ "dotenv": "^17.2.3",
43
+ "tsx": "^4.20.6",
44
+ "typescript": "^5.0.0"
45
+ },
46
+ "engines": {
47
+ "node": ">=18.0.0"
48
+ },
49
+ "files": [
50
+ "dist",
51
+ "README.md",
52
+ "LICENSE"
53
+ ]
54
+ }