@teever/ez-hook-effect 0.4.4 → 0.5.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 (54) hide show
  1. package/README.md +88 -10
  2. package/dist/errors/WebhookError.d.ts +142 -3
  3. package/dist/errors/WebhookError.js +322 -0
  4. package/dist/errors/WebhookError.js.map +1 -0
  5. package/dist/errors/index.js +2 -0
  6. package/dist/errors/index.js.map +1 -0
  7. package/dist/index.d.ts +7 -3
  8. package/dist/index.js +493 -264
  9. package/dist/index.js.map +16 -14
  10. package/dist/layers/Config.d.ts +3 -3
  11. package/dist/layers/Config.js +166 -0
  12. package/dist/layers/Config.js.map +1 -0
  13. package/dist/layers/Default.d.ts +6 -0
  14. package/dist/layers/Default.js +9 -0
  15. package/dist/layers/Default.js.map +1 -0
  16. package/dist/layers/HttpClient.d.ts +8 -4
  17. package/dist/layers/HttpClient.js +209 -0
  18. package/dist/layers/HttpClient.js.map +1 -0
  19. package/dist/layers/index.js +3 -0
  20. package/dist/layers/index.js.map +1 -0
  21. package/dist/pipes/Embed.d.ts +2 -2
  22. package/dist/pipes/Embed.js +198 -0
  23. package/dist/pipes/Embed.js.map +1 -0
  24. package/dist/pipes/Webhook.d.ts +3 -2
  25. package/dist/pipes/Webhook.js +46 -0
  26. package/dist/pipes/Webhook.js.map +1 -0
  27. package/dist/pipes/index.js +3 -0
  28. package/dist/pipes/index.js.map +1 -0
  29. package/dist/schemas/Common.d.ts +6 -6
  30. package/dist/schemas/Common.js +30 -0
  31. package/dist/schemas/Common.js.map +1 -0
  32. package/dist/schemas/Discord.d.ts +1 -1
  33. package/dist/schemas/Discord.js +19 -0
  34. package/dist/schemas/Discord.js.map +1 -0
  35. package/dist/schemas/Embed.d.ts +58 -229
  36. package/dist/schemas/Embed.js +139 -0
  37. package/dist/schemas/Embed.js.map +1 -0
  38. package/dist/schemas/Field.d.ts +6 -27
  39. package/dist/schemas/Field.js +25 -0
  40. package/dist/schemas/Field.js.map +1 -0
  41. package/dist/schemas/Webhook.d.ts +42 -160
  42. package/dist/schemas/Webhook.js +87 -0
  43. package/dist/schemas/Webhook.js.map +1 -0
  44. package/dist/schemas/index.js +6 -0
  45. package/dist/schemas/index.js.map +1 -0
  46. package/dist/services/WebhookService.d.ts +27 -5
  47. package/dist/services/WebhookService.js +116 -0
  48. package/dist/services/WebhookService.js.map +1 -0
  49. package/dist/services/index.js +2 -0
  50. package/dist/services/index.js.map +1 -0
  51. package/dist/utils/normalize.d.ts +1 -0
  52. package/dist/utils/normalize.js +17 -0
  53. package/dist/utils/normalize.js.map +1 -0
  54. package/package.json +56 -54
@@ -3,201 +3,83 @@ import { Attachment } from "./Embed";
3
3
  /**
4
4
  * File attachment for webhooks
5
5
  */
