@omelhorsite/sdk 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.
Files changed (36) hide show
  1. package/README.md +321 -0
  2. package/dist/index.js +11589 -0
  3. package/dist/types/auth/device.d.ts +156 -0
  4. package/dist/types/auth/index.d.ts +127 -0
  5. package/dist/types/auth/tokens.d.ts +356 -0
  6. package/dist/types/client.d.ts +133 -0
  7. package/dist/types/errors.d.ts +202 -0
  8. package/dist/types/http.d.ts +204 -0
  9. package/dist/types/index.d.ts +33 -0
  10. package/dist/types/local/index.d.ts +42 -0
  11. package/dist/types/local/password.d.ts +169 -0
  12. package/dist/types/local/qr.d.ts +127 -0
  13. package/dist/types/local/wordlist.d.ts +26 -0
  14. package/dist/types/resources/account.d.ts +296 -0
  15. package/dist/types/resources/chests.d.ts +194 -0
  16. package/dist/types/resources/dynamicQrs.d.ts +172 -0
  17. package/dist/types/resources/forms.d.ts +331 -0
  18. package/dist/types/resources/index.d.ts +30 -0
  19. package/dist/types/resources/ipLookup.d.ts +63 -0
  20. package/dist/types/resources/jobs.d.ts +233 -0
  21. package/dist/types/resources/linkTrees.d.ts +249 -0
  22. package/dist/types/resources/notepads.d.ts +96 -0
  23. package/dist/types/resources/shortLinks.d.ts +248 -0
  24. package/dist/types/resources/storage/upload.d.ts +459 -0
  25. package/dist/types/resources/storage.d.ts +527 -0
  26. package/dist/types/resources/tickets.d.ts +236 -0
  27. package/dist/types/resources/tools/backgroundRemoval.d.ts +99 -0
  28. package/dist/types/resources/tools/captions.d.ts +318 -0
  29. package/dist/types/resources/tools/downloader.d.ts +397 -0
  30. package/dist/types/resources/tools/index.d.ts +215 -0
  31. package/dist/types/resources/tools/jumpstyle.d.ts +194 -0
  32. package/dist/types/resources/tools/transcription.d.ts +178 -0
  33. package/dist/types/resources/tools/upscale.d.ts +94 -0
  34. package/dist/types/resources/tools/vocalSeparation.d.ts +183 -0
  35. package/dist/types/types.d.ts +245 -0
  36. package/package.json +37 -0
