@eduzz/miau-client 0.0.19 → 0.0.21

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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @eduzz/miau-client@0.0.19 build:types /home/runner/work/eduzz-miau/eduzz-miau/packages/client
2
+ > @eduzz/miau-client@0.0.21 build:types /home/runner/work/eduzz-miau/eduzz-miau/packages/client
3
3
  > tsc --emitDeclarationOnly --outDir dist
4
4
 
@@ -1,4 +1,4 @@
1
1
 
2
- > @eduzz/miau-client@0.0.19 prepublish /home/runner/work/eduzz-miau/eduzz-miau/packages/client
2
+ > @eduzz/miau-client@0.0.21 prepublish /home/runner/work/eduzz-miau/eduzz-miau/packages/client
3
3
  > sh ./scripts/prepare-publish.sh
4
4
 
@@ -1,21 +1,20 @@
1
1
  import { type RequestHandler } from 'express';
2
- import { type Permission } from '@eduzz/miau-types';
2
+ import { type SecretEnv, type Permission } from '@eduzz/miau-types';
3
3
  import { type RequestAugmentation } from './middleware';
4
4
  type MiauClientConfig = {
5
5
  apiUrl: string;
6
6
  appSecret: string;
7
- environment: string;
7
+ environment: SecretEnv;
8
8
  };
