@thorprovider/adapters 4.2.0 → 4.3.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/CHANGELOG.md +6 -0
- package/PROVIDER_IMPLEMENTATION_ANALYSIS.md +659 -0
- package/README.md +19 -0
- package/dist/index.d.mts +249 -2
- package/dist/index.d.ts +249 -2
- package/dist/index.js +1450 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1448 -2
- package/dist/index.mjs.map +1 -1
- package/docs/RETRY_SOLUTION_SUMMARY.md +26 -11
- package/docs/authentication.md +115 -62
- package/docs/capabilities-system.md +34 -2
- package/docs/category-customization.md +37 -29
- package/docs/fetch-reliability-solution.md +127 -278
- package/docs/getting-started.md +43 -29
- package/docs/profile-management.md +68 -38
- package/docs/providers-overview.md +14 -0
- package/docs/services-overview.md +20 -2
- package/package.json +10 -6
- package/quick-reference.md +34 -0
- package/src/factory/index.ts +4 -0
- package/src/index.ts +3 -0
- package/src/providers/index.ts +3 -0
- package/src/providers/medusa/admin.test.ts +404 -0
- package/src/providers/medusa/admin.ts +442 -0
- package/src/providers/medusa/auth.test.ts +137 -0
- package/src/providers/medusa/auth.ts +96 -1
- package/src/providers/medusa/index.ts +21 -1
- package/src/providers/shopify/auth.ts +6 -0
- package/src/providers/stelorder/client.test-helpers.ts +3 -0
- package/src/providers/stelorder/client.test.ts +58 -0
- package/src/providers/stelorder/client.ts +326 -0
- package/src/providers/stelorder/index.test.ts +48 -0
- package/src/providers/stelorder/index.ts +685 -0
- package/src/providers/stelorder/live-smoke.test.ts +54 -0
- package/src/providers/stelorder/transforms.test.ts +103 -0
- package/src/providers/stelorder/transforms.ts +631 -0
- package/src/resilience/README.md +70 -48
- package/src/types/capabilities.types.ts +51 -0
- package/vitest.config.ts +13 -0
- package/vitest.setup.ts +6 -0
- package/.turbo/turbo-build.log +0 -18
- package/dist/.tsbuildinfo +0 -1
- package/src/core/errors.js +0 -161
- package/src/core/fetch-utils.js +0 -240
- package/src/core/logger.js +0 -63
- package/src/metadata/channel-scope-validation.js +0 -136
- package/src/metadata/channel-scope.js +0 -174
- package/src/metadata/index.js +0 -31
- package/src/providers/medusa/auth.js +0 -601
- package/src/providers/medusa/index.js +0 -2485
- package/src/providers/medusa/payment.js +0 -265
- package/src/providers/medusa/transforms.js +0 -505
- package/src/types/capabilities.types.js +0 -141
- package/src/types/provider.js +0 -9
- package/src/utils/payment-utils.js +0 -152
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Channel Scope — Backend-Agnostic Multi-Tenant Helpers
|
|
4
|
-
*
|
|
5
|
-
* Provides utilities for tagging, reading and filtering entity metadata by
|
|
6
|
-
* sales-channel (or any future tenant key). Works with any backend that
|
|
7
|
-
* exposes a writable `metadata: Record<string, unknown>` field on its
|
|
8
|
-
* entities (Medusa, Shopify metafields, WooCommerce meta, etc.).
|
|
9
|
-
*
|
|
10
|
-
* ## Design decisions
|
|
11
|
-
*
|
|
12
|
-
* | Decision | Rationale |
|
|
13
|
-
* |----------|-----------|
|
|
14
|
-
* | Flat key (`sales_channel_id`) | Simpler queries, no prefix parsing required |
|
|
15
|
-
* | Metadata, not custom fields | Zero DB migrations; works across backends |
|
|
16
|
-
* | Pure functions | No side effects → easily testable; usable in any layer |
|
|
17
|
-
* | `assigned_at` timestamp | Audit trail for dropshipper / admin assignment |
|
|
18
|
-
*
|
|
19
|
-
* @module metadata/channel-scope
|
|
20
|
-
*/
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.CHANNEL_ASSIGNED_BY_KEY = exports.CHANNEL_ASSIGNED_AT_KEY = exports.CHANNEL_SCOPE_KEY = void 0;
|
|
23
|
-
exports.buildChannelScopeMetadata = buildChannelScopeMetadata;
|
|
24
|
-
exports.getChannelScope = getChannelScope;
|
|
25
|
-
exports.isScopedToChannel = isScopedToChannel;
|
|
26
|
-
exports.isGlobalEntity = isGlobalEntity;
|
|
27
|
-
exports.filterByChannel = filterByChannel;
|
|
28
|
-
exports.filterGlobalOnly = filterGlobalOnly;
|
|
29
|
-
exports.partitionByChannel = partitionByChannel;
|
|
30
|
-
// ────────────────────────────────────────────────────────────────────
|
|
31
|
-
// Constants
|
|
32
|
-
// ────────────────────────────────────────────────────────────────────
|
|
33
|
-
/**
|
|
34
|
-
* Well-known metadata key used to store the owning sales-channel on any
|
|
35
|
-
* entity that Medusa (or the backend) does not natively scope.
|
|
36
|
-
*
|
|
37
|
-
* Convention: every entity whose metadata contains this key is
|
|
38
|
-
* considered "owned" by the referenced channel. Entities without it
|
|
39
|
-
* are global / unscoped.
|
|
40
|
-
*/
|
|
41
|
-
exports.CHANNEL_SCOPE_KEY = 'sales_channel_id';
|
|
42
|
-
/**
|
|
43
|
-
* Optional audit key — ISO-8601 timestamp of when the channel was assigned.
|
|
44
|
-
*/
|
|
45
|
-
exports.CHANNEL_ASSIGNED_AT_KEY = 'channel_assigned_at';
|
|
46
|
-
/**
|
|
47
|
-
* Optional audit key — who assigned the entity to the channel.
|
|
48
|
-
* Value is a free-form string (admin email, user id, "system", etc.).
|
|
49
|
-
*/
|
|
50
|
-
exports.CHANNEL_ASSIGNED_BY_KEY = 'channel_assigned_by';
|
|
51
|
-
// ────────────────────────────────────────────────────────────────────
|
|
52
|
-
// Builders
|
|
53
|
-
// ────────────────────────────────────────────────────────────────────
|
|
54
|
-
/**
|
|
55
|
-
* Build channel-scope metadata payload.
|
|
56
|
-
*
|
|
57
|
-
* The returned object should be **merged** into the entity's existing
|
|
58
|
-
* `metadata` field when calling `updateCustomer`, `updateOrder`, etc.
|
|
59
|
-
*
|
|
60
|
-
* @param channelId - Sales-channel ID (e.g. `"sc_01HXXX"`)
|
|
61
|
-
* @param assignedBy - Optional identifier of who performed the assignment
|
|
62
|
-
* @returns Metadata fragment ready to spread into an update payload
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* const scope = buildChannelScopeMetadata('sc_01HXXX', 'admin@store.com');
|
|
67
|
-
* await commerce.updateCustomer(customerId, {
|
|
68
|
-
* metadata: { ...existingMeta, ...scope },
|
|
69
|
-
* });
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
function buildChannelScopeMetadata(channelId, assignedBy) {
|
|
73
|
-
var _a;
|
|
74
|
-
var payload = (_a = {},
|
|
75
|
-
_a[exports.CHANNEL_SCOPE_KEY] = channelId,
|
|
76
|
-
_a[exports.CHANNEL_ASSIGNED_AT_KEY] = new Date().toISOString(),
|
|
77
|
-
_a);
|
|
78
|
-
if (assignedBy) {
|
|
79
|
-
payload[exports.CHANNEL_ASSIGNED_BY_KEY] = assignedBy;
|
|
80
|
-
}
|
|
81
|
-
return payload;
|
|
82
|
-
}
|
|
83
|
-
// ────────────────────────────────────────────────────────────────────
|
|
84
|
-
// Readers
|
|
85
|
-
// ────────────────────────────────────────────────────────────────────
|
|
86
|
-
/**
|
|
87
|
-
* Read the channel-scope value from an entity's metadata.
|
|
88
|
-
*
|
|
89
|
-
* @returns The channel ID string, or `null` if the entity has no scope set.
|
|
90
|
-
*/
|
|
91
|
-
function getChannelScope(entity) {
|
|
92
|
-
var _a;
|
|
93
|
-
var value = (_a = entity.metadata) === null || _a === void 0 ? void 0 : _a[exports.CHANNEL_SCOPE_KEY];
|
|
94
|
-
return typeof value === 'string' && value.length > 0 ? value : null;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Check if an entity is scoped to a specific channel.
|
|
98
|
-
*
|
|
99
|
-
* @param entity - Any entity with optional `metadata`
|
|
100
|
-
* @param channelId - Channel ID to match against
|
|
101
|
-
* @returns `true` if entity's metadata contains a matching scope key
|
|
102
|
-
*/
|
|
103
|
-
function isScopedToChannel(entity, channelId) {
|
|
104
|
-
return getChannelScope(entity) === channelId;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Check if an entity has **no** channel scope (i.e. it is "global").
|
|
108
|
-
*/
|
|
109
|
-
function isGlobalEntity(entity) {
|
|
110
|
-
return getChannelScope(entity) === null;
|
|
111
|
-
}
|
|
112
|
-
// ────────────────────────────────────────────────────────────────────
|
|
113
|
-
// Filters
|
|
114
|
-
// ────────────────────────────────────────────────────────────────────
|
|
115
|
-
/**
|
|
116
|
-
* Filter an array of entities to only those belonging to a channel.
|
|
117
|
-
*
|
|
118
|
-
* If `channelId` is `undefined` or empty, returns the full array unfiltered.
|
|
119
|
-
* This preserves backward compatibility for admin views that intentionally
|
|
120
|
-
* list all entities regardless of tenant.
|
|
121
|
-
*
|
|
122
|
-
* @param entities - Array of channel-scopeable entities
|
|
123
|
-
* @param channelId - Optional channel ID to filter by
|
|
124
|
-
* @returns Filtered (or unfiltered) array
|
|
125
|
-
*
|
|
126
|
-
* @example
|
|
127
|
-
* ```typescript
|
|
128
|
-
* const allCustomers = await commerce.getCustomers();
|
|
129
|
-
* const myCustomers = filterByChannel(allCustomers, salesChannelId);
|
|
130
|
-
* ```
|
|
131
|
-
*/
|
|
132
|
-
function filterByChannel(entities, channelId) {
|
|
133
|
-
if (!channelId)
|
|
134
|
-
return entities;
|
|
135
|
-
return entities.filter(function (e) { return isScopedToChannel(e, channelId); });
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Filter an array of entities to only those that are global (unscoped).
|
|
139
|
-
*
|
|
140
|
-
* Useful for admin views that want to list entities not yet assigned to
|
|
141
|
-
* any channel.
|
|
142
|
-
*/
|
|
143
|
-
function filterGlobalOnly(entities) {
|
|
144
|
-
return entities.filter(isGlobalEntity);
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Partition entities into `{ scoped, global }` groups.
|
|
148
|
-
*
|
|
149
|
-
* @param entities - Array of channel-scopeable entities
|
|
150
|
-
* @param channelId - Channel ID to partition against
|
|
151
|
-
* @returns Object with `scoped` (matching channel) and `global` (no scope) arrays
|
|
152
|
-
*
|
|
153
|
-
* @example
|
|
154
|
-
* ```typescript
|
|
155
|
-
* const { scoped, global } = partitionByChannel(customers, 'sc_123');
|
|
156
|
-
* // scoped → customers assigned to sc_123
|
|
157
|
-
* // global → customers not assigned to any channel
|
|
158
|
-
* ```
|
|
159
|
-
*/
|
|
160
|
-
function partitionByChannel(entities, channelId) {
|
|
161
|
-
var scoped = [];
|
|
162
|
-
var global = [];
|
|
163
|
-
for (var _i = 0, entities_1 = entities; _i < entities_1.length; _i++) {
|
|
164
|
-
var entity = entities_1[_i];
|
|
165
|
-
if (isScopedToChannel(entity, channelId)) {
|
|
166
|
-
scoped.push(entity);
|
|
167
|
-
}
|
|
168
|
-
else if (isGlobalEntity(entity)) {
|
|
169
|
-
global.push(entity);
|
|
170
|
-
}
|
|
171
|
-
// Entities scoped to a *different* channel are silently excluded.
|
|
172
|
-
}
|
|
173
|
-
return { scoped: scoped, global: global };
|
|
174
|
-
}
|
package/src/metadata/index.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Metadata — Channel Scope Utilities
|
|
4
|
-
*
|
|
5
|
-
* Backend-agnostic helpers for multi-tenant channel scoping.
|
|
6
|
-
* Used by L2 adapters to tag, validate and filter entities by sales channel.
|
|
7
|
-
*
|
|
8
|
-
* @module metadata
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.assertEntityBelongsToChannel = exports.validateChannelScopeAssignment = exports.validateAssignedBy = exports.validateEntityId = exports.validateChannelId = exports.ChannelScopeValidationError = exports.partitionByChannel = exports.filterGlobalOnly = exports.filterByChannel = exports.isGlobalEntity = exports.isScopedToChannel = exports.getChannelScope = exports.buildChannelScopeMetadata = exports.CHANNEL_ASSIGNED_BY_KEY = exports.CHANNEL_ASSIGNED_AT_KEY = exports.CHANNEL_SCOPE_KEY = void 0;
|
|
12
|
-
// Builders, readers & filters
|
|
13
|
-
var channel_scope_1 = require("./channel-scope");
|
|
14
|
-
Object.defineProperty(exports, "CHANNEL_SCOPE_KEY", { enumerable: true, get: function () { return channel_scope_1.CHANNEL_SCOPE_KEY; } });
|
|
15
|
-
Object.defineProperty(exports, "CHANNEL_ASSIGNED_AT_KEY", { enumerable: true, get: function () { return channel_scope_1.CHANNEL_ASSIGNED_AT_KEY; } });
|
|
16
|
-
Object.defineProperty(exports, "CHANNEL_ASSIGNED_BY_KEY", { enumerable: true, get: function () { return channel_scope_1.CHANNEL_ASSIGNED_BY_KEY; } });
|
|
17
|
-
Object.defineProperty(exports, "buildChannelScopeMetadata", { enumerable: true, get: function () { return channel_scope_1.buildChannelScopeMetadata; } });
|
|
18
|
-
Object.defineProperty(exports, "getChannelScope", { enumerable: true, get: function () { return channel_scope_1.getChannelScope; } });
|
|
19
|
-
Object.defineProperty(exports, "isScopedToChannel", { enumerable: true, get: function () { return channel_scope_1.isScopedToChannel; } });
|
|
20
|
-
Object.defineProperty(exports, "isGlobalEntity", { enumerable: true, get: function () { return channel_scope_1.isGlobalEntity; } });
|
|
21
|
-
Object.defineProperty(exports, "filterByChannel", { enumerable: true, get: function () { return channel_scope_1.filterByChannel; } });
|
|
22
|
-
Object.defineProperty(exports, "filterGlobalOnly", { enumerable: true, get: function () { return channel_scope_1.filterGlobalOnly; } });
|
|
23
|
-
Object.defineProperty(exports, "partitionByChannel", { enumerable: true, get: function () { return channel_scope_1.partitionByChannel; } });
|
|
24
|
-
// Validation
|
|
25
|
-
var channel_scope_validation_1 = require("./channel-scope-validation");
|
|
26
|
-
Object.defineProperty(exports, "ChannelScopeValidationError", { enumerable: true, get: function () { return channel_scope_validation_1.ChannelScopeValidationError; } });
|
|
27
|
-
Object.defineProperty(exports, "validateChannelId", { enumerable: true, get: function () { return channel_scope_validation_1.validateChannelId; } });
|
|
28
|
-
Object.defineProperty(exports, "validateEntityId", { enumerable: true, get: function () { return channel_scope_validation_1.validateEntityId; } });
|
|
29
|
-
Object.defineProperty(exports, "validateAssignedBy", { enumerable: true, get: function () { return channel_scope_validation_1.validateAssignedBy; } });
|
|
30
|
-
Object.defineProperty(exports, "validateChannelScopeAssignment", { enumerable: true, get: function () { return channel_scope_validation_1.validateChannelScopeAssignment; } });
|
|
31
|
-
Object.defineProperty(exports, "assertEntityBelongsToChannel", { enumerable: true, get: function () { return channel_scope_validation_1.assertEntityBelongsToChannel; } });
|