@betarena/ad-engine 0.0.63 → 0.0.65
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/package.json +3 -2
- package/src/lib/Advert-Engine-Widget.svelte +71 -29
- package/src/lib/Advert-InterScroller-Child.svelte +20 -11
- package/src/lib/Advert-LeftSide.svelte +37 -0
- package/src/lib/Advert-Slide-Child.svelte +24 -11
- package/src/lib/store/session.ts +12 -1
- package/src/lib/types/session.d.ts +15 -0
- package/src/lib/utils/debug.ts +0 -0
- package/src/lib/utils/device.ts +0 -0
- package/src/lib/utils/geo.ts +0 -0
- package/src/lib/utils/fetch.ts +0 -107
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@betarena/ad-engine",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.65",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Betarena ad-engine widget",
|
|
6
6
|
"keywords": [
|
|
@@ -61,8 +61,9 @@
|
|
|
61
61
|
"vite": "5.1.6"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@betarena/scores-lib": "1.
|
|
64
|
+
"@betarena/scores-lib": "4.1.0",
|
|
65
65
|
"@fontsource/roboto": "5.0.12",
|
|
66
|
+
"chalk": "5.3.0",
|
|
66
67
|
"colorthief": "2.6.0",
|
|
67
68
|
"device-detector-js": "3.0.3",
|
|
68
69
|
"svelte-preprocess": "5.1.3",
|
|
@@ -39,27 +39,27 @@
|
|
|
39
39
|
// ╰────────────────────────────────────────────────────────────────────────╯
|
|
40
40
|
|
|
41
41
|
import { onMount } from 'svelte';
|
|
42
|
-
|
|
43
42
|
// import '@fontsource/roboto';
|
|
44
43
|
|
|
45
|
-
import {
|
|
44
|
+
import { ServiceAdEngine } from '@betarena/scores-lib/dist/classes/_service.adengine.js';
|
|
45
|
+
import { removeNull } from '@betarena/scores-lib/dist/util/common.js';
|
|
46
46
|
import { betarenaAdEngineStore } from './_store.js';
|
|
47
47
|
import { betarenaEndpoint } from './constants/instance.js';
|
|
48
48
|
import { storeSession } from './store/session.js';
|
|
49
49
|
import { logger } from './utils/debug.js';
|
|
50
50
|
import { detectDeviceWithUA } from './utils/device.js';
|
|
51
|
-
import { postMod } from './utils/fetch.js';
|
|
52
51
|
import { getUserLocation } from './utils/geo.js';
|
|
53
52
|
|
|
54
53
|
import WidgetAdGeneral from './Advert-General-Child.svelte';
|
|
55
54
|
import AdvertInterScrollerChild from './Advert-InterScroller-Child.svelte';
|
|
55
|
+
import AdvertLeftSide from './Advert-LeftSide.svelte';
|
|
56
56
|
import WidgetAdvertSlide from './Advert-Slide-Child.svelte';
|
|
57
57
|
import DevInfoBox from './misc/admin/Dev-Info-Box.svelte';
|
|
58
58
|
|
|
59
59
|
import '../style/app.scss';
|
|
60
60
|
|
|
61
|
-
import type {
|
|
62
|
-
import type {
|
|
61
|
+
import type { IAdsServiceData } from '@betarena/scores-lib/types/ad-engine/index.js';
|
|
62
|
+
import type { AdsCreativeMain } from '@betarena/scores-lib/types/v8/_HASURA-0.js';
|
|
63
63
|
import type { GeoJsResponse } from './types/geojs.js';
|
|
64
64
|
|
|
65
65
|
// #endregion ➤ 📦 Package Imports
|
|
@@ -98,7 +98,12 @@
|
|
|
98
98
|
* @description
|
|
99
99
|
* 📝 Dark theme value
|
|
100
100
|
*/
|
|
101
|
-
isDarkTheme: boolean = false
|
|
101
|
+
isDarkTheme: boolean = false,
|
|
102
|
+
/**
|
|
103
|
+
* @description
|
|
104
|
+
* 📝 Translation target
|
|
105
|
+
*/
|
|
106
|
+
strTranslationTarget = 'es'
|
|
102
107
|
;
|
|
103
108
|
|
|
104
109
|
/**
|
|
@@ -243,13 +248,13 @@
|
|
|
243
248
|
* 🟦 HELPER
|
|
244
249
|
* @description
|
|
245
250
|
* 📝 Generates adverts (+ complementary data) for appropiate zones
|
|
246
|
-
* @param {
|
|
251
|
+
* @param { IAdsServiceData } opts
|
|
247
252
|
* 💠 **[required]** `list` of zone ids
|
|
248
253
|
* @returns { Promise < void > }
|
|
249
254
|
*/
|
|
250
255
|
async function injectBetarenaAds
|
|
251
256
|
(
|
|
252
|
-
opts:
|
|
257
|
+
opts: IAdsServiceData['request']['body']
|
|
253
258
|
): Promise < void >
|
|
254
259
|
{
|
|
255
260
|
if (!document) return;
|
|
@@ -259,15 +264,33 @@
|
|
|
259
264
|
* @description
|
|
260
265
|
* 📝 Response from `fetch`
|
|
261
266
|
*/
|
|
262
|
-
|
|
263
|
-
= await
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
267
|
+
dataRes0
|
|
268
|
+
= await new ServiceAdEngine
|
|
269
|
+
(
|
|
270
|
+
betarenaEndpoint
|
|
271
|
+
).getAdEngineData
|
|
272
|
+
(
|
|
273
|
+
{
|
|
274
|
+
query: {},
|
|
275
|
+
body: opts
|
|
276
|
+
}
|
|
277
|
+
),
|
|
278
|
+
/**
|
|
279
|
+
* @description
|
|
280
|
+
* 📝 Response from `fetch`
|
|
281
|
+
*/
|
|
282
|
+
dataRes1
|
|
283
|
+
= await new ServiceAdEngine
|
|
268
284
|
(
|
|
269
|
-
|
|
270
|
-
|
|
285
|
+
betarenaEndpoint
|
|
286
|
+
).getAdEgnineTranslationData
|
|
287
|
+
(
|
|
288
|
+
{
|
|
289
|
+
query: {
|
|
290
|
+
language: strTranslationTarget
|
|
291
|
+
},
|
|
292
|
+
body: {}
|
|
293
|
+
}
|
|
271
294
|
)
|
|
272
295
|
;
|
|
273
296
|
|
|
@@ -276,33 +299,44 @@
|
|
|
276
299
|
(
|
|
277
300
|
[
|
|
278
301
|
'🚏 checkpoint ➤ injectBetarenaAds(..) // START',
|
|
279
|
-
`🔹 [var] ➤
|
|
302
|
+
`🔹 [var] ➤ dataRes0 ${JSON.stringify(dataRes0)}`,
|
|
303
|
+
`🔹 [var] ➤ dataRes1 ${JSON.stringify(dataRes1)}`
|
|
280
304
|
]
|
|
281
305
|
);
|
|
282
306
|
|
|
283
|
-
|
|
307
|
+
storeSession.updateData
|
|
308
|
+
(
|
|
309
|
+
[
|
|
310
|
+
[
|
|
311
|
+
'setTranslation',
|
|
312
|
+
dataRes1.success.data
|
|
313
|
+
]
|
|
314
|
+
]
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
mapCreative = new Map(dataRes0.success.data.ads ?? []);
|
|
284
318
|
|
|
285
319
|
const
|
|
286
320
|
/**
|
|
287
321
|
* @description
|
|
288
322
|
* 📝 `Map` where, `key=ZoneId` and `value=listCampaignId`
|
|
289
323
|
*/
|
|
290
|
-
mapZoneIdToCampaignId = new Map (
|
|
324
|
+
mapZoneIdToCampaignId = new Map (dataRes0.success.data.mapZoneIdToCampaignId),
|
|
291
325
|
/**
|
|
292
326
|
* @description
|
|
293
327
|
* 📝 `Map` where, `key=CampaignId` and `value=listCreativeId`
|
|
294
328
|
*/
|
|
295
|
-
mapCampaignIdToCreativeId = new Map (
|
|
329
|
+
mapCampaignIdToCreativeId = new Map (dataRes0.success.data.mapCampaignIdToCreativeId),
|
|
296
330
|
/**
|
|
297
331
|
* @description
|
|
298
332
|
* 📝 `Map` where, `key=ZoneId` and `value=listAuthorId`
|
|
299
333
|
*/
|
|
300
|
-
mapZoneToAuthorIds = new Map (
|
|
334
|
+
mapZoneToAuthorIds = new Map (dataRes0.success.data.mapZoneIdToAuthorIds),
|
|
301
335
|
/**
|
|
302
336
|
* @description
|
|
303
337
|
* 📝 `Map` where, `key=ZoneId` and `value=listTagId`
|
|
304
338
|
*/
|
|
305
|
-
mapZoneToTagIds = new Map (
|
|
339
|
+
mapZoneToTagIds = new Map (dataRes0.success.data.mapZoneIdToTagIds)
|
|
306
340
|
;
|
|
307
341
|
|
|
308
342
|
// ╭─────
|
|
@@ -398,17 +432,25 @@
|
|
|
398
432
|
else if (zoneId == 2 || zoneId == 3)
|
|
399
433
|
{
|
|
400
434
|
for (const adData of (creativeAdData ?? []))
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
{
|
|
435
|
+
if (adData.targeting.device.includes('desktop'))
|
|
436
|
+
new AdvertLeftSide({
|
|
404
437
|
target: element,
|
|
405
|
-
props:
|
|
438
|
+
props: {
|
|
439
|
+
objectAdvertData: adData
|
|
440
|
+
}
|
|
441
|
+
})
|
|
442
|
+
else
|
|
443
|
+
new AdvertInterScrollerChild
|
|
444
|
+
(
|
|
445
|
+
{
|
|
446
|
+
target: element,
|
|
447
|
+
props:
|
|
406
448
|
{
|
|
407
449
|
instanceNode: element,
|
|
408
|
-
|
|
450
|
+
objectAdvertData: adData
|
|
409
451
|
}
|
|
410
|
-
|
|
411
|
-
|
|
452
|
+
}
|
|
453
|
+
);
|
|
412
454
|
;
|
|
413
455
|
}
|
|
414
456
|
}
|
|
@@ -40,12 +40,13 @@
|
|
|
40
40
|
|
|
41
41
|
import { onMount } from 'svelte';
|
|
42
42
|
|
|
43
|
+
import { ServiceAdEngine } from '@betarena/scores-lib/dist/classes/_service.adengine.js';
|
|
43
44
|
import { betarenaEndpoint } from './constants/instance.js';
|
|
44
45
|
import { storeAdmin } from './store/admin.js';
|
|
45
|
-
import {
|
|
46
|
+
import { storeSession } from './store/session.js';
|
|
46
47
|
import { getImageBgColor } from './utils/npm.colorthief.js';
|
|
47
48
|
|
|
48
|
-
import type { AdsCreativeMain } from '@betarena/scores-lib/types/
|
|
49
|
+
import type { AdsCreativeMain } from '@betarena/scores-lib/types/v8/_HASURA-0.js';
|
|
49
50
|
|
|
50
51
|
// #endregion ➤ 📦 Package Imports
|
|
51
52
|
|
|
@@ -72,7 +73,7 @@
|
|
|
72
73
|
/**
|
|
73
74
|
* @augments AdsCreativeMain
|
|
74
75
|
*/
|
|
75
|
-
|
|
76
|
+
objectAdvertData: AdsCreativeMain,
|
|
76
77
|
/**
|
|
77
78
|
* @description
|
|
78
79
|
* 📝
|
|
@@ -88,6 +89,8 @@
|
|
|
88
89
|
instanceAdvertInterscroller: HTMLDivElement
|
|
89
90
|
;
|
|
90
91
|
|
|
92
|
+
$: ({ data: { translation } } = $storeSession);
|
|
93
|
+
|
|
91
94
|
// #endregion ➤ 📌 VARIABLES
|
|
92
95
|
|
|
93
96
|
// #region ➤ 🛠️ METHODS
|
|
@@ -201,7 +204,7 @@
|
|
|
201
204
|
{
|
|
202
205
|
getImageBgColor
|
|
203
206
|
(
|
|
204
|
-
|
|
207
|
+
objectAdvertData.data?.media ?? '',
|
|
205
208
|
'--betarena-ad-engine-interscroller-advert-background-image-'
|
|
206
209
|
);
|
|
207
210
|
|
|
@@ -242,7 +245,7 @@
|
|
|
242
245
|
'
|
|
243
246
|
>
|
|
244
247
|
<h2 class='info-box'>
|
|
245
|
-
|
|
248
|
+
{translation.translation.advertisement ?? 'ADVERTISEMENT'}
|
|
246
249
|
</h2>
|
|
247
250
|
|
|
248
251
|
<div
|
|
@@ -263,22 +266,28 @@
|
|
|
263
266
|
{
|
|
264
267
|
() =>
|
|
265
268
|
{
|
|
266
|
-
|
|
269
|
+
new ServiceAdEngine
|
|
270
|
+
(
|
|
271
|
+
betarenaEndpoint
|
|
272
|
+
).updateAdEngineClickCounter
|
|
267
273
|
(
|
|
268
|
-
`${betarenaEndpoint}/ad/update/click`,
|
|
269
274
|
{
|
|
270
|
-
|
|
275
|
+
query: {
|
|
276
|
+
creativeId: objectAdvertData.id
|
|
277
|
+
},
|
|
278
|
+
body: {}
|
|
271
279
|
}
|
|
272
280
|
);
|
|
281
|
+
return;
|
|
273
282
|
}
|
|
274
283
|
}
|
|
275
|
-
href={
|
|
284
|
+
href={objectAdvertData.data?.cta_link}
|
|
276
285
|
>
|
|
277
286
|
<div
|
|
278
287
|
id='advert'
|
|
279
288
|
style=
|
|
280
289
|
'
|
|
281
|
-
background: url({
|
|
290
|
+
background: url({objectAdvertData.data?.media});
|
|
282
291
|
background-repeat: no-repeat;
|
|
283
292
|
background-size: 100vw 100vh;
|
|
284
293
|
'
|
|
@@ -288,7 +297,7 @@
|
|
|
288
297
|
</div>
|
|
289
298
|
|
|
290
299
|
<h2 class='info-box'>
|
|
291
|
-
|
|
300
|
+
{translation.translation.scroll ?? 'SCROLL TO CONTINUE'}
|
|
292
301
|
</h2>
|
|
293
302
|
</div>
|
|
294
303
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { AdsCreativeMain } from '@betarena/scores-lib/types/v8/_HASURA-0';
|
|
3
|
+
import { onMount } from 'svelte';
|
|
4
|
+
import { storeAdmin } from './store/admin';
|
|
5
|
+
|
|
6
|
+
export let /**
|
|
7
|
+
* @augments AdsCreativeMain
|
|
8
|
+
*/
|
|
9
|
+
objectAdvertData: AdsCreativeMain;
|
|
10
|
+
|
|
11
|
+
onMount(() =>
|
|
12
|
+
{
|
|
13
|
+
storeAdmin.updateData([['numberOfAdvertsActive', null]]);
|
|
14
|
+
return;
|
|
15
|
+
});
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<a
|
|
19
|
+
target="_blank"
|
|
20
|
+
href={objectAdvertData.data?.cta_link}
|
|
21
|
+
on:click={() =>
|
|
22
|
+
{
|
|
23
|
+
|
|
24
|
+
}}
|
|
25
|
+
>
|
|
26
|
+
<img alt="ad_image" src={objectAdvertData.data?.media} class="desktop_ad" />
|
|
27
|
+
</a>
|
|
28
|
+
|
|
29
|
+
<style>
|
|
30
|
+
.desktop_ad {
|
|
31
|
+
position: fixed;
|
|
32
|
+
right: 0 !important;
|
|
33
|
+
max-height: 100% !important;
|
|
34
|
+
top: 0 !important;
|
|
35
|
+
width: initial !important;
|
|
36
|
+
}
|
|
37
|
+
</style>
|
|
@@ -41,16 +41,17 @@
|
|
|
41
41
|
import { onMount } from 'svelte';
|
|
42
42
|
import { fly } from 'svelte/transition';
|
|
43
43
|
|
|
44
|
+
import { ServiceAdEngine } from '@betarena/scores-lib/dist/classes/_service.adengine.js';
|
|
44
45
|
import { betarenaAdEngineStore } from './_store.js';
|
|
45
|
-
import { storeAdmin } from './store/admin.js';
|
|
46
|
-
import { postMod } from './utils/fetch.js';
|
|
47
46
|
import { betarenaEndpoint } from './constants/instance.js';
|
|
47
|
+
import { storeAdmin } from './store/admin.js';
|
|
48
48
|
import { storeSession } from './store/session.js';
|
|
49
49
|
|
|
50
50
|
import iconClose from './assets/icon-close.svg';
|
|
51
51
|
import iconArrow from './assets/icon-external-link.svg';
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
|
|
54
|
+
import type { AdsCreativeMain } from '@betarena/scores-lib/types/v8/_HASURA-0.js';
|
|
54
55
|
|
|
55
56
|
// #endregion ➤ 📦 Package Imports
|
|
56
57
|
|
|
@@ -240,7 +241,7 @@
|
|
|
240
241
|
-->
|
|
241
242
|
{#if ((adData.type == 1 || adData.type == 4) && adData.data?.media)}
|
|
242
243
|
<a
|
|
243
|
-
href={adData.data
|
|
244
|
+
href={adData.data.video_link}
|
|
244
245
|
target="_blank"
|
|
245
246
|
rel=
|
|
246
247
|
"
|
|
@@ -251,13 +252,19 @@
|
|
|
251
252
|
{
|
|
252
253
|
() =>
|
|
253
254
|
{
|
|
254
|
-
|
|
255
|
+
new ServiceAdEngine
|
|
256
|
+
(
|
|
257
|
+
betarenaEndpoint
|
|
258
|
+
).updateAdEngineClickCounter
|
|
255
259
|
(
|
|
256
|
-
`${betarenaEndpoint}/ad/update/click`,
|
|
257
260
|
{
|
|
258
|
-
|
|
261
|
+
query: {
|
|
262
|
+
creativeId: adData.id
|
|
263
|
+
},
|
|
264
|
+
body: {}
|
|
259
265
|
}
|
|
260
266
|
);
|
|
267
|
+
return;
|
|
261
268
|
}
|
|
262
269
|
}
|
|
263
270
|
>
|
|
@@ -272,7 +279,7 @@
|
|
|
272
279
|
id="banner"
|
|
273
280
|
width=250
|
|
274
281
|
height=250
|
|
275
|
-
src={adData.data
|
|
282
|
+
src={adData.data.media}
|
|
276
283
|
autoplay={true}
|
|
277
284
|
muted={true}
|
|
278
285
|
playsinline={true}
|
|
@@ -336,13 +343,19 @@
|
|
|
336
343
|
{
|
|
337
344
|
() =>
|
|
338
345
|
{
|
|
339
|
-
|
|
346
|
+
new ServiceAdEngine
|
|
347
|
+
(
|
|
348
|
+
betarenaEndpoint
|
|
349
|
+
).updateAdEngineClickCounter
|
|
340
350
|
(
|
|
341
|
-
`${betarenaEndpoint}/ad/update/click`,
|
|
342
351
|
{
|
|
343
|
-
|
|
352
|
+
query: {
|
|
353
|
+
creativeId: adData.id
|
|
354
|
+
},
|
|
355
|
+
body: {}
|
|
344
356
|
}
|
|
345
357
|
);
|
|
358
|
+
return;
|
|
346
359
|
}
|
|
347
360
|
}
|
|
348
361
|
>
|
package/src/lib/store/session.ts
CHANGED
|
@@ -30,7 +30,16 @@ const
|
|
|
30
30
|
*/
|
|
31
31
|
storeObject: IAdEngineSessionStore
|
|
32
32
|
= {
|
|
33
|
-
isDarkTheme: false
|
|
33
|
+
isDarkTheme: false,
|
|
34
|
+
data:
|
|
35
|
+
{
|
|
36
|
+
translation:
|
|
37
|
+
{
|
|
38
|
+
language: 'en',
|
|
39
|
+
// @ts-expect-error - 📝 translation object
|
|
40
|
+
translations: {},
|
|
41
|
+
},
|
|
42
|
+
}
|
|
34
43
|
}
|
|
35
44
|
;
|
|
36
45
|
|
|
@@ -111,6 +120,8 @@ function createLocalStore
|
|
|
111
120
|
|
|
112
121
|
if (dataTarget == 'darkTheme')
|
|
113
122
|
storeObject.isDarkTheme = !storeObject.isDarkTheme;
|
|
123
|
+
else if (dataTarget == 'setTranslation')
|
|
124
|
+
storeObject.data.translation = dataPoint;
|
|
114
125
|
;
|
|
115
126
|
}
|
|
116
127
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { IAdsServiceTranslations } from "@betarena/scores-lib/types/ad-engine/index.js";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @author
|
|
3
5
|
* @migbash
|
|
@@ -15,6 +17,18 @@ export interface IAdEngineSessionStore
|
|
|
15
17
|
* :: false
|
|
16
18
|
*/
|
|
17
19
|
isDarkTheme: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* @description
|
|
22
|
+
* 📝 store data proerty (to be updated)
|
|
23
|
+
*/
|
|
24
|
+
data:
|
|
25
|
+
{
|
|
26
|
+
/**
|
|
27
|
+
* @description
|
|
28
|
+
* 📝 store data proerty (to be updated)
|
|
29
|
+
*/
|
|
30
|
+
translation: IAdsServiceTranslations['response']['success']['data'];
|
|
31
|
+
}
|
|
18
32
|
}
|
|
19
33
|
|
|
20
34
|
/**
|
|
@@ -23,4 +37,5 @@ export interface IAdEngineSessionStore
|
|
|
23
37
|
*/
|
|
24
38
|
type IAdEngineSessionDataProp =
|
|
25
39
|
| 'darkTheme'
|
|
40
|
+
| 'setTranslation';
|
|
26
41
|
;
|
package/src/lib/utils/debug.ts
CHANGED
|
File without changes
|
package/src/lib/utils/device.ts
CHANGED
|
File without changes
|
package/src/lib/utils/geo.ts
CHANGED
|
File without changes
|
package/src/lib/utils/fetch.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
// #region ➤ 📦 Package Imports
|
|
2
|
-
|
|
3
|
-
import { tryCatchAsyncV2 } from '@betarena/scores-lib/dist/util/util.common.js';
|
|
4
|
-
|
|
5
|
-
// #endregion ➤ 📦 Package Imports
|
|
6
|
-
|
|
7
|
-
interface IResponseError
|
|
8
|
-
{
|
|
9
|
-
/**
|
|
10
|
-
* @description
|
|
11
|
-
* 📝
|
|
12
|
-
*/
|
|
13
|
-
error: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* @description
|
|
16
|
-
* 📝
|
|
17
|
-
*/
|
|
18
|
-
errorLogs: unknown;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @author
|
|
23
|
-
* @migbash
|
|
24
|
-
* @summary
|
|
25
|
-
* - 🔹 HELPER
|
|
26
|
-
* - 🟥 IMPORTANT
|
|
27
|
-
* @description
|
|
28
|
-
* 📣 PROXY Fetch type POST
|
|
29
|
-
* @param { string } path
|
|
30
|
-
* 💠 **[required]** `endpoint/url` to fetch data from.
|
|
31
|
-
* @param { T2 } data
|
|
32
|
-
* 💠 [optional] Target data to pass as `body`.
|
|
33
|
-
* @returns { Promise < T1 | NullUndef | unknown | IResponseError > }
|
|
34
|
-
* 📤 Returns an `unkown`.
|
|
35
|
-
*/
|
|
36
|
-
export async function postMod
|
|
37
|
-
<
|
|
38
|
-
T1,
|
|
39
|
-
T2
|
|
40
|
-
>
|
|
41
|
-
(
|
|
42
|
-
path: string,
|
|
43
|
-
data: T1
|
|
44
|
-
): Promise < T2 | IResponseError >
|
|
45
|
-
{
|
|
46
|
-
console.log('path', path);
|
|
47
|
-
console.log('data', data);
|
|
48
|
-
|
|
49
|
-
return await tryCatchAsyncV2
|
|
50
|
-
<
|
|
51
|
-
T2
|
|
52
|
-
>
|
|
53
|
-
(
|
|
54
|
-
async (
|
|
55
|
-
): Promise < T2 > =>
|
|
56
|
-
{
|
|
57
|
-
const
|
|
58
|
-
/**
|
|
59
|
-
* @description
|
|
60
|
-
* 📝 Target endpoint response.
|
|
61
|
-
*/
|
|
62
|
-
res: Response
|
|
63
|
-
= await fetch
|
|
64
|
-
(
|
|
65
|
-
path,
|
|
66
|
-
{
|
|
67
|
-
method: 'POST',
|
|
68
|
-
credentials: 'include',
|
|
69
|
-
body: JSON.stringify(data),
|
|
70
|
-
mode: 'cors',
|
|
71
|
-
headers:
|
|
72
|
-
{
|
|
73
|
-
Accept: 'application/json',
|
|
74
|
-
'Content-Type': 'application/json'
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
),
|
|
78
|
-
/**
|
|
79
|
-
* @description
|
|
80
|
-
* 📝 Target `json` resonse from `endpoint`.
|
|
81
|
-
*/
|
|
82
|
-
resJson = await res.json()
|
|
83
|
-
;
|
|
84
|
-
|
|
85
|
-
if (!res.ok)
|
|
86
|
-
throw new Error
|
|
87
|
-
(
|
|
88
|
-
JSON.stringify(resJson) ?? 'network response was not ok'
|
|
89
|
-
);
|
|
90
|
-
;
|
|
91
|
-
|
|
92
|
-
return resJson;
|
|
93
|
-
},
|
|
94
|
-
(
|
|
95
|
-
ex: unknown
|
|
96
|
-
): IResponseError =>
|
|
97
|
-
{
|
|
98
|
-
// [🐞]
|
|
99
|
-
console.error(`💀 Unhandled :: ${ex}`);
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
error: true,
|
|
103
|
-
errorLogs: ex
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
);
|
|
107
|
-
}
|