-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add opt out client with methods, tests
- Loading branch information
1 parent
d5f44c7
commit b415604
Showing
6 changed files
with
192 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
sdk/communication/communication-sms/src/optOutsClient.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { tracingClient } from "./generated/src/tracing.js"; | ||
import type { OptOutResponseItem } from "./generated/src/index.js"; | ||
import type { SmsApiClient } from "./generated/src/smsApiClient.js"; | ||
import { generateOptOutRequest } from "./utils/smsUtils.js"; | ||
import { extractOperationOptions } from "./extractOperationOptions.js"; | ||
import type { OperationOptions } from "@azure/core-client"; | ||
|
||
export interface OptOutCheckResult { | ||
to: string; | ||
isOptedOut: boolean; | ||
httpStatusCode: number; | ||
errorMessage?: string; | ||
} | ||
|
||
export interface OptOutAddResult { | ||
to: string; | ||
httpStatusCode: number; | ||
errorMessage?: string; | ||
} | ||
|
||
export interface OptOutRemoveResult { | ||
to: string; | ||
httpStatusCode: number; | ||
errorMessage?: string; | ||
} | ||
|
||
export interface CheckOptions extends OperationOptions { | ||
} | ||
|
||
export interface AddOptions extends OperationOptions { | ||
} | ||
|
||
export interface RemoveOptions extends OperationOptions { | ||
} | ||
|
||
export class OptOutsClient { | ||
private readonly api: SmsApiClient; | ||
|
||
constructor(api: SmsApiClient) { | ||
this.api = api; | ||
} | ||
|
||
public async remove( from: string, | ||
to: string[], | ||
options:RemoveOptions = {}): Promise<OptOutRemoveResult[]> { | ||
const { operationOptions } = extractOperationOptions(options); | ||
return tracingClient.withSpan("OptOuts-Remove", operationOptions, async (updatedOptions) => { | ||
const response = await this.api.optOuts.add( | ||
generateOptOutRequest(from, to), | ||
updatedOptions, | ||
); | ||
|
||
return response.value.map((optOutResponseItem: OptOutResponseItem) => { | ||
return { | ||
to: optOutResponseItem.to, | ||
httpStatusCode: optOutResponseItem.httpStatusCode, | ||
errorMessage: optOutResponseItem.errorMessage ?? "" | ||
}; | ||
}); | ||
}); | ||
} | ||
|
||
public async add( | ||
from: string, | ||
to: string[], | ||
options:AddOptions = {}): Promise<OptOutAddResult[]> { | ||
const { operationOptions } = extractOperationOptions(options); | ||
return tracingClient.withSpan("OptOuts-Add", operationOptions, async (updatedOptions) => { | ||
const response = await this.api.optOuts.add( | ||
generateOptOutRequest(from, to), | ||
updatedOptions, | ||
); | ||
|
||
return response.value.map((optOutResponseItem: OptOutResponseItem) => { | ||
return { | ||
to: optOutResponseItem.to, | ||
httpStatusCode: optOutResponseItem.httpStatusCode, | ||
errorMessage: optOutResponseItem.errorMessage ?? "" | ||
}; | ||
}); | ||
}); | ||
} | ||
|
||
public async check( | ||
from: string, | ||
to: string[], | ||
options:CheckOptions = {} | ||
): Promise<OptOutCheckResult[]> { | ||
const { operationOptions } = extractOperationOptions(options); | ||
return tracingClient.withSpan("OptOuts-Check", operationOptions, async (updatedOptions) => { | ||
const response = await this.api.optOuts.check( | ||
generateOptOutRequest(from, to), | ||
updatedOptions, | ||
); | ||
|
||
return response.value.map((optOutResponseItem: OptOutResponseItem) => { | ||
return { | ||
to: optOutResponseItem.to, | ||
isOptedOut: optOutResponseItem.isOptedOut ?? false, | ||
httpStatusCode: optOutResponseItem.httpStatusCode, | ||
errorMessage: optOutResponseItem.errorMessage ?? "" | ||
}; | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters