@plures/praxis 1.0.3 → 1.1.1
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/FRAMEWORK.md +55 -5
- package/README.md +162 -375
- package/core/codegen/docs-generator.ts +5 -2
- package/core/codegen/index.ts +1 -1
- package/core/db-adapter/index.ts +2 -2
- package/core/db-adapter/sync-engine.ts +17 -6
- package/core/logic-engine/engine.ts +1 -1
- package/core/logic-engine/index.ts +2 -2
- package/core/logic-engine/protocol.ts +1 -1
- package/core/logic-engine/psf-adapter.ts +8 -4
- package/core/logic-engine/rules.ts +1 -1
- package/core/schema-engine/compiler.ts +53 -11
- package/core/schema-engine/generator.ts +17 -7
- package/core/schema-engine/index.ts +2 -2
- package/core/schema-engine/psf.ts +12 -3
- package/core/schema-engine/types.ts +3 -11
- package/core/schema-engine/validator.ts +112 -22
- package/dist/browser/engine-BjdqxeXG.d.ts +333 -0
- package/dist/browser/index.d.ts +3004 -0
- package/dist/browser/index.js +2892 -0
- package/dist/{src → browser}/integrations/svelte.d.ts +19 -17
- package/dist/browser/integrations/svelte.js +298 -0
- package/dist/node/auth-STARLY7I.js +207 -0
- package/dist/node/build-Y7OT5VBF.js +144 -0
- package/dist/node/canvas-UERZHJYW.js +362 -0
- package/dist/node/chunk-DSDC2JWZ.js +256 -0
- package/dist/node/chunk-FXQZXAWF.js +175 -0
- package/dist/node/chunk-N5Y37EUV.js +202 -0
- package/dist/node/chunk-QGM4M3NI.js +37 -0
- package/dist/node/chunk-RJMWCNHR.js +175 -0
- package/dist/node/chunk-SRM3OPPM.js +404 -0
- package/dist/node/chunk-UATVJBNV.js +175 -0
- package/dist/node/chunk-UY7YEBE2.js +159 -0
- package/dist/node/chunk-XCY2VIFX.js +143 -0
- package/dist/node/chunk-YXH4Y7ZZ.js +349 -0
- package/dist/node/cli/index.cjs +215139 -0
- package/dist/node/cli/index.d.cts +1 -0
- package/dist/node/cli/index.d.ts +1 -0
- package/dist/node/cli/index.js +690 -0
- package/dist/node/cloud/index.cjs +1043 -0
- package/dist/node/cloud/index.d.cts +864 -0
- package/dist/node/cloud/index.d.ts +864 -0
- package/dist/node/cloud/index.js +456 -0
- package/dist/node/cloud-AXOK4PSN.js +212 -0
- package/dist/node/component.cjs +374 -0
- package/dist/node/component.d.cts +125 -0
- package/dist/{src/core/component/generator.d.ts → node/component.d.ts} +11 -8
- package/dist/node/component.js +9 -0
- package/dist/node/components/index.cjs +216 -0
- package/dist/node/components/index.d.cts +43 -0
- package/dist/{src → node}/components/index.d.ts +8 -8
- package/dist/node/components/index.js +7 -0
- package/dist/node/create-TRLSVCNQ.js +584 -0
- package/dist/node/dev-PMJZUYGE.js +65 -0
- package/dist/node/engine-1iqLe6_P.d.ts +214 -0
- package/dist/node/engine-CVJobhHm.d.cts +214 -0
- package/dist/node/index.cjs +3247 -0
- package/dist/node/index.d.cts +2579 -0
- package/dist/node/index.d.ts +2579 -0
- package/dist/node/index.js +2098 -0
- package/dist/node/integrations/svelte.cjs +330 -0
- package/dist/node/integrations/svelte.d.cts +309 -0
- package/dist/node/integrations/svelte.d.ts +309 -0
- package/dist/node/integrations/svelte.js +300 -0
- package/dist/node/orchestrate-737TCL5H.js +127 -0
- package/dist/{src/core/protocol.d.ts → node/protocol-Qek7ebBl.d.cts} +11 -10
- package/dist/node/protocol-Qek7ebBl.d.ts +122 -0
- package/dist/node/schema.cjs +200 -0
- package/dist/{src/core/schema/types.d.ts → node/schema.d.cts} +30 -29
- package/dist/node/schema.d.ts +371 -0
- package/dist/node/schema.js +9 -0
- package/dist/{src/runtime/terminal-adapter.d.ts → node/terminal-adapter-07HGftGQ.d.ts} +86 -11
- package/dist/node/terminal-adapter-XLtCjjb_.d.cts +231 -0
- package/dist/node/verify-QRYKRIDU.js +210960 -0
- package/docs/MONETIZATION.md +21 -16
- package/docs/REACTIVE_REDESIGN.md +132 -0
- package/docs/README.md +47 -36
- package/docs/SVELTE_INTEGRATION_STRATEGY.md +68 -0
- package/docs/TERMINAL_NODE.md +27 -24
- package/docs/core/building-extensions.md +58 -61
- package/docs/core/cli-usage.md +59 -59
- package/docs/core/code-canvas-sync.md +28 -16
- package/docs/core/logic-engine.md +77 -82
- package/docs/core/pluresdb-integration.md +29 -39
- package/docs/core/schema-model.md +66 -52
- package/docs/core/ui-generation.md +57 -49
- package/docs/core/what-is-praxis.md +32 -15
- package/docs/guides/canvas.md +21 -5
- package/docs/guides/getting-started.md +13 -7
- package/docs/guides/history-state-pattern.md +65 -51
- package/docs/guides/orchestration.md +46 -32
- package/docs/guides/parallel-state-pattern.md +56 -72
- package/docs/guides/svelte-integration.md +45 -53
- package/docs/tutorials/README.md +16 -0
- package/docs/tutorials/ecommerce-cart.md +177 -95
- package/docs/tutorials/first-app.md +26 -41
- package/docs/tutorials/form-builder.md +191 -138
- package/docs/tutorials/todo-pluresdb.md +71 -69
- package/package.json +58 -23
- package/src/__tests__/actors.test.ts +68 -68
- package/src/__tests__/billing.test.ts +32 -32
- package/src/__tests__/canvas-components.test.ts +94 -73
- package/src/__tests__/cli-create.test.ts +28 -28
- package/src/__tests__/cloud.test.ts +36 -36
- package/src/__tests__/code-canvas-integration.test.ts +132 -141
- package/src/__tests__/docs-generator.test.ts +3 -9
- package/src/__tests__/dsl.test.ts +58 -64
- package/src/__tests__/edge-cases.test.ts +106 -108
- package/src/__tests__/engine.test.ts +51 -25
- package/src/__tests__/generators.test.ts +42 -44
- package/src/__tests__/introspection.test.ts +104 -114
- package/src/__tests__/pluresdb.test.ts +189 -187
- package/src/__tests__/protocol.test.ts +15 -15
- package/src/__tests__/provisioning.test.ts +61 -61
- package/src/__tests__/schema.test.ts +7 -11
- package/src/__tests__/state-docs-integration.test.ts +162 -145
- package/src/__tests__/svelte-integration.test.ts +16 -19
- package/src/__tests__/tauri-integration.test.ts +149 -147
- package/src/__tests__/terminal-node.test.ts +12 -7
- package/src/__tests__/unum-integration.test.ts +68 -68
- package/src/adapters/cli.ts +21 -15
- package/src/cli/commands/auth.ts +82 -78
- package/src/cli/commands/build.ts +29 -27
- package/src/cli/commands/canvas.ts +338 -127
- package/src/cli/commands/cloud.ts +47 -47
- package/src/cli/commands/create.ts +59 -47
- package/src/cli/commands/dev.ts +12 -12
- package/src/cli/commands/generate.ts +29 -40
- package/src/cli/commands/orchestrate.ts +24 -24
- package/src/cli/commands/verify.ts +7 -8
- package/src/cli/index.ts +14 -10
- package/src/cloud/README.md +28 -15
- package/src/cloud/auth.ts +55 -70
- package/src/cloud/billing.ts +59 -58
- package/src/cloud/client.ts +29 -35
- package/src/cloud/index.ts +19 -40
- package/src/cloud/marketplace.ts +69 -78
- package/src/cloud/provisioning.ts +42 -51
- package/src/cloud/relay/endpoints.ts +30 -34
- package/src/cloud/relay/health/index.ts +1 -1
- package/src/cloud/relay/stats/index.ts +1 -1
- package/src/cloud/relay/sync/index.ts +1 -1
- package/src/cloud/relay/usage/index.ts +1 -1
- package/src/cloud/sponsors.ts +31 -34
- package/src/cloud/types.ts +4 -4
- package/src/components/README.md +1 -0
- package/src/components/index.ts +3 -4
- package/src/core/actors.ts +7 -7
- package/src/core/component/generator.ts +10 -28
- package/src/core/engine.ts +51 -24
- package/src/core/introspection.ts +37 -35
- package/src/core/logic/generator.ts +62 -62
- package/src/core/pluresdb/adapter.ts +8 -8
- package/src/core/pluresdb/generator.ts +39 -35
- package/src/core/pluresdb/index.ts +9 -12
- package/src/core/pluresdb/schema-registry.ts +22 -25
- package/src/core/pluresdb/store.ts +57 -57
- package/src/core/protocol.ts +14 -14
- package/src/core/reactive-engine.svelte.ts +65 -0
- package/src/core/reactive-engine.ts +67 -0
- package/src/core/rules.ts +4 -4
- package/src/core/schema/loader.common.ts +150 -0
- package/src/core/schema/loader.ts +19 -149
- package/src/core/schema/normalize.ts +34 -51
- package/src/core/schema/types.ts +47 -11
- package/src/dsl/index.ts +8 -8
- package/src/dsl.ts +11 -17
- package/src/examples/advanced-todo/README.md +58 -40
- package/src/examples/advanced-todo/index.ts +3 -3
- package/src/examples/auth-basic/index.ts +30 -30
- package/src/examples/cart/index.ts +50 -50
- package/src/examples/hero-ecommerce/index.ts +130 -157
- package/src/examples/svelte-counter/index.ts +22 -26
- package/src/flows.ts +6 -17
- package/src/index.browser.ts +204 -0
- package/src/index.ts +37 -42
- package/src/integrations/code-canvas.ts +237 -193
- package/src/integrations/pluresdb.ts +55 -35
- package/src/integrations/state-docs.ts +104 -104
- package/src/integrations/svelte.ts +35 -35
- package/src/integrations/tauri.ts +75 -73
- package/src/integrations/unum.ts +68 -61
- package/src/registry.ts +7 -14
- package/src/runtime/terminal-adapter.ts +31 -26
- package/src/step.ts +10 -16
- package/src/types.ts +1 -1
- package/templates/basic-app/README.md +6 -9
- package/templates/fullstack-app/README.md +10 -0
- package/dist/core/codegen/docs-generator.d.ts +0 -123
- package/dist/core/codegen/docs-generator.d.ts.map +0 -1
- package/dist/core/codegen/docs-generator.js +0 -674
- package/dist/core/codegen/docs-generator.js.map +0 -1
- package/dist/core/codegen/index.d.ts +0 -11
- package/dist/core/codegen/index.d.ts.map +0 -1
- package/dist/core/codegen/index.js +0 -13
- package/dist/core/codegen/index.js.map +0 -1
- package/dist/core/codegen/ts-generator.d.ts +0 -8
- package/dist/core/codegen/ts-generator.d.ts.map +0 -1
- package/dist/core/codegen/ts-generator.js +0 -8
- package/dist/core/codegen/ts-generator.js.map +0 -1
- package/dist/core/db-adapter/index.d.ts +0 -18
- package/dist/core/db-adapter/index.d.ts.map +0 -1
- package/dist/core/db-adapter/index.js +0 -23
- package/dist/core/db-adapter/index.js.map +0 -1
- package/dist/core/db-adapter/sync-engine.d.ts +0 -180
- package/dist/core/db-adapter/sync-engine.d.ts.map +0 -1
- package/dist/core/db-adapter/sync-engine.js +0 -342
- package/dist/core/db-adapter/sync-engine.js.map +0 -1
- package/dist/core/logic-engine/engine.d.ts +0 -8
- package/dist/core/logic-engine/engine.d.ts.map +0 -1
- package/dist/core/logic-engine/engine.js +0 -8
- package/dist/core/logic-engine/engine.js.map +0 -1
- package/dist/core/logic-engine/index.d.ts +0 -16
- package/dist/core/logic-engine/index.d.ts.map +0 -1
- package/dist/core/logic-engine/index.js +0 -16
- package/dist/core/logic-engine/index.js.map +0 -1
- package/dist/core/logic-engine/protocol.d.ts +0 -7
- package/dist/core/logic-engine/protocol.d.ts.map +0 -1
- package/dist/core/logic-engine/protocol.js +0 -7
- package/dist/core/logic-engine/protocol.js.map +0 -1
- package/dist/core/logic-engine/psf-adapter.d.ts +0 -88
- package/dist/core/logic-engine/psf-adapter.d.ts.map +0 -1
- package/dist/core/logic-engine/psf-adapter.js +0 -207
- package/dist/core/logic-engine/psf-adapter.js.map +0 -1
- package/dist/core/logic-engine/rules.d.ts +0 -7
- package/dist/core/logic-engine/rules.d.ts.map +0 -1
- package/dist/core/logic-engine/rules.js +0 -7
- package/dist/core/logic-engine/rules.js.map +0 -1
- package/dist/core/schema-engine/compiler.d.ts +0 -198
- package/dist/core/schema-engine/compiler.d.ts.map +0 -1
- package/dist/core/schema-engine/compiler.js +0 -262
- package/dist/core/schema-engine/compiler.js.map +0 -1
- package/dist/core/schema-engine/generator.d.ts +0 -115
- package/dist/core/schema-engine/generator.d.ts.map +0 -1
- package/dist/core/schema-engine/generator.js +0 -506
- package/dist/core/schema-engine/generator.js.map +0 -1
- package/dist/core/schema-engine/index.d.ts +0 -18
- package/dist/core/schema-engine/index.d.ts.map +0 -1
- package/dist/core/schema-engine/index.js +0 -18
- package/dist/core/schema-engine/index.js.map +0 -1
- package/dist/core/schema-engine/psf.d.ts +0 -612
- package/dist/core/schema-engine/psf.d.ts.map +0 -1
- package/dist/core/schema-engine/psf.js +0 -45
- package/dist/core/schema-engine/psf.js.map +0 -1
- package/dist/core/schema-engine/types.d.ts +0 -10
- package/dist/core/schema-engine/types.d.ts.map +0 -1
- package/dist/core/schema-engine/types.js +0 -7
- package/dist/core/schema-engine/types.js.map +0 -1
- package/dist/core/schema-engine/validator.d.ts +0 -140
- package/dist/core/schema-engine/validator.d.ts.map +0 -1
- package/dist/core/schema-engine/validator.js +0 -407
- package/dist/core/schema-engine/validator.js.map +0 -1
- package/dist/src/adapters/cli.d.ts +0 -43
- package/dist/src/adapters/cli.d.ts.map +0 -1
- package/dist/src/adapters/cli.js +0 -126
- package/dist/src/adapters/cli.js.map +0 -1
- package/dist/src/cli/commands/auth.d.ts +0 -26
- package/dist/src/cli/commands/auth.d.ts.map +0 -1
- package/dist/src/cli/commands/auth.js +0 -233
- package/dist/src/cli/commands/auth.js.map +0 -1
- package/dist/src/cli/commands/build.d.ts +0 -23
- package/dist/src/cli/commands/build.d.ts.map +0 -1
- package/dist/src/cli/commands/build.js +0 -162
- package/dist/src/cli/commands/build.js.map +0 -1
- package/dist/src/cli/commands/canvas.d.ts +0 -23
- package/dist/src/cli/commands/canvas.d.ts.map +0 -1
- package/dist/src/cli/commands/canvas.js +0 -215
- package/dist/src/cli/commands/canvas.js.map +0 -1
- package/dist/src/cli/commands/cloud.d.ts +0 -27
- package/dist/src/cli/commands/cloud.d.ts.map +0 -1
- package/dist/src/cli/commands/cloud.js +0 -232
- package/dist/src/cli/commands/cloud.js.map +0 -1
- package/dist/src/cli/commands/create.d.ts +0 -21
- package/dist/src/cli/commands/create.d.ts.map +0 -1
- package/dist/src/cli/commands/create.js +0 -621
- package/dist/src/cli/commands/create.js.map +0 -1
- package/dist/src/cli/commands/dev.d.ts +0 -21
- package/dist/src/cli/commands/dev.d.ts.map +0 -1
- package/dist/src/cli/commands/dev.js +0 -71
- package/dist/src/cli/commands/dev.js.map +0 -1
- package/dist/src/cli/commands/generate.d.ts +0 -25
- package/dist/src/cli/commands/generate.d.ts.map +0 -1
- package/dist/src/cli/commands/generate.js +0 -168
- package/dist/src/cli/commands/generate.js.map +0 -1
- package/dist/src/cli/commands/orchestrate.d.ts +0 -44
- package/dist/src/cli/commands/orchestrate.d.ts.map +0 -1
- package/dist/src/cli/commands/orchestrate.js +0 -150
- package/dist/src/cli/commands/orchestrate.js.map +0 -1
- package/dist/src/cli/commands/verify.d.ts +0 -10
- package/dist/src/cli/commands/verify.d.ts.map +0 -1
- package/dist/src/cli/commands/verify.js +0 -39
- package/dist/src/cli/commands/verify.js.map +0 -1
- package/dist/src/cli/index.d.ts +0 -8
- package/dist/src/cli/index.d.ts.map +0 -1
- package/dist/src/cli/index.js +0 -226
- package/dist/src/cli/index.js.map +0 -1
- package/dist/src/cloud/auth.d.ts +0 -51
- package/dist/src/cloud/auth.d.ts.map +0 -1
- package/dist/src/cloud/auth.js +0 -194
- package/dist/src/cloud/auth.js.map +0 -1
- package/dist/src/cloud/billing.d.ts +0 -184
- package/dist/src/cloud/billing.d.ts.map +0 -1
- package/dist/src/cloud/billing.js +0 -179
- package/dist/src/cloud/billing.js.map +0 -1
- package/dist/src/cloud/client.d.ts +0 -39
- package/dist/src/cloud/client.d.ts.map +0 -1
- package/dist/src/cloud/client.js +0 -176
- package/dist/src/cloud/client.js.map +0 -1
- package/dist/src/cloud/index.d.ts +0 -44
- package/dist/src/cloud/index.d.ts.map +0 -1
- package/dist/src/cloud/index.js +0 -44
- package/dist/src/cloud/index.js.map +0 -1
- package/dist/src/cloud/marketplace.d.ts +0 -166
- package/dist/src/cloud/marketplace.d.ts.map +0 -1
- package/dist/src/cloud/marketplace.js +0 -159
- package/dist/src/cloud/marketplace.js.map +0 -1
- package/dist/src/cloud/provisioning.d.ts +0 -110
- package/dist/src/cloud/provisioning.d.ts.map +0 -1
- package/dist/src/cloud/provisioning.js +0 -148
- package/dist/src/cloud/provisioning.js.map +0 -1
- package/dist/src/cloud/relay/endpoints.d.ts +0 -62
- package/dist/src/cloud/relay/endpoints.d.ts.map +0 -1
- package/dist/src/cloud/relay/endpoints.js +0 -217
- package/dist/src/cloud/relay/endpoints.js.map +0 -1
- package/dist/src/cloud/relay/health/index.d.ts +0 -5
- package/dist/src/cloud/relay/health/index.d.ts.map +0 -1
- package/dist/src/cloud/relay/health/index.js +0 -9
- package/dist/src/cloud/relay/health/index.js.map +0 -1
- package/dist/src/cloud/relay/stats/index.d.ts +0 -5
- package/dist/src/cloud/relay/stats/index.d.ts.map +0 -1
- package/dist/src/cloud/relay/stats/index.js +0 -9
- package/dist/src/cloud/relay/stats/index.js.map +0 -1
- package/dist/src/cloud/relay/sync/index.d.ts +0 -5
- package/dist/src/cloud/relay/sync/index.d.ts.map +0 -1
- package/dist/src/cloud/relay/sync/index.js +0 -9
- package/dist/src/cloud/relay/sync/index.js.map +0 -1
- package/dist/src/cloud/relay/usage/index.d.ts +0 -5
- package/dist/src/cloud/relay/usage/index.d.ts.map +0 -1
- package/dist/src/cloud/relay/usage/index.js +0 -9
- package/dist/src/cloud/relay/usage/index.js.map +0 -1
- package/dist/src/cloud/sponsors.d.ts +0 -81
- package/dist/src/cloud/sponsors.d.ts.map +0 -1
- package/dist/src/cloud/sponsors.js +0 -130
- package/dist/src/cloud/sponsors.js.map +0 -1
- package/dist/src/cloud/types.d.ts +0 -169
- package/dist/src/cloud/types.d.ts.map +0 -1
- package/dist/src/cloud/types.js +0 -7
- package/dist/src/cloud/types.js.map +0 -1
- package/dist/src/components/index.d.ts.map +0 -1
- package/dist/src/components/index.js +0 -17
- package/dist/src/components/index.js.map +0 -1
- package/dist/src/core/actors.d.ts +0 -95
- package/dist/src/core/actors.d.ts.map +0 -1
- package/dist/src/core/actors.js +0 -158
- package/dist/src/core/actors.js.map +0 -1
- package/dist/src/core/component/generator.d.ts.map +0 -1
- package/dist/src/core/component/generator.js +0 -349
- package/dist/src/core/component/generator.js.map +0 -1
- package/dist/src/core/engine.d.ts +0 -92
- package/dist/src/core/engine.d.ts.map +0 -1
- package/dist/src/core/engine.js +0 -199
- package/dist/src/core/engine.js.map +0 -1
- package/dist/src/core/introspection.d.ts +0 -141
- package/dist/src/core/introspection.d.ts.map +0 -1
- package/dist/src/core/introspection.js +0 -208
- package/dist/src/core/introspection.js.map +0 -1
- package/dist/src/core/logic/generator.d.ts +0 -76
- package/dist/src/core/logic/generator.d.ts.map +0 -1
- package/dist/src/core/logic/generator.js +0 -370
- package/dist/src/core/logic/generator.js.map +0 -1
- package/dist/src/core/pluresdb/adapter.d.ts +0 -72
- package/dist/src/core/pluresdb/adapter.d.ts.map +0 -1
- package/dist/src/core/pluresdb/adapter.js +0 -73
- package/dist/src/core/pluresdb/adapter.js.map +0 -1
- package/dist/src/core/pluresdb/generator.d.ts +0 -58
- package/dist/src/core/pluresdb/generator.d.ts.map +0 -1
- package/dist/src/core/pluresdb/generator.js +0 -191
- package/dist/src/core/pluresdb/generator.js.map +0 -1
- package/dist/src/core/pluresdb/index.d.ts +0 -15
- package/dist/src/core/pluresdb/index.d.ts.map +0 -1
- package/dist/src/core/pluresdb/index.js +0 -11
- package/dist/src/core/pluresdb/index.js.map +0 -1
- package/dist/src/core/pluresdb/schema-registry.d.ts +0 -104
- package/dist/src/core/pluresdb/schema-registry.d.ts.map +0 -1
- package/dist/src/core/pluresdb/schema-registry.js +0 -130
- package/dist/src/core/pluresdb/schema-registry.js.map +0 -1
- package/dist/src/core/pluresdb/store.d.ts +0 -199
- package/dist/src/core/pluresdb/store.d.ts.map +0 -1
- package/dist/src/core/pluresdb/store.js +0 -344
- package/dist/src/core/pluresdb/store.js.map +0 -1
- package/dist/src/core/protocol.d.ts.map +0 -1
- package/dist/src/core/protocol.js +0 -46
- package/dist/src/core/protocol.js.map +0 -1
- package/dist/src/core/rules.d.ts +0 -120
- package/dist/src/core/rules.d.ts.map +0 -1
- package/dist/src/core/rules.js +0 -81
- package/dist/src/core/rules.js.map +0 -1
- package/dist/src/core/schema/loader.d.ts +0 -47
- package/dist/src/core/schema/loader.d.ts.map +0 -1
- package/dist/src/core/schema/loader.js +0 -189
- package/dist/src/core/schema/loader.js.map +0 -1
- package/dist/src/core/schema/normalize.d.ts +0 -72
- package/dist/src/core/schema/normalize.d.ts.map +0 -1
- package/dist/src/core/schema/normalize.js +0 -190
- package/dist/src/core/schema/normalize.js.map +0 -1
- package/dist/src/core/schema/types.d.ts.map +0 -1
- package/dist/src/core/schema/types.js +0 -161
- package/dist/src/core/schema/types.js.map +0 -1
- package/dist/src/dsl/index.d.ts +0 -152
- package/dist/src/dsl/index.d.ts.map +0 -1
- package/dist/src/dsl/index.js +0 -132
- package/dist/src/dsl/index.js.map +0 -1
- package/dist/src/dsl.d.ts +0 -124
- package/dist/src/dsl.d.ts.map +0 -1
- package/dist/src/dsl.js +0 -130
- package/dist/src/dsl.js.map +0 -1
- package/dist/src/examples/advanced-todo/index.d.ts +0 -55
- package/dist/src/examples/advanced-todo/index.d.ts.map +0 -1
- package/dist/src/examples/advanced-todo/index.js +0 -222
- package/dist/src/examples/advanced-todo/index.js.map +0 -1
- package/dist/src/examples/auth-basic/index.d.ts +0 -17
- package/dist/src/examples/auth-basic/index.d.ts.map +0 -1
- package/dist/src/examples/auth-basic/index.js +0 -122
- package/dist/src/examples/auth-basic/index.js.map +0 -1
- package/dist/src/examples/cart/index.d.ts +0 -19
- package/dist/src/examples/cart/index.d.ts.map +0 -1
- package/dist/src/examples/cart/index.js +0 -202
- package/dist/src/examples/cart/index.js.map +0 -1
- package/dist/src/examples/hero-ecommerce/index.d.ts +0 -39
- package/dist/src/examples/hero-ecommerce/index.d.ts.map +0 -1
- package/dist/src/examples/hero-ecommerce/index.js +0 -506
- package/dist/src/examples/hero-ecommerce/index.js.map +0 -1
- package/dist/src/examples/svelte-counter/index.d.ts +0 -31
- package/dist/src/examples/svelte-counter/index.d.ts.map +0 -1
- package/dist/src/examples/svelte-counter/index.js +0 -123
- package/dist/src/examples/svelte-counter/index.js.map +0 -1
- package/dist/src/flows.d.ts +0 -125
- package/dist/src/flows.d.ts.map +0 -1
- package/dist/src/flows.js +0 -160
- package/dist/src/flows.js.map +0 -1
- package/dist/src/index.d.ts +0 -77
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -64
- package/dist/src/index.js.map +0 -1
- package/dist/src/integrations/code-canvas.d.ts +0 -265
- package/dist/src/integrations/code-canvas.d.ts.map +0 -1
- package/dist/src/integrations/code-canvas.js +0 -451
- package/dist/src/integrations/code-canvas.js.map +0 -1
- package/dist/src/integrations/pluresdb.d.ts +0 -117
- package/dist/src/integrations/pluresdb.d.ts.map +0 -1
- package/dist/src/integrations/pluresdb.js +0 -117
- package/dist/src/integrations/pluresdb.js.map +0 -1
- package/dist/src/integrations/state-docs.d.ts +0 -191
- package/dist/src/integrations/state-docs.d.ts.map +0 -1
- package/dist/src/integrations/state-docs.js +0 -515
- package/dist/src/integrations/state-docs.js.map +0 -1
- package/dist/src/integrations/svelte.d.ts.map +0 -1
- package/dist/src/integrations/svelte.js +0 -447
- package/dist/src/integrations/svelte.js.map +0 -1
- package/dist/src/integrations/tauri.d.ts +0 -360
- package/dist/src/integrations/tauri.d.ts.map +0 -1
- package/dist/src/integrations/tauri.js +0 -278
- package/dist/src/integrations/tauri.js.map +0 -1
- package/dist/src/integrations/unum.d.ts +0 -159
- package/dist/src/integrations/unum.d.ts.map +0 -1
- package/dist/src/integrations/unum.js +0 -240
- package/dist/src/integrations/unum.js.map +0 -1
- package/dist/src/registry.d.ts +0 -94
- package/dist/src/registry.d.ts.map +0 -1
- package/dist/src/registry.js +0 -181
- package/dist/src/registry.js.map +0 -1
- package/dist/src/runtime/terminal-adapter.d.ts.map +0 -1
- package/dist/src/runtime/terminal-adapter.js +0 -239
- package/dist/src/runtime/terminal-adapter.js.map +0 -1
- package/dist/src/step.d.ts +0 -34
- package/dist/src/step.d.ts.map +0 -1
- package/dist/src/step.js +0 -111
- package/dist/src/step.js.map +0 -1
- package/dist/src/types.d.ts +0 -63
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js +0 -6
- package/dist/src/types.js.map +0 -1
- package/dist/tools/ast-analyzer/src/ast-analyzer.d.ts +0 -8
- package/dist/tools/ast-analyzer/src/ast-analyzer.d.ts.map +0 -1
- package/dist/tools/ast-analyzer/src/ast-analyzer.js +0 -119
- package/dist/tools/ast-analyzer/src/ast-analyzer.js.map +0 -1
- package/dist/tools/cli/commands/index.d.ts +0 -7
- package/dist/tools/cli/commands/index.d.ts.map +0 -1
- package/dist/tools/cli/commands/index.js +0 -7
- package/dist/tools/cli/commands/index.js.map +0 -1
- package/dist/tools/cli/index.d.ts +0 -8
- package/dist/tools/cli/index.d.ts.map +0 -1
- package/dist/tools/cli/index.js +0 -9
- package/dist/tools/cli/index.js.map +0 -1
- package/dist/tools/watcher/index.d.ts +0 -105
- package/dist/tools/watcher/index.d.ts.map +0 -1
- package/dist/tools/watcher/index.js +0 -213
- package/dist/tools/watcher/index.js.map +0 -1
- package/dist/ui/canvas/canvas-projection.d.ts +0 -78
- package/dist/ui/canvas/canvas-projection.d.ts.map +0 -1
- package/dist/ui/canvas/canvas-projection.js +0 -416
- package/dist/ui/canvas/canvas-projection.js.map +0 -1
- package/dist/ui/canvas/canvas-state.d.ts +0 -200
- package/dist/ui/canvas/canvas-state.d.ts.map +0 -1
- package/dist/ui/canvas/canvas-state.js +0 -464
- package/dist/ui/canvas/canvas-state.js.map +0 -1
- package/dist/ui/canvas/components/index.d.ts +0 -95
- package/dist/ui/canvas/components/index.d.ts.map +0 -1
- package/dist/ui/canvas/components/index.js +0 -19
- package/dist/ui/canvas/components/index.js.map +0 -1
- package/dist/ui/canvas/index.d.ts +0 -32
- package/dist/ui/canvas/index.d.ts.map +0 -1
- package/dist/ui/canvas/index.js +0 -32
- package/dist/ui/canvas/index.js.map +0 -1
- package/dist/ui/canvas-inspector/src/server.d.ts +0 -2
- package/dist/ui/canvas-inspector/src/server.d.ts.map +0 -1
- package/dist/ui/canvas-inspector/src/server.js +0 -248
- package/dist/ui/canvas-inspector/src/server.js.map +0 -1
- package/dist/ui/canvas-inspector/src/verify-fsm-implementation.d.ts +0 -5
- package/dist/ui/canvas-inspector/src/verify-fsm-implementation.d.ts.map +0 -1
- package/dist/ui/canvas-inspector/src/verify-fsm-implementation.js +0 -58
- package/dist/ui/canvas-inspector/src/verify-fsm-implementation.js.map +0 -1
- package/dist/ui/svelte-generator/index.d.ts +0 -9
- package/dist/ui/svelte-generator/index.d.ts.map +0 -1
- package/dist/ui/svelte-generator/index.js +0 -11
- package/dist/ui/svelte-generator/index.js.map +0 -1
- package/dist/ui/svelte-generator/psf-generator.d.ts +0 -128
- package/dist/ui/svelte-generator/psf-generator.d.ts.map +0 -1
- package/dist/ui/svelte-generator/psf-generator.js +0 -506
- package/dist/ui/svelte-generator/psf-generator.js.map +0 -1
|
@@ -0,0 +1,1043 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/cloud/index.ts
|
|
21
|
+
var cloud_exports = {};
|
|
22
|
+
__export(cloud_exports, {
|
|
23
|
+
BillingProvider: () => BillingProvider,
|
|
24
|
+
GitHubMarketplaceClient: () => GitHubMarketplaceClient,
|
|
25
|
+
GitHubOAuth: () => GitHubOAuth,
|
|
26
|
+
GitHubSponsorsClient: () => GitHubSponsorsClient,
|
|
27
|
+
MARKETPLACE_PLANS: () => MARKETPLACE_PLANS,
|
|
28
|
+
SubscriptionStatus: () => SubscriptionStatus,
|
|
29
|
+
SubscriptionTier: () => SubscriptionTier,
|
|
30
|
+
TIER_LIMITS: () => TIER_LIMITS,
|
|
31
|
+
authenticateWithDeviceFlow: () => authenticateWithDeviceFlow,
|
|
32
|
+
checkUsageLimits: () => checkUsageLimits,
|
|
33
|
+
connectRelay: () => connectRelay,
|
|
34
|
+
createCloudRelay: () => createCloudRelay,
|
|
35
|
+
createFreeSubscription: () => createFreeSubscription,
|
|
36
|
+
createGitHubOAuth: () => createGitHubOAuth,
|
|
37
|
+
createMarketplaceClient: () => createMarketplaceClient,
|
|
38
|
+
createSponsorSubscription: () => createSponsorSubscription,
|
|
39
|
+
createSponsorsClient: () => createSponsorsClient,
|
|
40
|
+
createTenant: () => createTenant,
|
|
41
|
+
eventsEndpoint: () => eventsEndpoint,
|
|
42
|
+
generateStorageNamespace: () => generateStorageNamespace,
|
|
43
|
+
generateTenantId: () => generateTenantId,
|
|
44
|
+
getAppStorageContainer: () => getAppStorageContainer,
|
|
45
|
+
getOrCreateTenant: () => getOrCreateTenant,
|
|
46
|
+
hasAccessToTier: () => hasAccessToTier,
|
|
47
|
+
healthEndpoint: () => healthEndpoint,
|
|
48
|
+
provisionTenant: () => provisionTenant,
|
|
49
|
+
schemaEndpoint: () => schemaEndpoint,
|
|
50
|
+
statsEndpoint: () => statsEndpoint,
|
|
51
|
+
syncEndpoint: () => syncEndpoint,
|
|
52
|
+
usageEndpoint: () => usageEndpoint,
|
|
53
|
+
validateStorageNamespace: () => validateStorageNamespace
|
|
54
|
+
});
|
|
55
|
+
module.exports = __toCommonJS(cloud_exports);
|
|
56
|
+
|
|
57
|
+
// src/cloud/client.ts
|
|
58
|
+
function createCloudRelay(config) {
|
|
59
|
+
let status = {
|
|
60
|
+
connected: false,
|
|
61
|
+
endpoint: config.endpoint,
|
|
62
|
+
appId: config.appId
|
|
63
|
+
};
|
|
64
|
+
let syncTimer = null;
|
|
65
|
+
const vectorClock = {};
|
|
66
|
+
return {
|
|
67
|
+
async connect() {
|
|
68
|
+
if (!config.endpoint) {
|
|
69
|
+
throw new Error("Cloud relay endpoint is required");
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
const response = await fetch(`${config.endpoint}/health`, {
|
|
73
|
+
method: "GET",
|
|
74
|
+
headers: {
|
|
75
|
+
"Content-Type": "application/json",
|
|
76
|
+
...config.authToken && {
|
|
77
|
+
Authorization: `Bearer ${config.authToken}`
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
if (!response.ok) {
|
|
82
|
+
throw new Error(`Health check failed: ${response.statusText}`);
|
|
83
|
+
}
|
|
84
|
+
status.connected = true;
|
|
85
|
+
status.lastSync = Date.now();
|
|
86
|
+
if (config.autoSync) {
|
|
87
|
+
const interval = config.syncInterval || 5e3;
|
|
88
|
+
syncTimer = setInterval(() => {
|
|
89
|
+
status.lastSync = Date.now();
|
|
90
|
+
}, interval);
|
|
91
|
+
}
|
|
92
|
+
} catch (error) {
|
|
93
|
+
status.connected = false;
|
|
94
|
+
throw new Error(
|
|
95
|
+
`Failed to connect to cloud relay: ${error instanceof Error ? error.message : String(error)}`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
async disconnect() {
|
|
100
|
+
if (syncTimer) {
|
|
101
|
+
clearInterval(syncTimer);
|
|
102
|
+
syncTimer = null;
|
|
103
|
+
}
|
|
104
|
+
status.connected = false;
|
|
105
|
+
},
|
|
106
|
+
async sync(message) {
|
|
107
|
+
if (!status.connected) {
|
|
108
|
+
throw new Error("Not connected to cloud relay");
|
|
109
|
+
}
|
|
110
|
+
vectorClock[config.appId] = (vectorClock[config.appId] || 0) + 1;
|
|
111
|
+
message.clock = { ...vectorClock };
|
|
112
|
+
try {
|
|
113
|
+
const response = await fetch(`${config.endpoint}/sync`, {
|
|
114
|
+
method: "POST",
|
|
115
|
+
headers: {
|
|
116
|
+
"Content-Type": "application/json",
|
|
117
|
+
...config.authToken && {
|
|
118
|
+
Authorization: `Bearer ${config.authToken}`
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
body: JSON.stringify(message)
|
|
122
|
+
});
|
|
123
|
+
if (!response.ok) {
|
|
124
|
+
throw new Error(`Sync failed: ${response.statusText}`);
|
|
125
|
+
}
|
|
126
|
+
status.lastSync = Date.now();
|
|
127
|
+
const result = await response.json();
|
|
128
|
+
if (result.clock) {
|
|
129
|
+
Object.entries(result.clock).forEach(([key, value]) => {
|
|
130
|
+
vectorClock[key] = Math.max(vectorClock[key] || 0, value);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
} catch (error) {
|
|
134
|
+
throw new Error(
|
|
135
|
+
`Failed to sync: ${error instanceof Error ? error.message : String(error)}`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
async getUsage() {
|
|
140
|
+
if (!status.connected) {
|
|
141
|
+
throw new Error("Not connected to cloud relay");
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
const response = await fetch(`${config.endpoint}/usage?appId=${config.appId}`, {
|
|
145
|
+
method: "GET",
|
|
146
|
+
headers: {
|
|
147
|
+
"Content-Type": "application/json",
|
|
148
|
+
...config.authToken && {
|
|
149
|
+
Authorization: `Bearer ${config.authToken}`
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
if (!response.ok) {
|
|
154
|
+
throw new Error(`Failed to get usage: ${response.statusText}`);
|
|
155
|
+
}
|
|
156
|
+
return await response.json();
|
|
157
|
+
} catch (error) {
|
|
158
|
+
throw new Error(
|
|
159
|
+
`Failed to get usage metrics: ${error instanceof Error ? error.message : String(error)}`
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
async getHealth() {
|
|
164
|
+
try {
|
|
165
|
+
const response = await fetch(`${config.endpoint}/health`, {
|
|
166
|
+
method: "GET",
|
|
167
|
+
headers: {
|
|
168
|
+
"Content-Type": "application/json"
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
if (!response.ok) {
|
|
172
|
+
throw new Error(`Health check failed: ${response.statusText}`);
|
|
173
|
+
}
|
|
174
|
+
return await response.json();
|
|
175
|
+
} catch (error) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
`Failed to get health status: ${error instanceof Error ? error.message : String(error)}`
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
getStatus() {
|
|
182
|
+
return { ...status };
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
async function connectRelay(endpoint, options = { appId: "default" }) {
|
|
187
|
+
const config = {
|
|
188
|
+
endpoint,
|
|
189
|
+
...options
|
|
190
|
+
};
|
|
191
|
+
const client = createCloudRelay(config);
|
|
192
|
+
await client.connect();
|
|
193
|
+
return client;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// src/cloud/auth.ts
|
|
197
|
+
var GitHubOAuth = class {
|
|
198
|
+
config;
|
|
199
|
+
constructor(config) {
|
|
200
|
+
this.config = config;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Get the OAuth authorization URL
|
|
204
|
+
*/
|
|
205
|
+
getAuthorizationUrl(state) {
|
|
206
|
+
const params = new URLSearchParams({
|
|
207
|
+
client_id: this.config.clientId,
|
|
208
|
+
scope: this.config.scope || "read:user user:email",
|
|
209
|
+
state: state || this.generateState()
|
|
210
|
+
});
|
|
211
|
+
if (this.config.redirectUri) {
|
|
212
|
+
params.set("redirect_uri", this.config.redirectUri);
|
|
213
|
+
}
|
|
214
|
+
return `https://github.com/login/oauth/authorize?${params.toString()}`;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Exchange authorization code for access token
|
|
218
|
+
*/
|
|
219
|
+
async exchangeCode(code) {
|
|
220
|
+
if (!this.config.clientSecret) {
|
|
221
|
+
throw new Error("Client secret is required for code exchange");
|
|
222
|
+
}
|
|
223
|
+
try {
|
|
224
|
+
const response = await fetch("https://github.com/login/oauth/access_token", {
|
|
225
|
+
method: "POST",
|
|
226
|
+
headers: {
|
|
227
|
+
"Content-Type": "application/json",
|
|
228
|
+
Accept: "application/json"
|
|
229
|
+
},
|
|
230
|
+
body: JSON.stringify({
|
|
231
|
+
client_id: this.config.clientId,
|
|
232
|
+
client_secret: this.config.clientSecret,
|
|
233
|
+
code
|
|
234
|
+
})
|
|
235
|
+
});
|
|
236
|
+
if (!response.ok) {
|
|
237
|
+
throw new Error(`Token exchange failed: ${response.statusText}`);
|
|
238
|
+
}
|
|
239
|
+
const data = await response.json();
|
|
240
|
+
if (data.error) {
|
|
241
|
+
throw new Error(`GitHub OAuth error: ${data.error_description || data.error}`);
|
|
242
|
+
}
|
|
243
|
+
const user = await this.getUserInfo(data.access_token);
|
|
244
|
+
return {
|
|
245
|
+
success: true,
|
|
246
|
+
token: data.access_token,
|
|
247
|
+
user,
|
|
248
|
+
expiresAt: data.expires_in ? Date.now() + data.expires_in * 1e3 : void 0
|
|
249
|
+
};
|
|
250
|
+
} catch (error) {
|
|
251
|
+
return {
|
|
252
|
+
success: false
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Get user information from GitHub
|
|
258
|
+
*/
|
|
259
|
+
async getUserInfo(token) {
|
|
260
|
+
const response = await fetch("https://api.github.com/user", {
|
|
261
|
+
headers: {
|
|
262
|
+
Authorization: `Bearer ${token}`,
|
|
263
|
+
Accept: "application/vnd.github.v3+json"
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
if (!response.ok) {
|
|
267
|
+
throw new Error(`Failed to get user info: ${response.statusText}`);
|
|
268
|
+
}
|
|
269
|
+
const data = await response.json();
|
|
270
|
+
return {
|
|
271
|
+
id: data.id,
|
|
272
|
+
login: data.login,
|
|
273
|
+
email: data.email,
|
|
274
|
+
name: data.name,
|
|
275
|
+
avatarUrl: data.avatar_url
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Verify a token is valid
|
|
280
|
+
*/
|
|
281
|
+
async verifyToken(token) {
|
|
282
|
+
try {
|
|
283
|
+
await this.getUserInfo(token);
|
|
284
|
+
return true;
|
|
285
|
+
} catch {
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Generate a random state parameter for CSRF protection
|
|
291
|
+
*/
|
|
292
|
+
generateState() {
|
|
293
|
+
const array = new Uint8Array(16);
|
|
294
|
+
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
295
|
+
crypto.getRandomValues(array);
|
|
296
|
+
} else {
|
|
297
|
+
for (let i = 0; i < array.length; i++) {
|
|
298
|
+
array[i] = Math.floor(Math.random() * 256);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return Array.from(array, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
function createGitHubOAuth(config) {
|
|
305
|
+
return new GitHubOAuth(config);
|
|
306
|
+
}
|
|
307
|
+
async function authenticateWithDeviceFlow(clientId) {
|
|
308
|
+
try {
|
|
309
|
+
const deviceResponse = await fetch("https://github.com/login/device/code", {
|
|
310
|
+
method: "POST",
|
|
311
|
+
headers: {
|
|
312
|
+
"Content-Type": "application/json",
|
|
313
|
+
Accept: "application/json"
|
|
314
|
+
},
|
|
315
|
+
body: JSON.stringify({
|
|
316
|
+
client_id: clientId,
|
|
317
|
+
scope: "read:user user:email"
|
|
318
|
+
})
|
|
319
|
+
});
|
|
320
|
+
if (!deviceResponse.ok) {
|
|
321
|
+
throw new Error(`Device flow initiation failed: ${deviceResponse.statusText}`);
|
|
322
|
+
}
|
|
323
|
+
const deviceData = await deviceResponse.json();
|
|
324
|
+
console.log("\nTo authenticate with GitHub:");
|
|
325
|
+
console.log(`1. Visit: ${deviceData.verification_uri}`);
|
|
326
|
+
console.log(`2. Enter code: ${deviceData.user_code}`);
|
|
327
|
+
console.log("\nWaiting for authentication...\n");
|
|
328
|
+
const interval = deviceData.interval * 1e3 || 5e3;
|
|
329
|
+
const expiresAt = Date.now() + deviceData.expires_in * 1e3;
|
|
330
|
+
while (Date.now() < expiresAt) {
|
|
331
|
+
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
332
|
+
const tokenResponse = await fetch("https://github.com/login/oauth/access_token", {
|
|
333
|
+
method: "POST",
|
|
334
|
+
headers: {
|
|
335
|
+
"Content-Type": "application/json",
|
|
336
|
+
Accept: "application/json"
|
|
337
|
+
},
|
|
338
|
+
body: JSON.stringify({
|
|
339
|
+
client_id: clientId,
|
|
340
|
+
device_code: deviceData.device_code,
|
|
341
|
+
grant_type: "urn:ietf:params:oauth:grant-type:device_code"
|
|
342
|
+
})
|
|
343
|
+
});
|
|
344
|
+
const tokenData = await tokenResponse.json();
|
|
345
|
+
if (tokenData.access_token) {
|
|
346
|
+
const oauth = new GitHubOAuth({ clientId });
|
|
347
|
+
const user = await oauth.getUserInfo(tokenData.access_token);
|
|
348
|
+
return {
|
|
349
|
+
success: true,
|
|
350
|
+
token: tokenData.access_token,
|
|
351
|
+
user
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
if (tokenData.error && tokenData.error !== "authorization_pending") {
|
|
355
|
+
throw new Error(`Authentication failed: ${tokenData.error_description || tokenData.error}`);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
throw new Error("Authentication timeout");
|
|
359
|
+
} catch (error) {
|
|
360
|
+
return {
|
|
361
|
+
success: false
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// src/cloud/billing.ts
|
|
367
|
+
var SubscriptionTier = /* @__PURE__ */ ((SubscriptionTier2) => {
|
|
368
|
+
SubscriptionTier2["FREE"] = "free";
|
|
369
|
+
SubscriptionTier2["SOLO"] = "solo";
|
|
370
|
+
SubscriptionTier2["TEAM"] = "team";
|
|
371
|
+
SubscriptionTier2["ENTERPRISE"] = "enterprise";
|
|
372
|
+
return SubscriptionTier2;
|
|
373
|
+
})(SubscriptionTier || {});
|
|
374
|
+
var BillingProvider = /* @__PURE__ */ ((BillingProvider2) => {
|
|
375
|
+
BillingProvider2["SPONSORS"] = "sponsors";
|
|
376
|
+
BillingProvider2["MARKETPLACE"] = "marketplace";
|
|
377
|
+
BillingProvider2["NONE"] = "none";
|
|
378
|
+
return BillingProvider2;
|
|
379
|
+
})(BillingProvider || {});
|
|
380
|
+
var SubscriptionStatus = /* @__PURE__ */ ((SubscriptionStatus2) => {
|
|
381
|
+
SubscriptionStatus2["ACTIVE"] = "active";
|
|
382
|
+
SubscriptionStatus2["CANCELLED"] = "cancelled";
|
|
383
|
+
SubscriptionStatus2["EXPIRED"] = "expired";
|
|
384
|
+
SubscriptionStatus2["NONE"] = "none";
|
|
385
|
+
return SubscriptionStatus2;
|
|
386
|
+
})(SubscriptionStatus || {});
|
|
387
|
+
var TIER_LIMITS = {
|
|
388
|
+
["free" /* FREE */]: {
|
|
389
|
+
maxSyncsPerMonth: 1e3,
|
|
390
|
+
maxStorageBytes: 10 * 1024 * 1024,
|
|
391
|
+
// 10 MB
|
|
392
|
+
maxTeamMembers: 1,
|
|
393
|
+
maxApps: 1,
|
|
394
|
+
supportLevel: "community"
|
|
395
|
+
},
|
|
396
|
+
["solo" /* SOLO */]: {
|
|
397
|
+
maxSyncsPerMonth: 5e4,
|
|
398
|
+
maxStorageBytes: 1024 * 1024 * 1024,
|
|
399
|
+
// 1 GB
|
|
400
|
+
maxTeamMembers: 1,
|
|
401
|
+
maxApps: 10,
|
|
402
|
+
supportLevel: "standard"
|
|
403
|
+
},
|
|
404
|
+
["team" /* TEAM */]: {
|
|
405
|
+
maxSyncsPerMonth: 5e5,
|
|
406
|
+
maxStorageBytes: 10 * 1024 * 1024 * 1024,
|
|
407
|
+
// 10 GB
|
|
408
|
+
maxTeamMembers: 10,
|
|
409
|
+
maxApps: 50,
|
|
410
|
+
supportLevel: "standard"
|
|
411
|
+
},
|
|
412
|
+
["enterprise" /* ENTERPRISE */]: {
|
|
413
|
+
maxSyncsPerMonth: 5e6,
|
|
414
|
+
maxStorageBytes: 100 * 1024 * 1024 * 1024,
|
|
415
|
+
// 100 GB
|
|
416
|
+
maxTeamMembers: null,
|
|
417
|
+
// unlimited
|
|
418
|
+
maxApps: 1e3,
|
|
419
|
+
supportLevel: "priority"
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
function hasAccessToTier(subscription, requiredTier) {
|
|
423
|
+
if (subscription.status !== "active" /* ACTIVE */) {
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
const tierOrder = [
|
|
427
|
+
"free" /* FREE */,
|
|
428
|
+
"solo" /* SOLO */,
|
|
429
|
+
"team" /* TEAM */,
|
|
430
|
+
"enterprise" /* ENTERPRISE */
|
|
431
|
+
];
|
|
432
|
+
const currentTierIndex = tierOrder.indexOf(subscription.tier);
|
|
433
|
+
const requiredTierIndex = tierOrder.indexOf(requiredTier);
|
|
434
|
+
return currentTierIndex >= requiredTierIndex;
|
|
435
|
+
}
|
|
436
|
+
function checkUsageLimits(subscription, usage) {
|
|
437
|
+
const violations = [];
|
|
438
|
+
if (usage.syncCount > subscription.limits.maxSyncsPerMonth) {
|
|
439
|
+
violations.push(
|
|
440
|
+
`Sync limit exceeded: ${usage.syncCount}/${subscription.limits.maxSyncsPerMonth}`
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
if (usage.storageBytes > subscription.limits.maxStorageBytes) {
|
|
444
|
+
violations.push(
|
|
445
|
+
`Storage limit exceeded: ${(usage.storageBytes / 1024 / 1024).toFixed(2)}MB/${(subscription.limits.maxStorageBytes / 1024 / 1024).toFixed(2)}MB`
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
if (subscription.limits.maxTeamMembers !== null && usage.teamMembers > subscription.limits.maxTeamMembers) {
|
|
449
|
+
violations.push(
|
|
450
|
+
`Team member limit exceeded: ${usage.teamMembers}/${subscription.limits.maxTeamMembers}`
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
if (usage.appCount > subscription.limits.maxApps) {
|
|
454
|
+
violations.push(`App limit exceeded: ${usage.appCount}/${subscription.limits.maxApps}`);
|
|
455
|
+
}
|
|
456
|
+
return {
|
|
457
|
+
withinLimits: violations.length === 0,
|
|
458
|
+
violations
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
function createFreeSubscription() {
|
|
462
|
+
return {
|
|
463
|
+
tier: "free" /* FREE */,
|
|
464
|
+
status: "active" /* ACTIVE */,
|
|
465
|
+
provider: "none" /* NONE */,
|
|
466
|
+
startDate: Date.now(),
|
|
467
|
+
autoRenew: true,
|
|
468
|
+
limits: TIER_LIMITS["free" /* FREE */]
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
function createSponsorSubscription(tierName, monthlyPriceInCents) {
|
|
472
|
+
let tier = "free" /* FREE */;
|
|
473
|
+
if (monthlyPriceInCents >= 5e3) {
|
|
474
|
+
tier = "enterprise" /* ENTERPRISE */;
|
|
475
|
+
} else if (monthlyPriceInCents >= 2e3) {
|
|
476
|
+
tier = "team" /* TEAM */;
|
|
477
|
+
} else if (monthlyPriceInCents >= 500) {
|
|
478
|
+
tier = "solo" /* SOLO */;
|
|
479
|
+
}
|
|
480
|
+
return {
|
|
481
|
+
tier,
|
|
482
|
+
status: "active" /* ACTIVE */,
|
|
483
|
+
provider: "sponsors" /* SPONSORS */,
|
|
484
|
+
sponsorTierId: tierName,
|
|
485
|
+
startDate: Date.now(),
|
|
486
|
+
autoRenew: true,
|
|
487
|
+
limits: TIER_LIMITS[tier]
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
// src/cloud/sponsors.ts
|
|
492
|
+
var GitHubSponsorsClient = class {
|
|
493
|
+
token;
|
|
494
|
+
accountLogin;
|
|
495
|
+
constructor(token, accountLogin) {
|
|
496
|
+
this.token = token;
|
|
497
|
+
this.accountLogin = accountLogin;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Get current user's sponsorship of the Praxis account
|
|
501
|
+
*/
|
|
502
|
+
async getSponsorship(userLogin) {
|
|
503
|
+
try {
|
|
504
|
+
const query = `
|
|
505
|
+
query($accountLogin: String!, $userLogin: String!) {
|
|
506
|
+
user(login: $userLogin) {
|
|
507
|
+
sponsorshipForViewerAsSponsor(activeOnly: true) {
|
|
508
|
+
tier {
|
|
509
|
+
id
|
|
510
|
+
name
|
|
511
|
+
monthlyPriceInCents
|
|
512
|
+
description
|
|
513
|
+
isOneTime
|
|
514
|
+
}
|
|
515
|
+
createdAt
|
|
516
|
+
isActive
|
|
517
|
+
}
|
|
518
|
+
sponsorshipsAsSponsor(first: 100, activeOnly: true) {
|
|
519
|
+
nodes {
|
|
520
|
+
sponsorable {
|
|
521
|
+
... on User {
|
|
522
|
+
login
|
|
523
|
+
}
|
|
524
|
+
... on Organization {
|
|
525
|
+
login
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
tier {
|
|
529
|
+
id
|
|
530
|
+
name
|
|
531
|
+
monthlyPriceInCents
|
|
532
|
+
description
|
|
533
|
+
isOneTime
|
|
534
|
+
}
|
|
535
|
+
createdAt
|
|
536
|
+
isActive
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
`;
|
|
542
|
+
const response = await fetch("https://api.github.com/graphql", {
|
|
543
|
+
method: "POST",
|
|
544
|
+
headers: {
|
|
545
|
+
Authorization: `Bearer ${this.token}`,
|
|
546
|
+
"Content-Type": "application/json"
|
|
547
|
+
},
|
|
548
|
+
body: JSON.stringify({
|
|
549
|
+
query,
|
|
550
|
+
variables: {
|
|
551
|
+
accountLogin: this.accountLogin,
|
|
552
|
+
userLogin
|
|
553
|
+
}
|
|
554
|
+
})
|
|
555
|
+
});
|
|
556
|
+
if (!response.ok) {
|
|
557
|
+
throw new Error(`GitHub API error: ${response.statusText}`);
|
|
558
|
+
}
|
|
559
|
+
const data = await response.json();
|
|
560
|
+
if (data.errors) {
|
|
561
|
+
throw new Error(`GraphQL error: ${JSON.stringify(data.errors)}`);
|
|
562
|
+
}
|
|
563
|
+
const sponsorships = data.data?.user?.sponsorshipsAsSponsor?.nodes || [];
|
|
564
|
+
const praxisSponsorship = sponsorships.find(
|
|
565
|
+
(s) => s.sponsorable?.login === this.accountLogin
|
|
566
|
+
);
|
|
567
|
+
if (!praxisSponsorship) {
|
|
568
|
+
return null;
|
|
569
|
+
}
|
|
570
|
+
return {
|
|
571
|
+
sponsorLogin: userLogin,
|
|
572
|
+
sponsorId: data.data.user.id,
|
|
573
|
+
tier: {
|
|
574
|
+
id: praxisSponsorship.tier.id,
|
|
575
|
+
name: praxisSponsorship.tier.name,
|
|
576
|
+
monthlyPriceInCents: praxisSponsorship.tier.monthlyPriceInCents,
|
|
577
|
+
description: praxisSponsorship.tier.description,
|
|
578
|
+
isOneTime: praxisSponsorship.tier.isOneTime
|
|
579
|
+
},
|
|
580
|
+
createdAt: praxisSponsorship.createdAt,
|
|
581
|
+
isActive: praxisSponsorship.isActive
|
|
582
|
+
};
|
|
583
|
+
} catch (error) {
|
|
584
|
+
console.error("Failed to get sponsorship:", error);
|
|
585
|
+
return null;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Get subscription from sponsorship
|
|
590
|
+
*/
|
|
591
|
+
async getSubscription(userLogin) {
|
|
592
|
+
const sponsorship = await this.getSponsorship(userLogin);
|
|
593
|
+
if (!sponsorship || !sponsorship.isActive) {
|
|
594
|
+
return createFreeSubscription();
|
|
595
|
+
}
|
|
596
|
+
return createSponsorSubscription(sponsorship.tier.name, sponsorship.tier.monthlyPriceInCents);
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Check if user is a sponsor
|
|
600
|
+
*/
|
|
601
|
+
async isSponsor(userLogin) {
|
|
602
|
+
const sponsorship = await this.getSponsorship(userLogin);
|
|
603
|
+
return sponsorship !== null && sponsorship.isActive;
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
function createSponsorsClient(token, accountLogin = "plures") {
|
|
607
|
+
return new GitHubSponsorsClient(token, accountLogin);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// src/cloud/marketplace.ts
|
|
611
|
+
var MARKETPLACE_PLANS = {
|
|
612
|
+
solo: {
|
|
613
|
+
name: "Praxis Cloud Solo",
|
|
614
|
+
description: "For individual developers",
|
|
615
|
+
monthlyPriceInCents: 500,
|
|
616
|
+
// $5/month
|
|
617
|
+
yearlyPriceInCents: 5e3,
|
|
618
|
+
// $50/year (2 months free)
|
|
619
|
+
features: ["50,000 syncs/month", "1 GB storage", "10 apps/projects", "Standard support"]
|
|
620
|
+
},
|
|
621
|
+
team: {
|
|
622
|
+
name: "Praxis Cloud Team",
|
|
623
|
+
description: "For small teams",
|
|
624
|
+
monthlyPriceInCents: 2e3,
|
|
625
|
+
// $20/month
|
|
626
|
+
yearlyPriceInCents: 2e4,
|
|
627
|
+
// $200/year (2 months free)
|
|
628
|
+
features: [
|
|
629
|
+
"500,000 syncs/month",
|
|
630
|
+
"10 GB storage",
|
|
631
|
+
"50 apps/projects",
|
|
632
|
+
"Up to 10 team members",
|
|
633
|
+
"Standard support"
|
|
634
|
+
]
|
|
635
|
+
},
|
|
636
|
+
enterprise: {
|
|
637
|
+
name: "Praxis Cloud Enterprise",
|
|
638
|
+
description: "For large teams and organizations",
|
|
639
|
+
monthlyPriceInCents: 5e3,
|
|
640
|
+
// $50/month
|
|
641
|
+
yearlyPriceInCents: 5e4,
|
|
642
|
+
// $500/year (2 months free)
|
|
643
|
+
features: [
|
|
644
|
+
"5,000,000 syncs/month",
|
|
645
|
+
"100 GB storage",
|
|
646
|
+
"1,000 apps/projects",
|
|
647
|
+
"Unlimited team members",
|
|
648
|
+
"Priority support",
|
|
649
|
+
"SLA guarantees"
|
|
650
|
+
]
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
var GitHubMarketplaceClient = class {
|
|
654
|
+
token;
|
|
655
|
+
constructor(token) {
|
|
656
|
+
this.token = token;
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* Get accounts for the authenticated user
|
|
660
|
+
*/
|
|
661
|
+
async getAccounts() {
|
|
662
|
+
try {
|
|
663
|
+
const response = await fetch("https://api.github.com/marketplace_listing/accounts", {
|
|
664
|
+
headers: {
|
|
665
|
+
Authorization: `Bearer ${this.token}`,
|
|
666
|
+
Accept: "application/vnd.github.v3+json"
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
if (!response.ok) {
|
|
670
|
+
throw new Error(`GitHub API error: ${response.statusText}`);
|
|
671
|
+
}
|
|
672
|
+
return await response.json();
|
|
673
|
+
} catch (error) {
|
|
674
|
+
console.error("Failed to get marketplace accounts:", error);
|
|
675
|
+
return [];
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Get subscription from marketplace account
|
|
680
|
+
*/
|
|
681
|
+
async getSubscription(accountId) {
|
|
682
|
+
const accounts = await this.getAccounts();
|
|
683
|
+
const account = accounts.find((a) => a.id === accountId);
|
|
684
|
+
if (!account) {
|
|
685
|
+
return null;
|
|
686
|
+
}
|
|
687
|
+
let tier = "free" /* FREE */;
|
|
688
|
+
if (account.plan.monthlyPriceInCents >= 5e3) {
|
|
689
|
+
tier = "enterprise" /* ENTERPRISE */;
|
|
690
|
+
} else if (account.plan.monthlyPriceInCents >= 2e3) {
|
|
691
|
+
tier = "team" /* TEAM */;
|
|
692
|
+
} else if (account.plan.monthlyPriceInCents >= 500) {
|
|
693
|
+
tier = "solo" /* SOLO */;
|
|
694
|
+
}
|
|
695
|
+
return {
|
|
696
|
+
tier,
|
|
697
|
+
status: "active" /* ACTIVE */,
|
|
698
|
+
provider: "marketplace" /* MARKETPLACE */,
|
|
699
|
+
marketplacePlanId: account.plan.id,
|
|
700
|
+
startDate: account.onFreeTrial && account.freeTrialEndsOn ? new Date(account.freeTrialEndsOn).getTime() : Date.now(),
|
|
701
|
+
periodEnd: account.nextBillingDate ? new Date(account.nextBillingDate).getTime() : void 0,
|
|
702
|
+
autoRenew: true,
|
|
703
|
+
limits: TIER_LIMITS[tier]
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Handle marketplace webhook event
|
|
708
|
+
*/
|
|
709
|
+
handleWebhookEvent(event) {
|
|
710
|
+
const account = event.marketplacePurchase.account;
|
|
711
|
+
if (event.action === "cancelled") {
|
|
712
|
+
return null;
|
|
713
|
+
}
|
|
714
|
+
let tier = "free" /* FREE */;
|
|
715
|
+
if (account.plan.monthlyPriceInCents >= 5e3) {
|
|
716
|
+
tier = "enterprise" /* ENTERPRISE */;
|
|
717
|
+
} else if (account.plan.monthlyPriceInCents >= 2e3) {
|
|
718
|
+
tier = "team" /* TEAM */;
|
|
719
|
+
} else if (account.plan.monthlyPriceInCents >= 500) {
|
|
720
|
+
tier = "solo" /* SOLO */;
|
|
721
|
+
}
|
|
722
|
+
return {
|
|
723
|
+
userId: account.id,
|
|
724
|
+
userLogin: account.login,
|
|
725
|
+
subscription: {
|
|
726
|
+
tier,
|
|
727
|
+
status: "active" /* ACTIVE */,
|
|
728
|
+
provider: "marketplace" /* MARKETPLACE */,
|
|
729
|
+
marketplacePlanId: account.plan.id,
|
|
730
|
+
startDate: Date.now(),
|
|
731
|
+
periodEnd: event.marketplacePurchase.nextBillingDate ? new Date(event.marketplacePurchase.nextBillingDate).getTime() : void 0,
|
|
732
|
+
autoRenew: true,
|
|
733
|
+
limits: TIER_LIMITS[tier]
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
function createMarketplaceClient(token) {
|
|
739
|
+
return new GitHubMarketplaceClient(token);
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// src/cloud/provisioning.ts
|
|
743
|
+
function generateStorageNamespace(githubLogin, userId) {
|
|
744
|
+
const sanitized = githubLogin.toLowerCase().replace(/[^a-z0-9]/g, "-");
|
|
745
|
+
const hash = userId.toString(36).padStart(6, "0");
|
|
746
|
+
return `gh-${sanitized}-${hash}`;
|
|
747
|
+
}
|
|
748
|
+
function generateTenantId(githubUser) {
|
|
749
|
+
return `github-${githubUser.id}`;
|
|
750
|
+
}
|
|
751
|
+
function createTenant(githubUser, subscription) {
|
|
752
|
+
const tenantId = generateTenantId(githubUser);
|
|
753
|
+
const storageNamespace = generateStorageNamespace(githubUser.login, githubUser.id);
|
|
754
|
+
return {
|
|
755
|
+
id: tenantId,
|
|
756
|
+
githubUserId: githubUser.id,
|
|
757
|
+
githubLogin: githubUser.login,
|
|
758
|
+
type: "user",
|
|
759
|
+
// Could be "organization" if checking org membership
|
|
760
|
+
subscription,
|
|
761
|
+
storageNamespace,
|
|
762
|
+
createdAt: Date.now(),
|
|
763
|
+
lastAccessedAt: Date.now()
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
function validateStorageNamespace(namespace) {
|
|
767
|
+
if (namespace.length < 3 || namespace.length > 63) {
|
|
768
|
+
return {
|
|
769
|
+
valid: false,
|
|
770
|
+
error: "Namespace must be 3-63 characters"
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
if (!/^[a-z0-9]/.test(namespace)) {
|
|
774
|
+
return {
|
|
775
|
+
valid: false,
|
|
776
|
+
error: "Namespace must start with a letter or number"
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
if (!/^[a-z0-9-]+$/.test(namespace)) {
|
|
780
|
+
return {
|
|
781
|
+
valid: false,
|
|
782
|
+
error: "Namespace can only contain lowercase letters, numbers, and hyphens"
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
if (/--/.test(namespace)) {
|
|
786
|
+
return {
|
|
787
|
+
valid: false,
|
|
788
|
+
error: "Namespace cannot contain consecutive hyphens"
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
return { valid: true };
|
|
792
|
+
}
|
|
793
|
+
function getAppStorageContainer(tenantNamespace, appId) {
|
|
794
|
+
const sanitizedAppId = appId.toLowerCase().replace(/[^a-z0-9]/g, "-");
|
|
795
|
+
return `${tenantNamespace}-${sanitizedAppId}`;
|
|
796
|
+
}
|
|
797
|
+
async function provisionTenant(githubUser, subscription) {
|
|
798
|
+
try {
|
|
799
|
+
const tenant = createTenant(githubUser, subscription);
|
|
800
|
+
const validation = validateStorageNamespace(tenant.storageNamespace);
|
|
801
|
+
if (!validation.valid) {
|
|
802
|
+
return {
|
|
803
|
+
success: false,
|
|
804
|
+
error: validation.error
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
console.log(`Provisioned tenant: ${tenant.id}`);
|
|
808
|
+
console.log(`Storage namespace: ${tenant.storageNamespace}`);
|
|
809
|
+
return {
|
|
810
|
+
success: true,
|
|
811
|
+
tenant
|
|
812
|
+
};
|
|
813
|
+
} catch (error) {
|
|
814
|
+
return {
|
|
815
|
+
success: false,
|
|
816
|
+
error: error instanceof Error ? error.message : String(error)
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
async function getOrCreateTenant(githubUser, subscription, tenantLookup) {
|
|
821
|
+
const tenantId = generateTenantId(githubUser);
|
|
822
|
+
const existing = await tenantLookup(tenantId);
|
|
823
|
+
if (existing) {
|
|
824
|
+
existing.lastAccessedAt = Date.now();
|
|
825
|
+
return existing;
|
|
826
|
+
}
|
|
827
|
+
const result = await provisionTenant(githubUser, subscription);
|
|
828
|
+
if (!result.success || !result.tenant) {
|
|
829
|
+
throw new Error(`Failed to provision tenant: ${result.error}`);
|
|
830
|
+
}
|
|
831
|
+
return result.tenant;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
// src/cloud/relay/endpoints.ts
|
|
835
|
+
var storage = {
|
|
836
|
+
syncs: /* @__PURE__ */ new Map(),
|
|
837
|
+
usage: /* @__PURE__ */ new Map()
|
|
838
|
+
};
|
|
839
|
+
async function healthEndpoint(context, _req) {
|
|
840
|
+
context.log("Health check requested");
|
|
841
|
+
const response = {
|
|
842
|
+
status: "healthy",
|
|
843
|
+
timestamp: Date.now(),
|
|
844
|
+
version: "0.1.0",
|
|
845
|
+
services: {
|
|
846
|
+
relay: true,
|
|
847
|
+
eventGrid: true,
|
|
848
|
+
storage: true,
|
|
849
|
+
auth: true
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
return {
|
|
853
|
+
status: 200,
|
|
854
|
+
headers: { "Content-Type": "application/json" },
|
|
855
|
+
body: response
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
async function syncEndpoint(context, req) {
|
|
859
|
+
context.log("Sync request received");
|
|
860
|
+
if (req.method !== "POST") {
|
|
861
|
+
return {
|
|
862
|
+
status: 405,
|
|
863
|
+
body: { error: "Method not allowed" }
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
const message = req.body;
|
|
867
|
+
if (!message || !message.appId) {
|
|
868
|
+
return {
|
|
869
|
+
status: 400,
|
|
870
|
+
body: { error: "Invalid sync message" }
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
const appSyncs = storage.syncs.get(message.appId) || [];
|
|
874
|
+
appSyncs.push(message);
|
|
875
|
+
storage.syncs.set(message.appId, appSyncs);
|
|
876
|
+
const usage = storage.usage.get(message.appId) || {
|
|
877
|
+
appId: message.appId,
|
|
878
|
+
syncCount: 0,
|
|
879
|
+
eventCount: 0,
|
|
880
|
+
factCount: 0,
|
|
881
|
+
storageBytes: 0,
|
|
882
|
+
periodStart: Date.now(),
|
|
883
|
+
periodEnd: Date.now()
|
|
884
|
+
};
|
|
885
|
+
usage.syncCount++;
|
|
886
|
+
usage.eventCount += message.events?.length || 0;
|
|
887
|
+
usage.factCount += message.facts?.length || 0;
|
|
888
|
+
usage.storageBytes += JSON.stringify(message).length;
|
|
889
|
+
usage.periodEnd = Date.now();
|
|
890
|
+
storage.usage.set(message.appId, usage);
|
|
891
|
+
context.log(`Synced for app ${message.appId}: ${usage.syncCount} total syncs`);
|
|
892
|
+
return {
|
|
893
|
+
status: 200,
|
|
894
|
+
headers: { "Content-Type": "application/json" },
|
|
895
|
+
body: {
|
|
896
|
+
success: true,
|
|
897
|
+
clock: message.clock,
|
|
898
|
+
timestamp: Date.now()
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
async function usageEndpoint(context, req) {
|
|
903
|
+
context.log("Usage metrics requested");
|
|
904
|
+
const appId = req.query.appId;
|
|
905
|
+
if (!appId) {
|
|
906
|
+
return {
|
|
907
|
+
status: 400,
|
|
908
|
+
body: { error: "appId query parameter is required" }
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
const usage = storage.usage.get(appId);
|
|
912
|
+
if (!usage) {
|
|
913
|
+
return {
|
|
914
|
+
status: 404,
|
|
915
|
+
body: { error: "No usage data found for this app" }
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
return {
|
|
919
|
+
status: 200,
|
|
920
|
+
headers: { "Content-Type": "application/json" },
|
|
921
|
+
body: usage
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
async function statsEndpoint(context, req) {
|
|
925
|
+
context.log("Stats requested");
|
|
926
|
+
const appId = req.query.appId;
|
|
927
|
+
if (!appId) {
|
|
928
|
+
return {
|
|
929
|
+
status: 400,
|
|
930
|
+
body: { error: "appId query parameter is required" }
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
const usage = storage.usage.get(appId);
|
|
934
|
+
const syncs = storage.syncs.get(appId) || [];
|
|
935
|
+
return {
|
|
936
|
+
status: 200,
|
|
937
|
+
headers: { "Content-Type": "application/json" },
|
|
938
|
+
body: {
|
|
939
|
+
appId,
|
|
940
|
+
totalSyncs: syncs.length,
|
|
941
|
+
usage: usage || null,
|
|
942
|
+
lastSync: syncs.length > 0 ? syncs[syncs.length - 1].timestamp : null
|
|
943
|
+
}
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
async function eventsEndpoint(context, req) {
|
|
947
|
+
context.log("Event forwarding requested");
|
|
948
|
+
if (req.method !== "POST") {
|
|
949
|
+
return {
|
|
950
|
+
status: 405,
|
|
951
|
+
body: { error: "Method not allowed" }
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
const { appId, events } = req.body;
|
|
955
|
+
if (!appId || !events) {
|
|
956
|
+
return {
|
|
957
|
+
status: 400,
|
|
958
|
+
body: { error: "Invalid event forwarding request" }
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
context.log(`Forwarding ${events.length} events for app ${appId}`);
|
|
962
|
+
return {
|
|
963
|
+
status: 200,
|
|
964
|
+
headers: { "Content-Type": "application/json" },
|
|
965
|
+
body: {
|
|
966
|
+
success: true,
|
|
967
|
+
forwarded: events.length,
|
|
968
|
+
timestamp: Date.now()
|
|
969
|
+
}
|
|
970
|
+
};
|
|
971
|
+
}
|
|
972
|
+
async function schemaEndpoint(context, req) {
|
|
973
|
+
context.log("Schema registry requested");
|
|
974
|
+
if (req.method === "POST") {
|
|
975
|
+
const { appId: appId2, schema } = req.body;
|
|
976
|
+
if (!appId2 || !schema) {
|
|
977
|
+
return {
|
|
978
|
+
status: 400,
|
|
979
|
+
body: { error: "Invalid schema registration request" }
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
context.log(`Schema registered for app ${appId2}`);
|
|
983
|
+
return {
|
|
984
|
+
status: 200,
|
|
985
|
+
headers: { "Content-Type": "application/json" },
|
|
986
|
+
body: {
|
|
987
|
+
success: true,
|
|
988
|
+
schemaId: `${appId2}-${Date.now()}`,
|
|
989
|
+
timestamp: Date.now()
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
const appId = req.query.appId;
|
|
994
|
+
if (!appId) {
|
|
995
|
+
return {
|
|
996
|
+
status: 400,
|
|
997
|
+
body: { error: "appId query parameter is required" }
|
|
998
|
+
};
|
|
999
|
+
}
|
|
1000
|
+
return {
|
|
1001
|
+
status: 200,
|
|
1002
|
+
headers: { "Content-Type": "application/json" },
|
|
1003
|
+
body: {
|
|
1004
|
+
appId,
|
|
1005
|
+
schema: null,
|
|
1006
|
+
message: "Schema not found"
|
|
1007
|
+
}
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
1010
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1011
|
+
0 && (module.exports = {
|
|
1012
|
+
BillingProvider,
|
|
1013
|
+
GitHubMarketplaceClient,
|
|
1014
|
+
GitHubOAuth,
|
|
1015
|
+
GitHubSponsorsClient,
|
|
1016
|
+
MARKETPLACE_PLANS,
|
|
1017
|
+
SubscriptionStatus,
|
|
1018
|
+
SubscriptionTier,
|
|
1019
|
+
TIER_LIMITS,
|
|
1020
|
+
authenticateWithDeviceFlow,
|
|
1021
|
+
checkUsageLimits,
|
|
1022
|
+
connectRelay,
|
|
1023
|
+
createCloudRelay,
|
|
1024
|
+
createFreeSubscription,
|
|
1025
|
+
createGitHubOAuth,
|
|
1026
|
+
createMarketplaceClient,
|
|
1027
|
+
createSponsorSubscription,
|
|
1028
|
+
createSponsorsClient,
|
|
1029
|
+
createTenant,
|
|
1030
|
+
eventsEndpoint,
|
|
1031
|
+
generateStorageNamespace,
|
|
1032
|
+
generateTenantId,
|
|
1033
|
+
getAppStorageContainer,
|
|
1034
|
+
getOrCreateTenant,
|
|
1035
|
+
hasAccessToTier,
|
|
1036
|
+
healthEndpoint,
|
|
1037
|
+
provisionTenant,
|
|
1038
|
+
schemaEndpoint,
|
|
1039
|
+
statsEndpoint,
|
|
1040
|
+
syncEndpoint,
|
|
1041
|
+
usageEndpoint,
|
|
1042
|
+
validateStorageNamespace
|
|
1043
|
+
});
|