@sprucelabs/spruce-invite-utils 3.2.39 → 3.3.1

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.
@@ -0,0 +1,7 @@
1
+ export default class LoginAndConfirmTestFixture {
2
+ private static hitCount;
3
+ static beforeEach(): void;
4
+ static getHitCount(): number;
5
+ static setResponse(r: boolean): void;
6
+ private static setClass;
7
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const LoginAndConfirmJoinController_1 = __importDefault(require("../../loggingInAndConfirmingJoin/LoginAndConfirmJoinController"));
7
+ class LoginAndConfirmTestFixture {
8
+ static beforeEach() {
9
+ this.setClass(CountingLoginAndConfirmController);
10
+ this.hitCount = 0;
11
+ }
12
+ static getHitCount() {
13
+ return this.hitCount;
14
+ }
15
+ static setResponse(r) {
16
+ const Class = r
17
+ ? PassingLoginAndConfirmController
18
+ : FailingLoginAndConfirmController;
19
+ this.setClass(Class);
20
+ }
21
+ static setClass(Class) {
22
+ LoginAndConfirmJoinController_1.default.setClass(Class);
23
+ }
24
+ }
25
+ exports.default = LoginAndConfirmTestFixture;
26
+ LoginAndConfirmTestFixture.hitCount = 0;
27
+ class CountingLoginAndConfirmController {
28
+ async promptForLoginAndConfirmJoin() {
29
+ //@ts-ignore
30
+ LoginAndConfirmTestFixture.hitCount++;
31
+ return true;
32
+ }
33
+ }
34
+ class PassingLoginAndConfirmController {
35
+ async promptForLoginAndConfirmJoin() {
36
+ return true;
37
+ }
38
+ }
39
+ class FailingLoginAndConfirmController {
40
+ async promptForLoginAndConfirmJoin() {
41
+ return false;
42
+ }
43
+ }
@@ -0,0 +1,7 @@
1
+ export default class LoginAndConfirmTestFixture {
2
+ private static hitCount;
3
+ static beforeEach(): void;
4
+ static getHitCount(): number;
5
+ static setResponse(r: boolean): void;
6
+ private static setClass;
7
+ }
@@ -0,0 +1,52 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import LoginAndConfirmJoinControllerImpl from '../../loggingInAndConfirmingJoin/LoginAndConfirmJoinController.js';
11
+ export default class LoginAndConfirmTestFixture {
12
+ static beforeEach() {
13
+ this.setClass(CountingLoginAndConfirmController);
14
+ this.hitCount = 0;
15
+ }
16
+ static getHitCount() {
17
+ return this.hitCount;
18
+ }
19
+ static setResponse(r) {
20
+ const Class = r
21
+ ? PassingLoginAndConfirmController
22
+ : FailingLoginAndConfirmController;
23
+ this.setClass(Class);
24
+ }
25
+ static setClass(Class) {
26
+ LoginAndConfirmJoinControllerImpl.setClass(Class);
27
+ }
28
+ }
29
+ LoginAndConfirmTestFixture.hitCount = 0;
30
+ class CountingLoginAndConfirmController {
31
+ promptForLoginAndConfirmJoin() {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ //@ts-ignore
34
+ LoginAndConfirmTestFixture.hitCount++;
35
+ return true;
36
+ });
37
+ }
38
+ }
39
+ class PassingLoginAndConfirmController {
40
+ promptForLoginAndConfirmJoin() {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ return true;
43
+ });
44
+ }
45
+ }
46
+ class FailingLoginAndConfirmController {
47
+ promptForLoginAndConfirmJoin() {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ return false;
50
+ });
51
+ }
52
+ }
@@ -1 +1,5 @@
1
1
  export { default as buildRouteToCreateInvite } from './sending/buildRouteToCreateInvite';
2
+ export { default as LoginAndConfirmJoinController } from './loggingInAndConfirmingJoin/LoginAndConfirmJoinController';
3
+ export * from './loggingInAndConfirmingJoin/LoginAndConfirmJoinController';
4
+ export { default as LoginAndConfirmTestFixture } from './__tests__/support/LoginAndConfirmTestFixture';
5
+ export * from './__tests__/support/LoginAndConfirmTestFixture';
@@ -1 +1,5 @@
1
1
  export { default as buildRouteToCreateInvite } from './sending/buildRouteToCreateInvite.js';
