@sixtyninecommerce/admin 0.8.0 → 0.9.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 (161) hide show
  1. package/README.md +2445 -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 +489 -0
  28. package/dist/catalog/products.js +365 -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 +274 -0
  34. package/dist/catalog/variants.js +258 -0
  35. package/dist/catalog/visibility.d.ts +57 -0
  36. package/dist/catalog/visibility.js +59 -0
  37. package/dist/client.d.ts +171 -3
  38. package/dist/client.js +81 -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 +360 -0
  66. package/dist/fulfillments/index.js +425 -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 +84 -9
  74. package/dist/index.js +16 -1
  75. package/dist/jobs/bulk-action-run.d.ts +65 -0
  76. package/dist/jobs/bulk-action-run.js +70 -0
  77. package/dist/locations/index.d.ts +6 -2
  78. package/dist/meta/index.d.ts +32 -0
  79. package/dist/orders/commit-edit.d.ts +123 -0
  80. package/dist/orders/commit-edit.js +142 -0
  81. package/dist/orders/get.d.ts +722 -0
  82. package/dist/orders/get.js +530 -0
  83. package/dist/orders/index.d.ts +105 -20
  84. package/dist/orders/index.js +44 -0
  85. package/dist/orders/line-price-preview.d.ts +297 -0
  86. package/dist/orders/line-price-preview.js +50 -0
  87. package/dist/orders/manual-discounts.d.ts +132 -0
  88. package/dist/orders/manual-discounts.js +95 -0
  89. package/dist/orders/manual-pricing.d.ts +192 -0
  90. package/dist/orders/manual-pricing.js +72 -0
  91. package/dist/orders/order-entry.d.ts +566 -0
  92. package/dist/orders/order-entry.js +129 -0
  93. package/dist/orders/parcel-charge.d.ts +45 -0
  94. package/dist/orders/parcel-charge.js +55 -0
  95. package/dist/orders/plan-edit.d.ts +489 -0
  96. package/dist/orders/plan-edit.js +93 -0
  97. package/dist/orders/status.d.ts +235 -0
  98. package/dist/orders/status.js +96 -0
  99. package/dist/orders/surcharges.d.ts +75 -2
  100. package/dist/orders/surcharges.js +110 -4
  101. package/dist/payments/account-credit.d.ts +171 -0
  102. package/dist/payments/account-credit.js +107 -0
  103. package/dist/payments/index.d.ts +234 -9
  104. package/dist/payments/index.js +90 -0
  105. package/dist/platform/catalog.d.ts +148 -0
  106. package/dist/platform/catalog.js +74 -0
  107. package/dist/platform/entitlements.d.ts +111 -0
  108. package/dist/platform/entitlements.js +86 -0
  109. package/dist/platform/legal-entities.d.ts +139 -0
  110. package/dist/platform/legal-entities.js +126 -0
  111. package/dist/platform/legal-entity-numbering.d.ts +103 -0
  112. package/dist/platform/legal-entity-numbering.js +101 -0
  113. package/dist/platform/organization-membership.d.ts +80 -0
  114. package/dist/platform/organization-membership.js +71 -0
  115. package/dist/platform/organization-settings.d.ts +33 -0
  116. package/dist/platform/organization-settings.js +42 -0
  117. package/dist/platform/organization-sharing.d.ts +172 -0
  118. package/dist/platform/organization-sharing.js +120 -0
  119. package/dist/platform/organizations.d.ts +205 -0
  120. package/dist/platform/organizations.js +180 -0
  121. package/dist/platform/provision-store.d.ts +88 -8
  122. package/dist/platform/provision-store.js +12 -0
  123. package/dist/platform/reports.d.ts +46 -0
  124. package/dist/platform/reports.js +31 -0
  125. package/dist/platform/server-metrics.d.ts +58 -0
  126. package/dist/platform/server-metrics.js +11 -0
  127. package/dist/pos/index.d.ts +567 -0
  128. package/dist/pos/index.js +205 -0
  129. package/dist/pricing/index.d.ts +405 -0
  130. package/dist/pricing/index.js +351 -0
  131. package/dist/provenance/index.d.ts +93 -0
  132. package/dist/provenance/index.js +53 -0
  133. package/dist/reports/index.d.ts +199 -0
  134. package/dist/reports/index.js +154 -0
  135. package/dist/shipping/parcel-count-suggestion.d.ts +52 -0
  136. package/dist/shipping/parcel-count-suggestion.js +73 -0
  137. package/dist/shipping/parcel-rule.d.ts +48 -0
  138. package/dist/shipping/parcel-rule.js +91 -0
  139. package/dist/stock/index.d.ts +166 -0
  140. package/dist/stock/index.js +115 -0
  141. package/dist/stock/transfers.d.ts +520 -0
  142. package/dist/stock/transfers.js +437 -0
  143. package/dist/stored-value/index.d.ts +154 -0
  144. package/dist/stored-value/index.js +130 -0
  145. package/dist/tenant/capabilities.d.ts +10 -0
  146. package/dist/tenant/entitlements.d.ts +35 -0
  147. package/dist/tenant/entitlements.js +15 -0
  148. package/dist/tenant/field-groups.d.ts +64 -0
  149. package/dist/tenant/field-groups.js +34 -0
  150. package/dist/tenant/legal-entity.d.ts +32 -0
  151. package/dist/tenant/legal-entity.js +41 -0
  152. package/dist/tenant/notifications.d.ts +148 -0
  153. package/dist/tenant/notifications.js +79 -0
  154. package/dist/tenant/retention.d.ts +10 -4
  155. package/dist/tenant/settings-sources.d.ts +103 -0
  156. package/dist/tenant/settings-sources.js +92 -0
  157. package/dist/types.d.ts +86 -11
  158. package/dist/uploads/index.d.ts +11 -7
  159. package/dist/users/index.d.ts +104 -0
  160. package/dist/users/index.js +80 -0
  161. package/package.json +3 -2
