@hermoso/sdk 0.0.0-stage → 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 (39) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +86 -2
  3. package/dist/gen/client/client.gen.d.ts +2 -0
  4. package/dist/gen/client/client.gen.js +216 -0
  5. package/dist/gen/client/index.d.ts +10 -0
  6. package/dist/gen/client/index.js +6 -0
  7. package/dist/gen/client/types.gen.d.ts +120 -0
  8. package/dist/gen/client/types.gen.js +2 -0
  9. package/dist/gen/client/utils.gen.d.ts +37 -0
  10. package/dist/gen/client/utils.gen.js +228 -0
  11. package/dist/gen/client.gen.d.ts +12 -0
  12. package/dist/gen/client.gen.js +3 -0
  13. package/dist/gen/core/auth.gen.d.ts +25 -0
  14. package/dist/gen/core/auth.gen.js +14 -0
  15. package/dist/gen/core/bodySerializer.gen.d.ts +25 -0
  16. package/dist/gen/core/bodySerializer.gen.js +57 -0
  17. package/dist/gen/core/params.gen.d.ts +43 -0
  18. package/dist/gen/core/params.gen.js +109 -0
  19. package/dist/gen/core/pathSerializer.gen.d.ts +33 -0
  20. package/dist/gen/core/pathSerializer.gen.js +106 -0
  21. package/dist/gen/core/queryKeySerializer.gen.d.ts +18 -0
  22. package/dist/gen/core/queryKeySerializer.gen.js +92 -0
  23. package/dist/gen/core/serverSentEvents.gen.d.ts +71 -0
  24. package/dist/gen/core/serverSentEvents.gen.js +132 -0
  25. package/dist/gen/core/types.gen.d.ts +83 -0
  26. package/dist/gen/core/types.gen.js +2 -0
  27. package/dist/gen/core/utils.gen.d.ts +19 -0
  28. package/dist/gen/core/utils.gen.js +87 -0
  29. package/dist/gen/index.d.ts +2 -0
  30. package/dist/gen/index.js +2 -0
  31. package/dist/gen/sdk.gen.d.ts +433 -0
  32. package/dist/gen/sdk.gen.js +771 -0
  33. package/dist/gen/spec.gen.d.ts +4 -0
  34. package/dist/gen/spec.gen.js +5 -0
  35. package/dist/gen/types.gen.d.ts +4621 -0
  36. package/dist/gen/types.gen.js +2 -0
  37. package/dist/index.d.ts +75 -0
  38. package/dist/index.js +101 -0
  39. package/package.json +51 -4
