@surfside/ads-core 2.0.1

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.
Files changed (122) hide show
  1. package/README.md +15 -0
  2. package/lib/cjs/index.js +3488 -0
  3. package/lib/cjs/index.js.map +54 -0
  4. package/lib/esm/index.js +3460 -0
  5. package/lib/esm/index.js.map +54 -0
  6. package/lib/index.js +1 -0
  7. package/lib/index.js.map +1 -0
  8. package/lib/types/Api.d.ts +169 -0
  9. package/lib/types/constant-values/index.d.ts +46 -0
  10. package/lib/types/errors/index.d.ts +3 -0
  11. package/lib/types/helpers/Generator.d.ts +5 -0
  12. package/lib/types/helpers/Handlebars.d.ts +124 -0
  13. package/lib/types/helpers/NativeRequestBuilder.d.ts +29 -0
  14. package/lib/types/helpers/RequestBuilder.d.ts +16 -0
  15. package/lib/types/helpers/TryGet.d.ts +2 -0
  16. package/lib/types/helpers/Window.d.ts +3 -0
  17. package/lib/types/helpers/generators/CollectN.d.ts +2 -0
  18. package/lib/types/helpers/generators/index.d.ts +1 -0
  19. package/lib/types/helpers/handlebars/index.d.ts +119 -0
  20. package/lib/types/helpers/index.d.ts +7 -0
  21. package/lib/types/helpers/requests/RequestBuilder.d.ts +124 -0
  22. package/lib/types/helpers/requests/SimpleBannerRequest.d.ts +26 -0
  23. package/lib/types/helpers/requests/index.d.ts +2 -0
  24. package/lib/types/helpers/response/Banner.d.ts +22 -0
  25. package/lib/types/helpers/response/BuiltResponse.d.ts +31 -0
  26. package/lib/types/helpers/response/Carousel.d.ts +51 -0
  27. package/lib/types/helpers/response/Clickthrough.d.ts +3 -0
  28. package/lib/types/helpers/response/ProductCard.d.ts +49 -0
  29. package/lib/types/helpers/response/Video.d.ts +17 -0
  30. package/lib/types/helpers/response/index.d.ts +6 -0
  31. package/lib/types/helpers/responses/BuildBannerResponse.d.ts +10 -0
  32. package/lib/types/helpers/responses/BuildNativeResponse.d.ts +21 -0
  33. package/lib/types/helpers/responses/BuildVideoResponse.d.ts +0 -0
  34. package/lib/types/helpers/responses/ClickthroughHelpers.d.ts +2 -0
  35. package/lib/types/helpers/responses/VastHelpers.d.ts +4 -0
  36. package/lib/types/helpers/responses/index.d.ts +4 -0
  37. package/lib/types/index.d.ts +4 -0
  38. package/lib/types/middleware/DeviceMiddleware.d.ts +3 -0
  39. package/lib/types/middleware/GeoMiddleware.d.ts +3 -0
  40. package/lib/types/middleware/IdentityMiddleware.d.ts +4 -0
  41. package/lib/types/middleware/index.d.ts +3 -0
  42. package/lib/types/models/dynamic/DynamicZone.d.ts +37 -0
  43. package/lib/types/models/dynamic/index.d.ts +1 -0
  44. package/lib/types/models/index.d.ts +5 -0
  45. package/lib/types/models/retail/Configuration.d.ts +66 -0
  46. package/lib/types/models/retail/IProductInformation.d.ts +37 -0
  47. package/lib/types/models/retail/IPublisherConfiguration.d.ts +64 -0
  48. package/lib/types/models/retail/IRecommenderResponse.d.ts +10 -0
  49. package/lib/types/models/retail/Product.d.ts +19 -0
  50. package/lib/types/models/retail/Recommended.d.ts +10 -0
  51. package/lib/types/models/retail/index.d.ts +3 -0
  52. package/lib/types/models/rtb/BidRequest.d.ts +409 -0
  53. package/lib/types/models/rtb/BidResponse.d.ts +47 -0
  54. package/lib/types/models/rtb/IBidRequest.d.ts +399 -0
  55. package/lib/types/models/rtb/IBidResponse.d.ts +47 -0
  56. package/lib/types/models/rtb/NativeRequest.d.ts +170 -0
  57. package/lib/types/models/rtb/NativeResponse.d.ts +60 -0
  58. package/lib/types/models/rtb/index.d.ts +4 -0
  59. package/lib/types/models/rtb/native/Constants.d.ts +60 -0
  60. package/lib/types/models/rtb/native/INativeRequest.d.ts +54 -0
  61. package/lib/types/models/rtb/native/INativeResponse.d.ts +60 -0
  62. package/lib/types/models/rtb/native/NativeConstants.d.ts +120 -0
  63. package/lib/types/models/rtb/native/NativeRequestBuilder.d.ts +158 -0
  64. package/lib/types/models/rtb/native/index.d.ts +4 -0
  65. package/lib/types/models/tracking/Geo.d.ts +14 -0
  66. package/lib/types/models/tracking/IEvents.d.ts +82 -0
  67. package/lib/types/models/tracking/IGeoContext.d.ts +14 -0
  68. package/lib/types/models/tracking/IUserID.d.ts +1 -0
  69. package/lib/types/models/tracking/index.d.ts +1 -0
  70. package/lib/types/models/vast/Vast.d.ts +47 -0
  71. package/lib/types/models/vast/index.d.ts +1 -0
  72. package/lib/types/services/Bidder.d.ts +31 -0
  73. package/lib/types/services/Configuration.d.ts +6 -0
  74. package/lib/types/services/Device.d.ts +12 -0
  75. package/lib/types/services/Dynamic.d.ts +26 -0
  76. package/lib/types/services/Geo.d.ts +6 -0
  77. package/lib/types/services/Logger.d.ts +14 -0
  78. package/lib/types/services/Memoization.d.ts +1 -0
  79. package/lib/types/services/OverrideService.d.ts +10 -0
  80. package/lib/types/services/Product.d.ts +13 -0
  81. package/lib/types/services/Recommender.d.ts +8 -0
  82. package/lib/types/services/Result.d.ts +57 -0
  83. package/lib/types/services/Template.d.ts +7 -0
  84. package/lib/types/services/index.d.ts +11 -0
  85. package/lib/types/services/logger/ILoggerService.d.ts +39 -0
  86. package/lib/types/services/logger/LocalLoggerService.d.ts +19 -0
  87. package/lib/types/services/logger/index.d.ts +2 -0
  88. package/lib/types/services/mock/Bidder.d.ts +1 -0
  89. package/lib/types/services/mock/index.d.ts +1 -0
  90. package/lib/types/services/product-feed/IProductFeedService.d.ts +5 -0
  91. package/lib/types/services/product-feed/SurfsideProductFeedService.d.ts +11 -0
  92. package/lib/types/services/product-feed/index.d.ts +2 -0
  93. package/lib/types/services/recommender/IRecommenderService.d.ts +47 -0
  94. package/lib/types/services/recommender/SurfsideRecommenderService.d.ts +31 -0
  95. package/lib/types/services/recommender/index.d.ts +2 -0
  96. package/lib/types/services/rtb/bidder/IBidderService.d.ts +12 -0
  97. package/lib/types/services/rtb/bidder/SurfsideBidderService.d.ts +28 -0
  98. package/lib/types/services/rtb/bidder/index.d.ts +2 -0
  99. package/lib/types/services/rtb/configuration/IConfigurationService.d.ts +14 -0
  100. package/lib/types/services/rtb/configuration/SurfsideConfigurationService.d.ts +29 -0
  101. package/lib/types/services/rtb/configuration/index.d.ts +2 -0
  102. package/lib/types/services/rtb/index.d.ts +2 -0
  103. package/lib/types/services/tracking/device/DeviceOverrideService.d.ts +8 -0
  104. package/lib/types/services/tracking/device/IDeviceService.d.ts +4 -0
  105. package/lib/types/services/tracking/device/SurfsideDeviceService.d.ts +16 -0
  106. package/lib/types/services/tracking/device/index.d.ts +3 -0
  107. package/lib/types/services/tracking/events/IEventService.d.ts +5 -0
  108. package/lib/types/services/tracking/events/SurfsideEventService.d.ts +42 -0
  109. package/lib/types/services/tracking/events/index.d.ts +2 -0
  110. package/lib/types/services/tracking/geo/GeoOverrideService.d.ts +8 -0
  111. package/lib/types/services/tracking/geo/IGeoService.d.ts +12 -0
  112. package/lib/types/services/tracking/geo/SurfsideGeoService.d.ts +7 -0
  113. package/lib/types/services/tracking/geo/index.d.ts +3 -0
  114. package/lib/types/services/tracking/index.d.ts +4 -0
  115. package/lib/types/services/tracking/user/IUserIDService.d.ts +4 -0
  116. package/lib/types/services/tracking/user/SurfsideUserIDService.d.ts +7 -0
  117. package/lib/types/services/tracking/user/UserOverrideService.d.ts +8 -0
  118. package/lib/types/services/tracking/user/index.d.ts +3 -0
  119. package/lib/types/utils/Protocol.d.ts +1 -0
  120. package/lib/types/utils/Rendering.d.ts +44 -0
  121. package/lib/types/utils/index.d.ts +2 -0
  122. package/package.json +34 -0
