@distilled.cloud/slack 1.0.0-rc.15 → 1.0.0-rc.17

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 (255) hide show
  1. package/lib/.lazy.json +1 -0
  2. package/lib/_bundle/lazy.js +4 -0
  3. package/lib/_bundle/sdk.js +2 -0
  4. package/lib/_bundle/sdk.js.map +1 -0
  5. package/lib/credentials.d.ts +1 -1
  6. package/lib/credentials.d.ts.map +1 -1
  7. package/lib/credentials.js +1 -53
  8. package/lib/errors.d.ts +31 -31
  9. package/lib/errors.d.ts.map +1 -1
  10. package/lib/errors.js +1 -59
  11. package/lib/index.d.ts +1 -1
  12. package/lib/index.js +0 -10
  13. package/lib/index.lazy.js +7 -0
  14. package/lib/pagination.d.ts +2 -2
  15. package/lib/pagination.js +1 -31
  16. package/lib/protocol.d.ts.map +1 -1
  17. package/lib/protocol.js +1 -231
  18. package/lib/retry.d.ts +2 -2
  19. package/lib/retry.d.ts.map +1 -1
  20. package/lib/retry.js +1 -45
  21. package/lib/services/admin.d.ts +123 -575
  22. package/lib/services/admin.d.ts.map +1 -1
  23. package/lib/services/admin.js +141 -2884
  24. package/lib/services/admin.js.map +1 -1
  25. package/lib/services/agents.d.ts +13 -55
  26. package/lib/services/agents.d.ts.map +1 -1
  27. package/lib/services/agents.js +1 -314
  28. package/lib/services/agents.js.map +1 -1
  29. package/lib/services/api.d.ts +0 -4
  30. package/lib/services/api.d.ts.map +1 -1
  31. package/lib/services/api.js +1 -23
  32. package/lib/services/api.js.map +1 -1
  33. package/lib/services/apps.d.ts +25 -106
  34. package/lib/services/apps.d.ts.map +1 -1
  35. package/lib/services/apps.js +35 -515
  36. package/lib/services/apps.js.map +1 -1
  37. package/lib/services/assistant.d.ts +6 -40
  38. package/lib/services/assistant.d.ts.map +1 -1
  39. package/lib/services/assistant.js +1 -209
  40. package/lib/services/assistant.js.map +1 -1
  41. package/lib/services/auth.d.ts +4 -15
  42. package/lib/services/auth.d.ts.map +1 -1
  43. package/lib/services/auth.js +1 -96
  44. package/lib/services/auth.js.map +1 -1
  45. package/lib/services/blocks.d.ts +1 -7
  46. package/lib/services/blocks.d.ts.map +1 -1
  47. package/lib/services/blocks.js +1 -26
  48. package/lib/services/blocks.js.map +1 -1
  49. package/lib/services/bookmarks.d.ts +4 -15
  50. package/lib/services/bookmarks.d.ts.map +1 -1
  51. package/lib/services/bookmarks.js +1 -81
  52. package/lib/services/bookmarks.js.map +1 -1
  53. package/lib/services/bots.d.ts +1 -9
  54. package/lib/services/bots.d.ts.map +1 -1
  55. package/lib/services/bots.js +1 -59
  56. package/lib/services/bots.js.map +1 -1
  57. package/lib/services/calls.d.ts +6 -22
  58. package/lib/services/calls.d.ts.map +1 -1
  59. package/lib/services/calls.js +1 -115
  60. package/lib/services/calls.js.map +1 -1
  61. package/lib/services/canvases.d.ts +7 -35
  62. package/lib/services/canvases.d.ts.map +1 -1
  63. package/lib/services/canvases.js +1 -140
  64. package/lib/services/canvases.js.map +1 -1
  65. package/lib/services/chat.d.ts +14 -83
  66. package/lib/services/chat.d.ts.map +1 -1
  67. package/lib/services/chat.js +1 -387
  68. package/lib/services/chat.js.map +1 -1
  69. package/lib/services/conversations.d.ts +31 -116
  70. package/lib/services/conversations.d.ts.map +1 -1
  71. package/lib/services/conversations.js +40 -696
  72. package/lib/services/conversations.js.map +1 -1
  73. package/lib/services/dialog.d.ts +1 -4
  74. package/lib/services/dialog.d.ts.map +1 -1
  75. package/lib/services/dialog.js +1 -22
  76. package/lib/services/dialog.js.map +1 -1
  77. package/lib/services/dnd.d.ts +5 -17
  78. package/lib/services/dnd.d.ts.map +1 -1
  79. package/lib/services/dnd.js +1 -96
  80. package/lib/services/dnd.js.map +1 -1
  81. package/lib/services/emoji.d.ts +1 -8
  82. package/lib/services/emoji.d.ts.map +1 -1
  83. package/lib/services/emoji.js +1 -34
  84. package/lib/services/emoji.js.map +1 -1
  85. package/lib/services/entity.d.ts +4 -16
  86. package/lib/services/entity.d.ts.map +1 -1
  87. package/lib/services/entity.js +1 -76
  88. package/lib/services/entity.js.map +1 -1
  89. package/lib/services/files.d.ts +16 -80
  90. package/lib/services/files.d.ts.map +1 -1
  91. package/lib/services/files.js +1 -439
  92. package/lib/services/files.js.map +1 -1
  93. package/lib/services/functions.d.ts +8 -49
  94. package/lib/services/functions.d.ts.map +1 -1
  95. package/lib/services/functions.js +1 -208
  96. package/lib/services/functions.js.map +1 -1
  97. package/lib/services/index.js +0 -2
  98. package/lib/services/lists.d.ts +13 -55
  99. package/lib/services/lists.d.ts.map +1 -1
  100. package/lib/services/lists.js +1 -254
  101. package/lib/services/lists.js.map +1 -1
  102. package/lib/services/migration.d.ts +1 -7
  103. package/lib/services/migration.d.ts.map +1 -1
  104. package/lib/services/migration.js +1 -32
  105. package/lib/services/migration.js.map +1 -1
  106. package/lib/services/oauth.d.ts +7 -43
  107. package/lib/services/oauth.d.ts.map +1 -1
  108. package/lib/services/oauth.js +1 -294
  109. package/lib/services/oauth.js.map +1 -1
  110. package/lib/services/openid.d.ts +3 -10
  111. package/lib/services/openid.d.ts.map +1 -1
  112. package/lib/services/openid.js +1 -84
  113. package/lib/services/openid.js.map +1 -1
  114. package/lib/services/pins.d.ts +3 -13
  115. package/lib/services/pins.d.ts.map +1 -1
  116. package/lib/services/pins.js +1 -66
  117. package/lib/services/pins.js.map +1 -1
  118. package/lib/services/reactions.d.ts +5 -17
  119. package/lib/services/reactions.d.ts.map +1 -1
  120. package/lib/services/reactions.js +1 -102
  121. package/lib/services/reactions.js.map +1 -1
  122. package/lib/services/reminders.d.ts +5 -17
  123. package/lib/services/reminders.d.ts.map +1 -1
  124. package/lib/services/reminders.js +1 -88
  125. package/lib/services/reminders.js.map +1 -1
  126. package/lib/services/rtm.d.ts +2 -11
  127. package/lib/services/rtm.d.ts.map +1 -1
  128. package/lib/services/rtm.js +1 -61
  129. package/lib/services/rtm.js.map +1 -1
  130. package/lib/services/search.d.ts +4 -35
  131. package/lib/services/search.d.ts.map +1 -1
  132. package/lib/services/search.js +1 -172
  133. package/lib/services/search.js.map +1 -1
  134. package/lib/services/stars.d.ts +4 -26
  135. package/lib/services/stars.d.ts.map +1 -1
  136. package/lib/services/stars.js +1 -134
  137. package/lib/services/stars.js.map +1 -1
  138. package/lib/services/team.d.ts +11 -63
  139. package/lib/services/team.d.ts.map +1 -1
  140. package/lib/services/team.js +1 -295
  141. package/lib/services/team.js.map +1 -1
  142. package/lib/services/tooling.d.ts +2 -5
  143. package/lib/services/tooling.d.ts.map +1 -1
  144. package/lib/services/tooling.js +1 -33
  145. package/lib/services/tooling.js.map +1 -1
  146. package/lib/services/usergroups.d.ts +7 -31
  147. package/lib/services/usergroups.d.ts.map +1 -1
  148. package/lib/services/usergroups.js +1 -151
  149. package/lib/services/usergroups.js.map +1 -1
  150. package/lib/services/users.d.ts +14 -48
  151. package/lib/services/users.d.ts.map +1 -1
  152. package/lib/services/users.js +1 -255
  153. package/lib/services/users.js.map +1 -1
  154. package/lib/services/views.d.ts +4 -14
  155. package/lib/services/views.d.ts.map +1 -1
  156. package/lib/services/views.js +1 -78
  157. package/lib/services/views.js.map +1 -1
  158. package/lib/services/workflows.d.ts +8 -51
  159. package/lib/services/workflows.d.ts.map +1 -1
  160. package/lib/services/workflows.js +1 -193
  161. package/lib/services/workflows.js.map +1 -1
  162. package/lib/services.lazy/admin.js +3 -0
  163. package/lib/services.lazy/agents.js +1 -0
  164. package/lib/services.lazy/api.js +1 -0
  165. package/lib/services.lazy/apps.js +3 -0
  166. package/lib/services.lazy/assistant.js +1 -0
  167. package/lib/services.lazy/auth.js +1 -0
  168. package/lib/services.lazy/blocks.js +1 -0
  169. package/lib/services.lazy/bookmarks.js +1 -0
  170. package/lib/services.lazy/bots.js +1 -0
  171. package/lib/services.lazy/calls.js +1 -0
  172. package/lib/services.lazy/canvases.js +1 -0
  173. package/lib/services.lazy/chat.js +1 -0
  174. package/lib/services.lazy/conversations.js +3 -0
  175. package/lib/services.lazy/dialog.js +1 -0
  176. package/lib/services.lazy/dnd.js +1 -0
  177. package/lib/services.lazy/emoji.js +1 -0
  178. package/lib/services.lazy/entity.js +1 -0
  179. package/lib/services.lazy/files.js +1 -0
  180. package/lib/services.lazy/functions.js +1 -0
  181. package/lib/services.lazy/index.js +3 -0
  182. package/lib/services.lazy/lists.js +1 -0
  183. package/lib/services.lazy/migration.js +1 -0
  184. package/lib/services.lazy/oauth.js +1 -0
  185. package/lib/services.lazy/openid.js +1 -0
  186. package/lib/services.lazy/pins.js +1 -0
  187. package/lib/services.lazy/reactions.js +1 -0
  188. package/lib/services.lazy/reminders.js +1 -0
  189. package/lib/services.lazy/rtm.js +1 -0
  190. package/lib/services.lazy/search.js +1 -0
  191. package/lib/services.lazy/stars.js +1 -0
  192. package/lib/services.lazy/team.js +1 -0
  193. package/lib/services.lazy/tooling.js +1 -0
  194. package/lib/services.lazy/usergroups.js +1 -0
  195. package/lib/services.lazy/users.js +1 -0
  196. package/lib/services.lazy/views.js +1 -0
  197. package/lib/services.lazy/workflows.js +1 -0
  198. package/lib/traits.d.ts +1 -1
  199. package/lib/traits.js +1 -12
  200. package/package.json +10 -8
  201. package/src/credentials.ts +20 -21
  202. package/src/errors.ts +31 -27
  203. package/src/index.ts +1 -1
  204. package/src/pagination.ts +2 -2
  205. package/src/protocol.ts +30 -29
  206. package/src/retry.ts +6 -6
  207. package/src/services/admin.ts +2717 -3451
  208. package/src/services/agents.ts +380 -370
  209. package/src/services/api.ts +31 -21
  210. package/src/services/apps.ts +569 -621
  211. package/src/services/assistant.ts +235 -270
  212. package/src/services/auth.ts +118 -100
  213. package/src/services/blocks.ts +33 -29
  214. package/src/services/bookmarks.ts +101 -83
  215. package/src/services/bots.ts +74 -67
  216. package/src/services/calls.ts +118 -124
  217. package/src/services/canvases.ts +171 -178
  218. package/src/services/chat.ts +428 -496
  219. package/src/services/conversations.ts +675 -761
  220. package/src/services/dialog.ts +30 -17
  221. package/src/services/dnd.ts +125 -99
  222. package/src/services/emoji.ts +46 -42
  223. package/src/services/entity.ts +94 -92
  224. package/src/services/files.ts +536 -531
  225. package/src/services/functions.ts +209 -274
  226. package/src/services/lists.ts +289 -304
  227. package/src/services/migration.ts +39 -37
  228. package/src/services/oauth.ts +345 -361
  229. package/src/services/openid.ts +137 -122
  230. package/src/services/pins.ts +83 -70
  231. package/src/services/reactions.ts +119 -103
  232. package/src/services/reminders.ts +112 -90
  233. package/src/services/rtm.ts +73 -65
  234. package/src/services/search.ts +193 -244
  235. package/src/services/stars.ts +101 -160
  236. package/src/services/team.ts +333 -369
  237. package/src/services/tooling.ts +43 -30
  238. package/src/services/usergroups.ts +175 -179
  239. package/src/services/users.ts +301 -268
  240. package/src/services/views.ts +85 -80
  241. package/src/services/workflows.ts +184 -269
  242. package/src/traits.ts +1 -1
  243. package/lib/credentials.js.map +0 -1
  244. package/lib/errors.js.map +0 -1
  245. package/lib/pagination.js.map +0 -1
  246. package/lib/protocol.js.map +0 -1
  247. package/lib/protocol.test.d.ts +0 -2
  248. package/lib/protocol.test.d.ts.map +0 -1
  249. package/lib/protocol.test.js +0 -288
  250. package/lib/protocol.test.js.map +0 -1
  251. package/lib/retry.js.map +0 -1
  252. package/lib/services/index.js.map +0 -1
  253. package/lib/traits.js.map +0 -1
  254. package/src/protocol.test.ts +0 -372
  255. /package/lib/{index.js.map → index.lazy.js.map} +0 -0
