@pincast/api 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +140 -2
- package/openapi/placecard-v1.openapi.json +1074 -0
- package/package.json +57 -4
- package/src/client.js +155 -0
- package/src/errors.js +31 -0
- package/src/generated/operations.js +19 -0
- package/src/generated/types.d.ts +537 -0
- package/src/index.d.ts +109 -0
- package/src/index.js +5 -0
- package/src/keys.js +39 -0
- package/src/mock.d.ts +45 -0
- package/src/mock.js +156 -0
- package/src/openapi.js +28 -0
- package/src/resend-queue.d.ts +60 -0
- package/src/resend-queue.js +122 -0
- package/src/validate.js +72 -0
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
// Generated by scripts/generate.mjs from openapi/placecard-v1.openapi.json
|
|
2
|
+
// (Placecard registry 1.0.0, sha256 0714846067829acca4724b34730facf69f17d2d564cab9917d7ef8d27b3ba36e). Do not edit: run npm run generate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The body of every error. message says what was wrong, for a person to read; statusCode repeats the HTTP status; data, on every 4xx and on a 503, says what to do.
|
|
6
|
+
*/
|
|
7
|
+
export type Error = {
|
|
8
|
+
/**
|
|
9
|
+
* The path that was called.
|
|
10
|
+
*/
|
|
11
|
+
url: string
|
|
12
|
+
statusCode: number
|
|
13
|
+
/**
|
|
14
|
+
* Empty, or Not Found on a 404.
|
|
15
|
+
*/
|
|
16
|
+
statusMessage: string
|
|
17
|
+
message: string
|
|
18
|
+
/**
|
|
19
|
+
* Always empty in production.
|
|
20
|
+
*/
|
|
21
|
+
stack?: string
|
|
22
|
+
data?: ErrorData
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* What to do about a 4xx or a 503. Branch on code: it stays the same from release to release, while message and fix are for people and may be worded better later.
|
|
27
|
+
*/
|
|
28
|
+
export type ErrorData = {
|
|
29
|
+
/**
|
|
30
|
+
* Each code with the status it comes with: key_missing 401, key_invalid 403, key_expired 403, key_conflict 400, key_ability_missing 403, key_kind_refused 403, test_person_required 403, test_limit_reached 409, test_apps_limit 429, browser_not_allowed 403, rate_limited 429, quota_exceeded 429, set_id_invalid 400, idempotency_key_invalid 400, body_not_json 400, field_required 400, field_invalid 400, too_many_cards 400, duplicate_card_key 400, parent_not_registered 400, too_many_actors 400, same_player 400, set_not_registered 404, card_not_registered 404, card_retired 409, actor_signed_in 409, idempotency_key_reused 422, token_invalid 400, token_expired 400, token_other_app 403, person_not_signed_in 403, signin_check_unavailable 503. field_required is a field left out or blank; field_invalid is one sent with the wrong type, shape, length or range. key_conflict is a call that sent X-Pincast-Key and X-Placecard-Key with different keys. key_ability_missing is a restricted key that does not name what this call needs. key_kind_refused is a kind of key that cannot make this call. test_person_required is a test key's call for a person whose id does not start test_, or one that sends a sign-in token. test_limit_reached is a test key's write that would take its test app past the test limits. test_apps_limit is POST /test-apps when Pincast has made all the test apps it makes in a day. browser_not_allowed is POST /test-apps called from a web page. quota_exceeded is a call past your app's quota of calls for the UTC day.
|
|
31
|
+
*/
|
|
32
|
+
code: "key_missing" | "key_invalid" | "key_expired" | "key_conflict" | "key_ability_missing" | "key_kind_refused" | "test_person_required" | "test_limit_reached" | "test_apps_limit" | "browser_not_allowed" | "rate_limited" | "quota_exceeded" | "set_id_invalid" | "idempotency_key_invalid" | "body_not_json" | "field_required" | "field_invalid" | "too_many_cards" | "duplicate_card_key" | "parent_not_registered" | "too_many_actors" | "same_player" | "set_not_registered" | "card_not_registered" | "card_retired" | "actor_signed_in" | "idempotency_key_reused" | "token_invalid" | "token_expired" | "token_other_app" | "person_not_signed_in" | "signin_check_unavailable"
|
|
33
|
+
/**
|
|
34
|
+
* Where the fault is: a body field's path (name, meta.checkout, cards[3].key, card.title, actor.id, from, to, token, testPerson), the set path parameter (set), the actor query parameter (actor), or a header (X-Pincast-Key at api.pincast.fm, X-Placecard-Key at the older address, Idempotency-Key). Left out when no one field is at fault.
|
|
35
|
+
*/
|
|
36
|
+
field?: string
|
|
37
|
+
/**
|
|
38
|
+
* What to send instead, in one sentence.
|
|
39
|
+
*/
|
|
40
|
+
fix: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Lowercase letters, digits, underscores and hyphens, starting with a letter or digit, 64 characters at most.
|
|
45
|
+
*/
|
|
46
|
+
export type SetId = string
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Your app's own id for the card, unique in the set: letters, digits and : _ . or hyphen, starting with a letter or digit, 128 characters at most.
|
|
50
|
+
*/
|
|
51
|
+
export type CardKey = string
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Your app's own word for the kind of card (species, tree): a lowercase word of 32 characters at most.
|
|
55
|
+
*/
|
|
56
|
+
export type CardType = string
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* An ISO 8601 time.
|
|
60
|
+
*/
|
|
61
|
+
export type Time = string
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* A count for each card type.
|
|
65
|
+
*/
|
|
66
|
+
export type TypeCounts = {
|
|
67
|
+
[key: string]: number
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* One card as your app sends it. An empty string or null counts as left out. The server ignores fields not listed here.
|
|
72
|
+
*/
|
|
73
|
+
export type Card = {
|
|
74
|
+
key: CardKey
|
|
75
|
+
type: CardType
|
|
76
|
+
/**
|
|
77
|
+
* The key of the card this one belongs to (a tree card's species card). It must be in the same call or already registered, and is never the card itself.
|
|
78
|
+
*/
|
|
79
|
+
parent?: CardKey
|
|
80
|
+
title: string
|
|
81
|
+
subtitle?: string
|
|
82
|
+
fact?: string
|
|
83
|
+
/**
|
|
84
|
+
* Your app's own word, printed as given.
|
|
85
|
+
*/
|
|
86
|
+
rarity?: string
|
|
87
|
+
/**
|
|
88
|
+
* Only true makes a foil card.
|
|
89
|
+
*/
|
|
90
|
+
foil?: boolean
|
|
91
|
+
image?: {
|
|
92
|
+
url?: string
|
|
93
|
+
credit?: string
|
|
94
|
+
license?: string
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Where your app plays this card.
|
|
98
|
+
*/
|
|
99
|
+
url?: string
|
|
100
|
+
/**
|
|
101
|
+
* Sent with lng. A numeric string is also accepted.
|
|
102
|
+
*/
|
|
103
|
+
lat?: number
|
|
104
|
+
/**
|
|
105
|
+
* Sent with lat. A numeric string is also accepted.
|
|
106
|
+
*/
|
|
107
|
+
lng?: number
|
|
108
|
+
/**
|
|
109
|
+
* Anything else your card's face needs, under 8000 characters as JSON.
|
|
110
|
+
*/
|
|
111
|
+
data?: {
|
|
112
|
+
[key: string]: unknown
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* A retired card stays with the people who hold it and takes no new collects.
|
|
116
|
+
*/
|
|
117
|
+
status?: "active" | "retired"
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export type PutSetRequest = {
|
|
121
|
+
/**
|
|
122
|
+
* Trimmed before the check.
|
|
123
|
+
*/
|
|
124
|
+
name: string
|
|
125
|
+
/**
|
|
126
|
+
* Anything about the set your app wants kept, under 8000 characters as JSON. Two keys matter to every app: listed (false keeps the set off the map, the front page and card pages for people who do not hold its cards) and checkout (refused with field_invalid unless it is one of Pincast's own checkout paths for your app; selling through Pincast's checkout comes later).
|
|
127
|
+
*/
|
|
128
|
+
meta?: {
|
|
129
|
+
[key: string]: unknown
|
|
130
|
+
}
|
|
131
|
+
cards?: Array<Card>
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type PutSetResponse = {
|
|
135
|
+
/**
|
|
136
|
+
* Your app's id.
|
|
137
|
+
*/
|
|
138
|
+
app: string
|
|
139
|
+
set: SetId
|
|
140
|
+
name: string
|
|
141
|
+
/**
|
|
142
|
+
* True when this call created the set.
|
|
143
|
+
*/
|
|
144
|
+
setCreated: boolean
|
|
145
|
+
cards: {
|
|
146
|
+
created: number
|
|
147
|
+
updated: number
|
|
148
|
+
unchanged: number
|
|
149
|
+
/**
|
|
150
|
+
* Cards whose parent this call set or changed.
|
|
151
|
+
*/
|
|
152
|
+
parentsSet: number
|
|
153
|
+
}
|
|
154
|
+
active: TypeCounts
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export type SetResponse = {
|
|
158
|
+
app: string
|
|
159
|
+
set: SetId
|
|
160
|
+
name: string
|
|
161
|
+
meta: {
|
|
162
|
+
[key: string]: unknown
|
|
163
|
+
}
|
|
164
|
+
updatedAt: Time
|
|
165
|
+
active: TypeCounts
|
|
166
|
+
/**
|
|
167
|
+
* Cards collected directly, one per person and card.
|
|
168
|
+
*/
|
|
169
|
+
collects: number
|
|
170
|
+
/**
|
|
171
|
+
* People who collected at least one card.
|
|
172
|
+
*/
|
|
173
|
+
players: number
|
|
174
|
+
/**
|
|
175
|
+
* Whether the set lists: on the Placecard map, the front page and card pages for people who do not hold its cards. A new app's sets list once Pincast has reviewed the app.
|
|
176
|
+
*/
|
|
177
|
+
listing: {
|
|
178
|
+
listed: boolean
|
|
179
|
+
/**
|
|
180
|
+
* Null when the set lists, otherwise the first reason it doesn't: app_not_reviewed (Pincast hasn't reviewed your app yet; a test app always answers this, because it never lists), app_hidden or set_hidden (Pincast took your app or this set off the lists; ask us why), set_off (your own meta.listed is false). People keep the cards they hold either way, and your key keeps writing.
|
|
181
|
+
*/
|
|
182
|
+
reason: "app_not_reviewed" | "app_hidden" | "set_hidden" | "set_off" | null
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export type Actor = {
|
|
187
|
+
/**
|
|
188
|
+
* A Logto id, or your app's guest token for this device. Trimmed before the check. Under a test key, an id that starts test_.
|
|
189
|
+
*/
|
|
190
|
+
id: string
|
|
191
|
+
/**
|
|
192
|
+
* logto for a signed in person, once your app has sent their sign-in token with POST /people; anonymous for a guest token, never a person's id (409 actor_signed_in for an id that holds cards in your app as a signed-in person).
|
|
193
|
+
*/
|
|
194
|
+
source: "logto" | "anonymous"
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export type CollectRequest = {
|
|
198
|
+
/**
|
|
199
|
+
* The card's key, or the whole card to register or update it first.
|
|
200
|
+
*/
|
|
201
|
+
card: CardKey | Card
|
|
202
|
+
actor: Actor
|
|
203
|
+
/**
|
|
204
|
+
* When it was collected, on your app's clock. Not more than five minutes ahead of Placecard's clock, and not before 2015. Leave it out for now.
|
|
205
|
+
*/
|
|
206
|
+
at?: Time
|
|
207
|
+
/**
|
|
208
|
+
* Where it was collected. Sent with lng.
|
|
209
|
+
*/
|
|
210
|
+
lat?: number
|
|
211
|
+
/**
|
|
212
|
+
* Sent with lat.
|
|
213
|
+
*/
|
|
214
|
+
lng?: number
|
|
215
|
+
/**
|
|
216
|
+
* How sure the place is, in metres.
|
|
217
|
+
*/
|
|
218
|
+
accuracy?: number
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export type CollectResponse = {
|
|
222
|
+
collected: true
|
|
223
|
+
/**
|
|
224
|
+
* True when this collect's time is this person's first hold of the card, so a resend answers as the first send did.
|
|
225
|
+
*/
|
|
226
|
+
first: boolean
|
|
227
|
+
/**
|
|
228
|
+
* How many times this person collected the card directly.
|
|
229
|
+
*/
|
|
230
|
+
count: number
|
|
231
|
+
/**
|
|
232
|
+
* This person's first collect of the card.
|
|
233
|
+
*/
|
|
234
|
+
collectedAt: Time
|
|
235
|
+
card: {
|
|
236
|
+
key: CardKey
|
|
237
|
+
type: CardType
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* The parent card, held through this one; null when the card has none.
|
|
241
|
+
*/
|
|
242
|
+
parent: {
|
|
243
|
+
key: CardKey
|
|
244
|
+
/**
|
|
245
|
+
* True when this collect is this person's first hold of the parent: its time is their first hold of the parent, and through this card.
|
|
246
|
+
*/
|
|
247
|
+
first: boolean
|
|
248
|
+
} | null
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export type HeldCard = {
|
|
252
|
+
key: CardKey
|
|
253
|
+
type: CardType
|
|
254
|
+
/**
|
|
255
|
+
* The key of the card this one belongs to.
|
|
256
|
+
*/
|
|
257
|
+
parent: string | null
|
|
258
|
+
/**
|
|
259
|
+
* The child card this one was first held through, when it was.
|
|
260
|
+
*/
|
|
261
|
+
via: string | null
|
|
262
|
+
collectedAt: Time
|
|
263
|
+
lastCollectedAt: Time
|
|
264
|
+
/**
|
|
265
|
+
* Direct collects; 0 when held only through a child card.
|
|
266
|
+
*/
|
|
267
|
+
count: number
|
|
268
|
+
source: "logto" | "anonymous"
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export type CollectsResponse = {
|
|
272
|
+
app: string
|
|
273
|
+
set: SetId
|
|
274
|
+
held: TypeCounts
|
|
275
|
+
cards: Array<HeldCard>
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export type ClaimRequest = {
|
|
279
|
+
/**
|
|
280
|
+
* This device's guest token, as your app read it. Under a test key, an id that starts test_.
|
|
281
|
+
*/
|
|
282
|
+
from: string
|
|
283
|
+
/**
|
|
284
|
+
* The Logto id of the person who just signed in, once your app has sent their sign-in token with POST /people. Never the same as from. Under a test key, an id that starts test_.
|
|
285
|
+
*/
|
|
286
|
+
to: string
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export type ClaimResponse = {
|
|
290
|
+
app: string
|
|
291
|
+
set: SetId
|
|
292
|
+
claimed: number
|
|
293
|
+
moved: number
|
|
294
|
+
merged: number
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* token under a live key, testPerson under a test key.
|
|
299
|
+
*/
|
|
300
|
+
export type PersonRequest = ({
|
|
301
|
+
/**
|
|
302
|
+
* The person's ID token from id.pincast.fm, a JWT, exactly as your app received it at sign-in. Refused under a test key.
|
|
303
|
+
*/
|
|
304
|
+
token: string
|
|
305
|
+
/**
|
|
306
|
+
* Under a test key: the test person to answer for, such as test_demo. Nothing is stored.
|
|
307
|
+
*/
|
|
308
|
+
testPerson?: never
|
|
309
|
+
}) | ({
|
|
310
|
+
/**
|
|
311
|
+
* The person's ID token from id.pincast.fm, a JWT, exactly as your app received it at sign-in. Refused under a test key.
|
|
312
|
+
*/
|
|
313
|
+
token?: never
|
|
314
|
+
/**
|
|
315
|
+
* Under a test key: the test person to answer for, such as test_demo. Nothing is stored.
|
|
316
|
+
*/
|
|
317
|
+
testPerson: string
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
export type PersonResponse = {
|
|
321
|
+
app: string
|
|
322
|
+
/**
|
|
323
|
+
* The person's Logto id, the token's subject, or under a test key the testPerson you sent: send it as actor.id and as to.
|
|
324
|
+
*/
|
|
325
|
+
person: string
|
|
326
|
+
linkedAt: Time
|
|
327
|
+
/**
|
|
328
|
+
* Present only under a test key: nothing was stored.
|
|
329
|
+
*/
|
|
330
|
+
simulated?: true
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* What POST /test-apps takes. Any other field is refused.
|
|
335
|
+
*/
|
|
336
|
+
export type TestAppRequest = {
|
|
337
|
+
/**
|
|
338
|
+
* The app's name. Left out, it is Test app.
|
|
339
|
+
*/
|
|
340
|
+
name?: string
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export type TestAppResponse = {
|
|
344
|
+
app: {
|
|
345
|
+
id: string
|
|
346
|
+
name: string
|
|
347
|
+
mode: "test"
|
|
348
|
+
expiresAt: Time
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* The restricted test key, shown only here. Send it in X-Pincast-Key.
|
|
352
|
+
*/
|
|
353
|
+
key: string
|
|
354
|
+
keyId: string
|
|
355
|
+
claim: {
|
|
356
|
+
/**
|
|
357
|
+
* Works once, shown only here.
|
|
358
|
+
*/
|
|
359
|
+
code: string
|
|
360
|
+
/**
|
|
361
|
+
* Open it signed in to Pincast to keep this app.
|
|
362
|
+
*/
|
|
363
|
+
url: string
|
|
364
|
+
expiresAt: Time
|
|
365
|
+
}
|
|
366
|
+
api: "https://api.pincast.fm/v1"
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export type AppsResponse = {
|
|
370
|
+
/**
|
|
371
|
+
* The featured app first while its slot runs, then every app by name.
|
|
372
|
+
*/
|
|
373
|
+
apps: Array<App>
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export type App = {
|
|
377
|
+
/**
|
|
378
|
+
* The app's id: the one in its key, and app on every set and card.
|
|
379
|
+
*/
|
|
380
|
+
id: string
|
|
381
|
+
name: string
|
|
382
|
+
/**
|
|
383
|
+
* What the app is, in a sentence or two of plain text. Null when it has none yet.
|
|
384
|
+
*/
|
|
385
|
+
description: string | null
|
|
386
|
+
/**
|
|
387
|
+
* The app's home page, always https. Null when it has none.
|
|
388
|
+
*/
|
|
389
|
+
url: string | null
|
|
390
|
+
/**
|
|
391
|
+
* The address of the app's icon, always https. Null when it has none.
|
|
392
|
+
*/
|
|
393
|
+
icon: string | null
|
|
394
|
+
/**
|
|
395
|
+
* The app's color as #rrggbb, for its chips, pins and marks. Null when it has none.
|
|
396
|
+
*/
|
|
397
|
+
color: string | null
|
|
398
|
+
/**
|
|
399
|
+
* What kind of app it is, one of a short list Pincast keeps. The list may grow. Null when it has none yet.
|
|
400
|
+
*/
|
|
401
|
+
category: "walks" | "nature" | "history" | "art" | "food" | "games" | "making" | null
|
|
402
|
+
/**
|
|
403
|
+
* Set on the featured app while its slot runs, null on every other app. One app at a time.
|
|
404
|
+
*/
|
|
405
|
+
featured: {
|
|
406
|
+
/**
|
|
407
|
+
* A line on why the app is featured, or null.
|
|
408
|
+
*/
|
|
409
|
+
note: string | null
|
|
410
|
+
/**
|
|
411
|
+
* When the slot ends, or null when Pincast ends it by hand.
|
|
412
|
+
*/
|
|
413
|
+
until: string | null
|
|
414
|
+
} | null
|
|
415
|
+
/**
|
|
416
|
+
* true when the app has cards on Placecard: a listed set with one card or more.
|
|
417
|
+
*/
|
|
418
|
+
cardApp: boolean
|
|
419
|
+
/**
|
|
420
|
+
* The cards in the app's listed sets that Placecard shows as cards: active ones that show on their own: not an experience (a walk, say), not a place (a tree), and with no parent or an experience for a parent.
|
|
421
|
+
*/
|
|
422
|
+
cardCount: number
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** Every code an error can carry. */
|
|
426
|
+
export type ErrorCode = ErrorData['code']
|
|
427
|
+
|
|
428
|
+
/** Each operation in the API file: its address, what it takes and what it answers. */
|
|
429
|
+
export interface Operations {
|
|
430
|
+
/**
|
|
431
|
+
* GET /sets/{set}: Read a set back
|
|
432
|
+
*/
|
|
433
|
+
getSet: {
|
|
434
|
+
method: "GET"
|
|
435
|
+
path: "/sets/{set}"
|
|
436
|
+
pathParams: { set: SetId }
|
|
437
|
+
query: {}
|
|
438
|
+
body: never
|
|
439
|
+
response: SetResponse
|
|
440
|
+
key: true
|
|
441
|
+
idempotencyKey: false
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* PUT /sets/{set}: Register a card set, or update it and its cards
|
|
445
|
+
*/
|
|
446
|
+
putSet: {
|
|
447
|
+
method: "PUT"
|
|
448
|
+
path: "/sets/{set}"
|
|
449
|
+
pathParams: { set: SetId }
|
|
450
|
+
query: {}
|
|
451
|
+
body: PutSetRequest
|
|
452
|
+
response: PutSetResponse
|
|
453
|
+
key: true
|
|
454
|
+
idempotencyKey: true
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* GET /sets/{set}/collects: Read what a person holds in this set
|
|
458
|
+
*/
|
|
459
|
+
getCollects: {
|
|
460
|
+
method: "GET"
|
|
461
|
+
path: "/sets/{set}/collects"
|
|
462
|
+
pathParams: { set: SetId }
|
|
463
|
+
query: { actor: Array<string> }
|
|
464
|
+
body: never
|
|
465
|
+
response: CollectsResponse
|
|
466
|
+
key: true
|
|
467
|
+
idempotencyKey: false
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* POST /sets/{set}/collects: Record that a person collected a card
|
|
471
|
+
*/
|
|
472
|
+
postCollect: {
|
|
473
|
+
method: "POST"
|
|
474
|
+
path: "/sets/{set}/collects"
|
|
475
|
+
pathParams: { set: SetId }
|
|
476
|
+
query: {}
|
|
477
|
+
body: CollectRequest
|
|
478
|
+
response: CollectResponse
|
|
479
|
+
key: true
|
|
480
|
+
idempotencyKey: true
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* POST /sets/{set}/claims: Move a guest's cards to the person who just signed in
|
|
484
|
+
*/
|
|
485
|
+
postClaim: {
|
|
486
|
+
method: "POST"
|
|
487
|
+
path: "/sets/{set}/claims"
|
|
488
|
+
pathParams: { set: SetId }
|
|
489
|
+
query: {}
|
|
490
|
+
body: ClaimRequest
|
|
491
|
+
response: ClaimResponse
|
|
492
|
+
key: true
|
|
493
|
+
idempotencyKey: true
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* POST /people: Link a person who signed in to your app
|
|
497
|
+
*/
|
|
498
|
+
postPerson: {
|
|
499
|
+
method: "POST"
|
|
500
|
+
path: "/people"
|
|
501
|
+
pathParams: {}
|
|
502
|
+
query: {}
|
|
503
|
+
body: PersonRequest
|
|
504
|
+
response: PersonResponse
|
|
505
|
+
key: true
|
|
506
|
+
idempotencyKey: false
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* GET /apps: List the apps on Pincast
|
|
510
|
+
*/
|
|
511
|
+
getApps: {
|
|
512
|
+
method: "GET"
|
|
513
|
+
path: "/apps"
|
|
514
|
+
pathParams: {}
|
|
515
|
+
query: {}
|
|
516
|
+
body: never
|
|
517
|
+
response: AppsResponse
|
|
518
|
+
key: false
|
|
519
|
+
idempotencyKey: false
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* POST /test-apps: Make a test app with no account
|
|
523
|
+
*/
|
|
524
|
+
postTestApp: {
|
|
525
|
+
method: "POST"
|
|
526
|
+
path: "/test-apps"
|
|
527
|
+
pathParams: {}
|
|
528
|
+
query: {}
|
|
529
|
+
body: TestAppRequest | undefined
|
|
530
|
+
response: TestAppResponse
|
|
531
|
+
key: false
|
|
532
|
+
idempotencyKey: false
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/** The id of each operation, which is also the client method that makes it. */
|
|
537
|
+
export type OperationId = keyof Operations
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Types for @pincast/api. The API's own types are generated from the API file into
|
|
2
|
+
// ./generated/types.d.ts; this file declares the client around them.
|
|
3
|
+
import type {
|
|
4
|
+
AppsResponse, ClaimRequest, ClaimResponse, CollectRequest, CollectResponse, CollectsResponse, ErrorCode,
|
|
5
|
+
OperationId, Operations, PersonRequest, PersonResponse, PutSetRequest, PutSetResponse, SetId, SetResponse,
|
|
6
|
+
TestAppRequest, TestAppResponse,
|
|
7
|
+
} from './generated/types.js'
|
|
8
|
+
|
|
9
|
+
export type * from './generated/types.js'
|
|
10
|
+
|
|
11
|
+
export interface PincastOptions {
|
|
12
|
+
/** Your app's key. Defaults to process.env.PINCAST_KEY. getApps and postTestApp need none. */
|
|
13
|
+
key?: string | null
|
|
14
|
+
/** Defaults to https://api.pincast.fm/v1. */
|
|
15
|
+
baseUrl?: string
|
|
16
|
+
/** Defaults to the global fetch. */
|
|
17
|
+
fetch?: typeof fetch
|
|
18
|
+
/** Milliseconds to wait for each answer. Defaults to 10000. */
|
|
19
|
+
timeoutMs?: number
|
|
20
|
+
/** How many times one call waits out a 429 or 503 and sends again. Defaults to 2. */
|
|
21
|
+
retries?: number
|
|
22
|
+
/** The longest Retry-After, in seconds, the client waits out itself. Longer ones raise at once. Defaults to 60. */
|
|
23
|
+
maxRetryWait?: number
|
|
24
|
+
/** How the client waits. For tests; defaults to a timer. */
|
|
25
|
+
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface CallOptions {
|
|
29
|
+
signal?: AbortSignal
|
|
30
|
+
timeoutMs?: number
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface WriteOptions extends CallOptions {
|
|
34
|
+
/** Your own Idempotency-Key. Without one the client makes a new one for each call. */
|
|
35
|
+
idempotencyKey?: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface KeyInfo {
|
|
39
|
+
app: string
|
|
40
|
+
kind: 'secret' | 'restricted'
|
|
41
|
+
test: boolean
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type ErrorKind = 'key' | 'waiting' | 'later' | 'refused'
|
|
45
|
+
|
|
46
|
+
export declare class PincastError extends Error {
|
|
47
|
+
readonly name: 'PincastError'
|
|
48
|
+
/** The answer's status, or null when no answer came or the client refused before sending. */
|
|
49
|
+
readonly status: number | null
|
|
50
|
+
readonly code: ErrorCode | null
|
|
51
|
+
readonly field: string | null
|
|
52
|
+
readonly fix: string | null
|
|
53
|
+
/** Seconds from the answer's Retry-After header, when it sent one. */
|
|
54
|
+
readonly retryAfter: number | null
|
|
55
|
+
readonly operation: OperationId | null
|
|
56
|
+
/** The answer's JSON body, when there was one. */
|
|
57
|
+
readonly body: unknown
|
|
58
|
+
/** What the refusal means for a call you keep and send again. */
|
|
59
|
+
readonly kind: ErrorKind
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export declare const DEFAULT_BASE_URL: 'https://api.pincast.fm/v1'
|
|
63
|
+
export declare const KEY_HEADER: 'X-Pincast-Key'
|
|
64
|
+
export declare function retryAfterSeconds(value: string | null | undefined): number | null
|
|
65
|
+
|
|
66
|
+
export declare class Pincast {
|
|
67
|
+
constructor(options?: PincastOptions)
|
|
68
|
+
readonly keyInfo: KeyInfo | null
|
|
69
|
+
readonly baseUrl: string
|
|
70
|
+
/** PUT /sets/{set}: register a card set, or update it and its cards. */
|
|
71
|
+
putSet(set: SetId, body: PutSetRequest, options?: WriteOptions): Promise<PutSetResponse>
|
|
72
|
+
/** GET /sets/{set}: read a set back. */
|
|
73
|
+
getSet(set: SetId, options?: CallOptions): Promise<SetResponse>
|
|
74
|
+
/** POST /sets/{set}/collects: record that a person collected a card. */
|
|
75
|
+
postCollect(set: SetId, body: CollectRequest, options?: WriteOptions): Promise<CollectResponse>
|
|
76
|
+
/** GET /sets/{set}/collects: read what a person holds in this set (one to three actor ids). */
|
|
77
|
+
getCollects(set: SetId, query: { actor: string | string[] }, options?: CallOptions): Promise<CollectsResponse>
|
|
78
|
+
/** POST /sets/{set}/claims: move a guest's cards to the person who just signed in. */
|
|
79
|
+
postClaim(set: SetId, body: ClaimRequest, options?: WriteOptions): Promise<ClaimResponse>
|
|
80
|
+
/** POST /people: link a person who signed in to your app, or a test person under a test key. */
|
|
81
|
+
postPerson(body: PersonRequest, options?: CallOptions): Promise<PersonResponse>
|
|
82
|
+
/** GET /apps: the public list of apps on Pincast. Needs no key. */
|
|
83
|
+
getApps(options?: CallOptions): Promise<AppsResponse>
|
|
84
|
+
/** POST /test-apps: make a test app and its key. Needs no key or account. */
|
|
85
|
+
postTestApp(body?: TestAppRequest, options?: CallOptions): Promise<TestAppResponse>
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export declare function keyInfo(key: string): KeyInfo | null
|
|
89
|
+
export declare function isTestKey(key: string): boolean
|
|
90
|
+
export declare function isTestPerson(id: string): boolean
|
|
91
|
+
export declare function testPerson(name?: string): string
|
|
92
|
+
export declare function testActor(name?: string, source?: 'anonymous' | 'logto'): { id: string, source: 'anonymous' | 'logto' }
|
|
93
|
+
export declare const TEST_APP_ID_RE: RegExp
|
|
94
|
+
export declare const TEST_PERSON_RE: RegExp
|
|
95
|
+
|
|
96
|
+
export declare const operations: {
|
|
97
|
+
readonly [K in OperationId]: {
|
|
98
|
+
readonly method: Operations[K]['method']
|
|
99
|
+
readonly path: Operations[K]['path']
|
|
100
|
+
readonly pathParams: readonly string[]
|
|
101
|
+
readonly query: readonly string[]
|
|
102
|
+
readonly body: 'required' | 'optional' | 'none'
|
|
103
|
+
readonly key: Operations[K]['key']
|
|
104
|
+
readonly idempotencyKey: Operations[K]['idempotencyKey']
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export declare const apiFile: { readonly title: string, readonly version: string, readonly sha256: string }
|
|
108
|
+
export declare const errorCodes: readonly ErrorCode[]
|
|
109
|
+
export declare const servers: readonly string[]
|
package/src/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// @pincast/api: a typed client for the Pincast card registry (Placecard v1).
|
|
2
|
+
export { Pincast, DEFAULT_BASE_URL, KEY_HEADER, retryAfterSeconds } from './client.js'
|
|
3
|
+
export { PincastError } from './errors.js'
|
|
4
|
+
export { keyInfo, isTestKey, isTestPerson, testPerson, testActor, TEST_APP_ID_RE, TEST_PERSON_RE } from './keys.js'
|
|
5
|
+
export { operations, apiFile, errorCodes, servers } from './generated/operations.js'
|
package/src/keys.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Keys and test people. A key reads pck_, the app id, an underscore, then its secret. A newer key's
|
|
2
|
+
// secret starts sk_ (secret) or rk_ (restricted); an older key has no mark and works as a secret key.
|
|
3
|
+
// A test app's id is test- and 10 base32 letters. A test person's id starts test_.
|
|
4
|
+
export const TEST_APP_ID_RE = /^test-[a-z2-7]{10}$/
|
|
5
|
+
export const TEST_PERSON_RE = /^test_[a-z0-9_-]{1,64}$/
|
|
6
|
+
const KEY_RE = /^pck_([a-z0-9-]{1,64})_([A-Za-z0-9_-]{20,})$/
|
|
7
|
+
const BASE32 = 'abcdefghijklmnopqrstuvwxyz234567'
|
|
8
|
+
|
|
9
|
+
// What a key is, without its secret: { app, kind: 'secret' | 'restricted', test }. Null when the
|
|
10
|
+
// string doesn't read as a Pincast key.
|
|
11
|
+
export function keyInfo(key) {
|
|
12
|
+
const m = typeof key === 'string' ? KEY_RE.exec(key) : null
|
|
13
|
+
if (!m) return null
|
|
14
|
+
return Object.freeze({ app: m[1], kind: m[2].startsWith('rk_') ? 'restricted' : 'secret', test: TEST_APP_ID_RE.test(m[1]) })
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const isTestKey = (key) => keyInfo(key)?.test === true
|
|
18
|
+
export const isTestPerson = (id) => typeof id === 'string' && TEST_PERSON_RE.test(id)
|
|
19
|
+
|
|
20
|
+
// A test person's id. testPerson('Ana Lee') is test_ana-lee; testPerson() is a new random one,
|
|
21
|
+
// such as test_k3f7x2m4qa. An id that already starts test_ comes back as it is.
|
|
22
|
+
export function testPerson(name) {
|
|
23
|
+
if (name == null) {
|
|
24
|
+
let out = 'test_'
|
|
25
|
+
for (const b of globalThis.crypto.getRandomValues(new Uint8Array(10))) out += BASE32[b & 31]
|
|
26
|
+
return out
|
|
27
|
+
}
|
|
28
|
+
if (isTestPerson(name)) return name
|
|
29
|
+
const slug = String(name).toLowerCase().normalize('NFKD').replace(/[̀-ͯ]/g, '')
|
|
30
|
+
.replace(/^test_/, '').replace(/[^a-z0-9_-]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 64)
|
|
31
|
+
if (!slug) throw new TypeError(`testPerson: "${name}" has no letters or digits to make an id from`)
|
|
32
|
+
return `test_${slug}`
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// An actor for a collect or a read under a test key: { id: 'test_...', source }. Test people need
|
|
36
|
+
// no sign-in link, so the source can be either; it defaults to anonymous.
|
|
37
|
+
export function testActor(name, source = 'anonymous') {
|
|
38
|
+
return { id: testPerson(name), source }
|
|
39
|
+
}
|