@secondlayer/shared 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/db/index.d.ts +33 -1
- package/dist/src/db/queries/accounts.d.ts +27 -0
- package/dist/src/db/queries/integrity.d.ts +27 -0
- package/dist/src/db/queries/projects.d.ts +27 -0
- package/dist/src/db/queries/{marketplace.d.ts → provisioning-audit.d.ts} +48 -54
- package/dist/src/db/queries/provisioning-audit.js +40 -0
- package/dist/src/db/queries/provisioning-audit.js.map +10 -0
- package/dist/src/db/queries/subgraph-gaps.d.ts +27 -0
- package/dist/src/db/queries/subgraphs.d.ts +27 -0
- package/dist/src/db/queries/tenants.d.ts +35 -1
- package/dist/src/db/queries/tenants.js +27 -1
- package/dist/src/db/queries/tenants.js.map +3 -3
- package/dist/src/db/queries/usage.d.ts +27 -0
- package/dist/src/db/queries/workflows.d.ts +27 -0
- package/dist/src/db/schema.d.ts +33 -1
- package/dist/src/index.d.ts +60 -77
- package/dist/src/index.js +59 -69
- package/dist/src/index.js.map +4 -4
- package/dist/src/mode.d.ts +4 -5
- package/dist/src/mode.js.map +2 -2
- package/dist/src/node/local-client.d.ts +27 -0
- package/dist/src/schemas/accounts.d.ts +14 -0
- package/dist/src/schemas/{marketplace.js → accounts.js} +4 -14
- package/dist/src/schemas/accounts.js.map +10 -0
- package/dist/src/schemas/index.d.ts +28 -77
- package/dist/src/schemas/index.js +59 -69
- package/dist/src/schemas/index.js.map +4 -4
- package/migrations/0043_tenant_usage_monthly.ts +36 -0
- package/migrations/0044_provisioning_audit_log.ts +40 -0
- package/package.json +8 -8
- package/dist/src/db/queries/marketplace.js +0 -139
- package/dist/src/db/queries/marketplace.js.map +0 -10
- package/dist/src/schemas/marketplace.d.ts +0 -63
- package/dist/src/schemas/marketplace.js.map +0 -10
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/schemas/
|
|
3
|
+
"sources": ["../src/schemas/accounts.ts", "../src/schemas/filters.ts", "../src/schemas/subgraphs.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
+
"import { z } from \"zod/v4\";\n\n/**\n * Account profile shapes. Unrelated to marketplace — previously lived in\n * schemas/marketplace.ts alongside public-directory types. Kept here now\n * that marketplace is gone so the profile fields (display_name, bio, slug)\n * have a stable home.\n */\n\nexport interface UpdateProfileRequest {\n\tdisplay_name?: string;\n\tbio?: string;\n\tslug?: string;\n}\n\nexport const UpdateProfileRequestSchema: z.ZodType<UpdateProfileRequest> =\n\tz.object({\n\t\tdisplay_name: z.string().max(50).optional(),\n\t\tbio: z.string().max(300).optional(),\n\t\tslug: z\n\t\t\t.string()\n\t\t\t.regex(/^[a-z0-9-]+$/, \"lowercase alphanumeric + hyphens only\")\n\t\t\t.min(3)\n\t\t\t.max(30)\n\t\t\t.optional(),\n\t});\n",
|
|
5
6
|
"import { isValidAddress as _isValidAddress } from \"@secondlayer/stacks\";\nimport { z } from \"zod/v4\";\n\nconst isValidAddress = _isValidAddress as (addr: string) => boolean;\n\n/** Validate a Stacks principal (standard or contract, e.g. SP2J...ABC or SP2J...ABC.contract-name) */\nconst stacksPrincipal = z.string().refine((val) => {\n\tconst parts = val.split(\".\");\n\tif (parts.length > 2) return false;\n\treturn isValidAddress(parts[0]!);\n}, \"Invalid Stacks principal address\");\n\n// Base filter with common fields\nconst baseFilter = {\n\t// Optional: filter by sender\n\tsender: stacksPrincipal.optional(),\n\t// Optional: filter by recipient\n\trecipient: stacksPrincipal.optional(),\n};\n\n// Type exports — defined first so they can annotate schemas\nexport interface StxTransferFilter {\n\ttype: \"stx_transfer\";\n\tsender?: string;\n\trecipient?: string;\n\tminAmount?: number;\n\tmaxAmount?: number;\n}\n\nexport interface StxMintFilter {\n\ttype: \"stx_mint\";\n\trecipient?: string;\n\tminAmount?: number;\n}\n\nexport interface StxBurnFilter {\n\ttype: \"stx_burn\";\n\tsender?: string;\n\tminAmount?: number;\n}\n\nexport interface StxLockFilter {\n\ttype: \"stx_lock\";\n\tlockedAddress?: string;\n\tminAmount?: number;\n}\n\nexport interface FtTransferFilter {\n\ttype: \"ft_transfer\";\n\tsender?: string;\n\trecipient?: string;\n\tassetIdentifier?: string;\n\tminAmount?: number;\n}\n\nexport interface FtMintFilter {\n\ttype: \"ft_mint\";\n\trecipient?: string;\n\tassetIdentifier?: string;\n\tminAmount?: number;\n}\n\nexport interface FtBurnFilter {\n\ttype: \"ft_burn\";\n\tsender?: string;\n\tassetIdentifier?: string;\n\tminAmount?: number;\n}\n\nexport interface NftTransferFilter {\n\ttype: \"nft_transfer\";\n\tsender?: string;\n\trecipient?: string;\n\tassetIdentifier?: string;\n\ttokenId?: string;\n}\n\nexport interface NftMintFilter {\n\ttype: \"nft_mint\";\n\trecipient?: string;\n\tassetIdentifier?: string;\n\ttokenId?: string;\n}\n\nexport interface NftBurnFilter {\n\ttype: \"nft_burn\";\n\tsender?: string;\n\tassetIdentifier?: string;\n\ttokenId?: string;\n}\n\nexport interface ContractCallFilter {\n\ttype: \"contract_call\";\n\tcontractId?: string;\n\tfunctionName?: string;\n\tcaller?: string;\n}\n\nexport interface ContractDeployFilter {\n\ttype: \"contract_deploy\";\n\tdeployer?: string;\n\tcontractName?: string;\n}\n\nexport interface PrintEventFilter {\n\ttype: \"print_event\";\n\tcontractId?: string;\n\ttopic?: string;\n\tcontains?: string;\n}\n\nexport type EventFilter =\n\t| StxTransferFilter\n\t| StxMintFilter\n\t| StxBurnFilter\n\t| StxLockFilter\n\t| FtTransferFilter\n\t| FtMintFilter\n\t| FtBurnFilter\n\t| NftTransferFilter\n\t| NftMintFilter\n\t| NftBurnFilter\n\t| ContractCallFilter\n\t| ContractDeployFilter\n\t| PrintEventFilter;\n\n// STX Transfer Filter\nexport const StxTransferFilterSchema: z.ZodType<StxTransferFilter> = z.object({\n\ttype: z.literal(\"stx_transfer\"),\n\t...baseFilter,\n\t// Optional: minimum amount in microSTX\n\tminAmount: z.coerce.number().int().positive().optional(),\n\t// Optional: maximum amount in microSTX\n\tmaxAmount: z.coerce.number().int().positive().optional(),\n});\n\n// STX Mint Filter\nexport const StxMintFilterSchema: z.ZodType<StxMintFilter> = z.object({\n\ttype: z.literal(\"stx_mint\"),\n\trecipient: stacksPrincipal.optional(),\n\tminAmount: z.coerce.number().int().positive().optional(),\n});\n\n// STX Burn Filter\nexport const StxBurnFilterSchema: z.ZodType<StxBurnFilter> = z.object({\n\ttype: z.literal(\"stx_burn\"),\n\tsender: stacksPrincipal.optional(),\n\tminAmount: z.coerce.number().int().positive().optional(),\n});\n\n// STX Lock Filter\nexport const StxLockFilterSchema: z.ZodType<StxLockFilter> = z.object({\n\ttype: z.literal(\"stx_lock\"),\n\tlockedAddress: stacksPrincipal.optional(),\n\tminAmount: z.coerce.number().int().positive().optional(),\n});\n\n// FT Transfer Filter\nexport const FtTransferFilterSchema: z.ZodType<FtTransferFilter> = z.object({\n\ttype: z.literal(\"ft_transfer\"),\n\t...baseFilter,\n\t// Contract that defines the token (e.g., SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx)\n\tassetIdentifier: z.string().optional(),\n\tminAmount: z.coerce.number().int().positive().optional(),\n});\n\n// FT Mint Filter\nexport const FtMintFilterSchema: z.ZodType<FtMintFilter> = z.object({\n\ttype: z.literal(\"ft_mint\"),\n\trecipient: stacksPrincipal.optional(),\n\tassetIdentifier: z.string().optional(),\n\tminAmount: z.coerce.number().int().positive().optional(),\n});\n\n// FT Burn Filter\nexport const FtBurnFilterSchema: z.ZodType<FtBurnFilter> = z.object({\n\ttype: z.literal(\"ft_burn\"),\n\tsender: stacksPrincipal.optional(),\n\tassetIdentifier: z.string().optional(),\n\tminAmount: z.coerce.number().int().positive().optional(),\n});\n\n// NFT Transfer Filter\nexport const NftTransferFilterSchema: z.ZodType<NftTransferFilter> = z.object({\n\ttype: z.literal(\"nft_transfer\"),\n\t...baseFilter,\n\tassetIdentifier: z.string().optional(),\n\t// Optional: filter by specific token ID (Clarity value as hex)\n\ttokenId: z.string().optional(),\n});\n\n// NFT Mint Filter\nexport const NftMintFilterSchema: z.ZodType<NftMintFilter> = z.object({\n\ttype: z.literal(\"nft_mint\"),\n\trecipient: stacksPrincipal.optional(),\n\tassetIdentifier: z.string().optional(),\n\ttokenId: z.string().optional(),\n});\n\n// NFT Burn Filter\nexport const NftBurnFilterSchema: z.ZodType<NftBurnFilter> = z.object({\n\ttype: z.literal(\"nft_burn\"),\n\tsender: stacksPrincipal.optional(),\n\tassetIdentifier: z.string().optional(),\n\ttokenId: z.string().optional(),\n});\n\n// Contract Call Filter\nexport const ContractCallFilterSchema: z.ZodType<ContractCallFilter> = z.object(\n\t{\n\t\ttype: z.literal(\"contract_call\"),\n\t\t// Contract being called\n\t\tcontractId: stacksPrincipal.optional(),\n\t\t// Function name (supports wildcards with *)\n\t\tfunctionName: z.string().optional(),\n\t\t// Caller address\n\t\tcaller: stacksPrincipal.optional(),\n\t},\n);\n\n// Contract Deploy Filter\nexport const ContractDeployFilterSchema: z.ZodType<ContractDeployFilter> =\n\tz.object({\n\t\ttype: z.literal(\"contract_deploy\"),\n\t\t// Deployer address\n\t\tdeployer: stacksPrincipal.optional(),\n\t\t// Contract name pattern (supports wildcards)\n\t\tcontractName: z.string().optional(),\n\t});\n\n// Print Event Filter (smart contract events)\nexport const PrintEventFilterSchema: z.ZodType<PrintEventFilter> = z.object({\n\ttype: z.literal(\"print_event\"),\n\t// Contract emitting the event\n\tcontractId: stacksPrincipal.optional(),\n\t// Topic/name of the event\n\ttopic: z.string().optional(),\n\t// Search for substring in event data\n\tcontains: z.string().optional(),\n});\n\n// Union of all filter types\nexport const EventFilterSchema: z.ZodType<EventFilter> = z.discriminatedUnion(\n\t\"type\",\n\t[\n\t\tStxTransferFilterSchema as any,\n\t\tStxMintFilterSchema as any,\n\t\tStxBurnFilterSchema as any,\n\t\tStxLockFilterSchema as any,\n\t\tFtTransferFilterSchema as any,\n\t\tFtMintFilterSchema as any,\n\t\tFtBurnFilterSchema as any,\n\t\tNftTransferFilterSchema as any,\n\t\tNftMintFilterSchema as any,\n\t\tNftBurnFilterSchema as any,\n\t\tContractCallFilterSchema as any,\n\t\tContractDeployFilterSchema as any,\n\t\tPrintEventFilterSchema as any,\n\t],\n);\n",
|
|
6
|
-
"import { z } from \"zod/v4\";\n\n// ── Request Types ────────────────────────────────────────────────────\n\nexport interface PublishSubgraphRequest {\n\ttags?: string[];\n\tdescription?: string;\n}\n\nexport interface UpdateProfileRequest {\n\tdisplay_name?: string;\n\tbio?: string;\n\tslug?: string;\n}\n\nexport interface ForkSubgraphRequest {\n\tsourceSubgraphName: string;\n\tnewName?: string;\n}\n\n// ── Request Schemas ───────────────────────────────────────────────────\n\nexport const PublishSubgraphRequestSchema: z.ZodType<PublishSubgraphRequest> =\n\tz.object({\n\t\ttags: z.array(z.string().max(30)).max(5).optional(),\n\t\tdescription: z.string().max(500).optional(),\n\t});\n\nexport const UpdateProfileRequestSchema: z.ZodType<UpdateProfileRequest> =\n\tz.object({\n\t\tdisplay_name: z.string().max(50).optional(),\n\t\tbio: z.string().max(300).optional(),\n\t\tslug: z\n\t\t\t.string()\n\t\t\t.regex(/^[a-z0-9-]+$/, \"lowercase alphanumeric + hyphens only\")\n\t\t\t.min(3)\n\t\t\t.max(30)\n\t\t\t.optional(),\n\t});\n\nexport const ForkSubgraphRequestSchema: z.ZodType<ForkSubgraphRequest> =\n\tz.object({\n\t\tsourceSubgraphName: z.string(),\n\t\tnewName: z\n\t\t\t.string()\n\t\t\t.regex(/^[a-z0-9-]+$/, \"lowercase alphanumeric + hyphens only\")\n\t\t\t.max(63)\n\t\t\t.optional(),\n\t});\n\n// ── Response Types ────────────────────────────────────────────────────\n\nexport interface MarketplaceCreator {\n\tdisplayName: string | null;\n\tslug: string | null;\n}\n\nexport interface MarketplaceSubgraphSummary {\n\tname: string;\n\tdescription: string | null;\n\ttags: string[];\n\tcreator: MarketplaceCreator;\n\tstatus: string;\n\tversion: string;\n\ttables: string[];\n\ttotalQueries7d: number;\n\tprogress: number;\n\tcreatedAt: string;\n}\n\nexport interface MarketplaceSubgraphDetail extends MarketplaceSubgraphSummary {\n\ttableSchemas: Record<\n\t\tstring,\n\t\t{\n\t\t\tcolumns: Record<string, { type: string; nullable?: boolean }>;\n\t\t\trowCount: number;\n\t\t\tendpoint: string;\n\t\t}\n\t>;\n\tsources: Record<string, unknown>;\n\tstartBlock: number;\n\tlastProcessedBlock: number;\n\tforkedFrom: string | null;\n\tusage: {\n\t\ttotalQueries7d: number;\n\t\ttotalQueries30d: number;\n\t\tdaily: Array<{ date: string; count: number }>;\n\t};\n}\n\nexport interface CreatorProfile {\n\tdisplayName: string | null;\n\tbio: string | null;\n\tavatarUrl: string | null;\n\tslug: string | null;\n\tsubgraphs: MarketplaceSubgraphSummary[];\n}\n",
|
|
7
7
|
"import { z } from \"zod/v4\";\n\n// ── Deploy Subgraph Request ─────────────────────────────────────────────────\n\nexport interface DeploySubgraphRequest {\n\tname: string;\n\tversion?: string;\n\tdescription?: string;\n\tsources: Record<string, Record<string, unknown>>;\n\tschema: Record<string, unknown>;\n\thandlerCode: string;\n\t/** Original TypeScript source, persisted so chat can read/diff/edit later. */\n\tsourceCode?: string;\n\t/** @deprecated Use server auto-reindex on breaking changes instead */\n\treindex?: boolean;\n}\n\nexport const DeploySubgraphRequestSchema: z.ZodType<DeploySubgraphRequest> =\n\tz.object({\n\t\tname: z\n\t\t\t.string()\n\t\t\t.regex(/^[a-z0-9-]+$/, \"lowercase alphanumeric + hyphens only\")\n\t\t\t.max(63),\n\t\tversion: z.string().optional(),\n\t\tdescription: z.string().optional(),\n\t\tsources: z\n\t\t\t.record(z.string(), z.record(z.string(), z.unknown()))\n\t\t\t.refine(\n\t\t\t\t(s) => Object.keys(s).length > 0,\n\t\t\t\t\"Must have at least one source\",\n\t\t\t),\n\t\tschema: z.record(z.string(), z.unknown()),\n\t\thandlerCode: z.string().max(1_048_576, \"handler code exceeds 1MB limit\"),\n\t\tsourceCode: z\n\t\t\t.string()\n\t\t\t.max(1_048_576, \"source code exceeds 1MB limit\")\n\t\t\t.optional(),\n\t\treindex: z.boolean().optional(),\n\t});\n\nexport interface DeploySubgraphResponse {\n\taction: \"created\" | \"unchanged\" | \"updated\" | \"reindexed\";\n\tsubgraphId: string;\n\tversion: string;\n\tmessage: string;\n\tdiff?: {\n\t\taddedTables: string[];\n\t\tremovedTables: string[];\n\t\taddedColumns: Record<string, string[]>;\n\t\tbreakingChanges: string[];\n\t};\n}\n\n// Subgraph API response types\n\nexport interface SubgraphSummary {\n\tname: string;\n\tversion: string;\n\tstatus: string;\n\tlastProcessedBlock: number;\n\ttotalProcessed: number;\n\ttotalErrors: number;\n\ttables: string[];\n\tchainTip: number;\n\tprogress: number;\n\tgapCount: number;\n\tintegrity: \"complete\" | \"gaps_detected\";\n\tcreatedAt: string;\n}\n\nexport interface SubgraphGapRange {\n\tstart: number;\n\tend: number;\n\tsize: number;\n\treason: string;\n}\n\nexport interface SubgraphSyncInfo {\n\tstatus: \"synced\" | \"catching_up\" | \"reindexing\" | \"error\";\n\tstartBlock: number;\n\tlastProcessedBlock: number;\n\tchainTip: number;\n\tblocksRemaining: number;\n\tprogress: number;\n\tgaps: {\n\t\tcount: number;\n\t\ttotalMissingBlocks: number;\n\t\tranges: SubgraphGapRange[];\n\t};\n\tintegrity: \"complete\" | \"gaps_detected\";\n}\n\nexport interface SubgraphDetail {\n\tname: string;\n\tversion: string;\n\tstatus: string;\n\tlastProcessedBlock: number;\n\thealth: {\n\t\ttotalProcessed: number;\n\t\ttotalErrors: number;\n\t\terrorRate: number;\n\t\tlastError: string | null;\n\t\tlastErrorAt: string | null;\n\t};\n\tsync: SubgraphSyncInfo;\n\ttables: Record<\n\t\tstring,\n\t\t{\n\t\t\tendpoint: string;\n\t\t\tcolumns: Record<string, { type: string; nullable?: boolean }>;\n\t\t\trowCount: number;\n\t\t\texample: string;\n\t\t}\n\t>;\n\tcreatedAt: string;\n\tupdatedAt: string;\n}\n\nexport interface SubgraphGapEntry {\n\tstart: number;\n\tend: number;\n\tsize: number;\n\treason: string;\n\tdetectedAt: string;\n\tresolvedAt: string | null;\n}\n\nexport interface SubgraphGapsResponse {\n\tdata: SubgraphGapEntry[];\n\tmeta: {\n\t\ttotal: number;\n\t\ttotalMissingBlocks: number;\n\t\tlimit: number;\n\t\toffset: number;\n\t};\n}\n\nexport interface ReindexResponse {\n\tmessage: string;\n\tfromBlock: number;\n\ttoBlock: number | string;\n}\n\nexport interface SubgraphQueryParams {\n\tsort?: string;\n\torder?: string;\n\tlimit?: number;\n\toffset?: number;\n\tfields?: string;\n\tfilters?: Record<string, string>;\n}\n"
|
|
8
8
|
],
|
|
9
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA,2BAAS;AACT;
|
|
10
|
-
"debugId": "
|
|
9
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAeO,IAAM,6BACZ,EAAE,OAAO;AAAA,EACR,cAAc,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,SAAS;AAAA,EAC1C,KAAK,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,SAAS;AAAA,EAClC,MAAM,EACJ,OAAO,EACP,MAAM,gBAAgB,uCAAuC,EAC7D,IAAI,CAAC,EACL,IAAI,EAAE,EACN,SAAS;AACZ,CAAC;;;ACzBF,2BAAS;AACT,cAAS;AAET,IAAM,iBAAiB;AAGvB,IAAM,kBAAkB,GAAE,OAAO,EAAE,OAAO,CAAC,QAAQ;AAAA,EAClD,MAAM,QAAQ,IAAI,MAAM,GAAG;AAAA,EAC3B,IAAI,MAAM,SAAS;AAAA,IAAG,OAAO;AAAA,EAC7B,OAAO,eAAe,MAAM,EAAG;AAAA,GAC7B,kCAAkC;AAGrC,IAAM,aAAa;AAAA,EAElB,QAAQ,gBAAgB,SAAS;AAAA,EAEjC,WAAW,gBAAgB,SAAS;AACrC;AA6GO,IAAM,0BAAwD,GAAE,OAAO;A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EAE7B,YAAY,gBAAgB,SAAS;AAAA,EAErC,OAAO,GAAE,OAAO,EAAE,SAAS;AAAA,EAE3B,UAAU,GAAE,OAAO,EAAE,SAAS;AAC/B,CAAC;AAGM,IAAM,oBAA4C,GAAE,mBAC1D,QACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,CACD;;;ACnQA,cAAS;AAiBF,IAAM,8BACZ,GAAE,OAAO;AAAA,EACR,MAAM,GACJ,OAAO,EACP,MAAM,gBAAgB,uCAAuC,EAC7D,IAAI,EAAE;AAAA,EACR,SAAS,GAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,aAAa,GAAE,OAAO,EAAE,SAAS;AAAA,EACjC,SAAS,GACP,OAAO,GAAE,OAAO,GAAG,GAAE,OAAO,GAAE,OAAO,GAAG,GAAE,QAAQ,CAAC,CAAC,EACpD,OACA,CAAC,MAAM,OAAO,KAAK,CAAC,EAAE,SAAS,GAC/B,+BACD;AAAA,EACD,QAAQ,GAAE,OAAO,GAAE,OAAO,GAAG,GAAE,QAAQ,CAAC;AAAA,EACxC,aAAa,GAAE,OAAO,EAAE,IAAI,SAAW,gCAAgC;AAAA,EACvE,YAAY,GACV,OAAO,EACP,IAAI,SAAW,+BAA+B,EAC9C,SAAS;AAAA,EACX,SAAS,GAAE,QAAQ,EAAE,SAAS;AAC/B,CAAC;",
|
|
10
|
+
"debugId": "C2E332004F21E1EA64756E2164756E21",
|
|
11
11
|
"names": []
|
|
12
12
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Kysely, sql } from "kysely";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Monthly usage snapshots for tenants. Billing lands later; this table
|
|
5
|
+
* captures the raw measurements so we can backfill charges once pricing
|
|
6
|
+
* ships.
|
|
7
|
+
*
|
|
8
|
+
* One row per (tenant_id, period_month). The period_month is the first
|
|
9
|
+
* day of the calendar month in UTC (e.g. 2026-04-01). `storage_peak_mb`
|
|
10
|
+
* is the max observation within the period; `measurements` counts how
|
|
11
|
+
* many samples fed into peak/avg so we can judge confidence.
|
|
12
|
+
*/
|
|
13
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
14
|
+
await sql`
|
|
15
|
+
CREATE TABLE tenant_usage_monthly (
|
|
16
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
17
|
+
tenant_id uuid NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
|
|
18
|
+
period_month date NOT NULL,
|
|
19
|
+
storage_peak_mb integer NOT NULL DEFAULT 0,
|
|
20
|
+
storage_avg_mb integer NOT NULL DEFAULT 0,
|
|
21
|
+
storage_last_mb integer NOT NULL DEFAULT 0,
|
|
22
|
+
measurements integer NOT NULL DEFAULT 0,
|
|
23
|
+
first_at timestamptz NOT NULL DEFAULT now(),
|
|
24
|
+
last_at timestamptz NOT NULL DEFAULT now(),
|
|
25
|
+
UNIQUE (tenant_id, period_month)
|
|
26
|
+
)
|
|
27
|
+
`.execute(db);
|
|
28
|
+
await sql`
|
|
29
|
+
CREATE INDEX tenant_usage_monthly_period_idx
|
|
30
|
+
ON tenant_usage_monthly (period_month DESC)
|
|
31
|
+
`.execute(db);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
35
|
+
await sql`DROP TABLE IF EXISTS tenant_usage_monthly`.execute(db);
|
|
36
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type Kysely, sql } from "kysely";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Audit trail of provisioning-facing lifecycle events. Captures what
|
|
5
|
+
* happened, who triggered it, and the outcome — source of truth for
|
|
6
|
+
* post-incident review and billing disputes.
|
|
7
|
+
*
|
|
8
|
+
* `tenant_id` is nullable so provision-start rows (where the tenant row
|
|
9
|
+
* does not yet exist) can be recorded alongside lifecycle events on an
|
|
10
|
+
* existing tenant.
|
|
11
|
+
*/
|
|
12
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
13
|
+
await sql`
|
|
14
|
+
CREATE TABLE provisioning_audit_log (
|
|
15
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
16
|
+
tenant_id uuid REFERENCES tenants(id) ON DELETE SET NULL,
|
|
17
|
+
tenant_slug text,
|
|
18
|
+
account_id uuid REFERENCES accounts(id) ON DELETE SET NULL,
|
|
19
|
+
actor text NOT NULL,
|
|
20
|
+
event text NOT NULL,
|
|
21
|
+
status text NOT NULL,
|
|
22
|
+
detail jsonb,
|
|
23
|
+
error text,
|
|
24
|
+
created_at timestamptz NOT NULL DEFAULT now()
|
|
25
|
+
)
|
|
26
|
+
`.execute(db);
|
|
27
|
+
await sql`CREATE INDEX provisioning_audit_tenant_idx ON provisioning_audit_log (tenant_id, created_at DESC)`.execute(
|
|
28
|
+
db,
|
|
29
|
+
);
|
|
30
|
+
await sql`CREATE INDEX provisioning_audit_account_idx ON provisioning_audit_log (account_id, created_at DESC)`.execute(
|
|
31
|
+
db,
|
|
32
|
+
);
|
|
33
|
+
await sql`CREATE INDEX provisioning_audit_event_idx ON provisioning_audit_log (event, created_at DESC)`.execute(
|
|
34
|
+
db,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
39
|
+
await sql`DROP TABLE IF EXISTS provisioning_audit_log`.execute(db);
|
|
40
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@secondlayer/shared",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/src/index.js",
|
|
6
6
|
"types": "./dist/src/index.d.ts",
|
|
@@ -61,9 +61,9 @@
|
|
|
61
61
|
"types": "./dist/src/schemas/subgraphs.d.ts",
|
|
62
62
|
"import": "./dist/src/schemas/subgraphs.js"
|
|
63
63
|
},
|
|
64
|
-
"./schemas/
|
|
65
|
-
"types": "./dist/src/schemas/
|
|
66
|
-
"import": "./dist/src/schemas/
|
|
64
|
+
"./schemas/accounts": {
|
|
65
|
+
"types": "./dist/src/schemas/accounts.d.ts",
|
|
66
|
+
"import": "./dist/src/schemas/accounts.js"
|
|
67
67
|
},
|
|
68
68
|
"./schemas/workflows": {
|
|
69
69
|
"types": "./dist/src/schemas/workflows.d.ts",
|
|
@@ -77,14 +77,14 @@
|
|
|
77
77
|
"types": "./dist/src/db/queries/tenants.d.ts",
|
|
78
78
|
"import": "./dist/src/db/queries/tenants.js"
|
|
79
79
|
},
|
|
80
|
-
"./db/queries/marketplace": {
|
|
81
|
-
"types": "./dist/src/db/queries/marketplace.d.ts",
|
|
82
|
-
"import": "./dist/src/db/queries/marketplace.js"
|
|
83
|
-
},
|
|
84
80
|
"./db/queries/projects": {
|
|
85
81
|
"types": "./dist/src/db/queries/projects.d.ts",
|
|
86
82
|
"import": "./dist/src/db/queries/projects.js"
|
|
87
83
|
},
|
|
84
|
+
"./db/queries/provisioning-audit": {
|
|
85
|
+
"types": "./dist/src/db/queries/provisioning-audit.d.ts",
|
|
86
|
+
"import": "./dist/src/db/queries/provisioning-audit.js"
|
|
87
|
+
},
|
|
88
88
|
"./types": {
|
|
89
89
|
"types": "./dist/src/types.d.ts",
|
|
90
90
|
"import": "./dist/src/types.js"
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __returnValue = (v) => v;
|
|
4
|
-
function __exportSetter(name, newValue) {
|
|
5
|
-
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
-
}
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, {
|
|
10
|
-
get: all[name],
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
set: __exportSetter.bind(all, name)
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// src/db/queries/marketplace.ts
|
|
18
|
-
import { sql } from "kysely";
|
|
19
|
-
async function listPublicSubgraphs(db, opts = {}) {
|
|
20
|
-
const limit = Math.min(Math.max(1, opts.limit ?? 50), 100);
|
|
21
|
-
const offset = Math.max(0, opts.offset ?? 0);
|
|
22
|
-
let query = db.selectFrom("subgraphs").innerJoin("accounts", "accounts.id", "subgraphs.account_id").select([
|
|
23
|
-
"subgraphs.id",
|
|
24
|
-
"subgraphs.name",
|
|
25
|
-
"subgraphs.description",
|
|
26
|
-
"subgraphs.tags",
|
|
27
|
-
"subgraphs.status",
|
|
28
|
-
"subgraphs.version",
|
|
29
|
-
"subgraphs.definition",
|
|
30
|
-
"subgraphs.last_processed_block",
|
|
31
|
-
"subgraphs.start_block",
|
|
32
|
-
"subgraphs.total_processed",
|
|
33
|
-
"subgraphs.created_at",
|
|
34
|
-
"subgraphs.forked_from_id",
|
|
35
|
-
"accounts.display_name",
|
|
36
|
-
"accounts.slug",
|
|
37
|
-
sql`(SELECT COALESCE(SUM(query_count), 0) FROM subgraph_usage_daily WHERE subgraph_id = subgraphs.id AND date >= CURRENT_DATE - 7)::int`.as("queries_7d"),
|
|
38
|
-
sql`(SELECT COUNT(*) FROM subgraphs s2 WHERE s2.forked_from_id = subgraphs.id)::int`.as("fork_count")
|
|
39
|
-
]).where("subgraphs.is_public", "=", true);
|
|
40
|
-
if (opts.tags && opts.tags.length > 0) {
|
|
41
|
-
query = query.where(sql`subgraphs.tags @> ${sql.val(opts.tags)}::text[]`);
|
|
42
|
-
}
|
|
43
|
-
if (opts.search) {
|
|
44
|
-
const term = `%${opts.search}%`;
|
|
45
|
-
query = query.where((eb) => eb.or([
|
|
46
|
-
eb("subgraphs.name", "ilike", term),
|
|
47
|
-
eb("subgraphs.description", "ilike", term)
|
|
48
|
-
]));
|
|
49
|
-
}
|
|
50
|
-
if (opts.sort === "popular") {
|
|
51
|
-
query = query.orderBy(sql`queries_7d`, "desc");
|
|
52
|
-
} else if (opts.sort === "name") {
|
|
53
|
-
query = query.orderBy("subgraphs.name", "asc");
|
|
54
|
-
} else {
|
|
55
|
-
query = query.orderBy("subgraphs.created_at", "desc");
|
|
56
|
-
}
|
|
57
|
-
let countQuery = db.selectFrom("subgraphs").select(sql`count(*)::int`.as("count")).where("is_public", "=", true);
|
|
58
|
-
if (opts.tags && opts.tags.length > 0) {
|
|
59
|
-
countQuery = countQuery.where(sql`tags @> ${sql.val(opts.tags)}::text[]`);
|
|
60
|
-
}
|
|
61
|
-
if (opts.search) {
|
|
62
|
-
const term = `%${opts.search}%`;
|
|
63
|
-
countQuery = countQuery.where((eb) => eb.or([eb("name", "ilike", term), eb("description", "ilike", term)]));
|
|
64
|
-
}
|
|
65
|
-
const [rows, countRow] = await Promise.all([
|
|
66
|
-
query.limit(limit).offset(offset).execute(),
|
|
67
|
-
countQuery.executeTakeFirst()
|
|
68
|
-
]);
|
|
69
|
-
return {
|
|
70
|
-
data: rows,
|
|
71
|
-
meta: { total: countRow?.count ?? 0, limit, offset }
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
async function getPublicSubgraph(db, name) {
|
|
75
|
-
return db.selectFrom("subgraphs").innerJoin("accounts", "accounts.id", "subgraphs.account_id").selectAll("subgraphs").select(["accounts.display_name", "accounts.slug"]).where("subgraphs.name", "=", name).where("subgraphs.is_public", "=", true).executeTakeFirst();
|
|
76
|
-
}
|
|
77
|
-
async function getCreatorProfile(db, slug) {
|
|
78
|
-
const account = await db.selectFrom("accounts").select(["id", "display_name", "bio", "avatar_url", "slug"]).where("slug", "=", slug).executeTakeFirst();
|
|
79
|
-
if (!account)
|
|
80
|
-
return null;
|
|
81
|
-
const subgraphs = await db.selectFrom("subgraphs").select([
|
|
82
|
-
"subgraphs.id",
|
|
83
|
-
"subgraphs.name",
|
|
84
|
-
"subgraphs.description",
|
|
85
|
-
"subgraphs.tags",
|
|
86
|
-
"subgraphs.status",
|
|
87
|
-
"subgraphs.version",
|
|
88
|
-
"subgraphs.definition",
|
|
89
|
-
"subgraphs.last_processed_block",
|
|
90
|
-
"subgraphs.start_block",
|
|
91
|
-
"subgraphs.total_processed",
|
|
92
|
-
"subgraphs.created_at",
|
|
93
|
-
sql`(SELECT COALESCE(SUM(query_count), 0) FROM subgraph_usage_daily WHERE subgraph_id = subgraphs.id AND date >= CURRENT_DATE - 7)::int`.as("queries_7d")
|
|
94
|
-
]).where("subgraphs.account_id", "=", account.id).where("subgraphs.is_public", "=", true).orderBy("subgraphs.created_at", "desc").execute();
|
|
95
|
-
return { account, subgraphs };
|
|
96
|
-
}
|
|
97
|
-
async function publishSubgraph(db, subgraphId, opts) {
|
|
98
|
-
const set = {
|
|
99
|
-
is_public: true,
|
|
100
|
-
updated_at: new Date
|
|
101
|
-
};
|
|
102
|
-
if (opts?.tags)
|
|
103
|
-
set.tags = sql`${sql.val(opts.tags)}::text[]`;
|
|
104
|
-
if (opts?.description !== undefined)
|
|
105
|
-
set.description = opts.description;
|
|
106
|
-
return db.updateTable("subgraphs").set(set).where("id", "=", subgraphId).returningAll().executeTakeFirstOrThrow();
|
|
107
|
-
}
|
|
108
|
-
async function unpublishSubgraph(db, subgraphId) {
|
|
109
|
-
return db.updateTable("subgraphs").set({ is_public: false, updated_at: new Date }).where("id", "=", subgraphId).returningAll().executeTakeFirstOrThrow();
|
|
110
|
-
}
|
|
111
|
-
async function incrementSubgraphQueryCount(db, subgraphId) {
|
|
112
|
-
const today = new Date().toISOString().slice(0, 10);
|
|
113
|
-
await sql`
|
|
114
|
-
INSERT INTO subgraph_usage_daily (subgraph_id, date, query_count)
|
|
115
|
-
VALUES (${subgraphId}, ${today}, 1)
|
|
116
|
-
ON CONFLICT (subgraph_id, date)
|
|
117
|
-
DO UPDATE SET query_count = subgraph_usage_daily.query_count + 1
|
|
118
|
-
`.execute(db);
|
|
119
|
-
}
|
|
120
|
-
async function getSubgraphUsageHistory(db, subgraphId, days) {
|
|
121
|
-
return db.selectFrom("subgraph_usage_daily").select(["date", "query_count"]).where("subgraph_id", "=", subgraphId).where("date", ">=", sql`CURRENT_DATE - ${days}::int`).orderBy("date", "asc").execute();
|
|
122
|
-
}
|
|
123
|
-
async function getSubgraphQueryTotal(db, subgraphId, days) {
|
|
124
|
-
const row = await db.selectFrom("subgraph_usage_daily").select(sql`COALESCE(SUM(query_count), 0)::int`.as("total")).where("subgraph_id", "=", subgraphId).where("date", ">=", sql`CURRENT_DATE - ${days}::int`).executeTakeFirst();
|
|
125
|
-
return row?.total ?? 0;
|
|
126
|
-
}
|
|
127
|
-
export {
|
|
128
|
-
unpublishSubgraph,
|
|
129
|
-
publishSubgraph,
|
|
130
|
-
listPublicSubgraphs,
|
|
131
|
-
incrementSubgraphQueryCount,
|
|
132
|
-
getSubgraphUsageHistory,
|
|
133
|
-
getSubgraphQueryTotal,
|
|
134
|
-
getPublicSubgraph,
|
|
135
|
-
getCreatorProfile
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
//# debugId=C477C503DAA658BE64756E2164756E21
|
|
139
|
-
//# sourceMappingURL=marketplace.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/db/queries/marketplace.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import { type Kysely, sql } from \"kysely\";\nimport type { Database, Subgraph } from \"../types.ts\";\n\n/**\n * List public subgraphs with creator info and usage stats.\n */\nexport async function listPublicSubgraphs(\n\tdb: Kysely<Database>,\n\topts: {\n\t\tlimit?: number;\n\t\toffset?: number;\n\t\ttags?: string[];\n\t\tsearch?: string;\n\t\tsort?: \"recent\" | \"popular\" | \"name\";\n\t} = {},\n): Promise<{\n\tdata: any[];\n\tmeta: { total: number; limit: number; offset: number };\n}> {\n\tconst limit = Math.min(Math.max(1, opts.limit ?? 50), 100);\n\tconst offset = Math.max(0, opts.offset ?? 0);\n\n\tlet query = db\n\t\t.selectFrom(\"subgraphs\")\n\t\t.innerJoin(\"accounts\", \"accounts.id\", \"subgraphs.account_id\")\n\t\t.select([\n\t\t\t\"subgraphs.id\",\n\t\t\t\"subgraphs.name\",\n\t\t\t\"subgraphs.description\",\n\t\t\t\"subgraphs.tags\",\n\t\t\t\"subgraphs.status\",\n\t\t\t\"subgraphs.version\",\n\t\t\t\"subgraphs.definition\",\n\t\t\t\"subgraphs.last_processed_block\",\n\t\t\t\"subgraphs.start_block\",\n\t\t\t\"subgraphs.total_processed\",\n\t\t\t\"subgraphs.created_at\",\n\t\t\t\"subgraphs.forked_from_id\",\n\t\t\t\"accounts.display_name\",\n\t\t\t\"accounts.slug\",\n\t\t\tsql<number>`(SELECT COALESCE(SUM(query_count), 0) FROM subgraph_usage_daily WHERE subgraph_id = subgraphs.id AND date >= CURRENT_DATE - 7)::int`.as(\n\t\t\t\t\"queries_7d\",\n\t\t\t),\n\t\t\tsql<number>`(SELECT COUNT(*) FROM subgraphs s2 WHERE s2.forked_from_id = subgraphs.id)::int`.as(\n\t\t\t\t\"fork_count\",\n\t\t\t),\n\t\t])\n\t\t.where(\"subgraphs.is_public\", \"=\", true);\n\n\t// Filter by tags (AND — all must match)\n\tif (opts.tags && opts.tags.length > 0) {\n\t\tquery = query.where(\n\t\t\tsql<boolean>`subgraphs.tags @> ${sql.val(opts.tags)}::text[]`,\n\t\t);\n\t}\n\n\t// Search by name or description\n\tif (opts.search) {\n\t\tconst term = `%${opts.search}%`;\n\t\tquery = query.where((eb) =>\n\t\t\teb.or([\n\t\t\t\teb(\"subgraphs.name\", \"ilike\", term),\n\t\t\t\teb(\"subgraphs.description\", \"ilike\", term),\n\t\t\t]),\n\t\t);\n\t}\n\n\t// Sort\n\tif (opts.sort === \"popular\") {\n\t\tquery = query.orderBy(sql`queries_7d`, \"desc\");\n\t} else if (opts.sort === \"name\") {\n\t\tquery = query.orderBy(\"subgraphs.name\", \"asc\");\n\t} else {\n\t\t// Default: recent\n\t\tquery = query.orderBy(\"subgraphs.created_at\", \"desc\");\n\t}\n\n\t// Count\n\tlet countQuery = db\n\t\t.selectFrom(\"subgraphs\")\n\t\t.select(sql<number>`count(*)::int`.as(\"count\"))\n\t\t.where(\"is_public\", \"=\", true);\n\n\tif (opts.tags && opts.tags.length > 0) {\n\t\tcountQuery = countQuery.where(\n\t\t\tsql<boolean>`tags @> ${sql.val(opts.tags)}::text[]`,\n\t\t);\n\t}\n\tif (opts.search) {\n\t\tconst term = `%${opts.search}%`;\n\t\tcountQuery = countQuery.where((eb) =>\n\t\t\teb.or([eb(\"name\", \"ilike\", term), eb(\"description\", \"ilike\", term)]),\n\t\t);\n\t}\n\n\tconst [rows, countRow] = await Promise.all([\n\t\tquery.limit(limit).offset(offset).execute(),\n\t\tcountQuery.executeTakeFirst(),\n\t]);\n\n\treturn {\n\t\tdata: rows,\n\t\tmeta: { total: countRow?.count ?? 0, limit, offset },\n\t};\n}\n\n/**\n * Get a single public subgraph by name with creator info.\n */\nexport async function getPublicSubgraph(\n\tdb: Kysely<Database>,\n\tname: string,\n): Promise<any | undefined> {\n\treturn db\n\t\t.selectFrom(\"subgraphs\")\n\t\t.innerJoin(\"accounts\", \"accounts.id\", \"subgraphs.account_id\")\n\t\t.selectAll(\"subgraphs\")\n\t\t.select([\"accounts.display_name\", \"accounts.slug\"])\n\t\t.where(\"subgraphs.name\", \"=\", name)\n\t\t.where(\"subgraphs.is_public\", \"=\", true)\n\t\t.executeTakeFirst();\n}\n\n/**\n * Get a creator profile by slug with their public subgraphs.\n */\nexport async function getCreatorProfile(\n\tdb: Kysely<Database>,\n\tslug: string,\n): Promise<{ account: any; subgraphs: any[] } | null> {\n\tconst account = await db\n\t\t.selectFrom(\"accounts\")\n\t\t.select([\"id\", \"display_name\", \"bio\", \"avatar_url\", \"slug\"])\n\t\t.where(\"slug\", \"=\", slug)\n\t\t.executeTakeFirst();\n\n\tif (!account) return null;\n\n\tconst subgraphs = await db\n\t\t.selectFrom(\"subgraphs\")\n\t\t.select([\n\t\t\t\"subgraphs.id\",\n\t\t\t\"subgraphs.name\",\n\t\t\t\"subgraphs.description\",\n\t\t\t\"subgraphs.tags\",\n\t\t\t\"subgraphs.status\",\n\t\t\t\"subgraphs.version\",\n\t\t\t\"subgraphs.definition\",\n\t\t\t\"subgraphs.last_processed_block\",\n\t\t\t\"subgraphs.start_block\",\n\t\t\t\"subgraphs.total_processed\",\n\t\t\t\"subgraphs.created_at\",\n\t\t\tsql<number>`(SELECT COALESCE(SUM(query_count), 0) FROM subgraph_usage_daily WHERE subgraph_id = subgraphs.id AND date >= CURRENT_DATE - 7)::int`.as(\n\t\t\t\t\"queries_7d\",\n\t\t\t),\n\t\t])\n\t\t.where(\"subgraphs.account_id\", \"=\", account.id)\n\t\t.where(\"subgraphs.is_public\", \"=\", true)\n\t\t.orderBy(\"subgraphs.created_at\", \"desc\")\n\t\t.execute();\n\n\treturn { account, subgraphs };\n}\n\n/**\n * Publish a subgraph (set is_public = true).\n */\nexport async function publishSubgraph(\n\tdb: Kysely<Database>,\n\tsubgraphId: string,\n\topts?: { tags?: string[]; description?: string },\n): Promise<Subgraph> {\n\tconst set: Record<string, unknown> = {\n\t\tis_public: true,\n\t\tupdated_at: new Date(),\n\t};\n\tif (opts?.tags) set.tags = sql`${sql.val(opts.tags)}::text[]`;\n\tif (opts?.description !== undefined) set.description = opts.description;\n\n\treturn db\n\t\t.updateTable(\"subgraphs\")\n\t\t.set(set)\n\t\t.where(\"id\", \"=\", subgraphId)\n\t\t.returningAll()\n\t\t.executeTakeFirstOrThrow();\n}\n\n/**\n * Unpublish a subgraph (set is_public = false).\n */\nexport async function unpublishSubgraph(\n\tdb: Kysely<Database>,\n\tsubgraphId: string,\n): Promise<Subgraph> {\n\treturn db\n\t\t.updateTable(\"subgraphs\")\n\t\t.set({ is_public: false, updated_at: new Date() })\n\t\t.where(\"id\", \"=\", subgraphId)\n\t\t.returningAll()\n\t\t.executeTakeFirstOrThrow();\n}\n\n/**\n * Increment per-subgraph query count for today. Fire-and-forget safe.\n */\nexport async function incrementSubgraphQueryCount(\n\tdb: Kysely<Database>,\n\tsubgraphId: string,\n): Promise<void> {\n\tconst today = new Date().toISOString().slice(0, 10);\n\tawait sql`\n\t\tINSERT INTO subgraph_usage_daily (subgraph_id, date, query_count)\n\t\tVALUES (${subgraphId}, ${today}, 1)\n\t\tON CONFLICT (subgraph_id, date)\n\t\tDO UPDATE SET query_count = subgraph_usage_daily.query_count + 1\n\t`.execute(db);\n}\n\n/**\n * Get daily usage history for a subgraph.\n */\nexport async function getSubgraphUsageHistory(\n\tdb: Kysely<Database>,\n\tsubgraphId: string,\n\tdays: number,\n): Promise<Array<{ date: string; query_count: number }>> {\n\treturn db\n\t\t.selectFrom(\"subgraph_usage_daily\")\n\t\t.select([\"date\", \"query_count\"])\n\t\t.where(\"subgraph_id\", \"=\", subgraphId)\n\t\t.where(\"date\", \">=\", sql<string>`CURRENT_DATE - ${days}::int`)\n\t\t.orderBy(\"date\", \"asc\")\n\t\t.execute();\n}\n\n/**\n * Get total query count for a subgraph over last N days.\n */\nexport async function getSubgraphQueryTotal(\n\tdb: Kysely<Database>,\n\tsubgraphId: string,\n\tdays: number,\n): Promise<number> {\n\tconst row = await db\n\t\t.selectFrom(\"subgraph_usage_daily\")\n\t\t.select(sql<number>`COALESCE(SUM(query_count), 0)::int`.as(\"total\"))\n\t\t.where(\"subgraph_id\", \"=\", subgraphId)\n\t\t.where(\"date\", \">=\", sql<string>`CURRENT_DATE - ${days}::int`)\n\t\t.executeTakeFirst();\n\treturn row?.total ?? 0;\n}\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAMA,eAAsB,mBAAmB,CACxC,IACA,OAMI,CAAC,GAIH;AAAA,EACF,MAAM,QAAQ,KAAK,IAAI,KAAK,IAAI,GAAG,KAAK,SAAS,E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A,EAClB,MAAM,MAAM,MAAM,GAChB,WAAW,sBAAsB,EACjC,OAAO,wCAAgD,GAAG,OAAO,CAAC,EAClE,MAAM,eAAe,KAAK,UAAU,EACpC,MAAM,QAAQ,MAAM,qBAA6B,WAAW,EAC5D,iBAAiB;AAAA,EACnB,OAAO,KAAK,SAAS;AAAA;",
|
|
8
|
-
"debugId": "C477C503DAA658BE64756E2164756E21",
|
|
9
|
-
"names": []
|
|
10
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/v4";
|
|
2
|
-
interface PublishSubgraphRequest {
|
|
3
|
-
tags?: string[];
|
|
4
|
-
description?: string;
|
|
5
|
-
}
|
|
6
|
-
interface UpdateProfileRequest {
|
|
7
|
-
display_name?: string;
|
|
8
|
-
bio?: string;
|
|
9
|
-
slug?: string;
|
|
10
|
-
}
|
|
11
|
-
interface ForkSubgraphRequest {
|
|
12
|
-
sourceSubgraphName: string;
|
|
13
|
-
newName?: string;
|
|
14
|
-
}
|
|
15
|
-
declare const PublishSubgraphRequestSchema: z.ZodType<PublishSubgraphRequest>;
|
|
16
|
-
declare const UpdateProfileRequestSchema: z.ZodType<UpdateProfileRequest>;
|
|
17
|
-
declare const ForkSubgraphRequestSchema: z.ZodType<ForkSubgraphRequest>;
|
|
18
|
-
interface MarketplaceCreator {
|
|
19
|
-
displayName: string | null;
|
|
20
|
-
slug: string | null;
|
|
21
|
-
}
|
|
22
|
-
interface MarketplaceSubgraphSummary {
|
|
23
|
-
name: string;
|
|
24
|
-
description: string | null;
|
|
25
|
-
tags: string[];
|
|
26
|
-
creator: MarketplaceCreator;
|
|
27
|
-
status: string;
|
|
28
|
-
version: string;
|
|
29
|
-
tables: string[];
|
|
30
|
-
totalQueries7d: number;
|
|
31
|
-
progress: number;
|
|
32
|
-
createdAt: string;
|
|
33
|
-
}
|
|
34
|
-
interface MarketplaceSubgraphDetail extends MarketplaceSubgraphSummary {
|
|
35
|
-
tableSchemas: Record<string, {
|
|
36
|
-
columns: Record<string, {
|
|
37
|
-
type: string
|
|
38
|
-
nullable?: boolean
|
|
39
|
-
}>
|
|
40
|
-
rowCount: number
|
|
41
|
-
endpoint: string
|
|
42
|
-
}>;
|
|
43
|
-
sources: Record<string, unknown>;
|
|
44
|
-
startBlock: number;
|
|
45
|
-
lastProcessedBlock: number;
|
|
46
|
-
forkedFrom: string | null;
|
|
47
|
-
usage: {
|
|
48
|
-
totalQueries7d: number
|
|
49
|
-
totalQueries30d: number
|
|
50
|
-
daily: Array<{
|
|
51
|
-
date: string
|
|
52
|
-
count: number
|
|
53
|
-
}>
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
interface CreatorProfile {
|
|
57
|
-
displayName: string | null;
|
|
58
|
-
bio: string | null;
|
|
59
|
-
avatarUrl: string | null;
|
|
60
|
-
slug: string | null;
|
|
61
|
-
subgraphs: MarketplaceSubgraphSummary[];
|
|
62
|
-
}
|
|
63
|
-
export { UpdateProfileRequestSchema, UpdateProfileRequest, PublishSubgraphRequestSchema, PublishSubgraphRequest, MarketplaceSubgraphSummary, MarketplaceSubgraphDetail, MarketplaceCreator, ForkSubgraphRequestSchema, ForkSubgraphRequest, CreatorProfile };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/schemas/marketplace.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import { z } from \"zod/v4\";\n\n// ── Request Types ────────────────────────────────────────────────────\n\nexport interface PublishSubgraphRequest {\n\ttags?: string[];\n\tdescription?: string;\n}\n\nexport interface UpdateProfileRequest {\n\tdisplay_name?: string;\n\tbio?: string;\n\tslug?: string;\n}\n\nexport interface ForkSubgraphRequest {\n\tsourceSubgraphName: string;\n\tnewName?: string;\n}\n\n// ── Request Schemas ───────────────────────────────────────────────────\n\nexport const PublishSubgraphRequestSchema: z.ZodType<PublishSubgraphRequest> =\n\tz.object({\n\t\ttags: z.array(z.string().max(30)).max(5).optional(),\n\t\tdescription: z.string().max(500).optional(),\n\t});\n\nexport const UpdateProfileRequestSchema: z.ZodType<UpdateProfileRequest> =\n\tz.object({\n\t\tdisplay_name: z.string().max(50).optional(),\n\t\tbio: z.string().max(300).optional(),\n\t\tslug: z\n\t\t\t.string()\n\t\t\t.regex(/^[a-z0-9-]+$/, \"lowercase alphanumeric + hyphens only\")\n\t\t\t.min(3)\n\t\t\t.max(30)\n\t\t\t.optional(),\n\t});\n\nexport const ForkSubgraphRequestSchema: z.ZodType<ForkSubgraphRequest> =\n\tz.object({\n\t\tsourceSubgraphName: z.string(),\n\t\tnewName: z\n\t\t\t.string()\n\t\t\t.regex(/^[a-z0-9-]+$/, \"lowercase alphanumeric + hyphens only\")\n\t\t\t.max(63)\n\t\t\t.optional(),\n\t});\n\n// ── Response Types ────────────────────────────────────────────────────\n\nexport interface MarketplaceCreator {\n\tdisplayName: string | null;\n\tslug: string | null;\n}\n\nexport interface MarketplaceSubgraphSummary {\n\tname: string;\n\tdescription: string | null;\n\ttags: string[];\n\tcreator: MarketplaceCreator;\n\tstatus: string;\n\tversion: string;\n\ttables: string[];\n\ttotalQueries7d: number;\n\tprogress: number;\n\tcreatedAt: string;\n}\n\nexport interface MarketplaceSubgraphDetail extends MarketplaceSubgraphSummary {\n\ttableSchemas: Record<\n\t\tstring,\n\t\t{\n\t\t\tcolumns: Record<string, { type: string; nullable?: boolean }>;\n\t\t\trowCount: number;\n\t\t\tendpoint: string;\n\t\t}\n\t>;\n\tsources: Record<string, unknown>;\n\tstartBlock: number;\n\tlastProcessedBlock: number;\n\tforkedFrom: string | null;\n\tusage: {\n\t\ttotalQueries7d: number;\n\t\ttotalQueries30d: number;\n\t\tdaily: Array<{ date: string; count: number }>;\n\t};\n}\n\nexport interface CreatorProfile {\n\tdisplayName: string | null;\n\tbio: string | null;\n\tavatarUrl: string | null;\n\tslug: string | null;\n\tsubgraphs: MarketplaceSubgraphSummary[];\n}\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAsBO,IAAM,+BACZ,EAAE,OAAO;AAAA,EACR,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS;AAAA,EAClD,aAAa,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,SAAS;AAC3C,CAAC;AAEK,IAAM,6BACZ,EAAE,OAAO;AAAA,EACR,cAAc,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,SAAS;AAAA,EAC1C,KAAK,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,SAAS;AAAA,EAClC,MAAM,EACJ,OAAO,EACP,MAAM,gBAAgB,uCAAuC,EAC7D,IAAI,CAAC,EACL,IAAI,EAAE,EACN,SAAS;AACZ,CAAC;AAEK,IAAM,4BACZ,EAAE,OAAO;AAAA,EACR,oBAAoB,EAAE,OAAO;AAAA,EAC7B,SAAS,EACP,OAAO,EACP,MAAM,gBAAgB,uCAAuC,EAC7D,IAAI,EAAE,EACN,SAAS;AACZ,CAAC;",
|
|
8
|
-
"debugId": "14EEEDD6D32C5A5A64756E2164756E21",
|
|
9
|
-
"names": []
|
|
10
|
-
}
|