@distilled.cloud/discord 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.
- package/lib/.lazy.json +1 -0
- package/lib/_bundle/lazy.js +4 -0
- package/lib/_bundle/sdk.js +2 -0
- package/lib/_bundle/sdk.js.map +1 -0
- package/lib/credentials.d.ts +3 -3
- package/lib/credentials.d.ts.map +1 -1
- package/lib/credentials.js +1 -51
- package/lib/errors.d.ts +14 -14
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -31
- package/lib/index.d.ts +1 -1
- package/lib/index.js +0 -8
- package/lib/index.lazy.js +6 -0
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +1 -80
- package/lib/retry.d.ts +2 -2
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +1 -45
- package/lib/services/discord.d.ts +4 -1507
- package/lib/services/discord.d.ts.map +1 -1
- package/lib/services/discord.js +331 -11339
- package/lib/services/discord.js.map +1 -1
- package/lib/services/index.js +0 -2
- package/lib/services.lazy/discord.js +4 -0
- package/lib/services.lazy/index.js +3 -0
- package/lib/traits.d.ts +1 -1
- package/lib/traits.js +1 -11
- package/package.json +9 -7
- package/src/credentials.ts +25 -22
- package/src/errors.ts +11 -15
- package/src/index.ts +1 -1
- package/src/protocol.ts +5 -8
- package/src/retry.ts +6 -6
- package/src/services/discord.ts +10028 -14675
- package/src/traits.ts +1 -1
- package/lib/credentials.js.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/protocol.js.map +0 -1
- package/lib/retry.js.map +0 -1
- package/lib/services/index.js.map +0 -1
- package/lib/traits.js.map +0 -1
- /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,2 @@
|
|
|
1
|
+
import{api$D as e,api$call as t,api$error as n,api$named as ee,api$newError as te,api$op as ne,category$withBadRequestError as r,category$withParseError as i,category$withServerError as re,config$Redacted as a,config$String as o,config$all as ie,config$orElse as ae,config$withDefault as s,retry$capped as c,retry$jittered as l,retry$makeDefault as u,retry$throttlingFactory as d,retry$throttlingOptions as f,retry$transientFactory as p,retry$transientOptions as m,trait$Body as h,trait$FormDataFile as g,trait$Header as _,trait$Http as v,trait$HttpBody as y,trait$KeyDictionary as b,trait$Label as x,trait$Query as S,trait$ResponseCode as C,trait$UnionCases as w,trait$applyErrorMatchers as T,trait$bodySymbol as E,trait$errorMatchersSymbol as D,trait$formDataFileSymbol as O,trait$getErrorMatchers as k,trait$headerSymbol as A,trait$httpBodySymbol as j,trait$httpSymbol as M,trait$keyDictionarySymbol as N,trait$labelSymbol as P,trait$querySymbol as F,trait$responseCodeSymbol as I,trait$unionCasesSymbol as L}from"@distilled.cloud/core/_bundle/base";import{errors$API_ERRORS as R,errors$BadGateway as z,errors$BadRequest as B,errors$ConfigError as V,errors$Conflict as H,errors$DEFAULT_ERRORS as U,errors$Forbidden as W,errors$GatewayTimeout as G,errors$HTTP_STATUS_MAP as K,errors$InternalServerError as q,errors$Locked as J,errors$NotFound as oe,errors$ServiceUnavailable as se,errors$TooManyRequests as ce,errors$Unauthorized as le,errors$UnprocessableEntity as ue,protocol_rest$RawResponse as de,protocol_rest$RawResponseRoot as fe,protocol_rest$SensitiveValue as pe,protocol_rest$makeRestProtocol as me,protocol_rest$rawResponseRootSymbol as he,protocol_rest$rawResponseSymbol as ge,protocol_rest$sensitiveValueSymbol as _e,schema_lite$Array as ve,schema_lite$Boolean as ye,schema_lite$NullOr as be,schema_lite$Number as xe,schema_lite$Record as Se,schema_lite$String as Ce,schema_lite$Struct as we,schema_lite$TaggedError as Te,schema_lite$Unknown as Ee,schema_lite$at as De,schema_lite$optional as Oe,schema_lite$suspend as ke}from"@distilled.cloud/core/_bundle/rest";import*as Y from"effect/Context";import*as X from"effect/Effect";import*as Z from"effect/Layer";import*as Ae from"effect/Redacted";import*as Q from"@distilled.cloud/core/schema-lite-typed";const $=`https://discord.com/api/v10`;var Credentials=class extends (/*@__PURE__*/ Y.Service()(`DiscordCredentials`)){};const je=/*@__PURE__*/ ie({token:/*@__PURE__*/ a(`DISCORD_BOT_TOKEN`).pipe(/*@__PURE__*/ ae(()=>a(`DISCORD_TOKEN`))),tokenType:/*@__PURE__*/ o(`DISCORD_TOKEN_TYPE`).pipe(/*@__PURE__*/ s(`Bot`)),apiBaseUrl:/*@__PURE__*/ o(`DISCORD_API_URL`).pipe(/*@__PURE__*/ s($))});const Me=/*@__PURE__*/ Z.succeed(Credentials,/*@__PURE__*/ je.pipe(/*@__PURE__*/ X.mapError(()=>new V({message:`DISCORD_BOT_TOKEN (or DISCORD_TOKEN) environment variable is required`})),/*@__PURE__*/ X.map(({token:e,tokenType:t,apiBaseUrl:n})=>({token:e,tokenType:t.toLowerCase()===`bearer`?`Bearer`:`Bot`,apiBaseUrl:n})),X.orDie));const credentials=e=>Z.succeed(Credentials,X.succeed({token:e.token,tokenType:e.tokenType??`Bot`,apiBaseUrl:e.apiBaseUrl??`https://discord.com/api/v10`}));var UnknownDiscordError=class extends (/*@__PURE__*/ Q.TaggedError()(`UnknownDiscordError`,{code:/*@__PURE__*/ Q.optional(Q.Number),message:/*@__PURE__*/ Q.optional(Q.String),errors:/*@__PURE__*/ Q.optional(Q.Unknown),body:Q.Unknown}).pipe(re)){};var DiscordParseError=class extends (/*@__PURE__*/ Q.TaggedError()(`DiscordParseError`,{body:Q.Unknown,cause:Q.Unknown}).pipe(i)){};const errorEnvelope=e=>{if(e===null||typeof e!==`object`)return void 0;const t=e;const n=typeof t.message===`string`?t.message:typeof t.error_description===`string`?t.error_description:typeof t.error===`string`?t.error:void 0;return{code:typeof t.code===`number`||typeof t.code===`string`?t.code:void 0,message:n}};const errorDetails=e=>{if(e===null||typeof e!==`object`)return void 0;return e.errors};const numericCode=e=>{if(typeof e===`number`)return Number.isFinite(e)?e:void 0;if(typeof e!==`string`||e.trim()===``)return void 0;const t=Number(e);return Number.isFinite(t)?t:void 0};const Ne=/*@__PURE__*/ me({credentials:/*@__PURE__*/ X.flatMap(Credentials,e=>e),baseUrl:e=>e.apiBaseUrl,headers:e=>({Authorization:`${e.tokenType} ${Ae.value(e.token)}`}),errorEnvelope,unknownError:({code:e,message:t,body:n})=>new UnknownDiscordError({code:numericCode(e),message:t,errors:errorDetails(n),body:n}),parseError:({body:e,cause:t})=>new DiscordParseError({body:e,cause:t})});var Retry=class extends (/*@__PURE__*/ Y.Service()(`DiscordRetry`)){};const policy=e=>X.provide(Z.succeed(Retry,e));const Pe=/*@__PURE__*/ X.provide(/*@__PURE__*/ Z.succeed(Retry,{while:()=>false}));const Fe=u;const Ie=l;const Le=c;const Re=f;const ze=/*@__PURE__*/ policy(d);const Be=m;const Ve=/*@__PURE__*/ policy(p);export{te as _,Se as a,Te as c,Credentials as credentials$Credentials,Me as credentials$CredentialsFromEnv,$ as credentials$DEFAULT_API_BASE_URL,credentials as credentials$credentials,Oe as d,R as errors$API_ERRORS,z as errors$BadGateway,B as errors$BadRequest,V as errors$ConfigError,H as errors$Conflict,U as errors$DEFAULT_ERRORS,DiscordParseError as errors$DiscordParseError,W as errors$Forbidden,G as errors$GatewayTimeout,K as errors$HTTP_STATUS_MAP,q as errors$InternalServerError,J as errors$Locked,oe as errors$NotFound,se as errors$ServiceUnavailable,ce as errors$TooManyRequests,le as errors$Unauthorized,UnknownDiscordError as errors$UnknownDiscordError,ue as errors$UnprocessableEntity,ke as f,ee as g,n as h,xe as i,Ee as l,t as m,ye as n,Ce as o,e as p,Ne as protocol$DiscordProtocol,be as r,Retry as retry$Retry,Le as retry$capped,Ie as retry$jittered,Fe as retry$makeDefault,Pe as retry$none,policy as retry$policy,ze as retry$throttling,Re as retry$throttlingOptions,Ve as retry$transient,Be as retry$transientOptions,we as s,ve as t,h as traits$Body,g as traits$FormDataFile,_ as traits$Header,v as traits$Http,y as traits$HttpBody,b as traits$KeyDictionary,x as traits$Label,S as traits$Query,de as traits$RawResponse,fe as traits$RawResponseRoot,C as traits$ResponseCode,pe as traits$SensitiveValue,w as traits$UnionCases,T as traits$applyErrorMatchers,E as traits$bodySymbol,D as traits$errorMatchersSymbol,O as traits$formDataFileSymbol,k as traits$getErrorMatchers,A as traits$headerSymbol,j as traits$httpBodySymbol,M as traits$httpSymbol,N as traits$keyDictionarySymbol,P as traits$labelSymbol,F as traits$querySymbol,he as traits$rawResponseRootSymbol,ge as traits$rawResponseSymbol,I as traits$responseCodeSymbol,_e as traits$sensitiveValueSymbol,L as traits$unionCasesSymbol,De as u,ne as v,r as y};
|
|
2
|
+
//# sourceMappingURL=sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","names":["EffectConfig.Redacted","Category.withServerError","Category.withParseError","Retries.makeDefault","Retries.jittered","Retries.capped","Retries.throttlingOptions","Retries.throttlingFactory","Retries.transientOptions","Retries.transientFactory","D","call","error","named","newError","op","withBadRequestError","withParseError","withServerError","Redacted$2","String$1","all$1","orElse","withDefault","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","API_ERRORS","BadGateway","BadRequest","ConfigError","Conflict","DEFAULT_ERRORS","Forbidden","GatewayTimeout","HTTP_STATUS_MAP","InternalServerError","Locked","NotFound","ServiceUnavailable","TooManyRequests","Unauthorized","UnprocessableEntity","RawResponse","RawResponseRoot","SensitiveValue","makeRestProtocol","rawResponseRootSymbol","rawResponseSymbol","sensitiveValueSymbol","Array","Boolean","NullOr","Number$1","Record","String","Struct","TaggedError","Unknown","at","optional","suspend","Context","Effect","Layer","Redacted","Schema","DEFAULT_API_BASE_URL","envConfig","CredentialsFromEnv","tokenType","config","body","b","message","code","n","DiscordProtocol","resolve","creds","optionsOrFactory","none","makeDefault","jittered","capped","throttlingOptions","throttling","transientOptions","transient"],"sources":["../../src/credentials.ts","../../src/errors.ts","../../src/protocol.ts","../../src/retry.ts"],"mappings":"2tEA0BA,MAAa8F,EAAuB,8BAWpC,IAAa,YAAb,eACwB,gBAAQ,QAA4C,CAAC,CACzE,oBACF,EAAA,AAAE,CAAC,EAEL,MAAMC,GAA0B,iBAAiB,CAG/C,MAAqB,gBAAsB,mBAAmB,CAAC,CAAC,KAChD,qBAA0B/F,EAAsB,eAAe,CAAC,CAChF,EACA,UAAyB,gBAAoB,oBAAoB,CAAC,CAAC,KACnD,gBAAyB,KAAK,CAC9C,EACA,WAA0B,gBAAoB,iBAAiB,CAAC,CAAC,KACjD,gBAAyB8F,CAAoB,CAC7D,CACF,CAAC,EAED,MAAaE,GAAmC,gBAAM,QACpD,YACc,iBAAU,KACR,gBAAO,aAEjB,IAAIvC,EAAY,CACd,QAAS,uEACX,CAAC,CACL,EACc,gBAAO,KAAK,CAAE,QAAO,YAAW,iBAAkB,CAC9D,QAGA,UAAYwC,EAAU,YAAY,IAAM,SAAW,SAAW,MAC9D,YACF,EAAE,EACFP,EAAO,KACT,CACF,EAGA,MAAa,YAAe,GAK1BC,EAAM,QACJ,YACAD,EAAO,QAAQ,CACb,MAAOQ,EAAO,MACd,UAAWA,EAAO,WAAa,MAC/B,WAAYA,EAAO,YAAA,6BACrB,CAAC,CACH,ECrDF,IAAa,oBAAb,eACwB,gBAAO,YAAiC,CAAC,CAAC,sBAAuB,CACrF,KAAoB,gBAAO,SAASL,EAAO,MAAM,EACjD,QAAuB,gBAAO,SAASA,EAAO,MAAM,EACpD,OAAsB,gBAAO,SAASA,EAAO,OAAO,EACpD,KAAMA,EAAO,OACf,CAAC,CAAC,CAAC,KAAK5F,EAAwB,EAAA,AAAE,CAAC,EAGrC,IAAa,kBAAb,eACwB,gBAAO,YAA+B,CAAC,CAAC,oBAAqB,CACjF,KAAM4F,EAAO,QACb,MAAOA,EAAO,OAChB,CAAC,CAAC,CAAC,KAAK3F,CAAuB,EAAA,AAAE,CAAC,ECRpC,MAAM,cAAiB,GAAiD,CACtE,GAAIiG,IAAS,MAAQ,OAAOA,IAAS,SAAU,OAAO,IAAA,GACtD,MAAMC,EAAID,EACV,MAAME,EACJ,OAAOD,EAAE,UAAY,SACjBA,EAAE,QACF,OAAOA,EAAE,oBAAsB,SAC7BA,EAAE,kBACF,OAAOA,EAAE,QAAU,SACjBA,EAAE,MACF,IAAA,GAEV,MAAO,CAAE,KADI,OAAOA,EAAE,OAAS,UAAY,OAAOA,EAAE,OAAS,SAAWA,EAAE,KAAO,IAAA,GAClE,SAAQ,CACzB,EAGA,MAAM,aAAgB,GAA2B,CAC/C,GAAID,IAAS,MAAQ,OAAOA,IAAS,SAAU,OAAO,IAAA,GACtD,OAAQA,EAAiC,MAC3C,EAQA,MAAM,YAAe,GAA0D,CAC7E,GAAI,OAAOG,IAAS,SAAU,OAAO,OAAO,SAASA,CAAI,EAAIA,EAAO,IAAA,GACpE,GAAI,OAAOA,IAAS,UAAYA,EAAK,KAAK,IAAM,GAAI,OAAO,IAAA,GAC3D,MAAMC,EAAI,OAAOD,CAAI,EACrB,OAAO,OAAO,SAASC,CAAC,EAAIA,EAAI,IAAA,EAClC,EAEA,MAAaC,GAA2D,iBAAyB,CAI/F,YAA2B,gBAAO,QAAQ,YAAc,GAAYC,CAAO,EAC3E,QAAU,GAAUC,EAAM,WAC1B,QAAU,IAAW,CACnB,cAAe,GAAGA,EAAM,UAAU,GAAGd,GAAS,MAAMc,EAAM,KAAK,GACjE,GACA,cACA,cAAe,CAAE,OAAM,UAAS,UAC9B,IAAI,oBAAoB,CACtB,KAAM,YAAYJ,CAAI,EACtB,UACA,OAAQ,aAAaH,CAAI,EACzB,MACF,CAAC,EACH,YAAa,CAAE,OAAM,WAAY,IAAI,kBAAkB,CAAE,OAAM,OAAM,CAAC,CACxE,CAAC,EClED,IAAa,MAAb,eAAyC,gBAAQ,QAAuB,CAAC,CAAC,cAAc,EAAA,AAAE,CAAC,EAG3F,MAAa,OAOR,GAAwCT,EAAO,QAAQC,EAAM,QAAQ,MAAOgB,CAAgB,CAAC,EAGlG,MAAaC,GAE+C,gBAAO,QACnD,gBAAM,QAAQ,MAAO,CAAE,UAAa,KAAM,CAAC,CAC3D,EAOA,MAAaC,GAAuB1G,EAEpC,MAAa2G,GAAW1G,EACxB,MAAa2G,GAAS1G,EAGtB,MAAa2G,GAA6B1G,EAG1C,MAAa2G,GAE+C,qBAAO1G,CAAyB,EAG5F,MAAa2G,GAA4B1G,EAGzC,MAAa2G,GAE+C,qBAAO1G,CAAwB"}
|
package/lib/credentials.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ import * as Layer from "effect/Layer";
|
|
|
4
4
|
import * as Redacted from "effect/Redacted";
|
|
5
5
|
/**
|
|
6
6
|
* Discord HTTP API base URL. The trailing `/v10` is the API version the spec
|
|
7
|
-
* submodule describes
|
|
7
|
+
* submodule describes -- override via `DISCORD_API_URL` only to point at a
|
|
8
8
|
* proxy, not to change versions (the generated operations are v10-shaped).
|
|
9
9
|
*/
|
|
10
10
|
export declare const DEFAULT_API_BASE_URL = "https://discord.com/api/v10";
|
|
11
|
-
/** Authorization header prefix
|
|
11
|
+
/** Authorization header prefix -- see the module doc. */
|
|
12
12
|
export type TokenType = "Bot" | "Bearer";
|
|
13
13
|
export interface Config {
|
|
14
14
|
readonly token: Redacted.Redacted<string>;
|
|
@@ -16,7 +16,7 @@ export interface Config {
|
|
|
16
16
|
readonly apiBaseUrl: string;
|
|
17
17
|
}
|
|
18
18
|
declare const Credentials_base: Context.ServiceClass<Credentials, "DiscordCredentials", Effect.Effect<Config, never, never>>;
|
|
19
|
-
export declare class Credentials extends Credentials_base {
|
|
19
|
+
export declare class Credentials extends /*@__PURE__*/ Credentials_base {
|
|
20
20
|
}
|
|
21
21
|
export declare const CredentialsFromEnv: Layer.Layer<Credentials, never, never>;
|
|
22
22
|
/** Convenience layer from a redacted token + optional token type / base URL. */
|
package/lib/credentials.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAE5C;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,gCAAgC,CAAC;AAElE,
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAE5C;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,gCAAgC,CAAC;AAElE,yDAAyD;AACzD,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,QAAQ,CAAC;AAEzC,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;;AAED,qBAAa,WACX,SAAQ,aAAa,CAAC,gBAErB;CAAG;AAgBN,eAAO,MAAM,kBAAkB,wCAkB9B,CAAC;AAEF,gFAAgF;AAChF,eAAO,MAAM,WAAW,WAAY;IAClC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;IAC/B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B,KAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAQxB,CAAC"}
|
package/lib/credentials.js
CHANGED
|
@@ -1,51 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Discord credentials — hand-written.
|
|
4
|
-
*
|
|
5
|
-
* The `Credentials` service resolves `{ token, tokenType, apiBaseUrl }` per
|
|
6
|
-
* request; the protocol layer formats the `Authorization: <tokenType> <token>`
|
|
7
|
-
* header from it.
|
|
8
|
-
*
|
|
9
|
-
* Discord authorizes HTTP API calls two ways, distinguished by the token
|
|
10
|
-
* prefix (https://discord.com/developers/docs/reference#authentication):
|
|
11
|
-
* • `Bot <token>` — a bot token from the application's Bot page (the
|
|
12
|
-
* default; what almost every server-side integration uses)
|
|
13
|
-
* • `Bearer <token>` — an OAuth2 access token, for calls made on behalf of
|
|
14
|
-
* a user (`/users/@me`, `/users/@me/guilds`, …)
|
|
15
|
-
*/
|
|
16
|
-
import * as EffectConfig from "effect/Config";
|
|
17
|
-
import * as Context from "effect/Context";
|
|
18
|
-
import * as Effect from "effect/Effect";
|
|
19
|
-
import * as Layer from "effect/Layer";
|
|
20
|
-
import * as Redacted from "effect/Redacted";
|
|
21
|
-
/**
|
|
22
|
-
* Discord HTTP API base URL. The trailing `/v10` is the API version the spec
|
|
23
|
-
* submodule describes — override via `DISCORD_API_URL` only to point at a
|
|
24
|
-
* proxy, not to change versions (the generated operations are v10-shaped).
|
|
25
|
-
*/
|
|
26
|
-
export const DEFAULT_API_BASE_URL = "https://discord.com/api/v10";
|
|
27
|
-
export class Credentials extends Context.Service()("DiscordCredentials") {
|
|
28
|
-
}
|
|
29
|
-
const envConfig = EffectConfig.all({
|
|
30
|
-
// DISCORD_BOT_TOKEN is the spelling discord.js and most hosting platforms
|
|
31
|
-
// use; DISCORD_TOKEN is the fallback.
|
|
32
|
-
token: EffectConfig.Redacted("DISCORD_BOT_TOKEN").pipe(EffectConfig.orElse(() => EffectConfig.Redacted("DISCORD_TOKEN"))),
|
|
33
|
-
tokenType: EffectConfig.String("DISCORD_TOKEN_TYPE").pipe(EffectConfig.withDefault("Bot")),
|
|
34
|
-
apiBaseUrl: EffectConfig.String("DISCORD_API_URL").pipe(EffectConfig.withDefault(DEFAULT_API_BASE_URL)),
|
|
35
|
-
});
|
|
36
|
-
export const CredentialsFromEnv = Layer.succeed(Credentials, envConfig.pipe(Effect.mapError(() => new ConfigError({
|
|
37
|
-
message: "DISCORD_BOT_TOKEN (or DISCORD_TOKEN) environment variable is required",
|
|
38
|
-
})), Effect.map(({ token, tokenType, apiBaseUrl }) => ({
|
|
39
|
-
token,
|
|
40
|
-
// Anything but an explicit `Bearer` means a bot token — the OAuth2
|
|
41
|
-
// flavor is the opt-in.
|
|
42
|
-
tokenType: (tokenType.toLowerCase() === "bearer" ? "Bearer" : "Bot"),
|
|
43
|
-
apiBaseUrl,
|
|
44
|
-
})), Effect.orDie));
|
|
45
|
-
/** Convenience layer from a redacted token + optional token type / base URL. */
|
|
46
|
-
export const credentials = (config) => Layer.succeed(Credentials, Effect.succeed({
|
|
47
|
-
token: config.token,
|
|
48
|
-
tokenType: config.tokenType ?? "Bot",
|
|
49
|
-
apiBaseUrl: config.apiBaseUrl ?? DEFAULT_API_BASE_URL,
|
|
50
|
-
}));
|
|
51
|
-
//# 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
|
@@ -6,37 +6,37 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { BadGateway, BadRequest, Conflict, ConfigError, Forbidden, GatewayTimeout, InternalServerError, Locked, NotFound, ServiceUnavailable, TooManyRequests, Unauthorized, UnprocessableEntity, HTTP_STATUS_MAP, DEFAULT_ERRORS, API_ERRORS, } from "@distilled.cloud/core/errors";
|
|
8
8
|
import type { DefaultErrors as CoreDefaultErrors } from "@distilled.cloud/core/errors";
|
|
9
|
-
import * as Schema from "
|
|
10
|
-
declare const UnknownDiscordError_base: Schema.
|
|
11
|
-
readonly code: Schema.optional<Schema.Number>;
|
|
12
|
-
readonly message: Schema.optional<Schema.String>;
|
|
13
|
-
readonly errors: Schema.optional<Schema.Unknown>;
|
|
14
|
-
readonly body: Schema.Unknown;
|
|
15
|
-
}
|
|
9
|
+
import * as Schema from "@distilled.cloud/core/schema-lite-typed";
|
|
10
|
+
declare const UnknownDiscordError_base: Schema.TaggedErrorClass<"UnknownDiscordError", {
|
|
11
|
+
readonly code: import("effect/Schema").optional<import("effect/Schema").Number>;
|
|
12
|
+
readonly message: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
13
|
+
readonly errors: import("effect/Schema").optional<import("effect/Schema").Unknown>;
|
|
14
|
+
readonly body: import("effect/Schema").Unknown;
|
|
15
|
+
}> & (new (...args: any[]) => {
|
|
16
16
|
"@distilled.cloud/error/categories": {
|
|
17
17
|
ServerError: true;
|
|
18
18
|
};
|
|
19
19
|
});
|
|
20
20
|
/**
|
|
21
|
-
* Unknown Discord error
|
|
21
|
+
* Unknown Discord error -- returned when a failed response's HTTP status has
|
|
22
22
|
* no mapped error class. `code` is Discord's own JSON error code (e.g. 50001
|
|
23
23
|
* "Missing Access"), which is far more specific than the HTTP status and is
|
|
24
24
|
* the field worth branching on; `errors` carries the per-field validation
|
|
25
25
|
* detail Discord attaches to 400s. See
|
|
26
26
|
* https://discord.com/developers/docs/topics/opcodes-and-status-codes#json.
|
|
27
27
|
*/
|
|
28
|
-
export declare class UnknownDiscordError extends UnknownDiscordError_base {
|
|
28
|
+
export declare class UnknownDiscordError extends /*@__PURE__*/ UnknownDiscordError_base {
|
|
29
29
|
}
|
|
30
|
-
declare const DiscordParseError_base: Schema.
|
|
31
|
-
readonly body: Schema.Unknown;
|
|
32
|
-
readonly cause: Schema.Unknown;
|
|
33
|
-
}
|
|
30
|
+
declare const DiscordParseError_base: Schema.TaggedErrorClass<"DiscordParseError", {
|
|
31
|
+
readonly body: import("effect/Schema").Unknown;
|
|
32
|
+
readonly cause: import("effect/Schema").Unknown;
|
|
33
|
+
}> & (new (...args: any[]) => {
|
|
34
34
|
"@distilled.cloud/error/categories": {
|
|
35
35
|
ParseError: true;
|
|
36
36
|
};
|
|
37
37
|
});
|
|
38
38
|
/** Schema parse error wrapper. */
|
|
39
|
-
export declare class DiscordParseError extends DiscordParseError_base {
|
|
39
|
+
export declare class DiscordParseError extends /*@__PURE__*/ DiscordParseError_base {
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Errors any Discord operation may surface in addition to the shared HTTP
|
package/lib/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,UAAU,EACV,UAAU,EACV,QAAQ,EACR,WAAW,EACX,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,MAAM,EACN,QAAQ,EACR,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,UAAU,GACX,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACvF,OAAO,KAAK,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,UAAU,EACV,UAAU,EACV,QAAQ,EACR,WAAW,EACX,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,MAAM,EACN,QAAQ,EACR,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,UAAU,GACX,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACvF,OAAO,KAAK,MAAM,MAAM,yCAAyC,CAAC;;;;;;;;;;;AAElE;;;;;;;GAOG;AACH,qBAAa,mBACX,SAAQ,aAAa,CAAC,wBAKW;CAAG;;;;;;;;;AAEtC,kCAAkC;AAClC,qBAAa,iBACX,SAAQ,aAAa,CAAC,sBAGU;CAAG;AAErC;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,mBAAmB,GAAG,iBAAiB,CAAC;AAEnE;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,iBAAiB,GAAG,YAAY,CAAC"}
|
package/lib/errors.js
CHANGED
|
@@ -1,31 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Discord-specific error types.
|
|
3
|
-
*
|
|
4
|
-
* Re-exports the common HTTP errors from core and adds the Discord-specific
|
|
5
|
-
* unknown-error and parse-error wrappers.
|
|
6
|
-
*/
|
|
7
|
-
export { BadGateway, BadRequest, Conflict, ConfigError, Forbidden, GatewayTimeout, InternalServerError, Locked, NotFound, ServiceUnavailable, TooManyRequests, Unauthorized, UnprocessableEntity, HTTP_STATUS_MAP, DEFAULT_ERRORS, API_ERRORS, } from "@distilled.cloud/core/errors";
|
|
8
|
-
import * as Category from "@distilled.cloud/core/category";
|
|
9
|
-
import * as Schema from "effect/Schema";
|
|
10
|
-
/**
|
|
11
|
-
* Unknown Discord error — returned when a failed response's HTTP status has
|
|
12
|
-
* no mapped error class. `code` is Discord's own JSON error code (e.g. 50001
|
|
13
|
-
* "Missing Access"), which is far more specific than the HTTP status and is
|
|
14
|
-
* the field worth branching on; `errors` carries the per-field validation
|
|
15
|
-
* detail Discord attaches to 400s. See
|
|
16
|
-
* https://discord.com/developers/docs/topics/opcodes-and-status-codes#json.
|
|
17
|
-
*/
|
|
18
|
-
export class UnknownDiscordError extends Schema.TaggedError()("UnknownDiscordError", {
|
|
19
|
-
code: Schema.optional(Schema.Number),
|
|
20
|
-
message: Schema.optional(Schema.String),
|
|
21
|
-
errors: Schema.optional(Schema.Unknown),
|
|
22
|
-
body: Schema.Unknown,
|
|
23
|
-
}).pipe(Category.withServerError) {
|
|
24
|
-
}
|
|
25
|
-
/** Schema parse error wrapper. */
|
|
26
|
-
export class DiscordParseError extends Schema.TaggedError()("DiscordParseError", {
|
|
27
|
-
body: Schema.Unknown,
|
|
28
|
-
cause: Schema.Unknown,
|
|
29
|
-
}).pipe(Category.withParseError) {
|
|
30
|
-
}
|
|
31
|
-
//# 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$DiscordParseError as DiscordParseError, errors$Forbidden as Forbidden, errors$GatewayTimeout as GatewayTimeout, errors$HTTP_STATUS_MAP as HTTP_STATUS_MAP, errors$InternalServerError as InternalServerError, errors$Locked as Locked, errors$NotFound as NotFound, errors$ServiceUnavailable as ServiceUnavailable, errors$TooManyRequests as TooManyRequests, errors$Unauthorized as Unauthorized, errors$UnknownDiscordError as UnknownDiscordError, errors$UnprocessableEntity as UnprocessableEntity } from "./_bundle/sdk.js";
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @distilled.cloud/discord
|
|
2
|
+
* @distilled.cloud/discord -- Discord HTTP API (v10) SDK for Effect.
|
|
3
3
|
*
|
|
4
4
|
* `./services` is generated by `scripts/generate.ts` from the Smithy model in
|
|
5
5
|
* `.generated-specs` (written by `scripts/convert.ts` from the Discord
|
package/lib/index.js
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @distilled.cloud/discord — Discord HTTP API (v10) SDK for Effect.
|
|
3
|
-
*
|
|
4
|
-
* `./services` is generated by `scripts/generate.ts` from the Smithy model in
|
|
5
|
-
* `.generated-specs` (written by `scripts/convert.ts` from the Discord
|
|
6
|
-
* OpenAPI spec submodule). Everything else in this folder is hand-written.
|
|
7
|
-
*/
|
|
8
1
|
export * from "./credentials.js";
|
|
9
2
|
export * from "./errors.js";
|
|
10
3
|
export * as T from "./traits.js";
|
|
11
4
|
export { DiscordProtocol } from "./protocol.js";
|
|
12
5
|
export * as Retry from "./retry.js";
|
|
13
6
|
export * as Services from "./services/index.js";
|
|
14
|
-
//# sourceMappingURL=index.js.map
|
package/lib/protocol.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,2BAA2B,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAiBhE,OAAO,KAAK,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,KAAK,eAAe,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAuB,KAAK,aAAa,EAAqB,MAAM,aAAa,CAAC;AAEzF;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG,WAAW,GAAG,eAAe,CAAC,eAAe,CAAC;AAE3F,0EAA0E;AAC1E,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;AAyCnE,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,2BAA2B,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAiBhE,OAAO,KAAK,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,KAAK,eAAe,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAuB,KAAK,aAAa,EAAqB,MAAM,aAAa,CAAC;AAEzF;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG,WAAW,GAAG,eAAe,CAAC,eAAe,CAAC;AAE3F,0EAA0E;AAC1E,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;AAyCnE,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAkBpD,CAAC"}
|
package/lib/protocol.js
CHANGED
|
@@ -1,80 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* DiscordProtocol — the shared bearer-REST protocol instantiated for Discord.
|
|
4
|
-
*
|
|
5
|
-
* Discord speaks plain JSON with no response envelope: successful responses
|
|
6
|
-
* are the resource (or a bare array) verbatim. Failures carry
|
|
7
|
-
* `{ code, message, errors? }` where `code` is Discord's own numeric JSON
|
|
8
|
-
* error code — the shared HTTP status map turns the status into the error
|
|
9
|
-
* class, and anything unmapped becomes {@link UnknownDiscordError} with the
|
|
10
|
-
* code and per-field `errors` detail preserved.
|
|
11
|
-
*
|
|
12
|
-
* Rate limits (429) arrive as `TooManyRequests` with `retryAfter` read from
|
|
13
|
-
* the `Retry-After` header, so the default retry policy honors Discord's
|
|
14
|
-
* bucket hints without extra configuration.
|
|
15
|
-
*/
|
|
16
|
-
import * as Effect from "effect/Effect";
|
|
17
|
-
import * as Redacted from "effect/Redacted";
|
|
18
|
-
import { Credentials } from "./credentials.js";
|
|
19
|
-
import { UnknownDiscordError, DiscordParseError } from "./errors.js";
|
|
20
|
-
/**
|
|
21
|
-
* Discord's error body is `{ code: <numeric JSON error code>, message }`.
|
|
22
|
-
* The OAuth2 token endpoints answer in the OAuth style instead
|
|
23
|
-
* (`{ error, error_description }`), so both spellings are read here.
|
|
24
|
-
*/
|
|
25
|
-
const errorEnvelope = (body) => {
|
|
26
|
-
if (body === null || typeof body !== "object")
|
|
27
|
-
return undefined;
|
|
28
|
-
const b = body;
|
|
29
|
-
const message = typeof b.message === "string"
|
|
30
|
-
? b.message
|
|
31
|
-
: typeof b.error_description === "string"
|
|
32
|
-
? b.error_description
|
|
33
|
-
: typeof b.error === "string"
|
|
34
|
-
? b.error
|
|
35
|
-
: undefined;
|
|
36
|
-
const code = typeof b.code === "number" || typeof b.code === "string" ? b.code : undefined;
|
|
37
|
-
return { code, message };
|
|
38
|
-
};
|
|
39
|
-
/** Discord's `errors` object: per-field validation detail on 400s. */
|
|
40
|
-
const errorDetails = (body) => {
|
|
41
|
-
if (body === null || typeof body !== "object")
|
|
42
|
-
return undefined;
|
|
43
|
-
return body.errors;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Discord's JSON error code as a number. The OAuth2 endpoints answer with a
|
|
47
|
-
* string `error` slug instead of a numeric `code` — those carry no numeric
|
|
48
|
-
* code at all, so anything unparseable is dropped rather than surfaced as
|
|
49
|
-
* NaN.
|
|
50
|
-
*/
|
|
51
|
-
const numericCode = (code) => {
|
|
52
|
-
if (typeof code === "number")
|
|
53
|
-
return Number.isFinite(code) ? code : undefined;
|
|
54
|
-
if (typeof code !== "string" || code.trim() === "")
|
|
55
|
-
return undefined;
|
|
56
|
-
const n = Number(code);
|
|
57
|
-
return Number.isFinite(n) ? n : undefined;
|
|
58
|
-
};
|
|
59
|
-
export const DiscordProtocol = makeRestProtocol({
|
|
60
|
-
// Resolved on the CALLING fiber per request (the layer is memoized per
|
|
61
|
-
// process); the Credentials service holds an effect so rotating tokens
|
|
62
|
-
// Just Work.
|
|
63
|
-
credentials: Effect.gen(function* () {
|
|
64
|
-
const resolve = yield* Credentials;
|
|
65
|
-
return yield* resolve;
|
|
66
|
-
}),
|
|
67
|
-
baseUrl: (creds) => creds.apiBaseUrl,
|
|
68
|
-
headers: (creds) => ({
|
|
69
|
-
Authorization: `${creds.tokenType} ${Redacted.value(creds.token)}`,
|
|
70
|
-
}),
|
|
71
|
-
errorEnvelope,
|
|
72
|
-
unknownError: ({ code, message, body }) => new UnknownDiscordError({
|
|
73
|
-
code: numericCode(code),
|
|
74
|
-
message,
|
|
75
|
-
errors: errorDetails(body),
|
|
76
|
-
body,
|
|
77
|
-
}),
|
|
78
|
-
parseError: ({ body, cause }) => new DiscordParseError({ body, cause }),
|
|
79
|
-
});
|
|
80
|
-
//# sourceMappingURL=protocol.js.map
|
|
1
|
+
export { protocol$DiscordProtocol as DiscordProtocol } from "./_bundle/sdk.js";
|
package/lib/retry.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Retries from "@distilled.cloud/core/retry";
|
|
2
2
|
/**
|
|
3
|
-
* Discord retry surface
|
|
3
|
+
* Discord retry surface -- a veneer over `@distilled.cloud/core/retry`.
|
|
4
4
|
*
|
|
5
5
|
* The `Retry` service tag is threaded into every generated operation via
|
|
6
6
|
* `API.make({ retry: Retry })`, so a caller-installed policy applies to all
|
|
@@ -23,7 +23,7 @@ export type Factory = Retries.Factory;
|
|
|
23
23
|
export type Policy = Retries.Policy;
|
|
24
24
|
declare const Retry_base: Context.ServiceClass<Retry, "DiscordRetry", Retries.Policy>;
|
|
25
25
|
/** Context tag for configuring retry behavior of Discord API calls. */
|
|
26
|
-
export declare class Retry extends Retry_base {
|
|
26
|
+
export declare class Retry extends /*@__PURE__*/ Retry_base {
|
|
27
27
|
}
|
|
28
28
|
/** Provides a custom retry policy to every Discord API call below it. */
|
|
29
29
|
export declare const policy: {
|
package/lib/retry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,6BAA6B,CAAC;AACvD;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;AACtC,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;AACtC,MAAM,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;;AAEpC,uEAAuE;AACvE,qBAAa,KAAM,SAAQ,UAAgD;CAAG;
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,6BAA6B,CAAC;AACvD;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;AACtC,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;AACtC,MAAM,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;;AAEpC,uEAAuE;AACvE,qBAAa,KAAM,SAAQ,aAAa,CAAC,UAAgD;CAAG;AAE5F,yEAAyE;AACzE,eAAO,MAAM,MAAM,EAAE;IACnB,CACE,OAAO,EAAE,OAAO,GACf,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IACvF,CACE,OAAO,EAAE,OAAO,GACf,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;CACU,CAAC;AAEpG,sCAAsC;AACtC,eAAO,MAAM,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACzB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAC3B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAEzC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,OAA6B,CAAC;AAExD,eAAO,MAAM,QAAQ,0JAAmB,CAAC;AACzC,eAAO,MAAM,MAAM,uMAAiB,CAAC;AAErC,mEAAmE;AACnE,eAAO,MAAM,iBAAiB,EAAE,OAAmC,CAAC;AAEpE,0EAA0E;AAC1E,eAAO,MAAM,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAC3B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAmD,CAAC;AAE9F,kEAAkE;AAClE,eAAO,MAAM,gBAAgB,EAAE,OAAkC,CAAC;AAElE,yEAAyE;AACzE,eAAO,MAAM,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAC3B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAkD,CAAC"}
|
package/lib/retry.js
CHANGED
|
@@ -1,45 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Discord retry surface — a veneer over `@distilled.cloud/core/retry`.
|
|
4
|
-
*
|
|
5
|
-
* The `Retry` service tag is threaded into every generated operation via
|
|
6
|
-
* `API.make({ retry: Retry })`, so a caller-installed policy applies to all
|
|
7
|
-
* Discord calls below it and core's `makeDefault` is the fallback when none
|
|
8
|
-
* is provided. Discord rate limits aggressively per-bucket and answers 429s
|
|
9
|
-
* with a `Retry-After` header, which the default policy honors with
|
|
10
|
-
* precedence over its own backoff.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* import * as Discord from "@distilled.cloud/discord";
|
|
15
|
-
*
|
|
16
|
-
* myEffect.pipe(Discord.Retry.throttling);
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
import * as Context from "effect/Context";
|
|
20
|
-
import * as Effect from "effect/Effect";
|
|
21
|
-
import * as Layer from "effect/Layer";
|
|
22
|
-
/** Context tag for configuring retry behavior of Discord API calls. */
|
|
23
|
-
export class Retry extends Context.Service()("DiscordRetry") {
|
|
24
|
-
}
|
|
25
|
-
/** Provides a custom retry policy to every Discord API call below it. */
|
|
26
|
-
export const policy = (optionsOrFactory) => Effect.provide(Layer.succeed(Retry, optionsOrFactory));
|
|
27
|
-
/** Disables all automatic retries. */
|
|
28
|
-
export const none = Effect.provide(Layer.succeed(Retry, { while: () => false }));
|
|
29
|
-
/**
|
|
30
|
-
* The default retry policy (core's): transient/throttling/retryable errors,
|
|
31
|
-
* capped exponential backoff with jitter, server `retryAfter` hints honored
|
|
32
|
-
* with precedence.
|
|
33
|
-
*/
|
|
34
|
-
export const makeDefault = Retries.makeDefault;
|
|
35
|
-
export const jittered = Retries.jittered;
|
|
36
|
-
export const capped = Retries.capped;
|
|
37
|
-
/** Retry options that retry all throttling errors indefinitely. */
|
|
38
|
-
export const throttlingOptions = Retries.throttlingOptions;
|
|
39
|
-
/** Retries all throttling errors indefinitely (honoring server hints). */
|
|
40
|
-
export const throttling = policy(Retries.throttlingFactory);
|
|
41
|
-
/** Retry options that retry all transient errors indefinitely. */
|
|
42
|
-
export const transientOptions = Retries.transientOptions;
|
|
43
|
-
/** Retries all transient errors indefinitely (honoring server hints). */
|
|
44
|
-
export const transient = policy(Retries.transientFactory);
|
|
45
|
-
//# sourceMappingURL=retry.js.map
|
|
1
|
+
export { retry$Retry as Retry, retry$capped as capped, retry$jittered as jittered, retry$makeDefault as makeDefault, retry$none as none, retry$policy as policy, retry$throttling as throttling, retry$throttlingOptions as throttlingOptions, retry$transient as transient, retry$transientOptions as transientOptions } from "./_bundle/sdk.js";
|