sales-frontend-bridge 0.0.21 → 0.0.23

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/index.cjs CHANGED
@@ -1450,6 +1450,9 @@ var IframeBridgeCore = class extends CommonBridgeCore {
1450
1450
  super();
1451
1451
  __publicField(this, "pendingPromises", /* @__PURE__ */ new Map());
1452
1452
  __publicField(this, "responseHandler");
1453
+ if (!salesFrontendUtils.isClient()) {
1454
+ return;
1455
+ }
1453
1456
  this.initializeIframeBridge();
1454
1457
  }
1455
1458
  /**
@@ -1575,19 +1578,35 @@ var IframeBridge = class extends CommonBridge {
1575
1578
  // TODO: 필요 플러그인들 추가
1576
1579
  };
1577
1580
  var NativeBridgeCore = class extends CommonBridgeCore {
1578
- constructor() {
1581
+ constructor(callBridgeName = "n2Bridge", promiseHandleName = "n2bridge") {
1579
1582
  super();
1580
- this.initializeWindowBridge();
1583
+ __publicField(this, "promiseHandleName");
1584
+ __publicField(this, "callBridgeName");
1585
+ this.callBridgeName = callBridgeName;
1586
+ this.promiseHandleName = promiseHandleName;
1587
+ this.initializeWindowOzBridge();
1581
1588
  }
1582
1589
  /**
1583
- * 네이티브 통신을 위해 window.n2bridge 객체 초기화
1590
+ * Promise 관리용 브릿지 객체 가져오기 (window.n2bridge)
1591
+ */
1592
+ getPromiseHandleBridge() {
1593
+ return window[this.promiseHandleName];
1594
+ }
1595
+ /**
1596
+ * 앱 호출용 브릿지 객체 가져오기 (window.n2Bridge)
1597
+ */
1598
+ getCallBridge() {
1599
+ return window[this.callBridgeName];
1600
+ }
1601
+ /**
1602
+ * 네이티브 통신을 위해 window.n2OzBridge 객체 초기화
1584
1603
  */
