@pnp/nodejs 2.10.0 → 2.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
- import { AuthenticationResult, Configuration } from "@azure/msal-node";
2
- import { IHttpClientImpl } from "@pnp/common";
3
- export declare class MsalFetchClient implements IHttpClientImpl {
4
- private _scopes;
5
- private confidentialClient;
6
- constructor(_config: Configuration, _scopes?: string[]);
7
- fetch(url: string, options: any): Promise<Response>;
8
- acquireToken(scopes?: string[]): Promise<AuthenticationResult>;
9
- }
1
+ import { AuthenticationResult, Configuration } from "@azure/msal-node";
2
+ import { IHttpClientImpl } from "@pnp/common";
3
+ export declare class MsalFetchClient implements IHttpClientImpl {
4
+ private _scopes;
5
+ private confidentialClient;
6
+ constructor(_config: Configuration, _scopes?: string[]);
7
+ fetch(url: string, options: any): Promise<Response>;
8
+ acquireToken(scopes?: string[]): Promise<AuthenticationResult>;
9
+ }
10
10
  //# sourceMappingURL=msalfetchclient.d.ts.map
@@ -1,33 +1,33 @@
1
- import { ConfidentialClientApplication } from "@azure/msal-node";
2
- import { objectDefinedNotNull, assign, } from "@pnp/common";
3
- import { fetch } from "./fetch.js";
4
- var MsalFetchClient = /** @class */ (function () {
5
- function MsalFetchClient(_config, _scopes) {
6
- if (_scopes === void 0) { _scopes = ["https://graph.microsoft.com/.default"]; }
7
- this._scopes = _scopes;
8
- this.confidentialClient = new ConfidentialClientApplication(_config);
9
- }
10
- MsalFetchClient.prototype.fetch = function (url, options) {
11
- if (!objectDefinedNotNull(options)) {
12
- options = {
13
- headers: new Headers(),
14
- };
15
- }
16
- else if (!objectDefinedNotNull(options.headers)) {
17
- options = assign(options, {
18
- headers: new Headers(),
19
- });
20
- }
21
- return this.acquireToken().then(function (token) {
22
- options.headers.set("Authorization", token.tokenType + " " + token.accessToken);
23
- return fetch(url, options);
24
- });
25
- };
26
- MsalFetchClient.prototype.acquireToken = function (scopes) {
27
- if (scopes === void 0) { scopes = this._scopes; }
28
- return this.confidentialClient.acquireTokenByClientCredential({ scopes: scopes });
29
- };
30
- return MsalFetchClient;
31
- }());
32
- export { MsalFetchClient };
1
+ import { ConfidentialClientApplication } from "@azure/msal-node";
2
+ import { objectDefinedNotNull, assign, } from "@pnp/common";
3
+ import { fetch } from "./fetch.js";
4
+ var MsalFetchClient = /** @class */ (function () {
5
+ function MsalFetchClient(_config, _scopes) {
6
+ if (_scopes === void 0) { _scopes = ["https://graph.microsoft.com/.default"]; }
7
+ this._scopes = _scopes;
8
+ this.confidentialClient = new ConfidentialClientApplication(_config);
9
+ }
10
+ MsalFetchClient.prototype.fetch = function (url, options) {
11
+ if (!objectDefinedNotNull(options)) {
12
+ options = {
13
+ headers: new Headers(),
14
+ };
15
+ }
16
+ else if (!objectDefinedNotNull(options.headers)) {
17
+ options = assign(options, {
18
+ headers: new Headers(),
19
+ });
20
+ }
21
+ return this.acquireToken().then(function (token) {
22
+ options.headers.set("Authorization", token.tokenType + " " + token.accessToken);
23
+ return fetch(url, options);
24
+ });
25
+ };
26
+ MsalFetchClient.prototype.acquireToken = function (scopes) {
27
+ if (scopes === void 0) { scopes = this._scopes; }
28
+ return this.confidentialClient.acquireTokenByClientCredential({ scopes: scopes });
29
+ };
30
+ return MsalFetchClient;
31
+ }());
32
+ export { MsalFetchClient };
33
33
  //# sourceMappingURL=msalfetchclient.js.map
