@ptkl/sdk 1.8.0 → 1.9.2
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/dist/index.0.10.js +137 -0
- package/dist/index.0.9.js +140 -0
- package/dist/package.json +1 -1
- package/dist/v0.10/api/index.d.ts +2 -0
- package/dist/v0.10/api/integrations.d.ts +2 -0
- package/dist/v0.10/index.cjs.js +139 -2
- package/dist/v0.10/index.esm.js +136 -1
- package/dist/v0.10/util/prn.d.ts +38 -0
- package/dist/v0.9/api/component.d.ts +1 -0
- package/dist/v0.9/api/index.d.ts +2 -0
- package/dist/v0.9/api/integrations.d.ts +2 -0
- package/dist/v0.9/index.cjs.js +142 -2
- package/dist/v0.9/index.esm.js +139 -1
- package/dist/v0.9/util/prn.d.ts +38 -0
- package/package.json +1 -1
package/dist/index.0.10.js
CHANGED
|
@@ -3469,10 +3469,18 @@ var ProtokolSDK010 = (function (exports, axios) {
|
|
|
3469
3469
|
getEcommerce() {
|
|
3470
3470
|
return this.getInterfaceOf('protokol-ecommerce');
|
|
3471
3471
|
}
|
|
3472
|
+
async list() {
|
|
3473
|
+
const { data } = await this.client.get("/v1/integrations");
|
|
3474
|
+
return data;
|
|
3475
|
+
}
|
|
3472
3476
|
async isInstalled(id) {
|
|
3473
3477
|
const { data } = await this.client.get("/v1/integrations");
|
|
3474
3478
|
return data.find((i) => i.id == id) !== undefined;
|
|
3475
3479
|
}
|
|
3480
|
+
async isActive(id) {
|
|
3481
|
+
const { data } = await this.client.get("/v1/integrations");
|
|
3482
|
+
return data.find((i) => i.id == id && i.status == "active") !== undefined;
|
|
3483
|
+
}
|
|
3476
3484
|
getInterfaceOf(id) {
|
|
3477
3485
|
try {
|
|
3478
3486
|
return this.integrations[id];
|
|
@@ -3483,6 +3491,133 @@ var ProtokolSDK010 = (function (exports, axios) {
|
|
|
3483
3491
|
}
|
|
3484
3492
|
}
|
|
3485
3493
|
|
|
3494
|
+
// PRN — Protokol Resource Name
|
|
3495
|
+
//
|
|
3496
|
+
// Format:
|
|
3497
|
+
// prn:<type>:<ref>[:<path>][?<query>]
|
|
3498
|
+
//
|
|
3499
|
+
// Examples:
|
|
3500
|
+
// prn:component:my-component:settings.api_key
|
|
3501
|
+
// prn:integration:protokol-ecommerce:company.legal_name?lang=en
|
|
3502
|
+
// prn:user:actor:forge?app=abc123&behalf=user-uuid
|
|
3503
|
+
/**
|
|
3504
|
+
* Splits s on sep into at most n parts, keeping the remainder in the last part.
|
|
3505
|
+
* Mirrors Go's strings.SplitN behaviour.
|
|
3506
|
+
*/
|
|
3507
|
+
function splitN(s, sep, n) {
|
|
3508
|
+
const parts = [];
|
|
3509
|
+
let start = 0;
|
|
3510
|
+
for (let i = 1; i < n; i++) {
|
|
3511
|
+
const idx = s.indexOf(sep, start);
|
|
3512
|
+
if (idx === -1)
|
|
3513
|
+
break;
|
|
3514
|
+
parts.push(s.slice(start, idx));
|
|
3515
|
+
start = idx + sep.length;
|
|
3516
|
+
}
|
|
3517
|
+
parts.push(s.slice(start));
|
|
3518
|
+
return parts;
|
|
3519
|
+
}
|
|
3520
|
+
class PRN {
|
|
3521
|
+
constructor(raw) {
|
|
3522
|
+
this._raw = raw;
|
|
3523
|
+
}
|
|
3524
|
+
/**
|
|
3525
|
+
* Validates a PRN string and returns it as a PRN instance.
|
|
3526
|
+
* Throws if the string is not a valid PRN.
|
|
3527
|
+
*/
|
|
3528
|
+
static parse(s) {
|
|
3529
|
+
const parts = splitN(s, ':', 4);
|
|
3530
|
+
if (parts.length < 3) {
|
|
3531
|
+
throw new Error(`invalid PRN "${s}": expected format prn:<type>:<ref>[:<path>]`);
|
|
3532
|
+
}
|
|
3533
|
+
if (parts[0] !== 'prn') {
|
|
3534
|
+
throw new Error(`invalid PRN "${s}": must start with 'prn'`);
|
|
3535
|
+
}
|
|
3536
|
+
if (!parts[1]) {
|
|
3537
|
+
throw new Error(`invalid PRN "${s}": type must not be empty`);
|
|
3538
|
+
}
|
|
3539
|
+
if (!parts[2]) {
|
|
3540
|
+
throw new Error(`invalid PRN "${s}": ref must not be empty`);
|
|
3541
|
+
}
|
|
3542
|
+
return new PRN(s);
|
|
3543
|
+
}
|
|
3544
|
+
/**
|
|
3545
|
+
* Constructs a PRN from its constituent parts.
|
|
3546
|
+
* Params are sorted by key for deterministic output.
|
|
3547
|
+
*/
|
|
3548
|
+
static create(type, ref, path, params) {
|
|
3549
|
+
let s = `prn:${type}:${ref}`;
|
|
3550
|
+
if (path) {
|
|
3551
|
+
s += `:${path}`;
|
|
3552
|
+
}
|
|
3553
|
+
if (params && Object.keys(params).length > 0) {
|
|
3554
|
+
const sorted = Object.keys(params).sort();
|
|
3555
|
+
const qs = new URLSearchParams();
|
|
3556
|
+
for (const k of sorted) {
|
|
3557
|
+
qs.set(k, params[k]);
|
|
3558
|
+
}
|
|
3559
|
+
s += `?${qs.toString()}`;
|
|
3560
|
+
}
|
|
3561
|
+
return new PRN(s);
|
|
3562
|
+
}
|
|
3563
|
+
_parse() {
|
|
3564
|
+
var _a, _b;
|
|
3565
|
+
const s = this._raw;
|
|
3566
|
+
const parts = splitN(s, ':', 4);
|
|
3567
|
+
const type = (_a = parts[1]) !== null && _a !== void 0 ? _a : '';
|
|
3568
|
+
const ref = (_b = parts[2]) !== null && _b !== void 0 ? _b : '';
|
|
3569
|
+
let path = '';
|
|
3570
|
+
const params = {};
|
|
3571
|
+
if (parts.length === 4 && parts[3]) {
|
|
3572
|
+
const rawPath = parts[3];
|
|
3573
|
+
const qIdx = rawPath.indexOf('?');
|
|
3574
|
+
if (qIdx >= 0) {
|
|
3575
|
+
path = rawPath.slice(0, qIdx);
|
|
3576
|
+
const qs = new URLSearchParams(rawPath.slice(qIdx + 1));
|
|
3577
|
+
qs.forEach((v, k) => {
|
|
3578
|
+
params[k] = v;
|
|
3579
|
+
});
|
|
3580
|
+
}
|
|
3581
|
+
else {
|
|
3582
|
+
path = rawPath;
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
return { type, ref, path, params };
|
|
3586
|
+
}
|
|
3587
|
+
/** The resource category — e.g. "component", "integration", "user". */
|
|
3588
|
+
get type() {
|
|
3589
|
+
return this._parse().type;
|
|
3590
|
+
}
|
|
3591
|
+
/** The resource identifier within its type — slug, UUID, name. */
|
|
3592
|
+
get ref() {
|
|
3593
|
+
return this._parse().ref;
|
|
3594
|
+
}
|
|
3595
|
+
/** The resource path segment, or empty string if absent. */
|
|
3596
|
+
get path() {
|
|
3597
|
+
return this._parse().path;
|
|
3598
|
+
}
|
|
3599
|
+
/** All query-string key-value pairs, or empty object if none. */
|
|
3600
|
+
get params() {
|
|
3601
|
+
return this._parse().params;
|
|
3602
|
+
}
|
|
3603
|
+
/** Returns the value for the given query-param key, or empty string if not present. */
|
|
3604
|
+
param(key) {
|
|
3605
|
+
var _a;
|
|
3606
|
+
return (_a = this._parse().params[key]) !== null && _a !== void 0 ? _a : '';
|
|
3607
|
+
}
|
|
3608
|
+
toString() {
|
|
3609
|
+
return this._raw;
|
|
3610
|
+
}
|
|
3611
|
+
}
|
|
3612
|
+
/**
|
|
3613
|
+
* Convenience wrapper around PRN.parse.
|
|
3614
|
+
* Validates a PRN string and returns a PRN instance.
|
|
3615
|
+
* Throws if the string is not a valid PRN.
|
|
3616
|
+
*/
|
|
3617
|
+
function parsePRN(s) {
|
|
3618
|
+
return PRN.parse(s);
|
|
3619
|
+
}
|
|
3620
|
+
|
|
3486
3621
|
class Invoicing extends PlatformBaseClient {
|
|
3487
3622
|
async getSalesInvoices(provider, page) {
|
|
3488
3623
|
return await this.request("GET", `invoices/${provider}/sales`, {
|
|
@@ -3522,6 +3657,7 @@ var ProtokolSDK010 = (function (exports, axios) {
|
|
|
3522
3657
|
exports.Invoicing = Invoicing;
|
|
3523
3658
|
exports.Mail = Mail;
|
|
3524
3659
|
exports.NBS = NBS;
|
|
3660
|
+
exports.PRN = PRN;
|
|
3525
3661
|
exports.Payments = Payments;
|
|
3526
3662
|
exports.Platform = Platform;
|
|
3527
3663
|
exports.Project = Project;
|
|
@@ -3533,6 +3669,7 @@ var ProtokolSDK010 = (function (exports, axios) {
|
|
|
3533
3669
|
exports.Users = Users;
|
|
3534
3670
|
exports.VPFR = VPFR;
|
|
3535
3671
|
exports.Workflow = Workflow;
|
|
3672
|
+
exports.parsePRN = parsePRN;
|
|
3536
3673
|
|
|
3537
3674
|
return exports;
|
|
3538
3675
|
|
package/dist/index.0.9.js
CHANGED
|
@@ -372,6 +372,9 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
372
372
|
async settings() {
|
|
373
373
|
return await this.client.get(`/v3/system/component/settings/${this.ref}`);
|
|
374
374
|
}
|
|
375
|
+
async settingsForVersion(version) {
|
|
376
|
+
return await this.client.get(`/v3/system/component/settings/${this.ref}/${version}`);
|
|
377
|
+
}
|
|
375
378
|
async saveSettings(settings, version) {
|
|
376
379
|
return await this.client.post(`/v3/system/component/settings/${this.ref}/${version}`, settings);
|
|
377
380
|
}
|
|
@@ -3006,10 +3009,18 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
3006
3009
|
getEcommerce() {
|
|
3007
3010
|
return this.getInterfaceOf('protokol-ecommerce');
|
|
3008
3011
|
}
|
|
3012
|
+
async list() {
|
|
3013
|
+
const { data } = await this.client.get("/v1/integrations");
|
|
3014
|
+
return data;
|
|
3015
|
+
}
|
|
3009
3016
|
async isInstalled(id) {
|
|
3010
3017
|
const { data } = await this.client.get("/v1/integrations");
|
|
3011
3018
|
return data.find((i) => i.id == id) !== undefined;
|
|
3012
3019
|
}
|
|
3020
|
+
async isActive(id) {
|
|
3021
|
+
const { data } = await this.client.get("/v1/integrations");
|
|
3022
|
+
return data.find((i) => i.id == id && i.status == "active") !== undefined;
|
|
3023
|
+
}
|
|
3013
3024
|
getInterfaceOf(id) {
|
|
3014
3025
|
try {
|
|
3015
3026
|
return this.integrations[id];
|
|
@@ -3020,6 +3031,133 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
3020
3031
|
}
|
|
3021
3032
|
}
|
|
3022
3033
|
|
|
3034
|
+
// PRN — Protokol Resource Name
|
|
3035
|
+
//
|
|
3036
|
+
// Format:
|
|
3037
|
+
// prn:<type>:<ref>[:<path>][?<query>]
|
|
3038
|
+
//
|
|
3039
|
+
// Examples:
|
|
3040
|
+
// prn:component:my-component:settings.api_key
|
|
3041
|
+
// prn:integration:protokol-ecommerce:company.legal_name?lang=en
|
|
3042
|
+
// prn:user:actor:forge?app=abc123&behalf=user-uuid
|
|
3043
|
+
/**
|
|
3044
|
+
* Splits s on sep into at most n parts, keeping the remainder in the last part.
|
|
3045
|
+
* Mirrors Go's strings.SplitN behaviour.
|
|
3046
|
+
*/
|
|
3047
|
+
function splitN(s, sep, n) {
|
|
3048
|
+
const parts = [];
|
|
3049
|
+
let start = 0;
|
|
3050
|
+
for (let i = 1; i < n; i++) {
|
|
3051
|
+
const idx = s.indexOf(sep, start);
|
|
3052
|
+
if (idx === -1)
|
|
3053
|
+
break;
|
|
3054
|
+
parts.push(s.slice(start, idx));
|
|
3055
|
+
start = idx + sep.length;
|
|
3056
|
+
}
|
|
3057
|
+
parts.push(s.slice(start));
|
|
3058
|
+
return parts;
|
|
3059
|
+
}
|
|
3060
|
+
class PRN {
|
|
3061
|
+
constructor(raw) {
|
|
3062
|
+
this._raw = raw;
|
|
3063
|
+
}
|
|
3064
|
+
/**
|
|
3065
|
+
* Validates a PRN string and returns it as a PRN instance.
|
|
3066
|
+
* Throws if the string is not a valid PRN.
|
|
3067
|
+
*/
|
|
3068
|
+
static parse(s) {
|
|
3069
|
+
const parts = splitN(s, ':', 4);
|
|
3070
|
+
if (parts.length < 3) {
|
|
3071
|
+
throw new Error(`invalid PRN "${s}": expected format prn:<type>:<ref>[:<path>]`);
|
|
3072
|
+
}
|
|
3073
|
+
if (parts[0] !== 'prn') {
|
|
3074
|
+
throw new Error(`invalid PRN "${s}": must start with 'prn'`);
|
|
3075
|
+
}
|
|
3076
|
+
if (!parts[1]) {
|
|
3077
|
+
throw new Error(`invalid PRN "${s}": type must not be empty`);
|
|
3078
|
+
}
|
|
3079
|
+
if (!parts[2]) {
|
|
3080
|
+
throw new Error(`invalid PRN "${s}": ref must not be empty`);
|
|
3081
|
+
}
|
|
3082
|
+
return new PRN(s);
|
|
3083
|
+
}
|
|
3084
|
+
/**
|
|
3085
|
+
* Constructs a PRN from its constituent parts.
|
|
3086
|
+
* Params are sorted by key for deterministic output.
|
|
3087
|
+
*/
|
|
3088
|
+
static create(type, ref, path, params) {
|
|
3089
|
+
let s = `prn:${type}:${ref}`;
|
|
3090
|
+
if (path) {
|
|
3091
|
+
s += `:${path}`;
|
|
3092
|
+
}
|
|
3093
|
+
if (params && Object.keys(params).length > 0) {
|
|
3094
|
+
const sorted = Object.keys(params).sort();
|
|
3095
|
+
const qs = new URLSearchParams();
|
|
3096
|
+
for (const k of sorted) {
|
|
3097
|
+
qs.set(k, params[k]);
|
|
3098
|
+
}
|
|
3099
|
+
s += `?${qs.toString()}`;
|
|
3100
|
+
}
|
|
3101
|
+
return new PRN(s);
|
|
3102
|
+
}
|
|
3103
|
+
_parse() {
|
|
3104
|
+
var _a, _b;
|
|
3105
|
+
const s = this._raw;
|
|
3106
|
+
const parts = splitN(s, ':', 4);
|
|
3107
|
+
const type = (_a = parts[1]) !== null && _a !== void 0 ? _a : '';
|
|
3108
|
+
const ref = (_b = parts[2]) !== null && _b !== void 0 ? _b : '';
|
|
3109
|
+
let path = '';
|
|
3110
|
+
const params = {};
|
|
3111
|
+
if (parts.length === 4 && parts[3]) {
|
|
3112
|
+
const rawPath = parts[3];
|
|
3113
|
+
const qIdx = rawPath.indexOf('?');
|
|
3114
|
+
if (qIdx >= 0) {
|
|
3115
|
+
path = rawPath.slice(0, qIdx);
|
|
3116
|
+
const qs = new URLSearchParams(rawPath.slice(qIdx + 1));
|
|
3117
|
+
qs.forEach((v, k) => {
|
|
3118
|
+
params[k] = v;
|
|
3119
|
+
});
|
|
3120
|
+
}
|
|
3121
|
+
else {
|
|
3122
|
+
path = rawPath;
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
return { type, ref, path, params };
|
|
3126
|
+
}
|
|
3127
|
+
/** The resource category — e.g. "component", "integration", "user". */
|
|
3128
|
+
get type() {
|
|
3129
|
+
return this._parse().type;
|
|
3130
|
+
}
|
|
3131
|
+
/** The resource identifier within its type — slug, UUID, name. */
|
|
3132
|
+
get ref() {
|
|
3133
|
+
return this._parse().ref;
|
|
3134
|
+
}
|
|
3135
|
+
/** The resource path segment, or empty string if absent. */
|
|
3136
|
+
get path() {
|
|
3137
|
+
return this._parse().path;
|
|
3138
|
+
}
|
|
3139
|
+
/** All query-string key-value pairs, or empty object if none. */
|
|
3140
|
+
get params() {
|
|
3141
|
+
return this._parse().params;
|
|
3142
|
+
}
|
|
3143
|
+
/** Returns the value for the given query-param key, or empty string if not present. */
|
|
3144
|
+
param(key) {
|
|
3145
|
+
var _a;
|
|
3146
|
+
return (_a = this._parse().params[key]) !== null && _a !== void 0 ? _a : '';
|
|
3147
|
+
}
|
|
3148
|
+
toString() {
|
|
3149
|
+
return this._raw;
|
|
3150
|
+
}
|
|
3151
|
+
}
|
|
3152
|
+
/**
|
|
3153
|
+
* Convenience wrapper around PRN.parse.
|
|
3154
|
+
* Validates a PRN string and returns a PRN instance.
|
|
3155
|
+
* Throws if the string is not a valid PRN.
|
|
3156
|
+
*/
|
|
3157
|
+
function parsePRN(s) {
|
|
3158
|
+
return PRN.parse(s);
|
|
3159
|
+
}
|
|
3160
|
+
|
|
3023
3161
|
// API v0.9
|
|
3024
3162
|
// Export all API modules for version 0.9
|
|
3025
3163
|
// This version has specific method signatures and behaviors for v0.9
|
|
@@ -3037,6 +3175,7 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
3037
3175
|
exports.Integrations = Integrations;
|
|
3038
3176
|
exports.Invoicing = Invoicing;
|
|
3039
3177
|
exports.Mail = Mail;
|
|
3178
|
+
exports.PRN = PRN;
|
|
3040
3179
|
exports.Payments = Payments;
|
|
3041
3180
|
exports.Platform = Platform;
|
|
3042
3181
|
exports.Project = Project;
|
|
@@ -3049,6 +3188,7 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
3049
3188
|
exports.VPFR = VPFR;
|
|
3050
3189
|
exports.Workflow = Workflow;
|
|
3051
3190
|
exports.default = Platform;
|
|
3191
|
+
exports.parsePRN = parsePRN;
|
|
3052
3192
|
|
|
3053
3193
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3054
3194
|
|
package/dist/package.json
CHANGED
|
@@ -18,6 +18,8 @@ export { default as Project } from './project';
|
|
|
18
18
|
export { default as Config } from './config';
|
|
19
19
|
export { default as Integrations } from './integrations';
|
|
20
20
|
export { default as Integration } from './integrations';
|
|
21
|
+
export { PRN, parsePRN } from '../util/prn';
|
|
22
|
+
export type { ParsedPRN } from '../util/prn';
|
|
21
23
|
export { default as Payments } from './integrations/payments';
|
|
22
24
|
export { default as Invoicing } from './integrations/invoicing';
|
|
23
25
|
export { default as DMS } from './integrations/dms';
|
|
@@ -22,6 +22,8 @@ export default class Integrations extends IntegrationsBaseClient {
|
|
|
22
22
|
getNBS(): NBS;
|
|
23
23
|
getSerbiaMinFin(): MinFin;
|
|
24
24
|
getEcommerce(): Ecommerce;
|
|
25
|
+
list(): Promise<any>;
|
|
25
26
|
isInstalled(id: string): Promise<boolean>;
|
|
27
|
+
isActive(id: string): Promise<boolean>;
|
|
26
28
|
getInterfaceOf(id: string): any;
|
|
27
29
|
}
|
package/dist/v0.10/index.cjs.js
CHANGED
|
@@ -14618,7 +14618,7 @@ var transitionalDefaults = {
|
|
|
14618
14618
|
clarifyTimeoutError: false
|
|
14619
14619
|
};
|
|
14620
14620
|
|
|
14621
|
-
var URLSearchParams = require$$0$1.URLSearchParams;
|
|
14621
|
+
var URLSearchParams$1 = require$$0$1.URLSearchParams;
|
|
14622
14622
|
|
|
14623
14623
|
const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
|
|
14624
14624
|
|
|
@@ -14646,7 +14646,7 @@ const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
|
|
|
14646
14646
|
var platform$1 = {
|
|
14647
14647
|
isNode: true,
|
|
14648
14648
|
classes: {
|
|
14649
|
-
URLSearchParams,
|
|
14649
|
+
URLSearchParams: URLSearchParams$1,
|
|
14650
14650
|
FormData: FormData$1,
|
|
14651
14651
|
Blob: typeof Blob !== 'undefined' && Blob || null
|
|
14652
14652
|
},
|
|
@@ -22435,10 +22435,18 @@ class Integrations extends IntegrationsBaseClient {
|
|
|
22435
22435
|
getEcommerce() {
|
|
22436
22436
|
return this.getInterfaceOf('protokol-ecommerce');
|
|
22437
22437
|
}
|
|
22438
|
+
async list() {
|
|
22439
|
+
const { data } = await this.client.get("/v1/integrations");
|
|
22440
|
+
return data;
|
|
22441
|
+
}
|
|
22438
22442
|
async isInstalled(id) {
|
|
22439
22443
|
const { data } = await this.client.get("/v1/integrations");
|
|
22440
22444
|
return data.find((i) => i.id == id) !== undefined;
|
|
22441
22445
|
}
|
|
22446
|
+
async isActive(id) {
|
|
22447
|
+
const { data } = await this.client.get("/v1/integrations");
|
|
22448
|
+
return data.find((i) => i.id == id && i.status == "active") !== undefined;
|
|
22449
|
+
}
|
|
22442
22450
|
getInterfaceOf(id) {
|
|
22443
22451
|
try {
|
|
22444
22452
|
return this.integrations[id];
|
|
@@ -22449,6 +22457,133 @@ class Integrations extends IntegrationsBaseClient {
|
|
|
22449
22457
|
}
|
|
22450
22458
|
}
|
|
22451
22459
|
|
|
22460
|
+
// PRN — Protokol Resource Name
|
|
22461
|
+
//
|
|
22462
|
+
// Format:
|
|
22463
|
+
// prn:<type>:<ref>[:<path>][?<query>]
|
|
22464
|
+
//
|
|
22465
|
+
// Examples:
|
|
22466
|
+
// prn:component:my-component:settings.api_key
|
|
22467
|
+
// prn:integration:protokol-ecommerce:company.legal_name?lang=en
|
|
22468
|
+
// prn:user:actor:forge?app=abc123&behalf=user-uuid
|
|
22469
|
+
/**
|
|
22470
|
+
* Splits s on sep into at most n parts, keeping the remainder in the last part.
|
|
22471
|
+
* Mirrors Go's strings.SplitN behaviour.
|
|
22472
|
+
*/
|
|
22473
|
+
function splitN(s, sep, n) {
|
|
22474
|
+
const parts = [];
|
|
22475
|
+
let start = 0;
|
|
22476
|
+
for (let i = 1; i < n; i++) {
|
|
22477
|
+
const idx = s.indexOf(sep, start);
|
|
22478
|
+
if (idx === -1)
|
|
22479
|
+
break;
|
|
22480
|
+
parts.push(s.slice(start, idx));
|
|
22481
|
+
start = idx + sep.length;
|
|
22482
|
+
}
|
|
22483
|
+
parts.push(s.slice(start));
|
|
22484
|
+
return parts;
|
|
22485
|
+
}
|
|
22486
|
+
class PRN {
|
|
22487
|
+
constructor(raw) {
|
|
22488
|
+
this._raw = raw;
|
|
22489
|
+
}
|
|
22490
|
+
/**
|
|
22491
|
+
* Validates a PRN string and returns it as a PRN instance.
|
|
22492
|
+
* Throws if the string is not a valid PRN.
|
|
22493
|
+
*/
|
|
22494
|
+
static parse(s) {
|
|
22495
|
+
const parts = splitN(s, ':', 4);
|
|
22496
|
+
if (parts.length < 3) {
|
|
22497
|
+
throw new Error(`invalid PRN "${s}": expected format prn:<type>:<ref>[:<path>]`);
|
|
22498
|
+
}
|
|
22499
|
+
if (parts[0] !== 'prn') {
|
|
22500
|
+
throw new Error(`invalid PRN "${s}": must start with 'prn'`);
|
|
22501
|
+
}
|
|
22502
|
+
if (!parts[1]) {
|
|
22503
|
+
throw new Error(`invalid PRN "${s}": type must not be empty`);
|
|
22504
|
+
}
|
|
22505
|
+
if (!parts[2]) {
|
|
22506
|
+
throw new Error(`invalid PRN "${s}": ref must not be empty`);
|
|
22507
|
+
}
|
|
22508
|
+
return new PRN(s);
|
|
22509
|
+
}
|
|
22510
|
+
/**
|
|
22511
|
+
* Constructs a PRN from its constituent parts.
|
|
22512
|
+
* Params are sorted by key for deterministic output.
|
|
22513
|
+
*/
|
|
22514
|
+
static create(type, ref, path, params) {
|
|
22515
|
+
let s = `prn:${type}:${ref}`;
|
|
22516
|
+
if (path) {
|
|
22517
|
+
s += `:${path}`;
|
|
22518
|
+
}
|
|
22519
|
+
if (params && Object.keys(params).length > 0) {
|
|
22520
|
+
const sorted = Object.keys(params).sort();
|
|
22521
|
+
const qs = new URLSearchParams();
|
|
22522
|
+
for (const k of sorted) {
|
|
22523
|
+
qs.set(k, params[k]);
|
|
22524
|
+
}
|
|
22525
|
+
s += `?${qs.toString()}`;
|
|
22526
|
+
}
|
|
22527
|
+
return new PRN(s);
|
|
22528
|
+
}
|
|
22529
|
+
_parse() {
|
|
22530
|
+
var _a, _b;
|
|
22531
|
+
const s = this._raw;
|
|
22532
|
+
const parts = splitN(s, ':', 4);
|
|
22533
|
+
const type = (_a = parts[1]) !== null && _a !== void 0 ? _a : '';
|
|
22534
|
+
const ref = (_b = parts[2]) !== null && _b !== void 0 ? _b : '';
|
|
22535
|
+
let path = '';
|
|
22536
|
+
const params = {};
|
|
22537
|
+
if (parts.length === 4 && parts[3]) {
|
|
22538
|
+
const rawPath = parts[3];
|
|
22539
|
+
const qIdx = rawPath.indexOf('?');
|
|
22540
|
+
if (qIdx >= 0) {
|
|
22541
|
+
path = rawPath.slice(0, qIdx);
|
|
22542
|
+
const qs = new URLSearchParams(rawPath.slice(qIdx + 1));
|
|
22543
|
+
qs.forEach((v, k) => {
|
|
22544
|
+
params[k] = v;
|
|
22545
|
+
});
|
|
22546
|
+
}
|
|
22547
|
+
else {
|
|
22548
|
+
path = rawPath;
|
|
22549
|
+
}
|
|
22550
|
+
}
|
|
22551
|
+
return { type, ref, path, params };
|
|
22552
|
+
}
|
|
22553
|
+
/** The resource category — e.g. "component", "integration", "user". */
|
|
22554
|
+
get type() {
|
|
22555
|
+
return this._parse().type;
|
|
22556
|
+
}
|
|
22557
|
+
/** The resource identifier within its type — slug, UUID, name. */
|
|
22558
|
+
get ref() {
|
|
22559
|
+
return this._parse().ref;
|
|
22560
|
+
}
|
|
22561
|
+
/** The resource path segment, or empty string if absent. */
|
|
22562
|
+
get path() {
|
|
22563
|
+
return this._parse().path;
|
|
22564
|
+
}
|
|
22565
|
+
/** All query-string key-value pairs, or empty object if none. */
|
|
22566
|
+
get params() {
|
|
22567
|
+
return this._parse().params;
|
|
22568
|
+
}
|
|
22569
|
+
/** Returns the value for the given query-param key, or empty string if not present. */
|
|
22570
|
+
param(key) {
|
|
22571
|
+
var _a;
|
|
22572
|
+
return (_a = this._parse().params[key]) !== null && _a !== void 0 ? _a : '';
|
|
22573
|
+
}
|
|
22574
|
+
toString() {
|
|
22575
|
+
return this._raw;
|
|
22576
|
+
}
|
|
22577
|
+
}
|
|
22578
|
+
/**
|
|
22579
|
+
* Convenience wrapper around PRN.parse.
|
|
22580
|
+
* Validates a PRN string and returns a PRN instance.
|
|
22581
|
+
* Throws if the string is not a valid PRN.
|
|
22582
|
+
*/
|
|
22583
|
+
function parsePRN(s) {
|
|
22584
|
+
return PRN.parse(s);
|
|
22585
|
+
}
|
|
22586
|
+
|
|
22452
22587
|
class Invoicing extends PlatformBaseClient {
|
|
22453
22588
|
async getSalesInvoices(provider, page) {
|
|
22454
22589
|
return await this.request("GET", `invoices/${provider}/sales`, {
|
|
@@ -22488,6 +22623,7 @@ exports.Integrations = Integrations;
|
|
|
22488
22623
|
exports.Invoicing = Invoicing;
|
|
22489
22624
|
exports.Mail = Mail;
|
|
22490
22625
|
exports.NBS = NBS;
|
|
22626
|
+
exports.PRN = PRN;
|
|
22491
22627
|
exports.Payments = Payments;
|
|
22492
22628
|
exports.Platform = Platform;
|
|
22493
22629
|
exports.Project = Project;
|
|
@@ -22499,3 +22635,4 @@ exports.Thunder = Thunder;
|
|
|
22499
22635
|
exports.Users = Users;
|
|
22500
22636
|
exports.VPFR = VPFR;
|
|
22501
22637
|
exports.Workflow = Workflow;
|
|
22638
|
+
exports.parsePRN = parsePRN;
|
package/dist/v0.10/index.esm.js
CHANGED
|
@@ -3468,10 +3468,18 @@ class Integrations extends IntegrationsBaseClient {
|
|
|
3468
3468
|
getEcommerce() {
|
|
3469
3469
|
return this.getInterfaceOf('protokol-ecommerce');
|
|
3470
3470
|
}
|
|
3471
|
+
async list() {
|
|
3472
|
+
const { data } = await this.client.get("/v1/integrations");
|
|
3473
|
+
return data;
|
|
3474
|
+
}
|
|
3471
3475
|
async isInstalled(id) {
|
|
3472
3476
|
const { data } = await this.client.get("/v1/integrations");
|
|
3473
3477
|
return data.find((i) => i.id == id) !== undefined;
|
|
3474
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
|
+
}
|
|
3475
3483
|
getInterfaceOf(id) {
|
|
3476
3484
|
try {
|
|
3477
3485
|
return this.integrations[id];
|
|
@@ -3482,6 +3490,133 @@ class Integrations extends IntegrationsBaseClient {
|
|
|
3482
3490
|
}
|
|
3483
3491
|
}
|
|
3484
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
|
+
|
|
3485
3620
|
class Invoicing extends PlatformBaseClient {
|
|
3486
3621
|
async getSalesInvoices(provider, page) {
|
|
3487
3622
|
return await this.request("GET", `invoices/${provider}/sales`, {
|
|
@@ -3507,4 +3642,4 @@ class Invoicing extends PlatformBaseClient {
|
|
|
3507
3642
|
}
|
|
3508
3643
|
}
|
|
3509
3644
|
|
|
3510
|
-
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,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;
|
|
@@ -121,6 +121,7 @@ export default class Component extends PlatformBaseClient {
|
|
|
121
121
|
*/
|
|
122
122
|
aggregate(pipeline: FindAggregateParams): AggregateChainable;
|
|
123
123
|
settings(): Promise<AxiosResponse<any, any>>;
|
|
124
|
+
settingsForVersion(version: string): Promise<AxiosResponse<any, any>>;
|
|
124
125
|
saveSettings(settings: any, version: string): Promise<AxiosResponse<any, any>>;
|
|
125
126
|
saveTemplatesDist(version: string, sdkVersion: string, engine: string, dist: Record<string, string>): Promise<any>;
|
|
126
127
|
workflow(event: string, input: any): Promise<AxiosResponse<any, any>>;
|
package/dist/v0.9/api/index.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export { default as Project } from './project';
|
|
|
17
17
|
export { default as Config } from './config';
|
|
18
18
|
export { default as Integrations } from './integrations';
|
|
19
19
|
export { default as Integration } from './integrations';
|
|
20
|
+
export { PRN, parsePRN } from '../util/prn';
|
|
21
|
+
export type { ParsedPRN } from '../util/prn';
|
|
20
22
|
export { default as Payments } from './integrations/payments';
|
|
21
23
|
export { default as Invoicing } from './integrations/invoicing';
|
|
22
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
|
}
|
package/dist/v0.9/index.cjs.js
CHANGED
|
@@ -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
|
},
|
|
@@ -19340,6 +19340,9 @@ class Component extends PlatformBaseClient {
|
|
|
19340
19340
|
async settings() {
|
|
19341
19341
|
return await this.client.get(`/v3/system/component/settings/${this.ref}`);
|
|
19342
19342
|
}
|
|
19343
|
+
async settingsForVersion(version) {
|
|
19344
|
+
return await this.client.get(`/v3/system/component/settings/${this.ref}/${version}`);
|
|
19345
|
+
}
|
|
19343
19346
|
async saveSettings(settings, version) {
|
|
19344
19347
|
return await this.client.post(`/v3/system/component/settings/${this.ref}/${version}`, settings);
|
|
19345
19348
|
}
|
|
@@ -21974,10 +21977,18 @@ class Integrations extends IntegrationsBaseClient {
|
|
|
21974
21977
|
getEcommerce() {
|
|
21975
21978
|
return this.getInterfaceOf('protokol-ecommerce');
|
|
21976
21979
|
}
|
|
21980
|
+
async list() {
|
|
21981
|
+
const { data } = await this.client.get("/v1/integrations");
|
|
21982
|
+
return data;
|
|
21983
|
+
}
|
|
21977
21984
|
async isInstalled(id) {
|
|
21978
21985
|
const { data } = await this.client.get("/v1/integrations");
|
|
21979
21986
|
return data.find((i) => i.id == id) !== undefined;
|
|
21980
21987
|
}
|
|
21988
|
+
async isActive(id) {
|
|
21989
|
+
const { data } = await this.client.get("/v1/integrations");
|
|
21990
|
+
return data.find((i) => i.id == id && i.status == "active") !== undefined;
|
|
21991
|
+
}
|
|
21981
21992
|
getInterfaceOf(id) {
|
|
21982
21993
|
try {
|
|
21983
21994
|
return this.integrations[id];
|
|
@@ -21988,6 +21999,133 @@ class Integrations extends IntegrationsBaseClient {
|
|
|
21988
21999
|
}
|
|
21989
22000
|
}
|
|
21990
22001
|
|
|
22002
|
+
// PRN — Protokol Resource Name
|
|
22003
|
+
//
|
|
22004
|
+
// Format:
|
|
22005
|
+
// prn:<type>:<ref>[:<path>][?<query>]
|
|
22006
|
+
//
|
|
22007
|
+
// Examples:
|
|
22008
|
+
// prn:component:my-component:settings.api_key
|
|
22009
|
+
// prn:integration:protokol-ecommerce:company.legal_name?lang=en
|
|
22010
|
+
// prn:user:actor:forge?app=abc123&behalf=user-uuid
|
|
22011
|
+
/**
|
|
22012
|
+
* Splits s on sep into at most n parts, keeping the remainder in the last part.
|
|
22013
|
+
* Mirrors Go's strings.SplitN behaviour.
|
|
22014
|
+
*/
|
|
22015
|
+
function splitN(s, sep, n) {
|
|
22016
|
+
const parts = [];
|
|
22017
|
+
let start = 0;
|
|
22018
|
+
for (let i = 1; i < n; i++) {
|
|
22019
|
+
const idx = s.indexOf(sep, start);
|
|
22020
|
+
if (idx === -1)
|
|
22021
|
+
break;
|
|
22022
|
+
parts.push(s.slice(start, idx));
|
|
22023
|
+
start = idx + sep.length;
|
|
22024
|
+
}
|
|
22025
|
+
parts.push(s.slice(start));
|
|
22026
|
+
return parts;
|
|
22027
|
+
}
|
|
22028
|
+
class PRN {
|
|
22029
|
+
constructor(raw) {
|
|
22030
|
+
this._raw = raw;
|
|
22031
|
+
}
|
|
22032
|
+
/**
|
|
22033
|
+
* Validates a PRN string and returns it as a PRN instance.
|
|
22034
|
+
* Throws if the string is not a valid PRN.
|
|
22035
|
+
*/
|
|
22036
|
+
static parse(s) {
|
|
22037
|
+
const parts = splitN(s, ':', 4);
|
|
22038
|
+
if (parts.length < 3) {
|
|
22039
|
+
throw new Error(`invalid PRN "${s}": expected format prn:<type>:<ref>[:<path>]`);
|
|
22040
|
+
}
|
|
22041
|
+
if (parts[0] !== 'prn') {
|
|
22042
|
+
throw new Error(`invalid PRN "${s}": must start with 'prn'`);
|
|
22043
|
+
}
|
|
22044
|
+
if (!parts[1]) {
|
|
22045
|
+
throw new Error(`invalid PRN "${s}": type must not be empty`);
|
|
22046
|
+
}
|
|
22047
|
+
if (!parts[2]) {
|
|
22048
|
+
throw new Error(`invalid PRN "${s}": ref must not be empty`);
|
|
22049
|
+
}
|
|
22050
|
+
return new PRN(s);
|
|
22051
|
+
}
|
|
22052
|
+
/**
|
|
22053
|
+
* Constructs a PRN from its constituent parts.
|
|
22054
|
+
* Params are sorted by key for deterministic output.
|
|
22055
|
+
*/
|
|
22056
|
+
static create(type, ref, path, params) {
|
|
22057
|
+
let s = `prn:${type}:${ref}`;
|
|
22058
|
+
if (path) {
|
|
22059
|
+
s += `:${path}`;
|
|
22060
|
+
}
|
|
22061
|
+
if (params && Object.keys(params).length > 0) {
|
|
22062
|
+
const sorted = Object.keys(params).sort();
|
|
22063
|
+
const qs = new URLSearchParams();
|
|
22064
|
+
for (const k of sorted) {
|
|
22065
|
+
qs.set(k, params[k]);
|
|
22066
|
+
}
|
|
22067
|
+
s += `?${qs.toString()}`;
|
|
22068
|
+
}
|
|
22069
|
+
return new PRN(s);
|
|
22070
|
+
}
|
|
22071
|
+
_parse() {
|
|
22072
|
+
var _a, _b;
|
|
22073
|
+
const s = this._raw;
|
|
22074
|
+
const parts = splitN(s, ':', 4);
|
|
22075
|
+
const type = (_a = parts[1]) !== null && _a !== void 0 ? _a : '';
|
|
22076
|
+
const ref = (_b = parts[2]) !== null && _b !== void 0 ? _b : '';
|
|
22077
|
+
let path = '';
|
|
22078
|
+
const params = {};
|
|
22079
|
+
if (parts.length === 4 && parts[3]) {
|
|
22080
|
+
const rawPath = parts[3];
|
|
22081
|
+
const qIdx = rawPath.indexOf('?');
|
|
22082
|
+
if (qIdx >= 0) {
|
|
22083
|
+
path = rawPath.slice(0, qIdx);
|
|
22084
|
+
const qs = new URLSearchParams(rawPath.slice(qIdx + 1));
|
|
22085
|
+
qs.forEach((v, k) => {
|
|
22086
|
+
params[k] = v;
|
|
22087
|
+
});
|
|
22088
|
+
}
|
|
22089
|
+
else {
|
|
22090
|
+
path = rawPath;
|
|
22091
|
+
}
|
|
22092
|
+
}
|
|
22093
|
+
return { type, ref, path, params };
|
|
22094
|
+
}
|
|
22095
|
+
/** The resource category — e.g. "component", "integration", "user". */
|
|
22096
|
+
get type() {
|
|
22097
|
+
return this._parse().type;
|
|
22098
|
+
}
|
|
22099
|
+
/** The resource identifier within its type — slug, UUID, name. */
|
|
22100
|
+
get ref() {
|
|
22101
|
+
return this._parse().ref;
|
|
22102
|
+
}
|
|
22103
|
+
/** The resource path segment, or empty string if absent. */
|
|
22104
|
+
get path() {
|
|
22105
|
+
return this._parse().path;
|
|
22106
|
+
}
|
|
22107
|
+
/** All query-string key-value pairs, or empty object if none. */
|
|
22108
|
+
get params() {
|
|
22109
|
+
return this._parse().params;
|
|
22110
|
+
}
|
|
22111
|
+
/** Returns the value for the given query-param key, or empty string if not present. */
|
|
22112
|
+
param(key) {
|
|
22113
|
+
var _a;
|
|
22114
|
+
return (_a = this._parse().params[key]) !== null && _a !== void 0 ? _a : '';
|
|
22115
|
+
}
|
|
22116
|
+
toString() {
|
|
22117
|
+
return this._raw;
|
|
22118
|
+
}
|
|
22119
|
+
}
|
|
22120
|
+
/**
|
|
22121
|
+
* Convenience wrapper around PRN.parse.
|
|
22122
|
+
* Validates a PRN string and returns a PRN instance.
|
|
22123
|
+
* Throws if the string is not a valid PRN.
|
|
22124
|
+
*/
|
|
22125
|
+
function parsePRN(s) {
|
|
22126
|
+
return PRN.parse(s);
|
|
22127
|
+
}
|
|
22128
|
+
|
|
21991
22129
|
// API v0.9
|
|
21992
22130
|
// Export all API modules for version 0.9
|
|
21993
22131
|
// This version has specific method signatures and behaviors for v0.9
|
|
@@ -22005,6 +22143,7 @@ exports.Integration = Integrations;
|
|
|
22005
22143
|
exports.Integrations = Integrations;
|
|
22006
22144
|
exports.Invoicing = Invoicing;
|
|
22007
22145
|
exports.Mail = Mail;
|
|
22146
|
+
exports.PRN = PRN;
|
|
22008
22147
|
exports.Payments = Payments;
|
|
22009
22148
|
exports.Platform = Platform;
|
|
22010
22149
|
exports.Project = Project;
|
|
@@ -22017,3 +22156,4 @@ exports.Users = Users;
|
|
|
22017
22156
|
exports.VPFR = VPFR;
|
|
22018
22157
|
exports.Workflow = Workflow;
|
|
22019
22158
|
exports.default = Platform;
|
|
22159
|
+
exports.parsePRN = parsePRN;
|
package/dist/v0.9/index.esm.js
CHANGED
|
@@ -371,6 +371,9 @@ class Component extends PlatformBaseClient {
|
|
|
371
371
|
async settings() {
|
|
372
372
|
return await this.client.get(`/v3/system/component/settings/${this.ref}`);
|
|
373
373
|
}
|
|
374
|
+
async settingsForVersion(version) {
|
|
375
|
+
return await this.client.get(`/v3/system/component/settings/${this.ref}/${version}`);
|
|
376
|
+
}
|
|
374
377
|
async saveSettings(settings, version) {
|
|
375
378
|
return await this.client.post(`/v3/system/component/settings/${this.ref}/${version}`, settings);
|
|
376
379
|
}
|
|
@@ -3005,10 +3008,18 @@ class Integrations extends IntegrationsBaseClient {
|
|
|
3005
3008
|
getEcommerce() {
|
|
3006
3009
|
return this.getInterfaceOf('protokol-ecommerce');
|
|
3007
3010
|
}
|
|
3011
|
+
async list() {
|
|
3012
|
+
const { data } = await this.client.get("/v1/integrations");
|
|
3013
|
+
return data;
|
|
3014
|
+
}
|
|
3008
3015
|
async isInstalled(id) {
|
|
3009
3016
|
const { data } = await this.client.get("/v1/integrations");
|
|
3010
3017
|
return data.find((i) => i.id == id) !== undefined;
|
|
3011
3018
|
}
|
|
3019
|
+
async isActive(id) {
|
|
3020
|
+
const { data } = await this.client.get("/v1/integrations");
|
|
3021
|
+
return data.find((i) => i.id == id && i.status == "active") !== undefined;
|
|
3022
|
+
}
|
|
3012
3023
|
getInterfaceOf(id) {
|
|
3013
3024
|
try {
|
|
3014
3025
|
return this.integrations[id];
|
|
@@ -3019,8 +3030,135 @@ class Integrations extends IntegrationsBaseClient {
|
|
|
3019
3030
|
}
|
|
3020
3031
|
}
|
|
3021
3032
|
|
|
3033
|
+
// PRN — Protokol Resource Name
|
|
3034
|
+
//
|
|
3035
|
+
// Format:
|
|
3036
|
+
// prn:<type>:<ref>[:<path>][?<query>]
|
|
3037
|
+
//
|
|
3038
|
+
// Examples:
|
|
3039
|
+
// prn:component:my-component:settings.api_key
|
|
3040
|
+
// prn:integration:protokol-ecommerce:company.legal_name?lang=en
|
|
3041
|
+
// prn:user:actor:forge?app=abc123&behalf=user-uuid
|
|
3042
|
+
/**
|
|
3043
|
+
* Splits s on sep into at most n parts, keeping the remainder in the last part.
|
|
3044
|
+
* Mirrors Go's strings.SplitN behaviour.
|
|
3045
|
+
*/
|
|
3046
|
+
function splitN(s, sep, n) {
|
|
3047
|
+
const parts = [];
|
|
3048
|
+
let start = 0;
|
|
3049
|
+
for (let i = 1; i < n; i++) {
|
|
3050
|
+
const idx = s.indexOf(sep, start);
|
|
3051
|
+
if (idx === -1)
|
|
3052
|
+
break;
|
|
3053
|
+
parts.push(s.slice(start, idx));
|
|
3054
|
+
start = idx + sep.length;
|
|
3055
|
+
}
|
|
3056
|
+
parts.push(s.slice(start));
|
|
3057
|
+
return parts;
|
|
3058
|
+
}
|
|
3059
|
+
class PRN {
|
|
3060
|
+
constructor(raw) {
|
|
3061
|
+
this._raw = raw;
|
|
3062
|
+
}
|
|
3063
|
+
/**
|
|
3064
|
+
* Validates a PRN string and returns it as a PRN instance.
|
|
3065
|
+
* Throws if the string is not a valid PRN.
|
|
3066
|
+
*/
|
|
3067
|
+
static parse(s) {
|
|
3068
|
+
const parts = splitN(s, ':', 4);
|
|
3069
|
+
if (parts.length < 3) {
|
|
3070
|
+
throw new Error(`invalid PRN "${s}": expected format prn:<type>:<ref>[:<path>]`);
|
|
3071
|
+
}
|
|
3072
|
+
if (parts[0] !== 'prn') {
|
|
3073
|
+
throw new Error(`invalid PRN "${s}": must start with 'prn'`);
|
|
3074
|
+
}
|
|
3075
|
+
if (!parts[1]) {
|
|
3076
|
+
throw new Error(`invalid PRN "${s}": type must not be empty`);
|
|
3077
|
+
}
|
|
3078
|
+
if (!parts[2]) {
|
|
3079
|
+
throw new Error(`invalid PRN "${s}": ref must not be empty`);
|
|
3080
|
+
}
|
|
3081
|
+
return new PRN(s);
|
|
3082
|
+
}
|
|
3083
|
+
/**
|
|
3084
|
+
* Constructs a PRN from its constituent parts.
|
|
3085
|
+
* Params are sorted by key for deterministic output.
|
|
3086
|
+
*/
|
|
3087
|
+
static create(type, ref, path, params) {
|
|
3088
|
+
let s = `prn:${type}:${ref}`;
|
|
3089
|
+
if (path) {
|
|
3090
|
+
s += `:${path}`;
|
|
3091
|
+
}
|
|
3092
|
+
if (params && Object.keys(params).length > 0) {
|
|
3093
|
+
const sorted = Object.keys(params).sort();
|
|
3094
|
+
const qs = new URLSearchParams();
|
|
3095
|
+
for (const k of sorted) {
|
|
3096
|
+
qs.set(k, params[k]);
|
|
3097
|
+
}
|
|
3098
|
+
s += `?${qs.toString()}`;
|
|
3099
|
+
}
|
|
3100
|
+
return new PRN(s);
|
|
3101
|
+
}
|
|
3102
|
+
_parse() {
|
|
3103
|
+
var _a, _b;
|
|
3104
|
+
const s = this._raw;
|
|
3105
|
+
const parts = splitN(s, ':', 4);
|
|
3106
|
+
const type = (_a = parts[1]) !== null && _a !== void 0 ? _a : '';
|
|
3107
|
+
const ref = (_b = parts[2]) !== null && _b !== void 0 ? _b : '';
|
|
3108
|
+
let path = '';
|
|
3109
|
+
const params = {};
|
|
3110
|
+
if (parts.length === 4 && parts[3]) {
|
|
3111
|
+
const rawPath = parts[3];
|
|
3112
|
+
const qIdx = rawPath.indexOf('?');
|
|
3113
|
+
if (qIdx >= 0) {
|
|
3114
|
+
path = rawPath.slice(0, qIdx);
|
|
3115
|
+
const qs = new URLSearchParams(rawPath.slice(qIdx + 1));
|
|
3116
|
+
qs.forEach((v, k) => {
|
|
3117
|
+
params[k] = v;
|
|
3118
|
+
});
|
|
3119
|
+
}
|
|
3120
|
+
else {
|
|
3121
|
+
path = rawPath;
|
|
3122
|
+
}
|
|
3123
|
+
}
|
|
3124
|
+
return { type, ref, path, params };
|
|
3125
|
+
}
|
|
3126
|
+
/** The resource category — e.g. "component", "integration", "user". */
|
|
3127
|
+
get type() {
|
|
3128
|
+
return this._parse().type;
|
|
3129
|
+
}
|
|
3130
|
+
/** The resource identifier within its type — slug, UUID, name. */
|
|
3131
|
+
get ref() {
|
|
3132
|
+
return this._parse().ref;
|
|
3133
|
+
}
|
|
3134
|
+
/** The resource path segment, or empty string if absent. */
|
|
3135
|
+
get path() {
|
|
3136
|
+
return this._parse().path;
|
|
3137
|
+
}
|
|
3138
|
+
/** All query-string key-value pairs, or empty object if none. */
|
|
3139
|
+
get params() {
|
|
3140
|
+
return this._parse().params;
|
|
3141
|
+
}
|
|
3142
|
+
/** Returns the value for the given query-param key, or empty string if not present. */
|
|
3143
|
+
param(key) {
|
|
3144
|
+
var _a;
|
|
3145
|
+
return (_a = this._parse().params[key]) !== null && _a !== void 0 ? _a : '';
|
|
3146
|
+
}
|
|
3147
|
+
toString() {
|
|
3148
|
+
return this._raw;
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
/**
|
|
3152
|
+
* Convenience wrapper around PRN.parse.
|
|
3153
|
+
* Validates a PRN string and returns a PRN instance.
|
|
3154
|
+
* Throws if the string is not a valid PRN.
|
|
3155
|
+
*/
|
|
3156
|
+
function parsePRN(s) {
|
|
3157
|
+
return PRN.parse(s);
|
|
3158
|
+
}
|
|
3159
|
+
|
|
3022
3160
|
// API v0.9
|
|
3023
3161
|
// Export all API modules for version 0.9
|
|
3024
3162
|
// This version has specific method signatures and behaviors for v0.9
|
|
3025
3163
|
|
|
3026
|
-
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 };
|
|
3164
|
+
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 };
|
|
@@ -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;
|