@imposium-hub/components 2.5.18 → 2.6.0-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.
Files changed (77) hide show
  1. package/dist/cjs/Util.js +1 -2
  2. package/dist/cjs/Util.js.map +1 -1
  3. package/dist/cjs/components/app-wrapper/AppWrapper.d.ts +14 -22
  4. package/dist/cjs/components/app-wrapper/AppWrapper.js +170 -216
  5. package/dist/cjs/components/app-wrapper/AppWrapper.js.map +1 -1
  6. package/dist/cjs/components/app-wrapper/AppWrapperV2.d.ts +3 -9
  7. package/dist/cjs/components/app-wrapper/AppWrapperV2.js +119 -45
  8. package/dist/cjs/components/app-wrapper/AppWrapperV2.js.map +1 -1
  9. package/dist/cjs/components/app-wrapper/AppWrapperV3.d.ts +1 -1
  10. package/dist/cjs/components/app-wrapper/AppWrapperV3.js +7 -44
  11. package/dist/cjs/components/app-wrapper/AppWrapperV3.js.map +1 -1
  12. package/dist/cjs/components/compositions/TextLayer.js +0 -1
  13. package/dist/cjs/components/compositions/TextLayer.js.map +1 -1
  14. package/dist/cjs/components/header/Header.d.ts +6 -5
  15. package/dist/cjs/components/header/Header.js +46 -62
  16. package/dist/cjs/components/header/Header.js.map +1 -1
  17. package/dist/cjs/components/modal/Modal.d.ts +1 -1
  18. package/dist/cjs/components/modal/Modal.js +2 -3
  19. package/dist/cjs/components/modal/Modal.js.map +1 -1
  20. package/dist/cjs/index.d.ts +2 -7
  21. package/dist/cjs/index.js +5 -17
  22. package/dist/cjs/index.js.map +1 -1
  23. package/dist/cjs/redux/actions/asset-uploads.js +0 -1
  24. package/dist/cjs/redux/actions/asset-uploads.js.map +1 -1
  25. package/dist/cjs/services/API.d.ts +6 -2
  26. package/dist/cjs/services/API.js +38 -15
  27. package/dist/cjs/services/API.js.map +1 -1
  28. package/dist/cjs/services/Session.d.ts +0 -11
  29. package/dist/cjs/services/Session.js +3 -126
  30. package/dist/cjs/services/Session.js.map +1 -1
  31. package/dist/esm/Util.js +1 -2
  32. package/dist/esm/Util.js.map +1 -1
  33. package/dist/esm/components/app-wrapper/AppWrapper.d.ts +14 -22
  34. package/dist/esm/components/app-wrapper/AppWrapper.js +75 -182
  35. package/dist/esm/components/app-wrapper/AppWrapper.js.map +1 -1
  36. package/dist/esm/components/app-wrapper/AppWrapperV2.d.ts +3 -9
  37. package/dist/esm/components/app-wrapper/AppWrapperV2.js +30 -33
  38. package/dist/esm/components/app-wrapper/AppWrapperV2.js.map +1 -1
  39. package/dist/esm/components/app-wrapper/AppWrapperV3.d.ts +1 -1
  40. package/dist/esm/components/app-wrapper/AppWrapperV3.js +5 -42
  41. package/dist/esm/components/app-wrapper/AppWrapperV3.js.map +1 -1
  42. package/dist/esm/components/compositions/TextLayer.js +0 -1
  43. package/dist/esm/components/compositions/TextLayer.js.map +1 -1
  44. package/dist/esm/components/header/Header.d.ts +6 -5
  45. package/dist/esm/components/header/Header.js +46 -60
  46. package/dist/esm/components/header/Header.js.map +1 -1
  47. package/dist/esm/components/modal/Modal.d.ts +1 -1
  48. package/dist/esm/components/modal/Modal.js +2 -3
  49. package/dist/esm/components/modal/Modal.js.map +1 -1
  50. package/dist/esm/index.d.ts +2 -7
  51. package/dist/esm/index.js +2 -7
  52. package/dist/esm/index.js.map +1 -1
  53. package/dist/esm/redux/actions/asset-uploads.js +0 -1
  54. package/dist/esm/redux/actions/asset-uploads.js.map +1 -1
  55. package/dist/esm/services/API.d.ts +6 -2
  56. package/dist/esm/services/API.js +37 -15
  57. package/dist/esm/services/API.js.map +1 -1
  58. package/dist/esm/services/Session.d.ts +0 -11
  59. package/dist/esm/services/Session.js +3 -84
  60. package/dist/esm/services/Session.js.map +1 -1
  61. package/dist/styles.css +0 -5
  62. package/dist/styles.less +0 -1
  63. package/less/components/button.less +0 -1
  64. package/package.json +3 -2
  65. package/src/Util.ts +1 -2
  66. package/src/components/app-wrapper/AppWrapper.tsx +131 -272
  67. package/src/components/compositions/TextLayer.tsx +0 -1
  68. package/src/components/header/Header.tsx +55 -80
  69. package/src/components/modal/Modal.tsx +7 -10
  70. package/src/index.ts +1 -14
  71. package/src/redux/actions/asset-uploads.ts +0 -1
  72. package/src/services/API.ts +48 -17
  73. package/src/components/auth-gate/AuthGate.tsx +0 -84
  74. package/src/redux/actions/auth.ts +0 -30
  75. package/src/redux/reducers/auth.ts +0 -33
  76. package/src/services/Auth0.ts +0 -82
  77. package/src/services/Session.ts +0 -153
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import ImposiumDropdown from '../dropdown/Dropdown';
3
3
  import ServiceIcon from '../service-icon/ServiceIcon';
