phorge 0.1.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/LICENSE +201 -0
- package/dist/client.d.ts +20 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +187 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/models/maniphest.d.ts +182 -0
- package/dist/models/maniphest.d.ts.map +1 -0
- package/dist/models/maniphest.js +78 -0
- package/dist/models/maniphest.js.map +1 -0
- package/dist/models/phorge.d.ts +132 -0
- package/dist/models/phorge.d.ts.map +1 -0
- package/dist/models/phorge.js +18 -0
- package/dist/models/phorge.js.map +1 -0
- package/dist/models/project.d.ts +172 -0
- package/dist/models/project.d.ts.map +1 -0
- package/dist/models/project.js +80 -0
- package/dist/models/project.js.map +1 -0
- package/dist/models/transaction.d.ts +142 -0
- package/dist/models/transaction.d.ts.map +1 -0
- package/dist/models/transaction.js +36 -0
- package/dist/models/transaction.js.map +1 -0
- package/dist/models/user.d.ts +90 -0
- package/dist/models/user.d.ts.map +1 -0
- package/dist/models/user.js +43 -0
- package/dist/models/user.js.map +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +58 -0
- package/dist/utils.js.map +1 -0
- package/package.json +21 -0
- package/src/client.ts +200 -0
- package/src/index.ts +6 -0
- package/src/models/maniphest.ts +93 -0
- package/src/models/phorge.ts +74 -0
- package/src/models/project.ts +100 -0
- package/src/models/transaction.ts +49 -0
- package/src/models/user.ts +55 -0
- package/src/utils.ts +59 -0
- package/tsconfig.json +44 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type ApiResponse, CreateObjectResult, type PHID, type Policy } from "./phorge.js"
|
|
2
|
+
import * as z from "zod"
|
|
3
|
+
|
|
4
|
+
export const Icon = z.object({
|
|
5
|
+
key: z.string(),
|
|
6
|
+
name: z.string(),
|
|
7
|
+
icon: z.string()
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
export type Icon = z.infer<typeof Icon>
|
|
11
|
+
|
|
12
|
+
export const Color = z.object({
|
|
13
|
+
key: z.string(),
|
|
14
|
+
mame: z.string(),
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export type Color = z.infer<typeof Color>
|
|
18
|
+
|
|
19
|
+
export const ProjectTransaction = z.object({
|
|
20
|
+
parent: z.custom<PHID<"PROJ">>().optional(),
|
|
21
|
+
milestone: z.custom<PHID<"PROJ">>().optional(),
|
|
22
|
+
space: z.unknown().optional(),
|
|
23
|
+
name: z.string().optional(),
|
|
24
|
+
description: z.string().optional(),
|
|
25
|
+
icon: z.string().optional(),
|
|
26
|
+
color: z.string().optional(),
|
|
27
|
+
slugs: z.string().array().nonempty().optional(),
|
|
28
|
+
members: z.object({
|
|
29
|
+
add: z.custom<PHID<"USER">>().array().nonempty().optional(),
|
|
30
|
+
remove: z.custom<PHID<"USER">>().array().nonempty().optional(),
|
|
31
|
+
set: z.custom<PHID<"USER">>().array().nonempty().optional()
|
|
32
|
+
}).optional(),
|
|
33
|
+
view: z.custom<PHID<"PLCY">>().or(z.enum(["obj.project.members", "users", "admin", "no-one"])).optional(), // TODO, Check Policy ID, and policy constant
|
|
34
|
+
edit: z.custom<PHID<"PLCY">>().or(z.enum(["obj.project.members", "users", "admin", "no-one"])).optional(), // TODO, Check Policy ID, and policy constant
|
|
35
|
+
join: z.custom<PHID<"PLCY">>().or(z.enum(["obj.project.members", "users", "admin", "no-one"])).optional(), // TODO, Check Policy ID, and policy constant
|
|
36
|
+
subtype: z.string().optional(),
|
|
37
|
+
mfa: z.boolean().optional()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
export type ProjectTransaction = z.infer<typeof ProjectTransaction>
|
|
41
|
+
|
|
42
|
+
export const ProjectConstraints = z.object({
|
|
43
|
+
ids: z.number().array().nonempty().optional(),
|
|
44
|
+
phids: z.custom<PHID<"PROJ">>().array().nonempty().optional(),
|
|
45
|
+
slugs: z.string().array().nonempty().optional(),
|
|
46
|
+
members: z.custom<PHID<"USER">>().array().nonempty().optional(),
|
|
47
|
+
watchers: z.custom<PHID<"USER">>().array().nonempty().optional(),
|
|
48
|
+
status: z.enum(["active", "archived", "all"]).optional(),
|
|
49
|
+
isMilestone: z.boolean().optional(),
|
|
50
|
+
isRoot: z.boolean().optional(),
|
|
51
|
+
minDepth: z.number().optional(),
|
|
52
|
+
maxDepth: z.number().optional(),
|
|
53
|
+
subtypes: z.string().array().nonempty().optional(),
|
|
54
|
+
icons: z.string().array().nonempty().optional(),
|
|
55
|
+
colors: z.string().array().nonempty().optional(),
|
|
56
|
+
parents: z.custom<PHID<"PROJ">>().array().optional(),
|
|
57
|
+
ancestors: z.custom<PHID<"PROJ">>().array().optional(),
|
|
58
|
+
query: z.string().optional()
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
export type ProjectConstraints = z.infer<typeof ProjectConstraints>
|
|
62
|
+
|
|
63
|
+
export const ProjectSearchOptions = z.object({
|
|
64
|
+
queryKey: z.string().optional(),
|
|
65
|
+
constraints: z.custom<ProjectConstraints>().optional(),
|
|
66
|
+
attachments: z.unknown().optional(),
|
|
67
|
+
order: z.enum(["priority", "updated", "outdated", "newest", "oldest", "closed", "title", "relevance"]).optional(),
|
|
68
|
+
before: z.number().optional(),
|
|
69
|
+
after: z.number().optional(),
|
|
70
|
+
limit: z.number().optional()
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
export type ProjectSearchOptions = z.infer<typeof ProjectSearchOptions>
|
|
74
|
+
|
|
75
|
+
export const SearchProjectResult = z.object({
|
|
76
|
+
id: z.number(),
|
|
77
|
+
type: z.custom<"PROJ">(),
|
|
78
|
+
phid: z.custom<PHID<"PROJ">>(),
|
|
79
|
+
fields: z.object({
|
|
80
|
+
name: z.string(),
|
|
81
|
+
slug: z.string(),
|
|
82
|
+
subtype: z.string(),
|
|
83
|
+
milestone: z.unknown(),
|
|
84
|
+
depth: z.number(),
|
|
85
|
+
parent: z.custom<PHID<"PROJ">>(),
|
|
86
|
+
icon: z.custom<Icon>(),
|
|
87
|
+
color: z.custom<Color>(),
|
|
88
|
+
status: z.enum(["active", "archived", "all"]),
|
|
89
|
+
spacePHID: z.custom<PHID<"SPCE">>(),
|
|
90
|
+
dateCreated: z.number(),
|
|
91
|
+
dateModified: z.number(),
|
|
92
|
+
policy: z.custom<Policy>(),
|
|
93
|
+
description: z.string()
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
export type SearchProjectResult = z.infer<typeof SearchProjectResult>
|
|
98
|
+
|
|
99
|
+
export type CreateProjectResponse = ApiResponse<{ object: CreateObjectResult }>
|
|
100
|
+
export type SearchProjectResponse = ApiResponse<{ data: SearchProjectResult[] }>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { ObjectType, type ApiResponse, type PHID } from "./phorge.js";
|
|
3
|
+
|
|
4
|
+
export const TransactionConstraints = z.object({
|
|
5
|
+
phids: z.custom<PHID>().array().optional(),
|
|
6
|
+
authorPHIDs: z.custom<PHID<"USER">>().array().optional()
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
export type TransactionConstraints = z.infer<typeof TransactionConstraints>
|
|
10
|
+
|
|
11
|
+
export const TransactionSearchOptions = z.object({
|
|
12
|
+
objectIdentifier: z.custom<PHID>().optional(),
|
|
13
|
+
objectType: ObjectType.optional(),
|
|
14
|
+
constraints: z.custom<TransactionConstraints>().optional(),
|
|
15
|
+
before: z.number().optional(),
|
|
16
|
+
after: z.number().optional(),
|
|
17
|
+
limit: z.number().optional()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
export type TransactionSearchOptions = z.infer<typeof TransactionSearchOptions>
|
|
21
|
+
|
|
22
|
+
export const TransactionComment = z.object({
|
|
23
|
+
id: z.number(),
|
|
24
|
+
phid: z.string(),
|
|
25
|
+
version: z.number(),
|
|
26
|
+
authorPHID: z.custom<PHID<"USER">>(),
|
|
27
|
+
dateCreated: z.number(),
|
|
28
|
+
dateModified: z.number(),
|
|
29
|
+
removed: z.boolean(),
|
|
30
|
+
content: z.object({ raw: z.string() })
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
export type TransactionComment = z.infer<typeof TransactionComment>
|
|
34
|
+
|
|
35
|
+
export const SearchTransactionResult = z.object({
|
|
36
|
+
id: z.number(),
|
|
37
|
+
phid: z.string(),
|
|
38
|
+
type: z.string().nullable(),
|
|
39
|
+
authorPHID: z.custom<PHID<"USER">>(),
|
|
40
|
+
objectPHID: z.custom<PHID>(),
|
|
41
|
+
dateCreated: z.number(),
|
|
42
|
+
dateModified: z.number(),
|
|
43
|
+
groupID: z.string(),
|
|
44
|
+
comments: TransactionComment.array()
|
|
45
|
+
}).array();
|
|
46
|
+
|
|
47
|
+
export type SearchTransactionResult = z.infer<typeof SearchTransactionResult>
|
|
48
|
+
|
|
49
|
+
export type SearchTransactionResponse = ApiResponse<{ data: SearchTransactionResult[] }>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as z from "zod"
|
|
2
|
+
import type { ApiResponse, CreateObjectResult, PHID } from "./phorge.js"
|
|
3
|
+
|
|
4
|
+
export const UserConstraints = z.object({
|
|
5
|
+
ids: z.number().array().nonempty().optional(),
|
|
6
|
+
phids: z.custom<PHID<"USER">>().array().nonempty().optional(),
|
|
7
|
+
usernames: z.string().array().nonempty().optional(),
|
|
8
|
+
nameLike: z.string().nonempty().optional(),
|
|
9
|
+
isAdmin: z.boolean().optional(),
|
|
10
|
+
isDisabled: z.boolean().optional(),
|
|
11
|
+
isBot: z.boolean().optional(),
|
|
12
|
+
isMailingList: z.boolean().optional(),
|
|
13
|
+
needsApproval: z.boolean().optional(),
|
|
14
|
+
mfa: z.boolean().optional(),
|
|
15
|
+
createdStart: z.number().optional(),
|
|
16
|
+
createdEnd: z.number().optional(),
|
|
17
|
+
query: z.string().nonempty().optional()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
export type UserConstraints = z.infer<typeof UserConstraints>
|
|
21
|
+
|
|
22
|
+
export const UserSearchOptions = z.object({
|
|
23
|
+
queryKey: z.string().optional(),
|
|
24
|
+
constraints: z.custom<UserConstraints>().optional(),
|
|
25
|
+
attachments: z.unknown().optional(),
|
|
26
|
+
order: z.enum(["priority", "updated", "outdated", "newest", "oldest", "closed", "title", "relevance"]).optional(),
|
|
27
|
+
before: z.number().optional(),
|
|
28
|
+
after: z.number().optional(),
|
|
29
|
+
limit: z.number().optional()
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
export type UserSearchOptions = z.infer<typeof UserSearchOptions>
|
|
33
|
+
|
|
34
|
+
export const SearchUserResult = z.object({
|
|
35
|
+
id: z.number(),
|
|
36
|
+
type: z.literal("USER"),
|
|
37
|
+
phid: z.custom<PHID<"USER">>(),
|
|
38
|
+
fields: z.object({
|
|
39
|
+
username: z.string(),
|
|
40
|
+
realName: z.string(),
|
|
41
|
+
roles: z.string().array(),
|
|
42
|
+
dateCreated: z.number(),
|
|
43
|
+
dateModified: z.number(),
|
|
44
|
+
policy: z.object({
|
|
45
|
+
view: z.string(),
|
|
46
|
+
edit: z.string()
|
|
47
|
+
})
|
|
48
|
+
}),
|
|
49
|
+
attachments: z.unknown()
|
|
50
|
+
}).array()
|
|
51
|
+
|
|
52
|
+
export type SearchUserResult = z.infer<typeof SearchUserResult>
|
|
53
|
+
|
|
54
|
+
export type CreateUserResponse = ApiResponse<{ object: CreateObjectResult }>
|
|
55
|
+
export type SearchUserResponse = ApiResponse<{ data: SearchUserResult }>
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export function ConstraintObjectToParams(obj: Record<string, any>, prefix = ""): URLSearchParams {
|
|
2
|
+
const params = new URLSearchParams();
|
|
3
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
4
|
+
console.log(k, v)
|
|
5
|
+
if (Array.isArray(v)) {
|
|
6
|
+
let index = 0;
|
|
7
|
+
v.forEach((item: string, j: number) => {
|
|
8
|
+
const itemVal = typeof item === "string" ? item : JSON.stringify(item);
|
|
9
|
+
params.append(`constraints[${k}][${index}]`, itemVal);
|
|
10
|
+
index++;
|
|
11
|
+
});
|
|
12
|
+
} else {
|
|
13
|
+
const value = typeof v === "string" ? v : JSON.stringify(v);
|
|
14
|
+
params.append(`constraints[${k}]`, value);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return params;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function TransactionObjectToParams(obj: Record<string, any>, prefix = ""): URLSearchParams {
|
|
21
|
+
const params = new URLSearchParams();
|
|
22
|
+
let index = 0;
|
|
23
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
24
|
+
let val = v
|
|
25
|
+
let key = k;
|
|
26
|
+
|
|
27
|
+
if (["parents", "subtasks", "commits", "projects", "subscribers", "members"].includes(key)) {
|
|
28
|
+
if (Object.keys(v).includes("add")) {
|
|
29
|
+
key = `${key}.add`
|
|
30
|
+
val = val["add"]
|
|
31
|
+
} else if (Object.keys(v).includes("remove")) {
|
|
32
|
+
key = `${key}.remove`
|
|
33
|
+
val = val["remove"]
|
|
34
|
+
} else if (Object.keys(v).includes("set")) {
|
|
35
|
+
key = `${key}.set`
|
|
36
|
+
val = val["set"]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const typeKey = `transactions[${index}][type]`;
|
|
41
|
+
const valueKey = `transactions[${index}][value]`;
|
|
42
|
+
|
|
43
|
+
params.append(typeKey, key);
|
|
44
|
+
|
|
45
|
+
if (Array.isArray(val)) {
|
|
46
|
+
val.forEach((item: string, j: number) => {
|
|
47
|
+
const itemKey = `${valueKey}[${j}]`;
|
|
48
|
+
const itemVal = typeof item === "string" ? item : JSON.stringify(item);
|
|
49
|
+
params.append(itemKey, itemVal);
|
|
50
|
+
});
|
|
51
|
+
} else {
|
|
52
|
+
const value = typeof v === "string" ? v : JSON.stringify(v);
|
|
53
|
+
params.append(valueKey, value);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
index++;
|
|
57
|
+
}
|
|
58
|
+
return params;
|
|
59
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Visit https://aka.ms/tsconfig to read more about this file
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
// File Layout
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
|
|
8
|
+
// Environment Settings
|
|
9
|
+
// See also https://aka.ms/tsconfig/module
|
|
10
|
+
"module": "nodenext",
|
|
11
|
+
"target": "esnext",
|
|
12
|
+
"types": [],
|
|
13
|
+
// For nodejs:
|
|
14
|
+
// "lib": ["esnext"],
|
|
15
|
+
// "types": ["node"],
|
|
16
|
+
// and npm install -D @types/node
|
|
17
|
+
|
|
18
|
+
// Other Outputs
|
|
19
|
+
"sourceMap": true,
|
|
20
|
+
"declaration": true,
|
|
21
|
+
"declarationMap": true,
|
|
22
|
+
|
|
23
|
+
// Stricter Typechecking Options
|
|
24
|
+
"noUncheckedIndexedAccess": true,
|
|
25
|
+
"exactOptionalPropertyTypes": true,
|
|
26
|
+
|
|
27
|
+
// Style Options
|
|
28
|
+
// "noImplicitReturns": true,
|
|
29
|
+
// "noImplicitOverride": true,
|
|
30
|
+
// "noUnusedLocals": true,
|
|
31
|
+
// "noUnusedParameters": true,
|
|
32
|
+
// "noFallthroughCasesInSwitch": true,
|
|
33
|
+
// "noPropertyAccessFromIndexSignature": true,
|
|
34
|
+
|
|
35
|
+
// Recommended Options
|
|
36
|
+
"strict": true,
|
|
37
|
+
"jsx": "react-jsx",
|
|
38
|
+
"verbatimModuleSyntax": true,
|
|
39
|
+
"isolatedModules": true,
|
|
40
|
+
"noUncheckedSideEffectImports": true,
|
|
41
|
+
"moduleDetection": "force",
|
|
42
|
+
"skipLibCheck": true,
|
|
43
|
+
}
|
|
44
|
+
}
|