@auth0/ai 1.0.1 → 2.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.
Files changed (141) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/authorizers/ciba/CIBAAuthorizerBase.js +81 -55
  3. package/dist/cjs/authorizers/ciba/CIBAAuthorizerBase.js.map +1 -1
  4. package/dist/cjs/authorizers/ciba/CIBAAuthorizerParams.js.map +1 -1
  5. package/dist/cjs/authorizers/ciba/asyncLocalStorage.js +1 -1
  6. package/dist/cjs/authorizers/ciba/asyncLocalStorage.js.map +1 -1
  7. package/dist/cjs/authorizers/context.js +20 -0
  8. package/dist/cjs/authorizers/context.js.map +1 -0
  9. package/dist/cjs/authorizers/device-authorizer/DeviceAuthResponse.js +18 -0
  10. package/dist/cjs/authorizers/device-authorizer/DeviceAuthResponse.js.map +1 -0
  11. package/dist/cjs/authorizers/device-authorizer/DeviceAuthorizerBase.js +231 -0
  12. package/dist/cjs/authorizers/device-authorizer/DeviceAuthorizerBase.js.map +1 -0
  13. package/dist/cjs/{TokenResponse.js → authorizers/device-authorizer/DeviceAuthorizerParams.js} +1 -1
  14. package/dist/cjs/authorizers/device-authorizer/DeviceAuthorizerParams.js.map +1 -0
  15. package/dist/cjs/authorizers/device-authorizer/asyncLocalStorage.js +14 -0
  16. package/dist/cjs/authorizers/device-authorizer/asyncLocalStorage.js.map +1 -0
  17. package/dist/cjs/authorizers/device-authorizer/index.js +9 -0
  18. package/dist/cjs/authorizers/device-authorizer/index.js.map +1 -0
  19. package/dist/cjs/authorizers/federated-connections/FederatedConnectionAuthorizerBase.js +158 -0
  20. package/dist/cjs/authorizers/federated-connections/FederatedConnectionAuthorizerBase.js.map +1 -0
  21. package/dist/cjs/authorizers/federated-connections/FederatedConnectionAuthorizerParams.js +3 -0
  22. package/dist/cjs/authorizers/federated-connections/FederatedConnectionAuthorizerParams.js.map +1 -0
  23. package/dist/cjs/authorizers/federated-connections/asyncLocalStorage.js +5 -5
  24. package/dist/cjs/authorizers/federated-connections/asyncLocalStorage.js.map +1 -1
  25. package/dist/cjs/authorizers/federated-connections/index.js +5 -125
  26. package/dist/cjs/authorizers/federated-connections/index.js.map +1 -1
  27. package/dist/cjs/authorizers/index.js.map +1 -1
  28. package/dist/cjs/authorizers/types.js +14 -0
  29. package/dist/cjs/authorizers/types.js.map +1 -0
  30. package/dist/cjs/credentials.js +13 -0
  31. package/dist/cjs/credentials.js.map +1 -1
  32. package/dist/cjs/index.js +0 -1
  33. package/dist/cjs/index.js.map +1 -1
  34. package/dist/cjs/interrupts/Auth0Interrupt.js +2 -1
  35. package/dist/cjs/interrupts/Auth0Interrupt.js.map +1 -1
  36. package/dist/cjs/interrupts/DeviceInterrupts.js +79 -0
  37. package/dist/cjs/interrupts/DeviceInterrupts.js.map +1 -0
  38. package/dist/cjs/interrupts/index.js +37 -1
  39. package/dist/cjs/interrupts/index.js.map +1 -1
  40. package/dist/cjs/stores/Store.js +12 -0
  41. package/dist/cjs/stores/Store.js.map +1 -0
  42. package/dist/cjs/stores/SubStore.js +52 -0
  43. package/dist/cjs/stores/SubStore.js.map +1 -0
  44. package/dist/cjs/stores/impl/FSStore.js +80 -0
  45. package/dist/cjs/stores/impl/FSStore.js.map +1 -0
  46. package/dist/cjs/stores/impl/MemoryStore.js +15 -0
  47. package/dist/cjs/stores/impl/MemoryStore.js.map +1 -0
  48. package/dist/cjs/stores/impl/TempBoxStore.js +22 -0
  49. package/dist/cjs/stores/impl/TempBoxStore.js.map +1 -0
  50. package/dist/cjs/stores/index.js +10 -0
  51. package/dist/cjs/stores/index.js.map +1 -0
  52. package/dist/cjs/util/index.js +12 -0
  53. package/dist/cjs/util/index.js.map +1 -0
  54. package/dist/esm/authorizers/ciba/CIBAAuthorizerBase.d.ts +12 -8
  55. package/dist/esm/authorizers/ciba/CIBAAuthorizerBase.js +78 -55
  56. package/dist/esm/authorizers/ciba/CIBAAuthorizerBase.js.map +1 -1
  57. package/dist/esm/authorizers/ciba/CIBAAuthorizerParams.d.ts +20 -20
  58. package/dist/esm/authorizers/ciba/CIBAAuthorizerParams.js.map +1 -1
  59. package/dist/esm/authorizers/ciba/asyncLocalStorage.d.ts +7 -3
  60. package/dist/esm/authorizers/ciba/asyncLocalStorage.js +1 -1
  61. package/dist/esm/authorizers/ciba/asyncLocalStorage.js.map +1 -1
  62. package/dist/esm/authorizers/context.d.ts +16 -0
  63. package/dist/esm/authorizers/context.js +16 -0
  64. package/dist/esm/authorizers/context.js.map +1 -0
  65. package/dist/esm/authorizers/device-authorizer/DeviceAuthResponse.d.ts +38 -0
  66. package/dist/esm/authorizers/device-authorizer/DeviceAuthResponse.js +15 -0
  67. package/dist/esm/authorizers/device-authorizer/DeviceAuthResponse.js.map +1 -0
  68. package/dist/esm/authorizers/device-authorizer/DeviceAuthorizerBase.d.ts +49 -0
  69. package/dist/esm/authorizers/device-authorizer/DeviceAuthorizerBase.js +224 -0
  70. package/dist/esm/authorizers/device-authorizer/DeviceAuthorizerBase.js.map +1 -0
  71. package/dist/esm/authorizers/device-authorizer/DeviceAuthorizerParams.d.ts +58 -0
  72. package/dist/esm/authorizers/device-authorizer/DeviceAuthorizerParams.js +2 -0
  73. package/dist/esm/authorizers/device-authorizer/DeviceAuthorizerParams.js.map +1 -0
  74. package/dist/esm/authorizers/device-authorizer/asyncLocalStorage.d.ts +16 -0
  75. package/dist/esm/authorizers/device-authorizer/asyncLocalStorage.js +10 -0
  76. package/dist/esm/authorizers/device-authorizer/asyncLocalStorage.js.map +1 -0
  77. package/dist/esm/authorizers/device-authorizer/index.d.ts +4 -0
  78. package/dist/esm/authorizers/device-authorizer/index.js +3 -0
  79. package/dist/esm/authorizers/device-authorizer/index.js.map +1 -0
  80. package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerBase.d.ts +30 -0
  81. package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerBase.js +151 -0
  82. package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerBase.js.map +1 -0
  83. package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerParams.d.ts +38 -0
  84. package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerParams.js +2 -0
  85. package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerParams.js.map +1 -0
  86. package/dist/esm/authorizers/federated-connections/asyncLocalStorage.d.ts +7 -5
  87. package/dist/esm/authorizers/federated-connections/asyncLocalStorage.js +3 -3
  88. package/dist/esm/authorizers/federated-connections/asyncLocalStorage.js.map +1 -1
  89. package/dist/esm/authorizers/federated-connections/index.d.ts +3 -36
  90. package/dist/esm/authorizers/federated-connections/index.js +2 -122
  91. package/dist/esm/authorizers/federated-connections/index.js.map +1 -1
  92. package/dist/esm/authorizers/index.d.ts +1 -12
  93. package/dist/esm/authorizers/index.js.map +1 -1
  94. package/dist/esm/authorizers/types.d.ts +37 -0
  95. package/dist/esm/authorizers/types.js +11 -0
  96. package/dist/esm/authorizers/types.js.map +1 -0
  97. package/dist/esm/credentials.d.ts +33 -8
  98. package/dist/esm/credentials.js +11 -1
  99. package/dist/esm/credentials.js.map +1 -1
  100. package/dist/esm/index.d.ts +1 -3
  101. package/dist/esm/index.js +0 -1
  102. package/dist/esm/index.js.map +1 -1
  103. package/dist/esm/interrupts/Auth0Interrupt.js +2 -1
  104. package/dist/esm/interrupts/Auth0Interrupt.js.map +1 -1
  105. package/dist/esm/interrupts/DeviceInterrupts.d.ts +55 -0
  106. package/dist/esm/interrupts/DeviceInterrupts.js +70 -0
  107. package/dist/esm/interrupts/DeviceInterrupts.js.map +1 -0
  108. package/dist/esm/interrupts/index.d.ts +2 -0
  109. package/dist/esm/interrupts/index.js +2 -0
  110. package/dist/esm/interrupts/index.js.map +1 -1
  111. package/dist/esm/stores/Store.d.ts +40 -0
  112. package/dist/esm/stores/Store.js +11 -0
  113. package/dist/esm/stores/Store.js.map +1 -0
  114. package/dist/esm/stores/SubStore.d.ts +31 -0
  115. package/dist/esm/stores/SubStore.js +48 -0
  116. package/dist/esm/stores/SubStore.js.map +1 -0
  117. package/dist/esm/stores/impl/FSStore.d.ts +19 -0
  118. package/dist/esm/stores/impl/FSStore.js +72 -0
  119. package/dist/esm/stores/impl/FSStore.js.map +1 -0
  120. package/dist/esm/stores/impl/MemoryStore.d.ts +8 -0
  121. package/dist/esm/stores/impl/MemoryStore.js +11 -0
  122. package/dist/esm/stores/impl/MemoryStore.js.map +1 -0
  123. package/dist/esm/stores/impl/TempBoxStore.d.ts +13 -0
  124. package/dist/esm/stores/impl/TempBoxStore.js +18 -0
  125. package/dist/esm/stores/impl/TempBoxStore.js.map +1 -0
  126. package/dist/esm/stores/index.d.ts +5 -0
  127. package/dist/esm/stores/index.js +4 -0
  128. package/dist/esm/stores/index.js.map +1 -0
  129. package/dist/esm/util/index.d.ts +3 -0
  130. package/dist/esm/util/index.js +8 -0
  131. package/dist/esm/util/index.js.map +1 -0
  132. package/package.json +20 -4
  133. package/dist/cjs/TokenResponse.js.map +0 -1
  134. package/dist/cjs/authorizers/device-authorizer.js +0 -130
  135. package/dist/cjs/authorizers/device-authorizer.js.map +0 -1
  136. package/dist/esm/TokenResponse.d.ts +0 -15
  137. package/dist/esm/TokenResponse.js +0 -2
  138. package/dist/esm/TokenResponse.js.map +0 -1
  139. package/dist/esm/authorizers/device-authorizer.d.ts +0 -15
  140. package/dist/esm/authorizers/device-authorizer.js +0 -90
  141. package/dist/esm/authorizers/device-authorizer.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FederatedConnectionAuthorizerParams.js","sourceRoot":"","sources":["../../../../src/authorizers/federated-connections/FederatedConnectionAuthorizerParams.ts"],"names":[],"mappings":"","sourcesContent":["import { TokenResponse } from \"../../credentials\";\nimport { AuthorizerToolParameter } from \"../../parameters\";\nimport { Store } from \"../../stores\";\nimport { AuthContext } from \"../context\";\n\nexport type FederatedConnectionAuthorizerParams<ToolExecuteArgs extends any[]> =\n {\n /**\n * The Auth0 refresh token to exchange for an Federated Connection access token.\n */\n refreshToken?: AuthorizerToolParameter<ToolExecuteArgs, string | undefined>;\n\n /**\n * The Federated connection access token if available in the tool context.\n */\n accessToken?: AuthorizerToolParameter<\n ToolExecuteArgs,\n TokenResponse | undefined\n >;\n\n /**\n * The scopes required in the access token of the federated connection provider.\n */\n scopes: string[];\n\n /**\n * The connection name of the federated connection provider.\n */\n connection: string;\n\n /**\n * AuthContext defines the scope of credential sharing:\n * - \"tool-call\": Credentials are valid only for a single invocation of the tool.\n * - \"tool\": Credentials are shared across multiple calls to the same tool within the same thread.\n * - \"thread\": Credentials are shared across all tools using the same authorizer within the current thread.\n * - \"agent\": Credentials are shared globally across all threads and tools in the agent.\n *\n * @default \"thread\"\n */\n credentialsContext?: AuthContext;\n\n /**\n * An store used to store the authorization credentials according\n * to the `credentialsContext` scope.\n */\n store: Store;\n };\n"]}
