@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,169 @@
1
+ import type { INativeTemplateDelegateWindow, ICompiledPublisherConfiguration, IDevice, IGeoContext } from './models';
2
+ import { AsyncResult, INavigator, type IScreen, RequestBidsFn, ILogger, GetSponsoredProductFromNativeIdFn, PersonalRecommenderFn, NonPersonalRecommenderFn, GetConfigurationFn, GetGeoFn, GetDeviceFn, GetRecommendedProductFromProductIdFn, GetAllSponsoredProductFromNativeIdFn } from './services';
3
+ import { BuildAllSponsoredProductCardResponsesFn, GenerateSponsoredProductCardResponseFn, NativeRequestBuilderFn, RequestBuilderFn } from './helpers';
4
+ import Handlebars from 'handlebars/runtime';
5
+ import { BuildHybridCarouselFn, BuildHybridCarouselFromInitialBidFn, BuildRecommendedCarouselFn, BuildSponsoredCarouselFn, BuildSponsoredCarouselFromInitialBidFn } from './helpers/response/Carousel';
6
+ import { type EvaluateClickthroughTemplateFn, type EvaluateProductCardTemplateFn } from './services/Template';
7
+ import { BuildDynamicZoneRequestFn, GetDynamicZoneFn } from './services/Dynamic';
8
+ export declare const PROD_BIDDER = "//rtb.surfside.io/rtb/bids/surfside";
9
+ export declare const PROD_CONFIGURATION_SERVICE = "//r.surfside.io";
10
+ export declare const PROD_SPONSORED_PRODUCT_FEED = "//creative.surfside.io";
11
+ export declare const PROD_RECOMMENDED_PRODUCT_FEED = "//creative.surfside.io";
12
+ export declare const PROD_RECOMMENDER_SERVICE = "//t.surfside.io";
13
+ export declare const PROD_DYNAMIC_ZONE_SERVICE = "//r.surfside.io/";
14
+ /**
15
+ * A collection of services for querying the surfside API and building responses
16
+ */
17
+ export interface ISurfsideApi {
18
+ /**
19
+ * An optional logger
20
+ */
21
+ logger?: ILogger;
22
+ /**
23
+ * Gets information about the User's device in OpenRTB's device format
24
+ */
25
+ getDevice: GetDeviceFn;
26
+ /**
27
+ * The user's device info
28
+ */
29
+ device: IDevice | undefined;
30
+ /**
31
+ * Gets the user's current current geo and IP information.
32
+ */
33
+ getGeo: GetGeoFn;
34
+ /**
35
+ * The user's current geo and IP information
36
+ */
37
+ geo: IGeoContext | undefined;
38
+ /**
39
+ * The site's publisher configuration. Product card templates, clickthrough URL templates, settings, etc.
40
+ */
41
+ configuration: ICompiledPublisherConfiguration;
42
+ /**
43
+ * Gets the site's publisher configuration
44
+ */
45
+ getConfiguration: GetConfigurationFn;
46
+ /**
47
+ * A handlebars runtime instance, for evaluating templates
48
+ */
49
+ handlebars: typeof Handlebars;
50
+ /**
51
+ * Sends a bid request to the bidder and returns its response, if available
52
+ */
53
+ requestBids: RequestBidsFn;
54
+ /**
55
+ * Builds an OpenRTB 2.6 request
56
+ */
57
+ startRequest: RequestBuilderFn;
58
+ /**
59
+ * Builds an OpenRTB Native 1.2 request
60
+ */
61
+ startNative: NativeRequestBuilderFn;
62
+ /**
63
+ * Builds an OpenRTB Native 1.2 request with initial fields, such as site, app, and trackers
64
+ */
65
+ defaultNative: NativeRequestBuilderFn;
66
+ /**
67
+ * Creates a sponsored product generator from the given Native Creative ID. One native creative ID can generate
68
+ * multiple products
69
+ */
70
+ getSponsoredProduct: GetSponsoredProductFromNativeIdFn;
71
+ /**
72
+ * Gets all sponsored products from the native creative ID. One native creative ID can generate multiple products
73
+ */
74
+ getAllSponsoredProducts: GetAllSponsoredProductFromNativeIdFn;
75
+ /**
76
+ * Gets the associated product info for the site from a product ID
77
+ */
78
+ getRecommendedProduct: GetRecommendedProductFromProductIdFn;
79
+ /**
80
+ * Creates a recommended product generator for the top (most popular) products on the site.
81
+ */
82
+ generateTopProducts: NonPersonalRecommenderFn;
83
+ /**
84
+ * Creates a recommended product generator for products recommended for the user. If there are no recommended
85
+ * products for the user, or if the API was initialized without a user ID, this will return a generator for top
86
+ * products instead
87
+ */
88
+ generateForYou: PersonalRecommenderFn;
89
+ /**
90
+ * Creates a recommended product generator based on the user's previously purchased products. If there are no
91
+ * recommended products for the user, or if the API was initialized without a user ID, this will return a generator
92
+ * for top products instead
93
+ */
94
+ generatePreviousPurchases: PersonalRecommenderFn;
95
+ /**
96
+ * Creates a carousel state object using the bid request. The state object is a callback function which sends the
97
+ * bid request to the bidder and generates product cards from it. When the bid is out of product cards, the
98
+ * generator will request more bids with the same bid request. If no bids are returned, the generator completes.
99
+ */
100
+ buildSponsoredCarousel: BuildSponsoredCarouselFn;
101
+ /**
102
+ * Creates a carousel state object using the bid request and initializes it with a pre-existing bid. This is used
103
+ * for dynamic zones and probably doesn't need to be used in any client applications. The state object is a callback
104
+ * function which sends the bid request to the bidder and generates product cards from it. When the bid is out of
105
+ * product cards, the generator will request more bids with the same bid request. If no bids are returned, the
106
+ * generator completes.
107
+ */
108
+ buildSponsoredCarouselFromInitialBid: BuildSponsoredCarouselFromInitialBidFn;
109
+ /**
110
+ * Creates a carousel state object with recommendations from the given recommender type (top product, for you,
111
+ * previous purchases). The state object is a callback function which sends the bid request to the bidder and
112
+ * generates product cards from it. When the bid is out of product cards, the generator will request more bids with
113
+ * the same bid request. If no bids are returned, the generator completes.
114
+ */
115
+ buildRecommendedCarousel: BuildRecommendedCarouselFn;
116
+ buildHybridCarousel: BuildHybridCarouselFn;
117
+ buildHybridCarouselFromInitialBid: BuildHybridCarouselFromInitialBidFn;
118
+ buildAllSponsoredProductCardResponses: BuildAllSponsoredProductCardResponsesFn;
119
+ generateSponsoredProductCardResponse: GenerateSponsoredProductCardResponseFn;
120
+ evaluateProductCardTemplate: EvaluateProductCardTemplateFn;
121
+ evaluateClickthroughTemplate: EvaluateClickthroughTemplateFn;
122
+ getDynamicZone: GetDynamicZoneFn;
123
+ buildDynamicZoneRequest: BuildDynamicZoneRequestFn;
124
+ }
125
+ /**
126
+ * Initializes the API with the services explicitly passed to it. This function is used by the framework for overloading
127
+ * mock services. It should not be used in an application
128
+ * @param internalApiDto The list of services and helpers to inject
129
+ * @returns An initialized Surfside API
130
+ */
131
+ export declare function InitSurfAdsCoreInternal(internalApiDto: {
132
+ logger: ILogger | undefined;
133
+ requestBids: RequestBidsFn;
134
+ getConfiguration: GetConfigurationFn;
135
+ getGeo: GetGeoFn;
136
+ getDevice: GetDeviceFn;
137
+ getSponsoredProduct: GetSponsoredProductFromNativeIdFn;
138
+ getAllSponsoredProducts: GetAllSponsoredProductFromNativeIdFn;
139
+ getRecommendedProduct: GetRecommendedProductFromProductIdFn;
140
+ generateTopProducts: NonPersonalRecommenderFn;
141
+ generateForYou: PersonalRecommenderFn;
142
+ generatePreviousPurchases: PersonalRecommenderFn;
143
+ getDynamicZone: GetDynamicZoneFn;
144
+ buildAllSponsoredProductCardResponses: BuildAllSponsoredProductCardResponsesFn;
145
+ generateSponsoredProductCardResponse: GenerateSponsoredProductCardResponseFn;
146
+ evaluateProductCardTemplate: EvaluateProductCardTemplateFn;
147
+ evaluateClickthroughTemplate: EvaluateClickthroughTemplateFn;
148
+ handlebars: typeof Handlebars;
149
+ windowInfo: INativeTemplateDelegateWindow;
150
+ screenInfo: IScreen;
151
+ navigator: INavigator;
152
+ mobile: boolean;
153
+ ip: string | undefined;
154
+ geoProviderToken: string | undefined;
155
+ accountId: string;
156
+ siteId: string;
157
+ channelId: string;
158
+ locationId: string;
159
+ userId: string | undefined;
160
+ }): AsyncResult<ISurfsideApi>;
161
+ export declare const InitSurfAdsCoreServices: (logger: ILogger | undefined, bidderServiceUrl: string, configurationServiceUrl: string, productFeedUrl: string, recommendedProductFeedUrl: string, recommenderServiceUrl: string, dynamicZoneServiceUrl: string, windowInfo: INativeTemplateDelegateWindow, screenInfo: IScreen, navigator: INavigator, mobile: boolean, ip: string | undefined, geoProviderToken: string | undefined, accountId: string, siteId: string, channelId: string, locationId: string, userId: string | undefined) => AsyncResult<ISurfsideApi>;
162
+ export declare const InitSurfAdsCoreSSR: (windowInfo: INativeTemplateDelegateWindow, screen: IScreen, navigator: INavigator, mobile: boolean, ip: string, geoProviderToken: string, accountId: string, siteId: string, channelId: string, locationId: string, userId: string | undefined, logger?: ILogger) => AsyncResult<ISurfsideApi>;
163
+ export declare const InitSurfAdsCore: (channelId: string, accountId: string, siteId: string, locationId: string, userId: string | undefined, logger?: ILogger) => AsyncResult<ISurfsideApi>;
164
+ export declare class MissingConfigurationError extends Error {
165
+ constructor(accountId: string, siteId: string);
166
+ }
167
+ export declare class NotABrowserError extends Error {
168
+ constructor();
169
+ }
@@ -0,0 +1,46 @@
1
+ export declare enum HttpStatus {
2
+ OK = 200,
3
+ NO_CONTENT = 204,
4
+ BAD_REQUEST = 400,
5
+ NOT_FOUND = 404,
6
+ UNAUTHORIZED = 401,
7
+ FORBIDDEN = 403
8
+ }
9
+ export declare enum HttpStatusClass {
10
+ SUCCESS = 2,
11
+ CLIENT_ERROR = 4,
12
+ SERVER_ERROR = 5
13
+ }
14
+ export declare enum SurfColors {
15
+ INDIGO = "#331c7a",
16
+ ULTRAMARINE = "#1f69ff",
17
+ AQUAMARINE = "#4ceaaa",
18
+ ELECTRIC_LIME = "#c5f700",
19
+ CRAYOLA = "#f7a800",
20
+ ORANGE = "#f66d18",
21
+ RED = "#e72024",
22
+ LAVENDER = "#c0abff",
23
+ ULTRA_RED = "#f97585",
24
+ SOFT_GOLD = "#f4bd5d",
25
+ MAGIC_MINT = "#baf7db",
26
+ SKY_BLUE = "#7eceeb",
27
+ CARIBBEAN_GREN = "#0dcc91",
28
+ LAVENDER_GRAY = "#d3d3e0"
29
+ }
30
+ export declare enum IPServices {
31
+ IP2LOCATION = 1,
32
+ NEUSTAR = 2,
33
+ MAXMIND = 3,
34
+ NETACUITY = 4
35
+ }
36
+ export declare enum LocationType {
37
+ GPS = 1,
38
+ IP = 2,
39
+ USER = 3
40
+ }
41
+ export declare enum Environment {
42
+ PROD = "PROD",
43
+ STAGING = "STAGING",
44
+ LOCAL = "LOCAL",
45
+ MOCK = "MOCK"
46
+ }
@@ -0,0 +1,3 @@
1
+ export declare class NoBidResponseError extends Error {
2
+ constructor(message: string);
3
+ }
@@ -0,0 +1,5 @@
1
+ export declare const ConsumeN: <T>(generator: Generator<T>, n: number) => T[];
2
+ export declare const ConsumeAll: <T>(generator: Generator<T>) => T[];
3
+ export declare const ConsumeNAsync: <T>(generator: AsyncGenerator<T>, n: number) => Promise<[data: T[], finished: boolean]>;
4
+ export declare const ConsumeAllAsync: <T>(generator: AsyncGenerator<T>) => Promise<T[]>;
5
+ export declare function GenerateArray<T>(data: T[]): Generator<T>;
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Converts the passed string to a slug with the specified options. By default, the slug is hyphenated and only
3
+ * contains alphanumeric characters. You can pass a different hyphenation regex and a different drop regex to
4
+ * customize the slug. For example, {{slug "My Product Name"}} will return "my-product-name".
5
+ *
6
+ * To change which characters are converted to hyphens, you can pass a regular expression to the hyphenate option.
7
+ * For example, {{slug "My Product's Name" hyphenate="[\s']"}} will return "my-product-s-name".
8
+ * The default hyphenate regex is /[\s_\-,]/ig.
9
+ *
10
+ * To remove characters instead of hyphenate them, you can pass a regular expression to the drop option.
11
+ * For example, {{slug "My Product's Name" drop="[^A-Za-z0-9\s']"}} will return "my-product's-name".
12
+ * The default drop regex is /[^A-Za-z0-9\-]/ig.
13
+ *
14
+ * To limit the max number of hyphenated slug components returned, you can pass a length option.
15
+ * For example, {{slug "My Product's Name" length=2}} will return "my-product".
16
+ * The default length is 5.
17
+ *
18
+ * @param name The string to be slugified
19
+ * @param options The options object. Can take "hypenate", "drop", and "length" options.
20
+ * @returns The slugified string
21
+ */
22
+ export declare function slug(name: string, options: {
23
+ hash: {
24
+ hyphenate: string | undefined;
25
+ drop: string | undefined;
26
+ dropBefore: string | undefined;
27
+ length: number | undefined;
28
+ separator: string | undefined;
29
+ };
30
+ }): string;
31
+ /**
32
+ * Converts the passed string to lowercase. For example, {{lower "My Product Name"}} will return "my product name".
33
+ *
34
+ * @param name The string to be converted to lowercase
35
+ * @returns A lowercase version of the passed string
36
+ */
37
+ export declare function lower(name: string): string;
38
+ export declare function upper(name: string): string;
39
+ /**
40
+ * Returns the path component of the URL at the specified position, 1-indexed
41
+ * For example, if the URL is "https://example.com/foo/bar", {{path 1}} will return "foo".
42
+ *
43
+ * @param position The position of the path component to return, 1-indexed
44
+ * @returns The path component at the specified position
45
+ */
46
+ export declare function path(position: number): string | undefined;
47
+ export declare function sed(input: string, searchRegex: string, replacement: string): string;
48
+ export declare function replace(input: string, search: string, replacement: string, all?: boolean): string;
49
+ /**
50
+ * Returns the value of the specified query parameter from the URL, specified by key.
51
+ * For example, if the URL is "https://example.com?foo=bar", {{search "foo"}} will return "bar".
52
+ *
53
+ * @param name The name of the query parameter to return
54
+ * @returns The value of the query parameter, or an empty string if the parameter is not found
55
+ */
56
+ export declare function search(name: string): string;
57
+ /**
58
+ * Returns the first truthy argument, or an empty string if all arguments are falsy. Returns false for empty strings
59
+ * For example, {{coalesce false (eq "b" "d") c}} will return "c", because false is falsy, "b" is not equal to "d",
60
+ * and c is truthy.
61
+ *
62
+ * @returns The first truthy argument, or an empty string if all arguments are falsy
63
+ */
64
+ export declare function coalesce(): string;
65
+ /**
66
+ * Joins the passed arguments with the specified separator.
67
+ * For example, {{join "foo" "bar" "baz"}} will return "foo/bar/baz"..
68
+ *
69
+ * There is an optional "separator" argument that can be passed to change the separator. For example,
70
+ * {{join "foo" "bar" "baz" separator=","}} will return "foo,bar,baz".
71
+ *
72
+ * @returns The joined string
73
+ */
74
+ export declare function join(): string;
75
+ /**
76
+ * Encodes the passed string for use in a URI component.
77
+ *
78
+ * @param component The string to encode
79
+ * @returns The encoded string, or an empty string if the component is falsy
80
+ */
81
+ export declare function uri(component: string): string;
82
+ /**
83
+ * Returns true if the two passed arguments are equal (using javascript ===), false otherwise.
84
+ *
85
+ * @param a The first argument
86
+ * @param b The second argument
87
+ * @returns True if the two arguments are equal, false otherwise
88
+ */
89
+ export declare function eq(a: any, b: any): boolean;
90
+ /**
91
+ * Returns true if either of the passed arguments are truthy, false otherwise.
92
+ *
93
+ * @param a The first argument
94
+ * @param b The second argument
95
+ * @returns True if either of the arguments are truthy, false otherwise
96
+ */
97
+ export declare function or(a: any, b: any): boolean;
98
+ /**
99
+ * Returns true if both of the passed arguments are truthy, false otherwise.
100
+ *
101
+ * @param a The first argument
102
+ * @param b The second argument
103
+ * @returns True if both of the arguments are truthy, false otherwise
104
+ */
105
+ export declare function and(a: any, b: any): boolean;
106
+ /**
107
+ * Returns true if the first argument is in the second argument (an array). Otherwise, returns false.
108
+ * If the second argument is not an array, or the array is empty, this will return false.
109
+ *
110
+ * The name of the helper is "in" but the name of the function is "isIn" because "in" is a reserved word in javascript.
111
+ *
112
+ * @param a The value to check
113
+ * @param b The array to check against
114
+ * @returns True if the value is in the array, false otherwise
115
+ */
116
+ export declare function isIn(a: any, b: any[]): boolean;
117
+ /**
118
+ * Returns an array of the passed arguments. Useful with the "in" helper
119
+ *
120
+ * @returns An array of the passed arguments
121
+ */
122
+ export declare function array(): any[];
123
+ export type HandlebarsHelpers = Record<string, Function>;
124
+ export declare const GetHelpers: () => HandlebarsHelpers;
@@ -0,0 +1,29 @@
1
+ import { type INativeRequest } from '../models';
2
+ import { ILogger } from '../services';
3
+ export type NativeRequestBuilderFn = () => NativeRequestBuilder;
4
+ export type NativeRequestBuilder = {
5
+ withVer: (ver: string) => NativeRequestBuilder;
6
+ withContext: (context: number) => NativeRequestBuilder;
7
+ withContextSubType: (contextSubType: number) => NativeRequestBuilder;
8
+ withPlacementType: (placementType: number) => NativeRequestBuilder;
9
+ withTitle: (length?: number, required?: boolean) => NativeRequestBuilder;
10
+ withImage: (width: number, height: number, minWidth?: number, minHeight?: number, required?: boolean) => NativeRequestBuilder;
11
+ withVideo: (mimes: number[] | string[], minDuration: number, maxDuration: number, required?: boolean) => NativeRequestBuilder;
12
+ withData: (type: number, id: number, length?: number, required?: boolean) => NativeRequestBuilder;
13
+ withSponsored: (length?: number, required?: boolean) => NativeRequestBuilder;
14
+ withDescription: (length?: number, required?: boolean) => NativeRequestBuilder;
15
+ withRating: (length?: number, required?: boolean) => NativeRequestBuilder;
16
+ withPrice: (length?: number, required?: boolean) => NativeRequestBuilder;
17
+ withSalePrice: (length?: number, required?: boolean) => NativeRequestBuilder;
18
+ withDisplayURL: (length?: number, required?: boolean) => NativeRequestBuilder;
19
+ withCTAText: (length?: number, required?: boolean) => NativeRequestBuilder;
20
+ withCategory: (length?: number, required?: boolean) => NativeRequestBuilder;
21
+ withTHC: (length?: number, required?: boolean) => NativeRequestBuilder;
22
+ withCBD: (length?: number, required?: boolean) => NativeRequestBuilder;
23
+ withStrain: (length?: number, required?: boolean) => NativeRequestBuilder;
24
+ withMetaProduct: (length?: number, required?: boolean) => NativeRequestBuilder;
25
+ withEventTracker: (event: number, methods: number[]) => NativeRequestBuilder;
26
+ build: () => INativeRequest;
27
+ };
28
+ export declare const StartNative: (logger: ILogger | undefined) => NativeRequestBuilder;
29
+ export declare const DefaultNative: (logger: ILogger | undefined) => NativeRequestBuilder;
@@ -0,0 +1,16 @@
1
+ import { type IApp, type IBanner, type IBidRequest, type IDevice, type IGeoContext, type IImp, type INative, type INativeRequest, type IRegs, type ISite, type IUser, type IVideo } from '../models';
2
+ import { ILogger } from '../services';
3
+ export type RequestBuilderFn = (zoneId: string, id?: string) => RequestBuilder;
4
+ export type RequestWith<T> = (t: T) => RequestBuilder;
5
+ export type RequestBuilder = {
6
+ withUser: RequestWith<IUser>;
7
+ withRegulations: RequestWith<IRegs>;
8
+ withApp: RequestWith<IApp>;
9
+ withSite: RequestWith<ISite>;
10
+ withKeywords: RequestWith<string[]>;
11
+ withBanner: (w: number, h: number, options?: Partial<IBanner>, impOptions?: Partial<IImp>) => RequestBuilder;
12
+ withVideo: (w: number, h: number, minduration: number, maxduration: number, mimes?: string[], options?: Partial<IVideo>, impOptions?: Partial<IImp>) => RequestBuilder;
13
+ withNative: (request: string | INativeRequest, options?: Partial<INative>, impOptions?: Partial<IImp>) => RequestBuilder;
14
+ build: () => IBidRequest;
15
+ };
16
+ export declare function StartRequest(logger: ILogger | undefined, accountId: string, siteId: string, channelId: string, locationId: string, device: IDevice | undefined, geo: IGeoContext | undefined, userId: string | undefined, zoneId: string, id?: string): RequestBuilder;
@@ -0,0 +1,2 @@
1
+ import { Result } from '../services';
2
+ export declare const TryGet: <T>(get: () => T) => Result<T>;
@@ -0,0 +1,3 @@
1
+ import { INativeTemplateDelegateWindow } from '../models';
2
+ import { Result } from '../services';
3
+ export declare const GetWindowInfo: () => Result<INativeTemplateDelegateWindow>;
@@ -0,0 +1,2 @@
1
+ export declare function CollectN<T>(generator: Generator<T>, n: number): T[];
2
+ export declare function CollectNAsync<T>(generator: AsyncGenerator<T>, n: number): Promise<T[]>;
@@ -0,0 +1 @@
1
+ export * from './CollectN';
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Converts the passed string to a slug with the specified options. By default, the slug is hyphenated and only
3
+ * contains alphanumeric characters. You can pass a different hyphenation regex and a different drop regex to
4
+ * customize the slug. For example, {{slug "My Product Name"}} will return "my-product-name".
5
+ *
6
+ * To change which characters are converted to hyphens, you can pass a regular expression to the hyphenate option.
7
+ * For example, {{slug "My Product's Name" hyphenate="[\s']"}} will return "my-product-s-name".
8
+ * The default hyphenate regex is /[\s_\-,]/ig.
9
+ *
10
+ * To remove characters instead of hyphenate them, you can pass a regular expression to the drop option.
11
+ * For example, {{slug "My Product's Name" drop="[^A-Za-z0-9\s']"}} will return "my-product's-name".
12
+ * The default drop regex is /[^A-Za-z0-9\-]/ig.
13
+ *
14
+ * To limit the max number of hyphenated slug components returned, you can pass a length option.
15
+ * For example, {{slug "My Product's Name" length=2}} will return "my-product".
16
+ * The default length is 5.
17
+ *
18
+ * @param name The string to be slugified
19
+ * @param options The options object. Can take "hypenate", "drop", and "length" options.
20
+ * @returns The slugified string
21
+ */
22
+ export declare function slug(name: string, options: {
23
+ hash: {
24
+ hyphenate: string | undefined;
25
+ drop: string | undefined;
26
+ length: number | undefined;
27
+ };
28
+ }): string;
29
+ /**
30
+ * Converts the passed string to lowercase. For example, {{lower "My Product Name"}} will return "my product name".
31
+ *
32
+ * @param name The string to be converted to lowercase
33
+ * @returns A lowercase version of the passed string
34
+ */
35
+ export declare function lower(name: string): string;
36
+ /**
37
+ * Returns the path component of the URL at the specified position, 1-indexed
38
+ * For example, if the URL is "https://example.com/foo/bar", {{path 1}} will return "foo".
39
+ *
40
+ * @param position The position of the path component to return, 1-indexed
41
+ * @returns The path component at the specified position
42
+ */
43
+ export declare function path(position: number): string;
44
+ export declare function global(): any;
45
+ export declare function sed(input: string, searchRegex: string, replacement: string): string;
46
+ /**
47
+ * Returns the value of the specified query parameter from the URL, specified by key.
48
+ * For example, if the URL is "https://example.com?foo=bar", {{search "foo"}} will return "bar".
49
+ *
50
+ * @param name The name of the query parameter to return
51
+ * @returns The value of the query parameter, or an empty string if the parameter is not found
52
+ */
53
+ export declare function search(name: string): string;
54
+ /**
55
+ * Returns the first truthy argument, or an empty string if all arguments are falsy. Returns false for empty strings
56
+ * For example, {{coalesce false (eq "b" "d") c}} will return "c", because false is falsy, "b" is not equal to "d",
57
+ * and c is truthy.
58
+ *
59
+ * @returns The first truthy argument, or an empty string if all arguments are falsy
60
+ */
61
+ export declare function coalesce(): string;
62
+ /**
63
+ * Joins the passed arguments with the specified separator.
64
+ * For example, {{join "foo" "bar" "baz"}} will return "foo/bar/baz"..
65
+ *
66
+ * There is an optional "separator" argument that can be passed to change the separator. For example,
67
+ * {{join "foo" "bar" "baz" separator=","}} will return "foo,bar,baz".
68
+ *
69
+ * @returns The joined string
70
+ */
71
+ export declare function join(): string;
72
+ /**
73
+ * Encodes the passed string for use in a URI component.
74
+ *
75
+ * @param component The string to encode
76
+ * @returns The encoded string, or an empty string if the component is falsy
77
+ */
78
+ export declare function uri(component: string): string;
79
+ /**
80
+ * Returns true if the two passed arguments are equal (using javascript ===), false otherwise.
81
+ *
82
+ * @param a The first argument
83
+ * @param b The second argument
84
+ * @returns True if the two arguments are equal, false otherwise
85
+ */
86
+ export declare function eq(a: any, b: any): boolean;
87
+ /**
88
+ * Returns true if either of the passed arguments are truthy, false otherwise.
89
+ *
90
+ * @param a The first argument
91
+ * @param b The second argument
92
+ * @returns True if either of the arguments are truthy, false otherwise
93
+ */
94
+ export declare function or(a: any, b: any): boolean;
95
+ /**
96
+ * Returns true if both of the passed arguments are truthy, false otherwise.
97
+ *
98
+ * @param a The first argument
99
+ * @param b The second argument
100
+ * @returns True if both of the arguments are truthy, false otherwise
101
+ */
102
+ export declare function and(a: any, b: any): boolean;
103
+ /**
104
+ * Returns true if the first argument is in the second argument (an array). Otherwise, returns false.
105
+ * If the second argument is not an array, or the array is empty, this will return false.
106
+ *
107
+ * The name of the helper is "in" but the name of the function is "isIn" because "in" is a reserved word in javascript.
108
+ *
109
+ * @param a The value to check
110
+ * @param b The array to check against
111
+ * @returns True if the value is in the array, false otherwise
112
+ */
113
+ export declare function isIn(a: any, b: any[]): boolean;
114
+ /**
115
+ * Returns an array of the passed arguments. Useful with the "in" helper
116
+ *
117
+ * @returns An array of the passed arguments
118
+ */
119
+ export declare function array(): any[];
@@ -0,0 +1,7 @@
1
+ export * from './NativeRequestBuilder';
2
+ export * from './RequestBuilder';
3
+ export * from './response';
4
+ export * from './Handlebars';
5
+ export * from './TryGet';
6
+ export * from './Window';
7
+ export * from './Generator';
@@ -0,0 +1,124 @@
1
+ import type { IApp, IBanner, IBidRequest, IDevice, IImp, INative, IRegs, ISite, IUser, IVideo } from '../../models';
2
+ declare enum BuilderCreativeType {
3
+ BANNER = 0,
4
+ VIDEO = 1,
5
+ NATIVE = 2
6
+ }
7
+ interface IBuilderState<T, U> {
8
+ currentCreative: T;
9
+ type: U;
10
+ imp: IImp;
11
+ }
12
+ export interface IBannerBuilderState extends IBuilderState<IBanner, BuilderCreativeType.BANNER> {
13
+ }
14
+ export interface IVideoBuilderState extends IBuilderState<IVideo, BuilderCreativeType.VIDEO> {
15
+ }
16
+ export interface INativeBuilderState extends IBuilderState<INative, BuilderCreativeType.NATIVE> {
17
+ }
18
+ /** Builds an OpenRTB 2.6 bid request */
19
+ export declare class RequestBuilder {
20
+ private readonly _request;
21
+ private _builderState;
22
+ /**
23
+ *
24
+ * @param id The ID of the request. If not provided, a random ID will be generated.
25
+ */
26
+ constructor(id?: string);
27
+ /**
28
+ *
29
+ * @returns The built bid request
30
+ */
31
+ build(): IBidRequest;
32
+ /**
33
+ * Adds surfside-specific information to the top level bid request and all subsequent impression objects
34
+ * @param accountId The account ID of the current store
35
+ * @param siteId The site ID of the current store
36
+ * @param locationId The location ID of the current store (i.e: the ID of the specific brick and mortar store)
37
+ * @param zoneId The ID for the zone on the advertisement
38
+ * @param channelId The channel ID being advertised on
39
+ * @param keywords A set of keywords describing the content of the page.
40
+ * @returns The builder instance
41
+ */
42
+ withSurfContext(accountId: string, siteId: string, locationId: string, zoneId: string, channelId?: string, keywords?: string[]): this;
43
+ /**
44
+ * Adds a banner impression to the request. If a creative is already being built,
45
+ * it will be appended to the request.
46
+ * @param w The width of the banner being requested
47
+ * @param h The height of the banner being requested
48
+ * @param options Other OpenRTB fields to include in the banner object.
49
+ * @returns The builder instance
50
+ */
51
+ withBanner(w: number, h: number, options?: Partial<IBanner>): this;
52
+ /**
53
+ * Adds a video impression to the request. If a create is already being built,
54
+ * it will be appended to the request
55
+ * @param w The width of the video being requested
56
+ * @param h The height of the video being requested
57
+ * @param minduration The minimum duration of the video, in seconds
58
+ * @param maxduration The maximum duration of the video, in seconds
59
+ * @param mimes A list of MIME types supported by the video. Defaults to ['video/mp4', 'video/webm']
60
+ * @param options Other OpenRTB fields to include in the video object
61
+ * @returns The builder instance
62
+ */
63
+ withVideo(w: number, h: number, minduration: number, maxduration: number, mimes?: string[], options?: Partial<IVideo>): this;
64
+ /**
65
+ * Adds a native impression to the request. If a creative is already being built,
66
+ * it will be appended to the request. Native requests are stringified JSON objects
67
+ * in the OpenRTB Native 1.2 format. Use the NativeRequestBuilder to build these objects.
68
+ * @param request The native request object, as a stringified JSON object
69
+ * @param options Other OpenRTB fields to include in the native object
70
+ * @returns The builder instance
71
+ */
72
+ withNative(request: string, options?: Partial<INative>): this;
73
+ /**
74
+ * Sets the bid floor on the current impression. This operates on each impression,
75
+ * so it needs to be called again for each impression if multiple are present.
76
+ * @param bidfloor The bid floor to set
77
+ * @param bidfloorcur The currency of the bid floor. Defaults to 'USD'
78
+ * @returns The builder instance
79
+ */
80
+ withBidFloor(bidfloor: number, bidfloorcur?: string): this;
81
+ /**
82
+ * Adds an extension to the current impression. Extensions are dynamically typed dictionaries
83
+ * with options that are specific to the bidder. This operates on each impression, so it needs
84
+ * to be called again for each impression if multiple are present.
85
+ * @param ext The extension to add
86
+ * @returns The builder instance
87
+ */
88
+ withImpExt(ext: any): this;
89
+ /**
90
+ * The site that the ad appears on.
91
+ * @param site The site object. If not provided, a default site object will be created using the current hostname.
92
+ * @returns The builder instance
93
+ */
94
+ withSite(site?: ISite): this;
95
+ /**
96
+ * The app that the ad appears in.
97
+ * @param app The app object. If not provided, a default app object will be created using the current hostname.
98
+ * @returns The builder instance
99
+ */
100
+ withApp(app?: IApp): this;
101
+ /**
102
+ * Information about the current user's device, including useragent, IP, make and model as well as geo information.
103
+ * @param device The device object
104
+ * @returns The builder instance
105
+ */
106
+ withDevice(device: IDevice): this;
107
+ /**
108
+ * Information about the current user. Geo information can be included here, but is different
109
+ * from the device's geo information; this is the user's home location.
110
+ * @param user The user object
111
+ * @returns The builder instance
112
+ */
113
+ withUser(user: IUser): this;
114
+ /**
115
+ * Used if any data privacy regulations are relevant to the request (i.e: COPPA, GDPR, etc.)
116
+ * @param regs The regs object
117
+ * @returns The builder instance
118
+ */
119
+ withRegulations(regs: IRegs): this;
120
+ private _appendBuilderState;
121
+ private _appendImpression;
122
+ private _generateId;
123
+ }
124
+ export {};