@wavebirdai/api 0.1.0-beta.5 → 0.1.0-beta.7

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.5
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/server.js CHANGED
@@ -30,7 +30,8 @@ function normalizeOptions(options) {
30
30
  ["claimPlacement", "releaseRejectedPlacement", "bind", "claimGeneration", "phase"].some(name => typeof options.turnJournal?.[name] !== "function"))))
31
31
  throw new Error("publisher_turn_journal_invalid");
32
32
  if (typeof options.clientId !== "string" || !options.clientId.startsWith("wbproj_")) throw new Error("publisher_project_invalid");
33
- if (!String(options.secretKey || "").trim()) throw new Error("publisher_server_key_required");
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");
34
35
  if (!/^sk_(?:test|live)_/.test(options.secretKey)) throw new Error("publisher_server_key_invalid");
35
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");
36
37
  if (!["before", "during", "after"].includes(options.timing)) throw new Error("publisher_timing_invalid");
@@ -49,10 +50,23 @@ function normalizeOptions(options) {
49
50
  if (hasFloor !== hasCurrency || (hasFloor && (!Number.isFinite(options.bidfloor) || options.bidfloor < 0 || typeof options.bidfloorCurrency !== "string" || !/^[A-Za-z]{3}$/.test(options.bidfloorCurrency))))
50
51
  throw new Error("publisher_bidfloor_override_invalid");
51
52
  if (options.responsiveSizeSelection !== undefined && typeof options.responsiveSizeSelection !== "boolean") throw new Error("publisher_responsive_selection_invalid");
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");
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");
53
61
  if (!["chat", "code", "image", "voice", "agent"].includes(options.jobType) || typeof options.locale !== "string" || !options.locale) throw new Error("publisher_job_invalid");
54
- const base = String(options.apiBaseUrl || "https://api.wavebird.ai").trim().replace(/\/+$/, "").replace(/\/v1$/, "") + "/v1";
55
- if (!/^https:\/\//.test(base)) throw new Error("publisher_api_https_required");
62
+ const apiBaseUrl = options.apiBaseUrl === undefined ? "https://api.wavebird.ai" : options.apiBaseUrl;
63
+ if (typeof apiBaseUrl !== "string" || !apiBaseUrl.trim() || /[\\?#]/.test(apiBaseUrl)) throw new Error("publisher_api_https_required");
64
+ const endpoint = apiBaseUrl.trim();
65
+ let parsedEndpoint;
66
+ try { parsedEndpoint = new URL(endpoint); } catch { throw new Error("publisher_api_https_required"); }
67
+ if (parsedEndpoint.protocol !== "https:" || !parsedEndpoint.hostname || parsedEndpoint.username || parsedEndpoint.password ||
68
+ parsedEndpoint.search || parsedEndpoint.hash) throw new Error("publisher_api_https_required");
69
+ const base = endpoint.replace(/\/+$/, "").replace(/\/v1$/, "") + "/v1";
56
70
  {
57
71
  if (!Array.isArray(options.publicOrigins) || options.publicOrigins.length < 1 || options.publicOrigins.length > 8) throw new Error("publisher_public_origins_invalid");
58
72
  for (const origin of options.publicOrigins) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wavebirdai/api",
3
- "version": "0.1.0-beta.5",
3
+ "version": "0.1.0-beta.7",
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/server.js CHANGED
@@ -30,7 +30,8 @@ function normalizeOptions(options) {
30
30
  ["claimPlacement", "releaseRejectedPlacement", "bind", "claimGeneration", "phase"].some(name => typeof options.turnJournal?.[name] !== "function"))))
31
31
  throw new Error("publisher_turn_journal_invalid");
32
32
  if (typeof options.clientId !== "string" || !options.clientId.startsWith("wbproj_")) throw new Error("publisher_project_invalid");
33
- if (!String(options.secretKey || "").trim()) throw new Error("publisher_server_key_required");
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");
34
35
  if (!/^sk_(?:test|live)_/.test(options.secretKey)) throw new Error("publisher_server_key_invalid");
35
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");
36
37
  if (!["before", "during", "after"].includes(options.timing)) throw new Error("publisher_timing_invalid");
@@ -49,10 +50,23 @@ function normalizeOptions(options) {
49
50
  if (hasFloor !== hasCurrency || (hasFloor && (!Number.isFinite(options.bidfloor) || options.bidfloor < 0 || typeof options.bidfloorCurrency !== "string" || !/^[A-Za-z]{3}$/.test(options.bidfloorCurrency))))
50
51
  throw new Error("publisher_bidfloor_override_invalid");
51
52
  if (options.responsiveSizeSelection !== undefined && typeof options.responsiveSizeSelection !== "boolean") throw new Error("publisher_responsive_selection_invalid");
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");
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");
53
61
  if (!["chat", "code", "image", "voice", "agent"].includes(options.jobType) || typeof options.locale !== "string" || !options.locale) throw new Error("publisher_job_invalid");
54
- const base = String(options.apiBaseUrl || "https://api.wavebird.ai").trim().replace(/\/+$/, "").replace(/\/v1$/, "") + "/v1";
55
- if (!/^https:\/\//.test(base)) throw new Error("publisher_api_https_required");
62
+ const apiBaseUrl = options.apiBaseUrl === undefined ? "https://api.wavebird.ai" : options.apiBaseUrl;
63
+ if (typeof apiBaseUrl !== "string" || !apiBaseUrl.trim() || /[\\?#]/.test(apiBaseUrl)) throw new Error("publisher_api_https_required");
64
+ const endpoint = apiBaseUrl.trim();
65
+ let parsedEndpoint;
66
+ try { parsedEndpoint = new URL(endpoint); } catch { throw new Error("publisher_api_https_required"); }
67
+ if (parsedEndpoint.protocol !== "https:" || !parsedEndpoint.hostname || parsedEndpoint.username || parsedEndpoint.password ||
68
+ parsedEndpoint.search || parsedEndpoint.hash) throw new Error("publisher_api_https_required");
69
+ const base = endpoint.replace(/\/+$/, "").replace(/\/v1$/, "") + "/v1";
56
70
  {
57
71
  if (!Array.isArray(options.publicOrigins) || options.publicOrigins.length < 1 || options.publicOrigins.length > 8) throw new Error("publisher_public_origins_invalid");
58
72
  for (const origin of options.publicOrigins) {