@auth0/ai 2.1.0 → 3.0.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.
@@ -1,8 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCredentialsForConnection = exports.asyncLocalStorage = void 0;
3
+ exports.getAccessTokenForConnection = exports.getCredentialsForConnection = exports.asyncLocalStorage = void 0;
4
4
  const node_async_hooks_1 = require("node:async_hooks");
5
+ const interrupts_1 = require("../../interrupts");
5
6
  exports.asyncLocalStorage = new node_async_hooks_1.AsyncLocalStorage();
7
+ /**
8
+ * Returns the entire tokenset for the current connection.
9
+ *
10
+ * Use `getAccessTokenForConnection` if you only need the access token.
11
+ *
12
+ * @returns {TokenSet} The current token set.
13
+ */
6
14
  const getCredentialsForConnection = () => {
7
15
  const store = exports.asyncLocalStorage.getStore();
8
16
  if (typeof store === "undefined") {
@@ -11,4 +19,18 @@ const getCredentialsForConnection = () => {
11
19
  return store === null || store === void 0 ? void 0 : store.credentials;
12
20
  };
13
21
  exports.getCredentialsForConnection = getCredentialsForConnection;
22
+ /**
23
+ *
24
+ * Get the access token for the current connection.
25
+ *
26
+ * @returns The access token for the current connection.
27
+ */
28
+ const getAccessTokenForConnection = () => {
29
+ const credentials = (0, exports.getCredentialsForConnection)();
30
+ if (!credentials || !credentials.accessToken) {
31
+ throw new interrupts_1.FederatedConnectionError("No credentials found");
32
+ }
33
+ return credentials.accessToken;
34
+ };
35
+ exports.getAccessTokenForConnection = getAccessTokenForConnection;
14
36
  //# sourceMappingURL=asyncLocalStorage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"asyncLocalStorage.js","sourceRoot":"","sources":["../../../../src/authorizers/federated-connections/asyncLocalStorage.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AAgCxC,QAAA,iBAAiB,GAAG,IAAI,oCAAiB,EAAqB,CAAC;AAErE,MAAM,2BAA2B,GAAG,GAAG,EAAE;IAC9C,MAAM,KAAK,GAAG,yBAAiB,CAAC,QAAQ,EAAE,CAAC;IAC3C,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CACb,qEAAqE,CACtE,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,WAAW,CAAC;AAC5B,CAAC,CAAC;AARW,QAAA,2BAA2B,+BAQtC","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport { TokenSet } from \"../../credentials\";\nimport { ToolCallContext } from \"../context\";\n\nexport type AsyncStorageValue = {\n /**\n * The Federated Connection access token.\n */\n credentials?: TokenSet;\n\n /**\n * The tool execution context.\n */\n context: ToolCallContext;\n\n /**\n * The federated connection name.\n */\n connection: string;\n\n /**\n * The scopes required to access the federated connection.\n */\n scopes: string[];\n\n /**\n * The scopes that the current access token has.\n */\n currentScopes?: string[];\n};\n\nexport const asyncLocalStorage = new AsyncLocalStorage<AsyncStorageValue>();\n\nexport const getCredentialsForConnection = () => {\n const store = asyncLocalStorage.getStore();\n if (typeof store === \"undefined\") {\n throw new Error(\n \"The tool must be wrapped with the withTokenForConnections function.\"\n );\n }\n return store?.credentials;\n};\n"]}
1
+ {"version":3,"file":"asyncLocalStorage.js","sourceRoot":"","sources":["../../../../src/authorizers/federated-connections/asyncLocalStorage.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AAGrD,iDAA4D;AA8B/C,QAAA,iBAAiB,GAAG,IAAI,oCAAiB,EAAqB,CAAC;AAE5E;;;;;;GAMG;AACI,MAAM,2BAA2B,GAAG,GAAG,EAAE;IAC9C,MAAM,KAAK,GAAG,yBAAiB,CAAC,QAAQ,EAAE,CAAC;IAC3C,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CACb,qEAAqE,CACtE,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,WAAW,CAAC;AAC5B,CAAC,CAAC;AARW,QAAA,2BAA2B,+BAQtC;AAEF;;;;;GAKG;AACI,MAAM,2BAA2B,GAAG,GAAG,EAAE;IAC9C,MAAM,WAAW,GAAG,IAAA,mCAA2B,GAAE,CAAC;IAClD,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC;QAC7C,MAAM,IAAI,qCAAwB,CAAC,sBAAsB,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,WAAW,CAAC,WAAW,CAAC;AACjC,CAAC,CAAC;AANW,QAAA,2BAA2B,+BAMtC","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport { TokenSet } from \"../../credentials\";\nimport { FederatedConnectionError } from \"../../interrupts\";\nimport { ToolCallContext } from \"../context\";\n\nexport type AsyncStorageValue = {\n /**\n * The Federated Connection access token.\n */\n credentials?: TokenSet;\n\n /**\n * The tool execution context.\n */\n context: ToolCallContext;\n\n /**\n * The federated connection name.\n */\n connection: string;\n\n /**\n * The scopes required to access the federated connection.\n */\n scopes: string[];\n\n /**\n * The scopes that the current access token has.\n */\n currentScopes?: string[];\n};\n\nexport const asyncLocalStorage = new AsyncLocalStorage<AsyncStorageValue>();\n\n/**\n * Returns the entire tokenset for the current connection.\n *\n * Use `getAccessTokenForConnection` if you only need the access token.\n *\n * @returns {TokenSet} The current token set.\n */\nexport const getCredentialsForConnection = () => {\n const store = asyncLocalStorage.getStore();\n if (typeof store === \"undefined\") {\n throw new Error(\n \"The tool must be wrapped with the withTokenForConnections function.\"\n );\n }\n return store?.credentials;\n};\n\n/**\n *\n * Get the access token for the current connection.\n *\n * @returns The access token for the current connection.\n */\nexport const getAccessTokenForConnection = () => {\n const credentials = getCredentialsForConnection();\n if (!credentials || !credentials.accessToken) {\n throw new FederatedConnectionError(\"No credentials found\");\n }\n return credentials.accessToken;\n};\n"]}
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FederatedConnectionAuthorizerBase = exports.getAccessTokenForConnection = exports.asyncLocalStorage = void 0;
3
+ exports.FederatedConnectionAuthorizerBase = exports.getAccessTokenForConnection = exports.getCredentialsForConnection = exports.asyncLocalStorage = void 0;
4
4
  var asyncLocalStorage_1 = require("./asyncLocalStorage");
5
5
  Object.defineProperty(exports, "asyncLocalStorage", { enumerable: true, get: function () { return asyncLocalStorage_1.asyncLocalStorage; } });
6
- Object.defineProperty(exports, "getAccessTokenForConnection", { enumerable: true, get: function () { return asyncLocalStorage_1.getCredentialsForConnection; } });
6
+ Object.defineProperty(exports, "getCredentialsForConnection", { enumerable: true, get: function () { return asyncLocalStorage_1.getCredentialsForConnection; } });
7
+ Object.defineProperty(exports, "getAccessTokenForConnection", { enumerable: true, get: function () { return asyncLocalStorage_1.getAccessTokenForConnection; } });
7
8
  var FederatedConnectionAuthorizerBase_1 = require("./FederatedConnectionAuthorizerBase");
8
9
  Object.defineProperty(exports, "FederatedConnectionAuthorizerBase", { enumerable: true, get: function () { return FederatedConnectionAuthorizerBase_1.FederatedConnectionAuthorizerBase; } });
9
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/authorizers/federated-connections/index.ts"],"names":[],"mappings":";;;AAEA,yDAG6B;AAF3B,sHAAA,iBAAiB,OAAA;AACjB,gIAAA,2BAA2B,OAA+B;AAG5D,yFAAwF;AAA/E,sJAAA,iCAAiC,OAAA","sourcesContent":["export type { AsyncStorageValue } from \"./asyncLocalStorage\";\n\nexport {\n asyncLocalStorage,\n getCredentialsForConnection as getAccessTokenForConnection,\n} from \"./asyncLocalStorage\";\n\nexport { FederatedConnectionAuthorizerBase } from \"./FederatedConnectionAuthorizerBase\";\n\nexport type { FederatedConnectionAuthorizerParams } from \"./FederatedConnectionAuthorizerParams\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/authorizers/federated-connections/index.ts"],"names":[],"mappings":";;;AAEA,yDAI6B;AAH3B,sHAAA,iBAAiB,OAAA;AACjB,gIAAA,2BAA2B,OAAA;AAC3B,gIAAA,2BAA2B,OAAA;AAG7B,yFAAwF;AAA/E,sJAAA,iCAAiC,OAAA","sourcesContent":["export type { AsyncStorageValue } from \"./asyncLocalStorage\";\n\nexport {\n asyncLocalStorage,\n getCredentialsForConnection,\n getAccessTokenForConnection,\n} from \"./asyncLocalStorage\";\n\nexport { FederatedConnectionAuthorizerBase } from \"./FederatedConnectionAuthorizerBase\";\n\nexport type { FederatedConnectionAuthorizerParams } from \"./FederatedConnectionAuthorizerParams\";\n"]}
@@ -13,7 +13,8 @@ class CIBAInterrupt extends Auth0Interrupt_1.Auth0Interrupt {
13
13
  return (interrupt &&
14
14
  Auth0Interrupt_1.Auth0Interrupt.isInterrupt(interrupt) &&
15
15
  typeof interrupt.code === "string" &&
16
- interrupt.code.startsWith("CIBA_"));
16
+ (this.code === interrupt.code ||
17
+ (!this.code && interrupt.code.startsWith("CIBA_"))));
17
18
  }