@@ -1,13 +1,15 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
- export type AsyncStorageValue<TContext> = {
2
+ import { TokenSet } from "../../credentials";
3
+ import { ToolCallContext } from "../context";
4
+ export type AsyncStorageValue = {
3
5
  /**
4
6
  * The Federated Connection access token.
5
7
  */
6
- accessToken?: string;
8
+ credentials?: TokenSet;
7
9
  /**
8
10
  * The tool execution context.
9
11
  */
10
- context: TContext;
12
+ context: ToolCallContext;
11
13
  /**
12
14
  * The federated connection name.
13
15
  */
@@ -21,6 +23,6 @@ export type AsyncStorageValue<TContext> = {
21
23
  */
22
24
  currentScopes?: string[];
23
25
  };
24
- export declare const asyncLocalStorage: AsyncLocalStorage<AsyncStorageValue<any>>;
25
- export declare const getAccessTokenForConnection: () => string | undefined;
26
+ export declare const asyncLocalStorage: AsyncLocalStorage<AsyncStorageValue>;
27
+ export declare const getCredentialsForConnection: () => TokenSet | undefined;
26
28
  //# sourceMappingURL=asyncLocalStorage.d.ts.map
@@ -1,10 +1,10 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
2
  export const asyncLocalStorage = new AsyncLocalStorage();
3
- export const getAccessTokenForConnection = () => {
3
+ export const getCredentialsForConnection = () => {
4
4
  const store = asyncLocalStorage.getStore();
5
5
  if (typeof store === "undefined") {
6
- throw new Error("The tool must be wrapped with the withFederatedConnections function.");
6
+ throw new Error("The tool must be wrapped with the withTokenForConnections function.");
7
7
  }
8
- return store === null || store === void 0 ? void 0 : store.accessToken;
8
+ return store === null || store === void 0 ? void 0 : store.credentials;
9
9
  };
10
10
  //# 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;AA6BrD,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAEnD,CAAC;AAEJ,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,sEAAsE,CACvE,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,WAAW,CAAC;AAC5B,CAAC,CAAC","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nexport type AsyncStorageValue<TContext> = {\n /**\n * The Federated Connection access token.\n */\n accessToken?: string;\n\n /**\n * The tool execution context.\n */\n context: TContext;\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<\n AsyncStorageValue<any>\n>();\n\nexport const getAccessTokenForConnection = () => {\n const store = asyncLocalStorage.getStore();\n if (typeof store === \"undefined\") {\n throw new Error(\n \"The tool must be wrapped with the withFederatedConnections function.\"\n );\n }\n return store?.accessToken;\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;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,38 +1,5 @@
1
- import { Auth0Interrupt } from "../../interrupts";
2
- import { AuthorizerToolParameter } from "../../parameters";
3
- import { TokenResponse } from "../../TokenResponse";
4
1
  export type { AsyncStorageValue } from "./asyncLocalStorage";
5
- export { asyncLocalStorage, getAccessTokenForConnection, } from "./asyncLocalStorage";
6
- export type FederatedConnectionAuthorizerParams<ToolExecuteArgs extends any[]> = {
7
- refreshToken?: AuthorizerToolParameter<ToolExecuteArgs, string | undefined>;
8
- accessToken?: AuthorizerToolParameter<ToolExecuteArgs, TokenResponse | undefined>;
9
- scopes: AuthorizerToolParameter<ToolExecuteArgs, string[]>;
10
- connection: AuthorizerToolParameter<ToolExecuteArgs, string>;
11
- };
12
- /**
13
- * Requests authorization to a third party service via Federated Connection.
14
- */
15
- export declare class FederatedConnectionAuthorizerBase<ToolExecuteArgs extends any[]> {
16
- private readonly auth0;
17
- private params;
18
- constructor(auth0: {
19
- domain: string;
20
- clientId: string;
21
- clientSecret: string | undefined;
22
- }, params: FederatedConnectionAuthorizerParams<ToolExecuteArgs>);
23
- protected handleAuthorizationInterrupts(err: Auth0Interrupt): void;
24
- protected validateToken(tokenResponse?: TokenResponse): void;
25
- private getAccessTokenImpl;
26
- protected getAccessToken(...toolContext: ToolExecuteArgs): Promise<TokenResponse | undefined>;
27
- protected getRefreshToken(...toolContext: ToolExecuteArgs): Promise<string | undefined>;
28
- /**
29
- *
30
- * Wraps the execute method of an AI tool to handle Federated Connections authorization.
31
- *
32
- * @param getContext - A function that returns the context of the tool execution.
33
- * @param execute - The tool execute method.
34
- * @returns The wrapped execute method.
35
- */
36
- protect(getContext: (...args: ToolExecuteArgs) => any, execute: (...args: ToolExecuteArgs) => any): (...args: ToolExecuteArgs) => any;
37
- }
2
+ export { asyncLocalStorage, getCredentialsForConnection as getAccessTokenForConnection, } from "./asyncLocalStorage";
3
+ export { FederatedConnectionAuthorizerBase } from "./FederatedConnectionAuthorizerBase";
4
+ export type { FederatedConnectionAuthorizerParams } from "./FederatedConnectionAuthorizerParams";
38
5
  //# sourceMappingURL=index.d.ts.map
@@ -1,123 +1,3 @@
1
- import { Auth0Interrupt, FederatedConnectionError, FederatedConnectionInterrupt, } from "../../interrupts";
2
- import { resolveParameter } from "../../parameters";
3
- import { asyncLocalStorage } from "./asyncLocalStorage";
4
- export { asyncLocalStorage, getAccessTokenForConnection, } from "./asyncLocalStorage";
5
- /**
6
- * Requests authorization to a third party service via Federated Connection.
7
- */
8
- export class FederatedConnectionAuthorizerBase {
9
- constructor(auth0, params) {
10
- this.auth0 = auth0;
11
- this.params = params;
12
- if (typeof params.refreshToken === "undefined" &&
13
- typeof params.accessToken === "undefined") {
14
- throw new Error("Either refreshToken or accessToken must be provided to initialize the Authorizer.");
15
- }
16
- if (typeof params.accessToken !== "undefined" &&
17
- typeof params.refreshToken !== "undefined") {
18
- throw new Error("Only one of refreshToken or accessToken can be provided to initialize the Authorizer.");
19
- }
20
- }
21
- handleAuthorizationInterrupts(err) {
22
- throw err;
23
- }
24
- validateToken(tokenResponse) {
25
- var _a;
26
- const store = asyncLocalStorage.getStore();
27
- if (!store) {
28
- throw new Error("The tool must be wrapped with the FederationConnectionAuthorizer.");
29
- }
30
- const { scopes, connection } = store;
31
- if (!tokenResponse) {
32
- throw new FederatedConnectionInterrupt(`Authorization required to access the Federated Connection: ${this.params.connection}`, connection, scopes, scopes);
33
- }
34
- const currentScopes = ((_a = tokenResponse.scope) !== null && _a !== void 0 ? _a : "").split(" ");
35
- const missingScopes = scopes.filter((s) => !currentScopes.includes(s));
36
- store.currentScopes = currentScopes;
37
- if (missingScopes.length > 0) {
38
- throw new FederatedConnectionInterrupt(`Authorization required to access the Federated Connection: ${this.params.connection}. Missing scopes: ${missingScopes.join(", ")}`, connection, scopes, [...currentScopes, ...scopes]);
39
- }
40
- }
41
- async getAccessTokenImpl(...toolContext) {
42
- const store = asyncLocalStorage.getStore();
43
- if (!store) {
44
- throw new Error("The tool must be wrapped with the FederationConnectionAuthorizer.");
45
- }
46
- const { connection } = store;
47
- const subjectToken = await this.getRefreshToken(...toolContext);
48
- if (!subjectToken) {
49
- return;
50
- }
51
- const exchangeParams = {
52
- grant_type: "urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token",
53
- client_id: this.auth0.clientId,
54
- client_secret: this.auth0.clientSecret,
55
- subject_token_type: "urn:ietf:params:oauth:token-type:refresh_token",
56
- subject_token: subjectToken,
57
- connection: connection,
58
- requested_token_type: "http://auth0.com/oauth/token-type/federated-connection-access-token",
59
- };
60
- const res = await fetch(`https://${this.auth0.domain}/oauth/token`, {
61
- method: "POST",
62
- headers: { "Content-Type": "application/json" },
63
- body: JSON.stringify(exchangeParams),
64
- });
65
- if (!res.ok) {
66
- return;
67
- }
68
- const tokenResponse = await res.json();
69
- return tokenResponse;
70
- }
71
- async getAccessToken(...toolContext) {
72
- let tokenResponse;
73
- if (typeof this.params.refreshToken === "function") {
74
- tokenResponse = await this.getAccessTokenImpl(...toolContext);
75
- }
76
- else {
77
- tokenResponse = await resolveParameter(this.params.accessToken, toolContext);
78
- }
79
- this.validateToken(tokenResponse);
80
- return tokenResponse;
81
- }
82
- async getRefreshToken(...toolContext) {
83
- return await resolveParameter(this.params.refreshToken, toolContext);
84
- }
85
- /**
86
- *
87
- * Wraps the execute method of an AI tool to handle Federated Connections authorization.
88
- *
89
- * @param getContext - A function that returns the context of the tool execution.
90
- * @param execute - The tool execute method.
91
- * @returns The wrapped execute method.
92
- */
93
- protect(getContext, execute) {
94
- return async (...args) => {
95
- const asyncStore = {
96
- context: await getContext(...args),
97
- scopes: await resolveParameter(this.params.scopes, args),
98
- connection: await resolveParameter(this.params.connection, args),
99
- };
100
- if (asyncLocalStorage.getStore()) {
101
- throw new Error("Cannot nest tool calls that require federated connection authorization.");
102
- }
103
- return asyncLocalStorage.run(asyncStore, async () => {
104
- try {
105
- const tokenResponse = await this.getAccessToken(...args);
106
- asyncStore.accessToken = tokenResponse.access_token;
107
- return await execute(...args);
108
- }
109
- catch (err) {
110
- if (err instanceof FederatedConnectionError) {
111
- const interrupt = new FederatedConnectionInterrupt(err.message, asyncStore.connection, asyncStore.scopes, asyncStore.scopes);
112
- return this.handleAuthorizationInterrupts(interrupt);
113
- }
114
- if (err instanceof Auth0Interrupt) {
115
- return this.handleAuthorizationInterrupts(err);
116
- }
117
- throw err;
118
- }
119
- });
120
- };
121
- }
122
- }
1
+ export { asyncLocalStorage, getCredentialsForConnection as getAccessTokenForConnection, } from "./asyncLocalStorage";
2
+ export { FederatedConnectionAuthorizerBase } from "./FederatedConnectionAuthorizerBase";
123
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/authorizers/federated-connections/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,4BAA4B,GAC7B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAA2B,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE7E,OAAO,EAAE,iBAAiB,EAAqB,MAAM,qBAAqB,CAAC;AAI3E,OAAO,EACL,iBAAiB,EACjB,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAa7B;;GAEG;AACH,MAAM,OAAO,iCAAiC;IAC5C,YACmB,KAIhB,EACO,MAA4D;QALnD,UAAK,GAAL,KAAK,CAIrB;QACO,WAAM,GAAN,MAAM,CAAsD;QAEpE,IACE,OAAO,MAAM,CAAC,YAAY,KAAK,WAAW;YAC1C,OAAO,MAAM,CAAC,WAAW,KAAK,WAAW,EACzC,CAAC;YACD,MAAM,IAAI,KAAK,CACb,mFAAmF,CACpF,CAAC;QACJ,CAAC;QAED,IACE,OAAO,MAAM,CAAC,WAAW,KAAK,WAAW;YACzC,OAAO,MAAM,CAAC,YAAY,KAAK,WAAW,EAC1C,CAAC;YACD,MAAM,IAAI,KAAK,CACb,uFAAuF,CACxF,CAAC;QACJ,CAAC;IACH,CAAC;IAES,6BAA6B,CAAC,GAAmB;QACzD,MAAM,GAAG,CAAC;IACZ,CAAC;IAES,aAAa,CAAC,aAA6B;;QACnD,MAAM,KAAK,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAC;QAC3C,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,I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YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;CACF","sourcesContent":["import {\n Auth0Interrupt,\n FederatedConnectionError,\n FederatedConnectionInterrupt,\n} from \"../../interrupts\";\nimport { AuthorizerToolParameter, resolveParameter } from \"../../parameters\";\nimport { TokenResponse } from \"../../TokenResponse\";\nimport { asyncLocalStorage, AsyncStorageValue } from \"./asyncLocalStorage\";\n\nexport type { AsyncStorageValue } from \"./asyncLocalStorage\";\n\nexport {\n asyncLocalStorage,\n getAccessTokenForConnection,\n} from \"./asyncLocalStorage\";\n\nexport type FederatedConnectionAuthorizerParams<ToolExecuteArgs extends any[]> =\n {\n refreshToken?: AuthorizerToolParameter<ToolExecuteArgs, string | undefined>;\n accessToken?: AuthorizerToolParameter<\n ToolExecuteArgs,\n TokenResponse | undefined\n >;\n scopes: AuthorizerToolParameter<ToolExecuteArgs, string[]>;\n connection: AuthorizerToolParameter<ToolExecuteArgs, string>;\n };\n\n/**\n * Requests authorization to a third party service via Federated Connection.\n */\nexport class FederatedConnectionAuthorizerBase<ToolExecuteArgs extends any[]> {\n constructor(\n private readonly auth0: {\n domain: string;\n clientId: string;\n clientSecret: string | undefined;\n },\n private params: FederatedConnectionAuthorizerParams<ToolExecuteArgs>\n ) {\n if (\n typeof params.refreshToken === \"undefined\" &&\n typeof params.accessToken === \"undefined\"\n ) {\n throw new Error(\n \"Either refreshToken or accessToken must be provided to initialize the Authorizer.\"\n );\n }\n\n if (\n typeof params.accessToken !== \"undefined\" &&\n typeof params.refreshToken !== \"undefined\"\n ) {\n throw new Error(\n \"Only one of refreshToken or accessToken can be provided to initialize the Authorizer.\"\n );\n }\n }\n\n protected handleAuthorizationInterrupts(err: Auth0Interrupt) {\n throw err;\n }\n\n protected validateToken(tokenResponse?: TokenResponse) {\n const store = asyncLocalStorage.getStore();\n if (!store) {\n throw new Error(\n \"The tool must be wrapped with the FederationConnectionAuthorizer.\"\n );\n }\n\n const { scopes, connection } = store;\n\n if (!tokenResponse) {\n throw new FederatedConnectionInterrupt(\n `Authorization required to access the Federated Connection: ${this.params.connection}`,\n connection,\n scopes,\n scopes\n );\n }\n\n const currentScopes = (tokenResponse.scope ?? \"\").split(\" \");\n const missingScopes = scopes.filter((s) => !currentScopes.includes(s));\n store.currentScopes = currentScopes;\n\n if (missingScopes.length > 0) {\n throw new FederatedConnectionInterrupt(\n `Authorization required to access the Federated Connection: ${\n this.params.connection\n }. Missing scopes: ${missingScopes.join(\", \")}`,\n connection,\n scopes,\n [...currentScopes, ...scopes]\n );\n }\n }\n\n private async getAccessTokenImpl(\n ...toolContext: ToolExecuteArgs\n ): Promise<TokenResponse | undefined> {\n const store = asyncLocalStorage.getStore();\n if (!store) {\n throw new Error(\n \"The tool must be wrapped with the FederationConnectionAuthorizer.\"\n );\n }\n\n const { connection } = store;\n\n const subjectToken = await this.getRefreshToken(...toolContext);\n\n if (!subjectToken) {\n return;\n }\n\n const exchangeParams = {\n grant_type:\n \"urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token\",\n client_id: this.auth0.clientId,\n client_secret: this.auth0.clientSecret,\n subject_token_type: \"urn:ietf:params:oauth:token-type:refresh_token\",\n subject_token: subjectToken,\n connection: connection,\n requested_token_type:\n \"http://auth0.com/oauth/token-type/federated-connection-access-token\",\n };\n\n const res = await fetch(`https://${this.auth0.domain}/oauth/token`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(exchangeParams),\n });\n\n if (!res.ok) {\n return;\n }\n\n const tokenResponse: TokenResponse = await res.json();\n return tokenResponse;\n }\n\n protected async getAccessToken(\n ...toolContext: ToolExecuteArgs\n ): Promise<TokenResponse | undefined> {\n let tokenResponse: TokenResponse | undefined;\n if (typeof this.params.refreshToken === \"function\") {\n tokenResponse = await this.getAccessTokenImpl(...toolContext);\n } else {\n tokenResponse = await resolveParameter(\n this.params.accessToken!,\n toolContext\n );\n }\n this.validateToken(tokenResponse);\n return tokenResponse;\n }\n\n protected async getRefreshToken(...toolContext: ToolExecuteArgs) {\n return await resolveParameter(this.params.refreshToken, toolContext);\n }\n\n /**\n *\n * Wraps the execute method of an AI tool to handle Federated Connections authorization.\n *\n * @param getContext - A function that returns the context of the tool execution.\n * @param execute - The tool execute method.\n * @returns The wrapped execute method.\n */\n protect(\n getContext: (...args: ToolExecuteArgs) => any,\n execute: (...args: ToolExecuteArgs) => any\n ): (...args: ToolExecuteArgs) => any {\n return async (...args: ToolExecuteArgs) => {\n const asyncStore: AsyncStorageValue<any> = {\n context: await getContext(...args),\n scopes: await resolveParameter(this.params.scopes, args),\n connection: await resolveParameter(this.params.connection, args),\n };\n\n if (asyncLocalStorage.getStore()) {\n throw new Error(\n \"Cannot nest tool calls that require federated connection authorization.\"\n );\n }\n\n return asyncLocalStorage.run(asyncStore, async () => {\n try {\n const tokenResponse = await this.getAccessToken(...args);\n asyncStore.accessToken = tokenResponse!.access_token;\n return await execute(...args);\n } catch (err) {\n if (err instanceof FederatedConnectionError) {\n const interrupt = new FederatedConnectionInterrupt(\n err.message,\n asyncStore.connection,\n asyncStore.scopes,\n asyncStore.scopes\n );\n return this.handleAuthorizationInterrupts(interrupt);\n }\n if (err instanceof Auth0Interrupt) {\n return this.handleAuthorizationInterrupts(err);\n }\n throw err;\n }\n });\n };\n }\n}\n"]}
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,13 +1,2 @@
1
- import { AuthenticationClientOptions } from "auth0";
2
- import * as jose from "jose";
3
- export type AuthParams = {
4
- allowed?: boolean;
5
- accessToken?: string;
6
- claims?: jose.JWTPayload;
7
- };
8
- export type ToolWithAuthHandler<I, O, C> = (authParams: AuthParams, input: I, config?: C) => Promise<O>;
9
- export type AuthorizerParams = Omit<AuthenticationClientOptions, "domain" | "clientId"> & {
10
- domain?: string;
11
- clientId?: string;
12
- };
1
+ export type { ContextGetter } from "./context";
13
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/authorizers/index.ts"],"names":[],"mappings":"","sourcesContent":["import { AuthenticationClientOptions } from \"auth0\";\nimport * as jose from \"jose\";\n\nexport type AuthParams = {\n allowed?: boolean;\n accessToken?: string;\n claims?: jose.JWTPayload;\n};\n\nexport type ToolWithAuthHandler<I, O, C> = (\n authParams: AuthParams,\n input: I,\n config?: C\n) => Promise<O>;\n\nexport type AuthorizerParams = Omit<\n AuthenticationClientOptions,\n \"domain\" | \"clientId\"\n> & {\n domain?: string;\n clientId?: string;\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/authorizers/index.ts"],"names":[],"mappings":"","sourcesContent":["export type { ContextGetter } from \"./context\";\n"]}
@@ -0,0 +1,37 @@
1
+ import { AuthenticationClientOptions } from "auth0";
2
+ import * as jose from "jose";
3
+ import { z } from "zod";
4
+ export type AuthParams = {
5
+ allowed?: boolean;
6
+ accessToken?: string;
7
+ claims?: jose.JWTPayload;
8
+ };
9
+ export type ToolWithAuthHandler<I, O, C> = (authParams: AuthParams, input: I, config?: C) => Promise<O>;
10
+ export declare const Auth0ClientSchema: z.ZodObject<{
11
+ domain: z.ZodDefault<z.ZodString>;
12
+ clientId: z.ZodDefault<z.ZodString>;
13
+ clientSecret: z.ZodDefault<z.ZodString>;
14
+ }, "strip", z.ZodTypeAny, {
15
+ domain: string;
16
+ clientId: string;
17
+ clientSecret: string;
18
+ }, {
19
+ domain?: string | undefined;
20
+ clientId?: string | undefined;
21
+ clientSecret?: string | undefined;
22
+ }>;
23
+ export declare const Auth0PublicClientSchema: z.ZodObject<{
24
+ domain: z.ZodDefault<z.ZodString>;
25
+ clientId: z.ZodDefault<z.ZodString>;
26
+ }, "strip", z.ZodTypeAny, {
27
+ domain: string;
28
+ clientId: string;
29
+ }, {
30
+ domain?: string | undefined;
31
+ clientId?: string | undefined;
32
+ }>;
33
+ export type Auth0ClientParams = z.infer<typeof Auth0ClientSchema>;
34
+ export type Auth0PublicClientParams = z.infer<typeof Auth0PublicClientSchema>;
35
+ export type AuthorizerParams = Pick<AuthenticationClientOptions, "domain" | "clientId" | "clientSecret">;
36
+ export type OnAuthorizationRequest = "block" | "interrupt";
37
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,11 @@
1
+ import { z } from "zod";
2
+ export const Auth0ClientSchema = z.object({
3
+ domain: z.string().default(() => process.env.AUTH0_DOMAIN),
4
+ clientId: z.string().default(() => process.env.AUTH0_CLIENT_ID),
5
+ clientSecret: z.string().default(() => process.env.AUTH0_CLIENT_SECRET),
6
+ });
7
+ export const Auth0PublicClientSchema = z.object({
8
+ domain: z.string().default(() => process.env.AUTH0_DOMAIN),
9
+ clientId: z.string().default(() => process.env.AUTH0_CLIENT_ID),
10
+ });
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/authorizers/types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAcxB,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,YAAa,CAAC;IAC3D,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,eAAgB,CAAC;IAChE,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAoB,CAAC;CACzE,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,YAAa,CAAC;IAC3D,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,eAAgB,CAAC;CACjE,CAAC,CAAC","sourcesContent":["import { AuthenticationClientOptions } from \"auth0\";\nimport * as jose from \"jose\";\nimport { z } from \"zod\";\n\nexport type AuthParams = {\n allowed?: boolean;\n accessToken?: string;\n claims?: jose.JWTPayload;\n};\n\nexport type ToolWithAuthHandler<I, O, C> = (\n authParams: AuthParams,\n input: I,\n config?: C\n) => Promise<O>;\n\nexport const Auth0ClientSchema = z.object({\n domain: z.string().default(() => process.env.AUTH0_DOMAIN!),\n clientId: z.string().default(() => process.env.AUTH0_CLIENT_ID!),\n clientSecret: z.string().default(() => process.env.AUTH0_CLIENT_SECRET!),\n});\n\nexport const Auth0PublicClientSchema = z.object({\n domain: z.string().default(() => process.env.AUTH0_DOMAIN!),\n clientId: z.string().default(() => process.env.AUTH0_CLIENT_ID!),\n});\n\nexport type Auth0ClientParams = z.infer<typeof Auth0ClientSchema>;\nexport type Auth0PublicClientParams = z.infer<typeof Auth0PublicClientSchema>;\n\nexport type AuthorizerParams = Pick<\n AuthenticationClientOptions,\n \"domain\" | \"clientId\" | \"clientSecret\"\n>;\n\nexport type OnAuthorizationRequest = \"block\" | \"interrupt\";\n"]}
@@ -1,10 +1,35 @@
1
- export interface Credential {
2
- type: string;
3
- value: string;
4
- }
5
- export interface Credentials {
6
- idToken?: Credential;
7
- accessToken: Credential;
8
- refreshToken?: Credential;
1
+ export type TokenResponse = {
2
+ /** Bearer token for API authorization */
3
+ access_token: string;
4
+ /** Refresh token (requires `offline_access` scope) */
5
+ refresh_token?: string;
6
+ /** JWT containing user identity claims */
7
+ id_token: string;
8
+ /** Typically "Bearer" */
9
+ token_type?: string;
10
+ /** Token validity in seconds (default: 86400) */
11
+ expires_in: number;
12
+ /** Granted permissions space */
13
+ scope: string;
14
+ };
15
+ /**
16
+ * Represents a set of authentication tokens returned after a successful authentication flow.
17
+ *
18
+ * @interface TokenSet
19
+ * @property {string[]} [scopes] - Optional array of permission scopes granted for the token.
20
+ * @property {string} [idToken] - Optional JWT ID token containing user claims.
21
+ * @property {string} [refreshToken] - Optional token used to obtain new access tokens without re-authentication.
22
+ * @property {number} [expiresIn] - Optional time in seconds until the access token expires.
23
+ * @property {string} accessToken - The access token string used for API requests.
24
+ * @property {string} tokenType - The type of the token, typically "Bearer".
25
+ */
26
+ export interface TokenSet {
27
+ scopes?: string[];
28
+ idToken?: string;
29
+ refreshToken?: string;
30
+ expiresIn?: number;
31
+ accessToken: string;
32
+ tokenType: string;
9
33
  }
34
+ export declare const tokenSetFromTokenResponse: (tr: TokenResponse) => TokenSet;
10
35
  //# sourceMappingURL=credentials.d.ts.map
@@ -1,2 +1,12 @@
1
- export {};
1
+ export const tokenSetFromTokenResponse = (tr) => {
2
+ var _a;
3
+ return {
4
+ tokenType: (_a = tr.token_type) !== null && _a !== void 0 ? _a : "Bearer",
5
+ accessToken: tr.access_token,
6
+ idToken: tr.id_token,
7
+ refreshToken: tr.refresh_token,
8
+ expiresIn: tr.expires_in,
9
+ scopes: tr.scope ? tr.scope.split(" ") : undefined,
10
+ };
11
+ };
2
12
  //# sourceMappingURL=credentials.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/credentials.ts"],"names":[],"mappings":"","sourcesContent":["export interface Credential {\n type: string;\n value: string;\n}\n\nexport interface Credentials {\n idToken?: Credential;\n accessToken: Credential;\n refreshToken?: Credential;\n}\n"]}
1
+ {"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/credentials.ts"],"names":[],"mappings":"AAoCA,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,EAAiB,EAAY,EAAE;;IACvE,OAAO;QACL,SAAS,EAAE,MAAA,EAAE,CAAC,UAAU,mCAAI,QAAQ;QACpC,WAAW,EAAE,EAAE,CAAC,YAAY;QAC5B,OAAO,EAAE,EAAE,CAAC,QAAQ;QACpB,YAAY,EAAE,EAAE,CAAC,aAAa;QAC9B,SAAS,EAAE,EAAE,CAAC,UAAU;QACxB,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS;KACnD,CAAC;AACJ,CAAC,CAAC","sourcesContent":["export type TokenResponse = {\n /** Bearer token for API authorization */\n access_token: string;\n /** Refresh token (requires `offline_access` scope) */\n refresh_token?: string;\n /** JWT containing user identity claims */\n id_token: string;\n /** Typically \"Bearer\" */\n token_type?: string;\n /** Token validity in seconds (default: 86400) */\n expires_in: number;\n /** Granted permissions space */\n scope: string;\n};\n\n/**\n * Represents a set of authentication tokens returned after a successful authentication flow.\n *\n * @interface TokenSet\n * @property {string[]} [scopes] - Optional array of permission scopes granted for the token.\n * @property {string} [idToken] - Optional JWT ID token containing user claims.\n * @property {string} [refreshToken] - Optional token used to obtain new access tokens without re-authentication.\n * @property {number} [expiresIn] - Optional time in seconds until the access token expires.\n * @property {string} accessToken - The access token string used for API requests.\n * @property {string} tokenType - The type of the token, typically \"Bearer\".\n */\nexport interface TokenSet {\n scopes?: string[];\n idToken?: string;\n refreshToken?: string;\n\n expiresIn?: number;\n accessToken: string;\n tokenType: string;\n}\n\nexport const tokenSetFromTokenResponse = (tr: TokenResponse): TokenSet => {\n return {\n tokenType: tr.token_type ?? \"Bearer\",\n accessToken: tr.access_token,\n idToken: tr.id_token,\n refreshToken: tr.refresh_token,\n expiresIn: tr.expires_in,\n scopes: tr.scope ? tr.scope.split(\" \") : undefined,\n };\n};\n"]}
@@ -1,8 +1,6 @@
1
- export type { AuthParams, AuthorizerParams } from "./authorizers";
1
+ export type { AuthParams, AuthorizerParams } from "./authorizers/types";
2
2
  export type * from "./credentials";
