@sparted/shared-library 1.0.2 → 1.0.3

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,4 +1,11 @@
1
- import type { Cdn, ImgixConfig, TwicpicsConfig } from './types';
2
- declare type WhichCdn<Config> = Config extends ImgixConfig ? Cdn<ImgixConfig> : Cdn<TwicpicsConfig>;
3
- export declare function cdnFactory<Config extends ImgixConfig | TwicpicsConfig>(domain: string, config: Config): WhichCdn<Config>;
4
- export {};
1
+ import type { CreateCdn, TransformationQueries } from './types';
2
+ export declare const imgixTransformationQueries: TransformationQueries;
3
+ export declare const twicpicsTransformationQueries: TransformationQueries;
4
+ /**
5
+ *
6
+ * @param type cdn provider: 'twicpics' | 'imgix'
7
+ * @param domain provider domain
8
+ * @param instanceMapper domain + the result of the instanceMapper will form the base path
9
+ * @returns \{ getCdnUrl, transformationQueries \}
10
+ */
11
+ export declare const createCdn: CreateCdn;
@@ -2,18 +2,52 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var imgix_cdnCreator = require('./cdn-creators/imgix.cdn-creator.js');
6
- var twicpics_cdnCreator = require('./cdn-creators/twicpics.cdn-creator.js');
5
+ var _tslib = require('../_virtual/_tslib.js');
6
+ var getCdnFromS3Url_util = require('./utils/get-cdn-from-s3-url.util.js');
7
7
 
