@contrail/flexplm 1.0.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/README.md ADDED
@@ -0,0 +1 @@
1
+ Core model for contrail, which establishes the base peristence services (without dependency on a persistence implementaiton) and core NestJS elements such as the InvocationContext.
@@ -0,0 +1,3 @@
1
+ export declare class FlexPLMRequest {
2
+ static request(path: string, data: any): Promise<any>;
3
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.FlexPLMRequest = void 0;
13
+ const axios_1 = require("axios");
14
+ const BASE_URL = 'https://PP-2006031951wo.portal.ptc.io/Windchill/servlet/rest/cdee';
15
+ const BASE_CONFIG = {
16
+ method: 'POST',
17
+ headers: {
18
+ 'Accept': 'application/json',
19
+ 'Content-Type': 'application/json',
20
+ 'CSRF_NONCE': '2OaLp+0dWNBtrkTwtdDC491zaacu6Hykvqi/lpl6bZgJ/QXBrK/B1J5FErMkmAmktr/I3thcbO1Xn3HJ7Ne/l9kpaedUmn7H75Xey4ZbNLsenW+anM3vxIZ7ELosk3k=',
21
+ 'Authorization': 'Basic d2NhZG1pbjpSZXRhaWwyMDIwLQ==',
22
+ 'Cookie': 'JSESSIONID=36D5B3C74C1F963C6C73E9AF5B6BDA78.tomcat1; JSESSIONID=B8090C802D8548EA773C97F5886FAB79.tomcat1',
23
+ },
24
+ };
25
+ class FlexPLMRequest {
26
+ static request(path, data) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const config = Object.assign({}, BASE_CONFIG);
29
+ config.url = BASE_URL + path;
30
+ config.data = data;
31
+ try {
32
+ const resp = yield axios_1.default(config);
33
+ return Promise.resolve(resp.data);
34
+ }
35
+ catch (error) {
36
+ console.error(`${FlexPLMRequest} error: ${error.message}`);
37
+ return Promise.resolve(null);
38
+ }
39
+ });
40
+ }
41
+ }
42
+ exports.FlexPLMRequest = FlexPLMRequest;
@@ -0,0 +1,5 @@
1
+ export declare class FlexPLMUtils {
2
+ static convertTypePath: (path: string) => string;
3
+ static getParentTypePath: (path: string) => string;
4
+ static computeLevelFromPath(path: string): number;
5
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlexPLMUtils = void 0;
4
+ class FlexPLMUtils {
5
+ static computeLevelFromPath(path) {
6
+ return (path.match(/:/g) || []).length + 1;
7
+ }
8
+ }
9
+ exports.FlexPLMUtils = FlexPLMUtils;
10
+ FlexPLMUtils.convertTypePath = (path) => {
11
+ if (!path) {
12
+ return null;
13
+ }
14
+ let newPath = path;
15
+ while (newPath.indexOf('\\') > 1) {
16
+ newPath = newPath.replace('\\', ':');
17
+ }
18
+ while (newPath.indexOf(' ') > 1) {
19
+ newPath = newPath.replace(' ', '_');
20
+ }
21
+ newPath = newPath.toLowerCase();
22
+ return newPath;
23
+ };
24
+ FlexPLMUtils.getParentTypePath = (path) => {
25
+ const newPath = FlexPLMUtils.convertTypePath(path);
26
+ return (!newPath || newPath.indexOf(':') < 0) ? null : newPath.substring(0, newPath.lastIndexOf(':'));
27
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const flexplm_utils_1 = require("./flexplm-utils");
13
+ describe('Types Controller', () => {
14
+ beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
15
+ }));
16
+ it('should convert a type path', () => {
17
+ expect(flexplm_utils_1.FlexPLMUtils.convertTypePath('Product')).toEqual('product');
18
+ expect(flexplm_utils_1.FlexPLMUtils.convertTypePath('Product\\Apparel')).toEqual('product:apparel');
19
+ expect(flexplm_utils_1.FlexPLMUtils.convertTypePath('Product\\Skin Care')).toEqual('product:skin_care');
20
+ expect(flexplm_utils_1.FlexPLMUtils.convertTypePath('Product\\Apparel\\Shirt')).toEqual('product:apparel:shirt');
21
+ expect(flexplm_utils_1.FlexPLMUtils.convertTypePath('')).toBeNull();
22
+ });
23
+ it('should compute level in tree', () => {
24
+ expect(flexplm_utils_1.FlexPLMUtils.computeLevelFromPath('product')).toEqual(1);
25
+ expect(flexplm_utils_1.FlexPLMUtils.computeLevelFromPath('product:apparel')).toEqual(2);
26
+ expect(flexplm_utils_1.FlexPLMUtils.computeLevelFromPath('product:apparel:dress:mini')).toEqual(4);
27
+ });
28
+ it('should get a parent type path', () => {
29
+ expect(flexplm_utils_1.FlexPLMUtils.getParentTypePath('product')).toBeNull();
30
+ expect(flexplm_utils_1.FlexPLMUtils.getParentTypePath('product:apparel')).toEqual('product');
31
+ expect(flexplm_utils_1.FlexPLMUtils.getParentTypePath('product:apparel:stuff')).toEqual('product:apparel');
32
+ expect(flexplm_utils_1.FlexPLMUtils.getParentTypePath('Product\\Apparel')).toEqual('product');
33
+ });
34
+ });
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './flexplm-request';
2
+ export * from './flexplm-utils';
package/lib/index.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./flexplm-request"), exports);
14
+ __exportStar(require("./flexplm-utils"), exports);
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@contrail/flexplm",
3
+ "version": "1.0.0",
4
+ "description": "Library used for integration with flexplm.",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
10
+ "lint": "tslint -p tsconfig.json",
11
+ "test": "jest"
12
+ },
13
+ "keywords": [],
14
+ "author": "",
15
+ "license": "ISC",
16
+ "files": [
17
+ "lib/**/*"
18
+ ],
19
+ "devDependencies": {
20
+ "@types/jest": "^23.3.14",
21
+ "jest": "^23.6.0",
22
+ "prettier": "^1.19.1",
23
+ "ts-jest": "^23.10.5",
24
+ "tslint": "^5.11.0",
25
+ "tslint-config-prettier": "^1.18.0",
26
+ "typescript": "^3.0.1"
27
+ },
28
+ "jest": {
29
+ "moduleFileExtensions": [
30
+ "js",
31
+ "json",
32
+ "ts"
33
+ ],
34
+ "rootDir": "src",
35
+ "testRegex": ".spec.ts$",
36
+ "transform": {
37
+ "^.+\\.(t|j)s$": "ts-jest"
38
+ },
39
+ "coverageDirectory": "../coverage",
40
+ "testEnvironment": "node"
41
+ },
42
+ "dependencies": {
43
+ "axios": "^0.19.2"
44
+ }
45
+ }