@amalgm/automations 0.1.2 → 0.2.1

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.
Files changed (65) hide show
  1. package/AXIOMS.md +27 -11
  2. package/PURPOSE.md +13 -3
  3. package/README.md +60 -113
  4. package/dist/host/auth.d.ts +11 -0
  5. package/dist/host/auth.js +89 -0
  6. package/dist/host/config.d.ts +9 -0
  7. package/dist/host/config.js +30 -0
  8. package/dist/host/index.d.ts +3 -0
  9. package/dist/host/index.js +3 -0
  10. package/dist/host/main.d.ts +1 -0
  11. package/dist/host/main.js +48 -0
  12. package/dist/host/server.d.ts +12 -0
  13. package/dist/host/server.js +54 -0
  14. package/dist/src/automations.js +4 -1
  15. package/dist/src/client.d.ts +3 -1
  16. package/dist/src/client.js +6 -4
  17. package/dist/src/contract.d.ts +19 -2
  18. package/dist/src/crud/automations.d.ts +3 -0
  19. package/dist/src/crud/automations.js +55 -0
  20. package/dist/src/crud/context.d.ts +14 -0
  21. package/dist/src/crud/context.js +43 -0
  22. package/dist/src/crud/repository.d.ts +35 -0
  23. package/dist/src/crud/repository.js +1 -0
  24. package/dist/src/crud/runs.d.ts +3 -0
  25. package/dist/src/crud/runs.js +19 -0
  26. package/dist/src/crud/triggers.d.ts +3 -0
  27. package/dist/src/crud/triggers.js +118 -0
  28. package/dist/src/crud/workflow.d.ts +3 -0
  29. package/dist/src/crud/workflow.js +42 -0
  30. package/dist/src/crud.d.ts +3 -33
  31. package/dist/src/crud.js +10 -237
  32. package/dist/src/executor.d.ts +16 -0
  33. package/dist/src/executor.js +76 -0
  34. package/dist/src/index.d.ts +8 -2
  35. package/dist/src/index.js +5 -0
  36. package/dist/src/machine-client.d.ts +7 -0
  37. package/dist/src/machine-client.js +30 -0
  38. package/dist/src/machine-http.d.ts +5 -0
  39. package/dist/src/machine-http.js +40 -0
  40. package/dist/src/machine.d.ts +41 -0
  41. package/dist/src/machine.js +43 -0
  42. package/dist/src/mcp.js +3 -3
  43. package/dist/src/schema.d.ts +50 -42
  44. package/dist/src/schema.js +3 -1
  45. package/dist/src/supabase-crud/automations.d.ts +5 -0
  46. package/dist/src/supabase-crud/automations.js +36 -0
  47. package/dist/src/supabase-crud/mappers.d.ts +8 -0
  48. package/dist/src/supabase-crud/mappers.js +81 -0
  49. package/dist/src/supabase-crud/rows.d.ts +56 -0
  50. package/dist/src/supabase-crud/rows.js +1 -0
  51. package/dist/src/supabase-crud/rpc.d.ts +10 -0
  52. package/dist/src/supabase-crud/rpc.js +19 -0
  53. package/dist/src/supabase-crud/triggers.d.ts +5 -0
  54. package/dist/src/supabase-crud/triggers.js +46 -0
  55. package/dist/src/supabase-crud/workflow-runs.d.ts +5 -0
  56. package/dist/src/supabase-crud/workflow-runs.js +41 -0
  57. package/dist/src/supabase-crud.d.ts +5 -41
  58. package/dist/src/supabase-crud.js +4 -267
  59. package/dist/src/supabase-machine.d.ts +16 -0
  60. package/dist/src/supabase-machine.js +63 -0
  61. package/dist/src/supabase-store.js +1 -0
  62. package/dist/src/types.d.ts +1 -0
  63. package/package.json +12 -3
  64. package/skills/automations/SKILL.md +52 -0
  65. package/supabase/migrations/20260829010000_bounded_schedules_and_machine_claims.sql +311 -0
@@ -13,22 +13,22 @@ export declare const pageQuerySchema: z.ZodObject<{
13
13
  }>;
