@unboundcx/sdk 4.12.0 → 4.13.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboundcx/sdk",
3
- "version": "4.12.0",
3
+ "version": "4.13.0",
4
4
  "description": "Official JavaScript SDK for the Unbound API - A comprehensive toolkit for integrating with Unbound's communication, AI, and data management services",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -0,0 +1,116 @@
1
+ import { internalRequest } from '../../base.js';
2
+
3
+ function pickDefined(fields) {
4
+ const body = {};
5
+ for (const [key, value] of Object.entries(fields)) {
6
+ if (value !== undefined) body[key] = value;
7
+ }
8
+ return body;
9
+ }
10
+
11
+ /**
12
+ * Email generation via SpaceXAI. `sdk.ai.email.*`.
13
+ *
14
+ * @see app1-api src/services/ai/routes/email.js
15
+ */
16
+ export class EmailService {
17
+ constructor(sdk) {
18
+ this.sdk = sdk;
19
+ }
20
+
21
+ /**
22
+ * Generate or revise an email as a block-tree document.
23
+ *
24
+ * @param {Object} params
25
+ * @param {string} params.prompt - Generation prompt (required)
26
+ * @param {string} [params.brandKitId] - Brand kit to apply
27
+ * @param {string} [params.appearance] - `client` or `marketing`
28
+ * @param {Object|Array} [params.tree] - Existing block tree to revise
29
+ * @returns {Promise<Object>} `{ tree }`
30
+ */
31
+ async generate({ prompt, brandKitId, appearance, tree } = {}) {
32
+ this.sdk.validateParams(
33
+ { prompt, brandKitId, appearance, tree },
34
+ {
35
+ prompt: { type: 'string', required: true },
36
+ brandKitId: { type: 'string', required: false },
37
+ appearance: { type: 'string', required: false },
38
+ tree: { type: 'object', required: false },
39
+ },
40
+ );
41
+
42
+ return internalRequest(this.sdk, '/ai/email/generate', 'POST', {
43
+ body: pickDefined({ prompt, brandKitId, appearance, tree }),
44
+ });
45
+ }
46
+
47
+ /**
48
+ * Rewrite email copy.
49
+ *
50
+ * @param {Object} params
51
+ * @param {string} params.text - Source copy (required)
52
+ * @param {string} params.instruction - `tone` | `shorten` | `expand` | `translate`
53
+ * @param {string} [params.lang] - Target language (required when `translate`)
54
+ * @returns {Promise<Object>} `{ text }`
55
+ */
56
+ async rewrite({ text, instruction, lang } = {}) {
57
+ this.sdk.validateParams(
58
+ { text, instruction, lang },
59
+ {
60
+ text: { type: 'string', required: true },
61
+ instruction: { type: 'string', required: true },
62
+ lang: { type: 'string', required: false },
63
+ },
64
+ );
65
+
66
+ return internalRequest(this.sdk, '/ai/email/rewrite', 'POST', {
67
+ body: pickDefined({ text, instruction, lang }),
68
+ });
69
+ }
70
+
71
+ /**
72
+ * Generate subject + preheader variants.
73
+ *
74
+ * @param {Object} params
75
+ * @param {string} [params.html] - Rendered email HTML
76
+ * @param {string} [params.prompt] - Prompt describing the email
77
+ * @param {number} [params.n] - Variant count (1–5, default 3)
78
+ * @returns {Promise<Object>} `{ variants: [{ subject, preheader }] }`
79
+ */
80
+ async subjects({ html, prompt, n } = {}) {
81
+ this.sdk.validateParams(
82
+ { html, prompt, n },
83
+ {
84
+ html: { type: 'string', required: false },
85
+ prompt: { type: 'string', required: false },
86
+ n: { type: 'number', required: false },
87
+ },
88
+ );
89
+
90
+ return internalRequest(this.sdk, '/ai/email/subjects', 'POST', {
91
+ body: pickDefined({ html, prompt, n }),
92
+ });
93
+ }
94
+
95
+ /**
96
+ * Generate image alt text.
97
+ *
98
+ * @param {Object} params
99
+ * @param {string} [params.imageUrl] - https or data:image URL
100
+ * @param {string} [params.description] - Image description
101
+ * @returns {Promise<Object>} `{ alt }`
102
+ */
103
+ async altText({ imageUrl, description } = {}) {
104
+ this.sdk.validateParams(
105
+ { imageUrl, description },
106
+ {
107
+ imageUrl: { type: 'string', required: false },
108
+ description: { type: 'string', required: false },
109
+ },
110
+ );
111
+
112
+ return internalRequest(this.sdk, '/ai/email/alt-text', 'POST', {
113
+ body: pickDefined({ imageUrl, description }),
114
+ });
115
+ }
116
+ }
package/services/ai.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { internalRequest } from '../base.js';
2
2
  import { PlaybooksService } from './ai/playbooks.js';
3
3
  import { VocabularyService } from './ai/vocabulary.js';
4
+ import { EmailService } from './ai/email.js';
4
5
  import { translate as translateItems } from './ai/translate.js';
5
6
  import {
6
7
  getSettings as getAiSettings,
@@ -16,6 +17,7 @@ export class AIService {
16
17
  this.extract = new ExtractService(sdk);
17
18
  this.playbooks = new PlaybooksService(sdk);
18
19
  this.vocabulary = new VocabularyService(sdk);
20
+ this.email = new EmailService(sdk);
19
21
  }
20
22
 
21
23
  /**