@whatalo/plugin-sdk 1.0.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/adapters/express.cjs +87 -0
- package/dist/adapters/express.cjs.map +1 -0
- package/dist/adapters/express.d.cts +17 -0
- package/dist/adapters/express.d.ts +17 -0
- package/dist/adapters/express.mjs +60 -0
- package/dist/adapters/express.mjs.map +1 -0
- package/dist/adapters/hono.cjs +79 -0
- package/dist/adapters/hono.cjs.map +1 -0
- package/dist/adapters/hono.d.cts +15 -0
- package/dist/adapters/hono.d.ts +15 -0
- package/dist/adapters/hono.mjs +52 -0
- package/dist/adapters/hono.mjs.map +1 -0
- package/dist/adapters/nextjs.cjs +79 -0
- package/dist/adapters/nextjs.cjs.map +1 -0
- package/dist/adapters/nextjs.d.cts +7 -0
- package/dist/adapters/nextjs.d.ts +7 -0
- package/dist/adapters/nextjs.mjs +52 -0
- package/dist/adapters/nextjs.mjs.map +1 -0
- package/dist/bridge/index.cjs +290 -0
- package/dist/bridge/index.cjs.map +1 -0
- package/dist/bridge/index.d.cts +236 -0
- package/dist/bridge/index.d.ts +236 -0
- package/dist/bridge/index.mjs +260 -0
- package/dist/bridge/index.mjs.map +1 -0
- package/dist/client/index.cjs +423 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +131 -0
- package/dist/client/index.d.ts +131 -0
- package/dist/client/index.mjs +396 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/index.cjs +843 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +57 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.mjs +801 -0
- package/dist/index.mjs.map +1 -0
- package/dist/manifest/index.cjs +145 -0
- package/dist/manifest/index.cjs.map +1 -0
- package/dist/manifest/index.d.cts +78 -0
- package/dist/manifest/index.d.ts +78 -0
- package/dist/manifest/index.mjs +117 -0
- package/dist/manifest/index.mjs.map +1 -0
- package/dist/types-D2Efg3EG.d.ts +19 -0
- package/dist/types-DZ659i6f.d.ts +68 -0
- package/dist/types-Db_BeRCj.d.cts +19 -0
- package/dist/types-DdqKKyqX.d.cts +68 -0
- package/dist/types-M1eLMz6w.d.cts +279 -0
- package/dist/types-M1eLMz6w.d.ts +279 -0
- package/dist/webhooks/index.cjs +50 -0
- package/dist/webhooks/index.cjs.map +1 -0
- package/dist/webhooks/index.d.cts +18 -0
- package/dist/webhooks/index.d.ts +18 -0
- package/dist/webhooks/index.mjs +23 -0
- package/dist/webhooks/index.mjs.map +1 -0
- package/package.json +94 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client/errors.ts","../src/client/whatalo-client.ts","../src/webhooks/verify.ts","../src/manifest/validate.ts","../src/bridge/use-whatalo-context.ts","../src/bridge/use-whatalo-action.ts","../src/bridge/types.ts","../src/bridge/use-app-bridge.ts"],"sourcesContent":["// @whatalo/plugin-sdk — Official TypeScript SDK for building Whatalo plugins\nexport const SDK_VERSION = \"0.0.1\";\n\n// Client\nexport { WhataloClient } from \"./client/whatalo-client.js\";\nexport type {\n WhataloClientOptions,\n RateLimitInfo,\n PaginatedResponse,\n SingleResponse,\n Product,\n Order,\n Customer,\n Category,\n Discount,\n Store,\n InventoryItem,\n Webhook,\n ListProductsParams,\n CreateProductParams,\n UpdateProductParams,\n ListOrdersParams,\n ListCustomersParams,\n ListCategoriesParams,\n CreateCategoryParams,\n UpdateCategoryParams,\n ListDiscountsParams,\n CreateDiscountParams,\n UpdateDiscountParams,\n UpsertWebhookParams,\n UpdateWebhookParams,\n AdjustInventoryParams,\n} from \"./client/types.js\";\n\n// Error classes\nexport {\n WhataloAPIError,\n AuthenticationError,\n AuthorizationError,\n NotFoundError,\n ValidationError,\n RateLimitError,\n InternalError,\n} from \"./client/errors.js\";\n\n// Webhook verification\nexport { verifyWebhook } from \"./webhooks/verify.js\";\nexport type {\n VerifyWebhookParams,\n WebhookEvent,\n WebhookEventData,\n WebhookPayload,\n} from \"./webhooks/index.js\";\n\n// Manifest\nexport { defineApp, ManifestValidationError } from \"./manifest/index.js\";\nexport type {\n AppManifest,\n AppPermission,\n AppCategory,\n} from \"./manifest/index.js\";\n\n// Bridge (React hooks for plugin ↔ admin postMessage communication)\nexport { useAppBridge, useWhataloAction, useWhataloContext } from \"./bridge/index.js\";\nexport { BILLING_OPERATION } from \"./bridge/index.js\";\nexport type {\n AppBridge,\n AppBridgeToast,\n AppBridgeModal,\n BillingActions,\n UseWhataloActionReturn,\n UseWhataloContextReturn,\n WhataloContext,\n WhataloUser,\n BridgeAction,\n ActionAck,\n ToastPayload,\n NavigatePayload,\n ModalPayload,\n ResizePayload,\n BillingOperation,\n BillingPayload,\n BillingPlanResponse,\n BillingSubscriptionResponse,\n} from \"./bridge/index.js\";\n","/**\n * Base error for all SDK errors.\n * Contains the HTTP status code and a machine-readable error code.\n */\nexport class WhataloAPIError extends Error {\n readonly statusCode: number;\n readonly code: string;\n readonly requestId?: string;\n\n constructor(\n message: string,\n statusCode: number,\n code: string,\n requestId?: string\n ) {\n super(message);\n this.name = \"WhataloAPIError\";\n this.statusCode = statusCode;\n this.code = code;\n this.requestId = requestId;\n }\n}\n\n/** 401 — Invalid or missing API key */\nexport class AuthenticationError extends WhataloAPIError {\n constructor(\n message = \"Invalid or missing API key\",\n requestId?: string\n ) {\n super(message, 401, \"authentication_error\", requestId);\n this.name = \"AuthenticationError\";\n }\n}\n\n/** 403 — API key lacks required permission scope */\nexport class AuthorizationError extends WhataloAPIError {\n readonly requiredScope: string;\n\n constructor(\n message: string,\n requiredScope: string,\n requestId?: string\n ) {\n super(message, 403, \"authorization_error\", requestId);\n this.name = \"AuthorizationError\";\n this.requiredScope = requiredScope;\n }\n}\n\n/**\n * 403 — Installation does not have the required permission scope.\n *\n * Thrown when the merchant has not granted a scope that the current\n * API call requires. This is distinct from AuthorizationError:\n * - AuthorizationError = generic 403 (could be any auth reason)\n * - InsufficientScopeError = specific scope missing from granted_scopes\n *\n * The `requiredScope` field tells the developer exactly which scope to add\n * to their plugin manifest so they can request merchant re-consent.\n *\n * Example:\n * try {\n * await client.customers.list()\n * } catch (err) {\n * if (err instanceof InsufficientScopeError) {\n * console.error(`Add \"${err.requiredScope}\" to your manifest.`)\n * }\n * }\n */\nexport class InsufficientScopeError extends WhataloAPIError {\n /** The exact scope string missing from the installation's granted_scopes */\n readonly requiredScope: string;\n /** The scopes currently granted to this installation */\n readonly grantedScopes: string[];\n\n constructor(\n message: string,\n requiredScope: string,\n grantedScopes: string[],\n requestId?: string\n ) {\n super(message, 403, \"insufficient_scope\", requestId);\n this.name = \"InsufficientScopeError\";\n this.requiredScope = requiredScope;\n this.grantedScopes = grantedScopes;\n }\n}\n\n/** 404 — Resource not found */\nexport class NotFoundError extends WhataloAPIError {\n readonly resourceType: string;\n readonly resourceId: string;\n\n constructor(\n resourceType: string,\n resourceId: string,\n requestId?: string\n ) {\n super(\n `${resourceType} '${resourceId}' not found`,\n 404,\n \"not_found\",\n requestId\n );\n this.name = \"NotFoundError\";\n this.resourceType = resourceType;\n this.resourceId = resourceId;\n }\n}\n\n/** 422 — Request body validation failed */\nexport class ValidationError extends WhataloAPIError {\n readonly fieldErrors: Array<{ field: string; message: string }>;\n\n constructor(\n fieldErrors: Array<{ field: string; message: string }>,\n requestId?: string\n ) {\n const message = `Validation failed: ${fieldErrors\n .map((e) => `${e.field} — ${e.message}`)\n .join(\", \")}`;\n super(message, 422, \"validation_error\", requestId);\n this.name = \"ValidationError\";\n this.fieldErrors = fieldErrors;\n }\n}\n\n/** 429 — Rate limit exceeded */\nexport class RateLimitError extends WhataloAPIError {\n /** Seconds until the rate limit resets */\n readonly retryAfter: number;\n\n constructor(retryAfter: number, requestId?: string) {\n super(\n `Rate limit exceeded. Retry after ${retryAfter} seconds.`,\n 429,\n \"rate_limit_exceeded\",\n requestId\n );\n this.name = \"RateLimitError\";\n this.retryAfter = retryAfter;\n }\n}\n\n/** 500 — Server-side error */\nexport class InternalError extends WhataloAPIError {\n constructor(\n message = \"An internal error occurred\",\n requestId?: string\n ) {\n super(message, 500, \"internal_error\", requestId);\n this.name = \"InternalError\";\n }\n}\n","import type {\n WhataloClientOptions,\n RateLimitInfo,\n PaginatedResponse,\n SingleResponse,\n Product,\n Order,\n Customer,\n Category,\n Discount,\n Store,\n InventoryItem,\n Webhook,\n ListProductsParams,\n CreateProductParams,\n UpdateProductParams,\n ListOrdersParams,\n ListCustomersParams,\n ListCategoriesParams,\n CreateCategoryParams,\n UpdateCategoryParams,\n ListDiscountsParams,\n CreateDiscountParams,\n UpdateDiscountParams,\n UpsertWebhookParams,\n UpdateWebhookParams,\n AdjustInventoryParams,\n} from \"./types.js\";\nimport {\n WhataloAPIError,\n AuthenticationError,\n AuthorizationError,\n InsufficientScopeError,\n RateLimitError,\n InternalError,\n NotFoundError,\n ValidationError,\n} from \"./errors.js\";\n\nconst DEFAULT_BASE_URL = \"https://api.whatalo.com/v1\";\nconst DEFAULT_TIMEOUT = 30_000;\n\n/**\n * Official TypeScript client for the Whatalo REST API.\n * Zero runtime dependencies — uses native fetch.\n */\nexport class WhataloClient {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly timeout: number;\n private readonly maxRetries: number;\n private readonly fetchFn: typeof globalThis.fetch;\n private readonly onRequest?: (url: string, init: RequestInit) => void;\n private readonly onResponse?: (response: Response, durationMs: number) => void;\n\n /** Rate limit info from the most recent API response */\n rateLimit: RateLimitInfo = { limit: 0, remaining: 0, reset: 0 };\n\n /** Product resource methods */\n readonly products: ProductResource;\n /** Order resource methods */\n readonly orders: OrderResource;\n /** Customer resource methods */\n readonly customers: CustomerResource;\n /** Category resource methods */\n readonly categories: CategoryResource;\n /** Discount resource methods */\n readonly discounts: DiscountResource;\n /** Store resource methods */\n readonly store: StoreResource;\n /** Inventory resource methods */\n readonly inventory: InventoryResource;\n /** Webhook resource methods */\n readonly webhooks: WebhookResource;\n\n constructor(options: WhataloClientOptions) {\n this.apiKey = options.apiKey;\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/$/, \"\");\n this.timeout = options.timeout ?? DEFAULT_TIMEOUT;\n this.maxRetries = Math.min(options.retries ?? 0, 3);\n this.fetchFn = options.fetch ?? globalThis.fetch;\n this.onRequest = options.onRequest;\n this.onResponse = options.onResponse;\n\n this.products = new ProductResource(this);\n this.orders = new OrderResource(this);\n this.customers = new CustomerResource(this);\n this.categories = new CategoryResource(this);\n this.discounts = new DiscountResource(this);\n this.store = new StoreResource(this);\n this.inventory = new InventoryResource(this);\n this.webhooks = new WebhookResource(this);\n }\n\n /**\n * Internal request method shared by all resource namespaces.\n * Handles headers, timeout, error parsing, and rate limit extraction.\n */\n async request<T>(\n method: string,\n path: string,\n options?: {\n body?: unknown;\n params?: Record<string, string | number | boolean | undefined>;\n }\n ): Promise<T> {\n let url = `${this.baseUrl}${path}`;\n\n // Add query params\n if (options?.params) {\n const searchParams = new URLSearchParams();\n for (const [key, value] of Object.entries(options.params)) {\n if (value !== undefined) {\n searchParams.set(key, String(value));\n }\n }\n const qs = searchParams.toString();\n if (qs) url += `?${qs}`;\n }\n\n const headers: Record<string, string> = {\n \"X-API-Key\": this.apiKey,\n \"Content-Type\": \"application/json\",\n };\n\n let lastError: Error | null = null;\n\n for (let attempt = 0; attempt <= this.maxRetries; attempt++) {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.timeout);\n const requestInit: RequestInit = {\n method,\n headers,\n body: options?.body ? JSON.stringify(options.body) : undefined,\n signal: controller.signal,\n };\n const startedAt = Date.now();\n this.onRequest?.(url, requestInit);\n\n try {\n const response = await this.fetchFn(url, requestInit);\n\n clearTimeout(timeoutId);\n this.onResponse?.(response, Date.now() - startedAt);\n\n // Extract rate limit headers\n this.rateLimit = {\n limit: Number(response.headers.get(\"X-RateLimit-Limit\") ?? 0),\n remaining: Number(\n response.headers.get(\"X-RateLimit-Remaining\") ?? 0\n ),\n reset: Number(response.headers.get(\"X-RateLimit-Reset\") ?? 0),\n };\n\n const requestId =\n response.headers.get(\"X-Request-Id\") ?? undefined;\n\n if (response.ok) {\n return (await response.json()) as T;\n }\n\n // Handle error responses\n const errorBody = await response.json().catch(() => ({\n error: { code: \"unknown\", message: response.statusText },\n }));\n const errData = (errorBody as { error?: { code?: string; message?: string; details?: Array<{ field: string; message: string }> } }).error;\n\n switch (response.status) {\n case 401:\n throw new AuthenticationError(errData?.message, requestId);\n case 403:\n // Distinguish between a specific scope denial and a generic 403.\n // insufficient_scope means the merchant never granted this permission.\n if (errData?.code === \"insufficient_scope\") {\n const details = errorBody as {\n error?: { required?: string; granted?: string[] };\n };\n throw new InsufficientScopeError(\n errData.message ?? \"Insufficient scope\",\n details.error?.required ?? \"\",\n details.error?.granted ?? [],\n requestId\n );\n }\n throw new AuthorizationError(\n errData?.message ?? \"Forbidden\",\n errData?.code ?? \"unknown_scope\",\n requestId\n );\n case 404:\n throw new NotFoundError(\"Resource\", path, requestId);\n case 422:\n throw new ValidationError(\n errData?.details ?? [\n { field: \"unknown\", message: errData?.message ?? \"Validation failed\" },\n ],\n requestId\n );\n case 429: {\n const retryAfter = Number(\n response.headers.get(\"Retry-After\") ?? 60\n );\n throw new RateLimitError(retryAfter, requestId);\n }\n default:\n if (response.status >= 500 && attempt < this.maxRetries) {\n // Retry on 5xx\n lastError = new InternalError(errData?.message, requestId);\n await this.sleep(Math.pow(2, attempt) * 1000);\n continue;\n }\n throw new WhataloAPIError(\n errData?.message ?? \"API error\",\n response.status,\n errData?.code ?? \"unknown\",\n requestId\n );\n }\n } catch (err) {\n clearTimeout(timeoutId);\n if (err instanceof WhataloAPIError) throw err;\n if ((err as Error).name === \"AbortError\") {\n throw new WhataloAPIError(\n \"Request timed out\",\n 408,\n \"timeout\"\n );\n }\n throw err;\n }\n }\n\n throw lastError ?? new InternalError(\"Request failed after retries\");\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n\n/** Products API namespace */\nclass ProductResource {\n constructor(private readonly client: WhataloClient) {}\n\n async list(\n params?: ListProductsParams\n ): Promise<PaginatedResponse<Product>> {\n return this.client.request(\"GET\", \"/products\", {\n params: params as Record<string, string | number | boolean | undefined>,\n });\n }\n\n async get(id: string): Promise<SingleResponse<Product>> {\n return this.client.request(\"GET\", `/products/${id}`);\n }\n\n async create(\n data: CreateProductParams\n ): Promise<SingleResponse<Product>> {\n return this.client.request(\"POST\", \"/products\", { body: data });\n }\n\n async update(\n id: string,\n data: UpdateProductParams\n ): Promise<SingleResponse<Product>> {\n return this.client.request(\"PATCH\", `/products/${id}`, { body: data });\n }\n\n async delete(id: string): Promise<SingleResponse<{ deleted: boolean }>> {\n return this.client.request(\"DELETE\", `/products/${id}`);\n }\n\n async count(\n status?: \"active\" | \"inactive\" | \"all\"\n ): Promise<SingleResponse<{ count: number }>> {\n return this.client.request(\"GET\", \"/products/count\", {\n params: status ? { status } : undefined,\n });\n }\n}\n\n/** Orders API namespace */\nclass OrderResource {\n constructor(private readonly client: WhataloClient) {}\n\n async list(\n params?: ListOrdersParams\n ): Promise<PaginatedResponse<Order>> {\n return this.client.request(\"GET\", \"/orders\", {\n params: params as Record<string, string | number | boolean | undefined>,\n });\n }\n\n async get(id: string): Promise<SingleResponse<Order>> {\n return this.client.request(\"GET\", `/orders/${id}`);\n }\n\n async updateStatus(\n id: string,\n data: { status: string }\n ): Promise<SingleResponse<Order>> {\n return this.client.request(\"PATCH\", `/orders/${id}`, { body: data });\n }\n\n async count(\n status?: string\n ): Promise<SingleResponse<{ count: number }>> {\n return this.client.request(\"GET\", \"/orders/count\", {\n params: status ? { status } : undefined,\n });\n }\n}\n\n/** Customers API namespace */\nclass CustomerResource {\n constructor(private readonly client: WhataloClient) {}\n\n async list(params?: ListCustomersParams): Promise<PaginatedResponse<Customer>> {\n return this.client.request(\"GET\", \"/customers\", {\n params: params as Record<string, string | number | boolean | undefined>,\n });\n }\n\n async get(id: string): Promise<SingleResponse<Customer>> {\n return this.client.request(\"GET\", `/customers/${id}`);\n }\n}\n\n/** Categories API namespace */\nclass CategoryResource {\n constructor(private readonly client: WhataloClient) {}\n\n async list(\n params?: ListCategoriesParams\n ): Promise<PaginatedResponse<Category>> {\n return this.client.request(\"GET\", \"/categories\", {\n params: params as Record<string, string | number | boolean | undefined>,\n });\n }\n\n async get(id: string): Promise<SingleResponse<Category>> {\n return this.client.request(\"GET\", `/categories/${id}`);\n }\n\n async create(\n data: CreateCategoryParams\n ): Promise<SingleResponse<Category>> {\n return this.client.request(\"POST\", \"/categories\", { body: data });\n }\n\n async update(\n id: string,\n data: UpdateCategoryParams\n ): Promise<SingleResponse<Category>> {\n return this.client.request(\"PATCH\", `/categories/${id}`, { body: data });\n }\n\n async delete(id: string): Promise<SingleResponse<{ deleted: boolean }>> {\n return this.client.request(\"DELETE\", `/categories/${id}`);\n }\n\n async count(): Promise<SingleResponse<{ count: number }>> {\n return this.client.request(\"GET\", \"/categories/count\");\n }\n}\n\n/** Discounts API namespace */\nclass DiscountResource {\n constructor(private readonly client: WhataloClient) {}\n\n async list(\n params?: ListDiscountsParams\n ): Promise<PaginatedResponse<Discount>> {\n return this.client.request(\"GET\", \"/discounts\", {\n params: params as Record<string, string | number | boolean | undefined>,\n });\n }\n\n async get(id: string): Promise<SingleResponse<Discount>> {\n return this.client.request(\"GET\", `/discounts/${id}`);\n }\n\n async create(\n data: CreateDiscountParams\n ): Promise<SingleResponse<Discount>> {\n return this.client.request(\"POST\", \"/discounts\", { body: data });\n }\n\n async update(\n id: string,\n data: UpdateDiscountParams\n ): Promise<SingleResponse<Discount>> {\n return this.client.request(\"PATCH\", `/discounts/${id}`, { body: data });\n }\n\n async delete(id: string): Promise<SingleResponse<{ deleted: boolean }>> {\n return this.client.request(\"DELETE\", `/discounts/${id}`);\n }\n}\n\n/** Store API namespace */\nclass StoreResource {\n constructor(private readonly client: WhataloClient) {}\n\n async get(): Promise<SingleResponse<Store>> {\n return this.client.request(\"GET\", \"/store\");\n }\n}\n\n/** Inventory API namespace */\nclass InventoryResource {\n constructor(private readonly client: WhataloClient) {}\n\n async get(productId: string): Promise<SingleResponse<InventoryItem>> {\n return this.client.request(\"GET\", `/products/${productId}/inventory`);\n }\n\n async adjust(\n productId: string,\n data: AdjustInventoryParams\n ): Promise<SingleResponse<InventoryItem>> {\n return this.client.request(\"PATCH\", `/products/${productId}/inventory`, {\n body: data,\n });\n }\n}\n\n/** Webhooks API namespace */\nclass WebhookResource {\n constructor(private readonly client: WhataloClient) {}\n\n async list(): Promise<PaginatedResponse<Webhook>> {\n return this.client.request(\"GET\", \"/webhooks\");\n }\n\n async create(data: UpsertWebhookParams): Promise<SingleResponse<Webhook>> {\n return this.client.request(\"POST\", \"/webhooks\", { body: data });\n }\n\n async update(\n id: string,\n data: UpdateWebhookParams\n ): Promise<SingleResponse<Webhook>> {\n return this.client.request(\"PATCH\", `/webhooks/${id}`, { body: data });\n }\n\n async delete(id: string): Promise<SingleResponse<{ deleted: boolean }>> {\n return this.client.request(\"DELETE\", `/webhooks/${id}`);\n }\n}\n","import { createHmac, timingSafeEqual } from \"node:crypto\";\n\nexport interface VerifyWebhookParams {\n /** Raw request body as a string (NOT parsed JSON) */\n payload: string;\n /** Value of the X-Webhook-Signature header */\n signature: string;\n /** App's webhook secret (provided during app installation) */\n secret: string;\n}\n\n/**\n * Verify webhook signature using HMAC-SHA256.\n * Uses timing-safe comparison to prevent timing attacks.\n */\nexport function verifyWebhook({\n payload,\n signature,\n secret,\n}: VerifyWebhookParams): boolean {\n if (!payload || !signature || !secret) return false;\n\n const expected = createHmac(\"sha256\", secret)\n .update(payload, \"utf8\")\n .digest(\"hex\");\n\n if (expected.length !== signature.length) return false;\n\n try {\n return timingSafeEqual(\n Buffer.from(expected, \"hex\"),\n Buffer.from(signature, \"hex\")\n );\n } catch {\n return false;\n }\n}\n","import type { AppManifest } from \"./types.js\";\n\n/** Error thrown when manifest validation fails */\nexport class ManifestValidationError extends Error {\n readonly errors: Array<{ field: string; message: string }>;\n\n constructor(errors: Array<{ field: string; message: string }>) {\n const message = `Invalid app manifest: ${errors\n .map((e) => `${e.field}: ${e.message}`)\n .join(\"; \")}`;\n super(message);\n this.name = \"ManifestValidationError\";\n this.errors = errors;\n }\n}\n\nconst ID_REGEX = /^[a-z0-9][a-z0-9-]*[a-z0-9]$/;\nconst SEMVER_REGEX = /^\\d+\\.\\d+\\.\\d+$/;\nconst EMAIL_REGEX = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\nconst VALID_PERMISSIONS = new Set([\n \"read:products\",\n \"write:products\",\n \"read:orders\",\n \"write:orders\",\n \"read:customers\",\n \"write:customers\",\n \"read:inventory\",\n \"write:inventory\",\n \"read:store\",\n \"write:store\",\n \"read:webhooks\",\n \"write:webhooks\",\n \"read:discounts\",\n \"write:discounts\",\n \"read:analytics\",\n]);\n\nconst VALID_CATEGORIES = new Set([\n \"analytics\",\n \"marketing\",\n \"shipping\",\n \"payments\",\n \"payment\",\n \"inventory\",\n \"communication\",\n \"productivity\",\n \"accounting\",\n \"developer\",\n \"other\",\n]);\n\n/**\n * Validate and return a typed AppManifest.\n * Throws ManifestValidationError with detailed field-level errors.\n */\nexport function defineApp(manifest: AppManifest): AppManifest {\n const errors: Array<{ field: string; message: string }> = [];\n\n // id\n if (!manifest.id || manifest.id.length < 3 || manifest.id.length > 50) {\n errors.push({ field: \"id\", message: \"Must be 3-50 characters\" });\n } else if (!ID_REGEX.test(manifest.id)) {\n errors.push({\n field: \"id\",\n message: \"Must be lowercase alphanumeric with hyphens\",\n });\n }\n\n // name\n if (!manifest.name || manifest.name.length < 3 || manifest.name.length > 50) {\n errors.push({ field: \"name\", message: \"Must be 3-50 characters\" });\n }\n\n // description\n if (\n !manifest.description ||\n manifest.description.length < 10 ||\n manifest.description.length > 200\n ) {\n errors.push({\n field: \"description\",\n message: \"Must be 10-200 characters\",\n });\n }\n\n // version\n if (!manifest.version || !SEMVER_REGEX.test(manifest.version)) {\n errors.push({\n field: \"version\",\n message: \"Must be valid semver (e.g., 1.0.0)\",\n });\n }\n\n // author\n if (!manifest.author?.name) {\n errors.push({ field: \"author.name\", message: \"Required\" });\n }\n if (!manifest.author?.email || !EMAIL_REGEX.test(manifest.author.email)) {\n errors.push({\n field: \"author.email\",\n message: \"Must be a valid email address\",\n });\n }\n\n // permissions\n if (!manifest.permissions || manifest.permissions.length === 0) {\n errors.push({\n field: \"permissions\",\n message: \"At least one permission is required\",\n });\n } else {\n for (const perm of manifest.permissions) {\n if (!VALID_PERMISSIONS.has(perm)) {\n errors.push({\n field: \"permissions\",\n message: `Invalid permission: ${perm}`,\n });\n }\n }\n }\n\n // appUrl\n if (!manifest.appUrl) {\n errors.push({ field: \"appUrl\", message: \"Required\" });\n }\n\n // pricing\n if (manifest.pricing !== \"free\" && manifest.pricing !== \"paid\") {\n errors.push({\n field: \"pricing\",\n message: 'Must be \"free\" or \"paid\"',\n });\n }\n\n // category\n if (!VALID_CATEGORIES.has(manifest.category)) {\n errors.push({\n field: \"category\",\n message: `Invalid category: ${manifest.category}`,\n });\n }\n\n if (errors.length > 0) {\n throw new ManifestValidationError(errors);\n }\n\n return manifest;\n}\n","import { useState, useEffect, useCallback } from \"react\";\nimport type { WhataloContext, ContextMessage } from \"./types.js\";\nimport { attachInitListener, waitForParentOrigin } from \"./use-whatalo-action.js\";\n\nexport interface UseWhataloContextReturn extends WhataloContext {\n /** Whether the plugin has received context from the admin host */\n isReady: boolean;\n}\n\nconst DEFAULT_CONTEXT: WhataloContext = {\n storeId: \"\",\n storeName: \"\",\n user: { id: \"\", name: \"\", email: \"\", role: \"owner\" },\n appId: \"\",\n currentPage: \"\",\n locale: \"es\",\n theme: \"light\",\n initialHeight: 200,\n};\n\n/**\n * Listens for context messages from the admin host and signals readiness.\n * Automatically applies the theme attribute to the document root.\n */\nexport function useWhataloContext(): UseWhataloContextReturn {\n const [context, setContext] = useState<WhataloContext>(DEFAULT_CONTEXT);\n const [isReady, setIsReady] = useState(false);\n\n const handleMessage = useCallback((event: MessageEvent) => {\n if (!event.data || typeof event.data !== \"object\") return;\n const msg = event.data as ContextMessage & { context?: WhataloContext };\n if (msg.type !== \"whatalo:context\") return;\n\n const payload = msg.data ?? msg.context;\n if (!payload || typeof payload.storeId !== \"string\") return;\n\n setContext(payload);\n setIsReady(true);\n\n if (payload.theme) {\n document.documentElement.setAttribute(\"data-theme\", payload.theme);\n }\n }, []);\n\n useEffect(() => {\n // Ensure the whatalo:init listener is attached before doing anything else.\n // This is idempotent — safe to call multiple times.\n attachInitListener();\n\n window.addEventListener(\"message\", handleMessage);\n\n // Send the ready signal to the admin host. We wait for parentOrigin from\n // the whatalo:init handshake before sending so we never broadcast to \"*\".\n // The admin sends whatalo:init on iframe onLoad, which fires before the\n // plugin's React tree hydrates — so the wait is typically sub-millisecond.\n waitForParentOrigin().then((origin) => {\n window.parent.postMessage(\n {\n type: \"whatalo:action\",\n actionId: crypto.randomUUID(),\n action: \"ready\",\n payload: {},\n },\n origin,\n );\n });\n\n return () => window.removeEventListener(\"message\", handleMessage);\n }, [handleMessage]);\n\n return { ...context, isReady };\n}\n","import { useCallback, useRef, useEffect } from \"react\";\nimport type {\n BridgeAction,\n ActionAck,\n ToastPayload,\n ModalPayload,\n BillingOperation,\n BillingPayload,\n BillingPlanResponse,\n BillingSubscriptionResponse,\n} from \"./types.js\";\nimport { BILLING_OPERATION } from \"./types.js\";\n\nconst ACK_TIMEOUT_MS = 5_000;\n\n// ---------------------------------------------------------------------------\n// Module-level origin store (singleton shared across all hook instances)\n//\n// This module owns the handshake state. Both useWhataloAction and\n// useWhataloContext import from here so they target the same parentOrigin\n// once the admin sends the whatalo:init handshake.\n// ---------------------------------------------------------------------------\n\n/** Origin of the admin host, received via whatalo:init handshake. */\nlet parentOrigin: string | null = null;\n\n/** Callbacks waiting for parentOrigin to be resolved. */\nconst originResolvers: Array<(origin: string) => void> = [];\n\n/**\n * Returns a Promise that resolves with the parent origin.\n * If the handshake already completed, resolves immediately.\n */\nexport function waitForParentOrigin(): Promise<string> {\n if (parentOrigin !== null) {\n return Promise.resolve(parentOrigin);\n }\n return new Promise((resolve) => {\n originResolvers.push(resolve);\n });\n}\n\n/**\n * Initializes the origin listener exactly once (idempotent).\n * Listens for the whatalo:init message from the admin host and stores\n * the origin so all subsequent postMessage calls can target it explicitly.\n */\nlet initListenerAttached = false;\n\nexport function attachInitListener(): void {\n if (initListenerAttached) return;\n initListenerAttached = true;\n\n window.addEventListener(\"message\", (event: MessageEvent) => {\n // Only accept the init message from the direct parent window\n if (event.source !== window.parent) return;\n if (!event.data || typeof event.data !== \"object\") return;\n if (event.data.type !== \"whatalo:init\") return;\n\n const origin = event.data.origin;\n if (typeof origin !== \"string\" || !origin) return;\n\n // Store origin and flush any queued resolvers\n parentOrigin = origin;\n for (const resolve of originResolvers) {\n resolve(origin);\n }\n originResolvers.length = 0;\n });\n}\n\n/** Billing namespace returned by useWhataloAction. */\nexport interface BillingActions {\n /** Fetch all active pricing plans for this plugin. */\n getPlans(): Promise<BillingPlanResponse[]>;\n /** Fetch the store's current subscription to this plugin, or null if none. */\n getSubscription(): Promise<BillingSubscriptionResponse | null>;\n /**\n * Request a subscription to the given plan.\n * The host will redirect the admin to an approval page.\n */\n requestSubscription(planSlug: string): Promise<void>;\n /** Initiate a cancellation for the current subscription. */\n cancelSubscription(): Promise<void>;\n /** Reactivate a subscription that was scheduled for cancellation at period end. */\n reactivateSubscription(): Promise<void>;\n /** Switch the current subscription to a different plan with proration. */\n switchPlan(newPlanSlug: string): Promise<void>;\n}\n\nexport interface UseWhataloActionReturn {\n /** Send a raw bridge action to the admin host */\n sendAction: (\n action: BridgeAction,\n payload: Record<string, unknown>,\n ) => Promise<ActionAck>;\n /** Display a toast notification in the admin */\n showToast: (options: ToastPayload) => Promise<ActionAck>;\n /** Navigate the admin to a path */\n navigate: (path: string) => Promise<ActionAck>;\n /** Open a modal in the admin */\n openModal: (options: Omit<ModalPayload, \"operation\">) => Promise<ActionAck>;\n /** Close the currently open modal */\n closeModal: () => Promise<ActionAck>;\n /** Request an iframe resize */\n resize: (height: number) => Promise<ActionAck>;\n /** Billing actions — query plans, manage subscriptions. */\n billing: BillingActions;\n}\n\n/**\n * Sends actions to the admin host via postMessage and waits for acknowledgements.\n * Each action has a unique ID and a timeout to prevent hanging promises.\n *\n * All postMessage calls target parentOrigin (set via whatalo:init handshake)\n * instead of \"*\" to prevent message interception by malicious embedders.\n * If the handshake has not completed yet, the message is queued and flushed\n * once the origin is received.\n */\nexport function useWhataloAction(): UseWhataloActionReturn {\n const pendingAcks = useRef(\n new Map<string, (ack: ActionAck) => void>(),\n );\n\n useEffect(() => {\n // Ensure the init listener is running whenever this hook mounts\n attachInitListener();\n\n const handleMessage = (event: MessageEvent) => {\n if (!event.data || typeof event.data !== \"object\") return;\n const msg = event.data as ActionAck;\n if (msg.type !== \"whatalo:ack\") return;\n\n const resolve = pendingAcks.current.get(msg.actionId);\n if (resolve) {\n resolve(msg);\n pendingAcks.current.delete(msg.actionId);\n }\n };\n\n window.addEventListener(\"message\", handleMessage);\n return () => window.removeEventListener(\"message\", handleMessage);\n }, []);\n\n const sendAction = useCallback(\n (\n action: BridgeAction,\n payload: Record<string, unknown>,\n ): Promise<ActionAck> => {\n return new Promise((resolve) => {\n const actionId = crypto.randomUUID();\n\n const timeout = setTimeout(() => {\n pendingAcks.current.delete(actionId);\n resolve({\n type: \"whatalo:ack\",\n actionId,\n success: false,\n error: \"timeout\",\n });\n }, ACK_TIMEOUT_MS);\n\n pendingAcks.current.set(actionId, (ack) => {\n clearTimeout(timeout);\n resolve(ack);\n });\n\n // Wait for the parent origin from the whatalo:init handshake before\n // sending. If the handshake already completed this resolves synchronously.\n waitForParentOrigin().then((origin) => {\n window.parent.postMessage(\n { type: \"whatalo:action\", actionId, action, payload },\n origin,\n );\n });\n });\n },\n [],\n );\n\n const showToast = useCallback(\n (options: ToastPayload) =>\n sendAction(\"toast\", options as unknown as Record<string, unknown>),\n [sendAction],\n );\n\n const navigate = useCallback(\n (path: string) => sendAction(\"navigate\", { path }),\n [sendAction],\n );\n\n const openModal = useCallback(\n (options: Omit<ModalPayload, \"operation\">) =>\n sendAction(\"modal\", {\n operation: \"open\",\n ...options,\n } as unknown as Record<string, unknown>),\n [sendAction],\n );\n\n const closeModal = useCallback(\n () => sendAction(\"modal\", { operation: \"close\" }),\n [sendAction],\n );\n\n const resize = useCallback(\n (height: number) => sendAction(\"resize\", { height }),\n [sendAction],\n );\n\n // ---------------------------------------------------------------------------\n // Billing helpers\n //\n // Each billing method sends a \"billing\" action with a typed operation field.\n // The host resolves the operation against the store's app_plans /\n // app_subscriptions records and returns data in the ack payload.\n // ---------------------------------------------------------------------------\n\n /**\n * Extracts typed data from a billing ack payload.\n * Throws on failure so callers can use try/catch for error handling.\n */\n const sendBillingAction = useCallback(\n (operation: BillingOperation, extra?: Omit<BillingPayload, \"operation\">) =>\n sendAction(\"billing\", {\n operation,\n ...extra,\n } as unknown as Record<string, unknown>),\n [sendAction],\n );\n\n const billingGetPlans = useCallback(async (): Promise<BillingPlanResponse[]> => {\n const ack = await sendBillingAction(BILLING_OPERATION.GET_PLANS);\n if (!ack.success) {\n throw new Error(ack.error ?? \"billing.getPlans failed\");\n }\n // The host embeds the plans array in the ack under a `data` key\n return (ack as ActionAck & { data: BillingPlanResponse[] }).data ?? [];\n }, [sendBillingAction]);\n\n const billingGetSubscription = useCallback(\n async (): Promise<BillingSubscriptionResponse | null> => {\n const ack = await sendBillingAction(BILLING_OPERATION.GET_SUBSCRIPTION);\n if (!ack.success) {\n throw new Error(ack.error ?? \"billing.getSubscription failed\");\n }\n return (\n (ack as ActionAck & { data: BillingSubscriptionResponse | null }).data ??\n null\n );\n },\n [sendBillingAction],\n );\n\n const billingRequestSubscription = useCallback(\n async (planSlug: string): Promise<void> => {\n const ack = await sendBillingAction(BILLING_OPERATION.REQUEST_SUBSCRIPTION, {\n planSlug,\n });\n if (!ack.success) {\n throw new Error(ack.error ?? \"billing.requestSubscription failed\");\n }\n },\n [sendBillingAction],\n );\n\n const billingCancelSubscription = useCallback(async (): Promise<void> => {\n const ack = await sendBillingAction(BILLING_OPERATION.CANCEL_SUBSCRIPTION);\n if (!ack.success) {\n throw new Error(ack.error ?? \"billing.cancelSubscription failed\");\n }\n }, [sendBillingAction]);\n\n const billingReactivateSubscription = useCallback(async (): Promise<void> => {\n const ack = await sendBillingAction(BILLING_OPERATION.REACTIVATE_SUBSCRIPTION);\n if (!ack.success) {\n throw new Error(ack.error ?? \"billing.reactivateSubscription failed\");\n }\n }, [sendBillingAction]);\n\n const billingSwitchPlan = useCallback(\n async (newPlanSlug: string): Promise<void> => {\n const ack = await sendBillingAction(BILLING_OPERATION.SWITCH_PLAN, {\n planSlug: newPlanSlug,\n });\n if (!ack.success) {\n throw new Error(ack.error ?? \"billing.switchPlan failed\");\n }\n },\n [sendBillingAction],\n );\n\n const billing: BillingActions = {\n getPlans: billingGetPlans,\n getSubscription: billingGetSubscription,\n requestSubscription: billingRequestSubscription,\n cancelSubscription: billingCancelSubscription,\n reactivateSubscription: billingReactivateSubscription,\n switchPlan: billingSwitchPlan,\n };\n\n return { sendAction, showToast, navigate, openModal, closeModal, resize, billing };\n}\n","/** Context data sent from the admin host to a plugin iframe */\nexport interface WhataloContext {\n /** Store UUID */\n storeId: string;\n /** Store display name */\n storeName: string;\n /** Current order ID (set when plugin opens from order detail) */\n orderId?: string;\n /** Current order status */\n orderStatus?: string;\n /** Current product ID (set when plugin opens from product detail) */\n productId?: string;\n /** Authenticated user info */\n user: WhataloUser;\n /** Plugin ID from the manifest */\n appId: string;\n /** Current admin page path (e.g., \"/integrations/my-plugin/settings\") */\n currentPage: string;\n /** Locale code (e.g., \"es\", \"en\") */\n locale: string;\n /** Active color scheme */\n theme: \"light\" | \"dark\";\n /** Suggested initial iframe height in pixels */\n initialHeight: number;\n}\n\n/**\n * Authenticated user information provided to the plugin.\n *\n * `role` reflects the user's actual role in the store, not a hardcoded value.\n * Current Whatalo stores are single-owner, so the role will always be \"owner\"\n * for now. The union type is forward-compatible for future multi-member support.\n */\nexport interface WhataloUser {\n id: string;\n name: string;\n email: string;\n role: \"owner\" | \"admin\" | \"editor\" | \"staff\" | \"viewer\";\n}\n\n/** Available bridge actions the plugin can dispatch */\nexport type BridgeAction =\n | \"navigate\"\n | \"toast\"\n | \"modal\"\n | \"resize\"\n | \"ready\"\n | \"billing\";\n\n// ---------------------------------------------------------------------------\n// Billing types\n// ---------------------------------------------------------------------------\n\n/** All billing operations supported by the bridge. createUsageRecord is reserved for v2. */\nexport const BILLING_OPERATION = {\n GET_PLANS: \"getPlans\",\n GET_SUBSCRIPTION: \"getSubscription\",\n REQUEST_SUBSCRIPTION: \"requestSubscription\",\n CANCEL_SUBSCRIPTION: \"cancelSubscription\",\n REACTIVATE_SUBSCRIPTION: \"reactivateSubscription\",\n SWITCH_PLAN: \"switchPlan\",\n CREATE_USAGE_RECORD: \"createUsageRecord\",\n} as const;\n\nexport type BillingOperation =\n (typeof BILLING_OPERATION)[keyof typeof BILLING_OPERATION];\n\n/** Payload sent from the plugin to the host for billing actions. */\nexport interface BillingPayload {\n operation: BillingOperation;\n /** Required for requestSubscription */\n planSlug?: string;\n /** Human-readable reason for the subscription request */\n description?: string;\n /** Reserved for createUsageRecord (v2) */\n amount?: number;\n /** Idempotency key for safe retries (v2) */\n idempotencyKey?: string;\n}\n\n/** A single pricing plan returned by getPlans. */\nexport interface BillingPlanResponse {\n slug: string;\n name: string;\n price: number;\n currency: string;\n /** \"monthly\" | \"annual\" | null (null for one-time or usage plans) */\n interval: string | null;\n trialDays: number;\n features: string[];\n isPopular: boolean;\n}\n\n/** The store's current subscription to this plugin, returned by getSubscription. */\nexport interface BillingSubscriptionResponse {\n planSlug: string;\n planName: string;\n /** \"pending\" | \"trialing\" | \"active\" | \"past_due\" | \"canceled\" */\n status: string;\n trialEndsAt: string | null;\n currentPeriodEnd: string | null;\n /** Whether the subscription is scheduled for cancellation at period end */\n cancelAtPeriodEnd: boolean;\n /** ISO timestamp of when the cancellation was initiated, or null */\n canceledAt: string | null;\n}\n\n/** Message sent from admin host to plugin with context data */\nexport interface ContextMessage {\n type: \"whatalo:context\";\n data: WhataloContext;\n}\n\n/** Action message sent from plugin to admin host */\nexport interface ActionMessage {\n type: \"whatalo:action\";\n actionId: string;\n action: BridgeAction;\n payload: Record<string, unknown>;\n}\n\n/** Acknowledgement message sent from admin host back to plugin */\nexport interface ActionAck {\n type: \"whatalo:ack\";\n actionId: string;\n success: boolean;\n error?: string;\n}\n\n/** Payload for toast notifications */\nexport interface ToastPayload {\n title: string;\n description?: string;\n variant?: \"success\" | \"error\" | \"warning\" | \"info\";\n}\n\n/** Payload for admin navigation */\nexport interface NavigatePayload {\n path: string;\n}\n\n/** Payload for modal operations */\nexport interface ModalPayload {\n operation: \"open\" | \"close\";\n title?: string;\n url?: string;\n width?: number;\n height?: number;\n}\n\n/** Payload for iframe resize */\nexport interface ResizePayload {\n height: number;\n}\n","import { useWhataloContext } from \"./use-whatalo-context.js\";\nimport { useWhataloAction } from \"./use-whatalo-action.js\";\nimport type {\n ActionAck,\n ToastPayload,\n ModalPayload,\n WhataloUser,\n BillingPlanResponse,\n BillingSubscriptionResponse,\n} from \"./types.js\";\nimport type { BillingActions } from \"./use-whatalo-action.js\";\n\nexport interface AppBridgeToast {\n /** Show a toast notification in the admin host */\n show: (\n title: string,\n options?: Omit<ToastPayload, \"title\">,\n ) => Promise<ActionAck>;\n}\n\nexport interface AppBridgeModal {\n /** Open a modal in the admin host */\n open: (options: Omit<ModalPayload, \"operation\">) => Promise<ActionAck>;\n /** Close the currently open modal */\n close: () => Promise<ActionAck>;\n}\n\n/** Re-export for consumers who import directly from use-app-bridge */\nexport type { BillingActions, BillingPlanResponse, BillingSubscriptionResponse };\n\nexport interface AppBridge {\n /** Store UUID */\n storeId: string;\n /** Store display name */\n storeName: string;\n /** Locale code (e.g., \"es\", \"en\") */\n locale: string;\n /** Active color scheme */\n theme: \"light\" | \"dark\";\n /** Authenticated user info */\n user: WhataloUser;\n /** Plugin ID from the manifest */\n appId: string;\n /** Whether the plugin has received context from the admin host */\n isReady: boolean;\n /** Toast notification helpers */\n toast: AppBridgeToast;\n /** Navigate the admin to a path */\n navigate: (path: string) => Promise<ActionAck>;\n /** Modal helpers */\n modal: AppBridgeModal;\n /** Request an iframe resize */\n resize: (height: number) => Promise<ActionAck>;\n /** Billing actions — query plans and manage subscriptions */\n billing: BillingActions;\n}\n\n/**\n * Unified bridge hook that combines context and actions into a single API.\n * This is the primary hook plugin developers should use.\n *\n * @example\n * ```tsx\n * const bridge = useAppBridge();\n * bridge.toast.show(\"Saved!\", { variant: \"success\" });\n * bridge.navigate(\"/orders\");\n * ```\n */\nexport function useAppBridge(): AppBridge {\n const ctx = useWhataloContext();\n const actions = useWhataloAction();\n\n return {\n storeId: ctx.storeId,\n storeName: ctx.storeName,\n locale: ctx.locale,\n theme: ctx.theme,\n user: ctx.user,\n appId: ctx.appId,\n isReady: ctx.isReady,\n toast: {\n show: (title, options) =>\n actions.showToast({ title, ...options }),\n },\n navigate: actions.navigate,\n modal: {\n open: actions.openModal,\n close: actions.closeModal,\n },\n resize: actions.resize,\n billing: actions.billing,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EAET,YACE,SACA,YACA,MACA,WACA;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,OAAO;AACZ,SAAK,YAAY;AAAA,EACnB;AACF;AAGO,IAAM,sBAAN,cAAkC,gBAAgB;AAAA,EACvD,YACE,UAAU,8BACV,WACA;AACA,UAAM,SAAS,KAAK,wBAAwB,SAAS;AACrD,SAAK,OAAO;AAAA,EACd;AACF;AAGO,IAAM,qBAAN,cAAiC,gBAAgB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rC,aAAO,OAAO;AAAA,QACZ;AAAA,UACE,MAAM;AAAA,UACN,UAAU,OAAO,WAAW;AAAA,UAC5B,QAAQ;AAAA,UACR,SAAS,CAAC;AAAA,QACZ;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO,MAAM,OAAO,oBAAoB,WAAW,aAAa;AAAA,EAClE,GAAG,CAAC,aAAa,CAAC;AAElB,SAAO,EAAE,GAAG,SAAS,QAAQ;AAC/B;;;AGHO,SAAS,eAA0B;AACxC,QAAM,MAAM,kBAAkB;AAC9B,QAAM,UAAU,iBAAiB;AAEjC,SAAO;AAAA,IACL,SAAS,IAAI;AAAA,IACb,WAAW,IAAI;AAAA,IACf,QAAQ,IAAI;AAAA,IACZ,OAAO,IAAI;AAAA,IACX,MAAM,IAAI;AAAA,IACV,OAAO,IAAI;AAAA,IACX,SAAS,IAAI;AAAA,IACb,OAAO;AAAA,MACL,MAAM,CAAC,OAAO,YACZ,QAAQ,UAAU,EAAE,OAAO,GAAG,QAAQ,CAAC;AAAA,IAC3C;AAAA,IACA,UAAU,QAAQ;AAAA,IAClB,OAAO;AAAA,MACL,MAAM,QAAQ;AAAA,MACd,OAAO,QAAQ;AAAA,IACjB;AAAA,IACA,QAAQ,QAAQ;AAAA,IAChB,SAAS,QAAQ;AAAA,EACnB;AACF;;;AR3FO,IAAM,cAAc;","names":["import_react"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export { WhataloClient } from './client/index.cjs';
|
|
2
|
+
export { A as AdjustInventoryParams, f as Category, g as CreateCategoryParams, j as CreateDiscountParams, C as CreateProductParams, d as Customer, D as Discount, I as InventoryItem, e as ListCategoriesParams, c as ListCustomersParams, i as ListDiscountsParams, b as ListOrdersParams, L as ListProductsParams, O as Order, P as PaginatedResponse, a as Product, R as RateLimitInfo, S as SingleResponse, l as Store, h as UpdateCategoryParams, k as UpdateDiscountParams, U as UpdateProductParams, n as UpdateWebhookParams, m as UpsertWebhookParams, W as Webhook, o as WhataloClientOptions } from './types-M1eLMz6w.cjs';
|
|
3
|
+
export { VerifyWebhookParams, verifyWebhook } from './webhooks/index.cjs';
|
|
4
|
+
export { W as WebhookEvent, b as WebhookEventData, a as WebhookPayload } from './types-DdqKKyqX.cjs';
|
|
5
|
+
export { AppCategory, AppManifest, AppPermission, ManifestValidationError, defineApp } from './manifest/index.cjs';
|
|
6
|
+
export { ActionAck, AppBridge, AppBridgeModal, AppBridgeToast, BILLING_OPERATION, BillingActions, BillingOperation, BillingPayload, BillingPlanResponse, BillingSubscriptionResponse, BridgeAction, ModalPayload, NavigatePayload, ResizePayload, ToastPayload, UseWhataloActionReturn, UseWhataloContextReturn, WhataloContext, WhataloUser, useAppBridge, useWhataloAction, useWhataloContext } from './bridge/index.cjs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Base error for all SDK errors.
|
|
10
|
+
* Contains the HTTP status code and a machine-readable error code.
|
|
11
|
+
*/
|
|
12
|
+
declare class WhataloAPIError extends Error {
|
|
13
|
+
readonly statusCode: number;
|
|
14
|
+
readonly code: string;
|
|
15
|
+
readonly requestId?: string;
|
|
16
|
+
constructor(message: string, statusCode: number, code: string, requestId?: string);
|
|
17
|
+
}
|
|
18
|
+
/** 401 — Invalid or missing API key */
|
|
19
|
+
declare class AuthenticationError extends WhataloAPIError {
|
|
20
|
+
constructor(message?: string, requestId?: string);
|
|
21
|
+
}
|
|
22
|
+
/** 403 — API key lacks required permission scope */
|
|
23
|
+
declare class AuthorizationError extends WhataloAPIError {
|
|
24
|
+
readonly requiredScope: string;
|
|
25
|
+
constructor(message: string, requiredScope: string, requestId?: string);
|
|
26
|
+
}
|
|
27
|
+
/** 404 — Resource not found */
|
|
28
|
+
declare class NotFoundError extends WhataloAPIError {
|
|
29
|
+
readonly resourceType: string;
|
|
30
|
+
readonly resourceId: string;
|
|
31
|
+
constructor(resourceType: string, resourceId: string, requestId?: string);
|
|
32
|
+
}
|
|
33
|
+
/** 422 — Request body validation failed */
|
|
34
|
+
declare class ValidationError extends WhataloAPIError {
|
|
35
|
+
readonly fieldErrors: Array<{
|
|
36
|
+
field: string;
|
|
37
|
+
message: string;
|
|
38
|
+
}>;
|
|
39
|
+
constructor(fieldErrors: Array<{
|
|
40
|
+
field: string;
|
|
41
|
+
message: string;
|
|
42
|
+
}>, requestId?: string);
|
|
43
|
+
}
|
|
44
|
+
/** 429 — Rate limit exceeded */
|
|
45
|
+
declare class RateLimitError extends WhataloAPIError {
|
|
46
|
+
/** Seconds until the rate limit resets */
|
|
47
|
+
readonly retryAfter: number;
|
|
48
|
+
constructor(retryAfter: number, requestId?: string);
|
|
49
|
+
}
|
|
50
|
+
/** 500 — Server-side error */
|
|
51
|
+
declare class InternalError extends WhataloAPIError {
|
|
52
|
+
constructor(message?: string, requestId?: string);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
declare const SDK_VERSION = "0.0.1";
|
|
56
|
+
|
|
57
|
+
export { AuthenticationError, AuthorizationError, InternalError, NotFoundError, RateLimitError, SDK_VERSION, ValidationError, WhataloAPIError };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export { WhataloClient } from './client/index.js';
|
|
2
|
+
export { A as AdjustInventoryParams, f as Category, g as CreateCategoryParams, j as CreateDiscountParams, C as CreateProductParams, d as Customer, D as Discount, I as InventoryItem, e as ListCategoriesParams, c as ListCustomersParams, i as ListDiscountsParams, b as ListOrdersParams, L as ListProductsParams, O as Order, P as PaginatedResponse, a as Product, R as RateLimitInfo, S as SingleResponse, l as Store, h as UpdateCategoryParams, k as UpdateDiscountParams, U as UpdateProductParams, n as UpdateWebhookParams, m as UpsertWebhookParams, W as Webhook, o as WhataloClientOptions } from './types-M1eLMz6w.js';
|
|
3
|
+
export { VerifyWebhookParams, verifyWebhook } from './webhooks/index.js';
|
|
4
|
+
export { W as WebhookEvent, b as WebhookEventData, a as WebhookPayload } from './types-DZ659i6f.js';
|
|
5
|
+
export { AppCategory, AppManifest, AppPermission, ManifestValidationError, defineApp } from './manifest/index.js';
|
|
6
|
+
export { ActionAck, AppBridge, AppBridgeModal, AppBridgeToast, BILLING_OPERATION, BillingActions, BillingOperation, BillingPayload, BillingPlanResponse, BillingSubscriptionResponse, BridgeAction, ModalPayload, NavigatePayload, ResizePayload, ToastPayload, UseWhataloActionReturn, UseWhataloContextReturn, WhataloContext, WhataloUser, useAppBridge, useWhataloAction, useWhataloContext } from './bridge/index.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Base error for all SDK errors.
|
|
10
|
+
* Contains the HTTP status code and a machine-readable error code.
|
|
11
|
+
*/
|
|
12
|
+
declare class WhataloAPIError extends Error {
|
|
13
|
+
readonly statusCode: number;
|
|
14
|
+
readonly code: string;
|
|
15
|
+
readonly requestId?: string;
|
|
16
|
+
constructor(message: string, statusCode: number, code: string, requestId?: string);
|
|
17
|
+
}
|
|
18
|
+
/** 401 — Invalid or missing API key */
|
|
19
|
+
declare class AuthenticationError extends WhataloAPIError {
|
|
20
|
+
constructor(message?: string, requestId?: string);
|
|
21
|
+
}
|
|
22
|
+
/** 403 — API key lacks required permission scope */
|
|
23
|
+
declare class AuthorizationError extends WhataloAPIError {
|
|
24
|
+
readonly requiredScope: string;
|
|
25
|
+
constructor(message: string, requiredScope: string, requestId?: string);
|
|
26
|
+
}
|
|
27
|
+
/** 404 — Resource not found */
|
|
28
|
+
declare class NotFoundError extends WhataloAPIError {
|
|
29
|
+
readonly resourceType: string;
|
|
30
|
+
readonly resourceId: string;
|
|
31
|
+
constructor(resourceType: string, resourceId: string, requestId?: string);
|
|
32
|
+
}
|
|
33
|
+
/** 422 — Request body validation failed */
|
|
34
|
+
declare class ValidationError extends WhataloAPIError {
|
|
35
|
+
readonly fieldErrors: Array<{
|
|
36
|
+
field: string;
|
|
37
|
+
message: string;
|
|
38
|
+
}>;
|
|
39
|
+
constructor(fieldErrors: Array<{
|
|
40
|
+
field: string;
|
|
41
|
+
message: string;
|
|
42
|
+
}>, requestId?: string);
|
|
43
|
+
}
|
|
44
|
+
/** 429 — Rate limit exceeded */
|
|
45
|
+
declare class RateLimitError extends WhataloAPIError {
|
|
46
|
+
/** Seconds until the rate limit resets */
|
|
47
|
+
readonly retryAfter: number;
|
|
48
|
+
constructor(retryAfter: number, requestId?: string);
|
|
49
|
+
}
|
|
50
|
+
/** 500 — Server-side error */
|
|
51
|
+
declare class InternalError extends WhataloAPIError {
|
|
52
|
+
constructor(message?: string, requestId?: string);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
declare const SDK_VERSION = "0.0.1";
|
|
56
|
+
|
|
57
|
+
export { AuthenticationError, AuthorizationError, InternalError, NotFoundError, RateLimitError, SDK_VERSION, ValidationError, WhataloAPIError };
|