@microsoft/rayfin-client 1.20.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 ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) Microsoft Corporation.
2
+
3
+ MIT License
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/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # @microsoft/rayfin-client
2
+
3
+ ## Security
4
+
5
+ Microsoft takes the security of our software products and services seriously, which
6
+ includes all source code repositories in our GitHub organizations.
7
+
8
+ **Please do not report security vulnerabilities through public GitHub issues.**
9
+
10
+ For security reporting information, locations, contact information, and policies,
11
+ please review the latest guidance for Microsoft repositories at
12
+ [https://aka.ms/SECURITY.md](https://aka.ms/SECURITY.md).
13
+
14
+ ## Trademarks
15
+
16
+ This project may contain trademarks or logos for projects, products, or services.
17
+ Authorized use of Microsoft trademarks or logos must follow the [Microsoft Trademark and Brand Guidelines](https://www.microsoft.com/legal/intellectualproperty/trademarks/usage/general).
18
+ Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
19
+ Any use of third-party trademarks or logos is subject to those third parties' policies.
20
+
21
+ ## License
22
+
23
+ Copyright (c) Microsoft Corporation.
24
+
25
+ MIT License
26
+
27
+ Permission is hereby granted, free of charge, to any person obtaining a copy
28
+ of this software and associated documentation files (the "Software"), to deal
29
+ in the Software without restriction, including without limitation the rights
30
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31
+ copies of the Software, and to permit persons to whom the Software is
32
+ furnished to do so, subject to the following conditions:
33
+
34
+ The above copyright notice and this permission notice shall be included in all
35
+ copies or substantial portions of the Software.
36
+
37
+ THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43
+ SOFTWARE.
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @fileoverview Main entry point for the Rayfin SDK.
3
+ * This file orchestrates the different modules and provides the public SDK interface.
4
+ */
5
+ import { Auth, AuthStorage } from '@microsoft/rayfin-auth';
6
+ import { type EntitySchema, createDataApi } from '@microsoft/rayfin-data';
7
+ import { SdkError, NetworkError } from '@microsoft/rayfin-lib';
8
+ import { ApiClient, ApiClientConfig } from '@microsoft/rayfin-lib';
9
+ /**
10
+ * Auth error specific to the Rayfin SDK.
11
+ */
12
+ export declare class AuthError extends SdkError {
13
+ constructor(message: string, code?: string);
14
+ }
15
+ export interface RayfinClientConfig extends ApiClientConfig {
16
+ /**
17
+ * Storage implementation for authentication tokens.
18
+ * If set to true, localStorage will be used.
19
+ * If set to false, no storage will be used.
20
+ * You may also provide your own storage or use browser's built-in Session Storage
21
+ */
22
+ authStorage?: AuthStorage | boolean;
23
+ }
24
+ /**
25
+ * Main SDK class for Rayfin.
26
+ * This class acts as the primary interface for interacting with Rayfin services,
27
+ * providing authentication, and GraphQL capabilities through a single entry point.
28
+ *
29
+ * @template TSchema - Object type mapping entity names to their types
30
+ * @example
31
+ * ```typescript
32
+ * const client = new RayfinClient<{
33
+ * User: User;
34
+ * Organization: Organization;
35
+ * }>({
36
+ * baseUrl: 'http://localhost:5000',
37
+ * publishableKey: 'pk-Abc123-def456-GHI78'
38
+ * });
39
+ *
40
+ * // Authentication operations
41
+ * await client.auth.signUp({ email: 'user@example.com', password: 'password' });
42
+ *
43
+ * // GraphQL operations
44
+ * const activeUsers = await client.User
45
+ * .select(['id', 'name', 'email'])
46
+ * .where({ isActive: true })
47
+ * .execute();
48
+ * ```
49
+ */
50
+ export declare class RayfinClient<TSchema extends EntitySchema = Record<string, any>> {
51
+ 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
+ constructor(config: RayfinClientConfig);
58
+ static readonly errors: {
59
+ SdkError: typeof SdkError;
60
+ AuthError: typeof AuthError;
61
+ NetworkError: typeof NetworkError;
62
+ };
63
+ }
64
+ export default RayfinClient;
65
+ //# sourceMappingURL=client.d.ts.map
package/dist/client.js ADDED
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @fileoverview Main entry point for the Rayfin SDK.
3
+ * This file orchestrates the different modules and provides the public SDK interface.
4
+ */
5
+ import { Auth } from '@microsoft/rayfin-auth';
6
+ import { createDataApi } from '@microsoft/rayfin-data';
7
+ import { SdkError, NetworkError } from '@microsoft/rayfin-lib';
8
+ import { ApiClient } from '@microsoft/rayfin-lib';
9
+ /**
10
+ * Auth error specific to the Rayfin SDK.
11
+ */
12
+ export class AuthError extends SdkError {
13
+ constructor(message, code) {
14
+ super(message, code || 'AUTH_ERROR');
15
+ }
16
+ }
17
+ /**
18
+ * Main SDK class for Rayfin.
19
+ * This class acts as the primary interface for interacting with Rayfin services,
20
+ * providing authentication, and GraphQL capabilities through a single entry point.
21
+ *
22
+ * @template TSchema - Object type mapping entity names to their types
23
+ * @example
24
+ * ```typescript
25
+ * const client = new RayfinClient<{
26
+ * User: User;
27
+ * Organization: Organization;
28
+ * }>({
29
+ * baseUrl: 'http://localhost:5000',
30
+ * publishableKey: 'pk-Abc123-def456-GHI78'
31
+ * });
32
+ *
33
+ * // Authentication operations
34
+ * await client.auth.signUp({ email: 'user@example.com', password: 'password' });
35
+ *
36
+ * // GraphQL operations
37
+ * const activeUsers = await client.User
38
+ * .select(['id', 'name', 'email'])
39
+ * .where({ isActive: true })
40
+ * .execute();
41
+ * ```
42
+ */
43
+ export class RayfinClient {
44
+ auth; // The authentication module using the full Auth class
45
+ data; // Data-specific operations
46
+ apiClient;
47
+ /**
48
+ * @param config Configuration for the SDK, including API base URL and publishable key.
49
+ */
50
+ constructor(config) {
51
+ if (!config.baseUrl && !config.useProxy) {
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
65
+ 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
+ this.auth.attachToClient(this.apiClient);
69
+ }
70
+ // Static access to custom errors for easy import by consumers
71
+ static errors = {
72
+ SdkError,
73
+ AuthError,
74
+ NetworkError,
75
+ };
76
+ }
77
+ // Export default client and types
78
+ export default RayfinClient;
79
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1,29 @@
1
+ import { ServicePlugin, TServiceClasses, ServicePluginFactory } from '@microsoft/rayfin-lib';
2
+ import RayfinClient, { RayfinClientConfig } from '../client';
3
+ export { ServicePlugin, type TServiceClasses, type ServicePluginFactory as ServicePluginClass, };
4
+ /**
5
+ * (Experimental) Extendable Rayfin Client supports adding custom services. Use `ExtendableRayfinClient.create` to instantiate.
6
+ * @alpha
7
+ * @hidden
8
+ */
9
+ export declare class ExtendableRayfinClient<TSchema extends Record<string, any> = Record<string, any>, TServices extends Record<string, ServicePlugin> = Record<string, ServicePlugin>> extends RayfinClient<TSchema> {
10
+ private services;
11
+ protected constructor(config: RayfinClientConfig & {
12
+ services?: TServiceClasses<TServices>;
13
+ });
14
+ private createProxy;
15
+ /**
16
+ * (Experimental) Create an instance of ExtendableRayfinClient with custom services.
17
+ * @alpha
18
+ * @hidden
19
+ * @param config - The configuration for the Rayfin client.
20
+ * @param services - The custom services to extend the client with.
21
+ * @returns An instance of ExtendableRayfinClient with the specified services.
22
+ */
23
+ static create<TSchema extends Record<string, any>, TServices extends Record<string, ServicePlugin>>(config: RayfinClientConfig & {
24
+ schema?: TSchema;
25
+ } & {
26
+ services?: TServiceClasses<TServices>;
27
+ }): ExtendableRayfinClient<TSchema, TServices> & TServices;
28
+ }
29
+ //# sourceMappingURL=ExtendableRayfinClient.d.ts.map
@@ -0,0 +1,67 @@
1
+ import { ServicePlugin, } from '@microsoft/rayfin-lib';
2
+ import RayfinClient from '../client';
3
+ export { ServicePlugin, };
4
+ /**
5
+ * (Experimental) Extendable Rayfin Client supports adding custom services. Use `ExtendableRayfinClient.create` to instantiate.
6
+ * @alpha
7
+ * @hidden
8
+ */
9
+ export class ExtendableRayfinClient extends RayfinClient {
10
+ services = {};
11
+ constructor(config) {
12
+ super(config);
13
+ const services = config.services || {};
14
+ this.services = Object.keys(services).reduce((acc, key) => {
15
+ acc[key] = services[key](this.apiClient);
16
+ return acc;
17
+ }, {});
18
+ return this.createProxy();
19
+ }
20
+ // Prioritize the client and then go to the services proxy
21
+ createProxy() {
22
+ return new Proxy(this, {
23
+ get: (target, prop) => {
24
+ if (prop in target) {
25
+ return target[prop];
26
+ }
27
+ if (target.services[prop]) {
28
+ return target.services[prop];
29
+ }
30
+ return undefined;
31
+ },
32
+ has: (target, prop) => {
33
+ if (prop in target) {
34
+ return true;
35
+ }
36
+ if (target.services[prop]) {
37
+ return true;
38
+ }
39
+ return false;
40
+ },
41
+ ownKeys: () => {
42
+ return Object.keys(this.services);
43
+ },
44
+ getOwnPropertyDescriptor: (target, prop) => {
45
+ if (prop in target) {
46
+ return Object.getOwnPropertyDescriptor(target, prop);
47
+ }
48
+ if (target.services[prop]) {
49
+ return Object.getOwnPropertyDescriptor(target.services, prop);
50
+ }
51
+ return undefined;
52
+ },
53
+ });
54
+ }
55
+ /**
56
+ * (Experimental) Create an instance of ExtendableRayfinClient with custom services.
57
+ * @alpha
58
+ * @hidden
59
+ * @param config - The configuration for the Rayfin client.
60
+ * @param services - The custom services to extend the client with.
61
+ * @returns An instance of ExtendableRayfinClient with the specified services.
62
+ */
63
+ static create(config) {
64
+ return new ExtendableRayfinClient(config);
65
+ }
66
+ }
67
+ //# sourceMappingURL=ExtendableRayfinClient.js.map
@@ -0,0 +1,3 @@
1
+ export { ExtendableRayfinClient, ServicePlugin, } from './ExtendableRayfinClient';
2
+ export type { TServiceClasses, ServicePluginClass, } from './ExtendableRayfinClient';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { ExtendableRayfinClient, ServicePlugin, } from './ExtendableRayfinClient';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,5 @@
1
+ export * from './client';
2
+ export { default } from './client';
3
+ export type { TypedDataClients, EntitySchema } from '@microsoft/rayfin-data';
4
+ export type { ApiClientConfig } from '@microsoft/rayfin-lib';
5
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ // Export all from client.ts
2
+ export * from './client';
3
+ export { default } from './client';
4
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@microsoft/rayfin-client",
3
+ "version": "1.20.0",
4
+ "description": "Main client SDK for Rayfin services",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "default": "./dist/index.js",
9
+ "types": "./dist/index.d.ts"
10
+ },
11
+ "./experimental": {
12
+ "default": "./dist/experimental/index.js",
13
+ "types": "./dist/experimental/index.d.ts"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist/**/*.js",
18
+ "dist/**/*.d.ts",
19
+ "!dist/**/__tests__/**",
20
+ "LICENSE"
21
+ ],
22
+ "dependencies": {
23
+ "@microsoft/rayfin-auth": "1.20.0",
24
+ "@microsoft/rayfin-lib": "1.20.0",
25
+ "@microsoft/rayfin-data": "1.20.0"
26
+ },
27
+ "devDependencies": {
28
+ "typescript": "^5.8.3",
29
+ "vitest": "^3.2.3",
30
+ "@vitest/coverage-v8": "~3.2.4",
31
+ "jsdom": "^24.1.0",
32
+ "rimraf": "~6.0.1"
33
+ },
34
+ "publishConfig": {
35
+ "registry": "https://npm.pkg.github.com",
36
+ "access": "restricted"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/microsoft/project-rayfin.git",
41
+ "directory": "packages/typescript-sdk/client"
42
+ },
43
+ "license": "MIT",
44
+ "scripts": {
45
+ "build": "tsc",
46
+ "test": "vitest run",
47
+ "clean": "rimraf dist && rimraf .tsbuildinfo"
48
+ }
49
+ }