@sprucelabs/spruce-heartwood-utils 16.14.16 → 16.15.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,18 @@
1
+ import { CachedValue, Device } from '@sprucelabs/heartwood-view-controllers';
2
+ import { Orientation } from '../types/heartwood.types';
3
+ export declare class HeartwoodDevice implements Device {
4
+ private storage;
5
+ private orientation;
6
+ protected constructor(storage: Storage);
7
+ openUrl(url: string): void;
8
+ static Device(storage: Storage): HeartwoodDevice;
9
+ setCachedValue(key: string, value: CachedValue): void;
10
+ getCachedValue(key: string): CachedValue;
11
+ call(phoneNumber: string): void;
12
+ vibrate(): void;
13
+ setOrientation(orientation: Orientation): void;
14
+ getOrientation(): Orientation;
15
+ enablePushNotifications(): void;
16
+ signalSkillViewLoaded(): void;
17
+ sendCommand(command: string, payload?: Record<string, any>): void;
18
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HeartwoodDevice = void 0;
4
+ const schema_1 = require("@sprucelabs/schema");
5
+ class HeartwoodDevice {
6
+ constructor(storage) {
7
+ this.orientation = 'unknown-orientation';
8
+ this.storage = storage;
9
+ }
10
+ openUrl(url) {
11
+ this.sendCommand('openUrl', {
12
+ url,
13
+ });
14
+ }
15
+ static Device(storage) {
16
+ (0, schema_1.assertOptions)({ storage }, ['storage']);
17
+ return new this(storage);
18
+ }
19
+ setCachedValue(key, value) {
20
+ this.storage.setItem(key, JSON.stringify({ value }));
21
+ }
22
+ getCachedValue(key) {
23
+ const saved = this.storage.getItem(key);
24
+ if (saved) {
25
+ const parsed = JSON.parse(saved);
26
+ return parsed.value;
27
+ }
28
+ return null;
29
+ }
30
+ call(phoneNumber) {
31
+ window.location.href = `tel:${phoneNumber}`;
32
+ }
33
+ vibrate() {
34
+ this.sendCommand('vibrate');
35
+ }
36
+ setOrientation(orientation) {
37
+ this.orientation = orientation;
38
+ }
39
+ getOrientation() {
40
+ return this.orientation;
41
+ }
42
+ enablePushNotifications() {
43
+ this.sendCommand('enablePushNotifications');
44
+ }
45
+ signalSkillViewLoaded() {
46
+ this.sendCommand('skillViewLoaded');
47
+ }
48
+ sendCommand(command, payload) {
49
+ var _a, _b, _c, _d;
50
+ const options = {
51
+ command,
52
+ payload,
53
+ };
54
+ //@ts-ignore
55
+ (_d = (_c = (_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.messages) === null || _c === void 0 ? void 0 : _c.postMessage) === null || _d === void 0 ? void 0 : _d.call(_c, JSON.stringify(options));
56
+ // @ts-ignore
57
+ if (window.AndroidInterface) {
58
+ // @ts-ignore
59
+ window.AndroidInterface.postMessage(JSON.stringify(options));
60
+ }
61
+ }
62
+ }
63
+ exports.HeartwoodDevice = HeartwoodDevice;
64
+ //# sourceMappingURL=HeartwoodDevice.js.map
@@ -0,0 +1,18 @@
1
+ import { CachedValue, Device } from '@sprucelabs/heartwood-view-controllers';
2
+ import { Orientation } from '../types/heartwood.types';
3
+ export declare class HeartwoodDevice implements Device {
4
+ private storage;
5
+ private orientation;
6
+ protected constructor(storage: Storage);
7
+ openUrl(url: string): void;
8
+ static Device(storage: Storage): HeartwoodDevice;
9
+ setCachedValue(key: string, value: CachedValue): void;
10
+ getCachedValue(key: string): CachedValue;
11
+ call(phoneNumber: string): void;
12
+ vibrate(): void;
13
+ setOrientation(orientation: Orientation): void;
14
+ getOrientation(): Orientation;
15
+ enablePushNotifications(): void;
16
+ signalSkillViewLoaded(): void;
17
+ sendCommand(command: string, payload?: Record<string, any>): void;
18
+ }
@@ -0,0 +1,59 @@
1
+ import { assertOptions } from '@sprucelabs/schema';
2
+ export class HeartwoodDevice {
3
+ constructor(storage) {
4
+ this.orientation = 'unknown-orientation';
5
+ this.storage = storage;
6
+ }
7
+ openUrl(url) {
8
+ this.sendCommand('openUrl', {
9
+ url,
10
+ });
11
+ }
12
+ static Device(storage) {
13
+ assertOptions({ storage }, ['storage']);
14
+ return new this(storage);
15
+ }
16
+ setCachedValue(key, value) {
17
+ this.storage.setItem(key, JSON.stringify({ value }));
18
+ }
19
+ getCachedValue(key) {
20
+ const saved = this.storage.getItem(key);
21
+ if (saved) {
22
+ const parsed = JSON.parse(saved);
23
+ return parsed.value;
24
+ }
25
+ return null;
26
+ }
27
+ call(phoneNumber) {
28
+ window.location.href = `tel:${phoneNumber}`;
29
+ }
30
+ vibrate() {
31
+ this.sendCommand('vibrate');
32
+ }
33
+ setOrientation(orientation) {
34
+ this.orientation = orientation;
35
+ }
36
+ getOrientation() {
37
+ return this.orientation;
38
+ }
39
+ enablePushNotifications() {
40
+ this.sendCommand('enablePushNotifications');
41
+ }
42
+ signalSkillViewLoaded() {
43
+ this.sendCommand('skillViewLoaded');
44
+ }
45
+ sendCommand(command, payload) {
46
+ var _a, _b, _c, _d;
47
+ const options = {
48
+ command,
49
+ payload,
50
+ };
51
+ //@ts-ignore
52
+ (_d = (_c = (_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.messages) === null || _c === void 0 ? void 0 : _c.postMessage) === null || _d === void 0 ? void 0 : _d.call(_c, JSON.stringify(options));
53
+ // @ts-ignore
54
+ if (window.AndroidInterface) {
55
+ // @ts-ignore
56
+ window.AndroidInterface.postMessage(JSON.stringify(options));
57
+ }
58
+ }
59
+ }
@@ -63,11 +63,11 @@ class RemoteViewControllerFactoryImpl {
63
63
  source = yield this.fetchFromUrl(sourceUrl);
64
64
  }
65
65
  const importer = ViewControllerImporter.Importer();
66
- const { controllers: skillViews } = importer.import(source);
66
+ const { controllers: skillViews, plugins } = importer.import(source);
67
67
  skillViews.forEach((sv) => {
68
68
  sv.id = `${namespace}.${sv.id}`;
69
69
  });
70
- this.vcFactory.importControllers(skillViews);
70
+ this.vcFactory.importControllers(skillViews, plugins);
71
71
  if (theme) {
72
72
  this.themesByNamespace[namespace] = Object.assign(Object.assign({}, theme), { slug: namespace, name: namespace });
73
73
  }
@@ -54,11 +54,11 @@ class RemoteViewControllerFactoryImpl {
54
54
  source = await this.fetchFromUrl(sourceUrl);
55
55
  }
56
56
  const importer = heartwood_view_controllers_1.ViewControllerImporter.Importer();
57
- const { controllers: skillViews } = importer.import(source);
57
+ const { controllers: skillViews, plugins } = importer.import(source);
58
58
  skillViews.forEach((sv) => {
59
59
  sv.id = `${namespace}.${sv.id}`;
60
60
  });
61
- this.vcFactory.importControllers(skillViews);
61
+ this.vcFactory.importControllers(skillViews, plugins);
62
62
  if (theme) {
63
63
  this.themesByNamespace[namespace] = Object.assign(Object.assign({}, theme), { slug: namespace, name: namespace });
64
64
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-heartwood-utils",
3
3
  "description": "Heartwood Utilities",
4
- "version": "16.14.16",
4
+ "version": "16.15.1",
5
5
  "skill": {
6
6
  "namespace": "heartwood"
7
7
  },
@@ -26,6 +26,10 @@
26
26
  "build/skillViews/CardRegistrar.d.ts",
27
27
  "build/esm/skillViews/CardRegistrar.js",
28
28
  "build/esm/skillViews/CardRegistrar.d.ts",
29
+ "build/devices/HeartwoodDevice.js",
30
+ "build/devices/HeartwoodDevice.d.ts",
31
+ "build/esm/devices/HeartwoodDevice.js",
32
+ "build/esm/devices/HeartwoodDevice.d.ts",
29
33
  "build/theming/ThemeManager.js",
30
34
  "build/theming/ThemeManager.d.ts",
31
35
  "build/esm/theming/ThemeManager.js",