@wats/graph 0.3.13 → 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/index.d.ts CHANGED
@@ -10,6 +10,8 @@ export * from "./endpoints/wabaEndpoints.js";
10
10
  export * from "./endpoint.js";
11
11
  export { PhoneNumberClient, validatePhoneNumberClientConfig } from "./subclients/phoneNumberClient.js";
12
12
  export type { PhoneNumberClientConfig } from "./subclients/phoneNumberClient.js";
13
+ export { GroupClient, validateGroupClientConfig } from "./subclients/groupClient.js";
14
+ export type { GroupClientConfig } from "./subclients/groupClient.js";
13
15
  export { WABAClient, validateWABAClientConfig } from "./subclients/wabaClient.js";
14
16
  export type { WABAClientConfig } from "./subclients/wabaClient.js";
15
17
  export * from "./transport.js";
package/dist/index.js CHANGED
@@ -12,6 +12,10 @@ export {
12
12
  PhoneNumberClient,
13
13
  validatePhoneNumberClientConfig
14
14
  } from "./subclients/phoneNumberClient.js";
15
+ export {
16
+ GroupClient,
17
+ validateGroupClientConfig
18
+ } from "./subclients/groupClient.js";
15
19
  export {
16
20
  WABAClient,
17
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.13",
3
+ "version": "0.3.14",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",