Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@internxt/sdk",
"author": "Internxt <hello@internxt.com>",
"version": "1.12.4",
"version": "1.12.5",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions src/send/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './send';
49 changes: 49 additions & 0 deletions src/send/send.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { ApiUrl, AppDetails } from '../shared';
import { basicHeaders } from '../shared/headers';
import { HttpClient } from '../shared/http/client';
import { CreateSendLinksPayload, CreateSendLinksResponse, GetSendLinkResponse } from './types';

export class Send {
private readonly client: HttpClient;
private readonly appDetails: AppDetails;

public static client(apiUrl: ApiUrl, appDetails: AppDetails) {
return new Send(apiUrl, appDetails);
}

private constructor(apiUrl: ApiUrl, appDetails: AppDetails) {
this.client = HttpClient.create(apiUrl);
this.appDetails = appDetails;
}

/**
* Gets a send link by its id
* @param linkId id of the send link
* @returns a promise with the send link data
*/
public getSendLink(linkId: string): Promise<GetSendLinkResponse> {
return this.client.get('/links/' + linkId, this.headers());
}

/**
* Creates a new send link
* @param payload contains the data to create a new send link
* @returns a promise with the newly created send link data
*/
public createSendLink(payload: CreateSendLinksPayload): Promise<CreateSendLinksResponse> {
// Spread payload into a plain object literal so it matches the `Parameters`/Record<string, unknown> expected by HttpClient.post
return this.client.post('/links/', { ...payload }, this.headers());
}

/**
* Returns the basic needed headers for the module requests
* @private
*/
private headers() {
return basicHeaders({
clientName: this.appDetails.clientName,
clientVersion: this.appDetails.clientVersion,
customHeaders: this.appDetails.customHeaders,
});
}
}
64 changes: 64 additions & 0 deletions src/send/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
export interface SendItemBasic {
id: string;
name: string;
size: number;
type: 'file' | 'folder';
parent_folder: string | null;
}

export interface SendItem extends SendItemBasic {
linkId: string;
networkId: string;
encryptionKey: string;
createdAt: Date;
updatedAt: Date;
version: number;
path?: string;
countFiles?: number;
childrenFiles?: SendItem[];
childrenFolders?: SendItem[];
}

export interface GetSendLinkResponse {
id: string;
title: string;
subject: string;
code: string;
views: number;
userId: number | null;
items: SendItem[];
createdAt: string;
updatedAt: string;
expirationAt: string;
size: number;
}

export interface SendLink extends SendItemBasic {
networkId: string;
encryptionKey: string;
}

export interface CreateSendLinksPayload {
sender?: string;
receivers?: string[];
code: string;
title?: string;
subject?: string;
items: SendLink[];
mnemonic: string;
}

export interface CreateSendLinksResponse {
id: string;
title: string;
subject: string;
code: string;
sender: string;
receivers: string[];
views: number;
userId: number;
items: SendLink[];
createdAt: string;
updatedAt: string;
expirationAt: string;
}
Loading