@maxio-com/advanced-billing-sdk
Version:
Ultimate billing and pricing flexibility for B2B SaaS. Maxio integrates directly into your product, so you can seamlessly manage your product catalog, bill customers, and collect payments.
421 lines • 29.1 kB
JavaScript
"use strict";
/**
* AdvancedBilling
*
* This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomFieldsController = void 0;
var tslib_1 = require("tslib");
var core_js_1 = require("../core.js");
var basicDateField_js_1 = require("../models/basicDateField.js");
var createMetadataRequest_js_1 = require("../models/createMetadataRequest.js");
var createMetafieldsRequest_js_1 = require("../models/createMetafieldsRequest.js");
var listMetafieldsResponse_js_1 = require("../models/listMetafieldsResponse.js");
var metadata_js_1 = require("../models/metadata.js");
var metafield_js_1 = require("../models/metafield.js");
var paginatedMetadata_js_1 = require("../models/paginatedMetadata.js");
var resourceType_js_1 = require("../models/resourceType.js");
var sortingDirection_js_1 = require("../models/sortingDirection.js");
var updateMetadataRequest_js_1 = require("../models/updateMetadataRequest.js");
var updateMetafieldsRequest_js_1 = require("../models/updateMetafieldsRequest.js");
var schema_js_1 = require("../schema.js");
var baseController_js_1 = require("./baseController.js");
var core_1 = require("@apimatic/core");
var singleErrorResponseError_js_1 = require("../errors/singleErrorResponseError.js");
var CustomFieldsController = /** @class */ (function (_super) {
tslib_1.__extends(CustomFieldsController, _super);
function CustomFieldsController() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Creates metafields on a Site for either the Subscriptions or Customers resource.
*
* Metafields and their metadata are created in the Custom Fields configuration page on your Site.
* Metafields can be populated with metadata when you create them or later with the [Update
* Metafield]($e/Custom%20Fields/updateMetafield), [Create Metadata]($e/Custom%20Fields/createMetadata),
* or [Update Metadata]($e/Custom%20Fields/updateMetadata) endpoints. The Create Metadata and Update
* Metadata endpoints allow you to add metafields and metadata values to a specific subscription or
* customer.
*
* Each site is limited to 100 unique metafields per resource. This means you can have 100 metafields
* for Subscriptions and another 100 for Customers.
*
* > Note: After creating a metafield, the resource type cannot be modified.
*
* In the UI and product documentation, metafields and metadata are called Custom Fields.
*
* - Metafield is the custom field
* - Metadata is the data populating the custom field.
*
* See [Custom Fields Reference](https://docs.maxio.com/hc/en-us/articles/24266140850573-Custom-Fields-
* Reference) and [Custom Fields Tab](https://maxio.zendesk.com/hc/en-us/articles/24251701302925-
* Subscription-Summary-Custom-Fields-Tab) for information on using Custom Fields in the Advanced
* Billing UI.
*
* @param resourceType The resource type to which the metafields belong.
* @param body
* @return Response from the API call
*/
CustomFieldsController.prototype.createMetafields = function (resourceType, body, requestOptions) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_a) {
req = this.createRequest('POST');
mapped = req.prepareArgs({
resourceType: [resourceType, resourceType_js_1.resourceTypeSchema],
body: [body, (0, schema_js_1.optional)(createMetafieldsRequest_js_1.createMetafieldsRequestSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["/", "/metafields.json"], ["/", "/metafields.json"])), mapped.resourceType);
req.throwOn(422, singleErrorResponseError_js_1.SingleErrorResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson((0, schema_js_1.array)(metafield_js_1.metafieldSchema), requestOptions)];
});
});
};
/**
* Lists the metafields and their associated details for a Site and resource type. You can filter the
* request to a specific metafield.
*
* @param resourceType The resource type to which the metafields belong.
* @param name Filter by the name of the metafield.
* @param page Result records are organized in pages. By default, the first page of
* results is displayed. The page parameter specifies a page number of
* results to fetch. You can start navigating through the pages to consume
* the results. You do this by passing in a page parameter. Retrieve the
* next page by adding ?page=2 to the query string. If there are no results
* to return, then an empty result set will be returned. Use in query
* `page=1`.
* @param perPage This parameter indicates how many records to fetch in each request.
* Default value is 20. The maximum allowed values is 200; any per_page
* value over 200 will be changed to 200. Use in query `per_page=200`.
* @param direction Controls the order in which results are returned. Use in query
* `direction=asc`.
* @return Response from the API call
*/
CustomFieldsController.prototype.listMetafields = function (_a, requestOptions_1) {
return tslib_1.__awaiter(this, arguments, void 0, function (_b, requestOptions) {
var req, mapped;
var resourceType = _b.resourceType, name = _b.name, page = _b.page, perPage = _b.perPage, direction = _b.direction;
return tslib_1.__generator(this, function (_c) {
req = this.createRequest('GET');
mapped = req.prepareArgs({
resourceType: [resourceType, resourceType_js_1.resourceTypeSchema],
name: [name, (0, schema_js_1.optional)((0, schema_js_1.string)())],
page: [page, (0, schema_js_1.optional)((0, schema_js_1.number)())],
perPage: [perPage, (0, schema_js_1.optional)((0, schema_js_1.number)())],
direction: [direction, (0, schema_js_1.optional)(sortingDirection_js_1.sortingDirectionSchema)],
});
req.query('name', mapped.name, core_js_1.commaPrefix);
req.query('page', mapped.page, core_js_1.commaPrefix);
req.query('per_page', mapped.perPage, core_js_1.commaPrefix);
req.query('direction', mapped.direction, core_js_1.commaPrefix);
req.appendTemplatePath(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["/", "/metafields.json"], ["/", "/metafields.json"])), mapped.resourceType);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(listMetafieldsResponse_js_1.listMetafieldsResponseSchema, requestOptions)];
});
});
};
/**
* Updates metafields on your Site for a resource type. Depending on the request structure, you can
* update or add metafields and metadata to the Subscriptions or Customers resource.
*
* With this endpoint, you can:
*
* - Add metafields. If the metafield specified in current_name does not exist, a new metafield is
* added.
* >Note: Each site is limited to 100 unique metafields per resource. This means you can have 100
* metafields for Subscriptions and another 100 for Customers.
*
* - Change the name of a metafield.
* >Note: To keep the metafield name the same and only update the metadata for the metafield, you
* must use the current metafield name in both the `current_name` and `name` parameters.
*
* - Change the input type for the metafield. For example, you can change a metafield input type from
* text to a dropdown. If you change the input type from text to a dropdown or radio, you must update
* the specific subscriptions or customers where the metafield was used to reflect the updated
* metafield and metadata.
*
* - Add metadata values to the existing metadata for a dropdown or radio metafield.
* >Note: Updates to metadata overwrite. To add one or more values, you must specify all metadata
* values including the new value you want to add.
*
* - Add new metadata to a dropdown or radio for a metafield that was created without metadata.
*
* - Remove metadata for a dropdown or radio for a metafield.
* >Note: Updates to metadata overwrite existing values. To remove one or more values, specify all
* metadata values except those you want to remove.
*
* - Add or update scope settings for a metafield.
* >Note: Scope changes overwrite existing settings. You must specify the complete scope, including
* the changes you want to make.
*
* @param resourceType The resource type to which the metafields belong.
* @param body
* @return Response from the API call
*/
CustomFieldsController.prototype.updateMetafield = function (resourceType, body, requestOptions) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_a) {
req = this.createRequest('PUT');
mapped = req.prepareArgs({
resourceType: [resourceType, resourceType_js_1.resourceTypeSchema],
body: [body, (0, schema_js_1.optional)(updateMetafieldsRequest_js_1.updateMetafieldsRequestSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["/", "/metafields.json"], ["/", "/metafields.json"])), mapped.resourceType);
req.throwOn(422, singleErrorResponseError_js_1.SingleErrorResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson((0, schema_js_1.array)(metafield_js_1.metafieldSchema), requestOptions)];
});
});
};
/**
* Deletes a metafield from your Site. Removes the metafield and associated metadata from all
* Subscriptions or Customers resources on the Site.
*
* @param resourceType The resource type to which the metafields belong.
* @param name The name of the metafield to be deleted
* @return Response from the API call
*/
CustomFieldsController.prototype.deleteMetafield = function (resourceType, name, requestOptions) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_a) {
req = this.createRequest('DELETE');
mapped = req.prepareArgs({
resourceType: [resourceType, resourceType_js_1.resourceTypeSchema],
name: [name, (0, schema_js_1.optional)((0, schema_js_1.string)())],
});
req.query('name', mapped.name, core_js_1.commaPrefix);
req.appendTemplatePath(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["/", "/metafields.json"], ["/", "/metafields.json"])), mapped.resourceType);
req.throwOn(404, core_1.ApiError, true, "Not Found:'{$response.body}'");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.call(requestOptions)];
});
});
};
/**
* Creates metadata and metafields for a specific subscription or customer, or updates metadata values
* of existing metafields for a subscription or customer. Metadata values are limited to 2 KB in size.
*
* If you create metadata on a subscription or customer with a metafield that does not already exist,
* the metafield is created with the metadata you specify and it is always added as a text field. You
* can update the input_type for the metafield with the [Update
* Metafield]($e/Custom%20Fields/updateMetafield) endpoint.
*
* >Note: Each site is limited to 100 unique metafields per resource. This means you can have 100
* metafields for Subscriptions and another 100 for Customers.
*
* @param resourceType The resource type to which the metafields belong.
* @param resourceId The Advanced Billing id of the customer or the subscription
* for which the metadata applies
* @param body
* @return Response from the API call
*/
CustomFieldsController.prototype.createMetadata = function (resourceType, resourceId, body, requestOptions) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_a) {
req = this.createRequest('POST');
mapped = req.prepareArgs({
resourceType: [resourceType, resourceType_js_1.resourceTypeSchema],
resourceId: [resourceId, (0, schema_js_1.number)()],
body: [body, (0, schema_js_1.optional)(createMetadataRequest_js_1.createMetadataRequestSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["/", "/", "/metadata.json"], ["/", "/", "/metadata.json"])), mapped.resourceType, mapped.resourceId);
req.throwOn(422, singleErrorResponseError_js_1.SingleErrorResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson((0, schema_js_1.array)(metadata_js_1.metadataSchema), requestOptions)];
});
});
};
/**
* Lists metadata and metafields for a specific customer or subscription.
*
* @param resourceType The resource type to which the metafields belong.
* @param resourceId The Advanced Billing id of the customer or the subscription for which the
* metadata applies
* @param page Result records are organized in pages. By default, the first page of results
* is displayed. The page parameter specifies a page number of results to fetch.
* You can start navigating through the pages to consume the results. You do
* this by passing in a page parameter. Retrieve the next page by adding ?page=2
* to the query string. If there are no results to return, then an empty result
* set will be returned. Use in query `page=1`.
* @param perPage This parameter indicates how many records to fetch in each request. Default
* value is 20. The maximum allowed values is 200; any per_page value over 200
* will be changed to 200. Use in query `per_page=200`.
* @return Response from the API call
*/
CustomFieldsController.prototype.listMetadata = function (_a, requestOptions_1) {
return tslib_1.__awaiter(this, arguments, void 0, function (_b, requestOptions) {
var req, mapped;
var resourceType = _b.resourceType, resourceId = _b.resourceId, page = _b.page, perPage = _b.perPage;
return tslib_1.__generator(this, function (_c) {
req = this.createRequest('GET');
mapped = req.prepareArgs({
resourceType: [resourceType, resourceType_js_1.resourceTypeSchema],
resourceId: [resourceId, (0, schema_js_1.number)()],
page: [page, (0, schema_js_1.optional)((0, schema_js_1.number)())],
perPage: [perPage, (0, schema_js_1.optional)((0, schema_js_1.number)())],
});
req.query('page', mapped.page, core_js_1.commaPrefix);
req.query('per_page', mapped.perPage, core_js_1.commaPrefix);
req.appendTemplatePath(templateObject_6 || (templateObject_6 = tslib_1.__makeTemplateObject(["/", "/", "/metadata.json"], ["/", "/", "/metadata.json"])), mapped.resourceType, mapped.resourceId);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(paginatedMetadata_js_1.paginatedMetadataSchema, requestOptions)];
});
});
};
/**
* Updates metadata and metafields on the Site and the customer or subscription specified, and updates
* the metadata value on a subscription or customer.
*
* If you update metadata on a subscription or customer with a metafield that does not already exist,
* the metafield is created with the metadata you specify and it is always added as a text field to the
* Site and to the subscription or customer you specify. You can update the input_type for the
* metafield with the Update Metafield endpoint.
*
* Each site is limited to 100 unique metafields per resource. This means you can have 100 metafields
* for Subscription and another 100 for Customer.
*
* @param resourceType The resource type to which the metafields belong.
* @param resourceId The Advanced Billing id of the customer or the subscription
* for which the metadata applies
* @param body
* @return Response from the API call
*/
CustomFieldsController.prototype.updateMetadata = function (resourceType, resourceId, body, requestOptions) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_a) {
req = this.createRequest('PUT');
mapped = req.prepareArgs({
resourceType: [resourceType, resourceType_js_1.resourceTypeSchema],
resourceId: [resourceId, (0, schema_js_1.number)()],
body: [body, (0, schema_js_1.optional)(updateMetadataRequest_js_1.updateMetadataRequestSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_7 || (templateObject_7 = tslib_1.__makeTemplateObject(["/", "/", "/metadata.json"], ["/", "/", "/metadata.json"])), mapped.resourceType, mapped.resourceId);
req.throwOn(422, singleErrorResponseError_js_1.SingleErrorResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson((0, schema_js_1.array)(metadata_js_1.metadataSchema), requestOptions)];
});
});
};
/**
* Deletes one or more metafields (and associated metadata) from the specified subscription or customer.
*
* @param resourceType The resource type to which the metafields belong.
* @param resourceId The Advanced Billing id of the customer or the subscription for which the
* metadata applies
* @param name Name of field to be removed.
* @param names Names of fields to be removed. Use in query: `names[]=field1&names[]=my-
* field&names[]=another-field`.
* @return Response from the API call
*/
CustomFieldsController.prototype.deleteMetadata = function (resourceType, resourceId, name, names, requestOptions) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_a) {
req = this.createRequest('DELETE');
mapped = req.prepareArgs({
resourceType: [resourceType, resourceType_js_1.resourceTypeSchema],
resourceId: [resourceId, (0, schema_js_1.number)()],
name: [name, (0, schema_js_1.optional)((0, schema_js_1.string)())],
names: [names, (0, schema_js_1.optional)((0, schema_js_1.array)((0, schema_js_1.string)()))],
});
req.query('name', mapped.name, core_js_1.unindexedPrefix);
req.query('names', mapped.names, core_js_1.unindexedPrefix);
req.appendTemplatePath(templateObject_8 || (templateObject_8 = tslib_1.__makeTemplateObject(["/", "/", "/metadata.json"], ["/", "/", "/metadata.json"])), mapped.resourceType, mapped.resourceId);
req.throwOn(404, core_1.ApiError, true, "Not Found:'{$response.body}'");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.call(requestOptions)];
});
});
};
/**
* Lists metadata for a specified array of subscriptions or customers.
*
* @param resourceType The resource type to which the metafields belong.
* @param page Result records are organized in pages. By default, the first page of
* results is displayed. The page parameter specifies a page number of
* results to fetch. You can start navigating through the pages to consume
* the results. You do this by passing in a page parameter. Retrieve the
* next page by adding ?page=2 to the query string. If there are no results
* to return, then an empty result set will be returned. Use in query
* `page=1`.
* @param perPage This parameter indicates how many records to fetch in each request.
* Default value is 20. The maximum allowed values is 200; any per_page
* value over 200 will be changed to 200. Use in query `per_page=200`.
* @param dateField The type of filter you would like to apply to your search.
* @param startDate The start date (format YYYY-MM-DD) with which to filter the date_field.
* Returns metadata with a timestamp at or after midnight (12:00:00 AM) in
* your site’s time zone on the date specified.
* @param endDate The end date (format YYYY-MM-DD) with which to filter the date_field.
* Returns metadata with a timestamp up to and including 11:59:59PM in your
* site’s time zone on the date specified.
* @param startDatetime The start date and time (format YYYY-MM-DD HH:MM:SS) with which to
* filter the date_field. Returns metadata with a timestamp at or after
* exact time provided in query. You can specify timezone in query -
* otherwise your site's time zone will be used. If provided, this
* parameter will be used instead of start_date.
* @param endDatetime The end date and time (format YYYY-MM-DD HH:MM:SS) with which to filter
* the date_field. Returns metadata with a timestamp at or before exact
* time provided in query. You can specify timezone in query - otherwise
* your site's time zone will be used. If provided, this parameter will be
* used instead of end_date.
* @param withDeleted Allow to fetch deleted metadata.
* @param resourceIds Allow to fetch metadata for multiple records based on provided ids. Use
* in query: `resource_ids[]=122&resource_ids[]=123&resource_ids[]=124`.
* @param direction Controls the order in which results are returned. Use in query
* `direction=asc`.
* @return Response from the API call
*/
CustomFieldsController.prototype.listMetadataForResourceType = function (_a, requestOptions_1) {
return tslib_1.__awaiter(this, arguments, void 0, function (_b, requestOptions) {
var req, mapped;
var resourceType = _b.resourceType, page = _b.page, perPage = _b.perPage, dateField = _b.dateField, startDate = _b.startDate, endDate = _b.endDate, startDatetime = _b.startDatetime, endDatetime = _b.endDatetime, withDeleted = _b.withDeleted, resourceIds = _b.resourceIds, direction = _b.direction;
return tslib_1.__generator(this, function (_c) {
req = this.createRequest('GET');
mapped = req.prepareArgs({
resourceType: [resourceType, resourceType_js_1.resourceTypeSchema],
page: [page, (0, schema_js_1.optional)((0, schema_js_1.number)())],
perPage: [perPage, (0, schema_js_1.optional)((0, schema_js_1.number)())],
dateField: [dateField, (0, schema_js_1.optional)(basicDateField_js_1.basicDateFieldSchema)],
startDate: [startDate, (0, schema_js_1.optional)((0, schema_js_1.string)())],
endDate: [endDate, (0, schema_js_1.optional)((0, schema_js_1.string)())],
startDatetime: [startDatetime, (0, schema_js_1.optional)((0, schema_js_1.string)())],
endDatetime: [endDatetime, (0, schema_js_1.optional)((0, schema_js_1.string)())],
withDeleted: [withDeleted, (0, schema_js_1.optional)((0, schema_js_1.boolean)())],
resourceIds: [resourceIds, (0, schema_js_1.optional)((0, schema_js_1.array)((0, schema_js_1.number)()))],
direction: [direction, (0, schema_js_1.optional)(sortingDirection_js_1.sortingDirectionSchema)],
});
req.query('page', mapped.page, core_js_1.unindexedPrefix);
req.query('per_page', mapped.perPage, core_js_1.unindexedPrefix);
req.query('date_field', mapped.dateField, core_js_1.unindexedPrefix);
req.query('start_date', mapped.startDate, core_js_1.unindexedPrefix);
req.query('end_date', mapped.endDate, core_js_1.unindexedPrefix);
req.query('start_datetime', mapped.startDatetime, core_js_1.unindexedPrefix);
req.query('end_datetime', mapped.endDatetime, core_js_1.unindexedPrefix);
req.query('with_deleted', mapped.withDeleted, core_js_1.unindexedPrefix);
req.query('resource_ids', mapped.resourceIds, core_js_1.unindexedPrefix);
req.query('direction', mapped.direction, core_js_1.unindexedPrefix);
req.appendTemplatePath(templateObject_9 || (templateObject_9 = tslib_1.__makeTemplateObject(["/", "/metadata.json"], ["/", "/metadata.json"])), mapped.resourceType);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(paginatedMetadata_js_1.paginatedMetadataSchema, requestOptions)];
});
});
};
return CustomFieldsController;
}(baseController_js_1.BaseController));
exports.CustomFieldsController = CustomFieldsController;
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9;
//# sourceMappingURL=customFieldsController.js.map