sales-frontend-utils 0.0.58 → 0.0.60
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/dist/duplicate.cjs +36 -0
- package/dist/duplicate.cjs.map +1 -0
- package/dist/duplicate.d.cts +5 -0
- package/dist/duplicate.d.ts +5 -0
- package/dist/duplicate.js +32 -0
- package/dist/duplicate.js.map +1 -0
- package/dist/index.cjs +18 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +18 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/cookie-utils.cjs.map +1 -1
- package/dist/utils/cookie-utils.js.map +1 -1
- package/dist/utils/download-utils.cjs +38 -0
- package/dist/utils/download-utils.cjs.map +1 -1
- package/dist/utils/download-utils.js +38 -0
- package/dist/utils/download-utils.js.map +1 -1
- package/dist/utils/environment-utils.cjs +1 -1
- package/dist/utils/environment-utils.cjs.map +1 -1
- package/dist/utils/environment-utils.js +1 -1
- package/dist/utils/environment-utils.js.map +1 -1
- package/dist/utils/file-utils.cjs.map +1 -1
- package/dist/utils/file-utils.js.map +1 -1
- package/dist/utils/ga/index.cjs.map +1 -1
- package/dist/utils/ga/index.js.map +1 -1
- package/dist/utils/user-agent-utils.cjs.map +1 -1
- package/dist/utils/user-agent-utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/utils/environment-utils.ts
|
|
4
|
+
var isClient = () => {
|
|
5
|
+
try {
|
|
6
|
+
return !!window;
|
|
7
|
+
} catch {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/utils/cookie-utils.ts
|
|
13
|
+
var getCookie = (name) => {
|
|
14
|
+
if (!isClient()) {
|
|
15
|
+
return "";
|
|
16
|
+
}
|
|
17
|
+
if (typeof document === "undefined") {
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
const match = document.cookie.match(new RegExp(`(^|; *)${name}=([^;]*)`));
|
|
21
|
+
return match ? decodeURIComponent(match[2] || "") : "";
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/duplicate.ts
|
|
25
|
+
var filterNameCookieKey = "dsp-debug-mode-filter-name";
|
|
26
|
+
function isDebugByFilterName(name) {
|
|
27
|
+
const filterNames = getCookie(filterNameCookieKey)?.split(",");
|
|
28
|
+
return filterNames?.includes(name) || false;
|
|
29
|
+
}
|
|
30
|
+
var isDownloaderFilter = () => isDebugByFilterName("downloader");
|
|
31
|
+
|
|
32
|
+
exports.filterNameCookieKey = filterNameCookieKey;
|
|
33
|
+
exports.isDebugByFilterName = isDebugByFilterName;
|
|
34
|
+
exports.isDownloaderFilter = isDownloaderFilter;
|
|
35
|
+
//# sourceMappingURL=duplicate.cjs.map
|
|
36
|
+
//# sourceMappingURL=duplicate.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/environment-utils.ts","../src/utils/cookie-utils.ts","../src/duplicate.ts"],"names":[],"mappings":";;;AA4DO,IAAM,WAAW,MAAM;AAC5B,EAAI,IAAA;AACF,IAAA,OAAO,CAAC,CAAC,MAAA;AAAA,GACH,CAAA,MAAA;AACN,IAAO,OAAA,KAAA;AAAA;AAEX,CAAA;;;AChEO,IAAM,SAAA,GAAY,CAAC,IAAyB,KAAA;AACjD,EAAI,IAAA,CAAC,UAAY,EAAA;AACf,IAAO,OAAA,EAAA;AAAA;AAET,EAAI,IAAA,OAAO,aAAa,WAAa,EAAA;AACnC,IAAO,OAAA,EAAA;AAAA;AAET,EAAM,MAAA,KAAA,GAAQ,SAAS,MAAO,CAAA,KAAA,CAAM,IAAI,MAAO,CAAA,CAAA,OAAA,EAAU,IAAI,CAAA,QAAA,CAAU,CAAC,CAAA;AAExE,EAAA,OAAO,QAAQ,kBAAmB,CAAA,KAAA,CAAM,CAAC,CAAA,IAAK,EAAE,CAAI,GAAA,EAAA;AACtD,CAAA;;;ACTO,IAAM,mBAAsB,GAAA;AAC5B,SAAS,oBAAoB,IAAuB,EAAA;AACvD,EAAA,MAAM,WAAc,GAAA,SAAA,CAAU,mBAAmB,CAAA,EAAG,MAAM,GAAG,CAAA;AAE7D,EAAO,OAAA,WAAA,EAAa,QAAS,CAAA,IAAI,CAAK,IAAA,KAAA;AAE1C;AAEa,IAAA,kBAAA,GAAqB,MAAM,mBAAA,CAAoB,YAAY","file":"duplicate.cjs","sourcesContent":["import { getCookie } from './cookie-utils';\n\n/**\n * 호스트명에서 서브도메인을 추출합니다.\n * @param hostname 호스트명\n * @returns 서브도메인 (예: nxl-dsp-dev)\n */\nexport const getSubdomain = (hostname: string): string => {\n if (!hostname || hostname === 'localhost' || hostname === '127.0.0.1') {\n return '';\n }\n\n const parts = hostname.split('.');\n\n // 최소 3개 부분이 있어야 서브도메인 존재 (subdomain.domain.com)\n if (parts.length < 3) {\n return '';\n }\n\n // 첫 번째 부분이 서브도메인\n return parts[0] ?? '';\n};\n\n/**\n * 호스트명을 기반으로 환경을 판단합니다.\n * @param hostname 호스트명\n * @returns 환경 구분 문자열 ('local' | 'dev' | 'stg' | 'prd')\n */\nexport const getEnvironmentFromHostname = (hostname: string): 'local' | 'dev' | 'stg' | 'prd' => {\n if (isClient()) {\n const debugModeEnv = getCookie('dsp-debug-mode-env')?.toLowerCase();\n if (debugModeEnv) {\n return debugModeEnv as 'local' | 'dev' | 'stg' | 'prd';\n }\n }\n const subDomain = getSubdomain(hostname);\n\n // localhost 판단\n if (hostname === 'localhost' || hostname === '127.0.0.1' || hostname.startsWith('localhost')) {\n return 'local';\n }\n\n // dev 환경 판단\n if (subDomain.includes(`dev`)) {\n return 'dev';\n }\n\n // stg 환경 판단\n if (subDomain.includes('stg')) {\n return 'stg';\n }\n\n // 기본 운영\n return 'prd';\n};\n\n/**\n * @see https://github.com/storybookjs/storybook/issues/32028#issuecomment-3298982086\n * @note 스토리북에서 버그로인해 window객체를 정상적으로 탐지하지 못하는 이슈우회\n */\nexport const isClient = () => {\n try {\n return !!window;\n } catch {\n return false;\n }\n};\n\n// window.isStorybookEnv 접근을 위한 타입캐스팅\ndeclare const window: Window & { isStorybookEnv?: boolean };\n/**\n * 현재 실행 환경이 Storybook인지 확인하는 함수\n *\n * 사용 전, `viteFinal` 설정에서 `window.isStorybookEnv`를 `true`로 정의해야 정상 동작합니다.\n *\n * 예시:\n * ```ts\n * const config: StorybookConfig = {\n * viteFinal: (config) => {\n * // window.isStorybookEnv를 true로 설정 (boolean 값으로 처리됨)\n * config.define = {\n * ...config.define,\n * 'window.isStorybookEnv': 'true',\n * };\n *\n * return config;\n * },\n * };\n * ```\n */\nexport const isStorybookEnv = () => {\n try {\n return window.isStorybookEnv === true;\n } catch {\n // window가 존재하지 않는 등 예외 상황에서는 false 반환\n return false;\n }\n};\n\n/**\n * 현재 업무구분 코드 구하기\n * 원칙: pathname의 첫 번째가 업무구분코드를 사용할 경우 해당 값을 반환\n * @returns\n */\nexport const getBusinessWorkDivisionCode = (pathname?: string) => {\n if (pathname) {\n return pathname.split('/')[1] ?? '';\n }\n\n return location.pathname.split('/')[1] ?? '';\n};\n\n/**\n * @description storybook에서 동작을 고려하여 수정한 버전\n * @returns\n */\nexport const getServicePath = () => {\n if (typeof window.isStorybookEnv === 'boolean') {\n return '';\n } else {\n return `/${getBusinessWorkDivisionCode()}`;\n }\n};\n\n/**\n * 환경에 맞는 API 호스트명을 반환합니다.\n * 호스트명을 강제하고 싶으면 두 번째 파라미터로 넘기세요.\n * @param currentHostname\n * @param forceApiHostName\n * @returns\n */\n\nexport const getApiHostNameFromEnvironment = (currentHostname: string, forceApiHostName?: string) => {\n if (forceApiHostName) {\n return forceApiHostName;\n }\n\n const environment = getEnvironmentFromHostname(currentHostname);\n\n switch (environment) {\n case 'dev':\n return `https://nxl-dsp-dev.hanwhalife.com`;\n\n case 'local':\n case 'stg':\n return `https://nxl-dsp-stg.hanwhalife.com`;\n\n case 'prd':\n return `https://nxl-dsp.hanwhalife.com`;\n\n default:\n console.warn('DSP API environment is not defined');\n\n return '';\n }\n};\n\n/**\n * 환경에 맞는 CDN 호스트명을 반환합니다.\n * 호스트명을 강제하고 싶으면 두 번째 파라미터로 넘기세요.\n * @param currentHostname\n * @param forceApiHostName\n * @returns\n */\nexport const getCdnHostNameFromEnvironment = (currentHostname: string, forceApiHostName?: string) => {\n if (!isClient()) {\n return '';\n }\n\n if (forceApiHostName) {\n return forceApiHostName;\n }\n\n const environment = getEnvironmentFromHostname(currentHostname);\n\n switch (environment) {\n case 'dev':\n return `https://dev-dsp-static.hanwhalife.com`;\n\n case 'local':\n case 'stg':\n return `https://stg-dsp-static.hanwhalife.com`;\n\n case 'prd':\n return `https://dsp-static.hanwhalife.com`;\n\n default:\n console.warn('DSP environment is not defined');\n\n return '';\n }\n};\n\n/**\n * @description\n * 환경에 맞는 비정형PI 호스트명을 반환합니다.\n * @param serviceCode dea,dis,dcm\n * @param hostname window.location.hostname\n * @returns\n */\nexport const getDudApiBasePathFromEnvironment = (hostname: string, servicePath: string) => {\n const environment = getEnvironmentFromHostname(hostname);\n\n switch (environment) {\n /**\n * local에서 호출시, rewrite동작을 위해 상대주소를 호출합니다.\n * (cors이슈 해결을 위해 필수)\n */\n case 'local':\n return `${servicePath}/api/dud`;\n /**\n * local 이 아닌 환경에서는 전체주소를 호출합니다.\n */\n case 'dev':\n return `https://dsp-dud-dev.hanwhalife.com:10101/api`;\n\n case 'stg':\n return `https://dsp-dud-stg.hanwhalife.com:10102/api`;\n\n case 'prd':\n return `https://dsp-dud.hanwhalife.com/api`;\n\n default:\n console.warn('DUD API environment is not defined');\n\n return '';\n }\n};\n\n/**\n * @description\n * 환경에 맞는 Dsp 호스트명을 반환합니다.\n * client side에서 사용하는 함수입니다.\n * @param serviceCodeTo dea,dis 같은 api서버명\n * @param hostname window.location.hostname\n * @returns\n */\nexport const getDspApiBasePathFromEnvironment = (serviceCodeTo: string, hostname?: string) => {\n if (!isClient()) {\n return '';\n }\n const environment = getEnvironmentFromHostname(hostname || location.hostname);\n\n switch (environment) {\n /**\n * local에서 호출시, rewrite동작을 위해 상대주소를 호출합니다.\n * (cors이슈 해결을 위해 필수)\n */\n case 'local':\n return `${getServicePath()}/api/${serviceCodeTo}`;\n /**\n * local 이 아닌 환경에서는 전체주소를 호출합니다.\n */\n case 'dev':\n return `https://nxl-dsp-dev.hanwhalife.com/api/${serviceCodeTo}`;\n\n case 'stg':\n return `https://nxl-dsp-stg.hanwhalife.com/api/${serviceCodeTo}`;\n\n case 'prd':\n return `https://nxl-dsp.hanwhalife.com/api/${serviceCodeTo}`;\n\n default:\n console.warn('DSP API environment is not defined');\n\n return '';\n }\n};\n\n/**\n * @description\n * 환경에 맞는 NLC 호스트명을 반환합니다.\n * client side에서 사용하는 함수입니다.\n * @param hostname window.location.hostname\n * @returns\n */\nexport const getNlcHostFromEnvironment = (hostname?: string) => {\n if (!isClient()) {\n return '';\n }\n\n const environment = getEnvironmentFromHostname(hostname || location.hostname);\n\n switch (environment) {\n case 'local':\n return `https://nxl-nlc-stg.hanwhalife.com`;\n\n case 'dev':\n return `https://nxl-nlc-dev.hanwhalife.com`;\n\n case 'stg':\n return `https://nxl-nlc-stg.hanwhalife.com`;\n\n case 'prd':\n return `https://nxl-nlc.hanwhalife.com`;\n\n default:\n console.warn('NLC environment is not defined');\n\n return '';\n }\n};\n","import { isClient } from \"./environment-utils\";\n\nexport const getCookie = (name: string): string => {\n if (!isClient()) {\n return '';\n }\n if (typeof document === 'undefined') {\n return '';\n }\n const match = document.cookie.match(new RegExp(`(^|; *)${name}=([^;]*)`));\n\n return match ? decodeURIComponent(match[2] || '') : '';\n};\n\nexport const setCookie = (\n name: string,\n value: string,\n options: {\n expires?: number | Date; // number of days\n path?: string;\n domain?: string;\n secure?: boolean;\n } = {}\n): void => {\n if (!isClient()) {\n return;\n }\n if (typeof document === 'undefined') {\n return;\n }\n\n let cookieString = `${name}=${encodeURIComponent(value)}`;\n\n if (options.expires) {\n let expiresDate: Date;\n if (typeof options.expires === 'number') {\n expiresDate = new Date();\n expiresDate.setDate(expiresDate.getDate() + options.expires);\n } else {\n expiresDate = options.expires;\n }\n cookieString += `; expires=${expiresDate.toUTCString()}`;\n }\n\n cookieString += `; path=${options.path || '/'}`;\n\n if (options.domain) {\n cookieString += `; domain=${options.domain}`;\n }\n\n if (options.secure) {\n cookieString += '; secure';\n }\n\n document.cookie = cookieString;\n};\n\nexport const deleteCookie = (name: string, options: { path?: string; domain?: string } = {}): void => {\n if (!isClient()) {\n return;\n }\n setCookie(name, '', { ...options, expires: -1 });\n};\n","import { getCookie } from \"./utils/cookie-utils\";\n\n//중복코드지만, 패키지 의존성을 피하기위해서 별도로 재작성한 코드들입니다. \nexport const filterNameCookieKey = 'dsp-debug-mode-filter-name';\nexport function isDebugByFilterName(name: string): boolean {\n const filterNames = getCookie(filterNameCookieKey)?.split(',');\n\n return filterNames?.includes(name) || false;\n\n}\n\nexport const isDownloaderFilter = () => isDebugByFilterName('downloader');"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/utils/environment-utils.ts
|
|
2
|
+
var isClient = () => {
|
|
3
|
+
try {
|
|
4
|
+
return !!window;
|
|
5
|
+
} catch {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// src/utils/cookie-utils.ts
|
|
11
|
+
var getCookie = (name) => {
|
|
12
|
+
if (!isClient()) {
|
|
13
|
+
return "";
|
|
14
|
+
}
|
|
15
|
+
if (typeof document === "undefined") {
|
|
16
|
+
return "";
|
|
17
|
+
}
|
|
18
|
+
const match = document.cookie.match(new RegExp(`(^|; *)${name}=([^;]*)`));
|
|
19
|
+
return match ? decodeURIComponent(match[2] || "") : "";
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/duplicate.ts
|
|
23
|
+
var filterNameCookieKey = "dsp-debug-mode-filter-name";
|
|
24
|
+
function isDebugByFilterName(name) {
|
|
25
|
+
const filterNames = getCookie(filterNameCookieKey)?.split(",");
|
|
26
|
+
return filterNames?.includes(name) || false;
|
|
27
|
+
}
|
|
28
|
+
var isDownloaderFilter = () => isDebugByFilterName("downloader");
|
|
29
|
+
|
|
30
|
+
export { filterNameCookieKey, isDebugByFilterName, isDownloaderFilter };
|
|
31
|
+
//# sourceMappingURL=duplicate.js.map
|
|
32
|
+
//# sourceMappingURL=duplicate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/environment-utils.ts","../src/utils/cookie-utils.ts","../src/duplicate.ts"],"names":[],"mappings":";AA4DO,IAAM,WAAW,MAAM;AAC5B,EAAI,IAAA;AACF,IAAA,OAAO,CAAC,CAAC,MAAA;AAAA,GACH,CAAA,MAAA;AACN,IAAO,OAAA,KAAA;AAAA;AAEX,CAAA;;;AChEO,IAAM,SAAA,GAAY,CAAC,IAAyB,KAAA;AACjD,EAAI,IAAA,CAAC,UAAY,EAAA;AACf,IAAO,OAAA,EAAA;AAAA;AAET,EAAI,IAAA,OAAO,aAAa,WAAa,EAAA;AACnC,IAAO,OAAA,EAAA;AAAA;AAET,EAAM,MAAA,KAAA,GAAQ,SAAS,MAAO,CAAA,KAAA,CAAM,IAAI,MAAO,CAAA,CAAA,OAAA,EAAU,IAAI,CAAA,QAAA,CAAU,CAAC,CAAA;AAExE,EAAA,OAAO,QAAQ,kBAAmB,CAAA,KAAA,CAAM,CAAC,CAAA,IAAK,EAAE,CAAI,GAAA,EAAA;AACtD,CAAA;;;ACTO,IAAM,mBAAsB,GAAA;AAC5B,SAAS,oBAAoB,IAAuB,EAAA;AACvD,EAAA,MAAM,WAAc,GAAA,SAAA,CAAU,mBAAmB,CAAA,EAAG,MAAM,GAAG,CAAA;AAE7D,EAAO,OAAA,WAAA,EAAa,QAAS,CAAA,IAAI,CAAK,IAAA,KAAA;AAE1C;AAEa,IAAA,kBAAA,GAAqB,MAAM,mBAAA,CAAoB,YAAY","file":"duplicate.js","sourcesContent":["import { getCookie } from './cookie-utils';\n\n/**\n * 호스트명에서 서브도메인을 추출합니다.\n * @param hostname 호스트명\n * @returns 서브도메인 (예: nxl-dsp-dev)\n */\nexport const getSubdomain = (hostname: string): string => {\n if (!hostname || hostname === 'localhost' || hostname === '127.0.0.1') {\n return '';\n }\n\n const parts = hostname.split('.');\n\n // 최소 3개 부분이 있어야 서브도메인 존재 (subdomain.domain.com)\n if (parts.length < 3) {\n return '';\n }\n\n // 첫 번째 부분이 서브도메인\n return parts[0] ?? '';\n};\n\n/**\n * 호스트명을 기반으로 환경을 판단합니다.\n * @param hostname 호스트명\n * @returns 환경 구분 문자열 ('local' | 'dev' | 'stg' | 'prd')\n */\nexport const getEnvironmentFromHostname = (hostname: string): 'local' | 'dev' | 'stg' | 'prd' => {\n if (isClient()) {\n const debugModeEnv = getCookie('dsp-debug-mode-env')?.toLowerCase();\n if (debugModeEnv) {\n return debugModeEnv as 'local' | 'dev' | 'stg' | 'prd';\n }\n }\n const subDomain = getSubdomain(hostname);\n\n // localhost 판단\n if (hostname === 'localhost' || hostname === '127.0.0.1' || hostname.startsWith('localhost')) {\n return 'local';\n }\n\n // dev 환경 판단\n if (subDomain.includes(`dev`)) {\n return 'dev';\n }\n\n // stg 환경 판단\n if (subDomain.includes('stg')) {\n return 'stg';\n }\n\n // 기본 운영\n return 'prd';\n};\n\n/**\n * @see https://github.com/storybookjs/storybook/issues/32028#issuecomment-3298982086\n * @note 스토리북에서 버그로인해 window객체를 정상적으로 탐지하지 못하는 이슈우회\n */\nexport const isClient = () => {\n try {\n return !!window;\n } catch {\n return false;\n }\n};\n\n// window.isStorybookEnv 접근을 위한 타입캐스팅\ndeclare const window: Window & { isStorybookEnv?: boolean };\n/**\n * 현재 실행 환경이 Storybook인지 확인하는 함수\n *\n * 사용 전, `viteFinal` 설정에서 `window.isStorybookEnv`를 `true`로 정의해야 정상 동작합니다.\n *\n * 예시:\n * ```ts\n * const config: StorybookConfig = {\n * viteFinal: (config) => {\n * // window.isStorybookEnv를 true로 설정 (boolean 값으로 처리됨)\n * config.define = {\n * ...config.define,\n * 'window.isStorybookEnv': 'true',\n * };\n *\n * return config;\n * },\n * };\n * ```\n */\nexport const isStorybookEnv = () => {\n try {\n return window.isStorybookEnv === true;\n } catch {\n // window가 존재하지 않는 등 예외 상황에서는 false 반환\n return false;\n }\n};\n\n/**\n * 현재 업무구분 코드 구하기\n * 원칙: pathname의 첫 번째가 업무구분코드를 사용할 경우 해당 값을 반환\n * @returns\n */\nexport const getBusinessWorkDivisionCode = (pathname?: string) => {\n if (pathname) {\n return pathname.split('/')[1] ?? '';\n }\n\n return location.pathname.split('/')[1] ?? '';\n};\n\n/**\n * @description storybook에서 동작을 고려하여 수정한 버전\n * @returns\n */\nexport const getServicePath = () => {\n if (typeof window.isStorybookEnv === 'boolean') {\n return '';\n } else {\n return `/${getBusinessWorkDivisionCode()}`;\n }\n};\n\n/**\n * 환경에 맞는 API 호스트명을 반환합니다.\n * 호스트명을 강제하고 싶으면 두 번째 파라미터로 넘기세요.\n * @param currentHostname\n * @param forceApiHostName\n * @returns\n */\n\nexport const getApiHostNameFromEnvironment = (currentHostname: string, forceApiHostName?: string) => {\n if (forceApiHostName) {\n return forceApiHostName;\n }\n\n const environment = getEnvironmentFromHostname(currentHostname);\n\n switch (environment) {\n case 'dev':\n return `https://nxl-dsp-dev.hanwhalife.com`;\n\n case 'local':\n case 'stg':\n return `https://nxl-dsp-stg.hanwhalife.com`;\n\n case 'prd':\n return `https://nxl-dsp.hanwhalife.com`;\n\n default:\n console.warn('DSP API environment is not defined');\n\n return '';\n }\n};\n\n/**\n * 환경에 맞는 CDN 호스트명을 반환합니다.\n * 호스트명을 강제하고 싶으면 두 번째 파라미터로 넘기세요.\n * @param currentHostname\n * @param forceApiHostName\n * @returns\n */\nexport const getCdnHostNameFromEnvironment = (currentHostname: string, forceApiHostName?: string) => {\n if (!isClient()) {\n return '';\n }\n\n if (forceApiHostName) {\n return forceApiHostName;\n }\n\n const environment = getEnvironmentFromHostname(currentHostname);\n\n switch (environment) {\n case 'dev':\n return `https://dev-dsp-static.hanwhalife.com`;\n\n case 'local':\n case 'stg':\n return `https://stg-dsp-static.hanwhalife.com`;\n\n case 'prd':\n return `https://dsp-static.hanwhalife.com`;\n\n default:\n console.warn('DSP environment is not defined');\n\n return '';\n }\n};\n\n/**\n * @description\n * 환경에 맞는 비정형PI 호스트명을 반환합니다.\n * @param serviceCode dea,dis,dcm\n * @param hostname window.location.hostname\n * @returns\n */\nexport const getDudApiBasePathFromEnvironment = (hostname: string, servicePath: string) => {\n const environment = getEnvironmentFromHostname(hostname);\n\n switch (environment) {\n /**\n * local에서 호출시, rewrite동작을 위해 상대주소를 호출합니다.\n * (cors이슈 해결을 위해 필수)\n */\n case 'local':\n return `${servicePath}/api/dud`;\n /**\n * local 이 아닌 환경에서는 전체주소를 호출합니다.\n */\n case 'dev':\n return `https://dsp-dud-dev.hanwhalife.com:10101/api`;\n\n case 'stg':\n return `https://dsp-dud-stg.hanwhalife.com:10102/api`;\n\n case 'prd':\n return `https://dsp-dud.hanwhalife.com/api`;\n\n default:\n console.warn('DUD API environment is not defined');\n\n return '';\n }\n};\n\n/**\n * @description\n * 환경에 맞는 Dsp 호스트명을 반환합니다.\n * client side에서 사용하는 함수입니다.\n * @param serviceCodeTo dea,dis 같은 api서버명\n * @param hostname window.location.hostname\n * @returns\n */\nexport const getDspApiBasePathFromEnvironment = (serviceCodeTo: string, hostname?: string) => {\n if (!isClient()) {\n return '';\n }\n const environment = getEnvironmentFromHostname(hostname || location.hostname);\n\n switch (environment) {\n /**\n * local에서 호출시, rewrite동작을 위해 상대주소를 호출합니다.\n * (cors이슈 해결을 위해 필수)\n */\n case 'local':\n return `${getServicePath()}/api/${serviceCodeTo}`;\n /**\n * local 이 아닌 환경에서는 전체주소를 호출합니다.\n */\n case 'dev':\n return `https://nxl-dsp-dev.hanwhalife.com/api/${serviceCodeTo}`;\n\n case 'stg':\n return `https://nxl-dsp-stg.hanwhalife.com/api/${serviceCodeTo}`;\n\n case 'prd':\n return `https://nxl-dsp.hanwhalife.com/api/${serviceCodeTo}`;\n\n default:\n console.warn('DSP API environment is not defined');\n\n return '';\n }\n};\n\n/**\n * @description\n * 환경에 맞는 NLC 호스트명을 반환합니다.\n * client side에서 사용하는 함수입니다.\n * @param hostname window.location.hostname\n * @returns\n */\nexport const getNlcHostFromEnvironment = (hostname?: string) => {\n if (!isClient()) {\n return '';\n }\n\n const environment = getEnvironmentFromHostname(hostname || location.hostname);\n\n switch (environment) {\n case 'local':\n return `https://nxl-nlc-stg.hanwhalife.com`;\n\n case 'dev':\n return `https://nxl-nlc-dev.hanwhalife.com`;\n\n case 'stg':\n return `https://nxl-nlc-stg.hanwhalife.com`;\n\n case 'prd':\n return `https://nxl-nlc.hanwhalife.com`;\n\n default:\n console.warn('NLC environment is not defined');\n\n return '';\n }\n};\n","import { isClient } from \"./environment-utils\";\n\nexport const getCookie = (name: string): string => {\n if (!isClient()) {\n return '';\n }\n if (typeof document === 'undefined') {\n return '';\n }\n const match = document.cookie.match(new RegExp(`(^|; *)${name}=([^;]*)`));\n\n return match ? decodeURIComponent(match[2] || '') : '';\n};\n\nexport const setCookie = (\n name: string,\n value: string,\n options: {\n expires?: number | Date; // number of days\n path?: string;\n domain?: string;\n secure?: boolean;\n } = {}\n): void => {\n if (!isClient()) {\n return;\n }\n if (typeof document === 'undefined') {\n return;\n }\n\n let cookieString = `${name}=${encodeURIComponent(value)}`;\n\n if (options.expires) {\n let expiresDate: Date;\n if (typeof options.expires === 'number') {\n expiresDate = new Date();\n expiresDate.setDate(expiresDate.getDate() + options.expires);\n } else {\n expiresDate = options.expires;\n }\n cookieString += `; expires=${expiresDate.toUTCString()}`;\n }\n\n cookieString += `; path=${options.path || '/'}`;\n\n if (options.domain) {\n cookieString += `; domain=${options.domain}`;\n }\n\n if (options.secure) {\n cookieString += '; secure';\n }\n\n document.cookie = cookieString;\n};\n\nexport const deleteCookie = (name: string, options: { path?: string; domain?: string } = {}): void => {\n if (!isClient()) {\n return;\n }\n setCookie(name, '', { ...options, expires: -1 });\n};\n","import { getCookie } from \"./utils/cookie-utils\";\n\n//중복코드지만, 패키지 의존성을 피하기위해서 별도로 재작성한 코드들입니다. \nexport const filterNameCookieKey = 'dsp-debug-mode-filter-name';\nexport function isDebugByFilterName(name: string): boolean {\n const filterNames = getCookie(filterNameCookieKey)?.split(',');\n\n return filterNames?.includes(name) || false;\n\n}\n\nexport const isDownloaderFilter = () => isDebugByFilterName('downloader');"]}
|
package/dist/index.cjs
CHANGED
|
@@ -181,7 +181,7 @@ var getCdnHostNameFromEnvironment = (currentHostname, forceApiHostName) => {
|
|
|
181
181
|
case "stg":
|
|
182
182
|
return `https://stg-dsp-static.hanwhalife.com`;
|
|
183
183
|
case "prd":
|
|
184
|
-
return `https://dsp-static.hanwhalife.com
|
|
184
|
+
return `https://dsp-static.hanwhalife.com`;
|
|
185
185
|
default:
|
|
186
186
|
console.warn("DSP environment is not defined");
|
|
187
187
|
return "";
|
|
@@ -1192,8 +1192,19 @@ var getGenderName = (genderCode) => {
|
|
|
1192
1192
|
return genderCode ? GENDER_LABEL_MAP[genderCode] : "";
|
|
1193
1193
|
};
|
|
1194
1194
|
|
|
1195
|
+
// src/duplicate.ts
|
|
1196
|
+
var filterNameCookieKey = "dsp-debug-mode-filter-name";
|
|
1197
|
+
function isDebugByFilterName(name) {
|
|
1198
|
+
const filterNames = getCookie(filterNameCookieKey)?.split(",");
|
|
1199
|
+
return filterNames?.includes(name) || false;
|
|
1200
|
+
}
|
|
1201
|
+
var isDownloaderFilter = () => isDebugByFilterName("downloader");
|
|
1202
|
+
|
|
1195
1203
|
// src/utils/download-utils.ts
|
|
1196
1204
|
var getBlobUrl = async (url) => {
|
|
1205
|
+
if (isDownloaderFilter()) {
|
|
1206
|
+
alert(`[debug filter:downloader] getBlobUrl \uD638\uCD9C- ${url}`);
|
|
1207
|
+
}
|
|
1197
1208
|
let downloadUrl = "";
|
|
1198
1209
|
if (url.startsWith("http")) {
|
|
1199
1210
|
const response = await fetch(url);
|
|
@@ -1215,6 +1226,9 @@ var downloadFromNewWindow = async (url, fileName) => {
|
|
|
1215
1226
|
try {
|
|
1216
1227
|
const aTag = document.createElement("a");
|
|
1217
1228
|
const downloadUrl = await getBlobUrl(url);
|
|
1229
|
+
if (isDownloaderFilter()) {
|
|
1230
|
+
alert(`[debug filter:downloader] downloadFromNewWindow \uD638\uCD9C- ${downloadUrl}`);
|
|
1231
|
+
}
|
|
1218
1232
|
aTag.href = downloadUrl;
|
|
1219
1233
|
aTag.download = fileName;
|
|
1220
1234
|
const newWin = window.open();
|
|
@@ -1231,6 +1245,9 @@ var downloadFromCurrentWindow = async (url, fileName) => {
|
|
|
1231
1245
|
try {
|
|
1232
1246
|
const a = document.createElement("a");
|
|
1233
1247
|
const downloadUrl = await getBlobUrl(url);
|
|
1248
|
+
if (isDownloaderFilter()) {
|
|
1249
|
+
alert(`[debug filter:downloader] downloadFromCurrentWindow \uD638\uCD9C- ${downloadUrl}`);
|
|
1250
|
+
}
|
|
1234
1251
|
a.href = downloadUrl;
|
|
1235
1252
|
a.download = fileName;
|
|
1236
1253
|
document.body.appendChild(a);
|