@sixtyninecommerce/admin 0.8.0 → 0.10.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.
Files changed (179) hide show
  1. package/README.md +2739 -17
  2. package/dist/api-tokens/index.d.ts +15 -5
  3. package/dist/api-tokens/index.js +1 -0
  4. package/dist/apps/event-subscription.d.ts +59 -0
  5. package/dist/apps/event-subscription.js +32 -0
  6. package/dist/apps/hook-secret.d.ts +22 -0
  7. package/dist/apps/hook-secret.js +36 -0
  8. package/dist/apps/index.d.ts +54 -3
  9. package/dist/apps/index.js +17 -0
  10. package/dist/audit/index.d.ts +7 -0
  11. package/dist/auth/queries.d.ts +5 -1
  12. package/dist/auth/queries.js +6 -0
  13. package/dist/bulk/index.d.ts +323 -0
  14. package/dist/bulk/index.js +162 -0
  15. package/dist/catalog/assets.d.ts +147 -0
  16. package/dist/catalog/assets.js +164 -0
  17. package/dist/catalog/collections.d.ts +109 -0
  18. package/dist/catalog/collections.js +91 -0
  19. package/dist/catalog/facets.d.ts +103 -0
  20. package/dist/catalog/facets.js +100 -0
  21. package/dist/catalog/index.d.ts +115 -0
  22. package/dist/catalog/index.js +21 -0
  23. package/dist/catalog/options.d.ts +89 -0
  24. package/dist/catalog/options.js +88 -0
  25. package/dist/catalog/products-bulk.d.ts +21 -0
  26. package/dist/catalog/products-bulk.js +58 -0
  27. package/dist/catalog/products.d.ts +650 -0
  28. package/dist/catalog/products.js +458 -0
  29. package/dist/catalog/properties.d.ts +234 -0
  30. package/dist/catalog/properties.js +158 -0
  31. package/dist/catalog/types.d.ts +174 -0
  32. package/dist/catalog/types.js +141 -0
  33. package/dist/catalog/variants.d.ts +324 -0
  34. package/dist/catalog/variants.js +288 -0
  35. package/dist/catalog/visibility.d.ts +57 -0
  36. package/dist/catalog/visibility.js +59 -0
  37. package/dist/client.d.ts +192 -3
  38. package/dist/client.js +87 -12
  39. package/dist/compliance/index.d.ts +88 -0
  40. package/dist/compliance/index.js +88 -0
  41. package/dist/customer-data-redaction.d.ts +14 -0
  42. package/dist/customer-data-redaction.js +22 -0
  43. package/dist/customers/index.d.ts +428 -17
  44. package/dist/customers/index.js +322 -15
  45. package/dist/documents/index.d.ts +513 -16
  46. package/dist/documents/index.js +229 -3
  47. package/dist/events/index.d.ts +259 -0
  48. package/dist/events/index.js +147 -0
  49. package/dist/feeds/ai.d.ts +46 -0
  50. package/dist/feeds/ai.js +43 -0
  51. package/dist/feeds/categories.d.ts +50 -0
  52. package/dist/feeds/categories.js +56 -0
  53. package/dist/feeds/configs.d.ts +54 -0
  54. package/dist/feeds/configs.js +85 -0
  55. package/dist/feeds/identifier-fields.d.ts +25 -0
  56. package/dist/feeds/identifier-fields.js +29 -0
  57. package/dist/feeds/index.d.ts +54 -0
  58. package/dist/feeds/index.js +46 -0
  59. package/dist/feeds/preserve.d.ts +38 -0
  60. package/dist/feeds/preserve.js +74 -0
  61. package/dist/feeds/rules.d.ts +42 -0
  62. package/dist/feeds/rules.js +56 -0
  63. package/dist/feeds/types.d.ts +654 -0
  64. package/dist/feeds/types.js +135 -0
  65. package/dist/fulfillments/index.d.ts +437 -0
  66. package/dist/fulfillments/index.js +534 -0
  67. package/dist/heads/index.d.ts +60 -0
  68. package/dist/heads/index.js +45 -0
  69. package/dist/hooks/assignments.d.ts +90 -0
  70. package/dist/hooks/assignments.js +53 -0
  71. package/dist/hooks/index.d.ts +97 -0
  72. package/dist/hooks/index.js +76 -0
  73. package/dist/index.d.ts +95 -9
  74. package/dist/index.js +21 -1
  75. package/dist/integrations/index.d.ts +14 -0
  76. package/dist/integrations/index.js +9 -0
  77. package/dist/integrations/pipelines.d.ts +113 -0
  78. package/dist/integrations/pipelines.js +62 -0
  79. package/dist/integrations/types.d.ts +176 -0
  80. package/dist/integrations/types.js +8 -0
  81. package/dist/jobs/bulk-action-run.d.ts +74 -0
  82. package/dist/jobs/bulk-action-run.js +69 -0
  83. package/dist/locations/index.d.ts +6 -2
  84. package/dist/meta/index.d.ts +32 -0
  85. package/dist/orders/bulk.d.ts +75 -0
  86. package/dist/orders/bulk.js +150 -0
  87. package/dist/orders/commit-edit.d.ts +123 -0
  88. package/dist/orders/commit-edit.js +142 -0
  89. package/dist/orders/deposit-policy.d.ts +103 -0
  90. package/dist/orders/deposit-policy.js +202 -0
  91. package/dist/orders/get.d.ts +722 -0
  92. package/dist/orders/get.js +530 -0
  93. package/dist/orders/index.d.ts +186 -21
  94. package/dist/orders/index.js +57 -0
  95. package/dist/orders/line-price-preview.d.ts +297 -0
  96. package/dist/orders/line-price-preview.js +50 -0
  97. package/dist/orders/manual-discounts.d.ts +141 -0
  98. package/dist/orders/manual-discounts.js +97 -0
  99. package/dist/orders/manual-pricing.d.ts +192 -0
  100. package/dist/orders/manual-pricing.js +72 -0
  101. package/dist/orders/order-entry.d.ts +566 -0
  102. package/dist/orders/order-entry.js +129 -0
  103. package/dist/orders/parcel-charge.d.ts +45 -0
  104. package/dist/orders/parcel-charge.js +55 -0
  105. package/dist/orders/plan-edit.d.ts +489 -0
  106. package/dist/orders/plan-edit.js +93 -0
  107. package/dist/orders/status.d.ts +235 -0
  108. package/dist/orders/status.js +96 -0
  109. package/dist/orders/surcharges.d.ts +75 -2
  110. package/dist/orders/surcharges.js +110 -4
  111. package/dist/payments/account-credit.d.ts +171 -0
  112. package/dist/payments/account-credit.js +107 -0
  113. package/dist/payments/index.d.ts +241 -9
  114. package/dist/payments/index.js +92 -0
  115. package/dist/payments/methods.d.ts +37 -0
  116. package/dist/payments/methods.js +33 -0
  117. package/dist/platform/catalog.d.ts +148 -0
  118. package/dist/platform/catalog.js +74 -0
  119. package/dist/platform/entitlements.d.ts +111 -0
  120. package/dist/platform/entitlements.js +86 -0
  121. package/dist/platform/legal-entities.d.ts +139 -0
  122. package/dist/platform/legal-entities.js +126 -0
  123. package/dist/platform/legal-entity-numbering.d.ts +103 -0
  124. package/dist/platform/legal-entity-numbering.js +101 -0
  125. package/dist/platform/organization-membership.d.ts +80 -0
  126. package/dist/platform/organization-membership.js +71 -0
  127. package/dist/platform/organization-settings.d.ts +33 -0
  128. package/dist/platform/organization-settings.js +42 -0
  129. package/dist/platform/organization-sharing.d.ts +172 -0
  130. package/dist/platform/organization-sharing.js +120 -0
  131. package/dist/platform/organizations.d.ts +205 -0
  132. package/dist/platform/organizations.js +180 -0
  133. package/dist/platform/provision-store.d.ts +88 -8
  134. package/dist/platform/provision-store.js +12 -0
  135. package/dist/platform/reports.d.ts +46 -0
  136. package/dist/platform/reports.js +31 -0
  137. package/dist/platform/server-metrics.d.ts +58 -0
  138. package/dist/platform/server-metrics.js +11 -0
  139. package/dist/pos/index.d.ts +567 -0
  140. package/dist/pos/index.js +205 -0
  141. package/dist/pricing/index.d.ts +408 -0
  142. package/dist/pricing/index.js +353 -0
  143. package/dist/pricing/vouchers.d.ts +103 -0
  144. package/dist/pricing/vouchers.js +69 -0
  145. package/dist/provenance/index.d.ts +93 -0
  146. package/dist/provenance/index.js +53 -0
  147. package/dist/reports/index.d.ts +199 -0
  148. package/dist/reports/index.js +154 -0
  149. package/dist/returns/index.d.ts +225 -0
  150. package/dist/returns/index.js +160 -0
  151. package/dist/search/index.d.ts +99 -0
  152. package/dist/search/index.js +62 -0
  153. package/dist/shipping/parcel-count-suggestion.d.ts +52 -0
  154. package/dist/shipping/parcel-count-suggestion.js +73 -0
  155. package/dist/shipping/parcel-rule.d.ts +48 -0
  156. package/dist/shipping/parcel-rule.js +91 -0
  157. package/dist/stock/index.d.ts +166 -0
  158. package/dist/stock/index.js +115 -0
  159. package/dist/stock/transfers.d.ts +520 -0
  160. package/dist/stock/transfers.js +437 -0
  161. package/dist/stored-value/index.d.ts +154 -0
  162. package/dist/stored-value/index.js +130 -0
  163. package/dist/tenant/capabilities.d.ts +10 -0
  164. package/dist/tenant/entitlements.d.ts +35 -0
  165. package/dist/tenant/entitlements.js +15 -0
  166. package/dist/tenant/field-groups.d.ts +64 -0
  167. package/dist/tenant/field-groups.js +34 -0
  168. package/dist/tenant/legal-entity.d.ts +32 -0
  169. package/dist/tenant/legal-entity.js +41 -0
  170. package/dist/tenant/notifications.d.ts +148 -0
  171. package/dist/tenant/notifications.js +79 -0
  172. package/dist/tenant/retention.d.ts +10 -4
  173. package/dist/tenant/settings-sources.d.ts +103 -0
  174. package/dist/tenant/settings-sources.js +92 -0
  175. package/dist/types.d.ts +86 -11
  176. package/dist/uploads/index.d.ts +11 -7
  177. package/dist/users/index.d.ts +104 -0
  178. package/dist/users/index.js +80 -0
  179. package/package.json +3 -2
