@apps-in-toss/framework 0.0.8 → 0.0.10

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.d.ts CHANGED
@@ -1,14 +1,26 @@
1
+ import { ComponentType, PropsWithChildren } from 'react';
2
+ import { InitialProps, BedrockProps } from 'react-native-bedrock';
1
3
  import { EmitterSubscription } from 'react-native';
2
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
5
  import { WebViewProps as WebViewProps$1 } from '@react-native-bedrock/native/react-native-webview';
4
6
 
7
+ type AppsInTossProps = Pick<BedrockProps, 'context'>;
8
+ declare function registerApp(container: ComponentType<PropsWithChildren<InitialProps>>, { context }: AppsInTossProps): (initialProps: InitialProps) => JSX.Element;
9
+
10
+ declare const AppsInToss: {
11
+ registerApp: typeof registerApp;
12
+ };
13
+
5
14
  interface EventEmitterSchema<K extends string, P extends unknown[]> {
6
15
  name: K;
7
16
  params: P;
8
17
  }
9
18
 
10
19
  /**
11
- * 위치 정확도 옵션이에요.
20
+ * @public
21
+ * @category 위치 정보
22
+ * @name Accuracy
23
+ * @description 위치 정확도 옵션이에요.
12
24
  */
13
25
  declare enum Accuracy {
14
26
  /**
@@ -36,6 +48,12 @@ declare enum Accuracy {
36
48
  */
37
49
  BestForNavigation = 6
38
50
  }
51
+ /**
52
+ * @public
53
+ * @category 위치 정보
54
+ * @name Location
55
+ * @description 위치 정보를 나타내는 객체예요.
56
+ */
39
57
  interface Location {
40
58
  /**
41
59
  * Android에서만 지원하는 옵션이에요.
@@ -50,14 +68,42 @@ interface Location {
50
68
  * 위치가 업데이트된 시점의 유닉스 타임스탬프예요.
51
69
  */
52
70
  timestamp: number;
53
- coords: {
54
- latitude: number;
55
- longitude: number;
56
- altitude: number;
57
- accuracy: number;
58
- altitudeAccuracy: number;
59
- heading: number;
60
- };
71
+ /**
72
+ * @description 위치 정보를 나타내는 객체예요. 자세한 내용은 [LocationCoords](/reference/framework/Types/LocationCoords.html)을 참고해주세요.
73
+ */
74
+ coords: LocationCoords;
75
+ }
76
+ /**
77
+ * @public
78
+ * @category 위치 정보
79
+ * @name LocationCoords
80
+ * @description 세부 위치 정보를 나타내는 객체예요.
81
+ */
82
+ interface LocationCoords {
83
+ /**
84
+ * 위도
85
+ */
86
+ latitude: number;
87
+ /**
88
+ * 경도
89
+ */
90
+ longitude: number;
91
+ /**
92
+ * 높이
93
+ */
94
+ altitude: number;
95
+ /**
96
+ * 위치 정확도
97
+ */
98
+ accuracy: number;
99
+ /**
100
+ * 고도 정확도
101
+ */
102
+ altitudeAccuracy: number;
103
+ /**
104
+ * 방향
105
+ */
106
+ heading: number;
61
107
  }
