Skip to content

Commit

Permalink
chore: Update JSDoc and print warning message if deprecated mode para…
Browse files Browse the repository at this point in the history
…meter is used (#51)

* chore: Update JSDoc and print warning message if deprecated mode parameter is used to initialize FormSG SDK

* Update src/index.ts

Co-authored-by: Yuan Ruo <yuanruo@data.gov.sg>

* update README.md file

Co-authored-by: Yuan Ruo <yuanruo@data.gov.sg>
  • Loading branch information
frankchn and liangyuanruo committed Feb 2, 2021
1 parent a3ce917 commit bccad0a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ npm install @opengovsg/formsg-sdk --save

```javascript
const formsg = require('@opengovsg/formsg-sdk')({
mode: 'production',
publicKey: 'replace-me-with-public-key',
})
```

| Option | Default | Description |
| ------ | ------------ | --------------------------------------------------------------- |
| mode | 'production' | Set to 'staging' if integrating against FormSG staging servers. |
| Option | Description |
| --------- | ---------------------------------------------------------------------------------------------------- |
| publicKey | (required) This public key is used to authenticate or verify signed objects passed into this package. |

You can find the public key for the FormSG staging and production environments at the bottom of this README.md file.

## Usage

Expand Down
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import Crypto from './crypto'
/**
* Entrypoint into the FormSG SDK
* @param {PackageInitParams} config Package initialization config parameters
* @param {string} [config.publicKey] This public key is used to authenticate or verify signed objects passed into this package.
* @param {string?} [config.webhookSecretKey] Optional base64 secret key for signing webhooks
*//**
* Deprecated entrypoint into the FormSG SDK
*
* @deprecated since January 2021
* @param {PackageInitParams} config Package initialization config parameters
* @param {string?} [config.publicKey] Optional. If provided, this public key will be used instead to authenticate or verify signed objects passed into this package.
* @param {string?} [config.mode] Optional. Initializes public key used for verifying and decrypting in this package. If `config.signingPublicKey` is given, this param will be ignored.
* @param {string?} [config.webhookSecretKey] Optional base64 secret key for signing webhooks
Expand All @@ -20,6 +27,10 @@ export = function (config: PackageInitParams = {}) {
const verificationPublicKey =
publicKey || getVerificationPublicKey(mode || 'production')

if (typeof mode !== 'undefined') {
console.warn('Initializing the FormSG SDK with the `mode` parameter is now deprecated. Please switch to the publicKey parameter instead.')
}

return {
webhooks: new Webhooks({
publicKey: encryptionPublicKey,
Expand Down

0 comments on commit bccad0a

Please sign in to comment.