package/lib/.lazy.json ADDED
@@ -0,0 +1 @@
1
+ {"serviceDirs":["services"],"twins":["index.js"]}
@@ -0,0 +1,4 @@
1
+ import*as $0 from"./sdk.js";
2
+ import{api$lazyService as L}from"@distilled.cloud/core/_bundle/base";
3
+ const u=import.meta.url,N=[$0];
4
+ export const $L=(s,k,a,l,x)=>L(u,s,k,a===void 0?void 0:x?N.concat(x):N,a,l);
@@ -0,0 +1,2 @@
1
+ import{api$D as e,api$Protocol as t,api$call as n,api$named as r,api$op as i,api$opPaginated as a,category$withParseError as o,category$withThrottlingError as s,config$String as c,config$all as l,config$orElse as ee,config$withDefault as te,pagination$paginateCursor as ne,response_validation$validateResponse as u,retry$capped as re,retry$jittered as ie,retry$makeDefault as ae,retry$throttlingFactory as d,retry$throttlingOptions as f,retry$transientFactory as p,retry$transientOptions as m,trait$Body as oe,trait$FormDataFile as se,trait$Header as ce,trait$Http as le,trait$HttpBody as ue,trait$KeyDictionary as de,trait$Label as fe,trait$Query as pe,trait$ResponseCode as h,trait$UnionCases as g,trait$applyErrorMatchers as _,trait$bodySymbol as v,trait$errorMatchersSymbol as y,trait$formDataFileSymbol as b,trait$getErrorMatchers as x,trait$headerSymbol as S,trait$httpBodySymbol as C,trait$httpSymbol as w,trait$keyDictionarySymbol as T,trait$labelSymbol as E,trait$querySymbol as D,trait$responseCodeSymbol as O,trait$unionCasesSymbol as k}from"@distilled.cloud/core/_bundle/base";import{debug$debugHttp as A,error_category$withCategory as j,errors$API_ERRORS as M,errors$BadGateway as N,errors$BadRequest as P,errors$ConfigError as F,errors$Conflict as I,errors$DEFAULT_ERRORS as L,errors$DurationSchema as R,errors$Forbidden as z,errors$GatewayTimeout as B,errors$HTTP_STATUS_MAP as V,errors$InternalServerError as H,errors$NotFound as me,errors$RETRYABLE as he,errors$ServiceUnavailable as U,errors$TooManyRequests as ge,errors$Unauthorized as W,errors$UnprocessableEntity as _e,protocol_http$buildRequest as ve,protocol_http$getAnn as ye,protocol_http$getProps as be,protocol_http$hasPropAnn as G,protocol_http$mapKeys as xe,protocol_http$matchTypedError as Se,protocol_rest$RawResponse as Ce,protocol_rest$RawResponseRoot as we,protocol_rest$SensitiveValue as Te,protocol_rest$rawResponseRootSymbol as Ee,protocol_rest$rawResponseSymbol as De,protocol_rest$sensitiveValueSymbol as Oe,protocol_rest$unwrapRedactedDeep as ke,protocol_rest$wrapSensitive as Ae,retry_after$parseRetryAfterForStatus as K,retry_after$parseServerRetryHint as je,schema_lite$Array as Me,schema_lite$Boolean as Ne,schema_lite$NullOr as Pe,schema_lite$Number as Fe,schema_lite$Record as Ie,schema_lite$String as Le,schema_lite$Struct as Re,schema_lite$Unknown as ze,schema_lite$at as Be,schema_lite$optional as Ve,schema_lite$suspend as He}from"@distilled.cloud/core/_bundle/rest";import*as q from"effect/Context";import*as J from"effect/Effect";import*as Y from"effect/Layer";import*as X from"effect/Redacted";import*as Z from"@distilled.cloud/core/schema-lite-typed";const Q=`https://slack.com/api`;var Credentials=class extends (/*@__PURE__*/ q.Service()(`SlackCredentials`)){};const Ue=/*@__PURE__*/ l({token:/*@__PURE__*/ c(`SLACK_BOT_TOKEN`).pipe(/*@__PURE__*/ ee(()=>c(`SLACK_TOKEN`))),apiBaseUrl:/*@__PURE__*/ c(`SLACK_API_URL`).pipe(/*@__PURE__*/ te(Q))});const We=/*@__PURE__*/ Y.succeed(Credentials,/*@__PURE__*/ Ue.pipe(/*@__PURE__*/ J.mapError(()=>new F({message:`SLACK_BOT_TOKEN (or SLACK_TOKEN) environment variable is required`})),/*@__PURE__*/ J.map(({token:e,apiBaseUrl:t})=>({token:X.make(e),apiBaseUrl:t})),J.orDie));const credentials=e=>Y.succeed(Credentials,J.succeed({token:e.token,apiBaseUrl:e.apiBaseUrl??`https://slack.com/api`}));var SlackError=class extends (/*@__PURE__*/ Z.TaggedError()(`SlackError`,{code:Z.String,message:/*@__PURE__*/ Z.optional(Z.String),needed:/*@__PURE__*/ Z.optional(Z.String),provided:/*@__PURE__*/ Z.optional(Z.String),messages:/*@__PURE__*/ Z.optional(/*@__PURE__*/ Z.Array(Z.String))})){};var SlackRateLimited=class extends (/*@__PURE__*/ Z.TaggedError()(`SlackRateLimited`,{code:Z.String,message:/*@__PURE__*/ Z.optional(Z.String),retryAfter:/*@__PURE__*/ Z.optional(R)}).pipe(/*@__PURE__*/ j(he),s)){};var SlackHttpError=class extends (/*@__PURE__*/ Z.TaggedError()(`SlackHttpError`,{status:Z.Number,message:Z.String,body:/*@__PURE__*/ Z.optional(Z.String)})){};var SlackParseError=class extends (/*@__PURE__*/ Z.TaggedError()(`SlackParseError`,{body:Z.Unknown,cause:Z.Unknown}).pipe(o)){};const slackPaginate=(e,t,n)=>ne(e,t,n);const fail=e=>J.fail(e);const Ge=/*@__PURE__*/ new Set([`not_authed`,`invalid_auth`,`account_inactive`,`token_revoked`,`token_expired`]);const $={internal_error:e=>new H({message:e}),fatal_error:e=>new H({message:e}),service_unavailable:e=>new U({message:e}),request_timeout:e=>new B({message:e})};const serializeForWire=(e,t)=>{if(e===null||typeof e!==`object`||Array.isArray(e))return e;const n=ye(t,w)?.contentType===`form-urlencoded`;const r=be(t);if(r.length===0)return e;let i;for(const t of r){const r=String(t.name);const a=e[r];if(a===null||typeof a!==`object`)continue;const o=G(t,D);if(Array.isArray(a)&&(o||n)){i??={...e};i[r]=a.every(e=>typeof e!==`object`||e===null)?a.join(`,`):JSON.stringify(a)}else if(n&&!o){i??={...e};i[r]=JSON.stringify(a)}}return i??e};const encode=({input:e,inputAst:t})=>J.gen(function*(){const n=yield*yield*Credentials;const r=X.value(n.token);return ve({input:serializeForWire(ke(e),t),inputAst:t,baseUrl:n.apiBaseUrl,headers:r===``?{}:{authorization:`Bearer ${r}`}})});const decode=({response:e,outputAst:t,errors:n})=>J.gen(function*(){const r=new Uint8Array(yield*e.arrayBuffer.pipe(J.orDie));const i=new TextDecoder().decode(r);if(A())console.error(`[distilled] <- ${e.status} ${i.slice(0,400)}`);let a;if(i.trim().length>0)try{const e=JSON.parse(i);if(e!==null&&typeof e===`object`)a=e}catch{}const o=e.status;const s=e.headers;if(o>=400||a?.ok===false){const e=typeof a?.error===`string`?a.error:void 0;const t=[...(a?.response_metadata)?.messages??[],...Array.isArray(a?.errors)?a.errors:[]].filter(e=>typeof e===`string`);const r=t[0]??e??(a===void 0&&i.trim()?i.trim():`HTTP ${o}`);const c=Se(n,o,[{message:r}],{body:a===void 0?i:a,headers:s});if(c!==void 0)return yield*fail(c);if(o===429||e===`rate_limited`||e===`ratelimited`)return yield*fail(new SlackRateLimited({code:e??`rate_limited`,message:r,retryAfter:je(s)}));if(e!==void 0&&Ge.has(e))return yield*fail(new W({message:e}));if(e!==void 0&&e in $)return yield*fail($[e](r));if(e!==void 0)return yield*fail(new SlackError({code:e,...r!==e?{message:r}:{},...typeof a?.needed===`string`?{needed:a.needed}:{},...typeof a?.provided===`string`?{provided:a.provided}:{},...t.length>0?{messages:t}:{}}));const l=V[o];if(l)return yield*fail(new l({message:r,retryAfter:K(o,s)}));if(o>=500)return yield*fail(new H({message:r,retryAfter:K(o,s)}));return yield*fail(new SlackHttpError({status:o,message:r,body:i.slice(0,2e3)}))}if(a===void 0)return yield*u(t,r,e=>new SlackParseError({body:i,cause:e})).pipe(J.catch(fail));const c=yield*u(t,xe(t,a,`decode`),e=>new SlackParseError({body:a,cause:e})).pipe(J.catch(fail));return Ae(t,c)});const Ke=/*@__PURE__*/ Y.succeed(t,/*@__PURE__*/ t.of({encode:e=>encode(e),decode}));var Retry=class extends (/*@__PURE__*/ q.Service()(`SlackRetry`)){};const policy=e=>J.provide(Y.succeed(Retry,e));const qe=/*@__PURE__*/ J.provide(/*@__PURE__*/ Y.succeed(Retry,{while:()=>false}));const Je=ae;const Ye=ie;const Xe=re;const Ze=f;const Qe=/*@__PURE__*/ policy(d);const $e=m;const et=/*@__PURE__*/ policy(p);export{Ie as a,ze as c,Credentials as credentials$Credentials,We as credentials$CredentialsFromEnv,Q as credentials$DEFAULT_API_BASE_URL,credentials as credentials$credentials,He as d,M as errors$API_ERRORS,N as errors$BadGateway,P as errors$BadRequest,F as errors$ConfigError,I as errors$Conflict,L as errors$DEFAULT_ERRORS,z as errors$Forbidden,B as errors$GatewayTimeout,V as errors$HTTP_STATUS_MAP,H as errors$InternalServerError,me as errors$NotFound,U as errors$ServiceUnavailable,SlackError as errors$SlackError,SlackHttpError as errors$SlackHttpError,SlackParseError as errors$SlackParseError,SlackRateLimited as errors$SlackRateLimited,ge as errors$TooManyRequests,W as errors$Unauthorized,_e as errors$UnprocessableEntity,e as f,a as g,i as h,Fe as i,Be as l,r as m,Ne as n,Le as o,n as p,slackPaginate as pagination$slackPaginate,Ke as protocol$SlackProtocol,Pe as r,Retry as retry$Retry,Xe as retry$capped,Ye as retry$jittered,Je as retry$makeDefault,qe as retry$none,policy as retry$policy,Qe as retry$throttling,Ze as retry$throttlingOptions,et as retry$transient,$e as retry$transientOptions,Re as s,Me as t,oe as traits$Body,se as traits$FormDataFile,ce as traits$Header,le as traits$Http,ue as traits$HttpBody,de as traits$KeyDictionary,fe as traits$Label,pe as traits$Query,Ce as traits$RawResponse,we as traits$RawResponseRoot,h as traits$ResponseCode,Te as traits$SensitiveValue,g as traits$UnionCases,_ as traits$applyErrorMatchers,v as traits$bodySymbol,y as traits$errorMatchersSymbol,b as traits$formDataFileSymbol,x as traits$getErrorMatchers,S as traits$headerSymbol,C as traits$httpBodySymbol,w as traits$httpSymbol,T as traits$keyDictionarySymbol,E as traits$labelSymbol,D as traits$querySymbol,Ee as traits$rawResponseRootSymbol,De as traits$rawResponseSymbol,O as traits$responseCodeSymbol,Oe as traits$sensitiveValueSymbol,k as traits$unionCasesSymbol,Ve as u};
2
+ //# sourceMappingURL=sdk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk.js","names":["EffectConfig.String","Category.withThrottlingError","Category.withParseError","Pagination.paginateCursor","API.Protocol","Retries.makeDefault","Retries.jittered","Retries.capped","Retries.throttlingOptions","Retries.throttlingFactory","Retries.transientOptions","Retries.transientFactory","D","Protocol","call","named","op","opPaginated","withParseError","withThrottlingError","String$2","all$1","orElse","withDefault","paginateCursor","validateResponse","capped$1","jittered$1","makeDefault$1","throttlingFactory","throttlingOptions$1","transientFactory","transientOptions$1","Body","FormDataFile","Header","Http","HttpBody","KeyDictionary","Label","Query","ResponseCode","UnionCases","applyErrorMatchers","bodySymbol","errorMatchersSymbol","formDataFileSymbol","getErrorMatchers","headerSymbol","httpBodySymbol","httpSymbol","keyDictionarySymbol","labelSymbol","querySymbol","responseCodeSymbol","unionCasesSymbol","debugHttp","withCategory","API_ERRORS","BadGateway","BadRequest","ConfigError","Conflict","DEFAULT_ERRORS","DurationSchema","Forbidden","GatewayTimeout","HTTP_STATUS_MAP","InternalServerError","NotFound","RETRYABLE","ServiceUnavailable","TooManyRequests","Unauthorized","UnprocessableEntity","buildRequest","getAnn","getProps","hasPropAnn","mapKeys","matchTypedError","RawResponse","RawResponseRoot","SensitiveValue","rawResponseRootSymbol","rawResponseSymbol","sensitiveValueSymbol","unwrapRedactedDeep","wrapSensitive","parseRetryAfterForStatus","parseServerRetryHint","Array$1","Boolean","NullOr","Number","Record","String$1","Struct","Unknown","at","optional","suspend","Context","Effect","Layer","Redacted","Schema","DEFAULT_API_BASE_URL","envConfig","CredentialsFromEnv","token","config","operation","input","pagination","AUTH_SLUGS","SERVER_SLUGS","isForm","inputAst","props","out","prop","key","value","isQuery","v","creds","errorClasses","bytes","response","text","json","parsed","status","headers","slug","detailMessages","m","message","typed","StatusErrorClass","outputAst","mapped","SlackProtocol","args","optionsOrFactory","none","makeDefault","jittered","capped","throttlingOptions","throttling","transientOptions","transient"],"sources":["../../src/credentials.ts","../../src/errors.ts","../../src/pagination.ts","../../src/protocol.ts","../../src/retry.ts"],"mappings":"+lFA8BA,MAAa2G,EAAuB,wBAOpC,IAAa,YAAb,eACwB,gBAAQ,QAA4C,CAAC,CAAC,kBAAkB,EAAA,AAAE,CAAC,EAEnG,MAAMC,GAA0B,gBAAiB,CAG/C,MAAqB,gBAAoB,iBAAiB,CAAC,CAAC,KAC5C,qBAA0B5G,EAAoB,aAAa,CAAC,CAC5E,EACA,WAA0B,gBAAoB,eAAe,CAAC,CAAC,KAC/C,iBAAyB2G,CAAoB,CAC7D,CACF,CAAC,EAED,MAAaE,GAAmC,gBAAM,QACpD,YACc,iBAAU,KACR,gBAAO,aAEjB,IAAIhD,EAAY,CACd,QAAS,mEACX,CAAC,CACL,EACc,gBAAO,KAAK,CAAE,QAAO,iBAAkB,CACnD,MAAO4C,EAAS,KAAKK,CAAK,EAC1B,YACF,EAAE,EACFP,EAAO,KACT,CACF,EAMA,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uC,EAAS,MAAOrH,EACpBoH,EACA9D,GAAQ8D,EAAWV,EAAM,QAAQ,EAChC,GAAU,IAAI,gBAAgB,CAAE,KAAMA,EAAM,OAAM,CAAC,CACtD,CAAC,CAAC,KAAK5B,EAAO,MAAM,IAAI,CAAC,EACzB,OAAOf,GAAcqD,EAAWC,CAAM,CACxC,CAAC,EAEH,MAAaC,GAAyD,gBAAM,QAC1E3I,EACc,gBAAa,GAAG,CAE5B,OAAS,GAAS,OAAO4I,CAAI,EAC7B,MACF,CAAC,CACH,EC3RA,IAAa,MAAb,eAAyC,gBAAQ,QAAuB,CAAC,CAAC,YAAY,EAAA,AAAE,CAAC,EAGzF,MAAa,OAOR,GAAwCzC,EAAO,QAAQC,EAAM,QAAQ,MAAOyC,CAAgB,CAAC,EAGlG,MAAaC,GAE+C,gBAAO,QACnD,gBAAM,QAAQ,MAAO,CAAE,UAAa,KAAM,CAAC,CAC3D,EAOA,MAAaC,GAAuB9I,GAEpC,MAAa+I,GAAW9I,GACxB,MAAa+I,GAAS9I,GAGtB,MAAa+I,GAA6B9I,EAG1C,MAAa+I,GAE+C,qBAAO9I,CAAyB,EAG5F,MAAa+I,GAA4B9I,EAGzC,MAAa+I,GAE+C,qBAAO9I,CAAwB"}
@@ -12,7 +12,7 @@ export interface Config {
12
12
  readonly apiBaseUrl: string;
13
13
  }
