@pgds/api-interface 1.4.8 → 1.4.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 CHANGED
@@ -362,7 +362,7 @@ Prerequisites:
362
362
  Then, in root, run:
363
363
 
364
364
  ```typescript
365
- // Check out any untracked/ignored files (e.g. previously built files)
365
+ // Check out any untracked/ignored files (e.g. previously built files) ⚠ Do not do this unless you have committed any changes you want to keep ⚠
366
366
  yarn clean
367
367
 
368
368
  // Install dependencies
@@ -0,0 +1,4 @@
1
+ export type TestRequestSchema = {
2
+ name: string;
3
+ age: number;
4
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=TestRequestSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TestRequestSchema.js","sourceRoot":"","sources":["TestRequestSchema.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ export type TestResponseSchema = {
2
+ id: string;
3
+ name: string;
4
+ age: number;
5
+ };
6
+ export declare const TEST_RESPONSE_SCHEMA = "TestResponseSchema";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TEST_RESPONSE_SCHEMA = void 0;
4
+ exports.TEST_RESPONSE_SCHEMA = "TestResponseSchema";
5
+ //# sourceMappingURL=TestResponseSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TestResponseSchema.js","sourceRoot":"","sources":["TestResponseSchema.ts"],"names":[],"mappings":";;;AAMa,QAAA,oBAAoB,GAAG,oBAAoB,CAAC"}
@@ -13,6 +13,10 @@ interface RequestStore {
13
13
  * Will be automatically be added to any requests made with the clients extending FairtrailClient.
14
14
  **/
15
15
  reqId: string;
16
+ /**
17
+ * User agent of the current request
18
+ */
19
+ userAgent?: string;
16
20
  }
17
21
  type RequestContext = Request | string;
18
22
  /**
@@ -39,6 +39,7 @@ var constants_1 = require("../../constants");
39
39
  var async_hooks_1 = require("async_hooks");
40
40
  var ReqUser_1 = require("../models/ReqUser");
41
41
  var uuid = __importStar(require("uuid"));
42
+ var USER_AGENT_HEADER = "user-agent";
42
43
  function isRequest(reqContext) {
43
44
  return !!reqContext && typeof reqContext === "object";
44
45
  }
@@ -51,18 +52,20 @@ var asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
51
52
  * @throws Any error thrown by the inputted function
52
53
  */
53
54
  function runWithRequestContext(reqContext, fn) {
54
- var _a, _b, _c, _d;
55
+ var _a, _b, _c, _d, _e;
55
56
  var reqId = "";
56
57
  var user = undefined;
58
+ var userAgent = undefined;
57
59
  if (isRequest(reqContext)) {
58
60
  reqId = (_c = (_b = (_a = reqContext.header) === null || _a === void 0 ? void 0 : _a.call(reqContext, constants_1.REQUEST_ID_HEADER)) !== null && _b !== void 0 ? _b : reqContext.getId()) !== null && _c !== void 0 ? _c : uuid.v4();
59
61
  user = (_d = reqContext.user) !== null && _d !== void 0 ? _d : getFallbackUser(reqContext);
62
+ userAgent = (_e = reqContext.header) === null || _e === void 0 ? void 0 : _e.call(reqContext, USER_AGENT_HEADER);
60
63
  }
61
64
  else {
62
65
  reqId = reqContext !== null && reqContext !== void 0 ? reqContext : uuid.v4();
63
66
  }
64
67
  return new Promise(function (resolve, reject) {
65
- asyncLocalStorage.run({ reqId: reqId, user: user }, function () {
68
+ asyncLocalStorage.run({ reqId: reqId, user: user, userAgent: userAgent }, function () {
66
69
  try {
67
70
  resolve(fn());
68
71
  }
@@ -1 +1 @@
1
- {"version":3,"file":"asyncHooks.js","sourceRoot":"","sources":["asyncHooks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,sDAuBC;AAGD,kCAEC;AAxED,6CAOyB;AACzB,2CAAgD;AAChD,6CAA4C;AAE5C,yCAA6B;AAoB7B,SAAS,SAAS,CAAC,UAA0B;IAC3C,OAAO,CAAC,CAAC,UAAU,IAAI,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GAAG,CAAC,MAAM,CAAC,oCAAwB,CAAC,CAAC;IACzD,IAAM,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,kCAAsB,CAAC,CAAC;IACtD,IAAM,cAAc,GAAG,GAAG,CAAC,MAAM,CAAC,oCAAwB,CAAC,CAAC;IAC5D,IAAM,qBAAqB,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,8CAAkC,EAAE,IAAI,CAAC,CAAC,CAAC;IAE/F,oDAAoD;IACpD,IAAI,CAAC,MAAM,IAAI,CAAC,WAAW,IAAI,CAAC,UAAU,IAAI,CAAC,cAAc,IAAI,CAAC,qBAAqB,EAAE,CAAC;QACxF,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,IAAI,iBAAO,CAAC;QACjB,MAAM,QAAA;QACN,WAAW,aAAA;QACX,UAAU,EAAE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,KAAK,CAAC,GAAG,EAAE,MAAM,CACvC,UAAC,GAAG,EAAE,QAAQ;YACZ,GAAG,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;YACrB,OAAO,GAAG,CAAC;QACb,CAAC,EACD,EAA6B,CAC9B;QACD,cAAc,gBAAA;QACd,qBAAqB,uBAAA;KACtB,CAAC,CAAC;AACL,CAAC"}
@@ -1,3 +1,3 @@
1
1
  import { logger as pgdsLogger } from "@pgds/utils/logging";
2
2
  export declare function setLogger(inLogger: typeof pgdsLogger): void;
3
- export declare function getLogger(): import("bunyan");
3
+ export declare function getLogger(): typeof pgdsLogger;
package/package.json CHANGED
@@ -1,101 +1,101 @@
1
1
  {
2
- "name": "@pgds/api-interface",
3
- "description": "Api interface for pgds services",
4
- "authors": "Florry",
5
- "version": "1.4.8",
6
- "main": "index.js",
7
- "types": "types/",
8
- "scripts": {
9
- "prepublish": "npm run build",
10
- "build": "tsc",
11
- "pretest": "npm run build",
12
- "test": "nyc --require ts-node/register --reporter=html mocha --colors",
13
- "clean": "git clean -f -x -e node_modules/ -e coverage/"
14
- },
15
- "files": [
16
- "**/*.d.ts",
17
- "./index.js",
18
- "lib/**/*.js",
19
- "lib/**/*.js.map",
20
- "lib/**/*.d.ts",
21
- "errors/**/*.js",
22
- "errors/**/*.js.map",
23
- "errors/**/*.d.ts",
24
- "constants/**/*.js",
25
- "constants/**/*.js.map",
26
- "constants/**/*.d.ts",
27
- "utils/**/*.js",
28
- "utils/**/*.js.map",
29
- "utils/**/*.d.ts",
30
- "client/**/*.js",
31
- "client/**/*.js.map",
32
- "client/**/*.d.ts"
33
- ],
34
- "dependencies": {
35
- "@types/restify": "^8.5.12",
36
- "@types/restify-errors": "^4.3.9",
37
- "@pgds/utils": "1.0.7",
38
- "ajv": "8.17.1",
39
- "ajv-formats": "3.0.1",
40
- "axios": "1.7.9",
41
- "mustbe": "0.4.0",
42
- "nyc": "^17.1.0",
43
- "prom-client": "^12.0.0",
44
- "restify": "^11.1.0",
45
- "restify-errors": "8.0.2",
46
- "semver": "^7.3.8",
47
- "ts-node": "^10.9.2",
48
- "ts-node-test-register": "^10.0.0",
49
- "uuid": "9.0.1",
50
- "typescript": "^5.7.2",
51
- "typescript-json-schema": "0.65.1"
52
- },
53
- "devDependencies": {
54
- "@types/chai": "4.3.12",
55
- "@types/mocha": "^10.0.6",
56
- "@types/mockery": "^1.4.30",
57
- "@types/nock": "11.1.0",
58
- "@types/semver": "^7.3.13",
59
- "@types/supertest": "^2.0.11",
60
- "@types/uuid": "^8.3.4",
61
- "chai": "^4.3.6",
62
- "chai-subset": "^1.6.0",
63
- "mocha": "10.2.0",
64
- "mockery": "2.1.0",
65
- "supertest": "6.3.4",
66
- "nock": "13.5.5"
67
- },
68
- "directories": {
69
- "example": "examples",
70
- "lib": "lib",
71
- "types": "types"
72
- },
73
- "repository": {
74
- "type": "git",
75
- "url": "git+https://github.com/hiotlabs/hiot-api-interface.git"
76
- },
77
- "keywords": [
78
- "restify"
79
- ],
80
- "author": "",
81
- "license": "ISC",
82
- "bugs": {
83
- "url": "https://github.com/hiotlabs/hiot-api-interface/issues"
84
- },
85
- "homepage": "https://github.com/hiotlabs/hiot-api-interface#readme",
86
- "mocha": {
87
- "extension": [
88
- "ts",
89
- "js"
2
+ "name": "@pgds/api-interface",
3
+ "description": "Api interface for pgds services",
4
+ "authors": "Florry",
5
+ "version": "1.4.10",
6
+ "main": "index.js",
7
+ "types": "types/",
8
+ "scripts": {
9
+ "prepublish": "npm run build",
10
+ "build": "tsc",
11
+ "pretest": "npm run build",
12
+ "test": "nyc --require ts-node/register --reporter=html mocha --colors",
13
+ "clean": "git clean -f -x -e node_modules/ -e coverage/"
14
+ },
15
+ "files": [
16
+ "**/*.d.ts",
17
+ "./index.js",
18
+ "lib/**/*.js",
19
+ "lib/**/*.js.map",
20
+ "lib/**/*.d.ts",
21
+ "errors/**/*.js",
22
+ "errors/**/*.js.map",
23
+ "errors/**/*.d.ts",
24
+ "constants/**/*.js",
25
+ "constants/**/*.js.map",
26
+ "constants/**/*.d.ts",
27
+ "utils/**/*.js",
28
+ "utils/**/*.js.map",
29
+ "utils/**/*.d.ts",
30
+ "client/**/*.js",
31
+ "client/**/*.js.map",
32
+ "client/**/*.d.ts"
90
33
  ],
91
- "spec": "test/**/*.test.{ts,js}"
92
- },
93
- "nyc": {
94
- "exclude": [
95
- "coverage",
96
- "test",
97
- "**/*.d.ts",
98
- "**/*.js.map"
99
- ]
100
- }
34
+ "dependencies": {
35
+ "@types/restify": "^8.5.12",
36
+ "@types/restify-errors": "^4.3.9",
37
+ "@pgds/utils": "1.1.4",
38
+ "ajv": "8.17.1",
39
+ "ajv-formats": "3.0.1",
40
+ "axios": "1.7.9",
41
+ "mustbe": "0.4.0",
42
+ "nyc": "^17.1.0",
43
+ "prom-client": "^12.0.0",
44
+ "restify": "^11.1.0",
45
+ "restify-errors": "8.0.2",
46
+ "semver": "^7.3.8",
47
+ "ts-node": "^10.9.2",
48
+ "ts-node-test-register": "^10.0.0",
49
+ "uuid": "9.0.1",
50
+ "typescript": "^5.7.2",
51
+ "typescript-json-schema": "0.65.1"
52
+ },
53
+ "devDependencies": {
54
+ "@types/chai": "4.3.12",
55
+ "@types/mocha": "^10.0.6",
56
+ "@types/mockery": "^1.4.30",
57
+ "@types/nock": "11.1.0",
58
+ "@types/semver": "^7.3.13",
59
+ "@types/supertest": "^2.0.11",
60
+ "@types/uuid": "^8.3.4",
61
+ "chai": "^4.3.6",
62
+ "chai-subset": "^1.6.0",
63
+ "mocha": "10.2.0",
64
+ "mockery": "2.1.0",
65
+ "supertest": "6.3.4",
66
+ "nock": "13.5.5"
67
+ },
68
+ "directories": {
69
+ "example": "examples",
70
+ "lib": "lib",
71
+ "types": "types"
72
+ },
73
+ "repository": {
74
+ "type": "git",
75
+ "url": "git+https://github.com/hiotlabs/hiot-api-interface.git"
76
+ },
77
+ "keywords": [
78
+ "restify"
79
+ ],
80
+ "author": "",
81
+ "license": "ISC",
82
+ "bugs": {
83
+ "url": "https://github.com/hiotlabs/hiot-api-interface/issues"
84
+ },
85
+ "homepage": "https://github.com/hiotlabs/hiot-api-interface#readme",
86
+ "mocha": {
87
+ "extension": [
88
+ "ts",
89
+ "js"
90
+ ],
91
+ "spec": "test/**/*.test.{ts,js}"
92
+ },
93
+ "nyc": {
94
+ "exclude": [
95
+ "coverage",
96
+ "test",
97
+ "**/*.d.ts",
98
+ "**/*.js.map"
99
+ ]
100
+ }
101
101
  }