@palantir/pack.auth 0.0.1-beta.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 +42 -0
- package/.turbo/turbo-transpileBrowser.log +5 -0
- package/.turbo/turbo-transpileCjs.log +5 -0
- package/.turbo/turbo-transpileEsm.log +5 -0
- package/.turbo/turbo-transpileTypes.log +5 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/LICENSE.txt +13 -0
- package/README.md +105 -0
- package/build/browser/index.js +155 -0
- package/build/browser/index.js.map +1 -0
- package/build/cjs/index.cjs +163 -0
- package/build/cjs/index.cjs.map +1 -0
- package/build/cjs/index.d.cts +189 -0
- package/build/esm/index.js +155 -0
- package/build/esm/index.js.map +1 -0
- package/build/types/__tests__/AuthModuleImpl.test.d.ts +1 -0
- package/build/types/__tests__/AuthModuleImpl.test.d.ts.map +1 -0
- package/build/types/constants/AuthModuleKey.d.ts +4 -0
- package/build/types/constants/AuthModuleKey.d.ts.map +1 -0
- package/build/types/index.d.ts +11 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/types/AuthModule.d.ts +82 -0
- package/build/types/types/AuthModule.d.ts.map +1 -0
- package/build/types/types/AuthState.d.ts +14 -0
- package/build/types/types/AuthState.d.ts.map +1 -0
- package/build/types/types/BaseAuthService.d.ts +22 -0
- package/build/types/types/BaseAuthService.d.ts.map +1 -0
- package/build/types/types/TokenChange.d.ts +5 -0
- package/build/types/types/TokenChange.d.ts.map +1 -0
- package/build/types/types/UnverifiedTokenInfo.d.ts +13 -0
- package/build/types/types/UnverifiedTokenInfo.d.ts.map +1 -0
- package/build/types/types/UserRef.d.ts +21 -0
- package/build/types/types/UserRef.d.ts.map +1 -0
- package/build/types/utils/AuthModuleConfig.d.ts +16 -0
- package/build/types/utils/AuthModuleConfig.d.ts.map +1 -0
- package/build/types/utils/AuthModuleImpl.d.ts +25 -0
- package/build/types/utils/AuthModuleImpl.d.ts.map +1 -0
- package/package.json +67 -0
- package/src/__tests__/AuthModuleImpl.test.ts +249 -0
- package/src/constants/AuthModuleKey.ts +31 -0
- package/src/index.ts +27 -0
- package/src/types/AuthModule.ts +117 -0
- package/src/types/AuthState.ts +33 -0
- package/src/types/BaseAuthService.ts +39 -0
- package/src/types/TokenChange.ts +25 -0
- package/src/types/UnverifiedTokenInfo.ts +30 -0
- package/src/types/UserRef.ts +77 -0
- package/src/utils/AuthModuleConfig.ts +40 -0
- package/src/utils/AuthModuleImpl.ts +124 -0
- package/tsconfig.json +21 -0
- package/vitest.config.mjs +26 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
> @palantir/pack.auth@0.0.1-beta.1 lint /home/runner/work/pack/pack/packages/auth/core
|
|
3
|
+
> eslint ./src ; dprint check --config $(find-up dprint.json) --allow-no-files
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/home/runner/work/pack/pack/packages/auth/core/src/__tests__/AuthModuleImpl.test.ts
|
|
7
|
+
80:14 warning A method that is not declared with `this: void` may cause unintentional scoping of `this` when separated from its object.
|
|
8
|
+
Consider using an arrow function or explicitly `.bind()`ing the method to avoid calling the method with an unintended `this` value.
|
|
9
|
+
If a function does not access `this`, it can be annotated with `this: void` @typescript-eslint/unbound-method
|
|
10
|
+
127:14 warning A method that is not declared with `this: void` may cause unintentional scoping of `this` when separated from its object.
|
|
11
|
+
Consider using an arrow function or explicitly `.bind()`ing the method to avoid calling the method with an unintended `this` value.
|
|
12
|
+
If a function does not access `this`, it can be annotated with `this: void` @typescript-eslint/unbound-method
|
|
13
|
+
133:14 warning A method that is not declared with `this: void` may cause unintentional scoping of `this` when separated from its object.
|
|
14
|
+
Consider using an arrow function or explicitly `.bind()`ing the method to avoid calling the method with an unintended `this` value.
|
|
15
|
+
If a function does not access `this`, it can be annotated with `this: void` @typescript-eslint/unbound-method
|
|
16
|
+
139:14 warning A method that is not declared with `this: void` may cause unintentional scoping of `this` when separated from its object.
|
|
17
|
+
Consider using an arrow function or explicitly `.bind()`ing the method to avoid calling the method with an unintended `this` value.
|
|
18
|
+
If a function does not access `this`, it can be annotated with `this: void` @typescript-eslint/unbound-method
|
|
19
|
+
144:14 warning A method that is not declared with `this: void` may cause unintentional scoping of `this` when separated from its object.
|
|
20
|
+
Consider using an arrow function or explicitly `.bind()`ing the method to avoid calling the method with an unintended `this` value.
|
|
21
|
+
If a function does not access `this`, it can be annotated with `this: void` @typescript-eslint/unbound-method
|
|
22
|
+
149:14 warning A method that is not declared with `this: void` may cause unintentional scoping of `this` when separated from its object.
|
|
23
|
+
Consider using an arrow function or explicitly `.bind()`ing the method to avoid calling the method with an unintended `this` value.
|
|
24
|
+
If a function does not access `this`, it can be annotated with `this: void` @typescript-eslint/unbound-method
|
|
25
|
+
154:14 warning A method that is not declared with `this: void` may cause unintentional scoping of `this` when separated from its object.
|
|
26
|
+
Consider using an arrow function or explicitly `.bind()`ing the method to avoid calling the method with an unintended `this` value.
|
|
27
|
+
If a function does not access `this`, it can be annotated with `this: void` @typescript-eslint/unbound-method
|
|
28
|
+
160:14 warning A method that is not declared with `this: void` may cause unintentional scoping of `this` when separated from its object.
|
|
29
|
+
Consider using an arrow function or explicitly `.bind()`ing the method to avoid calling the method with an unintended `this` value.
|
|
30
|
+
If a function does not access `this`, it can be annotated with `this: void` @typescript-eslint/unbound-method
|
|
31
|
+
175:14 warning A method that is not declared with `this: void` may cause unintentional scoping of `this` when separated from its object.
|
|
32
|
+
Consider using an arrow function or explicitly `.bind()`ing the method to avoid calling the method with an unintended `this` value.
|
|
33
|
+
If a function does not access `this`, it can be annotated with `this: void` @typescript-eslint/unbound-method
|
|
34
|
+
198:14 warning A method that is not declared with `this: void` may cause unintentional scoping of `this` when separated from its object.
|
|
35
|
+
Consider using an arrow function or explicitly `.bind()`ing the method to avoid calling the method with an unintended `this` value.
|
|
36
|
+
If a function does not access `this`, it can be annotated with `this: void` @typescript-eslint/unbound-method
|
|
37
|
+
246:14 warning A method that is not declared with `this: void` may cause unintentional scoping of `this` when separated from its object.
|
|
38
|
+
Consider using an arrow function or explicitly `.bind()`ing the method to avoid calling the method with an unintended `this` value.
|
|
39
|
+
If a function does not access `this`, it can be annotated with `this: void` @typescript-eslint/unbound-method
|
|
40
|
+
|
|
41
|
+
✖ 11 problems (0 errors, 11 warnings)
|
|
42
|
+
|
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2025 Palantir Technologies, Inc.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# @palantir/pack.auth
|
|
2
|
+
|
|
3
|
+
Authentication types and interfaces for PACK applications.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides the core authentication types, interfaces, and utilities used across PACK applications. It defines the contract for authentication but does not include specific implementations - those are provided by companion packages like `@palantir/pack.auth.foundry`.
|
|
8
|
+
|
|
9
|
+
## Key Concepts
|
|
10
|
+
|
|
11
|
+
### Authentication vs Validation
|
|
12
|
+
|
|
13
|
+
PACK distinguishes between two important concepts:
|
|
14
|
+
|
|
15
|
+
- **Authentication** (`isAuthenticated()`): Whether the app has a token/credentials available
|
|
16
|
+
- **Validation** (`isValidated()`): Whether those credentials have been verified with the platform
|
|
17
|
+
|
|
18
|
+
This separation allows for:
|
|
19
|
+
|
|
20
|
+
- Fast startup without blocking network calls
|
|
21
|
+
- Explicit control over when validation occurs
|
|
22
|
+
- Support for pre-existing token scenarios
|
|
23
|
+
|
|
24
|
+
### Example Flow
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { createClient } from "@osdk/client";
|
|
28
|
+
import { createPublicOauthClient } from "@osdk/oauth";
|
|
29
|
+
|
|
30
|
+
const client = createClient(baseUrl, ontologyRid, auth);
|
|
31
|
+
const app = initPackApp(client, options);
|
|
32
|
+
|
|
33
|
+
// Authenticated immediately if token is available
|
|
34
|
+
console.log(app.auth.isAuthenticated()); // true (for static tokens)
|
|
35
|
+
console.log(app.auth.isValidated()); // false (not yet validated)
|
|
36
|
+
console.log(app.auth.getCurrentUser()); // undefined (no user data yet)
|
|
37
|
+
|
|
38
|
+
// Explicitly validate when needed
|
|
39
|
+
const isValid = await app.auth.validateToken();
|
|
40
|
+
if (isValid) {
|
|
41
|
+
console.log(app.auth.isValidated()); // true
|
|
42
|
+
console.log(app.auth.getCurrentUser()); // UserRef with platform data
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Core Types
|
|
47
|
+
|
|
48
|
+
### AuthModule
|
|
49
|
+
|
|
50
|
+
The main authentication interface providing:
|
|
51
|
+
|
|
52
|
+
- Token access (`getToken()`, `getTokenOrUndefined()`)
|
|
53
|
+
- Authentication state (`isAuthenticated()`, `isValidated()`)
|
|
54
|
+
- User information (`getCurrentUser()`)
|
|
55
|
+
- Auth lifecycle (`signIn()`, `signOut()`, `refresh()`)
|
|
56
|
+
- State changes (`onAuthStateChange()`)
|
|
57
|
+
- Token validation (`validateToken()`)
|
|
58
|
+
|
|
59
|
+
### AuthState
|
|
60
|
+
|
|
61
|
+
Represents the current authentication state:
|
|
62
|
+
|
|
63
|
+
- `Authenticating`: Currently in progress
|
|
64
|
+
- `Authenticated`: Has valid credentials
|
|
65
|
+
- `Unauthenticated`: No credentials or signed out
|
|
66
|
+
- `Error`: Authentication failed
|
|
67
|
+
|
|
68
|
+
### UserRef
|
|
69
|
+
|
|
70
|
+
Provides access to current user information with caching:
|
|
71
|
+
|
|
72
|
+
- `userId`: Platform user identifier
|
|
73
|
+
- `get()`: Fetch full user data from platform API
|
|
74
|
+
- Built-in 5-minute cache for performance
|
|
75
|
+
|
|
76
|
+
## Usage
|
|
77
|
+
|
|
78
|
+
This package is typically used indirectly through `initPackApp()` from `@palantir/pack.app`. The auth module is automatically available on the app instance:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { createClient } from "@osdk/client";
|
|
82
|
+
import { createPublicOauthClient } from "@osdk/oauth";
|
|
83
|
+
import { initPackApp } from "@palantir/pack.app";
|
|
84
|
+
|
|
85
|
+
// Create OSDK client with authentication
|
|
86
|
+
const auth = createPublicOauthClient(
|
|
87
|
+
"your-client-id",
|
|
88
|
+
"https://your-foundry-instance.com",
|
|
89
|
+
"http://localhost:3000/callback",
|
|
90
|
+
);
|
|
91
|
+
const client = createClient(baseUrl, ontologyRid, auth);
|
|
92
|
+
|
|
93
|
+
const app = initPackApp(client, {
|
|
94
|
+
app: { appId: "your-app" },
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Auth module is available as app.auth
|
|
98
|
+
await app.auth.signIn();
|
|
99
|
+
const user = app.auth.getCurrentUser();
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Implementation Packages
|
|
103
|
+
|
|
104
|
+
- **@palantir/pack.auth-foundry**: Foundry-specific auth implementations (OAuth, static tokens)
|
|
105
|
+
- Additional implementation packages can be created for other platforms
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { assertIsAppInternal } from '@palantir/pack.core';
|
|
2
|
+
|
|
3
|
+
// src/types/AuthModule.ts
|
|
4
|
+
|
|
5
|
+
// src/types/AuthState.ts
|
|
6
|
+
var AuthState = {
|
|
7
|
+
Authenticated: "authenticated",
|
|
8
|
+
Authenticating: "authenticating",
|
|
9
|
+
Error: "error",
|
|
10
|
+
Initializing: "initializing",
|
|
11
|
+
Unauthenticated: "unauthenticated"
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// src/types/UserRef.ts
|
|
15
|
+
var UserRefBrand = Symbol("UserRef");
|
|
16
|
+
var INVALID_USER_ID = "INVALID_USER_REF";
|
|
17
|
+
var INVALID_USER_REF = Object.freeze({
|
|
18
|
+
userId: INVALID_USER_ID,
|
|
19
|
+
[UserRefBrand]: UserRefBrand,
|
|
20
|
+
get: () => Promise.reject(new Error("Invalid user reference"))
|
|
21
|
+
});
|
|
22
|
+
function invalidUserRef() {
|
|
23
|
+
return INVALID_USER_REF;
|
|
24
|
+
}
|
|
25
|
+
function isValidUserRef(userRef) {
|
|
26
|
+
return userRef.userId !== INVALID_USER_ID && userRef.userId !== "";
|
|
27
|
+
}
|
|
28
|
+
var createUserRef = (app, userId) => {
|
|
29
|
+
return new UserRefImpl(app, userId);
|
|
30
|
+
};
|
|
31
|
+
var UserRefImpl = class {
|
|
32
|
+
userId;
|
|
33
|
+
#authModule;
|
|
34
|
+
constructor(app, userId) {
|
|
35
|
+
this.#authModule = getAuthModule(app);
|
|
36
|
+
this.userId = userId;
|
|
37
|
+
}
|
|
38
|
+
get(force) {
|
|
39
|
+
return this.#authModule.getUserData(this.userId, force);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/utils/AuthModuleImpl.ts
|
|
44
|
+
var AuthModuleImpl = class {
|
|
45
|
+
#authService;
|
|
46
|
+
app;
|
|
47
|
+
signInPromise;
|
|
48
|
+
constructor(app, authService) {
|
|
49
|
+
this.app = app;
|
|
50
|
+
this.#authService = authService;
|
|
51
|
+
}
|
|
52
|
+
// AuthModule interface implementation
|
|
53
|
+
isAuthenticated() {
|
|
54
|
+
return this.#authService.isAuthenticated();
|
|
55
|
+
}
|
|
56
|
+
async getToken() {
|
|
57
|
+
return this.#authService.getToken();
|
|
58
|
+
}
|
|
59
|
+
getTokenOrUndefined() {
|
|
60
|
+
return this.#authService.getTokenOrUndefined();
|
|
61
|
+
}
|
|
62
|
+
async signIn() {
|
|
63
|
+
if (this.signInPromise) {
|
|
64
|
+
return this.signInPromise;
|
|
65
|
+
}
|
|
66
|
+
this.signInPromise = (async () => {
|
|
67
|
+
try {
|
|
68
|
+
await this.#authService.signIn();
|
|
69
|
+
} finally {
|
|
70
|
+
this.signInPromise = void 0;
|
|
71
|
+
}
|
|
72
|
+
})();
|
|
73
|
+
return this.signInPromise;
|
|
74
|
+
}
|
|
75
|
+
async signOut() {
|
|
76
|
+
return this.#authService.signOut();
|
|
77
|
+
}
|
|
78
|
+
async refresh() {
|
|
79
|
+
if (!this.#authService.refresh) {
|
|
80
|
+
throw new Error("Refresh not supported for this auth client type");
|
|
81
|
+
}
|
|
82
|
+
return this.#authService.refresh();
|
|
83
|
+
}
|
|
84
|
+
onAuthStateChange(callback) {
|
|
85
|
+
return this.#authService.onAuthStateChange(callback);
|
|
86
|
+
}
|
|
87
|
+
onTokenChange(callback) {
|
|
88
|
+
return this.#authService.onTokenChange(callback);
|
|
89
|
+
}
|
|
90
|
+
async waitForAuth() {
|
|
91
|
+
if (this.isAuthenticated()) {
|
|
92
|
+
return Promise.resolve();
|
|
93
|
+
}
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
const unsubscribe = this.onAuthStateChange((event) => {
|
|
96
|
+
if (event.state === AuthState.Authenticated) {
|
|
97
|
+
unsubscribe();
|
|
98
|
+
resolve();
|
|
99
|
+
} else if (event.state === AuthState.Error) {
|
|
100
|
+
unsubscribe();
|
|
101
|
+
reject(new Error("Authentication failed", {
|
|
102
|
+
cause: event.error
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
getCurrentUser() {
|
|
109
|
+
const userId = this.#authService.getCurrentUserId();
|
|
110
|
+
if (!userId) {
|
|
111
|
+
return void 0;
|
|
112
|
+
}
|
|
113
|
+
return createUserRef(this.app, userId);
|
|
114
|
+
}
|
|
115
|
+
async validateToken() {
|
|
116
|
+
return this.#authService.validateToken();
|
|
117
|
+
}
|
|
118
|
+
async getUserData(userId, force) {
|
|
119
|
+
return this.#authService.getUserData(userId, force);
|
|
120
|
+
}
|
|
121
|
+
dispose() {
|
|
122
|
+
this.#authService.dispose();
|
|
123
|
+
this.signInPromise = void 0;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// src/constants/AuthModuleKey.ts
|
|
128
|
+
var AUTH_MODULE_KEY = {
|
|
129
|
+
appMemberName: "auth",
|
|
130
|
+
key: Symbol.for("pack.auth"),
|
|
131
|
+
initModule: (app, config) => {
|
|
132
|
+
if (!config) {
|
|
133
|
+
throw new Error("AuthModuleConfig is required to initialize AuthModule");
|
|
134
|
+
}
|
|
135
|
+
return new AuthModuleImpl(app, config.authService);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// src/types/AuthModule.ts
|
|
140
|
+
function getAuthModule(app) {
|
|
141
|
+
assertIsAppInternal(app);
|
|
142
|
+
return app.getModule(AUTH_MODULE_KEY);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/utils/AuthModuleConfig.ts
|
|
146
|
+
function createAuthModuleConfig(authService) {
|
|
147
|
+
const config = {
|
|
148
|
+
authService
|
|
149
|
+
};
|
|
150
|
+
return [AUTH_MODULE_KEY, config];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export { AuthModuleImpl, AuthState, createAuthModuleConfig, createUserRef, getAuthModule, invalidUserRef, isValidUserRef };
|
|
154
|
+
//# sourceMappingURL=index.js.map
|
|
155
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,aAA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pFO,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}"]}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var pack_core = require('@palantir/pack.core');
|
|
4
|
+
|
|
5
|
+
// src/types/AuthModule.ts
|
|
6
|
+
|
|
7
|
+
// src/types/AuthState.ts
|
|
8
|
+
var AuthState = {
|
|
9
|
+
Authenticated: "authenticated",
|
|
10
|
+
Authenticating: "authenticating",
|
|
11
|
+
Error: "error",
|
|
12
|
+
Initializing: "initializing",
|
|
13
|
+
Unauthenticated: "unauthenticated"
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// src/types/UserRef.ts
|
|
17
|
+
var UserRefBrand = Symbol("UserRef");
|
|
18
|
+
var INVALID_USER_ID = "INVALID_USER_REF";
|
|
19
|
+
var INVALID_USER_REF = Object.freeze({
|
|
20
|
+
userId: INVALID_USER_ID,
|
|
21
|
+
[UserRefBrand]: UserRefBrand,
|
|
22
|
+
get: () => Promise.reject(new Error("Invalid user reference"))
|
|
23
|
+
});
|
|
24
|
+
function invalidUserRef() {
|
|
25
|
+
return INVALID_USER_REF;
|
|
26
|
+
}
|
|
27
|
+
function isValidUserRef(userRef) {
|
|
28
|
+
return userRef.userId !== INVALID_USER_ID && userRef.userId !== "";
|
|
29
|
+
}
|
|
30
|
+
var createUserRef = (app, userId) => {
|
|
31
|
+
return new UserRefImpl(app, userId);
|
|
32
|
+
};
|
|
33
|
+
var UserRefImpl = class {
|
|
34
|
+
userId;
|
|
35
|
+
#authModule;
|
|
36
|
+
constructor(app, userId) {
|
|
37
|
+
this.#authModule = getAuthModule(app);
|
|
38
|
+
this.userId = userId;
|
|
39
|
+
}
|
|
40
|
+
get(force) {
|
|
41
|
+
return this.#authModule.getUserData(this.userId, force);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/utils/AuthModuleImpl.ts
|
|
46
|
+
var AuthModuleImpl = class {
|
|
47
|
+
#authService;
|
|
48
|
+
app;
|
|
49
|
+
signInPromise;
|
|
50
|
+
constructor(app, authService) {
|
|
51
|
+
this.app = app;
|
|
52
|
+
this.#authService = authService;
|
|
53
|
+
}
|
|
54
|
+
// AuthModule interface implementation
|
|
55
|
+
isAuthenticated() {
|
|
56
|
+
return this.#authService.isAuthenticated();
|
|
57
|
+
}
|
|
58
|
+
async getToken() {
|
|
59
|
+
return this.#authService.getToken();
|
|
60
|
+
}
|
|
61
|
+
getTokenOrUndefined() {
|
|
62
|
+
return this.#authService.getTokenOrUndefined();
|
|
63
|
+
}
|
|
64
|
+
async signIn() {
|
|
65
|
+
if (this.signInPromise) {
|
|
66
|
+
return this.signInPromise;
|
|
67
|
+
}
|
|
68
|
+
this.signInPromise = (async () => {
|
|
69
|
+
try {
|
|
70
|
+
await this.#authService.signIn();
|
|
71
|
+
} finally {
|
|
72
|
+
this.signInPromise = void 0;
|
|
73
|
+
}
|
|
74
|
+
})();
|
|
75
|
+
return this.signInPromise;
|
|
76
|
+
}
|
|
77
|
+
async signOut() {
|
|
78
|
+
return this.#authService.signOut();
|
|
79
|
+
}
|
|
80
|
+
async refresh() {
|
|
81
|
+
if (!this.#authService.refresh) {
|
|
82
|
+
throw new Error("Refresh not supported for this auth client type");
|
|
83
|
+
}
|
|
84
|
+
return this.#authService.refresh();
|
|
85
|
+
}
|
|
86
|
+
onAuthStateChange(callback) {
|
|
87
|
+
return this.#authService.onAuthStateChange(callback);
|
|
88
|
+
}
|
|
89
|
+
onTokenChange(callback) {
|
|
90
|
+
return this.#authService.onTokenChange(callback);
|
|
91
|
+
}
|
|
92
|
+
async waitForAuth() {
|
|
93
|
+
if (this.isAuthenticated()) {
|
|
94
|
+
return Promise.resolve();
|
|
95
|
+
}
|
|
96
|
+
return new Promise((resolve, reject) => {
|
|
97
|
+
const unsubscribe = this.onAuthStateChange((event) => {
|
|
98
|
+
if (event.state === AuthState.Authenticated) {
|
|
99
|
+
unsubscribe();
|
|
100
|
+
resolve();
|
|
101
|
+
} else if (event.state === AuthState.Error) {
|
|
102
|
+
unsubscribe();
|
|
103
|
+
reject(new Error("Authentication failed", {
|
|
104
|
+
cause: event.error
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
getCurrentUser() {
|
|
111
|
+
const userId = this.#authService.getCurrentUserId();
|
|
112
|
+
if (!userId) {
|
|
113
|
+
return void 0;
|
|
114
|
+
}
|
|
115
|
+
return createUserRef(this.app, userId);
|
|
116
|
+
}
|
|
117
|
+
async validateToken() {
|
|
118
|
+
return this.#authService.validateToken();
|
|
119
|
+
}
|
|
120
|
+
async getUserData(userId, force) {
|
|
121
|
+
return this.#authService.getUserData(userId, force);
|
|
122
|
+
}
|
|
123
|
+
dispose() {
|
|
124
|
+
this.#authService.dispose();
|
|
125
|
+
this.signInPromise = void 0;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// src/constants/AuthModuleKey.ts
|
|
130
|
+
var AUTH_MODULE_KEY = {
|
|
131
|
+
appMemberName: "auth",
|
|
132
|
+
key: Symbol.for("pack.auth"),
|
|
133
|
+
initModule: (app, config) => {
|
|
134
|
+
if (!config) {
|
|
135
|
+
throw new Error("AuthModuleConfig is required to initialize AuthModule");
|
|
136
|
+
}
|
|
137
|
+
return new AuthModuleImpl(app, config.authService);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// src/types/AuthModule.ts
|
|
142
|
+
function getAuthModule(app) {
|
|
143
|
+
pack_core.assertIsAppInternal(app);
|
|
144
|
+
return app.getModule(AUTH_MODULE_KEY);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/utils/AuthModuleConfig.ts
|
|
148
|
+
function createAuthModuleConfig(authService) {
|
|
149
|
+
const config = {
|
|
150
|
+
authService
|
|
151
|
+
};
|
|
152
|
+
return [AUTH_MODULE_KEY, config];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
exports.AuthModuleImpl = AuthModuleImpl;
|
|
156
|
+
exports.AuthState = AuthState;
|
|
157
|
+
exports.createAuthModuleConfig = createAuthModuleConfig;
|
|
158
|
+
exports.createUserRef = createUserRef;
|
|
159
|
+
exports.getAuthModule = getAuthModule;
|
|
160
|
+
exports.invalidUserRef = invalidUserRef;
|
|
161
|
+
exports.isValidUserRef = isValidUserRef;
|
|
162
|
+
//# sourceMappingURL=index.cjs.map
|
|
163
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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,OAAO,IAAI,WAAA,CAAY,GAAA,EAAK,MAAM,CAAA;AACpC;AACA,IAAM,cAAN,MAAkB;AAAA,EACh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;AACX,MAAA,OAAO,MAAA;AAAA,IACT;AACA,IAAA,OAAO,aAAA,CAAc,IAAA,CAAK,GAAA,EAAK,MAAM,CAAA;AAAA,EACvC;AAAA,EACA,MAAM,aAAA,GAAgB;AACpB,IAAA,OAAO,IAAA,CAAK,aAAa,aAAA,EAAc;AAAA,EACzC;AAAA,EACA,MAAM,WAAA,CAAY,MAAA,EAAQ,KAAA,EAAO;AAC/B,IAAA,OAAO,IAAA,CAAK,YAAA,CAAa,WAAA,CAAY,MAAA,EAAQ,KAAK,CAAA;AAAA,EACpD;AAAA,EACA,OAAA,GAAU;AACR,IAAA,IAAA,CAAK,aAAa,OAAA,EAAQ;AAC1B,IAAA,IAAA,CAAK,aAAA,GAAgB,MAAA;AAAA,EACvB;AACF;;;ACpFO,IAAM,eAAA,GAAkB;AAAA,EAC7B,aAAA,EAAe,MAAA;AAAA,EACf,GAAA,EAAK,MAAA,CAAO,GAAA,CAAI,WAAW,CAAA;AAAA,EAC3B,UAAA,EAAY,CAAC,GAAA,EAAK,MAAA,KAAW;AAC3B,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,MAAM,IAAI,MAAM,uDAAuD,CAAA;AAAA,IACzE;AACA,IAAA,OAAO,IAAI,cAAA,CAAe,GAAA,EAAK,MAAA,CAAO,WAAW,CAAA;AAAA,EACnD;AACF,CAAA;;;ACOO,SAAS,cAAc,GAAA,EAAK;AACjC,EAAAA,6BAAA,CAAoB,GAAG,CAAA;AACvB,EAAA,OAAO,GAAA,CAAI,UAAU,eAAe,CAAA;AACtC;;;ACRO,SAAS,uBAAuB,WAAA,EAAa;AAClD,EAAA,MAAM,MAAA,GAAS;AAAA,IACb;AAAA,GACF;AACA,EAAA,OAAO,CAAC,iBAAiB,MAAM,CAAA;AACjC","file":"index.cjs","sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const AuthState = {\n Authenticated: \"authenticated\",\n Authenticating: \"authenticating\",\n Error: \"error\",\n Initializing: \"initializing\",\n Unauthenticated: \"unauthenticated\"\n};","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getAuthModule } from \"./AuthModule.js\";\nconst UserRefBrand = Symbol(\"UserRef\");\n\n/**\n * Reference to a user from the platform API.\n * Provides access to user information with caching.\n */\n\nconst INVALID_USER_ID = \"INVALID_USER_REF\";\nconst INVALID_USER_REF = Object.freeze({\n userId: INVALID_USER_ID,\n [UserRefBrand]: UserRefBrand,\n get: () => Promise.reject(new Error(\"Invalid user reference\"))\n});\nexport function invalidUserRef() {\n return INVALID_USER_REF;\n}\nexport function isValidUserRef(userRef) {\n return userRef.userId !== INVALID_USER_ID && userRef.userId !== \"\";\n}\nexport const createUserRef = (app, userId) => {\n return new UserRefImpl(app, userId);\n};\nclass UserRefImpl {\n userId;\n #authModule;\n constructor(app, userId) {\n this.#authModule = getAuthModule(app);\n this.userId = userId;\n }\n get(force) {\n return this.#authModule.getUserData(this.userId, force);\n }\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AuthState } from \"../types/AuthState.js\";\nimport { createUserRef } from \"../types/UserRef.js\";\nexport class AuthModuleImpl {\n #authService;\n app;\n signInPromise;\n constructor(app, authService) {\n this.app = app;\n this.#authService = authService;\n }\n\n // AuthModule interface implementation\n isAuthenticated() {\n return this.#authService.isAuthenticated();\n }\n async getToken() {\n return this.#authService.getToken();\n }\n getTokenOrUndefined() {\n return this.#authService.getTokenOrUndefined();\n }\n async signIn() {\n if (this.signInPromise) {\n return this.signInPromise;\n }\n this.signInPromise = (async () => {\n try {\n await this.#authService.signIn();\n } finally {\n this.signInPromise = undefined;\n }\n })();\n return this.signInPromise;\n }\n async signOut() {\n return this.#authService.signOut();\n }\n async refresh() {\n if (!this.#authService.refresh) {\n throw new Error(\"Refresh not supported for this auth client type\");\n }\n return this.#authService.refresh();\n }\n onAuthStateChange(callback) {\n return this.#authService.onAuthStateChange(callback);\n }\n onTokenChange(callback) {\n return this.#authService.onTokenChange(callback);\n }\n async waitForAuth() {\n // If already authenticated, resolve immediately\n if (this.isAuthenticated()) {\n return Promise.resolve();\n }\n return new Promise((resolve, reject) => {\n const unsubscribe = this.onAuthStateChange(event => {\n if (event.state === AuthState.Authenticated) {\n unsubscribe();\n resolve();\n } else if (event.state === AuthState.Error) {\n unsubscribe();\n reject(new Error(\"Authentication failed\", {\n cause: event.error\n }));\n }\n });\n });\n }\n getCurrentUser() {\n const userId = this.#authService.getCurrentUserId();\n if (!userId) {\n return undefined;\n }\n return createUserRef(this.app, userId);\n }\n async validateToken() {\n return this.#authService.validateToken();\n }\n async getUserData(userId, force) {\n return this.#authService.getUserData(userId, force);\n }\n dispose() {\n this.#authService.dispose();\n this.signInPromise = undefined;\n }\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AuthModuleImpl } from \"../utils/AuthModuleImpl.js\";\nexport const AUTH_MODULE_KEY = {\n appMemberName: \"auth\",\n key: Symbol.for(\"pack.auth\"),\n initModule: (app, config) => {\n if (!config) {\n throw new Error(\"AuthModuleConfig is required to initialize AuthModule\");\n }\n return new AuthModuleImpl(app, config.authService);\n }\n};","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { assertIsAppInternal } from \"@palantir/pack.core\";\nimport { AUTH_MODULE_KEY } from \"../constants/AuthModuleKey.js\";\n\n/**\n * AuthModule provides unified authentication services for PACK applications.\n *\n * It wraps OSDK OAuth clients and provides a consistent interface for authentication\n * state management, token access, and auth lifecycle events.\n */\n// TODO: functions should be method style\n\n/**\n * Get the auth module from an PACK app instance.\n *\n * @param app - PACK app instance\n * @returns The auth module\n */\nexport function getAuthModule(app) {\n assertIsAppInternal(app);\n return app.getModule(AUTH_MODULE_KEY);\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AUTH_MODULE_KEY } from \"../constants/AuthModuleKey.js\";\n\n/**\n * Configuration for AuthModule initialization\n */\n\n/**\n * Creates an auth module configuration tuple.\n *\n * @param authService - The auth service to use\n * @returns Module configuration tuple for the auth module\n */\nexport function createAuthModuleConfig(authService) {\n const config = {\n authService\n };\n return [AUTH_MODULE_KEY, config];\n}"]}
|