@wats/graph 0.3.12 → 0.3.14
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/dist/endpoints/groups/callables.d.ts +66 -0
- package/dist/endpoints/groups/callables.js +196 -0
- package/dist/endpoints/groups/index.d.ts +4 -0
- package/dist/endpoints/groups/index.js +19 -0
- package/dist/endpoints/groups/shared.d.ts +29 -0
- package/dist/endpoints/groups/shared.js +114 -0
- package/dist/endpoints/groups/types.d.ts +108 -0
- package/dist/endpoints/groups/types.js +0 -0
- package/dist/endpoints/groups.d.ts +5 -0
- package/dist/endpoints/groups.js +17 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -0
- package/dist/subclients/groupClient.d.ts +32 -0
- package/dist/subclients/groupClient.js +105 -0
- package/dist/subclients/phoneNumberClient.d.ts +8 -0
- package/dist/subclients/phoneNumberClient.js +16 -0
- package/package.json +5 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type EndpointInvokeOptions } from "../../endpoint.js";
|
|
2
|
+
import type { GraphClient } from "../../client.js";
|
|
3
|
+
import type { CreateGroupBody, CreateGroupParams, GetGroupParams, GroupDetails, GroupIdParams, GroupInviteLinkResponse, GroupJoinRequestsResponse, GroupMutationResponse, ListGroupJoinRequestsParams, ListGroupsParams, ListGroupsResponse, ManageGroupJoinRequestsBody, RemoveGroupParticipantsBody, UpdateGroupBody } from "./types.js";
|
|
4
|
+
type WireBody = Record<string, unknown>;
|
|
5
|
+
export declare const createGroup: ((client: GraphClient, params: CreateGroupParams, body: CreateGroupBody, opts?: EndpointInvokeOptions) => Promise<GroupMutationResponse>) & {
|
|
6
|
+
definition: import("../../endpoint.js").EndpointDefinition<{
|
|
7
|
+
phoneNumberId: string;
|
|
8
|
+
}, WireBody, GroupMutationResponse>;
|
|
9
|
+
};
|
|
10
|
+
export declare const listGroups: ((client: GraphClient, params: ListGroupsParams, body?: never, opts?: EndpointInvokeOptions) => Promise<ListGroupsResponse>) & {
|
|
11
|
+
definition: import("../../endpoint.js").EndpointDefinition<{
|
|
12
|
+
phoneNumberId: string;
|
|
13
|
+
limit?: string;
|
|
14
|
+
after?: string;
|
|
15
|
+
before?: string;
|
|
16
|
+
}, never, ListGroupsResponse>;
|
|
17
|
+
};
|
|
18
|
+
export declare const getGroup: ((client: GraphClient, params: GetGroupParams, body?: never, opts?: EndpointInvokeOptions) => Promise<GroupDetails>) & {
|
|
19
|
+
definition: import("../../endpoint.js").EndpointDefinition<{
|
|
20
|
+
groupId: string;
|
|
21
|
+
fields?: string;
|
|
22
|
+
}, never, GroupDetails>;
|
|
23
|
+
};
|
|
24
|
+
export declare const updateGroup: ((client: GraphClient, params: GroupIdParams, body: UpdateGroupBody, opts?: EndpointInvokeOptions) => Promise<GroupMutationResponse>) & {
|
|
25
|
+
definition: import("../../endpoint.js").EndpointDefinition<{
|
|
26
|
+
groupId: string;
|
|
27
|
+
}, WireBody, GroupMutationResponse>;
|
|
28
|
+
};
|
|
29
|
+
export declare const deleteGroup: ((client: GraphClient, params: GroupIdParams, body?: never, opts?: EndpointInvokeOptions) => Promise<GroupMutationResponse>) & {
|
|
30
|
+
definition: import("../../endpoint.js").EndpointDefinition<{
|
|
31
|
+
groupId: string;
|
|
32
|
+
}, never, GroupMutationResponse>;
|
|
33
|
+
};
|
|
34
|
+
export declare const getGroupInviteLink: ((client: GraphClient, params: GroupIdParams, body?: never, opts?: EndpointInvokeOptions) => Promise<GroupInviteLinkResponse>) & {
|
|
35
|
+
definition: import("../../endpoint.js").EndpointDefinition<{
|
|
36
|
+
groupId: string;
|
|
37
|
+
}, never, GroupInviteLinkResponse>;
|
|
38
|
+
};
|
|
39
|
+
export declare const resetGroupInviteLink: ((client: GraphClient, params: GroupIdParams, body?: never, opts?: EndpointInvokeOptions) => Promise<GroupInviteLinkResponse>) & {
|
|
40
|
+
definition: import("../../endpoint.js").EndpointDefinition<{
|
|
41
|
+
groupId: string;
|
|
42
|
+
}, WireBody, GroupInviteLinkResponse>;
|
|
43
|
+
};
|
|
44
|
+
export declare const listGroupJoinRequests: ((client: GraphClient, params: ListGroupJoinRequestsParams, body?: never, opts?: EndpointInvokeOptions) => Promise<GroupJoinRequestsResponse>) & {
|
|
45
|
+
definition: import("../../endpoint.js").EndpointDefinition<{
|
|
46
|
+
groupId: string;
|
|
47
|
+
limit?: string;
|
|
48
|
+
after?: string;
|
|
49
|
+
}, never, GroupJoinRequestsResponse>;
|
|
50
|
+
};
|
|
51
|
+
export declare const approveGroupJoinRequests: ((client: GraphClient, params: GroupIdParams, body: ManageGroupJoinRequestsBody, opts?: EndpointInvokeOptions) => Promise<GroupMutationResponse>) & {
|
|
52
|
+
definition: import("../../endpoint.js").EndpointDefinition<{
|
|
53
|
+
groupId: string;
|
|
54
|
+
}, WireBody, GroupMutationResponse>;
|
|
55
|
+
};
|
|
56
|
+
export declare const rejectGroupJoinRequests: ((client: GraphClient, params: GroupIdParams, body: ManageGroupJoinRequestsBody, opts?: EndpointInvokeOptions) => Promise<GroupMutationResponse>) & {
|
|
57
|
+
definition: import("../../endpoint.js").EndpointDefinition<{
|
|
58
|
+
groupId: string;
|
|
59
|
+
}, WireBody, GroupMutationResponse>;
|
|
60
|
+
};
|
|
61
|
+
export declare const removeGroupParticipants: ((client: GraphClient, params: GroupIdParams, body: RemoveGroupParticipantsBody, opts?: EndpointInvokeOptions) => Promise<GroupMutationResponse>) & {
|
|
62
|
+
definition: import("../../endpoint.js").EndpointDefinition<{
|
|
63
|
+
groupId: string;
|
|
64
|
+
}, WireBody, GroupMutationResponse>;
|
|
65
|
+
};
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { defineEndpoint } from "../../endpoint.js";
|
|
2
|
+
import {
|
|
3
|
+
GROUP_DESCRIPTION_MAX_LENGTH,
|
|
4
|
+
GROUP_MAX_JOIN_REQUESTS,
|
|
5
|
+
GROUP_MAX_PARTICIPANTS,
|
|
6
|
+
GROUP_SUBJECT_MAX_LENGTH,
|
|
7
|
+
groupAssertPlainRecord,
|
|
8
|
+
groupError,
|
|
9
|
+
groupJoinApprovalMode,
|
|
10
|
+
groupMaybeString,
|
|
11
|
+
groupPathParam,
|
|
12
|
+
groupString,
|
|
13
|
+
groupStringArray
|
|
14
|
+
} from "./shared.js";
|
|
15
|
+
function buildCreateGroupBody(body) {
|
|
16
|
+
const record = groupAssertPlainRecord(body, "createGroup");
|
|
17
|
+
const out = {
|
|
18
|
+
messaging_product: "whatsapp",
|
|
19
|
+
subject: groupString(record.subject, "subject", "createGroup", GROUP_SUBJECT_MAX_LENGTH)
|
|
20
|
+
};
|
|
21
|
+
const description = groupMaybeString(record.description, "description", "createGroup", GROUP_DESCRIPTION_MAX_LENGTH);
|
|
22
|
+
if (description !== undefined)
|
|
23
|
+
out.description = description;
|
|
24
|
+
const mode = groupJoinApprovalMode(record.joinApprovalMode, "createGroup");
|
|
25
|
+
if (mode !== undefined)
|
|
26
|
+
out.join_approval_mode = mode;
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
function buildUpdateGroupBody(body) {
|
|
30
|
+
const record = groupAssertPlainRecord(body, "updateGroup");
|
|
31
|
+
const out = { messaging_product: "whatsapp" };
|
|
32
|
+
const subject = groupMaybeString(record.subject, "subject", "updateGroup", GROUP_SUBJECT_MAX_LENGTH);
|
|
33
|
+
if (subject !== undefined)
|
|
34
|
+
out.subject = subject;
|
|
35
|
+
const description = groupMaybeString(record.description, "description", "updateGroup", GROUP_DESCRIPTION_MAX_LENGTH);
|
|
36
|
+
if (description !== undefined)
|
|
37
|
+
out.description = description;
|
|
38
|
+
const mode = groupJoinApprovalMode(record.joinApprovalMode, "updateGroup");
|
|
39
|
+
if (mode !== undefined)
|
|
40
|
+
out.join_approval_mode = mode;
|
|
41
|
+
if (Object.keys(out).length === 1) {
|
|
42
|
+
throw groupError("Invalid updateGroup input: at least one of subject, description, or joinApprovalMode must be provided.");
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
function buildManageJoinRequestsBody(body, action, helperName) {
|
|
47
|
+
const record = groupAssertPlainRecord(body, helperName);
|
|
48
|
+
const ids = groupStringArray(record.joinRequestIds, "joinRequestIds", helperName, 1, GROUP_MAX_JOIN_REQUESTS);
|
|
49
|
+
return {
|
|
50
|
+
messaging_product: "whatsapp",
|
|
51
|
+
action,
|
|
52
|
+
join_requests: ids.map((id) => ({ join_request_id: id }))
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function buildRemoveParticipantsBody(body) {
|
|
56
|
+
const record = groupAssertPlainRecord(body, "removeGroupParticipants");
|
|
57
|
+
const waIds = groupStringArray(record.waIds, "waIds", "removeGroupParticipants", 1, GROUP_MAX_PARTICIPANTS);
|
|
58
|
+
return {
|
|
59
|
+
messaging_product: "whatsapp",
|
|
60
|
+
action: "remove",
|
|
61
|
+
participants: waIds.map((wa) => ({ wa_id: wa }))
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const createGroupRaw = defineEndpoint({
|
|
65
|
+
method: "POST",
|
|
66
|
+
pathTemplate: "/{phoneNumberId}/groups",
|
|
67
|
+
params: { phoneNumberId: { in: "path", required: true } },
|
|
68
|
+
bodyContentType: "application/json"
|
|
69
|
+
});
|
|
70
|
+
export const createGroup = Object.assign(async function createGroup(client, params, body, opts) {
|
|
71
|
+
return createGroupRaw(client, { phoneNumberId: groupPathParam(params, "createGroup", "phoneNumberId") }, buildCreateGroupBody(body), opts);
|
|
72
|
+
}, { definition: createGroupRaw.definition });
|
|
73
|
+
const listGroupsRaw = defineEndpoint({
|
|
74
|
+
method: "GET",
|
|
75
|
+
pathTemplate: "/{phoneNumberId}/groups",
|
|
76
|
+
params: {
|
|
77
|
+
phoneNumberId: { in: "path", required: true },
|
|
78
|
+
limit: { in: "query" },
|
|
79
|
+
after: { in: "query" },
|
|
80
|
+
before: { in: "query" }
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
export const listGroups = Object.assign(async function listGroups(client, params, body, opts) {
|
|
84
|
+
const record = groupAssertPlainRecord(params, "listGroups", "params");
|
|
85
|
+
const query = {
|
|
86
|
+
phoneNumberId: groupPathParam(params, "listGroups", "phoneNumberId")
|
|
87
|
+
};
|
|
88
|
+
if (record.limit !== undefined) {
|
|
89
|
+
query.limit = groupString(record.limit, "limit", "listGroups", 32);
|
|
90
|
+
}
|
|
91
|
+
if (record.after !== undefined) {
|
|
92
|
+
query.after = groupString(record.after, "after", "listGroups", 4096);
|
|
93
|
+
}
|
|
94
|
+
if (record.before !== undefined) {
|
|
95
|
+
query.before = groupString(record.before, "before", "listGroups", 4096);
|
|
96
|
+
}
|
|
97
|
+
return listGroupsRaw(client, query, body, opts);
|
|
98
|
+
}, { definition: listGroupsRaw.definition });
|
|
99
|
+
const getGroupRaw = defineEndpoint({
|
|
100
|
+
method: "GET",
|
|
101
|
+
pathTemplate: "/{groupId}",
|
|
102
|
+
params: { groupId: { in: "path", required: true }, fields: { in: "query" } }
|
|
103
|
+
});
|
|
104
|
+
export const getGroup = Object.assign(async function getGroup(client, params, body, opts) {
|
|
105
|
+
const record = groupAssertPlainRecord(params, "getGroup", "params");
|
|
106
|
+
const query = {
|
|
107
|
+
groupId: groupPathParam(params, "getGroup", "groupId")
|
|
108
|
+
};
|
|
109
|
+
if (record.fields !== undefined) {
|
|
110
|
+
query.fields = groupString(record.fields, "fields", "getGroup", 4096);
|
|
111
|
+
}
|
|
112
|
+
return getGroupRaw(client, query, body, opts);
|
|
113
|
+
}, { definition: getGroupRaw.definition });
|
|
114
|
+
const updateGroupRaw = defineEndpoint({
|
|
115
|
+
method: "POST",
|
|
116
|
+
pathTemplate: "/{groupId}",
|
|
117
|
+
params: { groupId: { in: "path", required: true } },
|
|
118
|
+
bodyContentType: "application/json"
|
|
119
|
+
});
|
|
120
|
+
export const updateGroup = Object.assign(async function updateGroup(client, params, body, opts) {
|
|
121
|
+
return updateGroupRaw(client, { groupId: groupPathParam(params, "updateGroup", "groupId") }, buildUpdateGroupBody(body), opts);
|
|
122
|
+
}, { definition: updateGroupRaw.definition });
|
|
123
|
+
const deleteGroupRaw = defineEndpoint({
|
|
124
|
+
method: "DELETE",
|
|
125
|
+
pathTemplate: "/{groupId}",
|
|
126
|
+
params: { groupId: { in: "path", required: true } }
|
|
127
|
+
});
|
|
128
|
+
export const deleteGroup = Object.assign(async function deleteGroup(client, params, body, opts) {
|
|
129
|
+
return deleteGroupRaw(client, { groupId: groupPathParam(params, "deleteGroup", "groupId") }, body, opts);
|
|
130
|
+
}, { definition: deleteGroupRaw.definition });
|
|
131
|
+
const getGroupInviteLinkRaw = defineEndpoint({
|
|
132
|
+
method: "GET",
|
|
133
|
+
pathTemplate: "/{groupId}/invite_link",
|
|
134
|
+
params: { groupId: { in: "path", required: true } }
|
|
135
|
+
});
|
|
136
|
+
export const getGroupInviteLink = Object.assign(async function getGroupInviteLink(client, params, body, opts) {
|
|
137
|
+
return getGroupInviteLinkRaw(client, { groupId: groupPathParam(params, "getGroupInviteLink", "groupId") }, body, opts);
|
|
138
|
+
}, { definition: getGroupInviteLinkRaw.definition });
|
|
139
|
+
const resetGroupInviteLinkRaw = defineEndpoint({
|
|
140
|
+
method: "POST",
|
|
141
|
+
pathTemplate: "/{groupId}/invite_link",
|
|
142
|
+
params: { groupId: { in: "path", required: true } },
|
|
143
|
+
bodyContentType: "application/json"
|
|
144
|
+
});
|
|
145
|
+
export const resetGroupInviteLink = Object.assign(async function resetGroupInviteLink(client, params, body, opts) {
|
|
146
|
+
return resetGroupInviteLinkRaw(client, { groupId: groupPathParam(params, "resetGroupInviteLink", "groupId") }, { messaging_product: "whatsapp" }, opts);
|
|
147
|
+
}, { definition: resetGroupInviteLinkRaw.definition });
|
|
148
|
+
const listGroupJoinRequestsRaw = defineEndpoint({
|
|
149
|
+
method: "GET",
|
|
150
|
+
pathTemplate: "/{groupId}/join_requests",
|
|
151
|
+
params: {
|
|
152
|
+
groupId: { in: "path", required: true },
|
|
153
|
+
limit: { in: "query" },
|
|
154
|
+
after: { in: "query" }
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
export const listGroupJoinRequests = Object.assign(async function listGroupJoinRequests(client, params, body, opts) {
|
|
158
|
+
const record = groupAssertPlainRecord(params, "listGroupJoinRequests", "params");
|
|
159
|
+
const query = {
|
|
160
|
+
groupId: groupPathParam(params, "listGroupJoinRequests", "groupId")
|
|
161
|
+
};
|
|
162
|
+
if (record.limit !== undefined) {
|
|
163
|
+
query.limit = groupString(record.limit, "limit", "listGroupJoinRequests", 32);
|
|
164
|
+
}
|
|
165
|
+
if (record.after !== undefined) {
|
|
166
|
+
query.after = groupString(record.after, "after", "listGroupJoinRequests", 4096);
|
|
167
|
+
}
|
|
168
|
+
return listGroupJoinRequestsRaw(client, query, body, opts);
|
|
169
|
+
}, { definition: listGroupJoinRequestsRaw.definition });
|
|
170
|
+
const approveGroupJoinRequestsRaw = defineEndpoint({
|
|
171
|
+
method: "POST",
|
|
172
|
+
pathTemplate: "/{groupId}/join_requests",
|
|
173
|
+
params: { groupId: { in: "path", required: true } },
|
|
174
|
+
bodyContentType: "application/json"
|
|
175
|
+
});
|
|
176
|
+
const rejectGroupJoinRequestsRaw = defineEndpoint({
|
|
177
|
+
method: "DELETE",
|
|
178
|
+
pathTemplate: "/{groupId}/join_requests",
|
|
179
|
+
params: { groupId: { in: "path", required: true } },
|
|
180
|
+
bodyContentType: "application/json"
|
|
181
|
+
});
|
|
182
|
+
export const approveGroupJoinRequests = Object.assign(async function approveGroupJoinRequests(client, params, body, opts) {
|
|
183
|
+
return approveGroupJoinRequestsRaw(client, { groupId: groupPathParam(params, "approveGroupJoinRequests", "groupId") }, buildManageJoinRequestsBody(body, "approve", "approveGroupJoinRequests"), opts);
|
|
184
|
+
}, { definition: approveGroupJoinRequestsRaw.definition });
|
|
185
|
+
export const rejectGroupJoinRequests = Object.assign(async function rejectGroupJoinRequests(client, params, body, opts) {
|
|
186
|
+
return rejectGroupJoinRequestsRaw(client, { groupId: groupPathParam(params, "rejectGroupJoinRequests", "groupId") }, buildManageJoinRequestsBody(body, "reject", "rejectGroupJoinRequests"), opts);
|
|
187
|
+
}, { definition: rejectGroupJoinRequestsRaw.definition });
|
|
188
|
+
const removeGroupParticipantsRaw = defineEndpoint({
|
|
189
|
+
method: "DELETE",
|
|
190
|
+
pathTemplate: "/{groupId}/participants",
|
|
191
|
+
params: { groupId: { in: "path", required: true } },
|
|
192
|
+
bodyContentType: "application/json"
|
|
193
|
+
});
|
|
194
|
+
export const removeGroupParticipants = Object.assign(async function removeGroupParticipants(client, params, body, opts) {
|
|
195
|
+
return removeGroupParticipantsRaw(client, { groupId: groupPathParam(params, "removeGroupParticipants", "groupId") }, buildRemoveParticipantsBody(body), opts);
|
|
196
|
+
}, { definition: removeGroupParticipantsRaw.definition });
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { approveGroupJoinRequests, createGroup, deleteGroup, getGroup, getGroupInviteLink, listGroupJoinRequests, listGroups, rejectGroupJoinRequests, removeGroupParticipants, resetGroupInviteLink, updateGroup } from "./callables.js";
|
|
2
|
+
export { GROUP_DESCRIPTION_MAX_LENGTH, GROUP_MAX_JOIN_REQUESTS, GROUP_MAX_PARTICIPANTS, GROUP_SUBJECT_MAX_LENGTH } from "./shared.js";
|
|
3
|
+
export type { GraphPaging } from "../waba/types.js";
|
|
4
|
+
export type { CreateGroupBody, CreateGroupParams, GetGroupParams, GroupDetails, GroupIdParams, GroupInviteLinkResponse, GroupJoinApprovalMode, GroupJoinRequestWire, GroupJoinRequestsResponse, GroupMutationResponse, GroupParticipantWire, GroupSummaryWire, ListGroupJoinRequestsParams, ListGroupsParams, ListGroupsResponse, ManageGroupJoinRequestsBody, RemoveGroupParticipantsBody, UpdateGroupBody } from "./types.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export {
|
|
2
|
+
approveGroupJoinRequests,
|
|
3
|
+
createGroup,
|
|
4
|
+
deleteGroup,
|
|
5
|
+
getGroup,
|
|
6
|
+
getGroupInviteLink,
|
|
7
|
+
listGroupJoinRequests,
|
|
8
|
+
listGroups,
|
|
9
|
+
rejectGroupJoinRequests,
|
|
10
|
+
removeGroupParticipants,
|
|
11
|
+
resetGroupInviteLink,
|
|
12
|
+
updateGroup
|
|
13
|
+
} from "./callables.js";
|
|
14
|
+
export {
|
|
15
|
+
GROUP_DESCRIPTION_MAX_LENGTH,
|
|
16
|
+
GROUP_MAX_JOIN_REQUESTS,
|
|
17
|
+
GROUP_MAX_PARTICIPANTS,
|
|
18
|
+
GROUP_SUBJECT_MAX_LENGTH
|
|
19
|
+
} from "./shared.js";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { GraphRequestValidationError } from "../../errors.js";
|
|
2
|
+
import type { GroupJoinApprovalMode } from "./types.js";
|
|
3
|
+
/** Subject max length (wire: `subject`). */
|
|
4
|
+
export declare const GROUP_SUBJECT_MAX_LENGTH = 128;
|
|
5
|
+
/** Description max length (wire: `description`). */
|
|
6
|
+
export declare const GROUP_DESCRIPTION_MAX_LENGTH = 2048;
|
|
7
|
+
/** Max participants excluding the business creator. */
|
|
8
|
+
export declare const GROUP_MAX_PARTICIPANTS = 8;
|
|
9
|
+
/** Max join requests addressable in a single approve/reject call. */
|
|
10
|
+
export declare const GROUP_MAX_JOIN_REQUESTS = 64;
|
|
11
|
+
export declare function groupError(message: string): GraphRequestValidationError;
|
|
12
|
+
export declare function groupHasControlChar(value: string): boolean;
|
|
13
|
+
export declare function groupIsUnsafeObjectKey(key: string): boolean;
|
|
14
|
+
export declare function groupAssertPlainRecord(value: unknown, helperName: string, path?: string): Record<string, unknown>;
|
|
15
|
+
export declare function groupString(value: unknown, fieldName: string, helperName: string, maxLength: number): string;
|
|
16
|
+
export declare function groupMaybeString(value: unknown, fieldName: string, helperName: string, maxLength: number): string | undefined;
|
|
17
|
+
export declare function groupJoinApprovalMode(value: unknown, helperName: string): GroupJoinApprovalMode | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Validate a bounded, non-empty array of opaque id strings (join-request
|
|
20
|
+
* ids or wa_ids), enforcing min/max and rejecting prototype-poisoned or
|
|
21
|
+
* accessor-bearing arrays.
|
|
22
|
+
*/
|
|
23
|
+
export declare function groupStringArray(value: unknown, fieldName: string, helperName: string, min: number, max: number, itemMaxLength?: number): string[];
|
|
24
|
+
/**
|
|
25
|
+
* Extract a required, string-valued path-param data property safely
|
|
26
|
+
* (no accessors), then run it through the field-length/control-char gate.
|
|
27
|
+
* The endpoint sanitizer applies path-segment safety on top.
|
|
28
|
+
*/
|
|
29
|
+
export declare function groupPathParam(input: unknown, helperName: string, fieldName: string): string;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { GraphRequestValidationError } from "../../errors.js";
|
|
2
|
+
export const GROUP_SUBJECT_MAX_LENGTH = 128;
|
|
3
|
+
export const GROUP_DESCRIPTION_MAX_LENGTH = 2048;
|
|
4
|
+
export const GROUP_MAX_PARTICIPANTS = 8;
|
|
5
|
+
export const GROUP_MAX_JOIN_REQUESTS = 64;
|
|
6
|
+
const JOIN_APPROVAL_MODES = new Set([
|
|
7
|
+
"auto_approve",
|
|
8
|
+
"approval_required"
|
|
9
|
+
]);
|
|
10
|
+
export function groupError(message) {
|
|
11
|
+
return new GraphRequestValidationError(message);
|
|
12
|
+
}
|
|
13
|
+
export function groupHasControlChar(value) {
|
|
14
|
+
for (let i = 0;i < value.length; i += 1) {
|
|
15
|
+
const code = value.charCodeAt(i);
|
|
16
|
+
if (code < 32 || code === 127)
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
export function groupIsUnsafeObjectKey(key) {
|
|
22
|
+
return key === "__proto__" || key === "constructor" || key === "prototype";
|
|
23
|
+
}
|
|
24
|
+
function isPlainObject(value) {
|
|
25
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26
|
+
}
|
|
27
|
+
export function groupAssertPlainRecord(value, helperName, path = "input") {
|
|
28
|
+
if (!isPlainObject(value)) {
|
|
29
|
+
throw groupError(`Invalid ${helperName} input: ${path} must be an object.`);
|
|
30
|
+
}
|
|
31
|
+
const proto = Object.getPrototypeOf(value);
|
|
32
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
33
|
+
throw groupError(`Invalid ${helperName} input: ${path} must be a plain object.`);
|
|
34
|
+
}
|
|
35
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
36
|
+
if (Object.prototype.hasOwnProperty.call(descriptors, "toJSON") || "toJSON" in value) {
|
|
37
|
+
throw groupError(`Invalid ${helperName} input: ${path} must not define toJSON.`);
|
|
38
|
+
}
|
|
39
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
40
|
+
if (groupIsUnsafeObjectKey(key)) {
|
|
41
|
+
throw groupError(`Invalid ${helperName} input: ${path} contains an unsafe prototype key.`);
|
|
42
|
+
}
|
|
43
|
+
if (typeof descriptor.get === "function" || typeof descriptor.set === "function") {
|
|
44
|
+
throw groupError(`Invalid ${helperName} input: ${path}.${key} must not use accessors.`);
|
|
45
|
+
}
|
|
46
|
+
if (typeof descriptor.value === "function" || typeof descriptor.value === "symbol") {
|
|
47
|
+
throw groupError(`Invalid ${helperName} input: ${path}.${key} must be JSON-serializable.`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
export function groupString(value, fieldName, helperName, maxLength) {
|
|
53
|
+
if (typeof value !== "string") {
|
|
54
|
+
throw groupError(`Invalid ${helperName} input: ${fieldName} must be a string.`);
|
|
55
|
+
}
|
|
56
|
+
if (value.length === 0 || value.trim().length === 0) {
|
|
57
|
+
throw groupError(`Invalid ${helperName} input: ${fieldName} must be non-empty.`);
|
|
58
|
+
}
|
|
59
|
+
if (groupHasControlChar(value)) {
|
|
60
|
+
throw groupError(`Invalid ${helperName} input: ${fieldName} must not contain control characters.`);
|
|
61
|
+
}
|
|
62
|
+
if (value.length > maxLength) {
|
|
63
|
+
throw groupError(`Invalid ${helperName} input: ${fieldName} exceeds ${maxLength}-character limit.`);
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
export function groupMaybeString(value, fieldName, helperName, maxLength) {
|
|
68
|
+
if (value === undefined)
|
|
69
|
+
return;
|
|
70
|
+
return groupString(value, fieldName, helperName, maxLength);
|
|
71
|
+
}
|
|
72
|
+
export function groupJoinApprovalMode(value, helperName) {
|
|
73
|
+
if (value === undefined)
|
|
74
|
+
return;
|
|
75
|
+
if (typeof value !== "string" || !JOIN_APPROVAL_MODES.has(value)) {
|
|
76
|
+
throw groupError(`Invalid ${helperName} input: joinApprovalMode must be one of "auto_approve" | "approval_required".`);
|
|
77
|
+
}
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
export function groupStringArray(value, fieldName, helperName, min, max, itemMaxLength = 256) {
|
|
81
|
+
if (!Array.isArray(value)) {
|
|
82
|
+
throw groupError(`Invalid ${helperName} input: ${fieldName} must be an array.`);
|
|
83
|
+
}
|
|
84
|
+
if (value.length < min || value.length > max) {
|
|
85
|
+
throw groupError(`Invalid ${helperName} input: ${fieldName} length must be between ${min} and ${max}.`);
|
|
86
|
+
}
|
|
87
|
+
if (Object.getPrototypeOf(value) !== Array.prototype) {
|
|
88
|
+
throw groupError(`Invalid ${helperName} input: ${fieldName} must use Array.prototype.`);
|
|
89
|
+
}
|
|
90
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
91
|
+
if (Object.prototype.hasOwnProperty.call(descriptors, "toJSON") || "toJSON" in value) {
|
|
92
|
+
throw groupError(`Invalid ${helperName} input: ${fieldName} must not define toJSON.`);
|
|
93
|
+
}
|
|
94
|
+
const out = [];
|
|
95
|
+
for (let index = 0;index < value.length; index += 1) {
|
|
96
|
+
if (!Object.prototype.hasOwnProperty.call(value, index)) {
|
|
97
|
+
throw groupError(`Invalid ${helperName} input: ${fieldName} must not contain sparse array holes.`);
|
|
98
|
+
}
|
|
99
|
+
const descriptor = descriptors[String(index)];
|
|
100
|
+
if (descriptor === undefined || typeof descriptor.get === "function" || typeof descriptor.set === "function") {
|
|
101
|
+
throw groupError(`Invalid ${helperName} input: ${fieldName} must not use accessors.`);
|
|
102
|
+
}
|
|
103
|
+
out.push(groupString(descriptor.value, `${fieldName}[${index}]`, helperName, itemMaxLength));
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
export function groupPathParam(input, helperName, fieldName) {
|
|
108
|
+
const record = groupAssertPlainRecord(input, helperName, "params");
|
|
109
|
+
const descriptor = Object.getOwnPropertyDescriptor(record, fieldName);
|
|
110
|
+
if (descriptor === undefined || typeof descriptor.get === "function" || typeof descriptor.set === "function" || typeof descriptor.value !== "string") {
|
|
111
|
+
throw groupError(`Invalid ${helperName} input: ${fieldName} must be a string data property.`);
|
|
112
|
+
}
|
|
113
|
+
return groupString(descriptor.value, fieldName, helperName, 256);
|
|
114
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { GraphPaging } from "../waba/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Group join-approval policy. `auto_approve` lets anyone with the invite
|
|
4
|
+
* link join immediately; `approval_required` routes joins through the
|
|
5
|
+
* join-request approval queue. Mirrors the `GroupJoinApprovalMode` public
|
|
6
|
+
* type in @wats/types/groups (WATS-131) at the Graph transport boundary.
|
|
7
|
+
*/
|
|
8
|
+
export type GroupJoinApprovalMode = "auto_approve" | "approval_required";
|
|
9
|
+
/** Wire-shaped participant as returned by Graph (`wa_id`). */
|
|
10
|
+
export interface GroupParticipantWire {
|
|
11
|
+
readonly wa_id?: string;
|
|
12
|
+
readonly [key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
/** Group metadata response from `GET /<group-id>` (raw Graph wire). */
|
|
15
|
+
export interface GroupDetails {
|
|
16
|
+
readonly id?: string;
|
|
17
|
+
readonly subject?: string;
|
|
18
|
+
readonly description?: string;
|
|
19
|
+
readonly join_approval_mode?: GroupJoinApprovalMode;
|
|
20
|
+
readonly suspended?: boolean;
|
|
21
|
+
readonly creation_timestamp?: number;
|
|
22
|
+
readonly total_participant_count?: number;
|
|
23
|
+
readonly participants?: readonly GroupParticipantWire[];
|
|
24
|
+
readonly [key: string]: unknown;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Async mutation acknowledgement. Group create/update/participant/join
|
|
28
|
+
* operations are asynchronous on the Cloud API: the HTTP call returns a
|
|
29
|
+
* `request_id` correlator and the outcome is delivered via the matching
|
|
30
|
+
* `group_*_update` webhook.
|
|
31
|
+
*/
|
|
32
|
+
export interface GroupMutationResponse {
|
|
33
|
+
readonly request_id?: string;
|
|
34
|
+
readonly success?: boolean;
|
|
35
|
+
readonly [key: string]: unknown;
|
|
36
|
+
}
|
|
37
|
+
/** Invite-link response from `GET /<group-id>/invite_link`. */
|
|
38
|
+
export interface GroupInviteLinkResponse {
|
|
39
|
+
readonly invite_link?: string;
|
|
40
|
+
readonly [key: string]: unknown;
|
|
41
|
+
}
|
|
42
|
+
/** A single group summary as returned by `GET /<phone-number-id>/groups`. */
|
|
43
|
+
export interface GroupSummaryWire {
|
|
44
|
+
readonly id?: string;
|
|
45
|
+
readonly subject?: string;
|
|
46
|
+
readonly created_at?: string;
|
|
47
|
+
readonly [key: string]: unknown;
|
|
48
|
+
}
|
|
49
|
+
/** Active-groups listing from `GET /<phone-number-id>/groups`. */
|
|
50
|
+
export interface ListGroupsResponse {
|
|
51
|
+
readonly data?: {
|
|
52
|
+
readonly groups?: readonly GroupSummaryWire[];
|
|
53
|
+
} | readonly GroupSummaryWire[];
|
|
54
|
+
readonly paging?: GraphPaging;
|
|
55
|
+
readonly [key: string]: unknown;
|
|
56
|
+
}
|
|
57
|
+
/** A single pending join request (raw Graph wire). */
|
|
58
|
+
export interface GroupJoinRequestWire {
|
|
59
|
+
readonly join_request_id?: string;
|
|
60
|
+
readonly wa_id?: string;
|
|
61
|
+
readonly creation_timestamp?: number;
|
|
62
|
+
readonly [key: string]: unknown;
|
|
63
|
+
}
|
|
64
|
+
/** Join-request listing from `GET /<group-id>/join_requests`. */
|
|
65
|
+
export interface GroupJoinRequestsResponse {
|
|
66
|
+
readonly data?: readonly GroupJoinRequestWire[];
|
|
67
|
+
readonly paging?: GraphPaging;
|
|
68
|
+
readonly [key: string]: unknown;
|
|
69
|
+
}
|
|
70
|
+
export interface CreateGroupParams {
|
|
71
|
+
readonly phoneNumberId: string;
|
|
72
|
+
}
|
|
73
|
+
export interface ListGroupsParams {
|
|
74
|
+
readonly phoneNumberId: string;
|
|
75
|
+
readonly limit?: string;
|
|
76
|
+
readonly after?: string;
|
|
77
|
+
readonly before?: string;
|
|
78
|
+
}
|
|
79
|
+
export interface CreateGroupBody {
|
|
80
|
+
readonly subject: string;
|
|
81
|
+
readonly description?: string;
|
|
82
|
+
readonly joinApprovalMode?: GroupJoinApprovalMode;
|
|
83
|
+
readonly [key: string]: unknown;
|
|
84
|
+
}
|
|
85
|
+
export interface GetGroupParams {
|
|
86
|
+
readonly groupId: string;
|
|
87
|
+
readonly fields?: string;
|
|
88
|
+
}
|
|
89
|
+
export interface GroupIdParams {
|
|
90
|
+
readonly groupId: string;
|
|
91
|
+
}
|
|
92
|
+
export interface UpdateGroupBody {
|
|
93
|
+
readonly subject?: string;
|
|
94
|
+
readonly description?: string;
|
|
95
|
+
readonly joinApprovalMode?: GroupJoinApprovalMode;
|
|
96
|
+
readonly [key: string]: unknown;
|
|
97
|
+
}
|
|
98
|
+
export interface ListGroupJoinRequestsParams {
|
|
99
|
+
readonly groupId: string;
|
|
100
|
+
readonly limit?: string;
|
|
101
|
+
readonly after?: string;
|
|
102
|
+
}
|
|
103
|
+
export interface ManageGroupJoinRequestsBody {
|
|
104
|
+
readonly joinRequestIds: readonly string[];
|
|
105
|
+
}
|
|
106
|
+
export interface RemoveGroupParticipantsBody {
|
|
107
|
+
readonly waIds: readonly string[];
|
|
108
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @experimental Groups endpoint helpers may change in 0.x minors while WATS expands Groups API parity.
|
|
3
|
+
*/
|
|
4
|
+
export { GROUP_DESCRIPTION_MAX_LENGTH, GROUP_MAX_JOIN_REQUESTS, GROUP_MAX_PARTICIPANTS, GROUP_SUBJECT_MAX_LENGTH, approveGroupJoinRequests, createGroup, deleteGroup, getGroup, getGroupInviteLink, listGroupJoinRequests, listGroups, rejectGroupJoinRequests, removeGroupParticipants, resetGroupInviteLink, updateGroup } from "./groups/index.js";
|
|
5
|
+
export type { CreateGroupBody, CreateGroupParams, GetGroupParams, GraphPaging, GroupDetails, GroupIdParams, GroupInviteLinkResponse, GroupJoinApprovalMode, GroupJoinRequestWire, GroupJoinRequestsResponse, GroupMutationResponse, GroupParticipantWire, GroupSummaryWire, ListGroupJoinRequestsParams, ListGroupsParams, ListGroupsResponse, ManageGroupJoinRequestsBody, RemoveGroupParticipantsBody, UpdateGroupBody } from "./groups/index.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export {
|
|
2
|
+
GROUP_DESCRIPTION_MAX_LENGTH,
|
|
3
|
+
GROUP_MAX_JOIN_REQUESTS,
|
|
4
|
+
GROUP_MAX_PARTICIPANTS,
|
|
5
|
+
GROUP_SUBJECT_MAX_LENGTH,
|
|
6
|
+
approveGroupJoinRequests,
|
|
7
|
+
createGroup,
|
|
8
|
+
deleteGroup,
|
|
9
|
+
getGroup,
|
|
10
|
+
getGroupInviteLink,
|
|
11
|
+
listGroupJoinRequests,
|
|
12
|
+
listGroups,
|
|
13
|
+
rejectGroupJoinRequests,
|
|
14
|
+
removeGroupParticipants,
|
|
15
|
+
resetGroupInviteLink,
|
|
16
|
+
updateGroup
|
|
17
|
+
} from "./groups/index.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -5,10 +5,13 @@ export * from "./errorSubclasses.js";
|
|
|
5
5
|
export * from "./endpoints/messages.js";
|
|
6
6
|
export * from "./endpoints/calling.js";
|
|
7
7
|
export * from "./endpoints/businessManagement.js";
|
|
8
|
+
export * from "./endpoints/groups.js";
|
|
8
9
|
export * from "./endpoints/wabaEndpoints.js";
|
|
9
10
|
export * from "./endpoint.js";
|
|
10
11
|
export { PhoneNumberClient, validatePhoneNumberClientConfig } from "./subclients/phoneNumberClient.js";
|
|
11
12
|
export type { PhoneNumberClientConfig } from "./subclients/phoneNumberClient.js";
|
|
13
|
+
export { GroupClient, validateGroupClientConfig } from "./subclients/groupClient.js";
|
|
14
|
+
export type { GroupClientConfig } from "./subclients/groupClient.js";
|
|
12
15
|
export { WABAClient, validateWABAClientConfig } from "./subclients/wabaClient.js";
|
|
13
16
|
export type { WABAClientConfig } from "./subclients/wabaClient.js";
|
|
14
17
|
export * from "./transport.js";
|
package/dist/index.js
CHANGED
|
@@ -5,12 +5,17 @@ export * from "./errorSubclasses.js";
|
|
|
5
5
|
export * from "./endpoints/messages.js";
|
|
6
6
|
export * from "./endpoints/calling.js";
|
|
7
7
|
export * from "./endpoints/businessManagement.js";
|
|
8
|
+
export * from "./endpoints/groups.js";
|
|
8
9
|
export * from "./endpoints/wabaEndpoints.js";
|
|
9
10
|
export * from "./endpoint.js";
|
|
10
11
|
export {
|
|
11
12
|
PhoneNumberClient,
|
|
12
13
|
validatePhoneNumberClientConfig
|
|
13
14
|
} from "./subclients/phoneNumberClient.js";
|
|
15
|
+
export {
|
|
16
|
+
GroupClient,
|
|
17
|
+
validateGroupClientConfig
|
|
18
|
+
} from "./subclients/groupClient.js";
|
|
14
19
|
export {
|
|
15
20
|
WABAClient,
|
|
16
21
|
validateWABAClientConfig
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { GraphClient } from "../client.js";
|
|
2
|
+
import type { EndpointInvokeOptions } from "../endpoint.js";
|
|
3
|
+
import { type GetGroupParams, type GroupDetails, type GroupInviteLinkResponse, type GroupJoinRequestsResponse, type GroupMutationResponse, type ListGroupJoinRequestsParams, type ManageGroupJoinRequestsBody, type RemoveGroupParticipantsBody, type UpdateGroupBody } from "../endpoints/groups.js";
|
|
4
|
+
export interface GroupClientConfig {
|
|
5
|
+
readonly graphClient: GraphClient;
|
|
6
|
+
readonly groupId: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function validateGroupClientConfig(config: GroupClientConfig): void;
|
|
9
|
+
export declare class GroupClient {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(config: GroupClientConfig);
|
|
12
|
+
get groupId(): string;
|
|
13
|
+
get graphClient(): GraphClient;
|
|
14
|
+
/** Graph `GET /{groupId}` — returns group metadata and participant fields. */
|
|
15
|
+
getInfo(params?: Omit<GetGroupParams, "groupId">, opts?: EndpointInvokeOptions): Promise<GroupDetails>;
|
|
16
|
+
/** Graph `POST /{groupId}` — update subject, description, or join approval mode. */
|
|
17
|
+
update(body: UpdateGroupBody, opts?: EndpointInvokeOptions): Promise<GroupMutationResponse>;
|
|
18
|
+
/** Graph `DELETE /{groupId}`. */
|
|
19
|
+
delete(params?: Record<string, never>, opts?: EndpointInvokeOptions): Promise<GroupMutationResponse>;
|
|
20
|
+
/** Graph `GET /{groupId}/invite_link`. */
|
|
21
|
+
getInviteLink(params?: Record<string, never>, opts?: EndpointInvokeOptions): Promise<GroupInviteLinkResponse>;
|
|
22
|
+
/** Graph `POST /{groupId}/invite_link` — resets the invite link. */
|
|
23
|
+
resetInviteLink(params?: Record<string, never>, opts?: EndpointInvokeOptions): Promise<GroupInviteLinkResponse>;
|
|
24
|
+
/** Graph `DELETE /{groupId}/participants` — remove up to 8 participants. */
|
|
25
|
+
removeParticipants(body: RemoveGroupParticipantsBody, opts?: EndpointInvokeOptions): Promise<GroupMutationResponse>;
|
|
26
|
+
/** Graph `GET /{groupId}/join_requests`. */
|
|
27
|
+
getJoinRequests(params?: Omit<ListGroupJoinRequestsParams, "groupId">, opts?: EndpointInvokeOptions): Promise<GroupJoinRequestsResponse>;
|
|
28
|
+
/** Graph `POST /{groupId}/join_requests` — approve pending join requests. */
|
|
29
|
+
approveJoinRequests(body: ManageGroupJoinRequestsBody, opts?: EndpointInvokeOptions): Promise<GroupMutationResponse>;
|
|
30
|
+
/** Graph `DELETE /{groupId}/join_requests` — reject pending join requests. */
|
|
31
|
+
rejectJoinRequests(body: ManageGroupJoinRequestsBody, opts?: EndpointInvokeOptions): Promise<GroupMutationResponse>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
export class GroupClient {
|
|
2
|
+
#graphClient;
|
|
3
|
+
#groupId;
|
|
4
|
+
constructor(config) {
|
|
5
|
+
validateGroupClientConfig(config);
|
|
6
|
+
this.#graphClient = config.graphClient;
|
|
7
|
+
this.#groupId = config.groupId;
|
|
8
|
+
}
|
|
9
|
+
get groupId() {
|
|
10
|
+
return this.#groupId;
|
|
11
|
+
}
|
|
12
|
+
get graphClient() {
|
|
13
|
+
return this.#graphClient;
|
|
14
|
+
}
|
|
15
|
+
async getInfo(params, opts) {
|
|
16
|
+
const scopedParams = copyOptionalParamsObject(params, "GroupClient.getInfo");
|
|
17
|
+
scopedParams.groupId = this.#groupId;
|
|
18
|
+
return getGroupEndpoint(this.#graphClient, scopedParams, undefined, opts);
|
|
19
|
+
}
|
|
20
|
+
async update(body, opts) {
|
|
21
|
+
return updateGroupEndpoint(this.#graphClient, { groupId: this.#groupId }, body, opts);
|
|
22
|
+
}
|
|
23
|
+
async delete(params, opts) {
|
|
24
|
+
copyOptionalParamsObject(params, "GroupClient.delete");
|
|
25
|
+
return deleteGroupEndpoint(this.#graphClient, { groupId: this.#groupId }, undefined, opts);
|
|
26
|
+
}
|
|
27
|
+
async getInviteLink(params, opts) {
|
|
28
|
+
copyOptionalParamsObject(params, "GroupClient.getInviteLink");
|
|
29
|
+
return getGroupInviteLinkEndpoint(this.#graphClient, { groupId: this.#groupId }, undefined, opts);
|
|
30
|
+
}
|
|
31
|
+
async resetInviteLink(params, opts) {
|
|
32
|
+
copyOptionalParamsObject(params, "GroupClient.resetInviteLink");
|
|
33
|
+
return resetGroupInviteLinkEndpoint(this.#graphClient, { groupId: this.#groupId }, undefined, opts);
|
|
34
|
+
}
|
|
35
|
+
async removeParticipants(body, opts) {
|
|
36
|
+
return removeGroupParticipantsEndpoint(this.#graphClient, { groupId: this.#groupId }, body, opts);
|
|
37
|
+
}
|
|
38
|
+
async getJoinRequests(params, opts) {
|
|
39
|
+
const scopedParams = copyOptionalParamsObject(params, "GroupClient.getJoinRequests");
|
|
40
|
+
scopedParams.groupId = this.#groupId;
|
|
41
|
+
return listGroupJoinRequestsEndpoint(this.#graphClient, scopedParams, undefined, opts);
|
|
42
|
+
}
|
|
43
|
+
async approveJoinRequests(body, opts) {
|
|
44
|
+
return approveGroupJoinRequestsEndpoint(this.#graphClient, { groupId: this.#groupId }, body, opts);
|
|
45
|
+
}
|
|
46
|
+
async rejectJoinRequests(body, opts) {
|
|
47
|
+
return rejectGroupJoinRequestsEndpoint(this.#graphClient, { groupId: this.#groupId }, body, opts);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
import { assertSafePathParamValue } from "../endpoint.js";
|
|
51
|
+
import { GraphRequestValidationError } from "../errors.js";
|
|
52
|
+
import { copyOptionalParamsObject } from "../internal/validation/options.js";
|
|
53
|
+
import {
|
|
54
|
+
approveGroupJoinRequests as approveGroupJoinRequestsEndpoint,
|
|
55
|
+
deleteGroup as deleteGroupEndpoint,
|
|
56
|
+
getGroup as getGroupEndpoint,
|
|
57
|
+
getGroupInviteLink as getGroupInviteLinkEndpoint,
|
|
58
|
+
listGroupJoinRequests as listGroupJoinRequestsEndpoint,
|
|
59
|
+
rejectGroupJoinRequests as rejectGroupJoinRequestsEndpoint,
|
|
60
|
+
removeGroupParticipants as removeGroupParticipantsEndpoint,
|
|
61
|
+
resetGroupInviteLink as resetGroupInviteLinkEndpoint,
|
|
62
|
+
updateGroup as updateGroupEndpoint
|
|
63
|
+
} from "../endpoints/groups.js";
|
|
64
|
+
function hasRequestMethod(candidate) {
|
|
65
|
+
if (candidate === null || typeof candidate !== "object") {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const maybe = candidate;
|
|
69
|
+
return typeof maybe.request === "function";
|
|
70
|
+
}
|
|
71
|
+
function assertNoEncodedUnsafePathParam(value, fieldName) {
|
|
72
|
+
let decoded = value;
|
|
73
|
+
for (let round = 0;round < 8; round += 1) {
|
|
74
|
+
let next;
|
|
75
|
+
try {
|
|
76
|
+
next = decodeURIComponent(decoded);
|
|
77
|
+
} catch {
|
|
78
|
+
throw new GraphRequestValidationError(`Invalid GroupClient config: ${fieldName} contains malformed percent encoding.`);
|
|
79
|
+
}
|
|
80
|
+
if (next === decoded)
|
|
81
|
+
return;
|
|
82
|
+
decoded = next;
|
|
83
|
+
if (decoded === "." || decoded === ".." || decoded.includes("/") || decoded.includes("\\") || decoded.includes("?") || decoded.includes("#")) {
|
|
84
|
+
throw new GraphRequestValidationError(`Invalid GroupClient config: ${fieldName} contains an unsafe path segment.`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
throw new GraphRequestValidationError(`Invalid GroupClient config: ${fieldName} contains excessive percent encoding.`);
|
|
88
|
+
}
|
|
89
|
+
export function validateGroupClientConfig(config) {
|
|
90
|
+
if (typeof config !== "object" || config === null) {
|
|
91
|
+
throw new GraphRequestValidationError("Invalid GroupClient config: expected an options object.");
|
|
92
|
+
}
|
|
93
|
+
const raw = config;
|
|
94
|
+
if (!hasRequestMethod(raw.graphClient)) {
|
|
95
|
+
throw new GraphRequestValidationError("Invalid GroupClient config: graphClient must expose a request() method.");
|
|
96
|
+
}
|
|
97
|
+
if (typeof raw.groupId !== "string") {
|
|
98
|
+
throw new GraphRequestValidationError("Invalid GroupClient config: groupId must be a non-empty string.");
|
|
99
|
+
}
|
|
100
|
+
if (raw.groupId.length === 0 || raw.groupId.trim().length === 0) {
|
|
101
|
+
throw new GraphRequestValidationError("Invalid GroupClient config: groupId must be a non-empty string.");
|
|
102
|
+
}
|
|
103
|
+
assertSafePathParamValue("groupId", raw.groupId);
|
|
104
|
+
assertNoEncodedUnsafePathParam(raw.groupId, "groupId");
|
|
105
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { GraphClient } from "../client.js";
|
|
2
2
|
import type { EndpointInvokeOptions } from "../endpoint.js";
|
|
3
|
+
import { GroupClient } from "./groupClient.js";
|
|
3
4
|
import { type BlockUsersInput, type BlockUsersResponse, type BlockedUsersResponse, type BusinessProfileResponse, type CommerceSettingsResponse, type GetBusinessProfileInput, type GetCommerceSettingsInput, type GetOfficialBusinessAccountStatusInput, type GetPhoneNumberInfoInput, type GetPhoneNumberSettingsInput, type ListBlockedUsersInput, type OfficialBusinessAccountReviewResponse, type OfficialBusinessAccountStatusResponse, type PhoneNumberInfo, type PhoneNumberSettingsResponse, type PhoneNumberSettingsUpdateResponse, type RequestOfficialBusinessAccountReviewInput, type SubmitDisplayNameForReviewInput, type SubmitDisplayNameForReviewResponse, type UnblockUsersInput, type UnblockUsersResponse, type UpdatePhoneNumberSettingsInput } from "../endpoints/businessManagement.js";
|
|
4
5
|
import { type AcceptCallRequest, type CallLifecycleResponse, type InitiateCallRequest, type PreAcceptCallRequest, type RejectCallRequest, type TerminateCallRequest } from "../endpoints/calling.js";
|
|
6
|
+
import { type CreateGroupBody, type GroupMutationResponse, type ListGroupsParams, type ListGroupsResponse } from "../endpoints/groups.js";
|
|
5
7
|
import { type GraphMessagesMarkMessageAsReadInput, type GraphMessagesRemoveReactionInput, type GraphMessagesRequestLocationInput, type GraphMessagesSendAudioInput, type GraphMessagesSendBody, type GraphMessagesSendButtonsInput, type GraphMessagesSendCallPermissionRequestInput, type GraphMessagesSendCatalogInput, type GraphMessagesSendContactsInput, type GraphMessagesSendCtaUrlInput, type GraphMessagesSendDocumentInput, type GraphMessagesSendImageInput, type GraphMessagesSendListInput, type GraphMessagesSendLocationInput, type GraphMessagesSendMarketingTemplateInput, type GraphMessagesMarketingTemplateResponse, type GraphMessagesSendProductInput, type GraphMessagesSendProductsInput, type GraphMessagesSendReactionInput, type GraphMessagesSendResponse, type GraphMessagesSendStickerInput, type GraphMessagesSendTemplateInput, type GraphMessagesSendTextInput, type GraphMessagesSendVideoInput, type GraphMessagesTypingIndicatorInput } from "../endpoints/messages.js";
|
|
6
8
|
export interface PhoneNumberClientConfig {
|
|
7
9
|
readonly graphClient: GraphClient;
|
|
@@ -13,6 +15,12 @@ export declare class PhoneNumberClient {
|
|
|
13
15
|
constructor(config: PhoneNumberClientConfig);
|
|
14
16
|
get phoneNumberId(): string;
|
|
15
17
|
get graphClient(): GraphClient;
|
|
18
|
+
/** Return a group-scoped client bound to a validated WhatsApp group id. */
|
|
19
|
+
group(groupId: string): GroupClient;
|
|
20
|
+
/** Graph `POST /{phoneNumberId}/groups` — create an invite-only business group. */
|
|
21
|
+
createGroup(body: CreateGroupBody, opts?: EndpointInvokeOptions): Promise<GroupMutationResponse>;
|
|
22
|
+
/** Graph `GET /{phoneNumberId}/groups` — list groups owned by this business number. */
|
|
23
|
+
listGroups(params?: Omit<ListGroupsParams, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<ListGroupsResponse>;
|
|
16
24
|
/** Graph `GET /{phoneNumberId}` — returns phone-number inventory/profile fields. */
|
|
17
25
|
getInfo(params?: Omit<GetPhoneNumberInfoInput, "phoneNumberId">, opts?: EndpointInvokeOptions): Promise<PhoneNumberInfo>;
|
|
18
26
|
/** Graph `GET /{phoneNumberId}/settings`; includeSipCredentials responses may be sensitive. */
|
|
@@ -12,6 +12,17 @@ export class PhoneNumberClient {
|
|
|
12
12
|
get graphClient() {
|
|
13
13
|
return this.#graphClient;
|
|
14
14
|
}
|
|
15
|
+
group(groupId) {
|
|
16
|
+
return new GroupClient({ graphClient: this.#graphClient, groupId });
|
|
17
|
+
}
|
|
18
|
+
async createGroup(body, opts) {
|
|
19
|
+
return createGroupEndpoint(this.#graphClient, { phoneNumberId: this.#phoneNumberId }, body, opts);
|
|
20
|
+
}
|
|
21
|
+
async listGroups(params, opts) {
|
|
22
|
+
const scopedParams = copyOptionalParamsObject(params, "PhoneNumberClient.listGroups");
|
|
23
|
+
scopedParams.phoneNumberId = this.#phoneNumberId;
|
|
24
|
+
return listGroupsEndpoint(this.#graphClient, scopedParams, undefined, opts);
|
|
25
|
+
}
|
|
15
26
|
async getInfo(params, opts) {
|
|
16
27
|
const scopedParams = copyOptionalParamsObject(params, "PhoneNumberClient.getInfo");
|
|
17
28
|
scopedParams.phoneNumberId = this.#phoneNumberId;
|
|
@@ -176,6 +187,7 @@ export class PhoneNumberClient {
|
|
|
176
187
|
import { assertSafePathParamValue } from "../endpoint.js";
|
|
177
188
|
import { GraphRequestValidationError } from "../errors.js";
|
|
178
189
|
import { copyOptionalParamsObject } from "../internal/validation/options.js";
|
|
190
|
+
import { GroupClient } from "./groupClient.js";
|
|
179
191
|
import {
|
|
180
192
|
getBusinessProfile as getBusinessProfileEndpoint,
|
|
181
193
|
getCommerceSettings as getCommerceSettingsEndpoint,
|
|
@@ -196,6 +208,10 @@ import {
|
|
|
196
208
|
rejectCall as rejectCallEndpoint,
|
|
197
209
|
terminateCall as terminateCallEndpoint
|
|
198
210
|
} from "../endpoints/calling.js";
|
|
211
|
+
import {
|
|
212
|
+
createGroup as createGroupEndpoint,
|
|
213
|
+
listGroups as listGroupsEndpoint
|
|
214
|
+
} from "../endpoints/groups.js";
|
|
199
215
|
import {
|
|
200
216
|
buildMarkMessageAsReadPayload,
|
|
201
217
|
buildRemoveReactionPayload,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wats/graph",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.14",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -43,6 +43,10 @@
|
|
|
43
43
|
"types": "./dist/endpoints/businessManagement.d.ts",
|
|
44
44
|
"import": "./dist/endpoints/businessManagement.js"
|
|
45
45
|
},
|
|
46
|
+
"./endpoints/groups": {
|
|
47
|
+
"types": "./dist/endpoints/groups.d.ts",
|
|
48
|
+
"import": "./dist/endpoints/groups.js"
|
|
49
|
+
},
|
|
46
50
|
"./transport": {
|
|
47
51
|
"types": "./dist/transport.d.ts",
|
|
48
52
|
"import": "./dist/transport.js"
|