@virtru/dsp-sdk 0.1.10-pr604.7ef7a158
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/.prettierrc +3 -0
- package/.rush/temp/operation/_phase_build/state.json +3 -0
- package/.rush/temp/package-deps__phase_build.json +41 -0
- package/.rush/temp/shrinkwrap-deps.json +329 -0
- package/CHANGELOG.json +103 -0
- package/CHANGELOG.md +53 -0
- package/README.md +98 -0
- package/dist/src/gen/buf/validate/validate_pb.d.ts +4517 -0
- package/dist/src/gen/buf/validate/validate_pb.js +484 -0
- package/dist/src/gen/config/v1/config_pb.d.ts +88 -0
- package/dist/src/gen/config/v1/config_pb.js +46 -0
- package/dist/src/gen/config/v1/meta_pb.d.ts +37 -0
- package/dist/src/gen/config/v1/meta_pb.js +33 -0
- package/dist/src/gen/config/v1/tagging_pb.d.ts +264 -0
- package/dist/src/gen/config/v1/tagging_pb.js +188 -0
- package/dist/src/gen/google/api/annotations_pb.d.ts +13 -0
- package/dist/src/gen/google/api/annotations_pb.js +30 -0
- package/dist/src/gen/google/api/http_pb.d.ts +440 -0
- package/dist/src/gen/google/api/http_pb.js +41 -0
- package/dist/src/gen/policyimportexport/v1/policy_import_export_pb.d.ts +241 -0
- package/dist/src/gen/policyimportexport/v1/policy_import_export_pb.js +89 -0
- package/dist/src/gen/shared/v1/shared_pb.d.ts +172 -0
- package/dist/src/gen/shared/v1/shared_pb.js +92 -0
- package/dist/src/gen/tagging/pdp/v2/tagging_pb.d.ts +872 -0
- package/dist/src/gen/tagging/pdp/v2/tagging_pb.js +274 -0
- package/dist/src/gen/version/v1/version_pb.d.ts +96 -0
- package/dist/src/gen/version/v1/version_pb.js +37 -0
- package/dist/src/index.d.ts +21 -0
- package/dist/src/index.js +28 -0
- package/dist/src/lib/client.d.ts +33 -0
- package/dist/src/lib/client.js +60 -0
- package/dist/src/lib/dsp.d.ts +18 -0
- package/dist/src/lib/dsp.js +44 -0
- package/dist/src/lib/utils.d.ts +15 -0
- package/dist/src/lib/utils.js +35 -0
- package/dist/tests/dsp-client.test.d.ts +1 -0
- package/dist/tests/dsp-client.test.js +49 -0
- package/dist/tests/dsp.test.d.ts +1 -0
- package/dist/tests/dsp.test.js +71 -0
- package/dist/tests/mocks/create-export-artifacts.d.ts +2 -0
- package/dist/tests/mocks/create-export-artifacts.js +13 -0
- package/dist/tests/mocks/tagging-pdp-tag.d.ts +2 -0
- package/dist/tests/mocks/tagging-pdp-tag.js +11 -0
- package/dist/tests/mocks/well-known-configuration.d.ts +2 -0
- package/dist/tests/mocks/well-known-configuration.js +12 -0
- package/dist/tests/setup-msw.d.ts +9 -0
- package/dist/tests/setup-msw.js +30 -0
- package/eslint.config.mjs +28 -0
- package/package.json +47 -0
- package/src/gen/buf/validate/validate_pb.ts +4879 -0
- package/src/gen/config/formatters/testdata/v1/test_pb.ts +287 -0
- package/src/gen/config/v1/config_pb.ts +137 -0
- package/src/gen/config/v1/meta_pb.ts +72 -0
- package/src/gen/config/v1/tagging_pb.ts +355 -0
- package/src/gen/google/api/annotations_pb.ts +43 -0
- package/src/gen/google/api/http_pb.ts +486 -0
- package/src/gen/helloworld/v1/helloworld_pb.ts +98 -0
- package/src/gen/policyimportexport/v1/policy_import_export_pb.ts +324 -0
- package/src/gen/shared/v1/shared_pb.ts +240 -0
- package/src/gen/shared/v2/shared_pb.ts +122 -0
- package/src/gen/tagging/pdp/v2/externalprocessors/processor_pb.ts +709 -0
- package/src/gen/tagging/pdp/v2/stanag/stanag_pb.ts +953 -0
- package/src/gen/tagging/pdp/v2/tagging_pb.ts +1064 -0
- package/src/gen/version/v1/version_pb.ts +143 -0
- package/src/index.ts +49 -0
- package/src/lib/client.ts +83 -0
- package/src/lib/dsp.ts +65 -0
- package/src/lib/utils.ts +43 -0
- package/src/vite-env.d.ts +7 -0
- package/tests/dsp-client.test.ts +67 -0
- package/tests/dsp.test.ts +95 -0
- package/tests/mocks/create-export-artifacts.ts +16 -0
- package/tests/mocks/tagging-pdp-tag.ts +13 -0
- package/tests/mocks/well-known-configuration.ts +15 -0
- package/tests/setup-msw.ts +35 -0
- package/tsconfig.json +32 -0
- package/vitest.config.ts +42 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Virtru Corporation. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// @generated by protoc-gen-es v2.3.0 with parameter "target=ts"
|
|
8
|
+
// @generated from file version/v1/version.proto (package version.v1, syntax proto3)
|
|
9
|
+
/* eslint-disable */
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
GenFile,
|
|
13
|
+
GenMessage,
|
|
14
|
+
GenService,
|
|
15
|
+
} from '@bufbuild/protobuf/codegenv1';
|
|
16
|
+
import {
|
|
17
|
+
fileDesc,
|
|
18
|
+
messageDesc,
|
|
19
|
+
serviceDesc,
|
|
20
|
+
} from '@bufbuild/protobuf/codegenv1';
|
|
21
|
+
import type { Message } from '@bufbuild/protobuf';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Describes the file version/v1/version.proto.
|
|
25
|
+
*/
|
|
26
|
+
export const file_version_v1_version: GenFile =
|
|
27
|
+
/*@__PURE__*/
|
|
28
|
+
fileDesc(
|
|
29
|
+
'Chh2ZXJzaW9uL3YxL3ZlcnNpb24ucHJvdG8SCnZlcnNpb24udjEiEwoRR2V0VmVyc2lvblJlcXVlc3QiLwoORGVwZW5kZW5jeUluZm8SDAoEbmFtZRgBIAEoCRIPCgd2ZXJzaW9uGAIgASgJIu8CChJHZXRWZXJzaW9uUmVzcG9uc2USDAoEbmFtZRgBIAEoCRIPCgd2ZXJzaW9uGAIgASgJEhIKCmdpdF9jb21taXQYAyABKAkSEgoKYnVpbGRfZGF0ZRgEIAEoCRISCgpnb192ZXJzaW9uGAUgASgJEg8KB29zX2FyY2gYBiABKAkSOwoXb3BlbnRkZl9zZXJ2aWNlX3ZlcnNpb24YByABKAsyGi52ZXJzaW9uLnYxLkRlcGVuZGVuY3lJbmZvEjcKE29wZW50ZGZfc2RrX3ZlcnNpb24YCCABKAsyGi52ZXJzaW9uLnYxLkRlcGVuZGVuY3lJbmZvEjwKGG9wZW50ZGZfcHJvdG9idWZfdmVyc2lvbhgJIAEoCzIaLnZlcnNpb24udjEuRGVwZW5kZW5jeUluZm8SOQoVb3BlbnRkZl9saWJzX3ZlcnNpb25zGAogAygLMhoudmVyc2lvbi52MS5EZXBlbmRlbmN5SW5mbzJdCg5WZXJzaW9uU2VydmljZRJLCgpHZXRWZXJzaW9uEh0udmVyc2lvbi52MS5HZXRWZXJzaW9uUmVxdWVzdBoeLnZlcnNpb24udjEuR2V0VmVyc2lvblJlc3BvbnNlQrYBCg5jb20udmVyc2lvbi52MUIMVmVyc2lvblByb3RvUAFaTWdpdGh1Yi5jb20vdmlydHJ1LWNvcnAvZGF0YS1zZWN1cml0eS1wbGF0Zm9ybS9zZGsvdjIvZ2VuL3ZlcnNpb24vdjE7dmVyc2lvbnYxogIDVlhYqgIKVmVyc2lvbi5WMcoCClZlcnNpb25cVjHiAhZWZXJzaW9uXFYxXEdQQk1ldGFkYXRh6gILVmVyc2lvbjo6VjFiBnByb3RvMw'
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @generated from message version.v1.GetVersionRequest
|
|
34
|
+
*/
|
|
35
|
+
export type GetVersionRequest = Message<'version.v1.GetVersionRequest'> & {};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Describes the message version.v1.GetVersionRequest.
|
|
39
|
+
* Use `create(GetVersionRequestSchema)` to create a new message.
|
|
40
|
+
*/
|
|
41
|
+
export const GetVersionRequestSchema: GenMessage<GetVersionRequest> =
|
|
42
|
+
/*@__PURE__*/
|
|
43
|
+
messageDesc(file_version_v1_version, 0);
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @generated from message version.v1.DependencyInfo
|
|
47
|
+
*/
|
|
48
|
+
export type DependencyInfo = Message<'version.v1.DependencyInfo'> & {
|
|
49
|
+
/**
|
|
50
|
+
* @generated from field: string name = 1;
|
|
51
|
+
*/
|
|
52
|
+
name: string;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @generated from field: string version = 2;
|
|
56
|
+
*/
|
|
57
|
+
version: string;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Describes the message version.v1.DependencyInfo.
|
|
62
|
+
* Use `create(DependencyInfoSchema)` to create a new message.
|
|
63
|
+
*/
|
|
64
|
+
export const DependencyInfoSchema: GenMessage<DependencyInfo> =
|
|
65
|
+
/*@__PURE__*/
|
|
66
|
+
messageDesc(file_version_v1_version, 1);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @generated from message version.v1.GetVersionResponse
|
|
70
|
+
*/
|
|
71
|
+
export type GetVersionResponse = Message<'version.v1.GetVersionResponse'> & {
|
|
72
|
+
/**
|
|
73
|
+
* @generated from field: string name = 1;
|
|
74
|
+
*/
|
|
75
|
+
name: string;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @generated from field: string version = 2;
|
|
79
|
+
*/
|
|
80
|
+
version: string;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @generated from field: string git_commit = 3;
|
|
84
|
+
*/
|
|
85
|
+
gitCommit: string;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @generated from field: string build_date = 4;
|
|
89
|
+
*/
|
|
90
|
+
buildDate: string;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @generated from field: string go_version = 5;
|
|
94
|
+
*/
|
|
95
|
+
goVersion: string;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @generated from field: string os_arch = 6;
|
|
99
|
+
*/
|
|
100
|
+
osArch: string;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @generated from field: version.v1.DependencyInfo opentdf_service_version = 7;
|
|
104
|
+
*/
|
|
105
|
+
opentdfServiceVersion?: DependencyInfo;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @generated from field: version.v1.DependencyInfo opentdf_sdk_version = 8;
|
|
109
|
+
*/
|
|
110
|
+
opentdfSdkVersion?: DependencyInfo;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @generated from field: version.v1.DependencyInfo opentdf_protobuf_version = 9;
|
|
114
|
+
*/
|
|
115
|
+
opentdfProtobufVersion?: DependencyInfo;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @generated from field: repeated version.v1.DependencyInfo opentdf_libs_versions = 10;
|
|
119
|
+
*/
|
|
120
|
+
opentdfLibsVersions: DependencyInfo[];
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Describes the message version.v1.GetVersionResponse.
|
|
125
|
+
* Use `create(GetVersionResponseSchema)` to create a new message.
|
|
126
|
+
*/
|
|
127
|
+
export const GetVersionResponseSchema: GenMessage<GetVersionResponse> =
|
|
128
|
+
/*@__PURE__*/
|
|
129
|
+
messageDesc(file_version_v1_version, 2);
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @generated from service version.v1.VersionService
|
|
133
|
+
*/
|
|
134
|
+
export const VersionService: GenService<{
|
|
135
|
+
/**
|
|
136
|
+
* @generated from rpc version.v1.VersionService.GetVersion
|
|
137
|
+
*/
|
|
138
|
+
getVersion: {
|
|
139
|
+
methodKind: 'unary';
|
|
140
|
+
input: typeof GetVersionRequestSchema;
|
|
141
|
+
output: typeof GetVersionResponseSchema;
|
|
142
|
+
};
|
|
143
|
+
}> = /*@__PURE__*/ serviceDesc(file_version_v1_version, 0);
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Virtru Corporation. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Exports Connect RPC and Connect Web RPC
|
|
9
|
+
*/
|
|
10
|
+
export {
|
|
11
|
+
platformConnect as dspConnect,
|
|
12
|
+
platformConnectWeb as dspConnectWeb,
|
|
13
|
+
} from '@opentdf/sdk/platform';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Exports the platform client
|
|
17
|
+
*/
|
|
18
|
+
export {
|
|
19
|
+
type DSPClientServicesV1 as DSPServicesV1,
|
|
20
|
+
type DSPClientServicesV2 as DSPServicesV2,
|
|
21
|
+
type DSPClientOptions,
|
|
22
|
+
DSPClient,
|
|
23
|
+
} from './lib/client';
|
|
24
|
+
export { PlatformClient } from '@opentdf/sdk/platform';
|
|
25
|
+
export { createAuthInterceptor, type Interceptor } from './lib/utils';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Exports the DSP wrapper of OpenTDF
|
|
29
|
+
*/
|
|
30
|
+
export { DSP, createDSP } from './lib/dsp';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Exports components of OpenTDF
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
version,
|
|
38
|
+
clientType,
|
|
39
|
+
tdfSpecVersion,
|
|
40
|
+
type DecoratedStream,
|
|
41
|
+
type CreateZTDFOptions,
|
|
42
|
+
} from '@opentdf/sdk';
|
|
43
|
+
|
|
44
|
+
// export AuthProvider during transition period
|
|
45
|
+
// TODO: remove this export once the SDK is updated to deprecate the AuthProvider
|
|
46
|
+
export { AuthProviders, type AuthProvider } from '@opentdf/sdk';
|
|
47
|
+
|
|
48
|
+
export * as singlecontainer from '@opentdf/sdk/singlecontainer';
|
|
49
|
+
export * as nano from '@opentdf/sdk/nano';
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Virtru Corporation. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// export client service definitions
|
|
8
|
+
|
|
9
|
+
// export Connect RPC framework
|
|
10
|
+
import type { AuthProvider } from '@opentdf/sdk';
|
|
11
|
+
import { type Client, createClient, type Interceptor } from '@connectrpc/connect';
|
|
12
|
+
import { createConnectTransport } from '@connectrpc/connect-web';
|
|
13
|
+
import { ConfigService } from '../gen/config/v1/config_pb';
|
|
14
|
+
import { PolicyArtifactService } from '../gen/policyimportexport/v1/policy_import_export_pb';
|
|
15
|
+
import { SharedService } from '../gen/shared/v1/shared_pb';
|
|
16
|
+
import { TaggingPDPService } from '../gen/tagging/pdp/v2/tagging_pb';
|
|
17
|
+
import { VersionService } from '../gen/version/v1/version_pb';
|
|
18
|
+
import { createAuthInterceptor } from './utils';
|
|
19
|
+
|
|
20
|
+
export interface DSPClientServicesV1 {
|
|
21
|
+
configService: Client<typeof ConfigService>;
|
|
22
|
+
policyArtifactService: Client<typeof PolicyArtifactService>;
|
|
23
|
+
sharedService: Client<typeof SharedService>;
|
|
24
|
+
versionService: Client<typeof VersionService>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface DSPClientServicesV2 {
|
|
28
|
+
taggingPDPService: Client<typeof TaggingPDPService>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface DSPClientOptions {
|
|
32
|
+
// Base URL of the DSP
|
|
33
|
+
platformUrl: string;
|
|
34
|
+
// List of interceptors to apply to rpc requests
|
|
35
|
+
interceptors?: Interceptor[];
|
|
36
|
+
// Auth provider for request signing
|
|
37
|
+
authProvider?: AuthProvider;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A client for interacting with the DSP using the Connect RPC framework.
|
|
42
|
+
*
|
|
43
|
+
* This client supports custom interceptors, which can be used to add
|
|
44
|
+
* authentication headers or other custom logic to outgoing requests.
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
export class DSPClient {
|
|
48
|
+
readonly v1: DSPClientServicesV1;
|
|
49
|
+
readonly v2: DSPClientServicesV2;
|
|
50
|
+
|
|
51
|
+
constructor(options: DSPClientOptions) {
|
|
52
|
+
const interceptors: Interceptor[] = [];
|
|
53
|
+
|
|
54
|
+
if (!options.platformUrl) {
|
|
55
|
+
throw new Error('platformUrl is required for DSP client');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (options.authProvider) {
|
|
59
|
+
const authInterceptor = createAuthInterceptor(options.authProvider);
|
|
60
|
+
interceptors.push(authInterceptor);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (options.interceptors?.length) {
|
|
64
|
+
interceptors.push(...options.interceptors);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const transport = createConnectTransport({
|
|
68
|
+
baseUrl: options.platformUrl,
|
|
69
|
+
interceptors,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
this.v1 = {
|
|
73
|
+
configService: createClient(ConfigService, transport),
|
|
74
|
+
policyArtifactService: createClient(PolicyArtifactService, transport),
|
|
75
|
+
sharedService: createClient(SharedService, transport),
|
|
76
|
+
versionService: createClient(VersionService, transport),
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
this.v2 = {
|
|
80
|
+
taggingPDPService: createClient(TaggingPDPService, transport),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
package/src/lib/dsp.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Virtru Corporation. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { OpenTDF, type OpenTDFOptions } from '@opentdf/sdk';
|
|
8
|
+
import { PlatformClient, type PlatformServices } from '@opentdf/sdk/platform';
|
|
9
|
+
import {
|
|
10
|
+
DSPClient,
|
|
11
|
+
type DSPClientServicesV1,
|
|
12
|
+
type DSPClientServicesV2,
|
|
13
|
+
} from './client';
|
|
14
|
+
import type { Interceptor } from '@connectrpc/connect';
|
|
15
|
+
|
|
16
|
+
export type DSPServicesV1 = DSPClientServicesV1 & PlatformServices;
|
|
17
|
+
export type DSPServicesV2 = DSPClientServicesV2;
|
|
18
|
+
|
|
19
|
+
export interface DSPOptions extends OpenTDFOptions {
|
|
20
|
+
// This is the URL of the DSP server that the client will connect to.
|
|
21
|
+
// PlatformUrl is required for DSP client
|
|
22
|
+
platformUrl: string;
|
|
23
|
+
// List interceptors to apply to rpc requests
|
|
24
|
+
interceptors?: Interceptor[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class DSP extends OpenTDF {
|
|
28
|
+
readonly services: {
|
|
29
|
+
v1: DSPServicesV1;
|
|
30
|
+
v2: DSPServicesV2;
|
|
31
|
+
};
|
|
32
|
+
constructor(options: DSPOptions) {
|
|
33
|
+
super(options);
|
|
34
|
+
|
|
35
|
+
if (!options.platformUrl) {
|
|
36
|
+
throw new Error('platformUrl is required for DSP client');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const dspClient = new DSPClient({
|
|
40
|
+
platformUrl: options.platformUrl,
|
|
41
|
+
interceptors: options.interceptors,
|
|
42
|
+
authProvider: options.authProvider,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const platformClient = new PlatformClient({
|
|
46
|
+
platformUrl: options.platformUrl,
|
|
47
|
+
interceptors: options.interceptors,
|
|
48
|
+
authProvider: options.authProvider,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
this.services = {
|
|
52
|
+
v1: {
|
|
53
|
+
...platformClient.v1,
|
|
54
|
+
...dspClient.v1,
|
|
55
|
+
},
|
|
56
|
+
v2: {
|
|
57
|
+
...dspClient.v2,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function createDSP(options: DSPOptions): DSP {
|
|
64
|
+
return new DSP(options);
|
|
65
|
+
}
|
package/src/lib/utils.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Virtru Corporation. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { AuthProvider } from '@opentdf/sdk';
|
|
8
|
+
import type { Interceptor as Inter } from '@connectrpc/connect';
|
|
9
|
+
export type Interceptor = Inter;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates an interceptor that adds authentication headers to outgoing requests.
|
|
13
|
+
*
|
|
14
|
+
* This function uses the provided `AuthProvider` to generate authentication credentials
|
|
15
|
+
* for each request. The `AuthProvider` is expected to implement a `withCreds` method
|
|
16
|
+
* that returns an object containing authentication headers. These headers are then
|
|
17
|
+
* added to the request before it is sent to the server.
|
|
18
|
+
*
|
|
19
|
+
* @param authProvider - An instance of `AuthProvider` used to generate authentication credentials.
|
|
20
|
+
* @returns An `Interceptor` function that modifies requests to include authentication headers.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export function createAuthInterceptor(authProvider: AuthProvider): Interceptor {
|
|
24
|
+
const authInterceptor: Interceptor = (next) => async (req) => {
|
|
25
|
+
const url = new URL(req.url);
|
|
26
|
+
const pathOnly = url.pathname;
|
|
27
|
+
// Signs only the path of the url in the request
|
|
28
|
+
const token = await authProvider.withCreds({
|
|
29
|
+
url: pathOnly,
|
|
30
|
+
method: 'POST',
|
|
31
|
+
headers: {
|
|
32
|
+
'Content-Type': 'application/json',
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
Object.entries(token.headers).forEach(([key, value]) => {
|
|
37
|
+
req.header.set(key, value);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return await next(req);
|
|
41
|
+
};
|
|
42
|
+
return authInterceptor;
|
|
43
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Virtru Corporation. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { expect, test, vi } from 'vitest';
|
|
8
|
+
import { http, HttpResponse } from 'msw';
|
|
9
|
+
import { setupMSW } from './setup-msw';
|
|
10
|
+
import { DSPClient } from '../src/index';
|
|
11
|
+
import { mockTaggingPDPResponse } from './mocks/tagging-pdp-tag';
|
|
12
|
+
import { mockCreateExportArtifactsResponse } from './mocks/create-export-artifacts';
|
|
13
|
+
|
|
14
|
+
const platformUrl = 'https://dsp.example.com';
|
|
15
|
+
|
|
16
|
+
const handlers = [
|
|
17
|
+
http.post(`${platformUrl}/tagging.pdp.v2.TaggingPDPService/Tag`, () => {
|
|
18
|
+
return HttpResponse.json(mockTaggingPDPResponse());
|
|
19
|
+
}),
|
|
20
|
+
http.post(
|
|
21
|
+
`${platformUrl}/policyimportexport.v1.PolicyArtifactService/CreateExportArtifacts`,
|
|
22
|
+
() => {
|
|
23
|
+
return HttpResponse.json(mockCreateExportArtifactsResponse());
|
|
24
|
+
}
|
|
25
|
+
),
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
setupMSW(handlers);
|
|
29
|
+
|
|
30
|
+
test('should create a new DSPClient instance with platformUrl', async () => {
|
|
31
|
+
const client = new DSPClient({ platformUrl });
|
|
32
|
+
expect(client).toBeInstanceOf(DSPClient);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('should throw an error if platformUrl is not provided', async () => {
|
|
36
|
+
expect(() => new DSPClient({} as never)).toThrowError(
|
|
37
|
+
'platformUrl is required for DSP client'
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('should perform RPC calls using the taggingPDPService', async () => {
|
|
42
|
+
const client = new DSPClient({ platformUrl });
|
|
43
|
+
expect(client).toBeInstanceOf(DSPClient);
|
|
44
|
+
const result = await client.v2.taggingPDPService.tag({});
|
|
45
|
+
expect(result.$typeName).toBe('tagging.pdp.v2.TaggingPDPResponse');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('should perform RPC calls using the policyArtifactService', async () => {
|
|
49
|
+
const client = new DSPClient({ platformUrl });
|
|
50
|
+
expect(client).toBeInstanceOf(DSPClient);
|
|
51
|
+
const result = await client.v1.policyArtifactService.createExportArtifacts(
|
|
52
|
+
{}
|
|
53
|
+
);
|
|
54
|
+
expect(result.$typeName).toBe(
|
|
55
|
+
'policyimportexport.v1.CreateExportArtifactsResponse'
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('should use provided interceptors when making RPC calls', async () => {
|
|
60
|
+
const mockInterceptor = vi.fn((next) => next);
|
|
61
|
+
const client = new DSPClient({
|
|
62
|
+
platformUrl,
|
|
63
|
+
interceptors: [mockInterceptor],
|
|
64
|
+
});
|
|
65
|
+
await client.v2.taggingPDPService.tag({});
|
|
66
|
+
expect(mockInterceptor).toHaveBeenCalled();
|
|
67
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Virtru Corporation. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { expect, test, vi } from 'vitest';
|
|
8
|
+
import { http, HttpResponse } from 'msw';
|
|
9
|
+
import { setupMSW } from './setup-msw';
|
|
10
|
+
import { DSP } from '../src';
|
|
11
|
+
import { mockTaggingPDPResponse } from './mocks/tagging-pdp-tag';
|
|
12
|
+
import { type AuthProvider, HttpRequest, withHeaders } from '@opentdf/sdk';
|
|
13
|
+
import { mockWellKnownConfiguration } from './mocks/well-known-configuration';
|
|
14
|
+
|
|
15
|
+
const platformUrl = 'https://dsp.example.com';
|
|
16
|
+
|
|
17
|
+
const authProvider = <AuthProvider>{
|
|
18
|
+
updateClientPublicKey: async () => {},
|
|
19
|
+
withCreds: async (req: HttpRequest): Promise<HttpRequest> =>
|
|
20
|
+
withHeaders(req, {
|
|
21
|
+
Authorization: 'Bearer dummy auth token for testing purposes',
|
|
22
|
+
}),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const handlers = [
|
|
26
|
+
http.post(`${platformUrl}/tagging.pdp.v2.TaggingPDPService/Tag`, () => {
|
|
27
|
+
return HttpResponse.json(mockTaggingPDPResponse());
|
|
28
|
+
}),
|
|
29
|
+
http.post(
|
|
30
|
+
`${platformUrl}/wellknownconfiguration.WellKnownService/GetWellKnownConfiguration`,
|
|
31
|
+
() => {
|
|
32
|
+
return HttpResponse.json(mockWellKnownConfiguration());
|
|
33
|
+
}
|
|
34
|
+
),
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
setupMSW(handlers);
|
|
38
|
+
|
|
39
|
+
test('should create a new DSP instance with platformUrl', () => {
|
|
40
|
+
const dsp = new DSP({ platformUrl, authProvider });
|
|
41
|
+
expect(dsp).toBeInstanceOf(DSP);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('should throw an error if platformUrl is not provided', () => {
|
|
45
|
+
expect(() => new DSP({} as never)).toThrowError(
|
|
46
|
+
'Client ID or custom AuthProvider must be defined'
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('should create a new DSP instance with platformUrl and authProvider', () => {
|
|
51
|
+
const dsp = new DSP({ platformUrl, authProvider });
|
|
52
|
+
expect(dsp).toBeInstanceOf(DSP);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('should perform RPC calls using the DSP client service', async () => {
|
|
56
|
+
const dsp = new DSP({ platformUrl, authProvider });
|
|
57
|
+
const result = await dsp.services.v2.taggingPDPService.tag({});
|
|
58
|
+
expect(result.$typeName).toBe('tagging.pdp.v2.TaggingPDPResponse');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('should perform RPC calls via internal PlatformClient service', async () => {
|
|
62
|
+
const dsp = new DSP({ platformUrl, authProvider });
|
|
63
|
+
const result = await dsp.services.v1.wellknown.getWellKnownConfiguration({});
|
|
64
|
+
expect(result.$typeName).toBe(
|
|
65
|
+
'wellknownconfiguration.GetWellKnownConfigurationResponse'
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('should use provided interceptors when making RPC calls', async () => {
|
|
70
|
+
const mockInterceptor = vi.fn((next) => next);
|
|
71
|
+
const dsp = new DSP({
|
|
72
|
+
platformUrl,
|
|
73
|
+
authProvider,
|
|
74
|
+
interceptors: [mockInterceptor],
|
|
75
|
+
});
|
|
76
|
+
await dsp.services.v2.taggingPDPService.tag({});
|
|
77
|
+
expect(mockInterceptor).toHaveBeenCalled();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('should expose expected service structure', () => {
|
|
81
|
+
const dsp = new DSP({ platformUrl, authProvider });
|
|
82
|
+
expect(dsp.services).toHaveProperty('v1');
|
|
83
|
+
expect(dsp.services.v2).toHaveProperty('taggingPDPService');
|
|
84
|
+
expect(dsp.services.v1).toHaveProperty('wellknown');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('should throw if authProvider is missing', () => {
|
|
88
|
+
expect(() => new DSP({ platformUrl } as never)).toThrowError(
|
|
89
|
+
'Client ID or custom AuthProvider must be defined'
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('should throw an error if platformUrl is not provided', async () => {
|
|
94
|
+
expect(() => new DSP({} as never)).toThrowError();
|
|
95
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Virtru Corporation. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { type CreateExportArtifactsResponse } from '@src/gen/policyimportexport/v1/policy_import_export_pb';
|
|
8
|
+
|
|
9
|
+
export const mockCreateExportArtifactsResponse =
|
|
10
|
+
(): CreateExportArtifactsResponse => ({
|
|
11
|
+
$typeName: 'policyimportexport.v1.CreateExportArtifactsResponse',
|
|
12
|
+
artifact: {
|
|
13
|
+
case: undefined,
|
|
14
|
+
value: undefined,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Virtru Corporation. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { type TaggingPDPResponse } from '@src/gen/tagging/pdp/v2/tagging_pb';
|
|
8
|
+
|
|
9
|
+
export const mockTaggingPDPResponse = (): TaggingPDPResponse => ({
|
|
10
|
+
$typeName: 'tagging.pdp.v2.TaggingPDPResponse',
|
|
11
|
+
events: [],
|
|
12
|
+
tags: [],
|
|
13
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Virtru Corporation. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { type GetWellKnownConfigurationResponse } from '@opentdf/sdk/platform/wellknownconfiguration/wellknown_configuration_pb.js';
|
|
8
|
+
|
|
9
|
+
export const mockWellKnownConfiguration =
|
|
10
|
+
(): GetWellKnownConfigurationResponse => ({
|
|
11
|
+
$typeName: 'wellknownconfiguration.GetWellKnownConfigurationResponse',
|
|
12
|
+
configuration: {
|
|
13
|
+
wellKnown: {},
|
|
14
|
+
},
|
|
15
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Virtru Corporation. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { type SetupWorker, setupWorker } from 'msw/browser';
|
|
8
|
+
import { beforeAll, afterEach, afterAll } from 'vitest';
|
|
9
|
+
import { HttpHandler } from 'msw';
|
|
10
|
+
|
|
11
|
+
let worker: SetupWorker | undefined;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Sets up the MSW (Mock Service Worker) for testing.
|
|
15
|
+
*
|
|
16
|
+
* @param handlers - An array of HTTP handlers to be used with MSW.
|
|
17
|
+
* @returns The MSW worker instance.
|
|
18
|
+
*/
|
|
19
|
+
export function setupMSW(handlers: HttpHandler[]): SetupWorker | undefined {
|
|
20
|
+
if (!worker) {
|
|
21
|
+
worker = setupWorker(...handlers);
|
|
22
|
+
|
|
23
|
+
beforeAll(async () => {
|
|
24
|
+
await worker!.start();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterEach(() => worker!.resetHandlers());
|
|
28
|
+
afterAll(() => worker!.stop());
|
|
29
|
+
} else {
|
|
30
|
+
// If worker already exists, just update handlers
|
|
31
|
+
worker.resetHandlers(...handlers);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return worker;
|
|
35
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"baseUrl": ".",
|
|
9
|
+
"paths": {
|
|
10
|
+
"@src/*": ["src/*"]
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
/* Bundler mode */
|
|
14
|
+
"moduleResolution": "bundler",
|
|
15
|
+
"allowImportingTsExtensions": false,
|
|
16
|
+
"verbatimModuleSyntax": true,
|
|
17
|
+
"moduleDetection": "force",
|
|
18
|
+
"noEmit": false,
|
|
19
|
+
"declaration": true,
|
|
20
|
+
"outDir": "dist",
|
|
21
|
+
"emitDeclarationOnly": false,
|
|
22
|
+
|
|
23
|
+
/* Linting */
|
|
24
|
+
"strict": true,
|
|
25
|
+
"noUnusedLocals": true,
|
|
26
|
+
"noUnusedParameters": true,
|
|
27
|
+
// "erasableSyntaxOnly": false,
|
|
28
|
+
"noFallthroughCasesInSwitch": true
|
|
29
|
+
// "noUncheckedSideEffectImports": true
|
|
30
|
+
},
|
|
31
|
+
"include": ["tests"]
|
|
32
|
+
}
|