@pylo/react 0.7.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/LICENSE +21 -0
- package/README.md +113 -0
- package/dist/chunk-DOPZ5GRU.js +540 -0
- package/dist/chunk-IKQ52QLH.js +347 -0
- package/dist/chunk-SBMMJYJT.js +346 -0
- package/dist/chunk-VUY6OTMP.js +540 -0
- package/dist/cli.js +27 -0
- package/dist/codegen.d.ts +1 -0
- package/dist/codegen.js +5 -0
- package/dist/hooks.d.ts +97 -0
- package/dist/hooks.js +8 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.js +28 -0
- package/dist/provider-DTTtfhib.d.ts +50 -0
- package/dist/provider.d.ts +6 -0
- package/dist/provider.js +12 -0
- package/dist/transport-55cSrvQo.d.ts +14 -0
- package/package.json +74 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { EntityName, EntitySelect, EntityResult } from '@pylo/core';
|
|
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
|
+
import { P as PyloStorage } from './provider-DTTtfhib.js';
|
|
4
|
+
export { a as PyloAuth, b as PyloProvider, c as PyloProviderProps, d as createLocalStorageAdapter, e as createMemoryStorage, u as usePyloAuth, f as usePyloClient, g as usePyloTransport } from './provider-DTTtfhib.js';
|
|
5
|
+
import { AuthResult } from '@pylo/auth';
|
|
6
|
+
export { AuthResult, PyloUser } from '@pylo/auth';
|
|
7
|
+
export { D as DirectTransportOptions, T as Transport, c as createDirectTransport } from './transport-55cSrvQo.js';
|
|
8
|
+
export { InfiniteListOptions, ListHookResult, StartUploadOptions, UploadHookOptions, UploadHookResult, createPyloHooks } from './hooks.js';
|
|
9
|
+
import 'react/jsx-runtime';
|
|
10
|
+
import 'react';
|
|
11
|
+
import '@tanstack/react-query';
|
|
12
|
+
|
|
13
|
+
type SessionStatus = "loading" | "signedIn" | "signedOut";
|
|
14
|
+
interface SessionState {
|
|
15
|
+
status: SessionStatus;
|
|
16
|
+
token: string | null;
|
|
17
|
+
}
|
|
18
|
+
interface SessionStoreOptions {
|
|
19
|
+
endpoint: string;
|
|
20
|
+
storage: PyloStorage;
|
|
21
|
+
appId?: string;
|
|
22
|
+
/** Namespaces the storage keys, for apps holding more than one session. */
|
|
23
|
+
keyPrefix?: string;
|
|
24
|
+
onSignOut?: () => void;
|
|
25
|
+
/** Called after a successful login, not after a refresh. */
|
|
26
|
+
onSignIn?: () => void;
|
|
27
|
+
}
|
|
28
|
+
interface SessionStore {
|
|
29
|
+
getState(): SessionState;
|
|
30
|
+
subscribe(listener: () => void): () => void;
|
|
31
|
+
init(): Promise<void>;
|
|
32
|
+
/** The token to send, refreshed first if it is close enough to expiry. */
|
|
33
|
+
getToken(): Promise<string | null>;
|
|
34
|
+
/** Forces a refresh regardless of expiry. Used after a rejected request. */
|
|
35
|
+
refresh(): Promise<string | null>;
|
|
36
|
+
login(email: string, password: string): Promise<AuthResult>;
|
|
37
|
+
logout(): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
declare function createSessionStore(options: SessionStoreOptions): SessionStore;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Augmentable registry that pins the schema type for the `PyloSelect` /
|
|
43
|
+
* `PyloResult` helpers. Generated code augments it, e.g.:
|
|
44
|
+
*
|
|
45
|
+
* declare module "@pylo/react" {
|
|
46
|
+
* interface PyloRegister { schema: PyloSchema }
|
|
47
|
+
* }
|
|
48
|
+
*
|
|
49
|
+
* With no augmentation the helpers fall back to an untyped (`any`) schema.
|
|
50
|
+
*/
|
|
51
|
+
interface PyloRegister {
|
|
52
|
+
}
|
|
53
|
+
type RegisteredSchema = PyloRegister extends {
|
|
54
|
+
schema: infer S;
|
|
55
|
+
} ? S : any;
|
|
56
|
+
/**
|
|
57
|
+
* Entity keys available on the registered schema — e.g. `"contact"`. Use as the
|
|
58
|
+
* type parameter for {@link PyloSelect} / {@link PyloResult}.
|
|
59
|
+
*/
|
|
60
|
+
type PyloEntity = EntityName<RegisteredSchema>;
|
|
61
|
+
/**
|
|
62
|
+
* A reusable, type-safe selection for one entity on the registered schema.
|
|
63
|
+
* Lets you define what to fetch once and reuse it across hooks.
|
|
64
|
+
*
|
|
65
|
+
* Declare the selection with `satisfies` (not a plain `: PyloSelect<…>`
|
|
66
|
+
* annotation) so the exact set of selected fields is preserved — that's what
|
|
67
|
+
* keeps {@link PyloResult} precise:
|
|
68
|
+
*
|
|
69
|
+
* ```ts
|
|
70
|
+
* const contactSelect = {
|
|
71
|
+
* name: true,
|
|
72
|
+
* email: true,
|
|
73
|
+
* company: { select: { name: true } },
|
|
74
|
+
* } satisfies PyloSelect<"contact">;
|
|
75
|
+
*
|
|
76
|
+
* const { data } = usePyloList("contact", { select: contactSelect });
|
|
77
|
+
* type Contact = PyloResult<"contact", typeof contactSelect>;
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
type PyloSelect<E extends PyloEntity> = EntitySelect<RegisteredSchema, E>;
|
|
81
|
+
/**
|
|
82
|
+
* The row type returned for a given entity and selection. Pair with
|
|
83
|
+
* `typeof <yourSelect>` (see {@link PyloSelect}) for an exact result type.
|
|
84
|
+
*/
|
|
85
|
+
type PyloResult<E extends PyloEntity, Sel extends PyloSelect<E>> = EntityResult<RegisteredSchema, E, Sel>;
|
|
86
|
+
|
|
87
|
+
export { type PyloEntity, type PyloRegister, type PyloResult, type PyloSelect, PyloStorage, type RegisteredSchema, type SessionState, type SessionStatus, type SessionStore, type SessionStoreOptions, createSessionStore };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createPyloHooks
|
|
3
|
+
} from "./chunk-DOPZ5GRU.js";
|
|
4
|
+
import {
|
|
5
|
+
PyloProvider,
|
|
6
|
+
createDirectTransport,
|
|
7
|
+
createLocalStorageAdapter,
|
|
8
|
+
createMemoryStorage,
|
|
9
|
+
createSessionStore,
|
|
10
|
+
usePyloAuth,
|
|
11
|
+
usePyloClient,
|
|
12
|
+
usePyloTransport
|
|
13
|
+
} from "./chunk-IKQ52QLH.js";
|
|
14
|
+
|
|
15
|
+
// src/index.ts
|
|
16
|
+
import { PyloError } from "@pylo/core";
|
|
17
|
+
export {
|
|
18
|
+
PyloError,
|
|
19
|
+
PyloProvider,
|
|
20
|
+
createDirectTransport,
|
|
21
|
+
createLocalStorageAdapter,
|
|
22
|
+
createMemoryStorage,
|
|
23
|
+
createPyloHooks,
|
|
24
|
+
createSessionStore,
|
|
25
|
+
usePyloAuth,
|
|
26
|
+
usePyloClient,
|
|
27
|
+
usePyloTransport
|
|
28
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { PyloClient } from '@pylo/core';
|
|
4
|
+
import { PyloUser, AuthResult } from '@pylo/auth';
|
|
5
|
+
import { T as Transport } from './transport-55cSrvQo.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The three operations a session needs from a key-value store. Async because
|
|
9
|
+
* the native implementations are: Expo's SecureStore has no synchronous API.
|
|
10
|
+
*/
|
|
11
|
+
interface PyloStorage {
|
|
12
|
+
getItem(key: string): Promise<string | null>;
|
|
13
|
+
setItem(key: string, value: string): Promise<void>;
|
|
14
|
+
removeItem(key: string): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
declare function createMemoryStorage(): PyloStorage;
|
|
17
|
+
/**
|
|
18
|
+
* Persists to `localStorage`, falling back to memory where it is missing or
|
|
19
|
+
* blocked — server rendering, and Safari's private mode, which throws on write.
|
|
20
|
+
* Falling back means the session lasts the page's lifetime rather than failing
|
|
21
|
+
* outright, so a read consults memory whenever the web store comes up empty.
|
|
22
|
+
*/
|
|
23
|
+
declare function createLocalStorageAdapter(): PyloStorage;
|
|
24
|
+
|
|
25
|
+
interface PyloProviderProps {
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
endpoint?: string;
|
|
28
|
+
appId?: string;
|
|
29
|
+
storage?: PyloStorage;
|
|
30
|
+
keyPrefix?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Escape hatch for apps whose auth lives elsewhere. Supplying it disables the
|
|
33
|
+
* session entirely: no login, no logout, no refresh.
|
|
34
|
+
*/
|
|
35
|
+
getToken?: () => Promise<string | null>;
|
|
36
|
+
}
|
|
37
|
+
declare function PyloProvider(props: PyloProviderProps): react_jsx_runtime.JSX.Element;
|
|
38
|
+
declare function usePyloTransport(): Transport;
|
|
39
|
+
declare function usePyloClient<S>(): PyloClient<S>;
|
|
40
|
+
interface PyloAuth {
|
|
41
|
+
isLoading: boolean;
|
|
42
|
+
isSignedIn: boolean;
|
|
43
|
+
user: PyloUser | undefined;
|
|
44
|
+
login: (email: string, password: string) => Promise<AuthResult>;
|
|
45
|
+
logout: () => Promise<void>;
|
|
46
|
+
getToken: () => Promise<string | null>;
|
|
47
|
+
}
|
|
48
|
+
declare function usePyloAuth(): PyloAuth;
|
|
49
|
+
|
|
50
|
+
export { type PyloStorage as P, type PyloAuth as a, PyloProvider as b, type PyloProviderProps as c, createLocalStorageAdapter as d, createMemoryStorage as e, usePyloClient as f, usePyloTransport as g, usePyloAuth as u };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import 'react/jsx-runtime';
|
|
2
|
+
import 'react';
|
|
3
|
+
import '@pylo/core';
|
|
4
|
+
import '@pylo/auth';
|
|
5
|
+
export { a as PyloAuth, b as PyloProvider, c as PyloProviderProps, u as usePyloAuth, f as usePyloClient, g as usePyloTransport } from './provider-DTTtfhib.js';
|
|
6
|
+
import './transport-55cSrvQo.js';
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the hooks reach the API. `@pylo/react` talks to it directly; `@pylo/nextjs`
|
|
3
|
+
* posts to its route handler so the token can stay in an httpOnly cookie.
|
|
4
|
+
*/
|
|
5
|
+
type Transport = (query: string, variables: Record<string, unknown>, headers?: Record<string, string>) => Promise<unknown>;
|
|
6
|
+
interface DirectTransportOptions {
|
|
7
|
+
endpoint: string;
|
|
8
|
+
getToken: () => Promise<string | null>;
|
|
9
|
+
/** Called once on an unauthorized response; returns the token to retry with. */
|
|
10
|
+
onUnauthorized?: () => Promise<string | null>;
|
|
11
|
+
}
|
|
12
|
+
declare function createDirectTransport(options: DirectTransportOptions): Transport;
|
|
13
|
+
|
|
14
|
+
export { type DirectTransportOptions as D, type Transport as T, createDirectTransport as c };
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pylo/react",
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "Type-safe React SDK for Pylo — hooks, session provider, client",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"pylo": "dist/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./codegen": {
|
|
16
|
+
"types": "./dist/codegen.d.ts",
|
|
17
|
+
"import": "./dist/codegen.js",
|
|
18
|
+
"default": "./dist/codegen.js"
|
|
19
|
+
},
|
|
20
|
+
"./hooks": {
|
|
21
|
+
"types": "./dist/hooks.d.ts",
|
|
22
|
+
"import": "./dist/hooks.js",
|
|
23
|
+
"default": "./dist/hooks.js"
|
|
24
|
+
},
|
|
25
|
+
"./provider": {
|
|
26
|
+
"types": "./dist/provider.d.ts",
|
|
27
|
+
"import": "./dist/provider.js",
|
|
28
|
+
"default": "./dist/provider.js"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"main": "dist/index.js",
|
|
33
|
+
"types": "dist/index.d.ts",
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@pylo/auth": "0.0.6",
|
|
40
|
+
"@pylo/core": "0.7.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@tanstack/react-query": ">=5.0.0",
|
|
44
|
+
"react": ">=18.0.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@tanstack/react-query": "^5.0.0",
|
|
48
|
+
"@types/node": "^22.15.21",
|
|
49
|
+
"@types/react": "^19.0.0",
|
|
50
|
+
"react": "^19.0.0",
|
|
51
|
+
"tsup": "^8.5.1",
|
|
52
|
+
"typescript": "^5.9.3"
|
|
53
|
+
},
|
|
54
|
+
"keywords": [
|
|
55
|
+
"pylo",
|
|
56
|
+
"react",
|
|
57
|
+
"sdk"
|
|
58
|
+
],
|
|
59
|
+
"author": "Okeano GmbH",
|
|
60
|
+
"license": "MIT",
|
|
61
|
+
"homepage": "https://github.com/Okeano-GmbH/pylo-sdks/tree/main/react#readme",
|
|
62
|
+
"repository": {
|
|
63
|
+
"type": "git",
|
|
64
|
+
"url": "git+https://github.com/Okeano-GmbH/pylo-sdks.git",
|
|
65
|
+
"directory": "react"
|
|
66
|
+
},
|
|
67
|
+
"bugs": {
|
|
68
|
+
"url": "https://github.com/Okeano-GmbH/pylo-sdks/issues"
|
|
69
|
+
},
|
|
70
|
+
"scripts": {
|
|
71
|
+
"build": "tsup",
|
|
72
|
+
"watch": "tsc -w"
|
|
73
|
+
}
|
|
74
|
+
}
|