9
9
  export declare class MiauClient {
10
- private apiUrl;
11
- private environment;
10
+ private config;
12
11
  private jwtToken;
13
12
  private jwksClient;
14
13
  private basicAuthToken;
15
14
  private permissionsCache;
16
15
  private permissionsRequests;
17
16
  constructor(config: MiauClientConfig);
18
- getEnvironment(): string;
17
+ getEnvironment(): SecretEnv;
19
18
  getPublicKey(kid: string): Promise<string>;
20
19
  getToken(): Promise<string | undefined>;
21
20
  middleware<T = Record<string, string>>(config?: {
package/dist/index.js CHANGED
@@ -11715,14 +11715,148 @@ var index_exports = {};
11715
11715
  __export(index_exports, {
11716
11716
  HttpMethods: () => HttpMethods,
11717
11717
  MiauClient: () => MiauClient,
11718
- ResourceProtocols: () => ResourceProtocols
11718
+ ResourceProtocols: () => ResourceProtocols,
11719
+ SecretEnvValues: () => SecretEnvValues,
11720
+ UserPermissions: () => UserPermissions,
11721
+ envMap: () => envMap,
11722
+ expirationOptions: () => expirationOptions,
11723
+ expirationOptionsValues: () => expirationOptionsValues,
11724
+ expirationTimeToDate: () => expirationTimeToDate,
11725
+ networks: () => networks
11719
11726
  });
11720
11727
  module.exports = __toCommonJS(index_exports);
11721
11728
 
11722
11729
  // ../types/src/types/Resource.ts
11723
- var ResourceProtocols = ["http", "websocket", "grpc"];
11730
+ var ResourceProtocols = ["http"];
11724
11731
  var HttpMethods = ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"];
11725
11732
 
11733
+ // ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/constants.js
11734
+ var daysInYear = 365.2425;
11735
+ var maxTime = Math.pow(10, 8) * 24 * 60 * 60 * 1e3;
11736
+ var minTime = -maxTime;
11737
+ var millisecondsInHour = 36e5;
11738
+ var secondsInHour = 3600;
11739
+ var secondsInDay = secondsInHour * 24;
11740
+ var secondsInWeek = secondsInDay * 7;
11741
+ var secondsInYear = secondsInDay * daysInYear;
11742
+ var secondsInMonth = secondsInYear / 12;
11743
+ var secondsInQuarter = secondsInMonth * 3;
11744
+ var constructFromSymbol = Symbol.for("constructDateFrom");
11745
+
11746
+ // ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/constructFrom.js
11747
+ function constructFrom(date, value) {
11748
+ if (typeof date === "function") return date(value);
11749
+ if (date && typeof date === "object" && constructFromSymbol in date)
11750
+ return date[constructFromSymbol](value);
11751
+ if (date instanceof Date) return new date.constructor(value);
11752
+ return new Date(value);
11753
+ }
11754
+
11755
+ // ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/toDate.js
11756
+ function toDate(argument, context) {
11757
+ return constructFrom(context || argument, argument);
11758
+ }
11759
+
11760
+ // ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/addDays.js
11761
+ function addDays(date, amount, options) {
11762
+ const _date = toDate(date, options?.in);
11763
+ if (isNaN(amount)) return constructFrom(options?.in || date, NaN);
11764
+ if (!amount) return _date;
11765
+ _date.setDate(_date.getDate() + amount);
11766
+ return _date;
11767
+ }
11768
+
11769
+ // ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/addMilliseconds.js
11770
+ function addMilliseconds(date, amount, options) {
11771
+ return constructFrom(options?.in || date, +toDate(date) + amount);
11772
+ }
11773
+
11774
+ // ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/addHours.js
11775
+ function addHours(date, amount, options) {
11776
+ return addMilliseconds(date, amount * millisecondsInHour, options);
11777
+ }
11778
+
11779
+ // ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/addMonths.js
11780
+ function addMonths(date, amount, options) {
11781
+ const _date = toDate(date, options?.in);
11782
+ if (isNaN(amount)) return constructFrom(options?.in || date, NaN);
11783
+ if (!amount) {
11784
+ return _date;
11785
+ }
11786
+ const dayOfMonth = _date.getDate();
11787
+ const endOfDesiredMonth = constructFrom(options?.in || date, _date.getTime());
11788
+ endOfDesiredMonth.setMonth(_date.getMonth() + amount + 1, 0);
11789
+ const daysInMonth = endOfDesiredMonth.getDate();
11790
+ if (dayOfMonth >= daysInMonth) {
11791
+ return endOfDesiredMonth;
11792
+ } else {
11793
+ _date.setFullYear(
11794
+ endOfDesiredMonth.getFullYear(),
11795
+ endOfDesiredMonth.getMonth(),
11796
+ dayOfMonth
11797
+ );
11798
+ return _date;
11799
+ }
11800
+ }
11801
+
11802
+ // ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/addYears.js
11803
+ function addYears(date, amount, options) {
11804
+ return addMonths(date, amount * 12, options);
11805
+ }
11806
+
11807
+ // ../types/src/types/Secret.ts
11808
+ var expirationOptions = {
11809
+ "Forever": "forever",
11810
+ "One hour": "oneHour",
11811
+ "Six hours": "sixHours",
11812
+ "Twelve hours": "twelveHours",
11813
+ "One day": "oneDay",
11814
+ "One week": "sevenDays",
11815
+ "One month": "oneMonth",
11816
+ "Six months": "sixMonths",
11817
+ "One year": "oneYear"
11818
+ };
11819
+ var expirationOptionsValues = Object.values(expirationOptions);
11820
+ var conversionMap = {
11821
+ forever: () => void 0,
11822
+ oneHour: () => addHours(/* @__PURE__ */ new Date(), 1),
11823
+ sixHours: () => addHours(/* @__PURE__ */ new Date(), 6),
11824
+ twelveHours: () => addHours(/* @__PURE__ */ new Date(), 12),
11825
+ oneDay: () => addDays(/* @__PURE__ */ new Date(), 1),
11826
+ sevenDays: () => addDays(/* @__PURE__ */ new Date(), 7),
11827
+ oneMonth: () => addMonths(/* @__PURE__ */ new Date(), 1),
11828
+ sixMonths: () => addMonths(/* @__PURE__ */ new Date(), 6),
11829
+ oneYear: () => addYears(/* @__PURE__ */ new Date(), 1)
11830
+ };
11831
+ var expirationTimeToDate = (option) => {
11832
+ return conversionMap[option]() ?? void 0;
11833
+ };
11834
+
11835
+ // ../types/src/types/Environments.ts
11836
+ var networks = {
11837
+ development: "10.11.0.0/16",
11838
+ test: "10.201.0.0/16",
11839
+ production: "10.150.0.0/16"
11840
+ };
11841
+ var SecretEnvValues = ["development", "test", "production"];
11842
+ var envMap = {
11843
+ development: "d",
11844
+ test: "q",
11845
+ production: "p"
11846
+ };
11847
+
11848
+ // ../types/src/types/User.ts
11849
+ var UserPermissions = {
11850
+ admin: "Administrator",
11851
+ manageApplications: "Manage Applications",
11852
+ deleteApplications: "Delete Applications",
11853
+ managePermissions: "Manage Permissions",
11854
+ manageResources: "Manage Resources",
11855
+ manageMetadata: "Manage Metadata",
11856
+ createSecrets: "Create Secrets",
11857
+ deleteSecrets: "Delete Secrets"
11858
+ };
11859
+
11726
11860
  // src/MiauClient.ts
11727
11861
  var import_node_crypto = __toESM(require("node:crypto"));
11728
11862
  var import_jsonwebtoken2 = __toESM(require_jsonwebtoken());
@@ -11780,7 +11914,8 @@ var miauMiddleware = (miauClient, requestAugmentation, fallbackMidlleware) => {
11780
11914
  throw new HttpError(403, "Forbidden", `You do not have permission to access ${req.method} ${req.path}`);
11781
11915
  }
11782
11916
  req.miauApplication = { id: application.id, name: application.name };
11783
- req.miauMetadata = permission?.metadata || {};
11917
+ const environment = miauClient.getEnvironment();
11918
+ req.miauMetadata = permission?.metadata?.[environment] || {};
11784
11919
  if (requestAugmentation) {
11785
11920
  requestAugmentation({ req, app: req.miauApplication, meta: req.miauMetadata });
11786
11921
  }
@@ -11814,22 +11949,27 @@ var MiauClient = class {
11814
11949
  this.permissionsCache = /* @__PURE__ */ new Map();
11815
11950
  this.permissionsRequests = /* @__PURE__ */ new Map();
11816
11951
  this.getApiJwtUrl = () => {
11817
- return `${this.apiUrl}/v1/jwt`;
11952
+ return `${this.config.apiUrl}/v1/jwt`;
11818
11953
  };
11819
11954
  this.getPermissionsUrl = () => {
11820
- return `${this.apiUrl}/v1/permissions`;
11955
+ return `${this.config.apiUrl}/v1/permissions`;
11821
11956
  };
11822
11957
  this.getJwksUrl = () => {
11823
- return `${this.apiUrl}/v1/jwks.json`;
11958
+ return `${this.config.apiUrl}/v1/jwks.json`;
11824
11959
  };
11825
- this.apiUrl = config.apiUrl;
11826
- this.environment = config.environment;
11960
+ if (!config.apiUrl || !config.appSecret || !config.environment) {
11961
+ throw new Error("Invalid MiauClient configuration. Please provide apiUrl, appSecret, and environment.");
11962
+ }
11963
+ if (!SecretEnvValues.includes(config.environment)) {
11964
+ throw new Error(`Invalid environment: ${config.environment}. Must be one of ${SecretEnvValues.join(", ")}`);
11965
+ }
11966
+ this.config = config;
11827
11967
  const apiKey = config.appSecret.substring(7, 32);
11828
11968
  const hashedSecret = import_node_crypto.default.createHash("sha256").update(config.appSecret).digest("hex");
11829
11969
  this.basicAuthToken = Buffer.from(`${apiKey}:${hashedSecret}`).toString("base64");
11830
11970
  }
11831
11971
  getEnvironment() {
11832
- return this.environment;
11972
+ return this.config.environment;
11833
11973
  }
11834
11974
  async getPublicKey(kid) {
11835
11975
  if (!this.jwksClient) {
@@ -11897,7 +12037,14 @@ var MiauClient = class {
11897
12037
  0 && (module.exports = {
11898
12038
  HttpMethods,
11899
12039
  MiauClient,
11900
- ResourceProtocols
12040
+ ResourceProtocols,
12041
+ SecretEnvValues,
12042
+ UserPermissions,
12043
+ envMap,
12044
+ expirationOptions,
12045
+ expirationOptionsValues,
12046
+ expirationTimeToDate,
12047
+ networks
11901
12048
  });
11902
12049
  /*! Bundled license information:
11903
12050