@usebecky/extension 0.0.0-stage → 0.2.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.
Files changed (65) hide show
  1. package/README.md +223 -2
  2. package/dist/accounts.d.ts +85 -0
  3. package/dist/accounts.js +149 -0
  4. package/dist/cli/index.d.ts +2 -0
  5. package/dist/cli/index.js +9 -0
  6. package/dist/cli/run.d.ts +25 -0
  7. package/dist/cli/run.js +330 -0
  8. package/dist/cli/skill.d.ts +16 -0
  9. package/dist/cli/skill.js +106 -0
  10. package/dist/crypto.d.ts +12 -0
  11. package/dist/crypto.js +56 -0
  12. package/dist/dev/pages.d.ts +155 -0
  13. package/dist/dev/pages.js +243 -0
  14. package/dist/dev/plans.d.ts +45 -0
  15. package/dist/dev/plans.js +135 -0
  16. package/dist/dev/samples.d.ts +61 -0
  17. package/dist/dev/samples.js +191 -0
  18. package/dist/dev/server.d.ts +120 -0
  19. package/dist/dev/server.js +1657 -0
  20. package/dist/dev/tagging.d.ts +16 -0
  21. package/dist/dev/tagging.js +81 -0
  22. package/dist/dev/ui-render.d.ts +25 -0
  23. package/dist/dev/ui-render.js +256 -0
  24. package/dist/dev/wordmark.d.ts +1 -0
  25. package/dist/dev/wordmark.js +2 -0
  26. package/dist/errors.d.ts +98 -0
  27. package/dist/errors.js +110 -0
  28. package/dist/events.d.ts +92 -0
  29. package/dist/events.js +54 -0
  30. package/dist/extension.d.ts +214 -0
  31. package/dist/extension.js +497 -0
  32. package/dist/handlers.d.ts +39 -0
  33. package/dist/handlers.js +113 -0
  34. package/dist/identity.d.ts +99 -0
  35. package/dist/identity.js +134 -0
  36. package/dist/index.d.ts +14 -0
  37. package/dist/index.js +17 -0
  38. package/dist/jwt.d.ts +62 -0
  39. package/dist/jwt.js +152 -0
  40. package/dist/manifest.d.ts +42 -0
  41. package/dist/manifest.js +785 -0
  42. package/dist/node.d.ts +10 -0
  43. package/dist/node.js +56 -0
  44. package/dist/pkce.d.ts +9 -0
  45. package/dist/pkce.js +16 -0
  46. package/dist/stores.d.ts +100 -0
  47. package/dist/stores.js +159 -0
  48. package/dist/types.d.ts +346 -0
  49. package/dist/types.js +70 -0
  50. package/dist/ui/handler.d.ts +66 -0
  51. package/dist/ui/handler.js +105 -0
  52. package/dist/ui/schema.d.ts +423 -0
  53. package/dist/ui/schema.js +666 -0
  54. package/dist/webhooks.d.ts +26 -0
  55. package/dist/webhooks.js +99 -0
  56. package/package.json +57 -4
  57. package/skill/usebecky-extension/SKILL.md +181 -0
  58. package/skill/usebecky-extension/references/accounts.md +125 -0
  59. package/skill/usebecky-extension/references/dev-server.md +102 -0
  60. package/skill/usebecky-extension/references/manifest.md +104 -0
  61. package/skill/usebecky-extension/references/oauth-and-tokens.md +179 -0
  62. package/skill/usebecky-extension/references/partner-api.md +87 -0
  63. package/skill/usebecky-extension/references/submit-and-pricing.md +31 -0
  64. package/skill/usebecky-extension/references/ui.md +172 -0
  65. package/skill/usebecky-extension/references/webhooks.md +97 -0
