@knpkv/atlassian-common 0.2.0 → 0.4.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.
- package/CHANGELOG.md +31 -0
- package/README.md +25 -10
- package/dist/Brand.d.ts +15 -15
- package/dist/Brand.d.ts.map +1 -1
- package/dist/Brand.js +5 -5
- package/dist/Brand.js.map +1 -1
- package/dist/Hash.d.ts +12 -14
- package/dist/Hash.d.ts.map +1 -1
- package/dist/Hash.js +18 -24
- package/dist/Hash.js.map +1 -1
- package/dist/ast/BlockNode.d.ts +120 -177
- package/dist/ast/BlockNode.d.ts.map +1 -1
- package/dist/ast/BlockNode.js +28 -8
- package/dist/ast/BlockNode.js.map +1 -1
- package/dist/ast/Document.d.ts +114 -156
- package/dist/ast/Document.d.ts.map +1 -1
- package/dist/ast/Document.js +1 -1
- package/dist/ast/Document.js.map +1 -1
- package/dist/ast/InlineNode.d.ts +59 -247
- package/dist/ast/InlineNode.d.ts.map +1 -1
- package/dist/ast/InlineNode.js +28 -3
- package/dist/ast/InlineNode.js.map +1 -1
- package/dist/ast/MacroNode.d.ts +62 -102
- package/dist/ast/MacroNode.d.ts.map +1 -1
- package/dist/ast/MacroNode.js +12 -5
- package/dist/ast/MacroNode.js.map +1 -1
- package/dist/auth/OAuthOperations.d.ts +1 -1
- package/dist/auth/OAuthOperations.d.ts.map +1 -1
- package/dist/auth/OAuthOperations.js +5 -6
- package/dist/auth/OAuthOperations.js.map +1 -1
- package/dist/auth/OAuthResponseSchemas.d.ts +13 -13
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +58 -0
- package/dist/bin.js.map +1 -0
- package/dist/config/AuthProfiles.d.ts +342 -0
- package/dist/config/AuthProfiles.d.ts.map +1 -0
- package/dist/config/AuthProfiles.js +275 -0
- package/dist/config/AuthProfiles.js.map +1 -0
- package/dist/config/ConfigPaths.d.ts +12 -26
- package/dist/config/ConfigPaths.d.ts.map +1 -1
- package/dist/config/ConfigPaths.js +33 -3
- package/dist/config/ConfigPaths.js.map +1 -1
- package/dist/config/OAuthSchemas.d.ts +24 -24
- package/dist/config/ProfileManager.d.ts +92 -0
- package/dist/config/ProfileManager.d.ts.map +1 -0
- package/dist/config/ProfileManager.js +175 -0
- package/dist/config/ProfileManager.js.map +1 -0
- package/dist/config/TokenStorage.d.ts +5 -24
- package/dist/config/TokenStorage.d.ts.map +1 -1
- package/dist/config/TokenStorage.js +35 -22
- package/dist/config/TokenStorage.js.map +1 -1
- package/dist/config/index.d.ts +3 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +5 -1
- package/dist/config/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +17 -11
- package/src/Brand.ts +5 -17
- package/src/Hash.ts +27 -27
- package/src/ast/BlockNode.ts +13 -13
- package/src/ast/Document.ts +1 -1
- package/src/ast/InlineNode.ts +5 -5
- package/src/ast/MacroNode.ts +7 -6
- package/src/auth/OAuthOperations.ts +5 -6
- package/src/bin.ts +115 -0
- package/src/config/AuthProfiles.ts +384 -0
- package/src/config/ConfigPaths.ts +21 -7
- package/src/config/ProfileManager.ts +268 -0
- package/src/config/TokenStorage.ts +23 -27
- package/src/config/index.ts +42 -0
- package/src/index.ts +1 -1
- package/test/AuthProfiles.test.ts +131 -0
- package/test/Hash.test.ts +52 -0
- package/test/OAuthOperations.test.ts +2 -3
- package/test/ProfileManager.test.ts +188 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,10 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Persistent token and OAuth config storage with schema validation and secure file I/O.
|
|
3
|
+
*
|
|
4
|
+
* **Mental model**
|
|
5
|
+
*
|
|
6
|
+
* - **Load returns null, not error**: {@link loadToken} and {@link loadOAuthConfig} return
|
|
7
|
+
* `null` for missing/corrupt files — callers decide whether absence is an error.
|
|
8
|
+
* - **Save is atomic**: Writes go through {@link writeSecureFile} with `0o600` permissions.
|
|
9
|
+
* - **Schema-gated reads**: JSON is parsed then validated via `Schema.decodeUnknownEffect` —
|
|
10
|
+
* corrupt data is treated as absent rather than crashing.
|
|
11
|
+
*
|
|
12
|
+
* **Common tasks**
|
|
13
|
+
*
|
|
14
|
+
* - Load stored token: {@link loadToken}
|
|
15
|
+
* - Persist after refresh: {@link saveToken}
|
|
16
|
+
* - Check expiration: {@link isTokenExpired}
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
2
20
|
import * as Data from "effect/Data";
|
|
3
21
|
import * as Effect from "effect/Effect";
|
|
22
|
+
import * as FileSystem from "effect/FileSystem";
|
|
4
23
|
import * as Schema from "effect/Schema";
|
|
5
24
|
import {} from "./ConfigPaths.js";
|
|
6
25
|
import { ensureConfigDir, getAuthPath, getOAuthConfigPath, writeSecureFile } from "./ConfigPaths.js";
|
|
7
26
|
import { OAuthConfigSchema, OAuthTokenSchema } from "./OAuthSchemas.js";
|
|
27
|
+
const parseJsonOrNull = (content) => {
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(content);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
8
35
|
/**
|
|
9
36
|
* Error during file system operations.
|
|
10
37
|
*
|
|
@@ -26,24 +53,17 @@ export class FileSystemError extends Data.TaggedError("FileSystemError") {
|
|
|
26
53
|
export const loadToken = (toolName) => Effect.gen(function* () {
|
|
27
54
|
const fs = yield* FileSystem.FileSystem;
|
|
28
55
|
const tokenPath = yield* getAuthPath(toolName);
|
|
29
|
-
const exists = yield* fs.exists(tokenPath).pipe(Effect.
|
|
56
|
+
const exists = yield* fs.exists(tokenPath).pipe(Effect.catchCause(() => Effect.succeed(false)));
|
|
30
57
|
if (!exists) {
|
|
31
58
|
return null;
|
|
32
59
|
}
|
|
33
60
|
const content = yield* fs.readFileString(tokenPath).pipe(Effect.mapError((cause) => new FileSystemError({ operation: "read", path: tokenPath, cause })));
|
|
34
|
-
const parsed = yield* Effect.sync(() =>
|
|
35
|
-
try {
|
|
36
|
-
return JSON.parse(content);
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
61
|
+
const parsed = yield* Effect.sync(() => parseJsonOrNull(content));
|
|
42
62
|
if (parsed === null) {
|
|
43
63
|
yield* Effect.logWarning(`Corrupted auth.json at ${tokenPath} — could not parse JSON`);
|
|
44
64
|
return null;
|
|
45
65
|
}
|
|
46
|
-
return yield* Schema.
|
|
66
|
+
return yield* Schema.decodeUnknownEffect(OAuthTokenSchema)(parsed).pipe(Effect.catchCause((e) => Effect.logWarning(`Invalid token schema in ${tokenPath}: ${e}`).pipe(Effect.map(() => null))));
|
|
47
67
|
});
|
|
48
68
|
/**
|
|
49
69
|
* Save OAuth token to disk with secure permissions.
|
|
@@ -69,7 +89,7 @@ export const saveToken = (toolName, token) => Effect.gen(function* () {
|
|
|
69
89
|
export const deleteToken = (toolName) => Effect.gen(function* () {
|
|
70
90
|
const fs = yield* FileSystem.FileSystem;
|
|
71
91
|
const tokenPath = yield* getAuthPath(toolName);
|
|
72
|
-
yield* fs.remove(tokenPath).pipe(Effect.
|
|
92
|
+
yield* fs.remove(tokenPath).pipe(Effect.catchCause(() => Effect.void));
|
|
73
93
|
});
|
|
74
94
|
/**
|
|
75
95
|
* Load OAuth client configuration from disk.
|
|
@@ -82,24 +102,17 @@ export const deleteToken = (toolName) => Effect.gen(function* () {
|
|
|
82
102
|
export const loadOAuthConfig = (toolName) => Effect.gen(function* () {
|
|
83
103
|
const fs = yield* FileSystem.FileSystem;
|
|
84
104
|
const configPath = yield* getOAuthConfigPath(toolName);
|
|
85
|
-
const exists = yield* fs.exists(configPath).pipe(Effect.
|
|
105
|
+
const exists = yield* fs.exists(configPath).pipe(Effect.catchCause(() => Effect.succeed(false)));
|
|
86
106
|
if (!exists) {
|
|
87
107
|
return null;
|
|
88
108
|
}
|
|
89
109
|
const content = yield* fs.readFileString(configPath).pipe(Effect.mapError((cause) => new FileSystemError({ operation: "read", path: configPath, cause })));
|
|
90
|
-
const parsed = yield* Effect.sync(() =>
|
|
91
|
-
try {
|
|
92
|
-
return JSON.parse(content);
|
|
93
|
-
}
|
|
94
|
-
catch {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
});
|
|
110
|
+
const parsed = yield* Effect.sync(() => parseJsonOrNull(content));
|
|
98
111
|
if (parsed === null) {
|
|
99
112
|
yield* Effect.logWarning(`Corrupted oauth config at ${configPath} — could not parse JSON`);
|
|
100
113
|
return null;
|
|
101
114
|
}
|
|
102
|
-
return yield* Schema.
|
|
115
|
+
return yield* Schema.decodeUnknownEffect(OAuthConfigSchema)(parsed).pipe(Effect.catchCause((e) => Effect.logWarning(`Invalid OAuth config schema in ${configPath}: ${e}`).pipe(Effect.map(() => null))));
|
|
103
116
|
});
|
|
104
117
|
/**
|
|
105
118
|
* Save OAuth client configuration to disk with secure permissions.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenStorage.js","sourceRoot":"","sources":["../../src/config/TokenStorage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TokenStorage.js","sourceRoot":"","sources":["../../src/config/TokenStorage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AACnC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAG/C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAkD,MAAM,kBAAkB,CAAA;AACjF,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACpG,OAAO,EAAoB,iBAAiB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AAG,IAAI,EAAW,EAAE,CAC7F,IAAI,CAAC,GAAG,EAAE,IAAI,KAAK,CAAC,UAAU,GAAG,QAAQ,CAAA"}
|
package/dist/config/index.d.ts
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
export { ensureConfigDir, getAuthPath, getConfigDir, getOAuthConfigPath, type HomeDirectory, HomeDirectoryError, HomeDirectoryLive, HomeDirectoryTag, writeSecureFile } from "./ConfigPaths.js";
|
|
6
|
+
export { ensureConfigDir, getAuthPath, getConfigDir, getOAuthConfigPath, getProfilesPath, type HomeDirectory, HomeDirectoryError, HomeDirectoryLive, HomeDirectoryTag, writeSecureFile } from "./ConfigPaths.js";
|
|
7
7
|
export { type AtlassianSite, AtlassianSiteSchema, type AtlassianUser, AtlassianUserSchema, type OAuthConfig, OAuthConfigSchema, type OAuthToken, OAuthTokenSchema, type OAuthUser, OAuthUserSchema } from "./OAuthSchemas.js";
|
|
8
8
|
export { deleteToken, FileSystemError, isTokenExpired, loadOAuthConfig, loadToken, saveOAuthConfig, saveToken } from "./TokenStorage.js";
|
|
9
|
+
export { type AuthProfile, AuthProfileSchema, type AuthProfilesFile, AuthProfilesFileSchema, deleteActiveProfile, deleteProfile, deleteProfileBySelector, findProfile, loadActiveProfile, loadActiveProfileToken, loadProfiles, profileFromToken, profileIdFromToken, profileNameFromToken, saveProfiles, saveProfileToken, setActiveProfile, setActiveProfileBySelector } from "./AuthProfiles.js";
|
|
10
|
+
export { ATLASSIAN_TOOLS, type AtlassianToolDefinition, CONFLUENCE_REQUIRED_SCOPES, inspectAllToolProfiles, inspectToolProfiles, JIRA_REQUIRED_SCOPES, migrateLegacyProfiles, MissingOAuthConfigError, missingScopes, ProfileNotFoundError, type ProfileTokenStatus, refreshActiveProfiles, tokenScopes, type ToolProfileStatus, useProfileForAllTools } from "./ProfileManager.js";
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,eAAe,EACf,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,KAAK,aAAa,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EAChB,MAAM,kBAAkB,CAAA;AAGzB,OAAO,EACL,KAAK,aAAa,EAClB,mBAAmB,EACnB,KAAK,aAAa,EAClB,mBAAmB,EACnB,KAAK,WAAW,EAChB,iBAAiB,EACjB,KAAK,UAAU,EACf,gBAAgB,EAChB,KAAK,SAAS,EACd,eAAe,EAChB,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EACL,WAAW,EACX,eAAe,EACf,cAAc,EACd,eAAe,EACf,SAAS,EACT,eAAe,EACf,SAAS,EACV,MAAM,mBAAmB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,eAAe,EACf,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,KAAK,aAAa,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EAChB,MAAM,kBAAkB,CAAA;AAGzB,OAAO,EACL,KAAK,aAAa,EAClB,mBAAmB,EACnB,KAAK,aAAa,EAClB,mBAAmB,EACnB,KAAK,WAAW,EAChB,iBAAiB,EACjB,KAAK,UAAU,EACf,gBAAgB,EAChB,KAAK,SAAS,EACd,eAAe,EAChB,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EACL,WAAW,EACX,eAAe,EACf,cAAc,EACd,eAAe,EACf,SAAS,EACT,eAAe,EACf,SAAS,EACV,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EACL,KAAK,WAAW,EAChB,iBAAiB,EACjB,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,aAAa,EACb,uBAAuB,EACvB,WAAW,EACX,iBAAiB,EACjB,sBAAsB,EACtB,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,0BAA0B,EAC3B,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EACL,eAAe,EACf,KAAK,uBAAuB,EAC5B,0BAA0B,EAC1B,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,aAAa,EACb,oBAAoB,EACpB,KAAK,kBAAkB,EACvB,qBAAqB,EACrB,WAAW,EACX,KAAK,iBAAiB,EACtB,qBAAqB,EACtB,MAAM,qBAAqB,CAAA"}
|
package/dist/config/index.js
CHANGED
|
@@ -4,9 +4,13 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
// Config paths
|
|
7
|
-
export { ensureConfigDir, getAuthPath, getConfigDir, getOAuthConfigPath, HomeDirectoryError, HomeDirectoryLive, HomeDirectoryTag, writeSecureFile } from "./ConfigPaths.js";
|
|
7
|
+
export { ensureConfigDir, getAuthPath, getConfigDir, getOAuthConfigPath, getProfilesPath, HomeDirectoryError, HomeDirectoryLive, HomeDirectoryTag, writeSecureFile } from "./ConfigPaths.js";
|
|
8
8
|
// OAuth schemas
|
|
9
9
|
export { AtlassianSiteSchema, AtlassianUserSchema, OAuthConfigSchema, OAuthTokenSchema, OAuthUserSchema } from "./OAuthSchemas.js";
|
|
10
10
|
// Token storage
|
|
11
11
|
export { deleteToken, FileSystemError, isTokenExpired, loadOAuthConfig, loadToken, saveOAuthConfig, saveToken } from "./TokenStorage.js";
|
|
12
|
+
// Auth profiles
|
|
13
|
+
export { AuthProfileSchema, AuthProfilesFileSchema, deleteActiveProfile, deleteProfile, deleteProfileBySelector, findProfile, loadActiveProfile, loadActiveProfileToken, loadProfiles, profileFromToken, profileIdFromToken, profileNameFromToken, saveProfiles, saveProfileToken, setActiveProfile, setActiveProfileBySelector } from "./AuthProfiles.js";
|
|
14
|
+
// Unified profile manager
|
|
15
|
+
export { ATLASSIAN_TOOLS, CONFLUENCE_REQUIRED_SCOPES, inspectAllToolProfiles, inspectToolProfiles, JIRA_REQUIRED_SCOPES, migrateLegacyProfiles, MissingOAuthConfigError, missingScopes, ProfileNotFoundError, refreshActiveProfiles, tokenScopes, useProfileForAllTools } from "./ProfileManager.js";
|
|
12
16
|
//# sourceMappingURL=index.js.map
|
package/dist/config/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAe;AACf,OAAO,EACL,eAAe,EACf,WAAW,EACX,YAAY,EACZ,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAe;AACf,OAAO,EACL,eAAe,EACf,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,eAAe,EAEf,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EAChB,MAAM,kBAAkB,CAAA;AAEzB,gBAAgB;AAChB,OAAO,EAEL,mBAAmB,EAEnB,mBAAmB,EAEnB,iBAAiB,EAEjB,gBAAgB,EAEhB,eAAe,EAChB,MAAM,mBAAmB,CAAA;AAE1B,gBAAgB;AAChB,OAAO,EACL,WAAW,EACX,eAAe,EACf,cAAc,EACd,eAAe,EACf,SAAS,EACT,eAAe,EACf,SAAS,EACV,MAAM,mBAAmB,CAAA;AAE1B,gBAAgB;AAChB,OAAO,EAEL,iBAAiB,EAEjB,sBAAsB,EACtB,mBAAmB,EACnB,aAAa,EACb,uBAAuB,EACvB,WAAW,EACX,iBAAiB,EACjB,sBAAsB,EACtB,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,0BAA0B,EAC3B,MAAM,mBAAmB,CAAA;AAE1B,0BAA0B;AAC1B,OAAO,EACL,eAAe,EAEf,0BAA0B,EAC1B,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,aAAa,EACb,oBAAoB,EAEpB,qBAAqB,EACrB,WAAW,EAEX,qBAAqB,EACtB,MAAM,qBAAqB,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export * from "./ast/index.js";
|
|
7
7
|
export { ContentHash, IssueKey, makeBrandedNonEmptyString, makeBrandedString, PageId, ProjectKey, SpaceKey } from "./Brand.js";
|
|
8
|
-
export { hashBuffer, hashContent,
|
|
8
|
+
export { hashBuffer, hashContent, hashEquals } from "./Hash.js";
|
|
9
9
|
export { ParseError, SerializeError } from "./SerializeError.js";
|
|
10
10
|
export { serializeInlineNodes, type SerializeOptions, serializeToMarkdown } from "./serializers/index.js";
|
|
11
11
|
export * from "./config/index.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,gBAAgB,CAAA;AAG9B,OAAO,EACL,WAAW,EACX,QAAQ,EACR,yBAAyB,EACzB,iBAAiB,EACjB,MAAM,EACN,UAAU,EACV,QAAQ,EACT,MAAM,YAAY,CAAA;AAGnB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,gBAAgB,CAAA;AAG9B,OAAO,EACL,WAAW,EACX,QAAQ,EACR,yBAAyB,EACzB,iBAAiB,EACjB,MAAM,EACN,UAAU,EACV,QAAQ,EACT,MAAM,YAAY,CAAA;AAGnB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAG/D,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAGhE,OAAO,EAAE,oBAAoB,EAAE,KAAK,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAGzG,cAAc,mBAAmB,CAAA;AAGjC,cAAc,iBAAiB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ export * from "./ast/index.js";
|
|
|
8
8
|
// Brand utilities
|
|
9
9
|
export { ContentHash, IssueKey, makeBrandedNonEmptyString, makeBrandedString, PageId, ProjectKey, SpaceKey } from "./Brand.js";
|
|
10
10
|
// Hash utilities
|
|
11
|
-
export { hashBuffer, hashContent,
|
|
11
|
+
export { hashBuffer, hashContent, hashEquals } from "./Hash.js";
|
|
12
12
|
// Error types
|
|
13
13
|
export { ParseError, SerializeError } from "./SerializeError.js";
|
|
14
14
|
// Serializers
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY;AACZ,cAAc,gBAAgB,CAAA;AAE9B,kBAAkB;AAClB,OAAO,EACL,WAAW,EACX,QAAQ,EACR,yBAAyB,EACzB,iBAAiB,EACjB,MAAM,EACN,UAAU,EACV,QAAQ,EACT,MAAM,YAAY,CAAA;AAEnB,iBAAiB;AACjB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY;AACZ,cAAc,gBAAgB,CAAA;AAE9B,kBAAkB;AAClB,OAAO,EACL,WAAW,EACX,QAAQ,EACR,yBAAyB,EACzB,iBAAiB,EACjB,MAAM,EACN,UAAU,EACV,QAAQ,EACT,MAAM,YAAY,CAAA;AAEnB,iBAAiB;AACjB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAE/D,cAAc;AACd,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEhE,cAAc;AACd,OAAO,EAAE,oBAAoB,EAAyB,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAEzG,mBAAmB;AACnB,cAAc,mBAAmB,CAAA;AAEjC,iBAAiB;AACjB,cAAc,iBAAiB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knpkv/atlassian-common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Shared utilities for Atlassian tools (AST, serializers, auth, config)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "knpkv",
|
|
@@ -41,29 +41,32 @@
|
|
|
41
41
|
"./config": {
|
|
42
42
|
"import": "./dist/config/index.js",
|
|
43
43
|
"types": "./dist/config/index.d.ts"
|
|
44
|
+
},
|
|
45
|
+
"./profile-manager": {
|
|
46
|
+
"import": "./dist/config/ProfileManager.js",
|
|
47
|
+
"types": "./dist/config/ProfileManager.d.ts"
|
|
44
48
|
}
|
|
45
49
|
},
|
|
46
50
|
"publishConfig": {
|
|
47
51
|
"access": "public"
|
|
48
52
|
},
|
|
49
53
|
"peerDependencies": {
|
|
50
|
-
"
|
|
51
|
-
"effect": ">=3.19.3"
|
|
54
|
+
"effect": "4.0.0-beta.87"
|
|
52
55
|
},
|
|
53
56
|
"dependencies": {
|
|
54
57
|
"remark-gfm": "^4.0.1",
|
|
55
58
|
"remark-parse": "^11.0.0",
|
|
56
59
|
"remark-stringify": "^11.0.0",
|
|
57
|
-
"unified": "^11.0.5"
|
|
60
|
+
"unified": "^11.0.5",
|
|
61
|
+
"@effect/platform-node": "4.0.0-beta.87"
|
|
58
62
|
},
|
|
59
63
|
"devDependencies": {
|
|
60
|
-
"@effect/platform": "
|
|
61
|
-
"@effect/
|
|
62
|
-
"@effect/vitest": "latest",
|
|
64
|
+
"@effect/platform-node": "4.0.0-beta.87",
|
|
65
|
+
"@effect/vitest": "4.0.0-beta.87",
|
|
63
66
|
"@types/node": "latest",
|
|
64
|
-
"effect": "
|
|
65
|
-
"typescript": "~
|
|
66
|
-
"vitest": "^4.
|
|
67
|
+
"effect": "4.0.0-beta.87",
|
|
68
|
+
"typescript": "~6.0.3",
|
|
69
|
+
"vitest": "^4.1.9"
|
|
67
70
|
},
|
|
68
71
|
"keywords": [
|
|
69
72
|
"effect",
|
|
@@ -74,8 +77,11 @@
|
|
|
74
77
|
"ast",
|
|
75
78
|
"markdown"
|
|
76
79
|
],
|
|
80
|
+
"bin": {
|
|
81
|
+
"atlassian": "./dist/bin.js"
|
|
82
|
+
},
|
|
77
83
|
"scripts": {
|
|
78
|
-
"build": "tsc",
|
|
84
|
+
"build": "tsc && chmod +x dist/bin.js",
|
|
79
85
|
"clean": "rimraf dist dist-test .tsbuildinfo",
|
|
80
86
|
"test": "vitest run",
|
|
81
87
|
"test:watch": "vitest",
|
package/src/Brand.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* **Mental model**
|
|
5
5
|
*
|
|
6
6
|
* - **Brand = runtime validation + compile-time narrowing**: Each brand combines
|
|
7
|
-
* an Effect `Brand.
|
|
7
|
+
* an Effect `Brand.make` (throws on invalid values) with an Effect `Schema`
|
|
8
8
|
* (composable validation). The `Type` property exposes the branded type for use
|
|
9
9
|
* in type annotations.
|
|
10
10
|
* - **Pattern-guarded strings**: `SpaceKey`, `IssueKey`, `ProjectKey` are regex-branded;
|
|
@@ -48,15 +48,9 @@ export const makeBrandedString = <B extends string>(
|
|
|
48
48
|
) => {
|
|
49
49
|
type BrandedType = string & Brand.Brand<B>
|
|
50
50
|
|
|
51
|
-
const brand = Brand.
|
|
52
|
-
(s) => pattern.test(s),
|
|
53
|
-
(s) => Brand.error(`Invalid ${name}: ${s} does not match ${pattern}`)
|
|
54
|
-
)
|
|
51
|
+
const brand = Brand.make<BrandedType>((s) => pattern.test(s) || `Invalid ${name}: ${s} does not match ${pattern}`)
|
|
55
52
|
|
|
56
|
-
const schema = Schema.String.pipe(
|
|
57
|
-
Schema.pattern(pattern),
|
|
58
|
-
Schema.brand(name)
|
|
59
|
-
)
|
|
53
|
+
const schema = Schema.String.check(Schema.isPattern(pattern)).pipe(Schema.brand(name))
|
|
60
54
|
|
|
61
55
|
return Object.assign(brand, {
|
|
62
56
|
schema,
|
|
@@ -83,15 +77,9 @@ export const makeBrandedString = <B extends string>(
|
|
|
83
77
|
export const makeBrandedNonEmptyString = <B extends string>(name: B) => {
|
|
84
78
|
type BrandedType = string & Brand.Brand<B>
|
|
85
79
|
|
|
86
|
-
const brand = Brand.
|
|
87
|
-
(s) => s.length > 0,
|
|
88
|
-
(_s) => Brand.error(`${name} cannot be empty`)
|
|
89
|
-
)
|
|
80
|
+
const brand = Brand.make<BrandedType>((s) => s.length > 0 || `${name} cannot be empty`)
|
|
90
81
|
|
|
91
|
-
const schema = Schema.
|
|
92
|
-
Schema.nonEmptyString(),
|
|
93
|
-
Schema.brand(name)
|
|
94
|
-
)
|
|
82
|
+
const schema = Schema.NonEmptyString.pipe(Schema.brand(name))
|
|
95
83
|
|
|
96
84
|
return Object.assign(brand, {
|
|
97
85
|
schema,
|
package/src/Hash.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* SHA256 content hashing via
|
|
2
|
+
* SHA256 content hashing via Effect's platform `Crypto` service, returning branded {@link ContentHash} values.
|
|
3
3
|
*
|
|
4
4
|
* **Mental model**
|
|
5
5
|
*
|
|
6
|
-
* - **
|
|
7
|
-
* `
|
|
8
|
-
*
|
|
6
|
+
* - **Service-backed crypto**: {@link hashContent} and {@link hashBuffer} use
|
|
7
|
+
* the `Crypto` service from Effect context, so applications provide the
|
|
8
|
+
* platform implementation at the runtime edge.
|
|
9
9
|
*
|
|
10
10
|
* **Common tasks**
|
|
11
11
|
*
|
|
@@ -15,40 +15,50 @@
|
|
|
15
15
|
*
|
|
16
16
|
* @module
|
|
17
17
|
*/
|
|
18
|
+
import * as Crypto from "effect/Crypto"
|
|
18
19
|
import * as Effect from "effect/Effect"
|
|
19
|
-
import * as
|
|
20
|
+
import * as Encoding from "effect/Encoding"
|
|
21
|
+
import type * as PlatformError from "effect/PlatformError"
|
|
20
22
|
import { ContentHash } from "./Brand.js"
|
|
21
23
|
|
|
24
|
+
const textEncoder = new TextEncoder()
|
|
25
|
+
|
|
26
|
+
const digestSha256 = (
|
|
27
|
+
bytes: Uint8Array
|
|
28
|
+
): Effect.Effect<ContentHash, PlatformError.PlatformError, Crypto.Crypto> =>
|
|
29
|
+
Effect.gen(function*() {
|
|
30
|
+
const crypto = yield* Crypto.Crypto
|
|
31
|
+
const digest = yield* crypto.digest("SHA-256", bytes)
|
|
32
|
+
return ContentHash(Encoding.encodeHex(digest))
|
|
33
|
+
})
|
|
34
|
+
|
|
22
35
|
/**
|
|
23
36
|
* Compute SHA256 hash of a string.
|
|
24
37
|
*
|
|
25
38
|
* @example
|
|
26
39
|
* ```typescript
|
|
27
|
-
* import
|
|
40
|
+
* import * as Crypto from "effect/Crypto"
|
|
28
41
|
* import * as Effect from "effect/Effect"
|
|
42
|
+
* import { hashContent } from "@knpkv/atlassian-common"
|
|
29
43
|
*
|
|
30
|
-
* const
|
|
44
|
+
* declare const crypto: Crypto.Crypto
|
|
45
|
+
* const hash = Effect.runSync(hashContent("hello world").pipe(Effect.provideService(Crypto.Crypto, crypto)))
|
|
31
46
|
* // => "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
|
|
32
47
|
* ```
|
|
33
48
|
*
|
|
34
49
|
* @category Hash
|
|
35
50
|
*/
|
|
36
|
-
export const hashContent = (content: string): Effect.Effect<ContentHash> =>
|
|
37
|
-
|
|
38
|
-
const hash = crypto.createHash("sha256").update(content, "utf8").digest("hex")
|
|
39
|
-
return ContentHash(hash)
|
|
40
|
-
})
|
|
51
|
+
export const hashContent = (content: string): Effect.Effect<ContentHash, PlatformError.PlatformError, Crypto.Crypto> =>
|
|
52
|
+
digestSha256(textEncoder.encode(content))
|
|
41
53
|
|
|
42
54
|
/**
|
|
43
55
|
* Compute SHA256 hash of a buffer.
|
|
44
56
|
*
|
|
45
57
|
* @category Hash
|
|
46
58
|
*/
|
|
47
|
-
export const hashBuffer = (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return ContentHash(hash)
|
|
51
|
-
})
|
|
59
|
+
export const hashBuffer = (
|
|
60
|
+
buffer: Uint8Array
|
|
61
|
+
): Effect.Effect<ContentHash, PlatformError.PlatformError, Crypto.Crypto> => digestSha256(buffer)
|
|
52
62
|
|
|
53
63
|
/**
|
|
54
64
|
* Check if two hashes are equal.
|
|
@@ -56,13 +66,3 @@ export const hashBuffer = (buffer: Buffer | Uint8Array): Effect.Effect<ContentHa
|
|
|
56
66
|
* @category Hash
|
|
57
67
|
*/
|
|
58
68
|
export const hashEquals = (a: ContentHash, b: ContentHash): boolean => a === b
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Synchronous version of hashContent for simple use cases.
|
|
62
|
-
*
|
|
63
|
-
* @category Hash
|
|
64
|
-
*/
|
|
65
|
-
export const hashContentSync = (content: string): ContentHash => {
|
|
66
|
-
const hash = crypto.createHash("sha256").update(content, "utf8").digest("hex")
|
|
67
|
-
return ContentHash(hash)
|
|
68
|
-
}
|
package/src/ast/BlockNode.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*
|
|
12
12
|
* @module
|
|
13
13
|
*/
|
|
14
|
+
import * as Effect from "effect/Effect"
|
|
14
15
|
import * as Schema from "effect/Schema"
|
|
15
16
|
import { InlineNode, type InlineNode as InlineNodeType } from "./InlineNode.js"
|
|
16
17
|
|
|
@@ -19,10 +20,9 @@ import { InlineNode, type InlineNode as InlineNodeType } from "./InlineNode.js"
|
|
|
19
20
|
*
|
|
20
21
|
* @category Version
|
|
21
22
|
*/
|
|
22
|
-
export const SchemaVersion = Schema.
|
|
23
|
-
Schema.
|
|
24
|
-
Schema.
|
|
25
|
-
Schema.optionalWith({ default: () => 1 })
|
|
23
|
+
export const SchemaVersion = Schema.Int.pipe(
|
|
24
|
+
Schema.check(Schema.isGreaterThan(0)),
|
|
25
|
+
Schema.withConstructorDefault(Effect.succeed(1))
|
|
26
26
|
)
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -49,7 +49,7 @@ export const RawSource = Schema.optional(Schema.String)
|
|
|
49
49
|
*/
|
|
50
50
|
export class Heading extends Schema.TaggedClass<Heading>()("Heading", {
|
|
51
51
|
version: SchemaVersion,
|
|
52
|
-
level: Schema.
|
|
52
|
+
level: Schema.Literals([1, 2, 3, 4, 5, 6]),
|
|
53
53
|
children: Schema.Array(InlineNode),
|
|
54
54
|
rawSource: RawSource
|
|
55
55
|
}) {}
|
|
@@ -59,7 +59,7 @@ export class Heading extends Schema.TaggedClass<Heading>()("Heading", {
|
|
|
59
59
|
*
|
|
60
60
|
* @category BlockNode
|
|
61
61
|
*/
|
|
62
|
-
export const TextAlignment = Schema.
|
|
62
|
+
export const TextAlignment = Schema.Literals(["left", "center", "right"])
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
65
|
* Type for TextAlignment.
|
|
@@ -187,7 +187,7 @@ export class Image extends Schema.TaggedClass<Image>()("Image", {
|
|
|
187
187
|
* @category BlockNode
|
|
188
188
|
*/
|
|
189
189
|
export class TableCell extends Schema.TaggedClass<TableCell>()("TableCell", {
|
|
190
|
-
isHeader: Schema.
|
|
190
|
+
isHeader: Schema.Boolean.pipe(Schema.withConstructorDefault(Effect.succeed(false))),
|
|
191
191
|
children: Schema.Array(InlineNode),
|
|
192
192
|
rawSource: RawSource
|
|
193
193
|
}) {}
|
|
@@ -223,11 +223,11 @@ export class UnsupportedBlock extends Schema.TaggedClass<UnsupportedBlock>()("Un
|
|
|
223
223
|
rawHtml: Schema.optional(Schema.String),
|
|
224
224
|
rawMarkdown: Schema.optional(Schema.String),
|
|
225
225
|
rawAdf: Schema.optional(Schema.String),
|
|
226
|
-
source: Schema.
|
|
226
|
+
source: Schema.Literals(["confluence", "markdown", "adf"])
|
|
227
227
|
}) {}
|
|
228
228
|
|
|
229
229
|
// Non-recursive block nodes
|
|
230
|
-
const SimpleBlockNode = Schema.Union(
|
|
230
|
+
const SimpleBlockNode = Schema.Union([
|
|
231
231
|
Heading,
|
|
232
232
|
Paragraph,
|
|
233
233
|
CodeBlock,
|
|
@@ -235,7 +235,7 @@ const SimpleBlockNode = Schema.Union(
|
|
|
235
235
|
Image,
|
|
236
236
|
Table,
|
|
237
237
|
UnsupportedBlock
|
|
238
|
-
)
|
|
238
|
+
])
|
|
239
239
|
|
|
240
240
|
/**
|
|
241
241
|
* Block quote element with nested block content.
|
|
@@ -305,7 +305,7 @@ export const TaskItem = Schema.Struct({
|
|
|
305
305
|
_tag: Schema.Literal("TaskItem"),
|
|
306
306
|
id: Schema.String,
|
|
307
307
|
uuid: Schema.String,
|
|
308
|
-
status: Schema.
|
|
308
|
+
status: Schema.Literals(["incomplete", "complete"]),
|
|
309
309
|
body: Schema.Array(InlineNode),
|
|
310
310
|
rawSource: RawSource
|
|
311
311
|
})
|
|
@@ -341,7 +341,7 @@ export type TaskList = Schema.Schema.Type<typeof TaskList>
|
|
|
341
341
|
*
|
|
342
342
|
* @category BlockNode
|
|
343
343
|
*/
|
|
344
|
-
export const BlockNode = Schema.Union(
|
|
344
|
+
export const BlockNode = Schema.Union([
|
|
345
345
|
Heading,
|
|
346
346
|
Paragraph,
|
|
347
347
|
CodeBlock,
|
|
@@ -352,7 +352,7 @@ export const BlockNode = Schema.Union(
|
|
|
352
352
|
List,
|
|
353
353
|
TaskList,
|
|
354
354
|
UnsupportedBlock
|
|
355
|
-
)
|
|
355
|
+
])
|
|
356
356
|
|
|
357
357
|
/**
|
|
358
358
|
* Type for block nodes.
|
package/src/ast/Document.ts
CHANGED
|
@@ -23,7 +23,7 @@ import { MacroNode, type MacroNode as MacroNodeType } from "./MacroNode.js"
|
|
|
23
23
|
*
|
|
24
24
|
* @category Document
|
|
25
25
|
*/
|
|
26
|
-
export const DocumentNode = Schema.Union(BlockNode, MacroNode)
|
|
26
|
+
export const DocumentNode = Schema.Union([BlockNode, MacroNode])
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Type for document nodes.
|
package/src/ast/InlineNode.ts
CHANGED
|
@@ -82,7 +82,7 @@ export class LineBreak extends Schema.TaggedClass<LineBreak>()("LineBreak", {})
|
|
|
82
82
|
*/
|
|
83
83
|
export class UnsupportedInline extends Schema.TaggedClass<UnsupportedInline>()("UnsupportedInline", {
|
|
84
84
|
raw: Schema.String,
|
|
85
|
-
source: Schema.
|
|
85
|
+
source: Schema.Literals(["confluence", "markdown", "adf"])
|
|
86
86
|
}) {}
|
|
87
87
|
|
|
88
88
|
/**
|
|
@@ -199,7 +199,7 @@ export class Highlight extends Schema.TaggedClass<Highlight>()("Highlight", {
|
|
|
199
199
|
}) {}
|
|
200
200
|
|
|
201
201
|
// Forward declaration for recursive types
|
|
202
|
-
const InlineNodeBase = Schema.Union(
|
|
202
|
+
const InlineNodeBase = Schema.Union([
|
|
203
203
|
Text,
|
|
204
204
|
InlineCode,
|
|
205
205
|
LineBreak,
|
|
@@ -207,7 +207,7 @@ const InlineNodeBase = Schema.Union(
|
|
|
207
207
|
UserMention,
|
|
208
208
|
DateTime,
|
|
209
209
|
UnsupportedInline
|
|
210
|
-
)
|
|
210
|
+
])
|
|
211
211
|
|
|
212
212
|
/**
|
|
213
213
|
* Inline node children schema - use this for recursive inline content.
|
|
@@ -278,7 +278,7 @@ export class Link extends Schema.TaggedClass<Link>()("Link", {
|
|
|
278
278
|
*
|
|
279
279
|
* @category InlineNode
|
|
280
280
|
*/
|
|
281
|
-
export const InlineNode = Schema.Union(
|
|
281
|
+
export const InlineNode = Schema.Union([
|
|
282
282
|
Text,
|
|
283
283
|
Strong,
|
|
284
284
|
Emphasis,
|
|
@@ -295,7 +295,7 @@ export const InlineNode = Schema.Union(
|
|
|
295
295
|
ColoredText,
|
|
296
296
|
Highlight,
|
|
297
297
|
UnsupportedInline
|
|
298
|
-
)
|
|
298
|
+
])
|
|
299
299
|
|
|
300
300
|
/**
|
|
301
301
|
* Type for inline nodes.
|
package/src/ast/MacroNode.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @module
|
|
12
12
|
*/
|
|
13
|
+
import * as Effect from "effect/Effect"
|
|
13
14
|
import * as Schema from "effect/Schema"
|
|
14
15
|
import { RawSource, SchemaVersion, SimpleBlockNode } from "./BlockNode.js"
|
|
15
16
|
|
|
@@ -25,7 +26,7 @@ export const PanelTypes = ["info", "warning", "note", "tip", "error", "panel"] a
|
|
|
25
26
|
*
|
|
26
27
|
* @category MacroNode
|
|
27
28
|
*/
|
|
28
|
-
export const PanelType = Schema.
|
|
29
|
+
export const PanelType = Schema.Literals(PanelTypes)
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
32
|
* Type for panel type.
|
|
@@ -118,8 +119,8 @@ export const CodeMacro = Schema.Struct({
|
|
|
118
119
|
language: Schema.optional(Schema.String),
|
|
119
120
|
title: Schema.optional(Schema.String),
|
|
120
121
|
code: Schema.String,
|
|
121
|
-
lineNumbers: Schema.
|
|
122
|
-
collapse: Schema.
|
|
122
|
+
lineNumbers: Schema.Boolean.pipe(Schema.withConstructorDefault(Effect.succeed(false))),
|
|
123
|
+
collapse: Schema.Boolean.pipe(Schema.withConstructorDefault(Effect.succeed(false))),
|
|
123
124
|
firstLine: Schema.optional(Schema.Number),
|
|
124
125
|
rawSource: RawSource
|
|
125
126
|
})
|
|
@@ -140,7 +141,7 @@ export const StatusMacro = Schema.Struct({
|
|
|
140
141
|
_tag: Schema.Literal("StatusMacro"),
|
|
141
142
|
version: SchemaVersion,
|
|
142
143
|
text: Schema.String,
|
|
143
|
-
color: Schema.
|
|
144
|
+
color: Schema.Literals(["Grey", "Red", "Yellow", "Green", "Blue"]),
|
|
144
145
|
rawSource: RawSource
|
|
145
146
|
})
|
|
146
147
|
|
|
@@ -156,13 +157,13 @@ export type StatusMacro = Schema.Schema.Type<typeof StatusMacro>
|
|
|
156
157
|
*
|
|
157
158
|
* @category MacroNode
|
|
158
159
|
*/
|
|
159
|
-
export const MacroNode = Schema.Union(
|
|
160
|
+
export const MacroNode = Schema.Union([
|
|
160
161
|
InfoPanel,
|
|
161
162
|
ExpandMacro,
|
|
162
163
|
TocMacro,
|
|
163
164
|
CodeMacro,
|
|
164
165
|
StatusMacro
|
|
165
|
-
)
|
|
166
|
+
])
|
|
166
167
|
|
|
167
168
|
/**
|
|
168
169
|
* Type for macro nodes.
|