@auditauth/core 0.2.0-beta.4 → 0.2.0-beta.6

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.
@@ -31,7 +31,10 @@ const authorizeCode = async ({ code, client_type }) => {
31
31
  credentials: "include"
32
32
  });
33
33
  if (!response.ok) {
34
- throw new Error("Unauthorized");
34
+ const errorMessage = await response.text().catch(() => "Unauthorized");
35
+ const error = new Error(errorMessage || "Unauthorized");
36
+ Object.assign(error, { status: response.status });
37
+ throw error;
35
38
  }
36
39
  const data = await response.json();
37
40
  return {
@@ -8,7 +8,10 @@ const authorizeCode = async ({ code, client_type }) => {
8
8
  credentials: "include"
9
9
  });
10
10
  if (!response.ok) {
11
- throw new Error("Unauthorized");
11
+ const errorMessage = await response.text().catch(() => "Unauthorized");
12
+ const error = new Error(errorMessage || "Unauthorized");
13
+ Object.assign(error, { status: response.status });
14
+ throw error;
12
15
  }
13
16
  const data = await response.json();
14
17
  return {
@@ -22,14 +22,14 @@ __export(buildAuthUrl_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(buildAuthUrl_exports);
24
24
  var import_settings = require("../settings.cjs");
25
- const buildAuthUrl = async ({ apiKey, redirectUrl }) => {
25
+ const buildAuthUrl = async ({ apiKey, redirectUrl, cancelUrl }) => {
26
26
  const response = await fetch(`${import_settings.CORE_SETTINGS.domains.api}/applications/login`, {
27
27
  method: "POST",
28
28
  headers: {
29
29
  "Content-Type": "application/json",
30
30
  "x-api-key": apiKey
31
31
  },
32
- body: JSON.stringify({ redirect_url: redirectUrl })
32
+ body: JSON.stringify({ redirect_url: redirectUrl, cancel_url: cancelUrl })
33
33
  });
34
34
  if (!response.ok) {
35
35
  const error = await response.text();
@@ -3,7 +3,8 @@ import * as url from 'url';
3
3
  type BuildAuthUrlPayload = {
4
4
  apiKey: string;
5
5
  redirectUrl: string;
6
+ cancelUrl: string;
6
7
  };
7
- declare const buildAuthUrl: ({ apiKey, redirectUrl }: BuildAuthUrlPayload) => Promise<url.URL>;
8
+ declare const buildAuthUrl: ({ apiKey, redirectUrl, cancelUrl }: BuildAuthUrlPayload) => Promise<url.URL>;
8
9
 
9
10
  export { buildAuthUrl as default };
@@ -3,7 +3,8 @@ import * as url from 'url';
3
3
  type BuildAuthUrlPayload = {
4
4
  apiKey: string;
5
5
  redirectUrl: string;
6
+ cancelUrl: string;
6
7
  };
7
- declare const buildAuthUrl: ({ apiKey, redirectUrl }: BuildAuthUrlPayload) => Promise<url.URL>;
8
+ declare const buildAuthUrl: ({ apiKey, redirectUrl, cancelUrl }: BuildAuthUrlPayload) => Promise<url.URL>;
8
9
 
9
10
  export { buildAuthUrl as default };
@@ -1,12 +1,12 @@
1
1
  import { CORE_SETTINGS } from "../settings.js";
2
- const buildAuthUrl = async ({ apiKey, redirectUrl }) => {
2
+ const buildAuthUrl = async ({ apiKey, redirectUrl, cancelUrl }) => {
3
3
  const response = await fetch(`${CORE_SETTINGS.domains.api}/applications/login`, {
4
4
  method: "POST",
5
5
  headers: {
6
6
  "Content-Type": "application/json",
7
7
  "x-api-key": apiKey
8
8
  },
9
- body: JSON.stringify({ redirect_url: redirectUrl })
9
+ body: JSON.stringify({ redirect_url: redirectUrl, cancel_url: cancelUrl })
10
10
  });
11
11
  if (!response.ok) {
12
12
  const error = await response.text();
package/dist/index.cjs CHANGED
@@ -19,10 +19,12 @@ __reExport(index_exports, require("./settings.cjs"), module.exports);
19
19
  __reExport(index_exports, require("./auth/index.cjs"), module.exports);
20
20
  __reExport(index_exports, require("./portal/index.cjs"), module.exports);
21
21
  __reExport(index_exports, require("./metrics/index.cjs"), module.exports);
22
+ __reExport(index_exports, require("./session/index.cjs"), module.exports);
22
23
  // Annotate the CommonJS export names for ESM import in node:
23
24
  0 && (module.exports = {
24
25
  ...require("./settings.cjs"),
25
26
  ...require("./auth/index.cjs"),
26
27
  ...require("./portal/index.cjs"),
27
- ...require("./metrics/index.cjs")
28
+ ...require("./metrics/index.cjs"),
29
+ ...require("./session/index.cjs")
28
30
  });
package/dist/index.d.cts CHANGED
@@ -6,4 +6,5 @@ export { default as revokeSession } from './auth/revokeSession.cjs';
6
6
  export { default as refreshTokens } from './auth/refreshTokens.cjs';
7
7
  export { default as buildPortalUrl } from './portal/buildPortalUrl.cjs';
8
8
  export { default as sendMetrics } from './metrics/sendMetrics.cjs';
9
+ export { default as getSessionUser } from './session/getUserSession.cjs';
9
10
  import 'url';
package/dist/index.d.ts CHANGED
@@ -6,4 +6,5 @@ export { default as revokeSession } from './auth/revokeSession.js';
6
6
  export { default as refreshTokens } from './auth/refreshTokens.js';
7
7
  export { default as buildPortalUrl } from './portal/buildPortalUrl.js';
8
8
  export { default as sendMetrics } from './metrics/sendMetrics.js';
9
+ export { default as getSessionUser } from './session/getUserSession.js';
9
10
  import 'url';
package/dist/index.js CHANGED
@@ -2,3 +2,4 @@ export * from "./settings.js";
2
2
  export * from "./auth/index.js";
3
3
  export * from "./portal/index.js";
4
4
  export * from "./metrics/index.js";
5
+ export * from "./session/index.js";
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var getUserSession_exports = {};
20
+ __export(getUserSession_exports, {
21
+ default: () => getUserSession_default
22
+ });
23
+ module.exports = __toCommonJS(getUserSession_exports);
24
+ var import_settings = require("../settings.cjs");
25
+ const getUserSession = async ({ access_token }) => {
26
+ const response = await fetch(`${import_settings.CORE_SETTINGS.domains.api}/portal/me`, {
27
+ method: "GET",
28
+ headers: {
29
+ Authorization: `Bearer ${access_token}`
30
+ }
31
+ });
32
+ if (!response.ok) {
33
+ const error = await response.text();
34
+ throw new Error(error);
35
+ }
36
+ const body = await response.json();
37
+ return body;
38
+ };
39
+ var getUserSession_default = getUserSession;
@@ -0,0 +1,8 @@
1
+ import { SessionUser } from '../types.cjs';
2
+
3
+ type GetUserSessionPayload = {
4
+ access_token: string;
5
+ };
6
+ declare const getUserSession: ({ access_token }: GetUserSessionPayload) => Promise<SessionUser>;
7
+
8
+ export { getUserSession as default };
@@ -0,0 +1,8 @@
1
+ import { SessionUser } from '../types.js';
2
+
3
+ type GetUserSessionPayload = {
4
+ access_token: string;
5
+ };
6
+ declare const getUserSession: ({ access_token }: GetUserSessionPayload) => Promise<SessionUser>;
7
+
8
+ export { getUserSession as default };
@@ -0,0 +1,19 @@
1
+ import { CORE_SETTINGS } from "../settings.js";
2
+ const getUserSession = async ({ access_token }) => {
3
+ const response = await fetch(`${CORE_SETTINGS.domains.api}/portal/me`, {
4
+ method: "GET",
5
+ headers: {
6
+ Authorization: `Bearer ${access_token}`
7
+ }
8
+ });
9
+ if (!response.ok) {
10
+ const error = await response.text();
11
+ throw new Error(error);
12
+ }
13
+ const body = await response.json();
14
+ return body;
15
+ };
16
+ var getUserSession_default = getUserSession;
17
+ export {
18
+ getUserSession_default as default
19
+ };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var session_exports = {};
30
+ __export(session_exports, {
31
+ getSessionUser: () => import_getUserSession.default
32
+ });
33
+ module.exports = __toCommonJS(session_exports);
34
+ var import_getUserSession = __toESM(require("./getUserSession.cjs"), 1);
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ getSessionUser
38
+ });
@@ -0,0 +1,2 @@
1
+ export { default as getSessionUser } from './getUserSession.cjs';
2
+ import '../types.cjs';
@@ -0,0 +1,2 @@
1
+ export { default as getSessionUser } from './getUserSession.js';
2
+ import '../types.js';
@@ -0,0 +1,4 @@
1
+ import { default as default2 } from "./getUserSession.js";
2
+ export {
3
+ default2 as getSessionUser
4
+ };
package/dist/settings.cjs CHANGED
@@ -27,7 +27,7 @@ const PROD_DOMAINS = {
27
27
  };
28
28
  const LOCAL_DOMAINS = {
29
29
  api: "http://localhost:4000/v1",
30
- client: "http://localhost:3000"
30
+ client: "https://localhost:3000"
31
31
  };
32
32
  const resolveImportMeta = () => {
33
33
  try {
@@ -2,11 +2,11 @@ declare const CORE_SETTINGS: {
2
2
  readonly jwt_public_key: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs2EYs4Q9OyjNuAEPqb4j\nIzc52JdfVcNvEbG43Xp8B2kI9QxwRyX7rtFSwKowj3W1BlCLaTIMK3TafWOf9QwH\nfemuL9Ni37PFcGptzpyuoCYYA650EuD82PENcO49lsObvty2cuXxQszbPPvAecm4\nJ/XG70td/W1UwbjAJcdmp8ktZGYR0JXM37hYA9Xq/aKwu7d0FTL6WdKTvt3L5VxL\nF6WNyLs65ZSbu+j8UEkwmoJ9h9Y0mLQmFtmkoh/HWOFyFDnBNiJX0vRb++RhJw6w\ncrSbqpbTu7z4vIep5lgSOut39P273SVTQZ3cGQIS+605Ur5wjkkSzzaJV1QLBBR9\nAQIDAQAB\n-----END PUBLIC KEY-----\n";
3
3
  readonly jwt_issuer: "https://api.auditauth.com";
4
4
  readonly domains: {
5
- readonly api: "http://localhost:4000/v1";
6
- readonly client: "http://localhost:3000";
7
- } | {
8
5
  readonly api: "https://api.auditauth.com/v1";
9
6
  readonly client: "https://auditauth.com";
7
+ } | {
8
+ readonly api: "http://localhost:4000/v1";
9
+ readonly client: "https://localhost:3000";
10
10
  };
11
11
  readonly storage_keys: {
12
12
  readonly access: "auditauth_access";
@@ -2,11 +2,11 @@ declare const CORE_SETTINGS: {
2
2
  readonly jwt_public_key: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs2EYs4Q9OyjNuAEPqb4j\nIzc52JdfVcNvEbG43Xp8B2kI9QxwRyX7rtFSwKowj3W1BlCLaTIMK3TafWOf9QwH\nfemuL9Ni37PFcGptzpyuoCYYA650EuD82PENcO49lsObvty2cuXxQszbPPvAecm4\nJ/XG70td/W1UwbjAJcdmp8ktZGYR0JXM37hYA9Xq/aKwu7d0FTL6WdKTvt3L5VxL\nF6WNyLs65ZSbu+j8UEkwmoJ9h9Y0mLQmFtmkoh/HWOFyFDnBNiJX0vRb++RhJw6w\ncrSbqpbTu7z4vIep5lgSOut39P273SVTQZ3cGQIS+605Ur5wjkkSzzaJV1QLBBR9\nAQIDAQAB\n-----END PUBLIC KEY-----\n";
3
3
  readonly jwt_issuer: "https://api.auditauth.com";
4
4
  readonly domains: {
5
- readonly api: "http://localhost:4000/v1";
6
- readonly client: "http://localhost:3000";
7
- } | {
8
5
  readonly api: "https://api.auditauth.com/v1";
9
6
  readonly client: "https://auditauth.com";
7
+ } | {
8
+ readonly api: "http://localhost:4000/v1";
9
+ readonly client: "https://localhost:3000";
10
10
  };
11
11
  readonly storage_keys: {
12
12
  readonly access: "auditauth_access";
package/dist/settings.js CHANGED
@@ -4,7 +4,7 @@ const PROD_DOMAINS = {
4
4
  };
5
5
  const LOCAL_DOMAINS = {
6
6
  api: "http://localhost:4000/v1",
7
- client: "http://localhost:3000"
7
+ client: "https://localhost:3000"
8
8
  };
9
9
  const resolveImportMeta = () => {
10
10
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auditauth/core",
3
- "version": "0.2.0-beta.4",
3
+ "version": "0.2.0-beta.6",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Nimibyte",