@@ -0,0 +1,26 @@
1
+ import { NativeRequestBuilderFn, RequestBuilder, RequestBuilderFn } from '../helpers';
2
+ import { IBidRequest, ICompiledPublisherConfiguration } from '../models';
3
+ import { DynamicCreative, IDynamicZone, IScreenSize } from '../models/dynamic/DynamicZone';
4
+ import { IScreen } from './Device';
5
+ import { ILogger } from './Logger';
6
+ import { AsyncResult, Result } from './Result';
7
+ export interface IDynamicZoneRequest {
8
+ request: IBidRequest;
9
+ requestIds: Record<string, DynamicCreative>;
10
+ }
11
+ export type BuildDynamicZoneRequestFn = (zoneId: string, dynamicZone: IDynamicZone) => Result<IDynamicZoneRequest>;
12
+ export type GetDynamicZoneFn = (zoneId: string) => AsyncResult<IDynamicZone>;
13
+ export declare const GetDynamicZone: (logger: ILogger | undefined, config: ICompiledPublisherConfiguration, zoneId: string) => Promise<import("./Result").ErrResult<MissingDynamicZoneError> | import("./Result").OkResult<IDynamicZone>>;
14
+ export declare const BuildDynamicZoneRequest: (logger: ILogger | undefined, startRequest: RequestBuilderFn, nativeRequest: NativeRequestBuilderFn, screenInfo: IScreen, zoneId: string, dynamicZone: IDynamicZone) => Result<IDynamicZoneRequest>;
15
+ export declare class NoDynamicScreenSizeMatchError extends Error {
16
+ readonly dynamicZone: IDynamicZone;
17
+ readonly screenInfo: IScreen;
18
+ readonly selectedStringSize: string;
19
+ constructor(dynamicZone: IDynamicZone, screenInfo: IScreen, selectedStringSize: string);
20
+ }
21
+ export declare const buildDynamicBidRequestFromSelectedScreenSize: (logger: ILogger | undefined, startRequest: RequestBuilderFn, nativeRequest: NativeRequestBuilderFn, zoneId: string, screenSize: IScreenSize) => Result<IDynamicZoneRequest>;
22
+ export declare const buildDynamicBidRequestRecursive: (logger: ILogger | undefined, nativeRequest: NativeRequestBuilderFn, builder: RequestBuilder, requestIds: Record<string, DynamicCreative>, [head, ...tail]: DynamicCreative[]) => Result<[builder: RequestBuilder, requestIds: Record<string, DynamicCreative>]>;
23
+ export declare class MissingDynamicZoneError extends Error {
24
+ readonly zoneId: string;
25
+ constructor(zoneId: string);
26
+ }
@@ -0,0 +1,6 @@
1
+ import type { IGeo, IGeoContext } from '../models';
2
+ import { type ILogger } from './Logger';
3
+ import { type AsyncResult } from './Result';
4
+ export type GetGeoFn = (ip?: string, geoProviderToken?: string) => AsyncResult<IGeoContext>;
5
+ export declare const GetGeo: (logger?: ILogger, apiToken?: string, ip?: string) => AsyncResult<IGeoContext>;
6
+ export declare const GeoContextToORTB: (logger: ILogger | undefined, geoContext: IGeoContext) => IGeo;
@@ -0,0 +1,14 @@
1
+ export type LoggerFn = (...args: any[]) => void;
2
+ export type ContextFn = (...prefix: (string | undefined)[]) => IContextLogger;
3
+ export interface ILogger {
4
+ info: LoggerFn;
5
+ debug: LoggerFn;
6
+ warn: LoggerFn;
7
+ error: LoggerFn;
8
+ table: (data: any, properties?: string[]) => void;
9
+ }
10
+ export interface IContextLogger extends ILogger {
11
+ with: ContextFn;
12
+ }
13
+ export declare const InitLogger: () => IContextLogger;
14
+ export declare const Ctx: (logger: ILogger | undefined) => IContextLogger | undefined;
@@ -0,0 +1 @@
1
+ export declare const Memo: <T extends any[], R>(fn: (...args: T) => R) => (...args: T) => R;
@@ -0,0 +1,10 @@
1
+ import type { ILoggerService } from './logger';
2
+ export declare abstract class OverrideService<T> {
3
+ private readonly _selector;
4
+ protected readonly logger?: ILoggerService | undefined;
5
+ protected overrideData: T | null;
6
+ protected overrideNode: HTMLElement | null;
7
+ constructor(_selector: string, logger?: ILoggerService | undefined);
8
+ protected getOverrideNode(): HTMLElement | null;
9
+ abstract mapDataSetToData(dataset: DOMStringMap): T | null;
10
+ }
@@ -0,0 +1,13 @@
1
+ import type { IProductInformation } from '../models';
2
+ import { type ILogger } from './Logger';
3
+ import { Result, type AsyncResult } from './Result';
4
+ export type GetSponsoredProductFromNativeIdFn = (nativeId: string) => AsyncGenerator<IProductInformation>;
5
+ export type GetAllSponsoredProductFromNativeIdFn = (nativeId: string) => Promise<Result<IProductInformation[]>>;
6
+ export type GetRecommendedProductFromProductIdFn = (productId: string) => AsyncResult<IProductInformation>;
7
+ export declare function GetSponsoredProduct(logger: ILogger | undefined, url: string, accountId: string, locationId: string, nativeId: string): AsyncGenerator<IProductInformation>;
8
+ export declare const GetAllSponsoredProducts: (logger: ILogger | undefined, url: string, accountId: string, locationId: string, nativeId: string) => Promise<Result<IProductInformation[]>>;
9
+ export declare const GetRecommendedProduct: (logger: ILogger | undefined, url: string, accountId: string, locationId: string, productId: string) => AsyncResult<IProductInformation>;
10
+ export declare class NoNativeError extends Error {
11
+ nativeId: string;
12
+ constructor(nativeId: string);
13
+ }
@@ -0,0 +1,8 @@
1
+ import type { IProductInformation } from '../models';
2
+ import { type ILogger } from './Logger';
3
+ import type { GetRecommendedProductFromProductIdFn } from './Product';
4
+ export type NonPersonalRecommenderFn = () => AsyncGenerator<IProductInformation>;
5
+ export type PersonalRecommenderFn = (userId: string) => AsyncGenerator<IProductInformation>;
6
+ export declare function GenerateTopProducts(logger: ILogger | undefined, productFeed: GetRecommendedProductFromProductIdFn, url: string, accountId: string, siteId: string, locationId: string): AsyncGenerator<IProductInformation>;
7
+ export declare function GenerateForYou(logger: ILogger | undefined, productFeed: GetRecommendedProductFromProductIdFn, url: string, accountId: string, siteId: string, locationId: string, userId: string): AsyncGenerator<IProductInformation>;
8
+ export declare function GeneratePreviousPurchases(logger: ILogger | undefined, productFeed: GetRecommendedProductFromProductIdFn, url: string, accountId: string, siteId: string, locationId: string, userId: string): AsyncGenerator<IProductInformation>;
@@ -0,0 +1,57 @@
1
+ export type OkResult<T> = {
2
+ ok: true;
3
+ value: T;
4
+ };
5
+ export type ErrResult<E = Error> = {
6
+ ok: false;
7
+ error: E;
8
+ };
9
+ export type Result<T, E = Error> = OkResult<T> | ErrResult<E>;
10
+ export type AsyncResult<T, E = Error> = Promise<Result<T, E>>;
11
+ export declare const Ok: <T>(t: T) => OkResult<T>;
12
+ export declare const Err: <E = Error>(e: E) => ErrResult<E>;
13
+ export declare const TryDo: <T, E = Error>(fn: () => T) => Result<T, E>;
14
+ export declare const TryDoFlat: <T, E = Error>(fn: () => Result<T, E>) => Result<T, E>;
15
+ export declare const TryDoAsync: <T, E = Error>(fn: () => Promise<T>) => AsyncResult<T, E>;
16
+ export declare const GetValue: <T, E = Error>(result: Result<T, E> | undefined) => T | undefined;
17
+ export declare const ValueOr: <T, E = Error, U = T>(result: Result<T, E> | undefined, or: U) => T | U;
18
+ export declare const GetValueOrThrow: <T>(result: Result<T, Error>) => T;
19
+ export declare const WrapValue: <T>(value: T | undefined | null) => Result<T>;
20
+ export declare const AssertValue: <T>(result: Result<T, Error>) => T;
21
+ export declare const AllOrNone: <T>(results: Result<T, Error>[]) => Result<T[]>;
22
+ export declare const Some: <T>(results: Result<T, Error>[]) => OkResult<T[]>;
23
+ export declare const Filter: <T>(...results: Result<T, Error>[]) => [OkResult<T>[], ErrResult[]];
24
+ export declare const AnyFailed: (...results: Result<any, Error>[]) => [true, Error[]] | [false];
25
+ export declare class MultipleErrorsError extends Error {
26
+ readonly errors: Error[];
27
+ constructor(errors: Error[]);
28
+ }
29
+ export interface IResultPipe<T, E = Error> {
30
+ then: <U>(fn: (t: T) => U) => IResultPipe<U, E>;
31
+ result: () => Result<T, E>;
32
+ value: () => T | undefined;
33
+ valueOr: <U>(or: U) => T | U;
34
+ valueOrThrow: () => T;
35
+ }
36
+ export declare const Pipe: <T, E = Error>(result: Result<T, E>) => IResultPipe<T, E>;
37
+ export interface IAsyncResultPipe<T, E = Error> {
38
+ then: <U>(fn: (t: T) => AsyncResult<U> | Result<U>) => IAsyncResultPipe<U, E>;
39
+ result: () => AsyncResult<T, E>;
40
+ value: () => Promise<T | undefined>;
41
+ valueOr: <U>(or: U) => Promise<T | U>;
42
+ valueOrThrow: () => Promise<T>;
43
+ }
44
+ export declare const AsyncPipe: <T, E>(result: AsyncResult<T, E>) => IAsyncResultPipe<T, E>;
45
+ export type IResultStream<T, E = Error> = {
46
+ map: <U>(fn: (t: T) => U) => IResultStream<U, E>;
47
+ filter: (fn: (t: T) => boolean) => IResultStream<T, E>;
48
+ results: () => Result<T[], E>;
49
+ value: () => T[] | undefined;
50
+ valueOr: <U>(u: U) => T[] | U;
51
+ valueOrThrow: () => T[];
52
+ };
53
+ export declare const ResultStream: <T, E = Error>(results: Result<T[], E>) => IResultStream<T, E>;
54
+ export declare class NoValueError extends Error {
55
+ readonly value: undefined | null;
56
+ constructor(value: undefined | null);
57
+ }
@@ -0,0 +1,7 @@
1
+ import { ICompiledPublisherConfiguration, INativeTemplateDelegateWindow, IProductInformation } from '../models';
2
+ import { ILogger } from './Logger';
3
+ import { Result } from './Result';
4
+ export type EvaluateProductCardTemplateFn = (product: IProductInformation, clickthrough?: string) => Result<string>;
5
+ export type EvaluateClickthroughTemplateFn = (product: IProductInformation) => Result<string>;
6
+ export declare const EvaluateHandlebarsProductCardTemplate: (logger: ILogger | undefined, windowInfo: INativeTemplateDelegateWindow, publisher: ICompiledPublisherConfiguration, product: IProductInformation, clickthrough?: string) => Result<string>;
7
+ export declare const EvaluateHandlebarsClickthroughTemplate: (logger: ILogger | undefined, windowInfo: INativeTemplateDelegateWindow, publisher: ICompiledPublisherConfiguration, product: IProductInformation) => Result<string>;
@@ -0,0 +1,11 @@
1
+ export * from './Geo';
2
+ export * from './Logger';
3
+ export * from './Result';
4
+ export * from './Device';
5
+ export * from './Configuration';
6
+ export * from './Bidder';
7
+ export * from './Product';
8
+ export * from './Recommender';
9
+ export * from './mock';
10
+ export * from './Template';
11
+ export * from './Dynamic';
@@ -0,0 +1,39 @@
1
+ export declare enum LogLevel {
2
+ NONE = 0,
3
+ ERRORS = 1,
4
+ INFO = 2,
5
+ DEBUG = 3
6
+ }
7
+ /**
8
+ * Interface for a logger service
9
+ */
10
+ export interface ILoggerService {
11
+ /**
12
+ * Prints info. This is useful for tracking the lifecycle of a bid request
13
+ *
14
+ * @param args The arguments to print
15
+ */
16
+ info: (...args: any[]) => void;
17
+ /**
18
+ * Prints a warning. This is useful for tracking potential issues, but not critical errors. Warnings should not
19
+ * prevent the bidding process from continuing, but may disable certain features such as commerce media or certain
20
+ * types of targeting
21
+ *
22
+ * @param args
23
+ */
24
+ warn: (...args: any[]) => void;
25
+ /**
26
+ * Prints an error. This is useful for tracking critical errors. Printing an error should indicate that the bidding
27
+ * process can go no further.
28
+ *
29
+ * @param args The arguments to print
30
+ */
31
+ error: (...args: any[]) => void;
32
+ /**
33
+ * Spammy messages. This is useful for tracking the lifecycle of a bid request and debugging issues with special
34
+ * flags enabled. When there is an issue on the client side, enabling debug logs will help the developer understand
35
+ * where the issue is in the code and potentially what the issue is. These should be added to every function.
36
+ * @param args The arguments to print
37
+ */
38
+ debug: (...args: any[]) => void;
39
+ }
@@ -0,0 +1,19 @@
1
+ import { type ILoggerService, LogLevel } from '../../services';
2
+ /**
3
+ * Logger service which adds some color to the console logs
4
+ */
5
+ export declare class LocalLoggerService implements ILoggerService {
6
+ private readonly _logLevel;
7
+ constructor(_logLevel: LogLevel);
8
+ debug(...args: any[]): void;
9
+ info(...args: any[]): void;
10
+ warn(...args: any[]): void;
11
+ error(...args: any[]): void;
12
+ /**
13
+ * Shows a log message with [SURF] prepended and colored
14
+ * @param log The console log function to use (e.g: console.log, console.error, etc.)
15
+ * @param args The actual log message
16
+ * @param color The color to use for the log message
17
+ */
18
+ private _log;
19
+ }
@@ -0,0 +1,2 @@
1
+ export * from './ILoggerService';
2
+ export * from './LocalLoggerService';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from './Bidder';
@@ -0,0 +1,5 @@
1
+ import type { IProductInformation } from '../../models';
2
+ export interface IProductFeedService {
3
+ getProduct: (accountId: string, siteId: string, locationId: string, productId: string) => Promise<IProductInformation | null>;
4
+ getNativeProduct: (accountId: string, siteId: string, locationId: string, productId: string) => Promise<IProductInformation | null>;
5
+ }
@@ -0,0 +1,11 @@
1
+ import type { IProductInformation } from '../../models';
2
+ import type { ILoggerService, IProductFeedService } from '../../services';
3
+ export declare class SurfsideProductFeedService implements IProductFeedService {
4
+ private readonly _logger?;
5
+ private readonly _url;
6
+ constructor(url: string, _logger?: ILoggerService | undefined);
7
+ getProduct(accountId: string, siteId: string, locationId: string, productId: string): Promise<IProductInformation | null>;
8
+ getNativeProduct(accountId: string, siteId: string | undefined, locationId: string, productId: string): Promise<IProductInformation | null>;
9
+ private _mapResponseToProductInformation;
10
+ private _getFieldOrNull;
11
+ }
@@ -0,0 +1,2 @@
1
+ export * from './IProductFeedService';
2
+ export * from './SurfsideProductFeedService';
@@ -0,0 +1,47 @@
1
+ import type { IProductInformation, IRecommendedProduct } from '../../models';
2
+ /**
3
+ * Recommender service, provides methods to get recommendations for products.
4
+ */
5
+ export interface IRecommenderService {
6
+ /**
7
+ * @deprecated Use `generateTopProduct` instead
8
+ */
9
+ getTopProducts: (accountId: string, siteId: string, locationId: string, count: number) => Promise<IRecommendedProduct[] | null>;
10
+ /**
11
+ * Generator function for the next existing top recommended product.
12
+ * Returns when out of existing products.
13
+ * @param accountId The account id of the client.
14
+ * @param siteId The site id of the client.
15
+ * @param locationId The location id on the site.
16
+ * @returns A recommended product.
17
+ */
18
+ generateTopProduct: (accountId: string, siteId: string, locationId: string) => AsyncGenerator<IProductInformation>;
19
+ /**
20
+ * @deprecated Use `generateForYou` instead
21
+ */
22
+ getForYou: (accountId: string, siteId: string, locationId: string, userId: string, count: number) => Promise<IRecommendedProduct[] | null>;
23
+ /**
24
+ * Generator function for the next existing product recommended for the given user.
25
+ * Returns when out of existing products.
26
+ * @param accountId The account id of the client.
27
+ * @param siteId The site id of the client.
28
+ * @param locationId The location id on the site.
29
+ * @param userId The user id.
30
+ * @returns A recommended product.
31
+ */
32
+ generateForYou: (accountId: string, siteId: string, locationId: string, userId: string) => AsyncGenerator<IProductInformation>;
33
+ /**
34
+ * @deprecated Use `generatePreviousPurchase` instead
35
+ */
36
+ getPreviousPurchases: (accountId: string, siteId: string, locationId: string, userId: string, count: number) => Promise<IRecommendedProduct[] | null>;
37
+ /**
38
+ * Generator function for the next existing product recommended based on the user's
39
+ * previous purchases. Returns when out of existing products.
40
+ * @param accountId The account id of the client.
41
+ * @param siteId The site id of the client.
42
+ * @param locationId The location id on the site.
43
+ * @param userId The user id.
44
+ * @returns A recommended product.
45
+ */
46
+ generatePreviousPurchase: (accountId: string, siteId: string, locationId: string, userId: string) => AsyncGenerator<IProductInformation>;
47
+ }
@@ -0,0 +1,31 @@
1
+ import type { IProductInformation, IRecommendedProduct } from '../../models';
2
+ import type { ILoggerService, IProductFeedService, IRecommenderService } from '../../services';
3
+ export declare class SurfsideRecommenderService implements IRecommenderService {
4
+ private readonly _productFeedService;
5
+ private readonly _logger?;
6
+ private readonly _cache;
7
+ private readonly _url;
8
+ constructor(url: string, _productFeedService: IProductFeedService, _logger?: ILoggerService | undefined);
9
+ /**
10
+ * @deprecated Use `generateTopProduct` instead
11
+ */
12
+ getTopProducts(accountId: string, siteId: string, locationId: string, count: number): Promise<IRecommendedProduct[] | null>;
13
+ generateTopProduct(accountId: string, siteId: string, locationId: string): AsyncGenerator<IProductInformation>;
14
+ /**
15
+ * @deprecated Use `generateForYou` instead.
16
+ */
17
+ getForYou(accountId: string, siteId: string, locationId: string, userId: string, count: number): Promise<IRecommendedProduct[] | null>;
18
+ generateForYou(accountId: string, siteId: string, locationId: string, userId: string): AsyncGenerator<IProductInformation>;
19
+ /**
20
+ * @deprecated Use `generatePreviousPurchase` instead.
21
+ */
22
+ getPreviousPurchases(accountId: string, siteId: string, locationId: string, userId: string, count: number): Promise<IRecommendedProduct[] | null>;
23
+ generatePreviousPurchase(accountId: string, siteId: string, locationId: string, userId: string): AsyncGenerator<IProductInformation>;
24
+ private _generateProductRecommendation;
25
+ private _fetchRecommendations;
26
+ /**
27
+ * Used for the generator methods; just returns a simple list of products instead of managing a cache
28
+ */
29
+ private _fetchRecommendationList;
30
+ private _generateProduct;
31
+ }
@@ -0,0 +1,2 @@
1
+ export * from './IRecommenderService';
2
+ export * from './SurfsideRecommenderService';
@@ -0,0 +1,12 @@
1
+ import type { IBidRequest, IBidResponse } from '../../../models';
2
+ /**
3
+ * The core service for sending bid requests and receiving bid responses.
4
+ */
5
+ export interface IBidderService {
6
+ /**
7
+ * Sends a bid request to the bidder
8
+ * @param request an OpenRTB 2.6 bid request
9
+ * @returns a promise that resolves with the OpenRTB 2.6 bid response
10
+ */
11
+ requestBids: (request: IBidRequest) => Promise<IBidResponse>;
12
+ }
@@ -0,0 +1,28 @@
1
+ import type { IBidRequest, IBidResponse } from '../../../models';
2
+ import type { IBidderService } from './IBidderService';
3
+ import type { IConfigurationService, IDeviceService, IGeoService, ILoggerService, IUserIDService } from '../../../services';
4
+ /**
5
+ * The surfside implementation of the IBidderService interface. Sends all request to
6
+ * the surfside bidder.
7
+ */
8
+ export declare class SurfsideBidderService implements IBidderService {
9
+ private readonly _configService;
10
+ private readonly _geoService;
11
+ private readonly _deviceService;
12
+ private readonly _userService;
13
+ private readonly _logger?;
14
+ private readonly _url;
15
+ /**
16
+ * Creates a new instance of the SurfsideBidderService, sending requests to the specified URL
17
+ * @param _url The URL of the bidder API
18
+ * @param _logger An optional logger service, for debugging purposes
19
+ */
20
+ constructor(url: string, _configService: IConfigurationService, _geoService: IGeoService, _deviceService: IDeviceService, _userService: IUserIDService, _logger?: ILoggerService | undefined);
21
+ /**
22
+ * Sends a bid request to the bidder. If the bidder returns a status code other than 200,
23
+ * a NoBidResponseError is thrown with the status code and status text as the message.
24
+ * @param request The OpenRTB 2.6 bid request
25
+ * @returns A promise that resolves with the OpenRTB 2.6 bid response
26
+ */
27
+ requestBids(request: IBidRequest): Promise<IBidResponse>;
28
+ }
@@ -0,0 +1,2 @@
1
+ export * from './IBidderService';
2
+ export * from './SurfsideBidderService';
@@ -0,0 +1,14 @@
1
+ import type { ICompiledPublisherConfiguration } from '../../../models';
2
+ /**
3
+ * The configuration service interface. account and site IDs come from the creative component attributes.
4
+ * Publisher configurations have flags for features on the site, and templates for rendering commerce media creatives.
5
+ */
6
+ export interface IConfigurationService {
7
+ /**
8
+ * Gets the configuration for the given account and site IDs
9
+ * @param accountId The account ID of the component making the request
10
+ * @param siteId The site ID of the component making the request
11
+ * @returns The configuration for the account and site IDs, or null if no configuration is found
12
+ */
13
+ getConfiguration: (accountId: string, siteId: string) => Promise<ICompiledPublisherConfiguration | null>;
14
+ }
@@ -0,0 +1,29 @@
1
+ import type { ICompiledPublisherConfiguration } from '../../../models';
2
+ import type { ILoggerService } from '../../../services';
3
+ import type { IConfigurationService } from './IConfigurationService';
4
+ /**
5
+ * The Surfside Configuration Service fetches the configuration for a given account and site.
6
+ */
7
+ export declare class SurfsideConfigurationService implements IConfigurationService {
8
+ private readonly _handlebars;
9
+ private readonly _logger?;
10
+ private readonly _url;
11
+ /**
12
+ * Creates a new instance of the Surfside Configuration Service with the specified URL and Handlebars instance.
13
+ * Handlebars is used to parse the clickthrough URL templates and product card templates for the configuration.
14
+ * It is a peer dependency, so you will need to add handlebars to your project.
15
+ * @param _url The URL of the configuration service
16
+ * @param _handlebars The Handlebars instance to use for parsing templates. Created with `Handlebars.create()`
17
+ * @param _logger An optional logger service, for debugging purposes
18
+ */
19
+ constructor(url: string, _handlebars: typeof Handlebars, _logger?: ILoggerService | undefined);
20
+ /**
21
+ * Fetches the configuration for the specified account and site.
22
+ * @param accountId The account ID of the client
23
+ * @param siteId The site ID of the client
24
+ * @returns A promise that resolves with the compiled configuration, or null if the fetch fails
25
+ */
26
+ getConfiguration(accountId: string, siteId: string): Promise<ICompiledPublisherConfiguration | null>;
27
+ private _mapConfig;
28
+ private _importModule;
29
+ }
@@ -0,0 +1,2 @@
1
+ export * from './IConfigurationService';
2
+ export * from './SurfsideConfigurationService';
@@ -0,0 +1,2 @@
1
+ export * from './bidder';
2
+ export * from './configuration';
@@ -0,0 +1,8 @@
1
+ import { OverrideService } from '../../../services/OverrideService';
2
+ import type { IDevice } from '../../../models';
3
+ import { type IDeviceService, type ILoggerService } from '../../../services';
4
+ export declare class DeviceOverrideService extends OverrideService<IDevice> implements IDeviceService {
5
+ constructor(logger?: ILoggerService);
6
+ getDeviceInfo(): Promise<IDevice | null>;
7
+ mapDataSetToData(dataset: DOMStringMap): IDevice | null;
8
+ }
@@ -0,0 +1,4 @@
1
+ import type { IDevice } from '../../../models';
2
+ export interface IDeviceService {
3
+ getDeviceInfo: () => Promise<IDevice | null>;
4
+ }
@@ -0,0 +1,16 @@
1
+ import type { ILoggerService } from '../../logger';
2
+ import { DeviceOverrideService } from './DeviceOverrideService';
3
+ import { type IBrandVersion, type IDevice } from '../../../models';
4
+ interface IDeviceContext {
5
+ make?: string;
6
+ model?: string;
7
+ os?: string;
8
+ osv?: string;
9
+ browser?: IBrandVersion;
10
+ }
11
+ export declare class SurfsideDeviceService extends DeviceOverrideService {
12
+ constructor(logger?: ILoggerService);
13
+ getDeviceInfo(): Promise<IDevice | null>;
14
+ }
15
+ export declare function TryGetDeviceInfo(): IDeviceContext | null;
16
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from './IDeviceService';
2
+ export * from './DeviceOverrideService';
3
+ export * from './SurfsideDeviceService';
@@ -0,0 +1,5 @@
1
+ import type { IBidRequest, IBidResponse } from '../../../models';
2
+ export interface IEventService {
3
+ raiseBidRequested: (request: IBidRequest) => Promise<void>;
4
+ raiseBidResponded: (response: IBidResponse, request: IBidRequest) => Promise<void>;
5
+ }
@@ -0,0 +1,42 @@
1
+ import type { IBidRequest, IBidResponse } from '../../../models';
2
+ import type { IEventService, ILoggerService } from '../../../services';
3
+ interface ISurfTrackerOptions {
4
+ appId: string;
5
+ cookieName: string;
6
+ collectorUrl: string;
7
+ discoverRootDomain: boolean;
8
+ cookieSameSite: string;
9
+ }
10
+ type SurfTrack = (action: string, ...args: any[]) => void;
11
+ interface ISurfTracker extends SurfTrack {
12
+ q?: any[];
13
+ }
14
+ declare global {
15
+ interface Window {
16
+ surf: ISurfTracker;
17
+ surfContext: any[];
18
+ }
19
+ }
20
+ export interface ISurfsideEventServiceLazyLoadConfig extends Partial<ISurfTrackerOptions> {
21
+ lazyLoad: true;
22
+ src: string;
23
+ }
24
+ export interface ISurfsideEventServiceDefaultConfig extends Partial<ISurfTrackerOptions> {
25
+ lazyLoad: false;
26
+ }
27
+ /**
28
+ * The surfside event service. This service is responsible for tracking events. It converts
29
+ * bid requests and responses to legacy snowplow/prebidJS style events and sends them to the
30
+ * surfside tracker.
31
+ */
32
+ export declare class SurfsideEventService implements IEventService {
33
+ private readonly _logger?;
34
+ private _surf;
35
+ private readonly _appId;
36
+ private readonly _collectorUrl;
37
+ private readonly _src?;
38
+ constructor(config?: ISurfsideEventServiceLazyLoadConfig | ISurfsideEventServiceDefaultConfig, _logger?: ILoggerService | undefined);
39
+ raiseBidRequested(request: IBidRequest): Promise<void>;
40
+ raiseBidResponded(response: IBidResponse, request: IBidRequest): Promise<void>;
41
+ }
42
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './IEventService';
2
+ export * from './SurfsideEventService';
@@ -0,0 +1,8 @@
1
+ import { OverrideService } from '../../../services/OverrideService';
2
+ import type { IGeoContext } from '../../../models';
3
+ import { type IGeoService, type ILoggerService } from '../../../services';
4
+ export declare class GeoOverrideService extends OverrideService<IGeoContext> implements IGeoService {
5
+ constructor(logger?: ILoggerService);
6
+ mapDataSetToData(dataset: DOMStringMap): IGeoContext | null;
7
+ getGeo(): Promise<IGeoContext | null>;
8
+ }
@@ -0,0 +1,12 @@
1
+ import type { IGeoContext } from '../../../models';
2
+ /**
3
+ * The geo service interface. Returns the geo context for the user, as well as the IP address of the user.
4
+ * This is useful for targeting ads based on the user's location, and is added to the "device" object in the bid request
5
+ */
6
+ export interface IGeoService {
7
+ /**
8
+ * Gets the geo context for the user, including the user's location and IP address
9
+ * @returns The geo context, or null if the geo context could not be retrieved
10
+ */
11
+ getGeo: () => Promise<IGeoContext | null>;
12
+ }
@@ -0,0 +1,7 @@
1
+ import type { IGeoContext } from '../../../models';
2
+ import type { ILoggerService } from '../../../services';
3
+ import { GeoOverrideService } from './GeoOverrideService';
4
+ export declare class SurfsideGeoService extends GeoOverrideService {
5
+ constructor(logger?: ILoggerService);
6
+ getGeo(): Promise<IGeoContext | null>;
7
+ }
@@ -0,0 +1,3 @@
1
+ export * from './IGeoService';
2
+ export * from './SurfsideGeoService';
3
+ export * from './GeoOverrideService';
@@ -0,0 +1,4 @@
1
+ export * from './geo';
2
+ export * from './user';
3
+ export * from './events';
4
+ export * from './device';
@@ -0,0 +1,4 @@
1
+ import type { IUserID } from '../../../models';
2
+ export interface IUserIDService {
3
+ getUserId: () => Promise<IUserID | null>;
4
+ }
@@ -0,0 +1,7 @@
1
+ import type { IUserID } from '../../../models';
2
+ import type { ILoggerService } from '../../../services';
3
+ import { UserOverrideService } from './UserOverrideService';
4
+ export declare class SurfsideUserIDService extends UserOverrideService {
5
+ constructor(logger?: ILoggerService);
6
+ getUserId(): Promise<IUserID | null>;
7
+ }
@@ -0,0 +1,8 @@
1
+ import { OverrideService } from '../../../services/OverrideService';
2
+ import type { IUserID } from '../../../models';
3
+ import { type ILoggerService, type IUserIDService } from '../../../services';
4
+ export declare class UserOverrideService extends OverrideService<IUserID> implements IUserIDService {
5
+ constructor(logger?: ILoggerService);
6
+ getUserId(): Promise<IUserID | null>;
7
+ mapDataSetToData(dataset: DOMStringMap): string | null;
8
+ }
@@ -0,0 +1,3 @@
1
+ export * from './IUserIDService';
2
+ export * from './SurfsideUserIDService';
3
+ export * from './UserOverrideService';
@@ -0,0 +1 @@
1
+ export declare function GetSafeUrl(relativeUrl: string): string;