@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.
465 lines • 29.7 kB
JavaScript
"use strict";
/**
* AdvancedBilling
*
* This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
exports.__esModule = true;
exports.CustomFieldsController = void 0;
var tslib_1 = require("tslib");
var core_1 = require("../core");
var basicDateField_1 = require("../models/basicDateField");
var createMetadataRequest_1 = require("../models/createMetadataRequest");
var createMetafieldsRequest_1 = require("../models/createMetafieldsRequest");
var listMetafieldsResponse_1 = require("../models/listMetafieldsResponse");
var metadata_1 = require("../models/metadata");
var metafield_1 = require("../models/metafield");
var paginatedMetadata_1 = require("../models/paginatedMetadata");
var resourceType_1 = require("../models/resourceType");
var sortingDirection_1 = require("../models/sortingDirection");
var updateMetadataRequest_1 = require("../models/updateMetadataRequest");
var updateMetafieldsRequest_1 = require("../models/updateMetafieldsRequest");
var schema_1 = require("../schema");
var baseController_1 = require("./baseController");
var core_2 = require("@apimatic/core");
var singleErrorResponseError_1 = require("../errors/singleErrorResponseError");
var CustomFieldsController = /** @class */ (function (_super) {
tslib_1.__extends(CustomFieldsController, _super);
function CustomFieldsController() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* ## Custom Fields: Metafield Intro
*
* **Advanced Billing refers to Custom Fields in the API documentation as metafields and metadata.**
* Within the Advanced Billing UI, metadata and metafields are grouped together under the umbrella of
* "Custom Fields." All of our UI-based documentation that references custom fields will not cite the
* terminology metafields or metadata.
*
* + **Metafield is the custom field**
* + **Metadata is the data populating the custom field.**
*
* Advanced Billing Metafields are used to add meaningful attributes to subscription and customer
* resources. Full documentation on how to create Custom Fields in the Advanced Billing UI can be
* located [here](https://maxio.zendesk.com/hc/en-us/sections/24266118312589-Custom-Fields). For
* additional documentation on how to record data within custom fields, please see our subscription-
* based documentation [here](https://maxio.zendesk.com/hc/en-us/articles/24251701302925-Subscription-
* Summary-Custom-Fields-Tab).
*
* Metafield are the place where you will set up your resource to accept additional data. It is scoped
* to the site instead of a specific customer or subscription. Think of it as the key, and Metadata as
* the value on every record.
*
* ## Create Metafields
*
* Use this endpoint to create metafields for your Site. Metafields can be populated with metadata
* after the fact.
*
* Each site is limited to 100 unique Metafields (i.e. keys, or names) per resource. This means you can
* have 100 Metafields for Subscription and another 100 for Customer.
*
* ### Metafields "On-the-Fly"
*
* It is possible to create Metafields “on the fly” when you create your Metadata – if a non-existent
* name is passed when creating Metadata, a Metafield for that key will be automatically created. The
* Metafield API, however, gives you more control over your “keys”.
*
* ### Metafield Scope Warning
*
* If configuring metafields in the Admin UI or via the API, be careful sending updates to metafields
* with the scope attribute – **if a partial update is sent it will overwrite the current
* configuration**.
*
* @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_1.resourceTypeSchema],
body: [body, (0, schema_1.optional)(createMetafieldsRequest_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_1.SingleErrorResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson((0, schema_1.array)(metafield_1.metafieldSchema), requestOptions)];
});
});
};
/**
* This endpoint lists metafields associated with a site. The metafield description and usage is
* contained in the response.
*
* @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) {
var resourceType = _a.resourceType, name = _a.name, page = _a.page, perPage = _a.perPage, direction = _a.direction;
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_b) {
req = this.createRequest('GET');
mapped = req.prepareArgs({
resourceType: [resourceType, resourceType_1.resourceTypeSchema],
name: [name, (0, schema_1.optional)((0, schema_1.string)())],
page: [page, (0, schema_1.optional)((0, schema_1.number)())],
perPage: [perPage, (0, schema_1.optional)((0, schema_1.number)())],
direction: [direction, (0, schema_1.optional)(sortingDirection_1.sortingDirectionSchema)]
});
req.query('name', mapped.name, core_1.commaPrefix);
req.query('page', mapped.page, core_1.commaPrefix);
req.query('per_page', mapped.perPage, core_1.commaPrefix);
req.query('direction', mapped.direction, core_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_1.listMetafieldsResponseSchema, requestOptions)];
});
});
};
/**
* Use the following method to update metafields for your Site. Metafields can be populated with
* metadata after the fact.
*
* @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_1.resourceTypeSchema],
body: [body, (0, schema_1.optional)(updateMetafieldsRequest_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_1.SingleErrorResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson((0, schema_1.array)(metafield_1.metafieldSchema), requestOptions)];
});
});
};
/**
* Use the following method to delete a metafield. This will remove the metafield from the Site.
*
* Additionally, this will remove the metafield and associated metadata with all Subscriptions 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_1.resourceTypeSchema],
name: [name, (0, schema_1.optional)((0, schema_1.string)())]
});
req.query('name', mapped.name, core_1.commaPrefix);
req.appendTemplatePath(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["/", "/metafields.json"], ["/", "/metafields.json"])), mapped.resourceType);
req.throwOn(404, core_2.ApiError, true, "Not Found:'{$response.body}'");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.call(requestOptions)];
});
});
};
/**
* ## Custom Fields: Metadata Intro
*
* **Advanced Billing refers to Custom Fields in the API documentation as metafields and metadata.**
* Within the Advanced Billing UI, metadata and metafields are grouped together under the umbrella of
* "Custom Fields." All of our UI-based documentation that references custom fields will not cite the
* terminology metafields or metadata.
*
* + **Metafield is the custom field**
* + **Metadata is the data populating the custom field.**
*
* Advanced Billing Metafields are used to add meaningful attributes to subscription and customer
* resources. Full documentation on how to create Custom Fields in the Advanced Billing UI can be
* located [here](https://maxio.zendesk.com/hc/en-us/articles/24266164865677-Custom-Fields-Overview).
* For additional documentation on how to record data within custom fields, please see our subscription-
* based documentation [here.](https://maxio.zendesk.com/hc/en-us/articles/24251701302925-Subscription-
* Summary-Custom-Fields-Tab)
*
* Metadata is associated to a customer or subscription, and corresponds to a Metafield. When creating
* a new metadata object for a given record, **if the metafield is not present it will be created**.
*
* ## Metadata limits
*
* Metadata values are limited to 2kB in size. Additonally, there are limits on the number of unique
* metafields available per resource.
*
* ## Create Metadata
*
* This method will create a metafield for the site on the fly if it does not already exist, and
* populate the metadata value.
*
* ### Subscription or Customer Resource
*
* Please pay special attention to the resource you use when creating metadata.
*
* @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_1.resourceTypeSchema],
resourceId: [resourceId, (0, schema_1.number)()],
body: [body, (0, schema_1.optional)(createMetadataRequest_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_1.SingleErrorResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson((0, schema_1.array)(metadata_1.metadataSchema), requestOptions)];
});
});
};
/**
* This request will list all of the metadata belonging to a particular resource (ie. subscription,
* customer) that is specified.
*
* ## Metadata Data
*
* This endpoint will also display the current stats of your metadata to use as a tool for pagination.
*
* @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) {
var resourceType = _a.resourceType, resourceId = _a.resourceId, page = _a.page, perPage = _a.perPage;
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_b) {
req = this.createRequest('GET');
mapped = req.prepareArgs({
resourceType: [resourceType, resourceType_1.resourceTypeSchema],
resourceId: [resourceId, (0, schema_1.number)()],
page: [page, (0, schema_1.optional)((0, schema_1.number)())],
perPage: [perPage, (0, schema_1.optional)((0, schema_1.number)())]
});
req.query('page', mapped.page, core_1.commaPrefix);
req.query('per_page', mapped.perPage, core_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_1.paginatedMetadataSchema, requestOptions)];
});
});
};
/**
* This method allows you to update the existing metadata associated with a 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 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_1.resourceTypeSchema],
resourceId: [resourceId, (0, schema_1.number)()],
body: [body, (0, schema_1.optional)(updateMetadataRequest_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_1.SingleErrorResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson((0, schema_1.array)(metadata_1.metadataSchema), requestOptions)];
});
});
};
/**
* This method removes the metadata from the subscriber/customer cited.
*
* ## Query String Usage
*
* For instance if you wanted to delete the metadata for customer 99 named weight you would request:
*
* ```
* https://acme.chargify.com/customers/99/metadata.json?name=weight
* ```
*
* If you want to delete multiple metadata fields for a customer 99 named: `weight` and `age` you
* wrould request:
* ```
* https://acme.chargify.com/customers/99/metadata.json?names[]=weight&names[]=age
* ```
*
* ## Successful Response
*
* For a success, there will be a code `200` and the plain text response `true`.
*
* ## Unsuccessful Response
*
* When a failed response is encountered, you will receive a `404` response and the plain text response
* of `true`.
*
* @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_1.resourceTypeSchema],
resourceId: [resourceId, (0, schema_1.number)()],
name: [name, (0, schema_1.optional)((0, schema_1.string)())],
names: [names, (0, schema_1.optional)((0, schema_1.array)((0, schema_1.string)()))]
});
req.query('name', mapped.name, core_1.unindexedPrefix);
req.query('names', mapped.names, core_1.unindexedPrefix);
req.appendTemplatePath(templateObject_8 || (templateObject_8 = tslib_1.__makeTemplateObject(["/", "/", "/metadata.json"], ["/", "/", "/metadata.json"])), mapped.resourceType, mapped.resourceId);
req.throwOn(404, core_2.ApiError, true, "Not Found:'{$response.body}'");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.call(requestOptions)];
});
});
};
/**
* This method will provide you information on usage of metadata across your selected resource (ie.
* subscriptions, customers)
*
* ## Metadata Data
*
* This endpoint will also display the current stats of your metadata to use as a tool for pagination.
*
* ### Metadata for multiple records
*
* `https://acme.chargify.com/subscriptions/metadata.json?resource_ids[]=1&resource_ids[]=2`
*
* ## Read Metadata for a Site
*
* This endpoint will list the number of pages of metadata information that are contained within a site.
*
* @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) {
var resourceType = _a.resourceType, page = _a.page, perPage = _a.perPage, dateField = _a.dateField, startDate = _a.startDate, endDate = _a.endDate, startDatetime = _a.startDatetime, endDatetime = _a.endDatetime, withDeleted = _a.withDeleted, resourceIds = _a.resourceIds, direction = _a.direction;
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_b) {
req = this.createRequest('GET');
mapped = req.prepareArgs({
resourceType: [resourceType, resourceType_1.resourceTypeSchema],
page: [page, (0, schema_1.optional)((0, schema_1.number)())],
perPage: [perPage, (0, schema_1.optional)((0, schema_1.number)())],
dateField: [dateField, (0, schema_1.optional)(basicDateField_1.basicDateFieldSchema)],
startDate: [startDate, (0, schema_1.optional)((0, schema_1.string)())],
endDate: [endDate, (0, schema_1.optional)((0, schema_1.string)())],
startDatetime: [startDatetime, (0, schema_1.optional)((0, schema_1.string)())],
endDatetime: [endDatetime, (0, schema_1.optional)((0, schema_1.string)())],
withDeleted: [withDeleted, (0, schema_1.optional)((0, schema_1.boolean)())],
resourceIds: [resourceIds, (0, schema_1.optional)((0, schema_1.array)((0, schema_1.number)()))],
direction: [direction, (0, schema_1.optional)(sortingDirection_1.sortingDirectionSchema)]
});
req.query('page', mapped.page, core_1.unindexedPrefix);
req.query('per_page', mapped.perPage, core_1.unindexedPrefix);
req.query('date_field', mapped.dateField, core_1.unindexedPrefix);
req.query('start_date', mapped.startDate, core_1.unindexedPrefix);
req.query('end_date', mapped.endDate, core_1.unindexedPrefix);
req.query('start_datetime', mapped.startDatetime, core_1.unindexedPrefix);
req.query('end_datetime', mapped.endDatetime, core_1.unindexedPrefix);
req.query('with_deleted', mapped.withDeleted, core_1.unindexedPrefix);
req.query('resource_ids', mapped.resourceIds, core_1.unindexedPrefix);
req.query('direction', mapped.direction, core_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_1.paginatedMetadataSchema, requestOptions)];
});
});
};
return CustomFieldsController;
}(baseController_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