@verevoir/aigency-work 0.2.0 → 0.3.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 +126 -0
- package/dist/asf-board.js +112 -39
- package/dist/backlog-board.d.ts +21 -0
- package/dist/backlog-board.js +383 -0
- package/dist/card.d.ts +61 -17
- package/dist/card.js +38 -8
- package/dist/in-memory-board.d.ts +13 -1
- package/dist/in-memory-board.js +17 -2
- package/dist/index.d.ts +11 -3
- package/dist/index.js +5 -1
- package/dist/notion-board.d.ts +33 -0
- package/dist/notion-board.js +515 -4
- package/dist/status.d.ts +24 -0
- package/dist/status.js +36 -0
- package/dist/trello-board.d.ts +41 -0
- package/dist/trello-board.js +337 -0
- package/package.json +1 -1
package/dist/status.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// The normalized status vocabulary, and the helpers that map between it and
|
|
2
|
+
// a board's native states. A board derives `Card.status` from its native
|
|
3
|
+
// `Card.state` through a `StatusMap` it owns; the native state is never
|
|
4
|
+
// altered, so round trips are unaffected. The in-memory board does this
|
|
5
|
+
// when given a map. Other boards adopt it in their own changes.
|
|
6
|
+
export const STATUSES = [
|
|
7
|
+
'backlog',
|
|
8
|
+
'ready',
|
|
9
|
+
'in-progress',
|
|
10
|
+
'in-review',
|
|
11
|
+
'blocked',
|
|
12
|
+
'done',
|
|
13
|
+
'retracted',
|
|
14
|
+
];
|
|
15
|
+
export function isStatus(value) {
|
|
16
|
+
return typeof value === 'string' && STATUSES.includes(value);
|
|
17
|
+
}
|
|
18
|
+
/** Case-sensitive on the native name. Never throws, never guesses. */
|
|
19
|
+
export function normalizeStatus(nativeState, map) {
|
|
20
|
+
if (Object.prototype.hasOwnProperty.call(map.toStatus, nativeState)) {
|
|
21
|
+
const status = map.toStatus[nativeState];
|
|
22
|
+
if (status !== undefined) {
|
|
23
|
+
return { kind: 'mapped', status };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return { kind: 'unmapped', nativeState };
|
|
27
|
+
}
|
|
28
|
+
export function nativeStateFor(status, map) {
|
|
29
|
+
if (Object.prototype.hasOwnProperty.call(map.fromStatus, status)) {
|
|
30
|
+
const state = map.fromStatus[status];
|
|
31
|
+
if (state !== undefined) {
|
|
32
|
+
return { kind: 'mapped', state };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return { kind: 'unmapped', status };
|
|
36
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { CardSource, CardSink } from './board.js';
|
|
2
|
+
import type { StatusMap } from './status.js';
|
|
3
|
+
/** The reason given for any write that supplies `expectedRevision`. */
|
|
4
|
+
export declare const TRELLO_EXPECTED_REVISION_UNSUPPORTED_REASON = "expectedRevision is not supported by TrelloBoard: Trello has no compare-and-set primitive";
|
|
5
|
+
/** The reason `createCard` is refused: Trello mints card ids itself. */
|
|
6
|
+
export declare const TRELLO_CREATE_CARD_REFUSED_REASON = "TrelloBoard cannot create a card: Trello mints its own card ids and cannot honour a caller-supplied one, so get(card.id) could never return it";
|
|
7
|
+
/** The reason `annotate` is refused: a Trello card has no property bag. */
|
|
8
|
+
export declare const TRELLO_ANNOTATE_REFUSED_REASON = "TrelloBoard cannot annotate: a Trello card has no property bag, and custom fields are not supported";
|
|
9
|
+
/** Just enough of `fetch` to avoid depending on DOM lib types. */
|
|
10
|
+
export interface TrelloFetchResponse {
|
|
11
|
+
readonly status: number;
|
|
12
|
+
readonly ok: boolean;
|
|
13
|
+
json(): Promise<unknown>;
|
|
14
|
+
}
|
|
15
|
+
export interface TrelloFetchInit {
|
|
16
|
+
readonly method: 'GET' | 'PUT';
|
|
17
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
18
|
+
readonly body?: string;
|
|
19
|
+
}
|
|
20
|
+
export type TrelloFetch = (url: string, init: TrelloFetchInit) => Promise<TrelloFetchResponse>;
|
|
21
|
+
export interface TrelloBoardConfig {
|
|
22
|
+
/** The Trello board id (or short link) this board is scoped to. */
|
|
23
|
+
readonly boardId: string;
|
|
24
|
+
/** Resolves the key and token on every call. Never read from the environment, never logged. */
|
|
25
|
+
readonly getAuth: () => Promise<{
|
|
26
|
+
readonly apiKey: string;
|
|
27
|
+
readonly apiToken: string;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Sent as the `Referer` header on every request. Trello Power-Up keys are
|
|
31
|
+
* origin-scoped: a server-side caller must send a value matching the
|
|
32
|
+
* Power-Up's origin or every call is a 401.
|
|
33
|
+
*/
|
|
34
|
+
readonly referer?: string;
|
|
35
|
+
/** Maps list names to normalized statuses. With no map there is no `Card.status`. */
|
|
36
|
+
readonly statusMap?: StatusMap;
|
|
37
|
+
/** Injected for tests; defaults to the platform's global `fetch`. */
|
|
38
|
+
readonly fetch?: TrelloFetch;
|
|
39
|
+
}
|
|
40
|
+
export type TrelloBoard = CardSource & CardSink;
|
|
41
|
+
export declare function createTrelloBoard(config: TrelloBoardConfig): TrelloBoard;
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
// A `CardSource`/`CardSink` over one Trello board, talking to Trello's REST
|
|
2
|
+
// API v1 with raw `fetch` -- no SDK, no new dependency. Ported from the
|
|
3
|
+
// Trello layer in @verevoir/workflows (`src/trello/index.ts`); the call
|
|
4
|
+
// shapes (GET /boards/{id}/lists, GET /boards/{id}/cards, GET/PUT
|
|
5
|
+
// /cards/{id}) are carried over, the contract is this repository's.
|
|
6
|
+
//
|
|
7
|
+
// CREDENTIALS. `fetch`, `getAuth` and `referer` are all injected (see
|
|
8
|
+
// `TrelloBoardConfig`). Credentials come only through `getAuth`, are asked
|
|
9
|
+
// for on every call, and are never read from the environment. Trello takes
|
|
10
|
+
// the key and token as QUERY PARAMETERS, so the request URL is itself a
|
|
11
|
+
// secret: no outcome, reason or problem message ever contains a URL, and
|
|
12
|
+
// the message of a thrown error (which a runtime may build from the URL) is
|
|
13
|
+
// never copied into one. Reasons are fixed text plus an HTTP status.
|
|
14
|
+
//
|
|
15
|
+
// MODEL. A Trello list is the card's `state` (its name; lists carry no other
|
|
16
|
+
// identity a caller could be expected to know). `statusMap`, when given, maps
|
|
17
|
+
// list names to a normalized `Card.status` exactly as the other boards do;
|
|
18
|
+
// `writeState` also accepts a normalized status and resolves it back to a
|
|
19
|
+
// list name through `fromStatus`. A card whose list is not on the board's
|
|
20
|
+
// list set is `unparseable`, not given a made-up state.
|
|
21
|
+
//
|
|
22
|
+
// OUTCOMES. Nothing is thrown. A fetch failure, a thrown fetch, a 5xx/429 or
|
|
23
|
+
// a credentials failure is `unreachable`. A 404 (or Trello's 400 for a
|
|
24
|
+
// malformed id) on a read is `absent`. A reply that is not the expected
|
|
25
|
+
// JSON shape is `unparseable` on `get` and a per-card record on `list`
|
|
26
|
+
// (`ListResult` has no whole-listing `unparseable`, so a malformed card
|
|
27
|
+
// ARRAY, which no single card can be blamed for, is `unreachable`, naming
|
|
28
|
+
// that the reply was malformed). On a write a 404/400/401/403 is `refused`.
|
|
29
|
+
//
|
|
30
|
+
// CHOICES where the backlog item (AW-6) is silent or Trello differs:
|
|
31
|
+
// - `requires` and `parent` are UNSUPPORTED. Trello is flat (workflows'
|
|
32
|
+
// layer throws 501 for `parentId`). Reads never set `Card.requires` or
|
|
33
|
+
// `Card.parent`; every card says so in `unknownFields.unsupported`.
|
|
34
|
+
// - `createCard` is `refused`. Trello mints its own card ids and its API
|
|
35
|
+
// cannot accept a caller-supplied one, so an `applied` create could not
|
|
36
|
+
// keep the `CardSink.createCard` promise that `get(card.id)` then
|
|
37
|
+
// returns the card. The refusal is made before any request is sent.
|
|
38
|
+
// - `annotate` is `refused`: a Trello card has no property bag, and custom
|
|
39
|
+
// fields (a separate Power-Up endpoint, which workflows also stubs as
|
|
40
|
+
// `[]`) are not ported. Writing into the description would corrupt it.
|
|
41
|
+
// - `expectedRevision` is `unsupported`: Trello has no compare-and-set.
|
|
42
|
+
// - Not ported: comments, custom fields, `isCardFresh`.
|
|
43
|
+
// - Unmapped Trello fields (members, labels, due, short id, last activity)
|
|
44
|
+
// are carried in `unknownFields`, not dropped.
|
|
45
|
+
import { normalizeStatus, nativeStateFor, isStatus } from './status.js';
|
|
46
|
+
const TRELLO_API = 'https://api.trello.com/1';
|
|
47
|
+
const CARD_FIELDS = 'idShort,name,desc,idList,idMembers,labels,due,url,dateLastActivity';
|
|
48
|
+
/** The reason given for any write that supplies `expectedRevision`. */
|
|
49
|
+
export const TRELLO_EXPECTED_REVISION_UNSUPPORTED_REASON = 'expectedRevision is not supported by TrelloBoard: Trello has no compare-and-set primitive';
|
|
50
|
+
/** The reason `createCard` is refused: Trello mints card ids itself. */
|
|
51
|
+
export const TRELLO_CREATE_CARD_REFUSED_REASON = 'TrelloBoard cannot create a card: Trello mints its own card ids and cannot honour a caller-supplied one, so get(card.id) could never return it';
|
|
52
|
+
/** The reason `annotate` is refused: a Trello card has no property bag. */
|
|
53
|
+
export const TRELLO_ANNOTATE_REFUSED_REASON = 'TrelloBoard cannot annotate: a Trello card has no property bag, and custom fields are not supported';
|
|
54
|
+
// Calling the global through a local wrapper keeps `this` correct for any
|
|
55
|
+
// platform `fetch`, which throws "Illegal invocation" if detached.
|
|
56
|
+
const defaultFetch = (url, init) => globalThis.fetch(url, init);
|
|
57
|
+
function isRecord(value) {
|
|
58
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
59
|
+
}
|
|
60
|
+
function httpReason(status) {
|
|
61
|
+
return `Trello answered HTTP ${status}`;
|
|
62
|
+
}
|
|
63
|
+
export function createTrelloBoard(config) {
|
|
64
|
+
const doFetch = config.fetch ?? defaultFetch;
|
|
65
|
+
const source = `trello:${config.boardId}`;
|
|
66
|
+
async function call(method, path, options) {
|
|
67
|
+
let apiKey;
|
|
68
|
+
let apiToken;
|
|
69
|
+
try {
|
|
70
|
+
const auth = await config.getAuth();
|
|
71
|
+
apiKey = auth.apiKey;
|
|
72
|
+
apiToken = auth.apiToken;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// The thrown message is deliberately not copied: it is caller code's text.
|
|
76
|
+
return { kind: 'down', reason: 'Trello credentials could not be obtained (getAuth failed)' };
|
|
77
|
+
}
|
|
78
|
+
if (typeof apiKey !== 'string' ||
|
|
79
|
+
apiKey === '' ||
|
|
80
|
+
typeof apiToken !== 'string' ||
|
|
81
|
+
apiToken === '') {
|
|
82
|
+
return { kind: 'down', reason: 'Trello credentials were missing or empty' };
|
|
83
|
+
}
|
|
84
|
+
// Built by hand: this project's lib has no `URLSearchParams`. Key and token last.
|
|
85
|
+
const queryString = Object.entries({ ...options.query, key: apiKey, token: apiToken })
|
|
86
|
+
.map(([name, value]) => `${encodeURIComponent(name)}=${encodeURIComponent(value)}`)
|
|
87
|
+
.join('&');
|
|
88
|
+
const headers = {};
|
|
89
|
+
if (options.body !== undefined)
|
|
90
|
+
headers['Content-Type'] = 'application/json';
|
|
91
|
+
if (config.referer !== undefined && config.referer !== '')
|
|
92
|
+
headers['Referer'] = config.referer;
|
|
93
|
+
let response;
|
|
94
|
+
try {
|
|
95
|
+
response = await doFetch(`${TRELLO_API}${path}?${queryString}`, {
|
|
96
|
+
method,
|
|
97
|
+
headers,
|
|
98
|
+
...(options.body !== undefined ? { body: JSON.stringify(options.body) } : {}),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// A runtime may build this message from the URL, which carries the credentials.
|
|
103
|
+
return { kind: 'down', reason: 'Trello could not be reached (the request failed)' };
|
|
104
|
+
}
|
|
105
|
+
if (!response.ok)
|
|
106
|
+
return { kind: 'http', status: response.status };
|
|
107
|
+
if (!options.parse)
|
|
108
|
+
return { kind: 'ok', body: undefined };
|
|
109
|
+
try {
|
|
110
|
+
return { kind: 'ok', body: await response.json() };
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return { kind: 'garbled' };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function fetchLists() {
|
|
117
|
+
const reply = await call('GET', `/boards/${encodeURIComponent(config.boardId)}/lists`, {
|
|
118
|
+
query: { fields: 'name' },
|
|
119
|
+
parse: true,
|
|
120
|
+
});
|
|
121
|
+
if (reply.kind === 'down')
|
|
122
|
+
return { kind: 'unreachable', reason: reply.reason };
|
|
123
|
+
if (reply.kind === 'http')
|
|
124
|
+
return { kind: 'unreachable', reason: httpReason(reply.status) };
|
|
125
|
+
if (reply.kind === 'garbled') {
|
|
126
|
+
return { kind: 'malformed', message: 'the list reply was not valid JSON' };
|
|
127
|
+
}
|
|
128
|
+
if (!Array.isArray(reply.body)) {
|
|
129
|
+
return { kind: 'malformed', message: 'the list reply was not an array' };
|
|
130
|
+
}
|
|
131
|
+
const names = new Map();
|
|
132
|
+
for (const entry of reply.body) {
|
|
133
|
+
if (!isRecord(entry) || typeof entry.id !== 'string' || typeof entry.name !== 'string') {
|
|
134
|
+
return { kind: 'malformed', message: 'a list entry had no string id and name' };
|
|
135
|
+
}
|
|
136
|
+
names.set(entry.id, entry.name);
|
|
137
|
+
}
|
|
138
|
+
return { kind: 'ok', names };
|
|
139
|
+
}
|
|
140
|
+
function mapCard(raw, names, fallbackId) {
|
|
141
|
+
if (!isRecord(raw)) {
|
|
142
|
+
return {
|
|
143
|
+
ok: false,
|
|
144
|
+
id: fallbackId,
|
|
145
|
+
problems: [{ field: 'shape', message: 'a Trello card must be an object' }],
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
const id = typeof raw.id === 'string' && raw.id !== '' ? raw.id : fallbackId;
|
|
149
|
+
const problems = [];
|
|
150
|
+
if (typeof raw.id !== 'string' || raw.id === '') {
|
|
151
|
+
problems.push({ field: 'id', message: 'id is required and must be a non-empty string' });
|
|
152
|
+
}
|
|
153
|
+
if (typeof raw.name !== 'string') {
|
|
154
|
+
problems.push({ field: 'name', message: 'name is required and must be a string' });
|
|
155
|
+
}
|
|
156
|
+
if (typeof raw.url !== 'string') {
|
|
157
|
+
problems.push({ field: 'url', message: 'url is required and must be a string' });
|
|
158
|
+
}
|
|
159
|
+
if (raw.desc !== undefined && raw.desc !== null && typeof raw.desc !== 'string') {
|
|
160
|
+
problems.push({ field: 'desc', message: 'desc must be a string when present' });
|
|
161
|
+
}
|
|
162
|
+
if (raw.idMembers !== undefined && !Array.isArray(raw.idMembers)) {
|
|
163
|
+
problems.push({ field: 'idMembers', message: 'idMembers must be an array when present' });
|
|
164
|
+
}
|
|
165
|
+
if (raw.labels !== undefined && !Array.isArray(raw.labels)) {
|
|
166
|
+
problems.push({ field: 'labels', message: 'labels must be an array when present' });
|
|
167
|
+
}
|
|
168
|
+
let state = '';
|
|
169
|
+
if (typeof raw.idList !== 'string') {
|
|
170
|
+
problems.push({ field: 'idList', message: 'idList is required and must be a string' });
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
const listName = names.get(raw.idList);
|
|
174
|
+
if (listName === undefined) {
|
|
175
|
+
problems.push({ field: 'idList', message: 'the card is in a list not on this board' });
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
state = listName;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (problems.length > 0)
|
|
182
|
+
return { ok: false, id, problems };
|
|
183
|
+
const unknownFields = {
|
|
184
|
+
idList: raw.idList,
|
|
185
|
+
unsupported: ['requires', 'parent'],
|
|
186
|
+
};
|
|
187
|
+
for (const key of ['idShort', 'idMembers', 'labels', 'due', 'dateLastActivity']) {
|
|
188
|
+
if (raw[key] !== undefined && raw[key] !== null)
|
|
189
|
+
unknownFields[key] = raw[key];
|
|
190
|
+
}
|
|
191
|
+
const derived = config.statusMap !== undefined ? normalizeStatus(state, config.statusMap) : undefined;
|
|
192
|
+
return {
|
|
193
|
+
ok: true,
|
|
194
|
+
card: {
|
|
195
|
+
id,
|
|
196
|
+
state,
|
|
197
|
+
reference: raw.url,
|
|
198
|
+
source,
|
|
199
|
+
unknownFields,
|
|
200
|
+
title: raw.name,
|
|
201
|
+
...(typeof raw.desc === 'string' && raw.desc !== '' ? { body: raw.desc } : {}),
|
|
202
|
+
...(derived?.kind === 'mapped' ? { status: derived.status } : {}),
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
async function get(id) {
|
|
207
|
+
const reply = await call('GET', `/cards/${encodeURIComponent(id)}`, {
|
|
208
|
+
query: { fields: CARD_FIELDS },
|
|
209
|
+
parse: true,
|
|
210
|
+
});
|
|
211
|
+
if (reply.kind === 'down')
|
|
212
|
+
return { outcome: 'unreachable', reason: reply.reason };
|
|
213
|
+
if (reply.kind === 'http') {
|
|
214
|
+
// Trello answers 400 "invalid id" for an id that cannot be a card id.
|
|
215
|
+
if (reply.status === 404 || reply.status === 400)
|
|
216
|
+
return { outcome: 'absent' };
|
|
217
|
+
return { outcome: 'unreachable', reason: httpReason(reply.status) };
|
|
218
|
+
}
|
|
219
|
+
if (reply.kind === 'garbled') {
|
|
220
|
+
return {
|
|
221
|
+
outcome: 'unparseable',
|
|
222
|
+
id,
|
|
223
|
+
problems: [{ field: 'shape', message: 'the card reply was not valid JSON' }],
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
const lists = await fetchLists();
|
|
227
|
+
if (lists.kind === 'unreachable')
|
|
228
|
+
return { outcome: 'unreachable', reason: lists.reason };
|
|
229
|
+
if (lists.kind === 'malformed') {
|
|
230
|
+
return {
|
|
231
|
+
outcome: 'unparseable',
|
|
232
|
+
id,
|
|
233
|
+
problems: [{ field: 'lists', message: lists.message }],
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
const mapped = mapCard(reply.body, lists.names, id);
|
|
237
|
+
return mapped.ok
|
|
238
|
+
? { outcome: 'found', card: mapped.card }
|
|
239
|
+
: { outcome: 'unparseable', id: mapped.id, problems: mapped.problems };
|
|
240
|
+
}
|
|
241
|
+
async function list() {
|
|
242
|
+
const cards = await call('GET', `/boards/${encodeURIComponent(config.boardId)}/cards`, {
|
|
243
|
+
query: { fields: CARD_FIELDS },
|
|
244
|
+
parse: true,
|
|
245
|
+
});
|
|
246
|
+
if (cards.kind === 'down')
|
|
247
|
+
return { outcome: 'unreachable', reason: cards.reason };
|
|
248
|
+
if (cards.kind === 'http')
|
|
249
|
+
return { outcome: 'unreachable', reason: httpReason(cards.status) };
|
|
250
|
+
if (cards.kind === 'garbled' || !Array.isArray(cards.body)) {
|
|
251
|
+
return { outcome: 'unreachable', reason: 'Trello answered with a malformed card list' };
|
|
252
|
+
}
|
|
253
|
+
const lists = await fetchLists();
|
|
254
|
+
if (lists.kind === 'unreachable')
|
|
255
|
+
return { outcome: 'unreachable', reason: lists.reason };
|
|
256
|
+
if (lists.kind === 'malformed') {
|
|
257
|
+
return {
|
|
258
|
+
outcome: 'unreachable',
|
|
259
|
+
reason: `Trello answered with a malformed list set: ${lists.message}`,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
const raws = cards.body;
|
|
263
|
+
if (raws.length === 0)
|
|
264
|
+
return { outcome: 'empty' };
|
|
265
|
+
const good = [];
|
|
266
|
+
const bad = [];
|
|
267
|
+
raws.forEach((raw, index) => {
|
|
268
|
+
const mapped = mapCard(raw, lists.names, `index ${index}`);
|
|
269
|
+
if (mapped.ok)
|
|
270
|
+
good.push(mapped.card);
|
|
271
|
+
else
|
|
272
|
+
bad.push({ id: mapped.id, problems: mapped.problems });
|
|
273
|
+
});
|
|
274
|
+
return { outcome: 'cards', cards: good, unparseable: bad, danglingIds: [] };
|
|
275
|
+
}
|
|
276
|
+
async function writeState(id, state, options) {
|
|
277
|
+
if (options?.expectedRevision !== undefined) {
|
|
278
|
+
return { outcome: 'unsupported', id, reason: TRELLO_EXPECTED_REVISION_UNSUPPORTED_REASON };
|
|
279
|
+
}
|
|
280
|
+
const lists = await fetchLists();
|
|
281
|
+
if (lists.kind === 'unreachable')
|
|
282
|
+
return { outcome: 'unreachable', reason: lists.reason };
|
|
283
|
+
if (lists.kind === 'malformed') {
|
|
284
|
+
return {
|
|
285
|
+
outcome: 'refused',
|
|
286
|
+
reason: `Trello answered with a malformed list set: ${lists.message}`,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
let wanted = state;
|
|
290
|
+
let matches = [...lists.names].filter(([, name]) => name === wanted);
|
|
291
|
+
if (matches.length === 0 && config.statusMap !== undefined && isStatus(state)) {
|
|
292
|
+
const native = nativeStateFor(state, config.statusMap);
|
|
293
|
+
if (native.kind === 'mapped') {
|
|
294
|
+
wanted = native.state;
|
|
295
|
+
matches = [...lists.names].filter(([, name]) => name === wanted);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if (matches.length === 0) {
|
|
299
|
+
return { outcome: 'refused', reason: `no list named "${state}" on this board` };
|
|
300
|
+
}
|
|
301
|
+
if (matches.length > 1) {
|
|
302
|
+
return {
|
|
303
|
+
outcome: 'refused',
|
|
304
|
+
reason: `more than one list is named "${wanted}" on this board`,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
const listId = matches[0][0];
|
|
308
|
+
const reply = await call('PUT', `/cards/${encodeURIComponent(id)}`, {
|
|
309
|
+
body: { idList: listId },
|
|
310
|
+
parse: false,
|
|
311
|
+
});
|
|
312
|
+
if (reply.kind === 'ok')
|
|
313
|
+
return { outcome: 'applied' };
|
|
314
|
+
if (reply.kind === 'down')
|
|
315
|
+
return { outcome: 'unreachable', reason: reply.reason };
|
|
316
|
+
if (reply.kind === 'http') {
|
|
317
|
+
if (reply.status === 404 || reply.status === 400) {
|
|
318
|
+
return { outcome: 'refused', reason: `no card with id ${id}` };
|
|
319
|
+
}
|
|
320
|
+
if (reply.status === 401 || reply.status === 403) {
|
|
321
|
+
return { outcome: 'refused', reason: httpReason(reply.status) };
|
|
322
|
+
}
|
|
323
|
+
return { outcome: 'unreachable', reason: httpReason(reply.status) };
|
|
324
|
+
}
|
|
325
|
+
return { outcome: 'unreachable', reason: 'Trello answered with an unreadable reply' };
|
|
326
|
+
}
|
|
327
|
+
async function createCard() {
|
|
328
|
+
return { outcome: 'refused', reason: TRELLO_CREATE_CARD_REFUSED_REASON };
|
|
329
|
+
}
|
|
330
|
+
async function annotate(id, _patch, options) {
|
|
331
|
+
if (options?.expectedRevision !== undefined) {
|
|
332
|
+
return { outcome: 'unsupported', id, reason: TRELLO_EXPECTED_REVISION_UNSUPPORTED_REASON };
|
|
333
|
+
}
|
|
334
|
+
return { outcome: 'refused', reason: TRELLO_ANNOTATE_REFUSED_REASON };
|
|
335
|
+
}
|
|
336
|
+
return { get, list, writeState, createCard, annotate };
|
|
337
|
+
}
|