@memberjunction/integration-engine 0.0.1 → 5.9.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/README.md +142 -28
- package/dist/BaseIntegrationConnector.d.ts +177 -0
- package/dist/BaseIntegrationConnector.d.ts.map +1 -0
- package/dist/BaseIntegrationConnector.js +110 -0
- package/dist/BaseIntegrationConnector.js.map +1 -0
- package/dist/BaseRESTIntegrationConnector.d.ts +222 -0
- package/dist/BaseRESTIntegrationConnector.d.ts.map +1 -0
- package/dist/BaseRESTIntegrationConnector.js +482 -0
- package/dist/BaseRESTIntegrationConnector.js.map +1 -0
- package/dist/ConnectorFactory.d.ts +28 -0
- package/dist/ConnectorFactory.d.ts.map +1 -0
- package/dist/ConnectorFactory.js +42 -0
- package/dist/ConnectorFactory.js.map +1 -0
- package/dist/FieldMappingEngine.d.ts +94 -0
- package/dist/FieldMappingEngine.d.ts.map +1 -0
- package/dist/FieldMappingEngine.js +250 -0
- package/dist/FieldMappingEngine.js.map +1 -0
- package/dist/IntegrationEngine.d.ts +173 -0
- package/dist/IntegrationEngine.d.ts.map +1 -0
- package/dist/IntegrationEngine.js +677 -0
- package/dist/IntegrationEngine.js.map +1 -0
- package/dist/MatchEngine.d.ts +51 -0
- package/dist/MatchEngine.d.ts.map +1 -0
- package/dist/MatchEngine.js +129 -0
- package/dist/MatchEngine.js.map +1 -0
- package/dist/RetryRunner.d.ts +27 -0
- package/dist/RetryRunner.d.ts.map +1 -0
- package/dist/RetryRunner.js +59 -0
- package/dist/RetryRunner.js.map +1 -0
- package/dist/WatermarkService.d.ts +44 -0
- package/dist/WatermarkService.d.ts.map +1 -0
- package/dist/WatermarkService.js +97 -0
- package/dist/WatermarkService.js.map +1 -0
- package/dist/entity-types.d.ts +90 -0
- package/dist/entity-types.d.ts.map +1 -0
- package/dist/entity-types.js +13 -0
- package/dist/entity-types.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/transforms.d.ts +75 -0
- package/dist/transforms.d.ts.map +1 -0
- package/dist/transforms.js +2 -0
- package/dist/transforms.js.map +1 -0
- package/dist/types.d.ts +196 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +44 -0
- package/dist/types.js.map +1 -0
- package/package.json +30 -7
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
import { RunView } from '@memberjunction/core';
|
|
2
|
+
import { UUIDsEqual } from '@memberjunction/global';
|
|
3
|
+
import { IntegrationEngineBase } from '@memberjunction/integration-engine-base';
|
|
4
|
+
import { BaseIntegrationConnector, } from './BaseIntegrationConnector.js';
|
|
5
|
+
/** Maximum number of pages to fetch before stopping (safety limit to prevent infinite loops) */
|
|
6
|
+
const MAX_PAGINATION_PAGES = 200;
|
|
7
|
+
// ─── BaseRESTIntegrationConnector ────────────────────────────────────
|
|
8
|
+
/**
|
|
9
|
+
* Abstract base class for REST API integration connectors.
|
|
10
|
+
*
|
|
11
|
+
* Implements the generic REST sync pattern: reads IntegrationObject/Field
|
|
12
|
+
* metadata from the MJ database, handles pagination, template variable
|
|
13
|
+
* resolution (per-parent iteration), and converts raw API responses to
|
|
14
|
+
* ExternalRecord format.
|
|
15
|
+
*
|
|
16
|
+
* Concrete connectors (YourMembership, Salesforce, HubSpot, etc.) extend
|
|
17
|
+
* this class and implement only auth, HTTP transport, and response normalization.
|
|
18
|
+
*/
|
|
19
|
+
export class BaseRESTIntegrationConnector extends BaseIntegrationConnector {
|
|
20
|
+
// ── BaseIntegrationConnector implementations ─────────────────────
|
|
21
|
+
/**
|
|
22
|
+
* Discovers available objects from the IntegrationEngineBase cache.
|
|
23
|
+
*/
|
|
24
|
+
async DiscoverObjects(companyIntegration, _contextUser) {
|
|
25
|
+
const objects = IntegrationEngineBase.Instance.GetActiveIntegrationObjects(companyIntegration.IntegrationID);
|
|
26
|
+
return objects.map(obj => ({
|
|
27
|
+
Name: obj.Name,
|
|
28
|
+
Label: obj.DisplayName ?? obj.Name,
|
|
29
|
+
Description: obj.Description ?? undefined,
|
|
30
|
+
SupportsIncrementalSync: obj.SupportsIncrementalSync,
|
|
31
|
+
SupportsWrite: obj.SupportsWrite,
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Discovers fields for a specific object from the IntegrationEngineBase cache.
|
|
36
|
+
*/
|
|
37
|
+
async DiscoverFields(companyIntegration, objectName, _contextUser) {
|
|
38
|
+
const obj = this.GetCachedObject(companyIntegration.IntegrationID, objectName);
|
|
39
|
+
const fields = this.GetCachedFields(obj.ID);
|
|
40
|
+
return fields.map(f => this.FieldEntityToSchema(f));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Builds SourceSchemaInfo from IntegrationEngineBase cached metadata.
|
|
44
|
+
* Provides richer metadata than the base class implementation, including
|
|
45
|
+
* FK relationships derived from RelatedIntegrationObjectID.
|
|
46
|
+
*/
|
|
47
|
+
async IntrospectSchema(companyIntegration, _contextUser) {
|
|
48
|
+
const integrationID = companyIntegration.IntegrationID;
|
|
49
|
+
const objects = IntegrationEngineBase.Instance.GetActiveIntegrationObjects(integrationID);
|
|
50
|
+
const result = { Objects: [] };
|
|
51
|
+
for (const obj of objects) {
|
|
52
|
+
const fields = this.GetCachedFields(obj.ID);
|
|
53
|
+
const sourceObject = this.BuildSourceObjectInfo(obj, fields, objects);
|
|
54
|
+
result.Objects.push(sourceObject);
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Fetches records from the external REST API using metadata-driven configuration.
|
|
60
|
+
* Handles both flat endpoints and template-variable (per-parent) endpoints.
|
|
61
|
+
*/
|
|
62
|
+
async FetchChanges(ctx) {
|
|
63
|
+
const obj = this.GetCachedObject(ctx.CompanyIntegration.IntegrationID, ctx.ObjectName);
|
|
64
|
+
const fields = this.GetCachedFields(obj.ID);
|
|
65
|
+
const auth = await this.Authenticate(ctx.CompanyIntegration);
|
|
66
|
+
const baseURL = this.GetBaseURL(ctx.CompanyIntegration);
|
|
67
|
+
const templateVars = this.DetectTemplateVars(obj.APIPath);
|
|
68
|
+
if (templateVars.length > 0) {
|
|
69
|
+
return this.FetchWithTemplateVars(auth, baseURL, obj, fields, templateVars, ctx);
|
|
70
|
+
}
|
|
71
|
+
return this.FetchFlat(auth, baseURL, obj, fields, ctx);
|
|
72
|
+
}
|
|
73
|
+
// ── Flat fetch (no template variables) ───────────────────────────
|
|
74
|
+
/**
|
|
75
|
+
* Fetches records from a flat endpoint (no template variable substitution).
|
|
76
|
+
*/
|
|
77
|
+
async FetchFlat(auth, baseURL, obj, fields, ctx) {
|
|
78
|
+
const fullPath = this.BuildFullURL(baseURL, obj.APIPath);
|
|
79
|
+
const result = await this.FetchWithPagination(auth, fullPath, obj, ctx.BatchSize);
|
|
80
|
+
const pkFieldName = this.FindPrimaryKeyFieldName(fields);
|
|
81
|
+
return {
|
|
82
|
+
Records: result.Records.map(r => this.ToExternalRecord(r, ctx.ObjectName, pkFieldName)),
|
|
83
|
+
HasMore: result.HasMore,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
// ── Per-parent fetch (template variables) ────────────────────────
|
|
87
|
+
/**
|
|
88
|
+
* Fetches records from a template-variable endpoint by iterating over parent records.
|
|
89
|
+
* Identifies the parent object from FK field metadata, loads parent IDs from the
|
|
90
|
+
* local database, then fetches child records per parent.
|
|
91
|
+
*/
|
|
92
|
+
async FetchWithTemplateVars(auth, baseURL, obj, fields, templateVars, ctx) {
|
|
93
|
+
const parentInfo = this.ResolveParentInfo(fields, templateVars, ctx.CompanyIntegration.IntegrationID);
|
|
94
|
+
if (!parentInfo) {
|
|
95
|
+
console.warn(`[BaseRESTIntegrationConnector] Skipping "${obj.Name}": template variables ` +
|
|
96
|
+
`[${templateVars.join(', ')}] could not be resolved to a parent object.`);
|
|
97
|
+
return { Records: [], HasMore: false };
|
|
98
|
+
}
|
|
99
|
+
const parentIDs = await this.LoadParentIDs(parentInfo.parentObjectID, ctx.ContextUser);
|
|
100
|
+
const pkFieldName = this.FindPrimaryKeyFieldName(fields);
|
|
101
|
+
const allRecords = [];
|
|
102
|
+
for (const parentID of parentIDs) {
|
|
103
|
+
const resolvedPath = this.SubstituteTemplateVars(obj.APIPath, parentInfo.templateVar, parentID);
|
|
104
|
+
const fullURL = this.BuildFullURL(baseURL, resolvedPath);
|
|
105
|
+
const result = await this.FetchWithPagination(auth, fullURL, obj, ctx.BatchSize - allRecords.length);
|
|
106
|
+
const tagged = result.Records.map(r => {
|
|
107
|
+
r[parentInfo.fkFieldName] = parentID;
|
|
108
|
+
return this.ToExternalRecord(r, ctx.ObjectName, pkFieldName);
|
|
109
|
+
});
|
|
110
|
+
allRecords.push(...tagged);
|
|
111
|
+
if (allRecords.length >= ctx.BatchSize)
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
return { Records: allRecords, HasMore: false };
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Resolves which template variable maps to which FK field + parent object.
|
|
118
|
+
*
|
|
119
|
+
* Resolution strategy (in order):
|
|
120
|
+
* 1. Explicit: FK field with RelatedIntegrationObjectID that matches a template var name
|
|
121
|
+
* 2. PK fallback: finds a sibling integration object whose primary key field name
|
|
122
|
+
* matches the template var, allowing resolution without explicit FK metadata
|
|
123
|
+
*
|
|
124
|
+
* Returns null if no match is found by either strategy.
|
|
125
|
+
*/
|
|
126
|
+
ResolveParentInfo(fields, templateVars, integrationID) {
|
|
127
|
+
// Strategy 1: Explicit FK field with RelatedIntegrationObjectID
|
|
128
|
+
for (const field of fields) {
|
|
129
|
+
if (!field.RelatedIntegrationObjectID)
|
|
130
|
+
continue;
|
|
131
|
+
for (const tVar of templateVars) {
|
|
132
|
+
if (field.Name.toLowerCase().includes(tVar.toLowerCase())) {
|
|
133
|
+
return {
|
|
134
|
+
templateVar: tVar,
|
|
135
|
+
fkFieldName: field.Name,
|
|
136
|
+
parentObjectID: field.RelatedIntegrationObjectID,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// Strategy 2: Match template var against PK fields of sibling objects
|
|
142
|
+
return this.ResolveParentByPKMatch(templateVars, integrationID);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Fallback resolution: finds a sibling integration object whose primary key
|
|
146
|
+
* field name matches one of the template variables (case-insensitive).
|
|
147
|
+
* E.g., {ProfileID} matches Members object which has PK field "ProfileID".
|
|
148
|
+
*/
|
|
149
|
+
ResolveParentByPKMatch(templateVars, integrationID) {
|
|
150
|
+
const siblingObjects = IntegrationEngineBase.Instance.GetActiveIntegrationObjects(integrationID);
|
|
151
|
+
for (const tVar of templateVars) {
|
|
152
|
+
const tVarLower = tVar.toLowerCase();
|
|
153
|
+
for (const sibling of siblingObjects) {
|
|
154
|
+
const siblingFields = IntegrationEngineBase.Instance.GetIntegrationObjectFields(sibling.ID);
|
|
155
|
+
const pkField = siblingFields.find(f => f.IsPrimaryKey);
|
|
156
|
+
if (!pkField)
|
|
157
|
+
continue;
|
|
158
|
+
if (pkField.Name.toLowerCase() === tVarLower) {
|
|
159
|
+
return {
|
|
160
|
+
templateVar: tVar,
|
|
161
|
+
fkFieldName: tVar, // Use the template var name as the FK field name
|
|
162
|
+
parentObjectID: sibling.ID,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Loads parent record IDs from the local MJ database.
|
|
171
|
+
* Uses IntegrationEngineBase cache for object/field metadata lookups,
|
|
172
|
+
* then queries the MJ entity via RunView for actual synced record IDs.
|
|
173
|
+
*/
|
|
174
|
+
async LoadParentIDs(parentObjectID, contextUser) {
|
|
175
|
+
// Use engine cache for metadata lookups
|
|
176
|
+
const parentObj = IntegrationEngineBase.Instance.GetIntegrationObjectByID(parentObjectID);
|
|
177
|
+
if (!parentObj) {
|
|
178
|
+
throw new Error(`Parent IntegrationObject not found: ${parentObjectID}`);
|
|
179
|
+
}
|
|
180
|
+
const parentFields = this.GetCachedFields(parentObj.ID);
|
|
181
|
+
const pkField = parentFields.find(f => f.IsPrimaryKey);
|
|
182
|
+
const pkFieldName = pkField ? pkField.Name : 'ID';
|
|
183
|
+
// Query the parent object's corresponding MJ entity for synced records
|
|
184
|
+
const rv = new RunView();
|
|
185
|
+
const entityMapResult = await rv.RunView({
|
|
186
|
+
EntityName: 'MJ: Company Integration Entity Maps',
|
|
187
|
+
ExtraFilter: `ExternalObjectName='${parentObj.Name}' AND SyncEnabled=1`,
|
|
188
|
+
Fields: ['EntityID', 'Entity'],
|
|
189
|
+
MaxRows: 1,
|
|
190
|
+
ResultType: 'simple',
|
|
191
|
+
}, contextUser);
|
|
192
|
+
if (!entityMapResult.Success || entityMapResult.Results.length === 0) {
|
|
193
|
+
return [];
|
|
194
|
+
}
|
|
195
|
+
const entityName = entityMapResult.Results[0].Entity;
|
|
196
|
+
const idResult = await rv.RunView({
|
|
197
|
+
EntityName: entityName,
|
|
198
|
+
Fields: [pkFieldName],
|
|
199
|
+
ResultType: 'simple',
|
|
200
|
+
}, contextUser);
|
|
201
|
+
if (!idResult.Success)
|
|
202
|
+
return [];
|
|
203
|
+
return idResult.Results.map(r => String(r[pkFieldName]));
|
|
204
|
+
}
|
|
205
|
+
// ── Pagination loop ──────────────────────────────────────────────
|
|
206
|
+
/**
|
|
207
|
+
* Fetches records from a single URL with pagination support.
|
|
208
|
+
* Loops through pages until no more data or maxRecords is reached.
|
|
209
|
+
*/
|
|
210
|
+
async FetchWithPagination(auth, basePath, obj, maxRecords) {
|
|
211
|
+
if (!obj.SupportsPagination || obj.PaginationType === 'None') {
|
|
212
|
+
return this.FetchSinglePage(auth, basePath, obj);
|
|
213
|
+
}
|
|
214
|
+
return this.FetchPaginatedLoop(auth, basePath, obj, maxRecords);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Fetches a single non-paginated page.
|
|
218
|
+
*/
|
|
219
|
+
async FetchSinglePage(auth, url, obj) {
|
|
220
|
+
const requestURL = this.AppendDefaultQueryParams(url, obj);
|
|
221
|
+
const headers = this.BuildHeaders(auth);
|
|
222
|
+
const response = await this.MakeHTTPRequest(auth, requestURL, 'GET', headers);
|
|
223
|
+
this.ValidateHTTPResponse(response, requestURL);
|
|
224
|
+
const records = this.NormalizeResponse(response.Body, obj.ResponseDataKey);
|
|
225
|
+
return { Records: records, HasMore: false };
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Iterates through paginated responses until exhausted or maxRecords is reached.
|
|
229
|
+
*/
|
|
230
|
+
async FetchPaginatedLoop(auth, basePath, obj, maxRecords) {
|
|
231
|
+
const allRecords = [];
|
|
232
|
+
let page = 1;
|
|
233
|
+
let offset = 0;
|
|
234
|
+
let cursor;
|
|
235
|
+
let hasMore = true;
|
|
236
|
+
let pageCount = 0;
|
|
237
|
+
let previousFirstRecordKey;
|
|
238
|
+
while (hasMore && allRecords.length < maxRecords && pageCount < MAX_PAGINATION_PAGES) {
|
|
239
|
+
pageCount++;
|
|
240
|
+
const url = this.BuildPaginatedURL(basePath, obj, page, offset, cursor);
|
|
241
|
+
const requestURL = this.AppendDefaultQueryParams(url, obj);
|
|
242
|
+
const headers = this.BuildHeaders(auth);
|
|
243
|
+
const response = await this.MakeHTTPRequest(auth, requestURL, 'GET', headers);
|
|
244
|
+
this.ValidateHTTPResponse(response, requestURL);
|
|
245
|
+
const records = this.NormalizeResponse(response.Body, obj.ResponseDataKey);
|
|
246
|
+
if (records.length === 0) {
|
|
247
|
+
hasMore = false;
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
// Detect duplicate pages: if the first record matches the previous page's first record,
|
|
251
|
+
// the API's pagination is broken (returning the same data repeatedly)
|
|
252
|
+
const currentFirstRecordKey = JSON.stringify(records[0]);
|
|
253
|
+
if (previousFirstRecordKey !== undefined && currentFirstRecordKey === previousFirstRecordKey) {
|
|
254
|
+
console.warn(`[BaseRESTIntegrationConnector] Duplicate page detected for "${obj.Name}" ` +
|
|
255
|
+
`on page ${pageCount}. API pagination appears broken. Stopping.`);
|
|
256
|
+
hasMore = false;
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
previousFirstRecordKey = currentFirstRecordKey;
|
|
260
|
+
allRecords.push(...records);
|
|
261
|
+
const paginationState = this.ExtractPaginationInfo(response.Body, obj.PaginationType, page, offset, obj.DefaultPageSize);
|
|
262
|
+
hasMore = paginationState.HasMore;
|
|
263
|
+
page = paginationState.NextPage ?? page + 1;
|
|
264
|
+
offset = paginationState.NextOffset ?? offset + records.length;
|
|
265
|
+
cursor = paginationState.NextCursor;
|
|
266
|
+
}
|
|
267
|
+
if (pageCount >= MAX_PAGINATION_PAGES) {
|
|
268
|
+
console.warn(`[BaseRESTIntegrationConnector] Pagination safety limit (${MAX_PAGINATION_PAGES} pages) ` +
|
|
269
|
+
`reached for "${obj.Name}". ${allRecords.length} records fetched so far.`);
|
|
270
|
+
hasMore = false; // prevent the engine's outer loop from restarting pagination
|
|
271
|
+
}
|
|
272
|
+
return { Records: allRecords, HasMore: hasMore };
|
|
273
|
+
}
|
|
274
|
+
// ── URL building helpers ─────────────────────────────────────────
|
|
275
|
+
/**
|
|
276
|
+
* Combines baseURL and apiPath into a full URL.
|
|
277
|
+
*/
|
|
278
|
+
BuildFullURL(baseURL, apiPath) {
|
|
279
|
+
const base = baseURL.endsWith('/') ? baseURL.slice(0, -1) : baseURL;
|
|
280
|
+
const path = apiPath.startsWith('/') ? apiPath : `/${apiPath}`;
|
|
281
|
+
return `${base}${path}`;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Appends pagination parameters to a URL based on the object's PaginationType.
|
|
285
|
+
* Override in subclasses to use vendor-specific parameter names.
|
|
286
|
+
*/
|
|
287
|
+
BuildPaginatedURL(basePath, obj, page, offset, cursor) {
|
|
288
|
+
const separator = basePath.includes('?') ? '&' : '?';
|
|
289
|
+
switch (obj.PaginationType) {
|
|
290
|
+
case 'PageNumber':
|
|
291
|
+
return `${basePath}${separator}page=${page}&pageSize=${obj.DefaultPageSize}`;
|
|
292
|
+
case 'Offset':
|
|
293
|
+
return `${basePath}${separator}offset=${offset}&limit=${obj.DefaultPageSize}`;
|
|
294
|
+
case 'Cursor':
|
|
295
|
+
return cursor
|
|
296
|
+
? `${basePath}${separator}cursor=${encodeURIComponent(cursor)}&limit=${obj.DefaultPageSize}`
|
|
297
|
+
: `${basePath}${separator}limit=${obj.DefaultPageSize}`;
|
|
298
|
+
default:
|
|
299
|
+
return basePath;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Appends default query parameters from the IntegrationObject metadata.
|
|
304
|
+
* DefaultQueryParams is stored as a JSON object like {"key": "value"}.
|
|
305
|
+
* Automatically skips params whose key (case-insensitive) already appears
|
|
306
|
+
* in the URL to avoid duplicates with pagination params.
|
|
307
|
+
*/
|
|
308
|
+
AppendDefaultQueryParams(url, obj) {
|
|
309
|
+
if (!obj.DefaultQueryParams)
|
|
310
|
+
return url;
|
|
311
|
+
try {
|
|
312
|
+
const params = JSON.parse(obj.DefaultQueryParams);
|
|
313
|
+
const entries = Object.entries(params);
|
|
314
|
+
if (entries.length === 0)
|
|
315
|
+
return url;
|
|
316
|
+
// Extract existing param keys from the URL (case-insensitive) to avoid duplicates
|
|
317
|
+
const existingKeys = this.ExtractURLParamKeys(url);
|
|
318
|
+
// Filter out any default params whose key already exists in the URL
|
|
319
|
+
const filtered = entries.filter(([k]) => !existingKeys.has(k.toLowerCase()));
|
|
320
|
+
if (filtered.length === 0)
|
|
321
|
+
return url;
|
|
322
|
+
const separator = url.includes('?') ? '&' : '?';
|
|
323
|
+
const queryString = filtered
|
|
324
|
+
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
|
|
325
|
+
.join('&');
|
|
326
|
+
return `${url}${separator}${queryString}`;
|
|
327
|
+
}
|
|
328
|
+
catch {
|
|
329
|
+
console.warn(`[BaseRESTIntegrationConnector] Invalid DefaultQueryParams JSON for object "${obj.Name}"`);
|
|
330
|
+
return url;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Extracts query parameter keys from a URL, returned as a Set of lowercase strings.
|
|
335
|
+
* Used to detect duplicates between pagination params and DefaultQueryParams.
|
|
336
|
+
*/
|
|
337
|
+
ExtractURLParamKeys(url) {
|
|
338
|
+
const keys = new Set();
|
|
339
|
+
const qIndex = url.indexOf('?');
|
|
340
|
+
if (qIndex < 0)
|
|
341
|
+
return keys;
|
|
342
|
+
const queryString = url.substring(qIndex + 1);
|
|
343
|
+
for (const pair of queryString.split('&')) {
|
|
344
|
+
const eqIndex = pair.indexOf('=');
|
|
345
|
+
const key = eqIndex >= 0 ? pair.substring(0, eqIndex) : pair;
|
|
346
|
+
keys.add(decodeURIComponent(key).toLowerCase());
|
|
347
|
+
}
|
|
348
|
+
return keys;
|
|
349
|
+
}
|
|
350
|
+
// ── Template variable helpers ────────────────────────────────────
|
|
351
|
+
/**
|
|
352
|
+
* Detects template variables in an API path. Template variables use
|
|
353
|
+
* the format {VariableName} (e.g., "/profiles/{ProfileID}/events").
|
|
354
|
+
*/
|
|
355
|
+
DetectTemplateVars(apiPath) {
|
|
356
|
+
const matches = apiPath.match(/\{(\w+)\}/g);
|
|
357
|
+
return matches ? matches.map(m => m.slice(1, -1)) : [];
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Substitutes a single template variable in a path.
|
|
361
|
+
*/
|
|
362
|
+
SubstituteTemplateVars(apiPath, varName, value) {
|
|
363
|
+
return apiPath.replace(`{${varName}}`, encodeURIComponent(value));
|
|
364
|
+
}
|
|
365
|
+
// ── Cached metadata accessors ───────────────────────────────────
|
|
366
|
+
/**
|
|
367
|
+
* Gets an IntegrationObject from the engine's cache by integration ID and object name.
|
|
368
|
+
* Throws if not found.
|
|
369
|
+
*/
|
|
370
|
+
GetCachedObject(integrationID, objectName) {
|
|
371
|
+
const obj = IntegrationEngineBase.Instance.GetIntegrationObject(integrationID, objectName);
|
|
372
|
+
if (!obj) {
|
|
373
|
+
throw new Error(`IntegrationObject not found: "${objectName}" for integration ${integrationID}`);
|
|
374
|
+
}
|
|
375
|
+
return obj;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Gets IntegrationObjectField records from the engine's cache for a given object ID.
|
|
379
|
+
* Returns only active fields sorted by Sequence.
|
|
380
|
+
*/
|
|
381
|
+
GetCachedFields(objectID) {
|
|
382
|
+
return IntegrationEngineBase.Instance.GetIntegrationObjectFields(objectID)
|
|
383
|
+
.filter(f => f.Status === 'Active')
|
|
384
|
+
.sort((a, b) => a.Sequence - b.Sequence);
|
|
385
|
+
}
|
|
386
|
+
// ── Conversion helpers ───────────────────────────────────────────
|
|
387
|
+
/**
|
|
388
|
+
* Converts a raw API record object to the ExternalRecord format.
|
|
389
|
+
*/
|
|
390
|
+
ToExternalRecord(raw, objectType, pkFieldName) {
|
|
391
|
+
const externalID = raw[pkFieldName] != null ? String(raw[pkFieldName]) : '';
|
|
392
|
+
return {
|
|
393
|
+
ExternalID: externalID,
|
|
394
|
+
ObjectType: objectType,
|
|
395
|
+
Fields: raw,
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Finds the primary key field name from a set of IntegrationObjectField records.
|
|
400
|
+
* Falls back to "ID" if no PK field is explicitly marked.
|
|
401
|
+
*/
|
|
402
|
+
FindPrimaryKeyFieldName(fields) {
|
|
403
|
+
const pkField = fields.find(f => f.IsPrimaryKey);
|
|
404
|
+
return pkField ? pkField.Name : 'ID';
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Converts an IntegrationObjectFieldEntity to the ExternalFieldSchema format.
|
|
408
|
+
*/
|
|
409
|
+
FieldEntityToSchema(f) {
|
|
410
|
+
return {
|
|
411
|
+
Name: f.Name,
|
|
412
|
+
Label: f.DisplayName ?? f.Name,
|
|
413
|
+
Description: f.Description ?? undefined,
|
|
414
|
+
DataType: f.Type,
|
|
415
|
+
IsRequired: f.IsRequired,
|
|
416
|
+
IsUniqueKey: f.IsUniqueKey,
|
|
417
|
+
IsReadOnly: f.IsReadOnly,
|
|
418
|
+
IsForeignKey: f.RelatedIntegrationObjectID != null,
|
|
419
|
+
ForeignKeyTarget: f.RelatedIntegrationObject ?? null,
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Builds a SourceObjectInfo from an IntegrationObject and its fields.
|
|
424
|
+
* Resolves FK relationships using the RelatedIntegrationObjectID.
|
|
425
|
+
*/
|
|
426
|
+
BuildSourceObjectInfo(obj, fields, allObjects) {
|
|
427
|
+
const relationships = this.BuildRelationships(fields, allObjects);
|
|
428
|
+
return {
|
|
429
|
+
ExternalName: obj.Name,
|
|
430
|
+
ExternalLabel: obj.DisplayName ?? obj.Name,
|
|
431
|
+
Description: obj.Description ?? undefined,
|
|
432
|
+
Fields: fields.map(f => ({
|
|
433
|
+
Name: f.Name,
|
|
434
|
+
Label: f.DisplayName ?? f.Name,
|
|
435
|
+
Description: f.Description ?? undefined,
|
|
436
|
+
SourceType: f.Type,
|
|
437
|
+
IsRequired: f.IsRequired,
|
|
438
|
+
MaxLength: f.Length,
|
|
439
|
+
Precision: f.Precision,
|
|
440
|
+
Scale: f.Scale,
|
|
441
|
+
DefaultValue: f.DefaultValue,
|
|
442
|
+
IsPrimaryKey: f.IsPrimaryKey,
|
|
443
|
+
IsForeignKey: f.RelatedIntegrationObjectID != null,
|
|
444
|
+
ForeignKeyTarget: f.RelatedIntegrationObject ?? null,
|
|
445
|
+
})),
|
|
446
|
+
PrimaryKeyFields: fields.filter(f => f.IsPrimaryKey).map(f => f.Name),
|
|
447
|
+
Relationships: relationships,
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Builds SourceRelationshipInfo entries from FK fields.
|
|
452
|
+
*/
|
|
453
|
+
BuildRelationships(fields, allObjects) {
|
|
454
|
+
const relationships = [];
|
|
455
|
+
for (const field of fields) {
|
|
456
|
+
if (!field.RelatedIntegrationObjectID)
|
|
457
|
+
continue;
|
|
458
|
+
const targetObj = allObjects.find(o => UUIDsEqual(o.ID, field.RelatedIntegrationObjectID));
|
|
459
|
+
if (!targetObj)
|
|
460
|
+
continue;
|
|
461
|
+
relationships.push({
|
|
462
|
+
FieldName: field.Name,
|
|
463
|
+
TargetObject: targetObj.Name,
|
|
464
|
+
TargetField: field.RelatedIntegrationObjectFieldName ?? 'ID',
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
return relationships;
|
|
468
|
+
}
|
|
469
|
+
// ── Validation ───────────────────────────────────────────────────
|
|
470
|
+
/**
|
|
471
|
+
* Validates an HTTP response and throws a descriptive error on non-2xx status.
|
|
472
|
+
*/
|
|
473
|
+
ValidateHTTPResponse(response, url) {
|
|
474
|
+
if (response.Status < 200 || response.Status >= 300) {
|
|
475
|
+
const bodyPreview = typeof response.Body === 'string'
|
|
476
|
+
? response.Body.slice(0, 500)
|
|
477
|
+
: JSON.stringify(response.Body).slice(0, 500);
|
|
478
|
+
throw new Error(`HTTP ${response.Status} from ${url}: ${bodyPreview}`);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
//# sourceMappingURL=BaseRESTIntegrationConnector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseRESTIntegrationConnector.js","sourceRoot":"","sources":["../src/BaseRESTIntegrationConnector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAiB,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AAChF,OAAO,EACH,wBAAwB,GAM3B,MAAM,+BAA+B,CAAC;AAkDvC,gGAA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AAC,0BAA0B;gBAAE,SAAS;YAEhD,MAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,0BAA0B,CAAC,CAAC,CAAC;YAC3F,IAAI,CAAC,SAAS;gBAAE,SAAS;YAEzB,aAAa,CAAC,IAAI,CAAC;gBACf,SAAS,EAAE,KAAK,CAAC,IAAI;gBACrB,YAAY,EAAE,SAAS,CAAC,IAAI;gBAC5B,WAAW,EAAE,KAAK,CAAC,iCAAiC,IAAI,IAAI;aAC/D,CAAC,CAAC;QACP,CAAC;QAED,OAAO,aAAa,CAAC;IACzB,CAAC;IAED,oEAAoE;IAEpE;;OAEG;IACK,oBAAoB,CAAC,QAAsB,EAAE,GAAW;QAC5D,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;YAClD,MAAM,WAAW,GAAG,OAAO,QAAQ,CAAC,IAAI,KAAK,QAAQ;gBACjD,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC;gBAC7B,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YAClD,MAAM,IAAI,KAAK,CACX,QAAQ,QAAQ,CAAC,MAAM,SAAS,GAAG,KAAK,WAAW,EAAE,CACxD,CAAC;QACN,CAAC;IACL,CAAC;CAEJ"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { MJIntegrationEntity } from '@memberjunction/core-entities';
|
|
2
|
+
import { BaseIntegrationConnector } from './BaseIntegrationConnector.js';
|
|
3
|
+
/**
|
|
4
|
+
* Factory for resolving integration connectors using MJGlobal.ClassFactory.
|
|
5
|
+
* Connectors register themselves via `@RegisterClass(BaseIntegrationConnector, 'DriverClassName')`.
|
|
6
|
+
*
|
|
7
|
+
* Resolution uses the `ClassName` field on the Integration entity directly —
|
|
8
|
+
* IntegrationSourceType is a general category (SaaS API, Database, File Feed)
|
|
9
|
+
* and is NOT used for connector lookup.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ConnectorFactory {
|
|
12
|
+
/**
|
|
13
|
+
* Resolves and instantiates the appropriate connector for an integration.
|
|
14
|
+
* Uses `integration.ClassName` to look up the registered connector class
|
|
15
|
+
* in MJGlobal.ClassFactory.
|
|
16
|
+
*
|
|
17
|
+
* @param integration - The integration entity defining which external system to connect to
|
|
18
|
+
* @returns An instance of the appropriate BaseIntegrationConnector subclass
|
|
19
|
+
* @throws Error if ClassName is missing or no connector is registered for it
|
|
20
|
+
*/
|
|
21
|
+
static Resolve(integration: MJIntegrationEntity): BaseIntegrationConnector;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a connector instance via MJGlobal.ClassFactory.
|
|
24
|
+
* First verifies a registration exists to avoid falling back to the abstract base class.
|
|
25
|
+
*/
|
|
26
|
+
private static CreateConnectorInstance;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=ConnectorFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectorFactory.d.ts","sourceRoot":"","sources":["../src/ConnectorFactory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE;;;;;;;GAOG;AACH,qBAAa,gBAAgB;IACzB;;;;;;;;OAQG;WACW,OAAO,CACjB,WAAW,EAAE,mBAAmB,GACjC,wBAAwB;IAW3B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,uBAAuB;CAoBzC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { MJGlobal } from '@memberjunction/global';
|
|
2
|
+
import { BaseIntegrationConnector } from './BaseIntegrationConnector.js';
|
|
3
|
+
/**
|
|
4
|
+
* Factory for resolving integration connectors using MJGlobal.ClassFactory.
|
|
5
|
+
* Connectors register themselves via `@RegisterClass(BaseIntegrationConnector, 'DriverClassName')`.
|
|
6
|
+
*
|
|
7
|
+
* Resolution uses the `ClassName` field on the Integration entity directly —
|
|
8
|
+
* IntegrationSourceType is a general category (SaaS API, Database, File Feed)
|
|
9
|
+
* and is NOT used for connector lookup.
|
|
10
|
+
*/
|
|
11
|
+
export class ConnectorFactory {
|
|
12
|
+
/**
|
|
13
|
+
* Resolves and instantiates the appropriate connector for an integration.
|
|
14
|
+
* Uses `integration.ClassName` to look up the registered connector class
|
|
15
|
+
* in MJGlobal.ClassFactory.
|
|
16
|
+
*
|
|
17
|
+
* @param integration - The integration entity defining which external system to connect to
|
|
18
|
+
* @returns An instance of the appropriate BaseIntegrationConnector subclass
|
|
19
|
+
* @throws Error if ClassName is missing or no connector is registered for it
|
|
20
|
+
*/
|
|
21
|
+
static Resolve(integration) {
|
|
22
|
+
const className = integration.ClassName;
|
|
23
|
+
if (!className) {
|
|
24
|
+
throw new Error(`Integration "${integration.Name}" does not have a ClassName configured.`);
|
|
25
|
+
}
|
|
26
|
+
return ConnectorFactory.CreateConnectorInstance(className);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Creates a connector instance via MJGlobal.ClassFactory.
|
|
30
|
+
* First verifies a registration exists to avoid falling back to the abstract base class.
|
|
31
|
+
*/
|
|
32
|
+
static CreateConnectorInstance(driverClass) {
|
|
33
|
+
const registration = MJGlobal.Instance.ClassFactory.GetRegistration(BaseIntegrationConnector, driverClass);
|
|
34
|
+
if (!registration) {
|
|
35
|
+
throw new Error(`No connector registered for driver class "${driverClass}". ` +
|
|
36
|
+
`Ensure a class is decorated with @RegisterClass(BaseIntegrationConnector, '${driverClass}').`);
|
|
37
|
+
}
|
|
38
|
+
const instance = MJGlobal.Instance.ClassFactory.CreateInstance(BaseIntegrationConnector, driverClass);
|
|
39
|
+
return instance;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=ConnectorFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectorFactory.js","sourceRoot":"","sources":["../src/ConnectorFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE;;;;;;;GAOG;AACH,MAAM,OAAO,gBAAgB;IACzB;;;;;;;;OAQG;IACI,MAAM,CAAC,OAAO,CACjB,WAAgC;QAEhC,MAAM,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC;QACxC,IAAI,CAAC,SAAS,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CACX,gBAAgB,WAAW,CAAC,IAAI,yCAAyC,CAC5E,CAAC;QACN,CAAC;QAED,OAAO,gBAAgB,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;IAC/D,CAAC;IAED;;;OAGG;IACK,MAAM,CAAC,uBAAuB,CAAC,WAAmB;QACtD,MAAM,YAAY,GAAG,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,eAAe,CAC/D,wBAAwB,EACxB,WAAW,CACd,CAAC;QAEF,IAAI,CAAC,YAAY,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CACX,6CAA6C,WAAW,KAAK;gBAC7D,8EAA8E,WAAW,KAAK,CACjG,CAAC;QACN,CAAC;QAED,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,cAAc,CAC1D,wBAAwB,EACxB,WAAW,CACd,CAAC;QAEF,OAAO,QAAS,CAAC;IACrB,CAAC;CACJ"}
|