npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wix/wix-groups-feed-client

v1.9.0

Published

Client library for Wix Groups Feed API to create, read, update, and delete feed items in Wix Groups.

Downloads

85

Readme

Client library for Wix Groups Feed API to create, read, update, and delete feed items in Wix Groups.

Usage

import {WixGroupsFeedService} from 'wix-groups-feed-client';

const authorization = 'value-auth-token-here'
const siteId = 'site-id-here'
const client = new WixGroupsFeedService(authorization, siteId);

try {
  const posts = await client.listFeedItems("<group_id>");
} catch (e) {
  console.log('Error with code: ', e.errorCode);
}

Authorization

The client library requires an authorization header to be passed to the constructor. Check Wix Api Keys and Api Keys support article which explains how to create it.

Important: The API token should be created with Wix Groups site permissions enabled (in Wix, you may choose apps and permissions for the token; make sure you select Wix Communities or Wix Groups).

The token should look like:

IST.eyJraWQiOiJQb3pIX2FDMiIsImFsZyI6IlJTMjU2In0.eyJkYXRh....RERER

Debug mode

To enable debug mode, specify the debugMode option in the constructor:

const client = new WixGroupsFeedService(authorization, siteId, {debugMode: true});

In a debug mode, the client library will log all requests and responses to the console.

API Overview

Feed Items

Each feed item could be a post about some group activity (created automatically by the system) or a Rich Content post made by a user (paid or not).

