@distilled.cloud/discord 1.0.0-rc.16 → 1.0.0-rc.18
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 +2 -1
- package/lib/credentials.d.ts.map +1 -1
- package/lib/credentials.js +1 -57
- package/lib/errors.js +1 -31
- package/lib/index.d.ts +3 -3
- package/lib/index.js +0 -8
- package/lib/index.lazy.js +6 -0
- package/lib/protocol.d.ts +2 -2
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +1 -77
- package/lib/retry.js +1 -46
- package/lib/services/discord.d.ts.map +1 -1
- package/lib/services/discord.js +333 -539
- package/lib/services/discord.js.map +1 -0
- 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.js +1 -11
- package/package.json +9 -10
- package/src/credentials.ts +1 -2
- package/src/index.ts +3 -3
- package/src/protocol.ts +6 -2
- package/src/services/discord.ts +505 -0
- 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 r,api$newError as ee,api$op as te,category$withBadRequestError as i,category$withParseError as a,category$withServerError as o,config$Redacted as s,config$String as c,config$all as ne,config$orElse as re,config$withDefault as l,retry$capped as ie,retry$jittered as ae,retry$makeDefault as u,retry$throttlingFactory as d,retry$throttlingOptions as f,retry$transientFactory as p,retry$transientOptions as m,schema_lite_typed$Number as h,schema_lite_typed$String as g,schema_lite_typed$TaggedError as _,schema_lite_typed$Unknown as v,schema_lite_typed$optional as y,trait$Body as b,trait$FormDataFile as x,trait$Header as S,trait$Http as C,trait$HttpBody as w,trait$KeyDictionary as T,trait$Label as E,trait$Query as D,trait$ResponseCode as O,trait$UnionCases as k,trait$applyErrorMatchers as A,trait$bodySymbol as j,trait$errorMatchersSymbol as M,trait$formDataFileSymbol as N,trait$getErrorMatchers as P,trait$headerSymbol as F,trait$httpBodySymbol as I,trait$httpSymbol as L,trait$keyDictionarySymbol as R,trait$labelSymbol as z,trait$querySymbol as B,trait$responseCodeSymbol as V,trait$unionCasesSymbol as H}from"@distilled.cloud/core/_bundle/base";import{errors$API_ERRORS as U,errors$BadGateway as W,errors$BadRequest as G,errors$ConfigError as K,errors$Conflict as q,errors$DEFAULT_ERRORS as J,errors$Forbidden as Y,errors$GatewayTimeout as oe,errors$HTTP_STATUS_MAP as se,errors$InternalServerError as ce,errors$Locked as le,errors$NotFound as ue,errors$ServiceUnavailable as de,errors$TooManyRequests as fe,errors$Unauthorized as pe,errors$UnprocessableEntity as me,protocol_rest$RawResponse as he,protocol_rest$RawResponseRoot as ge,protocol_rest$SensitiveValue as _e,protocol_rest$makeRestProtocol as ve,protocol_rest$rawResponseRootSymbol as ye,protocol_rest$rawResponseSymbol as be,protocol_rest$sensitiveValueSymbol as xe,schema_lite$Array as Se,schema_lite$Boolean as Ce,schema_lite$NullOr as we,schema_lite$Number as Te,schema_lite$Record as Ee,schema_lite$String as De,schema_lite$Struct as Oe,schema_lite$TaggedError as ke,schema_lite$Unknown as Ae,schema_lite$at as je,schema_lite$optional as Me,schema_lite$suspend as Ne}from"@distilled.cloud/core/_bundle/rest";import*as X from"effect/Context";import*as Z from"effect/Effect";import*as Q from"effect/Layer";import*as Pe from"effect/Redacted";const $=`https://discord.com/api/v10`;var Credentials=class extends (/*@__PURE__*/ X.Service()(`DiscordCredentials`)){};const Fe=/*@__PURE__*/ ne({token:/*@__PURE__*/ s(`DISCORD_BOT_TOKEN`).pipe(/*@__PURE__*/ re(()=>s(`DISCORD_TOKEN`))),tokenType:/*@__PURE__*/ c(`DISCORD_TOKEN_TYPE`).pipe(/*@__PURE__*/ l(`Bot`)),apiBaseUrl:/*@__PURE__*/ c(`DISCORD_API_URL`).pipe(/*@__PURE__*/ l($))});const Ie=/*@__PURE__*/ Q.succeed(Credentials,/*@__PURE__*/ Fe.pipe(/*@__PURE__*/ Z.mapError(()=>new K({message:`DISCORD_BOT_TOKEN (or DISCORD_TOKEN) environment variable is required`})),/*@__PURE__*/ Z.map(({token:e,tokenType:t,apiBaseUrl:n})=>({token:e,tokenType:t.toLowerCase()===`bearer`?`Bearer`:`Bot`,apiBaseUrl:n}))));const credentials=e=>Q.succeed(Credentials,Z.succeed({token:e.token,tokenType:e.tokenType??`Bot`,apiBaseUrl:e.apiBaseUrl??`https://discord.com/api/v10`}));var UnknownDiscordError=class extends (/*@__PURE__*/ _()(`UnknownDiscordError`,{code:/*@__PURE__*/ y(h),message:/*@__PURE__*/ y(g),errors:/*@__PURE__*/ y(v),body:v}).pipe(o)){};var DiscordParseError=class extends (/*@__PURE__*/ _()(`DiscordParseError`,{body:v,cause:v}).pipe(a)){};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 Le=/*@__PURE__*/ ve({credentials:/*@__PURE__*/ Z.flatMap(Credentials,e=>e),baseUrl:e=>e.apiBaseUrl,headers:e=>({Authorization:`${e.tokenType} ${Pe.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__*/ X.Service()(`DiscordRetry`)){};const policy=e=>Z.provide(Q.succeed(Retry,e));const Re=/*@__PURE__*/ Z.provide(/*@__PURE__*/ Q.succeed(Retry,{while:()=>false}));const ze=u;const Be=ae;const Ve=ie;const He=f;const Ue=/*@__PURE__*/ policy(d);const We=m;const Ge=/*@__PURE__*/ policy(p);export{Se as Rb,Ce as Sb,we as Zb,Te as _b,e as a,Ee as ac,t as c,De as cc,Credentials as credentials$Credentials,Ie as credentials$CredentialsFromEnv,$ as credentials$DEFAULT_API_BASE_URL,credentials as credentials$credentials,Oe as dc,n as e,U as errors$API_ERRORS,W as errors$BadGateway,G as errors$BadRequest,K as errors$ConfigError,q as errors$Conflict,J as errors$DEFAULT_ERRORS,DiscordParseError as errors$DiscordParseError,Y as errors$Forbidden,oe as errors$GatewayTimeout,se as errors$HTTP_STATUS_MAP,ce as errors$InternalServerError,le as errors$Locked,ue as errors$NotFound,de as errors$ServiceUnavailable,fe as errors$TooManyRequests,pe as errors$Unauthorized,UnknownDiscordError as errors$UnknownDiscordError,me as errors$UnprocessableEntity,ke as fc,Ae as ic,r as j,ee as k,je as kc,te as l,Me as pc,Le as protocol$DiscordProtocol,Ne as qc,Retry as retry$Retry,Ve as retry$capped,Be as retry$jittered,ze as retry$makeDefault,Re as retry$none,policy as retry$policy,Ue as retry$throttling,He as retry$throttlingOptions,Ge as retry$transient,We as retry$transientOptions,b as traits$Body,x as traits$FormDataFile,S as traits$Header,C as traits$Http,w as traits$HttpBody,T as traits$KeyDictionary,E as traits$Label,D as traits$Query,he as traits$RawResponse,ge as traits$RawResponseRoot,O as traits$ResponseCode,_e as traits$SensitiveValue,k as traits$UnionCases,A as traits$applyErrorMatchers,j as traits$bodySymbol,M as traits$errorMatchersSymbol,N as traits$formDataFileSymbol,P as traits$getErrorMatchers,F as traits$headerSymbol,I as traits$httpBodySymbol,L as traits$httpSymbol,R as traits$keyDictionarySymbol,z as traits$labelSymbol,B as traits$querySymbol,ye as traits$rawResponseRootSymbol,be as traits$rawResponseSymbol,V as traits$responseCodeSymbol,xe as traits$sensitiveValueSymbol,H as traits$unionCasesSymbol,i as wa};
|
|
2
|
+
//# sourceMappingURL=sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","names":["EffectConfig.Redacted","Schema.Number","Schema.String","Schema.Unknown","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$3","String$2","all$1","orElse","withDefault","capped$1","jittered$1","makeDefault$1","throttlingFactory","throttlingOptions$1","transientFactory","transientOptions$1","Number$2","String$1","TaggedError$1","Unknown$1","optional$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","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":"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"}
|
package/lib/credentials.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ConfigError } from "@distilled.cloud/core/errors";
|
|
1
2
|
import * as Context from "effect/Context";
|
|
2
3
|
import * as Effect from "effect/Effect";
|
|
3
4
|
import * as Layer from "effect/Layer";
|
|
@@ -15,7 +16,7 @@ export interface Config {
|
|
|
15
16
|
readonly tokenType: TokenType;
|
|
16
17
|
readonly apiBaseUrl: string;
|
|
17
18
|
}
|
|
18
|
-
declare const Credentials_base: Context.ServiceClass<Credentials, "DiscordCredentials", Effect.Effect<Config,
|
|
19
|
+
declare const Credentials_base: Context.ServiceClass<Credentials, "DiscordCredentials", Effect.Effect<Config, ConfigError, never>>;
|
|
19
20
|
export declare class Credentials extends /*@__PURE__*/ Credentials_base {
|
|
20
21
|
}
|
|
21
22
|
export declare const CredentialsFromEnv: Layer.Layer<Credentials, never, never>;
|
package/lib/credentials.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,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,wCAiB9B,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,57 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import * as EffectConfig from "@distilled.cloud/core/config";
|
|
16
|
-
import { ConfigError } from "@distilled.cloud/core/errors";
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export const DEFAULT_API_BASE_URL = "https://discord.com/api/v10";
|
|
27
|
-
export class Credentials extends /*@__PURE__*/ /*@__PURE__*/ Context.Service()("DiscordCredentials") {
|
|
28
|
-
}
|
|
29
|
-
const envConfig = /*@__PURE__*/ EffectConfig.all({
|
|
30
|
-
// DISCORD_BOT_TOKEN is the spelling discord.js and most hosting platforms
|
|
31
|
-
// use; DISCORD_TOKEN is the fallback.
|
|
32
|
-
token: /*@__PURE__*/ EffectConfig.Redacted("DISCORD_BOT_TOKEN").pipe(
|
|
33
|
-
/*@__PURE__*/ EffectConfig.orElse(() => EffectConfig.Redacted("DISCORD_TOKEN"))),
|
|
34
|
-
tokenType: /*@__PURE__*/ EffectConfig.String("DISCORD_TOKEN_TYPE").pipe(
|
|
35
|
-
/*@__PURE__*/ EffectConfig.withDefault("Bot")),
|
|
36
|
-
apiBaseUrl: /*@__PURE__*/ EffectConfig.String("DISCORD_API_URL").pipe(
|
|
37
|
-
/*@__PURE__*/ EffectConfig.withDefault(DEFAULT_API_BASE_URL)),
|
|
38
|
-
});
|
|
39
|
-
export const CredentialsFromEnv = /*@__PURE__*/ Layer.succeed(Credentials,
|
|
40
|
-
/*@__PURE__*/ envConfig.pipe(
|
|
41
|
-
/*@__PURE__*/ Effect.mapError(() => new ConfigError({
|
|
42
|
-
message: "DISCORD_BOT_TOKEN (or DISCORD_TOKEN) environment variable is required",
|
|
43
|
-
})),
|
|
44
|
-
/*@__PURE__*/ Effect.map(({ token, tokenType, apiBaseUrl }) => ({
|
|
45
|
-
token,
|
|
46
|
-
// Anything but an explicit `Bearer` means a bot token -- the OAuth2
|
|
47
|
-
// flavor is the opt-in.
|
|
48
|
-
tokenType: (tokenType.toLowerCase() === "bearer" ? "Bearer" : "Bot"),
|
|
49
|
-
apiBaseUrl,
|
|
50
|
-
})), Effect.orDie));
|
|
51
|
-
|
|
52
|
-
export const credentials = (config) => Layer.succeed(Credentials, Effect.succeed({
|
|
53
|
-
token: config.token,
|
|
54
|
-
tokenType: config.tokenType ?? "Bot",
|
|
55
|
-
apiBaseUrl: config.apiBaseUrl ?? DEFAULT_API_BASE_URL,
|
|
56
|
-
}));
|
|
57
|
-
//# 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.js
CHANGED
|
@@ -1,31 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 "@distilled.cloud/core/schema-lite-typed";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export class UnknownDiscordError extends /*@__PURE__*/ /*@__PURE__*/ Schema.TaggedError()("UnknownDiscordError", {
|
|
19
|
-
code: /*@__PURE__*/ Schema.optional(Schema.Number),
|
|
20
|
-
message: /*@__PURE__*/ Schema.optional(Schema.String),
|
|
21
|
-
errors: /*@__PURE__*/ Schema.optional(Schema.Unknown),
|
|
22
|
-
body: Schema.Unknown,
|
|
23
|
-
}).pipe(Category.withServerError) {
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export class DiscordParseError extends /*@__PURE__*/ /*@__PURE__*/ 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,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @distilled.cloud/discord -- Discord HTTP API (v10) SDK for Effect.
|
|
3
3
|
*
|
|
4
|
-
* `./services` is generated by `scripts/generate.ts` from the Smithy model
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* `./services` is generated by `scripts/generate.ts` from the Smithy model that
|
|
5
|
+
* `scripts/convert.ts` converts from the Discord OpenAPI spec submodule.
|
|
6
|
+
* Everything else in this folder is hand-written.
|
|
7
7
|
*/
|
|
8
8
|
export * from "./credentials.ts";
|
|
9
9
|
export * from "./errors.ts";
|
package/lib/index.js
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as API from "@distilled.cloud/core/api";
|
|
2
|
-
import type { ConfigError } from "@distilled.cloud/core/errors";
|
|
2
|
+
import type { ConfigError, InvalidInput } from "@distilled.cloud/core/errors";
|
|
3
3
|
import type * as HttpClient from "effect/http/HttpClient";
|
|
4
4
|
import type * as HttpClientError from "effect/http/HttpClientError";
|
|
5
5
|
import type * as Layer from "effect/Layer";
|
|
@@ -11,7 +11,7 @@ import { type DefaultErrors } from "./errors.ts";
|
|
|
11
11
|
* DiscordOpError, DiscordOpContext>` explicitly so the compiler never infers
|
|
12
12
|
* these back out of the schema generics.
|
|
13
13
|
*/
|
|
14
|
-
export type DiscordOpError = DefaultErrors | ConfigError | HttpClientError.HttpClientError;
|
|
14
|
+
export type DiscordOpError = DefaultErrors | ConfigError | HttpClientError.HttpClientError | InvalidInput;
|
|
15
15
|
/** Context (requirements) shared by every generated Discord operation. */
|
|
16
16
|
export type DiscordOpContext = Credentials | HttpClient.HttpClient;
|
|
17
17
|
export declare const DiscordProtocol: Layer.Layer<API.Protocol>;
|
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;
|
|
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,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAiB9E,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,GACtB,aAAa,GACb,WAAW,GACX,eAAe,CAAC,eAAe,GAC/B,YAAY,CAAC;AAEjB,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,77 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
40
|
-
const errorDetails = (body) => {
|
|
41
|
-
if (body === null || typeof body !== "object")
|
|
42
|
-
return undefined;
|
|
43
|
-
return body.errors;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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 = /*@__PURE__*/ 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: /*@__PURE__*/ Effect.flatMap(Credentials, (resolve) => resolve),
|
|
64
|
-
baseUrl: (creds) => creds.apiBaseUrl,
|
|
65
|
-
headers: (creds) => ({
|
|
66
|
-
Authorization: `${creds.tokenType} ${Redacted.value(creds.token)}`,
|
|
67
|
-
}),
|
|
68
|
-
errorEnvelope,
|
|
69
|
-
unknownError: ({ code, message, body }) => new UnknownDiscordError({
|
|
70
|
-
code: numericCode(code),
|
|
71
|
-
message,
|
|
72
|
-
errors: errorDetails(body),
|
|
73
|
-
body,
|
|
74
|
-
}),
|
|
75
|
-
parseError: ({ body, cause }) => new DiscordParseError({ body, cause }),
|
|
76
|
-
});
|
|
77
|
-
//# sourceMappingURL=protocol.js.map
|
|
1
|
+
export { protocol$DiscordProtocol as DiscordProtocol } from "./_bundle/sdk.js";
|
package/lib/retry.js
CHANGED
|
@@ -1,46 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import * as Context from "effect/Context";
|
|
20
|
-
import * as Effect from "effect/Effect";
|
|
21
|
-
import * as Layer from "effect/Layer";
|
|
22
|
-
|
|
23
|
-
export class Retry extends /*@__PURE__*/ /*@__PURE__*/ Context.Service()("DiscordRetry") {
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const policy = (optionsOrFactory) => Effect.provide(Layer.succeed(Retry, optionsOrFactory));
|
|
27
|
-
|
|
28
|
-
export const none = /*@__PURE__*/ Effect.provide(
|
|
29
|
-
/*@__PURE__*/ Layer.succeed(Retry, { while: () => false }));
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export const makeDefault = Retries.makeDefault;
|
|
36
|
-
export const jittered = Retries.jittered;
|
|
37
|
-
export const capped = Retries.capped;
|
|
38
|
-
|
|
39
|
-
export const throttlingOptions = Retries.throttlingOptions;
|
|
40
|
-
|
|
41
|
-
export const throttling = /*@__PURE__*/ policy(Retries.throttlingFactory);
|
|
42
|
-
|
|
43
|
-
export const transientOptions = Retries.transientOptions;
|
|
44
|
-
|
|
45
|
-
export const transient = /*@__PURE__*/ policy(Retries.transientFactory);
|
|
46
|
-
//# 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";
|