Gathering detailed insights and metrics for @knocklabs/node
Gathering detailed insights and metrics for @knocklabs/node
Gathering detailed insights and metrics for @knocklabs/node
Gathering detailed insights and metrics for @knocklabs/node
@knocklabs/react-core
A set of React components to build notification experiences powered by Knock
@knocklabs/react
A set of React components to build notification experiences powered by Knock
@knocklabs/types
Type definitions for Knock libraries
@knocklabs/client
The clientside library for interacting with Knock
npm install @knocklabs/node
98.6
Supply Chain
99.6
Quality
90.3
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
41 Stars
122 Commits
6 Forks
7 Watching
23 Branches
13 Contributors
Updated on 20 Nov 2024
Minified
Minified + Gzipped
TypeScript (100%)
Cumulative downloads
Total Downloads
Last day
51.4%
107,698
Compared to previous day
Last week
14.1%
458,496
Compared to previous week
Last month
7.1%
1,623,691
Compared to previous month
Last year
315.2%
6,762,851
Compared to previous year
1
7
Knock API access for applications written in server-side Javascript. This package is compatible with the Vercel Edge runtime and with Cloudflare Workers.
See the documentation for Node.js usage examples.
1npm install @knocklabs/node
To use the library you must provide a secret API key, provided in the Knock dashboard.
If you are using enhanced security mode you will also need to provide your signing key.
You can set both as environment variables:
1KNOCK_API_KEY="sk_12345" 2KNOCK_SIGNING_KEY="S25vY2sga25vY2sh..."
You can also pass the Knock API key in the constructor. The signing key is passed separately to the signUserToken
method (see below):
1import { Knock } from "@knocklabs/node"; 2 3const knockClient = new Knock("sk_12345");
1import { Knock } from "@knocklabs/node"; 2const knockClient = new Knock("sk_12345"); 3 4// The key of the workflow (from Knock dashboard) 5await knockClient.workflows.trigger("dinosaurs-loose", { 6 // user id of who performed the action 7 actor: "dnedry", 8 // list of user ids for who should receive the notification 9 recipients: ["jhammond", "agrant", "imalcolm", "esattler"], 10 // data payload to send through 11 data: { 12 type: "trex", 13 priority: 1, 14 }, 15 // an optional identifier for the tenant that the notifications belong to 16 tenant: "jurassic-park", 17 // an optional key to provide to cancel a workflow 18 cancellationKey: triggerAlert.id, 19});
1import { Knock } from "@knocklabs/node"; 2const knockClient = new Knock("sk_12345"); 3 4await knockClient.workflows.cancel("dinosaurs-loose", triggerAlert.id, { 5 // optionally you can specify recipients here 6 recipients: ["jhammond"], 7});
1import { Knock } from "@knocklabs/node"; 2const knockClient = new Knock("sk_12345"); 3 4await knockClient.users.identify("jhammond", { 5 name: "John Hammond", 6 email: "jhammond@ingen.net", 7});
1import { Knock } from "@knocklabs/node"; 2const knockClient = new Knock("sk_12345"); 3 4await knockClient.users.get("jhammond");
1import { Knock } from "@knocklabs/node"; 2const knockClient = new Knock("sk_12345"); 3 4await knockClient.users.delete("jhammond");
1import { Knock } from "@knocklabs/node"; 2const knockClient = new Knock("sk_12345"); 3 4// Set an entire preference set 5await knockClient.users.setPreferences("jhammond", { 6 channel_types: { email: true, sms: false }, 7 workflows: { 8 "dinosaurs-loose": { 9 channel_types: { email: false, in_app_feed: true }, 10 }, 11 }, 12}); 13 14// Retrieve a whole preference set 15const preferences = await knockClient.users.getPreferences("jhammond");
1import { Knock } from "@knocklabs/node"; 2const knockClient = new Knock("sk_12345"); 3 4// Setting channel data for an APNS 5await knockClient.users.setChannelData("jhammond", KNOCK_APNS_CHANNEL_ID, { 6 tokens: [apnsToken], 7}); 8 9// Getting channel data for the APNS channel 10await knockClient.users.getChannelData("jhammond", KNOCK_APNS_CHANNEL_ID);
1import { Knock } from "@knocklabs/node"; 2const knockClient = new Knock("sk_12345"); 3 4const tenantId = "tenant-123"; 5const knockSlackChannelId = "7c1e0042-5ef2-411a-a43b-e541acb139ed"; 6// An optional object containing the query options passed to Slack: 7// https://api.slack.com/methods/conversations.list#arg_cursor 8const queryOptions = { 9 cursor: null, 10 limit: 200, 11 exclude_archived: true, 12 team_id: null, 13 types: "public_channel", 14}; 15 16// Retrieve a list of Slack channels 17const channelsInput = { 18 tenant: tenantId, 19 knockChannelId: knockSlackChannelId, 20 queryOptions, 21}; 22await knockClient.slack.getChannels(channelsInput); 23 24// Check Slack connection 25const authInput = { tenant: tenantId, knockChannelId: knockSlackChannelId }; 26await knockClient.slack.authCheck(authInput); 27 28// Revoke access token 29const revokeInput = { tenant: tenantId, knockChannelId: knockSlackChannelId }; 30await knockClient.slack.revokeAccessToken(revokeInput);
When using enhanced security mode (recommended in production), you will need to sign JWTs server-side to authenticate your users.
You will need to generate an environment specific signing key in the Knock dashboard under "API Keys", and then enable enhanced security mode for your environment.
1import { Knock } from "@knocklabs/node"; 2 3// When signing user tokens, you do not need to instantiate a Knock client. 4 5// jhammond is the user id for which to sign this token 6const token = await Knock.signUserToken("jhammond", { 7 // The signing key from the Knock Dashboard in base-64 or PEM-encoded format. 8 // If not provided, the key will be read from the KNOCK_SIGNING_KEY environment variable. 9 signingKey: "S25vY2sga25vY2sh...", 10 // Optional: How long the token should be valid for, in seconds (default 1 hour) 11 // For long-lived connections, you will need to refresh the token before it expires. 12 expiresInSeconds: 60 * 60, 13}); 14 15// This token can now be safely passed to your client e.g. in a cookie or API response.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
Found 19/30 approved changesets -- score normalized to 6
Reason
3 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 2
Reason
8 existing vulnerabilities detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
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 More