@webority-technologies/mobile-core 0.0.1 → 0.0.3
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/README.md +22 -1
- package/lib/commonjs/api/baseUrl.js +34 -0
- package/lib/commonjs/api/curl.js +109 -0
- package/lib/commonjs/api/publicClient.js +11 -20
- package/lib/commonjs/api/retry.js +75 -0
- package/lib/commonjs/api/userClient.js +46 -22
- package/lib/commonjs/auth/authStore.js +101 -33
- package/lib/commonjs/auth/jwt.js +32 -8
- package/lib/commonjs/config/index.js +2 -1
- package/lib/commonjs/deepLink/index.js +286 -0
- package/lib/commonjs/download/adapters/expoFs.js +100 -0
- package/lib/commonjs/download/adapters/shared.js +13 -0
- package/lib/commonjs/download/index.js +272 -0
- package/lib/commonjs/formatters/date.js +1 -1
- package/lib/commonjs/formatters/index.js +24 -0
- package/lib/commonjs/formatters/phone.js +132 -15
- package/lib/commonjs/geolocation/adapters/expoLocation.js +126 -0
- package/lib/commonjs/geolocation/index.js +339 -0
- package/lib/commonjs/index.js +151 -48
- package/lib/commonjs/initSDK.js +23 -2
- package/lib/commonjs/initUserAuth.js +2 -1
- package/lib/commonjs/logger/index.js +159 -5
- package/lib/commonjs/network/index.js +6 -0
- package/lib/commonjs/network/networkStatus.js +50 -15
- package/lib/commonjs/permissions/index.js +24 -1
- package/lib/commonjs/sqlite/adapters/expo.js +53 -0
- package/lib/commonjs/sqlite/adapters/op.js +43 -0
- package/lib/commonjs/sqlite/adapters/rows.js +33 -0
- package/lib/commonjs/sqlite/adapters/storage.js +50 -0
- package/lib/commonjs/sqlite/adapters/sync.js +45 -0
- package/lib/commonjs/sqlite/index.js +610 -0
- package/lib/commonjs/sqlite/nitro.js +17 -0
- package/lib/commonjs/sqlite/op.js +18 -0
- package/lib/commonjs/sqlite/quick.js +14 -0
- package/lib/commonjs/sqlite/storage.js +14 -0
- package/lib/commonjs/storage/index.js +41 -20
- package/lib/commonjs/types/globals.d.js +6 -0
- package/lib/commonjs/utils/imageCompression.js +51 -14
- package/lib/commonjs/utils/index.js +6 -0
- package/lib/commonjs/versionCheck/index.js +28 -4
- package/lib/module/api/baseUrl.js +30 -0
- package/lib/module/api/curl.js +104 -0
- package/lib/module/api/publicClient.js +11 -20
- package/lib/module/api/retry.js +69 -0
- package/lib/module/api/userClient.js +45 -21
- package/lib/module/auth/authStore.js +99 -32
- package/lib/module/auth/jwt.js +32 -8
- package/lib/module/config/index.js +2 -1
- package/lib/module/deepLink/index.js +280 -0
- package/lib/module/download/adapters/expoFs.js +95 -0
- package/lib/module/download/adapters/shared.js +8 -0
- package/lib/module/download/index.js +264 -0
- package/lib/module/formatters/date.js +1 -1
- package/lib/module/formatters/index.js +1 -1
- package/lib/module/formatters/phone.js +110 -13
- package/lib/module/geolocation/adapters/expoLocation.js +121 -0
- package/lib/module/geolocation/index.js +332 -0
- package/lib/module/index.js +28 -11
- package/lib/module/initSDK.js +23 -2
- package/lib/module/initUserAuth.js +2 -1
- package/lib/module/logger/index.js +156 -4
- package/lib/module/network/index.js +1 -1
- package/lib/module/network/networkStatus.js +47 -14
- package/lib/module/permissions/index.js +22 -0
- package/lib/module/sqlite/adapters/expo.js +48 -0
- package/lib/module/sqlite/adapters/op.js +38 -0
- package/lib/module/sqlite/adapters/rows.js +28 -0
- package/lib/module/sqlite/adapters/storage.js +46 -0
- package/lib/module/sqlite/adapters/sync.js +41 -0
- package/lib/module/sqlite/index.js +600 -0
- package/lib/module/sqlite/nitro.js +12 -0
- package/lib/module/sqlite/op.js +13 -0
- package/lib/module/sqlite/quick.js +9 -0
- package/lib/module/sqlite/storage.js +9 -0
- package/lib/module/storage/index.js +38 -19
- package/lib/module/types/globals.d.js +10 -0
- package/lib/module/utils/imageCompression.js +49 -13
- package/lib/module/utils/index.js +1 -1
- package/lib/module/versionCheck/index.js +27 -4
- package/lib/typescript/commonjs/api/baseUrl.d.ts +20 -0
- package/lib/typescript/commonjs/api/curl.d.ts +18 -0
- package/lib/typescript/commonjs/api/retry.d.ts +27 -0
- package/lib/typescript/commonjs/api/userClient.d.ts +11 -0
- package/lib/typescript/commonjs/auth/authStore.d.ts +29 -6
- package/lib/typescript/commonjs/config/index.d.ts +6 -0
- package/lib/typescript/commonjs/deepLink/index.d.ts +54 -0
- package/lib/typescript/commonjs/download/adapters/expoFs.d.ts +45 -0
- package/lib/typescript/commonjs/download/adapters/shared.d.ts +3 -0
- package/lib/typescript/commonjs/download/index.d.ts +76 -0
- package/lib/typescript/commonjs/formatters/index.d.ts +2 -1
- package/lib/typescript/commonjs/formatters/phone.d.ts +27 -1
- package/lib/typescript/commonjs/geolocation/adapters/expoLocation.d.ts +42 -0
- package/lib/typescript/commonjs/geolocation/index.d.ts +89 -0
- package/lib/typescript/commonjs/index.d.ts +30 -13
- package/lib/typescript/commonjs/initSDK.d.ts +32 -0
- package/lib/typescript/commonjs/logger/index.d.ts +39 -0
- package/lib/typescript/commonjs/network/index.d.ts +2 -2
- package/lib/typescript/commonjs/network/networkStatus.d.ts +16 -0
- package/lib/typescript/commonjs/permissions/index.d.ts +35 -0
- package/lib/typescript/commonjs/sqlite/adapters/expo.d.ts +30 -0
- package/lib/typescript/commonjs/sqlite/adapters/op.d.ts +27 -0
- package/lib/typescript/commonjs/sqlite/adapters/rows.d.ts +7 -0
- package/lib/typescript/commonjs/sqlite/adapters/storage.d.ts +30 -0
- package/lib/typescript/commonjs/sqlite/adapters/sync.d.ts +31 -0
- package/lib/typescript/commonjs/sqlite/index.d.ts +121 -0
- package/lib/typescript/commonjs/sqlite/nitro.d.ts +7 -0
- package/lib/typescript/commonjs/sqlite/op.d.ts +8 -0
- package/lib/typescript/commonjs/sqlite/quick.d.ts +4 -0
- package/lib/typescript/commonjs/sqlite/storage.d.ts +4 -0
- package/lib/typescript/commonjs/storage/index.d.ts +25 -3
- package/lib/typescript/commonjs/utils/imageCompression.d.ts +17 -0
- package/lib/typescript/commonjs/utils/index.d.ts +2 -2
- package/lib/typescript/module/api/baseUrl.d.ts +20 -0
- package/lib/typescript/module/api/curl.d.ts +18 -0
- package/lib/typescript/module/api/retry.d.ts +27 -0
- package/lib/typescript/module/api/userClient.d.ts +11 -0
- package/lib/typescript/module/auth/authStore.d.ts +29 -6
- package/lib/typescript/module/config/index.d.ts +6 -0
- package/lib/typescript/module/deepLink/index.d.ts +54 -0
- package/lib/typescript/module/download/adapters/expoFs.d.ts +45 -0
- package/lib/typescript/module/download/adapters/shared.d.ts +3 -0
- package/lib/typescript/module/download/index.d.ts +76 -0
- package/lib/typescript/module/formatters/index.d.ts +2 -1
- package/lib/typescript/module/formatters/phone.d.ts +27 -1
- package/lib/typescript/module/geolocation/adapters/expoLocation.d.ts +42 -0
- package/lib/typescript/module/geolocation/index.d.ts +89 -0
- package/lib/typescript/module/index.d.ts +30 -13
- package/lib/typescript/module/initSDK.d.ts +32 -0
- package/lib/typescript/module/logger/index.d.ts +39 -0
- package/lib/typescript/module/network/index.d.ts +2 -2
- package/lib/typescript/module/network/networkStatus.d.ts +16 -0
- package/lib/typescript/module/permissions/index.d.ts +35 -0
- package/lib/typescript/module/sqlite/adapters/expo.d.ts +30 -0
- package/lib/typescript/module/sqlite/adapters/op.d.ts +27 -0
- package/lib/typescript/module/sqlite/adapters/rows.d.ts +7 -0
- package/lib/typescript/module/sqlite/adapters/storage.d.ts +30 -0
- package/lib/typescript/module/sqlite/adapters/sync.d.ts +31 -0
- package/lib/typescript/module/sqlite/index.d.ts +121 -0
- package/lib/typescript/module/sqlite/nitro.d.ts +7 -0
- package/lib/typescript/module/sqlite/op.d.ts +8 -0
- package/lib/typescript/module/sqlite/quick.d.ts +4 -0
- package/lib/typescript/module/sqlite/storage.d.ts +4 -0
- package/lib/typescript/module/storage/index.d.ts +25 -3
- package/lib/typescript/module/utils/imageCompression.d.ts +17 -0
- package/lib/typescript/module/utils/index.d.ts +2 -2
- package/package.json +102 -13
package/lib/commonjs/auth/jwt.js
CHANGED
|
@@ -14,16 +14,40 @@ const base64UrlToBase64 = input => {
|
|
|
14
14
|
const padded = input + '='.repeat((4 - input.length % 4) % 4);
|
|
15
15
|
return padded.replace(/-/g, '+').replace(/_/g, '/');
|
|
16
16
|
};
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const BASE64_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Pure-JS base64, used only when the runtime has no `atob`.
|
|
21
|
+
*
|
|
22
|
+
* This used to be `require('buffer')`. That was a latent bundling failure for
|
|
23
|
+
* every consumer: `buffer` is a Node builtin that React Native does not
|
|
24
|
+
* provide, it was never declared as a dependency, and Metro resolves requires
|
|
25
|
+
* STATICALLY — so sitting inside an unreached fallback branch did not save it.
|
|
26
|
+
* The app still failed to bundle, with an error naming this file. It only went
|
|
27
|
+
* unnoticed because the repo's own checks never bundle for a device.
|
|
28
|
+
*
|
|
29
|
+
* Decoding four base64 characters yields three bytes; the padding tells us how
|
|
30
|
+
* many of those three are real.
|
|
31
|
+
*/
|
|
32
|
+
const decodeBase64Fallback = input => {
|
|
33
|
+
let out = '';
|
|
34
|
+
for (let i = 0; i < input.length; i += 4) {
|
|
35
|
+
const chunk = [0, 1, 2, 3].map(offset => BASE64_ALPHABET.indexOf(input[i + offset] ?? '='));
|
|
36
|
+
const bits = Math.max(chunk[0], 0) << 18 | Math.max(chunk[1], 0) << 12 | Math.max(chunk[2], 0) << 6 | Math.max(chunk[3], 0);
|
|
37
|
+
out += String.fromCharCode(bits >> 16 & 0xff);
|
|
38
|
+
if (chunk[2] !== -1) {
|
|
39
|
+
out += String.fromCharCode(bits >> 8 & 0xff);
|
|
40
|
+
}
|
|
41
|
+
if (chunk[3] !== -1) {
|
|
42
|
+
out += String.fromCharCode(bits & 0xff);
|
|
43
|
+
}
|
|
21
44
|
}
|
|
22
|
-
|
|
23
|
-
Buffer
|
|
24
|
-
} = require('buffer');
|
|
25
|
-
return Buffer.from(input, 'base64').toString('utf-8');
|
|
45
|
+
return out;
|
|
26
46
|
};
|
|
47
|
+
const decodeBase64 = input =>
|
|
48
|
+
// Every RN runtime the library supports has `atob` (Hermes 0.71+), so the
|
|
49
|
+
// fallback is a safety net rather than a path anyone is expected to take.
|
|
50
|
+
typeof atob === 'function' ? atob(input) : decodeBase64Fallback(input);
|
|
27
51
|
const utf8FromBinary = binary => {
|
|
28
52
|
// Convert percent-encoded UTF-8 sequence so multi-byte chars survive.
|
|
29
53
|
try {
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useDeepLink = exports.parseDeepLink = exports.DeepLink = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _index = require("../logger/index.js");
|
|
10
|
+
const PREFIX = '[@webority-technologies/mobile-core]';
|
|
11
|
+
const decodeSafe = value => {
|
|
12
|
+
try {
|
|
13
|
+
return decodeURIComponent(value.replace(/\+/g, ' '));
|
|
14
|
+
} catch {
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const parseQuery = raw => {
|
|
19
|
+
const out = {};
|
|
20
|
+
if (!raw) {
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
for (const pair of raw.split('&')) {
|
|
24
|
+
if (!pair) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const eq = pair.indexOf('=');
|
|
28
|
+
const key = decodeSafe(eq >= 0 ? pair.slice(0, eq) : pair);
|
|
29
|
+
if (!key) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
out[key] = eq >= 0 ? decodeSafe(pair.slice(eq + 1)) : '';
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
};
|
|
36
|
+
const trimSlashes = value => value.replace(/^\/+/, '').replace(/\/+$/, '');
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Parse a deep-link URL. Returns null for anything that is not a usable URL so
|
|
40
|
+
* a hostile or truncated link can never throw on the native event path.
|
|
41
|
+
*/
|
|
42
|
+
const parseDeepLink = url => {
|
|
43
|
+
if (typeof url !== 'string') {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const trimmed = url.trim();
|
|
47
|
+
if (!trimmed || /\s/.test(trimmed)) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const withoutFragment = trimmed.split('#')[0] ?? '';
|
|
51
|
+
const schemeEnd = withoutFragment.indexOf('://');
|
|
52
|
+
let scheme = '';
|
|
53
|
+
let rest = withoutFragment;
|
|
54
|
+
if (schemeEnd >= 0) {
|
|
55
|
+
const rawScheme = withoutFragment.slice(0, schemeEnd);
|
|
56
|
+
if (!/^[a-zA-Z][a-zA-Z0-9+.-]*$/.test(rawScheme)) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
scheme = rawScheme.toLowerCase();
|
|
60
|
+
rest = withoutFragment.slice(schemeEnd + 3);
|
|
61
|
+
}
|
|
62
|
+
const queryStart = rest.indexOf('?');
|
|
63
|
+
const rawPath = queryStart >= 0 ? rest.slice(0, queryStart) : rest;
|
|
64
|
+
const query = parseQuery(queryStart >= 0 ? rest.slice(queryStart + 1) : '');
|
|
65
|
+
let host = '';
|
|
66
|
+
let pathPart = rawPath;
|
|
67
|
+
if (scheme === 'http' || scheme === 'https') {
|
|
68
|
+
const slash = rawPath.indexOf('/');
|
|
69
|
+
host = slash >= 0 ? rawPath.slice(0, slash) : rawPath;
|
|
70
|
+
pathPart = slash >= 0 ? rawPath.slice(slash + 1) : '';
|
|
71
|
+
}
|
|
72
|
+
const path = trimSlashes(pathPart);
|
|
73
|
+
const segments = path ? path.split('/').filter(Boolean) : [];
|
|
74
|
+
if (scheme && scheme !== 'http' && scheme !== 'https') {
|
|
75
|
+
host = segments[0] ?? '';
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
url: trimmed,
|
|
79
|
+
scheme,
|
|
80
|
+
host,
|
|
81
|
+
path,
|
|
82
|
+
segments,
|
|
83
|
+
query
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
exports.parseDeepLink = parseDeepLink;
|
|
87
|
+
const matchPattern = (pattern, segments) => {
|
|
88
|
+
const patternSegments = trimSlashes(pattern).split('/').filter(Boolean);
|
|
89
|
+
if (patternSegments.length !== segments.length) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const params = {};
|
|
93
|
+
for (let i = 0; i < patternSegments.length; i += 1) {
|
|
94
|
+
const p = patternSegments[i];
|
|
95
|
+
const s = segments[i];
|
|
96
|
+
if (p.startsWith(':')) {
|
|
97
|
+
const name = p.slice(1);
|
|
98
|
+
if (!name) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
params[name] = s;
|
|
102
|
+
} else if (p.toLowerCase() !== s.toLowerCase()) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return params;
|
|
107
|
+
};
|
|
108
|
+
const matchRegExp = (pattern, path) => {
|
|
109
|
+
// A /g or /y pattern carries lastIndex between calls, so the same link would
|
|
110
|
+
// match on one dispatch and miss on the next.
|
|
111
|
+
if (pattern.global || pattern.sticky) {
|
|
112
|
+
pattern.lastIndex = 0;
|
|
113
|
+
}
|
|
114
|
+
const result = pattern.exec(path);
|
|
115
|
+
if (!result) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
const params = {};
|
|
119
|
+
for (let i = 1; i < result.length; i += 1) {
|
|
120
|
+
const group = result[i];
|
|
121
|
+
if (group !== undefined) {
|
|
122
|
+
params[String(i)] = group;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
for (const [name, value] of Object.entries(result.groups ?? {})) {
|
|
126
|
+
if (value !== undefined) {
|
|
127
|
+
params[name] = value;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return params;
|
|
131
|
+
};
|
|
132
|
+
const matchRoute = (routes, link) => {
|
|
133
|
+
for (const route of routes) {
|
|
134
|
+
const params = typeof route.match === 'string' ? matchPattern(route.match, link.segments) : matchRegExp(route.match, link.path);
|
|
135
|
+
if (params) {
|
|
136
|
+
return {
|
|
137
|
+
route,
|
|
138
|
+
params
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
};
|
|
144
|
+
let config = null;
|
|
145
|
+
let subscription = null;
|
|
146
|
+
let started = false;
|
|
147
|
+
let pending = null;
|
|
148
|
+
let readyOverride = null;
|
|
149
|
+
const isReady = () => {
|
|
150
|
+
if (readyOverride !== null) {
|
|
151
|
+
return readyOverride;
|
|
152
|
+
}
|
|
153
|
+
return config?.isReady?.() ?? true;
|
|
154
|
+
};
|
|
155
|
+
const isAuthenticated = () => config?.isAuthenticated?.() ?? true;
|
|
156
|
+
const dispatch = link => {
|
|
157
|
+
const active = config;
|
|
158
|
+
if (!active) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const matched = matchRoute(active.routes, link);
|
|
162
|
+
if (!matched) {
|
|
163
|
+
active.onUnmatched?.(link);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (matched.route.requiresAuth && !isAuthenticated()) {
|
|
167
|
+
pending = link;
|
|
168
|
+
active.onUnauthenticated?.(link);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
matched.route.handler(link, matched.params);
|
|
172
|
+
};
|
|
173
|
+
const flushPending = () => {
|
|
174
|
+
const link = pending;
|
|
175
|
+
if (!link) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
// Cleared BEFORE dispatch: a handler that navigates can re-enter this path,
|
|
179
|
+
// and a link that fires twice is the classic deep-link duplicate-screen bug.
|
|
180
|
+
pending = null;
|
|
181
|
+
dispatch(link);
|
|
182
|
+
};
|
|
183
|
+
const configure = next => {
|
|
184
|
+
if (!next || !Array.isArray(next.routes)) {
|
|
185
|
+
throw new Error(`${PREFIX} DeepLink.configure() needs a config object with a "routes" array. ` + 'Pass { routes: [{ match: "order/:id", handler }] }.');
|
|
186
|
+
}
|
|
187
|
+
config = next;
|
|
188
|
+
};
|
|
189
|
+
const handleUrl = url => {
|
|
190
|
+
if (!config) {
|
|
191
|
+
_index.Logger.error(`${PREFIX} DeepLink received a URL before configure() was called; the link was dropped. ` + 'Call DeepLink.configure({ routes }) (or useDeepLink) during app start.');
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const parsed = parseDeepLink(url);
|
|
195
|
+
// A malformed URL still reaches the app through onUnmatched, with the raw
|
|
196
|
+
// value in `url`, rather than vanishing.
|
|
197
|
+
if (!parsed) {
|
|
198
|
+
config.onUnmatched?.({
|
|
199
|
+
url: typeof url === 'string' ? url : '',
|
|
200
|
+
scheme: '',
|
|
201
|
+
host: '',
|
|
202
|
+
path: '',
|
|
203
|
+
segments: [],
|
|
204
|
+
query: {}
|
|
205
|
+
});
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const link = parsed;
|
|
209
|
+
if (!isReady()) {
|
|
210
|
+
pending = link;
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
dispatch(link);
|
|
214
|
+
};
|
|
215
|
+
const start = async () => {
|
|
216
|
+
if (!config) {
|
|
217
|
+
throw new Error(`${PREFIX} DeepLink.start() was called before configure(). ` + 'Call DeepLink.configure({ routes }) first, or use the useDeepLink() hook.');
|
|
218
|
+
}
|
|
219
|
+
if (started) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
started = true;
|
|
223
|
+
// Subscribe before reading the cold-start URL so a link arriving during the
|
|
224
|
+
// await is not lost.
|
|
225
|
+
subscription = _reactNative.Linking.addEventListener('url', event => {
|
|
226
|
+
handleUrl(event.url);
|
|
227
|
+
});
|
|
228
|
+
try {
|
|
229
|
+
const initial = await _reactNative.Linking.getInitialURL();
|
|
230
|
+
if (initial) {
|
|
231
|
+
handleUrl(initial);
|
|
232
|
+
}
|
|
233
|
+
} catch (error) {
|
|
234
|
+
_index.Logger.error(`${PREFIX} DeepLink could not read the cold-start URL`, error);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
const stop = () => {
|
|
238
|
+
subscription?.remove?.();
|
|
239
|
+
subscription = null;
|
|
240
|
+
started = false;
|
|
241
|
+
pending = null;
|
|
242
|
+
readyOverride = null;
|
|
243
|
+
};
|
|
244
|
+
const setReady = ready => {
|
|
245
|
+
readyOverride = ready;
|
|
246
|
+
if (ready) {
|
|
247
|
+
flushPending();
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
const DeepLink = exports.DeepLink = {
|
|
251
|
+
configure,
|
|
252
|
+
start,
|
|
253
|
+
stop,
|
|
254
|
+
handleUrl,
|
|
255
|
+
setReady,
|
|
256
|
+
/** Replay the stashed link, once. Call after a successful login. */
|
|
257
|
+
replayPending: flushPending,
|
|
258
|
+
getPending: () => pending
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Configure and start the deep-link service for the lifetime of a component.
|
|
263
|
+
* The stored config delegates to the latest render, so new route closures do
|
|
264
|
+
* not tear down and re-subscribe the native listener.
|
|
265
|
+
*/
|
|
266
|
+
const useDeepLink = deepLinkConfig => {
|
|
267
|
+
const configRef = (0, _react.useRef)(deepLinkConfig);
|
|
268
|
+
configRef.current = deepLinkConfig;
|
|
269
|
+
(0, _react.useEffect)(() => {
|
|
270
|
+
DeepLink.configure({
|
|
271
|
+
get routes() {
|
|
272
|
+
return configRef.current.routes;
|
|
273
|
+
},
|
|
274
|
+
isReady: () => configRef.current.isReady?.() ?? true,
|
|
275
|
+
isAuthenticated: () => configRef.current.isAuthenticated?.() ?? true,
|
|
276
|
+
onUnauthenticated: link => configRef.current.onUnauthenticated?.(link),
|
|
277
|
+
onUnmatched: link => configRef.current.onUnmatched?.(link)
|
|
278
|
+
});
|
|
279
|
+
void DeepLink.start();
|
|
280
|
+
return () => {
|
|
281
|
+
DeepLink.stop();
|
|
282
|
+
};
|
|
283
|
+
}, []);
|
|
284
|
+
};
|
|
285
|
+
exports.useDeepLink = useDeepLink;
|
|
286
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.adaptExpoFileSystem = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* expo-file-system. Shape verified against 57.0.6, where the legacy function
|
|
9
|
+
* API (`downloadAsync`, `getInfoAsync`) still exists on the main entry point
|
|
10
|
+
* but every one of those functions THROWS at runtime; they now live behind
|
|
11
|
+
* `expo-file-system/legacy`. This adapter therefore uses the class API only.
|
|
12
|
+
*
|
|
13
|
+
* The REQUIRE lives in the entry point beside this file, never here.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* expo reports a directory as a URI with a trailing slash, and the download
|
|
18
|
+
* module joins a directory to a file name with a `/` of its own.
|
|
19
|
+
*/
|
|
20
|
+
const asDirectoryPath = uri => uri.replace(/\/+$/, '');
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* expo REJECTS a non-2xx download rather than resolving a status, and the two
|
|
24
|
+
* platforms word it differently: iOS "server returned HTTP 404", Android
|
|
25
|
+
* "HTTP 404", and the non-task download path "response has status: 404".
|
|
26
|
+
* Recovering the code is what lets the download module report `http-error` with
|
|
27
|
+
* a status rather than a bare `network` failure. A future wording change
|
|
28
|
+
* degrades to `network`, never to a wrong status.
|
|
29
|
+
*/
|
|
30
|
+
const HTTP_STATUS = /(?:HTTP|status)\s*:?\s*(\d{3})\b/i;
|
|
31
|
+
const statusFrom = error => {
|
|
32
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
33
|
+
const match = HTTP_STATUS.exec(message);
|
|
34
|
+
return match ? Number(match[1]) : undefined;
|
|
35
|
+
};
|
|
36
|
+
const adaptExpoFileSystem = mod => {
|
|
37
|
+
const lib = mod?.default ?? mod;
|
|
38
|
+
if (typeof lib?.File !== 'function' || typeof lib.File.createDownloadTask !== 'function') {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const {
|
|
42
|
+
File,
|
|
43
|
+
Directory,
|
|
44
|
+
Paths
|
|
45
|
+
} = lib;
|
|
46
|
+
const documents = asDirectoryPath(Paths.document.uri);
|
|
47
|
+
return {
|
|
48
|
+
dirs: {
|
|
49
|
+
documents,
|
|
50
|
+
cache: asDirectoryPath(Paths.cache.uri),
|
|
51
|
+
// expo exposes no public Downloads directory, so a "downloads" request
|
|
52
|
+
// lands in the app's documents directory instead of the shared folder.
|
|
53
|
+
downloads: documents
|
|
54
|
+
},
|
|
55
|
+
download: ({
|
|
56
|
+
url,
|
|
57
|
+
path,
|
|
58
|
+
headers,
|
|
59
|
+
onProgress
|
|
60
|
+
}) => {
|
|
61
|
+
const task = File.createDownloadTask(url, new File(path), {
|
|
62
|
+
headers,
|
|
63
|
+
onProgress: onProgress ? progress => onProgress(progress.bytesWritten, progress.totalBytes) : undefined
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
promise: task.downloadAsync().then(file => ({
|
|
67
|
+
bytes: file?.size
|
|
68
|
+
}), error => {
|
|
69
|
+
const status = statusFrom(error);
|
|
70
|
+
if (status === undefined) {
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
status
|
|
75
|
+
};
|
|
76
|
+
}),
|
|
77
|
+
cancel: () => task.cancel()
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
exists: path => Promise.resolve(new File(path).exists),
|
|
81
|
+
stat: path => Promise.resolve({
|
|
82
|
+
size: new File(path).size
|
|
83
|
+
}),
|
|
84
|
+
unlink: path => {
|
|
85
|
+
new File(path).delete();
|
|
86
|
+
return Promise.resolve();
|
|
87
|
+
},
|
|
88
|
+
// The download module calls this for a directory that usually already
|
|
89
|
+
// exists, so it must be idempotent rather than throw on the second run.
|
|
90
|
+
mkdir: path => {
|
|
91
|
+
new Directory(path).create({
|
|
92
|
+
intermediates: true,
|
|
93
|
+
idempotent: true
|
|
94
|
+
});
|
|
95
|
+
return Promise.resolve();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
exports.adaptExpoFileSystem = adaptExpoFileSystem;
|
|
100
|
+
//# sourceMappingURL=expoFs.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.asNumber = void 0;
|
|
7
|
+
/** Coerce a driver-supplied size, which some report as a string. */
|
|
8
|
+
const asNumber = value => {
|
|
9
|
+
const n = typeof value === 'number' ? value : Number(value);
|
|
10
|
+
return Number.isFinite(n) ? n : 0;
|
|
11
|
+
};
|
|
12
|
+
exports.asNumber = asNumber;
|
|
13
|
+
//# sourceMappingURL=shared.js.map
|