Skip to content

Commit 0d0db5b

Browse files
authoredNov 26, 2024··
Initial commit
0 parents  commit 0d0db5b

17 files changed

+866
-0
lines changed
 

‎.github/workflows/build.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: build
5+
6+
on:
7+
push:
8+
branches: [ main ]
9+
pull_request:
10+
branches: [ main ]
11+
12+
jobs:
13+
build:
14+
environment: test
15+
env:
16+
TRELLO_APIKEY: ${{secrets.TRELLO_APIKEY}}
17+
TRELLO_USERTOKEN: ${{secrets.TRELLO_USERTOKEN}}
18+
19+
timeout-minutes: 6
20+
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
os: [ubuntu-latest, windows-latest, macos-latest]
25+
node-version: [lts/*, 17.x, 16.x]
26+
27+
runs-on: ${{ matrix.os }}
28+
29+
steps:
30+
- uses: actions/checkout@v2
31+
- name: Use Node.js ${{ matrix.node-version }}
32+
uses: actions/setup-node@v2
33+
with:
34+
node-version: ${{ matrix.node-version }}
35+
- run: npm install
36+
# manually install peerdeps for node 12,14
37+
- run: npm i seneca seneca-entity seneca-promisify @seneca/provider @seneca/env
38+
- run: npm run build --if-present
39+
- run: npm test
40+
41+
- name: Coveralls
42+
uses: coverallsapp/github-action@master
43+
with:
44+
github-token: ${{ secrets.GITHUB_TOKEN }}
45+
path-to-lcov: ./coverage/lcov.info

‎.github/workflows/todo.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: "TODO"
2+
on: ["push"]
3+
jobs:
4+
build:
5+
runs-on: "ubuntu-latest"
6+
steps:
7+
- uses: "actions/checkout@master"
8+
- name: "todo-to-issue"
9+
uses: "senecajs/todo-to-issue-action@master"
10+
with:
11+
REPO: ${{ github.repository }}
12+
BEFORE: ${{ github.event.before }}
13+
SHA: ${{ github.sha }}
14+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
15+
LABEL: "TODO:"
16+
COMMENT_MARKER: "//"
17+
INCLUDE_EXT: ".js,.md,.ts"
18+
id: "todo"

‎.gitignore

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
78+
# Next.js build output
79+
.next
80+
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
84+
# Gatsby files
85+
.cache/
86+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
87+
# https://nextjs.org/blog/next-9-1#public-directory-support
88+
# public
89+
90+
# vuepress build output
91+
.vuepress/dist
92+
93+
# Serverless directories
94+
.serverless/
95+
96+
# FuseBox cache
97+
.fusebox/
98+
99+
# DynamoDB Local files
100+
.dynamodb/
101+
102+
# TernJS port file
103+
.tern-port
104+
105+
*~
106+
107+
package-lock.json
108+
yarn.lock
109+
110+
test/local-config.js
111+
test/local-env.js
112+

‎LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Seneca Microservices Framework
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎README.md

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
![Seneca Tangocard-Provider](http://senecajs.org/files/assets/seneca-logo.png)
2+
3+
> _Seneca Tangocard-Provider_ is a plugin for [Seneca](http://senecajs.org)
4+
5+
6+
Provides access to the Tangocard API using the Seneca *provider*
7+
convention. Tangocard API entities are represented as Seneca entities so
8+
that they can be accessed using the Seneca entity API and messages.
9+
10+
See [seneca-entity](senecajs/seneca-entity) and the [Seneca Data
11+
Entities
12+
Tutorial](https://senecajs.org/docs/tutorials/understanding-data-entities.html) for more details on the Seneca entity API.
13+
14+
NOTE: underlying third party SDK needs to be replaced as out of date and has a security issue.
15+
16+
[![npm version](https://img.shields.io/npm/v/@seneca/tangocard-provider.svg)](https://npmjs.com/package/@seneca/tangocard-provider)
17+
[![build](https://github.com/senecajs/seneca-tangocard-provider/actions/workflows/build.yml/badge.svg)](https://github.com/senecajs/seneca-tangocard-provider/actions/workflows/build.yml)
18+
[![Coverage Status](https://coveralls.io/repos/github/senecajs/seneca-tangocard-provider/badge.svg?branch=main)](https://coveralls.io/github/senecajs/seneca-tangocard-provider?branch=main)
19+
[![Known Vulnerabilities](https://snyk.io/test/github/senecajs/seneca-tangocard-provider/badge.svg)](https://snyk.io/test/github/senecajs/seneca-tangocard-provider)
20+
[![DeepScan grade](https://deepscan.io/api/teams/5016/projects/19462/branches/505954/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=5016&pid=19462&bid=505954)
21+
[![Maintainability](https://api.codeclimate.com/v1/badges/f76e83896b731bb5d609/maintainability)](https://codeclimate.com/github/senecajs/seneca-tangocard-provider/maintainability)
22+
23+
24+
| ![Voxgig](https://www.voxgig.com/res/img/vgt01r.png) | This open source module is sponsored and supported by [Voxgig](https://www.voxgig.com). |
25+
|---|---|
26+
27+
28+
## Quick Example
29+
30+
31+
```js
32+
33+
// Setup - get the key value (<SECRET>) separately from a vault or
34+
// environment variable.
35+
Seneca()
36+
// Get API keys using the seneca-env plugin
37+
.use('env', {
38+
var: {
39+
$TANGOCARD_APIKEY: String,
40+
$TANGOCARD_USERTOKEN: String,
41+
}
42+
})
43+
.use('provider', {
44+
provider: {
45+
tangocard: {
46+
keys: {
47+
apikey: { value: '$TANGOCARD_APIKEY' },
48+
usertoken: { value: '$TANGOCARD_USERTOKEN' },
49+
}
50+
}
51+
}
52+
})
53+
.use('tangocard-provider')
54+
55+
let board = await seneca.entity('provider/tangocard/board')
56+
.load$('<tangocard-board-id>')
57+
58+
Console.log('BOARD', board)
59+
60+
board.desc = 'New description'
61+
board = await board.save$()
62+
63+
Console.log('UPDATED BOARD', board)
64+
65+
```
66+
67+
## Install
68+
69+
```sh
70+
$ npm install @seneca/tangocard-provider @seneca/env
71+
```
72+
73+
74+
75+
<!--START:options-->
76+
77+
78+
## Options
79+
80+
* `debug` : boolean <i><small>false</small></i>
81+
82+
83+
Set plugin options when loading with:
84+
```js
85+
86+
87+
seneca.use('TangocardProvider', { name: value, ... })
88+
89+
90+
```
91+
92+
93+
<small>Note: <code>foo.bar</code> in the list above means
94+
<code>{ foo: { bar: ... } }</code></small>
95+
96+
97+
98+
<!--END:options-->
99+
100+
<!--START:action-list-->
101+
102+
103+
## Action Patterns
104+
105+
* [role:entity,base:tangocard,cmd:load,name:repo,zone:provider](#-roleentitybasetangocardcmdloadnamerepozoneprovider-)
106+
* [role:entity,base:tangocard,cmd:save,name:repo,zone:provider](#-roleentitybasetangocardcmdsavenamerepozoneprovider-)
107+
* [sys:provider,get:info,provider:tangocard](#-sysprovidergetinfoprovidertangocard-)
108+
109+
110+
<!--END:action-list-->
111+
112+
<!--START:action-desc-->
113+
114+
115+
## Action Descriptions
116+
117+
### &laquo; `role:entity,base:tangocard,cmd:load,name:repo,zone:provider` &raquo;
118+
119+
Load Tangocard repository data into an entity.
120+
121+
122+
123+
----------
124+
### &laquo; `role:entity,base:tangocard,cmd:save,name:repo,zone:provider` &raquo;
125+
126+
Update Tangocard repository data from an entity.
127+
128+
129+
130+
----------
131+
### &laquo; `sys:provider,get:info,provider:tangocard` &raquo;
132+
133+
Get information about the provider.
134+
135+
136+
137+
----------
138+
139+
140+
<!--END:action-desc-->

‎jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
transform: {
3+
"^.+\\.tsx?$": "es-jest"
4+
},
5+
testEnvironment: 'node',
6+
testMatch: ['**/test/**/*.test.ts'],
7+
watchPathIgnorePatterns: ['dist\\/'],
8+
collectCoverageFrom: ['src/**/*.ts'],
9+
coverageProvider: 'v8',
10+
}