1585
- initializeWindowBridge() {
1604
+ initializeWindowOzBridge() {
1586
1605
  if (!salesFrontendUtils.isClient()) {
1587
1606
  return;
1588
1607
  }
1589
- if (!window.n2bridge) {
1590
- window.n2bridge = {
1608
+ if (!window[this.promiseHandleName]) {
1609
+ window[this.promiseHandleName] = {
1591
1610
  promises: {},
1592
1611
  resolvePromise: () => {
1593
1612
  },
@@ -1597,11 +1616,11 @@ var NativeBridgeCore = class extends CommonBridgeCore {
1597
1616
  }
1598
1617
  };
1599
1618
  }
1600
- window.n2bridge.resolvePromise = this.createResolvePromiseHandler();
1601
- window.n2bridge.finallyResolvePromise = this.createFinallyResolvePromiseHandler();
1602
- window.n2bridge.callFromNative = this.createCallFromNativeHandler();
1619
+ const bridge = this.getPromiseHandleBridge();
1620
+ bridge.resolvePromise = this.createResolvePromiseHandler();
1621
+ bridge.finallyResolvePromise = this.createFinallyResolvePromiseHandler();
1603
1622
  if (salesFrontendUtils.isStorybookEnv() && window.parent) {
1604
- window.parent.n2bridge = window.n2bridge;
1623
+ window.parent[this.promiseHandleName] = bridge;
1605
1624
  window.parent.dispatchEvent = (...args) => window.dispatchEvent.apply(null, args);
1606
1625
  }
1607
1626
  }
@@ -1612,7 +1631,8 @@ var NativeBridgeCore = class extends CommonBridgeCore {
1612
1631
  createResolvePromiseHandler() {
1613
1632
  return (promiseId, data, error) => {
1614
1633
  console.log("[NativeBridgeCore resolvePromise]::", promiseId, data, error);
1615
- const promise = window.n2bridge.promises[promiseId];
1634
+ const bridge = this.getPromiseHandleBridge();
1635
+ const promise = bridge.promises[promiseId];
1616
1636
  if (!promise) {
1617
1637
  console.error("[NativeBridgeCore resolvePromise] Promise not found::", promiseId);
1618
1638
  return;
@@ -1623,10 +1643,6 @@ var NativeBridgeCore = class extends CommonBridgeCore {
1623
1643
  this.cleanupPromise(promiseId);
1624
1644
  return;
1625
1645
  }
1626
- if (promise.retain) {
1627
- promise.retain(data);
1628
- return;
1629
- }
1630
1646
  promise.resolve(data);
1631
1647
  this.cleanupPromise(promiseId);
1632
1648
  } catch (err) {
@@ -1641,7 +1657,8 @@ var NativeBridgeCore = class extends CommonBridgeCore {
1641
1657
  */
1642
1658
  createFinallyResolvePromiseHandler() {
1643
1659
  return (promiseId, data, error) => {
1644
- const promise = window.n2bridge.promises[promiseId];
1660
+ const bridge = this.getPromiseHandleBridge();
1661
+ const promise = bridge.promises[promiseId];
1645
1662
  if (!promise) {
1646
1663
  console.error("[NativeBridgeCore resolvePromise] Promise not found::", promiseId);
1647
1664
  return;
@@ -1652,10 +1669,6 @@ var NativeBridgeCore = class extends CommonBridgeCore {
1652
1669
  this.cleanupPromise(promiseId);
1653
1670
  return;
1654
1671
  }
1655
- if (promise.retain) {
1656
- promise.retain(data);
1657
- return;
1658
- }
1659
1672
  promise.resolve(data);
1660
1673
  this.cleanupPromise(promiseId);
1661
1674
  } catch (err) {
@@ -1664,55 +1677,40 @@ var NativeBridgeCore = class extends CommonBridgeCore {
1664
1677
  }
1665
1678
  };
1666
1679
  }
1667
- /**
1668
- * Native 에서 웹으로 호출하는 함수
1669
- * TODO: 필요시 추가 코딩
1670
- * @returns
1671
- */
1672
- createCallFromNativeHandler() {
1673
- return (jsonStr) => {
1674
- try {
1675
- const command = JSON.parse(jsonStr);
1676
- console.log("[NativeBridgeCore callFromNative]::", command);
1677
- } catch (error) {
1678
- console.error("[NativeBridgeCore callFromNative] parse error::", error);
1679
- }
1680
- };
1681
- }
1682
1680
  /**
1683
1681
  * 네이티브 통신
1684
1682
  * @param action
1685
1683
  * @param options
1686
1684
  * @returns
1687
1685
  */
1688
- async callToTarget(action, options) {
1689
- const { retainCallback: retain, ...commandOptions } = options || {};
1686
+ async callToTarget(action, option) {
1690
1687
  return new Promise((resolve, reject) => {
1691
1688
  const promiseId = `${action}_${this.generatePromiseId()}`;
1692
1689
  console.log("[NativeBridgeCore callToNative] promiseId::", promiseId);
1693
- window.n2bridge.promises[promiseId] = {
1690
+ const bridge = this.getPromiseHandleBridge();
1691
+ bridge.promises[promiseId] = {
1694
1692
  resolve: (value) => {
1695
1693
  resolve(value);
1696
1694
  },
1697
1695
  reject: (reason) => {
1698
1696
  reject(reason);
1699
- },
1700
- retain
1697
+ }
1701
1698
  };
1702
1699
  try {
1703
1700
  const command = {
1704
1701
  action,
1705
1702
  promiseId,
1706
- option: commandOptions
1703
+ option
1707
1704
  };
1708
1705
  console.log("[NativeBridgeCore callToNative] command::", command);
1709
1706
  const platform = salesFrontendUtils.getDspExecutionEnvironment();
1710
1707
  if (platform === "android-webview") {
1711
- window.n2Bridge?.callFromWeb?.(JSON.stringify(command));
1708
+ const callBridge = this.getCallBridge();
1709
+ callBridge?.callFromWeb?.(JSON.stringify(command));
1712
1710
  return;
1713
1711
  }
1714
1712
  if (platform === "ios-webview") {
1715
- window.webkit?.messageHandlers?.n2Bridge?.postMessage(JSON.stringify(command));
1713
+ window.webkit?.messageHandlers?.[this.callBridgeName]?.postMessage(JSON.stringify(command));
1716
1714
  return;
1717
1715
  }
1718
1716
  console.warn(
@@ -1732,7 +1730,8 @@ var NativeBridgeCore = class extends CommonBridgeCore {
1732
1730
  * @param promiseId
1733
1731
  */
1734
1732
  cleanupPromise(promiseId) {
1735
- delete window.n2bridge.promises[promiseId];
1733
+ const bridge = this.getPromiseHandleBridge();
1734
+ delete bridge.promises[promiseId];
1736
1735
  }
1737
1736
  };
1738
1737
 
@@ -1775,6 +1774,22 @@ var NativeBridge = class extends CommonBridge {
1775
1774
  async jumpSafari(options) {
1776
1775
  return this.core.callToTarget("jumpSafari", options);
1777
1776
  }
1777
+ /**
1778
+ * 기능명: 본인인증 결과 정보 넘기기
1779
+ * 목적: NXL One 에서 본인인증 결과 값을 네이티브로 넘기기 위함
1780
+ * @param options
1781
+ * @returns
1782
+ */
1783
+ async onAuthenticationResult(options) {
1784
+ return this.core.callToTarget("onAuthenticationResult", options);
1785
+ }
1786
+ /**
1787
+ * Access Token 가져오기
1788
+ * @returns
1789
+ */
1790
+ async getAccessToken() {
1791
+ return this.core.callToTarget("getAccessToken");
1792
+ }
1778
1793
  /**
1779
1794
  * ### Bridge for Oz
1780
1795
  * 설정한 뷰어 파라미터를 기준으로 뷰어에 새로운 보고서를 바인딩합니다.
@@ -1784,9 +1799,9 @@ var NativeBridge = class extends CommonBridge {
1784
1799
  * Bridge.native.createReportEx({ param: "connection.openfile=sample.ozd" });
1785
1800
  * ```
1786
1801
  */
1787
- createReportEx(options) {
1802
+ createOZViewer(options) {
1788
1803
  return this.core.callToTarget(
1789
- "createReportEx",
1804
+ "createOZViewer",
1790
1805
  Object.assign({ delimiter: "\n" }, options)
1791
1806
  );
1792
1807
  }
@@ -1799,8 +1814,62 @@ var NativeBridge = class extends CommonBridge {
1799
1814
  * Bridge.native.hideViewer();
1800
1815
  * ```
1801
1816
  */
1802
- hideViewer() {
1803
- return this.core.callToTarget("hideViewer");
1817
+ hideOZViewer() {
1818
+ return this.core.callToTarget("hideOZViewer");
1819
+ }
1820
+ /**
1821
+ * ### Bridge for Oz
1822
+ * 오즈 파라미터에서 사용할 OZD를 다운받는 브릿지입니다
1823
+ * @example
1824
+ * ```tsx
1825
+ * const data = [
1826
+ * { name: "문서1", file: ["doc1.ozd"], complete: true },
1827
+ * { name: "문서2", file: ["doc2.ozd", "doc3.ozd"], complete: true }
1828
+ * ]
1829
+ * await Bridge.native.downloadDocument(data)
1830
+ * ```
1831
+ * returnData는 file 경로가 절대경로로 매핑되어 돌아온다
1832
+ * ```json
1833
+ * {
1834
+ * "action":"downloadDocument",
1835
+ * "data":[
1836
+ * {
1837
+ * "name":"aaa",
1838
+ * "file":[
1839
+ * "/data/user/0/com.hanwhalife.ssp.stg/files/A0010.ozd",
1840
+ * "/data/user/0/com.hanwhalife.ssp.stg/files/C0401.ozd"
1841
+ * ],
1842
+ * "complete":false
1843
+ * },
1844
+ * {
1845
+ * "name":"bbb",
1846
+ * "file":[
1847
+ * "/data/user/0/com.hanwhalife.ssp.stg/files/A1500.ozd"
1848
+ * ],
1849
+ * "complete":false
1850
+ * }
1851
+ * ]
1852
+ * }
1853
+ * ```
1854
+ */
1855
+ async downloadDocument(options) {
1856
+ return this.core.callToTarget("downloadDocument", options);
1857
+ }
1858
+ // TODO: 필요 플러그인들 추가
1859
+ };
1860
+
1861
+ // src/native/bridge-oz/native-bridge-oz.ts
1862
+ var NativeBridgeOz = class extends CommonBridge {
1863
+ constructor() {
1864
+ super();
1865
+ __publicField(this, "core");
1866
+ this.core = new NativeBridgeCore("n2OzBridge", "n2OzBridge");
1867
+ }
1868
+ /**
1869
+ * Iframe, App 공통으로 구현해야할 함수
1870
+ */
1871
+ hello() {
1872
+ console.log("[NativeBridge] hello");
1804
1873
  }
1805
1874
  /**
1806
1875
  * ### Bridge for Oz
@@ -1914,44 +1983,6 @@ var NativeBridge = class extends CommonBridge {
1914
1983
  async getOzFontParam() {
1915
1984
  return this.core.callToTarget("getOzFontParam");
1916
1985
  }
1917
- /**
1918
- * ### Bridge for Oz
1919
- * 오즈 파라미터에서 사용할 OZD를 다운받는 브릿지입니다
1920
- * @example
1921
- * ```tsx
1922
- * const data = [
1923
- * { name: "문서1", file: ["doc1.ozd"], complete: true },
1924
- * { name: "문서2", file: ["doc2.ozd", "doc3.ozd"], complete: true }
1925
- * ]
1926
- * await Bridge.native.downloadDocument(data)
1927
- * ```
1928
- * returnData는 file 경로가 절대경로로 매핑되어 돌아온다
1929
- * ```json
1930
- * {
1931
- * "action":"downloadDocument",
1932
- * "data":[
1933
- * {
1934
- * "name":"aaa",
1935
- * "file":[
1936
- * "/data/user/0/com.hanwhalife.ssp.stg/files/A0010.ozd",
1937
- * "/data/user/0/com.hanwhalife.ssp.stg/files/C0401.ozd"
1938
- * ],
1939
- * "complete":false
1940
- * },
1941
- * {
1942
- * "name":"bbb",
1943
- * "file":[
1944
- * "/data/user/0/com.hanwhalife.ssp.stg/files/A1500.ozd"
1945
- * ],
1946
- * "complete":false
1947
- * }
1948
- * ]
1949
- * }
1950
- * ```
1951
- */
1952
- async downloadDocument(options) {
1953
- return this.core.callToTarget("downloadDocument", options);
1954
- }
1955
1986
  /**
1956
1987
  * ### Bridge for Oz
1957
1988
  * 서식의 진행중/완료 상태를 업데이트하는 브릿지
@@ -2011,13 +2042,26 @@ var NativeBridge = class extends CommonBridge {
2011
2042
  return this.core.callToTarget("hideOzPdfViewer");
2012
2043
  }
2013
2044
  /**
2014
- * 기능명: 본인인증 결과 정보 넘기기
2015
- * 목적: NXL One 에서 본인인증 결과 값을 네이티브로 넘기기 위함
2016
- * @param options
2017
- * @returns
2045
+ * 로더 컴포넌트 show
2046
+ * @example
2047
+ * ```tsx
2048
+ * // 사용 예시
2049
+ * await Bridge.native.showLoader()
2050
+ * ```
2018
2051
  */
2019
- async onAuthenticationResult(options) {
2020
- return this.core.callToTarget("onAuthenticationResult", options);
2052
+ async showLoader() {
2053
+ return this.core.callToTarget("showLoader");
2054
+ }
2055
+ /**
2056
+ * 로더 컴포넌트 hide
2057
+ * @example
2058
+ * ```tsx
2059
+ * // 사용 예시
2060
+ * await Bridge.native.hideLoader()
2061
+ * ```
2062
+ */
2063
+ async hideLoader() {
2064
+ return this.core.callToTarget("hideLoader");
2021
2065
  }
2022
2066
  // TODO: 필요 플러그인들 추가
2023
2067
  };
@@ -2025,6 +2069,7 @@ var NativeBridge = class extends CommonBridge {
2025
2069
  // src/bridge.ts
2026
2070
  var Bridge = {
2027
2071
  native: new NativeBridge(),
2072
+ nativeOz: new NativeBridgeOz(),
2028
2073
  iframe: new IframeBridge(),
2029
2074
  nativeCore: new NativeBridgeCore(),
2030
2075
  iframeCore: new IframeBridgeCore()
@@ -2053,10 +2098,25 @@ var commonOzParam = [
2053
2098
  `eform.signpad_type=embedded`,
2054
2099
  // `eform.signpad_type=keypad`,
2055
2100
  `eform.show_prev_next_input=true`,
2056
- `eform.signpad_prev_next_iconposition=sign_top_left`,
2101
+ // `eform.signpad_prev_next_iconposition=sign_top_left`,
2102
+ `eform.signpad_prev_next_iconposition=sign_top`,
2103
+ `eform.inputcomponent_toolbar_button_json=${JSON.stringify({
2104
+ // 서명패드 버튼 배열 수정
2105
+ "all": {
2106
+ // 왼쪽에 이전, 다시쓰기 버튼
2107
+ "left_align": "prev,clear",
2108
+ // 오른쪽에 완료 성명,서명 불러오기, 다음
2109
+ "right_align": "ok,reusablesign,next"
2110
+ }
2111
+ })}`,
2057
2112
  `eform.signpad_show_draw_erase_button=false`,
2113
+ `eform.signpad_viewtype=keepratioandfittoframe`,
2058
2114
  `eform.radiobutton_type=ensurevisible_at_prev_next`,
2059
2115
  `eform.checkbox_type=ensurevisible_at_prev_next`,
2116
+ `eform.prev_next_required_rule=required_only`,
2117
+ `eform.prev_next_navigation_rule=required_only`,
2118
+ `eform.prev_next_constraint_rule=empty_only`,
2119
+ `viewer.pagenavigate_by_prev_next=true`,
2060
2120
  `eform.imagepicker_id_info=${JSON.stringify({
2061
2121
  ids: [
2062
2122
  {
@@ -2153,7 +2213,7 @@ async function fetchDocument(options) {
2153
2213
  return data.map((i) => ({ ...i, startPage: 0, endPage: 0 }));
2154
2214
  }
2155
2215
  async function fetchFont() {
2156
- const { data: fontMap } = await Bridge.native.getOzFontParam();
2216
+ const { data: fontMap } = await Bridge.nativeOz.getOzFontParam();
2157
2217
  const fontParms = Object.keys(fontMap).map((i) => `font.${i}=${fontMap[i]}`);
2158
2218
  return fontParms;
2159
2219
  }
@@ -2202,8 +2262,7 @@ function getFileListByGlobalIndex(index, data) {
2202
2262
  }
2203
2263
 
2204
2264
  // src/oz/use-create-report.ts
2205
- function useCreateReport({ documentInfo, extraData = {} }) {
2206
- const documentList = (0, import_react.useMemo)(() => documentInfo.map((i) => i.file).flat(1), [documentInfo]);
2265
+ function useCreateReport({ documentList, extraData = {} }) {
2207
2266
  const CreateReport = (0, import_react.useCallback)(async () => {
2208
2267
  if (documentList.length === 0) {
2209
2268
  throw new Error("\uBB38\uC11C\uBAA9\uB85D\uC774 \uBE44\uC5B4\uC788\uC2B5\uB2C8\uB2E4");
@@ -2233,25 +2292,64 @@ function useCreateReport({ documentInfo, extraData = {} }) {
2233
2292
  ...fontParms,
2234
2293
  ...extraParams.flat(1)
2235
2294
  ];
2236
- Bridge.native.createReportEx({ param: params.join("\n") });
2295
+ Bridge.native.createOZViewer({ param: params.join("\n") });
2237
2296
  }, [documentList, extraData]);
2297
+ return { CreateReport };
2298
+ }
2299
+
2300
+ // src/oz/use-document-info.tsx
2301
+ var import_react2 = __toESM(require_react());
2302
+ function useDocumentInfo(initialValue) {
2303
+ const [documentInfo, setDocumentInfo] = (0, import_react2.useState)([...initialValue]);
2304
+ const documentList = (0, import_react2.useMemo)(() => documentInfo.map((i) => i.file).flat(1), [documentInfo]);
2305
+ const documentIndexMap = documentList.reduce((acc, cur, index) => {
2306
+ acc[cur] = index;
2307
+ return acc;
2308
+ }, {});
2309
+ const documentTemplateMap = (0, import_react2.useMemo)(() => documentInfo.reduce((map, doc) => {
2310
+ doc.file.forEach((file) => {
2311
+ map[file] = { ...doc };
2312
+ });
2313
+ return map;
2314
+ }, {}), [documentInfo]);
2315
+ const nameTemplateMap = documentInfo.reduce((acc, doc) => {
2316
+ acc[doc.name] = doc;
2317
+ return acc;
2318
+ }, {});
2319
+ const groupIndexes = (0, import_react2.useMemo)(() => documentInfo.reduce((acc, item) => {
2320
+ item.file.forEach((file) => {
2321
+ const currentIndex = documentIndexMap[file];
2322
+ if (!acc[currentIndex]) {
2323
+ acc[currentIndex] = [];
2324
+ }
2325
+ item.file.forEach((groupFile) => {
2326
+ acc[currentIndex].push(documentIndexMap[groupFile]);
2327
+ });
2328
+ });
2329
+ return acc;
2330
+ }, []), [documentIndexMap, documentInfo]);
2238
2331
  return {
2332
+ setDocumentInfo,
2333
+ documentInfo,
2239
2334
  documentList,
2240
- CreateReport
2335
+ documentTemplateMap,
2336
+ documentIndexMap,
2337
+ nameTemplateMap,
2338
+ groupIndexes
2241
2339
  };
2242
2340
  }
2243
2341
 
2244
2342
  // src/oz/use-oz-event-listener.tsx
2245
- var import_react2 = __toESM(require_react());
2343
+ var import_react3 = __toESM(require_react());
2246
2344
  function useOzEventListener({ event, handler }) {
2247
- const handleEvent = (0, import_react2.useCallback)(
2345
+ const handleEvent = (0, import_react3.useCallback)(
2248
2346
  async (e) => {
2249
2347
  const customEvent = e;
2250
2348
  return await handler(customEvent);
2251
2349
  },
2252
2350
  [handler]
2253
2351
  );
2254
- (0, import_react2.useEffect)(() => {
2352
+ (0, import_react3.useEffect)(() => {
2255
2353
  window.addEventListener(event, handleEvent);
2256
2354
  return () => {
2257
2355
  window.removeEventListener(event, handleEvent);
@@ -2294,6 +2392,7 @@ exports.fetchDocument = fetchDocument;
2294
2392
  exports.fetchFont = fetchFont;
2295
2393
  exports.getFileListByGlobalIndex = getFileListByGlobalIndex;
2296
2394
  exports.useCreateReport = useCreateReport;
2395
+ exports.useDocumentInfo = useDocumentInfo;
2297
2396
  exports.useOzEventListener = useOzEventListener;
2298
2397
  exports.wrapperStyle = wrapperStyle;
2299
2398
  //# sourceMappingURL=index.cjs.map