@porulle/adapter-tax-manual 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 +32 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/package.json +49 -0
- package/src/index.ts +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @porulle/adapter-tax-manual
|
|
2
|
+
|
|
3
|
+
`TaxAdapter` that applies a single flat rate. For stores that need basic tax math without a third-party service.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { defineConfig } from "@porulle/core";
|
|
9
|
+
import { manualTaxAdapter } from "@porulle/adapter-tax-manual";
|
|
10
|
+
|
|
11
|
+
export default defineConfig({
|
|
12
|
+
tax: {
|
|
13
|
+
adapter: manualTaxAdapter({
|
|
14
|
+
rate: 0.08, // 8% flat
|
|
15
|
+
shippingTaxable: true, // default: true
|
|
16
|
+
}),
|
|
17
|
+
},
|
|
18
|
+
// …
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## What it does
|
|
23
|
+
|
|
24
|
+
`calculateTax` applies the rate to the line-item subtotal (post-discount) plus shipping if `shippingTaxable` is true. `reportTransaction` and `voidTransaction` are no-ops — there's nothing to file.
|
|
25
|
+
|
|
26
|
+
## When to use this
|
|
27
|
+
|
|
28
|
+
- Single-jurisdiction stores
|
|
29
|
+
- Local development / tests
|
|
30
|
+
- Markets where you handle filing manually outside the framework
|
|
31
|
+
|
|
32
|
+
For multi-jurisdiction tax calculation and automated filing, use `@porulle/adapter-taxjar` (or build a new adapter for your jurisdiction's preferred service).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type TaxAdapter } from "@porulle/core";
|
|
2
|
+
export interface ManualTaxAdapterOptions {
|
|
3
|
+
rate: number;
|
|
4
|
+
shippingTaxable?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function manualTaxAdapter(options: ManualTaxAdapterOptions): TaxAdapter;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,KAAK,UAAU,EAA6B,MAAM,eAAe,CAAC;AAE/E,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAUD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,UAAU,CAqB7E"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Ok } from "@porulle/core";
|
|
2
|
+
function taxableSubtotal(params, shippingTaxable) {
|
|
3
|
+
const lineTaxable = params.lineItems.reduce((sum, lineItem) => sum + lineItem.unitPrice * lineItem.quantity - (lineItem.discount ?? 0), 0);
|
|
4
|
+
return lineTaxable + (shippingTaxable ? params.shippingAmount : 0);
|
|
5
|
+
}
|
|
6
|
+
export function manualTaxAdapter(options) {
|
|
7
|
+
const rate = Math.max(0, options.rate);
|
|
8
|
+
return {
|
|
9
|
+
providerId: "tax-manual",
|
|
10
|
+
async calculateTax(params) {
|
|
11
|
+
const taxableAmount = taxableSubtotal(params, options.shippingTaxable ?? true);
|
|
12
|
+
const amountToCollect = Math.round(taxableAmount * rate);
|
|
13
|
+
return Ok({
|
|
14
|
+
amountToCollect,
|
|
15
|
+
taxableAmount,
|
|
16
|
+
rate,
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
async reportTransaction(params) {
|
|
20
|
+
return Ok({ transactionId: params.transactionId });
|
|
21
|
+
},
|
|
22
|
+
async voidTransaction(params) {
|
|
23
|
+
return Ok({ transactionId: params.transactionId });
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@porulle/adapter-tax-manual",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"bun": "./src/index.ts",
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"types": "./src/index.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "rm -rf dist tsconfig.build.tsbuildinfo && tsc -p tsconfig.build.json",
|
|
15
|
+
"check-types": "tsc --noEmit",
|
|
16
|
+
"lint": "eslint . --max-warnings 1000",
|
|
17
|
+
"test": "vitest run"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@porulle/core": "workspace:*"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@repo/eslint-config": "*",
|
|
24
|
+
"@repo/typescript-config": "*",
|
|
25
|
+
"@types/node": "^24.5.2",
|
|
26
|
+
"eslint": "^9.39.1",
|
|
27
|
+
"typescript": "5.9.2",
|
|
28
|
+
"vitest": "^3.2.4"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"src",
|
|
35
|
+
"dist",
|
|
36
|
+
"README.md"
|
|
37
|
+
],
|
|
38
|
+
"description": "TaxAdapter that applies a single flat rate. For stores that need basic tax math without a third-party service.",
|
|
39
|
+
"homepage": "https://porulle-docs.vercel.app",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/asyncdotengineering/porulle/issues"
|
|
42
|
+
},
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/asyncdotengineering/porulle.git",
|
|
46
|
+
"directory": "packages/adapters/adapter-tax-manual"
|
|
47
|
+
},
|
|
48
|
+
"author": "Porulle contributors"
|
|
49
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Ok, type TaxAdapter, type TaxCalculationParams } from "@porulle/core";
|
|
2
|
+
|
|
3
|
+
export interface ManualTaxAdapterOptions {
|
|
4
|
+
rate: number;
|
|
5
|
+
shippingTaxable?: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function taxableSubtotal(params: TaxCalculationParams, shippingTaxable: boolean): number {
|
|
9
|
+
const lineTaxable = params.lineItems.reduce(
|
|
10
|
+
(sum, lineItem) => sum + lineItem.unitPrice * lineItem.quantity - (lineItem.discount ?? 0),
|
|
11
|
+
0,
|
|
12
|
+
);
|
|
13
|
+
return lineTaxable + (shippingTaxable ? params.shippingAmount : 0);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function manualTaxAdapter(options: ManualTaxAdapterOptions): TaxAdapter {
|
|
17
|
+
const rate = Math.max(0, options.rate);
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
providerId: "tax-manual",
|
|
21
|
+
async calculateTax(params) {
|
|
22
|
+
const taxableAmount = taxableSubtotal(params, options.shippingTaxable ?? true);
|
|
23
|
+
const amountToCollect = Math.round(taxableAmount * rate);
|
|
24
|
+
return Ok({
|
|
25
|
+
amountToCollect,
|
|
26
|
+
taxableAmount,
|
|
27
|
+
rate,
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
async reportTransaction(params) {
|
|
31
|
+
return Ok({ transactionId: params.transactionId });
|
|
32
|
+
},
|
|
33
|
+
async voidTransaction(params) {
|
|
34
|
+
return Ok({ transactionId: params.transactionId });
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|