@merchi/product-form-sdk 1.0.9
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 +177 -0
- package/dist/components/Field.d.ts +7 -0
- package/dist/components/Field.js +353 -0
- package/dist/components/ProductFormActions.d.ts +11 -0
- package/dist/components/ProductFormActions.js +20 -0
- package/dist/components/context.d.ts +85 -0
- package/dist/components/context.js +198 -0
- package/dist/components/footerActions.d.ts +18 -0
- package/dist/components/footerActions.js +67 -0
- package/dist/components/groups.d.ts +25 -0
- package/dist/components/groups.js +204 -0
- package/dist/components/index.d.ts +8 -0
- package/dist/components/index.js +7 -0
- package/dist/components/layout.d.ts +43 -0
- package/dist/components/layout.js +69 -0
- package/dist/components/shell.d.ts +15 -0
- package/dist/components/shell.js +100 -0
- package/dist/helpers/area.d.ts +90 -0
- package/dist/helpers/area.js +287 -0
- package/dist/helpers/buildJob.d.ts +29 -0
- package/dist/helpers/buildJob.js +190 -0
- package/dist/helpers/constants.d.ts +8 -0
- package/dist/helpers/constants.js +8 -0
- package/dist/helpers/format.d.ts +4 -0
- package/dist/helpers/format.js +18 -0
- package/dist/helpers/gridQuote.d.ts +10 -0
- package/dist/helpers/gridQuote.js +32 -0
- package/dist/helpers/product.d.ts +7 -0
- package/dist/helpers/product.js +27 -0
- package/dist/helpers/serialize.d.ts +9 -0
- package/dist/helpers/serialize.js +35 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +11 -0
- package/dist/runtime/clientPricing.d.ts +31 -0
- package/dist/runtime/clientPricing.js +70 -0
- package/dist/runtime/pricing.d.ts +29 -0
- package/dist/runtime/pricing.js +70 -0
- package/dist/runtime/runtime.d.ts +36 -0
- package/dist/runtime/runtime.js +32 -0
- package/dist/types/form.d.ts +26 -0
- package/dist/types/form.js +1 -0
- package/dist/types/job.d.ts +26 -0
- package/dist/types/job.js +1 -0
- package/dist/types/product.d.ts +30 -0
- package/dist/types/product.js +1 -0
- package/dist/types/variation.d.ts +46 -0
- package/dist/types/variation.js +1 -0
- package/dist/version.d.ts +4 -0
- package/dist/version.js +6 -0
- package/package.json +49 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
import { ProductJson } from './product';
|
|
3
|
+
import { JobJson } from './job';
|
|
4
|
+
import { Pricing } from '../runtime/pricing';
|
|
5
|
+
import { Actions, Helpers } from '../runtime/runtime';
|
|
6
|
+
import type { FooterAction } from '../components/footerActions';
|
|
7
|
+
/** Props every custom product form receives. This is the ONLY surface a form
|
|
8
|
+
* may rely on; the static-analysis gate (Plan 3) rejects anything else. */
|
|
9
|
+
export interface ProductFormProps {
|
|
10
|
+
/** The product being ordered. */
|
|
11
|
+
product: ProductJson;
|
|
12
|
+
/** Request a quote for an arbitrary job (for live pricing as the user edits). */
|
|
13
|
+
pricing: Pricing;
|
|
14
|
+
/** Submit the order. The form builds + serializes the job, then calls one of
|
|
15
|
+
* these. Actions not enabled for the product/embed are undefined. */
|
|
16
|
+
actions: Actions;
|
|
17
|
+
/** Stateless helpers: serialize a job, filter qty>0 groups, format currency,
|
|
18
|
+
* build merchi urls. */
|
|
19
|
+
helpers: Helpers;
|
|
20
|
+
}
|
|
21
|
+
/** A custom product form is a default-exported React component of this type. */
|
|
22
|
+
export type ProductFormComponent = ComponentType<ProductFormProps> & {
|
|
23
|
+
/** Optional host-footer config (Get quote / Buy now / Add to cart). */
|
|
24
|
+
footerActions?: FooterAction[];
|
|
25
|
+
};
|
|
26
|
+
export type { JobJson, ProductJson };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { VariationJson, VariationsGroupJson } from './variation';
|
|
2
|
+
/** Pricing fields populated on a job by a quote (server or client-side). */
|
|
3
|
+
export interface QuoteFields {
|
|
4
|
+
cost?: number;
|
|
5
|
+
costPerUnit?: number;
|
|
6
|
+
taxAmount?: number;
|
|
7
|
+
totalCost?: number;
|
|
8
|
+
currency?: string;
|
|
9
|
+
}
|
|
10
|
+
/** The job (order) a form builds, serializes, and submits. Mirrors the JSON
|
|
11
|
+
* wire format used by @merchi/product-form: top-level variations for
|
|
12
|
+
* whole-order fields, variationsGroups for grouped line items. */
|
|
13
|
+
export interface JobJson extends QuoteFields {
|
|
14
|
+
quantity?: number;
|
|
15
|
+
variations?: VariationJson[];
|
|
16
|
+
variationsGroups?: VariationsGroupJson[];
|
|
17
|
+
product?: {
|
|
18
|
+
id?: number;
|
|
19
|
+
};
|
|
20
|
+
client?: {
|
|
21
|
+
id?: number;
|
|
22
|
+
};
|
|
23
|
+
tags?: Array<{
|
|
24
|
+
id: number;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { VariationFieldJson } from './variation';
|
|
2
|
+
/** The product JSON a custom form receives. Fields are optional because the
|
|
3
|
+
* shape varies by product type; the commonly-used fields are documented here. */
|
|
4
|
+
export interface ProductJson {
|
|
5
|
+
id?: number;
|
|
6
|
+
name?: string;
|
|
7
|
+
productType?: number;
|
|
8
|
+
currency?: string;
|
|
9
|
+
unitPrice?: number;
|
|
10
|
+
bestPrice?: number;
|
|
11
|
+
minimum?: number;
|
|
12
|
+
minOrderQuantity?: number;
|
|
13
|
+
groupsFirst?: boolean;
|
|
14
|
+
needsInventory?: boolean;
|
|
15
|
+
allowAddToCart?: boolean;
|
|
16
|
+
allowPaymentUpfront?: boolean;
|
|
17
|
+
allowQuotation?: boolean;
|
|
18
|
+
clientSideCalculation?: boolean;
|
|
19
|
+
defaultJob?: Record<string, unknown>;
|
|
20
|
+
independentVariationFields?: VariationFieldJson[];
|
|
21
|
+
groupVariationFields?: VariationFieldJson[];
|
|
22
|
+
images?: Array<{
|
|
23
|
+
id?: string;
|
|
24
|
+
viewUrl?: string;
|
|
25
|
+
}>;
|
|
26
|
+
domain?: {
|
|
27
|
+
id?: number;
|
|
28
|
+
domain?: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** A selectable option within a variation field (e.g. a colour swatch). */
|
|
2
|
+
export interface OptionJson {
|
|
3
|
+
id?: number;
|
|
4
|
+
value?: string;
|
|
5
|
+
colour?: string;
|
|
6
|
+
isExtracted?: boolean;
|
|
7
|
+
isVisible?: boolean;
|
|
8
|
+
available?: boolean;
|
|
9
|
+
linkedFile?: {
|
|
10
|
+
id?: string;
|
|
11
|
+
viewUrl?: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/** A single variation field definition on a product. */
|
|
15
|
+
export interface VariationFieldJson {
|
|
16
|
+
id?: number;
|
|
17
|
+
name?: string;
|
|
18
|
+
fieldType?: number;
|
|
19
|
+
required?: boolean;
|
|
20
|
+
currency?: string;
|
|
21
|
+
options?: OptionJson[];
|
|
22
|
+
maxColours?: number;
|
|
23
|
+
simplifyColours?: boolean;
|
|
24
|
+
colourVariationCost?: number;
|
|
25
|
+
colourVariationUnitCost?: number;
|
|
26
|
+
}
|
|
27
|
+
/** A variation selection within a job (one chosen field value). */
|
|
28
|
+
export interface VariationJson {
|
|
29
|
+
id?: number;
|
|
30
|
+
variationField?: number | VariationFieldJson;
|
|
31
|
+
value?: string | number | null;
|
|
32
|
+
selectedOptions?: OptionJson[];
|
|
33
|
+
variationFiles?: Array<{
|
|
34
|
+
id?: string;
|
|
35
|
+
}>;
|
|
36
|
+
isVisible?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** A grouped line item: a set of variations with its own quantity. */
|
|
39
|
+
export interface VariationsGroupJson {
|
|
40
|
+
id?: number;
|
|
41
|
+
quantity?: number;
|
|
42
|
+
groupCost?: number | null;
|
|
43
|
+
variations?: VariationJson[];
|
|
44
|
+
inventoryCount?: number;
|
|
45
|
+
inventorySufficient?: boolean;
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Auto-synced from package.json — do not edit; run `npm run build`. */
|
|
2
|
+
export function getProductFormSdkVersion() {
|
|
3
|
+
return '1.0.9';
|
|
4
|
+
}
|
|
5
|
+
/** @deprecated Prefer getProductFormSdkVersion(); kept for gate/export compatibility. */
|
|
6
|
+
export const SDK_VERSION = getProductFormSdkVersion();
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@merchi/product-form-sdk",
|
|
3
|
+
"version": "1.0.9",
|
|
4
|
+
"description": "Contract SDK for AI-built Merchi custom product forms.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/merchisdk/merchi_ts.git",
|
|
8
|
+
"directory": "packages/product-form-sdk"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"author": "James Campton <james@merchi.co>",
|
|
14
|
+
"license": "GPL-3.0",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"module": "dist/index.js",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"prebuild": "node scripts/sync-version.mjs",
|
|
24
|
+
"build": "tsc",
|
|
25
|
+
"test": "jest",
|
|
26
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
27
|
+
"prepublishOnly": "node scripts/sync-version.mjs && npm run build && npm test"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@merchi/sdk": "^1.40.2"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/jest": "^29.0.0",
|
|
37
|
+
"@types/node": "^20.0.0",
|
|
38
|
+
"@types/react": "^19.0.0",
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
40
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
41
|
+
"eslint": "^8.47.0",
|
|
42
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
43
|
+
"jest": "^29.0.0",
|
|
44
|
+
"jest-environment-jsdom": "^29.0.0",
|
|
45
|
+
"react": "^19.0.0",
|
|
46
|
+
"ts-jest": "^29.0.0",
|
|
47
|
+
"typescript": "^5.1.6"
|
|
48
|
+
}
|
|
49
|
+
}
|