@openinc/parse-server-opendash 3.22.0 → 3.23.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.
@@ -1,4 +1,4 @@
1
- import { _User, Tenant } from "../../../types";
1
+ import { _User, Tenant, Assets } from "../../../types";
2
2
  import { DocumentationStructure } from "../types";
3
3
  /**
4
4
  * Service for cleaning up old documentation that no longer exists in the repository
@@ -11,6 +11,7 @@ export declare class DocumentationCleanup {
11
11
  deletedDocuments: number;
12
12
  deletedCategories: number;
13
13
  }>;
14
+ static findExistingAssets(user: _User | undefined, tenant: Tenant | undefined): Promise<Assets[]>;
14
15
  /**
15
16
  * Collect all git paths from the documentation structure
16
17
  */
@@ -18,6 +18,7 @@ class DocumentationCleanup {
18
18
  // Find all existing default documentation for this user/tenant
19
19
  const existingDocuments = await this.findExistingDefaultDocuments(user, tenant);
20
20
  const existingCategories = await this.findExistingDefaultCategories(user, tenant);
21
+ const existingAssets = await this.findExistingAssets(user, tenant);
21
22
  console.log(`[DocumentationCleanup] Found ${existingDocuments.length} existing documents and ${existingCategories.length} existing categories`);
22
23
  // Identify documents to delete
23
24
  const documentsToDelete = existingDocuments.filter((doc) => {
@@ -60,9 +61,41 @@ class DocumentationCleanup {
60
61
  console.error(`[DocumentationCleanup] Failed to delete category ${cat.id}:`, error);
61
62
  }
62
63
  }
64
+ // delete old assets
65
+ let deletedAssets = 0;
66
+ for (const asset of existingAssets) {
67
+ const meta = asset.get("meta") || {};
68
+ if (meta.importedByDocumentation) {
69
+ try {
70
+ console.log(`[DocumentationCleanup] Deleting asset: ${asset.get("description")} (id: ${asset.id})`);
71
+ await asset.destroy({ useMasterKey: true });
72
+ deletedAssets++;
73
+ }
74
+ catch (error) {
75
+ console.error(`[DocumentationCleanup] Failed to delete asset ${asset.id}:`, error);
76
+ }
77
+ }
78
+ }
79
+ if (deletedAssets > 0) {
80
+ console.log(`[DocumentationCleanup] Deleted ${deletedAssets} old assets imported by documentation`);
81
+ }
63
82
  console.log(`[DocumentationCleanup] Cleanup complete: deleted ${deletedDocuments} documents and ${deletedCategories} categories`);
64
83
  return { deletedDocuments, deletedCategories };
65
84
  }
85
+ static async findExistingAssets(user, tenant) {
86
+ const query = new Parse.Query(types_1.Assets);
87
+ if (tenant) {
88
+ query.equalTo("tenant", tenant);
89
+ }
90
+ if (user) {
91
+ query.equalTo("user", user);
92
+ }
93
+ const assets = await query
94
+ // @ts-expect-error
95
+ .exists("meta.importedByDocumentation")
96
+ .findAll({ useMasterKey: true });
97
+ return assets;
98
+ }
66
99
  /**
67
100
  * Collect all git paths from the documentation structure
68
101
  */
@@ -1,5 +1,8 @@
1
1
  import { _User, Tenant } from "../../../types";
2
2
  import { DocumentationFile } from "../types";
3
+ /**
4
+ * Service to resolve and upload linked local files/images in documentation content
5
+ */
3
6
  export declare class LinkResolver {
4
7
  private gitHubClient;
5
8
  private files;
@@ -7,6 +7,9 @@ exports.LinkResolver = void 0;
7
7
  const types_1 = require("../../../types");
8
8
  const GitHubClient_1 = require("./GitHubClient");
9
9
  const path_1 = __importDefault(require("path"));
10
+ /**
11
+ * Service to resolve and upload linked local files/images in documentation content
12
+ */
10
13
  class LinkResolver {
11
14
  constructor(gitHubToken, files = []) {
12
15
  this.files = [];
@@ -63,6 +66,9 @@ class LinkResolver {
63
66
  tenant,
64
67
  user,
65
68
  description: fileName,
69
+ meta: {
70
+ importedByDocumentation: true,
71
+ },
66
72
  });
67
73
  const savedAsset = await asset.save(null, { useMasterKey: true });
68
74
  const newURL = savedAsset.file?.url() || "";
@@ -27,7 +27,11 @@ async function init() {
27
27
  if (!object.get("tagPrefix"))
28
28
  object.set("tagPrefix", `tenant-${object.id}-`);
29
29
  }
30
- // Handle Data Source
30
+ }
31
+ });
32
+ (0, __1.afterSaveHook)(types_1.Tenant, async ({ object, original, user }) => {
33
+ // Handle Data Source
34
+ if (object.id && !original?.get("dataSource")) {
31
35
  const rootSource = await new Parse.Query(types_1.Source)
32
36
  .equalTo("tag", "tenant-root-source")
33
37
  .first({ useMasterKey: true });
@@ -49,9 +53,8 @@ async function init() {
49
53
  dataSource.set("tenant", object);
50
54
  await dataSource.save(null, { useMasterKey: true });
51
55
  object.set("dataSource", dataSource);
56
+ await object.save(null, { useMasterKey: true });
52
57
  }
53
- });
54
- (0, __1.afterSaveHook)(types_1.Tenant, async ({ object, original, user }) => {
55
58
  await (0, __1.ensureRole)(`od-tenant-admin-${object.id}`, {
56
59
  label: `${object.get("label")} (Admin)`,
57
60
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "3.22.0",
3
+ "version": "3.23.1",
4
4
  "description": "Parse Server Cloud Code for open.INC Stack.",
5
5
  "packageManager": "pnpm@10.15.0",
6
6
  "keywords": [