From be0c694280569f9a8eb8f0ec95594371cb89c000 Mon Sep 17 00:00:00 2001
From: "stainless-app[bot]"
<142633134+stainless-app[bot]@users.noreply.github.com>
Date: Tue, 25 Feb 2025 19:04:31 +0000
Subject: [PATCH] feat(api): api update
---
.stats.yml | 2 +-
api.md | 14 ++
src/resources/alias/username/index.ts | 1 +
src/resources/alias/username/project-name.ts | 72 +++++++
src/resources/alias/username/username.ts | 6 +
src/resources/projects/files.ts | 180 ++++++++++++++++++
src/resources/projects/index.ts | 11 +-
src/resources/projects/projects.ts | 15 +-
.../alias/username/project-name.test.ts | 31 +++
tests/api-resources/projects/files.test.ts | 63 ++++++
10 files changed, 392 insertions(+), 3 deletions(-)
create mode 100644 src/resources/alias/username/project-name.ts
create mode 100644 tests/api-resources/alias/username/project-name.test.ts
diff --git a/.stats.yml b/.stats.yml
index d7219c6f6..1a9bdc2bc 100644
--- a/.stats.yml
+++ b/.stats.yml
@@ -1,2 +1,2 @@
-configured_endpoints: 32
+configured_endpoints: 35
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/val-town%2Fval-town-96c5c8e7372c1cfedb047e16fe48ce6cbf1a5c1ce242931b9347306942cc765c.yml
diff --git a/api.md b/api.md
index e449c641a..c387e23c3 100644
--- a/api.md
+++ b/api.md
@@ -34,6 +34,16 @@ Methods:
- client.alias.username.valName.retrieve(username, valName) -> ValNameRetrieveResponse
+### ProjectName
+
+Types:
+
+- ProjectNameRetrieveResponse
+
+Methods:
+
+- client.alias.username.projectName.retrieve(username, projectName) -> ProjectNameRetrieveResponse
+
# Me
## Profile
@@ -184,8 +194,12 @@ Methods:
Types:
+- FileRetrieveResponse
- FileListResponse
+- FileContentResponse
Methods:
+- client.projects.files.retrieve(projectId, path, { ...params }) -> FileRetrieveResponse
- client.projects.files.list(projectId, { ...params }) -> FileListResponsesPageCursorURL
+- client.projects.files.content(projectId, path, { ...params }) -> unknown
diff --git a/src/resources/alias/username/index.ts b/src/resources/alias/username/index.ts
index ad1e5a13c..aa282b627 100644
--- a/src/resources/alias/username/index.ts
+++ b/src/resources/alias/username/index.ts
@@ -1,4 +1,5 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+export { ProjectName, type ProjectNameRetrieveResponse } from './project-name';
export { Username } from './username';
export { ValName, type ValNameRetrieveResponse } from './val-name';
diff --git a/src/resources/alias/username/project-name.ts b/src/resources/alias/username/project-name.ts
new file mode 100644
index 000000000..5ef271ef3
--- /dev/null
+++ b/src/resources/alias/username/project-name.ts
@@ -0,0 +1,72 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+import { APIResource } from '../../../resource';
+import * as Core from '../../../core';
+
+export class ProjectName extends APIResource {
+ /**
+ * Get a project
+ */
+ retrieve(
+ username: string,
+ projectName: string,
+ options?: Core.RequestOptions,
+ ): Core.APIPromise {
+ return this._client.get(`/v1/alias/projects/${username}/${projectName}`, options);
+ }
+}
+
+/**
+ * A Project
+ */
+export interface ProjectNameRetrieveResponse {
+ /**
+ * The id of the project
+ */
+ id: string;
+
+ author: ProjectNameRetrieveResponse.Author;
+
+ createdAt: string;
+
+ description: string | null;
+
+ /**
+ * The URL of this project's image
+ */
+ imageUrl: string | null;
+
+ links: ProjectNameRetrieveResponse.Links;
+
+ name: string;
+
+ /**
+ * This resource's privacy setting. Unlisted resources do not appear on profile
+ * pages or elsewhere, but you can link to them.
+ */
+ privacy: 'public' | 'unlisted' | 'private';
+}
+
+export namespace ProjectNameRetrieveResponse {
+ export interface Author {
+ id: string;
+
+ username: string | null;
+ }
+
+ export interface Links {
+ /**
+ * The URL of this resource on Val Town
+ */
+ html: string;
+
+ /**
+ * The URL of this resource on this API
+ */
+ self: string;
+ }
+}
+
+export declare namespace ProjectName {
+ export { type ProjectNameRetrieveResponse as ProjectNameRetrieveResponse };
+}
diff --git a/src/resources/alias/username/username.ts b/src/resources/alias/username/username.ts
index be341c370..bc3b858da 100644
--- a/src/resources/alias/username/username.ts
+++ b/src/resources/alias/username/username.ts
@@ -3,11 +3,14 @@
import { APIResource } from '../../../resource';
import * as Core from '../../../core';
import * as Shared from '../../shared';
+import * as ProjectNameAPI from './project-name';
+import { ProjectName, ProjectNameRetrieveResponse } from './project-name';
import * as ValNameAPI from './val-name';
import { ValName, ValNameRetrieveResponse } from './val-name';
export class Username extends APIResource {
valName: ValNameAPI.ValName = new ValNameAPI.ValName(this._client);
+ projectName: ProjectNameAPI.ProjectName = new ProjectNameAPI.ProjectName(this._client);
/**
* Get basic details about a user, given their username
@@ -18,7 +21,10 @@ export class Username extends APIResource {
}
Username.ValName = ValName;
+Username.ProjectName = ProjectName;
export declare namespace Username {
export { ValName as ValName, type ValNameRetrieveResponse as ValNameRetrieveResponse };
+
+ export { ProjectName as ProjectName, type ProjectNameRetrieveResponse as ProjectNameRetrieveResponse };
}
diff --git a/src/resources/projects/files.ts b/src/resources/projects/files.ts
index 0e2f8430c..b940ab233 100644
--- a/src/resources/projects/files.ts
+++ b/src/resources/projects/files.ts
@@ -1,10 +1,24 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../resource';
+import { isRequestOptions } from '../../core';
import * as Core from '../../core';
+import * as Shared from '../shared';
import { PageCursorURL, type PageCursorURLParams } from '../../pagination';
export class Files extends APIResource {
+ /**
+ * Get metadata for files and directories in a project at the specified path
+ */
+ retrieve(
+ projectId: string,
+ path: string,
+ query: FileRetrieveParams,
+ options?: Core.RequestOptions,
+ ): Core.APIPromise {
+ return this._client.get(`/v1/projects/${projectId}/files/${path}`, { query, ...options });
+ }
+
/**
* Get metadata for files and directories in a project at the root directory
*/
@@ -18,10 +32,111 @@ export class Files extends APIResource {
...options,
});
}
+
+ /**
+ * Download file content
+ */
+ content(
+ projectId: string,
+ path: string,
+ params?: FileContentParams,
+ options?: Core.RequestOptions,
+ ): Core.APIPromise;
+ content(projectId: string, path: string, options?: Core.RequestOptions): Core.APIPromise;
+ content(
+ projectId: string,
+ path: string,
+ params: FileContentParams | Core.RequestOptions = {},
+ options?: Core.RequestOptions,
+ ): Core.APIPromise {
+ if (isRequestOptions(params)) {
+ return this.content(projectId, path, {}, params);
+ }
+ const {
+ 'Cache-Control': cacheControl,
+ 'If-Match': ifMatch,
+ 'If-Modified-Since': ifModifiedSince,
+ 'If-None-Match': ifNoneMatch,
+ 'If-Unmodified-Since': ifUnmodifiedSince,
+ ...query
+ } = params;
+ return this._client.get(`/v1/projects/${projectId}/files/${path}/content`, {
+ query,
+ ...options,
+ headers: {
+ ...(cacheControl != null ? { 'Cache-Control': cacheControl } : undefined),
+ ...(ifMatch != null ? { 'If-Match': ifMatch } : undefined),
+ ...(ifModifiedSince != null ? { 'If-Modified-Since': ifModifiedSince } : undefined),
+ ...(ifNoneMatch != null ? { 'If-None-Match': ifNoneMatch } : undefined),
+ ...(ifUnmodifiedSince != null ? { 'If-Unmodified-Since': ifUnmodifiedSince } : undefined),
+ ...options?.headers,
+ },
+ });
+ }
}
export class FileListResponsesPageCursorURL extends PageCursorURL {}
+/**
+ * A paginated result set
+ */
+export interface FileRetrieveResponse {
+ data: Array;
+
+ /**
+ * Links to use for pagination
+ */
+ links: Shared.PaginationLinks;
+}
+
+export namespace FileRetrieveResponse {
+ /**
+ * A File or Directory's Metadata
+ */
+ export interface Data {
+ /**
+ * The id of the resource
+ */
+ id: string;
+
+ links: Data.Links;
+
+ name: string;
+
+ path: string;
+
+ type: 'directory' | 'file' | 'interval' | 'http' | 'email' | 'script';
+
+ updatedAt: string;
+
+ version: number;
+ }
+
+ export namespace Data {
+ export interface Links {
+ /**
+ * The URL of this resource on Val Town
+ */
+ html: string;
+
+ /**
+ * The URL of this resource's source code as a module
+ */
+ module: string;
+
+ /**
+ * The URL of this resource on this API
+ */
+ self: string;
+
+ /**
+ * This resource's web endpoint, where it serves a website or API
+ */
+ endpoint?: string;
+ }
+ }
+}
+
/**
* A File or Directory's Metadata
*/
@@ -68,6 +183,30 @@ export namespace FileListResponse {
}
}
+export type FileContentResponse = unknown;
+
+export interface FileRetrieveParams {
+ /**
+ * Maximum items to return in each paginated response
+ */
+ limit: number;
+
+ /**
+ * Number of items to skip in order to deliver paginated results
+ */
+ offset: number;
+
+ /**
+ * Id to query
+ */
+ branch_id?: string;
+
+ /**
+ * Specific branch version to query
+ */
+ version?: number;
+}
+
export interface FileListParams extends PageCursorURLParams {
/**
* Id to query
@@ -85,12 +224,53 @@ export interface FileListParams extends PageCursorURLParams {
version?: number;
}
+export interface FileContentParams {
+ /**
+ * Query param: Id to query
+ */
+ branch_id?: string;
+
+ /**
+ * Query param: Specific branch version to query
+ */
+ version?: number;
+
+ /**
+ * Header param:
+ */
+ 'Cache-Control'?: string;
+
+ /**
+ * Header param:
+ */
+ 'If-Match'?: string;
+
+ /**
+ * Header param:
+ */
+ 'If-Modified-Since'?: string;
+
+ /**
+ * Header param:
+ */
+ 'If-None-Match'?: string;
+
+ /**
+ * Header param:
+ */
+ 'If-Unmodified-Since'?: string;
+}
+
Files.FileListResponsesPageCursorURL = FileListResponsesPageCursorURL;
export declare namespace Files {
export {
+ type FileRetrieveResponse as FileRetrieveResponse,
type FileListResponse as FileListResponse,
+ type FileContentResponse as FileContentResponse,
FileListResponsesPageCursorURL as FileListResponsesPageCursorURL,
+ type FileRetrieveParams as FileRetrieveParams,
type FileListParams as FileListParams,
+ type FileContentParams as FileContentParams,
};
}
diff --git a/src/resources/projects/index.ts b/src/resources/projects/index.ts
index 2da8b95e6..564695917 100644
--- a/src/resources/projects/index.ts
+++ b/src/resources/projects/index.ts
@@ -7,7 +7,16 @@ export {
type BranchListResponse,
type BranchListParams,
} from './branches';
-export { FileListResponsesPageCursorURL, Files, type FileListResponse, type FileListParams } from './files';
+export {
+ FileListResponsesPageCursorURL,
+ Files,
+ type FileRetrieveResponse,
+ type FileListResponse,
+ type FileContentResponse,
+ type FileRetrieveParams,
+ type FileListParams,
+ type FileContentParams,
+} from './files';
export {
ProjectListResponsesPageCursorURL,
Projects,
diff --git a/src/resources/projects/projects.ts b/src/resources/projects/projects.ts
index 4d50aaa91..84801c34d 100644
--- a/src/resources/projects/projects.ts
+++ b/src/resources/projects/projects.ts
@@ -11,7 +11,16 @@ import {
Branches,
} from './branches';
import * as FilesAPI from './files';
-import { FileListParams, FileListResponse, FileListResponsesPageCursorURL, Files } from './files';
+import {
+ FileContentParams,
+ FileContentResponse,
+ FileListParams,
+ FileListResponse,
+ FileListResponsesPageCursorURL,
+ FileRetrieveParams,
+ FileRetrieveResponse,
+ Files,
+} from './files';
import { PageCursorURL, type PageCursorURLParams } from '../../pagination';
/**
@@ -169,8 +178,12 @@ export declare namespace Projects {
export {
Files as Files,
+ type FileRetrieveResponse as FileRetrieveResponse,
type FileListResponse as FileListResponse,
+ type FileContentResponse as FileContentResponse,
FileListResponsesPageCursorURL as FileListResponsesPageCursorURL,
+ type FileRetrieveParams as FileRetrieveParams,
type FileListParams as FileListParams,
+ type FileContentParams as FileContentParams,
};
}
diff --git a/tests/api-resources/alias/username/project-name.test.ts b/tests/api-resources/alias/username/project-name.test.ts
new file mode 100644
index 000000000..f33582a76
--- /dev/null
+++ b/tests/api-resources/alias/username/project-name.test.ts
@@ -0,0 +1,31 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+import ValTown from '@valtown/sdk';
+import { Response } from 'node-fetch';
+
+const client = new ValTown({
+ bearerToken: 'My Bearer Token',
+ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
+});
+
+describe('resource projectName', () => {
+ test('retrieve', async () => {
+ const responsePromise = client.alias.username.projectName.retrieve('username', 'project_name');
+ const rawResponse = await responsePromise.asResponse();
+ expect(rawResponse).toBeInstanceOf(Response);
+ const response = await responsePromise;
+ expect(response).not.toBeInstanceOf(Response);
+ const dataAndResponse = await responsePromise.withResponse();
+ expect(dataAndResponse.data).toBe(response);
+ expect(dataAndResponse.response).toBe(rawResponse);
+ });
+
+ test('retrieve: request options instead of params are passed correctly', async () => {
+ // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+ await expect(
+ client.alias.username.projectName.retrieve('username', 'project_name', {
+ path: '/_stainless_unknown_path',
+ }),
+ ).rejects.toThrow(ValTown.NotFoundError);
+ });
+});
diff --git a/tests/api-resources/projects/files.test.ts b/tests/api-resources/projects/files.test.ts
index 8b1efdd1e..b5096df64 100644
--- a/tests/api-resources/projects/files.test.ts
+++ b/tests/api-resources/projects/files.test.ts
@@ -9,6 +9,29 @@ const client = new ValTown({
});
describe('resource files', () => {
+ test('retrieve: only required params', async () => {
+ const responsePromise = client.projects.files.retrieve('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'path', {
+ limit: 1,
+ offset: 0,
+ });
+ const rawResponse = await responsePromise.asResponse();
+ expect(rawResponse).toBeInstanceOf(Response);
+ const response = await responsePromise;
+ expect(response).not.toBeInstanceOf(Response);
+ const dataAndResponse = await responsePromise.withResponse();
+ expect(dataAndResponse.data).toBe(response);
+ expect(dataAndResponse.response).toBe(rawResponse);
+ });
+
+ test('retrieve: required and optional params', async () => {
+ const response = await client.projects.files.retrieve('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'path', {
+ limit: 1,
+ offset: 0,
+ branch_id: 'branch_id',
+ version: 0,
+ });
+ });
+
test('list: only required params', async () => {
const responsePromise = client.projects.files.list('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
limit: 1,
@@ -32,4 +55,44 @@ describe('resource files', () => {
version: 0,
});
});
+
+ test('content', async () => {
+ const responsePromise = client.projects.files.content('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'path');
+ const rawResponse = await responsePromise.asResponse();
+ expect(rawResponse).toBeInstanceOf(Response);
+ const response = await responsePromise;
+ expect(response).not.toBeInstanceOf(Response);
+ const dataAndResponse = await responsePromise.withResponse();
+ expect(dataAndResponse.data).toBe(response);
+ expect(dataAndResponse.response).toBe(rawResponse);
+ });
+
+ test('content: request options instead of params are passed correctly', async () => {
+ // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+ await expect(
+ client.projects.files.content('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'path', {
+ path: '/_stainless_unknown_path',
+ }),
+ ).rejects.toThrow(ValTown.NotFoundError);
+ });
+
+ test('content: request options and params are passed correctly', async () => {
+ // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+ await expect(
+ client.projects.files.content(
+ '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
+ 'path',
+ {
+ branch_id: 'branch_id',
+ version: 0,
+ 'Cache-Control': 'Cache-Control',
+ 'If-Match': 'If-Match',
+ 'If-Modified-Since': 'If-Modified-Since',
+ 'If-None-Match': 'If-None-Match',
+ 'If-Unmodified-Since': 'If-Unmodified-Since',
+ },
+ { path: '/_stainless_unknown_path' },
+ ),
+ ).rejects.toThrow(ValTown.NotFoundError);
+ });
});