anhedral 0.15.0 → 0.16.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 +29 -38
- package/assets/stack/ai-schema.ts.txt +5 -0
- package/assets/stack/ai.ts.txt +30 -0
- package/assets/stack/api-index.ts.txt +15 -0
- package/assets/stack/auth-features.ts.txt +4 -0
- package/assets/stack/auth-journal.json.txt +13 -0
- package/assets/stack/auth-migration.sql.txt +53 -0
- package/assets/stack/auth-routes.ts.txt +11 -0
- package/assets/stack/auth-schema.ts.txt +64 -0
- package/assets/stack/auth-snapshot.json.txt +346 -0
- package/assets/stack/auth.ts.txt +32 -0
- package/assets/stack/billing-mode.ts.txt +8 -0
- package/assets/stack/billing-schema.ts.txt +11 -0
- package/assets/stack/desktop.rs.txt +21 -0
- package/assets/stack/entitlement-guard.ts.txt +32 -0
- package/assets/stack/entitlements.ts.txt +8 -0
- package/assets/stack/events-schema.ts.txt +12 -0
- package/assets/stack/events.ts.txt +59 -0
- package/assets/stack/mobile-auth.ts.txt +25 -0
- package/assets/stack/mobile-billing.tsx.txt +63 -0
- package/assets/stack/mobile-session.tsx.txt +83 -0
- package/assets/stack/native-button.tsx.txt +108 -0
- package/assets/stack/native-global.css.txt +4 -0
- package/assets/stack/native-lib-utils.ts.txt +5 -0
- package/assets/stack/native-metro.config.js.txt +6 -0
- package/assets/stack/native-nativewind-env.d.ts.txt +1 -0
- package/assets/stack/native-tailwind.config.js.txt +73 -0
- package/assets/stack/native-text.tsx.txt +89 -0
- package/assets/stack/purchases.ts.txt +65 -0
- package/assets/stack/revenuecat.ts.txt +88 -0
- package/assets/stack/rtc-schema.ts.txt +10 -0
- package/assets/stack/rtc.ts.txt +122 -0
- package/assets/stack/security.ts.txt +31 -0
- package/assets/stack/storage.ts.txt +36 -0
- package/assets/stack/stripe.ts.txt +126 -0
- package/assets/stack/web-sign-in.tsx.txt +51 -0
- package/assets/ui/LICENSE.react-native-reusables +21 -0
- package/assets/ui/UPSTREAM.json +7 -1
- package/assets/ui/catalog.json +891 -0
- package/assets/ui/extensions/registry.json +6 -0
- package/assets/ui/native/_controls.tsx +521 -0
- package/assets/ui/native/_core.tsx +118 -0
- package/assets/ui/native/_data.tsx +200 -0
- package/assets/ui/native/_display.tsx +453 -0
- package/assets/ui/native/_feedback.tsx +242 -0
- package/assets/ui/native/_legacy-dialog.tsx +38 -0
- package/assets/ui/native/_motion.tsx +520 -0
- package/assets/ui/native/_overlay.tsx +402 -0
- package/assets/ui/native/_selection.tsx +366 -0
- package/assets/ui/native/accordion.tsx +1 -0
- package/assets/ui/native/alert-dialog.tsx +11 -0
- package/assets/ui/native/alert.tsx +1 -0
- package/assets/ui/native/aspect-ratio.tsx +1 -0
- package/assets/ui/native/attachment.tsx +8 -0
- package/assets/ui/native/avatar.tsx +8 -0
- package/assets/ui/native/badge.tsx +1 -0
- package/assets/ui/native/breadcrumb.tsx +9 -0
- package/assets/ui/native/bubble.tsx +1 -0
- package/assets/ui/native/button-group.tsx +1 -0
- package/assets/ui/native/button.tsx +2 -1
- package/assets/ui/native/calendar.tsx +170 -0
- package/assets/ui/native/card.tsx +16 -5
- package/assets/ui/native/carousel.tsx +1 -0
- package/assets/ui/native/chart.tsx +193 -0
- package/assets/ui/native/checkbox.tsx +1 -0
- package/assets/ui/native/code-block.tsx +137 -0
- package/assets/ui/native/collapsible.tsx +1 -0
- package/assets/ui/native/combobox.tsx +1 -0
- package/assets/ui/native/command.tsx +11 -0
- package/assets/ui/native/context-menu.tsx +16 -0
- package/assets/ui/native/data-table.tsx +1 -0
- package/assets/ui/native/date-picker.tsx +43 -0
- package/assets/ui/native/dialog.tsx +14 -74
- package/assets/ui/native/direction.tsx +1 -0
- package/assets/ui/native/drawer.tsx +10 -0
- package/assets/ui/native/dropdown-menu.tsx +16 -0
- package/assets/ui/native/empty.tsx +8 -0
- package/assets/ui/native/field.tsx +13 -0
- package/assets/ui/native/hover-card.tsx +1 -0
- package/assets/ui/native/input-group.tsx +8 -0
- package/assets/ui/native/input-otp.tsx +1 -0
- package/assets/ui/native/input.tsx +2 -1
- package/assets/ui/native/item.tsx +12 -0
- package/assets/ui/native/kbd.tsx +1 -0
- package/assets/ui/native/marker.tsx +1 -0
- package/assets/ui/native/menubar.tsx +17 -0
- package/assets/ui/native/message-scroller.tsx +6 -0
- package/assets/ui/native/message.tsx +10 -0
- package/assets/ui/native/native-select.tsx +1 -0
- package/assets/ui/native/navigation-menu.tsx +10 -0
- package/assets/ui/native/pagination.tsx +9 -0
- package/assets/ui/native/popover.tsx +1 -0
- package/assets/ui/native/progress.tsx +1 -0
- package/assets/ui/native/questionnaire.tsx +130 -0
- package/assets/ui/native/radio-group.tsx +1 -0
- package/assets/ui/native/registry.json +1103 -0
- package/assets/ui/native/resizable.tsx +1 -0
- package/assets/ui/native/scroll-area.tsx +1 -0
- package/assets/ui/native/select.tsx +11 -0
- package/assets/ui/native/separator.tsx +1 -0
- package/assets/ui/native/sheet.tsx +10 -0
- package/assets/ui/native/sidebar.tsx +22 -0
- package/assets/ui/native/skeleton.tsx +1 -0
- package/assets/ui/native/slider.tsx +1 -0
- package/assets/ui/native/spinner.tsx +1 -0
- package/assets/ui/native/switch.tsx +1 -0
- package/assets/ui/native/table.tsx +10 -0
- package/assets/ui/native/tabs.tsx +1 -0
- package/assets/ui/native/textarea.tsx +1 -0
- package/assets/ui/native/toast.tsx +11 -0
- package/assets/ui/native/toggle-group.tsx +1 -0
- package/assets/ui/native/toggle.tsx +1 -0
- package/assets/ui/native/tooltip.tsx +1 -0
- package/assets/ui/native/trace.tsx +20 -0
- package/assets/ui/native/typography.tsx +15 -0
- package/dist/bin.js +7 -12
- package/dist/capabilities.d.ts +4 -33
- package/dist/capabilities.js +2 -66
- package/dist/capability-catalog.d.ts +83 -0
- package/dist/capability-catalog.js +121 -0
- package/dist/capability-command.d.ts +3 -0
- package/dist/capability-command.js +188 -0
- package/dist/capability-editor.d.ts +17 -0
- package/dist/capability-editor.js +97 -0
- package/dist/capability-recipes.d.ts +4 -0
- package/dist/capability-recipes.js +520 -0
- package/dist/capability-references.d.ts +4 -0
- package/dist/capability-references.js +7 -0
- package/dist/cli-commands.d.ts +1 -2
- package/dist/cli-commands.js +10 -104
- package/dist/cli-output.d.ts +1 -2
- package/dist/cli-output.js +6 -251
- package/dist/command-schema.js +39 -322
- package/dist/dependencies.d.ts +29 -6
- package/dist/dependencies.js +61 -14
- package/dist/index.d.ts +1 -42
- package/dist/index.js +1 -27
- package/dist/platforms/mobile.js +1 -20
- package/dist/platforms/web.d.ts +1 -1
- package/dist/platforms/web.js +27 -75
- package/dist/project-config.d.ts +2 -13
- package/dist/project-config.js +10 -82
- package/dist/registry/options.js +1 -5
- package/dist/registry/resolve.d.ts +1 -1
- package/dist/registry/resolve.js +2 -10
- package/dist/registry/usage.js +3 -9
- package/dist/scaffold/backend.js +0 -3
- package/dist/scaffold/database.js +2 -1
- package/dist/scaffold/documentation.js +82 -20
- package/dist/scaffold/expo-runtime.js +3 -4
- package/dist/scaffold/native-ui.js +12 -7
- package/dist/scaffold/stack-documentation.js +1 -1
- package/dist/scaffold/storage.d.ts +2 -0
- package/dist/scaffold/storage.js +21 -0
- package/dist/scaffold/workspace.js +26 -21
- package/dist/stack-registry.d.ts +2 -8
- package/dist/stack-registry.js +11 -87
- package/dist/standard.js +1 -11
- package/dist/ui-catalog.d.ts +26 -0
- package/dist/ui-catalog.js +31 -0
- package/dist/ui-command.d.ts +3 -0
- package/dist/ui-command.js +219 -0
- package/dist/ui-project.d.ts +22 -0
- package/dist/ui-project.js +110 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/anhedral-stack.md +4 -20
- package/docs/capabilities.md +110 -0
- package/docs/native-ui.md +102 -0
- package/docs/software-factory.md +16 -44
- package/docs/stack-standard.md +11 -60
- package/docs/ui.md +33 -0
- package/docs/verification.md +191 -0
- package/package.json +19 -18
- package/dist/access.d.ts +0 -10
- package/dist/access.js +0 -93
- package/dist/auth-schema-snapshot.d.ts +0 -346
- package/dist/auth-schema-snapshot.js +0 -347
- package/dist/auth-schema.d.ts +0 -1
- package/dist/auth-schema.js +0 -57
- package/dist/capability-contract.d.ts +0 -47
- package/dist/capability-contract.js +0 -129
- package/dist/catalog-model.d.ts +0 -24
- package/dist/catalog-model.js +0 -1
- package/dist/catalog-registration.d.ts +0 -16
- package/dist/catalog-registration.js +0 -22
- package/dist/catalog-snapshot.d.ts +0 -5
- package/dist/catalog-snapshot.js +0 -97
- package/dist/cli-delivery.d.ts +0 -3
- package/dist/cli-delivery.js +0 -112
- package/dist/cloudflare.d.ts +0 -25
- package/dist/cloudflare.js +0 -226
- package/dist/delivery-evidence.d.ts +0 -62
- package/dist/delivery-evidence.js +0 -157
- package/dist/delivery.d.ts +0 -82
- package/dist/delivery.js +0 -489
- package/dist/inspector-model.d.ts +0 -123
- package/dist/inspector-model.js +0 -1
- package/dist/integration-service-readers.d.ts +0 -12
- package/dist/integration-service-readers.js +0 -92
- package/dist/lifecycle-model.d.ts +0 -15
- package/dist/lifecycle-model.js +0 -20
- package/dist/lifecycle.d.ts +0 -11
- package/dist/lifecycle.js +0 -91
- package/dist/management.d.ts +0 -3
- package/dist/management.js +0 -47
- package/dist/mobile-delivery.d.ts +0 -77
- package/dist/mobile-delivery.js +0 -370
- package/dist/project-catalog.d.ts +0 -41
- package/dist/project-catalog.js +0 -288
- package/dist/project-inspector.d.ts +0 -4
- package/dist/project-inspector.js +0 -671
- package/dist/project-lifecycle.d.ts +0 -25
- package/dist/project-lifecycle.js +0 -57
- package/dist/project-state.d.ts +0 -47
- package/dist/project-state.js +0 -480
- package/dist/provider-auth.d.ts +0 -41
- package/dist/provider-auth.js +0 -180
- package/dist/provider-readiness.d.ts +0 -30
- package/dist/provider-readiness.js +0 -85
- package/dist/providers/adapters.d.ts +0 -17
- package/dist/providers/adapters.js +0 -103
- package/dist/providers/api.d.ts +0 -29
- package/dist/providers/api.js +0 -253
- package/dist/providers/config.d.ts +0 -15
- package/dist/providers/config.js +0 -136
- package/dist/providers/definitions.d.ts +0 -115
- package/dist/providers/definitions.js +0 -42
- package/dist/providers/provision.d.ts +0 -24
- package/dist/providers/provision.js +0 -76
- package/dist/providers/receipts.d.ts +0 -20
- package/dist/providers/receipts.js +0 -56
- package/dist/providers/recovery-verification.d.ts +0 -7
- package/dist/providers/recovery-verification.js +0 -52
- package/dist/providers/recovery.d.ts +0 -30
- package/dist/providers/recovery.js +0 -34
- package/dist/providers/runtime.d.ts +0 -10
- package/dist/providers/runtime.js +0 -234
- package/dist/providers/schema.d.ts +0 -28
- package/dist/providers/schema.js +0 -49
- package/dist/providers/state.d.ts +0 -55
- package/dist/providers/state.js +0 -283
- package/dist/provision.d.ts +0 -47
- package/dist/provision.js +0 -208
- package/dist/r2-service-data.d.ts +0 -2
- package/dist/r2-service-data.js +0 -136
- package/dist/readiness.d.ts +0 -23
- package/dist/readiness.js +0 -117
- package/dist/registry/add.d.ts +0 -24
- package/dist/registry/add.js +0 -210
- package/dist/registry/bootstrap.d.ts +0 -3
- package/dist/registry/bootstrap.js +0 -5
- package/dist/registry/commands.d.ts +0 -3
- package/dist/registry/commands.js +0 -83
- package/dist/registry/preview.d.ts +0 -11
- package/dist/registry/preview.js +0 -91
- package/dist/registry/receipt.d.ts +0 -3
- package/dist/registry/receipt.js +0 -68
- package/dist/repository.d.ts +0 -24
- package/dist/repository.js +0 -96
- package/dist/scaffold/auth.d.ts +0 -2
- package/dist/scaffold/auth.js +0 -76
- package/dist/scaffold/billing-config.d.ts +0 -1
- package/dist/scaffold/billing-config.js +0 -73
- package/dist/scaffold/billing-contracts.d.ts +0 -2
- package/dist/scaffold/billing-contracts.js +0 -48
- package/dist/scaffold/billing-providers.d.ts +0 -1
- package/dist/scaffold/billing-providers.js +0 -249
- package/dist/scaffold/billing-schema.d.ts +0 -1
- package/dist/scaffold/billing-schema.js +0 -34
- package/dist/scaffold/billing-security.d.ts +0 -1
- package/dist/scaffold/billing-security.js +0 -46
- package/dist/scaffold/billing-server.d.ts +0 -1
- package/dist/scaffold/billing-server.js +0 -139
- package/dist/scaffold/billing-store.d.ts +0 -1
- package/dist/scaffold/billing-store.js +0 -72
- package/dist/scaffold/billing.d.ts +0 -2
- package/dist/scaffold/billing.js +0 -208
- package/dist/scaffold/expo-auth.d.ts +0 -3
- package/dist/scaffold/expo-auth.js +0 -203
- package/dist/scaffold/expo-billing.d.ts +0 -3
- package/dist/scaffold/expo-billing.js +0 -257
- package/dist/scaffold/integrations.d.ts +0 -2
- package/dist/scaffold/integrations.js +0 -11
- package/dist/scaffold/managed-email.d.ts +0 -3
- package/dist/scaffold/managed-email.js +0 -47
- package/dist/scaffold/password-reset.d.ts +0 -1
- package/dist/scaffold/password-reset.js +0 -99
- package/dist/scaffold/private-files.d.ts +0 -2
- package/dist/scaffold/private-files.js +0 -78
- package/dist/scaffold/web-billing.d.ts +0 -2
- package/dist/scaffold/web-billing.js +0 -48
- package/dist/service-deletion.d.ts +0 -29
- package/dist/service-deletion.js +0 -195
- package/dist/service-descriptor.d.ts +0 -10
- package/dist/service-descriptor.js +0 -71
- package/dist/service-model.d.ts +0 -49
- package/dist/service-model.js +0 -8
- package/dist/service-operations.d.ts +0 -29
- package/dist/service-operations.js +0 -48
- package/dist/service-readers.d.ts +0 -8
- package/dist/service-readers.js +0 -216
- package/dist/services-command.d.ts +0 -39
- package/dist/services-command.js +0 -96
- package/dist/ship.d.ts +0 -35
- package/dist/ship.js +0 -107
- package/docs/assets/anhedral-stack-light.png +0 -0
- package/docs/assets/anhedral-stack.png +0 -0
package/dist/providers/api.js
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import { PROVIDER_DEFINITIONS } from './definitions.js';
|
|
3
|
-
export function object(value) {
|
|
4
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
5
|
-
throw new Error('Provider returned an invalid resource.');
|
|
6
|
-
return value;
|
|
7
|
-
}
|
|
8
|
-
export function list(value) {
|
|
9
|
-
if (!Array.isArray(value))
|
|
10
|
-
throw new Error('Provider returned an invalid resource list.');
|
|
11
|
-
return value.map(object);
|
|
12
|
-
}
|
|
13
|
-
export function text(value) {
|
|
14
|
-
if (typeof value !== 'string' || !value || value.length > 16384 || /[\r\n\x00]/.test(value))
|
|
15
|
-
throw new Error('Provider returned an invalid resource field.');
|
|
16
|
-
return value;
|
|
17
|
-
}
|
|
18
|
-
export function resourceId(value) {
|
|
19
|
-
const id = typeof value === 'number' && Number.isSafeInteger(value) && value > 0
|
|
20
|
-
? String(value)
|
|
21
|
-
: text(value);
|
|
22
|
-
if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,254}$/.test(id))
|
|
23
|
-
throw new Error('Provider returned an invalid resource ID.');
|
|
24
|
-
return id;
|
|
25
|
-
}
|
|
26
|
-
/** Stable configuration and operation identity, never a password verifier. */
|
|
27
|
-
export function digest(value) {
|
|
28
|
-
const canonical = (item) => Array.isArray(item)
|
|
29
|
-
? item.map(canonical)
|
|
30
|
-
: item && typeof item === 'object'
|
|
31
|
-
? Object.fromEntries(Object.entries(item)
|
|
32
|
-
.sort(([a], [b]) => a.localeCompare(b))
|
|
33
|
-
.map(([key, entry]) => [key, canonical(entry)]))
|
|
34
|
-
: item;
|
|
35
|
-
return createHash('sha256')
|
|
36
|
-
.update(JSON.stringify(canonical(value)))
|
|
37
|
-
.digest('hex');
|
|
38
|
-
}
|
|
39
|
-
export const CREDENTIALS = Object.fromEntries(Object.entries(PROVIDER_DEFINITIONS).map(([id, definition]) => [id, definition.credential]));
|
|
40
|
-
export class ProviderRequestError extends Error {
|
|
41
|
-
rejected;
|
|
42
|
-
status;
|
|
43
|
-
constructor(message, rejected, status) {
|
|
44
|
-
super(message);
|
|
45
|
-
this.rejected = rejected;
|
|
46
|
-
this.status = status;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
class TransportFailure extends Error {
|
|
50
|
-
}
|
|
51
|
-
class RequestTimeout extends TransportFailure {
|
|
52
|
-
}
|
|
53
|
-
function retryPolicy(options) {
|
|
54
|
-
const policy = {
|
|
55
|
-
maxAttempts: options.maxAttempts ?? 3,
|
|
56
|
-
totalTimeoutMs: options.totalTimeoutMs ?? 30_000,
|
|
57
|
-
attemptTimeoutMs: options.attemptTimeoutMs ?? 10_000,
|
|
58
|
-
baseDelayMs: options.baseDelayMs ?? 100,
|
|
59
|
-
maxDelayMs: options.maxDelayMs ?? 2_000,
|
|
60
|
-
delay: options.delay ??
|
|
61
|
-
((milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds))),
|
|
62
|
-
};
|
|
63
|
-
if (!Number.isInteger(policy.maxAttempts) ||
|
|
64
|
-
policy.maxAttempts < 1 ||
|
|
65
|
-
policy.maxAttempts > 5 ||
|
|
66
|
-
[policy.totalTimeoutMs, policy.attemptTimeoutMs].some((value) => !Number.isInteger(value) || value < 1 || value > 30_000) ||
|
|
67
|
-
[policy.baseDelayMs, policy.maxDelayMs].some((value) => !Number.isInteger(value) || value < 0 || value > 2_000) ||
|
|
68
|
-
policy.baseDelayMs > policy.maxDelayMs ||
|
|
69
|
-
typeof policy.delay !== 'function')
|
|
70
|
-
throw new Error('Invalid bounded provider retry policy.');
|
|
71
|
-
return policy;
|
|
72
|
-
}
|
|
73
|
-
async function deadline(milliseconds, operation) {
|
|
74
|
-
const controller = new AbortController();
|
|
75
|
-
let timer;
|
|
76
|
-
const timeout = new Promise((_resolve, reject) => {
|
|
77
|
-
timer = setTimeout(() => {
|
|
78
|
-
controller.abort();
|
|
79
|
-
reject(new RequestTimeout());
|
|
80
|
-
}, milliseconds);
|
|
81
|
-
});
|
|
82
|
-
try {
|
|
83
|
-
return await Promise.race([operation(controller.signal), timeout]);
|
|
84
|
-
}
|
|
85
|
-
finally {
|
|
86
|
-
clearTimeout(timer);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
function cancelBody(response) {
|
|
90
|
-
try {
|
|
91
|
-
void response.body?.cancel().catch(() => undefined);
|
|
92
|
-
}
|
|
93
|
-
catch {
|
|
94
|
-
/* Cancellation is best effort; diagnostics stay sanitized. */
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
async function responseJson(id, response, signal) {
|
|
98
|
-
if (signal.aborted) {
|
|
99
|
-
cancelBody(response);
|
|
100
|
-
throw new RequestTimeout();
|
|
101
|
-
}
|
|
102
|
-
const reader = response.body?.getReader();
|
|
103
|
-
if (!reader)
|
|
104
|
-
throw new Error(`${id}: provider returned an empty response.`);
|
|
105
|
-
const cancel = () => {
|
|
106
|
-
void reader.cancel().catch(() => undefined);
|
|
107
|
-
};
|
|
108
|
-
signal.addEventListener('abort', cancel, { once: true });
|
|
109
|
-
const chunks = [];
|
|
110
|
-
let bytes = 0;
|
|
111
|
-
try {
|
|
112
|
-
for (;;) {
|
|
113
|
-
let chunk;
|
|
114
|
-
try {
|
|
115
|
-
chunk = await reader.read();
|
|
116
|
-
}
|
|
117
|
-
catch {
|
|
118
|
-
throw new TransportFailure();
|
|
119
|
-
}
|
|
120
|
-
if (chunk.done)
|
|
121
|
-
break;
|
|
122
|
-
bytes += chunk.value.length;
|
|
123
|
-
if (bytes > 2 * 1024 * 1024)
|
|
124
|
-
throw new Error('Response exceeded size limit.');
|
|
125
|
-
chunks.push(chunk.value);
|
|
126
|
-
}
|
|
127
|
-
return JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
cancel();
|
|
131
|
-
if (signal.aborted)
|
|
132
|
-
throw new RequestTimeout();
|
|
133
|
-
if (error instanceof TransportFailure)
|
|
134
|
-
throw error;
|
|
135
|
-
throw new Error(`${id}: provider returned invalid or oversized JSON.`);
|
|
136
|
-
}
|
|
137
|
-
finally {
|
|
138
|
-
signal.removeEventListener('abort', cancel);
|
|
139
|
-
reader.releaseLock();
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
function requestedDelay(value, maximum) {
|
|
143
|
-
if (!value)
|
|
144
|
-
return 0;
|
|
145
|
-
const milliseconds = /^\d+(?:\.\d+)?$/.test(value)
|
|
146
|
-
? Number(value) * 1000
|
|
147
|
-
: Date.parse(value) - Date.now();
|
|
148
|
-
if (!Number.isFinite(milliseconds))
|
|
149
|
-
return 0;
|
|
150
|
-
// Do not retry sooner than a provider's long waiting requirement. Return the
|
|
151
|
-
// sanitized error when that wait exceeds this deliberately short retry budget.
|
|
152
|
-
return milliseconds > maximum ? undefined : Math.max(0, Math.ceil(milliseconds));
|
|
153
|
-
}
|
|
154
|
-
/** Fixed origins, bounded reads and sanitized errors keep management keys out of output.
|
|
155
|
-
* Only GET requests retry transient failures; unknown mutation outcomes never replay. */
|
|
156
|
-
export function providerApi(id, _settings, environment, send, options = {}) {
|
|
157
|
-
const token = environment[CREDENTIALS[id]];
|
|
158
|
-
if (!token || /[^\x21-\x7e]/.test(token))
|
|
159
|
-
throw new Error(`${id}: supply ${CREDENTIALS[id]}.`);
|
|
160
|
-
const policy = retryPolicy(options);
|
|
161
|
-
const definition = PROVIDER_DEFINITIONS[id];
|
|
162
|
-
const origin = definition.origin;
|
|
163
|
-
return async (route, method = 'GET', body, operation) => {
|
|
164
|
-
if (!route.startsWith('/') ||
|
|
165
|
-
route.startsWith('//') ||
|
|
166
|
-
route.includes('..') ||
|
|
167
|
-
/[\r\n#\\]/.test(route))
|
|
168
|
-
throw new Error('Invalid provider API path.');
|
|
169
|
-
const url = new URL(route, origin);
|
|
170
|
-
if (url.origin !== origin)
|
|
171
|
-
throw new Error('Provider API origin changed.');
|
|
172
|
-
const headers = {
|
|
173
|
-
Authorization: `Bearer ${token}`,
|
|
174
|
-
Accept: 'application/json',
|
|
175
|
-
};
|
|
176
|
-
let payload;
|
|
177
|
-
if (body) {
|
|
178
|
-
if (id === 'stripe') {
|
|
179
|
-
const form = new URLSearchParams();
|
|
180
|
-
for (const [key, value] of Object.entries(body)) {
|
|
181
|
-
if (Array.isArray(value))
|
|
182
|
-
for (const entry of value)
|
|
183
|
-
form.append(`${key}[]`, String(entry));
|
|
184
|
-
else
|
|
185
|
-
form.set(key, String(value));
|
|
186
|
-
}
|
|
187
|
-
payload = form.toString();
|
|
188
|
-
headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
payload = JSON.stringify(body);
|
|
192
|
-
headers['Content-Type'] = 'application/json';
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
if (operation && id === 'stripe')
|
|
196
|
-
headers['Idempotency-Key'] = operation;
|
|
197
|
-
const started = performance.now();
|
|
198
|
-
const attempts = method === 'GET' ? policy.maxAttempts : 1;
|
|
199
|
-
for (let attempt = 0; attempt < attempts; attempt++) {
|
|
200
|
-
const remaining = policy.totalTimeoutMs - (performance.now() - started);
|
|
201
|
-
if (remaining <= 0)
|
|
202
|
-
throw new Error(`${id}: provider read retry deadline exceeded.`);
|
|
203
|
-
let retryAfter = 0;
|
|
204
|
-
try {
|
|
205
|
-
return await deadline(Math.min(remaining, method === 'GET' ? policy.attemptTimeoutMs : policy.totalTimeoutMs), async (signal) => {
|
|
206
|
-
let response;
|
|
207
|
-
try {
|
|
208
|
-
response = await send(url.toString(), {
|
|
209
|
-
method,
|
|
210
|
-
headers,
|
|
211
|
-
body: payload,
|
|
212
|
-
redirect: 'error',
|
|
213
|
-
signal,
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
catch {
|
|
217
|
-
throw new TransportFailure();
|
|
218
|
-
}
|
|
219
|
-
if (!response.ok) {
|
|
220
|
-
retryAfter =
|
|
221
|
-
requestedDelay(response.headers.get('Retry-After'), policy.maxDelayMs) ?? -1;
|
|
222
|
-
cancelBody(response);
|
|
223
|
-
throw new ProviderRequestError(`${id}: provider request failed (HTTP ${response.status}). Check account, permissions and quota.`, response.status >= 400 &&
|
|
224
|
-
response.status < 500 &&
|
|
225
|
-
![408, 429].includes(response.status), response.status);
|
|
226
|
-
}
|
|
227
|
-
return responseJson(id, response, signal);
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
catch (error) {
|
|
231
|
-
const retryable = error instanceof TransportFailure ||
|
|
232
|
-
(error instanceof ProviderRequestError &&
|
|
233
|
-
[429, 502, 503, 504].includes(error.status ?? 0));
|
|
234
|
-
const failure = error instanceof TransportFailure
|
|
235
|
-
? new Error(`${id}: provider request did not complete. Inspect remote status before retrying.`)
|
|
236
|
-
: error;
|
|
237
|
-
if (method !== 'GET' || !retryable || retryAfter < 0 || attempt + 1 >= attempts)
|
|
238
|
-
throw failure;
|
|
239
|
-
const delay = Math.max(retryAfter, Math.min(policy.maxDelayMs, policy.baseDelayMs * 2 ** attempt));
|
|
240
|
-
const budget = policy.totalTimeoutMs - (performance.now() - started);
|
|
241
|
-
if (delay >= budget)
|
|
242
|
-
throw failure;
|
|
243
|
-
try {
|
|
244
|
-
await deadline(budget, async () => policy.delay(delay));
|
|
245
|
-
}
|
|
246
|
-
catch {
|
|
247
|
-
throw new Error(`${id}: provider read retry deadline exceeded.`);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
throw new Error(`${id}: provider read retry deadline exceeded.`);
|
|
252
|
-
};
|
|
253
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type IntegrationProvider, type ProviderSettings, type ProviderSettingsById } from './definitions.js';
|
|
2
|
-
export { INTEGRATION_PROVIDERS } from './definitions.js';
|
|
3
|
-
export type { IntegrationProvider, ProviderSettings, ProviderSettingsById } from './definitions.js';
|
|
4
|
-
export interface ProviderConfiguration {
|
|
5
|
-
schemaVersion: 1;
|
|
6
|
-
providers: Partial<ProviderSettingsById>;
|
|
7
|
-
}
|
|
8
|
-
/** Validate untrusted JSON before assigning provider-specific types. */
|
|
9
|
-
export declare function validateProviderConfiguration(value: unknown, selected?: readonly IntegrationProvider[]): asserts value is ProviderConfiguration;
|
|
10
|
-
export declare function providerConfiguration(root: string): ProviderConfiguration;
|
|
11
|
-
export declare function setting(settings: ProviderSettings, key: string): string;
|
|
12
|
-
/** No identities, domains, prices or organizations are inferred from a user's last session. */
|
|
13
|
-
export declare function providerRequirements(id: IntegrationProvider, config: ProviderSettings): string[];
|
|
14
|
-
export declare function selectedIntegrations(root: string): IntegrationProvider[];
|
|
15
|
-
export declare function providerConfigurationTemplate(products: readonly string[], name: string): ProviderConfiguration;
|
package/dist/providers/config.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { realpathSync } from 'node:fs';
|
|
2
|
-
import { hasProjectSection, readProjectSection } from '../project-config.js';
|
|
3
|
-
import { validateSetupPlan } from '../readiness.js';
|
|
4
|
-
import { INTEGRATION_PROVIDERS, PROVIDER_DEFINITIONS, PROVIDER_EVENT_PATTERN, PROVIDER_IDENTITY_PATTERN, PROVIDER_TEXT_PATTERN, PROVIDER_WEBHOOK_PATTERN, } from './definitions.js';
|
|
5
|
-
export { INTEGRATION_PROVIDERS } from './definitions.js';
|
|
6
|
-
/** Validate untrusted JSON before assigning provider-specific types. */
|
|
7
|
-
export function validateProviderConfiguration(value, selected = INTEGRATION_PROVIDERS) {
|
|
8
|
-
if (!value ||
|
|
9
|
-
typeof value !== 'object' ||
|
|
10
|
-
Array.isArray(value) ||
|
|
11
|
-
!('schemaVersion' in value) ||
|
|
12
|
-
value.schemaVersion !== 1 ||
|
|
13
|
-
!('providers' in value) ||
|
|
14
|
-
!value.providers ||
|
|
15
|
-
typeof value.providers !== 'object' ||
|
|
16
|
-
Array.isArray(value.providers) ||
|
|
17
|
-
Object.keys(value).some((key) => !['schemaVersion', 'providers'].includes(key)))
|
|
18
|
-
throw new Error('Invalid provider configuration schema.');
|
|
19
|
-
for (const [id, settings] of Object.entries(value.providers)) {
|
|
20
|
-
if (!INTEGRATION_PROVIDERS.includes(id) ||
|
|
21
|
-
!selected.includes(id))
|
|
22
|
-
throw new Error('Provider configuration includes an unsupported or unselected provider.');
|
|
23
|
-
if (!settings || typeof settings !== 'object' || Array.isArray(settings))
|
|
24
|
-
throw new Error(`Invalid ${id} settings.`);
|
|
25
|
-
const definition = PROVIDER_DEFINITIONS[id];
|
|
26
|
-
for (const [key, entry] of Object.entries(settings)) {
|
|
27
|
-
const field = definition.fields[key];
|
|
28
|
-
if (!Object.hasOwn(definition.fields, key) || !field)
|
|
29
|
-
throw new Error(`Unsupported ${id} setting. Credentials belong in the environment.`);
|
|
30
|
-
if (field.kind === 'events') {
|
|
31
|
-
if (!Array.isArray(entry) ||
|
|
32
|
-
entry.length < 1 ||
|
|
33
|
-
entry.length > 100 ||
|
|
34
|
-
new Set(entry).size !== entry.length ||
|
|
35
|
-
entry.some((event) => typeof event !== 'string' || !new RegExp(PROVIDER_EVENT_PATTERN).test(event)))
|
|
36
|
-
throw new Error('Stripe webhook events must be explicit unique event names.');
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
if (typeof entry !== 'string' || entry.length > 255 || /[\x00-\x1f\x7f]/.test(entry))
|
|
40
|
-
throw new Error(`Invalid ${id} setting.`);
|
|
41
|
-
if (field.choices && !field.choices.includes(entry))
|
|
42
|
-
throw new Error(`Invalid ${id} ${key} choice.`);
|
|
43
|
-
if (field.kind === 'https-url') {
|
|
44
|
-
let url;
|
|
45
|
-
try {
|
|
46
|
-
url = new URL(entry);
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
throw new Error('Webhook URL must use HTTPS.');
|
|
50
|
-
}
|
|
51
|
-
if (!new RegExp(PROVIDER_WEBHOOK_PATTERN).test(entry) ||
|
|
52
|
-
url.protocol !== 'https:' ||
|
|
53
|
-
!url.hostname ||
|
|
54
|
-
url.username ||
|
|
55
|
-
url.password ||
|
|
56
|
-
url.hash ||
|
|
57
|
-
url.search)
|
|
58
|
-
throw new Error('Webhook URL must use HTTPS without credentials, query or fragment.');
|
|
59
|
-
}
|
|
60
|
-
else if (!new RegExp(field.kind === 'identity' ? PROVIDER_IDENTITY_PATTERN : PROVIDER_TEXT_PATTERN).test(entry))
|
|
61
|
-
throw new Error(`Invalid ${id} ${field.kind === 'identity' ? 'resource identity' : 'setting'}.`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
export function providerConfiguration(root) {
|
|
66
|
-
root = realpathSync(root);
|
|
67
|
-
const selected = selectedIntegrations(root);
|
|
68
|
-
if (!hasProjectSection(root, 'providers'))
|
|
69
|
-
return { schemaVersion: 1, providers: {} };
|
|
70
|
-
let value;
|
|
71
|
-
try {
|
|
72
|
-
value = readProjectSection(root, 'providers');
|
|
73
|
-
}
|
|
74
|
-
catch {
|
|
75
|
-
throw new Error('Invalid anhedral.json providers configuration.');
|
|
76
|
-
}
|
|
77
|
-
validateProviderConfiguration(value, selected);
|
|
78
|
-
return value;
|
|
79
|
-
}
|
|
80
|
-
export function setting(settings, key) {
|
|
81
|
-
const value = settings[key];
|
|
82
|
-
return typeof value === 'string' ? value : '';
|
|
83
|
-
}
|
|
84
|
-
/** No identities, domains, prices or organizations are inferred from a user's last session. */
|
|
85
|
-
export function providerRequirements(id, config) {
|
|
86
|
-
const missing = [];
|
|
87
|
-
const need = (key) => {
|
|
88
|
-
if (!setting(config, key))
|
|
89
|
-
missing.push(key);
|
|
90
|
-
};
|
|
91
|
-
const existingOrNew = () => {
|
|
92
|
-
if (!setting(config, 'projectId'))
|
|
93
|
-
need('name');
|
|
94
|
-
};
|
|
95
|
-
switch (id) {
|
|
96
|
-
case 'stripe':
|
|
97
|
-
need('accountId');
|
|
98
|
-
if (!['test', 'live'].includes(setting(config, 'mode')))
|
|
99
|
-
missing.push('mode');
|
|
100
|
-
if (setting(config, 'webhookUrl') && !config.webhookEvents)
|
|
101
|
-
missing.push('webhookEvents');
|
|
102
|
-
if (config.webhookEvents && !setting(config, 'webhookUrl'))
|
|
103
|
-
missing.push('webhookUrl');
|
|
104
|
-
break;
|
|
105
|
-
case 'revenuecat':
|
|
106
|
-
existingOrNew();
|
|
107
|
-
if (![
|
|
108
|
-
'iosAppId',
|
|
109
|
-
'androidAppId',
|
|
110
|
-
'webAppId',
|
|
111
|
-
'stripeAccountId',
|
|
112
|
-
'bundleId',
|
|
113
|
-
'packageName',
|
|
114
|
-
].some((key) => setting(config, key)))
|
|
115
|
-
missing.push('store app identifiers or a connected stripeAccountId');
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
return missing;
|
|
119
|
-
}
|
|
120
|
-
export function selectedIntegrations(root) {
|
|
121
|
-
const setup = readProjectSection(root, 'setup');
|
|
122
|
-
validateSetupPlan(setup);
|
|
123
|
-
return INTEGRATION_PROVIDERS.filter((id) => setup.products.includes(id));
|
|
124
|
-
}
|
|
125
|
-
export function providerConfigurationTemplate(products, name) {
|
|
126
|
-
const templates = {
|
|
127
|
-
stripe: { accountId: '', mode: 'test' },
|
|
128
|
-
revenuecat: products.includes('expo')
|
|
129
|
-
? { name, bundleId: '', packageName: '' }
|
|
130
|
-
: { name, stripeAccountId: '' },
|
|
131
|
-
};
|
|
132
|
-
return {
|
|
133
|
-
schemaVersion: 1,
|
|
134
|
-
providers: Object.fromEntries(INTEGRATION_PROVIDERS.filter((id) => products.includes(id)).map((id) => [id, templates[id]])),
|
|
135
|
-
};
|
|
136
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import type { StandardProduct } from '../stack-registry.js';
|
|
2
|
-
export interface StripeSettings {
|
|
3
|
-
accountId?: string;
|
|
4
|
-
mode?: '' | 'test' | 'live';
|
|
5
|
-
webhookUrl?: string;
|
|
6
|
-
webhookEvents?: string[];
|
|
7
|
-
}
|
|
8
|
-
export interface RevenueCatSettings {
|
|
9
|
-
projectId?: string;
|
|
10
|
-
name?: string;
|
|
11
|
-
iosAppId?: string;
|
|
12
|
-
androidAppId?: string;
|
|
13
|
-
webAppId?: string;
|
|
14
|
-
stripeAccountId?: string;
|
|
15
|
-
bundleId?: string;
|
|
16
|
-
packageName?: string;
|
|
17
|
-
}
|
|
18
|
-
export interface ProviderSettingsById {
|
|
19
|
-
stripe: StripeSettings;
|
|
20
|
-
revenuecat: RevenueCatSettings;
|
|
21
|
-
}
|
|
22
|
-
export type IntegrationProvider = keyof ProviderSettingsById;
|
|
23
|
-
/** Shared adapter access remains bounded to known fields; provider configuration itself
|
|
24
|
-
* uses ProviderSettingsById so fields cannot leak between providers. */
|
|
25
|
-
export type ProviderSettings = StripeSettings & RevenueCatSettings;
|
|
26
|
-
export type ProviderField = keyof ProviderSettings;
|
|
27
|
-
export type FieldKind = 'text' | 'identity' | 'https-url' | 'events';
|
|
28
|
-
export interface ProviderFieldDefinition {
|
|
29
|
-
kind: FieldKind;
|
|
30
|
-
choices?: readonly string[];
|
|
31
|
-
}
|
|
32
|
-
export interface ProviderDefinition {
|
|
33
|
-
credential: string;
|
|
34
|
-
auth: {
|
|
35
|
-
path: string;
|
|
36
|
-
products?: readonly StandardProduct[];
|
|
37
|
-
runtime?: {
|
|
38
|
-
credential: string;
|
|
39
|
-
path: string;
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
origin: string;
|
|
43
|
-
regionalOrigins?: Readonly<Record<string, string>>;
|
|
44
|
-
fields: Partial<Record<ProviderField, ProviderFieldDefinition>>;
|
|
45
|
-
/** Describes adapter scope, not account permissions or production readiness. */
|
|
46
|
-
resources: readonly string[];
|
|
47
|
-
ownerSteps: readonly string[];
|
|
48
|
-
}
|
|
49
|
-
export declare const PROVIDER_DEFINITIONS: {
|
|
50
|
-
readonly stripe: {
|
|
51
|
-
readonly credential: "STRIPE_SECRET_KEY";
|
|
52
|
-
readonly auth: {
|
|
53
|
-
readonly path: "/v1/account";
|
|
54
|
-
};
|
|
55
|
-
readonly origin: "https://api.stripe.com";
|
|
56
|
-
readonly fields: {
|
|
57
|
-
readonly accountId: {
|
|
58
|
-
readonly kind: "identity";
|
|
59
|
-
};
|
|
60
|
-
readonly mode: {
|
|
61
|
-
readonly kind: "text";
|
|
62
|
-
readonly choices: readonly ["", "test", "live"];
|
|
63
|
-
};
|
|
64
|
-
readonly webhookUrl: {
|
|
65
|
-
readonly kind: "https-url";
|
|
66
|
-
};
|
|
67
|
-
readonly webhookEvents: {
|
|
68
|
-
readonly kind: "events";
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
readonly resources: readonly ["account verification", "webhook"];
|
|
72
|
-
readonly ownerSteps: readonly ["Complete account activation; define products, prices, and purchase behavior."];
|
|
73
|
-
};
|
|
74
|
-
readonly revenuecat: {
|
|
75
|
-
readonly credential: "RC_API_KEY";
|
|
76
|
-
readonly auth: {
|
|
77
|
-
readonly path: "/v2/projects";
|
|
78
|
-
};
|
|
79
|
-
readonly origin: "https://api.revenuecat.com";
|
|
80
|
-
readonly fields: {
|
|
81
|
-
readonly projectId: {
|
|
82
|
-
readonly kind: "identity";
|
|
83
|
-
};
|
|
84
|
-
readonly name: {
|
|
85
|
-
readonly kind: "text";
|
|
86
|
-
};
|
|
87
|
-
readonly iosAppId: {
|
|
88
|
-
readonly kind: "identity";
|
|
89
|
-
};
|
|
90
|
-
readonly androidAppId: {
|
|
91
|
-
readonly kind: "identity";
|
|
92
|
-
};
|
|
93
|
-
readonly webAppId: {
|
|
94
|
-
readonly kind: "identity";
|
|
95
|
-
};
|
|
96
|
-
readonly stripeAccountId: {
|
|
97
|
-
readonly kind: "identity";
|
|
98
|
-
};
|
|
99
|
-
readonly bundleId: {
|
|
100
|
-
readonly kind: "text";
|
|
101
|
-
};
|
|
102
|
-
readonly packageName: {
|
|
103
|
-
readonly kind: "text";
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
readonly resources: readonly ["project", "application", "SDK keys"];
|
|
107
|
-
readonly ownerSteps: readonly ["Configure store credentials or Stripe, products, offerings, and entitlements; verify purchases."];
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
export declare const INTEGRATION_PROVIDERS: IntegrationProvider[];
|
|
111
|
-
export declare const PROVIDER_TEXT_PATTERN = "^(?:[a-zA-Z0-9][a-zA-Z0-9_. -]*)?$";
|
|
112
|
-
export declare const PROVIDER_IDENTITY_PATTERN = "^(?:[a-zA-Z0-9][a-zA-Z0-9_-]{0,254})?$";
|
|
113
|
-
export declare const PROVIDER_EVENT_PATTERN = "^[a-z][a-z0-9_.]{0,100}$";
|
|
114
|
-
/** Schema and runtime use the same pattern; URL parsing also verifies normalization. */
|
|
115
|
-
export declare const PROVIDER_WEBHOOK_PATTERN = "^https://[^/?#@\\\\\\s]+(?:/[^?#\\\\\\s]*)?$";
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const text = { kind: 'text' };
|
|
2
|
-
const identity = { kind: 'identity' };
|
|
3
|
-
export const PROVIDER_DEFINITIONS = {
|
|
4
|
-
stripe: {
|
|
5
|
-
credential: 'STRIPE_SECRET_KEY',
|
|
6
|
-
auth: { path: '/v1/account' },
|
|
7
|
-
origin: 'https://api.stripe.com',
|
|
8
|
-
fields: {
|
|
9
|
-
accountId: identity,
|
|
10
|
-
mode: { kind: 'text', choices: ['', 'test', 'live'] },
|
|
11
|
-
webhookUrl: { kind: 'https-url' },
|
|
12
|
-
webhookEvents: { kind: 'events' },
|
|
13
|
-
},
|
|
14
|
-
resources: ['account verification', 'webhook'],
|
|
15
|
-
ownerSteps: ['Complete account activation; define products, prices, and purchase behavior.'],
|
|
16
|
-
},
|
|
17
|
-
revenuecat: {
|
|
18
|
-
credential: 'RC_API_KEY',
|
|
19
|
-
auth: { path: '/v2/projects' },
|
|
20
|
-
origin: 'https://api.revenuecat.com',
|
|
21
|
-
fields: {
|
|
22
|
-
projectId: identity,
|
|
23
|
-
name: text,
|
|
24
|
-
iosAppId: identity,
|
|
25
|
-
androidAppId: identity,
|
|
26
|
-
webAppId: identity,
|
|
27
|
-
stripeAccountId: identity,
|
|
28
|
-
bundleId: text,
|
|
29
|
-
packageName: text,
|
|
30
|
-
},
|
|
31
|
-
resources: ['project', 'application', 'SDK keys'],
|
|
32
|
-
ownerSteps: [
|
|
33
|
-
'Configure store credentials or Stripe, products, offerings, and entitlements; verify purchases.',
|
|
34
|
-
],
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
export const INTEGRATION_PROVIDERS = Object.keys(PROVIDER_DEFINITIONS);
|
|
38
|
-
export const PROVIDER_TEXT_PATTERN = '^(?:[a-zA-Z0-9][a-zA-Z0-9_. -]*)?$';
|
|
39
|
-
export const PROVIDER_IDENTITY_PATTERN = '^(?:[a-zA-Z0-9][a-zA-Z0-9_-]{0,254})?$';
|
|
40
|
-
export const PROVIDER_EVENT_PATTERN = '^[a-z][a-z0-9_.]{0,100}$';
|
|
41
|
-
/** Schema and runtime use the same pattern; URL parsing also verifies normalization. */
|
|
42
|
-
export const PROVIDER_WEBHOOK_PATTERN = '^https://[^/?#@\\\\\\s]+(?:/[^?#\\\\\\s]*)?$';
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { type DeliveryRunner } from '../project-state.js';
|
|
2
|
-
export declare function planProviderProvisioning(root: string): {
|
|
3
|
-
schemaVersion: number;
|
|
4
|
-
providers: {
|
|
5
|
-
provider: keyof import("./definitions.js").ProviderSettingsById;
|
|
6
|
-
settings: import("./definitions.js").StripeSettings | import("./definitions.js").RevenueCatSettings;
|
|
7
|
-
credential: string;
|
|
8
|
-
missing: string[];
|
|
9
|
-
}[];
|
|
10
|
-
configured: boolean;
|
|
11
|
-
mutation: boolean;
|
|
12
|
-
};
|
|
13
|
-
export declare function provisionSelectedProviders(root: string, dryRun?: boolean, run?: DeliveryRunner, send?: typeof fetch, environment?: NodeJS.ProcessEnv): Promise<{
|
|
14
|
-
schemaVersion: number;
|
|
15
|
-
results: {
|
|
16
|
-
provider: string;
|
|
17
|
-
resources: Record<string, string>;
|
|
18
|
-
ready: boolean;
|
|
19
|
-
nextActions: string[];
|
|
20
|
-
}[];
|
|
21
|
-
ready: boolean;
|
|
22
|
-
configuredFiles: string[];
|
|
23
|
-
mutation: boolean;
|
|
24
|
-
}>;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { realpathSync } from 'node:fs';
|
|
2
|
-
import { defaultRunner, withApplicationLock } from '../project-state.js';
|
|
3
|
-
import { CREDENTIALS, providerApi, digest } from './api.js';
|
|
4
|
-
import { PROVIDER_ADAPTERS } from './adapters.js';
|
|
5
|
-
import { providerConfiguration, providerRequirements, selectedIntegrations } from './config.js';
|
|
6
|
-
import { privateStateDirectory, ProvisioningState } from './state.js';
|
|
7
|
-
import { configureRuntime } from './runtime.js';
|
|
8
|
-
export function planProviderProvisioning(root) {
|
|
9
|
-
const configuration = providerConfiguration(root);
|
|
10
|
-
const providers = selectedIntegrations(root).map((id) => {
|
|
11
|
-
const settings = configuration.providers[id] ?? {};
|
|
12
|
-
return {
|
|
13
|
-
provider: id,
|
|
14
|
-
settings,
|
|
15
|
-
credential: CREDENTIALS[id],
|
|
16
|
-
missing: providerRequirements(id, settings),
|
|
17
|
-
};
|
|
18
|
-
});
|
|
19
|
-
return {
|
|
20
|
-
schemaVersion: 1,
|
|
21
|
-
providers,
|
|
22
|
-
configured: providers.every((provider) => !provider.missing.length),
|
|
23
|
-
mutation: false,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
export async function provisionSelectedProviders(root, dryRun = false, run = defaultRunner, send = fetch, environment = process.env) {
|
|
27
|
-
root = realpathSync(root);
|
|
28
|
-
const plan = planProviderProvisioning(root);
|
|
29
|
-
const fingerprint = digest(providerConfiguration(root));
|
|
30
|
-
const assertConfiguration = () => {
|
|
31
|
-
if (digest(providerConfiguration(root)) !== fingerprint)
|
|
32
|
-
throw new Error('Provider configuration changed during provisioning; inspect recorded resources before retrying.');
|
|
33
|
-
};
|
|
34
|
-
if (dryRun || !plan.providers.length)
|
|
35
|
-
return { ...plan, ready: plan.configured, results: [], configuredFiles: [] };
|
|
36
|
-
for (const provider of plan.providers) {
|
|
37
|
-
if (provider.missing.length)
|
|
38
|
-
throw new Error(`${provider.provider}: complete anhedral.json providers configuration (${provider.missing.join(', ')}).`);
|
|
39
|
-
if (!environment[provider.credential])
|
|
40
|
-
throw new Error(`${provider.provider}: supply ${provider.credential} before provisioning.`);
|
|
41
|
-
}
|
|
42
|
-
const directory = await privateStateDirectory(root, run);
|
|
43
|
-
return withApplicationLock(root, async () => {
|
|
44
|
-
const state = new ProvisioningState(directory);
|
|
45
|
-
for (const provider of plan.providers)
|
|
46
|
-
state.context(provider.provider, provider.settings);
|
|
47
|
-
const results = [];
|
|
48
|
-
const values = {};
|
|
49
|
-
for (const provider of plan.providers) {
|
|
50
|
-
assertConfiguration();
|
|
51
|
-
const response = await PROVIDER_ADAPTERS[provider.provider]({
|
|
52
|
-
id: provider.provider,
|
|
53
|
-
settings: provider.settings,
|
|
54
|
-
state,
|
|
55
|
-
environment,
|
|
56
|
-
api: providerApi(provider.provider, provider.settings, environment, send),
|
|
57
|
-
});
|
|
58
|
-
Object.assign(values, response.runtime);
|
|
59
|
-
results.push({
|
|
60
|
-
provider: provider.provider,
|
|
61
|
-
resources: response.resources,
|
|
62
|
-
ready: response.ready,
|
|
63
|
-
nextActions: response.nextActions,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
assertConfiguration();
|
|
67
|
-
const configuredFiles = await configureRuntime(root, values, run);
|
|
68
|
-
return {
|
|
69
|
-
schemaVersion: 1,
|
|
70
|
-
results,
|
|
71
|
-
ready: results.every((result) => result.ready),
|
|
72
|
-
configuredFiles,
|
|
73
|
-
mutation: true,
|
|
74
|
-
};
|
|
75
|
-
});
|
|
76
|
-
}
|