@@ -0,0 +1,245 @@
1
+ /**
2
+ * Primitives shared by every namespace of the SDK.
3
+ *
4
+ * Nothing here touches the platform: no `node:*`, no `process`, no `console`.
5
+ * Files are values (Blob / Uint8Array / ReadableStream), never paths - the core
6
+ * has no filesystem. Turning a path into a {@link FileInput} is the CLI's job.
7
+ */
8
+ /** Any JSON value the API can send or receive. */
9
+ export type Json = string | number | boolean | null | Json[] | {
10
+ [key: string]: Json;
11
+ };
12
+ /** A JSON object. */
13
+ export type JsonObject = {
14
+ [key: string]: Json;
15
+ };
16
+ /**
17
+ * The fetch implementation the SDK talks through. Injected via the {@link Oms}
18
+ * constructor so the SDK works in a Worker isolate, under a test double, or
19
+ * behind an authenticating proxy.
20
+ */
21
+ export type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
22
+ /**
23
+ * Bytes handed to the SDK for upload.
24
+ *
25
+ * `data` is a value, never a path. `filename` is required because the API
26
+ * derives the stored name and, for some tools, the container format from it.
27
+ *
28
+ * `ReadableStream` is accepted for symmetry with the platform, but note that
29
+ * multipart form bodies have to be materialised: {@link readFileInput} buffers
30
+ * a stream into a Blob before it can be appended to a `FormData`. For anything
31
+ * large, prefer the storage direct-upload path, which streams straight to the
32
+ * object store and never passes through Rails.
33
+ */
34
+ export interface FileInput {
35
+ /** The bytes. */
36
+ readonly data: Blob | Uint8Array | ReadableStream<Uint8Array>;
37
+ /** Name the server should store, e.g. `"take-3.wav"`. Required. */
38
+ readonly filename: string;
39
+ /** MIME type. Defaults to the Blob's own type, then `application/octet-stream`. */
40
+ readonly contentType?: string;
41
+ /**
42
+ * Byte length, when known ahead of time. Lets the SDK pick an upload
43
+ * strategy (multipart above 32 MiB) without buffering the stream first.
44
+ */
45
+ readonly size?: number;
46
+ }
47
+ /** Bytes handed back by the SDK: a download, a rendered video, a zip. */
48
+ export interface FileOutput {
49
+ /** The bytes. */
50
+ readonly data: Blob;
51
+ /** Filename the server suggested, from `Content-Disposition` when present. */
52
+ readonly filename: string | undefined;
53
+ /** MIME type the server reported. */
54
+ readonly contentType: string | undefined;
55
+ /** Byte length of `data`. */
56
+ readonly size: number;
57
+ }
58
+ /**
59
+ * Normalises a {@link FileInput} into a Blob plus its metadata.
60
+ *
61
+ * Buffers a `ReadableStream` fully - see the note on {@link FileInput}. Uses
62
+ * only platform APIs, so it runs in an isolate.
63
+ */
64
+ export declare function readFileInput(input: FileInput): Promise<{
65
+ blob: Blob;
66
+ filename: string;
67
+ contentType: string;
68
+ }>;
69
+ /**
70
+ * Convenience constructor for a {@link FileInput}. Prefer it over an object
71
+ * literal so the `filename`-is-required rule stays visible at the call site.
72
+ */
73
+ export declare function file(data: Blob | Uint8Array | ReadableStream<Uint8Array>, filename: string, options?: {
74
+ contentType?: string;
75
+ size?: number;
76
+ }): FileInput;
77
+ /**
78
+ * Progress report for a long operation.
79
+ *
80
+ * `total` is `undefined` whenever the size is genuinely unknown (a stream
81
+ * upload, a server-side render with no ETA). Do not fake it with a guess.
82
+ */
83
+ export interface Progress {
84
+ /** What is happening right now. */
85
+ readonly phase: "upload" | "processing" | "download";
86
+ /** Units done so far - bytes for transfers, arbitrary ticks for processing. */
87
+ readonly loaded: number;
88
+ /** Total units, when known. */
89
+ readonly total: number | undefined;
90
+ /** Server-reported status string, when the endpoint has one (`"pending"`, `"rendering"`). */
91
+ readonly status?: string;
92
+ }
93
+ /** Called repeatedly while a long operation runs. Must never throw. */
94
+ export type ProgressCallback = (progress: Progress) => void;
95
+ /** Options every SDK method accepts as its last argument. */
96
+ export interface RequestOptions {
97
+ /**
98
+ * Caller-owned cancellation. Aborting raises an {@link OmsTimeoutError} with
99
+ * `code === "aborted"`.
100
+ */
101
+ readonly signal?: AbortSignal;
102
+ /**
103
+ * Deadline in milliseconds for the whole call, retries included. Overrides
104
+ * the client default. `0` disables the deadline.
105
+ */
106
+ readonly timeoutMs?: number;
107
+ /** Extra request headers. Merged over the client's, under `Authorization`. */
108
+ readonly headers?: Record<string, string>;
109
+ /**
110
+ * Per-call retry override. `false` disables retries entirely - pass it for
111
+ * any non-idempotent create you would rather see fail than duplicate.
112
+ */
113
+ readonly retry?: RetryOptions | false;
114
+ }
115
+ /** Options for a method that both uploads and waits. */
116
+ export interface OperationOptions extends RequestOptions {
117
+ /** Called as bytes move and as the server-side job advances. */
118
+ readonly onProgress?: ProgressCallback;
119
+ }
120
+ /** Backoff configuration. See {@link DEFAULT_RETRY}. */
121
+ export interface RetryOptions {
122
+ /** Total attempts including the first. `1` disables retrying. */
123
+ readonly maxAttempts?: number;
124
+ /** First backoff step in milliseconds; doubles each attempt. */
125
+ readonly baseDelayMs?: number;
126
+ /** Ceiling for a single backoff step. */
127
+ readonly maxDelayMs?: number;
128
+ /** Randomise each delay in `[0.5x, 1.5x]` to avoid a thundering herd. */
129
+ readonly jitter?: boolean;
130
+ }
131
+ /** Fully-resolved backoff configuration. */
132
+ export interface ResolvedRetry {
133
+ readonly maxAttempts: number;
134
+ readonly baseDelayMs: number;
135
+ readonly maxDelayMs: number;
136
+ readonly jitter: boolean;
137
+ }
138
+ /** Defaults applied when a caller says nothing about retrying. */
139
+ export declare const DEFAULT_RETRY: ResolvedRetry;
140
+ /**
141
+ * Query parameters. Nested objects and arrays are encoded the way Rails reads
142
+ * them (`search[status]=open`, `ids[]=1&ids[]=2`) - see `encodeQuery` in
143
+ * `http.ts`. `undefined` and `null` values are dropped, not sent as empty.
144
+ */
145
+ export type QueryValue = string | number | boolean | null | undefined | QueryValue[] | {
146
+ [key: string]: QueryValue;
147
+ };
148
+ /** A bag of query parameters. */
149
+ export type QueryParams = Record<string, QueryValue>;
150
+ /**
151
+ * Paging arguments accepted by every `list()` method.
152
+ *
153
+ * The backend pages with a single `modifiers[page]=<number>:<size>` string and
154
+ * caps `size` at 500. It does NOT return a total count, which is why
155
+ * {@link Paginated} has `hasMore` and no `total`.
156
+ */
157
+ export interface PageParams {
158
+ /** 1-based page number. Defaults to 1. */
159
+ readonly page?: number;
160
+ /** Items per page. Server maximum is 500. */
161
+ readonly pageSize?: number;
162
+ /** `"column:asc"` or `"column:desc"`, passed through as `modifiers[order]`. */
163
+ readonly order?: string;
164
+ }
165
+ /**
166
+ * One page of a listing.
167
+ *
168
+ * There is no `total`: the API answers index requests with a bare JSON array
169
+ * and no count, so a total would be a lie. `hasMore` is inferred from the page
170
+ * having come back full, which means the last page can report `hasMore: true`
171
+ * once and then yield an empty page. Iterate with {@link collect} or
172
+ * {@link pages} rather than trusting `hasMore` as an exact count.
173
+ */
174
+ export interface Paginated<T> {
175
+ /** The items on this page. */
176
+ readonly items: T[];
177
+ /** 1-based number of this page. */
178
+ readonly page: number;
179
+ /** Page size that was requested. */
180
+ readonly pageSize: number;
181
+ /** True when this page came back full, so another page may exist. */
182
+ readonly hasMore: boolean;
183
+ /** Fetches the following page, or resolves to `null` when there is none. */
184
+ next(): Promise<Paginated<T> | null>;
185
+ }
186
+ /** Loads one page. Given to {@link createPage} by a resource's `list()`. */
187
+ export type PageLoader<T> = (params: Required<Pick<PageParams, "page" | "pageSize">>) => Promise<T[]>;
188
+ /**
189
+ * Builds a {@link Paginated} from the raw array the API returned plus the
190
+ * loader that can fetch the next page. Resource modules use this instead of
191
+ * hand-rolling the shape.
192
+ */
193
+ export declare function createPage<T>(items: T[], page: number, pageSize: number, load: PageLoader<T>): Paginated<T>;
194
+ /** Walks every page of a listing, yielding one page at a time. */
195
+ export declare function pages<T>(first: Paginated<T>): AsyncGenerator<Paginated<T>, void, undefined>;
196
+ /**
197
+ * Walks every page and returns every item.
198
+ *
199
+ * @param limit Stop once this many items are collected. Always pass one when
200
+ * the listing could be unbounded; the caller, not the server, owns the cap.
201
+ */
202
+ export declare function collect<T>(first: Paginated<T>, limit?: number): Promise<T[]>;
203
+ /**
204
+ * Identifier of a record. The API uses opaque random strings, not integers, so
205
+ * never do arithmetic on one and never assume it sorts by creation.
206
+ */
207
+ export type Id = string;
208
+ /** ISO-8601 timestamp string, as the API sends it. */
209
+ export type Timestamp = string;
210
+ /** Fields present on essentially every record the API returns. */
211
+ export interface BaseRecord {
212
+ readonly id: Id;
213
+ readonly created_at: Timestamp;
214
+ readonly updated_at: Timestamp;
215
+ }
216
+ /**
217
+ * A daily quota answer. Every metered tool exposes one, but the unit differs
218
+ * (seconds for audio, edits for jumpstyle), so the concrete resource narrows
219
+ * this with its own interface.
220
+ */
221
+ export interface QuotaStatus {
222
+ /** Whether the caller was recognised. Anonymous callers get a smaller quota. */
223
+ readonly authenticated: boolean;
224
+ /** `true` when the account has no ceiling; the numeric fields are then meaningless. */
225
+ readonly unlimited: boolean;
226
+ }
227
+ /**
228
+ * How a long-running server-side job reports itself.
229
+ *
230
+ * These are the five strings `Job::STATUSES` holds, spelled exactly as the
231
+ * backend spells them: `"complete"` and `"canceled"`, not `"completed"` and
232
+ * `"cancelled"`. Compare against `JOB_STATUS` / `isJobTerminal` from the jobs
233
+ * namespace rather than against a literal you typed from memory - a wait loop
234
+ * that tests for `"completed"` never ends.
235
+ */
236
+ export type JobStatus = "pending" | "processing" | "complete" | "failed" | "canceled";
237
+ /** Options for the SDK helpers that poll a job to completion. */
238
+ export interface WaitOptions extends RequestOptions {
239
+ /** Called on each poll with the job's current state. */
240
+ readonly onProgress?: ProgressCallback;
241
+ /** Milliseconds between polls. Defaults to a bounded, backing-off interval. */
242
+ readonly pollIntervalMs?: number;
243
+ /** Give up after this long. Distinct from `timeoutMs`, which bounds one HTTP call. */
244
+ readonly waitTimeoutMs?: number;
245
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@omelhorsite/sdk",
3
+ "version": "0.1.0",
4
+ "description": "TypeScript SDK for the omelhorsite API. Isolate-safe: no node builtins, no environment access, no stdout.",
5
+ "type": "module",
6
+ "license": "UNLICENSED",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/types/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "types": "./dist/types/index.d.ts",
15
+ "main": "./dist/index.js",
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "typecheck": "tsc --noEmit -p .",
21
+ "check:isolate": "bun run scripts/check-isolate.ts",
22
+ "test": "bun run check:isolate && bun test",
23
+ "build": "bun build src/index.ts --target node --format esm --outdir dist --external uqr && tsc -p tsconfig.build.json",
24
+ "prepublishOnly": "bun run build"
25
+ },
26
+ "devDependencies": {
27
+ "typescript": "^5.9.3"
28
+ },
29
+ "dependencies": {
30
+ "uqr": "^0.1.3"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/afonsopc/omelhorsite.git",
35
+ "directory": "apps/cli/packages/core"
36
+ }
37
+ }