@surfside/ads-core 2.0.14 → 2.0.16

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 (81) hide show
  1. package/lib/cjs/Api.js +43 -18
  2. package/lib/cjs/Api.js.map +1 -1
  3. package/lib/cjs/BuildInfo.js +5 -0
  4. package/lib/cjs/BuildInfo.js.map +1 -0
  5. package/lib/cjs/helpers/Handlebars.js +97 -36
  6. package/lib/cjs/helpers/Handlebars.js.map +1 -1
  7. package/lib/cjs/helpers/RequestBuilder.js +39 -3
  8. package/lib/cjs/helpers/RequestBuilder.js.map +1 -1
  9. package/lib/cjs/helpers/response/Carousel.js +1 -1
  10. package/lib/cjs/helpers/response/Carousel.js.map +1 -1
  11. package/lib/cjs/helpers/response/Clickthrough.js +4 -1
  12. package/lib/cjs/helpers/response/Clickthrough.js.map +1 -1
  13. package/lib/cjs/index.js +1 -0
  14. package/lib/cjs/index.js.map +1 -1
  15. package/lib/cjs/models/retail/Category.js +3 -0
  16. package/lib/cjs/models/retail/Category.js.map +1 -0
  17. package/lib/cjs/models/retail/Configuration.js.map +1 -1
  18. package/lib/cjs/models/rtb/BidRequest.js.map +1 -1
  19. package/lib/cjs/services/BotFiltering.js +43 -0
  20. package/lib/cjs/services/BotFiltering.js.map +1 -0
  21. package/lib/cjs/services/Category.js +75 -0
  22. package/lib/cjs/services/Category.js.map +1 -0
  23. package/lib/cjs/services/Configuration.js +65 -9
  24. package/lib/cjs/services/Configuration.js.map +1 -1
  25. package/lib/cjs/services/Dynamic.js +4 -4
  26. package/lib/cjs/services/Dynamic.js.map +1 -1
  27. package/lib/cjs/services/Logger.js.map +1 -1
  28. package/lib/cjs/services/Memo.js +1 -1
  29. package/lib/cjs/services/Memo.js.map +1 -1
  30. package/lib/cjs/services/Product.js +15 -9
  31. package/lib/cjs/services/Product.js.map +1 -1
  32. package/lib/cjs/services/Result.js.map +1 -1
  33. package/lib/cjs/services/Template.js +2 -2
  34. package/lib/cjs/services/Template.js.map +1 -1
  35. package/lib/esm/Api.js +44 -19
  36. package/lib/esm/Api.js.map +1 -1
  37. package/lib/esm/BuildInfo.js +2 -0
  38. package/lib/esm/BuildInfo.js.map +1 -0
  39. package/lib/esm/helpers/Handlebars.js +92 -33
  40. package/lib/esm/helpers/Handlebars.js.map +1 -1
  41. package/lib/esm/helpers/RequestBuilder.js +39 -3
  42. package/lib/esm/helpers/RequestBuilder.js.map +1 -1
  43. package/lib/esm/helpers/response/Carousel.js +1 -1
  44. package/lib/esm/helpers/response/Carousel.js.map +1 -1
  45. package/lib/esm/helpers/response/Clickthrough.js +4 -1
  46. package/lib/esm/helpers/response/Clickthrough.js.map +1 -1
  47. package/lib/esm/index.js +1 -0
  48. package/lib/esm/index.js.map +1 -1
  49. package/lib/esm/models/retail/Category.js +2 -0
  50. package/lib/esm/models/retail/Category.js.map +1 -0
  51. package/lib/esm/models/retail/Configuration.js.map +1 -1
  52. package/lib/esm/models/rtb/BidRequest.js.map +1 -1
  53. package/lib/esm/services/BotFiltering.js +38 -0
  54. package/lib/esm/services/BotFiltering.js.map +1 -0
  55. package/lib/esm/services/Category.js +71 -0
  56. package/lib/esm/services/Category.js.map +1 -0
  57. package/lib/esm/services/Configuration.js +65 -9
  58. package/lib/esm/services/Configuration.js.map +1 -1
  59. package/lib/esm/services/Dynamic.js +4 -4
  60. package/lib/esm/services/Dynamic.js.map +1 -1
  61. package/lib/esm/services/Logger.js.map +1 -1
  62. package/lib/esm/services/Memo.js +1 -1
  63. package/lib/esm/services/Memo.js.map +1 -1
  64. package/lib/esm/services/Product.js +15 -9
  65. package/lib/esm/services/Product.js.map +1 -1
  66. package/lib/esm/services/Result.js.map +1 -1
  67. package/lib/esm/services/Template.js +2 -2
  68. package/lib/esm/services/Template.js.map +1 -1
  69. package/lib/types/Api.d.ts +6 -0
  70. package/lib/types/BuildInfo.d.ts +5 -0
  71. package/lib/types/helpers/Handlebars.d.ts +25 -4
  72. package/lib/types/helpers/RequestBuilder.d.ts +7 -1
  73. package/lib/types/index.d.ts +1 -0
  74. package/lib/types/models/retail/Category.d.ts +15 -0
  75. package/lib/types/models/retail/Configuration.d.ts +4 -0
  76. package/lib/types/models/rtb/BidRequest.d.ts +1 -0
  77. package/lib/types/services/BotFiltering.d.ts +3 -0
  78. package/lib/types/services/Category.d.ts +4 -0
  79. package/lib/types/services/Dynamic.d.ts +3 -3
  80. package/lib/types/services/Product.d.ts +4 -4
  81. package/package.json +7 -2
