Setup
To use the Secrets API, install the @wix/secrets
package using npm or Yarn:
1npm install @wix/secrets
or
1yarn add @wix/secrets
Then import { secrets }
from @wix/secrets
:
1import { secrets } from '@wix/secrets'
Creates a new secret.
The createSecret()
function returns a Promise that resolves secret ID when the secret is created.
Notes:
- The secret's name cannot start with
'wix'
or be identical to an existing secret's name. - Don't leave private keys in your code. Leaving them in your code is a security risk. Make sure to delete the keys from the code after running
createSecret()
.
Permission Scopes
For app development, you must have one of the following permission scopes:function createSecret(secret: Secret): Promise<string>
Fields of a new secret.
Deletes an existing secret by ID.
The deleteSecret()
function returns a Promise that resolves when the secret is deleted. You can retrieve the secret _id
using the listSecretInfo()
function.
Note: Deleting a secret is irreversible and will break all code using the secret.
Permission Scopes
For app development, you must have one of the following permission scopes:function deleteSecret(_id: string): Promise<void>
The unique ID of the secret to be deleted.
Retrieves the secret value specified by the secret name.
The getSecretValue()
function returns a Promise that resolves to the value of the secret with the specified given name.
Note: Only use a secret's value in the backend code. Returning the secret value in the frontend is a security risk.
Permission Scopes
For app development, you must have one of the following permission scopes:function getSecretValue(name: string): Promise<GetSecretValueResponse>
The name of the secret to get the value of.
Retrieves a list of objects containing information about all secrets.
The listSecretInfo()
function returns a Promise that resolves to a list containing information about all secrets stored on your site.
Note:
- The secret's value does not get returned for security reasons. To retrieve a secret's value, use the
getSecretValue()
function.
Permission Scopes
For app development, you must have one of the following permission scopes:function listSecretInfo(): Promise<ListSecretInfoResponse>
Updates the specified fields of an existing secret by ID.
The updateSecret()
function returns a Promise that resolves when the secret is successfully updated. You can update one or more fields. Only fields passed in the secret
object will be updated. All other properties will remain unchanged.
You can retrieve the _id
parameter from the listSecretInfo()
function. The secret _id
is different from the secret name
used by the getSecretValue()
function.
Notes:
- Changing a secret's name or value will break all code using the secret.
- You can't rename the secret with a name of an existing secret.
- Don't leave private keys in your code! Leaving them in is a security risk. Make sure to delete the keys from the code after running
updateSecret()
.
Permission Scopes
For app development, you must have one of the following permission scopes:function updateSecret(_id: string, secret: Secret): Promise<void>
The unique ID of the secret to be updated.
The secret fields to update.