@paperkite/sdk 0.1.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/index.d.ts +353 -0
- package/dist/index.js +149 -0
- package/dist/index.js.map +1 -0
- package/package.json +22 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
export type CapabilityKind = "action" | "trigger" | "service";
|
|
2
|
+
export interface RuntimeLogger {
|
|
3
|
+
debug(message: string, ...values: unknown[]): void;
|
|
4
|
+
info(message: string, ...values: unknown[]): void;
|
|
5
|
+
warn(message: string, ...values: unknown[]): void;
|
|
6
|
+
error(message: string, ...values: unknown[]): void;
|
|
7
|
+
child(scope: string): RuntimeLogger;
|
|
8
|
+
}
|
|
9
|
+
export interface TriggerEvent {
|
|
10
|
+
readonly id?: number;
|
|
11
|
+
readonly text: string;
|
|
12
|
+
readonly senderId?: string;
|
|
13
|
+
readonly senderUsername?: string;
|
|
14
|
+
readonly senderName?: string;
|
|
15
|
+
readonly chatId?: string;
|
|
16
|
+
readonly chatTitle?: string;
|
|
17
|
+
readonly date?: string;
|
|
18
|
+
readonly raw: unknown;
|
|
19
|
+
}
|
|
20
|
+
export interface TriggerEmission {
|
|
21
|
+
readonly source: {
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly capability: string;
|
|
24
|
+
};
|
|
25
|
+
readonly event: TriggerEvent | Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
export type SessionState = "starting" | "connected" | "isolated" | "waiting-auth";
|
|
28
|
+
export declare class SessionUnavailableError extends Error {
|
|
29
|
+
readonly session: string;
|
|
30
|
+
readonly state: SessionState;
|
|
31
|
+
constructor(session: string, state: SessionState, reason?: string);
|
|
32
|
+
}
|
|
33
|
+
export declare function isSessionUnavailable(error: unknown): error is SessionUnavailableError;
|
|
34
|
+
export interface SessionAccess {
|
|
35
|
+
run<T>(operation: (client: unknown) => T | Promise<T>): Promise<T>;
|
|
36
|
+
}
|
|
37
|
+
export interface ActionOutcome {
|
|
38
|
+
readonly skipped: boolean;
|
|
39
|
+
readonly effectiveConfig?: unknown;
|
|
40
|
+
}
|
|
41
|
+
export interface ActionContext<P = unknown> {
|
|
42
|
+
readonly id: string;
|
|
43
|
+
config: P;
|
|
44
|
+
readonly session?: string;
|
|
45
|
+
readonly signal: AbortSignal;
|
|
46
|
+
readonly sessions?: SessionAccess;
|
|
47
|
+
readonly control?: RuntimeControl;
|
|
48
|
+
readonly logger: RuntimeLogger;
|
|
49
|
+
emission: TriggerEmission | undefined;
|
|
50
|
+
readonly hook?: ActionHook;
|
|
51
|
+
spawn(task: Promise<unknown>): void;
|
|
52
|
+
outcome?: ActionOutcome;
|
|
53
|
+
}
|
|
54
|
+
export interface ActionHookResult {
|
|
55
|
+
config?: unknown;
|
|
56
|
+
skip?: boolean;
|
|
57
|
+
}
|
|
58
|
+
export type ActionHook = (input: {
|
|
59
|
+
config: unknown;
|
|
60
|
+
emission: TriggerEmission | undefined;
|
|
61
|
+
signal: AbortSignal;
|
|
62
|
+
}) => ActionHookResult | unknown | Promise<ActionHookResult | unknown>;
|
|
63
|
+
export declare abstract class Action<P = unknown> {
|
|
64
|
+
protected readonly context: ActionContext<P>;
|
|
65
|
+
constructor(context: ActionContext<P>);
|
|
66
|
+
get id(): string;
|
|
67
|
+
get config(): P;
|
|
68
|
+
set config(value: P);
|
|
69
|
+
get session(): string | undefined;
|
|
70
|
+
get signal(): AbortSignal;
|
|
71
|
+
get sessions(): SessionAccess | undefined;
|
|
72
|
+
get control(): RuntimeControl | undefined;
|
|
73
|
+
get emission(): TriggerEmission | undefined;
|
|
74
|
+
execute(): Promise<void>;
|
|
75
|
+
protected abstract run(): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
export declare abstract class Trigger<P = unknown> {
|
|
78
|
+
protected readonly context: TriggerContext<P>;
|
|
79
|
+
private runCount;
|
|
80
|
+
constructor(context: TriggerContext<P>);
|
|
81
|
+
get id(): string;
|
|
82
|
+
get config(): P;
|
|
83
|
+
get session(): string | undefined;
|
|
84
|
+
get signal(): AbortSignal;
|
|
85
|
+
get sessions(): SessionAccess | undefined;
|
|
86
|
+
get control(): RuntimeControl | undefined;
|
|
87
|
+
protected emit(event: TriggerEvent | Record<string, unknown>): Promise<void>;
|
|
88
|
+
protected canRun(): boolean;
|
|
89
|
+
protected recordRun(): boolean;
|
|
90
|
+
abstract run(): Promise<void>;
|
|
91
|
+
}
|
|
92
|
+
export interface TriggerContext<P = unknown> {
|
|
93
|
+
readonly id: string;
|
|
94
|
+
readonly capability: string;
|
|
95
|
+
readonly config: P;
|
|
96
|
+
readonly session?: string;
|
|
97
|
+
readonly signal: AbortSignal;
|
|
98
|
+
readonly sessions?: SessionAccess;
|
|
99
|
+
readonly control?: RuntimeControl;
|
|
100
|
+
readonly logger: RuntimeLogger;
|
|
101
|
+
readonly maxRuns?: number;
|
|
102
|
+
readonly emit?: (event: TriggerEvent | Record<string, unknown>) => Promise<void>;
|
|
103
|
+
}
|
|
104
|
+
export declare abstract class Service<P = unknown> {
|
|
105
|
+
protected readonly context: ServiceContext<P>;
|
|
106
|
+
constructor(context: ServiceContext<P>);
|
|
107
|
+
get id(): string;
|
|
108
|
+
get config(): P;
|
|
109
|
+
get session(): string | undefined;
|
|
110
|
+
get signal(): AbortSignal;
|
|
111
|
+
get sessions(): SessionAccess | undefined;
|
|
112
|
+
get control(): RuntimeControl | undefined;
|
|
113
|
+
abstract run(): Promise<void>;
|
|
114
|
+
}
|
|
115
|
+
export interface ServiceContext<P = unknown> {
|
|
116
|
+
readonly id: string;
|
|
117
|
+
readonly capability: string;
|
|
118
|
+
readonly config: P;
|
|
119
|
+
readonly session?: string;
|
|
120
|
+
readonly signal: AbortSignal;
|
|
121
|
+
readonly sessions?: SessionAccess;
|
|
122
|
+
readonly control?: RuntimeControl;
|
|
123
|
+
readonly logger: RuntimeLogger;
|
|
124
|
+
}
|
|
125
|
+
export type FlowKind = "trigger" | "command" | "schedule" | "service";
|
|
126
|
+
export interface FlowRef {
|
|
127
|
+
readonly kind: FlowKind;
|
|
128
|
+
readonly id: string;
|
|
129
|
+
}
|
|
130
|
+
export interface ActionSpecView {
|
|
131
|
+
readonly capability: string;
|
|
132
|
+
readonly session?: string;
|
|
133
|
+
readonly config?: unknown;
|
|
134
|
+
readonly hook?: string;
|
|
135
|
+
}
|
|
136
|
+
export interface FlowSnapshot {
|
|
137
|
+
readonly kind: FlowKind;
|
|
138
|
+
readonly id: string;
|
|
139
|
+
readonly capability: string;
|
|
140
|
+
readonly title?: string;
|
|
141
|
+
readonly symbol?: string;
|
|
142
|
+
readonly enabled: boolean;
|
|
143
|
+
readonly active: boolean;
|
|
144
|
+
readonly session?: string;
|
|
145
|
+
readonly actionSession?: string;
|
|
146
|
+
readonly autoStart?: boolean;
|
|
147
|
+
readonly cron?: string;
|
|
148
|
+
readonly intervalSeconds?: number;
|
|
149
|
+
readonly maxRuns?: number;
|
|
150
|
+
readonly config?: unknown;
|
|
151
|
+
readonly actions?: readonly ActionSpecView[];
|
|
152
|
+
readonly hook?: string;
|
|
153
|
+
readonly logFile: boolean;
|
|
154
|
+
readonly startedAt?: string;
|
|
155
|
+
readonly suspended?: FlowSuspension;
|
|
156
|
+
}
|
|
157
|
+
export interface FlowSuspension {
|
|
158
|
+
readonly since: string;
|
|
159
|
+
readonly reason: string;
|
|
160
|
+
readonly session?: string;
|
|
161
|
+
readonly error?: string;
|
|
162
|
+
}
|
|
163
|
+
export interface LogScopeInfo {
|
|
164
|
+
readonly scope: string;
|
|
165
|
+
readonly path: string;
|
|
166
|
+
}
|
|
167
|
+
export interface SessionSnapshot {
|
|
168
|
+
readonly name: string;
|
|
169
|
+
readonly state: SessionState;
|
|
170
|
+
readonly since: string;
|
|
171
|
+
readonly reason?: string;
|
|
172
|
+
readonly attempts: number;
|
|
173
|
+
readonly flows: readonly FlowRef[];
|
|
174
|
+
}
|
|
175
|
+
export interface ActiveActionView {
|
|
176
|
+
readonly id: string;
|
|
177
|
+
readonly capability: string;
|
|
178
|
+
readonly session?: string;
|
|
179
|
+
readonly flow?: FlowRef;
|
|
180
|
+
readonly startedAt: string;
|
|
181
|
+
}
|
|
182
|
+
export interface RuntimeSnapshot {
|
|
183
|
+
readonly running: boolean;
|
|
184
|
+
readonly pid: number;
|
|
185
|
+
readonly uptimeSeconds: number;
|
|
186
|
+
readonly triggers: readonly string[];
|
|
187
|
+
readonly services: readonly string[];
|
|
188
|
+
readonly schedules: readonly string[];
|
|
189
|
+
readonly activeServices: readonly string[];
|
|
190
|
+
readonly activeActions: readonly ActiveActionView[];
|
|
191
|
+
readonly sessions: readonly SessionSnapshot[];
|
|
192
|
+
readonly flows: readonly FlowSnapshot[];
|
|
193
|
+
readonly logs: readonly LogScopeInfo[];
|
|
194
|
+
}
|
|
195
|
+
export interface ActionSpecInput {
|
|
196
|
+
readonly capability: string;
|
|
197
|
+
readonly config?: unknown;
|
|
198
|
+
readonly session?: string;
|
|
199
|
+
readonly hook?: string;
|
|
200
|
+
readonly label?: string;
|
|
201
|
+
}
|
|
202
|
+
export interface ActionStartedEvent {
|
|
203
|
+
readonly type: "action.started";
|
|
204
|
+
readonly id: string;
|
|
205
|
+
readonly capability: string;
|
|
206
|
+
readonly session?: string;
|
|
207
|
+
readonly flow?: FlowRef;
|
|
208
|
+
readonly hook?: string;
|
|
209
|
+
readonly config?: unknown;
|
|
210
|
+
readonly at: string;
|
|
211
|
+
}
|
|
212
|
+
export interface ActionFinishedEvent {
|
|
213
|
+
readonly type: "action.finished";
|
|
214
|
+
readonly id: string;
|
|
215
|
+
readonly capability: string;
|
|
216
|
+
readonly session?: string;
|
|
217
|
+
readonly flow?: FlowRef;
|
|
218
|
+
readonly ok: boolean;
|
|
219
|
+
readonly skipped: boolean;
|
|
220
|
+
readonly durationMs: number;
|
|
221
|
+
readonly error?: string;
|
|
222
|
+
readonly effectiveConfig?: unknown;
|
|
223
|
+
readonly at: string;
|
|
224
|
+
}
|
|
225
|
+
export interface ServiceStartedEvent {
|
|
226
|
+
readonly type: "service.started";
|
|
227
|
+
readonly id: string;
|
|
228
|
+
readonly capability: string;
|
|
229
|
+
readonly session?: string;
|
|
230
|
+
readonly at: string;
|
|
231
|
+
}
|
|
232
|
+
export interface ServiceStoppedEvent {
|
|
233
|
+
readonly type: "service.stopped";
|
|
234
|
+
readonly id: string;
|
|
235
|
+
readonly capability: string;
|
|
236
|
+
readonly session?: string;
|
|
237
|
+
readonly reason: "stop" | "error" | "finished";
|
|
238
|
+
readonly error?: string;
|
|
239
|
+
readonly durationMs: number;
|
|
240
|
+
readonly at: string;
|
|
241
|
+
}
|
|
242
|
+
export interface FlowUpdatedEvent {
|
|
243
|
+
readonly type: "flow.updated";
|
|
244
|
+
readonly id: string;
|
|
245
|
+
readonly kind: FlowKind;
|
|
246
|
+
readonly at: string;
|
|
247
|
+
}
|
|
248
|
+
export interface FlowReloadedEvent {
|
|
249
|
+
readonly type: "flow.reloaded";
|
|
250
|
+
readonly id: string;
|
|
251
|
+
readonly kind: FlowKind;
|
|
252
|
+
readonly at: string;
|
|
253
|
+
}
|
|
254
|
+
export interface FlowFinishedEvent {
|
|
255
|
+
readonly type: "flow.finished";
|
|
256
|
+
readonly kind: FlowKind;
|
|
257
|
+
readonly id: string;
|
|
258
|
+
readonly capability: string;
|
|
259
|
+
readonly ok: boolean;
|
|
260
|
+
readonly durationMs: number;
|
|
261
|
+
readonly at: string;
|
|
262
|
+
}
|
|
263
|
+
export interface ScheduleFiredEvent {
|
|
264
|
+
readonly type: "schedule.fired";
|
|
265
|
+
readonly id: string;
|
|
266
|
+
readonly cron?: string;
|
|
267
|
+
readonly intervalSeconds?: number;
|
|
268
|
+
readonly at: string;
|
|
269
|
+
}
|
|
270
|
+
export interface FlowsReloadingEvent {
|
|
271
|
+
readonly type: "flows.reloading";
|
|
272
|
+
readonly at: string;
|
|
273
|
+
}
|
|
274
|
+
export interface FlowsReloadedEvent {
|
|
275
|
+
readonly type: "flows.reloaded";
|
|
276
|
+
readonly ok: boolean;
|
|
277
|
+
readonly error?: string;
|
|
278
|
+
readonly at: string;
|
|
279
|
+
}
|
|
280
|
+
export interface SessionStateEvent {
|
|
281
|
+
readonly type: "session.state";
|
|
282
|
+
readonly name: string;
|
|
283
|
+
readonly state: SessionState;
|
|
284
|
+
readonly reason?: string;
|
|
285
|
+
readonly since: string;
|
|
286
|
+
readonly at: string;
|
|
287
|
+
}
|
|
288
|
+
export interface FlowSuspendedEvent {
|
|
289
|
+
readonly type: "flow.suspended";
|
|
290
|
+
readonly id: string;
|
|
291
|
+
readonly kind: FlowKind;
|
|
292
|
+
readonly session: string;
|
|
293
|
+
readonly error?: string;
|
|
294
|
+
readonly at: string;
|
|
295
|
+
}
|
|
296
|
+
export interface FlowResumedEvent {
|
|
297
|
+
readonly type: "flow.resumed";
|
|
298
|
+
readonly id: string;
|
|
299
|
+
readonly kind: FlowKind;
|
|
300
|
+
readonly session: string;
|
|
301
|
+
readonly at: string;
|
|
302
|
+
}
|
|
303
|
+
export type RuntimeEvent = ActionStartedEvent | ActionFinishedEvent | ServiceStartedEvent | ServiceStoppedEvent | FlowUpdatedEvent | FlowReloadedEvent | FlowFinishedEvent | ScheduleFiredEvent | FlowsReloadingEvent | FlowsReloadedEvent | SessionStateEvent | FlowSuspendedEvent | FlowResumedEvent;
|
|
304
|
+
export type RuntimeEventListener = (event: RuntimeEvent) => void;
|
|
305
|
+
export type Unsubscribe = () => void;
|
|
306
|
+
export interface FlowPatch {
|
|
307
|
+
readonly enabled?: boolean;
|
|
308
|
+
readonly config?: unknown;
|
|
309
|
+
readonly session?: string;
|
|
310
|
+
readonly cron?: string;
|
|
311
|
+
readonly intervalSeconds?: number;
|
|
312
|
+
readonly title?: string;
|
|
313
|
+
readonly symbol?: string;
|
|
314
|
+
readonly autoStart?: boolean;
|
|
315
|
+
readonly maxRuns?: number;
|
|
316
|
+
readonly logFile?: boolean;
|
|
317
|
+
readonly actions?: readonly ActionSpecInput[];
|
|
318
|
+
readonly run?: ActionSpecInput | string;
|
|
319
|
+
}
|
|
320
|
+
export interface RuntimeControl {
|
|
321
|
+
readonly snapshot: RuntimeSnapshot;
|
|
322
|
+
executeAction(spec: ActionSpecInput): Promise<void>;
|
|
323
|
+
runFlow(identifier: string): Promise<void>;
|
|
324
|
+
updateFlow(identifier: string, patch: FlowPatch): Promise<boolean>;
|
|
325
|
+
reloadFlow(identifier: string): Promise<boolean>;
|
|
326
|
+
startService(identifier: string): Promise<void>;
|
|
327
|
+
stopService(identifier: string): Promise<void>;
|
|
328
|
+
reload(): Promise<void>;
|
|
329
|
+
reconnectSession(name: string): Promise<void>;
|
|
330
|
+
listPlugins(): readonly PluginInfo[];
|
|
331
|
+
subscribe(listener: RuntimeEventListener): Unsubscribe;
|
|
332
|
+
}
|
|
333
|
+
export interface CapabilityOptions {
|
|
334
|
+
readonly control?: boolean;
|
|
335
|
+
}
|
|
336
|
+
export type ActionConstructor = new (context: ActionContext<any>) => Action<any>;
|
|
337
|
+
export type TriggerConstructor = new (context: TriggerContext<any>) => Trigger<any>;
|
|
338
|
+
export type ServiceConstructor = new (context: ServiceContext<any>) => Service<any>;
|
|
339
|
+
export interface PluginCapability {
|
|
340
|
+
readonly kind: CapabilityKind;
|
|
341
|
+
readonly name: string;
|
|
342
|
+
readonly handler?: string;
|
|
343
|
+
readonly control?: boolean;
|
|
344
|
+
}
|
|
345
|
+
export interface PluginInfo {
|
|
346
|
+
readonly name: string;
|
|
347
|
+
readonly version?: string;
|
|
348
|
+
readonly capabilities: readonly PluginCapability[];
|
|
349
|
+
readonly loaded: boolean;
|
|
350
|
+
}
|
|
351
|
+
export interface PluginModule {
|
|
352
|
+
readonly [handler: string]: unknown;
|
|
353
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
export class SessionUnavailableError extends Error {
|
|
2
|
+
session;
|
|
3
|
+
state;
|
|
4
|
+
constructor(session, state, reason) {
|
|
5
|
+
super("session " + session + " is " + state + (reason ? ": " + reason : ""));
|
|
6
|
+
this.session = session;
|
|
7
|
+
this.state = state;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function isSessionUnavailable(error) {
|
|
11
|
+
return error instanceof SessionUnavailableError;
|
|
12
|
+
}
|
|
13
|
+
export class Action {
|
|
14
|
+
context;
|
|
15
|
+
constructor(context) {
|
|
16
|
+
this.context = context;
|
|
17
|
+
}
|
|
18
|
+
get id() {
|
|
19
|
+
return this.context.id;
|
|
20
|
+
}
|
|
21
|
+
get config() {
|
|
22
|
+
return this.context.config;
|
|
23
|
+
}
|
|
24
|
+
set config(value) {
|
|
25
|
+
this.context.config = value;
|
|
26
|
+
}
|
|
27
|
+
get session() {
|
|
28
|
+
return this.context.session;
|
|
29
|
+
}
|
|
30
|
+
get signal() {
|
|
31
|
+
return this.context.signal;
|
|
32
|
+
}
|
|
33
|
+
get sessions() {
|
|
34
|
+
return this.context.sessions;
|
|
35
|
+
}
|
|
36
|
+
get control() {
|
|
37
|
+
return this.context.control;
|
|
38
|
+
}
|
|
39
|
+
get emission() {
|
|
40
|
+
return this.context.emission;
|
|
41
|
+
}
|
|
42
|
+
async execute() {
|
|
43
|
+
const baseline = cloneValue(this.context.config);
|
|
44
|
+
try {
|
|
45
|
+
if (this.context.hook) {
|
|
46
|
+
const result = await this.context.hook({
|
|
47
|
+
config: this.context.config,
|
|
48
|
+
emission: this.context.emission,
|
|
49
|
+
signal: this.context.signal
|
|
50
|
+
});
|
|
51
|
+
const decision = normalizeHookResult(result, this.context.config);
|
|
52
|
+
this.context.config = decision.config;
|
|
53
|
+
this.context.outcome = { skipped: decision.skip, effectiveConfig: cloneValue(decision.config) };
|
|
54
|
+
if (decision.skip)
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
await this.run();
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
this.context.config = baseline;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export class Trigger {
|
|
65
|
+
context;
|
|
66
|
+
runCount = 0;
|
|
67
|
+
constructor(context) {
|
|
68
|
+
this.context = context;
|
|
69
|
+
}
|
|
70
|
+
get id() {
|
|
71
|
+
return this.context.id;
|
|
72
|
+
}
|
|
73
|
+
get config() {
|
|
74
|
+
return this.context.config;
|
|
75
|
+
}
|
|
76
|
+
get session() {
|
|
77
|
+
return this.context.session;
|
|
78
|
+
}
|
|
79
|
+
get signal() {
|
|
80
|
+
return this.context.signal;
|
|
81
|
+
}
|
|
82
|
+
get sessions() {
|
|
83
|
+
return this.context.sessions;
|
|
84
|
+
}
|
|
85
|
+
get control() {
|
|
86
|
+
return this.context.control;
|
|
87
|
+
}
|
|
88
|
+
async emit(event) {
|
|
89
|
+
if (!this.context.emit || !this.canRun())
|
|
90
|
+
return;
|
|
91
|
+
this.recordRun();
|
|
92
|
+
await this.context.emit(event);
|
|
93
|
+
}
|
|
94
|
+
canRun() {
|
|
95
|
+
return this.context.maxRuns === undefined || this.runCount < this.context.maxRuns;
|
|
96
|
+
}
|
|
97
|
+
recordRun() {
|
|
98
|
+
this.runCount += 1;
|
|
99
|
+
return this.context.maxRuns === undefined || this.runCount < this.context.maxRuns;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export class Service {
|
|
103
|
+
context;
|
|
104
|
+
constructor(context) {
|
|
105
|
+
this.context = context;
|
|
106
|
+
}
|
|
107
|
+
get id() {
|
|
108
|
+
return this.context.id;
|
|
109
|
+
}
|
|
110
|
+
get config() {
|
|
111
|
+
return this.context.config;
|
|
112
|
+
}
|
|
113
|
+
get session() {
|
|
114
|
+
return this.context.session;
|
|
115
|
+
}
|
|
116
|
+
get signal() {
|
|
117
|
+
return this.context.signal;
|
|
118
|
+
}
|
|
119
|
+
get sessions() {
|
|
120
|
+
return this.context.sessions;
|
|
121
|
+
}
|
|
122
|
+
get control() {
|
|
123
|
+
return this.context.control;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function normalizeHookResult(result, current) {
|
|
127
|
+
if (isHookResult(result)) {
|
|
128
|
+
return {
|
|
129
|
+
config: result.config === undefined ? current : mergeConfig(current, result.config),
|
|
130
|
+
skip: result.skip === true
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return { config: result === undefined ? current : mergeConfig(current, result), skip: false };
|
|
134
|
+
}
|
|
135
|
+
function isHookResult(value) {
|
|
136
|
+
return typeof value === "object" && value !== null && ("config" in value || "skip" in value);
|
|
137
|
+
}
|
|
138
|
+
function mergeConfig(current, next) {
|
|
139
|
+
if (isRecord(current) && isRecord(next))
|
|
140
|
+
return { ...current, ...next };
|
|
141
|
+
return next;
|
|
142
|
+
}
|
|
143
|
+
function isRecord(value) {
|
|
144
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
145
|
+
}
|
|
146
|
+
function cloneValue(value) {
|
|
147
|
+
return structuredClone(value);
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgCA,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAErC,OAAO;IACP,KAAK;IAFhB,YACW,OAAe,EACf,KAAmB,EAC5B,MAAe;QAEf,KAAK,CAAC,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;uBAJpE,OAAO;qBACP,KAAK;IAIhB,CAAC;CACF;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,OAAO,KAAK,YAAY,uBAAuB,CAAC;AAClD,CAAC;AAoCD,MAAM,OAAgB,MAAM;IACK,OAAO;IAAtC,YAA+B,OAAyB;uBAAzB,OAAO;IAAqB,CAAC;IAE5D,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;IACzB,CAAC;IAED,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;AAChG,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,QAAQ,IAAI,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC;AAC/F,CAAC;AAED,SAAS,WAAW,CAAC,OAAgB,EAAE,IAAa;IAClD,IAAI,QAAQ,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,IAAI,EAAE,CAAC;IACxE,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,UAAU,CAAI,KAAQ;IAC7B,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@paperkite/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"development": "./src/index.ts",
|
|
8
|
+
"default": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p tsconfig.json",
|
|
20
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
21
|
+
}
|
|
22
|
+
}
|