3
- export * from "./authorizers/device-authorizer";
4
3
  export * from "./errors";
5
- export type { TokenResponse } from "./TokenResponse";
6
4
  export * from "./authorizers/fga/fga-filter";
7
5
  export * from "./authorizers/fga/fga-client";
8
6
  export * from "./parameters";
package/dist/esm/index.js CHANGED
@@ -1,4 +1,3 @@
1
- export * from "./authorizers/device-authorizer";
2
1
  export * from "./errors";
3
2
  export * from "./authorizers/fga/fga-filter";
4
3
  export * from "./authorizers/fga/fga-client";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,iCAAiC,CAAC;AAChD,cAAc,UAAU,CAAC;AAEzB,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,cAAc,CAAC","sourcesContent":["export type { AuthParams, AuthorizerParams } from \"./authorizers\";\nexport type * from \"./credentials\";\nexport * from \"./authorizers/device-authorizer\";\nexport * from \"./errors\";\nexport type { TokenResponse } from \"./TokenResponse\";\nexport * from \"./authorizers/fga/fga-filter\";\nexport * from \"./authorizers/fga/fga-client\";\nexport * from \"./parameters\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,UAAU,CAAC;AACzB,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,cAAc,CAAC","sourcesContent":["export type { AuthParams, AuthorizerParams } from \"./authorizers/types\";\nexport type * from \"./credentials\";\nexport * from \"./errors\";\nexport * from \"./authorizers/fga/fga-filter\";\nexport * from \"./authorizers/fga/fga-client\";\nexport * from \"./parameters\";\n"]}
