forked from NuroDev/lemonsqueezy.ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.action.ts
56 lines (51 loc) · 1.29 KB
/
file.action.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { requestLemonSqueeze } from "~/shared";
import type {
ListAllFilesOptions,
ListAllFilesResult,
RetrieveFileOptions,
RetrieveFileResult,
} from "./file.types";
import type { SharedModuleOptions } from "~/shared";
/**
* List all files
*
* @description Returns a paginated list of files
*
* @docs https://docs.lemonsqueezy.com/api/files#list-all-files
*
* @param {Object} [options]
*
* @returns Returns a paginated list of file objects ordered by `sort`
*/
export async function listAllFiles(
options: ListAllFilesOptions & SharedModuleOptions
): Promise<ListAllFilesResult> {
const { variantId, ...rest } = options;
return requestLemonSqueeze<ListAllFilesResult>({
params: {
...(variantId ? { variant_id: variantId } : {}),
},
path: "/files",
...rest,
});
}
/**
* Retrieve file
*
* @description Retrieves the file with the given ID
*
* @docs https://docs.lemonsqueezy.com/api/files#retrieve-a-file
*
* @param {String} options.id - The ID of the file to retrieve
*
* @returns A file object
*/
export async function retrieveFile(
options: RetrieveFileOptions & SharedModuleOptions
): Promise<RetrieveFileResult> {
const { id, ...rest } = options;
return requestLemonSqueeze<RetrieveFileResult>({
path: `/files/${id}`,
...rest,
});
}