18
19
  static hasRequestData(interrupt) {
19
20
  return CIBAInterrupt.isInterrupt(interrupt) && "request" in interrupt;
@@ -67,7 +68,7 @@ AuthorizationPendingInterrupt.code = "CIBA_AUTHORIZATION_PENDING";
67
68
  /**
68
69
  * An interrupt that is thrown when the authorization polling fails.
69
70
  */
70
- class AuthorizationPollingInterrupt extends Auth0Interrupt_1.Auth0Interrupt {
71
+ class AuthorizationPollingInterrupt extends CIBAInterrupt {
71
72
  constructor(message, request) {
72
73
  super(message, AuthorizationPollingInterrupt.code);
73
74
  this.request = request;
@@ -78,7 +79,7 @@ AuthorizationPollingInterrupt.code = "CIBA_AUTHORIZATION_POLLING_ERROR";
78
79
  /**
79
80
  * An interrupt that is thrown when the authorization polling fails.
80
81
  */
81
- class InvalidGrantInterrupt extends Auth0Interrupt_1.Auth0Interrupt {
82
+ class InvalidGrantInterrupt extends CIBAInterrupt {
82
83
  constructor(message, request) {
83
84
  super(message, AuthorizationPollingInterrupt.code);
84
85
  this.request = request;
@@ -1 +1 @@
1
- {"version":3,"file":"CIBAInterrupts.js","sourceRoot":"","sources":["../../../src/interrupts/CIBAInterrupts.ts"],"names":[],"mappings":";;;AACA,qDAAsE;AAMtE;;GAEG;AACH,MAAa,aAAc,SAAQ,+BAAc;IAC/C,YAAY,OAAe,EAAE,IAAY;QACvC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,WAAW,CAEhB,SAAc;QAEd,OAAO,CACL,SAAS;YACT,+BAAc,CAAC,WAAW,CAAC,SAAS,CAAC;YACrC,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ;YAClC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CACnC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,SAAc;QAClC,OAAO,aAAa,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,SAAS,IAAI,SAAS,CAAC;IACxE,CAAC;CACF;AApBD,sCAoBC;AAED;;GAEG;AACH,MAAa,qBACX,SAAQ,aAAa;IAIrB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAF3B,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AAVH,sDAWC;AAPe,0BAAI,GAAW,oBAA6B,CAAC;AAS7D;;GAEG;AACH,MAAa,yCAA0C,SAAQ,aAAa;IAG1E,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,yCAAyC,CAAC,IAAI,CAAC,CAAC;IACjE,CAAC;;AALH,8FAMC;AALe,8CAAI,GAChB,4CAAqD,CAAC;AAM1D;;GAEG;AACH,MAAa,oCACX,SAAQ,aAAa;IAIrB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,oCAAoC,CAAC,IAAI,CAAC,CAAC;QAF1C,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AAVH,oFAWC;AAPe,yCAAI,GAAW,oCAA6C,CAAC;AAS7E;;;GAGG;AACH,MAAa,6BACX,SAAQ,aAAa;IAIrB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,6BAA6B,CAAC,IAAI,CAAC,CAAC;QAFnC,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AAVH,sEAWC;AAPe,kCAAI,GAAW,4BAAqC,CAAC;AASrE;;GAEG;AACH,MAAa,6BACX,SAAQ,+BAAc;IAItB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,6BAA6B,CAAC,IAAI,CAAC,CAAC;QAFnC,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AAVH,sEAWC;AAPe,kCAAI,GAAW,kCAA2C,CAAC;AAS3E;;GAEG;AACH,MAAa,qBACX,SAAQ,+BAAc;IAItB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,6BAA6B,CAAC,IAAI,CAAC,CAAC;QAFnC,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AAVH,sDAWC;AAPe,0BAAI,GAAW,oBAA6B,CAAC","sourcesContent":["import { CIBAAuthorizationRequest } from \"../authorizers/ciba/CIBAAuthorizationRequest\";\nimport { Auth0Interrupt, Auth0InterruptData } from \"./Auth0Interrupt\";\n\nexport interface WithRequestData {\n request: CIBAAuthorizationRequest;\n}\n\n/**\n * Base class for CIBA interrupts.\n */\nexport class CIBAInterrupt extends Auth0Interrupt {\n constructor(message: string, code: string) {\n super(message, code);\n }\n\n static isInterrupt<T extends abstract new (...args: any) => any>(\n this: T,\n interrupt: any\n ): interrupt is Auth0InterruptData<InstanceType<T>> {\n return (\n interrupt &&\n Auth0Interrupt.isInterrupt(interrupt) &&\n typeof interrupt.code === \"string\" &&\n interrupt.code.startsWith(\"CIBA_\")\n );\n }\n\n static hasRequestData(interrupt: any): interrupt is WithRequestData {\n return CIBAInterrupt.isInterrupt(interrupt) && \"request\" in interrupt;\n }\n}\n\n/**\n * An interrupt that is thrown when the user denies the authorization request.\n */\nexport class AccessDeniedInterrupt\n extends CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_ACCESS_DENIED\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AccessDeniedInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the user does not have push notifications enabled.\n */\nexport class UserDoesNotHavePushNotificationsInterrupt extends CIBAInterrupt {\n public static code: string =\n \"CIBA_USER_DOES_NOT_HAVE_PUSH_NOTIFICATIONS\" as const;\n constructor(message: string) {\n super(message, UserDoesNotHavePushNotificationsInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization request has expired.\n */\nexport class AuthorizationRequestExpiredInterrupt\n extends CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_REQUEST_EXPIRED\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationRequestExpiredInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization is still pending\n * and the Authorizer is in `mode: interrupt`.\n */\nexport class AuthorizationPendingInterrupt\n extends CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_PENDING\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationPendingInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization polling fails.\n */\nexport class AuthorizationPollingInterrupt\n extends Auth0Interrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_POLLING_ERROR\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationPollingInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization polling fails.\n */\nexport class InvalidGrantInterrupt\n extends Auth0Interrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_INVALID_GRANT\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationPollingInterrupt.code);\n }\n}\n"]}
1
+ {"version":3,"file":"CIBAInterrupts.js","sourceRoot":"","sources":["../../../src/interrupts/CIBAInterrupts.ts"],"names":[],"mappings":";;;AACA,qDAAsE;AAMtE;;GAEG;AACH,MAAa,aAAc,SAAQ,+BAAc;IAC/C,YAAY,OAAe,EAAE,IAAY;QACvC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,WAAW,CAEhB,SAAc;QAEd,OAAO,CACL,SAAS;YACT,+BAAc,CAAC,WAAW,CAAC,SAAS,CAAC;YACrC,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ;YAClC,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI;gBAC3B,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CACtD,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,SAAc;QAClC,OAAO,aAAa,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,SAAS,IAAI,SAAS,CAAC;IACxE,CAAC;CACF;AArBD,sCAqBC;AAED;;GAEG;AACH,MAAa,qBACX,SAAQ,aAAa;IAIrB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAF3B,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AAVH,sDAWC;AAPe,0BAAI,GAAW,oBAA6B,CAAC;AAS7D;;GAEG;AACH,MAAa,yCAA0C,SAAQ,aAAa;IAG1E,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,yCAAyC,CAAC,IAAI,CAAC,CAAC;IACjE,CAAC;;AALH,8FAMC;AALe,8CAAI,GAChB,4CAAqD,CAAC;AAM1D;;GAEG;AACH,MAAa,oCACX,SAAQ,aAAa;IAIrB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,oCAAoC,CAAC,IAAI,CAAC,CAAC;QAF1C,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AAVH,oFAWC;AAPe,yCAAI,GAAW,oCAA6C,CAAC;AAS7E;;;GAGG;AACH,MAAa,6BACX,SAAQ,aAAa;IAIrB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,6BAA6B,CAAC,IAAI,CAAC,CAAC;QAFnC,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AAVH,sEAWC;AAPe,kCAAI,GAAW,4BAAqC,CAAC;AASrE;;GAEG;AACH,MAAa,6BACX,SAAQ,aAAa;IAIrB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,6BAA6B,CAAC,IAAI,CAAC,CAAC;QAFnC,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AAVH,sEAWC;AAPe,kCAAI,GAAW,kCAA2C,CAAC;AAS3E;;GAEG;AACH,MAAa,qBACX,SAAQ,aAAa;IAIrB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,6BAA6B,CAAC,IAAI,CAAC,CAAC;QAFnC,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AAVH,sDAWC;AAPe,0BAAI,GAAW,oBAA6B,CAAC","sourcesContent":["import { CIBAAuthorizationRequest } from \"../authorizers/ciba/CIBAAuthorizationRequest\";\nimport { Auth0Interrupt, Auth0InterruptData } from \"./Auth0Interrupt\";\n\nexport interface WithRequestData {\n request: CIBAAuthorizationRequest;\n}\n\n/**\n * Base class for CIBA interrupts.\n */\nexport class CIBAInterrupt extends Auth0Interrupt {\n constructor(message: string, code: string) {\n super(message, code);\n }\n\n static isInterrupt<T extends abstract new (...args: any) => any>(\n this: T & { code?: string },\n interrupt: any\n ): interrupt is Auth0InterruptData<InstanceType<T>> {\n return (\n interrupt &&\n Auth0Interrupt.isInterrupt(interrupt) &&\n typeof interrupt.code === \"string\" &&\n (this.code === interrupt.code ||\n (!this.code && interrupt.code.startsWith(\"CIBA_\")))\n );\n }\n\n static hasRequestData(interrupt: any): interrupt is WithRequestData {\n return CIBAInterrupt.isInterrupt(interrupt) && \"request\" in interrupt;\n }\n}\n\n/**\n * An interrupt that is thrown when the user denies the authorization request.\n */\nexport class AccessDeniedInterrupt\n extends CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_ACCESS_DENIED\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AccessDeniedInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the user does not have push notifications enabled.\n */\nexport class UserDoesNotHavePushNotificationsInterrupt extends CIBAInterrupt {\n public static code: string =\n \"CIBA_USER_DOES_NOT_HAVE_PUSH_NOTIFICATIONS\" as const;\n constructor(message: string) {\n super(message, UserDoesNotHavePushNotificationsInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization request has expired.\n */\nexport class AuthorizationRequestExpiredInterrupt\n extends CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_REQUEST_EXPIRED\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationRequestExpiredInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization is still pending\n * and the Authorizer is in `mode: interrupt`.\n */\nexport class AuthorizationPendingInterrupt\n extends CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_PENDING\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationPendingInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization polling fails.\n */\nexport class AuthorizationPollingInterrupt\n extends CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_POLLING_ERROR\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationPollingInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization polling fails.\n */\nexport class InvalidGrantInterrupt\n extends CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_INVALID_GRANT\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationPollingInterrupt.code);\n }\n}\n"]}
@@ -13,7 +13,8 @@ class DeviceInterrupt extends Auth0Interrupt_1.Auth0Interrupt {
13
13
  return (interrupt &&
14
14
  Auth0Interrupt_1.Auth0Interrupt.isInterrupt(interrupt) &&
15
15
  typeof interrupt.code === "string" &&
16
- interrupt.code.startsWith("DEVICE_"));
16
+ (this.code === interrupt.code ||
17
+ (!this.code && interrupt.code.startsWith("DEVICE_"))));
17
18
  }
18
19
  static hasRequestData(interrupt) {
19
20
  return DeviceInterrupt.isInterrupt(interrupt) && "response" in interrupt;
@@ -1 +1 @@
1
- {"version":3,"file":"DeviceInterrupts.js","sourceRoot":"","sources":["../../../src/interrupts/DeviceInterrupts.ts"],"names":[],"mappings":";;;AACA,qDAAsE;AAMtE;;GAEG;AACH,MAAa,eAAgB,SAAQ,+BAAc;IACjD,YAAY,OAAe,EAAE,IAAY;QACvC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,WAAW,CAEhB,SAAc;QAEd,OAAO,CACL,SAAS;YACT,+BAAc,CAAC,WAAW,CAAC,SAAS,CAAC;YACrC,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ;YAClC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CACrC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,cAAc,CACnB,SAAc;QA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,sDAWC;AAPe,0BAAI,GAAW,sBAA+B,CAAC","sourcesContent":["import { DeviceAuthorizationResponse } from \"../authorizers/device-authorizer/DeviceAuthResponse\";\nimport { Auth0Interrupt, Auth0InterruptData } from \"./Auth0Interrupt\";\n\nexport interface WithDeviceAuthResponseData {\n response: DeviceAuthorizationResponse;\n}\n\n/**\n * Base class for Device interrupts.\n */\nexport class DeviceInterrupt extends Auth0Interrupt {\n constructor(message: string, code: string) {\n super(message, code);\n }\n\n static isInterrupt<T extends abstract new (...args: any) => any>(\n this: T,\n interrupt: any\n ): interrupt is Auth0InterruptData<InstanceType<T>> {\n return (\n interrupt &&\n Auth0Interrupt.isInterrupt(interrupt) &&\n typeof interrupt.code === \"string\" &&\n interrupt.code.startsWith(\"DEVICE_\")\n );\n }\n\n static hasRequestData(\n interrupt: any\n ): interrupt is WithDeviceAuthResponseData {\n return DeviceInterrupt.isInterrupt(interrupt) && \"response\" in interrupt;\n }\n}\n\n/**\n * An interrupt that is thrown when the user denies the authorization request.\n */\nexport class AccessDeniedInterrupt\n extends DeviceInterrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_ACCESS_DENIED\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AccessDeniedInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization request has expired.\n */\nexport class AuthorizationRequestExpiredInterrupt\n extends DeviceInterrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_AUTHORIZATION_REQUEST_EXPIRED\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AuthorizationRequestExpiredInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization is still pending\n * and the Authorizer is in `mode: interrupt`.\n */\nexport class AuthorizationPendingInterrupt\n extends DeviceInterrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_AUTHORIZATION_PENDING\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AuthorizationPendingInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization polling fails.\n */\nexport class AuthorizationPollingInterrupt\n extends Auth0Interrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_AUTHORIZATION_POLLING_ERROR\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AuthorizationPollingInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the grant is invalid.\n */\nexport class InvalidGrantInterrupt\n extends Auth0Interrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_INVALID_GRANT\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AuthorizationPollingInterrupt.code);\n }\n}\n"]}
1
+ {"version":3,"file":"DeviceInterrupts.js","sourceRoot":"","sources":["../../../src/interrupts/DeviceInterrupts.ts"],"names":[],"mappings":";;;AACA,qDAAsE;AAMtE;;GAEG;AACH,MAAa,eAAgB,SAAQ,+BAAc;IACjD,YAAY,OAAe,EAAE,IAAY;QACvC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,WAAW,CAEhB,SAAc;QAEd,OAAO,CACL,SAAS;YACT,+BAAc,CAAC,WAAW,CAAC,SAAS,CAAC;YACrC,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ;YAClC,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI;gBAC3B,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CACxD,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,cAAc,CACnB,SAAc;QAEd,OAAO,eAAe,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,UAAU,IAAI,SAAS,CAAC;IAC3E,CAAC;CACF;AAvBD,0CAuBC;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{ Auth0Interrupt, Auth0InterruptData } from \"./Auth0Interrupt\";\n\nexport interface WithDeviceAuthResponseData {\n response: DeviceAuthorizationResponse;\n}\n\n/**\n * Base class for Device interrupts.\n */\nexport class DeviceInterrupt extends Auth0Interrupt {\n constructor(message: string, code: string) {\n super(message, code);\n }\n\n static isInterrupt<T extends abstract new (...args: any) => any>(\n this: T & { code?: string },\n interrupt: any\n ): interrupt is Auth0InterruptData<InstanceType<T>> {\n return (\n interrupt &&\n Auth0Interrupt.isInterrupt(interrupt) &&\n typeof interrupt.code === \"string\" &&\n (this.code === interrupt.code ||\n (!this.code && interrupt.code.startsWith(\"DEVICE_\")))\n );\n }\n\n static hasRequestData(\n interrupt: any\n ): interrupt is WithDeviceAuthResponseData {\n return DeviceInterrupt.isInterrupt(interrupt) && \"response\" in interrupt;\n }\n}\n\n/**\n * An interrupt that is thrown when the user denies the authorization request.\n */\nexport class AccessDeniedInterrupt\n extends DeviceInterrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_ACCESS_DENIED\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AccessDeniedInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization request has expired.\n */\nexport class AuthorizationRequestExpiredInterrupt\n extends DeviceInterrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_AUTHORIZATION_REQUEST_EXPIRED\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AuthorizationRequestExpiredInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization is still pending\n * and the Authorizer is in `mode: interrupt`.\n */\nexport class AuthorizationPendingInterrupt\n extends DeviceInterrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_AUTHORIZATION_PENDING\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AuthorizationPendingInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization polling fails.\n */\nexport class AuthorizationPollingInterrupt\n extends Auth0Interrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_AUTHORIZATION_POLLING_ERROR\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AuthorizationPollingInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the grant is invalid.\n */\nexport class InvalidGrantInterrupt\n extends Auth0Interrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_INVALID_GRANT\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AuthorizationPollingInterrupt.code);\n }\n}\n"]}
@@ -24,5 +24,19 @@ export type AsyncStorageValue = {
24
24
  currentScopes?: string[];
25
25
  };
26
26
  export declare const asyncLocalStorage: AsyncLocalStorage<AsyncStorageValue>;
27
+ /**
28
+ * Returns the entire tokenset for the current connection.
29
+ *
30
+ * Use `getAccessTokenForConnection` if you only need the access token.
31
+ *
32
+ * @returns {TokenSet} The current token set.
33
+ */
27
34
  export declare const getCredentialsForConnection: () => TokenSet | undefined;
35
+ /**
36
+ *
37
+ * Get the access token for the current connection.
38
+ *
39
+ * @returns The access token for the current connection.
40
+ */
41
+ export declare const getAccessTokenForConnection: () => string;
28
42
  //# sourceMappingURL=asyncLocalStorage.d.ts.map
@@ -1,5 +1,13 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { FederatedConnectionError } from "../../interrupts";
2
3
  export const asyncLocalStorage = new AsyncLocalStorage();
4
+ /**
5
+ * Returns the entire tokenset for the current connection.
6
+ *
7
+ * Use `getAccessTokenForConnection` if you only need the access token.
8
+ *
9
+ * @returns {TokenSet} The current token set.
10
+ */
3
11
  export const getCredentialsForConnection = () => {
4
12
  const store = asyncLocalStorage.getStore();
5
13
  if (typeof store === "undefined") {
@@ -7,4 +15,17 @@ export const getCredentialsForConnection = () => {
7
15
  }
8
16
  return store === null || store === void 0 ? void 0 : store.credentials;
9
17
  };
18
+ /**
19
+ *
20
+ * Get the access token for the current connection.
21
+ *
22
+ * @returns The access token for the current connection.
23
+ */
24
+ export const getAccessTokenForConnection = () => {
25
+ const credentials = getCredentialsForConnection();
26
+ if (!credentials || !credentials.accessToken) {
27
+ throw new FederatedConnectionError("No credentials found");
28
+ }
29
+ return credentials.accessToken;
30
+ };
10
31
  //# sourceMappingURL=asyncLocalStorage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"asyncLocalStorage.js","sourceRoot":"","sources":["../../../../src/authorizers/federated-connections/asyncLocalStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAgCrD,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAqB,CAAC;AAE5E,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,EAAE;IAC9C,MAAM,KAAK,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAC;IAC3C,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CACb,qEAAqE,CACtE,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,WAAW,CAAC;AAC5B,CAAC,CAAC","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport { TokenSet } from \"../../credentials\";\nimport { ToolCallContext } from \"../context\";\n\nexport type AsyncStorageValue = {\n /**\n * The Federated Connection access token.\n */\n credentials?: TokenSet;\n\n /**\n * The tool execution context.\n */\n context: ToolCallContext;\n\n /**\n * The federated connection name.\n */\n connection: string;\n\n /**\n * The scopes required to access the federated connection.\n */\n scopes: string[];\n\n /**\n * The scopes that the current access token has.\n */\n currentScopes?: string[];\n};\n\nexport const asyncLocalStorage = new AsyncLocalStorage<AsyncStorageValue>();\n\nexport const getCredentialsForConnection = () => {\n const store = asyncLocalStorage.getStore();\n if (typeof store === \"undefined\") {\n throw new Error(\n \"The tool must be wrapped with the withTokenForConnections function.\"\n );\n }\n return store?.credentials;\n};\n"]}
1
+ {"version":3,"file":"asyncLocalStorage.js","sourceRoot":"","sources":["../../../../src/authorizers/federated-connections/asyncLocalStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AA8B5D,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAqB,CAAC;AAE5E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,EAAE;IAC9C,MAAM,KAAK,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAC;IAC3C,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CACb,qEAAqE,CACtE,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,WAAW,CAAC;AAC5B,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,EAAE;IAC9C,MAAM,WAAW,GAAG,2BAA2B,EAAE,CAAC;IAClD,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC;QAC7C,MAAM,IAAI,wBAAwB,CAAC,sBAAsB,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,WAAW,CAAC,WAAW,CAAC;AACjC,CAAC,CAAC","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport { TokenSet } from \"../../credentials\";\nimport { FederatedConnectionError } from \"../../interrupts\";\nimport { ToolCallContext } from \"../context\";\n\nexport type AsyncStorageValue = {\n /**\n * The Federated Connection access token.\n */\n credentials?: TokenSet;\n\n /**\n * The tool execution context.\n */\n context: ToolCallContext;\n\n /**\n * The federated connection name.\n */\n connection: string;\n\n /**\n * The scopes required to access the federated connection.\n */\n scopes: string[];\n\n /**\n * The scopes that the current access token has.\n */\n currentScopes?: string[];\n};\n\nexport const asyncLocalStorage = new AsyncLocalStorage<AsyncStorageValue>();\n\n/**\n * Returns the entire tokenset for the current connection.\n *\n * Use `getAccessTokenForConnection` if you only need the access token.\n *\n * @returns {TokenSet} The current token set.\n */\nexport const getCredentialsForConnection = () => {\n const store = asyncLocalStorage.getStore();\n if (typeof store === \"undefined\") {\n throw new Error(\n \"The tool must be wrapped with the withTokenForConnections function.\"\n );\n }\n return store?.credentials;\n};\n\n/**\n *\n * Get the access token for the current connection.\n *\n * @returns The access token for the current connection.\n */\nexport const getAccessTokenForConnection = () => {\n const credentials = getCredentialsForConnection();\n if (!credentials || !credentials.accessToken) {\n throw new FederatedConnectionError(\"No credentials found\");\n }\n return credentials.accessToken;\n};\n"]}
@@ -1,5 +1,5 @@
1
1
  export type { AsyncStorageValue } from "./asyncLocalStorage";
2
- export { asyncLocalStorage, getCredentialsForConnection as getAccessTokenForConnection, } from "./asyncLocalStorage";
2
+ export { asyncLocalStorage, getCredentialsForConnection, getAccessTokenForConnection, } from "./asyncLocalStorage";
3
3
  export { FederatedConnectionAuthorizerBase } from "./FederatedConnectionAuthorizerBase";
4
4
  export type { FederatedConnectionAuthorizerParams } from "./FederatedConnectionAuthorizerParams";
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,3 @@
1
- export { asyncLocalStorage, getCredentialsForConnection as getAccessTokenForConnection, } from "./asyncLocalStorage";
1
+ export { asyncLocalStorage, getCredentialsForConnection, getAccessTokenForConnection, } from "./asyncLocalStorage";
2
2
  export { FederatedConnectionAuthorizerBase } from "./FederatedConnectionAuthorizerBase";
3
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/authorizers/federated-connections/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,iBAAiB,EACjB,2BAA2B,IAAI,2BAA2B,GAC3D,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC","sourcesContent":["export type { AsyncStorageValue } from \"./asyncLocalStorage\";\n\nexport {\n asyncLocalStorage,\n getCredentialsForConnection as getAccessTokenForConnection,\n} from \"./asyncLocalStorage\";\n\nexport { FederatedConnectionAuthorizerBase } from \"./FederatedConnectionAuthorizerBase\";\n\nexport type { FederatedConnectionAuthorizerParams } from \"./FederatedConnectionAuthorizerParams\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/authorizers/federated-connections/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,iBAAiB,EACjB,2BAA2B,EAC3B,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC","sourcesContent":["export type { AsyncStorageValue } from \"./asyncLocalStorage\";\n\nexport {\n asyncLocalStorage,\n getCredentialsForConnection,\n getAccessTokenForConnection,\n} from \"./asyncLocalStorage\";\n\nexport { FederatedConnectionAuthorizerBase } from \"./FederatedConnectionAuthorizerBase\";\n\nexport type { FederatedConnectionAuthorizerParams } from \"./FederatedConnectionAuthorizerParams\";\n"]}
@@ -8,7 +8,9 @@ export interface WithRequestData {
8
8
  */
9
9
  export declare class CIBAInterrupt extends Auth0Interrupt {
10
10
  constructor(message: string, code: string);
11
- static isInterrupt<T extends abstract new (...args: any) => any>(this: T, interrupt: any): interrupt is Auth0InterruptData<InstanceType<T>>;
11
+ static isInterrupt<T extends abstract new (...args: any) => any>(this: T & {
12
+ code?: string;
13
+ }, interrupt: any): interrupt is Auth0InterruptData<InstanceType<T>>;
12
14
  static hasRequestData(interrupt: any): interrupt is WithRequestData;
13
15
  }
14
16
  /**
@@ -46,7 +48,7 @@ export declare class AuthorizationPendingInterrupt extends CIBAInterrupt impleme
46
48
  /**
47
49
  * An interrupt that is thrown when the authorization polling fails.
48
50
  */
49
- export declare class AuthorizationPollingInterrupt extends Auth0Interrupt implements WithRequestData {
51
+ export declare class AuthorizationPollingInterrupt extends CIBAInterrupt implements WithRequestData {
50
52
  readonly request: CIBAAuthorizationRequest;
51
53
  static code: string;
52
54
  constructor(message: string, request: CIBAAuthorizationRequest);
@@ -54,7 +56,7 @@ export declare class AuthorizationPollingInterrupt extends Auth0Interrupt implem
54
56
  /**
55
57
  * An interrupt that is thrown when the authorization polling fails.
56
58
  */
57
- export declare class InvalidGrantInterrupt extends Auth0Interrupt implements WithRequestData {
59
+ export declare class InvalidGrantInterrupt extends CIBAInterrupt implements WithRequestData {
58
60
  readonly request: CIBAAuthorizationRequest;
59
61
  static code: string;
60
62
  constructor(message: string, request: CIBAAuthorizationRequest);
@@ -10,7 +10,8 @@ export class CIBAInterrupt extends Auth0Interrupt {
10
10
  return (interrupt &&
11
11
  Auth0Interrupt.isInterrupt(interrupt) &&
12
12
  typeof interrupt.code === "string" &&
13
- interrupt.code.startsWith("CIBA_"));
13
+ (this.code === interrupt.code ||
14
+ (!this.code && interrupt.code.startsWith("CIBA_"))));
14
15
  }
15
16
  static hasRequestData(interrupt) {
16
17
  return CIBAInterrupt.isInterrupt(interrupt) && "request" in interrupt;
@@ -59,7 +60,7 @@ AuthorizationPendingInterrupt.code = "CIBA_AUTHORIZATION_PENDING";
59
60
  /**
60
61
  * An interrupt that is thrown when the authorization polling fails.
61
62
  */
62
- export class AuthorizationPollingInterrupt extends Auth0Interrupt {
63
+ export class AuthorizationPollingInterrupt extends CIBAInterrupt {
63
64
  constructor(message, request) {
64
65
  super(message, AuthorizationPollingInterrupt.code);
65
66
  this.request = request;
@@ -69,7 +70,7 @@ AuthorizationPollingInterrupt.code = "CIBA_AUTHORIZATION_POLLING_ERROR";
69
70
  /**
70
71
  * An interrupt that is thrown when the authorization polling fails.
71
72
  */
72
- export class InvalidGrantInterrupt extends Auth0Interrupt {
73
+ export class InvalidGrantInterrupt extends CIBAInterrupt {
73
74
  constructor(message, request) {
74
75
  super(message, AuthorizationPollingInterrupt.code);
75
76
  this.request = request;
@@ -1 +1 @@
1
- {"version":3,"file":"CIBAInterrupts.js","sourceRoot":"","sources":["../../../src/interrupts/CIBAInterrupts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAsB,MAAM,kBAAkB,CAAC;AAMtE;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,cAAc;IAC/C,YAAY,OAAe,EAAE,IAAY;QACvC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,WAAW,CAEhB,SAAc;QAEd,OAAO,CACL,SAAS;YACT,cAAc,CAAC,WAAW,CAAC,SAAS,CAAC;YACrC,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ;YAClC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CACnC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,SAAc;QAClC,OAAO,aAAa,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,SAAS,IAAI,SAAS,CAAC;IACxE,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,qBACX,SAAQ,aAAa;IAIrB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAF3B,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AANa,0BAAI,GAAW,oBAA6B,CAAC;AAS7D;;GAEG;AACH,MAAM,OAAO,yCAA0C,SAAQ,aAAa;IAG1E,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,yCAAyC,CAAC,IAAI,CAAC,CAAC;IACjE,CAAC;;AAJa,8CAAI,GAChB,4CAAqD,CAAC;AAM1D;;GAEG;AACH,MAAM,OAAO,oCACX,SAAQ,aAAa;IAIrB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,oCAAoC,CAAC,IAAI,CAAC,CAAC;QAF1C,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AANa,yCAAI,GAAW,oCAA6C,CAAC;AAS7E;;;GAGG;AACH,MAAM,OAAO,6BACX,SAAQ,aAAa;IAIrB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,6BAA6B,CAAC,IAAI,CAAC,CAAC;QAFnC,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AANa,kCAAI,GAAW,4BAAqC,CAAC;AASrE;;GAEG;AACH,MAAM,OAAO,6BACX,SAAQ,cAAc;IAItB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,6BAA6B,CAAC,IAAI,CAAC,CAAC;QAFnC,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AANa,kCAAI,GAAW,kCAA2C,CAAC;AAS3E;;GAEG;AACH,MAAM,OAAO,qBACX,SAAQ,cAAc;IAItB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,6BAA6B,CAAC,IAAI,CAAC,CAAC;QAFnC,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AANa,0BAAI,GAAW,oBAA6B,CAAC","sourcesContent":["import { CIBAAuthorizationRequest } from \"../authorizers/ciba/CIBAAuthorizationRequest\";\nimport { Auth0Interrupt, Auth0InterruptData } from \"./Auth0Interrupt\";\n\nexport interface WithRequestData {\n request: CIBAAuthorizationRequest;\n}\n\n/**\n * Base class for CIBA interrupts.\n */\nexport class CIBAInterrupt extends Auth0Interrupt {\n constructor(message: string, code: string) {\n super(message, code);\n }\n\n static isInterrupt<T extends abstract new (...args: any) => any>(\n this: T,\n interrupt: any\n ): interrupt is Auth0InterruptData<InstanceType<T>> {\n return (\n interrupt &&\n Auth0Interrupt.isInterrupt(interrupt) &&\n typeof interrupt.code === \"string\" &&\n interrupt.code.startsWith(\"CIBA_\")\n );\n }\n\n static hasRequestData(interrupt: any): interrupt is WithRequestData {\n return CIBAInterrupt.isInterrupt(interrupt) && \"request\" in interrupt;\n }\n}\n\n/**\n * An interrupt that is thrown when the user denies the authorization request.\n */\nexport class AccessDeniedInterrupt\n extends CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_ACCESS_DENIED\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AccessDeniedInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the user does not have push notifications enabled.\n */\nexport class UserDoesNotHavePushNotificationsInterrupt extends CIBAInterrupt {\n public static code: string =\n \"CIBA_USER_DOES_NOT_HAVE_PUSH_NOTIFICATIONS\" as const;\n constructor(message: string) {\n super(message, UserDoesNotHavePushNotificationsInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization request has expired.\n */\nexport class AuthorizationRequestExpiredInterrupt\n extends CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_REQUEST_EXPIRED\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationRequestExpiredInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization is still pending\n * and the Authorizer is in `mode: interrupt`.\n */\nexport class AuthorizationPendingInterrupt\n extends CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_PENDING\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationPendingInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization polling fails.\n */\nexport class AuthorizationPollingInterrupt\n extends Auth0Interrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_POLLING_ERROR\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationPollingInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization polling fails.\n */\nexport class InvalidGrantInterrupt\n extends Auth0Interrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_INVALID_GRANT\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationPollingInterrupt.code);\n }\n}\n"]}
1
+ {"version":3,"file":"CIBAInterrupts.js","sourceRoot":"","sources":["../../../src/interrupts/CIBAInterrupts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAsB,MAAM,kBAAkB,CAAC;AAMtE;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,cAAc;IAC/C,YAAY,OAAe,EAAE,IAAY;QACvC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,WAAW,CAEhB,SAAc;QAEd,OAAO,CACL,SAAS;YACT,cAAc,CAAC,WAAW,CAAC,SAAS,CAAC;YACrC,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ;YAClC,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI;gBAC3B,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CACtD,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,SAAc;QAClC,OAAO,aAAa,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,SAAS,IAAI,SAAS,CAAC;IACxE,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,qBACX,SAAQ,aAAa;IAIrB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAF3B,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AANa,0BAAI,GAAW,oBAA6B,CAAC;AAS7D;;GAEG;AACH,MAAM,OAAO,yCAA0C,SAAQ,aAAa;IAG1E,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,yCAAyC,CAAC,IAAI,CAAC,CAAC;IACjE,CAAC;;AAJa,8CAAI,GAChB,4CAAqD,CAAC;AAM1D;;GAEG;AACH,MAAM,OAAO,oCACX,SAAQ,aAAa;IAIrB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,oCAAoC,CAAC,IAAI,CAAC,CAAC;QAF1C,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AANa,yCAAI,GAAW,oCAA6C,CAAC;AAS7E;;;GAGG;AACH,MAAM,OAAO,6BACX,SAAQ,aAAa;IAIrB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,6BAA6B,CAAC,IAAI,CAAC,CAAC;QAFnC,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AANa,kCAAI,GAAW,4BAAqC,CAAC;AASrE;;GAEG;AACH,MAAM,OAAO,6BACX,SAAQ,aAAa;IAIrB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,6BAA6B,CAAC,IAAI,CAAC,CAAC;QAFnC,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AANa,kCAAI,GAAW,kCAA2C,CAAC;AAS3E;;GAEG;AACH,MAAM,OAAO,qBACX,SAAQ,aAAa;IAIrB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,6BAA6B,CAAC,IAAI,CAAC,CAAC;QAFnC,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AANa,0BAAI,GAAW,oBAA6B,CAAC","sourcesContent":["import { CIBAAuthorizationRequest } from \"../authorizers/ciba/CIBAAuthorizationRequest\";\nimport { Auth0Interrupt, Auth0InterruptData } from \"./Auth0Interrupt\";\n\nexport interface WithRequestData {\n request: CIBAAuthorizationRequest;\n}\n\n/**\n * Base class for CIBA interrupts.\n */\nexport class CIBAInterrupt extends Auth0Interrupt {\n constructor(message: string, code: string) {\n super(message, code);\n }\n\n static isInterrupt<T extends abstract new (...args: any) => any>(\n this: T & { code?: string },\n interrupt: any\n ): interrupt is Auth0InterruptData<InstanceType<T>> {\n return (\n interrupt &&\n Auth0Interrupt.isInterrupt(interrupt) &&\n typeof interrupt.code === \"string\" &&\n (this.code === interrupt.code ||\n (!this.code && interrupt.code.startsWith(\"CIBA_\")))\n );\n }\n\n static hasRequestData(interrupt: any): interrupt is WithRequestData {\n return CIBAInterrupt.isInterrupt(interrupt) && \"request\" in interrupt;\n }\n}\n\n/**\n * An interrupt that is thrown when the user denies the authorization request.\n */\nexport class AccessDeniedInterrupt\n extends CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_ACCESS_DENIED\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AccessDeniedInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the user does not have push notifications enabled.\n */\nexport class UserDoesNotHavePushNotificationsInterrupt extends CIBAInterrupt {\n public static code: string =\n \"CIBA_USER_DOES_NOT_HAVE_PUSH_NOTIFICATIONS\" as const;\n constructor(message: string) {\n super(message, UserDoesNotHavePushNotificationsInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization request has expired.\n */\nexport class AuthorizationRequestExpiredInterrupt\n extends CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_REQUEST_EXPIRED\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationRequestExpiredInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization is still pending\n * and the Authorizer is in `mode: interrupt`.\n */\nexport class AuthorizationPendingInterrupt\n extends CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_PENDING\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationPendingInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization polling fails.\n */\nexport class AuthorizationPollingInterrupt\n extends CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_POLLING_ERROR\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationPollingInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization polling fails.\n */\nexport class InvalidGrantInterrupt\n extends CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_INVALID_GRANT\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationPollingInterrupt.code);\n }\n}\n"]}
@@ -8,7 +8,9 @@ export interface WithDeviceAuthResponseData {
8
8
  */
9
9
  export declare class DeviceInterrupt extends Auth0Interrupt {
10
10
  constructor(message: string, code: string);
11
- static isInterrupt<T extends abstract new (...args: any) => any>(this: T, interrupt: any): interrupt is Auth0InterruptData<InstanceType<T>>;
11
+ static isInterrupt<T extends abstract new (...args: any) => any>(this: T & {
12
+ code?: string;
13
+ }, interrupt: any): interrupt is Auth0InterruptData<InstanceType<T>>;
12
14
  static hasRequestData(interrupt: any): interrupt is WithDeviceAuthResponseData;
13
15
  }
14
16
  /**
@@ -10,7 +10,8 @@ export class DeviceInterrupt extends Auth0Interrupt {
10
10
  return (interrupt &&
11
11
  Auth0Interrupt.isInterrupt(interrupt) &&
12
12
  typeof interrupt.code === "string" &&
13
- interrupt.code.startsWith("DEVICE_"));
13
+ (this.code === interrupt.code ||
14
+ (!this.code && interrupt.code.startsWith("DEVICE_"))));
14
15
  }
15
16
  static hasRequestData(interrupt) {
16
17
  return DeviceInterrupt.isInterrupt(interrupt) && "response" in interrupt;
@@ -1 +1 @@
1
- {"version":3,"file":"DeviceInterrupts.js","sourceRoot":"","sources":["../../../src/interrupts/DeviceInterrupts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAsB,MAAM,kBAAkB,CAAC;AAMtE;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,cAAc;IACjD,YAAY,OAAe,EAAE,IAAY;QACvC,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Q,GAAR,QAAQ,CAA6B;IAGvD,CAAC;;AANa,kCAAI,GAAW,oCAA6C,CAAC;AAS7E;;GAEG;AACH,MAAM,OAAO,qBACX,SAAQ,cAAc;IAItB,YACE,OAAe,EACC,QAAqC;QAErD,KAAK,CAAC,OAAO,EAAE,6BAA6B,CAAC,IAAI,CAAC,CAAC;QAFnC,aAAQ,GAAR,QAAQ,CAA6B;IAGvD,CAAC;;AANa,0BAAI,GAAW,sBAA+B,CAAC","sourcesContent":["import { DeviceAuthorizationResponse } from \"../authorizers/device-authorizer/DeviceAuthResponse\";\nimport { Auth0Interrupt, Auth0InterruptData } from \"./Auth0Interrupt\";\n\nexport interface WithDeviceAuthResponseData {\n response: DeviceAuthorizationResponse;\n}\n\n/**\n * Base class for Device interrupts.\n */\nexport class DeviceInterrupt extends Auth0Interrupt {\n constructor(message: string, code: string) {\n super(message, code);\n }\n\n static isInterrupt<T extends abstract new (...args: any) => any>(\n this: T,\n interrupt: any\n ): interrupt is Auth0InterruptData<InstanceType<T>> {\n return (\n interrupt &&\n Auth0Interrupt.isInterrupt(interrupt) &&\n typeof interrupt.code === \"string\" &&\n interrupt.code.startsWith(\"DEVICE_\")\n );\n }\n\n static hasRequestData(\n interrupt: any\n ): interrupt is WithDeviceAuthResponseData {\n return DeviceInterrupt.isInterrupt(interrupt) && \"response\" in interrupt;\n }\n}\n\n/**\n * An interrupt that is thrown when the user denies the authorization request.\n */\nexport class AccessDeniedInterrupt\n extends DeviceInterrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_ACCESS_DENIED\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AccessDeniedInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization request has expired.\n */\nexport class AuthorizationRequestExpiredInterrupt\n extends DeviceInterrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_AUTHORIZATION_REQUEST_EXPIRED\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AuthorizationRequestExpiredInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization is still pending\n * and the Authorizer is in `mode: interrupt`.\n */\nexport class AuthorizationPendingInterrupt\n extends DeviceInterrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_AUTHORIZATION_PENDING\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AuthorizationPendingInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization polling fails.\n */\nexport class AuthorizationPollingInterrupt\n extends Auth0Interrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_AUTHORIZATION_POLLING_ERROR\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AuthorizationPollingInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the grant is invalid.\n */\nexport class InvalidGrantInterrupt\n extends Auth0Interrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_INVALID_GRANT\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AuthorizationPollingInterrupt.code);\n }\n}\n"]}
1
+ {"version":3,"file":"DeviceInterrupts.js","sourceRoot":"","sources":["../../../src/interrupts/DeviceInterrupts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAsB,MAAM,kBAAkB,CAAC;AAMtE;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,cAAc;IACjD,YAAY,OAAe,EAAE,IAAY;QACvC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,WAAW,CAEhB,SAAc;QAEd,OAAO,CACL,SAAS;YACT,cAAc,CAAC,WAAW,CAAC,SAAS,CAAC;YACrC,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ;YAClC,CAAC,IAAI,CAAC,IAAI,KAAK,SA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,OAAe,EACC,QAAqC;QAErD,KAAK,CAAC,OAAO,EAAE,6BAA6B,CAAC,IAAI,CAAC,CAAC;QAFnC,aAAQ,GAAR,QAAQ,CAA6B;IAGvD,CAAC;;AANa,0BAAI,GAAW,sBAA+B,CAAC","sourcesContent":["import { DeviceAuthorizationResponse } from \"../authorizers/device-authorizer/DeviceAuthResponse\";\nimport { Auth0Interrupt, Auth0InterruptData } from \"./Auth0Interrupt\";\n\nexport interface WithDeviceAuthResponseData {\n response: DeviceAuthorizationResponse;\n}\n\n/**\n * Base class for Device interrupts.\n */\nexport class DeviceInterrupt extends Auth0Interrupt {\n constructor(message: string, code: string) {\n super(message, code);\n }\n\n static isInterrupt<T extends abstract new (...args: any) => any>(\n this: T & { code?: string },\n interrupt: any\n ): interrupt is Auth0InterruptData<InstanceType<T>> {\n return (\n interrupt &&\n Auth0Interrupt.isInterrupt(interrupt) &&\n typeof interrupt.code === \"string\" &&\n (this.code === interrupt.code ||\n (!this.code && interrupt.code.startsWith(\"DEVICE_\")))\n );\n }\n\n static hasRequestData(\n interrupt: any\n ): interrupt is WithDeviceAuthResponseData {\n return DeviceInterrupt.isInterrupt(interrupt) && \"response\" in interrupt;\n }\n}\n\n/**\n * An interrupt that is thrown when the user denies the authorization request.\n */\nexport class AccessDeniedInterrupt\n extends DeviceInterrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_ACCESS_DENIED\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AccessDeniedInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization request has expired.\n */\nexport class AuthorizationRequestExpiredInterrupt\n extends DeviceInterrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_AUTHORIZATION_REQUEST_EXPIRED\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AuthorizationRequestExpiredInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization is still pending\n * and the Authorizer is in `mode: interrupt`.\n */\nexport class AuthorizationPendingInterrupt\n extends DeviceInterrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_AUTHORIZATION_PENDING\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AuthorizationPendingInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization polling fails.\n */\nexport class AuthorizationPollingInterrupt\n extends Auth0Interrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_AUTHORIZATION_POLLING_ERROR\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AuthorizationPollingInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the grant is invalid.\n */\nexport class InvalidGrantInterrupt\n extends Auth0Interrupt\n implements WithDeviceAuthResponseData\n{\n public static code: string = \"DEVICE_INVALID_GRANT\" as const;\n constructor(\n message: string,\n public readonly response: DeviceAuthorizationResponse\n ) {\n super(message, AuthorizationPollingInterrupt.code);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auth0/ai",
3
- "version": "2.1.0",
3
+ "version": "3.0.0",
4
4
  "description": "Auth0AI SDK for JavaScript",
5
5
  "types": "dist/esm/index.d.ts",
6
6
  "main": "dist/cjs/index.js",