@auth0/ai 1.0.2 → 2.0.1

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 (137) 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 +161 -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/DeviceInterrupts.js +79 -0
  35. package/dist/cjs/interrupts/DeviceInterrupts.js.map +1 -0
  36. package/dist/cjs/interrupts/index.js +37 -1
  37. package/dist/cjs/interrupts/index.js.map +1 -1
  38. package/dist/cjs/stores/Store.js +12 -0
  39. package/dist/cjs/stores/Store.js.map +1 -0
  40. package/dist/cjs/stores/SubStore.js +52 -0
  41. package/dist/cjs/stores/SubStore.js.map +1 -0
  42. package/dist/cjs/stores/impl/FSStore.js +80 -0
  43. package/dist/cjs/stores/impl/FSStore.js.map +1 -0
  44. package/dist/cjs/stores/impl/MemoryStore.js +15 -0
  45. package/dist/cjs/stores/impl/MemoryStore.js.map +1 -0
  46. package/dist/cjs/stores/impl/TempBoxStore.js +22 -0
  47. package/dist/cjs/stores/impl/TempBoxStore.js.map +1 -0
  48. package/dist/cjs/stores/index.js +10 -0
  49. package/dist/cjs/stores/index.js.map +1 -0
  50. package/dist/cjs/util/index.js +12 -0
  51. package/dist/cjs/util/index.js.map +1 -0
  52. package/dist/esm/authorizers/ciba/CIBAAuthorizerBase.d.ts +12 -8
  53. package/dist/esm/authorizers/ciba/CIBAAuthorizerBase.js +78 -55
  54. package/dist/esm/authorizers/ciba/CIBAAuthorizerBase.js.map +1 -1
  55. package/dist/esm/authorizers/ciba/CIBAAuthorizerParams.d.ts +20 -20
  56. package/dist/esm/authorizers/ciba/CIBAAuthorizerParams.js.map +1 -1
  57. package/dist/esm/authorizers/ciba/asyncLocalStorage.d.ts +7 -3
  58. package/dist/esm/authorizers/ciba/asyncLocalStorage.js +1 -1
  59. package/dist/esm/authorizers/ciba/asyncLocalStorage.js.map +1 -1
  60. package/dist/esm/authorizers/context.d.ts +16 -0
  61. package/dist/esm/authorizers/context.js +16 -0
  62. package/dist/esm/authorizers/context.js.map +1 -0
  63. package/dist/esm/authorizers/device-authorizer/DeviceAuthResponse.d.ts +38 -0
  64. package/dist/esm/authorizers/device-authorizer/DeviceAuthResponse.js +15 -0
  65. package/dist/esm/authorizers/device-authorizer/DeviceAuthResponse.js.map +1 -0
  66. package/dist/esm/authorizers/device-authorizer/DeviceAuthorizerBase.d.ts +49 -0
  67. package/dist/esm/authorizers/device-authorizer/DeviceAuthorizerBase.js +224 -0
  68. package/dist/esm/authorizers/device-authorizer/DeviceAuthorizerBase.js.map +1 -0
  69. package/dist/esm/authorizers/device-authorizer/DeviceAuthorizerParams.d.ts +58 -0
  70. package/dist/esm/authorizers/device-authorizer/DeviceAuthorizerParams.js +2 -0
  71. package/dist/esm/authorizers/device-authorizer/DeviceAuthorizerParams.js.map +1 -0
  72. package/dist/esm/authorizers/device-authorizer/asyncLocalStorage.d.ts +16 -0
  73. package/dist/esm/authorizers/device-authorizer/asyncLocalStorage.js +10 -0
  74. package/dist/esm/authorizers/device-authorizer/asyncLocalStorage.js.map +1 -0
  75. package/dist/esm/authorizers/device-authorizer/index.d.ts +4 -0
  76. package/dist/esm/authorizers/device-authorizer/index.js +3 -0
  77. package/dist/esm/authorizers/device-authorizer/index.js.map +1 -0
  78. package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerBase.d.ts +30 -0
  79. package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerBase.js +154 -0
  80. package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerBase.js.map +1 -0
  81. package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerParams.d.ts +38 -0
  82. package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerParams.js +2 -0
  83. package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerParams.js.map +1 -0
  84. package/dist/esm/authorizers/federated-connections/asyncLocalStorage.d.ts +7 -5
  85. package/dist/esm/authorizers/federated-connections/asyncLocalStorage.js +3 -3
  86. package/dist/esm/authorizers/federated-connections/asyncLocalStorage.js.map +1 -1
  87. package/dist/esm/authorizers/federated-connections/index.d.ts +3 -36
  88. package/dist/esm/authorizers/federated-connections/index.js +2 -122
  89. package/dist/esm/authorizers/federated-connections/index.js.map +1 -1
  90. package/dist/esm/authorizers/index.d.ts +1 -12
  91. package/dist/esm/authorizers/index.js.map +1 -1
  92. package/dist/esm/authorizers/types.d.ts +37 -0
  93. package/dist/esm/authorizers/types.js +11 -0
  94. package/dist/esm/authorizers/types.js.map +1 -0
  95. package/dist/esm/credentials.d.ts +33 -8
  96. package/dist/esm/credentials.js +11 -1
  97. package/dist/esm/credentials.js.map +1 -1
  98. package/dist/esm/index.d.ts +1 -3
  99. package/dist/esm/index.js +0 -1
  100. package/dist/esm/index.js.map +1 -1
  101. package/dist/esm/interrupts/DeviceInterrupts.d.ts +55 -0
  102. package/dist/esm/interrupts/DeviceInterrupts.js +70 -0
  103. package/dist/esm/interrupts/DeviceInterrupts.js.map +1 -0
  104. package/dist/esm/interrupts/index.d.ts +2 -0
  105. package/dist/esm/interrupts/index.js +2 -0
  106. package/dist/esm/interrupts/index.js.map +1 -1
  107. package/dist/esm/stores/Store.d.ts +40 -0
  108. package/dist/esm/stores/Store.js +11 -0
  109. package/dist/esm/stores/Store.js.map +1 -0
  110. package/dist/esm/stores/SubStore.d.ts +31 -0
  111. package/dist/esm/stores/SubStore.js +48 -0
  112. package/dist/esm/stores/SubStore.js.map +1 -0
  113. package/dist/esm/stores/impl/FSStore.d.ts +19 -0
  114. package/dist/esm/stores/impl/FSStore.js +72 -0
  115. package/dist/esm/stores/impl/FSStore.js.map +1 -0
  116. package/dist/esm/stores/impl/MemoryStore.d.ts +8 -0
  117. package/dist/esm/stores/impl/MemoryStore.js +11 -0
  118. package/dist/esm/stores/impl/MemoryStore.js.map +1 -0
  119. package/dist/esm/stores/impl/TempBoxStore.d.ts +13 -0
  120. package/dist/esm/stores/impl/TempBoxStore.js +18 -0
  121. package/dist/esm/stores/impl/TempBoxStore.js.map +1 -0
  122. package/dist/esm/stores/index.d.ts +5 -0
  123. package/dist/esm/stores/index.js +4 -0
  124. package/dist/esm/stores/index.js.map +1 -0
  125. package/dist/esm/util/index.d.ts +3 -0
  126. package/dist/esm/util/index.js +8 -0
  127. package/dist/esm/util/index.js.map +1 -0
  128. package/package.json +20 -4
  129. package/dist/cjs/TokenResponse.js.map +0 -1
  130. package/dist/cjs/authorizers/device-authorizer.js +0 -130
  131. package/dist/cjs/authorizers/device-authorizer.js.map +0 -1
  132. package/dist/esm/TokenResponse.d.ts +0 -15
  133. package/dist/esm/TokenResponse.js +0 -2
  134. package/dist/esm/TokenResponse.js.map +0 -1
  135. package/dist/esm/authorizers/device-authorizer.d.ts +0 -15
  136. package/dist/esm/authorizers/device-authorizer.js +0 -90
  137. package/dist/esm/authorizers/device-authorizer.js.map +0 -1