62
108
  /**
63
109
  * 사진 조회 결과를 나타내는 타입이에요.
@@ -97,9 +143,7 @@ interface UpdateLocationEventEmitter extends EventEmitterSchema<'updateLocation'
97
143
  }
98
144
  /**
99
145
  * @public
100
- * @tag AppsInTossModule
101
- * @category AppsInTossModules
102
- * @kind function
146
+ * @category 위치 정보
103
147
  * @name startUpdateLocation
104
148
  * @description 디바이스의 위치 정보를 지속적으로 감지하고, 위치가 변경되면 콜백을 실행하는 함수예요. 콜백 함수를 등록하면 위치가 변경될 때마다 자동으로 호출돼요.
105
149
  * 실시간 위치 추적이 필요한 기능을 구현할 때 사용할 수 있어요. 예를 들어 지도 앱에서 사용자의 현재 위치를 실시간으로 업데이트할 때, 운동 앱에서 사용자의 이동 거리를 기록할 때 등이에요.
@@ -109,7 +153,7 @@ interface UpdateLocationEventEmitter extends EventEmitterSchema<'updateLocation'
109
153
  * @param {number} [options.accuracy] 위치 정확도를 설정해요.
110
154
  * @param {number} [options.timeInterval] 위치 정보를 업데이트하는 최소 주기로, 단위는 밀리초(ms)예요. 이 값은 위치 업데이트가 발생하는 가장 짧은 간격을 설정하지만, 시스템이나 환경의 영향을 받아 지정한 주기보다 더 긴 간격으로 업데이트될 수 있어요.
111
155
  * @param {number} [options.distanceInterval] 위치 변경 거리를 미터(m) 단위로 설정해요.
112
- * @param {(location: Location) => void} [options.callback] 위치 정보가 변경될 때 호출되는 콜백 함수예요.
156
+ * @param {(location: Location) => void} [options.callback] 위치 정보가 변경될 때 호출되는 콜백 함수예요. 자세한 내용은 [Location](/reference/framework/Types/Location.html)을 참고해주세요.
113
157
  *
114
158
  * @example
115
159
  * ### 위치 정보 변경 감지하기
@@ -126,7 +170,7 @@ interface UpdateLocationEventEmitter extends EventEmitterSchema<'updateLocation'
126
170
  * useEffect(() => {
127
171
  * return startUpdateLocation({
128
172
  * options: {
129
- * accuracy: Accuracy.Default,
173
+ * accuracy: Accuracy.Balanced,
130
174
  * timeInterval: 3000,
131
175
  * distanceInterval: 10,
132
176
  * },
@@ -164,9 +208,7 @@ declare function startUpdateLocation(eventParams: {
164
208
 
165
209
  /**
166
210
  * @public
167
- * @tag AppsInTossModule
168
- * @category AppsInTossModules
169
- * @kind function
211
+ * @category 클립보드
170
212
  * @name setClipboardText
171
213
  * @description 텍스트를 클립보드에 복사해서 사용자가 다른 곳에 붙여 넣기 할 수 있어요.
172
214
  * @param {Promise<void>} text - 클립보드에 복사할 텍스트예요. 문자열 형식으로 입력해요.
@@ -197,9 +239,7 @@ declare function setClipboardText(text: string): Promise<void>;
197
239
 
198
240
  /**
199
241
  * @public
200
- * @tag AppsInTossModule
201
- * @category AppsInTossModules
202
- * @kind function
242
+ * @category 클립보드
203
243
  * @name getClipboardText
204
244
  * @description 클립보드에 저장된 텍스트를 가져오는 함수예요. 복사된 텍스트를 읽어서 다른 작업에 활용할 수 있어요.
205
245
  * @returns {Promise<string>} - 클립보드에 저장된 텍스트를 반환해요. 클립보드에 텍스트가 없으면 빈 문자열을 반환해요.
@@ -247,9 +287,7 @@ interface ContactEntity {
247
287
  }
248
288
  /**
249
289
  * @public
250
- * @tag AppsInTossModule
251
- * @category AppsInTossModules
252
- * @kind function
290
+ * @category 연락처
253
291
  * @name fetchContacts
254
292
  * @description 사용자의 연락처 목록을 페이지 단위로 가져오는 함수예요.
255
293
  * @param size - 한 번에 가져올 연락처 개수예요. 예를 들어, 10을 전달하면 최대 10개의 연락처를 가져와요.
@@ -340,9 +378,7 @@ interface FetchAlbumPhotosOptions {
340
378
  }
341
379
  /**
342
380
  * @public
343
- * @tag AppsInTossModule
344
- * @category AppsInTossModules
345
- * @kind function
381
+ * @category 사진
346
382
  * @name fetchAlbumPhotos
347
383
  * @description
348
384
  * 사용자의 앨범에서 사진 목록을 불러오는 함수예요.
@@ -352,7 +388,7 @@ interface FetchAlbumPhotosOptions {
352
388
  * @param {number} [options.maxCount=10] 가져올 사진의 최대 개수를 설정해요. 숫자로 입력하며 기본값은 10이에요.
353
389
  * @param {number} [options.maxWidth=1024] 사진의 최대 폭을 제한해요. 단위는 픽셀이며 기본값은 `1024`이에요.
354
390
  * @param {boolean} [options.base64=false] 이미지를 base64 형식으로 반환할지 설정해요. 기본값은 `false`예요.
355
- * @returns {Promise<AlbumResponse[]>}
391
+ * @returns {Promise<ImageResponse[]>}
356
392
  * 앨범 사진의 고유 ID와 데이터 URI를 포함한 배열을 반환해요.
357
393
  *
358
394
  * @example
@@ -400,9 +436,7 @@ interface GetCurrentLocationOptions {
400
436
  }
401
437
  /**
402
438
  * @public
403
- * @tag AppsInTossModule
404
- * @category AppsInTossModules
405
- * @kind function
439
+ * @category 위치 정보
406
440
  * @name getCurrentLocation
407
441
  * @description 디바이스의 현재 위치 정보를 가져오는 함수예요.
408
442
  * 위치 기반 서비스를 구현할 때 사용되고, 한 번만 호출되어 현재 위치를 즉시 반환해요.
@@ -410,7 +444,7 @@ interface GetCurrentLocationOptions {
410
444
  *
411
445
  * @param {GetCurrentLocationOptions} options 위치 정보를 가져올 때 사용하는 옵션 객체예요.
412
446
  * @param {Accuracy} [options.accuracy] 위치 정보의 정확도 수준이에요. 정확도는 `Accuracy` 타입으로 설정돼요.
413
- * @returns {Promise<Location>} 디바이스의 위치 정보가 담긴 객체를 반환해요.
447
+ * @returns {Promise<Location>} 디바이스의 위치 정보가 담긴 객체를 반환해요. 자세한 내용은 [Location](/reference/framework/Types/Location.html)을 참고해주세요.
414
448
  *
415
449
  * @example
416
450
  * ### 디바이스의 현재 위치 정보 가져오기
@@ -464,9 +498,7 @@ interface OpenCameraOptions {
464
498
  }
465
499
  /**
466
500
  * @public
467
- * @tag AppsInTossModule
468
- * @category AppsInTossModules
469
- * @kind function
501
+ * @category 카메라
470
502
  * @name openCamera
471
503
  * @description 카메라를 실행해서 촬영된 이미지를 반환하는 함수예요.
472
504
  * @param {OpenCameraOptions} options - 카메라 실행 시 사용되는 옵션 객체예요.
@@ -513,17 +545,81 @@ interface OpenCameraOptions {
513
545
  */
