Skip to content

Commit

Permalink
chore(readme): update readme and test
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerald Baulig committed Dec 13, 2023
1 parent 0aacead commit 670d005
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 13 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup NodeJS
uses: actions/setup-node@v1
with:
node-version: '12.18'
node-version: '20.8.0'

- name: Setup System
uses: restorecommerce/setup-system-action@v1
Expand All @@ -21,22 +21,18 @@ jobs:

- name: Install Dependencies
run: npm ci
working-directory: demo-shop

- name: Import master data
- name: Import system master data
run: |
API_KEY=$(docker logs restorecommerce_facade_srv 2>/dev/null | grep API | awk '{print $7}')
node import.js import -t $API_KEY -j master
working-directory: demo-shop
node import.js import -t $API_KEY -d system -j master
- name: Import identity data
- name: Import system identity data
run: |
API_KEY=$(docker logs restorecommerce_facade_srv 2>/dev/null | grep API | awk '{print $7}')
node import.js import -t $API_KEY -j identity
working-directory: demo-shop
node import.js import -t $API_KEY -d system -j identity
- name: Import extra data
run: |
API_KEY=$(docker logs restorecommerce_facade_srv 2>/dev/null | grep API | awk '{print $7}')
node import.js import -t $API_KEY -j extra
working-directory: demo-shop
node import.js import -t $API_KEY -d system -j extra
5 changes: 3 additions & 2 deletions datasets/demo-shop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ The data set comprises the following resources:
The data is partially generated with a set of generator scripts which reside
under [generator](generator).

> NOTE: Please import dataset [System](../system) before [Demo Shop](../demo-shop).
## Usage

This data set comes with a set of scripts which import JSON and YAML data.
Expand All @@ -24,11 +26,10 @@ to import the data locally or into the production environment.

- master (imports resources `organizations`, `addresses`, `contact_points`, `shops`, `customers`)
- identity (imports `users`)
- extra (import resources )
- catalog (imports resources `price_group`, `manufacturer`, `product_category`, `product_prototype`, `product`)

> NOTE: Resources must be imported in a specific order!
> Master > Identity > Extra > Catalog.
> Master > Identity > Catalog.
>
> For the case when importing resources returns "Access denied", one way to fix
> this is to restart `facade-srv` in order to sync the api key with the other
Expand Down
2 changes: 1 addition & 1 deletion datasets/system/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
data/generated/
#data/generated/
objects/*.js
objects/*.js.map
objects/*.d.ts
64 changes: 64 additions & 0 deletions datasets/system/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# System Data Set for Restorecommerce

The data set comprises the following resources:

- System relevant enumerations
- Basic access control rules, policies and roles
- Tech users
- Unit codes, countries, timezones, taxes, etc.

The data is partially generated with a set of generator scripts which reside
under [generator](generator).

## Usage

This data set comes with a set of scripts which import JSON and YAML data.
Resources are imported using the [gql-bot](https://github.com/restorecommerce/gql-bot) which is an automated task processor with a GraphQL Client.
All data is imported via the GraphQL API exposed by the [facade-srv](https://github.com/restorecommerce/facade-srv).

All possible operations are exposed through JS scripts.
These scripts either execute GraphQL mutations/ queries through the `import.js` script.
The `import.js` also includes command-line options such as specifying if we wish
to import the data locally or into the production environment.

### Current supported jobs are

- master (imports resources `commands` `contact_points_types`, `countries`, `locales`, `organizations`, `tax_types`, `taxes`, `timezones`)
- identity (imports `users`, `policies`, `policy_sets`, `roles`, `rules`)
- extra (imports resources `unit_codes`)

> NOTE: Resources must be imported in a specific order!
> Master > Identity > Extra.
>
> For the case when importing resources returns "Access denied", one way to fix
> this is to restart `facade-srv` in order to sync the api key with the other
> upstream services.
### Script usage

1. Extract the API-KEY from the logs of `facade-srv`.

2. Either export the API-KEY, paste it to an `.env` file or paste as command argument.

2. Generate catalog datasets using [`transform.js script`](./generator/catalog/transform.js):

- `node ./transform.js`

3. Import datasets using [`import.js script`](./import.js):

- `node ./import.js import -t <access_token> -d system -j <job>`

4. Examples:

- `node ./import.js import -t <access_token> -d system -j master`
- `node ./import.js import -t <access_token> -d system -j identity`
- `node ./import.js import -t <access_token> -d system -j extra`

### Supported environment variables: `GQL_ENDPOINT`.

All flags are optional, and they can be listed by typing `node ./import.js -h`.
The API key can be obtained from the [`facade-srv`](https://github.com/restorecommerce/facade-srv/blob/master/cfg/config.json#L21) configuration.
The API key is generated during system startup from the `facade-srv` (Check the log message of facade-srv `Bootstrap API Key is`).

By default, the GraphQL importer uses the configuration file `config.json` to read data regarding endpoints for retrieving the API key
and executing mutations/ queries.
7 changes: 7 additions & 0 deletions datasets/system/jobs/job_master.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
"src": "./datasets/system/data/seed-data/",
"filter": "contact_point_types.yaml",
"mutation": "mutation{ master_data { contact_point_type { Mutate( input: { items: ${resource_list}, totalCount: 0, mode: UPSERT } ) { details{items {status {id, code, message}}, operationStatus { code message } } } } }}"
},
{
"name": "organizations",
"operation": "sync",
"src": "./datasets/system/data/seed-data/",
"filter": "organizations.yaml",
"mutation": "mutation mutateOrganizations($var: [IIoRestorecommerceOrganizationOrganization!]!){ master_data { organization { Mutate( input: { items: $var, totalCount: 0, mode: UPSERT } ) { details{items {status {id, code, message}}, operationStatus { code message } } } } }}"
}
]
}

0 comments on commit 670d005

Please sign in to comment.