@ptkl/sdk 1.3.4 → 1.5.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.
@@ -47,11 +47,15 @@ class PlatformBaseClient extends BaseClient {
47
47
  token = token !== null && token !== void 0 ? token : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_API_TOKEN;
48
48
  project_uuid = __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_UUID;
49
49
  if (isBrowser) {
50
- if (sessionStorage.getItem('protokol_context') == "forge") {
51
- headers['X-Project-Env'] = (_b = sessionStorage.getItem('forge_app_env')) !== null && _b !== void 0 ? _b : "dev";
50
+ if (sessionStorage.getItem('protokol_context') === 'forge') {
51
+ headers['X-Project-Env'] = (_b = sessionStorage.getItem('forge_app_env')) !== null && _b !== void 0 ? _b : 'dev';
52
+ // pick up forge actor token — overrides any other token source
53
+ const forgeToken = sessionStorage.getItem('forge_actor_token');
54
+ if (forgeToken)
55
+ token = forgeToken;
52
56
  }
53
57
  else {
54
- headers['X-Project-Env'] = (_c = localStorage.getItem('current_env')) !== null && _c !== void 0 ? _c : "dev";
58
+ headers['X-Project-Env'] = (_c = localStorage.getItem('current_env')) !== null && _c !== void 0 ? _c : 'dev';
55
59
  }
56
60
  }
57
61
  }
@@ -76,8 +80,7 @@ class PlatformBaseClient extends BaseClient {
76
80
  headers: {
77
81
  ...headers,
78
82
  'Content-Type': 'application/json',
79
- },
80
- withCredentials: true,
83
+ }
81
84
  });
82
85
  super(client);
83
86
  this.env = null;