4
- import { string2HexCode, parameterizeServiceUrl } from '../../Util';
4
+ import { string2HexCode, parameterizeServiceUrl, getLastModifiedStoryInOrg } from '../../Util';
5
5
  import {
6
6
  ICON_CHEVRON_DOWN,
7
7
  ICON_CHEVRON_UP,
@@ -9,11 +9,9 @@ import {
9
9
  ICON_UP_RIGHT_FROM_SQUARE
10
10
  } from '../../constants/icons';
11
11
  import { connect } from 'react-redux';
12
- import Spinner from '../spinner/Spinner';
13
12
  import _ from 'lodash';
14
13
  import DataTable from '../data-table/DataTable';
15
14
  import AssetsTableDateCell from '../assets/AssetsTableDateCell';
16
- import SessionService, { IHubSession } from '../../services/Session';
17
15
  import Button from '../button/Button';
18
16
  import Select, { createFilter } from 'react-select';
19
17
  import { setAccessData } from '../../redux/actions/access';
@@ -21,22 +19,24 @@ import { bindActionCreators } from 'redux';
21
19
  import { StoryTableTotalRendersCell } from '../assets/StoryTableTotalRendersCell';
22
20
  import StoryTableNameFilter from '../assets/StoryTableNameFilter';
23
21
  import { updateStoryFilter } from '../../redux/actions/story-filter';
22
+ import { IImposiumAPI } from '../../services/API';
24
23
 
25
24
  export interface IHeaderProps {
26
- email?: string;
25
+ auth0: any;
26
+ api: IImposiumAPI;
27
+ activeServiceId: string;
27
28
  activeOrganization: string;
28
29
  activeStory?: string;
29
30
  hideStoryPicker?: boolean;
30
31
  hideOrgPicker?: boolean;
31
32
  setAccessData(access: any): void;
32
- onOrganizationChange?: (orgId: any) => any;
33
+ onOrganizationChange?: (orgId: string, storyId: string) => any;
33
34
  onStoryChange?: (story: any) => any;
34
- logout: (...args) => any;
35
+ onLogout();
35
36
  additionalButtons?: any[];
36
37
  CrMLink?: string;
37
38
  auth: any;
38
39
  story: any;
39
- baseUrl: any;
40
40
  hideDocs?: boolean;
41
41
  showFTLogo?: boolean;
42
42
  access: any;
@@ -47,7 +47,6 @@ export interface IHeaderProps {
47
47
  export interface IHeaderState {
48
48
  inactiveOrganizations: any[];
49
49
  servicesByOrganization: any[];
50
- activeServiceBlob: any;
51
50
  activeOrganizationBlob: any;
52
51
  showAccountDropdown: boolean;
53
52
  showStoriesDropdown: boolean;
@@ -100,7 +99,6 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
100
99
  this.state = {
101
100
  inactiveOrganizations: [],
102
101
  servicesByOrganization: [],
103
- activeServiceBlob: undefined,
104
102
  activeOrganizationBlob: undefined,
105
103
  showAccountDropdown: false,
106
104
  showStoriesDropdown: false,
@@ -136,28 +134,20 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
136
134
  private parseAccessData = (accessData: any, activeOrganization: string): void => {
137
135
  const { organizations, services } = accessData;
138
136
 
139
- let activeOrgId = activeOrganization;
140
- if (activeOrgId === 'undefined') {
141
- const session: IHubSession = SessionService.getSession();
142
- activeOrgId = session.organization_id;
143
- }
144
- const activeOrganizationBlob: any = activeOrgId
145
- ? accessData.organizations.find((org) => org.id === activeOrgId)
137
+ const activeOrganizationBlob: any = activeOrganization
138
+ ? accessData.organizations.find((org) => org.id === activeOrganization)
146
139
  : undefined;
147
140
 
148
141
  const inactiveOrganizations: any[] =
149
- organizations.length > 1 ? organizations.filter((o) => o.id !== activeOrgId) : [];
142
+ organizations.length > 1
143
+ ? organizations.filter((o) => o.id !== activeOrganization)
144
+ : [];
150
145
 
151
146
  const servicesByOrganization: any[] =
152
147
  services && activeOrganizationBlob
153
148
  ? services.filter((s: any) => activeOrganizationBlob.services.includes(s.id))
154
149
  : [];
155
150
 
156
- const activeServiceBlob: any =
157
- servicesByOrganization.length > 1
158
- ? services.find((s: any) => window.location.href.includes(s.url))
159
- : undefined;
160
-
161
151
  let dropdownToggleColor: string = ImposiumHeader.DEFAULT_ACCOUNT_TOGGLE_COLOR;
162
152
  let activeFirstChar: string = '';
163
153
 
@@ -168,7 +158,6 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
168
158
 
169
159
  this.setState({
170
160
  servicesByOrganization,
171
- activeServiceBlob,
172
161
  inactiveOrganizations,
173
162
  activeOrganizationBlob,
174
163
  dropdownToggleColor,
@@ -183,51 +172,42 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
183
172
  }
184
173
 
185
174
  private changeStory = (story: any): void => {
186
- const { onStoryChange } = this.props;
175
+ const { onStoryChange, activeOrganization, api, activeServiceId } = this.props;
187
176
 
188
177
  if (typeof onStoryChange === 'function') {
189
178
  onStoryChange(story);
179
+ api.cacheActiveStory(activeServiceId, activeOrganization, story.id);
190
180
  this.closeStoriesDropDown();
191
181
  }
192
182
  };
193
183
 
194
- private toggleAccountDropdown = (toggle: boolean, newId: string = ''): void => {
195
- const { onOrganizationChange } = this.props;
196
-
184
+ private toggleAccountDropdown = (toggle: boolean, orgId: string = ''): void => {
185
+ const { onOrganizationChange, api, activeServiceId } = this.props;
197
186
  if (toggle) {
198
187
  this.setState({ showAccountDropdown: true });
199
188
  } else {
200
189
  this.setState({ showAccountDropdown: false });
201
-
202
- // Propagate handler if supplied (more useful in react / redux flow)
203
- if (newId && onOrganizationChange) {
204
- onOrganizationChange(newId);
190
+ const lastModified = getLastModifiedStoryInOrg(orgId, this.props.access);
191
+
192
+ if (orgId && onOrganizationChange) {
193
+ let storyId = lastModified;
194
+ api.getCachedStoryForOrg(activeServiceId, orgId)
195
+ .then((res) => {
196
+ storyId = res.story_id ? res.story_id : lastModified;
197
+ onOrganizationChange(orgId, storyId);
198
+ })
199
+ .catch((e) => {
200
+ console.error('Error getting cached storyID for Org');
201
+ onOrganizationChange(orgId, storyId);
202
+ });
203
+ api.cacheActiveStory(activeServiceId, orgId, storyId);
205
204
  }
206
-
207
- // V1 Default behavior - redirect to hub on org change
208
- if (newId && !onOrganizationChange) {
209
- window.location.replace(`${this.getHomeUrl()}?organization_id=${newId}`);
210
- }
211
- }
212
- };
213
-
214
- private getHomeUrl = (): string => {
215
- const {
216
- location: { hostname, host }
217
- } = window;
218
-
219
- if (hostname === 'localhost') {
220
- return 'http://localhost:3036';
221
- } else if (host.includes('.staging.')) {
222
- return 'https://launchpad.staging.imposium.com';
223
- } else {
224
- return 'https://launchpad.imposium.com';
225
205
  }
226
206
  };
227
207
 
228
208
  private doLogout = (): void => {
229
209
  this.setState({ showAccountDropdown: false });
230
- this.props.logout();
210
+ this.props.onLogout();
231
211
  };
232
212
 
233
213
  private pullFirstChar = (s: string): string => {
@@ -274,25 +254,6 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
274
254
  </div>
275
255
  );
276
256
 
277
- private getAccessDataHandler = () => {
278
- const {
279
- auth: { accessToken },
280
- baseUrl,
281
- activeOrganization
282
- } = this.props;
283
-
284
- this.setState({ totalRendersLoading: true });
285
-
286
- SessionService.getAccessData(accessToken, baseUrl, true, activeOrganization)
287
- .then((res) => {
288
- this.props.setAccessData(res);
289
- this.setState({ totalRendersLoading: false });
290
- })
291
- .catch((e) => {
292
- console.error(e);
293
- });
294
- };
295
-
296
257
  private getStoriesColumns() {
297
258
  return [
298
259
  {
@@ -359,7 +320,6 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
359
320
 
360
321
  public render() {
361
322
  const {
362
- email,
363
323
  activeOrganization,
364
324
  activeStory,
365
325
  hideStoryPicker,
@@ -369,12 +329,12 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
369
329
  showFTLogo,
370
330
  hideDocs,
371
331
  access,
332
+ api,
372
333
  access: { organizations }
373
334
  } = this.props;
374
335
  const {
375
336
  showAccountDropdown,
376
337
  servicesByOrganization,
377
- activeServiceBlob,
378
338
  showStoriesDropdown,
379
339
  activeOrganizationBlob,
380
340
  activeFirstChar,
@@ -391,7 +351,7 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
391
351
  let serviceAnchors: JSX.Element[];
392
352
  let privateAnchors: JSX.Element[];
393
353
  let accountDropdownToggle: JSX.Element;
394
- let storyToggle: JSX.Element = !hideStoryPicker ? <Spinner /> : null;
354
+ let storyToggle: JSX.Element;
395
355
  let storyMenuInner: JSX.Element = (
396
356
  <div className='no-stories-dialog'>{ImposiumHeader.NO_STORIES_COPY}</div>
397
357
  );
@@ -407,8 +367,8 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
407
367
  );
408
368
 
409
369
  if (access) {
410
- activeService = servicesByOrganization.find((s: any) =>
411
- window.location.href.includes(s.url)
370
+ activeService = servicesByOrganization.find(
371
+ (s: any) => s.id === this.props.activeServiceId
412
372
  );
413
373
 
414
374
  if (activeService) {
@@ -488,9 +448,7 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
488
448
  this.setState({ showServiceDropdown: !this.state.showServiceDropdown })
489
449
  }>
490
450
  <span>
491
- {activeServiceBlob
492
- ? activeServiceBlob.name
493
- : ImposiumHeader.SERVICE_MESH_ALIAS}
451
+ {activeService ? activeService.name : ImposiumHeader.SERVICE_MESH_ALIAS}
494
452
  </span>
495
453
  {this.renderDropdownChevron(showServiceDropdown)}
496
454
  </button>
@@ -515,7 +473,12 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
515
473
  storyToggle = null;
516
474
  }
517
475
 
518
- if (access && activeOrganizationBlob && !hideStoryPicker) {
476
+ if (
477
+ access &&
478
+ activeOrganizationBlob &&
479
+ !hideStoryPicker &&
480
+ activeOrganizationBlob.stories.length > 0
481
+ ) {
519
482
  currentStory = activeOrganizationBlob.stories.find((s: any) => s.id === activeStory);
520
483
  storyToggle = (
521
484
  <button
@@ -526,7 +489,16 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
526
489
  this.setState({ showStoriesDropdown: !showStoriesDropdown }, () => {
527
490
  if (showStoriesDropdown === false) {
528
491
  this.props.updateStoryFilter({ name: '' });
529
- this.getAccessDataHandler();
492
+ this.setState({ totalRendersLoading: true });
493
+ api.getAccessData(true)
494
+ .then((res) => {
495
+ this.props.setAccessData(res);
496
+ this.setState({ totalRendersLoading: false });
497
+ })
498
+ .catch((e) => {
499
+ console.error(e);
500
+ console.error('Error getting access data from Header');
501
+ });
530
502
  }
531
503
  });
532
504
  }}>
@@ -593,6 +565,9 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
593
565
  });
594
566
  }
595
567
 
568
+ const email = '';
569
+ // const email = scrapeEmail(auth);
570
+ // TODO: plug this back in
596
571
  const orgSelect = () => {
597
572
  return (
598
573
  <>
@@ -8,7 +8,7 @@ interface IModalProps {
8
8
  isOpen: boolean;
9
9
  style?: any;
10
10
  wrapperStyle?: any;
11
- onRequestClose?(e): void;
11
+ onRequestClose(e): void;
12
12
  }
13
13
 
14
14
  class Modal extends React.PureComponent<IModalProps> {
@@ -49,14 +49,7 @@ class Modal extends React.PureComponent<IModalProps> {
49
49
  }
50
50
 
51
51
  public render() {
52
- const { isOpen, style, wrapperStyle, onRequestClose } = this.props;
53
- const btnClose = onRequestClose ? (
54
- <Button
55
- onClick={this.evtHandlers.onClose}
56
- customStyles={this.closeStyles}>
57
- {ICON_TIMES}
58
- </Button>
59
- ) : null;
52
+ const { isOpen, style, wrapperStyle } = this.props;
60
53
 
61
54
  if (isOpen) {
62
55
  return (
@@ -71,7 +64,11 @@ class Modal extends React.PureComponent<IModalProps> {
71
64
  className='modal-container'
72
65
  style={style}>
73
66
  <div className='modal-content'>{this.props.children}</div>
74
- {btnClose}
67
+ <Button
68
+ onClick={this.evtHandlers.onClose}
69
+ customStyles={this.closeStyles}>
70
+ {ICON_TIMES}
71
+ </Button>
75
72
  </div>
76
73
  </div>
77
74
  );
package/src/index.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  /*
2
2
  React Components
3
3
  */
4
- import AppWrapper from './components/app-wrapper/AppWrapper';
5
- import AuthGate from './components/auth-gate/AuthGate';
6
4
  import ImposiumHeader from './components/header/Header';
7
5
  import ImposiumDropdown from './components/dropdown/Dropdown';
8
6
  import Button from './components/button/Button';
@@ -74,8 +72,6 @@ import SMPTEField from './components/smpte-field/SMPTEField';
74
72
  /*
75
73
  Redux Handlers / Thunks
76
74
  */
77
- import auth from './redux/reducers/auth';
78
- import { login, clearCachedAuth } from './redux/actions/auth';
79
75
  import access from './redux/reducers/access';
80
76
  import publish from './redux/reducers/publish';
81
77
  import {
@@ -118,8 +114,6 @@ import batchActions from './redux/actions/active-batch';
118
114
  /*
119
115
  Statics / Services
120
116
  */
121
- import AuthService, { IIdentity } from './services/Auth0';
122
- import SessionService, { IHubSession } from './services/Session';
123
117
  import API, { IImposiumAPI } from './services/API';
124
118
  import LegacyAPI from './services/API-Legacy';
125
119
  import StorageService from './services/Storage';
@@ -164,10 +158,10 @@ import AssetsTableAssetIdCell from './components/assets/AssetsTableAssetIdCell';
164
158
  import { resetStoryFilter, updateStoryFilter } from './redux/actions/story-filter';
165
159
  import storyFilter from './redux/reducers/story-filter';
166
160
  import StoryTableNameFilter from './components/assets/StoryTableNameFilter';
161
+ import { AppWrapper } from './components/app-wrapper/AppWrapper';
167
162
 
168
163
  export {
169
164
  AppWrapper,
170
- AuthGate,
171
165
  ImposiumHeader,
172
166
  ImposiumDropdown,
173
167
  Button,
@@ -239,9 +233,6 @@ export {
239
233
  DroppableAssetRenderer,
240
234
  PreviewNotAvailable,
241
235
  IStaticComposition,
242
- auth,
243
- login,
244
- clearCachedAuth,
245
236
  access,
246
237
  setAccessData,
247
238
  storyAdded,
@@ -276,10 +267,6 @@ export {
276
267
  assetActions,
277
268
  activeBatch,
278
269
  batchActions,
279
- AuthService,
280
- IIdentity,
281
- SessionService,
282
- IHubSession,
283
270
  API,
284
271
  IImposiumAPI,
285
272
  LegacyAPI,
@@ -410,7 +410,6 @@ const pollAssetJobs = (api, ongoingJobs: any[], timeout: number): void => {
410
410
  );
411
411
  }
412
412
  }
413
- // TODO: handle errored out
414
413
  });
415
414
 
416
415
  if (ongoingJobs.length > 0) {
@@ -8,10 +8,8 @@ import axios, {
8
8
  } from 'axios';
9
9
  import { isObjEmpty } from '../Util';
10
10
  import { JOB_TYPES } from '../constants/api';
11
- import { assets as copy } from '../constants/copy';
12
11
 
13
12
  export interface IImposiumAPI {
14
- updateProjectVersion(storyId: string);
15
13
  getAssets(filters: any, storyId: string, unprocessed?: boolean, showVariables?: boolean);
16
14
  getAssetItem(assetId: string);
17
15
  uploadAsset(
@@ -147,6 +145,9 @@ export interface IImposiumAPI {
147
145
  getAssetMap(storyId: string);
148
146
  clearStoryCache(storyId: string);
149
147
  debugId(id: string);
148
+ cacheActiveStory(serviceId: string, orgId: string, storyId: string);
149
+ getCachedStoryForOrg(serviceId: string, orgId: string);
150
+ getAccessData(includeTotalRenders?: boolean, orgId?: string);
150
151
  }
151
152
 
152
153
  interface ITTSOptions {
@@ -184,14 +185,19 @@ export default class API {
184
185
 
185
186
  constructor(baseURL: string, idToken: string, organizationId?: string) {
186
187
  // JWT
188
+ const headers = {
189
+ 'Authorization': `Bearer ${idToken}`,
190
+ 'X-Imposium-API-Version': '2.0.2'
191
+ // 'X-Imposium-Account-Id': organizationId || ''
192
+ };
193
+
187
194
  if (organizationId) {
195
+ headers['X-Imposium-Account-Id'] = organizationId;
196
+ }
197
+ if (idToken) {
188
198
  this.http = axios.create({
189
199
  baseURL,
190
- headers: {
191
- 'Authorization': `Bearer ${idToken}`,
192
- 'X-Imposium-API-Version': '2.0.2',
193
- 'X-Imposium-Account-Id': organizationId || ''
194
- }
200
+ headers
195
201
  });
196
202
 
197
203
  // Basic Access Key
@@ -222,21 +228,11 @@ export default class API {
222
228
  if (!axios.isCancel(e) && reqAlias) {
223
229
  this.clearCache(reqAlias);
224
230
  }
225
- if (e.response && (e.response.status === 403 || e.response.status === 401)) {
226
- alert(copy.sessionExpired);
227
- }
228
231
  reject(e);
229
232
  });
230
233
  });
231
234
  };
232
235
 
233
- public updateProjectVersion = (storyId: string): Promise<any | Error> => {
234
- return this.doRequest({
235
- method: 'POST',
236
- url: `/story/${storyId}/update-project-version`
237
- });
238
- };
239
-
240
236
  public saveQueueAssoc = (
241
237
  queueId: string,
242
238
  storyId: string,
@@ -1657,4 +1653,39 @@ export default class API {
1657
1653
  method: 'GET'
1658
1654
  });
1659
1655
  };
1656
+
1657
+ public cacheActiveStory = (serviceId, orgId, storyId): Promise<any | Error> => {
1658
+ const route = `/service/${serviceId}/${orgId}/active`;
1659
+
1660
+ return this.doRequest({
1661
+ method: 'POST',
1662
+ url: route,
1663
+ data: {
1664
+ story_id: storyId,
1665
+ organization_id: orgId
1666
+ }
1667
+ });
1668
+ };
1669
+
1670
+ public getCachedStoryForOrg = (serviceId, orgId): Promise<any | Error> => {
1671
+ const route = `/service/${serviceId}/${orgId}/last_active`;
1672
+
1673
+ return this.doRequest({
1674
+ method: 'GET',
1675
+ url: route
1676
+ });
1677
+ };
1678
+
1679
+ public getAccessData = (getTotalRenders: boolean = false): Promise<any | Error> => {
1680
+ let route = `/access`;
1681
+
1682
+ if (getTotalRenders) {
1683
+ route += '?include_total_renders=true';
1684
+ }
1685
+
1686
+ return this.doRequest({
1687
+ method: 'GET',
1688
+ url: route
1689
+ });
1690
+ };
1660
1691
  }
@@ -1,84 +0,0 @@
1
- import * as React from 'react';
2
- import ScaleLoader from 'react-spinners/ScaleLoader';
3
- import SessionService from '../../services/Session';
4
- import AuthService, { IIdentity } from '../../services/Auth0';
5
- import { connect } from 'react-redux';
6
- import { bindActionCreators } from 'redux';
7
- import { login } from '../../redux/actions/auth';
8
- import { setAccessData } from '../../redux/actions/access';
9
-
10
- interface IAuthGateProps {
11
- auth0ClientId: string;
12
- auth0Domain: string;
13
- auth0Hash: string;
14
- onAuthenticated: (storyId, orgId) => any;
15
- storyId: string;
16
- organizationId: string;
17
- baseUrl?: string;
18
- setAccessData(accessData: any): any;
19
- login: (id: IIdentity) => any;
20
- }
21
-
22
- class AuthGate extends React.PureComponent<IAuthGateProps> {
23
- private static readonly LOADER_COLOR: string = '#2d8ceb';
24
-
25
- constructor(p: IAuthGateProps) {
26
- super(p);
27
- }
28
-
29
- public componentDidMount = (): void => {
30
- const { auth0ClientId, auth0Hash, auth0Domain, onAuthenticated, baseUrl } = this.props;
31
-
32
- AuthService.bindToClient(auth0ClientId, auth0Domain);
33
-
34
- if (!auth0Hash) {
35
- console.info('No hash found, redirecting to login');
36
- AuthService.login();
37
- } else {
38
- AuthService.parseIdFromHash(auth0Hash)
39
- .then((freshIdentity: IIdentity) => {
40
- // Use the cached org ID and story ID if it exists
41
- const orgId = SessionService.getCachedOrgId() || null;
42
- const storyId = SessionService.getCachedStoryId() || null;
43
-
44
- SessionService.getAccessData(freshIdentity.accessToken, baseUrl, false, orgId)
45
- .then((freshAccess: any) => {
46
- this.props.login(freshIdentity);
47
- this.props.setAccessData(freshAccess);
48
- SessionService.buildFreshSession(freshIdentity, orgId, storyId);
49
- onAuthenticated(storyId, orgId);
50
- })
51
- .catch((e) => {
52
- console.error('Error getting access data, redirecting to root');
53
- console.error(e);
54
- onAuthenticated(null, null);
55
- });
56
- })
57
- .catch((e) => {
58
- console.error('Error parsing ID from hash, redirecting to login');
59
- console.error(e);
60
- AuthService.login();
61
- });
62
- }
63
- };
64
-
65
- public render = (): JSX.Element => {
66
- return (
67
- <div className='auth-gate'>
68
- <ScaleLoader color={AuthGate.LOADER_COLOR} />
69
- </div>
70
- );
71
- };
72
- }
73
-
74
- const mapDispatchToProps = (dispatch) => {
75
- return bindActionCreators(
76
- {
77
- login,
78
- setAccessData
79
- },
80
- dispatch
81
- );
82
- };
83
-
84
- export default connect(null, mapDispatchToProps)(AuthGate);
@@ -1,30 +0,0 @@
1
- import { IIdentity } from '../../services/Auth0';
2
-
3
- export const AUTH_CACHE_KEY: string = 'imposium_hub_creds';
4
-
5
- export const login = (auth: IIdentity): any => {
6
- try {
7
- localStorage.setItem(AUTH_CACHE_KEY, JSON.stringify(auth));
8
- } catch (e) {
9
- console.warn('Failed to cache auth creds...');
10
- }
11
-
12
- return { type: actions.LOGIN, auth };
13
- };
14
-
15
- export const clearCachedAuth = (): any => {
16
- try {
17
- localStorage.removeItem(AUTH_CACHE_KEY);
18
- } catch (e) {
19
- console.warn('Failed to remove cached creds');
20
- }
21
-
22
- return { type: actions.CLEAR };
23
- };
24
-
25
- const actions = {
26
- LOGIN: 'auth/LOGIN',
27
- CLEAR: 'auth/CLEAR'
28
- };
29
-
30
- export default actions;
@@ -1,33 +0,0 @@
1
- import actions, { AUTH_CACHE_KEY } from '../actions/auth';
2
- import AuthService, { IIdentity } from '../../services/Auth0';
3
-
4
- let initialState: IIdentity = null;
5
-
6
- try {
7
- const cachedAuth: IIdentity = JSON.parse(localStorage.getItem(AUTH_CACHE_KEY));
8
-
9
- if (cachedAuth) {
10
- const {
11
- idTokenPayload: { exp }
12
- } = cachedAuth;
13
-
14
- if (AuthService.checkExpiry(exp)) {
15
- initialState = cachedAuth;
16
- }
17
- }
18
- } catch (e) {
19
- console.warn('Cached credentials were malformed or missing, redirected to login.');
20
- }
21
-
22
- const auth = (state = initialState, action) => {
23
- switch (action.type) {
24
- case actions.LOGIN:
25
- return { ...action.auth };
26
- case actions.CLEAR:
27
- return null;
28
- default:
29
- return state;
30
- }
31
- };
32
-
33
- export default auth;