Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'getstream' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
console.error('STREAM_API_KEY should be set');
return;
}
if (!appId) {
console.error('STREAM_APP_ID should be set');
return;
}
if (!apiSecret) {
console.error('STREAM_SECRET should be set');
return;
}
console.log(apiKey, apiSecret);
let client: CloudClient = stream.connectCloud(apiKey, appId, {
// urlOverride: {
// api: apiUrl,
// },
keepAlive: false,
});
function createUserSession(userId): UserSession {
return client.createUserSession(
stream.signing.JWTUserSessionToken(apiSecret, userId),
);
}
let batman = createUserSession('batman');
let content = 'test2';
console.log(await batman.feed('notification').get({ limit: 1 }));
await batman.feed('notification').addActivity({
export const getErrorMessage = (
error: Error,
type: FlowRequestTypes,
detail: Object,
): string => {
console.warn(error);
if (!(error instanceof stream.errors.StreamApiError)) {
return fallbackErrorMessage(error, type, detail);
}
const response = error.response;
if (!response.statusCode || !response.body || !response.body.detail) {
return fallbackErrorMessage(error, type, detail);
}
const statusCode = response.statusCode;
const text = response.body.detail;
/* eslint-disable no-magic-numbers */
if (statusCode >= 400 && statusCode < 600) {
return text;
}
/* eslint-enable no-magic-numbers */
// this is split out so that the auth controller can follow featured podcasts at user creation
import Follow from '../models/follow';
import config from '../config';
import stream from 'getstream';
const client = stream.connect(config.stream.apiKey, config.stream.apiSecret);
const followPodcast = (userID, podcastID) => {
// couple things:
// find follow relationship already in DB - if it exists, return it, don't send a 409
// if not, create a new one, and:
// timeline follows podcast
// user_episode follows podcast
let obj = {
podcast: podcastID,
user: userID,
};
return Follow.findOne(obj).then(existingFollow => {
if (existingFollow) {
// serialize podcast and user ids
existingFollow.podcast = existingFollow.podcast._id;
existingFollow.user = existingFollow.user._id;
function createUserSession(userId): UserSession {
return client.createUserSession(
stream.signing.JWTUserSessionToken(apiSecret, userId),
);
}
import '../loadenv';
import '../utils/db';
import program from 'commander';
import logger from '../utils/logger';
import Follow from '../models/follow';
import { FollowSchema } from '../models/follow';
import asyncTasks from '../asyncTasks';
import stream from 'getstream';
import config from '../config';
const streamClient = stream.connect(config.stream.apiKey, config.stream.apiSecret);
program.parse(process.argv);
async function main() {
logger.info(`time to resync those follows, \\0/`);
let followCount = await Follow.count({});
let chunkSize = 500;
for (let i = 0, j = followCount; i < j; i += chunkSize) {
let follows = await Follow.find({})
.skip(i)
.limit(chunkSize)
.lean();
logger.info(`found ${follows.length} follows`);
let feedRelations = [];
import stream from 'getstream';
import Share from '../models/share';
import config from '../config';
import logger from '../utils/logger';
const client = stream.connect(
config.stream.apiKey,
config.stream.apiSecret,
);
exports.list = (req, res) => {
const page = parseInt(req.query.page, 10) || 0;
const perPage = parseInt(req.query.per_page, 10) || 10;
Share.find({ flags: { $lte: 5 } })
.skip(perPage * page)
.limit(perPage)
.then(shares => {
res.json(shares);
})
.catch(err => {
logger.error(err);
if (!apiKey) {
console.error('STREAM_API_KEY should be set');
return;
}
if (!appId) {
console.error('STREAM_APP_ID should be set');
return;
}
if (!apiSecret) {
console.error('STREAM_SECRET should be set');
return;
}
let client: CloudClient = stream.connectCloud(apiKey, appId);
function createUserSession(userId): UserSession {
return client.createUserSession(
stream.signing.JWTUserSessionToken(apiSecret, userId),
);
}
let batman = createUserSession('batman');
let fluff = createUserSession('fluff');
let league = createUserSession('justiceleague');
let bowie = createUserSession('davidbowie');
console.log('Add the following line to your .env file');
console.log('STREAM_API_TOKEN=' + batman.token);
await batman.user.getOrCreate({
export const getErrorMessage = (
error: Error,
type: FlowRequestTypes,
detail: Object,
): string => {
console.warn(error);
if (!(error instanceof stream.errors.StreamApiError)) {
return fallbackErrorMessage(error, type, detail);
}
const response = error.response;
if (!response.statusCode || !response.body || !response.body.detail) {
return fallbackErrorMessage(error, type, detail);
}
const statusCode = response.statusCode;
const text = response.body.detail;
if (statusCode >= 400 && statusCode < 500) {
return text;
} else if (statusCode >= 500 && statusCode < 600) {
return text;
}
export function getStreamClient() {
let client = stream.connect(
process.env.API_KEY,
process.env.API_SECRET,
process.env.APP_ID,
)
return client
}
constructor(props: StreamAppProps) {
super(props);
const client: StreamClient = stream.connect(
this.props.apiKey,
this.props.token,
this.props.appId,
this.props.options || {},
);
let analyticsClient;
if (this.props.analyticsToken) {
analyticsClient = new StreamAnalytics({
apiKey: this.props.apiKey,
token: this.props.analyticsToken,
});
analyticsClient.setUser(client.userId);
}
this.state = {
client,