‎package.json

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"name": "@seneca/tangocard-provider",
3+
"version": "1.0.0",
4+
"main": "dist/tangocard-provider.js",
5+
"type": "commonjs",
6+
"types": "dist/tangocard-provider.d.ts",
7+
"description": "Seneca entity provider for the Tangocard API.",
8+
"homepage": "https://github.com/senecajs/seneca-tangocard-provider",
9+
"keywords": [
10+
"seneca",
11+
"tangocard",
12+
"tangocard-provider"
13+
],
14+
"author": "Richard Rodger - richardrodger.com",
15+
"repository": {
16+
"type": "git",
17+
"url": "git://github.com/senecajs/seneca-tangocard-provider.git"
18+
},
19+
"scripts": {
20+
"test": "jest --coverage",
21+
"test-nocov": "jest --coverage",
22+
"test-some": "jest -t",
23+
"test-watch": "jest --coverage --watchAll",
24+
"watch": "tsc -w -d",
25+
"build": "tsc -d",
26+
"doc": "echo seneca-doc -p @seneca/provider FIX-broken",
27+
"clean": "rm -rf node_modules dist yarn.lock package-lock.json",
28+
"reset": "npm run clean && npm i && npm test",
29+
"repo-tag": "REPO_VERSION=`node -e \"console.log(require('./package').version)\"` && echo TAG: v$REPO_VERSION && git commit -a -m v$REPO_VERSION && git push && git tag v$REPO_VERSION && git push --tags;",
30+
"repo-publish": "npm run clean && npm i && npm run repo-publish-quick",
31+
"repo-publish-quick": "npm run build && npm run test && npm run doc && npm run repo-tag && npm publish --access public --registry https://registry.npmjs.org "
32+
},
33+
"license": "MIT",
34+
"files": [
35+
"dist",
36+
"src/**/*.ts",
37+
"LICENSE"
38+
],
39+
"engines": {
40+
"node": ">=14"
41+
},
42+
"dependencies": {
43+
},
44+
"peerDependencies": {
45+
"@seneca/env": ">=0.2",
46+
"@seneca/provider": ">=1.0",
47+
"seneca": ">=3",
48+
"seneca-entity": ">=19",
49+
"seneca-promisify": ">=3"
50+
},
51+
"devDependencies": {
52+
"@seneca/doc": "^4.1.0",
53+
"@seneca/env": ">=0.2",
54+
"@seneca/provider": ">=1.0",
55+
"@types/jest": "^29.4.0",
56+
"@types/node": "^18.13.0",
57+
"esbuild": "^0.17.7",
58+
"es-jest": "^2.1.0",
59+
"jest": "^29.4.2",
60+
"seneca": ">=3",
61+
"seneca-entity": ">=19",
62+
"seneca-msg-test": "^3.4.0",
63+
"seneca-promisify": ">=3",
64+
"typescript": "^4.9.5"
65+
}
66+
}

