@miradorlabs/parallax-web 1.0.0 → 1.0.2

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/index.ts CHANGED
@@ -1,2 +1,18 @@
1
1
  export * from './src/parallax';
2
2
  export { GrpcWebRpc } from './src/grpc';
3
+
4
+ // Re-export proto types for convenience
5
+ export {
6
+ CreateTraceRequest,
7
+ CreateTraceResponse,
8
+ StartSpanRequest,
9
+ StartSpanResponse,
10
+ FinishSpanRequest,
11
+ FinishSpanResponse,
12
+ AddSpanEventRequest,
13
+ AddSpanEventResponse,
14
+ AddSpanErrorRequest,
15
+ AddSpanErrorResponse,
16
+ AddSpanHintRequest,
17
+ AddSpanHintResponse,
18
+ } from 'mirador-gateway-parallax-web/proto/gateway/parallax/v1/parallax_gateway_pb';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miradorlabs/parallax-web",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Parallax Web Client Side SDK ",
5
5
  "main": "dist/index.umd.js",
6
6
  "module": "dist/index.esm.js",
@@ -45,6 +45,7 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "google-protobuf": "^4.0.1",
48
+ "grpc-web": "^2.0.2",
48
49
  "mirador-gateway-parallax-web": "https://storage.googleapis.com/mirador-shd-packages/gateway/parallax/grpc-web/mirador-gateway-parallax-grpc-web-1.0.9.tgz",
49
50
  "rxjs": "^7.8.2"
50
51
  },
package/rollup.config.mjs CHANGED
@@ -25,9 +25,7 @@ export default [
25
25
  }),
26
26
  ],
27
27
  external: [
28
- 'google-protobuf',
29
- 'mirador-gateway-parallax-web',
30
- /^mirador-gateway-parallax-web\/.*/,
28
+ // Keep these as peer dependencies - users should provide them
31
29
  'rxjs',
32
30
  /^rxjs\/.*/,
33
31
  ],
@@ -41,9 +39,6 @@ export default [
41
39
  name: 'ParallaxWeb',
42
40
  sourcemap: true,
43
41
  globals: {
44
- 'google-protobuf': 'googleProtobuf',
45
- 'mirador-gateway-parallax-web': 'miradorGatewayParallaxWeb',
46
- 'mirador-gateway-parallax-web/proto/gateway/parallax/v1/parallax_gateway': 'miradorGatewayParallaxWeb.parallaxGateway',
47
42
  'rxjs': 'rxjs',
48
43
  },
49
44
  },
@@ -60,9 +55,7 @@ export default [
60
55
  }),
61
56
  ],
62
57
  external: [
63
- 'google-protobuf',
64
- 'mirador-gateway-parallax-web',
65
- /^mirador-gateway-parallax-web\/.*/,
58
+ // Keep rxjs as external - it's commonly provided
66
59
  'rxjs',
67
60
  /^rxjs\/.*/,
68
61
  ],
@@ -76,9 +69,6 @@ export default [
76
69
  },
77
70
  plugins: [dts()],
78
71
  external: [
79
- 'google-protobuf',
80
- 'mirador-gateway-parallax-web',
81
- /^mirador-gateway-parallax-web\/.*/,
82
72
  'rxjs',
83
73
  /^rxjs\/.*/,
84
74
  ],
@@ -1,15 +1,19 @@
1
1
  // Parallax SDK Web Client
2
- import type {
2
+ import {
3
3
  CreateTraceRequest,
4
+ CreateTraceResponse,
4
5
  StartSpanRequest,
6
+ StartSpanResponse,
5
7
  FinishSpanRequest,
8
+ FinishSpanResponse,
6
9
  AddSpanEventRequest,
10
+ AddSpanEventResponse,
7
11
  AddSpanErrorRequest,
12
+ AddSpanErrorResponse,
8
13
  AddSpanHintRequest,
9
- AddSpanAttributesRequest
10
- } from "mirador-gateway-parallax-web/proto/gateway/parallax/v1/parallax_gateway";
11
- import * as apiGateway from "mirador-gateway-parallax-web/proto/gateway/parallax/v1/parallax_gateway";
12
- import { GrpcWebRpc } from "../grpc";
14
+ AddSpanHintResponse,
15
+ } from "mirador-gateway-parallax-web/proto/gateway/parallax/v1/parallax_gateway_pb";
16
+ import { ParallaxGatewayServiceClient } from "mirador-gateway-parallax-web/proto/gateway/parallax/v1/Parallax_gatewayServiceClientPb";
13
17
 
14
18
  const GRPC_GATEWAY_API_URL = "https://gateway-parallax-dev.platform.svc.cluster.local:50053";
15
19
 