2
+ export { default as LoginAndConfirmJoinController } from './loggingInAndConfirmingJoin/LoginAndConfirmJoinController.js';
3
+ export * from './loggingInAndConfirmingJoin/LoginAndConfirmJoinController.js';
4
+ export { default as LoginAndConfirmTestFixture } from './__tests__/support/LoginAndConfirmTestFixture.js';
5
+ export * from './__tests__/support/LoginAndConfirmTestFixture.js';
@@ -0,0 +1,34 @@
1
+ import { Authenticator, CardViewControllerImpl, ViewControllerFactory } from '@sprucelabs/heartwood-view-controllers';
2
+ import { MercuryClient } from '@sprucelabs/mercury-client';
3
+ export interface LoginAndConfirmJoinController {
4
+ promptForLoginAndConfirmJoin(): Promise<boolean>;
5
+ }
6
+ export default class LoginAndConfirmJoinControllerImpl implements LoginAndConfirmJoinController {
7
+ private views;
8
+ protected vc: CardViewControllerImpl;
9
+ private authenticator;
10
+ private dialog?;
11
+ private static Class?;
12
+ private organizationId;
13
+ private connectToApi;
14
+ private client;
15
+ private locationId?;
16
+ protected constructor(options: LoginAndConfirmJoinOptions);
17
+ static setClass(Class?: new () => LoginAndConfirmJoinController): void;
18
+ static Controller(options: LoginAndConfirmJoinOptions): LoginAndConfirmJoinController;
19
+ promptForLoginAndConfirmJoin(): Promise<boolean>;
20
+ private listRoles;
21
+ private confirmTheJoin;
22
+ private promptForLogin;
23
+ private renderInDialogAndWait;
24
+ }
25
+ export interface LoginAndConfirmJoinOptions {
26
+ authenticator: Authenticator;
27
+ views: Pick<ViewControllerFactory, 'Controller' | 'setController'>;
28
+ organizationId: string;
29
+ locationId?: string;
30
+ connectToApi: ConnectToApi;
31
+ }
32
+ export declare type LoginAndConfirmJoinConstructor = new () => LoginAndConfirmJoinController;
33
+ declare type ConnectToApi = () => Promise<MercuryClient>;
34
+ export {};
@@ -0,0 +1,111 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { assertOptions } from '@sprucelabs/schema';
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
+ }
22
+ static setClass(Class) {
23
+ this.Class = Class;
24
+ }
25
+ static Controller(options) {
26
+ var _a;
27
+ assertOptions(options, [
28
+ 'authenticator',
29
+ 'views',
30
+ 'organizationId',
31
+ 'connectToApi',
32
+ ]);
33
+ options.views.setController('invite.confirm-join-card', ConfirmJoinCardViewController);
34
+ return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(options);
35
+ }
36
+ promptForLoginAndConfirmJoin() {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ this.client = yield this.connectToApi();
39
+ if (this.authenticator.isLoggedIn()) {
40
+ return true;
41
+ }
42
+ const person = yield this.promptForLogin();
43
+ if (!person) {
44
+ return false;
45
+ }
46
+ const roles = yield this.listRoles(person.id);
47
+ if (roles.length > 0) {
48
+ return true;
49
+ }
50
+ const confirmed = yield this.confirmTheJoin();
51
+ return confirmed;
52
+ });
53
+ }
54
+ listRoles(personId) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const [{ roles }] = yield this.client.emitAndFlattenResponses('list-roles::v2020_12_25', {
57
+ target: {
58
+ personId,
59
+ locationId: this.locationId,
60
+ organizationId: this.organizationId,
61
+ },
62
+ });
63
+ return roles;
64
+ });
65
+ }
66
+ confirmTheJoin() {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ let accepted = false;
69
+ const confirmVc = this.views.Controller('invite.confirm-join-card', {
70
+ onAccept: () => __awaiter(this, void 0, void 0, function* () {
71
+ var _a;
72
+ accepted = true;
73
+ yield ((_a = this.dialog) === null || _a === void 0 ? void 0 : _a.hide());
74
+ }),
75
+ onDecline: () => __awaiter(this, void 0, void 0, function* () {
76
+ var _b;
77
+ yield ((_b = this.dialog) === null || _b === void 0 ? void 0 : _b.hide());
78
+ }),
79
+ onError: () => { },
80
+ organizationId: this.organizationId,
81
+ authenticator: this.authenticator,
82
+ viewContext: {},
83
+ });
84
+ yield confirmVc.load();
85
+ yield this.renderInDialogAndWait(confirmVc.render());
86
+ return accepted;
87
+ });
88
+ }
89
+ promptForLogin() {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ let person;
92
+ const loginVc = this.views.Controller('login', {
93
+ onLogin: (options) => __awaiter(this, void 0, void 0, function* () {
94
+ var _a;
95
+ person = options.person;
96
+ yield ((_a = this.dialog) === null || _a === void 0 ? void 0 : _a.hide());
97
+ }),
98
+ });
99
+ yield this.renderInDialogAndWait(loginVc.render());
100
+ return person;
101
+ });
102
+ }
103
+ renderInDialogAndWait(view) {
104
+ var _a;
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ //@ts-ignore
107
+ this.dialog = this.vc.renderInDialog(view);
108
+ yield ((_a = this.dialog) === null || _a === void 0 ? void 0 : _a.wait());
109
+ });
110
+ }
111
+ }
@@ -1 +1,5 @@
1
1
  export { default as buildRouteToCreateInvite } from './sending/buildRouteToCreateInvite';
