@adhese/sdk 1.12.3 → 1.13.0-nightly-20261002071913

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @adhese/sdk
2
2
 
3
+ ## 1.13.0-nightly-20261002071913
4
+
5
+ ### Minor Changes
6
+
7
+ - 54b51de: Move the default Adhese hosts to the new `adhese.eu` domains.
8
+
9
+ - `host`: `https://ads-<account>.adhese.com` → `https://<account>.ads.adhese.eu`
10
+ - `poolHost`: `https://pool-<account>.adhese.com` → `https://<account>.pool.adhese.eu`
11
+ - `previewHost`: `https://<account>-preview.adhese.org` → `https://<account>.preview.adhese.eu`
12
+
13
+ This applies to the SDK, the server-side ad request helpers, SDK Lite and the user sync plugin. The devtools campaign, booking and creative links now point to `https://<account>.classic.adhese.eu`.
14
+
15
+ Setups that pass `host`, `poolHost` or `previewHost` explicitly are not affected. If your site restricts outgoing requests (for example with a Content-Security-Policy `connect-src` or `frame-src`), add the new `*.adhese.eu` hosts.
16
+
3
17
  ## 1.12.3
4
18
 
5
19
  ### Patch Changes
package/README.md CHANGED
@@ -68,8 +68,8 @@ The `createAdhese` function accepts the following options:
68
68
  | Option | Type | Default | Description |
69
69
  |-----------------------|---------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
70
70
  | `account`<sup>*</sup> | `string` | - | Your Adhese account ID |
71
- | `host` | `string` | <code>'https://ads-<span v-pre>{{account}}</span>.adhese.com'</code> | The Adhese API host |
72
- | `poolHost` | `string` | <code>'https://pool-<span v-pre>{{account}}</span>.adhese.com'</code> | The Adhese pool host |
71
+ | `host` | `string` | <code>'https://<span v-pre>{{account}}</span>.ads.adhese.eu'</code> | The Adhese API host |
72
+ | `poolHost` | `string` | <code>'https://<span v-pre>{{account}}</span>.pool.adhese.eu'</code> | The Adhese pool host |
73
73
  | `location` | `string` | `window.location.pathname` | The page location. This is used to determine the current page location identifier. |
74
74
  | `requestType` | `'GET'` or `'POST'` | `'POST'` | The requestAds type to use for the Adhese API requests. This can be either `GET` or `POST`. `POST` is the default and offers the most options. `GET` is more limited as it needs pass its data as search parameters but can be used in environments where `POST` requests are not allowed. |
75
75
  | `debug` | `boolean` | `false` | Enable debug mode |