@@ -35,7 +35,8 @@ export class Auth0Interrupt extends Error {
35
35
  * @returns - True if the interrupt is of the specified type.
36
36
  */
37
37
  static isInterrupt(interrupt) {
38
- return (interrupt.name === "AUTH0_AI_INTERRUPT" &&
38
+ return (interrupt &&
39
+ interrupt.name === "AUTH0_AI_INTERRUPT" &&
39
40
  (typeof this.code === "undefined" || interrupt.code === this.code));
40
41
  }
41
42
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Auth0Interrupt.js","sourceRoot":"","sources":["../../../src/interrupts/Auth0Interrupt.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,aAAa,GAAG,oBAA6B,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAIvC,YAAY,OAAe,EAAE,IAAY;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QAJjB,SAAI,GAAG,aAAa,CAAC;QAKnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACH,MAAM;QACJ,OAAO;YACL,GAAG,MAAM,CAAC,WAAW,CACnB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CACzB,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,QAAQ,CAC/C,CACF;YACD,OAAO,EAAE,IAAI,CAAC,OAAO;SACM,CAAC;IAChC,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,WAAW,CAEhB,SAAc;QAEd,OAAO,CACL,SAAS,CAAC,IAAI,KAAK,oBAAoB;YACvC,CAAC,OAAO,IAAI,CAAC,IAAI,KAAK,WAAW,IAAI,SAAS,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,CACnE,CAAC;IACJ,CAAC;CACF","sourcesContent":["// Define a type alias for the generalized type\nexport type Auth0InterruptData<T extends Auth0Interrupt> = Omit<\n Omit<T, keyof Error>,\n \"toJSON\"\n> & { message: string };\n\nexport const InterruptName = \"AUTH0_AI_INTERRUPT\" as const;\n\n/**\n * Auth0Interrupt is the base class for all interruptions\n * in the Auth0 AI sdk.\n *\n * It is serializable to a JSON object.\n */\nexport class Auth0Interrupt extends Error {\n name = InterruptName;\n code: string;\n\n constructor(message: string, code: string) {\n super(message);\n this.code = code;\n }\n\n /**\n *\n * Serialize the interrupt to a JSON object.\n *\n * @returns - The JSON object representation of the interrupt.\n */\n toJSON(): Auth0InterruptData<this> {\n return {\n ...Object.fromEntries(\n Object.entries(this).filter(\n ([key]) => key !== \"stack\" && key !== \"toJSON\"\n )\n ),\n message: this.message,\n } as Auth0InterruptData<this>;\n }\n\n /**\n *\n * Checks if an interrupt is of a specific type asserting its data component.\n *\n * This method assert the data part of the interrupt.\n *\n * @param clazz - The class of the interrupt to check.\n * @param interrupt - The interrupt to check.\n *\n * @returns - True if the interrupt is of the specified type.\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.name === \"AUTH0_AI_INTERRUPT\" &&\n (typeof this.code === \"undefined\" || interrupt.code === this.code)\n );\n }\n}\n"]}
1
+ {"version":3,"file":"Auth0Interrupt.js","sourceRoot":"","sources":["../../../src/interrupts/Auth0Interrupt.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,aAAa,GAAG,oBAA6B,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAIvC,YAAY,OAAe,EAAE,IAAY;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QAJjB,SAAI,GAAG,aAAa,CAAC;QAKnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACH,MAAM;QACJ,OAAO;YACL,GAAG,MAAM,CAAC,WAAW,CACnB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CACzB,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,QAAQ,CAC/C,CACF;YACD,OAAO,EAAE,IAAI,CAAC,OAAO;SACM,CAAC;IAChC,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,WAAW,CAEhB,SAAc;QAEd,OAAO,CACL,SAAS;YACT,SAAS,CAAC,IAAI,KAAK,oBAAoB;YACvC,CAAC,OAAO,IAAI,CAAC,IAAI,KAAK,WAAW,IAAI,SAAS,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,CACnE,CAAC;IACJ,CAAC;CACF","sourcesContent":["// Define a type alias for the generalized type\nexport type Auth0InterruptData<T extends Auth0Interrupt> = Omit<\n Omit<T, keyof Error>,\n \"toJSON\"\n> & { message: string };\n\nexport const InterruptName = \"AUTH0_AI_INTERRUPT\" as const;\n\n/**\n * Auth0Interrupt is the base class for all interruptions\n * in the Auth0 AI sdk.\n *\n * It is serializable to a JSON object.\n */\nexport class Auth0Interrupt extends Error {\n name = InterruptName;\n code: string;\n\n constructor(message: string, code: string) {\n super(message);\n this.code = code;\n }\n\n /**\n *\n * Serialize the interrupt to a JSON object.\n *\n * @returns - The JSON object representation of the interrupt.\n */\n toJSON(): Auth0InterruptData<this> {\n return {\n ...Object.fromEntries(\n Object.entries(this).filter(\n ([key]) => key !== \"stack\" && key !== \"toJSON\"\n )\n ),\n message: this.message,\n } as Auth0InterruptData<this>;\n }\n\n /**\n *\n * Checks if an interrupt is of a specific type asserting its data component.\n *\n * This method assert the data part of the interrupt.\n *\n * @param clazz - The class of the interrupt to check.\n * @param interrupt - The interrupt to check.\n *\n * @returns - True if the interrupt is of the specified type.\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 interrupt.name === \"AUTH0_AI_INTERRUPT\" &&\n (typeof this.code === \"undefined\" || interrupt.code === this.code)\n );\n }\n}\n"]}
@@ -0,0 +1,55 @@
1
+ import { DeviceAuthorizationResponse } from "../authorizers/device-authorizer/DeviceAuthResponse";
2
+ import { Auth0Interrupt, Auth0InterruptData } from "./Auth0Interrupt";
3
+ export interface WithDeviceAuthResponseData {
4
+ response: DeviceAuthorizationResponse;
5
+ }
6
+ /**
7
+ * Base class for Device interrupts.
8
+ */
9
+ export declare class DeviceInterrupt extends Auth0Interrupt {
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>>;
12
+ static hasRequestData(interrupt: any): interrupt is WithDeviceAuthResponseData;
13
+ }
14
+ /**
15
+ * An interrupt that is thrown when the user denies the authorization request.
16
+ */
17
+ export declare class AccessDeniedInterrupt extends DeviceInterrupt implements WithDeviceAuthResponseData {
18
+ readonly response: DeviceAuthorizationResponse;
19
+ static code: string;
20
+ constructor(message: string, response: DeviceAuthorizationResponse);
21
+ }
22
+ /**
23
+ * An interrupt that is thrown when the authorization request has expired.
24
+ */
25
+ export declare class AuthorizationRequestExpiredInterrupt extends DeviceInterrupt implements WithDeviceAuthResponseData {
26
+ readonly response: DeviceAuthorizationResponse;
27
+ static code: string;
28
+ constructor(message: string, response: DeviceAuthorizationResponse);
29
+ }
30
+ /**
31
+ * An interrupt that is thrown when the authorization is still pending
32
+ * and the Authorizer is in `mode: interrupt`.
33
+ */
34
+ export declare class AuthorizationPendingInterrupt extends DeviceInterrupt implements WithDeviceAuthResponseData {
35
+ readonly response: DeviceAuthorizationResponse;
36
+ static code: string;
37
+ constructor(message: string, response: DeviceAuthorizationResponse);
38
+ }
39
+ /**
40
+ * An interrupt that is thrown when the authorization polling fails.
41
+ */
42
+ export declare class AuthorizationPollingInterrupt extends Auth0Interrupt implements WithDeviceAuthResponseData {
43
+ readonly response: DeviceAuthorizationResponse;
44
+ static code: string;
45
+ constructor(message: string, response: DeviceAuthorizationResponse);
46
+ }
47
+ /**
48
+ * An interrupt that is thrown when the grant is invalid.
49
+ */
50
+ export declare class InvalidGrantInterrupt extends Auth0Interrupt implements WithDeviceAuthResponseData {
51
+ readonly response: DeviceAuthorizationResponse;
52
+ static code: string;
53
+ constructor(message: string, response: DeviceAuthorizationResponse);
54
+ }
55
+ //# sourceMappingURL=DeviceInterrupts.d.ts.map
@@ -0,0 +1,70 @@
1
+ import { Auth0Interrupt } from "./Auth0Interrupt";
2
+ /**
3
+ * Base class for Device interrupts.
4
+ */
5
+ export class DeviceInterrupt extends Auth0Interrupt {
6
+ constructor(message, code) {
7
+ super(message, code);
8
+ }
9
+ static isInterrupt(interrupt) {
10
+ return (interrupt &&
11
+ Auth0Interrupt.isInterrupt(interrupt) &&
12
+ typeof interrupt.code === "string" &&
13
+ interrupt.code.startsWith("DEVICE_"));
14
+ }
15
+ static hasRequestData(interrupt) {
16
+ return DeviceInterrupt.isInterrupt(interrupt) && "response" in interrupt;
17
+ }
18
+ }
19
+ /**
20
+ * An interrupt that is thrown when the user denies the authorization request.
21
+ */
22
+ export class AccessDeniedInterrupt extends DeviceInterrupt {
23
+ constructor(message, response) {
24
+ super(message, AccessDeniedInterrupt.code);
25
+ this.response = response;
26
+ }
27
+ }
28
+ AccessDeniedInterrupt.code = "DEVICE_ACCESS_DENIED";
29
+ /**
30
+ * An interrupt that is thrown when the authorization request has expired.
31
+ */
32
+ export class AuthorizationRequestExpiredInterrupt extends DeviceInterrupt {
33
+ constructor(message, response) {
34
+ super(message, AuthorizationRequestExpiredInterrupt.code);
35
+ this.response = response;
36
+ }
37
+ }
38
+ AuthorizationRequestExpiredInterrupt.code = "DEVICE_AUTHORIZATION_REQUEST_EXPIRED";
39
+ /**
40
+ * An interrupt that is thrown when the authorization is still pending
41
+ * and the Authorizer is in `mode: interrupt`.
42
+ */
43
+ export class AuthorizationPendingInterrupt extends DeviceInterrupt {
44
+ constructor(message, response) {
45
+ super(message, AuthorizationPendingInterrupt.code);
46
+ this.response = response;
47
+ }
48
+ }
49
+ AuthorizationPendingInterrupt.code = "DEVICE_AUTHORIZATION_PENDING";
50
+ /**
51
+ * An interrupt that is thrown when the authorization polling fails.
52
+ */
53
+ export class AuthorizationPollingInterrupt extends Auth0Interrupt {
54
+ constructor(message, response) {
55
+ super(message, AuthorizationPollingInterrupt.code);
56
+ this.response = response;
57
+ }
58
+ }
59
+ AuthorizationPollingInterrupt.code = "DEVICE_AUTHORIZATION_POLLING_ERROR";
60
+ /**
61
+ * An interrupt that is thrown when the grant is invalid.
62
+ */
63
+ export class InvalidGrantInterrupt extends Auth0Interrupt {
64
+ constructor(message, response) {
65
+ super(message, AuthorizationPollingInterrupt.code);
66
+ this.response = response;
67
+ }
68
+ }
69
+ InvalidGrantInterrupt.code = "DEVICE_INVALID_GRANT";
70
+ //# sourceMappingURL=DeviceInterrupts.js.map
@@ -0,0 +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,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,SAAS,CAAC,CACrC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,cAAc,CACnB,SAAc;QAEd,OAAO,eAAe,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,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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,\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,4 +1,6 @@
1
1
  export { Auth0Interrupt } from "./Auth0Interrupt";
2
2
  export { FederatedConnectionInterrupt, FederatedConnectionError, } from "./FederatedConnectionInterrupt";
3
3
  export { CIBAInterrupt, AccessDeniedInterrupt, UserDoesNotHavePushNotificationsInterrupt, AuthorizationRequestExpiredInterrupt, AuthorizationPendingInterrupt, AuthorizationPollingInterrupt, InvalidGrantInterrupt, } from "./CIBAInterrupts";
4
+ export * as DeviceInterrupts from "./DeviceInterrupts";
5
+ export { DeviceInterrupt } from "./DeviceInterrupts";
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,6 @@
1
1
  export { Auth0Interrupt } from "./Auth0Interrupt";
2
2
  export { FederatedConnectionInterrupt, FederatedConnectionError, } from "./FederatedConnectionInterrupt";
3
3
  export { CIBAInterrupt, AccessDeniedInterrupt, UserDoesNotHavePushNotificationsInterrupt, AuthorizationRequestExpiredInterrupt, AuthorizationPendingInterrupt, AuthorizationPollingInterrupt, InvalidGrantInterrupt, } from "./CIBAInterrupts";
4
+ export * as DeviceInterrupts from "./DeviceInterrupts";
5
+ export { DeviceInterrupt } from "./DeviceInterrupts";
4
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interrupts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EACL,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,yCAAyC,EACzC,oCAAoC,EACpC,6BAA6B,EAC7B,6BAA6B,EAC7B,qBAAqB,GACtB,MAAM,kBAAkB,CAAC","sourcesContent":["export { Auth0Interrupt } from \"./Auth0Interrupt\";\n\nexport {\n FederatedConnectionInterrupt,\n FederatedConnectionError,\n} from \"./FederatedConnectionInterrupt\";\n\nexport {\n CIBAInterrupt,\n AccessDeniedInterrupt,\n UserDoesNotHavePushNotificationsInterrupt,\n AuthorizationRequestExpiredInterrupt,\n AuthorizationPendingInterrupt,\n AuthorizationPollingInterrupt,\n InvalidGrantInterrupt,\n} from \"./CIBAInterrupts\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interrupts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EACL,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,yCAAyC,EACzC,oCAAoC,EACpC,6BAA6B,EAC7B,6BAA6B,EAC7B,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,gBAAgB,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { Auth0Interrupt } from \"./Auth0Interrupt\";\n\nexport {\n FederatedConnectionInterrupt,\n FederatedConnectionError,\n} from \"./FederatedConnectionInterrupt\";\n\nexport {\n CIBAInterrupt,\n AccessDeniedInterrupt,\n UserDoesNotHavePushNotificationsInterrupt,\n AuthorizationRequestExpiredInterrupt,\n AuthorizationPendingInterrupt,\n AuthorizationPollingInterrupt,\n InvalidGrantInterrupt,\n} from \"./CIBAInterrupts\";\n\nexport * as DeviceInterrupts from \"./DeviceInterrupts\";\nexport { DeviceInterrupt } from \"./DeviceInterrupts\";\n"]}