14
14
  declare const Credentials_base: Context.ServiceClass<Credentials, "SlackCredentials", Effect.Effect<Config, never, never>>;
15
- export declare class Credentials extends Credentials_base {
15
+ export declare class Credentials extends /*@__PURE__*/ Credentials_base {
16
16
  }
17
17
  export declare const CredentialsFromEnv: Layer.Layer<Credentials, never, never>;
18
18
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MA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AM,CAAC,CAAC;IAC1C,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B,KAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAOxB,CAAC"}
@@ -1,53 +1 @@
1
- import { ConfigError } from "@distilled.cloud/core/errors";
2
- /**
3
- * Slack credentials — hand-written.
4
- *
5
- * The `Credentials` service resolves `{ token, apiBaseUrl }` per request; the
6
- * protocol layer formats the `Authorization: Bearer <token>` header from it.
7
- *
8
- * Slack authorizes Web API calls with one bearer token, and the token's
9
- * PREFIX carries its kind (https://docs.slack.dev/authentication/tokens):
10
- * • `xoxb-…` — a bot token (what almost every integration uses)
11
- * • `xoxp-…` — a user token, for calls made on behalf of a user
12
- * • `xoxe.xoxb-…` / `xoxe.xoxp-…` — rotating (expiring) variants
13
- * • `xapp-…` — an app-level token (Socket Mode / `apps.connections.open`)
14
- * The header is the same for all of them, so there is no token-type knob.
15
- *
16
- * The OAuth exchange methods (`oauth.v2.access`, `openid.connect.token`, …)
17
- * authenticate with `client_id`/`client_secret` args instead of a token — for
18
- * those, an empty-string token is allowed and the protocol simply omits the
19
- * Authorization header.
20
- */
21
- import * as EffectConfig from "effect/Config";
22
- import * as Context from "effect/Context";
23
- import * as Effect from "effect/Effect";
24
- import * as Layer from "effect/Layer";
25
- import * as Redacted from "effect/Redacted";
26
- /**
27
- * Slack Web API base URL. Every method is `POST/GET <base>/<method>`.
28
- * Override via `SLACK_API_URL` only to point at a proxy or a mock.
29
- */
30
- export const DEFAULT_API_BASE_URL = "https://slack.com/api";
31
- export class Credentials extends Context.Service()("SlackCredentials") {
32
- }
33
- const envConfig = EffectConfig.all({
34
- // SLACK_BOT_TOKEN is the spelling Bolt and most hosting platforms use;
35
- // SLACK_TOKEN is the fallback (the node SDK's CLI convention).
36
- token: EffectConfig.String("SLACK_BOT_TOKEN").pipe(EffectConfig.orElse(() => EffectConfig.String("SLACK_TOKEN"))),
37
- apiBaseUrl: EffectConfig.String("SLACK_API_URL").pipe(EffectConfig.withDefault(DEFAULT_API_BASE_URL)),
38
- });
39
- export const CredentialsFromEnv = Layer.succeed(Credentials, envConfig.pipe(Effect.mapError(() => new ConfigError({
40
- message: "SLACK_BOT_TOKEN (or SLACK_TOKEN) environment variable is required",
41
- })), Effect.map(({ token, apiBaseUrl }) => ({
42
- token: Redacted.make(token),
43
- apiBaseUrl,
44
- })), Effect.orDie));
45
- /**
46
- * Convenience layer from a redacted token + optional base URL. Pass an empty
47
- * token (`""`) for the credential-less OAuth exchange methods.
48
- */
49
- export const credentials = (config) => Layer.succeed(Credentials, Effect.succeed({
50
- token: config.token,
51
- apiBaseUrl: config.apiBaseUrl ?? DEFAULT_API_BASE_URL,
52
- }));
53
- //# sourceMappingURL=credentials.js.map
1
+ export { credentials$Credentials as Credentials, credentials$CredentialsFromEnv as CredentialsFromEnv, credentials$DEFAULT_API_BASE_URL as DEFAULT_API_BASE_URL, credentials$credentials as credentials } from "./_bundle/sdk.js";
package/lib/errors.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Slack-specific error types.
3
3
  *
4
- * Slack reports failures as `{ "ok": false, "error": "<slug>" }` — usually
5
- * with HTTP 200 — so the interesting field is the machine-readable `error`
4
+ * Slack reports failures as `{ "ok": false, "error": "<slug>" }` -- usually
5
+ * with HTTP 200 -- so the interesting field is the machine-readable `error`
6
6
  * slug, not the status. The protocol maps the well-known infrastructure
7
7
  * slugs (auth, throttling, server hiccups) onto core's shared HTTP error
8
8
  * classes and surfaces everything else as {@link SlackError} with the slug
@@ -11,29 +11,29 @@
11
11
  */
12
12
  export { BadGateway, BadRequest, Conflict, ConfigError, Forbidden, GatewayTimeout, InternalServerError, NotFound, ServiceUnavailable, TooManyRequests, Unauthorized, UnprocessableEntity, HTTP_STATUS_MAP, DEFAULT_ERRORS, API_ERRORS, } from "@distilled.cloud/core/errors";
13
13
  import type { DefaultErrors as CoreDefaultErrors } from "@distilled.cloud/core/errors";
14
- import * as Schema from "effect/Schema";
15
- declare const SlackError_base: Schema.Class<SlackError, Schema.TaggedStruct<"SlackError", {
16
- readonly code: Schema.String;
17
- readonly message: Schema.optional<Schema.String>;
18
- readonly needed: Schema.optional<Schema.String>;
19
- readonly provided: Schema.optional<Schema.String>;
20
- readonly messages: Schema.optional<Schema.$Array<Schema.String>>;
21
- }>, import("effect/Cause").YieldableError>;
14
+ import * as Schema from "@distilled.cloud/core/schema-lite-typed";
15
+ declare const SlackError_base: Schema.TaggedErrorClass<"SlackError", {
16
+ readonly code: import("effect/Schema").String;
17
+ readonly message: import("effect/Schema").optional<import("effect/Schema").String>;
18
+ readonly needed: import("effect/Schema").optional<import("effect/Schema").String>;
19
+ readonly provided: import("effect/Schema").optional<import("effect/Schema").String>;
20
+ readonly messages: import("effect/Schema").optional<Schema.$Array<import("effect/Schema").String>>;
21
+ }>;
22
22
  /**
23
23
  * A Slack API error envelope: `ok: false` with a machine-readable slug.
24
- * `code` is the slug (`channel_not_found`, `invalid_blocks`, …) — the field
24
+ * `code` is the slug (`channel_not_found`, `invalid_blocks`, ...) -- the field
25
25
  * to branch on; the per-method slugs are listed in each operation's doc
26
26
  * comment. `needed`/`provided` carry scope detail on `missing_scope`;
27
27
  * `messages` carries the envelope's `response_metadata.messages` (per-field
28
28
  * validation detail on `invalid_arguments`).
29
29
  */
30
- export declare class SlackError extends SlackError_base {
30
+ export declare class SlackError extends /*@__PURE__*/ SlackError_base {
31
31
  }
32
- declare const SlackRateLimited_base: Schema.Class<SlackRateLimited, Schema.TaggedStruct<"SlackRateLimited", {
33
- readonly code: Schema.String;
34
- readonly message: Schema.optional<Schema.String>;
35
- readonly retryAfter: Schema.optional<Schema.declare<import("effect/Duration").Duration, import("effect/Duration").Duration>>;
36
- }>, import("effect/Cause").YieldableError> & (new (...args: any[]) => {
32
+ declare const SlackRateLimited_base: Schema.TaggedErrorClass<"SlackRateLimited", {
33
+ readonly code: import("effect/Schema").String;
34
+ readonly message: import("effect/Schema").optional<import("effect/Schema").String>;
35
+ readonly retryAfter: import("effect/Schema").optional<import("effect/Schema").declare<import("effect/Duration").Duration, import("effect/Duration").Duration>>;
36
+ }> & (new (...args: any[]) => {
37
37
  "@distilled/meta/error-categories": {
38
38
  "@distilled/errors/retryable": true;
39
39
  };
@@ -43,32 +43,32 @@ declare const SlackRateLimited_base: Schema.Class<SlackRateLimited, Schema.Tagge
43
43
  };
44
44
  });
45
45
  /**
46
- * Slack rate limit — a 429 or the `rate_limited`/`ratelimited` slug. Slack
46
+ * Slack rate limit -- a 429 or the `rate_limited`/`ratelimited` slug. Slack
47
47
  * answers with a `Retry-After` header the default retry policy honors.
48
48
  */
49
- export declare class SlackRateLimited extends SlackRateLimited_base {
49
+ export declare class SlackRateLimited extends /*@__PURE__*/ SlackRateLimited_base {
50
50
  }
51
- declare const SlackHttpError_base: Schema.Class<SlackHttpError, Schema.TaggedStruct<"SlackHttpError", {
52
- readonly status: Schema.Number;
53
- readonly message: Schema.String;
54
- readonly body: Schema.optional<Schema.String>;
55
- }>, import("effect/Cause").YieldableError>;
51
+ declare const SlackHttpError_base: Schema.TaggedErrorClass<"SlackHttpError", {
52
+ readonly status: import("effect/Schema").Number;
53
+ readonly message: import("effect/Schema").String;
54
+ readonly body: import("effect/Schema").optional<import("effect/Schema").String>;
55
+ }>;
56
56
  /**
57
- * HTTP error — a non-2xx response without a parseable Slack error envelope
57
+ * HTTP error -- a non-2xx response without a parseable Slack error envelope
58
58
  * (proxy pages, HTML 5xx bodies).
59
59
  */
60
- export declare class SlackHttpError extends SlackHttpError_base {
60
+ export declare class SlackHttpError extends /*@__PURE__*/ SlackHttpError_base {
61
61
  }
62
- declare const SlackParseError_base: Schema.Class<SlackParseError, Schema.TaggedStruct<"SlackParseError", {
63
- readonly body: Schema.Unknown;
64
- readonly cause: Schema.Unknown;
65
- }>, import("effect/Cause").YieldableError> & (new (...args: any[]) => {
62
+ declare const SlackParseError_base: Schema.TaggedErrorClass<"SlackParseError", {
63
+ readonly body: import("effect/Schema").Unknown;
64
+ readonly cause: import("effect/Schema").Unknown;
65
+ }> & (new (...args: any[]) => {
66
66
  "@distilled.cloud/error/categories": {
67
67
  ParseError: true;
68
68
  };
69
69
  });
70
70
  /** Schema parse error wrapper. */
71
- export declare class SlackParseError extends SlackParseError_base {
71
+ export declare class SlackParseError extends /*@__PURE__*/ SlackParseError_base {
72
72
  }
73
73
  /**
74
74
  * Errors any Slack operation may surface in addition to the shared HTTP
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,UAAU,EACV,UAAU,EACV,QAAQ,EACR,WAAW,EACX,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,QAAQ,EACR,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,UAAU,GACX,MAAM,8BAA8B,CAAC;AAGtC,OAAO,KAAK,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEvF,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;;;;;;;;AAExC;;;;;;;GAOG;AACH,qBAAa,UAAW,SAAQ,eAM9B;CAAG;;;;;;;;;;;;;;AAEL;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,qBAIwB;CAAG;;;;;;AAEjE;;;GAGG;AACH,qBAAa,cAAe,SAAQ,mBAIlC;CAAG;;;;;;;;;AAEL,kCAAkC;AAClC,qBAAa,eAAgB,SAAQ,oBAGL;CAAG;AAEnC;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,gBAAgB,GAAG,cAAc,GAAG,eAAe,CAAC;AAE5F;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,iBAAiB,GAAG,YAAY,CAAC"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,UAAU,EACV,UAAU,EACV,QAAQ,EACR,WAAW,EACX,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,QAAQ,EACR,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,UAAU,GACX,MAAM,8BAA8B,CAAC;AAGtC,OAAO,KAAK,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEvF,OAAO,KAAK,MAAM,MAAM,yCAAyC,CAAC;;;;;;;;AAElE;;;;;;;GAOG;AACH,qBAAa,UACX,SAAQ,aAAa,CAAC,eAMpB;CAAG;;;;;;;;;;;;;;AAEP;;;GAGG;AACH,qBAAa,gBACX,SAAQ,aAAa,CAAC,qBAIsD;CAAG;;;;;;AAEjF;;;GAGG;AACH,qBAAa,cACX,SAAQ,aAAa,CAAC,mBAIpB;CAAG;;;;;;;;;AAEP,kCAAkC;AAClC,qBAAa,eACX,SAAQ,aAAa,CAAC,oBAGU;CAAG;AAErC;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,gBAAgB,GAAG,cAAc,GAAG,eAAe,CAAC;AAE5F;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,iBAAiB,GAAG,YAAY,CAAC"}
package/lib/errors.js CHANGED
@@ -1,59 +1 @@
1
- /**
2
- * Slack-specific error types.
3
- *
4
- * Slack reports failures as `{ "ok": false, "error": "<slug>" }` — usually
5
- * with HTTP 200 — so the interesting field is the machine-readable `error`
6
- * slug, not the status. The protocol maps the well-known infrastructure
7
- * slugs (auth, throttling, server hiccups) onto core's shared HTTP error
8
- * classes and surfaces everything else as {@link SlackError} with the slug
9
- * preserved for branching. Each generated operation's doc comment lists the
10
- * slugs that method can produce.
11
- */
12
- export { BadGateway, BadRequest, Conflict, ConfigError, Forbidden, GatewayTimeout, InternalServerError, NotFound, ServiceUnavailable, TooManyRequests, Unauthorized, UnprocessableEntity, HTTP_STATUS_MAP, DEFAULT_ERRORS, API_ERRORS, } from "@distilled.cloud/core/errors";
13
- import * as Category from "@distilled.cloud/core/category";
14
- import { withCategory } from "@distilled.cloud/core/error-category";
15
- import { DurationSchema, RETRYABLE } from "@distilled.cloud/core/errors";
16
- import * as Schema from "effect/Schema";
17
- /**
18
- * A Slack API error envelope: `ok: false` with a machine-readable slug.
19
- * `code` is the slug (`channel_not_found`, `invalid_blocks`, …) — the field
20
- * to branch on; the per-method slugs are listed in each operation's doc
21
- * comment. `needed`/`provided` carry scope detail on `missing_scope`;
22
- * `messages` carries the envelope's `response_metadata.messages` (per-field
23
- * validation detail on `invalid_arguments`).
24
- */
25
- export class SlackError extends Schema.TaggedError()("SlackError", {
26
- code: Schema.String,
27
- message: Schema.optional(Schema.String),
28
- needed: Schema.optional(Schema.String),
29
- provided: Schema.optional(Schema.String),
30
- messages: Schema.optional(Schema.Array(Schema.String)),
31
- }) {
32
- }
33
- /**
34
- * Slack rate limit — a 429 or the `rate_limited`/`ratelimited` slug. Slack
35
- * answers with a `Retry-After` header the default retry policy honors.
36
- */
37
- export class SlackRateLimited extends Schema.TaggedError()("SlackRateLimited", {
38
- code: Schema.String,
39
- message: Schema.optional(Schema.String),
40
- retryAfter: Schema.optional(DurationSchema),
41
- }).pipe(withCategory(RETRYABLE), Category.withThrottlingError) {
42
- }
43
- /**
44
- * HTTP error — a non-2xx response without a parseable Slack error envelope
45
- * (proxy pages, HTML 5xx bodies).
46
- */
47
- export class SlackHttpError extends Schema.TaggedError()("SlackHttpError", {
48
- status: Schema.Number,
49
- message: Schema.String,
50
- body: Schema.optional(Schema.String),
51
- }) {
52
- }
53
- /** Schema parse error wrapper. */
54
- export class SlackParseError extends Schema.TaggedError()("SlackParseError", {
55
- body: Schema.Unknown,
56
- cause: Schema.Unknown,
57
- }).pipe(Category.withParseError) {
58
- }
59
- //# sourceMappingURL=errors.js.map
1
+ export { errors$API_ERRORS as API_ERRORS, errors$BadGateway as BadGateway, errors$BadRequest as BadRequest, errors$ConfigError as ConfigError, errors$Conflict as Conflict, errors$DEFAULT_ERRORS as DEFAULT_ERRORS, errors$Forbidden as Forbidden, errors$GatewayTimeout as GatewayTimeout, errors$HTTP_STATUS_MAP as HTTP_STATUS_MAP, errors$InternalServerError as InternalServerError, errors$NotFound as NotFound, errors$ServiceUnavailable as ServiceUnavailable, errors$SlackError as SlackError, errors$SlackHttpError as SlackHttpError, errors$SlackParseError as SlackParseError, errors$SlackRateLimited as SlackRateLimited, errors$TooManyRequests as TooManyRequests, errors$Unauthorized as Unauthorized, errors$UnprocessableEntity as UnprocessableEntity } from "./_bundle/sdk.js";
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @distilled.cloud/slack — Slack Web API SDK for Effect.
2
+ * @distilled.cloud/slack -- Slack Web API SDK for Effect.
3
3
  *
4
4
  * `./services` is generated by `scripts/generate.ts` from the Smithy models
5
5
  * in `.generated-specs` (written by `scripts/convert.ts` from the JSON twins
package/lib/index.js CHANGED
@@ -1,12 +1,3 @@
1
- /**
2
- * @distilled.cloud/slack — Slack Web API SDK for Effect.
3
- *
4
- * `./services` is generated by `scripts/generate.ts` from the Smithy models
5
- * in `.generated-specs` (written by `scripts/convert.ts` from the JSON twins
6
- * of the docs.slack.dev method reference, which the spec mirror
7
- * `specs/spec-mirror-slack` snapshots). Everything else in this folder is
8
- * hand-written.
9
- */
10
1
  export * from "./credentials.js";
11
2
  export * from "./errors.js";
12
3
  export * as T from "./traits.js";
@@ -14,4 +5,3 @@ export { SlackProtocol } from "./protocol.js";
14
5
  export * as Retry from "./retry.js";
15
6
  export * as Pagination from "./pagination.js";
16
7
  export * from "./services/index.js";
17
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ export * from "./credentials.js";
2
+ export * from "./errors.js";
3
+ export * as T from "./traits.js";
4
+ export { SlackProtocol } from "./protocol.js";
5
+ export * as Retry from "./retry.js";
6
+ export * as Pagination from "./pagination.js";
7
+ export * from "./services.lazy/index.js";
@@ -1,9 +1,9 @@
1
1
  /**
2
- * Slack pagination — hand-written.
2
+ * Slack pagination -- hand-written.
3
3
  *
4
4
  * Slack's cursor convention: pass `cursor` (from the previous response's
5
5
  * `response_metadata.next_cursor`), and an EMPTY `next_cursor` means the
6
- * last page — which is exactly core's cursor traversal (`isTerminalToken`
6
+ * last page -- which is exactly core's cursor traversal (`isTerminalToken`
7
7
  * treats `""` as terminal). Paginated operations are compiled with this
8
8
  * strategy by scripts/generate.ts from the `smithy.api#paginated` traits the
9
9
  * converter stamps.
package/lib/pagination.js CHANGED
@@ -1,31 +1 @@
1
- /**
2
- * Slack pagination — hand-written.
3
- *
4
- * Slack's cursor convention: pass `cursor` (from the previous response's
5
- * `response_metadata.next_cursor`), and an EMPTY `next_cursor` means the
6
- * last page — which is exactly core's cursor traversal (`isTerminalToken`
7
- * treats `""` as terminal). Paginated operations are compiled with this
8
- * strategy by scripts/generate.ts from the `smithy.api#paginated` traits the
9
- * converter stamps.
10
- *
11
- * @example
12
- * ```ts
13
- * import * as Effect from "effect/Effect";
14
- * import * as Stream from "effect/Stream";
15
- * import * as Users from "@distilled.cloud/slack/users";
16
- *
17
- * // Every member, cursors followed automatically:
18
- * const members = Users.list.items({ limit: 200 }).pipe(
19
- * Stream.runCollect,
20
- * );
21
- * // Or page by page:
22
- * const pages = Users.list.pages({ limit: 200 });
23
- * ```
24
- */
25
- import * as Pagination from "@distilled.cloud/core/pagination";
26
- /**
27
- * Cursor traversal for Slack: follow `response_metadata.next_cursor` until
28
- * it comes back empty/absent.
29
- */
30
- export const slackPaginate = (operation, input, pagination) => Pagination.paginateCursor(operation, input, pagination);
31
- //# sourceMappingURL=pagination.js.map
1
+ export { pagination$slackPaginate as slackPaginate } from "./_bundle/sdk.js";
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,2BAA2B,CAAC;AACjD,OAAO,EACL,WAAW,EAMZ,MA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ib/protocol.js CHANGED
@@ -1,231 +1 @@
1
- import * as API from "@distilled.cloud/core/api";
2
- import { ConfigError, GatewayTimeout, HTTP_STATUS_MAP, InternalServerError, ServiceUnavailable, Unauthorized, } from "@distilled.cloud/core/errors";
3
- import { buildRequest, getAnn, getProps, hasPropAnn, mapKeys, matchTypedError, } from "@distilled.cloud/core/protocol-http";
4
- import { unwrapRedactedDeep, wrapSensitive } from "@distilled.cloud/core/protocol-rest";
5
- import { validateResponse } from "@distilled.cloud/core/response-validation";
6
- import { parseRetryAfterForStatus, parseServerRetryHint } from "@distilled.cloud/core/retry-after";
7
- import { httpSymbol, querySymbol } from "@distilled.cloud/core/trait";
8
- /**
9
- * SlackProtocol — hand-written.
10
- *
11
- * Speaks the Slack Web API convention. The generic request/response machinery
12
- * (trait-driven request building, recursive wire-name mapping, typed-error
13
- * matcher evaluation) lives in `@distilled.cloud/core/protocol-http`; this
14
- * module supplies what is Slack's own:
15
- *
16
- * request: credentials → `Authorization: Bearer <token>` (omitted for an
17
- * empty token — the OAuth exchange methods authenticate with
18
- * `client_id`/`client_secret` args instead), and array-valued
19
- * query args joined with commas (`channel_ids=C1,C2` — Slack
20
- * reads comma-separated lists, not repeated params)
21
- *
22
- * response: `{ "ok": true, …payload }` — the payload shares the envelope's
23
- * level, so a successful body maps onto the output schema
24
- * directly (`ok` is a modeled member).
25
- * `{ "ok": false, "error": "<slug>" }` — usually WITH HTTP 200 —
26
- * becomes a typed error: per-op matcher classes first, then the
27
- * infrastructure slugs (auth → Unauthorized, throttling →
28
- * SlackRateLimited, server hiccups → retryable 5xx classes),
29
- * then {@link SlackError} carrying the slug.
30
- * A successful NON-JSON body is returned as raw bytes — the one
31
- * method that answers this way (`admin.analytics.getFile`) sends
32
- * a gzipped NDJSON file.
33
- */
34
- import * as Effect from "effect/Effect";
35
- import * as Layer from "effect/Layer";
36
- import * as Redacted from "effect/Redacted";
37
- import { Credentials } from "./credentials.js";
38
- import { SlackError, SlackHttpError, SlackParseError, SlackRateLimited, } from "./errors.js";
39
- // Bridge: Protocol.decode is typed as Effect<unknown> (no error channel), but
40
- // Slack failures are real typed errors that an operation re-surfaces via its
41
- // `errors: [...]` list. Fail with the instance and erase the error type here;
42
- // `API.make`'s signature reintroduces it for callers.
43
- const fail = (e) => Effect.fail(e);
44
- /**
45
- * Envelope slugs that mean "the token is no good" on ANY method — mapped to
46
- * the shared Unauthorized class so one catch handles credential problems
47
- * across the SDK. Permission-shaped slugs (`missing_scope`, `no_permission`,
48
- * `access_denied`, …) stay {@link SlackError}: they carry method-specific
49
- * detail (`needed`/`provided`) the shared class would drop.
50
- */
51
- const AUTH_SLUGS = new Set([
52
- "not_authed",
53
- "invalid_auth",
54
- "account_inactive",
55
- "token_revoked",
56
- "token_expired",
57
- ]);
58
- /** Envelope slugs that are Slack-side hiccups — retryable server errors. */
59
- const SERVER_SLUGS = {
60
- internal_error: (message) => new InternalServerError({ message }),
61
- fatal_error: (message) => new InternalServerError({ message }),
62
- service_unavailable: (message) => new ServiceUnavailable({ message }),
63
- request_timeout: (message) => new GatewayTimeout({ message }),
64
- };
65
- /**
66
- * Serialize input members the way Slack's wire wants them, before the
67
- * generic request builder runs:
68
- *
69
- * • Array-valued QUERY args join with commas (`channel_ids=C1,C2`) —
70
- * core's default would repeat the param instead.
71
- * • On form-urlencoded operations, every non-scalar body member is
72
- * flattened to the string Slack's form convention reads: ID lists
73
- * comma-joined, rich values (blocks, barrier subjects, datastore items)
74
- * JSON-encoded — core's default is Stripe-style bracket notation, which
75
- * Slack does not speak.
76
- */
77
- const serializeForWire = (input, inputAst) => {
78
- if (input === null || typeof input !== "object" || Array.isArray(input)) {
79
- return input;
80
- }
81
- const isForm = getAnn(inputAst, httpSymbol)?.contentType === "form-urlencoded";
82
- const props = getProps(inputAst);
83
- if (props.length === 0)
84
- return input;
85
- let out;
86
- for (const prop of props) {
87
- const key = String(prop.name);
88
- const value = input[key];
89
- if (value === null || typeof value !== "object")
90
- continue;
91
- const isQuery = hasPropAnn(prop, querySymbol);
92
- if (Array.isArray(value) && (isQuery || isForm)) {
93
- out ??= { ...input };
94
- out[key] = value.every((v) => typeof v !== "object" || v === null)
95
- ? value.join(",")
96
- : JSON.stringify(value);
97
- }
98
- else if (isForm && !isQuery) {
99
- out ??= { ...input };
100
- out[key] = JSON.stringify(value);
101
- }
102
- }
103
- return out ?? input;
104
- };
105
- // The protocol layer is memoized per process by `API.make` (see
106
- // `OperationConfig.protocol`), so the build must not capture credentials —
107
- // `encode` resolves Credentials from the calling fiber's context on every
108
- // request instead. Like the error channel above, the requirement is erased at
109
- // this boundary (Protocol effects are typed with no requirements) and
110
- // reintroduced for callers by the generated `SlackOpContext` annotations.
111
- const encode = ({ input, inputAst }) => Effect.gen(function* () {
112
- const resolveCredentials = yield* Credentials;
113
- const creds = yield* resolveCredentials;
114
- const token = Redacted.value(creds.token);
115
- return buildRequest({
116
- input: serializeForWire(unwrapRedactedDeep(input), inputAst),
117
- inputAst,
118
- baseUrl: creds.apiBaseUrl,
119
- // An empty token means a credential-less call (the OAuth exchange
120
- // methods) — no Authorization header at all.
121
- headers: token === "" ? {} : { authorization: `Bearer ${token}` },
122
- });
123
- });
124
- const decode = ({ response, outputAst, errors: errorClasses, }) => Effect.gen(function* () {
125
- // Read as BYTES first: the analytics export answers a successful call
126
- // with a gzipped file, which a text read would corrupt. Everything else
127
- // decodes from the same buffer.
128
- const bytes = new Uint8Array(yield* response.arrayBuffer.pipe(Effect.orDie));
129
- const text = new TextDecoder().decode(bytes);
130
- if (process.env.DISTILLED_DEBUG_HTTP) {
131
- console.error(`[distilled] <- ${response.status} ${text.slice(0, 400)}`);
132
- }
133
- let json;
134
- if (text.trim().length > 0) {
135
- try {
136
- const parsed = JSON.parse(text);
137
- if (parsed !== null && typeof parsed === "object") {
138
- json = parsed;
139
- }
140
- }
141
- catch {
142
- // non-JSON — a binary success payload or an HTML error page
143
- }
144
- }
145
- const status = response.status;
146
- const headers = response.headers;
147
- // Slack reports failures as `ok: false`, usually WITH HTTP 200 — a
148
- // non-2xx status without an envelope (proxy pages) is also a failure.
149
- const failed = status >= 400 || json?.ok === false;
150
- if (failed) {
151
- const slug = typeof json?.error === "string" ? json.error : undefined;
152
- // `response_metadata.messages` carries per-field validation detail
153
- // (e.g. `invalid_arguments`); some envelopes use a bare `errors` list.
154
- const detailMessages = [
155
- ...(json?.response_metadata?.messages ?? []),
156
- ...(Array.isArray(json?.errors) ? json.errors : []),
157
- ].filter((m) => typeof m === "string");
158
- const message = detailMessages[0] ??
159
- slug ??
160
- (json === undefined && text.trim() ? text.trim() : `HTTP ${status}`);
161
- // 1. Per-operation typed error (matcher metadata on the class — none
162
- // are generated today, but model patches can add them). Slack's
163
- // error codes are string slugs, and matcher `code`s are numeric —
164
- // a patch-declared class matches on `status`/`message` instead
165
- // (`message` is the slug when the envelope carries no detail).
166
- const typed = matchTypedError(errorClasses, status, [{ message }], {
167
- body: json === undefined ? text : json,
168
- headers,
169
- });
170
- if (typed !== undefined)
171
- return yield* fail(typed);
172
- // 2. Throttling — the 429 or its envelope spellings.
173
- if (status === 429 || slug === "rate_limited" || slug === "ratelimited") {
174
- return yield* fail(new SlackRateLimited({
175
- code: slug ?? "rate_limited",
176
- message,
177
- retryAfter: parseServerRetryHint(headers),
178
- }));
179
- }
180
- // 3. Infrastructure slugs: credential problems and Slack-side hiccups.
181
- if (slug !== undefined && AUTH_SLUGS.has(slug)) {
182
- return yield* fail(new Unauthorized({ message: slug }));
183
- }
184
- if (slug !== undefined && slug in SERVER_SLUGS) {
185
- return yield* fail(SERVER_SLUGS[slug](message));
186
- }
187
- // 4. Any other envelope slug → SlackError, the slug preserved.
188
- if (slug !== undefined) {
189
- return yield* fail(new SlackError({
190
- code: slug,
191
- ...(message !== slug ? { message } : {}),
192
- ...(typeof json?.needed === "string" ? { needed: json.needed } : {}),
193
- ...(typeof json?.provided === "string" ? { provided: json.provided } : {}),
194
- ...(detailMessages.length > 0 ? { messages: detailMessages } : {}),
195
- }));
196
- }
197
- // 5. No envelope at all: HTTP-status classes / retryable 5xx / raw.
198
- const StatusErrorClass = HTTP_STATUS_MAP[status];
199
- if (StatusErrorClass) {
200
- return yield* fail(new StatusErrorClass({
201
- message,
202
- retryAfter: parseRetryAfterForStatus(status, headers),
203
- }));
204
- }
205
- if (status >= 500) {
206
- return yield* fail(new InternalServerError({
207
- message,
208
- retryAfter: parseRetryAfterForStatus(status, headers),
209
- }));
210
- }
211
- return yield* fail(new SlackHttpError({ status, message, body: text.slice(0, 2000) }));
212
- }
213
- // Successful non-JSON body: raw bytes (the analytics file download —
214
- // modeled as a Document output, so the bytes pass through verbatim).
215
- // Strict mode fails them for every other (struct) output.
216
- if (json === undefined) {
217
- return yield* validateResponse(outputAst, bytes, (cause) => new SlackParseError({ body: text, cause })).pipe(Effect.catch(fail));
218
- }
219
- // 2xx envelope: the body IS the payload (`ok` rides along as a modeled
220
- // member). Wire→TS key mapping is schema-driven; sensitive members
221
- // (OAuth access/refresh tokens) wrap in Redacted. Strict mode checks the
222
- // mapped payload against the output schema first.
223
- const mapped = yield* validateResponse(outputAst, mapKeys(outputAst, json, "decode"), (cause) => new SlackParseError({ body: json, cause })).pipe(Effect.catch(fail));
224
- return wrapSensitive(outputAst, mapped);
225
- });
226
- export const SlackProtocol = Layer.succeed(API.Protocol, API.Protocol.of({
227
- // Erase encode's Credentials requirement (see comment above).
228
- encode: (args) => encode(args),
229
- decode,
230
- }));
231
- //# sourceMappingURL=protocol.js.map
1
+ export { protocol$SlackProtocol as SlackProtocol } from "./_bundle/sdk.js";