Skip to content

Commit

Permalink
Reverted version from 2.1 to 2.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
gunjandatta committed Dec 13, 2024
1 parent 2196853 commit 5947218
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 27 deletions.
4 changes: 2 additions & 2 deletions @types/v2/drive.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ITargetInfoProps } from "../utils";

/**
* #### REST API
* _api/v2.1/drive
* _api/v2.0/drive
*
* #### Get the default library for a site.
*
Expand All @@ -20,7 +20,7 @@ export const drive: Idrive;

/**
* Drive
* The v2.1 REST endpoint.
* The v2.0 REST endpoint.
* @category Drive
*/
export interface Idrive {
Expand Down
4 changes: 2 additions & 2 deletions @types/v2/drives.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ITargetInfoProps } from "../utils";

/**
* #### REST API
* _api/v2.1/drives
* _api/v2.0/drives
*
* #### Get the libraries for a site.
*
Expand All @@ -20,7 +20,7 @@ export const drives: Idrives;

/**
* Drives
* The v2.1 REST endpoint.
* The v2.0 REST endpoint.
* @category Drives
*/
export interface Idrives {
Expand Down
4 changes: 2 additions & 2 deletions @types/v2/sites.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ITargetInfoProps } from "../utils";

/**
* #### REST API
* _api/v2.1/sites
* _api/v2.0/sites
*
* #### Get the current site
*
Expand Down Expand Up @@ -45,7 +45,7 @@ export interface IsiteIdResult {

/**
* Sites
* The v2.1 REST endpoint.
* The v2.0 REST endpoint.
* @category Sites
*/
export interface Isites {
Expand Down
12 changes: 6 additions & 6 deletions dist/gd-sprest.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4443,7 +4443,7 @@ declare module 'gd-sprest/v2/drive' {

/**
* #### REST API
* _api/v2.1/drive
* _api/v2.0/drive
*
* #### Get the default library for a site.
*
Expand All @@ -4459,7 +4459,7 @@ declare module 'gd-sprest/v2/drive' {

/**
* Drive
* The v2.1 REST endpoint.
* The v2.0 REST endpoint.
* @category Drive
*/
export interface Idrive {
Expand All @@ -4479,7 +4479,7 @@ declare module 'gd-sprest/v2/drives' {

/**
* #### REST API
* _api/v2.1/drives
* _api/v2.0/drives
*
* #### Get the libraries for a site.
*
Expand All @@ -4495,7 +4495,7 @@ declare module 'gd-sprest/v2/drives' {

/**
* Drives
* The v2.1 REST endpoint.
* The v2.0 REST endpoint.
* @category Drives
*/
export interface Idrives {
Expand All @@ -4520,7 +4520,7 @@ declare module 'gd-sprest/v2/sites' {

/**
* #### REST API
* _api/v2.1/sites
* _api/v2.0/sites
*
* #### Get the current site
*
Expand Down Expand Up @@ -4558,7 +4558,7 @@ declare module 'gd-sprest/v2/sites' {

/**
* Sites
* The v2.1 REST endpoint.
* The v2.0 REST endpoint.
* @category Sites
*/
export interface Isites {
Expand Down
2 changes: 1 addition & 1 deletion dist/gd-sprest.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/gd-sprest.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gd-sprest",
"version": "8.6.2",
"version": "8.6.3",
"description": "An easy way to develop against the SharePoint REST API.",
"author": "Gunjan Datta <[email protected]> (https://gunjandatta.github.io)",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IREST } from "../@types";
* SharePoint REST Library
*/
export const $REST: IREST = {
__ver: 8.62,
__ver: 8.63,
AppContext: (siteUrl: string) => { return Lib.Site.getAppContext(siteUrl); },
Apps: Lib.Apps,
ContextInfo: Lib.ContextInfo,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ export const Helper: IBaseHelper = {
if (obj["@odata.context"]) {
// Get the object type
let metadataType = (obj["@odata.context"] || objType);
let values = metadataType.split("_api/v2.1/$metadata#");
let values = metadataType.split("_api/v2.0/$metadata#");
if (values.length > 1) {
objType = values[1];
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const Request = {

// Get the object type
let objType = metadata && metadata.type ? metadata.type : obj.targetInfo.endpoint;
let isV2 = obj?.parent?.targetInfo?.endpoint.startsWith("_api/v2.1/") ||
let isV2 = obj?.parent?.targetInfo?.endpoint.startsWith("_api/v2.0/") ||
obj["@odata.context"] || objType.startsWith("@odata.context") ? true : false;
if (isV2) {
// See if we are overriding the object type
Expand All @@ -34,7 +34,7 @@ export const Request = {
} else {
// Get the object type from the context
let metadataType = (obj["@odata.context"] || objType);
let values = metadataType.split("_api/v2.1/$metadata#");
let values = metadataType.split("_api/v2.0/$metadata#");
if (values.length > 1) {
objType = values[1];
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/targetInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class TargetInfo implements ITargetInfo {

// Flag to determine if this is a graph request
get isGraph(): boolean {
return this.props.endpoint?.startsWith("_api/v2.1/") ||
return this.props.endpoint?.startsWith("_api/v2.0/") ||
this.props.requestType == RequestType.GraphGet || this.props.requestType == RequestType.GraphPost ||
this.props.requestType == RequestType.GraphGetReplace || this.props.requestType == RequestType.GraphPostReplace;
}
Expand Down
4 changes: 2 additions & 2 deletions src/v2/drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export const drive: Idrive = ((props: { siteId?: string, siteUrl?: string, targe
// See if an endpoint is not defined
if (drive.targetInfo.endpoint == undefined) {
// Default the endpoint
drive.targetInfo.endpoint = `_api/v2.1/${props.siteId ? "sites/" + props.siteId.replace(/[{}]/g, '') : ""}drive`;
drive.targetInfo.endpoint = `_api/v2.0/${props.siteId ? "sites/" + props.siteId.replace(/[{}]/g, '') : ""}drive`;

// Add the methods
Request.addMethods(drive, { __metadata: { type: "@odata.context/_api/v2.1/$metadata#drive" } });
Request.addMethods(drive, { __metadata: { type: "@odata.context/_api/v2.0/$metadata#drive" } });
}

// Return the default library
Expand Down
6 changes: 3 additions & 3 deletions src/v2/drives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ export const drives: Idrives = ((props: { driveId?: string, siteId?: string, sit
// See if an endpoint is not defined
if (drives.targetInfo.endpoint == undefined) {
// Default the endpoint
drives.targetInfo.endpoint = `_api/v2.1/${props.siteId ? "sites/" + props.siteId.replace(/[{}]/g, '') : ""}drives`;
drives.targetInfo.endpoint = `_api/v2.0/${props.siteId ? "sites/" + props.siteId.replace(/[{}]/g, '') : ""}drives`;

// See if the drive id was provided
if (props.driveId) {
// Append the id
drives.targetInfo.endpoint += "/" + props.driveId;

// Add the methods
Request.addMethods(drives, { __metadata: { type: "@odata.context/_api/v2.1/$metadata#drive" } });
Request.addMethods(drives, { __metadata: { type: "@odata.context/_api/v2.0/$metadata#drive" } });
} else {
// Add the methods
Request.addMethods(drives, { __metadata: { type: "@odata.context/_api/v2.1/$metadata#drives" } });
Request.addMethods(drives, { __metadata: { type: "@odata.context/_api/v2.0/$metadata#drives" } });
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/v2/sites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const sites: Isites = ((props: { siteId?: string, webId?: string, targetI

// Default the properties
sites.targetInfo.defaultToWebFl = true;
sites.targetInfo.endpoint = "_api/v2.1/sites" + (props.siteId ? "/" + props.siteId : "");
sites.targetInfo.endpoint = "_api/v2.0/sites" + (props.siteId ? "/" + props.siteId : "");
sites.targetInfo.requestType = RequestType.GraphGet;

// See if the site id was provided
Expand All @@ -34,7 +34,7 @@ export const sites: Isites = ((props: { siteId?: string, webId?: string, targetI
}

// Add the methods
Request.addMethods(sites, { __metadata: { type: "@odata.context/_api/v2.1/$metadata#sites" } });
Request.addMethods(sites, { __metadata: { type: "@odata.context/_api/v2.0/$metadata#sites" } });

// Return the sites
return sites;
Expand Down
4 changes: 4 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ v2.sites.getList({}).then(l => {
l.items(3).setSensitivityLabel({}).execute();
})

v2.sites({ targetInfo: { url: "" } }).query({ Search: "*"}).execute(s => {
s.siteCollection.root;
});
v2.sites.getCurrentSite();
v2.sites.getCurrentWeb();
v2.sites.getList({ listName: "Test" }).then(list => {
list.items.add({}).execute();
Expand Down

0 comments on commit 5947218

Please sign in to comment.