FeedItem object has the following fields:

  • feedItemId - the id of the feed item
  • entity - the entity of the feed item (returned only for user-created posts).
    • The format of user-created posts could be plain text, draft-js (deprecated), and a new format called RICH_CONTENT. You can read more about the new format on Ricos site.
  • activity - describes the activity of the feed item (returned only for activity posts). Examples of activity posts: group description has been changed, group name has been changed, group member has been added, etc.
  • preview - a preview for the paid posts. Returned if the user has no permission to view the full post.
  • pin - describes the pin status of the feed item. The pin object has the following fields:
    • pinnedBy - user who pinned the post
    • since - the date when the post was pinned
  • permissions - describes the current user's permissions on the feed item. The permissions object has the following fields:
    • canViewFullPost - user can view the full post
    • ``canAssignTopic` - user can assign a topic to the post
    • canUnassignTopic - user can unassign a topic from the post
    • canUpdate - user can update the post
    • canDelete - user can delete the post
    • canShare - user can share the post (always set to true based on current implementation)
    • canAddComment - user can add a comment to the post
    • canReact - user can add a reaction to the post
    • canPin - user can pin the post
  • createdBy - the id of the user who created the feed item
  • createdAt - the date when the feed item was created
  • requesterContext - describes the context of the user who requested the feed item. The requester context object has the following fields:
    • subscribed - whether the user is subscribed to the feed item

Additional Permissions

For list/query methods, the response contains a FeedPermissions object that describes actions for all posts or actions that are not specific to a single post. It has the following fields:

  • canViewPosts - user can view the posts at all
  • canCreatePosts - user can create a post
  • canCreatePaidPosts - user can create a paid post
  • canPinPost - user can pin a posts
  • canCreateTopic - user can create a new topic
  • canFollowPosts - user can follow posts

API Reference

Examples below show how to use the client library from Velo.

It's also possible to use the client library in any other environment that supports JavaScript.

createFeedItem(groupId: string)

Creates a feed item in the group feed.

Request example:

In example below we create a feed item with a DraftJS content.

export const createFeedItem = webMethod(
  Permissions.Anyone, 
  async (groupId) => {
    try {
      const content = {
        "blocks": [{
            "key": "au2sn",
            "text": "<TEXT>",
            "type": "unstyled",
            "depth": 0,
            "inlineStyleRanges": [{
                "offset": 0,
                "length": 4,
                "style": "BOLD"
            }],
            "entityRanges": [],
            "data": {}
        }],
        "entityMap": {},
        "documentStyle": {},
        "VERSION": "9.14.6",
        "ID": "94ca0800-9063-4d5b-9746-92501a34859a"
    }

      const post = await client.createFeedItem(groupId, {
        body: {
          contentType: 'DRAFTJS',
          content: JSON.stringify(content)
        }
      });
      return post;
    } catch (e) {
      console.log('Error with code: ', e);
    } 
  }
);

listFeedItems(groupId: string)

Get a list of feed items by group id.

Request example:
const authorization = '<value-auth-token-here>'
const client = new WixGroupsFeedService(authorization, '<site-id-here>', {debugMode: false});

export const listFeedItems = webMethod(
  Permissions.Anyone, // make sure to update permissions if needed
  async (groupId) => {
    try {
      const posts = await client.listFeedItems(groupId);
      return posts;
    } catch (e) {
      console.log('Error with code: ', e);
    } 
  }
);
Response example:
{
   "feedItems":[
      {
         "feedItemId":"c80bd29d-91ea-4253-a839-79de53469f2e",
         "entity":{
            "body":{
               "contentType":"DRAFTJS",
               "content":"{\"blocks\":[{\"key\":\"1\",\"text\":\"Welcome to our group My Site Group! A space for us to connect and share with each other. Start by posting your thoughts, sharing media, or creating a poll.\",\"type\":\"unstyled\",\"depth\":0,\"inlineStyleRanges\":[{\"offset\":21,\"length\":16,\"style\":\"BOLD\"}],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}}"
            }
         },
         "createdBy":"fc2258d5-a366-4b9c-a93f-1f344f14493f",
         "createdAt":"2024-03-13T12:25:30.822232258Z",
         "requesterContext":{
            "subscribed":false
         }
         "permissions":{
            "canViewFullPost":true,
            "canAssignTopic":false,
            "canUnassignTopic":false,
            "canUpdate":false,
            "canDelete":false,
            "canShare":true,
            "canAddComment":false,
            "canReact":false,
            "canPin":false
         }
      }
   ],
   "permissions":{
      "canViewPosts":true,
      "canCreatePosts":false,
      "canPinPosts":false,
      "canCreateTopic":false,
      "canFollowPosts":false,
      "canCreatePaidPosts":false
   }
}

getFeedItem(groupId: string, feedItemId: string)

Returns a feed item by its id.

Request example:
const authorization = '<value-auth-token-here>'
const client = new WixGroupsFeedService(authorization, '<site-id-here>', {debugMode: false});

export const getFeeditem = webMethod(
    Permissions.Anyone, // make sure to update permissions if needed
  async (groupId, feedItemId) => {
    try {
      const post = await client.getFeedItem(groupId, feedItemId);
      return post;
    } catch (e) {
      console.log('Error with code: ', e);
    } 
  }
);
Response example:
{
  "feedItemId":"c80bd29d-91ea-4253-a839-79de53469f2e",
  "entity": {...},
  ...
}

deleteFeedItem(groupId: string, feedItemId: string)

Deletes a feed item by its id.

Returns a deleted feed item.

Request example:
const authorization = '<value-auth-token-here>'
const client = new WixGroupsFeedService(authorization, '<site-id-here>', {debugMode: false});

export const deleteFeedItem = webMethod(
  Permissions.Anyone, // make sure to update permissions if needed
  async (groupId, feedItemId) => {
    try {
      const post = await client.deleteFeedItem(groupId, feedItemId);
      return post; // returns deleted post
    } catch (e) {
      console.log('Error with code: ', e);
    } 
  }
);

updateFeedItem(groupId: string, feedItemId: string, entity: FeedItemEntity)

Updates a feed item by its id. It allows you to update the content of the post.

Returns an updated feed item.

Request example:
export const updateFeedItem = webMethod(
  Permissions.Anyone, 
  async (groupId, feedItemId) => {
    try {
      const content = {
        "blocks": [{
            "key": "au2sn",
            "text": "<UPDATED_TEXt>",
            "type": "unstyled",
            "depth": 0,
            "inlineStyleRanges": [{
                "offset": 0,
                "length": 4,
                "style": "BOLD"
            }],
            "entityRanges": [],
            "data": {}
        }],
        "entityMap": {},
        "documentStyle": {},
        "VERSION": "9.14.6",
        "ID": "94ca0800-9063-4d5b-9746-92501a34859a"
      }

      const post = await client.updateFeedItem(groupId, feedItemId,  {
        body: {
          contentType: 'DRAFTJS',
          content: JSON.stringify(content)
        }
      });
      return post;
    } catch (e) {
      console.log('Error with code: ', e);
    } 
  }
);