npm package: @gcp-edge/tasks-client
Description: Google Cloud Tasks client for Edge Runtime environments using fetch API
Latest version: 0.0.1

# cloud-tasks-edge-client

Google Cloud Tasks REST API를 fetch로 구현한 클라이언트 라이브러리입니다.
공식 `@google-cloud/tasks` 라이브러리와 완전히 동일한 타입을 사용하여 동기화를 유지하며, Edge Runtime과 Cloudflare Workers에서 사용할 수 있도록 fetch 기반으로 구현되었습니다.

## Installation

```bash
npm install cloud-tasks-edge-client @google-cloud/tasks
```

## Usage

### Basic Setup

```ts
import { CloudTasksClient, type Task, type Queue } from 'cloud-tasks-edge-client';
import type { protos } from '@google-cloud/tasks';

const client = new CloudTasksClient({
  projectId: 'your-project-id',
  location: 'us-central1',
  credentials: {
    accessToken: 'your-access-token'
  }
});
```

### Creating a Task

```ts
const createTaskRequest: protos.google.cloud.tasks.v2.ICreateTaskRequest = {
  parent: client.queuePath('your-project', 'us-central1', 'your-queue'),
  task: {
    httpRequest: {
      url: 'https://your-app.com/handler',
      httpMethod: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({ data: 'example' })
    },
    scheduleTime: new Date(Date.now() + 60000).toISOString() // 1 minute from now
  },
  responseView: 'BASIC'
};

const [task] = await client.createTask(createTaskRequest);
console.log('Created task:', task.name);
```

### Getting a Task

```ts
const getTaskRequest: protos.google.cloud.tasks.v2.IGetTaskRequest = {
  name: 'projects/your-project/locations/us-central1/queues/your-queue/tasks/task-id',
  responseView: 'FULL'
};

const [task] = await client.getTask(getTaskRequest);
console.log('Task details:', task);
```

### Listing Tasks

```ts
const listTasksRequest: protos.google.cloud.tasks.v2.IListTasksRequest = {
  parent: client.queuePath('your-project', 'us-central1', 'your-queue'),
  responseView: 'BASIC',
  pageSize: 100
};

const [tasks] = await client.listTasks(listTasksRequest);
console.log('Tasks:', tasks);
```

### Queue Management

```ts
// Get queue
const getQueueRequest: protos.google.cloud.tasks.v2.IGetQueueRequest = {
  name: client.queuePath('your-project', 'us-central1', 'your-queue')
};
const [queue] = await client.getQueue(getQueueRequest);

// Pause queue
const pauseQueueRequest: protos.google.cloud.tasks.v2.IPauseQueueRequest = {
  name: client.queuePath('your-project', 'us-central1', 'your-queue')
};
await client.pauseQueue(pauseQueueRequest);

// Resume queue
const resumeQueueRequest: protos.google.cloud.tasks.v2.IResumeQueueRequest = {
  name: client.queuePath('your-project', 'us-central1', 'your-queue')
};
await client.resumeQueue(resumeQueueRequest);
```

## API Reference

### CloudTasksClient

Constructor options:
- `projectId`: Google Cloud Project ID
- `location`: Default location (e.g., 'us-central1')
- `credentials.accessToken`: OAuth 2.0 access token
- `baseURL`: API base URL (default: 'https://cloudtasks.googleapis.com')

### Methods

#### Task Management
- `createTask(request)`: Create a new task
- `getTask(request)`: Get task details
- `deleteTask(request)`: Delete a task
- `listTasks(request)`: List tasks in a queue

#### Queue Management
- `getQueue(request)`: Get queue details
- `createQueue(request)`: Create a new queue
- `updateQueue(request)`: Update queue configuration
- `deleteQueue(request)`: Delete a queue
- `purgeQueue(request)`: Purge all tasks from queue
- `pauseQueue(request)`: Pause task dispatching
- `resumeQueue(request)`: Resume task dispatching
- `listQueues(request)`: List queues in a location

#### Path Helpers
- `locationPath(project, location)`: Generate location path
- `queuePath(project, location, queue)`: Generate queue path  
- `taskPath(project, location, queue, task)`: Generate task path

## Authentication

This library requires a valid OAuth 2.0 access token. You can obtain one using:

- Google Cloud SDK: `gcloud auth print-access-token`
- Service Account JSON key with appropriate Cloud Tasks permissions
- Application Default Credentials in supported environments

## Edge Runtime Support

This library is designed to work in Edge Runtime environments including:
- Cloudflare Workers
- Vercel Edge Functions
- Next.js Edge Runtime
- Deno Deploy