@@ -1,24 +1,24 @@
1
- import { IHttpClientImpl } from "@pnp/common";
2
- /**
3
- * Fetch client that encapsulates the node-fetch library and also adds retry logic
4
- * when encountering transient errors.
5
- */
6
- export declare class NodeFetchClient implements IHttpClientImpl {
7
- private retryCount;
8
- private retryInterval;
9
- private minRetryInterval;
10
- private maxRetryInterval;
11
- /**
12
- *
13
- * @param retryCount: number - Maximum number of transient failure retries before throwing the error
14
- * @param retryInterval: number - Starting interval to delay the first retry attempt
15
- * @param minRetryInterval: number - Minimum retry delay boundary as retry intervals are randomly recalculated
16
- * @param maxRetryInterval: number - Maximum retry delay boundary as retry intervals are radnomaly recalculated
17
- */
18
- constructor(retryCount?: number, retryInterval?: number, minRetryInterval?: number, maxRetryInterval?: number);
19
- fetch(url: string, options?: any): Promise<Response>;
20
- private delay;
21
- private updateRetryData;
22
- private shouldRetry;
23
- }
1
+ import { IHttpClientImpl } from "@pnp/common";
2
+ /**
3
+ * Fetch client that encapsulates the node-fetch library and also adds retry logic
4
+ * when encountering transient errors.
5
+ */
6
+ export declare class NodeFetchClient implements IHttpClientImpl {
7
+ private retryCount;
8
+ private retryInterval;
9
+ private minRetryInterval;
10
+ private maxRetryInterval;
11
+ /**
12
+ *
13
+ * @param retryCount: number - Maximum number of transient failure retries before throwing the error
14
+ * @param retryInterval: number - Starting interval to delay the first retry attempt
15
+ * @param minRetryInterval: number - Minimum retry delay boundary as retry intervals are randomly recalculated
16
+ * @param maxRetryInterval: number - Maximum retry delay boundary as retry intervals are radnomaly recalculated
17
+ */
18
+ constructor(retryCount?: number, retryInterval?: number, minRetryInterval?: number, maxRetryInterval?: number);
19
+ fetch(url: string, options?: any): Promise<Response>;
20
+ private delay;
21
+ private updateRetryData;
22
+ private shouldRetry;
23
+ }
24
24
  //# sourceMappingURL=nodefetchclient.d.ts.map
