@memberjunction/work-queue-core 0.0.1-seed.1 → 6.2.0-edge.4
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/LICENSE +183 -0
- package/README.md +129 -3
- package/dist/api/WorkQueueApiPublisher.d.ts +35 -0
- package/dist/api/WorkQueueApiPublisher.d.ts.map +1 -0
- package/dist/api/WorkQueueApiPublisher.js +136 -0
- package/dist/api/WorkQueueApiPublisher.js.map +1 -0
- package/dist/api/restContract.d.ts +50 -0
- package/dist/api/restContract.d.ts.map +1 -0
- package/dist/api/restContract.js +247 -0
- package/dist/api/restContract.js.map +1 -0
- package/dist/backoff.d.ts +15 -0
- package/dist/backoff.d.ts.map +1 -0
- package/dist/backoff.js +29 -0
- package/dist/backoff.js.map +1 -0
- package/dist/compatibility.d.ts +10 -0
- package/dist/compatibility.d.ts.map +1 -0
- package/dist/compatibility.js +41 -0
- package/dist/compatibility.js.map +1 -0
- package/dist/envelope.d.ts +33 -0
- package/dist/envelope.d.ts.map +1 -0
- package/dist/envelope.js +2 -0
- package/dist/envelope.js.map +1 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +23 -0
- package/dist/errors.js.map +1 -0
- package/dist/filter.d.ts +12 -0
- package/dist/filter.d.ts.map +1 -0
- package/dist/filter.js +187 -0
- package/dist/filter.js.map +1 -0
- package/dist/filterTypes.d.ts +25 -0
- package/dist/filterTypes.d.ts.map +1 -0
- package/dist/filterTypes.js +2 -0
- package/dist/filterTypes.js.map +1 -0
- package/dist/handler.d.ts +56 -0
- package/dist/handler.d.ts.map +1 -0
- package/dist/handler.js +25 -0
- package/dist/handler.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.d.ts +46 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +2 -0
- package/dist/manifest.js.map +1 -0
- package/dist/memory/InMemoryConsumer.d.ts +18 -0
- package/dist/memory/InMemoryConsumer.d.ts.map +1 -0
- package/dist/memory/InMemoryConsumer.js +36 -0
- package/dist/memory/InMemoryConsumer.js.map +1 -0
- package/dist/memory/InMemoryOperator.d.ts +13 -0
- package/dist/memory/InMemoryOperator.d.ts.map +1 -0
- package/dist/memory/InMemoryOperator.js +25 -0
- package/dist/memory/InMemoryOperator.js.map +1 -0
- package/dist/memory/InMemoryStore.d.ts +82 -0
- package/dist/memory/InMemoryStore.d.ts.map +1 -0
- package/dist/memory/InMemoryStore.js +436 -0
- package/dist/memory/InMemoryStore.js.map +1 -0
- package/dist/memory/InMemoryTransport.d.ts +29 -0
- package/dist/memory/InMemoryTransport.d.ts.map +1 -0
- package/dist/memory/InMemoryTransport.js +48 -0
- package/dist/memory/InMemoryTransport.js.map +1 -0
- package/dist/operator.d.ts +60 -0
- package/dist/operator.d.ts.map +1 -0
- package/dist/operator.js +2 -0
- package/dist/operator.js.map +1 -0
- package/dist/policy.d.ts +24 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +10 -0
- package/dist/policy.js.map +1 -0
- package/dist/publishing.d.ts +58 -0
- package/dist/publishing.d.ts.map +1 -0
- package/dist/publishing.js +40 -0
- package/dist/publishing.js.map +1 -0
- package/dist/runtime/ConsumerRuntime.d.ts +46 -0
- package/dist/runtime/ConsumerRuntime.d.ts.map +1 -0
- package/dist/runtime/ConsumerRuntime.js +252 -0
- package/dist/runtime/ConsumerRuntime.js.map +1 -0
- package/dist/runtime/DeliveryExecution.d.ts +83 -0
- package/dist/runtime/DeliveryExecution.d.ts.map +1 -0
- package/dist/runtime/DeliveryExecution.js +0 -0
- package/dist/runtime/DeliveryExecution.js.map +1 -0
- package/dist/runtime/outcomes.d.ts +28 -0
- package/dist/runtime/outcomes.d.ts.map +1 -0
- package/dist/runtime/outcomes.js +65 -0
- package/dist/runtime/outcomes.js.map +1 -0
- package/dist/runtime/types.d.ts +14 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +2 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/testing/ConformanceHarness.d.ts +45 -0
- package/dist/testing/ConformanceHarness.d.ts.map +1 -0
- package/dist/testing/ConformanceHarness.js +2 -0
- package/dist/testing/ConformanceHarness.js.map +1 -0
- package/dist/testing/ConformanceScenario.d.ts +29 -0
- package/dist/testing/ConformanceScenario.d.ts.map +1 -0
- package/dist/testing/ConformanceScenario.js +83 -0
- package/dist/testing/ConformanceScenario.js.map +1 -0
- package/dist/testing/RunConformanceChecks.d.ts +10 -0
- package/dist/testing/RunConformanceChecks.d.ts.map +1 -0
- package/dist/testing/RunConformanceChecks.js +50 -0
- package/dist/testing/RunConformanceChecks.js.map +1 -0
- package/dist/testing/assertions.d.ts +13 -0
- package/dist/testing/assertions.d.ts.map +1 -0
- package/dist/testing/assertions.js +66 -0
- package/dist/testing/assertions.js.map +1 -0
- package/dist/testing/conformanceCases.d.ts +4 -0
- package/dist/testing/conformanceCases.d.ts.map +1 -0
- package/dist/testing/conformanceCases.js +359 -0
- package/dist/testing/conformanceCases.js.map +1 -0
- package/dist/testing/fixtures.d.ts +21 -0
- package/dist/testing/fixtures.d.ts.map +1 -0
- package/dist/testing/fixtures.js +39 -0
- package/dist/testing/fixtures.js.map +1 -0
- package/dist/testing/index.d.ts +6 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +5 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/vitest.d.ts +4 -0
- package/dist/testing/vitest.d.ts.map +1 -0
- package/dist/testing/vitest.js +19 -0
- package/dist/testing/vitest.js.map +1 -0
- package/dist/transport.d.ts +106 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +2 -0
- package/dist/transport.js.map +1 -0
- package/dist/validation.d.ts +26 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +177 -0
- package/dist/validation.js.map +1 -0
- package/package.json +46 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
Business Source License 1.1
|
|
2
|
+
|
|
3
|
+
License text copyright (c) 2024 MariaDB plc, All Rights Reserved.
|
|
4
|
+
"Business Source License" is a trademark of MariaDB plc.
|
|
5
|
+
|
|
6
|
+
-----------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
Parameters
|
|
9
|
+
|
|
10
|
+
Licensor: Blue Cypress, Inc.
|
|
11
|
+
|
|
12
|
+
Licensed Work: MemberJunction.
|
|
13
|
+
The Licensed Work is (c) 2023-2026 Blue Cypress, Inc.
|
|
14
|
+
|
|
15
|
+
Additional Use Grant: Subject to the terms of this License, Licensor grants
|
|
16
|
+
you the following additional rights to make Production
|
|
17
|
+
Use of the Licensed Work.
|
|
18
|
+
|
|
19
|
+
1. Internal Use
|
|
20
|
+
|
|
21
|
+
You may make production use of the Licensed Work for
|
|
22
|
+
your own internal business or organizational operations.
|
|
23
|
+
|
|
24
|
+
2. Nonprofit Use
|
|
25
|
+
|
|
26
|
+
If you are a Nonprofit, you may make production use of
|
|
27
|
+
the Licensed Work for the operations and activities of
|
|
28
|
+
your Organizational Family.
|
|
29
|
+
|
|
30
|
+
3. MemberJunction Certified Program Use
|
|
31
|
+
|
|
32
|
+
If you are authorized by Licensor under the
|
|
33
|
+
MemberJunction Certified Program to provide professional
|
|
34
|
+
services using the Licensed Work, you may make
|
|
35
|
+
production use of the Licensed Work in providing such
|
|
36
|
+
professional services to a client, provided that:
|
|
37
|
+
|
|
38
|
+
(a) the Licensed Work is deployed in, and the applicable
|
|
39
|
+
production use occurs within, an environment owned,
|
|
40
|
+
leased, licensed, subscribed to, or otherwise controlled
|
|
41
|
+
by that client; and
|
|
42
|
+
|
|
43
|
+
(b) the production use is for that client's own internal
|
|
44
|
+
business or organizational operations or is otherwise
|
|
45
|
+
independently permitted to that client under this
|
|
46
|
+
Additional Use Grant.
|
|
47
|
+
|
|
48
|
+
4. Definitions Applicable to the Additional Use Grant
|
|
49
|
+
|
|
50
|
+
"Affiliate" means, with respect to a specified Person,
|
|
51
|
+
any other Person that directly or indirectly Controls,
|
|
52
|
+
is Controlled by, or is under common Control with such
|
|
53
|
+
specified Person.
|
|
54
|
+
|
|
55
|
+
"Control" (including the terms "Controls," "Controlled
|
|
56
|
+
by," and "under common Control with") means the direct
|
|
57
|
+
or indirect possession of the power to direct or cause
|
|
58
|
+
the direction of the management and policies of a
|
|
59
|
+
Person, whether through ownership of voting interests,
|
|
60
|
+
by contract, or otherwise.
|
|
61
|
+
|
|
62
|
+
"Organizational Family" means, with respect to a Person,
|
|
63
|
+
(a) such Person and its Affiliates, and (b) any
|
|
64
|
+
nonprofit organization, governmental entity, chapter,
|
|
65
|
+
division, local affiliate, regional affiliate, state
|
|
66
|
+
affiliate, national affiliate, or other entity that is
|
|
67
|
+
formally affiliated with such Person through governing
|
|
68
|
+
documents, a charter, bylaws, a membership agreement, or
|
|
69
|
+
another written organizational instrument, and is
|
|
70
|
+
recognized under such documents as part of the same
|
|
71
|
+
organizational structure.
|
|
72
|
+
|
|
73
|
+
"Nonprofit" means a Person recognized by the Internal
|
|
74
|
+
Revenue Service as exempt from federal income taxation
|
|
75
|
+
under Section 501(c)(3), 501(c)(4), 501(c)(5), or
|
|
76
|
+
501(c)(6) of the Internal Revenue Code, or a foreign
|
|
77
|
+
organization recognized under substantially equivalent
|
|
78
|
+
laws.
|
|
79
|
+
|
|
80
|
+
A Person claiming eligibility as a Nonprofit shall, upon
|
|
81
|
+
Licensor's reasonable request, provide documentation
|
|
82
|
+
reasonably sufficient to demonstrate that it qualifies
|
|
83
|
+
as a Nonprofit. If such Person materially misrepresents,
|
|
84
|
+
or is unable to demonstrate, its qualification as a
|
|
85
|
+
Nonprofit, the rights granted to such Person under
|
|
86
|
+
Section 2 of this Additional Use Grant shall terminate.
|
|
87
|
+
|
|
88
|
+
"MemberJunction Certified Program" means Licensor's
|
|
89
|
+
then-current program for certifying and authorizing a
|
|
90
|
+
Person to provide professional services using the
|
|
91
|
+
Licensed Work.
|
|
92
|
+
|
|
93
|
+
"Person" means any individual, corporation, limited
|
|
94
|
+
liability company, partnership, association, nonprofit
|
|
95
|
+
organization, governmental entity, or other legal or
|
|
96
|
+
organizational entity.
|
|
97
|
+
|
|
98
|
+
Change Date: Four (4) years from the date the Licensed Work is first
|
|
99
|
+
made available.
|
|
100
|
+
|
|
101
|
+
Change License: MIT License.
|
|
102
|
+
|
|
103
|
+
For information about alternative licensing arrangements for the Licensed
|
|
104
|
+
Work, please contact Blue Cypress, Inc.
|
|
105
|
+
|
|
106
|
+
-----------------------------------------------------------------------------
|
|
107
|
+
|
|
108
|
+
Terms
|
|
109
|
+
|
|
110
|
+
The Licensor hereby grants you the right to copy, modify, create derivative
|
|
111
|
+
works, redistribute, and make non-production use of the Licensed Work. The
|
|
112
|
+
Licensor may make an Additional Use Grant, above, permitting limited
|
|
113
|
+
production use.
|
|
114
|
+
|
|
115
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly
|
|
116
|
+
available distribution of a specific version of the Licensed Work under this
|
|
117
|
+
License, whichever comes first, the Licensor hereby grants you rights under
|
|
118
|
+
the terms of the Change License, and the rights granted in the paragraph
|
|
119
|
+
above terminate.
|
|
120
|
+
|
|
121
|
+
If your use of the Licensed Work does not comply with the requirements
|
|
122
|
+
currently in effect as described in this License, you must purchase a
|
|
123
|
+
commercial license from the Licensor, its affiliated entities, or authorized
|
|
124
|
+
resellers, or you must refrain from using the Licensed Work.
|
|
125
|
+
|
|
126
|
+
All copies of the original and modified Licensed Work, and derivative works
|
|
127
|
+
of the Licensed Work, are subject to this License. This License applies
|
|
128
|
+
separately for each version of the Licensed Work and the Change Date may vary
|
|
129
|
+
for each version of the Licensed Work released by Licensor.
|
|
130
|
+
|
|
131
|
+
You must conspicuously display this License on each original or modified copy
|
|
132
|
+
of the Licensed Work. If you receive the Licensed Work in original or
|
|
133
|
+
modified form from a third party, the terms and conditions set forth in this
|
|
134
|
+
License apply to your use of that work.
|
|
135
|
+
|
|
136
|
+
Any use of the Licensed Work in violation of this License will automatically
|
|
137
|
+
terminate your rights under this License for the current and all other
|
|
138
|
+
versions of the Licensed Work.
|
|
139
|
+
|
|
140
|
+
This License does not grant you any right in any trademark or logo of
|
|
141
|
+
Licensor or its affiliates (provided that you may use a trademark or logo of
|
|
142
|
+
Licensor as expressly required by this License).
|
|
143
|
+
|
|
144
|
+
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
|
|
145
|
+
AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
|
|
146
|
+
EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
|
|
147
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
|
|
148
|
+
TITLE.
|
|
149
|
+
|
|
150
|
+
MariaDB hereby grants you permission to use this License's text to license
|
|
151
|
+
your works, and to refer to it using the trademark "Business Source License",
|
|
152
|
+
as long as you comply with the Covenants of Licensor below.
|
|
153
|
+
|
|
154
|
+
-----------------------------------------------------------------------------
|
|
155
|
+
|
|
156
|
+
Covenants of Licensor
|
|
157
|
+
|
|
158
|
+
In consideration of the right to use this License's text and the "Business
|
|
159
|
+
Source License" name and trademark, Licensor covenants to MariaDB, and to all
|
|
160
|
+
other recipients of the licensed work to be provided by Licensor:
|
|
161
|
+
|
|
162
|
+
1. To specify as the Change License the GPL Version 2.0 or any later version,
|
|
163
|
+
or a license that is compatible with GPL Version 2.0 or a later version,
|
|
164
|
+
where "compatible" means that software provided under the Change License
|
|
165
|
+
can be included in a program with software provided under GPL Version 2.0
|
|
166
|
+
or a later version. Licensor may specify additional Change Licenses without
|
|
167
|
+
limitation.
|
|
168
|
+
|
|
169
|
+
2. To either: (a) specify an additional grant of rights to use that does not
|
|
170
|
+
impose any additional restriction on the right granted in this License, as
|
|
171
|
+
the Additional Use Grant; or (b) insert the text "None".
|
|
172
|
+
|
|
173
|
+
3. To specify a Change Date.
|
|
174
|
+
|
|
175
|
+
4. Not to modify this License in any other way.
|
|
176
|
+
|
|
177
|
+
-----------------------------------------------------------------------------
|
|
178
|
+
|
|
179
|
+
Notice
|
|
180
|
+
|
|
181
|
+
The Business Source License (this document, or the "License") is not an Open
|
|
182
|
+
Source license. However, the Licensed Work will eventually be made available
|
|
183
|
+
under an Open Source License, as stated in this License.
|
package/README.md
CHANGED
|
@@ -1,4 +1,130 @@
|
|
|
1
1
|
# @memberjunction/work-queue-core
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
|
|
3
|
+
Transport-neutral contracts and runtime for the MemberJunction durable work queue. **No MemberJunction
|
|
4
|
+
runtime dependencies** — Lambda and other external consumers import only this package (plus a transport
|
|
5
|
+
package such as `@memberjunction/work-queue-aws`).
|
|
6
|
+
|
|
7
|
+
Design and contract: `02-implementation-overview.md` and `03-interfaces-and-tables.md` under `plans/work-queue-1/` on the `spec/work-queue` branch; the handler author's rules are in `guides/WORK_QUEUE_CONSUMER_GUIDE.md`.
|
|
8
|
+
|
|
9
|
+
## What is in the box
|
|
10
|
+
|
|
11
|
+
| Area | Exports |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| Envelope & publishing | `WorkMessage`, `PublishRequest`, `PublishResult`, `IWorkPublisher`, `ValidatePublishRequest`, `BuildWorkMessage`, `CanonicalEnvelope`, `PublishErrorCodes` |
|
|
14
|
+
| Handlers | `WorkHandler`, `WorkContext`, `Outcome`, `FatalWorkError`, `TransientWorkError` |
|
|
15
|
+
| Policy & rules | `SubscriptionPolicy`, `ParseSubscriptionFilter`, `ValidateSubscriptionFilter`, `MatchesFilter`, `FilterFields`, `WORK_QUEUE_FILTER_SUPPORT`, `ComputeBackoffSeconds`, `HeartbeatIntervalSeconds`, `SubscriptionUnsupportedReason`, `FilterUnsupportedReason` |
|
|
16
|
+
| Transports | `ITransportDriver`, `ITransportConsumer`, `ITransportOperator`, `TransportCapabilities` |
|
|
17
|
+
| Runtime | `ConsumerRuntime` (loop or `ProcessBatch`), `DeliveryExecution` |
|
|
18
|
+
| Reference transport | `InMemoryTransport` (Database-transport semantics, in memory) |
|
|
19
|
+
| REST client | `WorkQueueApiPublisher`, REST mapping helpers |
|
|
20
|
+
| Testing (`/testing`) | `RunConformanceChecks`, `CONFORMANCE_CASES`, `ConformanceAssertionError`, `BuildTopicBinding`, `BuildSubscriptionBinding`, `ManualClock` |
|
|
21
|
+
| Testing with vitest (`/testing/vitest`) | `RunTransportConformanceSuite` |
|
|
22
|
+
|
|
23
|
+
## Writing a handler
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { FatalWorkError, Outcome, type WorkContext, type WorkHandler, type WorkMessage } from '@memberjunction/work-queue-core';
|
|
27
|
+
|
|
28
|
+
interface UnsubscribePayload { email: string; occurredAt: string }
|
|
29
|
+
|
|
30
|
+
export class UnsubscribeHandler implements WorkHandler<UnsubscribePayload> {
|
|
31
|
+
public async Handle(message: WorkMessage<UnsubscribePayload>, context: WorkContext) {
|
|
32
|
+
if (!message.Payload?.email) {
|
|
33
|
+
throw new FatalWorkError('email missing'); // dead-letter immediately
|
|
34
|
+
}
|
|
35
|
+
await suppress(message.Payload.email, message.MessageID); // idempotent by MessageID
|
|
36
|
+
return Outcome.Complete(); // throw anything else → retry with backoff
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Handler rules
|
|
42
|
+
|
|
43
|
+
The queue guarantees durable delivery, one valid lease holder while your handler runs, and fencing. Everything
|
|
44
|
+
else is yours — see `guides/WORK_QUEUE_CONSUMER_GUIDE.md`. Four rules cover most handlers:
|
|
45
|
+
|
|
46
|
+
1. **Long awaits need no heartbeat code.** Keep `HeartbeatMode: 'Auto'` (the default) and set
|
|
47
|
+
`MaxProcessingSeconds` to the longest a healthy run should take: the runtime renews the lease while your
|
|
48
|
+
handler awaits, and aborts once the cap passes. Use `'Manual'` only when you want a *stuck* handler detected,
|
|
49
|
+
then call `await context.Heartbeat({ Percent })` at real progress boundaries.
|
|
50
|
+
2. **Honor `context.Signal`.** It aborts when an operator cancels the item, the lease is lost, the processing cap
|
|
51
|
+
is hit, or the host shuts down; `context.Signal.reason` says which (`'Cancelled'`, `'LeaseLost'`,
|
|
52
|
+
`'MaxProcessingSeconds'`, `'Shutdown'`). Stop whatever external work you started — a child process, a remote
|
|
53
|
+
job, a long query. Stopping promptly matters: after a cancel, the runtime acknowledges it as soon as your
|
|
54
|
+
handler returns, which frees an `Exclusive`/`Ordered` key immediately instead of at lease expiry.
|
|
55
|
+
3. **Never block the event loop.** A long synchronous CPU-bound loop stops the heartbeat timer with it and the
|
|
56
|
+
lease expires under you; move that work to a worker thread or child process.
|
|
57
|
+
4. **Non-restartable side effects need your own guard.** At-least-once delivery means a handler can run twice.
|
|
58
|
+
Make handlers idempotent (`message.MessageID` is stable across redeliveries and replays), and for work that
|
|
59
|
+
must not overlap — an infrastructure apply, a financial posting — set a `LeaseSeconds` larger than your worst
|
|
60
|
+
heartbeat outage *and* hold a domain lock of your own.
|
|
61
|
+
|
|
62
|
+
`context.Heartbeat` resolves `false` once the lease is gone or the delivery is cancelled; a transient transport
|
|
63
|
+
error does not — it is retried on the next tick. The runtime heartbeats every `min(LeaseSeconds / 3, 30 s)`, so a
|
|
64
|
+
cancel or a lost lease is noticed within 30 seconds however long the lease, and it enforces the lease's expiry on
|
|
65
|
+
its own timer in both heartbeat modes — a `Manual` handler that stops heartbeating is aborted when its lease runs
|
|
66
|
+
out.
|
|
67
|
+
|
|
68
|
+
**Ordering is publish order.** There is no producer-supplied ordering number. If one producer owns a key's order,
|
|
69
|
+
it publishes in order: do not publish N+1 until N is accepted, or publish both in one call. `Ordered`
|
|
70
|
+
subscriptions need a topic on the Database transport.
|
|
71
|
+
|
|
72
|
+
## Subscription filters
|
|
73
|
+
|
|
74
|
+
A filter is MJ's standard `CompositeFilterDescriptor` JSON over **envelope attributes** — the shape
|
|
75
|
+
`mj-filter-builder` edits and user views persist — restricted to what every transport can express:
|
|
76
|
+
|
|
77
|
+
```jsonc
|
|
78
|
+
{ "logic": "and", "filters": [
|
|
79
|
+
{ "field": "eventType", "operator": "eq", "value": "click" },
|
|
80
|
+
{ "logic": "or", "filters": [
|
|
81
|
+
{ "field": "tenant", "operator": "eq", "value": "acme" },
|
|
82
|
+
{ "field": "tenant", "operator": "eq", "value": "globex" } ] }
|
|
83
|
+
] }
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Operators: `eq`, `neq`, `startswith`, `isnull`, `isnotnull`. The root is `and`; a nested group may only be a
|
|
87
|
+
single-field OR of `eq`; and each field may be constrained only once (brokers read a field's values as OR, so two
|
|
88
|
+
AND-ed rules on one field would widen the filter rather than narrow it). Matching is **case-sensitive** (brokers match exactly, so MJ and the broker agree),
|
|
89
|
+
which is the one deliberate divergence from `CompositeFilter`'s case-insensitive comparison. Richer filters are
|
|
90
|
+
rejected by `ValidateSubscriptionFilter` / `SubscriptionUnsupportedReason` when a subscription is saved, rather
|
|
91
|
+
than silently delivering everything.
|
|
92
|
+
|
|
93
|
+
## Publishing from outside MJ
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { WorkQueueApiPublisher } from '@memberjunction/work-queue-core';
|
|
97
|
+
|
|
98
|
+
const publisher = new WorkQueueApiPublisher({ BaseUrl: 'https://api.example.com/work-queue', ApiKey: process.env.MJ_API_KEY ?? '' });
|
|
99
|
+
const results = await publisher.Publish('email.events', [
|
|
100
|
+
{ PartitionKey: 'alice@example.com', Attributes: { eventType: 'unsubscribe' }, Payload: { email: 'alice@example.com', occurredAt: '2026-09-16T12:00:00Z' }, DeduplicationKey: 'sg:evt-123' },
|
|
101
|
+
]);
|
|
102
|
+
// Every result is Accepted, Duplicate or Rejected; retry Rejected items whose Error.Retryable is true.
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Testing a transport driver
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { BuildTopicBinding, BuildSubscriptionBinding } from '@memberjunction/work-queue-core/testing';
|
|
109
|
+
import { RunTransportConformanceSuite } from '@memberjunction/work-queue-core/testing/vitest';
|
|
110
|
+
|
|
111
|
+
RunTransportConformanceSuite('MyTransport', {
|
|
112
|
+
Capabilities: MY_CAPABILITIES,
|
|
113
|
+
Traits: { ReleaseConsumesAttempt: false, ExpiredLeaseDeadLetters: true, ReceiveWaitSeconds: 0 },
|
|
114
|
+
CreateDriver: async () => new MyTransport(),
|
|
115
|
+
CreateTopic: async (_driver, name, overrides) => BuildTopicBinding(name, overrides),
|
|
116
|
+
CreateSubscription: async (_driver, topic, name, overrides) => BuildSubscriptionBinding(topic, name, overrides),
|
|
117
|
+
AdvanceTime: async (ms) => clock.Advance(ms),
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Outside vitest (for example an integration runner against a live database), call
|
|
122
|
+
`await RunConformanceChecks(harness)` from `/testing`: it runs the same 26 cases sequentially, never throws, and
|
|
123
|
+
returns `{ Id, Title, Status: 'Passed' | 'Failed' | 'Skipped', Detail, DurationMs }` per case.
|
|
124
|
+
|
|
125
|
+
`vitest` is an optional peer dependency used only by `/testing/vitest`.
|
|
126
|
+
|
|
127
|
+
## Rules for contributors
|
|
128
|
+
|
|
129
|
+
- No `@memberjunction/*` dependency or import, and no runtime `dependencies` — enforced by `src/__tests__/dependencyGuard.test.ts`.
|
|
130
|
+
- `cd packages/WorkQueue/core && pnpm test` and `pnpm run build`.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { WorkJson } from '../envelope.js';
|
|
2
|
+
import type { IWorkPublisher, PublishRequest, PublishResult } from '../publishing.js';
|
|
3
|
+
export interface WorkQueueApiPublisherOptions {
|
|
4
|
+
/** Root of the work-queue REST extension, e.g. https://api.example.com/work-queue */
|
|
5
|
+
BaseUrl: string;
|
|
6
|
+
/** MJ API key with workqueue:publish for the target topics. */
|
|
7
|
+
ApiKey: string;
|
|
8
|
+
Fetch?: typeof fetch;
|
|
9
|
+
/** Retries after the first attempt. Default 3. */
|
|
10
|
+
MaxRetries?: number;
|
|
11
|
+
/** Per-request timeout. Default 10000. */
|
|
12
|
+
TimeoutMs?: number;
|
|
13
|
+
/** Base for exponential retry delay. Default 200. */
|
|
14
|
+
RetryBaseDelayMs?: number;
|
|
15
|
+
NewId?: () => string;
|
|
16
|
+
Sleep?: (ms: number) => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export declare class WorkQueueApiPublisher implements IWorkPublisher {
|
|
19
|
+
private readonly options;
|
|
20
|
+
private readonly baseUrl;
|
|
21
|
+
private readonly fetchImpl;
|
|
22
|
+
private readonly maxRetries;
|
|
23
|
+
private readonly timeoutMs;
|
|
24
|
+
private readonly retryBaseDelayMs;
|
|
25
|
+
private readonly newId;
|
|
26
|
+
private readonly sleep;
|
|
27
|
+
constructor(options: WorkQueueApiPublisherOptions);
|
|
28
|
+
Publish<TPayload extends WorkJson>(topic: string, requests: PublishRequest<TPayload>[]): Promise<PublishResult[]>;
|
|
29
|
+
private publishChunk;
|
|
30
|
+
private send;
|
|
31
|
+
private retryDelayMs;
|
|
32
|
+
}
|
|
33
|
+
/** Upper bound on a server-requested wait: a hostile or mistaken header must not park a producer. */
|
|
34
|
+
export declare const MAX_RETRY_AFTER_SECONDS = 60;
|
|
35
|
+
//# sourceMappingURL=WorkQueueApiPublisher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WorkQueueApiPublisher.d.ts","sourceRoot":"","sources":["../../src/api/WorkQueueApiPublisher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAInF,MAAM,WAAW,4BAA4B;IACzC,qFAAqF;IACrF,OAAO,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACzC;AA2BD,qBAAa,qBAAsB,YAAW,cAAc;IAS5C,OAAO,CAAC,QAAQ,CAAC,OAAO;IARpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;IACzC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IACrC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgC;gBAEzB,OAAO,EAAE,4BAA4B;IAUrD,OAAO,CAAC,QAAQ,SAAS,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;YAShH,YAAY;YAgBZ,IAAI;IAoBlB,OAAO,CAAC,YAAY;CAMvB;AA2CD,qGAAqG;AACrG,eAAO,MAAM,uBAAuB,KAAK,CAAC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { PublishErrorCodes, RejectedPublishResult } from '../publishing.js';
|
|
2
|
+
import { MAX_REST_PUBLISH_BATCH, ParseRestPublishResponse, ToRestPublishRequest } from './restContract.js';
|
|
3
|
+
const FALLBACK_CODES = new Map([
|
|
4
|
+
[400, PublishErrorCodes.BadRequest],
|
|
5
|
+
[401, PublishErrorCodes.Unauthorized],
|
|
6
|
+
[403, PublishErrorCodes.Forbidden],
|
|
7
|
+
[404, PublishErrorCodes.TopicNotFound],
|
|
8
|
+
[413, PublishErrorCodes.PayloadTooLarge],
|
|
9
|
+
]);
|
|
10
|
+
/** IWorkPublisher for producers outside MJ: calls the MJ work-queue REST publish endpoint (spec 03 §9). */
|
|
11
|
+
/** Drops every trailing '/' without a regex (a `/\/+$/` pattern on caller input is polynomial-time). */
|
|
12
|
+
function TrimTrailingSlashes(url) {
|
|
13
|
+
let end = url.length;
|
|
14
|
+
while (end > 0 && url[end - 1] === '/') {
|
|
15
|
+
end -= 1;
|
|
16
|
+
}
|
|
17
|
+
return url.slice(0, end);
|
|
18
|
+
}
|
|
19
|
+
export class WorkQueueApiPublisher {
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.options = options;
|
|
22
|
+
this.baseUrl = TrimTrailingSlashes(options.BaseUrl);
|
|
23
|
+
this.fetchImpl = options.Fetch ?? ((input, init) => fetch(input, init));
|
|
24
|
+
this.maxRetries = options.MaxRetries ?? 3;
|
|
25
|
+
this.timeoutMs = options.TimeoutMs ?? 10_000;
|
|
26
|
+
this.retryBaseDelayMs = options.RetryBaseDelayMs ?? 200;
|
|
27
|
+
this.newId = options.NewId ?? (() => crypto.randomUUID());
|
|
28
|
+
this.sleep = options.Sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
29
|
+
}
|
|
30
|
+
async Publish(topic, requests) {
|
|
31
|
+
const identified = requests.map((request) => ({ ...request, MessageID: request.MessageID ?? this.newId() }));
|
|
32
|
+
const results = [];
|
|
33
|
+
for (let start = 0; start < identified.length; start += MAX_REST_PUBLISH_BATCH) {
|
|
34
|
+
results.push(...(await this.publishChunk(topic, identified.slice(start, start + MAX_REST_PUBLISH_BATCH))));
|
|
35
|
+
}
|
|
36
|
+
return results;
|
|
37
|
+
}
|
|
38
|
+
async publishChunk(topic, chunk) {
|
|
39
|
+
const url = `${this.baseUrl}/topics/${encodeURIComponent(topic)}/messages`;
|
|
40
|
+
const body = JSON.stringify({ messages: chunk.map((request) => ToRestPublishRequest(request)) });
|
|
41
|
+
for (let attempt = 0;; attempt += 1) {
|
|
42
|
+
const outcome = await this.send(url, body);
|
|
43
|
+
if (outcome.Kind === 'Response' && !isRetryableStatus(outcome.Status)) {
|
|
44
|
+
return mapResponse(outcome.Status, outcome.Body, chunk);
|
|
45
|
+
}
|
|
46
|
+
if (attempt >= this.maxRetries) {
|
|
47
|
+
const reason = outcome.Kind === 'Response' ? `HTTP ${outcome.Status}` : outcome.Error;
|
|
48
|
+
return chunk.map((request) => RejectedPublishResult(request.MessageID, PublishErrorCodes.TransportUnavailable, reason));
|
|
49
|
+
}
|
|
50
|
+
await this.sleep(this.retryDelayMs(attempt, outcome));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async send(url, body) {
|
|
54
|
+
const controller = new AbortController();
|
|
55
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
56
|
+
try {
|
|
57
|
+
const response = await this.fetchImpl(url, {
|
|
58
|
+
method: 'POST',
|
|
59
|
+
headers: { 'Content-Type': 'application/json', 'X-API-Key': this.options.ApiKey },
|
|
60
|
+
body,
|
|
61
|
+
signal: controller.signal,
|
|
62
|
+
});
|
|
63
|
+
const text = await response.text();
|
|
64
|
+
return { Kind: 'Response', Status: response.status, Body: parseJson(text), RetryAfterSeconds: parseRetryAfter(response.headers.get('Retry-After')) };
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
const message = controller.signal.aborted ? `Timed out after ${this.timeoutMs} ms` : error instanceof Error ? error.message : String(error);
|
|
68
|
+
return { Kind: 'NetworkError', Error: message };
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
clearTimeout(timer);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
retryDelayMs(attempt, outcome) {
|
|
75
|
+
if (outcome.Kind === 'Response' && outcome.RetryAfterSeconds !== null) {
|
|
76
|
+
return outcome.RetryAfterSeconds * 1000;
|
|
77
|
+
}
|
|
78
|
+
return this.retryBaseDelayMs * Math.pow(2, attempt);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function isRetryableStatus(status) {
|
|
82
|
+
return status === 429 || status >= 500;
|
|
83
|
+
}
|
|
84
|
+
function mapResponse(status, body, chunk) {
|
|
85
|
+
if (status === 200 || status === 202) {
|
|
86
|
+
const parsed = ParseRestPublishResponse(body, chunk.length);
|
|
87
|
+
if (parsed !== null) {
|
|
88
|
+
return parsed;
|
|
89
|
+
}
|
|
90
|
+
return chunk.map((request) => RejectedPublishResult(request.MessageID, PublishErrorCodes.InvalidResponse, `Unexpected response body for HTTP ${status}`));
|
|
91
|
+
}
|
|
92
|
+
const { Code, Message } = readErrorBody(status, body);
|
|
93
|
+
return chunk.map((request) => RejectedPublishResult(request.MessageID, Code, Message));
|
|
94
|
+
}
|
|
95
|
+
function readErrorBody(status, body) {
|
|
96
|
+
const fallback = FALLBACK_CODES.get(status) ?? `Http${status}`;
|
|
97
|
+
if (typeof body !== 'object' || body === null) {
|
|
98
|
+
return { Code: fallback, Message: `HTTP ${status}` };
|
|
99
|
+
}
|
|
100
|
+
const code = Reflect.get(body, 'code');
|
|
101
|
+
const message = Reflect.get(body, 'message');
|
|
102
|
+
return {
|
|
103
|
+
Code: typeof code === 'string' ? code : fallback,
|
|
104
|
+
Message: typeof message === 'string' ? message : `HTTP ${status}`,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function parseJson(text) {
|
|
108
|
+
if (text.trim() === '') {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const parsed = JSON.parse(text);
|
|
113
|
+
return parsed;
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** Upper bound on a server-requested wait: a hostile or mistaken header must not park a producer. */
|
|
120
|
+
export const MAX_RETRY_AFTER_SECONDS = 60;
|
|
121
|
+
/** RFC 9110 Retry-After: delta-seconds or an HTTP date. Capped at MAX_RETRY_AFTER_SECONDS. */
|
|
122
|
+
function parseRetryAfter(header) {
|
|
123
|
+
if (header === null || header.trim() === '') {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
const seconds = Number(header);
|
|
127
|
+
if (Number.isFinite(seconds)) {
|
|
128
|
+
return seconds >= 0 ? Math.min(seconds, MAX_RETRY_AFTER_SECONDS) : null;
|
|
129
|
+
}
|
|
130
|
+
const at = Date.parse(header);
|
|
131
|
+
if (Number.isNaN(at)) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
return Math.min(Math.max(0, (at - Date.now()) / 1000), MAX_RETRY_AFTER_SECONDS);
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=WorkQueueApiPublisher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WorkQueueApiPublisher.js","sourceRoot":"","sources":["../../src/api/WorkQueueApiPublisher.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAwBxG,MAAM,cAAc,GAAgC,IAAI,GAAG,CAAiB;IACxE,CAAC,GAAG,EAAE,iBAAiB,CAAC,UAAU,CAAC;IACnC,CAAC,GAAG,EAAE,iBAAiB,CAAC,YAAY,CAAC;IACrC,CAAC,GAAG,EAAE,iBAAiB,CAAC,SAAS,CAAC;IAClC,CAAC,GAAG,EAAE,iBAAiB,CAAC,aAAa,CAAC;IACtC,CAAC,GAAG,EAAE,iBAAiB,CAAC,eAAe,CAAC;CAC3C,CAAC,CAAC;AAEH,2GAA2G;AAE3G,wGAAwG;AACxG,SAAS,mBAAmB,CAAC,GAAW;IACpC,IA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B,CAAC;AACL,CAAC;AAED,qGAAqG;AACrG,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAE1C,8FAA8F;AAC9F,SAAS,eAAe,CAAC,MAAqB;IAC1C,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAC1C,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/B,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,OAAO,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC5E,CAAC;IACD,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9B,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,uBAAuB,CAAC,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { WorkJson } from '../envelope.js';
|
|
2
|
+
import type { PublishRequest, PublishResult, PublishStatus } from '../publishing.js';
|
|
3
|
+
export declare const MAX_REST_PUBLISH_BATCH = 100;
|
|
4
|
+
export interface RestPayloadRefJson {
|
|
5
|
+
uri: string;
|
|
6
|
+
contentType?: string;
|
|
7
|
+
sizeBytes?: number;
|
|
8
|
+
checksum?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface RestPublishRequestJson {
|
|
11
|
+
messageId?: string;
|
|
12
|
+
partitionKey?: string;
|
|
13
|
+
attributes?: Record<string, string>;
|
|
14
|
+
payload?: WorkJson;
|
|
15
|
+
payloadRef?: RestPayloadRefJson;
|
|
16
|
+
correlationId?: string;
|
|
17
|
+
deduplicationKey?: string;
|
|
18
|
+
deduplicationTtlSeconds?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface RestPublishBodyJson {
|
|
21
|
+
messages: RestPublishRequestJson[];
|
|
22
|
+
}
|
|
23
|
+
export interface RestPublishErrorJson {
|
|
24
|
+
code: string;
|
|
25
|
+
message: string;
|
|
26
|
+
retryable: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface RestPublishResultJson {
|
|
29
|
+
messageId: string;
|
|
30
|
+
status: PublishStatus;
|
|
31
|
+
error?: RestPublishErrorJson;
|
|
32
|
+
}
|
|
33
|
+
export interface RestPublishResponseJson {
|
|
34
|
+
results: RestPublishResultJson[];
|
|
35
|
+
}
|
|
36
|
+
export type RestPublishBodyParseResult = {
|
|
37
|
+
Kind: 'Parsed';
|
|
38
|
+
Requests: PublishRequest[];
|
|
39
|
+
} | {
|
|
40
|
+
Kind: 'Invalid';
|
|
41
|
+
Error: string;
|
|
42
|
+
};
|
|
43
|
+
export declare function ToRestPublishRequest(request: PublishRequest): RestPublishRequestJson;
|
|
44
|
+
export declare function FromRestPublishRequest(json: RestPublishRequestJson): PublishRequest;
|
|
45
|
+
export declare function ToRestPublishResult(result: PublishResult): RestPublishResultJson;
|
|
46
|
+
/** Checks the body's shape and maps it to PublishRequests. Envelope rules are ValidatePublishRequest's job. */
|
|
47
|
+
export declare function ParseRestPublishBody(value: unknown): RestPublishBodyParseResult;
|
|
48
|
+
export declare function ParseRestPublishResponse(value: unknown, expectedCount: number): PublishResult[] | null;
|
|
49
|
+
export declare function IsWorkJson(value: unknown): value is WorkJson;
|
|
50
|
+
//# sourceMappingURL=restContract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restContract.d.ts","sourceRoot":"","sources":["../../src/api/restContract.ts"],"names":[],"m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