@@ -0,0 +1,423 @@
1
+ export declare const UI_LIMITS: {
2
+ /** Answer size, bytes (usebecky reads no more). */
3
+ readonly responseBytes: number;
4
+ /** Blocks, buttons, items, rows and fields in one view, counted together. */
5
+ readonly nodes: 1500;
6
+ /** Lists of blocks inside each other: the view's, a section's, a column's (sections and columns nest at most twice). */
7
+ readonly depth: 3;
8
+ /** Blocks in one list (the view's, a section's, one column's). */
9
+ readonly blocks: 60;
10
+ /** Short text: labels, titles, values, cells. */
11
+ readonly short: 500;
12
+ /** A text block or a notice. */
13
+ readonly text: 5000;
14
+ /** A code block. */
15
+ readonly code: 20000;
16
+ readonly title: 80;
17
+ readonly description: 300;
18
+ readonly label: 60;
19
+ readonly viewActions: 3;
20
+ readonly stats: 8;
21
+ readonly series: 6;
22
+ readonly points: 400;
23
+ readonly bars: 50;
24
+ readonly listItems: 50;
25
+ readonly columns: 12;
26
+ readonly rows: 100;
27
+ readonly rowActions: 3;
28
+ readonly bulkActions: 3;
29
+ readonly filters: 3;
30
+ readonly filterOptions: 50;
31
+ readonly fields: 30;
32
+ readonly options: 100;
33
+ readonly buttons: 6;
34
+ readonly tabs: 8;
35
+ readonly columnsMin: 2;
36
+ readonly columnsMax: 3;
37
+ readonly params: 10;
38
+ readonly paramValue: 200;
39
+ readonly url: 2000;
40
+ readonly toast: 200;
41
+ /** Rows sent with one bulk action. */
42
+ readonly selectedRows: 100;
43
+ /** Characters of one form value sent to the extension. */
44
+ readonly value: 10000;
45
+ /** The largest number a chart, bar, stat change or total may hold (bigger ones break axes and formats). */
46
+ readonly number: 1000000000000000;
47
+ /** View.refresh_seconds: the dashboard asks for the page again every 5 to 60 seconds while it is open and in view, */
48
+ readonly refreshMin: 5;
49
+ readonly refreshMax: 60;
50
+ /** and stops after 30 minutes. */
51
+ readonly refreshStopMs: number;
52
+ };
53
+ /** Sidebar groups an extension's page may sit in (the dashboard's NAV_SECTIONS minus Home's). */
54
+ export declare const UI_SECTIONS: readonly ["backend", "website", "messages", "project"];
55
+ export type UiSection = (typeof UI_SECTIONS)[number];
56
+ /** The view on the extension's own page under Extensions (listing `ui.settings: true`). */
57
+ export declare const SETTINGS_PAGE = "settings";
58
+ export declare const PAGE_ID: RegExp;
59
+ export declare const ACTION_ID: RegExp;
60
+ export declare const PARAM_KEY: RegExp;
61
+ export declare const FIELD_KEY: RegExp;
62
+ /** A price plan's id in the listing's pricing ("monthly" for a monthly listing's one plan). */
63
+ export declare const PLAN_ID: RegExp;
64
+ /** Names that already mean something on every JavaScript object ("constructor", "toString"…): never a key or a param. */
65
+ export declare function isReservedName(name: string): boolean;
66
+ export type UiParams = Record<string, string>;
67
+ export type Tone = 'neutral' | 'info' | 'success' | 'warning' | 'danger';
68
+ /** Runs one of the extension's actions (usebecky POSTs `ui.action`). Developer role and up. */
69
+ export interface ActionButton {
70
+ label: string;
71
+ action: string;
72
+ /** The row it acts on (row buttons get their row's id by themselves). */
73
+ row?: string;
74
+ variant?: 'primary' | 'secondary' | 'danger';
75
+ /** Asked before the action runs, e.g. "Delete this review? This can't be undone." */
76
+ confirm?: string;
77
+ }
78
+ /** Opens another of the extension's pages (or the same one with other params). */
79
+ export interface PageButton {
80
+ label: string;
81
+ page: string;
82
+ params?: UiParams;
83
+ variant?: 'primary' | 'secondary' | 'danger';
84
+ }
85
+ /** Opens an https address in a new tab. */
86
+ export interface LinkButton {
87
+ label: string;
88
+ url: string;
89
+ variant?: 'primary' | 'secondary' | 'danger';
90
+ }
91
+ /** Opens usebecky's plan dialog for this extension with the plan `plan` (an id of the listing's pricing) selected. */
92
+ export interface PlanButton {
93
+ label: string;
94
+ plan: string;
95
+ variant?: 'primary' | 'secondary' | 'danger';
96
+ }
97
+ export type Button = ActionButton | PageButton | LinkButton | PlanButton;
98
+ export interface Stat {
99
+ label: string;
100
+ /** Already formatted the way it should show: "1,204", "€3,410", "4.8 ★". */
101
+ value: string;
102
+ /** Change against the previous period, in percent (12.5, -3). */
103
+ change?: number;
104
+ /** Whether a rise is good (green) or bad (red). Default "up". */
105
+ good?: 'up' | 'down';
106
+ hint?: string;
107
+ }
108
+ export type ValueFormat = 'number' | 'percent' | 'currency';
109
+ export interface Series {
110
+ name: string;
111
+ /** One per label; null for a gap. */
112
+ values: Array<number | null>;
113
+ }
114
+ export interface Column {
115
+ key: string;
116
+ label: string;
117
+ align?: 'left' | 'right';
118
+ /** Clicking the header asks for the page again with params.sort = key (or -key). */
119
+ sortable?: boolean;
120
+ }
121
+ export type Cell = string | number | null | {
122
+ text: string;
123
+ tone: Tone;
124
+ } | {
125
+ text: string;
126
+ url: string;
127
+ } | {
128
+ text: string;
129
+ page: string;
130
+ params?: UiParams;
131
+ };
132
+ export interface Row {
133
+ id: string;
134
+ cells: Record<string, Cell>;
135
+ actions?: Button[];
136
+ }
137
+ export interface Filter {
138
+ /** The params key it sets. */
139
+ param: string;
140
+ label: string;
141
+ options: Array<{
142
+ value: string;
143
+ label: string;
144
+ }>;
145
+ }
146
+ export interface Field {
147
+ key: string;
148
+ label: string;
149
+ type: 'text' | 'textarea' | 'number' | 'email' | 'url' | 'password' | 'select' | 'checkbox';
150
+ help?: string;
151
+ placeholder?: string;
152
+ required?: boolean;
153
+ /** select only. */
154
+ options?: Array<{
155
+ value: string;
156
+ label: string;
157
+ }>;
158
+ /** number only. */
159
+ min?: number;
160
+ max?: number;
161
+ /** text, textarea, email, url, password. */
162
+ max_length?: number;
163
+ }
164
+ export type FieldValue = string | number | boolean | null;
165
+ export type Block = {
166
+ type: 'text';
167
+ text: string;
168
+ tone?: 'muted';
169
+ } | {
170
+ type: 'heading';
171
+ text: string;
172
+ } | {
173
+ type: 'notice';
174
+ tone: 'info' | 'success' | 'warning' | 'danger';
175
+ title?: string;
176
+ text: string;
177
+ action?: Button;
178
+ } | {
179
+ type: 'stats';
180
+ items: Stat[];
181
+ } | {
182
+ type: 'chart';
183
+ kind: 'line' | 'column';
184
+ title?: string;
185
+ labels: string[];
186
+ series: Series[];
187
+ format?: ValueFormat;
188
+ currency?: string;
189
+ } | {
190
+ type: 'bars';
191
+ title?: string;
192
+ label_header?: string;
193
+ value_header?: string;
194
+ items: Array<{
195
+ label: string;
196
+ value: number;
197
+ display?: string;
198
+ }>;
199
+ } | {
200
+ type: 'table';
201
+ columns: Column[];
202
+ rows: Row[];
203
+ empty?: string;
204
+ /** A search box that asks for the page again with params[param] (default "q"). */
205
+ search?: {
206
+ param?: string;
207
+ placeholder?: string;
208
+ };
209
+ filters?: Filter[];
210
+ /** The sort the rows are in (from params.sort). */
211
+ sort?: {
212
+ column: string;
213
+ direction: 'asc' | 'desc';
214
+ };
215
+ /** Next / previous page: asks for the page again with params.cursor. */
216
+ next_cursor?: string;
217
+ prev_cursor?: string;
218
+ total?: number;
219
+ /** Rows get checkboxes; these actions get the checked rows' ids (action.rows). */
220
+ bulk?: ActionButton[];
221
+ } | {
222
+ type: 'list';
223
+ items: Array<{
224
+ label: string;
225
+ value: string;
226
+ copy?: boolean;
227
+ }>;
228
+ } | {
229
+ type: 'form';
230
+ action: string;
231
+ fields: Field[];
232
+ submit: string;
233
+ values?: Record<string, FieldValue>;
234
+ } | {
235
+ type: 'buttons';
236
+ items: Button[];
237
+ } | {
238
+ type: 'code';
239
+ text: string;
240
+ copy?: boolean;
241
+ } | {
242
+ type: 'empty';
243
+ title: string;
244
+ text?: string;
245
+ action?: Button;
246
+ } | {
247
+ type: 'tabs';
248
+ param: string;
249
+ items: Array<{
250
+ id: string;
251
+ label: string;
252
+ }>;
253
+ active: string;
254
+ } | {
255
+ type: 'section';
256
+ title?: string;
257
+ description?: string;
258
+ blocks: Block[];
259
+ } | {
260
+ type: 'columns';
261
+ columns: Block[][];
262
+ };
263
+ export type BlockType = Block['type'];
264
+ export interface View {
265
+ /** Default: the page's label from the listing. */
266
+ title?: string;
267
+ description?: string;
268
+ /** Buttons next to the title (one primary at most). */
269
+ actions?: Button[];
270
+ blocks: Block[];
271
+ /**
272
+ * 5 to 60: while the page is open and the browser tab is visible, usebecky asks for the page again every this many
273
+ * seconds (an ordinary ui.render request). It waits while a form on the page has unsaved input or a dialog is open,
274
+ * and stops after 30 minutes, or as soon as an answer leaves refresh_seconds out.
275
+ */
276
+ refresh_seconds?: number;
277
+ }
278
+ /** What an action answers. `{}`: done, show the page again. */
279
+ export interface ActionResult {
280
+ /** Show this instead of asking for the page again. */
281
+ view?: View;
282
+ /** A short confirmation, like "Saved." */
283
+ toast?: string;
284
+ /** A form's problems, by field key: shown under the fields, nothing else changes. */
285
+ errors?: Record<string, string>;
286
+ /** Go to another page (or the same one with other params). */
287
+ go?: {
288
+ page: string;
289
+ params?: UiParams;
290
+ };
291
+ }
292
+ /** trialing: in the free trial. active: paid. past_due: a payment failed and is being retried. canceled: ended. */
293
+ export type PlanStatus = 'trialing' | 'active' | 'past_due' | 'canceled';
294
+ /** A downgrade (or a removed plan's replacement) waiting for the end of the paid period. */
295
+ export interface NextPlan {
296
+ id: string;
297
+ name: string;
298
+ /** US cents a month, before tax. */
299
+ amount: number;
300
+ /** ISO 8601: when it takes over (the end of the current period). */
301
+ starts_at: string;
302
+ }
303
+ /** The discount code the install pays with (made in the Developer area → Discount codes), or null. */
304
+ export interface PlanDiscount {
305
+ /** Upper case, 3 to 30 letters, digits or dashes. */
306
+ code: string;
307
+ /** Percent off (1 to 100), or */
308
+ percent_off?: number;
309
+ /** US cents off each discounted payment. */
310
+ amount_off?: number;
311
+ /** once: the next payment; repeating: each payment until ends_at; forever: every payment. */
312
+ duration: 'once' | 'repeating' | 'forever';
313
+ /** ISO 8601. once: the payment it reduces (after the trial, if any); repeating: when its months are over; forever: null. */
314
+ ends_at: string | null;
315
+ }
316
+ /**
317
+ * The install's price plan: one of the listing's pricing plans, or the single plan "monthly" (the listing's name) of a
318
+ * monthly listing. Null for free extensions. Installs in a test project get a simulated one (nothing is paid).
319
+ */
320
+ export interface Plan {
321
+ /** The plan's id in the listing ("monthly" for a monthly listing). */
322
+ id: string;
323
+ name: string;
324
+ /** What this install pays for it, in US cents a month, before tax. */
325
+ amount: number;
326
+ currency: 'usd';
327
+ status: PlanStatus;
328
+ /** ISO 8601 while in the free trial, else null. */
329
+ trial_ends_at: string | null;
330
+ /** ISO 8601: the end of the period paid for (or of the trial). */
331
+ current_period_end: string | null;
332
+ /** The customer disconnected it: it ends at current_period_end. */
333
+ cancel_at_period_end: boolean;
334
+ /** A downgrade waiting for the end of the period, else null. */
335
+ next_plan: NextPlan | null;
336
+ discount: PlanDiscount | null;
337
+ }
338
+ /** usebecky → the extension's `ui.url` (signed like webhooks, `usebecky-event-type: extension.ui`). */
339
+ export interface UiRequestBase {
340
+ id: string;
341
+ created_at: string;
342
+ /** The extension's slug. */
343
+ extension: string;
344
+ /** The install's id (the same as in webhooks and tokens). */
345
+ install: string;
346
+ project: {
347
+ ref: string;
348
+ name: string;
349
+ };
350
+ /** Who is looking: the pairwise `sub` (like the id_token), their role in the project's team, their language. */
351
+ user: {
352
+ sub: string;
353
+ role: 'owner' | 'admin' | 'developer' | 'viewer';
354
+ locale: string;
355
+ };
356
+ /** The page id (one of the listing's ui.pages, or "settings"). */
357
+ page: string;
358
+ params: UiParams;
359
+ /** The install's price plan; null for a free extension. */
360
+ plan: Plan | null;
361
+ /** Installs in a developer's test project. */
362
+ test?: true;
363
+ }
364
+ export interface UiRenderRequest extends UiRequestBase {
365
+ type: 'ui.render';
366
+ }
367
+ export interface UiActionRequest extends UiRequestBase {
368
+ type: 'ui.action';
369
+ action: {
370
+ id: string;
371
+ row?: string;
372
+ rows?: string[];
373
+ values?: Record<string, FieldValue>;
374
+ };
375
+ }
376
+ export type UiRequest = UiRenderRequest | UiActionRequest;
377
+ export declare const UI_EVENT_TYPE = "extension.ui";
378
+ export type Inline = {
379
+ t: 'text';
380
+ v: string;
381
+ } | {
382
+ t: 'bold';
383
+ v: string;
384
+ } | {
385
+ t: 'code';
386
+ v: string;
387
+ } | {
388
+ t: 'link';
389
+ v: string;
390
+ href: string;
391
+ };
392
+ /**
393
+ * The little markup text blocks and notices understand: **bold**, `code` and [label](https://…). Nothing nests and
394
+ * nothing else is markup; a link that isn't https stays plain text. The dashboard and the dev server draw these tokens,
395
+ * never HTML from the extension.
396
+ */
397
+ export declare function inlineTokens(s: string): Inline[];
398
+ export declare function isHttpsUrl(v: unknown): boolean;
399
+ export interface UiProblem {
400
+ /** Where, like "blocks.2.items.0.value". */
401
+ path: string;
402
+ message: string;
403
+ }
404
+ export type UiCheck<T> = {
405
+ ok: true;
406
+ value: T;
407
+ } | {
408
+ ok: false;
409
+ problem: UiProblem;
410
+ };
411
+ export interface ViewCheckOptions {
412
+ /** The pages a button or `go` may open (the listing's ui.pages ids and "settings"). Unknown pages are refused when given. */
413
+ pages?: readonly string[];
414
+ }
415
+ export declare function checkParams(path: string, v: unknown): UiParams;
416
+ /** A render answer: `{ "view": { … } }`. */
417
+ export declare function checkRenderAnswer(input: unknown, options?: ViewCheckOptions): UiCheck<View>;
418
+ /** A view on its own (the kit checks what a page handler returns). */
419
+ export declare function checkView(input: unknown, options?: ViewCheckOptions): UiCheck<View>;
420
+ /** An action's answer: any of view, toast, errors, go; `{}` shows the page again. */
421
+ export declare function checkActionAnswer(input: unknown, options?: ViewCheckOptions): UiCheck<ActionResult>;
422
+ /** The params usebecky sends (from the dashboard's address): a check usebecky makes before asking the extension. */
423
+ export declare function checkRequestParams(input: unknown): UiCheck<UiParams>;