threeu-sdk 0.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/README.md +176 -0
- package/dist/admin/index.d.ts +22 -0
- package/dist/admin/index.js +17 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/chunk-2TGBSV6L.js +197 -0
- package/dist/chunk-2TGBSV6L.js.map +1 -0
- package/dist/chunk-6S7OFN23.js +81 -0
- package/dist/chunk-6S7OFN23.js.map +1 -0
- package/dist/chunk-6ZCBDWWQ.js +140 -0
- package/dist/chunk-6ZCBDWWQ.js.map +1 -0
- package/dist/chunk-BCUODRZW.js +78 -0
- package/dist/chunk-BCUODRZW.js.map +1 -0
- package/dist/chunk-H3XILKGI.js +70 -0
- package/dist/chunk-H3XILKGI.js.map +1 -0
- package/dist/chunk-HYSJ6YPN.js +425 -0
- package/dist/chunk-HYSJ6YPN.js.map +1 -0
- package/dist/chunk-LFF5LPWT.js +122 -0
- package/dist/chunk-LFF5LPWT.js.map +1 -0
- package/dist/chunk-OXAQGEMQ.js +3 -0
- package/dist/chunk-OXAQGEMQ.js.map +1 -0
- package/dist/chunk-USFJIM5K.js +195 -0
- package/dist/chunk-USFJIM5K.js.map +1 -0
- package/dist/chunk-ZWLFJIAM.js +69 -0
- package/dist/chunk-ZWLFJIAM.js.map +1 -0
- package/dist/define-B6ZJMWDI.d.ts +24 -0
- package/dist/developer/index.d.ts +120 -0
- package/dist/developer/index.js +106 -0
- package/dist/developer/index.js.map +1 -0
- package/dist/errors/index.d.ts +83 -0
- package/dist/errors/index.js +4 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index-ksmDFDZc.d.ts +90 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin/index.d.ts +13 -0
- package/dist/plugin/index.js +27 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/server/index.d.ts +70 -0
- package/dist/plugin/server/index.js +105 -0
- package/dist/plugin/server/index.js.map +1 -0
- package/dist/pos/index.d.ts +26 -0
- package/dist/pos/index.js +24 -0
- package/dist/pos/index.js.map +1 -0
- package/dist/react/index.d.ts +5 -0
- package/dist/react/index.js +7 -0
- package/dist/react/index.js.map +1 -0
- package/dist/session-BFDRm-KJ.d.ts +94 -0
- package/dist/storefront/index.d.ts +76 -0
- package/dist/storefront/index.js +6 -0
- package/dist/storefront/index.js.map +1 -0
- package/dist/testing/index.d.ts +82 -0
- package/dist/testing/index.js +106 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/theme/index.d.ts +109 -0
- package/dist/theme/index.js +152 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/threeu-BesFjXdw.d.ts +143 -0
- package/dist/types-BoGD3IXz.d.ts +173 -0
- package/dist/types-DfyYnoLn.d.ts +248 -0
- package/dist/webhooks/index.d.ts +36 -0
- package/dist/webhooks/index.js +4 -0
- package/dist/webhooks/index.js.map +1 -0
- package/package.json +110 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/theme/define.ts","../../src/theme/components.tsx"],"names":[],"mappings":";;;;;;;;;;AAkCO,SAAS,YAAY,OAAA,EAA2C;AACrE,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,IAAA,CAAK,OAAA,CAAQ,KAAK,CAAA;AAE3C,EAAA,MAAM,WAAW,MAAqB;AACpC,IAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,MAAA,IAAU,EAAC;AACpC,IAAA,MAAM,YAAY,aAAA,EAAc;AAChC,IAAA,MAAM,MAAA,uBAAa,GAAA,EAAgC;AACnD,IAAA,KAAA,MAAW,CAAA,IAAK,CAAC,GAAG,SAAA,EAAW,GAAG,QAAQ,CAAA,EAAG,MAAA,CAAO,GAAA,CAAI,CAAA,CAAE,IAAA,EAAM,CAAC,CAAA;AACjE,IAAA,OAAO,kBAAA,CAAmB;AAAA,MACxB,MAAM,OAAA,CAAQ,IAAA;AAAA,MACd,MAAM,O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;AACnD;AAEA,SAAS,WAAA,CAAY,OAAoC,QAAA,EAAsC;AAC7F,EAAA,IAAI,KAAA,KAAU,QAAW,OAAO,EAAA;AAChC,EAAA,MAAM,IAAI,OAAO,KAAA,KAAU,QAAA,GAAW,MAAA,CAAO,KAAK,CAAA,GAAI,KAAA;AACtD,EAAA,IAAI,CAAC,MAAA,CAAO,QAAA,CAAS,CAAC,CAAA,EAAG,OAAO,OAAO,KAAK,CAAA;AAC5C,EAAA,OAAO,CAAA,EAAG,EAAE,OAAA,CAAQ,CAAC,CAAC,CAAA,CAAA,EAAI,QAAA,IAAY,EAAE,CAAA,CAAA,CAAG,IAAA,EAAK;AAClD","file":"index.js","sourcesContent":["/**\n * createTheme / defineTheme — register pages and produce a theme manifest.\n *\n * Editable fields are discovered at render time via the runtime registry, so\n * `manifest()` merges any explicitly declared fields with those collected from\n * the most recent render/extraction pass. A CLI build step can render each page\n * once and then call `manifest()` to capture the full field set.\n */\nimport type { ComponentType } from \"react\";\nimport { buildThemeManifest } from \"../manifests/build\";\nimport type { ThemeEditableField, ThemeManifest, ThemeVisibility } from \"../manifests/types\";\nimport { extractFields } from \"./runtime\";\n\nexport interface CreateThemeOptions {\n name: string;\n slug: string;\n version?: string;\n visibility?: ThemeVisibility;\n pages: Record<string, ComponentType<Record<string, unknown>>>;\n /** Explicitly declared editable fields (merged with render-extracted ones). */\n fields?: ThemeEditableField[];\n}\n\nexport interface DefinedTheme {\n readonly name: string;\n readonly slug: string;\n readonly visibility: ThemeVisibility;\n readonly pages: Record<string, ComponentType<Record<string, unknown>>>;\n getPage(name: string): ComponentType<Record<string, unknown>> | undefined;\n /** Build the theme manifest, merging declared + render-extracted fields. */\n manifest(): ThemeManifest;\n toJSON(): ThemeManifest;\n}\n\nexport function createTheme(options: CreateThemeOptions): DefinedTheme {\n const pageNames = Object.keys(options.pages);\n\n const manifest = (): ThemeManifest => {\n const declared = options.fields ?? [];\n const extracted = extractFields();\n const byName = new Map<string, ThemeEditableField>();\n for (const f of [...extracted, ...declared]) byName.set(f.name, f);\n return buildThemeManifest({\n name: options.name,\n slug: options.slug,\n version: options.version,\n visibility: options.visibility,\n pages: pageNames,\n fields: Array.from(byName.values()),\n });\n };\n\n return {\n name: options.name,\n slug: options.slug,\n visibility: options.visibility ?? \"public\",\n pages: options.pages,\n getPage: (name) => options.pages[name],\n manifest,\n toJSON: manifest,\n };\n}\n\n/** Alias — some authors prefer `defineTheme`. */\nexport const defineTheme = createTheme;\n","/**\n * Type-safe, customizable theme components. Each `T*` component registers the\n * editable field it exposes (so the theme editor / build step can enumerate\n * them) and resolves its current value from the active customization.\n *\n * Editable elements carry a `data-threeu-field` attribute the in-app editor uses\n * to target them.\n */\nimport type { CSSProperties, ReactNode } from \"react\";\nimport { useThemeField } from \"./context\";\nimport { registerField, resolveValue } from \"./runtime\";\nimport type { Collection, Product } from \"../resources/types\";\n\n/** Resolve (and register) a color field. Usable inline: `TColor(\"hero.bg\", \"#000\")`. */\nexport function TColor(name: string, fallback = \"#000000\"): string {\n registerField(name, \"color\", fallback);\n return resolveValue<string>(name, fallback);\n}\n\ninterface FieldProps {\n name: string;\n className?: string;\n style?: CSSProperties;\n}\n\nexport function TSection(props: FieldProps & { children?: ReactNode }): JSX.Element {\n return (\n <section data-threeu-field={props.name} data-threeu-kind=\"section\" className={props.className} style={props.style}>\n {props.children}\n </section>\n );\n}\n\nexport function THeading(props: FieldProps & { children?: ReactNode; as?: \"h1\" | \"h2\" | \"h3\" }): JSX.Element {\n const text = useThemeField<string>(props.name, \"heading\", asText(props.children));\n const Tag = props.as ?? \"h1\";\n return (\n <Tag data-threeu-field={props.name} data-threeu-kind=\"heading\" className={props.className} style={props.style}>\n {text}\n </Tag>\n );\n}\n\nexport function TParagraph(props: FieldProps & { children?: ReactNode }): JSX.Element {\n const text = useThemeField<string>(props.name, \"paragraph\", asText(props.children));\n return (\n <p data-threeu-field={props.name} data-threeu-kind=\"paragraph\" className={props.className} style={props.style}>\n {text}\n </p>\n );\n}\n\nexport function TText(props: FieldProps & { children?: ReactNode }): JSX.Element {\n const text = useThemeField<string>(props.name, \"text\", asText(props.children));\n return (\n <span data-threeu-field={props.name} data-threeu-kind=\"text\" className={props.className} style={props.style}>\n {text}\n </span>\n );\n}\n\nexport function TSpan(props: FieldProps & { children?: ReactNode }): JSX.Element {\n const text = useThemeField<string>(props.name, \"span\", asText(props.children));\n return (\n <span data-threeu-field={props.name} data-threeu-kind=\"span\" className={props.className} style={props.style}>\n {text}\n </span>\n );\n}\n\nexport function TImage(\n props: FieldProps & { src: string; alt: string; width?: number | string; height?: number | string },\n): JSX.Element {\n const src = useThemeField<string>(props.name, \"image\", props.src);\n return (\n <img\n data-threeu-field={props.name}\n data-threeu-kind=\"image\"\n src={src}\n alt={props.alt}\n width={props.width}\n height={props.height}\n className={props.className}\n style={props.style}\n />\n );\n}\n\nexport function TButton(\n props: FieldProps & { children?: ReactNode; onClick?: () => void; type?: \"button\" | \"submit\" },\n): JSX.Element {\n const label = useThemeField<string>(props.name, \"text\", asText(props.children));\n return (\n <button\n data-threeu-field={props.name}\n data-threeu-kind=\"text\"\n type={props.type ?? \"button\"}\n onClick={props.onClick}\n className={props.className}\n style={props.style}\n >\n {label}\n </button>\n );\n}\n\nexport function TLink(props: FieldProps & { href: string; children?: ReactNode }): JSX.Element {\n const href = useThemeField<string>(props.name, \"link\", props.href);\n return (\n <a data-threeu-field={props.name} data-threeu-kind=\"link\" href={href} className={props.className} style={props.style}>\n {props.children}\n </a>\n );\n}\n\n// --- Data display components (not editable; render brand data) --------------\n\nexport function TProductCard(props: { product: Product; className?: string }): JSX.Element {\n const { product } = props;\n return (\n <div data-threeu-product={String(product.id)} className={props.className}>\n <div className=\"threeu-product-name\">{String(product.name ?? \"\")}</div>\n <div className=\"threeu-product-price\">{formatPrice(product.price, product.currency)}</div>\n </div>\n );\n}\n\nexport function TProductGrid(props: { products: Product[]; columns?: number; className?: string }): JSX.Element {\n const columns = props.columns ?? 3;\n return (\n <div\n className={props.className}\n style={{ display: \"grid\", gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`, gap: \"1rem\" }}\n >\n {props.products.map((p) => (\n <TProductCard key={String(p.id)} product={p} />\n ))}\n </div>\n );\n}\n\nexport function TCollectionGrid(props: { collections: Collection[]; className?: string }): JSX.Element {\n return (\n <div className={props.className} style={{ display: \"grid\", gap: \"1rem\" }}>\n {props.collections.map((c) => (\n <div key={String(c.id)} data-threeu-collection={String(c.id)}>\n {String(c.title ?? c.handle ?? c.id)}\n </div>\n ))}\n </div>\n );\n}\n\nexport function TCartSummary(props: { cart?: Record<string, unknown>; className?: string }): JSX.Element {\n const items = Array.isArray(props.cart?.items) ? (props.cart?.items as unknown[]) : [];\n return (\n <div className={props.className} data-threeu-cart-summary>\n <div>{items.length} item(s)</div>\n </div>\n );\n}\n\nexport function TCheckoutForm(props: {\n onSubmit?: (data: Record<string, FormDataEntryValue>) => void;\n className?: string;\n children?: ReactNode;\n}): JSX.Element {\n return (\n <form\n className={props.className}\n data-threeu-checkout-form\n onSubmit={(e) => {\n e.preventDefault();\n const data = Object.fromEntries(new FormData(e.currentTarget).entries());\n props.onSubmit?.(data);\n }}\n >\n {props.children}\n </form>\n );\n}\n\nfunction asText(children: ReactNode): string {\n return typeof children === \"string\" ? children : \"\";\n}\n\nfunction formatPrice(price: number | string | undefined, currency: string | undefined): string {\n if (price === undefined) return \"\";\n const n = typeof price === \"string\" ? Number(price) : price;\n if (!Number.isFinite(n)) return String(price);\n return `${n.toFixed(2)} ${currency ?? \"\"}`.trim();\n}\n"]}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { d as Product, e as ProductInput, O as Order, I as Id, a as Customer, b as InventoryItem, C as Collection, D as Discount, P as Payment, S as ShippingRate, c as Location, T as ThreeuHttpClient, j as TokenType, i as ThreeuClientOptions } from './types-DfyYnoLn.js';
|
|
2
|
+
import { h as CrudResource, R as ResourceContext, g as PosNamespace } from './session-BFDRm-KJ.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Concrete brand resources. Each adds domain actions on top of `CrudResource`.
|
|
6
|
+
* Resource path constants live here so backend route changes are a one-line edit.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare class ProductsResource extends CrudResource<Product, ProductInput> {
|
|
10
|
+
constructor(ctx: ResourceContext);
|
|
11
|
+
}
|
|
12
|
+
declare class OrdersResource extends CrudResource<Order> {
|
|
13
|
+
constructor(ctx: ResourceContext);
|
|
14
|
+
fulfill(id: Id, body?: Record<string, unknown>): Promise<Order>;
|
|
15
|
+
cancel(id: Id, body?: Record<string, unknown>): Promise<Order>;
|
|
16
|
+
}
|
|
17
|
+
declare class CustomersResource extends CrudResource<Customer> {
|
|
18
|
+
constructor(ctx: ResourceContext);
|
|
19
|
+
}
|
|
20
|
+
declare class CollectionsResource extends CrudResource<Collection> {
|
|
21
|
+
constructor(ctx: ResourceContext);
|
|
22
|
+
}
|
|
23
|
+
declare class DiscountsResource extends CrudResource<Discount> {
|
|
24
|
+
constructor(ctx: ResourceContext);
|
|
25
|
+
}
|
|
26
|
+
declare class LocationsResource extends CrudResource<Location> {
|
|
27
|
+
constructor(ctx: ResourceContext);
|
|
28
|
+
}
|
|
29
|
+
declare class InventoryResource extends CrudResource<InventoryItem> {
|
|
30
|
+
constructor(ctx: ResourceContext);
|
|
31
|
+
adjust(body: {
|
|
32
|
+
product_id: Id;
|
|
33
|
+
location_id?: Id;
|
|
34
|
+
delta: number;
|
|
35
|
+
reason?: string;
|
|
36
|
+
}): Promise<InventoryItem>;
|
|
37
|
+
transfer(body: {
|
|
38
|
+
product_id: Id;
|
|
39
|
+
from_location_id: Id;
|
|
40
|
+
to_location_id: Id;
|
|
41
|
+
quantity: number;
|
|
42
|
+
}): Promise<InventoryItem>;
|
|
43
|
+
}
|
|
44
|
+
declare class PaymentsResource extends CrudResource<Payment> {
|
|
45
|
+
constructor(ctx: ResourceContext);
|
|
46
|
+
refund(id: Id, body?: {
|
|
47
|
+
amount?: number;
|
|
48
|
+
reason?: string;
|
|
49
|
+
}): Promise<Payment>;
|
|
50
|
+
}
|
|
51
|
+
declare class ShippingResource {
|
|
52
|
+
private readonly ctx;
|
|
53
|
+
constructor(ctx: ResourceContext);
|
|
54
|
+
private opts;
|
|
55
|
+
rates(body: {
|
|
56
|
+
destination: string;
|
|
57
|
+
items: unknown[];
|
|
58
|
+
}): Promise<ShippingRate[]>;
|
|
59
|
+
createShipment(body: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
60
|
+
trackShipment(trackingNumber: string): Promise<Record<string, unknown>>;
|
|
61
|
+
}
|
|
62
|
+
declare class AnalyticsResource {
|
|
63
|
+
private readonly ctx;
|
|
64
|
+
constructor(ctx: ResourceContext);
|
|
65
|
+
private opts;
|
|
66
|
+
summary(params?: {
|
|
67
|
+
from?: string;
|
|
68
|
+
to?: string;
|
|
69
|
+
}): Promise<Record<string, unknown>>;
|
|
70
|
+
sales(params?: {
|
|
71
|
+
from?: string;
|
|
72
|
+
to?: string;
|
|
73
|
+
interval?: string;
|
|
74
|
+
}): Promise<Record<string, unknown>>;
|
|
75
|
+
products(params?: {
|
|
76
|
+
from?: string;
|
|
77
|
+
to?: string;
|
|
78
|
+
limit?: number;
|
|
79
|
+
}): Promise<Record<string, unknown>>;
|
|
80
|
+
}
|
|
81
|
+
declare class CampaignsResource extends CrudResource {
|
|
82
|
+
constructor(ctx: ResourceContext);
|
|
83
|
+
}
|
|
84
|
+
declare class MarketingResource {
|
|
85
|
+
readonly campaigns: CampaignsResource;
|
|
86
|
+
constructor(ctx: ResourceContext);
|
|
87
|
+
}
|
|
88
|
+
declare class ThemeResource {
|
|
89
|
+
private readonly ctx;
|
|
90
|
+
constructor(ctx: ResourceContext);
|
|
91
|
+
private opts;
|
|
92
|
+
get(): Promise<Record<string, unknown>>;
|
|
93
|
+
update(body: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Scoped brand object returned by `client.brand(slug)`. Every resource call is
|
|
98
|
+
* automatically scoped to this brand via the `platform-id` header. This is the
|
|
99
|
+
* SDK object the brief's core DX revolves around (`brand.products.create(...)`).
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
declare class BrandClient {
|
|
103
|
+
readonly id: Id;
|
|
104
|
+
readonly products: ProductsResource;
|
|
105
|
+
readonly orders: OrdersResource;
|
|
106
|
+
readonly customers: CustomersResource;
|
|
107
|
+
readonly inventory: InventoryResource;
|
|
108
|
+
readonly collections: CollectionsResource;
|
|
109
|
+
readonly discounts: DiscountsResource;
|
|
110
|
+
readonly payments: PaymentsResource;
|
|
111
|
+
readonly shipping: ShippingResource;
|
|
112
|
+
readonly locations: LocationsResource;
|
|
113
|
+
readonly analytics: AnalyticsResource;
|
|
114
|
+
readonly marketing: MarketingResource;
|
|
115
|
+
readonly theme: ThemeResource;
|
|
116
|
+
readonly pos: PosNamespace;
|
|
117
|
+
constructor(http: ThreeuHttpClient, brand: Id);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* `Threeu` — the high-level entry client. Constructed with a secret key, it
|
|
122
|
+
* yields brand-scoped objects:
|
|
123
|
+
*
|
|
124
|
+
* const threeu = new Threeu(process.env.THREEU_SECRET_KEY!);
|
|
125
|
+
* const brand = await threeu.brand("my-store");
|
|
126
|
+
* await brand.products.create({ name: "Black Abaya", price: 350, currency: "QAR" });
|
|
127
|
+
*/
|
|
128
|
+
|
|
129
|
+
type ThreeuOptions = Omit<ThreeuClientOptions, "token" | "tokenType">;
|
|
130
|
+
declare class Threeu {
|
|
131
|
+
readonly http: ThreeuHttpClient;
|
|
132
|
+
protected readonly tokenType: TokenType;
|
|
133
|
+
constructor(token: string, options?: ThreeuOptions, tokenType?: TokenType);
|
|
134
|
+
/**
|
|
135
|
+
* Return a brand-scoped client. Synchronous, but returns a value safe to
|
|
136
|
+
* `await` so both `threeu.brand(x)` and `await threeu.brand(x)` work.
|
|
137
|
+
*/
|
|
138
|
+
brand(brand: Id): BrandClient;
|
|
139
|
+
/** Flush telemetry and release timers. */
|
|
140
|
+
close(): Promise<void>;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export { BrandClient as B, Threeu as T, type ThreeuOptions as a };
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manifest type system.
|
|
3
|
+
*
|
|
4
|
+
* Two layers:
|
|
5
|
+
* - *Definition* types are what developers author (camelCase, ergonomic).
|
|
6
|
+
* - *Manifest* types are the normalized JSON contract the backend stores in
|
|
7
|
+
* `plugins.manifest` (snake_case — see docs/ARCHITECTURE_MAP.md §1/§4).
|
|
8
|
+
*
|
|
9
|
+
* `definePlugin` / `defineApp` / `defineTheme` validate a Definition and emit a
|
|
10
|
+
* Manifest. `provider_class` is INTERNAL to ThreeU and is never set by a
|
|
11
|
+
* community developer — they declare `provider.type` and the backend maps it.
|
|
12
|
+
*/
|
|
13
|
+
type PluginCategory = "payment" | "shipping" | "sales_channel" | "marketing" | "analytics" | "accounting" | "inventory" | "customer_service" | "ai" | "custom";
|
|
14
|
+
type SurfaceType = "plugin" | "page";
|
|
15
|
+
type TriggerMode = "manual" | "automatic";
|
|
16
|
+
type Ownership = "official" | "community" | "custom";
|
|
17
|
+
type ProviderType = "remote_http" | "native" | "iframe_app" | "theme_extension" | "webhook_only" | "manual_gateway";
|
|
18
|
+
type Permission = string;
|
|
19
|
+
type HttpVerb = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
20
|
+
type ConfigFieldType = "text" | "secret" | "number" | "boolean" | "select" | "url" | "email";
|
|
21
|
+
interface ConfigFieldDefinition {
|
|
22
|
+
type: ConfigFieldType;
|
|
23
|
+
label: string;
|
|
24
|
+
required?: boolean;
|
|
25
|
+
default?: unknown;
|
|
26
|
+
options?: string[];
|
|
27
|
+
placeholder?: string;
|
|
28
|
+
help?: string;
|
|
29
|
+
}
|
|
30
|
+
type ConfigSchema = Record<string, ConfigFieldDefinition>;
|
|
31
|
+
interface ActionDefinition {
|
|
32
|
+
method: HttpVerb;
|
|
33
|
+
path: string;
|
|
34
|
+
timeoutMs?: number;
|
|
35
|
+
}
|
|
36
|
+
interface WebhookDefinition {
|
|
37
|
+
events: string[];
|
|
38
|
+
}
|
|
39
|
+
interface RemoteHttpProviderDefinition {
|
|
40
|
+
type: "remote_http";
|
|
41
|
+
baseUrl: string;
|
|
42
|
+
healthPath?: string;
|
|
43
|
+
actions?: Record<string, ActionDefinition>;
|
|
44
|
+
webhooks?: WebhookDefinition;
|
|
45
|
+
}
|
|
46
|
+
interface SimpleProviderDefinition {
|
|
47
|
+
type: Exclude<ProviderType, "remote_http">;
|
|
48
|
+
baseUrl?: string;
|
|
49
|
+
healthPath?: string;
|
|
50
|
+
}
|
|
51
|
+
type ProviderDefinition = RemoteHttpProviderDefinition | SimpleProviderDefinition;
|
|
52
|
+
interface PluginDefinition {
|
|
53
|
+
name: string;
|
|
54
|
+
slug: string;
|
|
55
|
+
version?: string;
|
|
56
|
+
type?: "plugin";
|
|
57
|
+
category: PluginCategory;
|
|
58
|
+
surfaceType?: SurfaceType;
|
|
59
|
+
triggerMode?: TriggerMode;
|
|
60
|
+
ownership?: Ownership;
|
|
61
|
+
description?: string;
|
|
62
|
+
permissions?: Permission[];
|
|
63
|
+
settings?: ConfigSchema;
|
|
64
|
+
provider: ProviderDefinition;
|
|
65
|
+
subscribedActions?: string[];
|
|
66
|
+
adminBlocks?: Record<string, AdminBlock>;
|
|
67
|
+
}
|
|
68
|
+
interface AdminBlock {
|
|
69
|
+
component: string;
|
|
70
|
+
title?: string;
|
|
71
|
+
}
|
|
72
|
+
interface ExtensionPoint {
|
|
73
|
+
id: string;
|
|
74
|
+
surface: string;
|
|
75
|
+
component: string;
|
|
76
|
+
}
|
|
77
|
+
interface AppDefinition {
|
|
78
|
+
name: string;
|
|
79
|
+
slug: string;
|
|
80
|
+
version?: string;
|
|
81
|
+
surface: "admin" | "pos";
|
|
82
|
+
category?: PluginCategory;
|
|
83
|
+
permissions?: Permission[];
|
|
84
|
+
settings?: ConfigSchema;
|
|
85
|
+
blocks?: Record<string, AdminBlock>;
|
|
86
|
+
extensionPoints?: ExtensionPoint[];
|
|
87
|
+
provider?: ProviderDefinition;
|
|
88
|
+
}
|
|
89
|
+
type ThemeVisibility = "public" | "exclusive";
|
|
90
|
+
interface ThemeEditableField {
|
|
91
|
+
name: string;
|
|
92
|
+
kind: "text" | "image" | "color" | "section" | "link" | "heading" | "paragraph" | "span";
|
|
93
|
+
default?: unknown;
|
|
94
|
+
label?: string;
|
|
95
|
+
}
|
|
96
|
+
interface ThemeDefinition {
|
|
97
|
+
name: string;
|
|
98
|
+
slug: string;
|
|
99
|
+
version?: string;
|
|
100
|
+
visibility?: ThemeVisibility;
|
|
101
|
+
pages: string[];
|
|
102
|
+
fields?: ThemeEditableField[];
|
|
103
|
+
}
|
|
104
|
+
interface ActionManifest {
|
|
105
|
+
method: HttpVerb;
|
|
106
|
+
path: string;
|
|
107
|
+
timeout_ms?: number;
|
|
108
|
+
}
|
|
109
|
+
interface ProviderAuthManifest {
|
|
110
|
+
type: "hmac_sha256";
|
|
111
|
+
signature_header: string;
|
|
112
|
+
timestamp_header: string;
|
|
113
|
+
}
|
|
114
|
+
interface ProviderManifest {
|
|
115
|
+
type: ProviderType;
|
|
116
|
+
base_url?: string;
|
|
117
|
+
health_path?: string;
|
|
118
|
+
auth?: ProviderAuthManifest;
|
|
119
|
+
actions?: Record<string, ActionManifest>;
|
|
120
|
+
webhooks?: {
|
|
121
|
+
inbound_url_mode: "threeu_generated";
|
|
122
|
+
signature_header: string;
|
|
123
|
+
brand_header: string;
|
|
124
|
+
events?: string[];
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
interface PluginManifest {
|
|
128
|
+
type: "plugin";
|
|
129
|
+
runtime: ProviderType;
|
|
130
|
+
name: string;
|
|
131
|
+
slug: string;
|
|
132
|
+
version: string;
|
|
133
|
+
category: PluginCategory;
|
|
134
|
+
surface_type: SurfaceType;
|
|
135
|
+
trigger_mode: TriggerMode;
|
|
136
|
+
ownership: Ownership;
|
|
137
|
+
description?: string;
|
|
138
|
+
permissions: Permission[];
|
|
139
|
+
config_schema?: ConfigSchema;
|
|
140
|
+
subscribed_actions?: string[];
|
|
141
|
+
provider: ProviderManifest;
|
|
142
|
+
admin_blocks?: Record<string, AdminBlock>;
|
|
143
|
+
}
|
|
144
|
+
interface ThemeManifest {
|
|
145
|
+
type: "theme";
|
|
146
|
+
name: string;
|
|
147
|
+
slug: string;
|
|
148
|
+
version: string;
|
|
149
|
+
visibility: ThemeVisibility;
|
|
150
|
+
pages: string[];
|
|
151
|
+
editable_fields: ThemeEditableField[];
|
|
152
|
+
}
|
|
153
|
+
interface AdminAppManifest {
|
|
154
|
+
type: "admin_app";
|
|
155
|
+
name: string;
|
|
156
|
+
slug: string;
|
|
157
|
+
version: string;
|
|
158
|
+
permissions: Permission[];
|
|
159
|
+
config_schema?: ConfigSchema;
|
|
160
|
+
blocks?: Record<string, AdminBlock>;
|
|
161
|
+
extension_points?: ExtensionPoint[];
|
|
162
|
+
provider?: ProviderManifest;
|
|
163
|
+
}
|
|
164
|
+
interface POSAppManifest extends Omit<AdminAppManifest, "type"> {
|
|
165
|
+
type: "pos_app";
|
|
166
|
+
}
|
|
167
|
+
type RemoteHttpProviderManifest = ProviderManifest & {
|
|
168
|
+
type: "remote_http";
|
|
169
|
+
};
|
|
170
|
+
type PluginActionManifest = ActionManifest;
|
|
171
|
+
type PluginWebhookManifest = NonNullable<ProviderManifest["webhooks"]>;
|
|
172
|
+
|
|
173
|
+
export type { AppDefinition as A, ConfigFieldDefinition as C, ExtensionPoint as E, HttpVerb as H, Ownership as O, PluginManifest as P, RemoteHttpProviderDefinition as R, SimpleProviderDefinition as S, ThemeDefinition as T, WebhookDefinition as W, AdminAppManifest as a, POSAppManifest as b, PluginDefinition as c, ThemeManifest as d, ActionDefinition as e, ActionManifest as f, AdminBlock as g, ConfigFieldType as h, ConfigSchema as i, Permission as j, PluginActionManifest as k, PluginCategory as l, PluginWebhookManifest as m, ProviderAuthManifest as n, ProviderDefinition as o, ProviderManifest as p, ProviderType as q, RemoteHttpProviderManifest as r, SurfaceType as s, TriggerMode as t, ThemeVisibility as u, ThemeEditableField as v };
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pagination normalization. The backend wraps a Laravel paginator inside the
|
|
3
|
+
* `data` field: `{ success, data: { data:[...], current_page, per_page, total,
|
|
4
|
+
* last_page } }`; some endpoints return a flat array in `data`
|
|
5
|
+
* (docs/ARCHITECTURE_MAP.md §11). Both shapes normalize to a `Page<T>`.
|
|
6
|
+
*/
|
|
7
|
+
interface PageMeta {
|
|
8
|
+
page: number;
|
|
9
|
+
perPage: number;
|
|
10
|
+
total: number;
|
|
11
|
+
lastPage: number;
|
|
12
|
+
hasMore: boolean;
|
|
13
|
+
}
|
|
14
|
+
declare class Page<T> {
|
|
15
|
+
readonly items: T[];
|
|
16
|
+
readonly meta: PageMeta;
|
|
17
|
+
constructor(items: T[], meta: PageMeta);
|
|
18
|
+
get length(): number;
|
|
19
|
+
[Symbol.iterator](): Iterator<T>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Normalize a parsed response body into a `Page<T>`. Accepts the ThreeU
|
|
23
|
+
* `{ success, data }` envelope where `data` is either a paginator or a flat array.
|
|
24
|
+
*/
|
|
25
|
+
declare function normalizePage<T>(body: unknown): Page<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Async generator that walks every page by incrementing `page` until the last
|
|
28
|
+
* page is reached. `fetchPage` receives the 1-based page number.
|
|
29
|
+
*/
|
|
30
|
+
declare function iteratePages<T>(fetchPage: (page: number) => Promise<Page<T>>): AsyncGenerator<T, void, void>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Runtime detection + capability probes.
|
|
34
|
+
*
|
|
35
|
+
* The SDK behaves differently per runtime: it refuses to attach secret/admin
|
|
36
|
+
* tokens in a browser, picks Web Crypto vs node:crypto for webhook signing, and
|
|
37
|
+
* tags telemetry with the runtime name.
|
|
38
|
+
*/
|
|
39
|
+
type ThreeuRuntime = "browser" | "node" | "edge" | "unknown";
|
|
40
|
+
declare function detectRuntime(): ThreeuRuntime;
|
|
41
|
+
/** True in environments where exposing a secret token is a security risk. */
|
|
42
|
+
declare function isBrowserLike(runtime?: ThreeuRuntime): boolean;
|
|
43
|
+
/** True when running in development (used to gate dev-only safety warnings). */
|
|
44
|
+
declare function isDevelopment(): boolean;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Token classes the SDK understands. Each maps to a backend auth context and a
|
|
48
|
+
* set of safety rules (e.g. `secret_admin` must never run in a browser).
|
|
49
|
+
* See docs/ARCHITECTURE_MAP.md §9.
|
|
50
|
+
*/
|
|
51
|
+
type TokenType = "secret_admin" | "public_storefront" | "plugin_installation" | "pos" | "theme_dev" | "developer";
|
|
52
|
+
/** Token types that grant privileged/secret access and must stay server-side. */
|
|
53
|
+
declare const SECRET_TOKEN_TYPES: ReadonlySet<TokenType>;
|
|
54
|
+
interface ThreeuAppInfo {
|
|
55
|
+
name?: string;
|
|
56
|
+
version?: string;
|
|
57
|
+
}
|
|
58
|
+
interface ThreeuTelemetryOptions {
|
|
59
|
+
enabled?: boolean;
|
|
60
|
+
endpoint?: string;
|
|
61
|
+
sampleRate?: number;
|
|
62
|
+
flushIntervalMs?: number;
|
|
63
|
+
maxBatchSize?: number;
|
|
64
|
+
}
|
|
65
|
+
/** Options shared by every client (core, admin, pos, storefront, developer). */
|
|
66
|
+
interface ThreeuClientOptions {
|
|
67
|
+
baseUrl?: string;
|
|
68
|
+
token?: string;
|
|
69
|
+
tokenType?: TokenType;
|
|
70
|
+
/** Brand/tenant id sent as the `platform-id` header (and `X-Brand-ID` alias). */
|
|
71
|
+
brand?: string | number;
|
|
72
|
+
timeoutMs?: number;
|
|
73
|
+
retries?: number;
|
|
74
|
+
/** Custom fetch (e.g. undici, node-fetch, a mock). Defaults to global fetch. */
|
|
75
|
+
fetch?: typeof fetch;
|
|
76
|
+
logger?: ThreeuLogger;
|
|
77
|
+
telemetry?: ThreeuTelemetryOptions;
|
|
78
|
+
app?: ThreeuAppInfo;
|
|
79
|
+
/** Extra headers merged into every request (never overrides auth/brand). */
|
|
80
|
+
defaultHeaders?: Record<string, string>;
|
|
81
|
+
/** Opt out of the dev-only unsafe-usage warnings. */
|
|
82
|
+
suppressWarnings?: boolean;
|
|
83
|
+
}
|
|
84
|
+
/** Per-request overrides. */
|
|
85
|
+
interface RequestOptions {
|
|
86
|
+
query?: Record<string, unknown> | undefined;
|
|
87
|
+
body?: unknown;
|
|
88
|
+
headers?: Record<string, string>;
|
|
89
|
+
timeoutMs?: number;
|
|
90
|
+
retries?: number;
|
|
91
|
+
signal?: AbortSignal;
|
|
92
|
+
/** Idempotency key for safe retries of mutating requests. */
|
|
93
|
+
idempotencyKey?: string;
|
|
94
|
+
/** Mark the request idempotent so the client may auto-retry it. */
|
|
95
|
+
idempotent?: boolean;
|
|
96
|
+
/** Override the brand for this single request. */
|
|
97
|
+
brand?: string | number;
|
|
98
|
+
/** Raw multipart form data (skips JSON serialization). */
|
|
99
|
+
form?: FormData;
|
|
100
|
+
}
|
|
101
|
+
type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
102
|
+
/** A structured, safe-to-log SDK event. Never contains tokens/PII/raw bodies. */
|
|
103
|
+
interface ThreeuLogEvent {
|
|
104
|
+
type: ThreeuEventType;
|
|
105
|
+
requestId?: string;
|
|
106
|
+
method?: HttpMethod;
|
|
107
|
+
/** Path template with ids elided, e.g. `/plugins/:id/webhook`. */
|
|
108
|
+
pathTemplate?: string;
|
|
109
|
+
resource?: string;
|
|
110
|
+
action?: string;
|
|
111
|
+
statusCode?: number;
|
|
112
|
+
durationMs?: number;
|
|
113
|
+
retryCount?: number;
|
|
114
|
+
runtime?: ThreeuRuntime;
|
|
115
|
+
sdkVersion?: string;
|
|
116
|
+
appName?: string;
|
|
117
|
+
developerId?: string | number;
|
|
118
|
+
pluginId?: string | number;
|
|
119
|
+
brandId?: string | number;
|
|
120
|
+
errorCode?: string;
|
|
121
|
+
errorType?: string;
|
|
122
|
+
message?: string;
|
|
123
|
+
}
|
|
124
|
+
type ThreeuEventType = "request:start" | "request:success" | "request:error" | "request:retry" | "request:timeout" | "request:rate_limited" | "request:permission_denied" | "request:validation_failed";
|
|
125
|
+
interface ThreeuLogger {
|
|
126
|
+
debug?(event: ThreeuLogEvent): void;
|
|
127
|
+
info?(event: ThreeuLogEvent): void;
|
|
128
|
+
warn?(event: ThreeuLogEvent): void;
|
|
129
|
+
error?(event: ThreeuLogEvent): void;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Central fetch-based transport shared by every client. Owns timeouts, safe
|
|
134
|
+
* retries with backoff, idempotency keys, request-id propagation, query/JSON/
|
|
135
|
+
* multipart serialization, error normalization, and logger/telemetry emission.
|
|
136
|
+
*/
|
|
137
|
+
declare class ThreeuHttpClient {
|
|
138
|
+
readonly baseUrl: string;
|
|
139
|
+
private readonly token?;
|
|
140
|
+
private readonly tokenType?;
|
|
141
|
+
private readonly brand?;
|
|
142
|
+
private readonly timeoutMs;
|
|
143
|
+
private readonly retries;
|
|
144
|
+
private readonly fetchImpl;
|
|
145
|
+
private readonly logger?;
|
|
146
|
+
private readonly telemetry;
|
|
147
|
+
private readonly defaultHeaders;
|
|
148
|
+
private readonly appName?;
|
|
149
|
+
private readonly runtime;
|
|
150
|
+
constructor(options?: ThreeuClientOptions);
|
|
151
|
+
get(path: string, options?: RequestOptions): Promise<unknown>;
|
|
152
|
+
post(path: string, options?: RequestOptions): Promise<unknown>;
|
|
153
|
+
put(path: string, options?: RequestOptions): Promise<unknown>;
|
|
154
|
+
patch(path: string, options?: RequestOptions): Promise<unknown>;
|
|
155
|
+
delete(path: string, options?: RequestOptions): Promise<unknown>;
|
|
156
|
+
/** Fetch a single page and normalize it into a `Page<T>`. */
|
|
157
|
+
list<T>(path: string, options?: RequestOptions): Promise<Page<T>>;
|
|
158
|
+
/** Async-iterate every item across all pages. */
|
|
159
|
+
iterate<T>(path: string, options?: RequestOptions): AsyncGenerator<T, void, void>;
|
|
160
|
+
/** Flush and stop telemetry; call on shutdown. */
|
|
161
|
+
close(): Promise<void>;
|
|
162
|
+
request(method: HttpMethod, path: string, options?: RequestOptions): Promise<unknown>;
|
|
163
|
+
private send;
|
|
164
|
+
private buildHeaders;
|
|
165
|
+
private buildUrl;
|
|
166
|
+
private normalizeThrown;
|
|
167
|
+
private emit;
|
|
168
|
+
private emitError;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Domain types. Deliberately permissive — the backend has no single typed
|
|
173
|
+
* contract and serializes decimals as strings (docs/ARCHITECTURE_MAP.md §14), so
|
|
174
|
+
* these model the common shape and allow extra fields via index signatures.
|
|
175
|
+
*/
|
|
176
|
+
type Id = string | number;
|
|
177
|
+
interface BaseRecord {
|
|
178
|
+
id: Id;
|
|
179
|
+
[key: string]: unknown;
|
|
180
|
+
}
|
|
181
|
+
interface Money {
|
|
182
|
+
amount: number;
|
|
183
|
+
currency: string;
|
|
184
|
+
}
|
|
185
|
+
interface Product extends BaseRecord {
|
|
186
|
+
name?: string;
|
|
187
|
+
price?: number | string;
|
|
188
|
+
currency?: string;
|
|
189
|
+
stock?: number;
|
|
190
|
+
status?: string;
|
|
191
|
+
}
|
|
192
|
+
interface ProductInput {
|
|
193
|
+
name: string;
|
|
194
|
+
price: number;
|
|
195
|
+
currency?: string;
|
|
196
|
+
stock?: number;
|
|
197
|
+
description?: string;
|
|
198
|
+
[key: string]: unknown;
|
|
199
|
+
}
|
|
200
|
+
interface Order extends BaseRecord {
|
|
201
|
+
status?: string;
|
|
202
|
+
total?: number | string;
|
|
203
|
+
currency?: string;
|
|
204
|
+
customer_id?: Id;
|
|
205
|
+
}
|
|
206
|
+
interface Customer extends BaseRecord {
|
|
207
|
+
name?: string;
|
|
208
|
+
email?: string;
|
|
209
|
+
phone?: string;
|
|
210
|
+
}
|
|
211
|
+
interface Collection extends BaseRecord {
|
|
212
|
+
title?: string;
|
|
213
|
+
handle?: string;
|
|
214
|
+
}
|
|
215
|
+
interface Discount extends BaseRecord {
|
|
216
|
+
code?: string;
|
|
217
|
+
type?: "percentage" | "fixed";
|
|
218
|
+
value?: number;
|
|
219
|
+
}
|
|
220
|
+
interface InventoryItem extends BaseRecord {
|
|
221
|
+
product_id?: Id;
|
|
222
|
+
location_id?: Id;
|
|
223
|
+
quantity?: number;
|
|
224
|
+
}
|
|
225
|
+
interface Location extends BaseRecord {
|
|
226
|
+
name?: string;
|
|
227
|
+
address?: string;
|
|
228
|
+
}
|
|
229
|
+
interface Payment extends BaseRecord {
|
|
230
|
+
status?: string;
|
|
231
|
+
amount?: number | string;
|
|
232
|
+
currency?: string;
|
|
233
|
+
}
|
|
234
|
+
interface ShippingRate {
|
|
235
|
+
service: string;
|
|
236
|
+
price: number;
|
|
237
|
+
currency: string;
|
|
238
|
+
estimatedDays?: number;
|
|
239
|
+
}
|
|
240
|
+
interface ListParams {
|
|
241
|
+
page?: number;
|
|
242
|
+
per_page?: number;
|
|
243
|
+
search?: string;
|
|
244
|
+
status?: string;
|
|
245
|
+
[key: string]: unknown;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export { type BaseRecord as B, type Collection as C, type Discount as D, type HttpMethod as H, type Id as I, type ListParams as L, type Money as M, type Order as O, type Payment as P, type RequestOptions as R, type ShippingRate as S, ThreeuHttpClient as T, type Customer as a, type InventoryItem as b, type Location as c, type Product as d, type ProductInput as e, Page as f, type ThreeuLogger as g, type ThreeuTelemetryOptions as h, type ThreeuClientOptions as i, type TokenType as j, type ThreeuLogEvent as k, type PageMeta as l, SECRET_TOKEN_TYPES as m, type ThreeuAppInfo as n, type ThreeuEventType as o, type ThreeuRuntime as p, detectRuntime as q, isBrowserLike as r, isDevelopment as s, iteratePages as t, normalizePage as u };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Constant-time string comparison to avoid timing leaks. */
|
|
2
|
+
declare function timingSafeEqual(a: string, b: string): boolean;
|
|
3
|
+
interface SignWebhookParams {
|
|
4
|
+
secret: string;
|
|
5
|
+
rawBody: string;
|
|
6
|
+
/** Unix seconds. Defaults to now. */
|
|
7
|
+
timestamp?: number;
|
|
8
|
+
}
|
|
9
|
+
interface SignedWebhook {
|
|
10
|
+
signature: string;
|
|
11
|
+
timestamp: number;
|
|
12
|
+
}
|
|
13
|
+
/** Sign a raw body with the target scheme. Returns the `sha256=` header value. */
|
|
14
|
+
declare function signWebhookPayload(params: SignWebhookParams): Promise<SignedWebhook>;
|
|
15
|
+
interface VerifyWebhookParams {
|
|
16
|
+
secret: string;
|
|
17
|
+
rawBody: string;
|
|
18
|
+
timestamp: number | string;
|
|
19
|
+
signature: string;
|
|
20
|
+
/** Reject timestamps older/newer than this many seconds. Default 300. */
|
|
21
|
+
toleranceSeconds?: number;
|
|
22
|
+
/** Override "now" (unix seconds) — useful in tests. */
|
|
23
|
+
now?: number;
|
|
24
|
+
}
|
|
25
|
+
/** Verify a raw-body signature with replay-window enforcement. Boolean result. */
|
|
26
|
+
declare function verifyWebhookSignature(params: VerifyWebhookParams): Promise<boolean>;
|
|
27
|
+
/** Like `verifyWebhookSignature` but throws `ThreeuWebhookSignatureError` on failure. */
|
|
28
|
+
declare function assertWebhookSignature(params: VerifyWebhookParams): Promise<void>;
|
|
29
|
+
/** Extract the hex digest from a `sha256=<hex>` header (or pass-through bare hex). */
|
|
30
|
+
declare function parseWebhookSignatureHeader(header: string): string;
|
|
31
|
+
/** Sign the legacy way: HMAC over the JSON-encoded payload, no timestamp. */
|
|
32
|
+
declare function signLegacyWebhook(secret: string, payload: unknown): Promise<string>;
|
|
33
|
+
/** Verify a legacy signature (no timestamp / replay window). */
|
|
34
|
+
declare function verifyLegacyWebhook(secret: string, payload: unknown, signature: string): Promise<boolean>;
|
|
35
|
+
|
|
36
|
+
export { type SignWebhookParams, type SignedWebhook, type VerifyWebhookParams, assertWebhookSignature, parseWebhookSignatureHeader, signLegacyWebhook, signWebhookPayload, timingSafeEqual, verifyLegacyWebhook, verifyWebhookSignature };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { assertWebhookSignature, parseWebhookSignatureHeader, signLegacyWebhook, signWebhookPayload, timingSafeEqual, verifyLegacyWebhook, verifyWebhookSignature } from '../chunk-ZWLFJIAM.js';
|
|
2
|
+
import '../chunk-LFF5LPWT.js';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|