@sprucelabs/spruce-appointment-utils 6.2.0 → 6.2.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,10 @@
1
+ export default class RemoteRoleCapabilityStore {
2
+ private client;
3
+ private organizationId;
4
+ private queuedCapabilities;
5
+ constructor(options: any);
6
+ queue(value: any): Promise<any>;
7
+ persist(): Promise<import("@sprucelabs/schema").SchemaStaticValues<import("@sprucelabs/mercury-types").SpruceSchemas.Appointments.v2021_06_23.UpdateRoleCapabilitySchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<import("@sprucelabs/mercury-types").SpruceSchemas.Appointments.v2021_06_23.UpdateRoleCapabilitySchema>, import("@sprucelabs/schema").StaticSchemaAllValues<import("@sprucelabs/mercury-types").SpruceSchemas.Appointments.v2021_06_23.UpdateRoleCapabilitySchema, false>>[]>;
8
+ private createCapability;
9
+ protected updateCapability(id: any, values: any): Promise<import("@sprucelabs/schema").SchemaStaticValues<import("@sprucelabs/mercury-types").SpruceSchemas.Appointments.v2021_06_23.UpdateRoleCapabilitySchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<import("@sprucelabs/mercury-types").SpruceSchemas.Appointments.v2021_06_23.UpdateRoleCapabilitySchema>, import("@sprucelabs/schema").StaticSchemaAllValues<import("@sprucelabs/mercury-types").SpruceSchemas.Appointments.v2021_06_23.UpdateRoleCapabilitySchema, false>>>;
10
+ }
@@ -0,0 +1,82 @@
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
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ import { assertOptions } from '@sprucelabs/schema';
22
+ export default class RemoteRoleCapabilityStore {
23
+ constructor(options) {
24
+ this.queuedCapabilities = [];
25
+ assertOptions(options, ['client', 'organizationId']);
26
+ this.client = options.client;
27
+ this.organizationId = options.organizationId;
28
+ }
29
+ queue(value) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ assertOptions(value, ['serviceId', 'roleId']);
32
+ const id = `${this.organizationId}-${value.serviceId}-${value.roleId}`;
33
+ this.queuedCapabilities[id] = Object.assign(Object.assign({}, this.queuedCapabilities[id]), value);
34
+ if (!value.id) {
35
+ return Object.assign(Object.assign({}, value), { id });
36
+ }
37
+ return value;
38
+ });
39
+ }
40
+ persist() {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ let response = [];
43
+ for (let key in this.queuedCapabilities) {
44
+ const _a = this.queuedCapabilities[key], { id, roleId, serviceId } = _a, values = __rest(_a, ["id", "roleId", "serviceId"]);
45
+ if (id) {
46
+ const capability = yield this.updateCapability(id, values);
47
+ response.push(capability);
48
+ }
49
+ else {
50
+ const capability = yield this.createCapability(roleId, serviceId, values);
51
+ response.push(capability);
52
+ }
53
+ delete this.queuedCapabilities[key];
54
+ }
55
+ return response;
56
+ });
57
+ }
58
+ createCapability(roleId, serviceId, values) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ const [{ capability }] = yield this.client.emitAndFlattenResponses('appointments.create-role-capability::v2021_06_23', {
61
+ target: {
62
+ organizationId: this.organizationId,
63
+ roleId,
64
+ },
65
+ payload: Object.assign({ serviceId, isEnabled: true, doesOffer: true }, values),
66
+ });
67
+ return capability;
68
+ });
69
+ }
70
+ updateCapability(id, values) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ const [{ capability }] = yield this.client.emitAndFlattenResponses('appointments.update-role-capability::v2021_06_23', {
73
+ target: {
74
+ organizationId: this.organizationId,
75
+ capabilityId: id,
76
+ },
77
+ payload: Object.assign({}, values),
78
+ });
79
+ return capability;
80
+ });
81
+ }
82
+ }
@@ -0,0 +1,10 @@
1
+ export default class RemoteRoleCapabilityStore {
2
+ private client;
3
+ private organizationId;
4
+ private queuedCapabilities;
5
+ constructor(options: any);
6
+ queue(value: any): Promise<any>;
7
+ persist(): Promise<import("@sprucelabs/schema").SchemaStaticValues<import("@sprucelabs/mercury-types").SpruceSchemas.Appointments.v2021_06_23.UpdateRoleCapabilitySchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<import("@sprucelabs/mercury-types").SpruceSchemas.Appointments.v2021_06_23.UpdateRoleCapabilitySchema>, import("@sprucelabs/schema").StaticSchemaAllValues<import("@sprucelabs/mercury-types").SpruceSchemas.Appointments.v2021_06_23.UpdateRoleCapabilitySchema, false>>[]>;
8
+ private createCapability;
9
+ protected updateCapability(id: any, values: any): Promise<import("@sprucelabs/schema").SchemaStaticValues<import("@sprucelabs/mercury-types").SpruceSchemas.Appointments.v2021_06_23.UpdateRoleCapabilitySchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<import("@sprucelabs/mercury-types").SpruceSchemas.Appointments.v2021_06_23.UpdateRoleCapabilitySchema>, import("@sprucelabs/schema").StaticSchemaAllValues<import("@sprucelabs/mercury-types").SpruceSchemas.Appointments.v2021_06_23.UpdateRoleCapabilitySchema, false>>>;
10
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ const schema_1 = require("@sprucelabs/schema");
15
+ class RemoteRoleCapabilityStore {
16
+ constructor(options) {
17
+ this.queuedCapabilities = [];
18
+ (0, schema_1.assertOptions)(options, ['client', 'organizationId']);
19
+ this.client = options.client;
20
+ this.organizationId = options.organizationId;
21
+ }
22
+ async queue(value) {
23
+ (0, schema_1.assertOptions)(value, ['serviceId', 'roleId']);
24
+ const id = `${this.organizationId}-${value.serviceId}-${value.roleId}`;
25
+ this.queuedCapabilities[id] = Object.assign(Object.assign({}, this.queuedCapabilities[id]), value);
26
+ if (!value.id) {
27
+ return Object.assign(Object.assign({}, value), { id });
28
+ }
29
+ return value;
30
+ }
31
+ async persist() {
32
+ let response = [];
33
+ for (let key in this.queuedCapabilities) {
34
+ const _a = this.queuedCapabilities[key], { id, roleId, serviceId } = _a, values = __rest(_a, ["id", "roleId", "serviceId"]);
35
+ if (id) {
36
+ const capability = await this.updateCapability(id, values);
37
+ response.push(capability);
38
+ }
39
+ else {
40
+ const capability = await this.createCapability(roleId, serviceId, values);
41
+ response.push(capability);
42
+ }
43
+ delete this.queuedCapabilities[key];
44
+ }
45
+ return response;
46
+ }
47
+ async createCapability(roleId, serviceId, values) {
48
+ const [{ capability }] = await this.client.emitAndFlattenResponses('appointments.create-role-capability::v2021_06_23', {
49
+ target: {
50
+ organizationId: this.organizationId,
51
+ roleId,
52
+ },
53
+ payload: Object.assign({ serviceId, isEnabled: true, doesOffer: true }, values),
54
+ });
55
+ return capability;
56
+ }
57
+ async updateCapability(id, values) {
58
+ const [{ capability }] = await this.client.emitAndFlattenResponses('appointments.update-role-capability::v2021_06_23', {
59
+ target: {
60
+ organizationId: this.organizationId,
61
+ capabilityId: id,
62
+ },
63
+ payload: Object.assign({}, values),
64
+ });
65
+ return capability;
66
+ }
67
+ }
68
+ exports.default = RemoteRoleCapabilityStore;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-appointment-utils",
3
3
  "description": "Utils for working with appointments and Sprucebot.",
4
- "version": "6.2.0",
4
+ "version": "6.2.1",
5
5
  "skill": {
6
6
  "namespace": "appointments"
7
7
  },
@@ -18,6 +18,8 @@
18
18
  "build/index-module.d.ts",
19
19
  "build/types-module.js",
20
20
  "build/types-module.d.ts",
21
+ "build/stores/RemoteRoleCapabilityStore.d.ts",
22
+ "build/stores/RemoteRoleCapabilityStore.js",
21
23
  "build/viewControllers/AbstractCapabilityCardViewController.js",
22
24
  "build/viewControllers/AbstractCapabilityCardViewController.d.ts",
23
25
  "build/viewControllers/DurationCard.vc.js",
@@ -34,6 +36,8 @@
34
36
  "build/esm/index-module.d.ts",
35
37
  "build/esm/types-module.js",
36
38
  "build/esm/types-module.d.ts",
39
+ "build/esm/stores/RemoteRoleCapabilityStore.d.ts",
40
+ "build/esm/stores/RemoteRoleCapabilityStore.js",
37
41
  "build/esm/viewControllers/AbstractCapabilityCardViewController.js",
38
42
  "build/esm/viewControllers/AbstractCapabilityCardViewController.d.ts",
39
43
  "build/esm/viewControllers/DurationCard.vc.js",