514
546
  declare function openCamera(options?: OpenCameraOptions): Promise<ImageResponse>;
515
547
 
548
+ /**
549
+ * @public
550
+ * @category 로그인
551
+ * @name appLogin
552
+ * @description 토스 인증으로 로그인해요. 로그인이 완료되면 다시 토스 앱으로 이동해요.
553
+ * @example
554
+ *
555
+ * ### 토스 인증을 통해 로그인을 하는 예제
556
+ *
557
+ * ```tsx
558
+ * import { Button } from 'react-native';
559
+ * import { appLogin } from '@apps-in-toss/framework';
560
+ *
561
+ * function Page() {
562
+ * const handleLogin = async () => {
563
+ * const { authorizationCode, referrer } = await appLogin();
564
+ *
565
+ * // 획득한 인가 코드(`authorizationCode`)와 `referrer`를 서버로 전달해요.
566
+ * }
567
+ *
568
+ * return <Button title="로그인" onPress={handleLogin} />;
569
+ * }
570
+ * ```
571
+ */
572
+ declare function appLogin(): Promise<{
573
+ authorizationCode: string;
574
+ referrer: "DEFAULT" | "SANDBOX";
575
+ }>;
576
+
577
+ /**
578
+ * @public
579
+ * @category 환경 확인
580
+ * @kind function
581
+ * @name getOperationalEnvironment
582
+ * @description
583
+ * 현재 실행 중인 앱의 운영 환경을 확인해요.
584
+ * 토스 앱에서 실행 중이라면 `'toss'`, 샌드박스 환경에서 실행 중이라면 `'sandbox'`를 반환해요.
585
+ *
586
+ * 운영 환경은 앱이 실행되는 컨텍스트를 의미하며, 특정 기능의 사용 가능 여부를 판단하는 데 활용할 수 있어요.
587
+ *
588
+ * @returns {'toss' | 'sandbox'}
589
+ * 현재 운영 환경을 나타내는 문자열이에요.
590
+ * - `'toss'`: 토스 앱에서 실행 중이에요.
591
+ * - `'sandbox'`: 샌드박스 환경에서 실행 중이에요.
592
+ *
593
+ * @example
594
+ * ### 현재 운영 환경 확인하기
595
+ *
596
+ * ```tsx
597
+ * import { getOperationalEnvironment } from '@apps-in-toss/framework';
598
+ * import { Text } from 'react-native';
599
+ *
600
+ * function EnvironmentInfo() {
601
+ * const environment = getOperationalEnvironment();
602
+ *
603
+ * return (
604
+ * <Text>현재 운영 환경: {environment}</Text>
605
+ * );
606
+ * }
607
+ * ```
608
+ */
609
+ declare function getOperationalEnvironment(): 'toss' | 'sandbox';
610
+
516
611
  interface WebViewProps extends Omit<WebViewProps$1, 'source' | 'sharedCookiesEnabled' | 'thirdPartyCookiesEnabled' | 'injectedJavaScriptBeforeContentLoaded'> {
517
- localhostPort?: number;
612
+ local: {
613
+ port: number;
614
+ host: number;
615
+ };
518
616
  }
