@seenn/node 0.1.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/LICENSE +21 -0
- package/README.md +188 -0
- package/dist/client.d.ts +43 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +59 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +62 -0
- package/dist/errors.js.map +1 -0
- package/dist/http.d.ts +14 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +125 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/job.d.ts +87 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +125 -0
- package/dist/job.js.map +1 -0
- package/dist/types.d.ts +98 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +64 -0
- package/src/client.ts +83 -0
- package/src/errors.ts +64 -0
- package/src/http.ts +179 -0
- package/src/index.ts +20 -0
- package/src/job.ts +201 -0
- package/src/types.ts +111 -0
package/dist/job.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { HttpClient } from './http.js';
|
|
2
|
+
import type { JobResponse, QueueInfo, StageInfo, JobResult, JobError } from './types.js';
|
|
3
|
+
export type JobStatus = 'pending' | 'running' | 'completed' | 'failed';
|
|
4
|
+
export interface JobData {
|
|
5
|
+
id: string;
|
|
6
|
+
appId: string;
|
|
7
|
+
userId: string;
|
|
8
|
+
jobType: string;
|
|
9
|
+
title: string;
|
|
10
|
+
status: JobStatus;
|
|
11
|
+
progress: number;
|
|
12
|
+
message?: string;
|
|
13
|
+
queue?: QueueInfo;
|
|
14
|
+
stage?: StageInfo;
|
|
15
|
+
result?: JobResult;
|
|
16
|
+
error?: JobError;
|
|
17
|
+
metadata?: Record<string, unknown>;
|
|
18
|
+
estimatedCompletionAt?: string;
|
|
19
|
+
createdAt: Date;
|
|
20
|
+
updatedAt: Date;
|
|
21
|
+
completedAt?: Date;
|
|
22
|
+
}
|
|
23
|
+
export interface ProgressOptions {
|
|
24
|
+
message?: string;
|
|
25
|
+
queue?: QueueInfo;
|
|
26
|
+
stage?: StageInfo;
|
|
27
|
+
estimatedCompletionAt?: string;
|
|
28
|
+
metadata?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
export interface CompleteOptions {
|
|
31
|
+
result?: JobResult;
|
|
32
|
+
message?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface FailOptions {
|
|
35
|
+
error: JobError;
|
|
36
|
+
retryable?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Job instance with fluent API for updates
|
|
40
|
+
*/
|
|
41
|
+
export declare class Job implements JobData {
|
|
42
|
+
readonly id: string;
|
|
43
|
+
readonly appId: string;
|
|
44
|
+
readonly userId: string;
|
|
45
|
+
readonly jobType: string;
|
|
46
|
+
readonly title: string;
|
|
47
|
+
status: JobStatus;
|
|
48
|
+
progress: number;
|
|
49
|
+
message?: string;
|
|
50
|
+
queue?: QueueInfo;
|
|
51
|
+
stage?: StageInfo;
|
|
52
|
+
result?: JobResult;
|
|
53
|
+
error?: JobError;
|
|
54
|
+
metadata?: Record<string, unknown>;
|
|
55
|
+
estimatedCompletionAt?: string;
|
|
56
|
+
readonly createdAt: Date;
|
|
57
|
+
updatedAt: Date;
|
|
58
|
+
completedAt?: Date;
|
|
59
|
+
private readonly http;
|
|
60
|
+
constructor(data: JobResponse, http: HttpClient);
|
|
61
|
+
/**
|
|
62
|
+
* Update job progress (0-100)
|
|
63
|
+
*/
|
|
64
|
+
setProgress(progress: number, options?: ProgressOptions): Promise<this>;
|
|
65
|
+
/**
|
|
66
|
+
* Mark job as completed
|
|
67
|
+
*/
|
|
68
|
+
complete(options?: CompleteOptions): Promise<this>;
|
|
69
|
+
/**
|
|
70
|
+
* Mark job as failed
|
|
71
|
+
*/
|
|
72
|
+
fail(options: FailOptions): Promise<this>;
|
|
73
|
+
/**
|
|
74
|
+
* Refresh job data from server
|
|
75
|
+
*/
|
|
76
|
+
refresh(): Promise<this>;
|
|
77
|
+
/**
|
|
78
|
+
* Check if job is in a terminal state
|
|
79
|
+
*/
|
|
80
|
+
get isTerminal(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Get plain object representation
|
|
83
|
+
*/
|
|
84
|
+
toJSON(): JobData;
|
|
85
|
+
private updateFromResponse;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=job.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job.d.ts","sourceRoot":"","sources":["../src/job.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EACV,WAAW,EAIX,SAAS,EACT,SAAS,EACT,SAAS,EACT,QAAQ,EACT,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;AAEvE,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,SAAS,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,qBAAqB,C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AS,EAAE,IAAI,CAAC;IAChB,WAAW,CAAC,EAAE,IAAI,CAAC;IAEnB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;gBAEtB,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU;IAsB/C;;OAEG;IACG,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAe7E;;OAEG;IACG,QAAQ,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAYxD;;OAEG;IACG,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAY/C;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAM9B;;OAEG;IACH,IAAI,UAAU,IAAI,OAAO,CAExB;IAED;;OAEG;IACH,MAAM,IAAI,OAAO;IAsBjB,OAAO,CAAC,kBAAkB;CAa3B"}
|
package/dist/job.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Job instance with fluent API for updates
|
|
3
|
+
*/
|
|
4
|
+
export class Job {
|
|
5
|
+
id;
|
|
6
|
+
appId;
|
|
7
|
+
userId;
|
|
8
|
+
jobType;
|
|
9
|
+
title;
|
|
10
|
+
status;
|
|
11
|
+
progress;
|
|
12
|
+
message;
|
|
13
|
+
queue;
|
|
14
|
+
stage;
|
|
15
|
+
result;
|
|
16
|
+
error;
|
|
17
|
+
metadata;
|
|
18
|
+
estimatedCompletionAt;
|
|
19
|
+
createdAt;
|
|
20
|
+
updatedAt;
|
|
21
|
+
completedAt;
|
|
22
|
+
http;
|
|
23
|
+
constructor(data, http) {
|
|
24
|
+
this.id = data.id;
|
|
25
|
+
this.appId = data.appId;
|
|
26
|
+
this.userId = data.userId;
|
|
27
|
+
this.jobType = data.jobType;
|
|
28
|
+
this.title = data.title;
|
|
29
|
+
this.status = data.status;
|
|
30
|
+
this.progress = data.progress;
|
|
31
|
+
this.message = data.message;
|
|
32
|
+
this.queue = data.queue;
|
|
33
|
+
this.stage = data.stage;
|
|
34
|
+
this.result = data.result;
|
|
35
|
+
this.error = data.error;
|
|
36
|
+
this.metadata = data.metadata;
|
|
37
|
+
this.estimatedCompletionAt = data.estimatedCompletionAt;
|
|
38
|
+
this.createdAt = new Date(data.createdAt);
|
|
39
|
+
this.updatedAt = new Date(data.updatedAt);
|
|
40
|
+
this.completedAt = data.completedAt ? new Date(data.completedAt) : undefined;
|
|
41
|
+
this.http = http;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Update job progress (0-100)
|
|
45
|
+
*/
|
|
46
|
+
async setProgress(progress, options) {
|
|
47
|
+
const params = {
|
|
48
|
+
progress,
|
|
49
|
+
...options,
|
|
50
|
+
};
|
|
51
|
+
const response = await this.http.post(`/v1/jobs/${this.id}/progress`, params);
|
|
52
|
+
this.updateFromResponse(response);
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Mark job as completed
|
|
57
|
+
*/
|
|
58
|
+
async complete(options) {
|
|
59
|
+
const params = options || {};
|
|
60
|
+
const response = await this.http.post(`/v1/jobs/${this.id}/complete`, params);
|
|
61
|
+
this.updateFromResponse(response);
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Mark job as failed
|
|
66
|
+
*/
|
|
67
|
+
async fail(options) {
|
|
68
|
+
const params = options;
|
|
69
|
+
const response = await this.http.post(`/v1/jobs/${this.id}/fail`, params);
|
|
70
|
+
this.updateFromResponse(response);
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Refresh job data from server
|
|
75
|
+
*/
|
|
76
|
+
async refresh() {
|
|
77
|
+
const response = await this.http.get(`/v1/jobs/${this.id}`);
|
|
78
|
+
this.updateFromResponse(response);
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Check if job is in a terminal state
|
|
83
|
+
*/
|
|
84
|
+
get isTerminal() {
|
|
85
|
+
return this.status === 'completed' || this.status === 'failed';
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get plain object representation
|
|
89
|
+
*/
|
|
90
|
+
toJSON() {
|
|
91
|
+
return {
|
|
92
|
+
id: this.id,
|
|
93
|
+
appId: this.appId,
|
|
94
|
+
userId: this.userId,
|
|
95
|
+
jobType: this.jobType,
|
|
96
|
+
title: this.title,
|
|
97
|
+
status: this.status,
|
|
98
|
+
progress: this.progress,
|
|
99
|
+
message: this.message,
|
|
100
|
+
queue: this.queue,
|
|
101
|
+
stage: this.stage,
|
|
102
|
+
result: this.result,
|
|
103
|
+
error: this.error,
|
|
104
|
+
metadata: this.metadata,
|
|
105
|
+
estimatedCompletionAt: this.estimatedCompletionAt,
|
|
106
|
+
createdAt: this.createdAt,
|
|
107
|
+
updatedAt: this.updatedAt,
|
|
108
|
+
completedAt: this.completedAt,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
updateFromResponse(response) {
|
|
112
|
+
this.status = response.status;
|
|
113
|
+
this.progress = response.progress;
|
|
114
|
+
this.message = response.message;
|
|
115
|
+
this.queue = response.queue;
|
|
116
|
+
this.stage = response.stage;
|
|
117
|
+
this.result = response.result;
|
|
118
|
+
this.error = response.error;
|
|
119
|
+
this.metadata = response.metadata;
|
|
120
|
+
this.estimatedCompletionAt = response.estimatedCompletionAt;
|
|
121
|
+
this.updatedAt = new Date(response.updatedAt);
|
|
122
|
+
this.completedAt = response.completedAt ? new Date(response.completedAt) : undefined;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=job.js.map
|
package/dist/job.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job.js","sourceRoot":"","sources":["../src/job.ts"],"names":[],"mappings":"AAoDA;;GAEG;AACH,MAAM,OAAO,GAAG;IACL,EAAE,CAAS;IACX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AAC;QAC5B,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;QAC9B,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;QAClC,IAAI,CAAC,qBAAqB,GAAG,QAAQ,CAAC,qBAAqB,CAAC;QAC5D,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAC9C,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACvF,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export interface StartJobParams {
|
|
2
|
+
/** Unique job type identifier (e.g., 'video-generation', 'image-processing') */
|
|
3
|
+
jobType: string;
|
|
4
|
+
/** User ID who owns this job */
|
|
5
|
+
userId: string;
|
|
6
|
+
/** Human-readable title for the job */
|
|
7
|
+
title: string;
|
|
8
|
+
/** Optional metadata (max 10KB) */
|
|
9
|
+
metadata?: Record<string, unknown>;
|
|
10
|
+
/** Optional initial queue information */
|
|
11
|
+
queue?: QueueInfo;
|
|
12
|
+
/** Optional initial stage information */
|
|
13
|
+
stage?: StageInfo;
|
|
14
|
+
/** Optional estimated completion time (ISO 8601) */
|
|
15
|
+
estimatedCompletionAt?: string;
|
|
16
|
+
/** Optional TTL in seconds (default: 30 days) */
|
|
17
|
+
ttlSeconds?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface ProgressParams {
|
|
20
|
+
/** Progress percentage (0-100) */
|
|
21
|
+
progress: number;
|
|
22
|
+
/** Optional status message */
|
|
23
|
+
message?: string;
|
|
24
|
+
/** Optional updated queue information */
|
|
25
|
+
queue?: QueueInfo;
|
|
26
|
+
/** Optional updated stage information */
|
|
27
|
+
stage?: StageInfo;
|
|
28
|
+
/** Optional updated ETA */
|
|
29
|
+
estimatedCompletionAt?: string;
|
|
30
|
+
/** Optional metadata update (merged with existing) */
|
|
31
|
+
metadata?: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
export interface CompleteParams {
|
|
34
|
+
/** Result data (max 100KB) */
|
|
35
|
+
result?: JobResult;
|
|
36
|
+
/** Optional completion message */
|
|
37
|
+
message?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface FailParams {
|
|
40
|
+
/** Error information */
|
|
41
|
+
error: JobError;
|
|
42
|
+
/** Whether the job can be retried */
|
|
43
|
+
retryable?: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface QueueInfo {
|
|
46
|
+
/** Current position in queue (1-based) */
|
|
47
|
+
position: number;
|
|
48
|
+
/** Total items in queue */
|
|
49
|
+
total?: number;
|
|
50
|
+
/** Optional queue name/tier */
|
|
51
|
+
queueName?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface StageInfo {
|
|
54
|
+
/** Current stage name */
|
|
55
|
+
name: string;
|
|
56
|
+
/** Current stage number (1-based) */
|
|
57
|
+
current: number;
|
|
58
|
+
/** Total number of stages */
|
|
59
|
+
total: number;
|
|
60
|
+
/** Optional stage description */
|
|
61
|
+
description?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface JobResult {
|
|
64
|
+
/** Result type identifier */
|
|
65
|
+
type?: string;
|
|
66
|
+
/** Result URL (e.g., generated video URL) */
|
|
67
|
+
url?: string;
|
|
68
|
+
/** Additional result data */
|
|
69
|
+
data?: Record<string, unknown>;
|
|
70
|
+
}
|
|
71
|
+
export interface JobError {
|
|
72
|
+
/** Error code */
|
|
73
|
+
code: string;
|
|
74
|
+
/** Human-readable error message */
|
|
75
|
+
message: string;
|
|
76
|
+
/** Additional error details */
|
|
77
|
+
details?: Record<string, unknown>;
|
|
78
|
+
}
|
|
79
|
+
export interface JobResponse {
|
|
80
|
+
id: string;
|
|
81
|
+
appId: string;
|
|
82
|
+
userId: string;
|
|
83
|
+
jobType: string;
|
|
84
|
+
title: string;
|
|
85
|
+
status: 'pending' | 'running' | 'completed' | 'failed';
|
|
86
|
+
progress: number;
|
|
87
|
+
message?: string;
|
|
88
|
+
queue?: QueueInfo;
|
|
89
|
+
stage?: StageInfo;
|
|
90
|
+
result?: JobResult;
|
|
91
|
+
error?: JobError;
|
|
92
|
+
metadata?: Record<string, unknown>;
|
|
93
|
+
estimatedCompletionAt?: string;
|
|
94
|
+
createdAt: string;
|
|
95
|
+
updatedAt: string;
|
|
96
|
+
completedAt?: string;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC7B,gFAAgF;IAChF,OAAO,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,mCAAmC;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,yCAAyC;IACzC,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,yCAAyC;IACzC,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,oDAAoD;IACpD,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,iDAAiD;IACjD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yCAAyC;IACzC,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,yCAAyC;IACzC,KAAK,CAAC,EAAE,SAAS,CAA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B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;IACvD,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,iBAAiB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@seenn/node",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Seenn Node.js Backend SDK - Open source job state transport for real-time progress tracking",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"src",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"dev": "tsc --watch",
|
|
23
|
+
"lint": "tsc --noEmit",
|
|
24
|
+
"typecheck": "tsc --noEmit",
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"test:watch": "vitest",
|
|
27
|
+
"prepublishOnly": "pnpm build"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"ulid": "^2.3.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"vitest": "^2.1.0"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"seenn",
|
|
37
|
+
"job",
|
|
38
|
+
"progress",
|
|
39
|
+
"realtime",
|
|
40
|
+
"push",
|
|
41
|
+
"notification",
|
|
42
|
+
"live-activity",
|
|
43
|
+
"sse",
|
|
44
|
+
"backend",
|
|
45
|
+
"api",
|
|
46
|
+
"open-source"
|
|
47
|
+
],
|
|
48
|
+
"author": "Seenn <hello@seenn.io>",
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "https://github.com/seenn-io/node.git"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://seenn.io",
|
|
55
|
+
"bugs": {
|
|
56
|
+
"url": "https://github.com/seenn-io/node/issues"
|
|
57
|
+
},
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public"
|
|
60
|
+
},
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=18.0.0"
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Job } from './job.js';
|
|
2
|
+
import { HttpClient } from './http.js';
|
|
3
|
+
import type { StartJobParams, JobResponse } from './types.js';
|
|
4
|
+
|
|
5
|
+
export interface SeennConfig {
|
|
6
|
+
/** API key (sk_live_xxx or sk_test_xxx) */
|
|
7
|
+
apiKey: string;
|
|
8
|
+
/** Base URL (default: https://api.seenn.io) */
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
/** Request timeout in ms (default: 30000) */
|
|
11
|
+
timeout?: number;
|
|
12
|
+
/** Max retry attempts (default: 3) */
|
|
13
|
+
maxRetries?: number;
|
|
14
|
+
/** Enable debug logging */
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class SeennClient {
|
|
19
|
+
private readonly http: HttpClient;
|
|
20
|
+
private readonly config: Required<SeennConfig>;
|
|
21
|
+
|
|
22
|
+
constructor(config: SeennConfig) {
|
|
23
|
+
if (!config.apiKey) {
|
|
24
|
+
throw new Error('apiKey is required');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!config.apiKey.startsWith('sk_')) {
|
|
28
|
+
throw new Error('apiKey must start with sk_live_ or sk_test_');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
this.config = {
|
|
32
|
+
apiKey: config.apiKey,
|
|
33
|
+
baseUrl: config.baseUrl || 'https://api.seenn.io',
|
|
34
|
+
timeout: config.timeout || 30000,
|
|
35
|
+
maxRetries: config.maxRetries || 3,
|
|
36
|
+
debug: config.debug || false,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
this.http = new HttpClient(this.config);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Jobs resource
|
|
44
|
+
*/
|
|
45
|
+
get jobs() {
|
|
46
|
+
return {
|
|
47
|
+
/**
|
|
48
|
+
* Start a new job
|
|
49
|
+
*/
|
|
50
|
+
start: async (params: StartJobParams): Promise<Job> => {
|
|
51
|
+
const response = await this.http.post<JobResponse>('/v1/jobs', params);
|
|
52
|
+
return new Job(response, this.http);
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Get a job by ID
|
|
57
|
+
*/
|
|
58
|
+
get: async (jobId: string): Promise<Job> => {
|
|
59
|
+
const response = await this.http.get<JobResponse>(`/v1/jobs/${jobId}`);
|
|
60
|
+
return new Job(response, this.http);
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* List jobs for a user
|
|
65
|
+
*/
|
|
66
|
+
list: async (userId: string, options?: { limit?: number; cursor?: string }) => {
|
|
67
|
+
const params = new URLSearchParams({ userId });
|
|
68
|
+
if (options?.limit) params.set('limit', String(options.limit));
|
|
69
|
+
if (options?.cursor) params.set('cursor', options.cursor);
|
|
70
|
+
|
|
71
|
+
const response = await this.http.get<{
|
|
72
|
+
jobs: JobResponse[];
|
|
73
|
+
nextCursor?: string;
|
|
74
|
+
}>(`/v1/jobs?${params}`);
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
jobs: response.jobs.map((j) => new Job(j, this.http)),
|
|
78
|
+
nextCursor: response.nextCursor,
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export class SeennError extends Error {
|
|
2
|
+
constructor(
|
|
3
|
+
message: string,
|
|
4
|
+
public readonly code: string,
|
|
5
|
+
public readonly statusCode: number = 500,
|
|
6
|
+
public readonly details?: Record<string, unknown>
|
|
7
|
+
) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = 'SeennError';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
toJSON() {
|
|
13
|
+
return {
|
|
14
|
+
name: this.name,
|
|
15
|
+
code: this.code,
|
|
16
|
+
message: this.message,
|
|
17
|
+
statusCode: this.statusCode,
|
|
18
|
+
details: this.details,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class ValidationError extends SeennError {
|
|
24
|
+
constructor(message: string, details?: Record<string, unknown>) {
|
|
25
|
+
super(message, 'VALIDATION_ERROR', 400, details);
|
|
26
|
+
this.name = 'ValidationError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class NotFoundError extends SeennError {
|
|
31
|
+
constructor(resource: string, id: string) {
|
|
32
|
+
super(`${resource} not found: ${id}`, 'NOT_FOUND', 404, { resource, id });
|
|
33
|
+
this.name = 'NotFoundError';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class RateLimitError extends SeennError {
|
|
38
|
+
constructor(
|
|
39
|
+
public readonly retryAfter: number,
|
|
40
|
+
public readonly limit: number,
|
|
41
|
+
public readonly remaining: number
|
|
42
|
+
) {
|
|
43
|
+
super(`Rate limit exceeded. Retry after ${retryAfter} seconds`, 'RATE_LIMIT_EXCEEDED', 429, {
|
|
44
|
+
retryAfter,
|
|
45
|
+
limit,
|
|
46
|
+
remaining,
|
|
47
|
+
});
|
|
48
|
+
this.name = 'RateLimitError';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export class AuthenticationError extends SeennError {
|
|
53
|
+
constructor(message: string = 'Invalid or missing API key') {
|
|
54
|
+
super(message, 'AUTHENTICATION_ERROR', 401);
|
|
55
|
+
this.name = 'AuthenticationError';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export class ConflictError extends SeennError {
|
|
60
|
+
constructor(message: string, details?: Record<string, unknown>) {
|
|
61
|
+
super(message, 'CONFLICT', 409, details);
|
|
62
|
+
this.name = 'ConflictError';
|
|
63
|
+
}
|
|
64
|
+
}
|