@gorgo/medusa-integration 0.0.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.
- package/.medusa/server/src/admin/index.js +2259 -0
- package/.medusa/server/src/admin/index.mjs +2257 -0
- package/.medusa/server/src/api/admin/integrations/[provider_id]/enable/route.d.ts +5 -0
- package/.medusa/server/src/api/admin/integrations/[provider_id]/enable/route.js +17 -0
- package/.medusa/server/src/api/admin/integrations/[provider_id]/route.d.ts +7 -0
- package/.medusa/server/src/api/admin/integrations/[provider_id]/route.js +46 -0
- package/.medusa/server/src/api/admin/integrations/[provider_id]/test-connection/route.d.ts +3 -0
- package/.medusa/server/src/api/admin/integrations/[provider_id]/test-connection/route.js +16 -0
- package/.medusa/server/src/api/admin/integrations/_helpers.d.ts +16 -0
- package/.medusa/server/src/api/admin/integrations/_helpers.js +52 -0
- package/.medusa/server/src/api/admin/integrations/middlewares.d.ts +2 -0
- package/.medusa/server/src/api/admin/integrations/middlewares.js +21 -0
- package/.medusa/server/src/api/admin/integrations/route.d.ts +3 -0
- package/.medusa/server/src/api/admin/integrations/route.js +11 -0
- package/.medusa/server/src/api/admin/integrations/validators.d.ts +11 -0
- package/.medusa/server/src/api/admin/integrations/validators.js +15 -0
- package/.medusa/server/src/api/middlewares.d.ts +2 -0
- package/.medusa/server/src/api/middlewares.js +10 -0
- package/.medusa/server/src/index.d.ts +10 -0
- package/.medusa/server/src/index.js +22 -0
- package/.medusa/server/src/jobs/test-integration-connections.d.ts +16 -0
- package/.medusa/server/src/jobs/test-integration-connections.js +53 -0
- package/.medusa/server/src/modules/integration/descriptor/__tests__/build-zod.unit.spec.d.ts +1 -0
- package/.medusa/server/src/modules/integration/descriptor/__tests__/build-zod.unit.spec.js +64 -0
- package/.medusa/server/src/modules/integration/descriptor/__tests__/define.unit.spec.d.ts +1 -0
- package/.medusa/server/src/modules/integration/descriptor/__tests__/define.unit.spec.js +41 -0
- package/.medusa/server/src/modules/integration/descriptor/__tests__/introspect.unit.spec.d.ts +1 -0
- package/.medusa/server/src/modules/integration/descriptor/__tests__/introspect.unit.spec.js +93 -0
- package/.medusa/server/src/modules/integration/descriptor/__tests__/validate.unit.spec.d.ts +1 -0
- package/.medusa/server/src/modules/integration/descriptor/__tests__/validate.unit.spec.js +64 -0
- package/.medusa/server/src/modules/integration/descriptor/build-zod.d.ts +8 -0
- package/.medusa/server/src/modules/integration/descriptor/build-zod.js +82 -0
- package/.medusa/server/src/modules/integration/descriptor/define.d.ts +74 -0
- package/.medusa/server/src/modules/integration/descriptor/define.js +31 -0
- package/.medusa/server/src/modules/integration/descriptor/index.d.ts +5 -0
- package/.medusa/server/src/modules/integration/descriptor/index.js +22 -0
- package/.medusa/server/src/modules/integration/descriptor/introspect.d.ts +5 -0
- package/.medusa/server/src/modules/integration/descriptor/introspect.js +67 -0
- package/.medusa/server/src/modules/integration/descriptor/meta.d.ts +7 -0
- package/.medusa/server/src/modules/integration/descriptor/meta.js +3 -0
- package/.medusa/server/src/modules/integration/descriptor/option.d.ts +104 -0
- package/.medusa/server/src/modules/integration/descriptor/option.js +3 -0
- package/.medusa/server/src/modules/integration/descriptor/validate.d.ts +29 -0
- package/.medusa/server/src/modules/integration/descriptor/validate.js +69 -0
- package/.medusa/server/src/modules/integration/index.d.ts +22 -0
- package/.medusa/server/src/modules/integration/index.js +15 -0
- package/.medusa/server/src/modules/integration/loaders/index.d.ts +1 -0
- package/.medusa/server/src/modules/integration/loaders/index.js +9 -0
- package/.medusa/server/src/modules/integration/loaders/load-providers.d.ts +5 -0
- package/.medusa/server/src/modules/integration/loaders/load-providers.js +35 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260610215533.d.ts +5 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260610215533.js +18 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260618154037.d.ts +5 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260618154037.js +27 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260622120502.d.ts +5 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260622120502.js +14 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260701095518.d.ts +5 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260701095518.js +14 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260708072033.d.ts +5 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260708072033.js +14 -0
- package/.medusa/server/src/modules/integration/models/integration.d.ts +13 -0
- package/.medusa/server/src/modules/integration/models/integration.js +27 -0
- package/.medusa/server/src/modules/integration/services/__tests__/crypto.unit.spec.d.ts +1 -0
- package/.medusa/server/src/modules/integration/services/__tests__/crypto.unit.spec.js +33 -0
- package/.medusa/server/src/modules/integration/services/__tests__/integration-provider.unit.spec.d.ts +1 -0
- package/.medusa/server/src/modules/integration/services/__tests__/integration-provider.unit.spec.js +77 -0
- package/.medusa/server/src/modules/integration/services/__tests__/secrets.unit.spec.d.ts +1 -0
- package/.medusa/server/src/modules/integration/services/__tests__/secrets.unit.spec.js +33 -0
- package/.medusa/server/src/modules/integration/services/crypto.d.ts +10 -0
- package/.medusa/server/src/modules/integration/services/crypto.js +41 -0
- package/.medusa/server/src/modules/integration/services/index.d.ts +3 -0
- package/.medusa/server/src/modules/integration/services/index.js +11 -0
- package/.medusa/server/src/modules/integration/services/integration-module.d.ts +113 -0
- package/.medusa/server/src/modules/integration/services/integration-module.js +219 -0
- package/.medusa/server/src/modules/integration/services/integration-provider.d.ts +49 -0
- package/.medusa/server/src/modules/integration/services/integration-provider.js +76 -0
- package/.medusa/server/src/modules/integration/services/secrets.d.ts +11 -0
- package/.medusa/server/src/modules/integration/services/secrets.js +31 -0
- package/.medusa/server/src/modules/integration/types/index.d.ts +13 -0
- package/.medusa/server/src/modules/integration/types/index.js +10 -0
- package/.medusa/server/src/modules/integration/utils/abstract-integration-provider.d.ts +39 -0
- package/.medusa/server/src/modules/integration/utils/abstract-integration-provider.js +42 -0
- package/.medusa/server/src/modules/integration/utils/index.d.ts +1 -0
- package/.medusa/server/src/modules/integration/utils/index.js +6 -0
- package/.medusa/server/src/subscribers/invalidate-options-cache.d.ts +5 -0
- package/.medusa/server/src/subscribers/invalidate-options-cache.js +13 -0
- package/.medusa/server/src/types/bundles.d.ts +1 -0
- package/.medusa/server/src/types/bundles.js +38 -0
- package/.medusa/server/src/types/http/index.d.ts +1 -0
- package/.medusa/server/src/types/http/index.js +18 -0
- package/.medusa/server/src/types/http/integration/admin/entities.d.ts +32 -0
- package/.medusa/server/src/types/http/integration/admin/entities.js +3 -0
- package/.medusa/server/src/types/http/integration/admin/index.d.ts +2 -0
- package/.medusa/server/src/types/http/integration/admin/index.js +19 -0
- package/.medusa/server/src/types/http/integration/admin/responses.d.ts +19 -0
- package/.medusa/server/src/types/http/integration/admin/responses.js +3 -0
- package/.medusa/server/src/types/http/integration/index.d.ts +1 -0
- package/.medusa/server/src/types/http/integration/index.js +18 -0
- package/.medusa/server/src/types/index.d.ts +3 -0
- package/.medusa/server/src/types/index.js +20 -0
- package/.medusa/server/src/types/integration/common.d.ts +70 -0
- package/.medusa/server/src/types/integration/common.js +3 -0
- package/.medusa/server/src/types/integration/index.d.ts +1 -0
- package/.medusa/server/src/types/integration/index.js +18 -0
- package/.medusa/server/src/workflows/integration/index.d.ts +2 -0
- package/.medusa/server/src/workflows/integration/index.js +19 -0
- package/.medusa/server/src/workflows/integration/steps/apply-integration-section.d.ts +22 -0
- package/.medusa/server/src/workflows/integration/steps/apply-integration-section.js +70 -0
- package/.medusa/server/src/workflows/integration/steps/delete-integration-record.d.ts +6 -0
- package/.medusa/server/src/workflows/integration/steps/delete-integration-record.js +16 -0
- package/.medusa/server/src/workflows/integration/steps/emit-integration-event.d.ts +5 -0
- package/.medusa/server/src/workflows/integration/steps/emit-integration-event.js +11 -0
- package/.medusa/server/src/workflows/integration/steps/index.d.ts +6 -0
- package/.medusa/server/src/workflows/integration/steps/index.js +16 -0
- package/.medusa/server/src/workflows/integration/steps/run-test-connection.d.ts +4 -0
- package/.medusa/server/src/workflows/integration/steps/run-test-connection.js +20 -0
- package/.medusa/server/src/workflows/integration/steps/set-integration-enabled.d.ts +19 -0
- package/.medusa/server/src/workflows/integration/steps/set-integration-enabled.js +27 -0
- package/.medusa/server/src/workflows/integration/steps/upsert-integration-record.d.ts +9 -0
- package/.medusa/server/src/workflows/integration/steps/upsert-integration-record.js +18 -0
- package/.medusa/server/src/workflows/integration/workflows/delete-integration.d.ts +7 -0
- package/.medusa/server/src/workflows/integration/workflows/delete-integration.js +18 -0
- package/.medusa/server/src/workflows/integration/workflows/index.d.ts +4 -0
- package/.medusa/server/src/workflows/integration/workflows/index.js +12 -0
- package/.medusa/server/src/workflows/integration/workflows/set-integration-enabled.d.ts +20 -0
- package/.medusa/server/src/workflows/integration/workflows/set-integration-enabled.js +20 -0
- package/.medusa/server/src/workflows/integration/workflows/test-integration-connection.d.ts +5 -0
- package/.medusa/server/src/workflows/integration/workflows/test-integration-connection.js +21 -0
- package/.medusa/server/src/workflows/integration/workflows/upsert-integration.d.ts +8 -0
- package/.medusa/server/src/workflows/integration/workflows/upsert-integration.js +30 -0
- package/LICENSE +21 -0
- package/README.md +46 -0
- package/package.json +79 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.deriveKey = deriveKey;
|
|
7
|
+
exports.encryptValue = encryptValue;
|
|
8
|
+
exports.decryptValue = decryptValue;
|
|
9
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
10
|
+
const ALGO = "aes-256-gcm";
|
|
11
|
+
const TAG_LEN = 16;
|
|
12
|
+
const IV_LEN = 12;
|
|
13
|
+
/** Derive a 32-byte AES key from any non-empty passphrase (SHA-256). */
|
|
14
|
+
function deriveKey(passphrase) {
|
|
15
|
+
return crypto_1.default.createHash("sha256").update(passphrase, "utf8").digest();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Encrypt one JSON-serializable value. Returns a single base64 string containing
|
|
19
|
+
* `iv ‖ authTag ‖ ciphertext` — the IV is random per call (required for GCM) and folded
|
|
20
|
+
* into the blob, so no separate IV field is stored.
|
|
21
|
+
*/
|
|
22
|
+
function encryptValue(value, key) {
|
|
23
|
+
const iv = crypto_1.default.randomBytes(IV_LEN);
|
|
24
|
+
const cipher = crypto_1.default.createCipheriv(ALGO, key, iv);
|
|
25
|
+
const plaintext = Buffer.from(JSON.stringify(value), "utf8");
|
|
26
|
+
const enc = Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
27
|
+
const tag = cipher.getAuthTag();
|
|
28
|
+
return Buffer.concat([iv, tag, enc]).toString("base64");
|
|
29
|
+
}
|
|
30
|
+
/** Inverse of {@link encryptValue}. Throws if the key is wrong or the blob was tampered. */
|
|
31
|
+
function decryptValue(blob, key) {
|
|
32
|
+
const raw = Buffer.from(blob, "base64");
|
|
33
|
+
const iv = raw.subarray(0, IV_LEN);
|
|
34
|
+
const tag = raw.subarray(IV_LEN, IV_LEN + TAG_LEN);
|
|
35
|
+
const enc = raw.subarray(IV_LEN + TAG_LEN);
|
|
36
|
+
const decipher = crypto_1.default.createDecipheriv(ALGO, key, iv);
|
|
37
|
+
decipher.setAuthTag(tag);
|
|
38
|
+
const dec = Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
39
|
+
return JSON.parse(dec.toString("utf8"));
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3J5cHRvLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vc3JjL21vZHVsZXMvaW50ZWdyYXRpb24vc2VydmljZXMvY3J5cHRvLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3M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mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.IntegrationProviderService = exports.IntegrationModuleService = void 0;
|
|
7
|
+
var integration_module_1 = require("./integration-module");
|
|
8
|
+
Object.defineProperty(exports, "IntegrationModuleService", { enumerable: true, get: function () { return __importDefault(integration_module_1).default; } });
|
|
9
|
+
var integration_provider_1 = require("./integration-provider");
|
|
10
|
+
Object.defineProperty(exports, "IntegrationProviderService", { enumerable: true, get: function () { return __importDefault(integration_provider_1).default; } });
|
|
11
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvbW9kdWxlcy9pbnRlZ3JhdGlvbi9zZXJ2aWNlcy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQSwyREFBMEU7QUFBakUsK0lBQUEsT0FBTyxPQUE0QjtBQUM1QywrREFBOEU7QUFBckUsbUpBQUEsT0FBTyxPQUE4QiJ9
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Logger } from "@medusajs/framework/types";
|
|
2
|
+
import IntegrationProviderService from "./integration-provider";
|
|
3
|
+
import type { IntegrationDescriptor, TestConnectionResult } from "../descriptor/define";
|
|
4
|
+
import { type UiDescriptor } from "../descriptor/introspect";
|
|
5
|
+
import { INTEGRATION_OPTIONS_KEY, type IntegrationModuleOptions } from "../types";
|
|
6
|
+
import type { IntegrationOverviewItem } from "../../../types";
|
|
7
|
+
type InjectedDependencies = {
|
|
8
|
+
logger?: Logger;
|
|
9
|
+
integrationProviderService: IntegrationProviderService;
|
|
10
|
+
[INTEGRATION_OPTIONS_KEY]?: IntegrationModuleOptions;
|
|
11
|
+
};
|
|
12
|
+
export type ResolvedOptions = {
|
|
13
|
+
options: Record<string, unknown>;
|
|
14
|
+
meta: {
|
|
15
|
+
provider_id: string;
|
|
16
|
+
module: string | null;
|
|
17
|
+
is_enabled: boolean;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
declare const IntegrationModuleService_base: import("@medusajs/framework/utils").MedusaServiceReturnType<import("@medusajs/framework/utils").ModelConfigurationsToConfigTemplate<{
|
|
21
|
+
readonly Integration: import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<{
|
|
22
|
+
id: import("@medusajs/framework/utils").PrimaryKeyModifier<string, import("@medusajs/framework/utils").IdProperty>;
|
|
23
|
+
module: import("@medusajs/framework/utils").EnumProperty<["payment", "fulfillment", "marketplace", "crm", "erp", "pim", "notification", "feed", "tax", "other"]>;
|
|
24
|
+
provider_id: import("@medusajs/framework/utils").TextProperty;
|
|
25
|
+
title: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
|
|
26
|
+
options: import("@medusajs/framework/utils").JSONProperty;
|
|
27
|
+
options_version: import("@medusajs/framework/utils").NumberProperty;
|
|
28
|
+
is_enabled: import("@medusajs/framework/utils").BooleanProperty;
|
|
29
|
+
last_test_at: import("@medusajs/framework/utils").NullableModifier<Date, import("@medusajs/framework/utils").DateTimeProperty>;
|
|
30
|
+
last_test_status: import("@medusajs/framework/utils").NullableModifier<"ok" | "fail" | "skipped", import("@medusajs/framework/utils").EnumProperty<["ok", "fail", "skipped"]>>;
|
|
31
|
+
last_test_message: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
|
|
32
|
+
}>, "integration">;
|
|
33
|
+
}>>;
|
|
34
|
+
export default class IntegrationModuleService extends IntegrationModuleService_base {
|
|
35
|
+
protected providerService_: IntegrationProviderService;
|
|
36
|
+
protected options_: IntegrationModuleOptions;
|
|
37
|
+
protected cache_: Map<string, {
|
|
38
|
+
value: ResolvedOptions | null;
|
|
39
|
+
expiresAt: number;
|
|
40
|
+
}>;
|
|
41
|
+
protected key_?: Buffer;
|
|
42
|
+
constructor(deps: InjectedDependencies);
|
|
43
|
+
/** UI descriptors for every registration (one per instance). */
|
|
44
|
+
listUiDescriptors(): UiDescriptor[];
|
|
45
|
+
/** Stamped descriptor (schema + pluginId/instanceId) for one `provider_id`. */
|
|
46
|
+
getProviderDescriptor(providerId: string): IntegrationDescriptor | undefined;
|
|
47
|
+
/** UI descriptor for one `provider_id` (container key). */
|
|
48
|
+
getProviderUiDescriptor(providerId: string): UiDescriptor | undefined;
|
|
49
|
+
/** Whether a provider is registered under this `provider_id` (container key). */
|
|
50
|
+
hasProviderId(providerId: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* The single stored row for a `provider_id` (it's unique), or `undefined`. One place for
|
|
53
|
+
* the "load the row for this provider" lookup shared by the service, steps and routes.
|
|
54
|
+
*/
|
|
55
|
+
findByProviderId(providerId: string): Promise<{
|
|
56
|
+
id: string;
|
|
57
|
+
module: "payment" | "fulfillment" | "marketplace" | "crm" | "erp" | "pim" | "notification" | "feed" | "tax" | "other";
|
|
58
|
+
provider_id: string;
|
|
59
|
+
title: string | null;
|
|
60
|
+
options: Record<string, unknown>;
|
|
61
|
+
options_version: number;
|
|
62
|
+
is_enabled: boolean;
|
|
63
|
+
last_test_at: Date | null;
|
|
64
|
+
last_test_status: "ok" | "fail" | "skipped" | null;
|
|
65
|
+
last_test_message: string | null;
|
|
66
|
+
created_at: Date;
|
|
67
|
+
updated_at: Date;
|
|
68
|
+
deleted_at: Date | null;
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* Full decrypted config (non-secret options + decrypted secrets) for one `provider_id`,
|
|
72
|
+
* or `{}` if no row exists. Used at write time to merge submitted option values over the
|
|
73
|
+
* rest of the stored config without losing secrets the form never sends back.
|
|
74
|
+
*/
|
|
75
|
+
getStoredValues(providerId: string): Promise<Record<string, unknown>>;
|
|
76
|
+
/**
|
|
77
|
+
* Whether a loaded row passes full validation against its provider's descriptor (all
|
|
78
|
+
* required options present + every option's `validate` and the cross-section `validate`).
|
|
79
|
+
* Derived on demand — never persisted — so it can't drift when the descriptor changes.
|
|
80
|
+
*/
|
|
81
|
+
isComplete(record: any): boolean;
|
|
82
|
+
/** Decrypt inline secret keys within a loaded record's `options` → plaintext values. */
|
|
83
|
+
protected assembleValues(record: any): Record<string, unknown>;
|
|
84
|
+
/**
|
|
85
|
+
* Admin overview: every declared instance (registration) merged with its current row
|
|
86
|
+
* state. Lets the UI list configurable integrations before any row exists. No secrets.
|
|
87
|
+
*/
|
|
88
|
+
listIntegrationsOverview(): Promise<IntegrationOverviewItem[]>;
|
|
89
|
+
/**
|
|
90
|
+
* Run the provider's connection test against the currently-resolved settings.
|
|
91
|
+
* Delegates to the integration-provider's `testConnection` (if it has one).
|
|
92
|
+
*/
|
|
93
|
+
runTestConnection(providerId: string): Promise<TestConnectionResult>;
|
|
94
|
+
/** The configured passphrase (any non-empty string). Throws if missing. */
|
|
95
|
+
protected resolveKey(): string;
|
|
96
|
+
/** The derived 32-byte AES key, computed once from the passphrase. */
|
|
97
|
+
protected getKey(): Buffer;
|
|
98
|
+
/** Secret option ids declared by the provider for a `provider_id` (empty if none/unknown). */
|
|
99
|
+
getSecretKeys(providerId: string): string[];
|
|
100
|
+
/**
|
|
101
|
+
* Build the `options` object to persist: secret keys encrypted inline (base64 iv‖tag‖ct),
|
|
102
|
+
* non-secret keys as-is. Requires a configured key only when the descriptor has secrets.
|
|
103
|
+
*/
|
|
104
|
+
encryptForStorage(descriptor: IntegrationDescriptor, values: Record<string, unknown>): Record<string, unknown>;
|
|
105
|
+
/** Clear the resolved-options cache for one `provider_id`, or all when omitted. */
|
|
106
|
+
clearOptionsCache(providerId?: string): void;
|
|
107
|
+
/**
|
|
108
|
+
* Resolve decrypted options for a `(pluginId, instanceId)` pair (the consumer-facing
|
|
109
|
+
* shape) — mapped internally to the `provider_id` key `int_<pluginId>[_<instanceId>]`.
|
|
110
|
+
*/
|
|
111
|
+
getResolvedOptions(pluginId: string, instanceId?: string | null): Promise<ResolvedOptions | null>;
|
|
112
|
+
}
|
|
113
|
+
export {};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
7
|
+
const integration_1 = __importDefault(require("../models/integration"));
|
|
8
|
+
const crypto_1 = require("./crypto");
|
|
9
|
+
const secrets_1 = require("./secrets");
|
|
10
|
+
const integration_provider_1 = __importDefault(require("./integration-provider"));
|
|
11
|
+
const introspect_1 = require("../descriptor/introspect");
|
|
12
|
+
const validate_1 = require("../descriptor/validate");
|
|
13
|
+
const types_1 = require("../types");
|
|
14
|
+
const CACHE_TTL_MS = 60_000;
|
|
15
|
+
class IntegrationModuleService extends (0, utils_1.MedusaService)({
|
|
16
|
+
Integration: integration_1.default,
|
|
17
|
+
}) {
|
|
18
|
+
constructor(deps) {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.cache_ = new Map();
|
|
21
|
+
this.providerService_ = deps.integrationProviderService;
|
|
22
|
+
this.options_ = deps[types_1.INTEGRATION_OPTIONS_KEY] ?? {};
|
|
23
|
+
}
|
|
24
|
+
// ── descriptors (sourced from registered integration-providers) ──────────────
|
|
25
|
+
/** UI descriptors for every registration (one per instance). */
|
|
26
|
+
listUiDescriptors() {
|
|
27
|
+
return this.providerService_.listRegistrations().map((r) => (0, introspect_1.introspectDescriptor)({ ...r.provider.getDescriptor(), pluginId: r.pluginId, instanceId: r.instanceId }, typeof r.provider.testConnection === "function"));
|
|
28
|
+
}
|
|
29
|
+
/** Stamped descriptor (schema + pluginId/instanceId) for one `provider_id`. */
|
|
30
|
+
getProviderDescriptor(providerId) {
|
|
31
|
+
const r = this.providerService_.getRegistration(providerId);
|
|
32
|
+
if (!r)
|
|
33
|
+
return undefined;
|
|
34
|
+
return { ...r.provider.getDescriptor(), pluginId: r.pluginId, instanceId: r.instanceId };
|
|
35
|
+
}
|
|
36
|
+
/** UI descriptor for one `provider_id` (container key). */
|
|
37
|
+
getProviderUiDescriptor(providerId) {
|
|
38
|
+
const r = this.providerService_.getRegistration(providerId);
|
|
39
|
+
if (!r)
|
|
40
|
+
return undefined;
|
|
41
|
+
return (0, introspect_1.introspectDescriptor)({ ...r.provider.getDescriptor(), pluginId: r.pluginId, instanceId: r.instanceId }, typeof r.provider.testConnection === "function");
|
|
42
|
+
}
|
|
43
|
+
/** Whether a provider is registered under this `provider_id` (container key). */
|
|
44
|
+
hasProviderId(providerId) {
|
|
45
|
+
return !!this.providerService_.getRegistration(providerId);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The single stored row for a `provider_id` (it's unique), or `undefined`. One place for
|
|
49
|
+
* the "load the row for this provider" lookup shared by the service, steps and routes.
|
|
50
|
+
*/
|
|
51
|
+
async findByProviderId(providerId) {
|
|
52
|
+
const [record] = await this.listIntegrations({ provider_id: providerId }, { take: 1 });
|
|
53
|
+
return record;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Full decrypted config (non-secret options + decrypted secrets) for one `provider_id`,
|
|
57
|
+
* or `{}` if no row exists. Used at write time to merge submitted option values over the
|
|
58
|
+
* rest of the stored config without losing secrets the form never sends back.
|
|
59
|
+
*/
|
|
60
|
+
async getStoredValues(providerId) {
|
|
61
|
+
const record = await this.findByProviderId(providerId);
|
|
62
|
+
return record ? this.assembleValues(record) : {};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Whether a loaded row passes full validation against its provider's descriptor (all
|
|
66
|
+
* required options present + every option's `validate` and the cross-section `validate`).
|
|
67
|
+
* Derived on demand — never persisted — so it can't drift when the descriptor changes.
|
|
68
|
+
*/
|
|
69
|
+
isComplete(record) {
|
|
70
|
+
const descriptor = this.getProviderDescriptor(record.provider_id);
|
|
71
|
+
if (!descriptor)
|
|
72
|
+
return false;
|
|
73
|
+
return (0, validate_1.isDescriptorComplete)(descriptor, this.assembleValues(record));
|
|
74
|
+
}
|
|
75
|
+
/** Decrypt inline secret keys within a loaded record's `options` → plaintext values. */
|
|
76
|
+
assembleValues(record) {
|
|
77
|
+
const options = (record.options ?? {});
|
|
78
|
+
const descriptor = this.getProviderDescriptor(record.provider_id);
|
|
79
|
+
const secretKeys = descriptor ? (0, introspect_1.secretFieldNames)(descriptor) : [];
|
|
80
|
+
if (secretKeys.length === 0)
|
|
81
|
+
return { ...options };
|
|
82
|
+
return (0, secrets_1.decryptSecretsInline)(options, secretKeys, this.getKey());
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Admin overview: every declared instance (registration) merged with its current row
|
|
86
|
+
* state. Lets the UI list configurable integrations before any row exists. No secrets.
|
|
87
|
+
*/
|
|
88
|
+
async listIntegrationsOverview() {
|
|
89
|
+
const regs = this.providerService_.listRegistrations();
|
|
90
|
+
const rows = await this.listIntegrations({}, { take: 1000 });
|
|
91
|
+
const byId = new Map(rows.map((r) => [r.provider_id, r]));
|
|
92
|
+
return regs.map((r) => {
|
|
93
|
+
const d = r.provider.getDescriptor();
|
|
94
|
+
const row = byId.get(r.key);
|
|
95
|
+
return {
|
|
96
|
+
provider_id: r.key,
|
|
97
|
+
plugin_id: r.pluginId,
|
|
98
|
+
instance_id: r.instanceId,
|
|
99
|
+
module: d.module,
|
|
100
|
+
display_name: d.displayName,
|
|
101
|
+
icon: d.icon,
|
|
102
|
+
supports_multiple_instances: d.supportsMultipleInstances ?? false,
|
|
103
|
+
has_test_connection: typeof r.provider.testConnection === "function",
|
|
104
|
+
is_configured: !!row,
|
|
105
|
+
is_enabled: row?.is_enabled ?? false,
|
|
106
|
+
is_complete: row ? this.isComplete(row) : false,
|
|
107
|
+
last_test_status: row?.last_test_status ?? null,
|
|
108
|
+
last_test_at: row?.last_test_at ?? null,
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Run the provider's connection test against the currently-resolved settings.
|
|
114
|
+
* Delegates to the integration-provider's `testConnection` (if it has one).
|
|
115
|
+
*/
|
|
116
|
+
async runTestConnection(providerId) {
|
|
117
|
+
let provider;
|
|
118
|
+
try {
|
|
119
|
+
provider = this.providerService_.retrieveByKey(providerId);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return { status: "fail", message: `Unknown integration provider "${providerId}"` };
|
|
123
|
+
}
|
|
124
|
+
if (!provider.testConnection) {
|
|
125
|
+
return { status: "skipped", message: "No test configured" };
|
|
126
|
+
}
|
|
127
|
+
const resolved = await this.getResolvedOptions(provider.getIdentifier(), provider.getInstanceId());
|
|
128
|
+
if (!resolved) {
|
|
129
|
+
return { status: "fail", message: "Not configured" };
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
return await provider.testConnection({
|
|
133
|
+
options: resolved.options,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
return { status: "fail", message: e?.message ?? "Test failed" };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// ── encryption ───────────────────────────────────────────────────────────────
|
|
141
|
+
/** The configured passphrase (any non-empty string). Throws if missing. */
|
|
142
|
+
resolveKey() {
|
|
143
|
+
const key = this.options_.encryptionKey;
|
|
144
|
+
if (key && key.length > 0)
|
|
145
|
+
return key;
|
|
146
|
+
throw new Error("[integration] encryptionKey is required. Set GORGO_INTEGRATION_ENCRYPTION_KEY to any " +
|
|
147
|
+
"non-empty secret (high-entropy recommended, e.g. `openssl rand -hex 32`).");
|
|
148
|
+
}
|
|
149
|
+
/** The derived 32-byte AES key, computed once from the passphrase. */
|
|
150
|
+
getKey() {
|
|
151
|
+
return (this.key_ ??= (0, crypto_1.deriveKey)(this.resolveKey()));
|
|
152
|
+
}
|
|
153
|
+
/** Secret option ids declared by the provider for a `provider_id` (empty if none/unknown). */
|
|
154
|
+
getSecretKeys(providerId) {
|
|
155
|
+
const descriptor = this.getProviderDescriptor(providerId);
|
|
156
|
+
return descriptor ? (0, introspect_1.secretFieldNames)(descriptor) : [];
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Build the `options` object to persist: secret keys encrypted inline (base64 iv‖tag‖ct),
|
|
160
|
+
* non-secret keys as-is. Requires a configured key only when the descriptor has secrets.
|
|
161
|
+
*/
|
|
162
|
+
encryptForStorage(descriptor, values) {
|
|
163
|
+
const secretKeys = (0, introspect_1.secretFieldNames)(descriptor);
|
|
164
|
+
if (secretKeys.length === 0)
|
|
165
|
+
return { ...values };
|
|
166
|
+
return (0, secrets_1.encryptSecretsInline)(values, secretKeys, this.getKey());
|
|
167
|
+
}
|
|
168
|
+
// ── resolver (runtime read, cached) ──────────────────────────────────────────
|
|
169
|
+
/** Clear the resolved-options cache for one `provider_id`, or all when omitted. */
|
|
170
|
+
clearOptionsCache(providerId) {
|
|
171
|
+
if (!providerId) {
|
|
172
|
+
this.cache_.clear();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
this.cache_.delete(providerId);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Resolve decrypted options for a `(pluginId, instanceId)` pair (the consumer-facing
|
|
179
|
+
* shape) — mapped internally to the `provider_id` key `int_<pluginId>[_<instanceId>]`.
|
|
180
|
+
*/
|
|
181
|
+
async getResolvedOptions(pluginId, instanceId) {
|
|
182
|
+
const providerId = integration_provider_1.default.key(pluginId, instanceId);
|
|
183
|
+
const hit = this.cache_.get(providerId);
|
|
184
|
+
if (hit && hit.expiresAt > Date.now())
|
|
185
|
+
return hit.value;
|
|
186
|
+
// The provider_id must correspond to a declared registration. A miss here is a
|
|
187
|
+
// misconfiguration (forgot to register / wrong id), distinct from "registered but
|
|
188
|
+
// not configured yet" (handled below by returning null).
|
|
189
|
+
if (!this.hasProviderId(providerId)) {
|
|
190
|
+
throw new Error(`No integration provider registered for "${providerId}". ` +
|
|
191
|
+
`Declare it in medusa-config under the integration plugin's options.providers.`);
|
|
192
|
+
}
|
|
193
|
+
const record = await this.findByProviderId(providerId);
|
|
194
|
+
let value = null;
|
|
195
|
+
// An incomplete config is invisible to consumers (treated like "not configured"), so a
|
|
196
|
+
// partially-filled draft can never leak into a provider mid-setup. Completeness is the
|
|
197
|
+
// full validation: every option + the descriptor's cross-section `validate`.
|
|
198
|
+
if (record && record.is_enabled) {
|
|
199
|
+
const descriptor = this.getProviderDescriptor(providerId);
|
|
200
|
+
const assembled = this.assembleValues(record);
|
|
201
|
+
if ((0, validate_1.isDescriptorComplete)(descriptor, assembled)) {
|
|
202
|
+
// Apply option defaults for fields the user never set explicitly.
|
|
203
|
+
const parsed = descriptor.optionsSchema.safeParse(assembled);
|
|
204
|
+
value = {
|
|
205
|
+
options: parsed.success ? parsed.data : assembled,
|
|
206
|
+
meta: {
|
|
207
|
+
provider_id: record.provider_id,
|
|
208
|
+
module: record.module ?? null,
|
|
209
|
+
is_enabled: record.is_enabled,
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
this.cache_.set(providerId, { value, expiresAt: Date.now() + CACHE_TTL_MS });
|
|
215
|
+
return value;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.default = IntegrationModuleService;
|
|
219
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW50ZWdyYXRpb24tbW9kdWxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vc3JjL21vZHVsZXMvaW50ZWdyYXRpb24vc2VydmljZXMvaW50ZWdyYXRpb24tbW9kdWxlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEscURBQXlEO0FBRXpELHdFQUErQztBQUMvQyxxQ0FBb0M7QUFDcEMsdU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NLEdBQUcsVUFBVSxDQUFDLGFBQWEsQ0FBQyxTQUFTLENBQUMsU0FBUyxDQUFDLENBQUE7Z0JBQzVELEtBQUssR0FBRztvQkFDTixPQUFPLEVBQUUsTUFBTSxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUUsTUFBTSxDQUFDLElBQWdDLENBQUMsQ0FBQyxDQUFDLFNBQVM7b0JBQzlFLElBQUksRUFBRTt3QkFDSixXQUFXLEVBQUUsTUFBTSxDQUFDLFdBQVc7d0JBQy9CLE1BQU0sRUFBRSxNQUFNLENBQUMsTUFBTSxJQUFJLElBQUk7d0JBQzdCLFVBQVUsRUFBRSxNQUFNLENBQUMsVUFBVTtxQkFDOUI7aUJBQ0YsQ0FBQTtZQUNILENBQUM7UUFDSCxDQUFDO1FBQ0QsSUFBSSxDQUFDLE1BQU0sQ0FBQyxHQUFHLENBQUMsVUFBVSxFQUFFLEVBQUUsS0FBSyxFQUFFLFNBQVMsRUFBRSxJQUFJLENBQUMsR0FBRyxFQUFFLEdBQUcsWUFBWSxFQUFFLENBQUMsQ0FBQTtRQUM1RSxPQUFPLEtBQUssQ0FBQTtJQUNkLENBQUM7Q0FDRjtBQTFPRCwyQ0EwT0MifQ==
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { IntegrationProviderRegistrationPrefix } from "../types";
|
|
2
|
+
import type { AbstractIntegrationProvider } from "../utils/abstract-integration-provider";
|
|
3
|
+
import type { IntegrationDescriptor } from "../descriptor/define";
|
|
4
|
+
type InjectedDependencies = {
|
|
5
|
+
[key: `${typeof IntegrationProviderRegistrationPrefix}${string}`]: AbstractIntegrationProvider;
|
|
6
|
+
};
|
|
7
|
+
/** A single registered provider = one integration *instance*. */
|
|
8
|
+
export type ProviderRegistration = {
|
|
9
|
+
/** Container key `int_<identifier>[_<id>]` — the instance's stable identity. */
|
|
10
|
+
key: string;
|
|
11
|
+
pluginId: string;
|
|
12
|
+
instanceId: string | null;
|
|
13
|
+
provider: AbstractIntegrationProvider;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Thin registry over the integration-providers registered into the module container by
|
|
17
|
+
* `loadProviders`. Each registration in `options.providers` is one instance, identified
|
|
18
|
+
* by its container key `int_<identifier>[_<id>]` — which is also the DB `provider_id`.
|
|
19
|
+
* Instances are declared in medusa-config, not created at runtime. `pluginId`/`instanceId`
|
|
20
|
+
* (= `getIdentifier()`/`getInstanceId()`) are derived for descriptors/UI.
|
|
21
|
+
*
|
|
22
|
+
* Intentionally minimal: it locates providers; callers invoke provider methods directly,
|
|
23
|
+
* so new provider methods never require changes here.
|
|
24
|
+
*/
|
|
25
|
+
export default class IntegrationProviderService {
|
|
26
|
+
protected dependencies_: InjectedDependencies;
|
|
27
|
+
constructor(container: InjectedDependencies);
|
|
28
|
+
/** Build the container key for a `(pluginId, instanceId)` pair. */
|
|
29
|
+
static key(pluginId: string, instanceId?: string | null): string;
|
|
30
|
+
/** All registered provider instances. */
|
|
31
|
+
listProviders(): AbstractIntegrationProvider[];
|
|
32
|
+
/** Every registration with its derived `(pluginId, instanceId)` identity. */
|
|
33
|
+
listRegistrations(): ProviderRegistration[];
|
|
34
|
+
/** Resolve a provider by its exact container key. */
|
|
35
|
+
retrieveByKey(key: string): AbstractIntegrationProvider;
|
|
36
|
+
/** Resolve the provider for a `(pluginId, instanceId)` pair. */
|
|
37
|
+
retrieveProvider(pluginId: string, instanceId?: string | null): AbstractIntegrationProvider;
|
|
38
|
+
/** Whether a provider is registered for this `(pluginId, instanceId)` pair. */
|
|
39
|
+
hasProvider(pluginId: string, instanceId?: string | null): boolean;
|
|
40
|
+
/** Resolve `(pluginId, instanceId)` from a container key, or undefined if unregistered. */
|
|
41
|
+
getRegistration(key: string): ProviderRegistration | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Descriptors of every registered provider — feeds the introspection/UI pipeline.
|
|
44
|
+
* `pluginId`/`instanceId` are stamped from each registration, so authors never repeat
|
|
45
|
+
* them in the descriptor. One descriptor per registration (one per instance).
|
|
46
|
+
*/
|
|
47
|
+
listDescriptors(): IntegrationDescriptor[];
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const types_1 = require("../types");
|
|
4
|
+
/**
|
|
5
|
+
* Thin registry over the integration-providers registered into the module container by
|
|
6
|
+
* `loadProviders`. Each registration in `options.providers` is one instance, identified
|
|
7
|
+
* by its container key `int_<identifier>[_<id>]` — which is also the DB `provider_id`.
|
|
8
|
+
* Instances are declared in medusa-config, not created at runtime. `pluginId`/`instanceId`
|
|
9
|
+
* (= `getIdentifier()`/`getInstanceId()`) are derived for descriptors/UI.
|
|
10
|
+
*
|
|
11
|
+
* Intentionally minimal: it locates providers; callers invoke provider methods directly,
|
|
12
|
+
* so new provider methods never require changes here.
|
|
13
|
+
*/
|
|
14
|
+
class IntegrationProviderService {
|
|
15
|
+
constructor(container) {
|
|
16
|
+
this.dependencies_ = container;
|
|
17
|
+
}
|
|
18
|
+
/** Build the container key for a `(pluginId, instanceId)` pair. */
|
|
19
|
+
static key(pluginId, instanceId) {
|
|
20
|
+
return `${types_1.IntegrationProviderRegistrationPrefix}${pluginId}${instanceId ? `_${instanceId}` : ""}`;
|
|
21
|
+
}
|
|
22
|
+
/** All registered provider instances. */
|
|
23
|
+
listProviders() {
|
|
24
|
+
return Object.keys(this.dependencies_)
|
|
25
|
+
.filter((k) => k.startsWith(types_1.IntegrationProviderRegistrationPrefix))
|
|
26
|
+
.map((k) => this.dependencies_[k]);
|
|
27
|
+
}
|
|
28
|
+
/** Every registration with its derived `(pluginId, instanceId)` identity. */
|
|
29
|
+
listRegistrations() {
|
|
30
|
+
return Object.keys(this.dependencies_)
|
|
31
|
+
.filter((k) => k.startsWith(types_1.IntegrationProviderRegistrationPrefix))
|
|
32
|
+
.map((k) => {
|
|
33
|
+
const provider = this.dependencies_[k];
|
|
34
|
+
return {
|
|
35
|
+
key: k,
|
|
36
|
+
pluginId: provider.getIdentifier(),
|
|
37
|
+
instanceId: provider.getInstanceId(),
|
|
38
|
+
provider,
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** Resolve a provider by its exact container key. */
|
|
43
|
+
retrieveByKey(key) {
|
|
44
|
+
const provider = this.dependencies_[key];
|
|
45
|
+
if (!provider) {
|
|
46
|
+
throw new Error(`Unable to retrieve integration provider "${key}". Make sure it is registered in medusa-config under the integration plugin's \`options.providers\`.`);
|
|
47
|
+
}
|
|
48
|
+
return provider;
|
|
49
|
+
}
|
|
50
|
+
/** Resolve the provider for a `(pluginId, instanceId)` pair. */
|
|
51
|
+
retrieveProvider(pluginId, instanceId) {
|
|
52
|
+
return this.retrieveByKey(IntegrationProviderService.key(pluginId, instanceId));
|
|
53
|
+
}
|
|
54
|
+
/** Whether a provider is registered for this `(pluginId, instanceId)` pair. */
|
|
55
|
+
hasProvider(pluginId, instanceId) {
|
|
56
|
+
return !!this.dependencies_[IntegrationProviderService.key(pluginId, instanceId)];
|
|
57
|
+
}
|
|
58
|
+
/** Resolve `(pluginId, instanceId)` from a container key, or undefined if unregistered. */
|
|
59
|
+
getRegistration(key) {
|
|
60
|
+
return this.listRegistrations().find((r) => r.key === key);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Descriptors of every registered provider — feeds the introspection/UI pipeline.
|
|
64
|
+
* `pluginId`/`instanceId` are stamped from each registration, so authors never repeat
|
|
65
|
+
* them in the descriptor. One descriptor per registration (one per instance).
|
|
66
|
+
*/
|
|
67
|
+
listDescriptors() {
|
|
68
|
+
return this.listRegistrations().map((r) => ({
|
|
69
|
+
...r.provider.getDescriptor(),
|
|
70
|
+
pluginId: r.pluginId,
|
|
71
|
+
instanceId: r.instanceId,
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.default = IntegrationProviderService;
|
|
76
|
+
//# sourceMappingURL=data:application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6QiwwQkFBMEIsQ0FBQyxHQUFHLENBQUMsUUFBUSxFQUFFLFVBQVUsQ0FBK0IsQ0FDbkYsQ0FBQTtJQUNILENBQUM7SUFFRCwyRkFBMkY7SUFDM0YsZUFBZSxDQUFDLEdBQVc7UUFDekIsT0FBTyxJQUFJLENBQUMsaUJBQWlCLEVBQUUsQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLEVBQUUsRUFBRSxDQUFDLENBQUMsQ0FBQyxHQUFHLEtBQUssR0FBRyxDQUFDLENBQUE7SUFDNUQsQ0FBQztJQUVEOzs7O09BSUc7SUFDSCxlQUFlO1FBQ2IsT0FBTyxJQUFJLENBQUMsaUJBQWlCLEVBQUUsQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLEVBQUUsRUFBRSxDQUFDLENBQUM7WUFDMUMsR0FBRyxDQUFDLENBQUMsUUFBUSxDQUFDLGFBQWEsRUFBRTtZQUM3QixRQUFRLEVBQUUsQ0FBQyxDQUFDLFFBQVE7WUFDcEIsVUFBVSxFQUFFLENBQUMsQ0FBQyxVQUFVO1NBQ3pCLENBQUMsQ0FBQyxDQUFBO0lBQ0wsQ0FBQztDQUNGO0FBMUVELDZDQTBFQyJ9
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Return a copy of `values` where each secret key (per the descriptor's `secret` flags)
|
|
3
|
+
* holds a `base64(iv‖tag‖ct)` string; non-secret keys pass through unchanged. Empty/absent
|
|
4
|
+
* secret values are left as-is (nothing to encrypt).
|
|
5
|
+
*/
|
|
6
|
+
export declare function encryptSecretsInline(values: Record<string, unknown>, secretKeys: Iterable<string>, key: Buffer): Record<string, unknown>;
|
|
7
|
+
/**
|
|
8
|
+
* Inverse of {@link encryptSecretsInline}: decrypt each secret key holding a non-empty
|
|
9
|
+
* string blob back to its plaintext value; everything else passes through unchanged.
|
|
10
|
+
*/
|
|
11
|
+
export declare function decryptSecretsInline(options: Record<string, unknown>, secretKeys: Iterable<string>, key: Buffer): Record<string, unknown>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encryptSecretsInline = encryptSecretsInline;
|
|
4
|
+
exports.decryptSecretsInline = decryptSecretsInline;
|
|
5
|
+
const crypto_1 = require("./crypto");
|
|
6
|
+
/**
|
|
7
|
+
* Return a copy of `values` where each secret key (per the descriptor's `secret` flags)
|
|
8
|
+
* holds a `base64(iv‖tag‖ct)` string; non-secret keys pass through unchanged. Empty/absent
|
|
9
|
+
* secret values are left as-is (nothing to encrypt).
|
|
10
|
+
*/
|
|
11
|
+
function encryptSecretsInline(values, secretKeys, key) {
|
|
12
|
+
const secret = new Set(secretKeys);
|
|
13
|
+
const out = {};
|
|
14
|
+
for (const [k, v] of Object.entries(values)) {
|
|
15
|
+
out[k] = secret.has(k) && v != null && v !== "" ? (0, crypto_1.encryptValue)(v, key) : v;
|
|
16
|
+
}
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Inverse of {@link encryptSecretsInline}: decrypt each secret key holding a non-empty
|
|
21
|
+
* string blob back to its plaintext value; everything else passes through unchanged.
|
|
22
|
+
*/
|
|
23
|
+
function decryptSecretsInline(options, secretKeys, key) {
|
|
24
|
+
const secret = new Set(secretKeys);
|
|
25
|
+
const out = {};
|
|
26
|
+
for (const [k, v] of Object.entries(options)) {
|
|
27
|
+
out[k] = secret.has(k) && typeof v === "string" && v !== "" ? (0, crypto_1.decryptValue)(v, key) : v;
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VjcmV0cy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3NyYy9tb2R1bGVzL2ludGVncmF0aW9uL3NlcnZpY2VzL3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ENBQUMsR0FBRyxNQUFNLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxJQUFJLE9BQU8sQ0FBQyxLQUFLLFFBQVEsSUFBSSxDQUFDLEtBQUssRUFBRSxDQUFDLENBQUMsQ0FBQyxJQUFBLHFCQUFZLEVBQUMsQ0FBQyxFQUFFLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUE7SUFDeEYsQ0FBQztJQUNELE9BQU8sR0FBRyxDQUFBO0FBQ1osQ0FBQyJ9
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ModuleProvider } from "@medusajs/framework/types";
|
|
2
|
+
/** Awilix list-key under which every registered integration-provider key is collected. */
|
|
3
|
+
export declare const IntegrationProviderRegistrationKey = "integration_providers";
|
|
4
|
+
/** Prefix for each provider's container registration key: `int_<identifier>[_<id>]`. */
|
|
5
|
+
export declare const IntegrationProviderRegistrationPrefix = "int_";
|
|
6
|
+
/** Container key under which the resolved module options are registered. */
|
|
7
|
+
export declare const INTEGRATION_OPTIONS_KEY = "integrationModuleOptions";
|
|
8
|
+
export type IntegrationModuleOptions = {
|
|
9
|
+
/** Any non-empty secret; SHA-256-derived to a 32-byte AES-256-GCM key. High-entropy recommended (openssl rand -hex 32). */
|
|
10
|
+
encryptionKey?: string;
|
|
11
|
+
/** Integration-providers, each `{ resolve, id?, options? }` — like payment/fulfillment. */
|
|
12
|
+
providers?: ModuleProvider[];
|
|
13
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.INTEGRATION_OPTIONS_KEY = exports.IntegrationProviderRegistrationPrefix = exports.IntegrationProviderRegistrationKey = void 0;
|
|
4
|
+
/** Awilix list-key under which every registered integration-provider key is collected. */
|
|
5
|
+
exports.IntegrationProviderRegistrationKey = "integration_providers";
|
|
6
|
+
/** Prefix for each provider's container registration key: `int_<identifier>[_<id>]`. */
|
|
7
|
+
exports.IntegrationProviderRegistrationPrefix = "int_";
|
|
8
|
+
/** Container key under which the resolved module options are registered. */
|
|
9
|
+
exports.INTEGRATION_OPTIONS_KEY = "integrationModuleOptions";
|
|
10
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvbW9kdWxlcy9pbnRlZ3JhdGlvbi90eXBlcy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFFQSwwRkFBMEY7QUFDN0UsUUFBQSxrQ0FBa0MsR0FBRyx1QkFBdUIsQ0FBQTtBQUV6RSx3RkFBd0Y7QUFDM0UsUUFBQSxxQ0FBcUMsR0FBRyxNQUFNLENBQUE7QUFFM0QsNEVBQTRFO0FBQy9ELFFBQUEsdUJBQXVCLEdBQUcsMEJBQTBCLENBQUEifQ==
|