@wavebirdai/api 0.1.0-beta.4 → 0.1.0-beta.6

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/README.md CHANGED
@@ -9,7 +9,7 @@ You need a saved Wavebird Test project and placement in Dashboard, a Server Test
9
9
  1. Install the package and generate the route files for your app directory:
10
10
 
11
11
  ```sh
12
- npm install @wavebirdai/api@0.1.0-beta.4
12
+ npm install @wavebirdai/api@0.1.0-beta.6
13
13
  ./node_modules/.bin/wavebird-next init --lang ts --root . --app-dir src/app
14
14
  ```
15
15
 
package/dist/browser.d.ts CHANGED
@@ -14,7 +14,7 @@ export function createPublisherAds(options: {
14
14
  target: HTMLElement;
15
15
  clientId: string;
16
16
  surfaceId: string;
17
- jobType: string;
17
+ jobType: "chat" | "code" | "image" | "voice" | "agent";
18
18
  userId: string;
19
19
  conversationId: string;
20
20
  /** Opt-in successor contract: a session ID supplied by the host's authenticated context. */
package/dist/browser.js CHANGED
@@ -21,6 +21,7 @@ function loadRenderer(url) {
21
21
  export function createPublisherAds(options) {
22
22
  const target = options.target;
23
23
  if (!target || !options.userId || !options.conversationId) throw new Error("Application container and session are required");
24
+ if (!["chat", "code", "image", "voice", "agent"].includes(options.jobType)) throw new Error("publisher_job_invalid");
24
25
  const turnBinding = options.turnBinding === true;
25
26
  const validId = value => typeof value === "string" && /^[A-Za-z0-9_-]{1,128}$/.test(value);
26
27
  if (turnBinding && !validId(options.sessionId)) throw new Error("publisher_trusted_session_required");
@@ -152,7 +153,7 @@ export function createPublisherAds(options) {
152
153
  if (typeof record.data !== "string" || record.data.length > 21848 || !/^[A-Za-z0-9+/]*={0,2}$/.test(record.data)) throw new Error("generation_bytes_invalid");
153
154
  const raw = atob(record.data), bytes = Uint8Array.from(raw, value => value.charCodeAt(0));
154
155
  controller.enqueue(bytes);
155
- if (timing !== "before" && !["image", "image_generation"].includes(options.jobType)) event(job, "progress");
156
+ if (timing !== "before" && options.jobType !== "image") event(job, "progress");
156
157
  return;
157
158
  }
158
159
  if (["done", "error", "abort"].includes(record.type)) {
package/dist/server.d.ts CHANGED
@@ -43,7 +43,7 @@ export type PublisherServerOptions = {
43
43
  publicOrigins: string[];
44
44
  surfaceId: string;
45
45
  placementKey: string;
46
- jobType: string;
46
+ jobType: "chat" | "code" | "image" | "voice" | "agent";
47
47
  locale: string;
48
48
  timing: "before" | "during" | "after";
49
49
  consentMode: "wavebird_consent" | "own_cmp";
package/dist/server.js CHANGED
@@ -24,16 +24,19 @@ function normalizeOptions(options) {
24
24
  if (typeof window !== "undefined") throw new Error("publisher_server_only");
25
25
  if (options && Object.keys(options).some(key => !SERVER_OPTION_KEYS.has(key))) throw new Error("publisher_option_unknown");
26
26
  if (!options || typeof options.authorize !== "function") throw new Error("publisher_authorize_required");
27
+ if (typeof options.preferenceSecret !== "string" || new TextEncoder().encode(options.preferenceSecret).byteLength < 32) throw new Error("preference_secret_required");
27
28
  if ((options.turnJournal === undefined) !== (options.sessionIdForRequest === undefined) ||
28
29
  (options.turnJournal !== undefined && (typeof options.sessionIdForRequest !== "function" ||
29
30
  ["claimPlacement", "releaseRejectedPlacement", "bind", "claimGeneration", "phase"].some(name => typeof options.turnJournal?.[name] !== "function"))))
30
31
  throw new Error("publisher_turn_journal_invalid");
31
- if (!String(options.clientId || "").startsWith("wbproj_")) throw new Error("publisher_project_invalid");
32
- if (!String(options.secretKey || "").trim()) throw new Error("publisher_server_key_required");
32
+ if (typeof options.clientId !== "string" || !options.clientId.startsWith("wbproj_")) throw new Error("publisher_project_invalid");
33
+ if (typeof options.secretKey !== "string") throw new Error("publisher_server_key_invalid");
34
+ if (!options.secretKey.trim()) throw new Error("publisher_server_key_required");
33
35
  if (!/^sk_(?:test|live)_/.test(options.secretKey)) throw new Error("publisher_server_key_invalid");
34
- if (!ID.test(options.surfaceId || "") || !PLACEMENT_KEY.test(options.placementKey || "")) throw new Error("publisher_placement_invalid");
36
+ if (typeof options.surfaceId !== "string" || typeof options.placementKey !== "string" || !ID.test(options.surfaceId) || !PLACEMENT_KEY.test(options.placementKey)) throw new Error("publisher_placement_invalid");
35
37
  if (!["before", "during", "after"].includes(options.timing)) throw new Error("publisher_timing_invalid");
36
38
  if (!["wavebird_consent", "own_cmp"].includes(options.consentMode)) throw new Error("publisher_consent_mode_invalid");
39
+ if (options.gdprApplies !== undefined && typeof options.gdprApplies !== "boolean") throw new Error("publisher_gdpr_invalid");
37
40
  if (!Array.isArray(options.allowedFormats) || options.allowedFormats.length === 0 || options.allowedFormats.some(value => !["banner", "native", "clip"].includes(value))) throw new Error("publisher_formats_invalid");
38
41
  if (!["above", "below", "sidebar", "between"].includes(options.positionHint)) throw new Error("publisher_position_invalid");
39
42
  if (!Array.isArray(options.allowedSizes) || options.allowedSizes.length === 0 || options.allowedSizes.some(size => !size || typeof size !== "object" || Object.keys(size).some(key => !["width", "height", "formats"].includes(key)) || !Number.isSafeInteger(size.width) || !Number.isSafeInteger(size.height) || size.width < 1 || size.height < 1 ||
@@ -47,8 +50,15 @@ function normalizeOptions(options) {
47
50
  if (hasFloor !== hasCurrency || (hasFloor && (!Number.isFinite(options.bidfloor) || options.bidfloor < 0 || typeof options.bidfloorCurrency !== "string" || !/^[A-Za-z]{3}$/.test(options.bidfloorCurrency))))
48
51
  throw new Error("publisher_bidfloor_override_invalid");
49
52
  if (options.responsiveSizeSelection !== undefined && typeof options.responsiveSizeSelection !== "boolean") throw new Error("publisher_responsive_selection_invalid");
50
- if (!options.publisher || typeof options.publisher !== "object" || Object.keys(options.publisher).some(key => !["app_name", "app_domain", "categories"].includes(key)) || typeof options.publisher.app_name !== "string" || typeof options.publisher.app_domain !== "string" || !Array.isArray(options.publisher.categories)) throw new Error("publisher_identity_invalid");
51
- if (typeof options.jobType !== "string" || !options.jobType || typeof options.locale !== "string" || !options.locale) throw new Error("publisher_job_invalid");
53
+ if (!options.publisher || typeof options.publisher !== "object" || Object.keys(options.publisher).some(key => !["app_name", "app_domain", "categories"].includes(key)) ||
54
+ typeof options.publisher.app_name !== "string" || !options.publisher.app_name.trim() ||
55
+ typeof options.publisher.app_domain !== "string" || !options.publisher.app_domain.trim() ||
56
+ !Array.isArray(options.publisher.categories) ||
57
+ options.publisher.categories.some(value => typeof value !== "string" || !value.trim())) throw new Error("publisher_identity_invalid");
58
+ if (options.blockedCategories !== undefined && (!Array.isArray(options.blockedCategories) ||
59
+ options.blockedCategories.some(value => typeof value !== "string" || !value.trim())))
60
+ throw new Error("publisher_blocked_categories_invalid");
61
+ if (!["chat", "code", "image", "voice", "agent"].includes(options.jobType) || typeof options.locale !== "string" || !options.locale) throw new Error("publisher_job_invalid");
52
62
  const base = String(options.apiBaseUrl || "https://api.wavebird.ai").trim().replace(/\/+$/, "").replace(/\/v1$/, "") + "/v1";
53
63
  if (!/^https:\/\//.test(base)) throw new Error("publisher_api_https_required");
54
64
  {
@@ -262,7 +272,7 @@ export function createPublisherServer(inputOptions) {
262
272
  const scope = request => ({ project: options.clientId, surface: options.surfaceId, version: PREFERENCE_VERSION,
263
273
  profile: options.consentMode === "wavebird_consent" ? "wavebird_dialog" : "publisher_custom", origin: publicOrigin(request, options) });
264
274
  async function preferenceKey() {
265
- if (!options.preferenceSecret || options.preferenceSecret.length < 32) throw new Error("preference_secret_required");
275
+ if (new TextEncoder().encode(options.preferenceSecret).byteLength < 32) throw new Error("preference_secret_required");
266
276
  return crypto.subtle.importKey("raw", new TextEncoder().encode(options.preferenceSecret), { name: "HMAC", hash: "SHA-256" }, false, ["sign", "verify"]);
267
277
  }
268
278
  async function signPreference(request, state) {
@@ -326,7 +336,6 @@ export function createPublisherServer(inputOptions) {
326
336
  allowed_sizes: allowedSizes, presentation_version: "sponsored_moment_v2" },
327
337
  overrides: { allowed_formats: allowedFormats, timing: options.timing,
328
338
  ...(Object.hasOwn(options, "bidfloor") ? { bidfloor: options.bidfloor, bidfloor_currency: options.bidfloorCurrency.toUpperCase() } : {}),
329
- gdpr_applies: options.gdprApplies === true,
330
339
  publisher: { app_name: options.publisher.app_name, app_domain: options.publisher.app_domain,
331
340
  ...(options.publisher.categories.length ? { categories: options.publisher.categories } : {}) },
332
341
  ...(options.blockedCategories?.length ? { blocked_categories: options.blockedCategories } : {}) },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wavebirdai/api",
3
- "version": "0.1.0-beta.4",
3
+ "version": "0.1.0-beta.6",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Integrate Banner, Native, and Clip placements into authenticated chat apps with server-side keys, consent, and generation lifecycle handling",
package/src/browser.d.ts CHANGED
@@ -14,7 +14,7 @@ export function createPublisherAds(options: {
14
14
  target: HTMLElement;
15
15
  clientId: string;
16
16
  surfaceId: string;
17
- jobType: string;
17
+ jobType: "chat" | "code" | "image" | "voice" | "agent";
18
18
  userId: string;
19
19
  conversationId: string;
20
20
  /** Opt-in successor contract: a session ID supplied by the host's authenticated context. */
package/src/browser.js CHANGED
@@ -21,6 +21,7 @@ function loadRenderer(url) {
21
21
  export function createPublisherAds(options) {
22
22
  const target = options.target;
23
23
  if (!target || !options.userId || !options.conversationId) throw new Error("Application container and session are required");
24
+ if (!["chat", "code", "image", "voice", "agent"].includes(options.jobType)) throw new Error("publisher_job_invalid");
24
25
  const turnBinding = options.turnBinding === true;
25
26
  const validId = value => typeof value === "string" && /^[A-Za-z0-9_-]{1,128}$/.test(value);
26
27
  if (turnBinding && !validId(options.sessionId)) throw new Error("publisher_trusted_session_required");
@@ -152,7 +153,7 @@ export function createPublisherAds(options) {
152
153
  if (typeof record.data !== "string" || record.data.length > 21848 || !/^[A-Za-z0-9+/]*={0,2}$/.test(record.data)) throw new Error("generation_bytes_invalid");
153
154
  const raw = atob(record.data), bytes = Uint8Array.from(raw, value => value.charCodeAt(0));
154
155
  controller.enqueue(bytes);
155
- if (timing !== "before" && !["image", "image_generation"].includes(options.jobType)) event(job, "progress");
156
+ if (timing !== "before" && options.jobType !== "image") event(job, "progress");
156
157
  return;
157
158
  }
158
159
  if (["done", "error", "abort"].includes(record.type)) {
package/src/server.d.ts CHANGED
@@ -43,7 +43,7 @@ export type PublisherServerOptions = {
43
43
  publicOrigins: string[];
44
44
  surfaceId: string;
45
45
  placementKey: string;
46
- jobType: string;
46
+ jobType: "chat" | "code" | "image" | "voice" | "agent";
47
47
  locale: string;
48
48
  timing: "before" | "during" | "after";
49
49
  consentMode: "wavebird_consent" | "own_cmp";
package/src/server.js CHANGED
@@ -24,16 +24,19 @@ function normalizeOptions(options) {
24
24
  if (typeof window !== "undefined") throw new Error("publisher_server_only");
25
25
  if (options && Object.keys(options).some(key => !SERVER_OPTION_KEYS.has(key))) throw new Error("publisher_option_unknown");
26
26
  if (!options || typeof options.authorize !== "function") throw new Error("publisher_authorize_required");
27
+ if (typeof options.preferenceSecret !== "string" || new TextEncoder().encode(options.preferenceSecret).byteLength < 32) throw new Error("preference_secret_required");
27
28
  if ((options.turnJournal === undefined) !== (options.sessionIdForRequest === undefined) ||
28
29
  (options.turnJournal !== undefined && (typeof options.sessionIdForRequest !== "function" ||
29
30
  ["claimPlacement", "releaseRejectedPlacement", "bind", "claimGeneration", "phase"].some(name => typeof options.turnJournal?.[name] !== "function"))))
30
31
  throw new Error("publisher_turn_journal_invalid");
31
- if (!String(options.clientId || "").startsWith("wbproj_")) throw new Error("publisher_project_invalid");
32
- if (!String(options.secretKey || "").trim()) throw new Error("publisher_server_key_required");
32
+ if (typeof options.clientId !== "string" || !options.clientId.startsWith("wbproj_")) throw new Error("publisher_project_invalid");
33
+ if (typeof options.secretKey !== "string") throw new Error("publisher_server_key_invalid");
34
+ if (!options.secretKey.trim()) throw new Error("publisher_server_key_required");
33
35
  if (!/^sk_(?:test|live)_/.test(options.secretKey)) throw new Error("publisher_server_key_invalid");
34
- if (!ID.test(options.surfaceId || "") || !PLACEMENT_KEY.test(options.placementKey || "")) throw new Error("publisher_placement_invalid");
36
+ if (typeof options.surfaceId !== "string" || typeof options.placementKey !== "string" || !ID.test(options.surfaceId) || !PLACEMENT_KEY.test(options.placementKey)) throw new Error("publisher_placement_invalid");
35
37
  if (!["before", "during", "after"].includes(options.timing)) throw new Error("publisher_timing_invalid");
36
38
  if (!["wavebird_consent", "own_cmp"].includes(options.consentMode)) throw new Error("publisher_consent_mode_invalid");
39
+ if (options.gdprApplies !== undefined && typeof options.gdprApplies !== "boolean") throw new Error("publisher_gdpr_invalid");
37
40
  if (!Array.isArray(options.allowedFormats) || options.allowedFormats.length === 0 || options.allowedFormats.some(value => !["banner", "native", "clip"].includes(value))) throw new Error("publisher_formats_invalid");
38
41
  if (!["above", "below", "sidebar", "between"].includes(options.positionHint)) throw new Error("publisher_position_invalid");
39
42
  if (!Array.isArray(options.allowedSizes) || options.allowedSizes.length === 0 || options.allowedSizes.some(size => !size || typeof size !== "object" || Object.keys(size).some(key => !["width", "height", "formats"].includes(key)) || !Number.isSafeInteger(size.width) || !Number.isSafeInteger(size.height) || size.width < 1 || size.height < 1 ||
@@ -47,8 +50,15 @@ function normalizeOptions(options) {
47
50
  if (hasFloor !== hasCurrency || (hasFloor && (!Number.isFinite(options.bidfloor) || options.bidfloor < 0 || typeof options.bidfloorCurrency !== "string" || !/^[A-Za-z]{3}$/.test(options.bidfloorCurrency))))
48
51
  throw new Error("publisher_bidfloor_override_invalid");
49
52
  if (options.responsiveSizeSelection !== undefined && typeof options.responsiveSizeSelection !== "boolean") throw new Error("publisher_responsive_selection_invalid");
50
- if (!options.publisher || typeof options.publisher !== "object" || Object.keys(options.publisher).some(key => !["app_name", "app_domain", "categories"].includes(key)) || typeof options.publisher.app_name !== "string" || typeof options.publisher.app_domain !== "string" || !Array.isArray(options.publisher.categories)) throw new Error("publisher_identity_invalid");
51
- if (typeof options.jobType !== "string" || !options.jobType || typeof options.locale !== "string" || !options.locale) throw new Error("publisher_job_invalid");
53
+ if (!options.publisher || typeof options.publisher !== "object" || Object.keys(options.publisher).some(key => !["app_name", "app_domain", "categories"].includes(key)) ||
54
+ typeof options.publisher.app_name !== "string" || !options.publisher.app_name.trim() ||
55
+ typeof options.publisher.app_domain !== "string" || !options.publisher.app_domain.trim() ||
56
+ !Array.isArray(options.publisher.categories) ||
57
+ options.publisher.categories.some(value => typeof value !== "string" || !value.trim())) throw new Error("publisher_identity_invalid");
58
+ if (options.blockedCategories !== undefined && (!Array.isArray(options.blockedCategories) ||
59
+ options.blockedCategories.some(value => typeof value !== "string" || !value.trim())))
60
+ throw new Error("publisher_blocked_categories_invalid");
61
+ if (!["chat", "code", "image", "voice", "agent"].includes(options.jobType) || typeof options.locale !== "string" || !options.locale) throw new Error("publisher_job_invalid");
52
62
  const base = String(options.apiBaseUrl || "https://api.wavebird.ai").trim().replace(/\/+$/, "").replace(/\/v1$/, "") + "/v1";
53
63
  if (!/^https:\/\//.test(base)) throw new Error("publisher_api_https_required");
54
64
  {
@@ -262,7 +272,7 @@ export function createPublisherServer(inputOptions) {
262
272
  const scope = request => ({ project: options.clientId, surface: options.surfaceId, version: PREFERENCE_VERSION,
263
273
  profile: options.consentMode === "wavebird_consent" ? "wavebird_dialog" : "publisher_custom", origin: publicOrigin(request, options) });
264
274
  async function preferenceKey() {
265
- if (!options.preferenceSecret || options.preferenceSecret.length < 32) throw new Error("preference_secret_required");
275
+ if (new TextEncoder().encode(options.preferenceSecret).byteLength < 32) throw new Error("preference_secret_required");
266
276
  return crypto.subtle.importKey("raw", new TextEncoder().encode(options.preferenceSecret), { name: "HMAC", hash: "SHA-256" }, false, ["sign", "verify"]);
267
277
  }
268
278
  async function signPreference(request, state) {
@@ -326,7 +336,6 @@ export function createPublisherServer(inputOptions) {
326
336
  allowed_sizes: allowedSizes, presentation_version: "sponsored_moment_v2" },
327
337
  overrides: { allowed_formats: allowedFormats, timing: options.timing,
328
338
  ...(Object.hasOwn(options, "bidfloor") ? { bidfloor: options.bidfloor, bidfloor_currency: options.bidfloorCurrency.toUpperCase() } : {}),
329
- gdpr_applies: options.gdprApplies === true,
330
339
  publisher: { app_name: options.publisher.app_name, app_domain: options.publisher.app_domain,
331
340
  ...(options.publisher.categories.length ? { categories: options.publisher.categories } : {}) },
332
341
  ...(options.blockedCategories?.length ? { blocked_categories: options.blockedCategories } : {}) },