Doppler Share Secrets
This example uses a simple form to collect data.
The full source code of the example can be found here. You can install the extension here.
In this example we use a form to collect inputs from a user. To make it interesting, we use Doppler which is a service to make it easy to securely share sensitive information such as API keys or passwords.
Example: Safely share secrets with Doppler
The extension has one command. The command is a simple form with a textfield for the secret, a dropdown for an expiration after views and a second dropdown for an alternate expiration after a maximum of days.

Add form items

First, we render the static form. For this we add all the mentioned form items:
1
import { Form } from "@raycast/api";
2
3
export default function Command() {
4
return (
5
<Form>
6
<Form.TextArea id="secret" title="Secret" placeholder="Enter sensitive data to securely share..." />
7
<Form.Dropdown id="expireViews" title="Expire After Views" storeValue>
8
<Form.Dropdown.Item value="1" title="1 View" />
9
<Form.Dropdown.Item value="2" title="2 Views" />
10
<Form.Dropdown.Item value="3" title="3 Views" />
11
<Form.Dropdown.Item value="5" title="5 Views" />
12
<Form.Dropdown.Item value="10" title="10 Views" />
13
<Form.Dropdown.Item value="20" title="20 Views" />
14
<Form.Dropdown.Item value="50" title="50 Views" />
15
<Form.Dropdown.Item value="-1" title="Unlimited Views" />
16
</Form.Dropdown>
17
<Form.Dropdown id="expireDays" title="Expire After Days" storeValue>
18
<Form.Dropdown.Item value="1" title="1 Day" />
19
<Form.Dropdown.Item value="2" title="2 Days" />
20
<Form.Dropdown.Item value="3" title="3 Days" />
21
<Form.Dropdown.Item value="7" title="1 Week" />
22
<Form.Dropdown.Item value="14" title="2 Weeks" />
23
<Form.Dropdown.Item value="30" title="1 Month" />
24
<Form.Dropdown.Item value="90" title="3 Months" />
25
</Form.Dropdown>
26
</Form>
27
);
28
}
Copied!
Both dropdowns set the storeValue to true. This restores the last selected value when the command is opened again. This option is handy when your users select the same options often. In this case, we assume that users want to keep the expiration settings persisted.

Submit form values

Now that we have the form, we want to collect the inserted values, send them to Doppler and copy the URL that allows us to share the information securely. For this, we create a new action:
1
function ShareSecretAction() {
2
async function handleSubmit(values: { secret: string; expireViews: number; expireDays: number }) {
3
if (!values.secret) {
4
showToast(ToastStyle.Failure, "Secret is required");
5
return;
6
}
7
8
const toast = new Toast({ style: ToastStyle.Animated, title: "Sharing secret" });
9
await toast.show();
10
11
try {
12
const { body } = await got.post("https://api.doppler.com/v1/share/secrets/plain", {
13
json: { secret: values.secret, expire_views: values.expireViews, expire_days: values.expireDays },
14
responseType: "json",
15
});
16
17
await copyTextToClipboard((body as any).authenticated_url);
18
19
toast.style = ToastStyle.Success;
20
toast.title = "Shared secret";
21
toast.message = "Copied link to clipboard";
22
} catch (error) {
23
toast.style = ToastStyle.Failure;
24
toast.title = "Failed sharing secret";
25
toast.message = String(error);
26
}
27
}
28
29
return <SubmitFormAction icon={Icon.Upload} title="Share Secret" onSubmit={handleSubmit} />;
30
}
Copied!
Let's break this down:
    The <ShareSecretAction> returns a <SubmitFormAction>.
    The handleSubmit() gets called when the form is submitted with it's values.
      First we check if the user entered a secret. If not, we show a toast.
      Then we show a toast to hint that there is a network call in progress to share the secret.
      We call Doppler's API with the form values
        If the network response succeds, we copy the authenticated URL to the clipboard and show a success toast.
        If the network response fails, we show a failure toast with additional information about the failure.

Wire it up

The last step is to add the <ShareSecretAction> to the form:
1
export default function Command() {
2
return (
3
<Form
4
actions={
5
<ActionPanel>
6
<ShareSecretAction />
7
</ActionPanel>
8
}
9
>
10
{/* ... */}
11
</Form>
12
);
13
}
Copied!
And there you go. A simple form to enter a secret and get a URL that you can share with others that will "destroy itself" accordingly to your preferences. As next steps, you could use the <PasteAction> to paste the link directly to front-most application or add another action that clears the form and let's you create another shareable link.
Last modified 7d ago