@apps-in-toss/framework 0.0.3 → 0.0.5

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.js CHANGED
@@ -1,33 +1,13 @@
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 __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- getClipboardText: () => getClipboardText,
24
- setClipboardText: () => setClipboardText
25
- });
26
- module.exports = __toCommonJS(src_exports);
1
+ // src/native-event-emitter/nativeEventEmitter.ts
2
+ import { NativeEventEmitter } from "react-native";
27
3
 
28
4
  // src/native-modules/AppsInTossModule.ts
29
- var import_react_native = require("react-native");
30
- var AppsInTossModule = import_react_native.NativeModules.AppsInTossModule;
5
+ import { NativeModules } from "react-native";
6
+ var AppsInTossModuleInstance = NativeModules.AppsInTossModule;
7
+ var AppsInTossModule = AppsInTossModuleInstance;
8
+
9
+ // src/native-event-emitter/nativeEventEmitter.ts
10
+ var nativeEventEmitter = new NativeEventEmitter(AppsInTossModuleInstance);
31
11
 
32
12
  // src/native-modules/getPermission.ts
33
13
  function getPermission(permission) {
@@ -51,6 +31,33 @@ async function requestPermission(permission) {
51
31
  }
52
32
  }
53
33
 
34
+ // src/native-event-emitter/startUpdateLocation.ts
35
+ async function startUpdateLocation(options) {
36
+ const { callback, ...nativeOptions } = options;
37
+ const permissionStatus = await requestPermission({ name: "geolocation", access: "access" });
38
+ if (permissionStatus === "denied") {
39
+ throw new Error("\uC704\uCE58 \uAD8C\uD55C\uC774 \uAC70\uBD80\uB418\uC5C8\uC5B4\uC694.");
40
+ }
41
+ await AppsInTossModuleInstance.startUpdateLocation(nativeOptions);
42
+ const subscription = nativeEventEmitter.addListener("updateLocation", callback);
43
+ subscriptionCount++;
44
+ const subscriptionProxy = new Proxy(subscription, {
45
+ get: (target, key, receiver) => {
46
+ const result = Reflect.get(target, key, receiver);
47
+ if (key === "remove") {
48
+ return async () => {
49
+ await (--subscriptionCount === 0 && AppsInTossModuleInstance.stopUpdateLocation({}));
50
+ const remove = result;
51
+ remove();
52
+ };
53
+ }
54
+ return result;
55
+ }
56
+ });
57
+ return subscriptionProxy;
58
+ }
59
+ var subscriptionCount = 0;
60
+
54
61
  // src/native-modules/setClipboardText.ts
55
62
  async function setClipboardText(text) {
56
63
  const permissionStatus = await requestPermission({ name: "clipboard", access: "write" });
@@ -68,8 +75,158 @@ async function getClipboardText() {
68
75
  }
69
76
  return AppsInTossModule.getClipboardText({});
70
77
  }
