@pylo/react 0.8.0 → 0.9.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.
@@ -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: "signedIn", token: auth });
44
+ setState({ status: "loggedIn", token: auth });
45
45
  }
46
- async function signIn(auth, refresh2) {
46
+ async function startSession(auth, refresh2) {
47
47
  var _a2;
48
48
  await persist(auth, refresh2);
49
- (_a2 = options.onSignIn) == null ? void 0 : _a2.call(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: "signedOut", token: null });
57
- (_a2 = options.onSignOut) == null ? void 0 : _a2.call(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 !== "signedIn") return null;
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: "signedIn", token: auth } : { status: "signedOut", token: null }
91
+ auth ? { status: "loggedIn", token: auth } : { status: "loggedOut", token: null }
92
92
  );
93
93
  } catch {
94
94
  refreshToken = null;
95
- setState({ status: "signedOut", token: null });
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 signIn(auth_token, refresh_token);
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: "SIGN_IN_FAILED",
167
- message: error instanceof Error ? error.message : "Sign-in failed"
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: "SIGN_IN_FAILED",
176
- message: (_a2 = extractErrorMessage(response.errors)) != null ? _a2 : "Sign-in failed"
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 signIn(auth_token, refresh_token);
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 createSocialSignIn(o) {
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("SIGN_IN_FAILED", "No sign-in response in this URL");
209
- if ("error" in parsed) return failed("SIGN_IN_FAILED", parsed.error);
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("SIGN_IN_FAILED", "No sign-in was started in this browser session");
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("SIGN_IN_FAILED", error instanceof Error ? error.message : "Sign-in failed");
228
+ return failed("LOGIN_FAILED", error instanceof Error ? error.message : "Login failed");
229
229
  }
230
230
  }
231
231
  return {
232
- async signInWith(provider, { returnUrl, redirect, invite }) {
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
- "SIGN_IN_FAILED",
252
- error instanceof Error ? error.message : "Sign-in failed"
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", "Sign-in was 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
- completeSignIn(url) {
264
+ completeLogin(url) {
265
265
  if (o.openAuthSession) {
266
266
  return Promise.resolve(
267
- failed("SIGN_IN_FAILED", "signInWith already completes the sign-in in this environment")
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 SIGNED_OUT = { status: "signedOut", token: null };
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
- onSignOut: () => queryClient.clear(),
395
- onSignIn: () => void queryClient.invalidateQueries({ queryKey: ["pylo"] })
394
+ onLogout: () => queryClient.clear(),
395
+ onLogin: () => void queryClient.invalidateQueries({ queryKey: ["pylo"] })
396
396
  });
397
397
  if (props.appId !== void 0) {
398
- socialRef.current = createSocialSignIn({
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 : () => SIGNED_OUT,
415
- store ? store.getState : () => SIGNED_OUT
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 isSignedIn = state.status === "signedIn";
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: isSignedIn
460
+ enabled: isLoggedIn
461
461
  });
462
462
  return {
463
- isLoading: state.status === "loading" || isSignedIn && me.isLoading,
464
- isSignedIn,
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
- signInWith: async (provider, options) => requireSocial("signInWith").signInWith(provider, options),
479
- completeSignIn: async (url) => requireSocial("completeSignIn").completeSignIn(url),
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-3WSGP2SO.js";
3
+ } from "./chunk-BPRHGSZF.js";
4
4
 
5
5
  // src/hooks.ts
6
6
  import { useCallback, useRef, useState } from "react";
package/dist/hooks.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  import {
3
3
  createPyloHooks
4
- } from "./chunk-RCW4MW4F.js";
5
- import "./chunk-ZWYBNMHS.js";
4
+ } from "./chunk-O456XBDT.js";
5
+ import "./chunk-BPRHGSZF.js";
6
6
  export {
7
7
  createPyloHooks
8
8
  };
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-X8jgqOeN.js';
6
- export { O as OpenAuthSession, b as PyloProvider, c as PyloProviderProps, S as SocialSignIn, d as SocialSignInResult, e as createLocalStorageAdapter, f as createMemoryStorage, u as usePyloClient, g as usePyloTransport } from './provider-X8jgqOeN.js';
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" | "signedIn" | "signedOut";
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
- onSignOut?: () => void;
24
+ onLogout?: () => void;
25
25
  /** Called after a successful login or handoff, not after a refresh. */
26
- onSignIn?: () => void;
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 sign-in handoff code. A failure leaves any existing session intact. */
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 `signInWith` accepts. Codegen narrows it to those enabled for the app. */
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 `signInWith` accepts. Codegen narrows it to the app's allowlist. */
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-RCW4MW4F.js";
3
+ } from "./chunk-O456XBDT.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-ZWYBNMHS.js";
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 SocialSignInResult = AuthResult & {
25
+ type SocialLoginResult = AuthResult & {
26
26
  redirect?: string;
27
27
  };
28
28
  type OpenAuthSession = (url: string, returnUrl: string) => Promise<string | null>;
29
- interface SocialSignIn<P extends string = SocialProvider, U extends string = string> {
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 `completeSignIn`. With `openAuthSession` it resolves once the session ends.
32
+ * with `completeLogin`. With `openAuthSession` it resolves once the session ends.
33
33
  */
34
- signInWith(provider: P, options: {
34
+ loginWith(provider: P, options: {
35
35
  returnUrl: U;
36
36
  redirect?: string;
37
37
  invite?: string;
38
- }): Promise<SocialSignInResult>;
39
- /** Finishes a web sign-in from the return page's URL. */
40
- completeSignIn(url?: string): Promise<SocialSignInResult>;
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 sign-in in an in-app browser session instead of navigating the
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 SocialSignIn<P, U> {
64
+ interface PyloAuth<P extends string = SocialProvider, U extends string = string> extends SocialLogin<P, U> {
65
65
  isLoading: boolean;
66
- isSignedIn: boolean;
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 SocialSignIn as S, type PyloAuth as a, PyloProvider as b, type PyloProviderProps as c, type SocialSignInResult as d, createLocalStorageAdapter as e, createMemoryStorage as f, usePyloTransport as g, usePyloAuth as h, usePyloClient as u };
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 };
@@ -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-X8jgqOeN.js';
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
@@ -3,7 +3,7 @@ import {
3
3
  usePyloAuth,
4
4
  usePyloClient,
5
5
  usePyloTransport
6
- } from "./chunk-ZWYBNMHS.js";
6
+ } from "./chunk-BPRHGSZF.js";
7
7
  export {
8
8
  PyloProvider,
9
9
  usePyloAuth,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pylo/react",
3
- "version": "0.8.0",
3
+ "version": "0.9.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.1.0",
40
- "@pylo/core": "0.8.0"
39
+ "@pylo/auth": "0.2.0",
40
+ "@pylo/core": "0.8.1"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "@tanstack/react-query": ">=5.0.0",