14
14
  export declare const createAutomationSchema: z.ZodObject<{
15
15
  id: z.ZodOptional<z.ZodString>;
16
- targetId: z.ZodString;
16
+ targetId: z.ZodOptional<z.ZodString>;
17
17
  name: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
18
18
  description: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
19
19
  enabled: z.ZodOptional<z.ZodBoolean>;
20
20
  }, "strict", z.ZodTypeAny, {
21
- id?: string | undefined;
22
- targetId: string;
21
+ targetId?: string | undefined;
22
+ enabled?: boolean | undefined;
23
23
  name?: string | undefined;
24
+ id?: string | undefined;
24
25
  description?: string | undefined;
25
- enabled?: boolean | undefined;
26
26
  }, {
27
- id?: string | undefined;
28
- targetId: string;
27
+ targetId?: string | undefined;
28
+ enabled?: boolean | undefined;
29
29
  name?: string | undefined;
30
+ id?: string | undefined;
30
31
  description?: string | undefined;
31
- enabled?: boolean | undefined;
32
32
  }>;
33
33
  export declare const updateAutomationSchema: z.ZodEffects<z.ZodObject<{
34
34
  targetId: z.ZodOptional<z.ZodString>;
@@ -37,24 +37,24 @@ export declare const updateAutomationSchema: z.ZodEffects<z.ZodObject<{
37
37
  enabled: z.ZodOptional<z.ZodBoolean>;
38
38
  }, "strict", z.ZodTypeAny, {
39
39
  targetId?: string | undefined;
40
+ enabled?: boolean | undefined;
40
41
  name?: string | null | undefined;
41
42
  description?: string | null | undefined;
42
- enabled?: boolean | undefined;
43
43
  }, {
44
44
  targetId?: string | undefined;
45
+ enabled?: boolean | undefined;
45
46
  name?: string | null | undefined;
46
47
  description?: string | null | undefined;
47
- enabled?: boolean | undefined;
48
48
  }>, {
49
49
  targetId?: string | undefined;
50
+ enabled?: boolean | undefined;
50
51
  name?: string | null | undefined;
51
52
  description?: string | null | undefined;
52
- enabled?: boolean | undefined;
53
53
  }, {
54
54
  targetId?: string | undefined;
55
+ enabled?: boolean | undefined;
55
56
  name?: string | null | undefined;
56
57
  description?: string | null | undefined;
57
- enabled?: boolean | undefined;
58
58
  }>;
59
59
  export declare const listAutomationsSchema: z.ZodObject<{
60
60
  limit: z.ZodOptional<z.ZodNumber>;
@@ -63,52 +63,60 @@ export declare const listAutomationsSchema: z.ZodObject<{
63
63
  targetId: z.ZodOptional<z.ZodString>;
64
64
  enabled: z.ZodOptional<z.ZodBoolean>;
65
65
  }, "strict", z.ZodTypeAny, {
66
- limit?: number | undefined;
67
- offset?: number | undefined;
68
66
  targetId?: string | undefined;
69
67
  enabled?: boolean | undefined;
70
- }, {
71
68
  limit?: number | undefined;
72
69
  offset?: number | undefined;
70
+ }, {
73
71
  targetId?: string | undefined;
74
72
  enabled?: boolean | undefined;
73
+ limit?: number | undefined;
74
+ offset?: number | undefined;
75
75
  }>;
76
76
  export declare const createScheduleTriggerSchema: z.ZodObject<{
77
77
  id: z.ZodOptional<z.ZodString>;
78
78
  cron: z.ZodEffects<z.ZodString, string, string>;
79
79
  timezone: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
80
80
  enabled: z.ZodOptional<z.ZodBoolean>;
81
+ maxOccurrences: z.ZodOptional<z.ZodNumber>;
81
82
  }, "strict", z.ZodTypeAny, {
82
- id?: string | undefined;
83
83
  cron: string;
84
- timezone?: string | undefined;
85
84
  enabled?: boolean | undefined;
86
- }, {
87
85
  id?: string | undefined;
88
- cron: string;
89
86
  timezone?: string | undefined;
87
+ maxOccurrences?: number | undefined;
88
+ }, {
89
+ cron: string;
90
90
  enabled?: boolean | undefined;
91
+ id?: string | undefined;
92
+ timezone?: string | undefined;
93
+ maxOccurrences?: number | undefined;
91
94
  }>;
92
95
  export declare const updateScheduleTriggerSchema: z.ZodEffects<z.ZodObject<{
93
96
  cron: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
94
97
  timezone: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
95
98
  enabled: z.ZodOptional<z.ZodBoolean>;
99
+ maxOccurrences: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
96
100
  }, "strict", z.ZodTypeAny, {
101
+ enabled?: boolean | undefined;
97
102
  cron?: string | undefined;
98
103
  timezone?: string | undefined;
99
- enabled?: boolean | undefined;
104
+ maxOccurrences?: number | null | undefined;
100
105
  }, {
106
+ enabled?: boolean | undefined;
101
107
  cron?: string | undefined;
102
108
  timezone?: string | undefined;
103
- enabled?: boolean | undefined;
109
+ maxOccurrences?: number | null | undefined;
104
110
  }>, {
111
+ enabled?: boolean | undefined;
105
112
  cron?: string | undefined;
106
113
  timezone?: string | undefined;
107
- enabled?: boolean | undefined;
114
+ maxOccurrences?: number | null | undefined;
108
115
  }, {
116
+ enabled?: boolean | undefined;
109
117
  cron?: string | undefined;
110
118
  timezone?: string | undefined;
111
- enabled?: boolean | undefined;
119
+ maxOccurrences?: number | null | undefined;
112
120
  }>;
113
121
  export declare const createWebhookTriggerSchema: z.ZodObject<{
114
122
  id: z.ZodOptional<z.ZodString>;
@@ -117,17 +125,17 @@ export declare const createWebhookTriggerSchema: z.ZodObject<{
117
125
  secret: z.ZodString;
118
126
  enabled: z.ZodOptional<z.ZodBoolean>;
119
127
  }, "strict", z.ZodTypeAny, {
120
- id?: string | undefined;
121
- source?: string | undefined;
122
- event?: string | undefined;
123
128
  secret: string;
124
129
  enabled?: boolean | undefined;
125
- }, {
126
- id?: string | undefined;
127
- source?: string | undefined;
128
130
  event?: string | undefined;
131
+ source?: string | undefined;
132
+ id?: string | undefined;
133
+ }, {
129
134
  secret: string;
130
135
  enabled?: boolean | undefined;
136
+ event?: string | undefined;
137
+ source?: string | undefined;
138
+ id?: string | undefined;
131
139
  }>;
132
140
  export declare const updateWebhookTriggerSchema: z.ZodEffects<z.ZodObject<{
133
141
  source: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
@@ -135,25 +143,25 @@ export declare const updateWebhookTriggerSchema: z.ZodEffects<z.ZodObject<{
135
143
  secret: z.ZodOptional<z.ZodString>;
136
144
  enabled: z.ZodOptional<z.ZodBoolean>;
137
145
  }, "strict", z.ZodTypeAny, {
138
- source?: string | undefined;
146
+ enabled?: boolean | undefined;
139
147
  event?: string | undefined;
140
148
  secret?: string | undefined;
141
- enabled?: boolean | undefined;
142
- }, {
143
149
  source?: string | undefined;
150
+ }, {
151
+ enabled?: boolean | undefined;
144
152
  event?: string | undefined;
145
153
  secret?: string | undefined;
146
- enabled?: boolean | undefined;
147
- }>, {
148
154
  source?: string | undefined;
155
+ }>, {
156
+ enabled?: boolean | undefined;
149
157
  event?: string | undefined;
150
158
  secret?: string | undefined;
151
- enabled?: boolean | undefined;
152
- }, {
153
159
  source?: string | undefined;
160
+ }, {
161
+ enabled?: boolean | undefined;
154
162
  event?: string | undefined;
155
163
  secret?: string | undefined;
156
- enabled?: boolean | undefined;
164
+ source?: string | undefined;
157
165
  }>;
158
166
  export declare const createWorkflowSchema: z.ZodObject<{
159
167
  id: z.ZodOptional<z.ZodString>;
@@ -163,16 +171,16 @@ export declare const createWorkflowSchema: z.ZodObject<{
163
171
  allowlist: z.ZodOptional<z.ZodType<Json, z.ZodTypeDef, Json>>;
164
172
  limits: z.ZodOptional<z.ZodType<Json, z.ZodTypeDef, Json>>;
165
173
  }, "strict", z.ZodTypeAny, {
166
- id?: string | undefined;
167
- name?: string | undefined;
168
174
  script: string;
175
+ name?: string | undefined;
176
+ id?: string | undefined;
169
177
  compiled?: Json | undefined;
170
178
  allowlist?: Json | undefined;
171
179
  limits?: Json | undefined;
172
180
  }, {
173
- id?: string | undefined;
174
- name?: string | undefined;
175
181
  script: string;
182
+ name?: string | undefined;
183
+ id?: string | undefined;
176
184
  compiled?: Json | undefined;
177
185
  allowlist?: Json | undefined;
178
186
  limits?: Json | undefined;
@@ -214,13 +222,13 @@ export declare const listRunsSchema: z.ZodObject<{
214
222
  } & {
215
223
  status: z.ZodOptional<z.ZodEnum<["pending", "sent", "running", "completed", "failed"]>>;
216
224
  }, "strict", z.ZodTypeAny, {
225
+ status?: "pending" | "sent" | "running" | "completed" | "failed" | undefined;
217
226
  limit?: number | undefined;
218
227
  offset?: number | undefined;
219
- status?: "completed" | "failed" | "pending" | "running" | "sent" | undefined;
220
228
  }, {
229
+ status?: "pending" | "sent" | "running" | "completed" | "failed" | undefined;
221
230
  limit?: number | undefined;
222
231
  offset?: number | undefined;
223
- status?: "completed" | "failed" | "pending" | "running" | "sent" | undefined;
224
232
  }>;
225
233
  export declare function parseCreateAutomation(value: unknown): CreateAutomation;
226
234
  export declare function parseUpdateAutomation(value: unknown): UpdateAutomation;
@@ -21,7 +21,7 @@ const jsonSchema = z.lazy(() => z.union([
21
21
  ]));
22
22
  export const createAutomationSchema = z.object({
23
23
  id: identifierSchema.optional(),
24
- targetId: identifierSchema,
24
+ targetId: identifierSchema.optional(),
25
25
  name: text(500, 'Automation name').optional(),
26
26
  description: text(10_000, 'Automation description').optional(),
27
27
  enabled: z.boolean().optional(),
@@ -41,11 +41,13 @@ export const createScheduleTriggerSchema = z.object({
41
41
  cron: text(200, 'Schedule cron'),
42
42
  timezone: text(200, 'Schedule timezone').optional(),
43
43
  enabled: z.boolean().optional(),
44
+ maxOccurrences: z.number().int().min(1).max(100_000).optional(),
44
45
  }).strict();
45
46
  export const updateScheduleTriggerSchema = z.object({
46
47
  cron: text(200, 'Schedule cron').optional(),
47
48
  timezone: text(200, 'Schedule timezone').optional(),
48
49
  enabled: z.boolean().optional(),
50
+ maxOccurrences: z.number().int().min(1).max(100_000).nullable().optional(),
49
51
  }).strict().refine((patch) => Object.keys(patch).length > 0, 'Schedule trigger update must include a change');
50
52
  export const createWebhookTriggerSchema = z.object({
51
53
  id: identifierSchema.optional(),
@@ -0,0 +1,5 @@
1
+ import type { AutomationCrudRepository } from '../crud.js';
2
+ import { type SupabaseRpcClient } from './rpc.js';
3
+ type Operations = Pick<AutomationCrudRepository, 'createAutomation' | 'listAutomations' | 'getAutomation' | 'updateAutomation' | 'deleteAutomation'>;
4
+ export declare function automationRepository(client: SupabaseRpcClient): Operations;
5
+ export {};
@@ -0,0 +1,36 @@
1
+ import { automation, paged } from './mappers.js';
2
+ import { call } from './rpc.js';
3
+ export function automationRepository(client) {
4
+ return {
5
+ createAutomation: async (userId, input) => automation(await call(client, 'create_amalgm_automation', {
6
+ p_user_id: userId,
7
+ p_automation: input,
8
+ })),
9
+ listAutomations: async (userId, query) => paged(await call(client, 'list_amalgm_automations', {
10
+ p_user_id: userId,
11
+ p_target_id: query.targetId || null,
12
+ p_enabled: query.enabled ?? null,
13
+ p_limit: query.limit,
14
+ p_offset: query.offset,
15
+ }), automation, query),
16
+ getAutomation: async (userId, automationId) => {
17
+ const row = await call(client, 'get_amalgm_automation', {
18
+ p_user_id: userId,
19
+ p_automation_id: automationId,
20
+ });
21
+ return row ? automation(row) : null;
22
+ },
23
+ updateAutomation: async (userId, automationId, patch) => {
24
+ const row = await call(client, 'update_amalgm_automation', {
25
+ p_user_id: userId,
26
+ p_automation_id: automationId,
27
+ p_patch: patch,
28
+ });
29
+ return row ? automation(row) : null;
30
+ },
31
+ deleteAutomation: (userId, automationId) => call(client, 'delete_amalgm_automation', {
32
+ p_user_id: userId,
33
+ p_automation_id: automationId,
34
+ }),
35
+ };
36
+ }
@@ -0,0 +1,8 @@
1
+ import type { Automation, AutomationRun, Page, PageQuery, ScheduleTrigger, WebhookTrigger, Workflow } from '../contract.js';
2
+ import type { AutomationRow, PageResult, RunRow, TriggerRow, WorkflowRow } from './rows.js';
3
+ export declare function automation(row: AutomationRow): Automation;
4
+ export declare function schedule(row: TriggerRow): ScheduleTrigger;
5
+ export declare function webhook(row: TriggerRow): WebhookTrigger;
6
+ export declare function workflow(row: WorkflowRow): Workflow;
7
+ export declare function run(row: RunRow): AutomationRun;
8
+ export declare function paged<T, U>(result: PageResult<T>, mapper: (row: T) => U, query: Required<PageQuery>): Page<U>;
@@ -0,0 +1,81 @@
1
+ export function automation(row) {
2
+ return {
3
+ id: row.id,
4
+ targetId: row.target_id,
5
+ ...(row.name ? { name: row.name } : {}),
6
+ ...(row.description ? { description: row.description } : {}),
7
+ enabled: row.enabled,
8
+ createdAt: timestamp(row.created_at),
9
+ updatedAt: timestamp(row.updated_at),
10
+ };
11
+ }
12
+ export function schedule(row) {
13
+ return {
14
+ id: row.id,
15
+ automationId: row.automation_id,
16
+ kind: 'schedule',
17
+ enabled: row.enabled,
18
+ cron: row.cron,
19
+ timezone: row.timezone,
20
+ nextRunAt: timestamp(row.next_run_at),
21
+ ...(row.max_occurrences === null ? {} : { maxOccurrences: row.max_occurrences }),
22
+ ...(row.remaining_occurrences === null ? {} : { remainingOccurrences: row.remaining_occurrences }),
23
+ createdAt: timestamp(row.created_at),
24
+ updatedAt: timestamp(row.updated_at),
25
+ };
26
+ }
27
+ export function webhook(row) {
28
+ return {
29
+ id: row.id,
30
+ automationId: row.automation_id,
31
+ kind: 'webhook',
32
+ enabled: row.enabled,
33
+ source: row.source,
34
+ event: row.event,
35
+ secretConfigured: row.secret_configured,
36
+ createdAt: timestamp(row.created_at),
37
+ updatedAt: timestamp(row.updated_at),
38
+ };
39
+ }
40
+ export function workflow(row) {
41
+ return {
42
+ id: row.id,
43
+ automationId: row.automation_id,
44
+ ...(row.name ? { name: row.name } : {}),
45
+ script: row.script,
46
+ ...(row.compiled !== null ? { compiled: row.compiled } : {}),
47
+ ...(row.allowlist !== null ? { allowlist: row.allowlist } : {}),
48
+ ...(row.limits !== null ? { limits: row.limits } : {}),
49
+ createdAt: timestamp(row.created_at),
50
+ updatedAt: timestamp(row.updated_at),
51
+ };
52
+ }
53
+ export function run(row) {
54
+ return {
55
+ id: row.id,
56
+ automationId: row.automation_id,
57
+ triggerId: row.trigger_id,
58
+ workflowId: row.workflow_id,
59
+ targetId: row.target_id,
60
+ status: row.status,
61
+ input: row.input,
62
+ createdAt: timestamp(row.created_at),
63
+ ...(row.sent_at ? { sentAt: timestamp(row.sent_at) } : {}),
64
+ ...(row.started_at ? { startedAt: timestamp(row.started_at) } : {}),
65
+ ...(row.finished_at ? { finishedAt: timestamp(row.finished_at) } : {}),
66
+ ...(row.output !== null ? { output: row.output } : {}),
67
+ ...(row.error !== null ? { error: row.error } : {}),
68
+ };
69
+ }
70
+ export function paged(result, mapper, query) {
71
+ return {
72
+ items: result.items.map(mapper),
73
+ total: result.total,
74
+ limit: query.limit,
75
+ offset: query.offset,
76
+ hasMore: query.offset + result.items.length < result.total,
77
+ };
78
+ }
79
+ function timestamp(value) {
80
+ return new Date(value).toISOString();
81
+ }
@@ -0,0 +1,56 @@
1
+ import type { AutomationRun, Workflow } from '../contract.js';
2
+ export type AutomationRow = {
3
+ id: string;
4
+ target_id: string;
5
+ name: string | null;
6
+ description: string | null;
7
+ enabled: boolean;
8
+ created_at: Date | string;
9
+ updated_at: Date | string;
10
+ };
11
+ export type TriggerRow = {
12
+ id: string;
13
+ automation_id: string;
14
+ kind: 'schedule' | 'webhook';
15
+ enabled: boolean;
16
+ cron: string | null;
17
+ timezone: string | null;
18
+ next_run_at: Date | string | null;
19
+ max_occurrences: number | null;
20
+ remaining_occurrences: number | null;
21
+ source: string | null;
22
+ event: string | null;
23
+ secret_configured: boolean;
24
+ created_at: Date | string;
25
+ updated_at: Date | string;
26
+ };
27
+ export type WorkflowRow = {
28
+ id: string;
29
+ automation_id: string;
30
+ name: string | null;
31
+ script: string;
32
+ compiled: Workflow['compiled'] | null;
33
+ allowlist: Workflow['allowlist'] | null;
34
+ limits: Workflow['limits'] | null;
35
+ created_at: Date | string;
36
+ updated_at: Date | string;
37
+ };
38
+ export type RunRow = {
39
+ id: string;
40
+ automation_id: string;
41
+ trigger_id: string;
42
+ workflow_id: string;
43
+ target_id: string;
44
+ status: AutomationRun['status'];
45
+ input: AutomationRun['input'];
46
+ created_at: Date | string;
47
+ sent_at: Date | string | null;
48
+ started_at: Date | string | null;
49
+ finished_at: Date | string | null;
50
+ output: AutomationRun['output'] | null;
51
+ error: string | null;
52
+ };
53
+ export type PageResult<T> = {
54
+ items: T[];
55
+ total: number;
56
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ export interface SupabaseRpcClient {
2
+ rpc(functionName: string, arguments_: Record<string, unknown>): PromiseLike<{
3
+ data: unknown;
4
+ error: {
5
+ code?: string;
6
+ message?: string;
7
+ } | null;
8
+ }>;
9
+ }
10
+ export declare function call<T>(client: SupabaseRpcClient, functionName: string, arguments_: Record<string, unknown>): Promise<T>;
@@ -0,0 +1,19 @@
1
+ import { ConflictError } from '../errors.js';
2
+ export async function call(client, functionName, arguments_) {
3
+ const { data, error } = await client.rpc(functionName, arguments_);
4
+ if (!error)
5
+ return data;
6
+ if (error.code === '23505' || /duplicate key|unique constraint/i.test(error.message || '')) {
7
+ throw new ConflictError(resource(functionName));
8
+ }
9
+ throw new Error(error.message || `Supabase function ${functionName} failed`);
10
+ }
11
+ function resource(functionName) {
12
+ if (functionName.includes('workflow'))
13
+ return 'Workflow';
14
+ if (functionName.includes('trigger'))
15
+ return 'Trigger';
16
+ if (functionName.includes('automation'))
17
+ return 'Automation';
18
+ return 'Automation resource';
19
+ }
@@ -0,0 +1,5 @@
1
+ import type { AutomationCrudRepository } from '../crud.js';
2
+ import { type SupabaseRpcClient } from './rpc.js';
3
+ type Operations = Pick<AutomationCrudRepository, 'createScheduleTrigger' | 'listScheduleTriggers' | 'getScheduleTrigger' | 'updateScheduleTrigger' | 'deleteScheduleTrigger' | 'createWebhookTrigger' | 'listWebhookTriggers' | 'getWebhookTrigger' | 'updateWebhookTrigger' | 'deleteWebhookTrigger' | 'listTriggers'>;
4
+ export declare function triggerRepository(client: SupabaseRpcClient): Operations;
5
+ export {};
@@ -0,0 +1,46 @@
1
+ import { paged, schedule, webhook } from './mappers.js';
2
+ import { call } from './rpc.js';
3
+ export function triggerRepository(client) {
4
+ const list = async (functionName, userId, automationId, query, mapper) => paged(await call(client, functionName, {
5
+ p_user_id: userId,
6
+ p_automation_id: automationId,
7
+ p_limit: query.limit,
8
+ p_offset: query.offset,
9
+ }), mapper, query);
10
+ return {
11
+ createScheduleTrigger: async (userId, automationId, input) => schedule(await call(client, 'create_amalgm_schedule_trigger', { p_user_id: userId, p_automation_id: automationId, p_trigger: input })),
12
+ listScheduleTriggers: (userId, automationId, query) => list('list_amalgm_schedule_triggers', userId, automationId, query, schedule),
13
+ getScheduleTrigger: async (userId, automationId, triggerId) => {
14
+ const row = await call(client, 'get_amalgm_schedule_trigger', {
15
+ p_user_id: userId, p_automation_id: automationId, p_trigger_id: triggerId,
16
+ });
17
+ return row ? schedule(row) : null;
18
+ },
19
+ updateScheduleTrigger: async (userId, automationId, triggerId, patch) => {
20
+ const row = await call(client, 'update_amalgm_schedule_trigger', {
21
+ p_user_id: userId, p_automation_id: automationId, p_trigger_id: triggerId, p_patch: patch,
22
+ });
23
+ return row ? schedule(row) : null;
24
+ },
25
+ deleteScheduleTrigger: (userId, automationId, triggerId) => call(client, 'delete_amalgm_schedule_trigger', { p_user_id: userId, p_automation_id: automationId, p_trigger_id: triggerId }),
26
+ createWebhookTrigger: async (userId, automationId, input) => webhook(await call(client, 'create_amalgm_webhook_trigger', { p_user_id: userId, p_automation_id: automationId, p_trigger: input })),
27
+ listWebhookTriggers: (userId, automationId, query) => list('list_amalgm_webhook_triggers', userId, automationId, query, webhook),
28
+ getWebhookTrigger: async (userId, automationId, triggerId) => {
29
+ const row = await call(client, 'get_amalgm_webhook_trigger', {
30
+ p_user_id: userId, p_automation_id: automationId, p_trigger_id: triggerId,
31
+ });
32
+ return row ? webhook(row) : null;
33
+ },
34
+ updateWebhookTrigger: async (userId, automationId, triggerId, patch) => {
35
+ const row = await call(client, 'update_amalgm_webhook_trigger', {
36
+ p_user_id: userId, p_automation_id: automationId, p_trigger_id: triggerId, p_patch: patch,
37
+ });
38
+ return row ? webhook(row) : null;
39
+ },
40
+ deleteWebhookTrigger: (userId, automationId, triggerId) => call(client, 'delete_amalgm_webhook_trigger', { p_user_id: userId, p_automation_id: automationId, p_trigger_id: triggerId }),
41
+ listTriggers: async (userId, automationId) => (await call(client, 'list_amalgm_triggers', {
42
+ p_user_id: userId,
43
+ p_automation_id: automationId,
44
+ })).map((row) => row.kind === 'schedule' ? schedule(row) : webhook(row)),
45
+ };
46
+ }
@@ -0,0 +1,5 @@
1
+ import type { AutomationCrudRepository } from '../crud.js';
2
+ import { type SupabaseRpcClient } from './rpc.js';
3
+ type Operations = Pick<AutomationCrudRepository, 'createWorkflow' | 'getWorkflow' | 'updateWorkflow' | 'deleteWorkflow' | 'listRuns' | 'getRun'>;
4
+ export declare function workflowRunRepository(client: SupabaseRpcClient): Operations;
5
+ export {};
@@ -0,0 +1,41 @@
1
+ import { paged, run, workflow } from './mappers.js';
2
+ import { call } from './rpc.js';
3
+ export function workflowRunRepository(client) {
4
+ return {
5
+ createWorkflow: async (userId, automationId, input) => workflow(await call(client, 'create_amalgm_workflow', { p_user_id: userId, p_automation_id: automationId, p_workflow: input })),
6
+ getWorkflow: async (userId, automationId) => {
7
+ const row = await call(client, 'get_amalgm_workflow', {
8
+ p_user_id: userId,
9
+ p_automation_id: automationId,
10
+ });
11
+ return row ? workflow(row) : null;
12
+ },
13
+ updateWorkflow: async (userId, automationId, patch) => {
14
+ const row = await call(client, 'update_amalgm_workflow', {
15
+ p_user_id: userId,
16
+ p_automation_id: automationId,
17
+ p_patch: patch,
18
+ });
19
+ return row ? workflow(row) : null;
20
+ },
21
+ deleteWorkflow: (userId, automationId) => call(client, 'delete_amalgm_workflow', {
22
+ p_user_id: userId,
23
+ p_automation_id: automationId,
24
+ }),
25
+ listRuns: async (userId, automationId, query) => paged(await call(client, 'list_amalgm_runs', {
26
+ p_user_id: userId,
27
+ p_automation_id: automationId,
28
+ p_status: query.status || null,
29
+ p_limit: query.limit,
30
+ p_offset: query.offset,
31
+ }), run, query),
32
+ getRun: async (userId, automationId, runId) => {
33
+ const row = await call(client, 'get_amalgm_run', {
34
+ p_user_id: userId,
35
+ p_automation_id: automationId,
36
+ p_run_id: runId,
37
+ });
38
+ return row ? run(row) : null;
39
+ },
40
+ };
41
+ }
@@ -1,44 +1,8 @@
1
- import type { Automation, AutomationRun, CreateAutomation, CreateWebhookTrigger, CreateWorkflow, Page, ScheduleTrigger, Trigger, UpdateAutomation, UpdateWebhookTrigger, UpdateWorkflow, WebhookTrigger, Workflow } from './contract.js';
2
- import type { AutomationCrudRepository, NormalizedListAutomations, NormalizedListRuns, StoredScheduleCreate, StoredScheduleUpdate } from './crud.js';
3
- export interface SupabaseRpcClient {
4
- rpc(functionName: string, arguments_: Record<string, unknown>): PromiseLike<{
5
- data: unknown;
6
- error: {
7
- code?: string;
8
- message?: string;
9
- } | null;
10
- }>;
1
+ import type { AutomationCrudRepository } from './crud.js';
2
+ import type { SupabaseRpcClient } from './supabase-crud/rpc.js';
3
+ export type { SupabaseRpcClient } from './supabase-crud/rpc.js';
4
+ export interface SupabaseAutomationCrudRepository extends AutomationCrudRepository {
11
5
  }
12
- export declare class SupabaseAutomationCrudRepository implements AutomationCrudRepository {
13
- #private;
14
- private readonly client;
6
+ export declare class SupabaseAutomationCrudRepository {
15
7
  constructor(client: SupabaseRpcClient);
16
- createAutomation(userId: string, input: Required<CreateAutomation>): Promise<Automation>;
17
- listAutomations(userId: string, query: NormalizedListAutomations): Promise<Page<Automation>>;
18
- getAutomation(userId: string, automationId: string): Promise<Automation | null>;
19
- updateAutomation(userId: string, automationId: string, patch: UpdateAutomation): Promise<Automation | null>;
20
- deleteAutomation(userId: string, automationId: string): Promise<boolean>;
21
- createScheduleTrigger(userId: string, automationId: string, input: StoredScheduleCreate): Promise<ScheduleTrigger>;
22
- listScheduleTriggers(userId: string, automationId: string, query: Required<{
23
- limit?: number;
24
- offset?: number;
25
- }>): Promise<Page<ScheduleTrigger>>;
26
- getScheduleTrigger(userId: string, automationId: string, triggerId: string): Promise<ScheduleTrigger | null>;
27
- updateScheduleTrigger(userId: string, automationId: string, triggerId: string, patch: StoredScheduleUpdate): Promise<ScheduleTrigger | null>;
28
- deleteScheduleTrigger(userId: string, automationId: string, triggerId: string): Promise<boolean>;
29
- createWebhookTrigger(userId: string, automationId: string, input: Required<CreateWebhookTrigger>): Promise<WebhookTrigger>;
30
- listWebhookTriggers(userId: string, automationId: string, query: Required<{
31
- limit?: number;
32
- offset?: number;
33
- }>): Promise<Page<WebhookTrigger>>;
34
- getWebhookTrigger(userId: string, automationId: string, triggerId: string): Promise<WebhookTrigger | null>;
35
- updateWebhookTrigger(userId: string, automationId: string, triggerId: string, patch: UpdateWebhookTrigger): Promise<WebhookTrigger | null>;
36
- deleteWebhookTrigger(userId: string, automationId: string, triggerId: string): Promise<boolean>;
37
- listTriggers(userId: string, automationId: string): Promise<Trigger[]>;
38
- createWorkflow(userId: string, automationId: string, input: Required<CreateWorkflow>): Promise<Workflow>;
39
- getWorkflow(userId: string, automationId: string): Promise<Workflow | null>;
40
- updateWorkflow(userId: string, automationId: string, patch: UpdateWorkflow): Promise<Workflow | null>;
41
- deleteWorkflow(userId: string, automationId: string): Promise<boolean>;
42
- listRuns(userId: string, automationId: string, query: NormalizedListRuns): Promise<Page<AutomationRun>>;
43
- getRun(userId: string, automationId: string, runId: string): Promise<AutomationRun | null>;
44
8
  }