@memberjunction/doc-utils 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ import { BaseEngine, UserInfo } from "@memberjunction/core";
2
+ import { LibraryEntity } from "@memberjunction/core-entities";
3
+ /**
4
+ * Represents a single item within a library/package that is used to provide documentation for the MemberJunction system. For example a library would be something like
5
+ * @memberjunction/core and an item within that library might be the BaseEntity or BaseEngine class.
6
+ */
7
+ export declare class LibraryItem {
8
+ Name: string;
9
+ URL: string;
10
+ HTMLContent: string;
11
+ Library: LibraryEntity;
12
+ }
13
+ export declare class LibraryEntityExtended extends LibraryEntity {
14
+ private _items;
15
+ get Items(): LibraryItem[];
16
+ }
17
+ /**
18
+ * Provides utility functionality for documentation of the MemberJunction system using external website content from the MemberJunction project.
19
+ */
20
+ export declare class DocumentationEngine extends BaseEngine<DocumentationEngine> {
21
+ private constructor();
22
+ static get Instance(): DocumentationEngine;
23
+ private _Libraries;
24
+ /**
25
+ * This method is called to configure the ActionEngine. It loads the metadata for the actions, filters, and result codes and caches them in the GlobalObjectStore. You must call this method before running any actions.
26
+ * If this method was previously run on the instance of the ActionEngine, it will return immediately without re-loading the metadata. If you want to force a reload of the metadata, you can pass true for the forceReload parameter.
27
+ * @param forceRefresh If true, the metadata will be loaded from the database even if it was previously loaded.
28
+ * @param contextUser If you are running the action on the server side you must pass this in, but it is not required in an environment where a user is authenticated directly, e.g. a browser or other client.
29
+ */
30
+ Config(forceRefresh?: boolean, contextUser?: UserInfo): Promise<void>;
31
+ private _baseURL;
32
+ protected AdditionalLoading(contextUser?: UserInfo): Promise<void>;
33
+ protected GetContent(url: string, rootSelector?: string): Promise<string>;
34
+ protected fetchDocumentation(url: string): Promise<string>;
35
+ protected parseDocumentation(html: string, rootSelector?: string): string;
36
+ /**
37
+ * List of all the Entity Action objects that are available for use in the system. Make sure you call Config() before any other methods on this class.
38
+ */
39
+ get Libraries(): LibraryE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Engine.js ADDED
@@ -0,0 +1,116 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DocumentationEngine = exports.LibraryEntityExtended = exports.LibraryItem = void 0;
13
+ const axios_1 = __importDefault(require("axios"));
14
+ const jsdom_1 = require("jsdom");
15
+ const core_1 = require("@memberjunction/core");
16
+ const core_entities_1 = require("@memberjunction/core-entities");
17
+ const global_1 = require("@memberjunction/global");
18
+ const typeorm_1 = require("typeorm");
19
+ /**
20
+ * Represents a single item within a library/package that is used to provide documentation for the MemberJunction system. For example a library would be something like
21
+ * @memberjunction/core and an item within that library might be the BaseEntity or BaseEngine class.
22
+ */
23
+ class LibraryItem {
24
+ }
25
+ exports.LibraryItem = LibraryItem;
26
+ let LibraryEntityExtended = class LibraryEntityExtended extends core_entities_1.LibraryEntity {
27
+ constructor() {
28
+ super(...arguments);
29
+ this._items = [];
30
+ }
31
+ get Items() {
32
+ return this._items;
33
+ }
34
+ };
35
+ exports.LibraryEntityExtended = LibraryEntityExtended;
36
+ exports.LibraryEntityExtended = LibraryEntityExtended = __decorate([
37
+ (0, global_1.RegisterClass)(typeorm_1.BaseEntity, "Libraries")
38
+ ], LibraryEntityExtended);
39
+ /**
40
+ * Provides utility functionality for documentation of the MemberJunction system using external website content from the MemberJunction project.
41
+ */
42
+ class DocumentationEngine extends core_1.BaseEngine {
43
+ constructor() {
44
+ super('MJ_Documentation_Metadata');
45
+ // internal instance properties used for the singleton pattern
46
+ this._Libraries = [];
47
+ this._baseURL = 'https://memberjunction.github.io/MJ/classes/';
48
+ }
49
+ static get Instance() {
50
+ return super.getInstance('MJ_Documentation_Metadata');
51
+ }
52
+ /**
53
+ * This method is called to configure the ActionEngine. It loads the metadata for the actions, filters, and result codes and caches them in the GlobalObjectStore. You must call this method before running any actions.
54
+ * If this method was previously run on the instance of the ActionEngine, it will return immediately without re-loading the metadata. If you want to force a reload of the metadata, you can pass true for the forceReload parameter.
55
+ * @param forceRefresh If true, the metadata will be loaded from the database even if it was previously loaded.
56
+ * @param contextUser If you are running the action on the server side you must pass this in, but it is not required in an environment where a user is authenticated directly, e.g. a browser or other client.
57
+ */
58
+ async Config(forceRefresh = false, contextUser) {
59
+ const configs = [
60
+ {
61
+ EntityName: 'Libraries',
62
+ PropertyName: '_Libraries'
63
+ },
64
+ ];
65
+ await this.Load(configs, forceRefresh, contextUser);
66
+ }
67
+ async AdditionalLoading(contextUser) {
68
+ // Load the items for each library using the comma delimited list of included items in the Library metadata
69
+ for (const library of this.Libraries) {
70
+ const items = library.ExportedItems.split(',').map(x => x.trim());
71
+ for (const item of items) {
72
+ const libraryItem = new LibraryItem();
73
+ // lib code name is replace all instances of @ . and / or \ in the library name with _
74
+ const codeName = library.Name.replace(/[@.\/\\]/g, '_');
75
+ libraryItem.Name = item;
76
+ libraryItem.URL = `${this._baseURL}${codeName}.${item}.html`;
77
+ libraryItem.HTMLContent = await this.GetContent(libraryItem.URL);
78
+ libraryItem.Library = library;
79
+ library.Items.push(libraryItem);
80
+ }
81
+ }
82
+ }
83
+ async GetContent(url, rootSelector) {
84
+ const html = await this.fetchDocumentation(url);
85
+ return this.parseDocumentation(html, rootSelector);
86
+ }
87
+ async fetchDocumentation(url) {
88
+ try {
89
+ const response = await axios_1.default.get(url);
90
+ if (response.status === 200) {
91
+ return response.data;
92
+ }
93
+ else {
94
+ return 'No content found';
95
+ }
96
+ }
97
+ catch (e) {
98
+ (0, core_1.LogError)(e);
99
+ return "Error fetching content";
100
+ }
101
+ }
102
+ parseDocumentation(html, rootSelector) {
103
+ const dom = new jsdom_1.JSDOM(html);
104
+ const document = dom.window.document;
105
+ const content = document.querySelector('div.col-content')?.innerHTML;
106
+ return content || 'No relevant content found';
107
+ }
108
+ /**
109
+ * List of all the Entity Action objects that are available for use in the system. Make sure you call Config() before any other methods on this class.
110
+ */
111
+ get Libraries() {
112
+ return this._Libraries;
113
+ }
114
+ }
115
+ exports.DocumentationEngine = DocumentationEngine;
116
+ //# sourceMappingURL=Engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Engine.js","sourceRoot":"","sources":["../src/Engine.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAA0B;AAC1B,iCAA8B;AAE9B,+CAAgG;AAChG,iEAA8D;AAC9D,mDAAuD;AACvD,qCAAqC;AAGrC;;;GAGG;AACH,MAAa,WAAW;CAKvB;AALD,kCAKC;AAGM,IAAM,qBAAqB,GAA3B,MAAM,qBAAsB,SAAQ,6BAAa;IAAjD;;QACK,WAAM,GAAkB,EAAE,CAAC;IAIvC,CAAC;IAHG,IAAW,KAAK;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;CACJ,CAAA;AALY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,sBAAa,EAAC,oBAAU,EAAE,WAAW,CAAC;GAC1B,qBAAqB,CAKjC;AAED;;GAEG;AACH,MAAa,mBAAoB,SAAQ,iBAA+B;IACpE;QACI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAQvC,8DAA8D;QACtD,eAAU,GAA4B,EAAE,CAAC;QAkBzC,aAAQ,GAAW,8CAA8C,CAAC;IA1B1E,CAAC;IAEM,MAAM,KAAK,QAAQ;QACtB,OAAO,KAAK,CAAC,WAAW,CAAsB,2BAA2B,CAAC,CAAC;IAC/E,CAAC;IAMD;;;;;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I,CAAC,kBAAkB,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IACvD,CAAC;IACS,KAAK,CAAC,kBAAkB,CAAC,GAAW;QAC1C,IAAI,CAAC;YACD,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACtC,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;gBAC1B,OAAO,QAAQ,CAAC,IAAI,CAAC;YACzB,CAAC;iBAAM,CAAC;gBACJ,OAAO,kBAAkB,CAAC;YAC9B,CAAC;QACL,CAAC;QACD,OAAO,CAAC,EAAE,CAAC;YACP,IAAA,eAAQ,EAAC,CAAC,CAAC,CAAA;YACX,OAAO,wBAAwB,CAAA;QACnC,CAAC;IACL,CAAC;IACU,kBAAkB,CAAC,IAAY,EAAE,YAAqB;QAC7D,MAAM,GAAG,GAAG,IAAI,aAAK,CAAC,IAAI,CAAC,CAAC;QAC5B,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC;QACrC,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,iBAAiB,CAAC,EAAE,SAAS,CAAC;QACrE,OAAO,OAAO,IAAI,2BAA2B,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;CACJ;AA9ED,kDA8EC"}
@@ -0,0 +1,2 @@
1
+ export * from './Engine';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ //PUBLIC API SURFACE AREA
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./Engine"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,yBAAyB;;;;;;;;;;;;;;;;AAEzB,2CAAyB"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@memberjunction/doc-utils",
3
+ "version": "1.4.1",
4
+ "description": "This library provides functionality for dynamically retreiving documentation from the official MemberJunction object model documentation site, parsing it, and caching elements in memory for performance. Use this whenever you need dynamic access to the MJ documentation to feed to AI models and for any other similar purpose.",
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
+ "ts-node-dev": "^2.0.0",
19
+ "typescript": "^5.3.3"
20
+ },
21
+ "dependencies": {
22
+ "@memberjunction/ai": "~1.4.1",
23
+ "@memberjunction/core": "~1.4.1",
24
+ "@memberjunction/actions": "~1.4.1",
25
+ "@memberjunction/core-entities": "~1.4.1",
26
+ "@memberjunction/global": "~1.4.1",
27
+ "@memberjunction/sqlserver-dataprovider": "~1.4.1",
28
+ "env-var": "^7.4.1",
29
+ "fs-extra": "^11.1.1",
30
+ "glob": "^10.3.10",
31
+ "typeorm": "^0.3.20",
32
+ "jsdom": "^24.1.0"
33
+ }
34
+ }