@mosaicast/plugin-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/LICENSE +201 -0
- package/README.md +102 -0
- package/dist/index.d.ts +201 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +129 -0
- package/dist/index.js.map +1 -0
- package/dist/testing.d.ts +51 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +60 -0
- package/dist/testing.js.map +1 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# mosaicast-plugin-sdk
|
|
2
|
+
|
|
3
|
+
> Versioned plugin contract SDK (Java `plugin-api` + `@mosaicast/plugin-sdk` TS) plus a test kit.
|
|
4
|
+
|
|
5
|
+
Part of **[Mosaicast](https://github.com/mosaicast)** — an extensible website platform for podcasts. Status: **v1 in development**.
|
|
6
|
+
|
|
7
|
+
This repo is the **hard contract boundary** of the whole system: core AND every plugin compile against it, and it depends on neither. See `docs/ARCHITECTURE.md` for the big picture and `docs/BRIEF.md` for this repo's scope.
|
|
8
|
+
|
|
9
|
+
## Layout
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
plugin-api/ Java: the plugin contract (interfaces + records, no impl) → dev.mosaicast.plugin.api.*
|
|
13
|
+
plugin-testkit/ Java: test doubles (FakePluginContext, InMemoryDocStore, …) → dev.mosaicast.plugin.testkit.*
|
|
14
|
+
src/index.ts TS: @mosaicast/plugin-sdk — PluginContext, defineMosaicastElement, createPluginI18n
|
|
15
|
+
src/testing.ts TS: @mosaicast/plugin-sdk/testing — makeMockCtx
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The contract version is a **single SemVer anchor** mirrored in four places that MUST move together
|
|
19
|
+
(CI enforces it): `build.gradle.kts` · `package.json` · `PlatformApi.VERSION` · `PLATFORM_API_VERSION`.
|
|
20
|
+
A breaking change is a major bump; the host rejects plugins with an incompatible `platformApi` at startup.
|
|
21
|
+
|
|
22
|
+
## Build & test
|
|
23
|
+
```bash
|
|
24
|
+
./gradlew build publishToMavenLocal # Java: both JARs (+ sources & javadoc) → ~/.m2
|
|
25
|
+
npm ci && npm run build # TypeScript: src → dist (.js + .d.ts)
|
|
26
|
+
./gradlew test && npm test # all tests
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Using it
|
|
30
|
+
- **Java (plugin backend)** — three ways to obtain the artifacts:
|
|
31
|
+
- Composite build (nicest during parallel dev): `includeBuild("../mosaicast-plugin-sdk")`.
|
|
32
|
+
- Local: `./gradlew publishToMavenLocal`, then depend on `dev.mosaicast:plugin-api:<version>`.
|
|
33
|
+
- Released: from **GitHub Packages** (see below).
|
|
34
|
+
```kotlin
|
|
35
|
+
dependencies {
|
|
36
|
+
compileOnly("dev.mosaicast:plugin-api:0.1.0") // contract, provided by the host
|
|
37
|
+
testImplementation("dev.mosaicast:plugin-testkit:0.1.0") // test doubles only
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
Sources + Javadoc JARs give IDE hover docs automatically.
|
|
41
|
+
- **TypeScript (plugin frontend):** `npm install @mosaicast/plugin-sdk` (published on npm), or `npm link` / a tarball for local dev. `.d.ts` + TSDoc give IDE hover docs.
|
|
42
|
+
- **The source of truth for signatures** is this built SDK + its docs.
|
|
43
|
+
|
|
44
|
+
### Consuming released Java artifacts (GitHub Packages)
|
|
45
|
+
GitHub Packages requires authentication even for public reads. In the consumer's `build.gradle.kts`:
|
|
46
|
+
```kotlin
|
|
47
|
+
repositories {
|
|
48
|
+
mavenCentral()
|
|
49
|
+
maven {
|
|
50
|
+
url = uri("https://maven.pkg.github.com/Mosaicast/mosaicast-plugin-sdk")
|
|
51
|
+
credentials {
|
|
52
|
+
username = providers.gradleProperty("gpr.user").orNull ?: System.getenv("GITHUB_ACTOR")
|
|
53
|
+
password = providers.gradleProperty("gpr.token").orNull ?: System.getenv("GITHUB_TOKEN")
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
The token is any GitHub PAT with `read:packages`. (Anonymous-pull via Maven Central is a possible future move.)
|
|
59
|
+
|
|
60
|
+
## Releasing (maintainers)
|
|
61
|
+
Publishing is automated and fires on a **published GitHub Release**, not on PR merge
|
|
62
|
+
(`.github/workflows/release.yml`).
|
|
63
|
+
1. `scripts/set-version.sh <version>` — bumps the SemVer anchor in all four sources at once.
|
|
64
|
+
2. Commit on a branch, open a PR, merge to `master` (CI `version-parity` guards drift).
|
|
65
|
+
3. Draft a **GitHub Release** with tag `v<version>` and publish it.
|
|
66
|
+
4. The release workflow verifies the tag equals the anchor, rebuilds + tests, then publishes
|
|
67
|
+
`@mosaicast/plugin-sdk` to npm (OIDC trusted publishing, with provenance) and the Java artifacts to
|
|
68
|
+
GitHub Packages. A tag/anchor mismatch fails the release before anything is published.
|
|
69
|
+
|
|
70
|
+
## Test kit — mini examples
|
|
71
|
+
|
|
72
|
+
**Java** (`plugin-testkit`, no core, no DB):
|
|
73
|
+
```java
|
|
74
|
+
var ctx = new FakePluginContext(); // in-memory store, config, feeds; sync onSchedule
|
|
75
|
+
myPlugin.register(ctx); // exercise the backend
|
|
76
|
+
assertEquals(Optional.of("world"),
|
|
77
|
+
ctx.store().get(Scope.site("main"), "hello", String.class));
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**TypeScript** (`@mosaicast/plugin-sdk/testing`, jsdom):
|
|
81
|
+
```ts
|
|
82
|
+
import { makeMockCtx } from '@mosaicast/plugin-sdk/testing';
|
|
83
|
+
|
|
84
|
+
const el = document.createElement('bingo-episode-card') as HTMLElement & { ctx: PluginContext };
|
|
85
|
+
el.ctx = makeMockCtx({ scope: { type: 'episode', id: 'ep-1' } });
|
|
86
|
+
document.body.appendChild(el);
|
|
87
|
+
expect(el.shadowRoot!.querySelector('.card')).not.toBeNull();
|
|
88
|
+
// el.ctx.api is a MockApiClient: assert el.ctx.api.calls after interactions
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Contributing
|
|
92
|
+
Contributions welcome — see [`CONTRIBUTING.md`](CONTRIBUTING.md). In short: `git commit -s` (DCO, required), SPDX header in new files, add tests.
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
**Apache License 2.0** — see [`LICENSE`](LICENSE). Header per source file:
|
|
96
|
+
```
|
|
97
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
98
|
+
// SPDX-FileCopyrightText: 2026 The Mosaicast Authors
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Name & trademark
|
|
102
|
+
"Mosaicast" and the logo denote the official project. Please rename forks.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@mosaicast/plugin-sdk` — the versioned frontend plugin contract for Mosaicast.
|
|
3
|
+
*
|
|
4
|
+
* This is the entire interface a plugin author has to learn: the {@link PluginContext} the host sets on
|
|
5
|
+
* the mounted Web Component, plus two small helpers ({@link defineMosaicastElement},
|
|
6
|
+
* {@link createPluginI18n}). See ARCHITECTURE §7.5.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The plugin contract version (SemVer).
|
|
12
|
+
*
|
|
13
|
+
* Mirror of the Java `dev.mosaicast.plugin.api.PlatformApi.VERSION` constant and the npm package
|
|
14
|
+
* version. The host rejects a plugin whose manifest `platformApi` is incompatible with this value
|
|
15
|
+
* (ARCHITECTURE §7.2). **These move together — a breaking change is a major bump.**
|
|
16
|
+
*/
|
|
17
|
+
export declare const PLATFORM_API_VERSION: "0.1.0";
|
|
18
|
+
/** A user's role (ARCHITECTURE §8.5). Anonymous visitors have no role (`user` is `null`). */
|
|
19
|
+
export type Role = 'admin' | 'podcaster' | 'fan';
|
|
20
|
+
/** The level plus concrete entity a view is scoped to (ARCHITECTURE §6.1). */
|
|
21
|
+
export interface Scope {
|
|
22
|
+
/** The scope level. */
|
|
23
|
+
type: 'site' | 'feed' | 'season' | 'episode';
|
|
24
|
+
/** The id of the entity at that level (e.g. the `EpisodeRef` id for `episode`). */
|
|
25
|
+
id: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The host-owned filter axes for the current view (ARCHITECTURE §6.1).
|
|
29
|
+
*
|
|
30
|
+
* Filter state lives in the URL and is defined by the host; **plugins consume it read-only** and never
|
|
31
|
+
* define new axes. Known axes are typed; the index signature allows the host to add more without a
|
|
32
|
+
* breaking change.
|
|
33
|
+
*/
|
|
34
|
+
export interface FilterState {
|
|
35
|
+
/** Selected season number, if the view is filtered by season. */
|
|
36
|
+
season?: number;
|
|
37
|
+
/** Selected tags/keywords, if the view is filtered by tag. */
|
|
38
|
+
tags?: string[];
|
|
39
|
+
/** Active sort key, if any. */
|
|
40
|
+
sort?: string;
|
|
41
|
+
/** Additional host-defined axes. */
|
|
42
|
+
[axis: string]: unknown;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The host theme exposed to plugins as semantic tokens (ARCHITECTURE §12.3).
|
|
46
|
+
*
|
|
47
|
+
* The shell and plugins read the **same** tokens, so a plugin re-themes automatically in light/dark.
|
|
48
|
+
* {@link defineMosaicastElement} injects these into the component's shadow root as `--mc-*` CSS custom
|
|
49
|
+
* properties (e.g. `textMuted` → `--mc-text-muted`).
|
|
50
|
+
*/
|
|
51
|
+
export interface ThemeTokens {
|
|
52
|
+
/** Page background. */
|
|
53
|
+
bg: string;
|
|
54
|
+
/** Raised surface background. */
|
|
55
|
+
surface: string;
|
|
56
|
+
/** Primary text color. */
|
|
57
|
+
text: string;
|
|
58
|
+
/** Muted/secondary text color. */
|
|
59
|
+
textMuted: string;
|
|
60
|
+
/** Accent color. */
|
|
61
|
+
accent: string;
|
|
62
|
+
/** Readable text color on top of {@link accent}. */
|
|
63
|
+
accentContrast: string;
|
|
64
|
+
/** Optional secondary accent. */
|
|
65
|
+
accent2?: string;
|
|
66
|
+
/** Border/divider color. */
|
|
67
|
+
border: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A thin authenticated REST client for the plugin's own backend.
|
|
71
|
+
*
|
|
72
|
+
* All paths are relative to the plugin's base (`/api/plugins/<id>/`); the host attaches the auth token
|
|
73
|
+
* and base path. Methods reject on non-2xx responses (RFC 7807 `application/problem+json` body,
|
|
74
|
+
* ARCHITECTURE §13).
|
|
75
|
+
*/
|
|
76
|
+
export interface PluginApiClient {
|
|
77
|
+
/** GET a path, resolving to the parsed JSON body. */
|
|
78
|
+
get<T = unknown>(path: string): Promise<T>;
|
|
79
|
+
/** POST a JSON body, resolving to the parsed JSON response. */
|
|
80
|
+
post<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
81
|
+
/** PUT a JSON body, resolving to the parsed JSON response. */
|
|
82
|
+
put<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
83
|
+
/** DELETE a path, resolving to the parsed JSON response. */
|
|
84
|
+
delete<T = unknown>(path: string): Promise<T>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Everything a frontend plugin is given, set by the host on the mounted custom element
|
|
88
|
+
* (ARCHITECTURE §7.5). This is the **entire** interface a plugin author must learn.
|
|
89
|
+
*/
|
|
90
|
+
export interface PluginContext {
|
|
91
|
+
/** The scope this plugin instance is mounted in. */
|
|
92
|
+
scope: Scope;
|
|
93
|
+
/** The `EpisodeRef` ids in scope, resolved (and access-filtered) by the host. */
|
|
94
|
+
episodes: string[];
|
|
95
|
+
/** Present on the `episode` scope: lifecycle status of the current episode. */
|
|
96
|
+
episode?: {
|
|
97
|
+
status: 'PLANNED' | 'PUBLISHED' | 'WITHDRAWN';
|
|
98
|
+
};
|
|
99
|
+
/** The signed-in user, or `null` for anonymous visitors. */
|
|
100
|
+
user: {
|
|
101
|
+
id: string;
|
|
102
|
+
role: Role;
|
|
103
|
+
} | null;
|
|
104
|
+
/** Authenticated client for the plugin's own backend. */
|
|
105
|
+
api: PluginApiClient;
|
|
106
|
+
/** Cookie/consent gate for third-party resources (ARCHITECTURE §12.5). */
|
|
107
|
+
consent: {
|
|
108
|
+
has(cat: string): boolean;
|
|
109
|
+
onChange(cb: () => void): void;
|
|
110
|
+
};
|
|
111
|
+
/** Read-only access to the host's URL filter state (ARCHITECTURE §6.1). */
|
|
112
|
+
filter: {
|
|
113
|
+
current(): FilterState;
|
|
114
|
+
onChange(cb: (f: FilterState) => void): void;
|
|
115
|
+
};
|
|
116
|
+
/** Player position + control, for sync plugins (ARCHITECTURE §6.5). */
|
|
117
|
+
player: {
|
|
118
|
+
currentTime(): number;
|
|
119
|
+
seekTo(s: number): void;
|
|
120
|
+
on(ev: string, cb: (...args: unknown[]) => void): void;
|
|
121
|
+
};
|
|
122
|
+
/** The subpath under `/p/<pluginId>/`, for deep-linkable plugin content (ARCHITECTURE §6.4). */
|
|
123
|
+
route: {
|
|
124
|
+
path: string;
|
|
125
|
+
onChange(cb: (p: string) => void): void;
|
|
126
|
+
};
|
|
127
|
+
/** The active UI locale (ARCHITECTURE §12.7). */
|
|
128
|
+
locale: {
|
|
129
|
+
current(): string;
|
|
130
|
+
onChange(cb: (l: string) => void): void;
|
|
131
|
+
};
|
|
132
|
+
/** Core listening progress in seconds, or `null` if unknown (ARCHITECTURE §6.5). */
|
|
133
|
+
progress: {
|
|
134
|
+
get(episodeId: string): Promise<number | null>;
|
|
135
|
+
};
|
|
136
|
+
/** Host theme tokens, also injected as `--mc-*` CSS custom properties. */
|
|
137
|
+
theme: ThemeTokens;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* What a plugin author implements: render logic given the mount point and context.
|
|
141
|
+
*
|
|
142
|
+
* @param args.ctx the host-provided context
|
|
143
|
+
* @param args.root a dedicated container inside the component's shadow root to render into; it is
|
|
144
|
+
* cleared by the SDK before each call
|
|
145
|
+
* @returns an optional cleanup callback, run before the next render and on disconnect
|
|
146
|
+
*/
|
|
147
|
+
export type MosaicastRender = (args: {
|
|
148
|
+
ctx: PluginContext;
|
|
149
|
+
root: HTMLElement;
|
|
150
|
+
}) => void | (() => void);
|
|
151
|
+
/** Options for {@link defineMosaicastElement}. */
|
|
152
|
+
export interface DefineElementOptions {
|
|
153
|
+
/** The custom-element tag name (must contain a hyphen), e.g. `bingo-episode-card`. */
|
|
154
|
+
tag: string;
|
|
155
|
+
/** The render callback invoked whenever `ctx` is (re)assigned. */
|
|
156
|
+
render: MosaicastRender;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Registers a Mosaicast plugin Web Component.
|
|
160
|
+
*
|
|
161
|
+
* The created custom element attaches an open shadow root, accepts the host's {@link PluginContext} via
|
|
162
|
+
* a `ctx` property, injects the theme tokens as `--mc-*` CSS custom properties into the shadow root, and
|
|
163
|
+
* calls your {@link DefineElementOptions.render} into a dedicated container — so you write only render
|
|
164
|
+
* logic. Re-assigning `ctx` re-renders (after running any cleanup the previous render returned).
|
|
165
|
+
*
|
|
166
|
+
* Calling twice with the same tag is a no-op (the browser forbids redefining a custom element).
|
|
167
|
+
*
|
|
168
|
+
* @param options the tag name and render callback
|
|
169
|
+
*/
|
|
170
|
+
export declare function defineMosaicastElement(options: DefineElementOptions): void;
|
|
171
|
+
/** A translation catalog: message key → template string (with `{{param}}` placeholders). */
|
|
172
|
+
export type I18nCatalog = Record<string, string>;
|
|
173
|
+
/** Catalogs keyed by locale code, e.g. `{ en: {...}, de: {...} }`. */
|
|
174
|
+
export type I18nCatalogs = Record<string, I18nCatalog>;
|
|
175
|
+
/** The translator returned by {@link createPluginI18n}. */
|
|
176
|
+
export interface PluginI18n {
|
|
177
|
+
/**
|
|
178
|
+
* Translates a key against the active locale, interpolating `{{param}}` placeholders.
|
|
179
|
+
*
|
|
180
|
+
* Resolution: active locale → source locale (`en`) → the key itself as a last-resort fallback.
|
|
181
|
+
*
|
|
182
|
+
* @param key the message key
|
|
183
|
+
* @param params values for `{{placeholder}}` interpolation
|
|
184
|
+
*/
|
|
185
|
+
t(key: string, params?: Record<string, string | number>): string;
|
|
186
|
+
/** The currently active locale code. */
|
|
187
|
+
readonly locale: string;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Creates a plugin-local translator bound to the host's active locale (ARCHITECTURE §12.7).
|
|
191
|
+
*
|
|
192
|
+
* A plugin ships its own `locales/*.json` catalogs and translates against `ctx.locale`, re-rendering on
|
|
193
|
+
* change — the same convention as the shell, no extra i18n library required. English (`en`) is the
|
|
194
|
+
* source language and the fallback.
|
|
195
|
+
*
|
|
196
|
+
* @param catalogs catalogs keyed by locale code
|
|
197
|
+
* @param locale the host locale handle, i.e. `ctx.locale`; its `onChange` drives re-selection
|
|
198
|
+
* @returns a translator whose `t` and `locale` reflect the currently active locale
|
|
199
|
+
*/
|
|
200
|
+
export declare function createPluginI18n(catalogs: I18nCatalogs, locale: PluginContext['locale']): PluginI18n;
|
|
201
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,EAAG,OAAgB,CAAC;AAErD,6FAA6F;AAC7F,MAAM,MAAM,IAAI,GAAG,OAAO,GAAG,WAAW,GAAG,KAAK,CAAC;AAEjD,8EAA8E;AAC9E,MAAM,WAAW,KAAK;IACpB,uBAAuB;IACvB,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG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E,aAAa,CAAC,QAAQ,CAAC,GAC9B,UAAU,CAgBZ"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2026 The Mosaicast Authors
|
|
3
|
+
/**
|
|
4
|
+
* `@mosaicast/plugin-sdk` — the versioned frontend plugin contract for Mosaicast.
|
|
5
|
+
*
|
|
6
|
+
* This is the entire interface a plugin author has to learn: the {@link PluginContext} the host sets on
|
|
7
|
+
* the mounted Web Component, plus two small helpers ({@link defineMosaicastElement},
|
|
8
|
+
* {@link createPluginI18n}). See ARCHITECTURE §7.5.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* The plugin contract version (SemVer).
|
|
14
|
+
*
|
|
15
|
+
* Mirror of the Java `dev.mosaicast.plugin.api.PlatformApi.VERSION` constant and the npm package
|
|
16
|
+
* version. The host rejects a plugin whose manifest `platformApi` is incompatible with this value
|
|
17
|
+
* (ARCHITECTURE §7.2). **These move together — a breaking change is a major bump.**
|
|
18
|
+
*/
|
|
19
|
+
export const PLATFORM_API_VERSION = '0.1.0';
|
|
20
|
+
const THEME_TOKEN_VARS = [
|
|
21
|
+
['bg', '--mc-bg'],
|
|
22
|
+
['surface', '--mc-surface'],
|
|
23
|
+
['text', '--mc-text'],
|
|
24
|
+
['textMuted', '--mc-text-muted'],
|
|
25
|
+
['accent', '--mc-accent'],
|
|
26
|
+
['accentContrast', '--mc-accent-contrast'],
|
|
27
|
+
['accent2', '--mc-accent-2'],
|
|
28
|
+
['border', '--mc-border'],
|
|
29
|
+
];
|
|
30
|
+
/** Builds the `:host { --mc-*: … }` rule from theme tokens. */
|
|
31
|
+
function themeCss(theme) {
|
|
32
|
+
const decls = THEME_TOKEN_VARS.filter(([key]) => theme[key] != null)
|
|
33
|
+
.map(([key, cssVar]) => `${cssVar}: ${theme[key]};`)
|
|
34
|
+
.join(' ');
|
|
35
|
+
return `:host { display: block; ${decls} }`;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Registers a Mosaicast plugin Web Component.
|
|
39
|
+
*
|
|
40
|
+
* The created custom element attaches an open shadow root, accepts the host's {@link PluginContext} via
|
|
41
|
+
* a `ctx` property, injects the theme tokens as `--mc-*` CSS custom properties into the shadow root, and
|
|
42
|
+
* calls your {@link DefineElementOptions.render} into a dedicated container — so you write only render
|
|
43
|
+
* logic. Re-assigning `ctx` re-renders (after running any cleanup the previous render returned).
|
|
44
|
+
*
|
|
45
|
+
* Calling twice with the same tag is a no-op (the browser forbids redefining a custom element).
|
|
46
|
+
*
|
|
47
|
+
* @param options the tag name and render callback
|
|
48
|
+
*/
|
|
49
|
+
export function defineMosaicastElement(options) {
|
|
50
|
+
const { tag, render } = options;
|
|
51
|
+
if (customElements.get(tag)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
class MosaicastElement extends HTMLElement {
|
|
55
|
+
styleEl;
|
|
56
|
+
root;
|
|
57
|
+
ctxValue = null;
|
|
58
|
+
cleanup = undefined;
|
|
59
|
+
constructor() {
|
|
60
|
+
super();
|
|
61
|
+
const shadow = this.attachShadow({ mode: 'open' });
|
|
62
|
+
this.styleEl = document.createElement('style');
|
|
63
|
+
this.root = document.createElement('div');
|
|
64
|
+
shadow.append(this.styleEl, this.root);
|
|
65
|
+
}
|
|
66
|
+
/** The host sets this to (re)render the component. */
|
|
67
|
+
set ctx(value) {
|
|
68
|
+
this.ctxValue = value;
|
|
69
|
+
this.rerender();
|
|
70
|
+
}
|
|
71
|
+
get ctx() {
|
|
72
|
+
return this.ctxValue;
|
|
73
|
+
}
|
|
74
|
+
rerender() {
|
|
75
|
+
const ctx = this.ctxValue;
|
|
76
|
+
if (!ctx) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (typeof this.cleanup === 'function') {
|
|
80
|
+
this.cleanup();
|
|
81
|
+
this.cleanup = undefined;
|
|
82
|
+
}
|
|
83
|
+
this.styleEl.textContent = themeCss(ctx.theme);
|
|
84
|
+
this.root.replaceChildren();
|
|
85
|
+
this.cleanup = render({ ctx, root: this.root });
|
|
86
|
+
}
|
|
87
|
+
disconnectedCallback() {
|
|
88
|
+
if (typeof this.cleanup === 'function') {
|
|
89
|
+
this.cleanup();
|
|
90
|
+
this.cleanup = undefined;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
customElements.define(tag, MosaicastElement);
|
|
95
|
+
}
|
|
96
|
+
const SOURCE_LOCALE = 'en';
|
|
97
|
+
function interpolate(template, params) {
|
|
98
|
+
if (!params) {
|
|
99
|
+
return template;
|
|
100
|
+
}
|
|
101
|
+
return template.replace(/\{\{\s*(\w+)\s*\}\}/g, (whole, name) => Object.prototype.hasOwnProperty.call(params, name) ? String(params[name]) : whole);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Creates a plugin-local translator bound to the host's active locale (ARCHITECTURE §12.7).
|
|
105
|
+
*
|
|
106
|
+
* A plugin ships its own `locales/*.json` catalogs and translates against `ctx.locale`, re-rendering on
|
|
107
|
+
* change — the same convention as the shell, no extra i18n library required. English (`en`) is the
|
|
108
|
+
* source language and the fallback.
|
|
109
|
+
*
|
|
110
|
+
* @param catalogs catalogs keyed by locale code
|
|
111
|
+
* @param locale the host locale handle, i.e. `ctx.locale`; its `onChange` drives re-selection
|
|
112
|
+
* @returns a translator whose `t` and `locale` reflect the currently active locale
|
|
113
|
+
*/
|
|
114
|
+
export function createPluginI18n(catalogs, locale) {
|
|
115
|
+
let active = locale.current();
|
|
116
|
+
locale.onChange((l) => {
|
|
117
|
+
active = l;
|
|
118
|
+
});
|
|
119
|
+
return {
|
|
120
|
+
get locale() {
|
|
121
|
+
return active;
|
|
122
|
+
},
|
|
123
|
+
t(key, params) {
|
|
124
|
+
const template = catalogs[active]?.[key] ?? catalogs[SOURCE_LOCALE]?.[key] ?? key;
|
|
125
|
+
return interpolate(template, params);
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,qDAAqD;AAErD;;;;;;;;GAQG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,OAAgB,CAAC;AA4HrD,MAAM,gBAAgB,GAA+C;IACnE,CAAC,IAAI,EAAE,SAAS,CAAC;IACjB,CAAC,SAAS,EAAE,cAAc,CAAC;IAC3B,CAAC,MAAM,EAAE,WAAW,CAAC;IACrB,CAAC,WAAW,EAAE,iBAAiB,CAAC;IAChC,CAAC,QAAQ,EAAE,aAAa,CAAC;IACzB,CAAC,gBAAgB,EAAE,sBAAsB,CAAC;IAC1C,CAAC,SAAS,EAAE,eAAe,CAAC;IAC5B,CAAC,QAAQ,EAAE,aAAa,CAAC;CAC1B,CAAC;AAEF,+DAA+D;AAC/D,SAAS,QAAQ,CAAC,KAAkB;IAClC,MAAM,KAAK,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;SACjE,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,GAAG,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;SACnD,IAAI,CAAC,GAAG,CAAC,CAAC;IACb,OAAO,2BAA2B,KAAK,IAAI,CAAC;AAC9C,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAA6B;IAClE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAChC,IAAI,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QA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AAM,CAAC,CAAC;QACvC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@mosaicast/plugin-sdk/testing` — dev-only test doubles for frontend plugins (ARCHITECTURE §13.5).
|
|
3
|
+
*
|
|
4
|
+
* Mount your Web Component with {@link makeMockCtx} and assert against the rendered DOM and the recorded
|
|
5
|
+
* `api` calls — no core, no network. This subpath is not part of the production surface.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import type { PluginApiClient, PluginContext, ThemeTokens } from './index.js';
|
|
10
|
+
/** One recorded {@link MockApiClient} call. */
|
|
11
|
+
export interface RecordedCall {
|
|
12
|
+
/** HTTP method, lowercase. */
|
|
13
|
+
method: 'get' | 'post' | 'put' | 'delete';
|
|
14
|
+
/** The requested path (relative to the plugin base). */
|
|
15
|
+
path: string;
|
|
16
|
+
/** The request body, if any. */
|
|
17
|
+
body?: unknown;
|
|
18
|
+
}
|
|
19
|
+
/** A {@link PluginApiClient} that records calls and returns canned responses. */
|
|
20
|
+
export interface MockApiClient extends PluginApiClient {
|
|
21
|
+
/** Every call made through this client, in order. */
|
|
22
|
+
readonly calls: RecordedCall[];
|
|
23
|
+
/**
|
|
24
|
+
* Canned responses keyed by `"<method> <path>"` (e.g. `"get /board"`) or bare `path`; the more
|
|
25
|
+
* specific key wins. Missing keys resolve to `undefined`.
|
|
26
|
+
*/
|
|
27
|
+
responses: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
/** Default theme tokens (neutral light values) used when a test does not override them. */
|
|
30
|
+
export declare const DEFAULT_THEME: ThemeTokens;
|
|
31
|
+
/** Overrides accepted by {@link makeMockCtx}. */
|
|
32
|
+
export interface MockCtxOverrides extends Partial<Omit<PluginContext, 'api'>> {
|
|
33
|
+
/** Canned responses for the mock `api`, keyed as described on {@link MockApiClient.responses}. */
|
|
34
|
+
apiResponses?: Record<string, unknown>;
|
|
35
|
+
/** A ready-made mock api; if omitted one is created from {@link apiResponses}. */
|
|
36
|
+
api?: MockApiClient;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Builds a {@link PluginContext} wired with in-memory doubles for unit tests.
|
|
40
|
+
*
|
|
41
|
+
* Defaults: `site` scope, no episodes, anonymous user, all consent denied, empty filter, a player
|
|
42
|
+
* parked at 0s, empty route, `en` locale, unknown progress, and {@link DEFAULT_THEME}. Pass overrides to
|
|
43
|
+
* change any field; the returned `api` is a {@link MockApiClient} recording every call.
|
|
44
|
+
*
|
|
45
|
+
* @param overrides partial context plus optional `apiResponses`
|
|
46
|
+
* @returns a full context whose `api` is a {@link MockApiClient}
|
|
47
|
+
*/
|
|
48
|
+
export declare function makeMockCtx(overrides?: MockCtxOverrides): PluginContext & {
|
|
49
|
+
api: MockApiClient;
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAEV,eAAe,EACf,aAAa,EACb,WAAW,EACZ,MAAM,YAAY,CAAC;AAEpB,+CAA+C;AAC/C,MAAM,WAAW,YAAY;IAC3B,8BAA8B;IAC9B,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;IAC1C,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,iFAAiF;AACjF,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD,qDAAqD;IACrD,QAAQ,CAAC,KAAK,EAAE,YAAY,EAAE,CAAC;IAC/B;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAoBD,2FAA2F;AAC3F,eAAO,MAAM,aAAa,EAAE,WAS3B,CAAC;AAEF,iDAAiD;AACjD,MAAM,WAAW,gBAAiB,SAAQ,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IAC3E,kGAAkG;IAClG,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,kFAAkF;IAClF,GAAG,CAAC,EAAE,aAAa,CAAC;CACrB;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,SAAS,GAAE,gBAAqB,GAAG,aAAa,GAAG;IAAE,GAAG,EAAE,aAAa,CAAA;CAAE,CAoBpG"}
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2026 The Mosaicast Authors
|
|
3
|
+
function makeMockApi(responses) {
|
|
4
|
+
const calls = [];
|
|
5
|
+
const resolve = (method, path, body) => {
|
|
6
|
+
calls.push({ method, path, body });
|
|
7
|
+
const canned = api.responses[`${method} ${path}`] ?? api.responses[path];
|
|
8
|
+
return Promise.resolve(canned);
|
|
9
|
+
};
|
|
10
|
+
const api = {
|
|
11
|
+
calls,
|
|
12
|
+
responses,
|
|
13
|
+
get: (path) => resolve('get', path),
|
|
14
|
+
post: (path, body) => resolve('post', path, body),
|
|
15
|
+
put: (path, body) => resolve('put', path, body),
|
|
16
|
+
delete: (path) => resolve('delete', path),
|
|
17
|
+
};
|
|
18
|
+
return api;
|
|
19
|
+
}
|
|
20
|
+
/** Default theme tokens (neutral light values) used when a test does not override them. */
|
|
21
|
+
export const DEFAULT_THEME = {
|
|
22
|
+
bg: '#ffffff',
|
|
23
|
+
surface: '#f5f5f5',
|
|
24
|
+
text: '#111111',
|
|
25
|
+
textMuted: '#666666',
|
|
26
|
+
accent: '#3b5bdb',
|
|
27
|
+
accentContrast: '#ffffff',
|
|
28
|
+
accent2: '#7048e8',
|
|
29
|
+
border: '#dddddd',
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Builds a {@link PluginContext} wired with in-memory doubles for unit tests.
|
|
33
|
+
*
|
|
34
|
+
* Defaults: `site` scope, no episodes, anonymous user, all consent denied, empty filter, a player
|
|
35
|
+
* parked at 0s, empty route, `en` locale, unknown progress, and {@link DEFAULT_THEME}. Pass overrides to
|
|
36
|
+
* change any field; the returned `api` is a {@link MockApiClient} recording every call.
|
|
37
|
+
*
|
|
38
|
+
* @param overrides partial context plus optional `apiResponses`
|
|
39
|
+
* @returns a full context whose `api` is a {@link MockApiClient}
|
|
40
|
+
*/
|
|
41
|
+
export function makeMockCtx(overrides = {}) {
|
|
42
|
+
const { apiResponses, api, ...rest } = overrides;
|
|
43
|
+
const mockApi = api ?? makeMockApi(apiResponses ?? {});
|
|
44
|
+
const filter = rest.filter?.current() ?? {};
|
|
45
|
+
const base = {
|
|
46
|
+
scope: { type: 'site', id: 'main' },
|
|
47
|
+
episodes: [],
|
|
48
|
+
user: null,
|
|
49
|
+
api: mockApi,
|
|
50
|
+
consent: { has: () => false, onChange: () => { } },
|
|
51
|
+
filter: { current: () => filter, onChange: () => { } },
|
|
52
|
+
player: { currentTime: () => 0, seekTo: () => { }, on: () => { } },
|
|
53
|
+
route: { path: '', onChange: () => { } },
|
|
54
|
+
locale: { current: () => 'en', onChange: () => { } },
|
|
55
|
+
progress: { get: () => Promise.resolve(null) },
|
|
56
|
+
theme: DEFAULT_THEME,
|
|
57
|
+
};
|
|
58
|
+
return { ...base, ...rest, api: mockApi };
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,qDAAqD;AAuCrD,SAAS,WAAW,CAAC,SAAkC;IACrD,MAAM,KAAK,GAAmB,EAAE,CAAC;IACjC,MAAM,OAAO,GAAG,CAAC,MAA8B,EAAE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"Versioned plugin contract for Mosaicast: the frontend PluginContext types, a Web Component base helper, an i18n helper, plus a test kit under the /testing subpath.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./testing": {
|
|
17
|
+
"types": "./dist/testing.d.ts",
|
|
18
|
+
"import": "./dist/testing.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc -p tsconfig.json",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"test:watch": "vitest"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"jsdom": "^24.1.0",
|
|
29
|
+
"typescript": "^5.5.4",
|
|
30
|
+
"vitest": "^2.0.5"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
}
|
|
35
|
+
}
|