6
- export declare const WebhookFile: Schema.Union<[typeof Schema.String, typeof Attachment, Schema.Struct<{
7
- name: typeof Schema.String;
8
- data: Schema.Union<[typeof Schema.String, Schema.instanceOf<Uint8Array<ArrayBuffer>>]>;
6
+ export declare const WebhookFile: Schema.Union<readonly [Schema.String, typeof Attachment, Schema.Struct<{
7
+ readonly name: Schema.String;
8
+ readonly data: Schema.Union<readonly [Schema.String, Schema.instanceOf<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>]>;
9
9
  }>]>;
10
- declare const Webhook_base: Schema.Class<Webhook, {
10
+ declare const Webhook_base: Schema.ExtendableClass<Webhook, Schema.Struct<{
11
11
  /**
12
12
  * Webhook username override.
13
13
  */
14
- username: Schema.optional<Schema.filter<typeof Schema.String>>;
14
+ readonly username: Schema.optionalKey<Schema.String>;
15
15
  /**
16
16
  * Webhook avatar URL override.
17
17
  */
18
- avatar_url: Schema.optional<Schema.refine<string, typeof Schema.String>>;
18
+ readonly avatar_url: Schema.optionalKey<Schema.String>;
19
19
  /**
20
20
  * Whether or not this notification should be read as text to speech.
21
21
  */
22
- tts: Schema.optional<typeof Schema.Boolean>;
22
+ readonly tts: Schema.optionalKey<Schema.Boolean>;
23
23
  /**
24
24
  * Message contents.
25
25
  * Max 2000 characters
26
26
  */
27
- content: Schema.optional<Schema.filter<typeof Schema.String>>;
27
+ readonly content: Schema.optionalKey<Schema.String>;
28
28
  /**
29
29
  * Contents of a file being sent.
30
30
  */
31
- file: Schema.optional<Schema.Union<[typeof Schema.String, typeof Attachment, Schema.Struct<{
32
- name: typeof Schema.String;
33
- data: Schema.Union<[typeof Schema.String, Schema.instanceOf<Uint8Array<ArrayBuffer>>]>;
31
+ readonly file: Schema.optionalKey<Schema.Union<readonly [Schema.String, typeof Attachment, Schema.Struct<{
32
+ readonly name: Schema.String;
33
+ readonly data: Schema.Union<readonly [Schema.String, Schema.instanceOf<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>]>;
34
34
  }>]>>;
35
35
  /**
36
36
  * Embedded "rich" content.
37
37
  * Max 10 embeds
38
38
  */
39
- embeds: Schema.optional<Schema.filter<Schema.Array$<typeof import("./Embed").Embed>>>;
40
- }, Schema.Struct.Encoded<{
41
- /**
42
- * Webhook username override.
43
- */
44
- username: Schema.optional<Schema.filter<typeof Schema.String>>;
45
- /**
46
- * Webhook avatar URL override.
47
- */
48
- avatar_url: Schema.optional<Schema.refine<string, typeof Schema.String>>;
49
- /**
50
- * Whether or not this notification should be read as text to speech.
51
- */
52
- tts: Schema.optional<typeof Schema.Boolean>;
53
- /**
54
- * Message contents.
55
- * Max 2000 characters
56
- */
57
- content: Schema.optional<Schema.filter<typeof Schema.String>>;
58
- /**
59
- * Contents of a file being sent.
60
- */
61
- file: Schema.optional<Schema.Union<[typeof Schema.String, typeof Attachment, Schema.Struct<{
62
- name: typeof Schema.String;
63
- data: Schema.Union<[typeof Schema.String, Schema.instanceOf<Uint8Array<ArrayBuffer>>]>;
64
- }>]>>;
65
- /**
66
- * Embedded "rich" content.
67
- * Max 10 embeds
68
- */
69
- embeds: Schema.optional<Schema.filter<Schema.Array$<typeof import("./Embed").Embed>>>;
70
- }>, never, {
71
- readonly username?: string;
72
- } & {
73
- readonly avatar_url?: string;
74
- } & {
75
- readonly tts?: boolean;
76
- } & {
77
- readonly content?: string;
78
- } & {
79
- readonly file?: string | Attachment | {
80
- readonly name: string;
81
- readonly data: string | Uint8Array<ArrayBuffer>;
82
- };
83
- } & {
84
- readonly embeds?: readonly import("./Embed").Embed[];
85
- }, {}, {}>;
39
+ readonly embeds: Schema.optionalKey<Schema.$Array<typeof import("./Embed").Embed>>;
40
+ }>, {}>;
86
41
  /**
87
42
  * Main Webhook schema
88
43
  */
89
44
  export declare class Webhook extends Webhook_base {
90
45
  }
91
- declare const WebhookParameter_base: Schema.Class<WebhookParameter, {
92
- name: Schema.optional<Schema.filter<typeof Schema.String>>;
93
- avatar: Schema.optional<Schema.refine<string, typeof Schema.String>>;
94
- channel_id: Schema.optional<typeof Schema.String>;
95
- }, Schema.Struct.Encoded<{
96
- name: Schema.optional<Schema.filter<typeof Schema.String>>;
97
- avatar: Schema.optional<Schema.refine<string, typeof Schema.String>>;
98
- channel_id: Schema.optional<typeof Schema.String>;
99
- }>, never, {
100
- readonly name?: string;
101
- } & {
102
- readonly avatar?: string;
103
- } & {
104
- readonly channel_id?: string;
105
- }, {}, {}>;
46
+ declare const WebhookParameter_base: Schema.ExtendableClass<WebhookParameter, Schema.Struct<{
47
+ readonly name: Schema.optionalKey<Schema.String>;
48
+ readonly avatar: Schema.optionalKey<Schema.String>;
49
+ readonly channel_id: Schema.optionalKey<Schema.String>;
50
+ }>, {}>;
106
51
  /**
107
52
  * Webhook parameter schema (for modify operations)
108
53
  */
109
54
  export declare class WebhookParameter extends WebhookParameter_base {
110
55
  }
111
- declare const WebhookResponse_base: Schema.Class<WebhookResponse, {
112
- id: typeof Schema.String;
113
- type: typeof Schema.Number;
114
- guild_id: Schema.optional<typeof Schema.String>;
115
- channel_id: typeof Schema.String;
116
- user: Schema.optional<Schema.Struct<{
117
- id: typeof Schema.String;
118
- username: typeof Schema.String;
119
- avatar: Schema.optional<typeof Schema.String>;
120
- discriminator: typeof Schema.String;
121
- public_flags: Schema.optional<typeof Schema.Number>;
122
- }>>;
123
- name: Schema.optional<typeof Schema.String>;
124
- avatar: Schema.optional<typeof Schema.String>;
125
- token: Schema.optional<typeof Schema.String>;
126
- application_id: Schema.optional<typeof Schema.String>;
127
- source_guild: Schema.optional<Schema.Struct<{
128
- id: typeof Schema.String;
129
- name: typeof Schema.String;
130
- icon: Schema.optional<typeof Schema.String>;
131
- }>>;
132
- source_channel: Schema.optional<Schema.Struct<{
133
- id: typeof Schema.String;
134
- name: typeof Schema.String;
135
- }>>;
136
- url: Schema.optional<Schema.refine<string, typeof Schema.String>>;
137
- }, Schema.Struct.Encoded<{
138
- id: typeof Schema.String;
139
- type: typeof Schema.Number;
140
- guild_id: Schema.optional<typeof Schema.String>;
141
- channel_id: typeof Schema.String;
142
- user: Schema.optional<Schema.Struct<{
143
- id: typeof Schema.String;
144
- username: typeof Schema.String;
145
- avatar: Schema.optional<typeof Schema.String>;
146
- discriminator: typeof Schema.String;
147
- public_flags: Schema.optional<typeof Schema.Number>;
56
+ declare const WebhookResponse_base: Schema.ExtendableClass<WebhookResponse, Schema.Struct<{
57
+ readonly id: Schema.String;
58
+ readonly type: Schema.Number;
59
+ readonly guild_id: Schema.optionalKey<Schema.String>;
60
+ readonly channel_id: Schema.String;
61
+ readonly user: Schema.optionalKey<Schema.Struct<{
62
+ readonly id: Schema.String;
63
+ readonly username: Schema.String;
64
+ readonly avatar: Schema.optionalKey<Schema.String>;
65
+ readonly discriminator: Schema.String;
66
+ readonly public_flags: Schema.optionalKey<Schema.Number>;
148
67
  }>>;
149
- name: Schema.optional<typeof Schema.String>;
150
- avatar: Schema.optional<typeof Schema.String>;
151
- token: Schema.optional<typeof Schema.String>;
152
- application_id: Schema.optional<typeof Schema.String>;
153
- source_guild: Schema.optional<Schema.Struct<{
154
- id: typeof Schema.String;
155
- name: typeof Schema.String;
156
- icon: Schema.optional<typeof Schema.String>;
68
+ readonly name: Schema.optionalKey<Schema.String>;
69
+ readonly avatar: Schema.optionalKey<Schema.String>;
70
+ readonly token: Schema.optionalKey<Schema.String>;
71
+ readonly application_id: Schema.optionalKey<Schema.String>;
72
+ readonly source_guild: Schema.optionalKey<Schema.Struct<{
73
+ readonly id: Schema.String;
74
+ readonly name: Schema.String;
75
+ readonly icon: Schema.optionalKey<Schema.String>;
157
76
  }>>;
158
- source_channel: Schema.optional<Schema.Struct<{
159
- id: typeof Schema.String;
160
- name: typeof Schema.String;
77
+ readonly source_channel: Schema.optionalKey<Schema.Struct<{
78
+ readonly id: Schema.String;
79
+ readonly name: Schema.String;
161
80
  }>>;
162
- url: Schema.optional<Schema.refine<string, typeof Schema.String>>;
163
- }>, never, {
164
- readonly url?: string;
165
- } & {
166
- readonly id: string;
167
- } & {
168
- readonly token?: string;
169
- } & {
170
- readonly name?: string;
171
- } & {
172
- readonly type: number;
173
- } & {
174
- readonly avatar?: string;
175
- } & {
176
- readonly channel_id: string;
177
- } & {
178
- readonly guild_id?: string;
179
- } & {
180
- readonly user?: {
181
- readonly id: string;
182
- readonly username: string;
183
- readonly avatar?: string;
184
- readonly discriminator: string;
185
- readonly public_flags?: number;
186
- };
187
- } & {
188
- readonly application_id?: string;
189
- } & {
190
- readonly source_guild?: {
191
- readonly id: string;
192
- readonly name: string;
193
- readonly icon?: string;
194
- };
195
- } & {
196
- readonly source_channel?: {
197
- readonly id: string;
198
- readonly name: string;
199
- };
200
- }, {}, {}>;
81
+ readonly url: Schema.optionalKey<Schema.String>;
82
+ }>, {}>;
201
83
  /**
202
84
  * Webhook response schema
203
85
  */
@@ -0,0 +1,87 @@
1
+ import { Schema } from "effect";
2
+ import { maxLength, Uint8ArraySchema, UrlString } from "./Common";
3
+ import { Attachment, EmbedArray } from "./Embed";
4
+ /**
5
+ * File attachment for webhooks
6
+ */
7
+ export const WebhookFile = Schema.Union([
8
+ Schema.String,
9
+ Attachment,
10
+ Schema.Struct({
11
+ name: Schema.String,
12
+ data: Schema.Union([Schema.String, Uint8ArraySchema]),
13
+ }),
14
+ ]);
15
+ /**
16
+ * Main Webhook schema
17
+ */
18
+ export class Webhook extends Schema.Class("Webhook")({
19
+ /**
20
+ * Webhook username override.
21
+ */
22
+ username: Schema.optionalKey(maxLength(80)),
23
+ /**
24
+ * Webhook avatar URL override.
25
+ */
26
+ avatar_url: Schema.optionalKey(UrlString),
27
+ /**
28
+ * Whether or not this notification should be read as text to speech.
29
+ */
30
+ tts: Schema.optionalKey(Schema.Boolean),
31
+ /**
32
+ * Message contents.
33
+ * Max 2000 characters
34
+ */
35
+ content: Schema.optionalKey(maxLength(2000)),
36
+ /**
37
+ * Contents of a file being sent.
38
+ */
39
+ file: Schema.optionalKey(WebhookFile),
40
+ /**
41
+ * Embedded "rich" content.
42
+ * Max 10 embeds
43
+ */
44
+ embeds: Schema.optionalKey(EmbedArray),
45
+ }) {
46
+ }
47
+ /**
48
+ * Webhook parameter schema (for modify operations)
49
+ */
50
+ export class WebhookParameter extends Schema.Class("WebhookParameter")({
51
+ name: Schema.optionalKey(maxLength(80)),
52
+ avatar: Schema.optionalKey(UrlString),
53
+ channel_id: Schema.optionalKey(Schema.String),
54
+ }) {
55
+ }
56
+ /**
57
+ * Webhook response schema
58
+ */
59
+ export class WebhookResponse extends Schema.Class("WebhookResponse")({
60
+ id: Schema.String,
61
+ type: Schema.Number,
62
+ guild_id: Schema.optionalKey(Schema.String),
63
+ channel_id: Schema.String,
64
+ user: Schema.optionalKey(Schema.Struct({
65
+ id: Schema.String,
66
+ username: Schema.String,
67
+ avatar: Schema.optionalKey(Schema.String),
68
+ discriminator: Schema.String,
69
+ public_flags: Schema.optionalKey(Schema.Number),
70
+ })),
71
+ name: Schema.optionalKey(Schema.String),
72
+ avatar: Schema.optionalKey(Schema.String),
73
+ token: Schema.optionalKey(Schema.String),
74
+ application_id: Schema.optionalKey(Schema.String),
75
+ source_guild: Schema.optionalKey(Schema.Struct({
76
+ id: Schema.String,
77
+ name: Schema.String,
78
+ icon: Schema.optionalKey(Schema.String),
79
+ })),
80
+ source_channel: Schema.optionalKey(Schema.Struct({
81
+ id: Schema.String,
82
+ name: Schema.String,
83
+ })),
84
+ url: Schema.optionalKey(UrlString),
85
+ }) {
86
+ }
87
+ //# sourceMappingURL=Webhook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Webhook.js","sourceRoot":"","sources":["../../src/schemas/Webhook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC;IACvC,MAAM,CAAC,MAAM;IACb,UAAU;IACV,MAAM,CAAC,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC,MAAM;QACnB,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;KACrD,CAAC;CACF,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,OAAO,OAAQ,SAAQ,MAAM,CAAC,KAAK,CAAU,SAAS,CAAC,CAAC;IAC7D;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IAE3C;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC;IAEzC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC;IAEvC;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAE5C;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC;IAErC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC,WAAW,CA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MAAM,CAAC,MAAM,CAAC;QACb,EAAE,EAAE,MAAM,CAAC,MAAM;QACjB,IAAI,EAAE,MAAM,CAAC,MAAM;QACnB,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC;KACvC,CAAC,CACF;IACD,cAAc,EAAE,MAAM,CAAC,WAAW,CACjC,MAAM,CAAC,MAAM,CAAC;QACb,EAAE,EAAE,MAAM,CAAC,MAAM;QACjB,IAAI,EAAE,MAAM,CAAC,MAAM;KACnB,CAAC,CACF;IACD,GAAG,EAAE,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC;CAClC,CAAC;CAAG"}
@@ -0,0 +1,6 @@
1
+ export * from "./Common";
2
+ export * from "./Discord";
3
+ export * from "./Embed";
4
+ export * from "./Field";
5
+ export * from "./Webhook";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
@@ -1,13 +1,17 @@
1
- import { Context, Effect, Layer } from "effect";
1
+ import { Effect, Layer, ServiceMap } from "effect";
2
2
  import { HttpError, NetworkError, RateLimitError, ValidationError, WebhookError } from "../errors";
3
3
  import { Config } from "../layers/Config";
4
4
  import { HttpClient } from "../layers/HttpClient";
5
5
  import { Webhook, WebhookParameter, WebhookResponse } from "../schemas";
6
- declare const WebhookService_base: Context.TagClass<WebhookService, "WebhookService", {
6
+ declare const WebhookService_base: ServiceMap.ServiceClass<WebhookService, "WebhookService", {
7
7
  /**
8
8
  * Send a webhook message
9
9
  */
10
- readonly sendWebhook: (webhook: Webhook) => Effect.Effect<boolean, WebhookError | ValidationError | NetworkError | HttpError | RateLimitError>;
10
+ readonly sendWebhook: (webhook: Webhook) => Effect.Effect<void, WebhookError | ValidationError | NetworkError | HttpError | RateLimitError>;
11
+ /**
12
+ * Send a webhook message and return the raw response.
13
+ */
14
+ readonly sendWebhookRaw: (webhook: Webhook) => Effect.Effect<SendWebhookRawResult, WebhookError | ValidationError | NetworkError | HttpError | RateLimitError>;
11
15
  /**
12
16
  * Modify webhook settings
13
17
  */
@@ -30,11 +34,25 @@ declare const WebhookService_base: Context.TagClass<WebhookService, "WebhookServ
30
34
  */
31
35
  export declare class WebhookService extends WebhookService_base {
32
36
  }
37
+ export type SendWebhookRawResult = {
38
+ status: number;
39
+ ok: boolean;
40
+ headers: Record<string, string>;
41
+ body: unknown;
42
+ text: string;
43
+ };
33
44
  /**
34
45
  * Create webhook service implementation
35
46
  */
36
47
  export declare const makeWebhookService: Effect.Effect<{
37
- sendWebhook: (webhook: Webhook) => Effect.Effect<boolean, ValidationError | NetworkError | RateLimitError | HttpError, never>;
48
+ sendWebhook: (webhook: Webhook) => Effect.Effect<void, WebhookError | ValidationError | NetworkError | RateLimitError | HttpError, never>;
49
+ sendWebhookRaw: (webhook: Webhook) => Effect.Effect<{
50
+ status: number;
51
+ ok: boolean;
52
+ headers: Record<string, string>;
53
+ body: unknown;
54
+ text: string;
55
+ }, ValidationError | NetworkError | RateLimitError | HttpError, never>;
38
56
  modifyWebhook: (params: WebhookParameter) => Effect.Effect<WebhookResponse, WebhookError | ValidationError | NetworkError | RateLimitError | HttpError, never>;
39
57
  getWebhook: () => Effect.Effect<WebhookResponse, WebhookError | NetworkError | RateLimitError | HttpError, never>;
40
58
  deleteWebhook: () => Effect.Effect<boolean, NetworkError | RateLimitError | HttpError, never>;
@@ -48,7 +66,11 @@ export declare const WebhookServiceLive: Layer.Layer<WebhookService, never, Conf
48
66
  * Send a webhook message
49
67
  * Module-level accessor that reads from context
50
68
  */
51
- export declare const sendWebhook: (webhook: Webhook) => Effect.Effect<boolean, WebhookError | ValidationError | NetworkError | HttpError | RateLimitError, WebhookService>;
69
+ export declare const sendWebhook: (webhook: Webhook) => Effect.Effect<void, WebhookError | ValidationError | NetworkError | HttpError | RateLimitError, WebhookService>;
70
+ /**
71
+ * Send a webhook message and return the raw response.
72
+ */
73
+ export declare const sendWebhookRaw: (webhook: Webhook) => Effect.Effect<SendWebhookRawResult, WebhookError | ValidationError | NetworkError | HttpError | RateLimitError, WebhookService>;
52
74
  /**
53
75
  * Modify webhook settings
54
76
  * Module-level accessor that reads from context
@@ -0,0 +1,116 @@
1
+ import { Duration, Effect, Layer, pipe, Schedule, Schema, ServiceMap, } from "effect";
2
+ import { HttpError, NetworkError, RateLimitError, ValidationError, WebhookError, } from "../errors";
3
+ import { Config } from "../layers/Config";
4
+ import { createRetrySchedule, HttpClient } from "../layers/HttpClient";
5
+ import { Webhook, WebhookParameter, WebhookResponse } from "../schemas";
6
+ import { stripUndefined } from "../utils/normalize";
7
+ /**
8
+ * Webhook service tag
9
+ */
10
+ export class WebhookService extends ServiceMap.Service()("WebhookService") {
11
+ }
12
+ /**
13
+ * Create webhook service implementation
14
+ */
15
+ export const makeWebhookService = Effect.gen(function* () {
16
+ // body unchanged
17
+ const config = yield* Config;
18
+ const httpClient = yield* HttpClient;
19
+ const webhookUrl = config.webhook.webhookUrl;
20
+ // Create retry schedule based on config
21
+ const retrySchedule = createRetrySchedule({
22
+ maxRetries: config.webhook.maxRetries ?? httpClient.retryConfig.maxRetries,
23
+ baseDelay: Duration.millis(config.webhook.baseDelayMs ??
24
+ Duration.toMillis(httpClient.retryConfig.baseDelay)),
25
+ maxDelay: Duration.millis(config.webhook.maxDelayMs ??
26
+ Duration.toMillis(httpClient.retryConfig.maxDelay)),
27
+ jitter: config.webhook.enableJitter ?? httpClient.retryConfig.jitter,
28
+ });
29
+ const sendWebhookRaw = (webhook) => pipe(Schema.decodeUnknownEffect(Webhook)(stripUndefined(webhook)), Effect.mapError((e) => ValidationError.fromParseError(e, { field: "webhook", value: webhook })), Effect.flatMap((validatedWebhook) => httpClient
30
+ .request({
31
+ method: "POST",
32
+ url: webhookUrl,
33
+ body: validatedWebhook,
34
+ })
35
+ .pipe(Effect.retry(Schedule.while(retrySchedule, (meta) => Effect.succeed(meta.input instanceof NetworkError ||
36
+ meta.input instanceof RateLimitError ||
37
+ (meta.input instanceof HttpError &&
38
+ (meta.input.response?.status ?? 0) >= 500)))))), Effect.map((response) => ({
39
+ status: response.status,
40
+ ok: response.status >= 200 && response.status < 300,
41
+ headers: response.headers,
42
+ body: response.body,
43
+ text: response.text,
44
+ })));
45
+ const sendWebhook = (webhook) => pipe(sendWebhookRaw(webhook), Effect.flatMap((response) => response.status === 204 && response.text === ""
46
+ ? Effect.void
47
+ : Effect.fail(new WebhookError({
48
+ message: `Unexpected webhook response: ${response.status}`,
49
+ cause: response,
50
+ }))));
51
+ const modifyWebhook = (params) => pipe(Schema.decodeUnknownEffect(WebhookParameter)(stripUndefined(params)), Effect.mapError((e) => ValidationError.fromParseError(e, { field: "params", value: params })), Effect.flatMap((validatedParams) => httpClient.request({
52
+ method: "PATCH",
53
+ url: webhookUrl,
54
+ body: validatedParams,
55
+ })), Effect.flatMap((response) => Schema.decodeUnknownEffect(WebhookResponse)(response.body).pipe(Effect.mapError(() => new WebhookError({
56
+ message: "Invalid webhook response",
57
+ cause: response.body,
58
+ })))));
59
+ const getWebhook = () => pipe(httpClient.request({
60
+ method: "GET",
61
+ url: webhookUrl,
62
+ }), Effect.flatMap((response) => Schema.decodeUnknownEffect(WebhookResponse)(response.body).pipe(Effect.mapError(() => new WebhookError({
63
+ message: "Invalid webhook response",
64
+ cause: response.body,
65
+ })))));
66
+ const validateWebhook = () => pipe(httpClient.request({
67
+ method: "GET",
68
+ url: webhookUrl,
69
+ }), Effect.as(true), Effect.catch(() => Effect.succeed(false)));
70
+ const deleteWebhook = () => pipe(httpClient.request({
71
+ method: "DELETE",
72
+ url: webhookUrl,
73
+ }), Effect.map((response) => response.status === 204));
74
+ return {
75
+ sendWebhook,
76
+ sendWebhookRaw,
77
+ modifyWebhook,
78
+ getWebhook,
79
+ deleteWebhook,
80
+ validateWebhook,
81
+ };
82
+ });
83
+ /**
84
+ * Live webhook service layer
85
+ */
86
+ export const WebhookServiceLive = Layer.effect(WebhookService, makeWebhookService);
87
+ /**
88
+ * Send a webhook message
89
+ * Module-level accessor that reads from context
90
+ */
91
+ export const sendWebhook = (webhook) => WebhookService.use((service) => service.sendWebhook(webhook));
92
+ /**
93
+ * Send a webhook message and return the raw response.
94
+ */
95
+ export const sendWebhookRaw = (webhook) => WebhookService.use((service) => service.sendWebhookRaw(webhook));
96
+ /**
97
+ * Modify webhook settings
98
+ * Module-level accessor that reads from context
99
+ */
100
+ export const modifyWebhook = (params) => WebhookService.use((service) => service.modifyWebhook(params));
101
+ /**
102
+ * Get webhook information
103
+ * Module-level accessor that reads from context
104
+ */
105
+ export const getWebhook = () => WebhookService.use((service) => service.getWebhook());
106
+ /**
107
+ * Delete the webhook
108
+ * Module-level accessor that reads from context
109
+ */
110
+ export const deleteWebhook = () => WebhookService.use((service) => service.deleteWebhook());
111
+ /**
112
+ * Validate webhook by checking if it exists and is accessible
113
+ * Module-level accessor that reads from context
114
+ */
115
+ export const validateWebhook = () => WebhookService.use((service) => service.validateWebhook());
116
+ //# sourceMappingURL=WebhookService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebhookService.js","sourceRoot":"","sources":["../../src/services/WebhookService.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,QAAQ,EACR,MAAM,EACN,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,UAAU,GACV,MAAM,QAAQ,CAAC;AAChB,OAAO,EACN,SAAS,EACT,YAAY,EACZ,cAAc,EACd,eAAe,EACf,YAAY,GACZ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,C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M,CAAC,MAAM,aAAa,GAAG,CAC5B,MAAwB,EAKvB,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;AAEpE;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,GAIxB,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;AAE3D;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,GAI3B,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;AAE9D;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,GAI7B,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./WebhookService";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const stripUndefined: (input: unknown) => unknown;
@@ -0,0 +1,17 @@
1
+ export const stripUndefined = (input) => {
2
+ if (Array.isArray(input)) {
3
+ return input.map(stripUndefined);
4
+ }
5
+ if (input && typeof input === "object") {
6
+ const proto = Object.getPrototypeOf(input);
7
+ if (proto !== Object.prototype && proto !== null) {
8
+ return input;
9
+ }
10
+ const entries = Object.entries(input)
11
+ .filter(([, value]) => value !== undefined)
12
+ .map(([key, value]) => [key, stripUndefined(value)]);
13
+ return Object.fromEntries(entries);
14
+ }
15
+ return input;
16
+ };
17
+ //# sourceMappingURL=normalize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../src/utils/normalize.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAc,EAAW,EAAE;IACzD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC3C,IAAI,KAAK,KAAK,MAAM,CAAC,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAClD,OAAO,KAAK,CAAC;QACd,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC;aAC9D,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC;aAC1C,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,cAAc,CAAC,KAAK,CAAC,CAAU,CAAC,CAAC;QAC/D,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC,CAAC"}