Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rr-apilib

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rr-apilib - npm Package Compare versions

Comparing version 0.3.5-alpha to 0.4.0-alpha

8

lib/builders/AttachmentBuilder.d.ts
import Ressource from "../class/Resource";
export interface AttachmentDataBuilder {
file: string;
file?: File;
resource?: Ressource;

@@ -8,12 +8,12 @@ }

export default class AttachmentBuilder implements AttachmentDataBuilder {
file: string;
file?: File;
resource?: Ressource;
constructor(data?: Partial<AttachmentDataBuilder>);
setData(data: string): this;
setFile(file: File): this;
setRessource(ressource: Ressource): this;
/** Return data for api request */
toJSON(): {
file: string;
file: File | undefined;
resource: string | undefined;
};
}
/** Represents a attachment in a ressource */
var AttachmentBuilder = /** @class */ (function () {
function AttachmentBuilder(data) {
var _a;
this.file = (_a = data === null || data === void 0 ? void 0 : data.file) !== null && _a !== void 0 ? _a : "";
this.file = data === null || data === void 0 ? void 0 : data.file;
this.resource = data === null || data === void 0 ? void 0 : data.resource;
}
AttachmentBuilder.prototype.setData = function (data) {
this.file = data;
AttachmentBuilder.prototype.setFile = function (file) {
this.file = file;
return this;

@@ -11,0 +10,0 @@ };

@@ -31,3 +31,3 @@ import Category from "../class/Category";

attachments: {
file: string;
file: File | undefined;
resource: string | undefined;

@@ -34,0 +34,0 @@ }[];

@@ -15,3 +15,3 @@ import { __extends } from "tslib";

_this.createdAt = new Date(data.createdAt);
_this.updatedAt = data.updatedAt ? new Date(data.updatedAt) : new Date();
_this.updatedAt = data.updatedAt ? new Date(data.updatedAt) : null;
_this.resources = new UserResourceManager(_this);

@@ -18,0 +18,0 @@ return _this;

import { CreateAxiosDefaults } from 'axios';
import { APIResourceAttachmentData } from '../@types';
import AttachmentBuilder from '../builders/AttachmentBuilder';
import Client from './Client';

@@ -28,2 +30,3 @@ export declare enum RequestMethod {

private sendRequest;
postAttachmentResource(attachmentBuilder: AttachmentBuilder): Promise<APIResourceAttachmentData>;
/** Send a get request to the API */

@@ -30,0 +33,0 @@ getRequest(url: string, needAuth?: boolean): Promise<any>;

@@ -55,2 +55,33 @@ import { __assign, __awaiter, __generator } from "tslib";

};
REST.prototype.postAttachmentResource = function (attachmentBuilder) {
return __awaiter(this, void 0, void 0, function () {
var formData, response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.client.auth.checkAuth();
if (!attachmentBuilder.file || !attachmentBuilder.resource) {
throw new Error("Error: Thanks to provide a valid file and resource");
}
formData = new FormData();
formData.set('file', attachmentBuilder.file);
formData.set('resource', attachmentBuilder.resource.id);
return [4 /*yield*/, this.instance({
url: "/attachments/resource",
method: RequestMethod.Post,
headers: {
"Content-Type": "multipart/form-data",
},
data: formData
})];
case 1:
response = _a.sent();
if (response.status === 201) {
return [2 /*return*/, response.data];
}
throw new Error("Error ".concat(response.status, ", ").concat(response.statusText));
}
});
});
};
/** Send a get request to the API */

@@ -57,0 +88,0 @@ REST.prototype.getRequest = function (url, needAuth) {

@@ -20,8 +20,6 @@ import { __awaiter, __extends, __generator } from "tslib";

return __awaiter(this, void 0, void 0, function () {
var json, attachData, attachment;
var attachData, attachment;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
json = data.setRessource(this.resource).toJSON();
return [4 /*yield*/, this.client.rest.postRequest("/attachments/resource", json)];
case 0: return [4 /*yield*/, this.client.rest.postAttachmentResource(data)];
case 1:

@@ -28,0 +26,0 @@ attachData = _a.sent();

{
"name": "rr-apilib",
"version": "0.3.5-alpha",
"version": "0.4.0-alpha",
"description": "Library for interact with RR-API",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc