gd-sprest 7.6.7 → 7.6.9

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.
@@ -57,6 +57,11 @@ export interface IList {
57
57
  * @param parameters - The optional list data parameters.
58
58
  */
59
59
  getDataAsStream(listFullUrl: string, parameters?: RenderListDataParameters): IBaseExecution<IListDataStream>;
60
+
61
+ /**
62
+ * Runs a flow against a list item.
63
+ */
64
+ runFlow(props: IRunFlow): PromiseLike<IRunFlowResult>;
60
65
  }
61
66
 
62
67
  /**
@@ -91,4 +96,26 @@ export interface IListEntityProps {
91
96
 
92
97
  /** The relative url of the web containing the list. */
93
98
  url?: string;
99
+ }
100
+
101
+ /**
102
+ * Properties for running a flow
103
+ */
104
+ export interface IRunFlow {
105
+ cloudEnv?: string;
106
+ data: object;
107
+ id?: string;
108
+ list: string;
109
+ token?: string;
110
+ webUrl?: string;
111
+ }
112
+
113
+ /**
114
+ * Flow execution result
115
+ */
116
+ export interface IRunFlowResult {
117
+ errorDetails?: object;
118
+ errorMessage?: string;
119
+ executed: boolean;
120
+ flowToken?: string;
94
121
  }
package/build/lib/list.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.List = void 0;
4
+ var sptypes_1 = require("../sptypes");
4
5
  var utils_1 = require("../utils");
6
+ var graph_1 = require("./graph");
5
7
  var web_1 = require("./web");
6
8
  /**
7
9
  * List
@@ -55,3 +57,122 @@ exports.List.getDataAsStream = (function (listFullUrl, parameters) {
55
57
  endpoint: "SP.List.getListDataAsStream" + params
56
58
  });
57
59
  });
60
+ // Static method for executing a flow against a list item
61
+ exports.List.runFlow = function (props) {
62
+ // Return a promise
63
+ return new Promise(function (resolve) {
64
+ // Gets the graph token
65
+ var getGraphToken = function () {
66
+ // Return a promise
67
+ return new Promise(function (resolveAuth) {
68
+ // Get the graph token
69
+ graph_1.Graph.getAccessToken(sptypes_1.SPTypes.CloudEnvironment.Flow).execute(function (auth) {
70
+ // Resolve the request
71
+ resolveAuth(auth.access_token);
72
+ },
73
+ // Error
74
+ function (ex) {
75
+ // Resolve the request
76
+ resolve({
77
+ executed: false,
78
+ errorDetails: ex.response,
79
+ errorMessage: "Auth Error: Unable to get the flow token."
80
+ });
81
+ });
82
+ });
83
+ };
84
+ // Gets the flow token
85
+ var getFlowToken = function (flowInfo) {
86
+ // Return a promise
87
+ return new Promise(function (resolveAuth) {
88
+ // See if the flow token is provided
89
+ if (props.token) {
90
+ // Resolve the request
91
+ resolveAuth(props.token);
92
+ }
93
+ else {
94
+ // Get the graph token
95
+ getGraphToken().then(function (token) {
96
+ // See if the cloud environment was provided
97
+ if (props.cloudEnv) {
98
+ // Set the url
99
+ var authUrl = "" + props.cloudEnv + flowInfo.properties.environment.id + "/users/me/onBehalfOfTokenBundle?api-version=2016-11-01";
100
+ // Execute the request
101
+ new utils_1.Base({
102
+ endpoint: authUrl,
103
+ method: "POST",
104
+ requestType: utils_1.RequestType.GraphPost,
105
+ requestHeader: {
106
+ "authorization": "Bearer " + token
107
+ }
108
+ }).execute(function (tokenInfo) {
109
+ // Resolve the request
110
+ resolveAuth(tokenInfo.audienceToToken["https://" + flowInfo.properties.connectionReferences.shared_sharepointonline.swagger.host] || token);
111
+ },
112
+ // Error
113
+ function (ex) {
114
+ // Resolve the request
115
+ resolve({
116
+ executed: false,
117
+ errorDetails: ex.response,
118
+ errorMessage: "Auth Error: Unable to get the flow token for cloud: " + props.cloudEnv
119
+ });
120
+ });
121
+ }
122
+ else {
123
+ // Resolve the request
124
+ resolveAuth(token);
125
+ }
126
+ });
127
+ }
128
+ });
129
+ };
130
+ // Get the flow information
131
+ web_1.Web(props.webUrl).Lists(props.list).syncFlowInstance(props.id).execute(
132
+ // Success
133
+ function (flow) {
134
+ // Get the flow information
135
+ var flowInfo = JSON.parse(flow.SynchronizationData);
136
+ // Get the flow token
137
+ getFlowToken(flowInfo).then(function (token) {
138
+ // Trigger the flow
139
+ new utils_1.Base({
140
+ accessToken: token,
141
+ requestType: utils_1.RequestType.GraphPost,
142
+ endpoint: flowInfo.properties.flowTriggerUri,
143
+ data: {
144
+ rows: [{
145
+ entity: props.data
146
+ }]
147
+ }
148
+ }).execute(
149
+ // Success
150
+ function () {
151
+ // Resolve the request
152
+ resolve({
153
+ executed: true,
154
+ flowToken: token
155
+ });
156
+ },
157
+ // Error
158
+ function (ex) {
159
+ // Resolve the request
160
+ resolve({
161
+ executed: false,
162
+ errorDetails: ex.response,
163
+ errorMessage: "Error triggering the flow."
164
+ });
165
+ });
166
+ });
167
+ },
168
+ // Error
169
+ function (ex) {
170
+ // Resolve the request
171
+ resolve({
172
+ executed: false,
173
+ errorDetails: ex.response,
174
+ errorMessage: "Error getting the flow information."
175
+ });
176
+ });
177
+ });
178
+ };
package/build/rest.js CHANGED
@@ -8,7 +8,7 @@ var sptypes_1 = require("./sptypes");
8
8
  * SharePoint REST Library
9
9
  */