519
- declare function WebView({ localhostPort, onMessage, ...props }: WebViewProps): react_jsx_runtime.JSX.Element;
617
+ declare function WebView({ local, onMessage, ...props }: WebViewProps): react_jsx_runtime.JSX.Element;
520
618
 
521
619
  type UseGeolocationOptions = Omit<StartUpdateLocationOptions, 'callback'>;
522
620
  /**
523
621
  * @public
524
- * @tag AppsInTossModule
525
- * @category AppsInTossModules
526
- * @kind function
622
+ * @category 위치 정보
527
623
  * @name useGeolocation
528
624
  * @description 디바이스의 위치 정보를 반환하는 훅이에요. 위치가 변경되면 값도 변경돼요.
529
625
  * GPS 정보를 활용해 현재 위치를 감지하고, 사용자의 이동에 따라 자동으로 업데이트돼요.
@@ -534,6 +630,7 @@ type UseGeolocationOptions = Omit<StartUpdateLocationOptions, 'callback'>;
534
630
  * @param {Accuracy} [options.accuracy] 위치 정확도를 설정해요. `Accuracy.Lowest`: 오차범위 3KM 이내, `Accuracy.Low`: 오차범위 1KM 이내, `Accuracy.Balanced`: 오차범위 몇 백미터 이내, `Accuracy.High`: 오차범위 10M 이내, `Accuracy.Highest`: 가장 높은 정확도, `Accuracy.BestForNavigation`: 네비게이션을 위한 최고 정확도
535
631
  * @param {number} [options.timeInterval] 위치 정보를 업데이트하는 최소 주기로, 단위는 밀리초(ms)예요. 이 값은 위치 업데이트가 발생하는 가장 짧은 간격을 설정하지만, 시스템이나 환경의 영향을 받아 지정한 주기보다 더 긴 간격으로 업데이트될 수 있어요.
536
632
  * @param {number} [options.distanceInterval] 위치 변경 거리를 미터(m) 단위로 설정해요.
633
+ * @returns {Location | null} 디바이스의 위치 정보가 담긴 객체를 반환해요. 자세한 내용은 [Location](/reference/framework/Types/Location.html)을 참고해주세요.
537
634
  *
538
635
  * @example
539
636
  * ### 위치 정보 변경 감지하기
@@ -569,4 +666,4 @@ declare const env: {
569
666
  getDeploymentId: () => string | undefined;
570
667
  };
571
668
 
572
- export { Accuracy, type ContactEntity, type FetchAlbumPhotosOptions, type GetCurrentLocationOptions, type ImageResponse, type Location, type OpenCameraOptions, type StartUpdateLocationOptions, type StartUpdateLocationSubscription, type UpdateLocationEventEmitter, type UseGeolocationOptions, WebView, type WebViewProps, env, fetchAlbumPhotos, fetchContacts, getClipboardText, getCurrentLocation, openCamera, setClipboardText, startUpdateLocation, useGeolocation };
669
+ export { Accuracy, AppsInToss, type ContactEntity, type FetchAlbumPhotosOptions, type GetCurrentLocationOptions, type ImageResponse, type Location, type LocationCoords, type OpenCameraOptions, type StartUpdateLocationOptions, type StartUpdateLocationSubscription, type UpdateLocationEventEmitter, type UseGeolocationOptions, WebView, type WebViewProps, appLogin, env, fetchAlbumPhotos, fetchContacts, getClipboardText, getCurrentLocation, getOperationalEnvironment, openCamera, setClipboardText, startUpdateLocation, useGeolocation };
package/dist/index.js CHANGED
@@ -4,6 +4,32 @@ var __export = (target, all) => {
4
4
  __defProp(target, name, { get: all[name], enumerable: true });
5
5
  };
6
6
 
7
+ // src/core/registerApp.tsx
8
+ import { Bedrock } from "react-native-bedrock";
9
+ import { jsx } from "react/jsx-runtime";
10
+ function AppsInTossContainer(Container, { children, ...initialProps }) {
11
+ return /* @__PURE__ */ jsx(Container, { ...initialProps, children });
12
+ }
13
+ function registerApp(container, { context }) {
14
+ return Bedrock.registerApp(AppsInTossContainer.bind(null, container), {
15
+ appName: getAppName(),
16
+ context
17
+ });
18
+ }
19
+ function getAppName() {
20
+ try {
21
+ return global.__bedrock.app.name;
22
+ } catch (error) {
23
+ console.error("unexpected error occurred while getting app name");
24
+ throw error;
25
+ }
26
+ }
27
+
28
+ // src/core/index.ts
29
+ var AppsInToss = {
30
+ registerApp
31
+ };
32
+
7
33
  // src/native-event-emitter/index.ts
