@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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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
|
+
import { expect, test, vi } from 'vitest';
|
|
7
|
+
import { http, HttpResponse } from 'msw';
|
|
8
|
+
import { setupMSW } from './setup-msw';
|
|
9
|
+
import { DSPClient } from '../src/index';
|
|
10
|
+
import { mockTaggingPDPResponse } from './mocks/tagging-pdp-tag';
|
|
11
|
+
import { mockCreateExportArtifactsResponse } from './mocks/create-export-artifacts';
|
|
12
|
+
const platformUrl = 'https://dsp.example.com';
|
|
13
|
+
const handlers = [
|
|
14
|
+
http.post(`${platformUrl}/tagging.pdp.v2.TaggingPDPService/Tag`, () => {
|
|
15
|
+
return HttpResponse.json(mockTaggingPDPResponse());
|
|
16
|
+
}),
|
|
17
|
+
http.post(`${platformUrl}/policyimportexport.v1.PolicyArtifactService/CreateExportArtifacts`, () => {
|
|
18
|
+
return HttpResponse.json(mockCreateExportArtifactsResponse());
|
|
19
|
+
}),
|
|
20
|
+
];
|
|
21
|
+
setupMSW(handlers);
|
|
22
|
+
test('should create a new DSPClient instance with platformUrl', async () => {
|
|
23
|
+
const client = new DSPClient({ platformUrl });
|
|
24
|
+
expect(client).toBeInstanceOf(DSPClient);
|
|
25
|
+
});
|
|
26
|
+
test('should throw an error if platformUrl is not provided', async () => {
|
|
27
|
+
expect(() => new DSPClient({})).toThrowError('platformUrl is required for DSP client');
|
|
28
|
+
});
|
|
29
|
+
test('should perform RPC calls using the taggingPDPService', async () => {
|
|
30
|
+
const client = new DSPClient({ platformUrl });
|
|
31
|
+
expect(client).toBeInstanceOf(DSPClient);
|
|
32
|
+
const result = await client.v2.taggingPDPService.tag({});
|
|
33
|
+
expect(result.$typeName).toBe('tagging.pdp.v2.TaggingPDPResponse');
|
|
34
|
+
});
|
|
35
|
+
test('should perform RPC calls using the policyArtifactService', async () => {
|
|
36
|
+
const client = new DSPClient({ platformUrl });
|
|
37
|
+
expect(client).toBeInstanceOf(DSPClient);
|
|
38
|
+
const result = await client.v1.policyArtifactService.createExportArtifacts({});
|
|
39
|
+
expect(result.$typeName).toBe('policyimportexport.v1.CreateExportArtifactsResponse');
|
|
40
|
+
});
|
|
41
|
+
test('should use provided interceptors when making RPC calls', async () => {
|
|
42
|
+
const mockInterceptor = vi.fn((next) => next);
|
|
43
|
+
const client = new DSPClient({
|
|
44
|
+
platformUrl,
|
|
45
|
+
interceptors: [mockInterceptor],
|
|
46
|
+
});
|
|
47
|
+
await client.v2.taggingPDPService.tag({});
|
|
48
|
+
expect(mockInterceptor).toHaveBeenCalled();
|
|
49
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
import { expect, test, vi } from 'vitest';
|
|
7
|
+
import { http, HttpResponse } from 'msw';
|
|
8
|
+
import { setupMSW } from './setup-msw';
|
|
9
|
+
import { DSP } from '../src';
|
|
10
|
+
import { mockTaggingPDPResponse } from './mocks/tagging-pdp-tag';
|
|
11
|
+
import { HttpRequest, withHeaders } from '@opentdf/sdk';
|
|
12
|
+
import { mockWellKnownConfiguration } from './mocks/well-known-configuration';
|
|
13
|
+
const platformUrl = 'https://dsp.example.com';
|
|
14
|
+
const authProvider = {
|
|
15
|
+
updateClientPublicKey: async () => { },
|
|
16
|
+
withCreds: async (req) => withHeaders(req, {
|
|
17
|
+
Authorization: 'Bearer dummy auth token for testing purposes',
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
const handlers = [
|
|
21
|
+
http.post(`${platformUrl}/tagging.pdp.v2.TaggingPDPService/Tag`, () => {
|
|
22
|
+
return HttpResponse.json(mockTaggingPDPResponse());
|
|
23
|
+
}),
|
|
24
|
+
http.post(`${platformUrl}/wellknownconfiguration.WellKnownService/GetWellKnownConfiguration`, () => {
|
|
25
|
+
return HttpResponse.json(mockWellKnownConfiguration());
|
|
26
|
+
}),
|
|
27
|
+
];
|
|
28
|
+
setupMSW(handlers);
|
|
29
|
+
test('should create a new DSP instance with platformUrl', () => {
|
|
30
|
+
const dsp = new DSP({ platformUrl, authProvider });
|
|
31
|
+
expect(dsp).toBeInstanceOf(DSP);
|
|
32
|
+
});
|
|
33
|
+
test('should throw an error if platformUrl is not provided', () => {
|
|
34
|
+
expect(() => new DSP({})).toThrowError('Client ID or custom AuthProvider must be defined');
|
|
35
|
+
});
|
|
36
|
+
test('should create a new DSP instance with platformUrl and authProvider', () => {
|
|
37
|
+
const dsp = new DSP({ platformUrl, authProvider });
|
|
38
|
+
expect(dsp).toBeInstanceOf(DSP);
|
|
39
|
+
});
|
|
40
|
+
test('should perform RPC calls using the DSP client service', async () => {
|
|
41
|
+
const dsp = new DSP({ platformUrl, authProvider });
|
|
42
|
+
const result = await dsp.services.v2.taggingPDPService.tag({});
|
|
43
|
+
expect(result.$typeName).toBe('tagging.pdp.v2.TaggingPDPResponse');
|
|
44
|
+
});
|
|
45
|
+
test('should perform RPC calls via internal PlatformClient service', async () => {
|
|
46
|
+
const dsp = new DSP({ platformUrl, authProvider });
|
|
47
|
+
const result = await dsp.services.v1.wellknown.getWellKnownConfiguration({});
|
|
48
|
+
expect(result.$typeName).toBe('wellknownconfiguration.GetWellKnownConfigurationResponse');
|
|
49
|
+
});
|
|
50
|
+
test('should use provided interceptors when making RPC calls', async () => {
|
|
51
|
+
const mockInterceptor = vi.fn((next) => next);
|
|
52
|
+
const dsp = new DSP({
|
|
53
|
+
platformUrl,
|
|
54
|
+
authProvider,
|
|
55
|
+
interceptors: [mockInterceptor],
|
|
56
|
+
});
|
|
57
|
+
await dsp.services.v2.taggingPDPService.tag({});
|
|
58
|
+
expect(mockInterceptor).toHaveBeenCalled();
|
|
59
|
+
});
|
|
60
|
+
test('should expose expected service structure', () => {
|
|
61
|
+
const dsp = new DSP({ platformUrl, authProvider });
|
|
62
|
+
expect(dsp.services).toHaveProperty('v1');
|
|
63
|
+
expect(dsp.services.v2).toHaveProperty('taggingPDPService');
|
|
64
|
+
expect(dsp.services.v1).toHaveProperty('wellknown');
|
|
65
|
+
});
|
|
66
|
+
test('should throw if authProvider is missing', () => {
|
|
67
|
+
expect(() => new DSP({ platformUrl })).toThrowError('Client ID or custom AuthProvider must be defined');
|
|
68
|
+
});
|
|
69
|
+
test('should throw an error if platformUrl is not provided', async () => {
|
|
70
|
+
expect(() => new DSP({})).toThrowError();
|
|
71
|
+
});
|
|
@@ -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
|
+
import {} from '@src/gen/policyimportexport/v1/policy_import_export_pb';
|
|
7
|
+
export const mockCreateExportArtifactsResponse = () => ({
|
|
8
|
+
$typeName: 'policyimportexport.v1.CreateExportArtifactsResponse',
|
|
9
|
+
artifact: {
|
|
10
|
+
case: undefined,
|
|
11
|
+
value: undefined,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
import {} from '@src/gen/tagging/pdp/v2/tagging_pb';
|
|
7
|
+
export const mockTaggingPDPResponse = () => ({
|
|
8
|
+
$typeName: 'tagging.pdp.v2.TaggingPDPResponse',
|
|
9
|
+
events: [],
|
|
10
|
+
tags: [],
|
|
11
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
import {} from '@opentdf/sdk/platform/wellknownconfiguration/wellknown_configuration_pb.js';
|
|
7
|
+
export const mockWellKnownConfiguration = () => ({
|
|
8
|
+
$typeName: 'wellknownconfiguration.GetWellKnownConfigurationResponse',
|
|
9
|
+
configuration: {
|
|
10
|
+
wellKnown: {},
|
|
11
|
+
},
|
|
12
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type SetupWorker } from 'msw/browser';
|
|
2
|
+
import { HttpHandler } from 'msw';
|
|
3
|
+
/**
|
|
4
|
+
* Sets up the MSW (Mock Service Worker) for testing.
|
|
5
|
+
*
|
|
6
|
+
* @param handlers - An array of HTTP handlers to be used with MSW.
|
|
7
|
+
* @returns The MSW worker instance.
|
|
8
|
+
*/
|
|
9
|
+
export declare function setupMSW(handlers: HttpHandler[]): SetupWorker | undefined;
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
import { setupWorker } from 'msw/browser';
|
|
7
|
+
import { beforeAll, afterEach, afterAll } from 'vitest';
|
|
8
|
+
import { HttpHandler } from 'msw';
|
|
9
|
+
let worker;
|
|
10
|
+
/**
|
|
11
|
+
* Sets up the MSW (Mock Service Worker) for testing.
|
|
12
|
+
*
|
|
13
|
+
* @param handlers - An array of HTTP handlers to be used with MSW.
|
|
14
|
+
* @returns The MSW worker instance.
|
|
15
|
+
*/
|
|
16
|
+
export function setupMSW(handlers) {
|
|
17
|
+
if (!worker) {
|
|
18
|
+
worker = setupWorker(...handlers);
|
|
19
|
+
beforeAll(async () => {
|
|
20
|
+
await worker.start();
|
|
21
|
+
});
|
|
22
|
+
afterEach(() => worker.resetHandlers());
|
|
23
|
+
afterAll(() => worker.stop());
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
// If worker already exists, just update handlers
|
|
27
|
+
worker.resetHandlers(...handlers);
|
|
28
|
+
}
|
|
29
|
+
return worker;
|
|
30
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import js from '@eslint/js';
|
|
2
|
+
import globals from 'globals';
|
|
3
|
+
import tseslint from 'typescript-eslint';
|
|
4
|
+
import { defineConfig } from 'eslint/config';
|
|
5
|
+
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
|
|
6
|
+
|
|
7
|
+
export default defineConfig(
|
|
8
|
+
[
|
|
9
|
+
tseslint.configs.recommended,
|
|
10
|
+
eslintPluginPrettierRecommended,
|
|
11
|
+
{
|
|
12
|
+
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
|
|
13
|
+
plugins: { js, tseslint },
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
|
|
17
|
+
languageOptions: { globals: globals.browser },
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
{
|
|
21
|
+
ignores: ['dist/**'],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
linterOptions: {
|
|
25
|
+
reportUnusedDisableDirectives: 'off',
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
);
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@virtru/dsp-sdk",
|
|
3
|
+
"version": "0.1.10-pr604.7ef7a158",
|
|
4
|
+
"main": "dist/src/index.js",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"import": "./dist/src/index.js",
|
|
8
|
+
"require": "./dist-commonjs/src/index.js",
|
|
9
|
+
"types": "./dist/src/index.d.ts"
|
|
10
|
+
},
|
|
11
|
+
"./platform/*": {
|
|
12
|
+
"import": "./dist/src/gen/*.js",
|
|
13
|
+
"require": "./dist-commonjs/src/gen/*.js",
|
|
14
|
+
"types": "./dist/src/gen/*.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18.0.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^20.4.5",
|
|
22
|
+
"@vitest/browser": "^3.1.4",
|
|
23
|
+
"globals": "^16.3.0",
|
|
24
|
+
"jsdom": "^22.1.0",
|
|
25
|
+
"msw": "^2.8.4",
|
|
26
|
+
"playwright": "^1.52.0",
|
|
27
|
+
"vite": "^4.5.14",
|
|
28
|
+
"vite-plugin-dts": "^4.5.4",
|
|
29
|
+
"vitest": "~3.1.3",
|
|
30
|
+
"typescript": "^5.4.2"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@bufbuild/protobuf": "^2.7.0",
|
|
34
|
+
"@connectrpc/connect": "~2.0.2",
|
|
35
|
+
"@connectrpc/connect-web": "~2.0.2",
|
|
36
|
+
"@opentdf/sdk": "0.5.0-rc.44",
|
|
37
|
+
"@rushstack/heft": "^0.50.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "heft build --clean",
|
|
41
|
+
"lint": "eslint .",
|
|
42
|
+
"lint:fix": "eslint . --fix",
|
|
43
|
+
"test": "npx vitest --run --browser",
|
|
44
|
+
"test:ui": "npx vitest --browser.headless=false",
|
|
45
|
+
"_phase:build": "heft build --clean"
|
|
46
|
+
}
|
|
47
|
+
}
|