@mastra/auth-supabase 0.0.0-fix-generate-title-20250616171351 → 0.0.0-fix-9244-clickhouse-metadata-20251104213434

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +0,0 @@
1
- import * as child_process from 'child_process';
2
- import * as util from 'util';
3
-
4
- // ../../node_modules/.pnpm/@opentelemetry+resources@2.0.1_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/resources/build/esm/detectors/platform/node/machine-id/execAsync.js
5
- var execAsync = util.promisify(child_process.exec);
6
-
7
- export { execAsync };
@@ -1,21 +0,0 @@
1
- import { execAsync } from './chunk-N62AETLJ.js';
2
- import { diag } from './chunk-JLXWUSDO.js';
3
- import { promises } from 'fs';
4
-
5
- async function getMachineId() {
6
- try {
7
- const result = await promises.readFile("/etc/hostid", { encoding: "utf8" });
8
- return result.trim();
9
- } catch (e) {
10
- diag.debug(`error reading machine id: ${e}`);
11
- }
12
- try {
13
- const result = await execAsync("kenv -q smbios.system.uuid");
14
- return result.stdout.trim();
15
- } catch (e) {
16
- diag.debug(`error reading machine id: ${e}`);
17
- }
18
- return void 0;
19
- }
20
-
21
- export { getMachineId };
@@ -1,22 +0,0 @@
1
- import { execAsync } from './chunk-N62AETLJ.js';
2
- import { diag } from './chunk-JLXWUSDO.js';
3
-
4
- // ../../node_modules/.pnpm/@opentelemetry+resources@2.0.1_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/resources/build/esm/detectors/platform/node/machine-id/getMachineId-darwin.js
5
- async function getMachineId() {
6
- try {
7
- const result = await execAsync('ioreg -rd1 -c "IOPlatformExpertDevice"');
8
- const idLine = result.stdout.split("\n").find((line) => line.includes("IOPlatformUUID"));
9
- if (!idLine) {
10
- return void 0;
11
- }
12
- const parts = idLine.split('" = "');
13
- if (parts.length === 2) {
14
- return parts[1].slice(0, -1);
15
- }
16
- } catch (e) {
17
- diag.debug(`error reading machine id: ${e}`);
18
- }
19
- return void 0;
20
- }
21
-
22
- export { getMachineId };
@@ -1,17 +0,0 @@
1
- import { diag } from './chunk-JLXWUSDO.js';
2
- import { promises } from 'fs';
3
-
4
- async function getMachineId() {
5
- const paths = ["/etc/machine-id", "/var/lib/dbus/machine-id"];
6
- for (const path of paths) {
7
- try {
8
- const result = await promises.readFile(path, { encoding: "utf8" });
9
- return result.trim();
10
- } catch (e) {
11
- diag.debug(`error reading machine id: ${e}`);
12
- }
13
- }
14
- return void 0;
15
- }
16
-
17
- export { getMachineId };
@@ -1,9 +0,0 @@
1
- import { diag } from './chunk-JLXWUSDO.js';
2
-
3
- // ../../node_modules/.pnpm/@opentelemetry+resources@2.0.1_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/resources/build/esm/detectors/platform/node/machine-id/getMachineId-unsupported.js
4
- async function getMachineId() {
5
- diag.debug("could not read machine-id: unsupported platform");
6
- return void 0;
7
- }
8
-
9
- export { getMachineId };
@@ -1,23 +0,0 @@
1
- import { execAsync } from './chunk-N62AETLJ.js';
2
- import { diag } from './chunk-JLXWUSDO.js';
3
- import * as process from 'process';
4
-
5
- async function getMachineId() {
6
- const args = "QUERY HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography /v MachineGuid";
7
- let command = "%windir%\\System32\\REG.exe";
8
- if (process.arch === "ia32" && "PROCESSOR_ARCHITEW6432" in process.env) {
9
- command = "%windir%\\sysnative\\cmd.exe /c " + command;
10
- }
11
- try {
12
- const result = await execAsync(`${command} ${args}`);
13
- const parts = result.stdout.split("REG_SZ");
14
- if (parts.length === 2) {
15
- return parts[1].trim();
16
- }
17
- } catch (e) {
18
- diag.debug(`error reading machine id: ${e}`);
19
- }
20
- return void 0;
21
- }
22
-
23
- export { getMachineId };
package/dist/index.d.cts DELETED
@@ -1 +0,0 @@
1
- export { MastraAuthSupabase } from './_tsup-dts-rollup.cjs';
package/eslint.config.js DELETED
@@ -1,6 +0,0 @@
1
- import { createConfig } from '@internal/lint/eslint';
2
-
3
- const config = await createConfig();
4
-
5
- /** @type {import("eslint").Linter.Config[]} */
6
- export default [...config];
package/src/index.test.ts DELETED
@@ -1,152 +0,0 @@
1
- import { createClient } from '@supabase/supabase-js';
2
- import type { User } from '@supabase/supabase-js';
3
- import { describe, it, expect, vi, beforeEach } from 'vitest';
4
- import { MastraAuthSupabase } from './index';
5
-
6
- // Mock Supabase client
7
- vi.mock('@supabase/supabase-js', () => ({
8
- createClient: vi.fn(),
9
- }));
10
-
11
- describe('MastraAuthSupabase', () => {
12
- const mockSupabaseUrl = 'https://test.supabase.co';
13
- const mockSupabaseAnonKey = 'test-anon-key';
14
- const mockUser: User = {
15
- id: 'test-user-id',
16
- email: 'test@example.com',
17
- created_at: '',
18
- aud: '',
19
- role: '',
20
- app_metadata: {},
21
- user_metadata: {},
22
- };
23
-
24
- let authProvider: MastraAuthSupabase;
25
- let mockSupabaseClient: any;
26
-
27
- beforeEach(() => {
28
- // Reset environment variables
29
- vi.resetModules();
30
- process.env.SUPABASE_URL = mockSupabaseUrl;
31
- process.env.SUPABASE_ANON_KEY = mockSupabaseAnonKey;
32
-
33
- // Setup mock Supabase client
34
- mockSupabaseClient = {
35
- auth: {
36
- getUser: vi.fn(),
37
- },
38
- from: vi.fn().mockReturnThis(),
39
- select: vi.fn().mockReturnThis(),
40
- eq: vi.fn().mockReturnThis(),
41
- single: vi.fn(),
42
- };
43
-
44
- (createClient as any).mockReturnValue(mockSupabaseClient);
45
- authProvider = new MastraAuthSupabase();
46
- });
47
-
48
- describe('constructor', () => {
49
- it('should create instance with environment variables', () => {
50
- expect(createClient).toHaveBeenCalledWith(mockSupabaseUrl, mockSupabaseAnonKey);
51
- });
52
-
53
- it('should create instance with provided options', () => {
54
- const customUrl = 'https://custom.supabase.co';
55
- const customKey = 'custom-key';
56
- new MastraAuthSupabase({ url: customUrl, anonKey: customKey });
57
- expect(createClient).toHaveBeenCalledWith(customUrl, customKey);
58
- });
59
-
60
- it('should throw error when required credentials are missing', () => {
61
- delete process.env.SUPABASE_URL;
62
- delete process.env.SUPABASE_ANON_KEY;
63
-
64
- expect(() => new MastraAuthSupabase()).toThrow('Supabase URL and anon key are required');
65
- });
66
- });
67
-
68
- describe('authenticateToken', () => {
69
- it('should return user when token is valid', async () => {
70
- const mockToken = 'valid-token';
71
- mockSupabaseClient.auth.getUser.mockResolvedValue({
72
- data: { user: mockUser },
73
- error: null,
74
- });
75
-
76
- const result = await authProvider.authenticateToken(mockToken);
77
- expect(result).toEqual(mockUser);
78
- expect(mockSupabaseClient.auth.getUser).toHaveBeenCalledWith(mockToken);
79
- });
80
-
81
- it('should return null when token is invalid', async () => {
82
- const mockToken = 'invalid-token';
83
- mockSupabaseClient.auth.getUser.mockResolvedValue({
84
- data: { user: null },
85
- error: new Error('Invalid token'),
86
- });
87
-
88
- const result = await authProvider.authenticateToken(mockToken);
89
- expect(result).toBeNull();
90
- });
91
- });
92
-
93
- describe('authorizeUser', () => {
94
- it('should return true for admin users', async () => {
95
- mockSupabaseClient.single.mockResolvedValue({
96
- data: { isAdmin: true },
97
- error: null,
98
- });
99
-
100
- const result = await authProvider.authorizeUser(mockUser);
101
- expect(result).toBe(true);
102
- expect(mockSupabaseClient.from).toHaveBeenCalledWith('users');
103
- expect(mockSupabaseClient.select).toHaveBeenCalledWith('isAdmin');
104
- expect(mockSupabaseClient.eq).toHaveBeenCalledWith('id', mockUser.id);
105
- });
106
-
107
- it('should return false for non-admin users', async () => {
108
- mockSupabaseClient.single.mockResolvedValue({
109
- data: { isAdmin: false },
110
- error: null,
111
- });
112
-
113
- const result = await authProvider.authorizeUser(mockUser);
114
- expect(result).toBe(false);
115
- });
116
-
117
- it('should return false when user data cannot be retrieved', async () => {
118
- mockSupabaseClient.single.mockResolvedValue({
119
- data: null,
120
- error: new Error('Database error'),
121
- });
122
-
123
- const result = await authProvider.authorizeUser(mockUser);
124
- expect(result).toBe(false);
125
- });
126
- });
127
-
128
- it('can be overridden with custom authorization logic', async () => {
129
- // class CustomSupabase extends MastraAuthSupabase {
130
-
131
- // }
132
-
133
- const supabase = new MastraAuthSupabase({
134
- async authorizeUser(user: any): Promise<boolean> {
135
- // Custom authorization logic that checks for specific permissions
136
- return user?.permissions?.includes('admin') ?? false;
137
- },
138
- });
139
-
140
- // Test with admin user
141
- const adminUser = { sub: 'user123', permissions: ['admin'] } as unknown as User;
142
- expect(await supabase.authorizeUser(adminUser)).toBe(true);
143
-
144
- // Test with non-admin user
145
- const regularUser = { sub: 'user456', permissions: ['read'] } as unknown as User;
146
- expect(await supabase.authorizeUser(regularUser)).toBe(false);
147
-
148
- // Test with user without permissions
149
- const noPermissionsUser = { sub: 'user789' } as unknown as User;
150
- expect(await supabase.authorizeUser(noPermissionsUser)).toBe(false);
151
- });
152
- });
package/src/index.ts DELETED
@@ -1,55 +0,0 @@
1
- import type { MastraAuthProviderOptions } from '@mastra/core/server';
2
- import { MastraAuthProvider } from '@mastra/core/server';
3
-
4
- import { createClient } from '@supabase/supabase-js';
5
- import type { SupabaseClient, User } from '@supabase/supabase-js';
6
-
7
- interface MastraAuthSupabaseOptions extends MastraAuthProviderOptions<User> {
8
- url?: string;
9
- anonKey?: string;
10
- }
11
-
12
- export class MastraAuthSupabase extends MastraAuthProvider<User> {
13
- protected supabase: SupabaseClient;
14
-
15
- constructor(options?: MastraAuthSupabaseOptions) {
16
- super({ name: options?.name ?? 'supabase' });
17
-
18
- const supabaseUrl = options?.url ?? process.env.SUPABASE_URL;
19
- const supabaseAnonKey = options?.anonKey ?? process.env.SUPABASE_ANON_KEY;
20
-
21
- if (!supabaseUrl || !supabaseAnonKey) {
22
- throw new Error(
23
- 'Supabase URL and anon key are required, please provide them in the options or set the environment variables SUPABASE_URL and SUPABASE_ANON_KEY',
24
- );
25
- }
26
-
27
- this.supabase = createClient(supabaseUrl, supabaseAnonKey);
28
-
29
- this.registerOptions(options);
30
- }
31
-
32
- async authenticateToken(token: string): Promise<User | null> {
33
- const { data, error } = await this.supabase.auth.getUser(token);
34
-
35
- if (error) {
36
- return null;
37
- }
38
-
39
- return data.user;
40
- }
41
-
42
- async authorizeUser(user: User) {
43
- // Get user data from Supabase
44
- const { data, error } = await this.supabase.from('users').select('isAdmin').eq('id', user?.id).single();
45
-
46
- if (error) {
47
- return false;
48
- }
49
-
50
- const isAdmin = data?.isAdmin;
51
-
52
- // Check permissions based on role
53
- return isAdmin;
54
- }
55
- }
package/tsconfig.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.node.json",
3
- "include": ["src/**/*"],
4
- "exclude": ["node_modules", "**/*.test.ts"]
5
- }
package/vitest.config.ts DELETED
@@ -1,8 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
-
3
- export default defineConfig({
4
- test: {
5
- globals: true,
6
- include: ['src/**/*.test.ts'],
7
- },
8
- });