@kanorio/sdk 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +66 -2
- package/dist/customer-oauth.d.ts +86 -0
- package/dist/customer-oauth.js +112 -0
- package/dist/customer.d.ts +176 -0
- package/dist/customer.js +116 -0
- package/dist/delivery.d.ts +35 -0
- package/dist/delivery.js +49 -0
- package/dist/edge.d.ts +104 -0
- package/dist/edge.js +287 -0
- package/dist/forms.d.ts +123 -0
- package/dist/forms.js +130 -0
- package/dist/generated/customer.d.ts +3157 -0
- package/dist/generated/delivery.d.ts +2380 -0
- package/dist/generated/management.d.ts +38248 -0
- package/dist/http.d.ts +73 -0
- package/dist/http.js +162 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +17 -0
- package/dist/locales.d.ts +80 -0
- package/dist/locales.js +81 -0
- package/dist/management.d.ts +19 -0
- package/dist/management.js +22 -0
- package/dist/paginate.d.ts +18 -0
- package/dist/paginate.js +27 -0
- package/dist/preview.d.ts +40 -0
- package/dist/preview.js +131 -0
- package/dist/protection.d.ts +74 -0
- package/dist/protection.js +68 -0
- package/dist/revalidate.d.ts +84 -0
- package/dist/revalidate.js +143 -0
- package/dist/seo.d.ts +120 -0
- package/dist/seo.js +125 -0
- package/dist/server-key.d.ts +71 -0
- package/dist/server-key.js +103 -0
- package/dist/shared/api/delivery/cache-tags.d.ts +142 -0
- package/dist/shared/api/delivery/cache-tags.js +212 -0
- package/dist/shared/api/server-key.d.ts +86 -0
- package/dist/shared/api/server-key.js +252 -0
- package/dist/shared/business-registry/attribution.d.ts +14 -0
- package/dist/shared/business-registry/attribution.js +28 -0
- package/dist/shared/business-registry/define.d.ts +3 -0
- package/dist/shared/business-registry/define.js +4 -0
- package/dist/shared/business-registry/formats/eu-vat.d.ts +2 -0
- package/dist/shared/business-registry/formats/eu-vat.js +54 -0
- package/dist/shared/business-registry/formats/hk-br.d.ts +5 -0
- package/dist/shared/business-registry/formats/hk-br.js +23 -0
- package/dist/shared/business-registry/formats/jp-trn.d.ts +6 -0
- package/dist/shared/business-registry/formats/jp-trn.js +23 -0
- package/dist/shared/business-registry/formats/kr-brn.d.ts +6 -0
- package/dist/shared/business-registry/formats/kr-brn.js +30 -0
- package/dist/shared/business-registry/formats/my.d.ts +7 -0
- package/dist/shared/business-registry/formats/my.js +32 -0
- package/dist/shared/business-registry/formats/sg-uen.d.ts +1 -0
- package/dist/shared/business-registry/formats/sg-uen.js +21 -0
- package/dist/shared/business-registry/formats/tw-vat.d.ts +10 -0
- package/dist/shared/business-registry/formats/tw-vat.js +32 -0
- package/dist/shared/business-registry/index.d.ts +9 -0
- package/dist/shared/business-registry/index.js +10 -0
- package/dist/shared/business-registry/lookup-wire.d.ts +33 -0
- package/dist/shared/business-registry/lookup-wire.js +8 -0
- package/dist/shared/business-registry/normalize.d.ts +7 -0
- package/dist/shared/business-registry/normalize.js +12 -0
- package/dist/shared/business-registry/registry.d.ts +26 -0
- package/dist/shared/business-registry/registry.js +67 -0
- package/dist/shared/business-registry/types.d.ts +60 -0
- package/dist/shared/business-registry/types.js +10 -0
- package/dist/shared/localization/locale-path.d.ts +38 -0
- package/dist/shared/localization/locale-path.js +76 -0
- package/dist/shared/localization/request-locale.d.ts +42 -0
- package/dist/shared/localization/request-locale.js +61 -0
- package/dist/shared/seo/alternates.d.ts +61 -0
- package/dist/shared/seo/alternates.js +71 -0
- package/dist/shared/types/forms-logic.d.ts +96 -0
- package/dist/shared/types/forms-logic.js +209 -0
- package/dist/shared/types/number-input.d.ts +5 -0
- package/dist/shared/types/number-input.js +16 -0
- package/dist/shared/utils/redirect-matching.d.ts +67 -0
- package/dist/shared/utils/redirect-matching.js +148 -0
- package/dist/tax-id.d.ts +7 -0
- package/dist/tax-id.js +6 -0
- package/dist/typed.d.ts +85 -0
- package/dist/typed.js +28 -0
- package/package.json +86 -3
package/dist/typed.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 以 openapi-typescript 產生的 `paths` 介面推導型別的最小客戶端:
|
|
3
|
+
* `client.get("/sites/{siteId}", { params: { siteId }, query })` 會檢查路徑、路徑參數、查詢、body 與成功回應型別。
|
|
4
|
+
* 不做執行期驗證;伺服端怎麼回就怎麼給。
|
|
5
|
+
*/
|
|
6
|
+
function fillPath(template, params) {
|
|
7
|
+
return template.replace(/\{([^}]+)\}/g, (_, name) => {
|
|
8
|
+
const value = params?.[name];
|
|
9
|
+
if (value === undefined || value === null)
|
|
10
|
+
throw new Error(`@kanorio/sdk: missing path parameter "${name}" for ${template}`);
|
|
11
|
+
return encodeURIComponent(String(value));
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export function createTypedClient(http) {
|
|
15
|
+
const call = (method) => (path, req) => {
|
|
16
|
+
const r = (req ?? {});
|
|
17
|
+
const options = { query: r.query, body: r.body, headers: r.headers, signal: r.signal };
|
|
18
|
+
return http.request(method, fillPath(path, r.params), options);
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
get: call("GET"),
|
|
22
|
+
post: call("POST"),
|
|
23
|
+
put: call("PUT"),
|
|
24
|
+
patch: call("PATCH"),
|
|
25
|
+
delete: call("DELETE"),
|
|
26
|
+
http,
|
|
27
|
+
};
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,89 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanorio/sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Typed fetch clients and headless helpers (SEO rewrites, JSON-LD, webhook revalidateTag) for the Kanorio Management API, Content Delivery API and Customer API.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"private": false,
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://kanorio.com/en/developers/sdk",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"email": "support@kanorio.com"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"kanorio",
|
|
16
|
+
"sdk",
|
|
17
|
+
"headless",
|
|
18
|
+
"cms",
|
|
19
|
+
"commerce",
|
|
20
|
+
"api-client"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/Kanorio-Inc/kanorio.git",
|
|
25
|
+
"directory": "packages/sdk"
|
|
26
|
+
},
|
|
27
|
+
"type": "module",
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"import": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./management": {
|
|
36
|
+
"types": "./dist/management.d.ts",
|
|
37
|
+
"import": "./dist/management.js"
|
|
38
|
+
},
|
|
39
|
+
"./delivery": {
|
|
40
|
+
"types": "./dist/delivery.d.ts",
|
|
41
|
+
"import": "./dist/delivery.js"
|
|
42
|
+
},
|
|
43
|
+
"./customer": {
|
|
44
|
+
"types": "./dist/customer.d.ts",
|
|
45
|
+
"import": "./dist/customer.js"
|
|
46
|
+
},
|
|
47
|
+
"./customer-oauth": {
|
|
48
|
+
"types": "./dist/customer-oauth.d.ts",
|
|
49
|
+
"import": "./dist/customer-oauth.js"
|
|
50
|
+
},
|
|
51
|
+
"./edge": {
|
|
52
|
+
"types": "./dist/edge.d.ts",
|
|
53
|
+
"import": "./dist/edge.js"
|
|
54
|
+
},
|
|
55
|
+
"./forms": {
|
|
56
|
+
"types": "./dist/forms.d.ts",
|
|
57
|
+
"import": "./dist/forms.js"
|
|
58
|
+
},
|
|
59
|
+
"./tax-id": {
|
|
60
|
+
"types": "./dist/tax-id.d.ts",
|
|
61
|
+
"import": "./dist/tax-id.js"
|
|
62
|
+
},
|
|
63
|
+
"./preview": {
|
|
64
|
+
"types": "./dist/preview.d.ts",
|
|
65
|
+
"import": "./dist/preview.js"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"files": [
|
|
69
|
+
"dist",
|
|
70
|
+
"README.md",
|
|
71
|
+
"LICENSE"
|
|
72
|
+
],
|
|
73
|
+
"engines": {
|
|
74
|
+
"node": ">=20"
|
|
75
|
+
},
|
|
76
|
+
"devDependencies": {
|
|
77
|
+
"@types/node": "^20",
|
|
78
|
+
"openapi-typescript": "^7.6.1",
|
|
79
|
+
"typescript": "^5",
|
|
80
|
+
"vitest": "^4.1.11"
|
|
81
|
+
},
|
|
82
|
+
"scripts": {
|
|
83
|
+
"gen": "openapi-typescript ../shared/openapi/management.json -o src/generated/management.d.ts && openapi-typescript ../shared/openapi/delivery.json -o src/generated/delivery.d.ts && openapi-typescript ../shared/openapi/customer.json -o src/generated/customer.d.ts && node scripts/copy-shared.mjs",
|
|
84
|
+
"build": "tsc -p tsconfig.build.json && mkdir -p dist/generated && cp src/generated/*.d.ts dist/generated/",
|
|
85
|
+
"typecheck": "tsc --noEmit",
|
|
86
|
+
"test": "vitest run",
|
|
87
|
+
"lint": "echo \"@kanorio/sdk: no eslint config yet\""
|
|
88
|
+
}
|
|
6
89
|
}
|