@palantir/pack.auth 0.0.1-beta.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
 
2
- > @palantir/pack.auth@0.0.1-beta.1 lint /home/runner/work/pack/pack/packages/auth/core
3
- > eslint ./src ; dprint check --config $(find-up dprint.json) --allow-no-files
2
+ > @palantir/pack.auth@0.0.2 lint /home/runner/work/pack/pack/packages/auth/core
3
+ > eslint ./src && dprint check --config $(find-up dprint.json) --allow-no-files
4
4
 
5
5
 
6
6
  /home/runner/work/pack/pack/packages/auth/core/src/__tests__/AuthModuleImpl.test.ts
@@ -1,5 +1,5 @@
1
1
 
2
- > @palantir/pack.auth@0.0.1-beta.1 transpileBrowser /home/runner/work/pack/pack/packages/auth/core
2
+ > @palantir/pack.auth@0.0.2 transpileBrowser /home/runner/work/pack/pack/packages/auth/core
3
3
  > monorepo-transpile -f esm -m bundle -t browser
4
4
 
5
5
  👍
@@ -1,5 +1,5 @@
1
1
 
2
- > @palantir/pack.auth@0.0.1-beta.1 transpileCjs /home/runner/work/pack/pack/packages/auth/core
2
+ > @palantir/pack.auth@0.0.2 transpileCjs /home/runner/work/pack/pack/packages/auth/core
3
3
  > monorepo-transpile -f cjs -m bundle -t node
4
4
 
5
5
  👍
@@ -1,5 +1,5 @@
1
1
 
2
- > @palantir/pack.auth@0.0.1-beta.1 transpileEsm /home/runner/work/pack/pack/packages/auth/core
2
+ > @palantir/pack.auth@0.0.2 transpileEsm /home/runner/work/pack/pack/packages/auth/core
3
3
  > monorepo-transpile -f esm -m bundle -t node
4
4
 
5
5
  👍
@@ -1,5 +1,5 @@
1
1
 
2
- > @palantir/pack.auth@0.0.1-beta.1 transpileTypes /home/runner/work/pack/pack/packages/auth/core
2
+ > @palantir/pack.auth@0.0.2 transpileTypes /home/runner/work/pack/pack/packages/auth/core
3
3
  > monorepo-transpile -f esm -m types -t node
4
4
 
5
5
  👍
@@ -1,4 +1,4 @@
1
1
 
2
- > @palantir/pack.auth@0.0.1-beta.1 typecheck /home/runner/work/pack/pack/packages/auth/core
2
+ > @palantir/pack.auth@0.0.2 typecheck /home/runner/work/pack/pack/packages/auth/core
3
3
  > tsc --noEmit --emitDeclarationOnly false
4
4
 
package/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # @palantir/pack.auth
2
+
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 67df6e4: Documented public apis
8
+ - Updated dependencies [eba27ae]
9
+ - Updated dependencies [67df6e4]
10
+ - @palantir/pack.core@0.1.1
11
+
12
+ ## 0.0.1
13
+
14
+ ### Patch Changes
15
+
16
+ - 8ed48e6: Initial release of auth packages
17
+ - 09f7acd: Add activity & presence custom event subscriptions
18
+ - Updated dependencies [8698373]
19
+ - Updated dependencies [77c07c4]
20
+ - Updated dependencies [3ebc927]
21
+ - @palantir/pack.core@0.1.0
@@ -105,12 +105,12 @@ var AuthModuleImpl = class {
105
105
  });
106
106
  });
107
107
  }
108
- getCurrentUser() {
109
- const userId = this.#authService.getCurrentUserId();
110
- if (!userId) {
111
- return void 0;
108
+ getCurrentUser(allowUnverified = false) {
109
+ const userId = this.#authService.getCurrentUserId(allowUnverified);
110
+ if (userId != null) {
111
+ return createUserRef(this.app, userId);
112
112
  }
113
- return createUserRef(this.app, userId);
113
+ return void 0;
114
114
  }
115
115
  async validateToken() {
116
116
  return this.#authService.validateToken();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/AuthState.ts","../../src/types/UserRef.ts","../../src/utils/AuthModuleImpl.ts","../../src/constants/AuthModuleKey.ts","../../src/types/AuthModule.ts","../../src/utils/AuthModuleConfig.ts"],"names":[],"mappings":";;;;;AAgBO,IAAM,SAAA,GAAY;AAAA,EACvB,aAAA,EAAe,eAAA;AAAA,EACf,cAAA,EAAgB,gBAAA;AAAA,EAChB,KAAA,EAAO,OAAA;AAAA,EACP,YAAA,EAAc,cAAA;AAAA,E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A;AAAA,EAC3B,UAAA,EAAY,CAAC,GAAA,EAAK,MAAA,KAAW;AAC3B,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,MAAM,IAAI,MAAM,uDAAuD,CAAA;AAAA,IACzE;AACA,IAAA,OAAO,IAAI,cAAA,CAAe,GAAA,EAAK,MAAA,CAAO,WAAW,CAAA;AAAA,EACnD;AACF,CAAA;;;ACOO,SAAS,cAAc,GAAA,EAAK;AACjC,EAAA,mBAAA,CAAoB,GAAG,CAAA;AACvB,EAAA,OAAO,GAAA,CAAI,UAAU,eAAe,CAAA;AACtC;;;ACRO,SAAS,uBAAuB,WAAA,EAAa;AAClD,EAAA,MAAM,MAAA,GAAS;AAAA,IACb;AAAA,GACF;AACA,EAAA,OAAO,CAAC,iBAAiB,MAAM,CAAA;AACjC","file":"index.js","sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const AuthState = {\n Authenticated: \"authenticated\",\n Authenticating: \"authenticating\",\n Error: \"error\",\n Initializing: \"initializing\",\n Unauthenticated: \"unauthenticated\"\n};","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getAuthModule } from \"./AuthModule.js\";\nconst UserRefBrand = Symbol(\"UserRef\");\n\n/**\n * Reference to a user from the platform API.\n * Provides access to user information with caching.\n */\n\nconst INVALID_USER_ID = \"INVALID_USER_REF\";\nconst INVALID_USER_REF = Object.freeze({\n userId: INVALID_USER_ID,\n [UserRefBrand]: UserRefBrand,\n get: () => Promise.reject(new Error(\"Invalid user reference\"))\n});\nexport function invalidUserRef() {\n return INVALID_USER_REF;\n}\nexport function isValidUserRef(userRef) {\n return userRef.userId !== INVALID_USER_ID && userRef.userId !== \"\";\n}\nexport const createUserRef = (app, userId) => {\n return new UserRefImpl(app, userId);\n};\nclass UserRefImpl {\n userId;\n #authModule;\n constructor(app, userId) {\n this.#authModule = getAuthModule(app);\n this.userId = userId;\n }\n get(force) {\n return this.#authModule.getUserData(this.userId, force);\n }\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AuthState } from \"../types/AuthState.js\";\nimport { createUserRef } from \"../types/UserRef.js\";\nexport class AuthModuleImpl {\n #authService;\n app;\n signInPromise;\n constructor(app, authService) {\n this.app = app;\n this.#authService = authService;\n }\n\n // AuthModule interface implementation\n isAuthenticated() {\n return this.#authService.isAuthenticated();\n }\n async getToken() {\n return this.#authService.getToken();\n }\n getTokenOrUndefined() {\n return this.#authService.getTokenOrUndefined();\n }\n async signIn() {\n if (this.signInPromise) {\n return this.signInPromise;\n }\n this.signInPromise = (async () => {\n try {\n await this.#authService.signIn();\n } finally {\n this.signInPromise = undefined;\n }\n })();\n return this.signInPromise;\n }\n async signOut() {\n return this.#authService.signOut();\n }\n async refresh() {\n if (!this.#authService.refresh) {\n throw new Error(\"Refresh not supported for this auth client type\");\n }\n return this.#authService.refresh();\n }\n onAuthStateChange(callback) {\n return this.#authService.onAuthStateChange(callback);\n }\n onTokenChange(callback) {\n return this.#authService.onTokenChange(callback);\n }\n async waitForAuth() {\n // If already authenticated, resolve immediately\n if (this.isAuthenticated()) {\n return Promise.resolve();\n }\n return new Promise((resolve, reject) => {\n const unsubscribe = this.onAuthStateChange(event => {\n if (event.state === AuthState.Authenticated) {\n unsubscribe();\n resolve();\n } else if (event.state === AuthState.Error) {\n unsubscribe();\n reject(new Error(\"Authentication failed\", {\n cause: event.error\n }));\n }\n });\n });\n }\n getCurrentUser() {\n const userId = this.#authService.getCurrentUserId();\n if (!userId) {\n return undefined;\n }\n return createUserRef(this.app, userId);\n }\n async validateToken() {\n return this.#authService.validateToken();\n }\n async getUserData(userId, force) {\n return this.#authService.getUserData(userId, force);\n }\n dispose() {\n this.#authService.dispose();\n this.signInPromise = undefined;\n }\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AuthModuleImpl } from \"../utils/AuthModuleImpl.js\";\nexport const AUTH_MODULE_KEY = {\n appMemberName: \"auth\",\n key: Symbol.for(\"pack.auth\"),\n initModule: (app, config) => {\n if (!config) {\n throw new Error(\"AuthModuleConfig is required to initialize AuthModule\");\n }\n return new AuthModuleImpl(app, config.authService);\n }\n};","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { assertIsAppInternal } from \"@palantir/pack.core\";\nimport { AUTH_MODULE_KEY } from \"../constants/AuthModuleKey.js\";\n\n/**\n * AuthModule provides unified authentication services for PACK applications.\n *\n * It wraps OSDK OAuth clients and provides a consistent interface for authentication\n * state management, token access, and auth lifecycle events.\n */\n// TODO: functions should be method style\n\n/**\n * Get the auth module from an PACK app instance.\n *\n * @param app - PACK app instance\n * @returns The auth module\n */\nexport function getAuthModule(app) {\n assertIsAppInternal(app);\n return app.getModule(AUTH_MODULE_KEY);\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AUTH_MODULE_KEY } from \"../constants/AuthModuleKey.js\";\n\n/**\n * Configuration for AuthModule initialization\n */\n\n/**\n * Creates an auth module configuration tuple.\n *\n * @param authService - The auth service to use\n * @returns Module configuration tuple for the auth module\n */\nexport function createAuthModuleConfig(authService) {\n const config = {\n authService\n };\n return [AUTH_MODULE_KEY, config];\n}"]}
1
+ {"version":3,"sources":["../../src/types/AuthState.ts","../../src/types/UserRef.ts","../../src/utils/AuthModuleImpl.ts","../../src/constants/AuthModuleKey.ts","../../src/types/AuthModule.ts","../../src/utils/AuthModuleConfig.ts"],"names":[],"mapp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AAa,OAAA,EAAQ;AAC1B,IAAA,IAAA,CAAK,aAAA,GAAgB,MAAA;AAAA,EACvB;AACF;;;ACpFO,IAAM,eAAA,GAAkB;AAAA,EAC7B,aAAA,EAAe,MAAA;AAAA,EACf,GAAA,EAAK,MAAA,CAAO,GAAA,CAAI,WAAW,CAAA;AAAA,EAC3B,UAAA,EAAY,CAAC,GAAA,EAAK,MAAA,KAAW;AAC3B,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,MAAM,IAAI,MAAM,uDAAuD,CAAA;AAAA,IACzE;AACA,IAAA,OAAO,IAAI,cAAA,CAAe,GAAA,EAAK,MAAA,CAAO,WAAW,CAAA;AAAA,EACnD;AACF,CAAA;;;ACMO,SAAS,cAAc,GAAA,EAAK;AACjC,EAAA,mBAAA,CAAoB,GAAG,CAAA;AACvB,EAAA,OAAO,GAAA,CAAI,UAAU,eAAe,CAAA;AACtC;;;ACPO,SAAS,uBAAuB,WAAA,EAAa;AAClD,EAAA,MAAM,MAAA,GAAS;AAAA,IACb;AAAA,GACF;AACA,EAAA,OAAO,CAAC,iBAAiB,MAAM,CAAA;AACjC","file":"index.js","sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const AuthState = {\n Authenticated: \"authenticated\",\n Authenticating: \"authenticating\",\n Error: \"error\",\n Initializing: \"initializing\",\n Unauthenticated: \"unauthenticated\"\n};","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getAuthModule } from \"./AuthModule.js\";\nconst UserRefBrand = Symbol(\"UserRef\");\n\n/**\n * Reference to a user from the platform API.\n * Provides access to user information with caching.\n */\n\nconst INVALID_USER_ID = \"INVALID_USER_REF\";\nconst INVALID_USER_REF = Object.freeze({\n userId: INVALID_USER_ID,\n [UserRefBrand]: UserRefBrand,\n get: () => Promise.reject(new Error(\"Invalid user reference\"))\n});\n\n/**\n * Get an invalid user reference. This is a stable reference that can be used to\n * represent an invalid user.\n *\n * Not to be confused with a valid reference to a non-existent user, an invalid\n * reference is one that is not properly initialized. For example, code that\n * initializes with an undefined or empty userId might produce an invalid user\n * reference rather than propagate nullish types.\n *\n * Most operations on an invalid reference are no-ops. For the rest, it is\n * recommended to check for validity using {@link isValidUserRef} before\n * performing operations.\n */\nexport function invalidUserRef() {\n return INVALID_USER_REF;\n}\n\n/**\n * Check if a user reference is valid.\n *\n * Not to be confused with a valid reference to a non-existent user, an invalid\n * reference is one that is not properly initialized. For example, code that\n * initializes with an undefined or empty userId might produce an invalid user\n * reference rather than propagate nullish types.\n *\n * Most operations on an invalid reference are no-ops. For the rest, it is\n * recommended to check for validity using this function before performing\n * operations.\n */\nexport function isValidUserRef(userRef) {\n return userRef.userId !== INVALID_USER_ID && userRef.userId !== \"\";\n}\nexport const createUserRef = (app, userId) => {\n return new UserRefImpl(app, userId);\n};\nclass UserRefImpl {\n userId;\n #authModule;\n constructor(app, userId) {\n this.#authModule = getAuthModule(app);\n this.userId = userId;\n }\n get(force) {\n return this.#authModule.getUserData(this.userId, force);\n }\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AuthState } from \"../types/AuthState.js\";\nimport { createUserRef } from \"../types/UserRef.js\";\nexport class AuthModuleImpl {\n #authService;\n app;\n signInPromise;\n constructor(app, authService) {\n this.app = app;\n this.#authService = authService;\n }\n\n // AuthModule interface implementation\n isAuthenticated() {\n return this.#authService.isAuthenticated();\n }\n async getToken() {\n return this.#authService.getToken();\n }\n getTokenOrUndefined() {\n return this.#authService.getTokenOrUndefined();\n }\n async signIn() {\n if (this.signInPromise) {\n return this.signInPromise;\n }\n this.signInPromise = (async () => {\n try {\n await this.#authService.signIn();\n } finally {\n this.signInPromise = undefined;\n }\n })();\n return this.signInPromise;\n }\n async signOut() {\n return this.#authService.signOut();\n }\n async refresh() {\n if (!this.#authService.refresh) {\n throw new Error(\"Refresh not supported for this auth client type\");\n }\n return this.#authService.refresh();\n }\n onAuthStateChange(callback) {\n return this.#authService.onAuthStateChange(callback);\n }\n onTokenChange(callback) {\n return this.#authService.onTokenChange(callback);\n }\n async waitForAuth() {\n // If already authenticated, resolve immediately\n if (this.isAuthenticated()) {\n return Promise.resolve();\n }\n return new Promise((resolve, reject) => {\n const unsubscribe = this.onAuthStateChange(event => {\n if (event.state === AuthState.Authenticated) {\n unsubscribe();\n resolve();\n } else if (event.state === AuthState.Error) {\n unsubscribe();\n reject(new Error(\"Authentication failed\", {\n cause: event.error\n }));\n }\n });\n });\n }\n getCurrentUser(allowUnverified = false) {\n const userId = this.#authService.getCurrentUserId(allowUnverified);\n if (userId != null) {\n return createUserRef(this.app, userId);\n }\n return undefined;\n }\n async validateToken() {\n return this.#authService.validateToken();\n }\n async getUserData(userId, force) {\n return this.#authService.getUserData(userId, force);\n }\n dispose() {\n this.#authService.dispose();\n this.signInPromise = undefined;\n }\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AuthModuleImpl } from \"../utils/AuthModuleImpl.js\";\nexport const AUTH_MODULE_KEY = {\n appMemberName: \"auth\",\n key: Symbol.for(\"pack.auth\"),\n initModule: (app, config) => {\n if (!config) {\n throw new Error(\"AuthModuleConfig is required to initialize AuthModule\");\n }\n return new AuthModuleImpl(app, config.authService);\n }\n};","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { assertIsAppInternal } from \"@palantir/pack.core\";\nimport { AUTH_MODULE_KEY } from \"../constants/AuthModuleKey.js\";\n\n/**\n * AuthModule provides unified authentication services for PACK applications.\n *\n * It wraps OSDK OAuth clients and provides a consistent interface for authentication\n * state management, token access, and auth lifecycle events.\n */\n\n/**\n * Get the auth module from an PACK app instance.\n *\n * @param app - PACK app instance\n * @returns The auth module\n */\nexport function getAuthModule(app) {\n assertIsAppInternal(app);\n return app.getModule(AUTH_MODULE_KEY);\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AUTH_MODULE_KEY } from \"../constants/AuthModuleKey.js\";\n\n/**\n * Configuration for AuthModule initialization\n */\n\n/**\n * Creates an auth module configuration tuple.\n *\n * @param authService - The auth service to use\n * @returns Module configuration tuple for the auth module\n */\nexport function createAuthModuleConfig(authService) {\n const config = {\n authService\n };\n return [AUTH_MODULE_KEY, config];\n}"]}
@@ -107,12 +107,12 @@ var AuthModuleImpl = class {
107
107
  });
108
108
  });
109
109
  }
