diff --git a/airbyte-config/init/src/main/resources/config/STANDARD_SOURCE_DEFINITION/b3c1ecb8-f0de-11eb-9a03-0242ac130003.json b/airbyte-config/init/src/main/resources/config/STANDARD_SOURCE_DEFINITION/b3c1ecb8-f0de-11eb-9a03-0242ac130003.json new file mode 100644 index 0000000000000..c2082bde82159 --- /dev/null +++ b/airbyte-config/init/src/main/resources/config/STANDARD_SOURCE_DEFINITION/b3c1ecb8-f0de-11eb-9a03-0242ac130003.json @@ -0,0 +1,8 @@ +{ + "sourceDefinitionId": "b3c1ecb8-f0de-11eb-9a03-0242ac130003", + "name": "Woocommerce", + "dockerRepository": "airbyte/source-woocommerce", + "dockerImageTag": "0.1.0", + "documentationUrl": "https://docs.airbyte.io/integrations/sources/woocommerce", + "icon": "woocommerce.svg" +} diff --git a/airbyte-config/init/src/main/resources/icons/woocommerce.svg b/airbyte-config/init/src/main/resources/icons/woocommerce.svg new file mode 100644 index 0000000000000..514d0fc9857c2 --- /dev/null +++ b/airbyte-config/init/src/main/resources/icons/woocommerce.svg @@ -0,0 +1,14 @@ + + + + + + image/svg+xml + + + + + + + + diff --git a/airbyte-config/init/src/main/resources/seed/source_definitions.yaml b/airbyte-config/init/src/main/resources/seed/source_definitions.yaml index 3a34cbb230ef5..8b39949498bd7 100644 --- a/airbyte-config/init/src/main/resources/seed/source_definitions.yaml +++ b/airbyte-config/init/src/main/resources/seed/source_definitions.yaml @@ -548,6 +548,13 @@ documentationUrl: https://docs.airbyte.io/integrations/sources/mongodb-v2 icon: mongodb.svg sourceType: database +- sourceDefinitionId: b3c1ecb8-f0de-11eb-9a03-0242ac130003 + name: Woocommerce + dockerRepository: airbyte/source-woocommerce + dockerImageTag: 0.1.0 + documentationUrl: https://docs.airbyte.io/integrations/sources/woocommerce + icon: woocommerce.svg + sourceType: api - sourceDefinitionId: d917a47b-8537-4d0d-8c10-36a9928d4265 name: Kafka dockerRepository: airbyte/source-kafka @@ -560,3 +567,4 @@ dockerImageTag: 0.1.0 documentationUrl: https://docs.airbyte.io/integrations/sources/lever-hiring sourceType: api + diff --git a/airbyte-integrations/connectors/source-woocommerce/.dockerignore b/airbyte-integrations/connectors/source-woocommerce/.dockerignore new file mode 100644 index 0000000000000..9a6ab7d1183c0 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/.dockerignore @@ -0,0 +1,7 @@ +* +!Dockerfile +!Dockerfile.test +!main.py +!source_woocommerce +!setup.py +!secrets diff --git a/airbyte-integrations/connectors/source-woocommerce/Dockerfile b/airbyte-integrations/connectors/source-woocommerce/Dockerfile new file mode 100644 index 0000000000000..9294db18a3130 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/Dockerfile @@ -0,0 +1,16 @@ +FROM python:3.7-slim + +# Bash is installed for more convenient debugging. +RUN apt-get update && apt-get install -y bash && rm -rf /var/lib/apt/lists/* + +WORKDIR /airbyte/integration_code +COPY source_woocommerce ./source_woocommerce +COPY main.py ./ +COPY setup.py ./ +RUN pip install . + +ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py" +ENTRYPOINT ["python", "/airbyte/integration_code/main.py"] + +LABEL io.airbyte.version=0.1.0 +LABEL io.airbyte.name=airbyte/source-woocommerce diff --git a/airbyte-integrations/connectors/source-woocommerce/README.md b/airbyte-integrations/connectors/source-woocommerce/README.md new file mode 100644 index 0000000000000..6b05a84943b99 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/README.md @@ -0,0 +1,131 @@ +# Woocommerce Source + +This is the repository for the Woocommerce source connector, written in Python. +For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/sources/woocommerce). + +## Local development + +### Prerequisites +**To iterate on this connector, make sure to complete this prerequisites section.** + +#### Minimum Python version required `= 3.7.0` + +#### Build & Activate Virtual Environment and install dependencies +From this connector directory, create a virtual environment: +``` +python -m venv .venv +``` + +This will generate a virtualenv for this module in `.venv/`. Make sure this venv is active in your +development environment of choice. To activate it from the terminal, run: +``` +source .venv/bin/activate +pip install -r requirements.txt +``` +If you are in an IDE, follow your IDE's instructions to activate the virtualenv. + +Note that while we are installing dependencies from `requirements.txt`, you should only edit `setup.py` for your dependencies. `requirements.txt` is +used for editable installs (`pip install -e`) to pull in Python dependencies from the monorepo and will call `setup.py`. +If this is mumbo jumbo to you, don't worry about it, just put your deps in `setup.py` but install using `pip install -r requirements.txt` and everything +should work as you expect. + +#### Building via Gradle +You can also build the connector in Gradle. This is typically used in CI and not needed for your development workflow. + +To build using Gradle, from the Airbyte repository root, run: +``` +./gradlew :airbyte-integrations:connectors:source-woocommerce:build +``` + +#### Create credentials +**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/sources/woocommerce) +to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_woocommerce/spec.json` file. +Note that any directory named `secrets` is gitignored across the entire Airbyte repo, so there is no danger of accidentally checking in sensitive information. +See `integration_tests/sample_config.json` for a sample config file. + +**If you are an Airbyte core member**, copy the credentials in Lastpass under the secret name `source woocommerce test creds` +and place them into `secrets/config.json`. + +### Locally running the connector +``` +python main.py spec +python main.py check --config secrets/config.json +python main.py discover --config secrets/config.json +python main.py read --config secrets/config.json --catalog integration_tests/configured_catalog.json +``` + +### Locally running the connector docker image + +#### Build +First, make sure you build the latest Docker image: +``` +docker build . -t airbyte/source-woocommerce:dev +``` + +You can also build the connector image via Gradle: +``` +./gradlew :airbyte-integrations:connectors:source-woocommerce:airbyteDocker +``` +When building via Gradle, the docker image name and tag, respectively, are the values of the `io.airbyte.name` and `io.airbyte.version` `LABEL`s in +the Dockerfile. + +#### Run +Then run any of the connector commands as follows: +``` +docker run --rm airbyte/source-woocommerce:dev spec +docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-woocommerce:dev check --config /secrets/config.json +docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-woocommerce:dev discover --config /secrets/config.json +docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-woocommerce:dev read --config /secrets/config.json --catalog /integration_tests/configured_catalog.json +``` +## Testing +Make sure to familiarize yourself with [pytest test discovery](https://docs.pytest.org/en/latest/goodpractices.html#test-discovery) to know how your test files and methods should be named. +First install test dependencies into your virtual environment: +``` +pip install .[tests] +``` +### Unit Tests +To run unit tests locally, from the connector directory run: +``` +python -m pytest unit_tests +``` + +### Integration Tests +There are two types of integration tests: Acceptance Tests (Airbyte's test suite for all source connectors) and custom integration tests (which are specific to this connector). +#### Custom Integration tests +Place custom tests inside `integration_tests/` folder, then, from the connector root, run +``` +python -m pytest integration_tests +``` +#### Acceptance Tests +Customize `acceptance-test-config.yml` file to configure tests. See [Source Acceptance Tests](source-acceptance-tests.md) for more information. +If your connector requires to create or destroy resources for use during acceptance tests create fixtures for it and place them inside integration_tests/acceptance.py. +To run your integration tests with acceptance tests, from the connector root, run +``` +python -m pytest integration_tests -p integration_tests.acceptance +``` +To run your integration tests with docker + +### Using gradle to run tests +All commands should be run from airbyte project root. +To run unit tests: +``` +./gradlew :airbyte-integrations:connectors:source-woocommerce:unitTest +``` +To run acceptance and custom integration tests: +``` +./gradlew :airbyte-integrations:connectors:source-woocommerce:integrationTest +``` + +## Dependency Management +All of your dependencies should go in `setup.py`, NOT `requirements.txt`. The requirements file is only used to connect internal Airbyte dependencies in the monorepo for local development. +We split dependencies between two groups, dependencies that are: +* required for your connector to work need to go to `MAIN_REQUIREMENTS` list. +* required for the testing need to go to `TEST_REQUIREMENTS` list + +### Publishing a new version of the connector +You've checked out the repo, implemented a million dollar feature, and you're ready to share your changes with the world. Now what? +1. Make sure your changes are passing unit and integration tests. +1. Bump the connector version in `Dockerfile` -- just increment the value of the `LABEL io.airbyte.version` appropriately (we use [SemVer](https://semver.org/)). +1. Create a Pull Request. +1. Pat yourself on the back for being an awesome contributor. +1. Someone from Airbyte will take a look at your PR and iterate with you to merge it into master. diff --git a/airbyte-integrations/connectors/source-woocommerce/acceptance-test-config.yml b/airbyte-integrations/connectors/source-woocommerce/acceptance-test-config.yml new file mode 100644 index 0000000000000..e0d08fdcacf05 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/acceptance-test-config.yml @@ -0,0 +1,24 @@ +# See [Source Acceptance Tests](https://docs.airbyte.io/contributing-to-airbyte/building-new-connector/source-acceptance-tests.md) +# for more information about how to configure these tests +connector_image: airbyte/source-woocommerce:dev +tests: + spec: + - spec_path: "source_woocommerce/spec.json" + connection: + - config_path: "secrets/config.json" + status: "succeed" + - config_path: "integration_tests/invalid_config.json" + status: "failed" + discovery: + - config_path: "secrets/config.json" + basic_read: + - config_path: "secrets/config.json" + configured_catalog_path: "integration_tests/configured_catalog.json" + empty_streams: [] + incremental: # TODO if your connector does not implement incremental sync, remove this block + - config_path: "secrets/config.json" + configured_catalog_path: "integration_tests/configured_catalog.json" + future_state_path: "integration_tests/abnormal_state.json" + full_refresh: + - config_path: "secrets/config.json" + configured_catalog_path: "integration_tests/configured_catalog.json" diff --git a/airbyte-integrations/connectors/source-woocommerce/acceptance-test-docker.sh b/airbyte-integrations/connectors/source-woocommerce/acceptance-test-docker.sh new file mode 100644 index 0000000000000..1425ff74f1511 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/acceptance-test-docker.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env sh +docker run --rm -it \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v /tmp:/tmp \ + -v $(pwd):/test_input \ + airbyte/source-acceptance-test \ + --acceptance-test-config /test_input diff --git a/airbyte-integrations/connectors/source-woocommerce/build.gradle b/airbyte-integrations/connectors/source-woocommerce/build.gradle new file mode 100644 index 0000000000000..a33fd4ae8e6a8 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/build.gradle @@ -0,0 +1,14 @@ +plugins { + id 'airbyte-python' + id 'airbyte-docker' + id 'airbyte-source-acceptance-test' +} + +airbytePython { + moduleDirectory 'source_woocommerce' +} + +dependencies { + implementation files(project(':airbyte-integrations:bases:source-acceptance-test').airbyteDocker.outputs) + implementation files(project(':airbyte-integrations:bases:base-python').airbyteDocker.outputs) +} diff --git a/airbyte-integrations/connectors/source-woocommerce/integration_tests/__init__.py b/airbyte-integrations/connectors/source-woocommerce/integration_tests/__init__.py new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/airbyte-integrations/connectors/source-woocommerce/integration_tests/abnormal_state.json b/airbyte-integrations/connectors/source-woocommerce/integration_tests/abnormal_state.json new file mode 100644 index 0000000000000..8d6bef02c3ac5 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/integration_tests/abnormal_state.json @@ -0,0 +1,12 @@ +{ + "customers": { + "date_modified": "2030-07-30T22:16:46" + }, + "orders": { + "date_modified": "2050-07-30T22:16:46" + }, + "coupons": { + "date_modified": "2060-07-30T22:16:46" + } +} + diff --git a/airbyte-integrations/connectors/source-woocommerce/integration_tests/acceptance.py b/airbyte-integrations/connectors/source-woocommerce/integration_tests/acceptance.py new file mode 100644 index 0000000000000..eeb4a2d3e02e5 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/integration_tests/acceptance.py @@ -0,0 +1,36 @@ +# +# MIT License +# +# Copyright (c) 2020 Airbyte +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + + +import pytest + +pytest_plugins = ("source_acceptance_test.plugin",) + + +@pytest.fixture(scope="session", autouse=True) +def connector_setup(): + """ This fixture is a placeholder for external resources that acceptance test might require.""" + # TODO: setup test dependencies if needed. otherwise remove the TODO comments + yield + # TODO: clean up test dependencies diff --git a/airbyte-integrations/connectors/source-woocommerce/integration_tests/catalog.json b/airbyte-integrations/connectors/source-woocommerce/integration_tests/catalog.json new file mode 100644 index 0000000000000..7279c4ee6c2b5 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/integration_tests/catalog.json @@ -0,0 +1,1689 @@ +{ + "streams": [ + { + "name": "customers", + "json_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "date_created": { + "type": [ + "null", + "string" + ], + "format": "date-time" + }, + "date_created_gmt": { + "type": [ + "null", + "string" + ], + "format": "date-time" + }, + "date_modified": { + "type": [ + "null", + "string" + ], + "format": "date-time" + }, + "date_modified_gmt": { + "type": [ + "null", + "string" + ], + "format": "date-time" + }, + "email": { + "type": [ + "null", + "string" + ] + }, + "first_name": { + "type": [ + "null", + "string" + ] + }, + "last_name": { + "type": [ + "null", + "string" + ] + }, + "role": { + "type": [ + "null", + "string" + ] + }, + "username": { + "type": [ + "null", + "string" + ] + }, + "billing": { + "type": [ + "null", + "object" + ], + "properties": { + "first_name": { + "type": [ + "null", + "string" + ] + }, + "last_name": { + "type": [ + "null", + "string" + ] + }, + "company": { + "type": [ + "null", + "string" + ] + }, + "address_1": { + "type": [ + "null", + "string" + ] + }, + "address_2": { + "type": [ + "null", + "string" + ] + }, + "city": { + "type": [ + "null", + "string" + ] + }, + "state": { + "type": [ + "null", + "string" + ] + }, + "postcode": { + "type": [ + "null", + "string" + ] + }, + "country": { + "type": [ + "null", + "string" + ] + }, + "email": { + "type": [ + "null", + "string" + ] + }, + "phone": { + "type": [ + "null", + "string" + ] + } + } + }, + "shipping": { + "type": [ + "null", + "object" + ], + "properties": { + "first_name": { + "type": [ + "null", + "string" + ] + }, + "last_name": { + "type": [ + "null", + "string" + ] + }, + "company": { + "type": [ + "null", + "string" + ] + }, + "address_1": { + "type": [ + "null", + "string" + ] + }, + "address_2": { + "type": [ + "null", + "string" + ] + }, + "city": { + "type": [ + "null", + "string" + ] + }, + "state": { + "type": [ + "null", + "string" + ] + }, + "postcode": { + "type": [ + "null", + "string" + ] + }, + "country": { + "type": [ + "null", + "string" + ] + } + } + }, + "is_paying_customer": { + "type": [ + "null", + "boolean" + ] + }, + "avatar_url": { + "type": [ + "null", + "string" + ] + }, + "meta_data": { + "type": [ + "null", + "array" + ] + }, + "_links": { + "type": [ + "null", + "object" + ], + "properties": { + "self": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "href": { + "type": [ + "null", + "string" + ] + } + } + } + }, + "collection": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "href": { + "type": [ + "null", + "string" + ] + } + } + } + } + } + } + } + } + }, + { + "name": "coupons", + "json_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "code": { + "type": [ + "null", + "string" + ] + }, + "amount": { + "type": [ + "null", + "string" + ] + }, + "date_created": { + "type": [ + "null", + "string" + ], + "format": "date-time" + }, + "date_created_gmt": { + "type": [ + "null", + "string" + ], + "format": "date-time" + }, + "date_modified": { + "type": [ + "null", + "string" + ], + "format": "date-time" + }, + "date_modified_gmt": { + "type": [ + "null", + "string" + ], + "format": "date-time" + }, + "discount_type": { + "type": [ + "null", + "string" + ] + }, + "description": { + "type": [ + "null", + "string" + ] + }, + "date_expires": { + "type": [ + "null", + "string" + ] + }, + "date_expires_gmt": { + "type": [ + "null", + "string" + ] + }, + "usage_count": { + "type": [ + "null", + "integer" + ] + }, + "individual_use": { + "type": [ + "null", + "boolean" + ] + }, + "product_ids": { + "type": [ + "null", + "array" + ] + }, + "excluded_product_ids": { + "type": [ + "null", + "array" + ] + }, + "usage_limit": { + "type": [ + "null", + "integer" + ] + }, + "usage_limit_per_user": { + "type": [ + "null", + "integer" + ] + }, + "limit_usage_to_x_items": { + "type": [ + "null", + "integer" + ] + }, + "free_shipping": { + "type": [ + "null", + "boolean" + ] + }, + "product_categories": { + "type": [ + "null", + "array" + ] + }, + "excluded_product_categories": { + "type": [ + "null", + "array" + ] + }, + "exclude_sale_items": { + "type": [ + "null", + "boolean" + ] + }, + "minimum_amount": { + "type": [ + "null", + "string" + ] + }, + "maximum_amount": { + "type": [ + "null", + "string" + ] + }, + "email_restrictions": { + "type": [ + "null", + "array" + ] + }, + "used_by": { + "type": [ + "null", + "array" + ] + }, + "meta_data": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "key": { + "type": [ + "null", + "string" + ] + }, + "value": { + "type": [ + "null", + "string" + ] + } + } + } + }, + "_links": { + "type": [ + "null", + "object" + ], + "properties": { + "self": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "href": { + "type": [ + "null", + "string" + ] + } + } + } + }, + "collection": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "href": { + "type": [ + "null", + "string" + ] + } + } + } + } + } + } + } + } + }, + { + "name": "orders", + "json_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "parent_id": { + "type": [ + "null", + "integer" + ] + }, + "number": { + "type": [ + "null", + "string" + ] + }, + "order_key": { + "type": [ + "null", + "string" + ] + }, + "created_via": { + "type": [ + "null", + "string" + ] + }, + "version": { + "type": [ + "null", + "string" + ] + }, + "status": { + "type": [ + "null", + "string" + ] + }, + "currency": { + "type": [ + "null", + "string" + ] + }, + "date_created": { + "type": [ + "null", + "string" + ], + "format": "date-time" + }, + "date_created_gmt": { + "type": [ + "null", + "string" + ], + "format": "date-time" + }, + "date_modified": { + "type": [ + "null", + "string" + ], + "format": "date-time" + }, + "date_modified_gmt": { + "type": [ + "null", + "string" + ], + "format": "date-time" + }, + "discount_total": { + "type": [ + "null", + "string" + ] + }, + "discount_tax": { + "type": [ + "null", + "string" + ] + }, + "shipping_total": { + "type": [ + "null", + "string" + ] + }, + "shipping_tax": { + "type": [ + "null", + "string" + ] + }, + "cart_tax": { + "type": [ + "null", + "string" + ] + }, + "total": { + "type": [ + "null", + "string" + ] + }, + "total_tax": { + "type": [ + "null", + "string" + ] + }, + "prices_include_tax": { + "type": [ + "null", + "boolean" + ] + }, + "customer_id": { + "type": [ + "null", + "integer" + ] + }, + "customer_ip_address": { + "type": [ + "null", + "string" + ] + }, + "customer_user_agent": { + "type": [ + "null", + "string" + ] + }, + "customer_note": { + "type": [ + "null", + "string" + ] + }, + "billing": { + "type": [ + "null", + "object" + ], + "properties": { + "first_name": { + "type": [ + "null", + "string" + ] + }, + "last_name": { + "type": [ + "null", + "string" + ] + }, + "company": { + "type": [ + "null", + "string" + ] + }, + "address_1": { + "type": [ + "null", + "string" + ] + }, + "address_2": { + "type": [ + "null", + "string" + ] + }, + "city": { + "type": [ + "null", + "string" + ] + }, + "state": { + "type": [ + "null", + "string" + ] + }, + "postcode": { + "type": [ + "null", + "string" + ] + }, + "country": { + "type": [ + "null", + "string" + ] + }, + "email": { + "type": [ + "null", + "string" + ] + }, + "phone": { + "type": [ + "null", + "string" + ] + } + } + }, + "shipping": { + "type": [ + "null", + "object" + ], + "properties": { + "first_name": { + "type": [ + "null", + "string" + ] + }, + "last_name": { + "type": [ + "null", + "string" + ] + }, + "company": { + "type": [ + "null", + "string" + ] + }, + "address_1": { + "type": [ + "null", + "string" + ] + }, + "address_2": { + "type": [ + "null", + "string" + ] + }, + "city": { + "type": [ + "null", + "string" + ] + }, + "state": { + "type": [ + "null", + "string" + ] + }, + "postcode": { + "type": [ + "null", + "string" + ] + }, + "country": { + "type": [ + "null", + "string" + ] + } + } + }, + "payment_method": { + "type": [ + "null", + "string" + ] + }, + "payment_method_title": { + "type": [ + "null", + "string" + ] + }, + "transaction_id": { + "type": [ + "null", + "string" + ] + }, + "date_paid": { + "type": [ + "null", + "string" + ], + "format": "date-time" + }, + "date_paid_gmt": { + "type": [ + "null", + "string" + ], + "format": "date-time" + }, + "date_completed": { + "type": [ + "null", + "string" + ], + "format": "date-time" + }, + "date_completed_gmt": { + "type": [ + "null", + "string" + ], + "format": "date-time" + }, + "cart_hash": { + "type": [ + "null", + "string" + ] + }, + "meta_data": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "key": { + "type": [ + "null", + "string" + ] + }, + "value": { + "type": [ + "null", + "string" + ] + } + } + } + }, + "line_items": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "name": { + "type": [ + "null", + "string" + ] + }, + "product_id": { + "type": [ + "null", + "integer" + ] + }, + "variation_id": { + "type": [ + "null", + "integer" + ] + }, + "quantity": { + "type": [ + "null", + "integer" + ] + }, + "tax_class": { + "type": [ + "null", + "string" + ] + }, + "subtotal": { + "type": [ + "null", + "string" + ] + }, + "subtotal_tax": { + "type": [ + "null", + "string" + ] + }, + "total": { + "type": [ + "null", + "string" + ] + }, + "total_tax": { + "type": [ + "null", + "string" + ] + }, + "taxes": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "rate_code": { + "type": [ + "null", + "string" + ] + }, + "rate_id": { + "type": [ + "null", + "string" + ] + }, + "label": { + "type": [ + "null", + "string" + ] + }, + "compound": { + "type": [ + "null", + "boolean" + ] + }, + "tax_total": { + "type": [ + "null", + "string" + ] + }, + "shipping_tax_total": { + "type": [ + "null", + "string" + ] + }, + "meta_data": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "key": { + "type": [ + "null", + "string" + ] + }, + "value": { + "type": [ + "null", + "string" + ] + } + } + } + } + } + } + }, + "meta_data": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "key": { + "type": [ + "null", + "string" + ] + }, + "value": { + "type": [ + "null", + "string" + ] + } + } + } + }, + "sku": { + "type": [ + "null", + "string" + ] + }, + "price": { + "type": [ + "null", + "integer" + ] + } + } + } + }, + "tax_lines": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "rate_code": { + "type": [ + "null", + "string" + ] + }, + "rate_id": { + "type": [ + "null", + "string" + ] + }, + "label": { + "type": [ + "null", + "string" + ] + }, + "compound": { + "type": [ + "null", + "boolean" + ] + }, + "tax_total": { + "type": [ + "null", + "string" + ] + }, + "shipping_tax_total": { + "type": [ + "null", + "string" + ] + }, + "meta_data": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "key": { + "type": [ + "null", + "string" + ] + }, + "value": { + "type": [ + "null", + "string" + ] + } + } + } + } + } + } + }, + "shipping_lines": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "method_title": { + "type": [ + "null", + "string" + ] + }, + "method_id": { + "type": [ + "null", + "string" + ] + }, + "total": { + "type": [ + "null", + "string" + ] + }, + "total_tax": { + "type": [ + "null", + "string" + ] + }, + "taxes": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "rate_code": { + "type": [ + "null", + "string" + ] + }, + "rate_id": { + "type": [ + "null", + "string" + ] + }, + "label": { + "type": [ + "null", + "string" + ] + }, + "compound": { + "type": [ + "null", + "boolean" + ] + }, + "tax_total": { + "type": [ + "null", + "string" + ] + }, + "shipping_tax_total": { + "type": [ + "null", + "string" + ] + }, + "meta_data": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "key": { + "type": [ + "null", + "string" + ] + }, + "value": { + "type": [ + "null", + "string" + ] + } + } + } + } + } + } + }, + "meta_data": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "key": { + "type": [ + "null", + "string" + ] + }, + "value": { + "type": [ + "null", + "string" + ] + } + } + } + } + } + } + }, + "fee_lines": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "name": { + "type": [ + "null", + "string" + ] + }, + "tax_class": { + "type": [ + "null", + "string" + ] + }, + "tax_status": { + "type": [ + "null", + "string" + ] + }, + "total": { + "type": [ + "null", + "string" + ] + }, + "total_tax": { + "type": [ + "null", + "string" + ] + }, + "taxes": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "rate_code": { + "type": [ + "null", + "string" + ] + }, + "rate_id": { + "type": [ + "null", + "string" + ] + }, + "label": { + "type": [ + "null", + "string" + ] + }, + "compound": { + "type": [ + "null", + "boolean" + ] + }, + "tax_total": { + "type": [ + "null", + "string" + ] + }, + "shipping_tax_total": { + "type": [ + "null", + "string" + ] + }, + "meta_data": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "key": { + "type": [ + "null", + "string" + ] + }, + "value": { + "type": [ + "null", + "string" + ] + } + } + } + } + } + } + }, + "meta_data": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "key": { + "type": [ + "null", + "string" + ] + }, + "value": { + "type": [ + "null", + "string" + ] + } + } + } + } + } + } + }, + "coupon_lines": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "code": { + "type": [ + "null", + "string" + ] + }, + "discount": { + "type": [ + "null", + "string" + ] + }, + "discount_tax": { + "type": [ + "null", + "string" + ] + }, + "meta_data": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "key": { + "type": [ + "null", + "string" + ] + }, + "value": { + "type": [ + "null", + "string" + ] + } + } + } + } + } + } + }, + "refunds": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "id": { + "type": [ + "null", + "integer" + ] + }, + "reason": { + "type": [ + "null", + "string" + ] + }, + "total": { + "type": [ + "null", + "string" + ] + } + } + } + }, + "set_paid": { + "type": [ + "null", + "boolean" + ] + }, + "_links": { + "type": [ + "null", + "object" + ], + "properties": { + "self": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "href": { + "type": [ + "null", + "string" + ] + } + } + } + }, + "collection": { + "type": [ + "null", + "array" + ], + "items": { + "type": [ + "null", + "object" + ], + "properties": { + "href": { + "type": [ + "null", + "string" + ] + } + } + } + } + } + } + } + } + } + ] +} diff --git a/airbyte-integrations/connectors/source-woocommerce/integration_tests/configured_catalog.json b/airbyte-integrations/connectors/source-woocommerce/integration_tests/configured_catalog.json new file mode 100644 index 0000000000000..63d18a9937848 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/integration_tests/configured_catalog.json @@ -0,0 +1,935 @@ +{ + "streams": [ + { + "stream": { + "name": "customers", + "json_schema": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "date_created": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_created_gmt": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_modified": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_modified_gmt": { + "type": ["null", "string"], + "format": "date-time" + }, + "email": { + "type": ["null", "string"] + }, + "first_name": { + "type": ["null", "string"] + }, + "last_name": { + "type": ["null", "string"] + }, + "role": { + "type": ["null", "string"] + }, + "username": { + "type": ["null", "string"] + }, + "billing": { + "type": ["null", "object"], + "properties": { + "first_name": { + "type": ["null", "string"] + }, + "last_name": { + "type": ["null", "string"] + }, + "company": { + "type": ["null", "string"] + }, + "address_1": { + "type": ["null", "string"] + }, + "address_2": { + "type": ["null", "string"] + }, + "city": { + "type": ["null", "string"] + }, + "state": { + "type": ["null", "string"] + }, + "postcode": { + "type": ["null", "string"] + }, + "country": { + "type": ["null", "string"] + }, + "email": { + "type": ["null", "string"] + }, + "phone": { + "type": ["null", "string"] + } + } + }, + "shipping": { + "type": ["null", "object"], + "properties": { + "first_name": { + "type": ["null", "string"] + }, + "last_name": { + "type": ["null", "string"] + }, + "company": { + "type": ["null", "string"] + }, + "address_1": { + "type": ["null", "string"] + }, + "address_2": { + "type": ["null", "string"] + }, + "city": { + "type": ["null", "string"] + }, + "state": { + "type": ["null", "string"] + }, + "postcode": { + "type": ["null", "string"] + }, + "country": { + "type": ["null", "string"] + } + } + }, + "is_paying_customer": { + "type": ["null", "boolean"] + }, + "avatar_url": { + "type": ["null", "string"] + }, + "meta_data": { + "type": ["null","array"], + "items": { + "type": ["null","object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "key": { + "type": ["null", "string"] + }, + "value": { + "type": ["null", "string"] + } + } + } + }, + "_links": { + "type": ["null", "object"], + "properties": { + "self": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "href": { + "type": ["null", "string"] + } + } + } + }, + "collection": { + "type": ["null", "array"], + "items" : { + "type": ["null", "object"], + "properties": { + "href": { + "type": ["null", "string"] + } + } + } + } + } + } + } + }, + "supported_sync_modes": ["incremental", "full_refresh"], + "source_defined_cursor": true, + "default_cursor_field": ["date_modified"] + }, + "sync_mode": "incremental", + "cursor_field": ["date_modified"], + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "orders", + "json_schema": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "parent_id": { + "type": ["null", "integer"] + }, + "number": { + "type": ["null", "string"] + }, + "order_key": { + "type": ["null", "string"] + }, + "created_via": { + "type": ["null", "string"] + }, + "version": { + "type": ["null", "string"] + }, + "status": { + "type": ["null", "string"] + }, + "currency": { + "type": ["null", "string"] + }, + "date_created": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_created_gmt": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_modified": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_modified_gmt": { + "type": ["null", "string"], + "format": "date-time" + }, + "discount_total": { + "type": ["null", "string"] + }, + "discount_tax": { + "type": ["null", "string"] + }, + "shipping_total": { + "type": ["null", "string"] + }, + "shipping_tax": { + "type": ["null", "string"] + }, + "cart_tax": { + "type": ["null", "string"] + }, + "total": { + "type": ["null", "string"] + }, + "total_tax": { + "type": ["null", "string"] + }, + "prices_include_tax": { + "type": ["null", "boolean"] + }, + "customer_id": { + "type": ["null", "integer"] + }, + "customer_ip_address": { + "type": ["null", "string"] + }, + "customer_user_agent": { + "type": ["null", "string"] + }, + "customer_note": { + "type": ["null", "string"] + }, + "billing": { + "type": ["null", "object"], + "properties": { + "first_name": { + "type": ["null", "string"] + }, + "last_name": { + "type": ["null", "string"] + }, + "company": { + "type": ["null", "string"] + }, + "address_1": { + "type": ["null", "string"] + }, + "address_2": { + "type": ["null", "string"] + }, + "city": { + "type": ["null", "string"] + }, + "state": { + "type": ["null", "string"] + }, + "postcode": { + "type": ["null", "string"] + }, + "country": { + "type": ["null", "string"] + }, + "email": { + "type": ["null", "string"] + }, + "phone": { + "type": ["null", "string"] + } + } + }, + "shipping": { + "type": ["null", "object"], + "properties": { + "first_name": { + "type": ["null", "string"] + }, + "last_name": { + "type": ["null", "string"] + }, + "company": { + "type": ["null", "string"] + }, + "address_1": { + "type": ["null", "string"] + }, + "address_2": { + "type": ["null", "string"] + }, + "city": { + "type": ["null", "string"] + }, + "state": { + "type": ["null", "string"] + }, + "postcode": { + "type": ["null", "string"] + }, + "country": { + "type": ["null", "string"] + } + } + }, + "payment_method": { + "type": ["null", "string"] + }, + "payment_method_title": { + "type": ["null", "string"] + }, + "transaction_id": { + "type": ["null", "string"] + }, + "date_paid": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_paid_gmt": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_completed": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_completed_gmt": { + "type": ["null", "string"], + "format": "date-time" + }, + "cart_hash": { + "type": ["null", "string"] + }, + "meta_data": { + "type": ["null","array"], + "items": { + "type": ["null","object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "key": { + "type": ["null", "string"] + }, + "value": { + "type": ["null", "string"] + } + } + } + }, + "line_items": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "name": { + "type": ["null", "string"] + }, + "product_id": { + "type": ["null", "integer"] + }, + "variation_id": { + "type": ["null", "integer"] + }, + "quantity": { + "type": ["null", "integer"] + }, + "tax_class": { + "type": ["null", "string"] + }, + "subtotal": { + "type": ["null", "string"] + }, + "subtotal_tax": { + "type": ["null", "string"] + }, + "total": { + "type": ["null", "string"] + }, + "total_tax": { + "type": ["null", "string"] + }, + "taxes":{ + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "rate_code": { + "type": ["null", "string"] + }, + "rate_id": { + "type": ["null", "string"] + }, + "label": { + "type": ["null", "string"] + }, + "compound": { + "type": ["null", "boolean"] + }, + "tax_total": { + "type": ["null", "string"] + }, + "shipping_tax_total": { + "type": ["null", "string"] + }, + "meta_data": { + "type": ["null","array"], + "items": { + "type": ["null","object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "key": { + "type": ["null", "string"] + }, + "value": { + "type": ["null", "string"] + } + } + } + } + } + } + }, + "meta_data": { + "type": ["null","array"], + "items": { + "type": ["null","object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "key": { + "type": ["null", "string"] + }, + "value": { + "type": ["null", "string"] + } + } + } + }, + "sku": { + "type": ["null", "string"] + }, + "price": { + "type": ["null", "integer"] + } + } + } + }, + "tax_lines": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "rate_code": { + "type": ["null", "string"] + }, + "rate_id": { + "type": ["null", "string"] + }, + "label": { + "type": ["null", "string"] + }, + "compound": { + "type": ["null", "boolean"] + }, + "tax_total": { + "type": ["null", "string"] + }, + "shipping_tax_total": { + "type": ["null", "string"] + }, + "meta_data": { + "type": ["null","array"], + "items": { + "type": ["null","object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "key": { + "type": ["null", "string"] + }, + "value": { + "type": ["null", "string"] + } + } + } + } + } + } + }, + "shipping_lines": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "method_title": { + "type": ["null", "string"] + }, + "method_id": { + "type": ["null", "string"] + }, + "total": { + "type": ["null", "string"] + }, + "total_tax": { + "type": ["null", "string"] + }, + "taxes": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "rate_code": { + "type": ["null", "string"] + }, + "rate_id": { + "type": ["null", "string"] + }, + "label": { + "type": ["null", "string"] + }, + "compound": { + "type": ["null", "boolean"] + }, + "tax_total": { + "type": ["null", "string"] + }, + "shipping_tax_total": { + "type": ["null", "string"] + }, + "meta_data": { + "type": ["null","array"], + "items": { + "type": ["null","object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "key": { + "type": ["null", "string"] + }, + "value": { + "type": ["null", "string"] + } + } + } + } + } + } + }, + "meta_data": { + "type": ["null","array"], + "items": { + "type": ["null","object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "key": { + "type": ["null", "string"] + }, + "value": { + "type": ["null", "string"] + } + } + } + } + } + } + }, + "fee_lines": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "name": { + "type": ["null", "string"] + }, + "tax_class": { + "type": ["null", "string"] + }, + "tax_status": { + "type": ["null", "string"] + }, + "total": { + "type": ["null", "string"] + }, + "total_tax": { + "type": ["null", "string"] + }, + "taxes": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "rate_code": { + "type": ["null", "string"] + }, + "rate_id": { + "type": ["null", "string"] + }, + "label": { + "type": ["null", "string"] + }, + "compound": { + "type": ["null", "boolean"] + }, + "tax_total": { + "type": ["null", "string"] + }, + "shipping_tax_total": { + "type": ["null", "string"] + }, + "meta_data": { + "type": ["null","array"], + "items": { + "type": ["null","object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "key": { + "type": ["null", "string"] + }, + "value": { + "type": ["null", "string"] + } + } + } + } + } + } + }, + "meta_data": { + "type": ["null","array"], + "items": { + "type": ["null","object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "key": { + "type": ["null", "string"] + }, + "value": { + "type": ["null", "string"] + } + } + } + } + } + } + }, + "coupon_lines": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "code": { + "type": ["null", "string"] + }, + "discount": { + "type": ["null", "string"] + }, + "discount_tax": { + "type": ["null", "string"] + }, + "meta_data": { + "type": ["null","array"], + "items": { + "type": ["null","object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "key": { + "type": ["null", "string"] + }, + "value": { + "type": ["null", "string"] + } + } + } + } + } + } + }, + "refunds": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "reason": { + "type": ["null", "string"] + }, + "total": { + "type": ["null", "string"] + } + } + } + }, + "set_paid": { + "type": ["null", "boolean"] + }, + "_links": { + "type": ["null", "object"], + "properties": { + "self": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "href": { + "type": ["null", "string"] + } + } + } + }, + "collection": { + "type": ["null", "array"], + "items" : { + "type": ["null", "object"], + "properties": { + "href": { + "type": ["null", "string"] + } + } + } + } + } + } + } + }, + "supported_sync_modes": ["incremental", "full_refresh"], + "source_defined_cursor": true, + "default_cursor_field": ["date_modified"] + }, + "sync_mode": "incremental", + "cursor_field": ["date_modified"], + "destination_sync_mode": "append" + }, + { + "stream": { + "name": "coupons", + "json_schema": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "code": { + "type": ["null", "string"] + }, + "amount": { + "type": ["null", "string"] + }, + "date_created": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_created_gmt": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_modified": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_modified_gmt": { + "type": ["null", "string"], + "format": "date-time" + }, + "discount_type": { + "type": ["null", "string"] + }, + "description": { + "type": ["null", "string"] + }, + "date_expires": { + "type": ["null", "string"] + }, + "date_expires_gmt": { + "type": ["null", "string"] + }, + "usage_count": { + "type": ["null", "integer"] + }, + "individual_use": { + "type": ["null", "boolean"] + }, + "product_ids": { + "type": ["null", "array"] + }, + "excluded_product_ids": { + "type": ["null", "array"] + }, + "usage_limit": { + "type": ["null", "integer"] + }, + "usage_limit_per_user": { + "type": ["null", "integer"] + }, + "limit_usage_to_x_items": { + "type": ["null", "integer"] + }, + "free_shipping": { + "type": ["null", "boolean"] + }, + "product_categories": { + "type": ["null", "array"] + }, + "excluded_product_categories": { + "type": ["null", "array"] + }, + "exclude_sale_items": { + "type": ["null", "boolean"] + }, + "minimum_amount": { + "type": ["null", "string"] + }, + "maximum_amount": { + "type": ["null", "string"] + }, + "email_restrictions": { + "type": ["null", "array"] + }, + "used_by": { + "type": ["null", "array"] + }, + "meta_data": { + "type": ["null","array"], + "items": { + "type": ["null","object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "key": { + "type": ["null", "string"] + }, + "value": { + "type": ["null", "string"] + } + } + } + }, + "_links": { + "type": ["null", "object"], + "properties": { + "self": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "href": { + "type": ["null", "string"] + } + } + } + }, + "collection": { + "type": ["null", "array"], + "items" : { + "type": ["null", "object"], + "properties": { + "href": { + "type": ["null", "string"] + } + } + } + } + } + } + } + }, + "supported_sync_modes": ["incremental", "full_refresh"], + "source_defined_cursor": true, + "default_cursor_field": ["date_modified"] + }, + "sync_mode": "incremental", + "cursor_field": ["date_modified"], + "destination_sync_mode": "append" + } + ] +} diff --git a/airbyte-integrations/connectors/source-woocommerce/integration_tests/invalid_config.json b/airbyte-integrations/connectors/source-woocommerce/integration_tests/invalid_config.json new file mode 100644 index 0000000000000..9d3132ca34db2 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/integration_tests/invalid_config.json @@ -0,0 +1,6 @@ +{ + "shop": "SHOP_NAME", + "start_date": "2060-01-01", + "api_key": "API_KEY", + "api_secret": "API_SECRET" +} diff --git a/airbyte-integrations/connectors/source-woocommerce/integration_tests/sample_config.json b/airbyte-integrations/connectors/source-woocommerce/integration_tests/sample_config.json new file mode 100644 index 0000000000000..9d3132ca34db2 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/integration_tests/sample_config.json @@ -0,0 +1,6 @@ +{ + "shop": "SHOP_NAME", + "start_date": "2060-01-01", + "api_key": "API_KEY", + "api_secret": "API_SECRET" +} diff --git a/airbyte-integrations/connectors/source-woocommerce/integration_tests/sample_state.json b/airbyte-integrations/connectors/source-woocommerce/integration_tests/sample_state.json new file mode 100644 index 0000000000000..133b93cf866a3 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/integration_tests/sample_state.json @@ -0,0 +1,11 @@ +{ + "customers": { + "date_modified": "2021-07-30T21:11:46" + }, + "orders": { + "date_modified": "2021-07-30T21:10:46" + }, + "coupons": { + "date_modified": "2021-07-30T22:09:46" + } +} diff --git a/airbyte-integrations/connectors/source-woocommerce/main.py b/airbyte-integrations/connectors/source-woocommerce/main.py new file mode 100644 index 0000000000000..e5f3251e35bb5 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/main.py @@ -0,0 +1,33 @@ +# +# MIT License +# +# Copyright (c) 2020 Airbyte +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + + +import sys + +from airbyte_cdk.entrypoint import launch +from source_woocommerce import SourceWoocommerce + +if __name__ == "__main__": + source = SourceWoocommerce() + launch(source, sys.argv[1:]) diff --git a/airbyte-integrations/connectors/source-woocommerce/requirements.txt b/airbyte-integrations/connectors/source-woocommerce/requirements.txt new file mode 100644 index 0000000000000..0411042aa0911 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/requirements.txt @@ -0,0 +1,2 @@ +-e ../../bases/source-acceptance-test +-e . diff --git a/airbyte-integrations/connectors/source-woocommerce/setup.py b/airbyte-integrations/connectors/source-woocommerce/setup.py new file mode 100644 index 0000000000000..4ca73afe46939 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/setup.py @@ -0,0 +1,49 @@ +# +# MIT License +# +# Copyright (c) 2020 Airbyte +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + + +from setuptools import find_packages, setup + +MAIN_REQUIREMENTS = [ + "airbyte-cdk", +] + +TEST_REQUIREMENTS = [ + "pytest~=6.1", + "source-acceptance-test", +] + +setup( + name="source_woocommerce", + description="Source implementation for Woocommerce.", + author="Airbyte", + author_email="contact@airbyte.io", + packages=find_packages(), + install_requires=MAIN_REQUIREMENTS, + package_data={"": ["*.json", "schemas/*.json", "schemas/shared/*.json"]}, + extras_require={ + "tests": TEST_REQUIREMENTS, + }, +) + diff --git a/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/__init__.py b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/__init__.py new file mode 100644 index 0000000000000..fdcb21c284ba4 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/__init__.py @@ -0,0 +1,27 @@ +""" +MIT License + +Copyright (c) 2020 Airbyte + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +""" + +from .source import SourceWoocommerce + +__all__ = ["SourceWoocommerce"] diff --git a/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/coupons.json b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/coupons.json new file mode 100644 index 0000000000000..4c7692408a3f8 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/coupons.json @@ -0,0 +1,94 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": ["null", "integer"] + }, + "code": { + "type": ["null", "string"] + }, + "amount": { + "type": ["null", "string"] + }, + "date_created": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_created_gmt": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_modified": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_modified_gmt": { + "type": ["null", "string"], + "format": "date-time" + }, + "discount_type": { + "type": ["null", "string"] + }, + "description": { + "type": ["null", "string"] + }, + "date_expires": { + "type": ["null", "string"] + }, + "date_expires_gmt": { + "type": ["null", "string"] + }, + "usage_count": { + "type": ["null", "integer"] + }, + "individual_use": { + "type": ["null", "boolean"] + }, + "product_ids": { + "type": ["null", "array"] + }, + "excluded_product_ids": { + "type": ["null", "array"] + }, + "usage_limit": { + "type": ["null", "integer"] + }, + "usage_limit_per_user": { + "type": ["null", "integer"] + }, + "limit_usage_to_x_items": { + "type": ["null", "integer"] + }, + "free_shipping": { + "type": ["null", "boolean"] + }, + "product_categories": { + "type": ["null", "array"] + }, + "excluded_product_categories": { + "type": ["null", "array"] + }, + "exclude_sale_items": { + "type": ["null", "boolean"] + }, + "minimum_amount": { + "type": ["null", "string"] + }, + "maximum_amount": { + "type": ["null", "string"] + }, + "email_restrictions": { + "type": ["null", "array"] + }, + "used_by": { + "type": ["null", "array"] + }, + "meta_data": { + "$ref": "meta_data.json" + }, + "_links": { + "$ref": "_links.json" + } + } +} diff --git a/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/customers.json b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/customers.json new file mode 100644 index 0000000000000..e3497620f4d53 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/customers.json @@ -0,0 +1,58 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": ["null", "integer"] + }, + "date_created": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_created_gmt": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_modified": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_modified_gmt": { + "type": ["null", "string"], + "format": "date-time" + }, + "email": { + "type": ["null", "string"] + }, + "first_name": { + "type": ["null", "string"] + }, + "last_name": { + "type": ["null", "string"] + }, + "role": { + "type": ["null", "string"] + }, + "username": { + "type": ["null", "string"] + }, + "billing": { + "$ref": "billing.json" + }, + "shipping": { + "$ref": "shipping.json" + }, + "is_paying_customer": { + "type": ["null", "boolean"] + }, + "avatar_url": { + "type": ["null", "string"] + }, + "meta_data": { + "$ref": "meta_data.json" + }, + "_links": { + "$ref": "_links.json" + } + } +} diff --git a/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/orders.json b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/orders.json new file mode 100644 index 0000000000000..0a3840f080eaa --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/orders.json @@ -0,0 +1,279 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "id": { + "type": ["null", "integer"] + }, + "parent_id": { + "type": ["null", "integer"] + }, + "number": { + "type": ["null", "string"] + }, + "order_key": { + "type": ["null", "string"] + }, + "created_via": { + "type": ["null", "string"] + }, + "version": { + "type": ["null", "string"] + }, + "status": { + "type": ["null", "string"] + }, + "currency": { + "type": ["null", "string"] + }, + "date_created": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_created_gmt": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_modified": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_modified_gmt": { + "type": ["null", "string"], + "format": "date-time" + }, + "discount_total": { + "type": ["null", "string"] + }, + "discount_tax": { + "type": ["null", "string"] + }, + "shipping_total": { + "type": ["null", "string"] + }, + "shipping_tax": { + "type": ["null", "string"] + }, + "cart_tax": { + "type": ["null", "string"] + }, + "total": { + "type": ["null", "string"] + }, + "total_tax": { + "type": ["null", "string"] + }, + "prices_include_tax": { + "type": ["null", "boolean"] + }, + "customer_id": { + "type": ["null", "integer"] + }, + "customer_ip_address": { + "type": ["null", "string"] + }, + "customer_user_agent": { + "type": ["null", "string"] + }, + "customer_note": { + "type": ["null", "string"] + }, + "billing": { + "$ref": "billing.json" + }, + "shipping": { + "$ref": "shipping.json" + }, + "payment_method": { + "type": ["null", "string"] + }, + "payment_method_title": { + "type": ["null", "string"] + }, + "transaction_id": { + "type": ["null", "string"] + }, + "date_paid": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_paid_gmt": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_completed": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_completed_gmt": { + "type": ["null", "string"], + "format": "date-time" + }, + "cart_hash": { + "type": ["null", "string"] + }, + "meta_data": { + "$ref": "meta_data.json" + }, + "line_items": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "name": { + "type": ["null", "string"] + }, + "product_id": { + "type": ["null", "integer"] + }, + "variation_id": { + "type": ["null", "integer"] + }, + "quantity": { + "type": ["null", "integer"] + }, + "tax_class": { + "type": ["null", "string"] + }, + "subtotal": { + "type": ["null", "string"] + }, + "subtotal_tax": { + "type": ["null", "string"] + }, + "total": { + "type": ["null", "string"] + }, + "total_tax": { + "type": ["null", "string"] + }, + "taxes":{ + "$ref": "taxes.json" + }, + "meta_data": { + "$ref": "meta_data.json" + }, + "sku": { + "type": ["null", "string"] + }, + "price": { + "type": ["null", "integer"] + } + } + } + }, + "tax_lines": { + "$ref": "taxes.json" + }, + "shipping_lines": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "method_title": { + "type": ["null", "string"] + }, + "method_id": { + "type": ["null", "string"] + }, + "total": { + "type": ["null", "string"] + }, + "total_tax": { + "type": ["null", "string"] + }, + "taxes": { + "$ref": "taxes.json" + }, + "meta_data": { + "$ref": "meta_data.json" + } + } + } + }, + "fee_lines": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "name": { + "type": ["null", "string"] + }, + "tax_class": { + "type": ["null", "string"] + }, + "tax_status": { + "type": ["null", "string"] + }, + "total": { + "type": ["null", "string"] + }, + "total_tax": { + "type": ["null", "string"] + }, + "taxes": { + "$ref": "taxes.json" + }, + "meta_data": { + "$ref": "meta_data.json" + } + } + } + }, + "coupon_lines": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "code": { + "type": ["null", "string"] + }, + "discount": { + "type": ["null", "string"] + }, + "discount_tax": { + "type": ["null", "string"] + }, + "meta_data": { + "$ref": "meta_data.json" + } + } + } + }, + "refunds": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "reason": { + "type": ["null", "string"] + }, + "total": { + "type": ["null", "string"] + } + } + } + }, + "set_paid": { + "type": ["null", "boolean"] + }, + "_links": { + "$ref": "_links.json" + } + } +} diff --git a/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/shared/_links.json b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/shared/_links.json new file mode 100644 index 0000000000000..9b78d3ace360d --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/shared/_links.json @@ -0,0 +1,27 @@ +{ + "type": ["null", "object"], + "properties": { + "self": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "href": { + "type": ["null", "string"] + } + } + } + }, + "collection": { + "type": ["null", "array"], + "items" : { + "type": ["null", "object"], + "properties": { + "href": { + "type": ["null", "string"] + } + } + } + } + } +} diff --git a/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/shared/billing.json b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/shared/billing.json new file mode 100644 index 0000000000000..e14ea868df031 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/shared/billing.json @@ -0,0 +1,38 @@ +{ + "type": ["null", "object"], + "properties": { + "first_name": { + "type": ["null", "string"] + }, + "last_name": { + "type": ["null", "string"] + }, + "company": { + "type": ["null", "string"] + }, + "address_1": { + "type": ["null", "string"] + }, + "address_2": { + "type": ["null", "string"] + }, + "city": { + "type": ["null", "string"] + }, + "state": { + "type": ["null", "string"] + }, + "postcode": { + "type": ["null", "string"] + }, + "country": { + "type": ["null", "string"] + }, + "email": { + "type": ["null", "string"] + }, + "phone": { + "type": ["null", "string"] + } + } +} diff --git a/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/shared/meta_data.json b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/shared/meta_data.json new file mode 100644 index 0000000000000..dff0982b110a6 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/shared/meta_data.json @@ -0,0 +1,17 @@ +{ + "type": ["null","array"], + "items": { + "type": ["null","object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "key": { + "type": ["null", "string"] + }, + "value": { + "type": ["null", "string"] + } + } + } +} diff --git a/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/shared/shipping.json b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/shared/shipping.json new file mode 100644 index 0000000000000..cb0d139f6ec53 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/shared/shipping.json @@ -0,0 +1,32 @@ +{ + "type": ["null", "object"], + "properties": { + "first_name": { + "type": ["null", "string"] + }, + "last_name": { + "type": ["null", "string"] + }, + "company": { + "type": ["null", "string"] + }, + "address_1": { + "type": ["null", "string"] + }, + "address_2": { + "type": ["null", "string"] + }, + "city": { + "type": ["null", "string"] + }, + "state": { + "type": ["null", "string"] + }, + "postcode": { + "type": ["null", "string"] + }, + "country": { + "type": ["null", "string"] + } + } +} diff --git a/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/shared/taxes.json b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/shared/taxes.json new file mode 100644 index 0000000000000..7418d9010a962 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/schemas/shared/taxes.json @@ -0,0 +1,32 @@ +{ + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "integer"] + }, + "rate_code": { + "type": ["null", "string"] + }, + "rate_id": { + "type": ["null", "string"] + }, + "label": { + "type": ["null", "string"] + }, + "compound": { + "type": ["null", "boolean"] + }, + "tax_total": { + "type": ["null", "string"] + }, + "shipping_tax_total": { + "type": ["null", "string"] + }, + "meta_data": { + "$ref": "meta_data.json" + } + } + } +} diff --git a/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/source.py b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/source.py new file mode 100644 index 0000000000000..4442b410295d5 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/source.py @@ -0,0 +1,186 @@ +# +# MIT License +# +# Copyright (c) 2020 Airbyte +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + + +from base64 import b64encode +from abc import ABC +from typing import Any, Iterable, List, Mapping, MutableMapping, Optional, Tuple +from urllib.parse import parse_qsl, urlparse + +import requests +from airbyte_cdk import AirbyteLogger +from airbyte_cdk.models import SyncMode +from airbyte_cdk.sources import AbstractSource +from airbyte_cdk.sources.streams import Stream +from airbyte_cdk.sources.streams.http import HttpStream +from airbyte_cdk.sources.streams.http.auth import TokenAuthenticator + + +# Basic full refresh stream +class WoocommerceStream(HttpStream, ABC): + + # Latest Stable Release + api_version = "wc/v3" + # Page size + limit = 100 + # Define primary key as sort key for full_refresh, or very first sync for incremental_refresh + primary_key = "id" + order_field = "date" + + def __init__(self, shop: str, start_date: str, api_key: str, api_secret: str, **kwargs): + super().__init__(**kwargs) + self.start_date = start_date + self.shop = shop + self.api_key = api_key + self.api_secret = api_secret + + @property + def url_base(self) -> str: + return f"https://{self.shop}.com/wp-json/{self.api_version}/" + + def path(self, **kwargs) -> str: + return f"{self.data_field}" + + def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]: + next_page = response.links.get("next", None) + if next_page: + return dict(parse_qsl(urlparse(next_page.get("url")).query)) + else: + return None + + def request_params( + self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, any] = None, next_page_token: Mapping[str, Any] = None + ) -> MutableMapping[str, Any]: + params = {"per_page": self.limit} + if next_page_token: + params.update(**next_page_token) + else: + params.update({"orderby":self.order_field,"order":"asc"}) + return params + + def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]: + yield from response.json() + +class IncrementalWoocommerceStream(WoocommerceStream, ABC): + # Getting page size as 'limit' from parrent class + @property + def limit(self): + return super().limit + + # Setting the check point interval to the limit of the records output + state_checkpoint_interval = limit + # Setting the default cursor field for all streams + cursor_field = "date_modified" + + def get_updated_state(self, current_stream_state: MutableMapping[str, Any], latest_record: Mapping[str, Any]) -> Mapping[str, Any]: + return {self.cursor_field: max(latest_record.get(self.cursor_field, ""), current_stream_state.get(self.cursor_field, ""))} + + def request_params(self, stream_state: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None, **kwargs): + params = super().request_params(stream_state=stream_state, next_page_token=next_page_token, **kwargs) + # If there is a next page token then we should only send pagination-related parameters. + if not next_page_token: + params["orderby"] = self.order_field + params["order"] = "asc" + if stream_state: + params["after"] = stream_state.get(self.cursor_field) + return params + + # Parse the stream_slice with respect to stream_state for Incremental refresh + # cases where we slice the stream, the endpoints for those classes don't accept any other filtering, + # but they provide us with the updated_at field in most cases, so we used that as incremental filtering during the order slicing. + def filter_records_newer_than_state(self, stream_state: Mapping[str, Any] = None, records_slice: Mapping[str, Any] = None) -> Iterable: + # Getting records >= state + if stream_state: + for record in records_slice: + if record[self.cursor_field] >= stream_state.get(self.cursor_field): + yield record + else: + yield from records_slice + +class NonFilteredStream(IncrementalWoocommerceStream): + + def request_params(self, stream_state: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None, **kwargs): + params = super().request_params(stream_state=stream_state, next_page_token=next_page_token, **kwargs) + + if not next_page_token and stream_state: + del params["after"] + return params + + def read_records( + self, stream_state: Mapping[str, Any] = None, stream_slice: Optional[Mapping[str, Any]] = None, **kwargs + ) -> Iterable[Mapping[str, Any]]: + + slice = super().read_records(sync_mode = SyncMode.full_refresh, stream_slice = stream_slice,stream_state = stream_state) + yield from self.filter_records_newer_than_state(stream_state=stream_state, records_slice=slice) + + +class Coupons(IncrementalWoocommerceStream): + data_field = "coupons" + + +class Customers(NonFilteredStream): + data_field = "customers" + order_field = "registered_date" + + +class Orders(IncrementalWoocommerceStream): + data_field = "orders" + + +# Source +class SourceWoocommerce(AbstractSource): + + def _convert_auth_to_token(self, username: str, password: str) -> str: + username = username.encode("latin1") + password = password.encode("latin1") + token = b64encode(b":".join((username, password))).strip().decode("ascii") + return token + + def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) -> Tuple[bool, any]: + """ + Testing connection availability for the connector. + """ + shop = config['shop'] + headers = {"Accept": "application/json"} + url = f"https://{shop}.com/wp-json/wc/v3/" + + try: + auth = TokenAuthenticator(token=self._convert_auth_to_token(config["api_key"], config["api_secret"]), auth_method="Basic") + headers = dict(Accept = "application/json", **auth.get_auth_header()) + session = requests.get(url, headers=headers) + session.raise_for_status() + return True, None + except requests.exceptions.RequestException as e: + return False, e + + def streams(self, config: Mapping[str, Any]) -> List[Stream]: + + auth = auth = TokenAuthenticator(token=self._convert_auth_to_token(config["api_key"], config["api_secret"]), auth_method="Basic") # Oauth2Authenticator is also available if you need oauth support + args = {"authenticator": auth, "shop": config["shop"], "start_date": config["start_date"], "api_key": config["api_key"], "api_secret": config["api_secret"]} + + return [ + Customers(**args), + Coupons(**args), + Orders(**args) + ] diff --git a/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/spec.json b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/spec.json new file mode 100644 index 0000000000000..776576a135949 --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/source_woocommerce/spec.json @@ -0,0 +1,33 @@ +{ + "documentationUrl": "https://docs.airbyte.io/integrations/sources/woocommerce", + "connectionSpecification": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Woocommerce Source CDK Specifications", + "type": "object", + "required": ["shop", "start_date","api_key","api_secret"], + "additionalProperties": false, + "properties": { + "shop": { + "type": "string", + "description": "The name of the store. For https://EXAMPLE.com, the shop name is 'EXAMPLE'." + }, + "start_date": { + "type": "string", + "description": "The date you would like to replicate data. Format: YYYY-MM-DD.", + "examples": ["2021-01-01"], + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" + }, + "api_key": { + "type": "string", + "description": "The CUSTOMER KEY for API in WooCommerce shop.", + "airbyte_secret": true + }, + "api_secret": { + "type": "string", + "description": "The CUSTOMER SECRET for API in WooCommerce shop.", + "airbyte_secret": true + } + } + } +} + diff --git a/airbyte-integrations/connectors/source-woocommerce/unit_tests/unit_test.py b/airbyte-integrations/connectors/source-woocommerce/unit_tests/unit_test.py new file mode 100644 index 0000000000000..b8a8150b507fd --- /dev/null +++ b/airbyte-integrations/connectors/source-woocommerce/unit_tests/unit_test.py @@ -0,0 +1,27 @@ +# +# MIT License +# +# Copyright (c) 2020 Airbyte +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + + +def test_example_method(): + assert True diff --git a/docs/integrations/sources/woocommerce.md b/docs/integrations/sources/woocommerce.md new file mode 100644 index 0000000000000..4e97d0c065a1e --- /dev/null +++ b/docs/integrations/sources/woocommerce.md @@ -0,0 +1,50 @@ +# WooCommerce + +## Sync overview + +The WooCommerce source supports both Full Refresh and Incremental syncs. You can choose if this connector will copy only the new or updated data, or all rows in the tables and columns you set up for replication, every time a sync is run. + +This source can sync data for the [WooCommerce API](https://woocommerce.github.io/woocommerce-rest-api-docs/). + +This Source Connector is based on a [Airbyte CDK](https://docs.airbyte.io/connector-development/cdk-python). + +### Output schema + +This Source is capable of syncing the following core Streams: + +* [Customers](https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-customers) +* [Orders](https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-orders) +* [Coupons](https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-coupons) + +### Data type mapping + +| Integration Type | Airbyte Type | Notes | +| :--- | :--- | :--- | +| `string` | `string` | | +| `number` | `number` | | +| `array` | `array` | | +| `object` | `object` | | + +### Features + +| Feature | Supported?\(Yes/No\) | Notes | +| :--- | :--- | :--- | +| Full Refresh Sync | Yes | | +| Incremental - Append Sync | Yes | | +| Namespaces | No | | + +## Getting started + +1. Navigate to your store’s WordPress admin interface, go to (WooCommerce > Settings > Advanced > REST API) +2. Click on "Add Key" to generate an API Key +3. Choose the level of access for this REST API key, which can be Read access, Write access or Read/Write access. Airbyte only needs read-level access. + * Note: The UI will show all possible data sources and will show errors when syncing if it doesn't have permissions to access a resource. +4. The two keys, Consumer Key and Consumer Secret are what you'll use respectively as `api_key` and `api_secret` for the integration. +5. You're ready to set up WooCommerce in Airbyte! + + +## Changelog + +| Version | Date | Pull Request | Subject | +| :------ | :-------- | :----- | :------ | +| 0.1.0 | 2021-09-09 | [5955](https://github.com/airbytehq/airbyte/pull/5955) | Initial Release. Source WooCommerce |