@ht-sdks/consent-manager 0.1.0 → 0.2.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.
- package/commonjs/__tests__/consent-manager/dialog.test.js +33 -0
- package/commonjs/__tests__/consent-manager-builder/analytics.test.js +53 -46
- package/commonjs/__tests__/consent-manager-builder/index.todo.js +48 -87
- package/commonjs/__tests__/consent-manager-builder/preferences.test.js +34 -27
- package/commonjs/__tests__/index.test.js +12 -12
- package/commonjs/consent-manager/banner.js +35 -19
- package/commonjs/consent-manager/buttons.js +5 -5
- package/commonjs/consent-manager/cancel-dialog.js +26 -10
- package/commonjs/consent-manager/categories.js +2 -2
- package/commonjs/consent-manager/container.js +2 -3
- package/commonjs/consent-manager/dialog.js +39 -23
- package/commonjs/consent-manager/font-styles.js +2 -2
- package/commonjs/consent-manager/index.js +41 -25
- package/commonjs/consent-manager/preference-dialog.js +36 -20
- package/commonjs/consent-manager-builder/analytics.js +3 -5
- package/commonjs/consent-manager-builder/index.js +30 -30
- package/commonjs/consent-manager-builder/preferences.js +22 -16
- package/commonjs/index.js +5 -4
- package/commonjs/standalone.js +25 -11
- package/esm/__tests__/consent-manager/dialog.test.js +28 -0
- package/esm/__tests__/consent-manager-builder/analytics.test.js +41 -34
- package/esm/__tests__/consent-manager-builder/index.todo.js +34 -73
- package/esm/__tests__/consent-manager-builder/preferences.test.js +30 -23
- package/esm/consent-manager/banner.js +5 -3
- package/esm/consent-manager/buttons.js +4 -4
- package/esm/consent-manager/cancel-dialog.js +4 -2
- package/esm/consent-manager/categories.js +2 -2
- package/esm/consent-manager/container.js +1 -1
- package/esm/consent-manager/dialog.js +7 -5
- package/esm/consent-manager/font-styles.js +2 -2
- package/esm/consent-manager/index.js +19 -17
- package/esm/consent-manager/preference-dialog.js +7 -5
- package/esm/consent-manager-builder/analytics.js +2 -4
- package/esm/consent-manager-builder/index.js +26 -26
- package/esm/consent-manager-builder/preferences.js +17 -11
- package/esm/index.js +4 -3
- package/esm/standalone.js +3 -3
- package/esm/types.js +1 -0
- package/package.json +62 -67
- package/src/__tests__/consent-manager/dialog.test.tsx +42 -0
- package/src/__tests__/consent-manager-builder/analytics.test.ts +40 -33
- package/src/__tests__/consent-manager-builder/index.todo.js +52 -95
- package/src/__tests__/consent-manager-builder/preferences.test.ts +31 -21
- package/src/consent-manager/banner.tsx +11 -11
- package/src/consent-manager/buttons.tsx +26 -10
- package/src/consent-manager/cancel-dialog.tsx +1 -1
- package/src/consent-manager/categories.ts +2 -2
- package/src/consent-manager/container.tsx +14 -17
- package/src/consent-manager/dialog.tsx +4 -4
- package/src/consent-manager/font-styles.tsx +12 -2
- package/src/consent-manager/index.tsx +27 -29
- package/src/consent-manager/preference-dialog.tsx +13 -11
- package/src/consent-manager-builder/analytics.ts +5 -5
- package/src/consent-manager-builder/index.tsx +28 -28
- package/src/consent-manager-builder/preferences.ts +20 -14
- package/src/index.ts +8 -4
- package/src/standalone.tsx +1 -1
- package/src/types.ts +8 -2
- package/standalone/consent-manager.js +5 -10
- package/standalone/consent-manager.js.map +1 -1
- package/types/consent-manager/banner.d.ts +1 -1
- package/types/consent-manager/buttons.d.ts +6 -7
- package/types/consent-manager/cancel-dialog.d.ts +1 -1
- package/types/consent-manager/index.d.ts +3 -3
- package/types/consent-manager/preference-dialog.d.ts +1 -1
- package/types/consent-manager-builder/analytics.d.ts +1 -1
- package/types/consent-manager-builder/index.d.ts +7 -8
- package/types/consent-manager-builder/preferences.d.ts +4 -6
- package/types/index.d.ts +1 -1
- package/types/types.d.ts +14 -10
- package/commonjs/__tests__/consent-manager-builder/fetch-destinations.test.js +0 -155
- package/commonjs/consent-manager-builder/fetch-destinations.js +0 -104
- package/esm/__tests__/consent-manager-builder/fetch-destinations.test.js +0 -150
- package/esm/consent-manager-builder/fetch-destinations.js +0 -98
- package/src/__tests__/consent-manager-builder/fetch-destinations.test.ts +0 -89
- package/src/consent-manager-builder/fetch-destinations.ts +0 -50
- package/types/consent-manager-builder/fetch-destinations.d.ts +0 -2
- package/types/src/__tests__/consent-manager-builder/analytics.test.d.ts +0 -1
- package/types/src/__tests__/consent-manager-builder/fetch-destinations.test.d.ts +0 -1
- package/types/src/__tests__/consent-manager-builder/preferences.test.d.ts +0 -1
- package/types/src/__tests__/index.test.d.ts +0 -1
- package/types/src/consent-manager/banner.d.ts +0 -21
- package/types/src/consent-manager/buttons.d.ts +0 -13
- package/types/src/consent-manager/cancel-dialog.d.ts +0 -19
- package/types/src/consent-manager/categories.d.ts +0 -3
- package/types/src/consent-manager/container.d.ts +0 -35
- package/types/src/consent-manager/dialog.d.ts +0 -29
- package/types/src/consent-manager/font-styles.d.ts +0 -2
- package/types/src/consent-manager/index.d.ts +0 -35
- package/types/src/consent-manager/preference-dialog.d.ts +0 -32
- package/types/src/consent-manager-builder/analytics.d.ts +0 -14
- package/types/src/consent-manager-builder/fetch-destinations.d.ts +0 -2
- package/types/src/consent-manager-builder/index.d.ts +0 -126
- package/types/src/consent-manager-builder/preferences.d.ts +0 -26
- package/types/src/index.d.ts +0 -7
- package/types/src/standalone.d.ts +0 -5
- package/types/src/types.d.ts +0 -130
- /package/types/__tests__/{consent-manager-builder/fetch-destinations.test.d.ts → consent-manager/dialog.test.d.ts} +0 -0
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
export declare const DefaultButton: import("@emotion/styled").StyledComponent<{
|
|
3
|
-
theme?: import("@emotion/react").Theme
|
|
4
|
-
as?:
|
|
2
|
+
theme?: import("@emotion/react").Theme;
|
|
3
|
+
as?: React.ElementType;
|
|
5
4
|
}, import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, {}>;
|
|
6
5
|
export declare const GreenButton: import("@emotion/styled").StyledComponent<{
|
|
7
|
-
theme?: import("@emotion/react").Theme
|
|
8
|
-
as?:
|
|
6
|
+
theme?: import("@emotion/react").Theme;
|
|
7
|
+
as?: React.ElementType;
|
|
9
8
|
}, import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, {}>;
|
|
10
9
|
export declare const RedButton: import("@emotion/styled").StyledComponent<{
|
|
11
|
-
theme?: import("@emotion/react").Theme
|
|
12
|
-
as?:
|
|
10
|
+
theme?: import("@emotion/react").Theme;
|
|
11
|
+
as?: React.ElementType;
|
|
13
12
|
}, import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, {}>;
|
|
@@ -10,7 +10,7 @@ interface Props {
|
|
|
10
10
|
}
|
|
11
11
|
export default class CancelDialog extends PureComponent<Props> {
|
|
12
12
|
static displayName: string;
|
|
13
|
-
render(): JSX.Element;
|
|
13
|
+
render(): React.JSX.Element;
|
|
14
14
|
componentDidMount(): void;
|
|
15
15
|
componentWillUnmount(): void;
|
|
16
16
|
handleSubmit: (e: any) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PureComponent } from 'react';
|
|
1
|
+
import React, { PureComponent } from 'react';
|
|
2
2
|
import { CategoryPreferences, Destination, ConsentManagerProps, PreferenceDialogTemplate } from '../types';
|
|
3
3
|
export default class ConsentManager extends PureComponent<ConsentManagerProps, {}> {
|
|
4
4
|
static displayName: string;
|
|
@@ -19,13 +19,13 @@ export default class ConsentManager extends PureComponent<ConsentManagerProps, {
|
|
|
19
19
|
bannerSubContent: string;
|
|
20
20
|
bannerBackgroundColor: string;
|
|
21
21
|
preferencesDialogTitle: string;
|
|
22
|
-
preferencesDialogContent: JSX.Element;
|
|
22
|
+
preferencesDialogContent: React.JSX.Element;
|
|
23
23
|
cancelDialogTitle: string;
|
|
24
24
|
cancelDialogContent: string;
|
|
25
25
|
defaultDestinationBehavior: string;
|
|
26
26
|
preferencesDialogTemplate: PreferenceDialogTemplate;
|
|
27
27
|
};
|
|
28
|
-
render(): JSX.Element;
|
|
28
|
+
render(): React.JSX.Element;
|
|
29
29
|
mergeTemplates: (newProps: PreferenceDialogTemplate, defaultPreferencesDialogTemplate: PreferenceDialogTemplate) => PreferenceDialogTemplate;
|
|
30
30
|
getInitialPreferences: () => {};
|
|
31
31
|
handleMapCustomPreferences: (destinations: Destination[], preferences: CategoryPreferences) => {
|
|
@@ -25,7 +25,7 @@ export default class PreferenceDialog extends PureComponent<PreferenceDialogProp
|
|
|
25
25
|
advertising: null;
|
|
26
26
|
functional: null;
|
|
27
27
|
};
|
|
28
|
-
render(): JSX.Element;
|
|
28
|
+
render(): React.JSX.Element;
|
|
29
29
|
handleChange: (e: any) => void;
|
|
30
30
|
handleSubmit: (e: React.FormEvent<HTMLFormElement>) => void;
|
|
31
31
|
}
|
|
@@ -10,5 +10,5 @@ interface AnalyticsParams {
|
|
|
10
10
|
defaultDestinationBehavior?: DefaultDestinationBehavior;
|
|
11
11
|
categoryPreferences: CategoryPreferences | null | undefined;
|
|
12
12
|
}
|
|
13
|
-
export default function conditionallyLoadAnalytics({ writeKey, options, destinations, destinationPreferences, isConsentRequired, shouldReload, devMode, defaultDestinationBehavior, categoryPreferences }: AnalyticsParams): void;
|
|
13
|
+
export default function conditionallyLoadAnalytics({ writeKey, options, destinations, destinationPreferences, isConsentRequired, shouldReload, devMode, defaultDestinationBehavior, categoryPreferences, }: AnalyticsParams): void;
|
|
14
14
|
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Component } from 'react';
|
|
2
|
-
import { Destination, CategoryPreferences, CustomCategories, DefaultDestinationBehavior, HtEventsBrowserOptions } from '../types';
|
|
3
|
-
import { CookieAttributes } from 'js-cookie';
|
|
2
|
+
import { Destination, CategoryPreferences, CustomCategories, DefaultDestinationBehavior, HtEventsBrowserOptions, CookieAttributes } from '../types';
|
|
4
3
|
interface Props {
|
|
5
4
|
/** Your Hightouch Write key for your website */
|
|
6
5
|
writeKey: string;
|
|
@@ -45,7 +44,8 @@ interface Props {
|
|
|
45
44
|
*/
|
|
46
45
|
onError?: (err: Error) => void | Promise<void>;
|
|
47
46
|
/**
|
|
48
|
-
*
|
|
47
|
+
* Accepted for backward compatibility. Destinations are not fetched from the CDN,
|
|
48
|
+
* so this value is unused.
|
|
49
49
|
*/
|
|
50
50
|
cdnHost?: string;
|
|
51
51
|
/**
|
|
@@ -95,7 +95,6 @@ export default class ConsentManagerBuilder extends Component<Props, State> {
|
|
|
95
95
|
onError: undefined;
|
|
96
96
|
shouldRequireConsent: () => boolean;
|
|
97
97
|
initialPreferences: {};
|
|
98
|
-
cdnHost: string;
|
|
99
98
|
shouldReload: boolean;
|
|
100
99
|
devMode: boolean;
|
|
101
100
|
useDefaultCategories: boolean;
|
|
@@ -111,16 +110,16 @@ export default class ConsentManagerBuilder extends Component<Props, State> {
|
|
|
111
110
|
workspaceAddedNewDestinations: boolean;
|
|
112
111
|
useDefaultCategories: boolean;
|
|
113
112
|
};
|
|
114
|
-
render(): import("react").ReactElement<any, string |
|
|
113
|
+
render(): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | null;
|
|
115
114
|
componentDidMount(): Promise<void>;
|
|
116
115
|
initialise: () => Promise<void>;
|
|
117
116
|
handleSetPreferences: (newPreferences: CategoryPreferences) => void;
|
|
118
117
|
handleResetPreferences: () => void;
|
|
119
|
-
handleSaveConsent: (newPreferences: CategoryPreferences | undefined, shouldReload: boolean, devMode?: boolean
|
|
118
|
+
handleSaveConsent: (newPreferences: CategoryPreferences | undefined, shouldReload: boolean, devMode?: boolean) => void;
|
|
120
119
|
mergePreferences: (args: {
|
|
121
120
|
destinations: Destination[];
|
|
122
|
-
existingPreferences?: CategoryPreferences
|
|
123
|
-
newPreferences?: CategoryPreferences
|
|
121
|
+
existingPreferences?: CategoryPreferences;
|
|
122
|
+
newPreferences?: CategoryPreferences;
|
|
124
123
|
}) => CategoryPreferences;
|
|
125
124
|
}
|
|
126
125
|
export {};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { CookieAttributes } from 'js-cookie';
|
|
3
|
-
import { Preferences } from '../types';
|
|
1
|
+
import { Preferences, CookieAttributes } from '../types';
|
|
4
2
|
import { EventEmitter } from 'events';
|
|
5
3
|
export declare const DEFAULT_COOKIE_NAME = "ht-cm-preferences";
|
|
6
4
|
export interface PreferencesManager {
|
|
@@ -9,7 +7,7 @@ export interface PreferencesManager {
|
|
|
9
7
|
savePreferences(prefs: SavePreferences): void;
|
|
10
8
|
}
|
|
11
9
|
export declare function loadPreferences(cookieName?: string): Preferences;
|
|
12
|
-
|
|
10
|
+
type SavePreferences = Preferences & {
|
|
13
11
|
cookieDomain?: string;
|
|
14
12
|
cookieName?: string;
|
|
15
13
|
cookieExpires?: number;
|
|
@@ -21,6 +19,6 @@ declare type SavePreferences = Preferences & {
|
|
|
21
19
|
*
|
|
22
20
|
* @param listener a function to be invoked when ConsentPreferences are saved
|
|
23
21
|
*/
|
|
24
|
-
export declare function onPreferencesSaved(listener: (prefs: Preferences) => void): () => EventEmitter
|
|
25
|
-
export declare function savePreferences({ destinationPreferences, customPreferences, cookieDomain, cookieName, cookieExpires, cookieAttributes }: SavePreferences): void;
|
|
22
|
+
export declare function onPreferencesSaved(listener: (prefs: Preferences) => void): () => EventEmitter<[never]>;
|
|
23
|
+
export declare function savePreferences({ destinationPreferences, customPreferences, cookieDomain, cookieName, cookieExpires, cookieAttributes, }: SavePreferences): void;
|
|
26
24
|
export {};
|
package/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import CMB from './consent-manager-builder';
|
|
2
2
|
import CM from './consent-manager';
|
|
3
3
|
export { openDialog as openConsentManager } from './consent-manager/container';
|
|
4
|
-
export { loadPreferences, savePreferences, onPreferencesSaved } from './consent-manager-builder/preferences';
|
|
4
|
+
export { loadPreferences, savePreferences, onPreferencesSaved, } from './consent-manager-builder/preferences';
|
|
5
5
|
export declare const ConsentManagerBuilder: typeof CMB;
|
|
6
6
|
export declare const ConsentManager: typeof CM;
|
|
7
7
|
export declare function doNotTrack(): boolean | null;
|
package/types/types.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { CloseBehaviorFunction } from './consent-manager/container';
|
|
3
2
|
import { PreferencesManager } from './consent-manager-builder/preferences';
|
|
4
|
-
import
|
|
5
|
-
export
|
|
3
|
+
import Cookies from 'js-cookie';
|
|
4
|
+
export type CookieAttributes = NonNullable<Parameters<typeof Cookies.set>[2]>;
|
|
5
|
+
export type HtEventsBrowserOptions = {
|
|
6
6
|
integrations?: Record<string, boolean>;
|
|
7
7
|
apiHost?: string;
|
|
8
8
|
protocol?: string;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type HtEventsBrowser = {
|
|
11
11
|
initialized: boolean;
|
|
12
12
|
load: (writeKey: string, options?: HtEventsBrowserOptions) => void;
|
|
13
13
|
track: (event: string, properties: Record<string, any>, options?: any, callback?: any) => void;
|
|
14
14
|
addSourceMiddleware: (middleware: Middleware) => void;
|
|
15
15
|
};
|
|
16
|
-
export
|
|
16
|
+
export type Middleware = (input: MiddlewareInput) => void;
|
|
17
17
|
interface MiddlewareInput {
|
|
18
18
|
payload: {
|
|
19
19
|
obj: Record<string, any>;
|
|
@@ -22,17 +22,17 @@ interface MiddlewareInput {
|
|
|
22
22
|
integrations?: Record<string, boolean>;
|
|
23
23
|
next: (payload: MiddlewareInput['payload']) => void;
|
|
24
24
|
}
|
|
25
|
-
export
|
|
25
|
+
export type WindowWithHtEvents = Window & typeof globalThis & {
|
|
26
26
|
htevents?: HtEventsBrowser;
|
|
27
27
|
};
|
|
28
|
-
export
|
|
28
|
+
export type WindowWithConsentManagerConfig = Window & typeof globalThis & {
|
|
29
29
|
consentManagerConfig?: (args: StandaloneConsentManagerParams) => ConsentManagerInput | ConsentManagerInput;
|
|
30
30
|
};
|
|
31
|
-
export
|
|
31
|
+
export type ConsentManagerInput = ConsentManagerProps & {
|
|
32
32
|
container: string;
|
|
33
33
|
};
|
|
34
|
-
export
|
|
35
|
-
export
|
|
34
|
+
export type DefaultDestinationBehavior = 'enable' | 'disable' | 'imply' | 'ask';
|
|
35
|
+
export type CloseBehavior = 'accept' | 'deny' | 'dismiss';
|
|
36
36
|
interface StandaloneConsentManagerParams {
|
|
37
37
|
React: unknown;
|
|
38
38
|
version?: string;
|
|
@@ -119,6 +119,10 @@ export interface ConsentManagerProps {
|
|
|
119
119
|
initialPreferences?: CategoryPreferences;
|
|
120
120
|
customCategories?: CustomCategories;
|
|
121
121
|
defaultDestinationBehavior?: DefaultDestinationBehavior;
|
|
122
|
+
/**
|
|
123
|
+
* Accepted for backward compatibility. Destinations are not fetched from the CDN,
|
|
124
|
+
* so this value is unused.
|
|
125
|
+
*/
|
|
122
126
|
cdnHost?: string;
|
|
123
127
|
preferencesDialogTemplate?: PreferenceDialogTemplate;
|
|
124
128
|
}
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
var nock_1 = __importDefault(require("nock"));
|
|
43
|
-
var fetch_destinations_1 = __importDefault(require("../../consent-manager-builder/fetch-destinations"));
|
|
44
|
-
describe('fetchDestinations', function () {
|
|
45
|
-
test('Returns destinations for a writekey', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
46
|
-
var _a;
|
|
47
|
-
return __generator(this, function (_b) {
|
|
48
|
-
switch (_b.label) {
|
|
49
|
-
case 0:
|
|
50
|
-
nock_1.default('https://cdn.hightouch-events.com')
|
|
51
|
-
.get('/v1/projects/123/integrations')
|
|
52
|
-
.reply(200, [
|
|
53
|
-
{
|
|
54
|
-
name: 'Google Analytics',
|
|
55
|
-
creationName: 'Google Analytics'
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
name: 'Amplitude',
|
|
59
|
-
creationName: 'Amplitude'
|
|
60
|
-
}
|
|
61
|
-
]);
|
|
62
|
-
_a = expect;
|
|
63
|
-
return [4 /*yield*/, fetch_destinations_1.default('cdn.hightouch-events.com', ['123'])];
|
|
64
|
-
case 1:
|
|
65
|
-
_a.apply(void 0, [_b.sent()]).toMatchObject([
|
|
66
|
-
{
|
|
67
|
-
id: 'Amplitude',
|
|
68
|
-
name: 'Amplitude'
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
id: 'Google Analytics',
|
|
72
|
-
name: 'Google Analytics'
|
|
73
|
-
}
|
|
74
|
-
]);
|
|
75
|
-
return [2 /*return*/];
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}); });
|
|
79
|
-
test('Renames creationName to id', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
80
|
-
var _a;
|
|
81
|
-
return __generator(this, function (_b) {
|
|
82
|
-
switch (_b.label) {
|
|
83
|
-
case 0:
|
|
84
|
-
nock_1.default('https://cdn.hightouch-events.com')
|
|
85
|
-
.get('/v1/projects/123/integrations')
|
|
86
|
-
.reply(200, [
|
|
87
|
-
{
|
|
88
|
-
name: 'New Amplitude',
|
|
89
|
-
creationName: 'Old Amplitude'
|
|
90
|
-
}
|
|
91
|
-
]);
|
|
92
|
-
_a = expect;
|
|
93
|
-
return [4 /*yield*/, fetch_destinations_1.default('cdn.hightouch-events.com', ['123'])];
|
|
94
|
-
case 1:
|
|
95
|
-
_a.apply(void 0, [_b.sent()]).toMatchObject([
|
|
96
|
-
{
|
|
97
|
-
id: 'Old Amplitude',
|
|
98
|
-
name: 'New Amplitude'
|
|
99
|
-
}
|
|
100
|
-
]);
|
|
101
|
-
return [2 /*return*/];
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
}); });
|
|
105
|
-
test('Doesn՚t include duplicate destinations', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
106
|
-
var _a;
|
|
107
|
-
return __generator(this, function (_b) {
|
|
108
|
-
switch (_b.label) {
|
|
109
|
-
case 0:
|
|
110
|
-
nock_1.default('https://cdn.hightouch-events.com')
|
|
111
|
-
.get('/v1/projects/123/integrations')
|
|
112
|
-
.reply(200, [
|
|
113
|
-
{
|
|
114
|
-
name: 'Google Analytics',
|
|
115
|
-
creationName: 'Google Analytics'
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
name: 'Amplitude',
|
|
119
|
-
creationName: 'Amplitude'
|
|
120
|
-
}
|
|
121
|
-
])
|
|
122
|
-
.get('/v1/projects/abc/integrations')
|
|
123
|
-
.reply(200, [
|
|
124
|
-
{
|
|
125
|
-
name: 'Google Analytics',
|
|
126
|
-
creationName: 'Google Analytics'
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
name: 'FullStory',
|
|
130
|
-
creationName: 'FullStory'
|
|
131
|
-
}
|
|
132
|
-
]);
|
|
133
|
-
_a = expect;
|
|
134
|
-
return [4 /*yield*/, fetch_destinations_1.default('cdn.hightouch-events.com', ['123', 'abc'])];
|
|
135
|
-
case 1:
|
|
136
|
-
_a.apply(void 0, [_b.sent()]).toMatchObject([
|
|
137
|
-
{
|
|
138
|
-
id: 'Amplitude',
|
|
139
|
-
name: 'Amplitude'
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
id: 'FullStory',
|
|
143
|
-
name: 'FullStory'
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
id: 'Google Analytics',
|
|
147
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O3lCQUNELEdBQUcsQ0FBQywrQkFBK0IsQ0FBQzt5QkFDcEMsS0FBSyxDQUFDLEdBQUcsRUFBRTt3QkFDVjs0QkFDRSxJQUFJLEVBQUUsa0JBQWtCOzRCQUN4QixZQUFZLEVBQUUsa0JBQWtCO3lCQUNqQzt3QkFDRDs0QkFDRSxJQUFJLEVBQUUsV0FBVzs0QkFDakIsWUFBWSxFQUFFLFdBQVc7eUJBQzFCO3FCQUNGLENBQUMsQ0FBQTtvQkFFSixLQUFBLE1BQU0sQ0FBQTtvQkFBQyxxQkFBTSw0QkFBaUIsQ0FBQywwQkFBMEIsRUFBRSxDQUFDLEtBQUssRUFBRSxLQUFLLENBQUMsQ0FBQyxFQUFBOztvQkFBMUUsa0JBQU8sU0FBbUUsRUFBQyxDQUFDLGFBQWEsQ0FBQzt3QkFDeEY7NEJBQ0UsRUFBRSxFQUFFLFdBQVc7NEJBQ2YsSUFBSSxFQUFFLFdBQVc7eUJBQ2xCO3dCQUNEOzRCQUNFLEVBQUUsRUFBRSxXQUFXOzRCQUNmLElBQUksRUFBRSxXQUFXO3lCQUNsQjt3QkFDRDs0QkFDRSxFQUFFLEVBQUUsa0JBQWtCOzRCQUN0QixJQUFJLEVBQUUsa0JBQWtCO3lCQUN6QjtxQkFDRixDQUFDLENBQUE7Ozs7U0FDSCxDQUFDLENBQUE7QUFDSixDQUFDLENBQUMsQ0FBQSJ9
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
var isomorphic_fetch_1 = __importDefault(require("isomorphic-fetch"));
|
|
43
|
-
var flatten_1 = __importDefault(require("lodash/flatten"));
|
|
44
|
-
var sortedUniqBy_1 = __importDefault(require("lodash/sortedUniqBy"));
|
|
45
|
-
var sortBy_1 = __importDefault(require("lodash/sortBy"));
|
|
46
|
-
function fetchDestinationForWriteKey(cdnHost, writeKey) {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
-
var res, destinations, _i, destinations_1, destination;
|
|
49
|
-
return __generator(this, function (_a) {
|
|
50
|
-
switch (_a.label) {
|
|
51
|
-
case 0: return [4 /*yield*/, isomorphic_fetch_1.default("https://" + cdnHost + "/v1/projects/" + writeKey + "/integrations")];
|
|
52
|
-
case 1:
|
|
53
|
-
res = _a.sent();
|
|
54
|
-
if (!res.ok) {
|
|
55
|
-
throw new Error("Failed to fetch integrations for write key " + writeKey + ": HTTP " + res.status + " " + res.statusText);
|
|
56
|
-
}
|
|
57
|
-
return [4 /*yield*/, res.json()
|
|
58
|
-
// Rename creationName to id to abstract the weird data model
|
|
59
|
-
];
|
|
60
|
-
case 2:
|
|
61
|
-
destinations = _a.sent();
|
|
62
|
-
// Rename creationName to id to abstract the weird data model
|
|
63
|
-
for (_i = 0, destinations_1 = destinations; _i < destinations_1.length; _i++) {
|
|
64
|
-
destination = destinations_1[_i];
|
|
65
|
-
// Because of the legacy Fullstory integration the creationName for this integration is the `name`
|
|
66
|
-
if (destination.name === 'Fullstory') {
|
|
67
|
-
destination.id = destination.name;
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
destination.id = destination.creationName;
|
|
71
|
-
}
|
|
72
|
-
delete destination.creationName;
|
|
73
|
-
}
|
|
74
|
-
return [2 /*return*/, destinations];
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
function fetchDestinations(cdnHost, writeKeys) {
|
|
80
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
-
var destinationsRequests, _i, writeKeys_1, writeKey, destinations, _a;
|
|
82
|
-
return __generator(this, function (_b) {
|
|
83
|
-
switch (_b.label) {
|
|
84
|
-
case 0:
|
|
85
|
-
destinationsRequests = [];
|
|
86
|
-
for (_i = 0, writeKeys_1 = writeKeys; _i < writeKeys_1.length; _i++) {
|
|
87
|
-
writeKey = writeKeys_1[_i];
|
|
88
|
-
destinationsRequests.push(fetchDestinationForWriteKey(cdnHost, writeKey));
|
|
89
|
-
}
|
|
90
|
-
_a = flatten_1.default;
|
|
91
|
-
return [4 /*yield*/, Promise.all(destinationsRequests)];
|
|
92
|
-
case 1:
|
|
93
|
-
destinations = _a.apply(void 0, [_b.sent()]);
|
|
94
|
-
// Remove the dummy Repeater destination
|
|
95
|
-
destinations = destinations.filter(function (d) { return d.id !== 'Repeater'; });
|
|
96
|
-
destinations = sortBy_1.default(destinations, ['id']);
|
|
97
|
-
destinations = sortedUniqBy_1.default(destinations, 'id');
|
|
98
|
-
return [2 /*return*/, destinations];
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
exports.default = fetchDestinations;
|
|
104
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmV0Y2gtZGVzdGluYXRpb25zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NvbnNlbnQtbWFuYWdlci1idWlsZGVyL2ZldGNoLWRlc3RpbmF0aW9ucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs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