From 1cb423cbc2020493febda8cf48a2e4fdfcf5ecd7 Mon Sep 17 00:00:00 2001 From: Pierluigi Viti Date: Thu, 6 Jun 2024 13:13:45 +0200 Subject: [PATCH] feat: update resources to schema v5.4.0 --- gen/openapi.json | 1319 ++++++++++++++++++----- specs/resources/links.spec.ts | 176 +++ specs/resources/stock_transfers.spec.ts | 19 + src/api.ts | 3 + src/commercelayer.ts | 4 +- src/model.ts | 1 + src/resources/links.ts | 116 ++ src/resources/orders.ts | 1 - src/resources/stock_transfers.ts | 7 + 9 files changed, 1402 insertions(+), 244 deletions(-) create mode 100644 specs/resources/links.spec.ts create mode 100644 src/resources/links.ts diff --git a/gen/openapi.json b/gen/openapi.json index 8d42f394..d86a292e 100644 --- a/gen/openapi.json +++ b/gen/openapi.json @@ -2,7 +2,7 @@ "openapi": "3.1.0", "info": { "title": "Commerce Layer API", - "version": "5.3.3", + "version": "5.4.0", "contact": { "name": "API Support", "url": "https://commercelayer.io", @@ -14059,6 +14059,183 @@ } } }, + "/links": { + "get": { + "operationId": "GET/links", + "summary": "List all links", + "description": "List all links", + "tags": [ + "links" + ], + "responses": { + "200": { + "description": "A list of link objects", + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/linkResponseList" + } + } + } + } + } + }, + "post": { + "operationId": "POST/links", + "summary": "Create a link", + "description": "Create a link", + "tags": [ + "links" + ], + "requestBody": { + "required": true, + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/linkCreate" + } + } + } + }, + "responses": { + "201": { + "description": "The created link object", + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/linkResponse" + } + } + } + } + } + } + }, + "/links/{linkId}": { + "get": { + "operationId": "GET/links/linkId", + "summary": "Retrieve a link", + "description": "Retrieve a link", + "tags": [ + "links" + ], + "parameters": [ + { + "name": "linkId", + "in": "path", + "schema": { + "type": "string" + }, + "required": true, + "description": "The resource's id" + } + ], + "responses": { + "200": { + "description": "The link object", + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/linkResponse" + } + } + } + } + } + }, + "patch": { + "operationId": "PATCH/links/linkId", + "summary": "Update a link", + "description": "Update a link", + "tags": [ + "links" + ], + "parameters": [ + { + "name": "linkId", + "in": "path", + "schema": { + "type": "string" + }, + "required": true, + "description": "The resource's id" + } + ], + "requestBody": { + "required": true, + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/linkUpdate" + } + } + } + }, + "responses": { + "200": { + "description": "The updated link object", + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/linkResponse" + } + } + } + } + } + }, + "delete": { + "operationId": "DELETE/links/linkId", + "summary": "Delete a link", + "description": "Delete a link", + "tags": [ + "links" + ], + "parameters": [ + { + "name": "linkId", + "in": "path", + "schema": { + "type": "string" + }, + "required": true, + "description": "The resource's id" + } + ], + "responses": { + "204": { + "description": "No content" + } + } + } + }, + "/links/{linkId}/events": { + "get": { + "operationId": "GET/linkId/events", + "summary": "Retrieve the events associated to the link", + "description": "Retrieve the events associated to the link", + "tags": [ + "has_many", + "events" + ], + "parameters": [ + { + "name": "linkId", + "in": "path", + "schema": { + "type": "string" + }, + "required": true, + "description": "The resource's id" + } + ], + "responses": { + "200": { + "description": "The events associated to the link" + } + } + } + }, "/manual_gateways": { "get": { "operationId": "GET/manual_gateways", @@ -28384,6 +28561,33 @@ } } }, + "/stock_transfers/{stockTransferId}/attachments": { + "get": { + "operationId": "GET/stockTransferId/attachments", + "summary": "Retrieve the attachments associated to the stock transfer", + "description": "Retrieve the attachments associated to the stock transfer", + "tags": [ + "has_many", + "attachments" + ], + "parameters": [ + { + "name": "stockTransferId", + "in": "path", + "schema": { + "type": "string" + }, + "required": true, + "description": "The resource's id" + } + ], + "responses": { + "200": { + "description": "The attachments associated to the stock transfer" + } + } + } + }, "/stock_transfers/{stockTransferId}/events": { "get": { "operationId": "GET/stockTransferId/events", @@ -67617,6 +67821,583 @@ } } }, + "link": { + "type": "object", + "properties": { + "data": { + "type": "object", + "required": [ + "type", + "attributes" + ], + "properties": { + "type": { + "type": "string", + "description": "The resource's type", + "enum": [ + "links" + ] + }, + "attributes": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The link internal name.", + "example": "FW SALE 2023", + "nullable": false + }, + "client_id": { + "type": "string", + "description": "The link application client id, used to fetch JWT.", + "example": "xxxx-yyyy-zzzz", + "nullable": false + }, + "scope": { + "type": "string", + "description": "The link application scope, used to fetch JWT.", + "example": "market:GhvCxsElAQ,market:kJhgVcxZDr", + "nullable": false + }, + "starts_at": { + "type": "string", + "description": "The activation date/time of this link.", + "example": "2018-01-01T12:00:00.000Z", + "nullable": false + }, + "expires_at": { + "type": "string", + "description": "The expiration date/time of this link (must be after starts_at).", + "example": "2018-01-02T12:00:00.000Z", + "nullable": false + }, + "active": { + "type": "boolean", + "description": "Indicates if the link is active (enabled and not expired).", + "example": true, + "nullable": true + }, + "status": { + "type": "string", + "description": "The link status, one of 'expired', 'pending', 'active', or 'disabled'.", + "example": "pending", + "nullable": true, + "enum": [ + "expired", + "pending", + "active", + "disabled" + ] + }, + "domain": { + "type": "string", + "description": "The link URL second level domain.", + "example": "c11r.link", + "nullable": true + }, + "url": { + "type": "string", + "description": "The link URL.", + "example": "https://acme.c11r.link/a597dd63-576e-4aff-9094-0b7d690e94d6", + "nullable": true + }, + "created_at": { + "type": "string", + "description": "Time at which the resource was created.", + "example": "2018-01-01T12:00:00.000Z", + "nullable": false + }, + "updated_at": { + "type": "string", + "description": "Time at which the resource was last updated.", + "example": "2018-01-01T12:00:00.000Z", + "nullable": false + }, + "reference": { + "type": "string", + "description": "A string that you can use to add any external identifier to the resource. This can be useful for integrating the resource to an external system, like an ERP, a marketing tool, a CRM, or whatever.", + "example": "ANY-EXTERNAL-REFEFERNCE", + "nullable": true + }, + "reference_origin": { + "type": "string", + "description": "Any identifier of the third party system that defines the reference code", + "example": "ANY-EXTERNAL-REFEFERNCE-ORIGIN", + "nullable": true + }, + "metadata": { + "type": "object", + "description": "Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format.", + "example": { + "foo": "bar" + }, + "nullable": true + }, + "disabled_at": { + "type": "string", + "description": "Time at which this resource was disabled.", + "example": "2018-01-01T12:00:00.000Z", + "nullable": true + } + } + }, + "relationships": { + "type": "object", + "properties": { + "item": { + "type": "object", + "properties": { + "data": { + "type": "object", + "properties": { + "type": { + "type": "string", + "description": "The resource's type", + "enum": [ + "orders", + "sku_lists" + ] + }, + "id": { + "type": "string", + "description": "The resource's id", + "example": "XGZwpOSrWL" + } + } + } + }, + "oneOf": [ + { + "$ref": "#/components/schemas/order" + }, + { + "$ref": "#/components/schemas/skuList" + } + ] + }, + "events": { + "type": "object", + "properties": { + "data": { + "type": "object", + "properties": { + "type": { + "type": "string", + "description": "The resource's type", + "enum": [ + "events" + ] + }, + "id": { + "type": "string", + "description": "The resource's id", + "example": "XGZwpOSrWL" + } + } + } + } + } + } + } + } + } + } + }, + "linkCreate": { + "required": [ + "data" + ], + "type": "object", + "properties": { + "data": { + "type": "object", + "required": [ + "type", + "attributes" + ], + "properties": { + "type": { + "type": "string", + "description": "The resource's type", + "enum": [ + "links" + ] + }, + "attributes": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The link internal name.", + "example": "FW SALE 2023" + }, + "client_id": { + "type": "string", + "description": "The link application client id, used to fetch JWT.", + "example": "xxxx-yyyy-zzzz" + }, + "scope": { + "type": "string", + "description": "The link application scope, used to fetch JWT.", + "example": "market:GhvCxsElAQ,market:kJhgVcxZDr" + }, + "starts_at": { + "type": "string", + "description": "The activation date/time of this link.", + "example": "2018-01-01T12:00:00.000Z" + }, + "expires_at": { + "type": "string", + "description": "The expiration date/time of this link (must be after starts_at).", + "example": "2018-01-02T12:00:00.000Z" + }, + "domain": { + "type": "string", + "description": "The link URL second level domain.", + "example": "c11r.link" + }, + "reference": { + "type": "string", + "description": "A string that you can use to add any external identifier to the resource. This can be useful for integrating the resource to an external system, like an ERP, a marketing tool, a CRM, or whatever.", + "example": "ANY-EXTERNAL-REFEFERNCE" + }, + "reference_origin": { + "type": "string", + "description": "Any identifier of the third party system that defines the reference code", + "example": "ANY-EXTERNAL-REFEFERNCE-ORIGIN" + }, + "metadata": { + "type": "object", + "description": "Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format.", + "example": { + "foo": "bar" + } + }, + "_disable": { + "type": "boolean", + "description": "Send this attribute if you want to mark this resource as disabled.", + "example": true + }, + "_enable": { + "type": "boolean", + "description": "Send this attribute if you want to mark this resource as enabled.", + "example": true + } + }, + "required": [ + "name", + "client_id", + "scope", + "starts_at", + "expires_at" + ] + }, + "relationships": { + "type": "object", + "properties": { + "item": { + "required": [ + "data" + ], + "type": "object", + "properties": { + "data": { + "type": "object", + "properties": { + "type": { + "type": "string", + "description": "The resource's type", + "enum": [ + "orders", + "sku_lists" + ] + }, + "id": { + "type": "string", + "description": "The resource's id", + "example": "XGZwpOSrWL" + } + } + } + }, + "oneOf": [ + { + "$ref": "#/components/schemas/order" + }, + { + "$ref": "#/components/schemas/skuList" + } + ] + } + }, + "required": [ + "item" + ] + } + } + } + } + }, + "linkUpdate": { + "required": [ + "data" + ], + "type": "object", + "properties": { + "data": { + "type": "object", + "required": [ + "type", + "id", + "attributes" + ], + "properties": { + "type": { + "type": "string", + "description": "The resource's type", + "enum": [ + "links" + ] + }, + "id": { + "type": "string", + "description": "The resource's id", + "example": "XGZwpOSrWL" + }, + "attributes": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The link internal name.", + "example": "FW SALE 2023", + "nullable": false + }, + "client_id": { + "type": "string", + "description": "The link application client id, used to fetch JWT.", + "example": "xxxx-yyyy-zzzz", + "nullable": false + }, + "scope": { + "type": "string", + "description": "The link application scope, used to fetch JWT.", + "example": "market:GhvCxsElAQ,market:kJhgVcxZDr", + "nullable": false + }, + "starts_at": { + "type": "string", + "description": "The activation date/time of this link.", + "example": "2018-01-01T12:00:00.000Z", + "nullable": false + }, + "expires_at": { + "type": "string", + "description": "The expiration date/time of this link (must be after starts_at).", + "example": "2018-01-02T12:00:00.000Z", + "nullable": false + }, + "domain": { + "type": "string", + "description": "The link URL second level domain.", + "example": "c11r.link", + "nullable": true + }, + "reference": { + "type": "string", + "description": "A string that you can use to add any external identifier to the resource. This can be useful for integrating the resource to an external system, like an ERP, a marketing tool, a CRM, or whatever.", + "example": "ANY-EXTERNAL-REFEFERNCE", + "nullable": true + }, + "reference_origin": { + "type": "string", + "description": "Any identifier of the third party system that defines the reference code", + "example": "ANY-EXTERNAL-REFEFERNCE-ORIGIN", + "nullable": true + }, + "metadata": { + "type": "object", + "description": "Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format.", + "example": { + "foo": "bar" + }, + "nullable": true + }, + "_disable": { + "type": "boolean", + "description": "Send this attribute if you want to mark this resource as disabled.", + "example": true, + "nullable": false + }, + "_enable": { + "type": "boolean", + "description": "Send this attribute if you want to mark this resource as enabled.", + "example": true, + "nullable": false + } + } + }, + "relationships": { + "type": "object", + "properties": { + "item": { + "required": [ + "data" + ], + "type": "object", + "properties": { + "data": { + "type": "object", + "properties": { + "type": { + "type": "string", + "description": "The resource's type", + "enum": [ + "orders", + "sku_lists" + ] + }, + "id": { + "type": "string", + "description": "The resource's id", + "example": "XGZwpOSrWL" + } + } + } + }, + "oneOf": [ + { + "$ref": "#/components/schemas/order" + }, + { + "$ref": "#/components/schemas/skuList" + } + ] + } + } + } + } + } + } + }, + "linkResponse": { + "type": "object", + "properties": { + "data": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "The resource's id", + "example": "XGZwpOSrWL" + }, + "type": { + "type": "string", + "description": "The resource's type", + "enum": [ + "links" + ] + }, + "links": { + "type": "object", + "properties": { + "self": { + "type": "string", + "description": "URL" + } + } + }, + "attributes": { + "$ref": "#/components/schemas/link/properties/data/properties/attributes" + }, + "relationships": { + "type": "object", + "properties": { + "item": { + "type": "object", + "properties": { + "links": { + "type": "object", + "properties": { + "self": { + "type": "string", + "description": "URL" + }, + "related": { + "type": "string", + "description": "URL" + } + } + }, + "data": { + "type": "object", + "properties": { + "type": { + "type": "string", + "description": "The resource's type", + "enum": [ + "item" + ] + }, + "id": { + "type": "string", + "description": "The resource ID" + } + } + } + } + }, + "events": { + "type": "object", + "properties": { + "links": { + "type": "object", + "properties": { + "self": { + "type": "string", + "description": "URL" + }, + "related": { + "type": "string", + "description": "URL" + } + } + }, + "data": { + "type": "object", + "properties": { + "type": { + "type": "string", + "description": "The resource's type", + "enum": [ + "events" + ] + }, + "id": { + "type": "string", + "description": "The resource ID" + } + } + } + } + } + } + } + } + } + } + }, + "linkResponseList": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/components/schemas/linkResponse/properties/data" + } + } + } + }, "manualGateway": { "type": "object", "properties": { @@ -74429,12 +75210,6 @@ "example": "2018-01-01T12:00:00.000Z", "nullable": true }, - "expires_at": { - "type": "string", - "description": "Time at which an order is marked for cleanup. Any order will start with a default expire time of 2 months. Expiration is reset once a line item is added to the order.", - "example": "2018-01-01T12:00:00.000Z", - "nullable": true - }, "subscription_created_at": { "type": "string", "description": "Time at which the order has been marked to create a subscription from its recurring line items.", @@ -104107,6 +104882,28 @@ } } }, + "attachments": { + "type": "object", + "properties": { + "data": { + "type": "object", + "properties": { + "type": { + "type": "string", + "description": "The resource's type", + "enum": [ + "attachments" + ] + }, + "id": { + "type": "string", + "description": "The resource's id", + "example": "XGZwpOSrWL" + } + } + } + } + }, "events": { "type": "object", "properties": { @@ -104345,31 +105142,261 @@ } } } - }, - "required": [ - "sku", - "origin_stock_location", - "destination_stock_location" - ] + }, + "required": [ + "sku", + "origin_stock_location", + "destination_stock_location" + ] + } + } + } + } + }, + "stockTransferUpdate": { + "required": [ + "data" + ], + "type": "object", + "properties": { + "data": { + "type": "object", + "required": [ + "type", + "id", + "attributes" + ], + "properties": { + "type": { + "type": "string", + "description": "The resource's type", + "enum": [ + "stock_transfers" + ] + }, + "id": { + "type": "string", + "description": "The resource's id", + "example": "XGZwpOSrWL" + }, + "attributes": { + "type": "object", + "properties": { + "number": { + "type": "string", + "description": "Unique identifier for the stock transfer (numeric).", + "example": "1234", + "nullable": true + }, + "sku_code": { + "type": "string", + "description": "The code of the associated SKU.", + "example": "TSHIRTMM000000FFFFFFXLXX", + "nullable": true + }, + "_upcoming": { + "type": "boolean", + "description": "Send this attribute if you want to mark this stock transfer as upcoming.", + "example": true, + "nullable": false + }, + "_on_hold": { + "type": "boolean", + "description": "Send this attribute if you want to put this stock transfer on hold.", + "example": true, + "nullable": false + }, + "_picking": { + "type": "boolean", + "description": "Send this attribute if you want to start picking this stock transfer.", + "example": true, + "nullable": false + }, + "_in_transit": { + "type": "boolean", + "description": "Send this attribute if you want to mark this stock transfer as in transit.", + "example": true, + "nullable": false + }, + "_complete": { + "type": "boolean", + "description": "Send this attribute if you want to complete this stock transfer.", + "example": true, + "nullable": false + }, + "_cancel": { + "type": "boolean", + "description": "Send this attribute if you want to cancel this stock transfer.", + "example": true, + "nullable": false + }, + "reference": { + "type": "string", + "description": "A string that you can use to add any external identifier to the resource. This can be useful for integrating the resource to an external system, like an ERP, a marketing tool, a CRM, or whatever.", + "example": "ANY-EXTERNAL-REFEFERNCE", + "nullable": true + }, + "reference_origin": { + "type": "string", + "description": "Any identifier of the third party system that defines the reference code", + "example": "ANY-EXTERNAL-REFEFERNCE-ORIGIN", + "nullable": true + }, + "metadata": { + "type": "object", + "description": "Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format.", + "example": { + "foo": "bar" + }, + "nullable": true + } + } + }, + "relationships": { + "type": "object", + "properties": { + "sku": { + "required": [ + "data" + ], + "type": "object", + "properties": { + "data": { + "type": "object", + "properties": { + "type": { + "type": "string", + "description": "The resource's type", + "enum": [ + "skus" + ] + }, + "id": { + "type": "string", + "description": "The resource's id", + "example": "XGZwpOSrWL" + } + } + } + } + }, + "origin_stock_location": { + "required": [ + "data" + ], + "type": "object", + "properties": { + "data": { + "type": "object", + "properties": { + "type": { + "type": "string", + "description": "The resource's type", + "enum": [ + "stock_locations" + ] + }, + "id": { + "type": "string", + "description": "The resource's id", + "example": "XGZwpOSrWL" + } + } + } + } + }, + "destination_stock_location": { + "required": [ + "data" + ], + "type": "object", + "properties": { + "data": { + "type": "object", + "properties": { + "type": { + "type": "string", + "description": "The resource's type", + "enum": [ + "stock_locations" + ] + }, + "id": { + "type": "string", + "description": "The resource's id", + "example": "XGZwpOSrWL" + } + } + } + } + }, + "shipment": { + "required": [ + "data" + ], + "type": "object", + "properties": { + "data": { + "type": "object", + "properties": { + "type": { + "type": "string", + "description": "The resource's type", + "enum": [ + "shipments" + ] + }, + "id": { + "type": "string", + "description": "The resource's id", + "example": "XGZwpOSrWL" + } + } + } + } + }, + "line_item": { + "required": [ + "data" + ], + "type": "object", + "properties": { + "data": { + "type": "object", + "properties": { + "type": { + "type": "string", + "description": "The resource's type", + "enum": [ + "line_items" + ] + }, + "id": { + "type": "string", + "description": "The resource's id", + "example": "XGZwpOSrWL" + } + } + } + } + } + } } } } } }, - "stockTransferUpdate": { - "required": [ - "data" - ], + "stockTransferResponse": { "type": "object", "properties": { "data": { "type": "object", - "required": [ - "type", - "id", - "attributes" - ], "properties": { + "id": { + "type": "string", + "description": "The resource's id", + "example": "XGZwpOSrWL" + }, "type": { "type": "string", "description": "The resource's type", @@ -104377,168 +105404,37 @@ "stock_transfers" ] }, - "id": { - "type": "string", - "description": "The resource's id", - "example": "XGZwpOSrWL" - }, - "attributes": { + "links": { "type": "object", "properties": { - "number": { - "type": "string", - "description": "Unique identifier for the stock transfer (numeric).", - "example": "1234", - "nullable": true - }, - "sku_code": { - "type": "string", - "description": "The code of the associated SKU.", - "example": "TSHIRTMM000000FFFFFFXLXX", - "nullable": true - }, - "_upcoming": { - "type": "boolean", - "description": "Send this attribute if you want to mark this stock transfer as upcoming.", - "example": true, - "nullable": false - }, - "_on_hold": { - "type": "boolean", - "description": "Send this attribute if you want to put this stock transfer on hold.", - "example": true, - "nullable": false - }, - "_picking": { - "type": "boolean", - "description": "Send this attribute if you want to start picking this stock transfer.", - "example": true, - "nullable": false - }, - "_in_transit": { - "type": "boolean", - "description": "Send this attribute if you want to mark this stock transfer as in transit.", - "example": true, - "nullable": false - }, - "_complete": { - "type": "boolean", - "description": "Send this attribute if you want to complete this stock transfer.", - "example": true, - "nullable": false - }, - "_cancel": { - "type": "boolean", - "description": "Send this attribute if you want to cancel this stock transfer.", - "example": true, - "nullable": false - }, - "reference": { - "type": "string", - "description": "A string that you can use to add any external identifier to the resource. This can be useful for integrating the resource to an external system, like an ERP, a marketing tool, a CRM, or whatever.", - "example": "ANY-EXTERNAL-REFEFERNCE", - "nullable": true - }, - "reference_origin": { + "self": { "type": "string", - "description": "Any identifier of the third party system that defines the reference code", - "example": "ANY-EXTERNAL-REFEFERNCE-ORIGIN", - "nullable": true - }, - "metadata": { - "type": "object", - "description": "Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format.", - "example": { - "foo": "bar" - }, - "nullable": true + "description": "URL" } } }, + "attributes": { + "$ref": "#/components/schemas/stockTransfer/properties/data/properties/attributes" + }, "relationships": { "type": "object", "properties": { "sku": { - "required": [ - "data" - ], "type": "object", "properties": { - "data": { - "type": "object", - "properties": { - "type": { - "type": "string", - "description": "The resource's type", - "enum": [ - "skus" - ] - }, - "id": { - "type": "string", - "description": "The resource's id", - "example": "XGZwpOSrWL" - } - } - } - } - }, - "origin_stock_location": { - "required": [ - "data" - ], - "type": "object", - "properties": { - "data": { - "type": "object", - "properties": { - "type": { - "type": "string", - "description": "The resource's type", - "enum": [ - "stock_locations" - ] - }, - "id": { - "type": "string", - "description": "The resource's id", - "example": "XGZwpOSrWL" - } - } - } - } - }, - "destination_stock_location": { - "required": [ - "data" - ], - "type": "object", - "properties": { - "data": { + "links": { "type": "object", "properties": { - "type": { + "self": { "type": "string", - "description": "The resource's type", - "enum": [ - "stock_locations" - ] + "description": "URL" }, - "id": { + "related": { "type": "string", - "description": "The resource's id", - "example": "XGZwpOSrWL" + "description": "URL" } } - } - } - }, - "shipment": { - "required": [ - "data" - ], - "type": "object", - "properties": { + }, "data": { "type": "object", "properties": { @@ -104546,83 +105442,18 @@ "type": "string", "description": "The resource's type", "enum": [ - "shipments" + "sku" ] }, "id": { "type": "string", - "description": "The resource's id", - "example": "XGZwpOSrWL" + "description": "The resource ID" } } } } }, - "line_item": { - "required": [ - "data" - ], - "type": "object", - "properties": { - "data": { - "type": "object", - "properties": { - "type": { - "type": "string", - "description": "The resource's type", - "enum": [ - "line_items" - ] - }, - "id": { - "type": "string", - "description": "The resource's id", - "example": "XGZwpOSrWL" - } - } - } - } - } - } - } - } - } - } - }, - "stockTransferResponse": { - "type": "object", - "properties": { - "data": { - "type": "object", - "properties": { - "id": { - "type": "string", - "description": "The resource's id", - "example": "XGZwpOSrWL" - }, - "type": { - "type": "string", - "description": "The resource's type", - "enum": [ - "stock_transfers" - ] - }, - "links": { - "type": "object", - "properties": { - "self": { - "type": "string", - "description": "URL" - } - } - }, - "attributes": { - "$ref": "#/components/schemas/stockTransfer/properties/data/properties/attributes" - }, - "relationships": { - "type": "object", - "properties": { - "sku": { + "origin_stock_location": { "type": "object", "properties": { "links": { @@ -104645,7 +105476,7 @@ "type": "string", "description": "The resource's type", "enum": [ - "sku" + "origin_stock_location" ] }, "id": { @@ -104656,7 +105487,7 @@ } } }, - "origin_stock_location": { + "destination_stock_location": { "type": "object", "properties": { "links": { @@ -104679,7 +105510,7 @@ "type": "string", "description": "The resource's type", "enum": [ - "origin_stock_location" + "destination_stock_location" ] }, "id": { @@ -104690,7 +105521,7 @@ } } }, - "destination_stock_location": { + "shipment": { "type": "object", "properties": { "links": { @@ -104713,7 +105544,7 @@ "type": "string", "description": "The resource's type", "enum": [ - "destination_stock_location" + "shipment" ] }, "id": { @@ -104724,7 +105555,7 @@ } } }, - "shipment": { + "line_item": { "type": "object", "properties": { "links": { @@ -104747,7 +105578,7 @@ "type": "string", "description": "The resource's type", "enum": [ - "shipment" + "line_item" ] }, "id": { @@ -104758,7 +105589,7 @@ } } }, - "line_item": { + "attachments": { "type": "object", "properties": { "links": { @@ -104781,7 +105612,7 @@ "type": "string", "description": "The resource's type", "enum": [ - "line_item" + "attachments" ] }, "id": { @@ -110807,6 +111638,10 @@ "name": "line_items", "description": "resource type" }, + { + "name": "links", + "description": "resource type" + }, { "name": "manual_gateways", "description": "resource type" diff --git a/specs/resources/links.spec.ts b/specs/resources/links.spec.ts new file mode 100644 index 00000000..0b76b837 --- /dev/null +++ b/specs/resources/links.spec.ts @@ -0,0 +1,176 @@ +/** + * ©2024 Commerce Layer Inc. + * Source code generated automatically by SDK codegen + **/ + +import { CommerceLayerClient } from '../../src' +import { isEqual } from 'lodash' +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import { getClient, TestData, CommonData, handleError, interceptRequest, checkCommon, checkCommonData, checkCommonParamsList, checkCommonParams, currentAccessToken, randomValue } from '../../test/common' + + + +let cl: CommerceLayerClient + + +beforeAll(async () => { cl = await getClient() }) + + +describe('Links resource', () => { + + const resourceType = 'links' + + + /* spec.create.start */ + it(resourceType + '.create', async () => { + + const createAttributes = { + name: randomValue('string', 'name'), + client_id: randomValue('string', 'client_id'), + scope: randomValue('string', 'scope'), + starts_at: randomValue('string', 'starts_at'), + expires_at: randomValue('string', 'expires_at'), + item: cl.orders.relationship(TestData.id), + } + + const attributes = { ...createAttributes, reference: TestData.reference } + const params = { fields: { links: CommonData.paramsFields } } + const resData = attributes + + const intId = cl.addRequestInterceptor((config) => { + expect(config.method).toBe('post') + checkCommon(config, resourceType) + checkCommonData(config, resourceType, attributes) + expect(cl[resourceType].isLink(config.data.data)).toBeTruthy() + return interceptRequest() + }) + + await cl[resourceType].create(resData, params, CommonData.options) + .catch(handleError) + .finally(() => cl.removeInterceptor('request', intId)) + + }) + /* spec.create.stop */ + + + /* spec.retrieve.start */ + it(resourceType + '.retrieve', async () => { + + const id = TestData.id + const params = { fields: { links: CommonData.paramsFields } } + + const intId = cl.addRequestInterceptor((config) => { + expect(config.method).toBe('get') + checkCommon(config, resourceType, id, currentAccessToken) + checkCommonParams(config, params) + return interceptRequest() + }) + + await cl[resourceType].retrieve(id, params, CommonData.options) + .catch(handleError) + .finally(() => cl.removeInterceptor('request', intId)) + + }) + /* spec.retrieve.stop */ + + + /* spec.update.start */ + it(resourceType + '.update', async () => { + + const attributes = { reference_origin: TestData.reference_origin, metadata: TestData.metadata } + const params = { fields: { links: CommonData.paramsFields } } + const resData = { id: TestData.id, ...attributes} + + const intId = cl.addRequestInterceptor((config) => { + expect(config.method).toBe('patch') + checkCommon(config, resourceType, resData.id, currentAccessToken) + checkCommonData(config, resourceType, attributes, resData.id) + return interceptRequest() + }) + + await cl[resourceType].update(resData, params, CommonData.options) + .catch(handleError) + .finally(() => cl.removeInterceptor('request', intId)) + + }) + /* spec.update.stop */ + + + /* spec.delete.start */ + it(resourceType + '.delete', async () => { + + const id = TestData.id + + const intId = cl.addRequestInterceptor((config) => { + expect(config.method).toBe('delete') + checkCommon(config, resourceType, id, currentAccessToken) + return interceptRequest() + }) + + await cl[resourceType].delete(id, CommonData.options) + .catch(handleError) + .finally(() => cl.removeInterceptor('request', intId)) + + }) + /* spec.delete.stop */ + + + /* spec.list.start */ + it(resourceType + '.list', async () => { + + const params = CommonData.paramsList + + const intId = cl.addRequestInterceptor((config) => { + expect(config.method).toBe('get') + checkCommon(config, resourceType) + checkCommonParamsList(config, params) + return interceptRequest() + }) + + await cl[resourceType].list(params, CommonData.options) + .catch(handleError) + .finally(() => cl.removeInterceptor('request', intId)) + + }) + /* spec.list.stop */ + + + /* spec.type.start */ + it(resourceType + '.type', async () => { + + const resource = { id: TestData.id, type: resourceType } + expect(cl[resourceType].isLink(resource)).toBeTruthy() + + const relId = cl[resourceType].relationship(TestData.id) + expect(isEqual(relId, { id: TestData.id, type: resourceType})) + + const relResId = cl[resourceType].relationship({ id: TestData.id, type: resourceType }) + expect(isEqual(relResId, { id: TestData.id, type: resourceType})) + + const type = cl[resourceType].type() + expect(type).toBe(resourceType) + + }) + /* spec.type.stop */ + + + + it(resourceType + '.events', async () => { + + const id = TestData.id + const params = { fields: { events: CommonData.paramsFields } } + + const intId = cl.addRequestInterceptor((config) => { + expect(config.method).toBe('get') + checkCommon(config, resourceType, id, currentAccessToken, 'events') + checkCommonParams(config, params) + return interceptRequest() + }) + + await cl[resourceType].events(id, params, CommonData.options) + .catch(handleError) + .finally(() => cl.removeInterceptor('request', intId)) + + }) + +}) diff --git a/specs/resources/stock_transfers.spec.ts b/specs/resources/stock_transfers.spec.ts index 97ca34b7..cdd1da9b 100644 --- a/specs/resources/stock_transfers.spec.ts +++ b/specs/resources/stock_transfers.spec.ts @@ -250,6 +250,25 @@ describe('StockTransfers resource', () => { }) + it(resourceType + '.attachments', async () => { + + const id = TestData.id + const params = { fields: { attachments: CommonData.paramsFields } } + + const intId = cl.addRequestInterceptor((config) => { + expect(config.method).toBe('get') + checkCommon(config, resourceType, id, currentAccessToken, 'attachments') + checkCommonParams(config, params) + return interceptRequest() + }) + + await cl[resourceType].attachments(id, params, CommonData.options) + .catch(handleError) + .finally(() => cl.removeInterceptor('request', intId)) + + }) + + it(resourceType + '.events', async () => { const id = TestData.id diff --git a/src/api.ts b/src/api.ts index 69d34aa8..c8630cd7 100644 --- a/src/api.ts +++ b/src/api.ts @@ -60,6 +60,7 @@ export { default as KlarnaGateways } from './resources/klarna_gateways' export { default as KlarnaPayments } from './resources/klarna_payments' export { default as LineItemOptions } from './resources/line_item_options' export { default as LineItems } from './resources/line_items' +export { default as Links } from './resources/links' export { default as ManualGateways } from './resources/manual_gateways' export { default as ManualTaxCalculators } from './resources/manual_tax_calculators' export { default as Markets } from './resources/markets' @@ -187,6 +188,7 @@ export type ResourceTypeLock = | 'klarna_payments' | 'line_item_options' | 'line_items' +| 'links' | 'manual_gateways' | 'manual_tax_calculators' | 'markets' @@ -314,6 +316,7 @@ export const resourceList = [ 'klarna_payments', 'line_item_options', 'line_items', + 'links', 'manual_gateways', 'manual_tax_calculators', 'markets', diff --git a/src/commercelayer.ts b/src/commercelayer.ts index 4cf83627..a50ca47a 100644 --- a/src/commercelayer.ts +++ b/src/commercelayer.ts @@ -9,7 +9,7 @@ import Debug from './debug' const debug = Debug('commercelayer') // Autogenerated schema version number, do not remove this line -const OPEN_API_SCHEMA_VERSION = '5.3.3' +const OPEN_API_SCHEMA_VERSION = '5.4.0' export { OPEN_API_SCHEMA_VERSION } @@ -86,6 +86,7 @@ class CommerceLayerClient { klarna_payments: api.KlarnaPayments line_item_options: api.LineItemOptions line_items: api.LineItems + links: api.Links manual_gateways: api.ManualGateways manual_tax_calculators: api.ManualTaxCalculators markets: api.Markets @@ -220,6 +221,7 @@ class CommerceLayerClient { this.klarna_payments = new api.KlarnaPayments(this.#adapter) this.line_item_options = new api.LineItemOptions(this.#adapter) this.line_items = new api.LineItems(this.#adapter) + this.links = new api.Links(this.#adapter) this.manual_gateways = new api.ManualGateways(this.#adapter) this.manual_tax_calculators = new api.ManualTaxCalculators(this.#adapter) this.markets = new api.Markets(this.#adapter) diff --git a/src/model.ts b/src/model.ts index d06e481d..992e115e 100644 --- a/src/model.ts +++ b/src/model.ts @@ -60,6 +60,7 @@ export type { KlarnaGateway, KlarnaGatewayCreate, KlarnaGatewayUpdate } from './ export type { KlarnaPayment, KlarnaPaymentCreate, KlarnaPaymentUpdate } from './resources/klarna_payments' export type { LineItemOption, LineItemOptionCreate, LineItemOptionUpdate } from './resources/line_item_options' export type { LineItem, LineItemCreate, LineItemUpdate } from './resources/line_items' +export type { Link, LinkCreate, LinkUpdate } from './resources/links' export type { ManualGateway, ManualGatewayCreate, ManualGatewayUpdate } from './resources/manual_gateways' export type { ManualTaxCalculator, ManualTaxCalculatorCreate, ManualTaxCalculatorUpdate } from './resources/manual_tax_calculators' export type { Market, MarketCreate, MarketUpdate } from './resources/markets' diff --git a/src/resources/links.ts b/src/resources/links.ts new file mode 100644 index 00000000..698f411e --- /dev/null +++ b/src/resources/links.ts @@ -0,0 +1,116 @@ +import { ApiResource, Resource, ResourceCreate, ResourceUpdate, ResourcesConfig, ResourceId, ResourceRel, ListResponse } from '../resource' +import type { QueryParamsList, QueryParamsRetrieve } from '../query' + +import type { Order } from './orders' +import type { SkuList } from './sku_lists' +import type { Event } from './events' + + +type LinkRel = ResourceRel & { type: typeof Links.TYPE } +type OrderRel = ResourceRel & { type: 'orders' } +type SkuListRel = ResourceRel & { type: 'sku_lists' } + + +interface Link extends Resource { + + name?: string + client_id?: string + scope?: string + starts_at?: string + expires_at?: string + active?: boolean + status?: string + domain?: string + url?: string + disabled_at?: string + + item?: Order | SkuList + events?: Event[] + +} + + +interface LinkCreate extends ResourceCreate { + + name: string + client_id: string + scope: string + starts_at: string + expires_at: string + domain?: string + _disable?: boolean + _enable?: boolean + + item: OrderRel | SkuListRel + +} + + +interface LinkUpdate extends ResourceUpdate { + + name?: string + client_id?: string + scope?: string + starts_at?: string + expires_at?: string + domain?: string + _disable?: boolean + _enable?: boolean + + item?: OrderRel | SkuListRel + +} + + +class Links extends ApiResource { + + static readonly TYPE: 'links' = 'links' as const + // static readonly PATH = 'links' + + async list(params?: QueryParamsList, options?: ResourcesConfig): Promise> { + return this.resources.list({ type: Links.TYPE }, params, options) + } + + async create(resource: LinkCreate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise { + return this.resources.create({ ...resource, type: Links.TYPE }, params, options) + } + + async retrieve(id: string, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise { + return this.resources.retrieve({ type: Links.TYPE, id }, params, options) + } + + async update(resource: LinkUpdate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise { + return this.resources.update({ ...resource, type: Links.TYPE }, params, options) + } + + async delete(id: string, options?: ResourcesConfig): Promise { + await this.resources.delete({ type: Links.TYPE, id }, options) + } + + async events(linkId: string | Link, params?: QueryParamsList, options?: ResourcesConfig): Promise> { + const _linkId = (linkId as Link).id || linkId as string + return this.resources.fetch({ type: 'events' }, `links/${_linkId}/events`, params, options) as unknown as ListResponse + } + + + // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any + isLink(resource: any): resource is Link { + return resource.type && (resource.type === Links.TYPE) + } + + + relationship(id: string | ResourceId | null): LinkRel { + return ((id === null) || (typeof id === 'string')) ? { id, type: Links.TYPE } : { id: id.id, type: Links.TYPE } + } + + + type(): string { + return Links.TYPE + } + +} + + +export default Links + +export { Link, LinkCreate, LinkUpdate } diff --git a/src/resources/orders.ts b/src/resources/orders.ts index 539f58b4..6cf775ee 100644 --- a/src/resources/orders.ts +++ b/src/resources/orders.ts @@ -166,7 +166,6 @@ interface Order extends Resource { fulfillment_updated_at?: string refreshed_at?: string archived_at?: string - expires_at?: string subscription_created_at?: string circuit_state?: string circuit_failure_count?: number diff --git a/src/resources/stock_transfers.ts b/src/resources/stock_transfers.ts index 36e9f475..6bc19e63 100644 --- a/src/resources/stock_transfers.ts +++ b/src/resources/stock_transfers.ts @@ -5,6 +5,7 @@ import type { Sku } from './skus' import type { StockLocation } from './stock_locations' import type { Shipment } from './shipments' import type { LineItem } from './line_items' +import type { Attachment } from './attachments' import type { Event } from './events' import type { Version } from './versions' @@ -30,6 +31,7 @@ interface StockTransfer extends Resource { destination_stock_location?: StockLocation shipment?: Shipment line_item?: LineItem + attachments?: Attachment[] events?: Event[] versions?: Version[] @@ -121,6 +123,11 @@ class StockTransfers extends ApiResource { return this.resources.fetch({ type: 'line_items' }, `stock_transfers/${_stockTransferId}/line_item`, params, options) as unknown as LineItem } + async attachments(stockTransferId: string | StockTransfer, params?: QueryParamsList, options?: ResourcesConfig): Promise> { + const _stockTransferId = (stockTransferId as StockTransfer).id || stockTransferId as string + return this.resources.fetch({ type: 'attachments' }, `stock_transfers/${_stockTransferId}/attachments`, params, options) as unknown as ListResponse + } + async events(stockTransferId: string | StockTransfer, params?: QueryParamsList, options?: ResourcesConfig): Promise> { const _stockTransferId = (stockTransferId as StockTransfer).id || stockTransferId as string return this.resources.fetch({ type: 'events' }, `stock_transfers/${_stockTransferId}/events`, params, options) as unknown as ListResponse