71
- // Annotate the CommonJS export names for ESM import in node:
72
- 0 && (module.exports = {
78
+
79
+ // src/native-modules/fetchContacts.ts
80
+ async function fetchContacts({
81
+ size,
82
+ offset,
83
+ query
84
+ }) {
85
+ const permissionStatus = await requestPermission({ name: "contacts", access: "read" });
86
+ if (permissionStatus === "denied") {
87
+ throw new Error("\uC5F0\uB77D\uCC98 \uAD8C\uD55C\uC774 \uAC70\uBD80\uB418\uC5C8\uC5B4\uC694.");
88
+ }
89
+ const contacts = await AppsInTossModule.fetchContacts({
90
+ size,
91
+ offset,
92
+ query
93
+ });
94
+ return {
95
+ result: contacts.result,
96
+ nextOffset: contacts.nextOffset ?? null,
97
+ done: contacts.done
98
+ };
99
+ }
100
+
101
+ // src/native-modules/fetchAlbumPhotos.ts
102
+ var DEFAULT_MAX_COUNT = 10;
103
+ var DEFAULT_MAX_WIDTH = 1024;
104
+ async function fetchAlbumPhotos(options) {
105
+ const permissionStatus = await requestPermission({ name: "photos", access: "read" });
106
+ if (permissionStatus === "denied") {
107
+ throw new Error("\uC0AC\uC9C4\uCCA9 \uAD8C\uD55C\uC774 \uAC70\uBD80\uB418\uC5C8\uC5B4\uC694.");
108
+ }
109
+ const albumPhotos = await AppsInTossModule.fetchAlbumPhotos({
110
+ ...options,
111
+ maxCount: options.maxCount ?? DEFAULT_MAX_COUNT,
112
+ maxWidth: options.maxWidth ?? DEFAULT_MAX_WIDTH
113
+ });
114
+ return albumPhotos;
115
+ }
116
+
117
+ // src/native-modules/getCurrentLocation.ts
118
+ async function getCurrentLocation(options) {
119
+ const permissionStatus = await requestPermission({ name: "geolocation", access: "access" });
120
+ if (permissionStatus === "denied") {
121
+ throw new Error("\uC704\uCE58 \uAD8C\uD55C\uC774 \uAC70\uBD80\uB418\uC5C8\uC5B4\uC694.");
122
+ }
123
+ const position = await AppsInTossModule.getCurrentLocation(options);
124
+ return position;
125
+ }
126
+
127
+ // src/native-modules/openCamera.ts
128
+ async function openCamera(options) {
129
+ const permissionStatus = await requestPermission({ name: "camera", access: "access" });
130
+ if (permissionStatus === "denied") {
131
+ throw new Error("\uCE74\uBA54\uB77C \uAD8C\uD55C\uC774 \uAC70\uBD80\uB418\uC5C8\uC5B4\uC694.");
132
+ }
133
+ const photo = await AppsInTossModule.openCamera({ base64: false, maxWidth: 1024, ...options });
134
+ return photo;
135
+ }
136
+
137
+ // src/components/WebView.tsx
138
+ import {
139
+ WebView as OriginalWebView
140
+ } from "@react-native-bedrock/native/react-native-webview";
141
+ import { useMemo } from "react";
142
+ import { Bedrock } from "react-native-bedrock";
143
+
144
+ // src/components/getAppsInTossWebViewUrl.tsx
145
+ function getAppsInTossWebViewUrl({
146
+ appName,
147
+ groupId,
148
+ localhostPort,
149
+ env
150
+ }) {
151
+ if (env === "local") {
152
+ return `http://localhost:${localhostPort}`;
153
+ }
154
+ const subdomain = env === "alpha" ? "alpha-apps" : "apps";
155
+ return `https://${appName}--${groupId}.${subdomain}.tossmini.com`;
156
+ }
157
+
158
+ // src/components/WebView.tsx
159
+ import { jsx } from "react/jsx-runtime";
160
+ function WebView({ env, localhostPort = 5173, ...props }) {
161
+ const uri = useMemo(() => {
162
+ const $env = env ?? (__DEV__ ? "local" : AppsInTossModule.operationalEnvironment === "sandbox" ? "alpha" : "production");
163
+ return getAppsInTossWebViewUrl({
164
+ appName: Bedrock.appName,
165
+ groupId: AppsInTossModule.groupId,
166
+ localhostPort,
167
+ env: $env
168
+ });
169
+ }, [env, localhostPort]);
170
+ return /* @__PURE__ */ jsx(OriginalWebView, { source: { uri }, ...props });
171
+ }
172
+
173
+ // src/hooks/useGeolocation.ts
174
+ import { useState, useCallback, useEffect, useRef } from "react";
175
+ import { useVisibility } from "react-native-bedrock";
176
+ function useGeolocation({ accuracy, distanceInterval, timeInterval }) {
177
+ const isVisible = useVisibility();
178
+ const subscriptionRef = useRef();
179
+ const [location, setLocation] = useState(null);
180
+ const subscribe = useCallback(async () => {
181
+ try {
182
+ const subscription = await startUpdateLocation({
183
+ accuracy,
184
+ distanceInterval,
185
+ timeInterval,
186
+ callback: setLocation
187
+ });
188
+ subscriptionRef.current = subscription;
189
+ } catch (error) {
190
+ console.error("failed to subscribe location", error);
191
+ }
192
+ }, [accuracy, distanceInterval, timeInterval]);
193
+ const cleanup = useCallback(async () => {
194
+ try {
195
+ const prevSubscription = subscriptionRef.current;
196
+ subscriptionRef.current = void 0;
197
+ await prevSubscription?.remove();
198
+ } catch (error) {
199
+ console.error("failed to cleanup location subscription", error);
200
+ }
201
+ }, []);
202
+ useEffect(() => {
203
+ if (subscriptionRef.current == null && isVisible) {
204
+ subscribe();
205
+ }
206
+ return () => void cleanup();
207
+ }, [subscribe, cleanup, isVisible]);
208
+ return location;
209
+ }
210
+
211
+ // src/types.ts
212
+ var Accuracy = /* @__PURE__ */ ((Accuracy2) => {
213
+ Accuracy2[Accuracy2["Lowest"] = 1] = "Lowest";
214
+ Accuracy2[Accuracy2["Low"] = 2] = "Low";
215
+ Accuracy2[Accuracy2["Balanced"] = 3] = "Balanced";
216
+ Accuracy2[Accuracy2["High"] = 4] = "High";
217
+ Accuracy2[Accuracy2["Highest"] = 5] = "Highest";
218
+ Accuracy2[Accuracy2["BestForNavigation"] = 6] = "BestForNavigation";
219
+ return Accuracy2;
220
+ })(Accuracy || {});
221
+ export {
222
+ Accuracy,
223
+ WebView,
224
+ fetchAlbumPhotos,
225
+ fetchContacts,
73
226
  getClipboardText,
74
- setClipboardText
75
- });
227
+ getCurrentLocation,
228
+ openCamera,
229
+ setClipboardText,
230
+ startUpdateLocation,
231
+ useGeolocation
232
+ };
package/package.json CHANGED
@@ -1,42 +1,50 @@
1
1
  {
2
2
  "name": "@apps-in-toss/framework",
3
- "version": "0.0.3",
3
+ "type": "module",
4
+ "version": "0.0.5",
4
5
  "description": "Hub package for Apps In Toss",
5
6
  "scripts": {
6
7
  "prepack": "yarn build",
7
8
  "typecheck": "tsc --noEmit",
9
+ "test": "vitest --run",
8
10
  "lint": "eslint .",
9
- "build": "tsup src/index.ts src/cli-presets.ts --format cjs --dts"
11
+ "build": "tsup src/index.ts src/cli-presets.ts --format esm,cjs --dts"
10
12
  },
11
- "main": "./dist/index.js",
13
+ "main": "./dist/index.cjs",
14
+ "module": "./dist/index.js",
12
15
  "types": "./dist/index.d.ts",
13
16
  "exports": {
14
17
  ".": {
15
18
  "types": "./dist/index.d.ts",
16
- "default": "./dist/index.js"
19
+ "import": "./dist/index.js",
20
+ "require": "./dist/index.cjs"
17
21
  },
18
22
  "./cli-presets": {
19
23
  "types": "./dist/cli-presets.d.ts",
20
- "default": "./dist/cli-presets.js"
24
+ "import": "./dist/cli-presets.js",
25
+ "require": "./dist/cli-presets.cjs"
21
26
  },
22
27
  "./package.json": "./package.json"
23
28
  },
24
- "packageManager": "yarn@4.3.1",
25
29
  "files": [
26
- "dist/**/*.js",
27
- "dist/**/*.d.ts"
30
+ "dist/**/*"
28
31
  ],
29
32
  "dependencies": {
30
- "@apps-in-toss/cli-presets": "0.0.3"
33
+ "@apps-in-toss/cli-presets": "0.0.5"
31
34
  },
32
35
  "devDependencies": {
36
+ "@react-native-bedrock/native": "0.0.10",
37
+ "@types/react": "18.3.3",
33
38
  "eslint": "^9.7.0",
34
39
  "react": "18.2.0",
35
40
  "react-native": "0.72.6",
41
+ "react-native-bedrock": "0.0.10",
36
42
  "tsup": "^8.3.5",
37
- "typescript": "4.9.5"
43
+ "typescript": "4.9.5",
44
+ "vitest": "^3.0.3"
38
45
  },
39
46
  "peerDependencies": {
47
+ "@react-native-bedrock/native": "*",
40
48
  "react": "*",
41
49
  "react-native": "*",
42
50
  "react-native-bedrock": "*"
@@ -44,5 +52,5 @@
44
52
  "publishConfig": {
45
53
  "access": "public"
46
54
  },
47
- "gitHead": "ec5897db672f36341a867e508eab033a51adfdad"
55
+ "gitHead": "1f2a93c6e928096e0626a0f99167fe617d85c722"
48
56
  }