@vllnt/convex-music 0.1.0-canary.09eea4e
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 +21 -0
- package/README.md +169 -0
- package/dist/client/index.d.ts +284 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +166 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +100 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +2 -0
- package/dist/client/types.js.map +1 -0
- package/dist/component/_generated/api.d.ts +125 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +1143 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +133 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +80 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/actions.d.ts +144 -0
- package/dist/component/actions.d.ts.map +1 -0
- package/dist/component/actions.js +125 -0
- package/dist/component/actions.js.map +1 -0
- package/dist/component/catalog/browse_order.d.ts +22 -0
- package/dist/component/catalog/browse_order.d.ts.map +1 -0
- package/dist/component/catalog/browse_order.js +37 -0
- package/dist/component/catalog/browse_order.js.map +1 -0
- package/dist/component/catalog/field_source_policy.d.ts +30 -0
- package/dist/component/catalog/field_source_policy.d.ts.map +1 -0
- package/dist/component/catalog/field_source_policy.js +36 -0
- package/dist/component/catalog/field_source_policy.js.map +1 -0
- package/dist/component/catalog/merge.d.ts +58 -0
- package/dist/component/catalog/merge.d.ts.map +1 -0
- package/dist/component/catalog/merge.js +74 -0
- package/dist/component/catalog/merge.js.map +1 -0
- package/dist/component/catalog/mutations.d.ts +78 -0
- package/dist/component/catalog/mutations.d.ts.map +1 -0
- package/dist/component/catalog/mutations.js +259 -0
- package/dist/component/catalog/mutations.js.map +1 -0
- package/dist/component/catalog/promote.d.ts +21 -0
- package/dist/component/catalog/promote.d.ts.map +1 -0
- package/dist/component/catalog/promote.js +25 -0
- package/dist/component/catalog/promote.js.map +1 -0
- package/dist/component/catalog/queries.d.ts +421 -0
- package/dist/component/catalog/queries.d.ts.map +1 -0
- package/dist/component/catalog/queries.js +168 -0
- package/dist/component/catalog/queries.js.map +1 -0
- package/dist/component/config/mutations.d.ts +11 -0
- package/dist/component/config/mutations.d.ts.map +1 -0
- package/dist/component/config/mutations.js +30 -0
- package/dist/component/config/mutations.js.map +1 -0
- package/dist/component/config/queries.d.ts +9 -0
- package/dist/component/config/queries.d.ts.map +1 -0
- package/dist/component/config/queries.js +20 -0
- package/dist/component/config/queries.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +30 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/crons.d.ts +11 -0
- package/dist/component/crons.d.ts.map +1 -0
- package/dist/component/crons.js +41 -0
- package/dist/component/crons.js.map +1 -0
- package/dist/component/imports/actions.d.ts +119 -0
- package/dist/component/imports/actions.d.ts.map +1 -0
- package/dist/component/imports/actions.js +442 -0
- package/dist/component/imports/actions.js.map +1 -0
- package/dist/component/imports/dedupe.d.ts +29 -0
- package/dist/component/imports/dedupe.d.ts.map +1 -0
- package/dist/component/imports/dedupe.js +33 -0
- package/dist/component/imports/dedupe.js.map +1 -0
- package/dist/component/imports/mutations.d.ts +59 -0
- package/dist/component/imports/mutations.d.ts.map +1 -0
- package/dist/component/imports/mutations.js +151 -0
- package/dist/component/imports/mutations.js.map +1 -0
- package/dist/component/imports/queries.d.ts +68 -0
- package/dist/component/imports/queries.d.ts.map +1 -0
- package/dist/component/imports/queries.js +22 -0
- package/dist/component/imports/queries.js.map +1 -0
- package/dist/component/imports/state.d.ts +36 -0
- package/dist/component/imports/state.d.ts.map +1 -0
- package/dist/component/imports/state.js +62 -0
- package/dist/component/imports/state.js.map +1 -0
- package/dist/component/mutations.d.ts +55 -0
- package/dist/component/mutations.d.ts.map +1 -0
- package/dist/component/mutations.js +74 -0
- package/dist/component/mutations.js.map +1 -0
- package/dist/component/providers/actions.d.ts +26 -0
- package/dist/component/providers/actions.d.ts.map +1 -0
- package/dist/component/providers/actions.js +92 -0
- package/dist/component/providers/actions.js.map +1 -0
- package/dist/component/providers/apple/impl.d.ts +52 -0
- package/dist/component/providers/apple/impl.d.ts.map +1 -0
- package/dist/component/providers/apple/impl.js +127 -0
- package/dist/component/providers/apple/impl.js.map +1 -0
- package/dist/component/providers/apple/jwt.d.ts +32 -0
- package/dist/component/providers/apple/jwt.d.ts.map +1 -0
- package/dist/component/providers/apple/jwt.js +68 -0
- package/dist/component/providers/apple/jwt.js.map +1 -0
- package/dist/component/providers/apple/mappers.d.ts +20 -0
- package/dist/component/providers/apple/mappers.d.ts.map +1 -0
- package/dist/component/providers/apple/mappers.js +68 -0
- package/dist/component/providers/apple/mappers.js.map +1 -0
- package/dist/component/providers/apple/types.d.ts +80 -0
- package/dist/component/providers/apple/types.d.ts.map +1 -0
- package/dist/component/providers/apple/types.js +7 -0
- package/dist/component/providers/apple/types.js.map +1 -0
- package/dist/component/providers/deezer/impl.d.ts +37 -0
- package/dist/component/providers/deezer/impl.d.ts.map +1 -0
- package/dist/component/providers/deezer/impl.js +99 -0
- package/dist/component/providers/deezer/impl.js.map +1 -0
- package/dist/component/providers/deezer/mappers.d.ts +18 -0
- package/dist/component/providers/deezer/mappers.d.ts.map +1 -0
- package/dist/component/providers/deezer/mappers.js +53 -0
- package/dist/component/providers/deezer/mappers.js.map +1 -0
- package/dist/component/providers/deezer/types.d.ts +59 -0
- package/dist/component/providers/deezer/types.d.ts.map +1 -0
- package/dist/component/providers/deezer/types.js +7 -0
- package/dist/component/providers/deezer/types.js.map +1 -0
- package/dist/component/providers/fetch.d.ts +69 -0
- package/dist/component/providers/fetch.d.ts.map +1 -0
- package/dist/component/providers/fetch.js +145 -0
- package/dist/component/providers/fetch.js.map +1 -0
- package/dist/component/providers/musicbrainz/impl.d.ts +36 -0
- package/dist/component/providers/musicbrainz/impl.d.ts.map +1 -0
- package/dist/component/providers/musicbrainz/impl.js +74 -0
- package/dist/component/providers/musicbrainz/impl.js.map +1 -0
- package/dist/component/providers/musicbrainz/mappers.d.ts +10 -0
- package/dist/component/providers/musicbrainz/mappers.d.ts.map +1 -0
- package/dist/component/providers/musicbrainz/mappers.js +32 -0
- package/dist/component/providers/musicbrainz/mappers.js.map +1 -0
- package/dist/component/providers/musicbrainz/types.d.ts +24 -0
- package/dist/component/providers/musicbrainz/types.d.ts.map +1 -0
- package/dist/component/providers/musicbrainz/types.js +7 -0
- package/dist/component/providers/musicbrainz/types.js.map +1 -0
- package/dist/component/providers/registry.d.ts +22 -0
- package/dist/component/providers/registry.d.ts.map +1 -0
- package/dist/component/providers/registry.js +33 -0
- package/dist/component/providers/registry.js.map +1 -0
- package/dist/component/providers/spotify/client.d.ts +25 -0
- package/dist/component/providers/spotify/client.d.ts.map +1 -0
- package/dist/component/providers/spotify/client.js +30 -0
- package/dist/component/providers/spotify/client.js.map +1 -0
- package/dist/component/providers/spotify/impl.d.ts +51 -0
- package/dist/component/providers/spotify/impl.d.ts.map +1 -0
- package/dist/component/providers/spotify/impl.js +131 -0
- package/dist/component/providers/spotify/impl.js.map +1 -0
- package/dist/component/providers/spotify/mappers.d.ts +18 -0
- package/dist/component/providers/spotify/mappers.d.ts.map +1 -0
- package/dist/component/providers/spotify/mappers.js +60 -0
- package/dist/component/providers/spotify/mappers.js.map +1 -0
- package/dist/component/providers/spotify/types.d.ts +97 -0
- package/dist/component/providers/spotify/types.d.ts.map +1 -0
- package/dist/component/providers/spotify/types.js +7 -0
- package/dist/component/providers/spotify/types.js.map +1 -0
- package/dist/component/providers/types.d.ts +84 -0
- package/dist/component/providers/types.d.ts.map +1 -0
- package/dist/component/providers/types.js +10 -0
- package/dist/component/providers/types.js.map +1 -0
- package/dist/component/providers/wikidata/impl.d.ts +34 -0
- package/dist/component/providers/wikidata/impl.d.ts.map +1 -0
- package/dist/component/providers/wikidata/impl.js +88 -0
- package/dist/component/providers/wikidata/impl.js.map +1 -0
- package/dist/component/providers/wikidata/mappers.d.ts +11 -0
- package/dist/component/providers/wikidata/mappers.d.ts.map +1 -0
- package/dist/component/providers/wikidata/mappers.js +53 -0
- package/dist/component/providers/wikidata/mappers.js.map +1 -0
- package/dist/component/providers/wikidata/types.d.ts +35 -0
- package/dist/component/providers/wikidata/types.d.ts.map +1 -0
- package/dist/component/providers/wikidata/types.js +8 -0
- package/dist/component/providers/wikidata/types.js.map +1 -0
- package/dist/component/queries.d.ts +103 -0
- package/dist/component/queries.d.ts.map +1 -0
- package/dist/component/queries.js +45 -0
- package/dist/component/queries.js.map +1 -0
- package/dist/component/schema.d.ts +566 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +59 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/component/sources/actions.d.ts +51 -0
- package/dist/component/sources/actions.d.ts.map +1 -0
- package/dist/component/sources/actions.js +164 -0
- package/dist/component/sources/actions.js.map +1 -0
- package/dist/component/sources/mutations.d.ts +25 -0
- package/dist/component/sources/mutations.d.ts.map +1 -0
- package/dist/component/sources/mutations.js +64 -0
- package/dist/component/sources/mutations.js.map +1 -0
- package/dist/component/sources/queries.d.ts +19 -0
- package/dist/component/sources/queries.d.ts.map +1 -0
- package/dist/component/sources/queries.js +20 -0
- package/dist/component/sources/queries.js.map +1 -0
- package/dist/component/sync/lifecycle.d.ts +46 -0
- package/dist/component/sync/lifecycle.d.ts.map +1 -0
- package/dist/component/sync/lifecycle.js +87 -0
- package/dist/component/sync/lifecycle.js.map +1 -0
- package/dist/component/sync/mutations.d.ts +101 -0
- package/dist/component/sync/mutations.d.ts.map +1 -0
- package/dist/component/sync/mutations.js +132 -0
- package/dist/component/sync/mutations.js.map +1 -0
- package/dist/component/sync/queries.d.ts +69 -0
- package/dist/component/sync/queries.d.ts.map +1 -0
- package/dist/component/sync/queries.js +32 -0
- package/dist/component/sync/queries.js.map +1 -0
- package/dist/component/validators.d.ts +1112 -0
- package/dist/component/validators.d.ts.map +1 -0
- package/dist/component/validators.js +317 -0
- package/dist/component/validators.js.map +1 -0
- package/dist/react/index.d.ts +42 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +43 -0
- package/dist/react/index.js.map +1 -0
- package/dist/shared.d.ts +28 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +24 -0
- package/dist/shared.js.map +1 -0
- package/package.json +126 -0
- package/src/client/index.ts +558 -0
- package/src/client/types.ts +117 -0
- package/src/component/_generated/api.ts +141 -0
- package/src/component/_generated/component.ts +1814 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +169 -0
- package/src/component/actions.ts +156 -0
- package/src/component/catalog/browse_order.test.ts +55 -0
- package/src/component/catalog/browse_order.ts +43 -0
- package/src/component/catalog/field_source_policy.test.ts +47 -0
- package/src/component/catalog/field_source_policy.ts +44 -0
- package/src/component/catalog/merge.test.ts +187 -0
- package/src/component/catalog/merge.ts +134 -0
- package/src/component/catalog/mutations.ts +328 -0
- package/src/component/catalog/promote.ts +40 -0
- package/src/component/catalog/queries.ts +220 -0
- package/src/component/config/mutations.ts +29 -0
- package/src/component/config/queries.ts +20 -0
- package/src/component/convex.config.ts +32 -0
- package/src/component/crons.test.ts +8 -0
- package/src/component/crons.ts +52 -0
- package/src/component/imports/actions.ts +553 -0
- package/src/component/imports/dedupe.test.ts +66 -0
- package/src/component/imports/dedupe.ts +54 -0
- package/src/component/imports/mutations.ts +203 -0
- package/src/component/imports/queries.ts +25 -0
- package/src/component/imports/state.test.ts +60 -0
- package/src/component/imports/state.ts +74 -0
- package/src/component/mutations.ts +96 -0
- package/src/component/providers/actions.ts +127 -0
- package/src/component/providers/apple/impl.test.ts +267 -0
- package/src/component/providers/apple/impl.ts +224 -0
- package/src/component/providers/apple/jwt.test.ts +153 -0
- package/src/component/providers/apple/jwt.ts +99 -0
- package/src/component/providers/apple/mappers.test.ts +190 -0
- package/src/component/providers/apple/mappers.ts +100 -0
- package/src/component/providers/apple/types.ts +77 -0
- package/src/component/providers/deezer/impl.test.ts +109 -0
- package/src/component/providers/deezer/impl.ts +179 -0
- package/src/component/providers/deezer/mappers.test.ts +78 -0
- package/src/component/providers/deezer/mappers.ts +72 -0
- package/src/component/providers/deezer/types.ts +59 -0
- package/src/component/providers/fetch.test.ts +282 -0
- package/src/component/providers/fetch.ts +190 -0
- package/src/component/providers/musicbrainz/impl.test.ts +79 -0
- package/src/component/providers/musicbrainz/impl.ts +132 -0
- package/src/component/providers/musicbrainz/mappers.test.ts +75 -0
- package/src/component/providers/musicbrainz/mappers.ts +34 -0
- package/src/component/providers/musicbrainz/types.ts +20 -0
- package/src/component/providers/registry.test.ts +14 -0
- package/src/component/providers/registry.ts +48 -0
- package/src/component/providers/spotify/client.test.ts +80 -0
- package/src/component/providers/spotify/client.ts +57 -0
- package/src/component/providers/spotify/impl.test.ts +311 -0
- package/src/component/providers/spotify/impl.ts +230 -0
- package/src/component/providers/spotify/mappers.test.ts +182 -0
- package/src/component/providers/spotify/mappers.ts +81 -0
- package/src/component/providers/spotify/types.ts +101 -0
- package/src/component/providers/types.ts +95 -0
- package/src/component/providers/wikidata/impl.test.ts +81 -0
- package/src/component/providers/wikidata/impl.ts +139 -0
- package/src/component/providers/wikidata/mappers.test.ts +62 -0
- package/src/component/providers/wikidata/mappers.ts +66 -0
- package/src/component/providers/wikidata/types.ts +28 -0
- package/src/component/queries.ts +51 -0
- package/src/component/schema.ts +81 -0
- package/src/component/sources/actions.ts +177 -0
- package/src/component/sources/mutations.ts +67 -0
- package/src/component/sources/queries.ts +21 -0
- package/src/component/sync/lifecycle.test.ts +72 -0
- package/src/component/sync/lifecycle.ts +121 -0
- package/src/component/sync/mutations.ts +154 -0
- package/src/component/sync/queries.ts +33 -0
- package/src/component/validators.ts +411 -0
- package/src/react/index.test.ts +78 -0
- package/src/react/index.ts +112 -0
- package/src/shared.ts +32 -0
- package/src/test.ts +22 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apple Music adapter. Implements {@link MusicProvider} over the Apple Music API.
|
|
3
|
+
* The developer token (signed by {@link signAppleDeveloperToken}) is injected via
|
|
4
|
+
* `getToken` so the class stays pure + testable; the action layer signs + caches
|
|
5
|
+
* it. Apple inlines album/playlist tracks via `include=tracks`, so traversal needs
|
|
6
|
+
* fewer requests than Spotify.
|
|
7
|
+
*/
|
|
8
|
+
import { type FetchDeps, type RetryConfig } from "../fetch.js";
|
|
9
|
+
import type { ArtistAlbumsResult, MusicProvider, ProviderAlbum, ProviderArtist, ProviderPlaylist, ProviderSearchResult, ProviderTrack } from "../types.js";
|
|
10
|
+
/** Apple Music API base. */
|
|
11
|
+
export declare const APPLE_API_BASE = "https://api.music.apple.com/v1";
|
|
12
|
+
/** Tunable Apple limits (all overridable via mount policy). */
|
|
13
|
+
export interface AppleConfig {
|
|
14
|
+
/** Storefront / locale segment (e.g. `us`). */
|
|
15
|
+
storefront: string;
|
|
16
|
+
/** Retry/timeout policy for each call. */
|
|
17
|
+
retry: RetryConfig;
|
|
18
|
+
/** Max results per free-text search. */
|
|
19
|
+
searchLimit: number;
|
|
20
|
+
/** Page size for artist-album listings. */
|
|
21
|
+
albumLimit: number;
|
|
22
|
+
/** Cap on albums per artist. */
|
|
23
|
+
maxAlbumsPerArtist: number;
|
|
24
|
+
/** Ids per batch songs request. */
|
|
25
|
+
batchSize: number;
|
|
26
|
+
/** Concurrent batch requests. */
|
|
27
|
+
concurrency: number;
|
|
28
|
+
}
|
|
29
|
+
/** Default Apple limits. */
|
|
30
|
+
export declare const DEFAULT_APPLE_CONFIG: AppleConfig;
|
|
31
|
+
export declare class AppleProvider implements MusicProvider {
|
|
32
|
+
private readonly getToken;
|
|
33
|
+
private readonly cfg;
|
|
34
|
+
private readonly deps;
|
|
35
|
+
readonly id: "apple";
|
|
36
|
+
constructor(getToken: () => Promise<string>, cfg?: AppleConfig, deps?: FetchDeps);
|
|
37
|
+
private get catalog();
|
|
38
|
+
private api;
|
|
39
|
+
private firstOrThrow;
|
|
40
|
+
private toTrack;
|
|
41
|
+
private toAlbum;
|
|
42
|
+
getArtist(externalId: string): Promise<ProviderArtist>;
|
|
43
|
+
getTrack(externalId: string): Promise<ProviderTrack>;
|
|
44
|
+
getAlbum(externalId: string): Promise<ProviderAlbum>;
|
|
45
|
+
getPlaylist(externalId: string): Promise<ProviderPlaylist>;
|
|
46
|
+
getArtistTopTracks(externalId: string): Promise<ProviderTrack[]>;
|
|
47
|
+
getArtistAlbums(externalId: string): Promise<ArtistAlbumsResult>;
|
|
48
|
+
search(query: string, type: "artist" | "track"): Promise<ProviderSearchResult[]>;
|
|
49
|
+
searchByIsrc(isrc: string): Promise<ProviderTrack[]>;
|
|
50
|
+
getSeveralTracks(externalIds: string[]): Promise<ProviderTrack[]>;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"impl.d.ts","sourceRoot":"","sources":["../../../../src/component/providers/apple/impl.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,WAAW,EAIjB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACd,MAAM,aAAa,CAAC;AAgBrB,4BAA4B;AAC5B,eAAO,MAAM,cAAc,mCAAmC,CAAC;AAE/D,+DAA+D;AAC/D,MAAM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AAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAUrE;IAEK,MAAM,CACV,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,QAAQ,GAAG,OAAO,GACvB,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAoBjC;IAEK,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAMzD;IAEK,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAWtE;CACF"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apple Music adapter. Implements {@link MusicProvider} over the Apple Music API.
|
|
3
|
+
* The developer token (signed by {@link signAppleDeveloperToken}) is injected via
|
|
4
|
+
* `getToken` so the class stays pure + testable; the action layer signs + caches
|
|
5
|
+
* it. Apple inlines album/playlist tracks via `include=tracks`, so traversal needs
|
|
6
|
+
* fewer requests than Spotify.
|
|
7
|
+
*/
|
|
8
|
+
import { DEFAULT_RETRY_CONFIG, defaultFetchDeps, fetchJson, mapWithConcurrency, } from "../fetch.js";
|
|
9
|
+
import { mapAppleAlbum, mapAppleArtist, mapApplePlaylist, mapAppleTrack, } from "./mappers.js";
|
|
10
|
+
/** Apple Music API base. */
|
|
11
|
+
export const APPLE_API_BASE = "https://api.music.apple.com/v1";
|
|
12
|
+
/** Default Apple limits. */
|
|
13
|
+
export const DEFAULT_APPLE_CONFIG = {
|
|
14
|
+
storefront: "us",
|
|
15
|
+
retry: DEFAULT_RETRY_CONFIG,
|
|
16
|
+
searchLimit: 10,
|
|
17
|
+
albumLimit: 30,
|
|
18
|
+
maxAlbumsPerArtist: 30,
|
|
19
|
+
batchSize: 25,
|
|
20
|
+
concurrency: 5,
|
|
21
|
+
};
|
|
22
|
+
export class AppleProvider {
|
|
23
|
+
getToken;
|
|
24
|
+
cfg;
|
|
25
|
+
deps;
|
|
26
|
+
id = "apple";
|
|
27
|
+
constructor(getToken, cfg = DEFAULT_APPLE_CONFIG, deps = defaultFetchDeps) {
|
|
28
|
+
this.getToken = getToken;
|
|
29
|
+
this.cfg = cfg;
|
|
30
|
+
this.deps = deps;
|
|
31
|
+
}
|
|
32
|
+
get catalog() {
|
|
33
|
+
return `/catalog/${this.cfg.storefront}`;
|
|
34
|
+
}
|
|
35
|
+
async api(path, params = {}) {
|
|
36
|
+
const token = await this.getToken();
|
|
37
|
+
const url = new URL(APPLE_API_BASE + path);
|
|
38
|
+
for (const [key, value] of Object.entries(params)) {
|
|
39
|
+
url.searchParams.set(key, value);
|
|
40
|
+
}
|
|
41
|
+
return fetchJson("apple", url.toString(), { headers: { Authorization: `Bearer ${token}` } }, this.cfg.retry, this.deps);
|
|
42
|
+
}
|
|
43
|
+
firstOrThrow(data, kind, id) {
|
|
44
|
+
const item = data[0];
|
|
45
|
+
if (item === undefined)
|
|
46
|
+
throw new Error(`apple: ${kind} "${id}" not found`);
|
|
47
|
+
return item;
|
|
48
|
+
}
|
|
49
|
+
toTrack(raw) {
|
|
50
|
+
return { externalId: raw.id, value: mapAppleTrack(raw) };
|
|
51
|
+
}
|
|
52
|
+
toAlbum(raw) {
|
|
53
|
+
const tracks = raw.relationships?.tracks?.data ?? [];
|
|
54
|
+
return {
|
|
55
|
+
externalId: raw.id,
|
|
56
|
+
value: mapAppleAlbum(raw),
|
|
57
|
+
tracks: tracks.map((track) => this.toTrack(track)),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async getArtist(externalId) {
|
|
61
|
+
const res = await this.api(`${this.catalog}/artists/${encodeURIComponent(externalId)}`);
|
|
62
|
+
const raw = this.firstOrThrow(res.data, "artist", externalId);
|
|
63
|
+
return { externalId: raw.id, value: mapAppleArtist(raw) };
|
|
64
|
+
}
|
|
65
|
+
async getTrack(externalId) {
|
|
66
|
+
const res = await this.api(`${this.catalog}/songs/${encodeURIComponent(externalId)}`);
|
|
67
|
+
return this.toTrack(this.firstOrThrow(res.data, "song", externalId));
|
|
68
|
+
}
|
|
69
|
+
async getAlbum(externalId) {
|
|
70
|
+
const res = await this.api(`${this.catalog}/albums/${encodeURIComponent(externalId)}`, { include: "tracks,artists" });
|
|
71
|
+
return this.toAlbum(this.firstOrThrow(res.data, "album", externalId));
|
|
72
|
+
}
|
|
73
|
+
async getPlaylist(externalId) {
|
|
74
|
+
const res = await this.api(`${this.catalog}/playlists/${encodeURIComponent(externalId)}`, { include: "tracks" });
|
|
75
|
+
const raw = this.firstOrThrow(res.data, "playlist", externalId);
|
|
76
|
+
const tracks = raw.relationships?.tracks?.data ?? [];
|
|
77
|
+
return {
|
|
78
|
+
externalId: raw.id,
|
|
79
|
+
value: mapApplePlaylist(raw),
|
|
80
|
+
tracks: tracks.map((track) => this.toTrack(track)),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
async getArtistTopTracks(externalId) {
|
|
84
|
+
const res = await this.api(`${this.catalog}/artists/${encodeURIComponent(externalId)}/view/top-songs`);
|
|
85
|
+
return res.data.map((track) => this.toTrack(track));
|
|
86
|
+
}
|
|
87
|
+
async getArtistAlbums(externalId) {
|
|
88
|
+
const res = await this.api(`${this.catalog}/artists/${encodeURIComponent(externalId)}/albums`, { include: "tracks,artists", limit: String(this.cfg.albumLimit) });
|
|
89
|
+
const isPartial = res.next !== undefined;
|
|
90
|
+
const albums = res.data
|
|
91
|
+
.slice(0, this.cfg.maxAlbumsPerArtist)
|
|
92
|
+
.map((album) => this.toAlbum(album));
|
|
93
|
+
return { albums, isPartial };
|
|
94
|
+
}
|
|
95
|
+
async search(query, type) {
|
|
96
|
+
const res = await this.api(`${this.catalog}/search`, {
|
|
97
|
+
term: query,
|
|
98
|
+
types: type === "artist" ? "artists" : "songs",
|
|
99
|
+
limit: String(this.cfg.searchLimit),
|
|
100
|
+
});
|
|
101
|
+
if (type === "artist") {
|
|
102
|
+
return (res.results?.artists?.data ?? []).map((artist) => ({
|
|
103
|
+
type: "artist",
|
|
104
|
+
data: { externalId: artist.id, value: mapAppleArtist(artist) },
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
return (res.results?.songs?.data ?? []).map((song) => ({
|
|
108
|
+
type: "track",
|
|
109
|
+
data: this.toTrack(song),
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
async searchByIsrc(isrc) {
|
|
113
|
+
const res = await this.api(`${this.catalog}/songs`, { "filter[isrc]": isrc });
|
|
114
|
+
return res.data.map((track) => this.toTrack(track));
|
|
115
|
+
}
|
|
116
|
+
async getSeveralTracks(externalIds) {
|
|
117
|
+
const chunks = [];
|
|
118
|
+
for (let i = 0; i < externalIds.length; i += this.cfg.batchSize) {
|
|
119
|
+
chunks.push(externalIds.slice(i, i + this.cfg.batchSize));
|
|
120
|
+
}
|
|
121
|
+
const pages = await mapWithConcurrency(chunks, this.cfg.concurrency, (chunk) => this.api(`${this.catalog}/songs`, {
|
|
122
|
+
ids: chunk.join(","),
|
|
123
|
+
}));
|
|
124
|
+
return pages.flatMap((page) => page.data.map((track) => this.toTrack(track)));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=impl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"impl.js","sourceRoot":"","sources":["../../../../src/component/providers/apple/impl.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,oBAAoB,EAGpB,gBAAgB,EAChB,SAAS,EACT,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAUrB,OAAO,EACL,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,aAAa,GACd,MAAM,cAAc,CAAC;AAUtB,4BAA4B;AAC5B,MAAM,CAAC,MAAM,cAAc,GAAG,gCAAgC,CAAC;AAoB/D,4BAA4B;AAC5B,MAAM,CAAC,MAAM,oBAAoB,GAAgB;IAC/C,UAAU,EAAE,IAAI;IAChB,KAAK,EAAE,oBAAoB;IAC3B,WAAW,EAAE,EAAE;IACf,UAAU,EAAE,EAAE;IACd,kBAAkB,E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AC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAChF,CAAC;CACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apple Music developer token, signed with Web Crypto (ECDSA P-256 / ES256).
|
|
3
|
+
* A Convex component runs in V8 — it cannot use `jsonwebtoken` (Node `crypto`),
|
|
4
|
+
* so songtrivia's `jwt.sign(...)` is re-architected here on `crypto.subtle`:
|
|
5
|
+
* PKCS8 key import → JWS assembly → base64url, zero-dependency. Web Crypto emits
|
|
6
|
+
* the raw `r||s` signature JWS/ES256 expects, so no DER conversion is needed.
|
|
7
|
+
*/
|
|
8
|
+
/** Inputs for an Apple Music developer token. */
|
|
9
|
+
export interface AppleTokenInput {
|
|
10
|
+
/** Apple Developer Team ID — the `iss` claim. */
|
|
11
|
+
issuer: string;
|
|
12
|
+
/** MusicKit private-key id — the JWS `kid` header. */
|
|
13
|
+
keyId: string;
|
|
14
|
+
/** PEM-encoded PKCS8 EC P-256 private key. */
|
|
15
|
+
privateKeyPem: string;
|
|
16
|
+
/** Issued-at, in seconds since the epoch. */
|
|
17
|
+
nowSec: number;
|
|
18
|
+
/** Lifetime in seconds (default 6 months — Apple's maximum). */
|
|
19
|
+
ttlSec?: number;
|
|
20
|
+
}
|
|
21
|
+
/** Apple's maximum developer-token lifetime: ~6 months in seconds. */
|
|
22
|
+
export declare const APPLE_TOKEN_MAX_TTL_SEC = 15777000;
|
|
23
|
+
/**
|
|
24
|
+
* Sign an Apple Music developer token. The signed JWT authorizes Apple Music API
|
|
25
|
+
* requests for ~6 months (cache it; re-signing is cheap but pointless).
|
|
26
|
+
*
|
|
27
|
+
* @param input - issuer/keyId/PEM + issued-at + optional ttl.
|
|
28
|
+
* @param subtle - Web Crypto subtle (injectable for tests; defaults to the runtime).
|
|
29
|
+
* @returns the compact JWS `header.payload.signature`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function signAppleDeveloperToken(input: AppleTokenInput, subtle?: SubtleCrypto): Promise<string>;
|
|
32
|
+
//# sourceMappingURL=jwt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../../../src/component/providers/apple/jwt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,iDAAiD;AACjD,MAAM,WAAW,eAAe;IAC9B,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,8CAA8C;IAC9C,aAAa,EAAE,MAAM,CAAC;IACtB,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,sEAAsE;AACtE,eAAO,MAAM,uBAAuB,WAAa,CAAC;AAqClD;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,eAAe,EACtB,MAAM,GAAE,YAA4B,GACnC,OAAO,CAAC,MAAM,CAAC,CA2BjB"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apple Music developer token, signed with Web Crypto (ECDSA P-256 / ES256).
|
|
3
|
+
* A Convex component runs in V8 — it cannot use `jsonwebtoken` (Node `crypto`),
|
|
4
|
+
* so songtrivia's `jwt.sign(...)` is re-architected here on `crypto.subtle`:
|
|
5
|
+
* PKCS8 key import → JWS assembly → base64url, zero-dependency. Web Crypto emits
|
|
6
|
+
* the raw `r||s` signature JWS/ES256 expects, so no DER conversion is needed.
|
|
7
|
+
*/
|
|
8
|
+
/** Apple's maximum developer-token lifetime: ~6 months in seconds. */
|
|
9
|
+
export const APPLE_TOKEN_MAX_TTL_SEC = 15_777_000;
|
|
10
|
+
/** Base64url-encode bytes (no padding), per JWS. */
|
|
11
|
+
function base64Url(bytes) {
|
|
12
|
+
let binary = "";
|
|
13
|
+
for (const byte of bytes)
|
|
14
|
+
binary += String.fromCharCode(byte);
|
|
15
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
16
|
+
}
|
|
17
|
+
/** Base64url-encode a JSON value, per JWS. */
|
|
18
|
+
function base64UrlJson(value) {
|
|
19
|
+
return base64Url(new TextEncoder().encode(JSON.stringify(value)));
|
|
20
|
+
}
|
|
21
|
+
/** Decode a PEM block to the raw DER bytes Web Crypto imports. */
|
|
22
|
+
function pemToDer(pem) {
|
|
23
|
+
const body = pem
|
|
24
|
+
.replace(/-----BEGIN [^-]+-----/, "")
|
|
25
|
+
.replace(/-----END [^-]+-----/, "")
|
|
26
|
+
.replace(/\s+/g, "");
|
|
27
|
+
if (body.length === 0) {
|
|
28
|
+
throw new Error("Apple private key PEM is empty");
|
|
29
|
+
}
|
|
30
|
+
let binary;
|
|
31
|
+
try {
|
|
32
|
+
binary = atob(body);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// A non-base64 body (e.g. a PEM pasted with literal `\n` escapes) — fail with
|
|
36
|
+
// an actionable message, never echoing the key material.
|
|
37
|
+
throw new Error("Apple private key PEM is malformed");
|
|
38
|
+
}
|
|
39
|
+
const buffer = new ArrayBuffer(binary.length);
|
|
40
|
+
const bytes = new Uint8Array(buffer);
|
|
41
|
+
for (let i = 0; i < binary.length; i += 1)
|
|
42
|
+
bytes[i] = binary.charCodeAt(i);
|
|
43
|
+
return buffer;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Sign an Apple Music developer token. The signed JWT authorizes Apple Music API
|
|
47
|
+
* requests for ~6 months (cache it; re-signing is cheap but pointless).
|
|
48
|
+
*
|
|
49
|
+
* @param input - issuer/keyId/PEM + issued-at + optional ttl.
|
|
50
|
+
* @param subtle - Web Crypto subtle (injectable for tests; defaults to the runtime).
|
|
51
|
+
* @returns the compact JWS `header.payload.signature`.
|
|
52
|
+
*/
|
|
53
|
+
export async function signAppleDeveloperToken(input, subtle = crypto.subtle) {
|
|
54
|
+
// Clamp to Apple's 6-month maximum: a longer-lived signed token is rejected by
|
|
55
|
+
// Apple anyway, and a long-lived credential widens the blast radius if leaked.
|
|
56
|
+
const ttl = Math.min(input.ttlSec ?? APPLE_TOKEN_MAX_TTL_SEC, APPLE_TOKEN_MAX_TTL_SEC);
|
|
57
|
+
const header = { alg: "ES256", kid: input.keyId, typ: "JWT" };
|
|
58
|
+
const payload = {
|
|
59
|
+
iss: input.issuer,
|
|
60
|
+
iat: input.nowSec,
|
|
61
|
+
exp: input.nowSec + ttl,
|
|
62
|
+
};
|
|
63
|
+
const signingInput = `${base64UrlJson(header)}.${base64UrlJson(payload)}`;
|
|
64
|
+
const key = await subtle.importKey("pkcs8", pemToDer(input.privateKeyPem), { name: "ECDSA", namedCurve: "P-256" }, false, ["sign"]);
|
|
65
|
+
const signature = await subtle.sign({ name: "ECDSA", hash: "SHA-256" }, key, new TextEncoder().encode(signingInput));
|
|
66
|
+
return `${signingInput}.${base64Url(new Uint8Array(signature))}`;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=jwt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.js","sourceRoot":"","sources":["../../../../src/component/providers/apple/jwt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgBH,sEAAsE;AACtE,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAU,CAAC;AAElD,oDAAoD;AACpD,SAAS,SAAS,CAAC,KAAiB;IAClC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC9D,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC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AG,IAAI,CAAC,GAAG,CAClB,KAAK,CAAC,MAAM,IAAI,uBAAuB,EACvC,uBAAuB,CACxB,CAAC;IACF,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IAC9D,MAAM,OAAO,GAAG;QACd,GAAG,EAAE,KAAK,CAAC,MAAM;QACjB,GAAG,EAAE,KAAK,CAAC,MAAM;QACjB,GAAG,EAAE,KAAK,CAAC,MAAM,GAAG,GAAG;KACxB,CAAC;IACF,MAAM,YAAY,GAAG,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;IAC1E,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,SAAS,CAChC,OAAO,EACP,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC,EAC7B,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,EACtC,KAAK,EACL,CAAC,MAAM,CAAC,CACT,CAAC;IACF,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,IAAI,CACjC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,EAClC,GAAG,EACH,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CACvC,CAAC;IACF,OAAO,GAAG,YAAY,IAAI,SAAS,CAAC,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map raw Apple Music responses to the component's normalized schema. Pure
|
|
3
|
+
* functions; Apple's `{w}x{h}` artwork URLs are templated to a concrete size.
|
|
4
|
+
*/
|
|
5
|
+
import type { NormalizedAlbum, NormalizedArtist, NormalizedTrack } from "../../../client/types.js";
|
|
6
|
+
import type { NormalizedPlaylist } from "../types.js";
|
|
7
|
+
import type { AppleAlbum, AppleArtist, AppleArtwork, ApplePlaylist, AppleSong } from "./types.js";
|
|
8
|
+
/** Default artwork edge length when templating `{w}`/`{h}`. */
|
|
9
|
+
export declare const APPLE_ARTWORK_SIZE = 600;
|
|
10
|
+
/** Resolve Apple's templated artwork URL to a concrete size, if present. */
|
|
11
|
+
export declare function formatArtwork(artwork: AppleArtwork | undefined, size?: number): string | undefined;
|
|
12
|
+
/** Apple artist → normalized artist (no popularity; genres from genreNames). */
|
|
13
|
+
export declare function mapAppleArtist(raw: AppleArtist): NormalizedArtist;
|
|
14
|
+
/** Apple song → normalized track. */
|
|
15
|
+
export declare function mapAppleTrack(raw: AppleSong): NormalizedTrack;
|
|
16
|
+
/** Apple album → normalized album. */
|
|
17
|
+
export declare function mapAppleAlbum(raw: AppleAlbum): NormalizedAlbum;
|
|
18
|
+
/** Apple playlist → normalized playlist metadata. */
|
|
19
|
+
export declare function mapApplePlaylist(raw: ApplePlaylist): NormalizedPlaylist;
|
|
20
|
+
//# sourceMappingURL=mappers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mappers.d.ts","sourceRoot":"","sources":["../../../../src/component/providers/apple/mappers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAEV,eAAe,EACf,gBAAgB,EAChB,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,YAAY,EACZ,aAAa,EACb,SAAS,EACV,MAAM,YAAY,CAAC;AAEpB,+DAA+D;AAC/D,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC,4EAA4E;AAC5E,wBAAgB,aAAa,CAC3B,OAAO,EAAE,YAAY,GAAG,SAAS,EACjC,IAAI,GAAE,MAA2B,GAChC,MAAM,GAAG,SAAS,CAKpB;AAYD,gFAAgF;AAChF,wBAAgB,cAAc,CAAC,GAAG,EAAE,WAAW,GAAG,gBAAgB,CAOjE;AAED,qCAAqC;AACrC,wBAAgB,aAAa,CAAC,GAAG,EAAE,SAAS,GAAG,eAAe,CAgB7D;AAED,sCAAsC;AACtC,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,eAAe,CAc9D;AAED,qDAAqD;AACrD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,aAAa,GAAG,kBAAkB,CAQvE"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map raw Apple Music responses to the component's normalized schema. Pure
|
|
3
|
+
* functions; Apple's `{w}x{h}` artwork URLs are templated to a concrete size.
|
|
4
|
+
*/
|
|
5
|
+
/** Default artwork edge length when templating `{w}`/`{h}`. */
|
|
6
|
+
export const APPLE_ARTWORK_SIZE = 600;
|
|
7
|
+
/** Resolve Apple's templated artwork URL to a concrete size, if present. */
|
|
8
|
+
export function formatArtwork(artwork, size = APPLE_ARTWORK_SIZE) {
|
|
9
|
+
if (artwork === undefined)
|
|
10
|
+
return undefined;
|
|
11
|
+
return artwork.url
|
|
12
|
+
.replace("{w}", String(size))
|
|
13
|
+
.replace("{h}", String(size));
|
|
14
|
+
}
|
|
15
|
+
/** The credited artist ref for a song/album (Apple gives one primary name). */
|
|
16
|
+
function primaryArtistRef(name, relationshipArtistId) {
|
|
17
|
+
return relationshipArtistId === undefined
|
|
18
|
+
? { name }
|
|
19
|
+
: { name, externalId: relationshipArtistId };
|
|
20
|
+
}
|
|
21
|
+
/** Apple artist → normalized artist (no popularity; genres from genreNames). */
|
|
22
|
+
export function mapAppleArtist(raw) {
|
|
23
|
+
return {
|
|
24
|
+
name: raw.attributes.name,
|
|
25
|
+
genres: raw.attributes.genreNames ?? [],
|
|
26
|
+
imageUrl: formatArtwork(raw.attributes.artwork),
|
|
27
|
+
url: raw.attributes.url,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Apple song → normalized track. */
|
|
31
|
+
export function mapAppleTrack(raw) {
|
|
32
|
+
return {
|
|
33
|
+
title: raw.attributes.name,
|
|
34
|
+
artists: [
|
|
35
|
+
primaryArtistRef(raw.attributes.artistName, raw.relationships?.artists?.data?.[0]?.id),
|
|
36
|
+
],
|
|
37
|
+
isrc: raw.attributes.isrc,
|
|
38
|
+
genres: raw.attributes.genreNames ?? [],
|
|
39
|
+
durationMs: raw.attributes.durationInMillis,
|
|
40
|
+
previewUrl: raw.attributes.previews?.[0]?.url,
|
|
41
|
+
coverUrl: formatArtwork(raw.attributes.artwork),
|
|
42
|
+
url: raw.attributes.url,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** Apple album → normalized album. */
|
|
46
|
+
export function mapAppleAlbum(raw) {
|
|
47
|
+
return {
|
|
48
|
+
title: raw.attributes.name,
|
|
49
|
+
artists: [
|
|
50
|
+
primaryArtistRef(raw.attributes.artistName, raw.relationships?.artists?.data?.[0]?.id),
|
|
51
|
+
],
|
|
52
|
+
releaseDate: raw.attributes.releaseDate,
|
|
53
|
+
coverUrl: formatArtwork(raw.attributes.artwork),
|
|
54
|
+
url: raw.attributes.url,
|
|
55
|
+
trackCount: raw.attributes.trackCount,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Apple playlist → normalized playlist metadata. */
|
|
59
|
+
export function mapApplePlaylist(raw) {
|
|
60
|
+
return {
|
|
61
|
+
title: raw.attributes.name,
|
|
62
|
+
description: raw.attributes.description?.standard,
|
|
63
|
+
coverUrl: formatArtwork(raw.attributes.artwork),
|
|
64
|
+
url: raw.attributes.url,
|
|
65
|
+
owner: raw.attributes.curatorName,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=mappers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mappers.js","sourceRoot":"","sources":["../../../../src/component/providers/apple/mappers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiBH,+DAA+D;AAC/D,MAAM,CAAC,MAAM,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Apple adapter. Apple wraps
|
|
3
|
+
* resources as `{ data: [{ id, type, attributes, relationships }] }`; only the
|
|
4
|
+
* consumed fields are modeled. The public contract is the normalized schema.
|
|
5
|
+
*/
|
|
6
|
+
export interface AppleArtwork {
|
|
7
|
+
url: string;
|
|
8
|
+
width?: number;
|
|
9
|
+
height?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface AppleArtistRelationship {
|
|
12
|
+
data?: Array<{
|
|
13
|
+
id: string;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
export interface AppleArtistAttributes {
|
|
17
|
+
name: string;
|
|
18
|
+
genreNames?: string[];
|
|
19
|
+
url?: string;
|
|
20
|
+
artwork?: AppleArtwork;
|
|
21
|
+
}
|
|
22
|
+
export interface AppleSongAttributes {
|
|
23
|
+
name: string;
|
|
24
|
+
isrc?: string;
|
|
25
|
+
genreNames?: string[];
|
|
26
|
+
artistName: string;
|
|
27
|
+
durationInMillis?: number;
|
|
28
|
+
artwork?: AppleArtwork;
|
|
29
|
+
url?: string;
|
|
30
|
+
previews?: Array<{
|
|
31
|
+
url: string;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
export interface AppleAlbumAttributes {
|
|
35
|
+
name: string;
|
|
36
|
+
artistName: string;
|
|
37
|
+
releaseDate?: string;
|
|
38
|
+
trackCount?: number;
|
|
39
|
+
artwork?: AppleArtwork;
|
|
40
|
+
url?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface ApplePlaylistAttributes {
|
|
43
|
+
name: string;
|
|
44
|
+
description?: {
|
|
45
|
+
standard?: string;
|
|
46
|
+
};
|
|
47
|
+
curatorName?: string;
|
|
48
|
+
artwork?: AppleArtwork;
|
|
49
|
+
url?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface AppleResource<A> {
|
|
52
|
+
id: string;
|
|
53
|
+
type: string;
|
|
54
|
+
attributes: A;
|
|
55
|
+
relationships?: {
|
|
56
|
+
artists?: AppleArtistRelationship;
|
|
57
|
+
tracks?: {
|
|
58
|
+
data?: Array<AppleResource<AppleSongAttributes>>;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export type AppleArtist = AppleResource<AppleArtistAttributes>;
|
|
63
|
+
export type AppleSong = AppleResource<AppleSongAttributes>;
|
|
64
|
+
export type AppleAlbum = AppleResource<AppleAlbumAttributes>;
|
|
65
|
+
export type ApplePlaylist = AppleResource<ApplePlaylistAttributes>;
|
|
66
|
+
export interface AppleDataResponse<T> {
|
|
67
|
+
data: T[];
|
|
68
|
+
next?: string;
|
|
69
|
+
}
|
|
70
|
+
export interface AppleSearchResponse {
|
|
71
|
+
results?: {
|
|
72
|
+
artists?: {
|
|
73
|
+
data: AppleArtist[];
|
|
74
|
+
};
|
|
75
|
+
songs?: {
|
|
76
|
+
data: AppleSong[];
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/component/providers/apple/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,CAAC,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC9B;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;I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oB,CAAC,CAAC;AAC7D,MAAM,MAAM,aAAa,GAAG,aAAa,CAAC,uBAAuB,CAAC,CAAC;AAEnE,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,EAAE;YAAE,IAAI,EAAE,WAAW,EAAE,CAAA;SAAE,CAAC;QAClC,KAAK,CAAC,EAAE;YAAE,IAAI,EAAE,SAAS,EAAE,CAAA;SAAE,CAAC;KAC/B,CAAC;CACH"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw Apple Music API response shapes — private to the Apple adapter. Apple wraps
|
|
3
|
+
* resources as `{ data: [{ id, type, attributes, relationships }] }`; only the
|
|
4
|
+
* consumed fields are modeled. The public contract is the normalized schema.
|
|
5
|
+
*/
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/component/providers/apple/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deezer adapter — a no-auth, full music provider (previews + ISRC). Requests
|
|
3
|
+
* carry no bearer token. Ids are numbers (→ string external ids); the album/
|
|
4
|
+
* playlist endpoints inline their track list; artist albums fan out to per-album
|
|
5
|
+
* track fetches (bounded concurrency), like Spotify.
|
|
6
|
+
*/
|
|
7
|
+
import { type FetchDeps, type RetryConfig } from "../fetch.js";
|
|
8
|
+
import type { ArtistAlbumsResult, MusicProvider, ProviderAlbum, ProviderArtist, ProviderPlaylist, ProviderSearchResult, ProviderTrack } from "../types.js";
|
|
9
|
+
/** Tunable Deezer settings. */
|
|
10
|
+
export interface DeezerConfig {
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
retry: RetryConfig;
|
|
13
|
+
searchLimit: number;
|
|
14
|
+
topLimit: number;
|
|
15
|
+
maxAlbumsPerArtist: number;
|
|
16
|
+
albumConcurrency: number;
|
|
17
|
+
}
|
|
18
|
+
/** Default Deezer settings. */
|
|
19
|
+
export declare const DEFAULT_DEEZER_CONFIG: DeezerConfig;
|
|
20
|
+
export declare class DeezerProvider implements MusicProvider {
|
|
21
|
+
private readonly cfg;
|
|
22
|
+
private readonly deps;
|
|
23
|
+
readonly id: "deezer";
|
|
24
|
+
constructor(cfg?: DeezerConfig, deps?: FetchDeps);
|
|
25
|
+
private api;
|
|
26
|
+
private toTrack;
|
|
27
|
+
private toAlbum;
|
|
28
|
+
getArtist(externalId: string): Promise<ProviderArtist>;
|
|
29
|
+
getTrack(externalId: string): Promise<ProviderTrack>;
|
|
30
|
+
getAlbum(externalId: string): Promise<ProviderAlbum>;
|
|
31
|
+
getPlaylist(externalId: string): Promise<ProviderPlaylist>;
|
|
32
|
+
getArtistTopTracks(externalId: string): Promise<ProviderTrack[]>;
|
|
33
|
+
getArtistAlbums(externalId: string): Promise<ArtistAlbumsResult>;
|
|
34
|
+
search(query: string, type: "artist" | "track"): Promise<ProviderSearchResult[]>;
|
|
35
|
+
searchByIsrc(isrc: string): Promise<ProviderTrack[]>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"impl.d.ts","sourceRoot":"","sources":["../../../../src/component/providers/deezer/impl.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,WAAW,EAIjB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACd,MAAM,aAAa,CAAC;AAerB,+BAA+B;AAC/B,MAAM,W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
|
1
|
+
/**
|
|
2
|
+
* Deezer adapter — a no-auth, full music provider (previews + ISRC). Requests
|
|
3
|
+
* carry no bearer token. Ids are numbers (→ string external ids); the album/
|
|
4
|
+
* playlist endpoints inline their track list; artist albums fan out to per-album
|
|
5
|
+
* track fetches (bounded concurrency), like Spotify.
|
|
6
|
+
*/
|
|
7
|
+
import { DEFAULT_RETRY_CONFIG, defaultFetchDeps, fetchJson, mapWithConcurrency, } from "../fetch.js";
|
|
8
|
+
import { mapDeezerAlbum, mapDeezerArtist, mapDeezerPlaylist, mapDeezerTrack, } from "./mappers.js";
|
|
9
|
+
/** Default Deezer settings. */
|
|
10
|
+
export const DEFAULT_DEEZER_CONFIG = {
|
|
11
|
+
baseUrl: "https://api.deezer.com",
|
|
12
|
+
retry: DEFAULT_RETRY_CONFIG,
|
|
13
|
+
searchLimit: 10,
|
|
14
|
+
topLimit: 25,
|
|
15
|
+
maxAlbumsPerArtist: 30,
|
|
16
|
+
albumConcurrency: 5,
|
|
17
|
+
};
|
|
18
|
+
export class DeezerProvider {
|
|
19
|
+
cfg;
|
|
20
|
+
deps;
|
|
21
|
+
id = "deezer";
|
|
22
|
+
constructor(cfg = DEFAULT_DEEZER_CONFIG, deps = defaultFetchDeps) {
|
|
23
|
+
this.cfg = cfg;
|
|
24
|
+
this.deps = deps;
|
|
25
|
+
}
|
|
26
|
+
async api(path, params = {}) {
|
|
27
|
+
const url = new URL(this.cfg.baseUrl + path);
|
|
28
|
+
for (const [key, value] of Object.entries(params)) {
|
|
29
|
+
url.searchParams.set(key, value);
|
|
30
|
+
}
|
|
31
|
+
return fetchJson("deezer", url.toString(), {}, this.cfg.retry, this.deps);
|
|
32
|
+
}
|
|
33
|
+
toTrack(raw) {
|
|
34
|
+
return { externalId: String(raw.id), value: mapDeezerTrack(raw) };
|
|
35
|
+
}
|
|
36
|
+
toAlbum(raw) {
|
|
37
|
+
return {
|
|
38
|
+
externalId: String(raw.id),
|
|
39
|
+
value: mapDeezerAlbum(raw),
|
|
40
|
+
tracks: (raw.tracks?.data ?? []).map((track) => this.toTrack(track)),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async getArtist(externalId) {
|
|
44
|
+
const raw = await this.api(`/artist/${encodeURIComponent(externalId)}`);
|
|
45
|
+
return { externalId: String(raw.id), value: mapDeezerArtist(raw) };
|
|
46
|
+
}
|
|
47
|
+
async getTrack(externalId) {
|
|
48
|
+
return this.toTrack(await this.api(`/track/${encodeURIComponent(externalId)}`));
|
|
49
|
+
}
|
|
50
|
+
async getAlbum(externalId) {
|
|
51
|
+
return this.toAlbum(await this.api(`/album/${encodeURIComponent(externalId)}`));
|
|
52
|
+
}
|
|
53
|
+
async getPlaylist(externalId) {
|
|
54
|
+
const raw = await this.api(`/playlist/${encodeURIComponent(externalId)}`);
|
|
55
|
+
return {
|
|
56
|
+
externalId: String(raw.id),
|
|
57
|
+
value: mapDeezerPlaylist(raw),
|
|
58
|
+
tracks: (raw.tracks?.data ?? []).map((track) => this.toTrack(track)),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
async getArtistTopTracks(externalId) {
|
|
62
|
+
const res = await this.api(`/artist/${encodeURIComponent(externalId)}/top`, { limit: String(this.cfg.topLimit) });
|
|
63
|
+
return res.data.map((track) => this.toTrack(track));
|
|
64
|
+
}
|
|
65
|
+
async getArtistAlbums(externalId) {
|
|
66
|
+
const res = await this.api(`/artist/${encodeURIComponent(externalId)}/albums`, { limit: String(this.cfg.maxAlbumsPerArtist) });
|
|
67
|
+
const isPartial = res.next !== undefined;
|
|
68
|
+
const slice = res.data.slice(0, this.cfg.maxAlbumsPerArtist);
|
|
69
|
+
const albums = await mapWithConcurrency(slice, this.cfg.albumConcurrency, (album) => this.getAlbum(String(album.id)));
|
|
70
|
+
return { albums, isPartial };
|
|
71
|
+
}
|
|
72
|
+
async search(query, type) {
|
|
73
|
+
if (type === "artist") {
|
|
74
|
+
const res = await this.api("/search/artist", {
|
|
75
|
+
q: query,
|
|
76
|
+
limit: String(this.cfg.searchLimit),
|
|
77
|
+
});
|
|
78
|
+
return res.data.map((artist) => ({
|
|
79
|
+
type: "artist",
|
|
80
|
+
data: { externalId: String(artist.id), value: mapDeezerArtist(artist) },
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
const res = await this.api("/search/track", {
|
|
84
|
+
q: query,
|
|
85
|
+
limit: String(this.cfg.searchLimit),
|
|
86
|
+
});
|
|
87
|
+
return res.data.map((track) => ({
|
|
88
|
+
type: "track",
|
|
89
|
+
data: this.toTrack(track),
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
async searchByIsrc(isrc) {
|
|
93
|
+
const raw = await this.api(`/track/isrc:${encodeURIComponent(isrc)}`);
|
|
94
|
+
return raw.error === undefined && raw.id !== undefined
|
|
95
|
+
? [this.toTrack(raw)]
|
|
96
|
+
: [];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=impl.js.map
|