@mastra/auth-workos 0.0.0-1.x-tester-20251106055847
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/CHANGELOG.md +135 -0
- package/LICENSE.md +15 -0
- package/README.md +74 -0
- package/dist/index.cjs +168 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +166 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# @mastra/auth-workos
|
|
2
|
+
|
|
3
|
+
## 0.0.0-1.x-tester-20251106055847
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- Bump minimum required Node.js version to 22.13.0 ([#9706](https://github.com/mastra-ai/mastra/pull/9706))
|
|
8
|
+
|
|
9
|
+
- Experimental auth -> auth ([#9660](https://github.com/mastra-ai/mastra/pull/9660))
|
|
10
|
+
|
|
11
|
+
- Mark as stable ([`83d5942`](https://github.com/mastra-ai/mastra/commit/83d5942669ce7bba4a6ca4fd4da697a10eb5ebdc))
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`dd1c38d`](https://github.com/mastra-ai/mastra/commit/dd1c38d1b75f1b695c27b40d8d9d6ed00d5e0f6f), [`83d5942`](https://github.com/mastra-ai/mastra/commit/83d5942669ce7bba4a6ca4fd4da697a10eb5ebdc)]:
|
|
16
|
+
- @mastra/auth@0.0.0-1.x-tester-20251106055847
|
|
17
|
+
|
|
18
|
+
## 0.10.7
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Update package.json and README ([#7886](https://github.com/mastra-ai/mastra/pull/7886))
|
|
23
|
+
|
|
24
|
+
- Updated dependencies []:
|
|
25
|
+
- @mastra/auth@0.1.3
|
|
26
|
+
|
|
27
|
+
## 0.10.7-alpha.0
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- Update package.json and README ([#7886](https://github.com/mastra-ai/mastra/pull/7886))
|
|
32
|
+
|
|
33
|
+
- Updated dependencies []:
|
|
34
|
+
- @mastra/auth@0.1.3
|
|
35
|
+
|
|
36
|
+
## 0.10.6
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- dependencies updates: ([#7568](https://github.com/mastra-ai/mastra/pull/7568))
|
|
41
|
+
- Updated dependency [`@workos-inc/node@^7.69.2` ↗︎](https://www.npmjs.com/package/@workos-inc/node/v/7.69.2) (from `^7.69.1`, in `dependencies`)
|
|
42
|
+
- Updated dependencies []:
|
|
43
|
+
- @mastra/auth@0.1.3
|
|
44
|
+
|
|
45
|
+
## 0.10.6-alpha.0
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- dependencies updates: ([#7568](https://github.com/mastra-ai/mastra/pull/7568))
|
|
50
|
+
- Updated dependency [`@workos-inc/node@^7.69.2` ↗︎](https://www.npmjs.com/package/@workos-inc/node/v/7.69.2) (from `^7.69.1`, in `dependencies`)
|
|
51
|
+
- Updated dependencies []:
|
|
52
|
+
- @mastra/auth@0.1.3
|
|
53
|
+
|
|
54
|
+
## 0.10.5
|
|
55
|
+
|
|
56
|
+
### Patch Changes
|
|
57
|
+
|
|
58
|
+
- de3cbc6: Update the `package.json` file to include additional fields like `repository`, `homepage` or `files`.
|
|
59
|
+
- cb9aa8c: Cookie vuln
|
|
60
|
+
- Updated dependencies [de3cbc6]
|
|
61
|
+
- @mastra/auth@0.1.3
|
|
62
|
+
|
|
63
|
+
## 0.10.5-alpha.1
|
|
64
|
+
|
|
65
|
+
### Patch Changes
|
|
66
|
+
|
|
67
|
+
- [#7343](https://github.com/mastra-ai/mastra/pull/7343) [`de3cbc6`](https://github.com/mastra-ai/mastra/commit/de3cbc61079211431bd30487982ea3653517278e) Thanks [@LekoArts](https://github.com/LekoArts)! - Update the `package.json` file to include additional fields like `repository`, `homepage` or `files`.
|
|
68
|
+
|
|
69
|
+
- Updated dependencies [[`de3cbc6`](https://github.com/mastra-ai/mastra/commit/de3cbc61079211431bd30487982ea3653517278e)]:
|
|
70
|
+
- @mastra/auth@0.1.3-alpha.0
|
|
71
|
+
|
|
72
|
+
## 0.10.5-alpha.0
|
|
73
|
+
|
|
74
|
+
### Patch Changes
|
|
75
|
+
|
|
76
|
+
- [#7220](https://github.com/mastra-ai/mastra/pull/7220) [`cb9aa8c`](https://github.com/mastra-ai/mastra/commit/cb9aa8c8564bafa1b6e5321cca5a1bc4d3170590) Thanks [@abhiaiyer91](https://github.com/abhiaiyer91)! - Cookie vuln
|
|
77
|
+
|
|
78
|
+
- Updated dependencies []:
|
|
79
|
+
- @mastra/auth@0.1.2
|
|
80
|
+
|
|
81
|
+
## 0.10.4
|
|
82
|
+
|
|
83
|
+
### Patch Changes
|
|
84
|
+
|
|
85
|
+
- [`c6113ed`](https://github.com/mastra-ai/mastra/commit/c6113ed7f9df297e130d94436ceee310273d6430) Thanks [@wardpeet](https://github.com/wardpeet)! - Fix peerdpes for @mastra/core
|
|
86
|
+
|
|
87
|
+
- Updated dependencies [[`c6113ed`](https://github.com/mastra-ai/mastra/commit/c6113ed7f9df297e130d94436ceee310273d6430)]:
|
|
88
|
+
- @mastra/auth@0.1.2
|
|
89
|
+
|
|
90
|
+
## 0.10.3
|
|
91
|
+
|
|
92
|
+
### Patch Changes
|
|
93
|
+
|
|
94
|
+
- 4a406ec: fixes TypeScript declaration file imports to ensure proper ESM compatibility
|
|
95
|
+
- Updated dependencies [4a406ec]
|
|
96
|
+
- @mastra/auth@0.1.1
|
|
97
|
+
|
|
98
|
+
## 0.10.3-alpha.0
|
|
99
|
+
|
|
100
|
+
### Patch Changes
|
|
101
|
+
|
|
102
|
+
- 4a406ec: fixes TypeScript declaration file imports to ensure proper ESM compatibility
|
|
103
|
+
- Updated dependencies [4a406ec]
|
|
104
|
+
- @mastra/auth@0.1.1-alpha.0
|
|
105
|
+
|
|
106
|
+
## 0.10.2
|
|
107
|
+
|
|
108
|
+
### Patch Changes
|
|
109
|
+
|
|
110
|
+
- 9c159ee: dependencies updates:
|
|
111
|
+
- Updated dependency [`@workos-inc/node@^7.57.0` ↗︎](https://www.npmjs.com/package/@workos-inc/node/v/7.57.0) (from `^7.54.0`, in `dependencies`)
|
|
112
|
+
- @mastra/auth@0.1.0
|
|
113
|
+
|
|
114
|
+
## 0.10.2-alpha.0
|
|
115
|
+
|
|
116
|
+
### Patch Changes
|
|
117
|
+
|
|
118
|
+
- 9c159ee: dependencies updates:
|
|
119
|
+
- Updated dependency [`@workos-inc/node@^7.57.0` ↗︎](https://www.npmjs.com/package/@workos-inc/node/v/7.57.0) (from `^7.54.0`, in `dependencies`)
|
|
120
|
+
|
|
121
|
+
## 0.10.1
|
|
122
|
+
|
|
123
|
+
### Patch Changes
|
|
124
|
+
|
|
125
|
+
- 63f6b7d: dependencies updates:
|
|
126
|
+
- Updated dependency [`@workos-inc/node@^7.54.0` ↗︎](https://www.npmjs.com/package/@workos-inc/node/v/7.54.0) (from `^7.50.1`, in `dependencies`)
|
|
127
|
+
- @mastra/auth@0.1.0
|
|
128
|
+
|
|
129
|
+
## 0.10.1-alpha.0
|
|
130
|
+
|
|
131
|
+
### Patch Changes
|
|
132
|
+
|
|
133
|
+
- 63f6b7d: dependencies updates:
|
|
134
|
+
- Updated dependency [`@workos-inc/node@^7.54.0` ↗︎](https://www.npmjs.com/package/@workos-inc/node/v/7.54.0) (from `^7.50.1`, in `dependencies`)
|
|
135
|
+
- @mastra/auth@0.1.0
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# @mastra/auth-workos
|
|
2
|
+
|
|
3
|
+
A WorkOS authentication provider for Mastra, enabling seamless integration of WorkOS authentication and authorization in your applications.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔐 WorkOS authentication integration
|
|
8
|
+
- 👥 User management and organization membership support
|
|
9
|
+
- 🔑 JWT token verification using WorkOS JWKS
|
|
10
|
+
- 👮♂️ Role-based authorization with admin role support
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @mastra/auth-workos
|
|
16
|
+
# or
|
|
17
|
+
yarn add @mastra/auth-workos
|
|
18
|
+
# or
|
|
19
|
+
pnpm add @mastra/auth-workos
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { Mastra } from '@mastra/core/mastra';
|
|
26
|
+
import { MastraAuthWorkos } from '@mastra/auth-workos';
|
|
27
|
+
|
|
28
|
+
// Initialize with environment variables
|
|
29
|
+
const auth = new MastraAuthWorkos();
|
|
30
|
+
|
|
31
|
+
// Or initialize with explicit configuration
|
|
32
|
+
const auth = new MastraAuthWorkos({
|
|
33
|
+
apiKey: 'your_workos_api_key',
|
|
34
|
+
clientId: 'your_workos_client_id',
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Enable auth in Mastra
|
|
38
|
+
const mastra = new Mastra({
|
|
39
|
+
...
|
|
40
|
+
server: {
|
|
41
|
+
auth,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Configuration
|
|
47
|
+
|
|
48
|
+
The package requires the following configuration:
|
|
49
|
+
|
|
50
|
+
### Environment Variables
|
|
51
|
+
|
|
52
|
+
- `WORKOS_API_KEY`: Your WorkOS API key
|
|
53
|
+
- `WORKOS_CLIENT_ID`: Your WorkOS client ID
|
|
54
|
+
|
|
55
|
+
### Options
|
|
56
|
+
|
|
57
|
+
You can also provide these values directly when initializing the provider:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
interface MastraAuthWorkosOptions {
|
|
61
|
+
apiKey?: string;
|
|
62
|
+
clientId?: string;
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## API
|
|
67
|
+
|
|
68
|
+
### `authenticateToken(token: string): Promise<WorkosUser | null>`
|
|
69
|
+
|
|
70
|
+
Verifies a JWT token using WorkOS JWKS and returns the user information if valid.
|
|
71
|
+
|
|
72
|
+
### `authorizeUser(user: WorkosUser): Promise<boolean>`
|
|
73
|
+
|
|
74
|
+
Checks if a user has admin privileges by verifying their organization memberships and roles.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var auth = require('@mastra/auth');
|
|
4
|
+
var node = require('@workos-inc/node');
|
|
5
|
+
|
|
6
|
+
// src/index.ts
|
|
7
|
+
|
|
8
|
+
// ../../packages/core/dist/chunk-KJ2SW6VA.js
|
|
9
|
+
var RegisteredLogger = {
|
|
10
|
+
LLM: "LLM"};
|
|
11
|
+
var LogLevel = {
|
|
12
|
+
DEBUG: "debug",
|
|
13
|
+
INFO: "info",
|
|
14
|
+
WARN: "warn",
|
|
15
|
+
ERROR: "error"};
|
|
16
|
+
var MastraLogger = class {
|
|
17
|
+
name;
|
|
18
|
+
level;
|
|
19
|
+
transports;
|
|
20
|
+
constructor(options = {}) {
|
|
21
|
+
this.name = options.name || "Mastra";
|
|
22
|
+
this.level = options.level || LogLevel.ERROR;
|
|
23
|
+
this.transports = new Map(Object.entries(options.transports || {}));
|
|
24
|
+
}
|
|
25
|
+
getTransports() {
|
|
26
|
+
return this.transports;
|
|
27
|
+
}
|
|
28
|
+
trackException(_error) {
|
|
29
|
+
}
|
|
30
|
+
async listLogs(transportId, params) {
|
|
31
|
+
if (!transportId || !this.transports.has(transportId)) {
|
|
32
|
+
return { logs: [], total: 0, page: params?.page ?? 1, perPage: params?.perPage ?? 100, hasMore: false };
|
|
33
|
+
}
|
|
34
|
+
return this.transports.get(transportId).listLogs(params) ?? {
|
|
35
|
+
logs: [],
|
|
36
|
+
total: 0,
|
|
37
|
+
page: params?.page ?? 1,
|
|
38
|
+
perPage: params?.perPage ?? 100,
|
|
39
|
+
hasMore: false
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async listLogsByRunId({
|
|
43
|
+
transportId,
|
|
44
|
+
runId,
|
|
45
|
+
fromDate,
|
|
46
|
+
toDate,
|
|
47
|
+
logLevel,
|
|
48
|
+
filters,
|
|
49
|
+
page,
|
|
50
|
+
perPage
|
|
51
|
+
}) {
|
|
52
|
+
if (!transportId || !this.transports.has(transportId) || !runId) {
|
|
53
|
+
return { logs: [], total: 0, page: page ?? 1, perPage: perPage ?? 100, hasMore: false };
|
|
54
|
+
}
|
|
55
|
+
return this.transports.get(transportId).listLogsByRunId({ runId, fromDate, toDate, logLevel, filters, page, perPage }) ?? {
|
|
56
|
+
logs: [],
|
|
57
|
+
total: 0,
|
|
58
|
+
page: page ?? 1,
|
|
59
|
+
perPage: perPage ?? 100,
|
|
60
|
+
hasMore: false
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var ConsoleLogger = class extends MastraLogger {
|
|
65
|
+
constructor(options = {}) {
|
|
66
|
+
super(options);
|
|
67
|
+
}
|
|
68
|
+
debug(message, ...args) {
|
|
69
|
+
if (this.level === LogLevel.DEBUG) {
|
|
70
|
+
console.info(message, ...args);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
info(message, ...args) {
|
|
74
|
+
if (this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) {
|
|
75
|
+
console.info(message, ...args);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
warn(message, ...args) {
|
|
79
|
+
if (this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) {
|
|
80
|
+
console.info(message, ...args);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
error(message, ...args) {
|
|
84
|
+
if (this.level === LogLevel.ERROR || this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) {
|
|
85
|
+
console.error(message, ...args);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async listLogs(_transportId, _params) {
|
|
89
|
+
return { logs: [], total: 0, page: _params?.page ?? 1, perPage: _params?.perPage ?? 100, hasMore: false };
|
|
90
|
+
}
|
|
91
|
+
async listLogsByRunId(_args) {
|
|
92
|
+
return { logs: [], total: 0, page: _args.page ?? 1, perPage: _args.perPage ?? 100, hasMore: false };
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// ../../packages/core/dist/chunk-S6URFGCZ.js
|
|
97
|
+
var MastraBase = class {
|
|
98
|
+
component = RegisteredLogger.LLM;
|
|
99
|
+
logger;
|
|
100
|
+
name;
|
|
101
|
+
constructor({ component, name }) {
|
|
102
|
+
this.component = component || RegisteredLogger.LLM;
|
|
103
|
+
this.name = name;
|
|
104
|
+
this.logger = new ConsoleLogger({ name: `${this.component} - ${this.name}` });
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Set the logger for the agent
|
|
108
|
+
* @param logger
|
|
109
|
+
*/
|
|
110
|
+
__setLogger(logger) {
|
|
111
|
+
this.logger = logger;
|
|
112
|
+
if (this.component !== RegisteredLogger.LLM) {
|
|
113
|
+
this.logger.debug(`Logger updated [component=${this.component}] [name=${this.name}]`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// ../../packages/core/dist/server/index.js
|
|
119
|
+
var MastraAuthProvider = class extends MastraBase {
|
|
120
|
+
constructor(options) {
|
|
121
|
+
super({ component: "AUTH", name: options?.name });
|
|
122
|
+
if (options?.authorizeUser) {
|
|
123
|
+
this.authorizeUser = options.authorizeUser.bind(this);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
registerOptions(opts) {
|
|
127
|
+
if (opts?.authorizeUser) {
|
|
128
|
+
this.authorizeUser = opts.authorizeUser.bind(this);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
var MastraAuthWorkos = class extends MastraAuthProvider {
|
|
133
|
+
workos;
|
|
134
|
+
constructor(options) {
|
|
135
|
+
super({ name: options?.name ?? "workos" });
|
|
136
|
+
const apiKey = options?.apiKey ?? process.env.WORKOS_API_KEY;
|
|
137
|
+
const clientId = options?.clientId ?? process.env.WORKOS_CLIENT_ID;
|
|
138
|
+
if (!apiKey || !clientId) {
|
|
139
|
+
throw new Error(
|
|
140
|
+
"WorkOS API key and client ID are required, please provide them in the options or set the environment variables WORKOS_API_KEY and WORKOS_CLIENT_ID"
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
this.workos = new node.WorkOS(apiKey, {
|
|
144
|
+
clientId
|
|
145
|
+
});
|
|
146
|
+
this.registerOptions(options);
|
|
147
|
+
}
|
|
148
|
+
async authenticateToken(token) {
|
|
149
|
+
const jwksUri = this.workos.userManagement.getJwksUrl(process.env.WORKOS_CLIENT_ID);
|
|
150
|
+
const user = await auth.verifyJwks(token, jwksUri);
|
|
151
|
+
return user;
|
|
152
|
+
}
|
|
153
|
+
async authorizeUser(user) {
|
|
154
|
+
if (!user) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
const org = await this.workos.userManagement.listOrganizationMemberships({
|
|
158
|
+
userId: user.sub
|
|
159
|
+
});
|
|
160
|
+
const roles = org.data.map((org2) => org2.role);
|
|
161
|
+
const isAdmin = roles.some((role) => role.slug === "admin");
|
|
162
|
+
return isAdmin;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
exports.MastraAuthWorkos = MastraAuthWorkos;
|
|
167
|
+
//# sourceMappingURL=index.cjs.map
|
|
168
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../packages/core/src/logger/constants.ts","../../../packages/core/src/logger/logger.ts","../../../packages/core/src/logger/default-logger.ts","../../../packages/core/src/base.ts","../../../packages/core/src/server/auth.ts","../src/index.ts"],"names":["WorkOS","verifyJwks","org"],"mappings":";;;;;;;;AACO,IAAM,gBAAA,GAAmB;EAM9B,GAAA,EAAK,KAWP,CAAA;AAIO,IAAM,QAAA,GAAW;EACtB,KAAA,EAAO,OAAA;EACP,IAAA,EAAM,MAAA;EACN,IAAA,EAAM,MAAA;EACN,KAAA,EAAO,OAET,CAAA;ACOO,IAAe,eAAf,MAAqD;AAChD,EAAA,IAAA;AACA,EAAA,KAAA;AACA,EAAA,UAAA;EAEV,WAAA,CACE,OAAA,GAII,EAAA,EACJ;AACA,IAAA,IAAA,CAAK,IAAA,GAAO,QAAQ,IAAA,IAAQ,QAAA;AAC5B,IAAA,IAAA,CAAK,KAAA,GAAQ,OAAA,CAAQ,KAAA,IAAS,QAAA,CAAS,KAAA;AACvC,IAAA,IAAA,CAAK,UAAA,GAAa,IAAI,GAAA,CAAI,MAAA,CAAO,QAAQ,OAAA,CAAQ,UAAA,IAAc,EAAE,CAAC,CAAA;AACpE,EAAA;EAOA,aAAA,GAAgB;AACd,IAAA,OAAO,IAAA,CAAK,UAAA;AACd,EAAA;AAEA,EAAA,cAAA,CAAe,MAAA,EAAqB;AAAC,EAAA;EAErC,MAAM,QAAA,CACJ,a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IAAA,IAAA,CAAK,gBAAgB,OAAO,CAAA;AAAA,EAC9B;AAAA,EAEA,MAAM,kBAAkB,KAAA,EAA2C;AACjE,IAAA,MAAM,UAAU,IAAA,CAAK,MAAA,CAAO,eAAe,UAAA,CAAW,OAAA,CAAQ,IAAI,gBAAiB,CAAA;AACnF,IAAA,MAAM,IAAA,GAAO,MAAMC,eAAA,CAAW,KAAA,EAAO,OAAO,CAAA;AAC5C,IAAA,OAAO,IAAA;AAAA,EACT;AAAA,EAEA,MAAM,cAAc,IAAA,EAAkB;AACpC,IAAA,IAAI,CAAC,IAAA,EAAM;AACT,MAAA,OAAO,KAAA;AAAA,IACT;AAEA,IAAA,MAAM,GAAA,GAAM,MAAM,IAAA,CAAK,MAAA,CAAO,eAAe,2BAAA,CAA4B;AAAA,MACvE,QAAQ,IAAA,CAAK;AAAA,KACd,CAAA;AAED,IAAA,MAAM,QAAQ,GAAA,CAAI,IAAA,CAAK,IAAI,CAAAC,IAAAA,KAAOA,KAAI,IAAI,CAAA;AAE1C,IAAA,MAAM,UAAU,KAAA,CAAM,IAAA,CAAK,CAAA,IAAA,KAAQ,IAAA,CAAK,SAAS,OAAO,CAAA;AAExD,IAAA,OAAO,OAAA;AAAA,EACT;AACF","file":"index.cjs","sourcesContent":["// Constants and Types (keeping from original implementation)\nexport const RegisteredLogger = {\n AGENT: 'AGENT',\n OBSERVABILITY: 'OBSERVABILITY',\n AUTH: 'AUTH',\n NETWORK: 'NETWORK',\n WORKFLOW: 'WORKFLOW',\n LLM: 'LLM',\n TTS: 'TTS',\n VOICE: 'VOICE',\n VECTOR: 'VECTOR',\n BUNDLER: 'BUNDLER',\n DEPLOYER: 'DEPLOYER',\n MEMORY: 'MEMORY',\n STORAGE: 'STORAGE',\n EMBEDDINGS: 'EMBEDDINGS',\n MCP_SERVER: 'MCP_SERVER',\n SERVER_CACHE: 'SERVER_CACHE',\n} as const;\n\nexport type RegisteredLogger = (typeof RegisteredLogger)[keyof typeof RegisteredLogger];\n\nexport const LogLevel = {\n DEBUG: 'debug',\n INFO: 'info',\n WARN: 'warn',\n ERROR: 'error',\n NONE: 'silent',\n} as const;\n\nexport type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];\n","import type { MastraError } from '../error';\nimport { LogLevel } from './constants';\nimport type { BaseLogMessage, LoggerTransport } from './transport';\n\nexport interface IMastraLogger {\n debug(message: string, ...args: any[]): void;\n info(message: string, ...args: any[]): void;\n warn(message: string, ...args: any[]): void;\n error(message: string, ...args: any[]): void;\n trackException(error: MastraError): void;\n\n getTransports(): Map<string, LoggerTransport>;\n listLogs(\n _transportId: string,\n _params?: {\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n page?: number;\n perPage?: number;\n },\n ): Promise<{ logs: BaseLogMessage[]; total: number; page: number; perPage: number; hasMore: boolean }>;\n listLogsByRunId(_args: {\n transportId: string;\n runId: string;\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n page?: number;\n perPage?: number;\n }): Promise<{ logs: BaseLogMessage[]; total: number; page: number; perPage: number; hasMore: boolean }>;\n}\n\nexport abstract class MastraLogger implements IMastraLogger {\n protected name: string;\n protected level: LogLevel;\n protected transports: Map<string, LoggerTransport>;\n\n constructor(\n options: {\n name?: string;\n level?: LogLevel;\n transports?: Record<string, LoggerTransport>;\n } = {},\n ) {\n this.name = options.name || 'Mastra';\n this.level = options.level || LogLevel.ERROR;\n this.transports = new Map(Object.entries(options.transports || {}));\n }\n\n abstract debug(message: string, ...args: any[]): void;\n abstract info(message: string, ...args: any[]): void;\n abstract warn(message: string, ...args: any[]): void;\n abstract error(message: string, ...args: any[]): void;\n\n getTransports() {\n return this.transports;\n }\n\n trackException(_error: MastraError) {}\n\n async listLogs(\n transportId: string,\n params?: {\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n page?: number;\n perPage?: number;\n },\n ) {\n if (!transportId || !this.transports.has(transportId)) {\n return { logs: [], total: 0, page: params?.page ?? 1, perPage: params?.perPage ?? 100, hasMore: false };\n }\n\n return (\n this.transports.get(transportId)!.listLogs(params) ?? {\n logs: [],\n total: 0,\n page: params?.page ?? 1,\n perPage: params?.perPage ?? 100,\n hasMore: false,\n }\n );\n }\n\n async listLogsByRunId({\n transportId,\n runId,\n fromDate,\n toDate,\n logLevel,\n filters,\n page,\n perPage,\n }: {\n transportId: string;\n runId: string;\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n page?: number;\n perPage?: number;\n }) {\n if (!transportId || !this.transports.has(transportId) || !runId) {\n return { logs: [], total: 0, page: page ?? 1, perPage: perPage ?? 100, hasMore: false };\n }\n\n return (\n this.transports\n .get(transportId)!\n .listLogsByRunId({ runId, fromDate, toDate, logLevel, filters, page, perPage }) ?? {\n logs: [],\n total: 0,\n page: page ?? 1,\n perPage: perPage ?? 100,\n hasMore: false,\n }\n );\n }\n}\n","import { LogLevel } from './constants';\nimport { MastraLogger } from './logger';\nimport type { LoggerTransport } from './transport';\n\nexport const createLogger = (options: {\n name?: string;\n level?: LogLevel;\n transports?: Record<string, LoggerTransport>;\n}) => {\n const logger = new ConsoleLogger(options);\n\n logger.warn(`createLogger is deprecated. Please use \"new ConsoleLogger()\" from \"@mastra/core/logger\" instead.`);\n\n return logger;\n};\n\nexport class ConsoleLogger extends MastraLogger {\n constructor(\n options: {\n name?: string;\n level?: LogLevel;\n } = {},\n ) {\n super(options);\n }\n\n debug(message: string, ...args: any[]): void {\n if (this.level === LogLevel.DEBUG) {\n console.info(message, ...args);\n }\n }\n\n info(message: string, ...args: any[]): void {\n if (this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) {\n console.info(message, ...args);\n }\n }\n\n warn(message: string, ...args: any[]): void {\n if (this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) {\n console.info(message, ...args);\n }\n }\n\n error(message: string, ...args: any[]): void {\n if (\n this.level === LogLevel.ERROR ||\n this.level === LogLevel.WARN ||\n this.level === LogLevel.INFO ||\n this.level === LogLevel.DEBUG\n ) {\n console.error(message, ...args);\n }\n }\n\n async listLogs(\n _transportId: string,\n _params?: {\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n page?: number;\n perPage?: number;\n },\n ) {\n return { logs: [], total: 0, page: _params?.page ?? 1, perPage: _params?.perPage ?? 100, hasMore: false };\n }\n\n async listLogsByRunId(_args: {\n transportId: string;\n runId: string;\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n page?: number;\n perPage?: number;\n }) {\n return { logs: [], total: 0, page: _args.page ?? 1, perPage: _args.perPage ?? 100, hasMore: false };\n }\n}\n","import type { IMastraLogger } from './logger';\nimport { RegisteredLogger } from './logger/constants';\nimport { ConsoleLogger } from './logger/default-logger';\n\nexport class MastraBase {\n component: RegisteredLogger = RegisteredLogger.LLM;\n protected logger: IMastraLogger;\n name?: string;\n\n constructor({ component, name }: { component?: RegisteredLogger; name?: string }) {\n this.component = component || RegisteredLogger.LLM;\n this.name = name;\n this.logger = new ConsoleLogger({ name: `${this.component} - ${this.name}` });\n }\n\n /**\n * Set the logger for the agent\n * @param logger\n */\n __setLogger(logger: IMastraLogger) {\n this.logger = logger;\n\n if (this.component !== RegisteredLogger.LLM) {\n this.logger.debug(`Logger updated [component=${this.component}] [name=${this.name}]`);\n }\n }\n}\n\nexport * from './types';\n","import type { HonoRequest } from 'hono';\nimport { MastraBase } from '../base';\n\nexport interface MastraAuthProviderOptions<TUser = unknown> {\n name?: string;\n authorizeUser?: (user: TUser, request: HonoRequest) => Promise<boolean> | boolean;\n}\n\nexport abstract class MastraAuthProvider<TUser = unknown> extends MastraBase {\n constructor(options?: MastraAuthProviderOptions<TUser>) {\n super({ component: 'AUTH', name: options?.name });\n\n if (options?.authorizeUser) {\n this.authorizeUser = options.authorizeUser.bind(this);\n }\n }\n\n /**\n * Authenticate a token and return the payload\n * @param token - The token to authenticate\n * @param request - The request\n * @returns The payload\n */\n abstract authenticateToken(token: string, request: HonoRequest): Promise<TUser | null>;\n\n /**\n * Authorize a user for a path and method\n * @param user - The user to authorize\n * @param request - The request\n * @returns The authorization result\n */\n abstract authorizeUser(user: TUser, request: HonoRequest): Promise<boolean> | boolean;\n\n protected registerOptions(opts?: MastraAuthProviderOptions<TUser>) {\n if (opts?.authorizeUser) {\n this.authorizeUser = opts.authorizeUser.bind(this);\n }\n }\n}\n","import { verifyJwks } from '@mastra/auth';\nimport type { JwtPayload } from '@mastra/auth';\nimport type { MastraAuthProviderOptions } from '@mastra/core/server';\nimport { MastraAuthProvider } from '@mastra/core/server';\nimport { WorkOS } from '@workos-inc/node';\n\ntype WorkosUser = JwtPayload;\n\ninterface MastraAuthWorkosOptions extends MastraAuthProviderOptions<WorkosUser> {\n apiKey?: string;\n clientId?: string;\n}\n\nexport class MastraAuthWorkos extends MastraAuthProvider<WorkosUser> {\n protected workos: WorkOS;\n\n constructor(options?: MastraAuthWorkosOptions) {\n super({ name: options?.name ?? 'workos' });\n\n const apiKey = options?.apiKey ?? process.env.WORKOS_API_KEY;\n const clientId = options?.clientId ?? process.env.WORKOS_CLIENT_ID;\n\n if (!apiKey || !clientId) {\n throw new Error(\n 'WorkOS API key and client ID are required, please provide them in the options or set the environment variables WORKOS_API_KEY and WORKOS_CLIENT_ID',\n );\n }\n\n this.workos = new WorkOS(apiKey, {\n clientId,\n });\n\n this.registerOptions(options);\n }\n\n async authenticateToken(token: string): Promise<WorkosUser | null> {\n const jwksUri = this.workos.userManagement.getJwksUrl(process.env.WORKOS_CLIENT_ID!);\n const user = await verifyJwks(token, jwksUri);\n return user;\n }\n\n async authorizeUser(user: WorkosUser) {\n if (!user) {\n return false;\n }\n\n const org = await this.workos.userManagement.listOrganizationMemberships({\n userId: user.sub,\n });\n\n const roles = org.data.map(org => org.role);\n\n const isAdmin = roles.some(role => role.slug === 'admin');\n\n return isAdmin;\n }\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { JwtPayload } from '@mastra/auth';
|
|
2
|
+
import type { MastraAuthProviderOptions } from '@mastra/core/server';
|
|
3
|
+
import { MastraAuthProvider } from '@mastra/core/server';
|
|
4
|
+
import { WorkOS } from '@workos-inc/node';
|
|
5
|
+
type WorkosUser = JwtPayload;
|
|
6
|
+
interface MastraAuthWorkosOptions extends MastraAuthProviderOptions<WorkosUser> {
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
clientId?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class MastraAuthWorkos extends MastraAuthProvider<WorkosUser> {
|
|
11
|
+
protected workos: WorkOS;
|
|
12
|
+
constructor(options?: MastraAuthWorkosOptions);
|
|
13
|
+
authenticateToken(token: string): Promise<WorkosUser | null>;
|
|
14
|
+
authorizeUser(user: WorkosUser): Promise<boolean>;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,KAAK,UAAU,GAAG,UAAU,CAAC;AAE7B,UAAU,uBAAwB,SAAQ,yBAAyB,CAAC,UAAU,CAAC;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,gBAAiB,SAAQ,kBAAkB,CAAC,UAAU,CAAC;IAClE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEb,OAAO,CAAC,EAAE,uBAAuB;IAmBvC,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAM5D,aAAa,CAAC,IAAI,EAAE,UAAU;CAerC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { verifyJwks } from '@mastra/auth';
|
|
2
|
+
import { WorkOS } from '@workos-inc/node';
|
|
3
|
+
|
|
4
|
+
// src/index.ts
|
|
5
|
+
|
|
6
|
+
// ../../packages/core/dist/chunk-KJ2SW6VA.js
|
|
7
|
+
var RegisteredLogger = {
|
|
8
|
+
LLM: "LLM"};
|
|
9
|
+
var LogLevel = {
|
|
10
|
+
DEBUG: "debug",
|
|
11
|
+
INFO: "info",
|
|
12
|
+
WARN: "warn",
|
|
13
|
+
ERROR: "error"};
|
|
14
|
+
var MastraLogger = class {
|
|
15
|
+
name;
|
|
16
|
+
level;
|
|
17
|
+
transports;
|
|
18
|
+
constructor(options = {}) {
|
|
19
|
+
this.name = options.name || "Mastra";
|
|
20
|
+
this.level = options.level || LogLevel.ERROR;
|
|
21
|
+
this.transports = new Map(Object.entries(options.transports || {}));
|
|
22
|
+
}
|
|
23
|
+
getTransports() {
|
|
24
|
+
return this.transports;
|
|
25
|
+
}
|
|
26
|
+
trackException(_error) {
|
|
27
|
+
}
|
|
28
|
+
async listLogs(transportId, params) {
|
|
29
|
+
if (!transportId || !this.transports.has(transportId)) {
|
|
30
|
+
return { logs: [], total: 0, page: params?.page ?? 1, perPage: params?.perPage ?? 100, hasMore: false };
|
|
31
|
+
}
|
|
32
|
+
return this.transports.get(transportId).listLogs(params) ?? {
|
|
33
|
+
logs: [],
|
|
34
|
+
total: 0,
|
|
35
|
+
page: params?.page ?? 1,
|
|
36
|
+
perPage: params?.perPage ?? 100,
|
|
37
|
+
hasMore: false
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
async listLogsByRunId({
|
|
41
|
+
transportId,
|
|
42
|
+
runId,
|
|
43
|
+
fromDate,
|
|
44
|
+
toDate,
|
|
45
|
+
logLevel,
|
|
46
|
+
filters,
|
|
47
|
+
page,
|
|
48
|
+
perPage
|
|
49
|
+
}) {
|
|
50
|
+
if (!transportId || !this.transports.has(transportId) || !runId) {
|
|
51
|
+
return { logs: [], total: 0, page: page ?? 1, perPage: perPage ?? 100, hasMore: false };
|
|
52
|
+
}
|
|
53
|
+
return this.transports.get(transportId).listLogsByRunId({ runId, fromDate, toDate, logLevel, filters, page, perPage }) ?? {
|
|
54
|
+
logs: [],
|
|
55
|
+
total: 0,
|
|
56
|
+
page: page ?? 1,
|
|
57
|
+
perPage: perPage ?? 100,
|
|
58
|
+
hasMore: false
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var ConsoleLogger = class extends MastraLogger {
|
|
63
|
+
constructor(options = {}) {
|
|
64
|
+
super(options);
|
|
65
|
+
}
|
|
66
|
+
debug(message, ...args) {
|
|
67
|
+
if (this.level === LogLevel.DEBUG) {
|
|
68
|
+
console.info(message, ...args);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
info(message, ...args) {
|
|
72
|
+
if (this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) {
|
|
73
|
+
console.info(message, ...args);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
warn(message, ...args) {
|
|
77
|
+
if (this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) {
|
|
78
|
+
console.info(message, ...args);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
error(message, ...args) {
|
|
82
|
+
if (this.level === LogLevel.ERROR || this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) {
|
|
83
|
+
console.error(message, ...args);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async listLogs(_transportId, _params) {
|
|
87
|
+
return { logs: [], total: 0, page: _params?.page ?? 1, perPage: _params?.perPage ?? 100, hasMore: false };
|
|
88
|
+
}
|
|
89
|
+
async listLogsByRunId(_args) {
|
|
90
|
+
return { logs: [], total: 0, page: _args.page ?? 1, perPage: _args.perPage ?? 100, hasMore: false };
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// ../../packages/core/dist/chunk-S6URFGCZ.js
|
|
95
|
+
var MastraBase = class {
|
|
96
|
+
component = RegisteredLogger.LLM;
|
|
97
|
+
logger;
|
|
98
|
+
name;
|
|
99
|
+
constructor({ component, name }) {
|
|
100
|
+
this.component = component || RegisteredLogger.LLM;
|
|
101
|
+
this.name = name;
|
|
102
|
+
this.logger = new ConsoleLogger({ name: `${this.component} - ${this.name}` });
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Set the logger for the agent
|
|
106
|
+
* @param logger
|
|
107
|
+
*/
|
|
108
|
+
__setLogger(logger) {
|
|
109
|
+
this.logger = logger;
|
|
110
|
+
if (this.component !== RegisteredLogger.LLM) {
|
|
111
|
+
this.logger.debug(`Logger updated [component=${this.component}] [name=${this.name}]`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// ../../packages/core/dist/server/index.js
|
|
117
|
+
var MastraAuthProvider = class extends MastraBase {
|
|
118
|
+
constructor(options) {
|
|
119
|
+
super({ component: "AUTH", name: options?.name });
|
|
120
|
+
if (options?.authorizeUser) {
|
|
121
|
+
this.authorizeUser = options.authorizeUser.bind(this);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
registerOptions(opts) {
|
|
125
|
+
if (opts?.authorizeUser) {
|
|
126
|
+
this.authorizeUser = opts.authorizeUser.bind(this);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var MastraAuthWorkos = class extends MastraAuthProvider {
|
|
131
|
+
workos;
|
|
132
|
+
constructor(options) {
|
|
133
|
+
super({ name: options?.name ?? "workos" });
|
|
134
|
+
const apiKey = options?.apiKey ?? process.env.WORKOS_API_KEY;
|
|
135
|
+
const clientId = options?.clientId ?? process.env.WORKOS_CLIENT_ID;
|
|
136
|
+
if (!apiKey || !clientId) {
|
|
137
|
+
throw new Error(
|
|
138
|
+
"WorkOS API key and client ID are required, please provide them in the options or set the environment variables WORKOS_API_KEY and WORKOS_CLIENT_ID"
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
this.workos = new WorkOS(apiKey, {
|
|
142
|
+
clientId
|
|
143
|
+
});
|
|
144
|
+
this.registerOptions(options);
|
|
145
|
+
}
|
|
146
|
+
async authenticateToken(token) {
|
|
147
|
+
const jwksUri = this.workos.userManagement.getJwksUrl(process.env.WORKOS_CLIENT_ID);
|
|
148
|
+
const user = await verifyJwks(token, jwksUri);
|
|
149
|
+
return user;
|
|
150
|
+
}
|
|
151
|
+
async authorizeUser(user) {
|
|
152
|
+
if (!user) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
const org = await this.workos.userManagement.listOrganizationMemberships({
|
|
156
|
+
userId: user.sub
|
|
157
|
+
});
|
|
158
|
+
const roles = org.data.map((org2) => org2.role);
|
|
159
|
+
const isAdmin = roles.some((role) => role.slug === "admin");
|
|
160
|
+
return isAdmin;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export { MastraAuthWorkos };
|
|
165
|
+
//# sourceMappingURL=index.js.map
|
|
166
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../packages/core/src/logger/constants.ts","../../../packages/core/src/logger/logger.ts","../../../packages/core/src/logger/default-logger.ts","../../../packages/core/src/base.ts","../../../packages/core/src/server/auth.ts","../src/index.ts"],"names":["org"],"mappings":";;;;;;AACO,IAAM,gBAAA,GAAmB;EAM9B,GAAA,EAAK,KAWP,CAAA;AAIO,IAAM,QAAA,GAAW;EACtB,KAAA,EAAO,OAAA;EACP,IAAA,EAAM,MAAA;EACN,IAAA,EAAM,M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CAAK,CAAA,IAAA,KAAQ,IAAA,CAAK,SAAS,OAAO,CAAA;AAExD,IAAA,OAAO,OAAA;AAAA,EACT;AACF","file":"index.js","sourcesContent":["// Constants and Types (keeping from original implementation)\nexport const RegisteredLogger = {\n AGENT: 'AGENT',\n OBSERVABILITY: 'OBSERVABILITY',\n AUTH: 'AUTH',\n NETWORK: 'NETWORK',\n WORKFLOW: 'WORKFLOW',\n LLM: 'LLM',\n TTS: 'TTS',\n VOICE: 'VOICE',\n VECTOR: 'VECTOR',\n BUNDLER: 'BUNDLER',\n DEPLOYER: 'DEPLOYER',\n MEMORY: 'MEMORY',\n STORAGE: 'STORAGE',\n EMBEDDINGS: 'EMBEDDINGS',\n MCP_SERVER: 'MCP_SERVER',\n SERVER_CACHE: 'SERVER_CACHE',\n} as const;\n\nexport type RegisteredLogger = (typeof RegisteredLogger)[keyof typeof RegisteredLogger];\n\nexport const LogLevel = {\n DEBUG: 'debug',\n INFO: 'info',\n WARN: 'warn',\n ERROR: 'error',\n NONE: 'silent',\n} as const;\n\nexport type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];\n","import type { MastraError } from '../error';\nimport { LogLevel } from './constants';\nimport type { BaseLogMessage, LoggerTransport } from './transport';\n\nexport interface IMastraLogger {\n debug(message: string, ...args: any[]): void;\n info(message: string, ...args: any[]): void;\n warn(message: string, ...args: any[]): void;\n error(message: string, ...args: any[]): void;\n trackException(error: MastraError): void;\n\n getTransports(): Map<string, LoggerTransport>;\n listLogs(\n _transportId: string,\n _params?: {\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n page?: number;\n perPage?: number;\n },\n ): Promise<{ logs: BaseLogMessage[]; total: number; page: number; perPage: number; hasMore: boolean }>;\n listLogsByRunId(_args: {\n transportId: string;\n runId: string;\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n page?: number;\n perPage?: number;\n }): Promise<{ logs: BaseLogMessage[]; total: number; page: number; perPage: number; hasMore: boolean }>;\n}\n\nexport abstract class MastraLogger implements IMastraLogger {\n protected name: string;\n protected level: LogLevel;\n protected transports: Map<string, LoggerTransport>;\n\n constructor(\n options: {\n name?: string;\n level?: LogLevel;\n transports?: Record<string, LoggerTransport>;\n } = {},\n ) {\n this.name = options.name || 'Mastra';\n this.level = options.level || LogLevel.ERROR;\n this.transports = new Map(Object.entries(options.transports || {}));\n }\n\n abstract debug(message: string, ...args: any[]): void;\n abstract info(message: string, ...args: any[]): void;\n abstract warn(message: string, ...args: any[]): void;\n abstract error(message: string, ...args: any[]): void;\n\n getTransports() {\n return this.transports;\n }\n\n trackException(_error: MastraError) {}\n\n async listLogs(\n transportId: string,\n params?: {\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n page?: number;\n perPage?: number;\n },\n ) {\n if (!transportId || !this.transports.has(transportId)) {\n return { logs: [], total: 0, page: params?.page ?? 1, perPage: params?.perPage ?? 100, hasMore: false };\n }\n\n return (\n this.transports.get(transportId)!.listLogs(params) ?? {\n logs: [],\n total: 0,\n page: params?.page ?? 1,\n perPage: params?.perPage ?? 100,\n hasMore: false,\n }\n );\n }\n\n async listLogsByRunId({\n transportId,\n runId,\n fromDate,\n toDate,\n logLevel,\n filters,\n page,\n perPage,\n }: {\n transportId: string;\n runId: string;\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n page?: number;\n perPage?: number;\n }) {\n if (!transportId || !this.transports.has(transportId) || !runId) {\n return { logs: [], total: 0, page: page ?? 1, perPage: perPage ?? 100, hasMore: false };\n }\n\n return (\n this.transports\n .get(transportId)!\n .listLogsByRunId({ runId, fromDate, toDate, logLevel, filters, page, perPage }) ?? {\n logs: [],\n total: 0,\n page: page ?? 1,\n perPage: perPage ?? 100,\n hasMore: false,\n }\n );\n }\n}\n","import { LogLevel } from './constants';\nimport { MastraLogger } from './logger';\nimport type { LoggerTransport } from './transport';\n\nexport const createLogger = (options: {\n name?: string;\n level?: LogLevel;\n transports?: Record<string, LoggerTransport>;\n}) => {\n const logger = new ConsoleLogger(options);\n\n logger.warn(`createLogger is deprecated. Please use \"new ConsoleLogger()\" from \"@mastra/core/logger\" instead.`);\n\n return logger;\n};\n\nexport class ConsoleLogger extends MastraLogger {\n constructor(\n options: {\n name?: string;\n level?: LogLevel;\n } = {},\n ) {\n super(options);\n }\n\n debug(message: string, ...args: any[]): void {\n if (this.level === LogLevel.DEBUG) {\n console.info(message, ...args);\n }\n }\n\n info(message: string, ...args: any[]): void {\n if (this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) {\n console.info(message, ...args);\n }\n }\n\n warn(message: string, ...args: any[]): void {\n if (this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) {\n console.info(message, ...args);\n }\n }\n\n error(message: string, ...args: any[]): void {\n if (\n this.level === LogLevel.ERROR ||\n this.level === LogLevel.WARN ||\n this.level === LogLevel.INFO ||\n this.level === LogLevel.DEBUG\n ) {\n console.error(message, ...args);\n }\n }\n\n async listLogs(\n _transportId: string,\n _params?: {\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n page?: number;\n perPage?: number;\n },\n ) {\n return { logs: [], total: 0, page: _params?.page ?? 1, perPage: _params?.perPage ?? 100, hasMore: false };\n }\n\n async listLogsByRunId(_args: {\n transportId: string;\n runId: string;\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n page?: number;\n perPage?: number;\n }) {\n return { logs: [], total: 0, page: _args.page ?? 1, perPage: _args.perPage ?? 100, hasMore: false };\n }\n}\n","import type { IMastraLogger } from './logger';\nimport { RegisteredLogger } from './logger/constants';\nimport { ConsoleLogger } from './logger/default-logger';\n\nexport class MastraBase {\n component: RegisteredLogger = RegisteredLogger.LLM;\n protected logger: IMastraLogger;\n name?: string;\n\n constructor({ component, name }: { component?: RegisteredLogger; name?: string }) {\n this.component = component || RegisteredLogger.LLM;\n this.name = name;\n this.logger = new ConsoleLogger({ name: `${this.component} - ${this.name}` });\n }\n\n /**\n * Set the logger for the agent\n * @param logger\n */\n __setLogger(logger: IMastraLogger) {\n this.logger = logger;\n\n if (this.component !== RegisteredLogger.LLM) {\n this.logger.debug(`Logger updated [component=${this.component}] [name=${this.name}]`);\n }\n }\n}\n\nexport * from './types';\n","import type { HonoRequest } from 'hono';\nimport { MastraBase } from '../base';\n\nexport interface MastraAuthProviderOptions<TUser = unknown> {\n name?: string;\n authorizeUser?: (user: TUser, request: HonoRequest) => Promise<boolean> | boolean;\n}\n\nexport abstract class MastraAuthProvider<TUser = unknown> extends MastraBase {\n constructor(options?: MastraAuthProviderOptions<TUser>) {\n super({ component: 'AUTH', name: options?.name });\n\n if (options?.authorizeUser) {\n this.authorizeUser = options.authorizeUser.bind(this);\n }\n }\n\n /**\n * Authenticate a token and return the payload\n * @param token - The token to authenticate\n * @param request - The request\n * @returns The payload\n */\n abstract authenticateToken(token: string, request: HonoRequest): Promise<TUser | null>;\n\n /**\n * Authorize a user for a path and method\n * @param user - The user to authorize\n * @param request - The request\n * @returns The authorization result\n */\n abstract authorizeUser(user: TUser, request: HonoRequest): Promise<boolean> | boolean;\n\n protected registerOptions(opts?: MastraAuthProviderOptions<TUser>) {\n if (opts?.authorizeUser) {\n this.authorizeUser = opts.authorizeUser.bind(this);\n }\n }\n}\n","import { verifyJwks } from '@mastra/auth';\nimport type { JwtPayload } from '@mastra/auth';\nimport type { MastraAuthProviderOptions } from '@mastra/core/server';\nimport { MastraAuthProvider } from '@mastra/core/server';\nimport { WorkOS } from '@workos-inc/node';\n\ntype WorkosUser = JwtPayload;\n\ninterface MastraAuthWorkosOptions extends MastraAuthProviderOptions<WorkosUser> {\n apiKey?: string;\n clientId?: string;\n}\n\nexport class MastraAuthWorkos extends MastraAuthProvider<WorkosUser> {\n protected workos: WorkOS;\n\n constructor(options?: MastraAuthWorkosOptions) {\n super({ name: options?.name ?? 'workos' });\n\n const apiKey = options?.apiKey ?? process.env.WORKOS_API_KEY;\n const clientId = options?.clientId ?? process.env.WORKOS_CLIENT_ID;\n\n if (!apiKey || !clientId) {\n throw new Error(\n 'WorkOS API key and client ID are required, please provide them in the options or set the environment variables WORKOS_API_KEY and WORKOS_CLIENT_ID',\n );\n }\n\n this.workos = new WorkOS(apiKey, {\n clientId,\n });\n\n this.registerOptions(options);\n }\n\n async authenticateToken(token: string): Promise<WorkosUser | null> {\n const jwksUri = this.workos.userManagement.getJwksUrl(process.env.WORKOS_CLIENT_ID!);\n const user = await verifyJwks(token, jwksUri);\n return user;\n }\n\n async authorizeUser(user: WorkosUser) {\n if (!user) {\n return false;\n }\n\n const org = await this.workos.userManagement.listOrganizationMemberships({\n userId: user.sub,\n });\n\n const roles = org.data.map(org => org.role);\n\n const isAdmin = roles.some(role => role.slug === 'admin');\n\n return isAdmin;\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mastra/auth-workos",
|
|
3
|
+
"version": "0.0.0-1.x-tester-20251106055847",
|
|
4
|
+
"description": "Mastra WorkOS Auth integration",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@workos-inc/node": "^7.69.2",
|
|
24
|
+
"@mastra/auth": "0.0.0-1.x-tester-20251106055847"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^20.19.0",
|
|
28
|
+
"eslint": "^9.37.0",
|
|
29
|
+
"tsup": "^8.5.0",
|
|
30
|
+
"typescript": "^5.8.3",
|
|
31
|
+
"vitest": "^3.2.4",
|
|
32
|
+
"@internal/lint": "0.0.0-1.x-tester-20251106055847",
|
|
33
|
+
"@internal/types-builder": "0.0.0-1.x-tester-20251106055847",
|
|
34
|
+
"@mastra/core": "0.0.0-1.x-tester-20251106055847"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"CHANGELOG.md"
|
|
39
|
+
],
|
|
40
|
+
"homepage": "https://mastra.ai",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/mastra-ai/mastra.git",
|
|
44
|
+
"directory": "auth/workos"
|
|
45
|
+
},
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/mastra-ai/mastra/issues"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=22.13.0"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsup --silent --config tsup.config.ts",
|
|
54
|
+
"build:watch": "tsup --watch --silent --config tsup.config.ts",
|
|
55
|
+
"test": "vitest run",
|
|
56
|
+
"lint": "eslint ."
|
|
57
|
+
}
|
|
58
|
+
}
|