@@ -0,0 +1,164 @@
1
+ import { UpstreamError, ValidationError } from '@sixtyninecommerce/core';
2
+ import { assertDeleted, CATALOGUE_OWNERSHIP_FIELDS, DELETION_FIELDS, fieldOf, unwrapResult, vendureListPage, } from './types.js';
3
+ /**
4
+ * An asset's own fields, without `catalogueOwnership`: what a read outside the catalogue (the
5
+ * settings images) selects, so it keeps working against an engine older than the field.
6
+ */
7
+ export const ASSET_FILE_FIELDS = /* GraphQL */ `
8
+ id
9
+ createdAt
10
+ updatedAt
11
+ name
12
+ type
13
+ mimeType
14
+ fileSize
15
+ width
16
+ height
17
+ source
18
+ preview
19
+ focalPoint {
20
+ x
21
+ y
22
+ }
23
+ tags {
24
+ value
25
+ }
26
+ `;
27
+ export const ASSET_FIELDS = /* GraphQL */ `
28
+ ${ASSET_FILE_FIELDS}
29
+ ${CATALOGUE_OWNERSHIP_FIELDS}
30
+ `;
31
+ export const ASSETS_QUERY = /* GraphQL */ `
32
+ query CatalogAssets($options: AssetListOptions) {
33
+ assets(options: $options) {
34
+ items { ${ASSET_FIELDS} }
35
+ totalItems
36
+ }
37
+ }
38
+ `;
39
+ export const ASSET_QUERY = /* GraphQL */ `
40
+ query CatalogAsset($id: ID!) {
41
+ asset(id: $id) { ${ASSET_FIELDS} }
42
+ }
43
+ `;
44
+ export const CREATE_ASSETS_MUTATION = /* GraphQL */ `
45
+ mutation CatalogCreateAssets($input: [CreateAssetInput!]!) {
46
+ createAssets(input: $input) {
47
+ ... on Asset { ${ASSET_FIELDS} }
48
+ ... on ErrorResult {
49
+ errorCode
50
+ message
51
+ }
52
+ }
53
+ }
54
+ `;
55
+ export const UPDATE_ASSET_MUTATION = /* GraphQL */ `
56
+ mutation CatalogUpdateAsset($input: UpdateAssetInput!) {
57
+ updateAsset(input: $input) { ${ASSET_FIELDS} }
58
+ }
59
+ `;
60
+ export const DELETE_ASSET_MUTATION = /* GraphQL */ `
61
+ mutation CatalogDeleteAsset($input: DeleteAssetInput!) {
62
+ deleteAsset(input: $input) { ${DELETION_FIELDS} }
63
+ }
64
+ `;
65
+ export const SET_ASSET_DESCRIPTIONS_MUTATION = /* GraphQL */ `
66
+ mutation CatalogSetAssetDescriptions(
67
+ $assetId: ID!
68
+ $descriptions: [AssetDescriptionInput!]!
69
+ ) {
70
+ setAssetDescriptions(assetId: $assetId, descriptions: $descriptions) {
71
+ assetId
72
+ descriptions {
73
+ languageCode
74
+ description
75
+ }
76
+ altText
77
+ }
78
+ }
79
+ `;
80
+ export function toAsset(wire) {
81
+ return { ...wire, tags: wire.tags.map((tag) => tag.value) };
82
+ }
83
+ /** A `File` without depending on the DOM lib: anything Blob-like carrying a `name`. */
84
+ function nameOf(file) {
85
+ const name = file.name;
86
+ return typeof name === 'string' && name !== '' ? name : undefined;
87
+ }
88
+ export function createAssetsModule(transport) {
89
+ return {
90
+ descriptions: {
91
+ async get(assetId, options) {
92
+ const body = await transport.rest('cms', {
93
+ method: 'GET',
94
+ path: `/vendure-assets/${encodeURIComponent(assetId)}/descriptions`,
95
+ }, options);
96
+ return (body.data ?? []).map(({ languageCode, description }) => ({
97
+ languageCode,
98
+ description,
99
+ }));
100
+ },
101
+ set: (assetId, descriptions, options) => fieldOf(transport, SET_ASSET_DESCRIPTIONS_MUTATION, 'setAssetDescriptions', {
102
+ assetId,
103
+ descriptions: descriptions.map(({ languageCode, description }) => ({
104
+ languageCode,
105
+ description,
106
+ })),
107
+ }, options),
108
+ },
109
+ list: (options) => vendureListPage(transport, ASSETS_QUERY, 'assets', (skip, take) => ({
110
+ options: {
111
+ skip,
112
+ take,
113
+ ...(options?.name !== undefined
114
+ ? { filter: { name: { contains: options.name } } }
115
+ : {}),
116
+ ...(options?.tags !== undefined ? { tags: options.tags, tagsOperator: 'AND' } : {}),
117
+ },
118
+ }), options, toAsset),
119
+ async get(id, options) {
120
+ const wire = await fieldOf(transport, ASSET_QUERY, 'asset', { id }, options);
121
+ return wire ? toAsset(wire) : null;
122
+ },
123
+ async create(input, options) {
124
+ const fileName = input.fileName ?? nameOf(input.file);
125
+ if (fileName === undefined || fileName.trim() === '') {
126
+ throw new ValidationError({
127
+ code: 'ASSET_FILE_NAME_REQUIRED',
128
+ message: 'An asset needs a file name: pass fileName, or a File that carries one. A bare Blob would be stored as "blob".',
129
+ status: 400,
130
+ service: 'vendure',
131
+ });
132
+ }
133
+ const file = nameOf(input.file) === fileName
134
+ ? input.file
135
+ : new File([input.file], fileName, { type: input.file.type });
136
+ const data = await transport.graphql({
137
+ api: 'admin',
138
+ query: CREATE_ASSETS_MUTATION,
139
+ variables: {
140
+ input: [{ file: null, ...(input.tags !== undefined ? { tags: input.tags } : {}) }],
141
+ },
142
+ files: new Map([['variables.input.0.file', file]]),
143
+ }, options);
144
+ const created = data.createAssets;
145
+ if (!Array.isArray(created) || created.length === 0) {
146
+ throw new UpstreamError({
147
+ code: 'UNEXPECTED_RESPONSE',
148
+ message: 'The engine answered createAssets without the asset it created.',
149
+ status: 502,
150
+ service: 'vendure',
151
+ });
152
+ }
153
+ const first = created[0];
154
+ return toAsset(unwrapResult(first));
155
+ },
156
+ async update(input, options) {
157
+ return toAsset(await fieldOf(transport, UPDATE_ASSET_MUTATION, 'updateAsset', { input }, options));
158
+ },
159
+ async delete(id, options) {
160
+ const response = await fieldOf(transport, DELETE_ASSET_MUTATION, 'deleteAsset', { input: { assetId: id, force: options?.force ?? false } }, options);
161
+ assertDeleted('ASSET_NOT_DELETED', [response]);
162
+ },
163
+ };
164
+ }
@@ -0,0 +1,109 @@
1
+ import type { Page, Transport } from '@sixtyninecommerce/core';
2
+ import type { Call, ListOptions } from '../types.js';
3
+ import { type AssetRef, type CatalogueOwnership, type ConfigurableOperation, type ConfigurableOperationInput, type LanguageCode } from './types.js';
4
+ /**
5
+ * A collection. Membership is DERIVED: the engine applies `filters` (and the
6
+ * parent's, when `inheritFilters`) and recomputes the member variants in a
7
+ * background job after every write, so a product appears in a collection
8
+ * shortly after the call returns, not during it.
9
+ *
10
+ * The filters this platform ships: `facet-value-filter`, `variant-name-filter`,
11
+ * `product-id-filter` (arguments `productIds` — a JSON array of ids as a
12
+ * string — and `combineWithAnd`), `variant-id-filter`, and the import
13
+ * pipeline's `pipeline-manual-assignment`. The Admin API's
14
+ * `collectionFilters` query lists them with their argument definitions.
15
+ */
16
+ export interface Collection {
17
+ id: string;
18
+ createdAt: string;
19
+ updatedAt: string;
20
+ name: string;
21
+ slug: string;
22
+ description: string;
23
+ isPrivate: boolean;
24
+ /** The root collection's id for a top-level collection. */
25
+ parentId: string;
26
+ position: number;
27
+ inheritFilters: boolean;
28
+ filters: ConfigurableOperation[];
29
+ featuredAsset: AssetRef | null;
30
+ assets: AssetRef[];
31
+ breadcrumbs: Array<{
32
+ id: string;
33
+ name: string;
34
+ slug: string;
35
+ }>;
36
+ /** How many variants the last membership run matched. */
37
+ productVariantCount: number;
38
+ translations: Array<{
39
+ id: string;
40
+ languageCode: LanguageCode;
41
+ name: string;
42
+ slug: string;
43
+ description: string;
44
+ }>;
45
+ /** The store's own collection, or its organization's; see {@link CatalogueOwnership}. */
46
+ catalogueOwnership: CatalogueOwnership;
47
+ }
48
+ export interface CollectionTranslationInput {
49
+ languageCode: LanguageCode;
50
+ name: string;
51
+ slug: string;
52
+ description: string;
53
+ }
54
+ export interface CreateCollectionInput {
55
+ translations: CollectionTranslationInput[];
56
+ /** Replaces the whole filter list on update — send every filter the collection keeps. */
57
+ filters: ConfigurableOperationInput[];
58
+ parentId?: string;
59
+ isPrivate?: boolean;
60
+ inheritFilters?: boolean;
61
+ featuredAssetId?: string | null;
62
+ assetIds?: string[];
63
+ }
64
+ export interface UpdateCollectionInput extends Partial<Omit<CreateCollectionInput, 'translations'>> {
65
+ id: string;
66
+ /** On update a translation may name its row `id`; the four fields stay required by the engine. */
67
+ translations?: Array<CollectionTranslationInput & {
68
+ id?: string;
69
+ }>;
70
+ }
71
+ export interface CollectionListOptions extends ListOptions {
72
+ /** Only the direct children of this collection. */
73
+ parentId?: string;
74
+ /** Case-insensitive substring of the name. */
75
+ name?: string;
76
+ }
77
+ /**
78
+ * Collections. Reading needs `ReadCatalog` (or `ReadCollection`), writing the
79
+ * matching Create/Update/Delete permission.
80
+ *
81
+ * Refusals in the engine's words: "Cannot move a Collection into itself" on
82
+ * `move` (`ValidationError`), an unknown id as `NotFoundError`
83
+ * (`ENTITY_NOT_FOUND`), and a refused delete as `ConflictError`
84
+ * (`COLLECTION_NOT_DELETED`) with the engine's message. Deleting a collection
85
+ * deletes its descendants too.
86
+ *
87
+ * There is no `addProducts`: a manual collection's list lives INSIDE its
88
+ * `product-id-filter` arguments, so adding one product is a read-modify-write
89
+ * of the whole filter list, and doing that from a client (`update`) races
90
+ * every other writer. To put a product in collections, or take it out, use
91
+ * `catalog.products.setCollections`, which the engine runs under a row lock.
92
+ */
93
+ export interface CollectionsModule {
94
+ list(options?: CollectionListOptions): Promise<Page<Collection>>;
95
+ get(id: string, options?: Call): Promise<Collection | null>;
96
+ create(input: CreateCollectionInput, options?: Call): Promise<Collection>;
97
+ update(input: UpdateCollectionInput, options?: Call): Promise<Collection>;
98
+ delete(id: string, options?: Call): Promise<void>;
99
+ /** Re-parent and/or reorder: `index` is the position among the new parent's children. */
100
+ move(collectionId: string, parentId: string, index: number, options?: Call): Promise<Collection>;
101
+ }
102
+ export declare const COLLECTION_FIELDS = "\n id\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n createdAt\n updatedAt\n name\n slug\n description\n isPrivate\n parentId\n position\n inheritFilters\n filters {\n code\n args {\n name\n value\n }\n }\n featuredAsset { \n id\n name\n preview\n source\n }\n assets { \n id\n name\n preview\n source\n }\n breadcrumbs {\n id\n name\n slug\n }\n productVariantCount\n translations {\n id\n languageCode\n name\n slug\n description\n }\n";
103
+ export declare const COLLECTIONS_QUERY = "\n query CatalogCollections($options: CollectionListOptions) {\n collections(options: $options) {\n items { \n id\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n createdAt\n updatedAt\n name\n slug\n description\n isPrivate\n parentId\n position\n inheritFilters\n filters {\n code\n args {\n name\n value\n }\n }\n featuredAsset { \n id\n name\n preview\n source\n }\n assets { \n id\n name\n preview\n source\n }\n breadcrumbs {\n id\n name\n slug\n }\n productVariantCount\n translations {\n id\n languageCode\n name\n slug\n description\n }\n }\n totalItems\n }\n }\n";
104
+ export declare const COLLECTION_QUERY = "\n query CatalogCollection($id: ID!) {\n collection(id: $id) { \n id\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n createdAt\n updatedAt\n name\n slug\n description\n isPrivate\n parentId\n position\n inheritFilters\n filters {\n code\n args {\n name\n value\n }\n }\n featuredAsset { \n id\n name\n preview\n source\n }\n assets { \n id\n name\n preview\n source\n }\n breadcrumbs {\n id\n name\n slug\n }\n productVariantCount\n translations {\n id\n languageCode\n name\n slug\n description\n }\n }\n }\n";
105
+ export declare const CREATE_COLLECTION_MUTATION = "\n mutation CatalogCreateCollection($input: CreateCollectionInput!) {\n createCollection(input: $input) { \n id\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n createdAt\n updatedAt\n name\n slug\n description\n isPrivate\n parentId\n position\n inheritFilters\n filters {\n code\n args {\n name\n value\n }\n }\n featuredAsset { \n id\n name\n preview\n source\n }\n assets { \n id\n name\n preview\n source\n }\n breadcrumbs {\n id\n name\n slug\n }\n productVariantCount\n translations {\n id\n languageCode\n name\n slug\n description\n }\n }\n }\n";
106
+ export declare const UPDATE_COLLECTION_MUTATION = "\n mutation CatalogUpdateCollection($input: UpdateCollectionInput!) {\n updateCollection(input: $input) { \n id\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n createdAt\n updatedAt\n name\n slug\n description\n isPrivate\n parentId\n position\n inheritFilters\n filters {\n code\n args {\n name\n value\n }\n }\n featuredAsset { \n id\n name\n preview\n source\n }\n assets { \n id\n name\n preview\n source\n }\n breadcrumbs {\n id\n name\n slug\n }\n productVariantCount\n translations {\n id\n languageCode\n name\n slug\n description\n }\n }\n }\n";
107
+ export declare const DELETE_COLLECTION_MUTATION = "\n mutation CatalogDeleteCollection($id: ID!) {\n deleteCollection(id: $id) { \n result\n message\n }\n }\n";
108
+ export declare const MOVE_COLLECTION_MUTATION = "\n mutation CatalogMoveCollection($input: MoveCollectionInput!) {\n moveCollection(input: $input) { \n id\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n createdAt\n updatedAt\n name\n slug\n description\n isPrivate\n parentId\n position\n inheritFilters\n filters {\n code\n args {\n name\n value\n }\n }\n featuredAsset { \n id\n name\n preview\n source\n }\n assets { \n id\n name\n preview\n source\n }\n breadcrumbs {\n id\n name\n slug\n }\n productVariantCount\n translations {\n id\n languageCode\n name\n slug\n description\n }\n }\n }\n";
109
+ export declare function createCollectionsModule(transport: Transport): CollectionsModule;
@@ -0,0 +1,91 @@
1
+ import { ASSET_REF_FIELDS, assertDeleted, CATALOGUE_OWNERSHIP_FIELDS, DELETION_FIELDS, fieldOf, vendureListPage, } from './types.js';
2
+ export const COLLECTION_FIELDS = /* GraphQL */ `
3
+ id
4
+ ${CATALOGUE_OWNERSHIP_FIELDS}
5
+ createdAt
6
+ updatedAt
7
+ name
8
+ slug
9
+ description
10
+ isPrivate
11
+ parentId
12
+ position
13
+ inheritFilters
14
+ filters {
15
+ code
16
+ args {
17
+ name
18
+ value
19
+ }
20
+ }
21
+ featuredAsset { ${ASSET_REF_FIELDS} }
22
+ assets { ${ASSET_REF_FIELDS} }
23
+ breadcrumbs {
24
+ id
25
+ name
26
+ slug
27
+ }
28
+ productVariantCount
29
+ translations {
30
+ id
31
+ languageCode
32
+ name
33
+ slug
34
+ description
35
+ }
36
+ `;
37
+ export const COLLECTIONS_QUERY = /* GraphQL */ `
38
+ query CatalogCollections($options: CollectionListOptions) {
39
+ collections(options: $options) {
40
+ items { ${COLLECTION_FIELDS} }
41
+ totalItems
42
+ }
43
+ }
44
+ `;
45
+ export const COLLECTION_QUERY = /* GraphQL */ `
46
+ query CatalogCollection($id: ID!) {
47
+ collection(id: $id) { ${COLLECTION_FIELDS} }
48
+ }
49
+ `;
50
+ export const CREATE_COLLECTION_MUTATION = /* GraphQL */ `
51
+ mutation CatalogCreateCollection($input: CreateCollectionInput!) {
52
+ createCollection(input: $input) { ${COLLECTION_FIELDS} }
53
+ }
54
+ `;
55
+ export const UPDATE_COLLECTION_MUTATION = /* GraphQL */ `
56
+ mutation CatalogUpdateCollection($input: UpdateCollectionInput!) {
57
+ updateCollection(input: $input) { ${COLLECTION_FIELDS} }
58
+ }
59
+ `;
60
+ export const DELETE_COLLECTION_MUTATION = /* GraphQL */ `
61
+ mutation CatalogDeleteCollection($id: ID!) {
62
+ deleteCollection(id: $id) { ${DELETION_FIELDS} }
63
+ }
64
+ `;
65
+ export const MOVE_COLLECTION_MUTATION = /* GraphQL */ `
66
+ mutation CatalogMoveCollection($input: MoveCollectionInput!) {
67
+ moveCollection(input: $input) { ${COLLECTION_FIELDS} }
68
+ }
69
+ `;
70
+ export function createCollectionsModule(transport) {
71
+ return {
72
+ list: (options) => {
73
+ const filter = {};
74
+ if (options?.parentId !== undefined)
75
+ filter.parentId = { eq: options.parentId };
76
+ if (options?.name !== undefined)
77
+ filter.name = { contains: options.name };
78
+ return vendureListPage(transport, COLLECTIONS_QUERY, 'collections', (skip, take) => ({
79
+ options: { skip, take, ...(Object.keys(filter).length > 0 ? { filter } : {}) },
80
+ }), options);
81
+ },
82
+ get: (id, options) => fieldOf(transport, COLLECTION_QUERY, 'collection', { id }, options),
83
+ create: (input, options) => fieldOf(transport, CREATE_COLLECTION_MUTATION, 'createCollection', { input }, options),
84
+ update: (input, options) => fieldOf(transport, UPDATE_COLLECTION_MUTATION, 'updateCollection', { input }, options),
85
+ async delete(id, options) {
86
+ const response = await fieldOf(transport, DELETE_COLLECTION_MUTATION, 'deleteCollection', { id }, options);
87
+ assertDeleted('COLLECTION_NOT_DELETED', [response]);
88
+ },
89
+ move: (collectionId, parentId, index, options) => fieldOf(transport, MOVE_COLLECTION_MUTATION, 'moveCollection', { input: { collectionId, parentId, index } }, options),
90
+ };
91
+ }
@@ -0,0 +1,103 @@
1
+ import type { Page, Transport } from '@sixtyninecommerce/core';
2
+ import type { Call, ListOptions } from '../types.js';
3
+ import { type CatalogueOwnership, type LanguageCode, type TranslationInput } from './types.js';
4
+ export interface FacetValue {
5
+ id: string;
6
+ facetId: string;
7
+ code: string;
8
+ name: string;
9
+ translations: Array<{
10
+ id: string;
11
+ languageCode: LanguageCode;
12
+ name: string;
13
+ }>;
14
+ }
15
+ export interface Facet {
16
+ id: string;
17
+ code: string;
18
+ name: string;
19
+ /** Private facets are hidden from the Shop API. */
20
+ isPrivate: boolean;
21
+ values: FacetValue[];
22
+ translations: Array<{
23
+ id: string;
24
+ languageCode: LanguageCode;
25
+ name: string;
26
+ }>;
27
+ /** The store's own facet, or its organization's; see {@link CatalogueOwnership}. */
28
+ catalogueOwnership: CatalogueOwnership;
29
+ }
30
+ export interface FacetTranslationInput extends TranslationInput {
31
+ name?: string;
32
+ }
33
+ export interface CreateFacetInput {
34
+ code: string;
35
+ /** Defaults to false. */
36
+ isPrivate?: boolean;
37
+ translations: FacetTranslationInput[];
38
+ values?: Array<{
39
+ code: string;
40
+ translations: FacetTranslationInput[];
41
+ }>;
42
+ }
43
+ export interface UpdateFacetInput {
44
+ id: string;
45
+ code?: string;
46
+ isPrivate?: boolean;
47
+ translations?: FacetTranslationInput[];
48
+ }
49
+ export interface CreateFacetValueInput {
50
+ facetId: string;
51
+ code: string;
52
+ translations: FacetTranslationInput[];
53
+ }
54
+ export interface UpdateFacetValueInput {
55
+ id: string;
56
+ code?: string;
57
+ translations?: FacetTranslationInput[];
58
+ }
59
+ export interface FacetListOptions extends ListOptions {
60
+ /** Case-insensitive substring of the facet's name or code. */
61
+ term?: string;
62
+ }
63
+ /**
64
+ * Facets and their values. A product or variant carries values through
65
+ * `facetValueIds` on its own write.
66
+ *
67
+ * Deleting a facet or value still assigned to products is refused unless
68
+ * `force` is set, in the engine's words — "The Facet "{code}" includes
69
+ * FacetValues which are assigned to N Products" / "The FacetValue "{code}" is
70
+ * assigned to N Products" — as a `ConflictError` (`FACET_NOT_DELETED` /
71
+ * `FACET_VALUE_NOT_DELETED`). With `force` the values are removed from those
72
+ * products first.
73
+ *
74
+ * Facets that mirror a filterable PROPERTY are written by the properties
75
+ * plugin; editing them here is allowed by the engine and overwritten by the
76
+ * next property sync.
77
+ */
78
+ export interface FacetsModule {
79
+ list(options?: FacetListOptions): Promise<Page<Facet>>;
80
+ get(id: string, options?: Call): Promise<Facet | null>;
81
+ create(input: CreateFacetInput, options?: Call): Promise<Facet>;
82
+ update(input: UpdateFacetInput, options?: Call): Promise<Facet>;
83
+ delete(id: string, options?: Call & {
84
+ force?: boolean;
85
+ }): Promise<void>;
86
+ values: {
87
+ create(inputs: CreateFacetValueInput[], options?: Call): Promise<FacetValue[]>;
88
+ update(inputs: UpdateFacetValueInput[], options?: Call): Promise<FacetValue[]>;
89
+ delete(ids: string[], options?: Call & {
90
+ force?: boolean;
91
+ }): Promise<void>;
92
+ };
93
+ }
94
+ export declare const FACET_FIELDS = "\n id\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n code\n name\n isPrivate\n values { \n id\n facetId\n code\n name\n translations {\n id\n languageCode\n name\n }\n }\n translations {\n id\n languageCode\n name\n }\n";
95
+ export declare const FACETS_QUERY = "\n query CatalogFacets($options: FacetListOptions) {\n facets(options: $options) {\n items { \n id\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n code\n name\n isPrivate\n values { \n id\n facetId\n code\n name\n translations {\n id\n languageCode\n name\n }\n }\n translations {\n id\n languageCode\n name\n }\n }\n totalItems\n }\n }\n";
96
+ export declare const FACET_QUERY = "\n query CatalogFacet($id: ID!) {\n facet(id: $id) { \n id\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n code\n name\n isPrivate\n values { \n id\n facetId\n code\n name\n translations {\n id\n languageCode\n name\n }\n }\n translations {\n id\n languageCode\n name\n }\n }\n }\n";
97
+ export declare const CREATE_FACET_MUTATION = "\n mutation CatalogCreateFacet($input: CreateFacetInput!) {\n createFacet(input: $input) { \n id\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n code\n name\n isPrivate\n values { \n id\n facetId\n code\n name\n translations {\n id\n languageCode\n name\n }\n }\n translations {\n id\n languageCode\n name\n }\n }\n }\n";
98
+ export declare const UPDATE_FACET_MUTATION = "\n mutation CatalogUpdateFacet($input: UpdateFacetInput!) {\n updateFacet(input: $input) { \n id\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n code\n name\n isPrivate\n values { \n id\n facetId\n code\n name\n translations {\n id\n languageCode\n name\n }\n }\n translations {\n id\n languageCode\n name\n }\n }\n }\n";
99
+ export declare const DELETE_FACET_MUTATION = "\n mutation CatalogDeleteFacet($id: ID!, $force: Boolean) {\n deleteFacet(id: $id, force: $force) { \n result\n message\n }\n }\n";
100
+ export declare const CREATE_FACET_VALUES_MUTATION = "\n mutation CatalogCreateFacetValues($input: [CreateFacetValueInput!]!) {\n createFacetValues(input: $input) { \n id\n facetId\n code\n name\n translations {\n id\n languageCode\n name\n }\n }\n }\n";
101
+ export declare const UPDATE_FACET_VALUES_MUTATION = "\n mutation CatalogUpdateFacetValues($input: [UpdateFacetValueInput!]!) {\n updateFacetValues(input: $input) { \n id\n facetId\n code\n name\n translations {\n id\n languageCode\n name\n }\n }\n }\n";
102
+ export declare const DELETE_FACET_VALUES_MUTATION = "\n mutation CatalogDeleteFacetValues($ids: [ID!]!, $force: Boolean) {\n deleteFacetValues(ids: $ids, force: $force) { \n result\n message\n }\n }\n";
103
+ export declare function createFacetsModule(transport: Transport): FacetsModule;
@@ -0,0 +1,100 @@
1
+ import { assertDeleted, CATALOGUE_OWNERSHIP_FIELDS, DELETION_FIELDS, fieldOf, vendureListPage, } from './types.js';
2
+ const FACET_VALUE_FIELDS = /* GraphQL */ `
3
+ id
4
+ facetId
5
+ code
6
+ name
7
+ translations {
8
+ id
9
+ languageCode
10
+ name
11
+ }
12
+ `;
13
+ export const FACET_FIELDS = /* GraphQL */ `
14
+ id
15
+ ${CATALOGUE_OWNERSHIP_FIELDS}
16
+ code
17
+ name
18
+ isPrivate
19
+ values { ${FACET_VALUE_FIELDS} }
20
+ translations {
21
+ id
22
+ languageCode
23
+ name
24
+ }
25
+ `;
26
+ export const FACETS_QUERY = /* GraphQL */ `
27
+ query CatalogFacets($options: FacetListOptions) {
28
+ facets(options: $options) {
29
+ items { ${FACET_FIELDS} }
30
+ totalItems
31
+ }
32
+ }
33
+ `;
34
+ export const FACET_QUERY = /* GraphQL */ `
35
+ query CatalogFacet($id: ID!) {
36
+ facet(id: $id) { ${FACET_FIELDS} }
37
+ }
38
+ `;
39
+ export const CREATE_FACET_MUTATION = /* GraphQL */ `
40
+ mutation CatalogCreateFacet($input: CreateFacetInput!) {
41
+ createFacet(input: $input) { ${FACET_FIELDS} }
42
+ }
43
+ `;
44
+ export const UPDATE_FACET_MUTATION = /* GraphQL */ `
45
+ mutation CatalogUpdateFacet($input: UpdateFacetInput!) {
46
+ updateFacet(input: $input) { ${FACET_FIELDS} }
47
+ }
48
+ `;
49
+ export const DELETE_FACET_MUTATION = /* GraphQL */ `
50
+ mutation CatalogDeleteFacet($id: ID!, $force: Boolean) {
51
+ deleteFacet(id: $id, force: $force) { ${DELETION_FIELDS} }
52
+ }
53
+ `;
54
+ export const CREATE_FACET_VALUES_MUTATION = /* GraphQL */ `
55
+ mutation CatalogCreateFacetValues($input: [CreateFacetValueInput!]!) {
56
+ createFacetValues(input: $input) { ${FACET_VALUE_FIELDS} }
57
+ }
58
+ `;
59
+ export const UPDATE_FACET_VALUES_MUTATION = /* GraphQL */ `
60
+ mutation CatalogUpdateFacetValues($input: [UpdateFacetValueInput!]!) {
61
+ updateFacetValues(input: $input) { ${FACET_VALUE_FIELDS} }
62
+ }
63
+ `;
64
+ export const DELETE_FACET_VALUES_MUTATION = /* GraphQL */ `
65
+ mutation CatalogDeleteFacetValues($ids: [ID!]!, $force: Boolean) {
66
+ deleteFacetValues(ids: $ids, force: $force) { ${DELETION_FIELDS} }
67
+ }
68
+ `;
69
+ export function createFacetsModule(transport) {
70
+ const call = (document, field, variables, options) => fieldOf(transport, document, field, variables, options);
71
+ return {
72
+ list: (options) => vendureListPage(transport, FACETS_QUERY, 'facets', (skip, take) => ({
73
+ options: {
74
+ skip,
75
+ take,
76
+ ...(options?.term
77
+ ? {
78
+ filter: { name: { contains: options.term }, code: { contains: options.term } },
79
+ filterOperator: 'OR',
80
+ }
81
+ : {}),
82
+ },
83
+ }), options),
84
+ get: (id, options) => call(FACET_QUERY, 'facet', { id }, options),
85
+ create: (input, options) => call(CREATE_FACET_MUTATION, 'createFacet', { input: { ...input, isPrivate: input.isPrivate ?? false } }, options),
86
+ update: (input, options) => call(UPDATE_FACET_MUTATION, 'updateFacet', { input }, options),
87
+ async delete(id, options) {
88
+ const response = await call(DELETE_FACET_MUTATION, 'deleteFacet', { id, force: options?.force ?? false }, options);
89
+ assertDeleted('FACET_NOT_DELETED', [response]);
90
+ },
91
+ values: {
92
+ create: (inputs, options) => call(CREATE_FACET_VALUES_MUTATION, 'createFacetValues', { input: inputs }, options),
93
+ update: (inputs, options) => call(UPDATE_FACET_VALUES_MUTATION, 'updateFacetValues', { input: inputs }, options),
94
+ async delete(ids, options) {
95
+ const responses = await call(DELETE_FACET_VALUES_MUTATION, 'deleteFacetValues', { ids, force: options?.force ?? false }, options);
96
+ assertDeleted('FACET_VALUE_NOT_DELETED', responses);
97
+ },
98
+ },
99
+ };
100
+ }