Merge pull request #1075 from wrightia/v4-connection-stripe

Connection Stripe V4
This commit is contained in:
Sam 2022-02-01 12:35:06 +02:00 committed by GitHub
commit 89af216d13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 211 additions and 152 deletions

1
.pnp.cjs generated
View File

@ -5211,6 +5211,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["@lowdefy/connection-mongodb", "workspace:packages/plugins/connections/connection-mongodb"],
["@lowdefy/connection-redis", "workspace:packages/plugins/connections/connection-redis"],
["@lowdefy/connection-sendgrid", "workspace:packages/plugins/connections/connection-sendgrid"],
["@lowdefy/connection-stripe", "workspace:packages/plugins/connections/connection-stripe"],
["@lowdefy/helpers", "workspace:packages/utils/helpers"],
["@lowdefy/node-utils", "workspace:packages/utils/node-utils"],
["@lowdefy/nunjucks", "workspace:packages/utils/nunjucks"],

View File

@ -68,6 +68,7 @@
"@lowdefy/connection-mongodb": "4.0.0-alpha.6",
"@lowdefy/connection-redis": "4.0.0-alpha.6",
"@lowdefy/connection-sendgrid": "4.0.0-alpha.6",
"@lowdefy/connection-stripe": "4.0.0-alpha.6",
"@lowdefy/operators-change-case": "4.0.0-alpha.6",
"@lowdefy/operators-diff": "4.0.0-alpha.6",
"@lowdefy/operators-js": "4.0.0-alpha.6",

View File