@@ -0,0 +1,40 @@
1
+ /**
2
+ * A key-value store interface.
3
+ *
4
+ * Auth0AI uses this store in different stages:
5
+ *
6
+ * 1. to store the authorization request when an AI agent is interrupted (CIBA, Device Flow)
7
+ * 2. user credentials associated to threads to avoid re-authentication (CIBA, Device Flow, Federated Connection)
8
+ *
9
+ */
10
+ export interface Store<T = any> {
11
+ /**
12
+ *
13
+ * Get a value from the store.
14
+ *
15
+ * @param namespace - The namespace of the key
16
+ * @param key - The key
17
+ */
18
+ get(namespace: string[], key: string): Promise<T | undefined>;
19
+ /**
20
+ *
21
+ * Delete a value from the store.
22
+ * @param namespace - The namespace of the key
23
+ * @param key - The key
24
+ */
25
+ delete(namespace: string[], key: string): Promise<void>;
26
+ /**
27
+ *
28
+ * Put a value in the store.
29
+ *
30
+ * @param namespace - The namespace of the key
31
+ * @param key - The key
32
+ * @param value - The value to store
33
+ * @param [options] - The options to store the value
34
+ * @param [options.expiresIn] - The time in milliseconds to expire the value
35
+ */
36
+ put(namespace: string[], key: string, value: T, options?: {
37
+ expiresIn?: number;
38
+ }): Promise<void>;
39
+ }
40
+ //# sourceMappingURL=Store.d.ts.map
@@ -0,0 +1,11 @@
1
+ /**
2
+ * A key-value store interface.
3
+ *
4
+ * Auth0AI uses this store in different stages:
5
+ *
6
+ * 1. to store the authorization request when an AI agent is interrupted (CIBA, Device Flow)
7
+ * 2. user credentials associated to threads to avoid re-authentication (CIBA, Device Flow, Federated Connection)
8
+ *
9
+ */
10
+ export {};
11
+ //# sourceMappingURL=Store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Store.js","sourceRoot":"","sources":["../../../src/stores/Store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * A key-value store interface.\n *\n * Auth0AI uses this store in different stages:\n *\n * 1. to store the authorization request when an AI agent is interrupted (CIBA, Device Flow)\n * 2. user credentials associated to threads to avoid re-authentication (CIBA, Device Flow, Federated Connection)\n *\n */\n\nexport interface Store<T = any> {\n /**\n *\n * Get a value from the store.\n *\n * @param namespace - The namespace of the key\n * @param key - The key\n */\n get(namespace: string[], key: string): Promise<T | undefined>;\n\n /**\n *\n * Delete a value from the store.\n * @param namespace - The namespace of the key\n * @param key - The key\n */\n delete(namespace: string[], key: string): Promise<void>;\n\n /**\n *\n * Put a value in the store.\n *\n * @param namespace - The namespace of the key\n * @param key - The key\n * @param value - The value to store\n * @param [options] - The options to store the value\n * @param [options.expiresIn] - The time in milliseconds to expire the value\n */\n put(\n namespace: string[],\n key: string,\n value: T,\n options?: { expiresIn?: number }\n ): Promise<void>;\n}\n"]}
@@ -0,0 +1,31 @@
1
+ import { Store } from "./Store";
2
+ /**
3
+ * Parameters for configuring a SubStore.
4
+ * @template T The type of values to be stored in the SubStore.
5
+ * @property {string[]} [baseNamespace] - An optional base namespace for the SubStore, used to organize keys in a hierarchical structure.
6
+ * @property {(value: T) => number | undefined} [getTTL] - An optional function that returns the expiry time for a value in milliseconds since epoch, or undefined if the value doesn't expire.
7
+ */
8
+ type SubStoreParams<T> = {
9
+ baseNamespace?: string[];
10
+ getTTL?: (value: T) => number | undefined;
11
+ };
12
+ /**
13
+ * A store implementation that delegates operations to a parent store with optional namespace prefixing.
14
+ *
15
+ * @template T - The type of values stored in this SubStore
16
+ * @implements {Store<T>}
17
+ */
18
+ export declare class SubStore<T = any> implements Store<T> {
19
+ private readonly parent;
20
+ private readonly options;
21
+ constructor(parent: Store<any>, options?: SubStoreParams<T>);
22
+ private getFullNamespace;
23
+ get(namespace: string[], key: string): Promise<any>;
24
+ delete(namespace: string[], key: string): Promise<void>;
25
+ put(namespace: string[], key: string, value: T, options?: {
26
+ expiresIn?: number;
27
+ }): Promise<void>;
28
+ createSubStore<TNew>(options?: string | string[] | SubStoreParams<TNew>): SubStore<TNew>;
29
+ }
30
+ export {};
31
+ //# sourceMappingURL=SubStore.d.ts.map
@@ -0,0 +1,48 @@
1
+ /**
2
+ * A store implementation that delegates operations to a parent store with optional namespace prefixing.
3
+ *
4
+ * @template T - The type of values stored in this SubStore
5
+ * @implements {Store<T>}
6
+ */
7
+ export class SubStore {
8
+ constructor(parent, options = {}) {
9
+ this.parent = parent;
10
+ this.options = options;
11
+ if (typeof parent === "undefined") {
12
+ throw new Error("Parent store is required");
13
+ }
14
+ }
15
+ getFullNamespace(namespace) {
16
+ if (this.options.baseNamespace) {
17
+ return [...this.options.baseNamespace, ...namespace];
18
+ }
19
+ return namespace;
20
+ }
21
+ get(namespace, key) {
22
+ return this.parent.get(this.getFullNamespace(namespace), key);
23
+ }
24
+ delete(namespace, key) {
25
+ return this.parent.delete(this.getFullNamespace(namespace), key);
26
+ }
27
+ put(namespace, key, value, options) {
28
+ const expiresIn = (options === null || options === void 0 ? void 0 : options.expiresIn)
29
+ ? options.expiresIn
30
+ : this.options.getTTL
31
+ ? this.options.getTTL(value)
32
+ : undefined;
33
+ const fullNS = this.getFullNamespace(namespace);
34
+ return this.parent.put(fullNS, key, value, {
35
+ expiresIn,
36
+ });
37
+ }
38
+ createSubStore(options = {}) {
39
+ if (typeof options === "string") {
40
+ options = { baseNamespace: [options] };
41
+ }
42
+ else if (Array.isArray(options)) {
43
+ options = { baseNamespace: options };
44
+ }
45
+ return new SubStore(this, options);
46
+ }
47
+ }
48
+ //# sourceMappingURL=SubStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SubStore.js","sourceRoot":"","sources":["../../../src/stores/SubStore.ts"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,MAAM,OAAO,QAAQ;IACnB,YACmB,MAAkB,EAClB,UAA6B,EAAE;QAD/B,WAAM,GAAN,MAAM,CAAY;QAClB,YAAO,GAAP,OAAO,CAAwB;QAEhD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAEO,gBAAgB,CAAC,SAAmB;QAC1C,IAAI,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;YAC/B,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,SAAS,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,GAAG,CAAC,SAAmB,EAAE,GAAW;QAClC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,CAAC,SAAmB,EAAE,GAAW;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,CAAC;IACnE,CAAC;IAED,GAAG,CACD,SAAmB,EACnB,GAAW,EACX,KAAQ,EACR,OAAgC;QAEhC,MAAM,SAAS,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS;YAClC,CAAC,CAAC,OAAO,CAAC,SAAS;YACnB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM;gBACnB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC5B,CAAC,CAAC,SAAS,CAAC;QAEhB,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAEhD,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE;YACzC,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAED,cAAc,CAAO,UAAoD,EAAE;QACzE,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO,GAAG,EAAE,aAAa,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;QACzC,CAAC;aAAM,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YAClC,OAAO,GAAG,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC;QACvC,CAAC;QACD,OAAO,IAAI,QAAQ,CAAO,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;CACF","sourcesContent":["import { Store } from \"./Store\";\n\n/**\n * Parameters for configuring a SubStore.\n * @template T The type of values to be stored in the SubStore.\n * @property {string[]} [baseNamespace] - An optional base namespace for the SubStore, used to organize keys in a hierarchical structure.\n * @property {(value: T) => number | undefined} [getTTL] - An optional function that returns the expiry time for a value in milliseconds since epoch, or undefined if the value doesn't expire.\n */\ntype SubStoreParams<T> = {\n baseNamespace?: string[];\n getTTL?: (value: T) => number | undefined;\n};\n\n/**\n * A store implementation that delegates operations to a parent store with optional namespace prefixing.\n *\n * @template T - The type of values stored in this SubStore\n * @implements {Store<T>}\n */\nexport class SubStore<T = any> implements Store<T> {\n constructor(\n private readonly parent: Store<any>,\n private readonly options: SubStoreParams<T> = {}\n ) {\n if (typeof parent === \"undefined\") {\n throw new Error(\"Parent store is required\");\n }\n }\n\n private getFullNamespace(namespace: string[]) {\n if (this.options.baseNamespace) {\n return [...this.options.baseNamespace, ...namespace];\n }\n return namespace;\n }\n\n get(namespace: string[], key: string) {\n return this.parent.get(this.getFullNamespace(namespace), key);\n }\n\n delete(namespace: string[], key: string) {\n return this.parent.delete(this.getFullNamespace(namespace), key);\n }\n\n put(\n namespace: string[],\n key: string,\n value: T,\n options?: { expiresIn?: number }\n ): Promise<void> {\n const expiresIn = options?.expiresIn\n ? options.expiresIn\n : this.options.getTTL\n ? this.options.getTTL(value)\n : undefined;\n\n const fullNS = this.getFullNamespace(namespace);\n\n return this.parent.put(fullNS, key, value, {\n expiresIn,\n });\n }\n\n createSubStore<TNew>(options: string | string[] | SubStoreParams<TNew> = {}) {\n if (typeof options === \"string\") {\n options = { baseNamespace: [options] };\n } else if (Array.isArray(options)) {\n options = { baseNamespace: options };\n }\n return new SubStore<TNew>(this, options);\n }\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import { TempBox } from "tempbox";
2
+ import { TempBoxStore } from "./TempBoxStore";
3
+ export declare class PersistentTempBox extends TempBox {
4
+ private filepath;
5
+ private _pendingWriteTimeout;
6
+ private _debounceMs;
7
+ constructor(filepath: string, debounceMs?: number);
8
+ private _load;
9
+ private _debouncedPersist;
10
+ private _persist;
11
+ private _ensureDirectory;
12
+ }
13
+ /**
14
+ * An unsafe filesystem store for dev/demo purposes.
15
+ */
16
+ export declare class FSStore<T = any> extends TempBoxStore<T> {
17
+ constructor(filepath: string);
18
+ }
19
+ //# sourceMappingURL=FSStore.d.ts.map
@@ -0,0 +1,72 @@
1
+ import fs from "fs/promises";
2
+ import path from "path";
3
+ import { TempBox } from "tempbox";
4
+ import { TempBoxStore } from "./TempBoxStore";
5
+ export class PersistentTempBox extends TempBox {
6
+ constructor(filepath, debounceMs = 100) {
7
+ const absPath = path.resolve(filepath);
8
+ super({
9
+ onSet: () => this._debouncedPersist(),
10
+ onDelete: () => this._debouncedPersist(),
11
+ onClear: () => this._debouncedPersist(),
12
+ onExpire: () => this._debouncedPersist(),
13
+ });
14
+ this._pendingWriteTimeout = null;
15
+ this.filepath = absPath;
16
+ this._debounceMs = debounceMs;
17
+ this._load();
18
+ }
19
+ async _load() {
20
+ try {
21
+ const raw = await fs.readFile(this.filepath, "utf-8");
22
+ const parsed = JSON.parse(raw);
23
+ for (const [key, { value, expiresAt }] of Object.entries(parsed)) {
24
+ const ttl = expiresAt ? Math.max(0, expiresAt - Date.now()) : undefined;
25
+ if (ttl === undefined || ttl > 0) {
26
+ this.set(key, value, ttl);
27
+ }
28
+ }
29
+ }
30
+ catch (err) {
31
+ if (err.code !== "ENOENT") {
32
+ console.error(`Failed to load persisted store:`, err);
33
+ }
34
+ }
35
+ }
36
+ _debouncedPersist() {
37
+ if (this._pendingWriteTimeout) {
38
+ clearTimeout(this._pendingWriteTimeout);
39
+ }
40
+ this._pendingWriteTimeout = setTimeout(() => {
41
+ this._persist();
42
+ }, this._debounceMs);
43
+ }
44
+ async _persist() {
45
+ const entries = {};
46
+ for (const [key, { value, expiresAt }] of this["data"].entries()) {
47
+ if (!expiresAt || expiresAt > Date.now()) {
48
+ entries[key] = { value, expiresAt };
49
+ }
50
+ }
51
+ try {
52
+ await this._ensureDirectory();
53
+ await fs.writeFile(this.filepath, JSON.stringify(entries, null, 2), "utf-8");
54
+ }
55
+ catch (err) {
56
+ console.error(`Failed to persist store to disk:`, err);
57
+ }
58
+ }
59
+ async _ensureDirectory() {
60
+ const dir = path.dirname(this.filepath);
61
+ await fs.mkdir(dir, { recursive: true });
62
+ }
63
+ }
64
+ /**
65
+ * An unsafe filesystem store for dev/demo purposes.
66
+ */
67
+ export class FSStore extends TempBoxStore {
68
+ constructor(filepath) {
69
+ super(new PersistentTempBox(filepath));
70
+ }
71
+ }
72
+ //# sourceMappingURL=FSStore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CAAC,SAAS,CAChB,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAChC,OAAO,CACR,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,GAAG,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,gBAAgB;QAC5B,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,OAAiB,SAAQ,YAAe;IACnD,YAAY,QAAgB;QAC1B,KAAK,CAAC,IAAI,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzC,CAAC;CACF","sourcesContent":["import fs from \"fs/promises\";\nimport path from \"path\";\nimport { TempBox } from \"tempbox\";\n\nimport { TempBoxStore } from \"./TempBoxStore\";\n\ntype StoredEntry = {\n value: any;\n expiresAt: number | null;\n};\n\nexport class PersistentTempBox extends TempBox {\n private filepath: string;\n private _pendingWriteTimeout: NodeJS.Timeout | null = null;\n private _debounceMs: number;\n\n constructor(filepath: string, debounceMs = 100) {\n const absPath = path.resolve(filepath);\n super({\n onSet: () => this._debouncedPersist(),\n onDelete: () => this._debouncedPersist(),\n onClear: () => this._debouncedPersist(),\n onExpire: () => this._debouncedPersist(),\n });\n this.filepath = absPath;\n this._debounceMs = debounceMs;\n this._load();\n }\n\n private async _load() {\n try {\n const raw = await fs.readFile(this.filepath, \"utf-8\");\n const parsed: Record<string, StoredEntry> = JSON.parse(raw);\n\n for (const [key, { value, expiresAt }] of Object.entries(parsed)) {\n const ttl = expiresAt ? Math.max(0, expiresAt - Date.now()) : undefined;\n if (ttl === undefined || ttl > 0) {\n this.set(key, value, ttl);\n }\n }\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== \"ENOENT\") {\n console.error(`Failed to load persisted store:`, err);\n }\n }\n }\n\n private _debouncedPersist() {\n if (this._pendingWriteTimeout) {\n clearTimeout(this._pendingWriteTimeout);\n }\n\n this._pendingWriteTimeout = setTimeout(() => {\n this._persist();\n }, this._debounceMs);\n }\n\n private async _persist() {\n const entries: Record<string, StoredEntry> = {};\n for (const [key, { value, expiresAt }] of this[\"data\"].entries()) {\n if (!expiresAt || expiresAt > Date.now()) {\n entries[key] = { value, expiresAt };\n }\n }\n\n try {\n await this._ensureDirectory();\n await fs.writeFile(\n this.filepath,\n JSON.stringify(entries, null, 2),\n \"utf-8\"\n );\n } catch (err) {\n console.error(`Failed to persist store to disk:`, err);\n }\n }\n\n private async _ensureDirectory() {\n const dir = path.dirname(this.filepath);\n await fs.mkdir(dir, { recursive: true });\n }\n}\n\n/**\n * An unsafe filesystem store for dev/demo purposes.\n */\nexport class FSStore<T = any> extends TempBoxStore<T> {\n constructor(filepath: string) {\n super(new PersistentTempBox(filepath));\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import { TempBoxStore } from "./TempBoxStore";
2
+ /**
3
+ * An in-memory store for dev/demo purposes.
4
+ */
5
+ export declare class MemoryStore<T = any> extends TempBoxStore<T> {
6
+ constructor();
7
+ }
8
+ //# sourceMappingURL=MemoryStore.d.ts.map
@@ -0,0 +1,11 @@
1
+ import { TempBox } from "tempbox";
2
+ import { TempBoxStore } from "./TempBoxStore";
3
+ /**
4
+ * An in-memory store for dev/demo purposes.
5
+ */
6
+ export class MemoryStore extends TempBoxStore {
7
+ constructor() {
8
+ super(new TempBox());
9
+ }
10
+ }
11
+ //# sourceMappingURL=MemoryStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemoryStore.js","sourceRoot":"","sources":["../../../../src/stores/impl/MemoryStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,MAAM,OAAO,WAAqB,SAAQ,YAAe;IACvD;QACE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC;IACvB,CAAC;CACF","sourcesContent":["import { TempBox } from \"tempbox\";\n\nimport { TempBoxStore } from \"./TempBoxStore\";\n\n/**\n * An in-memory store for dev/demo purposes.\n */\nexport class MemoryStore<T = any> extends TempBoxStore<T> {\n constructor() {\n super(new TempBox());\n }\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import { TempBox } from "tempbox";
2
+ import { Store } from "../Store";
3
+ export declare class TempBoxStore<T = any> implements Store<T> {
4
+ private readonly store;
5
+ protected constructor(store: TempBox);
6
+ private getKey;
7
+ get(namespace: string[], key: string): Promise<any>;
8
+ delete(namespace: string[], key: string): Promise<void>;
9
+ put(namespace: string[], key: string, value: T, options?: {
10
+ expiresIn?: number;
11
+ }): Promise<void>;
12
+ }
13
+ //# sourceMappingURL=TempBoxStore.d.ts.map
@@ -0,0 +1,18 @@
1
+ export class TempBoxStore {
2
+ constructor(store) {
3
+ this.store = store;
4
+ }
5
+ getKey(namespace, key) {
6
+ return namespace.join("/") + "/" + key;
7
+ }
8
+ async get(namespace, key) {
9
+ return this.store.get(this.getKey(namespace, key));
10
+ }
11
+ async delete(namespace, key) {
12
+ this.store.delete(this.getKey(namespace, key));
13
+ }
14
+ async put(namespace, key, value, options) {
15
+ this.store.set(this.getKey(namespace, key), value, options === null || options === void 0 ? void 0 : options.expiresIn);
16
+ }
17
+ }
18
+ //# sourceMappingURL=TempBoxStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TempBoxStore.js","sourceRoot":"","sources":["../../../../src/stores/impl/TempBoxStore.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,YAAY;IACvB,YAAuC,KAAc;QAAd,UAAK,GAAL,KAAK,CAAS;IAAG,CAAC;IAEjD,MAAM,CAAC,SAAmB,EAAE,GAAW;QAC7C,OAAO,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,SAAmB,EAAE,GAAW;QACxC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,SAAmB,EAAE,GAAW;QAC3C,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,GAAG,CACP,SAAmB,EACnB,GAAW,EACX,KAAQ,EACR,OAAgC;QAEhC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,CAAC,CAAC;IACzE,CAAC;CACF","sourcesContent":["import { TempBox } from \"tempbox\";\n\nimport { Store } from \"../Store\";\n\nexport class TempBoxStore<T = any> implements Store<T> {\n protected constructor(private readonly store: TempBox) {}\n\n private getKey(namespace: string[], key: string) {\n return namespace.join(\"/\") + \"/\" + key;\n }\n\n async get(namespace: string[], key: string) {\n return this.store.get(this.getKey(namespace, key));\n }\n\n async delete(namespace: string[], key: string) {\n this.store.delete(this.getKey(namespace, key));\n }\n\n async put(\n namespace: string[],\n key: string,\n value: T,\n options?: { expiresIn?: number }\n ) {\n this.store.set(this.getKey(namespace, key), value, options?.expiresIn);\n }\n}\n"]}
@@ -0,0 +1,5 @@
1
+ export type { Store } from "./Store";
2
+ export { SubStore } from "./SubStore";
3
+ export { MemoryStore } from "./impl/MemoryStore";
4
+ export { FSStore } from "./impl/FSStore";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,4 @@
1
+ export { SubStore } from "./SubStore";
2
+ export { MemoryStore } from "./impl/MemoryStore";
3
+ export { FSStore } from "./impl/FSStore";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stores/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export type { Store } from \"./Store\";\nexport { SubStore } from \"./SubStore\";\nexport { MemoryStore } from \"./impl/MemoryStore\";\nexport { FSStore } from \"./impl/FSStore\";\n"]}
@@ -0,0 +1,3 @@
1
+ export declare const omit: <T extends object, K extends keyof T>(obj: T, keys: K[]) => Omit<T, K>;
2
+ export type RequireFields<T, K extends keyof T> = Required<Pick<T, K>> & Omit<T, K>;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,8 @@
1
+ export const omit = function omit(obj, keys) {
2
+ const result = { ...obj };
3
+ for (const key of keys) {
4
+ delete result[key];
5
+ }
6
+ return result;
7
+ };
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/util/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,IAAI,GAAG,SAAS,IAAI,CAC/B,GAAM,EACN,IAAS;IAET,MAAM,MAAM,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC;IAC1B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,MAAoB,CAAC;AAC9B,CAAC,CAAC","sourcesContent":["export const omit = function omit<T extends object, K extends keyof T>(\n obj: T,\n keys: K[]\n): Omit<T, K> {\n const result = { ...obj };\n for (const key of keys) {\n delete result[key];\n }\n return result as Omit<T, K>;\n};\n\nexport type RequireFields<T, K extends keyof T> = Required<Pick<T, K>> &\n Omit<T, K>;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auth0/ai",
3
- "version": "1.0.2",
3
+ "version": "2.0.1",
4
4
  "description": "Auth0AI SDK for JavaScript",
