New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@iguilhermeluis/sharepoint-orm-mod

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iguilhermeluis/sharepoint-orm-mod

Lib to consume sharepoint using axios

  • 1.3.12
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

Sharepoint ORM

npm version npm downloads Dependencies Status Dev dependencies Status

Install 🚀

# NPM
npm install --save @jorgejr568/sharepoint-orm

# Yarn
yarn add @jorgejr568/sharepoint-orm

Config 🔨

Create an plugins/sharepoint-orm.js file to place your configuration. We'll export two factories, creating our Auth and Builder services.

import { AuthFactory, BuilderFactory} from '@jorgejr568/sharepoint-orm'

const config = {
  apiUrl: process.env.API_URL,
  spUrl: process.env.SHAREPOINT_URL,
  tokenApi: process.env.API_TOKEN,
  application: process.env.APP_NAME, //'[uppercase and only letters portal name]',
  environment: process.env.APP_ENVIRONMENT //'DEV or PRD'
}

export const spAuth = AuthFactory(config)
export const spBuilder = BuilderFactory(config)

Authorization 🚪

import { spAuth } from '@/plugins/sharepoint-orm'

// sync
spAuth
  .authorize()
  .then(token => {
    // Token is automatically stored on spAuth
    console.log({ token })
    spAuth.current().then(user => {
      // Get current sharepoint user
      console.log({ user })
    })
  })
  .catch(e => {
    // Authorization error
    console.error({ e })    
  })

// async
try{
  const token = await spAuth.authorize()
  console.log({ token })
  
  const user = await spAuth.current()
  console.log({ user })
}
catch(e){
  console.error({ e })    
}

Refresh token 🔃

import { spAuth } from '@/plugins/sharepoint-orm'

try{
  const token = await spAuth.authorize()
  console.log({ token })
  setInterval(async () => {
    const newToken = await spAuth.refreshToken()
    // Token is automatically updated on spAuth
    console.log({ newToken })
  }, 2 * 60 * 1000) // Each 2 minutes
}
catch(e){
    // Authorization error
    console.error({ e })    
}

Querying 🎯

Simple select

import { spAuth, spBuilder } from '@/plugins/sharepoint-orm'

await spAuth.authorize()
const items = await spBuilder.table('ListName').select('*').get()
console.log({ items })
Available select methods
  • where
import { spAuth, spBuilder } from '@/plugins/sharepoint-orm'

await spAuth.authorize()
const items = await spBuilder
  .table('ListName')
  .select('*')
  .where('Id', 'eq', 1)
  .get()
console.log({ items })

// And condition

const items = await spBuilder
  .table('ListName')
  .select('*')
  .where('Id', 'eq', 1)
  .where('Title', 'eq', 'Player name')
  .get()
console.log({ items })
  • orWhere
import { spAuth, spBuilder } from '@/plugins/sharepoint-orm'

await spAuth.authorize()
const items = await spBuilder
  .table('ListName')
  .select('*')
  .where('Id', 'eq', 1)
  .orWhere('Id', 'eq', 2)
  .get()
console.log({ items })
  • whereNot
import { spAuth, spBuilder } from '@/plugins/sharepoint-orm'

await spAuth.authorize()
const items = await spBuilder
  .table('ListName')
  .select('*')
  .whereNot('Id', 'eq', 1)
  .get()
console.log({ items })
  • orWhereNot
import { spAuth, spBuilder } from '@/plugins/sharepoint-orm'

await spAuth.authorize()
const items = await spBuilder
  .table('ListName')
  .select('*')
  .whereNot('Id', 'eq', 1)
  .orWhereNot('Title', 'eq', 'Player name')
  .get()
console.log({ items })
  • whereRaw
import { spAuth, spBuilder } from '@/plugins/sharepoint-orm'

await spAuth.authorize()
const items = await spBuilder
  .table('ListName')
  .select('*')
  .whereRaw('Id eq 1')
  .get()
console.log({ items })
  • orWhereRaw
import { spAuth, spBuilder } from '@/plugins/sharepoint-orm'

await spAuth.authorize()
const items = await spBuilder
  .table('ListName')
  .select('*')
  .whereRaw('Id eq 1')
  .orWhereRaw(`Title eq 'Player name'`)
  .get()
console.log({ items })

Available leaf methods

  • get
// List all items
import { spAuth, spBuilder } from '@/plugins/sharepoint-orm'

await spAuth.authorize()
const items = await spBuilder.table('ListName').select('*').get()
console.log({ items })
  • first
// Get only first item or undefined
import { spAuth, spBuilder } from '@/plugins/sharepoint-orm'

await spAuth.authorize()
const item = await spBuilder
  .table('ListName')
  .select('*')
  .where('Id', 'eq', 1)
  .first()
console.log({ item })
  • insertGetId
import { spAuth, spBuilder } from '@/plugins/sharepoint-orm'

await spAuth.authorize()
const insertedId = await spBuilder
  .table('ListName')
  .insertGetId({
    Title: 'Player name'
  })
console.log({ insertedId })
  • update -> Must pass a where condition with id column
import { spAuth, spBuilder } from '@/plugins/sharepoint-orm'

await spAuth.authorize()
// Void return
await spBuilder
  .table('ListName')
  .where('Id', 'eq', 1)
  .update({
    Title: 'New player name'
  })
  • delete -> Must pass a where condition with id column
import { spAuth, spBuilder } from '@/plugins/sharepoint-orm'

await spAuth.authorize()
// Void return
await spBuilder
  .table('ListName')
  .where('Id', 'eq', 1)
  .delete()

Keywords

FAQs

Package last updated on 19 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc