diff --git a/package.json b/package.json index 988d197..ae14a1a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@trycourier/courier", - "version": "6.0.1", + "version": "v6.0.2", "private": false, "repository": "https://github.com/trycourier/courier-node", "main": "./index.js", @@ -12,13 +12,15 @@ }, "dependencies": { "url-join": "4.0.1", - "@types/url-join": "4.0.1", - "axios": "0.27.2", + "form-data": "4.0.0", + "node-fetch": "2.7.0", "qs": "6.11.2", - "@types/qs": "6.9.8", "js-base64": "3.7.2" }, "devDependencies": { + "@types/url-join": "4.0.1", + "@types/qs": "6.9.8", + "@types/node-fetch": "2.6.9", "@types/node": "17.0.33", "prettier": "2.7.1", "typescript": "4.6.4" diff --git a/src/Client.ts b/src/Client.ts index e9ff8a9..861642f 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -15,17 +15,17 @@ import { Brands } from "./api/resources/brands/client/Client"; import { Bulk } from "./api/resources/bulk/client/Client"; import { Lists } from "./api/resources/lists/client/Client"; import { Messages } from "./api/resources/messages/client/Client"; +import { Notifications } from "./api/resources/notifications/client/Client"; import { Profiles } from "./api/resources/profiles/client/Client"; import { Templates } from "./api/resources/templates/client/Client"; import { Tenants } from "./api/resources/tenants/client/Client"; -import { TokenManagement } from "./api/resources/tokenManagement/client/Client"; import { Translations } from "./api/resources/translations/client/Client"; -import { UserPreferences } from "./api/resources/userPreferences/client/Client"; +import { Users } from "./api/resources/users/client/Client"; export declare namespace CourierClient { interface Options { environment?: core.Supplier; - authorizationToken: core.Supplier; + authorizationToken?: core.Supplier; } interface RequestOptions { @@ -40,7 +40,7 @@ export declare namespace CourierClient { } export class CourierClient { - constructor(protected readonly _options: CourierClient.Options) {} + constructor(protected readonly _options: CourierClient.Options = {}) {} /** * Use the send API to send a message to one or more recipients. @@ -59,7 +59,7 @@ export class CourierClient { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", "Idempotency-Key": requestOptions?.idempotencyKey != null ? requestOptions?.idempotencyKey : undefined, "X-Idempotency-Expiration": requestOptions?.idempotencyExpiry != null @@ -145,6 +145,12 @@ export class CourierClient { return (this._messages ??= new Messages(this._options)); } + protected _notifications: Notifications | undefined; + + public get notifications(): Notifications { + return (this._notifications ??= new Notifications(this._options)); + } + protected _profiles: Profiles | undefined; public get profiles(): Profiles { @@ -163,22 +169,16 @@ export class CourierClient { return (this._tenants ??= new Tenants(this._options)); } - protected _tokenManagement: TokenManagement | undefined; - - public get tokenManagement(): TokenManagement { - return (this._tokenManagement ??= new TokenManagement(this._options)); - } - protected _translations: Translations | undefined; public get translations(): Translations { return (this._translations ??= new Translations(this._options)); } - protected _userPreferences: UserPreferences | undefined; + protected _users: Users | undefined; - public get userPreferences(): UserPreferences { - return (this._userPreferences ??= new UserPreferences(this._options)); + public get users(): Users { + return (this._users ??= new Users(this._options)); } protected async _getAuthorizationHeader() { diff --git a/src/api/resources/audiences/client/Client.ts b/src/api/resources/audiences/client/Client.ts index 814ff7d..3f01ac7 100644 --- a/src/api/resources/audiences/client/Client.ts +++ b/src/api/resources/audiences/client/Client.ts @@ -11,7 +11,7 @@ import * as errors from "../../../../errors"; export declare namespace Audiences { interface Options { environment?: core.Supplier; - authorizationToken: core.Supplier; + authorizationToken?: core.Supplier; } interface RequestOptions { @@ -21,7 +21,7 @@ export declare namespace Audiences { } export class Audiences { - constructor(protected readonly _options: Audiences.Options) {} + constructor(protected readonly _options: Audiences.Options = {}) {} /** * Returns the specified audience by id. @@ -37,7 +37,7 @@ export class Audiences { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -74,9 +74,9 @@ export class Audiences { */ public async update( audienceId: string, - request: Courier.AudienceRequest, + request: Courier.AudienceUpdateParams = {}, requestOptions?: Audiences.RequestOptions - ): Promise { + ): Promise { const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, @@ -87,7 +87,7 @@ export class Audiences { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", body: request, @@ -95,7 +95,7 @@ export class Audiences { maxRetries: requestOptions?.maxRetries, }); if (_response.ok) { - return _response.body as Courier.Audience; + return _response.body as Courier.AudienceUpdateResponse; } if (_response.error.reason === "status-code") { @@ -134,7 +134,7 @@ export class Audiences { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -172,7 +172,7 @@ export class Audiences { */ public async listMembers( audienceId: string, - request: Courier.ListAudienceMembersRequest = {}, + request: Courier.AudienceMembersListParams = {}, requestOptions?: Audiences.RequestOptions ): Promise { const { cursor } = request; @@ -191,7 +191,7 @@ export class Audiences { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", queryParameters: _queryParams, @@ -234,7 +234,7 @@ export class Audiences { * @throws {@link Courier.BadRequestError} */ public async listAudiences( - request: Courier.ListAudiencesRequest = {}, + request: Courier.AudiencesListParams = {}, requestOptions?: Audiences.RequestOptions ): Promise { const { cursor } = request; @@ -253,7 +253,7 @@ export class Audiences { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", queryParameters: _queryParams, diff --git a/src/api/resources/audiences/client/requests/ListAudienceMembersRequest.ts b/src/api/resources/audiences/client/requests/AudienceMembersListParams.ts similarity index 78% rename from src/api/resources/audiences/client/requests/ListAudienceMembersRequest.ts rename to src/api/resources/audiences/client/requests/AudienceMembersListParams.ts index 7517e06..cae7202 100644 --- a/src/api/resources/audiences/client/requests/ListAudienceMembersRequest.ts +++ b/src/api/resources/audiences/client/requests/AudienceMembersListParams.ts @@ -2,10 +2,9 @@ * This file was auto-generated by Fern from our API Definition. */ -export interface ListAudienceMembersRequest { +export interface AudienceMembersListParams { /** * A unique identifier that allows for fetching the next set of members - * */ cursor?: string; } diff --git a/src/api/resources/audiences/types/AudienceRequest.ts b/src/api/resources/audiences/client/requests/AudienceUpdateParams.ts similarity index 60% rename from src/api/resources/audiences/types/AudienceRequest.ts rename to src/api/resources/audiences/client/requests/AudienceUpdateParams.ts index d073828..1c6e754 100644 --- a/src/api/resources/audiences/types/AudienceRequest.ts +++ b/src/api/resources/audiences/client/requests/AudienceUpdateParams.ts @@ -2,11 +2,9 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Courier from "../../.."; +import * as Courier from "../../../.."; -export interface AudienceRequest { - /** A unique identifier representing the audience_id */ - id?: string; +export interface AudienceUpdateParams { /** The name of the audience */ name?: string; /** A description of the audience */ diff --git a/src/api/resources/audiences/client/requests/ListAudiencesRequest.ts b/src/api/resources/audiences/client/requests/AudiencesListParams.ts similarity index 80% rename from src/api/resources/audiences/client/requests/ListAudiencesRequest.ts rename to src/api/resources/audiences/client/requests/AudiencesListParams.ts index 636d353..fb56a93 100644 --- a/src/api/resources/audiences/client/requests/ListAudiencesRequest.ts +++ b/src/api/resources/audiences/client/requests/AudiencesListParams.ts @@ -2,10 +2,9 @@ * This file was auto-generated by Fern from our API Definition. */ -export interface ListAudiencesRequest { +export interface AudiencesListParams { /** * A unique identifier that allows for fetching the next set of audiences - * */ cursor?: string; } diff --git a/src/api/resources/audiences/client/requests/index.ts b/src/api/resources/audiences/client/requests/index.ts index b519c33..d56ca2e 100644 --- a/src/api/resources/audiences/client/requests/index.ts +++ b/src/api/resources/audiences/client/requests/index.ts @@ -1,2 +1,3 @@ -export { ListAudienceMembersRequest } from "./ListAudienceMembersRequest"; -export { ListAudiencesRequest } from "./ListAudiencesRequest"; +export { AudienceUpdateParams } from "./AudienceUpdateParams"; +export { AudienceMembersListParams } from "./AudienceMembersListParams"; +export { AudiencesListParams } from "./AudiencesListParams"; diff --git a/src/api/resources/audiences/types/AudiencePutResponse.ts b/src/api/resources/audiences/types/AudienceUpdateResponse.ts similarity index 77% rename from src/api/resources/audiences/types/AudiencePutResponse.ts rename to src/api/resources/audiences/types/AudienceUpdateResponse.ts index a6f9e00..1dd6c72 100644 --- a/src/api/resources/audiences/types/AudiencePutResponse.ts +++ b/src/api/resources/audiences/types/AudienceUpdateResponse.ts @@ -4,6 +4,6 @@ import * as Courier from "../../.."; -export interface AudiencePutResponse { +export interface AudienceUpdateResponse { audience: Courier.Audience; } diff --git a/src/api/resources/audiences/types/BaseFilterConfig.ts b/src/api/resources/audiences/types/BaseFilterConfig.ts index e04be54..0514266 100644 --- a/src/api/resources/audiences/types/BaseFilterConfig.ts +++ b/src/api/resources/audiences/types/BaseFilterConfig.ts @@ -5,9 +5,6 @@ import * as Courier from "../../.."; export interface BaseFilterConfig { - /** - * The operator to use for filtering - * - */ + /** The operator to use for filtering */ operator: Courier.Operator; } diff --git a/src/api/resources/audiences/types/index.ts b/src/api/resources/audiences/types/index.ts index 64f2753..1401956 100644 --- a/src/api/resources/audiences/types/index.ts +++ b/src/api/resources/audiences/types/index.ts @@ -1,4 +1,3 @@ -export * from "./AudienceRequest"; export * from "./Filter"; export * from "./Operator"; export * from "./BaseFilterConfig"; @@ -12,4 +11,4 @@ export * from "./AudienceMember"; export * from "./AudienceListResponse"; export * from "./AudienceMemberGetResponse"; export * from "./AudienceMemberListResponse"; -export * from "./AudiencePutResponse"; +export * from "./AudienceUpdateResponse"; diff --git a/src/api/resources/auditEvents/client/Client.ts b/src/api/resources/auditEvents/client/Client.ts index 21fd945..02ca511 100644 --- a/src/api/resources/auditEvents/client/Client.ts +++ b/src/api/resources/auditEvents/client/Client.ts @@ -11,7 +11,7 @@ import * as errors from "../../../../errors"; export declare namespace AuditEvents { interface Options { environment?: core.Supplier; - authorizationToken: core.Supplier; + authorizationToken?: core.Supplier; } interface RequestOptions { @@ -21,7 +21,7 @@ export declare namespace AuditEvents { } export class AuditEvents { - constructor(protected readonly _options: AuditEvents.Options) {} + constructor(protected readonly _options: AuditEvents.Options = {}) {} /** * Fetch the list of audit events @@ -46,7 +46,7 @@ export class AuditEvents { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", queryParameters: _queryParams, @@ -93,7 +93,7 @@ export class AuditEvents { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, diff --git a/src/api/resources/auditEvents/client/requests/ListAuditEventsRequest.ts b/src/api/resources/auditEvents/client/requests/ListAuditEventsRequest.ts index 59fe01b..f6055c4 100644 --- a/src/api/resources/auditEvents/client/requests/ListAuditEventsRequest.ts +++ b/src/api/resources/auditEvents/client/requests/ListAuditEventsRequest.ts @@ -5,7 +5,6 @@ export interface ListAuditEventsRequest { /** * A unique identifier that allows for fetching the next set of audit events. - * */ cursor?: string; } diff --git a/src/api/resources/authTokens/client/Client.ts b/src/api/resources/authTokens/client/Client.ts index 3f2ce00..f9473b3 100644 --- a/src/api/resources/authTokens/client/Client.ts +++ b/src/api/resources/authTokens/client/Client.ts @@ -11,7 +11,7 @@ import * as errors from "../../../../errors"; export declare namespace AuthTokens { interface Options { environment?: core.Supplier; - authorizationToken: core.Supplier; + authorizationToken?: core.Supplier; } interface RequestOptions { @@ -26,15 +26,15 @@ export declare namespace AuthTokens { } export class AuthTokens { - constructor(protected readonly _options: AuthTokens.Options) {} + constructor(protected readonly _options: AuthTokens.Options = {}) {} /** * Returns a new access token. */ public async issueToken( - request: Courier.AuthIssueTokenParameters, + request: Courier.IssueTokenParams, requestOptions?: AuthTokens.IdempotentRequestOptions - ): Promise { + ): Promise { const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, @@ -45,7 +45,7 @@ export class AuthTokens { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", "Idempotency-Key": requestOptions?.idempotencyKey != null ? requestOptions?.idempotencyKey : undefined, "X-Idempotency-Expiration": requestOptions?.idempotencyExpiry != null @@ -58,7 +58,7 @@ export class AuthTokens { maxRetries: requestOptions?.maxRetries, }); if (_response.ok) { - return _response.body as Courier.AuthIssueTokenResponse; + return _response.body as Courier.IssueTokenResponse; } if (_response.error.reason === "status-code") { diff --git a/src/api/resources/authTokens/client/index.ts b/src/api/resources/authTokens/client/index.ts index cb0ff5c..415726b 100644 --- a/src/api/resources/authTokens/client/index.ts +++ b/src/api/resources/authTokens/client/index.ts @@ -1 +1 @@ -export {}; +export * from "./requests"; diff --git a/src/api/resources/authTokens/types/AuthIssueTokenParameters.ts b/src/api/resources/authTokens/client/requests/IssueTokenParams.ts similarity index 58% rename from src/api/resources/authTokens/types/AuthIssueTokenParameters.ts rename to src/api/resources/authTokens/client/requests/IssueTokenParams.ts index 1c151f6..78e9599 100644 --- a/src/api/resources/authTokens/types/AuthIssueTokenParameters.ts +++ b/src/api/resources/authTokens/client/requests/IssueTokenParams.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -export interface AuthIssueTokenParameters { +export interface IssueTokenParams { scope: string; - expiresIn: string; + expires_in: string; } diff --git a/src/api/resources/authTokens/client/requests/index.ts b/src/api/resources/authTokens/client/requests/index.ts new file mode 100644 index 0000000..edeb0c4 --- /dev/null +++ b/src/api/resources/authTokens/client/requests/index.ts @@ -0,0 +1 @@ +export { IssueTokenParams } from "./IssueTokenParams"; diff --git a/src/api/resources/authTokens/types/AuthIssueTokenResponse.ts b/src/api/resources/authTokens/types/IssueTokenResponse.ts similarity index 69% rename from src/api/resources/authTokens/types/AuthIssueTokenResponse.ts rename to src/api/resources/authTokens/types/IssueTokenResponse.ts index d5ea5a8..26b8eb1 100644 --- a/src/api/resources/authTokens/types/AuthIssueTokenResponse.ts +++ b/src/api/resources/authTokens/types/IssueTokenResponse.ts @@ -2,6 +2,6 @@ * This file was auto-generated by Fern from our API Definition. */ -export interface AuthIssueTokenResponse { +export interface IssueTokenResponse { token?: string; } diff --git a/src/api/resources/authTokens/types/index.ts b/src/api/resources/authTokens/types/index.ts index e914807..1476165 100644 --- a/src/api/resources/authTokens/types/index.ts +++ b/src/api/resources/authTokens/types/index.ts @@ -1,2 +1 @@ -export * from "./AuthIssueTokenParameters"; -export * from "./AuthIssueTokenResponse"; +export * from "./IssueTokenResponse"; diff --git a/src/api/resources/automations/client/Client.ts b/src/api/resources/automations/client/Client.ts index f2f4542..d0fc33b 100644 --- a/src/api/resources/automations/client/Client.ts +++ b/src/api/resources/automations/client/Client.ts @@ -4,14 +4,14 @@ import * as environments from "../../../../environments"; import * as core from "../../../../core"; +import * as Courier from "../../.."; import urlJoin from "url-join"; import * as errors from "../../../../errors"; -import * as Courier from "../../.."; export declare namespace Automations { interface Options { environment?: core.Supplier; - authorizationToken: core.Supplier; + authorizationToken?: core.Supplier; } interface RequestOptions { @@ -26,15 +26,16 @@ export declare namespace Automations { } export class Automations { - constructor(protected readonly _options: Automations.Options) {} + constructor(protected readonly _options: Automations.Options = {}) {} /** * Invoke an automation run from an automation template. */ public async invokeAutomationTemplate( templateId: string, + request: Courier.AutomationInvokeParams, requestOptions?: Automations.IdempotentRequestOptions - ): Promise { + ): Promise { const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, @@ -45,7 +46,7 @@ export class Automations { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", "Idempotency-Key": requestOptions?.idempotencyKey != null ? requestOptions?.idempotencyKey : undefined, "X-Idempotency-Expiration": requestOptions?.idempotencyExpiry != null @@ -53,11 +54,12 @@ export class Automations { : undefined, }, contentType: "application/json", + body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, }); if (_response.ok) { - return; + return _response.body as Courier.AutomationInvokeResponse; } if (_response.error.reason === "status-code") { @@ -99,7 +101,7 @@ export class Automations { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", "Idempotency-Key": requestOptions?.idempotencyKey != null ? requestOptions?.idempotencyKey : undefined, "X-Idempotency-Expiration": requestOptions?.idempotencyExpiry != null diff --git a/src/api/resources/brands/client/Client.ts b/src/api/resources/brands/client/Client.ts index 5384aa4..4f4ad47 100644 --- a/src/api/resources/brands/client/Client.ts +++ b/src/api/resources/brands/client/Client.ts @@ -11,7 +11,7 @@ import * as errors from "../../../../errors"; export declare namespace Brands { interface Options { environment?: core.Supplier; - authorizationToken: core.Supplier; + authorizationToken?: core.Supplier; } interface RequestOptions { @@ -26,7 +26,7 @@ export declare namespace Brands { } export class Brands { - constructor(protected readonly _options: Brands.Options) {} + constructor(protected readonly _options: Brands.Options = {}) {} /** * @throws {@link Courier.BadRequestError} @@ -47,7 +47,7 @@ export class Brands { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", "Idempotency-Key": requestOptions?.idempotencyKey != null ? requestOptions?.idempotencyKey : undefined, "X-Idempotency-Expiration": requestOptions?.idempotencyExpiry != null @@ -108,7 +108,7 @@ export class Brands { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -163,7 +163,7 @@ export class Brands { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", queryParameters: _queryParams, @@ -211,7 +211,7 @@ export class Brands { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -248,6 +248,57 @@ export class Brands { } } + /** + * Replace an existing brand with the supplied values. + */ + public async replace( + brandId: string, + request: Courier.BrandUpdateParameters, + requestOptions?: Brands.RequestOptions + ): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, + `/brands/${brandId}` + ), + method: "PUT", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@trycourier/courier", + "X-Fern-SDK-Version": "v6.0.2", + }, + contentType: "application/json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + }); + if (_response.ok) { + return _response.body as Courier.Brand; + } + + if (_response.error.reason === "status-code") { + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.CourierTimeoutError(); + case "unknown": + throw new errors.CourierError({ + message: _response.error.errorMessage, + }); + } + } + protected async _getAuthorizationHeader() { const bearer = (await core.Supplier.get(this._options.authorizationToken)) ?? process.env["COURIER_AUTH_TOKEN"]; if (bearer == null) { diff --git a/src/api/resources/brands/types/BrandPutParameters.ts b/src/api/resources/brands/client/requests/BrandUpdateParameters.ts similarity index 56% rename from src/api/resources/brands/types/BrandPutParameters.ts rename to src/api/resources/brands/client/requests/BrandUpdateParameters.ts index 7248b84..6bce267 100644 --- a/src/api/resources/brands/types/BrandPutParameters.ts +++ b/src/api/resources/brands/client/requests/BrandUpdateParameters.ts @@ -2,12 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Courier from "../../.."; +import * as Courier from "../../../.."; -export interface BrandPutParameters { - id: string; +export interface BrandUpdateParameters { /** The name of the brand. */ name: string; - settings: Courier.BrandSettings; + settings?: Courier.BrandSettings; snippets?: Courier.BrandSnippets; } diff --git a/src/api/resources/brands/client/requests/index.ts b/src/api/resources/brands/client/requests/index.ts index fec68a2..a01231b 100644 --- a/src/api/resources/brands/client/requests/index.ts +++ b/src/api/resources/brands/client/requests/index.ts @@ -1 +1,2 @@ export { ListBrandsRequest } from "./ListBrandsRequest"; +export { BrandUpdateParameters } from "./BrandUpdateParameters"; diff --git a/src/api/resources/brands/types/index.ts b/src/api/resources/brands/types/index.ts index c89128c..7d2c1a6 100644 --- a/src/api/resources/brands/types/index.ts +++ b/src/api/resources/brands/types/index.ts @@ -1,6 +1,5 @@ export * from "./Brand"; export * from "./BrandParameters"; -export * from "./BrandPutParameters"; export * from "./BrandGetAllResponse"; export * from "./BrandsResponse"; export * from "./BrandSnippet"; diff --git a/src/api/resources/bulk/client/Client.ts b/src/api/resources/bulk/client/Client.ts index 51a6c65..b6d81cc 100644 --- a/src/api/resources/bulk/client/Client.ts +++ b/src/api/resources/bulk/client/Client.ts @@ -11,7 +11,7 @@ import * as errors from "../../../../errors"; export declare namespace Bulk { interface Options { environment?: core.Supplier; - authorizationToken: core.Supplier; + authorizationToken?: core.Supplier; } interface RequestOptions { @@ -26,12 +26,12 @@ export declare namespace Bulk { } export class Bulk { - constructor(protected readonly _options: Bulk.Options) {} + constructor(protected readonly _options: Bulk.Options = {}) {} /** * @throws {@link Courier.BadRequestError} */ - public async create( + public async createJob( request: Courier.BulkCreateJobParams, requestOptions?: Bulk.IdempotentRequestOptions ): Promise { @@ -45,7 +45,7 @@ export class Bulk { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", "Idempotency-Key": requestOptions?.idempotencyKey != null ? requestOptions?.idempotencyKey : undefined, "X-Idempotency-Expiration": requestOptions?.idempotencyExpiry != null @@ -106,7 +106,7 @@ export class Bulk { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", "Idempotency-Key": requestOptions?.idempotencyKey != null ? requestOptions?.idempotencyKey : undefined, "X-Idempotency-Expiration": requestOptions?.idempotencyExpiry != null @@ -148,11 +148,7 @@ export class Bulk { * Run a bulk job * @throws {@link Courier.BadRequestError} */ - public async runJob( - jobId: string, - request: Courier.BulkRunJobParams, - requestOptions?: Bulk.IdempotentRequestOptions - ): Promise { + public async runJob(jobId: string, requestOptions?: Bulk.IdempotentRequestOptions): Promise { const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, @@ -163,7 +159,7 @@ export class Bulk { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", "Idempotency-Key": requestOptions?.idempotencyKey != null ? requestOptions?.idempotencyKey : undefined, "X-Idempotency-Expiration": requestOptions?.idempotencyExpiry != null @@ -171,7 +167,6 @@ export class Bulk { : undefined, }, contentType: "application/json", - body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, }); @@ -221,7 +216,7 @@ export class Bulk { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -276,7 +271,7 @@ export class Bulk { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, diff --git a/src/api/resources/bulk/client/index.ts b/src/api/resources/bulk/client/index.ts index cb0ff5c..415726b 100644 --- a/src/api/resources/bulk/client/index.ts +++ b/src/api/resources/bulk/client/index.ts @@ -1 +1 @@ -export {}; +export * from "./requests"; diff --git a/src/api/resources/bulk/types/BulkCreateJobParams.ts b/src/api/resources/bulk/client/requests/BulkCreateJobParams.ts similarity index 79% rename from src/api/resources/bulk/types/BulkCreateJobParams.ts rename to src/api/resources/bulk/client/requests/BulkCreateJobParams.ts index 9d088d5..54c70c2 100644 --- a/src/api/resources/bulk/types/BulkCreateJobParams.ts +++ b/src/api/resources/bulk/client/requests/BulkCreateJobParams.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Courier from "../../.."; +import * as Courier from "../../../.."; export interface BulkCreateJobParams { message: Courier.InboundBulkMessage; diff --git a/src/api/resources/bulk/client/requests/index.ts b/src/api/resources/bulk/client/requests/index.ts new file mode 100644 index 0000000..52af27f --- /dev/null +++ b/src/api/resources/bulk/client/requests/index.ts @@ -0,0 +1 @@ +export { BulkCreateJobParams } from "./BulkCreateJobParams"; diff --git a/src/api/resources/bulk/types/BulkIngestUsersParams.ts b/src/api/resources/bulk/types/BulkIngestUsersParams.ts index da12ba9..0b5578f 100644 --- a/src/api/resources/bulk/types/BulkIngestUsersParams.ts +++ b/src/api/resources/bulk/types/BulkIngestUsersParams.ts @@ -5,6 +5,5 @@ import * as Courier from "../../.."; export interface BulkIngestUsersParams { - jobId: string; users: Courier.InboundBulkMessageUser[]; } diff --git a/src/api/resources/bulk/types/InboundBulkContentMessage.ts b/src/api/resources/bulk/types/InboundBulkContentMessage.ts new file mode 100644 index 0000000..c93e624 --- /dev/null +++ b/src/api/resources/bulk/types/InboundBulkContentMessage.ts @@ -0,0 +1,17 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../.."; + +/** + * The message property has the following primary top-level properties. They define the destination and content of the message. + * Additional advanced configuration fields [are defined below](https://www.courier.com/docs/reference/send/message/#other-message-properties). + */ +export interface InboundBulkContentMessage extends Courier.BaseMessage { + /** + * Describes the content of the message in a way that will work for email, push, + * chat, or any channel. Either this or template must be specified. + */ + content: Courier.Content; +} diff --git a/src/api/resources/bulk/types/InboundBulkMessage.ts b/src/api/resources/bulk/types/InboundBulkMessage.ts index 49ee6ea..3676e13 100644 --- a/src/api/resources/bulk/types/InboundBulkMessage.ts +++ b/src/api/resources/bulk/types/InboundBulkMessage.ts @@ -4,6 +4,6 @@ import * as Courier from "../../.."; -export interface InboundBulkMessage extends Courier.InboundBulkMessageApiV1 { - message?: Courier.InboundBulkMessageApiV2 | undefined; +export interface InboundBulkMessage extends Courier.InboundBulkMessageV1 { + message?: Courier.InboundBulkMessageV2; } diff --git a/src/api/resources/bulk/types/InboundBulkMessageApiV1.ts b/src/api/resources/bulk/types/InboundBulkMessageApiV1.ts deleted file mode 100644 index bd83664..0000000 --- a/src/api/resources/bulk/types/InboundBulkMessageApiV1.ts +++ /dev/null @@ -1,14 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export interface InboundBulkMessageApiV1 { - /** A unique identifier that represents the brand that should be used for rendering the notification. */ - brand?: string; - /** JSON that includes any data you want to pass to a message template. The data will populate the corresponding template variables. */ - data?: any; - event: string; - locale?: string; - /** JSON that is merged into the request sent by Courier to the provider to override properties or to gain access to features in the provider API that are not natively supported by Courier. */ - override?: any; -} diff --git a/src/api/resources/bulk/types/InboundBulkMessageApiV2.ts b/src/api/resources/bulk/types/InboundBulkMessageApiV2.ts deleted file mode 100644 index 1b8e7e1..0000000 --- a/src/api/resources/bulk/types/InboundBulkMessageApiV2.ts +++ /dev/null @@ -1,5 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export type InboundBulkMessageApiV2 = any; diff --git a/src/api/resources/bulk/types/InboundBulkMessageV1.ts b/src/api/resources/bulk/types/InboundBulkMessageV1.ts new file mode 100644 index 0000000..0132235 --- /dev/null +++ b/src/api/resources/bulk/types/InboundBulkMessageV1.ts @@ -0,0 +1,24 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface InboundBulkMessageV1 { + /** + * A unique identifier that represents the brand that should be used + * for rendering the notification. + */ + brand?: string; + /** + * JSON that includes any data you want to pass to a message template. + * The data will populate the corresponding template variables. + */ + data?: Record; + event?: string; + locale?: Record; + /** + * JSON that is merged into the request sent by Courier to the provider + * to override properties or to gain access to features in the provider + * API that are not natively supported by Courier. + */ + override?: any; +} diff --git a/src/api/resources/bulk/types/InboundBulkMessageV2.ts b/src/api/resources/bulk/types/InboundBulkMessageV2.ts new file mode 100644 index 0000000..b3b662f --- /dev/null +++ b/src/api/resources/bulk/types/InboundBulkMessageV2.ts @@ -0,0 +1,18 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../.."; + +export type InboundBulkMessageV2 = + /** + * Describes the content of the message in a way that will + * work for email, push, chat, or any channel. + * */ + | Courier.InboundBulkTemplateMessage + /** + * A template for a type of message that can be sent more than once. + * For example, you might create an "Appointment Reminder" Notification or + * “Reset Password” Notifications. + * */ + | Courier.InboundBulkContentMessage; diff --git a/src/api/resources/bulk/types/InboundBulkTemplateMessage.ts b/src/api/resources/bulk/types/InboundBulkTemplateMessage.ts new file mode 100644 index 0000000..9cb61b5 --- /dev/null +++ b/src/api/resources/bulk/types/InboundBulkTemplateMessage.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../.."; + +export interface InboundBulkTemplateMessage extends Courier.BaseMessage { + /** + * The id of the notification template to be rendered and sent to the recipient(s). + * This field or the content field must be supplied. + */ + template: string; +} diff --git a/src/api/resources/bulk/types/index.ts b/src/api/resources/bulk/types/index.ts index d72a9dd..522ecfb 100644 --- a/src/api/resources/bulk/types/index.ts +++ b/src/api/resources/bulk/types/index.ts @@ -1,13 +1,13 @@ -export * from "./InboundBulkMessageApiV1"; -export * from "./InboundBulkMessageApiV2"; +export * from "./InboundBulkMessageV1"; export * from "./InboundBulkMessage"; -export * from "./BulkCreateJobParams"; +export * from "./InboundBulkMessageV2"; +export * from "./InboundBulkTemplateMessage"; +export * from "./InboundBulkContentMessage"; export * from "./BulkCreateJobResponse"; export * from "./InboundBulkMessageUser"; export * from "./BulkIngestUsersParams"; export * from "./BulkIngestError"; export * from "./BulkIngestUsersResponse"; -export * from "./BulkRunJobParams"; export * from "./BulkGetJobParams"; export * from "./BulkJobStatus"; export * from "./BulkJobUserStatus"; diff --git a/src/api/resources/index.ts b/src/api/resources/index.ts index 7c09742..cadb08f 100644 --- a/src/api/resources/index.ts +++ b/src/api/resources/index.ts @@ -16,6 +16,8 @@ export * as lists from "./lists"; export * from "./lists/types"; export * as messages from "./messages"; export * from "./messages/types"; +export * as notifications from "./notifications"; +export * from "./notifications/types"; export * as profiles from "./profiles"; export * from "./profiles/types"; export * as send from "./send"; @@ -24,16 +26,17 @@ export * as templates from "./templates"; export * from "./templates/types"; export * as tenants from "./tenants"; export * from "./tenants/types"; -export * as tokenManagement from "./tokenManagement"; -export * from "./tokenManagement/types"; -export * as userPreferences from "./userPreferences"; -export * from "./userPreferences/types"; +export * as users from "./users"; export * from "./commons/errors"; export * as translations from "./translations"; export * from "./audiences/client/requests"; export * from "./auditEvents/client/requests"; +export * from "./authTokens/client/requests"; export * from "./brands/client/requests"; +export * from "./bulk/client/requests"; export * from "./lists/client/requests"; export * from "./messages/client/requests"; +export * from "./notifications/client/requests"; export * from "./profiles/client/requests"; export * from "./templates/client/requests"; +export * from "./tenants/client/requests"; diff --git a/src/api/resources/lists/client/Client.ts b/src/api/resources/lists/client/Client.ts index b4d143a..8092da8 100644 --- a/src/api/resources/lists/client/Client.ts +++ b/src/api/resources/lists/client/Client.ts @@ -11,7 +11,7 @@ import * as errors from "../../../../errors"; export declare namespace Lists { interface Options { environment?: core.Supplier; - authorizationToken: core.Supplier; + authorizationToken?: core.Supplier; } interface RequestOptions { @@ -26,7 +26,7 @@ export declare namespace Lists { } export class Lists { - constructor(protected readonly _options: Lists.Options) {} + constructor(protected readonly _options: Lists.Options = {}) {} /** * Returns all of the lists, with the ability to filter based on a pattern. @@ -56,7 +56,7 @@ export class Lists { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", queryParameters: _queryParams, @@ -123,7 +123,7 @@ export class Lists { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", queryParameters: _queryParams, @@ -179,7 +179,7 @@ export class Lists { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", body: request, @@ -212,11 +212,103 @@ export class Lists { } } + /** + * Delete a list by list ID. + */ + public async delete(listId: string, requestOptions?: Lists.RequestOptions): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, + `/lists/${listId}` + ), + method: "DELETE", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@trycourier/courier", + "X-Fern-SDK-Version": "v6.0.2", + }, + contentType: "application/json", + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + }); + if (_response.ok) { + return; + } + + if (_response.error.reason === "status-code") { + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.CourierTimeoutError(); + case "unknown": + throw new errors.CourierError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * Restore a previously deleted list. + */ + public async restore(listId: string, requestOptions?: Lists.RequestOptions): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, + `/lists/${listId}/restore` + ), + method: "PUT", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@trycourier/courier", + "X-Fern-SDK-Version": "v6.0.2", + }, + contentType: "application/json", + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + }); + if (_response.ok) { + return; + } + + if (_response.error.reason === "status-code") { + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.CourierTimeoutError(); + case "unknown": + throw new errors.CourierError({ + message: _response.error.errorMessage, + }); + } + } + /** * Get the list's subscriptions. * @throws {@link Courier.NotFoundError} */ - public async getSubscriptions( + public async getSubscribers( listId: string, request: Courier.GetSubscriptionForListRequest = {}, requestOptions?: Lists.RequestOptions @@ -237,7 +329,7 @@ export class Lists { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", queryParameters: _queryParams, @@ -279,7 +371,7 @@ export class Lists { * Subscribes the users to the list, overwriting existing subscriptions. If the list does not exist, it will be automatically created. * @throws {@link Courier.BadRequestError} */ - public async putSubscriptions( + public async updateSubscribers( listId: string, request: Courier.PutSubscriptionsRecipient[], requestOptions?: Lists.RequestOptions @@ -294,7 +386,7 @@ export class Lists { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", body: request, @@ -336,7 +428,7 @@ export class Lists { * Subscribes additional users to the list, without modifying existing subscriptions. If the list does not exist, it will be automatically created. * @throws {@link Courier.BadRequestError} */ - public async postSubscriptions( + public async addSubscribers( listId: string, request: Courier.PutSubscriptionsRecipient[], requestOptions?: Lists.IdempotentRequestOptions @@ -351,7 +443,7 @@ export class Lists { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", "Idempotency-Key": requestOptions?.idempotencyKey != null ? requestOptions?.idempotencyKey : undefined, "X-Idempotency-Expiration": requestOptions?.idempotencyExpiry != null @@ -400,7 +492,7 @@ export class Lists { public async subscribe( listId: string, userId: string, - request: Courier.SubscribeUserToListRequest, + request: Courier.SubscribeUserToListRequest = {}, requestOptions?: Lists.RequestOptions ): Promise { const _response = await core.fetcher({ @@ -413,7 +505,7 @@ export class Lists { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", body: request, @@ -461,7 +553,7 @@ export class Lists { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, diff --git a/src/api/resources/lists/client/requests/GetAllListsRequest.ts b/src/api/resources/lists/client/requests/GetAllListsRequest.ts index ce5bc60..2122c97 100644 --- a/src/api/resources/lists/client/requests/GetAllListsRequest.ts +++ b/src/api/resources/lists/client/requests/GetAllListsRequest.ts @@ -9,7 +9,6 @@ export interface GetAllListsRequest { cursor?: string; /** * "A pattern used to filter the list items returned. Pattern types supported: exact match on `list_id` or a pattern of one or more pattern parts. you may replace a part with either: `*` to match all parts in that position, or `**` to signify a wildcard `endsWith` pattern match." - * */ pattern?: string; } diff --git a/src/api/resources/lists/client/requests/GetListRequest.ts b/src/api/resources/lists/client/requests/GetListRequest.ts index 3904f5c..28abfcd 100644 --- a/src/api/resources/lists/client/requests/GetListRequest.ts +++ b/src/api/resources/lists/client/requests/GetListRequest.ts @@ -9,7 +9,6 @@ export interface GetListRequest { cursor?: string; /** * "A pattern used to filter the list items returned. Pattern types supported: exact match on `list_id` or a pattern of one or more pattern parts. you may replace a part with either: `*` to match all parts in that position, or `**` to signify a wildcard `endsWith` pattern match." - * */ pattern?: string; } diff --git a/src/api/resources/lists/client/requests/SubscribeUserToListRequest.ts b/src/api/resources/lists/client/requests/SubscribeUserToListRequest.ts index e5b6cb8..d0aea15 100644 --- a/src/api/resources/lists/client/requests/SubscribeUserToListRequest.ts +++ b/src/api/resources/lists/client/requests/SubscribeUserToListRequest.ts @@ -5,7 +5,5 @@ import * as Courier from "../../../.."; export interface SubscribeUserToListRequest { - listId: string; - recipientId: string; preferences?: Courier.RecipientPreferences; } diff --git a/src/api/resources/messages/client/Client.ts b/src/api/resources/messages/client/Client.ts index 711c07a..30e59ca 100644 --- a/src/api/resources/messages/client/Client.ts +++ b/src/api/resources/messages/client/Client.ts @@ -11,7 +11,7 @@ import * as errors from "../../../../errors"; export declare namespace Messages { interface Options { environment?: core.Supplier; - authorizationToken: core.Supplier; + authorizationToken?: core.Supplier; } interface RequestOptions { @@ -26,7 +26,7 @@ export declare namespace Messages { } export class Messages { - constructor(protected readonly _options: Messages.Options) {} + constructor(protected readonly _options: Messages.Options = {}) {} /** * Fetch the statuses of messages you've previously sent. @@ -45,7 +45,7 @@ export class Messages { recipient, status, tags, - enqueuedAfter, + enqueued_after: enqueuedAfter, traceId, } = request; const _queryParams: Record = {}; @@ -103,7 +103,7 @@ export class Messages { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", queryParameters: _queryParams, @@ -152,7 +152,7 @@ export class Messages { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -208,7 +208,7 @@ export class Messages { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", "Idempotency-Key": requestOptions?.idempotencyKey != null ? requestOptions?.idempotencyKey : undefined, "X-Idempotency-Expiration": requestOptions?.idempotencyExpiry != null @@ -271,7 +271,7 @@ export class Messages { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", queryParameters: _queryParams, @@ -329,7 +329,7 @@ export class Messages { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -379,7 +379,7 @@ export class Messages { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, diff --git a/src/api/resources/messages/client/requests/ListMessagesRequest.ts b/src/api/resources/messages/client/requests/ListMessagesRequest.ts index eafec40..a2aa377 100644 --- a/src/api/resources/messages/client/requests/ListMessagesRequest.ts +++ b/src/api/resources/messages/client/requests/ListMessagesRequest.ts @@ -42,7 +42,7 @@ export interface ListMessagesRequest { /** * The enqueued datetime of a message to filter out messages received before. */ - enqueuedAfter?: string; + enqueued_after?: string; /** * The unique identifier used to trace the requests */ diff --git a/src/api/resources/notifications/client/Client.ts b/src/api/resources/notifications/client/Client.ts new file mode 100644 index 0000000..cf2af8e --- /dev/null +++ b/src/api/resources/notifications/client/Client.ts @@ -0,0 +1,420 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as environments from "../../../../environments"; +import * as core from "../../../../core"; +import * as Courier from "../../.."; +import urlJoin from "url-join"; +import * as errors from "../../../../errors"; + +export declare namespace Notifications { + interface Options { + environment?: core.Supplier; + authorizationToken?: core.Supplier; + } + + interface RequestOptions { + timeoutInSeconds?: number; + maxRetries?: number; + } +} + +export class Notifications { + constructor(protected readonly _options: Notifications.Options = {}) {} + + public async list( + request: Courier.NotificationListParams = {}, + requestOptions?: Notifications.RequestOptions + ): Promise { + const { cursor } = request; + const _queryParams: Record = {}; + if (cursor != null) { + _queryParams["cursor"] = cursor; + } + + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, + "/notifications" + ), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@trycourier/courier", + "X-Fern-SDK-Version": "v6.0.2", + }, + contentType: "application/json", + queryParameters: _queryParams, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + }); + if (_response.ok) { + return _response.body as Courier.NotificationListResponse; + } + + if (_response.error.reason === "status-code") { + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.CourierTimeoutError(); + case "unknown": + throw new errors.CourierError({ + message: _response.error.errorMessage, + }); + } + } + + public async getContent( + id: string, + requestOptions?: Notifications.RequestOptions + ): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, + `/notifications/${id}/content` + ), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@trycourier/courier", + "X-Fern-SDK-Version": "v6.0.2", + }, + contentType: "application/json", + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + }); + if (_response.ok) { + return _response.body as Courier.NotificationGetContentResponse; + } + + if (_response.error.reason === "status-code") { + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.CourierTimeoutError(); + case "unknown": + throw new errors.CourierError({ + message: _response.error.errorMessage, + }); + } + } + + public async getDraftContent( + id: string, + requestOptions?: Notifications.RequestOptions + ): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, + `/notifications/${id}/draft/content` + ), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@trycourier/courier", + "X-Fern-SDK-Version": "v6.0.2", + }, + contentType: "application/json", + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + }); + if (_response.ok) { + return _response.body as Courier.NotificationGetContentResponse; + } + + if (_response.error.reason === "status-code") { + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.CourierTimeoutError(); + case "unknown": + throw new errors.CourierError({ + message: _response.error.errorMessage, + }); + } + } + + public async updateVariations( + id: string, + request: Courier.NotificationUpdateVariationsParams = {}, + requestOptions?: Notifications.RequestOptions + ): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, + `/notifications/${id}/variations` + ), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@trycourier/courier", + "X-Fern-SDK-Version": "v6.0.2", + }, + contentType: "application/json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + }); + if (_response.ok) { + return; + } + + if (_response.error.reason === "status-code") { + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.CourierTimeoutError(); + case "unknown": + throw new errors.CourierError({ + message: _response.error.errorMessage, + }); + } + } + + public async updateDraftVariations( + id: string, + request: Courier.NotificationDraftUpdateVariationsParams = {}, + requestOptions?: Notifications.RequestOptions + ): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, + `/notifications/${id}/draft/variations` + ), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@trycourier/courier", + "X-Fern-SDK-Version": "v6.0.2", + }, + contentType: "application/json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + }); + if (_response.ok) { + return; + } + + if (_response.error.reason === "status-code") { + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.CourierTimeoutError(); + case "unknown": + throw new errors.CourierError({ + message: _response.error.errorMessage, + }); + } + } + + public async getSubmissionChecks( + id: string, + submissionId: string, + requestOptions?: Notifications.RequestOptions + ): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, + `/notifications/${id}/${submissionId}/checks` + ), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@trycourier/courier", + "X-Fern-SDK-Version": "v6.0.2", + }, + contentType: "application/json", + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + }); + if (_response.ok) { + return _response.body as Courier.SubmissionChecksGetResponse; + } + + if (_response.error.reason === "status-code") { + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.CourierTimeoutError(); + case "unknown": + throw new errors.CourierError({ + message: _response.error.errorMessage, + }); + } + } + + public async replaceSubmissionChecks( + id: string, + submissionId: string, + request: Courier.SubmissionChecksReplaceParams, + requestOptions?: Notifications.RequestOptions + ): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, + `/notifications/${id}/${submissionId}/checks` + ), + method: "PUT", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@trycourier/courier", + "X-Fern-SDK-Version": "v6.0.2", + }, + contentType: "application/json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + }); + if (_response.ok) { + return _response.body as Courier.SubmissionChecksReplaceResponse; + } + + if (_response.error.reason === "status-code") { + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.CourierTimeoutError(); + case "unknown": + throw new errors.CourierError({ + message: _response.error.errorMessage, + }); + } + } + + public async cancelSubmission( + id: string, + submissionId: string, + requestOptions?: Notifications.RequestOptions + ): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, + `/notifications/${id}/${submissionId}/checks` + ), + method: "DELETE", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@trycourier/courier", + "X-Fern-SDK-Version": "v6.0.2", + }, + contentType: "application/json", + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + }); + if (_response.ok) { + return; + } + + if (_response.error.reason === "status-code") { + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.CourierTimeoutError(); + case "unknown": + throw new errors.CourierError({ + message: _response.error.errorMessage, + }); + } + } + + protected async _getAuthorizationHeader() { + const bearer = (await core.Supplier.get(this._options.authorizationToken)) ?? process.env["COURIER_AUTH_TOKEN"]; + if (bearer == null) { + throw new errors.CourierError({ + message: "Please specify COURIER_AUTH_TOKEN when instantiating the client.", + }); + } + + return `Bearer ${bearer}`; + } +} diff --git a/src/api/resources/notifications/client/index.ts b/src/api/resources/notifications/client/index.ts new file mode 100644 index 0000000..415726b --- /dev/null +++ b/src/api/resources/notifications/client/index.ts @@ -0,0 +1 @@ +export * from "./requests"; diff --git a/src/api/resources/notifications/client/requests/NotificationDraftUpdateVariationsParams.ts b/src/api/resources/notifications/client/requests/NotificationDraftUpdateVariationsParams.ts new file mode 100644 index 0000000..2241750 --- /dev/null +++ b/src/api/resources/notifications/client/requests/NotificationDraftUpdateVariationsParams.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../../.."; + +export interface NotificationDraftUpdateVariationsParams { + blocks?: Courier.NotificationBlock[]; + channels?: Courier.NotificationChannel[]; +} diff --git a/src/api/resources/bulk/types/BulkRunJobParams.ts b/src/api/resources/notifications/client/requests/NotificationListParams.ts similarity index 54% rename from src/api/resources/bulk/types/BulkRunJobParams.ts rename to src/api/resources/notifications/client/requests/NotificationListParams.ts index ecbe816..70e3736 100644 --- a/src/api/resources/bulk/types/BulkRunJobParams.ts +++ b/src/api/resources/notifications/client/requests/NotificationListParams.ts @@ -2,6 +2,6 @@ * This file was auto-generated by Fern from our API Definition. */ -export interface BulkRunJobParams { - jobId: string; +export interface NotificationListParams { + cursor?: string; } diff --git a/src/api/resources/notifications/client/requests/NotificationUpdateVariationsParams.ts b/src/api/resources/notifications/client/requests/NotificationUpdateVariationsParams.ts new file mode 100644 index 0000000..4d8e370 --- /dev/null +++ b/src/api/resources/notifications/client/requests/NotificationUpdateVariationsParams.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../../.."; + +export interface NotificationUpdateVariationsParams { + blocks?: Courier.NotificationBlock[]; + channels?: Courier.NotificationChannel[]; +} diff --git a/src/api/resources/notifications/client/requests/SubmissionChecksReplaceParams.ts b/src/api/resources/notifications/client/requests/SubmissionChecksReplaceParams.ts new file mode 100644 index 0000000..a999426 --- /dev/null +++ b/src/api/resources/notifications/client/requests/SubmissionChecksReplaceParams.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../../.."; + +export interface SubmissionChecksReplaceParams { + checks: Courier.BaseCheck[]; +} diff --git a/src/api/resources/notifications/client/requests/index.ts b/src/api/resources/notifications/client/requests/index.ts new file mode 100644 index 0000000..2da9ac0 --- /dev/null +++ b/src/api/resources/notifications/client/requests/index.ts @@ -0,0 +1,4 @@ +export { NotificationListParams } from "./NotificationListParams"; +export { NotificationUpdateVariationsParams } from "./NotificationUpdateVariationsParams"; +export { NotificationDraftUpdateVariationsParams } from "./NotificationDraftUpdateVariationsParams"; +export { SubmissionChecksReplaceParams } from "./SubmissionChecksReplaceParams"; diff --git a/src/api/resources/tokenManagement/index.ts b/src/api/resources/notifications/index.ts similarity index 100% rename from src/api/resources/tokenManagement/index.ts rename to src/api/resources/notifications/index.ts diff --git a/src/api/resources/notifications/types/BaseCheck.ts b/src/api/resources/notifications/types/BaseCheck.ts new file mode 100644 index 0000000..fe27ba4 --- /dev/null +++ b/src/api/resources/notifications/types/BaseCheck.ts @@ -0,0 +1,11 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../.."; + +export interface BaseCheck { + id: string; + status: Courier.CheckStatus; + type: "custom"; +} diff --git a/src/api/resources/notifications/types/BlockType.ts b/src/api/resources/notifications/types/BlockType.ts new file mode 100644 index 0000000..f4edcf1 --- /dev/null +++ b/src/api/resources/notifications/types/BlockType.ts @@ -0,0 +1,26 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export type BlockType = + | "action" + | "divider" + | "image" + | "jsonnet" + | "list" + | "markdown" + | "quote" + | "template" + | "text"; + +export const BlockType = { + Action: "action", + Divider: "divider", + Image: "image", + Jsonnet: "jsonnet", + List: "list", + Markdown: "markdown", + Quote: "quote", + Template: "template", + Text: "text", +} as const; diff --git a/src/api/resources/tokenManagement/types/PatchUserTokenOpts.ts b/src/api/resources/notifications/types/Check.ts similarity index 60% rename from src/api/resources/tokenManagement/types/PatchUserTokenOpts.ts rename to src/api/resources/notifications/types/Check.ts index 7bfc30d..8aa133a 100644 --- a/src/api/resources/tokenManagement/types/PatchUserTokenOpts.ts +++ b/src/api/resources/notifications/types/Check.ts @@ -4,6 +4,6 @@ import * as Courier from "../../.."; -export interface PatchUserTokenOpts { - patch: Courier.PatchOperation[]; +export interface Check extends Courier.BaseCheck { + updated: number; } diff --git a/src/api/resources/notifications/types/CheckStatus.ts b/src/api/resources/notifications/types/CheckStatus.ts new file mode 100644 index 0000000..ac6f583 --- /dev/null +++ b/src/api/resources/notifications/types/CheckStatus.ts @@ -0,0 +1,11 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export type CheckStatus = "RESOLVED" | "FAILED" | "PENDING"; + +export const CheckStatus = { + Resolved: "RESOLVED", + Failed: "FAILED", + Pending: "PENDING", +} as const; diff --git a/src/api/resources/notifications/types/MessageRouting.ts b/src/api/resources/notifications/types/MessageRouting.ts new file mode 100644 index 0000000..9922aef --- /dev/null +++ b/src/api/resources/notifications/types/MessageRouting.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../.."; + +export interface MessageRouting { + method: Courier.MessageRoutingMethod; + channels: Courier.MessageRoutingChannel[]; +} diff --git a/src/api/resources/notifications/types/MessageRoutingChannel.ts b/src/api/resources/notifications/types/MessageRoutingChannel.ts new file mode 100644 index 0000000..34a2d55 --- /dev/null +++ b/src/api/resources/notifications/types/MessageRoutingChannel.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../.."; + +export type MessageRoutingChannel = string | Courier.MessageRouting; diff --git a/src/api/resources/notifications/types/MessageRoutingMethod.ts b/src/api/resources/notifications/types/MessageRoutingMethod.ts new file mode 100644 index 0000000..77d165d --- /dev/null +++ b/src/api/resources/notifications/types/MessageRoutingMethod.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export type MessageRoutingMethod = "all" | "single"; + +export const MessageRoutingMethod = { + All: "all", + Single: "single", +} as const; diff --git a/src/api/resources/notifications/types/Notification.ts b/src/api/resources/notifications/types/Notification.ts new file mode 100644 index 0000000..c5bbdc4 --- /dev/null +++ b/src/api/resources/notifications/types/Notification.ts @@ -0,0 +1,11 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../.."; + +export interface Notification { + created_at: number; + id: string; + routing: Courier.MessageRouting; +} diff --git a/src/api/resources/notifications/types/NotificationBlock.ts b/src/api/resources/notifications/types/NotificationBlock.ts new file mode 100644 index 0000000..06247e2 --- /dev/null +++ b/src/api/resources/notifications/types/NotificationBlock.ts @@ -0,0 +1,15 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../.."; + +export interface NotificationBlock { + alias?: string; + context?: string; + id: string; + type: Courier.BlockType; + content?: Courier.NotificationContent; + locales?: Record; + checksum?: string; +} diff --git a/src/api/resources/notifications/types/NotificationChannel.ts b/src/api/resources/notifications/types/NotificationChannel.ts new file mode 100644 index 0000000..3ee8126 --- /dev/null +++ b/src/api/resources/notifications/types/NotificationChannel.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../.."; + +export interface NotificationChannel { + id: string; + type?: string; + content?: Courier.NotificationChannelContent; + locales?: Record; + checksum?: string; +} diff --git a/src/api/resources/notifications/types/NotificationChannelContent.ts b/src/api/resources/notifications/types/NotificationChannelContent.ts new file mode 100644 index 0000000..6cc5826 --- /dev/null +++ b/src/api/resources/notifications/types/NotificationChannelContent.ts @@ -0,0 +1,8 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface NotificationChannelContent { + subject?: string; + title?: string; +} diff --git a/src/api/resources/notifications/types/NotificationContent.ts b/src/api/resources/notifications/types/NotificationContent.ts new file mode 100644 index 0000000..a880e3c --- /dev/null +++ b/src/api/resources/notifications/types/NotificationContent.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../.."; + +export type NotificationContent = string | Courier.NotificationContentHierarchy; diff --git a/src/api/resources/notifications/types/NotificationContentHierarchy.ts b/src/api/resources/notifications/types/NotificationContentHierarchy.ts new file mode 100644 index 0000000..f59ed65 --- /dev/null +++ b/src/api/resources/notifications/types/NotificationContentHierarchy.ts @@ -0,0 +1,8 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface NotificationContentHierarchy { + parent?: string; + children?: string; +} diff --git a/src/api/resources/notifications/types/NotificationGetContentResponse.ts b/src/api/resources/notifications/types/NotificationGetContentResponse.ts new file mode 100644 index 0000000..a283099 --- /dev/null +++ b/src/api/resources/notifications/types/NotificationGetContentResponse.ts @@ -0,0 +1,11 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../.."; + +export interface NotificationGetContentResponse { + blocks?: Courier.NotificationBlock[]; + channels?: Courier.NotificationChannel[]; + checksum?: string; +} diff --git a/src/api/resources/notifications/types/NotificationListResponse.ts b/src/api/resources/notifications/types/NotificationListResponse.ts new file mode 100644 index 0000000..89fd1f0 --- /dev/null +++ b/src/api/resources/notifications/types/NotificationListResponse.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../.."; + +export interface NotificationListResponse { + paging: Courier.Paging; + results: Courier.Notification[]; +} diff --git a/src/api/resources/notifications/types/SubmissionChecksGetResponse.ts b/src/api/resources/notifications/types/SubmissionChecksGetResponse.ts new file mode 100644 index 0000000..8ed4c26 --- /dev/null +++ b/src/api/resources/notifications/types/SubmissionChecksGetResponse.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../.."; + +export interface SubmissionChecksGetResponse { + checks: Courier.Check[]; +} diff --git a/src/api/resources/notifications/types/SubmissionChecksReplaceResponse.ts b/src/api/resources/notifications/types/SubmissionChecksReplaceResponse.ts new file mode 100644 index 0000000..f348ba3 --- /dev/null +++ b/src/api/resources/notifications/types/SubmissionChecksReplaceResponse.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../.."; + +export interface SubmissionChecksReplaceResponse { + checks: Courier.Check[]; +} diff --git a/src/api/resources/notifications/types/index.ts b/src/api/resources/notifications/types/index.ts new file mode 100644 index 0000000..65cc9a1 --- /dev/null +++ b/src/api/resources/notifications/types/index.ts @@ -0,0 +1,17 @@ +export * from "./NotificationListResponse"; +export * from "./NotificationGetContentResponse"; +export * from "./Notification"; +export * from "./MessageRouting"; +export * from "./MessageRoutingMethod"; +export * from "./MessageRoutingChannel"; +export * from "./NotificationBlock"; +export * from "./NotificationContent"; +export * from "./NotificationContentHierarchy"; +export * from "./BlockType"; +export * from "./NotificationChannel"; +export * from "./NotificationChannelContent"; +export * from "./BaseCheck"; +export * from "./Check"; +export * from "./CheckStatus"; +export * from "./SubmissionChecksGetResponse"; +export * from "./SubmissionChecksReplaceResponse"; diff --git a/src/api/resources/profiles/client/Client.ts b/src/api/resources/profiles/client/Client.ts index 36254d9..22160e0 100644 --- a/src/api/resources/profiles/client/Client.ts +++ b/src/api/resources/profiles/client/Client.ts @@ -11,7 +11,7 @@ import * as errors from "../../../../errors"; export declare namespace Profiles { interface Options { environment?: core.Supplier; - authorizationToken: core.Supplier; + authorizationToken?: core.Supplier; } interface RequestOptions { @@ -26,7 +26,7 @@ export declare namespace Profiles { } export class Profiles { - constructor(protected readonly _options: Profiles.Options) {} + constructor(protected readonly _options: Profiles.Options = {}) {} /** * Returns the specified user profile. @@ -43,7 +43,7 @@ export class Profiles { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -99,7 +99,7 @@ export class Profiles { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", "Idempotency-Key": requestOptions?.idempotencyKey != null ? requestOptions?.idempotencyKey : undefined, "X-Idempotency-Expiration": requestOptions?.idempotencyExpiry != null @@ -147,7 +147,6 @@ export class Profiles { * Any key-value pairs that exist in the profile but fail to be included in the `PUT` request will be * removed from the profile. Remember, a `PUT` update is a full replacement of the data. For partial updates, * use the [Patch](https://www.courier.com/docs/reference/profiles/patch/) request. - * * @throws {@link Courier.BadRequestError} */ public async replace( @@ -165,7 +164,7 @@ export class Profiles { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", body: request, @@ -218,7 +217,7 @@ export class Profiles { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -280,7 +279,7 @@ export class Profiles { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", queryParameters: _queryParams, @@ -337,7 +336,7 @@ export class Profiles { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", "Idempotency-Key": requestOptions?.idempotencyKey != null ? requestOptions?.idempotencyKey : undefined, "X-Idempotency-Expiration": requestOptions?.idempotencyExpiry != null @@ -398,7 +397,7 @@ export class Profiles { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, diff --git a/src/api/resources/send/types/BaseMessage.ts b/src/api/resources/send/types/BaseMessage.ts index f39c59e..4852f4c 100644 --- a/src/api/resources/send/types/BaseMessage.ts +++ b/src/api/resources/send/types/BaseMessage.ts @@ -5,19 +5,13 @@ import * as Courier from "../../.."; export interface BaseMessage { - /** The recipient or a list of recipients of the message */ - to: Courier.MessageRecipient; /** * An arbitrary object that includes any data you want to pass to the message. * The data will populate the corresponding template or elements variables. - * */ data?: Courier.MessageData; brand_id?: string; - /** - * "Define run-time configuration for one or more channels. If you don't specify channels, the default configuration for each channel will be used. Valid ChannelId's are: email, sms, push, inbox, direct_message, banner, and webhook." - * - */ + /** "Define run-time configuration for one or more channels. If you don't specify channels, the default configuration for each channel will be used. Valid ChannelId's are: email, sms, push, inbox, direct_message, banner, and webhook." */ channels?: Courier.MessageChannels; /** Context to load with this recipient. Will override any context set on message.context. */ context?: Courier.MessageContext; @@ -33,7 +27,6 @@ export interface BaseMessage { /** * "Expiry allows you to set an absolute or relative time in which a message expires. * Note: This is only valid for the Courier Inbox channel as of 12-08-2022." - * */ expiry?: Courier.Expiry; } diff --git a/src/api/resources/send/types/Channel.ts b/src/api/resources/send/types/Channel.ts index 0d946c0..88d9825 100644 --- a/src/api/resources/send/types/Channel.ts +++ b/src/api/resources/send/types/Channel.ts @@ -8,27 +8,23 @@ export interface Channel { /** * Id of the brand that should be used for rendering the message. * If not specified, the brand configured as default brand will be used. - * */ brand_id?: string; /** * A list of providers enabled for this channel. Courier will select * one provider to send through unless routing_method is set to all. - * */ providers?: string[]; /** * The method for selecting the providers to send the message with. * Single will send to one of the available providers for this channel, * all will send the message through all channels. Defaults to `single`. - * */ routing_method?: Courier.RoutingMethod; /** * A JavaScript conditional expression to determine if the message should * be sent through the channel. Has access to the data and profile object. * For example, `data.name === profile.name` - * */ if?: string; timeouts?: Courier.Timeouts; diff --git a/src/api/resources/send/types/ContentMessage.ts b/src/api/resources/send/types/ContentMessage.ts index ce8e9b6..58516b5 100644 --- a/src/api/resources/send/types/ContentMessage.ts +++ b/src/api/resources/send/types/ContentMessage.ts @@ -7,13 +7,13 @@ import * as Courier from "../../.."; /** * The message property has the following primary top-level properties. They define the destination and content of the message. * Additional advanced configuration fields [are defined below](https://www.courier.com/docs/reference/send/message/#other-message-properties). - * */ export interface ContentMessage extends Courier.BaseMessage { /** * Describes the content of the message in a way that will work for email, push, * chat, or any channel. Either this or template must be specified. - * */ content: Courier.Content; + /** The recipient or a list of recipients of the message */ + to: Courier.MessageRecipient; } diff --git a/src/api/resources/send/types/ElementalChannelNode.ts b/src/api/resources/send/types/ElementalChannelNode.ts index d888415..97b9f53 100644 --- a/src/api/resources/send/types/ElementalChannelNode.ts +++ b/src/api/resources/send/types/ElementalChannelNode.ts @@ -13,25 +13,21 @@ import * as Courier from "../../.."; * Note: As an alternative, most elements support a `channel` property. Which allows you to selectively * display an individual element on a per channel basis. See the * [control flow docs](https://www.courier.com/docs/platform/content/elemental/control-flow/) for more details. - * */ export interface ElementalChannelNode extends Courier.ElementalBaseNode { /** * The channel the contents of this element should be applied to. Can be `email`, * `push`, `direct_message`, `sms` or a provider such as slack - * */ channel: string; /** * An array of elements to apply to the channel. If `raw` has not been * specified, `elements` is `required`. - * */ elements?: Courier.ElementalNode[]; /** * Raw data to apply to the channel. If `elements` has not been * specified, `raw` is `required`. - * */ raw?: Record; } diff --git a/src/api/resources/send/types/ElementalMetaNode.ts b/src/api/resources/send/types/ElementalMetaNode.ts index 846b4d0..039c1d5 100644 --- a/src/api/resources/send/types/ElementalMetaNode.ts +++ b/src/api/resources/send/types/ElementalMetaNode.ts @@ -8,7 +8,6 @@ import * as Courier from "../../.."; * The meta element contains information describing the notification that may * be used by a particular channel or provider. One important field is the title * field which will be used as the title for channels that support it. - * */ export interface ElementalMetaNode extends Courier.ElementalBaseNode { /** The title to be displayed by supported channels. For example, the email subject. */ diff --git a/src/api/resources/send/types/ElementalTextNode.ts b/src/api/resources/send/types/ElementalTextNode.ts index b10d188..e31c956 100644 --- a/src/api/resources/send/types/ElementalTextNode.ts +++ b/src/api/resources/send/types/ElementalTextNode.ts @@ -11,7 +11,6 @@ export interface ElementalTextNode extends Courier.ElementalBaseNode { /** * The text content displayed in the notification. Either this * field must be specified, or the elements field - * */ content: string; /** Text alignment. */ diff --git a/src/api/resources/send/types/MessageContext.ts b/src/api/resources/send/types/MessageContext.ts index 1e902f8..2275b36 100644 --- a/src/api/resources/send/types/MessageContext.ts +++ b/src/api/resources/send/types/MessageContext.ts @@ -6,7 +6,6 @@ export interface MessageContext { /** * An id of a tenant, see [tenants api docs](https://www.courier.com/docs/reference/tenants/). * Will load brand, default preferences and any other base context data associated with this tenant. - * */ tenant_id?: string; } diff --git a/src/api/resources/send/types/MessageProvidersType.ts b/src/api/resources/send/types/MessageProvidersType.ts index dfa84cd..c6ed5f4 100644 --- a/src/api/resources/send/types/MessageProvidersType.ts +++ b/src/api/resources/send/types/MessageProvidersType.ts @@ -11,7 +11,6 @@ export interface MessageProvidersType { * A JavaScript conditional expression to determine if the message should be sent * through the channel. Has access to the data and profile object. For example, * `data.name === profile.name` - * */ if?: string; timeouts?: number; diff --git a/src/api/resources/send/types/Routing.ts b/src/api/resources/send/types/Routing.ts index 9e7337d..b7e95e7 100644 --- a/src/api/resources/send/types/Routing.ts +++ b/src/api/resources/send/types/Routing.ts @@ -8,7 +8,6 @@ import * as Courier from "../../.."; * Allows you to customize which channel(s) Courier will potentially deliver the message. * If no routing key is specified, Courier will use the default routing configuration or * routing defined by the template. - * */ export interface Routing { method: Courier.RoutingMethod; @@ -16,7 +15,6 @@ export interface Routing { * A list of channels or providers to send the message through. Can also recursively define * sub-routing methods, which can be useful for defining advanced push notification * delivery strategies. - * */ channels: Courier.RoutingChannel[]; } diff --git a/src/api/resources/send/types/TemplateMessage.ts b/src/api/resources/send/types/TemplateMessage.ts index 71552ad..056bd7f 100644 --- a/src/api/resources/send/types/TemplateMessage.ts +++ b/src/api/resources/send/types/TemplateMessage.ts @@ -8,7 +8,8 @@ export interface TemplateMessage extends Courier.BaseMessage { /** * The id of the notification template to be rendered and sent to the recipient(s). * This field or the content field must be supplied. - * */ template: string; + /** The recipient or a list of recipients of the message */ + to: Courier.MessageRecipient; } diff --git a/src/api/resources/send/types/UserRecipient.ts b/src/api/resources/send/types/UserRecipient.ts index 68057ee..6df0747 100644 --- a/src/api/resources/send/types/UserRecipient.ts +++ b/src/api/resources/send/types/UserRecipient.ts @@ -19,7 +19,6 @@ export interface UserRecipient extends Courier.UserRecipientType { /** * An id of a tenant, [see tenants api docs](https://www.courier.com/docs/reference/tenants). * Will load brand, default preferences and any other base context data associated with this tenant. - * */ tenant_id?: string; } diff --git a/src/api/resources/templates/client/Client.ts b/src/api/resources/templates/client/Client.ts index 9686283..350c98e 100644 --- a/src/api/resources/templates/client/Client.ts +++ b/src/api/resources/templates/client/Client.ts @@ -11,7 +11,7 @@ import * as errors from "../../../../errors"; export declare namespace Templates { interface Options { environment?: core.Supplier; - authorizationToken: core.Supplier; + authorizationToken?: core.Supplier; } interface RequestOptions { @@ -21,7 +21,7 @@ export declare namespace Templates { } export class Templates { - constructor(protected readonly _options: Templates.Options) {} + constructor(protected readonly _options: Templates.Options = {}) {} /** * Returns a list of notification templates @@ -46,7 +46,7 @@ export class Templates { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", queryParameters: _queryParams, diff --git a/src/api/resources/tenants/client/Client.ts b/src/api/resources/tenants/client/Client.ts index 9504bcb..5086482 100644 --- a/src/api/resources/tenants/client/Client.ts +++ b/src/api/resources/tenants/client/Client.ts @@ -11,7 +11,7 @@ import * as errors from "../../../../errors"; export declare namespace Tenants { interface Options { environment?: core.Supplier; - authorizationToken: core.Supplier; + authorizationToken?: core.Supplier; } interface RequestOptions { @@ -21,16 +21,16 @@ export declare namespace Tenants { } export class Tenants { - constructor(protected readonly _options: Tenants.Options) {} + constructor(protected readonly _options: Tenants.Options = {}) {} /** * @throws {@link Courier.BadRequestError} */ public async createOrReplace( tenantId: string, - request: Courier.CreateOrReplaceTenantRequest, + request: Courier.TenantCreateOrReplaceParams, requestOptions?: Tenants.RequestOptions - ): Promise { + ): Promise { const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, @@ -41,7 +41,7 @@ export class Tenants { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", body: request, @@ -49,7 +49,7 @@ export class Tenants { maxRetries: requestOptions?.maxRetries, }); if (_response.ok) { - return _response.body as Courier.CreateOrReplaceTenantResponse; + return _response.body as Courier.Tenant; } if (_response.error.reason === "status-code") { @@ -79,6 +79,143 @@ export class Tenants { } } + /** + * @throws {@link Courier.BadRequestError} + */ + public async get(tenantId: string, requestOptions?: Tenants.RequestOptions): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, + `/tenants/${tenantId}` + ), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@trycourier/courier", + "X-Fern-SDK-Version": "v6.0.2", + }, + contentType: "application/json", + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + }); + if (_response.ok) { + return _response.body as Courier.Tenant; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Courier.BadRequestError(_response.error.body as Courier.BadRequest); + default: + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.CourierTimeoutError(); + case "unknown": + throw new errors.CourierError({ + message: _response.error.errorMessage, + }); + } + } + + public async list(requestOptions?: Tenants.RequestOptions): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, + "/tenants" + ), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@trycourier/courier", + "X-Fern-SDK-Version": "v6.0.2", + }, + contentType: "application/json", + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + }); + if (_response.ok) { + return _response.body as Courier.TenantListResponse; + } + + if (_response.error.reason === "status-code") { + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.CourierTimeoutError(); + case "unknown": + throw new errors.CourierError({ + message: _response.error.errorMessage, + }); + } + } + + public async delete(tenantId: string, requestOptions?: Tenants.RequestOptions): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, + `/tenants/${tenantId}` + ), + method: "DELETE", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@trycourier/courier", + "X-Fern-SDK-Version": "v6.0.2", + }, + contentType: "application/json", + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + }); + if (_response.ok) { + return; + } + + if (_response.error.reason === "status-code") { + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.CourierTimeoutError(); + case "unknown": + throw new errors.CourierError({ + message: _response.error.errorMessage, + }); + } + } + protected async _getAuthorizationHeader() { const bearer = (await core.Supplier.get(this._options.authorizationToken)) ?? process.env["COURIER_AUTH_TOKEN"]; if (bearer == null) { diff --git a/src/api/resources/tenants/client/index.ts b/src/api/resources/tenants/client/index.ts index cb0ff5c..415726b 100644 --- a/src/api/resources/tenants/client/index.ts +++ b/src/api/resources/tenants/client/index.ts @@ -1 +1 @@ -export {}; +export * from "./requests"; diff --git a/src/api/resources/tenants/types/CreateOrReplaceTenantRequest.ts b/src/api/resources/tenants/client/requests/TenantCreateOrReplaceParams.ts similarity index 61% rename from src/api/resources/tenants/types/CreateOrReplaceTenantRequest.ts rename to src/api/resources/tenants/client/requests/TenantCreateOrReplaceParams.ts index 744834e..c924ec8 100644 --- a/src/api/resources/tenants/types/CreateOrReplaceTenantRequest.ts +++ b/src/api/resources/tenants/client/requests/TenantCreateOrReplaceParams.ts @@ -2,19 +2,19 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Courier from "../../.."; +import * as Courier from "../../../.."; -export interface CreateOrReplaceTenantRequest { +export interface TenantCreateOrReplaceParams { /** Name of the tenant. */ name: string; /** Tenant's parent id (if any). */ - parent_tenant_id: string; + parent_tenant_id?: string; /** Defines the preferences used for the tenant when the user hasn't specified their own. */ - default_preferences: Courier.DefaultPreferences; + default_preferences?: Courier.DefaultPreferences; /** Arbitrary properties accessible to a template. */ - properties: (Courier.TemplateProperty | undefined)[]; + properties?: (Courier.TemplateProperty | undefined)[]; /** A user profile object merged with user profile on send. */ - user_profile?: any; + user_profile?: Record; /** Brand to be used for the account when one is not specified by the send call. */ - brand_id: string; + brand_id?: string; } diff --git a/src/api/resources/tenants/client/requests/index.ts b/src/api/resources/tenants/client/requests/index.ts new file mode 100644 index 0000000..18d1a4e --- /dev/null +++ b/src/api/resources/tenants/client/requests/index.ts @@ -0,0 +1 @@ +export { TenantCreateOrReplaceParams } from "./TenantCreateOrReplaceParams"; diff --git a/src/api/resources/tenants/types/CreateOrReplaceTenantResponse.ts b/src/api/resources/tenants/types/Tenant.ts similarity index 88% rename from src/api/resources/tenants/types/CreateOrReplaceTenantResponse.ts rename to src/api/resources/tenants/types/Tenant.ts index 1c1fa9f..406aa62 100644 --- a/src/api/resources/tenants/types/CreateOrReplaceTenantResponse.ts +++ b/src/api/resources/tenants/types/Tenant.ts @@ -4,7 +4,7 @@ import * as Courier from "../../.."; -export interface CreateOrReplaceTenantResponse { +export interface Tenant { /** Id of the tenant. */ id: string; /** Name of the tenant. */ @@ -16,7 +16,7 @@ export interface CreateOrReplaceTenantResponse { /** Arbitrary properties accessible to a template. */ properties?: Courier.TemplateProperty | undefined; /** A user profile object merged with user profile on send. */ - user_profile?: any; + user_profile?: Record; /** Brand to be used for the account when one is not specified by the send call. */ - brand_id: string; + brand_id?: string; } diff --git a/src/api/resources/tenants/types/TenantListResponse.ts b/src/api/resources/tenants/types/TenantListResponse.ts new file mode 100644 index 0000000..4875f07 --- /dev/null +++ b/src/api/resources/tenants/types/TenantListResponse.ts @@ -0,0 +1,23 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../.."; + +export interface TenantListResponse { + /** A pointer to the next page of results. Defined only whenhas_more is set to true. */ + cursor?: string; + /** Set to true when there are more pages that can be retrieved. */ + has_more: boolean; + /** An array of Tenants */ + items: Courier.Tenant[]; + /** + * A url that may be used to generate fetch the next set of results. + * Defined only whenhas_more is set to true + */ + next_url?: string; + /** A url that may be used to generate these results. */ + url: string; + /** Always set to "list". Represents the type of this object. */ + type: "list"; +} diff --git a/src/api/resources/tenants/types/index.ts b/src/api/resources/tenants/types/index.ts index a21cfd7..af52fb2 100644 --- a/src/api/resources/tenants/types/index.ts +++ b/src/api/resources/tenants/types/index.ts @@ -1,6 +1,6 @@ -export * from "./CreateOrReplaceTenantRequest"; export * from "./DefaultPreferences"; export * from "./SubscriptionTopic"; export * from "./SubscriptionTopicStatus"; -export * from "./CreateOrReplaceTenantResponse"; +export * from "./Tenant"; +export * from "./TenantListResponse"; export * from "./TemplateProperty"; diff --git a/src/api/resources/tokenManagement/types/GetUserTokenResponse.ts b/src/api/resources/tokenManagement/types/GetUserTokenResponse.ts deleted file mode 100644 index ed89b52..0000000 --- a/src/api/resources/tokenManagement/types/GetUserTokenResponse.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Courier from "../../.."; - -export interface GetUserTokenResponse extends Courier.UserToken { - status?: Courier.TokenStatus; - /** The reason for the token status. */ - status_reason?: string; -} diff --git a/src/api/resources/translations/client/Client.ts b/src/api/resources/translations/client/Client.ts index ff6b70d..2e133f0 100644 --- a/src/api/resources/translations/client/Client.ts +++ b/src/api/resources/translations/client/Client.ts @@ -11,7 +11,7 @@ import * as errors from "../../../../errors"; export declare namespace Translations { interface Options { environment?: core.Supplier; - authorizationToken: core.Supplier; + authorizationToken?: core.Supplier; } interface RequestOptions { @@ -21,7 +21,7 @@ export declare namespace Translations { } export class Translations { - constructor(protected readonly _options: Translations.Options) {} + constructor(protected readonly _options: Translations.Options = {}) {} /** * Get translations by locale @@ -38,7 +38,7 @@ export class Translations { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -95,7 +95,7 @@ export class Translations { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", body: request, diff --git a/src/api/resources/userPreferences/types/index.ts b/src/api/resources/userPreferences/types/index.ts deleted file mode 100644 index cebd0c1..0000000 --- a/src/api/resources/userPreferences/types/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from "./UserPreferences"; -export * from "./TopicPreference"; -export * from "./UpdateSubscriptionTopicRequest"; -export * from "./UpdateSubscriptionTopicResponse"; diff --git a/src/api/resources/users/client/Client.ts b/src/api/resources/users/client/Client.ts new file mode 100644 index 0000000..e88bdc1 --- /dev/null +++ b/src/api/resources/users/client/Client.ts @@ -0,0 +1,43 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as environments from "../../../../environments"; +import * as core from "../../../../core"; +import { Preferences } from "../resources/preferences/client/Client"; +import { Tenants } from "../resources/tenants/client/Client"; +import { Tokens } from "../resources/tokens/client/Client"; + +export declare namespace Users { + interface Options { + environment?: core.Supplier; + authorizationToken?: core.Supplier; + } + + interface RequestOptions { + timeoutInSeconds?: number; + maxRetries?: number; + } +} + +export class Users { + constructor(protected readonly _options: Users.Options = {}) {} + + protected _preferences: Preferences | undefined; + + public get preferences(): Preferences { + return (this._preferences ??= new Preferences(this._options)); + } + + protected _tenants: Tenants | undefined; + + public get tenants(): Tenants { + return (this._tenants ??= new Tenants(this._options)); + } + + protected _tokens: Tokens | undefined; + + public get tokens(): Tokens { + return (this._tokens ??= new Tokens(this._options)); + } +} diff --git a/src/api/resources/tokenManagement/client/index.ts b/src/api/resources/users/client/index.ts similarity index 100% rename from src/api/resources/tokenManagement/client/index.ts rename to src/api/resources/users/client/index.ts diff --git a/src/api/resources/users/index.ts b/src/api/resources/users/index.ts new file mode 100644 index 0000000..4ce0f39 --- /dev/null +++ b/src/api/resources/users/index.ts @@ -0,0 +1,2 @@ +export * from "./resources"; +export * from "./client"; diff --git a/src/api/resources/users/resources/index.ts b/src/api/resources/users/resources/index.ts new file mode 100644 index 0000000..c365ebf --- /dev/null +++ b/src/api/resources/users/resources/index.ts @@ -0,0 +1,8 @@ +export * as preferences from "./preferences"; +export * from "./preferences/types"; +export * as tenants from "./tenants"; +export * from "./tenants/types"; +export * as tokens from "./tokens"; +export * from "./tokens/types"; +export * from "./preferences/client/requests"; +export * from "./tenants/client/requests"; diff --git a/src/api/resources/userPreferences/client/Client.ts b/src/api/resources/users/resources/preferences/client/Client.ts similarity index 83% rename from src/api/resources/userPreferences/client/Client.ts rename to src/api/resources/users/resources/preferences/client/Client.ts index 7415b6e..44be525 100644 --- a/src/api/resources/userPreferences/client/Client.ts +++ b/src/api/resources/users/resources/preferences/client/Client.ts @@ -2,16 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Courier from "../../.."; +import * as environments from "../../../../../../environments"; +import * as core from "../../../../../../core"; +import * as Courier from "../../../../.."; import urlJoin from "url-join"; -import * as errors from "../../../../errors"; +import * as errors from "../../../../../../errors"; -export declare namespace UserPreferences { +export declare namespace Preferences { interface Options { environment?: core.Supplier; - authorizationToken: core.Supplier; + authorizationToken?: core.Supplier; } interface RequestOptions { @@ -20,17 +20,17 @@ export declare namespace UserPreferences { } } -export class UserPreferences { - constructor(protected readonly _options: UserPreferences.Options) {} +export class Preferences { + constructor(protected readonly _options: Preferences.Options = {}) {} /** * Fetch all user preferences. * @throws {@link Courier.BadRequestError} */ - public async getPreferences( + public async list( userId: string, - requestOptions?: UserPreferences.RequestOptions - ): Promise { + requestOptions?: Preferences.RequestOptions + ): Promise { const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, @@ -41,14 +41,14 @@ export class UserPreferences { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, }); if (_response.ok) { - return _response.body as Courier.UserPreferences; + return _response.body as Courier.users.UserPreferencesListResponse; } if (_response.error.reason === "status-code") { @@ -82,11 +82,11 @@ export class UserPreferences { * Fetch user preferences for a specific subscription topic. * @throws {@link Courier.NotFoundError} */ - public async getSubscriptionTopic( + public async get( userId: string, topicId: string, - requestOptions?: UserPreferences.RequestOptions - ): Promise { + requestOptions?: Preferences.RequestOptions + ): Promise { const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, @@ -97,14 +97,14 @@ export class UserPreferences { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, }); if (_response.ok) { - return _response.body as Courier.TopicPreference; + return _response.body as Courier.users.UserPreferencesGetResponse; } if (_response.error.reason === "status-code") { @@ -138,12 +138,12 @@ export class UserPreferences { * Fetch user preferences for a specific subscription topic. * @throws {@link Courier.BadRequestError} */ - public async updateSubscriptionTopic( + public async update( userId: string, topicId: string, - request: Courier.UpdateSubscriptionTopicRequest, - requestOptions?: UserPreferences.RequestOptions - ): Promise { + request: Courier.users.UserPreferencesUpdateParams, + requestOptions?: Preferences.RequestOptions + ): Promise { const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, @@ -154,7 +154,7 @@ export class UserPreferences { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", body: request, @@ -162,7 +162,7 @@ export class UserPreferences { maxRetries: requestOptions?.maxRetries, }); if (_response.ok) { - return _response.body as Courier.UpdateSubscriptionTopicResponse; + return _response.body as Courier.users.UserPreferencesUpdateResponse; } if (_response.error.reason === "status-code") { diff --git a/src/api/resources/users/resources/preferences/client/index.ts b/src/api/resources/users/resources/preferences/client/index.ts new file mode 100644 index 0000000..415726b --- /dev/null +++ b/src/api/resources/users/resources/preferences/client/index.ts @@ -0,0 +1 @@ +export * from "./requests"; diff --git a/src/api/resources/userPreferences/types/UpdateSubscriptionTopicRequest.ts b/src/api/resources/users/resources/preferences/client/requests/UserPreferencesUpdateParams.ts similarity index 65% rename from src/api/resources/userPreferences/types/UpdateSubscriptionTopicRequest.ts rename to src/api/resources/users/resources/preferences/client/requests/UserPreferencesUpdateParams.ts index 9134552..5d61517 100644 --- a/src/api/resources/userPreferences/types/UpdateSubscriptionTopicRequest.ts +++ b/src/api/resources/users/resources/preferences/client/requests/UserPreferencesUpdateParams.ts @@ -2,10 +2,10 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Courier from "../../.."; +import * as Courier from "../../../../../.."; -export interface UpdateSubscriptionTopicRequest { - status?: Courier.PreferenceStatus; +export interface UserPreferencesUpdateParams { + status: Courier.PreferenceStatus; /** Should contain unique items. */ custom_routing?: Courier.ChannelClassification[]; default_status: Courier.PreferenceStatus; diff --git a/src/api/resources/users/resources/preferences/client/requests/index.ts b/src/api/resources/users/resources/preferences/client/requests/index.ts new file mode 100644 index 0000000..b56384d --- /dev/null +++ b/src/api/resources/users/resources/preferences/client/requests/index.ts @@ -0,0 +1 @@ +export { UserPreferencesUpdateParams } from "./UserPreferencesUpdateParams"; diff --git a/src/api/resources/userPreferences/index.ts b/src/api/resources/users/resources/preferences/index.ts similarity index 100% rename from src/api/resources/userPreferences/index.ts rename to src/api/resources/users/resources/preferences/index.ts diff --git a/src/api/resources/userPreferences/types/TopicPreference.ts b/src/api/resources/users/resources/preferences/types/TopicPreference.ts similarity index 89% rename from src/api/resources/userPreferences/types/TopicPreference.ts rename to src/api/resources/users/resources/preferences/types/TopicPreference.ts index d65148a..c7a28e2 100644 --- a/src/api/resources/userPreferences/types/TopicPreference.ts +++ b/src/api/resources/users/resources/preferences/types/TopicPreference.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Courier from "../../.."; +import * as Courier from "../../../../.."; export interface TopicPreference { /** Should contain unique items. */ diff --git a/src/api/resources/users/resources/preferences/types/UserPreferencesGetResponse.ts b/src/api/resources/users/resources/preferences/types/UserPreferencesGetResponse.ts new file mode 100644 index 0000000..8dfe085 --- /dev/null +++ b/src/api/resources/users/resources/preferences/types/UserPreferencesGetResponse.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../../../.."; + +export interface UserPreferencesGetResponse { + topic: Courier.users.TopicPreference; +} diff --git a/src/api/resources/userPreferences/types/UserPreferences.ts b/src/api/resources/users/resources/preferences/types/UserPreferencesListResponse.ts similarity index 54% rename from src/api/resources/userPreferences/types/UserPreferences.ts rename to src/api/resources/users/resources/preferences/types/UserPreferencesListResponse.ts index 2db920f..33c5c99 100644 --- a/src/api/resources/userPreferences/types/UserPreferences.ts +++ b/src/api/resources/users/resources/preferences/types/UserPreferencesListResponse.ts @@ -2,10 +2,10 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Courier from "../../.."; +import * as Courier from "../../../../.."; -export interface UserPreferences { +export interface UserPreferencesListResponse { paging: Courier.Paging; /** The Preferences associated with the user_id. */ - items: Courier.TopicPreference[]; + items: Courier.users.TopicPreference[]; } diff --git a/src/api/resources/userPreferences/types/UpdateSubscriptionTopicResponse.ts b/src/api/resources/users/resources/preferences/types/UserPreferencesUpdateResponse.ts similarity index 65% rename from src/api/resources/userPreferences/types/UpdateSubscriptionTopicResponse.ts rename to src/api/resources/users/resources/preferences/types/UserPreferencesUpdateResponse.ts index b8d09a2..ee0406c 100644 --- a/src/api/resources/userPreferences/types/UpdateSubscriptionTopicResponse.ts +++ b/src/api/resources/users/resources/preferences/types/UserPreferencesUpdateResponse.ts @@ -2,6 +2,6 @@ * This file was auto-generated by Fern from our API Definition. */ -export interface UpdateSubscriptionTopicResponse { +export interface UserPreferencesUpdateResponse { message: string; } diff --git a/src/api/resources/users/resources/preferences/types/index.ts b/src/api/resources/users/resources/preferences/types/index.ts new file mode 100644 index 0000000..55b317b --- /dev/null +++ b/src/api/resources/users/resources/preferences/types/index.ts @@ -0,0 +1,4 @@ +export * from "./UserPreferencesListResponse"; +export * from "./UserPreferencesGetResponse"; +export * from "./TopicPreference"; +export * from "./UserPreferencesUpdateResponse"; diff --git a/src/api/resources/users/resources/tenants/client/Client.ts b/src/api/resources/users/resources/tenants/client/Client.ts new file mode 100644 index 0000000..56507d6 --- /dev/null +++ b/src/api/resources/users/resources/tenants/client/Client.ts @@ -0,0 +1,254 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as environments from "../../../../../../environments"; +import * as core from "../../../../../../core"; +import * as Courier from "../../../../.."; +import urlJoin from "url-join"; +import * as errors from "../../../../../../errors"; + +export declare namespace Tenants { + interface Options { + environment?: core.Supplier; + authorizationToken?: core.Supplier; + } + + interface RequestOptions { + timeoutInSeconds?: number; + maxRetries?: number; + } +} + +export class Tenants { + constructor(protected readonly _options: Tenants.Options = {}) {} + + /** + * This endpoint is used to add a user to + * multiple tenants in one call. + * A custom profile can also be supplied for each tenant. + * This profile will be merged with the user's main + * profile when sending to the user with that tenant. + */ + public async addMultple( + userId: string, + request: Courier.users.AddUserToMultipleTenantsParams, + requestOptions?: Tenants.RequestOptions + ): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, + `/users/users/${userId}/tenants` + ), + method: "PUT", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@trycourier/courier", + "X-Fern-SDK-Version": "v6.0.2", + }, + contentType: "application/json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + }); + if (_response.ok) { + return; + } + + if (_response.error.reason === "status-code") { + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.CourierTimeoutError(); + case "unknown": + throw new errors.CourierError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * This endpoint is used to add a single tenant. + * + * A custom profile can also be supplied with the tenant. + * This profile will be merged with the user's main profile + * when sending to the user with that tenant. + */ + public async add( + userId: string, + tenantId: string, + request: Courier.users.AddUserToSingleTenantsParams, + requestOptions?: Tenants.RequestOptions + ): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, + `/users/users/${userId}/tenants/${tenantId}` + ), + method: "PUT", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@trycourier/courier", + "X-Fern-SDK-Version": "v6.0.2", + }, + contentType: "application/json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + }); + if (_response.ok) { + return; + } + + if (_response.error.reason === "status-code") { + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.CourierTimeoutError(); + case "unknown": + throw new errors.CourierError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * Removes a user from the supplied tenant. + */ + public async remove(userId: string, tenantId: string, requestOptions?: Tenants.RequestOptions): Promise { + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, + `/users/users/${userId}/tenants/${tenantId}` + ), + method: "DELETE", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@trycourier/courier", + "X-Fern-SDK-Version": "v6.0.2", + }, + contentType: "application/json", + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + }); + if (_response.ok) { + return; + } + + if (_response.error.reason === "status-code") { + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.CourierTimeoutError(); + case "unknown": + throw new errors.CourierError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * Returns a paginated list of user tenant associations. + */ + public async list( + userId: string, + request: Courier.users.ListTenantsForUserParams = {}, + requestOptions?: Tenants.RequestOptions + ): Promise { + const { limit, starting_after: startingAfter } = request; + const _queryParams: Record = {}; + if (limit != null) { + _queryParams["limit"] = limit.toString(); + } + + if (startingAfter != null) { + _queryParams["starting_after"] = startingAfter.toString(); + } + + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, + `/users/users/${userId}/tenants` + ), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@trycourier/courier", + "X-Fern-SDK-Version": "v6.0.2", + }, + contentType: "application/json", + queryParameters: _queryParams, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + }); + if (_response.ok) { + return _response.body as Courier.users.ListTenantsForUserResponse; + } + + if (_response.error.reason === "status-code") { + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.CourierError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.CourierTimeoutError(); + case "unknown": + throw new errors.CourierError({ + message: _response.error.errorMessage, + }); + } + } + + protected async _getAuthorizationHeader() { + const bearer = (await core.Supplier.get(this._options.authorizationToken)) ?? process.env["COURIER_AUTH_TOKEN"]; + if (bearer == null) { + throw new errors.CourierError({ + message: "Please specify COURIER_AUTH_TOKEN when instantiating the client.", + }); + } + + return `Bearer ${bearer}`; + } +} diff --git a/src/api/resources/users/resources/tenants/client/index.ts b/src/api/resources/users/resources/tenants/client/index.ts new file mode 100644 index 0000000..415726b --- /dev/null +++ b/src/api/resources/users/resources/tenants/client/index.ts @@ -0,0 +1 @@ +export * from "./requests"; diff --git a/src/api/resources/users/resources/tenants/client/requests/AddUserToMultipleTenantsParams.ts b/src/api/resources/users/resources/tenants/client/requests/AddUserToMultipleTenantsParams.ts new file mode 100644 index 0000000..4be61c4 --- /dev/null +++ b/src/api/resources/users/resources/tenants/client/requests/AddUserToMultipleTenantsParams.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../../../../.."; + +export interface AddUserToMultipleTenantsParams { + tenants: Courier.users.UserTenantAssociation[]; +} diff --git a/src/api/resources/users/resources/tenants/client/requests/AddUserToSingleTenantsParams.ts b/src/api/resources/users/resources/tenants/client/requests/AddUserToSingleTenantsParams.ts new file mode 100644 index 0000000..7bf0fe9 --- /dev/null +++ b/src/api/resources/users/resources/tenants/client/requests/AddUserToSingleTenantsParams.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface AddUserToSingleTenantsParams { + profiles: Record; +} diff --git a/src/api/resources/users/resources/tenants/client/requests/ListTenantsForUserParams.ts b/src/api/resources/users/resources/tenants/client/requests/ListTenantsForUserParams.ts new file mode 100644 index 0000000..a131eaf --- /dev/null +++ b/src/api/resources/users/resources/tenants/client/requests/ListTenantsForUserParams.ts @@ -0,0 +1,15 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface ListTenantsForUserParams { + /** + * The number of accounts to return + * (defaults to 20, maximum value of 100) + */ + limit?: number; + /** + * Value of next_page from previous response + */ + starting_after?: number; +} diff --git a/src/api/resources/users/resources/tenants/client/requests/index.ts b/src/api/resources/users/resources/tenants/client/requests/index.ts new file mode 100644 index 0000000..0b45b0f --- /dev/null +++ b/src/api/resources/users/resources/tenants/client/requests/index.ts @@ -0,0 +1,3 @@ +export { AddUserToMultipleTenantsParams } from "./AddUserToMultipleTenantsParams"; +export { AddUserToSingleTenantsParams } from "./AddUserToSingleTenantsParams"; +export { ListTenantsForUserParams } from "./ListTenantsForUserParams"; diff --git a/src/api/resources/users/resources/tenants/index.ts b/src/api/resources/users/resources/tenants/index.ts new file mode 100644 index 0000000..c9240f8 --- /dev/null +++ b/src/api/resources/users/resources/tenants/index.ts @@ -0,0 +1,2 @@ +export * from "./types"; +export * from "./client"; diff --git a/src/api/resources/users/resources/tenants/types/ListTenantsForUserResponse.ts b/src/api/resources/users/resources/tenants/types/ListTenantsForUserResponse.ts new file mode 100644 index 0000000..a324459 --- /dev/null +++ b/src/api/resources/users/resources/tenants/types/ListTenantsForUserResponse.ts @@ -0,0 +1,25 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../../../.."; + +export interface ListTenantsForUserResponse { + items?: Courier.users.UserTenantAssociation; + /** Set to true when there are more pages that can be retrieved. */ + has_more: boolean; + /** A url that may be used to generate these results. */ + url: string; + /** + * A url that may be used to generate fetch the next set of results. + * Defined only when `has_more` is set to true + */ + next_url?: string; + /** + * A pointer to the next page of results. Defined + * only when `has_more` is set to true + */ + cursor?: string; + /** Always set to `list`. Represents the type of this object. */ + type: "list"; +} diff --git a/src/api/resources/users/resources/tenants/types/UserTenantAssociation.ts b/src/api/resources/users/resources/tenants/types/UserTenantAssociation.ts new file mode 100644 index 0000000..fb8fd0b --- /dev/null +++ b/src/api/resources/users/resources/tenants/types/UserTenantAssociation.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface UserTenantAssociation { + /** Tenant ID the user association is tied to. */ + tenant_id: string; + profile: Record; +} diff --git a/src/api/resources/users/resources/tenants/types/index.ts b/src/api/resources/users/resources/tenants/types/index.ts new file mode 100644 index 0000000..74f66d3 --- /dev/null +++ b/src/api/resources/users/resources/tenants/types/index.ts @@ -0,0 +1,2 @@ +export * from "./UserTenantAssociation"; +export * from "./ListTenantsForUserResponse"; diff --git a/src/api/resources/tokenManagement/client/Client.ts b/src/api/resources/users/resources/tokens/client/Client.ts similarity index 89% rename from src/api/resources/tokenManagement/client/Client.ts rename to src/api/resources/users/resources/tokens/client/Client.ts index d6569ee..02cb178 100644 --- a/src/api/resources/tokenManagement/client/Client.ts +++ b/src/api/resources/users/resources/tokens/client/Client.ts @@ -2,16 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Courier from "../../.."; +import * as environments from "../../../../../../environments"; +import * as core from "../../../../../../core"; +import * as Courier from "../../../../.."; import urlJoin from "url-join"; -import * as errors from "../../../../errors"; +import * as errors from "../../../../../../errors"; -export declare namespace TokenManagement { +export declare namespace Tokens { interface Options { environment?: core.Supplier; - authorizationToken: core.Supplier; + authorizationToken?: core.Supplier; } interface RequestOptions { @@ -20,14 +20,14 @@ export declare namespace TokenManagement { } } -export class TokenManagement { - constructor(protected readonly _options: TokenManagement.Options) {} +export class Tokens { + constructor(protected readonly _options: Tokens.Options = {}) {} /** * Adds multiple tokens to a user and overwrites matching existing tokens. * @throws {@link Courier.BadRequestError} */ - public async addMultipleTokens(userId: string, requestOptions?: TokenManagement.RequestOptions): Promise { + public async addMultiple(userId: string, requestOptions?: Tokens.RequestOptions): Promise { const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, @@ -38,7 +38,7 @@ export class TokenManagement { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -82,8 +82,8 @@ export class TokenManagement { public async add( userId: string, token: string, - request: Courier.UserToken, - requestOptions?: TokenManagement.RequestOptions + request: Courier.users.UserToken, + requestOptions?: Tokens.RequestOptions ): Promise { const _response = await core.fetcher({ url: urlJoin( @@ -95,7 +95,7 @@ export class TokenManagement { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", body: request, @@ -140,8 +140,8 @@ export class TokenManagement { public async update( userId: string, token: string, - request: Courier.PatchUserTokenOpts, - requestOptions?: TokenManagement.RequestOptions + request: Courier.users.PatchUserTokenOpts, + requestOptions?: Tokens.RequestOptions ): Promise { const _response = await core.fetcher({ url: urlJoin( @@ -153,7 +153,7 @@ export class TokenManagement { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", body: request, @@ -198,8 +198,8 @@ export class TokenManagement { public async get( userId: string, token: string, - requestOptions?: TokenManagement.RequestOptions - ): Promise { + requestOptions?: Tokens.RequestOptions + ): Promise { const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, @@ -210,14 +210,14 @@ export class TokenManagement { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, }); if (_response.ok) { - return _response.body as Courier.GetUserTokenResponse; + return _response.body as Courier.users.GetUserTokenResponse; } if (_response.error.reason === "status-code") { @@ -253,8 +253,8 @@ export class TokenManagement { */ public async list( userId: string, - requestOptions?: TokenManagement.RequestOptions - ): Promise { + requestOptions?: Tokens.RequestOptions + ): Promise { const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.CourierEnvironment.Production, @@ -265,14 +265,14 @@ export class TokenManagement { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@trycourier/courier", - "X-Fern-SDK-Version": "6.0.1", + "X-Fern-SDK-Version": "v6.0.2", }, contentType: "application/json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, }); if (_response.ok) { - return _response.body as Courier.GetAllTokensResponse; + return _response.body as Courier.users.GetAllTokensResponse; } if (_response.error.reason === "status-code") { diff --git a/src/api/resources/userPreferences/client/index.ts b/src/api/resources/users/resources/tokens/client/index.ts similarity index 100% rename from src/api/resources/userPreferences/client/index.ts rename to src/api/resources/users/resources/tokens/client/index.ts diff --git a/src/api/resources/users/resources/tokens/index.ts b/src/api/resources/users/resources/tokens/index.ts new file mode 100644 index 0000000..c9240f8 --- /dev/null +++ b/src/api/resources/users/resources/tokens/index.ts @@ -0,0 +1,2 @@ +export * from "./types"; +export * from "./client"; diff --git a/src/api/resources/tokenManagement/types/DeleteUserTokenOpts.ts b/src/api/resources/users/resources/tokens/types/DeleteUserTokenOpts.ts similarity index 100% rename from src/api/resources/tokenManagement/types/DeleteUserTokenOpts.ts rename to src/api/resources/users/resources/tokens/types/DeleteUserTokenOpts.ts diff --git a/src/api/resources/tokenManagement/types/Device.ts b/src/api/resources/users/resources/tokens/types/Device.ts similarity index 100% rename from src/api/resources/tokenManagement/types/Device.ts rename to src/api/resources/users/resources/tokens/types/Device.ts diff --git a/src/api/resources/tokenManagement/types/ExpiryDate.ts b/src/api/resources/users/resources/tokens/types/ExpiryDate.ts similarity index 100% rename from src/api/resources/tokenManagement/types/ExpiryDate.ts rename to src/api/resources/users/resources/tokens/types/ExpiryDate.ts diff --git a/src/api/resources/tokenManagement/types/GetAllTokensResponse.ts b/src/api/resources/users/resources/tokens/types/GetAllTokensResponse.ts similarity index 55% rename from src/api/resources/tokenManagement/types/GetAllTokensResponse.ts rename to src/api/resources/users/resources/tokens/types/GetAllTokensResponse.ts index 2c2b7f7..b3f8bc5 100644 --- a/src/api/resources/tokenManagement/types/GetAllTokensResponse.ts +++ b/src/api/resources/users/resources/tokens/types/GetAllTokensResponse.ts @@ -2,9 +2,9 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Courier from "../../.."; +import * as Courier from "../../../../.."; /** * A list of tokens registered with the user. */ -export type GetAllTokensResponse = Courier.UserToken[]; +export type GetAllTokensResponse = Courier.users.UserToken[]; diff --git a/src/api/resources/tokenManagement/types/GetUserTokenOpts.ts b/src/api/resources/users/resources/tokens/types/GetUserTokenOpts.ts similarity index 100% rename from src/api/resources/tokenManagement/types/GetUserTokenOpts.ts rename to src/api/resources/users/resources/tokens/types/GetUserTokenOpts.ts diff --git a/src/api/resources/users/resources/tokens/types/GetUserTokenResponse.ts b/src/api/resources/users/resources/tokens/types/GetUserTokenResponse.ts new file mode 100644 index 0000000..833f2eb --- /dev/null +++ b/src/api/resources/users/resources/tokens/types/GetUserTokenResponse.ts @@ -0,0 +1,11 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../../../.."; + +export interface GetUserTokenResponse extends Courier.users.UserToken { + status?: Courier.users.TokenStatus; + /** The reason for the token status. */ + status_reason?: string; +} diff --git a/src/api/resources/tokenManagement/types/GetUserTokensOpts.ts b/src/api/resources/users/resources/tokens/types/GetUserTokensOpts.ts similarity index 100% rename from src/api/resources/tokenManagement/types/GetUserTokensOpts.ts rename to src/api/resources/users/resources/tokens/types/GetUserTokensOpts.ts diff --git a/src/api/resources/tokenManagement/types/PatchOp.ts b/src/api/resources/users/resources/tokens/types/PatchOp.ts similarity index 100% rename from src/api/resources/tokenManagement/types/PatchOp.ts rename to src/api/resources/users/resources/tokens/types/PatchOp.ts diff --git a/src/api/resources/tokenManagement/types/PatchOperation.ts b/src/api/resources/users/resources/tokens/types/PatchOperation.ts similarity index 100% rename from src/api/resources/tokenManagement/types/PatchOperation.ts rename to src/api/resources/users/resources/tokens/types/PatchOperation.ts diff --git a/src/api/resources/users/resources/tokens/types/PatchUserTokenOpts.ts b/src/api/resources/users/resources/tokens/types/PatchUserTokenOpts.ts new file mode 100644 index 0000000..a1c02a8 --- /dev/null +++ b/src/api/resources/users/resources/tokens/types/PatchUserTokenOpts.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Courier from "../../../../.."; + +export interface PatchUserTokenOpts { + patch: Courier.users.PatchOperation[]; +} diff --git a/src/api/resources/tokenManagement/types/ProviderKey.ts b/src/api/resources/users/resources/tokens/types/ProviderKey.ts similarity index 100% rename from src/api/resources/tokenManagement/types/ProviderKey.ts rename to src/api/resources/users/resources/tokens/types/ProviderKey.ts diff --git a/src/api/resources/tokenManagement/types/PutUserTokenOpts.ts b/src/api/resources/users/resources/tokens/types/PutUserTokenOpts.ts similarity index 62% rename from src/api/resources/tokenManagement/types/PutUserTokenOpts.ts rename to src/api/resources/users/resources/tokens/types/PutUserTokenOpts.ts index 84053cc..483f427 100644 --- a/src/api/resources/tokenManagement/types/PutUserTokenOpts.ts +++ b/src/api/resources/users/resources/tokens/types/PutUserTokenOpts.ts @@ -2,9 +2,9 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Courier from "../../.."; +import * as Courier from "../../../../.."; export interface PutUserTokenOpts { user_id: string; - token: Courier.UserToken; + token: Courier.users.UserToken; } diff --git a/src/api/resources/tokenManagement/types/PutUserTokensOpts.ts b/src/api/resources/users/resources/tokens/types/PutUserTokensOpts.ts similarity index 62% rename from src/api/resources/tokenManagement/types/PutUserTokensOpts.ts rename to src/api/resources/users/resources/tokens/types/PutUserTokensOpts.ts index 4224349..7360805 100644 --- a/src/api/resources/tokenManagement/types/PutUserTokensOpts.ts +++ b/src/api/resources/users/resources/tokens/types/PutUserTokensOpts.ts @@ -2,9 +2,9 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Courier from "../../.."; +import * as Courier from "../../../../.."; export interface PutUserTokensOpts { user_id: string; - tokens: Courier.UserToken[]; + tokens: Courier.users.UserToken[]; } diff --git a/src/api/resources/tokenManagement/types/TokenStatus.ts b/src/api/resources/users/resources/tokens/types/TokenStatus.ts similarity index 100% rename from src/api/resources/tokenManagement/types/TokenStatus.ts rename to src/api/resources/users/resources/tokens/types/TokenStatus.ts diff --git a/src/api/resources/tokenManagement/types/Tracking.ts b/src/api/resources/users/resources/tokens/types/Tracking.ts similarity index 100% rename from src/api/resources/tokenManagement/types/Tracking.ts rename to src/api/resources/users/resources/tokens/types/Tracking.ts diff --git a/src/api/resources/tokenManagement/types/UserToken.ts b/src/api/resources/users/resources/tokens/types/UserToken.ts similarity index 71% rename from src/api/resources/tokenManagement/types/UserToken.ts rename to src/api/resources/users/resources/tokens/types/UserToken.ts index a6b0cfc..6ca62fd 100644 --- a/src/api/resources/tokenManagement/types/UserToken.ts +++ b/src/api/resources/users/resources/tokens/types/UserToken.ts @@ -2,18 +2,18 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Courier from "../../.."; +import * as Courier from "../../../../.."; export interface UserToken { /** Full body of the token. Must match token in URL. */ token?: string; - provider_key: Courier.ProviderKey; + provider_key: Courier.users.ProviderKey; /** ISO 8601 formatted date the token expires. Defaults to 2 months. Set to false to disable expiration. */ - expiry_date?: Courier.ExpiryDate; + expiry_date?: Courier.users.ExpiryDate; /** Properties sent to the provider along with the token */ properties?: any; /** Information about the device the token is associated with. */ - device?: Courier.Device; + device?: Courier.users.Device; /** Information about the device the token is associated with. */ - tracking?: Courier.Tracking; + tracking?: Courier.users.Tracking; } diff --git a/src/api/resources/tokenManagement/types/index.ts b/src/api/resources/users/resources/tokens/types/index.ts similarity index 100% rename from src/api/resources/tokenManagement/types/index.ts rename to src/api/resources/users/resources/tokens/types/index.ts diff --git a/src/api/types/SendMessageResponse.ts b/src/api/types/SendMessageResponse.ts index 8644374..97dd11c 100644 --- a/src/api/types/SendMessageResponse.ts +++ b/src/api/types/SendMessageResponse.ts @@ -9,7 +9,6 @@ export interface SendMessageResponse { * For send requests that have a single recipient, the `requestId` is assigned to the derived message as its message_id. Therefore the `requestId` can be supplied to the Message's API for single recipient messages. * * For send requests that have multiple recipients (accounts, audiences, lists, etc.), Courier assigns a unique id to each derived message as its `message_id`. Therefore the `requestId` cannot be supplied to the Message's API for single-recipient messages. - * */ requestId: string; } diff --git a/src/core/fetcher/APIResponse.ts b/src/core/fetcher/APIResponse.ts index ea838f3..3664d09 100644 --- a/src/core/fetcher/APIResponse.ts +++ b/src/core/fetcher/APIResponse.ts @@ -3,6 +3,7 @@ export type APIResponse = SuccessfulResponse | Failed export interface SuccessfulResponse { ok: true; body: T; + headers?: Record; } export interface FailedResponse { diff --git a/src/core/fetcher/Fetcher.ts b/src/core/fetcher/Fetcher.ts index 96c7004..e25819a 100644 --- a/src/core/fetcher/Fetcher.ts +++ b/src/core/fetcher/Fetcher.ts @@ -1,7 +1,11 @@ -import axios, { AxiosAdapter, AxiosError, AxiosResponse } from "axios"; +import { default as FormData } from "form-data"; import qs from "qs"; import { APIResponse } from "./APIResponse"; +if (typeof window === "undefined") { + global.fetch = require("node-fetch"); +} + export type FetchFunction = (args: Fetcher.Args) => Promise>; export declare namespace Fetcher { @@ -15,9 +19,7 @@ export declare namespace Fetcher { timeoutMs?: number; maxRetries?: number; withCredentials?: boolean; - responseType?: "json" | "blob"; - adapter?: AxiosAdapter; - onUploadProgress?: (event: ProgressEvent) => void; + responseType?: "json" | "blob" | "streaming"; } export type Error = FailedStatusCodeError | NonJsonError | TimeoutError | UnknownError; @@ -62,29 +64,37 @@ async function fetcherImpl(args: Fetcher.Args): Promise => - await axios({ - url: args.url, - params: args.queryParameters, - paramsSerializer: (params) => { - return qs.stringify(params, { arrayFormat: "repeat" }); - }, + const url = + Object.keys(args.queryParameters ?? {}).length > 0 + ? `${args.url}?${qs.stringify(args.queryParameters, { arrayFormat: "repeat" })}` + : args.url; + + let body: BodyInit | undefined = undefined; + if (args.body instanceof FormData) { + // @ts-expect-error + body = args.body; + } else { + body = JSON.stringify(args.body); + } + + const makeRequest = async (): Promise => { + const controller = new AbortController(); + let abortId = undefined; + if (args.timeoutMs != null) { + abortId = setTimeout(() => controller.abort(), args.timeoutMs); + } + const response = await fetch(url, { method: args.method, headers, - data: args.body, - validateStatus: () => true, - transformResponse: (response) => response, - timeout: args.timeoutMs, - transitional: { - clarifyTimeoutError: true, - }, - withCredentials: args.withCredentials, - adapter: args.adapter, - onUploadProgress: args.onUploadProgress, - maxBodyLength: Infinity, - maxContentLength: Infinity, - responseType: args.responseType ?? "json", + body, + signal: controller.signal, + credentials: args.withCredentials ? "same-origin" : undefined, }); + if (abortId != null) { + clearTimeout(abortId); + } + return response; + }; try { let response = await makeRequest(); @@ -97,25 +107,28 @@ async function fetcherImpl(args: Fetcher.Args): Promise= 500 ) { const delay = Math.min(INITIAL_RETRY_DELAY * Math.pow(i, 2), MAX_RETRY_DELAY); - response = await new Promise((resolve) => setTimeout(resolve, delay)); + await new Promise((resolve) => setTimeout(resolve, delay)); + response = await makeRequest(); } else { break; } } let body: unknown; - if (args.responseType === "blob") { - body = response.data; - } else if (response.data != null && response.data.length > 0) { + if (response.body != null && args.responseType === "blob") { + body = await response.blob(); + } else if (response.body != null && args.responseType === "streaming") { + body = response.body; + } else if (response.body != null) { try { - body = JSON.parse(response.data) ?? undefined; - } catch { + body = await response.json(); + } catch (err) { return { ok: false, error: { reason: "non-json", statusCode: response.status, - rawBody: response.data, + rawBody: await response.text(), }, }; } @@ -125,6 +138,7 @@ async function fetcherImpl(args: Fetcher.Args): Promise(args: Fetcher.Args): Promise, header: string): string | undefined { + for (const [headerKey, headerValue] of Object.entries(headers)) { + if (headerKey.toLowerCase() === header.toLowerCase()) { + return headerValue; + } + } + return undefined; +} diff --git a/src/core/fetcher/index.ts b/src/core/fetcher/index.ts index 6becab2..2d658ca 100644 --- a/src/core/fetcher/index.ts +++ b/src/core/fetcher/index.ts @@ -1,4 +1,5 @@ export type { APIResponse } from "./APIResponse"; export { fetcher } from "./Fetcher"; export type { Fetcher, FetchFunction } from "./Fetcher"; +export { getHeader } from "./getHeader"; export { Supplier } from "./Supplier"; diff --git a/yarn.lock b/yarn.lock index fa08e94..e504656 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,21 @@ # yarn lockfile v1 +"@types/node-fetch@2.6.9": + version "2.6.9" + resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.9.tgz#15f529d247f1ede1824f7e7acdaa192d5f28071e" + integrity sha512-bQVlnMLFJ2d35DkPNjEPmd9ueO/rh5EiaZt2bhqiSarPjZIuIV6bPQVqcrEyvNo+AfTrRGVazle1tl597w3gfA== + dependencies: + "@types/node" "*" + form-data "^4.0.0" + +"@types/node@*": + version "20.10.5" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.10.5.tgz#47ad460b514096b7ed63a1dae26fad0914ed3ab2" + integrity sha512-nNPsNE65wjMxEKI93yOP+NPGGBJz/PoN3kZsVLee0XMiJolxSekEVD8wRwBUBqkwc7UWop0edW50yrCQW4CyRw== + dependencies: + undici-types "~5.26.4" + "@types/node@17.0.33": version "17.0.33" resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.33.tgz#3c1879b276dc63e73030bb91165e62a4509cd506" @@ -22,14 +37,6 @@ asynckit@^0.4.0: resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q== -axios@0.27.2: - version "0.27.2" - resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972" - integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ== - dependencies: - follow-redirects "^1.14.9" - form-data "^4.0.0" - call-bind@^1.0.0: version "1.0.5" resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.5.tgz#6fa2b7845ce0ea49bf4d8b9ef64727a2c2e2e513" @@ -60,12 +67,7 @@ delayed-stream@~1.0.0: resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ== -follow-redirects@^1.14.9: - version "1.15.3" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.3.tgz#fe2f3ef2690afce7e82ed0b44db08165b207123a" - integrity sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q== - -form-data@^4.0.0: +form-data@4.0.0, form-data@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== @@ -137,6 +139,13 @@ mime-types@^2.1.12: dependencies: mime-db "1.52.0" +node-fetch@2.7.0: + version "2.7.0" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d" + integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A== + dependencies: + whatwg-url "^5.0.0" + object-inspect@^1.9.0: version "1.13.1" resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.13.1.tgz#b96c6109324ccfef6b12216a956ca4dc2ff94bc2" @@ -173,12 +182,35 @@ side-channel@^1.0.4: get-intrinsic "^1.0.2" object-inspect "^1.9.0" +tr46@~0.0.3: + version "0.0.3" + resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" + integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw== + typescript@4.6.4: version "4.6.4" resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.4.tgz#caa78bbc3a59e6a5c510d35703f6a09877ce45e9" integrity sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg== +undici-types@~5.26.4: + version "5.26.5" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" + integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== + url-join@4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/url-join/-/url-join-4.0.1.tgz#b642e21a2646808ffa178c4c5fda39844e12cde7" integrity sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA== + +webidl-conversions@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" + integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ== + +whatwg-url@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d" + integrity sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw== + dependencies: + tr46 "~0.0.3" + webidl-conversions "^3.0.0"