@palantir/pack.auth 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-transpileBrowser.log +1 -1
- package/.turbo/turbo-transpileCjs.log +1 -1
- package/.turbo/turbo-transpileEsm.log +1 -1
- package/.turbo/turbo-transpileTypes.log +1 -1
- package/.turbo/turbo-typecheck.log +1 -1
- package/CHANGELOG.md +20 -0
- package/build/browser/index.js.map +1 -1
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +41 -13
- package/build/esm/index.js.map +1 -1
- package/build/types/types/AuthModule.d.ts +12 -12
- package/build/types/types/AuthModule.d.ts.map +1 -1
- package/build/types/types/BaseAuthService.d.ts +4 -1
- package/build/types/types/BaseAuthService.d.ts.map +1 -1
- package/build/types/types/UserRef.d.ts +25 -0
- package/build/types/types/UserRef.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/types/AuthModule.ts +12 -13
- package/src/types/BaseAuthService.ts +4 -1
- package/src/types/UserRef.ts +25 -0
package/.turbo/turbo-lint.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @palantir/pack.auth
|
|
2
2
|
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- dfeaeb0: Fix bug in core, where multiple yDocs could get created, causing the initial update to be dropped
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [dfeaeb0]
|
|
12
|
+
- @palantir/pack.core@0.2.0
|
|
13
|
+
|
|
14
|
+
## 0.0.2
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 67df6e4: Documented public apis
|
|
19
|
+
- Updated dependencies [eba27ae]
|
|
20
|
+
- Updated dependencies [67df6e4]
|
|
21
|
+
- @palantir/pack.core@0.1.1
|
|
22
|
+
|
|
3
23
|
## 0.0.1
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -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,MAAA;AAAA,EACA,WAAA;AAAA,EACA,WAAA,CAAY,KAAK,MAAA,EAAQ;AACvB,IAAA,IAAA,CAAK,WAAA,GAAc,cAAc,GAAG,CAAA;AACpC,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;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AA,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(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// 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;AAClE;AACO,IAAM,aAAA,GAAgB,CAAC,GAAA,EAAK,MAAA,KAAW;AAC5C,EAAA,OAAO,IAAI,WAAA,CAAY,GAA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ologies, 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}"]}
|
package/build/cjs/index.cjs.map
CHANGED
|
@@ -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;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,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,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(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// 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;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;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,MAAA;AAAA,EACA,WAAA;AAAA,EACA,WAAA,CAAY,KAAK,MAAA,EAAQ;AACvB,IAAA,IAAA,CAAK,WAAA,GAAc,cAAc,GAAG,CAAA;AACpC,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AAAA,EAChB;AAAA,EACA,IAAI,KAAA,EAAO;AACT,IAAA,OAAO,I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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;;;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}"]}
|
package/build/cjs/index.d.cts
CHANGED
|
@@ -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
|
|
|
@@ -67,65 +92,65 @@ interface AuthModule {
|
|
|
67
92
|
* @param allowUnverified - If true, will extract userId from token without validation.
|
|
68
93
|
* Defaults to false (requires validated token).
|
|
69
94
|
*/
|
|
70
|
-
|
|
95
|
+
getCurrentUser(allowUnverified?: boolean): UserRef | undefined;
|
|
71
96
|
/**
|
|
72
97
|
* Get an access token, automatically refreshing if needed.
|
|
73
98
|
* Throws if authentication fails or user is not signed in.
|
|
74
99
|
*/
|
|
75
|
-
|
|
100
|
+
getToken(): Promise<string>;
|
|
76
101
|
/**
|
|
77
102
|
* Get the current access token without refresh, returns undefined if expired or unavailable.
|
|
78
103
|
*/
|
|
79
|
-
|
|
104
|
+
getTokenOrUndefined(): string | undefined;
|
|
80
105
|
/**
|
|
81
106
|
* Get user data for a specific user ID.
|
|
82
107
|
* @param userId - The user ID to fetch data for
|
|
83
108
|
* @param force - Force refresh of cached data
|
|
84
109
|
* @returns Promise resolving to user data
|
|
85
110
|
*/
|
|
86
|
-
|
|
111
|
+
getUserData(userId: string, force?: boolean): Promise<unknown>;
|
|
87
112
|
/**
|
|
88
113
|
* Check if the user is currently authenticated with a valid token.
|
|
89
114
|
*/
|
|
90
|
-
|
|
115
|
+
isAuthenticated(): boolean;
|
|
91
116
|
/**
|
|
92
117
|
* Subscribe to authentication state changes.
|
|
93
118
|
*
|
|
94
119
|
* @param callback Function called when auth state changes
|
|
95
120
|
* @returns Unsubscribe function
|
|
96
121
|
*/
|
|
97
|
-
|
|
122
|
+
onAuthStateChange(callback: AuthStateCallback): Unsubscribe;
|
|
98
123
|
/**
|
|
99
124
|
* Subscribe to token changes.
|
|
100
125
|
*
|
|
101
126
|
* @param callback Function called when token changes
|
|
102
127
|
* @returns Unsubscribe function
|
|
103
128
|
*/
|
|
104
|
-
|
|
129
|
+
onTokenChange(callback: TokenChangeCallback): Unsubscribe;
|
|
105
130
|
/**
|
|
106
131
|
* Manually refresh the access token using the refresh token.
|
|
107
132
|
* Only available for public OAuth clients.
|
|
108
133
|
*/
|
|
109
|
-
|
|
134
|
+
refresh?(): Promise<void>;
|
|
110
135
|
/**
|
|
111
136
|
* Initiate sign-in flow. For public clients, this redirects to OAuth.
|
|
112
137
|
* For confidential clients, this performs client credentials flow.
|
|
113
138
|
*/
|
|
114
|
-
|
|
139
|
+
signIn(): Promise<void>;
|
|
115
140
|
/**
|
|
116
141
|
* Sign out the current user and clear tokens.
|
|
117
142
|
*/
|
|
118
|
-
|
|
143
|
+
signOut(): Promise<void>;
|
|
119
144
|
/**
|
|
120
145
|
* Validate the current token by checking with the platform API.
|
|
121
146
|
* Returns true if the token is valid, false otherwise.
|
|
122
147
|
*/
|
|
123
|
-
|
|
148
|
+
validateToken(): Promise<boolean>;
|
|
124
149
|
/**
|
|
125
150
|
* Wait for authentication to complete. Resolves when authenticated,
|
|
126
151
|
* rejects if authentication fails or times out.
|
|
127
152
|
*/
|
|
128
|
-
|
|
153
|
+
waitForAuth(): Promise<void>;
|
|
129
154
|
}
|
|
130
155
|
/**
|
|
131
156
|
* Get the auth module from an PACK app instance.
|
|
@@ -136,7 +161,10 @@ interface AuthModule {
|
|
|
136
161
|
declare function getAuthModule(app: PackAppInternal): AuthModule;
|
|
137
162
|
|
|
138
163
|
/**
|
|
139
|
-
* 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.
|
|
140
168
|
*/
|
|
141
169
|
interface BaseAuthService {
|
|
142
170
|
dispose(): void;
|
package/build/esm/index.js.map
CHANGED
|
@@ -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,MAAA;AAAA,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UAAU,IAAA,EAAM;AAClB,MAAA,OAAO,aAAA,CAAc,IAAA,CAAK,GAAA,EAAK,MAAM,CAAA;AAAA,IACvC;AACA,IAAA,OAAO,MAAA;AAAA,EACT;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(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// 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,KA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,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}"]}
|
|
@@ -16,65 +16,65 @@ export interface AuthModule {
|
|
|
16
16
|
* @param allowUnverified - If true, will extract userId from token without validation.
|
|
17
17
|
* Defaults to false (requires validated token).
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
getCurrentUser(allowUnverified?: boolean): UserRef | undefined;
|
|
20
20
|
/**
|
|
21
21
|
* Get an access token, automatically refreshing if needed.
|
|
22
22
|
* Throws if authentication fails or user is not signed in.
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
getToken(): Promise<string>;
|
|
25
25
|
/**
|
|
26
26
|
* Get the current access token without refresh, returns undefined if expired or unavailable.
|
|
27
27
|
*/
|
|
28
|
-
|
|
28
|
+
getTokenOrUndefined(): string | undefined;
|
|
29
29
|
/**
|
|
30
30
|
* Get user data for a specific user ID.
|
|
31
31
|
* @param userId - The user ID to fetch data for
|
|
32
32
|
* @param force - Force refresh of cached data
|
|
33
33
|
* @returns Promise resolving to user data
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
getUserData(userId: string, force?: boolean): Promise<unknown>;
|
|
36
36
|
/**
|
|
37
37
|
* Check if the user is currently authenticated with a valid token.
|
|
38
38
|
*/
|
|
39
|
-
|
|
39
|
+
isAuthenticated(): boolean;
|
|
40
40
|
/**
|
|
41
41
|
* Subscribe to authentication state changes.
|
|
42
42
|
*
|
|
43
43
|
* @param callback Function called when auth state changes
|
|
44
44
|
* @returns Unsubscribe function
|
|
45
45
|
*/
|
|
46
|
-
|
|
46
|
+
onAuthStateChange(callback: AuthStateCallback): Unsubscribe;
|
|
47
47
|
/**
|
|
48
48
|
* Subscribe to token changes.
|
|
49
49
|
*
|
|
50
50
|
* @param callback Function called when token changes
|
|
51
51
|
* @returns Unsubscribe function
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
onTokenChange(callback: TokenChangeCallback): Unsubscribe;
|
|
54
54
|
/**
|
|
55
55
|
* Manually refresh the access token using the refresh token.
|
|
56
56
|
* Only available for public OAuth clients.
|
|
57
57
|
*/
|
|
58
|
-
|
|
58
|
+
refresh?(): Promise<void>;
|
|
59
59
|
/**
|
|
60
60
|
* Initiate sign-in flow. For public clients, this redirects to OAuth.
|
|
61
61
|
* For confidential clients, this performs client credentials flow.
|
|
62
62
|
*/
|
|
63
|
-
|
|
63
|
+
signIn(): Promise<void>;
|
|
64
64
|
/**
|
|
65
65
|
* Sign out the current user and clear tokens.
|
|
66
66
|
*/
|
|
67
|
-
|
|
67
|
+
signOut(): Promise<void>;
|
|
68
68
|
/**
|
|
69
69
|
* Validate the current token by checking with the platform API.
|
|
70
70
|
* Returns true if the token is valid, false otherwise.
|
|
71
71
|
*/
|
|
72
|
-
|
|
72
|
+
validateToken(): Promise<boolean>;
|
|
73
73
|
/**
|
|
74
74
|
* Wait for authentication to complete. Resolves when authenticated,
|
|
75
75
|
* rejects if authentication fails or times out.
|
|
76
76
|
*/
|
|
77
|
-
|
|
77
|
+
waitForAuth(): Promise<void>;
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
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;;;;;;;
|
|
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,7 +2,10 @@ 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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,cAAc,mBAAmB;AACjC,cAAc,WAAW,yBAAyB;AAClD,cAAc,2BAA2B
|
|
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
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@palantir/pack.auth",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
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.
|
|
32
|
+
"@palantir/pack.core": "0.2.0"
|
|
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.
|
|
42
|
+
"@palantir/pack.monorepo.tsconfig": "~0.4.3"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
package/src/types/AuthModule.ts
CHANGED
|
@@ -27,7 +27,6 @@ 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.
|
|
@@ -36,18 +35,18 @@ export interface AuthModule {
|
|
|
36
35
|
* @param allowUnverified - If true, will extract userId from token without validation.
|
|
37
36
|
* Defaults to false (requires validated token).
|
|
38
37
|
*/
|
|
39
|
-
|
|
38
|
+
getCurrentUser(allowUnverified?: boolean): UserRef | undefined;
|
|
40
39
|
|
|
41
40
|
/**
|
|
42
41
|
* Get an access token, automatically refreshing if needed.
|
|
43
42
|
* Throws if authentication fails or user is not signed in.
|
|
44
43
|
*/
|
|
45
|
-
|
|
44
|
+
getToken(): Promise<string>;
|
|
46
45
|
|
|
47
46
|
/**
|
|
48
47
|
* Get the current access token without refresh, returns undefined if expired or unavailable.
|
|
49
48
|
*/
|
|
50
|
-
|
|
49
|
+
getTokenOrUndefined(): string | undefined;
|
|
51
50
|
|
|
52
51
|
/**
|
|
53
52
|
* Get user data for a specific user ID.
|
|
@@ -55,12 +54,12 @@ export interface AuthModule {
|
|
|
55
54
|
* @param force - Force refresh of cached data
|
|
56
55
|
* @returns Promise resolving to user data
|
|
57
56
|
*/
|
|
58
|
-
|
|
57
|
+
getUserData(userId: string, force?: boolean): Promise<unknown>;
|
|
59
58
|
|
|
60
59
|
/**
|
|
61
60
|
* Check if the user is currently authenticated with a valid token.
|
|
62
61
|
*/
|
|
63
|
-
|
|
62
|
+
isAuthenticated(): boolean;
|
|
64
63
|
|
|
65
64
|
/**
|
|
66
65
|
* Subscribe to authentication state changes.
|
|
@@ -68,7 +67,7 @@ export interface AuthModule {
|
|
|
68
67
|
* @param callback Function called when auth state changes
|
|
69
68
|
* @returns Unsubscribe function
|
|
70
69
|
*/
|
|
71
|
-
|
|
70
|
+
onAuthStateChange(callback: AuthStateCallback): Unsubscribe;
|
|
72
71
|
|
|
73
72
|
/**
|
|
74
73
|
* Subscribe to token changes.
|
|
@@ -76,36 +75,36 @@ export interface AuthModule {
|
|
|
76
75
|
* @param callback Function called when token changes
|
|
77
76
|
* @returns Unsubscribe function
|
|
78
77
|
*/
|
|
79
|
-
|
|
78
|
+
onTokenChange(callback: TokenChangeCallback): Unsubscribe;
|
|
80
79
|
|
|
81
80
|
/**
|
|
82
81
|
* Manually refresh the access token using the refresh token.
|
|
83
82
|
* Only available for public OAuth clients.
|
|
84
83
|
*/
|
|
85
|
-
|
|
84
|
+
refresh?(): Promise<void>;
|
|
86
85
|
|
|
87
86
|
/**
|
|
88
87
|
* Initiate sign-in flow. For public clients, this redirects to OAuth.
|
|
89
88
|
* For confidential clients, this performs client credentials flow.
|
|
90
89
|
*/
|
|
91
|
-
|
|
90
|
+
signIn(): Promise<void>;
|
|
92
91
|
|
|
93
92
|
/**
|
|
94
93
|
* Sign out the current user and clear tokens.
|
|
95
94
|
*/
|
|
96
|
-
|
|
95
|
+
signOut(): Promise<void>;
|
|
97
96
|
|
|
98
97
|
/**
|
|
99
98
|
* Validate the current token by checking with the platform API.
|
|
100
99
|
* Returns true if the token is valid, false otherwise.
|
|
101
100
|
*/
|
|
102
|
-
|
|
101
|
+
validateToken(): Promise<boolean>;
|
|
103
102
|
|
|
104
103
|
/**
|
|
105
104
|
* Wait for authentication to complete. Resolves when authenticated,
|
|
106
105
|
* rejects if authentication fails or times out.
|
|
107
106
|
*/
|
|
108
|
-
|
|
107
|
+
waitForAuth(): Promise<void>;
|
|
109
108
|
}
|
|
110
109
|
|
|
111
110
|
/**
|
|
@@ -19,7 +19,10 @@ 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;
|
package/src/types/UserRef.ts
CHANGED
|
@@ -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
|
}
|