@dropins/tools 1.4.0-alpha1 → 1.4.0-alpha2

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.
@@ -1,44 +1,91 @@
1
- interface AemAssetsParams {
2
- quality?: number;
3
- format?: string;
4
- crop?: {
5
- xOrigin?: number;
6
- yOrigin?: number;
7
- width?: number;
8
- height?: number;
9
- };
10
- size?: {
11
- width?: number;
12
- height?: number;
13
- };
1
+ import { ImageProps } from '../../components';
2
+
3
+ declare const AEM_ASSETS_FORMATS: readonly ["gif", "jpg", "jpeg", "png", "webp"];
4
+ declare const AEM_ASSETS_ALLOWED_ROTATIONS: readonly [90, 180, 270];
5
+ declare const AEM_ASSETS_ALLOWED_FLIPS: readonly ["h", "v", "hv"];
6
+ /** The allowed formats for the `AEM Assets` image optimization API. */
7
+ export type AemAssetsFormat = (typeof AEM_ASSETS_FORMATS)[number];
8
+ /** The allowed rotations for the `AEM Assets` image optimization API. */
9
+ export type AemAssetsRotation = (typeof AEM_ASSETS_ALLOWED_ROTATIONS)[number];
10
+ /** The allowed flips for the `AEM Assets` image optimization API. */
11
+ export type AemAssetsFlip = (typeof AEM_ASSETS_ALLOWED_FLIPS)[number];
12
+ /**
13
+ * Defines a crop region of an image.
14
+ * @example
15
+ * ```ts
16
+ * // Crop the image to a 80% width and height, starting at 10% from the top and left.
17
+ * const cropSettings: AemAssetsCropSettings = {
18
+ * xOrigin: 10,
19
+ * yOrigin: 10,
20
+ * width: 80,
21
+ * height: 80,
22
+ * };
23
+ */
24
+ export interface AemAssetsCropSettings {
25
+ /** The (relative) x origin of the crop (between 0 and 100) */
26
+ xOrigin?: number;
27
+ /** The (relative) y origin of the crop (between 0 and 100) */
28
+ yOrigin?: number;
29
+ /** The width of the crop (between 0 and 100) */
14
30
  width?: number;
31
+ /** The height of the crop (between 0 and 100) */
15
32
  height?: number;
16
- [key: string]: any;
17
33
  }
18
- interface AemAssetsImageConfig {
19
- wrapper?: HTMLElement;
34
+ /**
35
+ * The parameters accepted by the `AEM Assets` image optimization API.
36
+ * @see https://adobe-aem-assets-delivery-experimental.redoc.ly/
37
+ */
38
+ export interface AemAssetsParams {
39
+ format: AemAssetsFormat;
40
+ rotate?: AemAssetsRotation;
41
+ flip?: AemAssetsFlip;
42
+ crop?: AemAssetsCropSettings;
43
+ width?: number;
44
+ height?: number;
45
+ quality?: number;
46
+ attachment?: boolean;
47
+ sharpen?: boolean;
48
+ blur?: number;
49
+ dpr?: number;
50
+ smartCrop?: string;
51
+ [key: string]: unknown;
52
+ }
53
+ type WithRequired<T, K extends keyof T> = T & {
54
+ [P in K]-?: T[P];
55
+ };
56
+ /** The parameters to be applied to the asset (known width required when using a slot) */
57
+ export type AemAssetsImageSlotConfigParams = WithRequired<Partial<AemAssetsParams>, 'width'>;
58
+ /** The configuration for an image slot. */
59
+ export interface AemAssetsImageSlotConfig {
60
+ /** The alias (i.e. seoName) of the image */
20
61
  alias: string;
21
- params: AemAssetsParams;
22
- imageProps: {
62
+ /** The props to be applied to the underlying {@link Image} component */
63
+ imageProps: Partial<Omit<ImageProps, 'params' | 'width' | 'height'>> & {
23
64
  src: string;
24
- width?: number;
25
- height?: number;
26
- [key: string]: any;
27
65
  };
28
- src?: string;
66
+ /** The parameters to be applied to the asset (known width required when using a slot) */
67
+ params: AemAssetsImageSlotConfigParams;
68
+ /** The element that will contain the image in the slot */
69
+ wrapper?: HTMLElement;
29
70
  }
30
71
  interface RenderContext {
31
72
  replaceWith: (element: HTMLElement) => void;
32
73
  }
74
+ /** Returns whether AEM Assets is enabled in the Storefront. */
33
75
  export declare function isAemAssetsEnabled(): boolean;
34
- export declare function getDefaultAemAssetsOptimizationParams(): {
35
- quality: number;
36
- format: string;
37
- };
76
+ /** The default optimization parameters used globally, unless overriden (per use). */
77
+ export declare function getDefaultAemAssetsOptimizationParams(): AemAssetsParams;
78
+ /** Returns true if the given URL is an AEM Assets URL. */
38
79
  export declare function isAemAssetsUrl(url: string | URL): boolean;
39
- export declare function generateAemAssetsOptimizedUrl(url: string, alias: string, params?: AemAssetsParams): string;
40
- export declare function tryGenerateAemAssetsOptimizedUrl(url: string, alias: string, params?: AemAssetsParams): string;
41
- export declare function makeAemAssetsImageSlot(config: AemAssetsImageConfig): (ctx: RenderContext) => void;
42
- export declare function tryRenderAemAssetsImage(ctx: RenderContext, config: AemAssetsImageConfig): void;
80
+ /** Generates an optimized URL for AEM Assets. */
81
+ export declare function generateAemAssetsOptimizedUrl(assetUrl: string, alias: string, params?: Partial<AemAssetsParams>): string;
82
+ /**
83
+ * Tries to generate an optimized URL for AEM Assets. Returns the given
84
+ * url if AEM Assets is not enabled or is not an AEM Assets URL.
85
+ */
86
+ export declare function tryGenerateAemAssetsOptimizedUrl(assetUrl: string, alias: string, params?: Partial<AemAssetsParams>): string;
87
+ /** Creates a slot that renders an AEM Assets image. */
88
+ export declare function makeAemAssetsImageSlot(config: AemAssetsImageSlotConfig): (ctx: RenderContext) => void;
89
+ export declare function tryRenderAemAssetsImage(ctx: RenderContext, config: AemAssetsImageSlotConfig): void;
43
90
  export {};
44
91
  //# sourceMappingURL=assets.d.ts.map
@@ -1 +0,0 @@
1
- export * from '../../types/elsie/src/lib/aem/assets.test'
@@ -1,4 +0,0 @@
1
- /*! Copyright 2025 Adobe
2
- All Rights Reserved. */
3
- import{isAemAssetsEnabled as m,getDefaultAemAssetsOptimizationParams as n,isAemAssetsUrl as l,generateAemAssetsOptimizedUrl as o,tryGenerateAemAssetsOptimizedUrl as i,makeAemAssetsImageSlot as c,tryRenderAemAssetsImage as p}from"./assets.js";import{getConfigValue as r}from"./configs.js";import"../../chunks/Image.js";import"../../preact-jsx-runtime.js";import"../../chunks/icons/Add.js";import"../../i18n.js";import"../../chunks/cjs.js";import"../../chunks/vcomponent.js";import"../../chunks/image-params-keymap.js";import"../../signals.js";import"../../chunks/get-path-value.js";jest.mock("./configs",()=>({getConfigValue:jest.fn().mockImplementation(e=>{if(e==="commerce-assets-enabled")return!0})}));Object.defineProperty(window,"location",{value:{pathname:"/",origin:"https://example.com",protocol:"https:"}});describe("AEM Assets",()=>{beforeEach(()=>{jest.clearAllMocks()}),test("should be enabled",()=>{expect(m()).toBe(!0),r.mockReturnValueOnce("true"),expect(m()).toBe(!0)}),test("should be disabled",()=>{r.mockReturnValueOnce(!1),expect(m()).toBe(!1)}),test("should return default optimization params",()=>{const e=n();expect(e).toEqual({quality:80,format:"webp"})}),test("should return true if url is aem assets url",()=>{expect(l("https://example.com/adobe/assets/urn:aaid:aem:1234567890")).toBe(!0)}),test("should return false if url is not aem assets url",()=>{expect(l("https://example.com/image.jpg")).toBe(!1)}),test("should return true if url is aem assets url with protocol relative path",()=>{expect(l("//example.com/adobe/assets/urn:aaid:aem:1234567890")).toBe(!0)}),test("should generate aem assets optimized url",()=>{const t=o("https://example.com/adobe/assets/urn:aaid:aem:1234567890","test",{quality:80,format:"webp"});expect(t).toBe("https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80")}),test("should generate aem assets optimized url with default params",()=>{const a=o("https://example.com/adobe/assets/urn:aaid:aem:1234567890","test");expect(a).toBe("https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80")}),test("should generate aem assets optimized url with crop",()=>{const t=o("https://example.com/adobe/assets/urn:aaid:aem:1234567890","test",{quality:80,format:"webp",crop:{xOrigin:0,yOrigin:0}});expect(t).toBe("https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&crop=0p%2C0p%2C100p%2C100p")}),test("should generate aem assets optimized url with size",()=>{const t=o("https://example.com/adobe/assets/urn:aaid:aem:1234567890","test",{quality:80,format:"webp",size:{width:100,height:100}});expect(t).toBe("https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&size=100%2C100")}),test("should generate aem assets optimized url with width and height",()=>{const t=o("https://example.com/adobe/assets/urn:aaid:aem:1234567890","test",{quality:80,format:"webp",width:100,height:100});expect(t).toBe("https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&width=100&height=100")}),test("should try generate aem assets optimized url",()=>{const t=i("https://example.com/adobe/assets/urn:aaid:aem:1234567890","test",{quality:80,format:"webp",width:100,height:100});expect(t).toBe("https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&width=100&height=100")}),test("should try generate aem assets optimized url with default params",()=>{const a=i("https://example.com/adobe/assets/urn:aaid:aem:1234567890","test");expect(a).toBe("https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80")}),test("should try generate aem assets optimized url with crop",()=>{const t=i("https://example.com/adobe/assets/urn:aaid:aem:1234567890","test",{quality:80,format:"webp",crop:{xOrigin:0,yOrigin:0,width:100,height:100}});expect(t).toBe("https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&crop=0p%2C0p%2C100p%2C100p")}),test("should return original url if aem assets is disabled",()=>{r.mockReturnValueOnce(!1);const e="https://example.com/adobe/assets/urn:aaid:aem:1234567890",t=i(e,"test",{quality:80,format:"webp"});expect(t).toBe(e)}),test("should return original url if url is not aem assets url",()=>{const e="https://example.com/image.jpg",t=i(e,"test",{quality:80,format:"webp"});expect(t).toBe(e)}),test("should make aem assets image slot",()=>{const e=c({alias:"test",params:{},imageProps:{src:"https://example.com/adobe/assets/urn:aaid:aem:1234567890"}}),s=document.createElement("div");e({replaceWith:a=>{s.appendChild(a)}})}),test("should try render aem assets image",()=>{const e=document.createElement("div");p({replaceWith:t=>{e.appendChild(t)}},{alias:"test",params:{},imageProps:{src:"https://example.com/adobe/assets/urn:aaid:aem:1234567890"}})}),test("should render default image if aem assets is disabled",()=>{r.mockReturnValueOnce(!1);const e=document.createElement("div");p({replaceWith:t=>{e.appendChild(t)}},{alias:"test",params:{},imageProps:{src:"https://example.com/adobe/assets/urn:aaid:aem:1234567890"}})}),test("should render default image if url is not aem assets url",()=>{const e=document.createElement("div");p({replaceWith:t=>{e.appendChild(t)}},{alias:"test",params:{},imageProps:{src:"https://example.com/image.jpg"}})})});
4
- //# sourceMappingURL=assets.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assets.test.js","sources":["/@dropins/tools/src/lib/aem/assets.test.ts"],"sourcesContent":["import {\n isAemAssetsEnabled,\n getDefaultAemAssetsOptimizationParams,\n isAemAssetsUrl,\n generateAemAssetsOptimizedUrl,\n tryGenerateAemAssetsOptimizedUrl,\n makeAemAssetsImageSlot,\n tryRenderAemAssetsImage,\n} from './assets';\n\nimport { getConfigValue } from './configs';\n\n// Mock the config\njest.mock('./configs', () => ({\n getConfigValue: jest.fn().mockImplementation((key: string) => {\n if (key === 'commerce-assets-enabled') {\n return true;\n }\n return undefined;\n }),\n}));\n\n// Mock window.location\nObject.defineProperty(window, 'location', {\nvalue: {\n pathname: '/',\n origin: 'https://example.com',\n protocol: 'https:',\n},\n});\n\ndescribe('AEM Assets', () => {\n beforeEach(() => {\n jest.clearAllMocks();\n });\n\n test('should be enabled', () => {\n expect(isAemAssetsEnabled()).toBe(true);\n\n (getConfigValue as jest.Mock).mockReturnValueOnce('true');\n expect(isAemAssetsEnabled()).toBe(true);\n });\n\n test('should be disabled', () => {\n (getConfigValue as jest.Mock).mockReturnValueOnce(false);\n expect(isAemAssetsEnabled()).toBe(false);\n });\n\n test('should return default optimization params', () => {\n const params = getDefaultAemAssetsOptimizationParams();\n expect(params).toEqual({\n quality: 80,\n format: 'webp',\n });\n });\n\n test('should return true if url is aem assets url', () => {\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n expect(isAemAssetsUrl(url)).toBe(true);\n });\n\n test('should return false if url is not aem assets url', () => {\n const url = 'https://example.com/image.jpg';\n expect(isAemAssetsUrl(url)).toBe(false);\n });\n\n test('should return true if url is aem assets url with protocol relative path', () => {\n const url = '//example.com/adobe/assets/urn:aaid:aem:1234567890';\n expect(isAemAssetsUrl(url)).toBe(true);\n });\n\n test('should generate aem assets optimized url', () => {\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n const alias = 'test';\n const params = {\n quality: 80,\n format: 'webp',\n };\n const optimizedUrl = generateAemAssetsOptimizedUrl(url, alias, params);\n expect(optimizedUrl).toBe('https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80');\n });\n\n test('should generate aem assets optimized url with default params', () => {\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n const alias = 'test';\n const optimizedUrl = generateAemAssetsOptimizedUrl(url, alias);\n expect(optimizedUrl).toBe('https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80');\n });\n\n test('should generate aem assets optimized url with crop', () => {\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n const alias = 'test';\n const params = {\n quality: 80,\n format: 'webp',\n crop: {\n xOrigin: 0,\n yOrigin: 0,\n },\n };\n const optimizedUrl = generateAemAssetsOptimizedUrl(url, alias, params);\n expect(optimizedUrl).toBe('https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&crop=0p%2C0p%2C100p%2C100p');\n });\n\n test('should generate aem assets optimized url with size', () => {\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n const alias = 'test';\n const params = {\n quality: 80,\n format: 'webp',\n size: {\n width: 100,\n height: 100,\n },\n };\n const optimizedUrl = generateAemAssetsOptimizedUrl(url, alias, params);\n expect(optimizedUrl).toBe('https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&size=100%2C100');\n });\n\n test('should generate aem assets optimized url with width and height', () => {\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n const alias = 'test';\n const params = {\n quality: 80,\n format: 'webp',\n width: 100,\n height: 100,\n };\n const optimizedUrl = generateAemAssetsOptimizedUrl(url, alias, params);\n expect(optimizedUrl).toBe('https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&width=100&height=100');\n });\n\n test('should try generate aem assets optimized url', () => {\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n const alias = 'test';\n const params = {\n quality: 80,\n format: 'webp',\n width: 100,\n height: 100,\n };\n const optimizedUrl = tryGenerateAemAssetsOptimizedUrl(url, alias, params);\n expect(optimizedUrl).toBe('https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&width=100&height=100');\n });\n\n test('should try generate aem assets optimized url with default params', () => {\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n const alias = 'test';\n const optimizedUrl = tryGenerateAemAssetsOptimizedUrl(url, alias);\n expect(optimizedUrl).toBe('https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80');\n });\n\n test('should try generate aem assets optimized url with crop', () => {\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n const alias = 'test';\n const params = {\n quality: 80,\n format: 'webp',\n crop: {\n xOrigin: 0,\n yOrigin: 0,\n width: 100,\n height: 100,\n },\n };\n const optimizedUrl = tryGenerateAemAssetsOptimizedUrl(url, alias, params);\n expect(optimizedUrl).toBe('https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&crop=0p%2C0p%2C100p%2C100p');\n }); \n\n test('should return original url if aem assets is disabled', () => {\n (getConfigValue as jest.Mock).mockReturnValueOnce(false);\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n const alias = 'test';\n const params = {\n quality: 80,\n format: 'webp',\n };\n const optimizedUrl = tryGenerateAemAssetsOptimizedUrl(url, alias, params); \n expect(optimizedUrl).toBe(url);\n });\n\n test('should return original url if url is not aem assets url', () => {\n const url = 'https://example.com/image.jpg';\n const alias = 'test';\n const params = {\n quality: 80,\n format: 'webp',\n };\n const optimizedUrl = tryGenerateAemAssetsOptimizedUrl(url, alias, params);\n expect(optimizedUrl).toBe(url);\n });\n\n test('should make aem assets image slot', () => {\n const slot = makeAemAssetsImageSlot({\n alias: 'test',\n params: {},\n imageProps: {\n src: 'https://example.com/adobe/assets/urn:aaid:aem:1234567890',\n },\n });\n const container = document.createElement('div');\n slot({ replaceWith: (element: HTMLElement) => {\n container.appendChild(element);\n } });\n });\n\n test('should try render aem assets image', () => {\n const container = document.createElement('div');\n const ctx = {\n replaceWith: (element: HTMLElement) => {\n container.appendChild(element);\n },\n };\n const config = {\n alias: 'test',\n params: {},\n imageProps: {\n src: 'https://example.com/adobe/assets/urn:aaid:aem:1234567890',\n },\n };\n tryRenderAemAssetsImage(ctx, config);\n });\n\n test('should render default image if aem assets is disabled', () => {\n (getConfigValue as jest.Mock).mockReturnValueOnce(false);\n const container = document.createElement('div');\n const ctx = {\n replaceWith: (element: HTMLElement) => {\n container.appendChild(element);\n },\n };\n const config = {\n alias: 'test',\n params: {},\n imageProps: {\n src: 'https://example.com/adobe/assets/urn:aaid:aem:1234567890',\n },\n };\n tryRenderAemAssetsImage(ctx, config);\n });\n\n test('should render default image if url is not aem assets url', () => {\n const container = document.createElement('div');\n const ctx = {\n replaceWith: (element: HTMLElement) => {\n container.appendChild(element);\n },\n };\n const config = {\n alias: 'test',\n params: {},\n imageProps: {\n src: 'https://example.com/image.jpg',\n },\n };\n tryRenderAemAssetsImage(ctx, config);\n });\n});"],"names":["key","isAemAssetsEnabled","getConfigValue","params","getDefaultAemAssetsOptimizationParams","isAemAssetsUrl","optimizedUrl","generateAemAssetsOptimizedUrl","tryGenerateAemAssetsOptimizedUrl","url","slot","makeAemAssetsImageSlot","container","element","tryRenderAemAssetsImage"],"mappings":"qkBAaA,KAAK,KAAK,YAAa,KAAO,CAC5B,eAAgB,KAAK,GAAK,EAAA,mBAAoBA,GAAgB,CAC5D,GAAIA,IAAQ,0BACH,MAAA,EAGV,CAAA,CACH,EAAE,EAGF,OAAO,eAAe,OAAQ,WAAY,CAC1C,MAAO,CACH,SAAU,IACV,OAAQ,sBACR,SAAU,QAAA,CAEd,CAAC,EAED,SAAS,aAAc,IAAM,CAC3B,WAAW,IAAM,CACf,KAAK,cAAc,CAAA,CACpB,EAED,KAAK,oBAAqB,IAAM,CAC9B,OAAOC,EAAmB,CAAC,EAA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,GAAyB,CAC5CD,EAAU,YAAYC,CAAO,CAAA,EAC5B,CAAA,CACJ,EAED,KAAK,qCAAsC,IAAM,CACzC,MAAAD,EAAY,SAAS,cAAc,KAAK,EAa9CE,EAZY,CACV,YAAcD,GAAyB,CACrCD,EAAU,YAAYC,CAAO,CAAA,CAEjC,EACe,CACb,MAAO,OACP,OAAQ,CAAC,EACT,WAAY,CACV,IAAK,0DAAA,CAET,CACmC,CAAA,CACpC,EAED,KAAK,wDAAyD,IAAM,CACjEX,EAA6B,oBAAoB,EAAK,EACjD,MAAAU,EAAY,SAAS,cAAc,KAAK,EAa9CE,EAZY,CACV,YAAcD,GAAyB,CACrCD,EAAU,YAAYC,CAAO,CAAA,CAEjC,EACe,CACb,MAAO,OACP,OAAQ,CAAC,EACT,WAAY,CACV,IAAK,0DAAA,CAET,CACmC,CAAA,CACpC,EAED,KAAK,2DAA4D,IAAM,CAC/D,MAAAD,EAAY,SAAS,cAAc,KAAK,EAa9CE,EAZY,CACV,YAAcD,GAAyB,CACrCD,EAAU,YAAYC,CAAO,CAAA,CAEjC,EACe,CACb,MAAO,OACP,OAAQ,CAAC,EACT,WAAY,CACV,IAAK,+BAAA,CAET,CACmC,CAAA,CACpC,CACH,CAAC"}
@@ -1 +0,0 @@
1
- export * from '../../types/elsie/src/lib/aem/configs.test'
@@ -1,4 +0,0 @@
1
- /*! Copyright 2025 Adobe
2
- All Rights Reserved. */
3
- import{initializeConfig as o,getConfigValue as s,getRootPath as n,getListOfRootPaths as c,isMultistore as u,getHeaders as a,resetConfig as f}from"./configs.js";import"../../chunks/get-path-value.js";import"../../chunks/cjs.js";describe("AEM Config",()=>{const t={public:{default:{headers:{all:{"x-test":"test"},commerce:{"x-commerce":"commerce"}}}}};beforeEach(()=>{i("/"),f()}),afterEach(()=>{jest.clearAllMocks(),jest.restoreAllMocks()}),test("should initialize config (default)",()=>{const e={public:{default:{foo:"bar"}}},l=o(e);expect(l).toEqual(e.public.default)}),test("should initialize config with default config if root path is not found",()=>{i("/not-found/");const e=o(t);expect(e).toEqual(t.public.default)}),test("should initialize config with default config if root path is empty",()=>{i("/sub-path/");const e=o({...t,public:{...t.public,"/sub-path/":{}}});expect(e).toEqual(t.public.default)}),test("should initialize config with overrides if root path is not empty",()=>{i("/sub-path/");const e=o({...t,public:{...t.public,"/sub-path/":{headers:{all:{"x-test":"test2"}}}}});expect(e).toEqual({headers:{all:{"x-test":"test2"},commerce:{"x-commerce":"commerce"}}})}),test("should throw error if no config is initialized",async()=>{expect(()=>s("foo")).toThrow("Configuration not initialized. Call initializeConfig() first.")}),test("should get config value",async()=>{o({public:{default:{foo:"bar"}}}),expect(s("foo")).toBe("bar")}),test("should get config value from root path",()=>{i("/sub-path/"),o({...t,public:{...t.public,"/sub-path/":{foo:"baz",nested:{foo:"nested"}}}}),expect(s("headers.all.x-test")).toBe("test"),expect(s("foo")).toBe("baz"),expect(s("nested.foo")).toBe("nested")}),test("should warn if value is not found",async()=>{const e=jest.spyOn(console,"warn").mockImplementation(()=>{});o(t),s("foo.bar"),expect(e).toHaveBeenCalledWith("Property foo.bar does not exist in the object")}),test("should warn if the root path has no config",async()=>{const e=jest.spyOn(console,"warn").mockImplementation(()=>{}),l=n(null);expect(l).toBe("/"),expect(e).toHaveBeenCalledWith("No config found. Please call initializeConfig() first.")}),test("should warn if the root path is not found",async()=>{i("/no-found/");const e=n({public:{default:{}}});expect(e).toBe("/")}),test("should get default root path",async()=>{i("/path/"),o(t),expect(n()).toBe("/")}),test("should get root path from public config",async()=>{i("/test/"),o({...t,public:{...t.public,"/test/":{}}}),expect(n()).toBe("/test/")}),test("should get list of root paths",async()=>{o({...t,public:{...t.public,"/test/":{},"/test2/":{}}}),expect(c()).toEqual(["/test/","/test2/"])}),test("should warn if list of root paths has no config",async()=>{const e=jest.spyOn(console,"warn").mockImplementation(()=>{}),l=c();expect(e).toHaveBeenCalledWith("No config found. Please call initializeConfig() first."),expect(l).toEqual([])}),test("should check if multistore",async()=>{o(t),expect(u()).toBe(!1),o({...t,public:{...t.public,"/test/":{}}}),expect(u()).toBe(!0)}),test("should throw error if headers are not initialized",async()=>{expect(()=>a("all")).toThrow("Configuration not initialized. Call initializeConfig() first.")}),test("should get headers",async()=>{o(t),expect(a("all")).toEqual(t.public.default.headers.all),expect(a("commerce")).toEqual({...t.public.default.headers.all,...t.public.default.headers.commerce})}),test('should get "all" headers if no config is found',async()=>{o(t),expect(a("not-found")).toEqual({...t.public.default.headers.all})}),test("should get empty headers if no config is found",async()=>{o({public:{default:{}}}),expect(a("not-found")).toEqual({})})});function i(t){Object.defineProperty(window,"location",{value:{pathname:t,origin:"http://localhost"}})}
4
- //# sourceMappingURL=configs.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"configs.test.js","sources":["/@dropins/tools/src/lib/aem/configs.test.ts"],"sourcesContent":["import {\n resetConfig,\n getRootPath,\n getListOfRootPaths,\n isMultistore,\n getConfigValue,\n getHeaders,\n initializeConfig,\n} from './configs';\n\ndescribe('AEM Config', () => {\n const mockConfig = {\n public: {\n default: {\n headers: {\n all: {\n 'x-test': 'test',\n },\n commerce: {\n 'x-commerce': 'commerce',\n },\n },\n },\n },\n };\n\n beforeEach(() => {\n mockLocation('/');\n resetConfig();\n });\n\n afterEach(() => {\n jest.clearAllMocks();\n jest.restoreAllMocks();\n });\n\n test('should initialize config (default)', () => {\n const mockConfig = {\n public: {\n default: {\n foo: 'bar',\n },\n },\n };\n\n const rootConfig = initializeConfig(mockConfig);\n\n // Test config value retrieval\n expect(rootConfig).toEqual(mockConfig.public.default);\n });\n\n test('should initialize config with default config if root path is not found', () => {\n mockLocation('/not-found/');\n\n const rootConfig = initializeConfig(mockConfig);\n\n // Test config value retrieval\n expect(rootConfig).toEqual(mockConfig.public.default);\n });\n\n test('should initialize config with default config if root path is empty', () => {\n mockLocation('/sub-path/');\n\n const rootConfig = initializeConfig({\n ...mockConfig,\n public: {\n ...mockConfig.public,\n '/sub-path/': {},\n },\n });\n\n // Test config value retrieval\n expect(rootConfig).toEqual(mockConfig.public.default);\n });\n\n test('should initialize config with overrides if root path is not empty', () => {\n mockLocation('/sub-path/');\n\n const rootConfig = initializeConfig({\n ...mockConfig,\n public: {\n ...mockConfig.public,\n '/sub-path/': {\n headers: {\n all: {\n 'x-test': 'test2',\n },\n },\n },\n },\n });\n\n // Test config value retrieval\n expect(rootConfig).toEqual({\n headers: {\n all: {\n 'x-test': 'test2',\n },\n commerce: {\n 'x-commerce': 'commerce',\n },\n },\n });\n });\n\n test('should throw error if no config is initialized', async () => {\n expect(() => getConfigValue('foo')).toThrow(\n 'Configuration not initialized. Call initializeConfig() first.'\n );\n });\n\n test('should get config value', async () => {\n initializeConfig({\n public: {\n default: {\n foo: 'bar',\n },\n },\n });\n\n expect(getConfigValue('foo')).toBe('bar');\n });\n\n test('should get config value from root path', () => {\n mockLocation('/sub-path/');\n\n initializeConfig({\n ...mockConfig,\n public: {\n ...mockConfig.public,\n '/sub-path/': {\n foo: 'baz',\n nested: {\n foo: 'nested',\n },\n },\n },\n });\n\n expect(getConfigValue('headers.all.x-test')).toBe('test');\n expect(getConfigValue('foo')).toBe('baz');\n expect(getConfigValue('nested.foo')).toBe('nested');\n });\n\n test('should warn if value is not found', async () => {\n const consoleSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});\n initializeConfig(mockConfig);\n\n getConfigValue('foo.bar');\n\n expect(consoleSpy).toHaveBeenCalledWith(\n 'Property foo.bar does not exist in the object'\n );\n });\n\n test('should warn if the root path has no config', async () => {\n const consoleSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});\n\n const rootPath = getRootPath(null);\n\n expect(rootPath).toBe('/');\n\n expect(consoleSpy).toHaveBeenCalledWith(\n 'No config found. Please call initializeConfig() first.'\n );\n });\n\n test('should warn if the root path is not found', async () => {\n mockLocation('/no-found/');\n\n const rootPath = getRootPath({\n public: {\n default: {},\n },\n });\n\n expect(rootPath).toBe('/');\n });\n\n test('should get default root path', async () => {\n mockLocation('/path/');\n\n initializeConfig(mockConfig);\n\n expect(getRootPath()).toBe('/');\n });\n\n test('should get root path from public config', async () => {\n mockLocation('/test/');\n\n initializeConfig({\n ...mockConfig,\n public: {\n ...mockConfig.public,\n '/test/': {},\n },\n });\n\n expect(getRootPath()).toBe('/test/');\n });\n\n test('should get list of root paths', async () => {\n initializeConfig({\n ...mockConfig,\n public: {\n ...mockConfig.public,\n '/test/': {},\n '/test2/': {},\n },\n });\n\n expect(getListOfRootPaths()).toEqual(['/test/', '/test2/']);\n });\n\n test('should warn if list of root paths has no config', async () => {\n const consoleSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});\n\n const rootPaths = getListOfRootPaths();\n\n expect(consoleSpy).toHaveBeenCalledWith(\n 'No config found. Please call initializeConfig() first.'\n );\n\n expect(rootPaths).toEqual([]);\n });\n\n test('should check if multistore', async () => {\n initializeConfig(mockConfig);\n\n expect(isMultistore()).toBe(false);\n\n initializeConfig({\n ...mockConfig,\n public: {\n ...mockConfig.public,\n '/test/': {},\n },\n });\n\n expect(isMultistore()).toBe(true);\n });\n\n test('should throw error if headers are not initialized', async () => {\n expect(() => getHeaders('all')).toThrow(\n 'Configuration not initialized. Call initializeConfig() first.'\n );\n });\n\n test('should get headers', async () => {\n initializeConfig(mockConfig);\n\n // All headers\n expect(getHeaders('all')).toEqual(mockConfig.public.default.headers.all);\n expect(getHeaders('commerce')).toEqual({\n ...mockConfig.public.default.headers.all,\n ...mockConfig.public.default.headers.commerce,\n });\n });\n\n test('should get \"all\" headers if no config is found', async () => {\n initializeConfig(mockConfig);\n\n expect(getHeaders('not-found')).toEqual({\n ...mockConfig.public.default.headers.all,\n });\n });\n\n test('should get empty headers if no config is found', async () => {\n initializeConfig({\n public: {\n default: {},\n },\n });\n\n expect(getHeaders('not-found')).toEqual({});\n });\n});\n\nfunction mockLocation(pathname: string) {\n Object.defineProperty(window, 'location', {\n value: {\n pathname,\n origin: 'http://localhost',\n },\n });\n}\n"],"names":["mockConfig","mockLocation","resetConfig","rootConfig","initializeConfig","getConfigValue","consoleSpy","rootPath","getRootPath","getListOfRootPaths","rootPaths","isMultistore","getHeaders","pathname"],"mappings":"mOAUA,SAAS,aAAc,IAAM,CAC3B,MAAMA,EAAa,CACjB,OAAQ,CACN,QAAS,CACP,QAAS,CACP,IAAK,CACH,SAAU,MACZ,EACA,SAAU,CACR,aAAc,UAAA,CAChB,CACF,CACF,CAEJ,EAEA,WAAW,IAAM,CACfC,EAAa,GAAG,EACJC,EAAA,CAAA,CACb,EAED,UAAU,IAAM,CACd,KAAK,cAAc,EACnB,KAAK,gBAAgB,CAAA,CACtB,EAED,KAAK,qCAAsC,IAAM,CAC/C,MAAMF,EAAa,CACjB,OAAQ,CACN,QAAS,CACP,IAAK,KAAA,CACP,CAEJ,EAEMG,EAAaC,EAAiBJ,CAAU,EAG9C,OAAOG,CAAU,EAAE,QAAQH,EAAW,OAAO,OAAO,CAAA,CACrD,EAED,KAAK,yEAA0E,IAAM,CACnFC,EAAa,aAAa,EAEpB,MAAAE,EAAaC,EAAiBJ,CAAU,EAG9C,OAAOG,CAAU,EAAE,QAAQH,EAAW,OAAO,OAAO,CAAA,CACrD,EAED,KAAK,qEAAsE,IAAM,CAC/EC,EAAa,YAAY,EAEzB,MAAME,EAAaC,EAAiB,CAClC,GAAGJ,EACH,OAAQ,CACN,GAAGA,EAAW,OACd,aAAc,CAAA,CAAC,CACjB,CACD,EAGD,OAAOG,CAAU,EAAE,QAAQH,EAAW,OAAO,OAAO,CAAA,CACrD,EAED,KAAK,oEAAqE,IAAM,CAC9EC,EAAa,YAAY,EAEzB,MAAME,EAAaC,EAAiB,CAClC,GAAGJ,EACH,OAAQ,CACN,GAAGA,EAAW,OACd,aAAc,CACZ,QAAS,CACP,IAAK,CACH,SAAU,OAAA,CACZ,CACF,CACF,CACF,CACD,EAGM,OAAAG,CAAU,EAAE,QAAQ,CACzB,QAAS,CACP,IAAK,CACH,SAAU,OACZ,EACA,SAAU,CACR,aAAc,UAAA,CAChB,CACF,CACD,CAAA,CACF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