110
- getCurrentUser() {
111
- const userId = this.#authService.getCurrentUserId();
112
- if (!userId) {
113
- return void 0;
110
+ getCurrentUser(allowUnverified = false) {
111
+ const userId = this.#authService.getCurrentUserId(allowUnverified);
112
+ if (userId != null) {
113
+ return createUserRef(this.app, userId);
114
114
  }
115
- return createUserRef(this.app, userId);
115
+ return void 0;
116
116
  }
117
117
  async validateToken() {
118
118
  return this.#authService.validateToken();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/AuthState.ts","../../src/types/UserRef.ts","../../src/utils/AuthModuleImpl.ts","../../src/constants/AuthModuleKey.ts","../../src/types/AuthModule.ts","../../src/utils/AuthModuleConfig.ts"],"names":["assertIsAppInternal"],"mappings":";;;;;;;AAgBO,IAAM,SAAA,GAAY;AAAA,EACvB,aAAA,EAAe,eAAA;AAAA,EACf,cAAA,EAAgB,gBAAA;AAAA,EAChB,KAAA,EAAO,OAAA;AAAA,EACP,YAAA,EAAc,cAAA;AAAA,EACd,eAAA,EAAiB;AACnB;;;ACLA,IAAM,YAAA,GAAe,OAAO,SAAS,CAAA;AAOrC,IAAM,eA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MAAA,EAAQ;AACX,MAAA,MAAM,IAAI,MAAM,uDAAuD,CAAA;AAAA,IACzE;AACA,IAAA,OAAO,IAAI,cAAA,CAAe,GAAA,EAAK,MAAA,CAAO,WAAW,CAAA;AAAA,EACnD;AACF,CAAA;;;ACOO,SAAS,cAAc,GAAA,EAAK;AACjC,EAAAA,6BAAA,CAAoB,GAAG,CAAA;AACvB,EAAA,OAAO,GAAA,CAAI,UAAU,eAAe,CAAA;AACtC;;;ACRO,SAAS,uBAAuB,WAAA,EAAa;AAClD,EAAA,MAAM,MAAA,GAAS;AAAA,IACb;AAAA,GACF;AACA,EAAA,OAAO,CAAC,iBAAiB,MAAM,CAAA;AACjC","file":"index.cjs","sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const AuthState = {\n Authenticated: \"authenticated\",\n Authenticating: \"authenticating\",\n Error: \"error\",\n Initializing: \"initializing\",\n Unauthenticated: \"unauthenticated\"\n};","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getAuthModule } from \"./AuthModule.js\";\nconst UserRefBrand = Symbol(\"UserRef\");\n\n/**\n * Reference to a user from the platform API.\n * Provides access to user information with caching.\n */\n\nconst INVALID_USER_ID = \"INVALID_USER_REF\";\nconst INVALID_USER_REF = Object.freeze({\n userId: INVALID_USER_ID,\n [UserRefBrand]: UserRefBrand,\n get: () => Promise.reject(new Error(\"Invalid user reference\"))\n});\nexport function invalidUserRef() {\n return INVALID_USER_REF;\n}\nexport function isValidUserRef(userRef) {\n return userRef.userId !== INVALID_USER_ID && userRef.userId !== \"\";\n}\nexport const createUserRef = (app, userId) => {\n return new UserRefImpl(app, userId);\n};\nclass UserRefImpl {\n userId;\n #authModule;\n constructor(app, userId) {\n this.#authModule = getAuthModule(app);\n this.userId = userId;\n }\n get(force) {\n return this.#authModule.getUserData(this.userId, force);\n }\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AuthState } from \"../types/AuthState.js\";\nimport { createUserRef } from \"../types/UserRef.js\";\nexport class AuthModuleImpl {\n #authService;\n app;\n signInPromise;\n constructor(app, authService) {\n this.app = app;\n this.#authService = authService;\n }\n\n // AuthModule interface implementation\n isAuthenticated() {\n return this.#authService.isAuthenticated();\n }\n async getToken() {\n return this.#authService.getToken();\n }\n getTokenOrUndefined() {\n return this.#authService.getTokenOrUndefined();\n }\n async signIn() {\n if (this.signInPromise) {\n return this.signInPromise;\n }\n this.signInPromise = (async () => {\n try {\n await this.#authService.signIn();\n } finally {\n this.signInPromise = undefined;\n }\n })();\n return this.signInPromise;\n }\n async signOut() {\n return this.#authService.signOut();\n }\n async refresh() {\n if (!this.#authService.refresh) {\n throw new Error(\"Refresh not supported for this auth client type\");\n }\n return this.#authService.refresh();\n }\n onAuthStateChange(callback) {\n return this.#authService.onAuthStateChange(callback);\n }\n onTokenChange(callback) {\n return this.#authService.onTokenChange(callback);\n }\n async waitForAuth() {\n // If already authenticated, resolve immediately\n if (this.isAuthenticated()) {\n return Promise.resolve();\n }\n return new Promise((resolve, reject) => {\n const unsubscribe = this.onAuthStateChange(event => {\n if (event.state === AuthState.Authenticated) {\n unsubscribe();\n resolve();\n } else if (event.state === AuthState.Error) {\n unsubscribe();\n reject(new Error(\"Authentication failed\", {\n cause: event.error\n }));\n }\n });\n });\n }\n getCurrentUser() {\n const userId = this.#authService.getCurrentUserId();\n if (!userId) {\n return undefined;\n }\n return createUserRef(this.app, userId);\n }\n async validateToken() {\n return this.#authService.validateToken();\n }\n async getUserData(userId, force) {\n return this.#authService.getUserData(userId, force);\n }\n dispose() {\n this.#authService.dispose();\n this.signInPromise = undefined;\n }\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AuthModuleImpl } from \"../utils/AuthModuleImpl.js\";\nexport const AUTH_MODULE_KEY = {\n appMemberName: \"auth\",\n key: Symbol.for(\"pack.auth\"),\n initModule: (app, config) => {\n if (!config) {\n throw new Error(\"AuthModuleConfig is required to initialize AuthModule\");\n }\n return new AuthModuleImpl(app, config.authService);\n }\n};","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { assertIsAppInternal } from \"@palantir/pack.core\";\nimport { AUTH_MODULE_KEY } from \"../constants/AuthModuleKey.js\";\n\n/**\n * AuthModule provides unified authentication services for PACK applications.\n *\n * It wraps OSDK OAuth clients and provides a consistent interface for authentication\n * state management, token access, and auth lifecycle events.\n */\n// TODO: functions should be method style\n\n/**\n * Get the auth module from an PACK app instance.\n *\n * @param app - PACK app instance\n * @returns The auth module\n */\nexport function getAuthModule(app) {\n assertIsAppInternal(app);\n return app.getModule(AUTH_MODULE_KEY);\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AUTH_MODULE_KEY } from \"../constants/AuthModuleKey.js\";\n\n/**\n * Configuration for AuthModule initialization\n */\n\n/**\n * Creates an auth module configuration tuple.\n *\n * @param authService - The auth service to use\n * @returns Module configuration tuple for the auth module\n */\nexport function createAuthModuleConfig(authService) {\n const config = {\n authService\n };\n return [AUTH_MODULE_KEY, config];\n}"]}
1
+ {"version":3,"sources":["../../src/types/AuthState.ts","../../src/types/UserRef.ts","../../src/utils/AuthModuleImpl.ts","../../src/constants/AuthModuleKey.ts","../../src/types/AuthModule.ts","../../src/utils/AuthModuleConfig.ts"],"names":["assertIsAppInternal"],"mappings":";;;;;;;AAgBO,IAAM,SAAA,GAAY;AAAA,EACvB,aAAA,EAAe,eAAA;A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AA,EACvB;AACF;;;ACpFO,IAAM,eAAA,GAAkB;AAAA,EAC7B,aAAA,EAAe,MAAA;AAAA,EACf,GAAA,EAAK,MAAA,CAAO,GAAA,CAAI,WAAW,CAAA;AAAA,EAC3B,UAAA,EAAY,CAAC,GAAA,EAAK,MAAA,KAAW;AAC3B,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,MAAM,IAAI,MAAM,uDAAuD,CAAA;AAAA,IACzE;AACA,IAAA,OAAO,IAAI,cAAA,CAAe,GAAA,EAAK,MAAA,CAAO,WAAW,CAAA;AAAA,EACnD;AACF,CAAA;;;ACMO,SAAS,cAAc,GAAA,EAAK;AACjC,EAAAA,6BAAA,CAAoB,GAAG,CAAA;AACvB,EAAA,OAAO,GAAA,CAAI,UAAU,eAAe,CAAA;AACtC;;;ACPO,SAAS,uBAAuB,WAAA,EAAa;AAClD,EAAA,MAAM,MAAA,GAAS;AAAA,IACb;AAAA,GACF;AACA,EAAA,OAAO,CAAC,iBAAiB,MAAM,CAAA;AACjC","file":"index.cjs","sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const AuthState = {\n Authenticated: \"authenticated\",\n Authenticating: \"authenticating\",\n Error: \"error\",\n Initializing: \"initializing\",\n Unauthenticated: \"unauthenticated\"\n};","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getAuthModule } from \"./AuthModule.js\";\nconst UserRefBrand = Symbol(\"UserRef\");\n\n/**\n * Reference to a user from the platform API.\n * Provides access to user information with caching.\n */\n\nconst INVALID_USER_ID = \"INVALID_USER_REF\";\nconst INVALID_USER_REF = Object.freeze({\n userId: INVALID_USER_ID,\n [UserRefBrand]: UserRefBrand,\n get: () => Promise.reject(new Error(\"Invalid user reference\"))\n});\n\n/**\n * Get an invalid user reference. This is a stable reference that can be used to\n * represent an invalid user.\n *\n * Not to be confused with a valid reference to a non-existent user, an invalid\n * reference is one that is not properly initialized. For example, code that\n * initializes with an undefined or empty userId might produce an invalid user\n * reference rather than propagate nullish types.\n *\n * Most operations on an invalid reference are no-ops. For the rest, it is\n * recommended to check for validity using {@link isValidUserRef} before\n * performing operations.\n */\nexport function invalidUserRef() {\n return INVALID_USER_REF;\n}\n\n/**\n * Check if a user reference is valid.\n *\n * Not to be confused with a valid reference to a non-existent user, an invalid\n * reference is one that is not properly initialized. For example, code that\n * initializes with an undefined or empty userId might produce an invalid user\n * reference rather than propagate nullish types.\n *\n * Most operations on an invalid reference are no-ops. For the rest, it is\n * recommended to check for validity using this function before performing\n * operations.\n */\nexport function isValidUserRef(userRef) {\n return userRef.userId !== INVALID_USER_ID && userRef.userId !== \"\";\n}\nexport const createUserRef = (app, userId) => {\n return new UserRefImpl(app, userId);\n};\nclass UserRefImpl {\n userId;\n #authModule;\n constructor(app, userId) {\n this.#authModule = getAuthModule(app);\n this.userId = userId;\n }\n get(force) {\n return this.#authModule.getUserData(this.userId, force);\n }\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AuthState } from \"../types/AuthState.js\";\nimport { createUserRef } from \"../types/UserRef.js\";\nexport class AuthModuleImpl {\n #authService;\n app;\n signInPromise;\n constructor(app, authService) {\n this.app = app;\n this.#authService = authService;\n }\n\n // AuthModule interface implementation\n isAuthenticated() {\n return this.#authService.isAuthenticated();\n }\n async getToken() {\n return this.#authService.getToken();\n }\n getTokenOrUndefined() {\n return this.#authService.getTokenOrUndefined();\n }\n async signIn() {\n if (this.signInPromise) {\n return this.signInPromise;\n }\n this.signInPromise = (async () => {\n try {\n await this.#authService.signIn();\n } finally {\n this.signInPromise = undefined;\n }\n })();\n return this.signInPromise;\n }\n async signOut() {\n return this.#authService.signOut();\n }\n async refresh() {\n if (!this.#authService.refresh) {\n throw new Error(\"Refresh not supported for this auth client type\");\n }\n return this.#authService.refresh();\n }\n onAuthStateChange(callback) {\n return this.#authService.onAuthStateChange(callback);\n }\n onTokenChange(callback) {\n return this.#authService.onTokenChange(callback);\n }\n async waitForAuth() {\n // If already authenticated, resolve immediately\n if (this.isAuthenticated()) {\n return Promise.resolve();\n }\n return new Promise((resolve, reject) => {\n const unsubscribe = this.onAuthStateChange(event => {\n if (event.state === AuthState.Authenticated) {\n unsubscribe();\n resolve();\n } else if (event.state === AuthState.Error) {\n unsubscribe();\n reject(new Error(\"Authentication failed\", {\n cause: event.error\n }));\n }\n });\n });\n }\n getCurrentUser(allowUnverified = false) {\n const userId = this.#authService.getCurrentUserId(allowUnverified);\n if (userId != null) {\n return createUserRef(this.app, userId);\n }\n return undefined;\n }\n async validateToken() {\n return this.#authService.validateToken();\n }\n async getUserData(userId, force) {\n return this.#authService.getUserData(userId, force);\n }\n dispose() {\n this.#authService.dispose();\n this.signInPromise = undefined;\n }\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AuthModuleImpl } from \"../utils/AuthModuleImpl.js\";\nexport const AUTH_MODULE_KEY = {\n appMemberName: \"auth\",\n key: Symbol.for(\"pack.auth\"),\n initModule: (app, config) => {\n if (!config) {\n throw new Error(\"AuthModuleConfig is required to initialize AuthModule\");\n }\n return new AuthModuleImpl(app, config.authService);\n }\n};","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { assertIsAppInternal } from \"@palantir/pack.core\";\nimport { AUTH_MODULE_KEY } from \"../constants/AuthModuleKey.js\";\n\n/**\n * AuthModule provides unified authentication services for PACK applications.\n *\n * It wraps OSDK OAuth clients and provides a consistent interface for authentication\n * state management, token access, and auth lifecycle events.\n */\n\n/**\n * Get the auth module from an PACK app instance.\n *\n * @param app - PACK app instance\n * @returns The auth module\n */\nexport function getAuthModule(app) {\n assertIsAppInternal(app);\n return app.getModule(AUTH_MODULE_KEY);\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AUTH_MODULE_KEY } from \"../constants/AuthModuleKey.js\";\n\n/**\n * Configuration for AuthModule initialization\n */\n\n/**\n * Creates an auth module configuration tuple.\n *\n * @param authService - The auth service to use\n * @returns Module configuration tuple for the auth module\n */\nexport function createAuthModuleConfig(authService) {\n const config = {\n authService\n };\n return [AUTH_MODULE_KEY, config];\n}"]}
@@ -31,7 +31,32 @@ interface UserRef {
31
31
  */
32
32
  readonly get: (force?: boolean) => Promise<unknown>;
33
33
  }
34
+ /**
35
+ * Get an invalid user reference. This is a stable reference that can be used to
36
+ * represent an invalid user.
37
+ *
38
+ * Not to be confused with a valid reference to a non-existent user, an invalid
39
+ * reference is one that is not properly initialized. For example, code that
40
+ * initializes with an undefined or empty userId might produce an invalid user
41
+ * reference rather than propagate nullish types.
42
+ *
43
+ * Most operations on an invalid reference are no-ops. For the rest, it is
44
+ * recommended to check for validity using {@link isValidUserRef} before
45
+ * performing operations.
46
+ */
34
47
  declare function invalidUserRef(): UserRef;
48
+ /**
49
+ * Check if a user reference is valid.
50
+ *
51
+ * Not to be confused with a valid reference to a non-existent user, an invalid
52
+ * reference is one that is not properly initialized. For example, code that
53
+ * initializes with an undefined or empty userId might produce an invalid user
54
+ * reference rather than propagate nullish types.
55
+ *
56
+ * Most operations on an invalid reference are no-ops. For the rest, it is
57
+ * recommended to check for validity using this function before performing
58
+ * operations.
59
+ */
35
60
  declare function isValidUserRef(userRef: UserRef): boolean;
36
61
  declare const createUserRef: (app: PackAppInternal, userId: UserId) => UserRef;
37
62
 
@@ -63,66 +88,69 @@ interface AuthModule {
63
88
  /**
64
89
  * Get the current user information.
65
90
  * Returns undefined if not authenticated or user data not available.
91
+ *
92
+ * @param allowUnverified - If true, will extract userId from token without validation.
93
+ * Defaults to false (requires validated token).
66
94
  */
67
- readonly getCurrentUser: () => UserRef | undefined;
95
+ getCurrentUser(allowUnverified?: boolean): UserRef | undefined;
68
96
  /**
69
97
  * Get an access token, automatically refreshing if needed.
70
98
  * Throws if authentication fails or user is not signed in.
71
99
  */
72
- readonly getToken: () => Promise<string>;
100
+ getToken(): Promise<string>;
73
101
  /**
74
102
  * Get the current access token without refresh, returns undefined if expired or unavailable.
75
103
  */
76
- readonly getTokenOrUndefined: () => string | undefined;
104
+ getTokenOrUndefined(): string | undefined;
77
105
  /**
78
106
  * Get user data for a specific user ID.
79
107
  * @param userId - The user ID to fetch data for
80
108
  * @param force - Force refresh of cached data
81
109
  * @returns Promise resolving to user data
82
110
  */
83
- readonly getUserData: (userId: string, force?: boolean) => Promise<unknown>;
111
+ getUserData(userId: string, force?: boolean): Promise<unknown>;
84
112
  /**
85
113
  * Check if the user is currently authenticated with a valid token.
86
114
  */
87
- readonly isAuthenticated: () => boolean;
115
+ isAuthenticated(): boolean;
88
116
  /**
89
117
  * Subscribe to authentication state changes.
90
118
  *
91
119
  * @param callback Function called when auth state changes
92
120
  * @returns Unsubscribe function
93
121
  */
94
- readonly onAuthStateChange: (callback: AuthStateCallback) => Unsubscribe;
122
+ onAuthStateChange(callback: AuthStateCallback): Unsubscribe;
95
123
  /**
96
124
  * Subscribe to token changes.
97
125
  *
98
126
  * @param callback Function called when token changes
99
127
  * @returns Unsubscribe function
100
128
  */
101
- readonly onTokenChange: (callback: TokenChangeCallback) => Unsubscribe;
129
+ onTokenChange(callback: TokenChangeCallback): Unsubscribe;
102
130
  /**
103
131
  * Manually refresh the access token using the refresh token.
104
132
  * Only available for public OAuth clients.
105
133
  */
106
- readonly refresh?: () => Promise<void>;
134
+ refresh?(): Promise<void>;
107
135
  /**
108
136
  * Initiate sign-in flow. For public clients, this redirects to OAuth.
109
137
  * For confidential clients, this performs client credentials flow.
110
138
  */
111
- readonly signIn: () => Promise<void>;
139
+ signIn(): Promise<void>;
112
140
  /**
113
141
  * Sign out the current user and clear tokens.
114
142
  */
115
- readonly signOut: () => Promise<void>;
143
+ signOut(): Promise<void>;
116
144
  /**
117
145
  * Validate the current token by checking with the platform API.
118
146
  * Returns true if the token is valid, false otherwise.
119
147
  */
120
- readonly validateToken: () => Promise<boolean>;
148
+ validateToken(): Promise<boolean>;
121
149
  /**
122
150
  * Wait for authentication to complete. Resolves when authenticated,
123
151
  * rejects if authentication fails or times out.
124
152
  */
125
- readonly waitForAuth: () => Promise<void>;
153
+ waitForAuth(): Promise<void>;
126
154
  }
127
155
  /**
128
156
  * Get the auth module from an PACK app instance.
@@ -133,12 +161,15 @@ interface AuthModule {
133
161
  declare function getAuthModule(app: PackAppInternal): AuthModule;
134
162
 
135
163
  /**
136
- * Base interface for auth services that wrap different OAuth client implementations
164
+ * Base interface for auth services that wrap different OAuth client implementations.
165
+ *
166
+ * This provides necessary functionality for other pack modules to seamlessly handle
167
+ * authentication flow & token management events such as initial login or token refresh.
137
168
  */
138
169
  interface BaseAuthService {
139
170
  dispose(): void;
140
171
  getCurrentState(): AuthState;
141
- getCurrentUserId(): string | undefined;
172
+ getCurrentUserId(allowUnverified?: boolean): string | undefined;
142
173
  getToken(): Promise<string>;
143
174
  getTokenOrUndefined(): string | undefined;
144
175
  getUserData(userId: string, force?: boolean): Promise<unknown>;
@@ -180,7 +211,7 @@ declare class AuthModuleImpl implements AuthModule {
180
211
  onAuthStateChange(callback: AuthStateCallback): Unsubscribe;
181
212
  onTokenChange(callback: TokenChangeCallback): Unsubscribe;
182
213
  waitForAuth(): Promise<void>;
183
- getCurrentUser(): UserRef | undefined;
214
+ getCurrentUser(allowUnverified?: boolean): UserRef | undefined;
184
215
  validateToken(): Promise<boolean>;
185
216
  getUserData(userId: string, force?: boolean): Promise<unknown>;
186
217
  dispose(): void;
@@ -105,12 +105,12 @@ var AuthModuleImpl = class {
105
105
  });
106
106
  });
107
107
  }
