Skip to content

Commit e0b4e59

Browse files
committed
feat: initial v3 version
1 parent e72541d commit e0b4e59

File tree

10 files changed

+23299
-21930
lines changed

10 files changed

+23299
-21930
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ jspm_packages
5555
test/fixtures/init/empty
5656

5757
# Compiled plugin
58-
dist
58+
lib
5959

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
legacy-peer-deps=true

README.md

Lines changed: 71 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,94 @@
11
# sanity-secrets
22

3+
> **NOTE**
4+
>
5+
> This is the **Sanity Studio v3 version** of sanity-secrets.
6+
>
7+
> For the v2 version, please refer to the [v2-branch](https://github.com/sanity-io/sanity-secrets).
8+
39
React hooks and UI for reading and managing secrets in a Sanity Studio. This is a good pattern for keeping configuration secret. Instead of using environment variables which would be bundled with the Studio source (it is an SPA), we store secret information in a document in the dataset. This document will not be readable to externals even in a public dataset. With custom access controls you can also specify which users can read the configuration in your Studio.
410

511
## Caveat
612

7-
This plugin stores secrets as fields on a document in your dataset. Even though that document is not accessible without having the correct permissions (logged in user with read access) it will be included in any export your may do of your dataset and this is important to be aware of.
13+
This plugin stores secrets as fields on a document in your dataset.
14+
Even though that document is not accessible without having the correct permissions
15+
(logged in user with read access) it will be included in any export your may do of your dataset and this is important to be aware of.
816

917
## Future deprecation
1018

1119
When native server-side secrets handling is available on the Sanity platform this plugin will be deprecated and a migration path will be provided.
1220

13-
# Usage Example
21+
## Installation
22+
23+
```
24+
npm install --save @sanity/sanity-secrets@studio-v3
25+
```
26+
27+
or
28+
29+
```
30+
yarn add @sanity/sanity-secrets@studio-v3
31+
```
32+
33+
## Usage
34+
1435
Quick example of both using the secrets and putting up a dialog to let user enter them.
1536

1637
```javascript
38+
import {useEffect, useState} from 'react'
1739
import {useSecrets, SettingsView} from 'sanity-secrets'
1840

19-
const namespace = "myPlugin"
41+
const namespace = "myPlugin";
2042

21-
const pluginConfigKeys = [{
22-
key: 'apiKey',
23-
title: 'Your secret API key'
24-
}]
43+
const pluginConfigKeys = [
44+
{
45+
key: "apiKey",
46+
title: "Your secret API key",
47+
},
48+
];
2549

2650
const MyComponent = () => {
27-
const {secrets} = useSecrets(namespace)
28-
const [showSettings, setShowSettings] = useState(false)
29-
51+
const { secrets } = useSecrets(namespace);
52+
const [showSettings, setShowSettings] = useState(false);
53+
3054
useEffect(() => {
31-
if (!secrets) { setShowSettings(true)}
32-
}, [secrets])
33-
55+
if (!secrets) {
56+
setShowSettings(true);
57+
}
58+
}, [secrets]);
59+
60+
if (!showSettings) {
61+
return null;
62+
}
3463
return (
35-
{showSettings && (
36-
<SettingsView
37-
namespace={namespace}
38-
keys={pluginConfigKeys}
39-
onClose={() => {
40-
setShowSettings(false)
41-
}}
42-
/>
43-
)}
44-
)
45-
}
64+
<SettingsView
65+
title={"sdfds"}
66+
namespace={namespace}
67+
keys={pluginConfigKeys}
68+
onClose={() => {
69+
setShowSettings(false);
70+
}}
71+
/>
72+
);
73+
};
74+
4675
```
76+
## License
77+
78+
MIT-licensed. See LICENSE.
79+
80+
## Develop & Test
81+
82+
This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)
83+
with default configuration for build & watch scripts.
84+
85+
See [Testing a plugin in Sanity Studio](https://github.com/sanity-io/plugin-kit#testing-a-plugin-in-sanity-studio)
86+
on how to run this plugin with hotreload in the studio.
87+
88+
### Release new version
89+
90+
Run ["CI & Release" workflow](https://github.com/sanity-io/sanity-secrets/actions/workflows/main.yml).
91+
Make sure to select the main branch and check "Release new version".
92+
93+
Semantic release will only release on configured branches, so it is safe to run release on any branch.
4794

0 commit comments

Comments
 (0)