@apps-in-toss/native-modules 0.0.0-dev.1752115036458 → 0.0.0-dev.1757056983098

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.
Files changed (77) hide show
  1. package/dist/bridges-meta.json +36 -13
  2. package/dist/index.cjs +343 -129
  3. package/dist/index.d.cts +1212 -418
  4. package/dist/index.d.ts +1212 -418
  5. package/dist/index.js +315 -108
  6. package/package.json +7 -8
  7. package/src/AppsInTossModule/constants.ts +6 -0
  8. package/src/AppsInTossModule/native-event-emitter/appsInTossEvent.ts +15 -0
  9. package/src/AppsInTossModule/native-event-emitter/contactsViral.ts +140 -0
  10. package/src/AppsInTossModule/native-event-emitter/event-plugins/EntryMessageExitedEvent.ts +10 -0
  11. package/src/AppsInTossModule/native-event-emitter/event-plugins/HomeIconButtonClickHandleEvent.ts +10 -0
  12. package/src/AppsInTossModule/native-event-emitter/event-plugins/UpdateLocationEvent.ts +60 -0
  13. package/src/AppsInTossModule/native-event-emitter/index.ts +6 -0
  14. package/src/AppsInTossModule/native-event-emitter/internal/AppBridgeCallbackEvent.ts +45 -0
  15. package/src/AppsInTossModule/native-event-emitter/internal/VisibilityChangedByTransparentServiceWebEvent.ts +50 -0
  16. package/src/AppsInTossModule/native-event-emitter/internal/appBridge.spec.ts +135 -0
  17. package/src/AppsInTossModule/native-event-emitter/internal/appBridge.ts +79 -0
  18. package/src/AppsInTossModule/native-event-emitter/internal/onVisibilityChangedByTransparentServiceWeb.ts +20 -0
  19. package/src/AppsInTossModule/native-event-emitter/nativeEventEmitter.ts +35 -0
  20. package/src/AppsInTossModule/native-event-emitter/startUpdateLocation.ts +98 -0
  21. package/src/AppsInTossModule/native-event-emitter/types.ts +4 -0
  22. package/src/AppsInTossModule/native-modules/AppsInTossModule.ts +89 -0
  23. package/src/AppsInTossModule/native-modules/ads/googleAdMob.ts +681 -0
  24. package/src/AppsInTossModule/native-modules/ads/googleAdMobV2.ts +363 -0
  25. package/src/AppsInTossModule/native-modules/ads/types.ts +123 -0
  26. package/src/AppsInTossModule/native-modules/appLogin.ts +29 -0
  27. package/src/AppsInTossModule/native-modules/checkoutPayment.ts +80 -0
  28. package/src/AppsInTossModule/native-modules/eventLog.spec.ts +300 -0
  29. package/src/AppsInTossModule/native-modules/eventLog.ts +77 -0
  30. package/src/AppsInTossModule/native-modules/fetchAlbumPhotos.ts +88 -0
  31. package/src/AppsInTossModule/native-modules/fetchContacts.ts +121 -0
  32. package/src/AppsInTossModule/native-modules/getClipboardText.ts +47 -0
  33. package/src/AppsInTossModule/native-modules/getCurrentLocation.ts +65 -0
  34. package/src/AppsInTossModule/native-modules/getDeviceId.ts +33 -0
  35. package/src/AppsInTossModule/native-modules/getGameCenterGameProfile.ts +68 -0
  36. package/src/AppsInTossModule/native-modules/getOperationalEnvironment.ts +37 -0
  37. package/src/AppsInTossModule/native-modules/getPermission.ts +58 -0
  38. package/src/AppsInTossModule/native-modules/getTossAppVersion.ts +33 -0
  39. package/src/AppsInTossModule/native-modules/getTossShareLink.ts +39 -0
  40. package/src/AppsInTossModule/native-modules/iap.ts +213 -0
  41. package/src/AppsInTossModule/native-modules/index.ts +104 -0
  42. package/src/AppsInTossModule/native-modules/isMinVersionSupported.spec.ts +190 -0
  43. package/src/AppsInTossModule/native-modules/isMinVersionSupported.ts +68 -0
  44. package/src/AppsInTossModule/native-modules/openCamera.ts +81 -0
  45. package/src/AppsInTossModule/native-modules/openGameCenterLeaderboard.ts +44 -0
  46. package/src/AppsInTossModule/native-modules/openPermissionDialog.ts +54 -0
  47. package/src/AppsInTossModule/native-modules/requestPermission.ts +63 -0
  48. package/src/AppsInTossModule/native-modules/saveBase64Data.ts +57 -0
  49. package/src/AppsInTossModule/native-modules/setClipboardText.ts +39 -0
  50. package/src/AppsInTossModule/native-modules/setDeviceOrientation.ts +74 -0
  51. package/src/AppsInTossModule/native-modules/storage.ts +100 -0
  52. package/src/AppsInTossModule/native-modules/submitGameCenterLeaderBoardScore.ts +74 -0
  53. package/src/AppsInTossModule/native-modules/tossCore.ts +29 -0
  54. package/src/BedrockModule/native-modules/core/BedrockCoreModule.ts +8 -0
  55. package/src/BedrockModule/native-modules/index.ts +4 -0
  56. package/src/BedrockModule/native-modules/natives/BedrockModule.ts +20 -0
  57. package/src/BedrockModule/native-modules/natives/closeView.ts +25 -0
  58. package/src/BedrockModule/native-modules/natives/generateHapticFeedback/index.ts +27 -0
  59. package/src/BedrockModule/native-modules/natives/generateHapticFeedback/types.ts +38 -0
  60. package/src/BedrockModule/native-modules/natives/getLocale.ts +46 -0
  61. package/src/BedrockModule/native-modules/natives/getNetworkStatus/index.ts +59 -0
  62. package/src/BedrockModule/native-modules/natives/getNetworkStatus/types.ts +1 -0
  63. package/src/BedrockModule/native-modules/natives/getPlatformOS.ts +37 -0
  64. package/src/BedrockModule/native-modules/natives/getSchemeUri.ts +27 -0
  65. package/src/BedrockModule/native-modules/natives/index.ts +11 -0
  66. package/src/BedrockModule/native-modules/natives/openURL.ts +40 -0
  67. package/src/BedrockModule/native-modules/natives/setIosSwipeGestureEnabled.ts +43 -0
  68. package/src/BedrockModule/native-modules/natives/setScreenAwakeMode.ts +66 -0
  69. package/src/BedrockModule/native-modules/natives/setSecureScreen.ts +31 -0
  70. package/src/BedrockModule/native-modules/natives/share.ts +36 -0
  71. package/src/async-bridges.ts +3 -0
  72. package/src/event-bridges.ts +2 -0
  73. package/src/index.ts +16 -0
  74. package/src/types.ts +108 -0
  75. package/src/utils/compareVersion.spec.ts +176 -0
  76. package/src/utils/compareVersion.ts +104 -0
  77. package/src/utils/generateUUID.ts +5 -0
