@surfside/ads 2.0.0 → 3.6.0-05c824af.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/README.md +15 -69
- package/lib/cjs/BuildInfo.js +9 -0
- package/lib/cjs/BuildInfo.js.map +1 -0
- package/lib/cjs/Constants.js +5 -0
- package/lib/cjs/Constants.js.map +1 -0
- package/lib/cjs/Init.js +137 -0
- package/lib/cjs/Init.js.map +1 -0
- package/lib/cjs/components/Banner.js +150 -0
- package/lib/cjs/components/Banner.js.map +1 -0
- package/lib/cjs/components/Card.js +170 -0
- package/lib/cjs/components/Card.js.map +1 -0
- package/lib/cjs/components/Carousel.js +266 -0
- package/lib/cjs/components/Carousel.js.map +1 -0
- package/lib/cjs/components/Creative.js +290 -0
- package/lib/cjs/components/Creative.js.map +1 -0
- package/lib/cjs/components/Debug.js +20 -0
- package/lib/cjs/components/Debug.js.map +1 -0
- package/lib/cjs/components/Dynamic.js +310 -0
- package/lib/cjs/components/Dynamic.js.map +1 -0
- package/lib/cjs/components/SimpleCreative.js +81 -0
- package/lib/cjs/components/SimpleCreative.js.map +1 -0
- package/lib/cjs/components/Video.js +144 -0
- package/lib/cjs/components/Video.js.map +1 -0
- package/lib/cjs/demo/test.js +7 -0
- package/lib/cjs/demo/test.js.map +1 -0
- package/lib/cjs/index.module.js +113 -0
- package/lib/cjs/index.module.js.map +1 -0
- package/lib/cjs/index.script.js +103 -0
- package/lib/cjs/index.script.js.map +1 -0
- package/lib/cjs/index.script.mock.js +154 -0
- package/lib/cjs/index.script.mock.js.map +1 -0
- package/lib/cjs/service/Init.js +3 -0
- package/lib/cjs/service/Init.js.map +1 -0
- package/lib/cjs/util/Attributes.js +93 -0
- package/lib/cjs/util/Attributes.js.map +1 -0
- package/lib/cjs/util/Types.js +3 -0
- package/lib/cjs/util/Types.js.map +1 -0
- package/lib/esm/BuildInfo.js +6 -0
- package/lib/esm/BuildInfo.js.map +1 -0
- package/lib/esm/Constants.js +2 -0
- package/lib/esm/Constants.js.map +1 -0
- package/lib/esm/Init.js +99 -0
- package/lib/esm/Init.js.map +1 -0
- package/lib/esm/components/Banner.js +146 -0
- package/lib/esm/components/Banner.js.map +1 -0
- package/lib/esm/components/Card.js +166 -0
- package/lib/esm/components/Card.js.map +1 -0
- package/lib/esm/components/Carousel.js +262 -0
- package/lib/esm/components/Carousel.js.map +1 -0
- package/lib/esm/components/Creative.js +285 -0
- package/lib/esm/components/Creative.js.map +1 -0
- package/lib/esm/components/Debug.js +16 -0
- package/lib/esm/components/Debug.js.map +1 -0
- package/lib/esm/components/Dynamic.js +306 -0
- package/lib/esm/components/Dynamic.js.map +1 -0
- package/lib/esm/components/SimpleCreative.js +75 -0
- package/lib/esm/components/SimpleCreative.js.map +1 -0
- package/lib/esm/components/Video.js +140 -0
- package/lib/esm/components/Video.js.map +1 -0
- package/lib/esm/demo/test.js +5 -0
- package/lib/esm/demo/test.js.map +1 -0
- package/lib/esm/index.module.js +73 -0
- package/lib/esm/index.module.js.map +1 -0
- package/lib/esm/index.script.js +101 -0
- package/lib/esm/index.script.js.map +1 -0
- package/lib/esm/index.script.mock.js +152 -0
- package/lib/esm/index.script.mock.js.map +1 -0
- package/lib/esm/service/Init.js +2 -0
- package/lib/esm/service/Init.js.map +1 -0
- package/lib/esm/util/Attributes.js +81 -0
- package/lib/esm/util/Attributes.js.map +1 -0
- package/lib/esm/util/Types.js +2 -0
- package/lib/esm/util/Types.js.map +1 -0
- package/lib/types/BuildInfo.d.ts +5 -0
- package/lib/types/Constants.d.ts +1 -0
- package/lib/types/Init.d.ts +32 -0
- package/lib/types/components/Banner.d.ts +16 -0
- package/lib/types/components/Card.d.ts +18 -0
- package/lib/types/components/Carousel.d.ts +33 -0
- package/lib/types/components/Creative.d.ts +92 -0
- package/lib/types/components/Debug.d.ts +2 -0
- package/lib/types/components/Dynamic.d.ts +24 -0
- package/lib/types/components/SimpleCreative.d.ts +21 -0
- package/lib/types/components/Video.d.ts +22 -0
- package/lib/types/demo/test.d.ts +1 -0
- package/lib/types/index.module.d.ts +12 -0
- package/lib/types/index.script.d.ts +1 -0
- package/lib/types/index.script.mock.d.ts +1 -0
- package/lib/types/service/Init.d.ts +1 -0
- package/lib/types/util/Attributes.d.ts +24 -0
- package/lib/types/util/Types.d.ts +3 -0
- package/package.json +42 -73
- package/lib/index.js +0 -2
package/README.md
CHANGED
|
@@ -1,69 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- **Improved Observability**: Enhanced monitoring and logging features provide deep insights into system behavior, making it easier to diagnose and resolve issues efficiently.
|
|
18
|
-
|
|
19
|
-
- **New Build Environments**: New build environments have been added, making it easier to develop against **mock services**, as well as to QA against **staging** and **local services**. This allows smoother workflows for development, testing, and deployment.
|
|
20
|
-
|
|
21
|
-
Surfside Ads delivers a modern, streamlined platform that enhances both developer productivity and user experience while providing a more robust and efficient system for all stages of development and deployment.
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
## Contributing
|
|
26
|
-
|
|
27
|
-
### Hooks
|
|
28
|
-
|
|
29
|
-
This repository uses git hooks to automate some quality control processes. Run `./load-hooks.sh` to install necessary hooks for this project:
|
|
30
|
-
|
|
31
|
-
#### `commit-msg`
|
|
32
|
-
|
|
33
|
-
Requires the following format for all commit messages
|
|
34
|
-
```
|
|
35
|
-
{BranchName}:
|
|
36
|
-
* Item 1
|
|
37
|
-
* Item 2
|
|
38
|
-
* Item 3
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
Where each item is a summary of features added or bugs fixed. The commit message must begin with the name of the branch followed by a colon. Branch names must be the ticket you are working on (i.e, if your ticket is `ISSUE-1234`, then your branch name should be `ISSUE-1234`).
|
|
42
|
-
|
|
43
|
-
#### `pre-push`
|
|
44
|
-
|
|
45
|
-
Runs `npm run lint` as a pre-requisite before pushing to the origin. All code must pass linting before it will be code reviewed
|
|
46
|
-
|
|
47
|
-
### VSCode Plugins
|
|
48
|
-
|
|
49
|
-
#### ESLint
|
|
50
|
-
|
|
51
|
-
In order to promote code quality and uniformity, this project includes an `.eslintrc.json` file. It is **highly suggested** that you use the [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) plugin. It will help you autoformat your code and alert you of issues. If you manage to push code with ESLint failures, **gitlab will fail your build automatically**, so save yourself some time and install the plugin. ESLint is only *required* for files under `src`. `demo` files do not require ESLint.
|
|
52
|
-
|
|
53
|
-
#### Highlight
|
|
54
|
-
|
|
55
|
-
In order to make the project more readable, this project includes default configurations for the [Highlight](https://marketplace.visualstudio.com/items?itemName=fabiospampinato.vscode-highlight) plugin. This configuration (under `.vscode/settings.json`) adds opacity to logger calls, so that they fade into the background while actual business logic appears brighter. This encourages us to spam debug logs for observability.
|
|
56
|
-
|
|
57
|
-
---
|
|
58
|
-
|
|
59
|
-
## Building
|
|
60
|
-
|
|
61
|
-
run `npm install` to install all dev dependencies and then run `npm build:[environment]` to build (where `[environment]` is either `MOCK`, `LOCAL`, `STAGING`, or `PROD`). This will create `r.js`
|
|
62
|
-
in `dist`, as well as some html files in `dist` for testing with.
|
|
63
|
-
|
|
64
|
-
---
|
|
65
|
-
|
|
66
|
-
## Running
|
|
67
|
-
|
|
68
|
-
Run `npm run serve` to build the library and show a simple test creative at
|
|
69
|
-
`https://localhost:8081/dist`
|
|
1
|
+
# @surfside/ads@3.0.0
|
|
2
|
+
|
|
3
|
+
To install dependencies:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
bun install
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
To run:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bun run src/index.ts
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
This project was created using `bun init` in bun v1.2.19. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VersionInfo = void 0;
|
|
4
|
+
exports.VersionInfo = {
|
|
5
|
+
'buildBranch': 'HEAD',
|
|
6
|
+
'buildHash': '05c824a',
|
|
7
|
+
'buildVer': '3.6.0-5adc7a2.0.0'
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=BuildInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuildInfo.js","sourceRoot":"../@surfside-ads/","sources":["BuildInfo.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG;IACvB,aAAa,EAAE,MAAM;IACrB,WAAW,EAAE,SAAS;IACtB,UAAU,EAAE,mBAAmB;CAClC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Constants.js","sourceRoot":"../@surfside-ads/","sources":["Constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,mBAAmB,GAAG,GAAG,CAAC"}
|
package/lib/cjs/Init.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.LoadSurfAds = exports.CreateSurfAds = void 0;
|
|
37
|
+
const ads_core_web_1 = require("@surfside/ads-core-web");
|
|
38
|
+
const Banner_1 = require("./components/Banner");
|
|
39
|
+
const Video_1 = require("./components/Video");
|
|
40
|
+
const Carousel_1 = require("./components/Carousel");
|
|
41
|
+
const Card_1 = require("./components/Card");
|
|
42
|
+
const Dynamic_1 = require("./components/Dynamic");
|
|
43
|
+
const ads_core_1 = require("@surfside/ads-core");
|
|
44
|
+
const ads_core_client_1 = require("@surfside/ads-core-client");
|
|
45
|
+
const SurfsideAdsVersionInfo = __importStar(require("./BuildInfo"));
|
|
46
|
+
;
|
|
47
|
+
const webApiInitializer = (config) => (0, ads_core_1.MemoizeAsync)(async (accountId, siteId, channelId, locationId, userId,
|
|
48
|
+
/* This is used for memoizing the init function, but isn't used directly. It's loaded from global
|
|
49
|
+
* state later on */
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
51
|
+
url) => {
|
|
52
|
+
return await (0, ads_core_web_1.LoadSurfAdsWebSimple)(accountId, siteId, channelId, locationId, userId, config?.logger, config?.telemetry, config?.overrides);
|
|
53
|
+
});
|
|
54
|
+
/** Injects dependencies into the advertising web components and passes them an initializer service.
|
|
55
|
+
* Be warned! This function has no side effects, but it returns stateful classes. The web components
|
|
56
|
+
* call their own initialization functions lazily with side effects. Once you begin
|
|
57
|
+
* using Surfside Ads Web components, you have moved out of functional programming land and into OOP
|
|
58
|
+
* land. State for Surfside ads web components is managed within the web component classes.
|
|
59
|
+
*/
|
|
60
|
+
const CreateSurfAds = (config) => {
|
|
61
|
+
const { logger, isDebug: optionalIsDebug } = config ?? {};
|
|
62
|
+
const initApi = webApiInitializer(config);
|
|
63
|
+
const log = (0, ads_core_1.Ctx)(logger)?.with('CreateSurfAds');
|
|
64
|
+
log?.info('🏄♂️ Initializing surfside ads web components');
|
|
65
|
+
log?.table(SurfsideAdsVersionTable);
|
|
66
|
+
const isDebug = optionalIsDebug === true;
|
|
67
|
+
const getUserId = config?.getUserId ?? ads_core_web_1.GetSurfUserIdCookie;
|
|
68
|
+
const dependencies = {
|
|
69
|
+
initApi,
|
|
70
|
+
getUserId,
|
|
71
|
+
isDebug,
|
|
72
|
+
logger
|
|
73
|
+
};
|
|
74
|
+
const bannerComponent = class extends Banner_1.SurfsideBanner {
|
|
75
|
+
constructor() {
|
|
76
|
+
super(dependencies);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const videoComponent = class extends Video_1.SurfsideVideo {
|
|
80
|
+
constructor() {
|
|
81
|
+
super(dependencies);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const carouselComponent = class extends Carousel_1.SurfsideCarousel {
|
|
85
|
+
constructor() {
|
|
86
|
+
super(dependencies);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const productCardComponent = class extends Card_1.SurfsideProductCard {
|
|
90
|
+
constructor() {
|
|
91
|
+
super(dependencies);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const dynamicZoneComponent = class extends Dynamic_1.SurfsideDynamicZone {
|
|
95
|
+
constructor() {
|
|
96
|
+
super(dependencies);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
return (0, ads_core_1.Ok)({
|
|
100
|
+
bannerComponent,
|
|
101
|
+
videoComponent,
|
|
102
|
+
carouselComponent,
|
|
103
|
+
productCardComponent,
|
|
104
|
+
dynamicZoneComponent
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
exports.CreateSurfAds = CreateSurfAds;
|
|
108
|
+
const LoadSurfAds = (config) => {
|
|
109
|
+
const surfAdsRes = (0, exports.CreateSurfAds)(config);
|
|
110
|
+
if (!surfAdsRes.ok) {
|
|
111
|
+
return surfAdsRes;
|
|
112
|
+
}
|
|
113
|
+
const surfAds = surfAdsRes.value;
|
|
114
|
+
const { bannerComponent, productCardComponent, videoComponent, carouselComponent, dynamicZoneComponent } = surfAds;
|
|
115
|
+
customElements.define('surf-banner', bannerComponent);
|
|
116
|
+
customElements.define('surf-video', videoComponent);
|
|
117
|
+
customElements.define('surf-carousel', carouselComponent);
|
|
118
|
+
customElements.define('surf-product-card', productCardComponent);
|
|
119
|
+
customElements.define('surf-dynamic-zone', dynamicZoneComponent);
|
|
120
|
+
return surfAdsRes;
|
|
121
|
+
};
|
|
122
|
+
exports.LoadSurfAds = LoadSurfAds;
|
|
123
|
+
const pad = (name) => {
|
|
124
|
+
let newName = name;
|
|
125
|
+
const remaining = 25 - name.length;
|
|
126
|
+
for (let i = 0; i < remaining; i++) {
|
|
127
|
+
newName += ' ';
|
|
128
|
+
}
|
|
129
|
+
return newName;
|
|
130
|
+
};
|
|
131
|
+
const SurfsideAdsVersionTable = {
|
|
132
|
+
[pad('@surfside/ads-core')]: ads_core_1.SurfsideAdsCoreVersionInfo.VersionInfo,
|
|
133
|
+
[pad('@surfside/ads-core-client')]: ads_core_client_1.SurfsideAdsCoreClientVersionInfo.VersionInfo,
|
|
134
|
+
[pad('@surfside/ads-core-web')]: ads_core_web_1.SurfsideAdsCoreWebVersionInfo.VersionInfo,
|
|
135
|
+
[pad('@surfside/ads')]: SurfsideAdsVersionInfo.VersionInfo
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=Init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Init.js","sourceRoot":"../@surfside-ads/","sources":["Init.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAMgC;AAChC,gDAAqD;AACrD,8CAAmD;AACnD,oDAAyD;AACzD,4CAAwD;AACxD,kDAA2D;AAC3D,iDAO4B;AAC5B,+DAA6E;AAC7E,oEAAsD;AAmBrD,CAAC;AAEF,MAAM,iBAAiB,GACnB,CAAC,MAA8B,EAAE,EAAE,CAC/B,IAAA,uBAAY,EACR,KAAK,EACD,SAAiB,EACjB,MAAc,EACd,SAAiB,EACjB,UAAkB,EAClB,MAA0B;AAC1B;oBACoB;AACpB,6DAA6D;AAC7D,GAAW,EACb,EAAE;IACA,OAAO,MAAM,IAAA,mCAAoB,EAC7B,SAAS,EACT,MAAM,EACN,SAAS,EACT,UAAU,EACV,MAAM,EACN,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,SAAS,CACpB,CAAC;AACN,CAAC,CAAC,CAAC;AAEf;;;;;GAKG;AACI,MAAM,aAAa,GAAG,CACzB,MAA8B,EACP,EAAE;IACzB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,MAAM,IAAI,EAAE,CAAC;IAC1D,MAAM,OAAO,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC1C,MAAM,GAAG,GAAG,IAAA,cAAG,EAAC,MAAM,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;IAC/C,GAAG,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
3
|
+
exports.SurfsideBanner = void 0;
|
|
4
|
+
const ads_core_1 = require("@surfside/ads-core");
|
|
5
|
+
const SimpleCreative_1 = require("./SimpleCreative");
|
|
6
|
+
const Creative_1 = require("./Creative");
|
|
7
|
+
const Debug_1 = require("./Debug");
|
|
8
|
+
;
|
|
9
|
+
class SurfsideBanner extends SimpleCreative_1.SimpleCreativeComponent {
|
|
10
|
+
_cancellationToken = new ads_core_1.CancellationToken();
|
|
11
|
+
_bounce;
|
|
12
|
+
static get observedAttributes() {
|
|
13
|
+
return SimpleCreative_1.SimpleCreativeComponent.observedSimpleAttributes;
|
|
14
|
+
}
|
|
15
|
+
constructor(dependencies) {
|
|
16
|
+
super(dependencies);
|
|
17
|
+
const { logger } = dependencies;
|
|
18
|
+
logger?.info('Building SurfsideBanner', this.instanceId);
|
|
19
|
+
}
|
|
20
|
+
getComponentName() {
|
|
21
|
+
return 'SurfsideBanner';
|
|
22
|
+
}
|
|
23
|
+
async attributeChangedCallback(name, oldValue, newValue) {
|
|
24
|
+
const log = this.log?.with('attributeChangedCallback');
|
|
25
|
+
log?.info('Attribute changed', name, oldValue, newValue);
|
|
26
|
+
await this.handleSimpleAttributeChange(name, oldValue, newValue, log);
|
|
27
|
+
const totem = crypto.randomUUID();
|
|
28
|
+
this.totem = totem;
|
|
29
|
+
log?.debug(name, 'totem', totem);
|
|
30
|
+
if (!this.attributesLoaded()) {
|
|
31
|
+
log?.debug('Attributes not ready yet...');
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
await this.lazyLoadApi();
|
|
35
|
+
if (this.totem !== totem) {
|
|
36
|
+
log?.debug('Totem changed. Deferring rendering of banner until last attribute changed', totem, this.totem);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
log?.debug(`Rendering banner upon [${name}] changed!`);
|
|
40
|
+
if (this.isConnected) {
|
|
41
|
+
if (this._bounce !== undefined) {
|
|
42
|
+
globalThis.clearTimeout(this._bounce);
|
|
43
|
+
}
|
|
44
|
+
this._bounce = globalThis.setTimeout(() => this.render(), Creative_1.DEBOUNCE_THRESHOLD);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async connectedCallback() {
|
|
48
|
+
super.connectedCallback();
|
|
49
|
+
this.log?.info('Banner component callback: connected');
|
|
50
|
+
this.readSimpleAttributes();
|
|
51
|
+
await this.initApi();
|
|
52
|
+
const totem = crypto.randomUUID();
|
|
53
|
+
this.totem = totem;
|
|
54
|
+
if (this.attributesLoaded()) {
|
|
55
|
+
await this.lazyLoadApi();
|
|
56
|
+
if (this.totem !== totem) {
|
|
57
|
+
this.log?.debug('Attributes changed after connectedCallback, waiting to render');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
this.log?.debug('Rendering upon connectedCallback');
|
|
61
|
+
await this.render();
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
this.log?.warn('ConnectedCallback called before attributes were all ready.');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
adoptedCallback() {
|
|
68
|
+
this.log?.info('Banner component callback: adopted');
|
|
69
|
+
}
|
|
70
|
+
disconnectedCallback() {
|
|
71
|
+
super.disconnectedCallback();
|
|
72
|
+
this._cancellationToken.cancel();
|
|
73
|
+
if (this._bounce !== undefined) {
|
|
74
|
+
globalThis.clearTimeout(this._bounce);
|
|
75
|
+
this._bounce = undefined;
|
|
76
|
+
}
|
|
77
|
+
this.log?.info('Banner component callback: disconnected', this.instanceId);
|
|
78
|
+
}
|
|
79
|
+
connectedMoveCallback() {
|
|
80
|
+
this.log?.info('Banner component callback: moved', this.instanceId);
|
|
81
|
+
}
|
|
82
|
+
async render() {
|
|
83
|
+
const log = this.log?.with('SurfsideBanner', { zoneId: this.zoneId });
|
|
84
|
+
log?.info('rendering banner web component', this.instanceId);
|
|
85
|
+
log?.debug('width', this.width, 'height', this.height);
|
|
86
|
+
const stopTimer = log?.time?.('render banner');
|
|
87
|
+
this._cancellationToken.cancel();
|
|
88
|
+
this.clearReauction();
|
|
89
|
+
const token = new ads_core_1.CancellationToken();
|
|
90
|
+
this._cancellationToken = token;
|
|
91
|
+
const { requestBids, startRequest, buildBannerResponse, renderBanner } = this.api;
|
|
92
|
+
log?.debug('Category:', this.category);
|
|
93
|
+
const response = await requestBids(startRequest(this.zoneId)
|
|
94
|
+
.withSurfCategory(this.category)
|
|
95
|
+
.withKeywords(this.keywords)
|
|
96
|
+
.withImp(this.zoneId)
|
|
97
|
+
.andBanner(this.width, this.height)
|
|
98
|
+
.build());
|
|
99
|
+
if (!response.ok) {
|
|
100
|
+
log?.warn('Failed to get bid response! Got ', response.error);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const bidRes = (0, ads_core_1.WrapValue)(response.value.seatbid?.[0]?.bid[0]);
|
|
104
|
+
if (!bidRes.ok) {
|
|
105
|
+
log?.warn('Bid response had no bid!', bidRes.error);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const bannerResponse = buildBannerResponse(bidRes.value);
|
|
109
|
+
if (!bannerResponse.ok) {
|
|
110
|
+
log?.warn('Banner failed to build response', bannerResponse.error);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const bannerRes = renderBanner(bannerResponse.value);
|
|
114
|
+
if (!bannerRes.ok) {
|
|
115
|
+
log?.warn('Failed to render banner', bannerRes.error);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const element = bannerRes.value;
|
|
119
|
+
if (!token.cancelled) {
|
|
120
|
+
this.shadow.innerHTML = '';
|
|
121
|
+
this.shadow.appendChild(element);
|
|
122
|
+
if (this.isDebug) {
|
|
123
|
+
this.shadow.appendChild((0, Debug_1.CreateDebugButton)('banners', {
|
|
124
|
+
accountId: this.accountId,
|
|
125
|
+
siteId: this.siteId,
|
|
126
|
+
channelId: this.channelId,
|
|
127
|
+
zoneId: this.zoneId,
|
|
128
|
+
locationId: this.locationId,
|
|
129
|
+
width: this.width.toString(),
|
|
130
|
+
height: this.height.toString()
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
element.classList.add(`surf-zone-${this.zoneId}`);
|
|
134
|
+
stopTimer?.();
|
|
135
|
+
this.restartEndToEndTimer?.();
|
|
136
|
+
/* Reauction */
|
|
137
|
+
log?.debug('Settings ', this.api.configuration.settings);
|
|
138
|
+
if (this.api.configuration.settings.reauctionEnabled && bidRes.value.ext?.takeover !== true) {
|
|
139
|
+
const interval = Math.max(this.api.configuration.settings.reauctionIntervalMs, 10000);
|
|
140
|
+
log?.info('Setting up re-auction in ' + interval + 'ms');
|
|
141
|
+
this.scheduleReauction(() => this.render(), interval);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
log?.info('Not setting up reauction');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.SurfsideBanner = SurfsideBanner;
|
|
150
|
+
//# sourceMappingURL=Banner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Banner.js","sourceRoot":"../@surfside-ads/","sources":["components/Banner.ts"],"names":[],"mappings":";;;AAAA,iDAAkF;AAClF,qDAI0B;AAC1B,yCAAgD;AAChD,mCAA4C;AAEyD,CAAC;AAEtG,MAAa,cAAe,SAAQ,wCAAuB;IAC/C,kBAAkB,GAAsB,IAAI,4BAAiB,EAAE,CAAC;IAChE,OAAO,CAAwB;IAEhC,MAAM,KAAK,kBAAkB;QAChC,OAAO,wCAAuB,CAAC,wBAAwB,CAAC;IAC5D,CAAC;IAED,YACI,YAAkD;QAElD,KAAK,CAAC,YAAY,CAAC,CAAC;QACpB,MAAM,EAAE,MAAM,EAAE,GAAG,YAAY,CAAC;QAChC,MAAM,EAAE,IAAI,CAAC,yBAAyB,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC7D,CAAC;IAEkB,gBAAgB;QAC/B,OAAO,gBAAgB,CAAC;IAC5B,CAAC;IAEM,KAAK,CAAC,wBAAwB,CAEjC,IAAY,EACZ,QA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C,UAAU;oBAC3B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;oBAC5B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;iBACjC,CACJ,CAAC,CAAC;YACP,CAAC;YAED,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,aAAa,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YAClD,SAAS,EAAE,EAAE,CAAC;YACd,IAAI,CAAC,oBAAoB,EAAE,EAAE,CAAC;YAC9B,eAAe;YACf,GAAG,EAAE,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YACzD,IAAI,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,gBAAgB,IAAI,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,QAAQ,KAAK,IAAI,EAAE,CAAC;gBAC1F,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;gBACtF,GAAG,EAAE,IAAI,CAAC,2BAA2B,GAAG,QAAQ,GAAG,IAAI,CAAC,CAAC;gBAEzD,IAAI,CAAC,iBAAiB,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,QAAQ,CAAC,CAAC;YAC1D,CAAC;iBAAM,CAAC;gBACJ,GAAG,EAAE,IAAI,CAAC,0BAA0B,CAAC,CAAC;YAC1C,CAAC;QACL,CAAC;IACL,CAAC;CACJ;AArLD,wCAqLC"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SurfsideProductCard = void 0;
|
|
4
|
+
const ads_core_1 = require("@surfside/ads-core");
|
|
5
|
+
const Creative_1 = require("./Creative");
|
|
6
|
+
class SurfsideProductCard extends Creative_1.CreativeComponent {
|
|
7
|
+
_cancellationToken = new ads_core_1.CancellationToken();
|
|
8
|
+
recommend = 'top-products';
|
|
9
|
+
strategy = Creative_1.ProductFeedStrategy.Hybrid;
|
|
10
|
+
_bounce;
|
|
11
|
+
static get observedAttributes() {
|
|
12
|
+
return [
|
|
13
|
+
...Creative_1.CreativeComponent.observedBaseAttributes,
|
|
14
|
+
'recommend',
|
|
15
|
+
'strategy'
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
getComponentName() {
|
|
19
|
+
return 'SurfsideProductCard';
|
|
20
|
+
}
|
|
21
|
+
async attributeChangedCallback(name, oldValue, newValue) {
|
|
22
|
+
const log = this.log?.with('attributeChangedCallback');
|
|
23
|
+
log?.info('detected attribute change');
|
|
24
|
+
log?.debug(name, oldValue, newValue);
|
|
25
|
+
switch (name) {
|
|
26
|
+
case 'strategy': {
|
|
27
|
+
const strategy = newValue?.toLowerCase();
|
|
28
|
+
switch (strategy) {
|
|
29
|
+
case Creative_1.ProductFeedStrategy.Sponsored:
|
|
30
|
+
case Creative_1.ProductFeedStrategy.Hybrid:
|
|
31
|
+
case Creative_1.ProductFeedStrategy.Recommended:
|
|
32
|
+
this.strategy = strategy;
|
|
33
|
+
break;
|
|
34
|
+
default:
|
|
35
|
+
log?.warn('Unrecognized or null strategy:', newValue);
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
case 'recommend': {
|
|
41
|
+
const recommend = newValue?.toLowerCase();
|
|
42
|
+
switch (recommend) {
|
|
43
|
+
case Creative_1.RecommenderTypeInputs.TopProducts:
|
|
44
|
+
this.recommend = 'top-products';
|
|
45
|
+
break;
|
|
46
|
+
case Creative_1.RecommenderTypeInputs.ForYou:
|
|
47
|
+
this.recommend = 'for-you';
|
|
48
|
+
break;
|
|
49
|
+
case Creative_1.RecommenderTypeInputs.PastPurchases:
|
|
50
|
+
case Creative_1.RecommenderTypeInputs.BuyAgain:
|
|
51
|
+
this.recommend = 'past-purchases';
|
|
52
|
+
break;
|
|
53
|
+
default:
|
|
54
|
+
log?.warn('Unrecognized or null recommender type:', newValue);
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
default: {
|
|
60
|
+
const baseName = name;
|
|
61
|
+
if (Creative_1.CreativeComponent.observedBaseAttributes.includes(baseName)) {
|
|
62
|
+
await super.baseAttributeChangedCallback(baseName, oldValue, newValue, log);
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const totem = crypto.randomUUID();
|
|
68
|
+
this.totem = totem;
|
|
69
|
+
if (!this.attributesLoaded()) {
|
|
70
|
+
log?.warn('Attributes not ready yet...', this.getBaseAttributeValues());
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
log?.debug('Attributes ready!');
|
|
75
|
+
}
|
|
76
|
+
await this.lazyLoadApi();
|
|
77
|
+
if (totem !== this.totem) {
|
|
78
|
+
log?.debug('Totem changed between attribute callbacks. Deferring product card render until last attribute');
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (this._bounce !== undefined) {
|
|
82
|
+
globalThis.clearTimeout(this._bounce);
|
|
83
|
+
}
|
|
84
|
+
this._bounce = globalThis.setTimeout(() => this.render(), Creative_1.DEBOUNCE_THRESHOLD);
|
|
85
|
+
}
|
|
86
|
+
async connectedCallback() {
|
|
87
|
+
super.connectedCallback();
|
|
88
|
+
const log = this.log?.with('connectedCallback');
|
|
89
|
+
log?.info('connectedCallback');
|
|
90
|
+
await this.initApi();
|
|
91
|
+
const totem = crypto.randomUUID();
|
|
92
|
+
this.totem = totem;
|
|
93
|
+
if (this.attributesLoaded()) {
|
|
94
|
+
await this.lazyLoadApi();
|
|
95
|
+
if (this.totem !== totem) {
|
|
96
|
+
this.log?.debug('Totem changed during connectedCallback. Waiting for attribute callbacks to render');
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (this.isConnected) {
|
|
100
|
+
await this.render();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
disconnectedCallback() {
|
|
105
|
+
super.disconnectedCallback();
|
|
106
|
+
this._cancellationToken.cancel();
|
|
107
|
+
if (this._bounce !== undefined) {
|
|
108
|
+
globalThis.clearTimeout(this._bounce);
|
|
109
|
+
this._bounce = undefined;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async render() {
|
|
113
|
+
const log = this.log?.with('SurfsideProductCard', { zoneId: this.zoneId });
|
|
114
|
+
log?.info('Rendering carousel', this.api);
|
|
115
|
+
const stopTimer = log?.time?.('render product card');
|
|
116
|
+
this._cancellationToken.cancel();
|
|
117
|
+
const token = new ads_core_1.CancellationToken();
|
|
118
|
+
this._cancellationToken = token;
|
|
119
|
+
const { startRequest, defaultNative, buildHybridCarousel, buildSponsoredCarousel, buildRecommendedCarousel, renderProductCard } = this.api;
|
|
120
|
+
const native = defaultNative()
|
|
121
|
+
.withManyMetaProducts(6, 80, false)
|
|
122
|
+
.withMetaBrand(80, false)
|
|
123
|
+
.build();
|
|
124
|
+
const carousel = (0, ads_core_1.TryDoFlat)(() => {
|
|
125
|
+
const request = startRequest(this.zoneId)
|
|
126
|
+
.withSurfCategory(this.category)
|
|
127
|
+
.withKeywords(this.keywords)
|
|
128
|
+
.withNative(native)
|
|
129
|
+
.build();
|
|
130
|
+
switch (this.strategy) {
|
|
131
|
+
case Creative_1.ProductFeedStrategy.Hybrid:
|
|
132
|
+
return buildHybridCarousel({
|
|
133
|
+
type: this.recommend,
|
|
134
|
+
}, request);
|
|
135
|
+
case Creative_1.ProductFeedStrategy.Sponsored:
|
|
136
|
+
return buildSponsoredCarousel(request);
|
|
137
|
+
case Creative_1.ProductFeedStrategy.Recommended:
|
|
138
|
+
return buildRecommendedCarousel({
|
|
139
|
+
type: this.recommend
|
|
140
|
+
}, this.category?.[0]);
|
|
141
|
+
default:
|
|
142
|
+
return (0, ads_core_1.Err)(new ads_core_1.InvalidRecommenderTypeError(this.strategy));
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
if (!carousel.ok) {
|
|
146
|
+
log?.error(carousel.error);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const [[builtProductCard]] = await (0, ads_core_1.ConsumeNAsync)(carousel.value.getProduct(), 1);
|
|
150
|
+
if (this._cancellationToken.cancelled) {
|
|
151
|
+
log?.debug('Render cancelled');
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (builtProductCard === undefined) {
|
|
155
|
+
log?.warn('Built product card was undefined. No inventory available. Check the rest of the logs');
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const container = renderProductCard(builtProductCard);
|
|
159
|
+
if (!container.ok) {
|
|
160
|
+
log?.error('Failed to render product card', container.error);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
stopTimer?.();
|
|
164
|
+
this.shadow.innerHTML = '';
|
|
165
|
+
container.value.classList.add(`surf-zone-${this.zoneId}`);
|
|
166
|
+
this.shadow.appendChild(container.value);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.SurfsideProductCard = SurfsideProductCard;
|
|
170
|
+
//# sourceMappingURL=Card.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Card.js","sourceRoot":"../@surfside-ads/","sources":["components/Card.ts"],"names":[],"mappings":";;;AAAA,iDAQ4B;AAC5B,yCAOoB;AAMpB,MAAa,mBAAoB,SAAQ,4BAAiB;IAC9C,kBAAkB,GAAsB,IAAI,4BAAiB,EAAE,CAAC;IAE9D,SAAS,GAAoB,cAAc,CAAC;IAC5C,QAAQ,GAAW,8BAAmB,CAAC,MAAM,CAAC;IAEhD,OAAO,CAAwB;IAEhC,MAAM,KAAK,kBAAkB;QAChC,OAAO;YACH,GAAG,4BAAiB,CAAC,sBAAsB;YAC3C,WAAW;YACX,UAAU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