@agentuity/schedule 1.0.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +37 -0
- package/README.md +57 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -0
- package/src/index.ts +118 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Agent Guidelines for @agentuity/schedule
|
|
2
|
+
|
|
3
|
+
## Package Overview
|
|
4
|
+
|
|
5
|
+
Standalone package for the Agentuity Schedule service. Provides a simple, ergonomic client for managing cron-based scheduled jobs.
|
|
6
|
+
|
|
7
|
+
## Commands
|
|
8
|
+
|
|
9
|
+
- **Build**: `bun run build`
|
|
10
|
+
- **Typecheck**: `bun run typecheck`
|
|
11
|
+
- **Clean**: `rm -rf dist`
|
|
12
|
+
|
|
13
|
+
## Architecture
|
|
14
|
+
|
|
15
|
+
- **Runtime**: Node.js and Bun compatible
|
|
16
|
+
- **Exports**: ScheduleClient and all types from @agentuity/core/schedule
|
|
17
|
+
- **Dependencies**: @agentuity/core, @agentuity/server, zod
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { ScheduleClient } from '@agentuity/schedule';
|
|
23
|
+
|
|
24
|
+
const client = new ScheduleClient();
|
|
25
|
+
|
|
26
|
+
// Create a schedule
|
|
27
|
+
const result = await client.create({
|
|
28
|
+
name: 'Hourly Sync',
|
|
29
|
+
expression: '0 * * * *',
|
|
30
|
+
destinations: [{ type: 'url', config: { url: 'https://example.com/sync' } }]
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Publishing
|
|
35
|
+
|
|
36
|
+
1. Run `bun run build`
|
|
37
|
+
2. Must publish **after** @agentuity/core
|
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# @agentuity/schedule
|
|
2
|
+
|
|
3
|
+
A standalone package for the Agentuity Schedule service.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @agentuity/schedule
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { ScheduleClient } from '@agentuity/schedule';
|
|
15
|
+
|
|
16
|
+
const client = new ScheduleClient();
|
|
17
|
+
|
|
18
|
+
// Create a schedule that runs every hour
|
|
19
|
+
const result = await client.create({
|
|
20
|
+
name: 'Hourly Sync',
|
|
21
|
+
expression: '0 * * * *',
|
|
22
|
+
destinations: [
|
|
23
|
+
{ type: 'url', config: { url: 'https://example.com/sync' } }
|
|
24
|
+
]
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
console.log('Created schedule:', result.schedule.id);
|
|
28
|
+
console.log('Next run:', result.schedule.due_date);
|
|
29
|
+
|
|
30
|
+
// List all schedules
|
|
31
|
+
const { schedules, total } = await client.list();
|
|
32
|
+
console.log(`Found ${total} schedules`);
|
|
33
|
+
|
|
34
|
+
// Get schedule details
|
|
35
|
+
const { schedule, destinations } = await client.get(result.schedule.id);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Configuration
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
const client = new ScheduleClient({
|
|
42
|
+
apiKey: 'your-api-key',
|
|
43
|
+
url: 'https://api.agentuity.com',
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Environment Variables
|
|
48
|
+
|
|
49
|
+
| Variable | Description | Default |
|
|
50
|
+
|----------|-------------|---------|
|
|
51
|
+
| `AGENTUITY_SDK_KEY` | API key for authentication | Required |
|
|
52
|
+
| `AGENTUITY_REGION` | Region for API endpoints | `usc` |
|
|
53
|
+
| `AGENTUITY_SCHEDULE_URL` | Override Schedule API URL | Auto-detected |
|
|
54
|
+
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
Apache-2.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export { ScheduleService, type Schedule, type ScheduleDestination, type ScheduleDelivery, type CreateScheduleParams, type UpdateScheduleParams, type CreateScheduleDestinationParams, type ScheduleListResult, type ScheduleGetResult, type ScheduleCreateResult, type ScheduleDeliveryListResult, ScheduleSchema, ScheduleDestinationSchema, ScheduleDeliverySchema, CreateScheduleParamsSchema, UpdateScheduleParamsSchema, CreateScheduleDestinationParamsSchema, ScheduleListResultSchema, ScheduleGetResultSchema, ScheduleCreateResultSchema, ScheduleDeliveryListResultSchema, } from '@agentuity/core/schedule';
|
|
2
|
+
import { type CreateScheduleParams, type UpdateScheduleParams, type CreateScheduleDestinationParams, type ScheduleGetResult, type ScheduleListResult, type ScheduleCreateResult, type ScheduleDeliveryListResult, type Schedule, type ScheduleDestination } from '@agentuity/core/schedule';
|
|
3
|
+
import { type Logger } from '@agentuity/server';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
export declare const ScheduleClientOptionsSchema: z.ZodObject<{
|
|
6
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
7
|
+
url: z.ZodOptional<z.ZodString>;
|
|
8
|
+
orgId: z.ZodOptional<z.ZodString>;
|
|
9
|
+
logger: z.ZodOptional<z.ZodCustom<Logger, Logger>>;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
export type ScheduleClientOptions = z.infer<typeof ScheduleClientOptionsSchema>;
|
|
12
|
+
export declare class ScheduleClient {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(options?: ScheduleClientOptions);
|
|
15
|
+
create(params: CreateScheduleParams): Promise<ScheduleCreateResult>;
|
|
16
|
+
list(params?: {
|
|
17
|
+
limit?: number;
|
|
18
|
+
offset?: number;
|
|
19
|
+
}): Promise<ScheduleListResult>;
|
|
20
|
+
get(scheduleId: string): Promise<ScheduleGetResult>;
|
|
21
|
+
update(scheduleId: string, params: UpdateScheduleParams): Promise<{
|
|
22
|
+
schedule: Schedule;
|
|
23
|
+
}>;
|
|
24
|
+
delete(scheduleId: string): Promise<void>;
|
|
25
|
+
createDestination(scheduleId: string, params: CreateScheduleDestinationParams): Promise<{
|
|
26
|
+
destination: ScheduleDestination;
|
|
27
|
+
}>;
|
|
28
|
+
deleteDestination(destinationId: string): Promise<void>;
|
|
29
|
+
listDeliveries(scheduleId: string, params?: {
|
|
30
|
+
limit?: number;
|
|
31
|
+
offset?: number;
|
|
32
|
+
}): Promise<ScheduleDeliveryListResult>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,eAAe,EACf,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,+BAA+B,EACpC,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,0BAA0B,EAC/B,cAAc,EACd,yBAAyB,EACzB,sBAAsB,EACtB,0BAA0B,EAC1B,0BAA0B,EAC1B,qCAAqC,EACrC,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,EAC1B,gCAAgC,GAChC,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAEN,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,+BAA+B,EACpC,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,0BAA0B,EAC/B,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAgD,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAI9F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB,eAAO,MAAM,2BAA2B;;;;;iBAKtC,CAAC;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEhF,qBAAa,cAAc;;gBAGd,OAAO,GAAE,qBAA0B;IAoBzC,MAAM,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAInE,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAI/E,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAInD,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC;QAAE,QAAQ,EAAE,QAAQ,CAAA;KAAE,CAAC;IAIzF,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,iBAAiB,CACtB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,+BAA+B,GACrC,OAAO,CAAC;QAAE,WAAW,EAAE,mBAAmB,CAAA;KAAE,CAAC;IAI1C,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvD,cAAc,CACnB,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAC1C,OAAO,CAAC,0BAA0B,CAAC;CAGtC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export { ScheduleService, ScheduleSchema, ScheduleDestinationSchema, ScheduleDeliverySchema, CreateScheduleParamsSchema, UpdateScheduleParamsSchema, CreateScheduleDestinationParamsSchema, ScheduleListResultSchema, ScheduleGetResultSchema, ScheduleCreateResultSchema, ScheduleDeliveryListResultSchema, } from '@agentuity/core/schedule';
|
|
2
|
+
import { ScheduleService, } from '@agentuity/core/schedule';
|
|
3
|
+
import { createServerFetchAdapter, buildClientHeaders } from '@agentuity/server';
|
|
4
|
+
import { createMinimalLogger } from '@agentuity/core';
|
|
5
|
+
import { getEnv } from '@agentuity/core';
|
|
6
|
+
import { getServiceUrls } from '@agentuity/core/config';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
const isLogger = (val) => typeof val === 'object' &&
|
|
9
|
+
val !== null &&
|
|
10
|
+
['info', 'warn', 'error', 'debug', 'trace'].every((m) => typeof val[m] === 'function');
|
|
11
|
+
export const ScheduleClientOptionsSchema = z.object({
|
|
12
|
+
apiKey: z.string().optional().describe('API key for authentication'),
|
|
13
|
+
url: z.string().optional().describe('Base URL for the Schedule API'),
|
|
14
|
+
orgId: z.string().optional().describe('Organization ID for multi-tenant operations'),
|
|
15
|
+
logger: z.custom(isLogger).optional().describe('Custom logger instance'),
|
|
16
|
+
});
|
|
17
|
+
export class ScheduleClient {
|
|
18
|
+
#service;
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
const validatedOptions = ScheduleClientOptionsSchema.parse(options);
|
|
21
|
+
const apiKey = validatedOptions.apiKey || getEnv('AGENTUITY_SDK_KEY') || getEnv('AGENTUITY_CLI_KEY');
|
|
22
|
+
const region = getEnv('AGENTUITY_REGION') ?? 'usc';
|
|
23
|
+
const serviceUrls = getServiceUrls(region);
|
|
24
|
+
const url = validatedOptions.url || getEnv('AGENTUITY_SCHEDULE_URL') || serviceUrls.catalyst;
|
|
25
|
+
const logger = validatedOptions.logger ?? createMinimalLogger();
|
|
26
|
+
const headers = buildClientHeaders({
|
|
27
|
+
apiKey,
|
|
28
|
+
orgId: validatedOptions.orgId,
|
|
29
|
+
});
|
|
30
|
+
const adapter = createServerFetchAdapter({ headers }, logger);
|
|
31
|
+
this.#service = new ScheduleService(url, adapter);
|
|
32
|
+
}
|
|
33
|
+
async create(params) {
|
|
34
|
+
return this.#service.create(params);
|
|
35
|
+
}
|
|
36
|
+
async list(params) {
|
|
37
|
+
return this.#service.list(params);
|
|
38
|
+
}
|
|
39
|
+
async get(scheduleId) {
|
|
40
|
+
return this.#service.get(scheduleId);
|
|
41
|
+
}
|
|
42
|
+
async update(scheduleId, params) {
|
|
43
|
+
return this.#service.update(scheduleId, params);
|
|
44
|
+
}
|
|
45
|
+
async delete(scheduleId) {
|
|
46
|
+
return this.#service.delete(scheduleId);
|
|
47
|
+
}
|
|
48
|
+
async createDestination(scheduleId, params) {
|
|
49
|
+
return this.#service.createDestination(scheduleId, params);
|
|
50
|
+
}
|
|
51
|
+
async deleteDestination(destinationId) {
|
|
52
|
+
return this.#service.deleteDestination(destinationId);
|
|
53
|
+
}
|
|
54
|
+
async listDeliveries(scheduleId, params) {
|
|
55
|
+
return this.#service.listDeliveries(scheduleId, params);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,eAAe,EAWf,cAAc,EACd,yBAAyB,EACzB,sBAAsB,EACtB,0BAA0B,EAC1B,0BAA0B,EAC1B,qCAAqC,EACrC,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,EAC1B,gCAAgC,GAChC,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACN,eAAe,GAUf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAe,MAAM,mBAAmB,CAAC;AAC9F,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,C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AAC;IACvD,CAAC;IAED,KAAK,CAAC,cAAc,CACnB,UAAkB,EAClB,MAA4C;QAE5C,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;CACD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentuity/schedule",
|
|
3
|
+
"version": "1.0.54",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"author": "Agentuity employees and contributors",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"AGENTS.md",
|
|
11
|
+
"README.md",
|
|
12
|
+
"src",
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
23
|
+
"build": "bunx tsc --build --force",
|
|
24
|
+
"typecheck": "bunx tsc --noEmit",
|
|
25
|
+
"prepublishOnly": "bun run clean && bun run build"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@agentuity/core": "1.0.54",
|
|
29
|
+
"@agentuity/server": "1.0.54",
|
|
30
|
+
"zod": "^4.3.5"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/bun": "latest",
|
|
34
|
+
"@types/node": "^22.0.0",
|
|
35
|
+
"bun-types": "latest",
|
|
36
|
+
"typescript": "^5.9.0"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"sideEffects": false
|
|
42
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
export {
|
|
2
|
+
ScheduleService,
|
|
3
|
+
type Schedule,
|
|
4
|
+
type ScheduleDestination,
|
|
5
|
+
type ScheduleDelivery,
|
|
6
|
+
type CreateScheduleParams,
|
|
7
|
+
type UpdateScheduleParams,
|
|
8
|
+
type CreateScheduleDestinationParams,
|
|
9
|
+
type ScheduleListResult,
|
|
10
|
+
type ScheduleGetResult,
|
|
11
|
+
type ScheduleCreateResult,
|
|
12
|
+
type ScheduleDeliveryListResult,
|
|
13
|
+
ScheduleSchema,
|
|
14
|
+
ScheduleDestinationSchema,
|
|
15
|
+
ScheduleDeliverySchema,
|
|
16
|
+
CreateScheduleParamsSchema,
|
|
17
|
+
UpdateScheduleParamsSchema,
|
|
18
|
+
CreateScheduleDestinationParamsSchema,
|
|
19
|
+
ScheduleListResultSchema,
|
|
20
|
+
ScheduleGetResultSchema,
|
|
21
|
+
ScheduleCreateResultSchema,
|
|
22
|
+
ScheduleDeliveryListResultSchema,
|
|
23
|
+
} from '@agentuity/core/schedule';
|
|
24
|
+
|
|
25
|
+
import {
|
|
26
|
+
ScheduleService,
|
|
27
|
+
type CreateScheduleParams,
|
|
28
|
+
type UpdateScheduleParams,
|
|
29
|
+
type CreateScheduleDestinationParams,
|
|
30
|
+
type ScheduleGetResult,
|
|
31
|
+
type ScheduleListResult,
|
|
32
|
+
type ScheduleCreateResult,
|
|
33
|
+
type ScheduleDeliveryListResult,
|
|
34
|
+
type Schedule,
|
|
35
|
+
type ScheduleDestination,
|
|
36
|
+
} from '@agentuity/core/schedule';
|
|
37
|
+
import { createServerFetchAdapter, buildClientHeaders, type Logger } from '@agentuity/server';
|
|
38
|
+
import { createMinimalLogger } from '@agentuity/core';
|
|
39
|
+
import { getEnv } from '@agentuity/core';
|
|
40
|
+
import { getServiceUrls } from '@agentuity/core/config';
|
|
41
|
+
import { z } from 'zod';
|
|
42
|
+
|
|
43
|
+
const isLogger = (val: unknown): val is Logger =>
|
|
44
|
+
typeof val === 'object' &&
|
|
45
|
+
val !== null &&
|
|
46
|
+
['info', 'warn', 'error', 'debug', 'trace'].every(
|
|
47
|
+
(m) => typeof (val as Record<string, unknown>)[m] === 'function'
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
export const ScheduleClientOptionsSchema = z.object({
|
|
51
|
+
apiKey: z.string().optional().describe('API key for authentication'),
|
|
52
|
+
url: z.string().optional().describe('Base URL for the Schedule API'),
|
|
53
|
+
orgId: z.string().optional().describe('Organization ID for multi-tenant operations'),
|
|
54
|
+
logger: z.custom<Logger>(isLogger).optional().describe('Custom logger instance'),
|
|
55
|
+
});
|
|
56
|
+
export type ScheduleClientOptions = z.infer<typeof ScheduleClientOptionsSchema>;
|
|
57
|
+
|
|
58
|
+
export class ScheduleClient {
|
|
59
|
+
readonly #service: ScheduleService;
|
|
60
|
+
|
|
61
|
+
constructor(options: ScheduleClientOptions = {}) {
|
|
62
|
+
const validatedOptions = ScheduleClientOptionsSchema.parse(options);
|
|
63
|
+
const apiKey =
|
|
64
|
+
validatedOptions.apiKey || getEnv('AGENTUITY_SDK_KEY') || getEnv('AGENTUITY_CLI_KEY');
|
|
65
|
+
const region = getEnv('AGENTUITY_REGION') ?? 'usc';
|
|
66
|
+
const serviceUrls = getServiceUrls(region);
|
|
67
|
+
|
|
68
|
+
const url = validatedOptions.url || getEnv('AGENTUITY_SCHEDULE_URL') || serviceUrls.catalyst;
|
|
69
|
+
|
|
70
|
+
const logger = validatedOptions.logger ?? createMinimalLogger();
|
|
71
|
+
|
|
72
|
+
const headers = buildClientHeaders({
|
|
73
|
+
apiKey,
|
|
74
|
+
orgId: validatedOptions.orgId,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const adapter = createServerFetchAdapter({ headers }, logger);
|
|
78
|
+
this.#service = new ScheduleService(url, adapter);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async create(params: CreateScheduleParams): Promise<ScheduleCreateResult> {
|
|
82
|
+
return this.#service.create(params);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async list(params?: { limit?: number; offset?: number }): Promise<ScheduleListResult> {
|
|
86
|
+
return this.#service.list(params);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async get(scheduleId: string): Promise<ScheduleGetResult> {
|
|
90
|
+
return this.#service.get(scheduleId);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async update(scheduleId: string, params: UpdateScheduleParams): Promise<{ schedule: Schedule }> {
|
|
94
|
+
return this.#service.update(scheduleId, params);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async delete(scheduleId: string): Promise<void> {
|
|
98
|
+
return this.#service.delete(scheduleId);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async createDestination(
|
|
102
|
+
scheduleId: string,
|
|
103
|
+
params: CreateScheduleDestinationParams
|
|
104
|
+
): Promise<{ destination: ScheduleDestination }> {
|
|
105
|
+
return this.#service.createDestination(scheduleId, params);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async deleteDestination(destinationId: string): Promise<void> {
|
|
109
|
+
return this.#service.deleteDestination(destinationId);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async listDeliveries(
|
|
113
|
+
scheduleId: string,
|
|
114
|
+
params?: { limit?: number; offset?: number }
|
|
115
|
+
): Promise<ScheduleDeliveryListResult> {
|
|
116
|
+
return this.#service.listDeliveries(scheduleId, params);
|
|
117
|
+
}
|
|
118
|
+
}
|