@ptkl/sdk 1.7.1 → 1.9.1

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.
@@ -1252,6 +1252,21 @@ class System extends PlatformBaseClient {
1252
1252
  }
1253
1253
 
1254
1254
  class Workflow extends PlatformBaseClient {
1255
+ async create(data) {
1256
+ return await this.client.post(`/v1/project/workflow/workflow`, data);
1257
+ }
1258
+ async update(id, data) {
1259
+ return await this.client.patch(`/v1/project/workflow/workflow/${id}`, data);
1260
+ }
1261
+ async get(id) {
1262
+ return await this.client.get(`/v1/project/workflow/workflow/${id}`);
1263
+ }
1264
+ async list() {
1265
+ return await this.client.get(`/v1/project/workflow/workflows`);
1266
+ }
1267
+ async delete(id) {
1268
+ return await this.client.delete(`/v1/project/workflow/workflow/${id}`);
1269
+ }
1255
1270
  async trigger(id, event, data) {
1256
1271
  return await this.client.post(`/v1/project/workflow/workflow/${id}/event/${event}`, data);
1257
1272
  }
@@ -3453,10 +3468,18 @@ class Integrations extends IntegrationsBaseClient {
3453
3468
  getEcommerce() {
3454
3469
  return this.getInterfaceOf('protokol-ecommerce');
3455
3470
  }
3471
+ async list() {
3472
+ const { data } = await this.client.get("/v1/integrations");
3473
+ return data;
3474
+ }
3456
3475
  async isInstalled(id) {
3457
3476
  const { data } = await this.client.get("/v1/integrations");
3458
3477
  return data.find((i) => i.id == id) !== undefined;
3459
3478
  }
3479
+ async isActive(id) {
3480
+ const { data } = await this.client.get("/v1/integrations");
3481
+ return data.find((i) => i.id == id && i.status == "active") !== undefined;
3482
+ }
3460
3483
  getInterfaceOf(id) {
3461
3484
  try {
3462
3485
  return this.integrations[id];
@@ -3467,6 +3490,133 @@ class Integrations extends IntegrationsBaseClient {
3467
3490
  }
3468
3491
  }
3469
3492
 
3493
+ // PRN — Protokol Resource Name
3494
+ //
3495
+ // Format:
3496
+ // prn:<type>:<ref>[:<path>][?<query>]
3497
+ //
3498
+ // Examples:
3499
+ // prn:component:my-component:settings.api_key
3500
+ // prn:integration:protokol-ecommerce:company.legal_name?lang=en
3501
+ // prn:user:actor:forge?app=abc123&behalf=user-uuid
3502
+ /**
3503
+ * Splits s on sep into at most n parts, keeping the remainder in the last part.
3504
+ * Mirrors Go's strings.SplitN behaviour.
3505
+ */
3506
+ function splitN(s, sep, n) {
3507
+ const parts = [];
3508
+ let start = 0;
3509
+ for (let i = 1; i < n; i++) {
3510
+ const idx = s.indexOf(sep, start);
3511
+ if (idx === -1)
3512
+ break;
3513
+ parts.push(s.slice(start, idx));
3514
+ start = idx + sep.length;
3515
+ }
3516
+ parts.push(s.slice(start));
3517
+ return parts;
3518
+ }
3519
+ class PRN {
3520
+ constructor(raw) {
3521
+ this._raw = raw;
3522
+ }
3523
+ /**
3524
+ * Validates a PRN string and returns it as a PRN instance.
3525
+ * Throws if the string is not a valid PRN.
3526
+ */
3527
+ static parse(s) {
3528
+ const parts = splitN(s, ':', 4);
3529
+ if (parts.length < 3) {
3530
+ throw new Error(`invalid PRN "${s}": expected format prn:<type>:<ref>[:<path>]`);
3531
+ }
3532
+ if (parts[0] !== 'prn') {
3533
+ throw new Error(`invalid PRN "${s}": must start with 'prn'`);
3534
+ }
3535
+ if (!parts[1]) {
3536
+ throw new Error(`invalid PRN "${s}": type must not be empty`);
3537
+ }
3538
+ if (!parts[2]) {
3539
+ throw new Error(`invalid PRN "${s}": ref must not be empty`);
3540
+ }
3541
+ return new PRN(s);
3542
+ }
3543
+ /**
3544
+ * Constructs a PRN from its constituent parts.
3545
+ * Params are sorted by key for deterministic output.
3546
+ */
3547
+ static create(type, ref, path, params) {
3548
+ let s = `prn:${type}:${ref}`;
3549
+ if (path) {
3550
+ s += `:${path}`;
3551
+ }
3552
+ if (params && Object.keys(params).length > 0) {
3553
+ const sorted = Object.keys(params).sort();
3554
+ const qs = new URLSearchParams();
3555
+ for (const k of sorted) {
3556
+ qs.set(k, params[k]);
3557
+ }
3558
+ s += `?${qs.toString()}`;
3559
+ }
3560
+ return new PRN(s);
3561
+ }
3562
+ _parse() {
3563
+ var _a, _b;
3564
+ const s = this._raw;
3565
+ const parts = splitN(s, ':', 4);
3566
+ const type = (_a = parts[1]) !== null && _a !== void 0 ? _a : '';
3567
+ const ref = (_b = parts[2]) !== null && _b !== void 0 ? _b : '';
3568
+ let path = '';
3569
+ const params = {};
3570
+ if (parts.length === 4 && parts[3]) {
3571
+ const rawPath = parts[3];
3572
+ const qIdx = rawPath.indexOf('?');
3573
+ if (qIdx >= 0) {
3574
+ path = rawPath.slice(0, qIdx);
3575
+ const qs = new URLSearchParams(rawPath.slice(qIdx + 1));
3576
+ qs.forEach((v, k) => {
3577
+ params[k] = v;
3578
+ });
3579
+ }
3580
+ else {
3581
+ path = rawPath;
3582
+ }
3583
+ }
3584
+ return { type, ref, path, params };
3585
+ }
3586
+ /** The resource category — e.g. "component", "integration", "user". */
3587
+ get type() {
3588
+ return this._parse().type;
3589
+ }
3590
+ /** The resource identifier within its type — slug, UUID, name. */
3591
+ get ref() {
3592
+ return this._parse().ref;
3593
+ }
3594
+ /** The resource path segment, or empty string if absent. */
3595
+ get path() {
3596
+ return this._parse().path;
3597
+ }
3598
+ /** All query-string key-value pairs, or empty object if none. */
3599
+ get params() {
3600
+ return this._parse().params;
3601
+ }
3602
+ /** Returns the value for the given query-param key, or empty string if not present. */
3603
+ param(key) {
3604
+ var _a;
3605
+ return (_a = this._parse().params[key]) !== null && _a !== void 0 ? _a : '';
3606
+ }
3607
+ toString() {
3608
+ return this._raw;
3609
+ }
3610
+ }
3611
+ /**
3612
+ * Convenience wrapper around PRN.parse.
3613
+ * Validates a PRN string and returns a PRN instance.
3614
+ * Throws if the string is not a valid PRN.
3615
+ */
3616
+ function parsePRN(s) {
3617
+ return PRN.parse(s);
3618
+ }
3619
+
3470
3620
  class Invoicing extends PlatformBaseClient {
3471
3621
  async getSalesInvoices(provider, page) {
3472
3622
  return await this.request("GET", `invoices/${provider}/sales`, {
@@ -3492,4 +3642,4 @@ class Invoicing extends PlatformBaseClient {
3492
3642
  }
3493
3643
  }
3494
3644
 
3495
- export { APIUser, Apps, Component, ComponentUtils, Config, DMS, Ecommerce, Forge, Functions, Integrations as Integration, Integrations, Invoicing, Mail, NBS, Payments, Platform, Project, Ratchet, Sandbox, MinFin as SerbiaMinFin, System, Thunder, Users, VPFR, Workflow };
3645
+ export { APIUser, Apps, Component, ComponentUtils, Config, DMS, Ecommerce, Forge, Functions, Integrations as Integration, Integrations, Invoicing, Mail, NBS, PRN, Payments, Platform, Project, Ratchet, Sandbox, MinFin as SerbiaMinFin, System, Thunder, Users, VPFR, Workflow, parsePRN };
@@ -0,0 +1,48 @@
1
+ type WorkflowNode = {
2
+ id: number;
3
+ x: number;
4
+ y: number;
5
+ name: string;
6
+ action: string;
7
+ type: string;
8
+ connections: WorkflowNodeConnection[];
9
+ paused: boolean;
10
+ parallel: boolean;
11
+ data: Record<string, any>;
12
+ };
13
+ type WorkflowNodeConnection = {
14
+ node_id: number;
15
+ [key: string]: any;
16
+ };
17
+ type WorkflowSettings = {
18
+ version: string;
19
+ nodes: WorkflowNode[];
20
+ };
21
+ type WorkflowModel = {
22
+ uuid: string;
23
+ name: string;
24
+ project_uuid: string;
25
+ dev_version: string;
26
+ public_version: string;
27
+ integrator: string;
28
+ roles: string[];
29
+ settings: WorkflowSettings[];
30
+ };
31
+ type WorkflowCreatePayload = {
32
+ name: string;
33
+ dev_version?: string;
34
+ public_version?: string;
35
+ integrator?: string;
36
+ roles?: string[];
37
+ settings?: WorkflowSettings[];
38
+ };
39
+ type WorkflowUpdatePayload = {
40
+ name?: string;
41
+ dev_version?: string;
42
+ public_version?: string;
43
+ integrator?: string;
44
+ roles?: string[];
45
+ settings?: WorkflowSettings[];
46
+ };
47
+ type WorkflowListResponse = WorkflowModel[];
48
+ export { WorkflowNode, WorkflowNodeConnection, WorkflowSettings, WorkflowModel, WorkflowCreatePayload, WorkflowUpdatePayload, WorkflowListResponse, };
@@ -0,0 +1,38 @@
1
+ export interface ParsedPRN {
2
+ type: string;
3
+ ref: string;
4
+ path: string;
5
+ params: Record<string, string>;
6
+ }
7
+ export declare class PRN {
8
+ private readonly _raw;
9
+ private constructor();
10
+ /**
11
+ * Validates a PRN string and returns it as a PRN instance.
12
+ * Throws if the string is not a valid PRN.
13
+ */
14
+ static parse(s: string): PRN;
15
+ /**
16
+ * Constructs a PRN from its constituent parts.
17
+ * Params are sorted by key for deterministic output.
18
+ */
19
+ static create(type: string, ref: string, path?: string, params?: Record<string, string>): PRN;
20
+ private _parse;
21
+ /** The resource category — e.g. "component", "integration", "user". */
22
+ get type(): string;
23
+ /** The resource identifier within its type — slug, UUID, name. */
24
+ get ref(): string;
25
+ /** The resource path segment, or empty string if absent. */
26
+ get path(): string;
27
+ /** All query-string key-value pairs, or empty object if none. */
28
+ get params(): Record<string, string>;
29
+ /** Returns the value for the given query-param key, or empty string if not present. */
30
+ param(key: string): string;
31
+ toString(): string;
32
+ }
33
+ /**
34
+ * Convenience wrapper around PRN.parse.
35
+ * Validates a PRN string and returns a PRN instance.
36
+ * Throws if the string is not a valid PRN.
37
+ */
38
+ export declare function parsePRN(s: string): PRN;
@@ -1,4 +1,5 @@
1
1
  export type { Settings, SettingsField, FieldRoles, FieldConstraints, Context, Preset, PresetContext, Filters, Extension, Policy, SetupData, Model, } from '../types/component';
2
+ export type { WorkflowModel, WorkflowSettings, WorkflowNode, WorkflowNodeConnection, WorkflowCreatePayload, WorkflowUpdatePayload, WorkflowListResponse, } from '../types/workflow';
2
3
  export { default as Component } from './component';
3
4
  export { default as Platform } from './platform';
4
5
  export { default as Functions } from './functions';
@@ -16,6 +17,8 @@ export { default as Project } from './project';
16
17
  export { default as Config } from './config';
17
18
  export { default as Integrations } from './integrations';
18
19
  export { default as Integration } from './integrations';
20
+ export { PRN, parsePRN } from '../util/prn';
21
+ export type { ParsedPRN } from '../util/prn';
19
22
  export { default as Payments } from './integrations/payments';
20
23
  export { default as Invoicing } from './integrations/invoicing';
21
24
  export { default as DMS } from './integrations/dms';
@@ -21,6 +21,8 @@ export default class Integrations extends IntegrationsBaseClient {
21
21
  getPayments(): Payments;
22
22
  getMinimax(): Minimax;
23
23
  getEcommerce(): Ecommerce;
24
+ list(): Promise<any>;
24
25
  isInstalled(id: string): Promise<boolean>;
26
+ isActive(id: string): Promise<boolean>;
25
27
  getInterfaceOf(id: string): any;
26
28
  }
@@ -1,5 +1,12 @@
1
+ import { AxiosResponse } from 'axios';
1
2
  import PlatformBaseClient from "./platformBaseClient";
3
+ import { WorkflowModel, WorkflowCreatePayload, WorkflowUpdatePayload, WorkflowListResponse } from '../types/workflow';
2
4
  export default class Workflow extends PlatformBaseClient {
3
- trigger(id: string, event: string, data: any): Promise<import("axios").AxiosResponse<any, any>>;
4
- publish(event: string, data: any): Promise<import("axios").AxiosResponse<any, any>>;
5
+ create(data: WorkflowCreatePayload): Promise<AxiosResponse<WorkflowModel>>;
6
+ update(id: string, data: WorkflowUpdatePayload): Promise<AxiosResponse<WorkflowModel>>;
7
+ get(id: string): Promise<AxiosResponse<WorkflowModel>>;
8
+ list(): Promise<AxiosResponse<WorkflowListResponse>>;
9
+ delete(id: string): Promise<AxiosResponse<void>>;
10
+ trigger(id: string, event: string, data: any): Promise<AxiosResponse<any, any>>;
11
+ publish(event: string, data: any): Promise<AxiosResponse<any, any>>;
5
12
  }
@@ -14620,7 +14620,7 @@ var transitionalDefaults = {
14620
14620
  clarifyTimeoutError: false
14621
14621
  };
14622
14622
 
14623
- var URLSearchParams = require$$0$1.URLSearchParams;
14623
+ var URLSearchParams$1 = require$$0$1.URLSearchParams;
14624
14624
 
14625
14625
  const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
14626
14626
 
@@ -14648,7 +14648,7 @@ const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
14648
14648
  var platform$1 = {
14649
14649
  isNode: true,
14650
14650
  classes: {
14651
- URLSearchParams,
14651
+ URLSearchParams: URLSearchParams$1,
14652
14652
  FormData: FormData$1,
14653
14653
  Blob: typeof Blob !== 'undefined' && Blob || null
14654
14654
  },
@@ -19908,6 +19908,21 @@ class System extends PlatformBaseClient {
19908
19908
  }
19909
19909
 
19910
19910
  class Workflow extends PlatformBaseClient {
19911
+ async create(data) {
19912
+ return await this.client.post(`/v1/project/workflow/workflow`, data);
19913
+ }
19914
+ async update(id, data) {
19915
+ return await this.client.patch(`/v1/project/workflow/workflow/${id}`, data);
19916
+ }
19917
+ async get(id) {
19918
+ return await this.client.get(`/v1/project/workflow/workflow/${id}`);
19919
+ }
19920
+ async list() {
19921
+ return await this.client.get(`/v1/project/workflow/workflows`);
19922
+ }
19923
+ async delete(id) {
19924
+ return await this.client.delete(`/v1/project/workflow/workflow/${id}`);
19925
+ }
19911
19926
  async trigger(id, event, data) {
19912
19927
  return await this.client.post(`/v1/project/workflow/workflow/${id}/event/${event}`, data);
19913
19928
  }
@@ -21959,10 +21974,18 @@ class Integrations extends IntegrationsBaseClient {
21959
21974
  getEcommerce() {
21960
21975
  return this.getInterfaceOf('protokol-ecommerce');
21961
21976
  }
21977
+ async list() {
21978
+ const { data } = await this.client.get("/v1/integrations");
21979
+ return data;
21980
+ }
21962
21981
  async isInstalled(id) {
21963
21982
  const { data } = await this.client.get("/v1/integrations");
21964
21983
  return data.find((i) => i.id == id) !== undefined;
21965
21984
  }
21985
+ async isActive(id) {
21986
+ const { data } = await this.client.get("/v1/integrations");
21987
+ return data.find((i) => i.id == id && i.status == "active") !== undefined;
21988
+ }
21966
21989
  getInterfaceOf(id) {
21967
21990
  try {
21968
21991
  return this.integrations[id];
@@ -21973,6 +21996,133 @@ class Integrations extends IntegrationsBaseClient {
21973
21996
  }
21974
21997
  }
21975
21998
 
21999
+ // PRN — Protokol Resource Name
22000
+ //
22001
+ // Format:
22002
+ // prn:<type>:<ref>[:<path>][?<query>]
22003
+ //
22004
+ // Examples:
22005
+ // prn:component:my-component:settings.api_key
22006
+ // prn:integration:protokol-ecommerce:company.legal_name?lang=en
22007
+ // prn:user:actor:forge?app=abc123&behalf=user-uuid
22008
+ /**
22009
+ * Splits s on sep into at most n parts, keeping the remainder in the last part.
22010
+ * Mirrors Go's strings.SplitN behaviour.
22011
+ */
22012
+ function splitN(s, sep, n) {
22013
+ const parts = [];
22014
+ let start = 0;
22015
+ for (let i = 1; i < n; i++) {
22016
+ const idx = s.indexOf(sep, start);
22017
+ if (idx === -1)
22018
+ break;
22019
+ parts.push(s.slice(start, idx));
22020
+ start = idx + sep.length;
22021
+ }
22022
+ parts.push(s.slice(start));
22023
+ return parts;
22024
+ }
22025
+ class PRN {
22026
+ constructor(raw) {
22027
+ this._raw = raw;
22028
+ }
22029
+ /**
22030
+ * Validates a PRN string and returns it as a PRN instance.
22031
+ * Throws if the string is not a valid PRN.
22032
+ */
22033
+ static parse(s) {
22034
+ const parts = splitN(s, ':', 4);
22035
+ if (parts.length < 3) {
22036
+ throw new Error(`invalid PRN "${s}": expected format prn:<type>:<ref>[:<path>]`);
22037
+ }
22038
+ if (parts[0] !== 'prn') {
22039
+ throw new Error(`invalid PRN "${s}": must start with 'prn'`);
22040
+ }
22041
+ if (!parts[1]) {
22042
+ throw new Error(`invalid PRN "${s}": type must not be empty`);
22043
+ }
22044
+ if (!parts[2]) {
22045
+ throw new Error(`invalid PRN "${s}": ref must not be empty`);
22046
+ }
22047
+ return new PRN(s);
22048
+ }
22049
+ /**
22050
+ * Constructs a PRN from its constituent parts.
22051
+ * Params are sorted by key for deterministic output.
22052
+ */
22053
+ static create(type, ref, path, params) {
22054
+ let s = `prn:${type}:${ref}`;
22055
+ if (path) {
22056
+ s += `:${path}`;
22057
+ }
22058
+ if (params && Object.keys(params).length > 0) {
22059
+ const sorted = Object.keys(params).sort();
22060
+ const qs = new URLSearchParams();
22061
+ for (const k of sorted) {
22062
+ qs.set(k, params[k]);
22063
+ }
22064
+ s += `?${qs.toString()}`;
22065
+ }
22066
+ return new PRN(s);
22067
+ }
22068
+ _parse() {
22069
+ var _a, _b;
22070
+ const s = this._raw;
22071
+ const parts = splitN(s, ':', 4);
22072
+ const type = (_a = parts[1]) !== null && _a !== void 0 ? _a : '';
22073
+ const ref = (_b = parts[2]) !== null && _b !== void 0 ? _b : '';
22074
+ let path = '';
22075
+ const params = {};
22076
+ if (parts.length === 4 && parts[3]) {
22077
+ const rawPath = parts[3];
22078
+ const qIdx = rawPath.indexOf('?');
22079
+ if (qIdx >= 0) {
22080
+ path = rawPath.slice(0, qIdx);
22081
+ const qs = new URLSearchParams(rawPath.slice(qIdx + 1));
22082
+ qs.forEach((v, k) => {
22083
+ params[k] = v;
22084
+ });
22085
+ }
22086
+ else {
22087
+ path = rawPath;
22088
+ }
22089
+ }
22090
+ return { type, ref, path, params };
22091
+ }
22092
+ /** The resource category — e.g. "component", "integration", "user". */
22093
+ get type() {
22094
+ return this._parse().type;
22095
+ }
22096
+ /** The resource identifier within its type — slug, UUID, name. */
22097
+ get ref() {
22098
+ return this._parse().ref;
22099
+ }
22100
+ /** The resource path segment, or empty string if absent. */
22101
+ get path() {
22102
+ return this._parse().path;
22103
+ }
22104
+ /** All query-string key-value pairs, or empty object if none. */
22105
+ get params() {
22106
+ return this._parse().params;
22107
+ }
22108
+ /** Returns the value for the given query-param key, or empty string if not present. */
22109
+ param(key) {
22110
+ var _a;
22111
+ return (_a = this._parse().params[key]) !== null && _a !== void 0 ? _a : '';
22112
+ }
22113
+ toString() {
22114
+ return this._raw;
22115
+ }
22116
+ }
22117
+ /**
22118
+ * Convenience wrapper around PRN.parse.
22119
+ * Validates a PRN string and returns a PRN instance.
22120
+ * Throws if the string is not a valid PRN.
22121
+ */
22122
+ function parsePRN(s) {
22123
+ return PRN.parse(s);
22124
+ }
22125
+
21976
22126
  // API v0.9
21977
22127
  // Export all API modules for version 0.9
21978
22128
  // This version has specific method signatures and behaviors for v0.9
@@ -21990,6 +22140,7 @@ exports.Integration = Integrations;
21990
22140
  exports.Integrations = Integrations;
21991
22141
  exports.Invoicing = Invoicing;
21992
22142
  exports.Mail = Mail;
22143
+ exports.PRN = PRN;
21993
22144
  exports.Payments = Payments;
21994
22145
  exports.Platform = Platform;
21995
22146
  exports.Project = Project;
@@ -22002,3 +22153,4 @@ exports.Users = Users;
22002
22153
  exports.VPFR = VPFR;
22003
22154
  exports.Workflow = Workflow;
22004
22155
  exports.default = Platform;
22156
+ exports.parsePRN = parsePRN;
@@ -939,6 +939,21 @@ class System extends PlatformBaseClient {
939
939
  }
940
940
 
941
941
  class Workflow extends PlatformBaseClient {
942
+ async create(data) {
943
+ return await this.client.post(`/v1/project/workflow/workflow`, data);
944
+ }
945
+ async update(id, data) {
946
+ return await this.client.patch(`/v1/project/workflow/workflow/${id}`, data);
947
+ }
948
+ async get(id) {
949
+ return await this.client.get(`/v1/project/workflow/workflow/${id}`);
950
+ }
951
+ async list() {
952
+ return await this.client.get(`/v1/project/workflow/workflows`);
953
+ }
954
+ async delete(id) {
955
+ return await this.client.delete(`/v1/project/workflow/workflow/${id}`);
956
+ }
942
957
  async trigger(id, event, data) {
943
958
  return await this.client.post(`/v1/project/workflow/workflow/${id}/event/${event}`, data);
944
959
  }
@@ -2990,10 +3005,18 @@ class Integrations extends IntegrationsBaseClient {
2990
3005
  getEcommerce() {
2991
3006
  return this.getInterfaceOf('protokol-ecommerce');
2992
3007
  }
3008
+ async list() {
3009
+ const { data } = await this.client.get("/v1/integrations");
3010
+ return data;
3011
+ }
2993
3012
  async isInstalled(id) {
2994
3013
  const { data } = await this.client.get("/v1/integrations");
2995
3014
  return data.find((i) => i.id == id) !== undefined;
2996
3015
  }
3016
+ async isActive(id) {
3017
+ const { data } = await this.client.get("/v1/integrations");
3018
+ return data.find((i) => i.id == id && i.status == "active") !== undefined;
3019
+ }
2997
3020
  getInterfaceOf(id) {
2998
3021
  try {
2999
3022
  return this.integrations[id];
@@ -3004,8 +3027,135 @@ class Integrations extends IntegrationsBaseClient {
3004
3027
  }
3005
3028
  }
3006
3029
 
3030
+ // PRN — Protokol Resource Name
3031
+ //
3032
+ // Format:
3033
+ // prn:<type>:<ref>[:<path>][?<query>]
3034
+ //
3035
+ // Examples:
3036
+ // prn:component:my-component:settings.api_key
3037
+ // prn:integration:protokol-ecommerce:company.legal_name?lang=en
3038
+ // prn:user:actor:forge?app=abc123&behalf=user-uuid
3039
+ /**
3040
+ * Splits s on sep into at most n parts, keeping the remainder in the last part.
3041
+ * Mirrors Go's strings.SplitN behaviour.
3042
+ */
3043
+ function splitN(s, sep, n) {
3044
+ const parts = [];
3045
+ let start = 0;
3046
+ for (let i = 1; i < n; i++) {
3047
+ const idx = s.indexOf(sep, start);
3048
+ if (idx === -1)
3049
+ break;
3050
+ parts.push(s.slice(start, idx));
3051
+ start = idx + sep.length;
3052
+ }
3053
+ parts.push(s.slice(start));
3054
+ return parts;
3055
+ }
3056
+ class PRN {
3057
+ constructor(raw) {
3058
+ this._raw = raw;
3059
+ }
3060
+ /**
3061
+ * Validates a PRN string and returns it as a PRN instance.
3062
+ * Throws if the string is not a valid PRN.
3063
+ */
3064
+ static parse(s) {
3065
+ const parts = splitN(s, ':', 4);
3066
+ if (parts.length < 3) {
3067
+ throw new Error(`invalid PRN "${s}": expected format prn:<type>:<ref>[:<path>]`);
3068
+ }
3069
+ if (parts[0] !== 'prn') {
3070
+ throw new Error(`invalid PRN "${s}": must start with 'prn'`);
3071
+ }
3072
+ if (!parts[1]) {
3073
+ throw new Error(`invalid PRN "${s}": type must not be empty`);
3074
+ }
3075
+ if (!parts[2]) {
3076
+ throw new Error(`invalid PRN "${s}": ref must not be empty`);
3077
+ }
3078
+ return new PRN(s);
3079
+ }
3080
+ /**
3081
+ * Constructs a PRN from its constituent parts.
3082
+ * Params are sorted by key for deterministic output.
3083
+ */
3084
+ static create(type, ref, path, params) {
3085
+ let s = `prn:${type}:${ref}`;
3086
+ if (path) {
3087
+ s += `:${path}`;
3088
+ }
3089
+ if (params && Object.keys(params).length > 0) {
3090
+ const sorted = Object.keys(params).sort();
3091
+ const qs = new URLSearchParams();
3092
+ for (const k of sorted) {
3093
+ qs.set(k, params[k]);
3094
+ }
3095
+ s += `?${qs.toString()}`;
3096
+ }
3097
+ return new PRN(s);
3098
+ }
3099
+ _parse() {
3100
+ var _a, _b;
3101
+ const s = this._raw;
3102
+ const parts = splitN(s, ':', 4);
3103
+ const type = (_a = parts[1]) !== null && _a !== void 0 ? _a : '';
3104
+ const ref = (_b = parts[2]) !== null && _b !== void 0 ? _b : '';
3105
+ let path = '';
3106
+ const params = {};
3107
+ if (parts.length === 4 && parts[3]) {
3108
+ const rawPath = parts[3];
3109
+ const qIdx = rawPath.indexOf('?');
3110
+ if (qIdx >= 0) {
3111
+ path = rawPath.slice(0, qIdx);
3112
+ const qs = new URLSearchParams(rawPath.slice(qIdx + 1));
3113
+ qs.forEach((v, k) => {
3114
+ params[k] = v;
3115
+ });
3116
+ }
3117
+ else {
3118
+ path = rawPath;
3119
+ }
3120
+ }
3121
+ return { type, ref, path, params };
3122
+ }
3123
+ /** The resource category — e.g. "component", "integration", "user". */
3124
+ get type() {
3125
+ return this._parse().type;
3126
+ }
3127
+ /** The resource identifier within its type — slug, UUID, name. */
3128
+ get ref() {
3129
+ return this._parse().ref;
3130
+ }
3131
+ /** The resource path segment, or empty string if absent. */
3132
+ get path() {
3133
+ return this._parse().path;
3134
+ }
3135
+ /** All query-string key-value pairs, or empty object if none. */
3136
+ get params() {
3137
+ return this._parse().params;
3138
+ }
3139
+ /** Returns the value for the given query-param key, or empty string if not present. */
3140
+ param(key) {
3141
+ var _a;
3142
+ return (_a = this._parse().params[key]) !== null && _a !== void 0 ? _a : '';
3143
+ }
3144
+ toString() {
3145
+ return this._raw;
3146
+ }
3147
+ }
3148
+ /**
3149
+ * Convenience wrapper around PRN.parse.
3150
+ * Validates a PRN string and returns a PRN instance.
3151
+ * Throws if the string is not a valid PRN.
3152
+ */
3153
+ function parsePRN(s) {
3154
+ return PRN.parse(s);
3155
+ }
3156
+
3007
3157
  // API v0.9
3008
3158
  // Export all API modules for version 0.9
3009
3159
  // This version has specific method signatures and behaviors for v0.9
3010
3160
 
3011
- 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 };
3161
+ export { APIUser, Apps, Component, ComponentUtils, Config, DMS, Ecommerce, Forge, Functions, Integrations as Integration, Integrations, Invoicing, Mail, PRN, Payments, Platform, Project, Ratchet, Sandbox, SerbiaUtil, System, Thunder, Users, VPFR, Workflow, Platform as default, parsePRN };