@zeplin/sdk
Version:
Zeplin API client for JavaScript
347 lines (341 loc) • 18.5 kB
JavaScript
;
require("core-js/modules/es.symbol.to-primitive.js");
require("core-js/modules/es.date.to-primitive.js");
require("core-js/modules/es.symbol.js");
require("core-js/modules/es.symbol.description.js");
require("core-js/modules/es.number.constructor.js");
require("core-js/modules/es.object.define-property.js");
require("core-js/modules/es.object.keys.js");
require("core-js/modules/es.array.filter.js");
require("core-js/modules/es.object.get-own-property-descriptor.js");
require("core-js/modules/es.array.for-each.js");
require("core-js/modules/web.dom-collections.for-each.js");
require("core-js/modules/es.object.get-own-property-descriptors.js");
require("core-js/modules/es.object.define-properties.js");
require("core-js/modules/es.promise.js");
require("core-js/modules/es.object.set-prototype-of.js");
require("core-js/modules/es.function.bind.js");
require("core-js/modules/es.object.get-prototype-of.js");
require("core-js/modules/es.reflect.construct.js");
require("core-js/modules/es.object.create.js");
require("core-js/modules/es.symbol.iterator.js");
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.AuthorizationApiFp = exports.AuthorizationApiAxiosParamCreator = exports.AuthorizationApi = void 0;
require("regenerator-runtime/runtime.js");
require("core-js/modules/es.array.iterator.js");
require("core-js/modules/es.object.to-string.js");
require("core-js/modules/es.string.iterator.js");
require("core-js/modules/web.dom-collections.iterator.js");
require("core-js/modules/web.url.js");
var _axios = _interopRequireDefault(require("axios"));
var _common = require("../common");
var _base = require("../base");
var _models = require("../models");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = _getPrototypeOf(t); if (r) { var s = _getPrototypeOf(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return _possibleConstructorReturn(this, e); }; }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /* tslint:disable */ /* eslint-disable */ /**
* Zeplin API
* Access your resources in Zeplin
*
* Contact: support@zeplin.io
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/ // Some imports not used depending on template conditions
// @ts-ignore
// @ts-ignore
// @ts-ignore
// @ts-ignore
// @ts-ignore
/**
* AuthorizationApi - axios parameter creator
* @export
*/
var AuthorizationApiAxiosParamCreator = function AuthorizationApiAxiosParamCreator(configuration) {
return {
/**
* Users are redirected to web app to authenticate themselves and authorize the app with `client_id` to act on behalf of themselves.
* @summary Authorization endpoint
* @param {string} responseType Only `code` flow is supported
* @param {string} clientId Identifier of the Zeplin app requesting user authentication
* @param {string} redirectUri User is redirected to this endpoint after authorization
* @param {string} [state] RECOMMENDED. An opaque value used by the client to maintain state between the request and callback.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
oAuthAuthorize: function oAuthAuthorize(responseType, clientId, redirectUri, state, codeChallenge, codeChallengeMethod) {
var options = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {};
// verify required parameter 'responseType' is not null or undefined
(0, _common.assertParamExists)('oAuthAuthorize', 'responseType', responseType);
// verify required parameter 'clientId' is not null or undefined
(0, _common.assertParamExists)('oAuthAuthorize', 'clientId', clientId);
// verify required parameter 'redirectUri' is not null or undefined
(0, _common.assertParamExists)('oAuthAuthorize', 'redirectUri', redirectUri);
var localVarPath = "/v1/oauth/authorize";
// use dummy base URL string because the URL constructor only accepts absolute URLs.
var localVarUrlObj = new URL(localVarPath, _common.DUMMY_BASE_URL);
var baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
var localVarRequestOptions = _objectSpread(_objectSpread({
method: 'GET'
}, baseOptions), options);
var localVarHeaderParameter = {};
var localVarQueryParameter = {};
if (responseType !== undefined) {
localVarQueryParameter['response_type'] = responseType;
}
if (clientId !== undefined) {
localVarQueryParameter['client_id'] = clientId;
}
if (redirectUri !== undefined) {
localVarQueryParameter['redirect_uri'] = redirectUri;
}
if (state !== undefined) {
localVarQueryParameter['state'] = state;
}
if (codeChallenge !== undefined) {
localVarQueryParameter['code_challenge'] = codeChallenge;
localVarQueryParameter['code_challenge_method'] = 'S256';
}
if (codeChallengeMethod !== undefined) {
localVarQueryParameter['code_challenge_method'] = codeChallengeMethod;
}
(0, _common.setSearchParams)(localVarUrlObj, localVarQueryParameter, options.query);
var headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = _objectSpread(_objectSpread(_objectSpread({}, localVarHeaderParameter), headersFromBaseOptions), options.headers);
return {
url: (0, _common.toPathString)(localVarUrlObj),
options: localVarRequestOptions
};
},
/**
* If `grant_type` is given as `authorization_code`; handles code flow. If `grant_type` is given as `refresh_token` handles refresh token flow.
* @summary Access token endpoint
* @param {TokenCreateBody} tokenCreateBody
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
oAuthPostToken: function oAuthPostToken(tokenCreateBody) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
// verify required parameter 'tokenCreateBody' is not null or undefined
(0, _common.assertParamExists)('oAuthPostToken', 'tokenCreateBody', tokenCreateBody);
var localVarPath = "/v1/oauth/token";
// use dummy base URL string because the URL constructor only accepts absolute URLs.
var localVarUrlObj = new URL(localVarPath, _common.DUMMY_BASE_URL);
var baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
var localVarRequestOptions = _objectSpread(_objectSpread({
method: 'POST'
}, baseOptions), options);
var localVarHeaderParameter = {};
var localVarQueryParameter = {};
localVarHeaderParameter['Content-Type'] = 'application/json';
(0, _common.setSearchParams)(localVarUrlObj, localVarQueryParameter, options.query);
var headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = _objectSpread(_objectSpread(_objectSpread({}, localVarHeaderParameter), headersFromBaseOptions), options.headers);
localVarRequestOptions.data = (0, _common.serializeDataIfNeeded)((0, _models.transformTokenCreateBodyToJSON)(tokenCreateBody), localVarRequestOptions, configuration);
return {
url: (0, _common.toPathString)(localVarUrlObj),
options: localVarRequestOptions
};
}
};
};
/**
* AuthorizationApi - functional programming interface
* @export
*/
exports.AuthorizationApiAxiosParamCreator = AuthorizationApiAxiosParamCreator;
var AuthorizationApiFp = function AuthorizationApiFp(configuration) {
var localVarAxiosParamCreator = AuthorizationApiAxiosParamCreator(configuration);
return {
/**
* If `grant_type` is given as `authorization_code`; handles code flow. If `grant_type` is given as `refresh_token` handles refresh token flow.
* @summary Access token endpoint
* @param {TokenCreateBody} tokenCreateBody
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
oAuthPostToken: function oAuthPostToken(tokenCreateBody, options) {
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
var localVarAxiosArgs;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return localVarAxiosParamCreator.oAuthPostToken(tokenCreateBody, options);
case 2:
localVarAxiosArgs = _context.sent;
return _context.abrupt("return", (0, _common.createRequestFunction)(localVarAxiosArgs, _axios["default"], _base.BASE_PATH, configuration));
case 4:
case "end":
return _context.stop();
}
}
}, _callee);
}))();
}
};
};
/**
* Search parameters for getAuthorizeUrl operation in AuthorizationApi.
* @export
* @interface AuthorizationApiGetAuthorizationUrlSearchParams
*/
/**
* Search parameters for createToken operation in AuthorizationApi.
* @export
* @interface AuthorizationApiCreateTokenParams
*/
/**
* Search parameters for refreshToken operation in AuthorizationApi.
* @export
* @interface AuthorizationApiRefreshTokenParams
*/
exports.AuthorizationApiFp = AuthorizationApiFp;
/**
* AuthorizationApi - object-oriented interface
* @export
* @class AuthorizationApi
* @extends {BaseAPI}
*/
var AuthorizationApi = /*#__PURE__*/function (_BaseAPI) {
_inherits(AuthorizationApi, _BaseAPI);
var _super = _createSuper(AuthorizationApi);
function AuthorizationApi() {
_classCallCheck(this, AuthorizationApi);
return _super.apply(this, arguments);
}
_createClass(AuthorizationApi, [{
key: "getAuthorizationUrl",
value:
/**
* Users are redirected to web app to authenticate themselves and authorize the app with `client_id` to act on behalf of themselves.
* @summary Authorization endpoint
* @param {AuthorizationApiGetAuthorizationUrlSearchParams} searchParams Search parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof AuthorizationApi
*/
function getAuthorizationUrl(searchParams, options) {
var paramCreator = AuthorizationApiAxiosParamCreator(this.configuration);
var params = paramCreator.oAuthAuthorize("code", searchParams.clientId, searchParams.redirectUri, searchParams.state, searchParams.codeChallenge, searchParams.codeChallengeMethod, options);
return this.axios.getUri(_objectSpread(_objectSpread({}, params.options), {}, {
url: this.basePath + params.url
}));
}
/**
* Handles code flow
* @summary Access token endpoint
* @param {AuthorizationApiCreateTokenParams} params
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof AuthorizationApi
*/
}, {
key: "createToken",
value: (function () {
var _createToken = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(params, options) {
var authorizationApiFp, request, response;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
authorizationApiFp = AuthorizationApiFp(this.configuration);
_context2.next = 3;
return authorizationApiFp.oAuthPostToken(_objectSpread(_objectSpread({}, params), {}, {
grantType: "authorization_code"
}), options);
case 3:
request = _context2.sent;
_context2.next = 6;
return request(this.axios, this.basePath);
case 6:
response = _context2.sent;
return _context2.abrupt("return", _objectSpread(_objectSpread({}, response), {}, {
data: (0, _models.transformJSONToTokenResponse)(response.data)
}));
case 8:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
function createToken(_x, _x2) {
return _createToken.apply(this, arguments);
}
return createToken;
}()
/**
* Handles refresh token flow
* @summary Access token endpoint
* @param {AuthorizationApiCreateTokenParams} params
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof AuthorizationApi
*/
)
}, {
key: "refreshToken",
value: (function () {
var _refreshToken = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(params, options) {
var authorizationApiFp, request, response;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
authorizationApiFp = AuthorizationApiFp(this.configuration);
_context3.next = 3;
return authorizationApiFp.oAuthPostToken(_objectSpread(_objectSpread({}, params), {}, {
grantType: "refresh_token"
}), options);
case 3:
request = _context3.sent;
_context3.next = 6;
return request(this.axios, this.basePath);
case 6:
response = _context3.sent;
return _context3.abrupt("return", _objectSpread(_objectSpread({}, response), {}, {
data: (0, _models.transformJSONToTokenResponse)(response.data)
}));
case 8:
case "end":
return _context3.stop();
}
}
}, _callee3, this);
}));
function refreshToken(_x3, _x4) {
return _refreshToken.apply(this, arguments);
}
return refreshToken;
}())
}]);
return AuthorizationApi;
}(_base.BaseAPI);
exports.AuthorizationApi = AuthorizationApi;