2
+ export { default as LoginAndConfirmJoinController } from './loggingInAndConfirmingJoin/LoginAndConfirmJoinController';
3
+ export * from './loggingInAndConfirmingJoin/LoginAndConfirmJoinController';
4
+ export { default as LoginAndConfirmTestFixture } from './__tests__/support/LoginAndConfirmTestFixture';
5
+ export * from './__tests__/support/LoginAndConfirmTestFixture';
@@ -1,8 +1,28 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
18
  };
5
19
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.buildRouteToCreateInvite = void 0;
20
+ exports.LoginAndConfirmTestFixture = exports.LoginAndConfirmJoinController = exports.buildRouteToCreateInvite = void 0;
7
21
  var buildRouteToCreateInvite_1 = require("./sending/buildRouteToCreateInvite");
8
22
  Object.defineProperty(exports, "buildRouteToCreateInvite", { enumerable: true, get: function () { return __importDefault(buildRouteToCreateInvite_1).default; } });
23
+ var LoginAndConfirmJoinController_1 = require("./loggingInAndConfirmingJoin/LoginAndConfirmJoinController");
24
+ Object.defineProperty(exports, "LoginAndConfirmJoinController", { enumerable: true, get: function () { return __importDefault(LoginAndConfirmJoinController_1).default; } });
25
+ __exportStar(require("./loggingInAndConfirmingJoin/LoginAndConfirmJoinController"), exports);
26
+ var LoginAndConfirmTestFixture_1 = require("./__tests__/support/LoginAndConfirmTestFixture");
27
+ Object.defineProperty(exports, "LoginAndConfirmTestFixture", { enumerable: true, get: function () { return __importDefault(LoginAndConfirmTestFixture_1).default; } });
28
+ __exportStar(require("./__tests__/support/LoginAndConfirmTestFixture"), exports);
@@ -0,0 +1,34 @@
1
+ import { Authenticator, CardViewControllerImpl, ViewControllerFactory } from '@sprucelabs/heartwood-view-controllers';
2
+ import { MercuryClient } from '@sprucelabs/mercury-client';
3
+ export interface LoginAndConfirmJoinController {
4
+ promptForLoginAndConfirmJoin(): Promise<boolean>;
5
+ }
6
+ export default class LoginAndConfirmJoinControllerImpl implements LoginAndConfirmJoinController {
7
+ private views;
8
+ protected vc: CardViewControllerImpl;
9
+ private authenticator;
10
+ private dialog?;
11
+ private static Class?;
12
+ private organizationId;
13
+ private connectToApi;
14
+ private client;
15
+ private locationId?;
16
+ protected constructor(options: LoginAndConfirmJoinOptions);
17
+ static setClass(Class?: new () => LoginAndConfirmJoinController): void;
18
+ static Controller(options: LoginAndConfirmJoinOptions): LoginAndConfirmJoinController;
19
+ promptForLoginAndConfirmJoin(): Promise<boolean>;
20
+ private listRoles;
21
+ private confirmTheJoin;
22
+ private promptForLogin;
23
+ private renderInDialogAndWait;
24
+ }
25
+ export interface LoginAndConfirmJoinOptions {
26
+ authenticator: Authenticator;
27
+ views: Pick<ViewControllerFactory, 'Controller' | 'setController'>;
28
+ organizationId: string;
29
+ locationId?: string;
30
+ connectToApi: ConnectToApi;
31
+ }
32
+ export declare type LoginAndConfirmJoinConstructor = new () => LoginAndConfirmJoinController;
33
+ declare type ConnectToApi = () => Promise<MercuryClient>;
34
+ export {};
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const schema_1 = require("@sprucelabs/schema");
7
+ 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
+ }
18
+ static setClass(Class) {
19
+ this.Class = Class;
20
+ }
21
+ static Controller(options) {
22
+ var _a;
23
+ (0, schema_1.assertOptions)(options, [
24
+ 'authenticator',
25
+ 'views',
26
+ 'organizationId',
27
+ 'connectToApi',
28
+ ]);
29
+ options.views.setController('invite.confirm-join-card', ConfirmJoinCard_vc_1.default);
30
+ return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(options);
31
+ }
32
+ async promptForLoginAndConfirmJoin() {
33
+ this.client = await this.connectToApi();
34
+ if (this.authenticator.isLoggedIn()) {
35
+ return true;
36
+ }
37
+ const person = await this.promptForLogin();
38
+ if (!person) {
39
+ return false;
40
+ }
41
+ const roles = await this.listRoles(person.id);
42
+ if (roles.length > 0) {
43
+ return true;
44
+ }
45
+ const confirmed = await this.confirmTheJoin();
46
+ return confirmed;
47
+ }
48
+ async listRoles(personId) {
49
+ const [{ roles }] = await this.client.emitAndFlattenResponses('list-roles::v2020_12_25', {
50
+ target: {
51
+ personId,
52
+ locationId: this.locationId,
53
+ organizationId: this.organizationId,
54
+ },
55
+ });
56
+ return roles;
57
+ }
58
+ async confirmTheJoin() {
59
+ let accepted = false;
60
+ const confirmVc = this.views.Controller('invite.confirm-join-card', {
61
+ onAccept: async () => {
62
+ var _a;
63
+ accepted = true;
64
+ await ((_a = this.dialog) === null || _a === void 0 ? void 0 : _a.hide());
65
+ },
66
+ onDecline: async () => {
67
+ var _a;
68
+ await ((_a = this.dialog) === null || _a === void 0 ? void 0 : _a.hide());
69
+ },
70
+ onError: () => { },
71
+ organizationId: this.organizationId,
72
+ authenticator: this.authenticator,
73
+ viewContext: {},
74
+ });
75
+ await confirmVc.load();
76
+ await this.renderInDialogAndWait(confirmVc.render());
77
+ return accepted;
78
+ }
79
+ async promptForLogin() {
80
+ let person;
81
+ const loginVc = this.views.Controller('login', {
82
+ onLogin: async (options) => {
83
+ var _a;
84
+ person = options.person;
85
+ await ((_a = this.dialog) === null || _a === void 0 ? void 0 : _a.hide());
86
+ },
87
+ });
88
+ await this.renderInDialogAndWait(loginVc.render());
89
+ return person;
90
+ }
91
+ async renderInDialogAndWait(view) {
92
+ var _a;
93
+ //@ts-ignore
94
+ this.dialog = this.vc.renderInDialog(view);
95
+ await ((_a = this.dialog) === null || _a === void 0 ? void 0 : _a.wait());
96
+ }
97
+ }
98
+ exports.default = LoginAndConfirmJoinControllerImpl;
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.2.39",
4
+ "version": "3.3.1",
5
5
  "skill": {
6
6
  "namespace": "invite"
7
7
  },
