@pgds/api-interface 1.2.6 → 1.3.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.
@@ -193,7 +193,7 @@ var FairtrailClient = /** @class */ (function (_super) {
193
193
  _a[constants_1.AUTH_ACTIVE_LOGIN_HEADER] = (_e = this.reqUser.activeLogin) !== null && _e !== void 0 ? _e : "",
194
194
  _a[constants_1.AUTH_ACTIVITIES_HEADER] = Object.keys((_f = this.reqUser.activities) !== null && _f !== void 0 ? _f : []).join(","),
195
195
  _a[constants_1.AUTH_ORGANIZATION_HEADER] = (_g = this.reqUser.organizationId) !== null && _g !== void 0 ? _g : "",
196
- _a[constants_1.AUTH_CHILD_ORGANIZATIONS_HEADER] = ((_h = this.reqUser.childOrganizationIds) !== null && _h !== void 0 ? _h : []).join(","),
196
+ _a[constants_1.AUTH_ORGANIZATION_HIERARCHY_HEADER] = JSON.stringify((_h = this.reqUser.organizationHierarchy) !== null && _h !== void 0 ? _h : {}),
197
197
  _a)];
198
198
  }
199
199
  if (this.reqAsGlobal) {
@@ -1 +1 @@
1
- {"version":3,"file":"FairtrailClient.js","sourceRoot":"","sources":["FairtrailClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAQsB;AACtB,8BAAwC;AACxC,wDAAsE;AAEtE,2CAA0C;AAE1C;;;;GAIG;AACH;IAAqC,mCAAU;IAA/C;;QAEU,iBAAW,GAAY,KAAK,CAAC;QAC7B,8BAAwB,GAAY,KAAK,CAAC;;IAmHpD,CAAC;IAhHC,sBAAc,qCAAQ;aAAtB;YAAA,iBAsBC;YArBC,OAAO;gBACL,GAAG,EAAE,UAAO,OAAuC;;;oCAC1C,qBAAM,IAAI,CAAC,GAAG,uBAAM,OAAO,KAAE,IAAI,EAAE,UAAG,oCAAwB,SAAG,OAAO,CAAC,IAAI,CAAE,IAAG,EAAA;o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9E,GAAC,oCAAwB,IAAG,MAAA,IAAI,CAAC,OAAO,CAAC,cAAc,mCAAI,EAAE;4BAC7D,GAAC,8CAAkC,IAAG,IAAI,CAAC,SAAS,CAAC,MAAA,IAAI,CAAC,OAAO,CAAC,qBAAqB,mCAAI,EAAE,CAAC;iCAC9F;gBACJ,CAAC;gBAED,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;oBACrB;4BACE,GAAC,4BAAgB,IAAG,IAAI,CAAC,cAAc;4BACvC,GAAC,kCAAsB,IAAG,2BAAe;iCACzC;gBACJ,CAAC;gBAED,IAAI,IAAI,CAAC,wBAAwB,EAAE,CAAC;oBAClC;4BACE,GAAC,4BAAgB,IAAG,IAAI,CAAC,cAAc;4BACvC,GAAC,kCAAsB,IAAG,4CAAgC;4BAC1D,GAAC,oCAAwB,IAAG,MAAA,IAAI,CAAC,iBAAiB,mCAAI,EAAE;iCACxD;gBACJ,CAAC;gBAED,sBAAO,EAAE,EAAC;;;KACX;IACH,sBAAC;AAAD,CAAC,AAtHD,CAAqC,uBAAU,GAsH9C;AAtHY,0CAAe"}
@@ -1,6 +1,6 @@
1
1
  export declare const AUTH_USER_HEADER = "auth-user";
2
2
  export declare const AUTH_ORGANIZATION_HEADER = "auth-organization";
3
- export declare const AUTH_CHILD_ORGANIZATIONS_HEADER = "auth-child-organizations";
3
+ export declare const AUTH_ORGANIZATION_HIERARCHY_HEADER = "auth-organization-hierarchy";
4
4
  export declare const AUTH_ACTIVITIES_HEADER = "auth-activities";
5
5
  export declare const AUTH_ACTIVE_LOGIN_HEADER = "auth-active-login";
6
6
  export declare const GLOBAL_ACTIVITY = "global";
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.REQUEST_ID_HEADER = exports.CAN_MANAGE_ORGANIZATION_ACTIVITY = exports.GLOBAL_ACTIVITY = exports.AUTH_ACTIVE_LOGIN_HEADER = exports.AUTH_ACTIVITIES_HEADER = exports.AUTH_CHILD_ORGANIZATIONS_HEADER = exports.AUTH_ORGANIZATION_HEADER = exports.AUTH_USER_HEADER = void 0;
3
+ exports.REQUEST_ID_HEADER = exports.CAN_MANAGE_ORGANIZATION_ACTIVITY = exports.GLOBAL_ACTIVITY = exports.AUTH_ACTIVE_LOGIN_HEADER = exports.AUTH_ACTIVITIES_HEADER = exports.AUTH_ORGANIZATION_HIERARCHY_HEADER = exports.AUTH_ORGANIZATION_HEADER = exports.AUTH_USER_HEADER = void 0;
4
4
  /* Note: These will be exported to the library as @hiotlabs/hiot-api-interface/constants */
5
5
  exports.AUTH_USER_HEADER = "auth-user";
6
6
  exports.AUTH_ORGANIZATION_HEADER = "auth-organization";
7
- exports.AUTH_CHILD_ORGANIZATIONS_HEADER = "auth-child-organizations";
7
+ exports.AUTH_ORGANIZATION_HIERARCHY_HEADER = "auth-organization-hierarchy";
8
8
  exports.AUTH_ACTIVITIES_HEADER = "auth-activities";
9
9
  exports.AUTH_ACTIVE_LOGIN_HEADER = "auth-active-login";
10
10
  exports.GLOBAL_ACTIVITY = "global";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,2FAA2F;AAC9E,QAAA,gBAAgB,GAAG,WAAW,CAAC;AAC/B,QAAA,wBAAwB,GAAG,mBAAmB,CAAC;AAC/C,QAAA,+BAA+B,GAAG,0BAA0B,CAAC;AAC7D,QAAA,sBAAsB,GAAG,iBAAiB,CAAC;AAC3C,QAAA,wBAAwB,GAAG,mBAAmB,CAAC;AAE/C,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,gCAAgC,GAAG,uBAAuB,CAAC;AAE3D,QAAA,iBAAiB,GAAG,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,2FAA2F;AAC9E,QAAA,gBAAgB,GAAG,WAAW,CAAC;AAC/B,QAAA,wBAAwB,GAAG,mBAAmB,CAAC;AAC/C,QAAA,kCAAkC,GAAG,6BAA6B,CAAC;AACnE,QAAA,sBAAsB,GAAG,iBAAiB,CAAC;AAC3C,QAAA,wBAAwB,GAAG,mBAAmB,CAAC;AAE/C,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,gCAAgC,GAAG,uBAAuB,CAAC;AAE3D,QAAA,iBAAiB,GAAG,YAAY,CAAC"}
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runWithRequestContext = exports.useReqStore = exports.routeHelpers = exports.server = exports.closeServer = exports.Method = exports.internal = exports.put = exports.post = exports.patch = exports.get = exports.del = exports.endpointMetadata = exports.setupInterfaceLegacy = exports.setupApiInterface = void 0;
3
+ exports.runWithRequestContext = exports.useReqStore = exports.routeHelpers = exports.server = exports.closeServer = exports.ReqUser = exports.Method = exports.internal = exports.put = exports.post = exports.patch = exports.get = exports.del = exports.endpointMetadata = exports.setupInterfaceLegacy = exports.setupApiInterface = void 0;
4
4
  var lib_1 = require("./lib");
5
5
  Object.defineProperty(exports, "setupApiInterface", { enumerable: true, get: function () { return lib_1.setupApiInterface; } });
6
6
  Object.defineProperty(exports, "setupInterfaceLegacy", { enumerable: true, get: function () { return lib_1.setupInterfaceLegacy; } });
@@ -14,6 +14,8 @@ Object.defineProperty(exports, "internal", { enumerable: true, get: function ()
14
14
  Object.defineProperty(exports, "Method", { enumerable: true, get: function () { return lib_1.Method; } });
15
15
  var mustbeConfig_1 = require("./lib/auth/mustbeConfig");
16
16
  Object.defineProperty(exports, "routeHelpers", { enumerable: true, get: function () { return mustbeConfig_1.routeHelpers; } });
17
+ var ReqUser_1 = require("./lib/models/ReqUser");
18
+ Object.defineProperty(exports, "ReqUser", { enumerable: true, get: function () { return ReqUser_1.ReqUser; } });
17
19
  var server_1 = require("./lib/server/server");
18
20
  Object.defineProperty(exports, "closeServer", { enumerable: true, get: function () { return server_1.closeServer; } });
19
21
  Object.defineProperty(exports, "server", { enumerable: true, get: function () { return server_1.server; } });
@@ -1,6 +1,4 @@
1
- type Activities = {
2
- [activity: string]: boolean;
3
- };
1
+ import { Activities } from "../models/ReqUser";
4
2
  type MustbeRouteHelpers = () => {
5
3
  authorized: (activity: string) => void;
6
4
  authenticated: () => void;
@@ -41,6 +41,9 @@ exports.configureMustBe = configureMustBe;
41
41
  exports.isUserAuthorized = isUserAuthorized;
42
42
  var constants_1 = require("../../constants");
43
43
  var restifyErrors = __importStar(require("restify-errors"));
44
+ // TODO: this import crashes the library when used by a service
45
+ // import Configurator from "../../types/mustbe/config";
46
+ var ReqUser_1 = require("../models/ReqUser");
44
47
  var jsonSchemaUtils_1 = require("../utils/jsonSchemaUtils");
45
48
  var logger_1 = __importDefault(require("../utils/logger"));
46
49
  var mustbe = require("mustbe");
@@ -89,19 +92,10 @@ function configureMustBe() {
89
92
  function parseUser(req) {
90
93
  var userId = req.header(constants_1.AUTH_USER_HEADER, undefined);
91
94
  var organizationId = req.header(constants_1.AUTH_ORGANIZATION_HEADER, undefined);
92
- var childOrganizationIds = req
93
- .header(constants_1.AUTH_CHILD_ORGANIZATIONS_HEADER, "")
94
- .split(",")
95
- .filter(function (id) { return id !== ""; });
96
95
  var activities = parseActivities(req.header(constants_1.AUTH_ACTIVITIES_HEADER, ""));
97
96
  var activeLogin = req.header(constants_1.AUTH_ACTIVE_LOGIN_HEADER, undefined);
98
- var user = {
99
- userId: userId,
100
- organizationId: organizationId,
101
- childOrganizationIds: childOrganizationIds,
102
- activities: activities,
103
- activeLogin: activeLogin,
104
- };
97
+ var organizationHierarchy = JSON.parse(req.header(constants_1.AUTH_ORGANIZATION_HIERARCHY_HEADER, "{}"));
98
+ var user = new ReqUser_1.ReqUser({ userId: userId, organizationId: organizationId, activities: activities, activeLogin: activeLogin, organizationHierarchy: organizationHierarchy });
105
99
  // @ts-ignore
106
100
  req.user = user;
107
101
  return user;
@@ -111,7 +105,11 @@ function userIsUndefined(user) {
111
105
  return true;
112
106
  }
113
107
  var userId = user.userId, organizationId = user.organizationId, activeLogin = user.activeLogin, childOrganizationIds = user.childOrganizationIds;
114
- if (!userId && !organizationId && !activeLogin && !(childOrganizationIds === null || childOrganizationIds === void 0 ? void 0 : childOrganizationIds.length)) {
108
+ if (!userId &&
109
+ !organizationId &&
110
+ !activeLogin &&
111
+ !(childOrganizationIds === null || childOrganizationIds === void 0 ? void 0 : childOrganizationIds.length) &&
112
+ !Object.keys(user.organizationHierarchy).length) {
115
113
  return true;
116
114
  }
117
115
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"mustbeConfig.js","sourceRoot":"","sources":["mustbeConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,0CAqCC;AAqDD,4CAmBC;AApJD,6CAOyB;AACzB,4DAAgD;AAKhD,4DAAsF;AACtF,2DAAqC;AAErC,IAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAUjC,kDAAkD;AAClD,IAAM,YAAY,GAAG,CAAC;IACpB,IAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;IAExD,OAAO;QACL,UAAU,EAAE,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC;QACtD,aAAa,EAAE,YAAY,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC;QAC5D,aAAa,EAAE,UAAC,MAAW,IAAK,OAAA,IAAA,gDAA8B,EAAC,MAAM,EAAE,4BAAU,CAAC,IAAI,CAAC,EAAvD,CAAuD;KACxF,CAAC;AACJ,CAAC,CAAuB,CAAC;AAEhB,oCAAY;AAErB,SAAgB,eAAe;IAC7B,MAAM,CAAC,SAAS,CAAC,UAAC,MAAW,CAAC,kBAAkB;QAC9C,MAAM,CAAC,YAAY,CAAC,UAAC,EAAO;YAC1B,EAAE,CAAC,OAAO,CAAC,UAAC,GAAQ,EAAE,EAAO;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IAAM,UAAU,GACd,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,2BAAe,CAAC,CAAC;QAC5G,OAAO,UAAU,CAAC,CAAC,CAAC,kBAAkB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC7E,CAAC,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;GAEG;AACH,SAAS,kBAAkB,CAAC,QAAgB,EAAE,SAAiB;IAC7D,IAAM,gBAAgB,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACrD,IAAM,iBAAiB,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAEvD,IAAM,aAAa,GAAG,IAAI,MAAM,CAAC,WAAI,gBAAgB,MAAG,CAAC,CAAC;IAC1D,IAAM,cAAc,GAAG,IAAI,MAAM,CAAC,WAAI,iBAAiB,MAAG,CAAC,CAAC;IAE5D,IAAM,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAElF,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -1,10 +1,28 @@
1
- export interface ReqUser {
1
+ export type Activities = {
2
+ [activity: string]: boolean;
3
+ };
4
+ export declare class ReqUser {
2
5
  userId: string;
3
- activities: Record<string, boolean>;
6
+ activities: Activities;
4
7
  /** The organization id of the user */
5
8
  organizationId: string;
6
- /** Child organizations withing the organization hierarchy */
7
- childOrganizationIds: string[];
8
9
  /** The user account currently active for this login */
9
10
  activeLogin: string;
11
+ /** The hierarchy of the user's current organization */
12
+ organizationHierarchy: Record<string, string | null>;
13
+ constructor({ userId, organizationId, activities, activeLogin, organizationHierarchy, }: {
14
+ userId: typeof ReqUser.prototype.userId;
15
+ organizationId: typeof ReqUser.prototype.organizationId;
16
+ activities: typeof ReqUser.prototype.activities;
17
+ activeLogin: typeof ReqUser.prototype.activeLogin;
18
+ organizationHierarchy: typeof ReqUser.prototype.organizationHierarchy;
19
+ });
20
+ /**
21
+ * Returns the organizationIds in the hierarchy of the inputted organizationId
22
+ * Input must be inside the user's organization hierarchy.
23
+ * If no organization is inputted, it returns the ids in the user's organization hierarchy.
24
+ *
25
+ * @param organizationId The organizationId to get the children of
26
+ */
27
+ getOrganizationTreeIds(organizationId?: string): string[];
10
28
  }
@@ -1,3 +1,49 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReqUser = void 0;
4
+ var ReqUser = /** @class */ (function () {
5
+ function ReqUser(_a) {
6
+ var userId = _a.userId, organizationId = _a.organizationId, activities = _a.activities, activeLogin = _a.activeLogin, organizationHierarchy = _a.organizationHierarchy;
7
+ this.userId = userId;
8
+ this.organizationId = organizationId;
9
+ this.activities = activities;
10
+ this.activeLogin = activeLogin;
11
+ this.organizationHierarchy = organizationHierarchy;
12
+ }
13
+ /**
14
+ * Returns the organizationIds in the hierarchy of the inputted organizationId
15
+ * Input must be inside the user's organization hierarchy.
16
+ * If no organization is inputted, it returns the ids in the user's organization hierarchy.
17
+ *
18
+ * @param organizationId The organizationId to get the children of
19
+ */
20
+ ReqUser.prototype.getOrganizationTreeIds = function (organizationId) {
21
+ var stack = [];
22
+ var visited = new Set();
23
+ var result = [];
24
+ if (!organizationId || organizationId === this.organizationId) {
25
+ stack.push(this.organizationId);
26
+ }
27
+ else {
28
+ stack.push(organizationId);
29
+ }
30
+ while (stack.length > 0) {
31
+ var currentOrgId = stack.pop();
32
+ if (visited.has(currentOrgId)) {
33
+ continue;
34
+ }
35
+ visited.add(currentOrgId);
36
+ result.push(currentOrgId);
37
+ for (var _i = 0, _a = Object.entries(this.organizationHierarchy); _i < _a.length; _i++) {
38
+ var _b = _a[_i], childId = _b[0], parentId = _b[1];
39
+ if (parentId === currentOrgId && !visited.has(childId)) {
40
+ stack.push(childId);
41
+ }
42
+ }
43
+ }
44
+ return result;
45
+ };
46
+ return ReqUser;
47
+ }());
48
+ exports.ReqUser = ReqUser;
3
49
  //# sourceMappingURL=ReqUser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ReqUser.js","sourceRoot":"","sources":["ReqUser.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"ReqUser.js","sourceRoot":"","sources":["ReqUser.ts"],"names":[],"mappings":";;;AAEA;IAaE,iBAAY,EAYX;YAXC,MAAM,YAAA,EACN,cAAc,oBAAA,EACd,UAAU,gBAAA,EACV,WAAW,iBAAA,EACX,qBAAqB,2BAAA;QAQrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;IACrD,CAAC;IAED;;;;;;OAMG;IACI,wCAAsB,GAA7B,UAA8B,cAAuB;QACnD,IAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,IAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;QAClC,IAAM,MAAM,GAAa,EAAE,CAAC;QAE5B,IAAI,CAAC,cAAc,IAAI,cAAc,KAAK,IAAI,CAAC,cAAc,EAAE,CAAC;YAC9D,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAClC,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC7B,CAAC;QAED,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,IAAM,YAAY,GAAG,KAAK,CAAC,GAAG,EAAG,CAAC;YAElC,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC9B,SAAS;YACX,CAAC;YAED,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YAC1B,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAE1B,KAAkC,UAA0C,EAA1C,KAAA,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,qBAAqB,CAAC,EAA1C,cAA0C,EAA1C,IAA0C,EAAE,CAAC;gBAApE,IAAA,WAAmB,EAAlB,OAAO,QAAA,EAAE,QAAQ,QAAA;gBAC3B,IAAI,QAAQ,KAAK,YAAY,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;oBACvD,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACtB,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IACH,cAAC;AAAD,CAAC,AAtED,IAsEC;AAtEY,0BAAO"}
@@ -37,6 +37,7 @@ exports.runWithRequestContext = runWithRequestContext;
37
37
  exports.useReqStore = useReqStore;
38
38
  var constants_1 = require("../../constants");
39
39
  var async_hooks_1 = require("async_hooks");
40
+ var ReqUser_1 = require("../models/ReqUser");
40
41
  var uuid = __importStar(require("uuid"));
41
42
  function isRequest(reqContext) {
42
43
  return typeof reqContext !== "string";
@@ -82,11 +83,12 @@ function getFallbackUser(req) {
82
83
  var activeLogin = req.header(constants_1.AUTH_ACTIVE_LOGIN_HEADER);
83
84
  var activities = req.header(constants_1.AUTH_ACTIVITIES_HEADER);
84
85
  var organizationId = req.header(constants_1.AUTH_ORGANIZATION_HEADER);
86
+ var organizationHierarchy = JSON.parse(req.header(constants_1.AUTH_ORGANIZATION_HIERARCHY_HEADER, "{}"));
85
87
  /* Make sure we don't create a user from thin air */
86
- if (!userId && !activeLogin && !activities && !organizationId) {
88
+ if (!userId && !activeLogin && !activities && !organizationId && !organizationHierarchy) {
87
89
  return undefined;
88
90
  }
89
- return {
91
+ return new ReqUser_1.ReqUser({
90
92
  userId: userId,
91
93
  activeLogin: activeLogin,
92
94
  activities: activities === null || activities === void 0 ? void 0 : activities.split(",").reduce(function (acc, activity) {
@@ -94,6 +96,7 @@ function getFallbackUser(req) {
94
96
  return acc;
95
97
  }, {}),
96
98
  organizationId: organizationId,
97
- };
99
+ organizationHierarchy: organizationHierarchy,
100
+ });
98
101
  }
99
102
  //# sourceMappingURL=asyncHooks.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"asyncHooks.js","sourceRoot":"","sources":["asyncHooks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,sDAoBC;AAGD,kCAEC;AApED,6CAMyB;AACzB,2CAAgD;AAGhD,yCAA6B;AAoB7B,SAAS,SAAS,CAAC,UAA0B;IAC3C,OAAO,OAAO,UAAU,KAAK,QAAQ,CAAC;AACxC,CAAC;AAED,IAAM,iBAAiB,GAAG,IAAI,+BAAiB,EAAgB,CAAC;AAEhE;;;;;;GAMG;AACH,SAAgB,qBAAqB,CAAC,UAA0B,EAAE,EAAc;;IAC9E,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,IAAI,IAAI,GAAwB,SAAS,CAAC;IAE1C,IAAI,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1B,KAAK,GAAG,MAAA,MAAA,MAAA,UAAU,CAAC,MAAM,2DAAG,6BAAiB,CAAC,mCAAI,UAAU,CAAC,KAAK,EAAE,mCAAI,IAAI,CAAC,EAAE,EAAE,CAAC;QAClF,IAAI,GAAG,MAAA,UAAU,CAAC,IAAI,mCAAI,eAAe,CAAC,UAAU,CAAC,CAAC;IACxD,CAAC;SAAM,CAAC;QACN,KAAK,GAAG,UAAU,CAAC;IACrB,CAAC;IAED,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QACjC,iBAAiB,CAAC,GAAG,CAAC,EAAE,KAAK,OAAA,EAAE,IAAI,MAAA,EAAE,EAAE;YACrC,IAAI,CAAC;g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AAM,WAAW,GAAG,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,CAAC,UAAC,GAAG,EAAE,QAAQ;YACtD,GAAG,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;YACrB,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAA6B,CAAC;QACjC,cAAc,gBAAA;QACd,qBAAqB,uBAAA;KACtB,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@pgds/api-interface",
3
3
  "description": "Api interface for pgds services",
4
4
  "authors": "Florry",
5
- "version": "1.2.6",
5
+ "version": "1.3.0",
6
6
  "main": "index.js",
7
7
  "types": "types/",
8
8
  "scripts": {
@@ -100,4 +100,4 @@
100
100
  "**/*.js.map"
101
101
  ]
102
102
  }
103
- }
103
+ }
package/utils/index.d.ts CHANGED
@@ -11,3 +11,9 @@ export declare function isGlobal(reqUser: ReqUser): boolean;
11
11
  * Short hand function to check if a user has the `canManageOrganization`(`CAN_MANAGE_ORGANIZATION_ACTIVITY`) activity.
12
12
  */
13
13
  export declare function canManageOrganization(reqUser: ReqUser): boolean;
14
+ /**
15
+ * Short hand function to check if a user has access to an organization. Organization must be in the user's hierarchy to be accessible.
16
+ * @param reqUser The user to check.
17
+ * @param organizationId The organizationId to check for access to.
18
+ */
19
+ export declare function isOrganizationAccessibleToUser(reqUser: ReqUser, organizationId: string): boolean;
package/utils/index.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hasActivity = hasActivity;
4
4
  exports.isGlobal = isGlobal;
5
5
  exports.canManageOrganization = canManageOrganization;
6
+ exports.isOrganizationAccessibleToUser = isOrganizationAccessibleToUser;
6
7
  var constants_1 = require("../constants");
7
8
  var mustbeConfig_1 = require("../lib/auth/mustbeConfig");
8
9
  /**
@@ -29,4 +30,12 @@ function isGlobal(reqUser) {
29
30
  function canManageOrganization(reqUser) {
30
31
  return hasActivity(reqUser, constants_1.CAN_MANAGE_ORGANIZATION_ACTIVITY);
31
32
  }
33
+ /**
34
+ * Short hand function to check if a user has access to an organization. Organization must be in the user's hierarchy to be accessible.
35
+ * @param reqUser The user to check.
36
+ * @param organizationId The organizationId to check for access to.
37
+ */
38
+ function isOrganizationAccessibleToUser(reqUser, organizationId) {
39
+ return reqUser.getOrganizationTreeIds().includes(organizationId);
40
+ }
32
41
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AAUA,kCAMC;AAED,4BAEC;AAKD,sDAEC;AA3BD,0CAAiF;AACjF,yDAA4D;AAG5D;;;;;GAKG;AACH,SAAgB,WAAW,CAAC,OAAgB,EAAE,QAAgB,EAAE,aAA6B;IAA7B,8BAAA,EAAA,oBAA6B;IAC3F,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,IAAA,+BAAgB,EAAC,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IACxD,CAAC;SAAM,CAAC;QACN,OAAO,QAAQ,CAAC,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+0,0 @@
1
- import { setupApiInterface, JsonResponse, del, endpointMetadata, get, getRouteHelpers, head, options, patch, post, put, internal, Method } from "./lib";
2
- import { Next, Request, Response } from "./lib/models/Http";
3
- import { User } from "./lib/models/User";
4
- export { endpointMetadata, del, get, getRouteHelpers, head, options, patch, post, put, internal, setupApiInterface, JsonResponse, Request, Response, Next, Method, User, };
@@ -1,2 +0,0 @@
1
- export declare const CI: boolean;
2
- export declare const SCHEMA_BASE_PATH = "api/schemas";
@@ -1,188 +0,0 @@
1
- /// <reference path="../../types/hiot.d.ts" />
2
- /// <reference types="node" />
3
- import fs from "fs";
4
- import App, { Locator } from "hiot";
5
- import { RouteOptions } from "restify";
6
- import { Next, Request, Response } from "./models/Http";
7
- export declare const readDirAsync: typeof fs.readdir.__promisify__;
8
- export declare enum Method {
9
- Post = "post",
10
- Get = "get",
11
- Put = "put",
12
- Patch = "patch",
13
- Del = "del",
14
- Head = "head",
15
- Options = "options"
16
- }
17
- type OmittedFields = "internal" | "method";
18
- export declare function get(options: Omit<EndpointOptions, OmittedFields>): {
19
- (api: App): void;
20
- /**
21
- * Makes it possible to access the requestHandler through the exported function.
22
- * If you need to test the function separately, without starting the server
23
- */
24
- requestHandler: (req: Request<any, any>, res?: Response<any> | undefined, next?: Next | undefined) => Promise<void | JsonResponse<any>>;
25
- /** Endpoint's full path (including any version number and internal prefix) */
26
- PATH: string;
27
- };
28
- export declare function post(options: Omit<EndpointOptions, OmittedFields>): {
29
- (api: App): void;
30
- /**
31
- * Makes it possible to access the requestHandler through the exported function.
32
- * If you need to test the function separately, without starting the server
33
- */
34
- requestHandler: (req: Request<any, any>, res?: Response<any> | undefined, next?: Next | undefined) => Promise<void | JsonResponse<any>>;
35
- /** Endpoint's full path (including any version number and internal prefix) */
36
- PATH: string;
37
- };
38
- export declare function put(options: Omit<EndpointOptions, OmittedFields>): {
39
- (api: App): void;
40
- /**
41
- * Makes it possible to access the requestHandler through the exported function.
42
- * If you need to test the function separately, without starting the server
43
- */
44
- requestHandler: (req: Request<any, any>, res?: Response<any> | undefined, next?: Next | undefined) => Promise<void | JsonResponse<any>>;
45
- /** Endpoint's full path (including any version number and internal prefix) */
46
- PATH: string;
47
- };
48
- export declare function patch(options: Omit<EndpointOptions, OmittedFields>): {
49
- (api: App): void;
50
- /**
51
- * Makes it possible to access the requestHandler through the exported function.
52
- * If you need to test the function separately, without starting the server
53
- */
54
- requestHandler: (req: Request<any, any>, res?: Response<any> | undefined, next?: Next | undefined) => Promise<void | JsonResponse<any>>;
55
- /** Endpoint's full path (including any version number and internal prefix) */
56
- PATH: string;
57
- };
58
- export declare function del(options: Omit<EndpointOptions, OmittedFields>): {
59
- (api: App): void;
60
- /**
61
- * Makes it possible to access the requestHandler through the exported function.
62
- * If you need to test the function separately, without starting the server
63
- */
64
- requestHandler: (req: Request<any, any>, res?: Response<any> | undefined, next?: Next | undefined) => Promise<void | JsonResponse<any>>;
65
- /** Endpoint's full path (including any version number and internal prefix) */
66
- PATH: string;
67
- };
68
- export declare function head(options: Omit<EndpointOptions, OmittedFields>): {
69
- (api: App): void;
70
- /**
71
- * Makes it possible to access the requestHandler through the exported function.
72
- * If you need to test the function separately, without starting the server
73
- */
74
- requestHandler: (req: Request<any, any>, res?: Response<any> | undefined, next?: Next | undefined) => Promise<void | JsonResponse<any>>;
75
- /** Endpoint's full path (including any version number and internal prefix) */
76
- PATH: string;
77
- };
78
- export declare function options(options: Omit<EndpointOptions, OmittedFields>): {
79
- (api: App): void;
80
- /**
81
- * Makes it possible to access the requestHandler through the exported function.
82
- * If you need to test the function separately, without starting the server
83
- */
84
- requestHandler: (req: Request<any, any>, res?: Response<any> | undefined, next?: Next | undefined) => Promise<void | JsonResponse<any>>;
85
- /** Endpoint's full path (including any version number and internal prefix) */
86
- PATH: string;
87
- };
88
- /** Internal endpoints are not available through the API */
89
- export declare function internal(options: Omit<EndpointOptions, "internal">): {
90
- (api: App): void;
91
- /**
92
- * Makes it possible to access the requestHandler through the exported function.
93
- * If you need to test the function separately, without starting the server
94
- */
95
- requestHandler: (req: Request<any, any>, res?: Response<any> | undefined, next?: Next | undefined) => Promise<void | JsonResponse<any>>;
96
- /** Endpoint's full path (including any version number and internal prefix) */
97
- PATH: string;
98
- };
99
- export interface JsonResponse<T> {
100
- /** Response body */
101
- body?: T;
102
- /** HTTP status code. @default 200 */
103
- status?: number;
104
- /** Additional headers */
105
- headers?: {
106
- totalcount?: number;
107
- [key: string]: any;
108
- };
109
- }
110
- export { Next, Request, Response };
111
- export interface EndpointOptions {
112
- /** Whether to add the endpoint to the metadata or not. @default true */
113
- addToMetadata?: boolean;
114
- /** Whether the endpoint is internal or not */
115
- internal?: boolean;
116
- /** The path to the endpoint */
117
- path: string;
118
- /** The activity that is required to access this endpoint */
119
- authorized?: string;
120
- /** Whether you need to be logged in or not to access the endpoint. Only needed if authorized is not used. */
121
- authenticated?: boolean;
122
- /** HTTP method */
123
- method: Method;
124
- /**
125
- * The request schema, either a JSON schema or the name of a typescript type
126
- * (See below. The name must match the name of the file in ./api/schemas).
127
- **/
128
- requestSchema?: object | string;
129
- /** Additional route options */
130
- opts?: RouteOptions;
131
- /** prefix for the path, e.g. /v1, defaults to what was set in setupApiInterface */
132
- version?: string;
133
- /** The documentation for the endpoint */
134
- documentation?: {
135
- /** Short description of the endpoint */
136
- summary: string;
137
- /** Long description of the endpoint */
138
- description?: string;
139
- /** Optional array of tags */
140
- tags?: string[];
141
- /**
142
- * Optional description for query params (can also be defined and described in the json schema,
143
- * since that's how we validate them)
144
- **/
145
- query?: Record<string, string>;
146
- /**
147
- * Optional description of url parameters.
148
- * Usually unnecessary since url params should be self descriptive, e.g. /dashboards/:dashboardId
149
- **/
150
- parameters?: Record<string, string>;
151
- /** Response schemas */
152
- responses?: {
153
- /** HTTP status code */
154
- status: number;
155
- /** An optional description of the response */
156
- description?: string;
157
- /**
158
- * An optional response schema, either a JSON schema or the name of a typescript type
159
- * (See below. The name must match the name of the file in ./api/schemas).
160
- **/
161
- schema?: any | any[];
162
- }[];
163
- };
164
- /** The request handler function */
165
- requestHandler: (req: Request<any>, res?: Response<any>, next?: Next) => Promise<JsonResponse<any> | void>;
166
- }
167
- export type EndpointMetadata = Omit<EndpointOptions, "requestHandler" | "opts">;
168
- export declare const endpointMetadata: {
169
- [key in Method]: Record<string, EndpointMetadata>;
170
- };
171
- export declare function getRouteHelpers(): {
172
- authenticated: () => App.RequestHandlerType;
173
- authorized: (activity: string) => App.RequestHandlerType;
174
- };
175
- export interface ApiInterfaceOptions {
176
- /** Name of the service */
177
- serviceName: string;
178
- /** Default log level for the service */
179
- serviceLogLevel: string;
180
- /** Whether to use typescript or not */
181
- typescript: boolean;
182
- /** Global version of the API @default v1. Can be overridden per endpoint */
183
- apiVersion: string;
184
- /** The base path to the schemas. @default api/schemas */
185
- schemaBasePath?: string;
186
- }
187
- export declare function getApiOptions(): ApiInterfaceOptions;
188
- export declare function setupApiInterface(options: ApiInterfaceOptions): (locator: Locator) => Promise<App.Locator>;
@@ -1,61 +0,0 @@
1
- import { User } from "./User";
2
- import { Request as RestifyRequest, Response as RestifyResponse, Next as RestifyNext } from "restify";
3
- export interface Request<BodyParams = Record<string, any>, QueryParams = any> extends RestifyRequest {
4
- params: BodyParams;
5
- user: User;
6
- query: QueryParams;
7
- }
8
- export interface Next extends RestifyNext {
9
- (err?: any): void;
10
- }
11
- export interface Response<Body = Record<string, any>> extends RestifyResponse {
12
- /**
13
- * short hand method for:
14
- * res.contentType = 'json';
15
- * res.send({hello: 'world'});
16
- * @param code http status code
17
- * @param body value to json.stringify
18
- * @param [headers] headers to set on the response
19
- */
20
- json(code: number, body: Body, headers?: {
21
- [header: string]: string;
22
- }): any;
23
- /**
24
- * short hand method for:
25
- * res.contentType = 'json';
26
- * res.send({hello: 'world'});
27
- * @param code http status code
28
- */
29
- json(code: number): any;
30
- /**
31
- * short hand method for:
32
- * res.contentType = 'json';
33
- * res.send({hello: 'world'});
34
- * @param body value to json.stringify
35
- * @param [headers] headers to set on the response
36
- */
37
- json(body: Body, headers?: {
38
- [header: string]: string;
39
- }): any;
40
- /**
41
- * sends the response object. pass through to internal __send that uses a
42
- * formatter based on the content-type header.
43
- * @param [code] http status code
44
- * @param [body] the content to send
45
- * @param [headers] any add'l headers to set
46
- * @returns the response object
47
- */
48
- send(code?: number, body?: Body, headers?: {
49
- [header: string]: string;
50
- }): any;
51
- /**
52
- * sends the response object. pass through to internal __send that uses a
53
- * formatter based on the content-type header.
54
- * @param [body] the content to send
55
- * @param [headers] any add'l headers to set
56
- * @returns the response object
57
- */
58
- send(body?: Body, headers?: {
59
- [header: string]: string;
60
- }): any;
61
- }
@@ -1,8 +0,0 @@
1
- export interface User {
2
- userId: string;
3
- name: string;
4
- cellPhones: string | string[];
5
- status: string;
6
- activities: Record<string, string>;
7
- organizationId: string;
8
- }
@@ -1,7 +0,0 @@
1
- import { EndpointOptions } from "..";
2
- /** Speeds up loading schemas when testing by only loading the schemas once instead of once per test file */
3
- export declare const schemaCache: Map<string, object>;
4
- export declare function getSchemas(schemaNames: string[]): void;
5
- export declare function getSchema(schemaName: string): object | undefined;
6
- export declare function prepareResponseSchemas(options: EndpointOptions): object[];
7
- export declare function validateResponseBody(schemas: object[], body: object): void;
@@ -1,4 +0,0 @@
1
- import bunyan from "bunyan";
2
- export declare function setupLogger(inServiceName: string, inServiceLogLevel: string): void;
3
- declare const _default: bunyan;
4
- export default _default;
@@ -1,2 +0,0 @@
1
- import { EndpointMetadata, EndpointOptions } from "..";
2
- export declare function prepareMetadata(options: EndpointOptions, metadata: EndpointMetadata): EndpointMetadata;
@@ -1 +0,0 @@
1
- export declare function route(version: string, path: string, internal?: boolean): string;