Skip to content

Commit

Permalink
Merge branch 'v1.2-next' into DEVEXP-519_E2E-SMS/Webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
asein-sinch authored Aug 22, 2024
2 parents d276a51 + e25ff05 commit a1ecf5f
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 44 deletions.
8 changes: 4 additions & 4 deletions examples/simple-examples/src/sms/groups/list/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import {
import { getPrintFormat, printFullResponse } from '../../../config';

const populateGroupsList = (
groupsPage: PageResult<Sms.CreateGroupResponse>,
fullGroupsList: Sms.CreateGroupResponse[],
groupsPage: PageResult<Sms.Group>,
fullGroupsList: Sms.Group[],
groupsList: string[],
) => {
// Populate the data structure that holds the response content
fullGroupsList.push(...groupsPage.data);
// Populate the data structure that holds the response content for pretty print
groupsPage.data.map((group: Sms.CreateGroupResponse) => {
groupsPage.data.map((group: Sms.Group) => {
groupsList.push(`Group ID: ${group.id} - Group name: ${group.name}`);
});
};
Expand All @@ -39,7 +39,7 @@ export const list = async(smsService: SmsService) => {
}

// Init data structure to hold the response content
const fullGroupsList: Sms.CreateGroupResponse[] = [];
const fullGroupsList: Sms.Group[] = [];
// Init data structure to hold the response content for pretty print
const groupsList: string[] = [];

Expand Down
4 changes: 0 additions & 4 deletions packages/sms/src/models/v1/create-group-response/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GroupAutoUpdate } from '../group-auto-update';

export interface CreateGroupResponse {
export interface Group {

/** The ID used to reference this group. */
id?: string;
Expand Down
1 change: 1 addition & 0 deletions packages/sms/src/models/v1/group/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { Group } from './group';
2 changes: 1 addition & 1 deletion packages/sms/src/models/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export * from './api-update-mt-message';
export * from './api-update-text-mt-message';
export * from './binary-request';
export * from './binary-response';
export * from './create-group-response';
export * from './group';
export * from './delivery-report';
export * from './delivery-report-list';
export * from './dry-run-request';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CreateGroupResponse } from '../create-group-response';
import { Group } from '../group';

export interface ListGroupsResponse {

Expand All @@ -9,7 +9,7 @@ export interface ListGroupsResponse {
/** The total number of groups. */
count?: number;
/** List of GroupObjects */
groups?: CreateGroupResponse[];
groups?: Group[];
}


Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UpdateGroupRequestAutoUpdate } from '../update-group-request-auto-updat
export interface UpdateGroupRequest {

/** The name of the group. Omitting `name` from the JSON body will leave the name unchanged. To remove an existing name set, name explicitly to the JSON value `null`. */
name?: string;
name?: string | null;
/** Add a list of phone numbers (MSISDNs) to this group. The phone numbers are a strings within an array and must be in <a href=\"https://community.sinch.com/t5/Glossary/E-164/ta-p/7537\" target=\"_blank\">E.164 format</a>. */
add?: string[];
/** Remove a list of phone numbers (MSISDNs) to this group.The phone numbers are a strings within an array and must be in <a href=\"https://community.sinch.com/t5/Glossary/E-164/ta-p/7537\" target=\"_blank\">E.164 format</a>. */
Expand Down
13 changes: 6 additions & 7 deletions packages/sms/src/rest/v1/groups/groups-api.jest.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { GroupsApi } from './groups-api';
import {
CreateGroupResponse,
GroupResponse,
Group,
CreateGroupRequestData,
DeleteGroupRequestData,
ListMembersRequestData,
Expand All @@ -17,7 +16,7 @@ export class GroupsApiFixture implements Partial<Readonly<GroupsApi>> {
/**
* Fixture associated to function createGroup
*/
public create: jest.Mock<Promise<CreateGroupResponse>, [CreateGroupRequestData]> = jest.fn();
public create: jest.Mock<Promise<Group>, [CreateGroupRequestData]> = jest.fn();
/**
* Fixture associated to function deleteGroup
*/
Expand All @@ -29,17 +28,17 @@ export class GroupsApiFixture implements Partial<Readonly<GroupsApi>> {
/**
* Fixture associated to function listGroups
*/
public list: jest.Mock<ApiListPromise<GroupResponse>, [ListGroupsRequestData]> = jest.fn();
public list: jest.Mock<ApiListPromise<Group>, [ListGroupsRequestData]> = jest.fn();
/**
* Fixture associated to function replaceGroup
*/
public replace: jest.Mock<Promise<GroupResponse>, [ReplaceGroupRequestData]> = jest.fn();
public replace: jest.Mock<Promise<Group>, [ReplaceGroupRequestData]> = jest.fn();
/**
* Fixture associated to function retrieveGroup
*/
public get: jest.Mock<Promise<GroupResponse>, [GetGroupRequestData]> = jest.fn();
public get: jest.Mock<Promise<Group>, [GetGroupRequestData]> = jest.fn();
/**
* Fixture associated to function updateGroup
*/
public update: jest.Mock<Promise<GroupResponse>, [UpdateGroupRequestData]> = jest.fn();
public update: jest.Mock<Promise<Group>, [UpdateGroupRequestData]> = jest.fn();
}
39 changes: 20 additions & 19 deletions packages/sms/src/rest/v1/groups/groups-api.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {
CreateGroupRequestData,
CreateGroupResponse, DeleteGroupRequestData, GetGroupRequestData,
GroupResponse, ListGroupsRequestData, ListMembersRequestData, ReplaceGroupRequestData,
ReplaceGroupResponse, UpdateGroupRequestData,
UpdateGroupResponse,
DeleteGroupRequestData,
GetGroupRequestData,
ListGroupsRequestData,
ListMembersRequestData,
ReplaceGroupRequestData,
UpdateGroupRequestData,
Group,
} from '../../../models';
import {
RequestBody,
Expand Down Expand Up @@ -32,7 +35,7 @@ export class GroupsApi extends SmsDomainApi {
* A group is a set of phone numbers (MSISDNs) that can be used as a target in the &#x60;send_batch_msg&#x60; operation. An MSISDN can only occur once in a group and any attempts to add a duplicate would be ignored but not rejected.
* @param { CreateGroupRequestData } data - The data to provide to the API call.
*/
public async create(data: CreateGroupRequestData): Promise<CreateGroupResponse> {
public async create(data: CreateGroupRequestData): Promise<Group> {
this.client = this.getSinchClient();
const getParams = this.client.extractQueryParams<CreateGroupRequestData>(data, [] as never[]);
const headers: { [key: string]: string | undefined } = {
Expand All @@ -47,7 +50,7 @@ export class GroupsApi extends SmsDomainApi {
= await this.client.prepareOptions(basePathUrl, 'POST', getParams, headers, body || undefined);
const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams);

return this.client.processCall<CreateGroupResponse>({
return this.client.processCall<Group>({
url,
requestOptions,
apiName: this.apiName,
Expand Down Expand Up @@ -115,12 +118,10 @@ export class GroupsApi extends SmsDomainApi {
* List Groups
* With the list operation you can list all groups that you have created. This operation supports pagination. Groups are returned in reverse chronological order.
* @param { ListGroupsRequestData } data - The data to provide to the API call.
* @return {ApiListPromise<CreateGroupResponse>}
* @return {ApiListPromise<Group>}
*/
public list(data: ListGroupsRequestData): ApiListPromise<GroupResponse> {
public list(data: ListGroupsRequestData): ApiListPromise<Group> {
this.client = this.getSinchClient();
data['page'] = data['page'] !== undefined ? data['page'] : 0;
data['page_size'] = data['page_size'] !== undefined ? data['page_size'] : 30;
const getParams = this.client.extractQueryParams<ListGroupsRequestData>(data, ['page', 'page_size']);
const headers: { [key: string]: string | undefined } = {
'Content-Type': 'application/json',
Expand All @@ -141,27 +142,27 @@ export class GroupsApi extends SmsDomainApi {
};

// Create the promise containing the response wrapped as a PageResult
const listPromise = buildPageResultPromise<GroupResponse>(
const listPromise = buildPageResultPromise<Group>(
this.client,
requestOptionsPromise,
operationProperties);

// Add properties to the Promise to offer the possibility to use it as an iterator
Object.assign(
listPromise,
createIteratorMethodsForPagination<GroupResponse>(
createIteratorMethodsForPagination<Group>(
this.client, requestOptionsPromise, listPromise, operationProperties),
);

return listPromise as ApiListPromise<GroupResponse>;
return listPromise as ApiListPromise<Group>;
}

/**
* Replace a group
* The replace operation will replace all parameters, including members, of an existing group with new values. Replacing a group targeted by a batch message scheduled in the future is allowed and changes will be reflected when the batch is sent.
* @param { ReplaceGroupRequestData } data - The data to provide to the API call.
*/
public async replace(data: ReplaceGroupRequestData): Promise<ReplaceGroupResponse> {
public async replace(data: ReplaceGroupRequestData): Promise<Group> {
this.client = this.getSinchClient();
const getParams = this.client.extractQueryParams<ReplaceGroupRequestData>(data, [] as never[]);
const headers: { [key: string]: string | undefined } = {
Expand All @@ -176,7 +177,7 @@ export class GroupsApi extends SmsDomainApi {
= await this.client.prepareOptions(basePathUrl, 'PUT', getParams, headers, body || undefined);
const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams);

return this.client.processCall<ReplaceGroupResponse>({
return this.client.processCall<Group>({
url,
requestOptions,
apiName: this.apiName,
Expand All @@ -189,7 +190,7 @@ export class GroupsApi extends SmsDomainApi {
* This operation retrieves a specific group with the provided group ID.
* @param { GetGroupRequestData } data - The data to provide to the API call.
*/
public async get(data: GetGroupRequestData): Promise<GroupResponse> {
public async get(data: GetGroupRequestData): Promise<Group> {
this.client = this.getSinchClient();
const getParams = this.client.extractQueryParams<GetGroupRequestData>(data, [] as never[]);
const headers: { [key: string]: string | undefined } = {
Expand All @@ -204,7 +205,7 @@ export class GroupsApi extends SmsDomainApi {
= await this.client.prepareOptions(basePathUrl, 'GET', getParams, headers, body || undefined);
const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams);

return this.client.processCall<GroupResponse>({
return this.client.processCall<Group>({
url,
requestOptions,
apiName: this.apiName,
Expand All @@ -217,7 +218,7 @@ export class GroupsApi extends SmsDomainApi {
* With the update group operation, you can add and remove members in an existing group as well as rename the group. This method encompasses a few ways to update a group: 1. By using &#x60;add&#x60; and &#x60;remove&#x60; arrays containing phone numbers, you control the group movements. Any list of valid numbers in E.164 format can be added. 2. By using the &#x60;auto_update&#x60; object, your customer can add or remove themselves from groups. 3. You can also add or remove other groups into this group with &#x60;add_from_group&#x60; and &#x60;remove_from_group&#x60;. #### Other group update info - The request will not be rejected for duplicate adds or unknown removes. - The additions will be done before the deletions. If an phone number is on both lists, it will not be apart of the resulting group. - Updating a group targeted by a batch message scheduled in the future is allowed. Changes will be reflected when the batch is sent.
* @param { UpdateGroupRequestData } data - The data to provide to the API call.
*/
public async update(data: UpdateGroupRequestData): Promise<UpdateGroupResponse> {
public async update(data: UpdateGroupRequestData): Promise<Group> {
this.client = this.getSinchClient();
const getParams = this.client.extractQueryParams<UpdateGroupRequestData>(data, [] as never[]);
const headers: { [key: string]: string | undefined } = {
Expand All @@ -232,7 +233,7 @@ export class GroupsApi extends SmsDomainApi {
= await this.client.prepareOptions(basePathUrl, 'POST', getParams, headers, body || undefined);
const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams);

return this.client.processCall<UpdateGroupResponse>({
return this.client.processCall<Group>({
url,
requestOptions,
apiName: this.apiName,
Expand Down
Empty file.
10 changes: 5 additions & 5 deletions packages/sms/tests/rest/v1/groups/groups-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('GroupsApi', () => {
],
},
};
const expectedResponse: Sms.CreateGroupResponse = {
const expectedResponse: Sms.Group = {
id: '01HF6EFE21REWJC3B3JWG4FYZ7',
name: 'My group',
size: 2,
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('GroupsApi', () => {
// Given
const requestData: Sms.ListGroupsRequestData = {};

const mockData: Sms.GroupResponse[] =[
const mockData: Sms.Group[] =[
{
id: '01HF6EFE21REWJC3B3JWG4FYZ7',
name: 'My group',
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('GroupsApi', () => {
],
},
};
const expectedResponse: Sms.GroupResponse = {
const expectedResponse: Sms.Group = {
id: '01HF6EFE21REWJC3B3JWG4FYZ7',
name: 'My new group name',
size: 1,
Expand All @@ -162,7 +162,7 @@ describe('GroupsApi', () => {
const requestData: Sms.GetGroupRequestData = {
group_id: '01HF6EFE21REWJC3B3JWG4FYZ7',
};
const expectedResponse: Sms.GroupResponse = {
const expectedResponse: Sms.Group = {
id: '01HF6EFE21REWJC3B3JWG4FYZ7',
name: 'My new group name',
size: 1,
Expand Down Expand Up @@ -193,7 +193,7 @@ describe('GroupsApi', () => {
],
},
};
const expectedResponse: Sms.GroupResponse = {
const expectedResponse: Sms.Group = {
id: '01HF6EFE21REWJC3B3JWG4FYZ7',
name: 'My new group name',
size: 3,
Expand Down
Loading

0 comments on commit a1ecf5f

Please sign in to comment.