soundlink 2.14.0 → 2.16.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.
@@ -162,7 +162,9 @@ function createEmulatorStore(options) {
162
162
  trackName: ids.trackId ? "Emulator Track" : null,
163
163
  createdAt: timestamp,
164
164
  updatedAt: timestamp,
165
- overview: null
165
+ overview: null,
166
+ partnerUploadDisapproved: false,
167
+ partnerUploadDisapprovalReason: null
166
168
  };
167
169
  campaigns.set(campaignId, record);
168
170
  return record;
@@ -279,6 +281,49 @@ function createEmulatorStore(options) {
279
281
  cpl: listeners > 0 ? Number((spendMedia / listeners).toFixed(4)) : 0,
280
282
  cpf: followers > 0 ? Number((spendMedia / followers).toFixed(4)) : 0
281
283
  };
284
+ },
285
+ buildCreatives(campaign) {
286
+ const overview = store.buildOverview(campaign);
287
+ const listeners = overview.listeners;
288
+ const followers = overview.followers;
289
+ const linkClicks = overview.link_clicks ?? 0;
290
+ const spendMedia = overview.spend_media;
291
+ const cpl = listeners > 0 ? Number((spendMedia / listeners).toFixed(4)) : 0;
292
+ const cpf = followers > 0 ? Number((spendMedia / followers).toFixed(4)) : 0;
293
+ const cpcLinkclick = linkClicks > 0 ? Number((spendMedia / linkClicks).toFixed(4)) : 0;
294
+ const deliveryState = campaign.partnerUploadDisapproved ? "disapproved" : null;
295
+ const child = {
296
+ caption: "Emulator partner upload",
297
+ language: "en",
298
+ spotify_track_id: campaign.trackId ?? "emulator_track",
299
+ timestamp_start_ms: null,
300
+ timestamp_end_ms: null,
301
+ listeners,
302
+ followers,
303
+ link_clicks: linkClicks,
304
+ cpl,
305
+ cpf,
306
+ cpc_linkclick: cpcLinkclick,
307
+ frequency: 1,
308
+ delivery_state: deliveryState,
309
+ delivery_reason: deliveryState ? campaign.partnerUploadDisapprovalReason : null
310
+ };
311
+ return {
312
+ creatives: [
313
+ {
314
+ video_id: "emu_partner_upload_video",
315
+ caption: child.caption,
316
+ listeners,
317
+ followers,
318
+ link_clicks: linkClicks,
319
+ cpl,
320
+ cpf,
321
+ cpc_linkclick: cpcLinkclick,
322
+ frequency: 1,
323
+ children: [child]
324
+ }
325
+ ]
326
+ };
282
327
  }
283
328
  };
284
329
  return store;
@@ -325,7 +370,7 @@ function applyRefundIfNeeded(store, campaign) {
325
370
  store.creditWallet(refund);
326
371
  campaign.refundedAt = (/* @__PURE__ */ new Date()).toISOString();
327
372
  }
