forked from deep-foundation/dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
payments.cjs
176 lines (151 loc) · 5.99 KB
/
payments.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
require('react');
require('graphql');
require('lodash');
require('subscriptions-transport-ws');
const { generateApolloClient } = require("@deep-foundation/hasura/client");
const { DeepClient } = require('@deep-foundation/deeplinks/imports/client');
const { minilinks, Link } = require('@deep-foundation/deeplinks/imports/minilinks');
const apolloClient = generateApolloClient({
path: process.env.NEXT_PUBLIC_GQL_PATH || '', // <<= HERE PATH TO UPDATE
ssl: !!~process.env.NEXT_PUBLIC_GQL_PATH.indexOf('localhost') ? false : true,
// admin token in prealpha deep secret key
// token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwczovL2hhc3VyYS5pby9qd3QvY2xhaW1zIjp7IngtaGFzdXJhLWFsbG93ZWQtcm9sZXMiOlsibGluayJdLCJ4LWhhc3VyYS1kZWZhdWx0LXJvbGUiOiJsaW5rIiwieC1oYXN1cmEtdXNlci1pZCI6IjI2MiJ9LCJpYXQiOjE2NTYxMzYyMTl9.dmyWwtQu9GLdS7ClSLxcXgQiKxmaG-JPDjQVxRXOpxs',
});
const unloginedDeep = new DeepClient({ apolloClient });
const delay = (time = 1000) => new Promise(res => setTimeout(res, time));
const f = async () => {
const guest = await unloginedDeep.guest();
const guestDeep = new DeepClient({ deep: unloginedDeep, ...guest });
const admin = await guestDeep.login({ linkId: await guestDeep.id('deep', 'admin') });
const deep = new DeepClient({ deep: guestDeep, ...admin });
const User = await deep.id('@deep-foundation/core', 'User');
const Type = await deep.id('@deep-foundation/core', 'Type');
const Any = await deep.id('@deep-foundation/core', 'Any');
const Join = await deep.id('@deep-foundation/core', 'Join');
const Contain = await deep.id('@deep-foundation/core', 'Contain');
const Value = await deep.id('@deep-foundation/core', 'Value');
const String = await deep.id('@deep-foundation/core', 'String');
const Package = await deep.id('@deep-foundation/core', 'Package');
const SyncTextFile = await deep.id('@deep-foundation/core', 'SyncTextFile');
const dockerSupportsJs = await deep.id('@deep-foundation/core', 'dockerSupportsJs');
const Handler = await deep.id('@deep-foundation/core', 'Handler');
const HandleInsert = await deep.id('@deep-foundation/core', 'HandleInsert');
const HandleDelete = await deep.id('@deep-foundation/core', 'HandleDelete');
const Tree = await deep.id('@deep-foundation/core', 'Tree');
const TreeIncludeNode = await deep.id('@deep-foundation/core', 'TreeIncludeNode');
const TreeIncludeUp = await deep.id('@deep-foundation/core', 'TreeIncludeUp');
const TreeIncludeFromCurrent = await deep.id('@deep-foundation/core', 'TreeIncludeFromCurrent');
const Rule = await deep.id('@deep-foundation/core', 'Rule');
const RuleSubject = await deep.id('@deep-foundation/core', 'RuleSubject');
const RuleObject = await deep.id('@deep-foundation/core', 'RuleObject');
const RuleAction = await deep.id('@deep-foundation/core', 'RuleAction');
const Selector = await deep.id('@deep-foundation/core', 'Selector');
const SelectorInclude = await deep.id('@deep-foundation/core', 'SelectorInclude');
const SelectorExclude = await deep.id('@deep-foundation/core', 'SelectorExclude');
const SelectorTree = await deep.id('@deep-foundation/core', 'SelectorTree');
const containTree = await deep.id('@deep-foundation/core', 'containTree');
const AllowInsertType = await deep.id('@deep-foundation/core', 'AllowInsertType');
const AllowDeleteType = await deep.id('@deep-foundation/core', 'AllowDeleteType');
const SelectorFilter = await deep.id('@deep-foundation/core', 'SelectorFilter');
const Query = await deep.id('@deep-foundation/core', 'Query');
const usersId = await deep.id('deep', 'users');
const { data: [{ id: packageId }] } = await deep.insert({
type_id: Package,
string: { data: { value: `@deep-foundation/payments` } },
in: { data: [
{
type_id: Contain,
from_id: deep.linkId
},
] },
out: { data: [
{
type_id: Join,
to_id: await deep.id('deep', 'users', 'packages'),
},
{
type_id: Join,
to_id: await deep.id('deep', 'admin'),
},
] },
});
console.log({ packageId });
const { data: [{ id: PPayment }] } = await deep.insert({
type_id: Type,
from_id: Any,
to_id: Any,
in: { data: {
type_id: Contain,
from_id: packageId,
string: { data: { value: 'Payment' } },
} },
});
console.log({ PPayment: PPayment });
const { data: [{ id: PObject }] } = await deep.insert({
type_id: Type,
from_id: Any,
to_id: Any,
in: { data: {
type_id: Contain,
from_id: packageId,
string: { data: { value: 'Object' } },
} },
});
console.log({ PObject: PObject });
const { data: [{ id: PSum }] } = await deep.insert({
type_id: Type,
from_id: Any,
to_id: Any,
in: { data: {
type_id: Contain,
from_id: packageId, // before created package
string: { data: { value: 'Sum' } },
} },
});
console.log({ PSum: PSum });
const { data: [{ id: PPay }] } = await deep.insert({
type_id: Type,
from_id: Any,
to_id: Any,
in: { data: {
type_id: Contain,
from_id: packageId, // before created package
string: { data: { value: 'Pay' } },
} },
});
console.log({ PPay: PPay });
const { data: [{ id: PUrl }] } = await deep.insert({
type_id: Type,
from_id: Any,
to_id: Any,
in: { data: {
type_id: Contain,
from_id: packageId, // before created package
string: { data: { value: 'Url' } },
} },
});
console.log({ PUrl: PUrl });
const { data: [{ id: PPayed }] } = await deep.insert({
type_id: Type,
from_id: Any,
to_id: Any,
in: { data: {
type_id: Contain,
from_id: packageId, // before created package
string: { data: { value: 'Payed' } },
} },
});
console.log({ PPayed: PPayed });
const { data: [{ id: PError }] } = await deep.insert({
type_id: Type,
from_id: Any,
to_id: Any,
in: { data: {
type_id: Contain,
from_id: packageId, // before created package
string: { data: { value: 'Error' } },
} },
});
console.log({ PError: PError });
};
f();