@@ -16,12 +16,20 @@
16
16
  "files": [
17
17
  "build/index-module.js",
18
18
  "build/index-module.d.ts",
19
- "build/sending/buildRouteToCreateInvite.js",
20
- "build/sending/buildRouteToCreateInvite.d.ts",
21
19
  "build/esm/index-module.js",
22
20
  "build/esm/index-module.d.ts",
21
+ "build/sending/buildRouteToCreateInvite.js",
22
+ "build/sending/buildRouteToCreateInvite.d.ts",
23
23
  "build/esm/sending/buildRouteToCreateInvite.js",
24
- "build/esm/sending/buildRouteToCreateInvite.d.ts"
24
+ "build/esm/sending/buildRouteToCreateInvite.d.ts",
25
+ "build/loggingInAndConfirmingJoin/LoginAndConfirmJoinController.js",
26
+ "build/loggingInAndConfirmingJoin/LoginAndConfirmJoinController.d.ts",
27
+ "build/esm/loggingInAndConfirmingJoin/LoginAndConfirmJoinController.js",
28
+ "build/esm/loggingInAndConfirmingJoin/LoginAndConfirmJoinController.d.ts",
29
+ "build/__tests__/support/LoginAndConfirmTestFixture.js",
30
+ "build/__tests__/support/LoginAndConfirmTestFixture.d.ts",
31
+ "build/esm/__tests__/support/LoginAndConfirmTestFixture.js",
32
+ "build/esm/__tests__/support/LoginAndConfirmTestFixture.d.ts"
25
33
  ],
26
34
  "keywords": [],
27
35
  "scripts": {