5
5
  "types": "dist/esm/index.d.ts",
6
6
  "main": "dist/cjs/index.js",
@@ -35,11 +35,26 @@
35
35
  "import": "./dist/esm/interrupts/index.js",
36
36
  "require": "./dist/cjs/interrupts/index.js"
37
37
  },
38
+ "./stores": {
39
+ "types": "./dist/esm/stores/index.d.ts",
40
+ "import": "./dist/esm/stores/index.js",
41
+ "require": "./dist/cjs/stores/index.js"
42
+ },
43
+ "./authorizers": {
44
+ "types": "./dist/esm/authorizers/index.d.ts",
45
+ "import": "./dist/esm/authorizers/index.js",
46
+ "require": "./dist/cjs/authorizers/index.js"
47
+ },
38
48
  "./FederatedConnections": {
39
49
  "types": "./dist/esm/authorizers/federated-connections/index.d.ts",
40
50
  "import": "./dist/esm/authorizers/federated-connections/index.js",
41
51
  "require": "./dist/cjs/authorizers/federated-connections/index.js"
42
52
  },
53
+ "./Device": {
54
+ "types": "./dist/esm/authorizers/device-authorizer/index.d.ts",
55
+ "import": "./dist/esm/authorizers/device-authorizer/index.js",
56
+ "require": "./dist/cjs/authorizers/device-authorizer/index.js"
57
+ },
43
58
  "./CIBA": {
44
59
  "types": "./dist/esm/authorizers/ciba/index.d.ts",
45
60
  "import": "./dist/esm/authorizers/ciba/index.js",
@@ -65,10 +80,11 @@
65
80
  "dependencies": {
66
81
  "@openfga/sdk": "^0.8.0",
67
82
  "auth0": "^4.18.0",
68
- "enquirer": "^2.4.1",
69
83
  "jose": "^5.9.6",
70
- "open": "^10.1.0",
71
- "openid-client": "^6.1.7"
84
+ "openid-client": "^6.1.7",
85
+ "stable-hash": "^0.0.5",
86
+ "tempbox": "^1.1.1",
87
+ "zod": "^3.24.2"
72
88
  },
73
89
  "publishConfig": {
74
90
  "access": "public"
@@ -1 +0,0 @@
1
- {"version":3,"file":"TokenResponse.js","sourceRoot":"","sources":["../../src/TokenResponse.ts"],"names":[],"mappings":"","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"]}
@@ -1,130 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.DeviceAuthorizer = void 0;
40
- const enquirer_1 = __importDefault(require("enquirer"));
41
- const jose = __importStar(require("jose"));
42
- const open_1 = __importDefault(require("open"));
43
- const openid_client_1 = require("openid-client");
44
- const errors_1 = require("../errors");
45
- class DeviceAuthorizer {
46
- constructor(params) {
47
- this.domain = (params === null || params === void 0 ? void 0 : params.domain) || process.env.AUTH0_DOMAIN;
48
- this.clientId = (params === null || params === void 0 ? void 0 : params.clientId) || process.env.AUTH0_CLIENT_ID;
49
- }
50
- async _authorize(params) {
51
- const config = await (0, openid_client_1.discovery)(new URL(`https://${this.domain}`), this.clientId);
52
- const handle = await (0, openid_client_1.initiateDeviceAuthorization)(config, {
53
- ...params,
54
- });
55
- const { verification_uri_complete, user_code, expires_in } = handle;
56
- const enquirer = new enquirer_1.default();
57
- await enquirer.prompt({
58
- type: "input",
59
- name: "confirmation",
60
- message: `Press Enter to open the browser to log in or press Ctrl+C to abort. You should see the following code: ${user_code}. It expires in ${expires_in % 60 === 0
61
- ? `${expires_in / 60} minutes`
62
- : `${expires_in} seconds`}.`,
63
- });
64
- await (0, open_1.default)(verification_uri_complete);
65
- let tokens = null;
66
- try {
67
- tokens = await (0, openid_client_1.pollDeviceAuthorizationGrant)(config, handle);
68
- }
69
- catch (err) {
70
- switch (err.error) {
71
- case "access_denied":
72
- throw new errors_1.AccessDeniedError(err.error_description);
73
- case "expired_token":
74
- throw new errors_1.AuthorizationRequestExpiredError("Authorization request has expired");
75
- default:
76
- throw new Error(`Error: ${err.error}; Description: ${err.error_description}`);
77
- }
78
- }
79
- if (!tokens) {
80
- throw new Error("Failed to obtain tokens");
81
- }
82
- const credentials = {
83
- accessToken: {
84
- type: tokens.token_type || "bearer",
85
- value: tokens.access_token,
86
- },
87
- };
88
- if (tokens.id_token) {
89
- credentials.idToken = {
90
- type: tokens.token_type || "bearer",
91
- value: tokens.id_token,
92
- };
93
- }
94
- return credentials;
95
- }
96
- static async authorize(options, params) {
97
- const authorizer = new DeviceAuthorizer(params);
98
- const credentials = await authorizer._authorize(options);
99
- let claims = {};
100
- if (credentials.idToken) {
101
- claims = jose.decodeJwt(credentials.idToken.value);
102
- }
103
- return { accessToken: credentials.accessToken.value, claims };
104
- }
105
- static create(params) {
106
- const authorizer = new DeviceAuthorizer(params);
107
- return (options) => {
108
- return function deviceFlow(handler, onError) {
109
- return async (input, config) => {
110
- try {
111
- const credentials = await authorizer._authorize(options);
112
- let claims = {};
113
- if (credentials.idToken) {
114
- claims = jose.decodeJwt(credentials.idToken.value);
115
- }
116
- return handler({ accessToken: credentials.accessToken.value, claims }, input, config);
117
- }
118
- catch (e) {
119
- if (typeof onError === "function") {
120
- return onError(e);
121
- }
122
- return "Access denied.";
123
- }
124
- };
125
- };
126
- };
127
- }
128
- }
129
- exports.DeviceAuthorizer = DeviceAuthorizer;
130
- //# sourceMappingURL=device-authorizer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"device-authorizer.js","sourceRoot":"","sources":["../../../src/authorizers/device-authorizer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAAgC;AAChC,2CAA6B;AAC7B,gDAAwB;AACxB,iDAMuB;AAGvB,sCAAgF;AAQhF,MAAa,gBAAgB;IAI3B,YAAoB,MAAyB;QAC3C,IAAI,CAAC,MAAM,GAAG,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,KAAI,OAAO,CAAC,GAAG,CAAC,YAAa,CAAC;QAC1D,IAAI,CAAC,QAAQ,GAAG,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,KAAI,OAAO,CAAC,GAAG,CAAC,eAAgB,CAAC;IACnE,CAAC;IAEO,KAAK,CAAC,UAAU,CACtB,MAA+B;QAE/B,MAAM,MAAM,GAAG,MAAM,IAAA,yBAAS,EAC5B,IAAI,GAAG,CAAC,WAAW,IAA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CAAC;4BACxB,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,OAAQ,CAAC,KAAK,CAAC,CAAC;wBACtD,CAAC;wBAED,OAAO,OAAO,CACZ,EAAE,WAAW,EAAE,WAAW,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EACtD,KAAK,EACL,MAAM,CACP,CAAC;oBACJ,CAAC;oBAAC,OAAO,CAAM,EAAE,CAAC;wBAChB,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;4BAClC,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;wBACpB,CAAC;wBAED,OAAO,gBAAqB,CAAC;oBAC/B,CAAC;gBACH,CAAC,CAAC;YACJ,CAAC,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;CACF;AA9HD,4CA8HC","sourcesContent":["import Enquirer from \"enquirer\";\nimport * as jose from \"jose\";\nimport open from \"open\";\nimport {\n discovery,\n initiateDeviceAuthorization,\n pollDeviceAuthorizationGrant,\n TokenEndpointResponse,\n TokenEndpointResponseHelpers,\n} from \"openid-client\";\n\nimport { Credentials } from \"../credentials\";\nimport { AccessDeniedError, AuthorizationRequestExpiredError } from \"../errors\";\nimport { AuthorizerParams, AuthParams, ToolWithAuthHandler } from \"./\";\n\nexport type DeviceAuthorizerOptions = {\n scope: string;\n audience?: string;\n};\n\nexport class DeviceAuthorizer {\n domain: string;\n clientId: string;\n\n private constructor(params?: AuthorizerParams) {\n this.domain = params?.domain || process.env.AUTH0_DOMAIN!;\n this.clientId = params?.clientId || process.env.AUTH0_CLIENT_ID!;\n }\n\n private async _authorize(\n params: DeviceAuthorizerOptions\n ): Promise<Credentials> {\n const config = await discovery(\n new URL(`https://${this.domain}`),\n this.clientId\n );\n\n const handle = await initiateDeviceAuthorization(config, {\n ...params,\n });\n\n const { verification_uri_complete, user_code, expires_in } = handle;\n\n const enquirer = new Enquirer();\n await enquirer.prompt({\n type: \"input\",\n name: \"confirmation\",\n message: `Press Enter to open the browser to log in or press Ctrl+C to abort. You should see the following code: ${user_code}. It expires in ${\n expires_in % 60 === 0\n ? `${expires_in / 60} minutes`\n : `${expires_in} seconds`\n }.`,\n });\n\n await open(verification_uri_complete!);\n\n let tokens: (TokenEndpointResponse & TokenEndpointResponseHelpers) | null =\n null;\n\n try {\n tokens = await pollDeviceAuthorizationGrant(config, handle);\n } catch (err: any) {\n switch (err.error) {\n case \"access_denied\":\n throw new AccessDeniedError(err.error_description);\n case \"expired_token\":\n throw new AuthorizationRequestExpiredError(\n \"Authorization request has expired\"\n );\n default:\n throw new Error(\n `Error: ${err.error}; Description: ${err.error_description}`\n );\n }\n }\n\n if (!tokens) {\n throw new Error(\"Failed to obtain tokens\");\n }\n\n const credentials: Credentials = {\n accessToken: {\n type: tokens.token_type || \"bearer\",\n value: tokens.access_token,\n },\n };\n\n if (tokens.id_token) {\n credentials.idToken = {\n type: tokens.token_type || \"bearer\",\n value: tokens.id_token,\n };\n }\n\n return credentials;\n }\n\n static async authorize(\n options: DeviceAuthorizerOptions,\n params?: AuthorizerParams\n ) {\n const authorizer = new DeviceAuthorizer(params);\n const credentials = await authorizer._authorize(options);\n\n let claims = {};\n\n if (credentials.idToken) {\n claims = jose.decodeJwt(credentials.idToken!.value);\n }\n\n return { accessToken: credentials.accessToken.value, claims } as AuthParams;\n }\n\n static create(params?: AuthorizerParams): DeviceFlowInstance {\n const authorizer = new DeviceAuthorizer(params);\n\n return (options: DeviceAuthorizerOptions) => {\n return function deviceFlow<I, O, C>(\n handler: ToolWithAuthHandler<I, O, C>,\n onError?: (error: Error) => Promise<O>\n ) {\n return async (input: I, config?: C): Promise<O> => {\n try {\n const credentials = await authorizer._authorize(options);\n let claims = {};\n\n if (credentials.idToken) {\n claims = jose.decodeJwt(credentials.idToken!.value);\n }\n\n return handler(\n { accessToken: credentials.accessToken.value, claims },\n input,\n config\n );\n } catch (e: any) {\n if (typeof onError === \"function\") {\n return onError(e);\n }\n\n return \"Access denied.\" as O;\n }\n };\n };\n };\n }\n}\n\nexport type DeviceFlowInstance = (\n options: DeviceAuthorizerOptions\n) => <I, O, C>(\n handler: ToolWithAuthHandler<I, O, C>,\n onError?: (error: Error) => Promise<O>\n) => (input: I, config?: C) => Promise<O>;\n"]}
@@ -1,15 +0,0 @@
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
- //# sourceMappingURL=TokenResponse.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=TokenResponse.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TokenResponse.js","sourceRoot":"","sources":["../../src/TokenResponse.ts"],"names":[],"mappings":"","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"]}
@@ -1,15 +0,0 @@
1
- import { AuthorizerParams, AuthParams, ToolWithAuthHandler } from "./";
2
- export type DeviceAuthorizerOptions = {
3
- scope: string;
4
- audience?: string;
5
- };
6
- export declare class DeviceAuthorizer {
7
- domain: string;
8
- clientId: string;
9
- private constructor();
10
- private _authorize;
11
- static authorize(options: DeviceAuthorizerOptions, params?: AuthorizerParams): Promise<AuthParams>;
12
- static create(params?: AuthorizerParams): DeviceFlowInstance;
13
- }
14
- export type DeviceFlowInstance = (options: DeviceAuthorizerOptions) => <I, O, C>(handler: ToolWithAuthHandler<I, O, C>, onError?: (error: Error) => Promise<O>) => (input: I, config?: C) => Promise<O>;
15
- //# sourceMappingURL=device-authorizer.d.ts.map