@flowdular/sdk 0.2.1 → 0.2.2
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.
- package/modules/auth/src/cli/index.ts +23 -16
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFile, readdir } from 'node:fs/promises';
|
|
2
|
-
import { join } from 'node:path';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
3
|
import { parse as parseYaml } from 'yaml';
|
|
4
4
|
import { defineCliExtension } from '@flowdular/sdk/cli-protocol';
|
|
5
5
|
import { AUTH_SCOPES, OWNER_SCOPES, PLATFORM_SCOPES } from '../acl/scopes.ts';
|
|
@@ -17,25 +17,31 @@ import {
|
|
|
17
17
|
|
|
18
18
|
/* Scopes are declared once, in the module specification. Reading them from
|
|
19
19
|
there keeps this command free of module code execution. */
|
|
20
|
-
async function declaredScopes(
|
|
20
|
+
export async function declaredScopes(
|
|
21
21
|
workspaceRoot: string,
|
|
22
22
|
moduleId: string,
|
|
23
|
+
moduleRoot = join(workspaceRoot, 'modules/auth'),
|
|
23
24
|
): Promise<{ readonly directory: string; readonly scopes: readonly string[] }> {
|
|
24
|
-
for (const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
for (const root of new Set([
|
|
26
|
+
join(workspaceRoot, 'modules'),
|
|
27
|
+
dirname(moduleRoot),
|
|
28
|
+
])) {
|
|
29
|
+
for (const entry of await readdir(root)) {
|
|
30
|
+
const specPath = join(root, entry, 'spec/module.yaml');
|
|
31
|
+
let spec: { id?: string; permissions?: { id?: string }[] };
|
|
32
|
+
try {
|
|
33
|
+
spec = parseYaml(await readFile(specPath, 'utf8')) as typeof spec;
|
|
34
|
+
} catch {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (spec.id !== moduleId) continue;
|
|
38
|
+
return {
|
|
39
|
+
directory: entry,
|
|
40
|
+
scopes: (spec.permissions ?? [])
|
|
41
|
+
.map((permission) => permission.id)
|
|
42
|
+
.filter((id): id is string => typeof id === 'string'),
|
|
43
|
+
};
|
|
31
44
|
}
|
|
32
|
-
if (spec.id !== moduleId) continue;
|
|
33
|
-
return {
|
|
34
|
-
directory: entry,
|
|
35
|
-
scopes: (spec.permissions ?? [])
|
|
36
|
-
.map((permission) => permission.id)
|
|
37
|
-
.filter((id): id is string => typeof id === 'string'),
|
|
38
|
-
};
|
|
39
45
|
}
|
|
40
46
|
throw new Error(`No enabled module declares the id "${moduleId}".`);
|
|
41
47
|
}
|
|
@@ -84,6 +90,7 @@ export const cliExtension = defineCliExtension({
|
|
|
84
90
|
const declared = await declaredScopes(
|
|
85
91
|
context.workspaceRoot,
|
|
86
92
|
moduleId.trim(),
|
|
93
|
+
context.moduleRoot,
|
|
87
94
|
);
|
|
88
95
|
const local = localDatabaseProvider(context.workspaceRoot);
|
|
89
96
|
const databases = local.create();
|