Installations
npm install @directus/sdk
Developer Guide
Typescript
Yes
Module System
ESM
Min. Node Version
>=22
Node Version
22.13.1
NPM Version
10.9.2
Score
99.5
Supply Chain
100
Quality
91.9
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Languages
TypeScript (71.67%)
Vue (26.28%)
SCSS (0.82%)
CSS (0.4%)
Liquid (0.4%)
JavaScript (0.38%)
Dockerfile (0.03%)
HTML (0.02%)
Developer
Download Statistics
Total Downloads
4,467,340
Last Day
8,393
Last Week
40,480
Last Month
187,164
Last Year
2,501,765
GitHub Statistics
28,945 Stars
12,607 Commits
4,041 Forks
323 Watching
173 Branches
447 Contributors
Bundle Size
47.61 kB
Minified
9.03 kB
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
19.0.1
Package Id
@directus/sdk@19.0.1
Unpacked Size
534.49 kB
Size
93.38 kB
File Count
9
NPM Version
10.9.2
Node Version
22.13.1
Publised On
04 Feb 2025
Total Downloads
Cumulative downloads
Total Downloads
4,467,340
Last day
-11.3%
8,393
Compared to previous day
Last week
-18.3%
40,480
Compared to previous week
Last month
-18.5%
187,164
Compared to previous month
Last year
85.8%
2,501,765
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Directus JavaScript SDK
Features
- TypeScript first: The SDK provides a robust and type-safe development experience.
- Modular architecture: The SDK is split into separate modules, giving you granular control over which features to include and which can be pruned at build-time.
- Lightweight and dependency-free: It does not require external libraries, ensuring a lighter bundle and streamlined experience.
Composable Client
The client is split up in separate features you can mix and match to compose a client with only the features you need or want.
1const client = createDirectus<Schema>('https://api.directus.io');
This client is currently an empty wrapper without any functionality. Before you can do anything with it you'll need to add some features. The following composables are available/in progress:
rest()
REST request functions- adds
.request(...)
on the client
- adds
graphql()
GraphQL request functions- adds
.query(...)
on the client
- adds
staticToken()
authentication functions- adds
.getToken()
and.setToken()
on the client
- adds
authenticate()
authentication functions- adds
.login({ email, password })
,.logout()
,.refresh()
on the client - adds
.getToken()
and.setToken()
on the client
- adds
realtime()
websocket connectivity- adds
.subscribe(...)
,.sendMessage(...)
,.onWebsocket('message', (message) => {})
on the client
- adds
For this example we'll build a client including rest
and graphql
:
1const client = createDirectus<Schema>('https://api.directus.io').with(rest()).with(graphql()); 2 3// do a REST request 4const restResult = await client.request(readItems('articles')); 5 6// do a GraphQL request 7const gqlResult = await client.query<OutputType>(` 8 query { 9 articles { 10 id 11 title 12 author { 13 first_name 14 } 15 } 16 } 17`);
Authentication
1const client = createDirectus<Schema>('https://api.directus.io').with(rest()).with(authentication('json')); 2 3await client.login('admin@example.com', 'd1r3ctu5'); 4 5// do authenticated requests
1const client = createDirectus<Schema>('https://api.directus.io').with(rest()).with(staticToken('super-secure-token')); 2 3// do authenticated requests
Real-Time
The realtime()
extension allows you to work with a Directus REST WebSocket.
Subscribing to updates:
1const client = createDirectus<Schema>('https://api.directus.io').with( 2 realtime({ 3 authMode: 'public', 4 }), 5); 6 7const { subscription, unsubscribe } = await client.subscribe('test', { 8 query: { fields: ['*'] }, 9}); 10 11for await (const item of subscription) { 12 console.log('subscription', { item }); 13} 14 15// unsubscribe()
Receive/Send messages:
1const client = createDirectus<Schema>('https://api.directus.io').with( 2 realtime({ 3 authMode: 'public', 4 }), 5); 6 7const stop = client.onWebSocket('message', (message) => { 8 if ('type' in message && message['type'] === 'pong') { 9 console.log('PONG received'); 10 stop(); 11 } 12}); 13 14client.sendMessage({ type: 'ping' });
Build Your Schema
1// The main schema type containing all collections available 2interface MySchema { 3 collection_a: CollectionA[]; // regular collections are array types 4 collection_b: CollectionB[]; 5 collection_c: CollectionC; // this is a singleton 6 // junction collections are collections too 7 collection_a_b_m2m: CollectionAB_Many[]; 8 collection_a_b_m2a: CollectionAB_Any[]; 9} 10 11// collection A 12interface CollectionA { 13 id: number; 14 status: string; 15 // relations 16 m2o: number | CollectionB; 17 o2m: number[] | CollectionB[]; 18 m2m: number[] | CollectionAB_Many[]; 19 m2a: number[] | CollectionAB_Any[]; 20} 21 22// Many-to-Many junction table 23interface CollectionAB_Many { 24 id: number; 25 collection_a_id: CollectionA; 26 collection_b_id: CollectionB; 27} 28 29// Many-to-Any junction table 30interface CollectionAB_Any { 31 id: number; 32 collection_a_id: CollectionA; 33 collection: 'collection_b' | 'collection_c'; 34 item: string | CollectionB | CollectionC; 35} 36 37// collection B 38interface CollectionB { 39 id: number; 40 value: string; 41} 42 43// singleton collection 44interface CollectionC { 45 id: number; 46 app_settings: string; 47 something: string; 48}
No vulnerabilities found.
Reason
30 commit(s) and 13 issue activity found in the last 90 days -- score normalized to 10
Reason
all changesets reviewed
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
packaging workflow detected
Details
- Info: Project packages its releases by way of GitHub Actions.: .github/workflows/release.yml:68
Reason
license file detected
Details
- Info: project has a license file: license:0
- Warn: project license file does not contain an FSF or OSI license.
Reason
SAST tool detected but not run on all commits
Details
- Info: SAST configuration detected: CodeQL
- Warn: 0 commits out of 30 are checked with a SAST tool
Reason
3 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-5359-pvf2-pw78
- Warn: Project is vulnerable to: GHSA-c76h-2ccp-4975
- Warn: Project is vulnerable to: GHSA-vg6x-rcgg-rjx6
Reason
security policy file detected
Details
- Info: security policy file detected: security.md:1
- Warn: no linked content found
- Warn: One or no descriptive hints of disclosure, vulnerability, and/or timelines in security policy
- Info: Found text in security policy: security.md:1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql-analysis.yml:16
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:17
- Warn: no topLevel permission defined: .github/workflows/blackbox.yml:1
- Warn: no topLevel permission defined: .github/workflows/check.yml:1
- Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1
- Warn: no topLevel permission defined: .github/workflows/docs.yml:1
- Warn: no topLevel permission defined: .github/workflows/release.yml:1
- Warn: no topLevel permission defined: .github/workflows/sync-dockerhub-readme.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/blackbox.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/blackbox.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/blackbox.yml:58: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/blackbox.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/check.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/check.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/check.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/check.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/check.yml:42: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/check.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/check.yml:45: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/check.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/check.yml:60: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/check.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/cla.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/cla.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/cla.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/cla.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/cla.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/cla.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:45: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:52: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/docs.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/docs.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/lock-threads.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/lock-threads.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:51: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:74: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:77: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:80: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:83: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:92: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:104: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:111: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:119: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/stale-issues.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/stale-issues.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/sync-dockerhub-readme.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/sync-dockerhub-readme.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/sync-dockerhub-readme.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/directus/directus/sync-dockerhub-readme.yml/main?enable=pin
- Warn: containerImage not pinned by hash: Dockerfile:8
- Warn: containerImage not pinned by hash: Dockerfile:51
- Warn: npmCommand not pinned by hash: Dockerfile:53
- Info: 0 out of 16 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 15 third-party GitHubAction dependencies pinned
- Info: 0 out of 2 containerImage dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Score
6.5
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to @directus/sdk
@directus/extensions-sdk
A toolkit to develop extensions to extend Directus
@directus/sdk-js
Directus SDK for JavaScript (Node and Browser)
pc-directus-interface
Internal implementation of generic Directus methods to interact with Directus
@fengsi/directus-sdk-js
Directus SDK for JavaScript (Node and Browser)