@@ -1,118 +1,118 @@
1
- import { __awaiter, __generator } from "tslib";
2
- import { Logger } from "@pnp/logging";
3
- import { fetch } from "./fetch.js";
4
- /**
5
- * Fetch client that encapsulates the node-fetch library and also adds retry logic
6
- * when encountering transient errors.
7
- */
8
- var NodeFetchClient = /** @class */ (function () {
9
- /**
10
- *
11
- * @param retryCount: number - Maximum number of transient failure retries before throwing the error
12
- * @param retryInterval: number - Starting interval to delay the first retry attempt
13
- * @param minRetryInterval: number - Minimum retry delay boundary as retry intervals are randomly recalculated
14
- * @param maxRetryInterval: number - Maximum retry delay boundary as retry intervals are radnomaly recalculated
15
- */
16
- function NodeFetchClient(retryCount, retryInterval, minRetryInterval, maxRetryInterval) {
17
- if (retryCount === void 0) { retryCount = 3; }
18
- if (retryInterval === void 0) { retryInterval = 3000; }
19
- if (minRetryInterval === void 0) { minRetryInterval = 3000; }
20
- if (maxRetryInterval === void 0) { maxRetryInterval = 90000; }
21
- this.retryCount = retryCount;
22
- this.retryInterval = retryInterval;
23
- this.minRetryInterval = minRetryInterval;
24
- this.maxRetryInterval = maxRetryInterval;
25
- }
26
- NodeFetchClient.prototype.fetch = function (url, options) {
27
- return __awaiter(this, void 0, void 0, function () {
28
- var wrapper;
29
- var _this = this;
30
- return __generator(this, function (_a) {
31
- switch (_a.label) {
32
- case 0:
33
- wrapper = function (retryData) { return __awaiter(_this, void 0, void 0, function () {
34
- var err_1, retry;
35
- return __generator(this, function (_a) {
36
- switch (_a.label) {
37
- case 0:
38
- _a.trys.push([0, 2, , 7]);
39
- return [4 /*yield*/, fetch(url, options || {})];
40
- case 1:
41
- // Try to make the request...
42
- return [2 /*return*/, _a.sent()];
43
- case 2:
44
- err_1 = _a.sent();
45
- retry = this.updateRetryData(retryData, err_1);
46
- // If there is no error code, this wasn't a transient error
47
- // so we throw immediately.
48
- if (!err_1.code) {
49
- throw err_1;
50
- }
51
- if (!(["ETIMEDOUT", "ESOCKETTIMEDOUT", "ECONNREFUSED", "ECONNRESET"].indexOf(err_1.code.toUpperCase()) > -1)) return [3 /*break*/, 6];
52
- Logger.write("Attempt #" + retry.retryCount + " - Retrying error code: " + err_1.code + "...", 0 /* Verbose */);
53
- if (!this.shouldRetry(retry)) return [3 /*break*/, 5];
54
- return [4 /*yield*/, this.delay(retry.retryInterval)];
55
- case 3:
56
- _a.sent();
57
- return [4 /*yield*/, wrapper(retry)];
58
- case 4: return [2 /*return*/, _a.sent()];
59
- case 5: // max amount of retries reached, so throw the error
60
- throw err_1;
61
- case 6: return [3 /*break*/, 7];
62
- case 7: return [2 /*return*/];
63
- }
64
- });
65
- }); };
66
- return [4 /*yield*/, wrapper(null)];
67
- case 1: return [2 /*return*/, _a.sent()];
68
- }
69
- });
70
- });
71
- };
72
- NodeFetchClient.prototype.delay = function (ms) {
73
- return __awaiter(this, void 0, void 0, function () {
74
- return __generator(this, function (_a) {
75
- return [2 /*return*/, new Promise(function (resolve) {
76
- setTimeout(function () {
77
- resolve();
78
- }, ms);
79
- })];
80
- });
81
- });
82
- };
83
- NodeFetchClient.prototype.updateRetryData = function (retryData, err) {
84
- var data = retryData || {
85
- error: null,
86
- retryCount: 0,
87
- retryInterval: 0,
88
- };
89
- var newError = err || null;
90
- // Keep track of errors from previous retries
91
- // if they exist
92
- if (newError) {
93
- if (data.error) {
94
- newError.innerError = data.error;
95
- }
96
- data.error = newError;
97
- }
98
- // Adjust retry interval and cap based on the min and max intervals specified
99
- var incrementDelta = Math.pow(2, data.retryCount) - 1;
100
- var boundedRandDelta = this.retryInterval * 0.8 +
101
- Math.floor(Math.random() * (this.retryInterval * 1.2 - this.retryInterval * 0.8));
102
- incrementDelta *= boundedRandDelta;
103
- // Adjust retry count
104
- data.retryCount++;
105
- data.retryInterval = Math.min(this.minRetryInterval + incrementDelta, this.maxRetryInterval);
106
- return data;
107
- };
108
- NodeFetchClient.prototype.shouldRetry = function (retryData) {
109
- if (!retryData) {
110
- throw new Error("ERROR: retryData cannot be null.");
111
- }
112
- var currentCount = (retryData && retryData.retryCount);
113
- return currentCount < this.retryCount;
114
- };
115
- return NodeFetchClient;
116
- }());
117
- export { NodeFetchClient };
1
+ import { __awaiter, __generator } from "tslib";
2
+ import { Logger } from "@pnp/logging";
3
+ import { fetch } from "./fetch.js";
4
+ /**
5
+ * Fetch client that encapsulates the node-fetch library and also adds retry logic
6
+ * when encountering transient errors.
7
+ */
8
+ var NodeFetchClient = /** @class */ (function () {
9
+ /**
10
+ *
11
+ * @param retryCount: number - Maximum number of transient failure retries before throwing the error
12
+ * @param retryInterval: number - Starting interval to delay the first retry attempt
13
+ * @param minRetryInterval: number - Minimum retry delay boundary as retry intervals are randomly recalculated
14
+ * @param maxRetryInterval: number - Maximum retry delay boundary as retry intervals are radnomaly recalculated
15
+ */
16
+ function NodeFetchClient(retryCount, retryInterval, minRetryInterval, maxRetryInterval) {
17
+ if (retryCount === void 0) { retryCount = 3; }
18
+ if (retryInterval === void 0) { retryInterval = 3000; }
19
+ if (minRetryInterval === void 0) { minRetryInterval = 3000; }
20
+ if (maxRetryInterval === void 0) { maxRetryInterval = 90000; }
21
+ this.retryCount = retryCount;
22
+ this.retryInterval = retryInterval;
23
+ this.minRetryInterval = minRetryInterval;
24
+ this.maxRetryInterval = maxRetryInterval;
25
+ }
26
+ NodeFetchClient.prototype.fetch = function (url, options) {
27
+ return __awaiter(this, void 0, void 0, function () {
28
+ var wrapper;
29
+ var _this = this;
30
+ return __generator(this, function (_a) {
31
+ switch (_a.label) {
32
+ case 0:
33
+ wrapper = function (retryData) { return __awaiter(_this, void 0, void 0, function () {
34
+ var err_1, retry;
35
+ return __generator(this, function (_a) {
36
+ switch (_a.label) {
37
+ case 0:
38
+ _a.trys.push([0, 2, , 7]);
39
+ return [4 /*yield*/, fetch(url, options || {})];
40
+ case 1:
41
+ // Try to make the request...
42
+ return [2 /*return*/, _a.sent()];
43
+ case 2:
44
+ err_1 = _a.sent();
45
+ retry = this.updateRetryData(retryData, err_1);
46
+ // If there is no error code, this wasn't a transient error
47
+ // so we throw immediately.
48
+ if (!err_1.code) {
49
+ throw err_1;
50
+ }
51
+ if (!(["ETIMEDOUT", "ESOCKETTIMEDOUT", "ECONNREFUSED", "ECONNRESET"].indexOf(err_1.code.toUpperCase()) > -1)) return [3 /*break*/, 6];
52
+ Logger.write("Attempt #" + retry.retryCount + " - Retrying error code: " + err_1.code + "...", 0 /* Verbose */);
53
+ if (!this.shouldRetry(retry)) return [3 /*break*/, 5];
54
+ return [4 /*yield*/, this.delay(retry.retryInterval)];
55
+ case 3:
56
+ _a.sent();
57
+ return [4 /*yield*/, wrapper(retry)];
58
+ case 4: return [2 /*return*/, _a.sent()];
59
+ case 5: // max amount of retries reached, so throw the error
60
+ throw err_1;
61
+ case 6: return [3 /*break*/, 7];
62
+ case 7: return [2 /*return*/];
63
+ }
64
+ });
65
+ }); };
66
+ return [4 /*yield*/, wrapper(null)];
67
+ case 1: return [2 /*return*/, _a.sent()];
68
+ }
69
+ });
70
+ });
71
+ };
72
+ NodeFetchClient.prototype.delay = function (ms) {
73
+ return __awaiter(this, void 0, void 0, function () {
74
+ return __generator(this, function (_a) {
75
+ return [2 /*return*/, new Promise(function (resolve) {
76
+ setTimeout(function () {
77
+ resolve();
78
+ }, ms);
79
+ })];
80
+ });
81
+ });
82
+ };
83
+ NodeFetchClient.prototype.updateRetryData = function (retryData, err) {
84
+ var data = retryData || {
85
+ error: null,
86
+ retryCount: 0,
87
+ retryInterval: 0,
88
+ };
89
+ var newError = err || null;
90
+ // Keep track of errors from previous retries
91
+ // if they exist
92
+ if (newError) {
93
+ if (data.error) {
94
+ newError.innerError = data.error;
95
+ }
96
+ data.error = newError;
97
+ }
98
+ // Adjust retry interval and cap based on the min and max intervals specified
99
+ var incrementDelta = Math.pow(2, data.retryCount) - 1;
100
+ var boundedRandDelta = this.retryInterval * 0.8 +
101
+ Math.floor(Math.random() * (this.retryInterval * 1.2 - this.retryInterval * 0.8));
102
+ incrementDelta *= boundedRandDelta;
103
+ // Adjust retry count
104
+ data.retryCount++;
105
+ data.retryInterval = Math.min(this.minRetryInterval + incrementDelta, this.maxRetryInterval);
106
+ return data;
107
+ };
108
+ NodeFetchClient.prototype.shouldRetry = function (retryData) {
109
+ if (!retryData) {
110
+ throw new Error("ERROR: retryData cannot be null.");
111
+ }
112
+ var currentCount = (retryData && retryData.retryCount);
113
+ return currentCount < this.retryCount;
114
+ };
115
+ return NodeFetchClient;
116
+ }());
117
+ export { NodeFetchClient };
118
118
  //# sourceMappingURL=nodefetchclient.js.map