10
10
  exports.$REST = {
11
- __ver: 7.67,
11
+ __ver: 7.69,
12
12
  AppContext: function (siteUrl) { return Lib.Site.getAppContext(siteUrl); },
13
13
  Apps: Lib.Apps,
14
14
  ContextInfo: Lib.ContextInfo,
@@ -1410,6 +1410,11 @@ declare module 'gd-sprest/lib/list' {
1410
1410
  * @param parameters - The optional list data parameters.
1411
1411
  */
1412
1412
  getDataAsStream(listFullUrl: string, parameters?: RenderListDataParameters): IBaseExecution<IListDataStream>;
1413
+
1414
+ /**
1415
+ * Runs a flow against a list item.
1416
+ */
1417
+ runFlow(props: IRunFlow): PromiseLike<IRunFlowResult>;
1413
1418
  }
1414
1419
 
1415
1420
  /**
@@ -1445,6 +1450,28 @@ declare module 'gd-sprest/lib/list' {
1445
1450
  /** The relative url of the web containing the list. */
1446
1451
  url?: string;
1447
1452
  }
1453
+
1454
+ /**
1455
+ * Properties for running a flow
1456
+ */
1457
+ export interface IRunFlow {
1458
+ cloudEnv?: string;
1459
+ data: object;
1460
+ id?: string;
1461
+ list: string;
1462
+ token?: string;
1463
+ webUrl?: string;
1464
+ }
1465
+
1466
+ /**
1467
+ * Flow execution result
1468
+ */
1469
+ export interface IRunFlowResult {
1470
+ errorDetails?: object;
1471
+ errorMessage?: string;
1472
+ executed: boolean;
1473
+ flowToken?: string;
1474
+ }
1448
1475
  }
1449
1476
 
1450
1477
  declare module 'gd-sprest/lib/navigation' {