@memberjunction/ai-recommendations 2.4.0 → 2.5.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/dist/Engine.d.ts +9 -28
- package/dist/Engine.d.ts.map +1 -1
- package/dist/Engine.js +148 -56
- package/dist/Engine.js.map +1 -1
- package/dist/ProviderBase.d.ts +15 -2
- package/dist/ProviderBase.d.ts.map +1 -1
- package/dist/ProviderBase.js +32 -0
- package/dist/ProviderBase.js.map +1 -1
- package/dist/generic/types.d.ts +83 -0
- package/dist/generic/types.d.ts.map +1 -0
- package/dist/generic/types.js +58 -0
- package/dist/generic/types.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/Engine.d.ts
CHANGED
|
@@ -1,37 +1,18 @@
|
|
|
1
1
|
import { BaseEngine, UserInfo } from '@memberjunction/core';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
* Used to make requests to providers
|
|
5
|
-
*/
|
|
6
|
-
export declare class RecommendationRequest {
|
|
7
|
-
/**
|
|
8
|
-
* Array of the requested recommendations
|
|
9
|
-
*/
|
|
10
|
-
Recommendations: RecommendationEntity[];
|
|
11
|
-
/**
|
|
12
|
-
* The specific provider to use for the request. Leave this undefined if you want to use the default recommendation.
|
|
13
|
-
*/
|
|
14
|
-
Provider?: RecommendationProviderEntity;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* This response is generated for each Recommend() request
|
|
18
|
-
*/
|
|
19
|
-
export declare class RecommendationResult {
|
|
20
|
-
Success: boolean;
|
|
21
|
-
Request: RecommendationRequest;
|
|
22
|
-
ErrorMessage: string;
|
|
23
|
-
constructor(request: RecommendationRequest);
|
|
24
|
-
}
|
|
2
|
+
import { RecommendationProviderEntity } from '@memberjunction/core-entities';
|
|
3
|
+
import { RecommendationRequest, RecommendationResult } from './generic/types';
|
|
25
4
|
/**
|
|
26
5
|
* Engine class to be used for running all recommendation requests
|
|
27
6
|
*/
|
|
28
7
|
export declare class RecommendationEngineBase extends BaseEngine<RecommendationEngineBase> {
|
|
29
8
|
private _RecommendationProviders;
|
|
9
|
+
static get Instance(): RecommendationEngineBase;
|
|
10
|
+
get RecommendationProviders(): RecommendationProviderEntity[];
|
|
30
11
|
Config(forceRefresh?: boolean, contextUser?: UserInfo): Promise<void>;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
12
|
+
Recommend(request: RecommendationRequest): Promise<RecommendationResult>;
|
|
13
|
+
private GetRecommendationEntities;
|
|
14
|
+
private GetRecommendationsByListID;
|
|
15
|
+
private GetRecommendationsByRecordIDs;
|
|
16
|
+
private IsNullOrUndefined;
|
|
36
17
|
}
|
|
37
18
|
//# sourceMappingURL=Engine.d.ts.map
|
package/dist/Engine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Engine.d.ts","sourceRoot":"","sources":["../src/Engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAY,QAAQ,
|
|
1
|
+
{"version":3,"file":"Engine.d.ts","sourceRoot":"","sources":["../src/Engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAY,QAAQ,EAAkC,MAAM,sBAAsB,CAAC;AACtG,OAAO,EAA8D,4BAA4B,EAA2B,MAAM,+BAA+B,CAAC;AAGlK,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAE9E;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,UAAU,CAAC,wBAAwB,CAAC;IAChF,OAAO,CAAC,wBAAwB,CAAsC;IAEtE,WAAkB,QAAQ,IAAI,wBAAwB,CAErD;IAED,IAAW,uBAAuB,IAAI,4BAA4B,EAAE,CAEnE;IAEY,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,QAAQ;IAWrD,SAAS,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,oBAAoB,CAAC;YAwDvE,yBAAyB;YA4BzB,0BAA0B;YAoE1B,6BAA6B;IAiC3C,OAAO,CAAC,iBAAiB;CAG1B"}
|
package/dist/Engine.js
CHANGED
|
@@ -1,30 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RecommendationEngineBase =
|
|
3
|
+
exports.RecommendationEngineBase = void 0;
|
|
4
4
|
const core_1 = require("@memberjunction/core");
|
|
5
5
|
const global_1 = require("@memberjunction/global");
|
|
6
6
|
const ProviderBase_1 = require("./ProviderBase");
|
|
7
|
-
/**
|
|
8
|
-
* Used to make requests to providers
|
|
9
|
-
*/
|
|
10
|
-
class RecommendationRequest {
|
|
11
|
-
constructor() {
|
|
12
|
-
/**
|
|
13
|
-
* Array of the requested recommendations
|
|
14
|
-
*/
|
|
15
|
-
this.Recommendations = [];
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.RecommendationRequest = RecommendationRequest;
|
|
19
|
-
/**
|
|
20
|
-
* This response is generated for each Recommend() request
|
|
21
|
-
*/
|
|
22
|
-
class RecommendationResult {
|
|
23
|
-
constructor(request) {
|
|
24
|
-
this.Request = request;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.RecommendationResult = RecommendationResult;
|
|
28
7
|
/**
|
|
29
8
|
* Engine class to be used for running all recommendation requests
|
|
30
9
|
*/
|
|
@@ -33,6 +12,12 @@ class RecommendationEngineBase extends core_1.BaseEngine {
|
|
|
33
12
|
super(...arguments);
|
|
34
13
|
this._RecommendationProviders = [];
|
|
35
14
|
}
|
|
15
|
+
static get Instance() {
|
|
16
|
+
return super.getInstance();
|
|
17
|
+
}
|
|
18
|
+
get RecommendationProviders() {
|
|
19
|
+
return this._RecommendationProviders;
|
|
20
|
+
}
|
|
36
21
|
async Config(forceRefresh, contextUser) {
|
|
37
22
|
const params = [
|
|
38
23
|
{
|
|
@@ -42,51 +27,158 @@ class RecommendationEngineBase extends core_1.BaseEngine {
|
|
|
42
27
|
];
|
|
43
28
|
return await this.Load(params, forceRefresh, contextUser);
|
|
44
29
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Call this method with a provider and a request and a result will be generated
|
|
47
|
-
* @param request - The Recommendations to request, and an optional provider
|
|
48
|
-
*/
|
|
49
30
|
async Recommend(request) {
|
|
50
|
-
|
|
31
|
+
super.TryThrowIfNotLoaded();
|
|
32
|
+
let provider = request.Provider;
|
|
51
33
|
if (!provider) {
|
|
52
|
-
|
|
34
|
+
if (this.RecommendationProviders.length == 0) {
|
|
35
|
+
throw new Error('No recommendation provider provider and no provider found in metadata');
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
provider = this.RecommendationProviders[0];
|
|
39
|
+
}
|
|
53
40
|
}
|
|
41
|
+
(0, core_1.LogStatus)(`Recommendation Engine is using provider: ${provider.Name}`);
|
|
54
42
|
// get the driver
|
|
55
43
|
const driver = global_1.MJGlobal.Instance.ClassFactory.CreateInstance(ProviderBase_1.RecommendationProviderBase, provider.Name);
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (runIDs.length > 1) {
|
|
59
|
-
const message = 'All Recommendations must use the same RecommendationRunID';
|
|
60
|
-
(0, core_1.LogError)(message, null, { runIDs });
|
|
61
|
-
throw new Error(message);
|
|
62
|
-
}
|
|
63
|
-
const [runID] = runIDs;
|
|
64
|
-
// load the run
|
|
65
|
-
const run = await new core_1.Metadata().GetEntityObject('Recommendation Runs');
|
|
66
|
-
if (!(await run.Load(runID))) {
|
|
67
|
-
throw new Error(`Error loading RecommendationRun with ID: ${runID}`);
|
|
44
|
+
if (!driver) {
|
|
45
|
+
throw new Error(`Could not find driver for provider: ${provider.Name}`);
|
|
68
46
|
}
|
|
47
|
+
const recommendations = await this.GetRecommendationEntities(request);
|
|
48
|
+
(0, core_1.LogStatus)(`Processing ${recommendations.length} recommendations`);
|
|
49
|
+
request.Recommendations = recommendations;
|
|
50
|
+
// load the run
|
|
51
|
+
const recommendationRunEntity = await new core_1.Metadata().GetEntityObject('Recommendation Runs', request.CurrentUser);
|
|
52
|
+
recommendationRunEntity.NewRecord();
|
|
69
53
|
// update status for current run
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
54
|
+
recommendationRunEntity.Status = 'In Progress';
|
|
55
|
+
recommendationRunEntity.RecommendationProviderID = provider.ID;
|
|
56
|
+
recommendationRunEntity.StartDate = new Date();
|
|
57
|
+
recommendationRunEntity.RunByUserID = request.CurrentUser ? request.CurrentUser.ID : super.ContextUser.ID;
|
|
58
|
+
const saveResult = await recommendationRunEntity.Save();
|
|
59
|
+
if (!saveResult) {
|
|
60
|
+
(0, core_1.LogStatus)(`Error saving RecommendationRun entity: `, undefined, recommendationRunEntity.LatestResult);
|
|
61
|
+
throw new Error('Error creating Recommendation Run entity');
|
|
62
|
+
}
|
|
63
|
+
request.RunID = recommendationRunEntity.ID;
|
|
64
|
+
const recommendResult = await driver.Recommend(request);
|
|
65
|
+
recommendationRunEntity.Status = recommendResult.Success ? 'Completed' : 'Error';
|
|
66
|
+
recommendationRunEntity.Description = recommendResult.ErrorMessage;
|
|
67
|
+
const postRunSaveResult = await recommendationRunEntity.Save();
|
|
68
|
+
if (!postRunSaveResult) {
|
|
69
|
+
(0, core_1.LogStatus)(`Error saving RecommendationRun entity: `, undefined, recommendationRunEntity.LatestResult);
|
|
70
|
+
throw new Error('Error updating Recommendation Run entity');
|
|
71
|
+
}
|
|
72
|
+
return recommendResult;
|
|
73
|
+
}
|
|
74
|
+
async GetRecommendationEntities(request) {
|
|
75
|
+
if (request.Recommendations) {
|
|
76
|
+
const invalidEntities = request.Recommendations.filter((r) => !this.IsNullOrUndefined(r.RecommendationRunID) || r.IsSaved);
|
|
77
|
+
if (invalidEntities.length > 0) {
|
|
78
|
+
throw new Error(`Recommendation entities must be new, not saved and have their RecommendationRunID not set. Invalid entities: ${invalidEntities.map((r) => r.ID).join(',')}`);
|
|
80
79
|
}
|
|
80
|
+
return request.Recommendations;
|
|
81
81
|
}
|
|
82
|
-
else {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
else if (request.ListID) {
|
|
83
|
+
return await this.GetRecommendationsByListID(request.ListID, request.CurrentUser);
|
|
84
|
+
}
|
|
85
|
+
else if (request.EntityAndRecordsInfo) {
|
|
86
|
+
const entityName = request.EntityAndRecordsInfo.EntityName;
|
|
87
|
+
const recordIDs = request.EntityAndRecordsInfo.RecordIDs;
|
|
88
|
+
if (!entityName) {
|
|
89
|
+
throw new Error('Entity name is required in EntityAndRecordsInfo');
|
|
90
|
+
}
|
|
91
|
+
if (!recordIDs) {
|
|
92
|
+
throw new Error('RecordIDs are required in EntityAndRecordsInfo');
|
|
87
93
|
}
|
|
94
|
+
return await this.GetRecommendationsByRecordIDs(entityName, recordIDs, request.CurrentUser);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async GetRecommendationsByListID(listID, currentUser) {
|
|
98
|
+
const rv = new core_1.RunView();
|
|
99
|
+
const md = new core_1.Metadata();
|
|
100
|
+
const rvListDetailsResult = await rv.RunViews([
|
|
101
|
+
{
|
|
102
|
+
EntityName: 'Lists',
|
|
103
|
+
ExtraFilter: `ID = '${listID}'`,
|
|
104
|
+
ResultType: 'simple'
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
EntityName: 'List Details',
|
|
108
|
+
ExtraFilter: `ListID = '${listID}'`,
|
|
109
|
+
ResultType: 'simple',
|
|
110
|
+
IgnoreMaxRows: true,
|
|
111
|
+
}
|
|
112
|
+
], currentUser);
|
|
113
|
+
const listViewResult = rvListDetailsResult[0];
|
|
114
|
+
if (!listViewResult.Success) {
|
|
115
|
+
throw new Error(`Error getting list with ID: ${listID}: ${listViewResult.ErrorMessage}`);
|
|
116
|
+
}
|
|
117
|
+
if (listViewResult.Results.length == 0) {
|
|
118
|
+
throw new Error(`No list found with ID: ${listID}`);
|
|
88
119
|
}
|
|
89
|
-
|
|
120
|
+
const list = listViewResult.Results[0];
|
|
121
|
+
const entityName = list.Entity;
|
|
122
|
+
(0, core_1.LogStatus)(`Getting recommendations for list: ${list.Name}. Entity: ${entityName}`);
|
|
123
|
+
const entityID = list.EntityID;
|
|
124
|
+
const entity = md.Entities.find((e) => e.ID == entityID);
|
|
125
|
+
const needsQuotes = entity.FirstPrimaryKey.NeedsQuotes ? "'" : '';
|
|
126
|
+
const listDetailsResult = rvListDetailsResult[1];
|
|
127
|
+
if (!listDetailsResult.Success) {
|
|
128
|
+
throw new Error(`Error getting list details for listID: ${listID}: ${listDetailsResult.ErrorMessage}`);
|
|
129
|
+
}
|
|
130
|
+
//list is empty, just exit early
|
|
131
|
+
if (listDetailsResult.Results.length == 0) {
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
const recordIDs = listDetailsResult.Results.map((ld) => `${needsQuotes}${ld.RecordID}${needsQuotes}`).join(',');
|
|
135
|
+
const rvEntityResult = await rv.RunView({
|
|
136
|
+
EntityName: entityName,
|
|
137
|
+
ExtraFilter: `${entity.FirstPrimaryKey.Name} IN (${recordIDs})`,
|
|
138
|
+
IgnoreMaxRows: true,
|
|
139
|
+
}, currentUser);
|
|
140
|
+
if (!rvEntityResult.Success) {
|
|
141
|
+
throw new Error(`Error getting entity records for listID: ${listID}: ${rvEntityResult.ErrorMessage}`);
|
|
142
|
+
}
|
|
143
|
+
let recommendations = [];
|
|
144
|
+
for (const entity of rvEntityResult.Results) {
|
|
145
|
+
const recommendationEntity = await md.GetEntityObject('Recommendations', currentUser);
|
|
146
|
+
recommendationEntity.NewRecord();
|
|
147
|
+
recommendationEntity.SourceEntityID = entityID;
|
|
148
|
+
recommendationEntity.SourceEntityRecordID = entity.ID;
|
|
149
|
+
recommendations.push(recommendationEntity);
|
|
150
|
+
}
|
|
151
|
+
return recommendations;
|
|
152
|
+
}
|
|
153
|
+
async GetRecommendationsByRecordIDs(entityName, recordIDs, currentUser) {
|
|
154
|
+
const md = new core_1.Metadata();
|
|
155
|
+
const rv = new core_1.RunView();
|
|
156
|
+
const entity = md.Entities.find((e) => e.Name.toLowerCase() == entityName.toLowerCase());
|
|
157
|
+
if (!entity) {
|
|
158
|
+
throw new Error(`Unable to get recommendations by entity info: Entity not found with name: ${entityName}`);
|
|
159
|
+
}
|
|
160
|
+
(0, core_1.LogStatus)(`Getting recommendations for entity: ${entityName}`);
|
|
161
|
+
const needsQuotes = entity.FirstPrimaryKey.NeedsQuotes ? "'" : '';
|
|
162
|
+
const recordIDsFilter = recordIDs.map((id) => `${needsQuotes}${id}${needsQuotes}`).join(',');
|
|
163
|
+
const rvEntityResult = await rv.RunView({
|
|
164
|
+
EntityName: entityName,
|
|
165
|
+
ExtraFilter: `${entity.FirstPrimaryKey.Name} IN (${recordIDsFilter})`,
|
|
166
|
+
IgnoreMaxRows: true,
|
|
167
|
+
}, currentUser);
|
|
168
|
+
if (!rvEntityResult.Success) {
|
|
169
|
+
throw new Error(`Error getting entity records for entity: ${entityName}: ${rvEntityResult.ErrorMessage}`);
|
|
170
|
+
}
|
|
171
|
+
let recommendations = [];
|
|
172
|
+
for (const entity of rvEntityResult.Results) {
|
|
173
|
+
const recommendationEntity = await md.GetEntityObject('Recommendations', currentUser);
|
|
174
|
+
recommendationEntity.NewRecord();
|
|
175
|
+
recommendationEntity.SourceEntityID = entity.ID;
|
|
176
|
+
recommendations.push(recommendationEntity);
|
|
177
|
+
}
|
|
178
|
+
return recommendations;
|
|
179
|
+
}
|
|
180
|
+
IsNullOrUndefined(value) {
|
|
181
|
+
return value === null || value === undefined;
|
|
90
182
|
}
|
|
91
183
|
}
|
|
92
184
|
exports.RecommendationEngineBase = RecommendationEngineBase;
|
package/dist/Engine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Engine.js","sourceRoot":"","sources":["../src/Engine.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"Engine.js","sourceRoot":"","sources":["../src/Engine.ts"],"names":[],"mappings":";;;AAAA,+CAAsG;AAEtG,mDAAkD;AAClD,iDAA4D;AAG5D;;GAEG;AACH,MAAa,wBAAyB,SAAQ,iBAAoC;IAAlF;;QACU,6BAAwB,GAAmC,EAAE,CAAC;IAiNxE,CAAC;IA/MQ,MAAM,KAAK,QAAQ;QACxB,OAAO,KAAK,CAAC,WAAW,EAA4B,CAAC;IACvD,CAAC;IAED,IAAW,uBAAuB;QAChC,OAAO,IAAI,CAAC,wBAAwB,CAAC;IACvC,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,YAAsB,EAAE,WAAsB;QAChE,MAAM,MAAM,GAAG;YACb;gBACE,YAAY,EAAE,0BAA0B;gBACxC,UAAU,EAAE,0BAA0B;aACvC;SACF,CAAC;QAEF,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;IAC5D,CAAC;IAEM,KAAK,CAAC,SAAS,CAAC,OAA8B;QACnD,KAAK,CAAC,mBAAmB,EAAE,CAAC;QAE5B,IAAI,QAAQ,GAAiC,OAAO,CAAC,QAAQ,CAAC;QAC9D,IAAI,CAAC,QAAQ,EAAC,CAAC;YACb,IAAG,IAAI,CAAC,uBAAuB,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;gBAC5C,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAC;YAC3F,CAAC;iBACG,CAAC;gBACH,QAAQ,GAAG,IAAI,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;QAED,IAAA,gBAAS,EAAC,4CAA4C,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QAEvE,iBAAiB;QACjB,MAAM,MAAM,GAAG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E,MAAM,eAAe,GAAW,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,WAAW,GAAG,EAAE,GAAG,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACrG,MAAM,cAAc,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC;YACtC,UAAU,EAAE,UAAU;YACtB,WAAW,EAAE,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,QAAQ,eAAe,GAAG;YACrE,aAAa,EAAE,IAAI;SACpB,EAAE,WAAW,CAAC,CAAC;QAEhB,IAAG,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,4CAA4C,UAAU,KAAK,cAAc,CAAC,YAAY,EAAE,CAAC,CAAC;QAC5G,CAAC;QAED,IAAI,eAAe,GAA2B,EAAE,CAAC;QACjD,KAAI,MAAM,MAAM,IAAI,cAAc,CAAC,OAAO,EAAE,CAAC;YAC3C,MAAM,oBAAoB,GAAyB,MAAM,EAAE,CAAC,eAAe,CAAuB,iBAAiB,EAAE,WAAW,CAAC,CAAC;YAClI,oBAAoB,CAAC,SAAS,EAAE,CAAC;YACjC,oBAAoB,CAAC,cAAc,GAAG,MAAM,CAAC,EAAE,CAAC;YAChD,eAAe,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAC7C,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;IAEO,iBAAiB,CAAC,KAAc;QACtC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;IAC/C,CAAC;CACF;AAlND,4DAkNC"}
|
package/dist/ProviderBase.d.ts
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RecommendationEntity, RecommendationItemEntity } from '@memberjunction/core-entities';
|
|
2
|
+
import { UserInfo } from '@memberjunction/core';
|
|
3
|
+
import { RecommendationRequest, RecommendationResult } from './generic/types';
|
|
2
4
|
/**
|
|
3
5
|
* Base class for all recommendation providers
|
|
4
6
|
*/
|
|
5
7
|
export declare abstract class RecommendationProviderBase {
|
|
8
|
+
private _md;
|
|
9
|
+
private _ContextUser;
|
|
10
|
+
constructor(ContextUser: UserInfo);
|
|
11
|
+
get ContextUser(): UserInfo;
|
|
6
12
|
/**
|
|
7
13
|
* For each entry in the request.Recommendations array, the provider's external API is called to
|
|
8
14
|
* produce zero or more {@link RecommendationItemEntity} records.
|
|
9
15
|
*
|
|
10
16
|
* @param request - The Recommendations to request from this provider
|
|
11
17
|
*/
|
|
12
|
-
abstract Recommend(request:
|
|
18
|
+
abstract Recommend(request: RecommendationRequest): Promise<RecommendationResult>;
|
|
19
|
+
/**
|
|
20
|
+
* This method is used by subclasses to update a Recommendation record in the database to set the RecommendationRunID column. In addition,
|
|
21
|
+
* this method will save all the RecommendationItem records associated with the Recommendation record and link them to the Recommendation record.
|
|
22
|
+
* @param recommendation
|
|
23
|
+
* @param RunID
|
|
24
|
+
*/
|
|
25
|
+
protected SaveRecommendation(recommendation: RecommendationEntity, RunID: string, items: RecommendationItemEntity[]): Promise<boolean>;
|
|
13
26
|
}
|
|
14
27
|
//# sourceMappingURL=ProviderBase.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProviderBase.d.ts","sourceRoot":"","sources":["../src/ProviderBase.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ProviderBase.d.ts","sourceRoot":"","sources":["../src/ProviderBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAC/F,OAAO,EAAsB,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAE9E;;GAEG;AACH,8BAAsB,0BAA0B;IAC9C,OAAO,CAAC,GAAG,CAAW;IACtB,OAAO,CAAC,YAAY,CAAW;gBAEZ,WAAW,EAAE,QAAQ;IAKxC,IAAW,WAAW,IAAI,QAAQ,CAEjC;IAED;;;;;OAKG;aACa,SAAS,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAExF;;;;;OAKG;cACa,kBAAkB,CAAC,cAAc,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,wBAAwB,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;CAoB7I"}
|
package/dist/ProviderBase.js
CHANGED
|
@@ -1,10 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RecommendationProviderBase = void 0;
|
|
4
|
+
const core_1 = require("@memberjunction/core");
|
|
4
5
|
/**
|
|
5
6
|
* Base class for all recommendation providers
|
|
6
7
|
*/
|
|
7
8
|
class RecommendationProviderBase {
|
|
9
|
+
constructor(ContextUser) {
|
|
10
|
+
this._ContextUser = ContextUser;
|
|
11
|
+
this._md = new core_1.Metadata();
|
|
12
|
+
}
|
|
13
|
+
get ContextUser() {
|
|
14
|
+
return this._ContextUser;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* This method is used by subclasses to update a Recommendation record in the database to set the RecommendationRunID column. In addition,
|
|
18
|
+
* this method will save all the RecommendationItem records associated with the Recommendation record and link them to the Recommendation record.
|
|
19
|
+
* @param recommendation
|
|
20
|
+
* @param RunID
|
|
21
|
+
*/
|
|
22
|
+
async SaveRecommendation(recommendation, RunID, items) {
|
|
23
|
+
recommendation.RecommendationRunID = RunID;
|
|
24
|
+
const recommendationSaveResult = await recommendation.Save();
|
|
25
|
+
if (!recommendationSaveResult) {
|
|
26
|
+
(0, core_1.LogError)(`Error saving recommendation for ${recommendation.ID}`, undefined, recommendation.LatestResult);
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
let allSaved = true;
|
|
30
|
+
for (const item of items) {
|
|
31
|
+
item.RecommendationID = recommendation.ID;
|
|
32
|
+
const saveResult = await item.Save();
|
|
33
|
+
if (!saveResult) {
|
|
34
|
+
(0, core_1.LogError)(`Error saving recommendation item for recommendation ${recommendation.ID}`, undefined, item.LatestResult);
|
|
35
|
+
allSaved = false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return allSaved;
|
|
39
|
+
}
|
|
8
40
|
}
|
|
9
41
|
exports.RecommendationProviderBase = RecommendationProviderBase;
|
|
10
42
|
//# sourceMappingURL=ProviderBase.js.map
|
package/dist/ProviderBase.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProviderBase.js","sourceRoot":"","sources":["../src/ProviderBase.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"ProviderBase.js","sourceRoot":"","sources":["../src/ProviderBase.ts"],"names":[],"mappings":";;;AACA,+CAAoE;AAGpE;;GAEG;AACH,MAAsB,0BAA0B;IAI9C,YAAmB,WAAqB;QACtC,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,GAAG,GAAG,IAAI,eAAQ,EAAE,CAAC;IAC5B,CAAC;IAED,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAUD;;;;;OAKG;IACO,KAAK,CAAC,kBAAkB,CAAC,cAAoC,EAAE,KAAa,EAAE,KAAiC;QACvH,cAAc,CAAC,mBAAmB,GAAG,KAAK,CAAC;QAC3C,MAAM,wBAAwB,GAAY,MAAM,cAAc,CAAC,IAAI,EAAE,CAAC;QACtE,IAAG,CAAC,wBAAwB,EAAE,CAAC;YAC7B,IAAA,eAAQ,EAAC,mCAAmC,cAAc,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;YACzG,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,QAAQ,GAAY,IAAI,CAAC;QAC7B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC,gBAAgB,GAAG,cAAc,CAAC,EAAE,CAAC;YAC1C,MAAM,UAAU,GAAY,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;YAC9C,IAAG,CAAC,UAAU,EAAE,CAAC;gBACf,IAAA,eAAQ,EAAC,uDAAuD,cAAc,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;gBACnH,QAAQ,GAAG,KAAK,CAAC;YACnB,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AA/CD,gEA+CC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { UserInfo } from "@memberjunction/core";
|
|
2
|
+
import { RecommendationEntity, RecommendationItemEntity, RecommendationProviderEntity, RecommendationRunEntity } from "@memberjunction/core-entities";
|
|
3
|
+
/**
|
|
4
|
+
* Used to make requests to Recommendation providers
|
|
5
|
+
*/
|
|
6
|
+
export declare class RecommendationRequest {
|
|
7
|
+
/**
|
|
8
|
+
* The ID of the RecommendationRun record that will be created by the caller of a given provider. This must be created before a provider is called.
|
|
9
|
+
* This is done automatically by the Recommendation Engine and can be populated manually if for some reason you want to call a provider directly outside
|
|
10
|
+
* of the engine. This is a required field.
|
|
11
|
+
*/
|
|
12
|
+
RunID?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Array of the requested recommendations. When preparing a batch of recommendations to request, do NOT set the RecommendationRunID or attempt
|
|
15
|
+
* to save the Recommendation records. This will be done as the batch is processed. You cannot save a Recommendation record until a Run is created
|
|
16
|
+
* which is done by the RecommendationEngineBase.Recommend() method.
|
|
17
|
+
*/
|
|
18
|
+
Recommendations?: RecommendationEntity[];
|
|
19
|
+
/**
|
|
20
|
+
* This is an optional field that can be passed in instead of the Recommendations field. If passed in,
|
|
21
|
+
* the Recommendations field will be populated with Recommendation Entities whose Primary key value matches any of the RecordIDs passed in.
|
|
22
|
+
*/
|
|
23
|
+
EntityAndRecordsInfo?: {
|
|
24
|
+
/**
|
|
25
|
+
* The name of the entity that the RecordIDs belong to
|
|
26
|
+
*/
|
|
27
|
+
EntityName: string;
|
|
28
|
+
/**
|
|
29
|
+
* The RecordIDs to fetch recommendations for. Note that if the record IDs
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
RecordIDs: Array<string | number>;
|
|
33
|
+
};
|
|
34
|
+
ListID?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The specific provider to use for the request. Leave this undefined if you want to use the default provider.
|
|
37
|
+
*/
|
|
38
|
+
Provider?: RecommendationProviderEntity;
|
|
39
|
+
/**
|
|
40
|
+
* UserInfo object to use when applicable.
|
|
41
|
+
*/
|
|
42
|
+
CurrentUser?: UserInfo;
|
|
43
|
+
/**
|
|
44
|
+
* Additional options to pass to the provider
|
|
45
|
+
*/
|
|
46
|
+
Options?: Record<string, any>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* This response is generated for each Recommend() request
|
|
50
|
+
*/
|
|
51
|
+
export declare class RecommendationResult {
|
|
52
|
+
Request: RecommendationRequest;
|
|
53
|
+
/**
|
|
54
|
+
* The Recommendation Run entity that was created by the recommendation engine
|
|
55
|
+
*/
|
|
56
|
+
RecommendationRun?: RecommendationRunEntity;
|
|
57
|
+
/**
|
|
58
|
+
* The Recommendation Item Entities that were created by the recommendation provider
|
|
59
|
+
*/
|
|
60
|
+
RecommendationItems?: RecommendationItemEntity[];
|
|
61
|
+
Success: boolean;
|
|
62
|
+
ErrorMessage: string;
|
|
63
|
+
constructor(request: RecommendationRequest);
|
|
64
|
+
/**
|
|
65
|
+
* Appends the provided warningMessage param to the ErrorMessage property,
|
|
66
|
+
* with "Warning: " prepended to the message and a newline character appended to the end.
|
|
67
|
+
* The value of the Success property is not changed.
|
|
68
|
+
*/
|
|
69
|
+
AppendWarning(warningMessage: string): void;
|
|
70
|
+
/**
|
|
71
|
+
* Appends the provided errorMessage param to the ErrorMessage property,
|
|
72
|
+
* with "Error: " prepended to the message and a newline character appended to the end.
|
|
73
|
+
* Also sets the Success property to false.
|
|
74
|
+
*/
|
|
75
|
+
AppendError(errorMessage: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* Returns the ErrorMessage property as an array of strings.
|
|
78
|
+
* Useful in the event multiple errors or warnings were produced
|
|
79
|
+
* during the recommendation run.
|
|
80
|
+
*/
|
|
81
|
+
GetErrorMessages(): string[];
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/generic/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,4BAA4B,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAEtJ;;GAEG;AACH,qBAAa,qBAAqB;IAC9B;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;OAIG;IACH,eAAe,CAAC,EAAE,oBAAoB,EAAE,CAAM;IAE9C;;;OAGG;IACH,oBAAoB,CAAC,EAAE;QACnB;;WAEG;QACH,UAAU,EAAE,MAAM,CAAC;QACnB;;;WAGG;QACH,SAAS,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;KACpC,CAAA;IAED,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,QAAQ,CAAC,EAAE,4BAA4B,CAAC;IAExC;;OAEG;IACH,WAAW,CAAC,EAAE,QAAQ,CAAC;IAEvB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACjC;AAED;;GAEG;AACH,qBAAa,oBAAoB;IAC7B,OAAO,EAAE,qBAAqB,CAAC;IAC/B;;OAEG;IACH,iBAAiB,CAAC,EAAE,uBAAuB,CAAC;IAC5C;;OAEG;IACH,mBAAmB,CAAC,EAAE,wBAAwB,EAAE,CAAM;IACtD,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;gBAET,OAAO,EAAE,qBAAqB;IAM1C;;;;OAIG;IACH,aAAa,CAAC,cAAc,EAAE,MAAM;IAIpC;;;;OAIG;IACH,WAAW,CAAC,YAAY,EAAE,MAAM;IAKhC;;;;OAIG;IACH,gBAAgB,IAAI,MAAM,EAAE;CAG/B"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RecommendationResult = exports.RecommendationRequest = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Used to make requests to Recommendation providers
|
|
6
|
+
*/
|
|
7
|
+
class RecommendationRequest {
|
|
8
|
+
constructor() {
|
|
9
|
+
/**
|
|
10
|
+
* Array of the requested recommendations. When preparing a batch of recommendations to request, do NOT set the RecommendationRunID or attempt
|
|
11
|
+
* to save the Recommendation records. This will be done as the batch is processed. You cannot save a Recommendation record until a Run is created
|
|
12
|
+
* which is done by the RecommendationEngineBase.Recommend() method.
|
|
13
|
+
*/
|
|
14
|
+
this.Recommendations = [];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.RecommendationRequest = RecommendationRequest;
|
|
18
|
+
/**
|
|
19
|
+
* This response is generated for each Recommend() request
|
|
20
|
+
*/
|
|
21
|
+
class RecommendationResult {
|
|
22
|
+
constructor(request) {
|
|
23
|
+
/**
|
|
24
|
+
* The Recommendation Item Entities that were created by the recommendation provider
|
|
25
|
+
*/
|
|
26
|
+
this.RecommendationItems = [];
|
|
27
|
+
this.Request = request;
|
|
28
|
+
this.Success = true;
|
|
29
|
+
this.ErrorMessage = "";
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Appends the provided warningMessage param to the ErrorMessage property,
|
|
33
|
+
* with "Warning: " prepended to the message and a newline character appended to the end.
|
|
34
|
+
* The value of the Success property is not changed.
|
|
35
|
+
*/
|
|
36
|
+
AppendWarning(warningMessage) {
|
|
37
|
+
this.ErrorMessage += `Warning: ${warningMessage} \n`;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Appends the provided errorMessage param to the ErrorMessage property,
|
|
41
|
+
* with "Error: " prepended to the message and a newline character appended to the end.
|
|
42
|
+
* Also sets the Success property to false.
|
|
43
|
+
*/
|
|
44
|
+
AppendError(errorMessage) {
|
|
45
|
+
this.Success = false;
|
|
46
|
+
this.ErrorMessage += `Error: ${errorMessage} \n`;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Returns the ErrorMessage property as an array of strings.
|
|
50
|
+
* Useful in the event multiple errors or warnings were produced
|
|
51
|
+
* during the recommendation run.
|
|
52
|
+
*/
|
|
53
|
+
GetErrorMessages() {
|
|
54
|
+
return this.ErrorMessage.split('\n');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.RecommendationResult = RecommendationResult;
|
|
58
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/generic/types.ts"],"names":[],"mappings":";;;AAGA;;GAEG;AACH,MAAa,qBAAqB;IAAlC;QAQI;;;;WAIG;QACH,oBAAe,GAA4B,EAAE,CAAC;IAkClD,CAAC;CAAA;AA/CD,sDA+CC;AAED;;GAEG;AACH,MAAa,oBAAoB;IAa7B,YAAY,OAA8B;QAP1C;;WAEG;QACH,wBAAmB,GAAgC,EAAE,CAAC;QAKlD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACH,aAAa,CAAC,cAAsB;QAChC,IAAI,CAAC,YAAY,IAAI,YAAY,cAAc,KAAK,CAAC;IACzD,CAAC;IAED;;;;OAIG;IACH,WAAW,CAAC,YAAoB;QAC5B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,YAAY,IAAI,UAAU,YAAY,KAAK,CAAC;IACrD,CAAC;IAED;;;;OAIG;IACH,gBAAgB;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;CACJ;AA9CD,oDA8CC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./Engine"), exports);
|
|
18
18
|
__exportStar(require("./ProviderBase"), exports);
|
|
19
|
+
__exportStar(require("./generic/types"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,iDAA+B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,iDAA+B;AAC/B,kDAAgC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ai-recommendations",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "MemberJunction Recommendations Engine",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"typescript": "^5.4.5"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@memberjunction/global": "2.
|
|
23
|
-
"@memberjunction/core": "2.
|
|
24
|
-
"@memberjunction/core-entities": "2.
|
|
25
|
-
"@memberjunction/ai": "2.
|
|
22
|
+
"@memberjunction/global": "2.5.0",
|
|
23
|
+
"@memberjunction/core": "2.5.0",
|
|
24
|
+
"@memberjunction/core-entities": "2.5.0",
|
|
25
|
+
"@memberjunction/ai": "2.5.0"
|
|
26
26
|
}
|
|
27
27
|
}
|