@pylo/react 0.8.0 → 0.10.0
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/{chunk-ZWYBNMHS.js → chunk-BPRHGSZF.js} +37 -37
- package/dist/{chunk-R3IJ4HH6.js → chunk-FKUNSR3E.js} +8 -3
- package/dist/hooks.d.ts +15 -9
- package/dist/hooks.js +2 -2
- package/dist/index.d.ts +8 -8
- package/dist/index.js +2 -2
- package/dist/{provider-X8jgqOeN.d.ts → provider-4DBl_6p0.d.ts} +11 -11
- package/dist/provider.d.ts +1 -1
- package/dist/provider.js +1 -1
- package/package.json +3 -3
- package/dist/chunk-3WSGP2SO.js +0 -483
- package/dist/chunk-A6UGLYBT.js +0 -540
- package/dist/chunk-DOPZ5GRU.js +0 -540
- package/dist/chunk-IKQ52QLH.js +0 -347
- package/dist/chunk-KOUVF33C.js +0 -540
- package/dist/chunk-RCW4MW4F.js +0 -540
- package/dist/chunk-XCHM5XBY.js +0 -468
- package/dist/chunk-XR5CLHMS.js +0 -470
- package/dist/provider-DTTtfhib.d.ts +0 -50
|
@@ -41,24 +41,24 @@ function createSessionStore(options) {
|
|
|
41
41
|
refreshToken = refresh2;
|
|
42
42
|
await options.storage.setItem(AUTH_KEY, auth);
|
|
43
43
|
await options.storage.setItem(REFRESH_KEY, refresh2);
|
|
44
|
-
setState({ status: "
|
|
44
|
+
setState({ status: "loggedIn", token: auth });
|
|
45
45
|
}
|
|
46
|
-
async function
|
|
46
|
+
async function startSession(auth, refresh2) {
|
|
47
47
|
var _a2;
|
|
48
48
|
await persist(auth, refresh2);
|
|
49
|
-
(_a2 = options.
|
|
49
|
+
(_a2 = options.onLogin) == null ? void 0 : _a2.call(options);
|
|
50
50
|
}
|
|
51
51
|
async function clear() {
|
|
52
52
|
var _a2;
|
|
53
53
|
refreshToken = null;
|
|
54
54
|
await options.storage.removeItem(AUTH_KEY);
|
|
55
55
|
await options.storage.removeItem(REFRESH_KEY);
|
|
56
|
-
setState({ status: "
|
|
57
|
-
(_a2 = options.
|
|
56
|
+
setState({ status: "loggedOut", token: null });
|
|
57
|
+
(_a2 = options.onLogout) == null ? void 0 : _a2.call(options);
|
|
58
58
|
}
|
|
59
59
|
async function runRefresh() {
|
|
60
60
|
await init();
|
|
61
|
-
if (state.status !== "
|
|
61
|
+
if (state.status !== "loggedIn") return null;
|
|
62
62
|
if (!refreshToken) {
|
|
63
63
|
await clear();
|
|
64
64
|
return null;
|
|
@@ -88,11 +88,11 @@ function createSessionStore(options) {
|
|
|
88
88
|
]);
|
|
89
89
|
refreshToken = stored;
|
|
90
90
|
setState(
|
|
91
|
-
auth ? { status: "
|
|
91
|
+
auth ? { status: "loggedIn", token: auth } : { status: "loggedOut", token: null }
|
|
92
92
|
);
|
|
93
93
|
} catch {
|
|
94
94
|
refreshToken = null;
|
|
95
|
-
setState({ status: "
|
|
95
|
+
setState({ status: "loggedOut", token: null });
|
|
96
96
|
}
|
|
97
97
|
})();
|
|
98
98
|
return ready;
|
|
@@ -146,7 +146,7 @@ function createSessionStore(options) {
|
|
|
146
146
|
};
|
|
147
147
|
}
|
|
148
148
|
const { auth_token, refresh_token } = response.data.login.data;
|
|
149
|
-
await
|
|
149
|
+
await startSession(auth_token, refresh_token);
|
|
150
150
|
return { success: true, authToken: auth_token, refreshToken: refresh_token };
|
|
151
151
|
},
|
|
152
152
|
async redeemHandoff(code, verifier) {
|
|
@@ -163,8 +163,8 @@ function createSessionStore(options) {
|
|
|
163
163
|
return {
|
|
164
164
|
success: false,
|
|
165
165
|
error: {
|
|
166
|
-
code: "
|
|
167
|
-
message: error instanceof Error ? error.message : "
|
|
166
|
+
code: "LOGIN_FAILED",
|
|
167
|
+
message: error instanceof Error ? error.message : "Login failed"
|
|
168
168
|
}
|
|
169
169
|
};
|
|
170
170
|
}
|
|
@@ -172,13 +172,13 @@ function createSessionStore(options) {
|
|
|
172
172
|
return {
|
|
173
173
|
success: false,
|
|
174
174
|
error: {
|
|
175
|
-
code: "
|
|
176
|
-
message: (_a2 = extractErrorMessage(response.errors)) != null ? _a2 : "
|
|
175
|
+
code: "LOGIN_FAILED",
|
|
176
|
+
message: (_a2 = extractErrorMessage(response.errors)) != null ? _a2 : "Login failed"
|
|
177
177
|
}
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
180
|
const { auth_token, refresh_token, redirect } = response.data.redeemLoginHandoff.data;
|
|
181
|
-
await
|
|
181
|
+
await startSession(auth_token, refresh_token);
|
|
182
182
|
const safe = safeRedirectPath(redirect);
|
|
183
183
|
return {
|
|
184
184
|
success: true,
|
|
@@ -201,14 +201,14 @@ import {
|
|
|
201
201
|
function failed(code, message) {
|
|
202
202
|
return { success: false, error: { code, message } };
|
|
203
203
|
}
|
|
204
|
-
function
|
|
204
|
+
function createSocialLogin(o) {
|
|
205
205
|
const verifierKey = `${o.keyPrefix}.handoff_verifier`;
|
|
206
206
|
let completing = null;
|
|
207
207
|
function redeem(parsed, verifier) {
|
|
208
|
-
if (!parsed) return failed("
|
|
209
|
-
if ("error" in parsed) return failed("
|
|
208
|
+
if (!parsed) return failed("LOGIN_FAILED", "No login response in this URL");
|
|
209
|
+
if ("error" in parsed) return failed("LOGIN_FAILED", parsed.error);
|
|
210
210
|
if (!verifier) {
|
|
211
|
-
return failed("
|
|
211
|
+
return failed("LOGIN_FAILED", "No login was started in this browser session");
|
|
212
212
|
}
|
|
213
213
|
return o.store.redeemHandoff(parsed.code, verifier);
|
|
214
214
|
}
|
|
@@ -225,11 +225,11 @@ function createSocialSignIn(o) {
|
|
|
225
225
|
}
|
|
226
226
|
return await redeem(parsed, verifier);
|
|
227
227
|
} catch (error) {
|
|
228
|
-
return failed("
|
|
228
|
+
return failed("LOGIN_FAILED", error instanceof Error ? error.message : "Login failed");
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
return {
|
|
232
|
-
async
|
|
232
|
+
async loginWith(provider, { returnUrl, redirect, invite }) {
|
|
233
233
|
let verifier;
|
|
234
234
|
let startUrl;
|
|
235
235
|
let finalUrl = null;
|
|
@@ -248,12 +248,12 @@ function createSocialSignIn(o) {
|
|
|
248
248
|
if (o.openAuthSession) finalUrl = await o.openAuthSession(startUrl, returnUrl);
|
|
249
249
|
} catch (error) {
|
|
250
250
|
return failed(
|
|
251
|
-
"
|
|
252
|
-
error instanceof Error ? error.message : "
|
|
251
|
+
"LOGIN_FAILED",
|
|
252
|
+
error instanceof Error ? error.message : "Login failed"
|
|
253
253
|
);
|
|
254
254
|
}
|
|
255
255
|
if (o.openAuthSession) {
|
|
256
|
-
if (finalUrl === null) return failed("CANCELLED", "
|
|
256
|
+
if (finalUrl === null) return failed("CANCELLED", "Login was cancelled");
|
|
257
257
|
return redeem(parseHandoffCallback(finalUrl), verifier);
|
|
258
258
|
}
|
|
259
259
|
sessionStorage.setItem(verifierKey, verifier);
|
|
@@ -261,10 +261,10 @@ function createSocialSignIn(o) {
|
|
|
261
261
|
return new Promise(() => {
|
|
262
262
|
});
|
|
263
263
|
},
|
|
264
|
-
|
|
264
|
+
completeLogin(url) {
|
|
265
265
|
if (o.openAuthSession) {
|
|
266
266
|
return Promise.resolve(
|
|
267
|
-
failed("
|
|
267
|
+
failed("LOGIN_FAILED", "loginWith already completes the login in this environment")
|
|
268
268
|
);
|
|
269
269
|
}
|
|
270
270
|
completing != null ? completing : completing = finish(url != null ? url : location.href).finally(() => {
|
|
@@ -374,7 +374,7 @@ function usePyloContext() {
|
|
|
374
374
|
}
|
|
375
375
|
return value;
|
|
376
376
|
}
|
|
377
|
-
var
|
|
377
|
+
var LOGGED_OUT = { status: "loggedOut", token: null };
|
|
378
378
|
var NO_OP = () => () => {
|
|
379
379
|
};
|
|
380
380
|
function PyloProvider(props) {
|
|
@@ -391,11 +391,11 @@ function PyloProvider(props) {
|
|
|
391
391
|
storage: (_a = props.storage) != null ? _a : createLocalStorageAdapter(),
|
|
392
392
|
...props.appId !== void 0 ? { appId: props.appId } : {},
|
|
393
393
|
...props.keyPrefix !== void 0 ? { keyPrefix: props.keyPrefix } : {},
|
|
394
|
-
|
|
395
|
-
|
|
394
|
+
onLogout: () => queryClient.clear(),
|
|
395
|
+
onLogin: () => void queryClient.invalidateQueries({ queryKey: ["pylo"] })
|
|
396
396
|
});
|
|
397
397
|
if (props.appId !== void 0) {
|
|
398
|
-
socialRef.current =
|
|
398
|
+
socialRef.current = createSocialLogin({
|
|
399
399
|
endpoint,
|
|
400
400
|
appId: props.appId,
|
|
401
401
|
keyPrefix: (_b = props.keyPrefix) != null ? _b : "pylo",
|
|
@@ -411,8 +411,8 @@ function PyloProvider(props) {
|
|
|
411
411
|
const social = socialRef.current;
|
|
412
412
|
const state = useSyncExternalStore(
|
|
413
413
|
store ? store.subscribe : NO_OP,
|
|
414
|
-
store ? store.getState : () =>
|
|
415
|
-
store ? store.getState : () =>
|
|
414
|
+
store ? store.getState : () => LOGGED_OUT,
|
|
415
|
+
store ? store.getState : () => LOGGED_OUT
|
|
416
416
|
);
|
|
417
417
|
useEffect(() => {
|
|
418
418
|
void (store == null ? void 0 : store.init());
|
|
@@ -450,18 +450,18 @@ function usePyloClient() {
|
|
|
450
450
|
}
|
|
451
451
|
function usePyloAuth() {
|
|
452
452
|
const { state, store, social, transport, getToken } = usePyloContext();
|
|
453
|
-
const
|
|
453
|
+
const isLoggedIn = state.status === "loggedIn";
|
|
454
454
|
const me = useQuery({
|
|
455
455
|
queryKey: ["pylo", "me"],
|
|
456
456
|
queryFn: async () => {
|
|
457
457
|
const data = await transport(ME_QUERY, {});
|
|
458
458
|
return data.me.current_user.data;
|
|
459
459
|
},
|
|
460
|
-
enabled:
|
|
460
|
+
enabled: isLoggedIn
|
|
461
461
|
});
|
|
462
462
|
return {
|
|
463
|
-
isLoading: state.status === "loading" ||
|
|
464
|
-
|
|
463
|
+
isLoading: state.status === "loading" || isLoggedIn && me.isLoading,
|
|
464
|
+
isLoggedIn,
|
|
465
465
|
user: me.data,
|
|
466
466
|
login: async (email, password) => {
|
|
467
467
|
if (!store) {
|
|
@@ -475,8 +475,8 @@ function usePyloAuth() {
|
|
|
475
475
|
}
|
|
476
476
|
await store.logout();
|
|
477
477
|
},
|
|
478
|
-
|
|
479
|
-
|
|
478
|
+
loginWith: async (provider, options) => requireSocial("loginWith").loginWith(provider, options),
|
|
479
|
+
completeLogin: async (url) => requireSocial("completeLogin").completeLogin(url),
|
|
480
480
|
getToken
|
|
481
481
|
};
|
|
482
482
|
function requireSocial(method) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
usePyloTransport
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-BPRHGSZF.js";
|
|
4
4
|
|
|
5
5
|
// src/hooks.ts
|
|
6
6
|
import { useCallback, useRef, useState } from "react";
|
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
uploadToUrl,
|
|
39
39
|
toUploadPart
|
|
40
40
|
} from "@pylo/core";
|
|
41
|
+
var INFINITE_PAGINATION_SELECT = { current_page: true, has_more_pages: true };
|
|
41
42
|
function createPyloHooks(options) {
|
|
42
43
|
var _a;
|
|
43
44
|
const useTransport = (_a = options == null ? void 0 : options.useTransport) != null ? _a : usePyloTransport;
|
|
@@ -71,7 +72,7 @@ function createPyloHooks(options) {
|
|
|
71
72
|
});
|
|
72
73
|
return {
|
|
73
74
|
data: (_b = (_a2 = result.data) == null ? void 0 : _a2.data) != null ? _b : void 0,
|
|
74
|
-
pagination: (_c = result.data) == null ? void 0 : _c.pagination,
|
|
75
|
+
..."_pagination" in queryOptions.select && { pagination: (_c = result.data) == null ? void 0 : _c.pagination },
|
|
75
76
|
isLoading: result.isLoading,
|
|
76
77
|
error: result.error,
|
|
77
78
|
refetch: result.refetch
|
|
@@ -95,8 +96,12 @@ function createPyloHooks(options) {
|
|
|
95
96
|
}
|
|
96
97
|
],
|
|
97
98
|
queryFn: async ({ pageParam }) => {
|
|
99
|
+
const select = infiniteOptions.select;
|
|
98
100
|
const runtimeOptions = {
|
|
99
|
-
select:
|
|
101
|
+
select: {
|
|
102
|
+
...select,
|
|
103
|
+
_pagination: { ...select._pagination, ...INFINITE_PAGINATION_SELECT }
|
|
104
|
+
},
|
|
100
105
|
filter: infiniteOptions == null ? void 0 : infiniteOptions.filter,
|
|
101
106
|
pagination: { page: pageParam, per_page: perPage }
|
|
102
107
|
};
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
import { T as Transport } from './transport-55cSrvQo.js';
|
|
2
2
|
import { UseQueryResult, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
|
|
3
|
-
import { EntityNameWith,
|
|
3
|
+
import { EntityNameWith, ListSelect, FilterInput, RequestOptions, WithPagination, EntityRelationPath, UploadAttachTarget, UploadProgress, PyloUploadedFile, UploadSource, ListSelectConstraint, ListOptions, EntityResult, PaginationData, SelectConstraint, ByIdOptions, EntityName, AggregateMetricInput, AggregateGroupByInput, AggregateOptions, AggregateResult, EventMetricInput, EventGroupByInput, EventAggregateOptions, UpsertInput, MutationRequestOptions, PyloEvent, PyloEventInput, PaginationSelect, EventListOptions, PyloEventListResult, PyloEventPropertyKeysOptions, PyloEventProperty, PyloEventFieldValuesOptions, PyloEventFieldValue } from '@pylo/core';
|
|
4
4
|
|
|
5
5
|
interface HooksOptions {
|
|
6
6
|
/** Defaults to reading the transport `PyloProvider` supplies. */
|
|
7
7
|
useTransport?: () => Transport;
|
|
8
8
|
headers?: Record<string, string>;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
type ListHookResult<T, Sel = unknown> = {
|
|
11
11
|
data: T[] | undefined;
|
|
12
|
-
pagination: PaginationData | undefined;
|
|
13
12
|
isLoading: boolean;
|
|
14
13
|
error: Error | null;
|
|
15
14
|
refetch: UseQueryResult["refetch"];
|
|
16
|
-
}
|
|
17
|
-
|
|
15
|
+
} & (WithPagination<Sel> extends {
|
|
16
|
+
pagination: infer D;
|
|
17
|
+
} ? {
|
|
18
|
+
pagination: D | undefined;
|
|
19
|
+
} : unknown);
|
|
20
|
+
type InfiniteListOptions<S, E extends EntityNameWith<S, "list">, Sel extends ListSelect<S, E>> = {
|
|
18
21
|
perPage?: number;
|
|
19
22
|
select: Sel;
|
|
20
23
|
filter?: FilterInput;
|
|
21
24
|
} & RequestOptions;
|
|
25
|
+
type InfinitePagination<Sel> = Pick<PaginationData, "current_page" | "has_more_pages" | (Sel extends {
|
|
26
|
+
_pagination: infer PS;
|
|
27
|
+
} ? keyof PS & keyof PaginationData : never)>;
|
|
22
28
|
interface UploadHookOptions<S> {
|
|
23
29
|
/**
|
|
24
30
|
* The pyloMedia relation the files are destined for, e.g. `"contact.avatar"`.
|
|
@@ -57,12 +63,12 @@ interface UploadHookResult<S> {
|
|
|
57
63
|
reset: () => void;
|
|
58
64
|
}
|
|
59
65
|
declare function createPyloHooks<S>(options?: HooksOptions): {
|
|
60
|
-
usePyloList: <E extends EntityNameWith<S, "list">, const Sel extends
|
|
61
|
-
usePyloInfiniteList: <E extends EntityNameWith<S, "list">, const Sel extends
|
|
66
|
+
usePyloList: <E extends EntityNameWith<S, "list">, const Sel extends ListSelectConstraint<S, E, Sel>>(entity: E, queryOptions: ListOptions<S, E, Sel> & RequestOptions) => ListHookResult<EntityResult<S, E, Sel>, Sel>;
|
|
67
|
+
usePyloInfiniteList: <E extends EntityNameWith<S, "list">, const Sel extends ListSelectConstraint<S, E, Sel>>(entity: E, infiniteOptions: InfiniteListOptions<S, E, Sel>) => UseInfiniteQueryResult<{
|
|
62
68
|
data: Array<EntityResult<S, E, Sel>>;
|
|
63
69
|
pages: Array<{
|
|
64
70
|
data: Array<EntityResult<S, E, Sel>>;
|
|
65
|
-
pagination:
|
|
71
|
+
pagination: InfinitePagination<Sel>;
|
|
66
72
|
}>;
|
|
67
73
|
}>;
|
|
68
74
|
usePyloById: <E extends EntityNameWith<S, "byId">, const Sel extends SelectConstraint<S, E, Sel>>(entity: E, id: string | null | undefined, queryOptions: ByIdOptions<S, E, Sel> & RequestOptions) => UseQueryResult<EntityResult<S, E, Sel> | null>;
|
|
@@ -85,7 +91,7 @@ declare function createPyloHooks<S>(options?: HooksOptions): {
|
|
|
85
91
|
success: boolean;
|
|
86
92
|
}, Error, string[]>;
|
|
87
93
|
usePyloIngestEvents: (mutationOptions?: Omit<UseMutationOptions<PyloEvent[], Error, PyloEventInput[]>, "mutationFn"> & MutationRequestOptions) => UseMutationResult<PyloEvent[], Error, PyloEventInput[]>;
|
|
88
|
-
usePyloEventList: (queryOptions?: EventListOptions & RequestOptions) => UseQueryResult<PyloEventListResult
|
|
94
|
+
usePyloEventList: <PS extends PaginationSelect = Record<never, never>>(queryOptions?: EventListOptions<PS> & RequestOptions) => UseQueryResult<PyloEventListResult<PS>>;
|
|
89
95
|
usePyloEventPropertyKeys: (queryOptions?: PyloEventPropertyKeysOptions & RequestOptions) => UseQueryResult<PyloEventProperty[]>;
|
|
90
96
|
usePyloEventFieldValues: (field: string | null | undefined, queryOptions?: PyloEventFieldValuesOptions & RequestOptions) => UseQueryResult<PyloEventFieldValue[]>;
|
|
91
97
|
usePyloUpload: (hookOptions?: UploadHookOptions<S>) => UploadHookResult<S>;
|
package/dist/hooks.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -2,15 +2,15 @@ import { EntityName, EntitySelect, EntityResult } from '@pylo/core';
|
|
|
2
2
|
export { AggregateFilterInput, AggregateFunction, AggregateGroupByInput, AggregateInput, AggregateInterval, AggregateIntervalUnit, AggregateMetricInput, AggregateOptions, AggregateResult, AggregateRow, AggregateRows, AggregateSortInput, AggregateSortKey, AggregateTotal, ByIdOptions, CallableEntityName, CreateUploadInput, CreateUploadUrlOptions, DimensionInput, DimensionValue, EntityAggregateApi, EntityCapability, EntityFields, EntityMethodName, EntityName, EntityNameWith, EntityRelationPath, EntityRelations, EntityResult, EntitySelect, EventAggregateOptions, EventGroupByInput, EventListFilterInput, EventListOptions, EventMetricInput, FieldName, FilesClient, FilterInput, HasCapability, IngestEvents, ListOptions, ListResult, Me, MetricValue, MutationRequestOptions, NumericFieldName, PaginationData, PaginationInput, PyloError, PyloEvent, PyloEventFieldValue, PyloEventFieldValuesOptions, PyloEventInput, PyloEventListResult, PyloEventProperty, PyloEventPropertyKeysOptions, PyloUploadedFile, QueryInput, QueryInputCondition, QueryOperator, RequestOptions, RowKeyOf, SearchValueInput, SortInput, SortOrder, SystemEntityName, TimeBucketInput, UploadAttachTarget, UploadOptions, UploadProgress, UploadSource, UploadUrl, UpsertInput, VirtualEntityName } from '@pylo/core';
|
|
3
3
|
import { AuthResult, SocialProvider } from '@pylo/auth';
|
|
4
4
|
export { AuthResult, HandoffCrypto, PyloUser, SocialProvider } from '@pylo/auth';
|
|
5
|
-
import { P as PyloStorage, a as PyloAuth } from './provider-
|
|
6
|
-
export { O as OpenAuthSession, b as PyloProvider, c as PyloProviderProps, S as
|
|
5
|
+
import { P as PyloStorage, a as PyloAuth } from './provider-4DBl_6p0.js';
|
|
6
|
+
export { O as OpenAuthSession, b as PyloProvider, c as PyloProviderProps, S as SocialLogin, d as SocialLoginResult, e as createLocalStorageAdapter, f as createMemoryStorage, u as usePyloClient, g as usePyloTransport } from './provider-4DBl_6p0.js';
|
|
7
7
|
export { D as DirectTransportOptions, T as Transport, c as createDirectTransport } from './transport-55cSrvQo.js';
|
|
8
8
|
export { InfiniteListOptions, ListHookResult, StartUploadOptions, UploadHookOptions, UploadHookResult, createPyloHooks } from './hooks.js';
|
|
9
9
|
import 'react/jsx-runtime';
|
|
10
10
|
import 'react';
|
|
11
11
|
import '@tanstack/react-query';
|
|
12
12
|
|
|
13
|
-
type SessionStatus = "loading" | "
|
|
13
|
+
type SessionStatus = "loading" | "loggedIn" | "loggedOut";
|
|
14
14
|
interface SessionState {
|
|
15
15
|
status: SessionStatus;
|
|
16
16
|
token: string | null;
|
|
@@ -21,9 +21,9 @@ interface SessionStoreOptions {
|
|
|
21
21
|
appId?: string;
|
|
22
22
|
/** Namespaces the storage keys, for apps holding more than one session. */
|
|
23
23
|
keyPrefix?: string;
|
|
24
|
-
|
|
24
|
+
onLogout?: () => void;
|
|
25
25
|
/** Called after a successful login or handoff, not after a refresh. */
|
|
26
|
-
|
|
26
|
+
onLogin?: () => void;
|
|
27
27
|
}
|
|
28
28
|
interface SessionStore {
|
|
29
29
|
getState(): SessionState;
|
|
@@ -34,7 +34,7 @@ interface SessionStore {
|
|
|
34
34
|
/** Forces a refresh regardless of expiry. Used after a rejected request. */
|
|
35
35
|
refresh(): Promise<string | null>;
|
|
36
36
|
login(email: string, password: string): Promise<AuthResult>;
|
|
37
|
-
/** Exchanges a social
|
|
37
|
+
/** Exchanges a social login handoff code. A failure leaves any existing session intact. */
|
|
38
38
|
redeemHandoff(code: string, verifier: string): Promise<AuthResult & {
|
|
39
39
|
redirect?: string;
|
|
40
40
|
}>;
|
|
@@ -87,11 +87,11 @@ type PyloSelect<E extends PyloEntity> = EntitySelect<RegisteredSchema, E>;
|
|
|
87
87
|
* `typeof <yourSelect>` (see {@link PyloSelect}) for an exact result type.
|
|
88
88
|
*/
|
|
89
89
|
type PyloResult<E extends PyloEntity, Sel extends PyloSelect<E>> = EntityResult<RegisteredSchema, E, Sel>;
|
|
90
|
-
/** Providers `
|
|
90
|
+
/** Providers `loginWith` accepts. Codegen narrows it to those enabled for the app. */
|
|
91
91
|
type RegisteredSocialProvider = PyloRegister extends {
|
|
92
92
|
socialProvider: infer P extends string;
|
|
93
93
|
} ? P : SocialProvider;
|
|
94
|
-
/** Return URLs `
|
|
94
|
+
/** Return URLs `loginWith` accepts. Codegen narrows it to the app's allowlist. */
|
|
95
95
|
type RegisteredSocialReturnUrl = PyloRegister extends {
|
|
96
96
|
socialReturnUrl: infer U extends string;
|
|
97
97
|
} ? U : string;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createPyloHooks
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-FKUNSR3E.js";
|
|
4
4
|
import {
|
|
5
5
|
PyloProvider,
|
|
6
6
|
createDirectTransport,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
usePyloAuth,
|
|
11
11
|
usePyloClient,
|
|
12
12
|
usePyloTransport
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-BPRHGSZF.js";
|
|
14
14
|
|
|
15
15
|
// src/index.ts
|
|
16
16
|
import { PyloError } from "@pylo/core";
|
|
@@ -22,22 +22,22 @@ declare function createMemoryStorage(): PyloStorage;
|
|
|
22
22
|
*/
|
|
23
23
|
declare function createLocalStorageAdapter(): PyloStorage;
|
|
24
24
|
|
|
25
|
-
type
|
|
25
|
+
type SocialLoginResult = AuthResult & {
|
|
26
26
|
redirect?: string;
|
|
27
27
|
};
|
|
28
28
|
type OpenAuthSession = (url: string, returnUrl: string) => Promise<string | null>;
|
|
29
|
-
interface
|
|
29
|
+
interface SocialLogin<P extends string = SocialProvider, U extends string = string> {
|
|
30
30
|
/**
|
|
31
31
|
* On the web this navigates away and never resolves; finish on the return page
|
|
32
|
-
* with `
|
|
32
|
+
* with `completeLogin`. With `openAuthSession` it resolves once the session ends.
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
loginWith(provider: P, options: {
|
|
35
35
|
returnUrl: U;
|
|
36
36
|
redirect?: string;
|
|
37
37
|
invite?: string;
|
|
38
|
-
}): Promise<
|
|
39
|
-
/** Finishes a web
|
|
40
|
-
|
|
38
|
+
}): Promise<SocialLoginResult>;
|
|
39
|
+
/** Finishes a web login from the return page's URL. */
|
|
40
|
+
completeLogin(url?: string): Promise<SocialLoginResult>;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
interface PyloProviderProps {
|
|
@@ -52,7 +52,7 @@ interface PyloProviderProps {
|
|
|
52
52
|
*/
|
|
53
53
|
getToken?: () => Promise<string | null>;
|
|
54
54
|
/**
|
|
55
|
-
* Runs social
|
|
55
|
+
* Runs social login in an in-app browser session instead of navigating the
|
|
56
56
|
* page. Resolves with the URL the session ended on, or `null` when dismissed.
|
|
57
57
|
*/
|
|
58
58
|
openAuthSession?: OpenAuthSession;
|
|
@@ -61,9 +61,9 @@ interface PyloProviderProps {
|
|
|
61
61
|
declare function PyloProvider(props: PyloProviderProps): react_jsx_runtime.JSX.Element;
|
|
62
62
|
declare function usePyloTransport(): Transport;
|
|
63
63
|
declare function usePyloClient<S>(): PyloClient<S>;
|
|
64
|
-
interface PyloAuth<P extends string = SocialProvider, U extends string = string> extends
|
|
64
|
+
interface PyloAuth<P extends string = SocialProvider, U extends string = string> extends SocialLogin<P, U> {
|
|
65
65
|
isLoading: boolean;
|
|
66
|
-
|
|
66
|
+
isLoggedIn: boolean;
|
|
67
67
|
user: PyloUser | undefined;
|
|
68
68
|
login: (email: string, password: string) => Promise<AuthResult>;
|
|
69
69
|
logout: () => Promise<void>;
|
|
@@ -71,4 +71,4 @@ interface PyloAuth<P extends string = SocialProvider, U extends string = string>
|
|
|
71
71
|
}
|
|
72
72
|
declare function usePyloAuth(): PyloAuth;
|
|
73
73
|
|
|
74
|
-
export { type OpenAuthSession as O, type PyloStorage as P, type
|
|
74
|
+
export { type OpenAuthSession as O, type PyloStorage as P, type SocialLogin as S, type PyloAuth as a, PyloProvider as b, type PyloProviderProps as c, type SocialLoginResult as d, createLocalStorageAdapter as e, createMemoryStorage as f, usePyloTransport as g, usePyloAuth as h, usePyloClient as u };
|
package/dist/provider.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import 'react/jsx-runtime';
|
|
|
2
2
|
import 'react';
|
|
3
3
|
import '@pylo/core';
|
|
4
4
|
import '@pylo/auth';
|
|
5
|
-
export { a as PyloAuth, b as PyloProvider, c as PyloProviderProps, h as usePyloAuth, u as usePyloClient, g as usePyloTransport } from './provider-
|
|
5
|
+
export { a as PyloAuth, b as PyloProvider, c as PyloProviderProps, h as usePyloAuth, u as usePyloClient, g as usePyloTransport } from './provider-4DBl_6p0.js';
|
|
6
6
|
import './transport-55cSrvQo.js';
|
package/dist/provider.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pylo/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Type-safe React SDK for Pylo — hooks, session provider, client",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"LICENSE"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@pylo/auth": "0.
|
|
40
|
-
"@pylo/core": "0.
|
|
39
|
+
"@pylo/auth": "0.2.0",
|
|
40
|
+
"@pylo/core": "0.10.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@tanstack/react-query": ">=5.0.0",
|