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

sp-typed-item

v0.1.0

Published

Generates TypeScript interfaces based on your SharePoint lists

Downloads

7

Readme

SharePoint Typed Item

Version npm version

Node.js module, CLI and VSCode extension for generating TypeScript interfaces based on SharePoint data.

How it works

  1. You should provide a configuration file, which describes your target site url, lists and content types you want to generate interfaces for.
  2. Run the generation process.
  3. Consume generated interfaces in your project, which deals with SharePoint REST API and list items data.

Checkout how it works in action using VSCode extension:

in action

How to use:

VSCode

Checkout VSCode extension home page

CLI

  1. Run $ npm install sp-typed-item -g
  2. Generate a file with your authentication details. sp-typed-item CLI understands format, used by node-sp-auth-config module and supports the same set of authentication options. Generate authentication file with node-sp-auth-config CLI: $ sp-auth init --path auth.private.json. Refer to node-sp-auth-config home page for usage details.
  3. Create configuration file sp-typed-item.json. Read about configuration file format further.
  4. Run $ sp-item render --config path-to-sp-typed-item-config.json

Node.js

  1. Run $ npm install sp-typed-item --save[-dev]
  2. import { SPTypedItem, Config } from 'sp-typed-item';
    
    let config: Config[] = require(path.resolve('path-to-sp-typed-item-config.json'));
    
    await SPTypedItem.renderFiles(config[0]);

Configuration file

sp-typed-item configuration file holds essential information about environment and interface generation settings.

Example file with all possible settings:

[
  {
    "siteUrl":"https://contoso.sharepoint.com/sites/dev",
    "authConfigPath":"./config/auth.json",
    "outputPath":"./Generated",
    "lists":[
      {
        "url":"Lists/Clients",
        "fileName":"IClientItems",
        "fields":{
          "exclude":[
            "Title",
            "FieldInternalName"
          ],
          "excludeHidden":true
        }
      }
    ],
    "contentTypes":[
      {
        "id":"0x01005207A2B9B939CE43AB38D848E245926B",
        "fileName":"IArchiveItems",
        "fields":{
          "exclude":[
            "Title",
            "FieldInternalName"
          ],
          "excludeHidden":true
        }
      }
    ]
  }
]

Root element

Array of configuration items. Currently CLI and VSCode extension support only one configuration element. Multiple elements support might come in future.

Configuration item

siteUrl - required, full url to your target SharePoint site

authConfigPath - path to your json authentication details file. It's not required for VSCode extension, because VSCode extension handles it for you. This setting contains a path to your node-sp-auth-config json file.

outputPath - required, path to a folder, where all interfaces will be generated.

lists - this node describes all lists, which should be included in generation process. Either lists or contentTypes node should be provided. Array of configuration items:

  • url - required, list url relative to a web, i.e. Lists/MyList, not sites/mysite/Lists/MyList
  • filename - you can provide custom file name (and interface name) for your list. Each list entry corresponds to one output interface file
  • fields - optional, you can filter out some unnecessary fields:
    • excludeHidden - optional, specify to filter out all hidden fields
    • exclude - optional array, the list of fields to be excluded by internal name

contentTypes - describes all content types to be included in generation process. Either lists or contentTypes node should be provided. Array of configuration items:

  • id - required, content type id
  • the rest of parameters are the same as for list, i.e. fileName, fields.

Minimal working configuration file:

[
  {
    "siteUrl":"https://contoso.sharepoint.com/sites/dev",
    "authConfigPath":"./config/auth.json",
    "outputPath":"./Generated",
    "lists":[
      {
        "url":"Lists/Clients"
      }
    ]
  }
]

NOTE: for VSCode extension authConfigPath is not required.