@wavebirdai/api 0.1.0-beta.4 → 0.1.0-beta.5
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 +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +2 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +6 -5
- package/package.json +1 -1
- package/src/browser.d.ts +1 -1
- package/src/browser.js +2 -1
- package/src/server.d.ts +1 -1
- package/src/server.js +6 -5
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.
|
|
12
|
+
npm install @wavebirdai/api@0.1.0-beta.5
|
|
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:
|
|
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" &&
|
|
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:
|
|
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,18 @@ 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 (
|
|
32
|
+
if (typeof options.clientId !== "string" || !options.clientId.startsWith("wbproj_")) throw new Error("publisher_project_invalid");
|
|
32
33
|
if (!String(options.secretKey || "").trim()) throw new Error("publisher_server_key_required");
|
|
33
34
|
if (!/^sk_(?:test|live)_/.test(options.secretKey)) throw new Error("publisher_server_key_invalid");
|
|
34
|
-
if (!ID.test(options.surfaceId
|
|
35
|
+
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
36
|
if (!["before", "during", "after"].includes(options.timing)) throw new Error("publisher_timing_invalid");
|
|
36
37
|
if (!["wavebird_consent", "own_cmp"].includes(options.consentMode)) throw new Error("publisher_consent_mode_invalid");
|
|
38
|
+
if (options.gdprApplies !== undefined && typeof options.gdprApplies !== "boolean") throw new Error("publisher_gdpr_invalid");
|
|
37
39
|
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
40
|
if (!["above", "below", "sidebar", "between"].includes(options.positionHint)) throw new Error("publisher_position_invalid");
|
|
39
41
|
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 ||
|
|
@@ -48,7 +50,7 @@ function normalizeOptions(options) {
|
|
|
48
50
|
throw new Error("publisher_bidfloor_override_invalid");
|
|
49
51
|
if (options.responsiveSizeSelection !== undefined && typeof options.responsiveSizeSelection !== "boolean") throw new Error("publisher_responsive_selection_invalid");
|
|
50
52
|
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 (
|
|
53
|
+
if (!["chat", "code", "image", "voice", "agent"].includes(options.jobType) || typeof options.locale !== "string" || !options.locale) throw new Error("publisher_job_invalid");
|
|
52
54
|
const base = String(options.apiBaseUrl || "https://api.wavebird.ai").trim().replace(/\/+$/, "").replace(/\/v1$/, "") + "/v1";
|
|
53
55
|
if (!/^https:\/\//.test(base)) throw new Error("publisher_api_https_required");
|
|
54
56
|
{
|
|
@@ -262,7 +264,7 @@ export function createPublisherServer(inputOptions) {
|
|
|
262
264
|
const scope = request => ({ project: options.clientId, surface: options.surfaceId, version: PREFERENCE_VERSION,
|
|
263
265
|
profile: options.consentMode === "wavebird_consent" ? "wavebird_dialog" : "publisher_custom", origin: publicOrigin(request, options) });
|
|
264
266
|
async function preferenceKey() {
|
|
265
|
-
if (
|
|
267
|
+
if (new TextEncoder().encode(options.preferenceSecret).byteLength < 32) throw new Error("preference_secret_required");
|
|
266
268
|
return crypto.subtle.importKey("raw", new TextEncoder().encode(options.preferenceSecret), { name: "HMAC", hash: "SHA-256" }, false, ["sign", "verify"]);
|
|
267
269
|
}
|
|
268
270
|
async function signPreference(request, state) {
|
|
@@ -326,7 +328,6 @@ export function createPublisherServer(inputOptions) {
|
|
|
326
328
|
allowed_sizes: allowedSizes, presentation_version: "sponsored_moment_v2" },
|
|
327
329
|
overrides: { allowed_formats: allowedFormats, timing: options.timing,
|
|
328
330
|
...(Object.hasOwn(options, "bidfloor") ? { bidfloor: options.bidfloor, bidfloor_currency: options.bidfloorCurrency.toUpperCase() } : {}),
|
|
329
|
-
gdpr_applies: options.gdprApplies === true,
|
|
330
331
|
publisher: { app_name: options.publisher.app_name, app_domain: options.publisher.app_domain,
|
|
331
332
|
...(options.publisher.categories.length ? { categories: options.publisher.categories } : {}) },
|
|
332
333
|
...(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.
|
|
3
|
+
"version": "0.1.0-beta.5",
|
|
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:
|
|
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" &&
|
|
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:
|
|
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,18 @@ 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 (
|
|
32
|
+
if (typeof options.clientId !== "string" || !options.clientId.startsWith("wbproj_")) throw new Error("publisher_project_invalid");
|
|
32
33
|
if (!String(options.secretKey || "").trim()) throw new Error("publisher_server_key_required");
|
|
33
34
|
if (!/^sk_(?:test|live)_/.test(options.secretKey)) throw new Error("publisher_server_key_invalid");
|
|
34
|
-
if (!ID.test(options.surfaceId
|
|
35
|
+
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
36
|
if (!["before", "during", "after"].includes(options.timing)) throw new Error("publisher_timing_invalid");
|
|
36
37
|
if (!["wavebird_consent", "own_cmp"].includes(options.consentMode)) throw new Error("publisher_consent_mode_invalid");
|
|
38
|
+
if (options.gdprApplies !== undefined && typeof options.gdprApplies !== "boolean") throw new Error("publisher_gdpr_invalid");
|
|
37
39
|
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
40
|
if (!["above", "below", "sidebar", "between"].includes(options.positionHint)) throw new Error("publisher_position_invalid");
|
|
39
41
|
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 ||
|
|
@@ -48,7 +50,7 @@ function normalizeOptions(options) {
|
|
|
48
50
|
throw new Error("publisher_bidfloor_override_invalid");
|
|
49
51
|
if (options.responsiveSizeSelection !== undefined && typeof options.responsiveSizeSelection !== "boolean") throw new Error("publisher_responsive_selection_invalid");
|
|
50
52
|
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 (
|
|
53
|
+
if (!["chat", "code", "image", "voice", "agent"].includes(options.jobType) || typeof options.locale !== "string" || !options.locale) throw new Error("publisher_job_invalid");
|
|
52
54
|
const base = String(options.apiBaseUrl || "https://api.wavebird.ai").trim().replace(/\/+$/, "").replace(/\/v1$/, "") + "/v1";
|
|
53
55
|
if (!/^https:\/\//.test(base)) throw new Error("publisher_api_https_required");
|
|
54
56
|
{
|
|
@@ -262,7 +264,7 @@ export function createPublisherServer(inputOptions) {
|
|
|
262
264
|
const scope = request => ({ project: options.clientId, surface: options.surfaceId, version: PREFERENCE_VERSION,
|
|
263
265
|
profile: options.consentMode === "wavebird_consent" ? "wavebird_dialog" : "publisher_custom", origin: publicOrigin(request, options) });
|
|
264
266
|
async function preferenceKey() {
|
|
265
|
-
if (
|
|
267
|
+
if (new TextEncoder().encode(options.preferenceSecret).byteLength < 32) throw new Error("preference_secret_required");
|
|
266
268
|
return crypto.subtle.importKey("raw", new TextEncoder().encode(options.preferenceSecret), { name: "HMAC", hash: "SHA-256" }, false, ["sign", "verify"]);
|
|
267
269
|
}
|
|
268
270
|
async function signPreference(request, state) {
|
|
@@ -326,7 +328,6 @@ export function createPublisherServer(inputOptions) {
|
|
|
326
328
|
allowed_sizes: allowedSizes, presentation_version: "sponsored_moment_v2" },
|
|
327
329
|
overrides: { allowed_formats: allowedFormats, timing: options.timing,
|
|
328
330
|
...(Object.hasOwn(options, "bidfloor") ? { bidfloor: options.bidfloor, bidfloor_currency: options.bidfloorCurrency.toUpperCase() } : {}),
|
|
329
|
-
gdpr_applies: options.gdprApplies === true,
|
|
330
331
|
publisher: { app_name: options.publisher.app_name, app_domain: options.publisher.app_domain,
|
|
331
332
|
...(options.publisher.categories.length ? { categories: options.publisher.categories } : {}) },
|
|
332
333
|
...(options.blockedCategories?.length ? { blocked_categories: options.blockedCategories } : {}) },
|