diff --git a/.gitignore b/.gitignore index f6a53fd7..815dc9e4 100644 --- a/.gitignore +++ b/.gitignore @@ -18,11 +18,21 @@ coverage # Dependency directory node_modules -# generated folders +# generated folders/files lib testing docs debugging +core.d.ts +core.js +graph.d.ts +graph.js +net.d.ts +net.js +odata.d.ts +odata.js +sp.d.ts +sp.js # Optional npm cache directory .npm diff --git a/.vscode/settings.json b/.vscode/settings.json index 660f965c..2383e1e5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,7 +8,16 @@ "coverage": true, "testing": true, "debugging": true, - "exports": true + "core.d.ts": true, + "core.js": true, + "graph.d.ts": true, + "graph.js": true, + "net.d.ts": true, + "net.js": true, + "odata.d.ts": true, + "odata.js": true, + "sp.d.ts": true, + "sp.js": true }, "typescript.tsdk": "node_modules/typescript/lib" } \ No newline at end of file diff --git a/assets/locale.ts b/assets/locale.ts deleted file mode 100644 index a149cf23..00000000 --- a/assets/locale.ts +++ /dev/null @@ -1,240 +0,0 @@ -export enum Locale { - AfrikaansSouthAfrica = 1078, - AlbanianAlbania = 1052, - Alsatian = 1156, - AmharicEthiopia = 1118, - ArabicSaudiArabia = 1025, - ArabicAlgeria = 5121, - ArabicBahrain = 15361, - ArabicEgypt = 3073, - ArabicIraq = 2049, - ArabicJordan = 11265, - ArabicKuwait = 13313, - ArabicLebanon = 12289, - ArabicLibya = 4097, - ArabicMorocco = 6145, - ArabicOman = 8193, - ArabicQatar = 16385, - ArabicSyria = 10241, - ArabicTunisia = 7169, - ArabicUAE = 14337, - ArabicYemen = 9217, - ArmenianArmenia = 1067, - Assamese = 1101, - AzeriCyrillic = 2092, - AzeriLatin = 1068, - Bashkir = 1133, - Basque = 1069, - Belarusian = 1059, - BengaliIndia = 1093, - BengaliBangladesh = 2117, - BosnianBosniaHerzegovina = 5146, - Breton = 1150, - Bulgarian = 1026, - Burmese = 1109, - Catalan = 1027, - CherokeeUnitedStates = 1116, - ChinesePeoplesRepublicofChina = 2052, - ChineseSingapore = 4100, - ChineseTaiwan = 1028, - ChineseHongKongSAR = 3076, - ChineseMacaoSAR = 5124, - Corsican = 1155, - Croatian = 1050, - CroatianBosniaHerzegovina = 4122, - Czech = 1029, - Danish = 1030, - Dari = 1164, - Divehi = 1125, - DutchNetherlands = 1043, - DutchBelgium = 2067, - Edo = 1126, - EnglishUnitedStates = 1033, - EnglishUnitedKingdom = 2057, - EnglishAustralia = 3081, - EnglishBelize = 10249, - EnglishCanada = 4105, - EnglishCaribbean = 9225, - EnglishHongKongSAR = 15369, - EnglishIndia = 16393, - EnglishIndonesia = 14345, - EnglishIreland = 6153, - EnglishJamaica = 8201, - EnglishMalaysia = 17417, - EnglishNewZealand = 5129, - EnglishPhilippines = 13321, - EnglishSingapore = 18441, - EnglishSouthAfrica = 7177, - EnglishTrinidad = 11273, - EnglishZimbabwe = 12297, - Estonian = 1061, - Faroese = 1080, - Farsi = 1065, - Filipino = 1124, - Finnish = 1035, - FrenchFrance = 1036, - FrenchBelgium = 2060, - FrenchCameroon = 11276, - FrenchCanada = 3084, - FrenchDemocraticRepofCongo = 9228, - FrenchCotedIvoire = 12300, - FrenchHaiti = 15372, - FrenchLuxembourg = 5132, - FrenchMali = 13324, - FrenchMonaco = 6156, - FrenchMorocco = 14348, - FrenchNorthAfrica = 58380, - FrenchReunion = 8204, - FrenchSenegal = 10252, - FrenchSwitzerland = 4108, - FrenchWestIndies = 7180, - FrisianNetherlands = 1122, - FulfuldeNigeria = 1127, - FYROMacedonian = 1071, - Galician = 1110, - Georgian = 1079, - GermanGermany = 1031, - GermanAustria = 3079, - GermanLiechtenstein = 5127, - GermanLuxembourg = 4103, - GermanSwitzerland = 2055, - Greek = 1032, - Greenlandic = 1135, - GuaraniParaguay = 1140, - Gujarati = 1095, - HausaNigeria = 1128, - HawaiianUnitedStates = 1141, - Hebrew = 1037, - Hindi = 1081, - Hungarian = 1038, - IbibioNigeria = 1129, - Icelandic = 1039, - IgboNigeria = 1136, - Indonesian = 1057, - Inuktitut = 1117, - Irish = 2108, - ItalianItaly = 1040, - ItalianSwitzerland = 2064, - Japanese = 1041, - Kiche = 1158, - Kannada = 1099, - KanuriNigeria = 1137, - Kashmiri = 2144, - KashmiriArabic = 1120, - Kazakh = 1087, - Khmer = 1107, - Kinyarwanda = 1159, - Konkani = 1111, - Korean = 1042, - KyrgyzCyrillic = 1088, - Lao = 1108, - Latin = 1142, - Latvian = 1062, - Lithuanian = 1063, - Luxembourgish = 1134, - MalayMalaysia = 1086, - MalayBruneiDarussalam = 2110, - Malayalam = 1100, - Maltese = 1082, - Manipuri = 1112, - MaoriNewZealand = 1153, - Mapudungun = 1146, - Marathi = 1102, - Mohawk = 1148, - MongolianCyrillic = 1104, - MongolianMongolian = 2128, - Nepali = 1121, - NepaliIndia = 2145, - NorwegianBokmÄl = 1044, - NorwegianNynorsk = 2068, - Occitan = 1154, - Oriya = 1096, - Oromo = 1138, - Papiamentu = 1145, - Pashto = 1123, - Polish = 1045, - PortugueseBrazil = 1046, - PortuguesePortugal = 2070, - Punjabi = 1094, - PunjabiPakistan = 2118, - QuechaBolivia = 1131, - QuechaEcuador = 2155, - QuechaPeru = 3179, - RhaetoRomanic = 1047, - Romanian = 1048, - RomanianMoldava = 2072, - Russian = 1049, - RussianMoldava = 2073, - SamiLappish = 1083, - Sanskrit = 1103, - ScottishGaelic = 1084, - Sepedi = 1132, - SerbianCyrillic = 3098, - SerbianLatin = 2074, - SindhiIndia = 1113, - SindhiPakistan = 2137, - SinhaleseSriLanka = 1115, - Slovak = 1051, - Slovenian = 1060, - Somali = 1143, - Sorbian = 1070, - SpanishSpainModernSort = 3082, - SpanishSpainTraditionalSort = 1034, - SpanishArgentina = 11274, - SpanishBolivia = 16394, - SpanishChile = 13322, - SpanishColombia = 9226, - SpanishCostaRica = 5130, - SpanishDominicanRepublic = 7178, - SpanishEcuador = 12298, - SpanishElSalvador = 17418, - SpanishGuatemala = 4106, - SpanishHonduras = 18442, - SpanishLatinAmerica = 22538, - SpanishMexico = 2058, - SpanishNicaragua = 19466, - SpanishPanama = 6154, - SpanishParaguay = 15370, - SpanishPeru = 10250, - SpanishPuertoRico = 20490, - SpanishUnitedStates = 21514, - SpanishUruguay = 14346, - SpanishVenezuela = 8202, - Sutu = 1072, - Swahili = 1089, - Swedish = 1053, - SwedishFinland = 2077, - Syriac = 1114, - Tajik = 1064, - TamazightArabic = 1119, - TamazightLatin = 2143, - Tamil = 1097, - Tatar = 1092, - Telugu = 1098, - Thai = 1054, - TibetanBhutan = 2129, - TibetanPeoplesRepublicofChina = 1105, - TigrignaEritrea = 2163, - TigrignaEthiopia = 1139, - Tsonga = 1073, - Tswana = 1074, - Turkish = 1055, - Turkmen = 1090, - UighurChina = 1152, - Ukrainian = 1058, - Urdu = 1056, - UrduIndia = 2080, - UzbekCyrillic = 2115, - UzbekLatin = 1091, - Venda = 1075, - Vietnamese = 1066, - Welsh = 1106, - Wolof = 1160, - Xhosa = 1076, - Yakut = 1157, - Yi = 1144, - Yiddish = 1085, - Yoruba = 1130, - Zulu = 1077, - HIDHumanInterfaceDevice = 1279, -} diff --git a/gulptasks/@configuration.js b/gulptasks/@configuration.js index 86501e4f..43a35ff6 100644 --- a/gulptasks/@configuration.js +++ b/gulptasks/@configuration.js @@ -30,7 +30,7 @@ module.exports = { paths: { dist: "./dist", lib: "./lib", - exports: "./exports", + exports: "./", source: "./src", sourceGlob: ["./src/**/*.ts", "!./src/exports/**/*.ts"], assetsGlob: "./assets/**/*.*", diff --git a/gulptasks/build.js b/gulptasks/build.js index 79fa2aa8..ca8e8dcd 100644 --- a/gulptasks/build.js +++ b/gulptasks/build.js @@ -36,8 +36,8 @@ gulp.task("build:exports", () => { .pipe(project()); return merge([ - built.dts.pipe(replace("../", "../lib/")).pipe(gulp.dest(config.paths.exports)), - built.js.pipe(replace("../", "../lib/")).pipe(gulp.dest(config.paths.exports)) + built.dts.pipe(replace("../", "./lib/")).pipe(gulp.dest(config.paths.exports)), + built.js.pipe(replace("../", "./lib/")).pipe(gulp.dest(config.paths.exports)) ]); }); diff --git a/gulptasks/clean.js b/gulptasks/clean.js index 48fb16f1..f9c43ad7 100644 --- a/gulptasks/clean.js +++ b/gulptasks/clean.js @@ -14,7 +14,6 @@ gulp.task('clean', (done) => { var directories = [ config.paths.dist, config.paths.lib, - config.paths.exports, config.testing.testingRoot, config.debug.outputRoot, config.docs.output diff --git a/package.json b/package.json index b376b903..d6dad52d 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "3.0.0-beta.0", "description": "A JavaScript library for SharePoint development.", "main": "./lib/pnp.js", - "typings": "./lib/pnp", + "typings": "./lib/pnp", "dependencies": { "@types/sharepoint": "2013.1.9" }, diff --git a/src/configuration/pnplibconfig.ts b/src/configuration/pnplibconfig.ts index 6dc93a54..758afb68 100644 --- a/src/configuration/pnplibconfig.ts +++ b/src/configuration/pnplibconfig.ts @@ -6,11 +6,6 @@ import { GraphHttpClientImpl } from "../net/graphclient"; export interface LibraryConfiguration { - /** - * Any headers to apply to all requests - */ - headers?: TypedHash; - /** * Allows caching to be global disabled, default: false */ @@ -41,6 +36,11 @@ export interface LibraryConfiguration { */ sp?: { + /** + * Any headers to apply to all requests + */ + headers?: TypedHash; + /** * Defines a factory method used to create fetch clients */ @@ -56,6 +56,12 @@ export interface LibraryConfiguration { * MS Graph specific library settings */ graph?: { + + /** + * Any headers to apply to all requests + */ + headers?: TypedHash; + /** * Defines a factory method used to create fetch clients */ @@ -70,7 +76,6 @@ export interface LibraryConfiguration { export class RuntimeConfigImpl { - private _headers: TypedHash; private _defaultCachingStore: "session" | "local"; private _defaultCachingTimeoutSeconds: number; private _globalCacheDisable: boolean; @@ -81,14 +86,15 @@ export class RuntimeConfigImpl { // sharepoint settings private _spFetchClientFactory: () => HttpClientImpl; private _spBaseUrl: string; + private _spHeaders: TypedHash; // graph settings + private _graphHeaders: TypedHash; private _graphFetchClientFactory: () => GraphHttpClientImpl; constructor() { // these are our default values for the library - this._headers = null; this._defaultCachingStore = "session"; this._defaultCachingTimeoutSeconds = 60; this._globalCacheDisable = false; @@ -99,17 +105,15 @@ export class RuntimeConfigImpl { // sharepoint settings this._spFetchClientFactory = () => new FetchClient(); this._spBaseUrl = null; + this._spHeaders = null; // ms graph settings + this._graphHeaders = null; this._graphFetchClientFactory = () => null; } public set(config: LibraryConfiguration): void { - if (config.hasOwnProperty("headers")) { - this._headers = config.headers; - } - if (config.hasOwnProperty("globalCacheDisable")) { this._globalCacheDisable = config.globalCacheDisable; } @@ -122,23 +126,42 @@ export class RuntimeConfigImpl { this._defaultCachingTimeoutSeconds = config.defaultCachingTimeoutSeconds; } - if (config.hasOwnProperty("sp") && config.sp.hasOwnProperty("fetchClientFactory")) { - this._spFetchClientFactory = config.sp.fetchClientFactory; - } + if (config.hasOwnProperty("sp")) { + + if (config.sp.hasOwnProperty("fetchClientFactory")) { + this._spFetchClientFactory = config.sp.fetchClientFactory; + } - if (config.hasOwnProperty("sp") && config.sp.hasOwnProperty("baseUrl")) { - this._spBaseUrl = config.sp.baseUrl; + if (config.sp.hasOwnProperty("baseUrl")) { + this._spBaseUrl = config.sp.baseUrl; + } + + if (config.sp.hasOwnProperty("headers")) { + this._spHeaders = config.sp.headers; + } } if (config.hasOwnProperty("spfxContext")) { this._spfxContext = config.spfxContext; - if (typeof this._spfxContext.graphHttpClient !== "undefined") { + if (typeof this._spfxContext.graphHttpClient !== "undefined") { this._graphFetchClientFactory = () => this._spfxContext.graphHttpClient; } } + if (config.hasOwnProperty("graph")) { + + if (config.graph.hasOwnProperty("headers")) { + this._graphHeaders = config.graph.headers; + } + + // this comes after the default setting of the _graphFetchClientFactory client so it can be overwritten + if (config.graph.hasOwnProperty("fetchClientFactory")) { + this._graphFetchClientFactory = config.graph.fetchClientFactory; + } + } + if (config.hasOwnProperty("enableCacheExpiration")) { this._enableCacheExpiration = config.enableCacheExpiration; } @@ -150,10 +173,6 @@ export class RuntimeConfigImpl { } } - public get headers(): TypedHash { - return this._headers; - } - public get defaultCachingStore(): "session" | "local" { return this._defaultCachingStore; } @@ -184,6 +203,10 @@ export class RuntimeConfigImpl { return null; } + public get spHeaders(): TypedHash { + return this._spHeaders; + } + public get enableCacheExpiration(): boolean { return this._enableCacheExpiration; } @@ -199,6 +222,10 @@ export class RuntimeConfigImpl { public get graphFetchClientFactory(): () => GraphHttpClientImpl { return this._graphFetchClientFactory; } + + public get graphHeaders(): TypedHash { + return this._graphHeaders; + } } const _runtimeConfig = new RuntimeConfigImpl(); diff --git a/src/exports/net.ts b/src/exports/net.ts index e83caec9..c4ac4624 100644 --- a/src/exports/net.ts +++ b/src/exports/net.ts @@ -3,4 +3,4 @@ export { ConfigOptions, FetchOptions } from "../net/utils"; export { SPRequestExecutorClient } from "../net/sprequestexecutorclient"; export { NodeFetchClient } from "../net/nodefetchclient"; export { FetchClient } from "../net/fetchclient"; -export { GraphHttpClient } from "../net/graphclient"; +export { GraphHttpClient, GraphHttpClientImpl } from "../net/graphclient"; diff --git a/src/exports/odata.ts b/src/exports/odata.ts index 1efee538..4d69b023 100644 --- a/src/exports/odata.ts +++ b/src/exports/odata.ts @@ -1,3 +1,4 @@ export * from "../odata/core"; export * from "../odata/parsers"; export * from "../odata/caching"; +export * from "../odata/queryable"; diff --git a/src/net/digestcache.ts b/src/net/digestcache.ts index b8bc5a0e..86434526 100644 --- a/src/net/digestcache.ts +++ b/src/net/digestcache.ts @@ -36,7 +36,7 @@ export class DigestCache { return this._httpClient.fetchRaw(url, { cache: "no-cache", credentials: "same-origin", - headers: Util.extend(headers, RuntimeConfig.headers, true), + headers: Util.extend(headers, RuntimeConfig.spHeaders, true), method: "POST", }).then((response) => { const parser = new ODataDefaultParser(); diff --git a/src/net/graphclient.ts b/src/net/graphclient.ts index a03b6f1d..061a9c8b 100644 --- a/src/net/graphclient.ts +++ b/src/net/graphclient.ts @@ -15,9 +15,18 @@ export class GraphHttpClient implements RequestClient { public fetch(url: string, options: FetchOptions = {}): Promise { + const headers = new Headers(); + + // first we add the global headers so they can be overwritten by any passed in locally to this call + mergeHeaders(headers, RuntimeConfig.graphHeaders); + + // second we add the local options so we can overwrite the globals + mergeHeaders(headers, options.headers); + + const opts = Util.extend(options, { headers: headers }); + // TODO: we could process auth here - // until we are doing things like establishing the auth just pass this to the SPFx client to do the heavy lifting - return this.fetchRaw(url, options); + return this.fetchRaw(url, opts); } public fetchRaw(url: string, options: FetchOptions = {}): Promise { diff --git a/src/net/httpclient.ts b/src/net/httpclient.ts index 87c17aa3..76be01fd 100644 --- a/src/net/httpclient.ts +++ b/src/net/httpclient.ts @@ -26,7 +26,7 @@ export class HttpClient implements RequestClient { const headers = new Headers(); // first we add the global headers so they can be overwritten by any passed in locally to this call - mergeHeaders(headers, RuntimeConfig.headers); + mergeHeaders(headers, RuntimeConfig.spHeaders); // second we add the local options so we can overwrite the globals mergeHeaders(headers, options.headers); diff --git a/src/pnp.ts b/src/pnp.ts index 207bdba3..13dd3130 100644 --- a/src/pnp.ts +++ b/src/pnp.ts @@ -48,7 +48,6 @@ export const setup: (config: LibraryConfiguration) => void = setRuntimeConfig; // /** // * Expose a subset of classes from the library for public consumption // */ -// export * from "./types/index"; // creating this class instead of directly assigning to default fixes issue #116 const Def = { diff --git a/src/sharepoint/batch.ts b/src/sharepoint/batch.ts index 5f1d08ed..1600f0f5 100644 --- a/src/sharepoint/batch.ts +++ b/src/sharepoint/batch.ts @@ -160,7 +160,7 @@ export class ODataBatch { } // merge global config headers - mergeHeaders(headers, RuntimeConfig.headers); + mergeHeaders(headers, RuntimeConfig.spHeaders); // merge per-request headers if (reqInfo.options) {