package/net/proxy.d.ts CHANGED
@@ -1,18 +1,18 @@
1
- import { IConfigOptions } from "@pnp/common";
2
- import * as HttpsProxyAgent from "https-proxy-agent";
3
- export declare function configureProxyOptions<T extends IConfigOptions>(opts: T): T & {
4
- agent: typeof HttpsProxyAgent;
5
- };
6
- /**
7
- * Sets the given url as a proxy on all requests
8
- *
9
- * @param url The url of the proxy
10
- */
11
- export declare function setProxyUrl(url: string): void;
12
- /**
13
- * Sets the given agent as a proxy on all requests
14
- *
15
- * @param agent The proxy agent to use
16
- */
17
- export declare function setProxyAgent(agent: any): void;
1
+ import { IConfigOptions } from "@pnp/common";
2
+ import * as HttpsProxyAgent from "https-proxy-agent";
3
+ export declare function configureProxyOptions<T extends IConfigOptions>(opts: T): T & {
4
+ agent: typeof HttpsProxyAgent;
5
+ };
6
+ /**
7
+ * Sets the given url as a proxy on all requests
8
+ *
9
+ * @param url The url of the proxy
10
+ */
11
+ export declare function setProxyUrl(url: string): void;
12
+ /**
13
+ * Sets the given agent as a proxy on all requests
14
+ *
15
+ * @param agent The proxy agent to use
16
+ */
17
+ export declare function setProxyAgent(agent: any): void;
18
18
  //# sourceMappingURL=proxy.d.ts.map
