@ampsec/platform-client 0.1.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
+ MIT License
2
+
3
+ Copyright (c) 2023 Fast-and-Reliable-Technologies
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,59 @@
1
+ # Amplifier Security - Data Library
2
+
3
+ Collection of data models used by our Platform API.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install @ampsec/platform-data
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ You can use the types by simply importing them.
14
+
15
+ ```ts
16
+ import {UpsertUserDto} from '@ampsec/platform-data'
17
+
18
+ const user: UpsertUserDto = {
19
+ id?: number;
20
+ etag: string;
21
+ department?: string;
22
+ emails: string[];
23
+ firstName: string;
24
+ lastName: string;
25
+ oid: number;
26
+ startDate?: string;
27
+ }
28
+ ```
29
+
30
+ TODO: deploy docs for refrence
31
+
32
+ ## Development
33
+
34
+ ```sh
35
+ npm install
36
+ npm run dev
37
+ npm run test
38
+
39
+ # Optional
40
+ npm link
41
+ cd /path/to/application
42
+ npm link @ampsec/platform-data
43
+ ```
44
+
45
+ ### Generating Docs
46
+
47
+ Published to <https://amplifier-security.gitlab.io/amp-data-lib/>
48
+
49
+ ```sh
50
+ npm run docs
51
+ # preview before deploying
52
+ npm run docs:serve
53
+ ```
54
+
55
+ ### Upgrade the dependencies
56
+
57
+ ```sh
58
+ npm upgrade
59
+ ```
@@ -0,0 +1,11 @@
1
+ export type EntityIds = {
2
+ id: number;
3
+ etag: string;
4
+ };
5
+ /**
6
+ * A lookup table used during ingestion pipeline to efficiently
7
+ * drop unmodified data and duplicate events.
8
+ */
9
+ export type EntityIdLookupMap = {
10
+ [extId: string]: EntityIds;
11
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=EntityIdLookupMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityIdLookupMap.js","sourceRoot":"","sources":["../../src/EntityIdLookupMap.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ export type BaseUpsertDto = {
2
+ /** Unique Row Identifier. Populated for entity updates. */
3
+ id?: number;
4
+ /** MD5 hash of a subset of properties to deted field level changes. */
5
+ etag: string;
6
+ };
7
+ export type BaseDto = {
8
+ /** Unique Row Identifier */
9
+ id: number;
10
+ /** MD5 hash of a subset of properties to deted field level changes. */
11
+ etag: string;
12
+ /** Record creation date in database. */
13
+ createdAt: string;
14
+ /** Last record update date in database. */
15
+ updatedAt: string;
16
+ /** Record creation date in database. Only present on soft deleted, i.e. `null => active` */
17
+ deletedAt: string | null;
18
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=base.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.dto.js","sourceRoot":"","sources":["../../../src/dto/base.dto.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ import { BaseDto, BaseUpsertDto } from './base.dto';
2
+ export type UpsertSaaSComponentDto = BaseUpsertDto & {
3
+ /** Organization ID */
4
+ oid: number;
5
+ /** Connector ID */
6
+ cid: number;
7
+ /** External ID */
8
+ extKey: string;
9
+ /** Owner ID */
10
+ uid: number | null;
11
+ /** Provider Specific Data */
12
+ meta: unknown;
13
+ };
14
+ export type SaaSComponentDto = BaseDto & UpsertSaaSComponentDto;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=components.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.dto.js","sourceRoot":"","sources":["../../../src/dto/components.dto.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ import { BaseDto, BaseUpsertDto } from './base.dto';
2
+ export type UpsertDeviceDto = BaseUpsertDto & {
3
+ /** Organization ID */
4
+ oid: number;
5
+ /** External ID: Serial Number */
6
+ sn: string;
7
+ /** Owner ID */
8
+ uid: number | null;
9
+ };
10
+ export type DeviceDto = BaseDto & UpsertDeviceDto;
11
+ export type UpsertSaaSDeviceDto = BaseUpsertDto & {
12
+ /** Organization ID */
13
+ oid: number;
14
+ /** External ID: Serial Number */
15
+ sn: string;
16
+ /** Owner ID */
17
+ uid: number | null;
18
+ /** Connector ID */
19
+ cid: number;
20
+ /** Provider Specific Data */
21
+ meta: unknown;
22
+ };
23
+ export type SaaSDeviceDto = BaseDto & UpsertSaaSDeviceDto;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=devices.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devices.dto.js","sourceRoot":"","sources":["../../../src/dto/devices.dto.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export * from './base.dto';
2
+ export * from './page.dto';
3
+ export * from './users.dto';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./base.dto"), exports);
18
+ __exportStar(require("./page.dto"), exports);
19
+ __exportStar(require("./users.dto"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/dto/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,6CAA2B;AAC3B,8CAA4B"}
@@ -0,0 +1,4 @@
1
+ export type Page<T> = {
2
+ items: T[];
3
+ hasMore: boolean;
4
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=page.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page.dto.js","sourceRoot":"","sources":["../../../src/dto/page.dto.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ import { BaseDto, BaseUpsertDto } from './base.dto';
2
+ export type UpsertUserDto = BaseUpsertDto & {
3
+ /** Organization ID */
4
+ oid: number;
5
+ /** External ID: list of emails, allows or merging users across email aliases */
6
+ emails: string[];
7
+ firstName: string;
8
+ lastName: string;
9
+ department?: string;
10
+ /** Employment start date used for calculating tenure */
11
+ startDate?: string;
12
+ };
13
+ export type UserDto = BaseDto & UpsertUserDto;
14
+ export type UpsertSaaSUserDto = BaseUpsertDto & {
15
+ /** Organization ID */
16
+ oid: number;
17
+ /** Connector ID */
18
+ cid: number;
19
+ /** Global User ID */
20
+ uid: number;
21
+ /** External ID */
22
+ email: string;
23
+ /** Provider Specific Data */
24
+ meta: unknown;
25
+ };
26
+ export type SaaSUserDto = BaseDto & UpsertSaaSUserDto;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=users.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"users.dto.js","sourceRoot":"","sources":["../../../src/dto/users.dto.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import { BaseDto, BaseUpsertDto } from './';
2
+ export declare function calculateEtag(model: unknown): string;
3
+ export declare function withEtag(model: BaseDto | BaseUpsertDto): void;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.withEtag = exports.calculateEtag = void 0;
7
+ const blueimp_md5_1 = __importDefault(require("blueimp-md5"));
8
+ function calculateEtag(model) {
9
+ const hashObject = { ...model };
10
+ delete hashObject.etag;
11
+ return (0, blueimp_md5_1.default)(JSON.stringify(hashObject));
12
+ }
13
+ exports.calculateEtag = calculateEtag;
14
+ function withEtag(model) {
15
+ model.etag = calculateEtag(model);
16
+ }
17
+ exports.withEtag = withEtag;
18
+ //# sourceMappingURL=etag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"etag.js","sourceRoot":"","sources":["../../src/etag.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA8B;AAG9B,SAAgB,aAAa,CAAC,KAAc;IAC1C,MAAM,UAAU,GAAoB,EAAC,GAAI,KAAgB,EAAC,CAAC;IAC3D,OAAO,UAAU,CAAC,IAAI,CAAC;IACvB,OAAO,IAAA,qBAAG,EAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;AACzC,CAAC;AAJD,sCAIC;AAED,SAAgB,QAAQ,CAAC,KAA8B;IACrD,KAAK,CAAC,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;AACpC,CAAC;AAFD,4BAEC"}
@@ -0,0 +1,3 @@
1
+ export * from './dto';
2
+ export * from './etag';
3
+ export * from './EntityIdLookupMap';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./dto"), exports);
18
+ __exportStar(require("./etag"), exports);
19
+ __exportStar(require("./EntityIdLookupMap"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,yCAAuB;AACvB,sDAAoC"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@ampsec/platform-client",
3
+ "version": "0.1.0",
4
+ "description": "",
5
+ "main": "build/src/index.js",
6
+ "scripts": {
7
+ "dev": "tsc --watch",
8
+ "prebuild": "rimraf build",
9
+ "build": "tsc",
10
+ "predocs": "rimraf public",
11
+ "docs": "typedoc --out public src/index.ts",
12
+ "docs:serve": "serve public -p 3080",
13
+ "lint": "gts lint",
14
+ "clean": "gts clean",
15
+ "fix": "gts fix",
16
+ "test": "jest"
17
+ },
18
+ "keywords": [],
19
+ "author": "Amplifier Security <engineering@amplifiersecurity.com>",
20
+ "license": "MIT",
21
+ "dependencies": {
22
+ "blueimp-md5": "^2.19.0",
23
+ "lodash.omit": "^4.5.0"
24
+ },
25
+ "devDependencies": {
26
+ "@jest/types": "^29.5.0",
27
+ "@types/blueimp-md5": "^2.18.0",
28
+ "@types/jest": "^29.5.1",
29
+ "@types/lodash.omit": "^4.5.7",
30
+ "gts": "^3.1.1",
31
+ "jest": "^29.5.0",
32
+ "rimraf": "^5.0.0",
33
+ "serve": "^14.2.0",
34
+ "ts-jest": "^29.1.0",
35
+ "ts-node": "^10.9.1",
36
+ "typedoc": "^0.24.7",
37
+ "typescript": "^5.0.4"
38
+ },
39
+ "files": [
40
+ "/build/src"
41
+ ]
42
+ }