@mindline/sync 1.0.8 → 1.0.10
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/README.md +0 -25
- package/index.js +60 -78
- package/index.test.js +6 -6
- package/package.json +4 -9
- package/sync.d.ts +51 -12
- package/vitest.config.ts +7 -0
- package/babel.config.json +0 -3
package/README.md
CHANGED
|
@@ -5,31 +5,6 @@ TODO: Guide users through getting your code up and running on their own system.
|
|
|
5
5
|
# 1. Installation process
|
|
6
6
|
## install Node
|
|
7
7
|
https://nodejs.org/en/download
|
|
8
|
-
## Enable jest for ES6 to enable Jest operation on my codebase
|
|
9
|
-
See this article
|
|
10
|
-
https://stackoverflow.com/questions/59879689/jest-syntaxerror-cannot-use-import-statement-outside-a-module
|
|
11
|
-
### install babel-jest
|
|
12
|
-
### `npm install --save-dev babel-jest`
|
|
13
|
-
### modify package.json file to use babel-jest
|
|
14
|
-
``` js
|
|
15
|
-
"jest": {
|
|
16
|
-
"transform": {
|
|
17
|
-
"^.+\\.[t|j]sx?$": "babel-jest"
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
```
|
|
21
|
-
### create .babelrc configuration file
|
|
22
|
-
Create a babel.config.json config in your project root and enable some presets.
|
|
23
|
-
To start, you can use the env preset, which enables transforms for ES2015+
|
|
24
|
-
``` js
|
|
25
|
-
npm install @babel/preset-env --save-dev
|
|
26
|
-
```
|
|
27
|
-
In order to enable the preset you have to define it in your babel.config.json file, like this:
|
|
28
|
-
``` js
|
|
29
|
-
{
|
|
30
|
-
"presets": ["@babel/preset-env"]
|
|
31
|
-
}
|
|
32
|
-
```
|
|
33
8
|
## install class transformer packages to convert JSON file imports into class objects
|
|
34
9
|
``` js
|
|
35
10
|
npm install class-transformer --save
|
package/index.js
CHANGED
|
@@ -1,90 +1,80 @@
|
|
|
1
1
|
//index.js
|
|
2
2
|
|
|
3
3
|
// called by unit test
|
|
4
|
-
function sum(a, b) {
|
|
4
|
+
export function sum(a, b) {
|
|
5
5
|
return a + b;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
// called by simpleclass test app
|
|
9
|
-
function helloNpm() {
|
|
9
|
+
export function helloNpm() {
|
|
10
10
|
return "hello NPM";
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
export class User {
|
|
14
|
+
constructor(){
|
|
15
|
+
this.authority = "";
|
|
16
|
+
this.oid = "";
|
|
17
|
+
this.tid = "";
|
|
18
|
+
this.upn = "";
|
|
19
|
+
this.name = "";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
19
22
|
|
|
20
|
-
class
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
export class UserConfigInfo {
|
|
24
|
+
constructor(){
|
|
25
|
+
this.vts = null;
|
|
26
|
+
this.sts = null;
|
|
27
|
+
this.scs = null;
|
|
28
|
+
}
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
// shared base class of virtual and sync tenants
|
|
29
|
-
class Tenant{
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// TODO: can we just reference response object
|
|
38
|
-
SignIn() {} // sign in and set signinToken
|
|
39
|
-
SignOut() {} // sign out and clear signinToken
|
|
40
|
-
SignInToken() {} // session access
|
|
41
|
-
};
|
|
32
|
+
export class Tenant {
|
|
33
|
+
constructor(){
|
|
34
|
+
this.authority = "";
|
|
35
|
+
this.tid = "";
|
|
36
|
+
this.name = "";
|
|
37
|
+
this.domain = "";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
42
40
|
|
|
43
41
|
// class for "hub" tenants
|
|
44
|
-
class VirtualTenant extends Tenant{
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// admin console reads all tenants configured in AAD OR present in our database that connect to this virtual tenant
|
|
52
|
-
ReadSyncTenants() {}
|
|
53
|
-
|
|
54
|
-
// admin console can add sync tenants in sovereign clouds that are NOT configured in AAD to sync to/from this virtual tenant
|
|
55
|
-
AddSyncTenant() {}
|
|
56
|
-
RemoveSyncTenant() {}
|
|
57
|
-
};
|
|
42
|
+
export class VirtualTenant extends Tenant {
|
|
43
|
+
constructor(){
|
|
44
|
+
super();
|
|
45
|
+
this.description = "";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
58
48
|
|
|
59
49
|
// class for "spoke" tenants
|
|
60
|
-
class SyncTenant extends Tenant{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// service principal creation in AAD
|
|
71
|
-
CreateReadSP() {}
|
|
72
|
-
CreateWriteSP() {}
|
|
73
|
-
|
|
74
|
-
// service principal removal from AAD
|
|
75
|
-
RemoveReadSP() {}
|
|
76
|
-
RemoveWriteSP() {}
|
|
77
|
-
};
|
|
50
|
+
export class SyncTenant extends Tenant {
|
|
51
|
+
constructor(){
|
|
52
|
+
super();
|
|
53
|
+
this.tenantType = "";
|
|
54
|
+
this.readServicePrincipal = "";
|
|
55
|
+
this.writeServicePrincipal = "";
|
|
56
|
+
this.virtualTenantID = "";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
78
59
|
|
|
79
60
|
// class for sync configuration
|
|
80
|
-
class SyncConfig {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
61
|
+
export class SyncConfig {
|
|
62
|
+
constructor(){
|
|
63
|
+
this.enabled = "";
|
|
64
|
+
this.virtualTenantID = "";
|
|
65
|
+
this.deltaLink = "";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
import { deserializeArray } from 'class-transformer';
|
|
70
|
+
import virtualTenants from "./virtualTenants.json";
|
|
71
|
+
import syncTenants from "./syncTenants.json";
|
|
72
|
+
import syncConfigs from "./syncConfigs.json";
|
|
73
|
+
import auditLogs from "./auditLogs.json";
|
|
74
|
+
import provisioningLogs from "./provisioningLogs.json";
|
|
85
75
|
|
|
86
76
|
// called by unit test
|
|
87
|
-
function readobjects() {
|
|
77
|
+
export function readobjects() {
|
|
88
78
|
// convert read JSON to VirtualTenant array
|
|
89
79
|
debugger;
|
|
90
80
|
let virtuals = null;
|
|
@@ -100,7 +90,7 @@ function readobjects() {
|
|
|
100
90
|
}
|
|
101
91
|
|
|
102
92
|
// retrievesync configurations based on passed user information
|
|
103
|
-
function readConfigs(user,
|
|
93
|
+
export function readConfigs(user, userConfigInfo)
|
|
104
94
|
{
|
|
105
95
|
debugger;
|
|
106
96
|
// for now, just get hardcoded data from JSON
|
|
@@ -108,20 +98,12 @@ function readConfigs(user, virtuals, syncs, configs)
|
|
|
108
98
|
var syncTenantsString = JSON.stringify(syncTenants);
|
|
109
99
|
var syncConfigsString = JSON.stringify(syncConfigs);
|
|
110
100
|
try {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
101
|
+
userConfigInfo.vts = deserializeArray(VirtualTenant, virtualTenantsString);
|
|
102
|
+
userConfigInfo.sts = deserializeArray(SyncTenant, syncTenantsString);
|
|
103
|
+
userConfigInfo.scs = deserializeArray(SyncConfig, syncConfigsString);
|
|
114
104
|
} catch (e) {
|
|
115
105
|
debugger;
|
|
116
106
|
return false;
|
|
117
107
|
}
|
|
118
108
|
return true;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export {
|
|
122
|
-
sum,
|
|
123
|
-
helloNpm,
|
|
124
|
-
readobjects,
|
|
125
|
-
User, VirtualTenant, SyncTenant, SyncConfig,
|
|
126
|
-
readConfigs
|
|
127
|
-
};
|
|
109
|
+
}
|
package/index.test.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {sum, readobjects, readConfigs, User, VirtualTenant, SyncTenant, SyncConfig} from "./index.js";
|
|
1
|
+
import {sum, readobjects, readConfigs, User, UserConfigInfo, VirtualTenant, SyncTenant, SyncConfig} from "./index.js";
|
|
2
|
+
import {test, expect} from "vitest";
|
|
2
3
|
|
|
3
4
|
test("adds 1 + 2 to equal 3", () => {
|
|
4
5
|
expect(sum(1, 2)).toBe(3);
|
|
@@ -7,9 +8,8 @@ test("loads array of VirtualTenants from JSON and expects 2", () => {
|
|
|
7
8
|
expect(readobjects()).toBe(2);
|
|
8
9
|
});
|
|
9
10
|
test("loads config based on a user and expects function to return true", () => {
|
|
10
|
-
let u = new User;
|
|
11
|
-
let
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
expect(readConfigs(u, vts, sts, scs)).toBe(true);
|
|
11
|
+
let u = new User();
|
|
12
|
+
let uci = new UserConfigInfo();
|
|
13
|
+
expect(readConfigs(u, uci)).toBe(true);
|
|
14
|
+
expect(uci.vts.length).toBe(2);
|
|
15
15
|
});
|
package/package.json
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mindline/sync",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.10",
|
|
5
5
|
"description": "sync is a node.js package encapsulating javscript classes required for configuring Mindline sync service.",
|
|
6
6
|
"exports": "./index.js",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "
|
|
9
|
-
|
|
10
|
-
"jest": {
|
|
11
|
-
"transform": {
|
|
12
|
-
"^.+\\.[t|j]sx?$": "babel-jest"
|
|
13
|
-
}
|
|
8
|
+
"test": "vitest",
|
|
9
|
+
"coverage": "vitest run --coverage"
|
|
14
10
|
},
|
|
15
11
|
"keywords": [],
|
|
16
12
|
"author": "",
|
|
17
13
|
"license": "ISC",
|
|
18
14
|
"devDependencies": {
|
|
19
|
-
"
|
|
20
|
-
"jest": "^29.5.0"
|
|
15
|
+
"vitest": "^0.29.8"
|
|
21
16
|
},
|
|
22
17
|
"dependencies": {
|
|
23
18
|
"class-transformer": "^0.5.1",
|
package/sync.d.ts
CHANGED
|
@@ -1,12 +1,51 @@
|
|
|
1
|
-
declare module
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
}
|
|
1
|
+
declare module "@mindline/sync" {
|
|
2
|
+
export function sum(a: number, b: number): number;
|
|
3
|
+
export function helloNpm(): string;
|
|
4
|
+
|
|
5
|
+
// user information passed to back end
|
|
6
|
+
export class User {
|
|
7
|
+
authority: string; // from AAD
|
|
8
|
+
oid: string; // from AAD
|
|
9
|
+
tid: string; // from AAD
|
|
10
|
+
upn: string; // from AAD
|
|
11
|
+
name: string; // from AAD
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// configuration information returned by back end
|
|
15
|
+
export class UserConfigInfo {
|
|
16
|
+
vts: VirtualTenant[];
|
|
17
|
+
sts: SyncTenant[];
|
|
18
|
+
scs: SyncConfig[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// shared base class of virtual and sync tenants
|
|
22
|
+
export class Tenant {
|
|
23
|
+
authority: string; // from AAD
|
|
24
|
+
tid: string; // from AAD
|
|
25
|
+
name: string; // from AAD: tenant display name
|
|
26
|
+
domain: string; // from AAD: tenant default domain
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// class for "hub" tenants
|
|
30
|
+
export class VirtualTenant extends Tenant {
|
|
31
|
+
description: string; // from DB
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// class for "spoke" tenants
|
|
35
|
+
export class SyncTenant extends Tenant {
|
|
36
|
+
tenantType: string; // from DB: AAD | AD | Google -- always AAD for now
|
|
37
|
+
readServicePrincipal: string; // from AAD
|
|
38
|
+
writeServicePrincipal: string; // from AAD
|
|
39
|
+
virtualTenantID: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// class for sync configuration
|
|
43
|
+
export class SyncConfig {
|
|
44
|
+
enabled: boolean; // from DB
|
|
45
|
+
virtualTenantID: string;
|
|
46
|
+
deltaLink: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function readobjects(): number;
|
|
50
|
+
export function readConfigs(u: User, uci: UserConfigInfo): boolean;
|
|
51
|
+
}
|
package/vitest.config.ts
ADDED
package/babel.config.json
DELETED