‎src/TangocardProvider-doc.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* Copyright © 2022 Seneca Project Contributors, MIT License. */
2+
3+
4+
const docs = {
5+
6+
get_info: {
7+
desc: 'Get information about the Tangocard SDK.',
8+
},
9+
10+
}
11+
12+
export default docs
13+
14+
if ('undefined' !== typeof (module)) {
15+
module.exports = docs
16+
}

‎src/tangocard-provider.ts

+181
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
/* Copyright © 2022-2023 Seneca Project Contributors, MIT License. */
2+
3+
4+
const Pkg = require('../package.json')
5+
6+
7+
type TangocardProviderOptions = {
8+
url: string
9+
fetch: any
10+
entity: Record<string, any>
11+
debug: boolean
12+
}
13+
14+
15+
function TangocardProvider(this: any, options: TangocardProviderOptions) {
16+
const seneca: any = this
17+
18+
const makeUtils = this.export('provider/makeUtils')
19+
20+
const {
21+
makeUrl,
22+
getJSON,
23+
postJSON,
24+
entityBuilder
25+
} = makeUtils({
26+
name: 'tangocard',
27+
url: options.url,
28+
})
29+
30+
31+
seneca
32+
.message('sys:provider,provider:tangocard,get:info', get_info)
33+
34+
35+
const makeConfig = (config?: any) => seneca.util.deep({
36+
headers: {
37+
...seneca.shared.headers
38+
}
39+
}, config)
40+
41+
42+
43+
async function get_info(this: any, _msg: any) {
44+
return {
45+
ok: true,
46+
name: 'tangocard',
47+
version: Pkg.version,
48+
}
49+
}
50+
51+
52+
entityBuilder(this, {
53+
provider: {
54+
name: 'tangocard'
55+
},
56+
entity: {
57+
customer: {
58+
cmd: {
59+
list: {
60+
action: async function(this: any, entize: any, msg: any) {
61+
let json: any =
62+
await getJSON(makeUrl('customers', msg.q), makeConfig())
63+
let customers = json
64+
let list = customers.map((data: any) => entize(data))
65+
return list
66+
},
67+
}
68+
}
69+
},
70+
brand: {
71+
cmd: {
72+
list: {
73+
action: async function(this: any, entize: any, msg: any) {
74+
let json: any =
75+
await getJSON(makeUrl('catalogs', msg.q), makeConfig())
76+
let brands = json.brands
77+
let list = brands.map((data: any) => entize(data))
78+
return list
79+
},
80+
}
81+
}
82+
},
83+
order: {
84+
cmd: {
85+
list: {
86+
action: async function(this: any, entize: any, msg: any) {
87+
let json: any =
88+
await getJSON(makeUrl('orders', msg.q), makeConfig())
89+
let orders = json.orders
90+
let list = orders.map((data: any) => entize(data))
91+
92+
// TODO: ensure seneca-transport preserves array props
93+
list.page = json.page
94+
95+
return list
96+
},
97+
},
98+
save: {
99+
action: async function(this: any, entize: any, msg: any) {
100+
let body = this.util.deep(
101+
this.shared.primary,
102+
options.entity.order.save,
103+
msg.ent.data$(false)
104+
)
105+
106+
let json: any =
107+
await postJSON(makeUrl('orders', msg.q), makeConfig({
108+
body
109+
}))
110+
111+
let order = json
112+
order.id = order.referenceOrderID
113+
return entize(order)
114+
},
115+
}
116+
}
117+
}
118+
}
119+
})
120+
121+
122+
123+
seneca.prepare(async function(this: any) {
124+
let res =
125+
await this.post('sys:provider,get:keymap,provider:tangocard')
126+
127+
if (!res.ok) {
128+
throw this.fail('keymap')
129+
}
130+
131+
let src = res.keymap.name.value + ':' + res.keymap.key.value
132+
let auth = Buffer.from(src).toString('base64')
133+
134+
this.shared.headers = {
135+
Authorization: 'Basic ' + auth
136+
}
137+
138+
this.shared.primary = {
139+
customerIdentifier: res.keymap.cust.value,
140+
accountIdentifier: res.keymap.acc.value,
141+
}
142+
143+
})
144+
145+
146+
return {
147+
exports: {
148+
}
149+
}
150+
}
151+
152+
153+
// Default options.
154+
const defaults: TangocardProviderOptions = {
155+
156+
// NOTE: include trailing /
157+
url: 'https://integration-api.tangocard.com/raas/v2/',
158+
159+
// Use global fetch by default - if exists
160+
fetch: ('undefined' === typeof fetch ? undefined : fetch),
161+
162+
entity: {
163+
order: {
164+
save: {
165+
// Default fields
166+
}
167+
}
168+
},
169+
170+
// TODO: Enable debug logging
171+
debug: false
172+
}
173+
174+
175+
Object.assign(TangocardProvider, { defaults })
176+
177+
export default TangocardProvider
178+
179+
if ('undefined' !== typeof (module)) {
180+
module.exports = TangocardProvider
181+
}

