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

@goldenhippo/gh-surveys

v0.0.46

Published

Initial survey package for Golden Hippo

Downloads

2,614

Readme

Golden Hippo Surveys

Table of Contents

Installation

npm i @goldenhippo/gh-surveys

This package requires that you have an instance of the GH Survey API deployed with a publicly accessible URL.

Usage

SurveyAPI

Import the SurveyAPI class from the package and instantiate it with a connection string to a deployed API. The connection string should be in the format of https://surveyapi.herokuapp.com (or whatever the deployed API URL is).

Note: There should be no slash at the end of the URL.

import { SurveyAPI } from "@goldenhippo/gh-surveys";

const surveyAPI = new SurveyAPI(
  "https://surveyapi.herokuapp.com"
);

SurveyAPI Methods

The SurveyAPI class has the following methods:

  • retrieve(sessionId: string) - Retrieves all responses for a given session ID. Returns a Promise that resolves to an array of SurveyRetrievalResponse objects.
  • ensureTableExists(create: boolean = false) - Confirms that the survey_responses table exists in the database. If it does not exist, the create parameter can be passed to create the table. Returns a Promise that resolves to a boolean indicating whether the table exists. This process should only be run on application startup because it is an expensive operation.
  • submitToDB(surveyResponse: SurveyResponse) - Submits a SurveyResponse object to the database. Returns a Promise that resolves to a SurveySubmitResponse object.

SurveyAPI Usage

import { SurveyAPI } from "@goldenhippo/gh-surveys";

const surveyAPI = new SurveyConnection(
  "https://surveyapi.herokuapp.com"
);

const responses = surveyAPI.retrieve("1234")
  .then((sessionResponses) => {
      console.log(sessionResponses);
      //Find the age response
      const ageResponse = sessionResponses.find(response => response instanceof SurveyResponse.Age)
      if(ageResponse) {
      const ageSelection = ageResponse.answer
      //Do something based on the answer which will be one of the enum options
    }
  })

const tableExists = await surveyAPI.ensureTableExists(); // Validate that table exists, but do not create it if it does not.
console.log(tableExists);

const tableExistsWithCreate = await surveyAPI.ensureTableExists(true); // Validate that table exists, and create it if it does not.
console.log(tableExistsWithCreate);

SurveyResponse

The SurveyResponse class is an abstract class that should be extended to create a response for a specific survey question type. The created object can then be submitted to the database using the SurveyAPI.submitToDB method and returns a promise that resolves to a SurveySubmitResponse object.

The response object has the following structure:

{
  success: boolean,
  response: {
    answer: string,
    sessionId: string,
    questionType: string
  } | null
}
import { SurveyAPI, SurveyResponse } from "@goldenhippo/gh-surveys";

const surveyAPI = new SurveyAPI(
  "https://surveyapi.herokuapp.com"
);

const ageResponse = new SurveyResponse.Age({
  question: "How old are you?",
  rawAnswer: "21",
  answer: "AGE_18_24",
  sessionId: "1234",
});
const ageSubmission = apiConnection.submitToDB(ageResponse)
.then((response) => {
  console.log(response);
  /*
   {
      success: true,
      response: {
        answer: "AGE_18_24",
        sessionId: "1234",
        questionType: "AGE"
      }
   }
   */
}

Question Types

The SurveyResponse class allows you to create responses for the following question types:

  • Age
  • Gender
  • DigestiveIssue
  • IssueAge
  • BowelMovementWeekly
  • SolutionDifficulty

Note: To view the available questions and answers, you can access the configuration file from your API URL at /config. For example, https://yourapi.herokuapp.com/config.

Answers

Each of the question types has a set of possible answers. The answers are defined as static properties on the class. For example, the SurveyResponse.Gender class has the following possible answers:

  • MALE
  • FEMALE
  • NON_BINARY
  • DECLINE_TO_ANSWER

Note: To view the available questions and answers, you can access the configuration file from your API URL at /config. For example, https://yourapi.herokuapp.com/config.