@@ -0,0 +1,2 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export {};
@@ -0,0 +1,75 @@
1
+ import { type Client } from './gen/client/index.js';
2
+ import type { Job, ToolResult, ToolJob } from './gen/types.gen.js';
3
+ export * from './gen/sdk.gen.js';
4
+ export type * from './gen/types.gen.js';
5
+ export { createClient, createConfig } from './gen/client/index.js';
6
+ export type { Client, Config, Options as RequestOptions } from './gen/client/index.js';
7
+ export { SPEC_SHA256, CONTRACT_VERSION } from './gen/spec.gen.js';
8
+ export declare const DEFAULT_BASE_URL = "https://app.hermoso.ai";
9
+ /** An error body from the API (`{ error: { type, code, message, … } }`), thrown by the helpers in this file. */
10
+ export declare class HermosoError extends Error {
11
+ readonly status: number | undefined;
12
+ readonly body: unknown;
13
+ constructor(body: unknown, status?: number);
14
+ }
15
+ export interface HermosoClientOptions {
16
+ /** A Hermoso API key (`hmk_…`). Defaults to the HERMOSO_API_KEY environment variable. */
17
+ apiKey?: string;
18
+ /** Act on this brand (an `id` from `listBrands`) instead of the one the key is pinned to. Sent as `X-Hermoso-User`. */
19
+ brand?: string;
20
+ /** Defaults to https://app.hermoso.ai. */
21
+ baseUrl?: string;
22
+ /** A custom fetch, e.g. for proxies or tests. */
23
+ fetch?: typeof fetch;
24
+ }
25
+ /**
26
+ * A client authenticated with your API key. Pass it as `client` to any operation:
27
+ *
28
+ * const hermoso = createHermosoClient();
29
+ * const { data } = await listChannels({ client: hermoso });
30
+ */
31
+ export declare function createHermosoClient(options?: HermosoClientOptions): Client;
32
+ type Page<T> = {
33
+ data?: T[];
34
+ has_more?: boolean;
35
+ next_cursor?: string | null;
36
+ };
37
+ type ListFn<O, T> = (options: O) => Promise<{
38
+ data?: Page<T> | undefined;
39
+ error?: unknown;
40
+ response?: Response;
41
+ }>;
42
+ /**
43
+ * Iterate every item of a cursor-paginated list (`listPosts`, `listJobs`, `listTools`, `listConversionEvents`),
44
+ * following `next_cursor` until `has_more` is false:
45
+ *
46
+ * for await (const post of paginate(listPosts, { client: hermoso, query: { status: 'scheduled' } })) { … }
47
+ *
48
+ * `listConversionEvents` takes its cursor as `cursor`; every other list takes `starting_after`. That is detected.
49
+ */
50
+ export declare function paginate<O extends {
51
+ query?: object;
52
+ }, T>(fn: ListFn<O, T>, options: O, { cursorParam }?: {
53
+ cursorParam?: string;
54
+ }): AsyncGenerator<T>;
55
+ /**
56
+ * Poll a job (a render, a stitch, an upscale…) until it is `done` or `error`, and return it. A finished job's file is
57
+ * `job.url`. Polling is free; re-calling the tool that started the job would start (and bill) a second one.
58
+ */
59
+ export declare function waitForJob(id: string, { client, intervalMs, timeoutMs }?: {
60
+ client?: Client;
61
+ intervalMs?: number;
62
+ timeoutMs?: number;
63
+ }): Promise<Job>;
64
+ /**
65
+ * Run any Hermoso tool through `POST /v1/tools/{name}` with its arguments, and get its result. When the tool starts
66
+ * a render, the result is a job handle: pass `job_id` to `waitForJob`. `GET /v1/tools/{name}` describes each tool's
67
+ * arguments.
68
+ *
69
+ * const plan = await runTool('plan_ad', { product: 'our cold brew, summer offer', format: 'video' }, { client: hermoso });
70
+ */
71
+ export declare function runTool(name: string, args?: Record<string, unknown>, { client, wait, idempotencyKey }?: {
72
+ client?: Client;
73
+ wait?: number;
74
+ idempotencyKey?: string;
75
+ }): Promise<ToolResult | ToolJob>;
package/dist/index.js ADDED
@@ -0,0 +1,101 @@
1
+ // @hermoso/sdk: the typed client for the Hermoso API (https://hermoso.ai/docs/api/).
2
+ //
3
+ // Everything under ./gen is GENERATED from the /v1 OpenAPI document by tools/sdk-generate.mjs and must not be edited.
4
+ // This file is the small hand-written layer on top: a client that reads your key, a cursor paginator, a job waiter
5
+ // and a one-line tool call.
6
+ import { createClient, createConfig } from './gen/client/index.js';
7
+ import { getJob, callTool } from './gen/sdk.gen.js';
8
+ export * from './gen/sdk.gen.js';
9
+ export { createClient, createConfig } from './gen/client/index.js';
10
+ export { SPEC_SHA256, CONTRACT_VERSION } from './gen/spec.gen.js';
11
+ export const DEFAULT_BASE_URL = 'https://app.hermoso.ai';
12
+ /** An error body from the API (`{ error: { type, code, message, … } }`), thrown by the helpers in this file. */
13
+ export class HermosoError extends Error {
14
+ status;
15
+ body;
16
+ constructor(body, status) {
17
+ const e = body?.error;
18
+ super(e?.message || `Hermoso API error${status ? ` (HTTP ${status})` : ''}`);
19
+ this.name = 'HermosoError';
20
+ this.status = status;
21
+ this.body = body;
22
+ }
23
+ }
24
+ const env = (k) => globalThis.process?.env?.[k];
25
+ /**
26
+ * A client authenticated with your API key. Pass it as `client` to any operation:
27
+ *
28
+ * const hermoso = createHermosoClient();
29
+ * const { data } = await listChannels({ client: hermoso });
30
+ */
31
+ export function createHermosoClient(options = {}) {
32
+ const apiKey = options.apiKey ?? env('HERMOSO_API_KEY');
33
+ if (!apiKey)
34
+ throw new Error('No Hermoso API key: pass { apiKey } or set HERMOSO_API_KEY. Create one at https://app.hermoso.ai on the "API, MCP & CLI" tab, under "Terminal & API keys".');
35
+ return createClient(createConfig({
36
+ baseUrl: options.baseUrl ?? DEFAULT_BASE_URL,
37
+ auth: () => apiKey,
38
+ ...(options.brand ? { headers: { 'X-Hermoso-User': options.brand } } : {}),
39
+ ...(options.fetch ? { fetch: options.fetch } : {}),
40
+ }));
41
+ }
42
+ /**
43
+ * Iterate every item of a cursor-paginated list (`listPosts`, `listJobs`, `listTools`, `listConversionEvents`),
44
+ * following `next_cursor` until `has_more` is false:
45
+ *
46
+ * for await (const post of paginate(listPosts, { client: hermoso, query: { status: 'scheduled' } })) { … }
47
+ *
48
+ * `listConversionEvents` takes its cursor as `cursor`; every other list takes `starting_after`. That is detected.
49
+ */
50
+ export async function* paginate(fn, options, { cursorParam } = {}) {
51
+ const param = cursorParam ?? (fn.name === 'listConversionEvents' ? 'cursor' : 'starting_after');
52
+ let cursor;
53
+ for (;;) {
54
+ const opts = cursor ? { ...options, query: { ...(options.query || {}), [param]: cursor } } : options;
55
+ const res = await fn(opts);
56
+ if (res.error !== undefined || !res.data)
57
+ throw new HermosoError(res.error, res.response?.status);
58
+ for (const item of res.data.data || [])
59
+ yield item;
60
+ cursor = res.data.next_cursor;
61
+ if (!cursor || res.data.has_more === false)
62
+ return;
63
+ }
64
+ }
65
+ /**
66
+ * Poll a job (a render, a stitch, an upscale…) until it is `done` or `error`, and return it. A finished job's file is
67
+ * `job.url`. Polling is free; re-calling the tool that started the job would start (and bill) a second one.
68
+ */
69
+ export async function waitForJob(id, { client, intervalMs = 5000, timeoutMs = 20 * 60_000 } = {}) {
70
+ const until = Date.now() + timeoutMs;
71
+ for (;;) {
72
+ const res = await getJob({ client, path: { id } });
73
+ if (res.error !== undefined || !res.data)
74
+ throw new HermosoError(res.error, res.response?.status);
75
+ const job = res.data;
76
+ if (job.status === 'done' || job.status === 'error')
77
+ return job;
78
+ if (Date.now() > until)
79
+ throw new Error(`Job ${id} is still ${job.status} after ${Math.round(timeoutMs / 1000)}s. It keeps running: call waitForJob again.`);
80
+ await new Promise((r) => setTimeout(r, intervalMs));
81
+ }
82
+ }
83
+ /**
84
+ * Run any Hermoso tool through `POST /v1/tools/{name}` with its arguments, and get its result. When the tool starts
85
+ * a render, the result is a job handle: pass `job_id` to `waitForJob`. `GET /v1/tools/{name}` describes each tool's
86
+ * arguments.
87
+ *
88
+ * const plan = await runTool('plan_ad', { product: 'our cold brew, summer offer', format: 'video' }, { client: hermoso });
89
+ */
90
+ export async function runTool(name, args = {}, { client, wait, idempotencyKey } = {}) {
91
+ const res = await callTool({
92
+ client,
93
+ path: { name },
94
+ body: args,
95
+ ...(wait !== undefined ? { query: { wait: String(wait) } } : {}),
96
+ ...(idempotencyKey ? { headers: { 'Idempotency-Key': idempotencyKey } } : {}),
97
+ });
98
+ if (res.error !== undefined || !res.data)
99
+ throw new HermosoError(res.error, res.response?.status);
100
+ return res.data;
101
+ }
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "@hermoso/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Typed TypeScript client for the Hermoso API: generate ads, publish and schedule posts, read analytics, and call every Hermoso tool from your own backend.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "sideEffects": false,
20
+ "engines": {
21
+ "node": ">=18"
22
+ },
23
+ "scripts": {
24
+ "build": "tsc -p tsconfig.json",
25
+ "prepublishOnly": "npm run build"
26
+ },
27
+ "devDependencies": {
28
+ "typescript": "5.9.3"
29
+ },
30
+ "keywords": [
31
+ "hermoso",
32
+ "api",
33
+ "sdk",
34
+ "openapi",
35
+ "ads",
36
+ "ad generation",
37
+ "social media",
38
+ "scheduling",
39
+ "marketing",
40
+ "typescript"
41
+ ],
42
+ "homepage": "https://hermoso.ai/docs/sdks/",
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/hermoso-ai/hermoso-sdks.git",
46
+ "directory": "typescript"
47
+ },
48
+ "bugs": {
49
+ "url": "https://github.com/hermoso-ai/hermoso-sdks/issues"
50
+ },
51
+ "author": "Hermoso <hello@hermoso.ai> (https://hermoso.ai)",
52
+ "license": "MIT"
53
+ }