@microsoft/rayfin-client 1.26.0 → 1.27.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/client.d.ts +37 -13
- package/dist/client.js +61 -32
- package/package.json +4 -4
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Main entry point for the Rayfin SDK.
|
|
3
|
-
*
|
|
3
|
+
* Exposes a browser-oriented RayfinClient (with full Auth support) and a
|
|
4
|
+
* server/worker-oriented RayfinServerClient (no Auth, token-based auth).
|
|
4
5
|
*/
|
|
5
6
|
import { Auth, AuthStorage } from '@microsoft/rayfin-auth';
|
|
6
7
|
import { type EntitySchema, createDataApi } from '@microsoft/rayfin-data';
|
|
@@ -21,13 +22,28 @@ export interface RayfinClientConfig extends ApiClientConfig {
|
|
|
21
22
|
*/
|
|
22
23
|
authStorage?: AuthStorage | boolean;
|
|
23
24
|
}
|
|
25
|
+
export interface RayfinServerClientConfig extends Omit<ApiClientConfig, 'getAccessToken'> {
|
|
26
|
+
/** Access token (string or function) for Authorization: Bearer <token>. Use the function form to rotate per request. */
|
|
27
|
+
accessToken?: string | (() => string | null);
|
|
28
|
+
}
|
|
29
|
+
/** Shared base for Rayfin clients: owns the typed data API and the underlying HTTP client. */
|
|
30
|
+
export declare abstract class RayfinClientBase<TSchema extends EntitySchema = Record<string, any>> {
|
|
31
|
+
readonly data: ReturnType<typeof createDataApi<TSchema>>;
|
|
32
|
+
protected apiClient: ApiClient;
|
|
33
|
+
protected constructor(config: ApiClientConfig);
|
|
34
|
+
static readonly errors: {
|
|
35
|
+
SdkError: typeof SdkError;
|
|
36
|
+
AuthError: typeof AuthError;
|
|
37
|
+
NetworkError: typeof NetworkError;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
24
40
|
/**
|
|
25
41
|
* Main SDK class for Rayfin.
|
|
26
42
|
* This class acts as the primary interface for interacting with Rayfin services,
|
|
27
43
|
* providing authentication, and GraphQL capabilities through a single entry point.
|
|
28
44
|
*
|
|
29
45
|
* @template TSchema - Object type mapping entity names to their types
|
|
30
|
-
* @example
|
|
46
|
+
* @example Frontend usage
|
|
31
47
|
* ```typescript
|
|
32
48
|
* const client = new RayfinClient<{
|
|
33
49
|
* User: User;
|
|
@@ -47,19 +63,27 @@ export interface RayfinClientConfig extends ApiClientConfig {
|
|
|
47
63
|
* .execute();
|
|
48
64
|
* ```
|
|
49
65
|
*/
|
|
50
|
-
export declare class RayfinClient<TSchema extends EntitySchema = Record<string, any>> {
|
|
66
|
+
export declare class RayfinClient<TSchema extends EntitySchema = Record<string, any>> extends RayfinClientBase<TSchema> {
|
|
51
67
|
readonly auth: Auth;
|
|
52
|
-
readonly data: ReturnType<typeof createDataApi<TSchema>>;
|
|
53
|
-
protected apiClient: ApiClient;
|
|
54
|
-
/**
|
|
55
|
-
* @param config Configuration for the SDK, including API base URL and publishable key.
|
|
56
|
-
*/
|
|
57
68
|
constructor(config: RayfinClientConfig);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Server / worker (Node.js) Rayfin client. Skips the browser-coupled Auth
|
|
72
|
+
* module entirely — authentication is supplied via the accessToken config.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const client = new RayfinServerClient<{ Todo: Todo }>({
|
|
77
|
+
* baseUrl: process.env.RAYFIN_BASE_URL!,
|
|
78
|
+
* publishableKey: process.env.RAYFIN_PUBLISHABLE_KEY!,
|
|
79
|
+
* accessToken: () => incomingRequest.headers.authorization,
|
|
80
|
+
* });
|
|
81
|
+
*
|
|
82
|
+
* const todos = await client.data.Todo.select(['id', 'title']).execute();
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare class RayfinServerClient<TSchema extends EntitySchema = Record<string, any>> extends RayfinClientBase<TSchema> {
|
|
86
|
+
constructor(config: RayfinServerClientConfig);
|
|
63
87
|
}
|
|
64
88
|
export default RayfinClient;
|
|
65
89
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Main entry point for the Rayfin SDK.
|
|
3
|
-
*
|
|
3
|
+
* Exposes a browser-oriented RayfinClient (with full Auth support) and a
|
|
4
|
+
* server/worker-oriented RayfinServerClient (no Auth, token-based auth).
|
|
4
5
|
*/
|
|
5
6
|
import { Auth } from '@microsoft/rayfin-auth';
|
|
6
7
|
import { createDataApi } from '@microsoft/rayfin-data';
|
|
@@ -14,13 +15,41 @@ export class AuthError extends SdkError {
|
|
|
14
15
|
super(message, code || 'AUTH_ERROR');
|
|
15
16
|
}
|
|
16
17
|
}
|
|
18
|
+
/** Shared base for Rayfin clients: owns the typed data API and the underlying HTTP client. */
|
|
19
|
+
export class RayfinClientBase {
|
|
20
|
+
data;
|
|
21
|
+
apiClient;
|
|
22
|
+
constructor(config) {
|
|
23
|
+
if (!config.baseUrl && !config.useProxy) {
|
|
24
|
+
throw new SdkError('SDK configuration requires a baseUrl.', 'MISSING_BASE_URL');
|
|
25
|
+
}
|
|
26
|
+
if (!config.publishableKey || config.publishableKey.trim() === '') {
|
|
27
|
+
throw new SdkError('SDK configuration requires a publishableKey for service-level authentication.', 'MISSING_PUBLISHABLE_KEY');
|
|
28
|
+
}
|
|
29
|
+
this.apiClient = new ApiClient({
|
|
30
|
+
baseUrl: config.baseUrl,
|
|
31
|
+
publishableKey: config.publishableKey,
|
|
32
|
+
useProxy: config.useProxy,
|
|
33
|
+
headers: config.headers,
|
|
34
|
+
timeout: config.timeout,
|
|
35
|
+
getAccessToken: config.getAccessToken,
|
|
36
|
+
});
|
|
37
|
+
this.data = createDataApi(this.apiClient);
|
|
38
|
+
}
|
|
39
|
+
// Static access to custom errors for easy import by consumers
|
|
40
|
+
static errors = {
|
|
41
|
+
SdkError,
|
|
42
|
+
AuthError,
|
|
43
|
+
NetworkError,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
17
46
|
/**
|
|
18
47
|
* Main SDK class for Rayfin.
|
|
19
48
|
* This class acts as the primary interface for interacting with Rayfin services,
|
|
20
49
|
* providing authentication, and GraphQL capabilities through a single entry point.
|
|
21
50
|
*
|
|
22
51
|
* @template TSchema - Object type mapping entity names to their types
|
|
23
|
-
* @example
|
|
52
|
+
* @example Frontend usage
|
|
24
53
|
* ```typescript
|
|
25
54
|
* const client = new RayfinClient<{
|
|
26
55
|
* User: User;
|
|
@@ -40,40 +69,40 @@ export class AuthError extends SdkError {
|
|
|
40
69
|
* .execute();
|
|
41
70
|
* ```
|
|
42
71
|
*/
|
|
43
|
-
export class RayfinClient {
|
|
44
|
-
auth;
|
|
45
|
-
data; // Data-specific operations
|
|
46
|
-
apiClient;
|
|
47
|
-
/**
|
|
48
|
-
* @param config Configuration for the SDK, including API base URL and publishable key.
|
|
49
|
-
*/
|
|
72
|
+
export class RayfinClient extends RayfinClientBase {
|
|
73
|
+
auth;
|
|
50
74
|
constructor(config) {
|
|
51
|
-
|
|
52
|
-
throw new SdkError('SDK configuration requires a baseUrl.', 'MISSING_BASE_URL');
|
|
53
|
-
}
|
|
54
|
-
if (!config.publishableKey || config.publishableKey.trim() === '') {
|
|
55
|
-
throw new SdkError('SDK configuration requires a publishableKey for service-level authentication.', 'MISSING_PUBLISHABLE_KEY');
|
|
56
|
-
}
|
|
57
|
-
this.apiClient = new ApiClient({
|
|
58
|
-
baseUrl: config.baseUrl,
|
|
59
|
-
publishableKey: config.publishableKey,
|
|
60
|
-
useProxy: config.useProxy,
|
|
61
|
-
headers: config.headers,
|
|
62
|
-
timeout: config.timeout,
|
|
63
|
-
});
|
|
64
|
-
// Initialize modules
|
|
75
|
+
super(config);
|
|
65
76
|
this.auth = new Auth(this.apiClient, { storage: config.authStorage });
|
|
66
|
-
this.data = createDataApi(this.apiClient);
|
|
67
|
-
// Wire up the token callback to automatically include tokens in API requests
|
|
68
77
|
this.auth.attachToClient(this.apiClient);
|
|
69
78
|
}
|
|
70
|
-
// Static access to custom errors for easy import by consumers
|
|
71
|
-
static errors = {
|
|
72
|
-
SdkError,
|
|
73
|
-
AuthError,
|
|
74
|
-
NetworkError,
|
|
75
|
-
};
|
|
76
79
|
}
|
|
77
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Server / worker (Node.js) Rayfin client. Skips the browser-coupled Auth
|
|
82
|
+
* module entirely — authentication is supplied via the accessToken config.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const client = new RayfinServerClient<{ Todo: Todo }>({
|
|
87
|
+
* baseUrl: process.env.RAYFIN_BASE_URL!,
|
|
88
|
+
* publishableKey: process.env.RAYFIN_PUBLISHABLE_KEY!,
|
|
89
|
+
* accessToken: () => incomingRequest.headers.authorization,
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* const todos = await client.data.Todo.select(['id', 'title']).execute();
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export class RayfinServerClient extends RayfinClientBase {
|
|
96
|
+
constructor(config) {
|
|
97
|
+
super(config);
|
|
98
|
+
if (config.accessToken !== undefined) {
|
|
99
|
+
const tokenFn = typeof config.accessToken === 'function'
|
|
100
|
+
? config.accessToken
|
|
101
|
+
: () => config.accessToken;
|
|
102
|
+
this.apiClient.setAccessTokenCallback(tokenFn);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Default export remains the browser client for backward compatibility.
|
|
78
107
|
export default RayfinClient;
|
|
79
108
|
//# sourceMappingURL=client.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/rayfin-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.27.0",
|
|
4
4
|
"description": "Main client SDK for Rayfin services",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"LICENSE"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@microsoft/rayfin-
|
|
24
|
-
"@microsoft/rayfin-
|
|
25
|
-
"@microsoft/rayfin-lib": "1.
|
|
23
|
+
"@microsoft/rayfin-auth": "1.27.0",
|
|
24
|
+
"@microsoft/rayfin-data": "1.27.0",
|
|
25
|
+
"@microsoft/rayfin-lib": "1.27.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"typescript": "^5.8.3",
|