@@ -1,3 +1,5 @@
1
+ import { type HelperDelegate } from 'handlebars';
2
+ import { type INativeTemplateDelegateWindow } from '../models';
1
3
  /**
2
4
  * Converts the passed string to a slug with the specified options. By default, the slug is hyphenated and only
3
5
  * contains alphanumeric characters. You can pass a different hyphenation regex and a different drop regex to
@@ -43,7 +45,16 @@ export declare function upper(name: string): string;
43
45
  * @param position The position of the path component to return, 1-indexed
44
46
  * @returns The path component at the specified position
45
47
  */
46
- export declare function path(position: number): string | undefined;
48
+ export declare const path: (pathname: string) => (position: number, options: {
49
+ hash: {
50
+ url?: string;
51
+ };
52
+ }) => string | undefined;
53
+ export declare function money(value: number | string, options: {
54
+ hash: {
55
+ cents?: boolean;
56
+ };
57
+ }): string;
47
58
  /**
48
59
  * A general-purpose string replacement tool - meant to behave like the Unix sed tool. Accepts a regex for
49
60
  * search, and a replacement string. for example, if the input string is "hello world" and the search is
@@ -96,7 +107,11 @@ export declare function replace(input: string, search: string, replacement: stri
96
107
  * @param name The name of the query parameter to return
97
108
  * @returns The value of the query parameter, or an empty string if the parameter is not found
98
109
  */
99
- export declare function search(name: string): string;
110
+ export declare const search: (search: string) => (name: string, options: {
111
+ hash: {
112
+ url?: string;
113
+ };
114
+ }) => string;
100
115
  /**
101
116
  * Returns the first truthy argument, or an empty string if all arguments are falsy. Returns false for empty strings
102
117
  * For example, {{coalesce false (eq "b" "d") c}} will return "c", because false is falsy, "b" is not equal to "d",
@@ -157,11 +172,17 @@ export declare function and(a: any, b: any): boolean;
157
172
  * @returns True if the value is in the array, false otherwise
158
173
  */
159
174
  export declare function isIn(a: any, b: any[]): boolean;
175
+ /**
176
+ * Grabs a variable off of the global window object. {{global "foo" "bar"}} will return `window.foo.bar`.
177
+ * If any part of the path is undefined, this returns undefined with no exceptions
178
+ * @returns The global variable
179
+ */
180
+ export declare function global(...args: any[]): any;
160
181
  /**
161
182
  * Returns an array of the passed arguments. Useful with the "in" helper
162
183
  * @group TemplateHelpers
163
184
  * @returns An array of the passed arguments
164
185
  */
165
186
  export declare function array(...args: any[]): any[];
166
- export type HandlebarsHelpers = Record<string, Function>;
167
- export declare const GetHelpers: () => HandlebarsHelpers;
187
+ export type HandlebarsHelpers = Record<string, HelperDelegate>;
188
+ export declare const GetHelpers: (windowInfo: INativeTemplateDelegateWindow) => HandlebarsHelpers;
@@ -1,5 +1,7 @@
1
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
2
  import { type ILogger } from '../services';
3
+ import { type NativeRequestBuilder } from './NativeRequestBuilder';
4
+ import { type GenerateCategoriesFn } from '../services/Category';
3
5
  export type RequestBuilderFn = (zoneId: string, id?: string) => RequestBuilder;
4
6
  export type RequestWith<T> = (t: T) => RequestBuilder;
5
7
  export type RequestBuilder = {
@@ -8,9 +10,13 @@ export type RequestBuilder = {
8
10
  withApp: RequestWith<IApp>;
9
11
  withSite: RequestWith<ISite>;
10
12
  withKeywords: RequestWith<string[]>;
13
+ withSurfCategory: RequestWith<string[]>;
11
14
  withBanner: (w: number, h: number, options?: Partial<IBanner>, impOptions?: Partial<IImp>) => RequestBuilder;
12
15
  withVideo: (w: number, h: number, minduration: number | undefined, maxduration: number, mimes?: string[], options?: Partial<IVideo>, impOptions?: Partial<IImp>) => RequestBuilder;
13
16
  withNative: (request: string | INativeRequest, options?: Partial<INative>, impOptions?: Partial<IImp>) => RequestBuilder;
17
+ withNatives: (requests: (string | INativeRequest)[], options?: Partial<INative>, impOptions?: Partial<IImp>) => RequestBuilder;
18
+ withNativeCopies: (request: string | INativeRequest, n: number, options?: Partial<INative>, impOptions?: Partial<IImp>) => RequestBuilder;
19
+ withProductCards: (nativeBuilder: NativeRequestBuilder, options?: Partial<INative>, impOptions?: Partial<IImp>) => RequestBuilder;
14
20
  build: () => IBidRequest;
15
21
  };
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;
22
+ export declare function StartRequest(logger: ILogger | undefined, accountId: string, siteId: string, channelId: string, locationId: string, device: IDevice | undefined, geo: IGeoContext | undefined, userId: string | undefined, generateCategories: GenerateCategoriesFn, zoneId: string, id?: string): RequestBuilder;
@@ -2,3 +2,4 @@ export * from './helpers';
2
2
  export * from './models';
3
3
  export * from './services';
4
4
  export * from './Api';
5
+ export * from './BuildInfo';
@@ -0,0 +1,15 @@
1
+ export type CategoryStrategy = 'url';
2
+ export interface ICompiledCategoryGlobalConfigDTO {
3
+ globalCanonicalMap: Record<string, string>;
4
+ globalPatterns: string[];
5
+ }
6
+ export interface ICompiledCategoryPublisherConfigurationDTO {
7
+ 'strategy': CategoryStrategy;
8
+ customCanonicalMap: Record<string, string>;
9
+ customPatterns: string[];
10
+ }
11
+ export interface ICompiledCategoryPublisherConfiguration {
12
+ strategy: CategoryStrategy;
13
+ canonicalMap: Record<string, string>;
14
+ patterns: string[];
15
+ }
@@ -1,4 +1,5 @@
1
1
  import type { IDynamicZone, IProductInformation } from '../../models';
2
+ import type { ICompiledCategoryPublisherConfiguration, ICompiledCategoryPublisherConfigurationDTO } from './Category';
2
3
  export type ProductCallback = (e: Event, product: IProductInformation) => void;
3
4
  export type Callbacks = Record<string, ProductCallback>;
4
5
  export type TemplateDelegate = (context: IProductContext) => string;
@@ -53,14 +54,17 @@ export interface ICompiledPublisherConfigurationSettingsDTO {
53
54
  reauctionIntervalMs: number;
54
55
  productFeedEnabled: boolean;
55
56
  sponsoredByEnabled?: boolean;
57
+ defaultImage?: string;
56
58
  }
57
59
  export interface ICompiledPublisherConfigurationDTO {
58
60
  templates: ICompiledPublisherConfigurationTemplatesDTO;
59
61
  settings: ICompiledPublisherConfigurationSettingsDTO;
62
+ category: ICompiledCategoryPublisherConfigurationDTO;
60
63
  dynamicZones?: Record<string, IDynamicZone>;
61
64
  }
62
65
  export interface ICompiledPublisherConfiguration {
63
66
  settings: ICompiledPublisherConfigurationSettingsDTO;
64
67
  templates: ICompiledPublisherConfigurationTemplates;
68
+ category: ICompiledCategoryPublisherConfiguration;
65
69
  dynamicZones?: Record<string, IDynamicZone>;
66
70
  }
@@ -406,5 +406,6 @@ export interface ISurfExtension {
406
406
  locationId: string;
407
407
  storeId: string;
408
408
  accountLocationId: string;
409
+ surfCategory: string[];
409
410
  keywords?: string[];
410
411
  }
@@ -0,0 +1,3 @@
1
+ import { ILogger } from './Logger';
2
+ export declare const FilterBots: <TArgs extends readonly unknown[], TReturn>(logger: ILogger | undefined, userAgent: string, fn: (...args: TArgs) => TReturn, fallback: (...args: TArgs) => TReturn) => (...args: TArgs) => TReturn;
3
+ export declare const FilterBotsAsyncGenerator: <TArgs extends readonly unknown[], TReturn>(logger: ILogger | undefined, userAgent: string, fn: (...args: TArgs) => AsyncGenerator<TReturn>) => (...args: TArgs) => AsyncGenerator<Awaited<TReturn>, void, any>;
@@ -0,0 +1,4 @@
1
+ import { type ICompiledCategoryPublisherConfiguration } from '../models/retail/Category';
2
+ import { type ILogger } from './Logger';
3
+ export type GenerateCategoriesFn = (providedCategories: string[]) => string[];
4
+ export declare const GenerateCategories: (logger: ILogger | undefined, providedCategories: string[], page: string, categoryConfig: ICompiledCategoryPublisherConfiguration) => string[];
@@ -8,17 +8,17 @@ export interface IDynamicZoneRequest {
8
8
  request: IBidRequest;
9
9
  requestIds: Record<string, DynamicCreative>;
10
10
  }
11
- export type BuildDynamicZoneRequestFn = (zoneId: string, dynamicZone: IDynamicZone) => Result<IDynamicZoneRequest>;
11
+ export type BuildDynamicZoneRequestFn = (zoneId: string, dynamicZone: IDynamicZone, category?: string[]) => Result<IDynamicZoneRequest>;
12
12
  export type GetDynamicZoneFn = (zoneId: string) => AsyncResult<IDynamicZone>;
13
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>;
14
+ export declare const BuildDynamicZoneRequest: (logger: ILogger | undefined, startRequest: RequestBuilderFn, nativeRequest: NativeRequestBuilderFn, screenInfo: IScreen, zoneId: string, dynamicZone: IDynamicZone, category?: string[]) => Result<IDynamicZoneRequest>;
15
15
  export declare class NoDynamicScreenSizeMatchError extends Error {
16
16
  readonly dynamicZone: IDynamicZone;
17
17
  readonly screenInfo: IScreen;
18
18
  readonly selectedStringSize: string;
19
19
  constructor(dynamicZone: IDynamicZone, screenInfo: IScreen, selectedStringSize: string);
20
20
  }
21
- export declare const buildDynamicBidRequestFromSelectedScreenSize: (logger: ILogger | undefined, startRequest: RequestBuilderFn, nativeRequest: NativeRequestBuilderFn, zoneId: string, screenSize: IScreenSize) => Result<IDynamicZoneRequest>;
21
+ export declare const buildDynamicBidRequestFromSelectedScreenSize: (logger: ILogger | undefined, startRequest: RequestBuilderFn, nativeRequest: NativeRequestBuilderFn, zoneId: string, screenSize: IScreenSize, category?: string[]) => Result<IDynamicZoneRequest>;
22
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
23
  export declare class MissingDynamicZoneError extends Error {
24
24
  readonly zoneId: string;
@@ -1,12 +1,12 @@
1
- import type { IProductInformation } from '../models';
1
+ import type { ICompiledPublisherConfiguration, IProductInformation } from '../models';
2
2
  import { type ILogger } from './Logger';
3
3
  import { type Result, type AsyncResult } from './Result';
4
4
  export type GetSponsoredProductFromNativeIdFn = (nativeId: string) => AsyncGenerator<IProductInformation>;
5
5
  export type GetAllSponsoredProductFromNativeIdFn = (nativeId: string) => Promise<Result<IProductInformation[]>>;
6
6
  export type GetRecommendedProductFromProductIdFn = (productId: string) => AsyncResult<IProductInformation>;
7
- export declare const GetAllSponsoredProducts: (logger: ILogger | undefined, url: string, accountId: string, locationId: string, nativeId: string) => Promise<Result<IProductInformation[]>>;
8
- export declare const GetAllSponsoredBrandProducts: (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>;
7
+ export declare const GetAllSponsoredProducts: (logger: ILogger | undefined, url: string, config: ICompiledPublisherConfiguration, accountId: string, locationId: string, nativeId: string) => Promise<Result<IProductInformation[]>>;
8
+ export declare const GetAllSponsoredBrandProducts: (logger: ILogger | undefined, url: string, config: ICompiledPublisherConfiguration, accountId: string, locationId: string, nativeId: string) => Promise<Result<IProductInformation[]>>;
9
+ export declare const GetRecommendedProduct: (logger: ILogger | undefined, url: string, config: ICompiledPublisherConfiguration, accountId: string, locationId: string, productId: string) => AsyncResult<IProductInformation>;
10
10
  export declare class NoNativeError extends Error {
11
11
  nativeId: string;
12
12
  constructor(nativeId: string);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@surfside/ads-core",
3
- "version": "2.0.14",
3
+ "version": "2.0.16",
4
4
  "module": "./lib/esm/index.js",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "types": "./lib/types/index.d.ts",
@@ -24,6 +24,7 @@
24
24
  "@types/jest": "^29.5.14",
25
25
  "eslint": "^9.25.1",
26
26
  "jest": "^29.7.0",
27
+ "npm-run-all": "^4.1.5",
27
28
  "ts-jest": "^29.3.2",
28
29
  "typedoc": "^0.28.5",
29
30
  "typescript-eslint": "^8.41.0"
@@ -36,7 +37,11 @@
36
37
  },
37
38
  "scripts": {
38
39
  "clean": "rm -rf ./lib",
39
- "build": "tsc -p ./tsconfig.types.json && tsc -p ./tsconfig.esm.json && tsc -p tsconfig.cjs.json",
40
+ "prebuild": "echo \"export const SurfsideAdsCoreVersionInfo = { buildBranch: '$(git rev-parse --abbrev-ref HEAD)', buildHash: '$(git rev-parse --short HEAD)', buildVer: '$(bun -e 'console.log(require(\"./package.json\").version)')'};\" > src/BuildInfo.ts",
41
+ "build": "bunx npm-run-all --parallel \"types\" \"esm\" \"cjs\"",
42
+ "types": "tsc -p ./tsconfig.types.json",
43
+ "esm": "tsc -p ./tsconfig.esm.json",
44
+ "cjs": "tsc -p tsconfig.cjs.json",
40
45
  "lint": "npx eslint"
41
46
  }
42
47
  }