statocysts 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.d.ts +4 -4
- package/dist/browser.js +9 -11
- package/dist/index.d.ts +4 -4
- package/dist/index.js +9 -11
- package/dist/{shared-DLVVDcdQ.js → shared-BiiZsNzb.js} +32 -4
- package/dist/shared-CR_VTatP.d.ts +34 -0
- package/package.json +1 -1
- package/dist/index-pwxPZaBo.d.ts +0 -50
package/dist/browser.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { a as DEFAULT_EXTRACTOR, c as ServiceProvider, i as
|
|
1
|
+
import { a as DEFAULT_EXTRACTOR, c as ServiceProvider, i as buildSenderRegistry, l as defineProvider, n as SenderRegistry, o as DefineProviderContext, r as SenderUrl, s as DefineProviderOptions, t as Sender } from "./shared-CR_VTatP.js";
|
|
2
2
|
import { FetchOptions } from "ofetch";
|
|
3
3
|
|
|
4
4
|
//#region src/browser.d.ts
|
|
5
|
-
|
|
6
|
-
declare
|
|
5
|
+
declare const senderRegistry: SenderRegistry;
|
|
6
|
+
declare function createSender(urls: SenderUrl[]): Sender;
|
|
7
7
|
declare function send(url: string | URL, message: string, options?: FetchOptions): Promise<void>;
|
|
8
8
|
//#endregion
|
|
9
|
-
export { DEFAULT_EXTRACTOR, DefineProviderContext, DefineProviderOptions,
|
|
9
|
+
export { DEFAULT_EXTRACTOR, DefineProviderContext, DefineProviderOptions, Sender, SenderRegistry, SenderUrl, ServiceProvider, buildSenderRegistry, createSender, defineProvider, send, senderRegistry };
|
package/dist/browser.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as defineProvider, i as DEFAULT_EXTRACTOR, n as json, o as assert, r as slack, t as buildSenderRegistry } from "./shared-BiiZsNzb.js";
|
|
2
2
|
import { ofetch } from "ofetch";
|
|
3
3
|
|
|
4
4
|
//#region src/browser.ts
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
5
|
+
const senderRegistry = buildSenderRegistry([json, slack]);
|
|
6
|
+
function createSender(urls) {
|
|
7
|
+
return senderRegistry(urls);
|
|
8
|
+
}
|
|
10
9
|
async function send(url, message, options) {
|
|
11
10
|
const _url = typeof url === "string" ? new URL(url) : url;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
await ofetch(await provider.buildRequest(_url.toString(), message), options);
|
|
11
|
+
const provider = senderRegistry.resolveProvider(_url);
|
|
12
|
+
assert(provider, `Unsupported protocol ${_url.protocol}`);
|
|
13
|
+
await ofetch(provider.buildRequest(_url.toString(), message, options), options);
|
|
16
14
|
}
|
|
17
15
|
|
|
18
16
|
//#endregion
|
|
19
|
-
export { DEFAULT_EXTRACTOR,
|
|
17
|
+
export { DEFAULT_EXTRACTOR, buildSenderRegistry, createSender, defineProvider, send, senderRegistry };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { a as DEFAULT_EXTRACTOR, c as ServiceProvider, i as
|
|
1
|
+
import { a as DEFAULT_EXTRACTOR, c as ServiceProvider, i as buildSenderRegistry, l as defineProvider, n as SenderRegistry, o as DefineProviderContext, r as SenderUrl, s as DefineProviderOptions, t as Sender } from "./shared-CR_VTatP.js";
|
|
2
2
|
import { FetchOptions } from "ofetch";
|
|
3
3
|
|
|
4
4
|
//#region src/index.d.ts
|
|
5
|
-
|
|
6
|
-
declare
|
|
5
|
+
declare const senderRegistry: SenderRegistry;
|
|
6
|
+
declare function createSender(urls: SenderUrl[]): Sender;
|
|
7
7
|
declare function send(url: string | URL, message: string, options?: FetchOptions): Promise<void>;
|
|
8
8
|
//#endregion
|
|
9
|
-
export { DEFAULT_EXTRACTOR, DefineProviderContext, DefineProviderOptions,
|
|
9
|
+
export { DEFAULT_EXTRACTOR, DefineProviderContext, DefineProviderOptions, Sender, SenderRegistry, SenderUrl, ServiceProvider, buildSenderRegistry, createSender, defineProvider, send, senderRegistry };
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as defineProvider, i as DEFAULT_EXTRACTOR, n as json, o as assert, r as slack, t as buildSenderRegistry } from "./shared-BiiZsNzb.js";
|
|
2
2
|
import { ofetch } from "ofetch";
|
|
3
3
|
|
|
4
4
|
//#region src/index.ts
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
5
|
+
const senderRegistry = buildSenderRegistry([json, slack]);
|
|
6
|
+
function createSender(urls) {
|
|
7
|
+
return senderRegistry(urls);
|
|
8
|
+
}
|
|
10
9
|
async function send(url, message, options) {
|
|
11
10
|
const _url = typeof url === "string" ? new URL(url) : url;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
await ofetch(await provider.buildRequest(_url.toString(), message), options);
|
|
11
|
+
const provider = senderRegistry.resolveProvider(_url);
|
|
12
|
+
assert(provider, `Unsupported protocol ${_url.protocol}`);
|
|
13
|
+
await ofetch(provider.buildRequest(_url.toString(), message, options), options);
|
|
16
14
|
}
|
|
17
15
|
|
|
18
16
|
//#endregion
|
|
19
|
-
export { DEFAULT_EXTRACTOR,
|
|
17
|
+
export { DEFAULT_EXTRACTOR, buildSenderRegistry, createSender, defineProvider, send, senderRegistry };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import defu from "defu";
|
|
2
2
|
import { withProtocol, withoutLeadingSlash } from "ufo";
|
|
3
|
+
import { ofetch } from "ofetch";
|
|
3
4
|
|
|
4
5
|
//#region src/utils/assert.ts
|
|
5
6
|
function assert(condition, message) {
|
|
@@ -11,7 +12,7 @@ function assert(condition, message) {
|
|
|
11
12
|
const DEFAULT_EXTRACTOR = (url) => Object.fromEntries(url.searchParams.entries());
|
|
12
13
|
function defineProvider(protocol, createOptions) {
|
|
13
14
|
const createOpt = defu(createOptions, { extractor: DEFAULT_EXTRACTOR });
|
|
14
|
-
const buildRequest =
|
|
15
|
+
const buildRequest = (protocolUrl, message, options) => {
|
|
15
16
|
const url = new URL(protocolUrl);
|
|
16
17
|
assert(url.protocol === protocol, `Unexpected protocol "${url.protocol}"`);
|
|
17
18
|
const ctx = {
|
|
@@ -36,7 +37,7 @@ function defineProvider(protocol, createOptions) {
|
|
|
36
37
|
|
|
37
38
|
//#endregion
|
|
38
39
|
//#region src/services/chat/slack/index.ts
|
|
39
|
-
const
|
|
40
|
+
const slack = defineProvider("slack:", {
|
|
40
41
|
extractor: (url) => {
|
|
41
42
|
assert(url.hostname === "bot" || url.hostname === "webhook", `Invalid slack URL: ${url.toString()}`);
|
|
42
43
|
if (url.hostname === "bot") {
|
|
@@ -79,7 +80,7 @@ const slackProvider = defineProvider("slack:", {
|
|
|
79
80
|
|
|
80
81
|
//#endregion
|
|
81
82
|
//#region src/services/specialized/json/index.ts
|
|
82
|
-
const
|
|
83
|
+
const json = defineProvider("json:", { createRequest() {
|
|
83
84
|
const url = new URL(this.url);
|
|
84
85
|
const headers = new Headers([["Content-Type", "application/json"]]);
|
|
85
86
|
const body = { message: this.message };
|
|
@@ -104,4 +105,31 @@ const jsonProvider = defineProvider("json:", { createRequest() {
|
|
|
104
105
|
} });
|
|
105
106
|
|
|
106
107
|
//#endregion
|
|
107
|
-
|
|
108
|
+
//#region src/core/sender.ts
|
|
109
|
+
function buildSenderRegistry(providers) {
|
|
110
|
+
const providersRegistry = /* @__PURE__ */ new Map();
|
|
111
|
+
providers.forEach((provider) => {
|
|
112
|
+
providersRegistry.set(provider.protocol, provider);
|
|
113
|
+
});
|
|
114
|
+
function resolveProvider(url) {
|
|
115
|
+
const _url = typeof url === "string" ? new URL(url) : url;
|
|
116
|
+
return providersRegistry.get(_url.protocol);
|
|
117
|
+
}
|
|
118
|
+
function createSender(urls) {
|
|
119
|
+
const registries = urls.map((url) => {
|
|
120
|
+
const provider = resolveProvider(url);
|
|
121
|
+
if (!provider) return;
|
|
122
|
+
return {
|
|
123
|
+
provider,
|
|
124
|
+
url
|
|
125
|
+
};
|
|
126
|
+
}).filter((p) => !!p);
|
|
127
|
+
return { async send(message, options) {
|
|
128
|
+
for (const registry of registries) await ofetch(registry.provider.buildRequest(registry.url.toString(), message), options);
|
|
129
|
+
} };
|
|
130
|
+
}
|
|
131
|
+
return Object.assign(createSender, { resolveProvider });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
//#endregion
|
|
135
|
+
export { defineProvider as a, DEFAULT_EXTRACTOR as i, json as n, assert as o, slack as r, buildSenderRegistry as t };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { FetchOptions } from "ofetch";
|
|
2
|
+
|
|
3
|
+
//#region src/core/provider.d.ts
|
|
4
|
+
interface ServiceProvider<Protocol extends string, Data = unknown, Options = unknown> {
|
|
5
|
+
readonly protocol: Protocol;
|
|
6
|
+
$infer: Data;
|
|
7
|
+
defaultOptions: Options | undefined;
|
|
8
|
+
buildRequest: (url: string, message: string, options?: Options) => Request;
|
|
9
|
+
}
|
|
10
|
+
interface DefineProviderContext<Data = unknown> {
|
|
11
|
+
url: URL;
|
|
12
|
+
message: string;
|
|
13
|
+
data: Data;
|
|
14
|
+
}
|
|
15
|
+
interface DefineProviderOptions<Data = unknown, Options = unknown> {
|
|
16
|
+
defaultOptions?: Options;
|
|
17
|
+
extractor?: (url: URL) => Data;
|
|
18
|
+
createRequest: (this: DefineProviderContext<Data>, ctx: DefineProviderContext<Data>, Options: Options) => Request;
|
|
19
|
+
}
|
|
20
|
+
declare const DEFAULT_EXTRACTOR: (url: URL) => unknown;
|
|
21
|
+
declare function defineProvider<const Protocol extends string, Data = unknown, Options = unknown>(protocol: Protocol, createOptions: DefineProviderOptions<Data, Options>): ServiceProvider<Protocol, Data, Options>;
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/core/sender.d.ts
|
|
24
|
+
interface Sender {
|
|
25
|
+
send: (message: string, options?: FetchOptions) => Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
type SenderUrl = string | URL;
|
|
28
|
+
interface SenderRegistry {
|
|
29
|
+
(urls: SenderUrl[]): Sender;
|
|
30
|
+
resolveProvider: (url: string | URL) => ServiceProvider<string> | undefined;
|
|
31
|
+
}
|
|
32
|
+
declare function buildSenderRegistry(providers: ServiceProvider<string, any, any>[]): SenderRegistry;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { DEFAULT_EXTRACTOR as a, ServiceProvider as c, buildSenderRegistry as i, defineProvider as l, SenderRegistry as n, DefineProviderContext as o, SenderUrl as r, DefineProviderOptions as s, Sender as t };
|
package/package.json
CHANGED
package/dist/index-pwxPZaBo.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
//#region src/core/provider.d.ts
|
|
2
|
-
interface ServiceProvider<Protocol extends string, Data = unknown, Options = unknown> {
|
|
3
|
-
readonly protocol: Protocol;
|
|
4
|
-
$infer: Data;
|
|
5
|
-
defaultOptions: Options | undefined;
|
|
6
|
-
buildRequest: (url: string, message: string, options?: Options) => Promise<Request>;
|
|
7
|
-
}
|
|
8
|
-
interface DefineProviderContext<Data = unknown> {
|
|
9
|
-
url: URL;
|
|
10
|
-
message: string;
|
|
11
|
-
data: Data;
|
|
12
|
-
}
|
|
13
|
-
interface DefineProviderOptions<Data = unknown, Options = unknown> {
|
|
14
|
-
defaultOptions?: Options;
|
|
15
|
-
extractor?: (url: URL) => Data;
|
|
16
|
-
createRequest: (this: DefineProviderContext<Data>, ctx: DefineProviderContext<Data>, Options: Options) => Request;
|
|
17
|
-
}
|
|
18
|
-
declare const DEFAULT_EXTRACTOR: (url: URL) => unknown;
|
|
19
|
-
declare function defineProvider<const Protocol extends string, Data = unknown, Options = unknown>(protocol: Protocol, createOptions: DefineProviderOptions<Data, Options>): ServiceProvider<Protocol, Data, Options>;
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region src/services/chat/slack/index.d.ts
|
|
22
|
-
interface SlackData {
|
|
23
|
-
type: 'bot' | 'webhook';
|
|
24
|
-
}
|
|
25
|
-
interface SlackOptions {
|
|
26
|
-
/**
|
|
27
|
-
* The base URL for webhook services
|
|
28
|
-
*
|
|
29
|
-
* @default `https://hooks.slack.com/services`
|
|
30
|
-
*/
|
|
31
|
-
hookBaseUrl?: string;
|
|
32
|
-
/**
|
|
33
|
-
* The base URL for bot API services
|
|
34
|
-
*
|
|
35
|
-
* @default `https://slack.com/api`
|
|
36
|
-
*/
|
|
37
|
-
botApiBaseUrl?: string;
|
|
38
|
-
/**
|
|
39
|
-
* The body of the request
|
|
40
|
-
*
|
|
41
|
-
* NOTICE*: This will override the body of the request. You should known what you are doing.
|
|
42
|
-
*/
|
|
43
|
-
body?: Record<string, any>;
|
|
44
|
-
}
|
|
45
|
-
declare const slackProvider: ServiceProvider<"slack:", SlackData, SlackOptions>;
|
|
46
|
-
//#endregion
|
|
47
|
-
//#region src/services/specialized/json/index.d.ts
|
|
48
|
-
declare const jsonProvider: ServiceProvider<"json:", unknown, unknown>;
|
|
49
|
-
//#endregion
|
|
50
|
-
export { DEFAULT_EXTRACTOR as a, ServiceProvider as c, slackProvider as i, defineProvider as l, SlackData as n, DefineProviderContext as o, SlackOptions as r, DefineProviderOptions as s, jsonProvider as t };
|