@@ -0,0 +1,42 @@
1
+ import { NotFoundError } from '@sixtyninecommerce/core';
2
+ import { requireHumanSession } from './guard.js';
3
+ // Through `organization(id)`, like `members`: the engine applies the organization reads' access
4
+ // rule there and answers null for an unknown id. A separate document rather than a field of every
5
+ // organization read, so `get`/`list` keep working against an engine older than the field.
6
+ export const ORGANIZATION_SETTINGS_OVERRIDES_QUERY = /* GraphQL */ `
7
+ query PlatformOrganizationSettingsOverrides($id: ID!) {
8
+ organization(id: $id) {
9
+ id
10
+ settingsOverrides {
11
+ channelId
12
+ channelCode
13
+ group
14
+ overriddenAt
15
+ }
16
+ }
17
+ }
18
+ `;
19
+ export function createOrganizationSettingsMethods(transport, config) {
20
+ // As in `organizations.ts`: a SuperAdmin needs no tenant, and an organization admin's
21
+ // workspace tenant is left alone.
22
+ const unscoped = (call) => ({ ...call, allowUnscoped: true });
23
+ return {
24
+ async settingsOverrides(organizationId, call) {
25
+ requireHumanSession(config);
26
+ const data = await transport.graphql({
27
+ api: 'admin',
28
+ query: ORGANIZATION_SETTINGS_OVERRIDES_QUERY,
29
+ variables: { id: organizationId },
30
+ }, unscoped(call));
31
+ if (!data.organization) {
32
+ throw new NotFoundError({
33
+ code: 'ORGANIZATION_NOT_FOUND',
34
+ message: `No organization has the id ${organizationId}.`,
35
+ status: 404,
36
+ service: 'vendure',
37
+ });
38
+ }
39
+ return data.organization.settingsOverrides;
40
+ },
41
+ };
42
+ }
@@ -0,0 +1,172 @@
1
+ import type { Transport } from '@sixtyninecommerce/core';
2
+ import type { AdminClientConfig } from '../client.js';
3
+ import type { Call } from '../types.js';
4
+ /**
5
+ * The kinds of data the platform can share across an organization's stores
6
+ * (multi-region spec §6), in the engine's catalog order. The catalog only
7
+ * grows, so a newer engine may answer a kind this SDK does not name yet.
8
+ */
9
+ export type OrganizationSharingKind = 'catalog' | 'collections' | 'customer_groups' | 'stock_locations' | 'customers' | 'settings.email' | 'settings.branding' | 'settings.returns' | 'settings.reviews' | 'settings.quotes' | 'settings.age_verification' | 'settings.tax_display' | 'settings.numbering_formats' | 'settings.seo' | 'entitlements' | 'tax_classes' | 'roles' | 'cms_templates' | 'events_api';
10
+ /** Where one organization stands on one sharing kind. */
11
+ export interface OrganizationSharingKindState {
12
+ kind: OrganizationSharingKind | (string & {});
13
+ /** What the organization's Sharing policy page calls it. */
14
+ name: string;
15
+ /** The platform (a SuperAdmin) allows this organization to share the kind. */
16
+ allowed: boolean;
17
+ /** The organization shares it. Only ever true while `allowed`. */
18
+ enabled: boolean;
19
+ /** Member stores cannot override the organization's value. Only ever true while `enabled`. */
20
+ locked: boolean;
21
+ /** Whether the kind can be locked at all. `settings.tax_display` never can. */
22
+ lockable: boolean;
23
+ /** The multi-region phase that makes the kind take effect; until then it is only a setting. */
24
+ phase: number;
25
+ /**
26
+ * Shared by every organization with no policy (today `entitlements` and
27
+ * `roles`): always `allowed` and `enabled`, never `locked`. `allow`,
28
+ * `disallow` and `set` on it are refused `ORGANIZATION_SHARING_KIND_ALWAYS_ON`.
29
+ */
30
+ alwaysOn: boolean;
31
+ }
32
+ /**
33
+ * A settings kind being switched off in the background: more member stores use
34
+ * the organization's values than one request copies into, so a job copies them
35
+ * in batches, then switches the kind off about 35 s after the last copy (while
36
+ * `storesDone` equals `storesTotal` the run is still `running`). Until then the
37
+ * kind stays on for every store, and changing it is refused
38
+ * `ORGANIZATION_SETTINGS_SWITCH_OFF_CONFLICT` (409 `ConflictError`).
39
+ */
40
+ export interface OrganizationSettingsSwitchOff {
41
+ id: string;
42
+ organizationId: string;
43
+ kind: OrganizationSharingKind | (string & {});
44
+ /**
45
+ * `running` (the kind is still on), `completed` (it is off; every store kept
46
+ * the organization's values) or `failed` (it is still on; switch it off again
47
+ * to retry). A string on the wire: a newer engine may add a status.
48
+ */
49
+ status: 'running' | 'completed' | 'failed' | (string & {});
50
+ /** Stores copied into so far. */
51
+ storesDone: number;
52
+ /** Stores copied into so far plus the ones still to copy, as of the last batch. */
53
+ storesTotal: number;
54
+ /** A failed run's code, such as `ORGANIZATION_SETTINGS_COPY_FAILED`. */
55
+ errorCode: string | null;
56
+ /** A failed run's message for the organization admin. */
57
+ errorMessage: string | null;
58
+ createdAt: string;
59
+ updatedAt: string;
60
+ /** When it completed or failed. */
61
+ finishedAt: string | null;
62
+ }
63
+ /**
64
+ * One settings kind and its latest background switch-off while that agrees with
65
+ * the kind: a `running` run always, a `failed` one while the kind is still on, a
66
+ * `completed` one while it is off, and a settled one only until the kind's
67
+ * policy changes again. Null otherwise, and when it never needed one.
68
+ */
69
+ export interface OrganizationSettingsKindSwitchOff {
70
+ kind: OrganizationSharingKind | (string & {});
71
+ switchOff: OrganizationSettingsSwitchOff | null;
72
+ }
73
+ export interface OrganizationSharingKindInput {
74
+ organizationId: string;
75
+ kind: OrganizationSharingKind | (string & {});
76
+ }
77
+ /** Only the flags given change; an omitted one stays as it is. */
78
+ export interface SetOrganizationSharingKindInput extends OrganizationSharingKindInput {
79
+ enabled?: boolean;
80
+ locked?: boolean;
81
+ }
82
+ /**
83
+ * `admin.platform.organizations.sharing` — the organization's sharing policy,
84
+ * two gates deep (multi-region spec §6, §9): the platform ALLOWS a kind, and
85
+ * the organization admin ENABLES an allowed kind and LOCKS a lockable one for
86
+ * every member store.
87
+ *
88
+ * `allow` and `disallow` are SuperAdmin-only. `get` and `set` also answer the
89
+ * organization admin for its own organization, with the workspace channel as
90
+ * the tenant (see `admin.platform.organizations`). Every method answers the
91
+ * kind's state after the call; `get` answers every kind, the ones not allowed
92
+ * included. Unknown organization: `ORGANIZATION_NOT_FOUND` (404); a kind the
93
+ * engine does not know: `ORGANIZATION_SHARING_KIND_INVALID` (400); an
94
+ * `alwaysOn` kind to `allow`, `disallow` or `set`:
95
+ * `ORGANIZATION_SHARING_KIND_ALWAYS_ON` (422 `BusinessRuleError`).
96
+ *
97
+ * **Kinds the platform has not released yet.** A kind whose `phase` is later
98
+ * than the engine's released one can be read, switched off and withdrawn, but
99
+ * allowing it, switching it on or locking it is refused
100
+ * `ORGANIZATION_SHARING_KIND_NOT_YET_AVAILABLE` (422 `BusinessRuleError`): no
101
+ * store, worker or dashboard of that release handles it yet. It is refused,
102
+ * never queued: allow the kind again once the platform ships it.
103
+ */
104
+ export interface OrganizationSharingModule {
105
+ get(organizationId: string, call?: Call): Promise<OrganizationSharingKindState[]>;
106
+ /**
107
+ * Starts switched off and unlocked. Allowing an allowed kind changes nothing.
108
+ * A kind the platform has not released yet: `ORGANIZATION_SHARING_KIND_NOT_YET_AVAILABLE` (422).
109
+ */
110
+ allow(input: OrganizationSharingKindInput, call?: Call): Promise<OrganizationSharingKindState>;
111
+ /**
112
+ * Refused with `ORGANIZATION_SHARING_KIND_ENABLED_CONFLICT` (409) while the
113
+ * organization has the kind switched on. Withdrawing a kind that is not
114
+ * allowed changes nothing.
115
+ */
116
+ disallow(input: OrganizationSharingKindInput, call?: Call): Promise<OrganizationSharingKindState>;
117
+ /**
118
+ * Refusals: `ORGANIZATION_SHARING_KIND_NOT_ALLOWED` (403) for a kind the
119
+ * platform has not allowed; `ORGANIZATION_SHARING_KIND_NOT_YET_AVAILABLE` (422)
120
+ * to switch on or lock a kind the platform has not released yet (switching it
121
+ * off stays open); `ORGANIZATION_SHARING_LOCK_INVALID` (400) to lock
122
+ * a kind that cannot be locked; `ORGANIZATION_SHARING_DISABLED_LOCK_INVALID`
123
+ * (400) for any change that would leave the kind locked while off — send
124
+ * `{ enabled: false, locked: false }` to switch a locked kind off;
125
+ * `ORGANIZATION_SHARING_KIND_IN_USE_CONFLICT` (409) to switch off a kind
126
+ * something still depends on; `ORGANIZATION_TAX_MODE_MISMATCH` (422
127
+ * `BusinessRuleError`) to switch `catalog` on while a member store's
128
+ * `pricesIncludeTax` differs from the organization's (the message names the
129
+ * stores); `ORGANIZATION_ACCESS_DENIED` (403) for another organization.
130
+ * While `catalog` is on, a change of `pricesIncludeTax` on the organization's
131
+ * workspace or any member store is refused with
132
+ * `ORGANIZATION_TAX_MODE_LOCKED` (422).
133
+ *
134
+ * Switching a `settings.*` kind off first copies the organization's current
135
+ * values into every member store that uses them, in the same call, so their
136
+ * customers see no change. A failed copy changes nothing (422):
137
+ * `ORGANIZATION_SETTINGS_COPY_FAILED`, `ORGANIZATION_SETTINGS_COPY_UNAVAILABLE`,
138
+ * `ORGANIZATION_SETTINGS_NOT_COPIED`. When more stores use them than one
139
+ * request copies into, the answer comes at once with the kind still
140
+ * `enabled`: the switch-off runs in the background ({@link switchOffs}). While
141
+ * it runs, `set` and `disallow` on that kind are refused
142
+ * `ORGANIZATION_SETTINGS_SWITCH_OFF_CONFLICT` (409).
143
+ */
144
+ set(input: SetOrganizationSharingKindInput, call?: Call): Promise<OrganizationSharingKindState>;
145
+ /**
146
+ * Each settings kind's latest background switch-off while it agrees with the
147
+ * kind (see {@link OrganizationSettingsKindSwitchOff}), in catalog order: poll
148
+ * it while one is `running` to show "n of m stores". Not a history: a failed
149
+ * run whose kind was switched off later reads null. Same callers as `get`.
150
+ * Needs a platform release that runs switch-offs in the background: an older
151
+ * engine fails the call as a whole.
152
+ */
153
+ switchOffs(organizationId: string, call?: Call): Promise<OrganizationSettingsKindSwitchOff[]>;
154
+ /**
155
+ * One background switch-off by id; null when there is none, or it belongs to
156
+ * another organization (to an organization admin). Same callers and release
157
+ * as {@link switchOffs}.
158
+ */
159
+ switchOff(id: string, call?: Call): Promise<OrganizationSettingsSwitchOff | null>;
160
+ }
161
+ /**
162
+ * Its own document, never part of `STATE_FIELDS`: `get`, `allow`, `disallow`
163
+ * and `set` keep working against an engine that predates background
164
+ * switch-offs, which would fail any document selecting `switchOff` whole.
165
+ */
166
+ export declare const ORGANIZATION_SETTINGS_SWITCH_OFFS_QUERY = "\n query PlatformOrganizationSettingsSwitchOffs($organizationId: ID!) {\n organizationSharingPolicy(organizationId: $organizationId) {\n kind\n switchOff { \n id\n organizationId\n kind\n status\n storesDone\n storesTotal\n errorCode\n errorMessage\n createdAt\n updatedAt\n finishedAt\n }\n }\n }\n";
167
+ export declare const ORGANIZATION_SETTINGS_SWITCH_OFF_QUERY = "\n query PlatformOrganizationSettingsSwitchOff($id: ID!) {\n organizationSettingsSwitchOff(id: $id) { \n id\n organizationId\n kind\n status\n storesDone\n storesTotal\n errorCode\n errorMessage\n createdAt\n updatedAt\n finishedAt\n }\n }\n";
168
+ export declare const ORGANIZATION_SHARING_POLICY_QUERY = "\n query PlatformOrganizationSharingPolicy($organizationId: ID!) {\n organizationSharingPolicy(organizationId: $organizationId) { \n kind\n name\n allowed\n enabled\n locked\n lockable\n phase\n alwaysOn\n }\n }\n";
169
+ export declare const ALLOW_ORGANIZATION_SHARING_KIND_MUTATION = "\n mutation PlatformAllowOrganizationSharingKind($organizationId: ID!, $kind: String!) {\n allowOrganizationSharingKind(organizationId: $organizationId, kind: $kind) { \n kind\n name\n allowed\n enabled\n locked\n lockable\n phase\n alwaysOn\n }\n }\n";
170
+ export declare const DISALLOW_ORGANIZATION_SHARING_KIND_MUTATION = "\n mutation PlatformDisallowOrganizationSharingKind($organizationId: ID!, $kind: String!) {\n disallowOrganizationSharingKind(organizationId: $organizationId, kind: $kind) { \n kind\n name\n allowed\n enabled\n locked\n lockable\n phase\n alwaysOn\n }\n }\n";
171
+ export declare const SET_ORGANIZATION_SHARING_KIND_MUTATION = "\n mutation PlatformSetOrganizationSharingKind(\n $organizationId: ID!\n $kind: String!\n $enabled: Boolean\n $locked: Boolean\n ) {\n setOrganizationSharingKind(\n organizationId: $organizationId\n kind: $kind\n enabled: $enabled\n locked: $locked\n ) { \n kind\n name\n allowed\n enabled\n locked\n lockable\n phase\n alwaysOn\n }\n }\n";
172
+ export declare function createOrganizationSharingModule(transport: Transport, config: AdminClientConfig): OrganizationSharingModule;
@@ -0,0 +1,120 @@
1
+ import { requireHumanSession } from './guard.js';
2
+ const STATE_FIELDS = /* GraphQL */ `
3
+ kind
4
+ name
5
+ allowed
6
+ enabled
7
+ locked
8
+ lockable
9
+ phase
10
+ alwaysOn
11
+ `;
12
+ const SWITCH_OFF_FIELDS = /* GraphQL */ `
13
+ id
14
+ organizationId
15
+ kind
16
+ status
17
+ storesDone
18
+ storesTotal
19
+ errorCode
20
+ errorMessage
21
+ createdAt
22
+ updatedAt
23
+ finishedAt
24
+ `;
25
+ /**
26
+ * Its own document, never part of `STATE_FIELDS`: `get`, `allow`, `disallow`
27
+ * and `set` keep working against an engine that predates background
28
+ * switch-offs, which would fail any document selecting `switchOff` whole.
29
+ */
30
+ export const ORGANIZATION_SETTINGS_SWITCH_OFFS_QUERY = /* GraphQL */ `
31
+ query PlatformOrganizationSettingsSwitchOffs($organizationId: ID!) {
32
+ organizationSharingPolicy(organizationId: $organizationId) {
33
+ kind
34
+ switchOff { ${SWITCH_OFF_FIELDS} }
35
+ }
36
+ }
37
+ `;
38
+ export const ORGANIZATION_SETTINGS_SWITCH_OFF_QUERY = /* GraphQL */ `
39
+ query PlatformOrganizationSettingsSwitchOff($id: ID!) {
40
+ organizationSettingsSwitchOff(id: $id) { ${SWITCH_OFF_FIELDS} }
41
+ }
42
+ `;
43
+ export const ORGANIZATION_SHARING_POLICY_QUERY = /* GraphQL */ `
44
+ query PlatformOrganizationSharingPolicy($organizationId: ID!) {
45
+ organizationSharingPolicy(organizationId: $organizationId) { ${STATE_FIELDS} }
46
+ }
47
+ `;
48
+ export const ALLOW_ORGANIZATION_SHARING_KIND_MUTATION = /* GraphQL */ `
49
+ mutation PlatformAllowOrganizationSharingKind($organizationId: ID!, $kind: String!) {
50
+ allowOrganizationSharingKind(organizationId: $organizationId, kind: $kind) { ${STATE_FIELDS} }
51
+ }
52
+ `;
53
+ export const DISALLOW_ORGANIZATION_SHARING_KIND_MUTATION = /* GraphQL */ `
54
+ mutation PlatformDisallowOrganizationSharingKind($organizationId: ID!, $kind: String!) {
55
+ disallowOrganizationSharingKind(organizationId: $organizationId, kind: $kind) { ${STATE_FIELDS} }
56
+ }
57
+ `;
58
+ export const SET_ORGANIZATION_SHARING_KIND_MUTATION = /* GraphQL */ `
59
+ mutation PlatformSetOrganizationSharingKind(
60
+ $organizationId: ID!
61
+ $kind: String!
62
+ $enabled: Boolean
63
+ $locked: Boolean
64
+ ) {
65
+ setOrganizationSharingKind(
66
+ organizationId: $organizationId
67
+ kind: $kind
68
+ enabled: $enabled
69
+ locked: $locked
70
+ ) { ${STATE_FIELDS} }
71
+ }
72
+ `;
73
+ export function createOrganizationSharingModule(transport, config) {
74
+ // As in `organizations.ts`: a SuperAdmin needs no tenant, and an
75
+ // organization admin's workspace tenant is left alone.
76
+ const unscoped = (call) => ({ ...call, allowUnscoped: true });
77
+ const write = async (field, query, variables, call) => {
78
+ requireHumanSession(config);
79
+ const data = await transport.graphql({ api: 'admin', query, variables }, unscoped(call));
80
+ return data[field];
81
+ };
82
+ return {
83
+ async get(organizationId, call) {
84
+ requireHumanSession(config);
85
+ const data = await transport.graphql({ api: 'admin', query: ORGANIZATION_SHARING_POLICY_QUERY, variables: { organizationId } }, unscoped(call));
86
+ return data.organizationSharingPolicy;
87
+ },
88
+ allow(input, call) {
89
+ return write('allowOrganizationSharingKind', ALLOW_ORGANIZATION_SHARING_KIND_MUTATION, { organizationId: input.organizationId, kind: input.kind }, call);
90
+ },
91
+ disallow(input, call) {
92
+ return write('disallowOrganizationSharingKind', DISALLOW_ORGANIZATION_SHARING_KIND_MUTATION, { organizationId: input.organizationId, kind: input.kind }, call);
93
+ },
94
+ set(input, call) {
95
+ // Named field by field: `enabled: false` is a value and is sent; an
96
+ // omitted flag stays off the wire, which the engine reads as "unchanged".
97
+ return write('setOrganizationSharingKind', SET_ORGANIZATION_SHARING_KIND_MUTATION, {
98
+ organizationId: input.organizationId,
99
+ kind: input.kind,
100
+ enabled: input.enabled,
101
+ locked: input.locked,
102
+ }, call);
103
+ },
104
+ async switchOffs(organizationId, call) {
105
+ requireHumanSession(config);
106
+ const data = await transport.graphql({
107
+ api: 'admin',
108
+ query: ORGANIZATION_SETTINGS_SWITCH_OFFS_QUERY,
109
+ variables: { organizationId },
110
+ }, unscoped(call));
111
+ // Only the settings kinds can be switched off in the background.
112
+ return data.organizationSharingPolicy.filter((entry) => entry.kind.startsWith('settings.'));
113
+ },
114
+ async switchOff(id, call) {
115
+ requireHumanSession(config);
116
+ const data = await transport.graphql({ api: 'admin', query: ORGANIZATION_SETTINGS_SWITCH_OFF_QUERY, variables: { id } }, unscoped(call));
117
+ return data.organizationSettingsSwitchOff;
118
+ },
119
+ };
120
+ }
@@ -0,0 +1,205 @@
1
+ import { type Page, type Transport } from '@sixtyninecommerce/core';
2
+ import type { AdminClientConfig } from '../client.js';
3
+ import type { Call, ListOptions } from '../types.js';
4
+ import { type OrganizationMembershipMethods } from './organization-membership.js';
5
+ import { type OrganizationSettingsMethods } from './organization-settings.js';
6
+ import { type OrganizationSharingModule } from './organization-sharing.js';
7
+ /** How member stores share customers (multi-region spec §7.3). Values only grow. */
8
+ export type OrganizationCustomerPolicy = 'none' | 'shared_login' | 'shared_record';
9
+ /** Whether every shared product reaches every member store, or a chosen assortment does. */
10
+ export type OrganizationAssortmentMode = 'all' | 'selected';
11
+ /**
12
+ * A group of stores run together (multi-region spec §5.1). Its workspace is a
13
+ * channel of its own, `org-<code>`, which owns every record the organization
14
+ * shares with its member stores.
15
+ */
16
+ export interface Organization {
17
+ id: string;
18
+ /** Immutable: it is the workspace channel's code (`org-<code>`) and every organization role's. */
19
+ code: string;
20
+ name: string;
21
+ hubChannelId: string;
22
+ /**
23
+ * The workspace channel. Null only when that channel was hard-deleted
24
+ * underneath the organization — the link carries no foreign key.
25
+ * `pricesIncludeTax` is the organization's tax mode: every member store
26
+ * enters prices the same way (a store with the other mode is refused
27
+ * `ORGANIZATION_TAX_MODE_MISMATCH`), so it is the mode to start a new
28
+ * member store from.
29
+ */
30
+ hubChannel: {
31
+ id: string;
32
+ code: string;
33
+ pricesIncludeTax: boolean;
34
+ } | null;
35
+ /** ISO 4217 code that analytics roll member stores up into. */
36
+ reportingCurrencyCode: string;
37
+ /** A string on the wire: a newer server may answer a value this SDK does not name yet. */
38
+ customerPolicy: OrganizationCustomerPolicy | (string & {});
39
+ assortmentMode: OrganizationAssortmentMode | (string & {});
40
+ /** Member stores that still exist. */
41
+ memberCount: number;
42
+ /** ISO-8601 UTC. */
43
+ createdAt: string;
44
+ updatedAt: string;
45
+ }
46
+ export interface CreateOrganizationInput {
47
+ /**
48
+ * 2–40 characters of lowercase letters, digits and single hyphens. It can
49
+ * never change: it becomes the workspace channel code `org-<code>`, its
50
+ * storage prefix and every organization role code.
51
+ */
52
+ code: string;
53
+ name: string;
54
+ /** A Vendure `LanguageCode`, such as `en` or `nl`. */
55
+ defaultLanguageCode: string;
56
+ /** A Vendure `CurrencyCode`, such as `EUR`. */
57
+ defaultCurrencyCode: string;
58
+ /**
59
+ * ISO 3166-1 alpha-2. Picks the most specific zone containing it for any
60
+ * zone id not given. Send a country, or both zone ids — neither is refused
61
+ * with `ORGANIZATION_ZONE_INVALID`.
62
+ */
63
+ country?: string;
64
+ defaultTaxZoneId?: string;
65
+ defaultShippingZoneId?: string;
66
+ /** Defaults to true. */
67
+ pricesIncludeTax?: boolean;
68
+ /** Defaults to `defaultCurrencyCode`. */
69
+ reportingCurrencyCode?: string;
70
+ }
71
+ /** Only the fields given change. The code and the workspace channel never do. */
72
+ export interface UpdateOrganizationInput {
73
+ id: string;
74
+ name?: string;
75
+ reportingCurrencyCode?: string;
76
+ assortmentMode?: OrganizationAssortmentMode;
77
+ }
78
+ /** A plugin entitlement granted to every member store of an organization. */
79
+ export interface OrganizationPluginEntitlement {
80
+ id: string;
81
+ organizationId: string;
82
+ pluginKey: string;
83
+ /** ISO-8601 UTC. */
84
+ connectedAt: string;
85
+ connectedByUserId: string | null;
86
+ notes: string | null;
87
+ createdAt: string;
88
+ updatedAt: string;
89
+ }
90
+ export interface SetOrganizationEntitlementInput {
91
+ organizationId: string;
92
+ /** An external plugin key from the platform's plugin catalog, such as `mollie`. */
93
+ pluginKey: string;
94
+ /** `true` grants the plugin to every member store; `false` revokes it. */
95
+ connected: boolean;
96
+ /**
97
+ * Operator notes, at most 512 characters. Omitted keeps the notes already
98
+ * stored; `''` clears them.
99
+ */
100
+ notes?: string;
101
+ }
102
+ /**
103
+ * `admin.platform.organizations.entitlements` — the organization tier of plugin
104
+ * entitlements. SuperAdmin only.
105
+ */
106
+ export interface OrganizationEntitlementsModule {
107
+ /** The organization's own grants, by plugin key. Unknown id: `ORGANIZATION_NOT_FOUND`. */
108
+ list(organizationId: string, call?: Call): Promise<OrganizationPluginEntitlement[]>;
109
+ /**
110
+ * Grant or revoke a plugin for every member store at once, and answer the
111
+ * organization's grants after the change. Member stores' Engine reads see it
112
+ * immediately; the plugins service's entitlement gates follow within its
113
+ * 60-second cache. A store's OWN grant of the same plugin is untouched by a
114
+ * revoke here. Refused with `INVALID_PLUGIN_KEY`, `INVALID_ENTITLEMENT_NOTES`
115
+ * (both `ValidationError`) or `ORGANIZATION_NOT_FOUND`.
116
+ */
117
+ set(input: SetOrganizationEntitlementInput, call?: Call): Promise<OrganizationPluginEntitlement[]>;
118
+ }
119
+ /**
120
+ * `admin.platform.organizations` — creating and editing organizations
121
+ * (multi-region spec §5.1, §9).
122
+ *
123
+ * Every method needs a human session: an API token or an app credential is
124
+ * refused with `PLATFORM_REQUIRES_SESSION` before anything is sent.
125
+ *
126
+ * Two kinds of caller:
127
+ *
128
+ * - **A SuperAdmin** can call everything, with or without a tenant on the
129
+ * client — these are platform-wide operations.
130
+ * - **An organization admin** (`ManageOrganization`, not a SuperAdmin) can
131
+ * call `get`, `getByCode`, `list`, `update`, `members` and
132
+ * `settingsOverrides` for its OWN
133
+ * organization, and only with the organization's workspace channel as the
134
+ * tenant:
135
+ * `admin.withTenant({ scope: { kind: 'channel', code: 'org-<code>' } })`, or
136
+ * the same `tenant` per call. The server tells whose organization it is from
137
+ * the active channel, so anywhere else it is a `PermissionDeniedError` (403):
138
+ * `FORBIDDEN` from no tenant or a channel where the caller holds no
139
+ * `ManageOrganization`, `ORGANIZATION_ACCESS_DENIED` for another
140
+ * organization — whether or not that one exists. `list` answers just its
141
+ * own organization; `sharing.get` and `sharing.set` answer the same way.
142
+ * `create`, `registerWorkspace`, `join`, `entitlements.*`, `sharing.allow`
143
+ * and `sharing.disallow` stay SuperAdmin-only.
144
+ *
145
+ * This SDK resolves a channel code through the CMS channel mirror, where
146
+ * `create` registers the workspace. A workspace the mirror does not hold is
147
+ * refused `CHANNEL_NOT_FOUND` (404) before the request is sent;
148
+ * `registerWorkspace` puts it there.
149
+ *
150
+ * None of the writes is deduplicated by an idempotency key (they are Admin
151
+ * API mutations). `create` is safe to repeat anyway: a second create on the
152
+ * same code is refused with `ORGANIZATION_CODE_TAKEN` (a `ConflictError`, 409),
153
+ * so read it back with `getByCode`.
154
+ */
155
+ export interface PlatformOrganizationsModule extends OrganizationMembershipMethods, OrganizationSettingsMethods {
156
+ /**
157
+ * Creates the organization with its workspace channel, the seller that owns
158
+ * it and its two roles (`org-<code>-admin`, `org-<code>-viewer`), in one
159
+ * transaction, then registers the workspace in the CMS channel mirror. A
160
+ * registration that fails does not fail the create — the organization
161
+ * exists; repair it with {@link registerWorkspace}. SuperAdmin only.
162
+ * Refusals: `ORGANIZATION_CODE_TAKEN`, `HUB_CHANNEL_CODE_TAKEN`,
163
+ * `ORGANIZATION_ROLE_CODE_TAKEN` (409); `ORGANIZATION_CODE_INVALID`,
164
+ * `ORGANIZATION_NAME_INVALID`, `ORGANIZATION_LANGUAGE_INVALID`,
165
+ * `ORGANIZATION_ZONE_INVALID`, `ORGANIZATION_REPORTING_CURRENCY_INVALID` (400).
166
+ */
167
+ create(input: CreateOrganizationInput, call?: Call): Promise<Organization>;
168
+ /**
169
+ * Registers the organization's workspace channel in the CMS channel mirror,
170
+ * which is how a client scoped to `org-<code>` resolves it — the repair for a
171
+ * `create` whose registration failed. Safe to repeat: a registered workspace
172
+ * answers the same. SuperAdmin only. Refusals: `ORGANIZATION_NOT_FOUND`,
173
+ * `ORGANIZATION_WORKSPACE_NOT_FOUND` (404);
174
+ * `ORGANIZATION_WORKSPACE_REGISTRATION_FAILED` (422 `BusinessRuleError`: the
175
+ * CMS did not confirm it — try again later).
176
+ */
177
+ registerWorkspace(id: string, call?: Call): Promise<Organization>;
178
+ /**
179
+ * Name, reporting currency and assortment. Refusals: `ORGANIZATION_NOT_FOUND`
180
+ * (404), `ORGANIZATION_ACCESS_DENIED` (403), `ORGANIZATION_NAME_INVALID`,
181
+ * `ORGANIZATION_REPORTING_CURRENCY_INVALID`,
182
+ * `ORGANIZATION_ASSORTMENT_MODE_INVALID` (400).
183
+ */
184
+ update(input: UpdateOrganizationInput, call?: Call): Promise<Organization>;
185
+ /**
186
+ * Organizations by name. Pages default to 50; the server caps a page at 100
187
+ * and walking on with `.next()` or `for await` still reaches every one.
188
+ */
189
+ list(options?: ListOptions): Promise<Page<Organization>>;
190
+ /** Null when no organization has that id. */
191
+ get(id: string, call?: Call): Promise<Organization | null>;
192
+ /** The organization code, not the `org-` workspace channel code. Null when none has it. */
193
+ getByCode(code: string, call?: Call): Promise<Organization | null>;
194
+ entitlements: OrganizationEntitlementsModule;
195
+ sharing: OrganizationSharingModule;
196
+ }
197
+ export declare const ORGANIZATIONS_QUERY = "\n query PlatformOrganizations($options: OrganizationListOptions) {\n organizations(options: $options) {\n totalItems\n items { \n id\n code\n name\n hubChannelId\n hubChannel {\n id\n code\n pricesIncludeTax\n }\n reportingCurrencyCode\n customerPolicy\n assortmentMode\n memberCount\n createdAt\n updatedAt\n }\n }\n }\n";
198
+ export declare const ORGANIZATION_QUERY = "\n query PlatformOrganization($id: ID!) {\n organization(id: $id) { \n id\n code\n name\n hubChannelId\n hubChannel {\n id\n code\n pricesIncludeTax\n }\n reportingCurrencyCode\n customerPolicy\n assortmentMode\n memberCount\n createdAt\n updatedAt\n }\n }\n";
199
+ export declare const ORGANIZATION_BY_CODE_QUERY = "\n query PlatformOrganizationByCode($code: String!) {\n organizationByCode(code: $code) { \n id\n code\n name\n hubChannelId\n hubChannel {\n id\n code\n pricesIncludeTax\n }\n reportingCurrencyCode\n customerPolicy\n assortmentMode\n memberCount\n createdAt\n updatedAt\n }\n }\n";
200
+ export declare const CREATE_ORGANIZATION_MUTATION = "\n mutation PlatformCreateOrganization($input: CreateOrganizationInput!) {\n createOrganization(input: $input) { \n id\n code\n name\n hubChannelId\n hubChannel {\n id\n code\n pricesIncludeTax\n }\n reportingCurrencyCode\n customerPolicy\n assortmentMode\n memberCount\n createdAt\n updatedAt\n }\n }\n";
201
+ export declare const REGISTER_ORGANIZATION_WORKSPACE_MUTATION = "\n mutation PlatformRegisterOrganizationWorkspace($id: ID!) {\n registerOrganizationWorkspace(id: $id) { \n id\n code\n name\n hubChannelId\n hubChannel {\n id\n code\n pricesIncludeTax\n }\n reportingCurrencyCode\n customerPolicy\n assortmentMode\n memberCount\n createdAt\n updatedAt\n }\n }\n";
202
+ export declare const UPDATE_ORGANIZATION_MUTATION = "\n mutation PlatformUpdateOrganization($input: UpdateOrganizationInput!) {\n updateOrganization(input: $input) { \n id\n code\n name\n hubChannelId\n hubChannel {\n id\n code\n pricesIncludeTax\n }\n reportingCurrencyCode\n customerPolicy\n assortmentMode\n memberCount\n createdAt\n updatedAt\n }\n }\n";
203
+ export declare const ORGANIZATION_ENTITLEMENTS_QUERY = "\n query PlatformOrganizationPluginEntitlements($organizationId: ID!) {\n organizationPluginEntitlements(organizationId: $organizationId) { \n id\n organizationId\n pluginKey\n connectedAt\n connectedByUserId\n notes\n createdAt\n updatedAt\n }\n }\n";
204
+ export declare const SET_ORGANIZATION_ENTITLEMENT_MUTATION = "\n mutation PlatformSetOrganizationPluginEntitlement(\n $organizationId: ID!\n $pluginKey: String!\n $connected: Boolean!\n $notes: String\n ) {\n setOrganizationPluginEntitlement(\n organizationId: $organizationId\n pluginKey: $pluginKey\n connected: $connected\n notes: $notes\n ) { \n id\n organizationId\n pluginKey\n connectedAt\n connectedByUserId\n notes\n createdAt\n updatedAt\n }\n }\n";
205
+ export declare function createPlatformOrganizationsModule(transport: Transport, config: AdminClientConfig): PlatformOrganizationsModule;