@openinc/parse-server-opendash 4.28.0 → 4.29.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.
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Gives every source without a tag one — a Parse Dashboard job, run from
3
+ * Jobs → "Schedule a job", then "Run now" on the scheduled entry.
4
+ *
5
+ * Some instances have `OD3_Source` rows whose `tag` was never set. The job sets
6
+ * it to `tenant-<tenant id>-<source id>`, which is unique by construction, so
7
+ * the duplicate check in `hooks/Source.ts` never has anything to object to.
8
+ *
9
+ * Saved with the master key, so the tag permission checks in that hook pass,
10
+ * and its afterSave creates the `AccessPermissions` row a tagged source gets —
11
+ * exactly as if the tag had been entered by hand.
12
+ *
13
+ * A source that already has a tag is left alone, so the job is safe to repeat.
14
+ * A source without a tenant is skipped and its id logged: there is nothing to
15
+ * build the tag from.
16
+ *
17
+ * Parameters (optional): `{"dryRun": true}` only counts what would change.
18
+ *
19
+ * @param name The job name, derived from the file name.
20
+ */
21
+ export declare function init(name: string): Promise<void>;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.init = init;
7
+ const node_1 = __importDefault(require("parse/node"));
8
+ const index_js_1 = require("../types/index.js");
9
+ /**
10
+ * Gives every source without a tag one — a Parse Dashboard job, run from
11
+ * Jobs → "Schedule a job", then "Run now" on the scheduled entry.
12
+ *
13
+ * Some instances have `OD3_Source` rows whose `tag` was never set. The job sets
14
+ * it to `tenant-<tenant id>-<source id>`, which is unique by construction, so
15
+ * the duplicate check in `hooks/Source.ts` never has anything to object to.
16
+ *
17
+ * Saved with the master key, so the tag permission checks in that hook pass,
18
+ * and its afterSave creates the `AccessPermissions` row a tagged source gets —
19
+ * exactly as if the tag had been entered by hand.
20
+ *
21
+ * A source that already has a tag is left alone, so the job is safe to repeat.
22
+ * A source without a tenant is skipped and its id logged: there is nothing to
23
+ * build the tag from.
24
+ *
25
+ * Parameters (optional): `{"dryRun": true}` only counts what would change.
26
+ *
27
+ * @param name The job name, derived from the file name.
28
+ */
29
+ async function init(name) {
30
+ node_1.default.Cloud.job(name, async function (request) {
31
+ // "Run now" in the dashboard posts the schedule's parameters as `input`,
32
+ // next to its own bookkeeping fields; a direct `POST /jobs/<name>` sends
33
+ // them as the body itself.
34
+ const params = request.params.input ?? request.params;
35
+ const dryRun = params?.dryRun === true;
36
+ const verb = dryRun ? "would be tagged" : "tagged";
37
+ let checked = 0;
38
+ let tagged = 0;
39
+ const withoutTenant = [];
40
+ const failed = [];
41
+ await new node_1.default.Query(index_js_1.Source).each(async (source) => {
42
+ checked++;
43
+ // An empty string counts as missing too — the Source hooks treat it
44
+ // the same way.
45
+ if (source.get("tag"))
46
+ return;
47
+ const tenant = source.get("tenant");
48
+ if (!tenant?.id) {
49
+ withoutTenant.push(source.id);
50
+ return;
51
+ }
52
+ if (!dryRun) {
53
+ try {
54
+ source.set("tag", `tenant-${tenant.id}-${source.id}`);
55
+ await source.save(null, { useMasterKey: true });
56
+ }
57
+ catch (error) {
58
+ // One bad row must not stop the rest; it is reported at the end.
59
+ failed.push(source.id);
60
+ console.error(`[@openinc/parse-server-opendash][${name}] Could not tag source ${source.id}:`, error);
61
+ return;
62
+ }
63
+ }
64
+ tagged++;
65
+ if (tagged % 100 === 0) {
66
+ request.message(`${tagged} sources ${verb} so far…`);
67
+ }
68
+ }, { useMasterKey: true });
69
+ if (withoutTenant.length > 0) {
70
+ console.warn(`[@openinc/parse-server-opendash][${name}] Sources without tag and tenant, skipped: ${withoutTenant.join(", ")}`);
71
+ }
72
+ const summary = `${dryRun ? "Dry run — nothing saved. " : ""}` +
73
+ `${checked} sources checked, ` +
74
+ `${tagged} ${verb}, ` +
75
+ `${withoutTenant.length} skipped without tenant, ` +
76
+ `${failed.length} failed.`;
77
+ console.log(`[@openinc/parse-server-opendash][${name}] ${summary}`);
78
+ // Thrown so the job status reads "failed" in the dashboard; the message of
79
+ // a native Error ends up in the status row just like a returned string.
80
+ if (failed.length > 0) {
81
+ throw new Error(`${summary} Failed ids: ${failed.join(", ")}`);
82
+ }
83
+ return summary;
84
+ });
85
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "4.28.0",
3
+ "version": "4.29.0",
4
4
  "description": "Parse Server Cloud Code for open.INC Stack.",
5
5
  "packageManager": "pnpm@12.8.1",
6
6
  "keywords": [