@tanglemedia/svelte-starter-directus-api 0.0.13 → 0.0.15
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/dist/auth.js +19 -19
- package/dist/client.js +13 -19
- package/package.json +9 -9
- package/src/auth.ts +20 -20
- package/src/client.ts +20 -20
package/dist/auth.js
CHANGED
|
@@ -22,29 +22,29 @@ const localDirectusStorage = (storageKey = 'access_token_directus') => {
|
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
|
-
const cookieDirectusStorage = (cookieKey = 'access_token_directus') => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
25
|
+
// const cookieDirectusStorage = (cookieKey: string = 'access_token_directus') => {
|
|
26
|
+
// return {
|
|
27
|
+
// get: async (): Promise<AuthenticationData | null> => {
|
|
28
|
+
// const data = JSON.parse(cookie.get(cookieKey)) || '{}';
|
|
29
|
+
// return data ? (data as AuthenticationData) : null;
|
|
30
|
+
// },
|
|
31
|
+
// set: async (value: AuthenticationData | null): Promise<void> => {
|
|
32
|
+
// cookie.set(cookieKey, JSON.stringify(value))
|
|
33
|
+
// }
|
|
34
|
+
// };
|
|
35
|
+
// }
|
|
36
36
|
const authenticationConfig = {
|
|
37
37
|
storage: localDirectusStorage(),
|
|
38
38
|
autoRefresh: true,
|
|
39
39
|
msRefreshBeforeExpires: 30000,
|
|
40
40
|
credentials: 'include'
|
|
41
41
|
};
|
|
42
|
-
const authenticationCookieConfig = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
};
|
|
42
|
+
// const authenticationCookieConfig: AuthenticationConfig = {
|
|
43
|
+
// storage: cookieDirectusStorage(),
|
|
44
|
+
// autoRefresh: true,
|
|
45
|
+
// msRefreshBeforeExpires: 30000,
|
|
46
|
+
// credentials: 'include'
|
|
47
|
+
// };
|
|
48
48
|
class ApiAuthDirectus {
|
|
49
49
|
baseURL;
|
|
50
50
|
storageMode;
|
|
@@ -63,8 +63,8 @@ class ApiAuthDirectus {
|
|
|
63
63
|
}
|
|
64
64
|
else {
|
|
65
65
|
this.directus = createDirectus(this.baseURL)
|
|
66
|
-
.with(
|
|
67
|
-
.with(
|
|
66
|
+
.with(authentication('cookie', { credentials: 'include' }))
|
|
67
|
+
.with(rest({ credentials: 'include' }));
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
catch (error) {
|
package/dist/client.js
CHANGED
|
@@ -22,29 +22,23 @@ const localDirectusStorage = (storageKey = 'access_token_directus') => {
|
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
|
-
const cookieDirectusStorage = (cookieKey = 'access_token_directus') => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
25
|
+
// const cookieDirectusStorage = (cookieKey: string = 'access_token_directus') => {
|
|
26
|
+
// return {
|
|
27
|
+
// get: async (): Promise<AuthenticationData | null> => {
|
|
28
|
+
// const data = JSON.parse(cookie.get(cookieKey)) || '{}';
|
|
29
|
+
// return data ? (data as AuthenticationData) : null;
|
|
30
|
+
// },
|
|
31
|
+
// set: async (value: AuthenticationData | null): Promise<void> => {
|
|
32
|
+
// cookie.set(cookieKey, JSON.stringify(value))
|
|
33
|
+
// }
|
|
34
|
+
// };
|
|
35
|
+
// }
|
|
36
36
|
const authenticationConfig = {
|
|
37
37
|
storage: localDirectusStorage(),
|
|
38
38
|
autoRefresh: true,
|
|
39
39
|
msRefreshBeforeExpires: 30000,
|
|
40
40
|
credentials: 'include'
|
|
41
41
|
};
|
|
42
|
-
const authenticationCookieConfig = {
|
|
43
|
-
storage: cookieDirectusStorage(),
|
|
44
|
-
autoRefresh: true,
|
|
45
|
-
msRefreshBeforeExpires: 30000,
|
|
46
|
-
credentials: 'include'
|
|
47
|
-
};
|
|
48
42
|
class ApiClientDirectus {
|
|
49
43
|
baseURL;
|
|
50
44
|
storageMode;
|
|
@@ -63,8 +57,8 @@ class ApiClientDirectus {
|
|
|
63
57
|
}
|
|
64
58
|
else {
|
|
65
59
|
this.directus = createDirectus(this.baseURL)
|
|
66
|
-
.with(
|
|
67
|
-
.with(
|
|
60
|
+
.with(authentication('cookie', { credentials: 'include' }))
|
|
61
|
+
.with(rest({ credentials: 'include' }));
|
|
68
62
|
}
|
|
69
63
|
}
|
|
70
64
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanglemedia/svelte-starter-directus-api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"types": "src/index.ts",
|
|
6
6
|
"description": "directus API wrapper for all the directus sdk functionality",
|
|
@@ -23,17 +23,17 @@
|
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@sveltejs/adapter-auto": "^3.1.0",
|
|
26
|
-
"@sveltejs/package": "^2.2.
|
|
26
|
+
"@sveltejs/package": "^2.2.6",
|
|
27
27
|
"@sveltejs/vite-plugin-svelte": "^3.0.1",
|
|
28
28
|
"@testing-library/jest-dom": "^6.2.0",
|
|
29
29
|
"@testing-library/svelte": "^4.0.5",
|
|
30
|
-
"@vitest/coverage-v8": "^1.2.
|
|
30
|
+
"@vitest/coverage-v8": "^1.2.1",
|
|
31
31
|
"jsdom": "^23.2.0",
|
|
32
|
-
"msw": "^2.1.
|
|
33
|
-
"svelte": "^4.2.
|
|
32
|
+
"msw": "^2.1.2",
|
|
33
|
+
"svelte": "^4.2.9",
|
|
34
34
|
"svelte-check": "^3.6.3",
|
|
35
|
-
"vite": "^5.0.
|
|
36
|
-
"vitest": "^1.2.
|
|
35
|
+
"vite": "^5.0.12",
|
|
36
|
+
"vitest": "^1.2.1",
|
|
37
37
|
"eslint-config-custom": "0.0.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@types/js-cookie": "^3.0.6",
|
|
42
42
|
"esm-env": "^1.0.0",
|
|
43
43
|
"js-cookie": "^3.0.5",
|
|
44
|
-
"@tanglemedia/svelte-starter-core": "0.0.
|
|
44
|
+
"@tanglemedia/svelte-starter-core": "0.0.16"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@sveltejs/kit": ">=1.20 <2",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"lint": "prettier --check --ignore-path=../../.prettierignore . && eslint \".\" --ignore-path=../../.prettierignore",
|
|
54
54
|
"format": "prettier --write --ignore-path=../../.prettierignore . && eslint \".\" --ignore-path=../../.prettierignore",
|
|
55
55
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
56
|
-
"test": "vitest",
|
|
56
|
+
"test": "vitest run",
|
|
57
57
|
"test:debug": "vitest --test-timeout=0 --reporter=verbose --coverage",
|
|
58
58
|
"clean": "rimraf ./dist && rimraf ./coverage"
|
|
59
59
|
}
|
package/src/auth.ts
CHANGED
|
@@ -38,18 +38,18 @@ const localDirectusStorage = (storageKey: string = 'access_token_directus') => {
|
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
const cookieDirectusStorage = (cookieKey: string = 'access_token_directus') => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
41
|
+
// const cookieDirectusStorage = (cookieKey: string = 'access_token_directus') => {
|
|
42
|
+
// return {
|
|
43
|
+
// get: async (): Promise<AuthenticationData | null> => {
|
|
44
|
+
// const data = JSON.parse(cookie.get(cookieKey)) || '{}';
|
|
45
|
+
// return data ? (data as AuthenticationData) : null;
|
|
46
|
+
|
|
47
|
+
// },
|
|
48
|
+
// set: async (value: AuthenticationData | null): Promise<void> => {
|
|
49
|
+
// cookie.set(cookieKey, JSON.stringify(value))
|
|
50
|
+
// }
|
|
51
|
+
// };
|
|
52
|
+
// }
|
|
53
53
|
|
|
54
54
|
const authenticationConfig: AuthenticationConfig = {
|
|
55
55
|
storage: localDirectusStorage(),
|
|
@@ -58,12 +58,12 @@ const authenticationConfig: AuthenticationConfig = {
|
|
|
58
58
|
credentials: 'include'
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
const authenticationCookieConfig: AuthenticationConfig = {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
61
|
+
// const authenticationCookieConfig: AuthenticationConfig = {
|
|
62
|
+
// storage: cookieDirectusStorage(),
|
|
63
|
+
// autoRefresh: true,
|
|
64
|
+
// msRefreshBeforeExpires: 30000,
|
|
65
|
+
// credentials: 'include'
|
|
66
|
+
// };
|
|
67
67
|
|
|
68
68
|
class ApiAuthDirectus {
|
|
69
69
|
private baseURL: string;
|
|
@@ -84,8 +84,8 @@ class ApiAuthDirectus {
|
|
|
84
84
|
.with(authentication('json', authenticationConfig));
|
|
85
85
|
}else {
|
|
86
86
|
this.directus = createDirectus<T>(this.baseURL)
|
|
87
|
-
.with(
|
|
88
|
-
.with(
|
|
87
|
+
.with(authentication('cookie', { credentials: 'include' }))
|
|
88
|
+
.with(rest({ credentials: 'include' }));
|
|
89
89
|
}
|
|
90
90
|
} catch (error) {
|
|
91
91
|
console.error(`Error initializing Directus:`, error);
|
package/src/client.ts
CHANGED
|
@@ -47,18 +47,18 @@ const localDirectusStorage = (storageKey: string = 'access_token_directus') => {
|
|
|
47
47
|
};
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
const cookieDirectusStorage = (cookieKey: string = 'access_token_directus') => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
50
|
+
// const cookieDirectusStorage = (cookieKey: string = 'access_token_directus') => {
|
|
51
|
+
// return {
|
|
52
|
+
// get: async (): Promise<AuthenticationData | null> => {
|
|
53
|
+
// const data = JSON.parse(cookie.get(cookieKey)) || '{}';
|
|
54
|
+
// return data ? (data as AuthenticationData) : null;
|
|
55
|
+
|
|
56
|
+
// },
|
|
57
|
+
// set: async (value: AuthenticationData | null): Promise<void> => {
|
|
58
|
+
// cookie.set(cookieKey, JSON.stringify(value))
|
|
59
|
+
// }
|
|
60
|
+
// };
|
|
61
|
+
// }
|
|
62
62
|
|
|
63
63
|
const authenticationConfig: AuthenticationConfig = {
|
|
64
64
|
storage: localDirectusStorage(),
|
|
@@ -67,12 +67,12 @@ const authenticationConfig: AuthenticationConfig = {
|
|
|
67
67
|
credentials: 'include'
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
-
const authenticationCookieConfig: AuthenticationConfig = {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
};
|
|
70
|
+
// const authenticationCookieConfig: AuthenticationConfig = {
|
|
71
|
+
// storage: cookieDirectusStorage(),
|
|
72
|
+
// autoRefresh: true,
|
|
73
|
+
// msRefreshBeforeExpires: 30000,
|
|
74
|
+
// credentials: 'include'
|
|
75
|
+
// };
|
|
76
76
|
|
|
77
77
|
type BaseApiMethods = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
78
78
|
|
|
@@ -97,8 +97,8 @@ class ApiClientDirectus implements ApiAdapterInterface {
|
|
|
97
97
|
.with(authentication('json', authenticationConfig));
|
|
98
98
|
}else {
|
|
99
99
|
this.directus = createDirectus<T>(this.baseURL)
|
|
100
|
-
.with(
|
|
101
|
-
.with(
|
|
100
|
+
.with(authentication('cookie', { credentials: 'include' }))
|
|
101
|
+
.with(rest({ credentials: 'include' }));
|
|
102
102
|
}
|
|
103
103
|
} catch (error) {
|
|
104
104
|
console.error(`Error initializing Directus:`, error);
|