@@ -20,13 +24,18 @@ const debugIssue = (trace: string, error: Error) => {
20
24
 
21
25
  class ParallaxClient {
22
26
  public apiUrl: string = GRPC_GATEWAY_API_URL;
23
- private apiGatewayRpc: GrpcWebRpc;
27
+ private client: ParallaxGatewayServiceClient;
24
28
 
25
29
  constructor(public apiKey?: string, apiUrl?: string) {
26
30
  if (apiUrl) {
27
31
  this.apiUrl = apiUrl;
28
32
  }
29
- this.apiGatewayRpc = new GrpcWebRpc(this.apiUrl, apiKey);
33
+
34
+ // Create credentials object with API key if provided
35
+ const credentials = apiKey ? { 'x-api-key': apiKey } : undefined;
36
+
37
+ // Initialize the gRPC-Web client
38
+ this.client = new ParallaxGatewayServiceClient(this.apiUrl, credentials);
30
39
  }
31
40
 
32
41
  /**
@@ -34,12 +43,9 @@ class ParallaxClient {
34
43
  * @param params Parameters to create a new trace
35
44
  * @returns Response from the create trace operation
36
45
  */
37
- async createTrace(params: CreateTraceRequest): Promise<apiGateway.CreateTraceResponse> {
46
+ async createTrace(params: CreateTraceRequest): Promise<CreateTraceResponse> {
38
47
  try {
39
- const apiGatewayClient = new apiGateway.ParallaxGatewayServiceClientImpl(
40
- this.apiGatewayRpc
41
- );
42
- return await apiGatewayClient.CreateTrace(params);
48
+ return await this.client.createTrace(params, null);
43
49
  } catch (_error) {
44
50
  debugIssue("createTrace", new Error('Error creating trace'));
45
51
  throw _error;
@@ -50,12 +56,9 @@ class ParallaxClient {
50
56
  * Start a new span within a trace
51
57
  * @param params Parameters to start a new span
52
58
  */
53
- async startSpan(params: StartSpanRequest) {
59
+ async startSpan(params: StartSpanRequest): Promise<StartSpanResponse> {
54
60
  try {
55
- const apiGatewayClient = new apiGateway.ParallaxGatewayServiceClientImpl(
56
- this.apiGatewayRpc
57
- );
58
- return await apiGatewayClient.StartSpan(params);
61
+ return await this.client.startSpan(params, null);
59
62
  } catch (_error) {
60
63
  debugIssue("startSpan", new Error('Error starting span'));
61
64
  throw _error;
@@ -66,44 +69,22 @@ class ParallaxClient {
66
69
  * Finish a span within a trace
67
70
  * @param params Parameters to finish a span
68
71
  */
69
- async finishSpan(params: FinishSpanRequest) {
72
+ async finishSpan(params: FinishSpanRequest): Promise<FinishSpanResponse> {
70
73
  try {
71
- const apiGatewayClient = new apiGateway.ParallaxGatewayServiceClientImpl(
72
- this.apiGatewayRpc
73
- );
74
- return await apiGatewayClient.FinishSpan(params);
74
+ return await this.client.finishSpan(params, null);
75
75
  } catch (_error) {
76
76
  debugIssue("finishSpan", new Error('Error finishing span'));
77
77
  throw _error;
78
78
  }
79
79
  }
80
80
 
81
- /**
82
- * Add attributes to a span
83
- * @param params Parameters to add attributes to a span
84
- */
85
- async addSpanAttributes(params: AddSpanAttributesRequest) {
86
- try {
87
- const apiGatewayClient = new apiGateway.ParallaxGatewayServiceClientImpl(
88
- this.apiGatewayRpc
89
- );
90
- return await apiGatewayClient.AddSpanAttributes(params);
91
- } catch (_error) {
92
- debugIssue("addSpanAttributes", new Error('Error adding span attributes'));
93
- throw _error;
94
- }
95
- }
96
-
97
81
  /**
98
82
  * Add an event to a span
99
83
  * @param params Parameters to add an event to a span
100
84
  */
101
- async addSpanEvent(params: AddSpanEventRequest) {
85
+ async addSpanEvent(params: AddSpanEventRequest): Promise<AddSpanEventResponse> {
102
86
  try {
103
- const apiGatewayClient = new apiGateway.ParallaxGatewayServiceClientImpl(
104
- this.apiGatewayRpc
105
- );
106
- return await apiGatewayClient.AddSpanEvent(params);
87
+ return await this.client.addSpanEvent(params, null);
107
88
  } catch (_error) {
108
89
  debugIssue("addSpanEvent", new Error('Error adding span event'));
109
90
  throw _error;
@@ -114,12 +95,9 @@ class ParallaxClient {
114
95
  * Add an error to a span
115
96
  * @param params Parameters to add an error to a span
116
97
  */
117
- async addSpanError(params: AddSpanErrorRequest) {
98
+ async addSpanError(params: AddSpanErrorRequest): Promise<AddSpanErrorResponse> {
118
99
  try {
119
- const apiGatewayClient = new apiGateway.ParallaxGatewayServiceClientImpl(
120
- this.apiGatewayRpc
121
- );
122
- return await apiGatewayClient.AddSpanError(params);
100
+ return await this.client.addSpanError(params, null);
123
101
  } catch (_error) {
124
102
  debugIssue("addSpanError", new Error('Error adding span error'));
125
103
  throw _error;
@@ -130,12 +108,9 @@ class ParallaxClient {
130
108
  * Add a hint to a span
131
109
  * @param params Parameters to add a hint to a span
132
110
  */
133
- async addSpanHint(params: AddSpanHintRequest) {
111
+ async addSpanHint(params: AddSpanHintRequest): Promise<AddSpanHintResponse> {
134
112
  try {
135
- const apiGatewayClient = new apiGateway.ParallaxGatewayServiceClientImpl(
136
- this.apiGatewayRpc
137
- );
138
- return await apiGatewayClient.AddSpanHint(params);
113
+ return await this.client.addSpanHint(params, null);
139
114
  } catch (_error) {
140
115
  debugIssue("addSpanHint", new Error('Error adding span hint'));
141
116
  throw _error;