@kanorio/sdk 0.0.0-stage → 1.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.
Files changed (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +66 -2
  3. package/dist/customer-oauth.d.ts +86 -0
  4. package/dist/customer-oauth.js +112 -0
  5. package/dist/customer.d.ts +176 -0
  6. package/dist/customer.js +125 -0
  7. package/dist/delivery.d.ts +35 -0
  8. package/dist/delivery.js +49 -0
  9. package/dist/edge.d.ts +108 -0
  10. package/dist/edge.js +287 -0
  11. package/dist/forms.d.ts +123 -0
  12. package/dist/forms.js +130 -0
  13. package/dist/generated/customer.d.ts +3157 -0
  14. package/dist/generated/delivery.d.ts +2408 -0
  15. package/dist/generated/management.d.ts +38333 -0
  16. package/dist/http.d.ts +73 -0
  17. package/dist/http.js +162 -0
  18. package/dist/index.d.ts +16 -0
  19. package/dist/index.js +17 -0
  20. package/dist/locales.d.ts +80 -0
  21. package/dist/locales.js +81 -0
  22. package/dist/management.d.ts +19 -0
  23. package/dist/management.js +22 -0
  24. package/dist/paginate.d.ts +18 -0
  25. package/dist/paginate.js +27 -0
  26. package/dist/preview.d.ts +40 -0
  27. package/dist/preview.js +131 -0
  28. package/dist/protection.d.ts +74 -0
  29. package/dist/protection.js +68 -0
  30. package/dist/revalidate.d.ts +84 -0
  31. package/dist/revalidate.js +143 -0
  32. package/dist/seo.d.ts +120 -0
  33. package/dist/seo.js +125 -0
  34. package/dist/server-key.d.ts +71 -0
  35. package/dist/server-key.js +103 -0
  36. package/dist/shared/api/delivery/cache-tags.d.ts +142 -0
  37. package/dist/shared/api/delivery/cache-tags.js +212 -0
  38. package/dist/shared/api/server-key.d.ts +90 -0
  39. package/dist/shared/api/server-key.js +260 -0
  40. package/dist/shared/business-registry/attribution.d.ts +14 -0
  41. package/dist/shared/business-registry/attribution.js +28 -0
  42. package/dist/shared/business-registry/define.d.ts +3 -0
  43. package/dist/shared/business-registry/define.js +4 -0
  44. package/dist/shared/business-registry/formats/eu-vat.d.ts +2 -0
  45. package/dist/shared/business-registry/formats/eu-vat.js +54 -0
  46. package/dist/shared/business-registry/formats/hk-br.d.ts +5 -0
  47. package/dist/shared/business-registry/formats/hk-br.js +23 -0
  48. package/dist/shared/business-registry/formats/jp-trn.d.ts +6 -0
  49. package/dist/shared/business-registry/formats/jp-trn.js +23 -0
  50. package/dist/shared/business-registry/formats/kr-brn.d.ts +6 -0
  51. package/dist/shared/business-registry/formats/kr-brn.js +30 -0
  52. package/dist/shared/business-registry/formats/my.d.ts +7 -0
  53. package/dist/shared/business-registry/formats/my.js +32 -0
  54. package/dist/shared/business-registry/formats/sg-uen.d.ts +1 -0
  55. package/dist/shared/business-registry/formats/sg-uen.js +21 -0
  56. package/dist/shared/business-registry/formats/tw-vat.d.ts +10 -0
  57. package/dist/shared/business-registry/formats/tw-vat.js +32 -0
  58. package/dist/shared/business-registry/index.d.ts +9 -0
  59. package/dist/shared/business-registry/index.js +10 -0
  60. package/dist/shared/business-registry/lookup-wire.d.ts +33 -0
  61. package/dist/shared/business-registry/lookup-wire.js +8 -0
  62. package/dist/shared/business-registry/normalize.d.ts +7 -0
  63. package/dist/shared/business-registry/normalize.js +12 -0
  64. package/dist/shared/business-registry/registry.d.ts +26 -0
  65. package/dist/shared/business-registry/registry.js +67 -0
  66. package/dist/shared/business-registry/types.d.ts +60 -0
  67. package/dist/shared/business-registry/types.js +10 -0
  68. package/dist/shared/localization/locale-path.d.ts +38 -0
  69. package/dist/shared/localization/locale-path.js +76 -0
  70. package/dist/shared/localization/request-locale.d.ts +42 -0
  71. package/dist/shared/localization/request-locale.js +61 -0
  72. package/dist/shared/seo/alternates.d.ts +61 -0
  73. package/dist/shared/seo/alternates.js +71 -0
  74. package/dist/shared/types/forms-logic.d.ts +96 -0
  75. package/dist/shared/types/forms-logic.js +209 -0
  76. package/dist/shared/types/number-input.d.ts +5 -0
  77. package/dist/shared/types/number-input.js +16 -0
  78. package/dist/shared/utils/redirect-matching.d.ts +76 -0
  79. package/dist/shared/utils/redirect-matching.js +181 -0
  80. package/dist/tax-id.d.ts +7 -0
  81. package/dist/tax-id.js +6 -0
  82. package/dist/typed.d.ts +85 -0
  83. package/dist/typed.js +28 -0
  84. package/package.json +86 -3
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Tax id format validation (checksums included where the country publishes one), the same rules Kanorio applies on its
3
+ * hosted checkout and forms. Pure functions with no network access: use them to validate while the visitor types.
4
+ * Registry lookups (registered name, status) stay on the server.
5
+ */
6
+ export { TAX_ID_FORMATS, cleanTaxIdInput, getTaxIdFormat, isBlockingTaxIdIssue, isTaxIdType, listTaxIdCountries, listTaxIdTypes, validateTaxIdFormat, } from "./shared/business-registry/index.js";
7
+ export type { RegistryAttributionWire, TaxIdEnforcement, TaxIdFormatDefinition, TaxIdFormatIssue, TaxIdFormatResult, TaxIdType, } from "./shared/business-registry/index.js";
package/dist/tax-id.js ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Tax id format validation (checksums included where the country publishes one), the same rules Kanorio applies on its
3
+ * hosted checkout and forms. Pure functions with no network access: use them to validate while the visitor types.
4
+ * Registry lookups (registered name, status) stay on the server.
5
+ */
6
+ export { TAX_ID_FORMATS, cleanTaxIdInput, getTaxIdFormat, isBlockingTaxIdIssue, isTaxIdType, listTaxIdCountries, listTaxIdTypes, validateTaxIdFormat, } from "./shared/business-registry/index.js";
@@ -0,0 +1,85 @@
1
+ /**
2
+ * A minimal client typed from the `paths` interface that openapi-typescript generates:
3
+ * `client.get("/sites/{siteId}", { params: { siteId }, query })` checks the path, path parameters, query, body and the success response type.
4
+ * No runtime validation; whatever the server answers is passed through.
5
+ */
6
+ import type { HttpClient } from "./http.js";
7
+ type HttpMethod = "get" | "post" | "put" | "patch" | "delete";
8
+ export type PathsWithMethod<P, M extends HttpMethod> = {
9
+ [K in keyof P]: P[K] extends {
10
+ [m in M]: unknown;
11
+ } ? (P[K][M] extends undefined | never ? never : K) : never;
12
+ }[keyof P];
13
+ type OperationOf<P, K extends keyof P, M extends HttpMethod> = P[K] extends {
14
+ [m in M]: infer O;
15
+ } ? O : never;
16
+ type PathParamsOf<O> = O extends {
17
+ parameters: {
18
+ path: infer PP;
19
+ };
20
+ } ? PP : O extends {
21
+ parameters: {
22
+ path?: infer PP;
23
+ };
24
+ } ? PP : never;
25
+ type QueryOf<O> = O extends {
26
+ parameters: {
27
+ query?: infer Q;
28
+ };
29
+ } ? Q : O extends {
30
+ parameters: {
31
+ query: infer Q;
32
+ };
33
+ } ? Q : never;
34
+ type JsonBodyOf<O> = O extends {
35
+ requestBody: {
36
+ content: {
37
+ "application/json": infer B;
38
+ };
39
+ };
40
+ } ? B : O extends {
41
+ requestBody?: {
42
+ content: {
43
+ "application/json": infer B;
44
+ };
45
+ };
46
+ } ? B | undefined : never;
47
+ type SuccessStatus = 200 | 201 | 202 | 204;
48
+ type ResponsesOf<O> = O extends {
49
+ responses: infer R;
50
+ } ? R : never;
51
+ type JsonOf<R> = R extends {
52
+ content: {
53
+ "application/json": infer J;
54
+ };
55
+ } ? J : R extends {
56
+ content?: never;
57
+ } ? void : unknown;
58
+ export type SuccessResponseOf<O> = {
59
+ [S in SuccessStatus & keyof ResponsesOf<O>]: JsonOf<ResponsesOf<O>[S]>;
60
+ }[SuccessStatus & keyof ResponsesOf<O>];
61
+ /** Not accepted when there is no such parameter; optional (`undefined`) or all-optional (`{}` is valid too, for a query with only `locale?`) parameters need not be passed */
62
+ type OptionalIfNever<K extends string, T> = [T] extends [never] ? {
63
+ [k in K]?: undefined;
64
+ } : undefined extends T ? {
65
+ [k in K]?: T;
66
+ } : {} extends T ? {
67
+ [k in K]?: T;
68
+ } : {
69
+ [k in K]: T;
70
+ };
71
+ export type TypedRequest<O> = OptionalIfNever<"params", PathParamsOf<O>> & OptionalIfNever<"query", QueryOf<O>> & OptionalIfNever<"body", JsonBodyOf<O>> & {
72
+ headers?: HeadersInit;
73
+ signal?: AbortSignal;
74
+ };
75
+ export interface TypedClient<P> {
76
+ get<K extends PathsWithMethod<P, "get">>(path: K, req?: TypedRequest<OperationOf<P, K, "get">>): Promise<SuccessResponseOf<OperationOf<P, K, "get">>>;
77
+ post<K extends PathsWithMethod<P, "post">>(path: K, req?: TypedRequest<OperationOf<P, K, "post">>): Promise<SuccessResponseOf<OperationOf<P, K, "post">>>;
78
+ put<K extends PathsWithMethod<P, "put">>(path: K, req?: TypedRequest<OperationOf<P, K, "put">>): Promise<SuccessResponseOf<OperationOf<P, K, "put">>>;
79
+ patch<K extends PathsWithMethod<P, "patch">>(path: K, req?: TypedRequest<OperationOf<P, K, "patch">>): Promise<SuccessResponseOf<OperationOf<P, K, "patch">>>;
80
+ delete<K extends PathsWithMethod<P, "delete">>(path: K, req?: TypedRequest<OperationOf<P, K, "delete">>): Promise<SuccessResponseOf<OperationOf<P, K, "delete">>>;
81
+ /** The underlying HTTP client (untyped) */
82
+ http: HttpClient;
83
+ }
84
+ export declare function createTypedClient<P>(http: HttpClient): TypedClient<P>;
85
+ export {};
package/dist/typed.js ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * A minimal client typed from the `paths` interface that openapi-typescript generates:
3
+ * `client.get("/sites/{siteId}", { params: { siteId }, query })` checks the path, path parameters, query, body and the success response type.
4
+ * No runtime validation; whatever the server answers is passed through.
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": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.1.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
+ "default": "./dist/index.js"
34
+ },
35
+ "./management": {
36
+ "types": "./dist/management.d.ts",
37
+ "default": "./dist/management.js"
38
+ },
39
+ "./delivery": {
40
+ "types": "./dist/delivery.d.ts",
41
+ "default": "./dist/delivery.js"
42
+ },
43
+ "./customer": {
44
+ "types": "./dist/customer.d.ts",
45
+ "default": "./dist/customer.js"
46
+ },
47
+ "./customer-oauth": {
48
+ "types": "./dist/customer-oauth.d.ts",
49
+ "default": "./dist/customer-oauth.js"
50
+ },
51
+ "./edge": {
52
+ "types": "./dist/edge.d.ts",
53
+ "default": "./dist/edge.js"
54
+ },
55
+ "./forms": {
56
+ "types": "./dist/forms.d.ts",
57
+ "default": "./dist/forms.js"
58
+ },
59
+ "./tax-id": {
60
+ "types": "./dist/tax-id.d.ts",
61
+ "default": "./dist/tax-id.js"
62
+ },
63
+ "./preview": {
64
+ "types": "./dist/preview.d.ts",
65
+ "default": "./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
  }