{"id":21655946,"url":"https://github.com/koltyakov/sppurge","last_synced_at":"2025-04-11T21:32:57.598Z","repository":{"id":14406973,"uuid":"76486262","full_name":"koltyakov/sppurge","owner":"koltyakov","description":"Delete files from SharePoint document libraries using Node.js without hassles","archived":false,"fork":false,"pushed_at":"2023-03-04T02:43:16.000Z","size":848,"stargazers_count":9,"open_issues_count":5,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T10:11:31.177Z","etag":null,"topics":["delete","developer-tools","javascript","nodejs","sharepoint","sharepoint-online","tasks"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koltyakov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-14T18:31:49.000Z","updated_at":"2021-10-06T17:39:33.000Z","dependencies_parsed_at":"2024-06-20T00:07:34.921Z","dependency_job_id":"e4484f87-c497-473b-86e5-ac38b8ab7322","html_url":"https://github.com/koltyakov/sppurge","commit_stats":{"total_commits":60,"total_committers":7,"mean_commits":8.571428571428571,"dds":0.6833333333333333,"last_synced_commit":"1e72f902336aa02bef91417939468f5533910180"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koltyakov%2Fsppurge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koltyakov%2Fsppurge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koltyakov%2Fsppurge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koltyakov%2Fsppurge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koltyakov","download_url":"https://codeload.github.com/koltyakov/sppurge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248482886,"owners_count":21111400,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["delete","developer-tools","javascript","nodejs","sharepoint","sharepoint-online","tasks"],"created_at":"2024-11-25T08:37:53.476Z","updated_at":"2025-04-11T21:32:57.564Z","avatar_url":"https://github.com/koltyakov.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SPPurge - simple client to delete files from SharePoint document libraries\n\n[![NPM](https://nodei.co/npm/sppurge.png?mini=true\u0026downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/sppurge/)\n\n[![npm version](https://badge.fury.io/js/sppurge.svg)](https://badge.fury.io/js/sppurge)\n[![Downloads](https://img.shields.io/npm/dm/sppurge.svg)](https://www.npmjs.com/package/sppurge)\n![Build Status](https://koltyakov.visualstudio.com/SPNode/_apis/build/status/sppurge?branchName=master)\n[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/sharepoint-node/Lobby)\n\nNode.js module for file deletion from SharePoint document libraries.\n\n## Supported SharePoint versions\n\n- SharePoint Online\n- SharePoint On-Prem (2019, 2016, 2013)\n\n## How to use\n\n### Install\n\n```bash\nnpm install sppurge --save-dev\n```\n\n### Usage\n\n```javascript\nconst sppurge = require('sppurge').default;\n\nconst context = {/*...*/};\nconst options = {/*...*/};\n\nsppurge(context, options)\n  .then(successHandler)\n  .catch(errorHandler);\n```\n\n#### Arguments\n\n##### Context\n\n- `siteUrl` - SharePoint site (SPWeb) url [string, **required**]\n- `creds`\n  - `username` - user name for SP authentication [string, optional in case of some auth methods]\n  - `password` - password [string, optional in case of some auth methods]\n\n**Additional authentication options:**\n\nSince SP client (sp-request), which is used in sppurge, had received additional SharePoint authentication methods, they are also supported in sppurge.\n\nFor more information please check node-sp-auth [credential options](https://github.com/s-KaiNet/node-sp-auth#params) and [wiki pages](https://github.com/s-KaiNet/node-sp-auth/wiki).\n\n##### Options\n\n- `folder` - relative folder in SharePoint to concat with filePath [string, optional, default: `` (empty string)]\n- `filePath` - relative file path, with extention [string, required in general, optional if `localFilePath` and `localBasePath` are both provided]\n- `localFilePath` - local full path to file [string, optional]\n- `localBasePath` - relative folder base path within project directory [string, optional]\n\nThe result file path is formed based on the following rule:\n\n- `siteUrl` + `folder` + `filePath`\n- If `filePath` is empty, then:\n  - `filePath` = path.resolve(localFilePath).replace(path.resolve(localBasePath), '')\n\n#### successHandler\n\nThe callback gets called upon successful file deletion.\n\n#### errorHandler\n\nThe callback gets executed in case of an exception inside `sppurge`. Accepts error object as first argument for callback.\n\n### Basic usage example (delete a single file)\n\n```javascript\nconst sppurge = require('sppurge').default;\n\nconst context = { /* auth context */ };\n\nconst options = {\n  folder: '/_catalogs/masterpage/spf/module_name',\n  filePath: '/scripts/dummy-file.js'\n};\n\nsppurge(context, options)\n  .then(deletionResults =\u003e {\n    console.log('A file has been deleted');\n  })\n  .catch(err =\u003e {\n    console.log('Core error has happened', err);\n  });\n```\n\n### Basic usage example (delete a folder)\n\n```javascript\nconst { Delete } = require('sppurge');\n\nconst context = { /* auth context */ };\nconst sppurge = new Delete();\n\nsppurge.deleteFolder(context, '/sites/site/folder/repative/path')\n  .then(deletionResults =\u003e {\n    console.log('A folder has been deleted');\n  })\n  .catch(err =\u003e {\n    console.log('Core error has happened', err);\n  });\n```\n\n### Within Gulp task\n\n```javascript\nconst gulp = require('gulp');\nconst watch = require('gulp-watch');      // Allows more than gulp.watch, is recommended\nconst spsave = require('gulp-spsave');    // Optional SPSave, but what is the reason to use SPPurge without SPSave?\nconst sppurge = require('sppurge').default;\nconst path = require('path');\n\nconst config = require('./gulp.config'); // Getting settings for SPPurge and SPSave\n\ngulp.task('watch-assets', () =\u003e {\n  return watch(config.watch.assets, function (event) {\n    // Base local folder path, e.g. 'src' from which\n    // project's files are mapped to SharePoint folder\n    const watchBase = config.watch.base;\n\n    // When file is deleted event value is \"unlink\"\n    if (event.event === 'unlink') {\n      const sppurgeOptions = {\n        folder: config.sppurge.options.spRootFolder,\n        filePath: path.resolve(event.path).replace(path.resolve(watchBase), '')\n      };\n      // OR:\n      // const sppurgeOptions = {\n      //   folder: config.sppurge.options.spRootFolder,\n      //   localFilePath: event.path,\n      //   localBasePath: watchBase\n      // };\n      sppurge(config.sppurge.context, sppurgeOptions)\n        .then((res) =\u003e console.log(`File has been deleted: ${res}`))\n        .catch((err) =\u003e console.log('Error', err));\n    } else {\n      // Saving files to SharePoint\n      gulp.src(event.path, {\n        base: watchBase\n      }).pipe(\n        spsave(\n          // SPSave's core options, see more in spsave documentation\n          config.spsave.coreOptions,\n          // node-sp-auth / spsave credential object\n          config.spsave.creds\n        )\n      );\n    }\n  });\n});\n```\n\n### Create React App usage scenario\n\n\u003e Delete JS's build folder then upload all files from/build folder\n\nOne of the architectural decisions in CRA is using hashes as a part of assets filenames. This allows avoiding issues related to browser cache. However, it can be challenging in terms of deployment to SharePoint assets folders, as all filenames are different on each build. The further sample shows a simple use case approach of deleting files based on folder and name pattern.\n\n```javascript\nconst { AuthConfig } = require('node-sp-auth-config');\nconst sppurge = require('sppurge').default;\nconst spsave = require('spsave').spsave;\n\n// client-side project's assets destination folder\nconst targetFolder = '_catalogs/masterpage/assets/cra-project';\n\nconst authConfig = new AuthConfig({\n  configPath: './config/private.json',\n  encryptPassword: true,\n  saveConfigOnDisk: true\n});\n\nauthConfig.getContext().then(({ siteUrl, authOptions: creds }) =\u003e {\n\n  const deleteOptions = {\n    folder: `${targetFolder}/static/js`,\n    fileRegExp: new RegExp('(.*)/(.*)\\.(js|map)', 'i'), // include .js, .map to delete\n    // filePath: 'SiteAssets/trash.txt' // for single file deletion\n  };\n\n  const spsaveCoreOptions = {\n    siteUrl,\n    notification: true,\n    checkin: true,\n    checkinType: 2 // 0=minor, 1=major, 2=overwrite\n  };\n\n  const spsaveFileOptions = {\n    glob: [ 'build/**/*.*' ],\n    base: 'build',\n    folder: targetFolder\n  };\n\n  return sppurge({ siteUrl, creds }, deleteOptions)\n    .then(_ =\u003e console.log('=== Files Deleted ==='));\n    .then(_ =\u003e spsave(spsaveCoreOptions, creds, spsaveFileOptions))\n    .then(_ =\u003e console.log('=== Files Uploaded ==='));\n\n}).catch(console.warn);\n```\n\n### Passwords storage\n\nTo eliminate any local password storing if preferable to use any two-way hashing technique, like [cpass](https://github.com/koltyakov/cpass).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoltyakov%2Fsppurge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoltyakov%2Fsppurge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoltyakov%2Fsppurge/lists"}