Socket
Socket
Sign inDemoInstall

@memberjunction/core

Package Overview
Dependencies
Maintainers
4
Versions
213
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@memberjunction/core - npm Package Compare versions

Comparing version 1.2.2 to 1.3.0

21

dist/generic/baseEntity.d.ts

@@ -1,3 +0,3 @@

import { EntityFieldInfo, EntityInfo, EntityFieldTSType, EntityPermissionType, RecordChange, ValidationResult, EntityRelationshipInfo, PrimaryKeyValue } from './entityInfo';
import { EntitySaveOptions, IEntityDataProvider } from './interfaces';
import { EntityFieldInfo, EntityInfo, EntityFieldTSType, EntityPermissionType, RecordChange, ValidationResult, EntityRelationshipInfo } from './entityInfo';
import { CompositeKey, EntitySaveOptions, IEntityDataProvider } from './interfaces';
import { UserInfo } from './securityInfo';

@@ -123,2 +123,3 @@ import { TransactionGroupBase } from './transactionGroup';

get PrimaryKeys(): EntityField[];
get CompositeKey(): CompositeKey;
/**

@@ -169,2 +170,6 @@ * Returns true if the record has been loaded from the database, false otherwise. This is useful to check to see if the record is in a "New Record" state or not.

GetRelatedEntityData(re: EntityRelationshipInfo, filter?: string, maxRecords?: number): Promise<any[]>;
GetRelatedEntityDataExt(re: EntityRelationshipInfo, filter?: string, maxRecords?: number): Promise<{
Data: any[];
TotalRowCount: number;
}>;
private init;

@@ -217,3 +222,3 @@ /**

* * NOTE: You should not be calling this method directly from outside of a sub-class in most cases. You will use the auto-generated sub-classes that have overriden versions of this method that blow out the primary keys into individual parameters. This is much easier to program against.
* @param PrimaryKeyValues An array of objects that contain the field name and value for the primary key of the record you want to load. For example, if you have a table called "Customers" with a primary key of "ID", you would pass in an array with a single object like this: {FieldName: "ID", Value: 1234}.
* @param CompositeKey Wrapper that holds an array of objects that contain the field name and value for the primary key of the record you want to load. For example, if you have a table called "Customers" with a primary key of "ID", you would pass in an array with a single object like this: {FieldName: "ID", Value: 1234}.
* *If you had a composite primary key, you would pass in an array with multiple objects, one for each field in the primary key. You may ONLY pass in the primary key fields, no other fields are allowed.

@@ -223,4 +228,4 @@ * @param EntityRelationshipsToLoad Optional, you can specify the names of the relationships to load up. This is an expensive operation as it loads up an array of the related entity objects for the main record, so use it sparingly.

*/
InnerLoad(PrimaryKeyValues: PrimaryKeyValue[], EntityRelationshipsToLoad?: string[]): Promise<boolean>;
protected ValidatePrimaryKeyArray(PrimaryKeyValues: PrimaryKeyValue[]): void;
InnerLoad(CompositeKey: CompositeKey, EntityRelationshipsToLoad?: string[]): Promise<boolean>;
protected ValidateCompositeKey(compositeKey: CompositeKey): void;
/**

@@ -264,9 +269,9 @@ * This method is meant to be used only in situations where you are sure that the data you are loading is current in the database. MAKE SURE YOU ARE PASSING IN ALL FIELDS.

/**
* Static Utility method to get RecordChanges for a given entityName/PrimaryKeyValue combination
* Static Utility method to get RecordChanges for a given entityName/KeyValuePair combination
* @param entityName
* @param PrimaryKeyValue
* @param KeyValuePair
* @returns
*/
static GetRecordChanges(entityName: string, PrimaryKeyValues: PrimaryKeyValue[]): Promise<RecordChange[]>;
static GetRecordChanges(entityName: string, CompositeKey: CompositeKey): Promise<RecordChange[]>;
}
//# sourceMappingURL=baseEntity.d.ts.map

