vessels-sdk 0.1.4 → 0.2.0
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/dist/index.cjs +41 -0
- package/dist/index.d.cts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.js +41 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -53,6 +53,47 @@ var Vessels = class {
|
|
|
53
53
|
createdAt: data.created_at
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
+
async pushMany(payload) {
|
|
57
|
+
const res = await fetch(`${this.baseUrl}/api/v1/push/many`, {
|
|
58
|
+
method: "POST",
|
|
59
|
+
headers: {
|
|
60
|
+
"Content-Type": "application/json",
|
|
61
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
62
|
+
},
|
|
63
|
+
body: JSON.stringify(payload)
|
|
64
|
+
});
|
|
65
|
+
const data = await res.json();
|
|
66
|
+
if (res.status === 401) throw new VesselsAuthError(data.error ?? "Unauthorized");
|
|
67
|
+
if (res.status === 429) throw new VesselsRateLimitError(data.error ?? "Rate limited", Number(res.headers.get("retry-after")));
|
|
68
|
+
if (res.status === 400) throw new VesselsValidationError(data.error ?? "Validation failed", data.details);
|
|
69
|
+
if (!res.ok) throw new Error(data.error ?? `HTTP ${res.status}`);
|
|
70
|
+
return {
|
|
71
|
+
ok: true,
|
|
72
|
+
results: (data.results ?? []).map((r) => ({
|
|
73
|
+
vessel: r.vessel,
|
|
74
|
+
messageId: r.message_id,
|
|
75
|
+
vesselId: r.vessel_id,
|
|
76
|
+
...r.error ? { error: r.error } : {}
|
|
77
|
+
}))
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
async editMessage(messageId, patch) {
|
|
81
|
+
const res = await fetch(`${this.baseUrl}/api/v1/messages/${messageId}`, {
|
|
82
|
+
method: "PATCH",
|
|
83
|
+
headers: {
|
|
84
|
+
"Content-Type": "application/json",
|
|
85
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
86
|
+
},
|
|
87
|
+
body: JSON.stringify(patch)
|
|
88
|
+
});
|
|
89
|
+
const data = await res.json();
|
|
90
|
+
if (res.status === 401) throw new VesselsAuthError(data.error ?? "Unauthorized");
|
|
91
|
+
if (res.status === 404) throw new Error(data.error ?? "Message not found");
|
|
92
|
+
if (res.status === 403) throw new Error(data.error ?? "Forbidden");
|
|
93
|
+
if (res.status === 400) throw new VesselsValidationError(data.error ?? "Validation failed", data.details);
|
|
94
|
+
if (!res.ok) throw new Error(data.error ?? `HTTP ${res.status}`);
|
|
95
|
+
return { ok: true };
|
|
96
|
+
}
|
|
56
97
|
// Interaction helpers
|
|
57
98
|
approval(opts) {
|
|
58
99
|
return { type: "approval", ...opts };
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _vessels_types from '@vessels/types';
|
|
2
|
-
export { ApprovalInteraction, Card, ChecklistInteraction, ChoiceInteraction, ConfirmPreviewInteraction, Interaction, PushPayload, TextInputInteraction } from '@vessels/types';
|
|
2
|
+
export { ApprovalInteraction, Attachment, Card, ChecklistInteraction, ChoiceInteraction, ConfirmPreviewInteraction, Interaction, MessagePatch, PushManyPayload, PushPayload, TextInputInteraction } from '@vessels/types';
|
|
3
3
|
|
|
4
4
|
declare class VesselsAuthError extends Error {
|
|
5
5
|
constructor(message: string);
|
|
@@ -22,6 +22,15 @@ interface PushResponse {
|
|
|
22
22
|
vesselId: string;
|
|
23
23
|
createdAt: string;
|
|
24
24
|
}
|
|
25
|
+
interface PushManyResult {
|
|
26
|
+
ok: true;
|
|
27
|
+
results: Array<{
|
|
28
|
+
vessel: string;
|
|
29
|
+
messageId: string;
|
|
30
|
+
vesselId: string;
|
|
31
|
+
error?: string;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
25
34
|
interface PollOptions {
|
|
26
35
|
since?: string;
|
|
27
36
|
limit?: number;
|
|
@@ -69,6 +78,10 @@ declare class Vessels {
|
|
|
69
78
|
private baseUrl;
|
|
70
79
|
constructor(config: VesselsConfig);
|
|
71
80
|
push(payload: _vessels_types.PushPayload): Promise<PushResponse>;
|
|
81
|
+
pushMany(payload: _vessels_types.PushManyPayload): Promise<PushManyResult>;
|
|
82
|
+
editMessage(messageId: string, patch: _vessels_types.MessagePatch): Promise<{
|
|
83
|
+
ok: true;
|
|
84
|
+
}>;
|
|
72
85
|
approval(opts: {
|
|
73
86
|
prompt: string;
|
|
74
87
|
approveLabel?: string;
|
|
@@ -117,4 +130,4 @@ declare class Vessels {
|
|
|
117
130
|
verifyWebhook(body: string, signature: string, webhookSecret: string): boolean;
|
|
118
131
|
}
|
|
119
132
|
|
|
120
|
-
export { type InteractionResponseEvent, type PollEvent, type PollOptions, type PollResponse, type PushResponse, type UserMessageEvent, type VesselContext, Vessels, VesselsAuthError, type VesselsConfig, VesselsRateLimitError, VesselsValidationError };
|
|
133
|
+
export { type InteractionResponseEvent, type PollEvent, type PollOptions, type PollResponse, type PushManyResult, type PushResponse, type UserMessageEvent, type VesselContext, Vessels, VesselsAuthError, type VesselsConfig, VesselsRateLimitError, VesselsValidationError };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _vessels_types from '@vessels/types';
|
|
2
|
-
export { ApprovalInteraction, Card, ChecklistInteraction, ChoiceInteraction, ConfirmPreviewInteraction, Interaction, PushPayload, TextInputInteraction } from '@vessels/types';
|
|
2
|
+
export { ApprovalInteraction, Attachment, Card, ChecklistInteraction, ChoiceInteraction, ConfirmPreviewInteraction, Interaction, MessagePatch, PushManyPayload, PushPayload, TextInputInteraction } from '@vessels/types';
|
|
3
3
|
|
|
4
4
|
declare class VesselsAuthError extends Error {
|
|
5
5
|
constructor(message: string);
|
|
@@ -22,6 +22,15 @@ interface PushResponse {
|
|
|
22
22
|
vesselId: string;
|
|
23
23
|
createdAt: string;
|
|
24
24
|
}
|
|
25
|
+
interface PushManyResult {
|
|
26
|
+
ok: true;
|
|
27
|
+
results: Array<{
|
|
28
|
+
vessel: string;
|
|
29
|
+
messageId: string;
|
|
30
|
+
vesselId: string;
|
|
31
|
+
error?: string;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
25
34
|
interface PollOptions {
|
|
26
35
|
since?: string;
|
|
27
36
|
limit?: number;
|
|
@@ -69,6 +78,10 @@ declare class Vessels {
|
|
|
69
78
|
private baseUrl;
|
|
70
79
|
constructor(config: VesselsConfig);
|
|
71
80
|
push(payload: _vessels_types.PushPayload): Promise<PushResponse>;
|
|
81
|
+
pushMany(payload: _vessels_types.PushManyPayload): Promise<PushManyResult>;
|
|
82
|
+
editMessage(messageId: string, patch: _vessels_types.MessagePatch): Promise<{
|
|
83
|
+
ok: true;
|
|
84
|
+
}>;
|
|
72
85
|
approval(opts: {
|
|
73
86
|
prompt: string;
|
|
74
87
|
approveLabel?: string;
|
|
@@ -117,4 +130,4 @@ declare class Vessels {
|
|
|
117
130
|
verifyWebhook(body: string, signature: string, webhookSecret: string): boolean;
|
|
118
131
|
}
|
|
119
132
|
|
|
120
|
-
export { type InteractionResponseEvent, type PollEvent, type PollOptions, type PollResponse, type PushResponse, type UserMessageEvent, type VesselContext, Vessels, VesselsAuthError, type VesselsConfig, VesselsRateLimitError, VesselsValidationError };
|
|
133
|
+
export { type InteractionResponseEvent, type PollEvent, type PollOptions, type PollResponse, type PushManyResult, type PushResponse, type UserMessageEvent, type VesselContext, Vessels, VesselsAuthError, type VesselsConfig, VesselsRateLimitError, VesselsValidationError };
|
package/dist/index.js
CHANGED
|
@@ -51,6 +51,47 @@ var Vessels = class {
|
|
|
51
51
|
createdAt: data.created_at
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
+
async pushMany(payload) {
|
|
55
|
+
const res = await fetch(`${this.baseUrl}/api/v1/push/many`, {
|
|
56
|
+
method: "POST",
|
|
57
|
+
headers: {
|
|
58
|
+
"Content-Type": "application/json",
|
|
59
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
60
|
+
},
|
|
61
|
+
body: JSON.stringify(payload)
|
|
62
|
+
});
|
|
63
|
+
const data = await res.json();
|
|
64
|
+
if (res.status === 401) throw new VesselsAuthError(data.error ?? "Unauthorized");
|
|
65
|
+
if (res.status === 429) throw new VesselsRateLimitError(data.error ?? "Rate limited", Number(res.headers.get("retry-after")));
|
|
66
|
+
if (res.status === 400) throw new VesselsValidationError(data.error ?? "Validation failed", data.details);
|
|
67
|
+
if (!res.ok) throw new Error(data.error ?? `HTTP ${res.status}`);
|
|
68
|
+
return {
|
|
69
|
+
ok: true,
|
|
70
|
+
results: (data.results ?? []).map((r) => ({
|
|
71
|
+
vessel: r.vessel,
|
|
72
|
+
messageId: r.message_id,
|
|
73
|
+
vesselId: r.vessel_id,
|
|
74
|
+
...r.error ? { error: r.error } : {}
|
|
75
|
+
}))
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
async editMessage(messageId, patch) {
|
|
79
|
+
const res = await fetch(`${this.baseUrl}/api/v1/messages/${messageId}`, {
|
|
80
|
+
method: "PATCH",
|
|
81
|
+
headers: {
|
|
82
|
+
"Content-Type": "application/json",
|
|
83
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
84
|
+
},
|
|
85
|
+
body: JSON.stringify(patch)
|
|
86
|
+
});
|
|
87
|
+
const data = await res.json();
|
|
88
|
+
if (res.status === 401) throw new VesselsAuthError(data.error ?? "Unauthorized");
|
|
89
|
+
if (res.status === 404) throw new Error(data.error ?? "Message not found");
|
|
90
|
+
if (res.status === 403) throw new Error(data.error ?? "Forbidden");
|
|
91
|
+
if (res.status === 400) throw new VesselsValidationError(data.error ?? "Validation failed", data.details);
|
|
92
|
+
if (!res.ok) throw new Error(data.error ?? `HTTP ${res.status}`);
|
|
93
|
+
return { ok: true };
|
|
94
|
+
}
|
|
54
95
|
// Interaction helpers
|
|
55
96
|
approval(opts) {
|
|
56
97
|
return { type: "approval", ...opts };
|