@quatrain/auth-supabase 1.2.7 → 1.2.10
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,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -45,7 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
45
12
|
exports.SupabaseAuthAdapter = void 0;
|
|
46
13
|
const auth_1 = require("@quatrain/auth");
|
|
47
14
|
const supabase_js_1 = require("@supabase/supabase-js");
|
|
48
|
-
const nativeFetch = __importStar(require("node-fetch-native"));
|
|
49
15
|
// Create a single supabase client for interacting with your database
|
|
50
16
|
/**
|
|
51
17
|
* Authentication adapter implementing the Supabase SDK ecosystem.
|
|
@@ -128,7 +94,7 @@ class SupabaseAuthAdapter extends auth_1.AbstractAuthAdapter {
|
|
|
128
94
|
refreshToken(refreshToken) {
|
|
129
95
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
96
|
const url = `${this._params.config.supabaseUrl}/auth/v1/token?grant_type=refresh_token`;
|
|
131
|
-
const response = yield
|
|
97
|
+
const response = yield fetch(url, {
|
|
132
98
|
method: 'POST',
|
|
133
99
|
headers: {
|
|
134
100
|
apikey: this._params.config.supabaseKey,
|
|
@@ -1,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -45,10 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
45
12
|
const SupabaseAuthAdapter_1 = require("./SupabaseAuthAdapter");
|
|
46
13
|
const auth_1 = require("@quatrain/auth");
|
|
47
14
|
const supabase_js_1 = require("@supabase/supabase-js");
|
|
48
|
-
const nativeFetch = __importStar(require("node-fetch-native"));
|
|
49
15
|
// Mock the dependencies
|
|
50
16
|
jest.mock('@supabase/supabase-js');
|
|
51
|
-
jest.mock('node-fetch-native');
|
|
52
17
|
describe('SupabaseAuthAdapter', () => {
|
|
53
18
|
let adapter;
|
|
54
19
|
let mockSupabaseClient;
|
|
@@ -57,6 +22,7 @@ describe('SupabaseAuthAdapter', () => {
|
|
|
57
22
|
beforeEach(() => {
|
|
58
23
|
// Clear all mocks before each test
|
|
59
24
|
jest.clearAllMocks();
|
|
25
|
+
global.fetch = jest.fn();
|
|
60
26
|
// Create mock Supabase client structure
|
|
61
27
|
mockAuthAdmin = {
|
|
62
28
|
createUser: jest.fn(),
|
|
@@ -208,9 +174,9 @@ describe('SupabaseAuthAdapter', () => {
|
|
|
208
174
|
const mockFetchResponse = {
|
|
209
175
|
json: jest.fn().mockResolvedValue(mockResponse),
|
|
210
176
|
};
|
|
211
|
-
|
|
177
|
+
global.fetch.mockResolvedValue(mockFetchResponse);
|
|
212
178
|
const result = yield adapter.refreshToken('old-refresh-token');
|
|
213
|
-
expect(
|
|
179
|
+
expect(global.fetch).toHaveBeenCalledWith('https://test.supabase.co/auth/v1/token?grant_type=refresh_token', {
|
|
214
180
|
method: 'POST',
|
|
215
181
|
headers: {
|
|
216
182
|
apikey: 'test-key-123',
|
|
@@ -228,9 +194,9 @@ describe('SupabaseAuthAdapter', () => {
|
|
|
228
194
|
const mockFetchResponse = {
|
|
229
195
|
json: jest.fn().mockResolvedValue({}),
|
|
230
196
|
};
|
|
231
|
-
|
|
197
|
+
global.fetch.mockResolvedValue(mockFetchResponse);
|
|
232
198
|
yield adapter.refreshToken('refresh-token');
|
|
233
|
-
const callArgs =
|
|
199
|
+
const callArgs = global.fetch.mock.calls[0];
|
|
234
200
|
expect(callArgs[0]).toBe('https://test.supabase.co/auth/v1/token?grant_type=refresh_token');
|
|
235
201
|
}));
|
|
236
202
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quatrain/auth-supabase",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.10",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,11 +19,10 @@
|
|
|
19
19
|
},
|
|
20
20
|
"author": "Quatrain Développement SAS <developers@quatrain.com>",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@quatrain/api": "^1.1.
|
|
23
|
-
"@quatrain/auth": "^1.2.
|
|
24
|
-
"@quatrain/backend": "^1.2.
|
|
25
|
-
"@supabase/supabase-js": "^2.
|
|
26
|
-
"node-fetch-native": "^1.6.4"
|
|
22
|
+
"@quatrain/api": "^1.1.7",
|
|
23
|
+
"@quatrain/auth": "^1.2.11",
|
|
24
|
+
"@quatrain/backend": "^1.2.17",
|
|
25
|
+
"@supabase/supabase-js": "^2.108.2"
|
|
27
26
|
},
|
|
28
27
|
"devDependencies": {
|
|
29
28
|
"@tsconfig/recommended": "^1.0.1",
|
|
@@ -2,11 +2,9 @@ import { SupabaseAuthAdapter } from './SupabaseAuthAdapter'
|
|
|
2
2
|
import { User } from '@quatrain/backend'
|
|
3
3
|
import { AuthenticationError } from '@quatrain/auth'
|
|
4
4
|
import { createClient } from '@supabase/supabase-js'
|
|
5
|
-
import * as nativeFetch from 'node-fetch-native'
|
|
6
5
|
|
|
7
6
|
// Mock the dependencies
|
|
8
7
|
jest.mock('@supabase/supabase-js')
|
|
9
|
-
jest.mock('node-fetch-native')
|
|
10
8
|
|
|
11
9
|
describe('SupabaseAuthAdapter', () => {
|
|
12
10
|
let adapter: SupabaseAuthAdapter
|
|
@@ -17,6 +15,7 @@ describe('SupabaseAuthAdapter', () => {
|
|
|
17
15
|
beforeEach(() => {
|
|
18
16
|
// Clear all mocks before each test
|
|
19
17
|
jest.clearAllMocks()
|
|
18
|
+
global.fetch = jest.fn()
|
|
20
19
|
|
|
21
20
|
// Create mock Supabase client structure
|
|
22
21
|
mockAuthAdmin = {
|
|
@@ -225,11 +224,11 @@ describe('SupabaseAuthAdapter', () => {
|
|
|
225
224
|
json: jest.fn().mockResolvedValue(mockResponse),
|
|
226
225
|
}
|
|
227
226
|
|
|
228
|
-
;(
|
|
227
|
+
;(global.fetch as unknown as jest.Mock).mockResolvedValue(mockFetchResponse)
|
|
229
228
|
|
|
230
229
|
const result = await adapter.refreshToken('old-refresh-token')
|
|
231
230
|
|
|
232
|
-
expect(
|
|
231
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
233
232
|
'https://test.supabase.co/auth/v1/token?grant_type=refresh_token',
|
|
234
233
|
{
|
|
235
234
|
method: 'POST',
|
|
@@ -253,11 +252,11 @@ describe('SupabaseAuthAdapter', () => {
|
|
|
253
252
|
json: jest.fn().mockResolvedValue({}),
|
|
254
253
|
}
|
|
255
254
|
|
|
256
|
-
;(
|
|
255
|
+
;(global.fetch as unknown as jest.Mock).mockResolvedValue(mockFetchResponse)
|
|
257
256
|
|
|
258
257
|
await adapter.refreshToken('refresh-token')
|
|
259
258
|
|
|
260
|
-
const callArgs = (
|
|
259
|
+
const callArgs = (global.fetch as unknown as jest.Mock).mock.calls[0]
|
|
261
260
|
expect(callArgs[0]).toBe(
|
|
262
261
|
'https://test.supabase.co/auth/v1/token?grant_type=refresh_token'
|
|
263
262
|
)
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
} from '@quatrain/auth'
|
|
8
8
|
|
|
9
9
|
import { createClient } from '@supabase/supabase-js'
|
|
10
|
-
import * as nativeFetch from 'node-fetch-native'
|
|
11
10
|
|
|
12
11
|
// Create a single supabase client for interacting with your database
|
|
13
12
|
/**
|
|
@@ -104,7 +103,7 @@ export class SupabaseAuthAdapter extends AbstractAuthAdapter {
|
|
|
104
103
|
*/
|
|
105
104
|
async refreshToken(refreshToken: string) {
|
|
106
105
|
const url = `${this._params.config.supabaseUrl}/auth/v1/token?grant_type=refresh_token`
|
|
107
|
-
const response = await
|
|
106
|
+
const response = await fetch(url, {
|
|
108
107
|
method: 'POST',
|
|
109
108
|
headers: {
|
|
110
109
|
apikey: this._params.config.supabaseKey,
|