108
- getCurrentUser() {
109
- const userId = this.#authService.getCurrentUserId();
110
- if (!userId) {
111
- return void 0;
108
+ getCurrentUser(allowUnverified = false) {
109
+ const userId = this.#authService.getCurrentUserId(allowUnverified);
110
+ if (userId != null) {
111
+ return createUserRef(this.app, userId);
112
112
  }
113
- return createUserRef(this.app, userId);
113
+ return void 0;
114
114
  }
115
115
  async validateToken() {
116
116
  return this.#authService.validateToken();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/AuthState.ts","../../src/types/UserRef.ts","../../src/utils/AuthModuleImpl.ts","../../src/constants/AuthModuleKey.ts","../../src/types/AuthModule.ts","../../src/utils/AuthModuleConfig.ts"],"names":[],"mappings":";;;;;AAgBO,IAAM,SAAA,GAAY;AAAA,EACvB,aAAA,EAAe,eAAA;AAAA,EACf,cAAA,EAAgB,gBAAA;AAAA,EAChB,KAAA,EAAO,OAAA;AAAA,EACP,YAAA,EAAc,cAAA;AAAA,EACd,eAAA,EAAiB;AACnB;;;ACLA,IAAM,YAAA,GAAe,OAAO,SAAS,CAAA;AAOrC,IAAM,eAAA,GAAkB,kBAAA;AACxB,IAAM,gBAAA,GAAmB,OAAO,MAAA,CAAO;AAAA,EACrC,MAAA,EAAQ,eAAA;AAAA,EACR,CAAC,YAAY,GAAG,YAAA;AAAA,EAChB,KAAK,MAAM,OAAA,CAAQ,OAAO,IAAI,KAAA,CAAM,wBAAwB,CAAC;AAC/D,CAAC,CAAA;AACM,SAAS,cAAA,GAAiB;AAC/B,EAAA,OAAO,gBAAA;AACT;AACO,SAAS,eAAe,OAAA,EAAS;AACtC,EAAA,OAAO,OAAA,CAAQ,MAAA,KAAW,eAAA,IAAmB,OAAA,CAAQ,MAAA,KAAW,EAAA;AAClE;AACO,IAAM,aAAA,GAAgB,CAAC,GAAA,EAAK,MAAA,KAAW;AAC5C,EAAA,OAAO,IAAI,WAAA,CAAY,GAAA,EAAK,MAAM,CAAA;AACpC;AACA,IAAM,cAAN,MAAkB;AAAA,EAChB,MA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,MAAA,OAAO,MAAA;AAAA,IACT;AACA,IAAA,OAAO,aAAA,CAAc,IAAA,CAAK,GAAA,EAAK,MAAM,CAAA;AAAA,EACvC;AAAA,EACA,MAAM,aAAA,GAAgB;AACpB,IAAA,OAAO,IAAA,CAAK,aAAa,aAAA,EAAc;AAAA,EACzC;AAAA,EACA,MAAM,WAAA,CAAY,MAAA,EAAQ,KAAA,EAAO;AAC/B,IAAA,OAAO,IAAA,CAAK,YAAA,CAAa,WAAA,CAAY,MAAA,EAAQ,KAAK,CAAA;AAAA,EACpD;AAAA,EACA,OAAA,GAAU;AACR,IAAA,IAAA,CAAK,aAAa,OAAA,EAAQ;AAC1B,IAAA,IAAA,CAAK,aAAA,GAAgB,MAAA;AAAA,EACvB;AACF;;;ACpFO,IAAM,eAAA,GAAkB;AAAA,EAC7B,aAAA,EAAe,MAAA;AAAA,EACf,GAAA,EAAK,MAAA,CAAO,GAAA,CAAI,WAAW,CAAA;AAAA,EAC3B,UAAA,EAAY,CAAC,GAAA,EAAK,MAAA,KAAW;AAC3B,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,MAAM,IAAI,MAAM,uDAAuD,CAAA;AAAA,IACzE;AACA,IAAA,OAAO,IAAI,cAAA,CAAe,GAAA,EAAK,MAAA,CAAO,WAAW,CAAA;AAAA,EACnD;AACF,CAAA;;;ACOO,SAAS,cAAc,GAAA,EAAK;AACjC,EAAA,mBAAA,CAAoB,GAAG,CAAA;AACvB,EAAA,OAAO,GAAA,CAAI,UAAU,eAAe,CAAA;AACtC;;;ACRO,SAAS,uBAAuB,WAAA,EAAa;AAClD,EAAA,MAAM,MAAA,GAAS;AAAA,IACb;AAAA,GACF;AACA,EAAA,OAAO,CAAC,iBAAiB,MAAM,CAAA;AACjC","file":"index.js","sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const AuthState = {\n Authenticated: \"authenticated\",\n Authenticating: \"authenticating\",\n Error: \"error\",\n Initializing: \"initializing\",\n Unauthenticated: \"unauthenticated\"\n};","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getAuthModule } from \"./AuthModule.js\";\nconst UserRefBrand = Symbol(\"UserRef\");\n\n/**\n * Reference to a user from the platform API.\n * Provides access to user information with caching.\n */\n\nconst INVALID_USER_ID = \"INVALID_USER_REF\";\nconst INVALID_USER_REF = Object.freeze({\n userId: INVALID_USER_ID,\n [UserRefBrand]: UserRefBrand,\n get: () => Promise.reject(new Error(\"Invalid user reference\"))\n});\nexport function invalidUserRef() {\n return INVALID_USER_REF;\n}\nexport function isValidUserRef(userRef) {\n return userRef.userId !== INVALID_USER_ID && userRef.userId !== \"\";\n}\nexport const createUserRef = (app, userId) => {\n return new UserRefImpl(app, userId);\n};\nclass UserRefImpl {\n userId;\n #authModule;\n constructor(app, userId) {\n this.#authModule = getAuthModule(app);\n this.userId = userId;\n }\n get(force) {\n return this.#authModule.getUserData(this.userId, force);\n }\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AuthState } from \"../types/AuthState.js\";\nimport { createUserRef } from \"../types/UserRef.js\";\nexport class AuthModuleImpl {\n #authService;\n app;\n signInPromise;\n constructor(app, authService) {\n this.app = app;\n this.#authService = authService;\n }\n\n // AuthModule interface implementation\n isAuthenticated() {\n return this.#authService.isAuthenticated();\n }\n async getToken() {\n return this.#authService.getToken();\n }\n getTokenOrUndefined() {\n return this.#authService.getTokenOrUndefined();\n }\n async signIn() {\n if (this.signInPromise) {\n return this.signInPromise;\n }\n this.signInPromise = (async () => {\n try {\n await this.#authService.signIn();\n } finally {\n this.signInPromise = undefined;\n }\n })();\n return this.signInPromise;\n }\n async signOut() {\n return this.#authService.signOut();\n }\n async refresh() {\n if (!this.#authService.refresh) {\n throw new Error(\"Refresh not supported for this auth client type\");\n }\n return this.#authService.refresh();\n }\n onAuthStateChange(callback) {\n return this.#authService.onAuthStateChange(callback);\n }\n onTokenChange(callback) {\n return this.#authService.onTokenChange(callback);\n }\n async waitForAuth() {\n // If already authenticated, resolve immediately\n if (this.isAuthenticated()) {\n return Promise.resolve();\n }\n return new Promise((resolve, reject) => {\n const unsubscribe = this.onAuthStateChange(event => {\n if (event.state === AuthState.Authenticated) {\n unsubscribe();\n resolve();\n } else if (event.state === AuthState.Error) {\n unsubscribe();\n reject(new Error(\"Authentication failed\", {\n cause: event.error\n }));\n }\n });\n });\n }\n getCurrentUser() {\n const userId = this.#authService.getCurrentUserId();\n if (!userId) {\n return undefined;\n }\n return createUserRef(this.app, userId);\n }\n async validateToken() {\n return this.#authService.validateToken();\n }\n async getUserData(userId, force) {\n return this.#authService.getUserData(userId, force);\n }\n dispose() {\n this.#authService.dispose();\n this.signInPromise = undefined;\n }\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AuthModuleImpl } from \"../utils/AuthModuleImpl.js\";\nexport const AUTH_MODULE_KEY = {\n appMemberName: \"auth\",\n key: Symbol.for(\"pack.auth\"),\n initModule: (app, config) => {\n if (!config) {\n throw new Error(\"AuthModuleConfig is required to initialize AuthModule\");\n }\n return new AuthModuleImpl(app, config.authService);\n }\n};","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { assertIsAppInternal } from \"@palantir/pack.core\";\nimport { AUTH_MODULE_KEY } from \"../constants/AuthModuleKey.js\";\n\n/**\n * AuthModule provides unified authentication services for PACK applications.\n *\n * It wraps OSDK OAuth clients and provides a consistent interface for authentication\n * state management, token access, and auth lifecycle events.\n */\n// TODO: functions should be method style\n\n/**\n * Get the auth module from an PACK app instance.\n *\n * @param app - PACK app instance\n * @returns The auth module\n */\nexport function getAuthModule(app) {\n assertIsAppInternal(app);\n return app.getModule(AUTH_MODULE_KEY);\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AUTH_MODULE_KEY } from \"../constants/AuthModuleKey.js\";\n\n/**\n * Configuration for AuthModule initialization\n */\n\n/**\n * Creates an auth module configuration tuple.\n *\n * @param authService - The auth service to use\n * @returns Module configuration tuple for the auth module\n */\nexport function createAuthModuleConfig(authService) {\n const config = {\n authService\n };\n return [AUTH_MODULE_KEY, config];\n}"]}
1
+ {"version":3,"sources":["../../src/types/AuthState.ts","../../src/types/UserRef.ts","../../src/utils/AuthModuleImpl.ts","../../src/constants/AuthModuleKey.ts","../../src/types/AuthModule.ts","../../src/utils/AuthModuleConfig.ts"],"names":[],"mappings":";;;;;AAgBO,IAAM,SAAA,GAAY;AAAA,EACvB,aAAA,EAAe,eAAA;AAAA,EACf,cAAA,EAAgB,gBAAA;AAAA,EAChB,KAAA,EAAO,OAAA;AAAA,EACP,YAAA,EAAc,cAAA;AAAA,EACd,eAAA,EAAiB;AACnB;;;ACLA,IAAM,YAAA,GAAe,OAAO,SAAS,CAAA;AAOrC,IAAM,eAAA,GAAkB,kBAAA;AACxB,IAAM,gBAAA,GAAmB,OAAO,MAAA,CAAO;AAAA,EACrC,MAAA,EAAQ,eAAA;AAAA,EACR,CAAC,YAAY,GAAG,YAAA;AAAA,EAChB,KAAK,MAAM,OAAA,CAAQ,OAAO,IAAI,KAAA,CAAM,wBAAwB,CAAC;AAC/D,CAAC,CAAA;AAeM,SAAS,cAAA,GAAiB;AAC/B,EAAA,OAAO,gBAAA;AACT;AAcO,SAAS,eAAe,OAAA,EAAS;AACtC,EAAA,OAAO,OAAA,CAAQ,MAAA,KAAW,eAAA,IAAmB,OAAA,CAAQ,MAAA,KAAW,EAAA;AA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AA,GACF;AACA,EAAA,OAAO,CAAC,iBAAiB,MAAM,CAAA;AACjC","file":"index.js","sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const AuthState = {\n Authenticated: \"authenticated\",\n Authenticating: \"authenticating\",\n Error: \"error\",\n Initializing: \"initializing\",\n Unauthenticated: \"unauthenticated\"\n};","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getAuthModule } from \"./AuthModule.js\";\nconst UserRefBrand = Symbol(\"UserRef\");\n\n/**\n * Reference to a user from the platform API.\n * Provides access to user information with caching.\n */\n\nconst INVALID_USER_ID = \"INVALID_USER_REF\";\nconst INVALID_USER_REF = Object.freeze({\n userId: INVALID_USER_ID,\n [UserRefBrand]: UserRefBrand,\n get: () => Promise.reject(new Error(\"Invalid user reference\"))\n});\n\n/**\n * Get an invalid user reference. This is a stable reference that can be used to\n * represent an invalid user.\n *\n * Not to be confused with a valid reference to a non-existent user, an invalid\n * reference is one that is not properly initialized. For example, code that\n * initializes with an undefined or empty userId might produce an invalid user\n * reference rather than propagate nullish types.\n *\n * Most operations on an invalid reference are no-ops. For the rest, it is\n * recommended to check for validity using {@link isValidUserRef} before\n * performing operations.\n */\nexport function invalidUserRef() {\n return INVALID_USER_REF;\n}\n\n/**\n * Check if a user reference is valid.\n *\n * Not to be confused with a valid reference to a non-existent user, an invalid\n * reference is one that is not properly initialized. For example, code that\n * initializes with an undefined or empty userId might produce an invalid user\n * reference rather than propagate nullish types.\n *\n * Most operations on an invalid reference are no-ops. For the rest, it is\n * recommended to check for validity using this function before performing\n * operations.\n */\nexport function isValidUserRef(userRef) {\n return userRef.userId !== INVALID_USER_ID && userRef.userId !== \"\";\n}\nexport const createUserRef = (app, userId) => {\n return new UserRefImpl(app, userId);\n};\nclass UserRefImpl {\n userId;\n #authModule;\n constructor(app, userId) {\n this.#authModule = getAuthModule(app);\n this.userId = userId;\n }\n get(force) {\n return this.#authModule.getUserData(this.userId, force);\n }\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AuthState } from \"../types/AuthState.js\";\nimport { createUserRef } from \"../types/UserRef.js\";\nexport class AuthModuleImpl {\n #authService;\n app;\n signInPromise;\n constructor(app, authService) {\n this.app = app;\n this.#authService = authService;\n }\n\n // AuthModule interface implementation\n isAuthenticated() {\n return this.#authService.isAuthenticated();\n }\n async getToken() {\n return this.#authService.getToken();\n }\n getTokenOrUndefined() {\n return this.#authService.getTokenOrUndefined();\n }\n async signIn() {\n if (this.signInPromise) {\n return this.signInPromise;\n }\n this.signInPromise = (async () => {\n try {\n await this.#authService.signIn();\n } finally {\n this.signInPromise = undefined;\n }\n })();\n return this.signInPromise;\n }\n async signOut() {\n return this.#authService.signOut();\n }\n async refresh() {\n if (!this.#authService.refresh) {\n throw new Error(\"Refresh not supported for this auth client type\");\n }\n return this.#authService.refresh();\n }\n onAuthStateChange(callback) {\n return this.#authService.onAuthStateChange(callback);\n }\n onTokenChange(callback) {\n return this.#authService.onTokenChange(callback);\n }\n async waitForAuth() {\n // If already authenticated, resolve immediately\n if (this.isAuthenticated()) {\n return Promise.resolve();\n }\n return new Promise((resolve, reject) => {\n const unsubscribe = this.onAuthStateChange(event => {\n if (event.state === AuthState.Authenticated) {\n unsubscribe();\n resolve();\n } else if (event.state === AuthState.Error) {\n unsubscribe();\n reject(new Error(\"Authentication failed\", {\n cause: event.error\n }));\n }\n });\n });\n }\n getCurrentUser(allowUnverified = false) {\n const userId = this.#authService.getCurrentUserId(allowUnverified);\n if (userId != null) {\n return createUserRef(this.app, userId);\n }\n return undefined;\n }\n async validateToken() {\n return this.#authService.validateToken();\n }\n async getUserData(userId, force) {\n return this.#authService.getUserData(userId, force);\n }\n dispose() {\n this.#authService.dispose();\n this.signInPromise = undefined;\n }\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AuthModuleImpl } from \"../utils/AuthModuleImpl.js\";\nexport const AUTH_MODULE_KEY = {\n appMemberName: \"auth\",\n key: Symbol.for(\"pack.auth\"),\n initModule: (app, config) => {\n if (!config) {\n throw new Error(\"AuthModuleConfig is required to initialize AuthModule\");\n }\n return new AuthModuleImpl(app, config.authService);\n }\n};","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { assertIsAppInternal } from \"@palantir/pack.core\";\nimport { AUTH_MODULE_KEY } from \"../constants/AuthModuleKey.js\";\n\n/**\n * AuthModule provides unified authentication services for PACK applications.\n *\n * It wraps OSDK OAuth clients and provides a consistent interface for authentication\n * state management, token access, and auth lifecycle events.\n */\n\n/**\n * Get the auth module from an PACK app instance.\n *\n * @param app - PACK app instance\n * @returns The auth module\n */\nexport function getAuthModule(app) {\n assertIsAppInternal(app);\n return app.getModule(AUTH_MODULE_KEY);\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AUTH_MODULE_KEY } from \"../constants/AuthModuleKey.js\";\n\n/**\n * Configuration for AuthModule initialization\n */\n\n/**\n * Creates an auth module configuration tuple.\n *\n * @param authService - The auth service to use\n * @returns Module configuration tuple for the auth module\n */\nexport function createAuthModuleConfig(authService) {\n const config = {\n authService\n };\n return [AUTH_MODULE_KEY, config];\n}"]}
@@ -12,66 +12,69 @@ export interface AuthModule {
12
12
  /**
13
13
  * Get the current user information.
14
14
  * Returns undefined if not authenticated or user data not available.
15
+ *
16
+ * @param allowUnverified - If true, will extract userId from token without validation.
17
+ * Defaults to false (requires validated token).
15
18
  */
16
- readonly getCurrentUser: () => UserRef | undefined;
19
+ getCurrentUser(allowUnverified?: boolean): UserRef | undefined;
17
20
  /**
18
21
  * Get an access token, automatically refreshing if needed.
19
22
  * Throws if authentication fails or user is not signed in.
20
23
  */
21
- readonly getToken: () => Promise<string>;
24
+ getToken(): Promise<string>;
22
25
  /**
23
26
  * Get the current access token without refresh, returns undefined if expired or unavailable.
24
27
  */
25
- readonly getTokenOrUndefined: () => string | undefined;
28
+ getTokenOrUndefined(): string | undefined;
26
29
  /**
27
30
  * Get user data for a specific user ID.
28
31
  * @param userId - The user ID to fetch data for
29
32
  * @param force - Force refresh of cached data
30
33
  * @returns Promise resolving to user data
31
34
  */
32
- readonly getUserData: (userId: string, force?: boolean) => Promise<unknown>;
35
+ getUserData(userId: string, force?: boolean): Promise<unknown>;
33
36
  /**
34
37
  * Check if the user is currently authenticated with a valid token.
35
38
  */
36
- readonly isAuthenticated: () => boolean;
39
+ isAuthenticated(): boolean;
37
40
  /**
38
41
  * Subscribe to authentication state changes.
39
42
  *
40
43
  * @param callback Function called when auth state changes
41
44
  * @returns Unsubscribe function
42
45
  */
43
- readonly onAuthStateChange: (callback: AuthStateCallback) => Unsubscribe;
46
+ onAuthStateChange(callback: AuthStateCallback): Unsubscribe;
44
47
  /**
45
48
  * Subscribe to token changes.
46
49
  *
47
50
  * @param callback Function called when token changes
48
51
  * @returns Unsubscribe function
49
52
  */
50
- readonly onTokenChange: (callback: TokenChangeCallback) => Unsubscribe;
53
+ onTokenChange(callback: TokenChangeCallback): Unsubscribe;
51
54
  /**
52
55
  * Manually refresh the access token using the refresh token.
53
56
  * Only available for public OAuth clients.
54
57
  */
55
- readonly refresh?: () => Promise<void>;
58
+ refresh?(): Promise<void>;
56
59
  /**
57
60
  * Initiate sign-in flow. For public clients, this redirects to OAuth.
58
61
  * For confidential clients, this performs client credentials flow.
59
62
  */
60
- readonly signIn: () => Promise<void>;
63
+ signIn(): Promise<void>;
61
64
  /**
62
65
  * Sign out the current user and clear tokens.
63
66
  */
64
- readonly signOut: () => Promise<void>;
67
+ signOut(): Promise<void>;
65
68
  /**
66
69
  * Validate the current token by checking with the platform API.
67
70
  * Returns true if the token is valid, false otherwise.
68
71
  */
69
- readonly validateToken: () => Promise<boolean>;
72
+ validateToken(): Promise<boolean>;
70
73
  /**
71
74
  * Wait for authentication to complete. Resolves when authenticated,
72
75
  * rejects if authentication fails or times out.
73
76
  */
74
- readonly waitForAuth: () => Promise<void>;
77
+ waitForAuth(): Promise<void>;
75
78
  }
76
79
  /**
77
80
  * Get the auth module from an PACK app instance.
@@ -1 +1 @@
1
- {"mappings":"AAgBA,cAAc,iBAAiB,mBAAmB;AAGlD,cAAc,yBAAyB;AACvC,cAAc,2BAA2B;AACzC,cAAc,eAAe;;;;;;;AAS7B,iBAAiB,WAAW;;;;;UAKjB,sBAAsB;;;;;UAMtB,gBAAgB;;;;UAKhB;;;;;;;UAQA,cAAc,gBAAgB,oBAAoB;;;;UAKlD;;;;;;;UAQA,oBAAoB,UAAU,sBAAsB;;;;;;;UAQpD,gBAAgB,UAAU,wBAAwB;;;;;UAMlD,gBAAgB;;;;;UAMhB,cAAc;;;;UAKd,eAAe;;;;;UAMf,qBAAqB;;;;;UAMrB,mBAAmB;;;;;;;;AAS9B,OAAO,iBAAS,cAAc,KAAK,kBAAkB","names":[],"sources":["../../../src/types/AuthModule.ts"],"version":3,"file":"AuthModule.d.ts"}
1
+ {"mappings":"AAgBA,cAAc,iBAAiB,mBAAmB;AAGlD,cAAc,yBAAyB;AACvC,cAAc,2BAA2B;AACzC,cAAc,eAAe;;;;;;;AAQ7B,iBAAiB,WAAW;;;;;;;;CAQ1B,eAAe,4BAA4B;;;;;CAM3C,YAAY;;;;CAKZ;;;;;;;CAQA,YAAY,gBAAgB,kBAAkB;;;;CAK9C;;;;;;;CAQA,kBAAkB,UAAU,oBAAoB;;;;;;;CAQhD,cAAc,UAAU,sBAAsB;;;;;CAM9C,YAAY;;;;;CAMZ,UAAU;;;;CAKV,WAAW;;;;;CAMX,iBAAiB;;;;;CAMjB,eAAe;;;;;;;;AASjB,OAAO,iBAAS,cAAc,KAAK,kBAAkB","names":[],"sources":["../../../src/types/AuthModule.ts"],"version":3,"file":"AuthModule.d.ts"}
@@ -2,12 +2,15 @@ import type { Unsubscribe } from "@palantir/pack.core";
2
2
  import type { AuthState, AuthStateCallback } from "./AuthState.js";
3
3
  import type { TokenChangeCallback } from "./TokenChange.js";
4
4
  /**
5
- * Base interface for auth services that wrap different OAuth client implementations
5
+ * Base interface for auth services that wrap different OAuth client implementations.
6
+ *
7
+ * This provides necessary functionality for other pack modules to seamlessly handle
8
+ * authentication flow & token management events such as initial login or token refresh.
6
9
  */
7
10
  export interface BaseAuthService {
8
11
  dispose(): void;
9
12
  getCurrentState(): AuthState;
10
- getCurrentUserId(): string | undefined;
13
+ getCurrentUserId(allowUnverified?: boolean): string | undefined;
11
14
  getToken(): Promise<string>;
12
15
  getTokenOrUndefined(): string | undefined;
13
16
  getUserData(userId: string, force?: boolean): Promise<unknown>;
@@ -1 +1 @@
1
- {"mappings":"AAgBA,cAAc,mBAAmB;AACjC,cAAc,WAAW,yBAAyB;AAClD,cAAc,2BAA2B;;;;AAKzC,iBAAiB,gBAAgB;CAC/B;CACA,mBAAmB;CACnB;CACA,YAAY;CACZ;CACA,YAAY,gBAAgB,kBAAkB;CAC9C;CACA;CACA,kBAAkB,UAAU,oBAAoB;CAChD,cAAc,UAAU,sBAAsB;CAC9C,YAAY;CACZ,UAAU;CACV,WAAW;CACX,iBAAiB","names":[],"sources":["../../../src/types/BaseAuthService.ts"],"version":3,"file":"BaseAuthService.d.ts"}
1
+ {"mappings":"AAgBA,cAAc,mBAAmB;AACjC,cAAc,WAAW,yBAAyB;AAClD,cAAc,2BAA2B;;;;;;;AAQzC,iBAAiB,gBAAgB;CAC/B;CACA,mBAAmB;CACnB,iBAAiB;CACjB,YAAY;CACZ;CACA,YAAY,gBAAgB,kBAAkB;CAC9C;CACA;CACA,kBAAkB,UAAU,oBAAoB;CAChD,cAAc,UAAU,sBAAsB;CAC9C,YAAY;CACZ,UAAU;CACV,WAAW;CACX,iBAAiB","names":[],"sources":["../../../src/types/BaseAuthService.ts"],"version":3,"file":"BaseAuthService.d.ts"}
@@ -15,7 +15,32 @@ export interface UserRef {
15
15
  */
16
16
  readonly get: (force?: boolean) => Promise<unknown>;
17
17
  }
18
+ /**
19
+ * Get an invalid user reference. This is a stable reference that can be used to
20
+ * represent an invalid user.
21
+ *
22
+ * Not to be confused with a valid reference to a non-existent user, an invalid
23
+ * reference is one that is not properly initialized. For example, code that
24
+ * initializes with an undefined or empty userId might produce an invalid user
25
+ * reference rather than propagate nullish types.
26
+ *
27
+ * Most operations on an invalid reference are no-ops. For the rest, it is
28
+ * recommended to check for validity using {@link isValidUserRef} before
29
+ * performing operations.
30
+ */
18
31
  export declare function invalidUserRef(): UserRef;
32
+ /**
33
+ * Check if a user reference is valid.
34
+ *
35
+ * Not to be confused with a valid reference to a non-existent user, an invalid
36
+ * reference is one that is not properly initialized. For example, code that
37
+ * initializes with an undefined or empty userId might produce an invalid user
38
+ * reference rather than propagate nullish types.
39
+ *
40
+ * Most operations on an invalid reference are no-ops. For the rest, it is
41
+ * recommended to check for validity using this function before performing
42
+ * operations.
43
+ */
19
44
  export declare function isValidUserRef(userRef: UserRef): boolean;
20
45
  export declare const createUserRef: (app: PackAppInternal, userId: UserId) => UserRef;
21
46
  export {};
@@ -1 +1 @@
1
- {"mappings":"AAgBA,cAAc,UAAU,uBAAuB;AAI/C,cAAMA;AACN,YAAY,SAAS,SAAS;;;;;AAM9B,iBAAiB,QAAQ;UACd,QAAQ;WACP,sBAAsB;;;;;;UAOvB,MAAM,oBAAoB;;AAYrC,OAAO,iBAAS,kBAAkB;AAIlC,OAAO,iBAAS,eAAe,SAAS;AAIxC,OAAO,cAAM,gBACX,KAAK,iBACL,QAAQ,WACP","names":["UserRefBrand: unique symbol"],"sources":["../../../src/types/UserRef.ts"],"version":3,"file":"UserRef.d.ts"}
1
+ {"mappings":"AAgBA,cAAc,UAAU,uBAAuB;AAI/C,cAAMA;AACN,YAAY,SAAS,SAAS;;;;;AAM9B,iBAAiB,QAAQ;UACd,QAAQ;WACP,sBAAsB;;;;;;UAOvB,MAAM,oBAAoB;;;;;;;;;;;;;;;AAyBrC,OAAO,iBAAS,kBAAkB;;;;;;;;;;;;;AAgBlC,OAAO,iBAAS,eAAe,SAAS;AAIxC,OAAO,cAAM,gBACX,KAAK,iBACL,QAAQ,WACP","names":["UserRefBrand: unique symbol"],"sources":["../../../src/types/UserRef.ts"],"version":3,"file":"UserRef.d.ts"}
@@ -18,7 +18,7 @@ export declare class AuthModuleImpl implements AuthModule {
18
18
  onAuthStateChange(callback: AuthStateCallback): Unsubscribe;
19
19
  onTokenChange(callback: TokenChangeCallback): Unsubscribe;
20
20
  waitForAuth(): Promise<void>;
21
- getCurrentUser(): UserRef | undefined;
21
+ getCurrentUser(allowUnverified?: boolean): UserRef | undefined;
22
22
  validateToken(): Promise<boolean>;
23
23
  getUserData(userId: string, force?: boolean): Promise<unknown>;
24
24
  dispose(): void;
@@ -1 +1 @@
1
- {"mappings":"AAgBA,cAAc,sBAAsB,mBAAmB;AACvD,cAAc,kBAAkB;AAChC,cAAc,yBAAyB;AAEvC,cAAc,uBAAuB;AACrC,cAAc,2BAA2B;AACzC,cAAc,eAAe;AAG7B,OAAO,cAAM,0BAA0B,WAAW;;CAEhD,iBAAiB;CACjB,QAAQ;CAER,YAAY,KAAK,iBAAiB,aAAa;CAM/C;CAIA,AAAM,YAAY;CAIlB;CAIA,AAAM,UAAU;CAgBhB,AAAM,WAAW;CAIjB,AAAM,WAAW;CAQjB,kBAAkB,UAAU,oBAAoB;CAIhD,cAAc,UAAU,sBAAsB;CAI9C,AAAM,eAAe;CAmBrB,kBAAkB;CAQlB,AAAM,iBAAiB;CAIvB,AAAM,YAAY,gBAAgB,kBAAkB;CAIpD","names":[],"sources":["../../../src/utils/AuthModuleImpl.ts"],"version":3,"file":"AuthModuleImpl.d.ts"}
1
+ {"mappings":"AAgBA,cAAc,sBAAsB,mBAAmB;AACvD,cAAc,kBAAkB;AAChC,cAAc,yBAAyB;AAEvC,cAAc,uBAAuB;AACrC,cAAc,2BAA2B;AACzC,cAAc,eAAe;AAG7B,OAAO,cAAM,0BAA0B,WAAW;;CAEhD,iBAAiB;CACjB,QAAQ;CAER,YAAY,KAAK,iBAAiB,aAAa;CAM/C;CAIA,AAAM,YAAY;CAIlB;CAIA,AAAM,UAAU;CAgBhB,AAAM,WAAW;CAIjB,AAAM,WAAW;CAQjB,kBAAkB,UAAU,oBAAoB;CAIhD,cAAc,UAAU,sBAAsB;CAI9C,AAAM,eAAe;CAmBrB,eAAe,4BAA0B;CAQzC,AAAM,iBAAiB;CAIvB,AAAM,YAAY,gBAAgB,kBAAkB;CAIpD","names":[],"sources":["../../../src/utils/AuthModuleImpl.ts"],"version":3,"file":"AuthModuleImpl.d.ts"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@palantir/pack.auth",
3
- "version": "0.0.1-beta.1",
3
+ "version": "0.0.2",
4
4
  "description": "Authentication system for PACK applications",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "tiny-invariant": "^1.3.3",
32
- "@palantir/pack.core": "0.1.0-beta.2"
32
+ "@palantir/pack.core": "0.1.1"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@osdk/client": "~2.4.2"
@@ -39,7 +39,7 @@
39
39
  "tslib": "^2.8.1",
40
40
  "typescript": "^5.9.2",
41
41
  "vitest-mock-extended": "^3.1.0",
42
- "@palantir/pack.monorepo.tsconfig": "~0.4.0-beta.1"
42
+ "@palantir/pack.monorepo.tsconfig": "~0.4.3"
43
43
  },
44
44
  "publishConfig": {
45
45
  "access": "public"
@@ -54,8 +54,8 @@
54
54
  "type": "module",
55
55
  "scripts": {
56
56
  "clean": "rimraf .turbo build dist lib test-output *.tgz tsconfig.tsbuildinfo",
57
- "lint": "eslint ./src ; dprint check --config $(find-up dprint.json) --allow-no-files",
58
- "lint:fix": "eslint ./src --fix ; dprint fmt --config $(find-up dprint.json) --allow-no-files",
57
+ "lint": "eslint ./src && dprint check --config $(find-up dprint.json) --allow-no-files",
58
+ "lint:fix": "eslint ./src --fix && dprint fmt --config $(find-up dprint.json) --allow-no-files",
59
59
  "test": "vitest run --passWithNoTests -u",
60
60
  "test:watch": "vitest --passWithNoTests",
61
61
  "transpileBrowser": "monorepo-transpile -f esm -m bundle -t browser",
@@ -27,24 +27,26 @@ import type { UserRef } from "./UserRef.js";
27
27
  * It wraps OSDK OAuth clients and provides a consistent interface for authentication
28
28
  * state management, token access, and auth lifecycle events.
29
29
  */
30
- // TODO: functions should be method style
31
30
  export interface AuthModule {
32
31
  /**
33
32
  * Get the current user information.
34
33
  * Returns undefined if not authenticated or user data not available.
34
+ *
35
+ * @param allowUnverified - If true, will extract userId from token without validation.
36
+ * Defaults to false (requires validated token).
35
37
  */
36
- readonly getCurrentUser: () => UserRef | undefined;
38
+ getCurrentUser(allowUnverified?: boolean): UserRef | undefined;
37
39
 
38
40
  /**
39
41
  * Get an access token, automatically refreshing if needed.
40
42
  * Throws if authentication fails or user is not signed in.
41
43
  */
42
- readonly getToken: () => Promise<string>;
44
+ getToken(): Promise<string>;
43
45
 
44
46
  /**
45
47
  * Get the current access token without refresh, returns undefined if expired or unavailable.
46
48
  */
47
- readonly getTokenOrUndefined: () => string | undefined;
49
+ getTokenOrUndefined(): string | undefined;
48
50
 
49
51
  /**
50
52
  * Get user data for a specific user ID.
@@ -52,12 +54,12 @@ export interface AuthModule {
52
54
  * @param force - Force refresh of cached data
53
55
  * @returns Promise resolving to user data
54
56
  */
55
- readonly getUserData: (userId: string, force?: boolean) => Promise<unknown>;
57
+ getUserData(userId: string, force?: boolean): Promise<unknown>;
56
58
 
57
59
  /**
58
60
  * Check if the user is currently authenticated with a valid token.
59
61
  */
60
- readonly isAuthenticated: () => boolean;
62
+ isAuthenticated(): boolean;
61
63
 
62
64
  /**
63
65
  * Subscribe to authentication state changes.
@@ -65,7 +67,7 @@ export interface AuthModule {
65
67
  * @param callback Function called when auth state changes
66
68
  * @returns Unsubscribe function
67
69
  */
68
- readonly onAuthStateChange: (callback: AuthStateCallback) => Unsubscribe;
70
+ onAuthStateChange(callback: AuthStateCallback): Unsubscribe;
69
71
 
70
72
  /**
71
73
  * Subscribe to token changes.
@@ -73,36 +75,36 @@ export interface AuthModule {
73
75
  * @param callback Function called when token changes
74
76
  * @returns Unsubscribe function
75
77
  */
76
- readonly onTokenChange: (callback: TokenChangeCallback) => Unsubscribe;
78
+ onTokenChange(callback: TokenChangeCallback): Unsubscribe;
77
79
 
78
80
  /**
79
81
  * Manually refresh the access token using the refresh token.
80
82
  * Only available for public OAuth clients.
81
83
  */
82
- readonly refresh?: () => Promise<void>;
84
+ refresh?(): Promise<void>;
83
85
 
84
86
  /**
85
87
  * Initiate sign-in flow. For public clients, this redirects to OAuth.
86
88
  * For confidential clients, this performs client credentials flow.
87
89
  */
88
- readonly signIn: () => Promise<void>;
90
+ signIn(): Promise<void>;
89
91
 
90
92
  /**
91
93
  * Sign out the current user and clear tokens.
92
94
  */
93
- readonly signOut: () => Promise<void>;
95
+ signOut(): Promise<void>;
94
96
 
95
97
  /**
96
98
  * Validate the current token by checking with the platform API.
97
99
  * Returns true if the token is valid, false otherwise.
98
100
  */
99
- readonly validateToken: () => Promise<boolean>;
101
+ validateToken(): Promise<boolean>;
100
102
 
101
103
  /**
102
104
  * Wait for authentication to complete. Resolves when authenticated,
103
105
  * rejects if authentication fails or times out.
104
106
  */
105
- readonly waitForAuth: () => Promise<void>;
107
+ waitForAuth(): Promise<void>;
106
108
  }
107
109
 
108
110
  /**
@@ -19,12 +19,15 @@ import type { AuthState, AuthStateCallback } from "./AuthState.js";
19
19
  import type { TokenChangeCallback } from "./TokenChange.js";
20
20
 
21
21
  /**
22
- * Base interface for auth services that wrap different OAuth client implementations
22
+ * Base interface for auth services that wrap different OAuth client implementations.
23
+ *
24
+ * This provides necessary functionality for other pack modules to seamlessly handle
25
+ * authentication flow & token management events such as initial login or token refresh.
23
26
  */
24
27
  export interface BaseAuthService {
25
28
  dispose(): void;
26
29
  getCurrentState(): AuthState;
27
- getCurrentUserId(): string | undefined;
30
+ getCurrentUserId(allowUnverified?: boolean): string | undefined;
28
31
  getToken(): Promise<string>;
29
32
  getTokenOrUndefined(): string | undefined;
30
33
  getUserData(userId: string, force?: boolean): Promise<unknown>;
@@ -46,10 +46,35 @@ const INVALID_USER_REF: UserRef = Object.freeze(
46
46
  } as const,
47
47
  );
48
48
 
49
+ /**
50
+ * Get an invalid user reference. This is a stable reference that can be used to
51
+ * represent an invalid user.
52
+ *
53
+ * Not to be confused with a valid reference to a non-existent user, an invalid
54
+ * reference is one that is not properly initialized. For example, code that
55
+ * initializes with an undefined or empty userId might produce an invalid user
56
+ * reference rather than propagate nullish types.
57
+ *
58
+ * Most operations on an invalid reference are no-ops. For the rest, it is
59
+ * recommended to check for validity using {@link isValidUserRef} before
60
+ * performing operations.
61
+ */
49
62
  export function invalidUserRef(): UserRef {
50
63
  return INVALID_USER_REF;
51
64
  }
52
65
 
66
+ /**
67
+ * Check if a user reference is valid.
68
+ *
69
+ * Not to be confused with a valid reference to a non-existent user, an invalid
70
+ * reference is one that is not properly initialized. For example, code that
71
+ * initializes with an undefined or empty userId might produce an invalid user
72
+ * reference rather than propagate nullish types.
73
+ *
74
+ * Most operations on an invalid reference are no-ops. For the rest, it is
75
+ * recommended to check for validity using this function before performing
76
+ * operations.
77
+ */
53
78
  export function isValidUserRef(userRef: UserRef): boolean {
54
79
  return userRef.userId !== INVALID_USER_ID && userRef.userId !== "";
55
80
  }
@@ -101,12 +101,12 @@ export class AuthModuleImpl implements AuthModule {
101
101
  });
102
102
  }
103
103
 
104
- getCurrentUser(): UserRef | undefined {
105
- const userId = this.#authService.getCurrentUserId();
106
- if (!userId) {
107
- return undefined;
104
+ getCurrentUser(allowUnverified = false): UserRef | undefined {
105
+ const userId = this.#authService.getCurrentUserId(allowUnverified);
106
+ if (userId != null) {
107
+ return createUserRef(this.app, userId);
108
108
  }
109
- return createUserRef(this.app, userId);
109
+ return undefined;
110
110
  }
111
111
 
112
112
  async validateToken(): Promise<boolean> {