@intoss/shared 0.0.14 → 0.0.15
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 +1 -522
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,522 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
-
var __spreadValues = (a, b) => {
|
|
12
|
-
for (var prop in b || (b = {}))
|
|
13
|
-
if (__hasOwnProp.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
if (__getOwnPropSymbols)
|
|
16
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
-
if (__propIsEnum.call(b, prop))
|
|
18
|
-
__defNormalProp(a, prop, b[prop]);
|
|
19
|
-
}
|
|
20
|
-
return a;
|
|
21
|
-
};
|
|
22
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
-
var __export = (target, all) => {
|
|
24
|
-
for (var name in all)
|
|
25
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
|
-
};
|
|
27
|
-
var __copyProps = (to, from, except, desc) => {
|
|
28
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
-
for (let key of __getOwnPropNames(from))
|
|
30
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
31
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
|
-
}
|
|
33
|
-
return to;
|
|
34
|
-
};
|
|
35
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
-
var __async = (__this, __arguments, generator) => {
|
|
37
|
-
return new Promise((resolve, reject) => {
|
|
38
|
-
var fulfilled = (value) => {
|
|
39
|
-
try {
|
|
40
|
-
step(generator.next(value));
|
|
41
|
-
} catch (e) {
|
|
42
|
-
reject(e);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
var rejected = (value) => {
|
|
46
|
-
try {
|
|
47
|
-
step(generator.throw(value));
|
|
48
|
-
} catch (e) {
|
|
49
|
-
reject(e);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
53
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
// src/index.ts
|
|
58
|
-
var index_exports = {};
|
|
59
|
-
__export(index_exports, {
|
|
60
|
-
AdGroupProvider: () => AdGroupProvider,
|
|
61
|
-
AuthStateProvider: () => AuthStateProvider,
|
|
62
|
-
ConfigProvider: () => ConfigProvider,
|
|
63
|
-
FetcherProvider: () => FetcherProvider,
|
|
64
|
-
QueryProvider: () => QueryProvider,
|
|
65
|
-
bind: () => bind,
|
|
66
|
-
calculateDay: () => calculateDay,
|
|
67
|
-
calculateDayOfWeek: () => calculateDayOfWeek,
|
|
68
|
-
calculateHour: () => calculateHour,
|
|
69
|
-
calculateMinute: () => calculateMinute,
|
|
70
|
-
calculateWeek: () => calculateWeek,
|
|
71
|
-
useAdGroup: () => useAdGroup,
|
|
72
|
-
useAdvertisement: () => useAdvertisement,
|
|
73
|
-
useAuthState: () => useAuthState,
|
|
74
|
-
useConfig: () => useConfig,
|
|
75
|
-
useFetcher: () => useFetcher,
|
|
76
|
-
useSignInWithToss: () => useSignInWithToss,
|
|
77
|
-
useStorage: () => useStorage
|
|
78
|
-
});
|
|
79
|
-
module.exports = __toCommonJS(index_exports);
|
|
80
|
-
|
|
81
|
-
// src/config/ConfigContext/ConfigContext.tsx
|
|
82
|
-
var import_react = require("react");
|
|
83
|
-
|
|
84
|
-
// src/config/ConfigContext/constant.ts
|
|
85
|
-
var import_framework = require("@apps-in-toss/framework");
|
|
86
|
-
var RUNNING_ENVIRONMENT = (0, import_framework.getOperationalEnvironment)() === "sandbox" ? "local" : (0, import_framework.getSchemeUri)().startsWith("intoss-private") ? "preview" : "production";
|
|
87
|
-
var API_ENDPOINT = {
|
|
88
|
-
local: "http://localhost:3000",
|
|
89
|
-
preview: "https://preview-api.intoss.app",
|
|
90
|
-
production: "https://api.intoss.app"
|
|
91
|
-
}[RUNNING_ENVIRONMENT];
|
|
92
|
-
|
|
93
|
-
// src/config/ConfigContext/ConfigContext.tsx
|
|
94
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
95
|
-
var ConfigContext = (0, import_react.createContext)({
|
|
96
|
-
appName: "",
|
|
97
|
-
apiEndpoint: "http://localhost:3000",
|
|
98
|
-
runningEnvironment: "local"
|
|
99
|
-
});
|
|
100
|
-
var ConfigProvider = ({ appName, children }) => {
|
|
101
|
-
const contextValue = (0, import_react.useMemo)(
|
|
102
|
-
() => ({
|
|
103
|
-
appName,
|
|
104
|
-
apiEndpoint: API_ENDPOINT,
|
|
105
|
-
runningEnvironment: RUNNING_ENVIRONMENT
|
|
106
|
-
}),
|
|
107
|
-
[appName]
|
|
108
|
-
);
|
|
109
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ConfigContext.Provider, { value: contextValue, children });
|
|
110
|
-
};
|
|
111
|
-
var useConfig = () => (0, import_react.useContext)(ConfigContext);
|
|
112
|
-
|
|
113
|
-
// src/advertisement/AdGroupContext/AdGroupContext.tsx
|
|
114
|
-
var import_react2 = require("react");
|
|
115
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
116
|
-
var AdGroupContext = (0, import_react2.createContext)({
|
|
117
|
-
getInterstitialAdGroup: () => ({ id: "ait-ad-test-interstitial-id", type: "interstitial" }),
|
|
118
|
-
getRewardedAdGroup: () => ({ id: "ait-ad-test-rewarded-id", type: "rewarded" })
|
|
119
|
-
});
|
|
120
|
-
var AdGroupProvider = ({ initial, children }) => {
|
|
121
|
-
const { appName, runningEnvironment } = useConfig();
|
|
122
|
-
const [initialized, setInitialized] = (0, import_react2.useState)(runningEnvironment !== "production");
|
|
123
|
-
const [adGroupList, setAdGroupList] = (0, import_react2.useState)(initial);
|
|
124
|
-
const getInterstitialAdGroup = (0, import_react2.useCallback)(
|
|
125
|
-
(key) => {
|
|
126
|
-
var _a;
|
|
127
|
-
return {
|
|
128
|
-
id: (_a = adGroupList[key]) != null ? _a : "ait-ad-test-interstitial-id",
|
|
129
|
-
type: "interstitial"
|
|
130
|
-
};
|
|
131
|
-
},
|
|
132
|
-
[adGroupList]
|
|
133
|
-
);
|
|
134
|
-
const getRewardedAdGroup = (0, import_react2.useCallback)(
|
|
135
|
-
(key) => {
|
|
136
|
-
var _a;
|
|
137
|
-
return {
|
|
138
|
-
id: (_a = adGroupList[key]) != null ? _a : "ait-ad-test-rewarded-id",
|
|
139
|
-
type: "rewarded"
|
|
140
|
-
};
|
|
141
|
-
},
|
|
142
|
-
[adGroupList]
|
|
143
|
-
);
|
|
144
|
-
const contextValue = (0, import_react2.useMemo)(
|
|
145
|
-
() => ({
|
|
146
|
-
getInterstitialAdGroup,
|
|
147
|
-
getRewardedAdGroup
|
|
148
|
-
}),
|
|
149
|
-
[getInterstitialAdGroup, getRewardedAdGroup]
|
|
150
|
-
);
|
|
151
|
-
(0, import_react2.useEffect)(() => {
|
|
152
|
-
if (initialized) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
const controller = new AbortController();
|
|
156
|
-
const timeoutId = setTimeout(() => controller.abort(), 3e3);
|
|
157
|
-
fetch(`https://static.intoss.app/${appName}/assets/adGroupList.json`, {
|
|
158
|
-
signal: controller.signal
|
|
159
|
-
}).then((res) => res.json()).then(setAdGroupList).finally(() => {
|
|
160
|
-
clearTimeout(timeoutId);
|
|
161
|
-
setInitialized(true);
|
|
162
|
-
});
|
|
163
|
-
}, [appName, initialized]);
|
|
164
|
-
if (!initialized) {
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AdGroupContext.Provider, { value: contextValue, children });
|
|
168
|
-
};
|
|
169
|
-
var useAdGroup = () => (0, import_react2.useContext)(AdGroupContext);
|
|
170
|
-
|
|
171
|
-
// src/advertisement/useAdvertisement/useAdvertisement.ts
|
|
172
|
-
var import_framework2 = require("@apps-in-toss/framework");
|
|
173
|
-
var import_react3 = require("react");
|
|
174
|
-
var useAdvertisement = ({
|
|
175
|
-
primaryAdGroup,
|
|
176
|
-
secondaryAdGroup,
|
|
177
|
-
onShowAd,
|
|
178
|
-
onDissmissAd
|
|
179
|
-
}) => {
|
|
180
|
-
const [initialized, setInitialized] = (0, import_react3.useState)(false);
|
|
181
|
-
const [adLoaded, setAdLoaded] = (0, import_react3.useState)(false);
|
|
182
|
-
const [adGroupId, setAdGroupId] = (0, import_react3.useState)();
|
|
183
|
-
const [adCleanup, setAdCleanup] = (0, import_react3.useState)(null);
|
|
184
|
-
const loadAd = (0, import_react3.useCallback)(
|
|
185
|
-
(adGroupId2) => new Promise((resolve) => {
|
|
186
|
-
const cleanup = import_framework2.GoogleAdMob.loadAppsInTossAdMob({
|
|
187
|
-
options: {
|
|
188
|
-
adGroupId: adGroupId2
|
|
189
|
-
},
|
|
190
|
-
onEvent: (event) => {
|
|
191
|
-
switch (event.type) {
|
|
192
|
-
case "loaded":
|
|
193
|
-
resolve([true, cleanup]);
|
|
194
|
-
break;
|
|
195
|
-
}
|
|
196
|
-
},
|
|
197
|
-
onError: () => resolve([false, cleanup])
|
|
198
|
-
});
|
|
199
|
-
}),
|
|
200
|
-
[]
|
|
201
|
-
);
|
|
202
|
-
const loadWaterfall = (0, import_react3.useCallback)(() => __async(null, null, function* () {
|
|
203
|
-
if (import_framework2.GoogleAdMob.loadAppsInTossAdMob.isSupported() !== true) {
|
|
204
|
-
setInitialized(true);
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
if (adLoaded) {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
const [primaryAdLoaded, primaryAdCleanup] = yield loadAd(primaryAdGroup.id);
|
|
211
|
-
if (primaryAdLoaded) {
|
|
212
|
-
setInitialized(true);
|
|
213
|
-
setAdLoaded(true);
|
|
214
|
-
setAdGroupId(primaryAdGroup.id);
|
|
215
|
-
setAdCleanup(() => primaryAdCleanup);
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
primaryAdCleanup();
|
|
219
|
-
if (!secondaryAdGroup) {
|
|
220
|
-
setInitialized(true);
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
const [secondaryAdLoaded, secondaryAdCleanup] = yield loadAd(secondaryAdGroup.id);
|
|
224
|
-
if (secondaryAdLoaded) {
|
|
225
|
-
setInitialized(true);
|
|
226
|
-
setAdLoaded(true);
|
|
227
|
-
setAdGroupId(secondaryAdGroup.id);
|
|
228
|
-
setAdCleanup(() => secondaryAdCleanup);
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
secondaryAdCleanup();
|
|
232
|
-
setInitialized(true);
|
|
233
|
-
}), [primaryAdGroup, secondaryAdGroup, adLoaded, loadAd]);
|
|
234
|
-
const cleanupAd = (0, import_react3.useCallback)(() => {
|
|
235
|
-
adCleanup == null ? void 0 : adCleanup();
|
|
236
|
-
setAdLoaded(false);
|
|
237
|
-
setAdGroupId(void 0);
|
|
238
|
-
setAdCleanup(null);
|
|
239
|
-
}, [adCleanup]);
|
|
240
|
-
const showAd = (0, import_react3.useCallback)(() => {
|
|
241
|
-
if (import_framework2.GoogleAdMob.loadAppsInTossAdMob.isSupported() !== true) {
|
|
242
|
-
onShowAd == null ? void 0 : onShowAd();
|
|
243
|
-
onDissmissAd == null ? void 0 : onDissmissAd();
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
if (!adLoaded || !adGroupId) {
|
|
247
|
-
onShowAd == null ? void 0 : onShowAd();
|
|
248
|
-
onDissmissAd == null ? void 0 : onDissmissAd();
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
import_framework2.GoogleAdMob.showAppsInTossAdMob({
|
|
252
|
-
options: {
|
|
253
|
-
adGroupId
|
|
254
|
-
},
|
|
255
|
-
onEvent: (event) => {
|
|
256
|
-
switch (event.type) {
|
|
257
|
-
case "show":
|
|
258
|
-
if (adGroupId === primaryAdGroup.id && primaryAdGroup.type === "interstitial" || adGroupId === (secondaryAdGroup == null ? void 0 : secondaryAdGroup.id) && secondaryAdGroup.type === "interstitial") {
|
|
259
|
-
onShowAd == null ? void 0 : onShowAd();
|
|
260
|
-
}
|
|
261
|
-
break;
|
|
262
|
-
case "failedToShow":
|
|
263
|
-
onShowAd == null ? void 0 : onShowAd();
|
|
264
|
-
cleanupAd();
|
|
265
|
-
break;
|
|
266
|
-
case "dismissed":
|
|
267
|
-
onDissmissAd == null ? void 0 : onDissmissAd();
|
|
268
|
-
cleanupAd();
|
|
269
|
-
break;
|
|
270
|
-
case "userEarnedReward":
|
|
271
|
-
onShowAd == null ? void 0 : onShowAd();
|
|
272
|
-
break;
|
|
273
|
-
}
|
|
274
|
-
},
|
|
275
|
-
onError: () => {
|
|
276
|
-
onShowAd == null ? void 0 : onShowAd();
|
|
277
|
-
cleanupAd();
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
}, [adLoaded, adGroupId, primaryAdGroup, secondaryAdGroup, onShowAd, onDissmissAd, cleanupAd]);
|
|
281
|
-
(0, import_react3.useEffect)(() => {
|
|
282
|
-
if (!adGroupId) {
|
|
283
|
-
loadWaterfall();
|
|
284
|
-
}
|
|
285
|
-
}, [adGroupId, loadWaterfall]);
|
|
286
|
-
(0, import_react3.useEffect)(() => () => cleanupAd(), []);
|
|
287
|
-
return {
|
|
288
|
-
initialized,
|
|
289
|
-
adLoaded,
|
|
290
|
-
showAd
|
|
291
|
-
};
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
// src/auth-state/AuthStateContext/AuthStateContext.tsx
|
|
295
|
-
var import_react_query = require("@tanstack/react-query");
|
|
296
|
-
var import_react4 = require("react");
|
|
297
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
298
|
-
var AuthStateContext = (0, import_react4.createContext)({
|
|
299
|
-
isPreparing: true,
|
|
300
|
-
isLoggedIn: false,
|
|
301
|
-
retry: () => Promise.resolve()
|
|
302
|
-
});
|
|
303
|
-
var AuthStateProvider = ({ children }) => {
|
|
304
|
-
const { data, isFetching, refetch } = (0, import_react_query.useQuery)({
|
|
305
|
-
queryKey: ["/my/user"]
|
|
306
|
-
});
|
|
307
|
-
const contextValue = (0, import_react4.useMemo)(
|
|
308
|
-
() => {
|
|
309
|
-
var _a;
|
|
310
|
-
return {
|
|
311
|
-
isPreparing: isFetching,
|
|
312
|
-
isLoggedIn: Boolean((_a = data == null ? void 0 : data.user) == null ? void 0 : _a.id),
|
|
313
|
-
retry: refetch
|
|
314
|
-
};
|
|
315
|
-
},
|
|
316
|
-
[data, isFetching, refetch]
|
|
317
|
-
);
|
|
318
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(AuthStateContext.Provider, { value: contextValue, children });
|
|
319
|
-
};
|
|
320
|
-
var useAuthState = () => (0, import_react4.useContext)(AuthStateContext);
|
|
321
|
-
|
|
322
|
-
// src/auth-state/useSignInWithToss/useSignInWithToss.ts
|
|
323
|
-
var import_framework4 = require("@apps-in-toss/framework");
|
|
324
|
-
|
|
325
|
-
// src/query/FetcherContext/FetcherContext.tsx
|
|
326
|
-
var import_framework3 = require("@apps-in-toss/framework");
|
|
327
|
-
var import_string = require("es-toolkit/string");
|
|
328
|
-
var import_react5 = require("react");
|
|
329
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
330
|
-
var KEY_TOKEN = "@auth/token";
|
|
331
|
-
var FetcherContext = (0, import_react5.createContext)({
|
|
332
|
-
fetcher: fetch,
|
|
333
|
-
setToken: () => null
|
|
334
|
-
});
|
|
335
|
-
var camelizeKeys = (input) => {
|
|
336
|
-
if (Array.isArray(input)) {
|
|
337
|
-
return input.map(camelizeKeys);
|
|
338
|
-
}
|
|
339
|
-
if (input !== null && typeof input === "object") {
|
|
340
|
-
return Object.fromEntries(
|
|
341
|
-
Object.entries(input).map(([key, value]) => [(0, import_string.camelCase)(key), camelizeKeys(value)])
|
|
342
|
-
);
|
|
343
|
-
}
|
|
344
|
-
return input;
|
|
345
|
-
};
|
|
346
|
-
var FetcherProvider = ({ baseUrl, children }) => {
|
|
347
|
-
const { appName, apiEndpoint } = useConfig();
|
|
348
|
-
const [token, setToken] = (0, import_react5.useState)(null);
|
|
349
|
-
const [initialized, setInitialized] = (0, import_react5.useState)(false);
|
|
350
|
-
const fetcher = (0, import_react5.useCallback)(
|
|
351
|
-
(input, init) => fetch(`${baseUrl != null ? baseUrl : apiEndpoint}/${appName}${input}`, __spreadProps(__spreadValues({}, init), {
|
|
352
|
-
headers: __spreadValues(__spreadValues({
|
|
353
|
-
"Content-Type": "application/json"
|
|
354
|
-
}, init == null ? void 0 : init.headers), token ? { Authorization: `Bearer ${token}` } : {})
|
|
355
|
-
})).then((res) => res.json()).then((data) => camelizeKeys(data)),
|
|
356
|
-
[appName, apiEndpoint, token, baseUrl]
|
|
357
|
-
);
|
|
358
|
-
(0, import_react5.useEffect)(() => {
|
|
359
|
-
import_framework3.Storage.getItem(KEY_TOKEN).then(setToken).finally(() => setInitialized(true));
|
|
360
|
-
}, []);
|
|
361
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(FetcherContext.Provider, { value: { fetcher, setToken }, children: initialized ? children : null });
|
|
362
|
-
};
|
|
363
|
-
var useFetcher = () => (0, import_react5.useContext)(FetcherContext);
|
|
364
|
-
|
|
365
|
-
// src/view-model/bind/bind.ts
|
|
366
|
-
var import_react6 = require("react");
|
|
367
|
-
var bind = (useViewModel, ViewComponent, options) => {
|
|
368
|
-
const { displayName } = options != null ? options : {};
|
|
369
|
-
const MemoizedViewComponent = (0, import_react6.memo)(ViewComponent);
|
|
370
|
-
const Component = (0, import_react6.memo)(
|
|
371
|
-
(props) => (0, import_react6.createElement)(
|
|
372
|
-
MemoizedViewComponent,
|
|
373
|
-
useViewModel(props)
|
|
374
|
-
)
|
|
375
|
-
);
|
|
376
|
-
Component.ViewComponent = MemoizedViewComponent;
|
|
377
|
-
if (displayName) {
|
|
378
|
-
Component.displayName = displayName;
|
|
379
|
-
Component.ViewComponent.displayName = `${displayName}View`;
|
|
380
|
-
}
|
|
381
|
-
return Component;
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
// src/query/QueryProvider/QueryProvider.tsx
|
|
385
|
-
var import_react_query3 = require("@tanstack/react-query");
|
|
386
|
-
|
|
387
|
-
// src/query/QueryProvider/useQueryProvider.ts
|
|
388
|
-
var import_react_query2 = require("@tanstack/react-query");
|
|
389
|
-
var import_react7 = require("react");
|
|
390
|
-
var useQueryProvider = ({ children }) => {
|
|
391
|
-
const { fetcher } = useFetcher();
|
|
392
|
-
const queryClient = (0, import_react7.useMemo)(
|
|
393
|
-
() => new import_react_query2.QueryClient({
|
|
394
|
-
defaultOptions: {
|
|
395
|
-
queries: {
|
|
396
|
-
queryFn: ({ queryKey }) => fetcher(queryKey[0])
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}),
|
|
400
|
-
[fetcher]
|
|
401
|
-
);
|
|
402
|
-
return {
|
|
403
|
-
queryClient,
|
|
404
|
-
children
|
|
405
|
-
};
|
|
406
|
-
};
|
|
407
|
-
|
|
408
|
-
// src/query/QueryProvider/QueryProvider.tsx
|
|
409
|
-
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
410
|
-
var QueryProvider = bind(useQueryProvider, ({ queryClient, children }) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_query3.QueryClientProvider, { client: queryClient, children }));
|
|
411
|
-
|
|
412
|
-
// src/auth-state/useSignInWithToss/useSignInWithToss.ts
|
|
413
|
-
var import_react_query4 = require("@tanstack/react-query");
|
|
414
|
-
var import_react8 = require("react");
|
|
415
|
-
var KEY_TOKEN2 = "@auth/token";
|
|
416
|
-
var useSignInWithToss = ({ onSuccess }) => {
|
|
417
|
-
const { retry } = useAuthState();
|
|
418
|
-
const { fetcher, setToken } = useFetcher();
|
|
419
|
-
const signInWithTossMutation = (0, import_react_query4.useMutation)({
|
|
420
|
-
mutationFn: (body) => __async(null, null, function* () {
|
|
421
|
-
return fetcher("/my/sessions", {
|
|
422
|
-
method: "POST",
|
|
423
|
-
body: JSON.stringify(body)
|
|
424
|
-
});
|
|
425
|
-
}),
|
|
426
|
-
onSuccess: (data) => __async(null, null, function* () {
|
|
427
|
-
setToken(data.token);
|
|
428
|
-
yield import_framework4.Storage.setItem(KEY_TOKEN2, data.token);
|
|
429
|
-
yield retry();
|
|
430
|
-
onSuccess == null ? void 0 : onSuccess();
|
|
431
|
-
})
|
|
432
|
-
});
|
|
433
|
-
const signInWithToss = (0, import_react8.useCallback)(() => __async(null, null, function* () {
|
|
434
|
-
const { authorizationCode, referrer } = yield (0, import_framework4.appLogin)();
|
|
435
|
-
signInWithTossMutation.mutate({
|
|
436
|
-
authorizationCode,
|
|
437
|
-
referrer
|
|
438
|
-
});
|
|
439
|
-
}), [signInWithTossMutation]);
|
|
440
|
-
return {
|
|
441
|
-
signInWithToss,
|
|
442
|
-
isLoading: signInWithTossMutation.isPending
|
|
443
|
-
};
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
// src/calendar/calculateDay/calculateDay.ts
|
|
447
|
-
var MS_PER_DAY = 864e5;
|
|
448
|
-
var KST_OFFSET_MS = 324e5;
|
|
449
|
-
var calculateDay = (timestamp) => Math.floor((timestamp + KST_OFFSET_MS) / MS_PER_DAY);
|
|
450
|
-
|
|
451
|
-
// src/calendar/calculateDayOfWeek/calculateDayOfWeek.ts
|
|
452
|
-
var KST_OFFSET_WEEKDAY = 3;
|
|
453
|
-
var calculateDayOfWeek = (day) => (day + KST_OFFSET_WEEKDAY) % 7;
|
|
454
|
-
|
|
455
|
-
// src/calendar/calculateHour/calculateHour.ts
|
|
456
|
-
var MS_PER_DAY2 = 864e5;
|
|
457
|
-
var MS_PER_HOUR = 36e5;
|
|
458
|
-
var KST_OFFSET_MS2 = 324e5;
|
|
459
|
-
var calculateHour = (timestamp) => Math.floor((timestamp + KST_OFFSET_MS2) % MS_PER_DAY2 / MS_PER_HOUR);
|
|
460
|
-
|
|
461
|
-
// src/calendar/calculateMinute/calculateMinute.ts
|
|
462
|
-
var MS_PER_HOUR2 = 36e5;
|
|
463
|
-
var MS_PER_MINUTE = 6e4;
|
|
464
|
-
var KST_OFFSET_MS3 = 324e5;
|
|
465
|
-
var calculateMinute = (timestamp) => Math.floor((timestamp + KST_OFFSET_MS3) % MS_PER_HOUR2 / MS_PER_MINUTE);
|
|
466
|
-
|
|
467
|
-
// src/calendar/calculateWeek/calculateWeek.ts
|
|
468
|
-
var KST_OFFSET_WEEKDAY2 = 3;
|
|
469
|
-
var calculateWeek = (day) => Math.floor((day + KST_OFFSET_WEEKDAY2) / 7);
|
|
470
|
-
|
|
471
|
-
// src/storage/useStorage/useStorage.ts
|
|
472
|
-
var import_framework5 = require("@apps-in-toss/framework");
|
|
473
|
-
var import_react9 = require("react");
|
|
474
|
-
var import_react_native = require("react-native");
|
|
475
|
-
var useStorage = (key) => {
|
|
476
|
-
const [stateValue, setStateValue] = (0, import_react9.useState)();
|
|
477
|
-
const [isLoading, setIsLoading] = (0, import_react9.useState)(true);
|
|
478
|
-
const updateValue = (0, import_react9.useCallback)(
|
|
479
|
-
(value) => {
|
|
480
|
-
setStateValue(value);
|
|
481
|
-
import_react_native.DeviceEventEmitter.emit(key, value);
|
|
482
|
-
return import_framework5.Storage.setItem(key, JSON.stringify({ value }));
|
|
483
|
-
},
|
|
484
|
-
[key]
|
|
485
|
-
);
|
|
486
|
-
(0, import_react9.useEffect)(() => {
|
|
487
|
-
setIsLoading(true);
|
|
488
|
-
import_framework5.Storage.getItem(key).then((item) => {
|
|
489
|
-
try {
|
|
490
|
-
setStateValue(item === null ? void 0 : JSON.parse(item).value);
|
|
491
|
-
} catch (e) {
|
|
492
|
-
setStateValue(void 0);
|
|
493
|
-
} finally {
|
|
494
|
-
setIsLoading(false);
|
|
495
|
-
}
|
|
496
|
-
});
|
|
497
|
-
const updateValueListener = import_react_native.DeviceEventEmitter.addListener(key, setStateValue);
|
|
498
|
-
return () => updateValueListener.remove();
|
|
499
|
-
}, [key]);
|
|
500
|
-
return [stateValue, updateValue, isLoading];
|
|
501
|
-
};
|
|
502
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
503
|
-
0 && (module.exports = {
|
|
504
|
-
AdGroupProvider,
|
|
505
|
-
AuthStateProvider,
|
|
506
|
-
ConfigProvider,
|
|
507
|
-
FetcherProvider,
|
|
508
|
-
QueryProvider,
|
|
509
|
-
bind,
|
|
510
|
-
calculateDay,
|
|
511
|
-
calculateDayOfWeek,
|
|
512
|
-
calculateHour,
|
|
513
|
-
calculateMinute,
|
|
514
|
-
calculateWeek,
|
|
515
|
-
useAdGroup,
|
|
516
|
-
useAdvertisement,
|
|
517
|
-
useAuthState,
|
|
518
|
-
useConfig,
|
|
519
|
-
useFetcher,
|
|
520
|
-
useSignInWithToss,
|
|
521
|
-
useStorage
|
|
522
|
-
});
|
|
1
|
+
"use strict";var k=Object.defineProperty,ve=Object.defineProperties,Me=Object.getOwnPropertyDescriptor,Fe=Object.getOwnPropertyDescriptors,Ve=Object.getOwnPropertyNames,ee=Object.getOwnPropertySymbols;var re=Object.prototype.hasOwnProperty,Se=Object.prototype.propertyIsEnumerable;var te=(e,r,t)=>r in e?k(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,b=(e,r)=>{for(var t in r||(r={}))re.call(r,t)&&te(e,t,r[t]);if(ee)for(var t of ee(r))Se.call(r,t)&&te(e,t,r[t]);return e},oe=(e,r)=>ve(e,Fe(r));var Ie=(e,r)=>{for(var t in r)k(e,t,{get:r[t],enumerable:!0})},Re=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of Ve(r))!re.call(e,n)&&n!==t&&k(e,n,{get:()=>r[n],enumerable:!(o=Me(r,n))||o.enumerable});return e};var Oe=e=>Re(k({},"__esModule",{value:!0}),e);var y=(e,r,t)=>new Promise((o,n)=>{var s=a=>{try{p(t.next(a))}catch(d){n(d)}},i=a=>{try{p(t.throw(a))}catch(d){n(d)}},p=a=>a.done?o(a.value):Promise.resolve(a.value).then(s,i);p((t=t.apply(e,r)).next())});var Ne={};Ie(Ne,{AdGroupProvider:()=>L,AuthStateProvider:()=>G,ConfigProvider:()=>K,FetcherProvider:()=>A,QueryProvider:()=>q,bind:()=>S,calculateDay:()=>$,calculateDayOfWeek:()=>U,calculateHour:()=>D,calculateMinute:()=>J,calculateWeek:()=>j,useAdGroup:()=>z,useAdvertisement:()=>Y,useAuthState:()=>F,useConfig:()=>x,useFetcher:()=>C,useSignInWithToss:()=>H,useStorage:()=>Z});module.exports=Oe(Ne);var h=require("react");var N=require("@apps-in-toss/framework"),w=(0,N.getOperationalEnvironment)()==="sandbox"?"local":(0,N.getSchemeUri)().startsWith("intoss-private")?"preview":"production",ne={local:"http://localhost:3000",preview:"https://preview-api.intoss.app",production:"https://api.intoss.app"}[w];var se=require("react/jsx-runtime"),ie=(0,h.createContext)({appName:"",apiEndpoint:"http://localhost:3000",runningEnvironment:"local"}),K=({appName:e,children:r})=>{let t=(0,h.useMemo)(()=>({appName:e,apiEndpoint:ne,runningEnvironment:w}),[e]);return(0,se.jsx)(ie.Provider,{value:t,children:r})},x=()=>(0,h.useContext)(ie);var l=require("react"),pe=require("react/jsx-runtime"),ae=(0,l.createContext)({getInterstitialAdGroup:()=>({id:"ait-ad-test-interstitial-id",type:"interstitial"}),getRewardedAdGroup:()=>({id:"ait-ad-test-rewarded-id",type:"rewarded"})}),L=({initial:e,children:r})=>{let{appName:t,runningEnvironment:o}=x(),[n,s]=(0,l.useState)(o!=="production"),[i,p]=(0,l.useState)(e),a=(0,l.useCallback)(u=>{var m;return{id:(m=i[u])!=null?m:"ait-ad-test-interstitial-id",type:"interstitial"}},[i]),d=(0,l.useCallback)(u=>{var m;return{id:(m=i[u])!=null?m:"ait-ad-test-rewarded-id",type:"rewarded"}},[i]),f=(0,l.useMemo)(()=>({getInterstitialAdGroup:a,getRewardedAdGroup:d}),[a,d]);return(0,l.useEffect)(()=>{if(n)return;let u=new AbortController,m=setTimeout(()=>u.abort(),3e3);fetch(`https://static.intoss.app/${t}/assets/adGroupList.json`,{signal:u.signal}).then(I=>I.json()).then(p).finally(()=>{clearTimeout(m),s(!0)})},[t,n]),n?(0,pe.jsx)(ae.Provider,{value:f,children:r}):null},z=()=>(0,l.useContext)(ae);var M=require("@apps-in-toss/framework"),c=require("react");var Y=({primaryAdGroup:e,secondaryAdGroup:r,onShowAd:t,onDissmissAd:o})=>{let[n,s]=(0,c.useState)(!1),[i,p]=(0,c.useState)(!1),[a,d]=(0,c.useState)(),[f,u]=(0,c.useState)(null),m=(0,c.useCallback)(T=>new Promise(v=>{let R=M.GoogleAdMob.loadAppsInTossAdMob({options:{adGroupId:T},onEvent:O=>{switch(O.type){case"loaded":v([!0,R]);break}},onError:()=>v([!1,R])})}),[]),I=(0,c.useCallback)(()=>y(null,null,function*(){if(M.GoogleAdMob.loadAppsInTossAdMob.isSupported()!==!0){s(!0);return}if(i)return;let[T,v]=yield m(e.id);if(T){s(!0),p(!0),d(e.id),u(()=>v);return}if(v(),!r){s(!0);return}let[R,O]=yield m(r.id);if(R){s(!0),p(!0),d(r.id),u(()=>O);return}O(),s(!0)}),[e,r,i,m]),_=(0,c.useCallback)(()=>{f==null||f(),p(!1),d(void 0),u(null)},[f]),Te=(0,c.useCallback)(()=>{if(M.GoogleAdMob.loadAppsInTossAdMob.isSupported()!==!0){t==null||t(),o==null||o();return}if(!i||!a){t==null||t(),o==null||o();return}M.GoogleAdMob.showAppsInTossAdMob({options:{adGroupId:a},onEvent:T=>{switch(T.type){case"show":(a===e.id&&e.type==="interstitial"||a===(r==null?void 0:r.id)&&r.type==="interstitial")&&(t==null||t());break;case"failedToShow":t==null||t(),_();break;case"dismissed":o==null||o(),_();break;case"userEarnedReward":t==null||t();break}},onError:()=>{t==null||t(),_()}})},[i,a,e,r,t,o,_]);return(0,c.useEffect)(()=>{a||I()},[a,I]),(0,c.useEffect)(()=>()=>_(),[]),{initialized:n,adLoaded:i,showAd:Te}};var ue=require("@tanstack/react-query"),E=require("react"),ce=require("react/jsx-runtime"),le=(0,E.createContext)({isPreparing:!0,isLoggedIn:!1,retry:()=>Promise.resolve()}),G=({children:e})=>{let{data:r,isFetching:t,refetch:o}=(0,ue.useQuery)({queryKey:["/my/user"]}),n=(0,E.useMemo)(()=>{var s;return{isPreparing:t,isLoggedIn:!!((s=r==null?void 0:r.user)!=null&&s.id),retry:o}},[r,t,o]);return(0,ce.jsx)(le.Provider,{value:n,children:e})},F=()=>(0,E.useContext)(le);var W=require("@apps-in-toss/framework");var de=require("@apps-in-toss/framework");var fe=require("es-toolkit/string"),g=require("react");var ge=require("react/jsx-runtime"),ke="@auth/token",me=(0,g.createContext)({fetcher:fetch,setToken:()=>null}),Q=e=>Array.isArray(e)?e.map(Q):e!==null&&typeof e=="object"?Object.fromEntries(Object.entries(e).map(([r,t])=>[(0,fe.camelCase)(r),Q(t)])):e,A=({baseUrl:e,children:r})=>{let{appName:t,apiEndpoint:o}=x(),[n,s]=(0,g.useState)(null),[i,p]=(0,g.useState)(!1),a=(0,g.useCallback)((d,f)=>fetch(`${e!=null?e:o}/${t}${d}`,oe(b({},f),{headers:b(b({"Content-Type":"application/json"},f==null?void 0:f.headers),n?{Authorization:`Bearer ${n}`}:{})})).then(u=>u.json()).then(u=>Q(u)),[t,o,n,e]);return(0,g.useEffect)(()=>{de.Storage.getItem(ke).then(s).finally(()=>p(!0))},[]),(0,ge.jsx)(me.Provider,{value:{fetcher:a,setToken:s},children:i?r:null})},C=()=>(0,g.useContext)(me);var V=require("react"),S=(e,r,t)=>{let{displayName:o}=t!=null?t:{},n=(0,V.memo)(r),s=(0,V.memo)(i=>(0,V.createElement)(n,e(i)));return s.ViewComponent=n,o&&(s.displayName=o,s.ViewComponent.displayName=`${o}View`),s};var ye=require("@tanstack/react-query");var xe=require("@tanstack/react-query"),Ce=require("react");var Pe=({children:e})=>{let{fetcher:r}=C();return{queryClient:(0,Ce.useMemo)(()=>new xe.QueryClient({defaultOptions:{queries:{queryFn:({queryKey:o})=>r(o[0])}}}),[r]),children:e}};var he=require("react/jsx-runtime"),q=S(Pe,({queryClient:e,children:r})=>(0,he.jsx)(ye.QueryClientProvider,{client:e,children:r}));var Ee=require("@tanstack/react-query"),_e=require("react");var be="@auth/token",H=({onSuccess:e})=>{let{retry:r}=F(),{fetcher:t,setToken:o}=C(),n=(0,Ee.useMutation)({mutationFn:i=>y(null,null,function*(){return t("/my/sessions",{method:"POST",body:JSON.stringify(i)})}),onSuccess:i=>y(null,null,function*(){o(i.token),yield W.Storage.setItem(be,i.token),yield r(),e==null||e()})});return{signInWithToss:(0,_e.useCallback)(()=>y(null,null,function*(){let{authorizationCode:i,referrer:p}=yield(0,W.appLogin)();n.mutate({authorizationCode:i,referrer:p})}),[n]),isLoading:n.isPending}};var $=e=>Math.floor((e+324e5)/864e5);var U=e=>(e+3)%7;var D=e=>Math.floor((e+324e5)%864e5/36e5);var J=e=>Math.floor((e+324e5)%36e5/6e4);var j=e=>Math.floor((e+3)/7);var B=require("@apps-in-toss/framework"),P=require("react"),X=require("react-native"),Z=e=>{let[r,t]=(0,P.useState)(),[o,n]=(0,P.useState)(!0),s=(0,P.useCallback)(i=>(t(i),X.DeviceEventEmitter.emit(e,i),B.Storage.setItem(e,JSON.stringify({value:i}))),[e]);return(0,P.useEffect)(()=>{n(!0),B.Storage.getItem(e).then(p=>{try{t(p===null?void 0:JSON.parse(p).value)}catch(a){t(void 0)}finally{n(!1)}});let i=X.DeviceEventEmitter.addListener(e,t);return()=>i.remove()},[e]),[r,s,o]};0&&(module.exports={AdGroupProvider,AuthStateProvider,ConfigProvider,FetcherProvider,QueryProvider,bind,calculateDay,calculateDayOfWeek,calculateHour,calculateMinute,calculateWeek,useAdGroup,useAdvertisement,useAuthState,useConfig,useFetcher,useSignInWithToss,useStorage});
|