@palantir/pack.auth 0.0.1-beta.1 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-lint.log +2 -2
- 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 +12 -0
- package/build/browser/index.js +5 -5
- package/build/browser/index.js.map +1 -1
- package/build/cjs/index.cjs +5 -5
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +6 -3
- package/build/esm/index.js +5 -5
- package/build/esm/index.js.map +1 -1
- package/build/types/types/AuthModule.d.ts +4 -1
- package/build/types/types/AuthModule.d.ts.map +1 -1
- package/build/types/types/BaseAuthService.d.ts +1 -1
- package/build/types/types/BaseAuthService.d.ts.map +1 -1
- package/build/types/utils/AuthModuleImpl.d.ts +1 -1
- package/build/types/utils/AuthModuleImpl.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/types/AuthModule.ts +4 -1
- package/src/types/BaseAuthService.ts +1 -1
- package/src/utils/AuthModuleImpl.ts +5 -5
package/.turbo/turbo-lint.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
> @palantir/pack.auth@0.0.1
|
|
3
|
-
> eslint ./src
|
|
2
|
+
> @palantir/pack.auth@0.0.1 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
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @palantir/pack.auth
|
|
2
|
+
|
|
3
|
+
## 0.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8ed48e6: Initial release of auth packages
|
|
8
|
+
- 09f7acd: Add activity & presence custom event subscriptions
|
|
9
|
+
- Updated dependencies [8698373]
|
|
10
|
+
- Updated dependencies [77c07c4]
|
|
11
|
+
- Updated dependencies [3ebc927]
|
|
12
|
+
- @palantir/pack.core@0.1.0
|
package/build/browser/index.js
CHANGED
|
@@ -105,12 +105,12 @@ var AuthModuleImpl = class {
|
|
|
105
105
|
});
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
|
-
getCurrentUser() {
|
|
109
|
-
const userId = this.#authService.getCurrentUserId();
|
|
110
|
-
if (
|
|
111
|
-
return
|
|
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
|
|
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,E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AA;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,O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AA,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}"]}
|
package/build/cjs/index.cjs
CHANGED
|
@@ -107,12 +107,12 @@ var AuthModuleImpl = class {
|
|
|
107
107
|
});
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
|
-
getCurrentUser() {
|
|
111
|
-
const userId = this.#authService.getCurrentUserId();
|
|
112
|
-
if (
|
|
113
|
-
return
|
|
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
|
|
115
|
+
return void 0;
|
|
116
116
|
}
|
|
117
117
|
async validateToken() {
|
|
118
118
|
return this.#authService.validateToken();
|
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;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,O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, 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;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,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,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}"]}
|
package/build/cjs/index.d.cts
CHANGED
|
@@ -63,8 +63,11 @@ interface AuthModule {
|
|
|
63
63
|
/**
|
|
64
64
|
* Get the current user information.
|
|
65
65
|
* Returns undefined if not authenticated or user data not available.
|
|
66
|
+
*
|
|
67
|
+
* @param allowUnverified - If true, will extract userId from token without validation.
|
|
68
|
+
* Defaults to false (requires validated token).
|
|
66
69
|
*/
|
|
67
|
-
readonly getCurrentUser: () => UserRef | undefined;
|
|
70
|
+
readonly getCurrentUser: (allowUnverified?: boolean) => UserRef | undefined;
|
|
68
71
|
/**
|
|
69
72
|
* Get an access token, automatically refreshing if needed.
|
|
70
73
|
* Throws if authentication fails or user is not signed in.
|
|
@@ -138,7 +141,7 @@ declare function getAuthModule(app: PackAppInternal): AuthModule;
|
|
|
138
141
|
interface BaseAuthService {
|
|
139
142
|
dispose(): void;
|
|
140
143
|
getCurrentState(): AuthState;
|
|
141
|
-
getCurrentUserId(): string | undefined;
|
|
144
|
+
getCurrentUserId(allowUnverified?: boolean): string | undefined;
|
|
142
145
|
getToken(): Promise<string>;
|
|
143
146
|
getTokenOrUndefined(): string | undefined;
|
|
144
147
|
getUserData(userId: string, force?: boolean): Promise<unknown>;
|
|
@@ -180,7 +183,7 @@ declare class AuthModuleImpl implements AuthModule {
|
|
|
180
183
|
onAuthStateChange(callback: AuthStateCallback): Unsubscribe;
|
|
181
184
|
onTokenChange(callback: TokenChangeCallback): Unsubscribe;
|
|
182
185
|
waitForAuth(): Promise<void>;
|
|
183
|
-
getCurrentUser(): UserRef | undefined;
|
|
186
|
+
getCurrentUser(allowUnverified?: boolean): UserRef | undefined;
|
|
184
187
|
validateToken(): Promise<boolean>;
|
|
185
188
|
getUserData(userId: string, force?: boolean): Promise<unknown>;
|
|
186
189
|
dispose(): void;
|
package/build/esm/index.js
CHANGED
|
@@ -105,12 +105,12 @@ var AuthModuleImpl = class {
|
|
|
105
105
|
});
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
|
-
getCurrentUser() {
|
|
109
|
-
const userId = this.#authService.getCurrentUserId();
|
|
110
|
-
if (
|
|
111
|
-
return
|
|
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
|
|
113
|
+
return void 0;
|
|
114
114
|
}
|
|
115
115
|
async validateToken() {
|
|
116
116
|
return this.#authService.validateToken();
|
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/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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;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;AAAA,EAChB;AAAA,EACA,IAAI,KAAA,EAAO;AACT,IAAA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A,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}"]}
|
|
@@ -12,8 +12,11 @@ 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
|
+
readonly 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.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,cAAc,iBAAiB,mBAAmB;AAGlD,cAAc,yBAAyB;AACvC,cAAc,2BAA2B;AACzC,cAAc,eAAe;;;;;;;AAS7B,iBAAiB,WAAW
|
|
1
|
+
{"mappings":"AAgBA,cAAc,iBAAiB,mBAAmB;AAGlD,cAAc,yBAAyB;AACvC,cAAc,2BAA2B;AACzC,cAAc,eAAe;;;;;;;AAS7B,iBAAiB,WAAW;;;;;;;;UAQjB,iBAAiB,8BAA8B;;;;;UAM/C,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"}
|
|
@@ -7,7 +7,7 @@ import type { TokenChangeCallback } from "./TokenChange.js";
|
|
|
7
7
|
export interface BaseAuthService {
|
|
8
8
|
dispose(): void;
|
|
9
9
|
getCurrentState(): AuthState;
|
|
10
|
-
getCurrentUserId(): string | undefined;
|
|
10
|
+
getCurrentUserId(allowUnverified?: boolean): string | undefined;
|
|
11
11
|
getToken(): Promise<string>;
|
|
12
12
|
getTokenOrUndefined(): string | undefined;
|
|
13
13
|
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;
|
|
1
|
+
{"mappings":"AAgBA,cAAc,mBAAmB;AACjC,cAAc,WAAW,yBAAyB;AAClD,cAAc,2BAA2B;;;;AAKzC,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"}
|
|
@@ -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,
|
|
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
|
|
3
|
+
"version": "0.0.1",
|
|
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
|
|
32
|
+
"@palantir/pack.core": "0.1.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.0
|
|
42
|
+
"@palantir/pack.monorepo.tsconfig": "~0.4.0"
|
|
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
|
|
58
|
-
"lint:fix": "eslint ./src --fix
|
|
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",
|
package/src/types/AuthModule.ts
CHANGED
|
@@ -32,8 +32,11 @@ export interface AuthModule {
|
|
|
32
32
|
/**
|
|
33
33
|
* Get the current user information.
|
|
34
34
|
* Returns undefined if not authenticated or user data not available.
|
|
35
|
+
*
|
|
36
|
+
* @param allowUnverified - If true, will extract userId from token without validation.
|
|
37
|
+
* Defaults to false (requires validated token).
|
|
35
38
|
*/
|
|
36
|
-
readonly getCurrentUser: () => UserRef | undefined;
|
|
39
|
+
readonly getCurrentUser: (allowUnverified?: boolean) => UserRef | undefined;
|
|
37
40
|
|
|
38
41
|
/**
|
|
39
42
|
* Get an access token, automatically refreshing if needed.
|
|
@@ -24,7 +24,7 @@ import type { TokenChangeCallback } from "./TokenChange.js";
|
|
|
24
24
|
export interface BaseAuthService {
|
|
25
25
|
dispose(): void;
|
|
26
26
|
getCurrentState(): AuthState;
|
|
27
|
-
getCurrentUserId(): string | undefined;
|
|
27
|
+
getCurrentUserId(allowUnverified?: boolean): string | undefined;
|
|
28
28
|
getToken(): Promise<string>;
|
|
29
29
|
getTokenOrUndefined(): string | undefined;
|
|
30
30
|
getUserData(userId: string, force?: boolean): Promise<unknown>;
|
|
@@ -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 (
|
|
107
|
-
return
|
|
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
|
|
109
|
+
return undefined;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
async validateToken(): Promise<boolean> {
|