@eduzz/miau-client 0.0.19 → 0.0.20

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.20 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.20 prepublish /home/runner/work/eduzz-miau/eduzz-miau/packages/client
3
3
  > sh ./scripts/prepare-publish.sh
4
4
 
@@ -1,10 +1,10 @@
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
10
  private apiUrl;
@@ -15,7 +15,7 @@ export declare class MiauClient {
15
15
  private permissionsCache;
16
16
  private permissionsRequests;
17
17
  constructor(config: MiauClientConfig);
18
- getEnvironment(): string;
18
+ getEnvironment(): SecretEnv;
19
19
  getPublicKey(kid: string): Promise<string>;
20
20
  getToken(): Promise<string | undefined>;
21
21
  middleware<T = Record<string, string>>(config?: {
package/dist/index.js CHANGED
@@ -11715,14 +11715,133 @@ var index_exports = {};
11715
11715
  __export(index_exports, {
11716
11716
  HttpMethods: () => HttpMethods,
11717
11717
  MiauClient: () => MiauClient,
11718
- ResourceProtocols: () => ResourceProtocols
11718
+ ResourceProtocols: () => ResourceProtocols,
11719
+ envMap: () => envMap,
11720
+ envs: () => envs,
11721
+ expirationOptions: () => expirationOptions,
11722
+ expirationOptionsValues: () => expirationOptionsValues,
11723
+ expirationTimeToDate: () => expirationTimeToDate
11719
11724
  });
11720
11725
  module.exports = __toCommonJS(index_exports);
11721
11726
 
11722
11727
  // ../types/src/types/Resource.ts
11723
- var ResourceProtocols = ["http", "websocket", "grpc"];
11728
+ var ResourceProtocols = ["http"];
11724
11729
  var HttpMethods = ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"];
11725
11730
 
11731
+ // ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/constants.js
11732
+ var daysInYear = 365.2425;
11733
+ var maxTime = Math.pow(10, 8) * 24 * 60 * 60 * 1e3;
11734
+ var minTime = -maxTime;
11735
+ var millisecondsInHour = 36e5;
11736
+ var secondsInHour = 3600;
11737
+ var secondsInDay = secondsInHour * 24;
11738
+ var secondsInWeek = secondsInDay * 7;
11739
+ var secondsInYear = secondsInDay * daysInYear;
11740
+ var secondsInMonth = secondsInYear / 12;
11741
+ var secondsInQuarter = secondsInMonth * 3;
11742
+ var constructFromSymbol = Symbol.for("constructDateFrom");
11743
+
11744
+ // ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/constructFrom.js
11745
+ function constructFrom(date, value) {
11746
+ if (typeof date === "function") return date(value);
11747
+ if (date && typeof date === "object" && constructFromSymbol in date)
11748
+ return date[constructFromSymbol](value);
11749
+ if (date instanceof Date) return new date.constructor(value);
11750
+ return new Date(value);
11751
+ }
11752
+
11753
+ // ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/toDate.js
11754
+ function toDate(argument, context) {
11755
+ return constructFrom(context || argument, argument);
11756
+ }
11757
+
11758
+ // ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/addDays.js
11759
+ function addDays(date, amount, options) {
11760
+ const _date = toDate(date, options?.in);
11761
+ if (isNaN(amount)) return constructFrom(options?.in || date, NaN);
11762
+ if (!amount) return _date;
11763
+ _date.setDate(_date.getDate() + amount);
11764
+ return _date;
11765
+ }
11766
+
11767
+ // ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/addMilliseconds.js
11768
+ function addMilliseconds(date, amount, options) {
11769
+ return constructFrom(options?.in || date, +toDate(date) + amount);
11770
+ }
11771
+
11772
+ // ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/addHours.js
11773
+ function addHours(date, amount, options) {
11774
+ return addMilliseconds(date, amount * millisecondsInHour, options);
11775
+ }
11776
+
11777
+ // ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/addMonths.js
11778
+ function addMonths(date, amount, options) {
11779
+ const _date = toDate(date, options?.in);
11780
+ if (isNaN(amount)) return constructFrom(options?.in || date, NaN);
11781
+ if (!amount) {
11782
+ return _date;
11783
+ }
11784
+ const dayOfMonth = _date.getDate();
11785
+ const endOfDesiredMonth = constructFrom(options?.in || date, _date.getTime());
11786
+ endOfDesiredMonth.setMonth(_date.getMonth() + amount + 1, 0);
11787
+ const daysInMonth = endOfDesiredMonth.getDate();
11788
+ if (dayOfMonth >= daysInMonth) {
11789
+ return endOfDesiredMonth;
11790
+ } else {
11791
+ _date.setFullYear(
11792
+ endOfDesiredMonth.getFullYear(),
11793
+ endOfDesiredMonth.getMonth(),
11794
+ dayOfMonth
11795
+ );
11796
+ return _date;
11797
+ }
11798
+ }
11799
+
11800
+ // ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/addYears.js
11801
+ function addYears(date, amount, options) {
11802
+ return addMonths(date, amount * 12, options);
11803
+ }
11804
+
11805
+ // ../types/src/types/Secret.ts
11806
+ var expirationOptions = {
11807
+ "Forever": "forever",
11808
+ "One hour": "oneHour",
11809
+ "Six hours": "sixHours",
11810
+ "Twelve hours": "twelveHours",
11811
+ "One day": "oneDay",
11812
+ "One week": "sevenDays",
11813
+ "One month": "oneMonth",
11814
+ "Six months": "sixMonths",
11815
+ "One year": "oneYear"
11816
+ };
11817
+ var expirationOptionsValues = Object.values(expirationOptions);
11818
+ var conversionMap = {
11819
+ forever: () => void 0,
11820
+ oneHour: () => addHours(/* @__PURE__ */ new Date(), 1),
11821
+ sixHours: () => addHours(/* @__PURE__ */ new Date(), 6),
11822
+ twelveHours: () => addHours(/* @__PURE__ */ new Date(), 12),
11823
+ oneDay: () => addDays(/* @__PURE__ */ new Date(), 1),
11824
+ sevenDays: () => addDays(/* @__PURE__ */ new Date(), 7),
11825
+ oneMonth: () => addMonths(/* @__PURE__ */ new Date(), 1),
11826
+ sixMonths: () => addMonths(/* @__PURE__ */ new Date(), 6),
11827
+ oneYear: () => addYears(/* @__PURE__ */ new Date(), 1)
11828
+ };
11829
+ var expirationTimeToDate = (option) => {
11830
+ return conversionMap[option]() ?? void 0;
11831
+ };
11832
+
11833
+ // ../types/src/types/Environments.ts
11834
+ var envs = {
11835
+ development: "Development",
11836
+ test: "Testing",
11837
+ production: "Production"
11838
+ };
11839
+ var envMap = {
11840
+ development: "d",
11841
+ test: "q",
11842
+ production: "p"
11843
+ };
11844
+
11726
11845
  // src/MiauClient.ts
11727
11846
  var import_node_crypto = __toESM(require("node:crypto"));
11728
11847
  var import_jsonwebtoken2 = __toESM(require_jsonwebtoken());
@@ -11780,7 +11899,8 @@ var miauMiddleware = (miauClient, requestAugmentation, fallbackMidlleware) => {
11780
11899
  throw new HttpError(403, "Forbidden", `You do not have permission to access ${req.method} ${req.path}`);
11781
11900
  }
11782
11901
  req.miauApplication = { id: application.id, name: application.name };
11783
- req.miauMetadata = permission?.metadata || {};
11902
+ const environment = miauClient.getEnvironment();
11903
+ req.miauMetadata = permission?.metadata?.[environment] || {};
11784
11904
  if (requestAugmentation) {
11785
11905
  requestAugmentation({ req, app: req.miauApplication, meta: req.miauMetadata });
11786
11906
  }
@@ -11897,7 +12017,12 @@ var MiauClient = class {
11897
12017
  0 && (module.exports = {
11898
12018
  HttpMethods,
11899
12019
  MiauClient,
11900
- ResourceProtocols
12020
+ ResourceProtocols,
12021
+ envMap,
12022
+ envs,
12023
+ expirationOptions,
12024
+ expirationOptionsValues,
12025
+ expirationTimeToDate
11901
12026
  });
11902
12027
  /*! Bundled license information:
11903
12028