@memberjunction/templates-base-types 1.5.3

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.
@@ -0,0 +1,28 @@
1
+ import { ValidationResult } from "@memberjunction/core";
2
+ import { TemplateContentEntity, TemplateEntity, TemplateParamEntity } from "@memberjunction/core-entities";
3
+ export declare class TemplateEntityExtended extends TemplateEntity {
4
+ private _Content;
5
+ get Content(): TemplateContentEntity[];
6
+ set Content(value: TemplateContentEntity[]);
7
+ private _Params;
8
+ get Params(): TemplateParamEntity[];
9
+ set Params(value: TemplateParamEntity[]);
10
+ /**
11
+ * Returns all content for a given type for the template
12
+ * @param type
13
+ * @returns
14
+ */
15
+ GetContentByType(type: string): TemplateContentEntity[];
16
+ /**
17
+ * Returns the highest priority content for the template
18
+ * @param type If provided, returns the highest priority content of the specified type
19
+ * @returns
20
+ */
21
+ GetHighestPriorityContent(type?: string): TemplateContentEntity;
22
+ /**
23
+ * This method is different from the Validate() method which validates the state of the Template itself. This method validates the data object provided meets the requirements for the template's parameter definitions.
24
+ * @param data - the data object to validate against the template's parameter definitions
25
+ */
26
+ ValidateTemplateInput(data: any): ValidationResult;
27
+ }
28
+ //# sourceMappingURL=TemplateEntityExtended.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TemplateEntityExtended.d.ts","sourceRoot":"","sources":["../src/TemplateEntityExtended.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACvF,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAG3G,qBACa,sBAAuB,SAAQ,cAAc;IACtD,OAAO,CAAC,QAAQ,CAA+B;IAC/C,IAAW,OAAO,IAAI,qBAAqB,EAAE,CAE5C;IACD,IAAW,OAAO,CAAC,KAAK,EAAE,qBAAqB,EAAE,EAEhD;IAED,OAAO,CAAC,OAAO,CAA6B;IAC5C,IAAW,MAAM,IAAI,mBAAmB,EAAE,CAEzC;IACD,IAAW,MAAM,CAAC,KAAK,EAAE,mBAAmB,EAAE,EAE7C;IAED;;;;OAIG;IACI,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB,EAAE;IAI9D;;;;OAIG;IACI,yBAAyB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,qBAAqB;IAUtE;;;OAGG;IACI,qBAAqB,CAAC,IAAI,EAAE,GAAG,GAAG,gBAAgB;CAoB5D"}
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.TemplateEntityExtended = void 0;
10
+ const core_1 = require("@memberjunction/core");
11
+ const core_entities_1 = require("@memberjunction/core-entities");
12
+ const global_1 = require("@memberjunction/global");
13
+ let TemplateEntityExtended = class TemplateEntityExtended extends core_entities_1.TemplateEntity {
14
+ constructor() {
15
+ super(...arguments);
16
+ this._Content = [];
17
+ this._Params = [];
18
+ }
19
+ get Content() {
20
+ return this._Content;
21
+ }
22
+ set Content(value) {
23
+ this._Content = value;
24
+ }
25
+ get Params() {
26
+ return this._Params;
27
+ }
28
+ set Params(value) {
29
+ this._Params = value;
30
+ }
31
+ /**
32
+ * Returns all content for a given type for the template
33
+ * @param type
34
+ * @returns
35
+ */
36
+ GetContentByType(type) {
37
+ return this.Content.filter(c => c.Type.trim().toLowerCase() === type.trim().toLowerCase());
38
+ }
39
+ /**
40
+ * Returns the highest priority content for the template
41
+ * @param type If provided, returns the highest priority content of the specified type
42
+ * @returns
43
+ */
44
+ GetHighestPriorityContent(type) {
45
+ if (type) {
46
+ return this.Content.filter(c => c.Type.trim().toLowerCase() === type.trim().toLowerCase())
47
+ .sort((a, b) => a.Priority - b.Priority)[0];
48
+ }
49
+ else {
50
+ return this.Content.sort((a, b) => a.Priority - b.Priority)[0];
51
+ }
52
+ }
53
+ /**
54
+ * This method is different from the Validate() method which validates the state of the Template itself. This method validates the data object provided meets the requirements for the template's parameter definitions.
55
+ * @param data - the data object to validate against the template's parameter definitions
56
+ */
57
+ ValidateTemplateInput(data) {
58
+ const result = new core_1.ValidationResult();
59
+ this.Params.forEach((p) => {
60
+ if (p.IsRequired) {
61
+ if (!data ||
62
+ data[p.Name] === undefined ||
63
+ data[p.Name] === null ||
64
+ (typeof data[p.Name] === 'string' && data[p.Name].toString().trim() === ''))
65
+ result.Errors.push({
66
+ Source: p.Name,
67
+ Message: `Parameter ${p.Name} is required.`,
68
+ Value: data[p.Name],
69
+ Type: 'Failure'
70
+ });
71
+ }
72
+ });
73
+ // now set result's top level success falg based on the existence of ANY failure record within the errors collection
74
+ result.Success = result.Errors.some(e => e.Type === 'Failure') ? false : true;
75
+ return result;
76
+ }
77
+ };
78
+ exports.TemplateEntityExtended = TemplateEntityExtended;
79
+ exports.TemplateEntityExtended = TemplateEntityExtended = __decorate([
80
+ (0, global_1.RegisterClass)(core_1.BaseEntity, 'Templates')
81
+ ], TemplateEntityExtended);
82
+ //# sourceMappingURL=TemplateEntityExtended.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TemplateEntityExtended.js","sourceRoot":"","sources":["../src/TemplateEntityExtended.ts"],"names":[],"mappings":";;;;;;;;;AAAA,+CAAuF;AACvF,iEAA2G;AAC3G,mDAAuD;AAGhD,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,8BAAc;IAAnD;;QACK,aAAQ,GAA4B,EAAE,CAAC;QAQvC,YAAO,GAA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,IAAI,uBAAgB,EAAE,CAAC;QACtC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YACtB,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;gBACf,IAAI,CAAC,IAAI;oBACL,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,SAAS;oBAC1B,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI;oBACrB,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;oBAC3E,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;wBACf,MAAM,EAAE,CAAC,CAAC,IAAI;wBACd,OAAO,EAAE,aAAa,CAAC,CAAC,IAAI,eAAe;wBAC3C,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;wBACnB,IAAI,EAAE,SAAS;qBAClB,CAAC,CAAC;YACX,CAAC;QACL,CAAC,CAAC,CAAC;QACH,oHAAoH;QACpH,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;QAC9E,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ,CAAA;AAjEY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,sBAAa,EAAC,iBAAU,EAAE,WAAW,CAAC;GAC1B,sBAAsB,CAiElC"}
@@ -0,0 +1,3 @@
1
+ export * from './TemplateEntityExtended';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./TemplateEntityExtended"), exports);
18
+ __exportStar(require("./types"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,0CAAwB"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Contains the results of a call to render a template
3
+ */
4
+ export declare class TemplateRenderResult {
5
+ Success: boolean;
6
+ Output: string;
7
+ /**
8
+ * Optional, typically used only for Success=false
9
+ */
10
+ Message?: string;
11
+ }
12
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,oBAAoB;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB"}
package/dist/types.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TemplateRenderResult = void 0;
4
+ /**
5
+ * Contains the results of a call to render a template
6
+ */
7
+ class TemplateRenderResult {
8
+ }
9
+ exports.TemplateRenderResult = TemplateRenderResult;
10
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,oBAAoB;CAOhC;AAPD,oDAOC"}
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@memberjunction/templates-base-types",
3
+ "version": "1.5.3",
4
+ "description": "MemberJunction Templating Base Types for Client/Server Use",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "/dist"
9
+ ],
10
+ "scripts": {
11
+ "start": "ts-node-dev src/index.ts",
12
+ "build": "tsc",
13
+ "test": "echo \"Error: no test specified\" && exit 1"
14
+ },
15
+ "author": "MemberJunction.com",
16
+ "license": "ISC",
17
+ "devDependencies": {
18
+ "typescript": "^5.4.5"
19
+ },
20
+ "dependencies": {
21
+ "@memberjunction/core": "1.5.3",
22
+ "@memberjunction/core-entities": "1.5.3",
23
+ "@memberjunction/global": "1.5.3"
24
+ }
25
+ }