@@ -519,21 +519,21 @@ type BaseOptions = {
519
519
  * The url that is used to connect to the Adhese ad server. Pass a custom URL if you want to use your own domain for
520
520
  * the connection.
521
521
  *
522
- * @default 'https://ads-{{account}}.adhese.com'
522
+ * @default 'https://{{account}}.ads.adhese.eu'
523
523
  */
524
524
  host?: string;
525
525
  /**
526
526
  * The url that is used to connect to the Adhese pool server. Pass a custom URL if you want to use your own domain for
527
527
  * the connection.
528
528
  *
529
- * @default 'https://pool-{{account}}.adhese.com'
529
+ * @default 'https://{{account}}.pool.adhese.eu'
530
530
  */
531
531
  poolHost?: string;
532
532
  /**
533
533
  * The url that is used to connect to the Adhese preview server. Pass a custom URL if you want to use your own domain for
534
534
  * the connection.
535
535
  *
536
- * @default 'https://{{account}}-preview.adhese.org'
536
+ * @default 'https://{{account}}.preview.adhese.eu'
537
537
  */
538
538
  previewHost?: string;
539
539
  /**
package/dist/cjs/main.cjs CHANGED
@@ -14,9 +14,9 @@ function createAdhese(options) {
14
14
  return scope.run(() => {
15
15
  var _a, _b, _c;
16
16
  const mergedOptions = {
17
- host: `https://ads-${options.account}.adhese.com`,
18
- poolHost: `https://pool-${options.account}.adhese.com`,
19
- previewHost: `https://${options.account}-preview.adhese.org`,
17
+ host: `https://${options.account}.ads.adhese.eu`,
18
+ poolHost: `https://${options.account}.pool.adhese.eu`,
19
+ previewHost: `https://${options.account}.preview.adhese.eu`,
20
20
  location: "homepage",
21
21
  requestType: "POST",
22
22
  debug: false,
@@ -1 +1 @@
1
- {"version":3,"file":"main.cjs","sources":["../../src/main.ts"],"sourcesContent":["import type {\n Adhese,\n AdheseContextStateWithPlugins,\n AdheseOptions,\n AdhesePlugin,\n MergedOptions,\n} from './main.types';\nimport type { AdheseSlot, AdheseSlotOptions } from './slot/slot.types';\nimport {\n awaitTimeout,\n createEventManager,\n effectScope,\n omit,\n reactive,\n watch,\n} from '@adhese/sdk-shared';\nimport { version } from '../package.json';\nimport { useConsent } from './consent/consent';\nimport { createGlobalHooks } from './hooks';\nimport { logger } from './logger/logger';\nimport {\n useMainDebugMode,\n useMainParameters,\n useMainQueryDetector,\n} from './main.composables';\nimport { fetchAllUnrenderedSlots } from './main.utils';\nimport { useQueryDetector } from './queryDetector/queryDetector';\nimport { createSlotManager } from './slotManager/slotManager';\n\n/**\n * Creates an Adhese instance. This instance is your main entry point to the Adhese API.\n *\n * @param options {AdheseOptions} The options to create the Adhese instance with. See the {@link AdheseOptions} type for more information.\n *\n * @return Adhese The Adhese instance.\n */\nexport function createAdhese<T extends ReadonlyArray<AdhesePlugin>>(\n options: AdheseOptions<T>,\n): Adhese<T> {\n const scope = effectScope();\n\n return scope.run(() => {\n const mergedOptions: MergedOptions = {\n host: `https://ads-${options.account}.adhese.com`,\n poolHost: `https://pool-${options.account}.adhese.com`,\n previewHost: `https://${options.account}-preview.adhese.org`,\n location: 'homepage',\n requestType: 'POST',\n debug: false,\n initialSlots: [],\n findDomSlotsOnLoad: false,\n consent: false,\n logReferrer: true,\n logUrl: true,\n eagerRendering: false,\n viewabilityTracking: true,\n refreshOnResize: true,\n ...options,\n };\n\n import('./requestAds/requestAds.schema').catch(logger.error);\n\n const hooks = createGlobalHooks();\n\n const context = reactive<AdheseContextStateWithPlugins<T>>({\n location: mergedOptions.location,\n consent: mergedOptions.consent,\n debug: mergedOptions.debug,\n options: mergedOptions,\n logger,\n isDisposed: false,\n parameters: new Map(),\n events: createEventManager(),\n slots: new Map(),\n device: 'unknown',\n hooks,\n plugins: {},\n dispose,\n findDomSlots,\n getAll,\n get,\n addSlot,\n });\n\n for (const [index, plugin] of options.plugins?.entries() ?? []) {\n const data = plugin(context, {\n index,\n version,\n hooks,\n });\n\n const name = data.name as keyof typeof context.plugins;\n context.plugins[name] = omit(data, [\n 'name',\n ]) as (typeof context.plugins)[typeof name];\n }\n\n watch(\n () => context.location,\n (newLocation) => {\n context.events?.locationChange.dispatch(newLocation);\n },\n );\n\n useMainParameters(context, mergedOptions);\n\n const slotManager = createSlotManager({\n initialSlots: mergedOptions.initialSlots,\n context,\n });\n\n function getAll(): ReadonlyArray<AdheseSlot> {\n return slotManager.getAll() ?? [];\n }\n context.getAll = getAll;\n\n function get(name: string): AdheseSlot | undefined {\n return slotManager.get(name);\n }\n context.get = get;\n\n function addSlot(slotOptions: AdheseSlotOptions): Readonly<AdheseSlot> {\n return slotManager.add(slotOptions);\n }\n context.addSlot = addSlot;\n\n async function findDomSlots(): Promise<ReadonlyArray<AdheseSlot>> {\n const domSlots = ((await slotManager.findDomSlots()) ?? []).filter(\n slot => !slot.lazyLoading,\n );\n\n if (domSlots.length <= 0)\n return [];\n\n await fetchAllUnrenderedSlots(context.getAll());\n\n return domSlots;\n }\n context.findDomSlots = findDomSlots;\n\n useMainDebugMode(context);\n if (mergedOptions.refreshOnResize) {\n useMainQueryDetector(mergedOptions, context);\n }\n else {\n const [device] = useQueryDetector(context, mergedOptions.queries);\n context.device = device.value;\n context.parameters?.set('dt', device.value);\n context.parameters?.set('br', device.value);\n }\n\n useConsent(context);\n\n function dispose(): void {\n context.isDisposed = true;\n\n slotManager.dispose();\n context.parameters?.clear();\n context.events?.dispose();\n\n hooks.runOnDispose();\n hooks.clearAll();\n\n scope.stop();\n }\n context.dispose = dispose;\n\n hooks.onInit(async () => {\n await awaitTimeout(0);\n\n if (mergedOptions.findDomSlotsOnLoad)\n await context?.findDomSlots();\n\n logger.debug('Created Adhese SDK instance', {\n mergedOptions,\n });\n\n if (!scope.active)\n dispose();\n });\n\n hooks.runOnInit();\n\n return context as Adhese<T>;\n })!;\n}\n"],"names":["effectScope","logger","hooks","createGlobalHooks","reactive","createEventManager","version","omit","watch","_a","useMainParameters","slotManager","createSlotManager","fetchAllUnrenderedSlots","useMainDebugMode","useMainQueryDetector","useQueryDetector","useConsent","_b","awaitTimeout"],"mappings":";;;;;;;;;;;AAoCO,SAAS,aACd,SACW;AACX,QAAM,QAAQA,UAAAA,YAAA;AAEd,SAAO,MAAM,IAAI,MAAM;;AACrB,UAAM,gBAA+B;AAAA,MACnC,MAAM,eAAe,QAAQ,OAAO;AAAA,MACpC,UAAU,gBAAgB,QAAQ,OAAO;AAAA,MACzC,aAAa,WAAW,QAAQ,OAAO;AAAA,MACvC,UAAU;AAAA,MACV,aAAa;AAAA,MACb,OAAO;AAAA,MACP,cAAc,CAAA;AAAA,MACd,oBAAoB;AAAA,MACpB,SAAS;AAAA,MACT,aAAa;AAAA,MACb,QAAQ;AAAA,MACR,gBAAgB;AAAA,MAChB,qBAAqB;AAAA,MACrB,iBAAiB;AAAA,MACjB,GAAG;AAAA,IAAA;AAGL,YAAA,QAAA,EAAA,KAAA,MAAA,QAAO,oCAAgC,CAAA,EAAE,MAAMC,OAAAA,OAAO,KAAK;AAE3D,UAAMC,UAAQC,MAAAA,kBAAA;AAEd,UAAM,UAAUC,UAAAA,SAA2C;AAAA,MACzD,UAAU,cAAc;AAAA,MACxB,SAAS,cAAc;AAAA,MACvB,OAAO,cAAc;AAAA,MACrB,SAAS;AAAA,MAAA,QACTH,OAAAA;AAAAA,MACA,YAAY;AAAA,MACZ,gCAAgB,IAAA;AAAA,MAChB,QAAQI,UAAAA,mBAAA;AAAA,MACR,2BAAW,IAAA;AAAA,MACX,QAAQ;AAAA,MAAA,OACRH;AAAAA,MACA,SAAS,CAAA;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAED,eAAW,CAAC,OAAO,MAAM,OAAK,aAAQ,YAAR,mBAAiB,cAAa,IAAI;AAC9D,YAAM,OAAO,OAAO,SAAS;AAAA,QAC3B;AAAA,QAAA,SACAI,SAAAA;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MAAM,OAAO;AAAA,IACvC;AAEAC,YAAAA,WAAW,OAAO;AAElB,aAAS,UAAgB;;AACvB,cAAQ,aAAa;AAErBN,oBAAY,QAAA;AACZ,OAAAF,MAAA,QAAQ,eAAR,gBAAAA,IAAoB;AACpB,OAAAS,MAAA,QAAQ,WAAR,gBAAAA,IAAgB;AAEhBhB,cAAM,aAAA;AACNA,cAAM,SAAA;AAEN,YAAM,KAAA;AAAA,IACR;AACA,YAAQ,UAAU;AAElBA,YAAM,OAAO,YAAY;AACvB,YAAMiB,UAAAA,aAAa,CAAC;AAEpB,UAAI,cAAc;AAChB,eAAM,mCAAS;AAEjBlB,aAAAA,OAAO,MAAM,+BAA+B;AAAA,QAC1C;AAAA,MAAA,CACD;AAED,UAAI,CAAC,MAAM;AACT,gBAAA;AAAA,IACJ,CAAC;AAEDC,YAAM,UAAA;AAEN,WAAO;AAAA,EACT,CAAC;AACH;;"}
1
+ {"version":3,"file":"main.cjs","sources":["../../src/main.ts"],"sourcesContent":["import type {\n Adhese,\n AdheseContextStateWithPlugins,\n AdheseOptions,\n AdhesePlugin,\n MergedOptions,\n} from './main.types';\nimport type { AdheseSlot, AdheseSlotOptions } from './slot/slot.types';\nimport {\n awaitTimeout,\n createEventManager,\n effectScope,\n omit,\n reactive,\n watch,\n} from '@adhese/sdk-shared';\nimport { version } from '../package.json';\nimport { useConsent } from './consent/consent';\nimport { createGlobalHooks } from './hooks';\nimport { logger } from './logger/logger';\nimport {\n useMainDebugMode,\n useMainParameters,\n useMainQueryDetector,\n} from './main.composables';\nimport { fetchAllUnrenderedSlots } from './main.utils';\nimport { useQueryDetector } from './queryDetector/queryDetector';\nimport { createSlotManager } from './slotManager/slotManager';\n\n/**\n * Creates an Adhese instance. This instance is your main entry point to the Adhese API.\n *\n * @param options {AdheseOptions} The options to create the Adhese instance with. See the {@link AdheseOptions} type for more information.\n *\n * @return Adhese The Adhese instance.\n */\nexport function createAdhese<T extends ReadonlyArray<AdhesePlugin>>(\n options: AdheseOptions<T>,\n): Adhese<T> {\n const scope = effectScope();\n\n return scope.run(() => {\n const mergedOptions: MergedOptions = {\n host: `https://${options.account}.ads.adhese.eu`,\n poolHost: `https://${options.account}.pool.adhese.eu`,\n previewHost: `https://${options.account}.preview.adhese.eu`,\n location: 'homepage',\n requestType: 'POST',\n debug: false,\n initialSlots: [],\n findDomSlotsOnLoad: false,\n consent: false,\n logReferrer: true,\n logUrl: true,\n eagerRendering: false,\n viewabilityTracking: true,\n refreshOnResize: true,\n ...options,\n };\n\n import('./requestAds/requestAds.schema').catch(logger.error);\n\n const hooks = createGlobalHooks();\n\n const context = reactive<AdheseContextStateWithPlugins<T>>({\n location: mergedOptions.location,\n consent: mergedOptions.consent,\n debug: mergedOptions.debug,\n options: mergedOptions,\n logger,\n isDisposed: false,\n parameters: new Map(),\n events: createEventManager(),\n slots: new Map(),\n device: 'unknown',\n hooks,\n plugins: {},\n dispose,\n findDomSlots,\n getAll,\n get,\n addSlot,\n });\n\n for (const [index, plugin] of options.plugins?.entries() ?? []) {\n const data = plugin(context, {\n index,\n version,\n hooks,\n });\n\n const name = data.name as keyof typeof context.plugins;\n context.plugins[name] = omit(data, [\n 'name',\n ]) as (typeof context.plugins)[typeof name];\n }\n\n watch(\n () => context.location,\n (newLocation) => {\n context.events?.locationChange.dispatch(newLocation);\n },\n );\n\n useMainParameters(context, mergedOptions);\n\n const slotManager = createSlotManager({\n initialSlots: mergedOptions.initialSlots,\n context,\n });\n\n function getAll(): ReadonlyArray<AdheseSlot> {\n return slotManager.getAll() ?? [];\n }\n context.getAll = getAll;\n\n function get(name: string): AdheseSlot | undefined {\n return slotManager.get(name);\n }\n context.get = get;\n\n function addSlot(slotOptions: AdheseSlotOptions): Readonly<AdheseSlot> {\n return slotManager.add(slotOptions);\n }\n context.addSlot = addSlot;\n\n async function findDomSlots(): Promise<ReadonlyArray<AdheseSlot>> {\n const domSlots = ((await slotManager.findDomSlots()) ?? []).filter(\n slot => !slot.lazyLoading,\n );\n\n if (domSlots.length <= 0)\n return [];\n\n await fetchAllUnrenderedSlots(context.getAll());\n\n return domSlots;\n }\n context.findDomSlots = findDomSlots;\n\n useMainDebugMode(context);\n if (mergedOptions.refreshOnResize) {\n useMainQueryDetector(mergedOptions, context);\n }\n else {\n const [device] = useQueryDetector(context, mergedOptions.queries);\n context.device = device.value;\n context.parameters?.set('dt', device.value);\n context.parameters?.set('br', device.value);\n }\n\n useConsent(context);\n\n function dispose(): void {\n context.isDisposed = true;\n\n slotManager.dispose();\n context.parameters?.clear();\n context.events?.dispose();\n\n hooks.runOnDispose();\n hooks.clearAll();\n\n scope.stop();\n }\n context.dispose = dispose;\n\n hooks.onInit(async () => {\n await awaitTimeout(0);\n\n if (mergedOptions.findDomSlotsOnLoad)\n await context?.findDomSlots();\n\n logger.debug('Created Adhese SDK instance', {\n mergedOptions,\n });\n\n if (!scope.active)\n dispose();\n });\n\n hooks.runOnInit();\n\n return context as Adhese<T>;\n })!;\n}\n"],"names":["effectScope","logger","hooks","createGlobalHooks","reactive","createEventManager","version","omit","watch","_a","useMainParameters","slotManager","createSlotManager","fetchAllUnrenderedSlots","useMainDebugMode","useMainQueryDetector","useQueryDetector","useConsent","_b","awaitTimeout"],"mappings":";;;;;;;;;;;AAoCO,SAAS,aACd,SACW;AACX,QAAM,QAAQA,UAAAA,YAAA;AAEd,SAAO,MAAM,IAAI,MAAM;;AACrB,UAAM,gBAA+B;AAAA,MACnC,MAAM,WAAW,QAAQ,OAAO;AAAA,MAChC,UAAU,WAAW,QAAQ,OAAO;AAAA,MACpC,aAAa,WAAW,QAAQ,OAAO;AAAA,MACvC,UAAU;AAAA,MACV,aAAa;AAAA,MACb,OAAO;AAAA,MACP,cAAc,CAAA;AAAA,MACd,oBAAoB;AAAA,MACpB,SAAS;AAAA,MACT,aAAa;AAAA,MACb,QAAQ;AAAA,MACR,gBAAgB;AAAA,MAChB,qBAAqB;AAAA,MACrB,iBAAiB;AAAA,MACjB,GAAG;AAAA,IAAA;AAGL,YAAA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{
7
7
  return new Map(Object.entries(record));
8
8
  }
9
9
  async function fetchWithPost(options, signal) {
10
- const host = `https://ads-${options.account}.adhese.com`;
10
+ const host = `https://${options.account}.ads.adhese.eu`;
11
11
  const payload = {
12
12
  slots: options.slots.map((slot) => ({
13
13
  slotname: sdkShared.generateName(options.location, slot.format, slot.slot),
@@ -26,7 +26,7 @@ async function fetchWithPost(options, signal) {
26
26
  });
27
27
  }
28
28
  async function fetchWithGet(options, signal) {
29
- const host = `https://ads-${options.account}.adhese.com`;
29
+ const host = `https://${options.account}.ads.adhese.eu`;
30
30
  const slotNames = options.slots.map((slot) => sdkShared.generateName(options.location, slot.format, slot.slot)).join("/sl");
31
31
  return fetch(`${host}/json/sl${slotNames}`, {
32
32
  method: "GET",
@@ -1 +1 @@
1
- {"version":3,"file":"server.cjs","sources":["../../src/server.ts"],"sourcesContent":["import { generateName } from '@adhese/sdk-shared';\nimport { type AdheseAd, parseResponse } from './requestAds/requestAds.schema';\nimport { parseParameters } from './requestAds/requestAds.utils';\n\nexport type FetchAdsSlot = {\n format: string;\n slot?: string;\n parameters?: Record<string, string | ReadonlyArray<string>>;\n};\n\ntype FetchAdsOptionsBase = {\n /**\n * The account name for the Adhese API\n */\n account: string;\n /**\n * The location/page identifier\n */\n location: string;\n /**\n * Array of slot configurations to fetch ads for\n */\n slots: ReadonlyArray<FetchAdsSlot>;\n /**\n * Request timeout in milliseconds. If the request takes longer than this,\n * an empty array is returned to prevent blocking page load.\n * Set to 0 or undefined for no timeout.\n */\n timeout?: number;\n};\n\ntype FetchAdsOptionsPost = FetchAdsOptionsBase & {\n /**\n * Use POST request (default). Supports global parameters.\n */\n requestType?: 'POST';\n /**\n * Global parameters to send with the request. Only available with POST.\n */\n parameters?: Record<string, string | ReadonlyArray<string>>;\n};\n\ntype FetchAdsOptionsGet = FetchAdsOptionsBase & {\n /**\n * Use GET request. More limited - does not support global parameters.\n */\n requestType: 'GET';\n};\n\nexport type FetchAdsOptions = FetchAdsOptionsPost | FetchAdsOptionsGet;\n\nfunction toMap<T>(record: Record<string, T>): Map<string, T> {\n return new Map(Object.entries(record));\n}\n\nasync function fetchWithPost(\n options: FetchAdsOptionsPost,\n signal?: AbortSignal,\n): Promise<Response> {\n const host = `https://ads-${options.account}.adhese.com`;\n\n const payload = {\n slots: options.slots.map(slot => ({\n slotname: generateName(options.location, slot.format, slot.slot),\n parameters: slot.parameters\n ? parseParameters(toMap(slot.parameters))\n : undefined,\n })),\n parameters: options.parameters\n ? parseParameters(toMap(options.parameters))\n : undefined,\n };\n\n return fetch(`${new URL(host).href}json`, {\n method: 'POST',\n body: JSON.stringify(payload),\n headers: {\n // eslint-disable-next-line ts/naming-convention\n 'content-type': 'application/json',\n },\n signal,\n });\n}\n\nasync function fetchWithGet(\n options: FetchAdsOptionsGet,\n signal?: AbortSignal,\n): Promise<Response> {\n const host = `https://ads-${options.account}.adhese.com`;\n const slotNames = options.slots\n .map(slot => generateName(options.location, slot.format, slot.slot))\n .join('/sl');\n\n return fetch(`${host}/json/sl${slotNames}`, {\n method: 'GET',\n headers: {\n // eslint-disable-next-line ts/naming-convention\n 'content-type': 'application/json',\n },\n signal,\n });\n}\n\n/**\n * Fetch ads from the Adhese API. This function can be used on the server (Node.js)\n * to pre-fetch ad data for SSR/hydration.\n *\n * @example\n * ```typescript\n * import { fetchAds } from '@adhese/sdk/server';\n *\n * // In a Next.js Server Component or getServerSideProps\n * const ads = await fetchAds({\n * account: 'demo',\n * location: 'homepage',\n * slots: [{ format: 'leaderboard' }],\n * timeout: 2000, // Don't block page load for more than 2 seconds\n * });\n *\n * // Use ads[0].width and ads[0].height to reserve space and prevent layout shift\n * ```\n */\nexport async function fetchAds(\n options: FetchAdsOptions,\n): Promise<ReadonlyArray<AdheseAd>> {\n let signal: AbortSignal | undefined;\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n\n if (options.timeout && options.timeout > 0) {\n const controller = new AbortController();\n ({ signal } = controller);\n timeoutId = setTimeout(() => {\n controller.abort();\n }, options.timeout);\n }\n\n try {\n const response\n = options.requestType === 'GET'\n ? await fetchWithGet(options, signal)\n : await fetchWithPost(options, signal);\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch ads: ${response.status} ${response.statusText}`,\n );\n }\n\n const data = await response.json();\n return parseResponse(data);\n }\n catch (error) {\n if (error instanceof Error && error.name === 'AbortError') {\n return [];\n }\n throw error;\n }\n finally {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n }\n}\n"],"names":["generateName","parseParameters","parseResponse"],"mappings":";;;;;AAmDA,SAAS,MAAS,QAA2C;AAC3D,SAAO,IAAI,IAAI,OAAO,QAAQ,MAAM,CAAC;AACvC;AAEA,eAAe,cACb,SACA,QACmB;AACnB,QAAM,OAAO,eAAe,QAAQ,OAAO;AAE3C,QAAM,UAAU;AAAA,IACd,OAAO,QAAQ,MAAM,IAAI,CAAA,UAAS;AAAA,MAChC,UAAUA,UAAAA,aAAa,QAAQ,UAAU,KAAK,QAAQ,KAAK,IAAI;AAAA,MAC/D,YAAY,KAAK,aACbC,iBAAAA,gBAAgB,MAAM,KAAK,UAAU,CAAC,IACtC;AAAA,IAAA,EACJ;AAAA,IACF,YAAY,QAAQ,aAChBA,iBAAAA,gBAAgB,MAAM,QAAQ,UAAU,CAAC,IACzC;AAAA,EAAA;AAGN,SAAO,MAAM,GAAG,IAAI,IAAI,IAAI,EAAE,IAAI,QAAQ;AAAA,IACxC,QAAQ;AAAA,IACR,MAAM,KAAK,UAAU,OAAO;AAAA,IAC5B,SAAS;AAAA;AAAA,MAEP,gBAAgB;AAAA,IAAA;AAAA,IAElB;AAAA,EAAA,CACD;AACH;AAEA,eAAe,aACb,SACA,QACmB;AACnB,QAAM,OAAO,eAAe,QAAQ,OAAO;AAC3C,QAAM,YAAY,QAAQ,MACvB,IAAI,UAAQD,uBAAa,QAAQ,UAAU,KAAK,QAAQ,KAAK,IAAI,CAAC,EAClE,KAAK,KAAK;AAEb,SAAO,MAAM,GAAG,IAAI,WAAW,SAAS,IAAI;AAAA,IAC1C,QAAQ;AAAA,IACR,SAAS;AAAA;AAAA,MAEP,gBAAgB;AAAA,IAAA;AAAA,IAElB;AAAA,EAAA,CACD;AACH;AAqBA,eAAsB,SACpB,SACkC;AAClC,MAAI;AACJ,MAAI;AAEJ,MAAI,QAAQ,WAAW,QAAQ,UAAU,GAAG;AAC1C,UAAM,aAAa,IAAI,gBAAA;AACvB,KAAC,EAAE,WAAW;AACd,gBAAY,WAAW,MAAM;AAC3B,iBAAW,MAAA;AAAA,IACb,GAAG,QAAQ,OAAO;AAAA,EACpB;AAEA,MAAI;AACF,UAAM,WACF,QAAQ,gBAAgB,QACtB,MAAM,aAAa,SAAS,MAAM,IAClC,MAAM,cAAc,SAAS,MAAM;AAEzC,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI;AAAA,QACR,wBAAwB,SAAS,MAAM,IAAI,SAAS,UAAU;AAAA,MAAA;AAAA,IAElE;AAEA,UAAM,OAAO,MAAM,SAAS,KAAA;AAC5B,WAAOE,kBAAAA,cAAc,IAAI;AAAA,EAC3B,SACO,OAAO;AACZ,QAAI,iBAAiB,SAAS,MAAM,SAAS,cAAc;AACzD,aAAO,CAAA;AAAA,IACT;AACA,UAAM;AAAA,EACR,UAAA;AAEE,QAAI,WAAW;AACb,mBAAa,SAAS;AAAA,IACxB;AAAA,EACF;AACF;;"}
1
+ {"version":3,"file":"server.cjs","sources":["../../src/server.ts"],"sourcesContent":["import { generateName } from '@adhese/sdk-shared';\nimport { type AdheseAd, parseResponse } from './requestAds/requestAds.schema';\nimport { parseParameters } from './requestAds/requestAds.utils';\n\nexport type FetchAdsSlot = {\n format: string;\n slot?: string;\n parameters?: Record<string, string | ReadonlyArray<string>>;\n};\n\ntype FetchAdsOptionsBase = {\n /**\n * The account name for the Adhese API\n */\n account: string;\n /**\n * The location/page identifier\n */\n location: string;\n /**\n * Array of slot configurations to fetch ads for\n */\n slots: ReadonlyArray<FetchAdsSlot>;\n /**\n * Request timeout in milliseconds. If the request takes longer than this,\n * an empty array is returned to prevent blocking page load.\n * Set to 0 or undefined for no timeout.\n */\n timeout?: number;\n};\n\ntype FetchAdsOptionsPost = FetchAdsOptionsBase & {\n /**\n * Use POST request (default). Supports global parameters.\n */\n requestType?: 'POST';\n /**\n * Global parameters to send with the request. Only available with POST.\n */\n parameters?: Record<string, string | ReadonlyArray<string>>;\n};\n\ntype FetchAdsOptionsGet = FetchAdsOptionsBase & {\n /**\n * Use GET request. More limited - does not support global parameters.\n */\n requestType: 'GET';\n};\n\nexport type FetchAdsOptions = FetchAdsOptionsPost | FetchAdsOptionsGet;\n\nfunction toMap<T>(record: Record<string, T>): Map<string, T> {\n return new Map(Object.entries(record));\n}\n\nasync function fetchWithPost(\n options: FetchAdsOptionsPost,\n signal?: AbortSignal,\n): Promise<Response> {\n const host = `https://${options.account}.ads.adhese.eu`;\n\n const payload = {\n slots: options.slots.map(slot => ({\n slotname: generateName(options.location, slot.format, slot.slot),\n parameters: slot.parameters\n ? parseParameters(toMap(slot.parameters))\n : undefined,\n })),\n parameters: options.parameters\n ? parseParameters(toMap(options.parameters))\n : undefined,\n };\n\n return fetch(`${new URL(host).href}json`, {\n method: 'POST',\n body: JSON.stringify(payload),\n headers: {\n // eslint-disable-next-line ts/naming-convention\n 'content-type': 'application/json',\n },\n signal,\n });\n}\n\nasync function fetchWithGet(\n options: FetchAdsOptionsGet,\n signal?: AbortSignal,\n): Promise<Response> {\n const host = `https://${options.account}.ads.adhese.eu`;\n const slotNames = options.slots\n .map(slot => generateName(options.location, slot.format, slot.slot))\n .join('/sl');\n\n return fetch(`${host}/json/sl${slotNames}`, {\n method: 'GET',\n headers: {\n // eslint-disable-next-line ts/naming-convention\n 'content-type': 'application/json',\n },\n signal,\n });\n}\n\n/**\n * Fetch ads from the Adhese API. This function can be used on the server (Node.js)\n * to pre-fetch ad data for SSR/hydration.\n *\n * @example\n * ```typescript\n * import { fetchAds } from '@adhese/sdk/server';\n *\n * // In a Next.js Server Component or getServerSideProps\n * const ads = await fetchAds({\n * account: 'demo',\n * location: 'homepage',\n * slots: [{ format: 'leaderboard' }],\n * timeout: 2000, // Don't block page load for more than 2 seconds\n * });\n *\n * // Use ads[0].width and ads[0].height to reserve space and prevent layout shift\n * ```\n */\nexport async function fetchAds(\n options: FetchAdsOptions,\n): Promise<ReadonlyArray<AdheseAd>> {\n let signal: AbortSignal | undefined;\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n\n if (options.timeout && options.timeout > 0) {\n const controller = new AbortController();\n ({ signal } = controller);\n timeoutId = setTimeout(() => {\n controller.abort();\n }, options.timeout);\n }\n\n try {\n const response\n = options.requestType === 'GET'\n ? await fetchWithGet(options, signal)\n : await fetchWithPost(options, signal);\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch ads: ${response.status} ${response.statusText}`,\n );\n }\n\n const data = await response.json();\n return parseResponse(data);\n }\n catch (error) {\n if (error instanceof Error && error.name === 'AbortError') {\n return [];\n }\n throw error;\n }\n finally {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n }\n}\n"],"names":["generateName","parseParameters","parseResponse"],"mappings":";;;;;AAmDA,SAAS,MAAS,QAA2C;AAC3D,SAAO,IAAI,IAAI,OAAO,QAAQ,MAAM,CAAC;AACvC;AAEA,eAAe,cACb,SACA,QACmB;AACnB,QAAM,OAAO,WAAW,QAAQ,OAAO;AAEvC,QAAM,UAAU;AAAA,IACd,OAAO,QAAQ,MAAM,IAAI,CAAA,UAAS;AAAA,MAChC,UAAUA,UAAAA,aAAa,QAAQ,UAAU,KAAK,QAAQ,KAAK,IAAI;AAAA,MAC/D,YAAY,KAAK,aACbC,iBAAAA,gBAAgB,MAAM,KAAK,UAAU,CAAC,IACtC;AAAA,IAAA,EACJ;AAAA,IACF,YAAY,QAAQ,aAChBA,iBAAAA,gBAAgB,MAAM,QAAQ,UAAU,CAAC,IACzC;AAAA,EAAA;AAGN,SAAO,MAAM,GAAG,IAAI,IAAI,IAAI,EAAE,IAAI,QAAQ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@ -12,9 +12,9 @@ function createAdhese(options) {
12
12
  return scope.run(() => {
13
13
  var _a, _b, _c;
14
14
  const mergedOptions = {
15
- host: `https://ads-${options.account}.adhese.com`,
16
- poolHost: `https://pool-${options.account}.adhese.com`,
17
- previewHost: `https://${options.account}-preview.adhese.org`,
15
+ host: `https://${options.account}.ads.adhese.eu`,
16
+ poolHost: `https://${options.account}.pool.adhese.eu`,
17
+ previewHost: `https://${options.account}.preview.adhese.eu`,
18
18
  location: "homepage",
19
19
  requestType: "POST",
20
20
  debug: false,
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","sources":["../src/main.ts"],"sourcesContent":["import type {\n Adhese,\n AdheseContextStateWithPlugins,\n AdheseOptions,\n AdhesePlugin,\n MergedOptions,\n} from './main.types';\nimport type { AdheseSlot, AdheseSlotOptions } from './slot/slot.types';\nimport {\n awaitTimeout,\n createEventManager,\n effectScope,\n omit,\n reactive,\n watch,\n} from '@adhese/sdk-shared';\nimport { version } from '../package.json';\nimport { useConsent } from './consent/consent';\nimport { createGlobalHooks } from './hooks';\nimport { logger } from './logger/logger';\nimport {\n useMainDebugMode,\n useMainParameters,\n useMainQueryDetector,\n} from './main.composables';\nimport { fetchAllUnrenderedSlots } from './main.utils';\nimport { useQueryDetector } from './queryDetector/queryDetector';\nimport { createSlotManager } from './slotManager/slotManager';\n\n/**\n * Creates an Adhese instance. This instance is your main entry point to the Adhese API.\n *\n * @param options {AdheseOptions} The options to create the Adhese instance with. See the {@link AdheseOptions} type for more information.\n *\n * @return Adhese The Adhese instance.\n */\nexport function createAdhese<T extends ReadonlyArray<AdhesePlugin>>(\n options: AdheseOptions<T>,\n): Adhese<T> {\n const scope = effectScope();\n\n return scope.run(() => {\n const mergedOptions: MergedOptions = {\n host: `https://ads-${options.account}.adhese.com`,\n poolHost: `https://pool-${options.account}.adhese.com`,\n previewHost: `https://${options.account}-preview.adhese.org`,\n location: 'homepage',\n requestType: 'POST',\n debug: false,\n initialSlots: [],\n findDomSlotsOnLoad: false,\n consent: false,\n logReferrer: true,\n logUrl: true,\n eagerRendering: false,\n viewabilityTracking: true,\n refreshOnResize: true,\n ...options,\n };\n\n import('./requestAds/requestAds.schema').catch(logger.error);\n\n const hooks = createGlobalHooks();\n\n const context = reactive<AdheseContextStateWithPlugins<T>>({\n location: mergedOptions.location,\n consent: mergedOptions.consent,\n debug: mergedOptions.debug,\n options: mergedOptions,\n logger,\n isDisposed: false,\n parameters: new Map(),\n events: createEventManager(),\n slots: new Map(),\n device: 'unknown',\n hooks,\n plugins: {},\n dispose,\n findDomSlots,\n getAll,\n get,\n addSlot,\n });\n\n for (const [index, plugin] of options.plugins?.entries() ?? []) {\n const data = plugin(context, {\n index,\n version,\n hooks,\n });\n\n const name = data.name as keyof typeof context.plugins;\n context.plugins[name] = omit(data, [\n 'name',\n ]) as (typeof context.plugins)[typeof name];\n }\n\n watch(\n () => context.location,\n (newLocation) => {\n context.events?.locationChange.dispatch(newLocation);\n },\n );\n\n useMainParameters(context, mergedOptions);\n\n const slotManager = createSlotManager({\n initialSlots: mergedOptions.initialSlots,\n context,\n });\n\n function getAll(): ReadonlyArray<AdheseSlot> {\n return slotManager.getAll() ?? [];\n }\n context.getAll = getAll;\n\n function get(name: string): AdheseSlot | undefined {\n return slotManager.get(name);\n }\n context.get = get;\n\n function addSlot(slotOptions: AdheseSlotOptions): Readonly<AdheseSlot> {\n return slotManager.add(slotOptions);\n }\n context.addSlot = addSlot;\n\n async function findDomSlots(): Promise<ReadonlyArray<AdheseSlot>> {\n const domSlots = ((await slotManager.findDomSlots()) ?? []).filter(\n slot => !slot.lazyLoading,\n );\n\n if (domSlots.length <= 0)\n return [];\n\n await fetchAllUnrenderedSlots(context.getAll());\n\n return domSlots;\n }\n context.findDomSlots = findDomSlots;\n\n useMainDebugMode(context);\n if (mergedOptions.refreshOnResize) {\n useMainQueryDetector(mergedOptions, context);\n }\n else {\n const [device] = useQueryDetector(context, mergedOptions.queries);\n context.device = device.value;\n context.parameters?.set('dt', device.value);\n context.parameters?.set('br', device.value);\n }\n\n useConsent(context);\n\n function dispose(): void {\n context.isDisposed = true;\n\n slotManager.dispose();\n context.parameters?.clear();\n context.events?.dispose();\n\n hooks.runOnDispose();\n hooks.clearAll();\n\n scope.stop();\n }\n context.dispose = dispose;\n\n hooks.onInit(async () => {\n await awaitTimeout(0);\n\n if (mergedOptions.findDomSlotsOnLoad)\n await context?.findDomSlots();\n\n logger.debug('Created Adhese SDK instance', {\n mergedOptions,\n });\n\n if (!scope.active)\n dispose();\n });\n\n hooks.runOnInit();\n\n return context as Adhese<T>;\n })!;\n}\n"],"names":["_a","_b"],"mappings":";;;;;;;;;AAoCO,SAAS,aACd,SACW;AACX,QAAM,QAAQ,YAAA;AAEd,SAAO,MAAM,IAAI,MAAM;;AACrB,UAAM,gBAA+B;AAAA,MACnC,MAAM,eAAe,QAAQ,OAAO;AAAA,MACpC,UAAU,gBAAgB,QAAQ,OAAO;AAAA,MACzC,aAAa,WAAW,QAAQ,OAAO;AAAA,MACvC,UAAU;AAAA,MACV,aAAa;AAAA,MACb,OAAO;AAAA,MACP,cAAc,CAAA;AAAA,MACd,oBAAoB;AAAA,MACpB,SAAS;AAAA,MACT,aAAa;AAAA,MACb,QAAQ;AAAA,MACR,gBAAgB;AAAA,MAChB,qBAAqB;AAAA,MACrB,iBAAiB;AAAA,MACjB,GAAG;AAAA,IAAA;AAGL,WAAO,mCAAgC,EAAE,MAAM,OAAO,KAAK;AAE3D,UAAM,QAAQ,kBAAA;AAEd,UAAM,UAAU,SAA2C;AAAA,MACzD,UAAU,cAAc;AAAA,MACxB,SAAS,cAAc;AAAA,MACvB,OAAO,cAAc;AAAA,MACrB,SAAS;AAAA,MACT;AAAA,MACA,YAAY;AAAA,MACZ,gCAAgB,IAAA;AAAA,MAChB,QAAQ,mBAAA;AAAA,MACR,2BAAW,IAAA;AAAA,MACX,QAAQ;AAAA,MACR;AAAA,MACA,SAAS,CAAA;AAAA,MACT;AAAA,MAC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AAO;AACxB,oBAAQ,eAAR,mBAAoB,IAAI,MAAM,OAAO;AACrC,oBAAQ,eAAR,mBAAoB,IAAI,MAAM,OAAO;AAAA,IACvC;AAEA,eAAW,OAAO;AAElB,aAAS,UAAgB;;AACvB,cAAQ,aAAa;AAErB,kBAAY,QAAA;AACZ,OAAAA,MAAA,QAAQ,eAAR,gBAAAA,IAAoB;AACpB,OAAAC,MAAA,QAAQ,WAAR,gBAAAA,IAAgB;AAEhB,YAAM,aAAA;AACN,YAAM,SAAA;AAEN,YAAM,KAAA;AAAA,IACR;AACA,YAAQ,UAAU;AAElB,UAAM,OAAO,YAAY;AACvB,YAAM,aAAa,CAAC;AAEpB,UAAI,cAAc;AAChB,eAAM,mCAAS;AAEjB,aAAO,MAAM,+BAA+B;AAAA,QAC1C;AAAA,MAAA,CACD;AAED,UAAI,CAAC,MAAM;AACT,gBAAA;AAAA,IACJ,CAAC;AAED,UAAM,UAAA;AAEN,WAAO;AAAA,EACT,CAAC;AACH;"}
1
+ {"version":3,"file":"main.js","sources":["../src/main.ts"],"sourcesContent":["import type {\n Adhese,\n AdheseContextStateWithPlugins,\n AdheseOptions,\n AdhesePlugin,\n MergedOptions,\n} from './main.types';\nimport type { AdheseSlot, AdheseSlotOptions } from './slot/slot.types';\nimport {\n awaitTimeout,\n createEventManager,\n effectScope,\n omit,\n reactive,\n watch,\n} from '@adhese/sdk-shared';\nimport { version } from '../package.json';\nimport { useConsent } from './consent/consent';\nimport { createGlobalHooks } from './hooks';\nimport { logger } from './logger/logger';\nimport {\n useMainDebugMode,\n useMainParameters,\n useMainQueryDetector,\n} from './main.composables';\nimport { fetchAllUnrenderedSlots } from './main.utils';\nimport { useQueryDetector } from './queryDetector/queryDetector';\nimport { createSlotManager } from './slotManager/slotManager';\n\n/**\n * Creates an Adhese instance. This instance is your main entry point to the Adhese API.\n *\n * @param options {AdheseOptions} The options to create the Adhese instance with. See the {@link AdheseOptions} type for more information.\n *\n * @return Adhese The Adhese instance.\n */\nexport function createAdhese<T extends ReadonlyArray<AdhesePlugin>>(\n options: AdheseOptions<T>,\n): Adhese<T> {\n const scope = effectScope();\n\n return scope.run(() => {\n const mergedOptions: MergedOptions = {\n host: `https://${options.account}.ads.adhese.eu`,\n poolHost: `https://${options.account}.pool.adhese.eu`,\n previewHost: `https://${options.account}.preview.adhese.eu`,\n location: 'homepage',\n requestType: 'POST',\n debug: false,\n initialSlots: [],\n findDomSlotsOnLoad: false,\n consent: false,\n logReferrer: true,\n logUrl: true,\n eagerRendering: false,\n viewabilityTracking: true,\n refreshOnResize: true,\n ...options,\n };\n\n import('./requestAds/requestAds.schema').catch(logger.error);\n\n const hooks = createGlobalHooks();\n\n const context = reactive<AdheseContextStateWithPlugins<T>>({\n location: mergedOptions.location,\n consent: mergedOptions.consent,\n debug: mergedOptions.debug,\n options: mergedOptions,\n logger,\n isDisposed: false,\n parameters: new Map(),\n events: createEventManager(),\n slots: new Map(),\n device: 'unknown',\n hooks,\n plugins: {},\n dispose,\n findDomSlots,\n getAll,\n get,\n addSlot,\n });\n\n for (const [index, plugin] of options.plugins?.entries() ?? []) {\n const data = plugin(context, {\n index,\n version,\n hooks,\n });\n\n const name = data.name as keyof typeof context.plugins;\n context.plugins[name] = omit(data, [\n 'name',\n ]) as (typeof context.plugins)[typeof name];\n }\n\n watch(\n () => context.location,\n (newLocation) => {\n context.events?.locationChange.dispatch(newLocation);\n },\n );\n\n useMainParameters(context, mergedOptions);\n\n const slotManager = createSlotManager({\n initialSlots: mergedOptions.initialSlots,\n context,\n });\n\n function getAll(): ReadonlyArray<AdheseSlot> {\n return slotManager.getAll() ?? [];\n }\n context.getAll = getAll;\n\n function get(name: string): AdheseSlot | undefined {\n return slotManager.get(name);\n }\n context.get = get;\n\n function addSlot(slotOptions: AdheseSlotOptions): Readonly<AdheseSlot> {\n return slotManager.add(slotOptions);\n }\n context.addSlot = addSlot;\n\n async function findDomSlots(): Promise<ReadonlyArray<AdheseSlot>> {\n const domSlots = ((await slotManager.findDomSlots()) ?? []).filter(\n slot => !slot.lazyLoading,\n );\n\n if (domSlots.length <= 0)\n return [];\n\n await fetchAllUnrenderedSlots(context.getAll());\n\n return domSlots;\n }\n context.findDomSlots = findDomSlots;\n\n useMainDebugMode(context);\n if (mergedOptions.refreshOnResize) {\n useMainQueryDetector(mergedOptions, context);\n }\n else {\n const [device] = useQueryDetector(context, mergedOptions.queries);\n context.device = device.value;\n context.parameters?.set('dt', device.value);\n context.parameters?.set('br', device.value);\n }\n\n useConsent(context);\n\n function dispose(): void {\n context.isDisposed = true;\n\n slotManager.dispose();\n context.parameters?.clear();\n context.events?.dispose();\n\n hooks.runOnDispose();\n hooks.clearAll();\n\n scope.stop();\n }\n context.dispose = dispose;\n\n hooks.onInit(async () => {\n await awaitTimeout(0);\n\n if (mergedOptions.findDomSlotsOnLoad)\n await context?.findDomSlots();\n\n logger.debug('Created Adhese SDK instance', {\n mergedOptions,\n });\n\n if (!scope.active)\n dispose();\n });\n\n hooks.runOnInit();\n\n return context as Adhese<T>;\n })!;\n}\n"],"names":["_a","_b"],"mappings":";;;;;;;;;AAoCO,SAAS,aACd,SACW;AACX,QAAM,QAAQ,YAAA;AAEd,SAAO,MAAM,IAAI,MAAM;;AACrB,UAAM,gBAA+B;AAAA,MACnC,MAAM,WAAW,QAAQ,OAAO;AAAA,MAChC,UAAU,WAAW,QAAQ,OAAO;AAAA,MACpC,aAAa,WAAW,QAAQ,OAAO;AAAA,MACvC,UAAU;AAAA,MACV,aAAa;AAAA,MACb,OAAO;AAAA,MACP,cAAc,CAAA;AAAA,MACd,oBAAoB;AAAA,MACpB,SAAS;AAAA,MACT,aAAa;AAAA,MACb,QAAQ;AAAA,MACR,gBAAgB;AAAA,MAChB,qBAAqB;AAAA,MACrB,iBAAiB;AAAA,MACjB,GAAG;AAAA,IAAA;AAGL,WAAO,mCAAgC,EAAE,MAAM,OAAO,KAAK;AAE3D,UAAM,QAAQ,kBAAA;AAEd,UAAM,UAAU,SAA2C;AAAA,MACzD,U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O,CAAA;AAET,YAAM,wBAAwB,QAAQ,QAAQ;AAE9C,aAAO;AAAA,IACT;AACA,YAAQ,eAAe;AAEvB,qBAAiB,OAAO;AACxB,QAAI,cAAc,iBAAiB;AACjC,2BAAqB,eAAe,OAAO;AAAA,IAC7C,OACK;AACH,YAAM,CAAC,MAAM,IAAI,iBAAiB,SAAS,cAAc,OAAO;AAChE,cAAQ,SAAS,OAAO;AACxB,oBAAQ,eAAR,mBAAoB,IAAI,MAAM,OAAO;AACrC,oBAAQ,eAAR,mBAAoB,IAAI,MAAM,OAAO;AAAA,IACvC;AAEA,eAAW,OAAO;AAElB,aAAS,UAAgB;;AACvB,cAAQ,aAAa;AAErB,kBAAY,QAAA;AACZ,OAAAA,MAAA,QAAQ,eAAR,gBAAAA,IAAoB;AACpB,OAAAC,MAAA,QAAQ,WAAR,gBAAAA,IAAgB;AAEhB,YAAM,aAAA;AACN,YAAM,SAAA;AAEN,YAAM,KAAA;AAAA,IACR;AACA,YAAQ,UAAU;AAElB,UAAM,OAAO,YAAY;AACvB,YAAM,aAAa,CAAC;AAEpB,UAAI,cAAc;AAChB,eAAM,mCAAS;AAEjB,aAAO,MAAM,+BAA+B;AAAA,QAC1C;AAAA,MAAA,CACD;AAED,UAAI,CAAC,MAAM;AACT,gBAAA;AAAA,IACJ,CAAC;AAED,UAAM,UAAA;AAEN,WAAO;AAAA,EACT,CAAC;AACH;"}
package/dist/server.js CHANGED
@@ -5,7 +5,7 @@ function toMap(record) {
5
5
  return new Map(Object.entries(record));
6
6
  }
7
7
  async function fetchWithPost(options, signal) {
8
- const host = `https://ads-${options.account}.adhese.com`;
8
+ const host = `https://${options.account}.ads.adhese.eu`;
9
9
  const payload = {
10
10
  slots: options.slots.map((slot) => ({
11
11
  slotname: generateName(options.location, slot.format, slot.slot),
@@ -24,7 +24,7 @@ async function fetchWithPost(options, signal) {
24
24
  });
25
25
  }
26
26
  async function fetchWithGet(options, signal) {
27
- const host = `https://ads-${options.account}.adhese.com`;
27
+ const host = `https://${options.account}.ads.adhese.eu`;
28
28
  const slotNames = options.slots.map((slot) => generateName(options.location, slot.format, slot.slot)).join("/sl");
29
29
  return fetch(`${host}/json/sl${slotNames}`, {
30
30
  method: "GET",
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sources":["../src/server.ts"],"sourcesContent":["import { generateName } from '@adhese/sdk-shared';\nimport { type AdheseAd, parseResponse } from './requestAds/requestAds.schema';\nimport { parseParameters } from './requestAds/requestAds.utils';\n\nexport type FetchAdsSlot = {\n format: string;\n slot?: string;\n parameters?: Record<string, string | ReadonlyArray<string>>;\n};\n\ntype FetchAdsOptionsBase = {\n /**\n * The account name for the Adhese API\n */\n account: string;\n /**\n * The location/page identifier\n */\n location: string;\n /**\n * Array of slot configurations to fetch ads for\n */\n slots: ReadonlyArray<FetchAdsSlot>;\n /**\n * Request timeout in milliseconds. If the request takes longer than this,\n * an empty array is returned to prevent blocking page load.\n * Set to 0 or undefined for no timeout.\n */\n timeout?: number;\n};\n\ntype FetchAdsOptionsPost = FetchAdsOptionsBase & {\n /**\n * Use POST request (default). Supports global parameters.\n */\n requestType?: 'POST';\n /**\n * Global parameters to send with the request. Only available with POST.\n */\n parameters?: Record<string, string | ReadonlyArray<string>>;\n};\n\ntype FetchAdsOptionsGet = FetchAdsOptionsBase & {\n /**\n * Use GET request. More limited - does not support global parameters.\n */\n requestType: 'GET';\n};\n\nexport type FetchAdsOptions = FetchAdsOptionsPost | FetchAdsOptionsGet;\n\nfunction toMap<T>(record: Record<string, T>): Map<string, T> {\n return new Map(Object.entries(record));\n}\n\nasync function fetchWithPost(\n options: FetchAdsOptionsPost,\n signal?: AbortSignal,\n): Promise<Response> {\n const host = `https://ads-${options.account}.adhese.com`;\n\n const payload = {\n slots: options.slots.map(slot => ({\n slotname: generateName(options.location, slot.format, slot.slot),\n parameters: slot.parameters\n ? parseParameters(toMap(slot.parameters))\n : undefined,\n })),\n parameters: options.parameters\n ? parseParameters(toMap(options.parameters))\n : undefined,\n };\n\n return fetch(`${new URL(host).href}json`, {\n method: 'POST',\n body: JSON.stringify(payload),\n headers: {\n // eslint-disable-next-line ts/naming-convention\n 'content-type': 'application/json',\n },\n signal,\n });\n}\n\nasync function fetchWithGet(\n options: FetchAdsOptionsGet,\n signal?: AbortSignal,\n): Promise<Response> {\n const host = `https://ads-${options.account}.adhese.com`;\n const slotNames = options.slots\n .map(slot => generateName(options.location, slot.format, slot.slot))\n .join('/sl');\n\n return fetch(`${host}/json/sl${slotNames}`, {\n method: 'GET',\n headers: {\n // eslint-disable-next-line ts/naming-convention\n 'content-type': 'application/json',\n },\n signal,\n });\n}\n\n/**\n * Fetch ads from the Adhese API. This function can be used on the server (Node.js)\n * to pre-fetch ad data for SSR/hydration.\n *\n * @example\n * ```typescript\n * import { fetchAds } from '@adhese/sdk/server';\n *\n * // In a Next.js Server Component or getServerSideProps\n * const ads = await fetchAds({\n * account: 'demo',\n * location: 'homepage',\n * slots: [{ format: 'leaderboard' }],\n * timeout: 2000, // Don't block page load for more than 2 seconds\n * });\n *\n * // Use ads[0].width and ads[0].height to reserve space and prevent layout shift\n * ```\n */\nexport async function fetchAds(\n options: FetchAdsOptions,\n): Promise<ReadonlyArray<AdheseAd>> {\n let signal: AbortSignal | undefined;\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n\n if (options.timeout && options.timeout > 0) {\n const controller = new AbortController();\n ({ signal } = controller);\n timeoutId = setTimeout(() => {\n controller.abort();\n }, options.timeout);\n }\n\n try {\n const response\n = options.requestType === 'GET'\n ? await fetchWithGet(options, signal)\n : await fetchWithPost(options, signal);\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch ads: ${response.status} ${response.statusText}`,\n );\n }\n\n const data = await response.json();\n return parseResponse(data);\n }\n catch (error) {\n if (error instanceof Error && error.name === 'AbortError') {\n return [];\n }\n throw error;\n }\n finally {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n }\n}\n"],"names":[],"mappings":";;;AAmDA,SAAS,MAAS,QAA2C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QAAQ,gBAAgB,QACtB,MAAM,aAAa,SAAS,MAAM,IAClC,MAAM,cAAc,SAAS,MAAM;AAEzC,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI;AAAA,QACR,wBAAwB,SAAS,MAAM,IAAI,SAAS,UAAU;AAAA,MAAA;AAAA,IAElE;AAEA,UAAM,OAAO,MAAM,SAAS,KAAA;AAC5B,WAAO,cAAc,IAAI;AAAA,EAC3B,SACO,OAAO;AACZ,QAAI,iBAAiB,SAAS,MAAM,SAAS,cAAc;AACzD,aAAO,CAAA;AAAA,IACT;AACA,UAAM;AAAA,EACR,UAAA;AAEE,QAAI,WAAW;AACb,mBAAa,SAAS;AAAA,IACxB;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"server.js","sources":["../src/server.ts"],"sourcesContent":["import { generateName } from '@adhese/sdk-shared';\nimport { type AdheseAd, parseResponse } from './requestAds/requestAds.schema';\nimport { parseParameters } from './requestAds/requestAds.utils';\n\nexport type FetchAdsSlot = {\n format: string;\n slot?: string;\n parameters?: Record<string, string | ReadonlyArray<string>>;\n};\n\ntype FetchAdsOptionsBase = {\n /**\n * The account name for the Adhese API\n */\n account: string;\n /**\n * The location/page identifier\n */\n location: string;\n /**\n * Array of slot configurations to fetch ads for\n */\n slots: ReadonlyArray<FetchAdsSlot>;\n /**\n * Request timeout in milliseconds. If the request takes longer than this,\n * an empty array is returned to prevent blocking page load.\n * Set to 0 or undefined for no timeout.\n */\n timeout?: number;\n};\n\ntype FetchAdsOptionsPost = FetchAdsOptionsBase & {\n /**\n * Use POST request (default). Supports global parameters.\n */\n requestType?: 'POST';\n /**\n * Global parameters to send with the request. Only available with POST.\n */\n parameters?: Record<string, string | ReadonlyArray<string>>;\n};\n\ntype FetchAdsOptionsGet = FetchAdsOptionsBase & {\n /**\n * Use GET request. More limited - does not support global parameters.\n */\n requestType: 'GET';\n};\n\nexport type FetchAdsOptions = FetchAdsOptionsPost | FetchAdsOptionsGet;\n\nfunction toMap<T>(record: Record<string, T>): Map<string, T> {\n return new Map(Object.entries(record));\n}\n\nasync function fetchWithPost(\n options: FetchAdsOptionsPost,\n signal?: AbortSignal,\n): Promise<Response> {\n const host = `https://${options.account}.ads.adhese.eu`;\n\n const payload = {\n slots: options.slots.map(slot => ({\n slotname: generateName(options.location, slot.format, slot.slot),\n parameters: slot.parameters\n ? parseParameters(toMap(slot.parameters))\n : undefined,\n })),\n parameters: options.parameters\n ? parseParameters(toMap(options.parameters))\n : undefined,\n };\n\n return fetch(`${new URL(host).href}json`, {\n method: 'POST',\n body: JSON.stringify(payload),\n headers: {\n // eslint-disable-next-line ts/naming-convention\n 'content-type': 'application/json',\n },\n signal,\n });\n}\n\nasync function fetchWithGet(\n options: FetchAdsOptionsGet,\n signal?: AbortSignal,\n): Promise<Response> {\n const host = `https://${options.account}.ads.adhese.eu`;\n const slotNames = options.slots\n .map(slot => generateName(options.location, slot.format, slot.slot))\n .join('/sl');\n\n return fetch(`${host}/json/sl${slotNames}`, {\n method: 'GET',\n headers: {\n // eslint-disable-next-line ts/naming-convention\n 'content-type': 'application/json',\n },\n signal,\n });\n}\n\n/**\n * Fetch ads from the Adhese API. This function can be used on the server (Node.js)\n * to pre-fetch ad data for SSR/hydration.\n *\n * @example\n * ```typescript\n * import { fetchAds } from '@adhese/sdk/server';\n *\n * // In a Next.js Server Component or getServerSideProps\n * const ads = await fetchAds({\n * account: 'demo',\n * location: 'homepage',\n * slots: [{ format: 'leaderboard' }],\n * timeout: 2000, // Don't block page load for more than 2 seconds\n * });\n *\n * // Use ads[0].width and ads[0].height to reserve space and prevent layout shift\n * ```\n */\nexport async function fetchAds(\n options: FetchAdsOptions,\n): Promise<ReadonlyArray<AdheseAd>> {\n let signal: AbortSignal | undefined;\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n\n if (options.timeout && options.timeout > 0) {\n const controller = new AbortController();\n ({ signal } = controller);\n timeoutId = setTimeout(() => {\n controller.abort();\n }, options.timeout);\n }\n\n try {\n const response\n = options.requestType === 'GET'\n ? await fetchWithGet(options, signal)\n : await fetchWithPost(options, signal);\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch ads: ${response.status} ${response.statusText}`,\n );\n }\n\n const data = await response.json();\n return parseResponse(data);\n }\n catch (error) {\n if (error instanceof Error && error.name === 'AbortError') {\n return [];\n }\n throw error;\n }\n finally {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n }\n}\n"],"names":[],"mappings":";;;AAmDA,SAAS,MAAS,QAA2C;AAC3D,SAAO,IAAI,IAAI,OAAO,QAAQ,MAAM,CAAC;AACvC;AAEA,eAAe,cACb,SACA,QACmB;AACnB,QAAM,OAAO,WAAW,QAAQ,OAAO;AAEvC,QAAM,UAAU;AAAA,IACd,OAAO,QAAQ,MAAM,IAAI,CAAA,UAAS;AAAA,MAChC,UAAU,aAAa,QAAQ,UAAU,KAAK,QAAQ,KAAK,IAAI;AAAA,MAC/D,YAAY,KAAK,aACb,gBAAgB,MAAM,KAAK,UAAU,CAAC,IACtC;AAAA,IAAA,EACJ;AAAA,IACF,YAAY,QAAQ,aAChB,gBAAgB,MAAM,QAAQ,UAAU,CAAC,IACzC;AAAA,EAAA;AAGN,SAAO,MAAM,GAAG,IAAI,IAAI,IAAI,EAAE,IAAI,QAAQ;AAAA,IACxC,QAAQ;AAAA,IACR,MAAM,KAAK,UAAU,OAAO;AAAA,IAC5B,SAAS;AAAA;AAAA,MAEP,gBAAgB;AAAA,IAAA;AAAA,IAElB;AAAA,EAAA,CACD;AACH;AAEA,eAAe,aACb,SACA,QACmB;AACnB,QAAM,OAAO,WAAW,QAAQ,OAAO;AACvC,QAAM,YAAY,QAAQ,MACvB,IAAI,UAAQ,aAAa,QAAQ,UAAU,KAAK,QAAQ,KAAK,IAAI,CAAC,EAClE,KAAK,KAAK;AAEb,SAAO,MAAM,GAAG,IAAI,WAAW,SAAS,IAAI;AAAA,IAC1C,QAAQ;AAAA,IACR,SAAS;AAAA;AAAA,MAEP,gBAAgB;AAAA,IAAA;AAAA,IAElB;AAAA,EAAA,CACD;AACH;AAqBA,eAAsB,SACpB,SACkC;AAClC,MAAI;AACJ,MAAI;AAEJ,MAAI,QAAQ,WAAW,QAAQ,UAAU,GAAG;AAC1C,UAAM,aAAa,IAAI,gBAAA;AACvB,KAAC,EAAE,WAAW;AACd,gBAAY,WAAW,MAAM;AAC3B,iBAAW,MAAA;AAAA,IACb,GAAG,QAAQ,OAAO;AAAA,EACpB;AAEA,MAAI;AACF,UAAM,WACF,QAAQ,gBAAgB,QACtB,MAAM,aAAa,SAAS,MAAM,IAClC,MAAM,cAAc,SAAS,MAAM;AAEzC,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI;AAAA,QACR,wBAAwB,SAAS,MAAM,IAAI,SAAS,UAAU;AAAA,MAAA;AAAA,IAElE;AAEA,UAAM,OAAO,MAAM,SAAS,KAAA;AAC5B,WAAO,cAAc,IAAI;AAAA,EAC3B,SACO,OAAO;AACZ,QAAI,iBAAiB,SAAS,MAAM,SAAS,cAAc;AACzD,aAAO,CAAA;AAAA,IACT;AACA,UAAM;AAAA,EACR,UAAA;AAEE,QAAI,WAAW;AACb,mBAAa,SAAS;AAAA,IACxB;AAAA,EACF;AACF;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adhese/sdk",
3
3
  "type": "module",
4
- "version": "1.12.3",
4
+ "version": "1.13.0-nightly-20261002071913",
5
5
  "description": "Adhese SDK",
6
6
  "license": "GPL-3.0",
7
7
  "repository": {