8
- function cdnFactory(domain, config) {
9
- if (config.type === 'twicpics') {
10
- return twicpics_cdnCreator.twicpicsCdnCreator(domain, config);
8
+ const imgixTransformationQueries = (_a) => {
9
+ var { fit } = _a, rest = _tslib.__rest(_a, ["fit"]);
10
+ return [
11
+ '?auto=compress,format',
12
+ ...Object.entries(Object.assign(Object.assign({}, (fit !== undefined && fit === 'crop' ? { fit } : {})), rest)).map(([k, v]) => `&${k}=${v}`),
13
+ ].join('');
14
+ };
15
+ const twicpicsTransformationQueries = (params) => {
16
+ if (params.fit !== undefined) {
17
+ if (params.width === undefined || params.height === undefined) {
18
+ // eslint-disable-next-line no-console
19
+ console.error('⚠️ The Twicpics api needs a width and a height.');
20
+ return '';
21
+ }
22
+ return `?twic=v1/${params.fit}=${params.width}x${params.height}`;
11
23
  }
12
- if (config.type === 'imgix') {
13
- return imgix_cdnCreator.imgixCdnCreator(domain);
24
+ if (params.width !== undefined) {
25
+ const resizeHeight = params.height !== undefined ? `x${params.height}` : '';
26
+ return `?twic=v1/resize=${params.width}${resizeHeight}`;
14
27
  }
15
- throw new Error('Unknown cdn type');
16
- }
28
+ return '';
29
+ };
30
+ /**
31
+ *
32
+ * @param type cdn provider: 'twicpics' | 'imgix'
33
+ * @param domain provider domain
34
+ * @param instanceMapper domain + the result of the instanceMapper will form the base path
35
+ * @returns \{ getCdnUrl, transformationQueries \}
36
+ */
37
+ const createCdn = ({ type, domain, instanceMapper }) => {
38
+ const getCdnUrl = (instanceId, path) => `${domain}${instanceMapper(instanceId)}${path}`;
39
+ return {
40
+ getCdnUrl,
41
+ getCdnFromS3Url: getCdnFromS3Url_util.getCdnFromS3UrlFactory({
42
+ getCdnUrl,
43
+ transformationQueries: type === 'imgix'
44
+ ? imgixTransformationQueries
45
+ : twicpicsTransformationQueries,
46
+ }),
47
+ };
48
+ };
17
49
 
18
- exports.cdnFactory = cdnFactory;
50
+ exports.createCdn = createCdn;
51
+ exports.imgixTransformationQueries = imgixTransformationQueries;
52
+ exports.twicpicsTransformationQueries = twicpicsTransformationQueries;
19
53
  //# sourceMappingURL=cdn.factory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cdn.factory.js","sources":["../../src/cdn/cdn.factory.ts"],"sourcesContent":["import { imgixCdnCreator, twicpicsCdnCreator } from './cdn-creators';\nimport type { Cdn, ImgixConfig, TwicpicsConfig } from './types';\n\ntype WhichCdn<Config> = Config extends ImgixConfig\n ? Cdn<ImgixConfig>\n : Cdn<TwicpicsConfig>;\n\nexport function cdnFactory<Config extends ImgixConfig | TwicpicsConfig>(\n domain: string,\n config: Config,\n): WhichCdn<Config> {\n if (config.type === 'twicpics') {\n return twicpicsCdnCreator(domain, config) as WhichCdn<Config>;\n }\n if (config.type === 'imgix') {\n return imgixCdnCreator(domain, config) as WhichCdn<Config>;\n }\n throw new Error('Unknown cdn type');\n}\n"],"names":["twicpicsCdnCreator","imgixCdnCreator"],"mappings":";;;;;;;AAOgB,SAAA,UAAU,CACxB,MAAc,EACd,MAAc,EAAA;AAEd,IAAA,IAAI,MAAM,CAAC,IAAI,KAAK,UAAU,EAAE;AAC9B,QAAA,OAAOA,sCAAkB,CAAC,MAAM,EAAE,MAAM,CAAqB,CAAC;AAC/D,KAAA;AACD,IAAA,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,EAAE;AAC3B,QAAA,OAAOC,gCAAe,CAAC,MAAc,CAAqB,CAAC;AAC5D,KAAA;AACD,IAAA,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;AACtC;;;;"}
1
+ {"version":3,"file":"cdn.factory.js","sources":["../../src/cdn/cdn.factory.ts"],"sourcesContent":["import type { CreateCdn, GetCdnUrl, TransformationQueries } from './types';\nimport { getCdnFromS3UrlFactory } from './utils/get-cdn-from-s3-url.util';\n\nexport const imgixTransformationQueries: TransformationQueries = ({ fit, ...rest }) => [\n '?auto=compress,format',\n ...Object.entries({\n ...(fit !== undefined && fit === 'crop' ? { fit } : {}),\n ...rest,\n }).map(([k, v]) => `&${k}=${v}`),\n].join('');\n\nexport const twicpicsTransformationQueries: TransformationQueries = (\n params,\n) => {\n if (params.fit !== undefined) {\n if (params.width === undefined || params.height === undefined) {\n // eslint-disable-next-line no-console\n console.error('⚠️ The Twicpics api needs a width and a height.');\n return '';\n }\n return `?twic=v1/${params.fit}=${params.width}x${params.height}`;\n }\n if (params.width !== undefined) {\n const resizeHeight = params.height !== undefined ? `x${params.height}` : '';\n return `?twic=v1/resize=${params.width}${resizeHeight}`;\n }\n return '';\n};\n\n/**\n *\n * @param type cdn provider: 'twicpics' | 'imgix'\n * @param domain provider domain\n * @param instanceMapper domain + the result of the instanceMapper will form the base path\n * @returns \\{ getCdnUrl, transformationQueries \\}\n */\nexport const createCdn: CreateCdn = ({ type, domain, instanceMapper }) => {\n const getCdnUrl: GetCdnUrl = (instanceId, path) => `${domain}${instanceMapper(instanceId)}${path}`;\n\n return {\n getCdnUrl,\n getCdnFromS3Url: getCdnFromS3UrlFactory({\n getCdnUrl,\n transformationQueries:\n type === 'imgix'\n ? imgixTransformationQueries\n : twicpicsTransformationQueries,\n }),\n };\n};\n"],"names":["__rest","getCdnFromS3UrlFactory"],"mappings":";;;;;;;AAGa,MAAA,0BAA0B,GAA0B,CAAC,EAAgB,KAAI;AAApB,IAAA,IAAA,EAAE,GAAG,EAAW,GAAA,EAAA,EAAN,IAAI,GAAAA,aAAA,CAAA,EAAA,EAAd,OAAgB,CAAF,CAAA;IAAO,OAAA;QACrF,uBAAuB;AACvB,QAAA,GAAG,MAAM,CAAC,OAAO,kCACX,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,MAAM,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,EAAC,EACpD,IAAI,CACP,CAAA,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAA,CAAA,EAAI,CAAC,CAAI,CAAA,EAAA,CAAC,EAAE,CAAC;AACjC,KAAA,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;EAAC;AAEE,MAAA,6BAA6B,GAA0B,CAClE,MAAM,KACJ;AACF,IAAA,IAAI,MAAM,CAAC,GAAG,KAAK,SAAS,EAAE;QAC5B,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE;;AAE7D,YAAA,OAAO,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAC;AAClE,YAAA,OAAO,EAAE,CAAC;AACX,SAAA;AACD,QAAA,OAAO,CAAY,SAAA,EAAA,MAAM,CAAC,GAAG,CAAI,CAAA,EAAA,MAAM,CAAC,KAAK,CAAI,CAAA,EAAA,MAAM,CAAC,MAAM,EAAE,CAAC;AAClE,KAAA;AACD,IAAA,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE;AAC9B,QAAA,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,KAAK,SAAS,GAAG,CAAI,CAAA,EAAA,MAAM,CAAC,MAAM,CAAA,CAAE,GAAG,EAAE,CAAC;AAC5E,QAAA,OAAO,mBAAmB,MAAM,CAAC,KAAK,CAAG,EAAA,YAAY,EAAE,CAAC;AACzD,KAAA;AACD,IAAA,OAAO,EAAE,CAAC;AACZ,EAAE;AAEF;;;;;;AAMG;AACI,MAAM,SAAS,GAAc,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,KAAI;AACvE,IAAA,MAAM,SAAS,GAAc,CAAC,UAAU,EAAE,IAAI,KAAK,GAAG,MAAM,CAAA,EAAG,cAAc,CAAC,UAAU,CAAC,CAAG,EAAA,IAAI,EAAE,CAAC;IAEnG,OAAO;QACL,SAAS;QACT,eAAe,EAAEC,2CAAsB,CAAC;YACtC,SAAS;YACT,qBAAqB,EACnB,IAAI,KAAK,OAAO;AACd,kBAAE,0BAA0B;AAC5B,kBAAE,6BAA6B;SACpC,CAAC;KACH,CAAC;AACJ;;;;;;"}
package/cdn/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { cdnFactory } from './cdn.factory';
1
+ export { createCdn } from './cdn.factory';
2
2
  export * from './types';
package/cdn/index.js CHANGED
@@ -6,5 +6,5 @@ var cdn_factory = require('./cdn.factory.js');
6
6
 
7
7
 
8
8
 
9
- exports.cdnFactory = cdn_factory.cdnFactory;
9
+ exports.createCdn = cdn_factory.createCdn;
10
10
  //# sourceMappingURL=index.js.map
@@ -1,24 +1,23 @@
1
- import type { ImgixTransformation, Transformation, TwicpicsTransformation } from './transformation.type';
2
- export declare type BaseConfig = {
3
- type: 'twicpics' | 'imgix';
4
- };
5
1
  export declare type BaseUrlMapperFunc = (instanceId: string) => string;
6
- export declare type TwicpicsConfig = BaseConfig & {
7
- type: 'twicpics';
8
- baseUrlMapper: BaseUrlMapperFunc;
9
- };
10
- export declare type ImgixConfig = BaseConfig & {
11
- type: 'imgix';
2
+ export declare type Transformation = {
3
+ fit?: 'crop' | 'contain';
4
+ width?: number;
5
+ height?: number;
12
6
  };
13
- export declare type CdnParams<T extends Transformation> = {
7
+ export declare type CdnParams = {
14
8
  asThumbnail?: boolean;
15
- transformation?: T;
9
+ transformation?: Transformation;
10
+ };
11
+ export declare type TransformationQueries = (params: Transformation) => string;
12
+ export declare type GetCdnUrl = (instanceId: string, path: `/${string}`) => string;
13
+ export declare type GetCdnFromS3Url = (url: string, params?: CdnParams) => string;
14
+ export declare type CdnConfig = {
15
+ type: 'twicpics' | 'imgix';
16
+ domain: `https://${string}`;
17
+ instanceMapper: (instanceId: string) => string;
16
18
  };
17
- export declare type GetCdnUrl = (path: string, instanceId: string) => string;
18
- export declare type GetCdnFromS3Url<T extends Transformation> = (url: string, params?: CdnParams<T>) => string;
19
- export declare type TransformationFromConfig<Config extends BaseConfig> = Config['type'] extends 'imgix' ? ImgixTransformation : TwicpicsTransformation;
20
- export declare type Cdn<Config extends BaseConfig> = {
19
+ export declare type Cdn = {
21
20
  getCdnUrl: GetCdnUrl;
22
- getCdnFromS3Url: GetCdnFromS3Url<TransformationFromConfig<Config>>;
21
+ getCdnFromS3Url: GetCdnFromS3Url;
23
22
  };
24
- export declare type CreateCdn<Config extends BaseConfig> = (domain: string, config: Config) => Cdn<typeof config>;
23
+ export declare type CreateCdn = (config: CdnConfig) => Cdn;
@@ -1,2 +1 @@
1
1
  export * from './cdn-factory.type';
2
- export * from './transformation.type';
@@ -1,6 +1,6 @@
1
1
  declare type ExtractInfoFromUrl = (url: string) => {
2
2
  instanceId: string;
3
- path: string;
3
+ path: `/${string}`;
4
4
  } | undefined;
5
5
  export declare const extractInfoFromUrl: ExtractInfoFromUrl;
6
6
  export {};
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const S3_URL_RE = /https:\/\/sparted-prod-([^.]+)\.s3(\.eu-west-1)?(\.amazonaws\.com)?(\.fr-par\.scw\.cloud)?([^?]+)/;
5
+ const S3_URL_RE = /https:\/\/sparted-prod-([^.]+)\.s3(\.eu-west-1)?(\.amazonaws\.com)?(\.fr-par\.scw\.cloud)?(\/[^?]+)/;
6
6
  const extractInfoFromUrl = (url) => {
7
7
  const matchS3Url = url.match(S3_URL_RE);
8
8
  if (!matchS3Url) {
@@ -1 +1 @@
1
- {"version":3,"file":"extract-info-from-url.util.js","sources":["../../../src/cdn/utils/extract-info-from-url.util.ts"],"sourcesContent":["type ExtractInfoFromUrl = (url: string) =>\n| {\n instanceId: string;\n path: string;\n}\n| undefined;\n\nconst S3_URL_RE = /https:\\/\\/sparted-prod-([^.]+)\\.s3(\\.eu-west-1)?(\\.amazonaws\\.com)?(\\.fr-par\\.scw\\.cloud)?([^?]+)/;\n\nexport const extractInfoFromUrl: ExtractInfoFromUrl = (url) => {\n const matchS3Url = url.match(S3_URL_RE);\n\n if (!matchS3Url) {\n return undefined;\n }\n\n const instanceId = matchS3Url[1];\n const path = matchS3Url[5];\n\n return { instanceId, path };\n};\n"],"names":[],"mappings":";;;;AAOA,MAAM,SAAS,GAAG,mGAAmG,CAAC;AAEzG,MAAA,kBAAkB,GAAuB,CAAC,GAAG,KAAI;IAC5D,MAAM,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAExC,IAAI,CAAC,UAAU,EAAE;AACf,QAAA,OAAO,SAAS,CAAC;AAClB,KAAA;AAED,IAAA,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;AACjC,IAAA,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;AAE3B,IAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;AAC9B;;;;"}
1
+ {"version":3,"file":"extract-info-from-url.util.js","sources":["../../../src/cdn/utils/extract-info-from-url.util.ts"],"sourcesContent":["type ExtractInfoFromUrl = (url: string) =>\n| {\n instanceId: string;\n path: `/${string}`;\n}\n| undefined;\n\nconst S3_URL_RE = /https:\\/\\/sparted-prod-([^.]+)\\.s3(\\.eu-west-1)?(\\.amazonaws\\.com)?(\\.fr-par\\.scw\\.cloud)?(\\/[^?]+)/;\n\nexport const extractInfoFromUrl: ExtractInfoFromUrl = (url) => {\n const matchS3Url = url.match(S3_URL_RE);\n\n if (!matchS3Url) {\n return undefined;\n }\n\n const instanceId = matchS3Url[1];\n const path = matchS3Url[5] as `/${string}`;\n\n return { instanceId, path };\n};\n"],"names":[],"mappings":";;;;AAOA,MAAM,SAAS,GAAG,qGAAqG,CAAC;AAE3G,MAAA,kBAAkB,GAAuB,CAAC,GAAG,KAAI;IAC5D,MAAM,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAExC,IAAI,CAAC,UAAU,EAAE;AACf,QAAA,OAAO,SAAS,CAAC;AAClB,KAAA;AAED,IAAA,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;AACjC,IAAA,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAiB,CAAC;AAE3C,IAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;AAC9B;;;;"}
@@ -1,7 +1,7 @@
1
- import type { GetCdnFromS3Url, GetCdnUrl, Transformation, TransformationQueries } from '../types';
2
- declare type FactoryConfig<T extends Transformation> = {
1
+ import type { GetCdnFromS3Url, GetCdnUrl, TransformationQueries } from '../types';
2
+ declare type FactoryConfig = {
3
3
  getCdnUrl: GetCdnUrl;
4
- transformationQueries: TransformationQueries<T>;
4
+ transformationQueries: TransformationQueries;
5
5
  };
6
- export declare function getCdnFromS3UrlFactory<T extends Transformation>(config: FactoryConfig<T>): GetCdnFromS3Url<T>;
6
+ export declare function getCdnFromS3UrlFactory(config: FactoryConfig): GetCdnFromS3Url;
7
7
  export {};
@@ -14,7 +14,7 @@ function getCdnFromS3UrlFactory(config) {
14
14
  }
15
15
  const { instanceId, path } = info;
16
16
  const { transformation = params.asThumbnail ? DEFAULT_THUMBNAIL_CONFIG : {}, } = params;
17
- return `${getCdnUrl(path, instanceId)}${transformationQueries(transformation)}`;
17
+ return `${getCdnUrl(instanceId, path)}${transformationQueries(transformation)}`;
18
18
  };
19
19
  }
20
20
 
@@ -1 +1 @@
1
- {"version":3,"file":"get-cdn-from-s3-url.util.js","sources":["../../../src/cdn/utils/get-cdn-from-s3-url.util.ts"],"sourcesContent":["import type {\n GetCdnFromS3Url,\n GetCdnUrl,\n Transformation,\n TransformationQueries,\n} from '../types';\nimport { extractInfoFromUrl } from './extract-info-from-url.util';\n\nconst DEFAULT_THUMBNAIL_CONFIG: Transformation = { width: 300, height: 300 };\n\ntype FactoryConfig<T extends Transformation> = {\n getCdnUrl: GetCdnUrl;\n transformationQueries: TransformationQueries<T>;\n};\n\nexport function getCdnFromS3UrlFactory<T extends Transformation>(\n config: FactoryConfig<T>,\n): GetCdnFromS3Url<T> {\n return (url, params = {}) => {\n const { getCdnUrl, transformationQueries } = config;\n\n const info = extractInfoFromUrl(url);\n if (info === undefined) {\n return url;\n }\n const { instanceId, path } = info;\n\n const {\n transformation = params.asThumbnail ? DEFAULT_THUMBNAIL_CONFIG : {},\n } = params;\n\n return `${getCdnUrl(path, instanceId)}${transformationQueries(\n transformation as T,\n )}`;\n };\n}\n"],"names":["extractInfoFromUrl"],"mappings":";;;;;;AAQA,MAAM,wBAAwB,GAAmB,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AAOvE,SAAU,sBAAsB,CACpC,MAAwB,EAAA;AAExB,IAAA,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,KAAI;AAC1B,QAAA,MAAM,EAAE,SAAS,EAAE,qBAAqB,EAAE,GAAG,MAAM,CAAC;AAEpD,QAAA,MAAM,IAAI,GAAGA,0CAAkB,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,IAAI,KAAK,SAAS,EAAE;AACtB,YAAA,OAAO,GAAG,CAAC;AACZ,SAAA;AACD,QAAA,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;AAElC,QAAA,MAAM,EACJ,cAAc,GAAG,MAAM,CAAC,WAAW,GAAG,wBAAwB,GAAG,EAAE,GACpE,GAAG,MAAM,CAAC;AAEX,QAAA,OAAO,CAAG,EAAA,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA,EAAG,qBAAqB,CAC3D,cAAmB,CACpB,EAAE,CAAC;AACN,KAAC,CAAC;AACJ;;;;"}
1
+ {"version":3,"file":"get-cdn-from-s3-url.util.js","sources":["../../../src/cdn/utils/get-cdn-from-s3-url.util.ts"],"sourcesContent":["import type {\n GetCdnFromS3Url,\n GetCdnUrl,\n Transformation,\n TransformationQueries,\n} from '../types';\nimport { extractInfoFromUrl } from './extract-info-from-url.util';\n\nconst DEFAULT_THUMBNAIL_CONFIG: Transformation = { width: 300, height: 300 };\n\ntype FactoryConfig = {\n getCdnUrl: GetCdnUrl;\n transformationQueries: TransformationQueries;\n};\n\nexport function getCdnFromS3UrlFactory(\n config: FactoryConfig,\n): GetCdnFromS3Url {\n return (url, params = {}) => {\n const { getCdnUrl, transformationQueries } = config;\n\n const info = extractInfoFromUrl(url);\n if (info === undefined) {\n return url;\n }\n const { instanceId, path } = info;\n\n const {\n transformation = params.asThumbnail ? DEFAULT_THUMBNAIL_CONFIG : {},\n } = params;\n\n return `${getCdnUrl(instanceId, path)}${transformationQueries(\n transformation,\n )}`;\n };\n}\n"],"names":["extractInfoFromUrl"],"mappings":";;;;;;AAQA,MAAM,wBAAwB,GAAmB,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AAOvE,SAAU,sBAAsB,CACpC,MAAqB,EAAA;AAErB,IAAA,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,KAAI;AAC1B,QAAA,MAAM,EAAE,SAAS,EAAE,qBAAqB,EAAE,GAAG,MAAM,CAAC;AAEpD,QAAA,MAAM,IAAI,GAAGA,0CAAkB,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,IAAI,KAAK,SAAS,EAAE;AACtB,YAAA,OAAO,GAAG,CAAC;AACZ,SAAA;AACD,QAAA,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;AAElC,QAAA,MAAM,EACJ,cAAc,GAAG,MAAM,CAAC,WAAW,GAAG,wBAAwB,GAAG,EAAE,GACpE,GAAG,MAAM,CAAC;AAEX,QAAA,OAAO,CAAG,EAAA,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA,EAAG,qBAAqB,CAC3D,cAAc,CACf,EAAE,CAAC;AACN,KAAC,CAAC;AACJ;;;;"}
package/index.js CHANGED
@@ -36,7 +36,7 @@ var replaceInTemplate = require('./string/replace-in-template.js');
36
36
 
37
37
  exports.arrayToMap = arrayToMap.arrayToMap;
38
38
  exports.valuesFromKeys = getValuesFromKeys.valuesFromKeys;
39
- exports.cdnFactory = cdn_factory.cdnFactory;
39
+ exports.createCdn = cdn_factory.createCdn;
40
40
  exports.MS_DAY = constants.MS_DAY;
41
41
  exports.MS_HOUR = constants.MS_HOUR;
42
42
  exports.MS_MINUTE = constants.MS_MINUTE;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparted/shared-library",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "repository": "git@github.com:Sparted/shared-library.git",
5
5
  "author": "Thomas <duprethomasfr@gmail.com>",
6
6
  "license": "MIT",
@@ -1,3 +0,0 @@
1
- import type { CreateCdn, ImgixConfig, ImgixTransformation, TransformationQueries } from '../types';
2
- export declare const imgixTransformationQueries: TransformationQueries<ImgixTransformation>;
3
- export declare const imgixCdnCreator: CreateCdn<ImgixConfig>;
@@ -1,24 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var getCdnFromS3Url_util = require('../utils/get-cdn-from-s3-url.util.js');
6
-
7
- const imgixTransformationQueries = (params) => [
8
- '?auto=compress,format',
9
- ...Object.entries(params).map(([k, v]) => `&${k}=${v}`),
10
- ].join('');
11
- const imgixCdnCreator = (domain) => {
12
- const getCdnUrl = (path) => `${domain}${path}`;
13
- return {
14
- getCdnUrl,
15
- getCdnFromS3Url: getCdnFromS3Url_util.getCdnFromS3UrlFactory({
16
- getCdnUrl,
17
- transformationQueries: imgixTransformationQueries,
18
- }),
19
- };
20
- };
21
-
22
- exports.imgixCdnCreator = imgixCdnCreator;
23
- exports.imgixTransformationQueries = imgixTransformationQueries;
24
- //# sourceMappingURL=imgix.cdn-creator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"imgix.cdn-creator.js","sources":["../../../src/cdn/cdn-creators/imgix.cdn-creator.ts"],"sourcesContent":["import type {\n CreateCdn,\n GetCdnUrl,\n ImgixConfig,\n ImgixTransformation,\n TransformationQueries,\n} from '../types';\nimport { getCdnFromS3UrlFactory } from '../utils/get-cdn-from-s3-url.util';\n\nexport const imgixTransformationQueries: TransformationQueries<\nImgixTransformation\n> = (params) => [\n '?auto=compress,format',\n ...Object.entries(params).map(([k, v]) => `&${k}=${v}`),\n].join('');\n\nexport const imgixCdnCreator: CreateCdn<ImgixConfig> = (domain) => {\n const getCdnUrl: GetCdnUrl = (path) => `${domain}${path}`;\n\n return {\n getCdnUrl,\n getCdnFromS3Url: getCdnFromS3UrlFactory({\n getCdnUrl,\n transformationQueries: imgixTransformationQueries,\n }),\n };\n};\n"],"names":["getCdnFromS3UrlFactory"],"mappings":";;;;;;MASa,0BAA0B,GAEnC,CAAC,MAAM,KAAK;IACd,uBAAuB;IACvB,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAA,CAAA,EAAI,CAAC,CAAA,CAAE,CAAC;AACxD,CAAA,CAAC,IAAI,CAAC,EAAE,EAAE;AAEE,MAAA,eAAe,GAA2B,CAAC,MAAM,KAAI;AAChE,IAAA,MAAM,SAAS,GAAc,CAAC,IAAI,KAAK,CAAA,EAAG,MAAM,CAAA,EAAG,IAAI,CAAA,CAAE,CAAC;IAE1D,OAAO;QACL,SAAS;QACT,eAAe,EAAEA,2CAAsB,CAAC;YACtC,SAAS;AACT,YAAA,qBAAqB,EAAE,0BAA0B;SAClD,CAAC;KACH,CAAC;AACJ;;;;;"}
@@ -1,2 +0,0 @@
1
- export * from './imgix.cdn-creator';
2
- export * from './twicpics.cdn-creator';
@@ -1,14 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var imgix_cdnCreator = require('./imgix.cdn-creator.js');
6
- var twicpics_cdnCreator = require('./twicpics.cdn-creator.js');
7
-
8
-
9
-
10
- exports.imgixCdnCreator = imgix_cdnCreator.imgixCdnCreator;
11
- exports.imgixTransformationQueries = imgix_cdnCreator.imgixTransformationQueries;
12
- exports.twicpicsCdnCreator = twicpics_cdnCreator.twicpicsCdnCreator;
13
- exports.twicpicsTransformationQueries = twicpics_cdnCreator.twicpicsTransformationQueries;
14
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
@@ -1,3 +0,0 @@
1
- import type { CreateCdn, TransformationQueries, TwicpicsConfig, TwicpicsTransformation } from '../types';
2
- export declare const twicpicsTransformationQueries: TransformationQueries<TwicpicsTransformation>;
3
- export declare const twicpicsCdnCreator: CreateCdn<TwicpicsConfig>;
@@ -1,30 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var getCdnFromS3Url_util = require('../utils/get-cdn-from-s3-url.util.js');
6
-
7
- const twicpicsTransformationQueries = (params) => {
8
- if (params.fit !== undefined) {
9
- return `?twic=v1/${params.fit}=${params.width}x${params.height}`;
10
- }
11
- if (params.width !== undefined) {
12
- return `?twic=v1/resize=${params.width}`;
13
- }
14
- return '';
15
- };
16
- const twicpicsCdnCreator = (domain, config) => {
17
- const { baseUrlMapper } = config;
18
- const getCdnUrl = (path, instanceId) => `${domain}${baseUrlMapper(instanceId)}${path}`;
19
- return {
20
- getCdnUrl,
21
- getCdnFromS3Url: getCdnFromS3Url_util.getCdnFromS3UrlFactory({
22
- getCdnUrl,
23
- transformationQueries: twicpicsTransformationQueries,
24
- }),
25
- };
26
- };
27
-
28
- exports.twicpicsCdnCreator = twicpicsCdnCreator;
29
- exports.twicpicsTransformationQueries = twicpicsTransformationQueries;
30
- //# sourceMappingURL=twicpics.cdn-creator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"twicpics.cdn-creator.js","sources":["../../../src/cdn/cdn-creators/twicpics.cdn-creator.ts"],"sourcesContent":["import type {\n CreateCdn,\n GetCdnUrl,\n TransformationQueries,\n TwicpicsConfig,\n TwicpicsTransformation,\n} from '../types';\nimport { getCdnFromS3UrlFactory } from '../utils';\n\nexport const twicpicsTransformationQueries: TransformationQueries<\nTwicpicsTransformation\n> = (params) => {\n if (params.fit !== undefined) {\n return `?twic=v1/${params.fit}=${params.width}x${params.height}`;\n }\n if (params.width !== undefined) {\n return `?twic=v1/resize=${params.width}`;\n }\n return '';\n};\n\nexport const twicpicsCdnCreator: CreateCdn<TwicpicsConfig> = (\n domain,\n config,\n) => {\n const { baseUrlMapper } = config;\n const getCdnUrl: GetCdnUrl = (path, instanceId) => `${domain}${baseUrlMapper(instanceId)}${path}`;\n\n return {\n getCdnUrl,\n getCdnFromS3Url: getCdnFromS3UrlFactory({\n getCdnUrl,\n transformationQueries: twicpicsTransformationQueries,\n }),\n };\n};\n"],"names":["getCdnFromS3UrlFactory"],"mappings":";;;;;;AASa,MAAA,6BAA6B,GAEtC,CAAC,MAAM,KAAI;AACb,IAAA,IAAI,MAAM,CAAC,GAAG,KAAK,SAAS,EAAE;AAC5B,QAAA,OAAO,CAAY,SAAA,EAAA,MAAM,CAAC,GAAG,CAAI,CAAA,EAAA,MAAM,CAAC,KAAK,CAAI,CAAA,EAAA,MAAM,CAAC,MAAM,EAAE,CAAC;AAClE,KAAA;AACD,IAAA,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE;AAC9B,QAAA,OAAO,CAAmB,gBAAA,EAAA,MAAM,CAAC,KAAK,EAAE,CAAC;AAC1C,KAAA;AACD,IAAA,OAAO,EAAE,CAAC;AACZ,EAAE;MAEW,kBAAkB,GAA8B,CAC3D,MAAM,EACN,MAAM,KACJ;AACF,IAAA,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC;AACjC,IAAA,MAAM,SAAS,GAAc,CAAC,IAAI,EAAE,UAAU,KAAK,GAAG,MAAM,CAAA,EAAG,aAAa,CAAC,UAAU,CAAC,CAAG,EAAA,IAAI,EAAE,CAAC;IAElG,OAAO;QACL,SAAS;QACT,eAAe,EAAEA,2CAAsB,CAAC;YACtC,SAAS;AACT,YAAA,qBAAqB,EAAE,6BAA6B;SACrD,CAAC;KACH,CAAC;AACJ;;;;;"}
@@ -1,17 +0,0 @@
1
- export declare type Transformation = {
2
- width?: number;
3
- height?: number;
4
- };
5
- export declare type TwicpicsTransformation = Transformation & ({
6
- fit: 'crop' | 'contain';
7
- width: number;
8
- height: number;
9
- } | {
10
- fit?: undefined;
11
- width: number;
12
- height?: undefined;
13
- });
14
- export declare type ImgixTransformation = Transformation & {
15
- fit?: 'crop';
16
- };
17
- export declare type TransformationQueries<T extends Transformation> = (params: T) => string;
@@ -1,2 +0,0 @@
1
- export * from './extract-info-from-url.util';
2
- export * from './get-cdn-from-s3-url.util';
@@ -1,12 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var extractInfoFromUrl_util = require('./extract-info-from-url.util.js');
6
- var getCdnFromS3Url_util = require('./get-cdn-from-s3-url.util.js');
7
-
8
-
9
-
10
- exports.extractInfoFromUrl = extractInfoFromUrl_util.extractInfoFromUrl;
11
- exports.getCdnFromS3UrlFactory = getCdnFromS3Url_util.getCdnFromS3UrlFactory;
12
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}