@elobdev/zoho-projects-wrapper 0.1.0 → 0.1.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/README.md +28 -8
- package/dist/client.d.ts +35 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +66 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +22 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +42 -0
- package/dist/errors.js.map +1 -0
- package/dist/http.d.ts +14 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +136 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/oauth.d.ts +20 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +103 -0
- package/dist/oauth.js.map +1 -0
- package/dist/query.d.ts +5 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +47 -0
- package/dist/query.js.map +1 -0
- package/dist/resource-base.d.ts +18 -0
- package/dist/resource-base.d.ts.map +1 -0
- package/dist/resource-base.js +46 -0
- package/dist/resource-base.js.map +1 -0
- package/dist/resources/custom-fields.d.ts +17 -0
- package/dist/resources/custom-fields.d.ts.map +1 -0
- package/dist/resources/custom-fields.js +11 -0
- package/dist/resources/custom-fields.js.map +1 -0
- package/dist/resources/issues.d.ts +67 -0
- package/dist/resources/issues.d.ts.map +1 -0
- package/dist/resources/issues.js +107 -0
- package/dist/resources/issues.js.map +1 -0
- package/dist/resources/module-meta.d.ts +2 -0
- package/dist/resources/module-meta.d.ts.map +1 -0
- package/dist/resources/module-meta.js +2 -0
- package/dist/resources/module-meta.js.map +1 -0
- package/dist/resources/phases.d.ts +46 -0
- package/dist/resources/phases.d.ts.map +1 -0
- package/dist/resources/phases.js +52 -0
- package/dist/resources/phases.js.map +1 -0
- package/dist/resources/portals.d.ts +15 -0
- package/dist/resources/portals.d.ts.map +1 -0
- package/dist/resources/portals.js +36 -0
- package/dist/resources/portals.js.map +1 -0
- package/dist/resources/project-groups.d.ts +18 -0
- package/dist/resources/project-groups.d.ts.map +1 -0
- package/dist/resources/project-groups.js +19 -0
- package/dist/resources/project-groups.js.map +1 -0
- package/dist/resources/projects.d.ts +33 -0
- package/dist/resources/projects.d.ts.map +1 -0
- package/dist/resources/projects.js +40 -0
- package/dist/resources/projects.js.map +1 -0
- package/dist/resources/records.d.ts +21 -0
- package/dist/resources/records.d.ts.map +1 -0
- package/dist/resources/records.js +31 -0
- package/dist/resources/records.js.map +1 -0
- package/dist/resources/settings.d.ts +46 -0
- package/dist/resources/settings.d.ts.map +1 -0
- package/dist/resources/settings.js +100 -0
- package/dist/resources/settings.js.map +1 -0
- package/dist/resources/tasklists.d.ts +38 -0
- package/dist/resources/tasklists.d.ts.map +1 -0
- package/dist/resources/tasklists.js +52 -0
- package/dist/resources/tasklists.js.map +1 -0
- package/dist/resources/tasks.d.ts +26 -0
- package/dist/resources/tasks.d.ts.map +1 -0
- package/dist/resources/tasks.js +34 -0
- package/dist/resources/tasks.js.map +1 -0
- package/dist/resources/time-logs.d.ts +56 -0
- package/dist/resources/time-logs.d.ts.map +1 -0
- package/dist/resources/time-logs.js +209 -0
- package/dist/resources/time-logs.js.map +1 -0
- package/dist/tools.d.ts +20 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +652 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +532 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +19 -1
- package/.codex +0 -0
- package/docs/zoho- +0 -0
- package/docs/zoho-projects-api-matrix.md +0 -368
- package/src/client.ts +0 -75
- package/src/errors.ts +0 -34
- package/src/http.ts +0 -166
- package/src/index.ts +0 -19
- package/src/oauth.ts +0 -121
- package/src/query.ts +0 -51
- package/src/resource-base.ts +0 -59
- package/src/resources/custom-fields.ts +0 -27
- package/src/resources/issues.ts +0 -166
- package/src/resources/module-meta.ts +0 -1
- package/src/resources/phases.ts +0 -68
- package/src/resources/portals.ts +0 -46
- package/src/resources/project-groups.ts +0 -24
- package/src/resources/projects.ts +0 -56
- package/src/resources/records.ts +0 -40
- package/src/resources/settings.ts +0 -132
- package/src/resources/tasklists.ts +0 -94
- package/src/resources/tasks.ts +0 -43
- package/src/resources/time-logs.ts +0 -274
- package/src/tools.ts +0 -741
- package/src/types.ts +0 -546
- package/test/helpers.ts +0 -28
- package/test/http.test.ts +0 -49
- package/test/node-shims.d.ts +0 -9
- package/test/oauth.test.ts +0 -72
- package/test/path-alias-hooks.js +0 -10
- package/test/query.test.ts +0 -46
- package/test/register-path-alias.js +0 -3
- package/test/resources.test.ts +0 -504
- package/test/tools.test.ts +0 -30
- package/tsconfig.json +0 -20
package/src/http.ts
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { createApiError } from '@/errors.ts';
|
|
2
|
-
import { serializeQuery } from '@/query.ts';
|
|
3
|
-
import type { RequestContext, RequestOptions, ZohoErrorPayload } from '@/types.ts';
|
|
4
|
-
|
|
5
|
-
const DEFAULT_API_BASE_URL = 'https://projectsapi.zoho.com/api/v3';
|
|
6
|
-
|
|
7
|
-
function joinPath(baseUrl: string, path: string): string {
|
|
8
|
-
const normalizedBase = baseUrl.replace(/\/+$/, '');
|
|
9
|
-
const normalizedPath = path.replace(/^\/+/, '');
|
|
10
|
-
return `${normalizedBase}/${normalizedPath}`;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function extractRequestId(headers: Headers): string | undefined {
|
|
14
|
-
return (
|
|
15
|
-
headers.get('x-request-id') ??
|
|
16
|
-
headers.get('request-id') ??
|
|
17
|
-
headers.get('x-zohos-request-id') ??
|
|
18
|
-
headers.get('x-zoho-request-id') ??
|
|
19
|
-
undefined
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async function safeReadBody(response: Response): Promise<unknown> {
|
|
24
|
-
const contentType = response.headers.get('content-type') ?? '';
|
|
25
|
-
if (response.status === 204) return null;
|
|
26
|
-
|
|
27
|
-
const raw = await response.text();
|
|
28
|
-
if (!raw) return null;
|
|
29
|
-
|
|
30
|
-
if (contentType.includes('application/json') || raw.startsWith('{') || raw.startsWith('[')) {
|
|
31
|
-
try {
|
|
32
|
-
return JSON.parse(raw) as ZohoErrorPayload;
|
|
33
|
-
} catch {
|
|
34
|
-
return raw;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return raw;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function buildHeaders(context: RequestContext, headers?: HeadersInit, hasJsonBody = false): Headers {
|
|
42
|
-
const out = new Headers(headers);
|
|
43
|
-
if (context.accessToken) {
|
|
44
|
-
out.set('Authorization', `Zoho-oauthtoken ${context.accessToken}`);
|
|
45
|
-
}
|
|
46
|
-
out.set('User-Agent', context.userAgent);
|
|
47
|
-
if (hasJsonBody && !out.has('Content-Type')) {
|
|
48
|
-
out.set('Content-Type', 'application/json');
|
|
49
|
-
}
|
|
50
|
-
return out;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function shouldRetryStatus(status: number): boolean {
|
|
54
|
-
return status === 429 || status >= 500;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export class ZohoHttpClient {
|
|
58
|
-
private readonly context: RequestContext;
|
|
59
|
-
|
|
60
|
-
constructor(context: RequestContext) {
|
|
61
|
-
this.context = context;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
setAccessToken(accessToken: string): ZohoHttpClient {
|
|
65
|
-
return new ZohoHttpClient({ ...this.context, accessToken });
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async request<T>(path: string, options: RequestOptions = {}): Promise<T> {
|
|
69
|
-
if (!this.context.accessToken && !(options.headers && new Headers(options.headers).has('Authorization'))) {
|
|
70
|
-
throw new Error('Zoho Projects access token is required for API requests');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const method = (options.method ?? 'GET').toUpperCase();
|
|
74
|
-
const retry = options.retry ?? 0;
|
|
75
|
-
const url = /^https?:\/\//i.test(path)
|
|
76
|
-
? new URL(path)
|
|
77
|
-
: new URL(joinPath(this.context.baseUrl ?? DEFAULT_API_BASE_URL, path));
|
|
78
|
-
|
|
79
|
-
const queryString = serializeQuery(options.query);
|
|
80
|
-
if (queryString) {
|
|
81
|
-
url.search = queryString;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const hasJsonBody = options.body !== undefined && options.formData === undefined;
|
|
85
|
-
const headers = buildHeaders(this.context, options.headers, hasJsonBody);
|
|
86
|
-
|
|
87
|
-
let body: BodyInit | undefined;
|
|
88
|
-
if (options.formData) {
|
|
89
|
-
body = options.formData;
|
|
90
|
-
} else if (options.body !== undefined) {
|
|
91
|
-
body = JSON.stringify(options.body);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
let attempt = 0;
|
|
95
|
-
// Keep requests simple by only retrying when the caller opts in.
|
|
96
|
-
while (true) {
|
|
97
|
-
const init: RequestInit = {
|
|
98
|
-
method,
|
|
99
|
-
headers,
|
|
100
|
-
};
|
|
101
|
-
if (body !== undefined) {
|
|
102
|
-
init.body = body;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const response = await this.context.fetchImpl(url, init);
|
|
106
|
-
|
|
107
|
-
if (response.ok) {
|
|
108
|
-
if (response.status === 204) {
|
|
109
|
-
return undefined as T;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const contentType = response.headers.get('content-type') ?? '';
|
|
113
|
-
if (contentType.includes('application/json')) {
|
|
114
|
-
return (await response.json()) as T;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const text = await response.text();
|
|
118
|
-
if (!text) return undefined as T;
|
|
119
|
-
try {
|
|
120
|
-
return JSON.parse(text) as T;
|
|
121
|
-
} catch {
|
|
122
|
-
return text as T;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const responseBody = await safeReadBody(response);
|
|
127
|
-
const requestId = extractRequestId(response.headers);
|
|
128
|
-
const message =
|
|
129
|
-
(typeof responseBody === 'object' && responseBody !== null
|
|
130
|
-
? (responseBody as ZohoErrorPayload).message ?? (responseBody as ZohoErrorPayload).error
|
|
131
|
-
: undefined) ??
|
|
132
|
-
response.statusText ??
|
|
133
|
-
`Zoho Projects request failed with status ${response.status}`;
|
|
134
|
-
const errorInfo = {
|
|
135
|
-
status: response.status,
|
|
136
|
-
retryable: shouldRetryStatus(response.status),
|
|
137
|
-
responseBody,
|
|
138
|
-
...(requestId !== undefined ? { requestId } : {}),
|
|
139
|
-
};
|
|
140
|
-
const error = createApiError(message, errorInfo);
|
|
141
|
-
|
|
142
|
-
if (attempt < retry && error.retryable) {
|
|
143
|
-
attempt += 1;
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
throw error;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export function createDefaultHttpClient(
|
|
153
|
-
config: {
|
|
154
|
-
baseUrl?: string | undefined;
|
|
155
|
-
accessToken?: string | undefined;
|
|
156
|
-
userAgent?: string | undefined;
|
|
157
|
-
fetchImpl: typeof fetch;
|
|
158
|
-
},
|
|
159
|
-
): ZohoHttpClient {
|
|
160
|
-
return new ZohoHttpClient({
|
|
161
|
-
baseUrl: config.baseUrl ?? DEFAULT_API_BASE_URL,
|
|
162
|
-
accessToken: config.accessToken,
|
|
163
|
-
userAgent: config.userAgent ?? 'zoho-projects-wrapper/0.1.0',
|
|
164
|
-
fetchImpl: config.fetchImpl,
|
|
165
|
-
});
|
|
166
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export * from '@/client.ts';
|
|
2
|
-
export * from '@/errors.ts';
|
|
3
|
-
export * from '@/http.ts';
|
|
4
|
-
export * from '@/oauth.ts';
|
|
5
|
-
export * from '@/query.ts';
|
|
6
|
-
export * from '@/types.ts';
|
|
7
|
-
export * from '@/resources/custom-fields.ts';
|
|
8
|
-
export * from '@/resources/issues.ts';
|
|
9
|
-
export * from '@/resources/module-meta.ts';
|
|
10
|
-
export * from '@/resources/project-groups.ts';
|
|
11
|
-
export * from '@/resources/portals.ts';
|
|
12
|
-
export * from '@/resources/projects.ts';
|
|
13
|
-
export * from '@/resources/phases.ts';
|
|
14
|
-
export * from '@/resources/records.ts';
|
|
15
|
-
export * from '@/resources/time-logs.ts';
|
|
16
|
-
export * from '@/resources/tasklists.ts';
|
|
17
|
-
export * from '@/resources/tasks.ts';
|
|
18
|
-
export * from '@/resources/settings.ts';
|
|
19
|
-
export * from '@/tools.ts';
|
package/src/oauth.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import type { ZohoOAuthConfig, ZohoOAuthTokens } from '@/types.ts';
|
|
2
|
-
|
|
3
|
-
function toScopeValue(scope?: string | string[]): string | undefined {
|
|
4
|
-
if (!scope) return undefined;
|
|
5
|
-
return Array.isArray(scope) ? scope.join(',') : scope;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function buildAccountsUrl(baseUrl: string | undefined, path: string): string {
|
|
9
|
-
const normalizedBase = (baseUrl ?? 'https://accounts.zoho.com').replace(/\/+$/, '');
|
|
10
|
-
return `${normalizedBase}${path.startsWith('/') ? path : `/${path}`}`;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function createQuery(params: Record<string, string | undefined>): string {
|
|
14
|
-
const searchParams = new URLSearchParams();
|
|
15
|
-
for (const [key, value] of Object.entries(params)) {
|
|
16
|
-
if (value !== undefined && value !== '') {
|
|
17
|
-
searchParams.set(key, value);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return searchParams.toString();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async function postForm<T>(fetchImpl: typeof fetch, url: string, form: Record<string, string>): Promise<T> {
|
|
24
|
-
const body = new URLSearchParams(form);
|
|
25
|
-
const response = await fetchImpl(url, {
|
|
26
|
-
method: 'POST',
|
|
27
|
-
headers: {
|
|
28
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
29
|
-
},
|
|
30
|
-
body,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const text = await response.text();
|
|
34
|
-
if (!response.ok) {
|
|
35
|
-
throw new Error(text || `OAuth request failed with status ${response.status}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return (text ? JSON.parse(text) : {}) as T;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export class ZohoOAuthClient {
|
|
42
|
-
private readonly config: ZohoOAuthConfig;
|
|
43
|
-
private readonly fetchImpl: typeof fetch;
|
|
44
|
-
|
|
45
|
-
constructor(
|
|
46
|
-
config: ZohoOAuthConfig,
|
|
47
|
-
fetchImpl: typeof fetch = fetch,
|
|
48
|
-
) {
|
|
49
|
-
this.config = config;
|
|
50
|
-
this.fetchImpl = fetchImpl;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
authorizationUrl(overrides: Partial<ZohoOAuthConfig> = {}): string {
|
|
54
|
-
const merged = { ...this.config, ...overrides };
|
|
55
|
-
if (!merged.clientId) {
|
|
56
|
-
throw new Error('clientId is required to build the Zoho authorization URL');
|
|
57
|
-
}
|
|
58
|
-
const url = new URL(buildAccountsUrl(merged.accountsBaseUrl, '/oauth/v2/auth'));
|
|
59
|
-
const scope = toScopeValue(merged.scope);
|
|
60
|
-
|
|
61
|
-
const params = createQuery({
|
|
62
|
-
client_id: merged.clientId,
|
|
63
|
-
redirect_uri: merged.redirectUri,
|
|
64
|
-
response_type: 'code',
|
|
65
|
-
scope,
|
|
66
|
-
access_type: merged.accessType ?? 'offline',
|
|
67
|
-
prompt: merged.prompt,
|
|
68
|
-
state: merged.state,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
url.search = params;
|
|
72
|
-
return url.toString();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async exchangeCode(params: { code: string; redirectUri?: string }): Promise<ZohoOAuthTokens> {
|
|
76
|
-
if (!this.config.clientId) {
|
|
77
|
-
throw new Error('clientId is required to exchange an authorization code');
|
|
78
|
-
}
|
|
79
|
-
if (!this.config.clientSecret) {
|
|
80
|
-
throw new Error('clientSecret is required to exchange an authorization code');
|
|
81
|
-
}
|
|
82
|
-
const url = buildAccountsUrl(this.config.accountsBaseUrl, '/oauth/v2/token');
|
|
83
|
-
return postForm<ZohoOAuthTokens>(this.fetchImpl, url, {
|
|
84
|
-
code: params.code,
|
|
85
|
-
client_id: this.config.clientId,
|
|
86
|
-
client_secret: this.config.clientSecret ?? '',
|
|
87
|
-
redirect_uri: params.redirectUri ?? this.config.redirectUri ?? '',
|
|
88
|
-
grant_type: 'authorization_code',
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async refreshAccessToken(params: { refreshToken: string }): Promise<ZohoOAuthTokens> {
|
|
93
|
-
if (!this.config.clientId) {
|
|
94
|
-
throw new Error('clientId is required to refresh a Zoho access token');
|
|
95
|
-
}
|
|
96
|
-
if (!this.config.clientSecret) {
|
|
97
|
-
throw new Error('clientSecret is required to refresh a Zoho access token');
|
|
98
|
-
}
|
|
99
|
-
const url = buildAccountsUrl(this.config.accountsBaseUrl, '/oauth/v2/token');
|
|
100
|
-
return postForm<ZohoOAuthTokens>(this.fetchImpl, url, {
|
|
101
|
-
refresh_token: params.refreshToken,
|
|
102
|
-
client_id: this.config.clientId,
|
|
103
|
-
client_secret: this.config.clientSecret ?? '',
|
|
104
|
-
grant_type: 'refresh_token',
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
async revokeToken(params: { token: string }): Promise<{ status: string }> {
|
|
109
|
-
const url = `${buildAccountsUrl(this.config.accountsBaseUrl, '/oauth/v2/token/revoke')}?${createQuery({
|
|
110
|
-
token: params.token,
|
|
111
|
-
})}`;
|
|
112
|
-
const response = await this.fetchImpl(url, { method: 'POST' });
|
|
113
|
-
const text = await response.text();
|
|
114
|
-
|
|
115
|
-
if (!response.ok) {
|
|
116
|
-
throw new Error(text || `Token revoke failed with status ${response.status}`);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return (text ? JSON.parse(text) : { status: 'success' }) as { status: string };
|
|
120
|
-
}
|
|
121
|
-
}
|
package/src/query.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { ZohoFilter } from '@/types.ts';
|
|
2
|
-
|
|
3
|
-
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
4
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value) && !(value instanceof Date) && !(value instanceof FormData);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function encodeValue(value: unknown): string {
|
|
8
|
-
if (value instanceof Date) return value.toISOString();
|
|
9
|
-
if (typeof value === 'string') return value;
|
|
10
|
-
if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') return String(value);
|
|
11
|
-
if (value === null || value === undefined) return '';
|
|
12
|
-
return JSON.stringify(value);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function serializeQuery(query?: Record<string, unknown>): string {
|
|
16
|
-
if (!query) return '';
|
|
17
|
-
const params = new URLSearchParams();
|
|
18
|
-
|
|
19
|
-
for (const [key, value] of Object.entries(query)) {
|
|
20
|
-
if (value === undefined || value === null) continue;
|
|
21
|
-
|
|
22
|
-
if (Array.isArray(value)) {
|
|
23
|
-
params.set(key, JSON.stringify(value));
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (isPlainObject(value)) {
|
|
28
|
-
params.set(key, JSON.stringify(value));
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const encoded = encodeValue(value);
|
|
33
|
-
if (encoded !== '') params.set(key, encoded);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return params.toString();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function normalizeFilter(filter?: ZohoFilter): Record<string, unknown> | undefined {
|
|
40
|
-
if (!filter) return undefined;
|
|
41
|
-
return filter;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function mergeQuery(
|
|
45
|
-
query?: Record<string, unknown>,
|
|
46
|
-
filter?: ZohoFilter,
|
|
47
|
-
): Record<string, unknown> | undefined {
|
|
48
|
-
const merged = { ...(query ?? {}) };
|
|
49
|
-
if (filter) merged.filter = normalizeFilter(filter);
|
|
50
|
-
return Object.keys(merged).length > 0 ? merged : undefined;
|
|
51
|
-
}
|
package/src/resource-base.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { ZohoHttpClient } from '@/http.ts';
|
|
2
|
-
import type { ZohoFilter } from '@/types.ts';
|
|
3
|
-
import { mergeQuery } from '@/query.ts';
|
|
4
|
-
|
|
5
|
-
export abstract class ResourceBase {
|
|
6
|
-
protected readonly http: ZohoHttpClient;
|
|
7
|
-
|
|
8
|
-
constructor(http: ZohoHttpClient) {
|
|
9
|
-
this.http = http;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
protected request<T>(path: string, init: Parameters<ZohoHttpClient['request']>[1] = {}): Promise<T> {
|
|
13
|
-
return this.http.request<T>(path, init);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
protected get<T>(path: string, query?: Record<string, unknown>): Promise<T> {
|
|
17
|
-
return this.request<T>(path, { method: 'GET', query });
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
protected post<T>(path: string, body?: unknown, query?: Record<string, unknown>): Promise<T> {
|
|
21
|
-
return this.request<T>(path, { method: 'POST', body, query });
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
protected patch<T>(path: string, body?: unknown, query?: Record<string, unknown>): Promise<T> {
|
|
25
|
-
return this.request<T>(path, { method: 'PATCH', body, query });
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
protected put<T>(path: string, body?: unknown, query?: Record<string, unknown>): Promise<T> {
|
|
29
|
-
return this.request<T>(path, { method: 'PUT', body, query });
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
protected delete<T>(path: string, body?: unknown, query?: Record<string, unknown>): Promise<T> {
|
|
33
|
-
return this.request<T>(path, { method: 'DELETE', body, query });
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
protected withFilter(query?: Record<string, unknown>, filter?: ZohoFilter): Record<string, unknown> | undefined {
|
|
37
|
-
return mergeQuery(query, filter);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
protected buildPath(parts: Array<string | number | undefined>): string {
|
|
41
|
-
return parts
|
|
42
|
-
.filter((part): part is string | number => part !== undefined && part !== null)
|
|
43
|
-
.map((part) => encodeURIComponent(String(part)))
|
|
44
|
-
.join('/')
|
|
45
|
-
.replace(/\/+/g, '/');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
protected portalPath(portalId: string | number, ...parts: Array<string | number | undefined>): string {
|
|
49
|
-
return this.buildPath(['portal', portalId, ...parts]);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
protected projectPath(portalId: string | number, projectId: string | number, ...parts: Array<string | number | undefined>): string {
|
|
53
|
-
return this.buildPath(['portal', portalId, 'projects', projectId, ...parts]);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
protected modulePath(portalId: string | number, moduleName: string, ...parts: Array<string | number | undefined>): string {
|
|
57
|
-
return this.buildPath(['portal', portalId, 'settings', 'modules', moduleName, ...parts]);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ResourceBase } from '@/resource-base.ts';
|
|
2
|
-
import type { ZohoCustomField, ZohoFilter, ZohoListResponse, ZohoPageParams } from '@/types.ts';
|
|
3
|
-
|
|
4
|
-
export class CustomFieldsResource extends ResourceBase {
|
|
5
|
-
getFields(
|
|
6
|
-
portalId: string | number,
|
|
7
|
-
moduleName: string,
|
|
8
|
-
params: ZohoPageParams & {
|
|
9
|
-
filter?: ZohoFilter;
|
|
10
|
-
view_id?: string | number;
|
|
11
|
-
module?: string;
|
|
12
|
-
project_id?: string | number;
|
|
13
|
-
layout_id?: string | number;
|
|
14
|
-
field_ids?: Array<string | number>;
|
|
15
|
-
fields?: string[];
|
|
16
|
-
search_term?: string;
|
|
17
|
-
index?: number;
|
|
18
|
-
range?: number;
|
|
19
|
-
} = {},
|
|
20
|
-
): Promise<ZohoListResponse<ZohoCustomField>> {
|
|
21
|
-
return this.get(this.portalPath(portalId, 'settings', 'fields'), {
|
|
22
|
-
...params,
|
|
23
|
-
module: moduleName,
|
|
24
|
-
filter: params.filter,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
package/src/resources/issues.ts
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { ResourceBase } from '@/resource-base.ts';
|
|
2
|
-
import type { ZohoComment, ZohoFilter, ZohoIssue, ZohoListResponse, ZohoPageParams } from '@/types.ts';
|
|
3
|
-
|
|
4
|
-
export class IssuesResource extends ResourceBase {
|
|
5
|
-
listAll(portalId: string | number, params: ZohoPageParams & { sort_by?: string; view_id?: string | number; issue_ids?: string; filter?: ZohoFilter } = {}): Promise<ZohoListResponse<ZohoIssue>> {
|
|
6
|
-
return this.get(this.portalPath(portalId, 'issues'), this.withFilter(params, params.filter));
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
list(portalId: string | number, projectId: string | number, params: ZohoPageParams & { sort_by?: string; view_id?: string | number; issue_ids?: string; filter?: ZohoFilter } = {}): Promise<ZohoListResponse<ZohoIssue>> {
|
|
10
|
-
return this.get(this.projectPath(portalId, projectId, 'issues'), this.withFilter(params, params.filter));
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
getById(portalId: string | number, projectId: string | number, issueId: string | number): Promise<ZohoIssue> {
|
|
14
|
-
return this.get(this.projectPath(portalId, projectId, 'issues', issueId));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
create(portalId: string | number, projectId: string | number, body: Record<string, unknown>): Promise<ZohoIssue> {
|
|
18
|
-
return this.post(this.projectPath(portalId, projectId, 'issues'), body);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
deleteById(portalId: string | number, projectId: string | number, issueId: string | number): Promise<unknown> {
|
|
22
|
-
return this.delete(this.projectPath(portalId, projectId, 'issues', issueId));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
listCustomViews(portalId: string | number, projectId: string | number, query?: Record<string, unknown>): Promise<unknown> {
|
|
26
|
-
return this.get(this.projectPath(portalId, projectId, 'issues', 'customviews'), query);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
getAssociatedTasks(portalId: string | number, projectId: string | number, issueId: string | number, query?: Record<string, unknown>): Promise<unknown> {
|
|
30
|
-
return this.get(this.projectPath(portalId, projectId, 'issues', issueId, 'associated-tasks'), query);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
getAssociatedTasksByIssues(portalId: string | number, issueIds: Array<string | number>, query?: Record<string, unknown>): Promise<unknown> {
|
|
34
|
-
return this.get(this.buildPath(['portal', portalId, 'issues', 'associated-tasks']), {
|
|
35
|
-
...query,
|
|
36
|
-
issue_ids: issueIds,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
getComments(
|
|
41
|
-
portalId: string | number,
|
|
42
|
-
projectId: string | number,
|
|
43
|
-
issueId: string | number,
|
|
44
|
-
params: ZohoPageParams & { sort_by?: string; filter?: ZohoFilter } = {},
|
|
45
|
-
): Promise<ZohoListResponse<ZohoComment>> {
|
|
46
|
-
return this.get(this.projectPath(portalId, projectId, 'issues', issueId, 'comments'), this.withFilter(params, params.filter));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
getComment(
|
|
50
|
-
portalId: string | number,
|
|
51
|
-
projectId: string | number,
|
|
52
|
-
issueId: string | number,
|
|
53
|
-
commentId: string | number,
|
|
54
|
-
): Promise<Record<string, unknown>> {
|
|
55
|
-
return this.get(this.projectPath(portalId, projectId, 'issues', issueId, 'comments', commentId));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
addComment(
|
|
59
|
-
portalId: string | number,
|
|
60
|
-
projectId: string | number,
|
|
61
|
-
issueId: string | number,
|
|
62
|
-
body: { content: string; attachments?: Array<Record<string, unknown>> },
|
|
63
|
-
): Promise<Record<string, unknown>> {
|
|
64
|
-
return this.post(this.projectPath(portalId, projectId, 'issues', issueId, 'comments'), body);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
updateComment(
|
|
68
|
-
portalId: string | number,
|
|
69
|
-
projectId: string | number,
|
|
70
|
-
issueId: string | number,
|
|
71
|
-
commentId: string | number,
|
|
72
|
-
body: { content: string; attachments?: Array<Record<string, unknown>> },
|
|
73
|
-
): Promise<Record<string, unknown>> {
|
|
74
|
-
return this.patch(this.projectPath(portalId, projectId, 'issues', issueId, 'comments', commentId), body);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
deleteComment(portalId: string | number, projectId: string | number, issueId: string | number, commentId: string | number): Promise<unknown> {
|
|
78
|
-
return this.delete(this.projectPath(portalId, projectId, 'issues', issueId, 'comments', commentId));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
bulkAssociateTasks(
|
|
82
|
-
portalId: string | number,
|
|
83
|
-
projectId: string | number,
|
|
84
|
-
body: { issue_ids: Array<string | number>; task_ids: Array<string | number> },
|
|
85
|
-
): Promise<unknown> {
|
|
86
|
-
return this.post(this.projectPath(portalId, projectId, 'issues', 'bulk-associate-tasks'), body);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
bulkLinkIssues(
|
|
90
|
-
portalId: string | number,
|
|
91
|
-
projectId: string | number,
|
|
92
|
-
body: { link_type: string; issue_ids: Array<string | number>; linking_issue_ids: Array<string | number> | string },
|
|
93
|
-
): Promise<unknown> {
|
|
94
|
-
return this.post(this.projectPath(portalId, projectId, 'issues', 'bulk-link-bugs'), body);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
update(portalId: string | number, projectId: string | number, issueId: string | number, body: Partial<ZohoIssue>): Promise<ZohoIssue> {
|
|
98
|
-
return this.patch(this.projectPath(portalId, projectId, 'issues', issueId), body);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
move(portalId: string | number, projectId: string | number, issueId: string | number, body: { to_project: string | number }): Promise<unknown> {
|
|
102
|
-
return this.post(this.projectPath(portalId, projectId, 'issues', issueId, 'move'), body);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
getFollowers(portalId: string | number, projectId: string | number, issueId: string | number, query?: Record<string, unknown>): Promise<unknown> {
|
|
106
|
-
return this.get(this.projectPath(portalId, projectId, 'issues', issueId, 'followers'), query);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
addFollowers(portalId: string | number, projectId: string | number, issueId: string | number, body?: Record<string, unknown>): Promise<unknown> {
|
|
110
|
-
return this.post(this.projectPath(portalId, projectId, 'issues', issueId, 'followers'), body);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
removeFollowers(portalId: string | number, projectId: string | number, issueId: string | number, body?: Record<string, unknown>): Promise<unknown> {
|
|
114
|
-
return this.delete(this.projectPath(portalId, projectId, 'issues', issueId, 'followers'), body);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
getLinkedIssues(portalId: string | number, projectId: string | number, issueId: string | number): Promise<unknown> {
|
|
118
|
-
return this.get(this.projectPath(portalId, projectId, 'issues', issueId, 'linkedissues'));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
associateTasks(portalId: string | number, projectId: string | number, issueId: string | number, body: { task_ids: Array<string | number> }): Promise<unknown> {
|
|
122
|
-
const form = new FormData();
|
|
123
|
-
form.set('task_ids', JSON.stringify(body.task_ids));
|
|
124
|
-
return this.request(this.projectPath(portalId, projectId, 'issues', issueId, 'associate-tasks'), {
|
|
125
|
-
method: 'POST',
|
|
126
|
-
formData: form,
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
getAttachments(portalId: string | number, projectId: string | number, issueId: string | number): Promise<unknown> {
|
|
131
|
-
return this.get(this.projectPath(portalId, projectId, 'issues', issueId, 'attachments'));
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
addAttachments(portalId: string | number, projectId: string | number, issueId: string | number, body: { attachment_ids: Array<string | number> }): Promise<unknown> {
|
|
135
|
-
const form = new FormData();
|
|
136
|
-
form.set('attachment_ids', JSON.stringify(body.attachment_ids));
|
|
137
|
-
return this.request(this.projectPath(portalId, projectId, 'issues', issueId, 'attachments'), {
|
|
138
|
-
method: 'POST',
|
|
139
|
-
formData: form,
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
removeAttachment(portalId: string | number, projectId: string | number, issueId: string | number, attachmentId: string | number): Promise<unknown> {
|
|
144
|
-
return this.delete(this.projectPath(portalId, projectId, 'issues', issueId, 'attachments', attachmentId));
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
dissociateTask(portalId: string | number, projectId: string | number, issueId: string | number, taskId: string | number): Promise<unknown> {
|
|
148
|
-
return this.delete(this.projectPath(portalId, projectId, 'issues', issueId, 'task', taskId));
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
getStatusTransition(portalId: string | number, projectId: string | number, issueId: string | number): Promise<unknown> {
|
|
152
|
-
return this.get(this.projectPath(portalId, projectId, 'issues', issueId, 'statustransition'));
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
addResolution(portalId: string | number, projectId: string | number, issueId: string | number, body: Record<string, unknown>): Promise<unknown> {
|
|
156
|
-
return this.post(this.projectPath(portalId, projectId, 'issues', issueId, 'resolution'), body);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
updateResolution(portalId: string | number, projectId: string | number, issueId: string | number, body: Record<string, unknown>): Promise<unknown> {
|
|
160
|
-
return this.put(this.projectPath(portalId, projectId, 'issues', issueId, 'resolution'), body);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
getCommentAttachment(portalId: string | number, projectId: string | number, issueId: string | number, commentId: string | number): Promise<unknown> {
|
|
164
|
-
return this.get(this.projectPath(portalId, projectId, 'issues', issueId, 'attachments', 'comments'), { comment_id: commentId });
|
|
165
|
-
}
|
|
166
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { SettingsResource as ModuleMetaResource } from '@/resources/settings.ts';
|