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.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/api-emulator.cjs +121 -7
- package/dist/cjs/api-emulator.cjs.map +1 -1
- package/dist/cjs/index.cjs +12 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/{api-iOibHCWR.d.ts → api-C_uaSg1_.d.ts} +22 -1
- package/dist/esm/api-emulator.d.ts +7 -3
- package/dist/esm/api-emulator.js +121 -7
- package/dist/esm/api-emulator.js.map +1 -1
- package/dist/esm/index.d.ts +10 -3
- package/dist/esm/index.js +12 -0
- package/dist/esm/index.js.map +1 -1
- package/docs/api-emulator.md +23 -10
- package/openapi/soundlink-public-api-v1.yaml +28 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# soundlink
|
|
2
2
|
|
|
3
|
+
## 2.16.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#56](https://github.com/Fan-ID/typescript-sdk/pull/56) [`bcdd032`](https://github.com/Fan-ID/typescript-sdk/commit/bcdd0320b8706c5ec8e9dffebe5ebf1cca3fafdd) Thanks [@jotanarciso](https://github.com/jotanarciso)! - Add `delivery_reason` on creative metrics children: the Meta policy name when `delivery_state` is `disapproved`, otherwise `null`. The local API emulator's `disapprove_creatives` transition accepts an optional `reason` to set it.
|
|
8
|
+
|
|
9
|
+
## 2.15.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#54](https://github.com/Fan-ID/typescript-sdk/pull/54) [`12ace94`](https://github.com/Fan-ID/typescript-sdk/commit/12ace946f1a2d33cc168e3c11e4ff4c300103add) Thanks [@jotanarciso](https://github.com/jotanarciso)! - Add optional `delivery_state` on creative metrics children (`disapproved` | `null`, omitted on older APIs). Expose `metrics.creativesBatch`, and teach the local API emulator `GET/POST` creatives metrics plus a `disapprove_creatives` harness transition for integrator tests. Prefer `== null` until every environment returns the field.
|
|
14
|
+
|
|
3
15
|
## 2.14.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -170,7 +170,9 @@ function createEmulatorStore(options) {
|
|
|
170
170
|
trackName: ids.trackId ? "Emulator Track" : null,
|
|
171
171
|
createdAt: timestamp,
|
|
172
172
|
updatedAt: timestamp,
|
|
173
|
-
overview: null
|
|
173
|
+
overview: null,
|
|
174
|
+
partnerUploadDisapproved: false,
|
|
175
|
+
partnerUploadDisapprovalReason: null
|
|
174
176
|
};
|
|
175
177
|
campaigns.set(campaignId, record);
|
|
176
178
|
return record;
|
|
@@ -287,6 +289,49 @@ function createEmulatorStore(options) {
|
|
|
287
289
|
cpl: listeners > 0 ? Number((spendMedia / listeners).toFixed(4)) : 0,
|
|
288
290
|
cpf: followers > 0 ? Number((spendMedia / followers).toFixed(4)) : 0
|
|
289
291
|
};
|
|
292
|
+
},
|
|
293
|
+
buildCreatives(campaign) {
|
|
294
|
+
const overview = store.buildOverview(campaign);
|
|
295
|
+
const listeners = overview.listeners;
|
|
296
|
+
const followers = overview.followers;
|
|
297
|
+
const linkClicks = overview.link_clicks ?? 0;
|
|
298
|
+
const spendMedia = overview.spend_media;
|
|
299
|
+
const cpl = listeners > 0 ? Number((spendMedia / listeners).toFixed(4)) : 0;
|
|
300
|
+
const cpf = followers > 0 ? Number((spendMedia / followers).toFixed(4)) : 0;
|
|
301
|
+
const cpcLinkclick = linkClicks > 0 ? Number((spendMedia / linkClicks).toFixed(4)) : 0;
|
|
302
|
+
const deliveryState = campaign.partnerUploadDisapproved ? "disapproved" : null;
|
|
303
|
+
const child = {
|
|
304
|
+
caption: "Emulator partner upload",
|
|
305
|
+
language: "en",
|
|
306
|
+
spotify_track_id: campaign.trackId ?? "emulator_track",
|
|
307
|
+
timestamp_start_ms: null,
|
|
308
|
+
timestamp_end_ms: null,
|
|
309
|
+
listeners,
|
|
310
|
+
followers,
|
|
311
|
+
link_clicks: linkClicks,
|
|
312
|
+
cpl,
|
|
313
|
+
cpf,
|
|
314
|
+
cpc_linkclick: cpcLinkclick,
|
|
315
|
+
frequency: 1,
|
|
316
|
+
delivery_state: deliveryState,
|
|
317
|
+
delivery_reason: deliveryState ? campaign.partnerUploadDisapprovalReason : null
|
|
318
|
+
};
|
|
319
|
+
return {
|
|
320
|
+
creatives: [
|
|
321
|
+
{
|
|
322
|
+
video_id: "emu_partner_upload_video",
|
|
323
|
+
caption: child.caption,
|
|
324
|
+
listeners,
|
|
325
|
+
followers,
|
|
326
|
+
link_clicks: linkClicks,
|
|
327
|
+
cpl,
|
|
328
|
+
cpf,
|
|
329
|
+
cpc_linkclick: cpcLinkclick,
|
|
330
|
+
frequency: 1,
|
|
331
|
+
children: [child]
|
|
332
|
+
}
|
|
333
|
+
]
|
|
334
|
+
};
|
|
290
335
|
}
|
|
291
336
|
};
|
|
292
337
|
return store;
|
|
@@ -333,7 +378,7 @@ function applyRefundIfNeeded(store, campaign) {
|
|
|
333
378
|
store.creditWallet(refund);
|
|
334
379
|
campaign.refundedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
335
380
|
}
|
|
336
|
-
function applyTransition(store, campaignId, action, mediaSpendUsd) {
|
|
381
|
+
function applyTransition(store, campaignId, action, mediaSpendUsd, reason) {
|
|
337
382
|
const campaign = store.getCampaign(campaignId);
|
|
338
383
|
if (!campaign) {
|
|
339
384
|
throw new TransitionError(404, "campaign_not_found", "Campaign not found.");
|
|
@@ -403,6 +448,14 @@ function applyTransition(store, campaignId, action, mediaSpendUsd) {
|
|
|
403
448
|
store.updateCampaign(campaign);
|
|
404
449
|
break;
|
|
405
450
|
}
|
|
451
|
+
case "disapprove_creatives": {
|
|
452
|
+
campaign.partnerUploadDisapproved = true;
|
|
453
|
+
if (reason !== void 0) {
|
|
454
|
+
campaign.partnerUploadDisapprovalReason = reason.trim() || null;
|
|
455
|
+
}
|
|
456
|
+
store.updateCampaign(campaign);
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
406
459
|
default: {
|
|
407
460
|
const _exhaustive = action;
|
|
408
461
|
throw new TransitionError(
|
|
@@ -515,8 +568,9 @@ function readIdempotencyKey(headers) {
|
|
|
515
568
|
return { key };
|
|
516
569
|
}
|
|
517
570
|
function isTransitionAction(value) {
|
|
518
|
-
return value === "activate" || value === "reject_meta" || value === "set_spend" || value === "end";
|
|
571
|
+
return value === "activate" || value === "reject_meta" || value === "set_spend" || value === "end" || value === "disapprove_creatives";
|
|
519
572
|
}
|
|
573
|
+
var CREATIVES_BATCH_MAX_IDS = 50;
|
|
520
574
|
var BUILT_IN_STRATEGIES = [
|
|
521
575
|
"maximum_growth",
|
|
522
576
|
"market_discovery",
|
|
@@ -702,6 +756,64 @@ function dispatch(store, request) {
|
|
|
702
756
|
}
|
|
703
757
|
return success(200, store.buildOverview(campaign));
|
|
704
758
|
}
|
|
759
|
+
const creativesCampaignId = matchPathGroup(
|
|
760
|
+
pathname,
|
|
761
|
+
/^\/v1\/campaigns\/([^/]+)\/metrics\/creatives$/
|
|
762
|
+
);
|
|
763
|
+
if (method === "GET" && creativesCampaignId) {
|
|
764
|
+
const campaign = store.getCampaign(decodeURIComponent(creativesCampaignId));
|
|
765
|
+
if (!campaign) {
|
|
766
|
+
return failure(404, "campaign_not_found", "Campaign not found.");
|
|
767
|
+
}
|
|
768
|
+
return success(200, store.buildCreatives(campaign));
|
|
769
|
+
}
|
|
770
|
+
if (method === "POST" && pathname === "/v1/campaigns/metrics/creatives/batch") {
|
|
771
|
+
if (request.body === null || typeof request.body !== "object" || Array.isArray(request.body)) {
|
|
772
|
+
return failure(400, "invalid_request", "Request body must be a JSON object.");
|
|
773
|
+
}
|
|
774
|
+
const body = request.body;
|
|
775
|
+
if (body.startDate !== void 0 || body.endDate !== void 0) {
|
|
776
|
+
return failure(
|
|
777
|
+
400,
|
|
778
|
+
"invalid_request",
|
|
779
|
+
"startDate and endDate are not supported. This endpoint returns a lifetime snapshot."
|
|
780
|
+
);
|
|
781
|
+
}
|
|
782
|
+
const campaignIds = body.campaignIds;
|
|
783
|
+
if (!Array.isArray(campaignIds) || campaignIds.length === 0) {
|
|
784
|
+
return failure(400, "invalid_request", "campaignIds must be a non-empty array.");
|
|
785
|
+
}
|
|
786
|
+
if (campaignIds.length > CREATIVES_BATCH_MAX_IDS) {
|
|
787
|
+
return failure(
|
|
788
|
+
400,
|
|
789
|
+
"invalid_request",
|
|
790
|
+
`campaignIds must contain at most ${String(CREATIVES_BATCH_MAX_IDS)} ids.`
|
|
791
|
+
);
|
|
792
|
+
}
|
|
793
|
+
if (!campaignIds.every(
|
|
794
|
+
(id) => typeof id === "string" && id.trim().length > 0
|
|
795
|
+
)) {
|
|
796
|
+
return failure(
|
|
797
|
+
400,
|
|
798
|
+
"invalid_request",
|
|
799
|
+
"campaignIds must contain non-empty strings."
|
|
800
|
+
);
|
|
801
|
+
}
|
|
802
|
+
const uniqueIds = [...new Set(campaignIds)];
|
|
803
|
+
const items = uniqueIds.flatMap((campaignId) => {
|
|
804
|
+
const campaign = store.getCampaign(campaignId);
|
|
805
|
+
if (!campaign) {
|
|
806
|
+
return [];
|
|
807
|
+
}
|
|
808
|
+
return [
|
|
809
|
+
{
|
|
810
|
+
campaignId,
|
|
811
|
+
creatives: store.buildCreatives(campaign).creatives
|
|
812
|
+
}
|
|
813
|
+
];
|
|
814
|
+
});
|
|
815
|
+
return success(200, { items });
|
|
816
|
+
}
|
|
705
817
|
if (method === "POST" && pathname === "/v1/campaigns") {
|
|
706
818
|
return handleCreateCampaign(store, request);
|
|
707
819
|
}
|
|
@@ -989,11 +1101,12 @@ function dispatchHarness(store, method, pathname, body) {
|
|
|
989
1101
|
const campaignId = decodeURIComponent(harnessCampaignId);
|
|
990
1102
|
const action = body && typeof body === "object" ? body.action : void 0;
|
|
991
1103
|
const mediaSpendUsd = body && typeof body === "object" ? body.mediaSpendUsd : void 0;
|
|
1104
|
+
const reason = body && typeof body === "object" ? body.reason : void 0;
|
|
992
1105
|
if (!isTransitionAction(action)) {
|
|
993
1106
|
return failure(
|
|
994
1107
|
400,
|
|
995
1108
|
"invalid_request",
|
|
996
|
-
"action must be activate | reject_meta | set_spend | end."
|
|
1109
|
+
"action must be activate | reject_meta | set_spend | end | disapprove_creatives."
|
|
997
1110
|
);
|
|
998
1111
|
}
|
|
999
1112
|
try {
|
|
@@ -1001,7 +1114,8 @@ function dispatchHarness(store, method, pathname, body) {
|
|
|
1001
1114
|
store,
|
|
1002
1115
|
campaignId,
|
|
1003
1116
|
action,
|
|
1004
|
-
typeof mediaSpendUsd === "number" ? mediaSpendUsd : void 0
|
|
1117
|
+
typeof mediaSpendUsd === "number" ? mediaSpendUsd : void 0,
|
|
1118
|
+
typeof reason === "string" ? reason : void 0
|
|
1005
1119
|
);
|
|
1006
1120
|
return success(200, result);
|
|
1007
1121
|
} catch (error) {
|
|
@@ -1188,8 +1302,8 @@ function createApiEmulator(options = {}) {
|
|
|
1188
1302
|
throw new Error("A fault is already armed.");
|
|
1189
1303
|
}
|
|
1190
1304
|
},
|
|
1191
|
-
transition(campaignId, action, mediaSpendUsd) {
|
|
1192
|
-
return applyTransition(store, campaignId, action, mediaSpendUsd);
|
|
1305
|
+
transition(campaignId, action, mediaSpendUsd, reason) {
|
|
1306
|
+
return applyTransition(store, campaignId, action, mediaSpendUsd, reason);
|
|
1193
1307
|
},
|
|
1194
1308
|
getWallet() {
|
|
1195
1309
|
return store.getWallet();
|