@particle-academy/youtube-js 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/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/README.md +51 -0
- package/dist/chunk-PVBL6AZS.js +109 -0
- package/dist/chunk-PVBL6AZS.js.map +1 -0
- package/dist/flow.cjs +133 -0
- package/dist/flow.cjs.map +1 -0
- package/dist/flow.d.cts +26 -0
- package/dist/flow.d.ts +26 -0
- package/dist/flow.js +25 -0
- package/dist/flow.js.map +1 -0
- package/dist/index.cjs +118 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +113 -0
- package/dist/index.d.ts +113 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +88 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@particle-academy/youtube-ui`,
|
|
4
|
+
`@particle-academy/youtube-js`, `particle-academy/youtube-php` and
|
|
5
|
+
`fancy-youtube`.
|
|
6
|
+
|
|
7
|
+
## [0.1.0] — 2026-08-23
|
|
8
|
+
|
|
9
|
+
First release.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `playlist_item_insert` — add a video to a YouTube playlist with
|
|
14
|
+
`POST /youtube/v3/playlistItems?part=snippet`.
|
|
15
|
+
- A top-level `PlaylistItem` faker for development without changing a channel.
|
|
16
|
+
|
|
17
|
+
### Fixed query protocol
|
|
18
|
+
|
|
19
|
+
YouTube requires `part=snippet` in the query. It names both the request section
|
|
20
|
+
being written and the response section included, so it is a fixed protocol
|
|
21
|
+
literal rather than a user-facing option.
|
|
22
|
+
|
|
23
|
+
### Narrow access, no sandbox, no idempotency
|
|
24
|
+
|
|
25
|
+
The connector requests `youtube.force-ssl`, the narrowest scope this method
|
|
26
|
+
accepts for modifying playlist contents. YouTube has no test estate, and
|
|
27
|
+
`playlistItems.insert` has no idempotency key; a retry can add the video twice.
|
|
28
|
+
|
|
29
|
+
[0.1.0]: https://github.com/Fancy-Friends/youtube/releases/tag/v0.1.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Particle Academy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# YouTube
|
|
2
|
+
|
|
3
|
+
YouTube for [fancy-flow][flow] — as **four imported, versioned packages**, one
|
|
4
|
+
per runtime. Not vendored source: a copy cannot be upgraded, and third-party APIs
|
|
5
|
+
change.
|
|
6
|
+
|
|
7
|
+
[flow]: https://github.com/Particle-Academy/fancy-flow
|
|
8
|
+
|
|
9
|
+
| Runtime | Package | Install |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| Authoring surface (every host) | `@particle-academy/youtube-ui` | `npm install @particle-academy/youtube-ui` |
|
|
12
|
+
| Node | `@particle-academy/youtube-js` | `npm install @particle-academy/youtube-js` |
|
|
13
|
+
| PHP 8.4+ | `particle-academy/youtube-php` | `composer require particle-academy/youtube-php` |
|
|
14
|
+
| Python 3.11+ | `fancy-youtube` | `pip install fancy-youtube` |
|
|
15
|
+
|
|
16
|
+
The `ui` package is the editor surface and is React on every host — a PHP or
|
|
17
|
+
Python project installs it *and* its own runtime package, and never the `js` one.
|
|
18
|
+
|
|
19
|
+
## What it costs you
|
|
20
|
+
|
|
21
|
+
One dependency: `@particle-academy/fancy-connector-core` (or
|
|
22
|
+
`particle-academy/fancy-connector-core` on Composer), which the `js` and `php`
|
|
23
|
+
packages pull in themselves. The Python package has **zero** runtime
|
|
24
|
+
dependencies.
|
|
25
|
+
|
|
26
|
+
**No YouTube SDK.** Plain HTTP, deliberately: a vendor SDK is third-party code
|
|
27
|
+
subject to the kit's full approval bar, and one per provider is hundreds of
|
|
28
|
+
dependencies nobody is tracking.
|
|
29
|
+
|
|
30
|
+
## Run it before you have credentials
|
|
31
|
+
|
|
32
|
+
Every operation ships a **faker**, whether or not YouTube has a sandbox. Set a
|
|
33
|
+
node's mode to `fake` and it returns the shape YouTube actually publishes — the
|
|
34
|
+
same field names, deterministically — so you can wire the downstream nodes before
|
|
35
|
+
touching an account, a key, or a network.
|
|
36
|
+
|
|
37
|
+
## This repository is generated
|
|
38
|
+
|
|
39
|
+
`provider/` is the source. Everything under `packages/` is emitted from it and
|
|
40
|
+
**must not be hand-edited** — CI regenerates and diffs on every push, and the
|
|
41
|
+
next protocol sync destroys anything it finds. See [`AGENTS.md`](AGENTS.md).
|
|
42
|
+
|
|
43
|
+
## Two namespaces, which do not match on purpose
|
|
44
|
+
|
|
45
|
+
The repo is `github.com/Fancy-Friends/youtube`; the packages publish under
|
|
46
|
+
`particle-academy`. Nothing derives one from the other — the names come from
|
|
47
|
+
weaver's `friends.json` and nowhere else.
|
|
48
|
+
|
|
49
|
+
## Licence
|
|
50
|
+
|
|
51
|
+
MIT.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { callConnector } from '@particle-academy/fancy-connector-core';
|
|
2
|
+
|
|
3
|
+
// src/faker.ts
|
|
4
|
+
function fakePlaylistItemInsert({ config, fake }) {
|
|
5
|
+
return {
|
|
6
|
+
"kind": "youtube#playlistItem",
|
|
7
|
+
"etag": "example-etag",
|
|
8
|
+
"id": fake.id("PLItem"),
|
|
9
|
+
"snippet": {
|
|
10
|
+
"publishedAt": "2026-01-01T00:00:00Z",
|
|
11
|
+
"channelId": "UCexamplechannel",
|
|
12
|
+
"title": "Example video",
|
|
13
|
+
"description": "",
|
|
14
|
+
"playlistId": config.playlistId !== void 0 && config.playlistId !== null && config.playlistId !== "" ? String(config.playlistId) : "PLexampleplaylist",
|
|
15
|
+
"position": 0,
|
|
16
|
+
"resourceId": {
|
|
17
|
+
"kind": "youtube#video",
|
|
18
|
+
"videoId": config.videoId !== void 0 && config.videoId !== null && config.videoId !== "" ? String(config.videoId) : "dQw4w9WgXcQ"
|
|
19
|
+
},
|
|
20
|
+
"videoOwnerChannelTitle": "Example channel",
|
|
21
|
+
"videoOwnerChannelId": "UCexampleowner"
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
var youtubeFaker = (operation, request) => {
|
|
26
|
+
switch (operation) {
|
|
27
|
+
case "playlist_item_insert":
|
|
28
|
+
return fakePlaylistItemInsert(request);
|
|
29
|
+
default:
|
|
30
|
+
throw new Error(
|
|
31
|
+
`youtube: no fake response is defined for "${operation}". Add a fixture under provider/fixtures/ and regenerate \u2014 a connector without a faker cannot be developed against, tested, or demonstrated.`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// src/service.ts
|
|
37
|
+
var CONNECTOR_API_VERSION = 1;
|
|
38
|
+
var YOUTUBE_BASE_URLS = {
|
|
39
|
+
"live": "https://youtube.googleapis.com"
|
|
40
|
+
};
|
|
41
|
+
var YOUTUBE_REQUIRES = [
|
|
42
|
+
"accessToken",
|
|
43
|
+
"refreshToken",
|
|
44
|
+
"clientId",
|
|
45
|
+
"clientSecret"
|
|
46
|
+
];
|
|
47
|
+
function youtubeAuthorize(credentials, request, _mode) {
|
|
48
|
+
request.headers.Authorization = `Bearer ${credentials.accessToken ?? ""}`;
|
|
49
|
+
}
|
|
50
|
+
var YOUTUBE = {
|
|
51
|
+
service: "youtube",
|
|
52
|
+
title: "YouTube",
|
|
53
|
+
sandbox: "none",
|
|
54
|
+
baseUrls: { ...YOUTUBE_BASE_URLS },
|
|
55
|
+
requires: [...YOUTUBE_REQUIRES],
|
|
56
|
+
authorize: youtubeAuthorize,
|
|
57
|
+
faker: youtubeFaker
|
|
58
|
+
};
|
|
59
|
+
var PLAYLIST_ITEM_INSERT_OPERATION = "playlist_item_insert";
|
|
60
|
+
async function youtubePlaylistItemInsert(options) {
|
|
61
|
+
const config = options.config ?? {};
|
|
62
|
+
if (config.playlistId === void 0 || config.playlistId === null || config.playlistId === "") {
|
|
63
|
+
throw new Error(`playlist_item_insert: "playlistId" is required (Playlist ID).`);
|
|
64
|
+
}
|
|
65
|
+
if (config.videoId === void 0 || config.videoId === null || config.videoId === "") {
|
|
66
|
+
throw new Error(`playlist_item_insert: "videoId" is required (Video ID).`);
|
|
67
|
+
}
|
|
68
|
+
return callConnector(YOUTUBE, {
|
|
69
|
+
operation: PLAYLIST_ITEM_INSERT_OPERATION,
|
|
70
|
+
config,
|
|
71
|
+
input: options.input,
|
|
72
|
+
...options.credentials === void 0 ? {} : { credentials: options.credentials },
|
|
73
|
+
...options.mode === void 0 ? {} : { mode: options.mode },
|
|
74
|
+
...options.connectionId === void 0 ? {} : { connectionId: options.connectionId },
|
|
75
|
+
...options.attempts === void 0 ? {} : { attempts: options.attempts },
|
|
76
|
+
...options.transport === void 0 ? {} : { transport: options.transport },
|
|
77
|
+
request: {
|
|
78
|
+
method: "POST",
|
|
79
|
+
path: "/youtube/v3/playlistItems",
|
|
80
|
+
json: nestFields({
|
|
81
|
+
"snippet.playlistId": String(config.playlistId),
|
|
82
|
+
"snippet.resourceId.videoId": String(config.videoId),
|
|
83
|
+
"snippet.resourceId.kind": "youtube#video"
|
|
84
|
+
}),
|
|
85
|
+
query: {
|
|
86
|
+
"part": "snippet"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
function nestFields(flat) {
|
|
92
|
+
const out = {};
|
|
93
|
+
for (const [path, value] of Object.entries(flat)) {
|
|
94
|
+
const parts = path.split(".");
|
|
95
|
+
let node = out;
|
|
96
|
+
while (parts.length > 1) {
|
|
97
|
+
const key = parts.shift();
|
|
98
|
+
const wantsArray = /^\d+$/.test(parts[0] ?? "");
|
|
99
|
+
if (typeof node[key] !== "object" || node[key] === null) node[key] = wantsArray ? [] : {};
|
|
100
|
+
node = node[key];
|
|
101
|
+
}
|
|
102
|
+
node[parts[0]] = value;
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export { CONNECTOR_API_VERSION, PLAYLIST_ITEM_INSERT_OPERATION, YOUTUBE, YOUTUBE_BASE_URLS, YOUTUBE_REQUIRES, youtubeAuthorize, youtubeFaker, youtubePlaylistItemInsert };
|
|
108
|
+
//# sourceMappingURL=chunk-PVBL6AZS.js.map
|
|
109
|
+
//# sourceMappingURL=chunk-PVBL6AZS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/faker.ts","../src/service.ts","../src/actions/playlist-item-insert.ts"],"names":[],"mappings":";;;AAyBA,SAAS,sBAAA,CAAuB,EAAE,MAAA,EAAQ,IAAA,EAAK,EAAyB;AACtE,EAAA,OAA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AAG,CAAA,KAAM,IAAA,OAAW,GAAG,CAAA,GAAI,UAAA,GAAa,KAAK,EAAC;AACxF,MAAA,IAAA,GAAO,KAAK,GAAG,CAAA;AAAA,IACjB;AAEA,IAAA,IAAA,CAAK,KAAA,CAAM,CAAC,CAAW,CAAA,GAAI,KAAA;AAAA,EAC7B;AAEA,EAAA,OAAO,GAAA;AACT","file":"chunk-PVBL6AZS.js","sourcesContent":["/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/fixtures/ by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/fixtures/ (or weaver's template/) and regenerate:\n *\n * npm run provider -- youtube\n */\n\n/**\n * The YouTube faker.\n *\n * Shapes, not behaviour: the goal is that a downstream node sees the field\n * NAMES YouTube actually publishes, so an author can wire {{ $json.data.id }}\n * against a fake and have it keep working against the real thing.\n *\n * Deterministic — same inputs, same output. A faker returning a fresh uuid\n * every call cannot be asserted on, so its fixtures degrade to \"it did not\n * throw\", which is the assertion that catches nothing.\n */\n\nimport type { ConnectorFaker, FakeRequest } from \"@particle-academy/fancy-connector-core\";\n\nfunction fakePlaylistItemInsert({ config, fake }: FakeRequest): unknown {\n return {\n \"kind\": \"youtube#playlistItem\",\n \"etag\": \"example-etag\",\n \"id\": fake.id(\"PLItem\"),\n \"snippet\": {\n \"publishedAt\": \"2026-01-01T00:00:00Z\",\n \"channelId\": \"UCexamplechannel\",\n \"title\": \"Example video\",\n \"description\": \"\",\n \"playlistId\": (config.playlistId !== undefined && config.playlistId !== null && config.playlistId !== \"\" ? String(config.playlistId) : \"PLexampleplaylist\"),\n \"position\": 0,\n \"resourceId\": {\n \"kind\": \"youtube#video\",\n \"videoId\": (config.videoId !== undefined && config.videoId !== null && config.videoId !== \"\" ? String(config.videoId) : \"dQw4w9WgXcQ\"),\n },\n \"videoOwnerChannelTitle\": \"Example channel\",\n \"videoOwnerChannelId\": \"UCexampleowner\",\n },\n };\n}\n\nexport const youtubeFaker: ConnectorFaker = (operation, request) => {\n switch (operation) {\n case \"playlist_item_insert\":\n return fakePlaylistItemInsert(request);\n\n default:\n // A faker asked for an operation it has no shape for must SAY so. Making\n // something up would produce a green run whose output silently has none\n // of the fields the author is about to reference.\n throw new Error(\n `youtube: no fake response is defined for \"${operation}\". ` +\n \"Add a fixture under provider/fixtures/ and regenerate — a connector without a faker \" +\n \"cannot be developed against, tested, or demonstrated.\",\n );\n }\n};\n","/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/manifest.json by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/manifest.json (or weaver's template/) and regenerate:\n *\n * npm run provider -- youtube\n */\n\n/**\n * YouTube, as one service descriptor shared by every YouTube operation.\n *\n * @particle-academy/fancy-connector-core carries what is true of ALL\n * connectors. This carries what is true of YouTube: its base URL, its auth\n * scheme, its idempotency header, and its faker.\n *\n * ## The sandbox trap, written down where it is used\n *\n * YouTube has no sandbox. Every live-mode add changes a real playlist; use the\n * faker during development and remove live test items afterward.\n */\n\nimport type { ConnectorMode, PreparedRequest, ServiceDescriptor } from \"@particle-academy/fancy-connector-core\";\n\nimport { youtubeFaker } from \"./faker.js\";\n\n/**\n * The connector API version this package was GENERATED against.\n *\n * A literal, never imported. An imported constant lets an upgrade rewrite the\n * very claim it exists to detect, after which the copy agrees with itself\n * forever.\n */\nexport const CONNECTOR_API_VERSION = 1;\n\nexport const YOUTUBE_BASE_URLS = {\n \"live\": \"https://youtube.googleapis.com\"\n} as const;\n\n/** Credential keys a remote call cannot proceed without. */\nexport const YOUTUBE_REQUIRES = [\n \"accessToken\",\n \"refreshToken\",\n \"clientId\",\n \"clientSecret\"\n] as const;\n\n/**\n * Apply YouTube's auth scheme to an outgoing request.\n *\n *\n *\n * The mode is passed in because for some providers auth and estate are the\n * same decision expressed in the URL; here it is unused, and saying so is\n * cheaper than wondering later whether it was forgotten.\n */\nexport function youtubeAuthorize(\n credentials: Record<string, string | undefined>,\n request: PreparedRequest,\n _mode: ConnectorMode,\n): void {\n request.headers.Authorization = `Bearer ${credentials.accessToken ?? \"\"}`;\n}\n\n/** The YouTube service, for the TypeScript runtime. */\nexport const YOUTUBE: ServiceDescriptor = {\n service: \"youtube\",\n title: \"YouTube\",\n sandbox: \"none\",\n baseUrls: { ...YOUTUBE_BASE_URLS },\n requires: [...YOUTUBE_REQUIRES],\n authorize: youtubeAuthorize,\n faker: youtubeFaker,\n};\n","/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/actions/playlist-item-insert.json by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/actions/playlist-item-insert.json (or weaver's template/) and regenerate:\n *\n * npm run provider -- youtube\n */\n\n/**\n * Add a video to a YouTube playlist.\n *\n * POST /youtube/v3/playlistItems —\n * https://developers.google.com/youtube/v3/docs/playlistItems/insert\n *\n * Notice what is NOT here: no key, no base URL, no mode check, no retry loop,\n * no fake/real branch. This describes the request; callConnector resolves the\n * connection, picks the estate, and either calls YouTube or calls the faker.\n *\n * sideEffects: unsafe-to-replay.\n */\n\nimport {\n callConnector,\n type ConnectorResult,\n type RequestedMode,\n type Transport,\n} from \"@particle-academy/fancy-connector-core\";\nimport { YOUTUBE } from \"../service.js\";\n\nexport const PLAYLIST_ITEM_INSERT_OPERATION = \"playlist_item_insert\";\n\nexport type PlaylistItemInsertOptions = {\n /** The node's resolved config. Keys: playlistId, videoId. */\n config: Record<string, unknown>;\n credentials?: Record<string, string | undefined>;\n mode?: RequestedMode;\n connectionId?: string | null;\n input?: unknown;\n attempts?: number;\n /** Override the transport. The only way to exercise this without a network. */\n transport?: Transport;\n};\n\nexport async function youtubePlaylistItemInsert(options: PlaylistItemInsertOptions): Promise<ConnectorResult> {\n const config = options.config ?? {};\n\n if (config.playlistId === undefined || config.playlistId === null || config.playlistId === \"\") {\n throw new Error(`playlist_item_insert: \"playlistId\" is required (Playlist ID).`);\n }\n\n if (config.videoId === undefined || config.videoId === null || config.videoId === \"\") {\n throw new Error(`playlist_item_insert: \"videoId\" is required (Video ID).`);\n }\n\n return callConnector(YOUTUBE, {\n operation: PLAYLIST_ITEM_INSERT_OPERATION,\n config,\n input: options.input,\n ...(options.credentials === undefined ? {} : { credentials: options.credentials }),\n ...(options.mode === undefined ? {} : { mode: options.mode }),\n ...(options.connectionId === undefined ? {} : { connectionId: options.connectionId }),\n ...(options.attempts === undefined ? {} : { attempts: options.attempts }),\n ...(options.transport === undefined ? {} : { transport: options.transport }),\n request: {\n method: \"POST\",\n path: \"/youtube/v3/playlistItems\",\n json: nestFields({\n \"snippet.playlistId\": String(config.playlistId),\n \"snippet.resourceId.videoId\": String(config.videoId),\n \"snippet.resourceId.kind\": \"youtube#video\",\n }),\n query: {\n \"part\": \"snippet\",\n },\n },\n });\n}\n\n/**\n * `{\"properties.email\": x}` -> `{properties: {email: x}}`.\n *\n * A dotted `as` means NESTING, and only a JSON body can nest. The validator\n * refuses that spelling anywhere else, because in a form body it already means\n * something different — a literal dotted key.\n */\nfunction nestFields(flat: Record<string, unknown>): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n\n for (const [path, value] of Object.entries(flat)) {\n const parts = path.split(\".\");\n let node = out;\n\n while (parts.length > 1) {\n const key = parts.shift() as string;\n // A NUMERIC segment is an array index: `dateRanges.0.startDate` has to\n // become `[{startDate}]`, not `{\"0\": {startDate}}`. PHP produced the\n // array by accident (its integer-keyed arrays serialise as JSON lists)\n // and the other two produced an object, which the provider rejects as\n // the wrong type. The parity suite is what caught the disagreement.\n const wantsArray = /^\\d+$/.test(parts[0] ?? \"\");\n\n if (typeof node[key] !== \"object\" || node[key] === null) node[key] = wantsArray ? [] : {};\n node = node[key] as Record<string, unknown>;\n }\n\n node[parts[0] as string] = value;\n }\n\n return out;\n}\n"]}
|
package/dist/flow.cjs
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fancyConnectorCore = require('@particle-academy/fancy-connector-core');
|
|
4
|
+
var youtubeUi = require('@particle-academy/youtube-ui');
|
|
5
|
+
|
|
6
|
+
// src/flow.ts
|
|
7
|
+
|
|
8
|
+
// src/faker.ts
|
|
9
|
+
function fakePlaylistItemInsert({ config, fake }) {
|
|
10
|
+
return {
|
|
11
|
+
"kind": "youtube#playlistItem",
|
|
12
|
+
"etag": "example-etag",
|
|
13
|
+
"id": fake.id("PLItem"),
|
|
14
|
+
"snippet": {
|
|
15
|
+
"publishedAt": "2026-01-01T00:00:00Z",
|
|
16
|
+
"channelId": "UCexamplechannel",
|
|
17
|
+
"title": "Example video",
|
|
18
|
+
"description": "",
|
|
19
|
+
"playlistId": config.playlistId !== void 0 && config.playlistId !== null && config.playlistId !== "" ? String(config.playlistId) : "PLexampleplaylist",
|
|
20
|
+
"position": 0,
|
|
21
|
+
"resourceId": {
|
|
22
|
+
"kind": "youtube#video",
|
|
23
|
+
"videoId": config.videoId !== void 0 && config.videoId !== null && config.videoId !== "" ? String(config.videoId) : "dQw4w9WgXcQ"
|
|
24
|
+
},
|
|
25
|
+
"videoOwnerChannelTitle": "Example channel",
|
|
26
|
+
"videoOwnerChannelId": "UCexampleowner"
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
var youtubeFaker = (operation, request) => {
|
|
31
|
+
switch (operation) {
|
|
32
|
+
case "playlist_item_insert":
|
|
33
|
+
return fakePlaylistItemInsert(request);
|
|
34
|
+
default:
|
|
35
|
+
throw new Error(
|
|
36
|
+
`youtube: no fake response is defined for "${operation}". Add a fixture under provider/fixtures/ and regenerate \u2014 a connector without a faker cannot be developed against, tested, or demonstrated.`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/service.ts
|
|
42
|
+
var YOUTUBE_BASE_URLS = {
|
|
43
|
+
"live": "https://youtube.googleapis.com"
|
|
44
|
+
};
|
|
45
|
+
var YOUTUBE_REQUIRES = [
|
|
46
|
+
"accessToken",
|
|
47
|
+
"refreshToken",
|
|
48
|
+
"clientId",
|
|
49
|
+
"clientSecret"
|
|
50
|
+
];
|
|
51
|
+
function youtubeAuthorize(credentials, request, _mode) {
|
|
52
|
+
request.headers.Authorization = `Bearer ${credentials.accessToken ?? ""}`;
|
|
53
|
+
}
|
|
54
|
+
var YOUTUBE = {
|
|
55
|
+
service: "youtube",
|
|
56
|
+
title: "YouTube",
|
|
57
|
+
sandbox: "none",
|
|
58
|
+
baseUrls: { ...YOUTUBE_BASE_URLS },
|
|
59
|
+
requires: [...YOUTUBE_REQUIRES],
|
|
60
|
+
authorize: youtubeAuthorize,
|
|
61
|
+
faker: youtubeFaker
|
|
62
|
+
};
|
|
63
|
+
var PLAYLIST_ITEM_INSERT_OPERATION = "playlist_item_insert";
|
|
64
|
+
async function youtubePlaylistItemInsert(options) {
|
|
65
|
+
const config = options.config ?? {};
|
|
66
|
+
if (config.playlistId === void 0 || config.playlistId === null || config.playlistId === "") {
|
|
67
|
+
throw new Error(`playlist_item_insert: "playlistId" is required (Playlist ID).`);
|
|
68
|
+
}
|
|
69
|
+
if (config.videoId === void 0 || config.videoId === null || config.videoId === "") {
|
|
70
|
+
throw new Error(`playlist_item_insert: "videoId" is required (Video ID).`);
|
|
71
|
+
}
|
|
72
|
+
return fancyConnectorCore.callConnector(YOUTUBE, {
|
|
73
|
+
operation: PLAYLIST_ITEM_INSERT_OPERATION,
|
|
74
|
+
config,
|
|
75
|
+
input: options.input,
|
|
76
|
+
...options.credentials === void 0 ? {} : { credentials: options.credentials },
|
|
77
|
+
...options.mode === void 0 ? {} : { mode: options.mode },
|
|
78
|
+
...options.connectionId === void 0 ? {} : { connectionId: options.connectionId },
|
|
79
|
+
...options.attempts === void 0 ? {} : { attempts: options.attempts },
|
|
80
|
+
...options.transport === void 0 ? {} : { transport: options.transport },
|
|
81
|
+
request: {
|
|
82
|
+
method: "POST",
|
|
83
|
+
path: "/youtube/v3/playlistItems",
|
|
84
|
+
json: nestFields({
|
|
85
|
+
"snippet.playlistId": String(config.playlistId),
|
|
86
|
+
"snippet.resourceId.videoId": String(config.videoId),
|
|
87
|
+
"snippet.resourceId.kind": "youtube#video"
|
|
88
|
+
}),
|
|
89
|
+
query: {
|
|
90
|
+
"part": "snippet"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function nestFields(flat) {
|
|
96
|
+
const out = {};
|
|
97
|
+
for (const [path, value] of Object.entries(flat)) {
|
|
98
|
+
const parts = path.split(".");
|
|
99
|
+
let node = out;
|
|
100
|
+
while (parts.length > 1) {
|
|
101
|
+
const key = parts.shift();
|
|
102
|
+
const wantsArray = /^\d+$/.test(parts[0] ?? "");
|
|
103
|
+
if (typeof node[key] !== "object" || node[key] === null) node[key] = wantsArray ? [] : {};
|
|
104
|
+
node = node[key];
|
|
105
|
+
}
|
|
106
|
+
node[parts[0]] = value;
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/flow.ts
|
|
112
|
+
var youtubePlaylistItemExecutor = async (ctx) => {
|
|
113
|
+
const config = ctx.node.data?.config ?? {};
|
|
114
|
+
const result = await youtubePlaylistItemInsert({
|
|
115
|
+
config,
|
|
116
|
+
input: ctx.inputs?.in
|
|
117
|
+
});
|
|
118
|
+
ctx.emit({
|
|
119
|
+
type: "log",
|
|
120
|
+
level: "info",
|
|
121
|
+
nodeId: ctx.node.id,
|
|
122
|
+
message: `youtube playlist_item_insert ${result.data?.id} (${result.mode})`
|
|
123
|
+
});
|
|
124
|
+
return { __port: "out", value: result };
|
|
125
|
+
};
|
|
126
|
+
var YOUTUBE_RUNNABLE_KINDS = [
|
|
127
|
+
{ ...youtubeUi.youtubePlaylistItemKind, executor: youtubePlaylistItemExecutor }
|
|
128
|
+
];
|
|
129
|
+
|
|
130
|
+
exports.YOUTUBE_RUNNABLE_KINDS = YOUTUBE_RUNNABLE_KINDS;
|
|
131
|
+
exports.youtubePlaylistItemExecutor = youtubePlaylistItemExecutor;
|
|
132
|
+
//# sourceMappingURL=flow.cjs.map
|
|
133
|
+
//# sourceMappingURL=flow.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/faker.ts","../src/service.ts","../src/actions/playlist-item-insert.ts","../src/flow.ts"],"names":["callConnector","youtubePlaylistItemKind"],"mappings":";;;;;;;;AAyBA,SAAS,sBAAA,CAAuB,EAAE,MAAA,EAAQ,IAAA,EAAK,EAAyB;AACtE,EAAA,OAAO;AAAA,IACL,MAAA,EAAQ,sBAAA;AAAA,IACR,MAAA,EAAQ,cAAA;AAAA,IACR,IAAA,EAAM,IAAA,CAAK,EAAA,CAAG,QAAQ,CAAA;AAAA,IACtB,SAAA,EAAW;AAAA,MACT,aAAA,EAAe,sBAAA;AAAA,MACf,WAAA,EAAa,kBAAA;AAAA,MACb,OAAA,EAAS,eAAA;AAAA,MACT,aAAA,EAAe,EAAA;AAAA,MACf,YAAA,EAAe,MAAA,CAAO,UAAA,KAAe,MAAA,IAAa,MAAA,CAAO,UAAA,KAAe,IAAA,IAAQ,MAAA,CAAO,UAAA,KAAe,EAAA,GAAK,MAAA,CAAO,MAAA,CAAO,UAAU,CAAA,GAAI,mBAAA;AAAA,MACvI,UAAA,EAAY,CAAA;AAAA,MACZ,YAAA,EAAc;AAAA,QACZ,MAAA,EAAQ,eAAA;AAAA,QACR,SAAA,EAAY,MAAA,CAAO,OAAA,KAAY,MAAA,IAAa,MAAA,CAAO,OAAA,KAAY,IAAA,IAAQ,MAAA,CAAO,OAAA,KAAY,EAAA,GAAK,MAAA,CAAO,MAAA,CAAO,OAAO,CAAA,GAAI;AAAA,OAC1H;AAAA,MACA,wBAAA,EAA0B,iBAAA;AAAA,MAC1B,qBAAA,EAAuB;AAAA;AACzB,GACF;AACF;AAEO,IAAM,YAAA,GAA+B,CAAC,SAAA,EAAW,OAAA,KAAY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BAAA,GAA+C;AAAA,EAC1D,EAAE,GAAGC,iCAAA,EAAyB,QAAA,EAAU,2BAAA;AAC1C","file":"flow.cjs","sourcesContent":["/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/fixtures/ by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/fixtures/ (or weaver's template/) and regenerate:\n *\n * npm run provider -- youtube\n */\n\n/**\n * The YouTube faker.\n *\n * Shapes, not behaviour: the goal is that a downstream node sees the field\n * NAMES YouTube actually publishes, so an author can wire {{ $json.data.id }}\n * against a fake and have it keep working against the real thing.\n *\n * Deterministic — same inputs, same output. A faker returning a fresh uuid\n * every call cannot be asserted on, so its fixtures degrade to \"it did not\n * throw\", which is the assertion that catches nothing.\n */\n\nimport type { ConnectorFaker, FakeRequest } from \"@particle-academy/fancy-connector-core\";\n\nfunction fakePlaylistItemInsert({ config, fake }: FakeRequest): unknown {\n return {\n \"kind\": \"youtube#playlistItem\",\n \"etag\": \"example-etag\",\n \"id\": fake.id(\"PLItem\"),\n \"snippet\": {\n \"publishedAt\": \"2026-01-01T00:00:00Z\",\n \"channelId\": \"UCexamplechannel\",\n \"title\": \"Example video\",\n \"description\": \"\",\n \"playlistId\": (config.playlistId !== undefined && config.playlistId !== null && config.playlistId !== \"\" ? String(config.playlistId) : \"PLexampleplaylist\"),\n \"position\": 0,\n \"resourceId\": {\n \"kind\": \"youtube#video\",\n \"videoId\": (config.videoId !== undefined && config.videoId !== null && config.videoId !== \"\" ? String(config.videoId) : \"dQw4w9WgXcQ\"),\n },\n \"videoOwnerChannelTitle\": \"Example channel\",\n \"videoOwnerChannelId\": \"UCexampleowner\",\n },\n };\n}\n\nexport const youtubeFaker: ConnectorFaker = (operation, request) => {\n switch (operation) {\n case \"playlist_item_insert\":\n return fakePlaylistItemInsert(request);\n\n default:\n // A faker asked for an operation it has no shape for must SAY so. Making\n // something up would produce a green run whose output silently has none\n // of the fields the author is about to reference.\n throw new Error(\n `youtube: no fake response is defined for \"${operation}\". ` +\n \"Add a fixture under provider/fixtures/ and regenerate — a connector without a faker \" +\n \"cannot be developed against, tested, or demonstrated.\",\n );\n }\n};\n","/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/manifest.json by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/manifest.json (or weaver's template/) and regenerate:\n *\n * npm run provider -- youtube\n */\n\n/**\n * YouTube, as one service descriptor shared by every YouTube operation.\n *\n * @particle-academy/fancy-connector-core carries what is true of ALL\n * connectors. This carries what is true of YouTube: its base URL, its auth\n * scheme, its idempotency header, and its faker.\n *\n * ## The sandbox trap, written down where it is used\n *\n * YouTube has no sandbox. Every live-mode add changes a real playlist; use the\n * faker during development and remove live test items afterward.\n */\n\nimport type { ConnectorMode, PreparedRequest, ServiceDescriptor } from \"@particle-academy/fancy-connector-core\";\n\nimport { youtubeFaker } from \"./faker.js\";\n\n/**\n * The connector API version this package was GENERATED against.\n *\n * A literal, never imported. An imported constant lets an upgrade rewrite the\n * very claim it exists to detect, after which the copy agrees with itself\n * forever.\n */\nexport const CONNECTOR_API_VERSION = 1;\n\nexport const YOUTUBE_BASE_URLS = {\n \"live\": \"https://youtube.googleapis.com\"\n} as const;\n\n/** Credential keys a remote call cannot proceed without. */\nexport const YOUTUBE_REQUIRES = [\n \"accessToken\",\n \"refreshToken\",\n \"clientId\",\n \"clientSecret\"\n] as const;\n\n/**\n * Apply YouTube's auth scheme to an outgoing request.\n *\n *\n *\n * The mode is passed in because for some providers auth and estate are the\n * same decision expressed in the URL; here it is unused, and saying so is\n * cheaper than wondering later whether it was forgotten.\n */\nexport function youtubeAuthorize(\n credentials: Record<string, string | undefined>,\n request: PreparedRequest,\n _mode: ConnectorMode,\n): void {\n request.headers.Authorization = `Bearer ${credentials.accessToken ?? \"\"}`;\n}\n\n/** The YouTube service, for the TypeScript runtime. */\nexport const YOUTUBE: ServiceDescriptor = {\n service: \"youtube\",\n title: \"YouTube\",\n sandbox: \"none\",\n baseUrls: { ...YOUTUBE_BASE_URLS },\n requires: [...YOUTUBE_REQUIRES],\n authorize: youtubeAuthorize,\n faker: youtubeFaker,\n};\n","/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/actions/playlist-item-insert.json by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/actions/playlist-item-insert.json (or weaver's template/) and regenerate:\n *\n * npm run provider -- youtube\n */\n\n/**\n * Add a video to a YouTube playlist.\n *\n * POST /youtube/v3/playlistItems —\n * https://developers.google.com/youtube/v3/docs/playlistItems/insert\n *\n * Notice what is NOT here: no key, no base URL, no mode check, no retry loop,\n * no fake/real branch. This describes the request; callConnector resolves the\n * connection, picks the estate, and either calls YouTube or calls the faker.\n *\n * sideEffects: unsafe-to-replay.\n */\n\nimport {\n callConnector,\n type ConnectorResult,\n type RequestedMode,\n type Transport,\n} from \"@particle-academy/fancy-connector-core\";\nimport { YOUTUBE } from \"../service.js\";\n\nexport const PLAYLIST_ITEM_INSERT_OPERATION = \"playlist_item_insert\";\n\nexport type PlaylistItemInsertOptions = {\n /** The node's resolved config. Keys: playlistId, videoId. */\n config: Record<string, unknown>;\n credentials?: Record<string, string | undefined>;\n mode?: RequestedMode;\n connectionId?: string | null;\n input?: unknown;\n attempts?: number;\n /** Override the transport. The only way to exercise this without a network. */\n transport?: Transport;\n};\n\nexport async function youtubePlaylistItemInsert(options: PlaylistItemInsertOptions): Promise<ConnectorResult> {\n const config = options.config ?? {};\n\n if (config.playlistId === undefined || config.playlistId === null || config.playlistId === \"\") {\n throw new Error(`playlist_item_insert: \"playlistId\" is required (Playlist ID).`);\n }\n\n if (config.videoId === undefined || config.videoId === null || config.videoId === \"\") {\n throw new Error(`playlist_item_insert: \"videoId\" is required (Video ID).`);\n }\n\n return callConnector(YOUTUBE, {\n operation: PLAYLIST_ITEM_INSERT_OPERATION,\n config,\n input: options.input,\n ...(options.credentials === undefined ? {} : { credentials: options.credentials }),\n ...(options.mode === undefined ? {} : { mode: options.mode }),\n ...(options.connectionId === undefined ? {} : { connectionId: options.connectionId }),\n ...(options.attempts === undefined ? {} : { attempts: options.attempts }),\n ...(options.transport === undefined ? {} : { transport: options.transport }),\n request: {\n method: \"POST\",\n path: \"/youtube/v3/playlistItems\",\n json: nestFields({\n \"snippet.playlistId\": String(config.playlistId),\n \"snippet.resourceId.videoId\": String(config.videoId),\n \"snippet.resourceId.kind\": \"youtube#video\",\n }),\n query: {\n \"part\": \"snippet\",\n },\n },\n });\n}\n\n/**\n * `{\"properties.email\": x}` -> `{properties: {email: x}}`.\n *\n * A dotted `as` means NESTING, and only a JSON body can nest. The validator\n * refuses that spelling anywhere else, because in a form body it already means\n * something different — a literal dotted key.\n */\nfunction nestFields(flat: Record<string, unknown>): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n\n for (const [path, value] of Object.entries(flat)) {\n const parts = path.split(\".\");\n let node = out;\n\n while (parts.length > 1) {\n const key = parts.shift() as string;\n // A NUMERIC segment is an array index: `dateRanges.0.startDate` has to\n // become `[{startDate}]`, not `{\"0\": {startDate}}`. PHP produced the\n // array by accident (its integer-keyed arrays serialise as JSON lists)\n // and the other two produced an object, which the provider rejects as\n // the wrong type. The parity suite is what caught the disagreement.\n const wantsArray = /^\\d+$/.test(parts[0] ?? \"\");\n\n if (typeof node[key] !== \"object\" || node[key] === null) node[key] = wantsArray ? [] : {};\n node = node[key] as Record<string, unknown>;\n }\n\n node[parts[0] as string] = value;\n }\n\n return out;\n}\n","/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/actions/ + triggers/ by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/actions/ + triggers/ (or weaver's template/) and regenerate:\n *\n * npm run provider -- youtube\n */\n\n/**\n * YouTube's node kinds with their TypeScript executors attached — for hosts\n * that EXECUTE on TS.\n *\n * The authoring surface in @particle-academy/youtube-ui carries no executor:\n * the editor is React on every host, so a PHP or Python project installs the\n * ui package and never this one.\n */\n\nimport type { NodeExecutor, NodeKindDefinition } from \"@particle-academy/fancy-flow/engine\";\nimport {\n idempotencyKeyFor,\n NO_IDEMPOTENCY_KEY_WARNING,\n resolveConnection,\n triggerEvent,\n type RequestedMode,\n} from \"@particle-academy/fancy-connector-core\";\nimport { YOUTUBE } from \"./service.js\";\n\nimport {\n youtubePlaylistItemKind,\n} from \"@particle-academy/youtube-ui\";\n\nimport { youtubePlaylistItemInsert } from \"./actions/playlist-item-insert.js\";\n\nexport const youtubePlaylistItemExecutor: NodeExecutor = async (ctx) => {\n const config = ((ctx.node.data as { config?: Record<string, unknown> })?.config ?? {});\n\n const result = await youtubePlaylistItemInsert({\n config,\n input: ctx.inputs?.in,\n });\n\n ctx.emit({\n type: \"log\",\n level: \"info\",\n nodeId: ctx.node.id,\n message: `youtube playlist_item_insert ${(result.data as { id?: string })?.id} (${result.mode})`,\n });\n\n return { __port: \"out\", value: result };\n};\n\n/** The kinds a TypeScript host registers. */\nexport const YOUTUBE_RUNNABLE_KINDS: NodeKindDefinition[] = [\n { ...youtubePlaylistItemKind, executor: youtubePlaylistItemExecutor },\n];\n"]}
|
package/dist/flow.d.cts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { NodeKindDefinition, NodeExecutor } from '@particle-academy/fancy-flow/engine';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GENERATED FILE — do not edit.
|
|
5
|
+
*
|
|
6
|
+
* Emitted from provider/actions/ + triggers/ by weaver's generator.
|
|
7
|
+
* A hand-edit here is destroyed by the next protocol sync, which is worse than
|
|
8
|
+
* being rejected, because it works until it silently does not. Fix
|
|
9
|
+
* provider/actions/ + triggers/ (or weaver's template/) and regenerate:
|
|
10
|
+
*
|
|
11
|
+
* npm run provider -- youtube
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* YouTube's node kinds with their TypeScript executors attached — for hosts
|
|
15
|
+
* that EXECUTE on TS.
|
|
16
|
+
*
|
|
17
|
+
* The authoring surface in @particle-academy/youtube-ui carries no executor:
|
|
18
|
+
* the editor is React on every host, so a PHP or Python project installs the
|
|
19
|
+
* ui package and never this one.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
declare const youtubePlaylistItemExecutor: NodeExecutor;
|
|
23
|
+
/** The kinds a TypeScript host registers. */
|
|
24
|
+
declare const YOUTUBE_RUNNABLE_KINDS: NodeKindDefinition[];
|
|
25
|
+
|
|
26
|
+
export { YOUTUBE_RUNNABLE_KINDS, youtubePlaylistItemExecutor };
|
package/dist/flow.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { NodeKindDefinition, NodeExecutor } from '@particle-academy/fancy-flow/engine';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GENERATED FILE — do not edit.
|
|
5
|
+
*
|
|
6
|
+
* Emitted from provider/actions/ + triggers/ by weaver's generator.
|
|
7
|
+
* A hand-edit here is destroyed by the next protocol sync, which is worse than
|
|
8
|
+
* being rejected, because it works until it silently does not. Fix
|
|
9
|
+
* provider/actions/ + triggers/ (or weaver's template/) and regenerate:
|
|
10
|
+
*
|
|
11
|
+
* npm run provider -- youtube
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* YouTube's node kinds with their TypeScript executors attached — for hosts
|
|
15
|
+
* that EXECUTE on TS.
|
|
16
|
+
*
|
|
17
|
+
* The authoring surface in @particle-academy/youtube-ui carries no executor:
|
|
18
|
+
* the editor is React on every host, so a PHP or Python project installs the
|
|
19
|
+
* ui package and never this one.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
declare const youtubePlaylistItemExecutor: NodeExecutor;
|
|
23
|
+
/** The kinds a TypeScript host registers. */
|
|
24
|
+
declare const YOUTUBE_RUNNABLE_KINDS: NodeKindDefinition[];
|
|
25
|
+
|
|
26
|
+
export { YOUTUBE_RUNNABLE_KINDS, youtubePlaylistItemExecutor };
|
package/dist/flow.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { youtubePlaylistItemInsert } from './chunk-PVBL6AZS.js';
|
|
2
|
+
import '@particle-academy/fancy-connector-core';
|
|
3
|
+
import { youtubePlaylistItemKind } from '@particle-academy/youtube-ui';
|
|
4
|
+
|
|
5
|
+
var youtubePlaylistItemExecutor = async (ctx) => {
|
|
6
|
+
const config = ctx.node.data?.config ?? {};
|
|
7
|
+
const result = await youtubePlaylistItemInsert({
|
|
8
|
+
config,
|
|
9
|
+
input: ctx.inputs?.in
|
|
10
|
+
});
|
|
11
|
+
ctx.emit({
|
|
12
|
+
type: "log",
|
|
13
|
+
level: "info",
|
|
14
|
+
nodeId: ctx.node.id,
|
|
15
|
+
message: `youtube playlist_item_insert ${result.data?.id} (${result.mode})`
|
|
16
|
+
});
|
|
17
|
+
return { __port: "out", value: result };
|
|
18
|
+
};
|
|
19
|
+
var YOUTUBE_RUNNABLE_KINDS = [
|
|
20
|
+
{ ...youtubePlaylistItemKind, executor: youtubePlaylistItemExecutor }
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
export { YOUTUBE_RUNNABLE_KINDS, youtubePlaylistItemExecutor };
|
|
24
|
+
//# sourceMappingURL=flow.js.map
|
|
25
|
+
//# sourceMappingURL=flow.js.map
|
package/dist/flow.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/flow.ts"],"names":[],"mappings":";;;;AAoCO,IAAM,2BAAA,GAA4C,OAAO,GAAA,KAAQ;AACtE,EAAA,MAAM,MAAA,GAAW,GAAA,CAAI,IAAA,CAAK,IAAA,EAA+C,UAAU,EAAC;AAEpF,EAAA,MAAM,MAAA,GAAS,MAAM,yBAAA,CAA0B;AAAA,IAC7C,MAAA;AAAA,IACA,KAAA,EAAO,IAAI,MAAA,EAAQ;AAAA,GACpB,CAAA;AAED,EAAA,GAAA,CAAI,IAAA,CAAK;AAAA,IACP,IAAA,EAAM,KAAA;AAAA,IACN,KAAA,EAAO,MAAA;AAAA,IACP,MAAA,EAAQ,IAAI,IAAA,CAAK,EAAA;AAAA,IACjB,SAAS,CAAA,6BAAA,EAAiC,MAAA,CAAO,MAA0B,EAAE,CAAA,EAAA,EAAK,OAAO,IAAI,CAAA,CAAA;AAAA,GAC9F,CAAA;AAED,EAAA,OAAO,EAAE,MAAA,EAAQ,KAAA,EAAO,KAAA,EAAO,MAAA,EAAO;AACxC;AAGO,IAAM,sBAAA,GAA+C;AAAA,EAC1D,EAAE,GAAG,uBAAA,EAAyB,QAAA,EAAU,2BAAA;AAC1C","file":"flow.js","sourcesContent":["/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/actions/ + triggers/ by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/actions/ + triggers/ (or weaver's template/) and regenerate:\n *\n * npm run provider -- youtube\n */\n\n/**\n * YouTube's node kinds with their TypeScript executors attached — for hosts\n * that EXECUTE on TS.\n *\n * The authoring surface in @particle-academy/youtube-ui carries no executor:\n * the editor is React on every host, so a PHP or Python project installs the\n * ui package and never this one.\n */\n\nimport type { NodeExecutor, NodeKindDefinition } from \"@particle-academy/fancy-flow/engine\";\nimport {\n idempotencyKeyFor,\n NO_IDEMPOTENCY_KEY_WARNING,\n resolveConnection,\n triggerEvent,\n type RequestedMode,\n} from \"@particle-academy/fancy-connector-core\";\nimport { YOUTUBE } from \"./service.js\";\n\nimport {\n youtubePlaylistItemKind,\n} from \"@particle-academy/youtube-ui\";\n\nimport { youtubePlaylistItemInsert } from \"./actions/playlist-item-insert.js\";\n\nexport const youtubePlaylistItemExecutor: NodeExecutor = async (ctx) => {\n const config = ((ctx.node.data as { config?: Record<string, unknown> })?.config ?? {});\n\n const result = await youtubePlaylistItemInsert({\n config,\n input: ctx.inputs?.in,\n });\n\n ctx.emit({\n type: \"log\",\n level: \"info\",\n nodeId: ctx.node.id,\n message: `youtube playlist_item_insert ${(result.data as { id?: string })?.id} (${result.mode})`,\n });\n\n return { __port: \"out\", value: result };\n};\n\n/** The kinds a TypeScript host registers. */\nexport const YOUTUBE_RUNNABLE_KINDS: NodeKindDefinition[] = [\n { ...youtubePlaylistItemKind, executor: youtubePlaylistItemExecutor },\n];\n"]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fancyConnectorCore = require('@particle-academy/fancy-connector-core');
|
|
4
|
+
|
|
5
|
+
// src/faker.ts
|
|
6
|
+
function fakePlaylistItemInsert({ config, fake }) {
|
|
7
|
+
return {
|
|
8
|
+
"kind": "youtube#playlistItem",
|
|
9
|
+
"etag": "example-etag",
|
|
10
|
+
"id": fake.id("PLItem"),
|
|
11
|
+
"snippet": {
|
|
12
|
+
"publishedAt": "2026-01-01T00:00:00Z",
|
|
13
|
+
"channelId": "UCexamplechannel",
|
|
14
|
+
"title": "Example video",
|
|
15
|
+
"description": "",
|
|
16
|
+
"playlistId": config.playlistId !== void 0 && config.playlistId !== null && config.playlistId !== "" ? String(config.playlistId) : "PLexampleplaylist",
|
|
17
|
+
"position": 0,
|
|
18
|
+
"resourceId": {
|
|
19
|
+
"kind": "youtube#video",
|
|
20
|
+
"videoId": config.videoId !== void 0 && config.videoId !== null && config.videoId !== "" ? String(config.videoId) : "dQw4w9WgXcQ"
|
|
21
|
+
},
|
|
22
|
+
"videoOwnerChannelTitle": "Example channel",
|
|
23
|
+
"videoOwnerChannelId": "UCexampleowner"
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
var youtubeFaker = (operation, request) => {
|
|
28
|
+
switch (operation) {
|
|
29
|
+
case "playlist_item_insert":
|
|
30
|
+
return fakePlaylistItemInsert(request);
|
|
31
|
+
default:
|
|
32
|
+
throw new Error(
|
|
33
|
+
`youtube: no fake response is defined for "${operation}". Add a fixture under provider/fixtures/ and regenerate \u2014 a connector without a faker cannot be developed against, tested, or demonstrated.`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// src/service.ts
|
|
39
|
+
var CONNECTOR_API_VERSION = 1;
|
|
40
|
+
var YOUTUBE_BASE_URLS = {
|
|
41
|
+
"live": "https://youtube.googleapis.com"
|
|
42
|
+
};
|
|
43
|
+
var YOUTUBE_REQUIRES = [
|
|
44
|
+
"accessToken",
|
|
45
|
+
"refreshToken",
|
|
46
|
+
"clientId",
|
|
47
|
+
"clientSecret"
|
|
48
|
+
];
|
|
49
|
+
function youtubeAuthorize(credentials, request, _mode) {
|
|
50
|
+
request.headers.Authorization = `Bearer ${credentials.accessToken ?? ""}`;
|
|
51
|
+
}
|
|
52
|
+
var YOUTUBE = {
|
|
53
|
+
service: "youtube",
|
|
54
|
+
title: "YouTube",
|
|
55
|
+
sandbox: "none",
|
|
56
|
+
baseUrls: { ...YOUTUBE_BASE_URLS },
|
|
57
|
+
requires: [...YOUTUBE_REQUIRES],
|
|
58
|
+
authorize: youtubeAuthorize,
|
|
59
|
+
faker: youtubeFaker
|
|
60
|
+
};
|
|
61
|
+
var PLAYLIST_ITEM_INSERT_OPERATION = "playlist_item_insert";
|
|
62
|
+
async function youtubePlaylistItemInsert(options) {
|
|
63
|
+
const config = options.config ?? {};
|
|
64
|
+
if (config.playlistId === void 0 || config.playlistId === null || config.playlistId === "") {
|
|
65
|
+
throw new Error(`playlist_item_insert: "playlistId" is required (Playlist ID).`);
|
|
66
|
+
}
|
|
67
|
+
if (config.videoId === void 0 || config.videoId === null || config.videoId === "") {
|
|
68
|
+
throw new Error(`playlist_item_insert: "videoId" is required (Video ID).`);
|
|
69
|
+
}
|
|
70
|
+
return fancyConnectorCore.callConnector(YOUTUBE, {
|
|
71
|
+
operation: PLAYLIST_ITEM_INSERT_OPERATION,
|
|
72
|
+
config,
|
|
73
|
+
input: options.input,
|
|
74
|
+
...options.credentials === void 0 ? {} : { credentials: options.credentials },
|
|
75
|
+
...options.mode === void 0 ? {} : { mode: options.mode },
|
|
76
|
+
...options.connectionId === void 0 ? {} : { connectionId: options.connectionId },
|
|
77
|
+
...options.attempts === void 0 ? {} : { attempts: options.attempts },
|
|
78
|
+
...options.transport === void 0 ? {} : { transport: options.transport },
|
|
79
|
+
request: {
|
|
80
|
+
method: "POST",
|
|
81
|
+
path: "/youtube/v3/playlistItems",
|
|
82
|
+
json: nestFields({
|
|
83
|
+
"snippet.playlistId": String(config.playlistId),
|
|
84
|
+
"snippet.resourceId.videoId": String(config.videoId),
|
|
85
|
+
"snippet.resourceId.kind": "youtube#video"
|
|
86
|
+
}),
|
|
87
|
+
query: {
|
|
88
|
+
"part": "snippet"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function nestFields(flat) {
|
|
94
|
+
const out = {};
|
|
95
|
+
for (const [path, value] of Object.entries(flat)) {
|
|
96
|
+
const parts = path.split(".");
|
|
97
|
+
let node = out;
|
|
98
|
+
while (parts.length > 1) {
|
|
99
|
+
const key = parts.shift();
|
|
100
|
+
const wantsArray = /^\d+$/.test(parts[0] ?? "");
|
|
101
|
+
if (typeof node[key] !== "object" || node[key] === null) node[key] = wantsArray ? [] : {};
|
|
102
|
+
node = node[key];
|
|
103
|
+
}
|
|
104
|
+
node[parts[0]] = value;
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
exports.CONNECTOR_API_VERSION = CONNECTOR_API_VERSION;
|
|
110
|
+
exports.PLAYLIST_ITEM_INSERT_OPERATION = PLAYLIST_ITEM_INSERT_OPERATION;
|
|
111
|
+
exports.YOUTUBE = YOUTUBE;
|
|
112
|
+
exports.YOUTUBE_BASE_URLS = YOUTUBE_BASE_URLS;
|
|
113
|
+
exports.YOUTUBE_REQUIRES = YOUTUBE_REQUIRES;
|
|
114
|
+
exports.youtubeAuthorize = youtubeAuthorize;
|
|
115
|
+
exports.youtubeFaker = youtubeFaker;
|
|
116
|
+
exports.youtubePlaylistItemInsert = youtubePlaylistItemInsert;
|
|
117
|
+
//# sourceMappingURL=index.cjs.map
|
|
118
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/faker.ts","../src/service.ts","../src/actions/playlist-item-insert.ts"],"names":["callConnector"],"mappings":";;;;;AAyBA,SAAS,sBAAA,CAAuB,EAAE,MAAA,EAAQ,IAAA,EAAK,EAAyB;AACtE,EAAA,OAAO;AAAA,IACL,MAAA,EAAQ,sBAAA;AAAA,IACR,MAAA,EAAQ,cAAA;AAAA,IACR,IAAA,EAAM,IAAA,CAAK,EAAA,CAAG,QAAQ,CAAA;AAAA,IACtB,SAAA,EAAW;AAAA,MACT,aAAA,EAAe,sBAAA;AAAA,MACf,WAAA,EAAa,kBAAA;AAAA,MACb,OAAA,EAAS,eAAA;AAAA,MACT,aAAA,EAAe,EAAA;AAAA,MACf,YAAA,EAAe,MAAA,CAAO,UAAA,KAAe,MAAA,IAAa,MAAA,CAAO,UAAA,KAAe,IAAA,IAAQ,MAAA,CAAO,UAAA,KAAe,EAAA,GAAK,MAAA,CAAO,MAAA,CAAO,UAAU,CAAA,GAAI,mBAAA;AAAA,MACvI,UAAA,EAAY,CAAA;AAAA,MACZ,YAAA,EAAc;AAAA,QACZ,MAAA,EAAQ,eAAA;AAAA,QACR,SAAA,EAAY,MAAA,CAAO,OAAA,KAAY,MAAA,IAAa,MAAA,CAAO,OAAA,KAAY,IAAA,IAAQ,MAAA,CAAO,OAAA,KAAY,EAAA,GAAK,MAAA,CAAO,MAAA,CAAO,OAAO,CAAA,GAAI;AAAA,OAC1H;AAAA,MACA,wBAAA,EAA0B,iBAAA;AAAA,MAC1B,qBAAA,EAAuB;AAAA;AACzB,GACF;AACF;AAEO,IAAM,YAAA,GAA+B,CAAC,SAAA,EAAW,OAAA,KAAY;AAClE,EAAA,QAAQ,SAAA;AA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AAM,KAAA,GAAQ,IAAA,CAAK,KAAA,CAAM,GAAG,CAAA;AAC5B,IAAA,IAAI,IAAA,GAAO,GAAA;AAEX,IAAA,OAAO,KAAA,CAAM,SAAS,CAAA,EAAG;AACvB,MAAA,MAAM,GAAA,GAAM,MAAM,KAAA,EAAM;AAMxB,MAAA,MAAM,aAAa,OAAA,CAAQ,IAAA,CAAK,KAAA,CAAM,CAAC,KAAK,EAAE,CAAA;AAE9C,MAAA,IAAI,OAAO,IAAA,CAAK,GAAG,CAAA,KAAM,YAAY,IAAA,CAAK,GAAG,CAAA,KAAM,IAAA,OAAW,GAAG,CAAA,GAAI,UAAA,GAAa,KAAK,EAAC;AACxF,MAAA,IAAA,GAAO,KAAK,GAAG,CAAA;AAAA,IACjB;AAEA,IAAA,IAAA,CAAK,KAAA,CAAM,CAAC,CAAW,CAAA,GAAI,KAAA;AAAA,EAC7B;AAEA,EAAA,OAAO,GAAA;AACT","file":"index.cjs","sourcesContent":["/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/fixtures/ by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/fixtures/ (or weaver's template/) and regenerate:\n *\n * npm run provider -- youtube\n */\n\n/**\n * The YouTube faker.\n *\n * Shapes, not behaviour: the goal is that a downstream node sees the field\n * NAMES YouTube actually publishes, so an author can wire {{ $json.data.id }}\n * against a fake and have it keep working against the real thing.\n *\n * Deterministic — same inputs, same output. A faker returning a fresh uuid\n * every call cannot be asserted on, so its fixtures degrade to \"it did not\n * throw\", which is the assertion that catches nothing.\n */\n\nimport type { ConnectorFaker, FakeRequest } from \"@particle-academy/fancy-connector-core\";\n\nfunction fakePlaylistItemInsert({ config, fake }: FakeRequest): unknown {\n return {\n \"kind\": \"youtube#playlistItem\",\n \"etag\": \"example-etag\",\n \"id\": fake.id(\"PLItem\"),\n \"snippet\": {\n \"publishedAt\": \"2026-01-01T00:00:00Z\",\n \"channelId\": \"UCexamplechannel\",\n \"title\": \"Example video\",\n \"description\": \"\",\n \"playlistId\": (config.playlistId !== undefined && config.playlistId !== null && config.playlistId !== \"\" ? String(config.playlistId) : \"PLexampleplaylist\"),\n \"position\": 0,\n \"resourceId\": {\n \"kind\": \"youtube#video\",\n \"videoId\": (config.videoId !== undefined && config.videoId !== null && config.videoId !== \"\" ? String(config.videoId) : \"dQw4w9WgXcQ\"),\n },\n \"videoOwnerChannelTitle\": \"Example channel\",\n \"videoOwnerChannelId\": \"UCexampleowner\",\n },\n };\n}\n\nexport const youtubeFaker: ConnectorFaker = (operation, request) => {\n switch (operation) {\n case \"playlist_item_insert\":\n return fakePlaylistItemInsert(request);\n\n default:\n // A faker asked for an operation it has no shape for must SAY so. Making\n // something up would produce a green run whose output silently has none\n // of the fields the author is about to reference.\n throw new Error(\n `youtube: no fake response is defined for \"${operation}\". ` +\n \"Add a fixture under provider/fixtures/ and regenerate — a connector without a faker \" +\n \"cannot be developed against, tested, or demonstrated.\",\n );\n }\n};\n","/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/manifest.json by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/manifest.json (or weaver's template/) and regenerate:\n *\n * npm run provider -- youtube\n */\n\n/**\n * YouTube, as one service descriptor shared by every YouTube operation.\n *\n * @particle-academy/fancy-connector-core carries what is true of ALL\n * connectors. This carries what is true of YouTube: its base URL, its auth\n * scheme, its idempotency header, and its faker.\n *\n * ## The sandbox trap, written down where it is used\n *\n * YouTube has no sandbox. Every live-mode add changes a real playlist; use the\n * faker during development and remove live test items afterward.\n */\n\nimport type { ConnectorMode, PreparedRequest, ServiceDescriptor } from \"@particle-academy/fancy-connector-core\";\n\nimport { youtubeFaker } from \"./faker.js\";\n\n/**\n * The connector API version this package was GENERATED against.\n *\n * A literal, never imported. An imported constant lets an upgrade rewrite the\n * very claim it exists to detect, after which the copy agrees with itself\n * forever.\n */\nexport const CONNECTOR_API_VERSION = 1;\n\nexport const YOUTUBE_BASE_URLS = {\n \"live\": \"https://youtube.googleapis.com\"\n} as const;\n\n/** Credential keys a remote call cannot proceed without. */\nexport const YOUTUBE_REQUIRES = [\n \"accessToken\",\n \"refreshToken\",\n \"clientId\",\n \"clientSecret\"\n] as const;\n\n/**\n * Apply YouTube's auth scheme to an outgoing request.\n *\n *\n *\n * The mode is passed in because for some providers auth and estate are the\n * same decision expressed in the URL; here it is unused, and saying so is\n * cheaper than wondering later whether it was forgotten.\n */\nexport function youtubeAuthorize(\n credentials: Record<string, string | undefined>,\n request: PreparedRequest,\n _mode: ConnectorMode,\n): void {\n request.headers.Authorization = `Bearer ${credentials.accessToken ?? \"\"}`;\n}\n\n/** The YouTube service, for the TypeScript runtime. */\nexport const YOUTUBE: ServiceDescriptor = {\n service: \"youtube\",\n title: \"YouTube\",\n sandbox: \"none\",\n baseUrls: { ...YOUTUBE_BASE_URLS },\n requires: [...YOUTUBE_REQUIRES],\n authorize: youtubeAuthorize,\n faker: youtubeFaker,\n};\n","/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/actions/playlist-item-insert.json by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/actions/playlist-item-insert.json (or weaver's template/) and regenerate:\n *\n * npm run provider -- youtube\n */\n\n/**\n * Add a video to a YouTube playlist.\n *\n * POST /youtube/v3/playlistItems —\n * https://developers.google.com/youtube/v3/docs/playlistItems/insert\n *\n * Notice what is NOT here: no key, no base URL, no mode check, no retry loop,\n * no fake/real branch. This describes the request; callConnector resolves the\n * connection, picks the estate, and either calls YouTube or calls the faker.\n *\n * sideEffects: unsafe-to-replay.\n */\n\nimport {\n callConnector,\n type ConnectorResult,\n type RequestedMode,\n type Transport,\n} from \"@particle-academy/fancy-connector-core\";\nimport { YOUTUBE } from \"../service.js\";\n\nexport const PLAYLIST_ITEM_INSERT_OPERATION = \"playlist_item_insert\";\n\nexport type PlaylistItemInsertOptions = {\n /** The node's resolved config. Keys: playlistId, videoId. */\n config: Record<string, unknown>;\n credentials?: Record<string, string | undefined>;\n mode?: RequestedMode;\n connectionId?: string | null;\n input?: unknown;\n attempts?: number;\n /** Override the transport. The only way to exercise this without a network. */\n transport?: Transport;\n};\n\nexport async function youtubePlaylistItemInsert(options: PlaylistItemInsertOptions): Promise<ConnectorResult> {\n const config = options.config ?? {};\n\n if (config.playlistId === undefined || config.playlistId === null || config.playlistId === \"\") {\n throw new Error(`playlist_item_insert: \"playlistId\" is required (Playlist ID).`);\n }\n\n if (config.videoId === undefined || config.videoId === null || config.videoId === \"\") {\n throw new Error(`playlist_item_insert: \"videoId\" is required (Video ID).`);\n }\n\n return callConnector(YOUTUBE, {\n operation: PLAYLIST_ITEM_INSERT_OPERATION,\n config,\n input: options.input,\n ...(options.credentials === undefined ? {} : { credentials: options.credentials }),\n ...(options.mode === undefined ? {} : { mode: options.mode }),\n ...(options.connectionId === undefined ? {} : { connectionId: options.connectionId }),\n ...(options.attempts === undefined ? {} : { attempts: options.attempts }),\n ...(options.transport === undefined ? {} : { transport: options.transport }),\n request: {\n method: \"POST\",\n path: \"/youtube/v3/playlistItems\",\n json: nestFields({\n \"snippet.playlistId\": String(config.playlistId),\n \"snippet.resourceId.videoId\": String(config.videoId),\n \"snippet.resourceId.kind\": \"youtube#video\",\n }),\n query: {\n \"part\": \"snippet\",\n },\n },\n });\n}\n\n/**\n * `{\"properties.email\": x}` -> `{properties: {email: x}}`.\n *\n * A dotted `as` means NESTING, and only a JSON body can nest. The validator\n * refuses that spelling anywhere else, because in a form body it already means\n * something different — a literal dotted key.\n */\nfunction nestFields(flat: Record<string, unknown>): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n\n for (const [path, value] of Object.entries(flat)) {\n const parts = path.split(\".\");\n let node = out;\n\n while (parts.length > 1) {\n const key = parts.shift() as string;\n // A NUMERIC segment is an array index: `dateRanges.0.startDate` has to\n // become `[{startDate}]`, not `{\"0\": {startDate}}`. PHP produced the\n // array by accident (its integer-keyed arrays serialise as JSON lists)\n // and the other two produced an object, which the provider rejects as\n // the wrong type. The parity suite is what caught the disagreement.\n const wantsArray = /^\\d+$/.test(parts[0] ?? \"\");\n\n if (typeof node[key] !== \"object\" || node[key] === null) node[key] = wantsArray ? [] : {};\n node = node[key] as Record<string, unknown>;\n }\n\n node[parts[0] as string] = value;\n }\n\n return out;\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { ServiceDescriptor, PreparedRequest, ConnectorMode, ConnectorFaker, RequestedMode, Transport, ConnectorResult } from '@particle-academy/fancy-connector-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GENERATED FILE — do not edit.
|
|
5
|
+
*
|
|
6
|
+
* Emitted from provider/manifest.json by weaver's generator.
|
|
7
|
+
* A hand-edit here is destroyed by the next protocol sync, which is worse than
|
|
8
|
+
* being rejected, because it works until it silently does not. Fix
|
|
9
|
+
* provider/manifest.json (or weaver's template/) and regenerate:
|
|
10
|
+
*
|
|
11
|
+
* npm run provider -- youtube
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* YouTube, as one service descriptor shared by every YouTube operation.
|
|
15
|
+
*
|
|
16
|
+
* @particle-academy/fancy-connector-core carries what is true of ALL
|
|
17
|
+
* connectors. This carries what is true of YouTube: its base URL, its auth
|
|
18
|
+
* scheme, its idempotency header, and its faker.
|
|
19
|
+
*
|
|
20
|
+
* ## The sandbox trap, written down where it is used
|
|
21
|
+
*
|
|
22
|
+
* YouTube has no sandbox. Every live-mode add changes a real playlist; use the
|
|
23
|
+
* faker during development and remove live test items afterward.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The connector API version this package was GENERATED against.
|
|
28
|
+
*
|
|
29
|
+
* A literal, never imported. An imported constant lets an upgrade rewrite the
|
|
30
|
+
* very claim it exists to detect, after which the copy agrees with itself
|
|
31
|
+
* forever.
|
|
32
|
+
*/
|
|
33
|
+
declare const CONNECTOR_API_VERSION = 1;
|
|
34
|
+
declare const YOUTUBE_BASE_URLS: {
|
|
35
|
+
readonly live: "https://youtube.googleapis.com";
|
|
36
|
+
};
|
|
37
|
+
/** Credential keys a remote call cannot proceed without. */
|
|
38
|
+
declare const YOUTUBE_REQUIRES: readonly ["accessToken", "refreshToken", "clientId", "clientSecret"];
|
|
39
|
+
/**
|
|
40
|
+
* Apply YouTube's auth scheme to an outgoing request.
|
|
41
|
+
*
|
|
42
|
+
*
|
|
43
|
+
*
|
|
44
|
+
* The mode is passed in because for some providers auth and estate are the
|
|
45
|
+
* same decision expressed in the URL; here it is unused, and saying so is
|
|
46
|
+
* cheaper than wondering later whether it was forgotten.
|
|
47
|
+
*/
|
|
48
|
+
declare function youtubeAuthorize(credentials: Record<string, string | undefined>, request: PreparedRequest, _mode: ConnectorMode): void;
|
|
49
|
+
/** The YouTube service, for the TypeScript runtime. */
|
|
50
|
+
declare const YOUTUBE: ServiceDescriptor;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* GENERATED FILE — do not edit.
|
|
54
|
+
*
|
|
55
|
+
* Emitted from provider/fixtures/ by weaver's generator.
|
|
56
|
+
* A hand-edit here is destroyed by the next protocol sync, which is worse than
|
|
57
|
+
* being rejected, because it works until it silently does not. Fix
|
|
58
|
+
* provider/fixtures/ (or weaver's template/) and regenerate:
|
|
59
|
+
*
|
|
60
|
+
* npm run provider -- youtube
|
|
61
|
+
*/
|
|
62
|
+
/**
|
|
63
|
+
* The YouTube faker.
|
|
64
|
+
*
|
|
65
|
+
* Shapes, not behaviour: the goal is that a downstream node sees the field
|
|
66
|
+
* NAMES YouTube actually publishes, so an author can wire {{ $json.data.id }}
|
|
67
|
+
* against a fake and have it keep working against the real thing.
|
|
68
|
+
*
|
|
69
|
+
* Deterministic — same inputs, same output. A faker returning a fresh uuid
|
|
70
|
+
* every call cannot be asserted on, so its fixtures degrade to "it did not
|
|
71
|
+
* throw", which is the assertion that catches nothing.
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
declare const youtubeFaker: ConnectorFaker;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* GENERATED FILE — do not edit.
|
|
78
|
+
*
|
|
79
|
+
* Emitted from provider/actions/playlist-item-insert.json by weaver's generator.
|
|
80
|
+
* A hand-edit here is destroyed by the next protocol sync, which is worse than
|
|
81
|
+
* being rejected, because it works until it silently does not. Fix
|
|
82
|
+
* provider/actions/playlist-item-insert.json (or weaver's template/) and regenerate:
|
|
83
|
+
*
|
|
84
|
+
* npm run provider -- youtube
|
|
85
|
+
*/
|
|
86
|
+
/**
|
|
87
|
+
* Add a video to a YouTube playlist.
|
|
88
|
+
*
|
|
89
|
+
* POST /youtube/v3/playlistItems —
|
|
90
|
+
* https://developers.google.com/youtube/v3/docs/playlistItems/insert
|
|
91
|
+
*
|
|
92
|
+
* Notice what is NOT here: no key, no base URL, no mode check, no retry loop,
|
|
93
|
+
* no fake/real branch. This describes the request; callConnector resolves the
|
|
94
|
+
* connection, picks the estate, and either calls YouTube or calls the faker.
|
|
95
|
+
*
|
|
96
|
+
* sideEffects: unsafe-to-replay.
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
declare const PLAYLIST_ITEM_INSERT_OPERATION = "playlist_item_insert";
|
|
100
|
+
type PlaylistItemInsertOptions = {
|
|
101
|
+
/** The node's resolved config. Keys: playlistId, videoId. */
|
|
102
|
+
config: Record<string, unknown>;
|
|
103
|
+
credentials?: Record<string, string | undefined>;
|
|
104
|
+
mode?: RequestedMode;
|
|
105
|
+
connectionId?: string | null;
|
|
106
|
+
input?: unknown;
|
|
107
|
+
attempts?: number;
|
|
108
|
+
/** Override the transport. The only way to exercise this without a network. */
|
|
109
|
+
transport?: Transport;
|
|
110
|
+
};
|
|
111
|
+
declare function youtubePlaylistItemInsert(options: PlaylistItemInsertOptions): Promise<ConnectorResult>;
|
|
112
|
+
|
|
113
|
+
export { CONNECTOR_API_VERSION, PLAYLIST_ITEM_INSERT_OPERATION, type PlaylistItemInsertOptions, YOUTUBE, YOUTUBE_BASE_URLS, YOUTUBE_REQUIRES, youtubeAuthorize, youtubeFaker, youtubePlaylistItemInsert };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { ServiceDescriptor, PreparedRequest, ConnectorMode, ConnectorFaker, RequestedMode, Transport, ConnectorResult } from '@particle-academy/fancy-connector-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GENERATED FILE — do not edit.
|
|
5
|
+
*
|
|
6
|
+
* Emitted from provider/manifest.json by weaver's generator.
|
|
7
|
+
* A hand-edit here is destroyed by the next protocol sync, which is worse than
|
|
8
|
+
* being rejected, because it works until it silently does not. Fix
|
|
9
|
+
* provider/manifest.json (or weaver's template/) and regenerate:
|
|
10
|
+
*
|
|
11
|
+
* npm run provider -- youtube
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* YouTube, as one service descriptor shared by every YouTube operation.
|
|
15
|
+
*
|
|
16
|
+
* @particle-academy/fancy-connector-core carries what is true of ALL
|
|
17
|
+
* connectors. This carries what is true of YouTube: its base URL, its auth
|
|
18
|
+
* scheme, its idempotency header, and its faker.
|
|
19
|
+
*
|
|
20
|
+
* ## The sandbox trap, written down where it is used
|
|
21
|
+
*
|
|
22
|
+
* YouTube has no sandbox. Every live-mode add changes a real playlist; use the
|
|
23
|
+
* faker during development and remove live test items afterward.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The connector API version this package was GENERATED against.
|
|
28
|
+
*
|
|
29
|
+
* A literal, never imported. An imported constant lets an upgrade rewrite the
|
|
30
|
+
* very claim it exists to detect, after which the copy agrees with itself
|
|
31
|
+
* forever.
|
|
32
|
+
*/
|
|
33
|
+
declare const CONNECTOR_API_VERSION = 1;
|
|
34
|
+
declare const YOUTUBE_BASE_URLS: {
|
|
35
|
+
readonly live: "https://youtube.googleapis.com";
|
|
36
|
+
};
|
|
37
|
+
/** Credential keys a remote call cannot proceed without. */
|
|
38
|
+
declare const YOUTUBE_REQUIRES: readonly ["accessToken", "refreshToken", "clientId", "clientSecret"];
|
|
39
|
+
/**
|
|
40
|
+
* Apply YouTube's auth scheme to an outgoing request.
|
|
41
|
+
*
|
|
42
|
+
*
|
|
43
|
+
*
|
|
44
|
+
* The mode is passed in because for some providers auth and estate are the
|
|
45
|
+
* same decision expressed in the URL; here it is unused, and saying so is
|
|
46
|
+
* cheaper than wondering later whether it was forgotten.
|
|
47
|
+
*/
|
|
48
|
+
declare function youtubeAuthorize(credentials: Record<string, string | undefined>, request: PreparedRequest, _mode: ConnectorMode): void;
|
|
49
|
+
/** The YouTube service, for the TypeScript runtime. */
|
|
50
|
+
declare const YOUTUBE: ServiceDescriptor;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* GENERATED FILE — do not edit.
|
|
54
|
+
*
|
|
55
|
+
* Emitted from provider/fixtures/ by weaver's generator.
|
|
56
|
+
* A hand-edit here is destroyed by the next protocol sync, which is worse than
|
|
57
|
+
* being rejected, because it works until it silently does not. Fix
|
|
58
|
+
* provider/fixtures/ (or weaver's template/) and regenerate:
|
|
59
|
+
*
|
|
60
|
+
* npm run provider -- youtube
|
|
61
|
+
*/
|
|
62
|
+
/**
|
|
63
|
+
* The YouTube faker.
|
|
64
|
+
*
|
|
65
|
+
* Shapes, not behaviour: the goal is that a downstream node sees the field
|
|
66
|
+
* NAMES YouTube actually publishes, so an author can wire {{ $json.data.id }}
|
|
67
|
+
* against a fake and have it keep working against the real thing.
|
|
68
|
+
*
|
|
69
|
+
* Deterministic — same inputs, same output. A faker returning a fresh uuid
|
|
70
|
+
* every call cannot be asserted on, so its fixtures degrade to "it did not
|
|
71
|
+
* throw", which is the assertion that catches nothing.
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
declare const youtubeFaker: ConnectorFaker;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* GENERATED FILE — do not edit.
|
|
78
|
+
*
|
|
79
|
+
* Emitted from provider/actions/playlist-item-insert.json by weaver's generator.
|
|
80
|
+
* A hand-edit here is destroyed by the next protocol sync, which is worse than
|
|
81
|
+
* being rejected, because it works until it silently does not. Fix
|
|
82
|
+
* provider/actions/playlist-item-insert.json (or weaver's template/) and regenerate:
|
|
83
|
+
*
|
|
84
|
+
* npm run provider -- youtube
|
|
85
|
+
*/
|
|
86
|
+
/**
|
|
87
|
+
* Add a video to a YouTube playlist.
|
|
88
|
+
*
|
|
89
|
+
* POST /youtube/v3/playlistItems —
|
|
90
|
+
* https://developers.google.com/youtube/v3/docs/playlistItems/insert
|
|
91
|
+
*
|
|
92
|
+
* Notice what is NOT here: no key, no base URL, no mode check, no retry loop,
|
|
93
|
+
* no fake/real branch. This describes the request; callConnector resolves the
|
|
94
|
+
* connection, picks the estate, and either calls YouTube or calls the faker.
|
|
95
|
+
*
|
|
96
|
+
* sideEffects: unsafe-to-replay.
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
declare const PLAYLIST_ITEM_INSERT_OPERATION = "playlist_item_insert";
|
|
100
|
+
type PlaylistItemInsertOptions = {
|
|
101
|
+
/** The node's resolved config. Keys: playlistId, videoId. */
|
|
102
|
+
config: Record<string, unknown>;
|
|
103
|
+
credentials?: Record<string, string | undefined>;
|
|
104
|
+
mode?: RequestedMode;
|
|
105
|
+
connectionId?: string | null;
|
|
106
|
+
input?: unknown;
|
|
107
|
+
attempts?: number;
|
|
108
|
+
/** Override the transport. The only way to exercise this without a network. */
|
|
109
|
+
transport?: Transport;
|
|
110
|
+
};
|
|
111
|
+
declare function youtubePlaylistItemInsert(options: PlaylistItemInsertOptions): Promise<ConnectorResult>;
|
|
112
|
+
|
|
113
|
+
export { CONNECTOR_API_VERSION, PLAYLIST_ITEM_INSERT_OPERATION, type PlaylistItemInsertOptions, YOUTUBE, YOUTUBE_BASE_URLS, YOUTUBE_REQUIRES, youtubeAuthorize, youtubeFaker, youtubePlaylistItemInsert };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
package/package.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@particle-academy/youtube-js",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "YouTube for Node — the service descriptor, its faker, its webhook verification, and one function per operation. Plain HTTP on @particle-academy/fancy-connector-core; no vendor SDK.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/Fancy-Friends/youtube.git"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/Fancy-Friends/youtube#readme",
|
|
10
|
+
"bugs": "https://github.com/Fancy-Friends/youtube/issues",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"require": {
|
|
22
|
+
"types": "./dist/index.d.cts",
|
|
23
|
+
"default": "./dist/index.cjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"./flow": {
|
|
27
|
+
"import": {
|
|
28
|
+
"types": "./dist/flow.d.ts",
|
|
29
|
+
"default": "./dist/flow.js"
|
|
30
|
+
},
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./dist/flow.d.cts",
|
|
33
|
+
"default": "./dist/flow.cjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"README.md",
|
|
41
|
+
"CHANGELOG.md",
|
|
42
|
+
"LICENSE"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup",
|
|
46
|
+
"lint": "tsc --noEmit",
|
|
47
|
+
"test": "node --import tsx --test tests/*.test.ts",
|
|
48
|
+
"prepublishOnly": "tsup"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@particle-academy/fancy-connector-core": ">=0.3.1 <2.0"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@particle-academy/fancy-flow": ">=0.47.1 <2.0",
|
|
55
|
+
"@particle-academy/youtube-ui": "0.1.0"
|
|
56
|
+
},
|
|
57
|
+
"peerDependenciesMeta": {
|
|
58
|
+
"@particle-academy/fancy-flow": {
|
|
59
|
+
"optional": true
|
|
60
|
+
},
|
|
61
|
+
"@particle-academy/youtube-ui": {
|
|
62
|
+
"optional": true
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@particle-academy/fancy-flow": ">=0.47.1 <2.0",
|
|
67
|
+
"@types/node": "^26.2.0",
|
|
68
|
+
"tsup": "^8.5.0",
|
|
69
|
+
"tsx": "^4.19.0",
|
|
70
|
+
"typescript": "^5.8.0"
|
|
71
|
+
},
|
|
72
|
+
"publishConfig": {
|
|
73
|
+
"access": "public"
|
|
74
|
+
},
|
|
75
|
+
"keywords": [
|
|
76
|
+
"youtube",
|
|
77
|
+
"marketing",
|
|
78
|
+
"connector",
|
|
79
|
+
"api",
|
|
80
|
+
"fancy-ui",
|
|
81
|
+
"particle-academy"
|
|
82
|
+
],
|
|
83
|
+
"license": "MIT",
|
|
84
|
+
"sideEffects": false,
|
|
85
|
+
"engines": {
|
|
86
|
+
"node": ">=22"
|
|
87
|
+
}
|
|
88
|
+
}
|