328
- function applyTransition(store, campaignId, action, mediaSpendUsd) {
373
+ function applyTransition(store, campaignId, action, mediaSpendUsd, reason) {
329
374
  const campaign = store.getCampaign(campaignId);
330
375
  if (!campaign) {
331
376
  throw new TransitionError(404, "campaign_not_found", "Campaign not found.");
@@ -395,6 +440,14 @@ function applyTransition(store, campaignId, action, mediaSpendUsd) {
395
440
  store.updateCampaign(campaign);
396
441
  break;
397
442
  }
443
+ case "disapprove_creatives": {
444
+ campaign.partnerUploadDisapproved = true;
445
+ if (reason !== void 0) {
446
+ campaign.partnerUploadDisapprovalReason = reason.trim() || null;
447
+ }
448
+ store.updateCampaign(campaign);
449
+ break;
450
+ }
398
451
  default: {
399
452
  const _exhaustive = action;
400
453
  throw new TransitionError(
@@ -507,8 +560,9 @@ function readIdempotencyKey(headers) {
507
560
  return { key };
508
561
  }
509
562
  function isTransitionAction(value) {
510
- return value === "activate" || value === "reject_meta" || value === "set_spend" || value === "end";
563
+ return value === "activate" || value === "reject_meta" || value === "set_spend" || value === "end" || value === "disapprove_creatives";
511
564
  }
565
+ var CREATIVES_BATCH_MAX_IDS = 50;
512
566
  var BUILT_IN_STRATEGIES = [
513
567
  "maximum_growth",
514
568
  "market_discovery",
@@ -694,6 +748,64 @@ function dispatch(store, request) {
694
748
  }
695
749
  return success(200, store.buildOverview(campaign));
696
750
  }
751
+ const creativesCampaignId = matchPathGroup(
752
+ pathname,
753
+ /^\/v1\/campaigns\/([^/]+)\/metrics\/creatives$/
754
+ );
755
+ if (method === "GET" && creativesCampaignId) {
756
+ const campaign = store.getCampaign(decodeURIComponent(creativesCampaignId));
757
+ if (!campaign) {
758
+ return failure(404, "campaign_not_found", "Campaign not found.");
759
+ }
760
+ return success(200, store.buildCreatives(campaign));
761
+ }
762
+ if (method === "POST" && pathname === "/v1/campaigns/metrics/creatives/batch") {
763
+ if (request.body === null || typeof request.body !== "object" || Array.isArray(request.body)) {
764
+ return failure(400, "invalid_request", "Request body must be a JSON object.");
765
+ }
766
+ const body = request.body;
767
+ if (body.startDate !== void 0 || body.endDate !== void 0) {
768
+ return failure(
769
+ 400,
770
+ "invalid_request",
771
+ "startDate and endDate are not supported. This endpoint returns a lifetime snapshot."
772
+ );
773
+ }
774
+ const campaignIds = body.campaignIds;
775
+ if (!Array.isArray(campaignIds) || campaignIds.length === 0) {
776
+ return failure(400, "invalid_request", "campaignIds must be a non-empty array.");
777
+ }
778
+ if (campaignIds.length > CREATIVES_BATCH_MAX_IDS) {
779
+ return failure(
780
+ 400,
781
+ "invalid_request",
782
+ `campaignIds must contain at most ${String(CREATIVES_BATCH_MAX_IDS)} ids.`
783
+ );
784
+ }
785
+ if (!campaignIds.every(
786
+ (id) => typeof id === "string" && id.trim().length > 0
787
+ )) {
788
+ return failure(
789
+ 400,
790
+ "invalid_request",
791
+ "campaignIds must contain non-empty strings."
792
+ );
793
+ }
794
+ const uniqueIds = [...new Set(campaignIds)];
795
+ const items = uniqueIds.flatMap((campaignId) => {
796
+ const campaign = store.getCampaign(campaignId);
797
+ if (!campaign) {
798
+ return [];
799
+ }
800
+ return [
801
+ {
802
+ campaignId,
803
+ creatives: store.buildCreatives(campaign).creatives
804
+ }
805
+ ];
806
+ });
807
+ return success(200, { items });
808
+ }
697
809
  if (method === "POST" && pathname === "/v1/campaigns") {
698
810
  return handleCreateCampaign(store, request);
699
811
  }
@@ -981,11 +1093,12 @@ function dispatchHarness(store, method, pathname, body) {
981
1093
  const campaignId = decodeURIComponent(harnessCampaignId);
982
1094
  const action = body && typeof body === "object" ? body.action : void 0;
983
1095
  const mediaSpendUsd = body && typeof body === "object" ? body.mediaSpendUsd : void 0;
1096
+ const reason = body && typeof body === "object" ? body.reason : void 0;
984
1097
  if (!isTransitionAction(action)) {
985
1098
  return failure(
986
1099
  400,
987
1100
  "invalid_request",
988
- "action must be activate | reject_meta | set_spend | end."
1101
+ "action must be activate | reject_meta | set_spend | end | disapprove_creatives."
989
1102
  );
990
1103
  }
991
1104
  try {
@@ -993,7 +1106,8 @@ function dispatchHarness(store, method, pathname, body) {
993
1106
  store,
994
1107
  campaignId,
995
1108
  action,
996
- typeof mediaSpendUsd === "number" ? mediaSpendUsd : void 0
1109
+ typeof mediaSpendUsd === "number" ? mediaSpendUsd : void 0,
1110
+ typeof reason === "string" ? reason : void 0
997
1111
  );
998
1112
  return success(200, result);
999
1113
  } catch (error) {
@@ -1180,8 +1294,8 @@ function createApiEmulator(options = {}) {
1180
1294
  throw new Error("A fault is already armed.");
1181
1295
  }
1182
1296
  },
1183
- transition(campaignId, action, mediaSpendUsd) {
1184
- return applyTransition(store, campaignId, action, mediaSpendUsd);
1297
+ transition(campaignId, action, mediaSpendUsd, reason) {
1298
+ return applyTransition(store, campaignId, action, mediaSpendUsd, reason);
1185
1299
  },
1186
1300
  getWallet() {
1187
1301
  return store.getWallet();