@sprucelabs/spruce-mmp-vc-plugin 2.1.4 → 2.1.5

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.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # MMP View Controller Plugin
2
+
3
+ More coming soon...
@@ -1,10 +1,11 @@
1
1
  import { ViewControllerPlugin, ViewControllerPluginOptions } from '@sprucelabs/heartwood-view-controllers';
2
- export default class AdjustMmpVcPlugin implements ViewControllerPlugin {
2
+ import { MmpVcPlugin } from './mmp.types';
3
+ export default class AdjustMmpVcPlugin implements ViewControllerPlugin, MmpVcPlugin<AdjustMmpVcPluginSetupOptions, AdjustTrackEventOptions> {
3
4
  private device;
4
5
  private isSetup;
5
6
  constructor(options: ViewControllerPluginOptions);
6
- setup(appToken: string, environment: string): void;
7
- trackEvent(eventToken: string, options?: AdjustTrackEventOptions): void;
7
+ setup(options: AdjustMmpVcPluginSetupOptions): void;
8
+ trackEvent(eventName: string, options?: AdjustTrackEventOptions): void;
8
9
  }
9
10
  export interface AdjustTrackEventOptions {
10
11
  revenue?: {
@@ -14,3 +15,7 @@ export interface AdjustTrackEventOptions {
14
15
  transationId?: string;
15
16
  productId?: string;
16
17
  }
18
+ export interface AdjustMmpVcPluginSetupOptions {
19
+ appToken: string;
20
+ environment: string;
21
+ }
@@ -11,26 +11,26 @@ class AdjustMmpVcPlugin {
11
11
  const { device } = options;
12
12
  this.device = device;
13
13
  }
14
- setup(appToken, environment) {
15
- (0, schema_1.assertOptions)({
16
- appToken,
17
- environment,
18
- }, ['appToken', 'environment']);
14
+ setup(options) {
15
+ const { appToken, environment } = (0, schema_1.assertOptions)(options, [
16
+ 'appToken',
17
+ 'environment',
18
+ ]);
19
19
  this.device.sendCommand('mmp_setup:adjust', {
20
20
  appToken,
21
21
  env: environment,
22
22
  });
23
23
  this.isSetup = true;
24
24
  }
25
- trackEvent(eventToken, options) {
25
+ trackEvent(eventName, options) {
26
26
  if (!this.isSetup) {
27
27
  throw new SpruceError_1.default({
28
28
  code: 'ADJUST_NOT_SETUP',
29
29
  });
30
30
  }
31
- (0, schema_1.assertOptions)({ eventToken }, ['eventToken']);
31
+ (0, schema_1.assertOptions)({ eventName }, ['eventName']);
32
32
  this.device.sendCommand('mmp_track_event:adjust', {
33
- eventToken,
33
+ eventName,
34
34
  ...options,
35
35
  });
36
36
  }
@@ -0,0 +1,13 @@
1
+ import { ViewControllerPlugin } from '@sprucelabs/heartwood-view-controllers';
2
+ import { AdjustMmpVcPluginSetupOptions } from './AdjustMmpVcPlugin';
3
+ import { MmpVcPlugin } from './mmp.types';
4
+ export default class MockAdjustMmpVcPlugin implements ViewControllerPlugin, MmpVcPlugin<Record<string, any>, Record<string, any>> {
5
+ private lastSetupOptions?;
6
+ private lastTrackedEvent?;
7
+ setup(options: Record<string, any>): void;
8
+ trackEvent(eventName: string, options?: Record<string, any> | undefined): void;
9
+ assertTrackEventWasCalled(): void;
10
+ assertTrackEventWasCalledWith(eventName: string, options?: Record<string, any>): void;
11
+ assertSetupWasCalled(): void;
12
+ assertSetupWasCalledWith(setupOptions: AdjustMmpVcPluginSetupOptions): void;
13
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const test_utils_1 = require("@sprucelabs/test-utils");
4
+ class MockAdjustMmpVcPlugin {
5
+ setup(options) {
6
+ this.lastSetupOptions = options;
7
+ }
8
+ trackEvent(eventName, options) {
9
+ this.lastTrackedEvent = {
10
+ eventName,
11
+ options,
12
+ };
13
+ }
14
+ assertTrackEventWasCalled() {
15
+ test_utils_1.assert.isTruthy(this.lastTrackedEvent, `You gotta call this.plugins.mmp.trackEvent(...)`);
16
+ }
17
+ assertTrackEventWasCalledWith(eventName, options) {
18
+ var _a, _b, _c;
19
+ test_utils_1.assert.isEqual(eventName, (_a = this.lastTrackedEvent) === null || _a === void 0 ? void 0 : _a.eventName, `this.plugins.mmp.trackEvent(...) was not called with the expected eventName. Expected: ${eventName}, got: ${(_b = this.lastTrackedEvent) === null || _b === void 0 ? void 0 : _b.eventName}`);
20
+ test_utils_1.assert.isEqualDeep(options, (_c = this.lastTrackedEvent) === null || _c === void 0 ? void 0 : _c.options, `this.plugins.mmp.trackEvent(...) was not called with the expected options.`);
21
+ }
22
+ assertSetupWasCalled() {
23
+ test_utils_1.assert.isTruthy(this.lastSetupOptions, `You gotta call this.plugins.mmp.setup(...)`);
24
+ }
25
+ assertSetupWasCalledWith(setupOptions) {
26
+ test_utils_1.assert.isEqualDeep(this.lastSetupOptions, setupOptions, `this.plugins.mmp.setup(...) was not called with the expected options.`);
27
+ }
28
+ }
29
+ exports.default = MockAdjustMmpVcPlugin;
@@ -1,10 +1,11 @@
1
1
  import { ViewControllerPlugin, ViewControllerPluginOptions } from '@sprucelabs/heartwood-view-controllers';
2
- export default class AdjustMmpVcPlugin implements ViewControllerPlugin {
2
+ import { MmpVcPlugin } from './mmp.types';
3
+ export default class AdjustMmpVcPlugin implements ViewControllerPlugin, MmpVcPlugin<AdjustMmpVcPluginSetupOptions, AdjustTrackEventOptions> {
3
4
  private device;
4
5
  private isSetup;
5
6
  constructor(options: ViewControllerPluginOptions);
6
- setup(appToken: string, environment: string): void;
7
- trackEvent(eventToken: string, options?: AdjustTrackEventOptions): void;
7
+ setup(options: AdjustMmpVcPluginSetupOptions): void;
8
+ trackEvent(eventName: string, options?: AdjustTrackEventOptions): void;
8
9
  }
9
10
  export interface AdjustTrackEventOptions {
10
11
  revenue?: {
@@ -14,3 +15,7 @@ export interface AdjustTrackEventOptions {
14
15
  transationId?: string;
15
16
  productId?: string;
16
17
  }
18
+ export interface AdjustMmpVcPluginSetupOptions {
19
+ appToken: string;
20
+ environment: string;
21
+ }
@@ -6,24 +6,24 @@ export default class AdjustMmpVcPlugin {
6
6
  const { device } = options;
7
7
  this.device = device;
8
8
  }
9
- setup(appToken, environment) {
10
- assertOptions({
11
- appToken,
12
- environment,
13
- }, ['appToken', 'environment']);
9
+ setup(options) {
10
+ const { appToken, environment } = assertOptions(options, [
11
+ 'appToken',
12
+ 'environment',
13
+ ]);
14
14
  this.device.sendCommand('mmp_setup:adjust', {
15
15
  appToken,
16
16
  env: environment,
17
17
  });
18
18
  this.isSetup = true;
19
19
  }
20
- trackEvent(eventToken, options) {
20
+ trackEvent(eventName, options) {
21
21
  if (!this.isSetup) {
22
22
  throw new SpruceError({
23
23
  code: 'ADJUST_NOT_SETUP',
24
24
  });
25
25
  }
26
- assertOptions({ eventToken }, ['eventToken']);
27
- this.device.sendCommand('mmp_track_event:adjust', Object.assign({ eventToken }, options));
26
+ assertOptions({ eventName }, ['eventName']);
27
+ this.device.sendCommand('mmp_track_event:adjust', Object.assign({ eventName }, options));
28
28
  }
29
29
  }
@@ -0,0 +1,13 @@
1
+ import { ViewControllerPlugin } from '@sprucelabs/heartwood-view-controllers';
2
+ import { AdjustMmpVcPluginSetupOptions } from './AdjustMmpVcPlugin';
3
+ import { MmpVcPlugin } from './mmp.types';
4
+ export default class MockAdjustMmpVcPlugin implements ViewControllerPlugin, MmpVcPlugin<Record<string, any>, Record<string, any>> {
5
+ private lastSetupOptions?;
6
+ private lastTrackedEvent?;
7
+ setup(options: Record<string, any>): void;
8
+ trackEvent(eventName: string, options?: Record<string, any> | undefined): void;
9
+ assertTrackEventWasCalled(): void;
10
+ assertTrackEventWasCalledWith(eventName: string, options?: Record<string, any>): void;
11
+ assertSetupWasCalled(): void;
12
+ assertSetupWasCalledWith(setupOptions: AdjustMmpVcPluginSetupOptions): void;
13
+ }
@@ -0,0 +1,26 @@
1
+ import { assert } from '@sprucelabs/test-utils';
2
+ export default class MockAdjustMmpVcPlugin {
3
+ setup(options) {
4
+ this.lastSetupOptions = options;
5
+ }
6
+ trackEvent(eventName, options) {
7
+ this.lastTrackedEvent = {
8
+ eventName,
9
+ options,
10
+ };
11
+ }
12
+ assertTrackEventWasCalled() {
13
+ assert.isTruthy(this.lastTrackedEvent, `You gotta call this.plugins.mmp.trackEvent(...)`);
14
+ }
15
+ assertTrackEventWasCalledWith(eventName, options) {
16
+ var _a, _b, _c;
17
+ assert.isEqual(eventName, (_a = this.lastTrackedEvent) === null || _a === void 0 ? void 0 : _a.eventName, `this.plugins.mmp.trackEvent(...) was not called with the expected eventName. Expected: ${eventName}, got: ${(_b = this.lastTrackedEvent) === null || _b === void 0 ? void 0 : _b.eventName}`);
18
+ assert.isEqualDeep(options, (_c = this.lastTrackedEvent) === null || _c === void 0 ? void 0 : _c.options, `this.plugins.mmp.trackEvent(...) was not called with the expected options.`);
19
+ }
20
+ assertSetupWasCalled() {
21
+ assert.isTruthy(this.lastSetupOptions, `You gotta call this.plugins.mmp.setup(...)`);
22
+ }
23
+ assertSetupWasCalledWith(setupOptions) {
24
+ assert.isEqualDeep(this.lastSetupOptions, setupOptions, `this.plugins.mmp.setup(...) was not called with the expected options.`);
25
+ }
26
+ }
@@ -1 +1,5 @@
1
1
  export { default as AdjustMmpVcPlugin } from './AdjustMmpVcPlugin';
2
+ export * from './AdjustMmpVcPlugin';
3
+ export * from './mmp.types';
4
+ export { default as mmpAssert } from './mmpAssert';
5
+ export * from './mmpAssert';
@@ -1 +1,5 @@
1
1
  export { default as AdjustMmpVcPlugin } from './AdjustMmpVcPlugin.js';
2
+ export * from './AdjustMmpVcPlugin.js';
3
+ export * from './mmp.types.js';
4
+ export { default as mmpAssert } from './mmpAssert.js';
5
+ export * from './mmpAssert.js';
@@ -0,0 +1,5 @@
1
+ export type Partner = 'adjust';
2
+ export interface MmpVcPlugin<SetupOptions, TrackEventOptions> {
3
+ setup(options: SetupOptions): void;
4
+ trackEvent(eventName: string, options?: TrackEventOptions): void;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ import { ViewControllerFactory } from '@sprucelabs/heartwood-view-controllers';
2
+ import { AdjustMmpVcPluginSetupOptions } from './AdjustMmpVcPlugin';
3
+ import { Partner } from './mmp.types';
4
+ declare const mmpAssert: {
5
+ beforeEach(views: ViewControllerFactory): void;
6
+ pluginIsSetup(options: PluginIsSetupOptions): Promise<void>;
7
+ didTrackEvent(options: DidTrackEventOptions): Promise<void>;
8
+ };
9
+ export default mmpAssert;
10
+ export interface PluginIsSetupOptions {
11
+ action: () => void | Promise<void>;
12
+ partner: Partner;
13
+ setupOptions?: AdjustMmpVcPluginSetupOptions;
14
+ }
15
+ export interface DidTrackEventOptions {
16
+ action: () => void | Promise<void>;
17
+ eventName: string;
18
+ trackOptions?: Record<string, any>;
19
+ }
@@ -0,0 +1,51 @@
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 { assert } from '@sprucelabs/test-utils';
12
+ import MockAdjustMmpVcPlugin from './MockAdjustMmpVcPlugin.js';
13
+ let mockPlugin;
14
+ const mmpAssert = {
15
+ beforeEach(views) {
16
+ mockPlugin = new MockAdjustMmpVcPlugin();
17
+ views.addPlugin('mmp', mockPlugin);
18
+ },
19
+ pluginIsSetup(options) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const { action, partner, setupOptions } = options !== null && options !== void 0 ? options : {};
22
+ assertBeforeEachCalled();
23
+ assertOptions({
24
+ action,
25
+ partner,
26
+ }, ['action', 'partner']);
27
+ assert.isEqual(partner, 'adjust', 'The partner you passed was invalid. For now I only support Adjust.');
28
+ yield action();
29
+ mockPlugin === null || mockPlugin === void 0 ? void 0 : mockPlugin.assertSetupWasCalled();
30
+ if (setupOptions) {
31
+ mockPlugin === null || mockPlugin === void 0 ? void 0 : mockPlugin.assertSetupWasCalledWith(setupOptions);
32
+ }
33
+ });
34
+ },
35
+ didTrackEvent(options) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ assertBeforeEachCalled();
38
+ const { action, eventName, trackOptions } = assertOptions(options, [
39
+ 'action',
40
+ 'eventName',
41
+ ]);
42
+ yield action();
43
+ mockPlugin === null || mockPlugin === void 0 ? void 0 : mockPlugin.assertTrackEventWasCalled();
44
+ mockPlugin === null || mockPlugin === void 0 ? void 0 : mockPlugin.assertTrackEventWasCalledWith(eventName, trackOptions);
45
+ });
46
+ },
47
+ };
48
+ export default mmpAssert;
49
+ function assertBeforeEachCalled() {
50
+ assert.isTruthy(mockPlugin, 'You must call mmpAssert.beforeEach(this.views.getFactory()) before using this assert util.');
51
+ }
package/build/index.d.ts CHANGED
@@ -1 +1,5 @@
1
1
  export { default as AdjustMmpVcPlugin } from './AdjustMmpVcPlugin';
2
+ export * from './AdjustMmpVcPlugin';
3
+ export * from './mmp.types';
4
+ export { default as mmpAssert } from './mmpAssert';
5
+ export * from './mmpAssert';
package/build/index.js CHANGED
@@ -1,8 +1,27 @@
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.AdjustMmpVcPlugin = void 0;
20
+ exports.mmpAssert = exports.AdjustMmpVcPlugin = void 0;
7
21
  var AdjustMmpVcPlugin_1 = require("./AdjustMmpVcPlugin");
8
22
  Object.defineProperty(exports, "AdjustMmpVcPlugin", { enumerable: true, get: function () { return __importDefault(AdjustMmpVcPlugin_1).default; } });
23
+ __exportStar(require("./AdjustMmpVcPlugin"), exports);
24
+ __exportStar(require("./mmp.types"), exports);
25
+ var mmpAssert_1 = require("./mmpAssert");
26
+ Object.defineProperty(exports, "mmpAssert", { enumerable: true, get: function () { return __importDefault(mmpAssert_1).default; } });
27
+ __exportStar(require("./mmpAssert"), exports);
@@ -0,0 +1,5 @@
1
+ export type Partner = 'adjust';
2
+ export interface MmpVcPlugin<SetupOptions, TrackEventOptions> {
3
+ setup(options: SetupOptions): void;
4
+ trackEvent(eventName: string, options?: TrackEventOptions): void;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,19 @@
1
+ import { ViewControllerFactory } from '@sprucelabs/heartwood-view-controllers';
2
+ import { AdjustMmpVcPluginSetupOptions } from './AdjustMmpVcPlugin';
3
+ import { Partner } from './mmp.types';
4
+ declare const mmpAssert: {
5
+ beforeEach(views: ViewControllerFactory): void;
6
+ pluginIsSetup(options: PluginIsSetupOptions): Promise<void>;
7
+ didTrackEvent(options: DidTrackEventOptions): Promise<void>;
8
+ };
9
+ export default mmpAssert;
10
+ export interface PluginIsSetupOptions {
11
+ action: () => void | Promise<void>;
12
+ partner: Partner;
13
+ setupOptions?: AdjustMmpVcPluginSetupOptions;
14
+ }
15
+ export interface DidTrackEventOptions {
16
+ action: () => void | Promise<void>;
17
+ eventName: string;
18
+ trackOptions?: Record<string, any>;
19
+ }
@@ -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 schema_1 = require("@sprucelabs/schema");
7
+ const test_utils_1 = require("@sprucelabs/test-utils");
8
+ const MockAdjustMmpVcPlugin_1 = __importDefault(require("./MockAdjustMmpVcPlugin"));
9
+ let mockPlugin;
10
+ const mmpAssert = {
11
+ beforeEach(views) {
12
+ mockPlugin = new MockAdjustMmpVcPlugin_1.default();
13
+ views.addPlugin('mmp', mockPlugin);
14
+ },
15
+ async pluginIsSetup(options) {
16
+ const { action, partner, setupOptions } = options !== null && options !== void 0 ? options : {};
17
+ assertBeforeEachCalled();
18
+ (0, schema_1.assertOptions)({
19
+ action,
20
+ partner,
21
+ }, ['action', 'partner']);
22
+ test_utils_1.assert.isEqual(partner, 'adjust', 'The partner you passed was invalid. For now I only support Adjust.');
23
+ await action();
24
+ mockPlugin === null || mockPlugin === void 0 ? void 0 : mockPlugin.assertSetupWasCalled();
25
+ if (setupOptions) {
26
+ mockPlugin === null || mockPlugin === void 0 ? void 0 : mockPlugin.assertSetupWasCalledWith(setupOptions);
27
+ }
28
+ },
29
+ async didTrackEvent(options) {
30
+ assertBeforeEachCalled();
31
+ const { action, eventName, trackOptions } = (0, schema_1.assertOptions)(options, [
32
+ 'action',
33
+ 'eventName',
34
+ ]);
35
+ await action();
36
+ mockPlugin === null || mockPlugin === void 0 ? void 0 : mockPlugin.assertTrackEventWasCalled();
37
+ mockPlugin === null || mockPlugin === void 0 ? void 0 : mockPlugin.assertTrackEventWasCalledWith(eventName, trackOptions);
38
+ },
39
+ };
40
+ exports.default = mmpAssert;
41
+ function assertBeforeEachCalled() {
42
+ test_utils_1.assert.isTruthy(mockPlugin, 'You must call mmpAssert.beforeEach(this.views.getFactory()) before using this assert util.');
43
+ }
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "sprucebot",
14
14
  "sprucelabs"
15
15
  ],
16
- "version": "2.1.4",
16
+ "version": "2.1.5",
17
17
  "scripts": {
18
18
  "build.ci": "yarn run build.tsc && yarn run build.resolve-paths && yarn run lint",
19
19
  "build.copy-files": "mkdir -p build && rsync -avzq --exclude='*.ts' ./src/ ./build/",