package/net/proxy.js CHANGED
@@ -1,29 +1,29 @@
1
- import { stringIsNullOrEmpty, mergeOptions, objectDefinedNotNull } from "@pnp/common";
2
- import * as HttpsProxyAgent from "https-proxy-agent";
3
- var proxyUrl = "";
4
- var proxyAgent = null;
5
- export function configureProxyOptions(opts) {
6
- if (!stringIsNullOrEmpty(proxyUrl) || objectDefinedNotNull(proxyAgent)) {
7
- mergeOptions(opts, {
8
- agent: proxyAgent || HttpsProxyAgent(proxyUrl),
9
- });
10
- }
11
- return opts;
12
- }
13
- /**
14
- * Sets the given url as a proxy on all requests
15
- *
16
- * @param url The url of the proxy
17
- */
18
- export function setProxyUrl(url) {
19
- proxyUrl = url;
20
- }
21
- /**
22
- * Sets the given agent as a proxy on all requests
23
- *
24
- * @param agent The proxy agent to use
25
- */
26
- export function setProxyAgent(agent) {
27
- proxyAgent = agent;
28
- }
1
+ import { stringIsNullOrEmpty, mergeOptions, objectDefinedNotNull } from "@pnp/common";
2
+ import * as HttpsProxyAgent from "https-proxy-agent";
3
+ var proxyUrl = "";
4
+ var proxyAgent = null;
5
+ export function configureProxyOptions(opts) {
6
+ if (!stringIsNullOrEmpty(proxyUrl) || objectDefinedNotNull(proxyAgent)) {
7
+ mergeOptions(opts, {
8
+ agent: proxyAgent || HttpsProxyAgent(proxyUrl),
9
+ });
10
+ }
11
+ return opts;
12
+ }
13
+ /**
14
+ * Sets the given url as a proxy on all requests
15
+ *
16
+ * @param url The url of the proxy
17
+ */
18
+ export function setProxyUrl(url) {
19
+ proxyUrl = url;
20
+ }
21
+ /**
22
+ * Sets the given agent as a proxy on all requests
23
+ *
24
+ * @param agent The proxy agent to use
25
+ */
26
+ export function setProxyAgent(agent) {
27
+ proxyAgent = agent;
28
+ }
29
29
  //# sourceMappingURL=proxy.js.map
