@vivoa/plugin-sdk 0.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.
package/dist/index.js ADDED
@@ -0,0 +1,563 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ ActionVariant: () => ActionVariant,
24
+ BlockType: () => BlockType,
25
+ CapabilityKind: () => CapabilityKind,
26
+ CodFeeType: () => CodFeeType,
27
+ ConfigScope: () => ConfigScope,
28
+ FieldType: () => FieldType,
29
+ FieldVariant: () => FieldVariant,
30
+ GatewayEnvironment: () => GatewayEnvironment,
31
+ LayoutMode: () => LayoutMode,
32
+ MessageVariant: () => MessageVariant,
33
+ PAYMENT_PLUGIN_TOKEN: () => PAYMENT_PLUGIN_TOKEN,
34
+ PluginType: () => PluginType,
35
+ RepeaterSource: () => RepeaterSource,
36
+ SDK_VERSION: () => SDK_VERSION,
37
+ SHIPPING_PLUGIN_TOKEN: () => SHIPPING_PLUGIN_TOKEN,
38
+ ShippingFeature: () => ShippingFeature,
39
+ StepStatusFrom: () => StepStatusFrom,
40
+ TransactionStatus: () => TransactionStatus,
41
+ capability: () => capability,
42
+ checkPermissions: () => checkPermissions,
43
+ createPluginConfig: () => createPluginConfig,
44
+ crossValidateSetupLayout: () => crossValidateSetupLayout,
45
+ definePlugin: () => definePlugin,
46
+ field: () => field,
47
+ isConfigurablePlugin: () => isConfigurablePlugin,
48
+ isPermissionGranted: () => isPermissionGranted,
49
+ isPluginFactory: () => isPluginFactory,
50
+ isSdkCompatible: () => isSdkCompatible,
51
+ parsePermission: () => parsePermission,
52
+ paymentCapability: () => paymentCapability,
53
+ shippingCapability: () => shippingCapability,
54
+ validateSetupLayout: () => validateSetupLayout
55
+ });
56
+ module.exports = __toCommonJS(index_exports);
57
+
58
+ // src/tokens.ts
59
+ var PAYMENT_PLUGIN_TOKEN = "PAYMENT_PLUGINS";
60
+ var SHIPPING_PLUGIN_TOKEN = "SHIPPING_PLUGINS";
61
+
62
+ // src/plugin.ts
63
+ var PluginType = /* @__PURE__ */ ((PluginType2) => {
64
+ PluginType2["Payment"] = "payment";
65
+ PluginType2["Shipping"] = "shipping";
66
+ PluginType2["Analytics"] = "analytics";
67
+ PluginType2["Generic"] = "generic";
68
+ return PluginType2;
69
+ })(PluginType || {});
70
+ var MessageVariant = /* @__PURE__ */ ((MessageVariant2) => {
71
+ MessageVariant2["Info"] = "info";
72
+ MessageVariant2["Warning"] = "warning";
73
+ MessageVariant2["Success"] = "success";
74
+ MessageVariant2["Danger"] = "danger";
75
+ return MessageVariant2;
76
+ })(MessageVariant || {});
77
+ function isConfigurablePlugin(plugin) {
78
+ return typeof plugin === "object" && plugin !== null && "loadConfig" in plugin && typeof plugin.loadConfig === "function";
79
+ }
80
+
81
+ // src/config.ts
82
+ var FieldType = /* @__PURE__ */ ((FieldType2) => {
83
+ FieldType2["String"] = "string";
84
+ FieldType2["Password"] = "password";
85
+ FieldType2["Url"] = "url";
86
+ FieldType2["Number"] = "number";
87
+ FieldType2["Boolean"] = "boolean";
88
+ FieldType2["Select"] = "select";
89
+ return FieldType2;
90
+ })(FieldType || {});
91
+ var ConfigScope = /* @__PURE__ */ ((ConfigScope2) => {
92
+ ConfigScope2["Global"] = "global";
93
+ ConfigScope2["Country"] = "country";
94
+ return ConfigScope2;
95
+ })(ConfigScope || {});
96
+
97
+ // src/config-schema.ts
98
+ var import_superstruct = require("superstruct");
99
+ function field(def) {
100
+ return { required: true, ...def };
101
+ }
102
+ function normalizeDependsOn(dep) {
103
+ if (!dep) return void 0;
104
+ return {
105
+ field: dep.field,
106
+ value: Array.isArray(dep.value) ? dep.value : [dep.value]
107
+ };
108
+ }
109
+ function buildStructForField(def) {
110
+ let base;
111
+ if (def.options) {
112
+ base = (0, import_superstruct.enums)(def.options.map((o) => o.value));
113
+ } else if (def.type === "boolean" /* Boolean */) {
114
+ base = (0, import_superstruct.boolean)();
115
+ } else if (def.type === "number" /* Number */) {
116
+ base = (0, import_superstruct.number)();
117
+ } else {
118
+ base = (0, import_superstruct.string)();
119
+ }
120
+ return def.required ? base : (0, import_superstruct.optional)(base);
121
+ }
122
+ function createPluginConfig(fields) {
123
+ const shape = {};
124
+ const configFields = [];
125
+ for (const [key, def] of Object.entries(fields)) {
126
+ shape[key] = buildStructForField(def);
127
+ configFields.push({
128
+ key,
129
+ label: def.label,
130
+ type: def.type,
131
+ required: def.required ?? true,
132
+ scopedTo: def.scopedTo,
133
+ dependsOn: normalizeDependsOn(def.dependsOn),
134
+ placeholder: def.placeholder,
135
+ description: def.description,
136
+ options: def.options,
137
+ internal: def.internal,
138
+ group: def.group
139
+ });
140
+ }
141
+ const schema = (0, import_superstruct.type)(shape);
142
+ return {
143
+ configFields,
144
+ validate: (data) => {
145
+ const [error, result] = (0, import_superstruct.validate)(data, schema);
146
+ if (error) {
147
+ const messages = error.failures().map((f) => {
148
+ const path = f.path.join(".");
149
+ return path ? `${path}: ${f.message}` : f.message;
150
+ });
151
+ return { success: false, errors: messages };
152
+ }
153
+ return { success: true, data: result };
154
+ }
155
+ };
156
+ }
157
+
158
+ // src/payment.ts
159
+ var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
160
+ TransactionStatus2["Pending"] = "Pending";
161
+ TransactionStatus2["PendingRedirect"] = "Pending_Redirect";
162
+ TransactionStatus2["Approved"] = "Approved";
163
+ TransactionStatus2["Declined"] = "Declined";
164
+ TransactionStatus2["Failed"] = "Failed";
165
+ TransactionStatus2["Error"] = "Error";
166
+ return TransactionStatus2;
167
+ })(TransactionStatus || {});
168
+ var GatewayEnvironment = /* @__PURE__ */ ((GatewayEnvironment2) => {
169
+ GatewayEnvironment2["Sandbox"] = "sandbox";
170
+ GatewayEnvironment2["Production"] = "production";
171
+ return GatewayEnvironment2;
172
+ })(GatewayEnvironment || {});
173
+
174
+ // src/shipping.ts
175
+ var ShippingFeature = /* @__PURE__ */ ((ShippingFeature2) => {
176
+ ShippingFeature2["Tracking"] = "tracking";
177
+ ShippingFeature2["Cod"] = "cod";
178
+ ShippingFeature2["Quotes"] = "quotes";
179
+ ShippingFeature2["Labels"] = "labels";
180
+ return ShippingFeature2;
181
+ })(ShippingFeature || {});
182
+ var CodFeeType = /* @__PURE__ */ ((CodFeeType2) => {
183
+ CodFeeType2["Percentage"] = "percentage";
184
+ CodFeeType2["Fixed"] = "fixed";
185
+ return CodFeeType2;
186
+ })(CodFeeType || {});
187
+
188
+ // src/setup-layout.ts
189
+ var import_superstruct2 = require("superstruct");
190
+ var FieldVariant = /* @__PURE__ */ ((FieldVariant2) => {
191
+ FieldVariant2["Text"] = "text";
192
+ FieldVariant2["Secret"] = "secret";
193
+ FieldVariant2["Url"] = "url";
194
+ FieldVariant2["Number"] = "number";
195
+ FieldVariant2["Select"] = "select";
196
+ FieldVariant2["Textarea"] = "textarea";
197
+ FieldVariant2["Segmented"] = "segmented";
198
+ return FieldVariant2;
199
+ })(FieldVariant || {});
200
+ var ActionVariant = /* @__PURE__ */ ((ActionVariant2) => {
201
+ ActionVariant2["Primary"] = "primary";
202
+ ActionVariant2["Secondary"] = "secondary";
203
+ ActionVariant2["Danger"] = "danger";
204
+ return ActionVariant2;
205
+ })(ActionVariant || {});
206
+ var RepeaterSource = /* @__PURE__ */ ((RepeaterSource2) => {
207
+ RepeaterSource2["SupportedCountries"] = "supportedCountries";
208
+ return RepeaterSource2;
209
+ })(RepeaterSource || {});
210
+ var LayoutMode = /* @__PURE__ */ ((LayoutMode2) => {
211
+ LayoutMode2["Wizard"] = "wizard";
212
+ LayoutMode2["Stacked"] = "stacked";
213
+ LayoutMode2["Tabs"] = "tabs";
214
+ LayoutMode2["Sections"] = "sections";
215
+ return LayoutMode2;
216
+ })(LayoutMode || {});
217
+ var BlockType = /* @__PURE__ */ ((BlockType2) => {
218
+ BlockType2["Field"] = "field";
219
+ BlockType2["Group"] = "group";
220
+ BlockType2["Toggle"] = "toggle";
221
+ BlockType2["Action"] = "action";
222
+ BlockType2["Callout"] = "callout";
223
+ BlockType2["Markdown"] = "markdown";
224
+ BlockType2["Divider"] = "divider";
225
+ BlockType2["Conditional"] = "conditional";
226
+ BlockType2["Repeater"] = "repeater";
227
+ BlockType2["Card"] = "card";
228
+ BlockType2["Banner"] = "banner";
229
+ BlockType2["CopyField"] = "copyField";
230
+ BlockType2["InlineRow"] = "inlineRow";
231
+ BlockType2["Tabs"] = "tabs";
232
+ BlockType2["Accordion"] = "accordion";
233
+ BlockType2["KeyValue"] = "keyValue";
234
+ return BlockType2;
235
+ })(BlockType || {});
236
+ var StepStatusFrom = /* @__PURE__ */ ((StepStatusFrom2) => {
237
+ StepStatusFrom2["Fields"] = "fields";
238
+ StepStatusFrom2["Action"] = "action";
239
+ return StepStatusFrom2;
240
+ })(StepStatusFrom || {});
241
+ var sFieldVariant = (0, import_superstruct2.enums)(Object.values(FieldVariant));
242
+ var sActionVariant = (0, import_superstruct2.enums)(Object.values(ActionVariant));
243
+ var sRepeaterSource = (0, import_superstruct2.enums)(Object.values(RepeaterSource));
244
+ var sMessageVariant = (0, import_superstruct2.enums)(Object.values(MessageVariant));
245
+ var sSpan = (0, import_superstruct2.optional)((0, import_superstruct2.number)());
246
+ var sFieldBlock = (0, import_superstruct2.object)({
247
+ type: (0, import_superstruct2.literal)("field" /* Field */),
248
+ key: (0, import_superstruct2.string)(),
249
+ variant: (0, import_superstruct2.optional)(sFieldVariant),
250
+ labelOverride: (0, import_superstruct2.optional)((0, import_superstruct2.string)()),
251
+ optionsFrom: (0, import_superstruct2.optional)((0, import_superstruct2.string)()),
252
+ span: sSpan
253
+ });
254
+ var sGroupBlock = (0, import_superstruct2.object)({
255
+ type: (0, import_superstruct2.literal)("group" /* Group */),
256
+ title: (0, import_superstruct2.string)(),
257
+ description: (0, import_superstruct2.optional)((0, import_superstruct2.string)()),
258
+ fields: (0, import_superstruct2.array)((0, import_superstruct2.string)()),
259
+ collapsible: (0, import_superstruct2.optional)((0, import_superstruct2.boolean)()),
260
+ defaultOpen: (0, import_superstruct2.optional)((0, import_superstruct2.boolean)()),
261
+ span: sSpan
262
+ });
263
+ var sToggleBlock = (0, import_superstruct2.object)({
264
+ type: (0, import_superstruct2.literal)("toggle" /* Toggle */),
265
+ key: (0, import_superstruct2.string)(),
266
+ label: (0, import_superstruct2.string)(),
267
+ description: (0, import_superstruct2.optional)((0, import_superstruct2.string)()),
268
+ span: sSpan
269
+ });
270
+ var sActionBlock = (0, import_superstruct2.object)({
271
+ type: (0, import_superstruct2.literal)("action" /* Action */),
272
+ id: (0, import_superstruct2.string)(),
273
+ label: (0, import_superstruct2.string)(),
274
+ variant: (0, import_superstruct2.optional)(sActionVariant),
275
+ resultSlot: (0, import_superstruct2.optional)((0, import_superstruct2.string)()),
276
+ span: sSpan
277
+ });
278
+ var sCalloutBlock = (0, import_superstruct2.object)({
279
+ type: (0, import_superstruct2.literal)("callout" /* Callout */),
280
+ variant: sMessageVariant,
281
+ text: (0, import_superstruct2.string)(),
282
+ slot: (0, import_superstruct2.optional)((0, import_superstruct2.string)()),
283
+ span: sSpan
284
+ });
285
+ var sMarkdownBlock = (0, import_superstruct2.object)({
286
+ type: (0, import_superstruct2.literal)("markdown" /* Markdown */),
287
+ content: (0, import_superstruct2.string)(),
288
+ span: sSpan
289
+ });
290
+ var sDividerBlock = (0, import_superstruct2.object)({ type: (0, import_superstruct2.literal)("divider" /* Divider */), span: sSpan });
291
+ var sConditionalBlock = (0, import_superstruct2.object)({
292
+ type: (0, import_superstruct2.literal)("conditional" /* Conditional */),
293
+ when: (0, import_superstruct2.object)({ key: (0, import_superstruct2.string)(), equals: (0, import_superstruct2.unknown)() }),
294
+ blocks: (0, import_superstruct2.array)((0, import_superstruct2.lazy)(() => sBlock)),
295
+ span: sSpan
296
+ });
297
+ var sRepeaterBlock = (0, import_superstruct2.object)({
298
+ type: (0, import_superstruct2.literal)("repeater" /* Repeater */),
299
+ source: sRepeaterSource,
300
+ blocks: (0, import_superstruct2.array)((0, import_superstruct2.lazy)(() => sBlock)),
301
+ span: sSpan
302
+ });
303
+ var sCardBlock = (0, import_superstruct2.object)({
304
+ type: (0, import_superstruct2.literal)("card" /* Card */),
305
+ title: (0, import_superstruct2.optional)((0, import_superstruct2.string)()),
306
+ description: (0, import_superstruct2.optional)((0, import_superstruct2.string)()),
307
+ blocks: (0, import_superstruct2.array)((0, import_superstruct2.lazy)(() => sBlock)),
308
+ span: sSpan
309
+ });
310
+ var sBannerBlock = (0, import_superstruct2.object)({
311
+ type: (0, import_superstruct2.literal)("banner" /* Banner */),
312
+ variant: sMessageVariant,
313
+ title: (0, import_superstruct2.optional)((0, import_superstruct2.string)()),
314
+ text: (0, import_superstruct2.string)(),
315
+ span: sSpan
316
+ });
317
+ var sCopyFieldBlock = (0, import_superstruct2.object)({
318
+ type: (0, import_superstruct2.literal)("copyField" /* CopyField */),
319
+ label: (0, import_superstruct2.string)(),
320
+ value: (0, import_superstruct2.optional)((0, import_superstruct2.string)()),
321
+ computedKey: (0, import_superstruct2.optional)((0, import_superstruct2.string)()),
322
+ fieldKey: (0, import_superstruct2.optional)((0, import_superstruct2.string)()),
323
+ span: sSpan
324
+ });
325
+ var sInlineRowBlock = (0, import_superstruct2.object)({
326
+ type: (0, import_superstruct2.literal)("inlineRow" /* InlineRow */),
327
+ blocks: (0, import_superstruct2.array)((0, import_superstruct2.lazy)(() => sBlock)),
328
+ span: sSpan
329
+ });
330
+ var sTabsBlock = (0, import_superstruct2.object)({
331
+ type: (0, import_superstruct2.literal)("tabs" /* Tabs */),
332
+ tabs: (0, import_superstruct2.array)(
333
+ (0, import_superstruct2.object)({
334
+ id: (0, import_superstruct2.string)(),
335
+ label: (0, import_superstruct2.string)(),
336
+ blocks: (0, import_superstruct2.array)((0, import_superstruct2.lazy)(() => sBlock))
337
+ })
338
+ ),
339
+ span: sSpan
340
+ });
341
+ var sAccordionBlock = (0, import_superstruct2.object)({
342
+ type: (0, import_superstruct2.literal)("accordion" /* Accordion */),
343
+ sections: (0, import_superstruct2.array)(
344
+ (0, import_superstruct2.object)({
345
+ id: (0, import_superstruct2.string)(),
346
+ title: (0, import_superstruct2.string)(),
347
+ defaultOpen: (0, import_superstruct2.optional)((0, import_superstruct2.boolean)()),
348
+ blocks: (0, import_superstruct2.array)((0, import_superstruct2.lazy)(() => sBlock))
349
+ })
350
+ ),
351
+ span: sSpan
352
+ });
353
+ var sKeyValueBlock = (0, import_superstruct2.object)({
354
+ type: (0, import_superstruct2.literal)("keyValue" /* KeyValue */),
355
+ rows: (0, import_superstruct2.array)(
356
+ (0, import_superstruct2.object)({
357
+ label: (0, import_superstruct2.string)(),
358
+ value: (0, import_superstruct2.optional)((0, import_superstruct2.string)()),
359
+ computedKey: (0, import_superstruct2.optional)((0, import_superstruct2.string)())
360
+ })
361
+ ),
362
+ span: sSpan
363
+ });
364
+ var sBlock = (0, import_superstruct2.union)([
365
+ sFieldBlock,
366
+ sGroupBlock,
367
+ sToggleBlock,
368
+ sActionBlock,
369
+ sCalloutBlock,
370
+ sMarkdownBlock,
371
+ sDividerBlock,
372
+ sConditionalBlock,
373
+ sRepeaterBlock,
374
+ sCardBlock,
375
+ sBannerBlock,
376
+ sCopyFieldBlock,
377
+ sInlineRowBlock,
378
+ sTabsBlock,
379
+ sAccordionBlock,
380
+ sKeyValueBlock
381
+ ]);
382
+ var sStep = (0, import_superstruct2.object)({
383
+ id: (0, import_superstruct2.string)(),
384
+ title: (0, import_superstruct2.string)(),
385
+ intro: (0, import_superstruct2.optional)((0, import_superstruct2.string)()),
386
+ blocks: (0, import_superstruct2.array)(sBlock),
387
+ repeatFor: (0, import_superstruct2.optional)(sRepeaterSource),
388
+ status: (0, import_superstruct2.optional)(
389
+ (0, import_superstruct2.union)([
390
+ (0, import_superstruct2.object)({ from: (0, import_superstruct2.literal)("fields" /* Fields */) }),
391
+ (0, import_superstruct2.object)({ from: (0, import_superstruct2.literal)("action" /* Action */), actionId: (0, import_superstruct2.string)() })
392
+ ])
393
+ )
394
+ });
395
+ var sAction = (0, import_superstruct2.object)({
396
+ id: (0, import_superstruct2.string)(),
397
+ label: (0, import_superstruct2.optional)((0, import_superstruct2.string)()),
398
+ perCountry: (0, import_superstruct2.optional)((0, import_superstruct2.boolean)())
399
+ });
400
+ var sSetupLayout = (0, import_superstruct2.object)({
401
+ customScreen: (0, import_superstruct2.optional)((0, import_superstruct2.string)()),
402
+ mode: (0, import_superstruct2.optional)((0, import_superstruct2.enums)(Object.values(LayoutMode))),
403
+ intro: (0, import_superstruct2.optional)((0, import_superstruct2.string)()),
404
+ steps: (0, import_superstruct2.array)(sStep),
405
+ actions: (0, import_superstruct2.optional)((0, import_superstruct2.array)(sAction))
406
+ });
407
+ function validateSetupLayout(input) {
408
+ const [error, result] = (0, import_superstruct2.validate)(input, sSetupLayout);
409
+ if (error) {
410
+ return {
411
+ success: false,
412
+ errors: error.failures().map((f) => {
413
+ const path = f.path.join(".");
414
+ return path ? `${path}: ${f.message}` : f.message;
415
+ })
416
+ };
417
+ }
418
+ return { success: true, data: result };
419
+ }
420
+ function crossValidateSetupLayout(layout, configSchema) {
421
+ const errors = [];
422
+ const knownKeys = new Set(configSchema.map((f) => f.key));
423
+ const knownActions = new Set((layout.actions ?? []).map((a) => a.id));
424
+ const walk = (blocks, path) => {
425
+ blocks.forEach((b, i) => {
426
+ const here = `${path}[${i}]`;
427
+ if (b.type === "field" /* Field */ && !knownKeys.has(b.key)) {
428
+ errors.push(`${here}.key: "${b.key}" not in configSchema`);
429
+ } else if (b.type === "group" /* Group */) {
430
+ b.fields.forEach((k, j) => {
431
+ if (!knownKeys.has(k)) {
432
+ errors.push(`${here}.fields[${j}]: "${k}" not in configSchema`);
433
+ }
434
+ });
435
+ } else if (b.type === "action" /* Action */ && knownActions.size > 0) {
436
+ if (!knownActions.has(b.id)) {
437
+ errors.push(`${here}.id: action "${b.id}" not declared`);
438
+ }
439
+ } else if (b.type === "conditional" /* Conditional */ || b.type === "repeater" /* Repeater */ || b.type === "card" /* Card */ || b.type === "inlineRow" /* InlineRow */) {
440
+ walk(b.blocks, `${here}.blocks`);
441
+ } else if (b.type === "tabs" /* Tabs */) {
442
+ b.tabs.forEach((t, j) => walk(t.blocks, `${here}.tabs[${j}].blocks`));
443
+ } else if (b.type === "accordion" /* Accordion */) {
444
+ b.sections.forEach(
445
+ (s, j) => walk(s.blocks, `${here}.sections[${j}].blocks`)
446
+ );
447
+ }
448
+ });
449
+ };
450
+ layout.steps.forEach((s, i) => walk(s.blocks, `steps[${i}].blocks`));
451
+ return errors;
452
+ }
453
+
454
+ // src/capability.ts
455
+ var CapabilityKind = {
456
+ Payment: "payment",
457
+ Shipping: "shipping",
458
+ Analytics: "analytics"
459
+ };
460
+ function capability(kind, impl) {
461
+ return { kind, impl };
462
+ }
463
+ function paymentCapability(impl) {
464
+ return { kind: CapabilityKind.Payment, impl };
465
+ }
466
+ function shippingCapability(impl) {
467
+ return { kind: CapabilityKind.Shipping, impl };
468
+ }
469
+ var PLUGIN_FACTORY_BRAND = /* @__PURE__ */ Symbol.for("vivoa.plugin.factory");
470
+ function definePlugin(factory) {
471
+ Object.defineProperty(factory, PLUGIN_FACTORY_BRAND, {
472
+ value: true,
473
+ enumerable: false
474
+ });
475
+ return factory;
476
+ }
477
+ function isPluginFactory(value) {
478
+ return typeof value === "function" && value[PLUGIN_FACTORY_BRAND] === true;
479
+ }
480
+
481
+ // src/permissions.ts
482
+ var PERMISSION_RE = /^([a-z0-9]+)\.([a-z0-9]+)(?::(.+))?$/i;
483
+ function parsePermission(raw) {
484
+ const m = PERMISSION_RE.exec(raw);
485
+ if (!m) return null;
486
+ const [, domain, action, resource] = m;
487
+ return resource === void 0 ? { domain, action } : { domain, action, resource };
488
+ }
489
+ function isPermissionGranted(required, granted) {
490
+ return granted.some((g) => {
491
+ if (g.domain !== required.domain || g.action !== required.action) {
492
+ return false;
493
+ }
494
+ if (required.resource === void 0) return true;
495
+ return g.resource === "*" || g.resource === required.resource;
496
+ });
497
+ }
498
+ function checkPermissions(required, grantedRaw) {
499
+ const grantedParsed = grantedRaw.map(parsePermission).filter((p) => p !== null);
500
+ const granted = [];
501
+ const missing = [];
502
+ for (const raw of required) {
503
+ const parsed = parsePermission(raw);
504
+ if (parsed && isPermissionGranted(parsed, grantedParsed)) {
505
+ granted.push(raw);
506
+ } else {
507
+ missing.push(raw);
508
+ }
509
+ }
510
+ return { ok: missing.length === 0, granted, missing };
511
+ }
512
+
513
+ // src/version.ts
514
+ var SDK_VERSION = "0.5.0";
515
+ function isSdkCompatible(pluginSdkVersion, hostSdkVersion) {
516
+ const parse = (v) => {
517
+ const m = /^(\d+)\.(\d+)\.(\d+)/.exec(v);
518
+ return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
519
+ };
520
+ const p = parse(pluginSdkVersion);
521
+ const h = parse(hostSdkVersion);
522
+ if (!p || !h) return false;
523
+ if (p[0] !== h[0]) return false;
524
+ if (p[0] === 0) {
525
+ return p[1] === h[1] && h[2] >= p[2];
526
+ }
527
+ return h[1] > p[1] || h[1] === p[1] && h[2] >= p[2];
528
+ }
529
+ // Annotate the CommonJS export names for ESM import in node:
530
+ 0 && (module.exports = {
531
+ ActionVariant,
532
+ BlockType,
533
+ CapabilityKind,
534
+ CodFeeType,
535
+ ConfigScope,
536
+ FieldType,
537
+ FieldVariant,
538
+ GatewayEnvironment,
539
+ LayoutMode,
540
+ MessageVariant,
541
+ PAYMENT_PLUGIN_TOKEN,
542
+ PluginType,
543
+ RepeaterSource,
544
+ SDK_VERSION,
545
+ SHIPPING_PLUGIN_TOKEN,
546
+ ShippingFeature,
547
+ StepStatusFrom,
548
+ TransactionStatus,
549
+ capability,
550
+ checkPermissions,
551
+ createPluginConfig,
552
+ crossValidateSetupLayout,
553
+ definePlugin,
554
+ field,
555
+ isConfigurablePlugin,
556
+ isPermissionGranted,
557
+ isPluginFactory,
558
+ isSdkCompatible,
559
+ parsePermission,
560
+ paymentCapability,
561
+ shippingCapability,
562
+ validateSetupLayout
563
+ });