@mediaviz/react-native-sdk 1.9.0-dev.116
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/LICENSE +21 -0
- package/dist/react.cjs +404 -0
- package/dist/react.d.cts +48 -0
- package/dist/react.d.ts +48 -0
- package/dist/react.esm.js +400 -0
- package/dist/sdk.cjs +3032 -0
- package/dist/sdk.d.cts +650 -0
- package/dist/sdk.d.ts +650 -0
- package/dist/sdk.esm.d.ts +650 -0
- package/dist/sdk.esm.js +2986 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MediaViz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/react.cjs
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var require$$0 = require('react');
|
|
4
|
+
|
|
5
|
+
function getDefaultExportFromCjs (x) {
|
|
6
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
var storage;
|
|
10
|
+
var hasRequiredStorage;
|
|
11
|
+
|
|
12
|
+
function requireStorage () {
|
|
13
|
+
if (hasRequiredStorage) return storage;
|
|
14
|
+
hasRequiredStorage = 1;
|
|
15
|
+
|
|
16
|
+
// Token persistence.
|
|
17
|
+
//
|
|
18
|
+
// Access and refresh tokens are kept under separate keys because
|
|
19
|
+
// expo-secure-store caps a single value at 2048 bytes and two JWTs in one blob
|
|
20
|
+
// can cross that. Keychain has no such cap, so it stores one JSON entry.
|
|
21
|
+
|
|
22
|
+
const ACCESS_KEY = 'mediaviz.accessToken';
|
|
23
|
+
const REFRESH_KEY = 'mediaviz.refreshToken';
|
|
24
|
+
|
|
25
|
+
/** Non-persistent default. Tokens are lost when the app is killed. */
|
|
26
|
+
class MemoryTokenStore {
|
|
27
|
+
constructor() {
|
|
28
|
+
this._tokens = { accessToken: null, refreshToken: null };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async load() {
|
|
32
|
+
return { ...this._tokens };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async save(tokens) {
|
|
36
|
+
this._tokens = normalize(tokens);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async clear() {
|
|
40
|
+
this._tokens = { accessToken: null, refreshToken: null };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Backed by expo-secure-store (Keychain on iOS, Keystore on Android).
|
|
46
|
+
* @param {{getItemAsync: Function, setItemAsync: Function, deleteItemAsync: Function}} SecureStore
|
|
47
|
+
*/
|
|
48
|
+
function createSecureTokenStore(SecureStore, options = {}) {
|
|
49
|
+
requireMethods(SecureStore, ['getItemAsync', 'setItemAsync', 'deleteItemAsync'], 'expo-secure-store');
|
|
50
|
+
const accessKey = options.accessKey ?? ACCESS_KEY;
|
|
51
|
+
const refreshKey = options.refreshKey ?? REFRESH_KEY;
|
|
52
|
+
const opts = options.secureStoreOptions;
|
|
53
|
+
return {
|
|
54
|
+
async load() {
|
|
55
|
+
const [accessToken, refreshToken] = await Promise.all([
|
|
56
|
+
SecureStore.getItemAsync(accessKey, opts),
|
|
57
|
+
SecureStore.getItemAsync(refreshKey, opts),
|
|
58
|
+
]);
|
|
59
|
+
return { accessToken: accessToken ?? null, refreshToken: refreshToken ?? null };
|
|
60
|
+
},
|
|
61
|
+
async save(tokens) {
|
|
62
|
+
const { accessToken, refreshToken } = normalize(tokens);
|
|
63
|
+
await Promise.all([
|
|
64
|
+
writeOrDelete(SecureStore, accessKey, accessToken, opts),
|
|
65
|
+
writeOrDelete(SecureStore, refreshKey, refreshToken, opts),
|
|
66
|
+
]);
|
|
67
|
+
},
|
|
68
|
+
async clear() {
|
|
69
|
+
await Promise.all([
|
|
70
|
+
SecureStore.deleteItemAsync(accessKey, opts),
|
|
71
|
+
SecureStore.deleteItemAsync(refreshKey, opts),
|
|
72
|
+
]);
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Backed by react-native-keychain.
|
|
79
|
+
* @param {{getGenericPassword: Function, setGenericPassword: Function, resetGenericPassword: Function}} Keychain
|
|
80
|
+
*/
|
|
81
|
+
function createKeychainTokenStore(Keychain, options = {}) {
|
|
82
|
+
requireMethods(Keychain, ['getGenericPassword', 'setGenericPassword', 'resetGenericPassword'], 'react-native-keychain');
|
|
83
|
+
const opts = { service: options.service ?? 'ai.mediaviz.tokens', ...options.keychainOptions };
|
|
84
|
+
return {
|
|
85
|
+
async load() {
|
|
86
|
+
const entry = await Keychain.getGenericPassword(opts);
|
|
87
|
+
if (!entry || !entry.password) return { accessToken: null, refreshToken: null };
|
|
88
|
+
return normalize(JSON.parse(entry.password));
|
|
89
|
+
},
|
|
90
|
+
async save(tokens) {
|
|
91
|
+
await Keychain.setGenericPassword('mediaviz', JSON.stringify(normalize(tokens)), opts);
|
|
92
|
+
},
|
|
93
|
+
async clear() {
|
|
94
|
+
await Keychain.resetGenericPassword(opts);
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// helpers
|
|
100
|
+
function normalize(tokens) {
|
|
101
|
+
// The OAuth client emits snake_case (access_token); MediaViz getters emit
|
|
102
|
+
// camelCase. Both reach this store, so both are accepted.
|
|
103
|
+
const t = tokens ?? {};
|
|
104
|
+
return {
|
|
105
|
+
accessToken: t.accessToken ?? t.access_token ?? null,
|
|
106
|
+
refreshToken: t.refreshToken ?? t.refresh_token ?? null,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function writeOrDelete(SecureStore, key, value, opts) {
|
|
111
|
+
// A null token must erase the key, not persist the string "null".
|
|
112
|
+
return value ? SecureStore.setItemAsync(key, value, opts) : SecureStore.deleteItemAsync(key, opts);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function requireMethods(mod, names, label) {
|
|
116
|
+
for (const name of names) {
|
|
117
|
+
if (typeof mod?.[name] !== 'function') {
|
|
118
|
+
throw new TypeError(`Expected the ${label} module; it has no ${name}()`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
storage = { MemoryTokenStore, createSecureTokenStore, createKeychainTokenStore };
|
|
124
|
+
return storage;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
var authSession;
|
|
128
|
+
var hasRequiredAuthSession;
|
|
129
|
+
|
|
130
|
+
function requireAuthSession () {
|
|
131
|
+
if (hasRequiredAuthSession) return authSession;
|
|
132
|
+
hasRequiredAuthSession = 1;
|
|
133
|
+
|
|
134
|
+
// Authorization Code + PKCE on device.
|
|
135
|
+
//
|
|
136
|
+
// The app injects openAuthSession (expo-web-browser's openAuthSessionAsync, or
|
|
137
|
+
// anything with the same contract), keeping this file free of native
|
|
138
|
+
// dependencies. The verifier never leaves this function, so there is nothing to
|
|
139
|
+
// persist across the redirect the way a web app must.
|
|
140
|
+
|
|
141
|
+
class AuthSessionError extends Error {
|
|
142
|
+
constructor(code, message) {
|
|
143
|
+
super(message);
|
|
144
|
+
this.name = 'AuthSessionError';
|
|
145
|
+
this.code = code;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Runs the full interactive login and leaves *mv* authenticated.
|
|
151
|
+
* @param {object} mv - a MediaViz client
|
|
152
|
+
* @param {{openAuthSession: Function, redirectUri: string, state?: string, sessionOptions?: object}} options
|
|
153
|
+
* @returns {Promise<object>} the token response
|
|
154
|
+
*/
|
|
155
|
+
async function startAuthSession(mv, options) {
|
|
156
|
+
const { openAuthSession, redirectUri, state: requestedState, sessionOptions } = options ?? {};
|
|
157
|
+
if (typeof openAuthSession !== 'function') {
|
|
158
|
+
throw new TypeError('startAuthSession requires openAuthSession(url, redirectUri, options)');
|
|
159
|
+
}
|
|
160
|
+
if (!redirectUri) {
|
|
161
|
+
throw new TypeError('startAuthSession requires redirectUri');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const { url, state, code_verifier: codeVerifier } = await mv.getAuthorizationUrl(requestedState);
|
|
165
|
+
const result = await openAuthSession(url, redirectUri, sessionOptions);
|
|
166
|
+
|
|
167
|
+
const type = result?.type;
|
|
168
|
+
if (type === 'cancel' || type === 'dismiss') {
|
|
169
|
+
throw new AuthSessionError('cancelled', 'The user dismissed the sign-in screen.');
|
|
170
|
+
}
|
|
171
|
+
if (type !== 'success' || !result?.url) {
|
|
172
|
+
throw new AuthSessionError('failed', `Sign-in did not complete (result type: ${type ?? 'none'}).`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const params = parseRedirectUrl(result.url);
|
|
176
|
+
if (params.error) {
|
|
177
|
+
throw new AuthSessionError(params.error, params.error_description ?? `Authorization failed: ${params.error}`);
|
|
178
|
+
}
|
|
179
|
+
// Rejecting a mismatched state is the CSRF defence the whole flow rests on —
|
|
180
|
+
// it must fail closed, including when the server returns no state at all.
|
|
181
|
+
if (params.state !== state) {
|
|
182
|
+
throw new AuthSessionError('state_mismatch', 'Authorization state did not match the request; discarding the response.');
|
|
183
|
+
}
|
|
184
|
+
if (!params.code) {
|
|
185
|
+
throw new AuthSessionError('no_code', 'Authorization redirect carried no code.');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return mv.handleCallback(params.code, codeVerifier);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Extracts query and fragment params from a redirect URL.
|
|
193
|
+
*
|
|
194
|
+
* Hand-rolled because React Native's URL polyfill mis-parses custom schemes
|
|
195
|
+
* (mediaviz://callback) — the very shape every native redirect URI takes.
|
|
196
|
+
* @param {string} url
|
|
197
|
+
* @returns {Record<string, string>}
|
|
198
|
+
*/
|
|
199
|
+
function parseRedirectUrl(url) {
|
|
200
|
+
const out = {};
|
|
201
|
+
const text = String(url ?? '');
|
|
202
|
+
const queryStart = text.indexOf('?');
|
|
203
|
+
const hashStart = text.indexOf('#');
|
|
204
|
+
if (queryStart !== -1) {
|
|
205
|
+
const end = hashStart > queryStart ? hashStart : text.length;
|
|
206
|
+
assign(out, text.slice(queryStart + 1, end));
|
|
207
|
+
}
|
|
208
|
+
if (hashStart !== -1) assign(out, text.slice(hashStart + 1));
|
|
209
|
+
return out;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// helpers
|
|
213
|
+
function assign(out, segment) {
|
|
214
|
+
for (const pair of segment.split('&')) {
|
|
215
|
+
if (!pair) continue;
|
|
216
|
+
const eq = pair.indexOf('=');
|
|
217
|
+
const key = decode(eq === -1 ? pair : pair.slice(0, eq));
|
|
218
|
+
if (!key) continue;
|
|
219
|
+
out[key] = eq === -1 ? '' : decode(pair.slice(eq + 1));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function decode(value) {
|
|
224
|
+
try {
|
|
225
|
+
return decodeURIComponent(value.replace(/\+/g, ' '));
|
|
226
|
+
} catch {
|
|
227
|
+
// A malformed escape must not take down the whole redirect parse; the
|
|
228
|
+
// caller's state/code checks still reject anything unusable.
|
|
229
|
+
return value;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
authSession = { startAuthSession, parseRedirectUrl, AuthSessionError };
|
|
234
|
+
return authSession;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
var session;
|
|
238
|
+
var hasRequiredSession;
|
|
239
|
+
|
|
240
|
+
function requireSession () {
|
|
241
|
+
if (hasRequiredSession) return session;
|
|
242
|
+
hasRequiredSession = 1;
|
|
243
|
+
|
|
244
|
+
// The authenticated-session lifecycle, independent of React.
|
|
245
|
+
//
|
|
246
|
+
// Everything stateful about being signed in — rehydrating persisted tokens,
|
|
247
|
+
// keeping the store in step with refresh-token rotation, running the
|
|
248
|
+
// interactive login, clearing on sign-out — lives here so it can be driven and
|
|
249
|
+
// tested without a renderer. react.js is a thin binding over this.
|
|
250
|
+
//
|
|
251
|
+
// The MediaViz class is injected because this module is copied *into* the
|
|
252
|
+
// generated package: it cannot name its own host, and MediaViz.js is ESM while
|
|
253
|
+
// this file is CommonJS.
|
|
254
|
+
|
|
255
|
+
const { MemoryTokenStore } = requireStorage();
|
|
256
|
+
const { startAuthSession } = requireAuthSession();
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* @param {{MediaViz: Function, config?: object, store?: object, openAuthSession?: Function, onTokens?: Function}} options
|
|
260
|
+
*/
|
|
261
|
+
function createSession(options) {
|
|
262
|
+
const { MediaViz, config, store, openAuthSession, onTokens } = options ?? {};
|
|
263
|
+
if (typeof MediaViz !== 'function') throw new TypeError('createSession requires the MediaViz class');
|
|
264
|
+
|
|
265
|
+
const tokenStore = store ?? new MemoryTokenStore();
|
|
266
|
+
const emit = (tokens) => {
|
|
267
|
+
if (onTokens) onTokens(tokens ?? null);
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const client = new MediaViz({
|
|
271
|
+
...config,
|
|
272
|
+
onTokenRefresh: (tokens) => {
|
|
273
|
+
emit(tokens);
|
|
274
|
+
// Fire-and-forget: the refresh already succeeded and the retry is waiting
|
|
275
|
+
// on this callback, so awaiting the write would stall the request. A
|
|
276
|
+
// failed write is not worth failing the call over — the next refresh
|
|
277
|
+
// rewrites it.
|
|
278
|
+
Promise.resolve(tokenStore.save(tokens)).catch(() => {});
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
return {
|
|
283
|
+
client,
|
|
284
|
+
store: tokenStore,
|
|
285
|
+
|
|
286
|
+
/** Loads persisted tokens into the client. Returns them, or null if none. */
|
|
287
|
+
async restore() {
|
|
288
|
+
const tokens = await tokenStore.load().catch(() => null);
|
|
289
|
+
if (!tokens || !tokens.accessToken) return null;
|
|
290
|
+
client.setTokens(tokens.accessToken, tokens.refreshToken ?? null);
|
|
291
|
+
emit(tokens);
|
|
292
|
+
return tokens;
|
|
293
|
+
},
|
|
294
|
+
|
|
295
|
+
async signIn(overrides = {}) {
|
|
296
|
+
const tokens = await startAuthSession(client, {
|
|
297
|
+
openAuthSession: overrides.openAuthSession ?? openAuthSession,
|
|
298
|
+
redirectUri: overrides.redirectUri ?? config?.redirectUri,
|
|
299
|
+
state: overrides.state,
|
|
300
|
+
sessionOptions: overrides.sessionOptions,
|
|
301
|
+
});
|
|
302
|
+
await tokenStore.save(tokens);
|
|
303
|
+
emit(tokens);
|
|
304
|
+
return tokens;
|
|
305
|
+
},
|
|
306
|
+
|
|
307
|
+
async signOut() {
|
|
308
|
+
client.setTokens(null, null);
|
|
309
|
+
emit(null);
|
|
310
|
+
await tokenStore.clear();
|
|
311
|
+
},
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
session = { createSession };
|
|
316
|
+
return session;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
var react;
|
|
320
|
+
var hasRequiredReact;
|
|
321
|
+
|
|
322
|
+
function requireReact () {
|
|
323
|
+
if (hasRequiredReact) return react;
|
|
324
|
+
hasRequiredReact = 1;
|
|
325
|
+
|
|
326
|
+
// React bindings, reachable at "<pkg>/react".
|
|
327
|
+
//
|
|
328
|
+
// Deliberately outside the package barrel: this is the only file that requires
|
|
329
|
+
// react, so keeping it on a subpath leaves the core SDK importable from plain
|
|
330
|
+
// modules, background tasks, and tests with no React in scope. All the actual
|
|
331
|
+
// lifecycle logic lives in session.js; this file only mirrors it into state.
|
|
332
|
+
|
|
333
|
+
const React = require$$0;
|
|
334
|
+
|
|
335
|
+
const { createSession } = requireSession();
|
|
336
|
+
|
|
337
|
+
const MediaVizContext = React.createContext(null);
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Provides an authenticated MediaViz client to the tree.
|
|
341
|
+
*
|
|
342
|
+
* Pass the MediaViz class itself as a prop — see session.js for why it cannot
|
|
343
|
+
* be imported here.
|
|
344
|
+
*/
|
|
345
|
+
function MediaVizProvider(props) {
|
|
346
|
+
const { MediaViz, config, store, openAuthSession, children } = props;
|
|
347
|
+
|
|
348
|
+
const [ready, setReady] = React.useState(false);
|
|
349
|
+
const [accessToken, setAccessToken] = React.useState(null);
|
|
350
|
+
|
|
351
|
+
const session = React.useMemo(
|
|
352
|
+
() =>
|
|
353
|
+
createSession({
|
|
354
|
+
MediaViz,
|
|
355
|
+
config,
|
|
356
|
+
store,
|
|
357
|
+
openAuthSession,
|
|
358
|
+
onTokens: (tokens) => setAccessToken(tokens?.accessToken ?? tokens?.access_token ?? null),
|
|
359
|
+
}),
|
|
360
|
+
[MediaViz, config, store, openAuthSession]
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
React.useEffect(() => {
|
|
364
|
+
let cancelled = false;
|
|
365
|
+
// `ready` gates the tree on the one-time keychain read, so it must flip even
|
|
366
|
+
// when there is nothing stored or the read fails.
|
|
367
|
+
session.restore().finally(() => {
|
|
368
|
+
if (!cancelled) setReady(true);
|
|
369
|
+
});
|
|
370
|
+
return () => {
|
|
371
|
+
cancelled = true;
|
|
372
|
+
};
|
|
373
|
+
}, [session]);
|
|
374
|
+
|
|
375
|
+
const signIn = React.useCallback((overrides) => session.signIn(overrides), [session]);
|
|
376
|
+
const signOut = React.useCallback(() => session.signOut(), [session]);
|
|
377
|
+
|
|
378
|
+
const value = React.useMemo(
|
|
379
|
+
() => ({ client: session.client, ready, signedIn: Boolean(accessToken), signIn, signOut }),
|
|
380
|
+
[session, ready, accessToken, signIn, signOut]
|
|
381
|
+
);
|
|
382
|
+
|
|
383
|
+
return React.createElement(MediaVizContext.Provider, { value }, children);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function useMediaViz() {
|
|
387
|
+
const value = React.useContext(MediaVizContext);
|
|
388
|
+
if (!value) throw new Error('useMediaViz must be used inside a <MediaVizProvider>');
|
|
389
|
+
return value;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
react = { MediaVizProvider, useMediaViz, MediaVizContext };
|
|
393
|
+
return react;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
var reactExports = requireReact();
|
|
397
|
+
var _react = /*@__PURE__*/getDefaultExportFromCjs(reactExports);
|
|
398
|
+
|
|
399
|
+
// Auto-generated — do not edit
|
|
400
|
+
const { MediaVizProvider, useMediaViz, MediaVizContext } = _react;
|
|
401
|
+
|
|
402
|
+
exports.MediaVizContext = MediaVizContext;
|
|
403
|
+
exports.MediaVizProvider = MediaVizProvider;
|
|
404
|
+
exports.useMediaViz = useMediaViz;
|
package/dist/react.d.cts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Auto-generated — do not edit
|
|
2
|
+
|
|
3
|
+
export interface TokenPair {
|
|
4
|
+
accessToken: string | null;
|
|
5
|
+
refreshToken: string | null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface TokenStore {
|
|
9
|
+
load(): Promise<TokenPair>;
|
|
10
|
+
save(tokens: unknown): Promise<void>;
|
|
11
|
+
clear(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Contract of expo-web-browser's openAuthSessionAsync. */
|
|
15
|
+
export type OpenAuthSession = (
|
|
16
|
+
url: string,
|
|
17
|
+
redirectUri: string,
|
|
18
|
+
options?: Record<string, unknown>
|
|
19
|
+
) => Promise<{ type: string; url?: string }>;
|
|
20
|
+
|
|
21
|
+
export interface SignInOverrides {
|
|
22
|
+
openAuthSession?: OpenAuthSession;
|
|
23
|
+
redirectUri?: string;
|
|
24
|
+
state?: string;
|
|
25
|
+
sessionOptions?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface MediaVizProviderProps {
|
|
29
|
+
/** The MediaViz class itself, imported from the package root. */
|
|
30
|
+
MediaViz: new (config?: Record<string, unknown>) => any;
|
|
31
|
+
config?: Record<string, unknown>;
|
|
32
|
+
store?: TokenStore;
|
|
33
|
+
openAuthSession?: OpenAuthSession;
|
|
34
|
+
children?: unknown;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface MediaVizContextValue {
|
|
38
|
+
client: any;
|
|
39
|
+
/** False until persisted tokens have been read back on mount. */
|
|
40
|
+
ready: boolean;
|
|
41
|
+
signedIn: boolean;
|
|
42
|
+
signIn(overrides?: SignInOverrides): Promise<Record<string, unknown>>;
|
|
43
|
+
signOut(): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export declare function MediaVizProvider(props: MediaVizProviderProps): unknown;
|
|
47
|
+
export declare function useMediaViz(): MediaVizContextValue;
|
|
48
|
+
export declare const MediaVizContext: unknown;
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Auto-generated — do not edit
|
|
2
|
+
|
|
3
|
+
export interface TokenPair {
|
|
4
|
+
accessToken: string | null;
|
|
5
|
+
refreshToken: string | null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface TokenStore {
|
|
9
|
+
load(): Promise<TokenPair>;
|
|
10
|
+
save(tokens: unknown): Promise<void>;
|
|
11
|
+
clear(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Contract of expo-web-browser's openAuthSessionAsync. */
|
|
15
|
+
export type OpenAuthSession = (
|
|
16
|
+
url: string,
|
|
17
|
+
redirectUri: string,
|
|
18
|
+
options?: Record<string, unknown>
|
|
19
|
+
) => Promise<{ type: string; url?: string }>;
|
|
20
|
+
|
|
21
|
+
export interface SignInOverrides {
|
|
22
|
+
openAuthSession?: OpenAuthSession;
|
|
23
|
+
redirectUri?: string;
|
|
24
|
+
state?: string;
|
|
25
|
+
sessionOptions?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface MediaVizProviderProps {
|
|
29
|
+
/** The MediaViz class itself, imported from the package root. */
|
|
30
|
+
MediaViz: new (config?: Record<string, unknown>) => any;
|
|
31
|
+
config?: Record<string, unknown>;
|
|
32
|
+
store?: TokenStore;
|
|
33
|
+
openAuthSession?: OpenAuthSession;
|
|
34
|
+
children?: unknown;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface MediaVizContextValue {
|
|
38
|
+
client: any;
|
|
39
|
+
/** False until persisted tokens have been read back on mount. */
|
|
40
|
+
ready: boolean;
|
|
41
|
+
signedIn: boolean;
|
|
42
|
+
signIn(overrides?: SignInOverrides): Promise<Record<string, unknown>>;
|
|
43
|
+
signOut(): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export declare function MediaVizProvider(props: MediaVizProviderProps): unknown;
|
|
47
|
+
export declare function useMediaViz(): MediaVizContextValue;
|
|
48
|
+
export declare const MediaVizContext: unknown;
|