@@ -1,22 +1,22 @@
1
- import { IHttpClientImpl } from "@pnp/common";
2
- import { SPOAuthEnv, AuthToken } from "../types.js";
3
- /**
4
- * Fetch client for use within nodejs, requires you register a client id and secret with app only permissions.
5
- *
6
- * See either the MSAL client or ADAL client for more modern options
7
- */
8
- export declare class SPFetchClient implements IHttpClientImpl {
9
- siteUrl: string;
10
- protected _clientId: string;
11
- protected _clientSecret: string;
12
- authEnv: SPOAuthEnv;
13
- protected _realm: string;
14
- protected _fetchClient: IHttpClientImpl;
15
- protected token: AuthToken | null;
16
- constructor(siteUrl: string, _clientId: string, _clientSecret: string, authEnv?: SPOAuthEnv, _realm?: string, _fetchClient?: IHttpClientImpl);
17
- fetch(url: string, options?: any): Promise<Response>;
18
- getAuthHostUrl(env: SPOAuthEnv): string;
19
- private getRealm;
20
- private getAuthUrl;
21
- }
1
+ import { IHttpClientImpl } from "@pnp/common";
2
+ import { SPOAuthEnv, AuthToken } from "../types.js";
3
+ /**
4
+ * Fetch client for use within nodejs, requires you register a client id and secret with app only permissions.
5
+ *
6
+ * See either the MSAL client or ADAL client for more modern options
7
+ */
8
+ export declare class SPFetchClient implements IHttpClientImpl {
9
+ siteUrl: string;
10
+ protected _clientId: string;
11
+ protected _clientSecret: string;
12
+ authEnv: SPOAuthEnv;
13
+ protected _realm: string;
14
+ protected _fetchClient: IHttpClientImpl;
15
+ protected token: AuthToken | null;
16
+ constructor(siteUrl: string, _clientId: string, _clientSecret: string, authEnv?: SPOAuthEnv, _realm?: string, _fetchClient?: IHttpClientImpl);
17
+ fetch(url: string, options?: any): Promise<Response>;
18
+ getAuthHostUrl(env: SPOAuthEnv): string;
19
+ private getRealm;
20
+ private getAuthUrl;
21
+ }
22
22
  //# sourceMappingURL=spfetchclient.d.ts.map