‎test/basic.messages.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* Copyright © 2022 Seneca Project Contributors, MIT License. */
2+
3+
const Pkg = require('../package.json')
4+
5+
module.exports = {
6+
print: false,
7+
pattern: 'sys:provider,provider:tangocard',
8+
allow: { missing: true },
9+
10+
calls: [
11+
{
12+
pattern: 'get:info',
13+
out: {
14+
ok: true,
15+
name: 'tangocard',
16+
version: Pkg.version,
17+
},
18+
}
19+
]
20+
}

‎test/live.js

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
2+
// IMPORTANT: assumes node-fetch@2
3+
const Fetch = require('node-fetch')
4+
5+
const Seneca = require('seneca')
6+
7+
// global.fetch = Fetch
8+
9+
10+
Seneca({ legacy: false })
11+
.test()
12+
.use('promisify')
13+
.use('entity')
14+
.use('env', {
15+
// debug: true,
16+
file: [__dirname + '/local-env.js;?'],
17+
var: {
18+
$TANGOCARD_KEY: String,
19+
$TANGOCARD_NAME: String,
20+
$TANGOCARD_CUSTID: String,
21+
$TANGOCARD_ACCID: String,
22+
}
23+
})
24+
.use('provider', {
25+
provider: {
26+
tangocard: {
27+
keys: {
28+
key: { value: '$TANGOCARD_KEY' },
29+
name: { value: '$TANGOCARD_NAME' },
30+
cust: { value: '$TANGOCARD_CUSTID' },
31+
acc: { value: '$TANGOCARD_ACCID' },
32+
}
33+
}
34+
}
35+
})
36+
.use('../',{
37+
fetch: Fetch,
38+
entity: {
39+
order: {
40+
save: {
41+
sendEmail: true,
42+
sender: {
43+
email: 'richard+tangocard.sender.01@ricebridge.com',
44+
firstName: 'Sender',
45+
lastName: ''
46+
}
47+
}
48+
}
49+
}
50+
})
51+
.ready(async function() {
52+
const seneca = this
53+
54+
console.log(await seneca.post('sys:provider,provider:tangocard,get:info'))
55+
56+
const brands = await seneca.entity("provider/tangocard/brand").list$({
57+
country: 'IE', verbose: false
58+
})
59+
console.log('brands',brands.length)
60+
// console.dir(brands,{depth:null})
61+
62+
let customers = await seneca.entity("provider/tangocard/customer").list$()
63+
console.log('customers', customers.length)
64+
console.dir(customers,{depth:null})
65+
66+
let orders = await seneca.entity('provider/tangocard/order').list$()
67+
console.log('orders',orders.length)
68+
69+
70+
let mark = Math.random()+''
71+
let utid = 'U768452'
72+
73+
let order = seneca.entity('provider/tangocard/order').data$({
74+
amount: 10,
75+
// campaign: 'test01',
76+
campaign: '',
77+
emailSubject: 'subject '+mark,
78+
etid: 'E000000',
79+
externalRefID: seneca.util.Nid(),
80+
message: 'msg '+mark,
81+
notes: 'note '+mark,
82+
recipient: {
83+
email: 'richard+tangocard.test.01@ricebridge.com',
84+
firstName: 'First',
85+
lastName: ''
86+
},
87+
// sendEmail: true,
88+
// sender: {
89+
// email: '',
90+
// firstName: '',
91+
// lastName: ''
92+
// },
93+
utid
94+
})
95+
96+
try {
97+
order = await order.save$()
98+
console.log('order',order)
99+
}
100+
catch(e) {
101+
console.log(e.message)
102+
console.log(e.status)
103+
console.log(e.body)
104+
}
105+
106+
})
107+