@@ -0,0 +1,300 @@
1
+ import { describe, beforeEach, it, expect, vi, afterEach } from 'vitest';
2
+
3
+ describe('eventLog', () => {
4
+ const mockEventLog = vi.fn();
5
+ let originalConsoleLog: typeof console.log;
6
+
7
+ // 테스트 전에 모킹 설정
8
+ beforeEach(() => {
9
+ // 각 테스트 전 모듈 캐시 초기화
10
+ vi.resetModules();
11
+
12
+ // 기본 모킹 설정
13
+ vi.doMock('react-native', () => ({
14
+ NativeModules: {
15
+ AppsInTossModule: {
16
+ eventLog: mockEventLog,
17
+ tossAppVersion: '5.208.0',
18
+ operationalEnvironment: 'toss',
19
+ },
20
+ },
21
+ Platform: {
22
+ OS: 'ios',
23
+ },
24
+ }));
25
+
26
+ originalConsoleLog = console.log;
27
+ console.log = vi.fn();
28
+ });
29
+
30
+ afterEach(() => {
31
+ console.log = originalConsoleLog;
32
+ vi.restoreAllMocks();
33
+ mockEventLog.mockReset();
34
+ });
35
+
36
+ it('샌드박스 환경에서는 콘솔에 로그를 출력하고 네이티브 모듈을 호출하지 않아야 한다', async () => {
37
+ vi.doMock('./AppsInTossModule.js', () => ({
38
+ AppsInTossModule: {
39
+ tossAppVersion: '5.208.0',
40
+ operationalEnvironment: 'sandbox',
41
+ },
42
+ }));
43
+
44
+ const { eventLog } = await import('./eventLog.js');
45
+
46
+ const params = {
47
+ log_name: 'test_log',
48
+ log_type: 'info' as const,
49
+ params: {
50
+ key1: 'value1',
51
+ key2: 123,
52
+ key3: true,
53
+ key4: undefined,
54
+ },
55
+ };
56
+
57
+ await eventLog(params);
58
+
59
+ expect(console.log).toHaveBeenCalledWith('[eventLogDebug]', {
60
+ log_name: 'test_log',
61
+ log_type: 'info',
62
+ params: {
63
+ key1: 'value1',
64
+ key2: '123',
65
+ key3: 'true',
66
+ },
67
+ });
68
+ expect(mockEventLog).not.toHaveBeenCalled();
69
+ });
70
+
71
+ it('토스 환경에서는 네이티브 모듈을 호출해야 한다', async () => {
72
+ vi.doMock('./AppsInTossModule.js', () => ({
73
+ AppsInTossModule: {
74
+ eventLog: mockEventLog,
75
+ tossAppVersion: '5.208.0',
76
+ operationalEnvironment: 'toss',
77
+ },
78
+ }));
79
+
80
+ const { eventLog } = await import('./eventLog.js');
81
+
82
+ const params = {
83
+ log_name: 'test_log',
84
+ log_type: 'error' as const,
85
+ params: {
86
+ key1: 'value1',
87
+ key2: 123,
88
+ key3: true,
89
+ key4: null,
90
+ key5: undefined,
91
+ },
92
+ };
93
+
94
+ await eventLog(params);
95
+
96
+ expect(mockEventLog).toHaveBeenCalledWith({
97
+ log_name: 'test_log',
98
+ log_type: 'error',
99
+ params: {
100
+ key1: 'value1',
101
+ key2: '123',
102
+ key3: 'true',
103
+ key4: 'null',
104
+ },
105
+ });
106
+ expect(console.log).not.toHaveBeenCalled();
107
+ });
108
+
109
+ it('undefined 값은 정규화된 파라미터에서 제외되어야 한다', async () => {
110
+ vi.doMock('./AppsInTossModule.js', () => ({
111
+ AppsInTossModule: {
112
+ eventLog: mockEventLog,
113
+ tossAppVersion: '5.208.0',
114
+ operationalEnvironment: 'toss',
115
+ },
116
+ }));
117
+
118
+ const { eventLog } = await import('./eventLog.js');
119
+
120
+ const params = {
121
+ log_name: 'test_log',
122
+ log_type: 'debug' as const,
123
+ params: {
124
+ key1: 'value1',
125
+ key2: undefined,
126
+ },
127
+ };
128
+
129
+ await eventLog(params);
130
+
131
+ expect(mockEventLog).toHaveBeenCalledWith({
132
+ log_name: 'test_log',
133
+ log_type: 'debug',
134
+ params: {
135
+ key1: 'value1',
136
+ },
137
+ });
138
+ });
139
+
140
+ it('모든 값은 문자열로 변환되어야 한다', async () => {
141
+ vi.doMock('./AppsInTossModule.js', () => ({
142
+ AppsInTossModule: {
143
+ eventLog: mockEventLog,
144
+ tossAppVersion: '5.208.0',
145
+ operationalEnvironment: 'toss',
146
+ },
147
+ }));
148
+
149
+ const { eventLog } = await import('./eventLog.js');
150
+
151
+ const params = {
152
+ log_name: 'test_log',
153
+ log_type: 'warn' as const,
154
+ params: {
155
+ number: 123,
156
+ boolean: false,
157
+ nullValue: null,
158
+ symbol: Symbol('test').toString(),
159
+ },
160
+ };
161
+
162
+ await eventLog(params);
163
+
164
+ expect(mockEventLog).toHaveBeenCalledWith({
165
+ log_name: 'test_log',
166
+ log_type: 'warn',
167
+ params: {
168
+ number: '123',
169
+ boolean: 'false',
170
+ nullValue: 'null',
171
+ symbol: 'Symbol(test)',
172
+ },
173
+ });
174
+ });
175
+
176
+ it('빈 객체가 전달되면 빈 객체를 반환해야 한다', async () => {
177
+ vi.doMock('./AppsInTossModule.js', () => ({
178
+ AppsInTossModule: {
179
+ eventLog: mockEventLog,
180
+ tossAppVersion: '5.208.0',
181
+ operationalEnvironment: 'toss',
182
+ },
183
+ }));
184
+
185
+ const { eventLog } = await import('./eventLog.js');
186
+
187
+ const params = {
188
+ log_name: 'test_log',
189
+ log_type: 'info' as const,
190
+ params: {},
191
+ };
192
+
193
+ await eventLog(params);
194
+
195
+ expect(mockEventLog).toHaveBeenCalledWith({
196
+ log_name: 'test_log',
197
+ log_type: 'info',
198
+ params: {},
199
+ });
200
+ });
201
+
202
+ it('여러 개의 undefined 값이 있는 경우 모두 제외되어야 한다', async () => {
203
+ vi.doMock('./AppsInTossModule.js', () => ({
204
+ AppsInTossModule: {
205
+ eventLog: mockEventLog,
206
+ tossAppVersion: '5.208.0',
207
+ operationalEnvironment: 'toss',
208
+ },
209
+ }));
210
+
211
+ const { eventLog } = await import('./eventLog.js');
212
+
213
+ const params = {
214
+ log_name: 'test_log',
215
+ log_type: 'debug' as const,
216
+ params: {
217
+ key1: undefined,
218
+ key2: undefined,
219
+ key3: 'value3',
220
+ key4: undefined,
221
+ },
222
+ };
223
+
224
+ await eventLog(params);
225
+
226
+ expect(mockEventLog).toHaveBeenCalledWith({
227
+ log_name: 'test_log',
228
+ log_type: 'debug',
229
+ params: {
230
+ key3: 'value3',
231
+ },
232
+ });
233
+ });
234
+
235
+ it('숫자 0과 빈 문자열은 정상적으로 문자열로 변환되어야 한다', async () => {
236
+ vi.doMock('./AppsInTossModule.js', () => ({
237
+ AppsInTossModule: {
238
+ eventLog: mockEventLog,
239
+ tossAppVersion: '5.208.0',
240
+ operationalEnvironment: 'toss',
241
+ },
242
+ }));
243
+
244
+ const { eventLog } = await import('./eventLog.js');
245
+
246
+ const params = {
247
+ log_name: 'test_log',
248
+ log_type: 'info' as const,
249
+ params: {
250
+ zeroNumber: 0,
251
+ emptyString: '',
252
+ falseValue: false,
253
+ },
254
+ };
255
+
256
+ await eventLog(params);
257
+
258
+ expect(mockEventLog).toHaveBeenCalledWith({
259
+ log_name: 'test_log',
260
+ log_type: 'info',
261
+ params: {
262
+ zeroNumber: '0',
263
+ emptyString: '',
264
+ falseValue: 'false',
265
+ },
266
+ });
267
+ });
268
+
269
+ it('복잡한 심볼 값도 문자열로 적절히 변환되어야 한다', async () => {
270
+ vi.doMock('./AppsInTossModule.js', () => ({
271
+ AppsInTossModule: {
272
+ eventLog: mockEventLog,
273
+ tossAppVersion: '5.208.0',
274
+ operationalEnvironment: 'toss',
275
+ },
276
+ }));
277
+
278
+ const { eventLog } = await import('./eventLog.js');
279
+
280
+ const testSymbol = Symbol('복잡한_테스트');
281
+
282
+ const params = {
283
+ log_name: 'test_log',
284
+ log_type: 'debug' as const,
285
+ params: {
286
+ symbolValue: testSymbol.toString(),
287
+ },
288
+ };
289
+
290
+ await eventLog(params);
291
+
292
+ expect(mockEventLog).toHaveBeenCalledWith({
293
+ log_name: 'test_log',
294
+ log_type: 'debug',
295
+ params: {
296
+ symbolValue: 'Symbol(복잡한_테스트)',
297
+ },
298
+ });
299
+ });
300
+ });
@@ -0,0 +1,77 @@
1
+ import { AppsInTossModule } from './AppsInTossModule';
2
+ import { isMinVersionSupported } from './isMinVersionSupported';
3
+ import { Primitive } from '../../types';
4
+
5
+ function normalizeParams(params: Record<string, Primitive>): Record<string, string> {
6
+ return Object.fromEntries(
7
+ Object.entries(params)
8
+ .filter(([, value]) => value !== undefined)
9
+ .map(([key, value]) => [key, String(value)])
10
+ );
11
+ }
12
+
13
+ export interface EventLogParams {
14
+ log_name: string;
15
+ log_type: 'debug' | 'info' | 'warn' | 'error' | 'screen' | 'impression' | 'click';
16
+ params: Record<string, Primitive>;
17
+ }
18
+
19
+ /**
20
+ * @category 로깅
21
+ * @kind function
22
+ * @name eventLog
23
+ * @description
24
+ * 이벤트 로그를 기록하는 함수예요.
25
+ *
26
+ * 이 함수는 앱 내에서 발생하는 다양한 이벤트를 로깅하는 데 사용돼요. 디버깅, 정보 제공, 경고, 오류 등 다양한 유형의 로그를 기록할 수 있어요. 샌드박스 환경에서는 콘솔에 로그가 출력되고, 실제 환경에서는 로그 시스템에 기록돼요.
27
+ *
28
+ * @param {Object} params 로그 기록에 필요한 매개변수 객체예요.
29
+ * @param {string} params.log_name 로그의 이름이에요.
30
+ * @param {'debug' | 'info' | 'warn' | 'error' | 'screen' | 'impression' | 'click'} params.log_type 로그의 유형이에요.
31
+ * @param {Record<string, Primitive>} params.params 로그에 포함할 추가 매개변수 객체예요.
32
+ *
33
+ * @returns {Promise<void>} 로그 기록이 완료되면 해결되는 Promise예요.
34
+ *
35
+ * @example
36
+ * ### 이벤트 로그 기록하기
37
+ *
38
+ * ```tsx
39
+ * import { eventLog } from '@apps-in-toss/framework';
40
+ *
41
+ * function logUserAction() {
42
+ * eventLog({
43
+ * log_name: 'user_action',
44
+ * log_type: 'info',
45
+ * params: {
46
+ * action: 'button_click',
47
+ * screen: 'main',
48
+ * userId: 12345
49
+ * }
50
+ * });
51
+ * }
52
+ * ```
53
+ */
54
+ export async function eventLog(params: EventLogParams) {
55
+ if (AppsInTossModule.operationalEnvironment === 'sandbox') {
56
+ console.log('[eventLogDebug]', {
57
+ log_name: params.log_name,
58
+ log_type: params.log_type,
59
+ params: normalizeParams(params.params),
60
+ });
61
+ return;
62
+ }
63
+
64
+ const isSupported = isMinVersionSupported({
65
+ android: '5.208.0',
66
+ ios: '5.208.0',
67
+ });
68
+ if (!isSupported) {
69
+ return;
70
+ }
71
+
72
+ return AppsInTossModule.eventLog({
73
+ log_name: params.log_name,
74
+ log_type: params.log_type,
75
+ params: normalizeParams(params.params),
76
+ });
77
+ }
@@ -0,0 +1,88 @@
1
+ import { AppsInTossModule } from './AppsInTossModule';
2
+ import { requestPermission } from './requestPermission';
3
+ import { ImageResponse } from '../../types';
4
+
5
+ const DEFAULT_MAX_COUNT = 10;
6
+ const DEFAULT_MAX_WIDTH = 1024;
7
+
8
+ /**
9
+ * 앨범 사진을 조회할 때 사용하는 옵션 타입이에요.
10
+ */
11
+ export interface FetchAlbumPhotosOptions {
12
+ /** 가져올 사진의 최대 개수를 설정해요. 숫자를 입력하고 기본값은 10이에요. */
13
+ maxCount?: number;
14
+ /** 사진의 최대 폭을 제한해요. 단위는 픽셀이고 기본값은 1024이에요. */
15
+ maxWidth?: number;
16
+ /** 이미지를 base64 형식으로 반환할지 설정해요. 기본값은 `false`예요. */
17
+ base64?: boolean;
18
+ }
19
+
20
+ /**
21
+ * @public
22
+ * @category 사진
23
+ * @name fetchAlbumPhotos
24
+ * @description
25
+ * 사용자의 앨범에서 사진 목록을 불러오는 함수예요.
26
+ * 최대 개수와 해상도를 설정할 수 있고 갤러리 미리보기, 이미지 선택 기능 등에 활용할 수 있어요.
27
+ *
28
+ * @param options - 조회 옵션을 담은 객체예요.
29
+ * @param {number} [options.maxCount=10] 가져올 사진의 최대 개수를 설정해요. 숫자로 입력하며 기본값은 10이에요.
30
+ * @param {number} [options.maxWidth=1024] 사진의 최대 폭을 제한해요. 단위는 픽셀이며 기본값은 `1024`이에요.
31
+ * @param {boolean} [options.base64=false] 이미지를 base64 형식으로 반환할지 설정해요. 기본값은 `false`예요.
32
+ * @returns {Promise<ImageResponse[]>}
33
+ * 앨범 사진의 고유 ID와 데이터 URI를 포함한 배열을 반환해요.
34
+ *
35
+ * @example
36
+ * ### 사진의 최대 폭을 360px로 제한하여 가져오기
37
+ *
38
+ * ```tsx
39
+ * import React, { useState } from 'react';
40
+ * import { View, Image, Button } from 'react-native';
41
+ * import { fetchAlbumPhotos } from '@apps-in-toss/framework';
42
+ *
43
+ * const base64 = true;
44
+ *
45
+ * // 앨범 사진 목록을 가져와 화면에 표시하는 컴포넌트
46
+ * function AlbumPhotoList() {
47
+ * const [albumPhotos, setAlbumPhotos] = useState([]);
48
+ *
49
+ * const handlePress = async () => {
50
+ * try {
51
+ * const response = await fetchAlbumPhotos({
52
+ * base64,
53
+ * maxWidth: 360,
54
+ * });
55
+ * setAlbumPhotos((prev) => ([...prev, ...response]));
56
+ * } catch (error) {
57
+ * console.error('앨범을 가져오는 데 실패했어요:', error);
58
+ * }
59
+ * };
60
+ *
61
+ * return (
62
+ * <View>
63
+ * {albumPhotos.map((image) => {
64
+ * // base64 형식으로 반환된 이미지를 표시하려면 데이터 URL 스키마 Prefix를 붙여야해요.
65
+ * const imageUri = base64 ? 'data:image/jpeg;base64,' + image.dataUri : image.dataUri;
66
+ *
67
+ * return <Image source={{ uri: imageUri }} key={image.id} />;
68
+ * })}
69
+ * <Button title="앨범 가져오기" onPress={handlePress} />
70
+ * </View>
71
+ * );
72
+ * }
73
+ * ```
74
+ */
75
+ export async function fetchAlbumPhotos(options: FetchAlbumPhotosOptions): Promise<ImageResponse[]> {
76
+ const permissionStatus = await requestPermission({ name: 'photos', access: 'read' });
77
+ if (permissionStatus === 'denied') {
78
+ throw new Error('사진첩 권한이 거부되었어요.');
79
+ }
80
+
81
+ const albumPhotos = await AppsInTossModule.fetchAlbumPhotos({
82
+ ...options,
83
+ maxCount: options.maxCount ?? DEFAULT_MAX_COUNT,
84
+ maxWidth: options.maxWidth ?? DEFAULT_MAX_WIDTH,
85
+ });
86
+
87
+ return albumPhotos;
88
+ }
@@ -0,0 +1,121 @@
1
+ import { AppsInTossModule } from './AppsInTossModule';
2
+ import { requestPermission } from './requestPermission';
3
+
4
+ /**
5
+ * 연락처 정보를 나타내는 타입이에요.
6
+ */
7
+ export interface ContactEntity {
8
+ /** 연락처 이름이에요. */
9
+ name: string;
10
+ /** 연락처 전화번호로, 문자열 형식이에요. */
11
+ phoneNumber: string;
12
+ }
13
+
14
+ export interface ContactResult {
15
+ result: ContactEntity[];
16
+ nextOffset: number | null;
17
+ done: boolean;
18
+ }
19
+
20
+ /**
21
+ * @public
22
+ * @category 연락처
23
+ * @name fetchContacts
24
+ * @description 사용자의 연락처 목록을 페이지 단위로 가져오는 함수예요.
25
+ * @param options - 연락처를 가져올 때 지정하는 옵션 객체예요.
26
+ * @param options.size - 한 번에 가져올 연락처 개수예요. 예를 들어, 10을 전달하면 최대 10개의 연락처를 가져와요.
27
+ * @param options.offset - 가져올 연락처의 시작 지점이에요. 처음 호출할 때는 `0`을 전달해야 해요. 이후에는 이전 호출에서 반환된 `nextOffset` 값을 사용해요.
28
+ * @param options.query - 추가적인 필터링 옵션이에요.
29
+ * @param options.query.contains - 이름에 특정 문자열이 포함된 연락처만 가져오고 싶을 때 사용해요. 이 값을 전달하지 않으면 모든 연락처를 가져와요.
30
+ * @returns {Promise<ContactResult>}
31
+ * 연락처 목록과 페이지네이션 정보를 포함한 객체를 반환해요.
32
+ * - `result`: 가져온 연락처 목록이에요.
33
+ * - `nextOffset`: 다음 호출에 사용할 오프셋 값이에요. 더 가져올 연락처가 없으면 `null`이에요.
34
+ * - `done`: 모든 연락처를 다 가져왔는지 여부를 나타내요. 모두 가져왔다면 `true`예요.
35
+ *
36
+ * @signature
37
+ * ```typescript
38
+ * function fetchContacts(options: {
39
+ * size: number;
40
+ * offset: number;
41
+ * query?: {
42
+ * contains?: string;
43
+ * };
44
+ * }): Promise<ContactResult>;
45
+ * ```
46
+ *
47
+ * @example
48
+ * ### 특정 문자열이 포함된 연락처 목록 가져오기
49
+ *
50
+ * ```tsx
51
+ * import React, { useState } from 'react';
52
+ * import { View, Text, Button } from 'react-native';
53
+ * import { fetchContacts, ContactEntity } from '@apps-in-toss/framework';
54
+ *
55
+ * // 특정 문자열을 포함한 연락처 목록을 가져와 화면에 표시하는 컴포넌트
56
+ * function ContactsList() {
57
+ * const [contacts, setContacts] = useState<{
58
+ * result: ContactEntity[];
59
+ * nextOffset: number | null;
60
+ * done: boolean;
61
+ * }>({
62
+ * result: [],
63
+ * nextOffset: null,
64
+ * done: false,
65
+ * });
66
+ *
67
+ * const handlePress = async () => {
68
+ * try {
69
+ * if (contacts.done) {
70
+ * console.log('모든 연락처를 가져왔어요.');
71
+ * return;
72
+ * }
73
+ *
74
+ * const response = await fetchContacts({
75
+ * size: 10,
76
+ * offset: contacts.nextOffset ?? 0,
77
+ * query: { contains: '김' },
78
+ * });
79
+ * setContacts((prev) => ({
80
+ * result: [...prev.result, ...response.result],
81
+ * nextOffset: response.nextOffset,
82
+ * done: response.done,
83
+ * }));
84
+ * } catch (error) {
85
+ * console.error('연락처를 가져오는 데 실패했어요:', error);
86
+ * }
87
+ * };
88
+ *
89
+ * return (
90
+ * <View>
91
+ * {contacts.result.map((contact, index) => (
92
+ * <Text key={index}>{contact.name}: {contact.phoneNumber}</Text>
93
+ * ))}
94
+ * <Button
95
+ * title={contacts.done ? '모든 연락처를 가져왔어요.' : '다음 연락처 가져오기'}
96
+ * disabled={contacts.done}
97
+ * onPress={handlePress}
98
+ * />
99
+ * </View>
100
+ * );
101
+ * }
102
+ * ```
103
+ */
104
+ export async function fetchContacts(options: {
105
+ size: number;
106
+ offset: number;
107
+ query?: {
108
+ contains?: string;
109
+ };
110
+ }): Promise<ContactResult> {
111
+ const permissionStatus = await requestPermission({ name: 'contacts', access: 'read' });
112
+ if (permissionStatus === 'denied') {
113
+ throw new Error('연락처 권한이 거부되었어요.');
114
+ }
115
+ const contacts = await AppsInTossModule.fetchContacts(options);
116
+ return {
117
+ result: contacts.result,
118
+ nextOffset: contacts.nextOffset ?? null,
119
+ done: contacts.done,
120
+ };
121
+ }
@@ -0,0 +1,47 @@
1
+ import { AppsInTossModule } from './AppsInTossModule';
2
+ import { requestPermission } from './requestPermission';
3
+
4
+ /**
5
+ * @public
6
+ * @category 클립보드
7
+ * @name getClipboardText
8
+ * @description 클립보드에 저장된 텍스트를 가져오는 함수예요. 복사된 텍스트를 읽어서 다른 작업에 활용할 수 있어요.
9
+ * @returns {Promise<string>} - 클립보드에 저장된 텍스트를 반환해요. 클립보드에 텍스트가 없으면 빈 문자열을 반환해요.
10
+ *
11
+ * @example
12
+ * ### 클립보드의 텍스트 가져오기
13
+ *
14
+ * ```tsx
15
+ * import React, { useState } from 'react';
16
+ * import { View, Text, Button } from 'react-native';
17
+ * import { getClipboardText } from '@apps-in-toss/framework';
18
+ *
19
+ * // '붙여넣기' 버튼을 누르면 클립보드에 저장된 텍스트를 가져와 화면에 표시해요.
20
+ * function PasteButton() {
21
+ * const [text, setText] = useState('');
22
+ *
23
+ * const handlePress = async () => {
24
+ * try {
25
+ * const clipboardText = await getClipboardText();
26
+ * setText(clipboardText || '클립보드에 텍스트가 없어요.');
27
+ * } catch (error) {
28
+ * console.error('클립보드에서 텍스트를 가져오지 못했어요:', error);
29
+ * }
30
+ * };
31
+ *
32
+ * return (
33
+ * <View>
34
+ * <Text>{text}</Text>
35
+ * <Button title="붙여넣기" onPress={handlePress} />
36
+ * </View>
37
+ * );
38
+ * }
39
+ * ```
40
+ */
41
+ export async function getClipboardText(): Promise<string> {
42
+ const permissionStatus = await requestPermission({ name: 'clipboard', access: 'read' });
43
+ if (permissionStatus === 'denied') {
44
+ throw new Error('클립보드 읽기 권한이 거부되었어요.');
45
+ }
46
+ return AppsInTossModule.getClipboardText({});
47
+ }
@@ -0,0 +1,65 @@
1
+ import { AppsInTossModule } from './AppsInTossModule';
2
+ import { requestPermission } from './requestPermission';
3
+ import type { Accuracy, Location } from '../../types';
4
+
5
+ export interface GetCurrentLocationOptions {
6
+ /**
7
+ * 위치 정보를 가져올 정확도 수준이에요.
8
+ */
9
+ accuracy: Accuracy;
10
+ }
11
+ /**
12
+ * @public
13
+ * @category 위치 정보
14
+ * @name getCurrentLocation
15
+ * @description 디바이스의 현재 위치 정보를 가져오는 함수예요.
16
+ * 위치 기반 서비스를 구현할 때 사용되고, 한 번만 호출되어 현재 위치를 즉시 반환해요.
17
+ * 예를 들어 지도 앱에서 사용자의 현재 위치를 한 번만 가져올 때, 날씨 앱에서 사용자의 위치를 기반으로 기상 정보를 제공할 때, 매장 찾기 기능에서 사용자의 위치를 기준으로 가까운 매장을 검색할 때 사용하면 유용해요.
18
+ *
19
+ * @param {GetCurrentLocationOptions} options 위치 정보를 가져올 때 사용하는 옵션 객체예요.
20
+ * @param {Accuracy} [options.accuracy] 위치 정보의 정확도 수준이에요. 정확도는 `Accuracy` 타입으로 설정돼요.
21
+ * @returns {Promise<Location>} 디바이스의 위치 정보가 담긴 객체를 반환해요. 자세한 내용은 [Location](/react-native/reference/native-modules/Types/Location.html)을 참고해주세요.
22
+ *
23
+ * @example
24
+ * ### 디바이스의 현재 위치 정보 가져오기
25
+ *
26
+ * ```tsx
27
+ * import React, { useState } from 'react';
28
+ * import { View, Text, Button } from 'react-native';
29
+ * import { getCurrentLocation } from '@apps-in-toss/framework';
30
+ *
31
+ * // 현재 위치 정보를 가져와 화면에 표시하는 컴포넌트
32
+ * function CurrentPosition() {
33
+ * const [position, setPosition] = useState(null);
34
+ *
35
+ * const handlePress = async () => {
36
+ * try {
37
+ * const response = await getCurrentLocation({ accuracy: Accuracy.Balanced });
38
+ * setPosition(response);
39
+ * } catch (error) {
40
+ * console.error('위치 정보를 가져오는 데 실패했어요:', error);
41
+ * }
42
+ * };
43
+ *
44
+ * return (
45
+ * <View>
46
+ * {position ? (
47
+ * <Text>위치: {position.coords.latitude}, {position.coords.longitude}</Text>
48
+ * ) : (
49
+ * <Text>위치 정보를 아직 가져오지 않았어요</Text>
50
+ * )}
51
+ * <Button title="현재 위치 정보 가져오기" onPress={handlePress} />
52
+ * </View>
53
+ * );
54
+ * }
55
+ * ```
56
+ */
57
+ export async function getCurrentLocation(options: GetCurrentLocationOptions): Promise<Location> {
58
+ const permissionStatus = await requestPermission({ name: 'geolocation', access: 'access' });
59
+ if (permissionStatus === 'denied') {
60
+ throw new Error('위치 권한이 거부되었어요.');
61
+ }
62
+ const position = await AppsInTossModule.getCurrentLocation(options);
63
+
64
+ return position;
65
+ }