@wats/graph 0.3.11 → 0.3.13

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.
@@ -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,6 +5,7 @@ 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";
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ 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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wats/graph",
3
- "version": "0.3.11",
3
+ "version": "0.3.13",
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"