‎test/local-config-template.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module.exports = {
2+
}

‎test/local-env-template.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
TANGOCARD_NAME: '<NAME>',
3+
TANGOCARD_KEY: '<KEY>',
4+
TANGOCARD_CUSTID: '<customerIdentifier>',
5+
TANGOCARD_ACCID: '<accountIdentifier>',
6+
}

‎test/quick.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
3+
4+
console.log('quick!')
5+
6+
7+

‎test/tangocard-provider.test.ts

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/* Copyright © 2022 Seneca Project Contributors, MIT License. */
2+
3+
import * as Fs from 'fs'
4+
5+
// const Fetch = require('node-fetch')
6+
7+
8+
const Seneca = require('seneca')
9+
const SenecaMsgTest = require('seneca-msg-test')
10+
11+
import TangocardProvider from '../src/tangocard-provider'
12+
import TangocardProviderDoc from '../src/TangocardProvider-doc'
13+
14+
const BasicMessages = require('./basic.messages.js')
15+
16+
17+
// Only run some tests locally (not on Github Actions).
18+
let Config = undefined
19+
if (Fs.existsSync(__dirname + '/local-config.js')) {
20+
Config = require('./local-config')
21+
}
22+
23+
24+
describe('tangocard-provider', () => {
25+
26+
test('happy', async () => {
27+
expect(TangocardProvider).toBeDefined()
28+
expect(TangocardProviderDoc).toBeDefined()
29+
30+
const seneca = await makeSeneca()
31+
32+
expect(await seneca.post('sys:provider,provider:tangocard,get:info'))
33+
.toMatchObject({
34+
ok: true,
35+
name: 'tangocard',
36+
})
37+
})
38+
39+
40+
test('messages', async () => {
41+
const seneca = await makeSeneca()
42+
await (SenecaMsgTest(seneca, BasicMessages)())
43+
})
44+
45+
46+
test('list-brand', async () => {
47+
if (!Config) return;
48+
const seneca = await makeSeneca()
49+
50+
const list = await seneca.entity("provider/tangocard/brand").list$()
51+
// console.log('BRANDS', list)
52+
53+
expect(list.length > 0).toBeTruthy()
54+
})
55+
56+
})
57+
58+
59+
async function makeSeneca() {
60+
const seneca = Seneca({ legacy: false })
61+
.test()
62+
.use('promisify')
63+
.use('entity')
64+
.use('env', {
65+
// debug: true,
66+
file: [__dirname + '/local-env.js;?'],
67+
var: {
68+
$TANGOCARD_KEY: String,
69+
$TANGOCARD_NAME: String,
70+
$TANGOCARD_CUSTID: String,
71+
$TANGOCARD_ACCID: String,
72+
}
73+
})
74+
.use('provider', {
75+
provider: {
76+
tangocard: {
77+
keys: {
78+
key: { value: '$TANGOCARD_KEY' },
79+
name: { value: '$TANGOCARD_NAME' },
80+
cust: { value: '$TANGOCARD_CUSTID' },
81+
acc: { value: '$TANGOCARD_ACCID' },
82+
}
83+
}
84+
}
85+
})
86+
.use(TangocardProvider, {
87+
// fetch: Fetch,
88+
})
89+
90+
return seneca.ready()
91+
}
92+

‎tsconfig.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"esModuleInterop": true,
4+
"isolatedModules": true,
5+
"module": "commonjs",
6+
"moduleResolution": "nodenext",
7+
"noEmitOnError": true,
8+
"outDir":"dist",
9+
"resolveJsonModule": true,
10+
"rootDir":"src",
11+
"sourceMap": true,
12+
"strict": true,
13+
"target": "ES2019"
14+
},
15+
"exclude": [
16+
"test",
17+
"dist",
18+
"node_modules"
19+
]
20+
}

‎tsfmt.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"indentSize": 2
3+
}

0 commit comments

Comments
 (0)
Please sign in to comment.