@@ -299,2 +299,7 @@ "use strict";

}
get CompositeKey() {
const ck = new interfaces_1.CompositeKey();
ck.LoadFromEntityFields(this.PrimaryKeys);
return ck;
}
/**

@@ -423,5 +428,17 @@ * Returns true if the record has been loaded from the database, false otherwise. This is useful to check to see if the record is in a "New Record" state or not.

// (which means to include all of 'em), or they did and this entity is in the list
const reData = await this.GetRelatedEntityData(re, pre.filter, pre.maxRecords);
if (reData)
obj[re.RelatedEntity] = reData; // got some data (or an empty array) back, add it to the object
const reData = await this.GetRelatedEntityDataExt(re, pre.filter, pre.maxRecords);
if (reData) {
obj[re.RelatedEntity] = reData; // got some data (or an empty array) back, add it to the object
if (pre.maxRecords > 0) {
// add a note to the object to let the caller know that only the first X records are returned so
// that a caller can know that there could be more records available if they want them
let msg;
if (pre.maxRecords < reData.TotalRowCount)
msg = `Only the first ${pre.maxRecords} records are included in this response. There are ${reData.TotalRowCount} total records available.`;
else
msg = `All ${reData.TotalRowCount} records are included in this response.`;
obj[re.RelatedEntity].Note = msg; // add the message to the object as "Note"
obj[re.RelatedEntity].MaxRecordsFilter = pre.maxRecords; // add the max records to the object as "MaxRecords"
}
}
}

@@ -433,2 +450,6 @@ }

async GetRelatedEntityData(re, filter = null, maxRecords = null) {
const ret = await this.GetRelatedEntityDataExt(re, filter, maxRecords);
return ret?.Data;
}
async GetRelatedEntityDataExt(re, filter = null, maxRecords = null) {
// we need to query the database to get related entity info

@@ -438,4 +459,10 @@ const params = entityInfo_1.EntityInfo.BuildRelationshipViewParams(this, re, filter, maxRecords);

const result = await rv.RunView(params, this._contextCurrentUser);
if (result && result.Success)
return result.Results;
if (result && result.Success) {
return {
Data: result.Results,
TotalRowCount: result.TotalRowCount
};
}
else
return null;
}

@@ -586,3 +613,3 @@ init() {

* * NOTE: You should not be calling this method directly from outside of a sub-class in most cases. You will use the auto-generated sub-classes that have overriden versions of this method that blow out the primary keys into individual parameters. This is much easier to program against.
* @param PrimaryKeyValues An array of objects that contain the field name and value for the primary key of the record you want to load. For example, if you have a table called "Customers" with a primary key of "ID", you would pass in an array with a single object like this: {FieldName: "ID", Value: 1234}.
* @param CompositeKey Wrapper that holds an array of objects that contain the field name and value for the primary key of the record you want to load. For example, if you have a table called "Customers" with a primary key of "ID", you would pass in an array with a single object like this: {FieldName: "ID", Value: 1234}.
* *If you had a composite primary key, you would pass in an array with multiple objects, one for each field in the primary key. You may ONLY pass in the primary key fields, no other fields are allowed.

@@ -592,3 +619,3 @@ * @param EntityRelationshipsToLoad Optional, you can specify the names of the relationships to load up. This is an expensive operation as it loads up an array of the related entity objects for the main record, so use it sparingly.

*/
async InnerLoad(PrimaryKeyValues, EntityRelationshipsToLoad = null) {
async InnerLoad(CompositeKey, EntityRelationshipsToLoad = null) {
if (BaseEntity.Provider == null) {

@@ -599,7 +626,12 @@ throw new Error('No provider set');

const start = new Date().getTime();
this.ValidatePrimaryKeyArray(PrimaryKeyValues);
this.ValidateCompositeKey(CompositeKey);
this.CheckPermissions(entityInfo_1.EntityPermissionType.Read, true); // this will throw an error and exit out if we don't have permission
if (!this.IsSaved)
if (!this.IsSaved) {
this.init(); // wipe out current data if we're loading on top of existing record
const data = await BaseEntity.Provider.Load(this, PrimaryKeyValues, EntityRelationshipsToLoad, this.ActiveUser);
}
const data = await BaseEntity.Provider.Load(this, CompositeKey, EntityRelationshipsToLoad, this.ActiveUser);
if (!data) {
(0, logging_1.LogError)(`Error in BaseEntity.Load(${this.EntityInfo.Name}, Key: ${CompositeKey.ToString()}`);
return false; // no data loaded, return false
}
this.SetMany(data);

@@ -621,20 +653,20 @@ if (EntityRelationshipsToLoad) {

}
ValidatePrimaryKeyArray(PrimaryKeyValues) {
// make sure that PrimaryKeyValues is an array of 1+ objects, and that each object has a FieldName and Value property and that the FieldName is a valid field on the entity that has IsPrimaryKey set to true
if (!PrimaryKeyValues || PrimaryKeyValues.length === 0)
throw new Error('PrimaryKeyValues cannot be null or empty');
ValidateCompositeKey(compositeKey) {
// make sure that KeyValuePairs is an array of 1+ objects, and that each object has a FieldName and Value property and that the FieldName is a valid field on the entity that has IsPrimaryKey set to true
if (!compositeKey || !compositeKey.KeyValuePairs || compositeKey.KeyValuePairs.length === 0)
throw new Error('KeyValuePairs cannot be null or empty');
else {
// now loop through the array and make sure each object has a FieldName and Value property
// and that the field name is a valid field on the entity that has IsPrimaryKey set to true
for (let i = 0; i < PrimaryKeyValues.length; i++) {
const pk = PrimaryKeyValues[i];
for (let i = 0; i < compositeKey.KeyValuePairs.length; i++) {
const pk = compositeKey.KeyValuePairs[i];
if (!pk.FieldName || pk.FieldName.trim().length === 0)
throw new Error(`PrimaryKeyValues[${i}].FieldName cannot be null, empty, or whitespace`);
throw new Error(`KeyValuePairs[${i}].FieldName cannot be null, empty, or whitespace`);
if (pk.Value === null || pk.Value === undefined)
throw new Error(`PrimaryKeyValues[${i}].Value cannot be null or undefined`);
throw new Error(`KeyValuePairs[${i}].Value cannot be null or undefined`);
const field = this.Fields.find(f => f.Name.trim().toLowerCase() === pk.FieldName.trim().toLowerCase());
if (!field)
throw new Error(`PrimaryKeyValues[${i}].FieldName of ${pk.FieldName} does not exist on ${this.EntityInfo.Name}`);
throw new Error(`KeyValuePairs[${i}].FieldName of ${pk.FieldName} does not exist on ${this.EntityInfo.Name}`);
if (!field.IsPrimaryKey)
throw new Error(`PrimaryKeyValues[${i}].FieldName of ${pk.FieldName} is not a primary key field on ${this.EntityInfo.Name}`);
throw new Error(`KeyValuePairs[${i}].FieldName of ${pk.FieldName} is not a primary key field on ${this.EntityInfo.Name}`);
}

@@ -724,14 +756,16 @@ }

get RecordChanges() {
if (this.IsSaved)
return BaseEntity.GetRecordChanges(this.EntityInfo.Name, this.PrimaryKeys.map(pk => { return { FieldName: pk.Name, Value: pk.Value }; }));
else
if (this.IsSaved) {
return BaseEntity.GetRecordChanges(this.EntityInfo.Name, this.CompositeKey);
}
else {
throw new Error('Cannot get record changes for a record that has not been saved yet');
}
}
/**
* Static Utility method to get RecordChanges for a given entityName/PrimaryKeyValue combination
* Static Utility method to get RecordChanges for a given entityName/KeyValuePair combination
* @param entityName
* @param PrimaryKeyValue
* @param KeyValuePair
* @returns
*/
static async GetRecordChanges(entityName, PrimaryKeyValues) {
static async GetRecordChanges(entityName, CompositeKey) {
if (BaseEntity.Provider === null) {

@@ -741,3 +775,3 @@ throw new Error('No provider set');

else {
const results = await BaseEntity.Provider.GetRecordChanges(entityName, PrimaryKeyValues);
const results = await BaseEntity.Provider.GetRecordChanges(entityName, CompositeKey);
if (results) {

@@ -744,0 +778,0 @@ const changes = [];

@@ -5,2 +5,3 @@ import { BaseInfo } from "./baseInfo";

import { RowLevelSecurityFilterInfo, UserInfo } from "./securityInfo";
import { CompositeKey } from "./interfaces";
/**

@@ -233,3 +234,3 @@ * The possible status values for a record change

/**
* For fields in the database that have spaces in them, we need to replace the spaces with _ in order to create variables for stored procedures. This property returns a consistent CodeName you can use everywhere to refer to the field when generated variable names
* For fields in the database that have characters invalid for SQL identifiers in them, we need to replace those characters with _ in order to create variables for stored procedures. This property returns a consistent CodeName you can use everywhere to refer to the field when generated variable names
*/

@@ -275,3 +276,3 @@ private _codeName;

*/
export declare class PrimaryKeyValue {
export declare class KeyValuePair {
FieldName: string;

@@ -281,9 +282,2 @@ Value: any;

/**
* Utility function to compare two primary key sets to see if they are the same or not
* @param pkeyValues1
* @param pkeyValues2
* @returns true if the primary key values are the same, false if they are different
*/
export declare function ComparePrimaryKeys(pkeyValues1: PrimaryKeyValue[], pkeyValues2: PrimaryKeyValue[]): boolean;
/**
* Metadata about an entity

@@ -469,3 +463,3 @@ */

*/
PrimaryKeyValue: any;
CompositeKey: CompositeKey;
}

@@ -481,9 +475,9 @@ /**

/**
* The primary key value(s) for the surviving record - if the entity in question has a single-valued primary key this will be an array with a single element, otherwise it will be an array with multiple elements
* The composite key for the surviving record
*/
SurvivingRecordPrimaryKeyValues: PrimaryKeyValue[];
SurvivingRecordCompositeKey: CompositeKey;
/**
* The primary key value(s) for the record(s) to merge into the surviving record - if the entity in question has a single-valued primary key, each item in the top level array will be an array with a single element, otherwise each item in the top level array will be an array with multiple elements
* The composite key(s) for the record(s) to merge into the surviving record
*/
RecordsToMerge: PrimaryKeyValue[][];
RecordsToMerge: CompositeKey[];
/**

@@ -504,3 +498,3 @@ * If you want to keep the values in the fields of the surviving record as they are, leave this blank. If you want to override the values in the surviving record with other values, specify the values you would like for each field in this array of objects. Each object has two properties, FieldName and Value. The FieldName is the name of the field to set and the Value is the value to set in it.

*/
PrimaryKeyValues: PrimaryKeyValue[];
CompositeKey: CompositeKey;
/**

@@ -507,0 +501,0 @@ * True if the merge for this specific record was successful, false if not

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RecordMergeResult = exports.RecordMergeDetailResult = exports.RecordMergeRequest = exports.RecordDependency = exports.EntityDependency = exports.ValidationResult = exports.ValidationErrorInfo = exports.ValidationErrorType = exports.EntityInfo = exports.ComparePrimaryKeys = exports.PrimaryKeyValue = exports.EntityFieldInfo = exports.GeneratedFormSectionType = exports.EntityFieldValueInfo = exports.EntityFieldValueListType = exports.EntityFieldGraphQLType = exports.EntityFieldTSType = exports.EntityPermissionInfo = exports.EntityUserPermissionInfo = exports.EntityPermissionType = exports.EntityRelationshipInfo = exports.RecordChange = exports.RecordChangeStatus = void 0;
exports.RecordMergeResult = exports.RecordMergeDetailResult = exports.RecordMergeRequest = exports.RecordDependency = exports.EntityDependency = exports.ValidationResult = exports.ValidationErrorInfo = exports.ValidationErrorType = exports.EntityInfo = exports.KeyValuePair = exports.EntityFieldInfo = exports.GeneratedFormSectionType = exports.EntityFieldValueInfo = exports.EntityFieldValueListType = exports.EntityFieldGraphQLType = exports.EntityFieldTSType = exports.EntityPermissionInfo = exports.EntityUserPermissionInfo = exports.EntityPermissionType = exports.EntityRelationshipInfo = exports.RecordChange = exports.RecordChangeStatus = void 0;
const baseInfo_1 = require("./baseInfo");

@@ -250,5 +250,5 @@ const metadata_1 = require("./metadata");

get CodeName() {
// the code below replaces spaces with _ and stashes the result in a private variable so we only do this once
// the code below replaces characters invalid for SQL identifiers with _ and stashes the result in a private variable so we only do this once
if (this._codeName == null)
this._codeName = this.Name.replace(/\s/g, "_");
this._codeName = this.Name.replace(/[\s-]/g, "_");
return this._codeName;

@@ -394,3 +394,3 @@ }

/**
* For fields in the database that have spaces in them, we need to replace the spaces with _ in order to create variables for stored procedures. This property returns a consistent CodeName you can use everywhere to refer to the field when generated variable names
* For fields in the database that have characters invalid for SQL identifiers in them, we need to replace those characters with _ in order to create variables for stored procedures. This property returns a consistent CodeName you can use everywhere to refer to the field when generated variable names
*/

@@ -416,22 +416,6 @@ this._codeName = null;

*/
class PrimaryKeyValue {
class KeyValuePair {
}
exports.PrimaryKeyValue = PrimaryKeyValue;
exports.KeyValuePair = KeyValuePair;
/**
* Utility function to compare two primary key sets to see if they are the same or not
* @param pkeyValues1
* @param pkeyValues2
* @returns true if the primary key values are the same, false if they are different
*/
function ComparePrimaryKeys(pkeyValues1, pkeyValues2) {
if (pkeyValues1.length !== pkeyValues2.length)
return false;
for (let i = 0; i < pkeyValues1.length; i++) {
if (pkeyValues1[i].Value !== pkeyValues2[i].Value)
return false;
}
return true;
}
exports.ComparePrimaryKeys = ComparePrimaryKeys;
/**
* Metadata about an entity

@@ -438,0 +422,0 @@ */

@@ -1,3 +0,3 @@

import { BaseEntity } from "./baseEntity";
import { EntityDependency, EntityInfo, PrimaryKeyValue, RecordChange, RecordDependency, RecordMergeRequest, RecordMergeResult } from "./entityInfo";
import { BaseEntity, EntityField } from "./baseEntity";
import { EntityDependency, EntityInfo, KeyValuePair, RecordChange, RecordDependency, RecordMergeRequest, RecordMergeResult } from "./entityInfo";
import { ApplicationInfo } from "./applicationInfo";

@@ -31,22 +31,98 @@ import { RunViewParams } from "../views/runView";

export type ProviderType = typeof ProviderType[keyof typeof ProviderType];
export declare class PrimaryKeyValueBase {
PrimaryKeyValues: PrimaryKeyValue[];
GetCompositeKey(): string;
export declare class CompositeKey {
KeyValuePairs: KeyValuePair[];
constructor(keyValuePairs?: KeyValuePair[]);
/**
* returns the value of the key value pair for the specified field name
* @param fieldName the field name to get the value for
* @returns the value of the key value pair for the specified field name
*/
GetValueByFieldName(fieldName: string): any;
/**
* returns the value of the key value pair at the specified index
* @param index the index of the key value pair to get the value for
* @returns the value of the key value pair at the specified index
*/
GetValueByIndex(index: number): any;
/**
* @returns a string representation of the primary key values in the format "FieldName=Value"
* @example "ID=1 AND Name=John"
* @param useIsNull if true, will return "FieldName IS NULL" for any key value pair that has a null or undefined value
*/
ToString(useIsNull?: boolean): string;
/**
* @returns a copy of the KeyValuePairs array but with the Value properties as type string
*/
ValuesAsString(): KeyValuePair[];
/**
* Utility function to return a copy of the CompositeKey with the Value properties as string
* @returns a copy of the KeyValuePairs array but with the Value properties as string
*/
Copy(): CompositeKey;
/**
* @returns the KeyValuePairs as a list of strings in the format "FieldName=Value"
* @param delimiter the delimiter to use between the field name and value. Defaults to '='
* @example ["ID=1", "Name=John"]
*/
ToList(delimiter?: string): string[];
/**
* @returns the value of each key value pair in the format "Value1, Value2, Value3"
* @param delimiter - the delimiter to use between the values. Defaults to ', '
* @example "1, John"
*/
Values(delimiter?: string): string;
/**
* Utility function to compare the key primary key of this object to another sets to see if they are the same or not
* @param kvPairs the primary key values to compare against
* @returns true if the primary key values are the same, false if they are different
*/
EqualsKey(kvPairs: KeyValuePair[]): boolean;
/**
* Utility function to compare this composite key to another
* @param compositeKey the composite key to compare against
* @returns true if the primary key values are the same, false if they are different
*/
Equals(compositeKey: CompositeKey): boolean;
LoadFromEntityFields(fields: EntityField[]): void;
LoadFromEntityInfoAndRecord(entity: EntityInfo, entityRecord: any): void;
/**
* Loads the KeyValuePairs from a list of strings in the format "FieldName=Value"
* @param list - the list of strings to load from
* @param delimiter - the delimiter to use between the field name and value. Defaults to '='
* @example ["ID=1", "Name=John"]
*/
LoadFromList(list: string[], delimiter?: string): void;
ToURLSegment(segment?: string): string;
LoadFromURLSegment(entity: EntityInfo, routeSegment: string, segment?: string): void;
/**
* Helper method to check if the underlying key value pairs are valid or not
* i.e. if any of the key value pairs are null or undefined
* @returns true if all key value pairs are valid, false if any are null or undefined
*/
Validate(): {
IsValid: boolean;
ErrorMessage: string;
};
}
export declare class PotentialDuplicate extends PrimaryKeyValueBase {
export declare class PotentialDuplicate extends CompositeKey {
ProbabilityScore: number;
}
export declare class PotentialDuplicateRequest extends PrimaryKeyValueBase {
export declare class PotentialDuplicateRequest {
/**
* The ID of the entity document to use
* The ID of the entity the record belongs to
**/
EntityDocumentID: number;
EntityID: number;
/**
* The ID of the entity the record belongs to
* The ID of the List entity to use
**/
EntityID?: number;
ListID: number;
/**
* The name of the entity the record belongs to
* The Primary Key values of each record
* we're checking for duplicates
*/
RecordIDs: CompositeKey[];
/**
* The ID of the entity document to use
**/
EntityName?: string;
EntityDocumentID?: number;
/**

@@ -61,12 +137,19 @@ * The minimum score in order to consider a record a potential duplicate

}
export declare class PotentialDuplicateResponse {
export declare class PotentialDuplicateResult {
EntityID: number;
RecordCompositeKey: CompositeKey;
Duplicates: PotentialDuplicate[];
DuplicateRunDetailMatchRecordIDs: number[];
}
export declare class PotentialDuplicateResponse {
Status: 'Inprogress' | 'Success' | 'Error';
ErrorMessage?: string;
PotentialDuplicateResult: PotentialDuplicateResult[];
}
export interface IEntityDataProvider {
Config(configData: ProviderConfigDataBase): Promise<boolean>;
Load(entity: BaseEntity, PrimaryKeyValues: PrimaryKeyValue[], EntityRelationshipsToLoad: string[], user: UserInfo): Promise<{}>;
Load(entity: BaseEntity, CompositeKey: CompositeKey, EntityRelationshipsToLoad: string[], user: UserInfo): Promise<{}>;
Save(entity: BaseEntity, user: UserInfo, options: EntitySaveOptions): Promise<{}>;
Delete(entity: BaseEntity, user: UserInfo): Promise<boolean>;
GetRecordChanges(entityName: string, PrimaryKeyValues: PrimaryKeyValue[]): Promise<RecordChange[]>;
GetRecordChanges(entityName: string, CompositeKey: CompositeKey): Promise<RecordChange[]>;
}

@@ -79,3 +162,3 @@ export declare class EntitySaveOptions {

EntityName: string;
PrimaryKeyValues: PrimaryKeyValue[];
CompositeKey: CompositeKey;
}

@@ -85,3 +168,3 @@ export declare class EntityRecordNameResult {

Status: string;
PrimaryKeyValues: PrimaryKeyValue[];
CompositeKey: CompositeKey;
EntityName: string;

@@ -119,9 +202,9 @@ RecordName?: string;

* @param entityName the name of the entity to check
* @param primaryKeyValues the primary key(s) for the record to check
* @param CompositeKey the compositeKey for the record to check
*/
GetRecordDependencies(entityName: string, primaryKeyValues: PrimaryKeyValue[]): Promise<RecordDependency[]>;
GetRecordDependencies(entityName: string, CompositeKey: CompositeKey): Promise<RecordDependency[]>;
/**
* Returns a list of record IDs that are possible duplicates of the specified record.
*
* @param params object containing many properties used in fetching records and determining which ones to return
* @param params Object containing many properties used in fetching records and determining which ones to return
*/

@@ -154,6 +237,6 @@ GetRecordDuplicates(params: PotentialDuplicateRequest, contextUser?: UserInfo): Promise<PotentialDuplicateResponse>;

* @param entityName
* @param primaryKeyValues
* @param CompositeKey
* @returns the name of the record
*/
GetEntityRecordName(entityName: string, primaryKeyValues: PrimaryKeyValue[]): Promise<string>;
GetEntityRecordName(entityName: string, compositeKey: CompositeKey): Promise<string>;
/**

@@ -165,4 +248,4 @@ * Returns one or more record names using the same logic as GetEntityRecordName, but for multiple records at once - more efficient to use this method if you need to get multiple record names at once

GetEntityRecordNames(info: EntityRecordNameInput[]): Promise<EntityRecordNameResult[]>;
GetRecordFavoriteStatus(userId: number, entityName: string, primaryKeyValues: PrimaryKeyValue[]): Promise<boolean>;
SetRecordFavoriteStatus(userId: number, entityName: string, primaryKeyValues: PrimaryKeyValue[], isFavorite: boolean, contextUser: UserInfo): Promise<void>;
GetRecordFavoriteStatus(userId: number, entityName: string, CompositeKey: CompositeKey): Promise<boolean>;
SetRecordFavoriteStatus(userId: number, entityName: string, CompositeKey: CompositeKey, isFavorite: boolean, contextUser: UserInfo): Promise<void>;
CreateTransactionGroup(): Promise<TransactionGroupBase>;

@@ -169,0 +252,0 @@ Refresh(): Promise<boolean>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EntityRecordNameResult = exports.EntityRecordNameInput = exports.EntitySaveOptions = exports.PotentialDuplicateResponse = exports.PotentialDuplicateRequest = exports.PotentialDuplicate = exports.PrimaryKeyValueBase = exports.ProviderType = exports.MetadataInfo = exports.ProviderConfigDataBase = void 0;
exports.EntityRecordNameResult = exports.EntityRecordNameInput = exports.EntitySaveOptions = exports.PotentialDuplicateResponse = exports.PotentialDuplicateResult = exports.PotentialDuplicateRequest = exports.PotentialDuplicate = exports.CompositeKey = exports.ProviderType = exports.MetadataInfo = exports.ProviderConfigDataBase = void 0;
const entityInfo_1 = require("./entityInfo");
class ProviderConfigDataBase {

@@ -37,24 +38,191 @@ get Data() {

};
class PrimaryKeyValueBase {
//MJ Server's DuplicateRecordResolve has a copy of this property
//changes here should be applied there as well
GetCompositeKey() {
if (!this.PrimaryKeyValues) {
return "";
class CompositeKey {
constructor(keyValuePairs) {
this.KeyValuePairs = keyValuePairs || [];
}
/**
* returns the value of the key value pair for the specified field name
* @param fieldName the field name to get the value for
* @returns the value of the key value pair for the specified field name
*/
GetValueByFieldName(fieldName) {
let key = this.KeyValuePairs.find((keyValue) => {
return keyValue.FieldName === fieldName;
});
return key ? key.Value : null;
}
/**
* returns the value of the key value pair at the specified index
* @param index the index of the key value pair to get the value for
* @returns the value of the key value pair at the specified index
*/
GetValueByIndex(index) {
if (index >= 0 && index < this.KeyValuePairs.length) {
return this.KeyValuePairs[index].Value;
}
if (this.PrimaryKeyValues.length === 1) {
return this.PrimaryKeyValues[0].Value.toString();
return null;
}
/**
* @returns a string representation of the primary key values in the format "FieldName=Value"
* @example "ID=1 AND Name=John"
* @param useIsNull if true, will return "FieldName IS NULL" for any key value pair that has a null or undefined value
*/
ToString(useIsNull) {
return this.KeyValuePairs.map((keyValue) => {
if (useIsNull && (keyValue.Value === null || keyValue.Value === undefined)) {
return `${keyValue.FieldName} IS NULL`;
}
return `${keyValue.FieldName}=${keyValue.Value}`;
}).join(" AND ");
}
/**
* @returns a copy of the KeyValuePairs array but with the Value properties as type string
*/
ValuesAsString() {
return this.KeyValuePairs.map((keyValue) => {
return {
FieldName: keyValue.FieldName,
Value: keyValue.Value.toString()
};
});
}
/**
* Utility function to return a copy of the CompositeKey with the Value properties as string
* @returns a copy of the KeyValuePairs array but with the Value properties as string
*/
Copy() {
let copy = new CompositeKey();
copy.KeyValuePairs = this.ValuesAsString();
return copy;
}
/**
* @returns the KeyValuePairs as a list of strings in the format "FieldName=Value"
* @param delimiter the delimiter to use between the field name and value. Defaults to '='
* @example ["ID=1", "Name=John"]
*/
ToList(delimiter) {
return this.KeyValuePairs.map((pk) => {
return delimiter ? `${pk.FieldName}${delimiter}${pk.Value}` : `${pk.FieldName}=${pk.Value}`;
});
}
/**
* @returns the value of each key value pair in the format "Value1, Value2, Value3"
* @param delimiter - the delimiter to use between the values. Defaults to ', '
* @example "1, John"
*/
Values(delimiter) {
return this.KeyValuePairs.map((keyValue) => {
return keyValue.Value;
}).join(delimiter || ", ");
}
/**
* Utility function to compare the key primary key of this object to another sets to see if they are the same or not
* @param kvPairs the primary key values to compare against
* @returns true if the primary key values are the same, false if they are different
*/
EqualsKey(kvPairs) {
if (!kvPairs || kvPairs.length === 0) {
return false;
}
return this.PrimaryKeyValues.map((keyValue, index) => {
return keyValue.Value.toString();
}).join(", ");
if (kvPairs.length !== this.KeyValuePairs.length) {
return false;
}
for (const [index, kvPair] of kvPairs.entries()) {
const sourcekvPair = this.KeyValuePairs[index];
if (kvPair.FieldName !== sourcekvPair.FieldName || kvPair.Value !== sourcekvPair.Value) {
return false;
}
}
return true;
}
/**
* Utility function to compare this composite key to another
* @param compositeKey the composite key to compare against
* @returns true if the primary key values are the same, false if they are different
*/
Equals(compositeKey) {
if (!compositeKey) {
return false;
}
return this.EqualsKey(compositeKey.KeyValuePairs);
}
LoadFromEntityFields(fields) {
this.KeyValuePairs = fields.map((field) => {
return {
FieldName: field.Name,
Value: field.Value
};
});
}
LoadFromEntityInfoAndRecord(entity, entityRecord) {
this.KeyValuePairs = entity.PrimaryKeys.map((pk) => {
return {
FieldName: pk.Name,
Value: entityRecord[pk.Name]
};
});
}
/**
* Loads the KeyValuePairs from a list of strings in the format "FieldName=Value"
* @param list - the list of strings to load from
* @param delimiter - the delimiter to use between the field name and value. Defaults to '='
* @example ["ID=1", "Name=John"]
*/
LoadFromList(list, delimiter) {
this.KeyValuePairs = list.map((pk) => {
let keyValue = delimiter ? pk.split(delimiter) : pk.split("=");
if (keyValue.length === 2) {
let keyValuePair = new entityInfo_1.KeyValuePair();
keyValuePair.FieldName = keyValue[0];
keyValuePair.Value = keyValue[1];
return keyValuePair;
}
return;
});
}
ToURLSegment(segment) {
return this.KeyValuePairs.map((pk) => {
return `${pk.FieldName}|${pk.Value}`;
}).join(segment || "||");
}
LoadFromURLSegment(entity, routeSegment, segment) {
if (!routeSegment.includes('|')) {
// If not, return a single element array with a default field name
this.KeyValuePairs = [{ FieldName: entity.PrimaryKey.Name, Value: routeSegment }];
}
else {
const parts = segment ? routeSegment.split(segment) : routeSegment.split('||');
const pkVals = [];
for (let p of parts) {
const kv = p.split('|');
pkVals.push({ FieldName: kv[0], Value: kv[1] });
}
this.KeyValuePairs = pkVals;
}
}
/**
* Helper method to check if the underlying key value pairs are valid or not
* i.e. if any of the key value pairs are null or undefined
* @returns true if all key value pairs are valid, false if any are null or undefined
*/
Validate() {
for (let j = 0; j < this.KeyValuePairs.length; j++) {
if (!this.KeyValuePairs[j] || !this.KeyValuePairs[j].Value) {
return { IsValid: false, ErrorMessage: 'CompositeKey.Validate: KeyValuePair cannot contain null values. FieldName: ' + this.KeyValuePairs[j]?.FieldName };
}
}
return { IsValid: true, ErrorMessage: '' };
}
}
exports.PrimaryKeyValueBase = PrimaryKeyValueBase;
class PotentialDuplicate extends PrimaryKeyValueBase {
exports.CompositeKey = CompositeKey;
class PotentialDuplicate extends CompositeKey {
}
exports.PotentialDuplicate = PotentialDuplicate;
class PotentialDuplicateRequest extends PrimaryKeyValueBase {
class PotentialDuplicateRequest {
}
exports.PotentialDuplicateRequest = PotentialDuplicateRequest;
class PotentialDuplicateResult {
}
exports.PotentialDuplicateResult = PotentialDuplicateResult;
//Wrapper for the PotentialDuplicateResponse class that includes additional properties
class PotentialDuplicateResponse {

@@ -61,0 +229,0 @@ }

@@ -1,3 +0,3 @@

import { DatasetItemFilterType, DatasetResultType, DatasetStatusResultType, EntityRecordNameInput, EntityRecordNameResult, ILocalStorageProvider, IMetadataProvider, PotentialDuplicateRequest, PotentialDuplicateResponse, ProviderConfigDataBase, ProviderType } from "./interfaces";
import { EntityDependency, EntityInfo, PrimaryKeyValue, RecordDependency, RecordMergeRequest, RecordMergeResult } from "./entityInfo";
import { DatasetItemFilterType, DatasetResultType, CompositeKey, DatasetStatusResultType, EntityRecordNameInput, EntityRecordNameResult, ILocalStorageProvider, IMetadataProvider, PotentialDuplicateRequest, PotentialDuplicateResponse, ProviderConfigDataBase, ProviderType } from "./interfaces";
import { EntityDependency, EntityInfo, RecordDependency, RecordMergeRequest, RecordMergeResult } from "./entityInfo";
import { ApplicationInfo } from "./applicationInfo";

@@ -51,18 +51,18 @@ import { BaseEntity } from "./baseEntity";

/**
* Returns true if the combination of userId/entityName/primaryKeyValues has a favorite status on (meaning the user has marked the record as a "favorite" for easy access)
* Returns true if the combination of userId/entityName/KeyValuePairs has a favorite status on (meaning the user has marked the record as a "favorite" for easy access)
* @param userId
* @param entityName
* @param primaryKeyValues
* @param KeyValuePairs
* @returns
*/
GetRecordFavoriteStatus(userId: number, entityName: string, primaryKeyValues: PrimaryKeyValue[]): Promise<boolean>;
GetRecordFavoriteStatus(userId: number, entityName: string, CompositeKey: CompositeKey): Promise<boolean>;
/**
* Sets the favorite status for a given user for a specific entityName/primaryKeyValues
* Sets the favorite status for a given user for a specific entityName/KeyValuePairs
* @param userId
* @param entityName
* @param primaryKeyValues
* @param KeyValuePairs
* @param isFavorite
* @param contextUser
*/
SetRecordFavoriteStatus(userId: number, entityName: string, primaryKeyValues: PrimaryKeyValue[], isFavorite: boolean, contextUser?: UserInfo): Promise<void>;
SetRecordFavoriteStatus(userId: number, entityName: string, CompositeKey: CompositeKey, isFavorite: boolean, contextUser?: UserInfo): Promise<void>;
/**

@@ -74,5 +74,5 @@ * Returns a list of dependencies - records that are linked to the specified Entity/Primary Key Value combination. A dependency is as defined by the relationships in the database. The MemberJunction metadata that is used

* @param entityName the name of the entity to check
* @param primaryKeyValue the primary key value to check
* @param KeyValuePair the primary key value to check
*/
GetRecordDependencies(entityName: string, primaryKeyValues: PrimaryKeyValue[]): Promise<RecordDependency[]>;
GetRecordDependencies(entityName: string, CompositeKey: CompositeKey): Promise<RecordDependency[]>;
/**

@@ -93,3 +93,3 @@ * Returns a list of record IDs that are possible duplicates of the specified record.

* 1. The surviving record is loaded and fields are updated from the field map, if provided, and the record is saved. If a FieldMap not provided within the request object, this step is skipped.
* 2. For each of the records that will be merged INTO the surviving record, we call the GetEntityDependencies() method and get a list of all other records in the database are linked to the record to be deleted. We then go through each of those dependencies and update the link to point to the SurvivingRecordPrimaryKeyValue and save the record.
* 2. For each of the records that will be merged INTO the surviving record, we call the GetEntityDependencies() method and get a list of all other records in the database are linked to the record to be deleted. We then go through each of those dependencies and update the link to point to the SurvivingRecordKeyValuePair and save the record.
* 3. The record to be deleted is then deleted.

@@ -116,10 +116,10 @@ *

/**
* Returns the Name of the specific primaryKeyValues for a given entityName. This is done by
* Returns the Name of the specific KeyValuePairs for a given entityName. This is done by
* looking for the IsNameField within the EntityFields collection for a given entity.
* If no IsNameField is found, but a field called "Name" exists, that value is returned. Otherwise null returned
* @param entityName
* @param primaryKeyValues
* @param KeyValuePairs
* @returns the name of the record
*/
GetEntityRecordName(entityName: string, primaryKeyValues: PrimaryKeyValue[]): Promise<string>;
GetEntityRecordName(entityName: string, compositeKey: CompositeKey): Promise<string>;
/**

@@ -126,0 +126,0 @@ * Returns one or more record names using the same logic as GetEntityRecordName, but for multiple records at once - more efficient to use this method if you need to get multiple record names at once

@@ -95,21 +95,21 @@ "use strict";

/**
* Returns true if the combination of userId/entityName/primaryKeyValues has a favorite status on (meaning the user has marked the record as a "favorite" for easy access)
* Returns true if the combination of userId/entityName/KeyValuePairs has a favorite status on (meaning the user has marked the record as a "favorite" for easy access)
* @param userId
* @param entityName
* @param primaryKeyValues
* @param KeyValuePairs
* @returns
*/
async GetRecordFavoriteStatus(userId, entityName, primaryKeyValues) {
return await Metadata.Provider.GetRecordFavoriteStatus(userId, entityName, primaryKeyValues);
async GetRecordFavoriteStatus(userId, entityName, CompositeKey) {
return await Metadata.Provider.GetRecordFavoriteStatus(userId, entityName, CompositeKey);
}
/**
* Sets the favorite status for a given user for a specific entityName/primaryKeyValues
* Sets the favorite status for a given user for a specific entityName/KeyValuePairs
* @param userId
* @param entityName
* @param primaryKeyValues
* @param KeyValuePairs
* @param isFavorite
* @param contextUser
*/
async SetRecordFavoriteStatus(userId, entityName, primaryKeyValues, isFavorite, contextUser = null) {
await Metadata.Provider.SetRecordFavoriteStatus(userId, entityName, primaryKeyValues, isFavorite, contextUser);
async SetRecordFavoriteStatus(userId, entityName, CompositeKey, isFavorite, contextUser = null) {
await Metadata.Provider.SetRecordFavoriteStatus(userId, entityName, CompositeKey, isFavorite, contextUser);
}

@@ -122,6 +122,6 @@ /**

* @param entityName the name of the entity to check
* @param primaryKeyValue the primary key value to check
* @param KeyValuePair the primary key value to check
*/
async GetRecordDependencies(entityName, primaryKeyValues) {
return await Metadata.Provider.GetRecordDependencies(entityName, primaryKeyValues);
async GetRecordDependencies(entityName, CompositeKey) {
return await Metadata.Provider.GetRecordDependencies(entityName, CompositeKey);
}

@@ -147,3 +147,3 @@ /**

* 1. The surviving record is loaded and fields are updated from the field map, if provided, and the record is saved. If a FieldMap not provided within the request object, this step is skipped.
* 2. For each of the records that will be merged INTO the surviving record, we call the GetEntityDependencies() method and get a list of all other records in the database are linked to the record to be deleted. We then go through each of those dependencies and update the link to point to the SurvivingRecordPrimaryKeyValue and save the record.
* 2. For each of the records that will be merged INTO the surviving record, we call the GetEntityDependencies() method and get a list of all other records in the database are linked to the record to be deleted. We then go through each of those dependencies and update the link to point to the SurvivingRecordKeyValuePair and save the record.
* 3. The record to be deleted is then deleted.

@@ -174,17 +174,15 @@ *

/**
* Returns the Name of the specific primaryKeyValues for a given entityName. This is done by
* Returns the Name of the specific KeyValuePairs for a given entityName. This is done by
* looking for the IsNameField within the EntityFields collection for a given entity.
* If no IsNameField is found, but a field called "Name" exists, that value is returned. Otherwise null returned
* @param entityName
* @param primaryKeyValues
* @param KeyValuePairs
* @returns the name of the record
*/
async GetEntityRecordName(entityName, primaryKeyValues) {
// check each primary key value to make sure it's not null
for (let j = 0; j < primaryKeyValues.length; j++) {
if (!primaryKeyValues[j] || !primaryKeyValues[j].Value) {
throw new Error('GetEntityRecordName: primaryKeyValues cannot contain null values. FieldName: ' + primaryKeyValues[j]?.FieldName);
}
async GetEntityRecordName(entityName, compositeKey) {
let result = compositeKey.Validate();
if (!result.IsValid) {
throw new Error(result.ErrorMessage);
}
return await Metadata.Provider.GetEntityRecordName(entityName, primaryKeyValues);
return await Metadata.Provider.GetEntityRecordName(entityName, compositeKey);
}

@@ -199,10 +197,10 @@ /**

for (let i = 0; i < info.length; i++) {
if (!info[i].PrimaryKeyValues || info[i].PrimaryKeyValues.length == 0) {
throw new Error('GetEntityRecordNames: PrimaryKeyValues cannot be null or empty. It is for item ' + i.toString() + ' in the input array.');
if (!info[i].CompositeKey.KeyValuePairs || info[i].CompositeKey.KeyValuePairs.length == 0) {
throw new Error('GetEntityRecordNames: KeyValuePairs cannot be null or empty. It is for item ' + i.toString() + ' in the input array.');
}
else {
// check each primary key value to make sure it's not null
for (let j = 0; j < info[i].PrimaryKeyValues.length; j++) {
if (!info[i].PrimaryKeyValues[j] || !info[i].PrimaryKeyValues[j].Value) {
throw new Error('GetEntityRecordNames: PrimaryKeyValues cannot contain null values. FieldName: ' + info[i].PrimaryKeyValues[j]?.FieldName);
for (let j = 0; j < info[i].CompositeKey.KeyValuePairs.length; j++) {
if (!info[i].CompositeKey.KeyValuePairs[j] || !info[i].CompositeKey.KeyValuePairs[j].Value) {
throw new Error('GetEntityRecordNames: KeyValuePairs cannot contain null values. FieldName: ' + info[i].CompositeKey.KeyValuePairs[j]?.FieldName);
}

@@ -209,0 +207,0 @@ }

import { BaseEntity } from "./baseEntity";
import { EntityDependency, EntityInfo, PrimaryKeyValue, RecordDependency, RecordMergeRequest, RecordMergeResult } from "./entityInfo";
import { IMetadataProvider, ProviderConfigDataBase, MetadataInfo, ILocalStorageProvider, DatasetResultType, DatasetStatusResultType, DatasetItemFilterType, EntityRecordNameInput, EntityRecordNameResult, ProviderType, PotentialDuplicateRequest, PotentialDuplicateResponse } from "./interfaces";
import { EntityDependency, EntityInfo, RecordDependency, RecordMergeRequest, RecordMergeResult } from "./entityInfo";
import { IMetadataProvider, ProviderConfigDataBase, MetadataInfo, CompositeKey, ILocalStorageProvider, DatasetResultType, DatasetStatusResultType, DatasetItemFilterType, EntityRecordNameInput, EntityRecordNameResult, ProviderType, PotentialDuplicateRequest, PotentialDuplicateResponse } from "./interfaces";
import { ApplicationInfo } from "../generic/applicationInfo";

@@ -40,6 +40,6 @@ import { AuditLogTypeInfo, AuthorizationInfo, RoleInfo, RowLevelSecurityFilterInfo, UserInfo } from "./securityInfo";

abstract get ProviderType(): ProviderType;
abstract GetEntityRecordName(entityName: string, primaryKeyValues: PrimaryKeyValue[]): Promise<string>;
abstract GetEntityRecordName(entityName: string, compositeKey: CompositeKey): Promise<string>;
abstract GetEntityRecordNames(info: EntityRecordNameInput[]): Promise<EntityRecordNameResult[]>;
abstract GetRecordFavoriteStatus(userId: number, entityName: string, primaryKeyValues: PrimaryKeyValue[]): Promise<boolean>;
abstract SetRecordFavoriteStatus(userId: number, entityName: string, primaryKeyValues: PrimaryKeyValue[], isFavorite: boolean, contextUser: UserInfo): Promise<void>;
abstract GetRecordFavoriteStatus(userId: number, entityName: string, CompositeKey: CompositeKey): Promise<boolean>;
abstract SetRecordFavoriteStatus(userId: number, entityName: string, CompositeKey: CompositeKey, isFavorite: boolean, contextUser: UserInfo): Promise<void>;
/******** END - ABSTRACT SECTION ****************************************************************** */

@@ -74,5 +74,5 @@ Config(data: ProviderConfigDataBase): Promise<boolean>;

* @param entityName the name of the entity to check
* @param primaryKeyValues the values of the primary key of the record to check
* @param KeyValuePairs the values of the primary key of the record to check
*/
abstract GetRecordDependencies(entityName: string, primaryKeyValues: PrimaryKeyValue[]): Promise<RecordDependency[]>;
abstract GetRecordDependencies(entityName: string, CompositeKey: CompositeKey): Promise<RecordDependency[]>;
/**

@@ -79,0 +79,0 @@ * Returns a list of record IDs that are possible duplicates of the specified record.

@@ -95,7 +95,7 @@ import { IRunViewProvider, RunViewResult } from '../generic/interfaces';

/**
* Result Type is either 'simple' or 'entity_object' and defaults to 'Plain'. If 'EntityObject' is specified, the Results[] array will contain
* BaseEntity-derived objects instead of plain objects. This is useful if you want to work with the data in a more strongly typed manner and/or
* if you plan to do any update/delete operations on the data.
* Result Type is: 'simple', 'entity_object', or 'count_only' and defaults to 'simple'. If 'entity_object' is specified, the Results[] array will contain
* BaseEntity-derived objects instead of simple objects. This is useful if you want to work with the data in a more strongly typed manner and/or
* if you plan to do any update/delete operations on the data after it is returned. The 'count_only' option will return no rows, but the TotalRowCount property of the RunViewResult object will be populated.
*/
ResultType?: 'simple' | 'entity_object';
ResultType?: 'simple' | 'entity_object' | 'count_only';
};

@@ -102,0 +102,0 @@ /**

{
"name": "@memberjunction/core",
"version": "1.2.2",
"version": "1.3.0",
"description": "MemberJunction: Core Library including Metadata, Application, Entity Retrieval and Manipulation, and Utilities",

@@ -22,4 +22,4 @@ "main": "dist/index.js",

"dependencies": {
"@memberjunction/global": "~1.2.2"
"@memberjunction/global": "~1.3.0"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc