@microsoft/teams-js 2.0.0-beta.3-dev.11 → 2.0.0-beta.3-dev.15

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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Microsoft Teams JavaScript client SDK
2
2
 
3
- Welcome to the Teams client SDK monorepo! For breaking changes, please refer to our changelog in the monorepo root.
3
+ Welcome to the Teams client SDK monorepo! For breaking changes, please refer to our changelog in the monorepo root of the `2.0-preview` branch.
4
4
 
5
5
  This JavaScript library is part of the [Microsoft Teams developer platform](https://developer.microsoft.com/microsoft-teams/). See full [SDK reference documentation](https://docs.microsoft.com/en-us/javascript/api/overview/msteams-client).
6
6
 
@@ -11,8 +11,8 @@ This JavaScript library is part of the [Microsoft Teams developer platform](http
11
11
 
12
12
  1. Clone the repo
13
13
  2. Navigate to the repo root and run `yarn install`
14
- 3. `yarn build` from repo root
15
- 4. to run Unit test `yarn test`
14
+ 3. Run `yarn build` from repo root
15
+ 4. To run Unit tests, run `yarn test`
16
16
 
17
17
  TIP: whenever building or testing the Teams client SDK, you can run `yarn build` or `yarn test` from the packages/teams-js directory.
18
18
 
@@ -52,7 +52,7 @@ Reference the SDK inside of your `.html` page using:
52
52
  <!-- Microsoft Teams JavaScript API (via CDN) -->
53
53
  <script
54
54
  src="https://res.cdn.office.net/teams-js/2.0.0-beta.2/js/MicrosoftTeams.min.js"
55
- integrity="sha384-Q2Z9S56exI6Oz/ThvYaV0SUn8j4HwS8BveGPmuwLXe4CvCUEGlL80qSzHMnvGqee"
55
+ integrity="sha384-RhShpWwRxSnc+keX0WZxCsf8olaKOOw416Jky+StW6qhctsNR3GMwav/hMB1Snas"
56
56
  crossorigin="anonymous"
57
57
  ></script>
58
58
 
@@ -2717,7 +2717,7 @@ export namespace app {
2717
2717
  *
2718
2718
  * @param validMessageOrigins - Optionally specify a list of cross frame message origins. They must have
2719
2719
  * https: protocol otherwise they will be ignored. Example: https:www.example.com
2720
- * @returns Promise that will be fulfilled when initialization has completed
2720
+ * @returns Promise that will be fulfilled when initialization has completed, or rejected if the initialization fails or times out
2721
2721
  */
2722
2722
  function initialize(validMessageOrigins?: string[]): Promise<void>;
2723
2723
  /**
@@ -3970,6 +3970,21 @@ export namespace monetization {
3970
3970
  term: string;
3971
3971
  }
3972
3972
  /**
3973
+ * @hidden
3974
+ * Hide from docs
3975
+ * Open dialog to start user's purchase experience
3976
+ *
3977
+ * @param planInfo optional parameter. It contains info of the subscription plan pushed to users.
3978
+ * error can either contain an error of type SdkError, incase of an error, or null when get is successful
3979
+ * @returns Promise that will be resolved when the operation has completed or rejected with SdkError value
3980
+ *
3981
+ * @internal
3982
+ */
3983
+ function openPurchaseExperience(planInfo?: PlanInfo): Promise<void>;
3984
+ /**
3985
+ * @deprecated
3986
+ * As of 2.0.0-beta.3, please use {@link monetization.openPurchaseExperience monetization.openPurchaseExperience(planInfo?: PlanInfo): Promise\<void\>} instead.
3987
+ *
3973
3988
  * @hidden
3974
3989
  * Hide from docs
3975
3990
  * Open dialog to start user's purchase experience
@@ -4280,6 +4295,20 @@ export namespace sharing {
4280
4295
  preview?: boolean;
4281
4296
  }
4282
4297
  /**
4298
+ * @hidden
4299
+ * Feature is under development
4300
+ * Opens a share dialog for web content
4301
+ *
4302
+ * @param shareWebContentRequest - web content info
4303
+ * @returns Promise that will be fulfilled when the operation has completed
4304
+ *
4305
+ * @internal
4306
+ */
4307
+ export function shareWebContent(shareWebContentRequest: IShareRequest<IShareRequestContentType>): Promise<void>;
4308
+ /**
4309
+ * @deprecated
4310
+ * As of 2.0.0-beta.3, please use {@link sharing.shareWebContent sharing.shareWebContent(shareWebContentRequest: IShareRequest\<IShareRequestContentType\>): Promise\<void\>} instead.
4311
+ *
4283
4312
  * @hidden
4284
4313
  * Feature is under development
4285
4314
  * Opens a share dialog for web content
@@ -4289,7 +4318,7 @@ export namespace sharing {
4289
4318
  *
4290
4319
  * @internal
4291
4320
  */
4292
- export function shareWebContent(shareWebContentRequest: IShareRequest<IShareRequestContentType>, callback?: (err?: SdkError) => void): void;
4321
+ export function shareWebContent(shareWebContentRequest: IShareRequest<IShareRequestContentType>, callback: (err?: SdkError) => void): void;
4293
4322
  export function isSupported(): boolean;
4294
4323
  export {};
4295
4324
  }
@@ -395,7 +395,7 @@ __webpack_require__.d(__webpack_exports__, {
395
395
  });
396
396
 
397
397
  ;// CONCATENATED MODULE: ./src/internal/constants.ts
398
- var version = '2.0.0-beta.3-dev.11';
398
+ var version = '2.0.0-beta.3-dev.15';
399
399
  /**
400
400
  * @hidden
401
401
  * The SDK version when all SDK APIs started to check platform compatibility for the APIs was 1.6.0.
@@ -780,6 +780,31 @@ function callCallbackWithErrorOrResultOrNullFromPromiseAndReturnPromise(funcHelp
780
780
  });
781
781
  return p;
782
782
  }
783
+ /**
784
+ * A helper function to add a timeout to an asynchronous operation.
785
+ *
786
+ * @param action Action to wrap the timeout around
787
+ * @param timeoutInMs Timeout period in milliseconds
788
+ * @param timeoutError Error to reject the promise with if timeout elapses before the action completed
789
+ * @returns A promise which resolves to the result of provided action or rejects with a provided timeout error
790
+ * if the initial action didn't complete within provided timeout.
791
+ *
792
+ * @internal
793
+ */
794
+ function runWithTimeout(action, timeoutInMs, timeoutError) {
795
+ return new Promise(function (resolve, reject) {
796
+ var timeoutHandle = setTimeout(reject, timeoutInMs, timeoutError);
797
+ action()
798
+ .then(function (result) {
799
+ clearTimeout(timeoutHandle);
800
+ resolve(result);
801
+ })
802
+ .catch(function (error) {
803
+ clearTimeout(timeoutHandle);
804
+ reject(error);
805
+ });
806
+ });
807
+ }
783
808
  function createTeamsAppLink(params) {
784
809
  var url = new URL('https://teams.microsoft.com/l/entity/' +
785
810
  encodeURIComponent(params.appId) +
@@ -1808,6 +1833,10 @@ var app_app;
1808
1833
  return GlobalVars.frameContext;
1809
1834
  }
1810
1835
  app.getFrameContext = getFrameContext;
1836
+ /**
1837
+ * Number of milliseconds we'll give the initialization call to return before timing it out
1838
+ */
1839
+ var initializationTimeoutInMs = 5000;
1811
1840
  /**
1812
1841
  * Initializes the library.
1813
1842
  *
@@ -1817,9 +1846,13 @@ var app_app;
1817
1846
  *
1818
1847
  * @param validMessageOrigins - Optionally specify a list of cross frame message origins. They must have
1819
1848
  * https: protocol otherwise they will be ignored. Example: https:www.example.com
1820
- * @returns Promise that will be fulfilled when initialization has completed
1849
+ * @returns Promise that will be fulfilled when initialization has completed, or rejected if the initialization fails or times out
1821
1850
  */
1822
1851
  function initialize(validMessageOrigins) {
1852
+ return runWithTimeout(function () { return initializeHelper(validMessageOrigins); }, initializationTimeoutInMs, new Error('SDK initialization timed out.'));
1853
+ }
1854
+ app.initialize = initialize;
1855
+ function initializeHelper(validMessageOrigins) {
1823
1856
  return new Promise(function (resolve) {
1824
1857
  // Independent components might not know whether the SDK is initialized so might call it to be safe.
1825
1858
  // Just no-op if that happens to make it easier to use.
@@ -1884,7 +1917,6 @@ var app_app;
1884
1917
  resolve(GlobalVars.initializePromise);
1885
1918
  });
1886
1919
  }
1887
- app.initialize = initialize;
1888
1920
  /**
1889
1921
  * @hidden
1890
1922
  * Hide from docs.
@@ -2694,10 +2726,15 @@ function initializeCommunication(validMessageOrigins) {
2694
2726
  Communication.currentWindow.addEventListener('message', CommunicationPrivate.messageListener, false);
2695
2727
  }
2696
2728
  if (!Communication.parentWindow) {
2697
- GlobalVars.isFramelessWindow = true;
2698
- /* eslint-disable @typescript-eslint/ban-ts-comment */
2699
- // @ts-ignore: window as ExtendedWindow
2700
- window.onNativeMessage = handleParentMessage;
2729
+ var extendedWindow = Communication.currentWindow;
2730
+ if (extendedWindow.nativeInterface) {
2731
+ GlobalVars.isFramelessWindow = true;
2732
+ extendedWindow.onNativeMessage = handleParentMessage;
2733
+ }
2734
+ else {
2735
+ // at this point we weren't able to find a parent to talk to, no way initialization will succeed
2736
+ return Promise.reject(new Error('Initialization Failed. No Parent window found.'));
2737
+ }
2701
2738
  }
2702
2739
  try {
2703
2740
  // Send the initialized message to any origin, because at this point we most likely don't know the origin
@@ -4261,6 +4298,7 @@ var meeting;
4261
4298
 
4262
4299
 
4263
4300
 
4301
+
4264
4302
  /**
4265
4303
  * @alpha
4266
4304
  */
@@ -4268,21 +4306,30 @@ var monetization;
4268
4306
  (function (monetization) {
4269
4307
  /**
4270
4308
  * @hidden
4271
- * Hide from docs
4272
- * Open dialog to start user's purchase experience
4273
- *
4274
- * @param callback Callback contains 1 parameters, error.
4275
- * @param planInfo optional parameter. It contains info of the subscription plan pushed to users.
4276
- * error can either contain an error of type SdkError, incase of an error, or null when get is successful
4277
- *
4278
- * @internal
4309
+ * This function is the overloaded implementation of openPurchaseExperience.
4310
+ * Since the method signatures of the v1 callback and v2 promise differ in the type of the first parameter,
4311
+ * we need to do an extra check to know the typeof the @param1 to set the proper arguments of the utility function.
4312
+ * @param param1
4313
+ * @param param2
4314
+ * @returns Promise that will be resolved when the operation has completed or rejected with SdkError value
4279
4315
  */
4280
- function openPurchaseExperience(callback, planInfo) {
4281
- if (!callback) {
4282
- throw new Error('[open purchase experience] Callback cannot be null');
4316
+ function openPurchaseExperience(param1, param2) {
4317
+ var callback;
4318
+ var planInfo;
4319
+ if (typeof param1 === 'function') {
4320
+ callback = param1;
4321
+ planInfo = param2;
4283
4322
  }
4323
+ else {
4324
+ planInfo = param1;
4325
+ }
4326
+ var wrappedFunction = function () {
4327
+ return new Promise(function (resolve) {
4328
+ resolve(sendAndHandleSdkError('monetization.openPurchaseExperience', planInfo));
4329
+ });
4330
+ };
4284
4331
  ensureInitialized(FrameContexts.content);
4285
- sendMessageToParent('monetization.openPurchaseExperience', [planInfo], callback);
4332
+ return callCallbackWithErrorOrResultOrNullFromPromiseAndReturnPromise(wrappedFunction, callback);
4286
4333
  }
4287
4334
  monetization.openPurchaseExperience = openPurchaseExperience;
4288
4335
  function isSupported() {
@@ -4518,6 +4565,7 @@ var video;
4518
4565
 
4519
4566
 
4520
4567
 
4568
+
4521
4569
  /**
4522
4570
  * @alpha
4523
4571
  */
@@ -4526,88 +4574,74 @@ var sharing;
4526
4574
  sharing.SharingAPIMessages = {
4527
4575
  shareWebContent: 'sharing.shareWebContent',
4528
4576
  };
4529
- /**
4530
- * @hidden
4531
- * Feature is under development
4532
- * Opens a share dialog for web content
4533
- *
4534
- * @param shareWebContentRequest - web content info
4535
- * @param callback - optional callback
4536
- *
4537
- * @internal
4538
- */
4539
4577
  function shareWebContent(shareWebContentRequest, callback) {
4540
- if (!validateNonEmptyContent(shareWebContentRequest, callback)) {
4541
- return;
4542
- }
4543
- if (!validateTypeConsistency(shareWebContentRequest, callback)) {
4544
- return;
4578
+ // validate the given input (synchronous check)
4579
+ try {
4580
+ validateNonEmptyContent(shareWebContentRequest);
4581
+ validateTypeConsistency(shareWebContentRequest);
4582
+ validateContentForSupportedTypes(shareWebContentRequest);
4545
4583
  }
4546
- if (!validateContentForSupportedTypes(shareWebContentRequest, callback)) {
4547
- return;
4584
+ catch (err) {
4585
+ //return the error via callback(v1) or rejected promise(v2)
4586
+ var wrappedFunction = function () { return Promise.reject(err); };
4587
+ return callCallbackWithSdkErrorFromPromiseAndReturnPromise(wrappedFunction, callback);
4548
4588
  }
4549
4589
  ensureInitialized(FrameContexts.content, FrameContexts.sidePanel, FrameContexts.task, FrameContexts.stage, FrameContexts.meetingStage);
4550
- sendMessageToParent(sharing.SharingAPIMessages.shareWebContent, [shareWebContentRequest], callback);
4590
+ return callCallbackWithSdkErrorFromPromiseAndReturnPromise(shareWebContentHelper, callback, shareWebContentRequest);
4551
4591
  }
4552
4592
  sharing.shareWebContent = shareWebContent;
4593
+ function shareWebContentHelper(shareWebContentRequest) {
4594
+ return new Promise(function (resolve) {
4595
+ resolve(sendAndHandleSdkError(sharing.SharingAPIMessages.shareWebContent, shareWebContentRequest));
4596
+ });
4597
+ }
4553
4598
  /**
4554
- * Error checks
4599
+ * Functions for validating the shareRequest input parameter
4555
4600
  */
4556
- function validateNonEmptyContent(shareRequest, callback) {
4601
+ function validateNonEmptyContent(shareRequest) {
4557
4602
  if (!(shareRequest && shareRequest.content && shareRequest.content.length)) {
4558
- if (callback) {
4559
- callback({
4560
- errorCode: ErrorCode.INVALID_ARGUMENTS,
4561
- message: 'Shared content is missing',
4562
- });
4563
- }
4564
- return false;
4603
+ var err = {
4604
+ errorCode: ErrorCode.INVALID_ARGUMENTS,
4605
+ message: 'Shared content is missing',
4606
+ };
4607
+ throw err;
4565
4608
  }
4566
- return true;
4567
4609
  }
4568
- function validateTypeConsistency(shareRequest, callback) {
4610
+ function validateTypeConsistency(shareRequest) {
4611
+ var err;
4569
4612
  if (shareRequest.content.some(function (item) { return !item.type; })) {
4570
- if (callback) {
4571
- callback({
4572
- errorCode: ErrorCode.INVALID_ARGUMENTS,
4573
- message: 'Shared content type cannot be undefined',
4574
- });
4575
- }
4576
- return false;
4613
+ err = {
4614
+ errorCode: ErrorCode.INVALID_ARGUMENTS,
4615
+ message: 'Shared content type cannot be undefined',
4616
+ };
4617
+ throw err;
4577
4618
  }
4578
4619
  if (shareRequest.content.some(function (item) { return item.type !== shareRequest.content[0].type; })) {
4579
- if (callback) {
4580
- callback({
4581
- errorCode: ErrorCode.INVALID_ARGUMENTS,
4582
- message: 'Shared content must be of the same type',
4583
- });
4584
- }
4585
- return false;
4620
+ err = {
4621
+ errorCode: ErrorCode.INVALID_ARGUMENTS,
4622
+ message: 'Shared content must be of the same type',
4623
+ };
4624
+ throw err;
4586
4625
  }
4587
- return true;
4588
4626
  }
4589
- function validateContentForSupportedTypes(shareRequest, callback) {
4627
+ function validateContentForSupportedTypes(shareRequest) {
4628
+ var err;
4590
4629
  if (shareRequest.content[0].type === 'URL') {
4591
4630
  if (shareRequest.content.some(function (item) { return !item.url; })) {
4592
- if (callback) {
4593
- callback({
4594
- errorCode: ErrorCode.INVALID_ARGUMENTS,
4595
- message: 'URLs are required for URL content types',
4596
- });
4597
- }
4598
- return false;
4631
+ err = {
4632
+ errorCode: ErrorCode.INVALID_ARGUMENTS,
4633
+ message: 'URLs are required for URL content types',
4634
+ };
4635
+ throw err;
4599
4636
  }
4600
4637
  }
4601
4638
  else {
4602
- if (callback) {
4603
- callback({
4604
- errorCode: ErrorCode.INVALID_ARGUMENTS,
4605
- message: 'Content type is unsupported',
4606
- });
4607
- }
4608
- return false;
4639
+ err = {
4640
+ errorCode: ErrorCode.INVALID_ARGUMENTS,
4641
+ message: 'Content type is unsupported',
4642
+ };
4643
+ throw err;
4609
4644
  }
4610
- return true;
4611
4645
  }
4612
4646
  function isSupported() {
4613
4647
  return runtime.supports.sharing ? true : false;
@@ -4725,6 +4759,7 @@ var appInitialization;
4725
4759
 
4726
4760
 
4727
4761
 
4762
+
4728
4763
  /**
4729
4764
  * @deprecated
4730
4765
  * As of 2.0.0-beta.1, please use {@link app.initialize app.initialize(validMessageOrigins?: string[]): Promise\<void\>} instead.
@@ -4979,16 +5014,13 @@ function shareDeepLink(deepLinkParameters) {
4979
5014
  */
4980
5015
  function executeDeepLink(deepLink, onComplete) {
4981
5016
  ensureInitialized(FrameContexts.content, FrameContexts.sidePanel, FrameContexts.settings, FrameContexts.task, FrameContexts.stage, FrameContexts.meetingStage);
5017
+ onComplete = onComplete ? onComplete : getGenericOnCompleteHandler();
4982
5018
  core.executeDeepLink(deepLink)
4983
5019
  .then(function () {
4984
- if (onComplete) {
4985
- onComplete(true);
4986
- }
5020
+ onComplete(true);
4987
5021
  })
4988
5022
  .catch(function (err) {
4989
- if (onComplete) {
4990
- onComplete(false, err.message);
4991
- }
5023
+ onComplete(false, err.message);
4992
5024
  });
4993
5025
  }
4994
5026
  /**
@@ -5095,6 +5127,7 @@ function transformAppContextToLegacyContext(appContext) {
5095
5127
 
5096
5128
 
5097
5129
 
5130
+
5098
5131
  /**
5099
5132
  * Navigation specific part of the SDK.
5100
5133
  */
@@ -5120,16 +5153,13 @@ function returnFocus(navigateForward) {
5120
5153
  */
5121
5154
  function navigateToTab(tabInstance, onComplete) {
5122
5155
  ensureInitialized();
5156
+ onComplete = onComplete ? onComplete : getGenericOnCompleteHandler();
5123
5157
  pages.tabs.navigateToTab(tabInstance)
5124
5158
  .then(function () {
5125
- if (onComplete) {
5126
- onComplete(true);
5127
- }
5159
+ onComplete(true);
5128
5160
  })
5129
5161
  .catch(function (error) {
5130
- if (onComplete) {
5131
- onComplete(false, error.message);
5132
- }
5162
+ onComplete(false, error.message);
5133
5163
  });
5134
5164
  }
5135
5165
  /**
@@ -5147,16 +5177,13 @@ function navigateToTab(tabInstance, onComplete) {
5147
5177
  */
5148
5178
  function navigateCrossDomain(url, onComplete) {
5149
5179
  ensureInitialized(FrameContexts.content, FrameContexts.sidePanel, FrameContexts.settings, FrameContexts.remove, FrameContexts.task, FrameContexts.stage, FrameContexts.meetingStage);
5180
+ onComplete = onComplete ? onComplete : getGenericOnCompleteHandler();
5150
5181
  pages.navigateCrossDomain(url)
5151
5182
  .then(function () {
5152
- if (onComplete) {
5153
- onComplete(true);
5154
- }
5183
+ onComplete(true);
5155
5184
  })
5156
5185
  .catch(function (error) {
5157
- if (onComplete) {
5158
- onComplete(false, error.message);
5159
- }
5186
+ onComplete(false, error.message);
5160
5187
  });
5161
5188
  }
5162
5189
  /**
@@ -5170,16 +5197,13 @@ function navigateCrossDomain(url, onComplete) {
5170
5197
  */
5171
5198
  function navigateBack(onComplete) {
5172
5199
  ensureInitialized();
5200
+ onComplete = onComplete ? onComplete : getGenericOnCompleteHandler();
5173
5201
  pages.backStack.navigateBack()
5174
5202
  .then(function () {
5175
- if (onComplete) {
5176
- onComplete(true);
5177
- }
5203
+ onComplete(true);
5178
5204
  })
5179
5205
  .catch(function (error) {
5180
- if (onComplete) {
5181
- onComplete(false, error.message);
5182
- }
5206
+ onComplete(false, error.message);
5183
5207
  });
5184
5208
  }
5185
5209
 
@@ -5187,6 +5211,7 @@ function navigateBack(onComplete) {
5187
5211
 
5188
5212
 
5189
5213
 
5214
+
5190
5215
  /**
5191
5216
  * @deprecated
5192
5217
  * As of 2.0.0-beta.1, please use {@link pages.config} namespace instead.
@@ -5235,16 +5260,13 @@ var settings;
5235
5260
  */
5236
5261
  function setSettings(instanceSettings, onComplete) {
5237
5262
  ensureInitialized(FrameContexts.content, FrameContexts.settings, FrameContexts.sidePanel);
5263
+ onComplete = onComplete ? onComplete : getGenericOnCompleteHandler();
5238
5264
  pages.config.setConfig(instanceSettings)
5239
5265
  .then(function () {
5240
- if (onComplete) {
5241
- onComplete(true);
5242
- }
5266
+ onComplete(true);
5243
5267
  })
5244
5268
  .catch(function (error) {
5245
- if (onComplete) {
5246
- onComplete(false, error.message);
5247
- }
5269
+ onComplete(false, error.message);
5248
5270
  });
5249
5271
  }
5250
5272
  settings.setSettings = setSettings;