@@ -235,7 +238,7 @@ class Component extends PlatformBaseClient {
235
238
  async updateMany(data, options) {
236
239
  return await this.client.patch(`${this.getComponentPath()}/models/bulk`, {
237
240
  data,
238
- options
241
+ options,
239
242
  });
240
243
  }
241
244
  /**
@@ -469,16 +472,6 @@ class Functions extends PlatformBaseClient {
469
472
  async update(uuid, update) {
470
473
  return await this.client.patch(`/v1/system/function/${uuid}`, update);
471
474
  }
472
- /**
473
- * Run platform function
474
- *
475
- * @param id - Function ID
476
- * @param d - Object containing input data, query parameters, and headers
477
- * @returns - Function result
478
- *
479
- * @example
480
- * const result = await platform.function().run("myFunction", {input: { foo: "bar" }})
481
- */
482
475
  async run(id, d) {
483
476
  const { data } = await this.client.post(`/v1/system/function/run/${id}`, d.input, {
484
477
  params: d.query,
@@ -922,10 +915,9 @@ class Sandbox extends PlatformBaseClient {
922
915
  }
923
916
 
924
917
  class System extends PlatformBaseClient {
925
- async resourceResolver(ref, resourceName, format) {
918
+ async resourceResolver(prn, format) {
926
919
  return await this.client.post("/v3/system/resource-resolver", {
927
- type: resourceName,
928
- ref,
920
+ prn,
929
921
  format,
930
922
  });
931
923
  }
@@ -1252,11 +1244,15 @@ class IntegrationsBaseClient extends BaseClient {
1252
1244
  env = env !== null && env !== void 0 ? env : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_ENV;
1253
1245
  token = token !== null && token !== void 0 ? token : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_API_TOKEN;
1254
1246
  if (isBrowser) {
1255
- if (sessionStorage.getItem('protokol_context') == "forge") {
1256
- headers['X-Project-Env'] = (_b = sessionStorage.getItem('forge_app_env')) !== null && _b !== void 0 ? _b : "dev";
1247
+ if (sessionStorage.getItem('protokol_context') === 'forge') {
1248
+ headers['X-Project-Env'] = (_b = sessionStorage.getItem('forge_app_env')) !== null && _b !== void 0 ? _b : 'dev';
1249
+ // pick up forge actor token — overrides any other token source
1250
+ const forgeToken = sessionStorage.getItem('forge_actor_token');
1251
+ if (forgeToken)
1252
+ token = forgeToken;
1257
1253
  }
1258
1254
  else {
1259
- headers['X-Project-Env'] = (_c = localStorage.getItem('current_env')) !== null && _c !== void 0 ? _c : "dev";
1255
+ headers['X-Project-Env'] = (_c = localStorage.getItem('current_env')) !== null && _c !== void 0 ? _c : 'dev';
1260
1256
  }
1261
1257
  }
1262
1258
  }
@@ -1280,8 +1276,7 @@ class IntegrationsBaseClient extends BaseClient {
1280
1276
  timeout: 30000,
1281
1277
  headers: {
1282
1278
  ...headers,
1283
- },
1284
- withCredentials: true,
1279
+ }
1285
1280
  });
1286
1281
  super(client);
1287
1282
  this.env = null;
@@ -2890,6 +2885,57 @@ class Minimax extends IntegrationsBaseClient {
2890
2885
  }
2891
2886
  }
2892
2887
 
2888
+ class Ecommerce extends IntegrationsBaseClient {
2889
+ /**
2890
+ * Get the ecommerce integration user for the current project.
2891
+ */
2892
+ async get() {
2893
+ return await this.client.get(`/v1/ecomm/user`);
2894
+ }
2895
+ /**
2896
+ * Update ecommerce integration settings (onboarding or partial update).
2897
+ */
2898
+ async update(req) {
2899
+ return await this.client.patch(`/v1/ecomm/user`, req);
2900
+ }
2901
+ /**
2902
+ * Check whether a base domain subdomain is available.
2903
+ */
2904
+ async checkBaseDomain(domain) {
2905
+ return await this.client.post(`/v1/ecomm/base-domain/check`, { domain });
2906
+ }
2907
+ /**
2908
+ * Add a custom domain (returns a verification token for DNS validation).
2909
+ */
2910
+ async addCustomDomain(domain) {
2911
+ return await this.client.post(`/v1/ecomm/domains`, { domain });
2912
+ }
2913
+ /**
2914
+ * Validate a custom domain with its verification token.
2915
+ */
2916
+ async validateCustomDomain(domain, token) {
2917
+ return await this.client.post(`/v1/ecomm/domains/validate`, { domain, token });
2918
+ }
2919
+ /**
2920
+ * Remove a custom domain.
2921
+ */
2922
+ async removeCustomDomain(domain) {
2923
+ return await this.client.delete(`/v1/ecomm/domains`, { data: { domain } });
2924
+ }
2925
+ /**
2926
+ * List pending (unvalidated) custom domains.
2927
+ */
2928
+ async getPendingDomains() {
2929
+ return await this.client.get(`/v1/ecomm/domains/pending`);
2930
+ }
2931
+ /**
2932
+ * List validated custom domains.
2933
+ */
2934
+ async getValidatedDomains() {
2935
+ return await this.client.get(`/v1/ecomm/domains/validated`);
2936
+ }
2937
+ }
2938
+
2893
2939
  // import integrations
2894
2940
  class Integrations extends IntegrationsBaseClient {
2895
2941
  constructor(options) {
@@ -2902,6 +2948,7 @@ class Integrations extends IntegrationsBaseClient {
2902
2948
  'serbia-utilities': new SerbiaUtil().setClient(this.client),
2903
2949
  'protokol-payments': new Payments().setClient(this.client),
2904
2950
  'protokol-minimax': new Minimax().setClient(this.client),
2951
+ 'protokol-ecommerce': new Ecommerce().setClient(this.client),
2905
2952
  };
2906
2953
  }
2907
2954
  getSerbiaUtilities() {
@@ -2925,6 +2972,9 @@ class Integrations extends IntegrationsBaseClient {
2925
2972
  getMinimax() {
2926
2973
  return this.getInterfaceOf('protokol-minimax');
2927
2974
  }
2975
+ getEcommerce() {
2976
+ return this.getInterfaceOf('protokol-ecommerce');
2977
+ }
2928
2978
  async isInstalled(id) {
2929
2979
  const { data } = await this.client.get("/v1/integrations");
2930
2980
  return data.find((i) => i.id == id) !== undefined;
@@ -2943,4 +2993,4 @@ class Integrations extends IntegrationsBaseClient {
2943
2993
  // Export all API modules for version 0.9
2944
2994
  // This version has specific method signatures and behaviors for v0.9
2945
2995
 
2946
- export { APIUser, Apps, Component, ComponentUtils, Config, DMS, Forge, Functions, Integrations as Integration, Integrations, Invoicing, Mail, Payments, Platform, Project, Ratchet, Sandbox, SerbiaUtil, System, Thunder, Users, VPFR, Workflow, Platform as default };
2996
+ export { APIUser, Apps, Component, ComponentUtils, Config, DMS, Ecommerce, Forge, Functions, Integrations as Integration, Integrations, Invoicing, Mail, Payments, Platform, Project, Ratchet, Sandbox, SerbiaUtil, System, Thunder, Users, VPFR, Workflow, Platform as default };
@@ -65,16 +65,17 @@ type Model = {
65
65
  [key: string]: any;
66
66
  };
67
67
  type UpdateOptions = {
68
- forceUpdateProtectedFields: boolean;
68
+ force_update_protected_fields: boolean;
69
69
  };
70
70
  type UpdateManyOptions = UpdateOptions & {
71
- rollbackOnError: boolean;
71
+ rollback_on_error: boolean;
72
72
  };
73
73
  type CreateManyOptions = {
74
- rollbackOnError: boolean;
74
+ rollback_on_error: boolean;
75
75
  };
76
76
  type ModifyOptions = {
77
77
  upsert: boolean;
78
+ force_update_protected_fields?: boolean;
78
79
  };
79
80
  type ComponentOptions = {
80
81
  version?: string;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * PlatformFunctions is an open interface that serves as a registry of platform
3
+ * function signatures. It is empty by default and can be extended in two ways:
4
+ *
5
+ * 1. **At build time** — run `ptkl generate-types` to fetch your project's
6
+ * functions and emit a `.d.ts` file with a module augmentation block:
7
+ * ```ts
8
+ * declare module "@ptkl/sdk" {
9
+ * interface PlatformFunctions {
10
+ * "send_email": { input: { body: string; to: string }; output: { status: boolean } }
11
+ * }
12
+ * }
13
+ * ```
14
+ *
15
+ * 2. **At runtime in Monaco editors** — the editor auto-patches the interface
16
+ * from your project's live function signatures.
17
+ */
18
+ export interface PlatformFunctions {
19
+ }
20
+ /**
21
+ * Access a single platform function's signature type by name.
22
+ *
23
+ * @example
24
+ * type EmailSig = PlatformFunction<"send_email">
25
+ * // → { input: { body: string; to: string }; output: { status: boolean } }
26
+ */
27
+ export type PlatformFunction<K extends keyof PlatformFunctions> = PlatformFunctions[K];
28
+ /** Inferred input type for a registered function, falling back to a generic record. */
29
+ export type FunctionInput<K extends keyof PlatformFunctions> = PlatformFunctions[K] extends {
30
+ input: infer I;
31
+ } ? I : Record<string, any>;
32
+ /** Inferred output type for a registered function, falling back to any. */
33
+ export type FunctionOutput<K extends keyof PlatformFunctions> = PlatformFunctions[K] extends {
34
+ output: infer O;
35
+ } ? O : any;
36
+ /** Parameters shape for a typed function call. */
37
+ export type FunctionCallParams<K extends keyof PlatformFunctions> = {
38
+ input: FunctionInput<K>;
39
+ query?: Record<string, string>;
40
+ headers?: Record<string, string>;
41
+ };
@@ -0,0 +1,199 @@
1
+ export type IDNamePair = {
2
+ id: string;
3
+ name: string;
4
+ };
5
+ export type ShippingMethodsConfig = {
6
+ methods: IDNamePair[];
7
+ };
8
+ export type PaymentMethodsConfig = {
9
+ methods: IDNamePair[];
10
+ };
11
+ export type PaymentProvidersConfig = {
12
+ options?: IDNamePair;
13
+ };
14
+ export type CartSettings = {
15
+ shipping_methods: ShippingMethodsConfig;
16
+ payment_methods: PaymentMethodsConfig;
17
+ payment_providers: PaymentProvidersConfig;
18
+ };
19
+ export type PriceSettings = {
20
+ default_currency: IDNamePair;
21
+ };
22
+ export type I18nSettings = {
23
+ default_locale: IDNamePair;
24
+ locales: IDNamePair[];
25
+ };
26
+ export type LogoConfig = {
27
+ position: number;
28
+ src: string;
29
+ alt: string;
30
+ width: number;
31
+ height: number;
32
+ };
33
+ export type ItemsConfig = {
34
+ position: number;
35
+ menu: IDNamePair;
36
+ };
37
+ export type ActionsConfig = {
38
+ position: number;
39
+ icons: Record<string, any>;
40
+ };
41
+ export type HeaderSettings = {
42
+ logo: LogoConfig;
43
+ items: ItemsConfig;
44
+ actions: ActionsConfig;
45
+ };
46
+ export type HomepageSection = {
47
+ id: string;
48
+ type: string;
49
+ show: boolean;
50
+ settings: Record<string, any>;
51
+ };
52
+ export type HomepageSettings = {
53
+ sections: HomepageSection[];
54
+ };
55
+ export type CategoryInfoConfig = {
56
+ text_position: IDNamePair;
57
+ show_title: boolean;
58
+ show_description: boolean;
59
+ show_image: boolean;
60
+ };
61
+ export type CategoryHeaderConfig = {
62
+ use_breadcrumbs: boolean;
63
+ category_info: CategoryInfoConfig;
64
+ };
65
+ export type CategoryFiltersConfig = {
66
+ show: boolean;
67
+ type: IDNamePair;
68
+ use_accordion: boolean;
69
+ };
70
+ export type CategorySettings = {
71
+ header: CategoryHeaderConfig;
72
+ filters: CategoryFiltersConfig;
73
+ };
74
+ export type DisplayConfig = {
75
+ show: boolean;
76
+ text_position: IDNamePair;
77
+ position: number;
78
+ };
79
+ export type SimpleDisplayConfig = {
80
+ show: boolean;
81
+ };
82
+ export type InventoryConfig = {
83
+ show: boolean;
84
+ text_position: IDNamePair;
85
+ position: number;
86
+ allow_backorder: boolean;
87
+ };
88
+ export type ActionButtonConfig = {
89
+ icon: IDNamePair;
90
+ button_variant: IDNamePair;
91
+ show: boolean;
92
+ };
93
+ export type ProductActionsConfig = {
94
+ position: number;
95
+ align: IDNamePair;
96
+ add_to_cart: ActionButtonConfig;
97
+ add_to_wishlist: ActionButtonConfig;
98
+ };
99
+ export type QuantitySelectorConfig = {
100
+ show: boolean;
101
+ text_position: IDNamePair;
102
+ };
103
+ export type ProductInfoConfig = {
104
+ title: DisplayConfig;
105
+ sku: DisplayConfig;
106
+ stock_status: SimpleDisplayConfig;
107
+ inventory: InventoryConfig;
108
+ description: DisplayConfig;
109
+ variants: DisplayConfig;
110
+ price: DisplayConfig;
111
+ actions: ProductActionsConfig;
112
+ discount_badge?: SimpleDisplayConfig;
113
+ quantity_selector?: QuantitySelectorConfig;
114
+ specifications?: SimpleDisplayConfig;
115
+ };
116
+ export type ProductSettings = {
117
+ product_info: ProductInfoConfig;
118
+ };
119
+ export type FooterLogoConfig = {
120
+ src: string;
121
+ alt: string;
122
+ width: number;
123
+ height: number;
124
+ };
125
+ export type FooterColumnOne = {
126
+ logo: FooterLogoConfig;
127
+ socials: any[];
128
+ };
129
+ export type FooterSettings = {
130
+ column_one: FooterColumnOne;
131
+ };
132
+ export type EcommerceSettings = {
133
+ maintenance: boolean;
134
+ cart: CartSettings;
135
+ price: PriceSettings;
136
+ i18n: I18nSettings;
137
+ header: HeaderSettings;
138
+ homepage: HomepageSettings;
139
+ category: CategorySettings;
140
+ product: ProductSettings;
141
+ footer: FooterSettings;
142
+ theme?: any;
143
+ };
144
+ export type EcommEnvSettings = {
145
+ dev: EcommerceSettings | null;
146
+ live: EcommerceSettings | null;
147
+ };
148
+ export type CompanyInfo = {
149
+ vat_number: string;
150
+ legal_name: string;
151
+ company_name: string;
152
+ address: string;
153
+ city: string;
154
+ zip_code: string;
155
+ phone: string;
156
+ email: string;
157
+ legal_representative: string;
158
+ additional_info?: Record<string, any>;
159
+ };
160
+ export type Documentation = {
161
+ terms_of_service: string | null;
162
+ privacy_policy: string | null;
163
+ };
164
+ export type EcommerceIntegrationUser = {
165
+ project_uuid: string;
166
+ base_domain: string;
167
+ custom_domains: string[];
168
+ company: CompanyInfo;
169
+ merchant_description: string;
170
+ mcc: string[];
171
+ documentation: Documentation;
172
+ product_types: string[];
173
+ settings: EcommEnvSettings;
174
+ data: Record<string, any>;
175
+ created_at: string;
176
+ updated_at: string;
177
+ deleted_at?: string | null;
178
+ };
179
+ export type UpdateEcommerceSettingsRequest = {
180
+ base_domain?: string;
181
+ custom_domains?: string[];
182
+ company?: Partial<CompanyInfo>;
183
+ merchant_description?: string;
184
+ mcc?: string[];
185
+ product_types?: string[];
186
+ documentation?: Partial<Documentation>;
187
+ settings?: Partial<EcommEnvSettings>;
188
+ };
189
+ export type CheckDomainResponse = {
190
+ domain: string;
191
+ available: boolean;
192
+ };
193
+ export type AddDomainResponse = {
194
+ integration: EcommerceIntegrationUser;
195
+ verification_token: string;
196
+ };
197
+ export type DomainsResponse = {
198
+ domains: string[];
199
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptkl/sdk",
3
- "version": "1.3.4",
3
+ "version": "1.5.0",
4
4
  "scripts": {
5
5
  "build": "rollup -c",
6
6
  "build:monaco": "npm run build && node scripts/generate-monaco-types.cjs",
@@ -13,17 +13,17 @@
13
13
  ".": {
14
14
  "import": "./dist/v0.9/index.esm.js",
15
15
  "require": "./dist/v0.9/index.cjs.js",
16
- "types": "./dist/v0.9/index.d.ts"
16
+ "types": "./dist/v0.9/api/index.d.ts"
17
17
  },
18
18
  "./beta": {
19
19
  "import": "./dist/v0.10/index.esm.js",
20
20
  "require": "./dist/v0.10/index.cjs.js",
21
- "types": "./dist/v0.10/index.d.ts"
21
+ "types": "./dist/v0.10/api/index.d.ts"
22
22
  }
23
23
  },
24
24
  "main": "./dist/v0.10/index.cjs.js",
25
25
  "module": "./dist/v0.10/index.esm.js",
26
- "types": "./dist/v0.10/index.d.ts",
26
+ "types": "./dist/v0.10/api/index.d.ts",
27
27
  "author": "protokol.io",
28
28
  "license": "ISC",
29
29
  "type": "module",
@@ -44,6 +44,7 @@
44
44
  "typescript": "^5.6.3"
45
45
  },
46
46
  "dependencies": {
47
+ "@ptkl/sdk": "file:",
47
48
  "@rollup/plugin-replace": "^6.0.2",
48
49
  "axios": "^1.7.7",
49
50
  "dom-parser": "^1.1.5",