@ -32,6 +32,7 @@ const defaultPackages = [
'@lowdefy/connection-mongodb',
'@lowdefy/connection-redis',
'@lowdefy/connection-sendgrid',
'@lowdefy/connection-stripe',
'@lowdefy/operators-change-case',
// '@lowdefy/operators-diff',
'@lowdefy/operators-js',

View File

@ -27,8 +27,8 @@
},
"type": "module",
"exports": {
".": "./dist/index.js",
"./connections/*": "./dist/connections/*"
"./connections": "./dist/connections.js",
"./types": "./dist/types.js"
},
"files": [
"dist/*"

View File

@ -14,13 +14,4 @@
limitations under the License.
*/
export default {
import: {
path: 'connections/Stripe/StripeRequest/StripeRequest.js',
schema: 'connections/Stripe/StripeRequest/StripeRequestSchema.json',
},
meta: {
checkRead: false,
checkWrite: false,
},
};
export { default as Stripe } from './connections/Stripe/Stripe.js';

View File

@ -15,11 +15,10 @@
*/
import StripeRequest from './StripeRequest/StripeRequest.js';
import schema from './schema.js';
export default {
import: {
schema: 'connections/Stripe/StripeSchema.json',
},
schema,
requests: {
StripeRequest,
},

View File

@ -16,7 +16,8 @@
import { validate } from '@lowdefy/ajv';
import Stripe from './Stripe.js';
import schema from './StripeSchema.json';
const schema = Stripe.schema;
test('All requests are present', () => {
expect(Stripe.requests.StripeRequest).toBeDefined();

View File

@ -16,9 +16,9 @@
import { get } from '@lowdefy/helpers';
import Stripe from 'stripe';
import schema from './StripeRequestSchema.json';
import schema from './schema.js';
async function stripeRequest({ request, connection }) {
async function StripeRequest({ request, connection }) {
const stripe = new Stripe(connection.secretKey, {
apiVersion: connection.apiVersion,
maxNetworkRetries: connection.maxNetworkRetries,
@ -46,4 +46,10 @@ async function stripeRequest({ request, connection }) {
return method.call(resource, ...(args || []));
}
export default stripeRequest;
StripeRequest.schema = schema;
StripeRequest.meta = {
checkRead: false,
checkWrite: false,
};
export default StripeRequest;

View File

@ -15,8 +15,10 @@
*/
import { validate } from '@lowdefy/ajv';
import stripeRequest from './StripeRequest.js';
import schema from './StripeRequestSchema.json';
import StripeRequest from './StripeRequest.js';
const { checkRead, checkWrite } = StripeRequest.meta;
const schema = StripeRequest.schema;
const connection = {
secretKey: 'foo',
@ -196,7 +198,7 @@ test('valid request for missing resource', async () => {
},
};
return expect(() => stripeRequest({ request, connection })).rejects.toThrow(
return expect(() => StripeRequest({ request, connection })).rejects.toThrow(
'Invalid Stripe method foo.bar'
);
});
@ -208,7 +210,7 @@ test('valid request for missing resource method', async () => {
},
};
return expect(() => stripeRequest({ request, connection })).rejects.toThrow(
return expect(() => StripeRequest({ request, connection })).rejects.toThrow(
'Invalid Stripe method customers.foo'
);
});
@ -220,7 +222,7 @@ test('valid request for missing resource method', async () => {
},
};
return expect(() => stripeRequest({ request, connection })).rejects.toThrow(
return expect(() => StripeRequest({ request, connection })).rejects.toThrow(
'Invalid Stripe method customers.missing'
);
});
@ -232,7 +234,15 @@ test('valid request', async () => {
},
};
const res = await stripeRequest({ request, connection });
const res = await StripeRequest({ request, connection });
return expect(res).toEqual(['foo', 42, { bar: true }]);
});
test('checkRead should be false', async () => {
expect(checkRead).toBe(false);
});
test('checkWrite should be false', async () => {
expect(checkWrite).toBe(false);
});

View File

@ -1,64 +0,0 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Lowdefy Request Schema - StripeRequest",
"type": "object",
"patternProperties": {
".+": {
"description": "Stripe API resource",
"type": "object",
"minProperties": 1,
"maxProperties": 1,
"errorMessage": {
"type": "StripeRequest resource should be an object.",
"minProperties": "StripeRequest resource should contain a method to call.",
"maxProperties": "StripeRequest resource should contain only a single method to call.",
"oneOf": "StripeRequest resource should only contain a method to call, or sub-resource with a method to call."
},
"oneOf": [
{
"description": "Stripe API method to call on the resource",
"patternProperties": {
".+": {
"description": "Parameters to pass to the resource method, if any",
"type": [
"array",
"null"
],
"errorMessage": {
"type": "Should be an array of parameters or null."
}
}
}
},
{
"description": "Stripe API sub-resource of the parent resource",
"patternProperties": {
".+": {
"description": "Stripe API method to call on the resource",
"type": "object",
"minProperties": 1,
"maxProperties": 1,
"patternProperties": {
".+": {
"description": "Parameters to pass to the sub-resource method, if any",
"type": [
"array",
"null"
]
}
}
}
}
}
]
}
},
"minProperties": 1,
"maxProperties": 1,
"errorMessage": {
"type": "StripeRequest request properties should be an object.",
"additionalProperties": "StripeRequest should contain a valid resource to call.",
"minProperties": "StripeRequest should contain a resource to call.",
"maxProperties": "StripeRequest should contain only a single resource to call."
}
}

View File

@ -0,0 +1,75 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
export default {
$schema: 'http://json-schema.org/draft-07/schema#',
title: 'Lowdefy Request Schema - StripeRequest',
type: 'object',
patternProperties: {
'.+': {
description: 'Stripe API resource',
type: 'object',
minProperties: 1,
maxProperties: 1,
errorMessage: {
type: 'StripeRequest resource should be an object.',
minProperties: 'StripeRequest resource should contain a method to call.',
maxProperties: 'StripeRequest resource should contain only a single method to call.',
oneOf:
'StripeRequest resource should only contain a method to call, or sub-resource with a method to call.',
},
oneOf: [
{
description: 'Stripe API method to call on the resource',
patternProperties: {
'.+': {
description: 'Parameters to pass to the resource method, if any',
type: ['array', 'null'],
errorMessage: {
type: 'Should be an array of parameters or null.',
},
},
},
},
{
description: 'Stripe API sub-resource of the parent resource',
patternProperties: {
'.+': {
description: 'Stripe API method to call on the resource',
type: 'object',
minProperties: 1,
maxProperties: 1,
patternProperties: {
'.+': {
description: 'Parameters to pass to the sub-resource method, if any',
type: ['array', 'null'],
},
},
},
},
},
],
},
},
minProperties: 1,
maxProperties: 1,
errorMessage: {
type: 'StripeRequest request properties should be an object.',
additionalProperties: 'StripeRequest should contain a valid resource to call.',
minProperties: 'StripeRequest should contain a resource to call.',
maxProperties: 'StripeRequest should contain only a single resource to call.',
},
};

View File

@ -1,55 +0,0 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Lowdefy Connection Schema - Stripe",
"type": "object",
"required": [
"secretKey"
],
"properties": {
"secretKey": {
"type": "string",
"description": "Stripe secret key.",
"errorMessage": {
"type": "Stripe connection property \"secretKey\" should be a string."
}
},
"apiVersion": {
"type": "string",
"description": "Stripe API version to use.",
"default": null,
"errorMessage": {
"type": "Stripe connection property \"apiVersion\" should be a string."
}
},
"telemetry": {
"type": "boolean",
"description": "Allow Stripe to send latency telemetry.",
"default": true,
"errorMessage": {
"type": "Stripe connection property \"telemetry\" should be a boolean."
}
},
"timeout": {
"type": "integer",
"description": "Maximum time each request can take in ms.",
"default": 80000,
"errorMessage": {
"type": "Stripe connection property \"timeout\" should be an integer."
}
},
"maxNetworkRetries": {
"type": "integer",
"description": "The amount of times a request should be retried.",
"default": 0,
"errorMessage": {
"type": "Stripe connection property \"maxNetworkRetries\" should be an integer."
}
}
},
"errorMessage": {
"type": "Stripe connection properties should be an object.",
"required": {
"secretKey": "Stripe connection should have required property \"secretKey\"."
}
}
}

View File

@ -0,0 +1,69 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
export default {
$schema: 'http://json-schema.org/draft-07/schema#',
title: 'Lowdefy Connection Schema - Stripe',
type: 'object',
required: ['secretKey'],
properties: {
secretKey: {
type: 'string',
description: 'Stripe secret key.',
errorMessage: {
type: 'Stripe connection property "secretKey" should be a string.',
},
},
apiVersion: {
type: 'string',
description: 'Stripe API version to use.',
default: null,
errorMessage: {
type: 'Stripe connection property "apiVersion" should be a string.',
},
},
telemetry: {
type: 'boolean',
description: 'Allow Stripe to send latency telemetry.',
default: true,
errorMessage: {
type: 'Stripe connection property "telemetry" should be a boolean.',
},
},
timeout: {
type: 'integer',
description: 'Maximum time each request can take in ms.',
default: 80000,
errorMessage: {
type: 'Stripe connection property "timeout" should be an integer.',
},
},
maxNetworkRetries: {
type: 'integer',
description: 'The amount of times a request should be retried.',
default: 0,
errorMessage: {
type: 'Stripe connection property "maxNetworkRetries" should be an integer.',
},
},
},
errorMessage: {
type: 'Stripe connection properties should be an object.',
required: {
secretKey: 'Stripe connection should have required property "secretKey".',
},
},
};

View File

@ -1,7 +0,0 @@
import Stripe from './connections/Stripe/Stripe.js';
export const connections = {
Stripe,
};
export default { connections };

View File

@ -0,0 +1,30 @@
/* eslint-disable import/namespace */
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import * as connections from './connections.js';
export default {
connections: Object.keys(connections),
requests: Object.keys(connections)
.map((connection) => Object.keys(connections[connection].requests))
.flat(),
};
// export default {
// connections: ['Stripe'],
// requests: ['StripeRequest'],
// };

View File

@ -3507,6 +3507,7 @@ __metadata:
"@lowdefy/connection-mongodb": 4.0.0-alpha.6
"@lowdefy/connection-redis": 4.0.0-alpha.6
"@lowdefy/connection-sendgrid": 4.0.0-alpha.6
"@lowdefy/connection-stripe": 4.0.0-alpha.6
"@lowdefy/helpers": 4.0.0-alpha.6
"@lowdefy/node-utils": 4.0.0-alpha.6
"@lowdefy/nunjucks": 4.0.0-alpha.6
@ -3637,7 +3638,7 @@ __metadata:
languageName: unknown
linkType: soft
"@lowdefy/connection-stripe@workspace:packages/plugins/connections/connection-stripe":
"@lowdefy/connection-stripe@4.0.0-alpha.6, @lowdefy/connection-stripe@workspace:packages/plugins/connections/connection-stripe":
version: 0.0.0-use.local
resolution: "@lowdefy/connection-stripe@workspace:packages/plugins/connections/connection-stripe"
dependencies: