@mhubcloud/tms_core 3.5.1 → 3.6.0-beta.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.
- package/LICENSE +202 -202
- package/dist/index.js +32 -0
- package/package.json +46 -46
- package/.eslintignore +0 -3
- package/.eslintrc.cjs +0 -87
- package/.prettierignore +0 -3
- package/.prettierrc +0 -10
- package/.vscode/extensions.json +0 -12
- package/.vscode/settings.json +0 -51
- package/index.js +0 -17
- package/releasePlan.md +0 -2
- package/src/broker.ts +0 -182
- package/src/defaultPublisher.ts +0 -144
- package/src/index.ts +0 -30
- package/src/publishers/affiliatePort.ts +0 -69
- package/src/publishers/cj.ts +0 -70
- package/src/publishers/facebook.ts +0 -93
- package/src/publishers/googleAds.ts +0 -193
- package/src/publishers/googleAnalytics4.ts +0 -60
- package/src/publishers/piano.ts +0 -71
- package/src/publishers/universalAnalytics.ts +0 -63
- package/src/types/EventPublisher.ts +0 -13
- package/src/types/EventToLog.ts +0 -5
- package/src/types/PlatformPublisher.ts +0 -20
- package/src/types/ServiceBusMessage.ts +0 -10
- package/src/types/UtilTypes.ts +0 -1
- package/src/types/global.d.ts +0 -3
- package/src/utils/testUtils.ts +0 -18
- package/src/utils/utils.ts +0 -433
- package/tests/AffiliatePort.js +0 -133
- package/tests/CJ.js +0 -161
- package/tests/Facebook.js +0 -128
- package/tests/GoogleAds.js +0 -130
- package/tests/GoogleAnalytics4.js +0 -99
- package/tests/Piano.js +0 -120
- package/tests/UniversalAnalytics.js +0 -107
- package/tsconfig.eslint.json +0 -43
- package/tsconfig.json +0 -26
package/.prettierignore
DELETED
package/.prettierrc
DELETED
package/.vscode/extensions.json
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
|
|
3
|
-
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
|
|
4
|
-
// List of extensions which should be recommended for users of this workspace.
|
|
5
|
-
"recommendations": [
|
|
6
|
-
"dbaeumer.vscode-eslint"
|
|
7
|
-
],
|
|
8
|
-
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
|
|
9
|
-
"unwantedRecommendations": [
|
|
10
|
-
"esbenp.prettier-vscode"
|
|
11
|
-
]
|
|
12
|
-
}
|
package/.vscode/settings.json
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// EDITOR
|
|
3
|
-
// ----------------------------------------
|
|
4
|
-
"[javascript]": {
|
|
5
|
-
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
6
|
-
},
|
|
7
|
-
"[json]": {
|
|
8
|
-
"editor.defaultFormatter": "vscode.json-language-features"
|
|
9
|
-
},
|
|
10
|
-
"[jsonc]": {
|
|
11
|
-
"editor.defaultFormatter": "vscode.json-language-features"
|
|
12
|
-
},
|
|
13
|
-
"[typescript]": {
|
|
14
|
-
"editor.autoClosingBrackets": "always",
|
|
15
|
-
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
16
|
-
},
|
|
17
|
-
"editor.codeActionsOnSave": [
|
|
18
|
-
// "source.organizeImports",
|
|
19
|
-
"source.fixAll.eslint"
|
|
20
|
-
],
|
|
21
|
-
// "editor.formatOnSave": true,
|
|
22
|
-
"typescript.tsdk": "node_modules/typescript/lib",
|
|
23
|
-
// ESLINT
|
|
24
|
-
// ----------------------------------------
|
|
25
|
-
"eslint.alwaysShowStatus": true,
|
|
26
|
-
"eslint.options": {
|
|
27
|
-
"extensions": [
|
|
28
|
-
".js",
|
|
29
|
-
".cjs",
|
|
30
|
-
".ts",
|
|
31
|
-
".tsx"
|
|
32
|
-
]
|
|
33
|
-
},
|
|
34
|
-
"eslint.validate": [
|
|
35
|
-
"javascript",
|
|
36
|
-
"typescript"
|
|
37
|
-
],
|
|
38
|
-
"eslint.format.enable": true,
|
|
39
|
-
// FILES
|
|
40
|
-
// ----------------------------------------
|
|
41
|
-
"files.exclude": {
|
|
42
|
-
"**/*.log": true,
|
|
43
|
-
"**/*.log*": true,
|
|
44
|
-
"**/build": true,
|
|
45
|
-
},
|
|
46
|
-
"search.exclude": {
|
|
47
|
-
"**/node_modules": false
|
|
48
|
-
},
|
|
49
|
-
"volar.completion.preferredTagNameCase": "pascal",
|
|
50
|
-
"eslint.packageManager": "pnpm"
|
|
51
|
-
}
|
package/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const utils = require('./lib/utils');
|
|
2
|
-
const DefaultPublisher = require('./lib/DefaultPublisher');
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
utils : utils,
|
|
6
|
-
DefaultPublisher : DefaultPublisher,
|
|
7
|
-
publisher : {
|
|
8
|
-
Piano : require('./publishers/Piano'),
|
|
9
|
-
Facebook : require('./publishers/Facebook'),
|
|
10
|
-
GoogleAnalytics4 : require('./publishers/GoogleAnalytics4'),
|
|
11
|
-
CJ : require('./publishers/CJ'),
|
|
12
|
-
UniversalAnalytics : require('./publishers/UniversalAnalytics'),
|
|
13
|
-
TableStorage : require('./publishers/TableStorage'),
|
|
14
|
-
HttpPublisher : require('./publishers/HttpPublisher'),
|
|
15
|
-
AffiliatePort : require('./publishers/AffiliatePort')
|
|
16
|
-
}
|
|
17
|
-
}
|
package/releasePlan.md
DELETED
package/src/broker.ts
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { CosmosClient } from '@azure/cosmos';
|
|
2
|
-
import { ServiceBusClient, ServiceBusSender } from '@azure/service-bus';
|
|
3
|
-
import { ServiceBusMessage } from './types/ServiceBusMessage';
|
|
4
|
-
import * as utils from './utils/utils';
|
|
5
|
-
const serviceBusConnectionString = process.env.ServiceBusConnectionString;
|
|
6
|
-
const cosmosConnectionString = process.env.CosmosDbConnectionString;
|
|
7
|
-
const cosmosDatabaseName = process.env.CosmosDbDatabaseName;
|
|
8
|
-
const cosmosContainerName = process.env.CosmosDbEventsContainerName;
|
|
9
|
-
let serviceBusClient: ServiceBusClient | undefined;
|
|
10
|
-
let cosmosClient: CosmosClient | undefined;
|
|
11
|
-
const senders: Record<string, ServiceBusSender> = {};
|
|
12
|
-
|
|
13
|
-
type PublisherConfig = Record<
|
|
14
|
-
string,
|
|
15
|
-
string | [string, PublisherEvent[]] | PublisherEvent[]
|
|
16
|
-
>;
|
|
17
|
-
|
|
18
|
-
type PublisherEvent = Record<string, string>;
|
|
19
|
-
interface EventInfo {
|
|
20
|
-
code: string;
|
|
21
|
-
[key: string]: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Evaluates an event against publisher configurations
|
|
26
|
-
* @param eventCode event.code parameter of the event
|
|
27
|
-
* @param publisherConfig object containing publisher event consumption configurations
|
|
28
|
-
* @returns list of publishers for which an event is relevant.
|
|
29
|
-
*/
|
|
30
|
-
export function resolveEvent(
|
|
31
|
-
event: EventInfo,
|
|
32
|
-
publisherConfig?: PublisherConfig,
|
|
33
|
-
) {
|
|
34
|
-
if (!publisherConfig) {
|
|
35
|
-
const envConfig = process.env.Broker_PublisherConfig;
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
37
|
-
publisherConfig = envConfig ? JSON.parse(envConfig) : {};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const publishers = [];
|
|
41
|
-
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
43
|
-
for (const publisher of Object.keys(publisherConfig!)) {
|
|
44
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
45
|
-
const publisherEvents = publisherConfig![publisher];
|
|
46
|
-
if (publisherEvents) {
|
|
47
|
-
if (publisherEvents[0] === '*') {
|
|
48
|
-
let matchesExcluded = false;
|
|
49
|
-
// Checking whether event matches any of the excluded events
|
|
50
|
-
if (
|
|
51
|
-
Array.isArray(publisherEvents[1]) &&
|
|
52
|
-
publisherEvents[1].length > 0
|
|
53
|
-
) {
|
|
54
|
-
for (const publisherEvent of publisherEvents[1]) {
|
|
55
|
-
if (matchesExcluded) {
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
matchesExcluded = matchEvent(event, publisherEvent);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (!matchesExcluded) {
|
|
63
|
-
publishers.push(publisher);
|
|
64
|
-
}
|
|
65
|
-
} else {
|
|
66
|
-
let match = false;
|
|
67
|
-
|
|
68
|
-
for (const publisherEvent of publisherEvents) {
|
|
69
|
-
if (Array.isArray(publisherEvent)) {
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
match = matchEvent(event, publisherEvent);
|
|
73
|
-
if (match) {
|
|
74
|
-
publishers.push(publisher);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (publishers.length === 0) {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return publishers;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function matchEvent(event: EventInfo, publisherEvent: string | PublisherEvent) {
|
|
89
|
-
if (typeof publisherEvent === 'string') {
|
|
90
|
-
const regex = new RegExp(publisherEvent);
|
|
91
|
-
const match = regex.test(event.code);
|
|
92
|
-
return match;
|
|
93
|
-
} else if (typeof publisherEvent === 'object') {
|
|
94
|
-
let paramMatch = true;
|
|
95
|
-
for (const key of Object.keys(publisherEvent)) {
|
|
96
|
-
const publisherEventParam = publisherEvent[key];
|
|
97
|
-
const eventParam = event[key];
|
|
98
|
-
if (
|
|
99
|
-
typeof publisherEventParam === 'string' &&
|
|
100
|
-
typeof eventParam === 'string'
|
|
101
|
-
) {
|
|
102
|
-
const regex = new RegExp(publisherEventParam);
|
|
103
|
-
paramMatch = regex.test(eventParam);
|
|
104
|
-
if (!paramMatch) {
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
} else if (publisherEventParam && !eventParam) {
|
|
108
|
-
return false;
|
|
109
|
-
} else {
|
|
110
|
-
throw new Error('Unexpected formatting in publisher configuration');
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return true;
|
|
114
|
-
} else {
|
|
115
|
-
throw new Error('Unexpected formatting in publisher configuration');
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Sends an event to Service Bus
|
|
121
|
-
* @param message event to be sent
|
|
122
|
-
* @param queues list of Service Bus queues to send the event to
|
|
123
|
-
*/
|
|
124
|
-
export async function dispatchEvent(
|
|
125
|
-
message: Record<string, string>,
|
|
126
|
-
queues: string[],
|
|
127
|
-
) {
|
|
128
|
-
if (!serviceBusClient) {
|
|
129
|
-
if (!serviceBusConnectionString) {
|
|
130
|
-
throw new Error('Service Bus connection string is missing.');
|
|
131
|
-
}
|
|
132
|
-
serviceBusClient = new ServiceBusClient(serviceBusConnectionString);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
await Promise.all(
|
|
136
|
-
queues.map(async (queue) => {
|
|
137
|
-
try {
|
|
138
|
-
let sender;
|
|
139
|
-
if (senders[queue]) {
|
|
140
|
-
sender = senders[queue];
|
|
141
|
-
} else {
|
|
142
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
143
|
-
senders[queue] = serviceBusClient!.createSender(queue);
|
|
144
|
-
sender = senders[queue];
|
|
145
|
-
}
|
|
146
|
-
await sender.sendMessages({ body: message });
|
|
147
|
-
} catch (e) {
|
|
148
|
-
console.log(`Sending to queue ${queue} failed`);
|
|
149
|
-
}
|
|
150
|
-
}),
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Logs an event to Cosmos DB
|
|
156
|
-
* @param message event to be logged
|
|
157
|
-
*/
|
|
158
|
-
export async function logToCosmosDb(message: ServiceBusMessage) {
|
|
159
|
-
if (!cosmosClient) {
|
|
160
|
-
if (!cosmosConnectionString) {
|
|
161
|
-
throw new Error('Cosmos DB connection string is missing.');
|
|
162
|
-
}
|
|
163
|
-
cosmosClient = new CosmosClient(cosmosConnectionString);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (!cosmosDatabaseName) {
|
|
167
|
-
throw new Error('Cosmos DB database name is missing.');
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (!cosmosContainerName) {
|
|
171
|
-
throw new Error('Cosmos DB events container name is missing.');
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
try {
|
|
175
|
-
await cosmosClient
|
|
176
|
-
.database(cosmosDatabaseName)
|
|
177
|
-
.container(cosmosContainerName)
|
|
178
|
-
.items.create(message);
|
|
179
|
-
} catch (e) {
|
|
180
|
-
utils.logException(e as Error);
|
|
181
|
-
}
|
|
182
|
-
}
|
package/src/defaultPublisher.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { Context, Logger } from '@azure/functions';
|
|
2
|
-
import { Telemetry } from 'applicationinsights/out/Declarations/Contracts';
|
|
3
|
-
import { EventPublisher } from './types/EventPublisher';
|
|
4
|
-
import { EventToLog } from './types/EventToLog';
|
|
5
|
-
import { PlatformPublisher } from './types/PlatformPublisher';
|
|
6
|
-
import { ServiceBusMessage } from './types/ServiceBusMessage';
|
|
7
|
-
import { TypeSafeObject } from './types/UtilTypes';
|
|
8
|
-
import * as utils from './utils/utils';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Implements the Azure Function, called for set of events received via Service Bus
|
|
12
|
-
* @deprecated Udelat novou metodu, ktera bude spravne a bude inicializovat classu
|
|
13
|
-
* @param azureFunctionContext Azure Function Context
|
|
14
|
-
* @param serviceBusMessage Message received from Service Bus
|
|
15
|
-
* @param source Name of the publisher (name of the folder in which it is implemented)
|
|
16
|
-
* @param platformPublisher Publisher implementation instance (from <publisher>/publisher.js)
|
|
17
|
-
* @param trigger
|
|
18
|
-
*/
|
|
19
|
-
export async function defaultPublisher(
|
|
20
|
-
azureFunctionContext: Context,
|
|
21
|
-
serviceBusMessage: ServiceBusMessage,
|
|
22
|
-
source: string,
|
|
23
|
-
platformPublisher: PlatformPublisher,
|
|
24
|
-
trigger: (a: unknown) => Promise<EventPublisher[]>,
|
|
25
|
-
) {
|
|
26
|
-
if (serviceBusMessage.$schema === 'mhub/pingtest') {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const processMessagePromises = [];
|
|
30
|
-
processMessagePromises.push(
|
|
31
|
-
processMessage(
|
|
32
|
-
serviceBusMessage,
|
|
33
|
-
azureFunctionContext.log,
|
|
34
|
-
platformPublisher,
|
|
35
|
-
trigger,
|
|
36
|
-
),
|
|
37
|
-
);
|
|
38
|
-
const results = await Promise.allSettled(processMessagePromises);
|
|
39
|
-
// ? musi nahoru probublat, ze aspon neco selhalo a to je to, co bude triggerovat nasledujici error. Error pro konkretniho publishera musi byt primo v processMessage v loopu. Hodnotu pro typ publishera vezmeme z platformBublisher.SOURCE
|
|
40
|
-
for (const result of results) {
|
|
41
|
-
if (result.status === 'rejected') {
|
|
42
|
-
if (result.reason instanceof Error) {
|
|
43
|
-
const formattedError = utils.formatError(result.reason);
|
|
44
|
-
utils.logException(new Error(formattedError.message));
|
|
45
|
-
throw formattedError;
|
|
46
|
-
} else {
|
|
47
|
-
const formattedError = utils.formatError(
|
|
48
|
-
typeof result.reason === 'object'
|
|
49
|
-
? JSON.stringify(result.reason)
|
|
50
|
-
: (result.reason as Error['message']),
|
|
51
|
-
);
|
|
52
|
-
utils.logException(new Error(formattedError.message));
|
|
53
|
-
throw formattedError;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Processes a single message from Service Bus
|
|
61
|
-
* @param message A message received from Service Bus
|
|
62
|
-
* @param log Azure Function context.log
|
|
63
|
-
* @param platformPublisher Publisher implementation instance (from <publisher>.js)
|
|
64
|
-
* @param trigger Publisher-specific trigger function (from trigger.js)
|
|
65
|
-
* @param source Name of the publisher as defined in index.js
|
|
66
|
-
* @returns Returns false if at least one publisher failed or in case of other failed requirements
|
|
67
|
-
*/
|
|
68
|
-
async function processMessage(
|
|
69
|
-
message: ServiceBusMessage,
|
|
70
|
-
log: Logger,
|
|
71
|
-
platformPublisher: PlatformPublisher,
|
|
72
|
-
trigger: (a: object, log: Logger) => Promise<EventPublisher[]>,
|
|
73
|
-
) {
|
|
74
|
-
const logProperties: Telemetry['properties'] = {
|
|
75
|
-
source: platformPublisher.source,
|
|
76
|
-
data: JSON.stringify(message),
|
|
77
|
-
};
|
|
78
|
-
const publishers = await trigger(message, log);
|
|
79
|
-
if (!publishers.length) {
|
|
80
|
-
utils.logMessage(
|
|
81
|
-
1,
|
|
82
|
-
'Message excluded by filter (no publishers determined)',
|
|
83
|
-
logProperties,
|
|
84
|
-
);
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
let publishedAny = false;
|
|
88
|
-
const failedToPublishAll = false;
|
|
89
|
-
for (const eventPublisher of publishers) {
|
|
90
|
-
const mapped = await eventPublisher.map(message, log);
|
|
91
|
-
|
|
92
|
-
const res = await publishMessage(
|
|
93
|
-
log,
|
|
94
|
-
mapped,
|
|
95
|
-
eventPublisher.config,
|
|
96
|
-
platformPublisher,
|
|
97
|
-
{
|
|
98
|
-
event:
|
|
99
|
-
message.event.code +
|
|
100
|
-
(message.event.name ? '/' + message.event.name : ''),
|
|
101
|
-
region: message.event.region,
|
|
102
|
-
id: message.messageId,
|
|
103
|
-
},
|
|
104
|
-
);
|
|
105
|
-
if (res) {
|
|
106
|
-
publishedAny = true;
|
|
107
|
-
} else {
|
|
108
|
-
utils.logException(
|
|
109
|
-
new Error(
|
|
110
|
-
`The message has not been published. Source: ${platformPublisher.source}`,
|
|
111
|
-
),
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (!publishedAny) {
|
|
116
|
-
utils.logException(
|
|
117
|
-
new Error(
|
|
118
|
-
'The message has not been published to any publisher configuration',
|
|
119
|
-
),
|
|
120
|
-
);
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
// Returns false
|
|
124
|
-
return !failedToPublishAll;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Publishes a message to configured publisher
|
|
129
|
-
* @param log Azure Function context.log
|
|
130
|
-
* @param mapped Mapped message data
|
|
131
|
-
* @param config Platform-specific platform publisher configuration
|
|
132
|
-
* @param platformPublisher Publisher implementation instance (from <publisher>/publisher.js)
|
|
133
|
-
* @param event Event for which logic was triggered
|
|
134
|
-
*/
|
|
135
|
-
async function publishMessage(
|
|
136
|
-
log: Logger,
|
|
137
|
-
mapped: TypeSafeObject,
|
|
138
|
-
config: TypeSafeObject,
|
|
139
|
-
platformPublisher: PlatformPublisher,
|
|
140
|
-
event: EventToLog,
|
|
141
|
-
) {
|
|
142
|
-
await platformPublisher.publish(log, config, mapped, event);
|
|
143
|
-
return true;
|
|
144
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import * as broker from './broker';
|
|
2
|
-
import { defaultPublisher } from './defaultPublisher';
|
|
3
|
-
import { affiliatePort } from './publishers/affiliatePort';
|
|
4
|
-
import { cj } from './publishers/cj';
|
|
5
|
-
import { facebook } from './publishers/facebook';
|
|
6
|
-
import { googleAds } from './publishers/googleAds';
|
|
7
|
-
import { googleAnalytics4 } from './publishers/googleAnalytics4';
|
|
8
|
-
import { piano } from './publishers/piano';
|
|
9
|
-
import { universalAnalytics } from './publishers/universalAnalytics';
|
|
10
|
-
import * as testUtils from './utils/testUtils';
|
|
11
|
-
import * as utils from './utils/utils';
|
|
12
|
-
|
|
13
|
-
export const publisher = {
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
15
|
-
Facebook: facebook,
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
17
|
-
CJ: cj,
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
19
|
-
GoogleAds: googleAds,
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
21
|
-
GoogleAnalytics4: googleAnalytics4,
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
23
|
-
UniversalAnalytics: universalAnalytics,
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
25
|
-
Piano: piano,
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
27
|
-
AffiliatePort: affiliatePort,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export { broker, utils, defaultPublisher as DefaultPublisher, testUtils };
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import * as utils from './../utils/utils';
|
|
2
|
-
import {
|
|
3
|
-
PlatformPublisher,
|
|
4
|
-
PlatformRequestOptions,
|
|
5
|
-
} from '../types/PlatformPublisher';
|
|
6
|
-
|
|
7
|
-
interface Product {
|
|
8
|
-
orderId: string;
|
|
9
|
-
quantity: number;
|
|
10
|
-
price: number;
|
|
11
|
-
category: string;
|
|
12
|
-
masterType: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface AffiliatePortData {
|
|
16
|
-
products: Product[];
|
|
17
|
-
orderId: string;
|
|
18
|
-
transactionID: string;
|
|
19
|
-
[x: string]: unknown;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const affiliatePort: PlatformPublisher = {
|
|
23
|
-
source: 'AffiliatePort',
|
|
24
|
-
/**
|
|
25
|
-
* Publishes data to AffiliatePort
|
|
26
|
-
* @param log zure Function context.log
|
|
27
|
-
* @param config Publisher configuration
|
|
28
|
-
* @param data Data in publisher-friendly format to be published
|
|
29
|
-
* @param event Event for which the function is triggered
|
|
30
|
-
*/
|
|
31
|
-
async publish(log, config, data, event) {
|
|
32
|
-
if (
|
|
33
|
-
(data as AffiliatePortData).products instanceof Array &&
|
|
34
|
-
(typeof config.offerId === 'string' || typeof config.offerId === 'number')
|
|
35
|
-
) {
|
|
36
|
-
const affiliatePortData = utils.removeUndefined(
|
|
37
|
-
data,
|
|
38
|
-
) as AffiliatePortData;
|
|
39
|
-
|
|
40
|
-
const requestOptions: PlatformRequestOptions = {
|
|
41
|
-
method: 'GET',
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const baseUrl = 'https://tracking.affiliateclub.cz/aff_lsr';
|
|
45
|
-
|
|
46
|
-
for (const product of affiliatePortData.products) {
|
|
47
|
-
// https://tracking.affiliateclub.cz/aff_lsr?offer_id=OFFER_ID&adv_sub=TID_SUB_ID&amount=AMOUNT&transaction_id=TRANSACTION_ID&adv_sub2=CATEGORY&adv_sub3=MASTER_TYPE
|
|
48
|
-
const query = `?offer_id=${encodeURIComponent(
|
|
49
|
-
config.offerId,
|
|
50
|
-
)}&adv_sub=TID_${affiliatePortData.orderId}&amount=${
|
|
51
|
-
product.quantity * product.price
|
|
52
|
-
}&transaction_id=${affiliatePortData.transactionID}&adv_sub2=${
|
|
53
|
-
product.category
|
|
54
|
-
}&adv_sub3=${product.masterType}`;
|
|
55
|
-
|
|
56
|
-
await utils.handlePlatformRequest({
|
|
57
|
-
source: this.source,
|
|
58
|
-
baseUrl,
|
|
59
|
-
query,
|
|
60
|
-
requestOptions,
|
|
61
|
-
event,
|
|
62
|
-
logger: log,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
} else {
|
|
66
|
-
throw new Error('Invalid config for platform ' + this.source);
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
};
|
package/src/publishers/cj.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import * as utils from './../utils/utils';
|
|
2
|
-
import {
|
|
3
|
-
PlatformPublisher,
|
|
4
|
-
PlatformRequestOptions,
|
|
5
|
-
} from '../types/PlatformPublisher';
|
|
6
|
-
import { TypeSafeObject } from '../types/UtilTypes';
|
|
7
|
-
|
|
8
|
-
interface CjData {
|
|
9
|
-
cjevent?: unknown;
|
|
10
|
-
[x: string]: unknown;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const cj: PlatformPublisher = {
|
|
14
|
-
source: 'CJAffiliate',
|
|
15
|
-
/**
|
|
16
|
-
* Publishes data to CJ
|
|
17
|
-
* @param log Azure Function context.log
|
|
18
|
-
* @param config Publisher configuration
|
|
19
|
-
* @param data Data in publisher-friendly format to be published
|
|
20
|
-
* @param event Event for which the function is triggered
|
|
21
|
-
*/
|
|
22
|
-
async publish(log, config, data, event) {
|
|
23
|
-
if (!(data as CjData).cjevent) {
|
|
24
|
-
utils.logMessage(
|
|
25
|
-
1,
|
|
26
|
-
`CJ - ${event.event} - skipped because CJEVENT is missing`,
|
|
27
|
-
);
|
|
28
|
-
// ? Tady se returnoval false, ale nemyslim, ze to neco pouzivalo
|
|
29
|
-
} else {
|
|
30
|
-
if (typeof config.cid === 'string' && typeof config.type === 'string') {
|
|
31
|
-
const cjData = utils.removeUndefined(data) as TypeSafeObject;
|
|
32
|
-
let query = '?cid=' + encodeURI(config.cid);
|
|
33
|
-
query += '&type=' + encodeURI(config.type);
|
|
34
|
-
for (const property in data) {
|
|
35
|
-
if (
|
|
36
|
-
Object.prototype.hasOwnProperty.call(cjData, property) &&
|
|
37
|
-
cjData[property] !== undefined
|
|
38
|
-
) {
|
|
39
|
-
query +=
|
|
40
|
-
'&' +
|
|
41
|
-
encodeURI(property) +
|
|
42
|
-
'=' +
|
|
43
|
-
encodeURI(
|
|
44
|
-
cjData[property] === null
|
|
45
|
-
? ''
|
|
46
|
-
: // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
|
|
47
|
-
(cjData[property]?.toString() as string),
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
const baseUrl = 'https://www.kdukvh.com/u';
|
|
52
|
-
|
|
53
|
-
const requestOptions: PlatformRequestOptions = {
|
|
54
|
-
method: 'GET',
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
await utils.handlePlatformRequest({
|
|
58
|
-
source: this.source,
|
|
59
|
-
baseUrl,
|
|
60
|
-
query,
|
|
61
|
-
requestOptions,
|
|
62
|
-
event,
|
|
63
|
-
logger: log,
|
|
64
|
-
});
|
|
65
|
-
} else {
|
|
66
|
-
throw new Error('Invalid config for platform ' + this.source);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import * as utils from './../utils/utils';
|
|
2
|
-
import {
|
|
3
|
-
PlatformPublisher,
|
|
4
|
-
PlatformRequestOptions,
|
|
5
|
-
} from '../types/PlatformPublisher';
|
|
6
|
-
|
|
7
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
8
|
-
interface FacebookData {
|
|
9
|
-
event_name: string;
|
|
10
|
-
event_time: number;
|
|
11
|
-
action_source: string;
|
|
12
|
-
event_id: string;
|
|
13
|
-
event_source_url: string;
|
|
14
|
-
opt_out: boolean;
|
|
15
|
-
user_data: {
|
|
16
|
-
client_user_agent: string;
|
|
17
|
-
fbc: string;
|
|
18
|
-
fbp: string;
|
|
19
|
-
client_ip_address: string;
|
|
20
|
-
};
|
|
21
|
-
custom_data: {
|
|
22
|
-
currency: string;
|
|
23
|
-
value: number;
|
|
24
|
-
contents: {
|
|
25
|
-
id: string;
|
|
26
|
-
quantity: number;
|
|
27
|
-
item_price: number;
|
|
28
|
-
}[];
|
|
29
|
-
content_type: string;
|
|
30
|
-
order_id: string;
|
|
31
|
-
content_category: string;
|
|
32
|
-
};
|
|
33
|
-
[x: string]: unknown;
|
|
34
|
-
}
|
|
35
|
-
/* eslint-enable @typescript-eslint/naming-convention */
|
|
36
|
-
|
|
37
|
-
export const facebook: PlatformPublisher = {
|
|
38
|
-
source: 'Facebook',
|
|
39
|
-
/**
|
|
40
|
-
*Publishes data to Facebook
|
|
41
|
-
* @param log Azure Function context.log
|
|
42
|
-
* @param config Publisher configuration
|
|
43
|
-
* @param data Data in publisher-friendly format to be published
|
|
44
|
-
* @param event Event for which the function is triggered
|
|
45
|
-
*/
|
|
46
|
-
async publish(log, config, data, event) {
|
|
47
|
-
if (
|
|
48
|
-
typeof config.id === 'string' &&
|
|
49
|
-
typeof config.access_token === 'string'
|
|
50
|
-
) {
|
|
51
|
-
if (
|
|
52
|
-
!(
|
|
53
|
-
(data as FacebookData).user_data.fbp ||
|
|
54
|
-
(data as FacebookData).user_data.fbc ||
|
|
55
|
-
((data as FacebookData).user_data.client_user_agent &&
|
|
56
|
-
(data as FacebookData).user_data.client_ip_address)
|
|
57
|
-
)
|
|
58
|
-
) {
|
|
59
|
-
utils.logMessage(
|
|
60
|
-
1,
|
|
61
|
-
`Facebook: excluded ${event.event} due to a lack of user identifiers`,
|
|
62
|
-
);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const requestOptions: PlatformRequestOptions = {
|
|
66
|
-
method: 'POST',
|
|
67
|
-
body: JSON.stringify({ data: [utils.removeUndefined(data)] }),
|
|
68
|
-
headers: {
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
70
|
-
'Content-Type': 'application/json',
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// https://graph.facebook.com/v11.0/<id>/events
|
|
75
|
-
const baseUrl = `https://graph.facebook.com/v11.0/${encodeURIComponent(
|
|
76
|
-
config.id,
|
|
77
|
-
)}/events`;
|
|
78
|
-
|
|
79
|
-
const query = `?access_token=${encodeURI(config.access_token)}`;
|
|
80
|
-
|
|
81
|
-
await utils.handlePlatformRequest({
|
|
82
|
-
source: this.source,
|
|
83
|
-
baseUrl,
|
|
84
|
-
query,
|
|
85
|
-
requestOptions,
|
|
86
|
-
event,
|
|
87
|
-
logger: log,
|
|
88
|
-
});
|
|
89
|
-
} else {
|
|
90
|
-
throw new Error('Invalid config for platform ' + this.source);
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
};
|