@sprucelabs/spruce-invite-utils 3.5.0 → 5.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.
@@ -1,12 +1,16 @@
1
+ import { SpruceSchemas } from '@sprucelabs/mercury-types';
1
2
  import { LoginAndConfirmJoinOptions, PromptForLoginAndConfirmOptions } from '../../loggingInAndConfirmingJoin/LoginAndConfirmJoinController';
2
3
  export default class LoginAndConfirmTestFixture {
3
4
  private static hitCount;
4
5
  private static wasBeforeEachCalled;
5
6
  static lastPromptOptions?: PromptForLoginAndConfirmOptions;
6
7
  static lastFactoryOptions?: LoginAndConfirmJoinOptions;
8
+ static loginAndJoinResponse: Person | null | undefined;
7
9
  static beforeEach(): void;
8
10
  static getHitCount(): number;
9
11
  private static assertBeforeEachWasCalled;
10
- static setResponse(r: boolean): void;
12
+ static setResponse(person: Person | null): void;
11
13
  private static setClass;
12
14
  }
15
+ declare type Person = SpruceSchemas.Spruce.v2020_07_22.Person;
16
+ export {};
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  const test_1 = require("@sprucelabs/test");
7
- const LoginAndConfirmJoinController_1 = __importDefault(require("../../loggingInAndConfirmingJoin/LoginAndConfirmJoinController"));
4
+ const test_utils_1 = require("@sprucelabs/test-utils");
5
+ const LoginAndConfirmJoinController_1 = require("../../loggingInAndConfirmingJoin/LoginAndConfirmJoinController");
8
6
  class LoginAndConfirmTestFixture {
9
7
  static beforeEach() {
10
8
  this.setClass(CountingLoginAndConfirmController);
@@ -18,33 +16,53 @@ class LoginAndConfirmTestFixture {
18
16
  static assertBeforeEachWasCalled() {
19
17
  test_1.assert.isTrue(this.wasBeforeEachCalled, `Make sure you call 'LoginAndConfirmTestFixture.beforeEach()' in your test!`);
20
18
  }
21
- static setResponse(r) {
19
+ static setResponse(person) {
22
20
  this.assertBeforeEachWasCalled();
23
- const Class = r
21
+ const Class = person
24
22
  ? PassingLoginAndConfirmController
25
23
  : FailingLoginAndConfirmController;
26
24
  this.setClass(Class);
25
+ this.loginAndJoinResponse = person;
27
26
  }
28
27
  static setClass(Class) {
29
- LoginAndConfirmJoinController_1.default.setClass(Class);
28
+ LoginAndConfirmJoinController_1.LoginAndConfirmJoinControllerFactory.setClass(Class);
30
29
  }
31
30
  }
32
31
  exports.default = LoginAndConfirmTestFixture;
33
32
  LoginAndConfirmTestFixture.hitCount = 0;
34
33
  LoginAndConfirmTestFixture.wasBeforeEachCalled = false;
34
+ LoginAndConfirmTestFixture.loginAndJoinResponse = undefined;
35
35
  class CountingLoginAndConfirmController {
36
36
  constructor(options) {
37
37
  LoginAndConfirmTestFixture.lastFactoryOptions = options;
38
+ this.auth = options.authenticator;
38
39
  }
39
40
  async promptForLoginAndConfirmJoin(options) {
40
41
  //@ts-ignore
41
42
  LoginAndConfirmTestFixture.hitCount++;
42
43
  LoginAndConfirmTestFixture.lastPromptOptions = options;
44
+ const response = LoginAndConfirmTestFixture.loginAndJoinResponse;
45
+ if (response) {
46
+ this.auth.setSessionToken((0, test_utils_1.generateId)(), response);
47
+ }
48
+ else if (response === null) {
49
+ this.auth.clearSession();
50
+ }
43
51
  return true;
44
52
  }
45
53
  }
46
54
  class PassingLoginAndConfirmController {
55
+ constructor(options) {
56
+ this.auth = options.authenticator;
57
+ }
47
58
  async promptForLoginAndConfirmJoin() {
59
+ const response = LoginAndConfirmTestFixture.loginAndJoinResponse;
60
+ if (response) {
61
+ this.auth.setSessionToken((0, test_utils_1.generateId)(), response);
62
+ }
63
+ else if (response === null) {
64
+ this.auth.clearSession();
65
+ }
48
66
  return true;
49
67
  }
50
68
  }
@@ -1,12 +1,16 @@
1
+ import { SpruceSchemas } from '@sprucelabs/mercury-types';
1
2
  import { LoginAndConfirmJoinOptions, PromptForLoginAndConfirmOptions } from '../../loggingInAndConfirmingJoin/LoginAndConfirmJoinController';
2
3
  export default class LoginAndConfirmTestFixture {
3
4
  private static hitCount;
4
5
  private static wasBeforeEachCalled;
5
6
  static lastPromptOptions?: PromptForLoginAndConfirmOptions;
6
7
  static lastFactoryOptions?: LoginAndConfirmJoinOptions;
8
+ static loginAndJoinResponse: Person | null | undefined;
7
9
  static beforeEach(): void;
8
10
  static getHitCount(): number;
9
11
  private static assertBeforeEachWasCalled;
10
- static setResponse(r: boolean): void;
12
+ static setResponse(person: Person | null): void;
11
13
  private static setClass;
12
14
  }
15
+ declare type Person = SpruceSchemas.Spruce.v2020_07_22.Person;
16
+ export {};
@@ -8,7 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { assert } from '@sprucelabs/test';
11
- import LoginAndConfirmJoinControllerImpl from '../../loggingInAndConfirmingJoin/LoginAndConfirmJoinController.js';
11
+ import { generateId } from '@sprucelabs/test-utils';
12
+ import { LoginAndConfirmJoinControllerFactory, } from '../../loggingInAndConfirmingJoin/LoginAndConfirmJoinController.js';
12
13
  export default class LoginAndConfirmTestFixture {
13
14
  static beforeEach() {
14
15
  this.setClass(CountingLoginAndConfirmController);
@@ -22,35 +23,55 @@ export default class LoginAndConfirmTestFixture {
22
23
  static assertBeforeEachWasCalled() {
23
24
  assert.isTrue(this.wasBeforeEachCalled, `Make sure you call 'LoginAndConfirmTestFixture.beforeEach()' in your test!`);
24
25
  }
25
- static setResponse(r) {
26
+ static setResponse(person) {
26
27
  this.assertBeforeEachWasCalled();
27
- const Class = r
28
+ const Class = person
28
29
  ? PassingLoginAndConfirmController
29
30
  : FailingLoginAndConfirmController;
30
31
  this.setClass(Class);
32
+ this.loginAndJoinResponse = person;
31
33
  }
32
34
  static setClass(Class) {
33
- LoginAndConfirmJoinControllerImpl.setClass(Class);
35
+ LoginAndConfirmJoinControllerFactory.setClass(Class);
34
36
  }
35
37
  }
36
38
  LoginAndConfirmTestFixture.hitCount = 0;
37
39
  LoginAndConfirmTestFixture.wasBeforeEachCalled = false;
40
+ LoginAndConfirmTestFixture.loginAndJoinResponse = undefined;
38
41
  class CountingLoginAndConfirmController {
39
42
  constructor(options) {
40
43
  LoginAndConfirmTestFixture.lastFactoryOptions = options;
44
+ this.auth = options.authenticator;
41
45
  }
42
46
  promptForLoginAndConfirmJoin(options) {
43
47
  return __awaiter(this, void 0, void 0, function* () {
44
48
  //@ts-ignore
45
49
  LoginAndConfirmTestFixture.hitCount++;
46
50
  LoginAndConfirmTestFixture.lastPromptOptions = options;
51
+ const response = LoginAndConfirmTestFixture.loginAndJoinResponse;
52
+ if (response) {
53
+ this.auth.setSessionToken(generateId(), response);
54
+ }
55
+ else if (response === null) {
56
+ this.auth.clearSession();
57
+ }
47
58
  return true;
48
59
  });
49
60
  }
50
61
  }
51
62
  class PassingLoginAndConfirmController {
63
+ constructor(options) {
64
+ this.auth = options.authenticator;
65
+ }
52
66
  promptForLoginAndConfirmJoin() {
53
67
  return __awaiter(this, void 0, void 0, function* () {
68
+ const response = LoginAndConfirmTestFixture.loginAndJoinResponse;
69
+ if (response) {
70
+ this.auth.setSessionToken(generateId(), response);
71
+ }
72
+ else if (response === null) {
73
+ this.auth.clearSession();
74
+ }
54
75
  return true;
55
76
  });
56
77
  }
@@ -1,5 +1,5 @@
1
1
  export { default as buildRouteToCreateInvite } from './sending/buildRouteToCreateInvite';
2
- export { default as LoginAndConfirmJoinController } from './loggingInAndConfirmingJoin/LoginAndConfirmJoinController';
2
+ export { default as LoginAndConfirmJoinControllerImpl } from './loggingInAndConfirmingJoin/LoginAndConfirmJoinController';
3
3
  export * from './loggingInAndConfirmingJoin/LoginAndConfirmJoinController';
4
4
  export { default as LoginAndConfirmTestFixture } from './__tests__/support/LoginAndConfirmTestFixture';
5
5
  export * from './__tests__/support/LoginAndConfirmTestFixture';
@@ -1,5 +1,5 @@
1
1
  export { default as buildRouteToCreateInvite } from './sending/buildRouteToCreateInvite.js';
2
- export { default as LoginAndConfirmJoinController } from './loggingInAndConfirmingJoin/LoginAndConfirmJoinController.js';
2
+ export { default as LoginAndConfirmJoinControllerImpl } from './loggingInAndConfirmingJoin/LoginAndConfirmJoinController.js';
3
3
  export * from './loggingInAndConfirmingJoin/LoginAndConfirmJoinController.js';
4
4
  export { default as LoginAndConfirmTestFixture } from './__tests__/support/LoginAndConfirmTestFixture.js';
5
5
  export * from './__tests__/support/LoginAndConfirmTestFixture.js';
@@ -1,19 +1,21 @@
1
- import { Authenticator, CardViewControllerImpl, SpruceSchemas, ViewControllerFactory } from '@sprucelabs/heartwood-view-controllers';
1
+ import { Authenticator, CardViewControllerImpl, ViewControllerFactory } from '@sprucelabs/heartwood-view-controllers';
2
2
  import { MercuryClient } from '@sprucelabs/mercury-client';
3
+ export declare class LoginAndConfirmJoinControllerFactory {
4
+ private static Class?;
5
+ static setClass(Class?: LoginAndConfirmJoinConstructor): void;
6
+ static Controller(options: LoginAndConfirmJoinOptions): LoginAndConfirmJoinController;
7
+ }
3
8
  export default class LoginAndConfirmJoinControllerImpl implements LoginAndConfirmJoinController {
4
9
  private views;
5
10
  protected vc: CardViewControllerImpl;
6
11
  private authenticator;
7
12
  private dialog?;
8
- private static Class?;
9
13
  private organizationId;
10
14
  private connectToApi;
11
15
  private client;
12
16
  private locationId?;
13
17
  private confirmJoinContext?;
14
- protected constructor(options: LoginAndConfirmJoinOptions);
15
- static setClass(Class?: LoginAndConfirmJoinConstructor): void;
16
- static Controller(options: LoginAndConfirmJoinOptions): LoginAndConfirmJoinController;
18
+ constructor(options: LoginAndConfirmJoinOptions);
17
19
  promptForLoginAndConfirmJoin(options?: PromptForLoginAndConfirmOptions): Promise<boolean>;
18
20
  private listRoles;
19
21
  private confirmTheJoin;
@@ -29,7 +31,9 @@ export interface LoginAndConfirmJoinOptions {
29
31
  }
30
32
  export declare type LoginAndConfirmJoinConstructor = new (options: LoginAndConfirmJoinOptions) => LoginAndConfirmJoinController;
31
33
  declare type ConnectToApi = () => Promise<MercuryClient>;
32
- export declare type InviteViewContext = SpruceSchemas.Invite.v2021_12_16.InviteViewContext;
34
+ export interface InviteViewContext {
35
+ roleName?: string | undefined | null;
36
+ }
33
37
  export interface PromptForLoginAndConfirmOptions {
34
38
  confirmJoinViewContext?: InviteViewContext;
35
39
  }
@@ -9,16 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { assertOptions } from '@sprucelabs/schema';
11
11
  import ConfirmJoinCardViewController from '../accepting/ConfirmJoinCard.vc.js';
12
- export default class LoginAndConfirmJoinControllerImpl {
13
- constructor(options) {
14
- const { views, authenticator, organizationId, connectToApi, locationId } = options;
15
- this.views = views;
16
- this.authenticator = authenticator;
17
- this.organizationId = organizationId;
18
- this.connectToApi = connectToApi;
19
- this.locationId = locationId;
20
- this.vc = this.views.Controller('card', {});
21
- }
12
+ export class LoginAndConfirmJoinControllerFactory {
22
13
  static setClass(Class) {
23
14
  this.Class = Class;
24
15
  }
@@ -33,7 +24,18 @@ export default class LoginAndConfirmJoinControllerImpl {
33
24
  if (!views.hasController('invite.confirm-join-card')) {
34
25
  views.setController('invite.confirm-join-card', ConfirmJoinCardViewController);
35
26
  }
36
- return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(options);
27
+ return new ((_a = this.Class) !== null && _a !== void 0 ? _a : LoginAndConfirmJoinControllerImpl)(options);
28
+ }
29
+ }
30
+ export default class LoginAndConfirmJoinControllerImpl {
31
+ constructor(options) {
32
+ const { views, authenticator, organizationId, connectToApi, locationId } = options;
33
+ this.views = views;
34
+ this.authenticator = authenticator;
35
+ this.organizationId = organizationId;
36
+ this.connectToApi = connectToApi;
37
+ this.locationId = locationId;
38
+ this.vc = this.views.Controller('card', {});
37
39
  }
38
40
  promptForLoginAndConfirmJoin(options) {
39
41
  return __awaiter(this, void 0, void 0, function* () {
@@ -1,5 +1,5 @@
1
1
  export { default as buildRouteToCreateInvite } from './sending/buildRouteToCreateInvite';
2
- export { default as LoginAndConfirmJoinController } from './loggingInAndConfirmingJoin/LoginAndConfirmJoinController';
2
+ export { default as LoginAndConfirmJoinControllerImpl } from './loggingInAndConfirmingJoin/LoginAndConfirmJoinController';
3
3
  export * from './loggingInAndConfirmingJoin/LoginAndConfirmJoinController';
4
4
  export { default as LoginAndConfirmTestFixture } from './__tests__/support/LoginAndConfirmTestFixture';
5
5
  export * from './__tests__/support/LoginAndConfirmTestFixture';
@@ -17,11 +17,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.LoginAndConfirmTestFixture = exports.LoginAndConfirmJoinController = exports.buildRouteToCreateInvite = void 0;
20
+ exports.LoginAndConfirmTestFixture = exports.LoginAndConfirmJoinControllerImpl = exports.buildRouteToCreateInvite = void 0;
21
21
  var buildRouteToCreateInvite_1 = require("./sending/buildRouteToCreateInvite");
22
22
  Object.defineProperty(exports, "buildRouteToCreateInvite", { enumerable: true, get: function () { return __importDefault(buildRouteToCreateInvite_1).default; } });
23
23
  var LoginAndConfirmJoinController_1 = require("./loggingInAndConfirmingJoin/LoginAndConfirmJoinController");
24
- Object.defineProperty(exports, "LoginAndConfirmJoinController", { enumerable: true, get: function () { return __importDefault(LoginAndConfirmJoinController_1).default; } });
24
+ Object.defineProperty(exports, "LoginAndConfirmJoinControllerImpl", { enumerable: true, get: function () { return __importDefault(LoginAndConfirmJoinController_1).default; } });
25
25
  __exportStar(require("./loggingInAndConfirmingJoin/LoginAndConfirmJoinController"), exports);
26
26
  var LoginAndConfirmTestFixture_1 = require("./__tests__/support/LoginAndConfirmTestFixture");
27
27
  Object.defineProperty(exports, "LoginAndConfirmTestFixture", { enumerable: true, get: function () { return __importDefault(LoginAndConfirmTestFixture_1).default; } });
@@ -1,19 +1,21 @@
1
- import { Authenticator, CardViewControllerImpl, SpruceSchemas, ViewControllerFactory } from '@sprucelabs/heartwood-view-controllers';
1
+ import { Authenticator, CardViewControllerImpl, ViewControllerFactory } from '@sprucelabs/heartwood-view-controllers';
2
2
  import { MercuryClient } from '@sprucelabs/mercury-client';
3
+ export declare class LoginAndConfirmJoinControllerFactory {
4
+ private static Class?;
5
+ static setClass(Class?: LoginAndConfirmJoinConstructor): void;
6
+ static Controller(options: LoginAndConfirmJoinOptions): LoginAndConfirmJoinController;
7
+ }
3
8
  export default class LoginAndConfirmJoinControllerImpl implements LoginAndConfirmJoinController {
4
9
  private views;
5
10
  protected vc: CardViewControllerImpl;
6
11
  private authenticator;
7
12
  private dialog?;
8
- private static Class?;
9
13
  private organizationId;
10
14
  private connectToApi;
11
15
  private client;
12
16
  private locationId?;
13
17
  private confirmJoinContext?;
14
- protected constructor(options: LoginAndConfirmJoinOptions);
15
- static setClass(Class?: LoginAndConfirmJoinConstructor): void;
16
- static Controller(options: LoginAndConfirmJoinOptions): LoginAndConfirmJoinController;
18
+ constructor(options: LoginAndConfirmJoinOptions);
17
19
  promptForLoginAndConfirmJoin(options?: PromptForLoginAndConfirmOptions): Promise<boolean>;
18
20
  private listRoles;
19
21
  private confirmTheJoin;
@@ -29,7 +31,9 @@ export interface LoginAndConfirmJoinOptions {
29
31
  }
30
32
  export declare type LoginAndConfirmJoinConstructor = new (options: LoginAndConfirmJoinOptions) => LoginAndConfirmJoinController;
31
33
  declare type ConnectToApi = () => Promise<MercuryClient>;
32
- export declare type InviteViewContext = SpruceSchemas.Invite.v2021_12_16.InviteViewContext;
34
+ export interface InviteViewContext {
35
+ roleName?: string | undefined | null;
36
+ }
33
37
  export interface PromptForLoginAndConfirmOptions {
34
38
  confirmJoinViewContext?: InviteViewContext;
35
39
  }
@@ -3,18 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LoginAndConfirmJoinControllerFactory = void 0;
6
7
  const schema_1 = require("@sprucelabs/schema");
7
8
  const ConfirmJoinCard_vc_1 = __importDefault(require("../accepting/ConfirmJoinCard.vc"));
8
- class LoginAndConfirmJoinControllerImpl {
9
- constructor(options) {
10
- const { views, authenticator, organizationId, connectToApi, locationId } = options;
11
- this.views = views;
12
- this.authenticator = authenticator;
13
- this.organizationId = organizationId;
14
- this.connectToApi = connectToApi;
15
- this.locationId = locationId;
16
- this.vc = this.views.Controller('card', {});
17
- }
9
+ class LoginAndConfirmJoinControllerFactory {
18
10
  static setClass(Class) {
19
11
  this.Class = Class;
20
12
  }
@@ -29,7 +21,19 @@ class LoginAndConfirmJoinControllerImpl {
29
21
  if (!views.hasController('invite.confirm-join-card')) {
30
22
  views.setController('invite.confirm-join-card', ConfirmJoinCard_vc_1.default);
31
23
  }
32
- return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(options);
24
+ return new ((_a = this.Class) !== null && _a !== void 0 ? _a : LoginAndConfirmJoinControllerImpl)(options);
25
+ }
26
+ }
27
+ exports.LoginAndConfirmJoinControllerFactory = LoginAndConfirmJoinControllerFactory;
28
+ class LoginAndConfirmJoinControllerImpl {
29
+ constructor(options) {
30
+ const { views, authenticator, organizationId, connectToApi, locationId } = options;
31
+ this.views = views;
32
+ this.authenticator = authenticator;
33
+ this.organizationId = organizationId;
34
+ this.connectToApi = connectToApi;
35
+ this.locationId = locationId;
36
+ this.vc = this.views.Controller('card', {});
33
37
  }
34
38
  async promptForLoginAndConfirmJoin(options) {
35
39
  this.client = await this.connectToApi();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-invite-utils",
3
3
  "description": "Invite Utilities",
4
- "version": "3.5.0",
4
+ "version": "5.0.0",
5
5
  "skill": {
6
6
  "namespace": "invite"
7
7
  },