8
34
  var native_event_emitter_exports = {};
9
35
  __export(native_event_emitter_exports, {
@@ -86,10 +112,12 @@ function startUpdateLocation(eventParams) {
86
112
  // src/native-modules/index.ts
87
113
  var native_modules_exports = {};
88
114
  __export(native_modules_exports, {
115
+ appLogin: () => appLogin,
89
116
  fetchAlbumPhotos: () => fetchAlbumPhotos,
90
117
  fetchContacts: () => fetchContacts,
91
118
  getClipboardText: () => getClipboardText,
92
119
  getCurrentLocation: () => getCurrentLocation,
120
+ getOperationalEnvironment: () => getOperationalEnvironment,
93
121
  openCamera: () => openCamera,
94
122
  setClipboardText: () => setClipboardText
95
123
  });
@@ -147,6 +175,14 @@ async function fetchAlbumPhotos(options) {
147
175
  maxCount: options.maxCount ?? DEFAULT_MAX_COUNT,
148
176
  maxWidth: options.maxWidth ?? DEFAULT_MAX_WIDTH
149
177
  });
178
+ if (options.base64) {
179
+ return albumPhotos.map((photo) => {
180
+ return {
181
+ ...photo,
182
+ dataUri: `data:image/jpeg;base64,${photo.dataUri}`
183
+ };
184
+ });
185
+ }
150
186
  return albumPhotos;
151
187
  }
152
188
 
@@ -170,6 +206,16 @@ async function openCamera(options) {
170
206
  return photo;
171
207
  }
172
208
 
209
+ // src/native-modules/appLogin.ts
210
+ async function appLogin() {
211
+ return AppsInTossModule.appLogin({});
212
+ }
213
+
214
+ // src/native-modules/getOperationalEnvironment.ts
215
+ function getOperationalEnvironment() {
216
+ return AppsInTossModule.operationalEnvironment;
217
+ }
218
+
173
219
  // src/components/WebView.tsx
174
220
  import {
175
221
  WebView as OriginalWebView
@@ -178,14 +224,14 @@ import { useMemo } from "react";
178
224
  import { useBridgeHandler } from "react-native-bedrock";
179
225
  import * as bridges from "react-native-bedrock/bridges";
180
226
  import * as constantBridges from "react-native-bedrock/constants";
181
- import { jsx } from "react/jsx-runtime";
182
- function WebView({ localhostPort = 5173, onMessage, ...props }) {
227
+ import { jsx as jsx2 } from "react/jsx-runtime";
228
+ function WebView({ local, onMessage, ...props }) {
183
229
  const uri = useMemo(() => {
184
230
  if (__DEV__) {
185
- return `http://localhost:${localhostPort}`;
231
+ return `http://${local.host}:${local.port}`;
186
232
  }
187
233
  return AppsInTossModule.getWebBundleURL({}).url;
188
- }, [localhostPort]);
234
+ }, [local]);
189
235
  const handler = useBridgeHandler({
190
236
  onMessage,
191
237
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -200,7 +246,7 @@ function WebView({ localhostPort = 5173, onMessage, ...props }) {
200
246
  ...native_modules_exports
201
247
  }
202
248
  });
203
- return /* @__PURE__ */ jsx(
249
+ return /* @__PURE__ */ jsx2(
204
250
  OriginalWebView,
205
251
  {
206
252
  ref: handler.ref,
@@ -255,12 +301,15 @@ var Accuracy2 = /* @__PURE__ */ ((Accuracy3) => {
255
301
  })(Accuracy2 || {});
256
302
  export {
257
303
  Accuracy2 as Accuracy,
304
+ AppsInToss,
258
305
  WebView,
306
+ appLogin,
259
307
  env,
260
308
  fetchAlbumPhotos,
261
309
  fetchContacts,
262
310
  getClipboardText,
263
311
  getCurrentLocation,
312
+ getOperationalEnvironment,
264
313
  openCamera,
265
314
  setClipboardText,
266
315
  startUpdateLocation,
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+
17
+ // src/jest/index.ts
18
+ var jest_exports = {};
19
+ module.exports = __toCommonJS(jest_exports);
20
+ __reExport(jest_exports, require("react-native-bedrock/jest"), module.exports);
21
+ // Annotate the CommonJS export names for ESM import in node:
22
+ 0 && (module.exports = {
23
+ ...require("react-native-bedrock/jest")
24
+ });
@@ -0,0 +1 @@
1
+ export * from 'react-native-bedrock/jest';
@@ -0,0 +1 @@
1
+ export * from 'react-native-bedrock/jest';
@@ -0,0 +1,4 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+
3
+ // src/jest/index.ts
4
+ export * from "react-native-bedrock/jest";