@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.
- package/README.md +223 -2
- package/dist/accounts.d.ts +85 -0
- package/dist/accounts.js +149 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +9 -0
- package/dist/cli/run.d.ts +25 -0
- package/dist/cli/run.js +330 -0
- package/dist/cli/skill.d.ts +16 -0
- package/dist/cli/skill.js +106 -0
- package/dist/crypto.d.ts +12 -0
- package/dist/crypto.js +56 -0
- package/dist/dev/pages.d.ts +155 -0
- package/dist/dev/pages.js +243 -0
- package/dist/dev/plans.d.ts +45 -0
- package/dist/dev/plans.js +135 -0
- package/dist/dev/samples.d.ts +61 -0
- package/dist/dev/samples.js +191 -0
- package/dist/dev/server.d.ts +120 -0
- package/dist/dev/server.js +1657 -0
- package/dist/dev/tagging.d.ts +16 -0
- package/dist/dev/tagging.js +81 -0
- package/dist/dev/ui-render.d.ts +25 -0
- package/dist/dev/ui-render.js +256 -0
- package/dist/dev/wordmark.d.ts +1 -0
- package/dist/dev/wordmark.js +2 -0
- package/dist/errors.d.ts +98 -0
- package/dist/errors.js +110 -0
- package/dist/events.d.ts +92 -0
- package/dist/events.js +54 -0
- package/dist/extension.d.ts +214 -0
- package/dist/extension.js +497 -0
- package/dist/handlers.d.ts +39 -0
- package/dist/handlers.js +113 -0
- package/dist/identity.d.ts +99 -0
- package/dist/identity.js +134 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +17 -0
- package/dist/jwt.d.ts +62 -0
- package/dist/jwt.js +152 -0
- package/dist/manifest.d.ts +42 -0
- package/dist/manifest.js +785 -0
- package/dist/node.d.ts +10 -0
- package/dist/node.js +56 -0
- package/dist/pkce.d.ts +9 -0
- package/dist/pkce.js +16 -0
- package/dist/stores.d.ts +100 -0
- package/dist/stores.js +159 -0
- package/dist/types.d.ts +346 -0
- package/dist/types.js +70 -0
- package/dist/ui/handler.d.ts +66 -0
- package/dist/ui/handler.js +105 -0
- package/dist/ui/schema.d.ts +423 -0
- package/dist/ui/schema.js +666 -0
- package/dist/webhooks.d.ts +26 -0
- package/dist/webhooks.js +99 -0
- package/package.json +57 -4
- package/skill/usebecky-extension/SKILL.md +181 -0
- package/skill/usebecky-extension/references/accounts.md +125 -0
- package/skill/usebecky-extension/references/dev-server.md +102 -0
- package/skill/usebecky-extension/references/manifest.md +104 -0
- package/skill/usebecky-extension/references/oauth-and-tokens.md +179 -0
- package/skill/usebecky-extension/references/partner-api.md +87 -0
- package/skill/usebecky-extension/references/submit-and-pricing.md +31 -0
- package/skill/usebecky-extension/references/ui.md +172 -0
- package/skill/usebecky-extension/references/webhooks.md +97 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ExtensionPricing, ExtensionScope, ExtensionSettings } from '../types.ts';
|
|
2
|
+
import type { Plan } from '../ui/schema.ts';
|
|
3
|
+
export interface EventEnvelope {
|
|
4
|
+
id: string;
|
|
5
|
+
type: string;
|
|
6
|
+
created_at: string;
|
|
7
|
+
project: string;
|
|
8
|
+
data: Record<string, unknown>;
|
|
9
|
+
test?: true;
|
|
10
|
+
}
|
|
11
|
+
/** The install an event is about. */
|
|
12
|
+
export interface SampleInstall {
|
|
13
|
+
id: string;
|
|
14
|
+
/** The extension's slug. */
|
|
15
|
+
extension: string;
|
|
16
|
+
project: {
|
|
17
|
+
ref: string;
|
|
18
|
+
name: string;
|
|
19
|
+
};
|
|
20
|
+
scopes: ExtensionScope[];
|
|
21
|
+
/** Non-secret settings only. */
|
|
22
|
+
settings: ExtensionSettings;
|
|
23
|
+
/** Your account id (account.provision "url"). */
|
|
24
|
+
account_id?: string;
|
|
25
|
+
/** The install's price plan (null: a free extension). */
|
|
26
|
+
plan?: Plan | null;
|
|
27
|
+
}
|
|
28
|
+
/** What "Send test event" uses for the project and the install. */
|
|
29
|
+
export declare const SAMPLE_PROJECT: {
|
|
30
|
+
readonly ref: "sampleproject";
|
|
31
|
+
readonly name: "Sample project";
|
|
32
|
+
};
|
|
33
|
+
export declare const SAMPLE_INSTALLATION_ID = "00000000-0000-4000-8000-000000000000";
|
|
34
|
+
/** extension.installed / extension.uninstalled / extension.plan_changed data, in usebecky's key order. */
|
|
35
|
+
export declare function lifecycleData(type: 'extension.installed' | 'extension.uninstalled' | 'extension.plan_changed', install: SampleInstall, reason?: 'customer' | 'subscription_ended', previous?: Plan | null): Record<string, unknown>;
|
|
36
|
+
/** The plans of a listing: its pricing plans, or a monthly listing's one plan "monthly" named like the extension. */
|
|
37
|
+
export declare function pricingPlans(pricing: ExtensionPricing | undefined | null, name: string): Array<{
|
|
38
|
+
id: string;
|
|
39
|
+
name: string;
|
|
40
|
+
amount: number;
|
|
41
|
+
summary?: string;
|
|
42
|
+
}>;
|
|
43
|
+
/** The sample plan of "Send test event" (webhooks.ts samplePlan): the first plan, in a 7-day trial; null when free. */
|
|
44
|
+
export declare function samplePlan(pricing: ExtensionPricing | undefined | null, name: string): Plan | null;
|
|
45
|
+
/** `data` of a usebecky event as a project's activity sends it. */
|
|
46
|
+
export declare function activityData(type: string, project: string): Record<string, unknown>;
|
|
47
|
+
/** A delivery for one install, as usebecky's webhook queue sends it. `previous`: the plan before an extension.plan_changed. */
|
|
48
|
+
export declare function deliveryEvent(type: string, install: SampleInstall, opts?: {
|
|
49
|
+
reason?: 'customer' | 'subscription_ended';
|
|
50
|
+
previous?: Plan | null;
|
|
51
|
+
}): EventEnvelope;
|
|
52
|
+
/** Exactly what the Developer area's "Send test event" sends for this listing. */
|
|
53
|
+
export declare function testEvent(type: string, listing: {
|
|
54
|
+
slug: string;
|
|
55
|
+
scopes: ExtensionScope[];
|
|
56
|
+
name?: string;
|
|
57
|
+
pricing?: ExtensionPricing;
|
|
58
|
+
}, project?: {
|
|
59
|
+
ref: string;
|
|
60
|
+
name: string;
|
|
61
|
+
}): EventEnvelope;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// Events as usebecky sends them, for the dev server and `npx @usebecky/extension send <event>`:
|
|
2
|
+
//
|
|
3
|
+
// deliveryEvent() a real delivery for one install: { id: 'evt_<32 hex>', type, created_at, project, data }, the
|
|
4
|
+
// lifecycle data of packages/server/src/modules/extensions/webhooks.ts (sendLifecycleEvent);
|
|
5
|
+
// extension.installed and extension.plan_changed carry the install's plan
|
|
6
|
+
// testEvent() the Developer area's "Send test event" (webhooks.ts sendTestEvent): project 'sampleproject',
|
|
7
|
+
// `"test": true`, usebecky's own sample data
|
|
8
|
+
import { randomToken } from "../crypto.js";
|
|
9
|
+
/** What "Send test event" uses for the project and the install. */
|
|
10
|
+
export const SAMPLE_PROJECT = { ref: 'sampleproject', name: 'Sample project' };
|
|
11
|
+
export const SAMPLE_INSTALLATION_ID = '00000000-0000-4000-8000-000000000000';
|
|
12
|
+
const at = () => new Date().toISOString();
|
|
13
|
+
const hex = (bytes) => Array.from(globalThis.crypto.getRandomValues(new Uint8Array(bytes)), (b) => b.toString(16).padStart(2, '0')).join('');
|
|
14
|
+
const id = (prefix) => `${prefix}_${hex(8)}`;
|
|
15
|
+
/** extension.installed / extension.uninstalled / extension.plan_changed data, in usebecky's key order. */
|
|
16
|
+
export function lifecycleData(type, install, reason = 'customer', previous = null) {
|
|
17
|
+
const base = { extension: install.extension, installation_id: install.id, project: { ref: install.project.ref, name: install.project.name }, scopes: [...install.scopes] };
|
|
18
|
+
const account = install.account_id ? { account_id: install.account_id } : {};
|
|
19
|
+
if (type === 'extension.plan_changed')
|
|
20
|
+
return { ...base, previous: clone(previous), plan: clone(install.plan ?? null) };
|
|
21
|
+
return type === 'extension.installed' ? { ...base, settings: { ...install.settings }, ...account, plan: clone(install.plan ?? null) } : { ...base, reason, ...account };
|
|
22
|
+
}
|
|
23
|
+
const clone = (v) => (v === null || v === undefined ? v : structuredClone(v));
|
|
24
|
+
/** The plans of a listing: its pricing plans, or a monthly listing's one plan "monthly" named like the extension. */
|
|
25
|
+
export function pricingPlans(pricing, name) {
|
|
26
|
+
if (pricing?.model === 'plans')
|
|
27
|
+
return (pricing.plans ?? []).map((p) => ({ id: p.id, name: p.name, amount: Number(p.amount), ...(p.summary ? { summary: p.summary } : {}) }));
|
|
28
|
+
if (pricing?.model === 'monthly')
|
|
29
|
+
return [{ id: 'monthly', name, amount: Number(pricing.amount) || 0 }];
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
/** The sample plan of "Send test event" (webhooks.ts samplePlan): the first plan, in a 7-day trial; null when free. */
|
|
33
|
+
export function samplePlan(pricing, name) {
|
|
34
|
+
const first = pricingPlans(pricing, name)[0];
|
|
35
|
+
if (!first)
|
|
36
|
+
return null;
|
|
37
|
+
const trialEnds = new Date(Date.now() + 7 * 86_400_000).toISOString();
|
|
38
|
+
return { id: first.id, name: first.name, amount: first.amount, currency: 'usd', status: 'trialing', trial_ends_at: trialEnds, current_period_end: trialEnds, cancel_at_period_end: false, next_plan: null, discount: null };
|
|
39
|
+
}
|
|
40
|
+
// ---- Realistic data for usebecky's own events (what a project's activity sends) ---------------------
|
|
41
|
+
const user = () => ({
|
|
42
|
+
id: '5f8c2a1e-3b7d-4e6f-9a01-2c3d4e5f6a7b',
|
|
43
|
+
email: 'ada@example.com',
|
|
44
|
+
email_confirmed_at: at(),
|
|
45
|
+
phone: null,
|
|
46
|
+
app_metadata: { provider: 'email' },
|
|
47
|
+
user_metadata: { name: 'Ada Lovelace' },
|
|
48
|
+
created_at: at(),
|
|
49
|
+
updated_at: at(),
|
|
50
|
+
});
|
|
51
|
+
const subscription = (status) => ({
|
|
52
|
+
id: id('sub'),
|
|
53
|
+
user_id: user().id,
|
|
54
|
+
product_key: 'pro',
|
|
55
|
+
status,
|
|
56
|
+
source: 'stripe',
|
|
57
|
+
current_period_end: new Date(Date.now() + 30 * 86400_000).toISOString(),
|
|
58
|
+
cancel_at_period_end: false,
|
|
59
|
+
created_at: at(),
|
|
60
|
+
});
|
|
61
|
+
const email = (status) => ({ email: { id: id('em'), kind: 'welcome', to: 'ada@example.com', subject: 'Welcome to Acme Shop', status, created_at: at() }, user_id: user().id });
|
|
62
|
+
function quota(type, project) {
|
|
63
|
+
const exceeded = type === 'quota.exceeded';
|
|
64
|
+
const month = new Date().toISOString().slice(0, 7);
|
|
65
|
+
return {
|
|
66
|
+
quota: 'emails_per_month',
|
|
67
|
+
label: 'Emails per month',
|
|
68
|
+
level: exceeded ? 100 : 80,
|
|
69
|
+
used: exceeded ? 3000 : 2400,
|
|
70
|
+
limit: 3000,
|
|
71
|
+
percent: exceeded ? 100 : 80,
|
|
72
|
+
plan: 'free',
|
|
73
|
+
period: month,
|
|
74
|
+
upgrade_url: `https://app.usebecky.com/project/${project}/settings/usage?upgrade=emails_per_month`,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** `data` of a usebecky event as a project's activity sends it. */
|
|
78
|
+
export function activityData(type, project) {
|
|
79
|
+
switch (type) {
|
|
80
|
+
case 'test.ping':
|
|
81
|
+
return { message: 'Hello from usebecky! Your endpoint works.' };
|
|
82
|
+
case 'user.created':
|
|
83
|
+
case 'user.updated':
|
|
84
|
+
return { user: user() };
|
|
85
|
+
case 'user.deleted':
|
|
86
|
+
return { user: { id: user().id, email: 'ada@example.com' } };
|
|
87
|
+
case 'user.signed_in':
|
|
88
|
+
return { user: user(), method: 'password' };
|
|
89
|
+
case 'subscription.created':
|
|
90
|
+
case 'subscription.updated':
|
|
91
|
+
return { user_id: user().id, subscription: subscription('active') };
|
|
92
|
+
case 'subscription.canceled':
|
|
93
|
+
return { user_id: user().id, subscription: subscription('canceled') };
|
|
94
|
+
case 'subscription.trial_will_end':
|
|
95
|
+
return { user_id: user().id, subscription: subscription('trialing') };
|
|
96
|
+
case 'subscription.gifted':
|
|
97
|
+
case 'subscription.gift_updated':
|
|
98
|
+
case 'subscription.gift_ended':
|
|
99
|
+
return { user_id: user().id, subscription: { ...subscription('active'), source: 'gift' }, gift: { active: type !== 'subscription.gift_ended', starts_at: at(), ends_at: null, note: 'Thanks for the feedback', gifted_by: null, ended_at: null, end_reason: null } };
|
|
100
|
+
case 'purchase.completed':
|
|
101
|
+
case 'purchase.refunded':
|
|
102
|
+
return { user_id: user().id, purchase: { id: id('pur'), product_key: 'lifetime', amount: 4900, currency: 'usd', status: type === 'purchase.refunded' ? 'refunded' : 'paid', created_at: at() } };
|
|
103
|
+
case 'order.paid':
|
|
104
|
+
case 'order.refunded':
|
|
105
|
+
case 'order.canceled':
|
|
106
|
+
case 'order.shipped':
|
|
107
|
+
case 'order.delivered': {
|
|
108
|
+
const status = type === 'order.refunded' ? 'refunded' : type === 'order.canceled' ? 'canceled' : 'paid';
|
|
109
|
+
// order.shipped / order.delivered: the team marked it (Dashboard → Orders, or PATCH /payments/v1/orders/:id).
|
|
110
|
+
const sent = type === 'order.shipped' || type === 'order.delivered';
|
|
111
|
+
const order = {
|
|
112
|
+
id: id('ord'), number: 1001, status, email: 'ada@example.com', name: 'Ada Lovelace', currency: 'usd',
|
|
113
|
+
subtotal: 3800, discount: 0, shipping: 0, tax: 0, total: 3800, amount_refunded: status === 'refunded' ? 3800 : 0,
|
|
114
|
+
fulfillment: type === 'order.delivered' ? 'delivered' : sent ? 'shipped' : 'unfulfilled',
|
|
115
|
+
carrier: sent ? 'DHL' : null, tracking_number: sent ? '00340434161094042557' : null,
|
|
116
|
+
tracking_url: sent ? 'https://www.dhl.com/track?id=00340434161094042557' : null,
|
|
117
|
+
shipped_at: sent ? at() : null, delivered_at: type === 'order.delivered' ? at() : null,
|
|
118
|
+
items: [
|
|
119
|
+
{ product_key: 'mug', price_key: 'mug', name: 'Mug', unit_amount: 1400, quantity: 2, amount: 2800 },
|
|
120
|
+
{ product_key: 'sticker', price_key: 'sticker', name: 'Sticker pack', unit_amount: 1000, quantity: 1, amount: 1000 },
|
|
121
|
+
],
|
|
122
|
+
metadata: {}, livemode: false, created_at: at(), paid_at: status === 'canceled' ? null : at(), user_id: null,
|
|
123
|
+
};
|
|
124
|
+
return { user_id: null, order, ...(status === 'refunded' ? { amount_refunded: 3800, amount: 3800 } : {}) };
|
|
125
|
+
}
|
|
126
|
+
case 'payment.failed':
|
|
127
|
+
return { user_id: user().id, payment: { id: id('in'), amount: 1900, currency: 'usd', reason: 'card_declined', next_attempt_at: new Date(Date.now() + 3 * 86400_000).toISOString() } };
|
|
128
|
+
case 'payment.disputed':
|
|
129
|
+
case 'payment.dispute_closed':
|
|
130
|
+
case 'payment.fraud_warning':
|
|
131
|
+
return { user_id: user().id, dispute: { id: id('dp'), amount: 1900, currency: 'usd', reason: 'fraudulent', status: type === 'payment.dispute_closed' ? 'won' : 'needs_response', created_at: at() } };
|
|
132
|
+
case 'storage.object.created':
|
|
133
|
+
case 'storage.object.deleted':
|
|
134
|
+
return { bucket: 'avatars', object: { name: `${user().id}/avatar.png`, size: 48213, content_type: 'image/png', created_at: at() } };
|
|
135
|
+
case 'form.submitted':
|
|
136
|
+
return {
|
|
137
|
+
form: { id: id('f'), key: 'contact', name: 'Contact form' },
|
|
138
|
+
submission: { id: id('sub'), data: { name: 'Ada Lovelace', email: 'ada@example.com', message: 'Do you ship to Austria?' }, extra: {}, submitter_email: 'ada@example.com', page_url: 'https://shop.example.com/contact', created_at: at() },
|
|
139
|
+
};
|
|
140
|
+
case 'email.sent':
|
|
141
|
+
case 'email.delivered':
|
|
142
|
+
case 'email.delayed':
|
|
143
|
+
return email(type.slice(6));
|
|
144
|
+
case 'email.bounced':
|
|
145
|
+
case 'email.complained':
|
|
146
|
+
case 'email.suppressed':
|
|
147
|
+
case 'email.failed':
|
|
148
|
+
return { ...email(type.slice(6)), reason: type === 'email.bounced' ? 'The mailbox does not exist.' : null };
|
|
149
|
+
case 'quota.warning':
|
|
150
|
+
case 'quota.exceeded':
|
|
151
|
+
return quota(type, project);
|
|
152
|
+
case 'newsletter.subscribed':
|
|
153
|
+
return { subscriber: { id: id('ns'), email: 'ada@example.com', status: 'subscribed', created_at: at() } };
|
|
154
|
+
case 'newsletter.unsubscribed':
|
|
155
|
+
return { subscriber: { id: id('ns'), email: 'ada@example.com', status: 'unsubscribed', created_at: at() }, reason: 'link', campaign_id: null };
|
|
156
|
+
case 'job.failed':
|
|
157
|
+
return { job: { id: id('job'), name: 'Nightly cleanup', type: 'http' }, run: { id: id('run'), status: 'failed', trigger: 'schedule', attempt: 3, error: 'Timed out after 10 s', started_at: at(), finished_at: at() } };
|
|
158
|
+
case 'function.failed':
|
|
159
|
+
return {
|
|
160
|
+
function: { id: id('fn'), name: 'send-receipts', version: 3 },
|
|
161
|
+
invocation: { id: id('inv'), trigger: 'http', status: 'failed', error: 'TypeError: Cannot read properties of undefined', duration_ms: 182, http_status: 500 },
|
|
162
|
+
failures_since_last_event: 0,
|
|
163
|
+
};
|
|
164
|
+
case 'certificate.renewed':
|
|
165
|
+
return { certificate: { id: id('cert'), domain: 'mugshop.com', names: ['mugshop.com', 'www.mugshop.com'], serial: '04a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7', not_before: '2026-11-25T09:00:00.000Z', not_after: '2027-02-23T09:00:00.000Z' } };
|
|
166
|
+
default:
|
|
167
|
+
return {};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/** A delivery for one install, as usebecky's webhook queue sends it. `previous`: the plan before an extension.plan_changed. */
|
|
171
|
+
export function deliveryEvent(type, install, opts = {}) {
|
|
172
|
+
const data = type === 'extension.installed' || type === 'extension.uninstalled' || type === 'extension.plan_changed' ? lifecycleData(type, install, opts.reason, opts.previous ?? null) : activityData(type, install.project.ref);
|
|
173
|
+
return { id: `evt_${hex(16)}`, type, created_at: at(), project: install.project.ref, data };
|
|
174
|
+
}
|
|
175
|
+
/** usebecky's sample data for "Send test event" (packages/server/src/modules/extensions/webhooks.ts SAMPLE_DATA). */
|
|
176
|
+
const TEST_SAMPLE_DATA = {
|
|
177
|
+
'user.created': { user: { id: '00000000-0000-4000-8000-000000000001', email: 'ada@example.com', created_at: '2026-01-01T12:00:00.000Z' } },
|
|
178
|
+
'purchase.completed': { purchase: { id: 'pur_sample', amount: 1900, currency: 'usd', product: 'Sample product' } },
|
|
179
|
+
'subscription.created': { subscription: { id: 'sub_sample', status: 'active', product: 'Sample plan', amount: 900, currency: 'usd', interval: 'month' } },
|
|
180
|
+
'form.submitted': { form: { id: 'frm_sample', name: 'Contact' }, submission: { id: 'sub_sample', fields: { email: 'ada@example.com', message: 'Hello!' } } },
|
|
181
|
+
};
|
|
182
|
+
/** Exactly what the Developer area's "Send test event" sends for this listing. */
|
|
183
|
+
export function testEvent(type, listing, project = SAMPLE_PROJECT) {
|
|
184
|
+
const isLifecycle = type === 'extension.installed' || type === 'extension.uninstalled' || type === 'extension.plan_changed';
|
|
185
|
+
const plan = samplePlan(listing.pricing, listing.name ?? listing.slug);
|
|
186
|
+
const lifecycle = type === 'extension.uninstalled' ? { reason: 'customer' } : type === 'extension.plan_changed' ? { previous: plan, plan: plan ? { ...plan, status: 'active', trial_ends_at: null } : null } : { settings: {}, plan };
|
|
187
|
+
const data = isLifecycle
|
|
188
|
+
? { extension: listing.slug, installation_id: SAMPLE_INSTALLATION_ID, project: { ref: project.ref, name: project.name }, scopes: [...listing.scopes], ...lifecycle }
|
|
189
|
+
: (TEST_SAMPLE_DATA[type] ?? { sample: true });
|
|
190
|
+
return { id: `evt_test_${randomToken(12)}`, type, created_at: at(), project: project.ref, data: structuredClone(data), test: true };
|
|
191
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { type ExtensionCapability, type ExtensionManifest, type Installation } from '../types.ts';
|
|
2
|
+
import type { Plan } from '../ui/schema.ts';
|
|
3
|
+
/** Test credentials the dev server accepts (and `npm run dev` passes to your extension). Real prefixes, never real values. */
|
|
4
|
+
export declare const DEV_CREDENTIALS: {
|
|
5
|
+
readonly clientId: "ub_ci_DevServerTestClient00000";
|
|
6
|
+
readonly clientSecret: "ub_cs_DevServerTestSecretNeverUseInProduction0";
|
|
7
|
+
readonly webhookSecret: "whsec_DevServerWebhookSecretNotReal000";
|
|
8
|
+
};
|
|
9
|
+
export declare const DEV_PORT = 4400;
|
|
10
|
+
/** A fake project, with what GET /extensions/v1/project returns about it. */
|
|
11
|
+
export interface DevProject {
|
|
12
|
+
ref: string;
|
|
13
|
+
name: string;
|
|
14
|
+
plan: 'free' | 'pro' | 'business';
|
|
15
|
+
api_url: string;
|
|
16
|
+
publishable_key: string;
|
|
17
|
+
allowed_hosts: string[];
|
|
18
|
+
}
|
|
19
|
+
/** The pretend person who installs on the dev server (the signed-in usebecky account). */
|
|
20
|
+
export declare const DEV_PERSON: {
|
|
21
|
+
name: string;
|
|
22
|
+
email: string;
|
|
23
|
+
email_verified: boolean;
|
|
24
|
+
role: "owner";
|
|
25
|
+
};
|
|
26
|
+
export declare const DEV_PROJECTS: ReadonlyArray<DevProject>;
|
|
27
|
+
export interface DevServerOptions {
|
|
28
|
+
/** Default 4400; 0 picks a free port. */
|
|
29
|
+
port?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Default 127.0.0.1 (only this computer). It answers requests addressed to localhost, 127.0.0.1, [::1] and this host;
|
|
32
|
+
* bound to every address (0.0.0.0 or ::), also to any IP address.
|
|
33
|
+
*/
|
|
34
|
+
host?: string;
|
|
35
|
+
/** More host names to answer to, e.g. host.docker.internal (with `host: '0.0.0.0'`). Every other name is refused. */
|
|
36
|
+
allowedHosts?: string[];
|
|
37
|
+
/**
|
|
38
|
+
* Behave like a test project (a developer's free project for trying extensions): GET /installation says
|
|
39
|
+
* `test: true` and every event and provision request carries `"test": true`. Default false: a real project.
|
|
40
|
+
*/
|
|
41
|
+
testProject?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* The capabilities usebecky set on your extension (only usebecky sets them, after review; the manifest's are
|
|
44
|
+
* ignored). `['sgtm_forwarding']` makes PUT /extensions/v1/installation/settings work; without it, it answers
|
|
45
|
+
* `403 capability_required` like usebecky. CLI: --capability sgtm_forwarding.
|
|
46
|
+
*/
|
|
47
|
+
capabilities?: ExtensionCapability[];
|
|
48
|
+
/** The parsed usebecky-extension.json. Or `manifestPath`. */
|
|
49
|
+
manifest?: ExtensionManifest | Record<string, unknown> | null;
|
|
50
|
+
/** Default: usebecky-extension.json in the current folder, if it exists. */
|
|
51
|
+
manifestPath?: string;
|
|
52
|
+
/** Your extension running locally, e.g. http://localhost:3000. The manifest's addresses are mapped onto it. */
|
|
53
|
+
appUrl?: string;
|
|
54
|
+
clientId?: string;
|
|
55
|
+
clientSecret?: string;
|
|
56
|
+
webhookSecret?: string;
|
|
57
|
+
/** Access token lifetime in seconds (default 3600, like usebecky). Lower it to watch refreshes happen. */
|
|
58
|
+
accessTokenTtl?: number;
|
|
59
|
+
/** Partner API requests per minute per install (default 300, like usebecky). */
|
|
60
|
+
rateLimitPerMinute?: number;
|
|
61
|
+
/** One line per thing that happened (default: console.log). Tokens and secrets are never logged. */
|
|
62
|
+
log?: (line: string) => void;
|
|
63
|
+
fetch?: typeof fetch;
|
|
64
|
+
}
|
|
65
|
+
export interface DevDelivery {
|
|
66
|
+
type: string;
|
|
67
|
+
url: string;
|
|
68
|
+
status: number | null;
|
|
69
|
+
ms: number;
|
|
70
|
+
error?: string;
|
|
71
|
+
eventId?: string;
|
|
72
|
+
}
|
|
73
|
+
/** An install as GET /extensions/v1/installation shows it, plus its state. */
|
|
74
|
+
export type DevInstallation = Installation & {
|
|
75
|
+
status: 'active' | 'error';
|
|
76
|
+
connected: boolean;
|
|
77
|
+
};
|
|
78
|
+
export interface DevServer {
|
|
79
|
+
url: string;
|
|
80
|
+
credentials: {
|
|
81
|
+
clientId: string;
|
|
82
|
+
clientSecret: string;
|
|
83
|
+
webhookSecret: string;
|
|
84
|
+
};
|
|
85
|
+
/** Current installs (one per project). */
|
|
86
|
+
installs(): DevInstallation[];
|
|
87
|
+
/**
|
|
88
|
+
* POST a signed event of `type` to the webhook URL. For an installed project (default: the first install) it is a
|
|
89
|
+
* delivery for that install; otherwise the Developer area's test event (`"test": true`, project `sampleproject`).
|
|
90
|
+
*/
|
|
91
|
+
sendEvent(type: string, project?: string): Promise<DevDelivery>;
|
|
92
|
+
/** Every webhook sent so far, newest last. */
|
|
93
|
+
deliveries: DevDelivery[];
|
|
94
|
+
/** The issuer of its id_tokens and launch tokens (its own URL); the JWKS is at `<issuer>/.well-known/jwks.json`. */
|
|
95
|
+
issuer: string;
|
|
96
|
+
/**
|
|
97
|
+
* "Open in <name>" for an install (default: the first): your sso_url with a fresh launch token (60 seconds, single
|
|
98
|
+
* use), mapped onto `appUrl`. Throws when the listing has no account.sso_url or nothing is installed.
|
|
99
|
+
*/
|
|
100
|
+
launchUrl(project?: string): Promise<string>;
|
|
101
|
+
/**
|
|
102
|
+
* The dev panel, from code: set an install's plan (default: the first install) with the fields of POST /dev/plan
|
|
103
|
+
* (`plan`, `status`, `trial_days`, `next_plan`, `cancel_at_period_end`, `discount_code` with `discount_percent` or
|
|
104
|
+
* `discount_amount` and `discount_duration`, or `renew: true`). extension.plan_changed is sent like usebecky sends it.
|
|
105
|
+
*/
|
|
106
|
+
setPlan(project: string | undefined, patch: Record<string, unknown>): Promise<{
|
|
107
|
+
plan: Plan | null;
|
|
108
|
+
sent: DevDelivery | null;
|
|
109
|
+
}>;
|
|
110
|
+
/** usebecky's plan dialog: "Change plan" to `plan` (upgrade now, downgrade at the period end, in the trial now). */
|
|
111
|
+
changePlan(project: string | undefined, plan: string): Promise<{
|
|
112
|
+
plan: Plan | null;
|
|
113
|
+
effect: 'now' | 'period_end' | 'undone' | 'none';
|
|
114
|
+
sent: DevDelivery | null;
|
|
115
|
+
}>;
|
|
116
|
+
close(): Promise<void>;
|
|
117
|
+
}
|
|
118
|
+
/** Map an address from the manifest onto the local app: same path and query, the app's origin. */
|
|
119
|
+
export declare function mapToApp(url: string | undefined, appUrl: string | undefined): string | null;
|
|
120
|
+
export declare function startDevServer(options?: DevServerOptions): Promise<DevServer>;
|